Skip to content

Dash #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Dash #57

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# wallet-address-validator
Simple wallet address validator for validating Bitcoin and other altcoins addresses in **Node.js and browser**.

Forked from [ryanralph/altcoin-address](https://github.com/ryanralph/altcoin-address).
Forked from [evo42/wallet-address-validator](https://github.com/evo42/wallet-address-validator).

**File size is ~17 kB (minifed and gzipped)**.

Expand Down Expand Up @@ -54,12 +54,11 @@ npm install wallet-address-validator
* BitcoinGold/BTG, `'bitcoingold'` or `'BTG'`
* Decred/DCR, `'decred'` or `'DCR'`
* Digibyte/DGB, `'digibyte'` or `'DGB'`


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


### Usage example
Expand All @@ -68,7 +67,7 @@ npm install wallet-address-validator
```javascript
var WAValidator = require('wallet-address-validator');

var valid = WAValidator.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'BTC');
var valid = WAValidator.validate('3D2oetdNuZUqQHPJmcMDDHYoqkyNVsFk9r', 'BTC');
if(valid)
console.log('This is a valid address');
else
Expand All @@ -80,7 +79,7 @@ else
```javascript
var WAValidator = require('wallet-address-validator');

var valid = WAValidator.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'litecoin', 'testnet');
var valid = WAValidator.validate('3D2oetdNuZUqQHPJmcMDDHYoqkyNVsFk9r', 'litecoin', 'testnet');
if(valid)
console.log('This is a valid address');
else
Expand All @@ -96,7 +95,7 @@ else

```javascript
// WAValidator is exposed as a global (window.WAValidator)
var valid = WAValidator.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'bitcoin');
var valid = WAValidator.validate('3D2oetdNuZUqQHPJmcMDDHYoqkyNVsFk9r', 'bitcoin');
if(valid)
alert('This is a valid address');
else
Expand Down
16 changes: 10 additions & 6 deletions dist/wallet-address-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,7 @@ function numberIsNaN (obj) {
},{"base64-js":1,"ieee754":3}],3:[function(require,module,exports){
exports.read = function (buffer, offset, isLE, mLen, nBytes) {
var e, m
var eLen = nBytes * 8 - mLen - 1
var eLen = (nBytes * 8) - mLen - 1
var eMax = (1 << eLen) - 1
var eBias = eMax >> 1
var nBits = -7
Expand All @@ -1870,12 +1870,12 @@ exports.read = function (buffer, offset, isLE, mLen, nBytes) {
e = s & ((1 << (-nBits)) - 1)
s >>= (-nBits)
nBits += eLen
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}

m = e & ((1 << (-nBits)) - 1)
e >>= (-nBits)
nBits += mLen
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}

if (e === 0) {
e = 1 - eBias
Expand All @@ -1890,7 +1890,7 @@ exports.read = function (buffer, offset, isLE, mLen, nBytes) {

exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
var e, m, c
var eLen = nBytes * 8 - mLen - 1
var eLen = (nBytes * 8) - mLen - 1
var eMax = (1 << eLen) - 1
var eBias = eMax >> 1
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
Expand Down Expand Up @@ -1923,7 +1923,7 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
m = 0
e = eMax
} else if (e + eBias >= 1) {
m = (value * c - 1) * Math.pow(2, mLen)
m = ((value * c) - 1) * Math.pow(2, mLen)
e = e + eBias
} else {
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
Expand Down Expand Up @@ -3172,6 +3172,10 @@ var CURRENCIES = [{
name: 'callisto',
symbol: 'clo',
eip55: true
},{
name: 'dash',
symbol: 'dash',
addressTypes: {prod: ['4c', '10'], testnet: ['8c', '13']}
}];


Expand Down Expand Up @@ -3305,4 +3309,4 @@ module.exports = {
};

},{"./crypto/base58":6,"./crypto/utils":9,"./currencies":10,"./ethereum_validator":11}]},{},[12])(12)
});
});
2 changes: 1 addition & 1 deletion dist/wallet-address-validator.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/currencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ var CURRENCIES = [{
name: 'callisto',
symbol: 'clo',
eip55: true
},{
name: 'dash',
symbol: 'dash',
addressTypes: {prod: ['4c', '10'], testnet: ['8c', '13']}
}];


Expand Down
9 changes: 9 additions & 0 deletions test/wallet_address_validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ describe('WAValidator.validate()', function () {
valid('0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb', 'callisto');
valid('0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb', 'CLO');
});

it('should return true for correct dash addresses', function () {
valid('XoAAqv3oUYZ6xRjX3brfbf9PotrGanS6Th', 'dash');
valid('yP5oXZQXBfBf9FyfZDpFiKDypxuNUKUV2E', 'dash', 'testnet');
});
});

describe('invalid results', function () {
Expand Down Expand Up @@ -319,5 +324,9 @@ describe('WAValidator.validate()', function () {
invalid('0x02fcd51aAbB814FfFe17908fbc888A8975D839A5', 'etherzero');
invalid('0x02fcd51aAbB814FfFe17908fbc888A8975D839A5', 'callisto');
});

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