UNPKG

2.59 kBMarkdownView Raw
1 # AMON libraries
2
3[![CircleCI](https://circleci.com/gh/amontech/amon-lib/tree/master.svg?style=svg&circle-token=35a5a437b160dcd5edeb20b19b5b75fcebd7082d)](https://circleci.com/gh/amontech/amon-lib/tree/master)
4
5This library is a set of common utilities used in various part of AMON projects.
6
7## Documentation:
8
9[API Documentation](https://amontech.github.io/amon-lib/)
10
11## Publish on NPM
12- update the package version
13- npm publish
14
15## Install
16
17Install via npm or yarn
18```bash
19npm i -S amon-lib
20yarn add amon-lib
21```
22
23Import in your project
24```javascript
25const AmonLib = require('amon-lib');
26import AmonLib from 'amon-lib';
27```
28
29## Examples
30
31First you need to get an instance of AmonLib. This instance is useful to use the lib on different networks.
32
33```javascript
34const amonLib = new AmonLib({ network: 'mainnet' });
35```
36
37`network` can be either `mainnet` or `testnet`
38
39### Coins
40
41Supported coins: `BTC`, `ETH`, `AMN`, `DASH`, `ZEC`
42
43- Validate address
44```javascript
45const validAddress = amonLib.coins('BTC').validAddress('1FJ2PMM75HRh63TmoYLe6Wd9apxNK3aem9');
46// validAddress = true
47```
48
49- Transaction block explorer url
50```javascript
51const txExplorerUrl = amonLib.coins('BTC').txExplorerUrl('ad44d7ff0a7a1e433d00fbe9db1a8cf4cd509c3bb928c3963f2e4575fc4c5861');
52// txExplorerUrl = 'https://live.blockcypher.com/btc/tx/ad44d7ff0a7a1e433d00fbe9db1a8cf4cd509c3bb928c3963f2e4575fc4c5861'
53```
54
55- Address block explorer url
56```javascript
57const addressExplorerUrl = amonLib.coins('BTC').addressExplorerUrl('1FJ2PMM75HRh63TmoYLe6Wd9apxNK3aem9');
58// addressExplorerUrl = 'https://live.blockcypher.com/btc/address/1FJ2PMM75HRh63TmoYLe6Wd9apxNK3aem9'
59```
60
61### URI
62
63#### Parse URI
64
65```js
66const data = amonLib.URI.parse('bitcoin:mkzgubTA5Ahi6BPSkE6MN9pEafRutznkMe?amount=0.12');
67const { address, coinCode, amount } = data;
68// address = mkzgubTA5Ahi6BPSkE6MN9pEafRutznkMe
69// coinCode = BTC
70// amount = 0.12
71```
72
73#### Generate URI
74
75```js
76const data = {
77 coinCode: 'BTC',
78 address: 'mkzgubTA5Ahi6BPSkE6MN9pEafRutznkMe',
79 amount: '0.12',
80};
81
82const str = amonLib.URI.stringify(data);
83// str = bitcoin:mkzgubTA5Ahi6BPSkE6MN9pEafRutznkMe?amount=0.12
84```
85
86
87### Hash
88
89#### SHA-256
90
91```js
92const password = 'secretsanta';
93const hash = AmonLib.crypto.sha.hash(password); // => 0a4f185e2483d5ea4e370c6b4ee31c51840f212a7c25de997509a8953d5fcb86
94```
95
96#### bcrypt
97
98```js
99const password = 'secretsanta';
100const hash = AmonLib.crypto.bcrypt.hash(password); // => 0a4f185e2483d5ea4e370c6b4ee31c51840f212a7c25de997509a8953d5fcb86
101const valid = AmonLib.crypto.bcrypt.verifyHash(password, hash); // => true
102```
103
104