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