]> zoso.dev Git - libnemo.git/commitdiff
Remove deprecated ckd functions from wallet subclasses. Fix freeze from ckd being...
authorChris Duncan <chris@zoso.dev>
Thu, 21 Nov 2024 06:25:42 +0000 (22:25 -0800)
committerChris Duncan <chris@zoso.dev>
Thu, 21 Nov 2024 06:25:42 +0000 (22:25 -0800)
src/lib/wallet.ts

index b2be0011ea1d4b7a79e7014dfb6bc37cc35a3f38..a1b74cb1a6c95a5ddf21190849d7dfa061294f7a 100644 (file)
@@ -84,17 +84,18 @@ abstract class Wallet {
                const indexes = []\r
                for (let i = from; i <= to; i++) {\r
                        if (this.#accounts[i] == null) {\r
-                               // this.#accounts[i] = await this.ckd(i)\r
                                indexes.push(i)\r
                        }\r
                }\r
-               let results = await this.ckd(indexes)\r
-               if (!Array.isArray(results)) results = [results]\r
-               for (const result of results) {\r
-                       if (result.index == null) {\r
-                               console.error('Wallet account calculated with null index')\r
-                       } else {\r
-                               this.#accounts[result.index] = result\r
+               if (indexes.length > 0) {\r
+                       let results = await this.ckd(indexes)\r
+                       if (!Array.isArray(results)) results = [results]\r
+                       for (const result of results) {\r
+                               if (result.index == null) {\r
+                                       throw new RangeError('Account key derived but index missing')\r
+                               } else {\r
+                                       this.#accounts[result.index] = result\r
+                               }\r
                        }\r
                }\r
                return this.#accounts.slice(from, to + 1)\r
@@ -409,34 +410,6 @@ export class Bip44Wallet extends Wallet {
                return wallet\r
        }\r
 \r
-       /**\r
-       * Derives BIP-44 Nano account private keys.\r
-       *\r
-       * @param {number} index - Index of the account\r
-       * @returns {Promise<Account>}\r
-       */\r
-       async ckd_old (index: number | number[]): Promise<Account[]> {\r
-               if (!Array.isArray(index)) index = [index]\r
-               const keys = []\r
-               let now = performance.now()\r
-               for (const i of index) {\r
-                       const key = await nanoCKD(this.seed, i)\r
-                       if (typeof key !== 'string') {\r
-                               throw new TypeError('BIP-44 child key derivation returned invalid data')\r
-                       }\r
-                       keys.push({ key, i })\r
-               }\r
-               console.log(-now + (now = performance.now()), 'ms')\r
-               console.log('bip44 ckd done')\r
-               const accounts = []\r
-               for (const key of keys) {\r
-                       accounts.push(await Account.fromPrivateKey(key.key, key.i))\r
-               }\r
-               console.log(-now + (now = performance.now()), 'ms')\r
-               console.log('bip44 account list done')\r
-               return accounts\r
-       }\r
-\r
        /**\r
        * Derives BIP-44 Nano account private keys.\r
        *\r
@@ -446,11 +419,8 @@ export class Bip44Wallet extends Wallet {
        async ckd (index: number | number[]): Promise<Account[]> {\r
                if (!Array.isArray(index)) index = [index]\r
                const data: any = []\r
-               let now = performance.now()\r
                index.forEach(i => data.push({ seed: this.seed, index: i }))\r
                const results: [{ index: number, key: string }] = await this.#pool.work(data)\r
-               console.log(-now + (now = performance.now()), 'ms')\r
-               console.log('bip44 ckd done')\r
                const accounts = []\r
                for (const result of results) {\r
                        const { index, key } = result\r
@@ -459,8 +429,6 @@ export class Bip44Wallet extends Wallet {
                        }\r
                        accounts.push(await Account.fromPrivateKey(key, index))\r
                }\r
-               console.log(-now + (now = performance.now()), 'ms')\r
-               console.log('bip44 account list done')\r
                return accounts\r
        }\r
 }\r
@@ -597,35 +565,6 @@ export class Blake2bWallet extends Wallet {
                return wallet\r
        }\r
 \r
-       /**\r
-       * Derives BLAKE2b account private keys.\r
-       *\r
-       * @param {number} index - Index of the account\r
-       * @returns {Promise<Account>}\r
-       */\r
-       async ckd_old (index: number | number[]): Promise<Account[]> {\r
-               if (!Array.isArray(index)) index = [index]\r
-               const keys = []\r
-               let now = performance.now()\r
-               for (const i of index) {\r
-                       const input = `${this.seed}${dec.toHex(i, 8)}`\r
-                       const key = blake2b(32).update(hex.toBytes(input)).digest('hex')\r
-                       if (typeof key !== 'string') {\r
-                               throw new TypeError('BLAKE2b child key derivation returned invalid data')\r
-                       }\r
-                       keys.push({ key, i })\r
-               }\r
-               console.log(-now + (now = performance.now()), 'ms')\r
-               console.log('blake2b ckd done')\r
-               const accounts = []\r
-               for (const key of keys) {\r
-                       accounts.push(await Account.fromPrivateKey(key.key, key.i))\r
-               }\r
-               console.log(-now + (now = performance.now()), 'ms')\r
-               console.log('blake2b account list done')\r
-               return accounts\r
-       }\r
-\r
        /**\r
        * Derives BLAKE2b account private keys.\r
        *\r
@@ -635,11 +574,8 @@ export class Blake2bWallet extends Wallet {
        async ckd (index: number | number[]): Promise<Account[]> {\r
                if (!Array.isArray(index)) index = [index]\r
                const data: any = []\r
-               let now = performance.now()\r
                index.forEach(i => data.push({ seed: this.seed, index: i }))\r
                const results: [{ index: number, key: string }] = await this.#pool.work(data)\r
-               console.log(-now + (now = performance.now()), 'ms')\r
-               console.log('blake2b ckd done')\r
                const accounts = []\r
                for (const result of results) {\r
                        const { index, key } = result\r
@@ -648,8 +584,6 @@ export class Blake2bWallet extends Wallet {
                        }\r
                        accounts.push(await Account.fromPrivateKey(key, index))\r
                }\r
-               console.log(-now + (now = performance.now()), 'ms')\r
-               console.log('blake2b account list done')\r
                return accounts\r
        }\r
 }\r