From: Miro Metsänheimo Date: Sat, 18 Sep 2021 20:00:42 +0000 (+0300) Subject: Version 1.3.5 X-Git-Tag: v0.0.1~17 X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=64c6107ce0be1e864352063f157af44bc345989a;p=libnemo.git Version 1.3.5 * Expose the blake2b hashing function * Expose the public key to address function --- diff --git a/README.md b/README.md index cd006f2..ede8a45 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ npm install nanocurrency-web ### In web ```html - + diff --git a/index.ts b/index.ts index 2234ae7..4146b4c 100644 --- 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 { diff --git a/package-lock.json b/package-lock.json index b2f2a83..9d1b70d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "nanocurrency-web", - "version": "1.3.4", + "version": "1.3.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index b4d2d91..fc6af57 100644 --- a/package.json +++ b/package.json @@ -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 ", "license": "MIT", diff --git a/test/test.js b/test/test.js index 45abdf7..8187d30 100644 --- a/test/test.js +++ b/test/test.js @@ -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') + }) + })