button.after(hourglass)
try {
const result = await fn()
+ console.log('Click done, waiting 6 seconds to reset transient user activation timer...')
+ await new Promise(r => setTimeout(r, 6000))
resolve(result)
} catch (err) {
reject(err)
'Sign and autogen PoW when processing',\r
async () => block.sign(OPEN_BLOCK.key)\r
))\r
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
- await new Promise(r => setTimeout(r, 6000))\r
\r
assert.nullish(block.work)\r
const result = await assert.rejects(block.process(rpc))\r
'Sign with BLAKE2b',\r
async () => wallet.sign(1, block)\r
))\r
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
- await new Promise(r => setTimeout(r, 6000))\r
assert.ok(await block.verify(BLAKE2B_PUBLIC_1))\r
\r
await assert.resolves(wallet.destroy())\r
'Sign with BIP-44',\r
async () => wallet.sign(0, block)\r
))\r
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
- await new Promise(r => setTimeout(r, 6000))\r
assert.ok(await block.verify(PUBLIC_0))\r
\r
await assert.resolves(wallet.destroy())\r
'Sign with Exodus',\r
async () => wallet.sign(0, block)\r
))\r
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
- await new Promise(r => setTimeout(r, 6000))\r
assert.ok(await block.verify(EXODUS.PUBLIC_0))\r
\r
await assert.resolves(wallet.destroy())\r
'Fail to sign while locked',\r
async () => wallet.sign(0, block)\r
))\r
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
- await new Promise(r => setTimeout(r, 6000))\r
assert.ok(block.signature === undefined)\r
\r
await wallet.destroy()\r
'Sign open block with key',\r
async () => block.sign(OPEN_BLOCK.key)\r
))\r
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
- await new Promise(r => setTimeout(r, 6000))\r
assert.equal(block.hash, OPEN_BLOCK.hash)\r
assert.equal(block.signature, OPEN_BLOCK.signature)\r
})\r
'Sign receive block with key',\r
async () => block.sign(RECEIVE_BLOCK.key)\r
))\r
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
- await new Promise(r => setTimeout(r, 6000))\r
\r
assert.equal(block.hash, RECEIVE_BLOCK.hash)\r
assert.equal(block.signature, RECEIVE_BLOCK.signature)\r
'Sign receive block without work',\r
async () => block.sign(RECEIVE_BLOCK.key)\r
))\r
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
- await new Promise(r => setTimeout(r, 6000))\r
\r
assert.equal(block.hash, RECEIVE_BLOCK.hash)\r
assert.equal(block.signature, RECEIVE_BLOCK.signature)\r
'Sign Ledger-derived block using BIP-44 wallet',\r
async () => wallet.sign(0, block)\r
))\r
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
- await new Promise(r => setTimeout(r, 6000))\r
\r
assert.equal(block.signature, LEDGER_NANOS.OPEN_BLOCK.signature)\r
assert.ok(await block.verify(account.publicKey))\r
'Sign send block with key',\r
async () => block.sign(SEND_BLOCK.key)\r
))\r
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
- await new Promise(r => setTimeout(r, 6000))\r
\r
assert.equal(block.hash, SEND_BLOCK.hash)\r
assert.equal(block.signature, SEND_BLOCK.signature)\r
'Sign send block without work',\r
async () => block.sign(SEND_BLOCK.key)\r
))\r
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
- await new Promise(r => setTimeout(r, 6000))\r
\r
assert.equal(block.hash, SEND_BLOCK.hash)\r
assert.equal(block.signature, SEND_BLOCK.signature)\r
'Sign change block with key',\r
async () => block.sign('781186FB9EF17DB6E3D1056550D9FAE5D5BBADA6A6BC370E4CBB938B1DC71DA3') // Did not find a private key at nano docs for this address\r
))\r
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
- await new Promise(r => setTimeout(r, 6000))\r
\r
assert.equal(block.signature?.toUpperCase(), 'A3C3C66D6519CBC0A198E56855942DEACC6EF741021A1B11279269ADC587DE1DA53CD478B8A47553231104CF24D742E1BB852B0546B87038C19BAE20F9082B0D')\r
assert.equal(block.work, work)\r
'Sign change block without work',\r
async () => block.sign(PRIVATE_0)\r
))\r
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
- await new Promise(r => setTimeout(r, 6000))\r
\r
assert.equal(block.signature?.toUpperCase(), '2BD2F905E74B5BEE3E2277CED1D1E3F7535E5286B6E22F7B08A814AA9E5C4E1FEA69B61D60B435ADC2CE756E6EE5F5BE7EC691FE87E024A0B22A3D980CA5B305')\r
assert.nullish(block.work)\r
//@ts-expect-error\r
async () => block.sign()\r
))\r
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
- await new Promise(r => setTimeout(r, 6000))\r
assert.nullish(block.signature)\r
\r
await assert.rejects(click(\r
//@ts-expect-error\r
async () => block.sign(null)\r
))\r
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
- await new Promise(r => setTimeout(r, 6000))\r
assert.nullish(block.signature)\r
\r
await assert.rejects(click(\r
'fail to sign with invalid string length',\r
async () => block.sign('1')\r
))\r
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
- await new Promise(r => setTimeout(r, 6000))\r
assert.nullish(block.signature)\r
\r
await assert.rejects(click(\r
'fail to sign with invalid string characters',\r
async () => block.sign('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')\r
))\r
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
- await new Promise(r => setTimeout(r, 6000))\r
assert.nullish(block.signature)\r
})\r
})\r
/** @type {Block} */ openBlock,
/** @type {Block} */ sendBlock,
/** @type {Block} */ receiveBlock,
- restored
+ /** @type {Wallet} */ restored
try {
wallet = await Wallet.create('Ledger')
} catch {
await click(
'Reset permissions, then click to continue',
- async () => new Promise(r => setTimeout(r, 5000))
+ async () => { }
)
+ // should initially be locked and disconnected after 6s timeout in click()
await assert.rejects(wallet.unlock())
assert.equal(wallet.isLocked, true)
assert.equal(Ledger.status, 'DISCONNECTED')
await assert.rejects(click(
'Unlock device, quit Nano app, then click to continue',
- async () => wallet.unlock()
+ async () => {
+ wallet.unlock()
+ assert.equal(wallet.isLocked, true)
+ assert.equal(Ledger.status, 'BUSY')
+ assert.equal(status, 'BUSY')
+ }
))
+
+ // should still be locked and busy after 6s timeout in click()
assert.equal(wallet.isLocked, true)
assert.equal(Ledger.status, 'BUSY')
assert.equal(status, 'BUSY')
- await new Promise(async (resolve, reject) => {
- console.log('Waiting 6 seconds...')
- setTimeout(async () => {
- try {
- // should still be locked and busy
- assert.equal(wallet.isLocked, true)
- assert.equal(Ledger.status, 'BUSY')
- assert.equal(status, 'BUSY')
- resolve(null)
- } catch (err) {
- reject(err)
- }
- }, 6000)
- })
-
await assert.rejects(click(
'Open Nano app on device, allow device to auto-lock, then click to continue',
- async () => wallet.unlock()
+ async () => {
+ wallet.unlock()
+ assert.equal(wallet.isLocked, true)
+ assert.equal(Ledger.status, 'LOCKED')
+ }
))
+
+ // should still be locked after 6s timeout in click()
assert.equal(wallet.isLocked, true)
assert.equal(Ledger.status, 'LOCKED')
-
- await new Promise(async (resolve, reject) => {
- console.log('Waiting 6 seconds...')
- setTimeout(async () => {
- try {
- // should still be locked
- assert.equal(wallet.isLocked, true)
- assert.equal(Ledger.status, 'LOCKED')
- assert.equal(status, 'LOCKED')
- resolve(null)
- } catch (err) {
- reject(err)
- }
- }, 6000)
- })
+ assert.equal(status, 'LOCKED')
await assert.resolves(click(
'Unlock device, verify Nano app is open, then click to continue',
- async () => wallet.unlock()
+ async () => {
+ wallet.unlock()
+ assert.equal(wallet.isLocked, false)
+ assert.equal(Ledger.status, 'CONNECTED')
+ assert.equal(status, 'CONNECTED')
+ }
))
+
+ // should still be unlocked after 6s timeout in click()
assert.equal(wallet.isLocked, false)
assert.equal(Ledger.status, 'CONNECTED')
assert.equal(status, 'CONNECTED')
- await new Promise(async (resolve, reject) => {
- console.log('Waiting 6 seconds...')
- setTimeout(async () => {
- try {
- // should still be unlocked
- assert.equal(wallet.isLocked, false)
- assert.equal(Ledger.status, 'CONNECTED')
- assert.equal(status, 'CONNECTED')
- resolve(null)
- } catch (err) {
- reject(err)
- }
- }, 6000)
- })
-
await new Promise(async (resolve, reject) => {
console.log('Waiting 90 seconds...')
setTimeout(async () => {
await assert.resolves(click(
'Unlock device again, then click to continue',
- async () => { }
+ async () => {
+ assert.equal(wallet.isLocked, false)
+ assert.equal(Ledger.status, 'CONNECTED')
+ assert.equal(status, 'CONNECTED')
+ }
))
- assert.equal(wallet.isLocked, false)
- assert.equal(Ledger.status, 'CONNECTED')
- assert.equal(status, 'CONNECTED')
})
await test('switch between interfaces', { skip: false || isNode || navigator?.usb == null }, async () => {
await assert.resolves(click(
'Verify current interface is HID, switch to unlocked Bluetooth device, then click to continue',
- async () => wallet.config({ connection: 'ble' })
+ async () => {
+ wallet.config({ connection: 'ble' })
+ assert.equal(wallet.isLocked, true)
+ assert.equal(Ledger.status, 'BUSY')
+ }
))
- assert.equal(wallet.isLocked, true)
- assert.equal(Ledger.status, 'BUSY')
await assert.resolves(click(
'Verify current interface is BLE, switch back to unlocked USB device, then click to continue',
- async () => wallet.config({ connection: 'usb' })
+ async () => {
+ wallet.config({ connection: 'usb' })
+ assert.equal(wallet.isLocked, false)
+ assert.equal(Ledger.status, 'CONNECTED')
+ }
))
- assert.equal(wallet.isLocked, false)
- assert.equal(Ledger.status, 'CONNECTED')
await assert.resolves(click(
'Verify current interface is USB, then click to continue',
- async () => wallet.config({ connection: 'hid' })
+ async () => {
+ wallet.config({ connection: 'hid' })
+ assert.equal(wallet.isLocked, false)
+ assert.equal(Ledger.status, 'CONNECTED')
+ }
))
- assert.equal(wallet.isLocked, false)
- assert.equal(Ledger.status, 'CONNECTED')
})
await test('verify mnemonic', async () => {
await click(
'Click to finish Ledger tests by destroying wallet',
- async () => new Promise(r => setTimeout(r))
+ async () => {
+ await new Promise(r => setTimeout(r))
+ await assert.resolves(wallet.destroy())
+ await assert.rejects(wallet.unlock())
+ await wallet.destroy()
+ await restored.destroy()
+ }
)
- await assert.resolves(wallet.destroy())
- await assert.rejects(wallet.unlock())
- await wallet.destroy()
- await restored.destroy()
})
})
])
signature = await Tools.sign(NANO_TEST_VECTORS.PRIVATE_0 + NANO_TEST_VECTORS.PUBLIC_0, data)
}
))
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')
- await new Promise(r => setTimeout(r, 6000))
await assert.resolves(Rolodex.add('JohnDoe', NANO_TEST_VECTORS.ADDRESS_0))
const result = await Rolodex.verify('JohnDoe', signature, data)
signature = await Tools.sign(NANO_TEST_VECTORS.PRIVATE_0 + NANO_TEST_VECTORS.PUBLIC_0, data)
}
))
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')
- await new Promise(r => setTimeout(r, 6000))
await assert.resolves(Rolodex.add('JaneSmith', NANO_TEST_VECTORS.ADDRESS_1))
const result = await Rolodex.verify('JaneSmith', signature, data)
result = Tools.sign(NANO_TEST_VECTORS.PRIVATE_0 + NANO_TEST_VECTORS.PUBLIC_0, m)\r
}\r
))\r
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
- await new Promise(r => setTimeout(r, 6000))\r
\r
assert.equal(result.toLowerCase(), '0ceebbc0b9b3a270a30bad1eef4eddc0931effd8d5c0b7cab007fcc61f30d3ee9760cd93d7eeb5b654ecc0d9d17bc7a6d53bee54aa163a8272f425fb1184e30e')\r
})\r
signature = await wallet.sign(0, data)\r
}\r
))\r
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
- await new Promise(r => setTimeout(r, 6000))\r
assert.ok(await Tools.verify(account.publicKey, signature, data))\r
await assert.resolves(wallet.destroy())\r
})\r
'Sign to test subsequent verification success',\r
async () => sendBlock.sign(wallet, 0)\r
))\r
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
- await new Promise(r => setTimeout(r, 6000))\r
\r
assert.ok(await sendBlock.verify(account.publicKey))\r
await assert.resolves(wallet.destroy())\r
'Sign to test subsequent verification failure',\r
async () => sendBlock.sign(wallet, 0)\r
))\r
- console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
- await new Promise(r => setTimeout(r, 6000))\r
\r
assert.ok(await sendBlock.verify(account.publicKey))\r
\r