Version 1.3.5
* Expose the blake2b hashing function * Expose the public key to address function
This commit is contained in:
parent
a54611534f
commit
64c6107ce0
5 changed files with 40 additions and 3 deletions
|
|
@ -33,7 +33,7 @@ npm install nanocurrency-web
|
||||||
### In web
|
### In web
|
||||||
|
|
||||||
```html
|
```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">
|
<script type="text/javascript">
|
||||||
NanocurrencyWeb.wallet.generate(...);
|
NanocurrencyWeb.wallet.generate(...);
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
24
index.ts
24
index.ts
|
|
@ -334,6 +334,30 @@ const tools = {
|
||||||
return Convert.ab2hex(publicKeyBytes).slice(0, 64)
|
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 {
|
export {
|
||||||
|
|
|
||||||
2
package-lock.json
generated
2
package-lock.json
generated
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "nanocurrency-web",
|
"name": "nanocurrency-web",
|
||||||
"version": "1.3.4",
|
"version": "1.3.5",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "nanocurrency-web",
|
"name": "nanocurrency-web",
|
||||||
"version": "1.3.4",
|
"version": "1.3.5",
|
||||||
"description": "Toolkit for Nano cryptocurrency client side offline integrations",
|
"description": "Toolkit for Nano cryptocurrency client side offline integrations",
|
||||||
"author": "Miro Metsänheimo <miro@metsanheimo.fi>",
|
"author": "Miro Metsänheimo <miro@metsanheimo.fi>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
||||||
13
test/test.js
13
test/test.js
|
|
@ -316,4 +316,17 @@ describe('Signer tests', () => {
|
||||||
expect(publicKey).to.equal('5b65b0e8173ee0802c2c3e6c9080d1a16b06de1176c938a924f58670904e82c4')
|
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')
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue