update npmignore to make the module smaller, update readme
This commit is contained in:
parent
06e7cf38db
commit
73f1de2b91
4 changed files with 84 additions and 74 deletions
|
|
@ -1,10 +1,11 @@
|
||||||
.git/
|
.git/
|
||||||
node_modules/
|
node_modules/
|
||||||
test/
|
test/
|
||||||
src/
|
lib/
|
||||||
.gitignore
|
.gitignore
|
||||||
.editorconfig
|
.editorconfig
|
||||||
.travis.yml
|
.travis.yml
|
||||||
webpack.config.json
|
webpack.config.js
|
||||||
tsconfig.json
|
tsconfig.json
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
index.ts
|
||||||
|
|
|
||||||
149
README.md
149
README.md
|
|
@ -1,7 +1,8 @@
|
||||||
# nanocurrency-web
|
# nanocurrency-web
|
||||||
|
|
||||||
[](https://travis-ci.org/numsu/nanocurrency-web-js)
|
[](https://travis-ci.org/numsu/nanocurrency-web-js)
|
||||||
[](https://github.com/numsu/nanocurrency-web-js/blob/master/LICENSE)
|
|
||||||
[](https://badge.fury.io/js/nanocurrency-web)
|
[](https://badge.fury.io/js/nanocurrency-web)
|
||||||
|
[](https://github.com/numsu/nanocurrency-web-js/blob/master/LICENSE)
|
||||||
|
|
||||||
Toolkit for Nano cryptocurrency client side offline implementations allowing you to build web- and mobile applications using Nano without compromising the user's keys by sending them out of their own device.
|
Toolkit for Nano cryptocurrency client side offline implementations allowing you to build web- and mobile applications using Nano without compromising the user's keys by sending them out of their own device.
|
||||||
|
|
||||||
|
|
@ -13,7 +14,7 @@ The toolkit supports creating and importing wallets and signing blocks on-device
|
||||||
* BIP39/44 private key derivation
|
* BIP39/44 private key derivation
|
||||||
* Mnemonic is compatible with the Ledger Nano implementation
|
* Mnemonic is compatible with the Ledger Nano implementation
|
||||||
* Import wallets with a mnemonic phrase or a seed
|
* Import wallets with a mnemonic phrase or a seed
|
||||||
* Sign send, receive and change blocks with a private key
|
* Sign send, receive and change representative blocks with a private key
|
||||||
* Runs in all web browsers and mobile frameworks built with Javascript
|
* Runs in all web browsers and mobile frameworks built with Javascript
|
||||||
* Convert Nano units
|
* Convert Nano units
|
||||||
|
|
||||||
|
|
@ -23,15 +24,16 @@ The toolkit supports creating and importing wallets and signing blocks on-device
|
||||||
|
|
||||||
### From NPM
|
### From NPM
|
||||||
|
|
||||||
```
|
```console
|
||||||
npm install nanocurrency-web
|
npm install nanocurrency-web
|
||||||
```
|
```
|
||||||
| WARNING: do not use any of the keys or addresses listed below to send real assets |
|
|
||||||
|
| WARNING: do not use any of the keys or addresses listed below to send real assets! |
|
||||||
| --- |
|
| --- |
|
||||||
|
|
||||||
|
#### Wallet handling
|
||||||
|
|
||||||
Wallet handling
|
```javascript
|
||||||
```
|
|
||||||
import { wallet } from 'nanocurrency-web'
|
import { wallet } from 'nanocurrency-web'
|
||||||
|
|
||||||
// Generates a new wallet with a mnemonic phrase, seed and an account
|
// Generates a new wallet with a mnemonic phrase, seed and an account
|
||||||
|
|
@ -48,114 +50,121 @@ const wallet = wallet.fromSeed(seed)
|
||||||
// Derive private keys for a seed, from and to are number indexes
|
// Derive private keys for a seed, from and to are number indexes
|
||||||
const accounts = wallet.accounts(seed, from, to)
|
const accounts = wallet.accounts(seed, from, to)
|
||||||
```
|
```
|
||||||
```
|
|
||||||
The returned wallet JSON format is as follows:
|
```javascript
|
||||||
|
// The returned wallet JSON format is as follows:
|
||||||
{
|
{
|
||||||
mnemonic: 'edge defense waste choose enrich upon flee junk siren film clown finish luggage leader kid quick brick print evidence swap drill paddle truly occur',
|
mnemonic: 'edge defense waste choose enrich upon flee junk siren film clown finish luggage leader kid quick brick print evidence swap drill paddle truly occur',
|
||||||
seed: '0dc285fde768f7ff29b66ce7252d56ed92fe003b605907f7a4f683c3dc8586d34a914d3c71fc099bb38ee4a59e5b081a3497b7a323e90cc68f67b5837690310c',
|
seed: '0dc285fde768f7ff29b66ce7252d56ed92fe003b605907f7a4f683c3dc8586d34a914d3c71fc099bb38ee4a59e5b081a3497b7a323e90cc68f67b5837690310c',
|
||||||
accounts: [
|
accounts: [
|
||||||
{
|
{
|
||||||
accountIndex: 0,
|
accountIndex: 0,
|
||||||
privateKey: '3be4fc2ef3f3b7374e6fc4fb6e7bb153f8a2998b3b3dab50853eabe128024143',
|
privateKey: '3be4fc2ef3f3b7374e6fc4fb6e7bb153f8a2998b3b3dab50853eabe128024143',
|
||||||
publicKey: '5b65b0e8173ee0802c2c3e6c9080d1a16b06de1176c938a924f58670904e82c4',
|
publicKey: '5b65b0e8173ee0802c2c3e6c9080d1a16b06de1176c938a924f58670904e82c4',
|
||||||
address: 'nano_1pu7p5n3ghq1i1p4rhmek41f5add1uh34xpb94nkbxe8g4a6x1p69emk8y1d'
|
address: 'nano_1pu7p5n3ghq1i1p4rhmek41f5add1uh34xpb94nkbxe8g4a6x1p69emk8y1d'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Signing a receive block
|
#### Signing a receive block
|
||||||
```
|
|
||||||
|
```javascript
|
||||||
import { block } from 'nanocurrency-web'
|
import { block } from 'nanocurrency-web'
|
||||||
|
|
||||||
const privateKey = '781186FB9EF17DB6E3D1056550D9FAE5D5BBADA6A6BC370E4CBB938B1DC71DA3';
|
const privateKey = '781186FB9EF17DB6E3D1056550D9FAE5D5BBADA6A6BC370E4CBB938B1DC71DA3';
|
||||||
const data = {
|
const data = {
|
||||||
// Your current balance in RAW
|
// Your current balance in RAW
|
||||||
walletBalanceRaw: '18618869000000000000000000000000',
|
walletBalanceRaw: '18618869000000000000000000000000',
|
||||||
|
|
||||||
// Your address
|
// Your address
|
||||||
toAddress: 'nano_3kyb49tqpt39ekc49kbej51ecsjqnimnzw1swxz4boix4ctm93w517umuiw8',
|
toAddress: 'nano_3kyb49tqpt39ekc49kbej51ecsjqnimnzw1swxz4boix4ctm93w517umuiw8',
|
||||||
|
|
||||||
// From wallet info
|
// From wallet info
|
||||||
representativeAddress: 'nano_1stofnrxuz3cai7ze75o174bpm7scwj9jn3nxsn8ntzg784jf1gzn1jjdkou',
|
representativeAddress: 'nano_1stofnrxuz3cai7ze75o174bpm7scwj9jn3nxsn8ntzg784jf1gzn1jjdkou',
|
||||||
|
|
||||||
// From wallet info
|
// From wallet info
|
||||||
frontier: '92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D',
|
frontier: '92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D',
|
||||||
|
|
||||||
// From the pending transaction
|
// From the pending transaction
|
||||||
transactionHash: 'CBC911F57B6827649423C92C88C0C56637A4274FF019E77E24D61D12B5338783',
|
transactionHash: 'CBC911F57B6827649423C92C88C0C56637A4274FF019E77E24D61D12B5338783',
|
||||||
|
|
||||||
// From the pending transaction in RAW
|
// From the pending transaction in RAW
|
||||||
amountRaw: '7000000000000000000000000000000',
|
amountRaw: '7000000000000000000000000000000',
|
||||||
|
|
||||||
// Generate the work server-side or with a DPOW service
|
// Generate the work server-side or with a DPOW service
|
||||||
work: 'c5cf86de24b24419',
|
work: 'c5cf86de24b24419',
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a correctly formatted and signed block ready to be sent to the blockchain
|
// Returns a correctly formatted and signed block ready to be sent to the blockchain
|
||||||
const signedBlock = block.receive(data, privateKey)
|
const signedBlock = block.receive(data, privateKey)
|
||||||
```
|
```
|
||||||
|
|
||||||
Signing a send block
|
#### Signing a send block
|
||||||
```
|
|
||||||
|
```javascript
|
||||||
import { block } from 'nanocurrency-web'
|
import { block } from 'nanocurrency-web'
|
||||||
|
|
||||||
const privateKey = '781186FB9EF17DB6E3D1056550D9FAE5D5BBADA6A6BC370E4CBB938B1DC71DA3';
|
const privateKey = '781186FB9EF17DB6E3D1056550D9FAE5D5BBADA6A6BC370E4CBB938B1DC71DA3';
|
||||||
const data = {
|
const data = {
|
||||||
// Current balance from wallet info
|
// Current balance from wallet info
|
||||||
walletBalanceRaw: '5618869000000000000000000000000',
|
walletBalanceRaw: '5618869000000000000000000000000',
|
||||||
|
|
||||||
// Your wallet address
|
// Your wallet address
|
||||||
fromAddress: 'nano_1e5aqegc1jb7qe964u4adzmcezyo6o146zb8hm6dft8tkp79za3sxwjym5rx',
|
fromAddress: 'nano_1e5aqegc1jb7qe964u4adzmcezyo6o146zb8hm6dft8tkp79za3sxwjym5rx',
|
||||||
|
|
||||||
// The address to send to
|
// The address to send to
|
||||||
toAddress: 'nano_1q3hqecaw15cjt7thbtxu3pbzr1eihtzzpzxguoc37bj1wc5ffoh7w74gi6p',
|
toAddress: 'nano_1q3hqecaw15cjt7thbtxu3pbzr1eihtzzpzxguoc37bj1wc5ffoh7w74gi6p',
|
||||||
|
|
||||||
// From wallet info
|
// From wallet info
|
||||||
representativeAddress: 'nano_1stofnrxuz3cai7ze75o174bpm7scwj9jn3nxsn8ntzg784jf1gzn1jjdkou',
|
representativeAddress: 'nano_1stofnrxuz3cai7ze75o174bpm7scwj9jn3nxsn8ntzg784jf1gzn1jjdkou',
|
||||||
|
|
||||||
// Previous block, from wallet info
|
// Previous block, from wallet info
|
||||||
frontier: '92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D',
|
frontier: '92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D',
|
||||||
|
|
||||||
// The amount to send in RAW
|
// The amount to send in RAW
|
||||||
amountRaw: '2000000000000000000000000000000',
|
amountRaw: '2000000000000000000000000000000',
|
||||||
|
|
||||||
// Generate work on server-side or with a DPOW service
|
// Generate work on server-side or with a DPOW service
|
||||||
work: 'fbffed7c73b61367',
|
work: 'fbffed7c73b61367',
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a correctly formatted and signed block ready to be sent to the blockchain
|
// Returns a correctly formatted and signed block ready to be sent to the blockchain
|
||||||
const signedBlock = block.send(data, privateKey)
|
const signedBlock = block.send(data, privateKey)
|
||||||
```
|
```
|
||||||
|
|
||||||
Signing a change representative block
|
#### Signing a change representative block
|
||||||
```
|
|
||||||
|
```javascript
|
||||||
import { block } from 'nanocurrency-web'
|
import { block } from 'nanocurrency-web'
|
||||||
|
|
||||||
const privateKey = '781186FB9EF17DB6E3D1056550D9FAE5D5BBADA6A6BC370E4CBB938B1DC71DA3';
|
const privateKey = '781186FB9EF17DB6E3D1056550D9FAE5D5BBADA6A6BC370E4CBB938B1DC71DA3';
|
||||||
const data = {
|
const data = {
|
||||||
// Your current balance, from account info
|
// Your current balance, from account info
|
||||||
walletBalanceRaw: '3000000000000000000000000000000',
|
walletBalanceRaw: '3000000000000000000000000000000',
|
||||||
|
|
||||||
// Your wallet address
|
// Your wallet address
|
||||||
address: 'nano_3igf8hd4sjshoibbbkeitmgkp1o6ug4xads43j6e4gqkj5xk5o83j8ja9php',
|
address: 'nano_3igf8hd4sjshoibbbkeitmgkp1o6ug4xads43j6e4gqkj5xk5o83j8ja9php',
|
||||||
|
|
||||||
// The new representative
|
// The new representative
|
||||||
representativeAddress: 'nano_1anrzcuwe64rwxzcco8dkhpyxpi8kd7zsjc1oeimpc3ppca4mrjtwnqposrs',
|
representativeAddress: 'nano_1anrzcuwe64rwxzcco8dkhpyxpi8kd7zsjc1oeimpc3ppca4mrjtwnqposrs',
|
||||||
|
|
||||||
// Previous block, from account info
|
// Previous block, from account info
|
||||||
frontier: '128106287002E595F479ACD615C818117FCB3860EC112670557A2467386249D4',
|
frontier: '128106287002E595F479ACD615C818117FCB3860EC112670557A2467386249D4',
|
||||||
|
|
||||||
// Generate work on the server side or with a DPOW service
|
// Generate work on the server side or with a DPOW service
|
||||||
work: '0000000000000000',
|
work: '0000000000000000',
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a correctly formatted and signed block ready to be sent to the blockchain
|
// Returns a correctly formatted and signed block ready to be sent to the blockchain
|
||||||
const signedBlock = block.representative(data, privateKey)
|
const signedBlock = block.representative(data, privateKey)
|
||||||
```
|
```
|
||||||
|
|
||||||
Converting units
|
#### Converting units
|
||||||
```
|
|
||||||
|
Supported unit values are RAW, NANO, MRAI, KRAI, RAW.
|
||||||
|
|
||||||
|
```javascript
|
||||||
import { converter } from 'nanocurrency-web'
|
import { converter } from 'nanocurrency-web'
|
||||||
|
|
||||||
// Convert 1 Nano to RAW
|
// Convert 1 Nano to RAW
|
||||||
|
|
@ -167,10 +176,10 @@ const converted = converter.convert('1000000000000000000000000000000', 'RAW', 'N
|
||||||
|
|
||||||
### In web
|
### In web
|
||||||
|
|
||||||
```
|
```html
|
||||||
<script src="https://unpkg.com/nanocurrency-web@1.0.5" type="text/javascript"></script>
|
<script src="https://unpkg.com/nanocurrency-web@1.0.6" type="text/javascript"></script>
|
||||||
<scrypt type="text/javascript">
|
<script type="text/javascript">
|
||||||
NanocurrencyWeb.wallet.generate(...);
|
NanocurrencyWeb.wallet.generate(...);
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -178,7 +187,7 @@ const converted = converter.convert('1000000000000000000000000000000', 'RAW', 'N
|
||||||
|
|
||||||
## Contributions
|
## Contributions
|
||||||
|
|
||||||
You are welcome to contribute to the module. To develop, use the following commands
|
You are welcome to contribute to the module. To develop, use the following commands.
|
||||||
|
|
||||||
* `npm install` to install all the dependencies
|
* `npm install` to install all the dependencies
|
||||||
* `npm run build` to build the Typescript code
|
* `npm run build` to build the Typescript code
|
||||||
|
|
@ -188,4 +197,4 @@ You are welcome to contribute to the module. To develop, use the following comma
|
||||||
|
|
||||||
If this helped you in your endeavours and you feel like supporting the developer, feel free to donate some Nano:
|
If this helped you in your endeavours and you feel like supporting the developer, feel free to donate some Nano:
|
||||||
|
|
||||||
`nano_35wfowmdqqe34uhmh4fo8i51kxkpr9ybahc4fb7yuzzxtez3oje4et5nk75d`
|
`nano_1wmcgzbqgbyyawsto6t37sc6y7pkekpctzp7n3ay6pcxcy717p5g79rpfj7e`
|
||||||
|
|
|
||||||
2
package-lock.json
generated
2
package-lock.json
generated
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "nanocurrency-web",
|
"name": "nanocurrency-web",
|
||||||
"version": "1.0.5",
|
"version": "1.0.6",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "nanocurrency-web",
|
"name": "nanocurrency-web",
|
||||||
"version": "1.0.5",
|
"version": "1.0.6",
|
||||||
"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",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue