multichain-address-validator 0.7.8 → 0.8.0

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 (50) hide show
  1. package/dist/cjs/chain-validators.js +21 -1
  2. package/dist/cjs/crypto/segwit_addr.js +8 -3
  3. package/dist/cjs/index.d.ts +1 -0
  4. package/dist/cjs/index.js +2 -1
  5. package/dist/cjs/validators/bitcoin_validator.d.ts +5 -0
  6. package/dist/cjs/validators/bitcoin_validator.js +6 -5
  7. package/dist/cjs/validators/bittensor_validator.d.ts +2 -0
  8. package/dist/cjs/validators/bittensor_validator.js +11 -0
  9. package/dist/cjs/validators/index.d.ts +2 -0
  10. package/dist/cjs/validators/index.js +5 -1
  11. package/dist/cjs/validators/polkadot_validator.d.ts +1 -4
  12. package/dist/cjs/validators/polkadot_validator.js +5 -49
  13. package/dist/cjs/validators/ss58_validator.d.ts +11 -0
  14. package/dist/cjs/validators/ss58_validator.js +70 -0
  15. package/dist/cjs/validators/zcash_validator.d.ts +5 -0
  16. package/dist/cjs/validators/zcash_validator.js +52 -0
  17. package/dist/esm/chain-validators.js +22 -2
  18. package/dist/esm/crypto/segwit_addr.js +8 -3
  19. package/dist/esm/index.d.ts +1 -0
  20. package/dist/esm/index.js +2 -1
  21. package/dist/esm/validators/bitcoin_validator.d.ts +5 -0
  22. package/dist/esm/validators/bitcoin_validator.js +5 -5
  23. package/dist/esm/validators/bittensor_validator.d.ts +2 -0
  24. package/dist/esm/validators/bittensor_validator.js +6 -0
  25. package/dist/esm/validators/index.d.ts +2 -0
  26. package/dist/esm/validators/index.js +2 -0
  27. package/dist/esm/validators/polkadot_validator.d.ts +1 -4
  28. package/dist/esm/validators/polkadot_validator.js +5 -49
  29. package/dist/esm/validators/ss58_validator.d.ts +11 -0
  30. package/dist/esm/validators/ss58_validator.js +64 -0
  31. package/dist/esm/validators/zcash_validator.d.ts +5 -0
  32. package/dist/esm/validators/zcash_validator.js +47 -0
  33. package/package-lock.json +1705 -0
  34. package/package.json +1 -1
  35. package/src/chain-validators.ts +23 -1
  36. package/src/crypto/segwit_addr.js +9 -3
  37. package/src/index.ts +2 -1
  38. package/src/validators/bitcoin_validator.ts +5 -6
  39. package/src/validators/bittensor_validator.ts +8 -0
  40. package/src/validators/index.ts +2 -0
  41. package/src/validators/polkadot_validator.ts +5 -55
  42. package/src/validators/ss58_validator.ts +80 -0
  43. package/src/validators/zcash_validator.ts +57 -0
  44. package/test/addresses/addresses.ts +4 -0
  45. package/test/addresses/bittensor.json +27 -0
  46. package/test/addresses/btc-testnet.json +1 -0
  47. package/test/addresses/btc.json +5 -1
  48. package/test/addresses/ltc.json +1 -0
  49. package/test/addresses/zcash.json +8 -0
  50. package/test/multichain-address-validator.test.ts +18 -1
@@ -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,
@@ -78,10 +85,12 @@ const chainValidators = {
78
85
  mainnet: (0, index_js_1.BTCValidator)({
79
86
  addressTypes: ['30', '32'],
80
87
  bech32Hrp: ['ltc'],
88
+ allowedSegwitVersions: [bitcoin_validator_1.SegwitVersion.NativeSegwit],
81
89
  }),
82
90
  testnet: (0, index_js_1.BTCValidator)({
83
91
  addressTypes: ['6f', 'c4', '3a'],
84
- bech32Hrp: ['tltc']
92
+ bech32Hrp: ['tltc'],
93
+ allowedSegwitVersions: [bitcoin_validator_1.SegwitVersion.NativeSegwit],
85
94
  })
86
95
  }
87
96
  },
@@ -91,6 +100,10 @@ const chainValidators = {
91
100
  testnet: (0, index_js_1.MoneroValidator)(types_js_1.NetworkType.TestNet),
92
101
  }
93
102
  },
103
+ monad: {
104
+ alternatives: ['mon'],
105
+ validator: index_js_1.ETHValidator,
106
+ },
94
107
  nem: { validator: index_js_1.NemValidator },
95
108
  nano: { validator: index_js_1.NanoValidator },
96
109
  polkadot: { validator: index_js_1.PolkadotValidator },
@@ -116,6 +129,13 @@ const chainValidators = {
116
129
  alternatives: ['stellar', 'stellarlumens'],
117
130
  validator: index_js_1.XLMValidator,
118
131
  },
132
+ zcash: {
133
+ alternatives: ['zec'],
134
+ validator: {
135
+ mainnet: (0, index_js_1.ZcashValidator)(types_js_1.NetworkType.MainNet),
136
+ testnet: (0, index_js_1.ZcashValidator)(types_js_1.NetworkType.TestNet),
137
+ }
138
+ },
119
139
  };
120
140
  function getValidatorForChain(chain) {
121
141
  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;
@@ -5,5 +5,6 @@ export type { Address, Chain };
5
5
  export { NetworkType };
6
6
  declare const _default: {
7
7
  validate: typeof validate;
8
+ validateMemo: typeof validateMemo;
8
9
  };
9
10
  export default _default;
package/dist/cjs/index.js CHANGED
@@ -21,5 +21,6 @@ function validateMemo(memo, chain) {
21
21
  return validator.isValidMemo?.(memo) ?? true;
22
22
  }
23
23
  exports.default = {
24
- validate
24
+ validate,
25
+ validateMemo
25
26
  };
@@ -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,
@@ -75,10 +82,12 @@ const chainValidators = {
75
82
  mainnet: BTCValidator({
76
83
  addressTypes: ['30', '32'],
77
84
  bech32Hrp: ['ltc'],
85
+ allowedSegwitVersions: [SegwitVersion.NativeSegwit],
78
86
  }),
79
87
  testnet: BTCValidator({
80
88
  addressTypes: ['6f', 'c4', '3a'],
81
- bech32Hrp: ['tltc']
89
+ bech32Hrp: ['tltc'],
90
+ allowedSegwitVersions: [SegwitVersion.NativeSegwit],
82
91
  })
83
92
  }
84
93
  },
@@ -88,6 +97,10 @@ const chainValidators = {
88
97
  testnet: MoneroValidator(NetworkType.TestNet),
89
98
  }
90
99
  },
100
+ monad: {
101
+ alternatives: ['mon'],
102
+ validator: ETHValidator,
103
+ },
91
104
  nem: { validator: NemValidator },
92
105
  nano: { validator: NanoValidator },
93
106
  polkadot: { validator: PolkadotValidator },
@@ -113,6 +126,13 @@ const chainValidators = {
113
126
  alternatives: ['stellar', 'stellarlumens'],
114
127
  validator: XLMValidator,
115
128
  },
129
+ zcash: {
130
+ alternatives: ['zec'],
131
+ validator: {
132
+ mainnet: ZcashValidator(NetworkType.MainNet),
133
+ testnet: ZcashValidator(NetworkType.TestNet),
134
+ }
135
+ },
116
136
  };
117
137
  export function getValidatorForChain(chain) {
118
138
  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;
@@ -5,5 +5,6 @@ export type { Address, Chain };
5
5
  export { NetworkType };
6
6
  declare const _default: {
7
7
  validate: typeof validate;
8
+ validateMemo: typeof validateMemo;
8
9
  };
9
10
  export default _default;
package/dist/esm/index.js CHANGED
@@ -16,5 +16,6 @@ export function validateMemo(memo, chain) {
16
16
  }
17
17
  export { NetworkType };
18
18
  export default {
19
- validate
19
+ validate,
20
+ validateMemo
20
21
  };
@@ -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;