paytaca-cli 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +91 -12
  2. package/dist/commands/address.d.ts +2 -0
  3. package/dist/commands/address.d.ts.map +1 -1
  4. package/dist/commands/address.js +19 -4
  5. package/dist/commands/address.js.map +1 -1
  6. package/dist/commands/balance.d.ts +2 -0
  7. package/dist/commands/balance.d.ts.map +1 -1
  8. package/dist/commands/balance.js +58 -12
  9. package/dist/commands/balance.js.map +1 -1
  10. package/dist/commands/check.d.ts +14 -0
  11. package/dist/commands/check.d.ts.map +1 -0
  12. package/dist/commands/check.js +162 -0
  13. package/dist/commands/check.js.map +1 -0
  14. package/dist/commands/claude.d.ts +9 -0
  15. package/dist/commands/claude.d.ts.map +1 -0
  16. package/dist/commands/claude.js +20 -0
  17. package/dist/commands/claude.js.map +1 -0
  18. package/dist/commands/history.d.ts +2 -0
  19. package/dist/commands/history.d.ts.map +1 -1
  20. package/dist/commands/history.js +40 -7
  21. package/dist/commands/history.js.map +1 -1
  22. package/dist/commands/opencode.d.ts +9 -0
  23. package/dist/commands/opencode.d.ts.map +1 -0
  24. package/dist/commands/opencode.js +20 -0
  25. package/dist/commands/opencode.js.map +1 -0
  26. package/dist/commands/pay.d.ts +17 -0
  27. package/dist/commands/pay.d.ts.map +1 -0
  28. package/dist/commands/pay.js +347 -0
  29. package/dist/commands/pay.js.map +1 -0
  30. package/dist/commands/receive.d.ts +9 -1
  31. package/dist/commands/receive.d.ts.map +1 -1
  32. package/dist/commands/receive.js +117 -8
  33. package/dist/commands/receive.js.map +1 -1
  34. package/dist/commands/token.d.ts +16 -0
  35. package/dist/commands/token.d.ts.map +1 -0
  36. package/dist/commands/token.js +351 -0
  37. package/dist/commands/token.js.map +1 -0
  38. package/dist/index.d.ts +2 -2
  39. package/dist/index.js +13 -3
  40. package/dist/index.js.map +1 -1
  41. package/dist/types/x402.d.ts +72 -0
  42. package/dist/types/x402.d.ts.map +1 -0
  43. package/dist/types/x402.js +9 -0
  44. package/dist/types/x402.js.map +1 -0
  45. package/dist/utils/skill.d.ts +17 -0
  46. package/dist/utils/skill.d.ts.map +1 -0
  47. package/dist/utils/skill.js +100 -0
  48. package/dist/utils/skill.js.map +1 -0
  49. package/dist/utils/x402.d.ts +17 -0
  50. package/dist/utils/x402.d.ts.map +1 -0
  51. package/dist/utils/x402.js +119 -0
  52. package/dist/utils/x402.js.map +1 -0
  53. package/dist/utils/x402.test.d.ts +2 -0
  54. package/dist/utils/x402.test.d.ts.map +1 -0
  55. package/dist/utils/x402.test.js +216 -0
  56. package/dist/utils/x402.test.js.map +1 -0
  57. package/dist/wallet/bch.d.ts +110 -3
  58. package/dist/wallet/bch.d.ts.map +1 -1
  59. package/dist/wallet/bch.js +214 -2
  60. package/dist/wallet/bch.js.map +1 -1
  61. package/dist/wallet/keys.d.ts +8 -0
  62. package/dist/wallet/keys.d.ts.map +1 -1
  63. package/dist/wallet/keys.js +10 -0
  64. package/dist/wallet/keys.js.map +1 -1
  65. package/dist/wallet/x402.d.ts +29 -0
  66. package/dist/wallet/x402.d.ts.map +1 -0
  67. package/dist/wallet/x402.js +45 -0
  68. package/dist/wallet/x402.js.map +1 -0
  69. package/package.json +8 -2
  70. package/skills/paytaca/SKILL.md +123 -0
@@ -0,0 +1,123 @@
1
+ ---
2
+ name: paytaca-x402
3
+ 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.
4
+ ---
5
+
6
+ # Paytaca x402 Payment Handler
7
+
8
+ This skill teaches the agent how to handle x402-based HTTP payments using the Paytaca CLI wallet.
9
+
10
+ ## Overview
11
+
12
+ Some APIs (like nanogpt, etc.) use the x402 protocol for HTTP payments. When you call these APIs:
13
+ - Server returns **HTTP 402 PAYMENT REQUIRED**
14
+ - You must pay with BCH to access the resource
15
+ - After payment, the server returns the actual response
16
+
17
+ ## Commands
18
+
19
+ ### Check if a URL requires payment (recommended first step)
20
+
21
+ ```bash
22
+ paytaca check <url> --json
23
+ # Returns: acceptsX402, acceptsBch, estimatedCostSats, etc.
24
+ ```
25
+
26
+ Example output:
27
+ ```json
28
+ {
29
+ "url": "https://api.nanogpt.com/v1/complete",
30
+ "acceptsX402": true,
31
+ "acceptsBch": true,
32
+ "paymentRequired": true,
33
+ "estimatedCostSats": "100",
34
+ "costInBch": "0.00000100"
35
+ }
36
+ ```
37
+
38
+ ### Preview payment without executing (dry-run)
39
+
40
+ ```bash
41
+ paytaca pay <url> --dry-run --json
42
+ # Shows what would happen without actually paying
43
+ ```
44
+
45
+ ### Make a paid request
46
+
47
+ ```bash
48
+ # Basic
49
+ paytaca pay <url>
50
+
51
+ # With JSON output (preferred for AI agents)
52
+ paytaca pay <url> --json
53
+
54
+ # POST request
55
+ paytaca pay <url> --method POST --body '{"prompt":"hello"}'
56
+
57
+ # Custom headers
58
+ paytaca pay <url> -H "Authorization: Bearer token123"
59
+ ```
60
+
61
+ ### Check wallet balance
62
+
63
+ ```bash
64
+ paytaca balance
65
+ ```
66
+
67
+ ## Decision Flow
68
+
69
+ When preparing to call an unfamiliar API that might require payment:
70
+
71
+ 1. **First check**: `paytaca check <url> --json`
72
+ - If `paymentRequired: false` → proceed normally
73
+ - If `paymentRequired: true` and `acceptsBch: true` → inform user of cost and **seek explicit approval** before paying
74
+ - If `paymentRequired: true` but `acceptsBch: false` → inform user
75
+
76
+ 2. **When encountering HTTP 402**:
77
+ - Parse the `PAYMENT-REQUIRED` headers
78
+ - **Seek explicit user approval** before spending any BCH
79
+ - Once approved, use `paytaca pay <url> --json` to handle payment
80
+ - The command handles: parse headers → build BCH tx → broadcast → retry with signature
81
+
82
+ 3. **For known paid APIs**:
83
+ - **Always seek user approval first**, then use `paytaca pay <url>` - it handles 402 automatically
84
+
85
+ ## ⚠️ User Approval Required Before Any Payment
86
+
87
+ **CRITICAL**: The agent MUST NOT execute `paytaca pay` without explicit user approval. Since `paytaca pay` spends real BCH from the user's wallet, always:
88
+
89
+ 1. Inform the user of the cost (e.g., "This API costs ~1000 sats")
90
+ 2. Wait for explicit user confirmation (e.g., "yes", "go ahead", "pay")
91
+ 3. Only then execute the payment
92
+
93
+ Do NOT assume the user wants to pay - even if the cost seems small.
94
+
95
+ ## AI Agent Workflow
96
+
97
+ ```
98
+ Task: Call nanogpt API
99
+ Agent: paytaca check https://api.nanogpt.com/v1/complete --json
100
+ → {"acceptsBch": true, "estimatedCostSats": "100"}
101
+
102
+ Agent: Informs user "This API costs 100 sats (0.00000100 BCH). Approve to proceed?"
103
+ User: "yes"
104
+
105
+ Agent: paytaca pay https://api.nanogpt.com/v1/complete --method POST --body '{"prompt":"hello"}' --json
106
+ → Handles 402 → pays 100 sats → returns response with txid
107
+ ```
108
+
109
+ ## Key Options
110
+
111
+ | Option | Description |
112
+ |--------|-------------|
113
+ | `--json` | Machine-readable output (recommended for AI) |
114
+ | `--dry-run` | Preview payment without executing |
115
+ | `--chipnet` | Use chipnet (testnet) instead of mainnet |
116
+ | `--max-amount` | Override max payment amount in sats |
117
+
118
+ ## Notes
119
+
120
+ - Payment is per-request (no batching)
121
+ - Each request = separate BCH transaction
122
+ - Only BCH payments are supported (no stablecoins)
123
+ - Uses local wallet from OS keychain (credentials never leave the machine)