forked from ryanralph/altcoin-address
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrating codebase to make validator usable in the browser as well.
- Loading branch information
Showing
18 changed files
with
582 additions
and
408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
bower_components |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- "0.8" | ||
- "0.10" | ||
- "0.12" | ||
- "0.11" | ||
- "0.10" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module.exports = function(grunt) { | ||
grunt.loadNpmTasks('grunt-simple-mocha'); | ||
grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
grunt.loadNpmTasks('grunt-mocha'); | ||
|
||
grunt.initConfig({ | ||
uglify: { | ||
dist: { | ||
files: { | ||
'dist/wallet-address-validator.min.js': [ | ||
'bower_components/jssha/src/sha256.js', | ||
'src/base58.js', | ||
'src/crypto_utils.js', | ||
'src/wallet_address_validator.js' | ||
] | ||
} | ||
} | ||
}, | ||
// running tests in node | ||
simplemocha: { | ||
options: { | ||
timeout: 3000, | ||
ignoreLeaks: false, | ||
ui: 'bdd', | ||
reporter: 'spec' | ||
}, | ||
all: { src: ['test/**/*.js'] } | ||
}, | ||
// running tests in browser | ||
mocha: { | ||
all: { | ||
src: ['test/runner.html'], | ||
}, | ||
options: { | ||
run: true | ||
} | ||
} | ||
}); | ||
|
||
grunt.registerTask('default', ['simplemocha', 'uglify', 'mocha']); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,93 @@ | ||
# altcoin-address [![Build Status](https://secure.travis-ci.org/ryanralph/altcoin-address.png)](http://travis-ci.org/ryanralph/altcoin-address) | ||
Functions for working with altcoin addresses, forked from [DefunctZombie](https://github.com/defunctzombie/bitcoin-address). | ||
# wallet-address-validator | ||
Simple wallet address validator for validating Bitcoin and other altcoins addresses in **Node.js and browser**. | ||
|
||
## API | ||
Forked from [ryanralph/altcoin-address](https://github.com/ryanralph/altcoin-address). | ||
|
||
### validate (address [, type]) | ||
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)**. | ||
|
||
> returns true if the address (string) is a valid altcoin address for the type specified | ||
> | ||
> if no options are specified it defaults to bitcoin | ||
## Installation | ||
|
||
### Node | ||
``` | ||
npm install wallet-address-validator | ||
``` | ||
|
||
### get_address_type (address) | ||
### Browser | ||
```html | ||
<script src="wallet-address-validator.min.js"></script> | ||
``` | ||
|
||
> returns address type if valid base58 address, otherwise null | ||
#### Using bower | ||
``` | ||
bower install wallet-address-validator | ||
``` | ||
|
||
### Address types | ||
|
||
* Bitcoin/BTC (bitcoin) | ||
* Litecoin/LTC (litecoin) | ||
* Peercoin/PPCoin/PPC (peercoin) | ||
* Dogecoin/DOGE (dogecoin) | ||
* BeaverCoin/BVC (beavercoin) | ||
* Freicoin/FRC (freicoin) | ||
* Protoshares/PTS (protoshares) | ||
* Megacoin/MEC (megacoin) | ||
* Primecoin/XPM (primecoin) | ||
* Auroracoin/AUR (auroracoin) | ||
* Namecoin/NMC (namecoin) | ||
## API | ||
|
||
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. | ||
### validate (address [, currency]) | ||
|
||
> This will work for both BIP-0016 P2SH addresses and regular addresses. | ||
> returns true if the address (string) is a valid wallet address for the crypto currency specified, see below for supported currencies. | ||
> | ||
> To check the validity of a testnet address for any of the listed coins just append 'Testnet' | ||
> if no options are specified it defaults to bitcoin | ||
### getAddressType (address) | ||
|
||
### Example | ||
> returns address type (as 2 character hex string) if valid base58 address, otherwise null | ||
### Supported crypto currencies | ||
|
||
* Bitcoin/BTC, `'bitcoin'` | ||
* Litecoin/LTC, `'litecoin'` | ||
* Peercoin/PPCoin/PPC, `'peercoin'` | ||
* Dogecoin/DOGE, `'dogecoin'` | ||
* BeaverCoin/BVC, `'beavercoin'` | ||
* Freicoin/FRC, `'freicoin'` | ||
* Protoshares/PTS, `'protoshares'` | ||
* Megacoin/MEC, `'megacoin'` | ||
* Primecoin/XPM, `'primecoin'` | ||
* Auroracoin/AUR, `'auroracoin'` | ||
* Namecoin/NMC, `'namecoin'` | ||
|
||
### Usage example | ||
|
||
#### Node | ||
```javascript | ||
var altcoin = require('altcoin-address'); | ||
var WAValidator = require('wallet-address-validator'); | ||
|
||
var valid = altcoin.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'bitcoin'); | ||
var valid = WAValidator.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'bitcoin'); | ||
if(valid) | ||
console.log('This is a valid address'); | ||
else | ||
console.log('Address INVALID'); | ||
|
||
|
||
//This should return that 'This is a valid address' | ||
// This will log 'This is a valid address' to the console. | ||
``` | ||
|
||
```javascript | ||
var altcoin = require('altcoin-address'); | ||
var WAValidator = require('wallet-address-validator'); | ||
|
||
var valid = altcoin.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'litecoinTestnet'); | ||
var valid = WAValidator.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'litecoinTestnet'); | ||
if(valid) | ||
console.log('This is a valid address'); | ||
else | ||
console.log('Address INVALID'); | ||
|
||
|
||
//As this is a invalid litecoin address response will be 'Address INVALID' | ||
// As this is a invalid litecoin address 'Address INVALID' will be logged to console. | ||
``` | ||
|
||
###Donations | ||
|
||
If you've found this useful feel free to send me a tip | ||
> BTC 1E3s7YjGVWrnhxTYkjkBKtTX3c673CCm3w | ||
#### Browser | ||
```html | ||
<script src="wallet-address-validator.min.js"></script> | ||
``` | ||
|
||
###Ports to other languages | ||
```javascript | ||
// WAValidator is exposed as a global (window.WAValidator) | ||
var valid = WAValidator.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'bitcoin'); | ||
if(valid) | ||
alert('This is a valid address'); | ||
else | ||
alert('Address INVALID'); | ||
|
||
Ruby: https://bitbucket.org/noveltylab/crypto-address | ||
// This should show a pop up with text 'This is a valid address'. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "wallet-address-validator", | ||
"description": "Wallet address validator for Bitcoin and other Altcoins.", | ||
"version": "0.0.1", | ||
"keywords": [ | ||
"bitcoin", | ||
"litecoin", | ||
"dogecoin", | ||
"altcoin", | ||
"address", | ||
"wallet", | ||
"validator" | ||
], | ||
"license": "MIT", | ||
"homepage": "https://github.com/ognus/wallet-address-validator", | ||
"main": "dist/wallet-address-validator.min.js", | ||
"devDependencies": { | ||
"jssha": "1.6.0" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.