]> zoso.dev Git - libnemo.git/commitdiff
Start substitution of blakejs with blake2b package.
authorChris Duncan <chris@zoso.dev>
Sun, 17 Nov 2024 01:16:39 +0000 (17:16 -0800)
committerChris Duncan <chris@zoso.dev>
Sun, 17 Nov 2024 01:16:39 +0000 (17:16 -0800)
package-lock.json
package.json
src/lib/ckd.ts

index 8fed5d2df8c4e25ee63c985f8a7e859e2cb7ed3a..6f7bc9660724a1c629b1666ecb45e29e60cea067 100644 (file)
@@ -9,9 +9,11 @@
                        "version": "0.0.19",
                        "license": "(GPL-3.0-or-later AND MIT)",
                        "dependencies": {
+                               "blake2b": "^2.1.4",
                                "blakejs": "^1.2.1"
                        },
                        "devDependencies": {
+                               "@types/blake2b": "^2.1.3",
                                "@types/node": "^22.8.6",
                                "@types/w3c-web-hid": "^1.0.6",
                                "@types/w3c-web-usb": "^1.0.10",
                        "license": "Apache-2.0",
                        "optional": true
                },
+               "node_modules/@types/blake2b": {
+                       "version": "2.1.3",
+                       "resolved": "https://registry.npmjs.org/@types/blake2b/-/blake2b-2.1.3.tgz",
+                       "integrity": "sha512-MFCdX0MNxFBP/xEILO5Td0kv6nI7+Q2iRWZbTL/yzH2/eDVZS5Wd1LHdsmXClvsCyzqaZfHFzZaN6BUeUCfSDA==",
+                       "dev": true,
+                       "license": "MIT"
+               },
                "node_modules/@types/node": {
                        "version": "22.8.6",
                        "resolved": "https://registry.npmjs.org/@types/node/-/node-22.8.6.tgz",
                        "dev": true,
                        "license": "MIT"
                },
+               "node_modules/b4a": {
+                       "version": "1.6.7",
+                       "resolved": "https://registry.npmjs.org/b4a/-/b4a-1.6.7.tgz",
+                       "integrity": "sha512-OnAYlL5b7LEkALw87fUVafQw5rVR9RjwGd4KUwNQ6DrrNmaVaUCgLipfVlzrPQ4tWOR9P0IXGNOx50jYCCdSJg==",
+                       "license": "Apache-2.0"
+               },
+               "node_modules/blake2b": {
+                       "version": "2.1.4",
+                       "resolved": "https://registry.npmjs.org/blake2b/-/blake2b-2.1.4.tgz",
+                       "integrity": "sha512-AyBuuJNI64gIvwx13qiICz6H6hpmjvYS5DGkG6jbXMOT8Z3WUJ3V1X0FlhIoT1b/5JtHE3ki+xjtMvu1nn+t9A==",
+                       "license": "ISC",
+                       "dependencies": {
+                               "blake2b-wasm": "^2.4.0",
+                               "nanoassert": "^2.0.0"
+                       }
+               },
+               "node_modules/blake2b-wasm": {
+                       "version": "2.4.0",
+                       "resolved": "https://registry.npmjs.org/blake2b-wasm/-/blake2b-wasm-2.4.0.tgz",
+                       "integrity": "sha512-S1kwmW2ZhZFFFOghcx73+ZajEfKBqhP82JMssxtLVMxlaPea1p9uoLiUZ5WYyHn0KddwbLc+0vh4wR0KBNoT5w==",
+                       "license": "MIT",
+                       "dependencies": {
+                               "b4a": "^1.0.1",
+                               "nanoassert": "^2.0.0"
+                       }
+               },
                "node_modules/blakejs": {
                        "version": "1.2.1",
                        "resolved": "https://registry.npmjs.org/blakejs/-/blakejs-1.2.1.tgz",
                                "node": ">=0.8.x"
                        }
                },
+               "node_modules/nanoassert": {
+                       "version": "2.0.0",
+                       "resolved": "https://registry.npmjs.org/nanoassert/-/nanoassert-2.0.0.tgz",
+                       "integrity": "sha512-7vO7n28+aYO4J+8w96AzhmU8G+Y/xpPDJz/se19ICsqj/momRbb9mh9ZUtkoJ5X3nTnPdhEJyc0qnM6yAsHBaA==",
+                       "license": "ISC"
+               },
                "node_modules/rxjs": {
                        "version": "7.8.1",
                        "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz",
index fc3ad005a10edd603d560a7d556d2d9ba172562d..8350511bf6d3c21f7f0bed48b2329582dea11249 100644 (file)
@@ -45,6 +45,7 @@
                "test:coverage:report": "npm run test:coverage -- --test-reporter=lcov --test-reporter-destination=coverage.info && genhtml coverage.info --output-directory test/coverage && rm coverage.info && xdg-open test/coverage/index.html"
        },
        "dependencies": {
+               "blake2b": "^2.1.4",
                "blakejs": "^1.2.1"
        },
        "optionalDependencies": {
@@ -53,6 +54,7 @@
                "@ledgerhq/hw-transport-webusb": "^6.29.4"
        },
        "devDependencies": {
+               "@types/blake2b": "^2.1.3",
                "@types/node": "^22.8.6",
                "@types/w3c-web-hid": "^1.0.6",
                "@types/w3c-web-usb": "^1.0.10",
index 377aacb032b51a449c09166385208be4c7384960..8e40b9db7f78d2485ed7ce814358b6f2009a4fb2 100644 (file)
@@ -1,9 +1,9 @@
 // SPDX-FileCopyrightText: 2024 Chris Duncan <chris@zoso.dev>
 // SPDX-License-Identifier: GPL-3.0-or-later
 
+import blake2b from 'blake2b'
 import { nanoCKD } from './bip32-key-derivation.js'
-import { bytes, dec } from './convert.js'
-import Tools from './tools.js'
+import { dec, hex } from './convert.js'
 
 if (globalThis.Worker == null) {
        const { isMainThread, parentPort } = await import('node:worker_threads')
@@ -50,6 +50,7 @@ async function ckdBip44 (seed: string, index: number): Promise<string> {
 * @returns {Promise<Account>}
 */
 async function ckdBlake2b (seed: string, index: number): Promise<string> {
-       const hash = await Tools.blake2b([seed, dec.toHex(index, 8)])
-       return bytes.toHex(hash)
+       const input = `${seed}${dec.toHex(index, 8)}`
+       const hash = blake2b(32).update(hex.toBytes(input)).digest('hex')
+       return hash
 }