Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/script address encoding 2 #66

Merged
merged 6 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
54 changes: 38 additions & 16 deletions docs/typescript/core/Blaze/classes/BlazeHelper.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Cardano addresses. These functions include:

## Methods

### getAddressHashes()
### getAddressAsType()

> `static` **getAddressHashes**(`address`): `object`
> `static` **getAddressAsType**(`address`): `object`

Helper function to parse addresses hashes from a Bech32 encoded address.

Expand All @@ -37,39 +37,61 @@ Helper function to parse addresses hashes from a Bech32 encoded address.

`object`

##### paymentCredentials
##### address

> **paymentCredentials**: `Hash28ByteBase16`
> **address**: `Address`

##### stakeCredentials?
##### type

> `optional` **stakeCredentials**: `string`
> **type**: `AddressType`

#### Defined in

[packages/core/src/Utilities/BlazeHelper.class.ts:28](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L28)

***

### isScriptAddress()
### isBaseAddress()

> `static` **isScriptAddress**(`address`): `boolean`
> `static` **isBaseAddress**(`type`): `boolean`

Helper function to check if an address is a script address.
Helper method to determine address type.

#### Parameters

• **address**: `string`
• **type**: `AddressType`

The address type.

#### Returns

`boolean`

#### Defined in

[packages/core/src/Utilities/BlazeHelper.class.ts:60](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L60)

***

### isEnterpriseAddress()

> `static` **isEnterpriseAddress**(`type`): `boolean`

Helper method to determine address type.

#### Parameters

• **type**: `AddressType`

The Bech32 encoded address.
The address type.

#### Returns

`boolean`

#### Defined in

[packages/core/src/Utilities/BlazeHelper.class.ts:137](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L137)
[packages/core/src/Utilities/BlazeHelper.class.ts:47](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L47)

***

Expand All @@ -93,7 +115,7 @@ Throws a useful error if the address, network, and instance network are on the w

#### Defined in

[packages/core/src/Utilities/BlazeHelper.class.ts:183](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L183)
[packages/core/src/Utilities/BlazeHelper.class.ts:203](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L203)

***

Expand All @@ -115,7 +137,7 @@ Throws an error describing the address and contextual information.

#### Defined in

[packages/core/src/Utilities/BlazeHelper.class.ts:210](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L210)
[packages/core/src/Utilities/BlazeHelper.class.ts:230](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L230)

***

Expand All @@ -142,7 +164,7 @@ and that the address is on the correct network.

#### Defined in

[packages/core/src/Utilities/BlazeHelper.class.ts:80](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L80)
[packages/core/src/Utilities/BlazeHelper.class.ts:112](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L112)

***

Expand All @@ -164,4 +186,4 @@ Validates that an address matches the provided network.

#### Defined in

[packages/core/src/Utilities/BlazeHelper.class.ts:151](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L151)
[packages/core/src/Utilities/BlazeHelper.class.ts:167](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L167)
10 changes: 5 additions & 5 deletions docs/typescript/core/Blaze/classes/DatumBuilderBlazeV1.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The current network id.

#### Defined in

[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts:41](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts#L41)
[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts:42](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts#L42)

***

Expand All @@ -33,7 +33,7 @@ The error to throw when the pool ident does not match V1 constraints.

#### Defined in

[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts:43](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts#L43)
[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts:44](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts#L44)

## Methods

Expand Down Expand Up @@ -102,7 +102,7 @@ An object containing the hash of the inline datum, the inline datum itself,

#### Defined in

[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts:96](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts#L96)
[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts:97](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts#L97)

***

Expand Down Expand Up @@ -184,7 +184,7 @@ An object containing the hash of the inline datum, the inline datum itself,

#### Defined in

[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts:62](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts#L62)
[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts:63](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts#L63)

***

Expand Down Expand Up @@ -254,4 +254,4 @@ An object comprising the hash of the inline datum, the inline datum itself,

#### Defined in

[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts:141](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts#L141)
[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts:142](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts#L142)
12 changes: 6 additions & 6 deletions docs/typescript/core/Blaze/classes/DatumBuilderBlazeV3.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ The UTxO txHash and index.

#### Defined in

[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts:516](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts#L516)
[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts:526](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts#L526)

***

Expand All @@ -389,7 +389,7 @@ The hex encoded pool ident.

#### Defined in

[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts:492](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts#L492)
[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts:502](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts#L502)

***

Expand All @@ -411,7 +411,7 @@ The hex encoded pool ident.

#### Defined in

[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts:480](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts#L480)
[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts:490](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts#L490)

***

Expand All @@ -433,7 +433,7 @@ The hex encoded pool ident.

#### Defined in

[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts:504](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts#L504)
[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts:514](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts#L514)

***

Expand Down Expand Up @@ -471,7 +471,7 @@ An object containing the staking and

#### Defined in

[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts:547](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts#L547)
[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts:557](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts#L557)

***

Expand Down Expand Up @@ -500,4 +500,4 @@ The signing key associated with the owner, extracted from the datum. This key is

#### Defined in

[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts:589](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts#L589)
[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts:599](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts#L599)
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default [
rules: {
"@typescript-eslint/no-this-alias": "off",
"@typescript-eslint/no-explicit-any": "warn",
"no-unused-expressions": "off",
},
languageOptions: {
globals: {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@
"lucid-cardano": "0.10.7",
"prettier": "^3.3.2",
"typedoc": "0.26.7",
"typedoc-plugin-frontmatter": "1.0.0",
"typedoc-plugin-markdown": "4.2.7",
"typedoc-plugin-frontmatter": "1.0.0"
"typescript": "5.5"
},
"dependencies": {},
"trustedDependencies": [
Expand Down
77 changes: 50 additions & 27 deletions packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
TWithdrawOrder,
WithdrawOrder,
} from "./ContractTypes/Contract.Blaze.v1.js";
import { V1Types } from "./ContractTypes/index.js";

/**
* The Blaze implementation for building valid Datums for
Expand Down Expand Up @@ -203,54 +204,76 @@ export class DatumBuilderBlazeV1 implements DatumBuilder {
});

const { DestinationAddress, AlternateAddress } = addresses;
const destinationHashes = BlazeHelper.getAddressHashes(
DestinationAddress.address,
);

if (DestinationAddress.datum.type === EDatumType.INLINE) {
throw new Error(
"Inline datum types are not supported in V1 contracts! Convert this to a hash.",
);
}

const destinationAddressCredentialType = BlazeHelper.isScriptAddress(
const paymentPart = BlazeHelper.getPaymentHashFromBech32(
DestinationAddress.address,
)
? ("ScriptHash" as keyof TDestination["credentials"]["paymentKey"])
: "KeyHash";
);
const stakingPart = BlazeHelper.getStakingHashFromBech32(
DestinationAddress.address,
);

let paymentKeyData: V1Types.TPaymentStakingHash | undefined;
if (BlazeHelper.isScriptAddress(DestinationAddress.address)) {
paymentKeyData = {
ScriptHash: {
value: paymentPart,
},
};
} else {
paymentKeyData = {
KeyHash: {
value: paymentPart,
},
};
}

let stakingKeyData: V1Types.TPaymentStakingHash | undefined;
if (stakingPart) {
if (BlazeHelper.isScriptAddress(DestinationAddress.address)) {
stakingKeyData = {
ScriptHash: {
value: stakingPart,
},
};
} else {
stakingKeyData = {
KeyHash: {
value: stakingPart,
},
};
}
}

const destination: TDestination = {
credentials: {
paymentKey: {
[destinationAddressCredentialType]: {
value: destinationHashes.paymentCredentials,
},
},
stakingKey: destinationHashes.stakeCredentials
? {
value: {
[destinationAddressCredentialType]: {
value: destinationHashes.stakeCredentials,
},
},
}
: null,
paymentKey: paymentKeyData,
stakingKey: stakingKeyData ? { value: stakingKeyData } : null,
},
datum:
DestinationAddress.datum.type !== EDatumType.NONE
? DestinationAddress.datum.value
: null,
};

const alternateHashes =
AlternateAddress && BlazeHelper.getAddressHashes(AlternateAddress);
let alternatePaymentPart: string | null = null;
let alternateStakingPart: string | undefined;

if (AlternateAddress) {
alternatePaymentPart =
BlazeHelper.getPaymentHashFromBech32(AlternateAddress);
alternateStakingPart =
BlazeHelper.getStakingHashFromBech32(AlternateAddress);
}

const datum: TOrderAddresses = {
destination,
alternate: alternateHashes
? (alternateHashes.stakeCredentials ??
alternateHashes.paymentCredentials)
: null,
alternate: alternateStakingPart || alternatePaymentPart,
};

const data = Data.to<TOrderAddresses>(datum, OrderAddresses);
Expand Down
Loading
Loading