|
1 |
| -# altcoin-address [](http://travis-ci.org/ryanralph/altcoin-address) |
2 |
| -Functions for working with altcoin addresses, forked from [DefunctZombie](https://github.com/defunctzombie/bitcoin-address). |
| 1 | +# wallet-address-validator |
| 2 | +Simple wallet address validator for validating Bitcoin and other altcoins addresses in **Node.js and browser**. |
3 | 3 |
|
4 |
| -## API |
| 4 | +Forked from [ryanralph/altcoin-address](https://github.com/ryanralph/altcoin-address). |
5 | 5 |
|
6 |
| -### validate (address [, type]) |
| 6 | +I forked it to remove all Node.js dependencies (crypro, Buffer etc.) to make it usable in the browser as well. I didn't use browserify to achieve smaller footprint, **file size is 3.9 kB (minifed and gzipped)**. |
7 | 7 |
|
8 |
| -> returns true if the address (string) is a valid altcoin address for the type specified |
9 |
| -> |
10 |
| -> if no options are specified it defaults to bitcoin |
| 8 | +## Installation |
| 9 | + |
| 10 | +### Node |
| 11 | +``` |
| 12 | +npm install wallet-address-validator |
| 13 | +``` |
11 | 14 |
|
12 |
| -### get_address_type (address) |
| 15 | +### Browser |
| 16 | +```html |
| 17 | +<script src="wallet-address-validator.min.js"></script> |
| 18 | +``` |
13 | 19 |
|
14 |
| -> returns address type if valid base58 address, otherwise null |
| 20 | +#### Using bower |
| 21 | +``` |
| 22 | +bower install wallet-address-validator |
| 23 | +``` |
15 | 24 |
|
16 |
| -### Address types |
17 | 25 |
|
18 |
| -* Bitcoin/BTC (bitcoin) |
19 |
| -* Litecoin/LTC (litecoin) |
20 |
| -* Peercoin/PPCoin/PPC (peercoin) |
21 |
| -* Dogecoin/DOGE (dogecoin) |
22 |
| -* BeaverCoin/BVC (beavercoin) |
23 |
| -* Freicoin/FRC (freicoin) |
24 |
| -* Protoshares/PTS (protoshares) |
25 |
| -* Megacoin/MEC (megacoin) |
26 |
| -* Primecoin/XPM (primecoin) |
27 |
| -* Auroracoin/AUR (auroracoin) |
28 |
| -* Namecoin/NMC (namecoin) |
| 26 | +## API |
29 | 27 |
|
30 |
| -I intend to update this to include more currencies in the future. If you would like a new currency added quickly please send a pull request including tests. |
| 28 | +### validate (address [, currency]) |
31 | 29 |
|
32 |
| -> This will work for both BIP-0016 P2SH addresses and regular addresses. |
| 30 | +> returns true if the address (string) is a valid wallet address for the crypto currency specified, see below for supported currencies. |
33 | 31 | >
|
34 |
| -> To check the validity of a testnet address for any of the listed coins just append 'Testnet' |
| 32 | +> if no options are specified it defaults to bitcoin |
| 33 | +
|
| 34 | +### getAddressType (address) |
35 | 35 |
|
36 |
| -### Example |
| 36 | +> returns address type (as 2 character hex string) if valid base58 address, otherwise null |
37 | 37 |
|
| 38 | +### Supported crypto currencies |
| 39 | + |
| 40 | +* Bitcoin/BTC, `'bitcoin'` |
| 41 | +* Litecoin/LTC, `'litecoin'` |
| 42 | +* Peercoin/PPCoin/PPC, `'peercoin'` |
| 43 | +* Dogecoin/DOGE, `'dogecoin'` |
| 44 | +* BeaverCoin/BVC, `'beavercoin'` |
| 45 | +* Freicoin/FRC, `'freicoin'` |
| 46 | +* Protoshares/PTS, `'protoshares'` |
| 47 | +* Megacoin/MEC, `'megacoin'` |
| 48 | +* Primecoin/XPM, `'primecoin'` |
| 49 | +* Auroracoin/AUR, `'auroracoin'` |
| 50 | +* Namecoin/NMC, `'namecoin'` |
| 51 | + |
| 52 | +### Usage example |
| 53 | + |
| 54 | +#### Node |
38 | 55 | ```javascript
|
39 |
| -var altcoin = require('altcoin-address'); |
| 56 | +var WAValidator = require('wallet-address-validator'); |
40 | 57 |
|
41 |
| -var valid = altcoin.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'bitcoin'); |
| 58 | +var valid = WAValidator.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'bitcoin'); |
42 | 59 | if(valid)
|
43 | 60 | console.log('This is a valid address');
|
44 | 61 | else
|
45 | 62 | console.log('Address INVALID');
|
46 | 63 |
|
47 |
| - |
48 |
| -//This should return that 'This is a valid address' |
| 64 | +// This will log 'This is a valid address' to the console. |
49 | 65 | ```
|
50 | 66 |
|
51 | 67 | ```javascript
|
52 |
| -var altcoin = require('altcoin-address'); |
| 68 | +var WAValidator = require('wallet-address-validator'); |
53 | 69 |
|
54 |
| -var valid = altcoin.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'litecoinTestnet'); |
| 70 | +var valid = WAValidator.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'litecoinTestnet'); |
55 | 71 | if(valid)
|
56 | 72 | console.log('This is a valid address');
|
57 | 73 | else
|
58 | 74 | console.log('Address INVALID');
|
59 | 75 |
|
60 |
| - |
61 |
| -//As this is a invalid litecoin address response will be 'Address INVALID' |
| 76 | +// As this is a invalid litecoin address 'Address INVALID' will be logged to console. |
62 | 77 | ```
|
63 | 78 |
|
64 |
| -###Donations |
65 |
| - |
66 |
| -If you've found this useful feel free to send me a tip |
67 |
| -> BTC 1E3s7YjGVWrnhxTYkjkBKtTX3c673CCm3w |
68 |
| -
|
| 79 | +#### Browser |
| 80 | +```html |
| 81 | +<script src="wallet-address-validator.min.js"></script> |
| 82 | +``` |
69 | 83 |
|
70 |
| -###Ports to other languages |
| 84 | +```javascript |
| 85 | +// WAValidator is exposed as a global (window.WAValidator) |
| 86 | +var valid = WAValidator.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'bitcoin'); |
| 87 | +if(valid) |
| 88 | + alert('This is a valid address'); |
| 89 | +else |
| 90 | + alert('Address INVALID'); |
71 | 91 |
|
72 |
| -Ruby: https://bitbucket.org/noveltylab/crypto-address |
| 92 | +// This should show a pop up with text 'This is a valid address'. |
| 93 | +``` |
0 commit comments