\r
# Coverage directory used by tools like istanbul\r
coverage\r
+coverage.info\r
\r
# nyc test coverage\r
.nyc_output\r
{
"name": "libnemo",
- "version": "0.0.19",
+ "version": "0.0.20",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "libnemo",
- "version": "0.0.19",
+ "version": "0.0.20",
"license": "(GPL-3.0-or-later AND MIT)",
"dependencies": {
- "blake2b-wasm": "^2.4.0",
- "blakejs": "^1.2.1"
+ "blake2b": "^2.1.4"
},
"devDependencies": {
- "@types/blake2b-wasm": "^2.4.3",
+ "@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-wasm": {
- "version": "2.4.3",
- "resolved": "https://registry.npmjs.org/@types/blake2b-wasm/-/blake2b-wasm-2.4.3.tgz",
- "integrity": "sha512-emsOJOuF5shxg5zhN3CHOy4BO/a26O++yk0ncFW9fePquKSGs1g6PIps8u8zFmApJjIkMQr7neVUqvoic4BRFw==",
+ "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",
- "integrity": "sha512-tosuJYKrIqjQIlVCM4PEGxOmyg3FCPa/fViuJChnGeEIhjA46oy8FMVoF9su1/v8PNs2a8Q0iFNyOx0uOF91nw==",
+ "version": "22.9.0",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-22.9.0.tgz",
+ "integrity": "sha512-vuyHg81vvWA1Z1ELfvLko2c8f34gyA0zaic0+Rllc5lbCnbSyuvb2Oxpm6TAUAC/2xZN3QGqxBNggD1nNR2AfQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"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",
"nanoassert": "^2.0.0"
}
},
- "node_modules/blakejs": {
- "version": "1.2.1",
- "resolved": "https://registry.npmjs.org/blakejs/-/blakejs-1.2.1.tgz",
- "integrity": "sha512-QXUSXI3QVc/gJME0dBpXrag1kbzOqCjCX8/b54ntNyW6sjtoqxqRk3LTmXzaJoh71zMsDCjM+47jS7XiwN/+fQ==",
- "license": "MIT"
- },
"node_modules/esbuild": {
"version": "0.24.0",
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.24.0.tgz",
{
"name": "libnemo",
- "version": "0.0.19",
+ "version": "0.0.20",
"description": "Asynchronous, non-blocking Nano cryptocurrency integration toolkit.",
"keywords": [
"nemo",
"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-wasm": "^2.4.0",
- "blakejs": "^1.2.1"
+ "blake2b": "^2.1.4"
},
"optionalDependencies": {
"@ledgerhq/hw-transport-web-ble": "^6.29.4",
"@ledgerhq/hw-transport-webusb": "^6.29.4"
},
"devDependencies": {
- "@types/blake2b-wasm": "^2.4.3",
+ "@types/blake2b": "^2.1.3",
"@types/node": "^22.8.6",
"@types/w3c-web-hid": "^1.0.6",
"@types/w3c-web-usb": "^1.0.10",
// SPDX-FileCopyrightText: 2024 Chris Duncan <chris@zoso.dev>\r
// SPDX-License-Identifier: GPL-3.0-or-later\r
\r
-import { blake2b } from 'blakejs'\r
+import blake2b from 'blake2b'\r
import { ACCOUNT_KEY_LENGTH, ALPHABET, PREFIX, PREFIX_LEGACY } from './constants.js'\r
import { base32, bytes, hex } from './convert.js'\r
import Ed25519 from './ed25519.js'\r
const expectedChecksum = address.slice(-8)\r
const keyBase32 = address.slice(address.indexOf('_') + 1, -8)\r
const keyBuf = base32.toBytes(keyBase32)\r
- const actualChecksumBuf = blake2b(keyBuf, undefined, 5).reverse()\r
+ const actualChecksumBuf = blake2b(5, undefined, undefined, undefined, true)\r
+ .update(keyBuf).digest().reverse()\r
const actualChecksum = bytes.toBase32(actualChecksumBuf)\r
\r
if (expectedChecksum !== actualChecksum) {\r
static #addressToKey (v: string): string {\r
const keyBytes = base32.toBytes(v.substring(0, 52))\r
const checksumBytes = base32.toBytes(v.substring(52, 60))\r
- const blakeHash = blake2b(keyBytes, undefined, 5).reverse()\r
+ const blakeHash = blake2b(5, undefined, undefined, undefined, true)\r
+ .update(keyBytes).digest().reverse()\r
if (bytes.toHex(checksumBytes) !== bytes.toHex(blakeHash)) {\r
throw new Error('Checksum mismatch in address')\r
}\r
\r
static async #keyToAddress (key: string): Promise<string> {\r
const publicKeyBytes = hex.toBytes(key)\r
- const checksum = blake2b(publicKeyBytes, undefined, 5).reverse()\r
+ const checksum = blake2b(5, undefined, undefined, undefined, true)\r
+ .update(publicKeyBytes).digest().reverse()\r
const encoded = bytes.toBase32(publicKeyBytes)\r
const encodedChecksum = bytes.toBase32(checksum)\r
return `${PREFIX}${encoded}${encodedChecksum}`\r
// SPDX-FileCopyrightText: 2024 Chris Duncan <chris@zoso.dev>
// SPDX-License-Identifier: GPL-3.0-or-later
-import { blake2b } from 'blakejs'
+import blake2b from 'blake2b'
/**
* Derived from:
for (let i = 0; i < n; ++i) {
input[i] = m[i]
}
- const hash = blake2b(input)
+ const hash = blake2b(64).update(input).digest()
for (let i = 0; i < 64; ++i) {
out[i] = hash[i]
}
// SPDX-FileCopyrightText: 2024 Chris Duncan <chris@zoso.dev>\r
// SPDX-License-Identifier: GPL-3.0-or-later\r
\r
-import blakejs from 'blakejs'\r
-const { blake2b, blake2bInit, blake2bUpdate, blake2bFinal } = blakejs\r
+import blake2b from 'blake2b'\r
import { bytes, hex } from './convert.js'\r
import Curve25519 from './curve25519.js'\r
\r
function getPublicKey (privateKey: string): string {\r
const pk = new Uint8Array(32)\r
const p = [curve.gf(), curve.gf(), curve.gf(), curve.gf()]\r
- const h = blake2b(hex.toBytes(privateKey), undefined, 64).slice(0, 32)\r
+ const h = blake2b(64).update(hex.toBytes(privateKey)).digest().slice(0, 32)\r
\r
h[0] &= 0xf8\r
h[31] &= 0x7f\r
return false\r
}\r
\r
- const ctx = blake2bInit(64, undefined)\r
- blake2bUpdate(ctx, signature.subarray(0, 32))\r
- blake2bUpdate(ctx, publicKey)\r
- blake2bUpdate(ctx, msg)\r
- let k = blake2bFinal(ctx)\r
+ const k = blake2b(64)\r
+ .update(signature.subarray(0, 32))\r
+ .update(publicKey)\r
+ .update(msg)\r
+ .digest()\r
reduce(k)\r
scalarmult(p, q, k)\r
\r
// SPDX-FileCopyrightText: 2024 Chris Duncan <chris@zoso.dev>
// SPDX-License-Identifier: GPL-3.0-or-later
-import blakejs from 'blakejs'
-const { blake2bInit, blake2bUpdate, blake2bFinal } = blakejs
+import blake from 'blake2b'
import { Account } from './account.js'
import { UNITS } from './constants.js'
import { bytes, hex } from './convert.js'
*/
export async function blake2b (data: string | string[]): Promise<Uint8Array> {
if (!Array.isArray(data)) data = [data]
- const ctx = blake2bInit(32)
- data.forEach(str => blake2bUpdate(ctx, hex.toBytes(str)))
- return blake2bFinal(ctx)
+ const hash = blake(32)
+ data.forEach(str => hash.update(hex.toBytes(str)))
+ return hash.digest()
}
/**
// SPDX-FileCopyrightText: 2024 Chris Duncan <chris@zoso.dev>\r
// SPDX-License-Identifier: GPL-3.0-or-later\r
\r
-import blake2b from 'blake2b-wasm'\r
+import blake2b from 'blake2b'\r
import { Account } from './account.js'\r
import { nanoCKD } from './bip32-key-derivation.js'\r
import { Bip39Mnemonic } from './bip39-mnemonic.js'\r
*/\r
async ckd (index: number): Promise<Account> {\r
const input = `${this.seed}${dec.toHex(index, 8)}`\r
- const key = blake2b().update(hex.toBytes(input)).digest('hex')\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
* https://github.com/trezor/python-mnemonic/blob/master/vectors.json
* https://tools.nanos.cc/?tool=seed
*/
-
export const GENESIS_ADDRESS = 'nano_3t6k35gi95xu6tergt6p69ck76ogmitsa8mnijtpxm9fkcm736xtoncuohr3'
export const RAW_MAX = '340282366920938463463374607431768211455'
export const SUPPLY_MAX = '133248297920938463463374607431768211455'
assert.ok(a.index != null)\r
}\r
})\r
+})\r
+\r
+describe('Ledger device accounts', { skip: true }, async () => {\r
+ const wallet = await LedgerWallet.create()\r
\r
- it('should fetch the first account from a Ledger device', { skip: true }, async () => {\r
- const wallet = await LedgerWallet.create()\r
+ it('should fetch the first account from a Ledger device', async () => {\r
const accounts = await wallet.accounts()\r
\r
assert.equal(accounts.length, 1)\r
assert.ok(accounts[0].address)\r
})\r
})\r
+\r
+describe('child key derivation performance', { skip: true }, async () => {\r
+ it('performance test of BIP-44 ckd', async function () {\r
+ const wallet = await Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD)\r
+ await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+\r
+ const accounts = await wallet.accounts(0, 0x7fff)\r
+\r
+ assert.equal(accounts.length, 0x8000)\r
+ })\r
+\r
+ it('performance test of BLAKE2b ckd', async function () {\r
+ const wallet = await Blake2bWallet.create(NANO_TEST_VECTORS.PASSWORD)\r
+ await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+\r
+ const accounts = await wallet.accounts(0, 0x7fff)\r
+\r
+ assert.equal(accounts.length, 0x8000)\r
+ })\r
+})\r
import { NANO_TEST_VECTORS, TREZOR_TEST_VECTORS } from './TEST_VECTORS.js'\r
import { Bip44Wallet, Blake2bWallet } from '../dist/main.js'\r
\r
-const skip = false\r
-\r
-describe('locking and unlocking a Bip44Wallet', { skip }, async () => {\r
+describe('locking and unlocking a Bip44Wallet', async () => {\r
it('should succeed with a password', async () => {\r
const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
\r
})\r
})\r
\r
-describe('locking and unlocking a Blake2bWallet', { skip }, async () => {\r
+describe('locking and unlocking a Blake2bWallet', async () => {\r
it('should succeed with a password', async () => {\r
const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0)\r
\r