From aaca2b8f1ec0112c3fb7a92e074c8003f10a03ca Mon Sep 17 00:00:00 2001 From: Angel Castillo Date: Thu, 12 Jun 2025 15:59:30 +0800 Subject: [PATCH 1/3] Revert "refactor!: make Bip32Account methods synchronous" This reverts commit b56110c2183e035086e9868e8aa4f6999e9390ed. --- .../test/local-network/register-pool.test.ts | 32 +++++++++++-------- .../long-running/cache-invalidation.test.ts | 16 ++++++---- .../PersonalWallet/cip30WalletApi.test.ts | 8 ++--- packages/key-management/src/Bip32Account.ts | 10 +++--- .../key-management/test/Bip32Account.test.ts | 2 +- .../src/tx-builder/initializeTx.ts | 4 ++- .../src/services/PublicStakeKeysTracker.ts | 15 +++++---- .../test/PersonalWallet/methods.test.ts | 11 ++----- .../services/PublicStakeKeysTracker.test.ts | 13 ++++---- 9 files changed, 59 insertions(+), 52 deletions(-) diff --git a/packages/e2e/test/local-network/register-pool.test.ts b/packages/e2e/test/local-network/register-pool.test.ts index 2bf8016f470..8bdeb4df45f 100644 --- a/packages/e2e/test/local-network/register-pool.test.ts +++ b/packages/e2e/test/local-network/register-pool.test.ts @@ -82,19 +82,21 @@ describe('local-network/register-pool', () => { await unDelegateWallet(wallet); - const poolPubKey = wallet1.bip32Account.derivePublicKey({ + const poolPubKey = await wallet1.bip32Account.derivePublicKey({ index: 0, role: KeyRole.External }); const poolKeyHash = bip32Ed25519.getPubKeyHash(poolPubKey); const poolId = Cardano.PoolId.fromKeyHash(poolKeyHash); - const poolRewardAccount = wallet1.bip32Account.deriveAddress( - { - index: 0, - type: AddressType.External - }, - 0 + const poolRewardAccount = ( + await wallet1.bip32Account.deriveAddress( + { + index: 0, + type: AddressType.External + }, + 0 + ) ).rewardAccount; const registrationCert: Cardano.PoolRegistrationCertificate = { @@ -167,19 +169,21 @@ describe('local-network/register-pool', () => { await walletReady(wallet); await unDelegateWallet(wallet); - const poolPubKey = wallet2.bip32Account.derivePublicKey({ + const poolPubKey = await wallet2.bip32Account.derivePublicKey({ index: 0, role: KeyRole.External }); const poolKeyHash = bip32Ed25519.getPubKeyHash(poolPubKey); const poolId = Cardano.PoolId.fromKeyHash(poolKeyHash); - const poolRewardAccount = wallet2.bip32Account.deriveAddress( - { - index: 0, - type: AddressType.External - }, - 0 + const poolRewardAccount = ( + await wallet2.bip32Account.deriveAddress( + { + index: 0, + type: AddressType.External + }, + 0 + ) ).rewardAccount; const registrationCert: Cardano.PoolRegistrationCertificate = { diff --git a/packages/e2e/test/long-running/cache-invalidation.test.ts b/packages/e2e/test/long-running/cache-invalidation.test.ts index cefa3d29130..659359387bc 100644 --- a/packages/e2e/test/long-running/cache-invalidation.test.ts +++ b/packages/e2e/test/long-running/cache-invalidation.test.ts @@ -107,19 +107,21 @@ describe('cache invalidation', () => { await walletReady(wallet); - const poolPubKey = wallet1.bip32Account.derivePublicKey({ + const poolPubKey = await wallet1.bip32Account.derivePublicKey({ index: 0, role: KeyRole.External }); const poolKeyHash = bip32Ed25519.getPubKeyHash(poolPubKey); const poolId = Cardano.PoolId.fromKeyHash(poolKeyHash); - const poolRewardAccount = wallet1.bip32Account.deriveAddress( - { - index: 0, - type: AddressType.External - }, - 0 + const poolRewardAccount = ( + await wallet1.bip32Account.deriveAddress( + { + index: 0, + type: AddressType.External + }, + 0 + ) ).rewardAccount; const registrationCert: Cardano.PoolRegistrationCertificate = { diff --git a/packages/e2e/test/wallet_epoch_0/PersonalWallet/cip30WalletApi.test.ts b/packages/e2e/test/wallet_epoch_0/PersonalWallet/cip30WalletApi.test.ts index e7e4383aa95..80d86a95f7d 100644 --- a/packages/e2e/test/wallet_epoch_0/PersonalWallet/cip30WalletApi.test.ts +++ b/packages/e2e/test/wallet_epoch_0/PersonalWallet/cip30WalletApi.test.ts @@ -69,7 +69,7 @@ describe('PersonalWallet/cip30WalletApi', () => { it('can signData with bech32 base address', async () => { const [{ address, index }] = await firstValueFrom(wallet.addresses$); - const paymentKeyHex = await bip32Account.derivePublicKey({ index, role: KeyRole.External }); + const paymentKeyHex = bip32Account.derivePublicKey({ index, role: KeyRole.External }); const signature = await walletApi.signData({ sender: '' } as unknown as SenderContext, address, HexBlob('abc123')); @@ -79,7 +79,7 @@ describe('PersonalWallet/cip30WalletApi', () => { it('can signData with hex-encoded base address', async () => { const [{ address, index }] = await firstValueFrom(wallet.addresses$); const addressHex = Cardano.Address.fromBech32(address).toBytes(); - const paymentKeyHex = await bip32Account.derivePublicKey({ index, role: KeyRole.External }); + const paymentKeyHex = bip32Account.derivePublicKey({ index, role: KeyRole.External }); const signature = await walletApi.signData( { sender: '' } as unknown as SenderContext, @@ -92,7 +92,7 @@ describe('PersonalWallet/cip30WalletApi', () => { it('can signData with bech32 base address', async () => { const [{ rewardAccount, index }] = await firstValueFrom(wallet.addresses$); - const stakeKeyHex = await bip32Account.derivePublicKey({ index, role: KeyRole.Stake }); + const stakeKeyHex = bip32Account.derivePublicKey({ index, role: KeyRole.Stake }); const signature = await walletApi.signData( { sender: '' } as unknown as SenderContext, @@ -106,7 +106,7 @@ describe('PersonalWallet/cip30WalletApi', () => { it('can signData with hex-encoded reward account', async () => { const [{ rewardAccount, index }] = await firstValueFrom(wallet.addresses$); const rewardAccountHex = Cardano.Address.fromBech32(rewardAccount).toBytes(); - const stakeKeyHex = await bip32Account.derivePublicKey({ index, role: KeyRole.Stake }); + const stakeKeyHex = bip32Account.derivePublicKey({ index, role: KeyRole.Stake }); const signature = await walletApi.signData( { sender: '' } as unknown as SenderContext, diff --git a/packages/key-management/src/Bip32Account.ts b/packages/key-management/src/Bip32Account.ts index f335dd9b180..1e5ee16082f 100644 --- a/packages/key-management/src/Bip32Account.ts +++ b/packages/key-management/src/Bip32Account.ts @@ -47,7 +47,7 @@ export class Bip32Account { this.accountIndex = accountIndex; } - derivePublicKey(derivationPath: AccountKeyDerivationPath) { + async derivePublicKey(derivationPath: AccountKeyDerivationPath) { const extendedKey = this.#bip32Ed25519.derivePublicKey(this.extendedAccountPublicKeyHex, [ derivationPath.role, derivationPath.index @@ -55,23 +55,23 @@ export class Bip32Account { return Ed25519PublicKeyHex.fromBip32PublicKey(extendedKey); } - deriveAddress( + async deriveAddress( paymentKeyDerivationPath: AccountAddressDerivationPath, stakeKeyDerivationIndex: number - ): GroupedAddress { + ): Promise { const stakeKeyDerivationPath = { index: stakeKeyDerivationIndex, role: KeyRole.Stake }; - const derivedPublicPaymentKey = this.derivePublicKey({ + const derivedPublicPaymentKey = await this.derivePublicKey({ index: paymentKeyDerivationPath.index, role: Number(paymentKeyDerivationPath.type) }); const derivedPublicPaymentKeyHash = this.#blake2b.hash(derivedPublicPaymentKey, BIP32_PUBLIC_KEY_HASH_LENGTH); - const publicStakeKey = this.derivePublicKey(stakeKeyDerivationPath); + const publicStakeKey = await this.derivePublicKey(stakeKeyDerivationPath); const publicStakeKeyHash = this.#blake2b.hash(publicStakeKey, BIP32_PUBLIC_KEY_HASH_LENGTH); const stakeCredential = { hash: publicStakeKeyHash, type: Cardano.CredentialType.KeyHash }; diff --git a/packages/key-management/test/Bip32Account.test.ts b/packages/key-management/test/Bip32Account.test.ts index 171e87a585c..500540c7489 100644 --- a/packages/key-management/test/Bip32Account.test.ts +++ b/packages/key-management/test/Bip32Account.test.ts @@ -83,7 +83,7 @@ describe('Bip32Account', () => { [4, '4444444444444444444444444444444444444444444444444444444444444444'] ]); - testnetAccount.derivePublicKey = jest.fn((x: AccountKeyDerivationPath) => + testnetAccount.derivePublicKey = jest.fn(async (x: AccountKeyDerivationPath) => Crypto.Ed25519PublicKeyHex(keyMap.get(x.index)!) ); diff --git a/packages/tx-construction/src/tx-builder/initializeTx.ts b/packages/tx-construction/src/tx-builder/initializeTx.ts index ec01dfea8f4..428407d68e2 100644 --- a/packages/tx-construction/src/tx-builder/initializeTx.ts +++ b/packages/tx-construction/src/tx-builder/initializeTx.ts @@ -12,7 +12,9 @@ import { hasCorrectVoteDelegation } from './hasCorrectVoteDelegation'; const dRepPublicKeyHash = async (addressManager?: Bip32Account): Promise => addressManager && - Ed25519PublicKey.fromHex(addressManager.derivePublicKey(util.DREP_KEY_DERIVATION_PATH)).hash().hex(); + Ed25519PublicKey.fromHex(await addressManager.derivePublicKey(util.DREP_KEY_DERIVATION_PATH)) + .hash() + .hex(); const DREP_REG_REQUIRED_PROTOCOL_VERSION = 10; diff --git a/packages/wallet/src/services/PublicStakeKeysTracker.ts b/packages/wallet/src/services/PublicStakeKeysTracker.ts index f2619f7d9b5..5dd22071ac2 100644 --- a/packages/wallet/src/services/PublicStakeKeysTracker.ts +++ b/packages/wallet/src/services/PublicStakeKeysTracker.ts @@ -1,7 +1,7 @@ import { AccountKeyDerivationPath, Bip32Account, GroupedAddress } from '@cardano-sdk/key-management'; import { Cardano } from '@cardano-sdk/core'; import { Ed25519PublicKeyHex } from '@cardano-sdk/crypto'; -import { Observable, distinctUntilChanged, map, switchMap } from 'rxjs'; +import { Observable, defaultIfEmpty, distinctUntilChanged, forkJoin, from, map, mergeMap, switchMap } from 'rxjs'; import { TrackerSubject } from '@cardano-sdk/util-rxjs'; import { deepEquals } from '@cardano-sdk/util'; @@ -48,11 +48,14 @@ export const createPublicStakeKeysTracker = ({ new TrackerSubject( rewardAccounts$.pipe( withStakeKeyDerivationPaths(addresses$), - map((derivationPathsAndStatus) => - derivationPathsAndStatus.map(({ stakeKeyDerivationPath, credentialStatus }) => ({ - credentialStatus, - publicStakeKey: addressManager.derivePublicKey(stakeKeyDerivationPath) - })) + mergeMap((derivationPathsAndStatus) => + forkJoin( + derivationPathsAndStatus.map(({ stakeKeyDerivationPath, credentialStatus }) => + from(addressManager.derivePublicKey(stakeKeyDerivationPath)).pipe( + map((publicStakeKey) => ({ credentialStatus, publicStakeKey })) + ) + ) + ).pipe(defaultIfEmpty([])) ), distinctUntilChanged(deepEquals) ) diff --git a/packages/wallet/test/PersonalWallet/methods.test.ts b/packages/wallet/test/PersonalWallet/methods.test.ts index 8a675c21fae..f2a056d560d 100644 --- a/packages/wallet/test/PersonalWallet/methods.test.ts +++ b/packages/wallet/test/PersonalWallet/methods.test.ts @@ -107,7 +107,7 @@ describe('BaseWallet methods', () => { const asyncKeyAgent = await testAsyncKeyAgent(); bip32Account = await Bip32Account.fromAsyncKeyAgent(asyncKeyAgent); - bip32Account.deriveAddress = jest.fn().mockReturnValue(groupedAddress); + bip32Account.deriveAddress = jest.fn().mockResolvedValue(groupedAddress); witnesser = util.createBip32Ed25519Witnesser(asyncKeyAgent); wallet = createPersonalWallet( { name: 'Test Wallet' }, @@ -671,12 +671,7 @@ describe('BaseWallet methods', () => { it('will retry deriving pubDrepKey if one does not exist', async () => { wallet.shutdown(); - bip32Account.derivePublicKey = jest - .fn() - .mockImplementationOnce(() => { - throw new Error('error'); - }) - .mockReturnValue('string'); + bip32Account.derivePublicKey = jest.fn().mockRejectedValueOnce('error').mockResolvedValue('string'); wallet = createPersonalWallet( { name: 'Test Wallet' }, { @@ -819,7 +814,7 @@ describe('BaseWallet methods', () => { beforeEach(() => { wallet.shutdown(); - bip32Account.deriveAddress = jest.fn((args) => { + bip32Account.deriveAddress = jest.fn(async (args) => { if (args.index === 0) { return groupedAddress; } diff --git a/packages/wallet/test/services/PublicStakeKeysTracker.test.ts b/packages/wallet/test/services/PublicStakeKeysTracker.test.ts index 71caf6a1b14..4be2a4c60f6 100644 --- a/packages/wallet/test/services/PublicStakeKeysTracker.test.ts +++ b/packages/wallet/test/services/PublicStakeKeysTracker.test.ts @@ -2,7 +2,7 @@ import { AccountKeyDerivationPath, Bip32Account, GroupedAddress, KeyRole } from import { Cardano } from '@cardano-sdk/core'; import { ObservableWallet } from '../../src'; import { PubStakeKeyAndStatus, createPublicStakeKeysTracker } from '../../src/services/PublicStakeKeysTracker'; -import { delay, firstValueFrom, from, lastValueFrom, of, shareReplay, toArray } from 'rxjs'; +import { firstValueFrom, from, lastValueFrom, of, shareReplay, toArray } from 'rxjs'; import { mockProviders as mocks } from '@cardano-sdk/util-dev'; describe('PublicStakeKeysTracker', () => { @@ -64,7 +64,9 @@ describe('PublicStakeKeysTracker', () => { } ]; - derivePublicKey = jest.fn().mockImplementation((path: AccountKeyDerivationPath) => `abc-${path.index}`); + derivePublicKey = jest + .fn() + .mockImplementation((path: AccountKeyDerivationPath) => Promise.resolve(`abc-${path.index}`)); bip32Account = { accountIndex: 0, chainId: Cardano.ChainIds.Preview, @@ -135,7 +137,7 @@ describe('PublicStakeKeysTracker', () => { it('emits when reward accounts change', async () => { const addresses$ = of(addresses); - const rewardAccounts$ = from([[rewardAccounts[0]], rewardAccounts]).pipe(delay(1)); + const rewardAccounts$ = from([[rewardAccounts[0]], rewardAccounts]); const stakePubKeys$ = createPublicStakeKeysTracker({ addresses$, @@ -155,7 +157,7 @@ describe('PublicStakeKeysTracker', () => { }); it('emits when addresses change', async () => { - const addresses$ = from([[addresses[0]], addresses]).pipe(delay(1)); + const addresses$ = from([[addresses[0]], addresses]); const rewardAccounts$ = of(rewardAccounts); const stakePubKeys$ = createPublicStakeKeysTracker({ @@ -176,9 +178,8 @@ describe('PublicStakeKeysTracker', () => { }); it('does not emit duplicates', async () => { - const rewardAccounts$ = from([rewardAccounts, rewardAccounts]).pipe(delay(1)); + const rewardAccounts$ = from([rewardAccounts, rewardAccounts]); const addresses$ = from([[addresses[0]], addresses, addresses]).pipe( - delay(1), shareReplay({ bufferSize: 1, refCount: true }) ); From 1a0091896f248749121feb4a3e8cbbcd6f503605 Mon Sep 17 00:00:00 2001 From: Angel Castillo Date: Thu, 12 Jun 2025 16:09:50 +0800 Subject: [PATCH 2/3] feat!: add hashAsync and derivePublicKeyAsync variants to Blake2b and Bip32Ed25519 --- packages/crypto/src/Bip32Ed25519.ts | 9 ++++++++ packages/crypto/src/blake2b-hash.ts | 13 ++++++++++++ .../crypto/src/strategies/CmlBip32Ed25519.ts | 11 ++++++++++ .../src/strategies/SodiumBip32Ed25519.ts | 11 ++++++++++ .../PersonalWallet/cip30WalletApi.test.ts | 8 +++---- packages/key-management/src/Bip32Account.ts | 21 ++++++++++++------- 6 files changed, 62 insertions(+), 11 deletions(-) diff --git a/packages/crypto/src/Bip32Ed25519.ts b/packages/crypto/src/Bip32Ed25519.ts index 55fc0a72273..5607ffb355f 100644 --- a/packages/crypto/src/Bip32Ed25519.ts +++ b/packages/crypto/src/Bip32Ed25519.ts @@ -82,6 +82,15 @@ export interface Bip32Ed25519 { */ derivePublicKey(parentKey: Bip32PublicKeyHex, derivationIndices: BIP32Path): Bip32PublicKeyHex; + /** + * Given a parent extended key and a set of indices, this function computes the corresponding child extended key. + * + * @param parentKey The parent extended key. + * @param derivationIndices The list of derivation indices. + * @returns A promise returning the child extended public key. + */ + derivePublicKeyAsync(parentKey: Bip32PublicKeyHex, derivationIndices: BIP32Path): Promise; + /** * Generates an Ed25519 signature using an extended private key. * diff --git a/packages/crypto/src/blake2b-hash.ts b/packages/crypto/src/blake2b-hash.ts index 0ab608a6942..e3e2c294502 100644 --- a/packages/crypto/src/blake2b-hash.ts +++ b/packages/crypto/src/blake2b-hash.ts @@ -22,10 +22,23 @@ export interface Blake2b { * @param outputLengthBytes digest size, e.g. 28 for blake2b-224 or 32 for blake2b-256 */ hash(message: HexBlob, outputLengthBytes: number): T; + + /** + * @param message payload to hash + * @param outputLengthBytes digest size, e.g. 28 for blake2b-224 or 32 for blake2b-256 + */ + hashAsync(message: HexBlob, outputLengthBytes: number): Promise; } export const blake2b: Blake2b = { hash(message: HexBlob, outputLengthBytes: number) { return hash(outputLengthBytes).update(hexStringToBuffer(message)).digest('hex') as T; + }, + async hashAsync(message: HexBlob, outputLengthBytes: number): Promise { + return new Promise((resolve) => { + setImmediate(() => { + resolve(blake2b.hash(message, outputLengthBytes)); + }); + }); } }; diff --git a/packages/crypto/src/strategies/CmlBip32Ed25519.ts b/packages/crypto/src/strategies/CmlBip32Ed25519.ts index d83aa0837e2..71da4c03091 100644 --- a/packages/crypto/src/strategies/CmlBip32Ed25519.ts +++ b/packages/crypto/src/strategies/CmlBip32Ed25519.ts @@ -100,6 +100,17 @@ export class CmlBip32Ed25519 implements Bip32Ed25519 { }); } + public async derivePublicKeyAsync( + parentKey: Bip32PublicKeyHex, + derivationIndices: BIP32Path + ): Promise { + return new Promise((resolve) => { + setImmediate(() => { + resolve(this.derivePublicKey(parentKey, derivationIndices)); + }); + }); + } + public sign( privateKey: Ed25519PrivateExtendedKeyHex | Ed25519PrivateNormalKeyHex, message: HexBlob diff --git a/packages/crypto/src/strategies/SodiumBip32Ed25519.ts b/packages/crypto/src/strategies/SodiumBip32Ed25519.ts index 38261b2ca18..90b22be9f1f 100644 --- a/packages/crypto/src/strategies/SodiumBip32Ed25519.ts +++ b/packages/crypto/src/strategies/SodiumBip32Ed25519.ts @@ -70,6 +70,17 @@ export class SodiumBip32Ed25519 implements Bip32Ed25519 { return pubKey.derive(derivationIndices).hex(); } + public async derivePublicKeyAsync( + parentKey: Bip32PublicKeyHex, + derivationIndices: BIP32Path + ): Promise { + return new Promise((resolve) => { + setImmediate(() => { + resolve(this.derivePublicKey(parentKey, derivationIndices)); + }); + }); + } + public sign( privateKey: Ed25519PrivateExtendedKeyHex | Ed25519PrivateNormalKeyHex, message: HexBlob diff --git a/packages/e2e/test/wallet_epoch_0/PersonalWallet/cip30WalletApi.test.ts b/packages/e2e/test/wallet_epoch_0/PersonalWallet/cip30WalletApi.test.ts index 80d86a95f7d..e7e4383aa95 100644 --- a/packages/e2e/test/wallet_epoch_0/PersonalWallet/cip30WalletApi.test.ts +++ b/packages/e2e/test/wallet_epoch_0/PersonalWallet/cip30WalletApi.test.ts @@ -69,7 +69,7 @@ describe('PersonalWallet/cip30WalletApi', () => { it('can signData with bech32 base address', async () => { const [{ address, index }] = await firstValueFrom(wallet.addresses$); - const paymentKeyHex = bip32Account.derivePublicKey({ index, role: KeyRole.External }); + const paymentKeyHex = await bip32Account.derivePublicKey({ index, role: KeyRole.External }); const signature = await walletApi.signData({ sender: '' } as unknown as SenderContext, address, HexBlob('abc123')); @@ -79,7 +79,7 @@ describe('PersonalWallet/cip30WalletApi', () => { it('can signData with hex-encoded base address', async () => { const [{ address, index }] = await firstValueFrom(wallet.addresses$); const addressHex = Cardano.Address.fromBech32(address).toBytes(); - const paymentKeyHex = bip32Account.derivePublicKey({ index, role: KeyRole.External }); + const paymentKeyHex = await bip32Account.derivePublicKey({ index, role: KeyRole.External }); const signature = await walletApi.signData( { sender: '' } as unknown as SenderContext, @@ -92,7 +92,7 @@ describe('PersonalWallet/cip30WalletApi', () => { it('can signData with bech32 base address', async () => { const [{ rewardAccount, index }] = await firstValueFrom(wallet.addresses$); - const stakeKeyHex = bip32Account.derivePublicKey({ index, role: KeyRole.Stake }); + const stakeKeyHex = await bip32Account.derivePublicKey({ index, role: KeyRole.Stake }); const signature = await walletApi.signData( { sender: '' } as unknown as SenderContext, @@ -106,7 +106,7 @@ describe('PersonalWallet/cip30WalletApi', () => { it('can signData with hex-encoded reward account', async () => { const [{ rewardAccount, index }] = await firstValueFrom(wallet.addresses$); const rewardAccountHex = Cardano.Address.fromBech32(rewardAccount).toBytes(); - const stakeKeyHex = bip32Account.derivePublicKey({ index, role: KeyRole.Stake }); + const stakeKeyHex = await bip32Account.derivePublicKey({ index, role: KeyRole.Stake }); const signature = await walletApi.signData( { sender: '' } as unknown as SenderContext, diff --git a/packages/key-management/src/Bip32Account.ts b/packages/key-management/src/Bip32Account.ts index 1e5ee16082f..43d82e440b3 100644 --- a/packages/key-management/src/Bip32Account.ts +++ b/packages/key-management/src/Bip32Account.ts @@ -23,8 +23,8 @@ type Bip32AccountProps = { }; export type Bip32AccountDependencies = { - bip32Ed25519: Pick; - blake2b: Blake2b; + bip32Ed25519: Pick; + blake2b: Pick; }; /** Derives public keys and addresses from a BIP32-ED25519 public key */ @@ -33,7 +33,7 @@ export class Bip32Account { readonly chainId: Cardano.ChainId; readonly accountIndex: number; readonly #bip32Ed25519: Bip32AccountDependencies['bip32Ed25519']; - readonly #blake2b: Blake2b; + readonly #blake2b: Bip32AccountDependencies['blake2b']; /** Initializes a new instance of the Bip32Ed25519AddressManager class. */ constructor( @@ -47,8 +47,8 @@ export class Bip32Account { this.accountIndex = accountIndex; } - async derivePublicKey(derivationPath: AccountKeyDerivationPath) { - const extendedKey = this.#bip32Ed25519.derivePublicKey(this.extendedAccountPublicKeyHex, [ + async derivePublicKey(derivationPath: AccountKeyDerivationPath): Promise { + const extendedKey = await this.#bip32Ed25519.derivePublicKeyAsync(this.extendedAccountPublicKeyHex, [ derivationPath.role, derivationPath.index ]); @@ -69,10 +69,16 @@ export class Bip32Account { role: Number(paymentKeyDerivationPath.type) }); - const derivedPublicPaymentKeyHash = this.#blake2b.hash(derivedPublicPaymentKey, BIP32_PUBLIC_KEY_HASH_LENGTH); + const derivedPublicPaymentKeyHash = (await this.#blake2b.hashAsync( + derivedPublicPaymentKey, + BIP32_PUBLIC_KEY_HASH_LENGTH + )) as Crypto.Hash28ByteBase16; const publicStakeKey = await this.derivePublicKey(stakeKeyDerivationPath); - const publicStakeKeyHash = this.#blake2b.hash(publicStakeKey, BIP32_PUBLIC_KEY_HASH_LENGTH); + const publicStakeKeyHash = (await this.#blake2b.hashAsync( + publicStakeKey, + BIP32_PUBLIC_KEY_HASH_LENGTH + )) as Crypto.Hash28ByteBase16; const stakeCredential = { hash: publicStakeKeyHash, type: Cardano.CredentialType.KeyHash }; @@ -105,6 +111,7 @@ export class Bip32Account { * Creates a new instance of the Bip32Ed25519AddressManager class. * * @param keyAgent The key agent that will be used to derive addresses. + * @param dependencies Optional dependencies for the Bip32Account. If not provided, default dependencies will be created. */ static async fromAsyncKeyAgent( keyAgent: AsyncKeyAgent, From 97c3adce7400016a891cb5b645a517cdb3ff3b61 Mon Sep 17 00:00:00 2001 From: Angel Castillo Date: Thu, 12 Jun 2025 21:12:06 +0800 Subject: [PATCH 3/3] test: disable KoraLabsHandleProvider flaky tests --- packages/e2e/test/handle/KoraLabsHandleProvider.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/e2e/test/handle/KoraLabsHandleProvider.test.ts b/packages/e2e/test/handle/KoraLabsHandleProvider.test.ts index 7b06b3e8a5d..1e3aec01d21 100644 --- a/packages/e2e/test/handle/KoraLabsHandleProvider.test.ts +++ b/packages/e2e/test/handle/KoraLabsHandleProvider.test.ts @@ -26,7 +26,8 @@ const checkHandleResolution = (source: string, result: unknown) => { expect(['string', 'undefined']).toContain(typeof profilePic); }; -describe('KoraLabsHandleProvider', () => { +// Fix flaky tests LW-13058 +describe.skip('KoraLabsHandleProvider', () => { let provider: KoraLabsHandleProvider; beforeAll(() => {