import './GLOBALS.mjs'\r
import { describe, it } from 'node:test'\r
import { strict as assert } from 'assert'\r
-import { NANO_TEST_VECTORS, TREZOR_TEST_VECTORS } from './TEST_VECTORS.js'\r
-import { Account, Bip44Wallet, Blake2bWallet, LedgerWallet } from '../dist/main.js'\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('generate wallet test', async () => {\r
- it('should fail to create a wallet when using new', () => {\r
- assert.throws(() => new Bip44Wallet())\r
- assert.throws(() => new Blake2bWallet())\r
- assert.throws(() => new LedgerWallet())\r
- })\r
+describe('creating a new wallet', async () => {\r
\r
- it('should fail to create a software wallet without a password', async () => {\r
- await assert.rejects(Bip44Wallet.create())\r
- await assert.rejects(Blake2bWallet.create())\r
- })\r
-\r
- it('should replace invalid salt with empty string', async () => {\r
- const invalidArgs = [null, true, false, 0, 1, 2, { "foo": "bar" }]\r
- for (const arg of invalidArgs) {\r
- await assert.doesNotReject(Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD, arg), `Rejected ${arg}`)\r
- }\r
- })\r
-\r
- it('should generate a BIP-44 wallet with random entropy', async () => {\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
- const accounts = await wallet.accounts()\r
\r
assert.ok('id' in wallet)\r
assert.ok('mnemonic' in wallet)\r
assert.ok('seed' in wallet)\r
- assert.ok(accounts[0] instanceof Account)\r
})\r
\r
- it('should generate a BLAKE2b wallet with random entropy', async () => {\r
+ it('BLAKE2b wallet with random entropy', async () => {\r
const wallet = await Blake2bWallet.create(NANO_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
- const accounts = await wallet.accounts()\r
\r
assert.ok('id' in wallet)\r
assert.ok('mnemonic' in wallet)\r
assert.ok('seed' in wallet)\r
- assert.ok(accounts[0] instanceof Account)\r
})\r
\r
- it('should generate the correct wallet with the given test vector', async () => {\r
- const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, '6CAF5A42BB8074314AAE20295975ECE663BE7AAD945A73613D193B0CC41C7970')\r
- await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
- const accounts = await wallet.accounts()\r
-\r
- assert.ok('mnemonic' in wallet)\r
- assert.ok('seed' in wallet)\r
- assert.ok(accounts[0] instanceof Account)\r
- assert.equal(wallet.mnemonic, 'hole kiss mouse jacket also board click series citizen slight kite smoke desk diary rent mercy inflict antique edge invite slush athlete total brain')\r
- assert.equal(wallet.seed, '1ACCDD4C25E06E47310D0C62C290EC166071D024352E003E5366E8BA6BA523F2A0CB34116AC55A238A886778880A9B2A547112FD7CFFADE81D8D8D084CCB7D36')\r
- assert.equal(accounts[0].privateKey, 'EB18B748BCC48F824CF8A1FE92F7FC93BFC6F2A1EB9C1D40FA26D335D8A0C30F')\r
- assert.equal(accounts[0].publicKey, 'A9EF7BBC004813CF75C5FC5C582066182D5C9CFFD42EB7EB81CEFEA8E78C47C5')\r
- assert.equal(accounts[0].address, 'nano_3chhhgy11k1msxtwdz4wd1i8e83fdkghzo3gpzor5mqyo5mrrjy79zpw1g34')\r
+ it('BIP-44 replace invalid salt with empty string', async () => {\r
+ const invalidArgs = [null, true, false, 0, 1, 2, { "foo": "bar" }]\r
+ for (const arg of invalidArgs) {\r
+ await assert.doesNotReject(Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD, arg), `Rejected ${arg}`)\r
+ }\r
})\r
\r
- it('should generate the correct wallet with the given test vector and a seed password', async () => {\r
- const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, '6CAF5A42BB8074314AAE20295975ECE663BE7AAD945A73613D193B0CC41C7970', NANO_TEST_VECTORS.PASSWORD)\r
- await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
- const accounts = await wallet.accounts()\r
-\r
- assert.ok('mnemonic' in wallet)\r
- assert.ok('seed' in wallet)\r
- assert.ok(accounts[0] instanceof Account)\r
-\r
- assert.equal(wallet.mnemonic, 'hole kiss mouse jacket also board click series citizen slight kite smoke desk diary rent mercy inflict antique edge invite slush athlete total brain')\r
- assert.notEqual(wallet.seed, '1ACCDD4C25E06E47310D0C62C290EC166071D024352E003E5366E8BA6BA523F2A0CB34116AC55A238A886778880A9B2A547112FD7CFFADE81D8D8D084CCB7D36')\r
- assert.notEqual(accounts[0].privateKey, 'EB18B748BCC48F824CF8A1FE92F7FC93BFC6F2A1EB9C1D40FA26D335D8A0C30F')\r
- assert.notEqual(accounts[0].publicKey, 'A9EF7BBC004813CF75C5FC5C582066182D5C9CFFD42EB7EB81CEFEA8E78C47C5')\r
- assert.notEqual(accounts[0].address, 'nano_3chhhgy11k1msxtwdz4wd1i8e83fdkghzo3gpzor5mqyo5mrrjy79zpw1g34')\r
-\r
- assert.equal(wallet.seed, '146E3E2A0530848C9174D45ECEC8C3F74A7BE3F1EE832F92EB6227284121EB2E48A6B8FC469403984CD5E8F0D1ED05777C78F458D0E98C911841590E5D645DC3')\r
- assert.equal(accounts[0].privateKey, '2D5851BD5A89B8C943078BE6AD5BBEE8AEAB77D6A4744C20D1B87D78E3286B93')\r
- assert.equal(accounts[0].publicKey, '923B6C7E281C1C5529FD2DC848117781216A1753CFD487FC34009F3591E636D7')\r
- assert.equal(accounts[0].address, 'nano_36jufjz4i91wcnnztdgab1aqh1b3fado9mynizy5a16z8payefpqo81zsshc')\r
+ it('fail when using new', () => {\r
+ assert.throws(() => new Bip44Wallet())\r
+ assert.throws(() => new Blake2bWallet())\r
+ assert.throws(() => new LedgerWallet())\r
})\r
\r
- it('should throw when given invalid entropy with an invalid length', async () => {\r
- assert.rejects(async () => await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, '6CAF5A42BB8074314AAE20295975ECE663BE7AAD945A73613D193B0CC41C797'))\r
- assert.rejects(async () => await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, '6CAF5A42BB8074314AAE20295975ECE663BE7AAD945A73613D193B0CC41C79701'))\r
- assert.rejects(async () => await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0.replaceAll(/./g, 'x')))\r
+ it('fail without a password', async () => {\r
+ await assert.rejects(Bip44Wallet.create())\r
+ await assert.rejects(Blake2bWallet.create())\r
})\r
-})\r
\r
-describe('ledger wallet', { skip: true }, async () => {\r
- it('should connect to ledger', async () => {\r
+ it('connect to ledger', { skip: true }, async () => {\r
const wallet = await LedgerWallet.create()\r
assert.ok(wallet)\r
})\r