Skip to content

Commit 356d42a

Browse files
committed
Validate tron address from hex string
1 parent 1bae652 commit 356d42a

4 files changed

+22
-1
lines changed

dist/wallet-address-validator.js

+10
Original file line numberDiff line numberDiff line change
@@ -7176,6 +7176,16 @@ module.exports = {
71767176
* tron address validation
71777177
*/
71787178
isValidAddress: function (mainAddress, currency, networkType) {
7179+
// Check if byteArray
7180+
if (mainAddress && mainAddress.byteLength !== undefined) {
7181+
if (mainAddress.length !== 21) {
7182+
return false;
7183+
}
7184+
return getEnv(currency, networkType) === mainAddress[0];
7185+
}
7186+
if (typeof mainAddress === 'string') {
7187+
if (mainAddress.length === 42 && mainAddress.startsWith('41')) return true;
7188+
}
71797189
var address = decodeBase58Address(mainAddress);
71807190

71817191
if (!address) {

dist/wallet-address-validator.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tron_validator.js

+10
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ module.exports = {
4646
* tron address validation
4747
*/
4848
isValidAddress: function (mainAddress, currency, networkType) {
49+
// Check if byteArray
50+
if (mainAddress && mainAddress.byteLength !== undefined) {
51+
if (mainAddress.length !== 21) {
52+
return false;
53+
}
54+
return getEnv(currency, networkType) === mainAddress[0];
55+
}
56+
if (typeof mainAddress === 'string') {
57+
if (mainAddress.length === 42 && mainAddress.startsWith('41')) return true;
58+
}
4959
var address = decodeBase58Address(mainAddress);
5060

5161
if (!address) {

test/wallet_address_validator.js

+1
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ describe('WAValidator.validate()', function () {
410410

411411
it('should return true for correct trx addresses', function () {
412412
valid('TNDzfERDpxLDS2w1q6yaFC7pzqaSQ3Bg3r', 'trx');
413+
valid('41e825d52582eec346c839b4875376117904a76cbc', 'trx');
413414
valid('27bLJCYjbH6MT8DBF9xcrK6yZnm43vx7MNQ', 'trx', 'testnet');
414415
});
415416
});

0 commit comments

Comments
 (0)