EventEmitter.defaultMaxListeners = navigator.hardwareConcurrency * 2
if (globalThis.sessionStorage == null) {
- const _sessionStorage = {}
+ let _sessionStorage = {}
Object.defineProperty(globalThis, 'sessionStorage', {
value: {
length: Object.entries(_sessionStorage).length,
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
+ //@ts-expect-error\r
await assert.doesNotReject(Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD, arg), `Rejected ${arg}`)\r
}\r
})\r
\r
it('fail when using new', async () => {\r
+ //@ts-expect-error\r
assert.throws(() => new Bip44Wallet())\r
+ //@ts-expect-error\r
assert.throws(() => new Blake2bWallet())\r
+ //@ts-expect-error\r
assert.throws(() => new LedgerWallet())\r
})\r
\r
it('fail without a password', async () => {\r
+ //@ts-expect-error\r
await assert.rejects(Bip44Wallet.create())\r
+ //@ts-expect-error\r
await assert.rejects(Blake2bWallet.create())\r
})\r
\r
const wallet = await Bip44Wallet.fromMnemonic(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
await assert.rejects(wallet.lock(), { message: 'Failed to lock wallet' })\r
assert.ok('mnemonic' in wallet)\r
assert.ok('seed' in wallet)\r
\r
await wallet.lock('password')\r
\r
+ //@ts-expect-error\r
await assert.rejects(wallet.unlock(), { message: 'Failed to unlock wallet' })\r
assert.ok('mnemonic' in wallet)\r
assert.ok('seed' in wallet)\r
const wallet = await Bip44Wallet.fromMnemonic(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
await assert.rejects(wallet.lock(1), { message: 'Failed to lock wallet' })\r
assert.ok('mnemonic' in wallet)\r
assert.ok('seed' in wallet)\r
\r
await wallet.lock(NANO_TEST_VECTORS.PASSWORD)\r
\r
+ //@ts-expect-error\r
await assert.rejects(wallet.unlock(1), { message: 'Failed to unlock wallet' })\r
assert.ok('mnemonic' in wallet)\r
assert.ok('seed' in wallet)\r
const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
\r
+ //@ts-expect-error\r
await assert.rejects(wallet.lock(), { message: 'Failed to lock wallet' })\r
assert.ok('mnemonic' in wallet)\r
assert.ok('seed' in wallet)\r
\r
await wallet.lock(NANO_TEST_VECTORS.PASSWORD)\r
\r
+ //@ts-expect-error\r
await assert.rejects(wallet.unlock(), { message: 'Failed to unlock wallet' })\r
assert.ok('mnemonic' in wallet)\r
assert.ok('seed' in wallet)\r
const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
\r
+ //@ts-expect-error\r
await assert.rejects(wallet.lock(1), { message: 'Failed to lock wallet' })\r
assert.ok('mnemonic' in wallet)\r
assert.ok('seed' in wallet)\r
\r
await wallet.lock(NANO_TEST_VECTORS.PASSWORD)\r
\r
+ //@ts-expect-error\r
await assert.rejects(wallet.unlock(1), { message: 'Failed to unlock wallet' })\r
assert.ok('mnemonic' in wallet)\r
assert.ok('seed' in wallet)\r
it('should return empty address array for blank contact names', () => {
const rolodex = new Rolodex()
+ //@ts-expect-error
assert.equal(Array.isArray(rolodex.getAddresses(undefined)), true)
+ //@ts-expect-error
assert.equal(rolodex.getAddresses(undefined).length, 0)
+ //@ts-expect-error
assert.equal(Array.isArray(rolodex.getAddresses(null)), true)
+ //@ts-expect-error
assert.equal(rolodex.getAddresses(null).length, 0)
assert.equal(Array.isArray(rolodex.getAddresses('')), true)
assert.equal(rolodex.getAddresses('').length, 0)
it('should return null for a blank address', async () => {
const rolodex = new Rolodex()
await rolodex.add('JohnDoe', NANO_TEST_VECTORS.ADDRESS_0)
+ //@ts-expect-error
assert.equal(rolodex.getName(undefined), null)
+ //@ts-expect-error
assert.notEqual(rolodex.getName(undefined), undefined)
+ //@ts-expect-error
assert.equal(rolodex.getName(null), null)
+ //@ts-expect-error
assert.notEqual(rolodex.getName(null), undefined)
assert.equal(rolodex.getName(''), null)
assert.notEqual(rolodex.getName(''), undefined)
describe('rolodex exceptions', async () => {
it('should throw if adding no data', async () => {
const rolodex = new Rolodex()
+ //@ts-expect-error
await assert.rejects(rolodex.add())
})
it('should throw if passed no address', async () => {
const rolodex = new Rolodex()
+ //@ts-expect-error
await assert.rejects(rolodex.add('JohnDoe'))
+ //@ts-expect-error
await assert.rejects(rolodex.add('JohnDoe', undefined))
+ //@ts-expect-error
await assert.rejects(rolodex.add('JohnDoe', null))
await assert.rejects(rolodex.add('JohnDoe', ''))
})
it('should throw if name is blank', async () => {
const rolodex = new Rolodex()
+ //@ts-expect-error
await assert.rejects(rolodex.add(undefined, NANO_TEST_VECTORS.ADDRESS_0))
+ //@ts-expect-error
await assert.rejects(rolodex.add(null, NANO_TEST_VECTORS.ADDRESS_0))
await assert.rejects(rolodex.add('', NANO_TEST_VECTORS.ADDRESS_0))
})
const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)
-const node = new Rpc(process.env.NODE_URL, process.env.API_KEY_NAME, process.env.API_KEY_VALUE)
+const node = new Rpc(process.env.NODE_URL ?? '', process.env.API_KEY_NAME)
const skip = true
assert.notEqual(account.balance, undefined)
assert.notEqual(account.balance, null)
assert.notEqual(account.balance, '')
- assert.notEqual(account.balance < 0, true)
+ assert.notEqual(account.balance && account.balance < 0, true)
assert.equal(typeof account.frontier, 'string')
assert.notEqual(account.frontier, undefined)
assert.notEqual(account.frontier, null)
assert.notEqual(account.frontier, '')
- assert.match(account.frontier, /^[0-9A-F]{64}$/i)
+ assert.match(account.frontier ?? '', /^[0-9A-F]{64}$/i)
- assert.equal(account.representative.constructor, Account)
+ assert.equal(account.representative && account.representative.constructor, Account)
assert.notEqual(account.representative, undefined)
assert.notEqual(account.representative, null)
assert.notEqual(account.representative, '')
- assert.notEqual(account.representative.address, undefined)
- assert.notEqual(account.representative.address, null)
- assert.notEqual(account.representative.address, '')
+ assert.notEqual(account.representative?.address, undefined)
+ assert.notEqual(account.representative?.address, null)
+ assert.notEqual(account.representative?.address, '')
})
it('should throw when refreshing unopened account', async () => {
})
it('should throw on invalid node URL', async () => {
+ //@ts-expect-error
await assert.rejects(wallet.getNextNewAccount())
+ //@ts-expect-error
await assert.rejects(wallet.getNextNewAccount(null))
+ //@ts-expect-error
await assert.rejects(wallet.getNextNewAccount(1))
+ //@ts-expect-error
await assert.rejects(wallet.getNextNewAccount(''))
+ //@ts-expect-error
await assert.rejects(wallet.getNextNewAccount('foo'))
})
it('should throw on invalid batch size', async () => {
+ //@ts-expect-error
await assert.rejects(wallet.getNextNewAccount(node, null))
await assert.rejects(wallet.getNextNewAccount(node, -1))
+ //@ts-expect-error
await assert.rejects(wallet.getNextNewAccount(node, ''))
+ //@ts-expect-error
await assert.rejects(wallet.getNextNewAccount(node, 'foo'))
+ //@ts-expect-error
await assert.rejects(wallet.getNextNewAccount(node, { 'foo': 'bar' }))
})
})
work,\r
)\r
await block.sign('781186FB9EF17DB6E3D1056550D9FAE5D5BBADA6A6BC370E4CBB938B1DC71DA3') // Did not find a private key at nano docs for this address\r
- assert.equal(block.signature.toUpperCase(), 'A3C3C66D6519CBC0A198E56855942DEACC6EF741021A1B11279269ADC587DE1DA53CD478B8A47553231104CF24D742E1BB852B0546B87038C19BAE20F9082B0D')\r
+ assert.equal(block.signature?.toUpperCase(), 'A3C3C66D6519CBC0A198E56855942DEACC6EF741021A1B11279269ADC587DE1DA53CD478B8A47553231104CF24D742E1BB852B0546B87038C19BAE20F9082B0D')\r
assert.equal(block.work, work)\r
})\r
\r
'F3C1D7B6EE97DA09D4C00538CEA93CBA5F74D78FD3FBE71347D2DFE7E53DF327'\r
)\r
await block.sign(NANO_TEST_VECTORS.PRIVATE_0)\r
- assert.equal(block.signature.toUpperCase(), '2BD2F905E74B5BEE3E2277CED1D1E3F7535E5286B6E22F7B08A814AA9E5C4E1FEA69B61D60B435ADC2CE756E6EE5F5BE7EC691FE87E024A0B22A3D980CA5B305')\r
+ assert.equal(block.signature?.toUpperCase(), '2BD2F905E74B5BEE3E2277CED1D1E3F7535E5286B6E22F7B08A814AA9E5C4E1FEA69B61D60B435ADC2CE756E6EE5F5BE7EC691FE87E024A0B22A3D980CA5B305')\r
assert.equal(block.work, '')\r
})\r
})\r
\r
const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
-const rpc = new Rpc(process.env.NODE_URL, process.env.API_KEY_NAME, process.env.API_KEY_VALUE)\r
+const rpc = new Rpc(process.env.NODE_URL ?? '', process.env.API_KEY_NAME)\r
\r
describe('unit conversion tests', async () => {\r
it('should convert nano to raw', async () => {\r
'nano_1stofnrxuz3cai7ze75o174bpm7scwj9jn3nxsn8ntzg784jf1gzn1jjdkou',\r
'92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D',\r
)\r
- await sendBlock.sign(account.privateKey)\r
+ await sendBlock.sign(account.privateKey ?? '')\r
const valid = await sendBlock.verify(account.publicKey)\r
assert.equal(valid, true)\r
})\r
'nano_1stofnrxuz3cai7ze75o174bpm7scwj9jn3nxsn8ntzg784jf1gzn1jjdkou',\r
'92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D',\r
)\r
- await sendBlock.sign(account.privateKey)\r
+ await sendBlock.sign(account.privateKey ?? '')\r
\r
- sendBlock.account = new Account('nano_1q3hqecaw15cjt7thbtxu3pbzr1eihtzzpzxguoc37bj1wc5ffoh7w74gi6p')\r
+ sendBlock.account = Account.fromAddress('nano_1q3hqecaw15cjt7thbtxu3pbzr1eihtzzpzxguoc37bj1wc5ffoh7w74gi6p')\r
const valid = await sendBlock.verify(account.publicKey)\r
assert.equal(valid, false)\r
})\r
-\r
- it('should create a BLAKE2b hash of a single string', async () => {\r
- const hash = await Tools.hash('asd')\r
- assert.equal(hash, 'F787FBCDD2B4C6F6447921D6F163E8FDDFB83D08432430CACAAAB1BBEDD723FE')\r
- })\r
-\r
- it('should create a BLAKE2b hash of a string array', async () => {\r
- const hash = await Tools.hash(['asd'])\r
- assert.equal(hash, 'F787FBCDD2B4C6F6447921D6F163E8FDDFB83D08432430CACAAAB1BBEDD723FE')\r
- })\r
})\r
\r
describe('sweeper', async () => {\r
it('throws without required parameters', async () => {\r
+ //@ts-expect-error\r
await assert.rejects(Tools.sweep(),\r
{ message: 'Missing required sweep arguments' })\r
})\r