Skip to content

Commit

Permalink
Vertcoin segwit addresses support
Browse files Browse the repository at this point in the history
  • Loading branch information
ognus committed Nov 17, 2018
1 parent 3866fa0 commit e8e2f6c
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 8 deletions.
7 changes: 4 additions & 3 deletions dist/wallet-address-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2388,7 +2388,7 @@ function isValidP2PKHandP2SHAddress(address, currency, networkType) {

module.exports = {
isValidAddress: function (address, currency, networkType) {
return isValidP2PKHandP2SHAddress(address, currency, networkType) || segwit.isValidAddress(address);
return isValidP2PKHandP2SHAddress(address, currency, networkType) || segwit.isValidAddress(address, currency.segwitHrp);
}
};

Expand Down Expand Up @@ -4500,8 +4500,8 @@ function encode (hrp, version, program) {
return ret;
}

function isValidAddress(address) {
var hrp = 'bc';
function isValidAddress(address, hrp) {
var hrp = hrp || 'bc';
var ret = decode(hrp, address);

if (ret === null) {
Expand Down Expand Up @@ -5291,6 +5291,7 @@ var CURRENCIES = [{
name: 'vertcoin',
symbol: 'vtc',
addressTypes: {prod: ['0x', '47'], testnet: ['6f', 'c4']},
segwitHrp: 'vtc',
validator: BTCValidator
},{
name: 'bitcoingold',
Expand Down
2 changes: 1 addition & 1 deletion dist/wallet-address-validator.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
"address",
"wallet",
"validator",
"vertcoin",
"javascript",
"browser",
"nodejs"
],
"version": "0.2.2",
"version": "0.2.3",
"author": "Tomek Kolasa <[email protected]>",
"homepage": "https://github.com/ognus/wallet-address-validator",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/bitcoin_validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ function isValidP2PKHandP2SHAddress(address, currency, networkType) {

module.exports = {
isValidAddress: function (address, currency, networkType) {
return isValidP2PKHandP2SHAddress(address, currency, networkType) || segwit.isValidAddress(address);
return isValidP2PKHandP2SHAddress(address, currency, networkType) || segwit.isValidAddress(address, currency.segwitHrp);
}
};
4 changes: 2 additions & 2 deletions src/crypto/segwit_addr.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ function encode (hrp, version, program) {
return ret;
}

function isValidAddress(address) {
var hrp = 'bc';
function isValidAddress(address, hrp) {
var hrp = hrp || 'bc';
var ret = decode(hrp, address);

if (ret === null) {
Expand Down
1 change: 1 addition & 0 deletions src/currencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ var CURRENCIES = [{
name: 'vertcoin',
symbol: 'vtc',
addressTypes: {prod: ['0x', '47'], testnet: ['6f', 'c4']},
segwitHrp: 'vtc',
validator: BTCValidator
},{
name: 'bitcoingold',
Expand Down
6 changes: 6 additions & 0 deletions test/wallet_address_validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ describe('WAValidator.validate()', function () {
valid('mvww6DEJ18dbyQUukpVQXvLgrNDJazZn1Y', 'vertcoin', 'testnet');
valid('mn3mdEE6cf1snxVsknNz4GRTdSrWXqYp7c', 'VTC', 'testnet');
valid('Vri6Q4GgNFfdtcpxD961TotJwaSaYQCaL5', 'VTC');
valid('vtc1qmzq3erafwvz23yfeu9tu45uz2kx3d7esk0rayg', 'VTC');
valid('vtc1qhy8eqwqxpyryz4wctus36yl2uu60t0z6ecrvtc', 'VTC');
valid('vtc1qh9y09s2crkp63mk26u3vrq9q4w3h8ee8gepjgw', 'VTC');
});

it('should return true for correct BitcoinGold addresses', function () {
Expand Down Expand Up @@ -439,6 +442,9 @@ describe('WAValidator.validate()', function () {

it('should return false for incorrect vertcoin addresses', function () {
commonTests('vertcoin');
invalid('vtc1qmzq3erafwvz23yabc9tu45uz2kx3d7esk0rayg', 'vertcoin');
invalid('vtc1qhy8eqwqxpyryz4wctus36yl2uu60t0z6ecrvt', 'vertcoin');
invalid('vtd1qhy8eqwqxpyryz4wctus36yl2uu60t0z6ecrvtc', 'vertcoin');
});

it('should return false for incorrect bitcoingold addresses', function () {
Expand Down

0 comments on commit e8e2f6c

Please sign in to comment.