From e2407acd14dab64694d978563db7577ea5c00d38 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 4 Jul 2025 01:32:07 -0700 Subject: [PATCH] Remove references to CryptoKey which is no longer accepted as a parameter for creating wallets. --- README.md | 4 ++-- src/lib/wallets/bip44-wallet.ts | 30 +++++++++++++++--------------- src/lib/wallets/blake2b-wallet.ts | 22 +++++++++++----------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 8a10272..78c427b 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,8 @@ For clarity, the following terms are used throughout the library: libnemo is able to generate and import HD and BLAKE2b wallets, and it can derive accounts for both. An HD wallet seed is 128 characters while a BLAKE2b wallet seed is 64 characters. For enhanced security, libnemo requires a password to -create or import wallets, and wallets are initialized in a locked state. More -advanced implementations can provide their own CryptoKey instead of a password. +create or import wallets, and wallets are initialized in a locked state. +Implementations can provide their own Uint8Array bytes instead of a password. Refer to the documentation on each class factory method for specific usage. ```javascript diff --git a/src/lib/wallets/bip44-wallet.ts b/src/lib/wallets/bip44-wallet.ts index 45bd381..8d72ca9 100644 --- a/src/lib/wallets/bip44-wallet.ts +++ b/src/lib/wallets/bip44-wallet.ts @@ -65,12 +65,12 @@ export class Bip44Wallet extends Wallet { * Creates a new HD wallet by using an entropy value generated using a * cryptographically strong pseudorandom number generator. * - * @param {CryptoKey} key - Encrypts the wallet to lock and unlock it + * @param {Uint8Array} key - Encrypts the wallet to lock and unlock it * @param {string} [salt=''] - Used when generating the final seed * @returns {Bip44Wallet} A newly instantiated Bip44Wallet */ - static async create (key: CryptoKey, salt?: string): Promise - static async create (passkey: string | CryptoKey, salt: string = ''): Promise { + static async create (key: Uint8Array, salt?: string): Promise + static async create (passkey: string | Uint8Array, salt: string = ''): Promise { try { const e = await Entropy.create() return await Bip44Wallet.fromEntropy(passkey as string, e.hex, salt) @@ -93,13 +93,13 @@ export class Bip44Wallet extends Wallet { * Creates a new HD wallet by using a pregenerated entropy value. The user * must ensure that it is cryptographically strongly random. * - * @param {CryptoKey} key - Used to lock and unlock the wallet + * @param {Uint8Array} key - Used to lock and unlock the wallet * @param {string} entropy - Used when generating the initial mnemonic phrase * @param {string} [salt=''] - Used when generating the final seed * @returns {Bip44Wallet} A newly instantiated Bip44Wallet */ - static async fromEntropy (key: CryptoKey, entropy: string, salt?: string): Promise - static async fromEntropy (passkey: string | CryptoKey, entropy: string, salt: string = ''): Promise { + static async fromEntropy (key: Uint8Array, entropy: string, salt?: string): Promise + static async fromEntropy (passkey: string | Uint8Array, entropy: string, salt: string = ''): Promise { try { const id = await Entropy.create(16) const e = await Entropy.import(entropy) @@ -107,7 +107,7 @@ export class Bip44Wallet extends Wallet { const s = await m.toBip39Seed(salt) Bip44Wallet.#isInternal = true const wallet = new this(id, s, m) - await wallet.lock(passkey as string) + await wallet.lock(passkey) return wallet } catch (err) { throw new Error(`Error importing Bip44Wallet from entropy: ${err}`) @@ -126,20 +126,20 @@ export class Bip44Wallet extends Wallet { /** * Creates a new HD wallet by using a pregenerated mnemonic phrase. * - * @param {CryptoKey} key - Used to lock and unlock the wallet + * @param {Uint8Array} key - Used to lock and unlock the wallet * @param {string} mnemonic - Used when generating the final seed * @param {string} [salt=''] - Used when generating the final seed * @returns {Bip44Wallet} A newly instantiated Bip44Wallet */ - static async fromMnemonic (key: CryptoKey, mnemonic: string, salt?: string): Promise - static async fromMnemonic (passkey: string | CryptoKey, mnemonic: string, salt: string = ''): Promise { + static async fromMnemonic (key: Uint8Array, mnemonic: string, salt?: string): Promise + static async fromMnemonic (passkey: string | Uint8Array, mnemonic: string, salt: string = ''): Promise { try { const id = await Entropy.create(16) const m = await Bip39Mnemonic.fromPhrase(mnemonic) const s = await m.toBip39Seed(salt) Bip44Wallet.#isInternal = true const wallet = new this(id, s, m) - await wallet.lock(passkey as string) + await wallet.lock(passkey) return wallet } catch (err) { throw new Error(`Error importing Bip44Wallet from mnemonic: ${err}`) @@ -161,12 +161,12 @@ export class Bip44Wallet extends Wallet { * be used to regenerate any higher level randomness which includes entropy, * mnemonic phrase, and salt. * - * @param {CryptoKey} key - Used to lock and unlock the wallet + * @param {Uint8Array} key - Used to lock and unlock the wallet * @param {string} seed - Hexadecimal 128-character string used to derive private-public key pairs * @returns {Bip44Wallet} A newly instantiated Bip44Wallet */ - static async fromSeed (key: CryptoKey, seed: string): Promise - static async fromSeed (passkey: string | CryptoKey, seed: string): Promise { + static async fromSeed (key: Uint8Array, seed: string): Promise + static async fromSeed (passkey: string | Uint8Array, seed: string): Promise { if (seed.length !== SEED_LENGTH_BIP44) { throw new Error(`Expected a ${SEED_LENGTH_BIP44}-character seed, but received ${seed.length}-character string.`) } @@ -176,7 +176,7 @@ export class Bip44Wallet extends Wallet { const id = await Entropy.create(16) Bip44Wallet.#isInternal = true const wallet = new this(id, seed) - await wallet.lock(passkey as string) + await wallet.lock(passkey) return wallet } diff --git a/src/lib/wallets/blake2b-wallet.ts b/src/lib/wallets/blake2b-wallet.ts index b5c7ac2..474ce3d 100644 --- a/src/lib/wallets/blake2b-wallet.ts +++ b/src/lib/wallets/blake2b-wallet.ts @@ -47,11 +47,11 @@ export class Blake2bWallet extends Wallet { * Creates a new BLAKE2b wallet by using a seed generated using a * cryptographically strong pseudorandom number generator. * - * @param {CryptoKey} key - Encrypts the wallet to lock and unlock it + * @param {Uint8Array} key - Encrypts the wallet to lock and unlock it * @returns {Blake2bWallet} A newly instantiated Blake2bWallet */ - static async create (key: CryptoKey): Promise - static async create (passkey: string | CryptoKey): Promise { + static async create (key: Uint8Array): Promise + static async create (passkey: string | Uint8Array): Promise { try { const seed = await Entropy.create() return await Blake2bWallet.fromSeed(passkey as string, seed.hex) @@ -73,12 +73,12 @@ export class Blake2bWallet extends Wallet { * Creates a new BLAKE2b wallet by using a pregenerated seed. The user must * ensure that it is cryptographically strongly random. * - * @param {CryptoKey} key - Used to lock and unlock the wallet + * @param {Uint8Array} key - Used to lock and unlock the wallet * @param {string} seed - Hexadecimal 64-character string used to derive private-public key pairs * @returns {Blake2bWallet} A newly instantiated Blake2bWallet */ - static async fromSeed (key: CryptoKey, seed: string): Promise - static async fromSeed (passkey: string | CryptoKey, seed: string): Promise { + static async fromSeed (key: Uint8Array, seed: string): Promise + static async fromSeed (passkey: string | Uint8Array, seed: string): Promise { if (seed.length !== SEED_LENGTH_BLAKE2B) { throw new Error(`Expected a ${SEED_LENGTH_BLAKE2B}-character seed, but received ${seed.length}-character string.`) } @@ -90,7 +90,7 @@ export class Blake2bWallet extends Wallet { const m = await Bip39Mnemonic.fromEntropy(seed) Blake2bWallet.#isInternal = true const wallet = new this(id, s, m) - await wallet.lock(passkey as string) + await wallet.lock(passkey) return wallet } @@ -105,19 +105,19 @@ export class Blake2bWallet extends Wallet { /** * Creates a new BLAKE2b wallet by using a pregenerated mnemonic phrase. * - * @param {CryptoKey} key - Used to lock and unlock the wallet + * @param {Uint8Array} key - Used to lock and unlock the wallet * @param {string} mnemonic - Used when generating the final seed * @returns {Blake2bWallet} A newly instantiated Blake2bWallet */ - static async fromMnemonic (key: CryptoKey, mnemonic: string): Promise - static async fromMnemonic (passkey: string | CryptoKey, mnemonic: string): Promise { + static async fromMnemonic (key: Uint8Array, mnemonic: string): Promise + static async fromMnemonic (passkey: string | Uint8Array, mnemonic: string): Promise { try { const id = await Entropy.create(16) const m = await Bip39Mnemonic.fromPhrase(mnemonic) const s = await m.toBlake2bSeed() Blake2bWallet.#isInternal = true const wallet = new this(id, s, m) - await wallet.lock(passkey as string) + await wallet.lock(passkey) return wallet } catch (err) { throw new Error(`Error importing Blake2bWallet from mnemonic: ${err}`) -- 2.47.3