*/
let Block
/**
-* @type {typeof import('../dist/types.d.ts').Ledger}
-*/
-let Ledger
-/**
* @type {typeof import('../dist/types.d.ts').Rpc}
*/
let Rpc
+/**
+* @type {typeof import('../dist/types.d.ts').Wallet}
+*/
+let Wallet
if (isNode) {
- ({ Account, Block, Ledger, Rpc } = await import('../dist/nodejs.min.js'))
+ ({ Account, Block, Rpc, Wallet } = await import('../dist/nodejs.min.js'))
} else {
- ({ Account, Block, Ledger, Rpc } = await import('../dist/browser.min.js'))
+ ({ Account, Block, Rpc, Wallet } = await import('../dist/browser.min.js'))
}
const rpc = new Rpc(env.NODE_URL ?? '', env.API_KEY_NAME)
*/
await Promise.all([
/* node:coverage disable */
- suite('Ledger hardware wallet', { skip: false || isNode || Ledger.isUnsupported }, async () => {
+ suite('Ledger hardware wallet', { skip: false || isNode }, async () => {
const { OPEN_BLOCK, RECEIVE_BLOCK, SEND_BLOCK } = NANO_TEST_VECTORS
-
let wallet, account, openBlock, sendBlock, receiveBlock
+ try {
+ wallet = await Wallet.create('Ledger')
+ } catch {
+ return
+ }
await test('request permissions', async () => {
- wallet = await Ledger.create()
- let status = wallet.status
- assert.equal(status, 'DISCONNECTED')
- assert.equal(status, wallet.status)
-
- status = await click(
- 'Reset permissions, unlock device, quit Nano app, then click to continue',
- async () => wallet.connect()
- )
- assert.equal(status, 'BUSY')
- assert.equal(status, wallet.status)
-
- status = await click(
- 'Open Nano app on device, allow device to auto-lock, then click to continue',
- async () => wallet.connect()
- )
- assert.equal(status, 'LOCKED')
- assert.equal(status, wallet.status)
-
- status = await click(
- 'Unlock device, verify Nano app is open, then click to continue',
- async () => wallet.connect()
- )
- assert.equal(status, 'CONNECTED')
- assert.equal(status, wallet.status)
- })
-
- await test('get version', async () => {
- const { status, name, version } = await wallet.version()
-
- assert.equal(status, 'OK')
- assert.equal(name, 'Nano')
- assert.equal(version, '1.2.6')
+ await assert.rejects(wallet.unlock(), 'expect DISCONNECTED')
+
+ await assert.rejects(async () => {
+ await click(
+ 'Reset permissions, unlock device, quit Nano app, then click to continue',
+ async () => wallet.unlock()
+ )
+ }, 'expect BUSY')
+
+ await assert.rejects(async () => {
+ await click(
+ 'Open Nano app on device, allow device to auto-lock, then click to continue',
+ async () => wallet.unlock()
+ )
+ }, 'expect LOCKED')
+
+ await assert.resolves(async () => {
+ await click(
+ 'Unlock device, verify Nano app is open, then click to continue',
+ async () => wallet.unlock()
+ )
+ }, 'expect CONNECTED')
})
await test('get first account', async () => {
assert.exists(account.address)
assert.exists(account.publicKey)
assert.exists(account.balance)
- assert.ok(account.balance >= 0)
+ assert.ok(account.balance ?? -1 >= 0)
}
})
assert.nullish(openBlock.signature)
assert.equal(openBlock.account.publicKey, account.publicKey)
- const signature = await wallet.sign(0, openBlock)
+ await wallet.sign(0, openBlock)
- assert.ok(/^[A-F0-9]{128}$/i.test(signature))
+ assert.ok(/^[A-F0-9]{128}$/i.test(openBlock.signature ?? ''))
- await openBlock.sign(0)
+ await openBlock.sign(wallet, 0)
assert.exists(openBlock.signature)
assert.ok(/^[A-F0-9]{128}$/i.test(openBlock.signature ?? ''))
- assert.equal(signature, openBlock.signature)
- })
-
- await test('cache open block', async () => {
- const { status } = await wallet.updateCache(0, openBlock)
-
- assert.equal(status, 'OK')
})
await test('sign send block from wallet which requires cache to be up-to-date', async () => {
assert.nullish(sendBlock.signature)
assert.equal(sendBlock.account.publicKey, account.publicKey)
- const signature = await wallet.sign(0, sendBlock, 'hex')
+ await wallet.sign(0, sendBlock, openBlock)
- assert.ok(/^[A-F0-9]{128}$/i.test(signature))
- assert.equal(signature, sendBlock.signature)
+ assert.ok(/^[A-F0-9]{128}$/i.test(sendBlock.signature ?? ''))
})
await test('sign a receive block from block object which can accept previous block for cache', async () => {
assert.nullish(receiveBlock.signature)
assert.equal(receiveBlock.account.publicKey, account.publicKey)
- await receiveBlock.sign(0, sendBlock)
+ await receiveBlock.sign(wallet, 0, sendBlock)
assert.exists(receiveBlock.signature)
assert.ok(/^[A-F0-9]{128}$/i.test(receiveBlock.signature ?? ''))
assert.nullish(sendBlock.signature)
assert.equal(sendBlock.account.publicKey, account.publicKey)
- await assert.rejects(wallet.sign(0, sendBlock, 'hex'))
+ await assert.rejects(wallet.sign(0, sendBlock))
})
await test('sign a send block from wallet including frontier block for cache', async () => {
assert.nullish(sendBlock.signature)
assert.equal(sendBlock.account.publicKey, account.publicKey)
- const signature = await wallet.sign(0, sendBlock, 'hex', receiveBlock)
+ await wallet.sign(0, sendBlock, receiveBlock)
assert.exists(sendBlock.signature)
assert.ok(/^[A-F0-9]{128}$/i.test(sendBlock.signature ?? ''))
- assert.equal(signature, sendBlock.signature)
})
await test('destroy wallet', async () => {
await wallet.destroy()
- await assert.rejects(wallet.version())
+ await assert.rejects(wallet.unlock())
})
await test('fail when using new', async () => {