Skip to content
Open
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
46 changes: 44 additions & 2 deletions dist/wallet-address-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11893,6 +11893,7 @@ var AlgoValidator = require('./algo_validator');
var DotValidator = require('./dot_validator');
var BIP173Validator = require('./bip173_validator')
var Base58Validator = require('./base58_validator')
var XDCValidtaor = require('./xinfin_validator');

// defines P2PKH and P2SH address types for standard (prod) and testnet networks
var CURRENCIES = [{
Expand Down Expand Up @@ -12470,6 +12471,11 @@ var CURRENCIES = [{
symbol: 'bnb',
validator: ETHValidator,
},
{
name: 'XinFin',
symbol: 'XDC',
validator: XDCValidtaor
},
];


Expand Down Expand Up @@ -12497,7 +12503,7 @@ var CURRENCIES = [{
//


},{"./ada_validator":37,"./algo_validator":38,"./base58_validator":39,"./bch_validator":40,"./bip173_validator":41,"./bitcoin_validator":42,"./dot_validator":54,"./eos_validator":55,"./ethereum_validator":56,"./lisk_validator":57,"./monero_validator":58,"./nano_validator":59,"./nem_validator":60,"./ripple_validator":61,"./siacoin_validator":62,"./stellar_validator":63,"./tezos_validator":64,"./tron_validator":65,"./usdt_validator":66}],54:[function(require,module,exports){
},{"./ada_validator":37,"./algo_validator":38,"./base58_validator":39,"./bch_validator":40,"./bip173_validator":41,"./bitcoin_validator":42,"./dot_validator":54,"./eos_validator":55,"./ethereum_validator":56,"./lisk_validator":57,"./monero_validator":58,"./nano_validator":59,"./nem_validator":60,"./ripple_validator":61,"./siacoin_validator":62,"./stellar_validator":63,"./tezos_validator":64,"./tron_validator":65,"./usdt_validator":66,"./xinfin_validator":68}],54:[function(require,module,exports){
const cryptoUtils = require('./crypto/utils');

// from https://github.com/paritytech/substrate/wiki/External-Address-Format-(SS58)
Expand Down Expand Up @@ -13006,5 +13012,41 @@ module.exports = {
}
};

},{"./currencies":53}]},{},[67])(67)
},{"./currencies":53}],68:[function(require,module,exports){
var cryptoUtils = require('./crypto/utils');

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

if (/^[xdcXDC]{3}[0-9a-f]{40}$/.test(address) || /^[xdcXDC]{3}[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.verifyChecksum(address);
},
verifyChecksum: function (address) {
// Check each case
address = address.replace(/^xdc/ig,'');

var addressHash = cryptoUtils.keccak256(address.toLowerCase());

for (var i = 0; i < 40; i++ ) {
// The nth letter should be uppercase if the nth digit of casemap is 1
if ((parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i]) ||
(parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i])) {
return false;
}
}

return true;
}
};

},{"./crypto/utils":52}]},{},[67])(67)
});
2 changes: 1 addition & 1 deletion dist/wallet-address-validator.min.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/currencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var AlgoValidator = require('./algo_validator');
var DotValidator = require('./dot_validator');
var BIP173Validator = require('./bip173_validator')
var Base58Validator = require('./base58_validator')
var XDCValidtaor = require('./xinfin_validator');

// defines P2PKH and P2SH address types for standard (prod) and testnet networks
var CURRENCIES = [{
Expand Down Expand Up @@ -594,6 +595,11 @@ var CURRENCIES = [{
symbol: 'bnb',
validator: ETHValidator,
},
{
name: 'XinFin',
symbol: 'XDC',
validator: XDCValidtaor
},
];


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

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

if (/^[xdcXDC]{3}[0-9a-f]{40}$/.test(address) || /^[xdcXDC]{3}[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.verifyChecksum(address);
},
verifyChecksum: function (address) {
// Check each case
address = address.replace(/^xdc/ig,'');

var addressHash = cryptoUtils.keccak256(address.toLowerCase());

for (var i = 0; i < 40; i++ ) {
// The nth letter should be uppercase if the nth digit of casemap is 1
if ((parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i]) ||
(parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i])) {
return false;
}
}

return true;
}
};
3 changes: 3 additions & 0 deletions test/wallet_address_validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,9 @@ describe('WAValidator.validate()', function () {
valid('G4qGCGF4vWGPzYi2pxc2Djvgv3j8NiWaHQMgTVebCX6W', 'sol');
});

it('should return true for correct xdc addresses', function () {
valid('xdc12301c38f07a30d60f474366b4d4ef9c4298f06e', 'xdc');
});
});

describe('invalid results', function () {
Expand Down