@@ -23,8 +23,8 @@ type Bip32AccountProps = {
23
23
} ;
24
24
25
25
export type Bip32AccountDependencies = {
26
- bip32Ed25519 : Pick < Bip32Ed25519 , 'derivePublicKey ' > ;
27
- blake2b : Blake2b ;
26
+ bip32Ed25519 : Pick < Bip32Ed25519 , 'derivePublicKeyAsync ' > ;
27
+ blake2b : Pick < Blake2b , 'hashAsync' > ;
28
28
} ;
29
29
30
30
/** Derives public keys and addresses from a BIP32-ED25519 public key */
@@ -33,7 +33,7 @@ export class Bip32Account {
33
33
readonly chainId : Cardano . ChainId ;
34
34
readonly accountIndex : number ;
35
35
readonly #bip32Ed25519: Bip32AccountDependencies [ 'bip32Ed25519' ] ;
36
- readonly #blake2b: Blake2b ;
36
+ readonly #blake2b: Bip32AccountDependencies [ 'blake2b' ] ;
37
37
38
38
/** Initializes a new instance of the Bip32Ed25519AddressManager class. */
39
39
constructor (
@@ -47,32 +47,38 @@ export class Bip32Account {
47
47
this . accountIndex = accountIndex ;
48
48
}
49
49
50
- derivePublicKey ( derivationPath : AccountKeyDerivationPath ) {
51
- const extendedKey = this . #bip32Ed25519. derivePublicKey ( this . extendedAccountPublicKeyHex , [
50
+ async derivePublicKey ( derivationPath : AccountKeyDerivationPath ) : Promise < Crypto . Ed25519PublicKeyHex > {
51
+ const extendedKey = await this . #bip32Ed25519. derivePublicKeyAsync ( this . extendedAccountPublicKeyHex , [
52
52
derivationPath . role ,
53
53
derivationPath . index
54
54
] ) ;
55
55
return Ed25519PublicKeyHex . fromBip32PublicKey ( extendedKey ) ;
56
56
}
57
57
58
- deriveAddress (
58
+ async deriveAddress (
59
59
paymentKeyDerivationPath : AccountAddressDerivationPath ,
60
60
stakeKeyDerivationIndex : number
61
- ) : GroupedAddress {
61
+ ) : Promise < GroupedAddress > {
62
62
const stakeKeyDerivationPath = {
63
63
index : stakeKeyDerivationIndex ,
64
64
role : KeyRole . Stake
65
65
} ;
66
66
67
- const derivedPublicPaymentKey = this . derivePublicKey ( {
67
+ const derivedPublicPaymentKey = await this . derivePublicKey ( {
68
68
index : paymentKeyDerivationPath . index ,
69
69
role : Number ( paymentKeyDerivationPath . type )
70
70
} ) ;
71
71
72
- const derivedPublicPaymentKeyHash = this . #blake2b. hash ( derivedPublicPaymentKey , BIP32_PUBLIC_KEY_HASH_LENGTH ) ;
72
+ const derivedPublicPaymentKeyHash = ( await this . #blake2b. hashAsync (
73
+ derivedPublicPaymentKey ,
74
+ BIP32_PUBLIC_KEY_HASH_LENGTH
75
+ ) ) as Crypto . Hash28ByteBase16 ;
73
76
74
- const publicStakeKey = this . derivePublicKey ( stakeKeyDerivationPath ) ;
75
- const publicStakeKeyHash = this . #blake2b. hash ( publicStakeKey , BIP32_PUBLIC_KEY_HASH_LENGTH ) ;
77
+ const publicStakeKey = await this . derivePublicKey ( stakeKeyDerivationPath ) ;
78
+ const publicStakeKeyHash = ( await this . #blake2b. hashAsync (
79
+ publicStakeKey ,
80
+ BIP32_PUBLIC_KEY_HASH_LENGTH
81
+ ) ) as Crypto . Hash28ByteBase16 ;
76
82
77
83
const stakeCredential = { hash : publicStakeKeyHash , type : Cardano . CredentialType . KeyHash } ;
78
84
@@ -105,6 +111,7 @@ export class Bip32Account {
105
111
* Creates a new instance of the Bip32Ed25519AddressManager class.
106
112
*
107
113
* @param keyAgent The key agent that will be used to derive addresses.
114
+ * @param dependencies Optional dependencies for the Bip32Account. If not provided, default dependencies will be created.
108
115
*/
109
116
static async fromAsyncKeyAgent (
110
117
keyAgent : AsyncKeyAgent ,
0 commit comments