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