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.
- package/AGENTS.md +74 -65
- package/CHANGELOG.md +24 -2
- package/README.md +23 -10
- package/dist/bitcoin.cjs +1 -1
- package/dist/bitcoin.mjs +1 -1
- package/dist/cardano.cjs +1 -1
- package/dist/cardano.mjs +1 -1
- package/dist/cosmos.cjs +1 -1
- package/dist/cosmos.mjs +1 -1
- package/dist/dogecoin.cjs +1 -1
- package/dist/dogecoin.mjs +1 -1
- package/dist/ethereum.cjs +1 -1
- package/dist/ethereum.mjs +1 -1
- package/dist/evm.cjs +1 -1
- package/dist/evm.mjs +1 -1
- package/dist/formatters.cjs +1 -1
- package/dist/formatters.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +0 -2
- package/dist/index.d.mts +0 -2
- package/dist/index.mjs +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/litecoin.cjs +1 -1
- package/dist/litecoin.mjs +1 -1
- package/dist/move.cjs +1 -1
- package/dist/move.mjs +1 -1
- package/dist/near.cjs +1 -1
- package/dist/near.mjs +1 -1
- package/dist/ripple.cjs +1 -1
- package/dist/ripple.mjs +1 -1
- package/dist/shared/base-3sYui6r0.cjs +1 -0
- package/dist/shared/base-CZZTeLCP.mjs +1 -0
- package/dist/shared/base58-DV6hu8Kq.cjs +1 -0
- package/dist/shared/base58-DY9-Un67.mjs +1 -0
- package/dist/shared/base58check-BeCwnkGe.cjs +1 -0
- package/dist/shared/base58check-rMkz2cjy.mjs +1 -0
- package/dist/shared/bech32-Cu41-5bd.mjs +1 -0
- package/dist/shared/bech32-Dk6Pnay4.cjs +1 -0
- package/dist/shared/utxo-BrSxcH2x.mjs +1 -0
- package/dist/shared/utxo-DF5Lt3lY.cjs +1 -0
- package/dist/solana.cjs +1 -1
- package/dist/solana.mjs +1 -1
- package/dist/tron.cjs +1 -1
- package/dist/tron.mjs +1 -1
- 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
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
-
|
|
65
|
-
-
|
|
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.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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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?)` |
|
|
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 **
|
|
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
|
|
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 `
|
|
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
|
|
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,
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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;
|