'use strict'\r
\r
import { assert, isNode, suite, test } from './GLOBALS.mjs'\r
-import { NANO_TEST_VECTORS } from './VECTORS.mjs'\r
+import { CUSTOM_TEST_VECTORS, NANO_TEST_VECTORS } from './VECTORS.mjs'\r
\r
+/**\r
+* @type {typeof import('../dist/types.d.ts').Account}\r
+*/\r
+let Account\r
/**\r
* @type {typeof import('../dist/types.d.ts').Block}\r
*/\r
*/\r
let Wallet\r
if (isNode) {\r
- ({ Block, Wallet } = await import('../dist/nodejs.min.js'))\r
+ ({ Account, Block, Wallet } = await import('../dist/nodejs.min.js'))\r
} else {\r
- ({ Block, Wallet } = await import('../dist/browser.min.js'))\r
+ ({ Account, Block, Wallet } = await import('../dist/browser.min.js'))\r
}\r
\r
await Promise.all([\r
\r
suite('Block signing using official test vectors', async () => {\r
const { ADDRESS_0, BIP39_SEED, BLAKE2B_ADDRESS_1, BLAKE2B_PUBLIC_1, BLAKE2B_SEED, OPEN_BLOCK, PASSWORD, PUBLIC_0, PRIVATE_0, RECEIVE_BLOCK, SEND_BLOCK } = NANO_TEST_VECTORS\r
+ const { LEDGER_ADDRESS_0, LEDGER_MNEMONIC, LEDGER_PRIVATE_0, LEDGER_PUBLIC_0, LEDGER_OPEN_BLOCK } = CUSTOM_TEST_VECTORS\r
\r
await test('sign open block with BLAKE2b wallet', async () => {\r
const wallet = await Wallet.load('BLAKE2b', PASSWORD, BLAKE2B_SEED)\r
assert.nullish(block.work)\r
})\r
\r
+ await test('sign Ledger-derived receive block', async () => {\r
+ const wallet = await Wallet.load('BIP-44', '', LEDGER_MNEMONIC)\r
+ await wallet.unlock('')\r
+ const account = await wallet.account()\r
+ assert.equal(account.publicKey, LEDGER_PUBLIC_0)\r
+ assert.equal(account.address, LEDGER_ADDRESS_0)\r
+ const block = new Block(LEDGER_OPEN_BLOCK.account, LEDGER_OPEN_BLOCK.balance, LEDGER_OPEN_BLOCK.previous, LEDGER_OPEN_BLOCK.representative)\r
+ .receive(LEDGER_OPEN_BLOCK.link, LEDGER_OPEN_BLOCK.balance)\r
+ assert.equal(block.hash, LEDGER_OPEN_BLOCK.hash)\r
+ await wallet.sign(0, block)\r
+ assert.equal(block.signature, LEDGER_OPEN_BLOCK.signature)\r
+ assert.ok(await block.verify(account.publicKey))\r
+ })\r
+\r
// skip since nano.org send block sample has receive block work difficulty\r
await test('sign send block', { skip: true }, async () => {\r
const block = await new Block(SEND_BLOCK.account, SEND_BLOCK.balance, SEND_BLOCK.previous, SEND_BLOCK.representative)\r
/* node:coverage disable */
suite('Ledger hardware wallet', { skip: false || isNode || Ledger.isUnsupported }, async () => {
- const { RECEIVE_BLOCK, SEND_BLOCK } = NANO_TEST_VECTORS
+ const { OPEN_BLOCK, RECEIVE_BLOCK, SEND_BLOCK } = NANO_TEST_VECTORS
let wallet, account, openBlock, sendBlock, receiveBlock
})
await test('sign open block from block', async () => {
- openBlock = new Block(account, '0', '0', RECEIVE_BLOCK.representative)
- .receive(RECEIVE_BLOCK.link, RECEIVE_BLOCK.balance)
+ openBlock = new Block(account, '0', '0', OPEN_BLOCK.representative)
+ .receive(OPEN_BLOCK.link, '0')
assert.ok(/^[A-F0-9]{64}$/i.test(openBlock.hash))
assert.nullish(openBlock.signature)
assert.equal(openBlock.account.publicKey, account.publicKey)
- const signature = await wallet.sign(0, openBlock, 'hex')
+ const signature = await wallet.sign(0, openBlock)
assert.ok(/^[A-F0-9]{128}$/i.test(signature))