Skip to content

Commit 0a2adc1

Browse files
committed
Migrating codebase to make validator usable in the browser as well.
1 parent 170e832 commit 0a2adc1

18 files changed

+582
-408
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
bower_components

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: node_js
22
node_js:
3-
- "0.8"
4-
- "0.10"
3+
- "0.12"
4+
- "0.11"
5+
- "0.10"

Gruntfile.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module.exports = function(grunt) {
2+
grunt.loadNpmTasks('grunt-simple-mocha');
3+
grunt.loadNpmTasks('grunt-contrib-uglify');
4+
grunt.loadNpmTasks('grunt-mocha');
5+
6+
grunt.initConfig({
7+
uglify: {
8+
dist: {
9+
files: {
10+
'dist/wallet-address-validator.min.js': [
11+
'bower_components/jssha/src/sha256.js',
12+
'src/base58.js',
13+
'src/crypto_utils.js',
14+
'src/wallet_address_validator.js'
15+
]
16+
}
17+
}
18+
},
19+
// running tests in node
20+
simplemocha: {
21+
options: {
22+
timeout: 3000,
23+
ignoreLeaks: false,
24+
ui: 'bdd',
25+
reporter: 'spec'
26+
},
27+
all: { src: ['test/**/*.js'] }
28+
},
29+
// running tests in browser
30+
mocha: {
31+
all: {
32+
src: ['test/runner.html'],
33+
},
34+
options: {
35+
run: true
36+
}
37+
}
38+
});
39+
40+
grunt.registerTask('default', ['simplemocha', 'uglify', 'mocha']);
41+
};

README.md

Lines changed: 61 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,93 @@
1-
# altcoin-address [![Build Status](https://secure.travis-ci.org/ryanralph/altcoin-address.png)](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**.
33

4-
## API
4+
Forked from [ryanralph/altcoin-address](https://github.com/ryanralph/altcoin-address).
55

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)**.
77

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+
```
1114

12-
### get_address_type (address)
15+
### Browser
16+
```html
17+
<script src="wallet-address-validator.min.js"></script>
18+
```
1319

14-
> returns address type if valid base58 address, otherwise null
20+
#### Using bower
21+
```
22+
bower install wallet-address-validator
23+
```
1524

16-
### Address types
1725

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
2927

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])
3129

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.
3331
>
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)
3535

36-
### Example
36+
> returns address type (as 2 character hex string) if valid base58 address, otherwise null
3737
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
3855
```javascript
39-
var altcoin = require('altcoin-address');
56+
var WAValidator = require('wallet-address-validator');
4057

41-
var valid = altcoin.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'bitcoin');
58+
var valid = WAValidator.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'bitcoin');
4259
if(valid)
4360
console.log('This is a valid address');
4461
else
4562
console.log('Address INVALID');
4663

47-
48-
//This should return that 'This is a valid address'
64+
// This will log 'This is a valid address' to the console.
4965
```
5066

5167
```javascript
52-
var altcoin = require('altcoin-address');
68+
var WAValidator = require('wallet-address-validator');
5369

54-
var valid = altcoin.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'litecoinTestnet');
70+
var valid = WAValidator.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'litecoinTestnet');
5571
if(valid)
5672
console.log('This is a valid address');
5773
else
5874
console.log('Address INVALID');
5975

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.
6277
```
6378

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+
```
6983

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');
7191

72-
Ruby: https://bitbucket.org/noveltylab/crypto-address
92+
// This should show a pop up with text 'This is a valid address'.
93+
```

base58.js

Lines changed: 0 additions & 59 deletions
This file was deleted.

bower.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "wallet-address-validator",
3+
"description": "Wallet address validator for Bitcoin and other Altcoins.",
4+
"version": "0.0.1",
5+
"keywords": [
6+
"bitcoin",
7+
"litecoin",
8+
"dogecoin",
9+
"altcoin",
10+
"address",
11+
"wallet",
12+
"validator"
13+
],
14+
"license": "MIT",
15+
"homepage": "https://github.com/ognus/wallet-address-validator",
16+
"main": "dist/wallet-address-validator.min.js",
17+
"devDependencies": {
18+
"jssha": "1.6.0"
19+
}
20+
}

dist/wallet-address-validator.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)