-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* New feature: verify signatures with the public key * New feature: convert nano address to a public key * Add documentation about how to verify ownership of user's Nano address by doing a signature challenge * npm audit fix
- Loading branch information
Showing
10 changed files
with
230 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,6 +174,32 @@ const data = { | |
|
||
// Returns a correctly formatted and signed block ready to be sent to the blockchain | ||
const signedBlock = block.representative(data, privateKey) | ||
``` | ||
#### Verifying signatures | ||
Cryptocurrencies rely on public key cryptographgy. This means that you can use the public key to validate the signature of the block that is signed with the private key. | ||
```javascript | ||
import { tools } from 'nanocurrency-web' | ||
|
||
const valid = tools.verifyBlock(publicKey, block) | ||
``` | ||
##### Using signature verification to prove ownership of the address | ||
You are able to challenge an user to prove ownership of a Nano address simply by making the user sign any string with the private key and validating the signature. | ||
```javascript | ||
import { tools } from 'nanocurrency-web' | ||
|
||
const nanoAddress = 'nano_1pu7p5n3ghq1i1p4rhmek41f5add1uh34xpb94nkbxe8g4a6x1p69emk8y1d' | ||
const privateKey = '3be4fc2ef3f3b7374e6fc4fb6e7bb153f8a2998b3b3dab50853eabe128024143' | ||
const data = 'sign this' | ||
|
||
// Make the user sign the data | ||
const signature = tools.sign(privateKey, data) | ||
|
||
// Infer the user's public key from the address (if not already known) | ||
const publicKey = tools.addressToPublicKey(nanoAddress) | ||
|
||
// Verify the signature using the public key, the signature and the original data | ||
const validSignature = tools.verify(publicKey, signature, data) | ||
|
||
``` | ||
#### Converting units | ||
|
@@ -217,7 +243,7 @@ const valid = tools.validateMnemonic('edge defense waste choose enrich upon flee | |
### In web | ||
```html | ||
<script src="https://unpkg.com/[email protected].2" type="text/javascript"></script> | ||
<script src="https://unpkg.com/[email protected].3" type="text/javascript"></script> | ||
<script type="text/javascript"> | ||
NanocurrencyWeb.wallet.generate(...); | ||
</script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "nanocurrency-web", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"description": "Toolkit for Nano cryptocurrency client side offline integrations", | ||
"author": "Miro Metsänheimo <[email protected]>", | ||
"license": "MIT", | ||
|
Oops, something went wrong.