Skip to content

Commit 0d664a6

Browse files
fixup! feat!: remove async from crypto API
1 parent dfc1811 commit 0d664a6

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

packages/crypto/src/Bip32/Bip32PrivateKey.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ export class Bip32PrivateKey {
7171
* - 32 bytes: Ed25519 curve scalar from which few bits have been tweaked according to ED25519-BIP32
7272
* - 32 bytes: Ed25519 binary blob used as IV for signing
7373
*
74+
* NOTE: You must call `Crypto.ready()` at least once before calling this function.
75+
*
7476
* @param entropy Random stream of bytes generated from a BIP39 seed phrase.
7577
* @param password The second factor authentication password for the mnemonic phrase.
7678
* @returns The secret extended key.
@@ -123,6 +125,8 @@ export class Bip32PrivateKey {
123125
* This is why deriving the private key should not fail while deriving
124126
* the public key may fail (if the derivation index is invalid).
125127
*
128+
* NOTE: You must call `Crypto.ready()` at least once before calling this function.
129+
*
126130
* @param derivationIndices The derivation indices.
127131
* @returns The child BIP-32 key.
128132
*/
@@ -144,6 +148,8 @@ export class Bip32PrivateKey {
144148
/**
145149
* Computes the BIP-32 public key from this BIP-32 private key.
146150
*
151+
* NOTE: You must call `Crypto.ready()` at least once before calling this function.
152+
*
147153
* @returns the public key.
148154
*/
149155
toPublic(): Bip32PublicKey {

packages/crypto/src/Bip32/Bip32PublicKey.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export class Bip32PublicKey {
5353
/**
5454
* Given a set of indices, this function computes the corresponding child extended key.
5555
*
56+
* NOTE: You must call `Crypto.ready()` at least once before calling this function.
57+
*
5658
* @param derivationIndices The list of derivation indices.
5759
* @returns The child extended private key.
5860
*/
@@ -76,7 +78,7 @@ export class Bip32PublicKey {
7678
return Bip32PublicKeyHex(Buffer.from(this.#key).toString('hex'));
7779
}
7880

79-
/** Gets the blake2 hash of the key. */
81+
/** Gets the blake2 hash of the key. NOTE: You must call `Crypto.ready()` at least once before calling this function. */
8082
hash(): Bip32PublicKeyHashHex {
8183
const hash = sodium.crypto_generichash(BIP32_PUBLIC_KEY_HASH_LENGTH, this.#key);
8284
return Bip32PublicKeyHashHex(Buffer.from(hash).toString('hex'));

packages/crypto/src/Ed25519e/Ed25519PrivateKey.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ export class Ed25519PrivateKey {
7878
/**
7979
* Computes the raw public key from this raw private key.
8080
*
81+
* NOTE: You must call `Crypto.ready()` at least once before calling this function.
82+
*
8183
* @returns the public key.
8284
*/
8385
toPublic(): Ed25519PublicKey {
@@ -91,6 +93,8 @@ export class Ed25519PrivateKey {
9193
/**
9294
* Generates an Ed25519 signature.
9395
*
96+
* NOTE: You must call `Crypto.ready()` at least once before calling this function.
97+
*
9498
* @param message The message to be signed.
9599
* @returns The Ed25519 digital signature.
96100
*/

packages/crypto/src/Ed25519e/Ed25519PublicKey.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export class Ed25519PublicKey {
2626
* Verifies that the passed-in signature was generated with a private key that matches
2727
* the given public key.
2828
*
29+
* NOTE: You must call `Crypto.ready()` at least once before calling this function.
30+
*
2931
* @param signature The signature bytes to be verified.
3032
* @param message The original message the signature was computed from.
3133
* @returns true if the signature is valid; otherwise; false.
@@ -57,7 +59,7 @@ export class Ed25519PublicKey {
5759
return Ed25519PublicKey.fromBytes(Buffer.from(keyMaterial, 'hex'));
5860
}
5961

60-
/** Gets the blake2 hash of the key material. */
62+
/** Gets the blake2 hash of the key material. NOTE: You must call `Crypto.ready()` at least once before calling this function. */
6163
hash(): Ed25519KeyHash {
6264
const hash = sodium.crypto_generichash(ED25519_PUBLIC_KEY_HASH_LENGTH, this.#keyMaterial);
6365
return Ed25519KeyHash.fromBytes(hash);

packages/crypto/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export * from './strategies';
99
export * from './hexTypes';
1010
export * from './types';
1111

12+
/** This function must be called before any other function in this module. it is safe to call this function multiple times. */
1213
export const ready = async (): Promise<void> => await sodium.ready;

0 commit comments

Comments
 (0)