@everestan/protocolbanks-sdk 0.0.0-stage → 0.2.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,3 +1,46 @@
1
- # Temporary Holding Version
1
+ # @everestan/protocolbanks-sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Agent execution, payments and invoicing for Protocol Banks.
4
+
5
+ ```bash
6
+ npm install @everestan/protocolbanks-sdk
7
+ ```
8
+
9
+ ## Agent API
10
+
11
+ One API key, one policy the server enforces (operations, per-call cap, daily
12
+ cap, coin allowlist). `order` executes through the account's Hyperliquid agent
13
+ wallet (trading-only rights); `pay`, `swap` and `invoice` return something the
14
+ agent signs itself — the platform holds no keys.
15
+
16
+ ```ts
17
+ import { ProtocolBanks } from "@everestan/protocolbanks-sdk"
18
+
19
+ const pb = new ProtocolBanks({ apiKey: process.env.PB_KEY! })
20
+
21
+ const state = await pb.agent.state() // mode, equity, positions, policy
22
+ const order = await pb.agent.order({ coin: "BTC", side: "long", sizeUsd: 20 })
23
+
24
+ // Refusals are returned with the HTTP status — they are not exceptions.
25
+ if (!order.ok) console.log(order.status, order.error) // 403 policy · 409 guard
26
+ ```
27
+
28
+ ```ts
29
+ await pb.agent.pay({ to: "0x…", amountUsd: 25, token: "USDC", chain: "base" })
30
+ await pb.agent.swap({ from: { symbol: "USDC", blockchain: "base" }, to: { symbol: "ETH", blockchain: "base" }, amount: "25", amountUsd: 25 })
31
+ const invoice = await pb.agent.invoice({ to: "0x…", amount: 25, description: "agent work" })
32
+ await pb.agent.invoiceStatus(invoice.invoice!.invoiceId, "sig-from-paymentLink")
33
+ ```
34
+
35
+ - Reference: https://github.com/everest-an/protocol-banks---web3/blob/main/docs/AGENT_API.md
36
+ - Contract: https://protocolbanks.com/api/agent.openapi.json
37
+ - Tool manifest: `@everestan/protocolbanks-agent-tools`
38
+
39
+ ## Payments
40
+
41
+ `pb.paymentLinks`, `pb.invoices`, `pb.checkout`, `pb.webhooks` and
42
+ `pb.embed()` cover the payment surfaces. See the docs above for the contracts.
43
+
44
+ ## License
45
+
46
+ GPL-3.0-only.
@@ -0,0 +1,555 @@
1
+ /**
2
+ * SDK Type Definitions
3
+ */
4
+ type TokenSymbol = "USDC" | "USDT" | "DAI";
5
+ type ChainId = 1 | 8453 | 42161 | 137 | 10 | 56;
6
+ type PaymentStatus = "pending" | "paid" | "expired" | "cancelled" | "failed";
7
+ interface ProtocolBanksConfig {
8
+ /** API key for authentication (pk_* format) */
9
+ apiKey: string;
10
+ /** API secret (sk_* format, server-side only) */
11
+ apiSecret?: string;
12
+ /** Base URL for the Protocol Banks API */
13
+ baseUrl?: string;
14
+ /** Default chain ID */
15
+ defaultChainId?: ChainId;
16
+ /** Default token */
17
+ defaultToken?: TokenSymbol;
18
+ }
19
+ interface PaymentLinkConfig {
20
+ /** Payment title */
21
+ title: string;
22
+ /** Payment description */
23
+ description?: string;
24
+ /** Fixed amount (if not set, customer enters amount) */
25
+ amount?: string;
26
+ /** Payment token */
27
+ token?: TokenSymbol;
28
+ /** Recipient wallet address */
29
+ recipientAddress: string;
30
+ /** Redirect URL after payment */
31
+ redirectUrl?: string;
32
+ /** Expiration in seconds */
33
+ expiresIn?: number;
34
+ /** Custom branding */
35
+ branding?: {
36
+ color?: string;
37
+ logoUrl?: string;
38
+ };
39
+ /** Post-payment asset distribution */
40
+ assetDistribution?: {
41
+ type: "nft" | "token";
42
+ contractAddress: string;
43
+ tokenId?: string;
44
+ amount?: string;
45
+ };
46
+ /** Custom metadata */
47
+ metadata?: Record<string, any>;
48
+ }
49
+ interface InvoiceConfig {
50
+ /** Recipient wallet address */
51
+ recipientAddress: string;
52
+ /** Crypto amount */
53
+ amount: string;
54
+ /** Payment token */
55
+ token?: TokenSymbol;
56
+ /** Invoice description */
57
+ description: string;
58
+ /** Merchant/business name */
59
+ merchantName: string;
60
+ /** Fiat amount for dual-currency display */
61
+ amountFiat?: string;
62
+ /** Fiat currency code */
63
+ fiatCurrency?: string;
64
+ /** Customer info */
65
+ customer?: {
66
+ name?: string;
67
+ email?: string;
68
+ };
69
+ /** Expiration in hours */
70
+ expiresInHours?: number;
71
+ /** Custom metadata */
72
+ metadata?: Record<string, any>;
73
+ }
74
+ interface CheckoutConfig {
75
+ /** Order amount */
76
+ amount: string;
77
+ /** Currency (USD, EUR, etc.) */
78
+ currency?: string;
79
+ /** Payment token */
80
+ token?: TokenSymbol;
81
+ /** Merchant ID */
82
+ merchantId: string;
83
+ /** Notification URL for payment callbacks */
84
+ notifyUrl?: string;
85
+ /** Return URL after payment */
86
+ returnUrl?: string;
87
+ /** Custom metadata */
88
+ metadata?: Record<string, any>;
89
+ }
90
+ interface PaymentResult {
91
+ success: boolean;
92
+ /** Payment/order ID */
93
+ id: string;
94
+ /** Payment link URL */
95
+ paymentUrl: string;
96
+ /** Short URL */
97
+ shortUrl?: string;
98
+ /** QR code data */
99
+ qrCodeData?: string;
100
+ /** Payment status */
101
+ status: PaymentStatus;
102
+ /** Transaction hash (after payment) */
103
+ txHash?: string;
104
+ /** Error message */
105
+ error?: string;
106
+ }
107
+
108
+ /**
109
+ * Payment Links Module
110
+ *
111
+ * Create and manage no-code payment links.
112
+ */
113
+
114
+ declare class PaymentLink {
115
+ private config;
116
+ constructor(config: ProtocolBanksConfig);
117
+ /**
118
+ * Create a new payment link
119
+ */
120
+ create(options: PaymentLinkConfig): Promise<PaymentResult>;
121
+ /**
122
+ * Get payment link details
123
+ */
124
+ get(linkId: string): Promise<any>;
125
+ /**
126
+ * List all payment links
127
+ */
128
+ list(merchantId?: string): Promise<any>;
129
+ /**
130
+ * Update a payment link
131
+ */
132
+ update(linkId: string, updates: Partial<PaymentLinkConfig> & {
133
+ status?: string;
134
+ }): Promise<any>;
135
+ /**
136
+ * Delete a payment link
137
+ */
138
+ delete(linkId: string): Promise<any>;
139
+ }
140
+
141
+ /**
142
+ * Invoice Module
143
+ *
144
+ * Create and manage crypto invoices.
145
+ */
146
+
147
+ declare class Invoice {
148
+ private config;
149
+ constructor(config: ProtocolBanksConfig);
150
+ /**
151
+ * Create a new invoice
152
+ */
153
+ create(options: InvoiceConfig): Promise<PaymentResult>;
154
+ /**
155
+ * Get invoice details
156
+ */
157
+ get(invoiceId: string, signature?: string): Promise<any>;
158
+ /**
159
+ * Update invoice status (e.g., after payment)
160
+ */
161
+ updateStatus(invoiceId: string, status: string, txHash?: string, paidBy?: string): Promise<any>;
162
+ /**
163
+ * Get printable invoice export URL
164
+ */
165
+ getExportUrl(invoiceId: string, signature?: string): string;
166
+ /**
167
+ * List invoices for a merchant
168
+ */
169
+ list(options?: {
170
+ status?: string;
171
+ limit?: number;
172
+ offset?: number;
173
+ }): Promise<any>;
174
+ }
175
+
176
+ /**
177
+ * Checkout Module
178
+ *
179
+ * Create checkout sessions for merchant acquiring.
180
+ */
181
+
182
+ declare class Checkout {
183
+ private config;
184
+ constructor(config: ProtocolBanksConfig);
185
+ /**
186
+ * Create a new checkout order
187
+ */
188
+ create(options: CheckoutConfig): Promise<PaymentResult>;
189
+ /**
190
+ * Get order status
191
+ */
192
+ getStatus(orderNo: string): Promise<any>;
193
+ /**
194
+ * List orders for a merchant
195
+ */
196
+ listOrders(merchantId?: string, options?: {
197
+ limit?: number;
198
+ offset?: number;
199
+ }): Promise<any>;
200
+ /**
201
+ * Open checkout in a popup window
202
+ */
203
+ openPopup(options: CheckoutConfig): Promise<PaymentResult>;
204
+ }
205
+
206
+ /**
207
+ * Webhook Module
208
+ *
209
+ * Verify incoming webhook signatures and manage webhook subscriptions.
210
+ */
211
+
212
+ interface WebhookEvent {
213
+ event: string;
214
+ timestamp: string;
215
+ data: Record<string, any>;
216
+ delivery_id?: string;
217
+ }
218
+ interface WebhookConfig {
219
+ /** Webhook name */
220
+ name: string;
221
+ /** Delivery URL */
222
+ url: string;
223
+ /** Events to subscribe to */
224
+ events: string[];
225
+ }
226
+ declare class Webhook {
227
+ private config;
228
+ constructor(config: ProtocolBanksConfig);
229
+ /**
230
+ * Verify an incoming webhook signature (server-side only).
231
+ *
232
+ * Use this in your webhook handler to validate that the request
233
+ * came from Protocol Banks.
234
+ *
235
+ * @example
236
+ * ```ts
237
+ * const pb = new ProtocolBanks({ apiKey: 'pk_...' });
238
+ *
239
+ * app.post('/webhook', (req, res) => {
240
+ * const signature = req.headers['x-webhook-signature'];
241
+ * const timestamp = req.headers['x-webhook-timestamp'];
242
+ * const body = JSON.stringify(req.body);
243
+ *
244
+ * if (!pb.webhooks.verify(body, signature, 'whsec_...')) {
245
+ * return res.status(401).send('Invalid signature');
246
+ * }
247
+ *
248
+ * // Process event
249
+ * const event = req.body;
250
+ * console.log('Received event:', event.event);
251
+ * res.status(200).send('OK');
252
+ * });
253
+ * ```
254
+ */
255
+ verify(payload: string, signature: string, secret: string): boolean;
256
+ /**
257
+ * Browser-compatible signature verification using Web Crypto API
258
+ */
259
+ private verifyBrowser;
260
+ /**
261
+ * Async signature verification using Web Crypto API (works in browser and Node.js)
262
+ */
263
+ verifyAsync(payload: string, signature: string, secret: string): Promise<boolean>;
264
+ /**
265
+ * Construct a webhook event from a raw request
266
+ */
267
+ constructEvent(payload: string, signature: string, secret: string): WebhookEvent;
268
+ /**
269
+ * Create a new webhook subscription
270
+ */
271
+ create(options: WebhookConfig): Promise<any>;
272
+ /**
273
+ * List webhook subscriptions
274
+ */
275
+ list(): Promise<any>;
276
+ /**
277
+ * Delete a webhook subscription
278
+ */
279
+ delete(webhookId: string): Promise<any>;
280
+ /**
281
+ * Get recent webhook deliveries
282
+ */
283
+ getDeliveries(webhookId: string): Promise<any>;
284
+ }
285
+
286
+ /**
287
+ * Agent module
288
+ *
289
+ * The programmatic surface for AI agents: one API key, one policy the server
290
+ * enforces (operations, per-call cap, daily cap, coin allowlist). `order`
291
+ * executes through the account's Hyperliquid agent wallet (trading-only
292
+ * rights); `pay`, `swap` and `invoice` prepare something the agent signs
293
+ * itself, because the platform holds no keys.
294
+ *
295
+ * Every response is the API envelope plus the HTTP `status`, so a refusal
296
+ * (`ok: false` with 403/409) is returned, never thrown — a model should see
297
+ * the refusal and stop, not retry it.
298
+ */
299
+
300
+ type AgentOp = "read" | "pay" | "swap" | "trade";
301
+ interface AgentPolicy {
302
+ allowedOps: AgentOp[];
303
+ maxNotionalUsd: number;
304
+ dailyCapUsd: number;
305
+ allowedCoins: string[];
306
+ /** Present on `state` only: metered notional already spent today (UTC). */
307
+ spentTodayUsd?: number;
308
+ }
309
+ interface AgentAccount {
310
+ totalEquity: number;
311
+ mainWallet: number;
312
+ tradingWallet: number;
313
+ budget: number;
314
+ maxLoss: number;
315
+ todayPnl: number;
316
+ todayPnlPct: number;
317
+ allTimePnl: number;
318
+ }
319
+ interface AgentPosition {
320
+ symbol: string;
321
+ side: "long" | "short";
322
+ size: number;
323
+ entry: number;
324
+ mark: number;
325
+ pnl: number;
326
+ pnlPct: number;
327
+ leverage: number;
328
+ reason: string;
329
+ }
330
+ interface AgentActivity {
331
+ time: string;
332
+ type: "open" | "close" | "scan" | "guard" | "info" | "error";
333
+ text: string;
334
+ pnl: number | null;
335
+ }
336
+ interface AgentStateResponse {
337
+ ok?: boolean;
338
+ status?: number;
339
+ error?: string;
340
+ mode?: "paper" | "live";
341
+ agent?: {
342
+ status: "running" | "paused" | "stopped";
343
+ strategy: string;
344
+ lastScanAt: string;
345
+ marketsScanned: number;
346
+ confidenceHighSignals: number;
347
+ };
348
+ account?: AgentAccount;
349
+ equity?: {
350
+ t: string;
351
+ v: number;
352
+ }[];
353
+ positions?: AgentPosition[];
354
+ activity?: AgentActivity[];
355
+ pendingTrade?: {
356
+ symbol: string;
357
+ side: "long" | "short";
358
+ score: number;
359
+ reason: string;
360
+ markPx: number;
361
+ createdAt: string;
362
+ } | null;
363
+ approvalMode?: "auto" | "manual";
364
+ policy?: AgentPolicy;
365
+ }
366
+ interface AgentOrderRequest {
367
+ coin: string;
368
+ side: "long" | "short";
369
+ /** Notional in USD. Clamped to the platform position cap; refused above the key's cap. */
370
+ sizeUsd: number;
371
+ reason?: string;
372
+ }
373
+ interface AgentFill {
374
+ coin: string;
375
+ side: "long" | "short";
376
+ avgPx: number;
377
+ size: number;
378
+ notional: number;
379
+ }
380
+ interface AgentOrderResponse {
381
+ ok: boolean;
382
+ status?: number;
383
+ fill?: AgentFill;
384
+ fee?: number;
385
+ mode?: "live" | "paper";
386
+ /** dailyCapUsd − spentTodayUsd − this order */
387
+ remainingTodayUsd?: number;
388
+ error?: string;
389
+ }
390
+ interface AgentPayRequest {
391
+ to: string;
392
+ amountUsd: number;
393
+ token?: string;
394
+ chain?: string;
395
+ memo?: string;
396
+ }
397
+ interface AgentPayIntent {
398
+ kind: "evm-transfer" | "solana-transfer";
399
+ to: string;
400
+ token: string;
401
+ chain: string;
402
+ amountUsd: number;
403
+ memo?: string;
404
+ remainingTodayUsd: number;
405
+ }
406
+ interface AgentPayResponse {
407
+ ok: boolean;
408
+ status?: number;
409
+ intent?: AgentPayIntent;
410
+ note?: string;
411
+ error?: string;
412
+ }
413
+ interface AgentSwapAsset {
414
+ symbol: string;
415
+ blockchain: string;
416
+ address?: string | null;
417
+ }
418
+ interface AgentSwapRequest {
419
+ from: AgentSwapAsset;
420
+ to: AgentSwapAsset;
421
+ /** Amount in token units, as a string to avoid float precision loss. */
422
+ amount: string;
423
+ amountUsd: number;
424
+ slippage?: number;
425
+ }
426
+ interface AgentSwapResponse {
427
+ ok: boolean;
428
+ status?: number;
429
+ route?: {
430
+ requestId: string;
431
+ outputAmount: string;
432
+ outputAmountUsd: number;
433
+ swaps: unknown[];
434
+ tags: unknown[];
435
+ estimatedTimeInSeconds: number;
436
+ totalFeeUsd: number;
437
+ priceImpact: number;
438
+ };
439
+ note?: string;
440
+ error?: string;
441
+ }
442
+ interface AgentInvoiceRequest {
443
+ to: string;
444
+ amount: number;
445
+ token?: string;
446
+ chain?: string;
447
+ description?: string;
448
+ expiresInHours?: number;
449
+ }
450
+ interface AgentInvoice {
451
+ invoiceId: string;
452
+ status: "pending" | "paid" | "expired" | "cancelled";
453
+ to: string;
454
+ amount: number;
455
+ token: string;
456
+ chain: string;
457
+ description?: string;
458
+ expiresAt: string;
459
+ signed: boolean;
460
+ /** Give this to the payer: /pay?invoice=…&sig=… */
461
+ paymentLink: string;
462
+ }
463
+ interface AgentInvoiceResponse {
464
+ ok: boolean;
465
+ status?: number;
466
+ invoice?: AgentInvoice;
467
+ note?: string;
468
+ error?: string;
469
+ }
470
+ interface AgentInvoiceStatusResponse {
471
+ ok: boolean;
472
+ status: number;
473
+ invoice?: {
474
+ invoice_id: string;
475
+ status: string;
476
+ token: string;
477
+ chain: string | null;
478
+ amount: number;
479
+ paid_at: string | null;
480
+ customer_wallet: string | null;
481
+ };
482
+ error?: string;
483
+ }
484
+ declare class Agent {
485
+ private readonly config;
486
+ constructor(config: ProtocolBanksConfig);
487
+ private baseUrl;
488
+ private call;
489
+ /** Mode, equity, positions, activity and the key's policy with spentTodayUsd. */
490
+ state(): Promise<AgentStateResponse>;
491
+ /** Place one order. Executes through the trading-only agent wallet. */
492
+ order(request: AgentOrderRequest): Promise<AgentOrderResponse>;
493
+ /** Validate a payment and return the intent the agent signs itself. */
494
+ pay(request: AgentPayRequest): Promise<AgentPayResponse>;
495
+ /** Quote a swap; the agent signs and submits the returned transaction. */
496
+ swap(request: AgentSwapRequest): Promise<AgentSwapResponse>;
497
+ /** Create a pending invoice and get the payer's paymentLink. */
498
+ invoice(request: AgentInvoiceRequest): Promise<AgentInvoiceResponse>;
499
+ /**
500
+ * Read an invoice back with the id and signature from its paymentLink
501
+ * (`/pay?invoice=<id>&sig=<sig>`). A signed invoice answers 403 without sig.
502
+ */
503
+ invoiceStatus(invoiceId: string, sig?: string): Promise<AgentInvoiceStatusResponse>;
504
+ }
505
+
506
+ /**
507
+ * Protocol Banks SDK Client
508
+ *
509
+ * Main entry point for interacting with Protocol Banks APIs.
510
+ */
511
+
512
+ declare class ProtocolBanks {
513
+ private config;
514
+ /** Payment Links module */
515
+ paymentLinks: PaymentLink;
516
+ /** Invoicing module */
517
+ invoices: Invoice;
518
+ /** Checkout module */
519
+ checkout: Checkout;
520
+ /** Webhooks module */
521
+ webhooks: Webhook;
522
+ /** Agent module — orders through the platform's risk envelope */
523
+ agent: Agent;
524
+ constructor(config: ProtocolBanksConfig);
525
+ /**
526
+ * Create an embeddable payment iframe
527
+ */
528
+ embed(options: {
529
+ container: HTMLElement | string;
530
+ to: string;
531
+ amount?: string;
532
+ token?: string;
533
+ merchantName?: string;
534
+ theme?: "light" | "dark";
535
+ onSuccess?: (result: PaymentResult) => void;
536
+ onError?: (error: Error) => void;
537
+ }): {
538
+ destroy: () => void;
539
+ };
540
+ /**
541
+ * Generate a payment URL for direct redirect
542
+ */
543
+ getPaymentUrl(options: {
544
+ to: string;
545
+ amount: string;
546
+ token?: string;
547
+ merchantName?: string;
548
+ }): string;
549
+ /**
550
+ * Make an authenticated API request
551
+ */
552
+ request<T = any>(path: string, options?: RequestInit): Promise<T>;
553
+ }
554
+
555
+ export { Agent, type AgentAccount, type AgentActivity, type AgentFill, type AgentInvoice, type AgentInvoiceRequest, type AgentInvoiceResponse, type AgentInvoiceStatusResponse, type AgentOp, type AgentOrderRequest, type AgentOrderResponse, type AgentPayIntent, type AgentPayRequest, type AgentPayResponse, type AgentPolicy, type AgentPosition, type AgentStateResponse, type AgentSwapAsset, type AgentSwapRequest, type AgentSwapResponse, type ChainId, Checkout, type CheckoutConfig, Invoice, type InvoiceConfig, PaymentLink, type PaymentLinkConfig, type PaymentResult, type PaymentStatus, ProtocolBanks, type ProtocolBanksConfig, type TokenSymbol, Webhook, type WebhookConfig, type WebhookEvent };