]> zoso.dev Git - libnemo.git/commitdiff
Version 1.3.5
authorMiro Metsänheimo <miro@metsanheimo.fi>
Sat, 18 Sep 2021 20:00:42 +0000 (23:00 +0300)
committerMiro Metsänheimo <miro@metsanheimo.fi>
Sat, 18 Sep 2021 20:00:42 +0000 (23:00 +0300)
* Expose the blake2b hashing function
* Expose the public key to address function

README.md
index.ts
package-lock.json
package.json
test/test.js

index cd006f21f999f527c7ca6efcaeb432b0c536d583..ede8a45991e7caa797135ed3b380ddefff753690 100644 (file)
--- a/README.md
+++ b/README.md
@@ -33,7 +33,7 @@ npm install nanocurrency-web
 ### In web
 
 ```html
-<script src="https://unpkg.com/nanocurrency-web@1.3.3" type="text/javascript"></script>
+<script src="https://unpkg.com/nanocurrency-web@1.3.5" type="text/javascript"></script>
 <script type="text/javascript">
     NanocurrencyWeb.wallet.generate(...);
 </script>
index 2234ae73b9556885b360c104e8cf42504b2aea6b..4146b4c7790ef58ecbea453e4fcedb45c306ee00 100644 (file)
--- a/index.ts
+++ b/index.ts
@@ -334,6 +334,30 @@ const tools = {
                return Convert.ab2hex(publicKeyBytes).slice(0, 64)
        },
 
+       /**
+        * Convert a public key to a Nano address
+        *
+        * @param {string} input Public key to convert
+        * @returns {string} the nano address
+        */
+       publicKeyToAddress: (input: string): string => {
+               return nanoAddress.deriveAddress(input)
+       },
+
+       /**
+        * Hash a string or array of strings with blake2b
+        *
+        * @param {string | string[]} input string to hash
+        * @returns {string} hashed string
+        */
+       blake2b: (input: string | string[]): string => {
+               if (Array.isArray(input)) {
+                       return Convert.ab2hex(signer.generateHash(input.map(Convert.stringToHex)))
+               } else {
+                       return Convert.ab2hex(signer.generateHash([Convert.stringToHex(input)]))
+               }
+       },
+
 }
 
 export {
index b2f2a8391b703161e86cc39cb376e49cac76d068..9d1b70df71a5b48802a5ca425b2a3181f6298dc5 100644 (file)
@@ -1,6 +1,6 @@
 {
        "name": "nanocurrency-web",
-       "version": "1.3.4",
+       "version": "1.3.5",
        "lockfileVersion": 1,
        "requires": true,
        "dependencies": {
index b4d2d918d0e3aea20d312ea3981b04c18b1e73ef..fc6af57d64e5a4400570dcf540455dc2ce83acec 100644 (file)
@@ -1,6 +1,6 @@
 {
        "name": "nanocurrency-web",
-       "version": "1.3.4",
+       "version": "1.3.5",
        "description": "Toolkit for Nano cryptocurrency client side offline integrations",
        "author": "Miro Metsänheimo <miro@metsanheimo.fi>",
        "license": "MIT",
index 45abdf7269f23946a3e9147c6ec3c78096d14954..8187d30367a72bf3b77b1b73e53f29d1f38d286c 100644 (file)
@@ -316,4 +316,17 @@ describe('Signer tests', () => {
                expect(publicKey).to.equal('5b65b0e8173ee0802c2c3e6c9080d1a16b06de1176c938a924f58670904e82c4')
        })
 
+       it('should convert a public key to a Nano address', () => {
+               const address = tools.publicKeyToAddress('5b65b0e8173ee0802c2c3e6c9080d1a16b06de1176c938a924f58670904e82c4')
+               expect(address).to.equal('nano_1pu7p5n3ghq1i1p4rhmek41f5add1uh34xpb94nkbxe8g4a6x1p69emk8y1d')
+       })
+
+       it('should create a blake2b hash', () => {
+               let hash = tools.blake2b('asd')
+               expect(hash).to.equal('f787fbcdd2b4c6f6447921d6f163e8fddfb83d08432430cacaaab1bbedd723fe')
+
+               hash = tools.blake2b(['asd'])
+               expect(hash).to.equal('f787fbcdd2b4c6f6447921d6f163e8fddfb83d08432430cacaaab1bbedd723fe')
+       })
+
 })