validator0x 0.4.0 → 0.4.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 (56) hide show
  1. package/AGENTS.md +4 -1
  2. package/CHANGELOG.md +14 -0
  3. package/README.md +10 -5
  4. package/dist/bitcoin.cjs +1 -1
  5. package/dist/bitcoin.mjs +1 -1
  6. package/dist/cardano.cjs +1 -1
  7. package/dist/cardano.mjs +1 -1
  8. package/dist/cosmos.cjs +1 -1
  9. package/dist/cosmos.mjs +1 -1
  10. package/dist/dogecoin.cjs +1 -1
  11. package/dist/dogecoin.mjs +1 -1
  12. package/dist/ethereum.cjs +1 -1
  13. package/dist/ethereum.mjs +1 -1
  14. package/dist/evm.cjs +1 -1
  15. package/dist/evm.mjs +1 -1
  16. package/dist/formatters.cjs +1 -1
  17. package/dist/formatters.mjs +1 -1
  18. package/dist/index.cjs +1 -1
  19. package/dist/index.d.cts +0 -2
  20. package/dist/index.d.mts +0 -2
  21. package/dist/index.mjs +1 -1
  22. package/dist/index.umd.js +1 -1
  23. package/dist/litecoin.cjs +1 -1
  24. package/dist/litecoin.mjs +1 -1
  25. package/dist/move.cjs +1 -1
  26. package/dist/move.mjs +1 -1
  27. package/dist/near.cjs +1 -1
  28. package/dist/near.mjs +1 -1
  29. package/dist/ripple.cjs +1 -1
  30. package/dist/ripple.mjs +1 -1
  31. package/dist/shared/base-3sYui6r0.cjs +1 -0
  32. package/dist/shared/base-CZZTeLCP.mjs +1 -0
  33. package/dist/shared/base58-DV6hu8Kq.cjs +1 -0
  34. package/dist/shared/base58-DY9-Un67.mjs +1 -0
  35. package/dist/shared/base58check-BeCwnkGe.cjs +1 -0
  36. package/dist/shared/base58check-rMkz2cjy.mjs +1 -0
  37. package/dist/shared/bech32-Cu41-5bd.mjs +1 -0
  38. package/dist/shared/bech32-Dk6Pnay4.cjs +1 -0
  39. package/dist/shared/{utxo-CRr3-5en.mjs → utxo-BrSxcH2x.mjs} +1 -1
  40. package/dist/shared/utxo-DF5Lt3lY.cjs +1 -0
  41. package/dist/solana.cjs +1 -1
  42. package/dist/solana.mjs +1 -1
  43. package/dist/tron.cjs +1 -1
  44. package/dist/tron.mjs +1 -1
  45. package/package.json +1 -1
  46. package/dist/shared/base-BtbJMDNm.cjs +0 -1
  47. package/dist/shared/base-D2s8b6tx.mjs +0 -1
  48. package/dist/shared/base58-CjvbdRzA.mjs +0 -1
  49. package/dist/shared/base58-DaLDoaS-.cjs +0 -1
  50. package/dist/shared/base58check-BBzwHAsr.mjs +0 -1
  51. package/dist/shared/base58check-CE9wLmUB.cjs +0 -1
  52. package/dist/shared/bech32-ClvuyXIQ.cjs +0 -1
  53. package/dist/shared/bech32-DsNhxmrB.mjs +0 -1
  54. package/dist/shared/sha256-BbwKo1_x.mjs +0 -1
  55. package/dist/shared/sha256-CRbh7pIK.cjs +0 -1
  56. package/dist/shared/utxo-DhlBlYDy.cjs +0 -1
package/AGENTS.md CHANGED
@@ -10,7 +10,7 @@ This file serves two audiences: agents integrating the installed npm package, an
10
10
  4. Pass untrusted addresses directly to `validateAddress`. It accepts `unknown` and returns `ValidationResult`. Check `result.valid` before using an address. For rejected input, use `result.error` and `result.details?.errorCode`, not string comparisons with implementation-specific messages.
11
11
  5. Validation trims outer ASCII spaces but does not return a normalized address. After successful validation of a string, use `input.trim()` for subsequent operations. Do not lowercase Base58 addresses or silently repair checksums, Unicode, missing characters, or invalid input.
12
12
  6. `strict: true` requires exact EIP-55 capitalization for EVM addresses, and canonical lowercase AIP-40 representation for Aptos. Mixed-case EVM checksums and mandatory Base58Check/Bech32 checksums are always checked. Choose strict mode deliberately; do not enable it blindly for existing lowercase EVM input flows.
13
- 7. `network: 'mainnet' | 'testnet' | 'auto'` and `allowTestnet` only filter networks encoded in an address. EVM, Solana, TRON, Cosmos, Sui, Aptos, and NEAR cannot establish mainnet/testnet from address syntax. An absent `details.network` means unknown, not mainnet.
13
+ 7. `network: 'mainnet' | 'testnet' | 'auto'` and `allowTestnet` only filter networks encoded in an address. Any other `network` value throws a `RangeError` before input is read, including for an empty batch or empty detection input. EVM, Solana, TRON, Cosmos, Sui, Aptos, and NEAR cannot establish mainnet/testnet from address syntax. An absent `details.network` means unknown, not mainnet.
14
14
  8. `detectBlockchain` returns a chain, an array of format candidates, or `null`. Never pick the first candidate automatically for a payment. EVM chains, Sui/Aptos, and some UTXO/NEAR formats overlap. Plain NEAR names are deliberately excluded from detection.
15
15
  9. Validation does not prove ownership, account existence, spendability, token compatibility, or recipient safety. Handle application-specific destination tags, memos, RPC checks, and asset/network selection separately. `allowBurnAddress` only controls the EVM all-zero address.
16
16
  10. Formatting is display logic. `shortenAddress` output must never become a transaction destination. `formatAddress` does not generally validate input; EVM checksum formatting and Aptos formatting can throw on malformed input. Validate first.
@@ -31,6 +31,9 @@ export function checkRecipient(input: unknown, chain: unknown) {
31
31
  return { ok: false as const, error: result.error ?? 'Invalid address' };
32
32
  }
33
33
  // The application must separately verify the selected asset and actual network.
34
+ if (chain === 'bitcoin' && result.details?.format === 'anchor') {
35
+ return { ok: false as const, error: 'Choose a Bitcoin payment address. Anyone can spend a fee anchor.' };
36
+ }
34
37
  if (chain === 'cardano' && result.details?.format === 'stake') {
35
38
  return { ok: false as const, error: 'Choose a Cardano payment address' };
36
39
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.1 - 2026-11-26
4
+
5
+ - Cardano Byron validation rejects noncanonical CBOR encodings of the address type, network magic, and encrypted path length.
6
+ - Cardano Byron validation accepts variable-length encrypted derivation paths, including the 32-byte paths in the ledger fixtures.
7
+ - Bitcoin BIP-433 fee anchors return `details.format === 'anchor'`. Both payment examples reject them as recipients.
8
+ - An unsupported `network` option value throws a `RangeError` from validation, batch validation, detection, and validator `validate` methods, before any input is read. Previously it reported `NETWORK_MISMATCH` for addresses that encode a network and was ignored for other chains. `undefined` and `null` still mean `auto`.
9
+ - Invalid network values are rejected without calling their conversion hooks. Unsafe address inputs return structured errors without creating an exception for each row.
10
+ - Arrays passed to `validateBatch` produce one result per original index, even with a custom iterator or inherited values at missing indices.
11
+ - Aptos accepts uppercase hex letters in short special addresses by default, including `0xF`. Strict mode requires the lowercase AIP-40 form. EVM validators report malformed repeated prefixes consistently and skip hashing digit-only addresses.
12
+ - Chain detection validates the shared EVM format once and preserves the full ordered candidate list. Cosmos validators reject mismatched prefixes before decoding the payload.
13
+ - Bitcoin-family and XRP addresses share the Base58 decoder and checksum logic. Bech32 and Bech32m use one checksum pass, reject non-ASCII input, and decode padding into a preallocated byte array. Cardano pointer parsing enforces each field's bounds during decoding.
14
+ - Keccak-256 uses 32-bit operations. SHA-256 and Base58Check reduce intermediate allocations. The package keeps zero runtime dependencies.
15
+ - Expanded regression and independent reference tests cover address mutations, checksum error codes, padding, pointer boundaries, Cosmos account formats, and ambiguous detection. Packed-consumer tests verify named exports, type identity, browser globals, and both documented payment examples. The benchmark now exercises sparse batches.
16
+
3
17
  ## 0.4.0
4
18
 
5
19
  - JavaScript EVM and Cosmos constructors reject unsupported family identifiers.
package/README.md CHANGED
@@ -54,6 +54,9 @@ export function checkRecipient(address: unknown, chain: unknown) {
54
54
  if (!result.valid || typeof address !== 'string') {
55
55
  return { ok: false as const, error: result.error ?? 'Invalid address' };
56
56
  }
57
+ if (chain === 'bitcoin' && result.details?.format === 'anchor') {
58
+ return { ok: false as const, error: 'Choose a Bitcoin payment address. Anyone can spend a fee anchor.' };
59
+ }
57
60
  if (chain === 'cardano' && result.details?.format === 'stake') {
58
61
  return { ok: false as const, error: 'Choose a Cardano payment address' };
59
62
  }
@@ -69,7 +72,7 @@ The validator trims outer ASCII spaces internally; use the trimmed string after
69
72
  | Public API | Result and behavior |
70
73
  | --- | --- |
71
74
  | `validateAddress(input, chain, options?)` | `ValidationResult`; invalid addresses return `valid: false` |
72
- | `validateBatch(inputs, chain, options?)` | Results in input order; accepts a readonly array |
75
+ | `validateBatch(inputs, chain, options?)` | One result per original array index, in order. Missing rows receive an invalid result. Accepts a readonly array. |
73
76
  | `isSupportedChain(value)` | Boolean and TypeScript type guard for unknown chain input |
74
77
  | `SUPPORTED_CHAINS` | Frozen list of supported identifiers; useful for a chain selector |
75
78
  | `detectBlockchain(input, options?)` | One chain, candidate array, or `null`; never proof of chain ownership |
@@ -127,19 +130,21 @@ The full minified ESM bundle is approximately **7.2 kB gzip**, and the Solana-on
127
130
  | --- | --- |
128
131
  | `ethereum`, `polygon`, `bsc`, `avalanche`, `arbitrum`, `optimism`, `base` | Ethereum 20-byte hexadecimal addresses; EIP-55 checksum |
129
132
  | `evm`, `fantom`, `sonic`, `gnosis`, `celo`, `cronos`, `moonbeam`, `moonriver`, `zksync`, `linea`, `scroll`, `mantle`, `blast`, `opbnb`, `zora`, `worldchain` | Same Ethereum/EIP-55 address rules |
130
- | `bitcoin` | Base58Check P2PKH/P2SH; SegWit v0; Bech32m v1-16, including Taproot; mainnet and testnet |
133
+ | `bitcoin` | Base58Check P2PKH/P2SH; SegWit v0; Bech32m v1-16, including Taproot and [BIP-433 fee anchors](https://github.com/bitcoin/bips/blob/master/bip-0433.mediawiki); mainnet and testnet |
131
134
  | `litecoin` | Base58Check P2PKH/P2SH (including legacy shared P2SH prefixes); standard witness v0-16; mainnet and testnet |
132
135
  | `dogecoin` | Base58Check P2PKH/P2SH; mainnet and testnet |
133
136
  | `solana` | Base58 decoding to exactly 32 bytes, including program addresses and PDAs |
134
- | `cardano` | Shelley base, enterprise, pointer, and stake addresses; header/network/length/padding checks; Byron CBOR envelope and CRC32 |
137
+ | `cardano` | Shelley base, enterprise, pointer, and stake addresses; header/network/length/padding checks; Byron CBOR envelopes with a 28-byte root, optional variable-length encrypted derivation path, and CRC32 |
135
138
  | `ripple` | XRP classic account addresses with the XRP Base58 alphabet and checksum |
136
139
  | `tron` | 34-character Base58Check or 42-character hex beginning with `41` |
137
140
  | `cosmos`, `osmosis`, `sei` | Bech32 account prefixes `cosmos`, `osmo`, `sei`; 20- or 32-byte payloads |
138
141
  | `celestia`, `injective` | Bech32 account prefixes `celestia`, `inj`; 20-byte payloads |
139
142
  | `sui` | `0x` followed by exactly 64 hex digits |
140
- | `aptos` | Full 32-byte hexadecimal addresses or special addresses `0x0` through `0xf`; strict canonical AIP-40 mode |
143
+ | `aptos` | Full 32-byte hexadecimal addresses or single-digit special addresses, each with a lowercase `0x` prefix. Default mode accepts either hex letter case. Strict mode requires the canonical AIP-40 spelling. |
141
144
  | `near` | 2-64 character account IDs with lowercase letters, numbers, and valid separators; named, implicit, Ethereum-like, deterministic, and universal forms |
142
145
 
146
+ For Cardano Byron addresses, the address type, network magic, and length of the encrypted path use the shortest CBOR encoding. Validation checks these fields even when the CRC32 matches.
147
+
143
148
  `avalanche` covers C-Chain addresses. For additional chains using standard Ethereum addresses, use `evm`; chain-specific checksum schemes such as EIP-1191 are outside its scope. For Sei's EVM format, use `evm`; `sei` validates its Bech32 format.
144
149
 
145
150
  Not supported: Bitcoin/Litecoin regtest HRPs, Litecoin MWEB, XRP X-addresses/destination tags, Cardano addresses longer than 256 characters, Cosmos validator/consensus prefixes, ENS or other name-service resolution. A syntactically valid future witness address is not necessarily spendable under today's consensus rules. Cardano pointer addresses are recognized for compatibility; this does not assert they can be newly created on mainnet. Solana validation does not test curve membership.
@@ -156,7 +161,7 @@ validateAddress(address, chain, {
156
161
  ```
157
162
 
158
163
  - `strict` defaults to `false`. On EVM, `true` requires the exact EIP-55 capitalization, including the rare valid all-lowercase/all-uppercase checksums. Invalid mixed-case EVM checksums are always rejected. On Aptos, strict mode requires lowercase AIP-40 canonical representation. Other formats always verify their mandatory checksums.
159
- - `network` defaults to `auto`. It filters networks **only when encoded in the address**, currently Bitcoin, Litecoin, Dogecoin, and Cardano. `details.network` is omitted for formats that cannot identify mainnet/testnet. Selecting a network never proves an address belongs to it.
164
+ - `network` defaults to `auto` (`undefined` and `null` also mean `auto`). Any other value than `'mainnet'`, `'testnet'`, or `'auto'` throws a `RangeError` from `validateAddress`, `validateBatch`, `detectBlockchain`, and validator `validate` methods. The option is checked before any input is read, so an empty batch or empty, blank, or unsafe input still throws. It filters networks **only when encoded in the address**, currently Bitcoin, Litecoin, Dogecoin, and Cardano. `details.network` is omitted for formats that cannot identify mainnet/testnet. Selecting a network never proves an address belongs to it.
160
165
  - `allowTestnet: false` rejects identifiable testnet addresses, including when `network: 'testnet'` is also supplied. It is not an on-chain network check.
161
166
  - `allowBurnAddress` defaults to `false` and controls only the EVM all-zero address. It is not a comprehensive burn-address database. Other reserved/program addresses may be syntactically valid.
162
167
 
package/dist/bitcoin.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("./shared/utxo-DhlBlYDy.cjs");require("./shared/base-BtbJMDNm.cjs"),require("./shared/base58check-CE9wLmUB.cjs"),require("./shared/base58-DaLDoaS-.cjs"),require("./shared/sha256-CRbh7pIK.cjs"),require("./shared/bech32-ClvuyXIQ.cjs");class s extends e.UtxoValidator{constructor(){super({chain:"bitcoin",versions:{0:"mainnet",5:"mainnet",111:"testnet",196:"testnet"},hrps:{bc:"mainnet",tb:"testnet"}})}}exports.BitcoinValidator=s;
1
+ "use strict";var e=require("./shared/utxo-DF5Lt3lY.cjs");require("./shared/base-3sYui6r0.cjs"),require("./shared/base58check-BeCwnkGe.cjs"),require("./shared/base58-DV6hu8Kq.cjs"),require("./shared/bech32-Dk6Pnay4.cjs");class s extends e.UtxoValidator{constructor(){super({chain:"bitcoin",versions:{0:"mainnet",5:"mainnet",111:"testnet",196:"testnet"},hrps:{bc:"mainnet",tb:"testnet"}})}}exports.BitcoinValidator=s;
package/dist/bitcoin.mjs CHANGED
@@ -1 +1 @@
1
- import{U as s}from"./shared/utxo-CRr3-5en.mjs";import"./shared/base-D2s8b6tx.mjs";import"./shared/base58check-BBzwHAsr.mjs";import"./shared/base58-CjvbdRzA.mjs";import"./shared/sha256-BbwKo1_x.mjs";import"./shared/bech32-DsNhxmrB.mjs";class e extends s{constructor(){super({chain:"bitcoin",versions:{0:"mainnet",5:"mainnet",111:"testnet",196:"testnet"},hrps:{bc:"mainnet",tb:"testnet"}})}}export{e as BitcoinValidator};
1
+ import{U as s}from"./shared/utxo-BrSxcH2x.mjs";import"./shared/base-CZZTeLCP.mjs";import"./shared/base58check-rMkz2cjy.mjs";import"./shared/base58-DY9-Un67.mjs";import"./shared/bech32-Cu41-5bd.mjs";class e extends s{constructor(){super({chain:"bitcoin",versions:{0:"mainnet",5:"mainnet",111:"testnet",196:"testnet"},hrps:{bc:"mainnet",tb:"testnet"}})}}export{e as BitcoinValidator};
package/dist/cardano.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t=require("./shared/base-BtbJMDNm.cjs"),e=require("./shared/base58-DaLDoaS-.cjs"),r=require("./shared/bech32-ClvuyXIQ.cjs");class n{constructor(t){this.data=t,this.offset=0}head(t){if(this.offset>=this.data.length)throw new Error("Truncated CBOR");const e=this.data[this.offset++];if(e>>>5!==t)throw new Error("Invalid CBOR type");const r=31&e;if(r<24)return r;if(r>26)throw new Error("Unsupported CBOR length");const n=1<<r-24;if(this.offset+n>this.data.length)throw new Error("Truncated CBOR");let s=0;for(let t=0;t<n;t++)s=256*s+this.data[this.offset++];return s}bytes(){const t=this.head(2);if(this.offset+t>this.data.length)throw new Error("Truncated bytes");const e=this.data.slice(this.offset,this.offset+t);return this.offset+=t,e}end(){if(this.offset!==this.data.length)throw new Error("Trailing CBOR data")}}class s extends t.AddressValidator{validateImplementation(t){if(/^(addr|stake)(_test)?1/i.test(t))return this.validateShelley(t);try{const r=function(t){try{const e=new n(t);if(2!==e.head(4)||24!==e.head(6))return null;const r=e.bytes();if(e.head(0)!==function(t){let e=4294967295;for(const r of t){e^=r;for(let t=0;t<8;t++)e=e>>>1^(1&e?3988292384:0)}return(4294967295^e)>>>0}(r))return null;e.end();const s=new n(r);if(3!==s.head(4)||28!==s.bytes().length)return null;const a=s.head(5);if(a>r.length)return null;const i=new Set;let o="mainnet";for(let t=0;t<a;t++){const t=s.head(0);if(i.has(t)||t>255)return null;i.add(t);const e=s.bytes();if(1===t){const t=new n(e);if(28!==t.bytes().length)return null;t.end()}if(2===t){const t=new n(e);t.head(0),t.end(),o="testnet"}}const d=s.head(0);return 0!==d&&2!==d?null:(s.end(),o)}catch{return null}}(e.decodeBase58(t));if(r)return{valid:!0,blockchain:"cardano",details:{format:"byron",network:r,checksum:!0}}}catch{}return this.invalid()}validateShelley(t){const e=r.decodeBech32(t,256),n=e&&r.wordsToBytes(e.data);if(!e||e.encoding!==r.Bech32Encoding.BECH32||!n?.length)return this.invalid();const s=n[0]>>>4,a=15&n[0];if(0!==a&&1!==a)return this.invalid();const i=14===s||15===s,o=(i?"stake":"addr")+(0===a?"_test":"");if(e.hrp!==o)return this.invalid();let d=!1;return s<=3?d=57===n.length:6===s||7===s||i?d=29===n.length:4!==s&&5!==s||(d=this.validPointer(n)),d?{valid:!0,blockchain:"cardano",details:{format:i?"stake":"shelley",network:1===a?"mainnet":"testnet",checksum:!0}}:this.invalid()}validPointer(t){let e=29;for(let r=0;r<3;r++){let n=0n;const s=e;do{if(e>=t.length||e-s>=10)return!1;n=n<<7n|BigInt(127&t[e])}while(128&t[e++]);if(e-s>1&&128===t[s]||n>(0===r?0xffffffffn:0xffffn))return!1}return e===t.length}invalid(){return{valid:!1,error:"Invalid Cardano address structure, network, or checksum",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}format(e,r){return t.formatPlainAddress(e,r,8)}}exports.CardanoValidator=s;
1
+ "use strict";var t=require("./shared/base-3sYui6r0.cjs"),e=require("./shared/base58-DV6hu8Kq.cjs"),r=require("./shared/bech32-Dk6Pnay4.cjs");const n=[24,256,65536];class s{constructor(t){this.data=t,this.offset=0}head(t,e=!1){if(this.offset>=this.data.length)throw new Error("Truncated CBOR");const r=this.data[this.offset++];if(r>>>5!==t)throw new Error("Invalid CBOR type");const s=31&r;if(s<24)return s;if(s>26)throw new Error("Unsupported CBOR length");const a=1<<s-24;if(this.offset+a>this.data.length)throw new Error("Truncated CBOR");let i=0;for(let t=0;t<a;t++)i=256*i+this.data[this.offset++];if(e&&i<n[s-24])throw new Error("Noncanonical CBOR argument");return i}bytes(t=!1){const e=this.head(2,t);if(this.offset+e>this.data.length)throw new Error("Truncated bytes");const r=this.data.slice(this.offset,this.offset+e);return this.offset+=e,r}end(){if(this.offset!==this.data.length)throw new Error("Trailing CBOR data")}}const a=[4294967295,65535,65535];class i extends t.AddressValidator{validateImplementation(t){if(/^(addr|stake)(_test)?1/i.test(t))return this.validateShelley(t);try{const r=function(t){try{const e=new s(t);if(2!==e.head(4)||24!==e.head(6))return null;const r=e.bytes();if(e.head(0)!==function(t){let e=4294967295;for(const r of t){e^=r;for(let t=0;t<8;t++)e=e>>>1^(1&e?3988292384:0)}return(4294967295^e)>>>0}(r))return null;e.end();const n=new s(r);if(3!==n.head(4)||28!==n.bytes().length)return null;const a=n.head(5);if(a>r.length)return null;const i=new Set;let o="mainnet";for(let t=0;t<a;t++){const t=n.head(0);if(i.has(t)||t>255)return null;i.add(t);const e=n.bytes();if(1===t){const t=new s(e);t.bytes(!0),t.end()}if(2===t){const t=new s(e);t.head(0,!0),t.end(),o="testnet"}}const d=n.head(0,!0);return 0!==d&&2!==d?null:(n.end(),o)}catch{return null}}(e.decodeBase58(t));if(r)return{valid:!0,blockchain:"cardano",details:{format:"byron",network:r,checksum:!0}}}catch{}return this.invalid()}validateShelley(t){const e=r.decodeBech32(t,256),n=e&&r.wordsToBytes(e.data);if(!e||e.encoding!==r.Bech32Encoding.BECH32||!n?.length)return this.invalid();const s=n[0]>>>4,a=15&n[0];if(0!==a&&1!==a)return this.invalid();const i=14===s||15===s,o=(i?"stake":"addr")+(0===a?"_test":"");if(e.hrp!==o)return this.invalid();let d=!1;return s<=3?d=57===n.length:6===s||7===s||i?d=29===n.length:4!==s&&5!==s||(d=this.validPointer(n)),d?{valid:!0,blockchain:"cardano",details:{format:i?"stake":"shelley",network:1===a?"mainnet":"testnet",checksum:!0}}:this.invalid()}validPointer(t){let e=29;for(const r of a){if(128===t[e])return!1;let n,s=0;do{if(e>=t.length)return!1;if(n=t[e++],s=128*s+(127&n),s>r)return!1}while(128&n)}return e===t.length}invalid(){return{valid:!1,error:"Invalid Cardano address structure, network, or checksum",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}format(e,r){return t.formatPlainAddress(e,r,8)}}exports.CardanoValidator=i;
package/dist/cardano.mjs CHANGED
@@ -1 +1 @@
1
- import{A as t,V as e,f as n}from"./shared/base-D2s8b6tx.mjs";import{d as r}from"./shared/base58-CjvbdRzA.mjs";import{d as s,w as a,B as i}from"./shared/bech32-DsNhxmrB.mjs";class o{constructor(t){this.data=t,this.offset=0}head(t){if(this.offset>=this.data.length)throw new Error("Truncated CBOR");const e=this.data[this.offset++];if(e>>>5!==t)throw new Error("Invalid CBOR type");const n=31&e;if(n<24)return n;if(n>26)throw new Error("Unsupported CBOR length");const r=1<<n-24;if(this.offset+r>this.data.length)throw new Error("Truncated CBOR");let s=0;for(let t=0;t<r;t++)s=256*s+this.data[this.offset++];return s}bytes(){const t=this.head(2);if(this.offset+t>this.data.length)throw new Error("Truncated bytes");const e=this.data.slice(this.offset,this.offset+t);return this.offset+=t,e}end(){if(this.offset!==this.data.length)throw new Error("Trailing CBOR data")}}class h extends t{validateImplementation(t){if(/^(addr|stake)(_test)?1/i.test(t))return this.validateShelley(t);try{const e=function(t){try{const e=new o(t);if(2!==e.head(4)||24!==e.head(6))return null;const n=e.bytes();if(e.head(0)!==function(t){let e=4294967295;for(const n of t){e^=n;for(let t=0;t<8;t++)e=e>>>1^(1&e?3988292384:0)}return(4294967295^e)>>>0}(n))return null;e.end();const r=new o(n);if(3!==r.head(4)||28!==r.bytes().length)return null;const s=r.head(5);if(s>n.length)return null;const a=new Set;let i="mainnet";for(let t=0;t<s;t++){const t=r.head(0);if(a.has(t)||t>255)return null;a.add(t);const e=r.bytes();if(1===t){const t=new o(e);if(28!==t.bytes().length)return null;t.end()}if(2===t){const t=new o(e);t.head(0),t.end(),i="testnet"}}const h=r.head(0);return 0!==h&&2!==h?null:(r.end(),i)}catch{return null}}(r(t));if(e)return{valid:!0,blockchain:"cardano",details:{format:"byron",network:e,checksum:!0}}}catch{}return this.invalid()}validateShelley(t){const e=s(t,256),n=e&&a(e.data);if(!e||e.encoding!==i.BECH32||!n?.length)return this.invalid();const r=n[0]>>>4,o=15&n[0];if(0!==o&&1!==o)return this.invalid();const h=14===r||15===r,l=(h?"stake":"addr")+(0===o?"_test":"");if(e.hrp!==l)return this.invalid();let f=!1;return r<=3?f=57===n.length:6===r||7===r||h?f=29===n.length:4!==r&&5!==r||(f=this.validPointer(n)),f?{valid:!0,blockchain:"cardano",details:{format:h?"stake":"shelley",network:1===o?"mainnet":"testnet",checksum:!0}}:this.invalid()}validPointer(t){let e=29;for(let n=0;n<3;n++){let r=0n;const s=e;do{if(e>=t.length||e-s>=10)return!1;r=r<<7n|BigInt(127&t[e])}while(128&t[e++]);if(e-s>1&&128===t[s]||r>(0===n?0xffffffffn:0xffffn))return!1}return e===t.length}invalid(){return{valid:!1,error:"Invalid Cardano address structure, network, or checksum",details:{errorCode:e.INVALID_FORMAT}}}format(t,e){return n(t,e,8)}}export{h as CardanoValidator};
1
+ import{A as t,V as e,f as n}from"./shared/base-CZZTeLCP.mjs";import{d as r}from"./shared/base58-DY9-Un67.mjs";import{d as s,w as a,B as i}from"./shared/bech32-Cu41-5bd.mjs";const o=[24,256,65536];class h{constructor(t){this.data=t,this.offset=0}head(t,e=!1){if(this.offset>=this.data.length)throw new Error("Truncated CBOR");const n=this.data[this.offset++];if(n>>>5!==t)throw new Error("Invalid CBOR type");const r=31&n;if(r<24)return r;if(r>26)throw new Error("Unsupported CBOR length");const s=1<<r-24;if(this.offset+s>this.data.length)throw new Error("Truncated CBOR");let a=0;for(let t=0;t<s;t++)a=256*a+this.data[this.offset++];if(e&&a<o[r-24])throw new Error("Noncanonical CBOR argument");return a}bytes(t=!1){const e=this.head(2,t);if(this.offset+e>this.data.length)throw new Error("Truncated bytes");const n=this.data.slice(this.offset,this.offset+e);return this.offset+=e,n}end(){if(this.offset!==this.data.length)throw new Error("Trailing CBOR data")}}const l=[4294967295,65535,65535];class d extends t{validateImplementation(t){if(/^(addr|stake)(_test)?1/i.test(t))return this.validateShelley(t);try{const e=function(t){try{const e=new h(t);if(2!==e.head(4)||24!==e.head(6))return null;const n=e.bytes();if(e.head(0)!==function(t){let e=4294967295;for(const n of t){e^=n;for(let t=0;t<8;t++)e=e>>>1^(1&e?3988292384:0)}return(4294967295^e)>>>0}(n))return null;e.end();const r=new h(n);if(3!==r.head(4)||28!==r.bytes().length)return null;const s=r.head(5);if(s>n.length)return null;const a=new Set;let i="mainnet";for(let t=0;t<s;t++){const t=r.head(0);if(a.has(t)||t>255)return null;a.add(t);const e=r.bytes();if(1===t){const t=new h(e);t.bytes(!0),t.end()}if(2===t){const t=new h(e);t.head(0,!0),t.end(),i="testnet"}}const o=r.head(0,!0);return 0!==o&&2!==o?null:(r.end(),i)}catch{return null}}(r(t));if(e)return{valid:!0,blockchain:"cardano",details:{format:"byron",network:e,checksum:!0}}}catch{}return this.invalid()}validateShelley(t){const e=s(t,256),n=e&&a(e.data);if(!e||e.encoding!==i.BECH32||!n?.length)return this.invalid();const r=n[0]>>>4,o=15&n[0];if(0!==o&&1!==o)return this.invalid();const h=14===r||15===r,l=(h?"stake":"addr")+(0===o?"_test":"");if(e.hrp!==l)return this.invalid();let d=!1;return r<=3?d=57===n.length:6===r||7===r||h?d=29===n.length:4!==r&&5!==r||(d=this.validPointer(n)),d?{valid:!0,blockchain:"cardano",details:{format:h?"stake":"shelley",network:1===o?"mainnet":"testnet",checksum:!0}}:this.invalid()}validPointer(t){let e=29;for(const n of l){if(128===t[e])return!1;let r,s=0;do{if(e>=t.length)return!1;if(r=t[e++],s=128*s+(127&r),s>n)return!1}while(128&r)}return e===t.length}invalid(){return{valid:!1,error:"Invalid Cardano address structure, network, or checksum",details:{errorCode:e.INVALID_FORMAT}}}format(t,e){return n(t,e,8)}}export{d as CardanoValidator};
package/dist/cosmos.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("./shared/base-BtbJMDNm.cjs"),s=require("./shared/bech32-ClvuyXIQ.cjs");const i={cosmos:"cosmos",osmosis:"osmo",celestia:"celestia",injective:"inj",sei:"sei"};class c extends e.AddressValidator{constructor(s="cosmos"){if(super(),this.chain=s,!e.COSMOS_CHAINS.includes(s))throw new RangeError(`Unsupported Cosmos chain: ${String(s)}`)}validateImplementation(c){const o=s.decodeBech32(c),r=o&&s.wordsToBytes(o.data),t="injective"===this.chain||"celestia"===this.chain?[20]:[20,32];return o&&o.hrp===i[this.chain]&&o.encoding===s.Bech32Encoding.BECH32&&r&&t.includes(r.length)?{valid:!0,blockchain:this.chain,details:{format:"bech32",checksum:!0}}:{valid:!1,error:"Invalid account prefix, checksum, length, or padding",details:{errorCode:e.ValidationError.INVALID_FORMAT}}}}exports.CosmosValidator=c;
1
+ "use strict";var e=require("./shared/base-3sYui6r0.cjs"),s=require("./shared/bech32-Dk6Pnay4.cjs");const i={cosmos:"cosmos",osmosis:"osmo",celestia:"celestia",injective:"inj",sei:"sei"};class o extends e.AddressValidator{constructor(s="cosmos"){if(super(),this.chain=s,!e.COSMOS_CHAINS.includes(s))throw new RangeError(`Unsupported Cosmos chain: ${String(s)}`)}validateImplementation(o){const c=s.decodeBech32(o,90,i[this.chain]);if(c?.encoding===s.Bech32Encoding.BECH32){const e=s.wordsToBytes(c.data)?.length;if(20===e||32===e&&"injective"!==this.chain&&"celestia"!==this.chain)return{valid:!0,blockchain:this.chain,details:{format:"bech32",checksum:!0}}}return{valid:!1,error:"Invalid account prefix, checksum, length, or padding",details:{errorCode:e.ValidationError.INVALID_FORMAT}}}}exports.CosmosValidator=o;
package/dist/cosmos.mjs CHANGED
@@ -1 +1 @@
1
- import{A as s,C as e,V as i}from"./shared/base-D2s8b6tx.mjs";import{d as a,w as o,B as c}from"./shared/bech32-DsNhxmrB.mjs";const t={cosmos:"cosmos",osmosis:"osmo",celestia:"celestia",injective:"inj",sei:"sei"};class n extends s{constructor(s="cosmos"){if(super(),this.chain=s,!e.includes(s))throw new RangeError(`Unsupported Cosmos chain: ${String(s)}`)}validateImplementation(s){const e=a(s),n=e&&o(e.data),r="injective"===this.chain||"celestia"===this.chain?[20]:[20,32];return e&&e.hrp===t[this.chain]&&e.encoding===c.BECH32&&n&&r.includes(n.length)?{valid:!0,blockchain:this.chain,details:{format:"bech32",checksum:!0}}:{valid:!1,error:"Invalid account prefix, checksum, length, or padding",details:{errorCode:i.INVALID_FORMAT}}}}export{n as CosmosValidator};
1
+ import{A as s,C as e,V as i}from"./shared/base-CZZTeLCP.mjs";import{d as a,B as o,w as t}from"./shared/bech32-Cu41-5bd.mjs";const c={cosmos:"cosmos",osmosis:"osmo",celestia:"celestia",injective:"inj",sei:"sei"};class n extends s{constructor(s="cosmos"){if(super(),this.chain=s,!e.includes(s))throw new RangeError(`Unsupported Cosmos chain: ${String(s)}`)}validateImplementation(s){const e=a(s,90,c[this.chain]);if(e?.encoding===o.BECH32){const s=t(e.data)?.length;if(20===s||32===s&&"injective"!==this.chain&&"celestia"!==this.chain)return{valid:!0,blockchain:this.chain,details:{format:"bech32",checksum:!0}}}return{valid:!1,error:"Invalid account prefix, checksum, length, or padding",details:{errorCode:i.INVALID_FORMAT}}}}export{n as CosmosValidator};
package/dist/dogecoin.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("./shared/utxo-DhlBlYDy.cjs");require("./shared/base-BtbJMDNm.cjs"),require("./shared/base58check-CE9wLmUB.cjs"),require("./shared/base58-DaLDoaS-.cjs"),require("./shared/sha256-CRbh7pIK.cjs"),require("./shared/bech32-ClvuyXIQ.cjs");class s extends e.UtxoValidator{constructor(){super({chain:"dogecoin",versions:{30:"mainnet",22:"mainnet",113:"testnet",196:"testnet"}})}}exports.DogecoinValidator=s;
1
+ "use strict";var e=require("./shared/utxo-DF5Lt3lY.cjs");require("./shared/base-3sYui6r0.cjs"),require("./shared/base58check-BeCwnkGe.cjs"),require("./shared/base58-DV6hu8Kq.cjs"),require("./shared/bech32-Dk6Pnay4.cjs");class s extends e.UtxoValidator{constructor(){super({chain:"dogecoin",versions:{30:"mainnet",22:"mainnet",113:"testnet",196:"testnet"}})}}exports.DogecoinValidator=s;
package/dist/dogecoin.mjs CHANGED
@@ -1 +1 @@
1
- import{U as s}from"./shared/utxo-CRr3-5en.mjs";import"./shared/base-D2s8b6tx.mjs";import"./shared/base58check-BBzwHAsr.mjs";import"./shared/base58-CjvbdRzA.mjs";import"./shared/sha256-BbwKo1_x.mjs";import"./shared/bech32-DsNhxmrB.mjs";class e extends s{constructor(){super({chain:"dogecoin",versions:{30:"mainnet",22:"mainnet",113:"testnet",196:"testnet"}})}}export{e as DogecoinValidator};
1
+ import{U as s}from"./shared/utxo-BrSxcH2x.mjs";import"./shared/base-CZZTeLCP.mjs";import"./shared/base58check-rMkz2cjy.mjs";import"./shared/base58-DY9-Un67.mjs";import"./shared/bech32-Cu41-5bd.mjs";class e extends s{constructor(){super({chain:"dogecoin",versions:{30:"mainnet",22:"mainnet",113:"testnet",196:"testnet"}})}}export{e as DogecoinValidator};
package/dist/ethereum.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var r=require("./shared/base-BtbJMDNm.cjs");function t(r){return r.startsWith("0x")?r.slice(2):r}function e(r){return r.startsWith("0x")?r:`0x${r}`}const n=(1n<<64n)-1n,o=[0,1,62,28,27,36,44,6,55,20,3,10,43,25,39,41,45,15,21,8,18,2,61,56,14],s=[0x0000000000000001n,0x0000000000008082n,0x800000000000808an,0x8000000080008000n,0x000000000000808bn,0x0000000080000001n,0x8000000080008081n,0x8000000000008009n,0x000000000000008an,0x0000000000000088n,0x0000000080008009n,0x000000008000000an,0x000000008000808bn,0x800000000000008bn,0x8000000000008089n,0x8000000000008003n,0x8000000000008002n,0x8000000000000080n,0x000000000000800an,0x800000008000000an,0x8000000080008081n,0x8000000000008080n,0x0000000080000001n,0x8000000080008008n];function a(r,t){return(r<<BigInt(t)|r>>BigInt(64-t))&n}function i(r){const t=new Array(5),e=new Array(25);for(const n of s){for(let e=0;e<5;e++)t[e]=r[e]^r[e+5]^r[e+10]^r[e+15]^r[e+20];for(let e=0;e<5;e++){const n=t[(e+4)%5]^a(t[(e+1)%5],1);for(let t=0;t<5;t++)r[e+5*t]^=n}for(let t=0;t<5;t++)for(let n=0;n<5;n++)e[n+(2*t+3*n)%5*5]=a(r[t+5*n],o[t+5*n]);for(let t=0;t<5;t++)for(let n=0;n<5;n++)r[t+5*n]=e[t+5*n]^~e[(t+1)%5+5*n]&e[(t+2)%5+5*n];r[0]^=n}}class d extends r.AddressValidator{validateImplementation(e,n){const o=t(e);if(40!==o.length)return{valid:!1,error:"Invalid length",details:{errorCode:r.ValidationError.INVALID_LENGTH}};if(!function(r){if("string"!=typeof r)return!1;const t=r.startsWith("0x")?r.slice(2):r;return/^[0-9a-fA-F]*$/.test(t)}(o))return{valid:!1,error:"Invalid hex characters",details:{errorCode:r.ValidationError.INVALID_CHARACTERS}};if(!n?.allowBurnAddress&&/^0+$/.test(o))return{valid:!1,error:"Burn address detected",details:{errorCode:r.ValidationError.BURN_ADDRESS}};const s=this.isChecksummed(o);return(n?.strict||o!==o.toLowerCase()&&o!==o.toUpperCase())&&!s?{valid:!1,error:"Invalid checksum",details:{errorCode:r.ValidationError.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:s}}}format(t,n){let o=e(r.InputSanitizer.sanitize(t));return n?.checksum&&(o=this.toChecksumAddress(o)),r.formatPlainAddress(o,n)}isChecksummed(r){const n=t(r);return e(n)===this.toChecksumAddress(n)}toChecksumAddress(r){const e=t(r).toLowerCase();if(!/^[0-9a-f]{40}$/.test(e))throw new Error("Expected a 20-byte hexadecimal address");const n=function(r){const t=(new TextEncoder).encode(r),e=new Uint8Array(136*(Math.floor(t.length/136)+1));e.set(t),e[t.length]=1,e[e.length-1]|=128;const n=new Array(25).fill(0n);for(let r=0;r<e.length;r+=136){for(let t=0;t<136;t++)n[t>>3]^=BigInt(e[r+t])<<BigInt(8*(7&t));i(n)}let o="";for(let r=0;r<32;r++)o+=Number(n[r>>3]>>BigInt(8*(7&r))&255n).toString(16).padStart(2,"0");return o}(e);return"0x"+[...e].map((r,t)=>parseInt(n[t],16)>=8?r.toUpperCase():r).join("")}}exports.EthereumValidator=d;
1
+ "use strict";var r=require("./shared/base-3sYui6r0.cjs");function e(r,e){if("string"!=typeof r)return!1;const t=r.startsWith("0x")?r.slice(2):r;return(void 0===e||t.length===e)&&/^[0-9a-fA-F]*$/.test(t)}function t(r){return r.startsWith("0x")?r.slice(2):r}const n=136,o=[0,1,62,28,27,36,44,6,55,20,3,10,43,25,39,41,45,15,21,8,18,2,61,56,14],s=new Uint32Array([1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648]),a=new Uint8Array(25);for(let r=0;r<5;r++)for(let e=0;e<5;e++)a[r+5*e]=e+(2*r+3*e)%5*5;const i=new Uint32Array(10),l=new Uint32Array(50);function d(r){for(let e=0;e<48;e+=2){for(let e=0;e<10;e++)i[e]=r[e]^r[e+10]^r[e+20]^r[e+30]^r[e+40];for(let e=0;e<5;e++){const t=(e+4)%5*2,n=(e+1)%5*2,o=i[t]^(i[n]<<1|i[n+1]>>>31),s=i[t+1]^(i[n+1]<<1|i[n]>>>31);for(let t=0;t<50;t+=10)r[2*e+t]^=o,r[2*e+t+1]^=s}for(let e=0;e<25;e++){const t=r[2*e],n=r[2*e+1],s=o[e],i=2*a[e];if(0===s)l[i]=t,l[i+1]=n;else if(s<32)l[i]=t<<s|n>>>32-s,l[i+1]=n<<s|t>>>32-s;else if(32===s)l[i]=n,l[i+1]=t;else{const r=s-32;l[i]=n<<r|t>>>32-r,l[i+1]=t<<r|n>>>32-r}}for(let e=0;e<50;e+=10)for(let t=0;t<5;t++){const n=e+2*t,o=e+(t+1)%5*2,s=e+(t+2)%5*2;r[n]=l[n]^~l[o]&l[s],r[n+1]=l[n+1]^~l[o+1]&l[s+1]}r[0]^=s[e],r[1]^=s[e+1]}}const c=new TextEncoder,f="0123456789abcdef";function u(r){if(/^[0-9]+$/.test(r))return r;const e=r.toLowerCase(),t=function(r){const e=c.encode(r),t=new Uint8Array((Math.floor(e.length/n)+1)*n);t.set(e),t[e.length]=1,t[t.length-1]|=128;const o=new Uint32Array(50);for(let r=0;r<t.length;r+=n){for(let e=0;e<n;e++)o[e>>2]^=t[r+e]<<8*(3&e);d(o)}let s="";for(let r=0;r<32;r++){const e=o[r>>2]>>>8*(3&r)&255;s+=f[e>>4]+f[15&e]}return s}(e);let o="";for(let r=0;r<e.length;r++)o+=t.charCodeAt(r)>=56?e[r].toUpperCase():e[r];return o}class h extends r.AddressValidator{validateImplementation(n,o){const s=t(n);if(40!==s.length)return{valid:!1,error:"Invalid length",details:{errorCode:r.ValidationError.INVALID_LENGTH}};if(!e(n))return{valid:!1,error:"Invalid hex characters",details:{errorCode:r.ValidationError.INVALID_CHARACTERS}};if(!o?.allowBurnAddress&&/^0+$/.test(s))return{valid:!1,error:"Burn address detected",details:{errorCode:r.ValidationError.BURN_ADDRESS}};const a=s===u(s);return!a&&(o?.strict||s!==s.toLowerCase()&&s!==s.toUpperCase())?{valid:!1,error:"Invalid checksum",details:{errorCode:r.ValidationError.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:a}}}format(n,o){const s=r.InputSanitizer.sanitize(n);if(!o?.checksum)return r.formatPlainAddress((a=s).startsWith("0x")?a:`0x${a}`,o);var a;if(!e(s,40))throw new Error("Expected a 20-byte hexadecimal address");return r.formatPlainAddress("0x"+u(t(s)),o)}}exports.EthereumValidator=h;
package/dist/ethereum.mjs CHANGED
@@ -1 +1 @@
1
- import{A as e,V as t,I as r,f as n}from"./shared/base-D2s8b6tx.mjs";function s(e){return e.startsWith("0x")?e.slice(2):e}function o(e){return e.startsWith("0x")?e:`0x${e}`}const a=(1n<<64n)-1n,i=[0,1,62,28,27,36,44,6,55,20,3,10,43,25,39,41,45,15,21,8,18,2,61,56,14],l=[0x0000000000000001n,0x0000000000008082n,0x800000000000808an,0x8000000080008000n,0x000000000000808bn,0x0000000080000001n,0x8000000080008081n,0x8000000000008009n,0x000000000000008an,0x0000000000000088n,0x0000000080008009n,0x000000008000000an,0x000000008000808bn,0x800000000000008bn,0x8000000000008089n,0x8000000000008003n,0x8000000000008002n,0x8000000000000080n,0x000000000000800an,0x800000008000000an,0x8000000080008081n,0x8000000000008080n,0x0000000080000001n,0x8000000080008008n];function c(e,t){return(e<<BigInt(t)|e>>BigInt(64-t))&a}function d(e){const t=new Array(5),r=new Array(25);for(const n of l){for(let r=0;r<5;r++)t[r]=e[r]^e[r+5]^e[r+10]^e[r+15]^e[r+20];for(let r=0;r<5;r++){const n=t[(r+4)%5]^c(t[(r+1)%5],1);for(let t=0;t<5;t++)e[r+5*t]^=n}for(let t=0;t<5;t++)for(let n=0;n<5;n++)r[n+(2*t+3*n)%5*5]=c(e[t+5*n],i[t+5*n]);for(let t=0;t<5;t++)for(let n=0;n<5;n++)e[t+5*n]=r[t+5*n]^~r[(t+1)%5+5*n]&r[(t+2)%5+5*n];e[0]^=n}}class x extends e{validateImplementation(e,r){const n=s(e);if(40!==n.length)return{valid:!1,error:"Invalid length",details:{errorCode:t.INVALID_LENGTH}};if(!function(e){if("string"!=typeof e)return!1;const t=e.startsWith("0x")?e.slice(2):e;return/^[0-9a-fA-F]*$/.test(t)}(n))return{valid:!1,error:"Invalid hex characters",details:{errorCode:t.INVALID_CHARACTERS}};if(!r?.allowBurnAddress&&/^0+$/.test(n))return{valid:!1,error:"Burn address detected",details:{errorCode:t.BURN_ADDRESS}};const o=this.isChecksummed(n);return(r?.strict||n!==n.toLowerCase()&&n!==n.toUpperCase())&&!o?{valid:!1,error:"Invalid checksum",details:{errorCode:t.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:o}}}format(e,t){let s=o(r.sanitize(e));return t?.checksum&&(s=this.toChecksumAddress(s)),n(s,t)}isChecksummed(e){const t=s(e);return o(t)===this.toChecksumAddress(t)}toChecksumAddress(e){const t=s(e).toLowerCase();if(!/^[0-9a-f]{40}$/.test(t))throw new Error("Expected a 20-byte hexadecimal address");const r=function(e){const t=(new TextEncoder).encode(e),r=new Uint8Array(136*(Math.floor(t.length/136)+1));r.set(t),r[t.length]=1,r[r.length-1]|=128;const n=new Array(25).fill(0n);for(let e=0;e<r.length;e+=136){for(let t=0;t<136;t++)n[t>>3]^=BigInt(r[e+t])<<BigInt(8*(7&t));d(n)}let s="";for(let e=0;e<32;e++)s+=Number(n[e>>3]>>BigInt(8*(7&e))&255n).toString(16).padStart(2,"0");return s}(t);return"0x"+[...t].map((e,t)=>parseInt(r[t],16)>=8?e.toUpperCase():e).join("")}}export{x as EthereumValidator};
1
+ import{A as e,V as t,I as r,f as n}from"./shared/base-CZZTeLCP.mjs";function o(e,t){if("string"!=typeof e)return!1;const r=e.startsWith("0x")?e.slice(2):e;return(void 0===t||r.length===t)&&/^[0-9a-fA-F]*$/.test(r)}function s(e){return e.startsWith("0x")?e.slice(2):e}const a=136,i=[0,1,62,28,27,36,44,6,55,20,3,10,43,25,39,41,45,15,21,8,18,2,61,56,14],l=new Uint32Array([1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648]),c=new Uint8Array(25);for(let e=0;e<5;e++)for(let t=0;t<5;t++)c[e+5*t]=t+(2*e+3*t)%5*5;const d=new Uint32Array(10),f=new Uint32Array(50);function h(e){for(let t=0;t<48;t+=2){for(let t=0;t<10;t++)d[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<5;t++){const r=(t+4)%5*2,n=(t+1)%5*2,o=d[r]^(d[n]<<1|d[n+1]>>>31),s=d[r+1]^(d[n+1]<<1|d[n]>>>31);for(let r=0;r<50;r+=10)e[2*t+r]^=o,e[2*t+r+1]^=s}for(let t=0;t<25;t++){const r=e[2*t],n=e[2*t+1],o=i[t],s=2*c[t];if(0===o)f[s]=r,f[s+1]=n;else if(o<32)f[s]=r<<o|n>>>32-o,f[s+1]=n<<o|r>>>32-o;else if(32===o)f[s]=n,f[s+1]=r;else{const e=o-32;f[s]=n<<e|r>>>32-e,f[s+1]=r<<e|n>>>32-e}}for(let t=0;t<50;t+=10)for(let r=0;r<5;r++){const n=t+2*r,o=t+(r+1)%5*2,s=t+(r+2)%5*2;e[n]=f[n]^~f[o]&f[s],e[n+1]=f[n+1]^~f[o+1]&f[s+1]}e[0]^=l[t],e[1]^=l[t+1]}}const u=new TextEncoder,A="0123456789abcdef";function C(e){if(/^[0-9]+$/.test(e))return e;const t=e.toLowerCase(),r=function(e){const t=u.encode(e),r=new Uint8Array((Math.floor(t.length/a)+1)*a);r.set(t),r[t.length]=1,r[r.length-1]|=128;const n=new Uint32Array(50);for(let e=0;e<r.length;e+=a){for(let t=0;t<a;t++)n[t>>2]^=r[e+t]<<8*(3&t);h(n)}let o="";for(let e=0;e<32;e++){const t=n[e>>2]>>>8*(3&e)&255;o+=A[t>>4]+A[15&t]}return o}(t);let n="";for(let e=0;e<t.length;e++)n+=r.charCodeAt(e)>=56?t[e].toUpperCase():t[e];return n}class w extends e{validateImplementation(e,r){const n=s(e);if(40!==n.length)return{valid:!1,error:"Invalid length",details:{errorCode:t.INVALID_LENGTH}};if(!o(e))return{valid:!1,error:"Invalid hex characters",details:{errorCode:t.INVALID_CHARACTERS}};if(!r?.allowBurnAddress&&/^0+$/.test(n))return{valid:!1,error:"Burn address detected",details:{errorCode:t.BURN_ADDRESS}};const a=n===C(n);return!a&&(r?.strict||n!==n.toLowerCase()&&n!==n.toUpperCase())?{valid:!1,error:"Invalid checksum",details:{errorCode:t.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:a}}}format(e,t){const a=r.sanitize(e);if(!t?.checksum)return n((i=a).startsWith("0x")?i:`0x${i}`,t);var i;if(!o(a,40))throw new Error("Expected a 20-byte hexadecimal address");return n("0x"+C(s(a)),t)}}export{w as EthereumValidator};
package/dist/evm.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("./ethereum.cjs"),a=require("./shared/base-BtbJMDNm.cjs");class t extends e.EthereumValidator{validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain="bsc"),t}}class i extends e.EthereumValidator{validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain="avalanche"),t}}class r extends e.EthereumValidator{validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain="arbitrum"),t}}class n extends e.EthereumValidator{validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain="optimism"),t}}class l extends e.EthereumValidator{validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain="base"),t}}class s extends e.EthereumValidator{constructor(e="evm"){if(super(),this.chain=e,!a.EVM_CHAINS.includes(e))throw new RangeError(`Unsupported EVM chain: ${String(e)}`)}validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain=this.chain),t}}exports.ArbitrumValidator=r,exports.AvalancheValidator=i,exports.BaseValidator=l,exports.BscValidator=t,exports.EvmValidator=s,exports.OptimismValidator=n;
1
+ "use strict";var e=require("./ethereum.cjs"),a=require("./shared/base-3sYui6r0.cjs");class t extends e.EthereumValidator{validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain="bsc"),t}}class i extends e.EthereumValidator{validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain="avalanche"),t}}class r extends e.EthereumValidator{validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain="arbitrum"),t}}class n extends e.EthereumValidator{validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain="optimism"),t}}class l extends e.EthereumValidator{validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain="base"),t}}class s extends e.EthereumValidator{constructor(e="evm"){if(super(),this.chain=e,!a.EVM_CHAINS.includes(e))throw new RangeError(`Unsupported EVM chain: ${String(e)}`)}validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain=this.chain),t}}exports.ArbitrumValidator=r,exports.AvalancheValidator=i,exports.BaseValidator=l,exports.BscValidator=t,exports.EvmValidator=s,exports.OptimismValidator=n;
package/dist/evm.mjs CHANGED
@@ -1 +1 @@
1
- import{EthereumValidator as e}from"./ethereum.mjs";import{E as t}from"./shared/base-D2s8b6tx.mjs";class a extends e{validateImplementation(e,t){const a=super.validateImplementation(e,t);return a.valid&&(a.blockchain="bsc"),a}}class n extends e{validateImplementation(e,t){const a=super.validateImplementation(e,t);return a.valid&&(a.blockchain="avalanche"),a}}class i extends e{validateImplementation(e,t){const a=super.validateImplementation(e,t);return a.valid&&(a.blockchain="arbitrum"),a}}class l extends e{validateImplementation(e,t){const a=super.validateImplementation(e,t);return a.valid&&(a.blockchain="optimism"),a}}class s extends e{validateImplementation(e,t){const a=super.validateImplementation(e,t);return a.valid&&(a.blockchain="base"),a}}class r extends e{constructor(e="evm"){if(super(),this.chain=e,!t.includes(e))throw new RangeError(`Unsupported EVM chain: ${String(e)}`)}validateImplementation(e,t){const a=super.validateImplementation(e,t);return a.valid&&(a.blockchain=this.chain),a}}export{i as ArbitrumValidator,n as AvalancheValidator,s as BaseValidator,a as BscValidator,r as EvmValidator,l as OptimismValidator};
1
+ import{EthereumValidator as e}from"./ethereum.mjs";import{E as t}from"./shared/base-CZZTeLCP.mjs";class a extends e{validateImplementation(e,t){const a=super.validateImplementation(e,t);return a.valid&&(a.blockchain="bsc"),a}}class n extends e{validateImplementation(e,t){const a=super.validateImplementation(e,t);return a.valid&&(a.blockchain="avalanche"),a}}class i extends e{validateImplementation(e,t){const a=super.validateImplementation(e,t);return a.valid&&(a.blockchain="arbitrum"),a}}class l extends e{validateImplementation(e,t){const a=super.validateImplementation(e,t);return a.valid&&(a.blockchain="optimism"),a}}class s extends e{validateImplementation(e,t){const a=super.validateImplementation(e,t);return a.valid&&(a.blockchain="base"),a}}class r extends e{constructor(e="evm"){if(super(),this.chain=e,!t.includes(e))throw new RangeError(`Unsupported EVM chain: ${String(e)}`)}validateImplementation(e,t){const a=super.validateImplementation(e,t);return a.valid&&(a.blockchain=this.chain),a}}export{i as ArbitrumValidator,n as AvalancheValidator,s as BaseValidator,a as BscValidator,r as EvmValidator,l as OptimismValidator};
@@ -1 +1 @@
1
- "use strict";var e=require("./shared/base-BtbJMDNm.cjs"),r=require("./ethereum.cjs");exports.addChecksum=function(t,s){return e.EVM_CHAINS.includes(s)?(new r.EthereumValidator).format(t,{checksum:!0}):e.InputSanitizer.sanitize(t)},exports.normalizeAddress=function(r,t){const s=e.InputSanitizer.sanitize(r);return e.EVM_CHAINS.includes(t)||"sui"===t||"aptos"===t?s.toLowerCase():s},exports.shortenAddress=function(r,t=4){return e.formatPlainAddress(r,{shorten:!0,shortenLength:t})};
1
+ "use strict";var e=require("./shared/base-3sYui6r0.cjs"),r=require("./ethereum.cjs");exports.addChecksum=function(t,s){return e.EVM_CHAINS.includes(s)?(new r.EthereumValidator).format(t,{checksum:!0}):e.InputSanitizer.sanitize(t)},exports.normalizeAddress=function(r,t){const s=e.InputSanitizer.sanitize(r);return e.EVM_CHAINS.includes(t)||"sui"===t||"aptos"===t?s.toLowerCase():s},exports.shortenAddress=function(r,t=4){return e.formatPlainAddress(r,{shorten:!0,shortenLength:t})};
@@ -1 +1 @@
1
- import{E as e,I as t,f as n}from"./shared/base-D2s8b6tx.mjs";import{EthereumValidator as s}from"./ethereum.mjs";function r(e,t=4){return n(e,{shorten:!0,shortenLength:t})}function o(n,s){const r=t.sanitize(n);return e.includes(s)||"sui"===s||"aptos"===s?r.toLowerCase():r}function i(n,r){return e.includes(r)?(new s).format(n,{checksum:!0}):t.sanitize(n)}export{i as addChecksum,o as normalizeAddress,r as shortenAddress};
1
+ import{E as e,I as t,f as n}from"./shared/base-CZZTeLCP.mjs";import{EthereumValidator as s}from"./ethereum.mjs";function r(e,t=4){return n(e,{shorten:!0,shortenLength:t})}function o(n,s){const r=t.sanitize(n);return e.includes(s)||"sui"===s||"aptos"===s?r.toLowerCase():r}function i(n,r){return e.includes(r)?(new s).format(n,{checksum:!0}):t.sanitize(n)}export{i as addChecksum,o as normalizeAddress,r as shortenAddress};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("./ethereum.cjs"),r=require("./solana.cjs"),t=require("./bitcoin.cjs"),a=require("./litecoin.cjs"),o=require("./dogecoin.cjs"),i=require("./cardano.cjs"),s=require("./ripple.cjs"),n=require("./evm.cjs"),d=require("./shared/base-BtbJMDNm.cjs"),l=require("./tron.cjs"),c=require("./cosmos.cjs"),u=require("./move.cjs"),p=require("./near.cjs"),V=require("./formatters.cjs");require("./shared/base58-DaLDoaS-.cjs"),require("./shared/utxo-DhlBlYDy.cjs"),require("./shared/base58check-CE9wLmUB.cjs"),require("./shared/sha256-CRbh7pIK.cjs"),require("./shared/bech32-ClvuyXIQ.cjs");class m extends e.EthereumValidator{validateImplementation(e,r){const t=super.validateImplementation(e,r);return t.valid&&(t.blockchain="polygon"),t}}const h=new Map;for(const r of d.EVM_CHAINS)h.set(r,"ethereum"===r?new e.EthereumValidator:new n.EvmValidator(r));for(const e of d.COSMOS_CHAINS)h.set(e,new c.CosmosValidator(e));h.set("bitcoin",new t.BitcoinValidator),h.set("litecoin",new a.LitecoinValidator),h.set("dogecoin",new o.DogecoinValidator),h.set("solana",new r.SolanaValidator),h.set("ripple",new s.RippleValidator),h.set("cardano",new i.CardanoValidator),h.set("tron",new l.TronValidator),h.set("sui",new u.SuiValidator),h.set("aptos",new u.AptosValidator),h.set("near",new p.NearValidator);const x=Object.freeze([...h.keys()]);function A(e){const r=h.get(e);if(!r)throw new Error(`Unsupported blockchain: ${String(e)}`);return r}exports.EthereumValidator=e.EthereumValidator,exports.SolanaValidator=r.SolanaValidator,exports.BitcoinValidator=t.BitcoinValidator,exports.LitecoinValidator=a.LitecoinValidator,exports.DogecoinValidator=o.DogecoinValidator,exports.CardanoValidator=i.CardanoValidator,exports.RippleValidator=s.RippleValidator,exports.ArbitrumValidator=n.ArbitrumValidator,exports.AvalancheValidator=n.AvalancheValidator,exports.BaseValidator=n.BaseValidator,exports.BscValidator=n.BscValidator,exports.EvmValidator=n.EvmValidator,exports.OptimismValidator=n.OptimismValidator,exports.AddressValidator=d.AddressValidator,exports.COSMOS_CHAINS=d.COSMOS_CHAINS,exports.EVM_CHAINS=d.EVM_CHAINS,Object.defineProperty(exports,"ValidationError",{enumerable:!0,get:function(){return d.ValidationError}}),exports.TronValidator=l.TronValidator,exports.CosmosValidator=c.CosmosValidator,exports.AptosValidator=u.AptosValidator,exports.SuiValidator=u.SuiValidator,exports.NearValidator=p.NearValidator,exports.addChecksum=V.addChecksum,exports.normalizeAddress=V.normalizeAddress,exports.shortenAddress=V.shortenAddress,exports.PolygonValidator=m,exports.SUPPORTED_CHAINS=x,exports.detectBlockchain=function(e,r){let t;try{t=d.InputSanitizer.sanitize(e)}catch{return null}if(!t)return null;const a=[];A("ethereum").validate(t,r).valid&&a.push(...d.EVM_CHAINS);for(const e of x)d.EVM_CHAINS.includes(e)||("near"!==e||/(\.near|\.testnet)$/.test(t)||/^[0-9a-f]{64}$/.test(t)||/^0[xs][0-9a-f]{40}$/.test(t)||/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(t))&&A(e).validate(t,r).valid&&a.push(e);return 0===a.length?null:1===a.length?a[0]:a},exports.formatAddress=function(e,r,t){return A(r).format(e,t)},exports.isSupportedChain=function(e){return"string"==typeof e&&h.has(e)},exports.validateAddress=function(e,r,t){return A(r).validate(e,t)},exports.validateBatch=function(e,r,t){const a=A(r);return Array.from(e,e=>a.validate(e,t))};
1
+ "use strict";var r=require("./ethereum.cjs"),e=require("./solana.cjs"),t=require("./bitcoin.cjs"),a=require("./litecoin.cjs"),o=require("./dogecoin.cjs"),i=require("./cardano.cjs"),s=require("./ripple.cjs"),n=require("./evm.cjs"),d=require("./shared/base-3sYui6r0.cjs"),l=require("./tron.cjs"),c=require("./cosmos.cjs"),p=require("./move.cjs"),u=require("./near.cjs"),V=require("./formatters.cjs");require("./shared/base58-DV6hu8Kq.cjs"),require("./shared/utxo-DF5Lt3lY.cjs"),require("./shared/base58check-BeCwnkGe.cjs"),require("./shared/bech32-Dk6Pnay4.cjs");class m extends r.EthereumValidator{validateImplementation(r,e){const t=super.validateImplementation(r,e);return t.valid&&(t.blockchain="polygon"),t}}const h=new Map;for(const e of d.EVM_CHAINS)h.set(e,"ethereum"===e?new r.EthereumValidator:new n.EvmValidator(e));for(const r of d.COSMOS_CHAINS)h.set(r,new c.CosmosValidator(r));h.set("bitcoin",new t.BitcoinValidator),h.set("litecoin",new a.LitecoinValidator),h.set("dogecoin",new o.DogecoinValidator),h.set("solana",new e.SolanaValidator),h.set("ripple",new s.RippleValidator),h.set("cardano",new i.CardanoValidator),h.set("tron",new l.TronValidator),h.set("sui",new p.SuiValidator),h.set("aptos",new p.AptosValidator),h.set("near",new u.NearValidator);const x=Object.freeze([...h.keys()]);function A(r){const e=h.get(r);if(!e)throw new Error(`Unsupported blockchain: ${String(r)}`);return e}const f=x.filter(r=>!d.EVM_CHAINS.includes(r));exports.EthereumValidator=r.EthereumValidator,exports.SolanaValidator=e.SolanaValidator,exports.BitcoinValidator=t.BitcoinValidator,exports.LitecoinValidator=a.LitecoinValidator,exports.DogecoinValidator=o.DogecoinValidator,exports.CardanoValidator=i.CardanoValidator,exports.RippleValidator=s.RippleValidator,exports.ArbitrumValidator=n.ArbitrumValidator,exports.AvalancheValidator=n.AvalancheValidator,exports.BaseValidator=n.BaseValidator,exports.BscValidator=n.BscValidator,exports.EvmValidator=n.EvmValidator,exports.OptimismValidator=n.OptimismValidator,exports.AddressValidator=d.AddressValidator,exports.COSMOS_CHAINS=d.COSMOS_CHAINS,exports.EVM_CHAINS=d.EVM_CHAINS,Object.defineProperty(exports,"ValidationError",{enumerable:!0,get:function(){return d.ValidationError}}),exports.TronValidator=l.TronValidator,exports.CosmosValidator=c.CosmosValidator,exports.AptosValidator=p.AptosValidator,exports.SuiValidator=p.SuiValidator,exports.NearValidator=u.NearValidator,exports.addChecksum=V.addChecksum,exports.normalizeAddress=V.normalizeAddress,exports.shortenAddress=V.shortenAddress,exports.PolygonValidator=m,exports.SUPPORTED_CHAINS=x,exports.detectBlockchain=function(r,e){d.assertValidationOptions(e);const t=d.InputSanitizer.trySanitize(r);if(!t)return null;const a=[];A("ethereum").validate(t,e).valid&&a.push(...d.EVM_CHAINS);for(const r of f){const o=A(r).validate(t,e);o.valid&&(("near"!==r||"named"!==o.details?.format||t.endsWith(".near")||t.endsWith(".testnet"))&&a.push(r))}return 0===a.length?null:1===a.length?a[0]:a},exports.formatAddress=function(r,e,t){return A(e).format(r,t)},exports.isSupportedChain=function(r){return"string"==typeof r&&h.has(r)},exports.validateAddress=function(r,e,t){return A(e).validate(r,t)},exports.validateBatch=function(r,e,t){const a=A(e);if(d.assertValidationOptions(t),!Array.isArray(r))return Array.from(r,r=>a.validate(r,t));const o=r.length,i=new Array(o);for(let e=0;e<o;e++){const o=Object.prototype.hasOwnProperty.call(r,e)?r[e]:void 0;i[e]=a.validate(o,t)}return i};
package/dist/index.d.cts CHANGED
@@ -50,8 +50,6 @@ declare abstract class AddressValidator {
50
50
  declare class EthereumValidator extends AddressValidator {
51
51
  protected validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
52
52
  format(address: string, options?: FormatOptions): string;
53
- private isChecksummed;
54
- private toChecksumAddress;
55
53
  }
56
54
 
57
55
  declare class SolanaValidator extends AddressValidator {
package/dist/index.d.mts CHANGED
@@ -50,8 +50,6 @@ declare abstract class AddressValidator {
50
50
  declare class EthereumValidator extends AddressValidator {
51
51
  protected validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
52
52
  format(address: string, options?: FormatOptions): string;
53
- private isChecksummed;
54
- private toChecksumAddress;
55
53
  }
56
54
 
57
55
  declare class SolanaValidator extends AddressValidator {
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{EthereumValidator as t}from"./ethereum.mjs";import{SolanaValidator as e}from"./solana.mjs";import{BitcoinValidator as r}from"./bitcoin.mjs";import{LitecoinValidator as o}from"./litecoin.mjs";import{DogecoinValidator as s}from"./dogecoin.mjs";import{CardanoValidator as n}from"./cardano.mjs";import{RippleValidator as a}from"./ripple.mjs";import{EvmValidator as m}from"./evm.mjs";export{ArbitrumValidator,AvalancheValidator,BaseValidator,BscValidator,OptimismValidator}from"./evm.mjs";import{E as i,C as l,I as c}from"./shared/base-D2s8b6tx.mjs";export{A as AddressValidator,V as ValidationError}from"./shared/base-D2s8b6tx.mjs";import{TronValidator as p}from"./tron.mjs";import{CosmosValidator as d}from"./cosmos.mjs";import{SuiValidator as f,AptosValidator as u}from"./move.mjs";import{NearValidator as h}from"./near.mjs";export{addChecksum,normalizeAddress,shortenAddress}from"./formatters.mjs";import"./shared/base58-CjvbdRzA.mjs";import"./shared/utxo-CRr3-5en.mjs";import"./shared/base58check-BBzwHAsr.mjs";import"./shared/sha256-BbwKo1_x.mjs";import"./shared/bech32-DsNhxmrB.mjs";class j extends t{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="polygon"),r}}const w=new Map;for(const e of i)w.set(e,"ethereum"===e?new t:new m(e));for(const t of l)w.set(t,new d(t));w.set("bitcoin",new r),w.set("litecoin",new o),w.set("dogecoin",new s),w.set("solana",new e),w.set("ripple",new a),w.set("cardano",new n),w.set("tron",new p),w.set("sui",new f),w.set("aptos",new u),w.set("near",new h);const v=Object.freeze([...w.keys()]);function b(t){return"string"==typeof t&&w.has(t)}function g(t){const e=w.get(t);if(!e)throw new Error(`Unsupported blockchain: ${String(t)}`);return e}function x(t,e){let r;try{r=c.sanitize(t)}catch{return null}if(!r)return null;const o=[];g("ethereum").validate(r,e).valid&&o.push(...i);for(const t of v)i.includes(t)||("near"!==t||/(\.near|\.testnet)$/.test(r)||/^[0-9a-f]{64}$/.test(r)||/^0[xs][0-9a-f]{40}$/.test(r)||/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(r))&&g(t).validate(r,e).valid&&o.push(t);return 0===o.length?null:1===o.length?o[0]:o}function k(t,e,r){return g(e).validate(t,r)}function y(t,e,r){const o=g(e);return Array.from(t,t=>o.validate(t,r))}function $(t,e,r){return g(e).format(t,r)}export{u as AptosValidator,r as BitcoinValidator,l as COSMOS_CHAINS,n as CardanoValidator,d as CosmosValidator,s as DogecoinValidator,i as EVM_CHAINS,t as EthereumValidator,m as EvmValidator,o as LitecoinValidator,h as NearValidator,j as PolygonValidator,a as RippleValidator,v as SUPPORTED_CHAINS,e as SolanaValidator,f as SuiValidator,p as TronValidator,x as detectBlockchain,$ as formatAddress,b as isSupportedChain,k as validateAddress,y as validateBatch};
1
+ import{EthereumValidator as t}from"./ethereum.mjs";import{SolanaValidator as e}from"./solana.mjs";import{BitcoinValidator as r}from"./bitcoin.mjs";import{LitecoinValidator as o}from"./litecoin.mjs";import{DogecoinValidator as s}from"./dogecoin.mjs";import{CardanoValidator as n}from"./cardano.mjs";import{RippleValidator as a}from"./ripple.mjs";import{EvmValidator as i}from"./evm.mjs";export{ArbitrumValidator,AvalancheValidator,BaseValidator,BscValidator,OptimismValidator}from"./evm.mjs";import{E as m,C as c,a as l,I as d}from"./shared/base-CZZTeLCP.mjs";export{A as AddressValidator,V as ValidationError}from"./shared/base-CZZTeLCP.mjs";import{TronValidator as p}from"./tron.mjs";import{CosmosValidator as f}from"./cosmos.mjs";import{SuiValidator as u,AptosValidator as h}from"./move.mjs";import{NearValidator as j}from"./near.mjs";export{addChecksum,normalizeAddress,shortenAddress}from"./formatters.mjs";import"./shared/base58-DY9-Un67.mjs";import"./shared/utxo-BrSxcH2x.mjs";import"./shared/base58check-rMkz2cjy.mjs";import"./shared/bech32-Cu41-5bd.mjs";class w extends t{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="polygon"),r}}const v=new Map;for(const e of m)v.set(e,"ethereum"===e?new t:new i(e));for(const t of c)v.set(t,new f(t));v.set("bitcoin",new r),v.set("litecoin",new o),v.set("dogecoin",new s),v.set("solana",new e),v.set("ripple",new a),v.set("cardano",new n),v.set("tron",new p),v.set("sui",new u),v.set("aptos",new h),v.set("near",new j);const b=Object.freeze([...v.keys()]);function y(t){return"string"==typeof t&&v.has(t)}function g(t){const e=v.get(t);if(!e)throw new Error(`Unsupported blockchain: ${String(t)}`);return e}const x=b.filter(t=>!m.includes(t));function k(t,e){l(e);const r=d.trySanitize(t);if(!r)return null;const o=[];g("ethereum").validate(r,e).valid&&o.push(...m);for(const t of x){const s=g(t).validate(r,e);s.valid&&(("near"!==t||"named"!==s.details?.format||r.endsWith(".near")||r.endsWith(".testnet"))&&o.push(t))}return 0===o.length?null:1===o.length?o[0]:o}function O(t,e,r){return g(e).validate(t,r)}function z(t,e,r){const o=g(e);if(l(r),!Array.isArray(t))return Array.from(t,t=>o.validate(t,r));const s=t.length,n=new Array(s);for(let e=0;e<s;e++){const s=Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;n[e]=o.validate(s,r)}return n}function E(t,e,r){return g(e).format(t,r)}export{h as AptosValidator,r as BitcoinValidator,c as COSMOS_CHAINS,n as CardanoValidator,f as CosmosValidator,s as DogecoinValidator,m as EVM_CHAINS,t as EthereumValidator,i as EvmValidator,o as LitecoinValidator,j as NearValidator,w as PolygonValidator,a as RippleValidator,b as SUPPORTED_CHAINS,e as SolanaValidator,u as SuiValidator,p as TronValidator,k as detectBlockchain,E as formatAddress,y as isSupportedChain,O as validateAddress,z as validateBatch};
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).validator0x={})}(this,function(t){"use strict";const e=Object.freeze(["ethereum","polygon","bsc","avalanche","arbitrum","optimism","base","evm","fantom","sonic","gnosis","celo","cronos","moonbeam","moonriver","zksync","linea","scroll","mantle","blast","opbnb","zora","worldchain"]),n=Object.freeze(["cosmos","osmosis","celestia","injective","sei"]);var r;t.ValidationError=void 0,(r=t.ValidationError||(t.ValidationError={})).INVALID_FORMAT="INVALID_FORMAT",r.INVALID_CHECKSUM="INVALID_CHECKSUM",r.INVALID_LENGTH="INVALID_LENGTH",r.INVALID_CHARACTERS="INVALID_CHARACTERS",r.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",r.BURN_ADDRESS="BURN_ADDRESS",r.UNSAFE_INPUT="UNSAFE_INPUT",r.NETWORK_MISMATCH="NETWORK_MISMATCH";class i{static sanitize(e){if(null==e)throw new Error(t.ValidationError.UNSAFE_INPUT);if("string"!=typeof e)throw new Error(t.ValidationError.UNSAFE_INPUT);if(e.length>256)throw new Error(t.ValidationError.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(e))throw new Error(t.ValidationError.UNSAFE_INPUT);return e.trim()}}class a{validate(e,n){try{const r=i.sanitize(e),a=this.validateImplementation(r,n),o=a.details?.network;return a.valid&&o&&(n?.network&&"auto"!==n.network&&n.network!==o||!1===n?.allowTestnet&&"testnet"===o)?{valid:!1,error:"Address network does not match the requested network",details:{...a.details,errorCode:t.ValidationError.NETWORK_MISMATCH}}:a}catch(e){const n=e instanceof Error?e.message:String(e);return n===t.ValidationError.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.ValidationError.UNSAFE_INPUT}}:{valid:!1,error:n,details:{errorCode:t.ValidationError.INVALID_FORMAT}}}}format(t,e){return o(t,e)}}function o(t,e,n=4){const r=i.sanitize(t);if(!e?.shorten)return r;const a=e.shortenLength??n;if(!Number.isSafeInteger(a)||a<1)throw new RangeError("shortenLength must be a positive integer");const o=r.startsWith("0x")?2:0;return r.length<=2*a+o+3?r:`${r.slice(0,a+o)}...${r.slice(-a)}`}function s(t){return t.startsWith("0x")?t.slice(2):t}function l(t){return t.startsWith("0x")?t:`0x${t}`}const c=(1n<<64n)-1n,d=[0,1,62,28,27,36,44,6,55,20,3,10,43,25,39,41,45,15,21,8,18,2,61,56,14],h=[0x0000000000000001n,0x0000000000008082n,0x800000000000808an,0x8000000080008000n,0x000000000000808bn,0x0000000080000001n,0x8000000080008081n,0x8000000000008009n,0x000000000000008an,0x0000000000000088n,0x0000000080008009n,0x000000008000000an,0x000000008000808bn,0x800000000000008bn,0x8000000000008089n,0x8000000000008003n,0x8000000000008002n,0x8000000000000080n,0x000000000000800an,0x800000008000000an,0x8000000080008081n,0x8000000000008080n,0x0000000080000001n,0x8000000080008008n];function u(t,e){return(t<<BigInt(e)|t>>BigInt(64-e))&c}function f(t){const e=new Array(5),n=new Array(25);for(const r of h){for(let n=0;n<5;n++)e[n]=t[n]^t[n+5]^t[n+10]^t[n+15]^t[n+20];for(let n=0;n<5;n++){const r=e[(n+4)%5]^u(e[(n+1)%5],1);for(let e=0;e<5;e++)t[n+5*e]^=r}for(let e=0;e<5;e++)for(let r=0;r<5;r++)n[r+(2*e+3*r)%5*5]=u(t[e+5*r],d[e+5*r]);for(let e=0;e<5;e++)for(let r=0;r<5;r++)t[e+5*r]=n[e+5*r]^~n[(e+1)%5+5*r]&n[(e+2)%5+5*r];t[0]^=r}}class m extends a{validateImplementation(e,n){const r=s(e);if(40!==r.length)return{valid:!1,error:"Invalid length",details:{errorCode:t.ValidationError.INVALID_LENGTH}};if(!function(t){if("string"!=typeof t)return!1;const e=t.startsWith("0x")?t.slice(2):t;return/^[0-9a-fA-F]*$/.test(e)}(r))return{valid:!1,error:"Invalid hex characters",details:{errorCode:t.ValidationError.INVALID_CHARACTERS}};if(!n?.allowBurnAddress&&/^0+$/.test(r))return{valid:!1,error:"Burn address detected",details:{errorCode:t.ValidationError.BURN_ADDRESS}};const i=this.isChecksummed(r);return(n?.strict||r!==r.toLowerCase()&&r!==r.toUpperCase())&&!i?{valid:!1,error:"Invalid checksum",details:{errorCode:t.ValidationError.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:i}}}format(t,e){let n=l(i.sanitize(t));return e?.checksum&&(n=this.toChecksumAddress(n)),o(n,e)}isChecksummed(t){const e=s(t);return l(e)===this.toChecksumAddress(e)}toChecksumAddress(t){const e=s(t).toLowerCase();if(!/^[0-9a-f]{40}$/.test(e))throw new Error("Expected a 20-byte hexadecimal address");const n=function(t){const e=(new TextEncoder).encode(t),n=new Uint8Array(136*(Math.floor(e.length/136)+1));n.set(e),n[e.length]=1,n[n.length-1]|=128;const r=new Array(25).fill(0n);for(let t=0;t<n.length;t+=136){for(let e=0;e<136;e++)r[e>>3]^=BigInt(n[t+e])<<BigInt(8*(7&e));f(r)}let i="";for(let t=0;t<32;t++)i+=Number(r[t>>3]>>BigInt(8*(7&t))&255n).toString(16).padStart(2,"0");return i}(e);return"0x"+[...e].map((t,e)=>parseInt(n[e],16)>=8?t.toUpperCase():t).join("")}}const v="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",I=v.charAt(0),g={};for(let t=0;t<58;t++)g[v.charAt(t)]=t;function p(t){if(0===t.length)return new Uint8Array(0);let e=0;for(;e<t.length&&t[e]===I;)e++;const n=e,r=[0];for(;e<t.length;e++){const n=t[e],i=g[n];if(void 0===i)throw new Error(`Invalid Base58 character: ${n}`);for(let t=0;t<r.length;t++)r[t]*=58;r[0]+=i;let a=0;for(let t=0;t<r.length;++t)r[t]+=a,a=r[t]>>8,r[t]&=255;for(;a;)r.push(255&a),a>>=8}const i=t.length===n?[]:r.reverse();return Uint8Array.from([...new Array(n).fill(0),...i])}class A extends a{validateImplementation(e){if(e.length<32||e.length>44)return{valid:!1,error:"Invalid length",details:{errorCode:t.ValidationError.INVALID_LENGTH}};try{if(32!==p(e).length)return{valid:!1,error:"Invalid public key length",details:{errorCode:t.ValidationError.INVALID_LENGTH}}}catch{return{valid:!1,error:"Invalid Base58 characters",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}return"11111111111111111111111111111111"===e?{valid:!0,blockchain:"solana",details:{format:"System Program"}}:{valid:!0,blockchain:"solana"}}}function E(t){const e=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],n=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],r=8*t.length,i=t.length,a=new Uint8Array(64-(i+8)%64+8);a[0]=128;const o=r,s=Math.floor(o/4294967296),l=o%4294967296,c=a.length;a[c-4]=l>>>24&255,a[c-3]=l>>>16&255,a[c-2]=l>>>8&255,a[c-1]=255&l,a[c-8]=s>>>24&255,a[c-7]=s>>>16&255,a[c-6]=s>>>8&255,a[c-5]=255&s;const d=new Uint8Array(i+a.length);d.set(t),d.set(a,i);const h=new Uint32Array(64);for(let t=0;t<d.length;t+=64){for(let e=0;e<16;e++)h[e]=d[t+4*e]<<24|d[t+4*e+1]<<16|d[t+4*e+2]<<8|d[t+4*e+3];for(let t=16;t<64;t++){const e=w(h[t-2],17)^w(h[t-2],19)^h[t-2]>>>10,n=w(h[t-15],7)^w(h[t-15],18)^h[t-15]>>>3;h[t]=e+h[t-7]+n+h[t-16]|0}let r=n[0],i=n[1],a=n[2],o=n[3],s=n[4],l=n[5],c=n[6],u=n[7];for(let t=0;t<64;t++){const n=u+(w(s,6)^w(s,11)^w(s,25))+(s&l^~s&c)+e[t]+h[t]|0,d=r&i^r&a^i&a;u=c,c=l,l=s,s=o+n|0,o=a,a=i,i=r,r=n+((w(r,2)^w(r,13)^w(r,22))+d|0)|0}n[0]=n[0]+r|0,n[1]=n[1]+i|0,n[2]=n[2]+a|0,n[3]=n[3]+o|0,n[4]=n[4]+s|0,n[5]=n[5]+l|0,n[6]=n[6]+c|0,n[7]=n[7]+u|0}const u=new Uint8Array(32);for(let t=0;t<8;t++)u[4*t]=n[t]>>>24&255,u[4*t+1]=n[t]>>>16&255,u[4*t+2]=n[t]>>>8&255,u[4*t+3]=255&n[t];return u}function w(t,e){return t>>>e|t<<32-e}function C(t){try{const e=p(t);if(e.length<5)return null;const n=e.slice(0,-4),r=E(E(n));return e.slice(-4).every((t,e)=>t===r[e])?n:null}catch{return null}}var V;!function(t){t.BECH32="bech32",t.BECH32M="bech32m"}(V||(V={}));const x=[996825010,642813549,513874426,1027748829,705979059];function N(t,e,n){const r=n===V.BECH32M?734539939:1;return function(t){let e=1;for(const n of t){const t=e>>25;e=(33554431&e)<<5^n;for(let n=0;n<5;n++)t>>n&1&&(e^=x[n])}return e}(function(t){const e=[];for(let n=0;n<t.length;n++)e.push(t.charCodeAt(n)>>5);e.push(0);for(let n=0;n<t.length;n++)e.push(31&t.charCodeAt(n));return e}(t).concat(e))===r}function k(t,e=90){if(t.length<8||t.length>e)return null;const n=t.toLowerCase();if(t!==n&&t!==t.toUpperCase())return null;const r=n.lastIndexOf("1");if(r<1||r+7>n.length)return null;const i=n.substring(0,r);if(/[^\x21-\x7E]/.test(i))return null;const a=[];for(let t=r+1;t<n.length;t++){const e="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(n[t]);if(-1===e)return null;a.push(e)}return N(i,a,V.BECH32)?{hrp:i,data:a.slice(0,a.length-6),encoding:V.BECH32}:N(i,a,V.BECH32M)?{hrp:i,data:a.slice(0,a.length-6),encoding:V.BECH32M}:null}function b(t){let e=0,n=0;const r=[];for(const i of t){if(!Number.isInteger(i)||i<0||i>31)return null;e=65535&(e<<5|i),n+=5,n>=8&&(n-=8,r.push(e>>>n&255))}return n>=5||e<<8-n&255?null:Uint8Array.from(r)}class y extends a{constructor(t){super(),this.config=t}validateImplementation(e){const n=e.toLowerCase().split("1")[0];if(this.config.hrps&&Object.prototype.hasOwnProperty.call(this.config.hrps,n))return this.validateWitness(e,this.config.hrps[n]);if(e.length<26||e.length>35)return this.invalid("Invalid address length",t.ValidationError.INVALID_LENGTH);const r=C(e);if(!r)return this.invalid("Invalid Base58Check address",t.ValidationError.INVALID_CHECKSUM);if(21!==r.length)return this.invalid("Invalid payload length",t.ValidationError.INVALID_LENGTH);const i=this.config.versions[r[0]];return i?{valid:!0,blockchain:this.config.chain,details:{format:"legacy",network:i,checksum:!0}}:this.invalid("Invalid address version")}validateWitness(e,n){const r=k(e);if(!r||0===r.data.length)return this.invalid("Invalid Bech32 encoding");const i=r.data[0],a=b(r.data.slice(1));if(i>16)return this.invalid("Invalid witness version");if(!a||a.length<2||a.length>40||0===i&&20!==a.length&&32!==a.length)return this.invalid("Invalid witness program or padding",t.ValidationError.INVALID_LENGTH);const o=0===i?V.BECH32:V.BECH32M;if(r.encoding!==o)return this.invalid("Wrong checksum encoding for witness version",t.ValidationError.INVALID_CHECKSUM);const s=0===i?"segwit":1===i&&32===a.length?"taproot":"future";return{valid:!0,blockchain:this.config.chain,details:{format:s,network:n,checksum:!0}}}invalid(e,n=t.ValidationError.INVALID_FORMAT){return{valid:!1,error:e,details:{errorCode:n}}}}class T extends y{constructor(){super({chain:"bitcoin",versions:{0:"mainnet",5:"mainnet",111:"testnet",196:"testnet"},hrps:{bc:"mainnet",tb:"testnet"}})}}class L extends y{constructor(){super({chain:"litecoin",versions:{48:"mainnet",50:"mainnet",5:"mainnet",111:"testnet",58:"testnet",196:"testnet"},hrps:{ltc:"mainnet",tltc:"testnet"}})}}class _ extends y{constructor(){super({chain:"dogecoin",versions:{30:"mainnet",22:"mainnet",113:"testnet",196:"testnet"}})}}class S{constructor(t){this.data=t,this.offset=0}head(t){if(this.offset>=this.data.length)throw new Error("Truncated CBOR");const e=this.data[this.offset++];if(e>>>5!==t)throw new Error("Invalid CBOR type");const n=31&e;if(n<24)return n;if(n>26)throw new Error("Unsupported CBOR length");const r=1<<n-24;if(this.offset+r>this.data.length)throw new Error("Truncated CBOR");let i=0;for(let t=0;t<r;t++)i=256*i+this.data[this.offset++];return i}bytes(){const t=this.head(2);if(this.offset+t>this.data.length)throw new Error("Truncated bytes");const e=this.data.slice(this.offset,this.offset+t);return this.offset+=t,e}end(){if(this.offset!==this.data.length)throw new Error("Trailing CBOR data")}}class U extends a{validateImplementation(t){if(/^(addr|stake)(_test)?1/i.test(t))return this.validateShelley(t);try{const e=function(t){try{const e=new S(t);if(2!==e.head(4)||24!==e.head(6))return null;const n=e.bytes();if(e.head(0)!==function(t){let e=4294967295;for(const n of t){e^=n;for(let t=0;t<8;t++)e=e>>>1^(1&e?3988292384:0)}return(4294967295^e)>>>0}(n))return null;e.end();const r=new S(n);if(3!==r.head(4)||28!==r.bytes().length)return null;const i=r.head(5);if(i>n.length)return null;const a=new Set;let o="mainnet";for(let t=0;t<i;t++){const t=r.head(0);if(a.has(t)||t>255)return null;a.add(t);const e=r.bytes();if(1===t){const t=new S(e);if(28!==t.bytes().length)return null;t.end()}if(2===t){const t=new S(e);t.head(0),t.end(),o="testnet"}}const s=r.head(0);return 0!==s&&2!==s?null:(r.end(),o)}catch{return null}}(p(t));if(e)return{valid:!0,blockchain:"cardano",details:{format:"byron",network:e,checksum:!0}}}catch{}return this.invalid()}validateShelley(t){const e=k(t,256),n=e&&b(e.data);if(!e||e.encoding!==V.BECH32||!n?.length)return this.invalid();const r=n[0]>>>4,i=15&n[0];if(0!==i&&1!==i)return this.invalid();const a=14===r||15===r,o=(a?"stake":"addr")+(0===i?"_test":"");if(e.hrp!==o)return this.invalid();let s=!1;return r<=3?s=57===n.length:6===r||7===r||a?s=29===n.length:4!==r&&5!==r||(s=this.validPointer(n)),s?{valid:!0,blockchain:"cardano",details:{format:a?"stake":"shelley",network:1===i?"mainnet":"testnet",checksum:!0}}:this.invalid()}validPointer(t){let e=29;for(let n=0;n<3;n++){let r=0n;const i=e;do{if(e>=t.length||e-i>=10)return!1;r=r<<7n|BigInt(127&t[e])}while(128&t[e++]);if(e-i>1&&128===t[i]||r>(0===n?0xffffffffn:0xffffn))return!1}return e===t.length}invalid(){return{valid:!1,error:"Invalid Cardano address structure, network, or checksum",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}format(t,e){return o(t,e,8)}}const R="rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz",D=R.charAt(0),H={};for(let t=0;t<58;t++)H[R.charAt(t)]=t;class B extends a{validateImplementation(e){if(!e.startsWith("r"))return{valid:!1,error:"Must start with r",details:{errorCode:t.ValidationError.INVALID_FORMAT}};if(e.length<25||e.length>35)return{valid:!1,error:"Invalid length",details:{errorCode:t.ValidationError.INVALID_LENGTH}};try{const n=function(t){if(0===t.length)return new Uint8Array(0);let e=0;for(;e<t.length&&t[e]===D;)e++;const n=e,r=[0];for(;e<t.length;e++){const n=t[e],i=H[n];if(void 0===i)throw new Error(`Invalid Ripple Base58 character: ${n}`);for(let t=0;t<r.length;t++)r[t]*=58;r[0]+=i;let a=0;for(let t=0;t<r.length;++t)r[t]+=a,a=r[t]>>8,r[t]&=255;for(;a;)r.push(255&a),a>>=8}let i=[];t.length!==n&&(i=r.reverse());for(let t=0;t<n;t++)i.unshift(0);return new Uint8Array(i)}(e);if(25!==n.length||0!==n[0])return{valid:!1,error:"Invalid decoded length",details:{errorCode:t.ValidationError.INVALID_LENGTH}};const r=n.slice(0,21),i=n.slice(21),a=E(r),o=E(a);return o[0]!==i[0]||o[1]!==i[1]||o[2]!==i[2]||o[3]!==i[3]?{valid:!1,error:"Invalid checksum",details:{errorCode:t.ValidationError.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ripple"}}catch{return{valid:!1,error:"Invalid characters",details:{errorCode:t.ValidationError.INVALID_CHARACTERS}}}}}class M extends m{constructor(t="evm"){if(super(),this.chain=t,!e.includes(t))throw new RangeError(`Unsupported EVM chain: ${String(t)}`)}validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain=this.chain),n}}class O extends a{validateImplementation(e){if(/^41[0-9a-fA-F]{40}$/.test(e))return{valid:!0,blockchain:"tron",details:{format:"hex",checksum:!1}};const n=34===e.length&&e.startsWith("T")?C(e):null;return n&&21===n.length&&65===n[0]?{valid:!0,blockchain:"tron",details:{format:"base58check",checksum:!0}}:{valid:!1,error:"Invalid TRON address",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}}const $={cosmos:"cosmos",osmosis:"osmo",celestia:"celestia",injective:"inj",sei:"sei"};class F extends a{constructor(t="cosmos"){if(super(),this.chain=t,!n.includes(t))throw new RangeError(`Unsupported Cosmos chain: ${String(t)}`)}validateImplementation(e){const n=k(e),r=n&&b(n.data),i="injective"===this.chain||"celestia"===this.chain?[20]:[20,32];return n&&n.hrp===$[this.chain]&&n.encoding===V.BECH32&&r&&i.includes(r.length)?{valid:!0,blockchain:this.chain,details:{format:"bech32",checksum:!0}}:{valid:!1,error:"Invalid account prefix, checksum, length, or padding",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}}class P extends a{validateImplementation(e){return/^0x[0-9a-fA-F]{64}$/.test(e)?{valid:!0,blockchain:"sui",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Expected 0x followed by 64 hex digits",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}}class z extends a{validateImplementation(e,n){const r=/^0x[0-9a-fA-F]{64}$/.test(e),i=/^0x[0-9a-f]$/.test(e),a=i||/^0x[0-9a-f]{64}$/.test(e)&&!/^0x0{63}[0-9a-f]$/.test(e);return(n?.strict?a:r||i)?{valid:!0,blockchain:"aptos",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Invalid Aptos address (AIP-40)",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}format(t,e){if(!this.validate(t).valid)throw new Error("Invalid Aptos address");let n=t.trim().toLowerCase();return/^0x0{63}[0-9a-f]$/.test(n)&&(n="0x"+n.slice(-1)),o(n,e)}}class j extends a{validateImplementation(e){if(e.length<2||e.length>64||!/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/.test(e))return{valid:!1,error:"Invalid NEAR account ID",details:{errorCode:t.ValidationError.INVALID_FORMAT}};return{valid:!0,blockchain:"near",details:{format:/^[0-9a-f]{64}$/.test(e)||/^0x[0-9a-f]{40}$/.test(e)?"implicit":/^0s[0-9a-f]{40}$/.test(e)?"deterministic":/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(e)?"universal":"named",checksum:!1}}}}const W=new Map;for(const t of e)W.set(t,"ethereum"===t?new m:new M(t));for(const t of n)W.set(t,new F(t));W.set("bitcoin",new T),W.set("litecoin",new L),W.set("dogecoin",new _),W.set("solana",new A),W.set("ripple",new B),W.set("cardano",new U),W.set("tron",new O),W.set("sui",new P),W.set("aptos",new z),W.set("near",new j);const G=Object.freeze([...W.keys()]);function K(t){const e=W.get(t);if(!e)throw new Error(`Unsupported blockchain: ${String(t)}`);return e}t.AddressValidator=a,t.AptosValidator=z,t.ArbitrumValidator=class extends m{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="arbitrum"),n}},t.AvalancheValidator=class extends m{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="avalanche"),n}},t.BaseValidator=class extends m{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="base"),n}},t.BitcoinValidator=T,t.BscValidator=class extends m{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="bsc"),n}},t.COSMOS_CHAINS=n,t.CardanoValidator=U,t.CosmosValidator=F,t.DogecoinValidator=_,t.EVM_CHAINS=e,t.EthereumValidator=m,t.EvmValidator=M,t.LitecoinValidator=L,t.NearValidator=j,t.OptimismValidator=class extends m{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="optimism"),n}},t.PolygonValidator=class extends m{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="polygon"),n}},t.RippleValidator=B,t.SUPPORTED_CHAINS=G,t.SolanaValidator=A,t.SuiValidator=P,t.TronValidator=O,t.addChecksum=function(t,n){return e.includes(n)?(new m).format(t,{checksum:!0}):i.sanitize(t)},t.detectBlockchain=function(t,n){let r;try{r=i.sanitize(t)}catch{return null}if(!r)return null;const a=[];K("ethereum").validate(r,n).valid&&a.push(...e);for(const t of G)e.includes(t)||("near"!==t||/(\.near|\.testnet)$/.test(r)||/^[0-9a-f]{64}$/.test(r)||/^0[xs][0-9a-f]{40}$/.test(r)||/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(r))&&K(t).validate(r,n).valid&&a.push(t);return 0===a.length?null:1===a.length?a[0]:a},t.formatAddress=function(t,e,n){return K(e).format(t,n)},t.isSupportedChain=function(t){return"string"==typeof t&&W.has(t)},t.normalizeAddress=function(t,n){const r=i.sanitize(t);return e.includes(n)||"sui"===n||"aptos"===n?r.toLowerCase():r},t.shortenAddress=function(t,e=4){return o(t,{shorten:!0,shortenLength:e})},t.validateAddress=function(t,e,n){return K(e).validate(t,n)},t.validateBatch=function(t,e,n){const r=K(e);return Array.from(t,t=>r.validate(t,n))}});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).validator0x={})}(this,function(t){"use strict";const e=Object.freeze(["ethereum","polygon","bsc","avalanche","arbitrum","optimism","base","evm","fantom","sonic","gnosis","celo","cronos","moonbeam","moonriver","zksync","linea","scroll","mantle","blast","opbnb","zora","worldchain"]),r=Object.freeze(["cosmos","osmosis","celestia","injective","sei"]);var n;t.ValidationError=void 0,(n=t.ValidationError||(t.ValidationError={})).INVALID_FORMAT="INVALID_FORMAT",n.INVALID_CHECKSUM="INVALID_CHECKSUM",n.INVALID_LENGTH="INVALID_LENGTH",n.INVALID_CHARACTERS="INVALID_CHARACTERS",n.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",n.BURN_ADDRESS="BURN_ADDRESS",n.UNSAFE_INPUT="UNSAFE_INPUT",n.NETWORK_MISMATCH="NETWORK_MISMATCH";class i{static trySanitize(t){return"string"!=typeof t||t.length>256||/[^\x20-\x7E]/.test(t)?null:t.trim()}static sanitize(e){const r=i.trySanitize(e);if(null===r)throw new Error(t.ValidationError.UNSAFE_INPUT);return r}}function a(){return{valid:!1,error:"Unsafe input detected",details:{errorCode:t.ValidationError.UNSAFE_INPUT}}}function o(t){const e=t?.network;if(null!=e&&"mainnet"!==e&&"testnet"!==e&&"auto"!==e)throw new RangeError("Invalid network option (expected 'mainnet', 'testnet' or 'auto')")}class s{validate(e,r){o(r);try{const n=i.trySanitize(e);if(null===n)return a();const o=this.validateImplementation(n,r),s=o.details?.network;return o.valid&&s&&(r?.network&&"auto"!==r.network&&r.network!==s||!1===r?.allowTestnet&&"testnet"===s)?{valid:!1,error:"Address network does not match the requested network",details:{...o.details,errorCode:t.ValidationError.NETWORK_MISMATCH}}:o}catch(e){const r=e instanceof Error?e.message:String(e);return r===t.ValidationError.UNSAFE_INPUT?a():{valid:!1,error:r,details:{errorCode:t.ValidationError.INVALID_FORMAT}}}}format(t,e){return l(t,e)}}function l(t,e,r=4){const n=i.sanitize(t);if(!e?.shorten)return n;const a=e.shortenLength??r;if(!Number.isSafeInteger(a)||a<1)throw new RangeError("shortenLength must be a positive integer");const o=n.startsWith("0x")?2:0;return n.length<=2*a+o+3?n:`${n.slice(0,a+o)}...${n.slice(-a)}`}function c(t,e){if("string"!=typeof t)return!1;const r=t.startsWith("0x")?t.slice(2):t;return(void 0===e||r.length===e)&&/^[0-9a-fA-F]*$/.test(r)}function d(t){return t.startsWith("0x")?t.slice(2):t}const h=136,u=[0,1,62,28,27,36,44,6,55,20,3,10,43,25,39,41,45,15,21,8,18,2,61,56,14],f=new Uint32Array([1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648]),v=new Uint8Array(25);for(let t=0;t<5;t++)for(let e=0;e<5;e++)v[t+5*e]=e+(2*t+3*e)%5*5;const m=new Uint32Array(10),I=new Uint32Array(50);function g(t){for(let e=0;e<48;e+=2){for(let e=0;e<10;e++)m[e]=t[e]^t[e+10]^t[e+20]^t[e+30]^t[e+40];for(let e=0;e<5;e++){const r=(e+4)%5*2,n=(e+1)%5*2,i=m[r]^(m[n]<<1|m[n+1]>>>31),a=m[r+1]^(m[n+1]<<1|m[n]>>>31);for(let r=0;r<50;r+=10)t[2*e+r]^=i,t[2*e+r+1]^=a}for(let e=0;e<25;e++){const r=t[2*e],n=t[2*e+1],i=u[e],a=2*v[e];if(0===i)I[a]=r,I[a+1]=n;else if(i<32)I[a]=r<<i|n>>>32-i,I[a+1]=n<<i|r>>>32-i;else if(32===i)I[a]=n,I[a+1]=r;else{const t=i-32;I[a]=n<<t|r>>>32-t,I[a+1]=r<<t|n>>>32-t}}for(let e=0;e<50;e+=10)for(let r=0;r<5;r++){const n=e+2*r,i=e+(r+1)%5*2,a=e+(r+2)%5*2;t[n]=I[n]^~I[i]&I[a],t[n+1]=I[n+1]^~I[i+1]&I[a+1]}t[0]^=f[e],t[1]^=f[e+1]}}const p=new TextEncoder,A="0123456789abcdef";function E(t){if(/^[0-9]+$/.test(t))return t;const e=t.toLowerCase(),r=function(t){const e=p.encode(t),r=new Uint8Array((Math.floor(e.length/h)+1)*h);r.set(e),r[e.length]=1,r[r.length-1]|=128;const n=new Uint32Array(50);for(let t=0;t<r.length;t+=h){for(let e=0;e<h;e++)n[e>>2]^=r[t+e]<<8*(3&e);g(n)}let i="";for(let t=0;t<32;t++){const e=n[t>>2]>>>8*(3&t)&255;i+=A[e>>4]+A[15&e]}return i}(e);let n="";for(let t=0;t<e.length;t++)n+=r.charCodeAt(t)>=56?e[t].toUpperCase():e[t];return n}class w extends s{validateImplementation(e,r){const n=d(e);if(40!==n.length)return{valid:!1,error:"Invalid length",details:{errorCode:t.ValidationError.INVALID_LENGTH}};if(!c(e))return{valid:!1,error:"Invalid hex characters",details:{errorCode:t.ValidationError.INVALID_CHARACTERS}};if(!r?.allowBurnAddress&&/^0+$/.test(n))return{valid:!1,error:"Burn address detected",details:{errorCode:t.ValidationError.BURN_ADDRESS}};const i=n===E(n);return!i&&(r?.strict||n!==n.toLowerCase()&&n!==n.toUpperCase())?{valid:!1,error:"Invalid checksum",details:{errorCode:t.ValidationError.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:i}}}format(t,e){const r=i.sanitize(t);if(!e?.checksum)return l((n=r).startsWith("0x")?n:`0x${n}`,e);var n;if(!c(r,40))throw new Error("Expected a 20-byte hexadecimal address");return l("0x"+E(d(r)),e)}}function V(t){const e=Object.create(null);for(let r=0;r<t.length;r++)e[t[r]]=r;return r=>{let n=0;for(;n<r.length&&r[n]===t[0];)n++;const i=[];for(let t=n;t<r.length;t++){let n=e[r[t]];if(void 0===n)throw new Error(`Invalid Base58 character: ${r[t]}`);for(let t=0;t<i.length;t++)n+=58*i[t],i[t]=255&n,n>>>=8;for(;n>0;)i.push(255&n),n>>>=8}const a=new Uint8Array(n+i.length);return a.set(i.reverse(),n),a}}const C=V("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");class N extends s{validateImplementation(e){if(e.length<32||e.length>44)return{valid:!1,error:"Invalid length",details:{errorCode:t.ValidationError.INVALID_LENGTH}};try{if(32!==C(e).length)return{valid:!1,error:"Invalid public key length",details:{errorCode:t.ValidationError.INVALID_LENGTH}}}catch{return{valid:!1,error:"Invalid Base58 characters",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}return"11111111111111111111111111111111"===e?{valid:!0,blockchain:"solana",details:{format:"System Program"}}:{valid:!0,blockchain:"solana"}}}const b=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function k(t){const e=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],r=64*Math.ceil((t.length+9)/64),n=new Uint8Array(r);n.set(t),n[t.length]=128;const i=8*t.length;y(n,r-8,Math.floor(i/4294967296)),y(n,r-4,i);const a=new Array(64);for(let t=0;t<r;t+=64){for(let e=0;e<16;e++){const r=t+4*e;a[e]=n[r]<<24|n[r+1]<<16|n[r+2]<<8|n[r+3]}for(let t=16;t<64;t++){const e=x(a[t-2],17)^x(a[t-2],19)^a[t-2]>>>10,r=x(a[t-15],7)^x(a[t-15],18)^a[t-15]>>>3;a[t]=e+a[t-7]+r+a[t-16]|0}let r=e[0],i=e[1],o=e[2],s=e[3],l=e[4],c=e[5],d=e[6],h=e[7];for(let t=0;t<64;t++){const e=h+(x(l,6)^x(l,11)^x(l,25))+(l&c^~l&d)+b[t]+a[t]|0,n=r&i^r&o^i&o;h=d,d=c,c=l,l=s+e|0,s=o,o=i,i=r,r=e+((x(r,2)^x(r,13)^x(r,22))+n|0)|0}e[0]=e[0]+r|0,e[1]=e[1]+i|0,e[2]=e[2]+o|0,e[3]=e[3]+s|0,e[4]=e[4]+l|0,e[5]=e[5]+c|0,e[6]=e[6]+d|0,e[7]=e[7]+h|0}const o=new Uint8Array(32);for(let t=0;t<e.length;t++)y(o,4*t,e[t]);return o}function y(t,e,r){t[e]=r>>>24,t[e+1]=r>>>16,t[e+2]=r>>>8,t[e+3]=r}function x(t,e){return t>>>e|t<<32-e}function L(t){if(t.length<5)return null;const e=t.subarray(0,-4),r=k(k(e));for(let n=0;n<4;n++)if(t[e.length+n]!==r[n])return null;return e}function T(t){try{return L(C(t))}catch{return null}}var _;!function(t){t.BECH32="bech32",t.BECH32M="bech32m"}(_||(_={}));const S=[996825010,642813549,513874426,1027748829,705979059],R=new Uint32Array(32);for(let t=1;t<R.length;t++)for(let e=0;e<S.length;e++)t&1<<e&&(R[t]^=S[e]);function D(t,e){return(33554431&t)<<5^e^R[t>>>25]}function U(t,e=90,r){if(t.length<8||t.length>e)return null;const n=t.lastIndexOf("1");if(n<1||n+7>t.length)return null;const i=t.slice(0,n).toLowerCase();if(void 0!==r&&i!==r)return null;if(/[^\x21-\x7E]/.test(t))return null;const a=t.toLowerCase();if(t!==a&&t!==t.toUpperCase())return null;const o=[];let s,l=function(t){let e=1;for(let r=0;r<t.length;r++)e=D(e,t.charCodeAt(r)>>>5);e=D(e,0);for(let r=0;r<t.length;r++)e=D(e,31&t.charCodeAt(r));return e}(i);for(let t=n+1;t<a.length;t++){const e="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(a[t]);if(-1===e)return null;l=D(l,e),t<a.length-6&&o.push(e)}if(1===l)s=_.BECH32;else{if(734539939!==l)return null;s=_.BECH32M}return{hrp:i,data:o,encoding:s}}function H(t){let e=0,r=0;const n=new Uint8Array(Math.floor(5*t.length/8));let i=0;for(const a of t){if(!Number.isInteger(a)||a<0||a>31)return null;e=65535&(e<<5|a),r+=5,r>=8&&(r-=8,n[i++]=e>>>r&255)}return r>=5||e<<8-r&255?null:n}class M extends s{constructor(t){super(),this.config=t}validateImplementation(e){const r=e.toLowerCase().split("1")[0];if(this.config.hrps&&Object.prototype.hasOwnProperty.call(this.config.hrps,r))return this.validateWitness(e,this.config.hrps[r]);if(e.length<26||e.length>35)return this.invalid("Invalid address length",t.ValidationError.INVALID_LENGTH);const n=T(e);if(!n)return this.invalid("Invalid Base58Check address",t.ValidationError.INVALID_CHECKSUM);if(21!==n.length)return this.invalid("Invalid payload length",t.ValidationError.INVALID_LENGTH);const i=this.config.versions[n[0]];return i?{valid:!0,blockchain:this.config.chain,details:{format:"legacy",network:i,checksum:!0}}:this.invalid("Invalid address version")}validateWitness(e,r){const n=U(e);if(!n||0===n.data.length)return this.invalid("Invalid Bech32 encoding");const i=n.data[0],a=H(n.data.slice(1));if(i>16)return this.invalid("Invalid witness version");if(!a||a.length<2||a.length>40||0===i&&20!==a.length&&32!==a.length)return this.invalid("Invalid witness program or padding",t.ValidationError.INVALID_LENGTH);const o=0===i?_.BECH32:_.BECH32M;if(n.encoding!==o)return this.invalid("Wrong checksum encoding for witness version",t.ValidationError.INVALID_CHECKSUM);let s="future";return 0===i?s="segwit":1===i&&32===a.length?s="taproot":"bitcoin"===this.config.chain&&1===i&&2===a.length&&78===a[0]&&115===a[1]&&(s="anchor"),{valid:!0,blockchain:this.config.chain,details:{format:s,network:r,checksum:!0}}}invalid(e,r=t.ValidationError.INVALID_FORMAT){return{valid:!1,error:e,details:{errorCode:r}}}}class O extends M{constructor(){super({chain:"bitcoin",versions:{0:"mainnet",5:"mainnet",111:"testnet",196:"testnet"},hrps:{bc:"mainnet",tb:"testnet"}})}}class B extends M{constructor(){super({chain:"litecoin",versions:{48:"mainnet",50:"mainnet",5:"mainnet",111:"testnet",58:"testnet",196:"testnet"},hrps:{ltc:"mainnet",tltc:"testnet"}})}}class F extends M{constructor(){super({chain:"dogecoin",versions:{30:"mainnet",22:"mainnet",113:"testnet",196:"testnet"}})}}const z=[24,256,65536];class P{constructor(t){this.data=t,this.offset=0}head(t,e=!1){if(this.offset>=this.data.length)throw new Error("Truncated CBOR");const r=this.data[this.offset++];if(r>>>5!==t)throw new Error("Invalid CBOR type");const n=31&r;if(n<24)return n;if(n>26)throw new Error("Unsupported CBOR length");const i=1<<n-24;if(this.offset+i>this.data.length)throw new Error("Truncated CBOR");let a=0;for(let t=0;t<i;t++)a=256*a+this.data[this.offset++];if(e&&a<z[n-24])throw new Error("Noncanonical CBOR argument");return a}bytes(t=!1){const e=this.head(2,t);if(this.offset+e>this.data.length)throw new Error("Truncated bytes");const r=this.data.slice(this.offset,this.offset+e);return this.offset+=e,r}end(){if(this.offset!==this.data.length)throw new Error("Trailing CBOR data")}}const W=[4294967295,65535,65535];class $ extends s{validateImplementation(t){if(/^(addr|stake)(_test)?1/i.test(t))return this.validateShelley(t);try{const e=function(t){try{const e=new P(t);if(2!==e.head(4)||24!==e.head(6))return null;const r=e.bytes();if(e.head(0)!==function(t){let e=4294967295;for(const r of t){e^=r;for(let t=0;t<8;t++)e=e>>>1^(1&e?3988292384:0)}return(4294967295^e)>>>0}(r))return null;e.end();const n=new P(r);if(3!==n.head(4)||28!==n.bytes().length)return null;const i=n.head(5);if(i>r.length)return null;const a=new Set;let o="mainnet";for(let t=0;t<i;t++){const t=n.head(0);if(a.has(t)||t>255)return null;a.add(t);const e=n.bytes();if(1===t){const t=new P(e);t.bytes(!0),t.end()}if(2===t){const t=new P(e);t.head(0,!0),t.end(),o="testnet"}}const s=n.head(0,!0);return 0!==s&&2!==s?null:(n.end(),o)}catch{return null}}(C(t));if(e)return{valid:!0,blockchain:"cardano",details:{format:"byron",network:e,checksum:!0}}}catch{}return this.invalid()}validateShelley(t){const e=U(t,256),r=e&&H(e.data);if(!e||e.encoding!==_.BECH32||!r?.length)return this.invalid();const n=r[0]>>>4,i=15&r[0];if(0!==i&&1!==i)return this.invalid();const a=14===n||15===n,o=(a?"stake":"addr")+(0===i?"_test":"");if(e.hrp!==o)return this.invalid();let s=!1;return n<=3?s=57===r.length:6===n||7===n||a?s=29===r.length:4!==n&&5!==n||(s=this.validPointer(r)),s?{valid:!0,blockchain:"cardano",details:{format:a?"stake":"shelley",network:1===i?"mainnet":"testnet",checksum:!0}}:this.invalid()}validPointer(t){let e=29;for(const r of W){if(128===t[e])return!1;let n,i=0;do{if(e>=t.length)return!1;if(n=t[e++],i=128*i+(127&n),i>r)return!1}while(128&n)}return e===t.length}invalid(){return{valid:!1,error:"Invalid Cardano address structure, network, or checksum",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}format(t,e){return l(t,e,8)}}const j=V("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");class G extends s{validateImplementation(e){if(!e.startsWith("r"))return{valid:!1,error:"Must start with r",details:{errorCode:t.ValidationError.INVALID_FORMAT}};if(e.length<25||e.length>35)return{valid:!1,error:"Invalid length",details:{errorCode:t.ValidationError.INVALID_LENGTH}};try{const r=j(e);return 25!==r.length||0!==r[0]?{valid:!1,error:"Invalid decoded length",details:{errorCode:t.ValidationError.INVALID_LENGTH}}:L(r)?{valid:!0,blockchain:"ripple"}:{valid:!1,error:"Invalid checksum",details:{errorCode:t.ValidationError.INVALID_CHECKSUM}}}catch{return{valid:!1,error:"Invalid characters",details:{errorCode:t.ValidationError.INVALID_CHARACTERS}}}}}class K extends w{constructor(t="evm"){if(super(),this.chain=t,!e.includes(t))throw new RangeError(`Unsupported EVM chain: ${String(t)}`)}validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain=this.chain),r}}class q extends s{validateImplementation(e){if(/^41[0-9a-fA-F]{40}$/.test(e))return{valid:!0,blockchain:"tron",details:{format:"hex",checksum:!1}};const r=34===e.length&&e.startsWith("T")?T(e):null;return r&&21===r.length&&65===r[0]?{valid:!0,blockchain:"tron",details:{format:"base58check",checksum:!0}}:{valid:!1,error:"Invalid TRON address",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}}const J={cosmos:"cosmos",osmosis:"osmo",celestia:"celestia",injective:"inj",sei:"sei"};class Q extends s{constructor(t="cosmos"){if(super(),this.chain=t,!r.includes(t))throw new RangeError(`Unsupported Cosmos chain: ${String(t)}`)}validateImplementation(e){const r=U(e,90,J[this.chain]);if(r?.encoding===_.BECH32){const t=H(r.data)?.length;if(20===t||32===t&&"injective"!==this.chain&&"celestia"!==this.chain)return{valid:!0,blockchain:this.chain,details:{format:"bech32",checksum:!0}}}return{valid:!1,error:"Invalid account prefix, checksum, length, or padding",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}}const X=/^0x[0-9a-fA-F]{64}$/,Y=/^0x[0-9a-fA-F]$/,Z="0x"+"0".repeat(63);class tt extends s{validateImplementation(e){return X.test(e)?{valid:!0,blockchain:"sui",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Expected 0x followed by 64 hex digits",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}}class et extends s{validateImplementation(e,r){return(3===e.length?Y:X).test(e)&&(!r?.strict||!/[A-F]/.test(e)&&!e.startsWith(Z))?{valid:!0,blockchain:"aptos",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Invalid Aptos address (AIP-40)",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}format(t,e){if(!this.validate(t).valid)throw new Error("Invalid Aptos address");let r=t.trim().toLowerCase();return r.startsWith(Z)&&(r="0x"+r.slice(-1)),l(r,e)}}class rt extends s{validateImplementation(e){if(e.length<2||e.length>64||!/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/.test(e))return{valid:!1,error:"Invalid NEAR account ID",details:{errorCode:t.ValidationError.INVALID_FORMAT}};return{valid:!0,blockchain:"near",details:{format:/^[0-9a-f]{64}$/.test(e)||/^0x[0-9a-f]{40}$/.test(e)?"implicit":/^0s[0-9a-f]{40}$/.test(e)?"deterministic":/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(e)?"universal":"named",checksum:!1}}}}const nt=new Map;for(const t of e)nt.set(t,"ethereum"===t?new w:new K(t));for(const t of r)nt.set(t,new Q(t));nt.set("bitcoin",new O),nt.set("litecoin",new B),nt.set("dogecoin",new F),nt.set("solana",new N),nt.set("ripple",new G),nt.set("cardano",new $),nt.set("tron",new q),nt.set("sui",new tt),nt.set("aptos",new et),nt.set("near",new rt);const it=Object.freeze([...nt.keys()]);function at(t){const e=nt.get(t);if(!e)throw new Error(`Unsupported blockchain: ${String(t)}`);return e}const ot=it.filter(t=>!e.includes(t));t.AddressValidator=s,t.AptosValidator=et,t.ArbitrumValidator=class extends w{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="arbitrum"),r}},t.AvalancheValidator=class extends w{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="avalanche"),r}},t.BaseValidator=class extends w{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="base"),r}},t.BitcoinValidator=O,t.BscValidator=class extends w{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="bsc"),r}},t.COSMOS_CHAINS=r,t.CardanoValidator=$,t.CosmosValidator=Q,t.DogecoinValidator=F,t.EVM_CHAINS=e,t.EthereumValidator=w,t.EvmValidator=K,t.LitecoinValidator=B,t.NearValidator=rt,t.OptimismValidator=class extends w{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="optimism"),r}},t.PolygonValidator=class extends w{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="polygon"),r}},t.RippleValidator=G,t.SUPPORTED_CHAINS=it,t.SolanaValidator=N,t.SuiValidator=tt,t.TronValidator=q,t.addChecksum=function(t,r){return e.includes(r)?(new w).format(t,{checksum:!0}):i.sanitize(t)},t.detectBlockchain=function(t,r){o(r);const n=i.trySanitize(t);if(!n)return null;const a=[];at("ethereum").validate(n,r).valid&&a.push(...e);for(const t of ot){const e=at(t).validate(n,r);e.valid&&(("near"!==t||"named"!==e.details?.format||n.endsWith(".near")||n.endsWith(".testnet"))&&a.push(t))}return 0===a.length?null:1===a.length?a[0]:a},t.formatAddress=function(t,e,r){return at(e).format(t,r)},t.isSupportedChain=function(t){return"string"==typeof t&&nt.has(t)},t.normalizeAddress=function(t,r){const n=i.sanitize(t);return e.includes(r)||"sui"===r||"aptos"===r?n.toLowerCase():n},t.shortenAddress=function(t,e=4){return l(t,{shorten:!0,shortenLength:e})},t.validateAddress=function(t,e,r){return at(e).validate(t,r)},t.validateBatch=function(t,e,r){const n=at(e);if(o(r),!Array.isArray(t))return Array.from(t,t=>n.validate(t,r));const i=t.length,a=new Array(i);for(let e=0;e<i;e++){const i=Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;a[e]=n.validate(i,r)}return a}});
package/dist/litecoin.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("./shared/utxo-DhlBlYDy.cjs");require("./shared/base-BtbJMDNm.cjs"),require("./shared/base58check-CE9wLmUB.cjs"),require("./shared/base58-DaLDoaS-.cjs"),require("./shared/sha256-CRbh7pIK.cjs"),require("./shared/bech32-ClvuyXIQ.cjs");class s extends e.UtxoValidator{constructor(){super({chain:"litecoin",versions:{48:"mainnet",50:"mainnet",5:"mainnet",111:"testnet",58:"testnet",196:"testnet"},hrps:{ltc:"mainnet",tltc:"testnet"}})}}exports.LitecoinValidator=s;
1
+ "use strict";var e=require("./shared/utxo-DF5Lt3lY.cjs");require("./shared/base-3sYui6r0.cjs"),require("./shared/base58check-BeCwnkGe.cjs"),require("./shared/base58-DV6hu8Kq.cjs"),require("./shared/bech32-Dk6Pnay4.cjs");class t extends e.UtxoValidator{constructor(){super({chain:"litecoin",versions:{48:"mainnet",50:"mainnet",5:"mainnet",111:"testnet",58:"testnet",196:"testnet"},hrps:{ltc:"mainnet",tltc:"testnet"}})}}exports.LitecoinValidator=t;
package/dist/litecoin.mjs CHANGED
@@ -1 +1 @@
1
- import{U as t}from"./shared/utxo-CRr3-5en.mjs";import"./shared/base-D2s8b6tx.mjs";import"./shared/base58check-BBzwHAsr.mjs";import"./shared/base58-CjvbdRzA.mjs";import"./shared/sha256-BbwKo1_x.mjs";import"./shared/bech32-DsNhxmrB.mjs";class e extends t{constructor(){super({chain:"litecoin",versions:{48:"mainnet",50:"mainnet",5:"mainnet",111:"testnet",58:"testnet",196:"testnet"},hrps:{ltc:"mainnet",tltc:"testnet"}})}}export{e as LitecoinValidator};
1
+ import{U as t}from"./shared/utxo-BrSxcH2x.mjs";import"./shared/base-CZZTeLCP.mjs";import"./shared/base58check-rMkz2cjy.mjs";import"./shared/base58-DY9-Un67.mjs";import"./shared/bech32-Cu41-5bd.mjs";class e extends t{constructor(){super({chain:"litecoin",versions:{48:"mainnet",50:"mainnet",5:"mainnet",111:"testnet",58:"testnet",196:"testnet"},hrps:{ltc:"mainnet",tltc:"testnet"}})}}export{e as LitecoinValidator};
package/dist/move.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t=require("./shared/base-BtbJMDNm.cjs");class e extends t.AddressValidator{validateImplementation(e){return/^0x[0-9a-fA-F]{64}$/.test(e)?{valid:!0,blockchain:"sui",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Expected 0x followed by 64 hex digits",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}}class a extends t.AddressValidator{validateImplementation(e,a){const r=/^0x[0-9a-fA-F]{64}$/.test(e),s=/^0x[0-9a-f]$/.test(e),d=s||/^0x[0-9a-f]{64}$/.test(e)&&!/^0x0{63}[0-9a-f]$/.test(e);return(a?.strict?d:r||s)?{valid:!0,blockchain:"aptos",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Invalid Aptos address (AIP-40)",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}format(e,a){if(!this.validate(e).valid)throw new Error("Invalid Aptos address");let r=e.trim().toLowerCase();return/^0x0{63}[0-9a-f]$/.test(r)&&(r="0x"+r.slice(-1)),t.formatPlainAddress(r,a)}}exports.AptosValidator=a,exports.SuiValidator=e;
1
+ "use strict";var t=require("./shared/base-3sYui6r0.cjs");const e=/^0x[0-9a-fA-F]{64}$/,r=/^0x[0-9a-fA-F]$/,a="0x"+"0".repeat(63);class s extends t.AddressValidator{validateImplementation(r){return e.test(r)?{valid:!0,blockchain:"sui",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Expected 0x followed by 64 hex digits",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}}class i extends t.AddressValidator{validateImplementation(s,i){return(3===s.length?r:e).test(s)&&(!i?.strict||!/[A-F]/.test(s)&&!s.startsWith(a))?{valid:!0,blockchain:"aptos",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Invalid Aptos address (AIP-40)",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}format(e,r){if(!this.validate(e).valid)throw new Error("Invalid Aptos address");let s=e.trim().toLowerCase();return s.startsWith(a)&&(s="0x"+s.slice(-1)),t.formatPlainAddress(s,r)}}exports.AptosValidator=i,exports.SuiValidator=s;
package/dist/move.mjs CHANGED
@@ -1 +1 @@
1
- import{A as e,V as t,f as a}from"./shared/base-D2s8b6tx.mjs";class s extends e{validateImplementation(e){return/^0x[0-9a-fA-F]{64}$/.test(e)?{valid:!0,blockchain:"sui",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Expected 0x followed by 64 hex digits",details:{errorCode:t.INVALID_FORMAT}}}}class r extends e{validateImplementation(e,a){const s=/^0x[0-9a-fA-F]{64}$/.test(e),r=/^0x[0-9a-f]$/.test(e),i=r||/^0x[0-9a-f]{64}$/.test(e)&&!/^0x0{63}[0-9a-f]$/.test(e);return(a?.strict?i:s||r)?{valid:!0,blockchain:"aptos",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Invalid Aptos address (AIP-40)",details:{errorCode:t.INVALID_FORMAT}}}format(e,t){if(!this.validate(e).valid)throw new Error("Invalid Aptos address");let s=e.trim().toLowerCase();return/^0x0{63}[0-9a-f]$/.test(s)&&(s="0x"+s.slice(-1)),a(s,t)}}export{r as AptosValidator,s as SuiValidator};
1
+ import{A as e,V as t,f as a}from"./shared/base-CZZTeLCP.mjs";const s=/^0x[0-9a-fA-F]{64}$/,r=/^0x[0-9a-fA-F]$/,i="0x"+"0".repeat(63);class d extends e{validateImplementation(e){return s.test(e)?{valid:!0,blockchain:"sui",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Expected 0x followed by 64 hex digits",details:{errorCode:t.INVALID_FORMAT}}}}class o extends e{validateImplementation(e,a){return(3===e.length?r:s).test(e)&&(!a?.strict||!/[A-F]/.test(e)&&!e.startsWith(i))?{valid:!0,blockchain:"aptos",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Invalid Aptos address (AIP-40)",details:{errorCode:t.INVALID_FORMAT}}}format(e,t){if(!this.validate(e).valid)throw new Error("Invalid Aptos address");let s=e.trim().toLowerCase();return s.startsWith(i)&&(s="0x"+s.slice(-1)),a(s,t)}}export{o as AptosValidator,d as SuiValidator};
package/dist/near.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("./shared/base-BtbJMDNm.cjs");class t extends e.AddressValidator{validateImplementation(t){if(t.length<2||t.length>64||!/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/.test(t))return{valid:!1,error:"Invalid NEAR account ID",details:{errorCode:e.ValidationError.INVALID_FORMAT}};return{valid:!0,blockchain:"near",details:{format:/^[0-9a-f]{64}$/.test(t)||/^0x[0-9a-f]{40}$/.test(t)?"implicit":/^0s[0-9a-f]{40}$/.test(t)?"deterministic":/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(t)?"universal":"named",checksum:!1}}}}exports.NearValidator=t;
1
+ "use strict";var e=require("./shared/base-3sYui6r0.cjs");class t extends e.AddressValidator{validateImplementation(t){if(t.length<2||t.length>64||!/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/.test(t))return{valid:!1,error:"Invalid NEAR account ID",details:{errorCode:e.ValidationError.INVALID_FORMAT}};return{valid:!0,blockchain:"near",details:{format:/^[0-9a-f]{64}$/.test(t)||/^0x[0-9a-f]{40}$/.test(t)?"implicit":/^0s[0-9a-f]{40}$/.test(t)?"deterministic":/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(t)?"universal":"named",checksum:!1}}}}exports.NearValidator=t;
package/dist/near.mjs CHANGED
@@ -1 +1 @@
1
- import{A as e,V as t}from"./shared/base-D2s8b6tx.mjs";class a extends e{validateImplementation(e){if(e.length<2||e.length>64||!/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/.test(e))return{valid:!1,error:"Invalid NEAR account ID",details:{errorCode:t.INVALID_FORMAT}};return{valid:!0,blockchain:"near",details:{format:/^[0-9a-f]{64}$/.test(e)||/^0x[0-9a-f]{40}$/.test(e)?"implicit":/^0s[0-9a-f]{40}$/.test(e)?"deterministic":/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(e)?"universal":"named",checksum:!1}}}}export{a as NearValidator};
1
+ import{A as e,V as t}from"./shared/base-CZZTeLCP.mjs";class a extends e{validateImplementation(e){if(e.length<2||e.length>64||!/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/.test(e))return{valid:!1,error:"Invalid NEAR account ID",details:{errorCode:t.INVALID_FORMAT}};return{valid:!0,blockchain:"near",details:{format:/^[0-9a-f]{64}$/.test(e)||/^0x[0-9a-f]{40}$/.test(e)?"implicit":/^0s[0-9a-f]{40}$/.test(e)?"deterministic":/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(e)?"universal":"named",checksum:!1}}}}export{a as NearValidator};
package/dist/ripple.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var r=require("./shared/base-BtbJMDNm.cjs"),e=require("./shared/sha256-CRbh7pIK.cjs");const t="rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz",a=t.charAt(0),i={};for(let r=0;r<58;r++)i[t.charAt(r)]=r;class l extends r.AddressValidator{validateImplementation(t){if(!t.startsWith("r"))return{valid:!1,error:"Must start with r",details:{errorCode:r.ValidationError.INVALID_FORMAT}};if(t.length<25||t.length>35)return{valid:!1,error:"Invalid length",details:{errorCode:r.ValidationError.INVALID_LENGTH}};try{const l=function(r){if(0===r.length)return new Uint8Array(0);let e=0;for(;e<r.length&&r[e]===a;)e++;const t=e,l=[0];for(;e<r.length;e++){const t=r[e],a=i[t];if(void 0===a)throw new Error(`Invalid Ripple Base58 character: ${t}`);for(let r=0;r<l.length;r++)l[r]*=58;l[0]+=a;let o=0;for(let r=0;r<l.length;++r)l[r]+=o,o=l[r]>>8,l[r]&=255;for(;o;)l.push(255&o),o>>=8}let o=[];r.length!==t&&(o=l.reverse());for(let r=0;r<t;r++)o.unshift(0);return new Uint8Array(o)}(t);if(25!==l.length||0!==l[0])return{valid:!1,error:"Invalid decoded length",details:{errorCode:r.ValidationError.INVALID_LENGTH}};const o=l.slice(0,21),n=l.slice(21),d=e.sha256(o),s=e.sha256(d);return s[0]!==n[0]||s[1]!==n[1]||s[2]!==n[2]||s[3]!==n[3]?{valid:!1,error:"Invalid checksum",details:{errorCode:r.ValidationError.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ripple"}}catch{return{valid:!1,error:"Invalid characters",details:{errorCode:r.ValidationError.INVALID_CHARACTERS}}}}}exports.RippleValidator=l;
1
+ "use strict";var r=require("./shared/base-3sYui6r0.cjs"),e=require("./shared/base58check-BeCwnkGe.cjs");const a=require("./shared/base58-DV6hu8Kq.cjs").createBase58Decoder("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");class t extends r.AddressValidator{validateImplementation(t){if(!t.startsWith("r"))return{valid:!1,error:"Must start with r",details:{errorCode:r.ValidationError.INVALID_FORMAT}};if(t.length<25||t.length>35)return{valid:!1,error:"Invalid length",details:{errorCode:r.ValidationError.INVALID_LENGTH}};try{const d=a(t);return 25!==d.length||0!==d[0]?{valid:!1,error:"Invalid decoded length",details:{errorCode:r.ValidationError.INVALID_LENGTH}}:e.checkedPayload(d)?{valid:!0,blockchain:"ripple"}:{valid:!1,error:"Invalid checksum",details:{errorCode:r.ValidationError.INVALID_CHECKSUM}}}catch{return{valid:!1,error:"Invalid characters",details:{errorCode:r.ValidationError.INVALID_CHARACTERS}}}}}exports.RippleValidator=t;
package/dist/ripple.mjs CHANGED
@@ -1 +1 @@
1
- import{A as r,V as e}from"./shared/base-D2s8b6tx.mjs";import{s as t}from"./shared/sha256-BbwKo1_x.mjs";const l="rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz",a=l.charAt(0),n={};for(let r=0;r<58;r++)n[l.charAt(r)]=r;class o extends r{validateImplementation(r){if(!r.startsWith("r"))return{valid:!1,error:"Must start with r",details:{errorCode:e.INVALID_FORMAT}};if(r.length<25||r.length>35)return{valid:!1,error:"Invalid length",details:{errorCode:e.INVALID_LENGTH}};try{const l=function(r){if(0===r.length)return new Uint8Array(0);let e=0;for(;e<r.length&&r[e]===a;)e++;const t=e,l=[0];for(;e<r.length;e++){const t=r[e],a=n[t];if(void 0===a)throw new Error(`Invalid Ripple Base58 character: ${t}`);for(let r=0;r<l.length;r++)l[r]*=58;l[0]+=a;let o=0;for(let r=0;r<l.length;++r)l[r]+=o,o=l[r]>>8,l[r]&=255;for(;o;)l.push(255&o),o>>=8}let o=[];r.length!==t&&(o=l.reverse());for(let r=0;r<t;r++)o.unshift(0);return new Uint8Array(o)}(r);if(25!==l.length||0!==l[0])return{valid:!1,error:"Invalid decoded length",details:{errorCode:e.INVALID_LENGTH}};const o=l.slice(0,21),i=l.slice(21),s=t(o),d=t(s);return d[0]!==i[0]||d[1]!==i[1]||d[2]!==i[2]||d[3]!==i[3]?{valid:!1,error:"Invalid checksum",details:{errorCode:e.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ripple"}}catch{return{valid:!1,error:"Invalid characters",details:{errorCode:e.INVALID_CHARACTERS}}}}}export{o as RippleValidator};
1
+ import{A as r,V as e}from"./shared/base-CZZTeLCP.mjs";import{c as a}from"./shared/base58check-rMkz2cjy.mjs";import{c as t}from"./shared/base58-DY9-Un67.mjs";const s=t("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");class d extends r{validateImplementation(r){if(!r.startsWith("r"))return{valid:!1,error:"Must start with r",details:{errorCode:e.INVALID_FORMAT}};if(r.length<25||r.length>35)return{valid:!1,error:"Invalid length",details:{errorCode:e.INVALID_LENGTH}};try{const t=s(r);return 25!==t.length||0!==t[0]?{valid:!1,error:"Invalid decoded length",details:{errorCode:e.INVALID_LENGTH}}:a(t)?{valid:!0,blockchain:"ripple"}:{valid:!1,error:"Invalid checksum",details:{errorCode:e.INVALID_CHECKSUM}}}catch{return{valid:!1,error:"Invalid characters",details:{errorCode:e.INVALID_CHARACTERS}}}}}export{d as RippleValidator};
@@ -0,0 +1 @@
1
+ "use strict";const t=Object.freeze(["ethereum","polygon","bsc","avalanche","arbitrum","optimism","base","evm","fantom","sonic","gnosis","celo","cronos","moonbeam","moonriver","zksync","linea","scroll","mantle","blast","opbnb","zora","worldchain"]),r=Object.freeze(["cosmos","osmosis","celestia","injective","sei"]);var e;exports.ValidationError=void 0,(e=exports.ValidationError||(exports.ValidationError={})).INVALID_FORMAT="INVALID_FORMAT",e.INVALID_CHECKSUM="INVALID_CHECKSUM",e.INVALID_LENGTH="INVALID_LENGTH",e.INVALID_CHARACTERS="INVALID_CHARACTERS",e.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",e.BURN_ADDRESS="BURN_ADDRESS",e.UNSAFE_INPUT="UNSAFE_INPUT",e.NETWORK_MISMATCH="NETWORK_MISMATCH";class o{static trySanitize(t){return"string"!=typeof t||t.length>256||/[^\x20-\x7E]/.test(t)?null:t.trim()}static sanitize(t){const r=o.trySanitize(t);if(null===r)throw new Error(exports.ValidationError.UNSAFE_INPUT);return r}}function n(){return{valid:!1,error:"Unsafe input detected",details:{errorCode:exports.ValidationError.UNSAFE_INPUT}}}function i(t){const r=t?.network;if(null!=r&&"mainnet"!==r&&"testnet"!==r&&"auto"!==r)throw new RangeError("Invalid network option (expected 'mainnet', 'testnet' or 'auto')")}function s(t,r,e=4){const n=o.sanitize(t);if(!r?.shorten)return n;const i=r.shortenLength??e;if(!Number.isSafeInteger(i)||i<1)throw new RangeError("shortenLength must be a positive integer");const s=n.startsWith("0x")?2:0;return n.length<=2*i+s+3?n:`${n.slice(0,i+s)}...${n.slice(-i)}`}exports.AddressValidator=class{validate(t,r){i(r);try{const e=o.trySanitize(t);if(null===e)return n();const i=this.validateImplementation(e,r),s=i.details?.network;return i.valid&&s&&(r?.network&&"auto"!==r.network&&r.network!==s||!1===r?.allowTestnet&&"testnet"===s)?{valid:!1,error:"Address network does not match the requested network",details:{...i.details,errorCode:exports.ValidationError.NETWORK_MISMATCH}}:i}catch(t){const r=t instanceof Error?t.message:String(t);return r===exports.ValidationError.UNSAFE_INPUT?n():{valid:!1,error:r,details:{errorCode:exports.ValidationError.INVALID_FORMAT}}}}format(t,r){return s(t,r)}},exports.COSMOS_CHAINS=r,exports.EVM_CHAINS=t,exports.InputSanitizer=o,exports.assertValidationOptions=i,exports.formatPlainAddress=s;
@@ -0,0 +1 @@
1
+ const e=Object.freeze(["ethereum","polygon","bsc","avalanche","arbitrum","optimism","base","evm","fantom","sonic","gnosis","celo","cronos","moonbeam","moonriver","zksync","linea","scroll","mantle","blast","opbnb","zora","worldchain"]),t=Object.freeze(["cosmos","osmosis","celestia","injective","sei"]);var n;!function(e){e.INVALID_FORMAT="INVALID_FORMAT",e.INVALID_CHECKSUM="INVALID_CHECKSUM",e.INVALID_LENGTH="INVALID_LENGTH",e.INVALID_CHARACTERS="INVALID_CHARACTERS",e.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",e.BURN_ADDRESS="BURN_ADDRESS",e.UNSAFE_INPUT="UNSAFE_INPUT",e.NETWORK_MISMATCH="NETWORK_MISMATCH"}(n||(n={}));class r{static trySanitize(e){return"string"!=typeof e||e.length>256||/[^\x20-\x7E]/.test(e)?null:e.trim()}static sanitize(e){const t=r.trySanitize(e);if(null===t)throw new Error(n.UNSAFE_INPUT);return t}}function o(){return{valid:!1,error:"Unsafe input detected",details:{errorCode:n.UNSAFE_INPUT}}}function s(e){const t=e?.network;if(null!=t&&"mainnet"!==t&&"testnet"!==t&&"auto"!==t)throw new RangeError("Invalid network option (expected 'mainnet', 'testnet' or 'auto')")}class a{validate(e,t){s(t);try{const s=r.trySanitize(e);if(null===s)return o();const a=this.validateImplementation(s,t),i=a.details?.network;return a.valid&&i&&(t?.network&&"auto"!==t.network&&t.network!==i||!1===t?.allowTestnet&&"testnet"===i)?{valid:!1,error:"Address network does not match the requested network",details:{...a.details,errorCode:n.NETWORK_MISMATCH}}:a}catch(e){const t=e instanceof Error?e.message:String(e);return t===n.UNSAFE_INPUT?o():{valid:!1,error:t,details:{errorCode:n.INVALID_FORMAT}}}}format(e,t){return i(e,t)}}function i(e,t,n=4){const o=r.sanitize(e);if(!t?.shorten)return o;const s=t.shortenLength??n;if(!Number.isSafeInteger(s)||s<1)throw new RangeError("shortenLength must be a positive integer");const a=o.startsWith("0x")?2:0;return o.length<=2*s+a+3?o:`${o.slice(0,s+a)}...${o.slice(-s)}`}export{a as A,t as C,e as E,r as I,n as V,s as a,i as f};
@@ -0,0 +1 @@
1
+ "use strict";function e(e){const t=Object.create(null);for(let r=0;r<e.length;r++)t[e[r]]=r;return r=>{let n=0;for(;n<r.length&&r[n]===e[0];)n++;const o=[];for(let e=n;e<r.length;e++){let n=t[r[e]];if(void 0===n)throw new Error(`Invalid Base58 character: ${r[e]}`);for(let e=0;e<o.length;e++)n+=58*o[e],o[e]=255&n,n>>>=8;for(;n>0;)o.push(255&n),n>>>=8}const s=new Uint8Array(n+o.length);return s.set(o.reverse(),n),s}}const t=e("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");exports.createBase58Decoder=e,exports.decodeBase58=t;
@@ -0,0 +1 @@
1
+ function e(e){const t=Object.create(null);for(let r=0;r<e.length;r++)t[e[r]]=r;return r=>{let n=0;for(;n<r.length&&r[n]===e[0];)n++;const o=[];for(let e=n;e<r.length;e++){let n=t[r[e]];if(void 0===n)throw new Error(`Invalid Base58 character: ${r[e]}`);for(let e=0;e<o.length;e++)n+=58*o[e],o[e]=255&n,n>>>=8;for(;n>0;)o.push(255&n),n>>>=8}const l=new Uint8Array(n+o.length);return l.set(o.reverse(),n),l}}const t=e("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");export{e as c,t as d};
@@ -0,0 +1 @@
1
+ "use strict";var t=require("./base58-DV6hu8Kq.cjs");const e=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function n(t){const n=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],c=64*Math.ceil((t.length+9)/64),l=new Uint8Array(c);l.set(t),l[t.length]=128;const s=8*t.length;r(l,c-8,Math.floor(s/4294967296)),r(l,c-4,s);const u=new Array(64);for(let t=0;t<c;t+=64){for(let e=0;e<16;e++){const n=t+4*e;u[e]=l[n]<<24|l[n+1]<<16|l[n+2]<<8|l[n+3]}for(let t=16;t<64;t++){const e=o(u[t-2],17)^o(u[t-2],19)^u[t-2]>>>10,n=o(u[t-15],7)^o(u[t-15],18)^u[t-15]>>>3;u[t]=e+u[t-7]+n+u[t-16]|0}let r=n[0],c=n[1],s=n[2],a=n[3],f=n[4],i=n[5],h=n[6],d=n[7];for(let t=0;t<64;t++){const n=d+(o(f,6)^o(f,11)^o(f,25))+(f&i^~f&h)+e[t]+u[t]|0,l=r&c^r&s^c&s;d=h,h=i,i=f,f=a+n|0,a=s,s=c,c=r,r=n+((o(r,2)^o(r,13)^o(r,22))+l|0)|0}n[0]=n[0]+r|0,n[1]=n[1]+c|0,n[2]=n[2]+s|0,n[3]=n[3]+a|0,n[4]=n[4]+f|0,n[5]=n[5]+i|0,n[6]=n[6]+h|0,n[7]=n[7]+d|0}const a=new Uint8Array(32);for(let t=0;t<n.length;t++)r(a,4*t,n[t]);return a}function r(t,e,n){t[e]=n>>>24,t[e+1]=n>>>16,t[e+2]=n>>>8,t[e+3]=n}function o(t,e){return t>>>e|t<<32-e}function c(t){if(t.length<5)return null;const e=t.subarray(0,-4),r=n(n(e));for(let n=0;n<4;n++)if(t[e.length+n]!==r[n])return null;return e}exports.checkedPayload=c,exports.decodeBase58Check=function(e){try{return c(t.decodeBase58(e))}catch{return null}};
@@ -0,0 +1 @@
1
+ import{d as t}from"./base58-DY9-Un67.mjs";const n=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function r(t){const r=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],l=64*Math.ceil((t.length+9)/64),c=new Uint8Array(l);c.set(t),c[t.length]=128;const s=8*t.length;e(c,l-8,Math.floor(s/4294967296)),e(c,l-4,s);const u=new Array(64);for(let t=0;t<l;t+=64){for(let n=0;n<16;n++){const r=t+4*n;u[n]=c[r]<<24|c[r+1]<<16|c[r+2]<<8|c[r+3]}for(let t=16;t<64;t++){const n=o(u[t-2],17)^o(u[t-2],19)^u[t-2]>>>10,r=o(u[t-15],7)^o(u[t-15],18)^u[t-15]>>>3;u[t]=n+u[t-7]+r+u[t-16]|0}let e=r[0],l=r[1],s=r[2],f=r[3],a=r[4],i=r[5],h=r[6],g=r[7];for(let t=0;t<64;t++){const r=g+(o(a,6)^o(a,11)^o(a,25))+(a&i^~a&h)+n[t]+u[t]|0,c=e&l^e&s^l&s;g=h,h=i,i=a,a=f+r|0,f=s,s=l,l=e,e=r+((o(e,2)^o(e,13)^o(e,22))+c|0)|0}r[0]=r[0]+e|0,r[1]=r[1]+l|0,r[2]=r[2]+s|0,r[3]=r[3]+f|0,r[4]=r[4]+a|0,r[5]=r[5]+i|0,r[6]=r[6]+h|0,r[7]=r[7]+g|0}const f=new Uint8Array(32);for(let t=0;t<r.length;t++)e(f,4*t,r[t]);return f}function e(t,n,r){t[n]=r>>>24,t[n+1]=r>>>16,t[n+2]=r>>>8,t[n+3]=r}function o(t,n){return t>>>n|t<<32-n}function l(t){if(t.length<5)return null;const n=t.subarray(0,-4),e=r(r(n));for(let r=0;r<4;r++)if(t[n.length+r]!==e[r])return null;return n}function c(n){try{return l(t(n))}catch{return null}}export{l as c,c as d};
@@ -0,0 +1 @@
1
+ var n;!function(n){n.BECH32="bech32",n.BECH32M="bech32m"}(n||(n={}));const t=[996825010,642813549,513874426,1027748829,705979059],e=new Uint32Array(32);for(let n=1;n<e.length;n++)for(let r=0;r<t.length;r++)n&1<<r&&(e[n]^=t[r]);function r(n,t){return(33554431&n)<<5^t^e[n>>>25]}function l(t,e=90,l){if(t.length<8||t.length>e)return null;const o=t.lastIndexOf("1");if(o<1||o+7>t.length)return null;const u=t.slice(0,o).toLowerCase();if(void 0!==l&&u!==l)return null;if(/[^\x21-\x7E]/.test(t))return null;const f=t.toLowerCase();if(t!==f&&t!==t.toUpperCase())return null;const i=[];let s,c=function(n){let t=1;for(let e=0;e<n.length;e++)t=r(t,n.charCodeAt(e)>>>5);t=r(t,0);for(let e=0;e<n.length;e++)t=r(t,31&n.charCodeAt(e));return t}(u);for(let n=o+1;n<f.length;n++){const t="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(f[n]);if(-1===t)return null;c=r(c,t),n<f.length-6&&i.push(t)}if(1===c)s=n.BECH32;else{if(734539939!==c)return null;s=n.BECH32M}return{hrp:u,data:i,encoding:s}}function o(n){let t=0,e=0;const r=new Uint8Array(Math.floor(5*n.length/8));let l=0;for(const o of n){if(!Number.isInteger(o)||o<0||o>31)return null;t=65535&(t<<5|o),e+=5,e>=8&&(e-=8,r[l++]=t>>>e&255)}return e>=5||t<<8-e&255?null:r}export{n as B,l as d,o as w};
@@ -0,0 +1 @@
1
+ "use strict";var e;exports.Bech32Encoding=void 0,(e=exports.Bech32Encoding||(exports.Bech32Encoding={})).BECH32="bech32",e.BECH32M="bech32m";const n=[996825010,642813549,513874426,1027748829,705979059],t=new Uint32Array(32);for(let e=1;e<t.length;e++)for(let r=0;r<n.length;r++)e&1<<r&&(t[e]^=n[r]);function r(e,n){return(33554431&e)<<5^n^t[e>>>25]}exports.decodeBech32=function(e,n=90,t){if(e.length<8||e.length>n)return null;const o=e.lastIndexOf("1");if(o<1||o+7>e.length)return null;const l=e.slice(0,o).toLowerCase();if(void 0!==t&&l!==t)return null;if(/[^\x21-\x7E]/.test(e))return null;const c=e.toLowerCase();if(e!==c&&e!==e.toUpperCase())return null;const s=[];let u,i=function(e){let n=1;for(let t=0;t<e.length;t++)n=r(n,e.charCodeAt(t)>>>5);n=r(n,0);for(let t=0;t<e.length;t++)n=r(n,31&e.charCodeAt(t));return n}(l);for(let e=o+1;e<c.length;e++){const n="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(c[e]);if(-1===n)return null;i=r(i,n),e<c.length-6&&s.push(n)}if(1===i)u=exports.Bech32Encoding.BECH32;else{if(734539939!==i)return null;u=exports.Bech32Encoding.BECH32M}return{hrp:l,data:s,encoding:u}},exports.wordsToBytes=function(e){let n=0,t=0;const r=new Uint8Array(Math.floor(5*e.length/8));let o=0;for(const l of e){if(!Number.isInteger(l)||l<0||l>31)return null;n=65535&(n<<5|l),t+=5,t>=8&&(t-=8,r[o++]=n>>>t&255)}return t>=5||n<<8-t&255?null:r};
@@ -1 +1 @@
1
- import{A as i,V as t}from"./base-D2s8b6tx.mjs";import{d as n}from"./base58check-BBzwHAsr.mjs";import{d as s,w as e,B as a}from"./bech32-DsNhxmrB.mjs";class r extends i{constructor(i){super(),this.config=i}validateImplementation(i){const s=i.toLowerCase().split("1")[0];if(this.config.hrps&&Object.prototype.hasOwnProperty.call(this.config.hrps,s))return this.validateWitness(i,this.config.hrps[s]);if(i.length<26||i.length>35)return this.invalid("Invalid address length",t.INVALID_LENGTH);const e=n(i);if(!e)return this.invalid("Invalid Base58Check address",t.INVALID_CHECKSUM);if(21!==e.length)return this.invalid("Invalid payload length",t.INVALID_LENGTH);const a=this.config.versions[e[0]];return a?{valid:!0,blockchain:this.config.chain,details:{format:"legacy",network:a,checksum:!0}}:this.invalid("Invalid address version")}validateWitness(i,n){const r=s(i);if(!r||0===r.data.length)return this.invalid("Invalid Bech32 encoding");const o=r.data[0],l=e(r.data.slice(1));if(o>16)return this.invalid("Invalid witness version");if(!l||l.length<2||l.length>40||0===o&&20!==l.length&&32!==l.length)return this.invalid("Invalid witness program or padding",t.INVALID_LENGTH);const d=0===o?a.BECH32:a.BECH32M;if(r.encoding!==d)return this.invalid("Wrong checksum encoding for witness version",t.INVALID_CHECKSUM);const h=0===o?"segwit":1===o&&32===l.length?"taproot":"future";return{valid:!0,blockchain:this.config.chain,details:{format:h,network:n,checksum:!0}}}invalid(i,n=t.INVALID_FORMAT){return{valid:!1,error:i,details:{errorCode:n}}}}export{r as U};
1
+ import{A as i,V as t}from"./base-CZZTeLCP.mjs";import{d as n}from"./base58check-rMkz2cjy.mjs";import{d as s,w as e,B as a}from"./bech32-Cu41-5bd.mjs";class r extends i{constructor(i){super(),this.config=i}validateImplementation(i){const s=i.toLowerCase().split("1")[0];if(this.config.hrps&&Object.prototype.hasOwnProperty.call(this.config.hrps,s))return this.validateWitness(i,this.config.hrps[s]);if(i.length<26||i.length>35)return this.invalid("Invalid address length",t.INVALID_LENGTH);const e=n(i);if(!e)return this.invalid("Invalid Base58Check address",t.INVALID_CHECKSUM);if(21!==e.length)return this.invalid("Invalid payload length",t.INVALID_LENGTH);const a=this.config.versions[e[0]];return a?{valid:!0,blockchain:this.config.chain,details:{format:"legacy",network:a,checksum:!0}}:this.invalid("Invalid address version")}validateWitness(i,n){const r=s(i);if(!r||0===r.data.length)return this.invalid("Invalid Bech32 encoding");const o=r.data[0],l=e(r.data.slice(1));if(o>16)return this.invalid("Invalid witness version");if(!l||l.length<2||l.length>40||0===o&&20!==l.length&&32!==l.length)return this.invalid("Invalid witness program or padding",t.INVALID_LENGTH);const h=0===o?a.BECH32:a.BECH32M;if(r.encoding!==h)return this.invalid("Wrong checksum encoding for witness version",t.INVALID_CHECKSUM);let c="future";return 0===o?c="segwit":1===o&&32===l.length?c="taproot":"bitcoin"===this.config.chain&&1===o&&2===l.length&&78===l[0]&&115===l[1]&&(c="anchor"),{valid:!0,blockchain:this.config.chain,details:{format:c,network:n,checksum:!0}}}invalid(i,n=t.INVALID_FORMAT){return{valid:!1,error:i,details:{errorCode:n}}}}export{r as U};
@@ -0,0 +1 @@
1
+ "use strict";var i=require("./base-3sYui6r0.cjs"),n=require("./base58check-BeCwnkGe.cjs"),t=require("./bech32-Dk6Pnay4.cjs");class e extends i.AddressValidator{constructor(i){super(),this.config=i}validateImplementation(t){const e=t.toLowerCase().split("1")[0];if(this.config.hrps&&Object.prototype.hasOwnProperty.call(this.config.hrps,e))return this.validateWitness(t,this.config.hrps[e]);if(t.length<26||t.length>35)return this.invalid("Invalid address length",i.ValidationError.INVALID_LENGTH);const r=n.decodeBase58Check(t);if(!r)return this.invalid("Invalid Base58Check address",i.ValidationError.INVALID_CHECKSUM);if(21!==r.length)return this.invalid("Invalid payload length",i.ValidationError.INVALID_LENGTH);const a=this.config.versions[r[0]];return a?{valid:!0,blockchain:this.config.chain,details:{format:"legacy",network:a,checksum:!0}}:this.invalid("Invalid address version")}validateWitness(n,e){const r=t.decodeBech32(n);if(!r||0===r.data.length)return this.invalid("Invalid Bech32 encoding");const a=r.data[0],s=t.wordsToBytes(r.data.slice(1));if(a>16)return this.invalid("Invalid witness version");if(!s||s.length<2||s.length>40||0===a&&20!==s.length&&32!==s.length)return this.invalid("Invalid witness program or padding",i.ValidationError.INVALID_LENGTH);const o=0===a?t.Bech32Encoding.BECH32:t.Bech32Encoding.BECH32M;if(r.encoding!==o)return this.invalid("Wrong checksum encoding for witness version",i.ValidationError.INVALID_CHECKSUM);let d="future";return 0===a?d="segwit":1===a&&32===s.length?d="taproot":"bitcoin"===this.config.chain&&1===a&&2===s.length&&78===s[0]&&115===s[1]&&(d="anchor"),{valid:!0,blockchain:this.config.chain,details:{format:d,network:e,checksum:!0}}}invalid(n,t=i.ValidationError.INVALID_FORMAT){return{valid:!1,error:n,details:{errorCode:t}}}}exports.UtxoValidator=e;
package/dist/solana.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var r=require("./shared/base-BtbJMDNm.cjs"),a=require("./shared/base58-DaLDoaS-.cjs");class e extends r.AddressValidator{validateImplementation(e){if(e.length<32||e.length>44)return{valid:!1,error:"Invalid length",details:{errorCode:r.ValidationError.INVALID_LENGTH}};try{if(32!==a.decodeBase58(e).length)return{valid:!1,error:"Invalid public key length",details:{errorCode:r.ValidationError.INVALID_LENGTH}}}catch{return{valid:!1,error:"Invalid Base58 characters",details:{errorCode:r.ValidationError.INVALID_FORMAT}}}return"11111111111111111111111111111111"===e?{valid:!0,blockchain:"solana",details:{format:"System Program"}}:{valid:!0,blockchain:"solana"}}}exports.SolanaValidator=e;
1
+ "use strict";var r=require("./shared/base-3sYui6r0.cjs"),a=require("./shared/base58-DV6hu8Kq.cjs");class e extends r.AddressValidator{validateImplementation(e){if(e.length<32||e.length>44)return{valid:!1,error:"Invalid length",details:{errorCode:r.ValidationError.INVALID_LENGTH}};try{if(32!==a.decodeBase58(e).length)return{valid:!1,error:"Invalid public key length",details:{errorCode:r.ValidationError.INVALID_LENGTH}}}catch{return{valid:!1,error:"Invalid Base58 characters",details:{errorCode:r.ValidationError.INVALID_FORMAT}}}return"11111111111111111111111111111111"===e?{valid:!0,blockchain:"solana",details:{format:"System Program"}}:{valid:!0,blockchain:"solana"}}}exports.SolanaValidator=e;
package/dist/solana.mjs CHANGED
@@ -1 +1 @@
1
- import{A as r,V as e}from"./shared/base-D2s8b6tx.mjs";import{d as a}from"./shared/base58-CjvbdRzA.mjs";class l extends r{validateImplementation(r){if(r.length<32||r.length>44)return{valid:!1,error:"Invalid length",details:{errorCode:e.INVALID_LENGTH}};try{if(32!==a(r).length)return{valid:!1,error:"Invalid public key length",details:{errorCode:e.INVALID_LENGTH}}}catch{return{valid:!1,error:"Invalid Base58 characters",details:{errorCode:e.INVALID_FORMAT}}}return"11111111111111111111111111111111"===r?{valid:!0,blockchain:"solana",details:{format:"System Program"}}:{valid:!0,blockchain:"solana"}}}export{l as SolanaValidator};
1
+ import{A as r,V as e}from"./shared/base-CZZTeLCP.mjs";import{d as a}from"./shared/base58-DY9-Un67.mjs";class l extends r{validateImplementation(r){if(r.length<32||r.length>44)return{valid:!1,error:"Invalid length",details:{errorCode:e.INVALID_LENGTH}};try{if(32!==a(r).length)return{valid:!1,error:"Invalid public key length",details:{errorCode:e.INVALID_LENGTH}}}catch{return{valid:!1,error:"Invalid Base58 characters",details:{errorCode:e.INVALID_FORMAT}}}return"11111111111111111111111111111111"===r?{valid:!0,blockchain:"solana",details:{format:"System Program"}}:{valid:!0,blockchain:"solana"}}}export{l as SolanaValidator};
package/dist/tron.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("./shared/base-BtbJMDNm.cjs"),r=require("./shared/base58check-CE9wLmUB.cjs");require("./shared/base58-DaLDoaS-.cjs"),require("./shared/sha256-CRbh7pIK.cjs");class a extends e.AddressValidator{validateImplementation(a){if(/^41[0-9a-fA-F]{40}$/.test(a))return{valid:!0,blockchain:"tron",details:{format:"hex",checksum:!1}};const s=34===a.length&&a.startsWith("T")?r.decodeBase58Check(a):null;return s&&21===s.length&&65===s[0]?{valid:!0,blockchain:"tron",details:{format:"base58check",checksum:!0}}:{valid:!1,error:"Invalid TRON address",details:{errorCode:e.ValidationError.INVALID_FORMAT}}}}exports.TronValidator=a;
1
+ "use strict";var e=require("./shared/base-3sYui6r0.cjs"),r=require("./shared/base58check-BeCwnkGe.cjs");require("./shared/base58-DV6hu8Kq.cjs");class a extends e.AddressValidator{validateImplementation(a){if(/^41[0-9a-fA-F]{40}$/.test(a))return{valid:!0,blockchain:"tron",details:{format:"hex",checksum:!1}};const s=34===a.length&&a.startsWith("T")?r.decodeBase58Check(a):null;return s&&21===s.length&&65===s[0]?{valid:!0,blockchain:"tron",details:{format:"base58check",checksum:!0}}:{valid:!1,error:"Invalid TRON address",details:{errorCode:e.ValidationError.INVALID_FORMAT}}}}exports.TronValidator=a;
package/dist/tron.mjs CHANGED
@@ -1 +1 @@
1
- import{A as e,V as a}from"./shared/base-D2s8b6tx.mjs";import{d as s}from"./shared/base58check-BBzwHAsr.mjs";import"./shared/base58-CjvbdRzA.mjs";import"./shared/sha256-BbwKo1_x.mjs";class r extends e{validateImplementation(e){if(/^41[0-9a-fA-F]{40}$/.test(e))return{valid:!0,blockchain:"tron",details:{format:"hex",checksum:!1}};const r=34===e.length&&e.startsWith("T")?s(e):null;return r&&21===r.length&&65===r[0]?{valid:!0,blockchain:"tron",details:{format:"base58check",checksum:!0}}:{valid:!1,error:"Invalid TRON address",details:{errorCode:a.INVALID_FORMAT}}}}export{r as TronValidator};
1
+ import{A as e,V as a}from"./shared/base-CZZTeLCP.mjs";import{d as s}from"./shared/base58check-rMkz2cjy.mjs";import"./shared/base58-DY9-Un67.mjs";class r extends e{validateImplementation(e){if(/^41[0-9a-fA-F]{40}$/.test(e))return{valid:!0,blockchain:"tron",details:{format:"hex",checksum:!1}};const r=34===e.length&&e.startsWith("T")?s(e):null;return r&&21===r.length&&65===r[0]?{valid:!0,blockchain:"tron",details:{format:"base58check",checksum:!0}}:{valid:!1,error:"Invalid TRON address",details:{errorCode:a.INVALID_FORMAT}}}}export{r as TronValidator};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "validator0x",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Lightweight, zero-dependency wallet address validation for EVM, Bitcoin, Solana, TRON, Cosmos, Cardano, Sui, Aptos, NEAR and more.",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -1 +0,0 @@
1
- "use strict";const r=Object.freeze(["ethereum","polygon","bsc","avalanche","arbitrum","optimism","base","evm","fantom","sonic","gnosis","celo","cronos","moonbeam","moonriver","zksync","linea","scroll","mantle","blast","opbnb","zora","worldchain"]),e=Object.freeze(["cosmos","osmosis","celestia","injective","sei"]);var t;exports.ValidationError=void 0,(t=exports.ValidationError||(exports.ValidationError={})).INVALID_FORMAT="INVALID_FORMAT",t.INVALID_CHECKSUM="INVALID_CHECKSUM",t.INVALID_LENGTH="INVALID_LENGTH",t.INVALID_CHARACTERS="INVALID_CHARACTERS",t.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",t.BURN_ADDRESS="BURN_ADDRESS",t.UNSAFE_INPUT="UNSAFE_INPUT",t.NETWORK_MISMATCH="NETWORK_MISMATCH";class o{static sanitize(r){if(null==r)throw new Error(exports.ValidationError.UNSAFE_INPUT);if("string"!=typeof r)throw new Error(exports.ValidationError.UNSAFE_INPUT);if(r.length>256)throw new Error(exports.ValidationError.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(r))throw new Error(exports.ValidationError.UNSAFE_INPUT);return r.trim()}}function s(r,e,t=4){const s=o.sanitize(r);if(!e?.shorten)return s;const i=e.shortenLength??t;if(!Number.isSafeInteger(i)||i<1)throw new RangeError("shortenLength must be a positive integer");const n=s.startsWith("0x")?2:0;return s.length<=2*i+n+3?s:`${s.slice(0,i+n)}...${s.slice(-i)}`}exports.AddressValidator=class{validate(r,e){try{const t=o.sanitize(r),s=this.validateImplementation(t,e),i=s.details?.network;return s.valid&&i&&(e?.network&&"auto"!==e.network&&e.network!==i||!1===e?.allowTestnet&&"testnet"===i)?{valid:!1,error:"Address network does not match the requested network",details:{...s.details,errorCode:exports.ValidationError.NETWORK_MISMATCH}}:s}catch(r){const e=r instanceof Error?r.message:String(r);return e===exports.ValidationError.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:exports.ValidationError.UNSAFE_INPUT}}:{valid:!1,error:e,details:{errorCode:exports.ValidationError.INVALID_FORMAT}}}}format(r,e){return s(r,e)}},exports.COSMOS_CHAINS=e,exports.EVM_CHAINS=r,exports.InputSanitizer=o,exports.formatPlainAddress=s;
@@ -1 +0,0 @@
1
- const e=Object.freeze(["ethereum","polygon","bsc","avalanche","arbitrum","optimism","base","evm","fantom","sonic","gnosis","celo","cronos","moonbeam","moonriver","zksync","linea","scroll","mantle","blast","opbnb","zora","worldchain"]),t=Object.freeze(["cosmos","osmosis","celestia","injective","sei"]);var r;!function(e){e.INVALID_FORMAT="INVALID_FORMAT",e.INVALID_CHECKSUM="INVALID_CHECKSUM",e.INVALID_LENGTH="INVALID_LENGTH",e.INVALID_CHARACTERS="INVALID_CHARACTERS",e.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",e.BURN_ADDRESS="BURN_ADDRESS",e.UNSAFE_INPUT="UNSAFE_INPUT",e.NETWORK_MISMATCH="NETWORK_MISMATCH"}(r||(r={}));class o{static sanitize(e){if(null==e)throw new Error(r.UNSAFE_INPUT);if("string"!=typeof e)throw new Error(r.UNSAFE_INPUT);if(e.length>256)throw new Error(r.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(e))throw new Error(r.UNSAFE_INPUT);return e.trim()}}class n{validate(e,t){try{const n=o.sanitize(e),s=this.validateImplementation(n,t),i=s.details?.network;return s.valid&&i&&(t?.network&&"auto"!==t.network&&t.network!==i||!1===t?.allowTestnet&&"testnet"===i)?{valid:!1,error:"Address network does not match the requested network",details:{...s.details,errorCode:r.NETWORK_MISMATCH}}:s}catch(e){const t=e instanceof Error?e.message:String(e);return t===r.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:r.UNSAFE_INPUT}}:{valid:!1,error:t,details:{errorCode:r.INVALID_FORMAT}}}}format(e,t){return s(e,t)}}function s(e,t,r=4){const n=o.sanitize(e);if(!t?.shorten)return n;const s=t.shortenLength??r;if(!Number.isSafeInteger(s)||s<1)throw new RangeError("shortenLength must be a positive integer");const i=n.startsWith("0x")?2:0;return n.length<=2*s+i+3?n:`${n.slice(0,s+i)}...${n.slice(-s)}`}export{n as A,t as C,e as E,o as I,r as V,s as f};
@@ -1 +0,0 @@
1
- const r="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",t=r.charAt(0),e={};for(let t=0;t<58;t++)e[r.charAt(t)]=t;function n(r){if(0===r.length)return new Uint8Array(0);let n=0;for(;n<r.length&&r[n]===t;)n++;const o=n,l=[0];for(;n<r.length;n++){const t=r[n],o=e[t];if(void 0===o)throw new Error(`Invalid Base58 character: ${t}`);for(let r=0;r<l.length;r++)l[r]*=58;l[0]+=o;let f=0;for(let r=0;r<l.length;++r)l[r]+=f,f=l[r]>>8,l[r]&=255;for(;f;)l.push(255&f),f>>=8}const f=r.length===o?[]:l.reverse();return Uint8Array.from([...new Array(o).fill(0),...f])}export{n as d};
@@ -1 +0,0 @@
1
- "use strict";const r="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",t=r.charAt(0),e={};for(let t=0;t<58;t++)e[r.charAt(t)]=t;exports.decodeBase58=function(r){if(0===r.length)return new Uint8Array(0);let n=0;for(;n<r.length&&r[n]===t;)n++;const o=n,l=[0];for(;n<r.length;n++){const t=r[n],o=e[t];if(void 0===o)throw new Error(`Invalid Base58 character: ${t}`);for(let r=0;r<l.length;r++)l[r]*=58;l[0]+=o;let c=0;for(let r=0;r<l.length;++r)l[r]+=c,c=l[r]>>8,l[r]&=255;for(;c;)l.push(255&c),c>>=8}const c=r.length===o?[]:l.reverse();return Uint8Array.from([...new Array(o).fill(0),...c])};
@@ -1 +0,0 @@
1
- import{d as r}from"./base58-CjvbdRzA.mjs";import{s}from"./sha256-BbwKo1_x.mjs";function t(t){try{const n=r(t);if(n.length<5)return null;const e=n.slice(0,-4),l=s(s(e));return n.slice(-4).every((r,s)=>r===l[s])?e:null}catch{return null}}export{t as d};
@@ -1 +0,0 @@
1
- "use strict";var e=require("./base58-DaLDoaS-.cjs"),r=require("./sha256-CRbh7pIK.cjs");exports.decodeBase58Check=function(s){try{const c=e.decodeBase58(s);if(c.length<5)return null;const t=c.slice(0,-4),n=r.sha256(r.sha256(t));return c.slice(-4).every((e,r)=>e===n[r])?t:null}catch{return null}};
@@ -1 +0,0 @@
1
- "use strict";var n;exports.Bech32Encoding=void 0,(n=exports.Bech32Encoding||(exports.Bech32Encoding={})).BECH32="bech32",n.BECH32M="bech32m";const t=[996825010,642813549,513874426,1027748829,705979059];function e(n,e,o){const r=o===exports.Bech32Encoding.BECH32M?734539939:1;return function(n){let e=1;for(const o of n){const n=e>>25;e=(33554431&e)<<5^o;for(let o=0;o<5;o++)n>>o&1&&(e^=t[o])}return e}(function(n){const t=[];for(let e=0;e<n.length;e++)t.push(n.charCodeAt(e)>>5);t.push(0);for(let e=0;e<n.length;e++)t.push(31&n.charCodeAt(e));return t}(n).concat(e))===r}exports.decodeBech32=function(n,t=90){if(n.length<8||n.length>t)return null;const o=n.toLowerCase();if(n!==o&&n!==n.toUpperCase())return null;const r=o.lastIndexOf("1");if(r<1||r+7>o.length)return null;const c=o.substring(0,r);if(/[^\x21-\x7E]/.test(c))return null;const s=[];for(let n=r+1;n<o.length;n++){const t="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(o[n]);if(-1===t)return null;s.push(t)}return e(c,s,exports.Bech32Encoding.BECH32)?{hrp:c,data:s.slice(0,s.length-6),encoding:exports.Bech32Encoding.BECH32}:e(c,s,exports.Bech32Encoding.BECH32M)?{hrp:c,data:s.slice(0,s.length-6),encoding:exports.Bech32Encoding.BECH32M}:null},exports.wordsToBytes=function(n){let t=0,e=0;const o=[];for(const r of n){if(!Number.isInteger(r)||r<0||r>31)return null;t=65535&(t<<5|r),e+=5,e>=8&&(e-=8,o.push(t>>>e&255))}return e>=5||t<<8-e&255?null:Uint8Array.from(o)};
@@ -1 +0,0 @@
1
- var n;!function(n){n.BECH32="bech32",n.BECH32M="bech32m"}(n||(n={}));const t=[996825010,642813549,513874426,1027748829,705979059];function e(e,r,o){const l=o===n.BECH32M?734539939:1;return function(n){let e=1;for(const r of n){const n=e>>25;e=(33554431&e)<<5^r;for(let r=0;r<5;r++)n>>r&1&&(e^=t[r])}return e}(function(n){const t=[];for(let e=0;e<n.length;e++)t.push(n.charCodeAt(e)>>5);t.push(0);for(let e=0;e<n.length;e++)t.push(31&n.charCodeAt(e));return t}(e).concat(r))===l}function r(t,r=90){if(t.length<8||t.length>r)return null;const o=t.toLowerCase();if(t!==o&&t!==t.toUpperCase())return null;const l=o.lastIndexOf("1");if(l<1||l+7>o.length)return null;const u=o.substring(0,l);if(/[^\x21-\x7E]/.test(u))return null;const s=[];for(let n=l+1;n<o.length;n++){const t="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(o[n]);if(-1===t)return null;s.push(t)}return e(u,s,n.BECH32)?{hrp:u,data:s.slice(0,s.length-6),encoding:n.BECH32}:e(u,s,n.BECH32M)?{hrp:u,data:s.slice(0,s.length-6),encoding:n.BECH32M}:null}function o(n){let t=0,e=0;const r=[];for(const o of n){if(!Number.isInteger(o)||o<0||o>31)return null;t=65535&(t<<5|o),e+=5,e>=8&&(e-=8,r.push(t>>>e&255))}return e>=5||t<<8-e&255?null:Uint8Array.from(r)}export{n as B,r as d,o as w};
@@ -1 +0,0 @@
1
- function t(t){const e=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],r=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],o=8*t.length,l=t.length,s=new Uint8Array(64-(l+8)%64+8);s[0]=128;const c=o,f=Math.floor(c/4294967296),a=c%4294967296,h=s.length;s[h-4]=a>>>24&255,s[h-3]=a>>>16&255,s[h-2]=a>>>8&255,s[h-1]=255&a,s[h-8]=f>>>24&255,s[h-7]=f>>>16&255,s[h-6]=f>>>8&255,s[h-5]=255&f;const i=new Uint8Array(l+s.length);i.set(t),i.set(s,l);const g=new Uint32Array(64);for(let t=0;t<i.length;t+=64){for(let n=0;n<16;n++)g[n]=i[t+4*n]<<24|i[t+4*n+1]<<16|i[t+4*n+2]<<8|i[t+4*n+3];for(let t=16;t<64;t++){const e=n(g[t-2],17)^n(g[t-2],19)^g[t-2]>>>10,r=n(g[t-15],7)^n(g[t-15],18)^g[t-15]>>>3;g[t]=e+g[t-7]+r+g[t-16]|0}let o=r[0],l=r[1],s=r[2],c=r[3],f=r[4],a=r[5],h=r[6],u=r[7];for(let t=0;t<64;t++){const r=u+(n(f,6)^n(f,11)^n(f,25))+(f&a^~f&h)+e[t]+g[t]|0,i=o&l^o&s^l&s;u=h,h=a,a=f,f=c+r|0,c=s,s=l,l=o,o=r+((n(o,2)^n(o,13)^n(o,22))+i|0)|0}r[0]=r[0]+o|0,r[1]=r[1]+l|0,r[2]=r[2]+s|0,r[3]=r[3]+c|0,r[4]=r[4]+f|0,r[5]=r[5]+a|0,r[6]=r[6]+h|0,r[7]=r[7]+u|0}const u=new Uint8Array(32);for(let t=0;t<8;t++)u[4*t]=r[t]>>>24&255,u[4*t+1]=r[t]>>>16&255,u[4*t+2]=r[t]>>>8&255,u[4*t+3]=255&r[t];return u}function n(t,n){return t>>>n|t<<32-n}export{t as s};
@@ -1 +0,0 @@
1
- "use strict";function t(t,n){return t>>>n|t<<32-n}exports.sha256=function(n){const e=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],r=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],o=8*n.length,s=n.length,l=new Uint8Array(64-(s+8)%64+8);l[0]=128;const c=o,f=Math.floor(c/4294967296),h=c%4294967296,i=l.length;l[i-4]=h>>>24&255,l[i-3]=h>>>16&255,l[i-2]=h>>>8&255,l[i-1]=255&h,l[i-8]=f>>>24&255,l[i-7]=f>>>16&255,l[i-6]=f>>>8&255,l[i-5]=255&f;const a=new Uint8Array(s+l.length);a.set(n),a.set(l,s);const g=new Uint32Array(64);for(let n=0;n<a.length;n+=64){for(let t=0;t<16;t++)g[t]=a[n+4*t]<<24|a[n+4*t+1]<<16|a[n+4*t+2]<<8|a[n+4*t+3];for(let n=16;n<64;n++){const e=t(g[n-2],17)^t(g[n-2],19)^g[n-2]>>>10,r=t(g[n-15],7)^t(g[n-15],18)^g[n-15]>>>3;g[n]=e+g[n-7]+r+g[n-16]|0}let o=r[0],s=r[1],l=r[2],c=r[3],f=r[4],h=r[5],i=r[6],u=r[7];for(let n=0;n<64;n++){const r=u+(t(f,6)^t(f,11)^t(f,25))+(f&h^~f&i)+e[n]+g[n]|0,a=o&s^o&l^s&l;u=i,i=h,h=f,f=c+r|0,c=l,l=s,s=o,o=r+((t(o,2)^t(o,13)^t(o,22))+a|0)|0}r[0]=r[0]+o|0,r[1]=r[1]+s|0,r[2]=r[2]+l|0,r[3]=r[3]+c|0,r[4]=r[4]+f|0,r[5]=r[5]+h|0,r[6]=r[6]+i|0,r[7]=r[7]+u|0}const u=new Uint8Array(32);for(let t=0;t<8;t++)u[4*t]=r[t]>>>24&255,u[4*t+1]=r[t]>>>16&255,u[4*t+2]=r[t]>>>8&255,u[4*t+3]=255&r[t];return u};
@@ -1 +0,0 @@
1
- "use strict";var i=require("./base-BtbJMDNm.cjs"),e=require("./base58check-CE9wLmUB.cjs"),t=require("./bech32-ClvuyXIQ.cjs");class n extends i.AddressValidator{constructor(i){super(),this.config=i}validateImplementation(t){const n=t.toLowerCase().split("1")[0];if(this.config.hrps&&Object.prototype.hasOwnProperty.call(this.config.hrps,n))return this.validateWitness(t,this.config.hrps[n]);if(t.length<26||t.length>35)return this.invalid("Invalid address length",i.ValidationError.INVALID_LENGTH);const r=e.decodeBase58Check(t);if(!r)return this.invalid("Invalid Base58Check address",i.ValidationError.INVALID_CHECKSUM);if(21!==r.length)return this.invalid("Invalid payload length",i.ValidationError.INVALID_LENGTH);const s=this.config.versions[r[0]];return s?{valid:!0,blockchain:this.config.chain,details:{format:"legacy",network:s,checksum:!0}}:this.invalid("Invalid address version")}validateWitness(e,n){const r=t.decodeBech32(e);if(!r||0===r.data.length)return this.invalid("Invalid Bech32 encoding");const s=r.data[0],a=t.wordsToBytes(r.data.slice(1));if(s>16)return this.invalid("Invalid witness version");if(!a||a.length<2||a.length>40||0===s&&20!==a.length&&32!==a.length)return this.invalid("Invalid witness program or padding",i.ValidationError.INVALID_LENGTH);const o=0===s?t.Bech32Encoding.BECH32:t.Bech32Encoding.BECH32M;if(r.encoding!==o)return this.invalid("Wrong checksum encoding for witness version",i.ValidationError.INVALID_CHECKSUM);const d=0===s?"segwit":1===s&&32===a.length?"taproot":"future";return{valid:!0,blockchain:this.config.chain,details:{format:d,network:n,checksum:!0}}}invalid(e,t=i.ValidationError.INVALID_FORMAT){return{valid:!1,error:e,details:{errorCode:t}}}}exports.UtxoValidator=n;