From 1134d96e28baa4096bfa63e8ae44fe6985993df6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Miro=20Mets=C3=A4nheimo?= Date: Tue, 30 Mar 2021 22:08:42 +0300 Subject: [PATCH] Version 1.3.2 * Allow work to be omitted since it's not required for the signature * npm audit fix --- README.md | 2 +- lib/block-signer.ts | 18 +++++------------ package-lock.json | 34 +++++++++++++++++++------------ package.json | 2 +- test/test.js | 49 ++++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 74 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index a4bcd3d..d7d1133 100644 --- a/README.md +++ b/README.md @@ -217,7 +217,7 @@ const valid = tools.validateMnemonic('edge defense waste choose enrich upon flee ### In web ```html - + diff --git a/lib/block-signer.ts b/lib/block-signer.ts index 6e41e94..15ea365 100644 --- a/lib/block-signer.ts +++ b/lib/block-signer.ts @@ -49,10 +49,6 @@ export default class BlockSigner { throw new Error('No frontier') } - if (!data.work) { - throw new Error('No work') - } - if (!privateKey) { throw new Error('Please input the private key to sign the block') } @@ -83,7 +79,7 @@ export default class BlockSigner { balance: newBalanceRaw, link: link, signature: signature, - work: data.work, + work: data.work || '', } } @@ -120,10 +116,6 @@ export default class BlockSigner { throw new Error('Frontier is not set') } - if (!data.work) { - throw new Error('Work is not set') - } - if (!privateKey) { throw new Error('Please input the private key to sign the block') } @@ -154,7 +146,7 @@ export default class BlockSigner { balance: newBalanceRaw, link: link, signature: signature, - work: data.work, + work: data.work || '', } } @@ -184,7 +176,7 @@ export interface ReceiveBlock { frontier: string representativeAddress: string amountRaw: string - work: string + work?: string } export interface SendBlock { @@ -194,7 +186,7 @@ export interface SendBlock { representativeAddress: string frontier: string amountRaw: string - work: string + work?: string } export interface RepresentativeBlock { @@ -202,7 +194,7 @@ export interface RepresentativeBlock { address: string representativeAddress: string frontier: string - work: string + work?: string } export interface SignedBlock { diff --git a/package-lock.json b/package-lock.json index c2c043b..21a4857 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "nanocurrency-web", - "version": "1.3.1", + "version": "1.3.2", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1123,18 +1123,26 @@ } }, "elliptic": { - "version": "6.5.3", - "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.3.tgz", - "integrity": "sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==", + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz", + "integrity": "sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==", "dev": true, "requires": { - "bn.js": "^4.4.0", - "brorand": "^1.0.1", + "bn.js": "^4.11.9", + "brorand": "^1.1.0", "hash.js": "^1.0.0", - "hmac-drbg": "^1.0.0", - "inherits": "^2.0.1", - "minimalistic-assert": "^1.0.0", - "minimalistic-crypto-utils": "^1.0.0" + "hmac-drbg": "^1.0.1", + "inherits": "^2.0.4", + "minimalistic-assert": "^1.0.1", + "minimalistic-crypto-utils": "^1.0.1" + }, + "dependencies": { + "bn.js": { + "version": "4.12.0", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", + "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==", + "dev": true + } } }, "emoji-regex": { @@ -4520,9 +4528,9 @@ "dev": true }, "y18n": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", - "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.1.tgz", + "integrity": "sha512-wNcy4NvjMYL8gogWWYAO7ZFWFfHcbdbE57tZO8e4cbpj8tfUcwrwqSl3ad8HxpYWCdXcJUCeKKZS62Av1affwQ==", "dev": true }, "yallist": { diff --git a/package.json b/package.json index e3b345e..8418f38 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nanocurrency-web", - "version": "1.3.1", + "version": "1.3.2", "description": "Toolkit for Nano cryptocurrency client side offline integrations", "author": "Miro Metsänheimo ", "license": "MIT", diff --git a/test/test.js b/test/test.js index 6fb57be..4f77812 100644 --- a/test/test.js +++ b/test/test.js @@ -159,6 +159,7 @@ describe('derive more accounts from the same seed test', () => { describe('block signing tests using official test vectors', () => { it('should create a valid signature for a receive block', () => { + const work = 'c5cf86de24b24419' const result = block.receive({ walletBalanceRaw: '18618869000000000000000000000000', transactionHash: 'CBC911F57B6827649423C92C88C0C56637A4274FF019E77E24D61D12B5338783', @@ -166,12 +167,27 @@ describe('block signing tests using official test vectors', () => { representativeAddress: 'nano_1stofnrxuz3cai7ze75o174bpm7scwj9jn3nxsn8ntzg784jf1gzn1jjdkou', frontier: '92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D', amountRaw: '7000000000000000000000000000000', - work: 'c5cf86de24b24419', + work, }, '781186FB9EF17DB6E3D1056550D9FAE5D5BBADA6A6BC370E4CBB938B1DC71DA3') expect(result.signature.toUpperCase()).to.equal('F25D751AD0379A5718E08F3773DA6061A9E18842EF5615163C7F207B804CC2C5DD2720CFCE5FE6A78E4CC108DD9CAB65051526403FA2C24A1ED943BB4EA7880B') + expect(result.work).to.equal(work) + }) + + it('should create a valid signature for a receive block without work', () => { + const result = block.receive({ + walletBalanceRaw: '18618869000000000000000000000000', + transactionHash: 'CBC911F57B6827649423C92C88C0C56637A4274FF019E77E24D61D12B5338783', + toAddress: 'nano_1e5aqegc1jb7qe964u4adzmcezyo6o146zb8hm6dft8tkp79za3sxwjym5rx', + representativeAddress: 'nano_1stofnrxuz3cai7ze75o174bpm7scwj9jn3nxsn8ntzg784jf1gzn1jjdkou', + frontier: '92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D', + amountRaw: '7000000000000000000000000000000', + }, '781186FB9EF17DB6E3D1056550D9FAE5D5BBADA6A6BC370E4CBB938B1DC71DA3') + expect(result.signature.toUpperCase()).to.equal('F25D751AD0379A5718E08F3773DA6061A9E18842EF5615163C7F207B804CC2C5DD2720CFCE5FE6A78E4CC108DD9CAB65051526403FA2C24A1ED943BB4EA7880B') + expect(result.work).to.equal('') }) it('should create a valid signature for a send block', () => { + const work = 'fbffed7c73b61367' const result = block.send({ walletBalanceRaw: '5618869000000000000000000000000', fromAddress: 'nano_1e5aqegc1jb7qe964u4adzmcezyo6o146zb8hm6dft8tkp79za3sxwjym5rx', @@ -179,20 +195,47 @@ describe('block signing tests using official test vectors', () => { representativeAddress: 'nano_1stofnrxuz3cai7ze75o174bpm7scwj9jn3nxsn8ntzg784jf1gzn1jjdkou', frontier: '92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D', amountRaw: '2000000000000000000000000000000', - work: 'fbffed7c73b61367', + work, }, '781186FB9EF17DB6E3D1056550D9FAE5D5BBADA6A6BC370E4CBB938B1DC71DA3') expect(result.signature.toUpperCase()).to.equal('79240D56231EF1885F354473733AF158DC6DA50E53836179565A20C0BE89D473ED3FF8CD11545FF0ED162A0B2C4626FD6BF84518568F8BB965A4884C7C32C205') + expect(result.work).to.equal(work) + }) + + it('should create a valid signature for a send block without work', () => { + const result = block.send({ + walletBalanceRaw: '5618869000000000000000000000000', + fromAddress: 'nano_1e5aqegc1jb7qe964u4adzmcezyo6o146zb8hm6dft8tkp79za3sxwjym5rx', + toAddress: 'nano_1q3hqecaw15cjt7thbtxu3pbzr1eihtzzpzxguoc37bj1wc5ffoh7w74gi6p', + representativeAddress: 'nano_1stofnrxuz3cai7ze75o174bpm7scwj9jn3nxsn8ntzg784jf1gzn1jjdkou', + frontier: '92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D', + amountRaw: '2000000000000000000000000000000', + }, '781186FB9EF17DB6E3D1056550D9FAE5D5BBADA6A6BC370E4CBB938B1DC71DA3') + expect(result.signature.toUpperCase()).to.equal('79240D56231EF1885F354473733AF158DC6DA50E53836179565A20C0BE89D473ED3FF8CD11545FF0ED162A0B2C4626FD6BF84518568F8BB965A4884C7C32C205') + expect(result.work).to.equal('') }) it('should create a valid signature for a change rep block', () => { + const work = '0000000000000000' + const result = block.representative({ + walletBalanceRaw: '3000000000000000000000000000000', + address: 'nano_3igf8hd4sjshoibbbkeitmgkp1o6ug4xads43j6e4gqkj5xk5o83j8ja9php', + representativeAddress: 'nano_1anrzcuwe64rwxzcco8dkhpyxpi8kd7zsjc1oeimpc3ppca4mrjtwnqposrs', + frontier: '128106287002E595F479ACD615C818117FCB3860EC112670557A2467386249D4', + work, + }, '781186FB9EF17DB6E3D1056550D9FAE5D5BBADA6A6BC370E4CBB938B1DC71DA3') // Did not find a private key at nano docs for this address + expect(result.signature.toUpperCase()).to.equal('A3C3C66D6519CBC0A198E56855942DEACC6EF741021A1B11279269ADC587DE1DA53CD478B8A47553231104CF24D742E1BB852B0546B87038C19BAE20F9082B0D') + expect(result.work).to.equal(work) + }) + + it('should create a valid signature for a change rep block without work', () => { const result = block.representative({ walletBalanceRaw: '3000000000000000000000000000000', address: 'nano_3igf8hd4sjshoibbbkeitmgkp1o6ug4xads43j6e4gqkj5xk5o83j8ja9php', representativeAddress: 'nano_1anrzcuwe64rwxzcco8dkhpyxpi8kd7zsjc1oeimpc3ppca4mrjtwnqposrs', frontier: '128106287002E595F479ACD615C818117FCB3860EC112670557A2467386249D4', - work: '0000000000000000', }, '781186FB9EF17DB6E3D1056550D9FAE5D5BBADA6A6BC370E4CBB938B1DC71DA3') // Did not find a private key at nano docs for this address expect(result.signature.toUpperCase()).to.equal('A3C3C66D6519CBC0A198E56855942DEACC6EF741021A1B11279269ADC587DE1DA53CD478B8A47553231104CF24D742E1BB852B0546B87038C19BAE20F9082B0D') + expect(result.work).to.equal('') }) }) -- 2.34.1