validator0x 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +71 -0
- package/CHANGELOG.md +42 -0
- package/README.md +201 -101
- package/dist/bitcoin.cjs +1 -0
- package/dist/bitcoin.d.cts +1 -0
- package/dist/bitcoin.d.mts +1 -0
- package/dist/bitcoin.mjs +1 -0
- package/dist/cardano.cjs +1 -0
- package/dist/cardano.d.cts +1 -0
- package/dist/cardano.d.mts +1 -0
- package/dist/cardano.mjs +1 -0
- package/dist/cosmos.cjs +1 -0
- package/dist/cosmos.d.cts +1 -0
- package/dist/cosmos.d.mts +1 -0
- package/dist/cosmos.mjs +1 -0
- package/dist/dogecoin.cjs +1 -0
- package/dist/dogecoin.d.cts +1 -0
- package/dist/dogecoin.d.mts +1 -0
- package/dist/dogecoin.mjs +1 -0
- package/dist/ethereum.cjs +1 -0
- package/dist/ethereum.d.cts +1 -0
- package/dist/ethereum.d.mts +1 -0
- package/dist/ethereum.mjs +1 -0
- package/dist/evm.cjs +1 -0
- package/dist/evm.d.cts +1 -0
- package/dist/evm.d.mts +1 -0
- package/dist/evm.mjs +1 -0
- package/dist/formatters.cjs +1 -0
- package/dist/formatters.d.cts +1 -0
- package/dist/formatters.d.mts +1 -0
- package/dist/formatters.mjs +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +164 -0
- package/dist/index.d.mts +164 -0
- package/dist/index.mjs +1 -0
- package/dist/index.umd.js +1 -2
- package/dist/litecoin.cjs +1 -0
- package/dist/litecoin.d.cts +1 -0
- package/dist/litecoin.d.mts +1 -0
- package/dist/litecoin.mjs +1 -0
- package/dist/move.cjs +1 -0
- package/dist/move.d.cts +1 -0
- package/dist/move.d.mts +1 -0
- package/dist/move.mjs +1 -0
- package/dist/near.cjs +1 -0
- package/dist/near.d.cts +1 -0
- package/dist/near.d.mts +1 -0
- package/dist/near.mjs +1 -0
- package/dist/ripple.cjs +1 -0
- package/dist/ripple.d.cts +1 -0
- package/dist/ripple.d.mts +1 -0
- package/dist/ripple.mjs +1 -0
- package/dist/shared/base-BtbJMDNm.cjs +1 -0
- package/dist/shared/base-D2s8b6tx.mjs +1 -0
- package/dist/shared/base58-CjvbdRzA.mjs +1 -0
- package/dist/shared/base58-DaLDoaS-.cjs +1 -0
- package/dist/shared/base58check-BBzwHAsr.mjs +1 -0
- package/dist/shared/base58check-CE9wLmUB.cjs +1 -0
- package/dist/shared/bech32-ClvuyXIQ.cjs +1 -0
- package/dist/shared/bech32-DsNhxmrB.mjs +1 -0
- package/dist/shared/sha256-BbwKo1_x.mjs +1 -0
- package/dist/shared/sha256-CRbh7pIK.cjs +1 -0
- package/dist/shared/utxo-CRr3-5en.mjs +1 -0
- package/dist/shared/utxo-DhlBlYDy.cjs +1 -0
- package/dist/solana.cjs +1 -0
- package/dist/solana.d.cts +1 -0
- package/dist/solana.d.mts +1 -0
- package/dist/solana.mjs +1 -0
- package/dist/tron.cjs +1 -0
- package/dist/tron.d.cts +1 -0
- package/dist/tron.d.mts +1 -0
- package/dist/tron.mjs +1 -0
- package/package.json +245 -29
- package/dist/detectors/chain-detector.d.ts +0 -8
- package/dist/detectors/chain-detector.d.ts.map +0 -1
- package/dist/formatters/index.d.ts +0 -5
- package/dist/formatters/index.d.ts.map +0 -1
- package/dist/index.cjs.js +0 -2
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.d.ts +0 -20
- package/dist/index.d.ts.map +0 -1
- package/dist/index.esm.js +0 -2
- package/dist/index.esm.js.map +0 -1
- package/dist/index.umd.js.map +0 -1
- package/dist/security/sanitizer.d.ts +0 -4
- package/dist/security/sanitizer.d.ts.map +0 -1
- package/dist/types.d.ts +0 -36
- package/dist/types.d.ts.map +0 -1
- package/dist/utils/base58.d.ts +0 -3
- package/dist/utils/base58.d.ts.map +0 -1
- package/dist/utils/bech32.d.ts +0 -12
- package/dist/utils/bech32.d.ts.map +0 -1
- package/dist/utils/hex.d.ts +0 -4
- package/dist/utils/hex.d.ts.map +0 -1
- package/dist/utils/keccak256.d.ts +0 -2
- package/dist/utils/keccak256.d.ts.map +0 -1
- package/dist/utils/sha256.d.ts +0 -2
- package/dist/utils/sha256.d.ts.map +0 -1
- package/dist/validators/base.d.ts +0 -12
- package/dist/validators/base.d.ts.map +0 -1
- package/dist/validators/bitcoin.d.ts +0 -9
- package/dist/validators/bitcoin.d.ts.map +0 -1
- package/dist/validators/cardano.d.ts +0 -9
- package/dist/validators/cardano.d.ts.map +0 -1
- package/dist/validators/dogecoin.d.ts +0 -7
- package/dist/validators/dogecoin.d.ts.map +0 -1
- package/dist/validators/ethereum.d.ts +0 -10
- package/dist/validators/ethereum.d.ts.map +0 -1
- package/dist/validators/evm.d.ts +0 -18
- package/dist/validators/evm.d.ts.map +0 -1
- package/dist/validators/litecoin.d.ts +0 -9
- package/dist/validators/litecoin.d.ts.map +0 -1
- package/dist/validators/polygon.d.ts +0 -6
- package/dist/validators/polygon.d.ts.map +0 -1
- package/dist/validators/ripple.d.ts +0 -7
- package/dist/validators/ripple.d.ts.map +0 -1
- package/dist/validators/solana.d.ts +0 -7
- package/dist/validators/solana.d.ts.map +0 -1
package/AGENTS.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# validator0x: instructions for AI coding agents
|
|
2
|
+
|
|
3
|
+
This file serves two audiences: agents integrating the installed npm package, and agents changing this repository. Apply only the relevant section. Read `README.md` and the installed package version before using an API. The consuming project's instructions and the user's explicit requirements take precedence.
|
|
4
|
+
|
|
5
|
+
## Integrating the npm package
|
|
6
|
+
|
|
7
|
+
1. Use the public package exports. Import from `validator0x` for multiple chains, or from a documented family entrypoint such as `validator0x/bitcoin` or `validator0x/solana` for smaller bundles. Never import private `src/` or `dist/` paths.
|
|
8
|
+
2. The package is synchronous and offline. It needs no API key, RPC connection, wallet connection, Node crypto polyfill, or runtime dependency. Node.js 22+ and modern ES2020 browsers/workers are supported; browser runtimes need BigInt and TextEncoder.
|
|
9
|
+
3. Take the intended chain from application state or the user. For dynamic chain values, narrow with `isSupportedChain` before calling `validateAddress`, `validateBatch`, or `formatAddress`; unsupported chains throw.
|
|
10
|
+
4. Pass untrusted addresses directly to `validateAddress`. It accepts `unknown` and returns `ValidationResult`. Check `result.valid` before using an address. For rejected input, use `result.error` and `result.details?.errorCode`, not string comparisons with implementation-specific messages.
|
|
11
|
+
5. Validation trims outer ASCII spaces but does not return a normalized address. After successful validation of a string, use `input.trim()` for subsequent operations. Do not lowercase Base58 addresses or silently repair checksums, Unicode, missing characters, or invalid input.
|
|
12
|
+
6. `strict: true` requires exact EIP-55 capitalization for EVM addresses, and canonical lowercase AIP-40 representation for Aptos. Mixed-case EVM checksums and mandatory Base58Check/Bech32 checksums are always checked. Choose strict mode deliberately; do not enable it blindly for existing lowercase EVM input flows.
|
|
13
|
+
7. `network: 'mainnet' | 'testnet' | 'auto'` and `allowTestnet` only filter networks encoded in an address. EVM, Solana, TRON, Cosmos, Sui, Aptos, and NEAR cannot establish mainnet/testnet from address syntax. An absent `details.network` means unknown, not mainnet.
|
|
14
|
+
8. `detectBlockchain` returns a chain, an array of format candidates, or `null`. Never pick the first candidate automatically for a payment. EVM chains, Sui/Aptos, and some UTXO/NEAR formats overlap. Plain NEAR names are deliberately excluded from detection.
|
|
15
|
+
9. Validation does not prove ownership, account existence, spendability, token compatibility, or recipient safety. Handle application-specific destination tags, memos, RPC checks, and asset/network selection separately. `allowBurnAddress` only controls the EVM all-zero address.
|
|
16
|
+
10. Formatting is display logic. `shortenAddress` output must never become a transaction destination. `formatAddress` does not generally validate input; EVM checksum formatting and Aptos formatting can throw on malformed input. Validate first.
|
|
17
|
+
11. Keep client bundle size small: reuse a family validator instance when only one chain is needed. Do not add an entire chain SDK just to wrap these checks.
|
|
18
|
+
12. Add consumer tests for valid input, invalid checksum/encoding, unsupported chain input, network policy, and ambiguous detection as relevant to the integration. Use the published protocol fixtures or verified addresses rather than invented strings.
|
|
19
|
+
|
|
20
|
+
### Safe dynamic-input example
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { EVM_CHAINS, isSupportedChain, validateAddress } from 'validator0x';
|
|
24
|
+
|
|
25
|
+
export function checkRecipient(input: unknown, chain: unknown) {
|
|
26
|
+
if (!isSupportedChain(chain)) {
|
|
27
|
+
return { ok: false as const, error: 'Choose a supported chain' };
|
|
28
|
+
}
|
|
29
|
+
const result = validateAddress(input, chain, { network: 'mainnet' });
|
|
30
|
+
if (!result.valid || typeof input !== 'string') {
|
|
31
|
+
return { ok: false as const, error: result.error ?? 'Invalid address' };
|
|
32
|
+
}
|
|
33
|
+
// The application must separately verify the selected asset and actual network.
|
|
34
|
+
if (chain === 'cardano' && result.details?.format === 'stake') {
|
|
35
|
+
return { ok: false as const, error: 'Choose a Cardano payment address' };
|
|
36
|
+
}
|
|
37
|
+
const trimmed = input.trim();
|
|
38
|
+
const isEvm = EVM_CHAINS.some(candidate => candidate === chain);
|
|
39
|
+
const destination = isEvm && !trimmed.startsWith('0x') ? '0x' + trimmed : trimmed;
|
|
40
|
+
return { ok: true as const, address: destination, chain };
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Small single-family example
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { BitcoinValidator } from 'validator0x/bitcoin';
|
|
48
|
+
|
|
49
|
+
const bitcoin = new BitcoinValidator();
|
|
50
|
+
const result = bitcoin.validate('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa', {
|
|
51
|
+
network: 'mainnet',
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Discovering this file after installation
|
|
56
|
+
|
|
57
|
+
The npm archive includes this file. Resolve it using `require.resolve('validator0x/AGENTS.md')` or read `node_modules/validator0x/AGENTS.md`. Merely installing a package does not guarantee that an agent automatically reads its instructions; explicitly point the agent to this file.
|
|
58
|
+
|
|
59
|
+
## Contributing to this repository
|
|
60
|
+
|
|
61
|
+
- Use Node.js 22.13+ or a supported newer LTS for development. Install the locked development dependencies with `npm ci`.
|
|
62
|
+
- Preserve zero runtime dependencies, synchronous offline behavior, and existing public exports. Never add telemetry or address logging. Cryptographic/encoding code lives in `src/utils/`; family validators in `src/validators/`; the shared registry in `src/registry.ts`; public types in `src/types.ts`.
|
|
63
|
+
- Route validation through `AddressValidator.validate` so sanitization, options, and network policy are consistent. Preserve the 256-character bound before decoding. Check decoded version bytes, payload sizes, checksum variants, and padding rather than relying on a prefix or regex alone.
|
|
64
|
+
- When adding chain support, verify current primary specifications. Update types, the registry, detection behavior, README scope, and positive/negative tests. Do not claim support for a chain's distinct address formats just because one format matches EVM.
|
|
65
|
+
- When adding public entrypoints, update `package.json` exports/typesVersions, `rollup.config.mjs`, and `scripts/declarations.mjs` together. Declaration re-exports must preserve type identity across root and family imports. Keep the package-content allowlist and consumer checks in `scripts/test-package.mjs` aligned.
|
|
66
|
+
- Keep `@noble/hashes` and `@scure/base` development-only. They are independent test oracles, not runtime imports. Test changes to hash/encoding code against independent implementations and official vectors.
|
|
67
|
+
- Required release checks: `npm run check`, `npm run test:coverage`, and `npm audit`. `npm run check` includes lint, source/test type checking, unit tests, build, differential tests, and installation of the actual tarball into fresh consumers. Coverage includes crypto and public APIs; do not weaken coverage or size thresholds just to make a change pass.
|
|
68
|
+
- Tests generate `.coverage/`; builds generate `dist/`; release archives end in `.tgz`. Do not commit generated output, credentials, npm tokens, or unrelated local changes. Legacy tracked `coverage/` files are not current test evidence.
|
|
69
|
+
- Inspect `git status` before staging. Stage the intended source, tests, configuration, and documentation explicitly; preserve unrelated user edits.
|
|
70
|
+
- For release steps, consult `RELEASING.md` in the repository. Prepare and verify the archive before asking for approval. Publishing, moving npm dist-tags, or unpublishing requires the maintainer's explicit authorization. A request to prepare a release is not permission to publish. The maintainer completes npm login and any MFA flow directly; never ask them to paste passwords, tokens, or one-time codes into the chat.
|
|
71
|
+
- Report what was tested, package sizes, limitations, and whether changes were committed, pushed, or published. Never claim the package is bug-free or formally audited.
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
- JavaScript EVM and Cosmos constructors reject unsupported family identifiers.
|
|
6
|
+
- Sparse batches produce an invalid result at each missing index.
|
|
7
|
+
- Cardano pointer fields enforce the strict ledger limits for slots and indices.
|
|
8
|
+
- Root and family imports share validator classes within each module format. The packed consumer checks exercise a bundled ESM family validator in a real Chrome worker.
|
|
9
|
+
- Payment-form examples reject Cardano reward addresses and prefix validated EVM destinations.
|
|
10
|
+
|
|
11
|
+
## 0.3.0 - 2026-11-13
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- TRON, Cosmos Hub, Osmosis, Celestia, Injective, Sei (Bech32), Sui, Aptos, and NEAR validators.
|
|
16
|
+
- Generic EVM support plus Fantom, Sonic, Gnosis, Celo, Cronos, Moonbeam, Moonriver, zkSync, Linea, Scroll, Mantle, Blast, opBNB, Zora, and World Chain identifiers.
|
|
17
|
+
- Mainnet/testnet checks for encoded UTXO and Cardano networks; readonly batch input; safe `unknown` address input; `SUPPORTED_CHAINS` and `isSupportedChain`.
|
|
18
|
+
- Native ESM/CommonJS exports with declarations for each module system; small family-specific entrypoints; browser UMD distribution; package size budgets.
|
|
19
|
+
- Protocol vector, independent codec/crypto, packed consumer, and cross-platform CI checks.
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- Validation options now reach every validator. EVM strict mode requires the exact checksum.
|
|
24
|
+
- Bitcoin/Litecoin witness programs are converted from five-bit words before checking length; padding, encoding/version combinations, and future witness lengths are validated.
|
|
25
|
+
- Base58 address versions are verified, SHA-256 works at block-padding boundaries, and all-zero Base58 encoding round-trips correctly.
|
|
26
|
+
- Cardano requires correct headers, payload sizes, prefixes, network tags, and canonical padding; Byron requires a complete CBOR envelope and CRC32 rather than a plausible Base58 length.
|
|
27
|
+
- EVM/Solana and other shared-format addresses no longer imply mainnet. Detector results preserve format ambiguity and accept untrusted input safely.
|
|
28
|
+
- Unsupported chain names cannot access Object.prototype members. Input limits apply before trimming; control and invisible characters are rejected.
|
|
29
|
+
- Normalization and checksum helpers cover every EVM chain. Shortening handles non-EVM prefixes and rejects invalid lengths. The error enum is available at runtime.
|
|
30
|
+
|
|
31
|
+
### Migration from 0.2.x
|
|
32
|
+
|
|
33
|
+
- Malformed addresses previously accepted by incomplete checks now fail. Replace fabricated test fixtures with published valid vectors.
|
|
34
|
+
- `strict: true` now rejects noncanonical uniform-case EVM input. Use checksum formatting on validated hex if canonical presentation is needed.
|
|
35
|
+
- Default network selection is `auto`; testnet UTXO addresses are now recognized. Set `network: 'mainnet'` or `allowTestnet: false` to reject identifiable testnet addresses.
|
|
36
|
+
- `details.network` is absent when the address format cannot encode it. Detection may return more candidates; do not depend on a fixed EVM array length or infer chain ownership.
|
|
37
|
+
- EVM zero-address rejection remains the default; `allowBurnAddress: true` opts in to syntactic validation.
|
|
38
|
+
- Public package imports are described by `exports`. Replace imports into private `dist/` paths with the root or documented family entrypoints.
|
|
39
|
+
- Supported Node.js baseline is 22; browsers/workers need ES2020, BigInt, and TextEncoder. Development tools require Node 22.13+ (or 24+).
|
|
40
|
+
- Tests now run with Vitest. Coverage is generated in `.coverage/` and includes crypto and the public API. Generated legacy coverage is not used as evidence of current coverage.
|
|
41
|
+
|
|
42
|
+
Published to the public npm registry with the `latest` tag. Registry integrity matched the approved archive; a fresh registry install passed the CommonJS/ESM entrypoints and agent-instruction discovery checks.
|
package/README.md
CHANGED
|
@@ -1,124 +1,224 @@
|
|
|
1
1
|
# validator0x
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Small, synchronous wallet address validation for **38 chain identifiers**, with **zero runtime dependencies**. Works offline in Node.js 22+, modern browsers, and workers supporting ES2020, BigInt, and TextEncoder. Includes native ESM, CommonJS, browser UMD, and TypeScript declarations.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Validation checks address encoding, payload structure, and checksums where the format has one. It does **not** establish ownership, account existence, balance, network connectivity, or whether an address can safely receive a particular asset.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- **Batch Validation**: Validate multiple addresses in a single call for better performance.
|
|
9
|
-
- **Zero Dependencies**: Lightweight and secure. All cryptographic primitives (Keccak-256, Base58, Bech32) are implemented internally.
|
|
10
|
-
- **Security Focused**:
|
|
11
|
-
- Input sanitization against control characters and length attacks.
|
|
12
|
-
- Burn address detection (e.g., `0x00...00` or System Programs).
|
|
13
|
-
- **Comprehensive Formatting**: Checksumming, lowercasing, and safe shortening.
|
|
14
|
-
- **TypeScript First**: Full type definitions included.
|
|
7
|
+
## Install and use
|
|
15
8
|
|
|
16
|
-
|
|
9
|
+
Install `validator0x` for the latest published release. See [migration notes](./CHANGELOG.md) before upgrading from 0.2.x.
|
|
17
10
|
|
|
18
|
-
```
|
|
11
|
+
```sh
|
|
19
12
|
npm install validator0x
|
|
20
13
|
```
|
|
21
14
|
|
|
22
|
-
|
|
15
|
+
```ts
|
|
16
|
+
import { validateAddress, validateBatch, ValidationError } from 'validator0x';
|
|
23
17
|
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
const result = validateAddress(
|
|
19
|
+
'0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
|
|
20
|
+
'base',
|
|
21
|
+
{ strict: true },
|
|
22
|
+
);
|
|
26
23
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
console.log('Valid Address!', result.details);
|
|
31
|
-
} else {
|
|
32
|
-
console.error('Invalid:', result.error); // e.g. "Invalid checksum"
|
|
24
|
+
if (!result.valid) {
|
|
25
|
+
console.log(result.error, result.details?.errorCode);
|
|
26
|
+
// e.g. ValidationError.INVALID_CHECKSUM
|
|
33
27
|
}
|
|
34
28
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
const results = validateBatch(
|
|
30
|
+
['TNPeeaaFB7K9cmo4uQpcU32zGK8G1NYqeL', 'invalid'],
|
|
31
|
+
'tron',
|
|
32
|
+
);
|
|
33
|
+
console.log(results.map(result => result.valid)); // [true, false]
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
CommonJS works too:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
const { validateAddress } = require('validator0x');
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Integrate into an application
|
|
43
|
+
|
|
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
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { EVM_CHAINS, isSupportedChain, validateAddress } from 'validator0x';
|
|
48
|
+
|
|
49
|
+
export function checkRecipient(address: unknown, chain: unknown) {
|
|
50
|
+
if (!isSupportedChain(chain)) {
|
|
51
|
+
return { ok: false as const, error: 'Choose a supported chain' };
|
|
52
|
+
}
|
|
53
|
+
const result = validateAddress(address, chain, { network: 'mainnet' });
|
|
54
|
+
if (!result.valid || typeof address !== 'string') {
|
|
55
|
+
return { ok: false as const, error: result.error ?? 'Invalid address' };
|
|
56
|
+
}
|
|
57
|
+
if (chain === 'cardano' && result.details?.format === 'stake') {
|
|
58
|
+
return { ok: false as const, error: 'Choose a Cardano payment address' };
|
|
59
|
+
}
|
|
60
|
+
const trimmed = address.trim();
|
|
61
|
+
const isEvm = EVM_CHAINS.some(candidate => candidate === chain);
|
|
62
|
+
const destination = isEvm && !trimmed.startsWith('0x') ? '0x' + trimmed : trimmed;
|
|
63
|
+
return { ok: true as const, address: destination, chain };
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The validator trims outer ASCII spaces internally; use the trimmed string after successful validation. Keep the original capitalization for case-sensitive addresses. Apply asset/network selection and any on-chain recipient checks separately. The package can be used directly in browser forms, server handlers, and workers without initialization or a wallet SDK.
|
|
68
|
+
|
|
69
|
+
| Public API | Result and behavior |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `validateAddress(input, chain, options?)` | `ValidationResult`; invalid addresses return `valid: false` |
|
|
72
|
+
| `validateBatch(inputs, chain, options?)` | Results in input order; accepts a readonly array |
|
|
73
|
+
| `isSupportedChain(value)` | Boolean and TypeScript type guard for unknown chain input |
|
|
74
|
+
| `SUPPORTED_CHAINS` | Frozen list of supported identifiers; useful for a chain selector |
|
|
75
|
+
| `detectBlockchain(input, options?)` | One chain, candidate array, or `null`; never proof of chain ownership |
|
|
76
|
+
| `formatAddress(address, chain, options?)` | Display string; validation is a separate step |
|
|
77
|
+
| `ValidationError` | Runtime enum for `result.details?.errorCode` |
|
|
78
|
+
|
|
79
|
+
### AI-assisted integration
|
|
80
|
+
|
|
81
|
+
Point your coding agent to [AGENTS.md](./AGENTS.md). It contains integration examples, API rules, chain ambiguity and network limitations, bundle guidance, and repository contribution instructions. It ships inside the npm package and is discoverable after installation:
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
node -p "require.resolve('validator0x/AGENTS.md')"
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Ask the agent to read that file before implementing an integration. Instructions inside installed packages are not automatically loaded by every AI tool.
|
|
88
|
+
|
|
89
|
+
## Keep your bundle small
|
|
90
|
+
|
|
91
|
+
Import a validator directly when your project needs only one family:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import { BitcoinValidator } from 'validator0x/bitcoin';
|
|
95
|
+
|
|
96
|
+
const bitcoin = new BitcoinValidator();
|
|
97
|
+
bitcoin.validate('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa', {
|
|
98
|
+
network: 'mainnet',
|
|
39
99
|
});
|
|
40
|
-
|
|
100
|
+
```
|
|
41
101
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
102
|
+
All direct imports support ESM, CommonJS, and TypeScript:
|
|
103
|
+
|
|
104
|
+
| Import | Exports |
|
|
105
|
+
| --- | --- |
|
|
106
|
+
| `validator0x/ethereum` | `EthereumValidator` |
|
|
107
|
+
| `validator0x/evm` | `EvmValidator`, existing BSC/Avalanche/Arbitrum/Optimism/Base classes |
|
|
108
|
+
| `validator0x/bitcoin` | `BitcoinValidator` |
|
|
109
|
+
| `validator0x/litecoin` | `LitecoinValidator` |
|
|
110
|
+
| `validator0x/dogecoin` | `DogecoinValidator` |
|
|
111
|
+
| `validator0x/solana` | `SolanaValidator` |
|
|
112
|
+
| `validator0x/ripple` | `RippleValidator` |
|
|
113
|
+
| `validator0x/cardano` | `CardanoValidator` |
|
|
114
|
+
| `validator0x/tron` | `TronValidator` |
|
|
115
|
+
| `validator0x/cosmos` | `CosmosValidator` |
|
|
116
|
+
| `validator0x/move` | `SuiValidator`, `AptosValidator` |
|
|
117
|
+
| `validator0x/near` | `NearValidator` |
|
|
118
|
+
| `validator0x/formatters` | `shortenAddress`, `normalizeAddress`, `addChecksum` |
|
|
119
|
+
|
|
120
|
+
For example, `new CosmosValidator('osmosis')` or `new EvmValidator('sonic')`. Existing validator classes, including `PolygonValidator`, remain available from the root import.
|
|
121
|
+
|
|
122
|
+
The full minified ESM bundle is approximately **7.2 kB gzip**, and the Solana-only entry approximately **1.2 kB gzip**. `npm run test:package` prints exact sizes and enforces budgets of 12 kB and 3 kB respectively. Runtime dependencies, RPC requests, polyfills, and chain SDKs: **none**. These sizes include shared modules. Root and family imports share validator constructors within each module format.
|
|
123
|
+
|
|
124
|
+
## Supported address formats
|
|
125
|
+
|
|
126
|
+
| Chain identifier | Scope |
|
|
127
|
+
| --- | --- |
|
|
128
|
+
| `ethereum`, `polygon`, `bsc`, `avalanche`, `arbitrum`, `optimism`, `base` | Ethereum 20-byte hexadecimal addresses; EIP-55 checksum |
|
|
129
|
+
| `evm`, `fantom`, `sonic`, `gnosis`, `celo`, `cronos`, `moonbeam`, `moonriver`, `zksync`, `linea`, `scroll`, `mantle`, `blast`, `opbnb`, `zora`, `worldchain` | Same Ethereum/EIP-55 address rules |
|
|
130
|
+
| `bitcoin` | Base58Check P2PKH/P2SH; SegWit v0; Bech32m v1-16, including Taproot; mainnet and testnet |
|
|
131
|
+
| `litecoin` | Base58Check P2PKH/P2SH (including legacy shared P2SH prefixes); standard witness v0-16; mainnet and testnet |
|
|
132
|
+
| `dogecoin` | Base58Check P2PKH/P2SH; mainnet and testnet |
|
|
133
|
+
| `solana` | Base58 decoding to exactly 32 bytes, including program addresses and PDAs |
|
|
134
|
+
| `cardano` | Shelley base, enterprise, pointer, and stake addresses; header/network/length/padding checks; Byron CBOR envelope and CRC32 |
|
|
135
|
+
| `ripple` | XRP classic account addresses with the XRP Base58 alphabet and checksum |
|
|
136
|
+
| `tron` | 34-character Base58Check or 42-character hex beginning with `41` |
|
|
137
|
+
| `cosmos`, `osmosis`, `sei` | Bech32 account prefixes `cosmos`, `osmo`, `sei`; 20- or 32-byte payloads |
|
|
138
|
+
| `celestia`, `injective` | Bech32 account prefixes `celestia`, `inj`; 20-byte payloads |
|
|
139
|
+
| `sui` | `0x` followed by exactly 64 hex digits |
|
|
140
|
+
| `aptos` | Full 32-byte hexadecimal addresses or special addresses `0x0` through `0xf`; strict canonical AIP-40 mode |
|
|
141
|
+
| `near` | 2-64 character account IDs with lowercase letters, numbers, and valid separators; named, implicit, Ethereum-like, deterministic, and universal forms |
|
|
142
|
+
|
|
143
|
+
`avalanche` covers C-Chain addresses. For additional chains using standard Ethereum addresses, use `evm`; chain-specific checksum schemes such as EIP-1191 are outside its scope. For Sei's EVM format, use `evm`; `sei` validates its Bech32 format.
|
|
144
|
+
|
|
145
|
+
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.
|
|
146
|
+
|
|
147
|
+
## Options and errors
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
validateAddress(address, chain, {
|
|
151
|
+
strict: true,
|
|
152
|
+
network: 'mainnet', // 'mainnet' | 'testnet' | 'auto'
|
|
153
|
+
allowTestnet: false,
|
|
154
|
+
allowBurnAddress: false,
|
|
155
|
+
});
|
|
156
|
+
```
|
|
45
157
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
158
|
+
- `strict` defaults to `false`. On EVM, `true` requires the exact EIP-55 capitalization, including the rare valid all-lowercase/all-uppercase checksums. Invalid mixed-case EVM checksums are always rejected. On Aptos, strict mode requires lowercase AIP-40 canonical representation. Other formats always verify their mandatory checksums.
|
|
159
|
+
- `network` defaults to `auto`. It filters networks **only when encoded in the address**, currently Bitcoin, Litecoin, Dogecoin, and Cardano. `details.network` is omitted for formats that cannot identify mainnet/testnet. Selecting a network never proves an address belongs to it.
|
|
160
|
+
- `allowTestnet: false` rejects identifiable testnet addresses, including when `network: 'testnet'` is also supplied. It is not an on-chain network check.
|
|
161
|
+
- `allowBurnAddress` defaults to `false` and controls only the EVM all-zero address. It is not a comprehensive burn-address database. Other reserved/program addresses may be syntactically valid.
|
|
162
|
+
|
|
163
|
+
`validateAddress` accepts `unknown` input and returns `{ valid: false, error, details: { errorCode } }` for malformed addresses. Outer ASCII spaces are trimmed. Inputs longer than 256 characters, control characters, Unicode, and invisible characters are rejected before decoding. `validateBatch` accepts a readonly array and preserves order. Unsupported chain identifiers throw a descriptive error; use `isSupportedChain(value)` for dynamic user input. `SUPPORTED_CHAINS` is a frozen list.
|
|
164
|
+
|
|
165
|
+
## Detection
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
import { detectBlockchain } from 'validator0x';
|
|
169
|
+
|
|
170
|
+
// 'bitcoin'
|
|
171
|
+
detectBlockchain('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq');
|
|
172
|
+
|
|
173
|
+
// An array of EVM candidates, since the format is shared.
|
|
174
|
+
detectBlockchain('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045');
|
|
52
175
|
```
|
|
53
176
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
```bash
|
|
70
|
-
npm install
|
|
71
|
-
npm test
|
|
72
|
-
npm run build
|
|
177
|
+
Returns one chain, an array of candidates, or `null`. The optional second argument accepts validation options. Ambiguity also exists between Sui/Aptos, shared UTXO prefixes, and lowercase EVM/NEAR addresses. Detection never chooses the intended network for a transfer. Plain NEAR names such as `root` are omitted from auto-detection to avoid matching arbitrary text; explicit NEAR validation accepts them.
|
|
178
|
+
|
|
179
|
+
## Formatting
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
import { formatAddress, shortenAddress, normalizeAddress } from 'validator0x';
|
|
183
|
+
|
|
184
|
+
formatAddress('0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 'ethereum', {
|
|
185
|
+
checksum: true,
|
|
186
|
+
shorten: true,
|
|
187
|
+
}); // '0xd8dA...6045'
|
|
188
|
+
|
|
189
|
+
shortenAddress('HN7cABqLq46Es1jh92dQQy4aWDtG751BHhP1K2HWT7k1'); // 'HN7c...T7k1'
|
|
190
|
+
normalizeAddress('0xABCD', 'base'); // '0xabcd'
|
|
73
191
|
```
|
|
74
192
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
3. **Run Tests**:
|
|
104
|
-
```bash
|
|
105
|
-
npm test
|
|
106
|
-
# Run specific test file
|
|
107
|
-
npx jest tests/ethereum.test.ts
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
4. **Lint & Format**:
|
|
111
|
-
```bash
|
|
112
|
-
npm run lint
|
|
113
|
-
npm run format
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
5. **Build**:
|
|
117
|
-
```bash
|
|
118
|
-
npm run build
|
|
119
|
-
# Output will be in /dist
|
|
120
|
-
```
|
|
193
|
+
Formatting is for display, not validation. Never send to a shortened address. `shortenLength` must be a positive integer; short strings are left intact. The `0x` prefix does not count against the leading character limit. EVM checksum formatting throws on malformed hex instead of returning misleading output. Aptos formatting returns canonical AIP-40 representation. `normalizeAddress` lowercases EVM/Sui/Aptos and preserves case-sensitive encodings.
|
|
194
|
+
|
|
195
|
+
## Development and verification
|
|
196
|
+
|
|
197
|
+
The packed browser test uses an installed Google Chrome stable browser. On a development host without Chrome, install it with `npx playwright-core install chrome` after `npm ci`.
|
|
198
|
+
|
|
199
|
+
```sh
|
|
200
|
+
npm ci
|
|
201
|
+
npm run check # lint, type checks, tests, build, differential and packed-consumer checks
|
|
202
|
+
npm run test:coverage # includes crypto and public API; writes .coverage/
|
|
203
|
+
npm run benchmark # measures the existing production build
|
|
204
|
+
npm audit
|
|
205
|
+
npm pack # rebuilds and produces a local release archive
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
For maintainers, `npm run prepare:release` runs the release checks and creates the verified archive. See [RELEASING.md on GitHub](https://github.com/Samarth208P/validator0x/blob/main/RELEASING.md) for the dry run, maintainer login, approval, and publication steps. Pushing commits does not publish to npm.
|
|
209
|
+
|
|
210
|
+
Tests include the complete native witness vectors from [BIP-350](https://bips.dev/350/), Shelley/stake vectors from [CIP-19](https://cips.cardano.org/cip/CIP-19), and EIP-55 checksum cases. Differential checks compare SHA-256 to Node crypto, Keccak-256 to `@noble/hashes`, and Base58/Bech32 to `@scure/base` across block boundaries, address versions, payload lengths, and malformed cases. Reference libraries are development-only dependencies.
|
|
211
|
+
|
|
212
|
+
Package checks install the actual tarball into a temporary consumer and verify all ESM/CommonJS entrypoints, TypeScript NodeNext/Bundler/legacy resolution, UMD execution without Node globals, and a bundled Solana ESM consumer in a real Chrome module worker. CI runs on Linux and Windows with Node 22, 24, and 26. Local checks do not substitute for executing that CI matrix.
|
|
213
|
+
|
|
214
|
+
The development-only `minimatch` override selects the patched 11.x release for the lint dependency tree; remove it once upstream ranges include the fix. Runtime consumers do not install it.
|
|
215
|
+
|
|
216
|
+
See [CHANGELOG.md](./CHANGELOG.md) for migration notes. These checks improve reliability but are not a formal audit or a guarantee of error-free behavior.
|
|
217
|
+
|
|
218
|
+
## Specification references
|
|
219
|
+
|
|
220
|
+
Address rules reviewed on **2026-11-13** against [EIP-55](https://eips.ethereum.org/EIPS/eip-55), [TRON accounts](https://developers.tron.network/docs/account), [Sui address requirements](https://www.docs.sui.io/develop/testing-debugging/common-errors), [Aptos AIP-40 SDK documentation](https://aptos-labs.github.io/aptos-rust-sdk/aptos_sdk/types/struct.AccountAddress.html), [NEAR account IDs](https://docs.near.org/protocol/accounts-contracts/account-id), [Cosmos ADR-028](https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-028-public-key-addresses.md), and the [Cosmos chain registry](https://github.com/cosmos/chain-registry).
|
|
121
221
|
|
|
122
222
|
## License
|
|
123
223
|
|
|
124
|
-
MIT
|
|
224
|
+
MIT. The CIP-19 fixture source is credited under CC-BY-4.0; see the [CIP-19 source and license](https://cips.cardano.org/cip/CIP-19).
|
package/dist/bitcoin.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./shared/utxo-DhlBlYDy.cjs");require("./shared/base-BtbJMDNm.cjs"),require("./shared/base58check-CE9wLmUB.cjs"),require("./shared/base58-DaLDoaS-.cjs"),require("./shared/sha256-CRbh7pIK.cjs"),require("./shared/bech32-ClvuyXIQ.cjs");class s extends e.UtxoValidator{constructor(){super({chain:"bitcoin",versions:{0:"mainnet",5:"mainnet",111:"testnet",196:"testnet"},hrps:{bc:"mainnet",tb:"testnet"}})}}exports.BitcoinValidator=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BitcoinValidator } from './index.cjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BitcoinValidator } from './index.mjs';
|
package/dist/bitcoin.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{U as s}from"./shared/utxo-CRr3-5en.mjs";import"./shared/base-D2s8b6tx.mjs";import"./shared/base58check-BBzwHAsr.mjs";import"./shared/base58-CjvbdRzA.mjs";import"./shared/sha256-BbwKo1_x.mjs";import"./shared/bech32-DsNhxmrB.mjs";class e extends s{constructor(){super({chain:"bitcoin",versions:{0:"mainnet",5:"mainnet",111:"testnet",196:"testnet"},hrps:{bc:"mainnet",tb:"testnet"}})}}export{e as BitcoinValidator};
|
package/dist/cardano.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=require("./shared/base-BtbJMDNm.cjs"),e=require("./shared/base58-DaLDoaS-.cjs"),r=require("./shared/bech32-ClvuyXIQ.cjs");class n{constructor(t){this.data=t,this.offset=0}head(t){if(this.offset>=this.data.length)throw new Error("Truncated CBOR");const e=this.data[this.offset++];if(e>>>5!==t)throw new Error("Invalid CBOR type");const r=31&e;if(r<24)return r;if(r>26)throw new Error("Unsupported CBOR length");const n=1<<r-24;if(this.offset+n>this.data.length)throw new Error("Truncated CBOR");let s=0;for(let t=0;t<n;t++)s=256*s+this.data[this.offset++];return s}bytes(){const t=this.head(2);if(this.offset+t>this.data.length)throw new Error("Truncated bytes");const e=this.data.slice(this.offset,this.offset+t);return this.offset+=t,e}end(){if(this.offset!==this.data.length)throw new Error("Trailing CBOR data")}}class s extends t.AddressValidator{validateImplementation(t){if(/^(addr|stake)(_test)?1/i.test(t))return this.validateShelley(t);try{const r=function(t){try{const e=new n(t);if(2!==e.head(4)||24!==e.head(6))return null;const r=e.bytes();if(e.head(0)!==function(t){let e=4294967295;for(const r of t){e^=r;for(let t=0;t<8;t++)e=e>>>1^(1&e?3988292384:0)}return(4294967295^e)>>>0}(r))return null;e.end();const s=new n(r);if(3!==s.head(4)||28!==s.bytes().length)return null;const a=s.head(5);if(a>r.length)return null;const i=new Set;let o="mainnet";for(let t=0;t<a;t++){const t=s.head(0);if(i.has(t)||t>255)return null;i.add(t);const e=s.bytes();if(1===t){const t=new n(e);if(28!==t.bytes().length)return null;t.end()}if(2===t){const t=new n(e);t.head(0),t.end(),o="testnet"}}const d=s.head(0);return 0!==d&&2!==d?null:(s.end(),o)}catch{return null}}(e.decodeBase58(t));if(r)return{valid:!0,blockchain:"cardano",details:{format:"byron",network:r,checksum:!0}}}catch{}return this.invalid()}validateShelley(t){const e=r.decodeBech32(t,256),n=e&&r.wordsToBytes(e.data);if(!e||e.encoding!==r.Bech32Encoding.BECH32||!n?.length)return this.invalid();const s=n[0]>>>4,a=15&n[0];if(0!==a&&1!==a)return this.invalid();const i=14===s||15===s,o=(i?"stake":"addr")+(0===a?"_test":"");if(e.hrp!==o)return this.invalid();let d=!1;return s<=3?d=57===n.length:6===s||7===s||i?d=29===n.length:4!==s&&5!==s||(d=this.validPointer(n)),d?{valid:!0,blockchain:"cardano",details:{format:i?"stake":"shelley",network:1===a?"mainnet":"testnet",checksum:!0}}:this.invalid()}validPointer(t){let e=29;for(let r=0;r<3;r++){let n=0n;const s=e;do{if(e>=t.length||e-s>=10)return!1;n=n<<7n|BigInt(127&t[e])}while(128&t[e++]);if(e-s>1&&128===t[s]||n>(0===r?0xffffffffn:0xffffn))return!1}return e===t.length}invalid(){return{valid:!1,error:"Invalid Cardano address structure, network, or checksum",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}format(e,r){return t.formatPlainAddress(e,r,8)}}exports.CardanoValidator=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CardanoValidator } from './index.cjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CardanoValidator } from './index.mjs';
|
package/dist/cardano.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{A as t,V as e,f as n}from"./shared/base-D2s8b6tx.mjs";import{d as r}from"./shared/base58-CjvbdRzA.mjs";import{d as s,w as a,B as i}from"./shared/bech32-DsNhxmrB.mjs";class o{constructor(t){this.data=t,this.offset=0}head(t){if(this.offset>=this.data.length)throw new Error("Truncated CBOR");const e=this.data[this.offset++];if(e>>>5!==t)throw new Error("Invalid CBOR type");const n=31&e;if(n<24)return n;if(n>26)throw new Error("Unsupported CBOR length");const r=1<<n-24;if(this.offset+r>this.data.length)throw new Error("Truncated CBOR");let s=0;for(let t=0;t<r;t++)s=256*s+this.data[this.offset++];return s}bytes(){const t=this.head(2);if(this.offset+t>this.data.length)throw new Error("Truncated bytes");const e=this.data.slice(this.offset,this.offset+t);return this.offset+=t,e}end(){if(this.offset!==this.data.length)throw new Error("Trailing CBOR data")}}class h extends t{validateImplementation(t){if(/^(addr|stake)(_test)?1/i.test(t))return this.validateShelley(t);try{const e=function(t){try{const e=new o(t);if(2!==e.head(4)||24!==e.head(6))return null;const n=e.bytes();if(e.head(0)!==function(t){let e=4294967295;for(const n of t){e^=n;for(let t=0;t<8;t++)e=e>>>1^(1&e?3988292384:0)}return(4294967295^e)>>>0}(n))return null;e.end();const r=new o(n);if(3!==r.head(4)||28!==r.bytes().length)return null;const s=r.head(5);if(s>n.length)return null;const a=new Set;let i="mainnet";for(let t=0;t<s;t++){const t=r.head(0);if(a.has(t)||t>255)return null;a.add(t);const e=r.bytes();if(1===t){const t=new o(e);if(28!==t.bytes().length)return null;t.end()}if(2===t){const t=new o(e);t.head(0),t.end(),i="testnet"}}const h=r.head(0);return 0!==h&&2!==h?null:(r.end(),i)}catch{return null}}(r(t));if(e)return{valid:!0,blockchain:"cardano",details:{format:"byron",network:e,checksum:!0}}}catch{}return this.invalid()}validateShelley(t){const e=s(t,256),n=e&&a(e.data);if(!e||e.encoding!==i.BECH32||!n?.length)return this.invalid();const r=n[0]>>>4,o=15&n[0];if(0!==o&&1!==o)return this.invalid();const h=14===r||15===r,l=(h?"stake":"addr")+(0===o?"_test":"");if(e.hrp!==l)return this.invalid();let f=!1;return r<=3?f=57===n.length:6===r||7===r||h?f=29===n.length:4!==r&&5!==r||(f=this.validPointer(n)),f?{valid:!0,blockchain:"cardano",details:{format:h?"stake":"shelley",network:1===o?"mainnet":"testnet",checksum:!0}}:this.invalid()}validPointer(t){let e=29;for(let n=0;n<3;n++){let r=0n;const s=e;do{if(e>=t.length||e-s>=10)return!1;r=r<<7n|BigInt(127&t[e])}while(128&t[e++]);if(e-s>1&&128===t[s]||r>(0===n?0xffffffffn:0xffffn))return!1}return e===t.length}invalid(){return{valid:!1,error:"Invalid Cardano address structure, network, or checksum",details:{errorCode:e.INVALID_FORMAT}}}format(t,e){return n(t,e,8)}}export{h as CardanoValidator};
|
package/dist/cosmos.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./shared/base-BtbJMDNm.cjs"),s=require("./shared/bech32-ClvuyXIQ.cjs");const i={cosmos:"cosmos",osmosis:"osmo",celestia:"celestia",injective:"inj",sei:"sei"};class c extends e.AddressValidator{constructor(s="cosmos"){if(super(),this.chain=s,!e.COSMOS_CHAINS.includes(s))throw new RangeError(`Unsupported Cosmos chain: ${String(s)}`)}validateImplementation(c){const o=s.decodeBech32(c),r=o&&s.wordsToBytes(o.data),t="injective"===this.chain||"celestia"===this.chain?[20]:[20,32];return o&&o.hrp===i[this.chain]&&o.encoding===s.Bech32Encoding.BECH32&&r&&t.includes(r.length)?{valid:!0,blockchain:this.chain,details:{format:"bech32",checksum:!0}}:{valid:!1,error:"Invalid account prefix, checksum, length, or padding",details:{errorCode:e.ValidationError.INVALID_FORMAT}}}}exports.CosmosValidator=c;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CosmosValidator } from './index.cjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CosmosValidator } from './index.mjs';
|
package/dist/cosmos.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{A as s,C as e,V as i}from"./shared/base-D2s8b6tx.mjs";import{d as a,w as o,B as c}from"./shared/bech32-DsNhxmrB.mjs";const t={cosmos:"cosmos",osmosis:"osmo",celestia:"celestia",injective:"inj",sei:"sei"};class n extends s{constructor(s="cosmos"){if(super(),this.chain=s,!e.includes(s))throw new RangeError(`Unsupported Cosmos chain: ${String(s)}`)}validateImplementation(s){const e=a(s),n=e&&o(e.data),r="injective"===this.chain||"celestia"===this.chain?[20]:[20,32];return e&&e.hrp===t[this.chain]&&e.encoding===c.BECH32&&n&&r.includes(n.length)?{valid:!0,blockchain:this.chain,details:{format:"bech32",checksum:!0}}:{valid:!1,error:"Invalid account prefix, checksum, length, or padding",details:{errorCode:i.INVALID_FORMAT}}}}export{n as CosmosValidator};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./shared/utxo-DhlBlYDy.cjs");require("./shared/base-BtbJMDNm.cjs"),require("./shared/base58check-CE9wLmUB.cjs"),require("./shared/base58-DaLDoaS-.cjs"),require("./shared/sha256-CRbh7pIK.cjs"),require("./shared/bech32-ClvuyXIQ.cjs");class s extends e.UtxoValidator{constructor(){super({chain:"dogecoin",versions:{30:"mainnet",22:"mainnet",113:"testnet",196:"testnet"}})}}exports.DogecoinValidator=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DogecoinValidator } from './index.cjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DogecoinValidator } from './index.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{U as s}from"./shared/utxo-CRr3-5en.mjs";import"./shared/base-D2s8b6tx.mjs";import"./shared/base58check-BBzwHAsr.mjs";import"./shared/base58-CjvbdRzA.mjs";import"./shared/sha256-BbwKo1_x.mjs";import"./shared/bech32-DsNhxmrB.mjs";class e extends s{constructor(){super({chain:"dogecoin",versions:{30:"mainnet",22:"mainnet",113:"testnet",196:"testnet"}})}}export{e as DogecoinValidator};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var r=require("./shared/base-BtbJMDNm.cjs");function t(r){return r.startsWith("0x")?r.slice(2):r}function e(r){return r.startsWith("0x")?r:`0x${r}`}const n=(1n<<64n)-1n,o=[0,1,62,28,27,36,44,6,55,20,3,10,43,25,39,41,45,15,21,8,18,2,61,56,14],s=[0x0000000000000001n,0x0000000000008082n,0x800000000000808an,0x8000000080008000n,0x000000000000808bn,0x0000000080000001n,0x8000000080008081n,0x8000000000008009n,0x000000000000008an,0x0000000000000088n,0x0000000080008009n,0x000000008000000an,0x000000008000808bn,0x800000000000008bn,0x8000000000008089n,0x8000000000008003n,0x8000000000008002n,0x8000000000000080n,0x000000000000800an,0x800000008000000an,0x8000000080008081n,0x8000000000008080n,0x0000000080000001n,0x8000000080008008n];function a(r,t){return(r<<BigInt(t)|r>>BigInt(64-t))&n}function i(r){const t=new Array(5),e=new Array(25);for(const n of s){for(let e=0;e<5;e++)t[e]=r[e]^r[e+5]^r[e+10]^r[e+15]^r[e+20];for(let e=0;e<5;e++){const n=t[(e+4)%5]^a(t[(e+1)%5],1);for(let t=0;t<5;t++)r[e+5*t]^=n}for(let t=0;t<5;t++)for(let n=0;n<5;n++)e[n+(2*t+3*n)%5*5]=a(r[t+5*n],o[t+5*n]);for(let t=0;t<5;t++)for(let n=0;n<5;n++)r[t+5*n]=e[t+5*n]^~e[(t+1)%5+5*n]&e[(t+2)%5+5*n];r[0]^=n}}class d extends r.AddressValidator{validateImplementation(e,n){const o=t(e);if(40!==o.length)return{valid:!1,error:"Invalid length",details:{errorCode:r.ValidationError.INVALID_LENGTH}};if(!function(r){if("string"!=typeof r)return!1;const t=r.startsWith("0x")?r.slice(2):r;return/^[0-9a-fA-F]*$/.test(t)}(o))return{valid:!1,error:"Invalid hex characters",details:{errorCode:r.ValidationError.INVALID_CHARACTERS}};if(!n?.allowBurnAddress&&/^0+$/.test(o))return{valid:!1,error:"Burn address detected",details:{errorCode:r.ValidationError.BURN_ADDRESS}};const s=this.isChecksummed(o);return(n?.strict||o!==o.toLowerCase()&&o!==o.toUpperCase())&&!s?{valid:!1,error:"Invalid checksum",details:{errorCode:r.ValidationError.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:s}}}format(t,n){let o=e(r.InputSanitizer.sanitize(t));return n?.checksum&&(o=this.toChecksumAddress(o)),r.formatPlainAddress(o,n)}isChecksummed(r){const n=t(r);return e(n)===this.toChecksumAddress(n)}toChecksumAddress(r){const e=t(r).toLowerCase();if(!/^[0-9a-f]{40}$/.test(e))throw new Error("Expected a 20-byte hexadecimal address");const n=function(r){const t=(new TextEncoder).encode(r),e=new Uint8Array(136*(Math.floor(t.length/136)+1));e.set(t),e[t.length]=1,e[e.length-1]|=128;const n=new Array(25).fill(0n);for(let r=0;r<e.length;r+=136){for(let t=0;t<136;t++)n[t>>3]^=BigInt(e[r+t])<<BigInt(8*(7&t));i(n)}let o="";for(let r=0;r<32;r++)o+=Number(n[r>>3]>>BigInt(8*(7&r))&255n).toString(16).padStart(2,"0");return o}(e);return"0x"+[...e].map((r,t)=>parseInt(n[t],16)>=8?r.toUpperCase():r).join("")}}exports.EthereumValidator=d;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { EthereumValidator } from './index.cjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { EthereumValidator } from './index.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{A as e,V as t,I as r,f as n}from"./shared/base-D2s8b6tx.mjs";function s(e){return e.startsWith("0x")?e.slice(2):e}function o(e){return e.startsWith("0x")?e:`0x${e}`}const a=(1n<<64n)-1n,i=[0,1,62,28,27,36,44,6,55,20,3,10,43,25,39,41,45,15,21,8,18,2,61,56,14],l=[0x0000000000000001n,0x0000000000008082n,0x800000000000808an,0x8000000080008000n,0x000000000000808bn,0x0000000080000001n,0x8000000080008081n,0x8000000000008009n,0x000000000000008an,0x0000000000000088n,0x0000000080008009n,0x000000008000000an,0x000000008000808bn,0x800000000000008bn,0x8000000000008089n,0x8000000000008003n,0x8000000000008002n,0x8000000000000080n,0x000000000000800an,0x800000008000000an,0x8000000080008081n,0x8000000000008080n,0x0000000080000001n,0x8000000080008008n];function c(e,t){return(e<<BigInt(t)|e>>BigInt(64-t))&a}function d(e){const t=new Array(5),r=new Array(25);for(const n of l){for(let r=0;r<5;r++)t[r]=e[r]^e[r+5]^e[r+10]^e[r+15]^e[r+20];for(let r=0;r<5;r++){const n=t[(r+4)%5]^c(t[(r+1)%5],1);for(let t=0;t<5;t++)e[r+5*t]^=n}for(let t=0;t<5;t++)for(let n=0;n<5;n++)r[n+(2*t+3*n)%5*5]=c(e[t+5*n],i[t+5*n]);for(let t=0;t<5;t++)for(let n=0;n<5;n++)e[t+5*n]=r[t+5*n]^~r[(t+1)%5+5*n]&r[(t+2)%5+5*n];e[0]^=n}}class x extends e{validateImplementation(e,r){const n=s(e);if(40!==n.length)return{valid:!1,error:"Invalid length",details:{errorCode:t.INVALID_LENGTH}};if(!function(e){if("string"!=typeof e)return!1;const t=e.startsWith("0x")?e.slice(2):e;return/^[0-9a-fA-F]*$/.test(t)}(n))return{valid:!1,error:"Invalid hex characters",details:{errorCode:t.INVALID_CHARACTERS}};if(!r?.allowBurnAddress&&/^0+$/.test(n))return{valid:!1,error:"Burn address detected",details:{errorCode:t.BURN_ADDRESS}};const o=this.isChecksummed(n);return(r?.strict||n!==n.toLowerCase()&&n!==n.toUpperCase())&&!o?{valid:!1,error:"Invalid checksum",details:{errorCode:t.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:o}}}format(e,t){let s=o(r.sanitize(e));return t?.checksum&&(s=this.toChecksumAddress(s)),n(s,t)}isChecksummed(e){const t=s(e);return o(t)===this.toChecksumAddress(t)}toChecksumAddress(e){const t=s(e).toLowerCase();if(!/^[0-9a-f]{40}$/.test(t))throw new Error("Expected a 20-byte hexadecimal address");const r=function(e){const t=(new TextEncoder).encode(e),r=new Uint8Array(136*(Math.floor(t.length/136)+1));r.set(t),r[t.length]=1,r[r.length-1]|=128;const n=new Array(25).fill(0n);for(let e=0;e<r.length;e+=136){for(let t=0;t<136;t++)n[t>>3]^=BigInt(r[e+t])<<BigInt(8*(7&t));d(n)}let s="";for(let e=0;e<32;e++)s+=Number(n[e>>3]>>BigInt(8*(7&e))&255n).toString(16).padStart(2,"0");return s}(t);return"0x"+[...t].map((e,t)=>parseInt(r[t],16)>=8?e.toUpperCase():e).join("")}}export{x as EthereumValidator};
|
package/dist/evm.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./ethereum.cjs"),a=require("./shared/base-BtbJMDNm.cjs");class t extends e.EthereumValidator{validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain="bsc"),t}}class i extends e.EthereumValidator{validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain="avalanche"),t}}class r extends e.EthereumValidator{validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain="arbitrum"),t}}class n extends e.EthereumValidator{validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain="optimism"),t}}class l extends e.EthereumValidator{validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain="base"),t}}class s extends e.EthereumValidator{constructor(e="evm"){if(super(),this.chain=e,!a.EVM_CHAINS.includes(e))throw new RangeError(`Unsupported EVM chain: ${String(e)}`)}validateImplementation(e,a){const t=super.validateImplementation(e,a);return t.valid&&(t.blockchain=this.chain),t}}exports.ArbitrumValidator=r,exports.AvalancheValidator=i,exports.BaseValidator=l,exports.BscValidator=t,exports.EvmValidator=s,exports.OptimismValidator=n;
|
package/dist/evm.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { EvmValidator, BscValidator, AvalancheValidator, ArbitrumValidator, OptimismValidator, BaseValidator } from './index.cjs';
|
package/dist/evm.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { EvmValidator, BscValidator, AvalancheValidator, ArbitrumValidator, OptimismValidator, BaseValidator } from './index.mjs';
|
package/dist/evm.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{EthereumValidator as e}from"./ethereum.mjs";import{E as t}from"./shared/base-D2s8b6tx.mjs";class a extends e{validateImplementation(e,t){const a=super.validateImplementation(e,t);return a.valid&&(a.blockchain="bsc"),a}}class n extends e{validateImplementation(e,t){const a=super.validateImplementation(e,t);return a.valid&&(a.blockchain="avalanche"),a}}class i extends e{validateImplementation(e,t){const a=super.validateImplementation(e,t);return a.valid&&(a.blockchain="arbitrum"),a}}class l extends e{validateImplementation(e,t){const a=super.validateImplementation(e,t);return a.valid&&(a.blockchain="optimism"),a}}class s extends e{validateImplementation(e,t){const a=super.validateImplementation(e,t);return a.valid&&(a.blockchain="base"),a}}class r extends e{constructor(e="evm"){if(super(),this.chain=e,!t.includes(e))throw new RangeError(`Unsupported EVM chain: ${String(e)}`)}validateImplementation(e,t){const a=super.validateImplementation(e,t);return a.valid&&(a.blockchain=this.chain),a}}export{i as ArbitrumValidator,n as AvalancheValidator,s as BaseValidator,a as BscValidator,r as EvmValidator,l as OptimismValidator};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./shared/base-BtbJMDNm.cjs"),r=require("./ethereum.cjs");exports.addChecksum=function(t,s){return e.EVM_CHAINS.includes(s)?(new r.EthereumValidator).format(t,{checksum:!0}):e.InputSanitizer.sanitize(t)},exports.normalizeAddress=function(r,t){const s=e.InputSanitizer.sanitize(r);return e.EVM_CHAINS.includes(t)||"sui"===t||"aptos"===t?s.toLowerCase():s},exports.shortenAddress=function(r,t=4){return e.formatPlainAddress(r,{shorten:!0,shortenLength:t})};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { shortenAddress, normalizeAddress, addChecksum } from './index.cjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { shortenAddress, normalizeAddress, addChecksum } from './index.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{E as e,I as t,f as n}from"./shared/base-D2s8b6tx.mjs";import{EthereumValidator as s}from"./ethereum.mjs";function r(e,t=4){return n(e,{shorten:!0,shortenLength:t})}function o(n,s){const r=t.sanitize(n);return e.includes(s)||"sui"===s||"aptos"===s?r.toLowerCase():r}function i(n,r){return e.includes(r)?(new s).format(n,{checksum:!0}):t.sanitize(n)}export{i as addChecksum,o as normalizeAddress,r as shortenAddress};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./ethereum.cjs"),r=require("./solana.cjs"),t=require("./bitcoin.cjs"),a=require("./litecoin.cjs"),o=require("./dogecoin.cjs"),i=require("./cardano.cjs"),s=require("./ripple.cjs"),n=require("./evm.cjs"),d=require("./shared/base-BtbJMDNm.cjs"),l=require("./tron.cjs"),c=require("./cosmos.cjs"),u=require("./move.cjs"),p=require("./near.cjs"),V=require("./formatters.cjs");require("./shared/base58-DaLDoaS-.cjs"),require("./shared/utxo-DhlBlYDy.cjs"),require("./shared/base58check-CE9wLmUB.cjs"),require("./shared/sha256-CRbh7pIK.cjs"),require("./shared/bech32-ClvuyXIQ.cjs");class m extends e.EthereumValidator{validateImplementation(e,r){const t=super.validateImplementation(e,r);return t.valid&&(t.blockchain="polygon"),t}}const h=new Map;for(const r of d.EVM_CHAINS)h.set(r,"ethereum"===r?new e.EthereumValidator:new n.EvmValidator(r));for(const e of d.COSMOS_CHAINS)h.set(e,new c.CosmosValidator(e));h.set("bitcoin",new t.BitcoinValidator),h.set("litecoin",new a.LitecoinValidator),h.set("dogecoin",new o.DogecoinValidator),h.set("solana",new r.SolanaValidator),h.set("ripple",new s.RippleValidator),h.set("cardano",new i.CardanoValidator),h.set("tron",new l.TronValidator),h.set("sui",new u.SuiValidator),h.set("aptos",new u.AptosValidator),h.set("near",new p.NearValidator);const x=Object.freeze([...h.keys()]);function A(e){const r=h.get(e);if(!r)throw new Error(`Unsupported blockchain: ${String(e)}`);return r}exports.EthereumValidator=e.EthereumValidator,exports.SolanaValidator=r.SolanaValidator,exports.BitcoinValidator=t.BitcoinValidator,exports.LitecoinValidator=a.LitecoinValidator,exports.DogecoinValidator=o.DogecoinValidator,exports.CardanoValidator=i.CardanoValidator,exports.RippleValidator=s.RippleValidator,exports.ArbitrumValidator=n.ArbitrumValidator,exports.AvalancheValidator=n.AvalancheValidator,exports.BaseValidator=n.BaseValidator,exports.BscValidator=n.BscValidator,exports.EvmValidator=n.EvmValidator,exports.OptimismValidator=n.OptimismValidator,exports.AddressValidator=d.AddressValidator,exports.COSMOS_CHAINS=d.COSMOS_CHAINS,exports.EVM_CHAINS=d.EVM_CHAINS,Object.defineProperty(exports,"ValidationError",{enumerable:!0,get:function(){return d.ValidationError}}),exports.TronValidator=l.TronValidator,exports.CosmosValidator=c.CosmosValidator,exports.AptosValidator=u.AptosValidator,exports.SuiValidator=u.SuiValidator,exports.NearValidator=p.NearValidator,exports.addChecksum=V.addChecksum,exports.normalizeAddress=V.normalizeAddress,exports.shortenAddress=V.shortenAddress,exports.PolygonValidator=m,exports.SUPPORTED_CHAINS=x,exports.detectBlockchain=function(e,r){let t;try{t=d.InputSanitizer.sanitize(e)}catch{return null}if(!t)return null;const a=[];A("ethereum").validate(t,r).valid&&a.push(...d.EVM_CHAINS);for(const e of x)d.EVM_CHAINS.includes(e)||("near"!==e||/(\.near|\.testnet)$/.test(t)||/^[0-9a-f]{64}$/.test(t)||/^0[xs][0-9a-f]{40}$/.test(t)||/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(t))&&A(e).validate(t,r).valid&&a.push(e);return 0===a.length?null:1===a.length?a[0]:a},exports.formatAddress=function(e,r,t){return A(r).format(e,t)},exports.isSupportedChain=function(e){return"string"==typeof e&&h.has(e)},exports.validateAddress=function(e,r,t){return A(r).validate(e,t)},exports.validateBatch=function(e,r,t){const a=A(r);return Array.from(e,e=>a.validate(e,t))};
|