Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Contributing to validator0x

## Local setup

Use Node.js 22.13 or later on the Node 22 line, or a newer supported LTS. From the repository root, install the locked dependencies with `npm ci`. The packed-browser test uses Google Chrome stable. If Chrome is missing, run `npx playwright-core install chrome`.

## Changing a validator

Keep validation synchronous and offline with zero runtime dependencies. Put family-specific rules in `src/validators/` and shared encoding or hashing logic in `src/utils/`. Route address input through `AddressValidator.validate` to apply the shared input limit and network policy.

For a bug fix, add a regression test using a public API and confirm that it fails on the affected revision. Include a valid control when changing which inputs are accepted. For chain or checksum changes, use published protocol vectors and cover malformed inputs, network options and ambiguous detection where applicable. Compare changes to cryptographic primitives against the independent reference implementations used by the differential suite.

Document changes to public behavior in the README and changelog. For a new entrypoint, follow the export, declaration and packed-consumer requirements in [AGENTS.md](./AGENTS.md).

## Before opening a pull request

Run these commands from the repository root.

```sh
npm run check
npm run test:coverage
npm audit
```

`npm run check` runs lint, type checking, unit tests, the production build, differential comparisons and installation tests against the actual npm tarball. The coverage command enforces the repository thresholds. Use `npm test -- tests/evm-prefix.test.ts` for a focused run while developing.

Open the PR against `main`. Link the issue, describe the user-visible change and include your test results. For a performance change, give the Node version and compare the same inputs on both revisions. Keep generated coverage, build output and package archives out of the diff.

## Merge checks

GitHub requires all seven CI jobs before merging into `main`. Six package jobs run on Ubuntu and Windows with Node 22, 24 and 26. Each installs the locked dependencies, runs the full check and audits dependencies. The seventh job checks coverage on Ubuntu with Node 24. If GitHub marks the branch out of date, update it with the latest `main` and let CI run on the new revision.

For release preparation and publishing permissions, see [RELEASING.md](./RELEASING.md).
23 changes: 23 additions & 0 deletions tests/evm-prefix.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { detectBlockchain, EVM_CHAINS, validateAddress, validateBatch } from '../src';

describe('EVM address prefixes', () => {
// After stripping one prefix, the remaining 40 characters still contain an x.
const repeatedPrefix = '0x0x' + '1'.repeat(38);
const checksummed = '0x52908400098527886E0F7030069857D2E4169EE7';

test.each(EVM_CHAINS)('%s rejects a repeated prefix with default options', chain => {
expect(validateAddress(repeatedPrefix, chain).valid).toBe(false);
});

test('detection finds no candidate for the repeated prefix', () => {
expect(detectBlockchain(repeatedPrefix)).toBeNull();
});

test('batch validation accepts either supported spelling and rejects a repeated prefix', () => {
const inputs = [checksummed, repeatedPrefix, checksummed.slice(2)];
for (const options of [undefined, { strict: true }]) {
expect(validateBatch(inputs, 'ethereum', options).map(result => result.valid))
.toEqual([true, false, true]);
}
});
});