multichain-address-validator 0.7.3 → 0.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/dist/cjs/chain-validators.js +124 -0
  2. package/dist/cjs/crypto/base32.js +66 -0
  3. package/dist/cjs/crypto/base58.js +44 -0
  4. package/dist/cjs/crypto/bech32.js +126 -0
  5. package/dist/cjs/crypto/biginteger.js +1313 -0
  6. package/dist/cjs/crypto/blake256.js +171 -0
  7. package/dist/cjs/crypto/blake2b.js +243 -0
  8. package/dist/cjs/crypto/cnBase58.js +211 -0
  9. package/dist/{crypto → cjs/crypto}/segwit_addr.d.ts +2 -2
  10. package/dist/cjs/crypto/segwit_addr.js +107 -0
  11. package/dist/cjs/crypto/utils.js +128 -0
  12. package/dist/cjs/helpers.js +8 -0
  13. package/dist/cjs/index.d.ts +8 -0
  14. package/dist/cjs/index.js +17 -0
  15. package/dist/cjs/package.json +1 -0
  16. package/dist/cjs/types.js +8 -0
  17. package/dist/cjs/validators/algorand_validator.js +28 -0
  18. package/dist/cjs/validators/base58_validator.js +36 -0
  19. package/dist/cjs/validators/bch_validator.js +55 -0
  20. package/dist/cjs/validators/bip173_validator.js +17 -0
  21. package/dist/cjs/validators/bitcoin_validator.js +73 -0
  22. package/dist/cjs/validators/cardano_validator.js +46 -0
  23. package/dist/cjs/validators/eos_validator.js +12 -0
  24. package/dist/cjs/validators/ethereum_validator.js +35 -0
  25. package/dist/cjs/validators/hedera_validator.js +10 -0
  26. package/dist/cjs/validators/index.js +42 -0
  27. package/dist/cjs/validators/monero_validator.js +63 -0
  28. package/dist/cjs/validators/move_validator.js +10 -0
  29. package/dist/cjs/validators/nano_validator.js +28 -0
  30. package/dist/cjs/validators/nem_validator.js +19 -0
  31. package/dist/cjs/validators/polkadot_validator.js +54 -0
  32. package/dist/cjs/validators/ripple_validator.js +35 -0
  33. package/dist/cjs/validators/sia_validator.js +32 -0
  34. package/dist/cjs/validators/solana_validator.js +15 -0
  35. package/dist/cjs/validators/tezos_validator.js +35 -0
  36. package/dist/cjs/validators/tron_validator.js +50 -0
  37. package/dist/cjs/validators/xlm_validator.js +43 -0
  38. package/dist/esm/chain-validators.d.ts +2 -0
  39. package/dist/{chain-validators.js → esm/chain-validators.js} +1 -1
  40. package/dist/esm/crypto/base32.d.ts +5 -0
  41. package/dist/esm/crypto/base58.d.ts +4 -0
  42. package/dist/esm/crypto/bech32.d.ts +17 -0
  43. package/dist/esm/crypto/biginteger.d.ts +57 -0
  44. package/dist/esm/crypto/blake256.d.ts +22 -0
  45. package/dist/esm/crypto/blake2b.d.ts +13 -0
  46. package/dist/esm/crypto/cnBase58.d.ts +7 -0
  47. package/dist/{crypto → esm/crypto}/cnBase58.js +1 -1
  48. package/dist/esm/crypto/segwit_addr.d.ts +12 -0
  49. package/dist/{crypto → esm/crypto}/segwit_addr.js +1 -1
  50. package/dist/esm/crypto/utils.d.ts +26 -0
  51. package/dist/esm/helpers.d.ts +2 -0
  52. package/dist/esm/index.d.ts +8 -0
  53. package/dist/{multichain-address-validator.js → esm/index.js} +5 -0
  54. package/dist/esm/types.d.ts +15 -0
  55. package/dist/esm/validators/algorand_validator.d.ts +5 -0
  56. package/dist/esm/validators/base58_validator.d.ts +4 -0
  57. package/dist/esm/validators/bch_validator.d.ts +13 -0
  58. package/dist/esm/validators/bip173_validator.d.ts +7 -0
  59. package/dist/esm/validators/bitcoin_validator.d.ts +12 -0
  60. package/dist/esm/validators/cardano_validator.d.ts +5 -0
  61. package/dist/esm/validators/eos_validator.d.ts +5 -0
  62. package/dist/esm/validators/ethereum_validator.d.ts +6 -0
  63. package/dist/esm/validators/hedera_validator.d.ts +5 -0
  64. package/dist/esm/validators/index.js +18 -0
  65. package/dist/esm/validators/monero_validator.d.ts +5 -0
  66. package/dist/esm/validators/move_validator.d.ts +5 -0
  67. package/dist/esm/validators/nano_validator.d.ts +6 -0
  68. package/dist/esm/validators/nem_validator.d.ts +5 -0
  69. package/dist/esm/validators/polkadot_validator.d.ts +5 -0
  70. package/dist/esm/validators/ripple_validator.d.ts +10 -0
  71. package/dist/esm/validators/sia_validator.d.ts +5 -0
  72. package/dist/esm/validators/solana_validator.d.ts +5 -0
  73. package/dist/esm/validators/tezos_validator.d.ts +5 -0
  74. package/dist/esm/validators/tron_validator.d.ts +8 -0
  75. package/dist/esm/validators/xlm_validator.d.ts +7 -0
  76. package/package.json +15 -3
  77. package/src/chain-validators.ts +1 -1
  78. package/src/crypto/cnBase58.js +1 -1
  79. package/src/crypto/segwit_addr.js +1 -1
  80. package/src/{multichain-address-validator.ts → index.ts} +6 -1
  81. package/test/addresses/ltc-testnet.json +3 -1
  82. package/test/addresses/ltc.json +0 -2
  83. package/test/multichain-address-validator.test.ts +1 -2
  84. package/tsconfig.cjs.json +7 -0
  85. package/tsconfig.esm.json +7 -0
  86. package/tsconfig.json +1 -0
  87. package/dist/multichain-address-validator.bundle.min.js +0 -17
  88. package/dist/multichain-address-validator.d.ts +0 -3
  89. /package/dist/{chain-validators.d.ts → cjs/chain-validators.d.ts} +0 -0
  90. /package/dist/{crypto → cjs/crypto}/base32.d.ts +0 -0
  91. /package/dist/{crypto → cjs/crypto}/base58.d.ts +0 -0
  92. /package/dist/{crypto → cjs/crypto}/bech32.d.ts +0 -0
  93. /package/dist/{crypto → cjs/crypto}/biginteger.d.ts +0 -0
  94. /package/dist/{crypto → cjs/crypto}/blake256.d.ts +0 -0
  95. /package/dist/{crypto → cjs/crypto}/blake2b.d.ts +0 -0
  96. /package/dist/{crypto → cjs/crypto}/cnBase58.d.ts +0 -0
  97. /package/dist/{crypto → cjs/crypto}/utils.d.ts +0 -0
  98. /package/dist/{helpers.d.ts → cjs/helpers.d.ts} +0 -0
  99. /package/dist/{types.d.ts → cjs/types.d.ts} +0 -0
  100. /package/dist/{validators → cjs/validators}/algorand_validator.d.ts +0 -0
  101. /package/dist/{validators → cjs/validators}/base58_validator.d.ts +0 -0
  102. /package/dist/{validators → cjs/validators}/bch_validator.d.ts +0 -0
  103. /package/dist/{validators → cjs/validators}/bip173_validator.d.ts +0 -0
  104. /package/dist/{validators → cjs/validators}/bitcoin_validator.d.ts +0 -0
  105. /package/dist/{validators → cjs/validators}/cardano_validator.d.ts +0 -0
  106. /package/dist/{validators → cjs/validators}/eos_validator.d.ts +0 -0
  107. /package/dist/{validators → cjs/validators}/ethereum_validator.d.ts +0 -0
  108. /package/dist/{validators → cjs/validators}/hedera_validator.d.ts +0 -0
  109. /package/dist/{validators → cjs/validators}/index.d.ts +0 -0
  110. /package/dist/{validators → cjs/validators}/monero_validator.d.ts +0 -0
  111. /package/dist/{validators → cjs/validators}/move_validator.d.ts +0 -0
  112. /package/dist/{validators → cjs/validators}/nano_validator.d.ts +0 -0
  113. /package/dist/{validators → cjs/validators}/nem_validator.d.ts +0 -0
  114. /package/dist/{validators → cjs/validators}/polkadot_validator.d.ts +0 -0
  115. /package/dist/{validators → cjs/validators}/ripple_validator.d.ts +0 -0
  116. /package/dist/{validators → cjs/validators}/sia_validator.d.ts +0 -0
  117. /package/dist/{validators → cjs/validators}/solana_validator.d.ts +0 -0
  118. /package/dist/{validators → cjs/validators}/tezos_validator.d.ts +0 -0
  119. /package/dist/{validators → cjs/validators}/tron_validator.d.ts +0 -0
  120. /package/dist/{validators → cjs/validators}/xlm_validator.d.ts +0 -0
  121. /package/dist/{crypto → esm/crypto}/base32.js +0 -0
  122. /package/dist/{crypto → esm/crypto}/base58.js +0 -0
  123. /package/dist/{crypto → esm/crypto}/bech32.js +0 -0
  124. /package/dist/{crypto → esm/crypto}/biginteger.js +0 -0
  125. /package/dist/{crypto → esm/crypto}/blake256.js +0 -0
  126. /package/dist/{crypto → esm/crypto}/blake2b.js +0 -0
  127. /package/dist/{crypto → esm/crypto}/utils.js +0 -0
  128. /package/dist/{helpers.js → esm/helpers.js} +0 -0
  129. /package/dist/{types.js → esm/types.js} +0 -0
  130. /package/dist/{validators → esm/validators}/algorand_validator.js +0 -0
  131. /package/dist/{validators → esm/validators}/base58_validator.js +0 -0
  132. /package/dist/{validators → esm/validators}/bch_validator.js +0 -0
  133. /package/dist/{validators → esm/validators}/bip173_validator.js +0 -0
  134. /package/dist/{validators → esm/validators}/bitcoin_validator.js +0 -0
  135. /package/dist/{validators → esm/validators}/cardano_validator.js +0 -0
  136. /package/dist/{validators → esm/validators}/eos_validator.js +0 -0
  137. /package/dist/{validators → esm/validators}/ethereum_validator.js +0 -0
  138. /package/dist/{validators → esm/validators}/hedera_validator.js +0 -0
  139. /package/dist/{validators/index.js → esm/validators/index.d.ts} +0 -0
  140. /package/dist/{validators → esm/validators}/monero_validator.js +0 -0
  141. /package/dist/{validators → esm/validators}/move_validator.js +0 -0
  142. /package/dist/{validators → esm/validators}/nano_validator.js +0 -0
  143. /package/dist/{validators → esm/validators}/nem_validator.js +0 -0
  144. /package/dist/{validators → esm/validators}/polkadot_validator.js +0 -0
  145. /package/dist/{validators → esm/validators}/ripple_validator.js +0 -0
  146. /package/dist/{validators → esm/validators}/sia_validator.js +0 -0
  147. /package/dist/{validators → esm/validators}/solana_validator.js +0 -0
  148. /package/dist/{validators → esm/validators}/tezos_validator.js +0 -0
  149. /package/dist/{validators → esm/validators}/tron_validator.js +0 -0
  150. /package/dist/{validators → esm/validators}/xlm_validator.js +0 -0
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_js_1 = __importDefault(require("../crypto/utils.js"));
7
+ const helpers_js_1 = require("../helpers.js");
8
+ const cnBase58_js_1 = __importDefault(require("../crypto/cnBase58.js"));
9
+ const addressRegTest = new RegExp('^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{95}$');
10
+ const integratedAddressRegTest = new RegExp('^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{106}$');
11
+ const types = {
12
+ addressTypes: { mainnet: ['18', '42'], testnet: ['53', '63'], stagenet: ['24'] },
13
+ iAddressTypes: { mainnet: ['19'], testnet: ['54'], stagenet: ['25'] },
14
+ };
15
+ function validateNetwork(decoded, networkType, addressType) {
16
+ const addressTypes = addressType === 'integrated'
17
+ ? types.iAddressTypes[networkType]
18
+ : types.addressTypes[networkType];
19
+ const at = parseInt(decoded.substr(0, 2), 16).toString();
20
+ switch (networkType) {
21
+ case 'mainnet':
22
+ return addressTypes.indexOf(at) >= 0;
23
+ case 'testnet':
24
+ return addressTypes.indexOf(at) >= 0;
25
+ // case 'stagenet':
26
+ // return network.stagenet.indexOf(at) >= 0
27
+ // case 'both':
28
+ // return network.prod.indexOf(at) >= 0 || network.testnet.indexOf(at) >= 0 || network.stagenet.indexOf(at) >= 0
29
+ default:
30
+ return false;
31
+ }
32
+ }
33
+ function hextobin(hex) {
34
+ if (hex.length % 2 !== 0)
35
+ return null;
36
+ const res = new Uint8Array(hex.length / 2);
37
+ for (let i = 0; i < hex.length / 2; ++i) {
38
+ res[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
39
+ }
40
+ return res;
41
+ }
42
+ exports.default = (networkType) => ({
43
+ isValidAddress(address) {
44
+ const addr = (0, helpers_js_1.getAddress)(address);
45
+ let addressType = 'standard';
46
+ if (!addressRegTest.test(addr)) {
47
+ if (integratedAddressRegTest.test(addr)) {
48
+ addressType = 'integrated';
49
+ }
50
+ else {
51
+ return false;
52
+ }
53
+ }
54
+ const decodedAddrStr = cnBase58_js_1.default.decode(addr);
55
+ if (!decodedAddrStr)
56
+ return false;
57
+ if (!validateNetwork(decodedAddrStr, networkType, addressType))
58
+ return false;
59
+ const addrChecksum = decodedAddrStr.slice(-8);
60
+ const hashChecksum = utils_js_1.default.keccak256Checksum(hextobin(decodedAddrStr.slice(0, -8)));
61
+ return addrChecksum === hashChecksum;
62
+ }
63
+ });
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const helpers_js_1 = require("../helpers.js");
4
+ const regexp = new RegExp('^0x[0-9a-fA-F]{64}$');
5
+ exports.default = {
6
+ isValidAddress(address) {
7
+ const addr = (0, helpers_js_1.getAddress)(address);
8
+ return regexp.test(addr);
9
+ },
10
+ };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const base_x_1 = __importDefault(require("base-x"));
7
+ const utils_js_1 = __importDefault(require("../crypto/utils.js"));
8
+ const helpers_js_1 = require("../helpers.js");
9
+ const ALLOWED_CHARS = '13456789abcdefghijkmnopqrstuwxyz';
10
+ const codec = (0, base_x_1.default)(ALLOWED_CHARS);
11
+ // https://github.com/nanocurrency/raiblocks/wiki/Accounts,-Keys,-Seeds,-and-Wallet-Identifiers
12
+ const regexp = new RegExp('^(xrb|nano)_([' + ALLOWED_CHARS + ']{60})$');
13
+ exports.default = {
14
+ isValidAddress(address) {
15
+ const addr = (0, helpers_js_1.getAddress)(address);
16
+ if (regexp.test(addr)) {
17
+ return this.verifyChecksum(addr);
18
+ }
19
+ return false;
20
+ },
21
+ verifyChecksum: function (address) {
22
+ const bytes = codec.decode(regexp.exec(address)[2]).slice(-37);
23
+ // https://github.com/nanocurrency/raiblocks/blob/master/rai/lib/numbers.cpp#L73
24
+ const computedChecksum = utils_js_1.default.blake2b(utils_js_1.default.toHex(bytes.slice(0, -5)), 5);
25
+ const checksum = utils_js_1.default.toHex(bytes.slice(-5).reverse());
26
+ return computedChecksum === checksum;
27
+ }
28
+ };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const buffer_1 = require("buffer");
7
+ const utils_js_1 = __importDefault(require("../crypto/utils.js"));
8
+ const helpers_js_1 = require("../helpers.js");
9
+ exports.default = {
10
+ isValidAddress(address) {
11
+ const addr = (0, helpers_js_1.getAddress)(address).toString().toUpperCase().replace(/-/g, '');
12
+ if (!address || addr.length !== 40) {
13
+ return false;
14
+ }
15
+ const decoded = utils_js_1.default.toHex(utils_js_1.default.base32.b32decode(addr));
16
+ const stepThreeChecksum = utils_js_1.default.keccak256Checksum(buffer_1.Buffer.from(decoded.slice(0, 42), 'hex'));
17
+ return stepThreeChecksum === decoded.slice(42);
18
+ }
19
+ };
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_js_1 = __importDefault(require("../crypto/utils.js"));
7
+ const helpers_js_1 = require("../helpers.js");
8
+ // from https://github.com/paritytech/substrate/wiki/External-Address-Format-(SS58)
9
+ const addressFormats = [
10
+ { addressLength: 3, accountIndexLength: 1, checkSumLength: 1 },
11
+ { addressLength: 4, accountIndexLength: 2, checkSumLength: 1 },
12
+ { addressLength: 5, accountIndexLength: 2, checkSumLength: 2 },
13
+ { addressLength: 6, accountIndexLength: 4, checkSumLength: 1 },
14
+ { addressLength: 7, accountIndexLength: 4, checkSumLength: 2 },
15
+ { addressLength: 8, accountIndexLength: 4, checkSumLength: 3 },
16
+ { addressLength: 9, accountIndexLength: 4, checkSumLength: 4 },
17
+ { addressLength: 10, accountIndexLength: 8, checkSumLength: 1 },
18
+ { addressLength: 11, accountIndexLength: 8, checkSumLength: 2 },
19
+ { addressLength: 12, accountIndexLength: 8, checkSumLength: 3 },
20
+ { addressLength: 13, accountIndexLength: 8, checkSumLength: 4 },
21
+ { addressLength: 14, accountIndexLength: 8, checkSumLength: 5 },
22
+ { addressLength: 15, accountIndexLength: 8, checkSumLength: 6 },
23
+ { addressLength: 16, accountIndexLength: 8, checkSumLength: 7 },
24
+ { addressLength: 17, accountIndexLength: 8, checkSumLength: 8 },
25
+ { addressLength: 34, accountIndexLength: 32, checkSumLength: 2 },
26
+ ];
27
+ function verifyChecksum(address) {
28
+ try {
29
+ const preImage = '53533538505245';
30
+ const decoded = utils_js_1.default.base58(address);
31
+ const addressType = utils_js_1.default.byteArray2hexStr(decoded.slice(0, 1));
32
+ const addressAndChecksum = decoded.slice(1);
33
+ // get the address format
34
+ const addressFormat = addressFormats.find(af => af.addressLength === addressAndChecksum.length);
35
+ if (!addressFormat) {
36
+ throw new Error('Invalid address length');
37
+ }
38
+ const decodedAddress = utils_js_1.default.byteArray2hexStr(addressAndChecksum.slice(0, addressFormat.accountIndexLength));
39
+ const checksum = utils_js_1.default.byteArray2hexStr(addressAndChecksum.slice(-addressFormat.checkSumLength));
40
+ const calculatedHash = utils_js_1.default
41
+ .blake2b(preImage + addressType + decodedAddress, 64)
42
+ .substr(0, addressFormat.checkSumLength * 2)
43
+ .toUpperCase();
44
+ return calculatedHash == checksum;
45
+ }
46
+ catch (err) {
47
+ return false;
48
+ }
49
+ }
50
+ exports.default = {
51
+ isValidAddress(address) {
52
+ return verifyChecksum((0, helpers_js_1.getAddress)(address));
53
+ },
54
+ };
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const base_x_1 = __importDefault(require("base-x"));
7
+ const utils_js_1 = __importDefault(require("../crypto/utils.js"));
8
+ const helpers_js_1 = require("../helpers.js");
9
+ const ALLOWED_CHARS = 'rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz';
10
+ const codec = (0, base_x_1.default)(ALLOWED_CHARS);
11
+ const regexp = new RegExp('^r[' + ALLOWED_CHARS + ']{27,35}$');
12
+ exports.default = {
13
+ /**
14
+ * ripple address validation
15
+ */
16
+ isValidAddress: function (address) {
17
+ const addr = (0, helpers_js_1.getAddress)(address);
18
+ const destinationTag = address.destinationTag;
19
+ const validAddress = regexp.test(addr) && this.verifyChecksum(addr);
20
+ return validAddress && this.verifyMemo(destinationTag);
21
+ },
22
+ verifyMemo(destinationTag) {
23
+ if (!destinationTag)
24
+ return true; // Optional
25
+ const tagNumber = Number(destinationTag);
26
+ // A destination tag is a 32-bit unsigned integer.
27
+ return /^[0-9]+$/.test(destinationTag) && tagNumber >= 0 && tagNumber <= 4294967295;
28
+ },
29
+ verifyChecksum: function (address) {
30
+ const bytes = codec.decode(address);
31
+ const computedChecksum = utils_js_1.default.sha256Checksum(utils_js_1.default.toHex(bytes.slice(0, -4)));
32
+ const checksum = utils_js_1.default.toHex(bytes.slice(-4));
33
+ return computedChecksum === checksum;
34
+ }
35
+ };
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const lodash_isequal_1 = __importDefault(require("lodash.isequal"));
7
+ const utils_js_1 = __importDefault(require("../crypto/utils.js"));
8
+ const helpers_js_1 = require("../helpers.js");
9
+ function hexToBytes(hex) {
10
+ const bytes = [];
11
+ for (let c = 0; c < hex.length; c += 2) {
12
+ bytes.push(parseInt(hex.substr(c, 2), 16));
13
+ }
14
+ return bytes;
15
+ }
16
+ function verifyChecksum(address) {
17
+ const checksumBytes = address.slice(0, 32 * 2);
18
+ const check = address.slice(32 * 2, 38 * 2);
19
+ const blakeHash = utils_js_1.default.blake2b(checksumBytes, 32).slice(0, 6 * 2);
20
+ return !!(0, lodash_isequal_1.default)(blakeHash, check);
21
+ }
22
+ exports.default = {
23
+ isValidAddress: function (address) {
24
+ const addr = (0, helpers_js_1.getAddress)(address);
25
+ if (addr.length !== 76) {
26
+ // Check if it has the basic requirements of an address
27
+ return false;
28
+ }
29
+ // Otherwise check each case
30
+ return verifyChecksum(addr);
31
+ },
32
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const base58_validator_js_1 = __importDefault(require("./base58_validator.js"));
7
+ const helpers_js_1 = require("../helpers.js");
8
+ exports.default = {
9
+ isValidAddress: function (address) {
10
+ return base58_validator_js_1.default.isValidAddress((0, helpers_js_1.getAddress)(address), {
11
+ maxLength: 44,
12
+ minLength: 43,
13
+ });
14
+ }
15
+ };
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const base58_js_1 = __importDefault(require("../crypto/base58.js"));
7
+ const utils_js_1 = __importDefault(require("../crypto/utils.js"));
8
+ const helpers_js_1 = require("../helpers.js");
9
+ const prefix = new Uint8Array([6, 161, 159]);
10
+ function decodeRaw(buffer) {
11
+ let payload = buffer.slice(0, -4);
12
+ let checksum = buffer.slice(-4);
13
+ let newChecksum = utils_js_1.default.hexStr2byteArray(utils_js_1.default.sha256x2(utils_js_1.default.byteArray2hexStr(payload)));
14
+ if (checksum[0] ^ newChecksum[0] |
15
+ checksum[1] ^ newChecksum[1] |
16
+ checksum[2] ^ newChecksum[2] |
17
+ checksum[3] ^ newChecksum[3])
18
+ return;
19
+ return payload;
20
+ }
21
+ exports.default = {
22
+ isValidAddress(address) {
23
+ try {
24
+ let buffer = base58_js_1.default.decode((0, helpers_js_1.getAddress)(address));
25
+ let payload = decodeRaw(buffer);
26
+ if (!payload)
27
+ return false;
28
+ payload.slice(prefix.length);
29
+ return true;
30
+ }
31
+ catch (e) {
32
+ return false;
33
+ }
34
+ }
35
+ };
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_js_1 = __importDefault(require("../crypto/utils.js"));
7
+ const helpers_js_1 = require("../helpers.js");
8
+ function decodeBase58Address(base58String) {
9
+ if (typeof (base58String) !== 'string') {
10
+ return false;
11
+ }
12
+ if (base58String.length !== 34) {
13
+ return false;
14
+ }
15
+ let address;
16
+ try {
17
+ address = utils_js_1.default.base58(base58String);
18
+ }
19
+ catch (e) {
20
+ return false;
21
+ }
22
+ const len = address.length;
23
+ const offset = len - 4;
24
+ const checkSum = address.slice(offset);
25
+ address = address.slice(0, offset);
26
+ const hash0 = utils_js_1.default.sha256(utils_js_1.default.byteArray2hexStr(address));
27
+ const hash1 = utils_js_1.default.hexStr2byteArray(utils_js_1.default.sha256(hash0));
28
+ const checkSum1 = hash1.slice(0, 4);
29
+ if (checkSum[0] === checkSum1[0] && checkSum[1] === checkSum1[1] && checkSum[2]
30
+ === checkSum1[2] && checkSum[3] === checkSum1[3]) {
31
+ return address;
32
+ }
33
+ return false;
34
+ }
35
+ const DefaultTronValidatorOpts = {
36
+ addressTypes: ['65']
37
+ };
38
+ exports.default = (opts) => ({
39
+ isValidAddress: function (address) {
40
+ const _opts = { ...DefaultTronValidatorOpts, ...opts };
41
+ const addr = decodeBase58Address((0, helpers_js_1.getAddress)(address));
42
+ if (!addr) {
43
+ return false;
44
+ }
45
+ if (addr.length !== 21) {
46
+ return false;
47
+ }
48
+ return _opts.addressTypes.includes(addr[0].toString());
49
+ }
50
+ });
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const base_x_1 = __importDefault(require("base-x"));
7
+ const crc_1 = __importDefault(require("crc"));
8
+ const utils_js_1 = __importDefault(require("../crypto/utils.js"));
9
+ const helpers_js_1 = require("../helpers.js");
10
+ const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
11
+ const base32 = (0, base_x_1.default)(ALPHABET);
12
+ const regexp = new RegExp('^[' + ALPHABET + ']{56}$');
13
+ const ed25519PublicKeyVersionByte = (6 << 3);
14
+ function swap16(number) {
15
+ const lower = number & 0xFF;
16
+ const upper = (number >> 8) & 0xFF;
17
+ return (lower << 8) | upper;
18
+ }
19
+ exports.default = {
20
+ isValidAddress: function (address) {
21
+ const addr = (0, helpers_js_1.getAddress)(address);
22
+ const destinationTag = address.destinationTag;
23
+ const validAddress = regexp.test(addr) && this.verifyChecksum(addr);
24
+ return validAddress && this.verifyMemo(destinationTag);
25
+ },
26
+ verifyMemo(memo) {
27
+ if (!memo)
28
+ return true; // Optional
29
+ // Ensure it's a valid UTF-8 string and does not exceed 28 bytes
30
+ const encoder = new TextEncoder();
31
+ return encoder.encode(memo).length <= 28;
32
+ },
33
+ verifyChecksum: function (address) {
34
+ // based on https://github.com/stellar/js-stellar-base/blob/master/src/strkey.js#L126
35
+ var bytes = base32.decode(address);
36
+ if (bytes[0] !== ed25519PublicKeyVersionByte) {
37
+ return false;
38
+ }
39
+ const computedChecksum = utils_js_1.default.numberToHex(swap16(crc_1.default.crc16xmodem(bytes.slice(0, -2))), 4);
40
+ const checksum = utils_js_1.default.toHex(bytes.slice(-2));
41
+ return computedChecksum === checksum;
42
+ }
43
+ };
@@ -0,0 +1,2 @@
1
+ import type { Chain, Validator } from './types.js';
2
+ export declare function getValidatorForChain(chain: Chain): Validator | undefined;
@@ -72,7 +72,7 @@ const chainValidators = {
72
72
  alternatives: ['ltc'],
73
73
  validator: {
74
74
  mainnet: BTCValidator({
75
- addressTypes: ['30', '05', '32'],
75
+ addressTypes: ['30', '32'],
76
76
  bech32Hrp: ['ltc'],
77
77
  }),
78
78
  testnet: BTCValidator({
@@ -0,0 +1,5 @@
1
+ declare const _default: {
2
+ b32decode: (s: string) => Uint8Array;
3
+ b32encode: (s: string) => string;
4
+ };
5
+ export default _default;
@@ -0,0 +1,4 @@
1
+ declare const _default: {
2
+ decode: (string: string) => number[];
3
+ };
4
+ export default _default;
@@ -0,0 +1,17 @@
1
+ declare namespace _default {
2
+ export { decode };
3
+ export { encode };
4
+ export { encodings };
5
+ export { verifyChecksum };
6
+ }
7
+ export default _default;
8
+ declare function decode(bechString: any, enc: any): {
9
+ hrp: any;
10
+ data: number[];
11
+ };
12
+ declare function encode(hrp: any, data: any, enc: any): string;
13
+ declare namespace encodings {
14
+ let BECH32: string;
15
+ let BECH32M: string;
16
+ }
17
+ declare function verifyChecksum(hrp: any, data: any, enc: any): boolean;
@@ -0,0 +1,57 @@
1
+ export function BigInteger(n: any, s: any, token: any): BigInteger;
2
+ export class BigInteger {
3
+ constructor(n: any, s: any, token: any);
4
+ _d: any;
5
+ _s: any;
6
+ toString(base: any): any;
7
+ add(n: any): any;
8
+ negate(): BigInteger;
9
+ abs(): BigInteger;
10
+ subtract(n: any): any;
11
+ compareAbs(n: any): any;
12
+ compare(n: any): any;
13
+ isUnit(): boolean;
14
+ multiply(n: any): any;
15
+ multiplySingleDigit(n: any): any;
16
+ square(): BigInteger;
17
+ quotient(n: any): BigInteger;
18
+ divide: any;
19
+ remainder(n: any): BigInteger;
20
+ divRem(n: any): BigInteger[];
21
+ divRemSmall(n: any): BigInteger[];
22
+ isEven(): boolean;
23
+ isOdd(): boolean;
24
+ sign(): any;
25
+ isPositive(): boolean;
26
+ isNegative(): boolean;
27
+ isZero(): boolean;
28
+ exp10(n: any): BigInteger;
29
+ pow(n: any): BigInteger;
30
+ modPow(exponent: any, modulus: any): BigInteger;
31
+ log(): number;
32
+ valueOf(): any;
33
+ toJSValue(): number;
34
+ lowVal(): any;
35
+ }
36
+ export namespace BigInteger {
37
+ export function _construct(n: any, s: any): BigInteger;
38
+ export { BigInteger_base as base };
39
+ export { BigInteger_base_log10 as base_log10 };
40
+ export { ZERO };
41
+ export { ONE };
42
+ export { M_ONE };
43
+ export { ZERO as _0 };
44
+ export { ONE as _1 };
45
+ export let small: BigInteger[];
46
+ export let digits: string[];
47
+ export let radixRegex: RegExp[];
48
+ export function parse(s: any, base: any): BigInteger;
49
+ export { MAX_EXP };
50
+ }
51
+ declare var BigInteger_base: number;
52
+ declare var BigInteger_base_log10: number;
53
+ declare var ZERO: BigInteger;
54
+ declare var ONE: BigInteger;
55
+ declare var M_ONE: BigInteger;
56
+ declare var MAX_EXP: BigInteger;
57
+ export {};
@@ -0,0 +1,22 @@
1
+ export default Blake256;
2
+ declare function Blake256(): void;
3
+ declare class Blake256 {
4
+ _h: number[];
5
+ _s: number[];
6
+ _block: any;
7
+ _blockOffset: number;
8
+ _length: number[];
9
+ _nullt: boolean;
10
+ _zo: any;
11
+ _oo: any;
12
+ _length_carry(arr: any): void;
13
+ update(data: any, encoding: any): this;
14
+ _compress(): void;
15
+ _padding(): void;
16
+ digest(encoding: any): any;
17
+ }
18
+ declare namespace Blake256 {
19
+ let sigma: number[][];
20
+ let u256: number[];
21
+ let padding: any;
22
+ }
@@ -0,0 +1,13 @@
1
+ export default Blake2b;
2
+ declare function Blake2b(outlen: any, key: any, salt: any, personal: any): void;
3
+ declare class Blake2b {
4
+ constructor(outlen: any, key: any, salt: any, personal: any);
5
+ b: Uint8Array;
6
+ h: Uint32Array;
7
+ t: number;
8
+ c: number;
9
+ outlen: any;
10
+ update(input: any): this;
11
+ digest(out: any): any;
12
+ final: any;
13
+ }
@@ -0,0 +1,7 @@
1
+ export default cnBase58;
2
+ declare namespace cnBase58 {
3
+ function encode_block(data: any, buf: any, index: any): any;
4
+ function encode(hex: any): string;
5
+ function decode_block(data: any, buf: any, index: any): any;
6
+ function decode(enc: any): string;
7
+ }
@@ -1,4 +1,4 @@
1
- import { BigInteger as JSBigInt } from './biginteger';
1
+ import { BigInteger as JSBigInt } from './biginteger.js';
2
2
  /**
3
3
  Copyright (c) 2017, moneroexamples
4
4
 
@@ -0,0 +1,12 @@
1
+ declare namespace _default {
2
+ export { encode };
3
+ export { decode };
4
+ export { isValidAddress };
5
+ }
6
+ export default _default;
7
+ declare function encode(hrp: any, version: any, program: any): string;
8
+ declare function decode(hrp: any, addr: any): {
9
+ version: number;
10
+ program: number[];
11
+ };
12
+ declare function isValidAddress(address: any, opts?: {}): boolean;
@@ -17,7 +17,7 @@
17
17
  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
18
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  // THE SOFTWARE.
20
- import bech32 from './bech32';
20
+ import bech32 from './bech32.js';
21
21
  function convertbits(data, frombits, tobits, pad) {
22
22
  var acc = 0;
23
23
  var bits = 0;
@@ -0,0 +1,26 @@
1
+ declare function numberToHex(number: number, length: number): string;
2
+ declare function byteArray2hexStr(byteArray: number[]): string;
3
+ declare function hexStr2byteArray(str: string): Uint8Array;
4
+ declare const _default: {
5
+ numberToHex: typeof numberToHex;
6
+ toHex: (arrayOfBytes: any) => string;
7
+ sha256: (payload: any, format?: string) => string;
8
+ sha256x2: (buffer: any, format?: string) => any;
9
+ sha256Checksum: (payload: any) => any;
10
+ sha512: (payload: any, format?: string) => string;
11
+ sha512_256: (payload: any, format?: string) => string;
12
+ blake256: (hexString: string) => any;
13
+ blake256Checksum: (payload: any) => any;
14
+ blake2b: (hexString: string, outlen: number) => any;
15
+ keccak256: (hexString: string) => string;
16
+ keccak256Checksum: (payload: any) => any;
17
+ blake2b256: (hexString: string) => any;
18
+ base58: (string: string) => number[];
19
+ byteArray2hexStr: typeof byteArray2hexStr;
20
+ hexStr2byteArray: typeof hexStr2byteArray;
21
+ base32: {
22
+ b32decode: (s: string) => Uint8Array;
23
+ b32encode: (s: string) => string;
24
+ };
25
+ };
26
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import { Address } from './types.js';
2
+ export declare function getAddress(address: Address): string;
@@ -0,0 +1,8 @@
1
+ import { Address, Chain, NetworkType } from './types.js';
2
+ export declare function validate(address: Address, chain: Chain): boolean;
3
+ export type { Address, Chain };
4
+ export { NetworkType };
5
+ declare const _default: {
6
+ validate: typeof validate;
7
+ };
8
+ export default _default;
@@ -1,3 +1,4 @@
1
+ import { NetworkType } from './types.js';
1
2
  import { getValidatorForChain } from './chain-validators.js';
2
3
  export function validate(address, chain) {
3
4
  const validator = getValidatorForChain(chain);
@@ -6,3 +7,7 @@ export function validate(address, chain) {
6
7
  }
7
8
  return validator.isValidAddress(address);
8
9
  }
10
+ export { NetworkType };
11
+ export default {
12
+ validate
13
+ };
@@ -0,0 +1,15 @@
1
+ export type Address = string | {
2
+ address: string;
3
+ memo?: string;
4
+ };
5
+ export type Chain = string | {
6
+ chain: string;
7
+ networkType?: NetworkType;
8
+ };
9
+ export interface Validator {
10
+ isValidAddress(address: Address): boolean;
11
+ }
12
+ export declare enum NetworkType {
13
+ MainNet = "mainnet",
14
+ TestNet = "testnet"
15
+ }
@@ -0,0 +1,5 @@
1
+ import { Address } from '../types.js';
2
+ declare const _default: {
3
+ isValidAddress: (address: Address) => boolean;
4
+ };
5
+ export default _default;
@@ -0,0 +1,4 @@
1
+ declare const _default: {
2
+ isValidAddress: (address: any, opts: any) => boolean;
3
+ };
4
+ export default _default;