]> git.codecow.com Git - libnemo.git/commitdiff
Remove references to CryptoKey which is no longer accepted as a parameter for creatin...
authorChris Duncan <chris@zoso.dev>
Fri, 4 Jul 2025 08:32:07 +0000 (01:32 -0700)
committerChris Duncan <chris@zoso.dev>
Fri, 4 Jul 2025 08:32:07 +0000 (01:32 -0700)
README.md
src/lib/wallets/bip44-wallet.ts
src/lib/wallets/blake2b-wallet.ts

index 8a10272c58ab92cdd7c7318ac311e5f5f0001474..78c427bec7a976154d5abff7ad80a407cdd31c0d 100644 (file)
--- 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
index 45bd3813d00d81b7a98a8ec512436a7e4743f9fa..8d72ca915285df5f748fd46819e549a10517091e 100644 (file)
@@ -65,12 +65,12 @@ export class Bip44Wallet extends Wallet {
        * Creates a new HD wallet by using an entropy value generated using a\r
        * cryptographically strong pseudorandom number generator.\r
        *\r
-       * @param {CryptoKey} key - Encrypts the wallet to lock and unlock it\r
+       * @param {Uint8Array} key - Encrypts the wallet to lock and unlock it\r
        * @param {string} [salt=''] - Used when generating the final seed\r
        * @returns {Bip44Wallet} A newly instantiated Bip44Wallet\r
        */\r
-       static async create (key: CryptoKey, salt?: string): Promise<Bip44Wallet>\r
-       static async create (passkey: string | CryptoKey, salt: string = ''): Promise<Bip44Wallet> {\r
+       static async create (key: Uint8Array, salt?: string): Promise<Bip44Wallet>\r
+       static async create (passkey: string | Uint8Array, salt: string = ''): Promise<Bip44Wallet> {\r
                try {\r
                        const e = await Entropy.create()\r
                        return await Bip44Wallet.fromEntropy(passkey as string, e.hex, salt)\r
@@ -93,13 +93,13 @@ export class Bip44Wallet extends Wallet {
        * Creates a new HD wallet by using a pregenerated entropy value. The user\r
        * must ensure that it is cryptographically strongly random.\r
        *\r
-       * @param {CryptoKey} key - Used to lock and unlock the wallet\r
+       * @param {Uint8Array} key - Used to lock and unlock the wallet\r
        * @param {string} entropy - Used when generating the initial mnemonic phrase\r
        * @param {string} [salt=''] - Used when generating the final seed\r
        * @returns {Bip44Wallet} A newly instantiated Bip44Wallet\r
        */\r
-       static async fromEntropy (key: CryptoKey, entropy: string, salt?: string): Promise<Bip44Wallet>\r
-       static async fromEntropy (passkey: string | CryptoKey, entropy: string, salt: string = ''): Promise<Bip44Wallet> {\r
+       static async fromEntropy (key: Uint8Array, entropy: string, salt?: string): Promise<Bip44Wallet>\r
+       static async fromEntropy (passkey: string | Uint8Array, entropy: string, salt: string = ''): Promise<Bip44Wallet> {\r
                try {\r
                        const id = await Entropy.create(16)\r
                        const e = await Entropy.import(entropy)\r
@@ -107,7 +107,7 @@ export class Bip44Wallet extends Wallet {
                        const s = await m.toBip39Seed(salt)\r
                        Bip44Wallet.#isInternal = true\r
                        const wallet = new this(id, s, m)\r
-                       await wallet.lock(passkey as string)\r
+                       await wallet.lock(passkey)\r
                        return wallet\r
                } catch (err) {\r
                        throw new Error(`Error importing Bip44Wallet from entropy: ${err}`)\r
@@ -126,20 +126,20 @@ export class Bip44Wallet extends Wallet {
        /**\r
        * Creates a new HD wallet by using a pregenerated mnemonic phrase.\r
        *\r
-       * @param {CryptoKey} key - Used to lock and unlock the wallet\r
+       * @param {Uint8Array} key - Used to lock and unlock the wallet\r
        * @param {string} mnemonic - Used when generating the final seed\r
        * @param {string} [salt=''] - Used when generating the final seed\r
        * @returns {Bip44Wallet} A newly instantiated Bip44Wallet\r
        */\r
-       static async fromMnemonic (key: CryptoKey, mnemonic: string, salt?: string): Promise<Bip44Wallet>\r
-       static async fromMnemonic (passkey: string | CryptoKey, mnemonic: string, salt: string = ''): Promise<Bip44Wallet> {\r
+       static async fromMnemonic (key: Uint8Array, mnemonic: string, salt?: string): Promise<Bip44Wallet>\r
+       static async fromMnemonic (passkey: string | Uint8Array, mnemonic: string, salt: string = ''): Promise<Bip44Wallet> {\r
                try {\r
                        const id = await Entropy.create(16)\r
                        const m = await Bip39Mnemonic.fromPhrase(mnemonic)\r
                        const s = await m.toBip39Seed(salt)\r
                        Bip44Wallet.#isInternal = true\r
                        const wallet = new this(id, s, m)\r
-                       await wallet.lock(passkey as string)\r
+                       await wallet.lock(passkey)\r
                        return wallet\r
                } catch (err) {\r
                        throw new Error(`Error importing Bip44Wallet from mnemonic: ${err}`)\r
@@ -161,12 +161,12 @@ export class Bip44Wallet extends Wallet {
        * be used to regenerate any higher level randomness which includes entropy,\r
        * mnemonic phrase, and salt.\r
        *\r
-       * @param {CryptoKey} key - Used to lock and unlock the wallet\r
+       * @param {Uint8Array} key - Used to lock and unlock the wallet\r
        * @param {string} seed - Hexadecimal 128-character string used to derive private-public key pairs\r
        * @returns {Bip44Wallet} A newly instantiated Bip44Wallet\r
        */\r
-       static async fromSeed (key: CryptoKey, seed: string): Promise<Bip44Wallet>\r
-       static async fromSeed (passkey: string | CryptoKey, seed: string): Promise<Bip44Wallet> {\r
+       static async fromSeed (key: Uint8Array, seed: string): Promise<Bip44Wallet>\r
+       static async fromSeed (passkey: string | Uint8Array, seed: string): Promise<Bip44Wallet> {\r
                if (seed.length !== SEED_LENGTH_BIP44) {\r
                        throw new Error(`Expected a ${SEED_LENGTH_BIP44}-character seed, but received ${seed.length}-character string.`)\r
                }\r
@@ -176,7 +176,7 @@ export class Bip44Wallet extends Wallet {
                const id = await Entropy.create(16)\r
                Bip44Wallet.#isInternal = true\r
                const wallet = new this(id, seed)\r
-               await wallet.lock(passkey as string)\r
+               await wallet.lock(passkey)\r
                return wallet\r
        }\r
 \r
index b5c7ac278b3b7cb6013bb17a7c3d28d24ccc6772..474ce3d22fa2e05786c66b398a210ab6f4e6fcdf 100644 (file)
@@ -47,11 +47,11 @@ export class Blake2bWallet extends Wallet {
        * Creates a new BLAKE2b wallet by using a seed generated using a\r
        * cryptographically strong pseudorandom number generator.\r
        *\r
-       * @param {CryptoKey} key - Encrypts the wallet to lock and unlock it\r
+       * @param {Uint8Array} key - Encrypts the wallet to lock and unlock it\r
        * @returns {Blake2bWallet} A newly instantiated Blake2bWallet\r
        */\r
-       static async create (key: CryptoKey): Promise<Blake2bWallet>\r
-       static async create (passkey: string | CryptoKey): Promise<Blake2bWallet> {\r
+       static async create (key: Uint8Array): Promise<Blake2bWallet>\r
+       static async create (passkey: string | Uint8Array): Promise<Blake2bWallet> {\r
                try {\r
                        const seed = await Entropy.create()\r
                        return await Blake2bWallet.fromSeed(passkey as string, seed.hex)\r
@@ -73,12 +73,12 @@ export class Blake2bWallet extends Wallet {
        * Creates a new BLAKE2b wallet by using a pregenerated seed. The user must\r
        * ensure that it is cryptographically strongly random.\r
        *\r
-       * @param {CryptoKey} key - Used to lock and unlock the wallet\r
+       * @param {Uint8Array} key - Used to lock and unlock the wallet\r
        * @param {string} seed - Hexadecimal 64-character string used to derive private-public key pairs\r
        * @returns {Blake2bWallet} A newly instantiated Blake2bWallet\r
        */\r
-       static async fromSeed (key: CryptoKey, seed: string): Promise<Blake2bWallet>\r
-       static async fromSeed (passkey: string | CryptoKey, seed: string): Promise<Blake2bWallet> {\r
+       static async fromSeed (key: Uint8Array, seed: string): Promise<Blake2bWallet>\r
+       static async fromSeed (passkey: string | Uint8Array, seed: string): Promise<Blake2bWallet> {\r
                if (seed.length !== SEED_LENGTH_BLAKE2B) {\r
                        throw new Error(`Expected a ${SEED_LENGTH_BLAKE2B}-character seed, but received ${seed.length}-character string.`)\r
                }\r
@@ -90,7 +90,7 @@ export class Blake2bWallet extends Wallet {
                const m = await Bip39Mnemonic.fromEntropy(seed)\r
                Blake2bWallet.#isInternal = true\r
                const wallet = new this(id, s, m)\r
-               await wallet.lock(passkey as string)\r
+               await wallet.lock(passkey)\r
                return wallet\r
        }\r
 \r
@@ -105,19 +105,19 @@ export class Blake2bWallet extends Wallet {
        /**\r
        * Creates a new BLAKE2b wallet by using a pregenerated mnemonic phrase.\r
        *\r
-       * @param {CryptoKey} key - Used to lock and unlock the wallet\r
+       * @param {Uint8Array} key - Used to lock and unlock the wallet\r
        * @param {string} mnemonic - Used when generating the final seed\r
        * @returns {Blake2bWallet} A newly instantiated Blake2bWallet\r
        */\r
-       static async fromMnemonic (key: CryptoKey, mnemonic: string): Promise<Blake2bWallet>\r
-       static async fromMnemonic (passkey: string | CryptoKey, mnemonic: string): Promise<Blake2bWallet> {\r
+       static async fromMnemonic (key: Uint8Array, mnemonic: string): Promise<Blake2bWallet>\r
+       static async fromMnemonic (passkey: string | Uint8Array, mnemonic: string): Promise<Blake2bWallet> {\r
                try {\r
                        const id = await Entropy.create(16)\r
                        const m = await Bip39Mnemonic.fromPhrase(mnemonic)\r
                        const s = await m.toBlake2bSeed()\r
                        Blake2bWallet.#isInternal = true\r
                        const wallet = new this(id, s, m)\r
-                       await wallet.lock(passkey as string)\r
+                       await wallet.lock(passkey)\r
                        return wallet\r
                } catch (err) {\r
                        throw new Error(`Error importing Blake2bWallet from mnemonic: ${err}`)\r