@paybox-sh/sdk 0.5.0 → 0.8.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.
package/README.md CHANGED
@@ -1,10 +1,13 @@
1
1
  # @paybox-sh/sdk
2
2
 
3
- Typed Node SDK and `paybox` CLI for the Paybox agent API. It mirrors the MCP tool
4
- surface — `list_credentials`, `request_payment`, `request_wallet_sign`,
5
- `request_secret`, `request_swap`, `discover_services`, `pay_x402`, `use_service`,
6
- `get_portfolio`, `get_request` — but talks to the REST API directly, with no MCP
7
- host and no signing iframe.
3
+ Typed Node SDK and `paybox` CLI for the PayBox agent API. It mirrors the MCP tool
4
+ surface — `list_credentials`, `request_payment`, `claim_payment_credentials`,
5
+ `request_wallet_sign`, `request_secret`, `request_swap`, `discover_services`,
6
+ `pay_x402`, `use_service`, `get_portfolio`, `get_buy_link`,
7
+ `request_account_change`, `get_request`, and read-only plugin tools (`world_*`,
8
+ `hyperliquid_*`) — but talks to the REST API directly, with no MCP host and no
9
+ signing iframe.
10
+ Geofenced World money tools are MCP-only.
8
11
 
9
12
  Wallet signing is **non-custodial and runs in-process**: the SDK reuses the exact
10
13
  signing core from the wallet-sign iframe (`@paybox/mcp-app`), builds the chain
@@ -18,13 +21,20 @@ pnpm add @paybox-sh/sdk # library
18
21
  npx @paybox-sh/sdk login # or use the CLI directly
19
22
  ```
20
23
 
24
+ Driving this CLI from an agent? [`SKILL.md`](SKILL.md) ships in the package and
25
+ describes the install and login flow as an agent skill: what the human has to do
26
+ (approve wallets, paste one signing key), and what the agent should not do
27
+ around it.
28
+
21
29
  ## CLI
22
30
 
23
31
  ```bash
24
32
  # Authenticate: OAuth in the browser (approve with a passkey), or store a key.
25
33
  # `paybox login` is a guided two-step: OAuth, then it opens the app to provision
26
34
  # a wallet signing key and prompts you to paste the `pbxk1.` token back.
27
- paybox login # OAuth 2.1 + PKCE, then provision a key
35
+ # The OAuth step is a device-code grant, so the browser that approves does not
36
+ # have to be on the machine running the CLI.
37
+ paybox login # device-code OAuth, then provision a key
28
38
  paybox login --no-provision # OAuth only, skip the key step
29
39
  paybox login --key pbx_live_… # personal API key instead (no OAuth)
30
40
  paybox login --signing-key pbxk1.… # supply the signing key non-interactively
@@ -37,11 +47,20 @@ paybox sign --credential <id> --intent '{"op":"message","message":"gm"}'
37
47
  paybox swap --credential <id> --src-chain eip155:8453 \
38
48
  --src-token native --dst-token 0x… --amount 1000000000000000
39
49
  paybox portfolio --address 0x… --networks 1,8453
40
- paybox discover "weather api" # browse paid x402 services (Bazaar)
50
+ paybox discover "weather api" # browse curated paid x402 services
51
+ paybox discover --raw "weather api" # debug: uncurated compact summaries
41
52
  paybox pay-x402 --credential <id> --url https://svc/api --accepts @accepts.json
42
53
  paybox use-service --credential <id> --url https://svc/api # paybox pays + fetches
54
+ paybox claim <request_id> # claim an approved payment's card (one-time)
55
+ paybox buy-link --credential <id> --amount-usd 50 # defaults EVM funding to Base
56
+ paybox buy-link --credential <id> --destination eip155:1 --currency eth
57
+ paybox account-change --note "need a wallet grant" # manage_url for the user to open
43
58
  paybox request <request_id> --wait # poll a pending request
44
59
 
60
+ # Plugins (enable them in the paybox app first)
61
+ paybox world markets --status active # browse prediction markets
62
+ paybox hyperliquid markets # spot discovery
63
+
45
64
  paybox version # installed version (+ update check)
46
65
  paybox update # update the global install to latest
47
66
  paybox uninstall # clear stored config (prints npm rm)
@@ -55,16 +74,19 @@ clears `~/.config/paybox` and prints the `npm rm -g` line (a package can't remov
55
74
  its own binary). For project installs use `pnpm up`/`pnpm rm`, or `npx
56
75
  @paybox-sh/sdk@latest` to always run the latest without installing.
57
76
 
58
- `sign`, `swap`, `pay-x402`, and `use-service` complete in-process when a `pbxk1.`
59
- signing key is configured and the operation clears immediately (autonomous
60
- grant). When the grant requires approval, the command returns `pending_approval`;
61
- approve in the app, then `paybox request <id> --wait`.
77
+ `sign`, `swap`, `pay-x402`, and `use-service` can complete in-process with a
78
+ configured `pbxk1.` key. World buy/sell/redeem are MCP-only.
79
+
80
+ For a Solana `swap` the SDK re-pins a fresh recent blockhash immediately before
81
+ signing (parity with the signing window — the quote-time blockhash expires
82
+ within ~60–90s, often before signing), so a swap that dwells for approval no
83
+ longer broadcasts as `BlockhashNotFound`. EVM swaps are unaffected.
62
84
 
63
85
  `pay-x402` is header mode — on success `output.value.x_payment` is the `X-PAYMENT`
64
86
  header to replay on the original request. `use-service` is gateway mode — paybox
65
87
  makes the paid call for you and returns the resource's reply on
66
- `output.value.response`. Pass `--accepts` from the resource's own 402 (browse the
67
- catalog with `paybox discover`).
88
+ `output.value.response`. Pass `--accepts` from the resource's own 402 (start from
89
+ the curated Bazaar set with `paybox discover`).
68
90
 
69
91
  ## Library
70
92
 
@@ -74,14 +96,18 @@ import { PayboxClient } from "@paybox-sh/sdk";
74
96
  const paybox = PayboxClient.fromConfig(); // reads ~/.config/paybox + env
75
97
  // or: new PayboxClient({ apiKey: "pbx_live_…", signingKey: "pbxk1.…" });
76
98
 
77
- const creds = await paybox.listCredentials();
99
+ const { credentials, ungranted } = await paybox.listCredentials();
78
100
  const pay = await paybox.requestPayment({
79
- credentialId: creds[0].credential.id,
101
+ credentialId: credentials[0].credential.id,
80
102
  merchant: "Acme",
81
103
  merchantUrl: "https://acme.com",
82
104
  amountCents: 1999,
83
105
  });
84
106
 
107
+ // Ungranted credentials the user owns but hasn't granted this connector — pass
108
+ // an id to request_account_change's `add` to ask for access.
109
+ console.log(ungranted.map((c) => `${c.name} (${c.kind})`));
110
+
85
111
  const sig = await paybox.requestWalletSign({
86
112
  credentialId: walletId,
87
113
  chain: "eip155:8453",
@@ -91,6 +117,7 @@ const sig = await paybox.requestWalletSign({
91
117
  // x402: discover a paid endpoint, then pay it — header mode (you replay the
92
118
  // X-PAYMENT header) or gateway mode (paybox fetches the paid content for you).
93
119
  const services = await paybox.discoverServices("weather api");
120
+ const rawServices = await paybox.discoverServices("weather api", { raw: true }); // debug only
94
121
  const paid = await paybox.useService({ credentialId: walletId, url: services[0].resource });
95
122
  // paid.response.output.value.response holds the resource's reply
96
123
  ```
@@ -114,6 +141,10 @@ env vars on shared Windows machines.
114
141
 
115
142
  ## Develop
116
143
 
144
+ `pnpm-lock.yaml` also contains the `../mcp-app` importer because this SDK
145
+ consumes the iframe's signing core through `file:../mcp-app`. The iframe build
146
+ shares this dependency resolution but keeps its installed modules separate.
147
+
117
148
  ```bash
118
149
  pnpm install
119
150
  pnpm typecheck
package/SKILL.md ADDED
@@ -0,0 +1,118 @@
1
+ ---
2
+ name: PayBox CLI setup
3
+ description: >-
4
+ Install and log in to the PayBox CLI (@paybox-sh/sdk) so an agent can pay,
5
+ sign, and hold wallet, card, and secret credentials on the user's behalf. Use
6
+ when the user says "install PayBox", "set up PayBox", "instalar PayBox", or
7
+ asks an agent to connect their PayBox wallet.
8
+ ---
9
+
10
+ # PayBox CLI setup
11
+
12
+ The user asks to install PayBox. Two things need them: they approve wallet
13
+ access with a passkey, and they paste one signing key. Everything else is yours,
14
+ and they should not see it happen.
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ npm install -g @paybox-sh/sdk
20
+ ```
21
+
22
+ The CLI runs wherever you run it, which is often not the user's own machine.
23
+ That is fine: login uses an OAuth device-code grant, so the browser that
24
+ approves does not have to be the one the CLI can reach.
25
+
26
+ Never delete or overwrite an existing config directory. To isolate a run from
27
+ credentials the user already has, point `PAYBOX_CONFIG_DIR` at a fresh
28
+ directory.
29
+
30
+ ## Log in
31
+
32
+ Run this once, in the same turn the user asks:
33
+
34
+ ```bash
35
+ paybox login
36
+ ```
37
+
38
+ Add `--base-url` and `--app-url` for an environment other than the default.
39
+
40
+ The command drives the whole flow itself. Do not reimplement any of it: it
41
+ registers a client, starts device authorization, prints a verification URL and a
42
+ short user code, tries to open that URL locally, polls until the user approves,
43
+ then opens the signing-key page and prompts for the key.
44
+
45
+ Login writes progress to stderr as plain prose, not JSON. Watch for the
46
+ verification URL and the `Code:` line.
47
+
48
+ ### Step 1 — Authorize wallets
49
+
50
+ The moment login prints the verification URL and code, put **one** message in
51
+ front of the user: a markdown link labeled **Authorize wallets** pointing at that
52
+ URL, plus the code.
53
+
54
+ Send that link even though the CLI also tries to open a browser. When the CLI
55
+ is not on the user's machine, that local open is useless or invisible, and your
56
+ message is the only way they reach the page.
57
+
58
+ The user approves in the browser. They should not open the link in a native
59
+ PayBox mobile app; that path cannot complete a device-code approval.
60
+
61
+ Then wait. The poll is the continue signal. Do not ask the user to type `done`,
62
+ confirm, or send a screenshot, and do not end your turn while login is running.
63
+ If the code expires before they approve, run `paybox login` again for a fresh
64
+ one rather than reusing the old link.
65
+
66
+ ### Step 2 — Paste the signing key
67
+
68
+ After approval, login opens the signing-key page and prompts for the key.
69
+ Present a **masked input** for the `pbxk1.` value and write what the user gives
70
+ you to that prompt's stdin.
71
+
72
+ Pass it through the prompt, never as `login --signing-key <value>` on the
73
+ command line: an argument lands in shell history and is visible to anyone who
74
+ can list processes.
75
+
76
+ Do not ask the user to click the signing-key link, it is already open. Do not
77
+ show the key field before that page has opened, and do not open it twice.
78
+
79
+ Wallet signing is non-custodial: the key stays on the user's machine and PayBox
80
+ never holds it. Never print, log, or echo it.
81
+
82
+ ### Step 3 — Confirm
83
+
84
+ ```bash
85
+ paybox --json whoami
86
+ ```
87
+
88
+ `canSign` must be `true`. If it is `false` the key did not save; redo step 2
89
+ rather than continuing, because signing and swaps will fail without it.
90
+
91
+ ## What the user sees
92
+
93
+ From the install request until `canSign` is `true`, exactly two messages, in
94
+ this order:
95
+
96
+ 1. The **Authorize wallets** link plus the code.
97
+ 2. The masked `pbxk1.` field, after the signing-key page has opened.
98
+
99
+ Nothing else. No "Installing…", "Opening…", "Got it", no CLI version, package
100
+ manager, config path, or request id, and no narration of a retry or fallback. If
101
+ something is blocked, switch approaches quietly. If you have nothing they need
102
+ to act on, send nothing.
103
+
104
+ Match the user's language. Default to English unless they write otherwise.
105
+
106
+ Once `canSign` is `true`, show them what they now have: `paybox --json
107
+ credentials` for the granted wallets, then `paybox --json portfolio --address
108
+ <wallet>` for balances. Render a compact table, never addresses or raw JSON. The
109
+ CLI cannot create wallets; it uses what the user granted during authorization.
110
+
111
+ ## A setup that went wrong
112
+
113
+ - The user had to prompt you after approving wallet access.
114
+ - The key field appeared before the signing-key page opened.
115
+ - You asked the user to click the signing-key link, or to type `done`.
116
+ - You opened either page twice.
117
+ - Setup chat contained anything besides those two messages.
118
+ - A token, API key, or `pbxk1.` value reached the transcript.