multichain-address-validator 0.7.9 → 0.8.1

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 (99) hide show
  1. package/README.md +0 -1
  2. package/dist/cjs/chain-validators.js +23 -1
  3. package/dist/cjs/crypto/segwit_addr.js +8 -3
  4. package/dist/cjs/validators/bitcoin_validator.d.ts +5 -0
  5. package/dist/cjs/validators/bitcoin_validator.js +6 -5
  6. package/dist/cjs/validators/bittensor_validator.d.ts +2 -0
  7. package/dist/cjs/validators/bittensor_validator.js +11 -0
  8. package/dist/cjs/validators/index.d.ts +2 -0
  9. package/dist/cjs/validators/index.js +5 -1
  10. package/dist/cjs/validators/polkadot_validator.d.ts +1 -4
  11. package/dist/cjs/validators/polkadot_validator.js +5 -49
  12. package/dist/cjs/validators/ss58_validator.d.ts +11 -0
  13. package/dist/cjs/validators/ss58_validator.js +70 -0
  14. package/dist/cjs/validators/zcash_validator.d.ts +5 -0
  15. package/dist/cjs/validators/zcash_validator.js +52 -0
  16. package/dist/esm/chain-validators.js +24 -2
  17. package/dist/esm/crypto/segwit_addr.js +8 -3
  18. package/dist/esm/validators/bitcoin_validator.d.ts +5 -0
  19. package/dist/esm/validators/bitcoin_validator.js +5 -5
  20. package/dist/esm/validators/bittensor_validator.d.ts +2 -0
  21. package/dist/esm/validators/bittensor_validator.js +6 -0
  22. package/dist/esm/validators/index.d.ts +2 -0
  23. package/dist/esm/validators/index.js +2 -0
  24. package/dist/esm/validators/polkadot_validator.d.ts +1 -4
  25. package/dist/esm/validators/polkadot_validator.js +5 -49
  26. package/dist/esm/validators/ss58_validator.d.ts +11 -0
  27. package/dist/esm/validators/ss58_validator.js +64 -0
  28. package/dist/esm/validators/zcash_validator.d.ts +5 -0
  29. package/dist/esm/validators/zcash_validator.js +47 -0
  30. package/package.json +3 -2
  31. package/.editorconfig +0 -10
  32. package/.travis.yml +0 -11
  33. package/.vscode/launch.json +0 -23
  34. package/index.html +0 -12
  35. package/src/chain-validators.ts +0 -161
  36. package/src/crypto/base32.ts +0 -66
  37. package/src/crypto/base58.ts +0 -46
  38. package/src/crypto/bech32.js +0 -132
  39. package/src/crypto/biginteger.js +0 -1426
  40. package/src/crypto/blake256.js +0 -188
  41. package/src/crypto/blake2b.js +0 -276
  42. package/src/crypto/cnBase58.js +0 -226
  43. package/src/crypto/segwit_addr.js +0 -112
  44. package/src/crypto/utils.ts +0 -133
  45. package/src/helpers.ts +0 -13
  46. package/src/index.ts +0 -28
  47. package/src/types.ts +0 -19
  48. package/src/validators/algorand_validator.ts +0 -28
  49. package/src/validators/base58_validator.ts +0 -32
  50. package/src/validators/bch_validator.ts +0 -66
  51. package/src/validators/bip173_validator.ts +0 -19
  52. package/src/validators/bitcoin_validator.ts +0 -94
  53. package/src/validators/cardano_validator.ts +0 -50
  54. package/src/validators/eos_validator.ts +0 -13
  55. package/src/validators/ethereum_validator.ts +0 -37
  56. package/src/validators/hedera_validator.ts +0 -10
  57. package/src/validators/index.ts +0 -18
  58. package/src/validators/monero_validator.ts +0 -72
  59. package/src/validators/move_validator.ts +0 -11
  60. package/src/validators/nano_validator.ts +0 -32
  61. package/src/validators/nem_validator.ts +0 -18
  62. package/src/validators/polkadot_validator.ts +0 -57
  63. package/src/validators/ripple_validator.ts +0 -44
  64. package/src/validators/sia_validator.ts +0 -33
  65. package/src/validators/solana_validator.ts +0 -21
  66. package/src/validators/tezos_validator.ts +0 -36
  67. package/src/validators/tron_validator.ts +0 -59
  68. package/src/validators/xlm_validator.ts +0 -54
  69. package/test/addresses/addresses.ts +0 -59
  70. package/test/addresses/algorand.json +0 -6
  71. package/test/addresses/aptos.json +0 -6
  72. package/test/addresses/bch-testnet.json +0 -4
  73. package/test/addresses/bch.json +0 -7
  74. package/test/addresses/btc-testnet.json +0 -13
  75. package/test/addresses/btc.json +0 -14
  76. package/test/addresses/cardano.json +0 -8
  77. package/test/addresses/doge-testnet.json +0 -3
  78. package/test/addresses/doge.json +0 -7
  79. package/test/addresses/eos.json +0 -6
  80. package/test/addresses/evm.json +0 -20
  81. package/test/addresses/hbar.json +0 -11
  82. package/test/addresses/ltc-testnet.json +0 -10
  83. package/test/addresses/ltc.json +0 -8
  84. package/test/addresses/monero-testnet.json +0 -5
  85. package/test/addresses/monero.json +0 -7
  86. package/test/addresses/nano.json +0 -12
  87. package/test/addresses/nem.json +0 -4
  88. package/test/addresses/polkadot.json +0 -8
  89. package/test/addresses/ripple.json +0 -20
  90. package/test/addresses/sia.json +0 -5
  91. package/test/addresses/solana.json +0 -12
  92. package/test/addresses/sui.json +0 -6
  93. package/test/addresses/tezos.json +0 -9
  94. package/test/addresses/tron.json +0 -6
  95. package/test/addresses/xlm.json +0 -21
  96. package/test/multichain-address-validator.test.ts +0 -225
  97. package/tsconfig.cjs.json +0 -7
  98. package/tsconfig.esm.json +0 -7
  99. package/tsconfig.json +0 -24
package/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # multichain address validator
2
2
  Simple blockchain address validator for validating Bitcoin and other blockchain addresses **Node.js and browser**.
3
3
 
4
- [![Build Status](https://travis-ci.org/christsim/multicchain-address-validator.svg?branch=master)](https://travis-ci.org/christsim/multichain-address-validator)
5
4
 
6
5
  ## Installation
7
6
 
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getValidatorForChain = getValidatorForChain;
4
4
  const types_js_1 = require("./types.js");
5
5
  const index_js_1 = require("./validators/index.js");
6
+ const bitcoin_validator_1 = require("./validators/bitcoin_validator");
6
7
  const chainValidators = {
7
8
  algorand: { validator: index_js_1.AlgorandValidator },
8
9
  aptos: { validator: index_js_1.MoveValidator },
@@ -12,10 +13,12 @@ const chainValidators = {
12
13
  mainnet: (0, index_js_1.BTCValidator)({
13
14
  addressTypes: ['00', '05'],
14
15
  bech32Hrp: ['bc'],
16
+ allowedSegwitVersions: [bitcoin_validator_1.SegwitVersion.NativeSegwit],
15
17
  }),
16
18
  testnet: (0, index_js_1.BTCValidator)({
17
19
  addressTypes: ['6f', 'c4', '3c', '26'],
18
20
  bech32Hrp: ['tb'],
21
+ allowedSegwitVersions: [bitcoin_validator_1.SegwitVersion.NativeSegwit],
19
22
  }),
20
23
  },
21
24
  },
@@ -34,6 +37,10 @@ const chainValidators = {
34
37
  }),
35
38
  }
36
39
  },
40
+ bittensor: {
41
+ alternatives: ['tao'],
42
+ validator: index_js_1.BittensorValidator,
43
+ },
37
44
  cardano: {
38
45
  alternatives: ['ada'],
39
46
  validator: index_js_1.CardanoValidator,
@@ -57,6 +64,8 @@ const chainValidators = {
57
64
  'BinanceSmartChain',
58
65
  'bnb',
59
66
  'bsc',
67
+ 'Xcap',
68
+ 'gas',
60
69
  'eth',
61
70
  'EthereumClassic',
62
71
  'EthereumPow',
@@ -78,10 +87,12 @@ const chainValidators = {
78
87
  mainnet: (0, index_js_1.BTCValidator)({
79
88
  addressTypes: ['30', '32'],
80
89
  bech32Hrp: ['ltc'],
90
+ allowedSegwitVersions: [bitcoin_validator_1.SegwitVersion.NativeSegwit],
81
91
  }),
82
92
  testnet: (0, index_js_1.BTCValidator)({
83
93
  addressTypes: ['6f', 'c4', '3a'],
84
- bech32Hrp: ['tltc']
94
+ bech32Hrp: ['tltc'],
95
+ allowedSegwitVersions: [bitcoin_validator_1.SegwitVersion.NativeSegwit],
85
96
  })
86
97
  }
87
98
  },
@@ -91,6 +102,10 @@ const chainValidators = {
91
102
  testnet: (0, index_js_1.MoneroValidator)(types_js_1.NetworkType.TestNet),
92
103
  }
93
104
  },
105
+ monad: {
106
+ alternatives: ['mon'],
107
+ validator: index_js_1.ETHValidator,
108
+ },
94
109
  nem: { validator: index_js_1.NemValidator },
95
110
  nano: { validator: index_js_1.NanoValidator },
96
111
  polkadot: { validator: index_js_1.PolkadotValidator },
@@ -116,6 +131,13 @@ const chainValidators = {
116
131
  alternatives: ['stellar', 'stellarlumens'],
117
132
  validator: index_js_1.XLMValidator,
118
133
  },
134
+ zcash: {
135
+ alternatives: ['zec'],
136
+ validator: {
137
+ mainnet: (0, index_js_1.ZcashValidator)(types_js_1.NetworkType.MainNet),
138
+ testnet: (0, index_js_1.ZcashValidator)(types_js_1.NetworkType.TestNet),
139
+ }
140
+ },
119
141
  };
120
142
  function getValidatorForChain(chain) {
121
143
  const chainName = chain.chain || chain;
@@ -91,11 +91,16 @@ function isValidAddress(address, opts = {}) {
91
91
  if (!opts.bech32Hrp || opts.bech32Hrp.length === 0) {
92
92
  return false;
93
93
  }
94
+ if (!opts.allowedSegwitVersions?.length) {
95
+ return false;
96
+ }
94
97
  const correctBech32Hrps = opts.bech32Hrp;
95
- for (var chrp of correctBech32Hrps) {
96
- var ret = decode(chrp, address);
98
+ for (const chrp of correctBech32Hrps) {
99
+ const ret = decode(chrp, address);
97
100
  if (ret) {
98
- return encode(chrp, ret.version, ret.program) === address.toLowerCase();
101
+ if (opts.allowedSegwitVersions.includes(ret.version)) {
102
+ return encode(chrp, ret.version, ret.program) === address.toLowerCase();
103
+ }
99
104
  }
100
105
  }
101
106
  return false;
@@ -1,8 +1,13 @@
1
1
  import { Address } from '../types.js';
2
+ export declare enum SegwitVersion {
3
+ NativeSegwit = 0,
4
+ TapRoot = 1
5
+ }
2
6
  interface BTCValidatorOpts {
3
7
  addressTypes: string[];
4
8
  expectedLength?: number;
5
9
  bech32Hrp?: [string];
10
+ allowedSegwitVersions?: [number];
6
11
  hashFunction?: 'blake256' | 'blake256keccak256' | 'keccak256' | 'sha256';
7
12
  regex?: RegExp;
8
13
  }
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SegwitVersion = void 0;
6
7
  const base58_js_1 = __importDefault(require("../crypto/base58.js"));
7
8
  const segwit_addr_js_1 = __importDefault(require("../crypto/segwit_addr.js"));
8
9
  const utils_js_1 = __importDefault(require("../crypto/utils.js"));
@@ -60,14 +61,14 @@ function isValidP2PKHandP2SHAddress(address, opts) {
60
61
  }
61
62
  return false;
62
63
  }
63
- // const DefaultBTCValidatorOpts: BTCValidatorOpts = {
64
- // addressTypes: {mainnet: ['00', '05'], testnet: ['6f', 'c4', '3c', '26']},
65
- // bech32Hrp: {mainnet: ['bc'], testnet: ['tb']},
66
- // }
64
+ var SegwitVersion;
65
+ (function (SegwitVersion) {
66
+ SegwitVersion[SegwitVersion["NativeSegwit"] = 0] = "NativeSegwit";
67
+ SegwitVersion[SegwitVersion["TapRoot"] = 1] = "TapRoot";
68
+ })(SegwitVersion || (exports.SegwitVersion = SegwitVersion = {}));
67
69
  exports.default = (opts) => ({
68
70
  isValidAddress(address) {
69
71
  const addr = (0, helpers_js_1.getAddress)(address);
70
- // const _opts = {...DefaultBTCValidatorOpts, ...opts}
71
72
  return isValidP2PKHandP2SHAddress(addr, opts) || segwit_addr_js_1.default.isValidAddress(addr, opts);
72
73
  }
73
74
  });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../types.js").Validator;
2
+ export default _default;
@@ -0,0 +1,11 @@
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 ss58_validator_js_1 = __importDefault(require("./ss58_validator.js"));
7
+ // Bittensor uses SS58 address format (Substrate-based) with network prefix 42
8
+ // Reference: https://docs.learnbittensor.org/evm-tutorials/convert-h160-to-ss58
9
+ // SS58 Registry: https://github.com/paritytech/ss58-registry
10
+ // Network prefix 42 (0x2A in hex) is used by Bittensor
11
+ exports.default = (0, ss58_validator_js_1.default)({ networkPrefix: 42 });
@@ -1,5 +1,6 @@
1
1
  export { default as AlgorandValidator } from "./algorand_validator.js";
2
2
  export { default as BCHValidator } from "./bch_validator.js";
3
+ export { default as BittensorValidator } from "./bittensor_validator.js";
3
4
  export { default as BTCValidator } from "./bitcoin_validator.js";
4
5
  export { default as CardanoValidator } from "./cardano_validator.js";
5
6
  export { default as EOSValidator } from "./eos_validator.js";
@@ -16,3 +17,4 @@ export { default as SolanaValidator } from "./solana_validator.js";
16
17
  export { default as TezosValidator } from "./tezos_validator.js";
17
18
  export { default as TronValidator } from "./tron_validator.js";
18
19
  export { default as XLMValidator } from "./xlm_validator.js";
20
+ export { default as ZcashValidator } from "./zcash_validator.js";
@@ -3,11 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.XLMValidator = exports.TronValidator = exports.TezosValidator = exports.SolanaValidator = exports.SiaValidator = exports.RippleValidator = exports.PolkadotValidator = exports.NanoValidator = exports.NemValidator = exports.MoveValidator = exports.MoneroValidator = exports.HederaValidator = exports.ETHValidator = exports.EOSValidator = exports.CardanoValidator = exports.BTCValidator = exports.BCHValidator = exports.AlgorandValidator = void 0;
6
+ exports.ZcashValidator = exports.XLMValidator = exports.TronValidator = exports.TezosValidator = exports.SolanaValidator = exports.SiaValidator = exports.RippleValidator = exports.PolkadotValidator = exports.NanoValidator = exports.NemValidator = exports.MoveValidator = exports.MoneroValidator = exports.HederaValidator = exports.ETHValidator = exports.EOSValidator = exports.CardanoValidator = exports.BTCValidator = exports.BittensorValidator = exports.BCHValidator = exports.AlgorandValidator = void 0;
7
7
  var algorand_validator_js_1 = require("./algorand_validator.js");
8
8
  Object.defineProperty(exports, "AlgorandValidator", { enumerable: true, get: function () { return __importDefault(algorand_validator_js_1).default; } });
9
9
  var bch_validator_js_1 = require("./bch_validator.js");
10
10
  Object.defineProperty(exports, "BCHValidator", { enumerable: true, get: function () { return __importDefault(bch_validator_js_1).default; } });
11
+ var bittensor_validator_js_1 = require("./bittensor_validator.js");
12
+ Object.defineProperty(exports, "BittensorValidator", { enumerable: true, get: function () { return __importDefault(bittensor_validator_js_1).default; } });
11
13
  var bitcoin_validator_js_1 = require("./bitcoin_validator.js");
12
14
  Object.defineProperty(exports, "BTCValidator", { enumerable: true, get: function () { return __importDefault(bitcoin_validator_js_1).default; } });
13
15
  var cardano_validator_js_1 = require("./cardano_validator.js");
@@ -40,3 +42,5 @@ var tron_validator_js_1 = require("./tron_validator.js");
40
42
  Object.defineProperty(exports, "TronValidator", { enumerable: true, get: function () { return __importDefault(tron_validator_js_1).default; } });
41
43
  var xlm_validator_js_1 = require("./xlm_validator.js");
42
44
  Object.defineProperty(exports, "XLMValidator", { enumerable: true, get: function () { return __importDefault(xlm_validator_js_1).default; } });
45
+ var zcash_validator_js_1 = require("./zcash_validator.js");
46
+ Object.defineProperty(exports, "ZcashValidator", { enumerable: true, get: function () { return __importDefault(zcash_validator_js_1).default; } });
@@ -1,5 +1,2 @@
1
- import { Address } from '../types.js';
2
- declare const _default: {
3
- isValidAddress(address: Address): boolean;
4
- };
1
+ declare const _default: import("../types.js").Validator;
5
2
  export default _default;
@@ -3,52 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
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
- };
6
+ const ss58_validator_js_1 = __importDefault(require("./ss58_validator.js"));
7
+ // Polkadot uses SS58 address format (Substrate-based)
8
+ // SS58 Registry: https://github.com/paritytech/ss58-registry
9
+ // Accepts any valid SS58 address (no network prefix restriction)
10
+ exports.default = (0, ss58_validator_js_1.default)();
@@ -0,0 +1,11 @@
1
+ import { Validator } from '../types.js';
2
+ interface SS58ValidatorOptions {
3
+ networkPrefix?: number;
4
+ }
5
+ /**
6
+ * Creates an SS58 validator with optional network prefix filtering
7
+ * @param options Configuration options including optional network prefix
8
+ * @returns Validator instance for SS58 addresses
9
+ */
10
+ export default function createSS58Validator(options?: SS58ValidatorOptions): Validator;
11
+ export {};
@@ -0,0 +1,70 @@
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
+ exports.default = createSS58Validator;
7
+ const utils_js_1 = __importDefault(require("../crypto/utils.js"));
8
+ const helpers_js_1 = require("../helpers.js");
9
+ // SS58 address format (Substrate-based)
10
+ // SS58 Registry: https://github.com/paritytech/ss58-registry
11
+ const addressFormats = [
12
+ { addressLength: 3, accountIndexLength: 1, checkSumLength: 1 },
13
+ { addressLength: 4, accountIndexLength: 2, checkSumLength: 1 },
14
+ { addressLength: 5, accountIndexLength: 2, checkSumLength: 2 },
15
+ { addressLength: 6, accountIndexLength: 4, checkSumLength: 1 },
16
+ { addressLength: 7, accountIndexLength: 4, checkSumLength: 2 },
17
+ { addressLength: 8, accountIndexLength: 4, checkSumLength: 3 },
18
+ { addressLength: 9, accountIndexLength: 4, checkSumLength: 4 },
19
+ { addressLength: 10, accountIndexLength: 8, checkSumLength: 1 },
20
+ { addressLength: 11, accountIndexLength: 8, checkSumLength: 2 },
21
+ { addressLength: 12, accountIndexLength: 8, checkSumLength: 3 },
22
+ { addressLength: 13, accountIndexLength: 8, checkSumLength: 4 },
23
+ { addressLength: 14, accountIndexLength: 8, checkSumLength: 5 },
24
+ { addressLength: 15, accountIndexLength: 8, checkSumLength: 6 },
25
+ { addressLength: 16, accountIndexLength: 8, checkSumLength: 7 },
26
+ { addressLength: 17, accountIndexLength: 8, checkSumLength: 8 },
27
+ { addressLength: 34, accountIndexLength: 32, checkSumLength: 2 },
28
+ ];
29
+ /**
30
+ * Creates an SS58 validator with optional network prefix filtering
31
+ * @param options Configuration options including optional network prefix
32
+ * @returns Validator instance for SS58 addresses
33
+ */
34
+ function createSS58Validator(options = {}) {
35
+ function verifyChecksum(address) {
36
+ try {
37
+ const preImage = '53533538505245';
38
+ const decoded = utils_js_1.default.base58(address);
39
+ const addressType = utils_js_1.default.byteArray2hexStr(decoded.slice(0, 1));
40
+ // If a specific network prefix is required, validate it
41
+ if (options.networkPrefix !== undefined) {
42
+ const expectedPrefix = options.networkPrefix.toString(16).padStart(2, '0').toUpperCase();
43
+ if (addressType.toUpperCase() !== expectedPrefix) {
44
+ return false;
45
+ }
46
+ }
47
+ const addressAndChecksum = decoded.slice(1);
48
+ // get the address format
49
+ const addressFormat = addressFormats.find(af => af.addressLength === addressAndChecksum.length);
50
+ if (!addressFormat) {
51
+ throw new Error('Invalid address length');
52
+ }
53
+ const decodedAddress = utils_js_1.default.byteArray2hexStr(addressAndChecksum.slice(0, addressFormat.accountIndexLength));
54
+ const checksum = utils_js_1.default.byteArray2hexStr(addressAndChecksum.slice(-addressFormat.checkSumLength));
55
+ const calculatedHash = utils_js_1.default
56
+ .blake2b(preImage + addressType + decodedAddress, 64)
57
+ .substr(0, addressFormat.checkSumLength * 2)
58
+ .toUpperCase();
59
+ return calculatedHash == checksum;
60
+ }
61
+ catch (err) {
62
+ return false;
63
+ }
64
+ }
65
+ return {
66
+ isValidAddress(address) {
67
+ return verifyChecksum((0, helpers_js_1.getAddress)(address));
68
+ },
69
+ };
70
+ }
@@ -0,0 +1,5 @@
1
+ import { Address, NetworkType } from '../types.js';
2
+ declare const _default: (networkType: NetworkType) => {
3
+ isValidAddress(address: Address): boolean;
4
+ };
5
+ export default _default;
@@ -0,0 +1,52 @@
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 types_js_1 = require("../types.js");
9
+ const helpers_js_1 = require("../helpers.js");
10
+ function getDecoded(address) {
11
+ try {
12
+ return base58_js_1.default.decode(address);
13
+ }
14
+ catch (e) {
15
+ // if decoding fails, assume invalid address
16
+ return null;
17
+ }
18
+ }
19
+ function getChecksum(payload) {
20
+ return utils_js_1.default.sha256Checksum(payload);
21
+ }
22
+ function isValidTransparentAddress(address, networkType) {
23
+ // Zcash transparent addresses use 2-byte version prefixes
24
+ // Expected length: 26 bytes (2 bytes version + 20 bytes payload + 4 bytes checksum)
25
+ const expectedLength = 26;
26
+ const decoded = getDecoded(address);
27
+ if (!decoded || decoded.length !== expectedLength) {
28
+ return false;
29
+ }
30
+ const checksum = utils_js_1.default.toHex(decoded.slice(expectedLength - 4, expectedLength));
31
+ const body = utils_js_1.default.toHex(decoded.slice(0, expectedLength - 4));
32
+ const goodChecksum = getChecksum(body);
33
+ if (checksum !== goodChecksum) {
34
+ return false;
35
+ }
36
+ // Get the 2-byte version prefix
37
+ const versionPrefix = utils_js_1.default.toHex(decoded.slice(0, 2));
38
+ // Define valid version prefixes for each network
39
+ // Only supporting transparent addresses (t1/t3 for mainnet, tm/t2 for testnet)
40
+ const validPrefixes = networkType === types_js_1.NetworkType.MainNet
41
+ ? ['1cb8', '1cbd'] // t1 (P2PKH) and t3 (P2SH) for mainnet
42
+ : ['1d25', '1cba']; // tm (P2PKH) and t2 (P2SH) for testnet
43
+ return validPrefixes.includes(versionPrefix);
44
+ }
45
+ exports.default = (networkType) => ({
46
+ isValidAddress(address) {
47
+ const addr = (0, helpers_js_1.getAddress)(address);
48
+ // Only validate transparent addresses (t1/t3 for mainnet, tm/t2 for testnet)
49
+ // Sapling (zs) and Unified (u) addresses are NOT supported
50
+ return isValidTransparentAddress(addr, networkType);
51
+ }
52
+ });
@@ -1,5 +1,6 @@
1
1
  import { NetworkType } from './types.js';
2
- import { AlgorandValidator, BCHValidator, BTCValidator, CardanoValidator, EOSValidator, ETHValidator, HederaValidator, MoneroValidator, MoveValidator, NanoValidator, NemValidator, PolkadotValidator, RippleValidator, SiaValidator, SolanaValidator, TezosValidator, TronValidator, XLMValidator, } from './validators/index.js';
2
+ import { AlgorandValidator, BCHValidator, BittensorValidator, BTCValidator, CardanoValidator, EOSValidator, ETHValidator, HederaValidator, MoneroValidator, MoveValidator, NanoValidator, NemValidator, PolkadotValidator, RippleValidator, SiaValidator, SolanaValidator, TezosValidator, TronValidator, XLMValidator, ZcashValidator, } from './validators/index.js';
3
+ import { SegwitVersion } from './validators/bitcoin_validator';
3
4
  const chainValidators = {
4
5
  algorand: { validator: AlgorandValidator },
5
6
  aptos: { validator: MoveValidator },
@@ -9,10 +10,12 @@ const chainValidators = {
9
10
  mainnet: BTCValidator({
10
11
  addressTypes: ['00', '05'],
11
12
  bech32Hrp: ['bc'],
13
+ allowedSegwitVersions: [SegwitVersion.NativeSegwit],
12
14
  }),
13
15
  testnet: BTCValidator({
14
16
  addressTypes: ['6f', 'c4', '3c', '26'],
15
17
  bech32Hrp: ['tb'],
18
+ allowedSegwitVersions: [SegwitVersion.NativeSegwit],
16
19
  }),
17
20
  },
18
21
  },
@@ -31,6 +34,10 @@ const chainValidators = {
31
34
  }),
32
35
  }
33
36
  },
37
+ bittensor: {
38
+ alternatives: ['tao'],
39
+ validator: BittensorValidator,
40
+ },
34
41
  cardano: {
35
42
  alternatives: ['ada'],
36
43
  validator: CardanoValidator,
@@ -54,6 +61,8 @@ const chainValidators = {
54
61
  'BinanceSmartChain',
55
62
  'bnb',
56
63
  'bsc',
64
+ 'Xcap',
65
+ 'gas',
57
66
  'eth',
58
67
  'EthereumClassic',
59
68
  'EthereumPow',
@@ -75,10 +84,12 @@ const chainValidators = {
75
84
  mainnet: BTCValidator({
76
85
  addressTypes: ['30', '32'],
77
86
  bech32Hrp: ['ltc'],
87
+ allowedSegwitVersions: [SegwitVersion.NativeSegwit],
78
88
  }),
79
89
  testnet: BTCValidator({
80
90
  addressTypes: ['6f', 'c4', '3a'],
81
- bech32Hrp: ['tltc']
91
+ bech32Hrp: ['tltc'],
92
+ allowedSegwitVersions: [SegwitVersion.NativeSegwit],
82
93
  })
83
94
  }
84
95
  },
@@ -88,6 +99,10 @@ const chainValidators = {
88
99
  testnet: MoneroValidator(NetworkType.TestNet),
89
100
  }
90
101
  },
102
+ monad: {
103
+ alternatives: ['mon'],
104
+ validator: ETHValidator,
105
+ },
91
106
  nem: { validator: NemValidator },
92
107
  nano: { validator: NanoValidator },
93
108
  polkadot: { validator: PolkadotValidator },
@@ -113,6 +128,13 @@ const chainValidators = {
113
128
  alternatives: ['stellar', 'stellarlumens'],
114
129
  validator: XLMValidator,
115
130
  },
131
+ zcash: {
132
+ alternatives: ['zec'],
133
+ validator: {
134
+ mainnet: ZcashValidator(NetworkType.MainNet),
135
+ testnet: ZcashValidator(NetworkType.TestNet),
136
+ }
137
+ },
116
138
  };
117
139
  export function getValidatorForChain(chain) {
118
140
  const chainName = chain.chain || chain;
@@ -86,11 +86,16 @@ function isValidAddress(address, opts = {}) {
86
86
  if (!opts.bech32Hrp || opts.bech32Hrp.length === 0) {
87
87
  return false;
88
88
  }
89
+ if (!opts.allowedSegwitVersions?.length) {
90
+ return false;
91
+ }
89
92
  const correctBech32Hrps = opts.bech32Hrp;
90
- for (var chrp of correctBech32Hrps) {
91
- var ret = decode(chrp, address);
93
+ for (const chrp of correctBech32Hrps) {
94
+ const ret = decode(chrp, address);
92
95
  if (ret) {
93
- return encode(chrp, ret.version, ret.program) === address.toLowerCase();
96
+ if (opts.allowedSegwitVersions.includes(ret.version)) {
97
+ return encode(chrp, ret.version, ret.program) === address.toLowerCase();
98
+ }
94
99
  }
95
100
  }
96
101
  return false;
@@ -1,8 +1,13 @@
1
1
  import { Address } from '../types.js';
2
+ export declare enum SegwitVersion {
3
+ NativeSegwit = 0,
4
+ TapRoot = 1
5
+ }
2
6
  interface BTCValidatorOpts {
3
7
  addressTypes: string[];
4
8
  expectedLength?: number;
5
9
  bech32Hrp?: [string];
10
+ allowedSegwitVersions?: [number];
6
11
  hashFunction?: 'blake256' | 'blake256keccak256' | 'keccak256' | 'sha256';
7
12
  regex?: RegExp;
8
13
  }
@@ -55,14 +55,14 @@ function isValidP2PKHandP2SHAddress(address, opts) {
55
55
  }
56
56
  return false;
57
57
  }
58
- // const DefaultBTCValidatorOpts: BTCValidatorOpts = {
59
- // addressTypes: {mainnet: ['00', '05'], testnet: ['6f', 'c4', '3c', '26']},
60
- // bech32Hrp: {mainnet: ['bc'], testnet: ['tb']},
61
- // }
58
+ export var SegwitVersion;
59
+ (function (SegwitVersion) {
60
+ SegwitVersion[SegwitVersion["NativeSegwit"] = 0] = "NativeSegwit";
61
+ SegwitVersion[SegwitVersion["TapRoot"] = 1] = "TapRoot";
62
+ })(SegwitVersion || (SegwitVersion = {}));
62
63
  export default (opts) => ({
63
64
  isValidAddress(address) {
64
65
  const addr = getAddress(address);
65
- // const _opts = {...DefaultBTCValidatorOpts, ...opts}
66
66
  return isValidP2PKHandP2SHAddress(addr, opts) || segwit.isValidAddress(addr, opts);
67
67
  }
68
68
  });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../types.js").Validator;
2
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import createSS58Validator from './ss58_validator.js';
2
+ // Bittensor uses SS58 address format (Substrate-based) with network prefix 42
3
+ // Reference: https://docs.learnbittensor.org/evm-tutorials/convert-h160-to-ss58
4
+ // SS58 Registry: https://github.com/paritytech/ss58-registry
5
+ // Network prefix 42 (0x2A in hex) is used by Bittensor
6
+ export default createSS58Validator({ networkPrefix: 42 });
@@ -1,5 +1,6 @@
1
1
  export { default as AlgorandValidator } from "./algorand_validator.js";
2
2
  export { default as BCHValidator } from "./bch_validator.js";
3
+ export { default as BittensorValidator } from "./bittensor_validator.js";
3
4
  export { default as BTCValidator } from "./bitcoin_validator.js";
4
5
  export { default as CardanoValidator } from "./cardano_validator.js";
5
6
  export { default as EOSValidator } from "./eos_validator.js";
@@ -16,3 +17,4 @@ export { default as SolanaValidator } from "./solana_validator.js";
16
17
  export { default as TezosValidator } from "./tezos_validator.js";
17
18
  export { default as TronValidator } from "./tron_validator.js";
18
19
  export { default as XLMValidator } from "./xlm_validator.js";
20
+ export { default as ZcashValidator } from "./zcash_validator.js";
@@ -1,5 +1,6 @@
1
1
  export { default as AlgorandValidator } from "./algorand_validator.js";
2
2
  export { default as BCHValidator } from "./bch_validator.js";
3
+ export { default as BittensorValidator } from "./bittensor_validator.js";
3
4
  export { default as BTCValidator } from "./bitcoin_validator.js";
4
5
  export { default as CardanoValidator } from "./cardano_validator.js";
5
6
  export { default as EOSValidator } from "./eos_validator.js";
@@ -16,3 +17,4 @@ export { default as SolanaValidator } from "./solana_validator.js";
16
17
  export { default as TezosValidator } from "./tezos_validator.js";
17
18
  export { default as TronValidator } from "./tron_validator.js";
18
19
  export { default as XLMValidator } from "./xlm_validator.js";
20
+ export { default as ZcashValidator } from "./zcash_validator.js";
@@ -1,5 +1,2 @@
1
- import { Address } from '../types.js';
2
- declare const _default: {
3
- isValidAddress(address: Address): boolean;
4
- };
1
+ declare const _default: import("../types.js").Validator;
5
2
  export default _default;