]> zoso.dev Git - libnemo.git/commitdiff
Version 1.3.2
authorMiro Metsänheimo <miro@metsanheimo.fi>
Tue, 30 Mar 2021 19:08:42 +0000 (22:08 +0300)
committerMiro Metsänheimo <miro@metsanheimo.fi>
Tue, 30 Mar 2021 19:08:42 +0000 (22:08 +0300)
* Allow work to be omitted since it's not required for the signature
* npm audit fix

README.md
lib/block-signer.ts
package-lock.json
package.json
test/test.js

index a4bcd3d2d39eb0776aa2464a6e7f9a646a5cd21f..d7d113337b56daafc0d59f47f929a3d05c13ee9f 100644 (file)
--- a/README.md
+++ b/README.md
@@ -217,7 +217,7 @@ const valid = tools.validateMnemonic('edge defense waste choose enrich upon flee
 ### In web
 
 ```html
-<script src="https://unpkg.com/nanocurrency-web@1.3.1" type="text/javascript"></script>
+<script src="https://unpkg.com/nanocurrency-web@1.3.2" type="text/javascript"></script>
 <script type="text/javascript">
     NanocurrencyWeb.wallet.generate(...);
 </script>
index 6e41e9405a1c30896765f594aef90f75f1b9a8fc..15ea3650064f116d996dbb31c41537bd32c3df15 100644 (file)
@@ -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 {
index c2c043bbb8e40c11e98795fed7825a1d270f02c3..21a485784d72e5edccedaf5e14e79f462f1f99e9 100644 (file)
@@ -1,6 +1,6 @@
 {
        "name": "nanocurrency-web",
-       "version": "1.3.1",
+       "version": "1.3.2",
        "lockfileVersion": 1,
        "requires": true,
        "dependencies": {
                        }
                },
                "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": {
                        "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": {
index e3b345e72740516aad574ee1f027c03fd89be33b..8418f38173a202cc156de73f1fa2061645005c1f 100644 (file)
@@ -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 <miro@metsanheimo.fi>",
        "license": "MIT",
index 6fb57be3295d7809a4783d1f122b7c2f99e263b2..4f77812c231ba7557e242f2a5c2e1a20737e91f3 100644 (file)
@@ -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('')
        })
 
 })