Skip to content

Commit

Permalink
Merge pull request #19 from ognus/dash
Browse files Browse the repository at this point in the history
Dash
  • Loading branch information
ognus authored Mar 26, 2018
2 parents 329ea9a + 824399c commit 5d97dbe
Show file tree
Hide file tree
Showing 11 changed files with 2,995 additions and 2,954 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
38 changes: 24 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,42 @@ npm install wallet-address-validator
### Supported crypto currencies

* Bitcoin/BTC, `'bitcoin'` or `'BTC'`
* Litecoin/LTC, `'litecoin'` or `'LTC'`
* Peercoin/PPCoin/PPC, `'peercoin'` or `'PPC'`
* Dogecoin/DOGE, `'dogecoin'` or `'DOGE'`
* BeaverCoin/BVC, `'beavercoin'` or `'BVC'`
* Freicoin/FRC, `'freicoin'` or `'FRC'`
* Protoshares/PTS, `'protoshares'` or `'PTS'`
* Megacoin/MEC, `'megacoin'` or `'MEC'`
* Primecoin/XPM, `'primecoin'` or `'XPM'`
* Auroracoin/AUR, `'auroracoin'` or `'AUR'`
* Namecoin/NMC, `'namecoin'` or `'NMC'`

* BeaverCoin/BVC, `'beavercoin'` or `'BVC'`
* Biocoin/BIO, `'biocoin'` or `'BIO'`
* Garlicoin/GRLC, `'garlicoin'` or `'GRLC'`
* Vertcoin/VTC, `'vertcoin'` or `'VTC'`
* Bitcoin/BTC, `'bitcoin'` or `'BTC'`
* BitcoinGold/BTG, `'bitcoingold'` or `'BTG'`

* Callisto/CLO, `'callisto'` or `'CLO'`

* Dash, `'dash'` or `'DASH'`
* Decred/DCR, `'decred'` or `'DCR'`
* Digibyte/DGB, `'digibyte'` or `'DGB'`

* Dogecoin/DOGE, `'dogecoin'` or `'DOGE'`

* Ethereum/ETH, `'ethereum'` or `'ETH'`
* EthereumClassic/ETH, `'ethereumclassic'` or `'ETC'`
* EthereumZero/ETZ, `'etherzero'` or `'ETZ'`
* Callisto/CLO, `'callisto'` or `'CLO'`

* Freicoin/FRC, `'freicoin'` or `'FRC'`

* Garlicoin/GRLC, `'garlicoin'` or `'GRLC'`

* Litecoin/LTC, `'litecoin'` or `'LTC'`

* Megacoin/MEC, `'megacoin'` or `'MEC'`

* Namecoin/NMC, `'namecoin'` or `'NMC'`

* Peercoin/PPCoin/PPC, `'peercoin'` or `'PPC'`
* Primecoin/XPM, `'primecoin'` or `'XPM'`
* Protoshares/PTS, `'protoshares'` or `'PTS'`

* Ripple/XRP, `'ripple'` or `'XRP'`

* Vertcoin/VTC, `'vertcoin'` or `'VTC'`


### Usage example

Expand Down
5,768 changes: 2,886 additions & 2,882 deletions dist/wallet-address-validator.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/wallet-address-validator.min.js

Large diffs are not rendered by default.

50 changes: 25 additions & 25 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
// Karma configuration
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['mocha', 'chai'],
files: [
'dist/wallet-address-validator.min.js',
'test/**/*.js'
],
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
browsers: ['ChromeHeadless'],
singleRun: true,
concurrency: Infinity
})
module.exports = function (config) {
config.set({
basePath: '',

frameworks: ['mocha', 'chai'],

files: [
'dist/wallet-address-validator.min.js',
'test/**/*.js'
],

reporters: ['progress'],

port: 9876,

colors: true,

logLevel: config.LOG_INFO,

browsers: ['ChromeHeadless'],

singleRun: true,

concurrency: Infinity
})
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"decred",
"dogecoin",
"ethereum",
"ripple",
"dash",
"altcoin",
"crypto",
"address",
Expand Down
15 changes: 9 additions & 6 deletions src/currencies.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var XRPValidator = require('./ripple_validator');
var ETHValidator = require('./ethereum_validator');

// defines P2PKH and P2SH address types for standard (prod) and testnet networks
var CURRENCIES = [{
Expand Down Expand Up @@ -71,28 +72,30 @@ var CURRENCIES = [{
name: 'digibyte',
symbol: 'dgb',
addressTypes: {prod: ['1e'], testnet: []},
eip55: false
},{
name: 'ethereum',
symbol: 'eth',
eip55: true
validator: ETHValidator,
},{
name: 'etherzero',
symbol: 'etz',
eip55: true
validator: ETHValidator,
},{
name: 'ethereumclassic',
symbol: 'etc',
eip55: true
validator: ETHValidator,
},{
name: 'callisto',
symbol: 'clo',
eip55: true
validator: ETHValidator,
},{
name: 'ripple',
symbol: 'xrp',
validator: XRPValidator,
eip55: false
},{
name: 'dash',
symbol: 'dash',
addressTypes: {prod: ['4c', '10'], testnet: ['8c', '13']}
}];


Expand Down
10 changes: 5 additions & 5 deletions src/ethereum_validator.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
var cryptoUtils = require('./crypto/utils');

module.exports = {
isAddress: function (address) {
isValidAddress: function (address) {
if (!/^0x[0-9a-fA-F]{40}$/.test(address)) {
// Check if it has the basic requirements of an address
return false;
}

if (/^0x[0-9a-f]{40}$/.test(address) || /^0x?[0-9A-F]{40}$/.test(address)) {
// If it's all small caps or all all caps, return true
return true;
}

// Otherwise check each case
return this.isChecksumAddress(address);
return this.verifyChecksum(address);
},
isChecksumAddress: function (address) {
verifyChecksum: function (address) {
// Check each case
address = address.replace('0x','');

Expand All @@ -28,7 +28,7 @@ module.exports = {
return false;
}
}

return true;
}
};
36 changes: 21 additions & 15 deletions src/ripple_validator.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
var cryptoUtils = require('./crypto/utils');
var baseX = require('base-x');
var codec = baseX("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"); // for ripple

var ALLOWED_CHARS = 'rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz';

var codec = baseX(ALLOWED_CHARS);
var regexp = new RegExp('^r[' + ALLOWED_CHARS + ']{27,35}$');

module.exports = {
/**
* ripple address validation
*/
isValidAddress: function (address) {
if (/^r[rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz]{27,35}$/.test(address) === false)
return false;
return this.verifyChecksum(address);
},
/**
* ripple address validation
*/
isValidAddress: function (address) {
if (regexp.test(address)) {
return this.verifyChecksum(address);
}

return false;
},

verifyChecksum: function (address) {
var bytes = codec.decode(address);
var computedChecksum = cryptoUtils.sha256Checksum(cryptoUtils.toHex(bytes.slice(0, -4)));
var checksum = cryptoUtils.toHex(bytes.slice(-4));
verifyChecksum: function (address) {
var bytes = codec.decode(address);
var computedChecksum = cryptoUtils.sha256Checksum(cryptoUtils.toHex(bytes.slice(0, -4)));
var checksum = cryptoUtils.toHex(bytes.slice(-4));

return computedChecksum === checksum
}
return computedChecksum === checksum
}
};
7 changes: 1 addition & 6 deletions src/wallet_address_validator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var base58 = require('./crypto/base58');
var cryptoUtils = require('./crypto/utils');
var currencies = require('./currencies');
var ETHValidator = require('./ethereum_validator');

var DEFAULT_CURRENCY_NAME = 'bitcoin';
var DEFAULT_NETWORK_TYPE = 'prod';
Expand Down Expand Up @@ -36,7 +35,7 @@ module.exports = {

return checksum === goodChecksum ? cryptoUtils.toHex(decoded.slice(0, expectedLength - 24)) : null;
}

return null;
},

Expand All @@ -62,10 +61,6 @@ module.exports = {
return currency.validator.isValidAddress(address);
}

if (currency.eip55) {
return ETHValidator.isAddress(address);
}

var correctAddressTypes;
var addressType = this.getAddressType(address, currency);

Expand Down
11 changes: 11 additions & 0 deletions test/wallet_address_validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ describe('WAValidator.validate()', function () {
valid('rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', 'XRP');
valid('rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN', 'XRP');
});

it('should return true for correct dash addresses', function () {
valid('Xx4dYKgz3Zcv6kheaqog3fynaKWjbahb6b', 'dash');
valid('XcY4WJ6Z2Q8w7vcYER1JypC8s2oa3SQ1b1', 'DASH');
valid('XqMkVUZnqe3w4xvgdZRtZoe7gMitDudGs4', 'dash');
valid('yPv7h2i8v3dJjfSH4L3x91JSJszjdbsJJA', 'dash', 'testnet');
});
});

describe('invalid results', function () {
Expand Down Expand Up @@ -334,5 +341,9 @@ describe('WAValidator.validate()', function () {
invalid('6xAff4d6793F584a473348EbA058deb8ca', 'ripple');
invalid('DJ53hTyLBdZp2wMi5BsCS3rtEL1ioYUkva', 'ripple');
});

it('should return false for incorrect dash addresses', function () {
commonTests('dash');
});
});
});

0 comments on commit 5d97dbe

Please sign in to comment.