From f2b83b4e6a7d0d47de4cd8f3297158f5a8770ad4 Mon Sep 17 00:00:00 2001 From: Calvin Koepke Date: Wed, 18 Dec 2024 12:15:37 -0700 Subject: [PATCH] fix: script addresses were using wrong encoding in the datum --- .../core/Blaze/classes/BlazeHelper.md | 14 +++++++++----- .../core/Blaze/classes/DatumBuilderBlazeV3.md | 12 ++++++------ .../DatumBuilder.Blaze.V3.class.ts | 19 +++++++++++++++---- .../core/src/Utilities/BlazeHelper.class.ts | 3 +++ 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/docs/typescript/core/Blaze/classes/BlazeHelper.md b/docs/typescript/core/Blaze/classes/BlazeHelper.md index 4b9daf7..32156fa 100644 --- a/docs/typescript/core/Blaze/classes/BlazeHelper.md +++ b/docs/typescript/core/Blaze/classes/BlazeHelper.md @@ -45,6 +45,10 @@ Helper function to parse addresses hashes from a Bech32 encoded address. > `optional` **stakeCredentials**: `string` +##### type + +> **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) @@ -69,7 +73,7 @@ The Bech32 encoded address. #### 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:140](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L140) *** @@ -93,7 +97,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:186](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L186) *** @@ -115,7 +119,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:213](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L213) *** @@ -142,7 +146,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:83](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L83) *** @@ -164,4 +168,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:154](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L154) diff --git a/docs/typescript/core/Blaze/classes/DatumBuilderBlazeV3.md b/docs/typescript/core/Blaze/classes/DatumBuilderBlazeV3.md index 62cd31d..c98e460 100644 --- a/docs/typescript/core/Blaze/classes/DatumBuilderBlazeV3.md +++ b/docs/typescript/core/Blaze/classes/DatumBuilderBlazeV3.md @@ -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:527](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts#L527) *** @@ -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:503](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts#L503) *** @@ -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:491](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts#L491) *** @@ -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:515](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts#L515) *** @@ -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:558](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts#L558) *** @@ -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:600](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts#L600) diff --git a/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts b/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts index 4ea7957..abc8ae3 100644 --- a/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts +++ b/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V3.class.ts @@ -390,11 +390,22 @@ export class DatumBuilderBlazeV3 implements DatumBuilder { public buildOwnerDatum(main: string): TDatumResult { BlazeHelper.validateAddressNetwork(main, this.network); - const { stakeCredentials, paymentCredentials } = + const { stakeCredentials, paymentCredentials, type } = BlazeHelper.getAddressHashes(main); - const ownerDatum: V3Types.TMultiSigScript = { - Address: { hex: stakeCredentials || paymentCredentials }, - }; + + let ownerDatum: V3Types.TMultiSigScript; + if ( + type === Core.AddressType.BasePaymentScriptStakeKey || + type === Core.AddressType.BasePaymentScriptStakeScript + ) { + ownerDatum = { + Script: { hex: stakeCredentials || paymentCredentials }, + }; + } else { + ownerDatum = { + Address: { hex: stakeCredentials || paymentCredentials }, + }; + } const data = Data.to(ownerDatum, V3Types.MultiSigScript); diff --git a/packages/core/src/Utilities/BlazeHelper.class.ts b/packages/core/src/Utilities/BlazeHelper.class.ts index 3fec6f7..d637269 100644 --- a/packages/core/src/Utilities/BlazeHelper.class.ts +++ b/packages/core/src/Utilities/BlazeHelper.class.ts @@ -28,6 +28,7 @@ export class BlazeHelper { static getAddressHashes(address: string): { paymentCredentials: Core.Hash28ByteBase16; stakeCredentials?: string; + type: Core.AddressType; } { const details = Core.Address.fromBech32(address); const addressType = details.getType(); @@ -46,6 +47,7 @@ export class BlazeHelper { return { paymentCredentials, stakeCredentials: details.asBase()?.getStakeCredential()?.hash, + type: addressType, }; } case Core.AddressType.EnterpriseKey: @@ -59,6 +61,7 @@ export class BlazeHelper { return { paymentCredentials, + type: addressType, }; }