diff --git a/.github/workflows/opencode.yml b/.github/workflows/opencode.yml
new file mode 100644
index 0000000..dddedc3
--- /dev/null
+++ b/.github/workflows/opencode.yml
@@ -0,0 +1,45 @@
+name: opencode
+
+on:
+ pull_request:
+ types: [opened, synchronize, ready_for_review]
+ issue_comment:
+ types: [created]
+ pull_request_review_comment:
+ types: [created]
+
+jobs:
+ opencode:
+ if: |
+ github.event_name == 'pull_request' ||
+ contains(github.event.comment.body, ' /oc') ||
+ startsWith(github.event.comment.body, '/oc') ||
+ contains(github.event.comment.body, ' /opencode') ||
+ startsWith(github.event.comment.body, '/opencode')
+ runs-on: ubuntu-latest
+ permissions:
+ id-token: write
+ contents: read
+ pull-requests: write
+ issues: read
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v6
+ with:
+ persist-credentials: false
+
+ - name: Setup Node.js
+ uses: actions/setup-node@v4
+ with:
+ node-version: '20'
+ cache: 'npm'
+
+ - name: Install dependencies
+ run: npm ci
+
+ - name: Run opencode
+ uses: anomalyco/opencode/github@latest
+ env:
+ OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
+ with:
+ model: opencode/kimi-k2.5
diff --git a/README.md b/README.md
index 5b49590..68835df 100644
--- a/README.md
+++ b/README.md
@@ -98,6 +98,37 @@ paytaca token send
--token # Send fungible tokens
paytaca token send-nft --token --commitment # Send an NFT
```
+### x402 Payments
+
+The x402 protocol enables HTTP payments via BCH. Some APIs (like nanogpt) require payment to access.
+
+```bash
+paytaca check # Check if URL requires payment, shows estimated cost
+paytaca pay # Make a paid HTTP request (handles 402 automatically)
+paytaca pay --json # JSON output (recommended for AI agents)
+paytaca pay --dry-run # Preview payment without executing
+paytaca pay --method POST # POST request with body
+paytaca pay --body '{"prompt":"hello"}'
+```
+
+**Example workflow:**
+```bash
+paytaca check https://api.nanogpt.com/v1/complete --json
+# → {"paymentRequired": true, "estimatedCostSats": "100"}
+
+paytaca pay https://api.nanogpt.com/v1/complete --method POST --body '{"prompt":"hello"}'
+# → Handles 402 → pays → returns response
+```
+
+### AI Agent Integration
+
+```bash
+paytaca opencode # Install Paytaca x402 skill for OpenCode AI agents
+paytaca claude # Install Paytaca x402 skill for Claude Code agents
+```
+
+This enables AI agents to autonomously handle HTTP 402 payment responses when calling x402-enabled APIs.
+
## Network
All commands default to **mainnet**. Pass `--chipnet` for testnet:
@@ -130,15 +161,23 @@ src/
history.ts transaction history (BCH and CashTokens)
address.ts HD address derivation (standard and z-prefix)
token.ts CashToken commands (list, info, send, send-nft)
+ pay.ts x402 BCH payment handler for HTTP requests
+ check.ts Check if URL requires x402 payment
+ opencode.ts Install x402 skill for OpenCode AI agents
+ claude.ts Install x402 skill for Claude Code AI agents
wallet/
index.ts Wallet class, mnemonic gen/import/load
bch.ts BchWallet (balance, send, history, CashTokens)
keys.ts LibauthHDWallet (HD key derivation, token addresses)
+ x402.ts X402Payer (BCH payment signing and verification)
storage/
keychain.ts OS keychain wrapper (@napi-rs/keyring)
utils/
crypto.ts pubkey -> CashAddress pipeline
network.ts Watchtower URLs, derivation paths
+ x402.ts x402 header parsing, payment requirement selection
+ types/
+ x402.ts x402 payment types (PaymentRequired, PaymentPayload, etc.)
```
## Key Dependencies
@@ -161,6 +200,22 @@ npm run build # One-time build
npm run clean # Remove dist/
```
+## x402 Server
+
+A reference x402 server implementation is included for testing:
+
+```bash
+cd x402-server
+npm install
+npm run dev # Start dev server on port 3001
+```
+
+The server implements the x402-bch v2.2 specification and provides:
+- `GET /api/quote` — Returns a quote (requires payment)
+- `POST /api/generate` — Text generation endpoint (requires payment)
+
+Useful for testing the `paytaca pay` workflow locally.
+
## License
Copyright Paytaca Inc. 2021. All rights reserved. See [LICENSE](LICENSE) for details.
diff --git a/package-lock.json b/package-lock.json
index 7227faa..865cfaf 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,13 +1,13 @@
{
"name": "paytaca-cli",
- "version": "0.1.0",
+ "version": "0.2.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "paytaca-cli",
- "version": "0.1.0",
- "license": "MIT",
+ "version": "0.2.0",
+ "license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@bitauth/libauth": "2.0.0-alpha.8",
"@napi-rs/keyring": "^1.2.0",
@@ -24,7 +24,9 @@
"devDependencies": {
"@types/node": "^22.0.0",
"@types/qrcode-terminal": "^0.12.2",
- "typescript": "^5.9.3"
+ "@vitest/ui": "^4.1.2",
+ "typescript": "^5.9.3",
+ "vitest": "^4.1.2"
},
"engines": {
"node": ">=20.0.0"
@@ -52,6 +54,50 @@
"node": ">=10.15.1"
}
},
+ "node_modules/@emnapi/core": {
+ "version": "1.9.1",
+ "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.9.1.tgz",
+ "integrity": "sha512-mukuNALVsoix/w1BJwFzwXBN/dHeejQtuVzcDsfOEsdpCumXb/E9j8w11h5S54tT1xhifGfbbSm/ICrObRb3KA==",
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "peer": true,
+ "dependencies": {
+ "@emnapi/wasi-threads": "1.2.0",
+ "tslib": "^2.4.0"
+ }
+ },
+ "node_modules/@emnapi/runtime": {
+ "version": "1.9.1",
+ "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.9.1.tgz",
+ "integrity": "sha512-VYi5+ZVLhpgK4hQ0TAjiQiZ6ol0oe4mBx7mVv7IflsiEp0OWoVsp/+f9Vc1hOhE0TtkORVrI1GvzyreqpgWtkA==",
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "peer": true,
+ "dependencies": {
+ "tslib": "^2.4.0"
+ }
+ },
+ "node_modules/@emnapi/wasi-threads": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.0.tgz",
+ "integrity": "sha512-N10dEJNSsUx41Z6pZsXU8FjPjpBEplgH24sfkmITrBED1/U2Esum9F3lfLrMjKHHjmi557zQn7kR9R+XWXu5Rg==",
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "peer": true,
+ "dependencies": {
+ "tslib": "^2.4.0"
+ }
+ },
+ "node_modules/@jridgewell/sourcemap-codec": {
+ "version": "1.5.5",
+ "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz",
+ "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/@ljharb/resumer": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/@ljharb/resumer/-/resumer-0.1.3.tgz",
@@ -296,6 +342,25 @@
"node": ">= 10"
}
},
+ "node_modules/@napi-rs/wasm-runtime": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.1.2.tgz",
+ "integrity": "sha512-sNXv5oLJ7ob93xkZ1XnxisYhGYXfaG9f65/ZgYuAu3qt7b3NadcOEhLvx28hv31PgX8SZJRYrAIPQilQmFpLVw==",
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "@tybys/wasm-util": "^0.10.1"
+ },
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/Brooooooklyn"
+ },
+ "peerDependencies": {
+ "@emnapi/core": "^1.7.1",
+ "@emnapi/runtime": "^1.7.1"
+ }
+ },
"node_modules/@noble/hashes": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.8.0.tgz",
@@ -308,6 +373,23 @@
"url": "https://paulmillr.com/funding/"
}
},
+ "node_modules/@oxc-project/types": {
+ "version": "0.122.0",
+ "resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.122.0.tgz",
+ "integrity": "sha512-oLAl5kBpV4w69UtFZ9xqcmTi+GENWOcPF7FCrczTiBbmC0ibXxCwyvZGbO39rCVEuLGAZM84DH0pUIyyv/YJzA==",
+ "dev": true,
+ "license": "MIT",
+ "funding": {
+ "url": "https://github.com/sponsors/Boshen"
+ }
+ },
+ "node_modules/@polka/url": {
+ "version": "1.0.0-next.29",
+ "resolved": "https://registry.npmjs.org/@polka/url/-/url-1.0.0-next.29.tgz",
+ "integrity": "sha512-wwQAWhWSuHaag8c4q/KN/vCoeOJYshAIvMQwD4GpSb3OiZklFfvAgmj0VCBBImRpuF/aFgIRzllXlVX93Jevww==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/@psf/bch-js": {
"version": "6.8.3",
"resolved": "https://registry.npmjs.org/@psf/bch-js/-/bch-js-6.8.3.tgz",
@@ -428,6 +510,311 @@
"@psf/bitcoincash-ops": "^2.0.0"
}
},
+ "node_modules/@rolldown/binding-android-arm64": {
+ "version": "1.0.0-rc.12",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.0.0-rc.12.tgz",
+ "integrity": "sha512-pv1y2Fv0JybcykuiiD3qBOBdz6RteYojRFY1d+b95WVuzx211CRh+ytI/+9iVyWQ6koTh5dawe4S/yRfOFjgaA==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "node_modules/@rolldown/binding-darwin-arm64": {
+ "version": "1.0.0-rc.12",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.0.0-rc.12.tgz",
+ "integrity": "sha512-cFYr6zTG/3PXXF3pUO+umXxt1wkRK/0AYT8lDwuqvRC+LuKYWSAQAQZjCWDQpAH172ZV6ieYrNnFzVVcnSflAg==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "node_modules/@rolldown/binding-darwin-x64": {
+ "version": "1.0.0-rc.12",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.0.0-rc.12.tgz",
+ "integrity": "sha512-ZCsYknnHzeXYps0lGBz8JrF37GpE9bFVefrlmDrAQhOEi4IOIlcoU1+FwHEtyXGx2VkYAvhu7dyBf75EJQffBw==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "node_modules/@rolldown/binding-freebsd-x64": {
+ "version": "1.0.0-rc.12",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.0.0-rc.12.tgz",
+ "integrity": "sha512-dMLeprcVsyJsKolRXyoTH3NL6qtsT0Y2xeuEA8WQJquWFXkEC4bcu1rLZZSnZRMtAqwtrF/Ib9Ddtpa/Gkge9Q==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "freebsd"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "node_modules/@rolldown/binding-linux-arm-gnueabihf": {
+ "version": "1.0.0-rc.12",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.0.0-rc.12.tgz",
+ "integrity": "sha512-YqWjAgGC/9M1lz3GR1r1rP79nMgo3mQiiA+Hfo+pvKFK1fAJ1bCi0ZQVh8noOqNacuY1qIcfyVfP6HoyBRZ85Q==",
+ "cpu": [
+ "arm"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "node_modules/@rolldown/binding-linux-arm64-gnu": {
+ "version": "1.0.0-rc.12",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.0.0-rc.12.tgz",
+ "integrity": "sha512-/I5AS4cIroLpslsmzXfwbe5OmWvSsrFuEw3mwvbQ1kDxJ822hFHIx+vsN/TAzNVyepI/j/GSzrtCIwQPeKCLIg==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "node_modules/@rolldown/binding-linux-arm64-musl": {
+ "version": "1.0.0-rc.12",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.0.0-rc.12.tgz",
+ "integrity": "sha512-V6/wZztnBqlx5hJQqNWwFdxIKN0m38p8Jas+VoSfgH54HSj9tKTt1dZvG6JRHcjh6D7TvrJPWFGaY9UBVOaWPw==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "node_modules/@rolldown/binding-linux-ppc64-gnu": {
+ "version": "1.0.0-rc.12",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.0.0-rc.12.tgz",
+ "integrity": "sha512-AP3E9BpcUYliZCxa3w5Kwj9OtEVDYK6sVoUzy4vTOJsjPOgdaJZKFmN4oOlX0Wp0RPV2ETfmIra9x1xuayFB7g==",
+ "cpu": [
+ "ppc64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "node_modules/@rolldown/binding-linux-s390x-gnu": {
+ "version": "1.0.0-rc.12",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.0.0-rc.12.tgz",
+ "integrity": "sha512-nWwpvUSPkoFmZo0kQazZYOrT7J5DGOJ/+QHHzjvNlooDZED8oH82Yg67HvehPPLAg5fUff7TfWFHQS8IV1n3og==",
+ "cpu": [
+ "s390x"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "node_modules/@rolldown/binding-linux-x64-gnu": {
+ "version": "1.0.0-rc.12",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.0.0-rc.12.tgz",
+ "integrity": "sha512-RNrafz5bcwRy+O9e6P8Z/OCAJW/A+qtBczIqVYwTs14pf4iV1/+eKEjdOUta93q2TsT/FI0XYDP3TCky38LMAg==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "node_modules/@rolldown/binding-linux-x64-musl": {
+ "version": "1.0.0-rc.12",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.0.0-rc.12.tgz",
+ "integrity": "sha512-Jpw/0iwoKWx3LJ2rc1yjFrj+T7iHZn2JDg1Yny1ma0luviFS4mhAIcd1LFNxK3EYu3DHWCps0ydXQ5i/rrJ2ig==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "node_modules/@rolldown/binding-openharmony-arm64": {
+ "version": "1.0.0-rc.12",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.0.0-rc.12.tgz",
+ "integrity": "sha512-vRugONE4yMfVn0+7lUKdKvN4D5YusEiPilaoO2sgUWpCvrncvWgPMzK00ZFFJuiPgLwgFNP5eSiUlv2tfc+lpA==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "openharmony"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "node_modules/@rolldown/binding-wasm32-wasi": {
+ "version": "1.0.0-rc.12",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-wasm32-wasi/-/binding-wasm32-wasi-1.0.0-rc.12.tgz",
+ "integrity": "sha512-ykGiLr/6kkiHc0XnBfmFJuCjr5ZYKKofkx+chJWDjitX+KsJuAmrzWhwyOMSHzPhzOHOy7u9HlFoa5MoAOJ/Zg==",
+ "cpu": [
+ "wasm32"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "@napi-rs/wasm-runtime": "^1.1.1"
+ },
+ "engines": {
+ "node": ">=14.0.0"
+ }
+ },
+ "node_modules/@rolldown/binding-win32-arm64-msvc": {
+ "version": "1.0.0-rc.12",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.0.0-rc.12.tgz",
+ "integrity": "sha512-5eOND4duWkwx1AzCxadcOrNeighiLwMInEADT0YM7xeEOOFcovWZCq8dadXgcRHSf3Ulh1kFo/qvzoFiCLOL1Q==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "node_modules/@rolldown/binding-win32-x64-msvc": {
+ "version": "1.0.0-rc.12",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.0.0-rc.12.tgz",
+ "integrity": "sha512-PyqoipaswDLAZtot351MLhrlrh6lcZPo2LSYE+VDxbVk24LVKAGOuE4hb8xZQmrPAuEtTZW8E6D2zc5EUZX4Lw==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "node_modules/@rolldown/pluginutils": {
+ "version": "1.0.0-rc.12",
+ "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.0-rc.12.tgz",
+ "integrity": "sha512-HHMwmarRKvoFsJorqYlFeFRzXZqCt2ETQlEDOb9aqssrnVBB1/+xgTGtuTrIk5vzLNX1MjMtTf7W9z3tsSbrxw==",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/@standard-schema/spec": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.1.0.tgz",
+ "integrity": "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/@tybys/wasm-util": {
+ "version": "0.10.1",
+ "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.1.tgz",
+ "integrity": "sha512-9tTaPJLSiejZKx+Bmog4uSubteqTvFrVrURwkmHixBo0G4seD0zUxp98E1DzUBJxLQ3NPwXrGKDiVjwx/DpPsg==",
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "tslib": "^2.4.0"
+ }
+ },
+ "node_modules/@types/chai": {
+ "version": "5.2.3",
+ "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz",
+ "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@types/deep-eql": "*",
+ "assertion-error": "^2.0.1"
+ }
+ },
+ "node_modules/@types/deep-eql": {
+ "version": "4.0.2",
+ "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz",
+ "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/@types/estree": {
+ "version": "1.0.8",
+ "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz",
+ "integrity": "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/@types/node": {
"version": "22.19.15",
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.19.15.tgz",
@@ -435,15 +822,150 @@
"dev": true,
"license": "MIT",
"dependencies": {
- "undici-types": "~6.21.0"
+ "undici-types": "~6.21.0"
+ }
+ },
+ "node_modules/@types/qrcode-terminal": {
+ "version": "0.12.2",
+ "resolved": "https://registry.npmjs.org/@types/qrcode-terminal/-/qrcode-terminal-0.12.2.tgz",
+ "integrity": "sha512-v+RcIEJ+Uhd6ygSQ0u5YYY7ZM+la7GgPbs0V/7l/kFs2uO4S8BcIUEMoP7za4DNIqNnUD5npf0A/7kBhrCKG5Q==",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/@vitest/expect": {
+ "version": "4.1.2",
+ "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-4.1.2.tgz",
+ "integrity": "sha512-gbu+7B0YgUJ2nkdsRJrFFW6X7NTP44WlhiclHniUhxADQJH5Szt9mZ9hWnJPJ8YwOK5zUOSSlSvyzRf0u1DSBQ==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@standard-schema/spec": "^1.1.0",
+ "@types/chai": "^5.2.2",
+ "@vitest/spy": "4.1.2",
+ "@vitest/utils": "4.1.2",
+ "chai": "^6.2.2",
+ "tinyrainbow": "^3.1.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ }
+ },
+ "node_modules/@vitest/mocker": {
+ "version": "4.1.2",
+ "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-4.1.2.tgz",
+ "integrity": "sha512-Ize4iQtEALHDttPRCmN+FKqOl2vxTiNUhzobQFFt/BM1lRUTG7zRCLOykG/6Vo4E4hnUdfVLo5/eqKPukcWW7Q==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@vitest/spy": "4.1.2",
+ "estree-walker": "^3.0.3",
+ "magic-string": "^0.30.21"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ },
+ "peerDependencies": {
+ "msw": "^2.4.9",
+ "vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
+ },
+ "peerDependenciesMeta": {
+ "msw": {
+ "optional": true
+ },
+ "vite": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/@vitest/pretty-format": {
+ "version": "4.1.2",
+ "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-4.1.2.tgz",
+ "integrity": "sha512-dwQga8aejqeuB+TvXCMzSQemvV9hNEtDDpgUKDzOmNQayl2OG241PSWeJwKRH3CiC+sESrmoFd49rfnq7T4RnA==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "tinyrainbow": "^3.1.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ }
+ },
+ "node_modules/@vitest/runner": {
+ "version": "4.1.2",
+ "resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-4.1.2.tgz",
+ "integrity": "sha512-Gr+FQan34CdiYAwpGJmQG8PgkyFVmARK8/xSijia3eTFgVfpcpztWLuP6FttGNfPLJhaZVP/euvujeNYar36OQ==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@vitest/utils": "4.1.2",
+ "pathe": "^2.0.3"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ }
+ },
+ "node_modules/@vitest/snapshot": {
+ "version": "4.1.2",
+ "resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-4.1.2.tgz",
+ "integrity": "sha512-g7yfUmxYS4mNxk31qbOYsSt2F4m1E02LFqO53Xpzg3zKMhLAPZAjjfyl9e6z7HrW6LvUdTwAQR3HHfLjpko16A==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@vitest/pretty-format": "4.1.2",
+ "@vitest/utils": "4.1.2",
+ "magic-string": "^0.30.21",
+ "pathe": "^2.0.3"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ }
+ },
+ "node_modules/@vitest/spy": {
+ "version": "4.1.2",
+ "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-4.1.2.tgz",
+ "integrity": "sha512-DU4fBnbVCJGNBwVA6xSToNXrkZNSiw59H8tcuUspVMsBDBST4nfvsPsEHDHGtWRRnqBERBQu7TrTKskmjqTXKA==",
+ "dev": true,
+ "license": "MIT",
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ }
+ },
+ "node_modules/@vitest/ui": {
+ "version": "4.1.2",
+ "resolved": "https://registry.npmjs.org/@vitest/ui/-/ui-4.1.2.tgz",
+ "integrity": "sha512-/irhyeAcKS2u6Zokagf9tqZJ0t8S6kMZq4ZG9BHZv7I+fkRrYfQX4w7geYeC2r6obThz39PDxvXQzZX+qXqGeg==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@vitest/utils": "4.1.2",
+ "fflate": "^0.8.2",
+ "flatted": "^3.4.2",
+ "pathe": "^2.0.3",
+ "sirv": "^3.0.2",
+ "tinyglobby": "^0.2.15",
+ "tinyrainbow": "^3.1.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ },
+ "peerDependencies": {
+ "vitest": "4.1.2"
}
},
- "node_modules/@types/qrcode-terminal": {
- "version": "0.12.2",
- "resolved": "https://registry.npmjs.org/@types/qrcode-terminal/-/qrcode-terminal-0.12.2.tgz",
- "integrity": "sha512-v+RcIEJ+Uhd6ygSQ0u5YYY7ZM+la7GgPbs0V/7l/kFs2uO4S8BcIUEMoP7za4DNIqNnUD5npf0A/7kBhrCKG5Q==",
+ "node_modules/@vitest/utils": {
+ "version": "4.1.2",
+ "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-4.1.2.tgz",
+ "integrity": "sha512-xw2/TiX82lQHA06cgbqRKFb5lCAy3axQ4H4SoUFhUsg+wztiet+co86IAMDtF6Vm1hc7J6j09oh/rgDn+JdKIQ==",
"dev": true,
- "license": "MIT"
+ "license": "MIT",
+ "dependencies": {
+ "@vitest/pretty-format": "4.1.2",
+ "convert-source-map": "^2.0.0",
+ "tinyrainbow": "^3.1.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ }
},
"node_modules/array-buffer-byte-length": {
"version": "1.0.2",
@@ -519,6 +1041,16 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/assertion-error": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz",
+ "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=12"
+ }
+ },
"node_modules/async-function": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/async-function/-/async-function-1.0.0.tgz",
@@ -832,6 +1364,16 @@
"big-integer": "^1.6.34"
}
},
+ "node_modules/chai": {
+ "version": "6.2.2",
+ "resolved": "https://registry.npmjs.org/chai/-/chai-6.2.2.tgz",
+ "integrity": "sha512-NUPRluOfOiTKBKvWPtSD4PhFvWCqOi0BGStNWs57X9js7XGTprSmFoz5F0tWhR4WPjNeR9jXqdC7/UpSJTnlRg==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=18"
+ }
+ },
"node_modules/chalk": {
"version": "5.6.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-5.6.2.tgz",
@@ -905,6 +1447,13 @@
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
"license": "MIT"
},
+ "node_modules/convert-source-map": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz",
+ "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/core-util-is": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
@@ -1073,6 +1622,16 @@
"node": ">=0.4.0"
}
},
+ "node_modules/detect-libc": {
+ "version": "2.1.2",
+ "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz",
+ "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==",
+ "dev": true,
+ "license": "Apache-2.0",
+ "engines": {
+ "node": ">=8"
+ }
+ },
"node_modules/dotignore": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/dotignore/-/dotignore-0.1.2.tgz",
@@ -1262,6 +1821,13 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/es-module-lexer": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.0.0.tgz",
+ "integrity": "sha512-5POEcUuZybH7IdmGsD8wlf0AI55wMecM9rVBTI/qEAy2c1kTOm3DjFYjrBdI2K3BaJjJYfYFeRtM0t9ssnRuxw==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/es-object-atoms": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
@@ -1318,6 +1884,16 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/estree-walker": {
+ "version": "3.0.3",
+ "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz",
+ "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@types/estree": "^1.0.0"
+ }
+ },
"node_modules/evp_bytestokey": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz",
@@ -1328,12 +1904,54 @@
"safe-buffer": "^5.1.1"
}
},
+ "node_modules/expect-type": {
+ "version": "1.3.0",
+ "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.3.0.tgz",
+ "integrity": "sha512-knvyeauYhqjOYvQ66MznSMs83wmHrCycNEN6Ao+2AeYEfxUIkuiVxdEa1qlGEPK+We3n0THiDciYSsCcgW/DoA==",
+ "dev": true,
+ "license": "Apache-2.0",
+ "engines": {
+ "node": ">=12.0.0"
+ }
+ },
+ "node_modules/fdir": {
+ "version": "6.5.0",
+ "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz",
+ "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=12.0.0"
+ },
+ "peerDependencies": {
+ "picomatch": "^3 || ^4"
+ },
+ "peerDependenciesMeta": {
+ "picomatch": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/fflate": {
+ "version": "0.8.2",
+ "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.2.tgz",
+ "integrity": "sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/file-uri-to-path": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
"integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==",
"license": "MIT"
},
+ "node_modules/flatted": {
+ "version": "3.4.2",
+ "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.4.2.tgz",
+ "integrity": "sha512-PjDse7RzhcPkIJwy5t7KPWQSZ9cAbzQXcafsetQoD7sOJRQlGikNbx7yZp2OotDnJyrDcbyRq3Ttb18iYOqkxA==",
+ "dev": true,
+ "license": "ISC"
+ },
"node_modules/follow-redirects": {
"version": "1.15.11",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.11.tgz",
@@ -1391,6 +2009,21 @@
"integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==",
"license": "ISC"
},
+ "node_modules/fsevents": {
+ "version": "2.3.3",
+ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
+ "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
+ "dev": true,
+ "hasInstallScript": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
+ }
+ },
"node_modules/function-bind": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
@@ -2111,53 +2744,324 @@
"call-bound": "^1.0.3"
},
"engines": {
- "node": ">= 0.4"
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/is-weakset": {
+ "version": "2.0.4",
+ "resolved": "https://registry.npmjs.org/is-weakset/-/is-weakset-2.0.4.tgz",
+ "integrity": "sha512-mfcwb6IzQyOKTs84CQMrOwW4gQcaTOAWJ0zzJCl2WSPDrWk/OzDaImWFH3djXhb24g4eudZfLRozAvPGw4d9hQ==",
+ "license": "MIT",
+ "dependencies": {
+ "call-bound": "^1.0.3",
+ "get-intrinsic": "^1.2.6"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/isarray": {
+ "version": "2.0.5",
+ "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz",
+ "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==",
+ "license": "MIT"
+ },
+ "node_modules/js-sha256": {
+ "version": "0.9.0",
+ "resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.9.0.tgz",
+ "integrity": "sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==",
+ "license": "MIT"
+ },
+ "node_modules/keccak": {
+ "version": "3.0.4",
+ "resolved": "https://registry.npmjs.org/keccak/-/keccak-3.0.4.tgz",
+ "integrity": "sha512-3vKuW0jV8J3XNTzvfyicFR5qvxrSAGl7KIhvgOu5cmWwM7tZRj3fMbj/pfIf4be7aznbc+prBWGjywox/g2Y6Q==",
+ "hasInstallScript": true,
+ "license": "MIT",
+ "dependencies": {
+ "node-addon-api": "^2.0.0",
+ "node-gyp-build": "^4.2.0",
+ "readable-stream": "^3.6.0"
+ },
+ "engines": {
+ "node": ">=10.0.0"
+ }
+ },
+ "node_modules/lightningcss": {
+ "version": "1.32.0",
+ "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.32.0.tgz",
+ "integrity": "sha512-NXYBzinNrblfraPGyrbPoD19C1h9lfI/1mzgWYvXUTe414Gz/X1FD2XBZSZM7rRTrMA8JL3OtAaGifrIKhQ5yQ==",
+ "dev": true,
+ "license": "MPL-2.0",
+ "dependencies": {
+ "detect-libc": "^2.0.3"
+ },
+ "engines": {
+ "node": ">= 12.0.0"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/parcel"
+ },
+ "optionalDependencies": {
+ "lightningcss-android-arm64": "1.32.0",
+ "lightningcss-darwin-arm64": "1.32.0",
+ "lightningcss-darwin-x64": "1.32.0",
+ "lightningcss-freebsd-x64": "1.32.0",
+ "lightningcss-linux-arm-gnueabihf": "1.32.0",
+ "lightningcss-linux-arm64-gnu": "1.32.0",
+ "lightningcss-linux-arm64-musl": "1.32.0",
+ "lightningcss-linux-x64-gnu": "1.32.0",
+ "lightningcss-linux-x64-musl": "1.32.0",
+ "lightningcss-win32-arm64-msvc": "1.32.0",
+ "lightningcss-win32-x64-msvc": "1.32.0"
+ }
+ },
+ "node_modules/lightningcss-android-arm64": {
+ "version": "1.32.0",
+ "resolved": "https://registry.npmjs.org/lightningcss-android-arm64/-/lightningcss-android-arm64-1.32.0.tgz",
+ "integrity": "sha512-YK7/ClTt4kAK0vo6w3X+Pnm0D2cf2vPHbhOXdoNti1Ga0al1P4TBZhwjATvjNwLEBCnKvjJc2jQgHXH0NEwlAg==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MPL-2.0",
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": ">= 12.0.0"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/parcel"
+ }
+ },
+ "node_modules/lightningcss-darwin-arm64": {
+ "version": "1.32.0",
+ "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.32.0.tgz",
+ "integrity": "sha512-RzeG9Ju5bag2Bv1/lwlVJvBE3q6TtXskdZLLCyfg5pt+HLz9BqlICO7LZM7VHNTTn/5PRhHFBSjk5lc4cmscPQ==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MPL-2.0",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">= 12.0.0"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/parcel"
+ }
+ },
+ "node_modules/lightningcss-darwin-x64": {
+ "version": "1.32.0",
+ "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.32.0.tgz",
+ "integrity": "sha512-U+QsBp2m/s2wqpUYT/6wnlagdZbtZdndSmut/NJqlCcMLTWp5muCrID+K5UJ6jqD2BFshejCYXniPDbNh73V8w==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MPL-2.0",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">= 12.0.0"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/parcel"
+ }
+ },
+ "node_modules/lightningcss-freebsd-x64": {
+ "version": "1.32.0",
+ "resolved": "https://registry.npmjs.org/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.32.0.tgz",
+ "integrity": "sha512-JCTigedEksZk3tHTTthnMdVfGf61Fky8Ji2E4YjUTEQX14xiy/lTzXnu1vwiZe3bYe0q+SpsSH/CTeDXK6WHig==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MPL-2.0",
+ "optional": true,
+ "os": [
+ "freebsd"
+ ],
+ "engines": {
+ "node": ">= 12.0.0"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/parcel"
+ }
+ },
+ "node_modules/lightningcss-linux-arm-gnueabihf": {
+ "version": "1.32.0",
+ "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.32.0.tgz",
+ "integrity": "sha512-x6rnnpRa2GL0zQOkt6rts3YDPzduLpWvwAF6EMhXFVZXD4tPrBkEFqzGowzCsIWsPjqSK+tyNEODUBXeeVHSkw==",
+ "cpu": [
+ "arm"
+ ],
+ "dev": true,
+ "license": "MPL-2.0",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">= 12.0.0"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/parcel"
+ }
+ },
+ "node_modules/lightningcss-linux-arm64-gnu": {
+ "version": "1.32.0",
+ "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.32.0.tgz",
+ "integrity": "sha512-0nnMyoyOLRJXfbMOilaSRcLH3Jw5z9HDNGfT/gwCPgaDjnx0i8w7vBzFLFR1f6CMLKF8gVbebmkUN3fa/kQJpQ==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MPL-2.0",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">= 12.0.0"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/parcel"
+ }
+ },
+ "node_modules/lightningcss-linux-arm64-musl": {
+ "version": "1.32.0",
+ "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.32.0.tgz",
+ "integrity": "sha512-UpQkoenr4UJEzgVIYpI80lDFvRmPVg6oqboNHfoH4CQIfNA+HOrZ7Mo7KZP02dC6LjghPQJeBsvXhJod/wnIBg==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MPL-2.0",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">= 12.0.0"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/parcel"
+ }
+ },
+ "node_modules/lightningcss-linux-x64-gnu": {
+ "version": "1.32.0",
+ "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.32.0.tgz",
+ "integrity": "sha512-V7Qr52IhZmdKPVr+Vtw8o+WLsQJYCTd8loIfpDaMRWGUZfBOYEJeyJIkqGIDMZPwPx24pUMfwSxxI8phr/MbOA==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MPL-2.0",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">= 12.0.0"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/parcel"
+ }
+ },
+ "node_modules/lightningcss-linux-x64-musl": {
+ "version": "1.32.0",
+ "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.32.0.tgz",
+ "integrity": "sha512-bYcLp+Vb0awsiXg/80uCRezCYHNg1/l3mt0gzHnWV9XP1W5sKa5/TCdGWaR/zBM2PeF/HbsQv/j2URNOiVuxWg==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MPL-2.0",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">= 12.0.0"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/parcel"
+ }
+ },
+ "node_modules/lightningcss-win32-arm64-msvc": {
+ "version": "1.32.0",
+ "resolved": "https://registry.npmjs.org/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.32.0.tgz",
+ "integrity": "sha512-8SbC8BR40pS6baCM8sbtYDSwEVQd4JlFTOlaD3gWGHfThTcABnNDBda6eTZeqbofalIJhFx0qKzgHJmcPTnGdw==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MPL-2.0",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">= 12.0.0"
},
"funding": {
- "url": "https://github.com/sponsors/ljharb"
+ "type": "opencollective",
+ "url": "https://opencollective.com/parcel"
}
},
- "node_modules/is-weakset": {
- "version": "2.0.4",
- "resolved": "https://registry.npmjs.org/is-weakset/-/is-weakset-2.0.4.tgz",
- "integrity": "sha512-mfcwb6IzQyOKTs84CQMrOwW4gQcaTOAWJ0zzJCl2WSPDrWk/OzDaImWFH3djXhb24g4eudZfLRozAvPGw4d9hQ==",
- "license": "MIT",
- "dependencies": {
- "call-bound": "^1.0.3",
- "get-intrinsic": "^1.2.6"
- },
+ "node_modules/lightningcss-win32-x64-msvc": {
+ "version": "1.32.0",
+ "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.32.0.tgz",
+ "integrity": "sha512-Amq9B/SoZYdDi1kFrojnoqPLxYhQ4Wo5XiL8EVJrVsB8ARoC1PWW6VGtT0WKCemjy8aC+louJnjS7U18x3b06Q==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MPL-2.0",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
"engines": {
- "node": ">= 0.4"
+ "node": ">= 12.0.0"
},
"funding": {
- "url": "https://github.com/sponsors/ljharb"
+ "type": "opencollective",
+ "url": "https://opencollective.com/parcel"
}
},
- "node_modules/isarray": {
- "version": "2.0.5",
- "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz",
- "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==",
- "license": "MIT"
- },
- "node_modules/js-sha256": {
- "version": "0.9.0",
- "resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.9.0.tgz",
- "integrity": "sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==",
- "license": "MIT"
- },
- "node_modules/keccak": {
- "version": "3.0.4",
- "resolved": "https://registry.npmjs.org/keccak/-/keccak-3.0.4.tgz",
- "integrity": "sha512-3vKuW0jV8J3XNTzvfyicFR5qvxrSAGl7KIhvgOu5cmWwM7tZRj3fMbj/pfIf4be7aznbc+prBWGjywox/g2Y6Q==",
- "hasInstallScript": true,
+ "node_modules/magic-string": {
+ "version": "0.30.21",
+ "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz",
+ "integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==",
+ "dev": true,
"license": "MIT",
"dependencies": {
- "node-addon-api": "^2.0.0",
- "node-gyp-build": "^4.2.0",
- "readable-stream": "^3.6.0"
- },
- "engines": {
- "node": ">=10.0.0"
+ "@jridgewell/sourcemap-codec": "^1.5.5"
}
},
"node_modules/math-intrinsics": {
@@ -2261,12 +3165,41 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/mrmime": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/mrmime/-/mrmime-2.0.1.tgz",
+ "integrity": "sha512-Y3wQdFg2Va6etvQ5I82yUhGdsKrcYox6p7FfL1LbK2J4V01F9TGlepTIhnK24t7koZibmg82KGglhA1XK5IsLQ==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=10"
+ }
+ },
"node_modules/nan": {
"version": "2.25.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.25.0.tgz",
"integrity": "sha512-0M90Ag7Xn5KMLLZ7zliPWP3rT90P6PN+IzVFS0VqmnPktBk3700xUVv8Ikm9EUaUE5SDWdp/BIxdENzVznpm1g==",
"license": "MIT"
},
+ "node_modules/nanoid": {
+ "version": "3.3.11",
+ "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.11.tgz",
+ "integrity": "sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w==",
+ "dev": true,
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/ai"
+ }
+ ],
+ "license": "MIT",
+ "bin": {
+ "nanoid": "bin/nanoid.cjs"
+ },
+ "engines": {
+ "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
+ }
+ },
"node_modules/node-addon-api": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz",
@@ -2374,6 +3307,17 @@
"node": ">= 0.4"
}
},
+ "node_modules/obug": {
+ "version": "2.1.1",
+ "resolved": "https://registry.npmjs.org/obug/-/obug-2.1.1.tgz",
+ "integrity": "sha512-uTqF9MuPraAQ+IsnPf366RG4cP9RtUi7MLO1N3KEc+wb0a6yKpeL0lmk2IB1jY5KHPAlTc6T/JRdC/YqxHNwkQ==",
+ "dev": true,
+ "funding": [
+ "https://github.com/sponsors/sxzz",
+ "https://opencollective.com/debug"
+ ],
+ "license": "MIT"
+ },
"node_modules/once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
@@ -2415,6 +3359,13 @@
"integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==",
"license": "MIT"
},
+ "node_modules/pathe": {
+ "version": "2.0.3",
+ "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz",
+ "integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/pbkdf2": {
"version": "3.1.5",
"resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.1.5.tgz",
@@ -2452,6 +3403,26 @@
],
"license": "MIT"
},
+ "node_modules/picocolors": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
+ "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
+ "dev": true,
+ "license": "ISC"
+ },
+ "node_modules/picomatch": {
+ "version": "4.0.4",
+ "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.4.tgz",
+ "integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=12"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/jonschlinkert"
+ }
+ },
"node_modules/possible-typed-array-names": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.1.0.tgz",
@@ -2461,6 +3432,35 @@
"node": ">= 0.4"
}
},
+ "node_modules/postcss": {
+ "version": "8.5.8",
+ "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.8.tgz",
+ "integrity": "sha512-OW/rX8O/jXnm82Ey1k44pObPtdblfiuWnrd8X7GJ7emImCOstunGbXUpp7HdBrFQX6rJzn3sPT397Wp5aCwCHg==",
+ "dev": true,
+ "funding": [
+ {
+ "type": "opencollective",
+ "url": "https://opencollective.com/postcss/"
+ },
+ {
+ "type": "tidelift",
+ "url": "https://tidelift.com/funding/github/npm/postcss"
+ },
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/ai"
+ }
+ ],
+ "license": "MIT",
+ "dependencies": {
+ "nanoid": "^3.3.11",
+ "picocolors": "^1.1.1",
+ "source-map-js": "^1.2.1"
+ },
+ "engines": {
+ "node": "^10 || ^12 || >=14"
+ }
+ },
"node_modules/process-nextick-args": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
@@ -2606,6 +3606,40 @@
"node": ">= 0.8"
}
},
+ "node_modules/rolldown": {
+ "version": "1.0.0-rc.12",
+ "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.0.0-rc.12.tgz",
+ "integrity": "sha512-yP4USLIMYrwpPHEFB5JGH1uxhcslv6/hL0OyvTuY+3qlOSJvZ7ntYnoWpehBxufkgN0cvXxppuTu5hHa/zPh+A==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@oxc-project/types": "=0.122.0",
+ "@rolldown/pluginutils": "1.0.0-rc.12"
+ },
+ "bin": {
+ "rolldown": "bin/cli.mjs"
+ },
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ },
+ "optionalDependencies": {
+ "@rolldown/binding-android-arm64": "1.0.0-rc.12",
+ "@rolldown/binding-darwin-arm64": "1.0.0-rc.12",
+ "@rolldown/binding-darwin-x64": "1.0.0-rc.12",
+ "@rolldown/binding-freebsd-x64": "1.0.0-rc.12",
+ "@rolldown/binding-linux-arm-gnueabihf": "1.0.0-rc.12",
+ "@rolldown/binding-linux-arm64-gnu": "1.0.0-rc.12",
+ "@rolldown/binding-linux-arm64-musl": "1.0.0-rc.12",
+ "@rolldown/binding-linux-ppc64-gnu": "1.0.0-rc.12",
+ "@rolldown/binding-linux-s390x-gnu": "1.0.0-rc.12",
+ "@rolldown/binding-linux-x64-gnu": "1.0.0-rc.12",
+ "@rolldown/binding-linux-x64-musl": "1.0.0-rc.12",
+ "@rolldown/binding-openharmony-arm64": "1.0.0-rc.12",
+ "@rolldown/binding-wasm32-wasi": "1.0.0-rc.12",
+ "@rolldown/binding-win32-arm64-msvc": "1.0.0-rc.12",
+ "@rolldown/binding-win32-x64-msvc": "1.0.0-rc.12"
+ }
+ },
"node_modules/safe-array-concat": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/safe-array-concat/-/safe-array-concat-1.1.3.tgz",
@@ -2866,6 +3900,28 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/siginfo": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/siginfo/-/siginfo-2.0.0.tgz",
+ "integrity": "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==",
+ "dev": true,
+ "license": "ISC"
+ },
+ "node_modules/sirv": {
+ "version": "3.0.2",
+ "resolved": "https://registry.npmjs.org/sirv/-/sirv-3.0.2.tgz",
+ "integrity": "sha512-2wcC/oGxHis/BoHkkPwldgiPSYcpZK3JU28WoMVv55yHJgcZ8rlXvuG9iZggz+sU1d4bRgIGASwyWqjxu3FM0g==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@polka/url": "^1.0.0-next.24",
+ "mrmime": "^2.0.0",
+ "totalist": "^3.0.0"
+ },
+ "engines": {
+ "node": ">=18"
+ }
+ },
"node_modules/slp-mdm": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/slp-mdm/-/slp-mdm-0.0.6.tgz",
@@ -2884,6 +3940,30 @@
"bignumber.js": "^9.0.0"
}
},
+ "node_modules/source-map-js": {
+ "version": "1.2.1",
+ "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
+ "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==",
+ "dev": true,
+ "license": "BSD-3-Clause",
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
+ "node_modules/stackback": {
+ "version": "0.0.2",
+ "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz",
+ "integrity": "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/std-env": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/std-env/-/std-env-4.0.0.tgz",
+ "integrity": "sha512-zUMPtQ/HBY3/50VbpkupYHbRroTRZJPRLvreamgErJVys0ceuzMkD44J/QjqhHjOzK42GQ3QZIeFG1OYfOtKqQ==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/stop-iteration-iterator": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/stop-iteration-iterator/-/stop-iteration-iterator-1.1.0.tgz",
@@ -3030,6 +4110,50 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/tinybench": {
+ "version": "2.9.0",
+ "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz",
+ "integrity": "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/tinyexec": {
+ "version": "1.0.4",
+ "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.0.4.tgz",
+ "integrity": "sha512-u9r3uZC0bdpGOXtlxUIdwf9pkmvhqJdrVCH9fapQtgy/OeTTMZ1nqH7agtvEfmGui6e1XxjcdrlxvxJvc3sMqw==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/tinyglobby": {
+ "version": "0.2.15",
+ "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.15.tgz",
+ "integrity": "sha512-j2Zq4NyQYG5XMST4cbs02Ak8iJUdxRM0XI5QyxXuZOzKOINmWurp3smXu3y5wDcJrptwpSjgXHzIQxR0omXljQ==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "fdir": "^6.5.0",
+ "picomatch": "^4.0.3"
+ },
+ "engines": {
+ "node": ">=12.0.0"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/SuperchupuDev"
+ }
+ },
+ "node_modules/tinyrainbow": {
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-3.1.0.tgz",
+ "integrity": "sha512-Bf+ILmBgretUrdJxzXM0SgXLZ3XfiaUuOj/IKQHuTXip+05Xn+uyEYdVg0kYDipTBcLrCVyUzAPz7QmArb0mmw==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=14.0.0"
+ }
+ },
"node_modules/to-buffer": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/to-buffer/-/to-buffer-1.2.2.tgz",
@@ -3064,6 +4188,24 @@
],
"license": "MIT"
},
+ "node_modules/totalist": {
+ "version": "3.0.1",
+ "resolved": "https://registry.npmjs.org/totalist/-/totalist-3.0.1.tgz",
+ "integrity": "sha512-sf4i37nQ2LBx4m3wB74y+ubopq6W/dIzXg0FDGjsYnZHVa1Da8FH853wlL2gtUhg+xJXjfk3kUZS3BRoQeoQBQ==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=6"
+ }
+ },
+ "node_modules/tslib": {
+ "version": "2.8.1",
+ "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
+ "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
+ "dev": true,
+ "license": "0BSD",
+ "optional": true
+ },
"node_modules/typed-array-buffer": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/typed-array-buffer/-/typed-array-buffer-1.0.3.tgz",
@@ -3198,6 +4340,166 @@
"safe-buffer": "^5.1.1"
}
},
+ "node_modules/vite": {
+ "version": "8.0.3",
+ "resolved": "https://registry.npmjs.org/vite/-/vite-8.0.3.tgz",
+ "integrity": "sha512-B9ifbFudT1TFhfltfaIPgjo9Z3mDynBTJSUYxTjOQruf/zHH+ezCQKcoqO+h7a9Pw9Nm/OtlXAiGT1axBgwqrQ==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "lightningcss": "^1.32.0",
+ "picomatch": "^4.0.4",
+ "postcss": "^8.5.8",
+ "rolldown": "1.0.0-rc.12",
+ "tinyglobby": "^0.2.15"
+ },
+ "bin": {
+ "vite": "bin/vite.js"
+ },
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ },
+ "funding": {
+ "url": "https://github.com/vitejs/vite?sponsor=1"
+ },
+ "optionalDependencies": {
+ "fsevents": "~2.3.3"
+ },
+ "peerDependencies": {
+ "@types/node": "^20.19.0 || >=22.12.0",
+ "@vitejs/devtools": "^0.1.0",
+ "esbuild": "^0.27.0",
+ "jiti": ">=1.21.0",
+ "less": "^4.0.0",
+ "sass": "^1.70.0",
+ "sass-embedded": "^1.70.0",
+ "stylus": ">=0.54.8",
+ "sugarss": "^5.0.0",
+ "terser": "^5.16.0",
+ "tsx": "^4.8.1",
+ "yaml": "^2.4.2"
+ },
+ "peerDependenciesMeta": {
+ "@types/node": {
+ "optional": true
+ },
+ "@vitejs/devtools": {
+ "optional": true
+ },
+ "esbuild": {
+ "optional": true
+ },
+ "jiti": {
+ "optional": true
+ },
+ "less": {
+ "optional": true
+ },
+ "sass": {
+ "optional": true
+ },
+ "sass-embedded": {
+ "optional": true
+ },
+ "stylus": {
+ "optional": true
+ },
+ "sugarss": {
+ "optional": true
+ },
+ "terser": {
+ "optional": true
+ },
+ "tsx": {
+ "optional": true
+ },
+ "yaml": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/vitest": {
+ "version": "4.1.2",
+ "resolved": "https://registry.npmjs.org/vitest/-/vitest-4.1.2.tgz",
+ "integrity": "sha512-xjR1dMTVHlFLh98JE3i/f/WePqJsah4A0FK9cc8Ehp9Udk0AZk6ccpIZhh1qJ/yxVWRZ+Q54ocnD8TXmkhspGg==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@vitest/expect": "4.1.2",
+ "@vitest/mocker": "4.1.2",
+ "@vitest/pretty-format": "4.1.2",
+ "@vitest/runner": "4.1.2",
+ "@vitest/snapshot": "4.1.2",
+ "@vitest/spy": "4.1.2",
+ "@vitest/utils": "4.1.2",
+ "es-module-lexer": "^2.0.0",
+ "expect-type": "^1.3.0",
+ "magic-string": "^0.30.21",
+ "obug": "^2.1.1",
+ "pathe": "^2.0.3",
+ "picomatch": "^4.0.3",
+ "std-env": "^4.0.0-rc.1",
+ "tinybench": "^2.9.0",
+ "tinyexec": "^1.0.2",
+ "tinyglobby": "^0.2.15",
+ "tinyrainbow": "^3.1.0",
+ "vite": "^6.0.0 || ^7.0.0 || ^8.0.0",
+ "why-is-node-running": "^2.3.0"
+ },
+ "bin": {
+ "vitest": "vitest.mjs"
+ },
+ "engines": {
+ "node": "^20.0.0 || ^22.0.0 || >=24.0.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ },
+ "peerDependencies": {
+ "@edge-runtime/vm": "*",
+ "@opentelemetry/api": "^1.9.0",
+ "@types/node": "^20.0.0 || ^22.0.0 || >=24.0.0",
+ "@vitest/browser-playwright": "4.1.2",
+ "@vitest/browser-preview": "4.1.2",
+ "@vitest/browser-webdriverio": "4.1.2",
+ "@vitest/ui": "4.1.2",
+ "happy-dom": "*",
+ "jsdom": "*",
+ "vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
+ },
+ "peerDependenciesMeta": {
+ "@edge-runtime/vm": {
+ "optional": true
+ },
+ "@opentelemetry/api": {
+ "optional": true
+ },
+ "@types/node": {
+ "optional": true
+ },
+ "@vitest/browser-playwright": {
+ "optional": true
+ },
+ "@vitest/browser-preview": {
+ "optional": true
+ },
+ "@vitest/browser-webdriverio": {
+ "optional": true
+ },
+ "@vitest/ui": {
+ "optional": true
+ },
+ "happy-dom": {
+ "optional": true
+ },
+ "jsdom": {
+ "optional": true
+ },
+ "vite": {
+ "optional": false
+ }
+ }
+ },
"node_modules/watchtower-cash-js": {
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/watchtower-cash-js/-/watchtower-cash-js-0.2.4.tgz",
@@ -3296,6 +4598,23 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/why-is-node-running": {
+ "version": "2.3.0",
+ "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-2.3.0.tgz",
+ "integrity": "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "siginfo": "^2.0.0",
+ "stackback": "0.0.2"
+ },
+ "bin": {
+ "why-is-node-running": "cli.js"
+ },
+ "engines": {
+ "node": ">=8"
+ }
+ },
"node_modules/wif": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/wif/-/wif-2.0.6.tgz",
diff --git a/package.json b/package.json
index a1583be..a30f9e5 100644
--- a/package.json
+++ b/package.json
@@ -11,6 +11,7 @@
"files": [
"bin/",
"dist/",
+ "skills/",
"LICENSE",
"README.md"
],
@@ -19,6 +20,8 @@
"dev": "tsc --watch",
"start": "node bin/paytaca.js",
"clean": "rm -rf dist",
+ "test": "vitest run",
+ "test:watch": "vitest",
"prepublishOnly": "npm run clean && npm run build"
},
"keywords": [
@@ -49,7 +52,9 @@
"devDependencies": {
"@types/node": "^22.0.0",
"@types/qrcode-terminal": "^0.12.2",
- "typescript": "^5.9.3"
+ "@vitest/ui": "^4.1.2",
+ "typescript": "^5.9.3",
+ "vitest": "^4.1.2"
},
"engines": {
"node": ">=20.0.0"
diff --git a/skills/paytaca/SKILL.md b/skills/paytaca/SKILL.md
new file mode 100644
index 0000000..e259a01
--- /dev/null
+++ b/skills/paytaca/SKILL.md
@@ -0,0 +1,123 @@
+---
+name: paytaca-x402
+description: Handles x402 HTTP payment requests using Paytaca BCH wallet. Use when encountering HTTP 402 responses or when calling APIs that may require payment via the x402 protocol.
+---
+
+# Paytaca x402 Payment Handler
+
+This skill teaches the agent how to handle x402-based HTTP payments using the Paytaca CLI wallet.
+
+## Overview
+
+Some APIs (like nanogpt, etc.) use the x402 protocol for HTTP payments. When you call these APIs:
+- Server returns **HTTP 402 PAYMENT REQUIRED**
+- You must pay with BCH to access the resource
+- After payment, the server returns the actual response
+
+## Commands
+
+### Check if a URL requires payment (recommended first step)
+
+```bash
+paytaca check --json
+# Returns: acceptsX402, acceptsBch, estimatedCostSats, etc.
+```
+
+Example output:
+```json
+{
+ "url": "https://api.nanogpt.com/v1/complete",
+ "acceptsX402": true,
+ "acceptsBch": true,
+ "paymentRequired": true,
+ "estimatedCostSats": "100",
+ "costInBch": "0.00000100"
+}
+```
+
+### Preview payment without executing (dry-run)
+
+```bash
+paytaca pay --dry-run --json
+# Shows what would happen without actually paying
+```
+
+### Make a paid request
+
+```bash
+# Basic
+paytaca pay
+
+# With JSON output (preferred for AI agents)
+paytaca pay --json
+
+# POST request
+paytaca pay --method POST --body '{"prompt":"hello"}'
+
+# Custom headers
+paytaca pay -H "Authorization: Bearer token123"
+```
+
+### Check wallet balance
+
+```bash
+paytaca balance
+```
+
+## Decision Flow
+
+When preparing to call an unfamiliar API that might require payment:
+
+1. **First check**: `paytaca check --json`
+ - If `paymentRequired: false` → proceed normally
+ - If `paymentRequired: true` and `acceptsBch: true` → inform user of cost and **seek explicit approval** before paying
+ - If `paymentRequired: true` but `acceptsBch: false` → inform user
+
+2. **When encountering HTTP 402**:
+ - Parse the `PAYMENT-REQUIRED` headers
+ - **Seek explicit user approval** before spending any BCH
+ - Once approved, use `paytaca pay --json` to handle payment
+ - The command handles: parse headers → build BCH tx → broadcast → retry with signature
+
+3. **For known paid APIs**:
+ - **Always seek user approval first**, then use `paytaca pay ` - it handles 402 automatically
+
+## ⚠️ User Approval Required Before Any Payment
+
+**CRITICAL**: The agent MUST NOT execute `paytaca pay` without explicit user approval. Since `paytaca pay` spends real BCH from the user's wallet, always:
+
+1. Inform the user of the cost (e.g., "This API costs ~1000 sats")
+2. Wait for explicit user confirmation (e.g., "yes", "go ahead", "pay")
+3. Only then execute the payment
+
+Do NOT assume the user wants to pay - even if the cost seems small.
+
+## AI Agent Workflow
+
+```
+Task: Call nanogpt API
+Agent: paytaca check https://api.nanogpt.com/v1/complete --json
+ → {"acceptsBch": true, "estimatedCostSats": "100"}
+
+Agent: Informs user "This API costs 100 sats (0.00000100 BCH). Approve to proceed?"
+User: "yes"
+
+Agent: paytaca pay https://api.nanogpt.com/v1/complete --method POST --body '{"prompt":"hello"}' --json
+ → Handles 402 → pays 100 sats → returns response with txid
+```
+
+## Key Options
+
+| Option | Description |
+|--------|-------------|
+| `--json` | Machine-readable output (recommended for AI) |
+| `--dry-run` | Preview payment without executing |
+| `--chipnet` | Use chipnet (testnet) instead of mainnet |
+| `--max-amount` | Override max payment amount in sats |
+
+## Notes
+
+- Payment is per-request (no batching)
+- Each request = separate BCH transaction
+- Only BCH payments are supported (no stablecoins)
+- Uses local wallet from OS keychain (credentials never leave the machine)
diff --git a/src/commands/check.ts b/src/commands/check.ts
new file mode 100644
index 0000000..1e828c6
--- /dev/null
+++ b/src/commands/check.ts
@@ -0,0 +1,206 @@
+/**
+ * CLI command: check
+ *
+ * Check if a URL accepts x402-bch v2.2 BCH payments without making the actual request.
+ * Useful for AI to determine if payment will be required before committing.
+ *
+ * Usage:
+ * paytaca check https://api.example.com
+ * paytaca check https://api.example.com --json
+ * paytaca check https://api.example.com --method POST --body '{"query":"hi"}'
+ */
+
+import { Command } from 'commander'
+import chalk from 'chalk'
+import { loadWallet, loadMnemonic } from '../wallet/index.js'
+import { LibauthHDWallet } from '../wallet/keys.js'
+import { BchWallet } from '../wallet/bch.js'
+import { parsePaymentRequiredJson, selectBchPaymentRequirements } from '../utils/x402.js'
+import { BCH_DERIVATION_PATH } from '../utils/network.js'
+import { PaymentRequired } from '../types/x402.js'
+
+interface CheckOptions {
+ method?: string
+ header?: string[]
+ body?: string
+ chipnet: boolean
+ json: boolean
+}
+
+interface CheckResult {
+ url: string
+ acceptsX402: boolean
+ acceptsBch: boolean
+ paymentRequired: boolean
+ estimatedCostSats?: string
+ costInBch?: string
+ paymentUrl?: string
+ maxTimeoutSeconds?: number
+ resourceUrl?: string
+ error?: string
+}
+
+export function registerCheckCommand(program: Command): void {
+ program
+ .command('check')
+ .description('Check if a URL accepts x402-bch v2.2 BCH payments')
+ .argument('', 'URL to check')
+ .option('-X, --method ', 'HTTP method to test (default: GET)', 'GET')
+ .option('-H, --header ', 'Add header to request (repeatable)')
+ .option('-d, --body ', 'Request body for POST/PUT requests')
+ .option('--chipnet', 'Use chipnet (testnet) instead of mainnet')
+ .option('--json', 'Output results as JSON')
+ .action(async (url: string, opts: CheckOptions) => {
+ const isChipnet = Boolean(opts.chipnet)
+ const isJson = Boolean(opts.json)
+ const network = isChipnet ? 'chipnet' : 'mainnet'
+
+ const data = loadMnemonic()
+ if (!data) {
+ const err = 'No wallet found. Run `paytaca wallet create` or `paytaca wallet import` first.'
+ if (isJson) {
+ console.log(JSON.stringify({ url, acceptsX402: false, acceptsBch: false, paymentRequired: false, error: err }))
+ } else {
+ console.log(chalk.red(`\n${err}\n`))
+ }
+ process.exit(1)
+ }
+
+ const wallet = loadWallet()!
+ const bchWallet = wallet.forNetwork(isChipnet)
+ const hdWallet = new LibauthHDWallet(
+ data.mnemonic,
+ BCH_DERIVATION_PATH,
+ isChipnet ? 'chipnet' : 'mainnet'
+ )
+
+ const headers: Record = {}
+ if (opts.header) {
+ for (const h of opts.header) {
+ const idx = h.indexOf(':')
+ if (idx === -1) {
+ const err = `Invalid header format: ${h}. Expected "Key: Value"`
+ if (isJson) {
+ console.log(JSON.stringify({ url, acceptsX402: false, acceptsBch: false, error: err }))
+ } else {
+ console.log(chalk.red(`\n Error: ${err}\n`))
+ }
+ process.exit(1)
+ }
+ const key = h.substring(0, idx).trim()
+ const value = h.substring(idx + 1).trim()
+ headers[key] = value
+ }
+ }
+
+ const method = opts.method?.toUpperCase() || 'GET'
+ const body = opts.body
+
+ if (!isJson) {
+ console.log(`\n ${chalk.bold('CHECK')} ${url}`)
+ console.log(chalk.dim(` Network: ${chalk.cyan(network)}`))
+ console.log(chalk.dim(` Method: ${method}`))
+ console.log()
+ }
+
+ try {
+ const result = await checkUrl(url, method, headers, body, bchWallet, isChipnet)
+
+ if (isJson) {
+ console.log(JSON.stringify(result, null, 2))
+ } else {
+ printCheckResult(result)
+ }
+ } catch (err: any) {
+ const errorResult: CheckResult = {
+ url,
+ acceptsX402: false,
+ acceptsBch: false,
+ paymentRequired: false,
+ error: err.message || String(err),
+ }
+ if (isJson) {
+ console.log(JSON.stringify(errorResult, null, 2))
+ } else {
+ console.log(chalk.red(`\n Error: ${err.message || err}\n`))
+ }
+ process.exit(1)
+ }
+
+ if (!isJson) console.log()
+ })
+}
+
+async function checkUrl(
+ url: string,
+ method: string,
+ headers: Record,
+ body: string | undefined,
+ bchWallet: BchWallet,
+ isChipnet: boolean
+): Promise {
+ const result: CheckResult = {
+ url,
+ acceptsX402: false,
+ acceptsBch: false,
+ paymentRequired: false,
+ }
+
+ const response = await fetch(url, {
+ method,
+ headers,
+ body: ['POST', 'PUT', 'PATCH'].includes(method) ? body : undefined,
+ })
+
+ result.paymentRequired = response.status === 402
+
+ if (response.status === 402) {
+ try {
+ const responseBody = await response.json()
+ const paymentRequired = parsePaymentRequiredJson(responseBody)
+
+ if (paymentRequired) {
+ result.acceptsX402 = paymentRequired.x402Version === 2
+ result.resourceUrl = paymentRequired.resource?.url
+
+ const bchReqs = selectBchPaymentRequirements(paymentRequired, isChipnet ? 'chipnet' : 'mainnet')
+ if (bchReqs) {
+ result.acceptsBch = true
+ result.paymentUrl = bchReqs.payTo
+ result.estimatedCostSats = bchReqs.amount
+ result.costInBch = (Number(bchReqs.amount) / 1e8).toFixed(8)
+ result.maxTimeoutSeconds = bchReqs.maxTimeoutSeconds
+ }
+ }
+ } catch (e) {
+ result.error = 'Failed to parse 402 response body'
+ }
+ }
+
+ return result
+}
+
+function printCheckResult(result: CheckResult): void {
+ if (result.paymentRequired) {
+ console.log(chalk.yellow(' Payment Required'))
+
+ if (result.acceptsX402) {
+ console.log(chalk.green(' ✓ Accepts x402-bch v2.2 protocol'))
+
+ if (result.acceptsBch) {
+ console.log(chalk.green(` ✓ Accepts BCH payment`))
+ console.log(chalk.dim(` Amount: ${result.estimatedCostSats} sats (${result.costInBch} BCH)`))
+ console.log(chalk.dim(` Payment URL: ${result.paymentUrl}`))
+ console.log(chalk.dim(` Timeout: ${result.maxTimeoutSeconds}s`))
+ console.log(chalk.dim(` Resource: ${result.resourceUrl}`))
+ } else {
+ console.log(chalk.red(' ✗ Does not accept BCH'))
+ }
+ } else {
+ console.log(chalk.red(' ✗ Unknown payment protocol (not x402-bch v2.2)'))
+ }
+ } else {
+ console.log(chalk.green(' ✓ No payment required'))
+ console.log(chalk.dim(` Status: ${result.url} is free to access`))
+ }
+}
diff --git a/src/commands/claude.ts b/src/commands/claude.ts
new file mode 100644
index 0000000..c7e1471
--- /dev/null
+++ b/src/commands/claude.ts
@@ -0,0 +1,24 @@
+/**
+ * CLI command: claude
+ *
+ * Set up paytaca x402 payment handling for Claude Code AI assistant.
+ * Installs the paytaca skill so Claude Code knows how to handle 402 responses.
+ */
+
+import { Command } from 'commander'
+import os from 'os'
+import path from 'path'
+import { SUPPORTED_ASSISTANTS, handleSkillAction } from '../utils/skill.js'
+
+export function registerClaudeCommand(program: Command): void {
+ const assistant = SUPPORTED_ASSISTANTS.find(a => a.name === 'Claude Code')
+ if (!assistant) return
+
+ program
+ .command('claude')
+ .description('Set up paytaca x402 payments for Claude Code AI assistant')
+ .argument('[action]', 'Action: install, uninstall, status', 'status')
+ .action(async (action: string) => {
+ handleSkillAction(assistant, action)
+ })
+}
diff --git a/src/commands/opencode.ts b/src/commands/opencode.ts
new file mode 100644
index 0000000..c6a13a7
--- /dev/null
+++ b/src/commands/opencode.ts
@@ -0,0 +1,22 @@
+/**
+ * CLI command: opencode
+ *
+ * Set up paytaca x402 payment handling for opencode AI assistant.
+ * Installs the paytaca skill so opencode knows how to handle 402 responses.
+ */
+
+import { Command } from 'commander'
+import { SUPPORTED_ASSISTANTS, handleSkillAction } from '../utils/skill.js'
+
+export function registerOpencodeCommand(program: Command): void {
+ const assistant = SUPPORTED_ASSISTANTS.find(a => a.name === 'opencode')
+ if (!assistant) return
+
+ program
+ .command('opencode')
+ .description('Set up paytaca x402 payments for opencode AI assistant')
+ .argument('[action]', 'Action: install, uninstall, status', 'status')
+ .action(async (action: string) => {
+ handleSkillAction(assistant, action)
+ })
+}
diff --git a/src/commands/pay.ts b/src/commands/pay.ts
new file mode 100644
index 0000000..40a457c
--- /dev/null
+++ b/src/commands/pay.ts
@@ -0,0 +1,482 @@
+/**
+ * CLI command: pay
+ *
+ * Makes an HTTP request to a URL, handling x402-bch v2.2 payment requirements.
+ * If the server returns 402 PAYMENT-REQUIRED, the wallet pays for the request.
+ *
+ * Flow:
+ * 1. Make HTTP request to URL
+ * 2. If 402 response, parse PaymentRequired JSON body
+ * 3. Build BCH transaction to pay the required amount
+ * 4. Broadcast transaction
+ * 5. Build PaymentPayload per x402-bch v2.2 spec
+ * 6. Retry original request with PAYMENT-SIGNATURE header containing JSON PayloadPayload
+ */
+
+import { Command } from 'commander'
+import chalk from 'chalk'
+import readline from 'readline'
+import { loadWallet, loadMnemonic } from '../wallet/index.js'
+import { LibauthHDWallet } from '../wallet/keys.js'
+import { BchWallet } from '../wallet/bch.js'
+import { X402Payer } from '../wallet/x402.js'
+import { parsePaymentRequiredJson, selectBchPaymentRequirements } from '../utils/x402.js'
+import { BCH_DERIVATION_PATH } from '../utils/network.js'
+import { PaymentRequired, PaymentRequirements, BCH_ASSET_ID } from '../types/x402.js'
+
+interface PayOptions {
+ method?: string
+ header?: string[]
+ body?: string
+ chipnet: boolean
+ maxAmount?: string
+ changeAddress?: string
+ payer?: string
+ dryRun: boolean
+ json: boolean
+}
+
+interface DryRunInfo {
+ url: string
+ method: string
+ willRequirePayment: boolean
+ payment?: {
+ acceptsBch: boolean
+ paymentUrl: string
+ amountSats: string
+ maxTimeoutSeconds: number
+ resourceUrl: string
+ payerAddress: string
+ changeAddress: string
+ network: string
+ }
+ balanceCheck?: {
+ available: string
+ required: string
+ sufficient: boolean
+ }
+}
+
+interface JsonResult {
+ success: boolean
+ status?: number
+ statusText?: string
+ headers?: Record
+ data?: any
+ payment?: {
+ required: boolean
+ txid?: string
+ error?: string
+ recipientAddress?: string
+ }
+ error?: string
+}
+
+export function registerPayCommand(program: Command): void {
+ program
+ .command('pay')
+ .description('Make a paid HTTP request with BCH payment via x402-bch v2.2 protocol')
+ .argument('', 'URL to request')
+ .option('-X, --method ', 'HTTP method (default: GET)', 'GET')
+ .option('-H, --header ', 'Add header to request (repeatable)')
+ .option('-d, --body ', 'Request body for POST/PUT requests')
+ .option('--chipnet', 'Use chipnet (testnet) instead of mainnet')
+ .option('--max-amount ', 'Maximum payment amount in satoshis (overrides server\'s max-amount)')
+ .option('--change-address ', 'Change address for BCH transaction')
+ .option('--payer ', 'Payer identifier (defaults to wallet address index 0, or pass custom value like user ID for server-side lookups)')
+ .option('--dry-run', 'Show what would happen without making payment')
+ .option('--json', 'Output results as JSON')
+ .action(async (url: string, opts: PayOptions) => {
+ const isChipnet = Boolean(opts.chipnet)
+ const network = isChipnet ? 'chipnet' : 'mainnet'
+ const isJson = Boolean(opts.json)
+ const isDryRun = Boolean(opts.dryRun)
+
+ const data = loadMnemonic()
+ if (!data) {
+ const err = 'No wallet found. Run `paytaca wallet create` or `paytaca wallet import` first.'
+ if (isJson) {
+ console.log(JSON.stringify({ success: false, error: err }))
+ } else {
+ console.log(chalk.red(`\n${err}\n`))
+ }
+ process.exit(1)
+ }
+
+ const wallet = loadWallet()!
+ const bchWallet = wallet.forNetwork(isChipnet)
+ const hdWallet = new LibauthHDWallet(
+ data.mnemonic,
+ BCH_DERIVATION_PATH,
+ isChipnet ? 'chipnet' : 'mainnet'
+ )
+
+ const x402Payer = new X402Payer({ hdWallet, addressIndex: 0 })
+
+ const headers: Record = {}
+ if (opts.header) {
+ for (const h of opts.header) {
+ const idx = h.indexOf(':')
+ if (idx === -1) {
+ const err = `Invalid header format: ${h}. Expected "Key: Value"`
+ if (isJson) {
+ console.log(JSON.stringify({ success: false, error: err }))
+ } else {
+ console.log(chalk.red(`\n Error: ${err}\n`))
+ }
+ process.exit(1)
+ }
+ const key = h.substring(0, idx).trim()
+ const value = h.substring(idx + 1).trim()
+ headers[key] = value
+ }
+ }
+
+ const method = opts.method?.toUpperCase() || 'GET'
+ const body = opts.body
+
+ if (isJson) {
+ await runPayJson(url, method, headers, body, opts, x402Payer, bchWallet, isChipnet)
+ } else if (isDryRun) {
+ await runPayDryRun(url, method, headers, body, opts, x402Payer, bchWallet, isChipnet)
+ } else {
+ await runPayHuman(url, method, headers, body, opts, x402Payer, bchWallet, isChipnet)
+ }
+ })
+}
+
+async function runPayHuman(
+ url: string,
+ method: string,
+ headers: Record,
+ body: string | undefined,
+ opts: PayOptions,
+ x402Payer: X402Payer,
+ bchWallet: BchWallet,
+ isChipnet: boolean
+): Promise {
+ const network = isChipnet ? 'chipnet' : 'mainnet'
+
+ console.log(`\n ${chalk.bold(method)} ${url}`)
+ console.log(chalk.dim(` Network: ${chalk.cyan(network)}`))
+ console.log(chalk.dim(` Payer: ${opts.payer || x402Payer.getPayerAddress()}`))
+ if (Object.keys(headers).length > 0) {
+ console.log(chalk.dim(` Headers: ${JSON.stringify(headers)}`))
+ }
+ console.log()
+
+ try {
+ const result = await executePay(url, method, headers, body, opts, x402Payer, bchWallet, false)
+
+ if (result.payment?.required && result.payment.txid) {
+ const explorer = isChipnet
+ ? 'https://chipnet.chaingraph.cash/tx/'
+ : 'https://bchexplorer.info/tx/'
+ console.log(chalk.dim(` Payment txid: ${explorer}${result.payment.txid}`))
+ if (result.payment.recipientAddress) {
+ console.log(chalk.dim(` Recipient: ${result.payment.recipientAddress}`))
+ }
+ }
+
+ console.log(chalk.green(`\n Response: ${result.status} ${result.statusText}`))
+ console.log()
+ console.log(formatResponse(result.data))
+ } catch (err: any) {
+ console.log(chalk.red(`\n Error: ${err.message || err}\n`))
+ process.exit(1)
+ }
+
+ console.log()
+}
+
+async function runPayDryRun(
+ url: string,
+ method: string,
+ headers: Record,
+ body: string | undefined,
+ opts: PayOptions,
+ x402Payer: X402Payer,
+ bchWallet: BchWallet,
+ isChipnet: boolean
+): Promise {
+ const network = isChipnet ? 'chipnet' : 'mainnet'
+ const dryRunInfo: DryRunInfo = {
+ url,
+ method,
+ willRequirePayment: false,
+ }
+
+ console.log(`\n ${chalk.bold(method)} ${url} ${chalk.dim('[DRY RUN]')}`)
+ console.log(chalk.dim(` Network: ${chalk.cyan(network)}`))
+ console.log(chalk.dim(` Payer: ${opts.payer || x402Payer.getPayerAddress()}`))
+ console.log()
+
+ try {
+ const response = await fetch(url, {
+ method,
+ headers,
+ body: ['POST', 'PUT', 'PATCH'].includes(method) ? body : undefined,
+ })
+
+ if (response.status === 402) {
+ dryRunInfo.willRequirePayment = true
+
+ const responseBody = await response.json()
+ const paymentRequired = parsePaymentRequiredJson(responseBody)
+
+ if (!paymentRequired) {
+ console.log(chalk.red(' Error: Could not parse PaymentRequired from 402 response body'))
+ process.exit(1)
+ }
+
+ const requirements = selectBchPaymentRequirements(paymentRequired, isChipnet ? 'chipnet' : 'mainnet')
+ if (!requirements) {
+ console.log(chalk.red(' Error: Server does not accept BCH payment'))
+ const acceptedSchemes = paymentRequired.accepts.map(a => `${a.scheme}:${a.network}`).join(', ')
+ console.log(chalk.dim(` Accepted schemes: ${acceptedSchemes}`))
+ process.exit(1)
+ }
+
+ const changeAddressSet = bchWallet.getAddressSetAt(0)
+ const changeAddress = opts.changeAddress || changeAddressSet.change
+
+ dryRunInfo.payment = {
+ acceptsBch: true,
+ paymentUrl: requirements.payTo,
+ amountSats: requirements.amount,
+ maxTimeoutSeconds: requirements.maxTimeoutSeconds,
+ resourceUrl: paymentRequired.resource.url,
+ payerAddress: opts.payer || x402Payer.getPayerAddress(),
+ changeAddress,
+ network: requirements.network,
+ }
+
+ try {
+ const balanceResult = await bchWallet.getBalance()
+ const available = (balanceResult.spendable * 1e8).toFixed(0)
+ const required = requirements.amount
+ const sufficient = BigInt(available) >= BigInt(required)
+
+ dryRunInfo.balanceCheck = {
+ available,
+ required,
+ sufficient,
+ }
+
+ console.log(chalk.yellow(' 402 PAYMENT REQUIRED'))
+ console.log(chalk.dim(' Payment details:'))
+ console.log(chalk.dim(` PayTo: ${requirements.payTo}`))
+ console.log(chalk.dim(` Amount: ${requirements.amount} sats (${(Number(requirements.amount) / 1e8).toFixed(8)} BCH)`))
+ console.log(chalk.dim(` Timeout: ${requirements.maxTimeoutSeconds}s`))
+ console.log(chalk.dim(` Resource: ${paymentRequired.resource.url}`))
+ console.log()
+ console.log(chalk.dim(' Wallet:'))
+ console.log(chalk.dim(` Payer: ${opts.payer || x402Payer.getPayerAddress()}`))
+ console.log(chalk.dim(` Change: ${changeAddress}`))
+ console.log()
+ if (sufficient) {
+ console.log(chalk.green(` Balance OK: ${available} sats available, ${required} sats required`))
+ } else {
+ console.log(chalk.red(` Insufficient: ${available} sats available, ${required} sats required`))
+ }
+ } catch (balanceErr) {
+ console.log(chalk.dim(` (Could not check balance: ${(balanceErr as Error).message})`))
+ }
+ } else {
+ console.log(chalk.green(` Response: ${response.status} ${response.statusText} (no payment required)`))
+ }
+
+ console.log()
+ console.log(chalk.dim(' To execute: paytaca pay ' + url))
+ } catch (err: any) {
+ console.log(chalk.red(`\n Error: ${err.message || err}\n`))
+ process.exit(1)
+ }
+}
+
+async function runPayJson(
+ url: string,
+ method: string,
+ headers: Record,
+ body: string | undefined,
+ opts: PayOptions,
+ x402Payer: X402Payer,
+ bchWallet: BchWallet,
+ isChipnet: boolean
+): Promise {
+ try {
+ const result = await executePay(url, method, headers, body, opts, x402Payer, bchWallet, false)
+ console.log(JSON.stringify(result, null, 2))
+ } catch (err: any) {
+ const errorResult: JsonResult = { success: false, error: err.message || String(err) }
+ console.log(JSON.stringify(errorResult, null, 2))
+ process.exit(1)
+ }
+}
+
+async function executePay(
+ url: string,
+ method: string,
+ headers: Record,
+ body: string | undefined,
+ opts: PayOptions,
+ x402Payer: X402Payer,
+ bchWallet: BchWallet,
+ skipPayment: boolean
+): Promise {
+ const response = await fetch(url, {
+ method,
+ headers,
+ body: ['POST', 'PUT', 'PATCH'].includes(method) ? body : undefined,
+ })
+
+ const responseHeaders: Record = {}
+ response.headers.forEach((value, key) => {
+ responseHeaders[key] = value
+ })
+
+ const responseText = await response.text()
+ let responseData: any
+ try {
+ responseData = JSON.parse(responseText)
+ } catch {
+ responseData = responseText
+ }
+
+ if (response.status === 402) {
+ const paymentRequired = parsePaymentRequiredJson(responseData)
+ if (!paymentRequired) {
+ return { success: false, status: 402, error: 'Could not parse PaymentRequired from 402 response body' }
+ }
+
+ const requirements = selectBchPaymentRequirements(paymentRequired, opts.chipnet ? 'chipnet' : 'mainnet')
+ if (!requirements) {
+ return {
+ success: false,
+ status: 402,
+ error: 'Server does not accept BCH payment',
+ data: { acceptedSchemes: paymentRequired.accepts.map(a => ({ scheme: a.scheme, network: a.network })) },
+ }
+ }
+
+ if (skipPayment) {
+ return {
+ success: true,
+ status: 402,
+ payment: { required: true },
+ }
+ }
+
+ const payerAddress = opts.payer || x402Payer.getPayerAddress()
+
+ const address = requirements.payTo
+
+ const amountBch = Number(requirements.amount) / 1e8
+
+ const changeAddressSet = bchWallet.getAddressSetAt(0)
+ const changeAddress = opts.changeAddress || changeAddressSet.change
+
+ console.log(chalk.yellow('\n ⚠ Payment Required'))
+ console.log(chalk.dim(` Amount: ${amountBch} BCH (${requirements.amount} sats)`))
+ console.log(chalk.dim(` To: ${address}`))
+ console.log(chalk.dim(` Change: ${changeAddress}`))
+ console.log(chalk.dim(` Payer: ${payerAddress}`))
+
+ const confirmed = await promptConfirmation('Confirm payment?')
+ if (!confirmed) {
+ return {
+ success: false,
+ status: 402,
+ payment: { required: true, error: 'Payment rejected by user' },
+ error: 'Payment rejected by user',
+ }
+ }
+
+ const sendResult = await bchWallet.sendBch(amountBch, address, changeAddress)
+
+ if (!sendResult.success) {
+ return {
+ success: false,
+ status: 402,
+ payment: { required: true, error: sendResult.error },
+ error: sendResult.error,
+ }
+ }
+
+ const txid = sendResult.txid!
+
+ const paymentPayload = await x402Payer.createPaymentPayload(
+ requirements,
+ paymentRequired.resource.url,
+ txid,
+ 0,
+ requirements.amount
+ )
+
+ headers['PAYMENT-SIGNATURE'] = JSON.stringify(paymentPayload)
+
+ const retryResponse = await fetch(url, {
+ method,
+ headers,
+ body: ['POST', 'PUT', 'PATCH'].includes(method) ? body : undefined,
+ })
+
+ const retryResponseHeaders: Record = {}
+ retryResponse.headers.forEach((value, key) => {
+ retryResponseHeaders[key] = value
+ })
+
+ const retryResponseText = await retryResponse.text()
+ let retryResponseData: any
+ try {
+ retryResponseData = JSON.parse(retryResponseText)
+ } catch {
+ retryResponseData = retryResponseText
+ }
+
+ return {
+ success: retryResponse.ok,
+ status: retryResponse.status,
+ statusText: retryResponse.statusText,
+ headers: retryResponseHeaders,
+ data: retryResponseData,
+ payment: { required: true, txid, recipientAddress: address },
+ }
+ }
+
+ return {
+ success: response.ok,
+ status: response.status,
+ statusText: response.statusText,
+ headers: responseHeaders,
+ data: responseData,
+ payment: { required: false },
+ }
+}
+
+function formatResponse(data: any): string {
+ if (typeof data === 'string') return data
+ if (typeof data === 'object') {
+ try {
+ return JSON.stringify(data, null, 2)
+ } catch {
+ return String(data)
+ }
+ }
+ return String(data)
+}
+
+async function promptConfirmation(message: string): Promise {
+ const rl = readline.createInterface({
+ input: process.stdin,
+ output: process.stdout,
+ })
+
+ return new Promise((resolve) => {
+ rl.question(chalk.bold(`\n ${message} (y/N): `), (answer) => {
+ rl.close()
+ const confirmed = answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes'
+ resolve(confirmed)
+ })
+ })
+}
diff --git a/src/index.ts b/src/index.ts
index bef74b5..214d548 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -14,6 +14,10 @@ import { registerBalanceCommand } from './commands/balance.js'
import { registerReceiveCommand } from './commands/receive.js'
import { registerHistoryCommand } from './commands/history.js'
import { registerTokenCommands } from './commands/token.js'
+import { registerPayCommand } from './commands/pay.js'
+import { registerCheckCommand } from './commands/check.js'
+import { registerOpencodeCommand } from './commands/opencode.js'
+import { registerClaudeCommand } from './commands/claude.js'
const program = new Command()
@@ -29,5 +33,9 @@ registerBalanceCommand(program)
registerReceiveCommand(program)
registerHistoryCommand(program)
registerTokenCommands(program)
+registerPayCommand(program)
+registerCheckCommand(program)
+registerOpencodeCommand(program)
+registerClaudeCommand(program)
program.parse()
diff --git a/src/types/bitcoinjs-message.d.ts b/src/types/bitcoinjs-message.d.ts
new file mode 100644
index 0000000..de14711
--- /dev/null
+++ b/src/types/bitcoinjs-message.d.ts
@@ -0,0 +1,20 @@
+declare module 'bitcoinjs-message' {
+ export function sign(
+ message: string,
+ privateKey: Buffer,
+ compressed?: boolean,
+ messagePrefix?: string
+ ): Buffer
+
+ export function verify(
+ message: string,
+ address: string,
+ signature: Buffer | string,
+ messagePrefix?: string
+ ): boolean
+
+ export function magicHash(
+ message: string,
+ messagePrefix?: string
+ ): Buffer
+}
diff --git a/src/types/x402.ts b/src/types/x402.ts
new file mode 100644
index 0000000..e764391
--- /dev/null
+++ b/src/types/x402.ts
@@ -0,0 +1,94 @@
+/**
+ * x402 BCH type definitions
+ * Implements x402-bch v2.2 specification
+ * https://github.com/x402-bch/x402-bch/blob/master/specs/x402-bch-specification-v2.2.md
+ */
+
+export const BCH_ASSET_ID = '0x0000000000000000000000000000000000000001'
+export const BCH_MAINNET_NETWORK = 'bip122:000000000000000000651ef99cb9fcbe'
+export const BCH_CHIPNET_NETWORK = 'bip122:000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'
+
+export interface ResourceInfo {
+ url: string
+ description?: string
+ mimeType?: string
+}
+
+export interface PaymentRequirements {
+ scheme: string
+ network: string
+ amount: string
+ asset: string
+ payTo: string
+ maxTimeoutSeconds: number
+ extra: object
+}
+
+export interface PaymentRequired {
+ x402Version: number
+ error?: string
+ resource: ResourceInfo
+ accepts: PaymentRequirements[]
+ extensions: object
+}
+
+export interface Authorization {
+ from: string
+ to: string
+ value: string
+ txid: string
+ vout: number | null
+ amount: string | null
+}
+
+export interface Payload {
+ signature: string
+ authorization: Authorization
+}
+
+export interface PaymentPayload {
+ x402Version: number
+ resource?: ResourceInfo
+ accepted: PaymentRequirements
+ payload: Payload
+ extensions: object
+}
+
+export interface VerifyResponse {
+ isValid: boolean
+ payer?: string
+ invalidReason?: string
+ remainingBalanceSat?: string
+}
+
+export interface X402PaymentResult {
+ success: boolean
+ response?: {
+ status: number
+ statusText: string
+ headers: Record
+ data?: any
+ }
+ error?: string
+ txid?: string
+ settlement?: {
+ success: boolean
+ txid?: string
+ error?: string
+ }
+}
+
+export type ErrorCode =
+ | 'missing_authorization'
+ | 'invalid_payload'
+ | 'invalid_scheme'
+ | 'invalid_network'
+ | 'invalid_receiver_address'
+ | 'invalid_exact_bch_payload_signature'
+ | 'insufficient_utxo_balance'
+ | 'utxo_not_found'
+ | 'no_utxo_found_for_address'
+ | 'unexpected_utxo_validation_error'
+ | 'unexpected_verify_error'
+ | 'unexpected_settle_error'
+ | 'invalid_x402_version'
diff --git a/src/utils/skill.ts b/src/utils/skill.ts
new file mode 100644
index 0000000..fa2735e
--- /dev/null
+++ b/src/utils/skill.ts
@@ -0,0 +1,118 @@
+/**
+ * Skill management utilities for AI assistant integration.
+ * Provides generic functions for installing/uninstalling/checking status
+ * of paytaca skill for various AI assistants.
+ */
+
+import chalk from 'chalk'
+import fs from 'fs'
+import path from 'path'
+import os from 'os'
+import { fileURLToPath } from 'url'
+
+export interface AssistantConfig {
+ name: string
+ skillsDir: string
+}
+
+export const SUPPORTED_ASSISTANTS: AssistantConfig[] = [
+ { name: 'opencode', skillsDir: path.join(os.homedir(), '.config', 'opencode', 'skills') },
+ { name: 'Claude Code', skillsDir: path.join(os.homedir(), '.claude', 'skills') },
+]
+
+export function getSkillSourcePath(): string {
+ try {
+ const modulePath = require.resolve('paytaca-cli')
+ const packageDir = path.dirname(modulePath)
+ return path.join(packageDir, 'skills', 'paytaca', 'SKILL.md')
+ } catch {
+ const currentFilePath = fileURLToPath(import.meta.url)
+ const srcPath = path.dirname(currentFilePath)
+ return path.join(srcPath, '..', '..', 'skills', 'paytaca', 'SKILL.md')
+ }
+}
+
+export function getSkillDestPath(skillsDir: string): string {
+ return path.join(skillsDir, 'paytaca', 'SKILL.md')
+}
+
+export function installSkill(skillsDir: string, assistantName: string): void {
+ try {
+ const sourcePath = getSkillSourcePath()
+ const destDir = path.join(skillsDir, 'paytaca')
+ const destPath = getSkillDestPath(skillsDir)
+
+ if (!fs.existsSync(sourcePath)) {
+ console.log(chalk.red('Skill source file not found. Is paytaca-cli properly installed?'))
+ process.exit(1)
+ }
+
+ fs.mkdirSync(destDir, { recursive: true })
+
+ const content = fs.readFileSync(sourcePath, 'utf8')
+ fs.writeFileSync(destPath, content)
+
+ console.log(chalk.green(`\n✓ Skill installed successfully for ${assistantName}!\n`))
+ console.log(chalk.bold('What this does:'))
+ console.log(' When the AI assistant encounters HTTP 402 or calls x402-enabled APIs,')
+ console.log(' it will automatically use paytaca to handle payments.\n')
+ console.log(chalk.dim('Location: ') + destPath)
+ console.log(chalk.dim('Source: ') + sourcePath)
+ console.log()
+ console.log(`Restart ${assistantName} to load the new skill.\n`)
+ } catch (err: any) {
+ console.log(chalk.red(`\nFailed to install skill: ${err.message}\n`))
+ process.exit(1)
+ }
+}
+
+export function uninstallSkill(skillsDir: string, assistantName: string): void {
+ try {
+ const destDir = path.join(skillsDir, 'paytaca')
+ const destPath = getSkillDestPath(skillsDir)
+
+ if (!fs.existsSync(destPath)) {
+ console.log(chalk.yellow('\nSkill is not installed.\n'))
+ process.exit(0)
+ }
+
+ fs.rmSync(destDir, { recursive: true })
+ console.log(chalk.green(`\n✓ Skill uninstalled for ${assistantName}!\n`))
+ } catch (err: any) {
+ console.log(chalk.red(`\nFailed to uninstall skill: ${err.message}\n`))
+ process.exit(1)
+ }
+}
+
+export function checkStatus(skillsDir: string, assistantName: string): void {
+ const destPath = getSkillDestPath(skillsDir)
+
+ if (fs.existsSync(destPath)) {
+ console.log(chalk.green('\n✓ Paytaca skill is installed\n'))
+ console.log(chalk.dim('Location: ') + destPath)
+ } else {
+ console.log(chalk.yellow(`\n○ Paytaca skill is not installed for ${assistantName}\n`))
+ console.log(`Run: paytaca ${assistantName.toLowerCase()} install`)
+ console.log()
+ }
+}
+
+export function handleSkillAction(
+ assistant: AssistantConfig,
+ action: string
+): void {
+ switch (action) {
+ case 'install':
+ installSkill(assistant.skillsDir, assistant.name)
+ break
+ case 'uninstall':
+ uninstallSkill(assistant.skillsDir, assistant.name)
+ break
+ case 'status':
+ checkStatus(assistant.skillsDir, assistant.name)
+ break
+ default:
+ console.log(chalk.yellow(`Unknown action: ${action}`))
+ console.log('Use: install, uninstall, or status')
+ }
+}
diff --git a/src/utils/x402.test.ts b/src/utils/x402.test.ts
new file mode 100644
index 0000000..aa2f050
--- /dev/null
+++ b/src/utils/x402.test.ts
@@ -0,0 +1,275 @@
+import { describe, it, expect } from 'vitest'
+import {
+ parsePaymentRequiredJson,
+ selectBchPaymentRequirements,
+ buildPaymentPayload,
+ buildAuthorization,
+ parsePaymentResponse,
+ isBchNetwork,
+ isChipnetNetwork,
+ BCH_MAINNET_NETWORK,
+ BCH_CHIPNET_NETWORK,
+ BCH_ASSET_ID,
+} from './x402.js'
+
+describe('x402 parsing', () => {
+ describe('parsePaymentRequiredJson', () => {
+ it('should parse valid PaymentRequired JSON', () => {
+ const input = {
+ x402Version: 2,
+ error: 'Payment required',
+ resource: { url: 'https://api.example.com/data' },
+ accepts: [
+ {
+ scheme: 'utxo',
+ network: BCH_MAINNET_NETWORK,
+ amount: '1000',
+ asset: BCH_ASSET_ID,
+ payTo: 'bitcoincash:qp2f5j6q3fj5gjwgk8rkq8xrk8q8q8q8q8q8q8q8q',
+ maxTimeoutSeconds: 300,
+ extra: {},
+ },
+ ],
+ extensions: {},
+ }
+
+ const result = parsePaymentRequiredJson(input)
+
+ expect(result).not.toBeNull()
+ expect(result!.x402Version).toBe(2)
+ expect(result!.error).toBe('Payment required')
+ expect(result!.resource.url).toBe('https://api.example.com/data')
+ expect(result!.accepts).toHaveLength(1)
+ expect(result!.accepts[0].scheme).toBe('utxo')
+ expect(result!.accepts[0].amount).toBe('1000')
+ })
+
+ it('should return null for null input', () => {
+ expect(parsePaymentRequiredJson(null)).toBeNull()
+ })
+
+ it('should return null for non-object input', () => {
+ expect(parsePaymentRequiredJson('string')).toBeNull()
+ expect(parsePaymentRequiredJson(123)).toBeNull()
+ })
+
+ it('should return null for wrong x402Version', () => {
+ const input = { x402Version: 1, accepts: [] }
+ expect(parsePaymentRequiredJson(input)).toBeNull()
+ })
+
+ it('should use default values for missing optional fields', () => {
+ const input = {
+ x402Version: 2,
+ resource: {},
+ accepts: [
+ {
+ scheme: 'utxo',
+ network: BCH_MAINNET_NETWORK,
+ payTo: 'bitcoincash:qp2f5j6q3fj5gjwgk8rkq8xrk8q8q8q8q8q8q8q8',
+ },
+ ],
+ }
+
+ const result = parsePaymentRequiredJson(input)
+
+ expect(result).not.toBeNull()
+ expect(result!.accepts[0].asset).toBe(BCH_ASSET_ID)
+ expect(result!.accepts[0].maxTimeoutSeconds).toBe(60)
+ })
+
+ it('should filter out invalid accepts entries', () => {
+ const input = {
+ x402Version: 2,
+ resource: { url: 'https://api.example.com' },
+ accepts: [
+ { scheme: 'utxo', network: BCH_MAINNET_NETWORK, payTo: 'valid1' },
+ { scheme: 'invalid' },
+ { network: BCH_MAINNET_NETWORK, payTo: 'missing-scheme' },
+ { scheme: 'utxo', payTo: 'missing-network' },
+ { scheme: 'utxo', network: BCH_MAINNET_NETWORK },
+ ],
+ }
+
+ const result = parsePaymentRequiredJson(input)
+
+ expect(result!.accepts).toHaveLength(1)
+ expect(result!.accepts[0].payTo).toBe('valid1')
+ })
+ })
+
+ describe('selectBchPaymentRequirements', () => {
+ const paymentRequired = {
+ x402Version: 2,
+ resource: { url: 'https://api.example.com' },
+ accepts: [
+ {
+ scheme: 'utxo',
+ network: BCH_MAINNET_NETWORK,
+ amount: '1000',
+ asset: BCH_ASSET_ID,
+ payTo: 'bitcoincash:mainnet-address',
+ maxTimeoutSeconds: 300,
+ extra: {},
+ },
+ {
+ scheme: 'utxo',
+ network: BCH_CHIPNET_NETWORK,
+ amount: '1000',
+ asset: BCH_ASSET_ID,
+ payTo: 'bitcoincash:chipnet-address',
+ maxTimeoutSeconds: 300,
+ extra: {},
+ },
+ ],
+ extensions: {},
+ }
+
+ it('should select mainnet requirements for mainnet client', () => {
+ const result = selectBchPaymentRequirements(paymentRequired, 'mainnet')
+ expect(result).not.toBeNull()
+ expect(result!.network).toBe(BCH_MAINNET_NETWORK)
+ expect(result!.payTo).toBe('bitcoincash:mainnet-address')
+ })
+
+ it('should select chipnet requirements for chipnet client', () => {
+ const result = selectBchPaymentRequirements(paymentRequired, 'chipnet')
+ expect(result).not.toBeNull()
+ expect(result!.network).toBe(BCH_CHIPNET_NETWORK)
+ expect(result!.payTo).toBe('bitcoincash:chipnet-address')
+ })
+
+ it('should return null when no matching network', () => {
+ const emptyAccepts = { ...paymentRequired, accepts: [paymentRequired.accepts[0]] }
+ const result = selectBchPaymentRequirements(emptyAccepts, 'chipnet')
+ expect(result).toBeNull()
+ })
+ })
+})
+
+describe('x402 building', () => {
+ describe('buildPaymentPayload', () => {
+ it('should build a valid PaymentPayload', () => {
+ const accepted = {
+ scheme: 'utxo',
+ network: BCH_MAINNET_NETWORK,
+ amount: '1000',
+ asset: BCH_ASSET_ID,
+ payTo: 'bitcoincash:qp2f5j6q3fj5gjwgk8rkq8xrk8q8q8q8q8q8q8q8',
+ maxTimeoutSeconds: 300,
+ extra: {},
+ }
+
+ const result = buildPaymentPayload(
+ accepted,
+ 'https://api.example.com/data',
+ 'bitcoincash:payer-address',
+ 'abc123txid',
+ 0,
+ '1000'
+ )
+
+ expect(result.x402Version).toBe(2)
+ expect(result.resource!.url).toBe('https://api.example.com/data')
+ expect(result.accepted).toBe(accepted)
+ expect(result.payload.authorization.from).toBe('bitcoincash:payer-address')
+ expect(result.payload.authorization.to).toBe(accepted.payTo)
+ expect(result.payload.authorization.txid).toBe('abc123txid')
+ expect(result.payload.signature).toBe('')
+ })
+ })
+
+ describe('buildAuthorization', () => {
+ it('should build a valid Authorization', () => {
+ const accepted = {
+ scheme: 'utxo',
+ network: BCH_MAINNET_NETWORK,
+ amount: '1000',
+ asset: BCH_ASSET_ID,
+ payTo: 'bitcoincash:qp2f5j6q3fj5gjwgk8rkq8xrk8q8q8q8q8q8q8q8',
+ maxTimeoutSeconds: 300,
+ extra: {},
+ }
+
+ const result = buildAuthorization(
+ accepted,
+ 'https://api.example.com/data',
+ 'bitcoincash:payer-address',
+ 'abc123txid',
+ 0,
+ '1000'
+ )
+
+ expect(result.from).toBe('bitcoincash:payer-address')
+ expect(result.to).toBe(accepted.payTo)
+ expect(result.txid).toBe('abc123txid')
+ expect(result.vout).toBe(0)
+ expect(result.amount).toBe('1000')
+ })
+ })
+})
+
+describe('parsePaymentResponse', () => {
+ it('should parse valid isValid response', () => {
+ const data = {
+ isValid: true,
+ payer: 'bitcoincash:abc123',
+ remainingBalanceSat: '1000000',
+ }
+
+ const result = parsePaymentResponse(data)
+
+ expect(result.isValid).toBe(true)
+ expect(result.payer).toBe('bitcoincash:abc123')
+ expect(result.remainingBalanceSat).toBe('1000000')
+ })
+
+ it('should parse error response', () => {
+ const data = { error: 'Invalid signature' }
+
+ const result = parsePaymentResponse(data)
+
+ expect(result.isValid).toBe(false)
+ expect(result.invalidReason).toBe('Invalid signature')
+ })
+
+ it('should return no_response_data for null input', () => {
+ const result = parsePaymentResponse(null)
+ expect(result.isValid).toBe(false)
+ expect(result.invalidReason).toBe('no_response_data')
+ })
+
+ it('should return unknown_response_format for unrecognized data', () => {
+ const data = { some: 'unknown', format: true }
+ const result = parsePaymentResponse(data)
+ expect(result.isValid).toBe(false)
+ expect(result.invalidReason).toBe('unknown_response_format')
+ })
+})
+
+describe('network helpers', () => {
+ describe('isBchNetwork', () => {
+ it('should return true for mainnet', () => {
+ expect(isBchNetwork(BCH_MAINNET_NETWORK)).toBe(true)
+ })
+
+ it('should return true for chipnet', () => {
+ expect(isBchNetwork(BCH_CHIPNET_NETWORK)).toBe(true)
+ })
+
+ it('should return false for other networks', () => {
+ expect(isBchNetwork('bitcoin')).toBe(false)
+ expect(isBchNetwork('litecoin')).toBe(false)
+ })
+ })
+
+ describe('isChipnetNetwork', () => {
+ it('should return true for chipnet', () => {
+ expect(isChipnetNetwork(BCH_CHIPNET_NETWORK)).toBe(true)
+ })
+
+ it('should return false for mainnet', () => {
+ expect(isChipnetNetwork(BCH_MAINNET_NETWORK)).toBe(false)
+ })
+ })
+})
diff --git a/src/utils/x402.ts b/src/utils/x402.ts
new file mode 100644
index 0000000..68b1267
--- /dev/null
+++ b/src/utils/x402.ts
@@ -0,0 +1,167 @@
+/**
+ * x402 utility functions for BCH payments
+ * Implements x402-bch v2.2 specification
+ * https://github.com/x402-bch/x402-bch/blob/master/specs/x402-bch-specification-v2.2.md
+ */
+
+import crypto from 'crypto'
+import {
+ PaymentRequired,
+ PaymentRequirements,
+ PaymentPayload,
+ Authorization,
+ ResourceInfo,
+ VerifyResponse,
+ BCH_ASSET_ID,
+ BCH_MAINNET_NETWORK,
+ BCH_CHIPNET_NETWORK,
+} from '../types/x402.js'
+import { secp256k1 } from '@bitauth/libauth'
+
+export { BCH_MAINNET_NETWORK, BCH_CHIPNET_NETWORK, BCH_ASSET_ID }
+
+export function isBchNetwork(network: string): boolean {
+ return network === BCH_MAINNET_NETWORK || network === BCH_CHIPNET_NETWORK
+}
+
+export function isChipnetNetwork(network: string): boolean {
+ return network === BCH_CHIPNET_NETWORK
+}
+
+export function parsePaymentRequiredJson(body: any): PaymentRequired | null {
+ if (!body || typeof body !== 'object') return null
+ if (body.x402Version !== 2) return null
+
+ const pr: PaymentRequired = {
+ x402Version: body.x402Version,
+ error: body.error,
+ resource: body.resource || { url: '' },
+ accepts: [],
+ extensions: body.extensions || {},
+ }
+
+ if (Array.isArray(body.accepts)) {
+ for (const accept of body.accepts) {
+ if (accept.scheme && accept.network && accept.payTo) {
+ pr.accepts.push({
+ scheme: accept.scheme,
+ network: accept.network,
+ amount: accept.amount,
+ asset: accept.asset || BCH_ASSET_ID,
+ payTo: accept.payTo,
+ maxTimeoutSeconds: accept.maxTimeoutSeconds || 60,
+ extra: accept.extra || {},
+ })
+ }
+ }
+ }
+
+ return pr
+}
+
+export function selectBchPaymentRequirements(
+ requirements: PaymentRequired,
+ clientNetwork: 'mainnet' | 'chipnet'
+): PaymentRequirements | null {
+ const clientNetworkId = clientNetwork === 'chipnet' ? BCH_CHIPNET_NETWORK : BCH_MAINNET_NETWORK
+ for (const accept of requirements.accepts) {
+ if (accept.scheme === 'utxo' && accept.network === clientNetworkId) {
+ return accept
+ }
+ }
+ return null
+}
+
+export function buildPaymentPayload(
+ accepted: PaymentRequirements,
+ resourceUrl: string,
+ payer: string,
+ txid: string,
+ vout: number | null,
+ amount: string | null
+): PaymentPayload {
+ const resource: ResourceInfo = {
+ url: resourceUrl,
+ description: '',
+ mimeType: 'application/json',
+ }
+
+ return {
+ x402Version: 2,
+ resource,
+ accepted,
+ payload: {
+ signature: '',
+ authorization: {
+ from: payer,
+ to: accepted.payTo,
+ value: accepted.amount,
+ txid,
+ vout,
+ amount,
+ },
+ },
+ extensions: {},
+ }
+}
+
+export function buildAuthorization(
+ accepted: PaymentRequirements,
+ resourceUrl: string,
+ payer: string,
+ txid: string,
+ vout: number | null,
+ amount: string | null
+): Authorization {
+ return {
+ from: payer,
+ to: accepted.payTo,
+ value: accepted.amount,
+ txid,
+ vout,
+ amount,
+ }
+}
+
+export function signMessageBCH(
+ message: string,
+ privateKeyHex: string,
+ compressed: boolean = true
+): string {
+ const prefix = '\x18Bitcoin Signed Message:\n'
+ const messageBytes = Buffer.from(message, 'utf8')
+ const prefixBytes = Buffer.from(prefix, 'utf8')
+ const lengthByte = Buffer.from([messageBytes.length])
+ const prefixedMessage = Buffer.concat([prefixBytes, lengthByte, messageBytes])
+ const hash = crypto.createHash('sha256').update(crypto.createHash('sha256').update(prefixedMessage).digest()).digest()
+ const privateKey = Buffer.from(privateKeyHex, 'hex')
+ const signature = secp256k1.signMessageHashDER(hash, privateKey)
+ return Buffer.from(signature).toString('base64')
+}
+
+export async function signAuthorization(
+ authorization: Authorization,
+ signMessage: (message: string) => Promise
+): Promise {
+ const message = JSON.stringify(authorization)
+ return signMessage(message)
+}
+
+export function parsePaymentResponse(data: any): VerifyResponse {
+ if (!data) return { isValid: false, invalidReason: 'no_response_data' }
+
+ if (typeof data.isValid === 'boolean') {
+ return {
+ isValid: data.isValid,
+ payer: data.payer,
+ invalidReason: data.invalidReason,
+ remainingBalanceSat: data.remainingBalanceSat,
+ }
+ }
+
+ if (data.error) {
+ return { isValid: false, invalidReason: data.error }
+ }
+
+ return { isValid: false, invalidReason: 'unknown_response_format' }
+}
diff --git a/src/wallet/x402.ts b/src/wallet/x402.ts
new file mode 100644
index 0000000..4ca93b2
--- /dev/null
+++ b/src/wallet/x402.ts
@@ -0,0 +1,99 @@
+/**
+ * x402 payment handler for BCH
+ * Implements x402-bch v2.2 specification
+ * https://github.com/x402-bch/x402-bch/blob/master/specs/x402-bch-specification-v2.2.md
+ */
+
+import { LibauthHDWallet } from './keys.js'
+import {
+ parsePaymentRequiredJson,
+ selectBchPaymentRequirements,
+ buildPaymentPayload,
+ buildAuthorization,
+ signAuthorization,
+ signMessageBCH,
+} from '../utils/x402.js'
+import {
+ PaymentRequired,
+ PaymentRequirements,
+ PaymentPayload,
+ Authorization,
+ X402PaymentResult,
+} from '../types/x402.js'
+
+export interface X402Signer {
+ address: string
+ signMessage: (message: string) => Promise
+}
+
+export interface X402PayerConfig {
+ hdWallet: LibauthHDWallet
+ addressIndex?: number
+}
+
+export class X402Payer {
+ private signer: X402Signer
+ private isChipnet: boolean
+
+ constructor(config: X402PayerConfig) {
+ this.isChipnet = config.hdWallet.isChipnet
+ this.signer = this.createSigner(config.hdWallet, config.addressIndex || 0)
+ }
+
+ private createSigner(hdWallet: LibauthHDWallet, index: number): X402Signer {
+ const addressSet = hdWallet.getAddressSetAt(index)
+ return {
+ address: addressSet.receiving,
+ signMessage: async (message: string) => {
+ const node = hdWallet.getNodeAt(`0/${index}`)
+ const privKeyHex = Buffer.from(node.privateKey).toString('hex')
+ return signMessageBCH(message, privKeyHex, true)
+ },
+ }
+ }
+
+ getPayerAddress(): string {
+ return this.signer.address
+ }
+
+ async createPaymentPayload(
+ requirements: PaymentRequirements,
+ resourceUrl: string,
+ txid: string,
+ vout: number | null,
+ amount: string | null
+ ): Promise {
+ const payload = buildPaymentPayload(
+ requirements,
+ resourceUrl,
+ this.signer.address,
+ txid,
+ vout,
+ amount
+ )
+
+ const signature = await signAuthorization(payload.payload.authorization, this.signer.signMessage.bind(this.signer))
+ payload.payload.signature = signature
+
+ return payload
+ }
+
+ async makePaymentRequest(
+ requirements: PaymentRequirements,
+ resourceUrl: string,
+ txid: string,
+ vout: number | null,
+ amount: string | null
+ ): Promise<{ paymentPayload: PaymentPayload; paymentUrl: string }> {
+ const paymentPayload = await this.createPaymentPayload(requirements, resourceUrl, txid, vout, amount)
+
+ return {
+ paymentPayload,
+ paymentUrl: requirements.payTo,
+ }
+ }
+}
+
+export function createX402Payer(hdWallet: LibauthHDWallet, addressIndex?: number): X402Payer {
+ return new X402Payer({ hdWallet, addressIndex })
+}
diff --git a/vitest.config.ts b/vitest.config.ts
new file mode 100644
index 0000000..d2d9690
--- /dev/null
+++ b/vitest.config.ts
@@ -0,0 +1,8 @@
+import { defineConfig } from 'vitest/config'
+
+export default defineConfig({
+ test: {
+ include: ['src/**/*.test.ts'],
+ environment: 'node',
+ },
+})
diff --git a/x402-server/README.md b/x402-server/README.md
new file mode 100644
index 0000000..bb1f02d
--- /dev/null
+++ b/x402-server/README.md
@@ -0,0 +1,128 @@
+# x402 BCH Reference Server
+
+A minimal reference implementation of an x402 server that accepts BCH payments.
+
+## Overview
+
+This server demonstrates how to build an x402-compatible API that accepts Bitcoin Cash (BCH) payments. It implements the `utxo` scheme for UTXO-based cryptocurrencies.
+
+## Quick Start
+
+```bash
+cd x402-server
+npm install
+npm start
+```
+
+Server runs at `http://localhost:3000`
+
+## Environment Variables
+
+| Variable | Description | Default |
+|----------|-------------|---------|
+| `PORT` | Server port | `3000` |
+| `BCH_NETWORK` | `mainnet` or `chipnet` | `mainnet` |
+| `RECEIVE_ADDRESS` | BCH address to receive payments | Required for real payments |
+
+## Endpoints
+
+| Endpoint | Cost | Description |
+|----------|------|-------------|
+| `GET /api/quote` | 100 sats | Returns a random inspirational quote |
+| `GET /api/weather` | 50 sats | Returns fake weather data |
+| `GET /api/status` | 1 sat | Returns server status |
+
+## Testing with paytaca-cli
+
+```bash
+# Check if endpoint requires payment
+paytaca check http://localhost:3000/api/quote
+
+# Make a paid request (will get 402 without wallet)
+paytaca pay http://localhost:3000/api/quote
+
+# Dry run to see payment details
+paytaca pay http://localhost:3000/api/quote --dry-run
+
+# With JSON output
+paytaca pay http://localhost:3000/api/quote --json
+```
+
+## How It Works
+
+### 1. Initial Request (No Payment)
+
+```
+GET /api/quote
+```
+
+Returns `402 Payment Required` with headers:
+
+```
+PAYMENT-REQUIRED:
+X-Scheme: utxo
+Max-Timeout-Ms: 60000
+Max-Amount: 100
+Resource-Id: /api/quote
+Accept-Currencies: BCH,bch,BCHn,bitcoincash
+```
+
+### 2. Payment Flow
+
+The client:
+1. Parses the 402 response headers
+2. Creates a BCH transaction paying the required amount
+3. Signs the payment payload
+4. Retries the request with `Authorization: x402 `
+
+### 3. Verification
+
+The server verifies:
+- Signature validity
+- Network matches (mainnet/chipnet)
+- Resource ID matches
+- Amount doesn't exceed maximum
+- Currency is accepted (BCH)
+
+## x402 Headers
+
+### Server → Client (402 Response)
+
+| Header | Description |
+|--------|-------------|
+| `PAYMENT-REQUIRED` | Base64-encoded PaymentRequired object |
+| `X-Scheme` | Payment scheme (`utxo`) |
+| `Max-Timeout-Ms` | Maximum time to complete payment |
+| `Max-Amount` | Maximum payment amount in satoshis |
+| `Resource-Id` | Unique identifier for the resource |
+| `Accept-Currencies` | Comma-separated list of accepted currencies |
+
+### Client → Server (Retry with Payment)
+
+| Header | Description |
+|--------|-------------|
+| `Authorization` | `x402 ` |
+
+## Network Identifiers
+
+| Network | CAIP-2 ID |
+|---------|-----------|
+| BCH Mainnet | `bip122:000000000000000000651ef99cb9fcbe` |
+| BCH Chipnet | `bip122:000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f` |
+
+## Production Considerations
+
+This is a **reference implementation** for testing. For production:
+
+1. **Use a real facilitator** - The official x402 facilitator handles payment verification
+2. **Set RECEIVE_ADDRESS** - Your BCH address for receiving payments
+3. **Verify on-chain** - In production, verify the actual transaction on-chain
+4. **Handle idempotency** - Prevent double-spending and replay attacks
+5. **Add rate limiting** - Prevent abuse
+6. **Use HTTPS** - In production, always use TLS
+
+## See Also
+
+- [x402 Protocol](https://x402.org)
+- [x402 BCH Specification](https://github.com/x402-bch/x402-bch)
+- [paytaca-cli](https://github.com/PayAINetwork/paytaca-cli)
diff --git a/x402-server/package-lock.json b/x402-server/package-lock.json
new file mode 100644
index 0000000..06434e7
--- /dev/null
+++ b/x402-server/package-lock.json
@@ -0,0 +1,682 @@
+{
+ "name": "x402-bch-server",
+ "version": "1.0.0",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "x402-bch-server",
+ "version": "1.0.0",
+ "dependencies": {
+ "bitcoinjs-lib": "^6.1.5"
+ },
+ "devDependencies": {
+ "@types/node": "^20.11.0",
+ "tsx": "^4.7.0"
+ }
+ },
+ "node_modules/@esbuild/aix-ppc64": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.27.4.tgz",
+ "integrity": "sha512-cQPwL2mp2nSmHHJlCyoXgHGhbEPMrEEU5xhkcy3Hs/O7nGZqEpZ2sUtLaL9MORLtDfRvVl2/3PAuEkYZH0Ty8Q==",
+ "cpu": [
+ "ppc64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "aix"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/android-arm": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.27.4.tgz",
+ "integrity": "sha512-X9bUgvxiC8CHAGKYufLIHGXPJWnr0OCdR0anD2e21vdvgCI8lIfqFbnoeOz7lBjdrAGUhqLZLcQo6MLhTO2DKQ==",
+ "cpu": [
+ "arm"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/android-arm64": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.27.4.tgz",
+ "integrity": "sha512-gdLscB7v75wRfu7QSm/zg6Rx29VLdy9eTr2t44sfTW7CxwAtQghZ4ZnqHk3/ogz7xao0QAgrkradbBzcqFPasw==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/android-x64": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.27.4.tgz",
+ "integrity": "sha512-PzPFnBNVF292sfpfhiyiXCGSn9HZg5BcAz+ivBuSsl6Rk4ga1oEXAamhOXRFyMcjwr2DVtm40G65N3GLeH1Lvw==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/darwin-arm64": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.27.4.tgz",
+ "integrity": "sha512-b7xaGIwdJlht8ZFCvMkpDN6uiSmnxxK56N2GDTMYPr2/gzvfdQN8rTfBsvVKmIVY/X7EM+/hJKEIbbHs9oA4tQ==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/darwin-x64": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.27.4.tgz",
+ "integrity": "sha512-sR+OiKLwd15nmCdqpXMnuJ9W2kpy0KigzqScqHI3Hqwr7IXxBp3Yva+yJwoqh7rE8V77tdoheRYataNKL4QrPw==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/freebsd-arm64": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.27.4.tgz",
+ "integrity": "sha512-jnfpKe+p79tCnm4GVav68A7tUFeKQwQyLgESwEAUzyxk/TJr4QdGog9sqWNcUbr/bZt/O/HXouspuQDd9JxFSw==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "freebsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/freebsd-x64": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.27.4.tgz",
+ "integrity": "sha512-2kb4ceA/CpfUrIcTUl1wrP/9ad9Atrp5J94Lq69w7UwOMolPIGrfLSvAKJp0RTvkPPyn6CIWrNy13kyLikZRZQ==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "freebsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-arm": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.27.4.tgz",
+ "integrity": "sha512-aBYgcIxX/wd5n2ys0yESGeYMGF+pv6g0DhZr3G1ZG4jMfruU9Tl1i2Z+Wnj9/KjGz1lTLCcorqE2viePZqj4Eg==",
+ "cpu": [
+ "arm"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-arm64": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.27.4.tgz",
+ "integrity": "sha512-7nQOttdzVGth1iz57kxg9uCz57dxQLHWxopL6mYuYthohPKEK0vU0C3O21CcBK6KDlkYVcnDXY099HcCDXd9dA==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-ia32": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.27.4.tgz",
+ "integrity": "sha512-oPtixtAIzgvzYcKBQM/qZ3R+9TEUd1aNJQu0HhGyqtx6oS7qTpvjheIWBbes4+qu1bNlo2V4cbkISr8q6gRBFA==",
+ "cpu": [
+ "ia32"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-loong64": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.27.4.tgz",
+ "integrity": "sha512-8mL/vh8qeCoRcFH2nM8wm5uJP+ZcVYGGayMavi8GmRJjuI3g1v6Z7Ni0JJKAJW+m0EtUuARb6Lmp4hMjzCBWzA==",
+ "cpu": [
+ "loong64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-mips64el": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.27.4.tgz",
+ "integrity": "sha512-1RdrWFFiiLIW7LQq9Q2NES+HiD4NyT8Itj9AUeCl0IVCA459WnPhREKgwrpaIfTOe+/2rdntisegiPWn/r/aAw==",
+ "cpu": [
+ "mips64el"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-ppc64": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.27.4.tgz",
+ "integrity": "sha512-tLCwNG47l3sd9lpfyx9LAGEGItCUeRCWeAx6x2Jmbav65nAwoPXfewtAdtbtit/pJFLUWOhpv0FpS6GQAmPrHA==",
+ "cpu": [
+ "ppc64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-riscv64": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.27.4.tgz",
+ "integrity": "sha512-BnASypppbUWyqjd1KIpU4AUBiIhVr6YlHx/cnPgqEkNoVOhHg+YiSVxM1RLfiy4t9cAulbRGTNCKOcqHrEQLIw==",
+ "cpu": [
+ "riscv64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-s390x": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.27.4.tgz",
+ "integrity": "sha512-+eUqgb/Z7vxVLezG8bVB9SfBie89gMueS+I0xYh2tJdw3vqA/0ImZJ2ROeWwVJN59ihBeZ7Tu92dF/5dy5FttA==",
+ "cpu": [
+ "s390x"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-x64": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.27.4.tgz",
+ "integrity": "sha512-S5qOXrKV8BQEzJPVxAwnryi2+Iq5pB40gTEIT69BQONqR7JH1EPIcQ/Uiv9mCnn05jff9umq/5nqzxlqTOg9NA==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/netbsd-arm64": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.27.4.tgz",
+ "integrity": "sha512-xHT8X4sb0GS8qTqiwzHqpY00C95DPAq7nAwX35Ie/s+LO9830hrMd3oX0ZMKLvy7vsonee73x0lmcdOVXFzd6Q==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "netbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/netbsd-x64": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.27.4.tgz",
+ "integrity": "sha512-RugOvOdXfdyi5Tyv40kgQnI0byv66BFgAqjdgtAKqHoZTbTF2QqfQrFwa7cHEORJf6X2ht+l9ABLMP0dnKYsgg==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "netbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/openbsd-arm64": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.27.4.tgz",
+ "integrity": "sha512-2MyL3IAaTX+1/qP0O1SwskwcwCoOI4kV2IBX1xYnDDqthmq5ArrW94qSIKCAuRraMgPOmG0RDTA74mzYNQA9ow==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "openbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/openbsd-x64": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.27.4.tgz",
+ "integrity": "sha512-u8fg/jQ5aQDfsnIV6+KwLOf1CmJnfu1ShpwqdwC0uA7ZPwFws55Ngc12vBdeUdnuWoQYx/SOQLGDcdlfXhYmXQ==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "openbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/openharmony-arm64": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.27.4.tgz",
+ "integrity": "sha512-JkTZrl6VbyO8lDQO3yv26nNr2RM2yZzNrNHEsj9bm6dOwwu9OYN28CjzZkH57bh4w0I2F7IodpQvUAEd1mbWXg==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "openharmony"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/sunos-x64": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.27.4.tgz",
+ "integrity": "sha512-/gOzgaewZJfeJTlsWhvUEmUG4tWEY2Spp5M20INYRg2ZKl9QPO3QEEgPeRtLjEWSW8FilRNacPOg8R1uaYkA6g==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "sunos"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/win32-arm64": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.27.4.tgz",
+ "integrity": "sha512-Z9SExBg2y32smoDQdf1HRwHRt6vAHLXcxD2uGgO/v2jK7Y718Ix4ndsbNMU/+1Qiem9OiOdaqitioZwxivhXYg==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/win32-ia32": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.27.4.tgz",
+ "integrity": "sha512-DAyGLS0Jz5G5iixEbMHi5KdiApqHBWMGzTtMiJ72ZOLhbu/bzxgAe8Ue8CTS3n3HbIUHQz/L51yMdGMeoxXNJw==",
+ "cpu": [
+ "ia32"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/win32-x64": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.27.4.tgz",
+ "integrity": "sha512-+knoa0BDoeXgkNvvV1vvbZX4+hizelrkwmGJBdT17t8FNPwG2lKemmuMZlmaNQ3ws3DKKCxpb4zRZEIp3UxFCg==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@noble/hashes": {
+ "version": "1.8.0",
+ "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.8.0.tgz",
+ "integrity": "sha512-jCs9ldd7NwzpgXDIf6P3+NrHh9/sD6CQdxHyjQI+h/6rDNo88ypBxxz45UDuZHz9r3tNz7N/VInSVoVdtXEI4A==",
+ "license": "MIT",
+ "engines": {
+ "node": "^14.21.3 || >=16"
+ },
+ "funding": {
+ "url": "https://paulmillr.com/funding/"
+ }
+ },
+ "node_modules/@types/node": {
+ "version": "20.19.37",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.37.tgz",
+ "integrity": "sha512-8kzdPJ3FsNsVIurqBs7oodNnCEVbni9yUEkaHbgptDACOPW04jimGagZ51E6+lXUwJjgnBw+hyko/lkFWCldqw==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "undici-types": "~6.21.0"
+ }
+ },
+ "node_modules/base-x": {
+ "version": "4.0.1",
+ "resolved": "https://registry.npmjs.org/base-x/-/base-x-4.0.1.tgz",
+ "integrity": "sha512-uAZ8x6r6S3aUM9rbHGVOIsR15U/ZSc82b3ymnCPsT45Gk1DDvhDPdIgB5MrhirZWt+5K0EEPQH985kNqZgNPFw==",
+ "license": "MIT"
+ },
+ "node_modules/bech32": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/bech32/-/bech32-2.0.0.tgz",
+ "integrity": "sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg==",
+ "license": "MIT"
+ },
+ "node_modules/bip174": {
+ "version": "2.1.1",
+ "resolved": "https://registry.npmjs.org/bip174/-/bip174-2.1.1.tgz",
+ "integrity": "sha512-mdFV5+/v0XyNYXjBS6CQPLo9ekCx4gtKZFnJm5PMto7Fs9hTTDpkkzOB7/FtluRI6JbUUAu+snTYfJRgHLZbZQ==",
+ "license": "MIT",
+ "engines": {
+ "node": ">=8.0.0"
+ }
+ },
+ "node_modules/bitcoinjs-lib": {
+ "version": "6.1.7",
+ "resolved": "https://registry.npmjs.org/bitcoinjs-lib/-/bitcoinjs-lib-6.1.7.tgz",
+ "integrity": "sha512-tlf/r2DGMbF7ky1MgUqXHzypYHakkEnm0SZP23CJKIqNY/5uNAnMbFhMJdhjrL/7anfb/U8+AlpdjPWjPnAalg==",
+ "license": "MIT",
+ "dependencies": {
+ "@noble/hashes": "^1.2.0",
+ "bech32": "^2.0.0",
+ "bip174": "^2.1.1",
+ "bs58check": "^3.0.1",
+ "typeforce": "^1.11.3",
+ "varuint-bitcoin": "^1.1.2"
+ },
+ "engines": {
+ "node": ">=8.0.0"
+ }
+ },
+ "node_modules/bs58": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/bs58/-/bs58-5.0.0.tgz",
+ "integrity": "sha512-r+ihvQJvahgYT50JD05dyJNKlmmSlMoOGwn1lCcEzanPglg7TxYjioQUYehQ9mAR/+hOSd2jRc/Z2y5UxBymvQ==",
+ "license": "MIT",
+ "dependencies": {
+ "base-x": "^4.0.0"
+ }
+ },
+ "node_modules/bs58check": {
+ "version": "3.0.1",
+ "resolved": "https://registry.npmjs.org/bs58check/-/bs58check-3.0.1.tgz",
+ "integrity": "sha512-hjuuJvoWEybo7Hn/0xOrczQKKEKD63WguEjlhLExYs2wUBcebDC1jDNK17eEAD2lYfw82d5ASC1d7K3SWszjaQ==",
+ "license": "MIT",
+ "dependencies": {
+ "@noble/hashes": "^1.2.0",
+ "bs58": "^5.0.0"
+ }
+ },
+ "node_modules/esbuild": {
+ "version": "0.27.4",
+ "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.27.4.tgz",
+ "integrity": "sha512-Rq4vbHnYkK5fws5NF7MYTU68FPRE1ajX7heQ/8QXXWqNgqqJ/GkmmyxIzUnf2Sr/bakf8l54716CcMGHYhMrrQ==",
+ "dev": true,
+ "hasInstallScript": true,
+ "license": "MIT",
+ "bin": {
+ "esbuild": "bin/esbuild"
+ },
+ "engines": {
+ "node": ">=18"
+ },
+ "optionalDependencies": {
+ "@esbuild/aix-ppc64": "0.27.4",
+ "@esbuild/android-arm": "0.27.4",
+ "@esbuild/android-arm64": "0.27.4",
+ "@esbuild/android-x64": "0.27.4",
+ "@esbuild/darwin-arm64": "0.27.4",
+ "@esbuild/darwin-x64": "0.27.4",
+ "@esbuild/freebsd-arm64": "0.27.4",
+ "@esbuild/freebsd-x64": "0.27.4",
+ "@esbuild/linux-arm": "0.27.4",
+ "@esbuild/linux-arm64": "0.27.4",
+ "@esbuild/linux-ia32": "0.27.4",
+ "@esbuild/linux-loong64": "0.27.4",
+ "@esbuild/linux-mips64el": "0.27.4",
+ "@esbuild/linux-ppc64": "0.27.4",
+ "@esbuild/linux-riscv64": "0.27.4",
+ "@esbuild/linux-s390x": "0.27.4",
+ "@esbuild/linux-x64": "0.27.4",
+ "@esbuild/netbsd-arm64": "0.27.4",
+ "@esbuild/netbsd-x64": "0.27.4",
+ "@esbuild/openbsd-arm64": "0.27.4",
+ "@esbuild/openbsd-x64": "0.27.4",
+ "@esbuild/openharmony-arm64": "0.27.4",
+ "@esbuild/sunos-x64": "0.27.4",
+ "@esbuild/win32-arm64": "0.27.4",
+ "@esbuild/win32-ia32": "0.27.4",
+ "@esbuild/win32-x64": "0.27.4"
+ }
+ },
+ "node_modules/fsevents": {
+ "version": "2.3.3",
+ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
+ "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
+ "dev": true,
+ "hasInstallScript": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
+ }
+ },
+ "node_modules/get-tsconfig": {
+ "version": "4.13.7",
+ "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.13.7.tgz",
+ "integrity": "sha512-7tN6rFgBlMgpBML5j8typ92BKFi2sFQvIdpAqLA2beia5avZDrMs0FLZiM5etShWq5irVyGcGMEA1jcDaK7A/Q==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "resolve-pkg-maps": "^1.0.0"
+ },
+ "funding": {
+ "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1"
+ }
+ },
+ "node_modules/resolve-pkg-maps": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz",
+ "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==",
+ "dev": true,
+ "license": "MIT",
+ "funding": {
+ "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1"
+ }
+ },
+ "node_modules/safe-buffer": {
+ "version": "5.2.1",
+ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
+ "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/feross"
+ },
+ {
+ "type": "patreon",
+ "url": "https://www.patreon.com/feross"
+ },
+ {
+ "type": "consulting",
+ "url": "https://feross.org/support"
+ }
+ ],
+ "license": "MIT"
+ },
+ "node_modules/tsx": {
+ "version": "4.21.0",
+ "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.21.0.tgz",
+ "integrity": "sha512-5C1sg4USs1lfG0GFb2RLXsdpXqBSEhAaA/0kPL01wxzpMqLILNxIxIOKiILz+cdg/pLnOUxFYOR5yhHU666wbw==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "esbuild": "~0.27.0",
+ "get-tsconfig": "^4.7.5"
+ },
+ "bin": {
+ "tsx": "dist/cli.mjs"
+ },
+ "engines": {
+ "node": ">=18.0.0"
+ },
+ "optionalDependencies": {
+ "fsevents": "~2.3.3"
+ }
+ },
+ "node_modules/typeforce": {
+ "version": "1.18.0",
+ "resolved": "https://registry.npmjs.org/typeforce/-/typeforce-1.18.0.tgz",
+ "integrity": "sha512-7uc1O8h1M1g0rArakJdf0uLRSSgFcYexrVoKo+bzJd32gd4gDy2L/Z+8/FjPnU9ydY3pEnVPtr9FyscYY60K1g==",
+ "license": "MIT"
+ },
+ "node_modules/undici-types": {
+ "version": "6.21.0",
+ "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
+ "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/varuint-bitcoin": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/varuint-bitcoin/-/varuint-bitcoin-1.1.2.tgz",
+ "integrity": "sha512-4EVb+w4rx+YfVM32HQX42AbbT7/1f5zwAYhIujKXKk8NQK+JfRVl3pqT3hjNn/L+RstigmGGKVwHA/P0wgITZw==",
+ "license": "MIT",
+ "dependencies": {
+ "safe-buffer": "^5.1.1"
+ }
+ }
+ }
+}
diff --git a/x402-server/package.json b/x402-server/package.json
new file mode 100644
index 0000000..a39c18d
--- /dev/null
+++ b/x402-server/package.json
@@ -0,0 +1,18 @@
+{
+ "name": "x402-bch-server",
+ "version": "1.0.0",
+ "description": "Reference x402 server implementation accepting BCH payments",
+ "type": "module",
+ "main": "src/server.ts",
+ "scripts": {
+ "start": "tsx src/server.ts",
+ "dev": "tsx watch src/server.ts"
+ },
+ "dependencies": {
+ "bitcoinjs-lib": "^6.1.5"
+ },
+ "devDependencies": {
+ "tsx": "^4.7.0",
+ "@types/node": "^20.11.0"
+ }
+}
diff --git a/x402-server/src/server.ts b/x402-server/src/server.ts
new file mode 100644
index 0000000..382c322
--- /dev/null
+++ b/x402-server/src/server.ts
@@ -0,0 +1,381 @@
+/**
+ * Reference x402-bch Server Implementation
+ *
+ * Conforms to x402-bch specification v2.2
+ * https://github.com/x402-bch/x402-bch/blob/master/specs/x402-bch-specification-v2.2.md
+ *
+ * Run with: npm start
+ *
+ * Endpoints:
+ * GET /api/quote - Returns a random quote (costs 1000 sats)
+ * GET /api/weather - Returns fake weather data (costs 50 sats)
+ * GET /api/status - Returns server status (costs 1 sat)
+ */
+
+import http from 'http'
+import crypto from 'crypto'
+
+const PORT = process.env.PORT || 3000
+const BCH_NETWORK = process.env.BCH_NETWORK || 'mainnet'
+
+const BCH_MAINNET = {
+ bip122: '000000000000000000651ef99cb9fcbe',
+ name: 'mainnet'
+}
+
+const BCH_CHIPNET = {
+ bip122: '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f',
+ name: 'chipnet'
+}
+
+const bchNetwork = BCH_NETWORK === 'chipnet' ? BCH_CHIPNET : BCH_MAINNET
+const NETWORK_ID = `bip122:${bchNetwork.bip122}`
+const ASSET_ID = '0x0000000000000000000000000000000000000001'
+const MAX_TIMEOUT_SECONDS = 60
+
+const RECEIVE_ADDRESS = process.env.RECEIVE_ADDRESS || null
+
+interface PaymentRequirements {
+ scheme: string
+ network: string
+ amount: string
+ asset: string
+ payTo: string
+ maxTimeoutSeconds: number
+ extra: object
+}
+
+interface ResourceInfo {
+ url: string
+ description?: string
+ mimeType?: string
+}
+
+interface PaymentRequired {
+ x402Version: number
+ error?: string
+ resource: ResourceInfo
+ accepts: PaymentRequirements[]
+ extensions: object
+}
+
+interface Authorization {
+ from: string
+ to: string
+ value: string
+ txid: string
+ vout: number | null
+ amount: string | null
+}
+
+interface Payload {
+ signature: string
+ authorization: Authorization
+}
+
+interface PaymentPayload {
+ x402Version: number
+ resource?: ResourceInfo
+ accepted: PaymentRequirements
+ payload: Payload
+ extensions: object
+}
+
+interface VerifyResponse {
+ isValid: boolean
+ payer?: string
+ invalidReason?: string
+ remainingBalanceSat?: string
+}
+
+interface RouteConfig {
+ price: number
+ description: string
+ mimeType: string
+ handler: (query: URLSearchParams) => Promise
+}
+
+const routes: Record = {
+ '/api/quote': {
+ price: 1000,
+ description: 'Get a random inspirational quote',
+ mimeType: 'application/json',
+ handler: async () => {
+ const quotes = [
+ { text: 'The best time to plant a tree was 20 years ago. The second best time is now.', author: 'Chinese Proverb' },
+ { text: 'In the middle of difficulty lies opportunity.', author: 'Albert Einstein' },
+ { text: 'Code is like humor. When you have to explain it, it\'s bad.', author: 'Cory House' },
+ { text: 'First, solve the problem. Then, write the code.', author: 'John Johnson' },
+ { text: 'Experience is the name everyone gives to their mistakes.', author: 'Oscar Wilde' },
+ ]
+ return quotes[Math.floor(Math.random() * quotes.length)]
+ }
+ },
+ '/api/weather': {
+ price: 50,
+ description: 'Get current weather information',
+ mimeType: 'application/json',
+ handler: async () => {
+ const conditions = ['sunny', 'cloudy', 'rainy', 'snowy', 'windy']
+ const condition = conditions[Math.floor(Math.random() * conditions.length)]
+ return {
+ temperature: Math.floor(Math.random() * 35) + 5,
+ condition,
+ humidity: Math.floor(Math.random() * 60) + 20,
+ windSpeed: Math.floor(Math.random() * 30),
+ }
+ }
+ },
+ '/api/status': {
+ price: 1,
+ description: 'Server status check',
+ mimeType: 'application/json',
+ handler: async () => ({
+ status: 'ok',
+ uptime: process.uptime(),
+ timestamp: new Date().toISOString(),
+ network: BCH_NETWORK,
+ memory: process.memoryUsage(),
+ })
+ },
+}
+
+function getPayToAddress(): string {
+ if (!RECEIVE_ADDRESS) {
+ return bchNetwork.name === 'mainnet'
+ ? 'bitcoincash:placeholder'
+ : 'bchtest:placeholder'
+ }
+ const addr = RECEIVE_ADDRESS.toLowerCase()
+ if (addr.startsWith('bitcoincash:') || addr.startsWith('bchtest:') || addr.startsWith('bch:')) {
+ return RECEIVE_ADDRESS
+ }
+ const prefix = bchNetwork.name === 'mainnet' ? 'bitcoincash' : 'bchtest'
+ return `bch:${prefix}:${RECEIVE_ADDRESS}`
+}
+
+function buildPaymentRequired(resourceUrl: string, priceSats: number): PaymentRequired {
+ return {
+ x402Version: 2,
+ error: 'PAYMENT-SIGNATURE header is required',
+ resource: {
+ url: resourceUrl,
+ description: routes[resourceUrl]?.description || '',
+ mimeType: 'application/json',
+ },
+ accepts: [{
+ scheme: 'utxo',
+ network: NETWORK_ID,
+ amount: priceSats.toString(),
+ asset: ASSET_ID,
+ payTo: getPayToAddress(),
+ maxTimeoutSeconds: MAX_TIMEOUT_SECONDS,
+ extra: {},
+ }],
+ extensions: {},
+ }
+}
+
+function send402Response(res: http.ServerResponse, paymentRequired: PaymentRequired): void {
+ res.writeHead(402, 'Payment Required', {
+ 'Content-Type': 'application/json',
+ })
+ res.end(JSON.stringify(paymentRequired, null, 2))
+}
+
+function sendErrorResponse(res: http.ServerResponse, statusCode: number, invalidReason: string, paymentRequired?: PaymentRequired): void {
+ res.writeHead(statusCode, 'Payment Failed', {
+ 'Content-Type': 'application/json',
+ })
+ const body: any = {
+ isValid: false,
+ invalidReason,
+ }
+ if (paymentRequired) {
+ body.paymentRequired = paymentRequired
+ }
+ res.end(JSON.stringify(body, null, 2))
+}
+
+function parsePaymentPayload(headerValue: string): { payload?: PaymentPayload; error?: string } {
+ if (!headerValue) {
+ return { error: 'missing_authorization' }
+ }
+
+ let paymentPayload: PaymentPayload
+ try {
+ paymentPayload = JSON.parse(headerValue)
+ } catch {
+ return { error: 'invalid_payload' }
+ }
+
+ if (paymentPayload.x402Version !== 2) {
+ return { error: 'invalid_x402_version' }
+ }
+
+ return { payload: paymentPayload }
+}
+
+function verifyPaymentPayload(payload: PaymentPayload, resourceUrl: string, maxAmountSats: bigint): { valid: boolean; invalidReason?: string; txid?: string; payer?: string } {
+ const accepted = payload.accepted
+
+ if (accepted.scheme !== 'utxo') {
+ return { valid: false, invalidReason: 'invalid_scheme' }
+ }
+
+ if (accepted.network !== NETWORK_ID) {
+ return { valid: false, invalidReason: 'invalid_network' }
+ }
+
+ if (accepted.payTo !== getPayToAddress()) {
+ return { valid: false, invalidReason: 'invalid_receiver_address' }
+ }
+
+ const acceptedAmount = BigInt(accepted.amount)
+ if (acceptedAmount > maxAmountSats) {
+ return { valid: false, invalidReason: 'insufficient_utxo_balance' }
+ }
+
+ if (accepted.asset !== ASSET_ID) {
+ return { valid: false, invalidReason: 'invalid_payload' }
+ }
+
+ const auth = payload.payload?.authorization
+ if (!auth) {
+ return { valid: false, invalidReason: 'missing_authorization' }
+ }
+
+ const valueSats = BigInt(auth.value)
+ if (valueSats > maxAmountSats) {
+ return { valid: false, invalidReason: 'insufficient_utxo_balance' }
+ }
+
+ if (auth.to !== accepted.payTo) {
+ return { valid: false, invalidReason: 'invalid_receiver_address' }
+ }
+
+ const txid = auth.txid === '*' ? crypto.randomUUID() : auth.txid
+ const payer = auth.from
+
+ console.log(`[PAYMENT REQUEST]`, JSON.stringify({
+ payer,
+ txid,
+ vout: auth.vout,
+ amount: auth.amount,
+ value: auth.value,
+ resource: resourceUrl,
+ }, null, 2))
+
+ if (!payload.payload?.signature) {
+ return { valid: false, invalidReason: 'invalid_exact_bch_payload_signature' }
+ }
+
+ return {
+ valid: true,
+ txid,
+ payer,
+ invalidReason: undefined,
+ }
+}
+
+async function handleRequest(req: http.IncomingMessage, res: http.ServerResponse): Promise {
+ const url = new URL(req.url || '/', `http://localhost:${PORT}`)
+ const path = url.pathname
+ const query = url.searchParams
+ const resourceUrl = `${path}${query.toString() ? '?' + query.toString() : ''}`
+
+ const route = routes[path]
+ if (!route) {
+ res.writeHead(404, { 'Content-Type': 'application/json' })
+ res.end(JSON.stringify({ error: 'Not found', available: Object.keys(routes) }))
+ return
+ }
+
+ const priceSats = route.price
+ const paymentRequired = buildPaymentRequired(`http://localhost:${PORT}${resourceUrl}`, priceSats)
+
+ if (req.method !== 'GET') {
+ res.writeHead(405, { 'Content-Type': 'application/json' })
+ res.end(JSON.stringify({ error: 'Method not allowed' }))
+ return
+ }
+
+ const paymentSignature = req.headers['payment-signature'] as string | undefined
+ const parsed = parsePaymentPayload(paymentSignature || '')
+
+ if (!parsed.payload) {
+ console.log(`[PAYMENT REQUIRED] ${path} - ${priceSats} sats - ${req.socket.remoteAddress}`)
+ send402Response(res, paymentRequired)
+ return
+ }
+
+ console.log(`[VERIFYING] ${path} from ${req.socket.remoteAddress}`)
+
+ const verifyResult = verifyPaymentPayload(parsed.payload, resourceUrl, BigInt(priceSats))
+
+ if (!verifyResult.valid) {
+ console.log(`[VERIFICATION FAILED] ${path} - ${verifyResult.invalidReason}`)
+ sendErrorResponse(res, 402, verifyResult.invalidReason!, paymentRequired)
+ return
+ }
+
+ console.log(`[VERIFIED] ${path} - txid: ${verifyResult.txid}`)
+
+ try {
+ const data = await route.handler(query)
+
+ const verifyResponse: VerifyResponse = {
+ isValid: true,
+ payer: verifyResult.payer,
+ remainingBalanceSat: '0',
+ }
+
+ res.writeHead(200, {
+ 'Content-Type': route.mimeType,
+ 'PAYMENT-RESPONSE': Buffer.from(JSON.stringify(verifyResponse)).toString('base64'),
+ })
+ res.end(JSON.stringify(data))
+ } catch (err: any) {
+ res.writeHead(500, { 'Content-Type': 'application/json' })
+ res.end(JSON.stringify({ error: err.message }))
+ }
+}
+
+const server = http.createServer(async (req, res) => {
+ try {
+ await handleRequest(req, res)
+ } catch (err) {
+ console.error('[ERROR]', err)
+ res.writeHead(500, { 'Content-Type': 'application/json' })
+ res.end(JSON.stringify({ error: 'Internal server error' }))
+ }
+})
+
+server.listen(PORT, () => {
+ console.log(`
+╔═══════════════════════════════════════════════════════════╗
+║ ║
+║ x402-bch Reference Server (v2.2 Compatible) ║
+║ Network: ${bchNetwork.name.padEnd(47)}║
+║ Port: ${PORT.toString().padEnd(47)}║
+║ ║
+╠═══════════════════════════════════════════════════════════╣
+║ ║
+║ Endpoints: ║
+║ GET /api/quote - ${routes['/api/quote'].price} sats - ${routes['/api/quote'].description.padEnd(25)}║
+║ GET /api/weather - ${routes['/api/weather'].price} sats - ${routes['/api/weather'].description.padEnd(25)}║
+║ GET /api/status - ${routes['/api/status'].price} sat - ${routes['/api/status'].description.padEnd(25)}║
+║ ║
+╠═══════════════════════════════════════════════════════════╣
+║ ║
+║ Set RECEIVE_ADDRESS env var to your BCH address ║
+║ Set BCH_NETWORK=chipnet for testnet ║
+║ ║
+╚═══════════════════════════════════════════════════════════╝
+`)
+})
+
+server.on('error', (err) => {
+ console.error('Server error:', err)
+ process.exit(1)
+})