]> git.codecow.com Git - libnemo.git/commitdiff
Fix case insensitivity in signatures.
authorChris Duncan <chris@zoso.dev>
Thu, 14 Aug 2025 15:55:31 +0000 (08:55 -0700)
committerChris Duncan <chris@zoso.dev>
Thu, 14 Aug 2025 15:55:31 +0000 (08:55 -0700)
src/lib/block.ts
test/test.create-wallet.mjs
test/test.ledger.mjs
test/test.refresh-accounts.mjs

index eec69f9d90b972834005d1456cfe65e1d93e6723..aa8a31c8aadc4ed3e725173f87477ac0aea4b421 100644 (file)
@@ -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)) {
index 4b009a26094567c018f2db6586d00d3f0f76fad2..389830ae3be0c0ac4d815b7877a246fb05afc655 100644 (file)
@@ -36,7 +36,7 @@ await Promise.all([
                        assert.ok('mnemonic' in wallet)\r
                        assert.ok(/^(?:[a-z]{3,8} ){11,23}[a-z]{3,8}$/.test(wallet.mnemonic ?? ''))\r
                        assert.ok('seed' in wallet)\r
-                       assert.ok(/^[A-Fa-f0-9]{128}$/.test(wallet.seed ?? ''))\r
+                       assert.ok(/^[A-F0-9]{128}$/i.test(wallet.seed ?? ''))\r
 \r
                        assert.ok('id' in wallet)\r
                        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))\r
@@ -57,7 +57,7 @@ await Promise.all([
                        assert.ok('mnemonic' in wallet)\r
                        assert.ok(/^(?:[a-z]{3,8} ){11,23}[a-z]{3,8}$/.test(wallet.mnemonic ?? ''))\r
                        assert.ok('seed' in wallet)\r
-                       assert.ok(/^[A-Fa-f0-9]{64}$/.test(wallet.seed ?? ''))\r
+                       assert.ok(/^[A-F0-9]{64}$/i.test(wallet.seed ?? ''))\r
 \r
                        assert.ok('id' in wallet)\r
                        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))\r
index 19edbac9e243189fede7e4ac7948063ed1a19470..cfd0caa7bcbabc8c64deeb7550ca1a769ddeb20a 100644 (file)
@@ -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)
                })
 
index 0ddbb4e5e07052ef02d7664f4c9dba4c8e56be80..2a0f270ca92b238d35bf19a89c3ad59a6f5ad0da 100644 (file)
@@ -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, '')