\r
/**\r
* Retrieves accounts from a wallet using its child key derivation function.\r
+ * Defaults to the first account at index 0.\r
+ *\r
+ * Note: The wallet index of a given requested account might not correlate with\r
+ * its index in the returned array.\r
+ *\r
+ * For example, calling `await wallet.accounts(5)` will return the sixth\r
+ * account of the wallet in the first array element position at index 0.\r
+ *\r
+ * A shorthand way of getting one specific account could be\r
+ * `const account = (await wallet.accounts(N))[0]` where N is the wallet index\r
+ * of the desired account.\r
*\r
* @param {number} from - Start index of secret keys. Default: 0\r
* @param {number} to - End index of secret keys. Default: `from`\r
}\r
\r
/**\r
- * Refreshes wallet account balances, frontiers, and representatives from the current state on the network.\r
+ * Refreshes wallet account balances, frontiers, and representatives from the\r
+ * current state on the network.\r
*\r
* A successful response will set these properties on each account.\r
*\r
// SPDX-FileCopyrightText: 2024 Chris Duncan <chris@zoso.dev>
// SPDX-License-Identifier: GPL-3.0-or-later
+/**
+* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
+*
+* Do not send any funds to the test vectors below!
+*
+* Sources:
+* https://docs.nano.org/integration-guides/key-management/
+* 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'
import { NANO_TEST_VECTORS } from './TEST_VECTORS.js'\r
import { Bip44Wallet, Blake2bWallet, LedgerWallet } from '../dist/main.js'\r
\r
-// WARNING: Do not send any funds to the test vectors below\r
-// Test vectors from https://docs.nano.org/integration-guides/key-management/ and elsewhere\r
describe('creating a new wallet', async () => {\r
-\r
it('BIP-44 wallet with random entropy', async () => {\r
const wallet = await Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
assert.ok(wallet)\r
})\r
})\r
-\r
-describe('wallet generation performance', { skip: true }, async () => {\r
- it('performance test creating BIP-44 wallets', async () => {\r
- const wallets = []\r
- for (let i = 0x100; i > 0; i--) {\r
- wallets.push(await Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD))\r
- }\r
- assert.equal(wallets.length, 0x100)\r
- })\r
-\r
- it('performance test creating BLAKE2b wallets', async () => {\r
- const wallets = []\r
- for (let i = 0x100; i > 0; i--) {\r
- wallets.push(await Blake2bWallet.create(NANO_TEST_VECTORS.PASSWORD))\r
- }\r
- assert.equal(wallets.length, 0x100)\r
- })\r
-})\r
import { NANO_TEST_VECTORS } from './TEST_VECTORS.js'\r
import { Bip44Wallet, Blake2bWallet, LedgerWallet } from '../dist/main.js'\r
\r
-// WARNING: Do not send any funds to the test vectors below\r
-// Test vectors from https://docs.nano.org/integration-guides/key-management/ and elsewhere\r
describe('derive child accounts from the same seed', async () => {\r
const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
\r
- it('should derive the first account from the given BIP-44 seed', async function () {\r
+ it('should derive the first account from the given BIP-44 seed', async () => {\r
const accounts = await wallet.accounts()\r
\r
assert.equal(accounts.length, 1)\r
assert.equal(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_0)\r
})\r
\r
- it('should derive low indexed accounts from the given BIP-44 seed', async function () {\r
+ it('should derive low indexed accounts from the given BIP-44 seed', async () => {\r
const accounts = await wallet.accounts(1, 2)\r
\r
assert.equal(accounts.length, 2)\r
assert.equal(accounts[1].address, NANO_TEST_VECTORS.ADDRESS_2)\r
})\r
\r
- it('should derive high indexed accounts from the given seed', async function () {\r
+ it('should derive high indexed accounts from the given seed', async () => {\r
const accounts = await wallet.accounts(0x70000000, 0x700000ff)\r
\r
assert.equal(accounts.length, 0x100)\r
}\r
})\r
\r
- it('should derive accounts for a BLAKE2b wallet', async function () {\r
+ it('should derive accounts for a BLAKE2b wallet', async () => {\r
const bwallet = await Blake2bWallet.create(NANO_TEST_VECTORS.PASSWORD)\r
await bwallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const lowAccounts = await bwallet.accounts(0, 2)\r
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', async function () {\r
+ it('should fetch the first account from a Ledger device', { skip: true }, async () => {\r
+ const wallet = await LedgerWallet.create()\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 () => {\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 { BIP32_TEST_VECTORS, CUSTOM_TEST_VECTORS, NANO_TEST_VECTORS, TREZOR_TEST_VECTORS } from './TEST_VECTORS.js'\r
import { Account, Bip44Wallet, Blake2bWallet } from '../dist/main.js'\r
\r
-// WARNING: Do not send any funds to the test vectors below\r
-// Test vectors from https://docs.nano.org/integration-guides/key-management/ and elsewhere\r
describe('import wallet with test vectors test', () => {\r
it('should successfully import a wallet with the official Nano test vectors mnemonic', async () => {\r
const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
\r
const skip = false\r
\r
-// WARNING: Do not send any funds to the test vectors below\r
-// Test vectors from https://docs.nano.org/integration-guides/key-management/ and elsewhere\r
describe('locking and unlocking a Bip44Wallet', { skip }, 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
--- /dev/null
+// SPDX-FileCopyrightText: 2024 Chris Duncan <chris@zoso.dev>
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+'use strict'
+
+import './GLOBALS.mjs'
+import { describe, it } from 'node:test'
+import { strict as assert } from 'assert'
+import { NANO_TEST_VECTORS } from './TEST_VECTORS.js'
+import { Bip44Wallet, Blake2bWallet } from '../dist/main.js'
+
+const skip = true
+
+describe('wallet generation performance', { skip }, async () => {
+ it('performance test creating BIP-44 wallets', async () => {
+ const wallets = []
+ for (let i = 0x80; i > 0; i--) {
+ wallets.push(await Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD))
+ }
+ assert.equal(wallets.length, 0x80)
+ })
+
+ it('performance test creating BLAKE2b wallets', async () => {
+ const wallets = []
+ for (let i = 0x80; i > 0; i--) {
+ wallets.push(await Blake2bWallet.create(NANO_TEST_VECTORS.PASSWORD))
+ }
+ assert.equal(wallets.length, 0x80)
+ })
+})
+
+describe('child key derivation performance', { skip }, async () => {
+ it('performance test of BIP-44 ckd', async () => {
+ const wallet = await Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD)
+ await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)
+
+ const accounts = await wallet.accounts(0, 0x7fff)
+
+ assert.equal(accounts.length, 0x8000)
+ })
+
+ it('performance test of BLAKE2b ckd', async () => {
+ const wallet = await Blake2bWallet.create(NANO_TEST_VECTORS.PASSWORD)
+ await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)
+
+ const accounts = await wallet.accounts(0, 0x7fff)
+
+ assert.equal(accounts.length, 0x8000)
+ })
+})
import { NANO_TEST_VECTORS } from './TEST_VECTORS.js'
import { Account, Bip44Wallet, Rpc } from '../dist/main.js'
-// WARNING: Do not send any funds to the test vectors below
-// Test vectors from https://docs.nano.org/integration-guides/key-management/ and elsewhere
-
const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)
const node = new Rpc(process.env.NODE_URL, process.env.API_KEY_NAME, process.env.API_KEY_VALUE)
import { NANO_TEST_VECTORS } from './TEST_VECTORS.js'\r
import { SendBlock, ReceiveBlock, ChangeBlock } from '../dist/main.js'\r
\r
-// WARNING: Do not send any funds to the test vectors below\r
-// Test vectors from https://docs.nano.org/integration-guides/key-management/\r
describe('valid blocks', async () => {\r
it('should not allow negative balances', async () => {\r
assert.throws(() => {\r