{"_id":"@canopy-finance/x402-client","name":"@canopy-finance/x402-client","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@canopy-finance/x402-client","version":"0.1.0","description":"Buyer-side x402 client for the Canopy facilitator: build and post exact-permit2-v2 payments (EIP-712 Permit2 witness). Works in the browser and in Node. Zero runtime deps except viem (peer).","license":"MIT","type":"module","engines":{"node":">=20"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs"}},"main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","sideEffects":false,"scripts":{"build":"tsup","typecheck":"tsc -p tsconfig.json --noEmit"},"peerDependencies":{"viem":"^2"},"devDependencies":{"tsup":"^8.3.5","typescript":"^5.5.0","viem":"^2.21.0"},"keywords":["x402","permit2","eip-712","canopy","robinhood-chain","payments","stablecoin"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/canopyfinance/canopy-facilitator.git","directory":"packages/x402-client"},"gitHead":"ff66d39269bb45a29a5df3f1dd6b942eb96ffaeb","_id":"@canopy-finance/x402-client@0.1.0","bugs":{"url":"https://github.com/canopyfinance/canopy-facilitator/issues"},"homepage":"https://github.com/canopyfinance/canopy-facilitator#readme","_nodeVersion":"25.6.1","_npmVersion":"11.9.0","dist":{"integrity":"sha512-EDDz6NKEoXQmdVLZ/bPlUmZE0wWqOpzqn98uCNF56NPr7veVNKaQWYg36L/0lEs14JCp0SjLUkOjrXAeat2L9w==","shasum":"b8d4dd778e5f35cd442f41d49ace20f91633e25d","tarball":"https://registry.npmjs.org/@canopy-finance/x402-client/-/x402-client-0.1.0.tgz","fileCount":6,"unpackedSize":28857,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIBCv1rH2cWjtnPBezHXXYGAMEyPKA512T+9XlhgzTbHIAiAmCVAyfQLhHTjzNd4pTXWOGTnp6MTfVBxXZbhWX3ugHg=="}]},"_npmUser":{"name":"canopy-finance","email":"heyagentsol@gmail.com"},"directories":{},"maintainers":[{"name":"canopy-finance","email":"heyagentsol@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/x402-client_0.1.0_1783945807670_0.8672751349377412"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-13T12:30:07.566Z","0.1.0":"2026-07-13T12:30:07.810Z","modified":"2026-07-13T12:30:07.960Z"},"maintainers":[{"name":"canopy-finance","email":"heyagentsol@gmail.com"}],"description":"Buyer-side x402 client for the Canopy facilitator: build and post exact-permit2-v2 payments (EIP-712 Permit2 witness). Works in the browser and in Node. Zero runtime deps except viem (peer).","homepage":"https://github.com/canopyfinance/canopy-facilitator#readme","keywords":["x402","permit2","eip-712","canopy","robinhood-chain","payments","stablecoin"],"repository":{"type":"git","url":"git+https://github.com/canopyfinance/canopy-facilitator.git","directory":"packages/x402-client"},"bugs":{"url":"https://github.com/canopyfinance/canopy-facilitator/issues"},"license":"MIT","readme":"# @canopy-finance/x402-client\n\nBuyer-side [x402](https://x402.org) client for the Canopy facilitator. Build and\npost **`exact-permit2-v2`** payments — an EIP-712 Permit2 witness that binds both\nthe recipient and a stable `serviceId` into the payer's signature — without\nhand-rolling the typed data.\n\n- Works in the **browser and in Node** (uses `fetch` + `globalThis.crypto` only).\n- **Zero runtime dependencies** except **viem** (peer).\n- Signer-agnostic: pass any `signTypedData` (viem wallet, ethers, injected wallet…).\n- ESM + CJS + type declarations.\n\nThe EIP-712 shape here is the single source of truth shared with the facilitator's\nverifier, so buyer and verifier can never drift.\n\n## Install\n\n```bash\nnpm install @canopy-finance/x402-client viem\n```\n\n## The four-step buyer flow\n\n```ts\nimport {\n  getSupported,\n  permit2ApprovalTx,\n  createExactPermit2V2Payment,\n  post,\n} from \"@canopy-finance/x402-client\";\nimport { createWalletClient, custom } from \"viem\";\n\nconst url = \"https://facilitator.canopyfinance.io\";\n\n// 1. Discover the facilitator's advertised kind (validates schemeVersion = 2).\nconst kind = await getSupported(url);\n\n// 2. (once per payer) Approve Permit2 to move the asset on your behalf.\nconst wallet = createWalletClient({ account, transport: custom(window.ethereum) });\nawait wallet.writeContract(permit2ApprovalTx(kind));\n\n// 3. Build a signed payment. `serviceId` comes from the resource's 402\n//    response (paymentRequirements.extra.serviceId).\nconst body = await createExactPermit2V2Payment({\n  chainId: 4663,\n  kind,\n  owner: account.address,\n  payTo,          // the seller's recipient address\n  amount: 10_000n, // atomic units (e.g. 0.01 USDG at 6 decimals)\n  serviceId,       // bytes32 from the resource's 402\n  signTypedData: (args) => wallet.signTypedData({ account, ...args }),\n});\n\n// 4. POST to /verify, then /settle.\nconst verified = await post(url, \"verify\", body);\nif (verified.isValid !== true) throw new Error(\"verify failed\");\nconst settled = await post(url, \"settle\", body /*, apiKey */);\n```\n\n## Migration from v1 (`exact-permit2`)\n\nThe legacy `exact-permit2` scheme is read-only. To integrate:\n\n1. Read `serviceId` from the resource's 402 (`extra.serviceId`).\n2. Call `createExactPermit2V2Payment` (the v1 creator `createPermit2Payment` now\n   throws `UnsupportedSchemeError`).\n3. Target a facilitator advertising `schemeVersion: 2` / `payloadVersion: 2`.\n\n## Exports\n\n- `getSupported(url)` — fetch + validate the `exact-permit2-v2` kind.\n- `permit2ApprovalTx(kind, amount?)` — viem `writeContract` config for the one-time approval.\n- `createExactPermit2V2Payment(params)` — build a signed, ready-to-POST payment body.\n- `post(url, \"verify\" | \"settle\", body, apiKey?)` — POST helper.\n- Constants: `PERMIT2_TYPES`, `WITNESS_TYPE_STRING`, `SUPPORTED_SCHEME`,\n  `SUPPORTED_SCHEME_VERSION`, `SUPPORTED_PAYLOAD_VERSION`.\n- Errors: `UnsupportedSchemeError`, `UnsupportedSchemeVersionError`,\n  `UnsupportedPayloadVersionError`, `MissingServiceIdError`.\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-96635b4fe15f2ce2797c45c2a52d9fd4"}