Version 1.3.5

* Expose the blake2b hashing function
* Expose the public key to address function
This commit is contained in:
Miro Metsänheimo 2021-09-18 23:00:42 +03:00
commit 64c6107ce0
5 changed files with 40 additions and 3 deletions

View file

@ -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>

View file

@ -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 {

2
package-lock.json generated
View file

@ -1,6 +1,6 @@
{
"name": "nanocurrency-web",
"version": "1.3.4",
"version": "1.3.5",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View 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",

View 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')
})
})