UNPKG

2.51 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## Install
12
13Install via npm or yarn
14```bash
15npm i -S amon-lib
16yarn add amon-lib
17```
18
19Import in your project
20```javascript
21const AmonLib = require('amon-lib');
22import AmonLib from 'amon-lib';
23```
24
25## Examples
26
27First you need to get an instance of AmonLib. This instance is useful to use the lib on different networks.
28
29```javascript
30const amonLib = new AmonLib({ network: 'mainnet' });
31```
32
33`network` can be either `mainnet` or `testnet`
34
35### Coins
36
37Supported coins: `BTC`, `ETH`, `AMN`
38- Validate address
39```javascript
40const validAddress = amonLib.coins('BTC').validAddress('1FJ2PMM75HRh63TmoYLe6Wd9apxNK3aem9');
41// validAddress = true
42```
43
44- Transaction block explorer url
45```javascript
46const txExplorerUrl = amonLib.coins('BTC').txExplorerUrl('ad44d7ff0a7a1e433d00fbe9db1a8cf4cd509c3bb928c3963f2e4575fc4c5861');
47// txExplorerUrl = 'https://live.blockcypher.com/btc/tx/ad44d7ff0a7a1e433d00fbe9db1a8cf4cd509c3bb928c3963f2e4575fc4c5861'
48```
49
50- Address block explorer url
51```javascript
52const addressExplorerUrl = amonLib.coins('BTC').addressExplorerUrl('1FJ2PMM75HRh63TmoYLe6Wd9apxNK3aem9');
53// addressExplorerUrl = 'https://live.blockcypher.com/btc/address/1FJ2PMM75HRh63TmoYLe6Wd9apxNK3aem9'
54```
55
56### URI
57
58#### Parse URI
59
60```js
61const data = amonLib.URI.parse('bitcoin:mkzgubTA5Ahi6BPSkE6MN9pEafRutznkMe?amount=0.12');
62const { address, coinCode, amount } = data;
63// address = mkzgubTA5Ahi6BPSkE6MN9pEafRutznkMe
64// coinCode = BTC
65// amount = 0.12
66```
67
68#### Generate URI
69
70```js
71const data = {
72 coinCode: 'BTC',
73 address: 'mkzgubTA5Ahi6BPSkE6MN9pEafRutznkMe',
74 amount: '0.12',
75};
76
77const str = amonLib.URI.stringify(data);
78// str = bitcoin:mkzgubTA5Ahi6BPSkE6MN9pEafRutznkMe?amount=0.12
79```
80
81
82### Hash
83
84#### SHA-256
85
86```js
87const password = 'secretsanta';
88const hash = AmonLib.crypto.sha.hash(password); // => 0a4f185e2483d5ea4e370c6b4ee31c51840f212a7c25de997509a8953d5fcb86
89```
90
91#### bcrypt
92
93```js
94const password = 'secretsanta';
95const hash = AmonLib.crypto.bcrypt.hash(password); // => 0a4f185e2483d5ea4e370c6b4ee31c51840f212a7c25de997509a8953d5fcb86
96const valid = AmonLib.crypto.bcrypt.verifyHash(password, hash); // => true
97```