validator0x 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/AGENTS.md +74 -65
  2. package/CHANGELOG.md +24 -2
  3. package/README.md +23 -10
  4. package/dist/bitcoin.cjs +1 -1
  5. package/dist/bitcoin.mjs +1 -1
  6. package/dist/cardano.cjs +1 -1
  7. package/dist/cardano.mjs +1 -1
  8. package/dist/cosmos.cjs +1 -1
  9. package/dist/cosmos.mjs +1 -1
  10. package/dist/dogecoin.cjs +1 -1
  11. package/dist/dogecoin.mjs +1 -1
  12. package/dist/ethereum.cjs +1 -1
  13. package/dist/ethereum.mjs +1 -1
  14. package/dist/evm.cjs +1 -1
  15. package/dist/evm.mjs +1 -1
  16. package/dist/formatters.cjs +1 -1
  17. package/dist/formatters.mjs +1 -1
  18. package/dist/index.cjs +1 -1
  19. package/dist/index.d.cts +0 -2
  20. package/dist/index.d.mts +0 -2
  21. package/dist/index.mjs +1 -1
  22. package/dist/index.umd.js +1 -1
  23. package/dist/litecoin.cjs +1 -1
  24. package/dist/litecoin.mjs +1 -1
  25. package/dist/move.cjs +1 -1
  26. package/dist/move.mjs +1 -1
  27. package/dist/near.cjs +1 -1
  28. package/dist/near.mjs +1 -1
  29. package/dist/ripple.cjs +1 -1
  30. package/dist/ripple.mjs +1 -1
  31. package/dist/shared/base-3sYui6r0.cjs +1 -0
  32. package/dist/shared/base-CZZTeLCP.mjs +1 -0
  33. package/dist/shared/base58-DV6hu8Kq.cjs +1 -0
  34. package/dist/shared/base58-DY9-Un67.mjs +1 -0
  35. package/dist/shared/base58check-BeCwnkGe.cjs +1 -0
  36. package/dist/shared/base58check-rMkz2cjy.mjs +1 -0
  37. package/dist/shared/bech32-Cu41-5bd.mjs +1 -0
  38. package/dist/shared/bech32-Dk6Pnay4.cjs +1 -0
  39. package/dist/shared/utxo-BrSxcH2x.mjs +1 -0
  40. package/dist/shared/utxo-DF5Lt3lY.cjs +1 -0
  41. package/dist/solana.cjs +1 -1
  42. package/dist/solana.mjs +1 -1
  43. package/dist/tron.cjs +1 -1
  44. package/dist/tron.mjs +1 -1
  45. package/package.json +9 -8
package/AGENTS.md CHANGED
@@ -1,65 +1,74 @@
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. Any other `network` value throws a `RangeError` before input is read, including for an empty batch or empty detection input. EVM, Solana, TRON, Cosmos, Sui, Aptos, and NEAR cannot establish mainnet/testnet from address syntax. An absent `details.network` means unknown, not mainnet.
14
+ 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 === 'bitcoin' && result.details?.format === 'anchor') {
35
+ return { ok: false as const, error: 'Choose a Bitcoin payment address. Anyone can spend a fee anchor.' };
36
+ }
37
+ if (chain === 'cardano' && result.details?.format === 'stake') {
38
+ return { ok: false as const, error: 'Choose a Cardano payment address' };
39
+ }
40
+ const trimmed = input.trim();
41
+ const isEvm = EVM_CHAINS.some(candidate => candidate === chain);
42
+ const destination = isEvm && !trimmed.startsWith('0x') ? '0x' + trimmed : trimmed;
43
+ return { ok: true as const, address: destination, chain };
44
+ }
45
+ ```
46
+
47
+ ### Small single-family example
48
+
49
+ ```ts
50
+ import { BitcoinValidator } from 'validator0x/bitcoin';
51
+
52
+ const bitcoin = new BitcoinValidator();
53
+ const result = bitcoin.validate('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa', {
54
+ network: 'mainnet',
55
+ });
56
+ ```
57
+
58
+ ### Discovering this file after installation
59
+
60
+ 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.
61
+
62
+ ## Contributing to this repository
63
+
64
+ - Use Node.js 22.13+ or a supported newer LTS for development. Install the locked development dependencies with `npm ci`.
65
+ - 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`.
66
+ - 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.
67
+ - 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.
68
+ - 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.
69
+ - 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.
70
+ - 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.
71
+ - 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.
72
+ - Inspect `git status` before staging. Stage the intended source, tests, configuration, and documentation explicitly; preserve unrelated user edits.
73
+ - 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.
74
+ - 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,28 @@
1
1
  # Changelog
2
2
 
3
- ## 0.3.0 - Unreleased
3
+ ## 0.4.1 - 2026-11-26
4
+
5
+ - Cardano Byron validation rejects noncanonical CBOR encodings of the address type, network magic, and encrypted path length.
6
+ - Cardano Byron validation accepts variable-length encrypted derivation paths, including the 32-byte paths in the ledger fixtures.
7
+ - Bitcoin BIP-433 fee anchors return `details.format === 'anchor'`. Both payment examples reject them as recipients.
8
+ - An unsupported `network` option value throws a `RangeError` from validation, batch validation, detection, and validator `validate` methods, before any input is read. Previously it reported `NETWORK_MISMATCH` for addresses that encode a network and was ignored for other chains. `undefined` and `null` still mean `auto`.
9
+ - Invalid network values are rejected without calling their conversion hooks. Unsafe address inputs return structured errors without creating an exception for each row.
10
+ - Arrays passed to `validateBatch` produce one result per original index, even with a custom iterator or inherited values at missing indices.
11
+ - Aptos accepts uppercase hex letters in short special addresses by default, including `0xF`. Strict mode requires the lowercase AIP-40 form. EVM validators report malformed repeated prefixes consistently and skip hashing digit-only addresses.
12
+ - Chain detection validates the shared EVM format once and preserves the full ordered candidate list. Cosmos validators reject mismatched prefixes before decoding the payload.
13
+ - Bitcoin-family and XRP addresses share the Base58 decoder and checksum logic. Bech32 and Bech32m use one checksum pass, reject non-ASCII input, and decode padding into a preallocated byte array. Cardano pointer parsing enforces each field's bounds during decoding.
14
+ - Keccak-256 uses 32-bit operations. SHA-256 and Base58Check reduce intermediate allocations. The package keeps zero runtime dependencies.
15
+ - Expanded regression and independent reference tests cover address mutations, checksum error codes, padding, pointer boundaries, Cosmos account formats, and ambiguous detection. Packed-consumer tests verify named exports, type identity, browser globals, and both documented payment examples. The benchmark now exercises sparse batches.
16
+
17
+ ## 0.4.0
18
+
19
+ - JavaScript EVM and Cosmos constructors reject unsupported family identifiers.
20
+ - Sparse batches produce an invalid result at each missing index.
21
+ - Cardano pointer fields enforce the strict ledger limits for slots and indices.
22
+ - 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.
23
+ - Payment-form examples reject Cardano reward addresses and prefix validated EVM destinations.
24
+
25
+ ## 0.3.0 - 2026-11-13
4
26
 
5
27
  ### Added
6
28
 
@@ -31,4 +53,4 @@
31
53
  - Supported Node.js baseline is 22; browsers/workers need ES2020, BigInt, and TextEncoder. Development tools require Node 22.13+ (or 24+).
32
54
  - 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
55
 
34
- This version is prepared locally; publication is a separate release action.
56
+ 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,16 @@ 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 === 'bitcoin' && result.details?.format === 'anchor') {
58
+ return { ok: false as const, error: 'Choose a Bitcoin payment address. Anyone can spend a fee anchor.' };
59
+ }
60
+ if (chain === 'cardano' && result.details?.format === 'stake') {
61
+ return { ok: false as const, error: 'Choose a Cardano payment address' };
62
+ }
63
+ const trimmed = address.trim();
64
+ const isEvm = EVM_CHAINS.some(candidate => candidate === chain);
65
+ const destination = isEvm && !trimmed.startsWith('0x') ? '0x' + trimmed : trimmed;
66
+ return { ok: true as const, address: destination, chain };
58
67
  }
59
68
  ```
60
69
 
@@ -63,7 +72,7 @@ The validator trims outer ASCII spaces internally; use the trimmed string after
63
72
  | Public API | Result and behavior |
64
73
  | --- | --- |
65
74
  | `validateAddress(input, chain, options?)` | `ValidationResult`; invalid addresses return `valid: false` |
66
- | `validateBatch(inputs, chain, options?)` | Results in input order; accepts a readonly array |
75
+ | `validateBatch(inputs, chain, options?)` | One result per original array index, in order. Missing rows receive an invalid result. Accepts a readonly array. |
67
76
  | `isSupportedChain(value)` | Boolean and TypeScript type guard for unknown chain input |
68
77
  | `SUPPORTED_CHAINS` | Frozen list of supported identifiers; useful for a chain selector |
69
78
  | `detectBlockchain(input, options?)` | One chain, candidate array, or `null`; never proof of chain ownership |
@@ -113,7 +122,7 @@ All direct imports support ESM, CommonJS, and TypeScript:
113
122
 
114
123
  For example, `new CosmosValidator('osmosis')` or `new EvmValidator('sonic')`. Existing validator classes, including `PolygonValidator`, remain available from the root import.
115
124
 
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.
125
+ 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
126
 
118
127
  ## Supported address formats
119
128
 
@@ -121,19 +130,21 @@ The full minified ESM bundle is approximately **6.8 kB gzip**, and the Solana-on
121
130
  | --- | --- |
122
131
  | `ethereum`, `polygon`, `bsc`, `avalanche`, `arbitrum`, `optimism`, `base` | Ethereum 20-byte hexadecimal addresses; EIP-55 checksum |
123
132
  | `evm`, `fantom`, `sonic`, `gnosis`, `celo`, `cronos`, `moonbeam`, `moonriver`, `zksync`, `linea`, `scroll`, `mantle`, `blast`, `opbnb`, `zora`, `worldchain` | Same Ethereum/EIP-55 address rules |
124
- | `bitcoin` | Base58Check P2PKH/P2SH; SegWit v0; Bech32m v1-16, including Taproot; mainnet and testnet |
133
+ | `bitcoin` | Base58Check P2PKH/P2SH; SegWit v0; Bech32m v1-16, including Taproot and [BIP-433 fee anchors](https://github.com/bitcoin/bips/blob/master/bip-0433.mediawiki); mainnet and testnet |
125
134
  | `litecoin` | Base58Check P2PKH/P2SH (including legacy shared P2SH prefixes); standard witness v0-16; mainnet and testnet |
126
135
  | `dogecoin` | Base58Check P2PKH/P2SH; mainnet and testnet |
127
136
  | `solana` | Base58 decoding to exactly 32 bytes, including program addresses and PDAs |
128
- | `cardano` | Shelley base, enterprise, pointer, and stake addresses; header/network/length/padding checks; Byron CBOR envelope and CRC32 |
137
+ | `cardano` | Shelley base, enterprise, pointer, and stake addresses; header/network/length/padding checks; Byron CBOR envelopes with a 28-byte root, optional variable-length encrypted derivation path, and CRC32 |
129
138
  | `ripple` | XRP classic account addresses with the XRP Base58 alphabet and checksum |
130
139
  | `tron` | 34-character Base58Check or 42-character hex beginning with `41` |
131
140
  | `cosmos`, `osmosis`, `sei` | Bech32 account prefixes `cosmos`, `osmo`, `sei`; 20- or 32-byte payloads |
132
141
  | `celestia`, `injective` | Bech32 account prefixes `celestia`, `inj`; 20-byte payloads |
133
142
  | `sui` | `0x` followed by exactly 64 hex digits |
134
- | `aptos` | Full 32-byte hexadecimal addresses or special addresses `0x0` through `0xf`; strict canonical AIP-40 mode |
143
+ | `aptos` | Full 32-byte hexadecimal addresses or single-digit special addresses, each with a lowercase `0x` prefix. Default mode accepts either hex letter case. Strict mode requires the canonical AIP-40 spelling. |
135
144
  | `near` | 2-64 character account IDs with lowercase letters, numbers, and valid separators; named, implicit, Ethereum-like, deterministic, and universal forms |
136
145
 
146
+ For Cardano Byron addresses, the address type, network magic, and length of the encrypted path use the shortest CBOR encoding. Validation checks these fields even when the CRC32 matches.
147
+
137
148
  `avalanche` covers C-Chain addresses. For additional chains using standard Ethereum addresses, use `evm`; chain-specific checksum schemes such as EIP-1191 are outside its scope. For Sei's EVM format, use `evm`; `sei` validates its Bech32 format.
138
149
 
139
150
  Not supported: Bitcoin/Litecoin regtest HRPs, Litecoin MWEB, XRP X-addresses/destination tags, Cardano addresses longer than 256 characters, Cosmos validator/consensus prefixes, ENS or other name-service resolution. A syntactically valid future witness address is not necessarily spendable under today's consensus rules. Cardano pointer addresses are recognized for compatibility; this does not assert they can be newly created on mainnet. Solana validation does not test curve membership.
@@ -150,7 +161,7 @@ validateAddress(address, chain, {
150
161
  ```
151
162
 
152
163
  - `strict` defaults to `false`. On EVM, `true` requires the exact EIP-55 capitalization, including the rare valid all-lowercase/all-uppercase checksums. Invalid mixed-case EVM checksums are always rejected. On Aptos, strict mode requires lowercase AIP-40 canonical representation. Other formats always verify their mandatory checksums.
153
- - `network` defaults to `auto`. It filters networks **only when encoded in the address**, currently Bitcoin, Litecoin, Dogecoin, and Cardano. `details.network` is omitted for formats that cannot identify mainnet/testnet. Selecting a network never proves an address belongs to it.
164
+ - `network` defaults to `auto` (`undefined` and `null` also mean `auto`). Any other value than `'mainnet'`, `'testnet'`, or `'auto'` throws a `RangeError` from `validateAddress`, `validateBatch`, `detectBlockchain`, and validator `validate` methods. The option is checked before any input is read, so an empty batch or empty, blank, or unsafe input still throws. It filters networks **only when encoded in the address**, currently Bitcoin, Litecoin, Dogecoin, and Cardano. `details.network` is omitted for formats that cannot identify mainnet/testnet. Selecting a network never proves an address belongs to it.
154
165
  - `allowTestnet: false` rejects identifiable testnet addresses, including when `network: 'testnet'` is also supplied. It is not an on-chain network check.
155
166
  - `allowBurnAddress` defaults to `false` and controls only the EVM all-zero address. It is not a comprehensive burn-address database. Other reserved/program addresses may be syntactically valid.
156
167
 
@@ -188,6 +199,8 @@ Formatting is for display, not validation. Never send to a shortened address. `s
188
199
 
189
200
  ## Development and verification
190
201
 
202
+ 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`.
203
+
191
204
  ```sh
192
205
  npm ci
193
206
  npm run check # lint, type checks, tests, build, differential and packed-consumer checks
@@ -201,7 +214,7 @@ For maintainers, `npm run prepare:release` runs the release checks and creates t
201
214
 
202
215
  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
216
 
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.
217
+ 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
218
 
206
219
  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
220
 
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-DF5Lt3lY.cjs");require("./shared/base-3sYui6r0.cjs"),require("./shared/base58check-BeCwnkGe.cjs"),require("./shared/base58-DV6hu8Kq.cjs"),require("./shared/bech32-Dk6Pnay4.cjs");class s extends e.UtxoValidator{constructor(){super({chain:"bitcoin",versions:{0:"mainnet",5:"mainnet",111:"testnet",196:"testnet"},hrps:{bc:"mainnet",tb:"testnet"}})}}exports.BitcoinValidator=s;
package/dist/bitcoin.mjs CHANGED
@@ -1 +1 @@
1
- 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-BrSxcH2x.mjs";import"./shared/base-CZZTeLCP.mjs";import"./shared/base58check-rMkz2cjy.mjs";import"./shared/base58-DY9-Un67.mjs";import"./shared/bech32-Cu41-5bd.mjs";class e extends s{constructor(){super({chain:"bitcoin",versions:{0:"mainnet",5:"mainnet",111:"testnet",196:"testnet"},hrps:{bc:"mainnet",tb:"testnet"}})}}export{e as BitcoinValidator};
package/dist/cardano.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t;!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-3sYui6r0.cjs"),e=require("./shared/base58-DV6hu8Kq.cjs"),r=require("./shared/bech32-Dk6Pnay4.cjs");const n=[24,256,65536];class s{constructor(t){this.data=t,this.offset=0}head(t,e=!1){if(this.offset>=this.data.length)throw new Error("Truncated CBOR");const r=this.data[this.offset++];if(r>>>5!==t)throw new Error("Invalid CBOR type");const s=31&r;if(s<24)return s;if(s>26)throw new Error("Unsupported CBOR length");const a=1<<s-24;if(this.offset+a>this.data.length)throw new Error("Truncated CBOR");let i=0;for(let t=0;t<a;t++)i=256*i+this.data[this.offset++];if(e&&i<n[s-24])throw new Error("Noncanonical CBOR argument");return i}bytes(t=!1){const e=this.head(2,t);if(this.offset+e>this.data.length)throw new Error("Truncated bytes");const r=this.data.slice(this.offset,this.offset+e);return this.offset+=e,r}end(){if(this.offset!==this.data.length)throw new Error("Trailing CBOR data")}}const a=[4294967295,65535,65535];class i extends t.AddressValidator{validateImplementation(t){if(/^(addr|stake)(_test)?1/i.test(t))return this.validateShelley(t);try{const r=function(t){try{const e=new s(t);if(2!==e.head(4)||24!==e.head(6))return null;const r=e.bytes();if(e.head(0)!==function(t){let e=4294967295;for(const r of t){e^=r;for(let t=0;t<8;t++)e=e>>>1^(1&e?3988292384:0)}return(4294967295^e)>>>0}(r))return null;e.end();const n=new s(r);if(3!==n.head(4)||28!==n.bytes().length)return null;const a=n.head(5);if(a>r.length)return null;const i=new Set;let o="mainnet";for(let t=0;t<a;t++){const t=n.head(0);if(i.has(t)||t>255)return null;i.add(t);const e=n.bytes();if(1===t){const t=new s(e);t.bytes(!0),t.end()}if(2===t){const t=new s(e);t.head(0,!0),t.end(),o="testnet"}}const d=n.head(0,!0);return 0!==d&&2!==d?null:(n.end(),o)}catch{return null}}(e.decodeBase58(t));if(r)return{valid:!0,blockchain:"cardano",details:{format:"byron",network:r,checksum:!0}}}catch{}return this.invalid()}validateShelley(t){const e=r.decodeBech32(t,256),n=e&&r.wordsToBytes(e.data);if(!e||e.encoding!==r.Bech32Encoding.BECH32||!n?.length)return this.invalid();const s=n[0]>>>4,a=15&n[0];if(0!==a&&1!==a)return this.invalid();const i=14===s||15===s,o=(i?"stake":"addr")+(0===a?"_test":"");if(e.hrp!==o)return this.invalid();let d=!1;return s<=3?d=57===n.length:6===s||7===s||i?d=29===n.length:4!==s&&5!==s||(d=this.validPointer(n)),d?{valid:!0,blockchain:"cardano",details:{format:i?"stake":"shelley",network:1===a?"mainnet":"testnet",checksum:!0}}:this.invalid()}validPointer(t){let e=29;for(const r of a){if(128===t[e])return!1;let n,s=0;do{if(e>=t.length)return!1;if(n=t[e++],s=128*s+(127&n),s>r)return!1}while(128&n)}return e===t.length}invalid(){return{valid:!1,error:"Invalid Cardano address structure, network, or checksum",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}format(e,r){return t.formatPlainAddress(e,r,8)}}exports.CardanoValidator=i;
package/dist/cardano.mjs CHANGED
@@ -1 +1 @@
1
- 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-CZZTeLCP.mjs";import{d as r}from"./shared/base58-DY9-Un67.mjs";import{d as s,w as a,B as i}from"./shared/bech32-Cu41-5bd.mjs";const o=[24,256,65536];class h{constructor(t){this.data=t,this.offset=0}head(t,e=!1){if(this.offset>=this.data.length)throw new Error("Truncated CBOR");const n=this.data[this.offset++];if(n>>>5!==t)throw new Error("Invalid CBOR type");const r=31&n;if(r<24)return r;if(r>26)throw new Error("Unsupported CBOR length");const s=1<<r-24;if(this.offset+s>this.data.length)throw new Error("Truncated CBOR");let a=0;for(let t=0;t<s;t++)a=256*a+this.data[this.offset++];if(e&&a<o[r-24])throw new Error("Noncanonical CBOR argument");return a}bytes(t=!1){const e=this.head(2,t);if(this.offset+e>this.data.length)throw new Error("Truncated bytes");const n=this.data.slice(this.offset,this.offset+e);return this.offset+=e,n}end(){if(this.offset!==this.data.length)throw new Error("Trailing CBOR data")}}const l=[4294967295,65535,65535];class d extends t{validateImplementation(t){if(/^(addr|stake)(_test)?1/i.test(t))return this.validateShelley(t);try{const e=function(t){try{const e=new h(t);if(2!==e.head(4)||24!==e.head(6))return null;const n=e.bytes();if(e.head(0)!==function(t){let e=4294967295;for(const n of t){e^=n;for(let t=0;t<8;t++)e=e>>>1^(1&e?3988292384:0)}return(4294967295^e)>>>0}(n))return null;e.end();const r=new h(n);if(3!==r.head(4)||28!==r.bytes().length)return null;const s=r.head(5);if(s>n.length)return null;const a=new Set;let i="mainnet";for(let t=0;t<s;t++){const t=r.head(0);if(a.has(t)||t>255)return null;a.add(t);const e=r.bytes();if(1===t){const t=new h(e);t.bytes(!0),t.end()}if(2===t){const t=new h(e);t.head(0,!0),t.end(),i="testnet"}}const o=r.head(0,!0);return 0!==o&&2!==o?null:(r.end(),i)}catch{return null}}(r(t));if(e)return{valid:!0,blockchain:"cardano",details:{format:"byron",network:e,checksum:!0}}}catch{}return this.invalid()}validateShelley(t){const e=s(t,256),n=e&&a(e.data);if(!e||e.encoding!==i.BECH32||!n?.length)return this.invalid();const r=n[0]>>>4,o=15&n[0];if(0!==o&&1!==o)return this.invalid();const h=14===r||15===r,l=(h?"stake":"addr")+(0===o?"_test":"");if(e.hrp!==l)return this.invalid();let d=!1;return r<=3?d=57===n.length:6===r||7===r||h?d=29===n.length:4!==r&&5!==r||(d=this.validPointer(n)),d?{valid:!0,blockchain:"cardano",details:{format:h?"stake":"shelley",network:1===o?"mainnet":"testnet",checksum:!0}}:this.invalid()}validPointer(t){let e=29;for(const n of l){if(128===t[e])return!1;let r,s=0;do{if(e>=t.length)return!1;if(r=t[e++],s=128*s+(127&r),s>n)return!1}while(128&r)}return e===t.length}invalid(){return{valid:!1,error:"Invalid Cardano address structure, network, or checksum",details:{errorCode:e.INVALID_FORMAT}}}format(t,e){return n(t,e,8)}}export{d as CardanoValidator};
package/dist/cosmos.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var 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-3sYui6r0.cjs"),s=require("./shared/bech32-Dk6Pnay4.cjs");const i={cosmos:"cosmos",osmosis:"osmo",celestia:"celestia",injective:"inj",sei:"sei"};class o extends e.AddressValidator{constructor(s="cosmos"){if(super(),this.chain=s,!e.COSMOS_CHAINS.includes(s))throw new RangeError(`Unsupported Cosmos chain: ${String(s)}`)}validateImplementation(o){const c=s.decodeBech32(o,90,i[this.chain]);if(c?.encoding===s.Bech32Encoding.BECH32){const e=s.wordsToBytes(c.data)?.length;if(20===e||32===e&&"injective"!==this.chain&&"celestia"!==this.chain)return{valid:!0,blockchain:this.chain,details:{format:"bech32",checksum:!0}}}return{valid:!1,error:"Invalid account prefix, checksum, length, or padding",details:{errorCode:e.ValidationError.INVALID_FORMAT}}}}exports.CosmosValidator=o;
package/dist/cosmos.mjs CHANGED
@@ -1 +1 @@
1
- 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-CZZTeLCP.mjs";import{d as a,B as o,w as t}from"./shared/bech32-Cu41-5bd.mjs";const c={cosmos:"cosmos",osmosis:"osmo",celestia:"celestia",injective:"inj",sei:"sei"};class n extends s{constructor(s="cosmos"){if(super(),this.chain=s,!e.includes(s))throw new RangeError(`Unsupported Cosmos chain: ${String(s)}`)}validateImplementation(s){const e=a(s,90,c[this.chain]);if(e?.encoding===o.BECH32){const s=t(e.data)?.length;if(20===s||32===s&&"injective"!==this.chain&&"celestia"!==this.chain)return{valid:!0,blockchain:this.chain,details:{format:"bech32",checksum:!0}}}return{valid:!1,error:"Invalid account prefix, checksum, length, or padding",details:{errorCode:i.INVALID_FORMAT}}}}export{n as CosmosValidator};
package/dist/dogecoin.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var 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-DF5Lt3lY.cjs");require("./shared/base-3sYui6r0.cjs"),require("./shared/base58check-BeCwnkGe.cjs"),require("./shared/base58-DV6hu8Kq.cjs"),require("./shared/bech32-Dk6Pnay4.cjs");class s extends e.UtxoValidator{constructor(){super({chain:"dogecoin",versions:{30:"mainnet",22:"mainnet",113:"testnet",196:"testnet"}})}}exports.DogecoinValidator=s;
package/dist/dogecoin.mjs CHANGED
@@ -1 +1 @@
1
- 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-BrSxcH2x.mjs";import"./shared/base-CZZTeLCP.mjs";import"./shared/base58check-rMkz2cjy.mjs";import"./shared/base58-DY9-Un67.mjs";import"./shared/bech32-Cu41-5bd.mjs";class e extends s{constructor(){super({chain:"dogecoin",versions:{30:"mainnet",22:"mainnet",113:"testnet",196:"testnet"}})}}export{e as DogecoinValidator};
package/dist/ethereum.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var 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-3sYui6r0.cjs");function e(r,e){if("string"!=typeof r)return!1;const t=r.startsWith("0x")?r.slice(2):r;return(void 0===e||t.length===e)&&/^[0-9a-fA-F]*$/.test(t)}function t(r){return r.startsWith("0x")?r.slice(2):r}const n=136,o=[0,1,62,28,27,36,44,6,55,20,3,10,43,25,39,41,45,15,21,8,18,2,61,56,14],s=new Uint32Array([1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648]),a=new Uint8Array(25);for(let r=0;r<5;r++)for(let e=0;e<5;e++)a[r+5*e]=e+(2*r+3*e)%5*5;const i=new Uint32Array(10),l=new Uint32Array(50);function d(r){for(let e=0;e<48;e+=2){for(let e=0;e<10;e++)i[e]=r[e]^r[e+10]^r[e+20]^r[e+30]^r[e+40];for(let e=0;e<5;e++){const t=(e+4)%5*2,n=(e+1)%5*2,o=i[t]^(i[n]<<1|i[n+1]>>>31),s=i[t+1]^(i[n+1]<<1|i[n]>>>31);for(let t=0;t<50;t+=10)r[2*e+t]^=o,r[2*e+t+1]^=s}for(let e=0;e<25;e++){const t=r[2*e],n=r[2*e+1],s=o[e],i=2*a[e];if(0===s)l[i]=t,l[i+1]=n;else if(s<32)l[i]=t<<s|n>>>32-s,l[i+1]=n<<s|t>>>32-s;else if(32===s)l[i]=n,l[i+1]=t;else{const r=s-32;l[i]=n<<r|t>>>32-r,l[i+1]=t<<r|n>>>32-r}}for(let e=0;e<50;e+=10)for(let t=0;t<5;t++){const n=e+2*t,o=e+(t+1)%5*2,s=e+(t+2)%5*2;r[n]=l[n]^~l[o]&l[s],r[n+1]=l[n+1]^~l[o+1]&l[s+1]}r[0]^=s[e],r[1]^=s[e+1]}}const c=new TextEncoder,f="0123456789abcdef";function u(r){if(/^[0-9]+$/.test(r))return r;const e=r.toLowerCase(),t=function(r){const e=c.encode(r),t=new Uint8Array((Math.floor(e.length/n)+1)*n);t.set(e),t[e.length]=1,t[t.length-1]|=128;const o=new Uint32Array(50);for(let r=0;r<t.length;r+=n){for(let e=0;e<n;e++)o[e>>2]^=t[r+e]<<8*(3&e);d(o)}let s="";for(let r=0;r<32;r++){const e=o[r>>2]>>>8*(3&r)&255;s+=f[e>>4]+f[15&e]}return s}(e);let o="";for(let r=0;r<e.length;r++)o+=t.charCodeAt(r)>=56?e[r].toUpperCase():e[r];return o}class h extends r.AddressValidator{validateImplementation(n,o){const s=t(n);if(40!==s.length)return{valid:!1,error:"Invalid length",details:{errorCode:r.ValidationError.INVALID_LENGTH}};if(!e(n))return{valid:!1,error:"Invalid hex characters",details:{errorCode:r.ValidationError.INVALID_CHARACTERS}};if(!o?.allowBurnAddress&&/^0+$/.test(s))return{valid:!1,error:"Burn address detected",details:{errorCode:r.ValidationError.BURN_ADDRESS}};const a=s===u(s);return!a&&(o?.strict||s!==s.toLowerCase()&&s!==s.toUpperCase())?{valid:!1,error:"Invalid checksum",details:{errorCode:r.ValidationError.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:a}}}format(n,o){const s=r.InputSanitizer.sanitize(n);if(!o?.checksum)return r.formatPlainAddress((a=s).startsWith("0x")?a:`0x${a}`,o);var a;if(!e(s,40))throw new Error("Expected a 20-byte hexadecimal address");return r.formatPlainAddress("0x"+u(t(s)),o)}}exports.EthereumValidator=h;
package/dist/ethereum.mjs CHANGED
@@ -1 +1 @@
1
- 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-CZZTeLCP.mjs";function o(e,t){if("string"!=typeof e)return!1;const r=e.startsWith("0x")?e.slice(2):e;return(void 0===t||r.length===t)&&/^[0-9a-fA-F]*$/.test(r)}function s(e){return e.startsWith("0x")?e.slice(2):e}const a=136,i=[0,1,62,28,27,36,44,6,55,20,3,10,43,25,39,41,45,15,21,8,18,2,61,56,14],l=new Uint32Array([1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648]),c=new Uint8Array(25);for(let e=0;e<5;e++)for(let t=0;t<5;t++)c[e+5*t]=t+(2*e+3*t)%5*5;const d=new Uint32Array(10),f=new Uint32Array(50);function h(e){for(let t=0;t<48;t+=2){for(let t=0;t<10;t++)d[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<5;t++){const r=(t+4)%5*2,n=(t+1)%5*2,o=d[r]^(d[n]<<1|d[n+1]>>>31),s=d[r+1]^(d[n+1]<<1|d[n]>>>31);for(let r=0;r<50;r+=10)e[2*t+r]^=o,e[2*t+r+1]^=s}for(let t=0;t<25;t++){const r=e[2*t],n=e[2*t+1],o=i[t],s=2*c[t];if(0===o)f[s]=r,f[s+1]=n;else if(o<32)f[s]=r<<o|n>>>32-o,f[s+1]=n<<o|r>>>32-o;else if(32===o)f[s]=n,f[s+1]=r;else{const e=o-32;f[s]=n<<e|r>>>32-e,f[s+1]=r<<e|n>>>32-e}}for(let t=0;t<50;t+=10)for(let r=0;r<5;r++){const n=t+2*r,o=t+(r+1)%5*2,s=t+(r+2)%5*2;e[n]=f[n]^~f[o]&f[s],e[n+1]=f[n+1]^~f[o+1]&f[s+1]}e[0]^=l[t],e[1]^=l[t+1]}}const u=new TextEncoder,A="0123456789abcdef";function C(e){if(/^[0-9]+$/.test(e))return e;const t=e.toLowerCase(),r=function(e){const t=u.encode(e),r=new Uint8Array((Math.floor(t.length/a)+1)*a);r.set(t),r[t.length]=1,r[r.length-1]|=128;const n=new Uint32Array(50);for(let e=0;e<r.length;e+=a){for(let t=0;t<a;t++)n[t>>2]^=r[e+t]<<8*(3&t);h(n)}let o="";for(let e=0;e<32;e++){const t=n[e>>2]>>>8*(3&e)&255;o+=A[t>>4]+A[15&t]}return o}(t);let n="";for(let e=0;e<t.length;e++)n+=r.charCodeAt(e)>=56?t[e].toUpperCase():t[e];return n}class w extends e{validateImplementation(e,r){const n=s(e);if(40!==n.length)return{valid:!1,error:"Invalid length",details:{errorCode:t.INVALID_LENGTH}};if(!o(e))return{valid:!1,error:"Invalid hex characters",details:{errorCode:t.INVALID_CHARACTERS}};if(!r?.allowBurnAddress&&/^0+$/.test(n))return{valid:!1,error:"Burn address detected",details:{errorCode:t.BURN_ADDRESS}};const a=n===C(n);return!a&&(r?.strict||n!==n.toLowerCase()&&n!==n.toUpperCase())?{valid:!1,error:"Invalid checksum",details:{errorCode:t.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:a}}}format(e,t){const a=r.sanitize(e);if(!t?.checksum)return n((i=a).startsWith("0x")?i:`0x${i}`,t);var i;if(!o(a,40))throw new Error("Expected a 20-byte hexadecimal address");return n("0x"+C(s(a)),t)}}export{w as EthereumValidator};
package/dist/evm.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var 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-3sYui6r0.cjs");class t extends e.EthereumValidator{validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain="bsc"),t}}class i extends e.EthereumValidator{validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain="avalanche"),t}}class r extends e.EthereumValidator{validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain="arbitrum"),t}}class n extends e.EthereumValidator{validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain="optimism"),t}}class l extends e.EthereumValidator{validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain="base"),t}}class s extends e.EthereumValidator{constructor(e="evm"){if(super(),this.chain=e,!a.EVM_CHAINS.includes(e))throw new RangeError(`Unsupported EVM chain: ${String(e)}`)}validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain=this.chain),t}}exports.ArbitrumValidator=r,exports.AvalancheValidator=i,exports.BaseValidator=l,exports.BscValidator=t,exports.EvmValidator=s,exports.OptimismValidator=n;