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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/opencode.yml
Original file line number Diff line number Diff line change
@@ -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
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,37 @@ paytaca token send <address> <amount> --token <cat> # Send fungible tokens
paytaca token send-nft <address> --token <cat> --commitment <hex> # Send an NFT
```

### x402 Payments

The x402 protocol enables HTTP payments via BCH. Some APIs (like nanogpt) require payment to access.

```bash
paytaca check <url> # Check if URL requires payment, shows estimated cost
paytaca pay <url> # Make a paid HTTP request (handles 402 automatically)
paytaca pay <url> --json # JSON output (recommended for AI agents)
paytaca pay <url> --dry-run # Preview payment without executing
paytaca pay <url> --method POST # POST request with body
paytaca pay <url> --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:
Expand Down Expand Up @@ -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
Expand All @@ -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.
Loading
Loading