validator0x 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/AGENTS.md +71 -65
  2. package/CHANGELOG.md +10 -2
  3. package/README.md +13 -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.mjs +1 -1
  20. package/dist/index.umd.js +1 -1
  21. package/dist/litecoin.cjs +1 -1
  22. package/dist/litecoin.mjs +1 -1
  23. package/dist/move.cjs +1 -1
  24. package/dist/move.mjs +1 -1
  25. package/dist/near.cjs +1 -1
  26. package/dist/near.mjs +1 -1
  27. package/dist/ripple.cjs +1 -1
  28. package/dist/ripple.mjs +1 -1
  29. package/dist/shared/base-BtbJMDNm.cjs +1 -0
  30. package/dist/shared/base-D2s8b6tx.mjs +1 -0
  31. package/dist/shared/base58-CjvbdRzA.mjs +1 -0
  32. package/dist/shared/base58-DaLDoaS-.cjs +1 -0
  33. package/dist/shared/base58check-BBzwHAsr.mjs +1 -0
  34. package/dist/shared/base58check-CE9wLmUB.cjs +1 -0
  35. package/dist/shared/bech32-ClvuyXIQ.cjs +1 -0
  36. package/dist/shared/bech32-DsNhxmrB.mjs +1 -0
  37. package/dist/shared/sha256-BbwKo1_x.mjs +1 -0
  38. package/dist/shared/sha256-CRbh7pIK.cjs +1 -0
  39. package/dist/shared/utxo-CRr3-5en.mjs +1 -0
  40. package/dist/shared/utxo-DhlBlYDy.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 +9 -8
package/AGENTS.md CHANGED
@@ -1,65 +1,71 @@
1
- # validator0x: instructions for AI coding agents
2
-
3
- This file serves two audiences: agents integrating the installed npm package, and agents changing this repository. Apply only the relevant section. Read `README.md` and the installed package version before using an API. The consuming project's instructions and the user's explicit requirements take precedence.
4
-
5
- ## Integrating the npm package
6
-
7
- 1. Use the public package exports. Import from `validator0x` for multiple chains, or from a documented family entrypoint such as `validator0x/bitcoin` or `validator0x/solana` for smaller bundles. Never import private `src/` or `dist/` paths.
8
- 2. The package is synchronous and offline. It needs no API key, RPC connection, wallet connection, Node crypto polyfill, or runtime dependency. Node.js 22+ and modern ES2020 browsers/workers are supported; browser runtimes need BigInt and TextEncoder.
9
- 3. Take the intended chain from application state or the user. For dynamic chain values, narrow with `isSupportedChain` before calling `validateAddress`, `validateBatch`, or `formatAddress`; unsupported chains throw.
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
- 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
- 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.
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
- 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
- 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.
17
- 11. Keep client bundle size small: reuse a family validator instance when only one chain is needed. Do not add an entire chain SDK just to wrap these checks.
18
- 12. Add consumer tests for valid input, invalid checksum/encoding, unsupported chain input, network policy, and ambiguous detection as relevant to the integration. Use the published protocol fixtures or verified addresses rather than invented strings.
19
-
20
- ### Safe dynamic-input example
21
-
22
- ```ts
23
- import { isSupportedChain, validateAddress } from 'validator0x';
24
-
25
- export function checkRecipient(input: unknown, chain: unknown) {
26
- if (!isSupportedChain(chain)) {
27
- return { ok: false as const, error: 'Choose a supported chain' };
28
- }
29
- const result = validateAddress(input, chain, { network: 'mainnet' });
30
- if (!result.valid || typeof input !== 'string') {
31
- return { ok: false as const, error: result.error ?? 'Invalid address' };
32
- }
33
- // The application must separately verify the selected asset and actual network.
34
- return { ok: true as const, address: input.trim(), chain };
35
- }
36
- ```
37
-
38
- ### Small single-family example
39
-
40
- ```ts
41
- import { BitcoinValidator } from 'validator0x/bitcoin';
42
-
43
- const bitcoin = new BitcoinValidator();
44
- const result = bitcoin.validate('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa', {
45
- network: 'mainnet',
46
- });
47
- ```
48
-
49
- ### Discovering this file after installation
50
-
51
- The npm archive includes this file. Resolve it using `require.resolve('validator0x/AGENTS.md')` or read `node_modules/validator0x/AGENTS.md`. Merely installing a package does not guarantee that an agent automatically reads its instructions; explicitly point the agent to this file.
52
-
53
- ## Contributing to this repository
54
-
55
- - Use Node.js 22.13+ or a supported newer LTS for development. Install the locked development dependencies with `npm ci`.
56
- - Preserve zero runtime dependencies, synchronous offline behavior, and existing public exports. Never add telemetry or address logging. Cryptographic/encoding code lives in `src/utils/`; family validators in `src/validators/`; the shared registry in `src/registry.ts`; public types in `src/types.ts`.
57
- - Route validation through `AddressValidator.validate` so sanitization, options, and network policy are consistent. Preserve the 256-character bound before decoding. Check decoded version bytes, payload sizes, checksum variants, and padding rather than relying on a prefix or regex alone.
58
- - When adding chain support, verify current primary specifications. Update types, the registry, detection behavior, README scope, and positive/negative tests. Do not claim support for a chain's distinct address formats just because one format matches EVM.
59
- - When adding public entrypoints, update `package.json` exports/typesVersions, `rollup.config.mjs`, and `scripts/declarations.mjs` together. Declaration re-exports must preserve type identity across root and family imports. Keep the package-content allowlist and consumer checks in `scripts/test-package.mjs` aligned.
60
- - Keep `@noble/hashes` and `@scure/base` development-only. They are independent test oracles, not runtime imports. Test changes to hash/encoding code against independent implementations and official vectors.
61
- - Required release checks: `npm run check`, `npm run test:coverage`, and `npm audit`. `npm run check` includes lint, source/test type checking, unit tests, build, differential tests, and installation of the actual tarball into fresh consumers. Coverage includes crypto and public APIs; do not weaken coverage or size thresholds just to make a change pass.
62
- - Tests generate `.coverage/`; builds generate `dist/`; release archives end in `.tgz`. Do not commit generated output, credentials, npm tokens, or unrelated local changes. Legacy tracked `coverage/` files are not current test evidence.
63
- - Inspect `git status` before staging. Stage the intended source, tests, configuration, and documentation explicitly; preserve unrelated user edits.
64
- - For release steps, consult `RELEASING.md` in the repository. Prepare and verify the archive before asking for approval. Publishing, moving npm dist-tags, or unpublishing requires the maintainer's explicit authorization. A request to prepare a release is not permission to publish. The maintainer completes npm login and any MFA flow directly; never ask them to paste passwords, tokens, or one-time codes into the chat.
65
- - Report what was tested, package sizes, limitations, and whether changes were committed, pushed, or published. Never claim the package is bug-free or formally audited.
1
+ # validator0x: instructions for AI coding agents
2
+
3
+ This file serves two audiences: agents integrating the installed npm package, and agents changing this repository. Apply only the relevant section. Read `README.md` and the installed package version before using an API. The consuming project's instructions and the user's explicit requirements take precedence.
4
+
5
+ ## Integrating the npm package
6
+
7
+ 1. Use the public package exports. Import from `validator0x` for multiple chains, or from a documented family entrypoint such as `validator0x/bitcoin` or `validator0x/solana` for smaller bundles. Never import private `src/` or `dist/` paths.
8
+ 2. The package is synchronous and offline. It needs no API key, RPC connection, wallet connection, Node crypto polyfill, or runtime dependency. Node.js 22+ and modern ES2020 browsers/workers are supported; browser runtimes need BigInt and TextEncoder.
9
+ 3. Take the intended chain from application state or the user. For dynamic chain values, narrow with `isSupportedChain` before calling `validateAddress`, `validateBatch`, or `formatAddress`; unsupported chains throw.
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
+ 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
+ 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.
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
+ 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
+ 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.
17
+ 11. Keep client bundle size small: reuse a family validator instance when only one chain is needed. Do not add an entire chain SDK just to wrap these checks.
18
+ 12. Add consumer tests for valid input, invalid checksum/encoding, unsupported chain input, network policy, and ambiguous detection as relevant to the integration. Use the published protocol fixtures or verified addresses rather than invented strings.
19
+
20
+ ### Safe dynamic-input example
21
+
22
+ ```ts
23
+ import { EVM_CHAINS, isSupportedChain, validateAddress } from 'validator0x';
24
+
25
+ export function checkRecipient(input: unknown, chain: unknown) {
26
+ if (!isSupportedChain(chain)) {
27
+ return { ok: false as const, error: 'Choose a supported chain' };
28
+ }
29
+ const result = validateAddress(input, chain, { network: 'mainnet' });
30
+ if (!result.valid || typeof input !== 'string') {
31
+ return { ok: false as const, error: result.error ?? 'Invalid address' };
32
+ }
33
+ // The application must separately verify the selected asset and actual network.
34
+ if (chain === 'cardano' && result.details?.format === 'stake') {
35
+ return { ok: false as const, error: 'Choose a Cardano payment address' };
36
+ }
37
+ const trimmed = input.trim();
38
+ const isEvm = EVM_CHAINS.some(candidate => candidate === chain);
39
+ const destination = isEvm && !trimmed.startsWith('0x') ? '0x' + trimmed : trimmed;
40
+ return { ok: true as const, address: destination, chain };
41
+ }
42
+ ```
43
+
44
+ ### Small single-family example
45
+
46
+ ```ts
47
+ import { BitcoinValidator } from 'validator0x/bitcoin';
48
+
49
+ const bitcoin = new BitcoinValidator();
50
+ const result = bitcoin.validate('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa', {
51
+ network: 'mainnet',
52
+ });
53
+ ```
54
+
55
+ ### Discovering this file after installation
56
+
57
+ The npm archive includes this file. Resolve it using `require.resolve('validator0x/AGENTS.md')` or read `node_modules/validator0x/AGENTS.md`. Merely installing a package does not guarantee that an agent automatically reads its instructions; explicitly point the agent to this file.
58
+
59
+ ## Contributing to this repository
60
+
61
+ - Use Node.js 22.13+ or a supported newer LTS for development. Install the locked development dependencies with `npm ci`.
62
+ - Preserve zero runtime dependencies, synchronous offline behavior, and existing public exports. Never add telemetry or address logging. Cryptographic/encoding code lives in `src/utils/`; family validators in `src/validators/`; the shared registry in `src/registry.ts`; public types in `src/types.ts`.
63
+ - Route validation through `AddressValidator.validate` so sanitization, options, and network policy are consistent. Preserve the 256-character bound before decoding. Check decoded version bytes, payload sizes, checksum variants, and padding rather than relying on a prefix or regex alone.
64
+ - When adding chain support, verify current primary specifications. Update types, the registry, detection behavior, README scope, and positive/negative tests. Do not claim support for a chain's distinct address formats just because one format matches EVM.
65
+ - When adding public entrypoints, update `package.json` exports/typesVersions, `rollup.config.mjs`, and `scripts/declarations.mjs` together. Declaration re-exports must preserve type identity across root and family imports. Keep the package-content allowlist and consumer checks in `scripts/test-package.mjs` aligned.
66
+ - Keep `@noble/hashes` and `@scure/base` development-only. They are independent test oracles, not runtime imports. Test changes to hash/encoding code against independent implementations and official vectors.
67
+ - Required release checks: `npm run check`, `npm run test:coverage`, and `npm audit`. `npm run check` includes lint, source/test type checking, unit tests, build, differential tests, and installation of the actual tarball into fresh consumers. Coverage includes crypto and public APIs; do not weaken coverage or size thresholds just to make a change pass.
68
+ - Tests generate `.coverage/`; builds generate `dist/`; release archives end in `.tgz`. Do not commit generated output, credentials, npm tokens, or unrelated local changes. Legacy tracked `coverage/` files are not current test evidence.
69
+ - Inspect `git status` before staging. Stage the intended source, tests, configuration, and documentation explicitly; preserve unrelated user edits.
70
+ - For release steps, consult `RELEASING.md` in the repository. Prepare and verify the archive before asking for approval. Publishing, moving npm dist-tags, or unpublishing requires the maintainer's explicit authorization. A request to prepare a release is not permission to publish. The maintainer completes npm login and any MFA flow directly; never ask them to paste passwords, tokens, or one-time codes into the chat.
71
+ - Report what was tested, package sizes, limitations, and whether changes were committed, pushed, or published. Never claim the package is bug-free or formally audited.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # Changelog
2
2
 
3
- ## 0.3.0 - Unreleased
3
+ ## 0.4.0
4
+
5
+ - JavaScript EVM and Cosmos constructors reject unsupported family identifiers.
6
+ - Sparse batches produce an invalid result at each missing index.
7
+ - Cardano pointer fields enforce the strict ledger limits for slots and indices.
8
+ - Root and family imports share validator classes within each module format. The packed consumer checks exercise a bundled ESM family validator in a real Chrome worker.
9
+ - Payment-form examples reject Cardano reward addresses and prefix validated EVM destinations.
10
+
11
+ ## 0.3.0 - 2026-11-13
4
12
 
5
13
  ### Added
6
14
 
@@ -31,4 +39,4 @@
31
39
  - Supported Node.js baseline is 22; browsers/workers need ES2020, BigInt, and TextEncoder. Development tools require Node 22.13+ (or 24+).
32
40
  - Tests now run with Vitest. Coverage is generated in `.coverage/` and includes crypto and the public API. Generated legacy coverage is not used as evidence of current coverage.
33
41
 
34
- This version is prepared locally; publication is a separate release action.
42
+ Published to the public npm registry with the `latest` tag. Registry integrity matched the approved archive; a fresh registry install passed the CommonJS/ESM entrypoints and agent-instruction discovery checks.
package/README.md CHANGED
@@ -6,7 +6,7 @@ Validation checks address encoding, payload structure, and checksums where the f
6
6
 
7
7
  ## Install and use
8
8
 
9
- This branch documents the upcoming **0.3.0** release. Until it is published, the registry's `latest` version may differ. For a local preview, install the prepared `validator0x-0.3.0.tgz` archive. See [migration notes](./CHANGELOG.md) before upgrading from 0.2.x.
9
+ Install `validator0x` for the latest published release. See [migration notes](./CHANGELOG.md) before upgrading from 0.2.x.
10
10
 
11
11
  ```sh
12
12
  npm install validator0x
@@ -44,7 +44,7 @@ const { validateAddress } = require('validator0x');
44
44
  Keep chain selection explicit. For an API request or form whose values are not already typed, validate the chain before validating the address:
45
45
 
46
46
  ```ts
47
- import { isSupportedChain, validateAddress } from 'validator0x';
47
+ import { EVM_CHAINS, isSupportedChain, validateAddress } from 'validator0x';
48
48
 
49
49
  export function checkRecipient(address: unknown, chain: unknown) {
50
50
  if (!isSupportedChain(chain)) {
@@ -54,7 +54,13 @@ 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
- return { ok: true as const, address: address.trim(), chain };
57
+ if (chain === 'cardano' && result.details?.format === 'stake') {
58
+ return { ok: false as const, error: 'Choose a Cardano payment address' };
59
+ }
60
+ const trimmed = address.trim();
61
+ const isEvm = EVM_CHAINS.some(candidate => candidate === chain);
62
+ const destination = isEvm && !trimmed.startsWith('0x') ? '0x' + trimmed : trimmed;
63
+ return { ok: true as const, address: destination, chain };
58
64
  }
59
65
  ```
60
66
 
@@ -113,7 +119,7 @@ All direct imports support ESM, CommonJS, and TypeScript:
113
119
 
114
120
  For example, `new CosmosValidator('osmosis')` or `new EvmValidator('sonic')`. Existing validator classes, including `PolygonValidator`, remain available from the root import.
115
121
 
116
- The full minified ESM bundle is approximately **6.8 kB gzip**, and the Solana-only entry approximately **1.2 kB gzip**. `npm run test:package` prints exact sizes and enforces budgets of 12 kB and 3 kB respectively. Runtime dependencies, RPC requests, polyfills, and chain SDKs: **none**. Root imports include the chain registry; direct imports exclude unrelated validators.
122
+ The full minified ESM bundle is approximately **7.2 kB gzip**, and the Solana-only entry approximately **1.2 kB gzip**. `npm run test:package` prints exact sizes and enforces budgets of 12 kB and 3 kB respectively. Runtime dependencies, RPC requests, polyfills, and chain SDKs: **none**. These sizes include shared modules. Root and family imports share validator constructors within each module format.
117
123
 
118
124
  ## Supported address formats
119
125
 
@@ -188,6 +194,8 @@ Formatting is for display, not validation. Never send to a shortened address. `s
188
194
 
189
195
  ## Development and verification
190
196
 
197
+ The packed browser test uses an installed Google Chrome stable browser. On a development host without Chrome, install it with `npx playwright-core install chrome` after `npm ci`.
198
+
191
199
  ```sh
192
200
  npm ci
193
201
  npm run check # lint, type checks, tests, build, differential and packed-consumer checks
@@ -201,7 +209,7 @@ For maintainers, `npm run prepare:release` runs the release checks and creates t
201
209
 
202
210
  Tests include the complete native witness vectors from [BIP-350](https://bips.dev/350/), Shelley/stake vectors from [CIP-19](https://cips.cardano.org/cip/CIP-19), and EIP-55 checksum cases. Differential checks compare SHA-256 to Node crypto, Keccak-256 to `@noble/hashes`, and Base58/Bech32 to `@scure/base` across block boundaries, address versions, payload lengths, and malformed cases. Reference libraries are development-only dependencies.
203
211
 
204
- Package checks install the actual tarball into a temporary consumer and verify all ESM/CommonJS entrypoints, TypeScript NodeNext/Bundler/legacy resolution, and UMD execution without Node globals. CI runs on Linux and Windows with Node 22, 24, and 26. Local checks do not substitute for executing that CI matrix.
212
+ Package checks install the actual tarball into a temporary consumer and verify all ESM/CommonJS entrypoints, TypeScript NodeNext/Bundler/legacy resolution, UMD execution without Node globals, and a bundled Solana ESM consumer in a real Chrome module worker. CI runs on Linux and Windows with Node 22, 24, and 26. Local checks do not substitute for executing that CI matrix.
205
213
 
206
214
  The development-only `minimatch` override selects the patched 11.x release for the lint dependency tree; remove it once upstream ranges include the fix. Runtime consumers do not install it.
207
215
 
package/dist/bitcoin.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t;!function(t){t.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"}(t||(t={}));class n{static sanitize(n){if(null==n)throw new Error(t.UNSAFE_INPUT);if("string"!=typeof n)throw new Error(t.UNSAFE_INPUT);if(n.length>256)throw new Error(t.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(n))throw new Error(t.UNSAFE_INPUT);return n.trim()}}class e{validate(e,r){try{const i=n.sanitize(e),o=this.validateImplementation(i,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.NETWORK_MISMATCH}}:o}catch(n){const e=n instanceof Error?n.message:String(n);return e===t.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.UNSAFE_INPUT}}:{valid:!1,error:e,details:{errorCode:t.INVALID_FORMAT}}}}format(t,e){return function(t,e,r=4){const i=n.sanitize(t);if(!e?.shorten)return i;const o=e.shortenLength??r;if(!Number.isSafeInteger(o)||o<1)throw new RangeError("shortenLength must be a positive integer");const s=i.startsWith("0x")?2:0;return i.length<=2*o+s+3?i:`${i.slice(0,o+s)}...${i.slice(-o)}`}(t,e)}}const r="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",i=r.charAt(0),o={};for(let t=0;t<58;t++)o[r.charAt(t)]=t;function s(t){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],e=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],r=8*t.length,i=t.length,o=new Uint8Array(64-(i+8)%64+8);o[0]=128;const s=r,a=Math.floor(s/4294967296),c=s%4294967296,h=o.length;o[h-4]=c>>>24&255,o[h-3]=c>>>16&255,o[h-2]=c>>>8&255,o[h-1]=255&c,o[h-8]=a>>>24&255,o[h-7]=a>>>16&255,o[h-6]=a>>>8&255,o[h-5]=255&a;const u=new Uint8Array(i+o.length);u.set(t),u.set(o,i);const f=new Uint32Array(64);for(let t=0;t<u.length;t+=64){for(let n=0;n<16;n++)f[n]=u[t+4*n]<<24|u[t+4*n+1]<<16|u[t+4*n+2]<<8|u[t+4*n+3];for(let t=16;t<64;t++){const n=l(f[t-2],17)^l(f[t-2],19)^f[t-2]>>>10,e=l(f[t-15],7)^l(f[t-15],18)^f[t-15]>>>3;f[t]=n+f[t-7]+e+f[t-16]|0}let r=e[0],i=e[1],o=e[2],s=e[3],a=e[4],c=e[5],h=e[6],d=e[7];for(let t=0;t<64;t++){const e=d+(l(a,6)^l(a,11)^l(a,25))+(a&c^~a&h)+n[t]+f[t]|0,u=r&i^r&o^i&o;d=h,h=c,c=a,a=s+e|0,s=o,o=i,i=r,r=e+((l(r,2)^l(r,13)^l(r,22))+u|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]+a|0,e[5]=e[5]+c|0,e[6]=e[6]+h|0,e[7]=e[7]+d|0}const d=new Uint8Array(32);for(let t=0;t<8;t++)d[4*t]=e[t]>>>24&255,d[4*t+1]=e[t]>>>16&255,d[4*t+2]=e[t]>>>8&255,d[4*t+3]=255&e[t];return d}function l(t,n){return t>>>n|t<<32-n}function a(t){try{const n=function(t){if(0===t.length)return new Uint8Array(0);let n=0;for(;n<t.length&&t[n]===i;)n++;const e=n,r=[0];for(;n<t.length;n++){const e=t[n],i=o[e];if(void 0===i)throw new Error(`Invalid Base58 character: ${e}`);for(let t=0;t<r.length;t++)r[t]*=58;r[0]+=i;let s=0;for(let t=0;t<r.length;++t)r[t]+=s,s=r[t]>>8,r[t]&=255;for(;s;)r.push(255&s),s>>=8}const s=t.length===e?[]:r.reverse();return Uint8Array.from([...new Array(e).fill(0),...s])}(t);if(n.length<5)return null;const e=n.slice(0,-4),r=s(s(e));return n.slice(-4).every((t,n)=>t===r[n])?e:null}catch{return null}}var c;!function(t){t.BECH32="bech32",t.BECH32M="bech32m"}(c||(c={}));const h=[996825010,642813549,513874426,1027748829,705979059];function u(t,n,e){const r=e===c.BECH32M?734539939:1;return function(t){let n=1;for(const e of t){const t=n>>25;n=(33554431&n)<<5^e;for(let e=0;e<5;e++)t>>e&1&&(n^=h[e])}return n}(function(t){const n=[];for(let e=0;e<t.length;e++)n.push(t.charCodeAt(e)>>5);n.push(0);for(let e=0;e<t.length;e++)n.push(31&t.charCodeAt(e));return n}(t).concat(n))===r}class f extends e{constructor(t){super(),this.config=t}validateImplementation(n){const e=n.toLowerCase().split("1")[0];if(this.config.hrps&&Object.prototype.hasOwnProperty.call(this.config.hrps,e))return this.validateWitness(n,this.config.hrps[e]);if(n.length<26||n.length>35)return this.invalid("Invalid address length",t.INVALID_LENGTH);const r=a(n);if(!r)return this.invalid("Invalid Base58Check address",t.INVALID_CHECKSUM);if(21!==r.length)return this.invalid("Invalid payload length",t.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(n,e){const r=function(t,n=90){if(t.length<8||t.length>n)return null;const e=t.toLowerCase();if(t!==e&&t!==t.toUpperCase())return null;const r=e.lastIndexOf("1");if(r<1||r+7>e.length)return null;const i=e.substring(0,r);if(/[^\x21-\x7E]/.test(i))return null;const o=[];for(let t=r+1;t<e.length;t++){const n="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(e[t]);if(-1===n)return null;o.push(n)}return u(i,o,c.BECH32)?{hrp:i,data:o.slice(0,o.length-6),encoding:c.BECH32}:u(i,o,c.BECH32M)?{hrp:i,data:o.slice(0,o.length-6),encoding:c.BECH32M}:null}(n);if(!r||0===r.data.length)return this.invalid("Invalid Bech32 encoding");const i=r.data[0],o=function(t){let n=0,e=0;const r=[];for(const i of t){if(!Number.isInteger(i)||i<0||i>31)return null;n=65535&(n<<5|i),e+=5,e>=8&&(e-=8,r.push(n>>>e&255))}return e>=5||n<<8-e&255?null:Uint8Array.from(r)}(r.data.slice(1));if(i>16)return this.invalid("Invalid witness version");if(!o||o.length<2||o.length>40||0===i&&20!==o.length&&32!==o.length)return this.invalid("Invalid witness program or padding",t.INVALID_LENGTH);const s=0===i?c.BECH32:c.BECH32M;if(r.encoding!==s)return this.invalid("Wrong checksum encoding for witness version",t.INVALID_CHECKSUM);const l=0===i?"segwit":1===i&&32===o.length?"taproot":"future";return{valid:!0,blockchain:this.config.chain,details:{format:l,network:e,checksum:!0}}}invalid(n,e=t.INVALID_FORMAT){return{valid:!1,error:n,details:{errorCode:e}}}}exports.BitcoinValidator=class extends f{constructor(){super({chain:"bitcoin",versions:{0:"mainnet",5:"mainnet",111:"testnet",196:"testnet"},hrps:{bc:"mainnet",tb:"testnet"}})}};
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;
package/dist/bitcoin.mjs CHANGED
@@ -1 +1 @@
1
- var t;!function(t){t.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"}(t||(t={}));class n{static sanitize(n){if(null==n)throw new Error(t.UNSAFE_INPUT);if("string"!=typeof n)throw new Error(t.UNSAFE_INPUT);if(n.length>256)throw new Error(t.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(n))throw new Error(t.UNSAFE_INPUT);return n.trim()}}class e{validate(e,r){try{const i=n.sanitize(e),o=this.validateImplementation(i,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.NETWORK_MISMATCH}}:o}catch(n){const e=n instanceof Error?n.message:String(n);return e===t.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.UNSAFE_INPUT}}:{valid:!1,error:e,details:{errorCode:t.INVALID_FORMAT}}}}format(t,e){return function(t,e,r=4){const i=n.sanitize(t);if(!e?.shorten)return i;const o=e.shortenLength??r;if(!Number.isSafeInteger(o)||o<1)throw new RangeError("shortenLength must be a positive integer");const s=i.startsWith("0x")?2:0;return i.length<=2*o+s+3?i:`${i.slice(0,o+s)}...${i.slice(-o)}`}(t,e)}}const r="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",i=r.charAt(0),o={};for(let t=0;t<58;t++)o[r.charAt(t)]=t;function s(t){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],e=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],r=8*t.length,i=t.length,o=new Uint8Array(64-(i+8)%64+8);o[0]=128;const s=r,a=Math.floor(s/4294967296),c=s%4294967296,h=o.length;o[h-4]=c>>>24&255,o[h-3]=c>>>16&255,o[h-2]=c>>>8&255,o[h-1]=255&c,o[h-8]=a>>>24&255,o[h-7]=a>>>16&255,o[h-6]=a>>>8&255,o[h-5]=255&a;const u=new Uint8Array(i+o.length);u.set(t),u.set(o,i);const f=new Uint32Array(64);for(let t=0;t<u.length;t+=64){for(let n=0;n<16;n++)f[n]=u[t+4*n]<<24|u[t+4*n+1]<<16|u[t+4*n+2]<<8|u[t+4*n+3];for(let t=16;t<64;t++){const n=l(f[t-2],17)^l(f[t-2],19)^f[t-2]>>>10,e=l(f[t-15],7)^l(f[t-15],18)^f[t-15]>>>3;f[t]=n+f[t-7]+e+f[t-16]|0}let r=e[0],i=e[1],o=e[2],s=e[3],a=e[4],c=e[5],h=e[6],d=e[7];for(let t=0;t<64;t++){const e=d+(l(a,6)^l(a,11)^l(a,25))+(a&c^~a&h)+n[t]+f[t]|0,u=r&i^r&o^i&o;d=h,h=c,c=a,a=s+e|0,s=o,o=i,i=r,r=e+((l(r,2)^l(r,13)^l(r,22))+u|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]+a|0,e[5]=e[5]+c|0,e[6]=e[6]+h|0,e[7]=e[7]+d|0}const d=new Uint8Array(32);for(let t=0;t<8;t++)d[4*t]=e[t]>>>24&255,d[4*t+1]=e[t]>>>16&255,d[4*t+2]=e[t]>>>8&255,d[4*t+3]=255&e[t];return d}function l(t,n){return t>>>n|t<<32-n}function a(t){try{const n=function(t){if(0===t.length)return new Uint8Array(0);let n=0;for(;n<t.length&&t[n]===i;)n++;const e=n,r=[0];for(;n<t.length;n++){const e=t[n],i=o[e];if(void 0===i)throw new Error(`Invalid Base58 character: ${e}`);for(let t=0;t<r.length;t++)r[t]*=58;r[0]+=i;let s=0;for(let t=0;t<r.length;++t)r[t]+=s,s=r[t]>>8,r[t]&=255;for(;s;)r.push(255&s),s>>=8}const s=t.length===e?[]:r.reverse();return Uint8Array.from([...new Array(e).fill(0),...s])}(t);if(n.length<5)return null;const e=n.slice(0,-4),r=s(s(e));return n.slice(-4).every((t,n)=>t===r[n])?e:null}catch{return null}}var c;!function(t){t.BECH32="bech32",t.BECH32M="bech32m"}(c||(c={}));const h=[996825010,642813549,513874426,1027748829,705979059];function u(t,n,e){const r=e===c.BECH32M?734539939:1;return function(t){let n=1;for(const e of t){const t=n>>25;n=(33554431&n)<<5^e;for(let e=0;e<5;e++)t>>e&1&&(n^=h[e])}return n}(function(t){const n=[];for(let e=0;e<t.length;e++)n.push(t.charCodeAt(e)>>5);n.push(0);for(let e=0;e<t.length;e++)n.push(31&t.charCodeAt(e));return n}(t).concat(n))===r}class f extends e{constructor(t){super(),this.config=t}validateImplementation(n){const e=n.toLowerCase().split("1")[0];if(this.config.hrps&&Object.prototype.hasOwnProperty.call(this.config.hrps,e))return this.validateWitness(n,this.config.hrps[e]);if(n.length<26||n.length>35)return this.invalid("Invalid address length",t.INVALID_LENGTH);const r=a(n);if(!r)return this.invalid("Invalid Base58Check address",t.INVALID_CHECKSUM);if(21!==r.length)return this.invalid("Invalid payload length",t.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(n,e){const r=function(t,n=90){if(t.length<8||t.length>n)return null;const e=t.toLowerCase();if(t!==e&&t!==t.toUpperCase())return null;const r=e.lastIndexOf("1");if(r<1||r+7>e.length)return null;const i=e.substring(0,r);if(/[^\x21-\x7E]/.test(i))return null;const o=[];for(let t=r+1;t<e.length;t++){const n="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(e[t]);if(-1===n)return null;o.push(n)}return u(i,o,c.BECH32)?{hrp:i,data:o.slice(0,o.length-6),encoding:c.BECH32}:u(i,o,c.BECH32M)?{hrp:i,data:o.slice(0,o.length-6),encoding:c.BECH32M}:null}(n);if(!r||0===r.data.length)return this.invalid("Invalid Bech32 encoding");const i=r.data[0],o=function(t){let n=0,e=0;const r=[];for(const i of t){if(!Number.isInteger(i)||i<0||i>31)return null;n=65535&(n<<5|i),e+=5,e>=8&&(e-=8,r.push(n>>>e&255))}return e>=5||n<<8-e&255?null:Uint8Array.from(r)}(r.data.slice(1));if(i>16)return this.invalid("Invalid witness version");if(!o||o.length<2||o.length>40||0===i&&20!==o.length&&32!==o.length)return this.invalid("Invalid witness program or padding",t.INVALID_LENGTH);const s=0===i?c.BECH32:c.BECH32M;if(r.encoding!==s)return this.invalid("Wrong checksum encoding for witness version",t.INVALID_CHECKSUM);const l=0===i?"segwit":1===i&&32===o.length?"taproot":"future";return{valid:!0,blockchain:this.config.chain,details:{format:l,network:e,checksum:!0}}}invalid(n,e=t.INVALID_FORMAT){return{valid:!1,error:n,details:{errorCode:e}}}}class d extends f{constructor(){super({chain:"bitcoin",versions:{0:"mainnet",5:"mainnet",111:"testnet",196:"testnet"},hrps:{bc:"mainnet",tb:"testnet"}})}}export{d as BitcoinValidator};
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};
package/dist/cardano.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t;!function(t){t.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"}(t||(t={}));class e{static sanitize(e){if(null==e)throw new Error(t.UNSAFE_INPUT);if("string"!=typeof e)throw new Error(t.UNSAFE_INPUT);if(e.length>256)throw new Error(t.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(e))throw new Error(t.UNSAFE_INPUT);return e.trim()}}class n{validate(n,r){try{const o=e.sanitize(n),s=this.validateImplementation(o,r),i=s.details?.network;return s.valid&&i&&(r?.network&&"auto"!==r.network&&r.network!==i||!1===r?.allowTestnet&&"testnet"===i)?{valid:!1,error:"Address network does not match the requested network",details:{...s.details,errorCode:t.NETWORK_MISMATCH}}:s}catch(e){const n=e instanceof Error?e.message:String(e);return n===t.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.UNSAFE_INPUT}}:{valid:!1,error:n,details:{errorCode:t.INVALID_FORMAT}}}}format(t,e){return r(t,e)}}function r(t,n,r=4){const o=e.sanitize(t);if(!n?.shorten)return o;const s=n.shortenLength??r;if(!Number.isSafeInteger(s)||s<1)throw new RangeError("shortenLength must be a positive integer");const i=o.startsWith("0x")?2:0;return o.length<=2*s+i+3?o:`${o.slice(0,s+i)}...${o.slice(-s)}`}const o="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",s=o.charAt(0),i={};for(let t=0;t<58;t++)i[o.charAt(t)]=t;var l;!function(t){t.BECH32="bech32",t.BECH32M="bech32m"}(l||(l={}));const a=[996825010,642813549,513874426,1027748829,705979059];function f(t,e,n){const r=n===l.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^=a[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}class h{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 o=0;for(let t=0;t<r;t++)o=256*o+this.data[this.offset++];return o}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")}}exports.CardanoValidator=class extends n{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 o=r.head(5);if(o>n.length)return null;const s=new Set;let i="mainnet";for(let t=0;t<o;t++){const t=r.head(0);if(s.has(t)||t>255)return null;s.add(t);const e=r.bytes();if(1===t){const t=new h(e);if(28!==t.bytes().length)return null;t.end()}if(2===t){const t=new h(e);t.head(0),t.end(),i="testnet"}}const l=r.head(0);return 0!==l&&2!==l?null:(r.end(),i)}catch{return null}}(function(t){if(0===t.length)return new Uint8Array(0);let e=0;for(;e<t.length&&t[e]===s;)e++;const n=e,r=[0];for(;e<t.length;e++){const n=t[e],o=i[n];if(void 0===o)throw new Error(`Invalid Base58 character: ${n}`);for(let t=0;t<r.length;t++)r[t]*=58;r[0]+=o;let s=0;for(let t=0;t<r.length;++t)r[t]+=s,s=r[t]>>8,r[t]&=255;for(;s;)r.push(255&s),s>>=8}const o=t.length===n?[]:r.reverse();return Uint8Array.from([...new Array(n).fill(0),...o])}(t));if(e)return{valid:!0,blockchain:"cardano",details:{format:"byron",network:e,checksum:!0}}}catch{}return this.invalid()}validateShelley(t){const e=function(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 o=n.substring(0,r);if(/[^\x21-\x7E]/.test(o))return null;const s=[];for(let t=r+1;t<n.length;t++){const e="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(n[t]);if(-1===e)return null;s.push(e)}return f(o,s,l.BECH32)?{hrp:o,data:s.slice(0,s.length-6),encoding:l.BECH32}:f(o,s,l.BECH32M)?{hrp:o,data:s.slice(0,s.length-6),encoding:l.BECH32M}:null}(t,256),n=e&&function(t){let e=0,n=0;const r=[];for(const o of t){if(!Number.isInteger(o)||o<0||o>31)return null;e=65535&(e<<5|o),n+=5,n>=8&&(n-=8,r.push(e>>>n&255))}return n>=5||e<<8-n&255?null:Uint8Array.from(r)}(e.data);if(!e||e.encoding!==l.BECH32||!n?.length)return this.invalid();const r=n[0]>>>4,o=15&n[0];if(0!==o&&1!==o)return this.invalid();const s=14===r||15===r,i=(s?"stake":"addr")+(0===o?"_test":"");if(e.hrp!==i)return this.invalid();let a=!1;return r<=3?a=57===n.length:6===r||7===r||s?a=29===n.length:4!==r&&5!==r||(a=this.validPointer(n)),a?{valid:!0,blockchain:"cardano",details:{format:s?"stake":"shelley",network:1===o?"mainnet":"testnet",checksum:!0}}:this.invalid()}validPointer(t){let e=29;for(let n=0;n<3;n++){let n=0n;const r=e;do{if(e>=t.length||e-r>=10)return!1;n=n<<7n|BigInt(127&t[e])}while(128&t[e++]);if(e-r>1&&128===t[r]||n>0xffffffffffffffffn)return!1}return e===t.length}invalid(){return{valid:!1,error:"Invalid Cardano address structure, network, or checksum",details:{errorCode:t.INVALID_FORMAT}}}format(t,e){return r(t,e,8)}};
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;
package/dist/cardano.mjs CHANGED
@@ -1 +1 @@
1
- var t;!function(t){t.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"}(t||(t={}));class e{static sanitize(e){if(null==e)throw new Error(t.UNSAFE_INPUT);if("string"!=typeof e)throw new Error(t.UNSAFE_INPUT);if(e.length>256)throw new Error(t.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(e))throw new Error(t.UNSAFE_INPUT);return e.trim()}}class n{validate(n,r){try{const o=e.sanitize(n),s=this.validateImplementation(o,r),i=s.details?.network;return s.valid&&i&&(r?.network&&"auto"!==r.network&&r.network!==i||!1===r?.allowTestnet&&"testnet"===i)?{valid:!1,error:"Address network does not match the requested network",details:{...s.details,errorCode:t.NETWORK_MISMATCH}}:s}catch(e){const n=e instanceof Error?e.message:String(e);return n===t.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.UNSAFE_INPUT}}:{valid:!1,error:n,details:{errorCode:t.INVALID_FORMAT}}}}format(t,e){return r(t,e)}}function r(t,n,r=4){const o=e.sanitize(t);if(!n?.shorten)return o;const s=n.shortenLength??r;if(!Number.isSafeInteger(s)||s<1)throw new RangeError("shortenLength must be a positive integer");const i=o.startsWith("0x")?2:0;return o.length<=2*s+i+3?o:`${o.slice(0,s+i)}...${o.slice(-s)}`}const o="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",s=o.charAt(0),i={};for(let t=0;t<58;t++)i[o.charAt(t)]=t;var l;!function(t){t.BECH32="bech32",t.BECH32M="bech32m"}(l||(l={}));const a=[996825010,642813549,513874426,1027748829,705979059];function f(t,e,n){const r=n===l.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^=a[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}class h{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 o=0;for(let t=0;t<r;t++)o=256*o+this.data[this.offset++];return o}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 c extends n{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 o=r.head(5);if(o>n.length)return null;const s=new Set;let i="mainnet";for(let t=0;t<o;t++){const t=r.head(0);if(s.has(t)||t>255)return null;s.add(t);const e=r.bytes();if(1===t){const t=new h(e);if(28!==t.bytes().length)return null;t.end()}if(2===t){const t=new h(e);t.head(0),t.end(),i="testnet"}}const l=r.head(0);return 0!==l&&2!==l?null:(r.end(),i)}catch{return null}}(function(t){if(0===t.length)return new Uint8Array(0);let e=0;for(;e<t.length&&t[e]===s;)e++;const n=e,r=[0];for(;e<t.length;e++){const n=t[e],o=i[n];if(void 0===o)throw new Error(`Invalid Base58 character: ${n}`);for(let t=0;t<r.length;t++)r[t]*=58;r[0]+=o;let s=0;for(let t=0;t<r.length;++t)r[t]+=s,s=r[t]>>8,r[t]&=255;for(;s;)r.push(255&s),s>>=8}const o=t.length===n?[]:r.reverse();return Uint8Array.from([...new Array(n).fill(0),...o])}(t));if(e)return{valid:!0,blockchain:"cardano",details:{format:"byron",network:e,checksum:!0}}}catch{}return this.invalid()}validateShelley(t){const e=function(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 o=n.substring(0,r);if(/[^\x21-\x7E]/.test(o))return null;const s=[];for(let t=r+1;t<n.length;t++){const e="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(n[t]);if(-1===e)return null;s.push(e)}return f(o,s,l.BECH32)?{hrp:o,data:s.slice(0,s.length-6),encoding:l.BECH32}:f(o,s,l.BECH32M)?{hrp:o,data:s.slice(0,s.length-6),encoding:l.BECH32M}:null}(t,256),n=e&&function(t){let e=0,n=0;const r=[];for(const o of t){if(!Number.isInteger(o)||o<0||o>31)return null;e=65535&(e<<5|o),n+=5,n>=8&&(n-=8,r.push(e>>>n&255))}return n>=5||e<<8-n&255?null:Uint8Array.from(r)}(e.data);if(!e||e.encoding!==l.BECH32||!n?.length)return this.invalid();const r=n[0]>>>4,o=15&n[0];if(0!==o&&1!==o)return this.invalid();const s=14===r||15===r,i=(s?"stake":"addr")+(0===o?"_test":"");if(e.hrp!==i)return this.invalid();let a=!1;return r<=3?a=57===n.length:6===r||7===r||s?a=29===n.length:4!==r&&5!==r||(a=this.validPointer(n)),a?{valid:!0,blockchain:"cardano",details:{format:s?"stake":"shelley",network:1===o?"mainnet":"testnet",checksum:!0}}:this.invalid()}validPointer(t){let e=29;for(let n=0;n<3;n++){let n=0n;const r=e;do{if(e>=t.length||e-r>=10)return!1;n=n<<7n|BigInt(127&t[e])}while(128&t[e++]);if(e-r>1&&128===t[r]||n>0xffffffffffffffffn)return!1}return e===t.length}invalid(){return{valid:!1,error:"Invalid Cardano address structure, network, or checksum",details:{errorCode:t.INVALID_FORMAT}}}format(t,e){return r(t,e,8)}}export{c as CardanoValidator};
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};
package/dist/cosmos.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t;!function(t){t.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"}(t||(t={}));class e{static sanitize(e){if(null==e)throw new Error(t.UNSAFE_INPUT);if("string"!=typeof e)throw new Error(t.UNSAFE_INPUT);if(e.length>256)throw new Error(t.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(e))throw new Error(t.UNSAFE_INPUT);return e.trim()}}class n{validate(n,r){try{const o=e.sanitize(n),s=this.validateImplementation(o,r),i=s.details?.network;return s.valid&&i&&(r?.network&&"auto"!==r.network&&r.network!==i||!1===r?.allowTestnet&&"testnet"===i)?{valid:!1,error:"Address network does not match the requested network",details:{...s.details,errorCode:t.NETWORK_MISMATCH}}:s}catch(e){const n=e instanceof Error?e.message:String(e);return n===t.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.UNSAFE_INPUT}}:{valid:!1,error:n,details:{errorCode:t.INVALID_FORMAT}}}}format(t,n){return function(t,n,r=4){const o=e.sanitize(t);if(!n?.shorten)return o;const s=n.shortenLength??r;if(!Number.isSafeInteger(s)||s<1)throw new RangeError("shortenLength must be a positive integer");const i=o.startsWith("0x")?2:0;return o.length<=2*s+i+3?o:`${o.slice(0,s+i)}...${o.slice(-s)}`}(t,n)}}var r;!function(t){t.BECH32="bech32",t.BECH32M="bech32m"}(r||(r={}));const o=[996825010,642813549,513874426,1027748829,705979059];function s(t,e,n){const s=n===r.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^=o[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))===s}const i={cosmos:"cosmos",osmosis:"osmo",celestia:"celestia",injective:"inj",sei:"sei"};exports.CosmosValidator=class extends n{constructor(t="cosmos"){super(),this.chain=t}validateImplementation(e){const n=function(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 o=n.lastIndexOf("1");if(o<1||o+7>n.length)return null;const i=n.substring(0,o);if(/[^\x21-\x7E]/.test(i))return null;const c=[];for(let t=o+1;t<n.length;t++){const e="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(n[t]);if(-1===e)return null;c.push(e)}return s(i,c,r.BECH32)?{hrp:i,data:c.slice(0,c.length-6),encoding:r.BECH32}:s(i,c,r.BECH32M)?{hrp:i,data:c.slice(0,c.length-6),encoding:r.BECH32M}:null}(e),o=n&&function(t){let e=0,n=0;const r=[];for(const o of t){if(!Number.isInteger(o)||o<0||o>31)return null;e=65535&(e<<5|o),n+=5,n>=8&&(n-=8,r.push(e>>>n&255))}return n>=5||e<<8-n&255?null:Uint8Array.from(r)}(n.data),c="injective"===this.chain||"celestia"===this.chain?[20]:[20,32];return n&&n.hrp===i[this.chain]&&n.encoding===r.BECH32&&o&&c.includes(o.length)?{valid:!0,blockchain:this.chain,details:{format:"bech32",checksum:!0}}:{valid:!1,error:"Invalid account prefix, checksum, length, or padding",details:{errorCode:t.INVALID_FORMAT}}}};
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;
package/dist/cosmos.mjs CHANGED
@@ -1 +1 @@
1
- var t;!function(t){t.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"}(t||(t={}));class e{static sanitize(e){if(null==e)throw new Error(t.UNSAFE_INPUT);if("string"!=typeof e)throw new Error(t.UNSAFE_INPUT);if(e.length>256)throw new Error(t.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(e))throw new Error(t.UNSAFE_INPUT);return e.trim()}}class n{validate(n,r){try{const o=e.sanitize(n),s=this.validateImplementation(o,r),i=s.details?.network;return s.valid&&i&&(r?.network&&"auto"!==r.network&&r.network!==i||!1===r?.allowTestnet&&"testnet"===i)?{valid:!1,error:"Address network does not match the requested network",details:{...s.details,errorCode:t.NETWORK_MISMATCH}}:s}catch(e){const n=e instanceof Error?e.message:String(e);return n===t.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.UNSAFE_INPUT}}:{valid:!1,error:n,details:{errorCode:t.INVALID_FORMAT}}}}format(t,n){return function(t,n,r=4){const o=e.sanitize(t);if(!n?.shorten)return o;const s=n.shortenLength??r;if(!Number.isSafeInteger(s)||s<1)throw new RangeError("shortenLength must be a positive integer");const i=o.startsWith("0x")?2:0;return o.length<=2*s+i+3?o:`${o.slice(0,s+i)}...${o.slice(-s)}`}(t,n)}}var r;!function(t){t.BECH32="bech32",t.BECH32M="bech32m"}(r||(r={}));const o=[996825010,642813549,513874426,1027748829,705979059];function s(t,e,n){const s=n===r.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^=o[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))===s}const i={cosmos:"cosmos",osmosis:"osmo",celestia:"celestia",injective:"inj",sei:"sei"};class c extends n{constructor(t="cosmos"){super(),this.chain=t}validateImplementation(e){const n=function(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 o=n.lastIndexOf("1");if(o<1||o+7>n.length)return null;const i=n.substring(0,o);if(/[^\x21-\x7E]/.test(i))return null;const c=[];for(let t=o+1;t<n.length;t++){const e="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(n[t]);if(-1===e)return null;c.push(e)}return s(i,c,r.BECH32)?{hrp:i,data:c.slice(0,c.length-6),encoding:r.BECH32}:s(i,c,r.BECH32M)?{hrp:i,data:c.slice(0,c.length-6),encoding:r.BECH32M}:null}(e),o=n&&function(t){let e=0,n=0;const r=[];for(const o of t){if(!Number.isInteger(o)||o<0||o>31)return null;e=65535&(e<<5|o),n+=5,n>=8&&(n-=8,r.push(e>>>n&255))}return n>=5||e<<8-n&255?null:Uint8Array.from(r)}(n.data),c="injective"===this.chain||"celestia"===this.chain?[20]:[20,32];return n&&n.hrp===i[this.chain]&&n.encoding===r.BECH32&&o&&c.includes(o.length)?{valid:!0,blockchain:this.chain,details:{format:"bech32",checksum:!0}}:{valid:!1,error:"Invalid account prefix, checksum, length, or padding",details:{errorCode:t.INVALID_FORMAT}}}}export{c as CosmosValidator};
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};
package/dist/dogecoin.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t;!function(t){t.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"}(t||(t={}));class n{static sanitize(n){if(null==n)throw new Error(t.UNSAFE_INPUT);if("string"!=typeof n)throw new Error(t.UNSAFE_INPUT);if(n.length>256)throw new Error(t.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(n))throw new Error(t.UNSAFE_INPUT);return n.trim()}}class e{validate(e,r){try{const i=n.sanitize(e),o=this.validateImplementation(i,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.NETWORK_MISMATCH}}:o}catch(n){const e=n instanceof Error?n.message:String(n);return e===t.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.UNSAFE_INPUT}}:{valid:!1,error:e,details:{errorCode:t.INVALID_FORMAT}}}}format(t,e){return function(t,e,r=4){const i=n.sanitize(t);if(!e?.shorten)return i;const o=e.shortenLength??r;if(!Number.isSafeInteger(o)||o<1)throw new RangeError("shortenLength must be a positive integer");const s=i.startsWith("0x")?2:0;return i.length<=2*o+s+3?i:`${i.slice(0,o+s)}...${i.slice(-o)}`}(t,e)}}const r="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",i=r.charAt(0),o={};for(let t=0;t<58;t++)o[r.charAt(t)]=t;function s(t){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],e=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],r=8*t.length,i=t.length,o=new Uint8Array(64-(i+8)%64+8);o[0]=128;const s=r,a=Math.floor(s/4294967296),c=s%4294967296,h=o.length;o[h-4]=c>>>24&255,o[h-3]=c>>>16&255,o[h-2]=c>>>8&255,o[h-1]=255&c,o[h-8]=a>>>24&255,o[h-7]=a>>>16&255,o[h-6]=a>>>8&255,o[h-5]=255&a;const u=new Uint8Array(i+o.length);u.set(t),u.set(o,i);const f=new Uint32Array(64);for(let t=0;t<u.length;t+=64){for(let n=0;n<16;n++)f[n]=u[t+4*n]<<24|u[t+4*n+1]<<16|u[t+4*n+2]<<8|u[t+4*n+3];for(let t=16;t<64;t++){const n=l(f[t-2],17)^l(f[t-2],19)^f[t-2]>>>10,e=l(f[t-15],7)^l(f[t-15],18)^f[t-15]>>>3;f[t]=n+f[t-7]+e+f[t-16]|0}let r=e[0],i=e[1],o=e[2],s=e[3],a=e[4],c=e[5],h=e[6],d=e[7];for(let t=0;t<64;t++){const e=d+(l(a,6)^l(a,11)^l(a,25))+(a&c^~a&h)+n[t]+f[t]|0,u=r&i^r&o^i&o;d=h,h=c,c=a,a=s+e|0,s=o,o=i,i=r,r=e+((l(r,2)^l(r,13)^l(r,22))+u|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]+a|0,e[5]=e[5]+c|0,e[6]=e[6]+h|0,e[7]=e[7]+d|0}const d=new Uint8Array(32);for(let t=0;t<8;t++)d[4*t]=e[t]>>>24&255,d[4*t+1]=e[t]>>>16&255,d[4*t+2]=e[t]>>>8&255,d[4*t+3]=255&e[t];return d}function l(t,n){return t>>>n|t<<32-n}function a(t){try{const n=function(t){if(0===t.length)return new Uint8Array(0);let n=0;for(;n<t.length&&t[n]===i;)n++;const e=n,r=[0];for(;n<t.length;n++){const e=t[n],i=o[e];if(void 0===i)throw new Error(`Invalid Base58 character: ${e}`);for(let t=0;t<r.length;t++)r[t]*=58;r[0]+=i;let s=0;for(let t=0;t<r.length;++t)r[t]+=s,s=r[t]>>8,r[t]&=255;for(;s;)r.push(255&s),s>>=8}const s=t.length===e?[]:r.reverse();return Uint8Array.from([...new Array(e).fill(0),...s])}(t);if(n.length<5)return null;const e=n.slice(0,-4),r=s(s(e));return n.slice(-4).every((t,n)=>t===r[n])?e:null}catch{return null}}var c;!function(t){t.BECH32="bech32",t.BECH32M="bech32m"}(c||(c={}));const h=[996825010,642813549,513874426,1027748829,705979059];function u(t,n,e){const r=e===c.BECH32M?734539939:1;return function(t){let n=1;for(const e of t){const t=n>>25;n=(33554431&n)<<5^e;for(let e=0;e<5;e++)t>>e&1&&(n^=h[e])}return n}(function(t){const n=[];for(let e=0;e<t.length;e++)n.push(t.charCodeAt(e)>>5);n.push(0);for(let e=0;e<t.length;e++)n.push(31&t.charCodeAt(e));return n}(t).concat(n))===r}class f extends e{constructor(t){super(),this.config=t}validateImplementation(n){const e=n.toLowerCase().split("1")[0];if(this.config.hrps&&Object.prototype.hasOwnProperty.call(this.config.hrps,e))return this.validateWitness(n,this.config.hrps[e]);if(n.length<26||n.length>35)return this.invalid("Invalid address length",t.INVALID_LENGTH);const r=a(n);if(!r)return this.invalid("Invalid Base58Check address",t.INVALID_CHECKSUM);if(21!==r.length)return this.invalid("Invalid payload length",t.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(n,e){const r=function(t,n=90){if(t.length<8||t.length>n)return null;const e=t.toLowerCase();if(t!==e&&t!==t.toUpperCase())return null;const r=e.lastIndexOf("1");if(r<1||r+7>e.length)return null;const i=e.substring(0,r);if(/[^\x21-\x7E]/.test(i))return null;const o=[];for(let t=r+1;t<e.length;t++){const n="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(e[t]);if(-1===n)return null;o.push(n)}return u(i,o,c.BECH32)?{hrp:i,data:o.slice(0,o.length-6),encoding:c.BECH32}:u(i,o,c.BECH32M)?{hrp:i,data:o.slice(0,o.length-6),encoding:c.BECH32M}:null}(n);if(!r||0===r.data.length)return this.invalid("Invalid Bech32 encoding");const i=r.data[0],o=function(t){let n=0,e=0;const r=[];for(const i of t){if(!Number.isInteger(i)||i<0||i>31)return null;n=65535&(n<<5|i),e+=5,e>=8&&(e-=8,r.push(n>>>e&255))}return e>=5||n<<8-e&255?null:Uint8Array.from(r)}(r.data.slice(1));if(i>16)return this.invalid("Invalid witness version");if(!o||o.length<2||o.length>40||0===i&&20!==o.length&&32!==o.length)return this.invalid("Invalid witness program or padding",t.INVALID_LENGTH);const s=0===i?c.BECH32:c.BECH32M;if(r.encoding!==s)return this.invalid("Wrong checksum encoding for witness version",t.INVALID_CHECKSUM);const l=0===i?"segwit":1===i&&32===o.length?"taproot":"future";return{valid:!0,blockchain:this.config.chain,details:{format:l,network:e,checksum:!0}}}invalid(n,e=t.INVALID_FORMAT){return{valid:!1,error:n,details:{errorCode:e}}}}exports.DogecoinValidator=class extends f{constructor(){super({chain:"dogecoin",versions:{30:"mainnet",22:"mainnet",113:"testnet",196:"testnet"}})}};
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;
package/dist/dogecoin.mjs CHANGED
@@ -1 +1 @@
1
- var t;!function(t){t.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"}(t||(t={}));class n{static sanitize(n){if(null==n)throw new Error(t.UNSAFE_INPUT);if("string"!=typeof n)throw new Error(t.UNSAFE_INPUT);if(n.length>256)throw new Error(t.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(n))throw new Error(t.UNSAFE_INPUT);return n.trim()}}class e{validate(e,r){try{const i=n.sanitize(e),o=this.validateImplementation(i,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.NETWORK_MISMATCH}}:o}catch(n){const e=n instanceof Error?n.message:String(n);return e===t.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.UNSAFE_INPUT}}:{valid:!1,error:e,details:{errorCode:t.INVALID_FORMAT}}}}format(t,e){return function(t,e,r=4){const i=n.sanitize(t);if(!e?.shorten)return i;const o=e.shortenLength??r;if(!Number.isSafeInteger(o)||o<1)throw new RangeError("shortenLength must be a positive integer");const s=i.startsWith("0x")?2:0;return i.length<=2*o+s+3?i:`${i.slice(0,o+s)}...${i.slice(-o)}`}(t,e)}}const r="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",i=r.charAt(0),o={};for(let t=0;t<58;t++)o[r.charAt(t)]=t;function s(t){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],e=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],r=8*t.length,i=t.length,o=new Uint8Array(64-(i+8)%64+8);o[0]=128;const s=r,a=Math.floor(s/4294967296),c=s%4294967296,h=o.length;o[h-4]=c>>>24&255,o[h-3]=c>>>16&255,o[h-2]=c>>>8&255,o[h-1]=255&c,o[h-8]=a>>>24&255,o[h-7]=a>>>16&255,o[h-6]=a>>>8&255,o[h-5]=255&a;const u=new Uint8Array(i+o.length);u.set(t),u.set(o,i);const f=new Uint32Array(64);for(let t=0;t<u.length;t+=64){for(let n=0;n<16;n++)f[n]=u[t+4*n]<<24|u[t+4*n+1]<<16|u[t+4*n+2]<<8|u[t+4*n+3];for(let t=16;t<64;t++){const n=l(f[t-2],17)^l(f[t-2],19)^f[t-2]>>>10,e=l(f[t-15],7)^l(f[t-15],18)^f[t-15]>>>3;f[t]=n+f[t-7]+e+f[t-16]|0}let r=e[0],i=e[1],o=e[2],s=e[3],a=e[4],c=e[5],h=e[6],d=e[7];for(let t=0;t<64;t++){const e=d+(l(a,6)^l(a,11)^l(a,25))+(a&c^~a&h)+n[t]+f[t]|0,u=r&i^r&o^i&o;d=h,h=c,c=a,a=s+e|0,s=o,o=i,i=r,r=e+((l(r,2)^l(r,13)^l(r,22))+u|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]+a|0,e[5]=e[5]+c|0,e[6]=e[6]+h|0,e[7]=e[7]+d|0}const d=new Uint8Array(32);for(let t=0;t<8;t++)d[4*t]=e[t]>>>24&255,d[4*t+1]=e[t]>>>16&255,d[4*t+2]=e[t]>>>8&255,d[4*t+3]=255&e[t];return d}function l(t,n){return t>>>n|t<<32-n}function a(t){try{const n=function(t){if(0===t.length)return new Uint8Array(0);let n=0;for(;n<t.length&&t[n]===i;)n++;const e=n,r=[0];for(;n<t.length;n++){const e=t[n],i=o[e];if(void 0===i)throw new Error(`Invalid Base58 character: ${e}`);for(let t=0;t<r.length;t++)r[t]*=58;r[0]+=i;let s=0;for(let t=0;t<r.length;++t)r[t]+=s,s=r[t]>>8,r[t]&=255;for(;s;)r.push(255&s),s>>=8}const s=t.length===e?[]:r.reverse();return Uint8Array.from([...new Array(e).fill(0),...s])}(t);if(n.length<5)return null;const e=n.slice(0,-4),r=s(s(e));return n.slice(-4).every((t,n)=>t===r[n])?e:null}catch{return null}}var c;!function(t){t.BECH32="bech32",t.BECH32M="bech32m"}(c||(c={}));const h=[996825010,642813549,513874426,1027748829,705979059];function u(t,n,e){const r=e===c.BECH32M?734539939:1;return function(t){let n=1;for(const e of t){const t=n>>25;n=(33554431&n)<<5^e;for(let e=0;e<5;e++)t>>e&1&&(n^=h[e])}return n}(function(t){const n=[];for(let e=0;e<t.length;e++)n.push(t.charCodeAt(e)>>5);n.push(0);for(let e=0;e<t.length;e++)n.push(31&t.charCodeAt(e));return n}(t).concat(n))===r}class f extends e{constructor(t){super(),this.config=t}validateImplementation(n){const e=n.toLowerCase().split("1")[0];if(this.config.hrps&&Object.prototype.hasOwnProperty.call(this.config.hrps,e))return this.validateWitness(n,this.config.hrps[e]);if(n.length<26||n.length>35)return this.invalid("Invalid address length",t.INVALID_LENGTH);const r=a(n);if(!r)return this.invalid("Invalid Base58Check address",t.INVALID_CHECKSUM);if(21!==r.length)return this.invalid("Invalid payload length",t.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(n,e){const r=function(t,n=90){if(t.length<8||t.length>n)return null;const e=t.toLowerCase();if(t!==e&&t!==t.toUpperCase())return null;const r=e.lastIndexOf("1");if(r<1||r+7>e.length)return null;const i=e.substring(0,r);if(/[^\x21-\x7E]/.test(i))return null;const o=[];for(let t=r+1;t<e.length;t++){const n="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(e[t]);if(-1===n)return null;o.push(n)}return u(i,o,c.BECH32)?{hrp:i,data:o.slice(0,o.length-6),encoding:c.BECH32}:u(i,o,c.BECH32M)?{hrp:i,data:o.slice(0,o.length-6),encoding:c.BECH32M}:null}(n);if(!r||0===r.data.length)return this.invalid("Invalid Bech32 encoding");const i=r.data[0],o=function(t){let n=0,e=0;const r=[];for(const i of t){if(!Number.isInteger(i)||i<0||i>31)return null;n=65535&(n<<5|i),e+=5,e>=8&&(e-=8,r.push(n>>>e&255))}return e>=5||n<<8-e&255?null:Uint8Array.from(r)}(r.data.slice(1));if(i>16)return this.invalid("Invalid witness version");if(!o||o.length<2||o.length>40||0===i&&20!==o.length&&32!==o.length)return this.invalid("Invalid witness program or padding",t.INVALID_LENGTH);const s=0===i?c.BECH32:c.BECH32M;if(r.encoding!==s)return this.invalid("Wrong checksum encoding for witness version",t.INVALID_CHECKSUM);const l=0===i?"segwit":1===i&&32===o.length?"taproot":"future";return{valid:!0,blockchain:this.config.chain,details:{format:l,network:e,checksum:!0}}}invalid(n,e=t.INVALID_FORMAT){return{valid:!1,error:n,details:{errorCode:e}}}}class d extends f{constructor(){super({chain:"dogecoin",versions:{30:"mainnet",22:"mainnet",113:"testnet",196:"testnet"}})}}export{d as DogecoinValidator};
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};
package/dist/ethereum.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t;!function(t){t.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"}(t||(t={}));class e{static sanitize(e){if(null==e)throw new Error(t.UNSAFE_INPUT);if("string"!=typeof e)throw new Error(t.UNSAFE_INPUT);if(e.length>256)throw new Error(t.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(e))throw new Error(t.UNSAFE_INPUT);return e.trim()}}class r{validate(r,n){try{const o=e.sanitize(r),s=this.validateImplementation(o,n),i=s.details?.network;return s.valid&&i&&(n?.network&&"auto"!==n.network&&n.network!==i||!1===n?.allowTestnet&&"testnet"===i)?{valid:!1,error:"Address network does not match the requested network",details:{...s.details,errorCode:t.NETWORK_MISMATCH}}:s}catch(e){const r=e instanceof Error?e.message:String(e);return r===t.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.UNSAFE_INPUT}}:{valid:!1,error:r,details:{errorCode:t.INVALID_FORMAT}}}}format(t,e){return n(t,e)}}function n(t,r,n=4){const o=e.sanitize(t);if(!r?.shorten)return o;const s=r.shortenLength??n;if(!Number.isSafeInteger(s)||s<1)throw new RangeError("shortenLength must be a positive integer");const i=o.startsWith("0x")?2:0;return o.length<=2*s+i+3?o:`${o.slice(0,s+i)}...${o.slice(-s)}`}function o(t){return t.startsWith("0x")?t.slice(2):t}function s(t){return t.startsWith("0x")?t:`0x${t}`}const i=(1n<<64n)-1n,a=[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 d(t,e){return(t<<BigInt(e)|t>>BigInt(64-e))&i}function c(t){const e=new Array(5),r=new Array(25);for(const n of l){for(let r=0;r<5;r++)e[r]=t[r]^t[r+5]^t[r+10]^t[r+15]^t[r+20];for(let r=0;r<5;r++){const n=e[(r+4)%5]^d(e[(r+1)%5],1);for(let e=0;e<5;e++)t[r+5*e]^=n}for(let e=0;e<5;e++)for(let n=0;n<5;n++)r[n+(2*e+3*n)%5*5]=d(t[e+5*n],a[e+5*n]);for(let e=0;e<5;e++)for(let n=0;n<5;n++)t[e+5*n]=r[e+5*n]^~r[(e+1)%5+5*n]&r[(e+2)%5+5*n];t[0]^=n}}exports.EthereumValidator=class extends r{validateImplementation(e,r){const n=o(e);if(40!==n.length)return{valid:!1,error:"Invalid length",details:{errorCode:t.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)}(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 s=this.isChecksummed(n);return(r?.strict||n!==n.toLowerCase()&&n!==n.toUpperCase())&&!s?{valid:!1,error:"Invalid checksum",details:{errorCode:t.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:s}}}format(t,r){let o=s(e.sanitize(t));return r?.checksum&&(o=this.toChecksumAddress(o)),n(o,r)}isChecksummed(t){const e=o(t);return s(e)===this.toChecksumAddress(e)}toChecksumAddress(t){const e=o(t).toLowerCase();if(!/^[0-9a-f]{40}$/.test(e))throw new Error("Expected a 20-byte hexadecimal address");const r=function(t){const e=(new TextEncoder).encode(t),r=new Uint8Array(136*(Math.floor(e.length/136)+1));r.set(e),r[e.length]=1,r[r.length-1]|=128;const n=new Array(25).fill(0n);for(let t=0;t<r.length;t+=136){for(let e=0;e<136;e++)n[e>>3]^=BigInt(r[t+e])<<BigInt(8*(7&e));c(n)}let o="";for(let t=0;t<32;t++)o+=Number(n[t>>3]>>BigInt(8*(7&t))&255n).toString(16).padStart(2,"0");return o}(e);return"0x"+[...e].map((t,e)=>parseInt(r[e],16)>=8?t.toUpperCase():t).join("")}};
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;
package/dist/ethereum.mjs CHANGED
@@ -1 +1 @@
1
- var t;!function(t){t.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"}(t||(t={}));class e{static sanitize(e){if(null==e)throw new Error(t.UNSAFE_INPUT);if("string"!=typeof e)throw new Error(t.UNSAFE_INPUT);if(e.length>256)throw new Error(t.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(e))throw new Error(t.UNSAFE_INPUT);return e.trim()}}class r{validate(r,n){try{const o=e.sanitize(r),s=this.validateImplementation(o,n),i=s.details?.network;return s.valid&&i&&(n?.network&&"auto"!==n.network&&n.network!==i||!1===n?.allowTestnet&&"testnet"===i)?{valid:!1,error:"Address network does not match the requested network",details:{...s.details,errorCode:t.NETWORK_MISMATCH}}:s}catch(e){const r=e instanceof Error?e.message:String(e);return r===t.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.UNSAFE_INPUT}}:{valid:!1,error:r,details:{errorCode:t.INVALID_FORMAT}}}}format(t,e){return n(t,e)}}function n(t,r,n=4){const o=e.sanitize(t);if(!r?.shorten)return o;const s=r.shortenLength??n;if(!Number.isSafeInteger(s)||s<1)throw new RangeError("shortenLength must be a positive integer");const i=o.startsWith("0x")?2:0;return o.length<=2*s+i+3?o:`${o.slice(0,s+i)}...${o.slice(-s)}`}function o(t){return t.startsWith("0x")?t.slice(2):t}function s(t){return t.startsWith("0x")?t:`0x${t}`}const i=(1n<<64n)-1n,a=[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 d(t,e){return(t<<BigInt(e)|t>>BigInt(64-e))&i}function c(t){const e=new Array(5),r=new Array(25);for(const n of l){for(let r=0;r<5;r++)e[r]=t[r]^t[r+5]^t[r+10]^t[r+15]^t[r+20];for(let r=0;r<5;r++){const n=e[(r+4)%5]^d(e[(r+1)%5],1);for(let e=0;e<5;e++)t[r+5*e]^=n}for(let e=0;e<5;e++)for(let n=0;n<5;n++)r[n+(2*e+3*n)%5*5]=d(t[e+5*n],a[e+5*n]);for(let e=0;e<5;e++)for(let n=0;n<5;n++)t[e+5*n]=r[e+5*n]^~r[(e+1)%5+5*n]&r[(e+2)%5+5*n];t[0]^=n}}class I extends r{validateImplementation(e,r){const n=o(e);if(40!==n.length)return{valid:!1,error:"Invalid length",details:{errorCode:t.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)}(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 s=this.isChecksummed(n);return(r?.strict||n!==n.toLowerCase()&&n!==n.toUpperCase())&&!s?{valid:!1,error:"Invalid checksum",details:{errorCode:t.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:s}}}format(t,r){let o=s(e.sanitize(t));return r?.checksum&&(o=this.toChecksumAddress(o)),n(o,r)}isChecksummed(t){const e=o(t);return s(e)===this.toChecksumAddress(e)}toChecksumAddress(t){const e=o(t).toLowerCase();if(!/^[0-9a-f]{40}$/.test(e))throw new Error("Expected a 20-byte hexadecimal address");const r=function(t){const e=(new TextEncoder).encode(t),r=new Uint8Array(136*(Math.floor(e.length/136)+1));r.set(e),r[e.length]=1,r[r.length-1]|=128;const n=new Array(25).fill(0n);for(let t=0;t<r.length;t+=136){for(let e=0;e<136;e++)n[e>>3]^=BigInt(r[t+e])<<BigInt(8*(7&e));c(n)}let o="";for(let t=0;t<32;t++)o+=Number(n[t>>3]>>BigInt(8*(7&t))&255n).toString(16).padStart(2,"0");return o}(e);return"0x"+[...e].map((t,e)=>parseInt(r[e],16)>=8?t.toUpperCase():t).join("")}}export{I as EthereumValidator};
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};
package/dist/evm.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t;!function(t){t.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"}(t||(t={}));class e{static sanitize(e){if(null==e)throw new Error(t.UNSAFE_INPUT);if("string"!=typeof e)throw new Error(t.UNSAFE_INPUT);if(e.length>256)throw new Error(t.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(e))throw new Error(t.UNSAFE_INPUT);return e.trim()}}class r{validate(r,n){try{const a=e.sanitize(r),s=this.validateImplementation(a,n),o=s.details?.network;return s.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:{...s.details,errorCode:t.NETWORK_MISMATCH}}:s}catch(e){const r=e instanceof Error?e.message:String(e);return r===t.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.UNSAFE_INPUT}}:{valid:!1,error:r,details:{errorCode:t.INVALID_FORMAT}}}}format(t,e){return n(t,e)}}function n(t,r,n=4){const a=e.sanitize(t);if(!r?.shorten)return a;const s=r.shortenLength??n;if(!Number.isSafeInteger(s)||s<1)throw new RangeError("shortenLength must be a positive integer");const o=a.startsWith("0x")?2:0;return a.length<=2*s+o+3?a:`${a.slice(0,s+o)}...${a.slice(-s)}`}function a(t){return t.startsWith("0x")?t.slice(2):t}function s(t){return t.startsWith("0x")?t:`0x${t}`}const o=(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(t,e){return(t<<BigInt(e)|t>>BigInt(64-e))&o}function d(t){const e=new Array(5),r=new Array(25);for(const n of l){for(let r=0;r<5;r++)e[r]=t[r]^t[r+5]^t[r+10]^t[r+15]^t[r+20];for(let r=0;r<5;r++){const n=e[(r+4)%5]^c(e[(r+1)%5],1);for(let e=0;e<5;e++)t[r+5*e]^=n}for(let e=0;e<5;e++)for(let n=0;n<5;n++)r[n+(2*e+3*n)%5*5]=c(t[e+5*n],i[e+5*n]);for(let e=0;e<5;e++)for(let n=0;n<5;n++)t[e+5*n]=r[e+5*n]^~r[(e+1)%5+5*n]&r[(e+2)%5+5*n];t[0]^=n}}class u extends r{validateImplementation(e,r){const n=a(e);if(40!==n.length)return{valid:!1,error:"Invalid length",details:{errorCode:t.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)}(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 s=this.isChecksummed(n);return(r?.strict||n!==n.toLowerCase()&&n!==n.toUpperCase())&&!s?{valid:!1,error:"Invalid checksum",details:{errorCode:t.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:s}}}format(t,r){let a=s(e.sanitize(t));return r?.checksum&&(a=this.toChecksumAddress(a)),n(a,r)}isChecksummed(t){const e=a(t);return s(e)===this.toChecksumAddress(e)}toChecksumAddress(t){const e=a(t).toLowerCase();if(!/^[0-9a-f]{40}$/.test(e))throw new Error("Expected a 20-byte hexadecimal address");const r=function(t){const e=(new TextEncoder).encode(t),r=new Uint8Array(136*(Math.floor(e.length/136)+1));r.set(e),r[e.length]=1,r[r.length-1]|=128;const n=new Array(25).fill(0n);for(let t=0;t<r.length;t+=136){for(let e=0;e<136;e++)n[e>>3]^=BigInt(r[t+e])<<BigInt(8*(7&e));d(n)}let a="";for(let t=0;t<32;t++)a+=Number(n[t>>3]>>BigInt(8*(7&t))&255n).toString(16).padStart(2,"0");return a}(e);return"0x"+[...e].map((t,e)=>parseInt(r[e],16)>=8?t.toUpperCase():t).join("")}}exports.ArbitrumValidator=class extends u{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="arbitrum"),r}},exports.AvalancheValidator=class extends u{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="avalanche"),r}},exports.BaseValidator=class extends u{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="base"),r}},exports.BscValidator=class extends u{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="bsc"),r}},exports.EvmValidator=class extends u{constructor(t="evm"){super(),this.chain=t}validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain=this.chain),r}},exports.OptimismValidator=class extends u{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="optimism"),r}};
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;
package/dist/evm.mjs CHANGED
@@ -1 +1 @@
1
- var e;!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"}(e||(e={}));class t{static sanitize(t){if(null==t)throw new Error(e.UNSAFE_INPUT);if("string"!=typeof t)throw new Error(e.UNSAFE_INPUT);if(t.length>256)throw new Error(e.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(t))throw new Error(e.UNSAFE_INPUT);return t.trim()}}class n{validate(n,r){try{const a=t.sanitize(n),s=this.validateImplementation(a,r),o=s.details?.network;return s.valid&&o&&(r?.network&&"auto"!==r.network&&r.network!==o||!1===r?.allowTestnet&&"testnet"===o)?{valid:!1,error:"Address network does not match the requested network",details:{...s.details,errorCode:e.NETWORK_MISMATCH}}:s}catch(t){const n=t instanceof Error?t.message:String(t);return n===e.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:e.UNSAFE_INPUT}}:{valid:!1,error:n,details:{errorCode:e.INVALID_FORMAT}}}}format(e,t){return r(e,t)}}function r(e,n,r=4){const a=t.sanitize(e);if(!n?.shorten)return a;const s=n.shortenLength??r;if(!Number.isSafeInteger(s)||s<1)throw new RangeError("shortenLength must be a positive integer");const o=a.startsWith("0x")?2:0;return a.length<=2*s+o+3?a:`${a.slice(0,s+o)}...${a.slice(-s)}`}function a(e){return e.startsWith("0x")?e.slice(2):e}function s(e){return e.startsWith("0x")?e:`0x${e}`}const o=(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))&o}function d(e){const t=new Array(5),n=new Array(25);for(const r of l){for(let n=0;n<5;n++)t[n]=e[n]^e[n+5]^e[n+10]^e[n+15]^e[n+20];for(let n=0;n<5;n++){const r=t[(n+4)%5]^c(t[(n+1)%5],1);for(let t=0;t<5;t++)e[n+5*t]^=r}for(let t=0;t<5;t++)for(let r=0;r<5;r++)n[r+(2*t+3*r)%5*5]=c(e[t+5*r],i[t+5*r]);for(let t=0;t<5;t++)for(let r=0;r<5;r++)e[t+5*r]=n[t+5*r]^~n[(t+1)%5+5*r]&n[(t+2)%5+5*r];e[0]^=r}}class I extends n{validateImplementation(t,n){const r=a(t);if(40!==r.length)return{valid:!1,error:"Invalid length",details:{errorCode:e.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)}(r))return{valid:!1,error:"Invalid hex characters",details:{errorCode:e.INVALID_CHARACTERS}};if(!n?.allowBurnAddress&&/^0+$/.test(r))return{valid:!1,error:"Burn address detected",details:{errorCode:e.BURN_ADDRESS}};const s=this.isChecksummed(r);return(n?.strict||r!==r.toLowerCase()&&r!==r.toUpperCase())&&!s?{valid:!1,error:"Invalid checksum",details:{errorCode:e.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:s}}}format(e,n){let a=s(t.sanitize(e));return n?.checksum&&(a=this.toChecksumAddress(a)),r(a,n)}isChecksummed(e){const t=a(e);return s(t)===this.toChecksumAddress(t)}toChecksumAddress(e){const t=a(e).toLowerCase();if(!/^[0-9a-f]{40}$/.test(t))throw new Error("Expected a 20-byte hexadecimal address");const n=function(e){const t=(new TextEncoder).encode(e),n=new Uint8Array(136*(Math.floor(t.length/136)+1));n.set(t),n[t.length]=1,n[n.length-1]|=128;const r=new Array(25).fill(0n);for(let e=0;e<n.length;e+=136){for(let t=0;t<136;t++)r[t>>3]^=BigInt(n[e+t])<<BigInt(8*(7&t));d(r)}let a="";for(let e=0;e<32;e++)a+=Number(r[e>>3]>>BigInt(8*(7&e))&255n).toString(16).padStart(2,"0");return a}(t);return"0x"+[...t].map((e,t)=>parseInt(n[t],16)>=8?e.toUpperCase():e).join("")}}class u extends I{validateImplementation(e,t){const n=super.validateImplementation(e,t);return n.valid&&(n.blockchain="bsc"),n}}class h extends I{validateImplementation(e,t){const n=super.validateImplementation(e,t);return n.valid&&(n.blockchain="avalanche"),n}}class m extends I{validateImplementation(e,t){const n=super.validateImplementation(e,t);return n.valid&&(n.blockchain="arbitrum"),n}}class A extends I{validateImplementation(e,t){const n=super.validateImplementation(e,t);return n.valid&&(n.blockchain="optimism"),n}}class x extends I{validateImplementation(e,t){const n=super.validateImplementation(e,t);return n.valid&&(n.blockchain="base"),n}}class N extends I{constructor(e="evm"){super(),this.chain=e}validateImplementation(e,t){const n=super.validateImplementation(e,t);return n.valid&&(n.blockchain=this.chain),n}}export{m as ArbitrumValidator,h as AvalancheValidator,x as BaseValidator,u as BscValidator,N as EvmValidator,A as OptimismValidator};
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 +1 @@
1
- "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"]);var t;!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"}(t||(t={}));class r{static sanitize(e){if(null==e)throw new Error(t.UNSAFE_INPUT);if("string"!=typeof e)throw new Error(t.UNSAFE_INPUT);if(e.length>256)throw new Error(t.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(e))throw new Error(t.UNSAFE_INPUT);return e.trim()}}class n{validate(e,n){try{const o=r.sanitize(e),s=this.validateImplementation(o,n),i=s.details?.network;return s.valid&&i&&(n?.network&&"auto"!==n.network&&n.network!==i||!1===n?.allowTestnet&&"testnet"===i)?{valid:!1,error:"Address network does not match the requested network",details:{...s.details,errorCode:t.NETWORK_MISMATCH}}:s}catch(e){const r=e instanceof Error?e.message:String(e);return r===t.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.UNSAFE_INPUT}}:{valid:!1,error:r,details:{errorCode:t.INVALID_FORMAT}}}}format(e,t){return o(e,t)}}function o(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 i=o.startsWith("0x")?2:0;return o.length<=2*s+i+3?o:`${o.slice(0,s+i)}...${o.slice(-s)}`}function s(e){return e.startsWith("0x")?e.slice(2):e}function i(e){return e.startsWith("0x")?e:`0x${e}`}const a=(1n<<64n)-1n,c=[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 d(e,t){return(e<<BigInt(t)|e>>BigInt(64-t))&a}function u(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]^d(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]=d(e[t+5*n],c[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 h extends n{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 n=i(r.sanitize(e));return t?.checksum&&(n=this.toChecksumAddress(n)),o(n,t)}isChecksummed(e){const t=s(e);return i(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));u(n)}let o="";for(let e=0;e<32;e++)o+=Number(n[e>>3]>>BigInt(8*(7&e))&255n).toString(16).padStart(2,"0");return o}(t);return"0x"+[...t].map((e,t)=>parseInt(r[t],16)>=8?e.toUpperCase():e).join("")}}exports.addChecksum=function(t,n){return e.includes(n)?(new h).format(t,{checksum:!0}):r.sanitize(t)},exports.normalizeAddress=function(t,n){const o=r.sanitize(t);return e.includes(n)||"sui"===n||"aptos"===n?o.toLowerCase():o},exports.shortenAddress=function(e,t=4){return o(e,{shorten:!0,shortenLength:t})};
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 +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"]);var t;!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"}(t||(t={}));class r{static sanitize(e){if(null==e)throw new Error(t.UNSAFE_INPUT);if("string"!=typeof e)throw new Error(t.UNSAFE_INPUT);if(e.length>256)throw new Error(t.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(e))throw new Error(t.UNSAFE_INPUT);return e.trim()}}class n{validate(e,n){try{const o=r.sanitize(e),s=this.validateImplementation(o,n),i=s.details?.network;return s.valid&&i&&(n?.network&&"auto"!==n.network&&n.network!==i||!1===n?.allowTestnet&&"testnet"===i)?{valid:!1,error:"Address network does not match the requested network",details:{...s.details,errorCode:t.NETWORK_MISMATCH}}:s}catch(e){const r=e instanceof Error?e.message:String(e);return r===t.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.UNSAFE_INPUT}}:{valid:!1,error:r,details:{errorCode:t.INVALID_FORMAT}}}}format(e,t){return o(e,t)}}function o(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 i=o.startsWith("0x")?2:0;return o.length<=2*s+i+3?o:`${o.slice(0,s+i)}...${o.slice(-s)}`}function s(e){return e.startsWith("0x")?e.slice(2):e}function i(e){return e.startsWith("0x")?e:`0x${e}`}const a=(1n<<64n)-1n,c=[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 d(e,t){return(e<<BigInt(t)|e>>BigInt(64-t))&a}function u(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]^d(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]=d(e[t+5*n],c[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 h extends n{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 n=i(r.sanitize(e));return t?.checksum&&(n=this.toChecksumAddress(n)),o(n,t)}isChecksummed(e){const t=s(e);return i(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));u(n)}let o="";for(let e=0;e<32;e++)o+=Number(n[e>>3]>>BigInt(8*(7&e))&255n).toString(16).padStart(2,"0");return o}(t);return"0x"+[...t].map((e,t)=>parseInt(r[t],16)>=8?e.toUpperCase():e).join("")}}function I(e,t=4){return o(e,{shorten:!0,shortenLength:t})}function f(t,n){const o=r.sanitize(t);return e.includes(n)||"sui"===n||"aptos"===n?o.toLowerCase():o}function A(t,n){return e.includes(n)?(new h).format(t,{checksum:!0}):r.sanitize(t)}export{A as addChecksum,f as normalizeAddress,I as shortenAddress};
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};