nirium-avalanche 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
File without changes
package/README.md CHANGED
@@ -1,55 +1,77 @@
1
- # nirium-avalanche
2
-
3
- Pay and charge with x402 on Avalanche, refuse a payment before it is signed, and keep a
4
- payer-signed receipt bound to the exact USDC `Transfer` log.
5
-
6
- The chain already shows who paid whom, how much and when. The receipt adds what the chain does
7
- not keep: which order the payment was for and who declared it. Anyone can check it against
8
- Avalanche with a public RPC. Part of [Nirium](https://nirium.xyz). Source, tests and the team's
9
- test payments: [nirium-avalanche](https://github.com/nirium-protocol/nirium-avalanche).
10
-
11
- ```bash
12
- npm install nirium-avalanche
13
- ```
14
-
15
- ```js
16
- import { x402Serve, createX402Fetch, settlementOf, bindReceipt, verifyReceipt, createRulesPolicy } from "nirium-avalanche";
17
-
18
- // Charge for your own API. Runs on your server: Nirium runs nothing in the middle.
19
- app.use(x402Serve({ payTo: "0x...", network: "eip155:43113", routes: { "GET /data": "$0.01" } }));
20
-
21
- // Pay, with a policy: a payment it refuses is never signed.
22
- const pay = createX402Fetch({ signer: account, network: "eip155:43113", maxAmountPerPayment: "10000",
23
- policy: createRulesPolicy({ maxAmount: "10000" }) });
24
- const res = await pay("https://seller.example/data", { headers: { "X-Nirium-Ref": "order-42" } });
25
-
26
- // A payer-signed receipt bound to the transfer, and its check against the chain.
27
- const receipt = await bindReceipt({ tx: settlementOf(res).transaction, network: "eip155:43113", ref: "order-42", signer: account });
28
- const { ok } = await verifyReceipt(receipt);
29
- ```
30
-
31
- `account` is a viem account for the payer's own key. Networks: Avalanche Fuji and C-Chain mainnet (mainnet needs `allowMainnet: true`). `x402Serve` needs `express` (4.22.3+ or 5.3.0+) in your
32
- app. Settlement is done by PayAI, an independent x402 facilitator.
33
-
34
- | Import | What it is |
35
- |---|---|
36
- | `nirium-avalanche` | `x402Serve`, `createX402Fetch`, `settlementOf`, `bindReceipt`, `verifyReceipt`, `createRulesPolicy` |
37
- | `nirium-avalanche/policy` | The pre-sign policy gate (decodes what is about to be signed, asks your policy, signs only on a bound ALLOW) |
38
- | `nirium-avalanche/policy/rules` | A small reference policy engine: max amount, approval line, allowlists |
39
- | `nirium-avalanche/receipt` | `bindReceipt` and `verifyReceipt` on their own, without the Express middleware |
40
- | `nirium-avalanche/decision` | Decision receipts: `bindDecision`, `verifyDecision`, `collectDecisions` (also exported from `nirium-avalanche`) |
41
- | `nirium-avalanche/verify` | The receipt verifier as a library. No Node-only code, so it runs in Node and in the browser |
42
-
43
- Check a receipt from the command line:
44
-
45
- ```bash
46
- npx -p nirium-avalanche nirium-verify-evm receipt.json
47
- ```
48
-
49
- Exit code 0 means valid, 1 means a check failed, 2 means bad input.
50
-
51
- Receipts are tamper-evident, not tamper-proof, and they do not prove that goods or a service
52
- were delivered. Non-custodial: every key stays with whoever pays or receives. No external audit
53
- yet. Report security problems privately: [SECURITY.md](https://github.com/nirium-protocol/nirium-avalanche/blob/main/SECURITY.md).
54
-
55
- License: Apache-2.0
1
+ # nirium-avalanche
2
+
3
+ Pay and charge with x402 on Avalanche, refuse a payment before it is signed, and keep a
4
+ payer-signed receipt bound to the exact USDC `Transfer` log.
5
+
6
+ The chain already shows who paid whom, how much and when. The receipt adds what the chain does
7
+ not keep: which order the payment was for and who declared it. Anyone can check it against
8
+ Avalanche with a public RPC. Part of [Nirium](https://nirium.xyz). Source, tests and the team's
9
+ test payments: [nirium-avalanche](https://github.com/nirium-protocol/nirium-avalanche).
10
+
11
+ ```bash
12
+ npm install nirium-avalanche
13
+ ```
14
+
15
+ ```js
16
+ import { x402Serve, createX402Fetch, settlementOf, bindReceipt, verifyReceipt, createRulesPolicy } from "nirium-avalanche";
17
+
18
+ // Charge for your own API. Runs on your server: Nirium runs nothing in the middle.
19
+ app.use(x402Serve({ payTo: "0x...", network: "eip155:43113", routes: { "GET /data": "$0.01" } }));
20
+
21
+ // Pay, with a policy: a payment it refuses is never signed.
22
+ const pay = createX402Fetch({ signer: account, network: "eip155:43113", maxAmountPerPayment: "10000",
23
+ policy: createRulesPolicy({ maxAmount: "10000" }) });
24
+ const res = await pay("https://seller.example/data", { headers: { "X-Nirium-Ref": "order-42" } });
25
+
26
+ // A payer-signed receipt bound to the transfer, and its check against the chain.
27
+ const receipt = await bindReceipt({ tx: settlementOf(res).transaction, network: "eip155:43113", ref: "order-42", signer: account });
28
+ const { ok } = await verifyReceipt(receipt);
29
+ ```
30
+
31
+ `account` is a viem account for the payer's own key. Networks: Avalanche Fuji and C-Chain mainnet (mainnet needs `allowMainnet: true`). `x402Serve` needs `express` (4.22.3+ or 5.3.0+) in your
32
+ app. Settlement is done by PayAI, an independent x402 facilitator.
33
+
34
+ | Import | What it is |
35
+ |---|---|
36
+ | `nirium-avalanche` | `x402Serve`, `createX402Fetch`, `settlementOf`, `bindReceipt`, `verifyReceipt`, `createRulesPolicy` |
37
+ | `nirium-avalanche/policy` | The pre-sign policy gate (decodes what is about to be signed, asks your policy, signs only on a bound ALLOW) |
38
+ | `nirium-avalanche/policy/rules` | A small reference policy engine: max amount, approval line, allowlists |
39
+ | `nirium-avalanche/receipt` | `bindReceipt` and `verifyReceipt` on their own, without the Express middleware |
40
+ | `nirium-avalanche/decision` | Decision receipts: `bindDecision`, `verifyDecision`, `collectDecisions` (also exported from `nirium-avalanche`) |
41
+ | `nirium-avalanche/verify` | The receipt verifier as a library. No Node-only code, so it runs in Node and in the browser |
42
+ | `nirium-avalanche/pq` | Post-quantum signature on receipts: `pqKeygen`, `registerPqKey`, `attestPq` (also exported from `nirium-avalanche`) |
43
+ | `nirium-avalanche/verify/pq` | The post-quantum checks on their own, browser-safe |
44
+
45
+ Check a receipt from the command line:
46
+
47
+ ```bash
48
+ npx -p nirium-avalanche nirium-verify-evm receipt.json
49
+ ```
50
+
51
+ Exit code 0 means valid, 1 means a check failed, 2 means bad input.
52
+
53
+ ## Post-quantum signature
54
+
55
+ A receipt can also carry an ML-DSA-65 (NIST FIPS 204) signature over the same statement the payer
56
+ signs with EIP-191. The payer registers sha-256 of that key once, from its own address, in
57
+ `NiriumPqKeyRegistry` (C-Chain `0xE7791Fa06FE503AacE8fa4f6FC2DFdc3922ba0a0`, Fuji `0x3aE0F4004bb67B8f754DE1fa8EA666A1B301D5b3`); the verifier accepts the
58
+ key only if it was registered in a block before the payment.
59
+
60
+ ```js
61
+ import { pqKeygen, registerPqKey, bindReceipt, verifyReceipt } from "nirium-avalanche";
62
+
63
+ const pq = pqKeygen(); // keep pq.seed safe: it rebuilds the key pair
64
+ await registerPqKey({ account, publicKey: pq.publicKey, network: "eip155:43113" }); // once, ever
65
+ const receipt = await bindReceipt({ tx, network: "eip155:43113", ref: "order-42", signer: account, pqSigner: pq });
66
+ const { ok } = await verifyReceipt(receipt, { requirePq: true });
67
+ ```
68
+
69
+ `npx -p nirium-avalanche nirium-verify-evm receipt.json --require-pq` does the same from the command
70
+ line. It protects the receipt, not the payment (the payment stays signed with secp256k1). The
71
+ ML-DSA check runs in the verifier, not in a contract: C-Chain has no ML-DSA precompile.
72
+
73
+ Receipts are tamper-evident, not tamper-proof, and they do not prove that goods or a service
74
+ were delivered. Non-custodial: every key stays with whoever pays or receives. No external audit
75
+ yet. Report security problems privately: [SECURITY.md](https://github.com/nirium-protocol/nirium-avalanche/blob/main/SECURITY.md).
76
+
77
+ License: Apache-2.0
package/package.json CHANGED
@@ -1,75 +1,81 @@
1
- {
2
- "name": "nirium-avalanche",
3
- "version": "0.3.0",
4
- "description": "Pay and charge with x402 on Avalanche, refuse a payment before it is signed, and keep a payer-signed receipt bound to the exact USDC transfer",
5
- "type": "module",
6
- "license": "Apache-2.0",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://github.com/nirium-protocol/nirium-avalanche.git",
10
- "directory": "avalanche"
11
- },
12
- "homepage": "https://github.com/nirium-protocol/nirium-avalanche#readme",
13
- "bugs": {
14
- "url": "https://github.com/nirium-protocol/nirium-avalanche/issues"
15
- },
16
- "keywords": [
17
- "x402",
18
- "avalanche",
19
- "usdc",
20
- "payments",
21
- "receipts",
22
- "ai-agents",
23
- "eip-3009",
24
- "erc-8004"
25
- ],
26
- "exports": {
27
- ".": "./sdk/index.mjs",
28
- "./policy": "./policy/evm-policy.mjs",
29
- "./policy/x402-fetch": "./policy/x402-fetch.mjs",
30
- "./policy/rules": "./policy/rules-policy.mjs",
31
- "./receipt": "./sdk/receipt.mjs",
32
- "./decision": "./sdk/decision.mjs",
33
- "./verify": "./verify-evm-core.mjs",
34
- "./package.json": "./package.json"
35
- },
36
- "bin": {
37
- "nirium-verify-evm": "verify-evm-receipt.mjs"
38
- },
39
- "files": [
40
- "sdk/*.mjs",
41
- "policy/evm-policy.mjs",
42
- "policy/x402-fetch.mjs",
43
- "policy/rules-policy.mjs",
44
- "verify-evm-core.mjs",
45
- "verify-evm-receipt.mjs"
46
- ],
47
- "scripts": {
48
- "test": "node --test test/*.test.mjs policy/test/*.test.mjs sdk/test/*.test.mjs",
49
- "test:verify": "node --test test/*.test.mjs",
50
- "test:policy": "node --test policy/test/*.test.mjs",
51
- "test:sdk": "node --test sdk/test/*.test.mjs",
52
- "test:live": "bash run-tests.sh"
53
- },
54
- "engines": {
55
- "node": ">=20"
56
- },
57
- "dependencies": {
58
- "viem": "2.58.7",
59
- "@x402/core": "2.32.0",
60
- "@x402/evm": "2.32.0",
61
- "@x402/express": "2.32.0",
62
- "@x402/fetch": "2.32.0"
63
- },
64
- "peerDependencies": {
65
- "express": "^4.22.3 || ^5.3.0"
66
- },
67
- "peerDependenciesMeta": {
68
- "express": {
69
- "optional": true
70
- }
71
- },
72
- "devDependencies": {
73
- "express": "5.3.0"
74
- }
75
- }
1
+ {
2
+ "name": "nirium-avalanche",
3
+ "version": "0.4.1",
4
+ "description": "Pay and charge with x402 on Avalanche, refuse a payment before it is signed, and keep a payer-signed receipt bound to the exact USDC transfer, optionally with a post-quantum (ML-DSA-65) signature",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/nirium-protocol/nirium-avalanche.git",
10
+ "directory": "avalanche"
11
+ },
12
+ "homepage": "https://github.com/nirium-protocol/nirium-avalanche#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/nirium-protocol/nirium-avalanche/issues"
15
+ },
16
+ "keywords": [
17
+ "x402",
18
+ "avalanche",
19
+ "usdc",
20
+ "payments",
21
+ "receipts",
22
+ "ai-agents",
23
+ "eip-3009",
24
+ "erc-8004",
25
+ "post-quantum",
26
+ "ml-dsa"
27
+ ],
28
+ "exports": {
29
+ ".": "./sdk/index.mjs",
30
+ "./policy": "./policy/evm-policy.mjs",
31
+ "./policy/x402-fetch": "./policy/x402-fetch.mjs",
32
+ "./policy/rules": "./policy/rules-policy.mjs",
33
+ "./receipt": "./sdk/receipt.mjs",
34
+ "./decision": "./sdk/decision.mjs",
35
+ "./verify": "./verify-evm-core.mjs",
36
+ "./package.json": "./package.json",
37
+ "./pq": "./sdk/pq.mjs",
38
+ "./verify/pq": "./verify-evm-pq.mjs"
39
+ },
40
+ "bin": {
41
+ "nirium-verify-evm": "verify-evm-receipt.mjs"
42
+ },
43
+ "files": [
44
+ "sdk/*.mjs",
45
+ "policy/evm-policy.mjs",
46
+ "policy/x402-fetch.mjs",
47
+ "policy/rules-policy.mjs",
48
+ "verify-evm-core.mjs",
49
+ "verify-evm-pq.mjs",
50
+ "verify-evm-receipt.mjs"
51
+ ],
52
+ "scripts": {
53
+ "test": "node --test test/*.test.mjs policy/test/*.test.mjs sdk/test/*.test.mjs",
54
+ "test:verify": "node --test test/*.test.mjs",
55
+ "test:policy": "node --test policy/test/*.test.mjs",
56
+ "test:sdk": "node --test sdk/test/*.test.mjs",
57
+ "test:live": "bash run-tests.sh"
58
+ },
59
+ "engines": {
60
+ "node": ">=20"
61
+ },
62
+ "dependencies": {
63
+ "viem": "2.58.7",
64
+ "@x402/core": "2.32.0",
65
+ "@x402/evm": "2.32.0",
66
+ "@x402/express": "2.32.0",
67
+ "@x402/fetch": "2.32.0",
68
+ "@noble/post-quantum": "0.7.1"
69
+ },
70
+ "peerDependencies": {
71
+ "express": "^4.22.3 || ^5.3.0"
72
+ },
73
+ "peerDependenciesMeta": {
74
+ "express": {
75
+ "optional": true
76
+ }
77
+ },
78
+ "devDependencies": {
79
+ "express": "5.3.0"
80
+ }
81
+ }