import { Wallet } from 'libnemo'
const wallet = await Wallet.create(password)
-const wallet = await Wallet.import(password, mnemonic, salt?)
-const wallet = await Wallet.import(password, seed)
+const wallet = await Wallet.load(password, mnemonic, salt?)
+const wallet = await Wallet.load(password, seed)
const wallet = await Wallet.create(password)
-const wallet = await Wallet.import(password, seed)
-const wallet = await Wallet.import(password, mnemonic)
+const wallet = await Wallet.load(password, seed)
+const wallet = await Wallet.load(password, mnemonic)
```
```javascript
const { ADDRESS_0, BIP39_SEED, BLAKE2B_ADDRESS_1, BLAKE2B_PUBLIC_1, BLAKE2B_SEED, OPEN_BLOCK, PASSWORD, PRIVATE_0, RECEIVE_BLOCK, SEND_BLOCK } = NANO_TEST_VECTORS\r
\r
await test('sign open block with BLAKE2b wallet', async () => {\r
- const wallet = await Wallet.import('BLAKE2b', PASSWORD, BLAKE2B_SEED)\r
+ const wallet = await Wallet.load('BLAKE2b', PASSWORD, BLAKE2B_SEED)\r
await assert.resolves(wallet.unlock(PASSWORD))\r
\r
const block = new Block(BLAKE2B_ADDRESS_1, '0', OPEN_BLOCK.previous, OPEN_BLOCK.representative)\r
})\r
\r
await test('sign open block with BIP-44 wallet', async () => {\r
- const wallet = await Wallet.import('BIP-44', PASSWORD, BIP39_SEED)\r
+ const wallet = await Wallet.load('BIP-44', PASSWORD, BIP39_SEED)\r
await assert.resolves(wallet.unlock(PASSWORD))\r
\r
const block = new Block(ADDRESS_0, '0', OPEN_BLOCK.previous, OPEN_BLOCK.representative)\r
})\r
\r
await test('fail to sign open block with wallet when locked', async () => {\r
- const wallet = await Wallet.import('BIP-44', PASSWORD, BIP39_SEED)\r
+ const wallet = await Wallet.load('BIP-44', PASSWORD, BIP39_SEED)\r
const block = new Block(ADDRESS_0, '0', OPEN_BLOCK.previous, OPEN_BLOCK.representative)\r
.receive(OPEN_BLOCK.link, OPEN_BLOCK.balance)\r
\r
suite('Derive accounts from BIP-44 wallet', async () => {\r
\r
await test('derive the first account from the given BIP-44 seed', async () => {\r
- const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
+ const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const account = await wallet.account()\r
\r
})\r
\r
await test('derive low indexed accounts from the given BIP-44 seed', async () => {\r
- const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
+ const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const accounts = await wallet.accounts(1, 2)\r
\r
})\r
\r
await test('derive high indexed accounts from the given seed', async () => {\r
- const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
+ const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const accounts = await wallet.accounts(0x70000000, 0x7000000f)\r
\r
suite('Derive accounts from BLAKE2b wallet', async () => {\r
\r
await test('derive the second account from the given BLAKE2b seed', async () => {\r
- const wallet = await Wallet.import('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BLAKE2B_SEED)\r
+ const wallet = await Wallet.load('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BLAKE2B_SEED)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const account = await wallet.account(1)\r
\r
})\r
\r
await test('derive low indexed accounts from the given BLAKE2B seed', async () => {\r
- const wallet = await Wallet.import('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BLAKE2B_SEED)\r
+ const wallet = await Wallet.load('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BLAKE2B_SEED)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const accounts = await wallet.accounts(2, 3)\r
\r
})\r
\r
await test('derive high indexed accounts from the given seed', async () => {\r
- const wallet = await Wallet.import('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BLAKE2B_SEED)\r
+ const wallet = await Wallet.load('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BLAKE2B_SEED)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const accounts = await wallet.accounts(0x70000000, 0x7000000f)\r
\r
suite('Import wallets', async () => {\r
\r
await test('nano.org BIP-44 test vector mnemonic', async () => {\r
- const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
+ const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const account = await wallet.account()\r
\r
})\r
\r
await test('nano.org BIP-44 test vector seed with no mnemonic', async () => {\r
- const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
+ const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const account = await wallet.account()\r
\r
})\r
\r
await test('Trezor-derived BIP-44 entropy for 12-word mnemonic', async () => {\r
- const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.MNEMONIC_0)\r
+ const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.MNEMONIC_0)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const account = await wallet.account()\r
\r
})\r
\r
await test('Trezor-derived BIP-44 entropy for 15-word mnemonic', async () => {\r
- const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.MNEMONIC_1)\r
+ const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.MNEMONIC_1)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const account = await wallet.account()\r
\r
})\r
\r
await test('Trezor-derived BIP-44 entropy for 18-word mnemonic', async () => {\r
- const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.MNEMONIC_2)\r
+ const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.MNEMONIC_2)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const account = await wallet.account()\r
\r
})\r
\r
await test('Trezor-derived BIP-44 entropy for 21-word mnemonic', async () => {\r
- const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.MNEMONIC_3)\r
+ const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.MNEMONIC_3)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const account = await wallet.account()\r
\r
})\r
\r
await test('BIP-44 zero-string entropy', async () => {\r
- const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_0, TREZOR_TEST_VECTORS.PASSWORD)\r
+ const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_0, TREZOR_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const accounts = await wallet.accounts(0, 3)\r
\r
})\r
\r
await test('BLAKE2b zero-string seed', async () => {\r
- const wallet = await Wallet.import('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_0)\r
+ const wallet = await Wallet.load('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_0)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const accounts = await wallet.accounts(0, 3)\r
\r
})\r
\r
await test('Trezor-derived BLAKE2b test vectors verified with third-party libraries', async () => {\r
- const wallet = await Wallet.import('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_1)\r
+ const wallet = await Wallet.load('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_1)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const accounts = await wallet.accounts(0, 1)\r
\r
})\r
\r
await test('BLAKE2b seed creates identical wallet as its derived mnemonic', async () => {\r
- const wallet = await Wallet.import('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_2)\r
+ const wallet = await Wallet.load('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_2)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const walletAccount = await wallet.account()\r
\r
assert.ok(await wallet.verify(TREZOR_TEST_VECTORS.MNEMONIC_2))\r
assert.ok(await wallet.verify(TREZOR_TEST_VECTORS.ENTROPY_2))\r
\r
- const imported = await Wallet.import('BLAKE2b', TREZOR_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_2)\r
+ const imported = await Wallet.load('BLAKE2b', TREZOR_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_2)\r
await imported.unlock(TREZOR_TEST_VECTORS.PASSWORD)\r
const importedAccount = await imported.account()\r
\r
})\r
\r
await test('BLAKE2b mnemonic for maximum seed value', async () => {\r
- const wallet = await Wallet.import('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_3)\r
+ const wallet = await Wallet.load('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_3)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const account = await wallet.account()\r
\r
})\r
\r
await test('Reject invalid seed', async () => {\r
- await assert.rejects(Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, '6CAF5A42BB8074314AAE20295975ECE663BE7AAD945A73613D193B0CC41C797'))\r
- await assert.rejects(Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, '6CAF5A42BB8074314AAE20295975ECE663BE7AAD945A73613D193B0CC41C79701'))\r
- await assert.rejects(Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0.replaceAll(/./g, 'x')))\r
+ await assert.rejects(Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, '6CAF5A42BB8074314AAE20295975ECE663BE7AAD945A73613D193B0CC41C797'))\r
+ await assert.rejects(Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, '6CAF5A42BB8074314AAE20295975ECE663BE7AAD945A73613D193B0CC41C79701'))\r
+ await assert.rejects(Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0.replaceAll(/./g, 'x')))\r
})\r
\r
await test('Reject invalid length seed', async () => {\r
- await assert.rejects(Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED + 'f'),\r
+ await assert.rejects(Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED + 'f'),\r
`Expected a ${NANO_TEST_VECTORS.BIP39_SEED.length}-character seed, but received ${NANO_TEST_VECTORS.BIP39_SEED.length + 1}-character string.`)\r
- await assert.rejects(Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED.slice(0, -1)),\r
+ await assert.rejects(Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED.slice(0, -1)),\r
`Expected a ${NANO_TEST_VECTORS.BIP39_SEED.length}-character seed, but received ${NANO_TEST_VECTORS.BIP39_SEED.length - 1}-character string.`)\r
})\r
\r
await test('Reject seed containing non-hex characters', async () => {\r
- await assert.rejects(Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.SEED_0.replace(/./, 'g')),\r
+ await assert.rejects(Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.SEED_0.replace(/./, 'g')),\r
'Seed contains invalid hexadecimal characters.')\r
- await assert.rejects(Wallet.import('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1.replace(/./, 'g')),\r
+ await assert.rejects(Wallet.load('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1.replace(/./, 'g')),\r
'Seed contains invalid hexadecimal characters.')\r
})\r
\r
await test('Import BIP-44 wallet from storage using a wallet-generated ID', async () => {\r
- const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
+ const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
const restored = await Wallet.restore(wallet.id)\r
\r
assert.ok('mnemonic' in restored)\r
})\r
\r
await test('Import BLAKE2B wallet from storage using a wallet-generated ID', async () => {\r
- const wallet = await Wallet.import('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0)\r
+ const wallet = await Wallet.load('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0)\r
const restored = await Wallet.restore(wallet.id)\r
\r
assert.ok('mnemonic' in restored)\r
})\r
\r
await test('export wallet IDs from storage and reimport them', async () => {\r
- const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
+ const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
const backups = await Wallet.export()\r
\r
assert.ok(backups.some(record => record.id === wallet.id))\r
suite('Lock and unlock wallets', async () => {\r
\r
await test('locking and unlocking a Bip44Wallet with a password', async () => {\r
- const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
+ const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
\r
assert.ok('mnemonic' in wallet)\r
assert.ok('seed' in wallet)\r
})\r
\r
await test('fail to unlock a Bip44Wallet with different passwords', async () => {\r
- const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
+ const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const lockResult = await wallet.lock()\r
\r
})\r
\r
await test('fail to unlock a Bip44Wallet with invalid input', async () => {\r
- const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
+ const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
\r
//@ts-expect-error\r
})\r
\r
await test('locking and unlocking a Blake2bWallet with a password', async () => {\r
- const wallet = await Wallet.import('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0)\r
+ const wallet = await Wallet.load('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0)\r
\r
assert.ok('mnemonic' in wallet)\r
assert.ok('seed' in wallet)\r
})\r
\r
await test('fail to unlock a Blake2bWallet with different passwords', async () => {\r
- const wallet = await Wallet.import('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1)\r
+ const wallet = await Wallet.load('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1)\r
\r
await assert.rejects(wallet.unlock(TREZOR_TEST_VECTORS.PASSWORD), { message: 'Failed to unlock wallet' })\r
assert.ok('mnemonic' in wallet)\r
})\r
\r
await test('fail to unlock a Blake2bWallet with no input', async () => {\r
- const wallet = await Wallet.import('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1)\r
+ const wallet = await Wallet.load('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1)\r
\r
//@ts-expect-error\r
await assert.rejects(wallet.unlock(), { message: 'Failed to unlock wallet' })\r
})\r
\r
await test('should verify a block using the public key', async () => {\r
- const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
+ const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const account = await wallet.account()\r
if (account.index == null) {\r
})\r
\r
await test('should reject a block using the wrong public key', async () => {\r
- const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
+ const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const account = await wallet.account()\r
if (account.index == null) {\r
})\r
\r
await test('sweeper fails gracefully for ineligible accounts', { skip: true }, async () => {\r
- const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
+ const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const results = await Tools.sweep(rpc, wallet, NANO_TEST_VECTORS.ADDRESS_1)\r
\r