From 747877d70ab9119257abc4db07898424ba8488c2 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Thu, 14 Aug 2025 08:55:31 -0700 Subject: [PATCH] Fix case insensitivity in signatures. --- src/lib/block.ts | 2 +- test/test.create-wallet.mjs | 4 ++-- test/test.ledger.mjs | 18 +++++++++--------- test/test.refresh-accounts.mjs | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/lib/block.ts b/src/lib/block.ts index eec69f9..aa8a31c 100644 --- a/src/lib/block.ts +++ b/src/lib/block.ts @@ -418,7 +418,7 @@ export class Block { } return new Promise(async (resolve, reject) => { try { - if (typeof input === 'string' && /^[A-F0-9]{64}$/.test(input)) { + if (typeof input === 'string' && /^[A-F0-9]{64}$/i.test(input)) { const signature = await NanoNaCl.detached(this.#hash(), hex.toBytes(input)) this.signature = bytes.toHex(signature) } else if (typeof input !== 'number' && typeof input !== 'string' && !(input instanceof Wallet)) { diff --git a/test/test.create-wallet.mjs b/test/test.create-wallet.mjs index 4b009a2..389830a 100644 --- a/test/test.create-wallet.mjs +++ b/test/test.create-wallet.mjs @@ -36,7 +36,7 @@ await Promise.all([ assert.ok('mnemonic' in wallet) assert.ok(/^(?:[a-z]{3,8} ){11,23}[a-z]{3,8}$/.test(wallet.mnemonic ?? '')) assert.ok('seed' in wallet) - assert.ok(/^[A-Fa-f0-9]{128}$/.test(wallet.seed ?? '')) + assert.ok(/^[A-F0-9]{128}$/i.test(wallet.seed ?? '')) assert.ok('id' in wallet) assert.ok(/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(wallet.id)) @@ -57,7 +57,7 @@ await Promise.all([ assert.ok('mnemonic' in wallet) assert.ok(/^(?:[a-z]{3,8} ){11,23}[a-z]{3,8}$/.test(wallet.mnemonic ?? '')) assert.ok('seed' in wallet) - assert.ok(/^[A-Fa-f0-9]{64}$/.test(wallet.seed ?? '')) + assert.ok(/^[A-F0-9]{64}$/i.test(wallet.seed ?? '')) assert.ok('id' in wallet) assert.ok(/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(wallet.id)) diff --git a/test/test.ledger.mjs b/test/test.ledger.mjs index 19edbac..cfd0caa 100644 --- a/test/test.ledger.mjs +++ b/test/test.ledger.mjs @@ -123,12 +123,12 @@ await Promise.all([ const signature = await wallet.sign(0, openBlock, 'hex') - assert.ok(/^[A-Fa-f0-9]{128}$/.test(signature)) + assert.ok(/^[A-F0-9]{128}$/i.test(signature)) await openBlock.sign(0) assert.exists(openBlock.signature) - assert.ok(/^[A-Fa-f0-9]{128}$/.test(openBlock.signature ?? '')) + assert.ok(/^[A-F0-9]{128}$/i.test(openBlock.signature ?? '')) assert.equal(signature, openBlock.signature) }) @@ -142,13 +142,13 @@ await Promise.all([ sendBlock = new Block(account, openBlock.balance, openBlock.hash, SEND_BLOCK.representative) .send(account.address, '0') - assert.ok(/^[A-Fa-f0-9]{64}$/.test(sendBlock.hash)) + assert.ok(/^[A-F0-9]{64}$/i.test(sendBlock.hash)) assert.nullish(sendBlock.signature) assert.equal(sendBlock.account.publicKey, account.publicKey) const signature = await wallet.sign(0, sendBlock, 'hex') - assert.ok(/^[A-Fa-f0-9]{128}$/.test(signature)) + assert.ok(/^[A-F0-9]{128}$/i.test(signature)) assert.equal(signature, sendBlock.signature) }) @@ -156,21 +156,21 @@ await Promise.all([ receiveBlock = new Block(account, sendBlock.balance, sendBlock.hash, RECEIVE_BLOCK.representative) .receive(sendBlock.hash, '0') - assert.ok(/^[A-Fa-f0-9]{64}$/.test(sendBlock.hash)) + assert.ok(/^[A-F0-9]{64}$/i.test(sendBlock.hash)) assert.nullish(receiveBlock.signature) assert.equal(receiveBlock.account.publicKey, account.publicKey) await receiveBlock.sign(0, sendBlock) assert.exists(receiveBlock.signature) - assert.ok(/^[A-Fa-f0-9]{128}$/.test(receiveBlock.signature ?? '')) + assert.ok(/^[A-F0-9]{128}$/i.test(receiveBlock.signature ?? '')) }) await test('fail to sign a send block from wallet without caching frontier block', async () => { sendBlock = new Block(account, receiveBlock.balance, receiveBlock.hash, SEND_BLOCK.representative) .send(account.address, '0') - assert.ok(/^[A-Fa-f0-9]{64}$/.test(sendBlock.hash)) + assert.ok(/^[A-F0-9]{64}$/i.test(sendBlock.hash)) assert.nullish(sendBlock.signature) assert.equal(sendBlock.account.publicKey, account.publicKey) @@ -181,14 +181,14 @@ await Promise.all([ sendBlock = new Block(account, receiveBlock.balance, receiveBlock.hash, SEND_BLOCK.representative) .send(account.address, '0') - assert.ok(/^[A-Fa-f0-9]{64}$/.test(sendBlock.hash)) + assert.ok(/^[A-F0-9]{64}$/i.test(sendBlock.hash)) assert.nullish(sendBlock.signature) assert.equal(sendBlock.account.publicKey, account.publicKey) const signature = await wallet.sign(0, sendBlock, 'hex', receiveBlock) assert.exists(sendBlock.signature) - assert.ok(/^[A-Fa-f0-9]{128}$/.test(sendBlock.signature ?? '')) + assert.ok(/^[A-F0-9]{128}$/i.test(sendBlock.signature ?? '')) assert.equal(signature, sendBlock.signature) }) diff --git a/test/test.refresh-accounts.mjs b/test/test.refresh-accounts.mjs index 0ddbb4e..2a0f270 100644 --- a/test/test.refresh-accounts.mjs +++ b/test/test.refresh-accounts.mjs @@ -44,7 +44,7 @@ await Promise.all([ assert.exists(account.frontier) assert.equal(typeof account.frontier, 'string') assert.notEqual(account.frontier, '') - assert.ok(/^[A-Fa-f0-9]{64}$/.test(account.frontier ?? '')) + assert.ok(/^[A-F0-9]{64}$/i.test(account.frontier ?? '')) assert.exists(account.representative) assert.notEqual(account.representative, '') -- 2.47.3