@pay-skill/sdk 0.1.1
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 +154 -0
- package/dist/auth.d.ts +47 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +121 -0
- package/dist/auth.js.map +1 -0
- package/dist/client.d.ts +93 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +391 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +24 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +42 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/models.d.ts +69 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +2 -0
- package/dist/models.js.map +1 -0
- package/dist/ows-signer.d.ts +75 -0
- package/dist/ows-signer.d.ts.map +1 -0
- package/dist/ows-signer.js +130 -0
- package/dist/ows-signer.js.map +1 -0
- package/dist/signer.d.ts +46 -0
- package/dist/signer.d.ts.map +1 -0
- package/dist/signer.js +112 -0
- package/dist/signer.js.map +1 -0
- package/dist/wallet.d.ts +121 -0
- package/dist/wallet.d.ts.map +1 -0
- package/dist/wallet.js +328 -0
- package/dist/wallet.js.map +1 -0
- package/eslint.config.js +22 -0
- package/package.json +44 -0
- package/src/auth.ts +200 -0
- package/src/client.ts +644 -0
- package/src/eip3009.ts +79 -0
- package/src/errors.ts +48 -0
- package/src/index.ts +51 -0
- package/src/models.ts +77 -0
- package/src/ows-signer.ts +223 -0
- package/src/signer.ts +147 -0
- package/src/wallet.ts +445 -0
- package/tests/test_auth_rejection.ts +154 -0
- package/tests/test_crypto.ts +251 -0
- package/tests/test_e2e.ts +158 -0
- package/tests/test_errors.ts +36 -0
- package/tests/test_ows_integration.ts +92 -0
- package/tests/test_ows_signer.ts +365 -0
- package/tests/test_signer.ts +47 -0
- package/tests/test_validation.ts +66 -0
- package/tsconfig.json +19 -0
package/dist/client.js
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PayClient — single entry point for the pay SDK.
|
|
3
|
+
*/
|
|
4
|
+
import { PayNetworkError, PayServerError, PayValidationError, } from "./errors.js";
|
|
5
|
+
import { createSigner } from "./signer.js";
|
|
6
|
+
import { buildAuthHeaders, buildAuthHeadersWithSigner, } from "./auth.js";
|
|
7
|
+
import { sign as viemSign, serializeSignature } from "viem/accounts";
|
|
8
|
+
const ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
9
|
+
const DIRECT_MIN = 1_000_000; // $1.00 USDC
|
|
10
|
+
const TAB_MIN = 5_000_000; // $5.00 USDC
|
|
11
|
+
export const DEFAULT_API_URL = "https://pay-skill.com/api/v1";
|
|
12
|
+
function validateAddress(address, field = "address") {
|
|
13
|
+
if (!ADDRESS_RE.test(address)) {
|
|
14
|
+
throw new PayValidationError(`Invalid Ethereum address: ${address}`, field);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function validateAmount(amount, minimum, field = "amount") {
|
|
18
|
+
if (amount < minimum) {
|
|
19
|
+
const minUsd = minimum / 1_000_000;
|
|
20
|
+
throw new PayValidationError(`Amount ${amount} below minimum ($${minUsd.toFixed(2)})`, field);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class PayClient {
|
|
24
|
+
apiUrl;
|
|
25
|
+
/** URL path prefix extracted from apiUrl (e.g., "/api/v1"). */
|
|
26
|
+
_basePath;
|
|
27
|
+
signer;
|
|
28
|
+
_privateKey;
|
|
29
|
+
_authConfig;
|
|
30
|
+
constructor(options = {}) {
|
|
31
|
+
this.apiUrl = (options.apiUrl ?? DEFAULT_API_URL).replace(/\/+$/, "");
|
|
32
|
+
// Extract the URL path to prepend to auth signing paths.
|
|
33
|
+
// e.g., "http://host:3001/api/v1" → "/api/v1"
|
|
34
|
+
try {
|
|
35
|
+
this._basePath = new URL(this.apiUrl).pathname.replace(/\/+$/, "");
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
this._basePath = "";
|
|
39
|
+
}
|
|
40
|
+
if (typeof options.signer === "object") {
|
|
41
|
+
this.signer = options.signer;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.signer = createSigner(options.signer ?? "cli", {
|
|
45
|
+
...options.signerOptions,
|
|
46
|
+
key: options.signerOptions?.key ?? options.privateKey,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
// Private key for direct signing (preferred over Signer for auth)
|
|
50
|
+
this._privateKey = options.privateKey
|
|
51
|
+
? (options.privateKey.startsWith("0x")
|
|
52
|
+
? options.privateKey
|
|
53
|
+
: "0x" + options.privateKey)
|
|
54
|
+
: null;
|
|
55
|
+
// Auth config for EIP-712 domain
|
|
56
|
+
if (options.chainId && options.routerAddress) {
|
|
57
|
+
this._authConfig = {
|
|
58
|
+
chainId: options.chainId,
|
|
59
|
+
routerAddress: options.routerAddress,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
this._authConfig = null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// ── Direct Payment ──────────────────────────────────────────────
|
|
67
|
+
async payDirect(to, amount, options = {}) {
|
|
68
|
+
validateAddress(to, "to");
|
|
69
|
+
validateAmount(amount, DIRECT_MIN);
|
|
70
|
+
// Get contract addresses to determine the spender
|
|
71
|
+
const contracts = await this.get("/contracts");
|
|
72
|
+
const permit = await this.prepareAndSignPermit(amount, contracts.direct);
|
|
73
|
+
const data = await this.post("/direct", {
|
|
74
|
+
to,
|
|
75
|
+
amount,
|
|
76
|
+
memo: options.memo ?? "",
|
|
77
|
+
permit,
|
|
78
|
+
});
|
|
79
|
+
return data;
|
|
80
|
+
}
|
|
81
|
+
// ── Tab Management ──────────────────────────────────────────────
|
|
82
|
+
async openTab(provider, amount, options) {
|
|
83
|
+
validateAddress(provider, "provider");
|
|
84
|
+
validateAmount(amount, TAB_MIN);
|
|
85
|
+
if (options.maxChargePerCall <= 0) {
|
|
86
|
+
throw new PayValidationError("maxChargePerCall must be positive", "maxChargePerCall");
|
|
87
|
+
}
|
|
88
|
+
const contracts = await this.get("/contracts");
|
|
89
|
+
const permit = await this.prepareAndSignPermit(amount, contracts.tab);
|
|
90
|
+
return this.post("/tabs", {
|
|
91
|
+
provider,
|
|
92
|
+
amount,
|
|
93
|
+
max_charge_per_call: options.maxChargePerCall,
|
|
94
|
+
permit,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
async closeTab(tabId) {
|
|
98
|
+
return this.post(`/tabs/${tabId}/close`, {});
|
|
99
|
+
}
|
|
100
|
+
async withdrawTab(tabId) {
|
|
101
|
+
return this.post(`/tabs/${tabId}/withdraw`, {});
|
|
102
|
+
}
|
|
103
|
+
async topUpTab(tabId, amount) {
|
|
104
|
+
validateAmount(amount, 1, "amount");
|
|
105
|
+
const contracts = await this.get("/contracts");
|
|
106
|
+
const permit = await this.prepareAndSignPermit(amount, contracts.tab);
|
|
107
|
+
return this.post(`/tabs/${tabId}/topup`, { amount, permit });
|
|
108
|
+
}
|
|
109
|
+
async listTabs() {
|
|
110
|
+
return this.get("/tabs");
|
|
111
|
+
}
|
|
112
|
+
async getTab(tabId) {
|
|
113
|
+
return this.get(`/tabs/${tabId}`);
|
|
114
|
+
}
|
|
115
|
+
// ── x402 ────────────────────────────────────────────────────────
|
|
116
|
+
static X402_TAB_MULTIPLIER = 10;
|
|
117
|
+
async request(url, options = {}) {
|
|
118
|
+
const method = options.method ?? "GET";
|
|
119
|
+
const headers = options.headers ?? {};
|
|
120
|
+
const bodyStr = options.body ? JSON.stringify(options.body) : undefined;
|
|
121
|
+
const resp = await fetch(url, { method, body: bodyStr, headers });
|
|
122
|
+
if (resp.status !== 402)
|
|
123
|
+
return resp;
|
|
124
|
+
return this.handle402(resp, url, method, bodyStr, headers);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Parse x402 V2 payment requirements from a 402 response.
|
|
128
|
+
*
|
|
129
|
+
* Checks PAYMENT-REQUIRED header first (base64-encoded JSON),
|
|
130
|
+
* falls back to response body. Requires x402Version 2 with
|
|
131
|
+
* a non-empty `accepts` array.
|
|
132
|
+
*/
|
|
133
|
+
async parse402Requirements(resp) {
|
|
134
|
+
const prHeader = resp.headers.get("payment-required");
|
|
135
|
+
if (prHeader) {
|
|
136
|
+
const parsed = this.tryParseV2(prHeader);
|
|
137
|
+
if (parsed)
|
|
138
|
+
return parsed;
|
|
139
|
+
}
|
|
140
|
+
// Fallback: try v2 format in response body
|
|
141
|
+
const body = (await resp.json());
|
|
142
|
+
if (body.x402Version === 2 && Array.isArray(body.accepts) && body.accepts.length > 0) {
|
|
143
|
+
const accepted = body.accepts[0];
|
|
144
|
+
return this.extractFromAccepted(accepted);
|
|
145
|
+
}
|
|
146
|
+
throw new PayServerError("Unrecognized 402 format — expected x402 v2", 402);
|
|
147
|
+
}
|
|
148
|
+
/** Decode a base64 header and extract v2 requirements, or null if not v2. */
|
|
149
|
+
tryParseV2(header) {
|
|
150
|
+
try {
|
|
151
|
+
const decoded = JSON.parse(atob(header));
|
|
152
|
+
if (decoded.x402Version !== 2 || !Array.isArray(decoded.accepts) || decoded.accepts.length === 0) {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
return this.extractFromAccepted(decoded.accepts[0]);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
extractFromAccepted(accepted) {
|
|
162
|
+
return {
|
|
163
|
+
settlement: accepted.extra?.settlement ?? "direct",
|
|
164
|
+
amount: Number(accepted.amount ?? 0),
|
|
165
|
+
to: accepted.payTo,
|
|
166
|
+
accepted,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
async handle402(resp, url, method, body, headers) {
|
|
170
|
+
const { settlement, amount, to: provider, accepted } = await this.parse402Requirements(resp);
|
|
171
|
+
if (settlement === "tab") {
|
|
172
|
+
return this.settleViaTab(url, method, body, headers, provider, amount, accepted);
|
|
173
|
+
}
|
|
174
|
+
return this.settleViaDirect(url, method, body, headers, provider, amount, accepted);
|
|
175
|
+
}
|
|
176
|
+
async settleViaDirect(url, method, body, headers, provider, amount, accepted) {
|
|
177
|
+
const result = await this.payDirect(provider, amount);
|
|
178
|
+
const txHash = result.txHash ??
|
|
179
|
+
result.tx_hash ??
|
|
180
|
+
"";
|
|
181
|
+
const paymentPayload = {
|
|
182
|
+
x402Version: 2,
|
|
183
|
+
accepted,
|
|
184
|
+
payload: { txHash },
|
|
185
|
+
extensions: {
|
|
186
|
+
pay: { settlement: "direct", status: result.status },
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
return fetch(url, {
|
|
190
|
+
method,
|
|
191
|
+
body,
|
|
192
|
+
headers: {
|
|
193
|
+
...headers,
|
|
194
|
+
"PAYMENT-SIGNATURE": btoa(JSON.stringify(paymentPayload)),
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
async settleViaTab(url, method, body, headers, provider, amount, accepted) {
|
|
199
|
+
const tabs = await this.listTabs();
|
|
200
|
+
let tab = tabs.find((t) => t.provider === provider && t.status === "open");
|
|
201
|
+
if (!tab) {
|
|
202
|
+
const tabAmount = Math.max(amount * PayClient.X402_TAB_MULTIPLIER, TAB_MIN);
|
|
203
|
+
tab = await this.openTab(provider, tabAmount, {
|
|
204
|
+
maxChargePerCall: amount,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
const chargeData = await this.post(`/tabs/${tab.tabId}/charge`, { amount });
|
|
208
|
+
const paymentPayload = {
|
|
209
|
+
x402Version: 2,
|
|
210
|
+
accepted,
|
|
211
|
+
payload: {},
|
|
212
|
+
extensions: {
|
|
213
|
+
pay: {
|
|
214
|
+
settlement: "tab",
|
|
215
|
+
tabId: tab.tabId,
|
|
216
|
+
chargeId: chargeData.chargeId ?? "",
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
return fetch(url, {
|
|
221
|
+
method,
|
|
222
|
+
body,
|
|
223
|
+
headers: {
|
|
224
|
+
...headers,
|
|
225
|
+
"PAYMENT-SIGNATURE": btoa(JSON.stringify(paymentPayload)),
|
|
226
|
+
},
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
// ── Wallet ──────────────────────────────────────────────────────
|
|
230
|
+
async getStatus() {
|
|
231
|
+
const raw = await this.get("/status");
|
|
232
|
+
return {
|
|
233
|
+
address: raw.wallet,
|
|
234
|
+
balance: raw.balance_usdc ? Number(raw.balance_usdc) : 0,
|
|
235
|
+
openTabs: [],
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
// ── Webhooks ────────────────────────────────────────────────────
|
|
239
|
+
async registerWebhook(url, options = {}) {
|
|
240
|
+
const payload = { url };
|
|
241
|
+
if (options.events)
|
|
242
|
+
payload.events = options.events;
|
|
243
|
+
if (options.secret)
|
|
244
|
+
payload.secret = options.secret;
|
|
245
|
+
const raw = await this.post("/webhooks", payload);
|
|
246
|
+
return { webhookId: raw.id, url: raw.url, events: raw.events };
|
|
247
|
+
}
|
|
248
|
+
async listWebhooks() {
|
|
249
|
+
const raw = await this.get("/webhooks");
|
|
250
|
+
return raw.map(w => ({ webhookId: w.id, url: w.url, events: w.events }));
|
|
251
|
+
}
|
|
252
|
+
async deleteWebhook(webhookId) {
|
|
253
|
+
await this.del(`/webhooks/${webhookId}`);
|
|
254
|
+
}
|
|
255
|
+
// ── Funding ─────────────────────────────────────────────────────
|
|
256
|
+
/** Create a one-time fund link via the server. Returns the dashboard URL. */
|
|
257
|
+
async createFundLink(options) {
|
|
258
|
+
const data = await this.post("/links/fund", {
|
|
259
|
+
messages: options?.messages ?? [],
|
|
260
|
+
agent_name: options?.agentName,
|
|
261
|
+
});
|
|
262
|
+
return data.url;
|
|
263
|
+
}
|
|
264
|
+
/** Create a one-time withdraw link via the server. Returns the dashboard URL. */
|
|
265
|
+
async createWithdrawLink(options) {
|
|
266
|
+
const data = await this.post("/links/withdraw", {
|
|
267
|
+
messages: options?.messages ?? [],
|
|
268
|
+
agent_name: options?.agentName,
|
|
269
|
+
});
|
|
270
|
+
return data.url;
|
|
271
|
+
}
|
|
272
|
+
// ── Permit signing ────────────────────────────────────────────
|
|
273
|
+
/**
|
|
274
|
+
* Prepare and sign a USDC EIP-2612 permit.
|
|
275
|
+
*
|
|
276
|
+
* 1. Calls GET /api/v1/permit/prepare to get the EIP-712 hash
|
|
277
|
+
* 2. Signs the hash with the agent's private key
|
|
278
|
+
* 3. Returns {nonce, deadline, v, r, s} for inclusion in payment body
|
|
279
|
+
*/
|
|
280
|
+
async prepareAndSignPermit(amount, spender) {
|
|
281
|
+
if (!this._privateKey) {
|
|
282
|
+
throw new PayValidationError("privateKey required for permit signing", "privateKey");
|
|
283
|
+
}
|
|
284
|
+
const prepare = await this.post("/permit/prepare", { amount, spender });
|
|
285
|
+
// Sign the hash
|
|
286
|
+
const hashHex = prepare.hash;
|
|
287
|
+
const raw = await viemSign({ hash: hashHex, privateKey: this._privateKey });
|
|
288
|
+
const sigHex = serializeSignature(raw);
|
|
289
|
+
// Parse signature into v, r, s
|
|
290
|
+
const sigBytes = Buffer.from(sigHex.slice(2), "hex");
|
|
291
|
+
const r = "0x" + sigBytes.subarray(0, 32).toString("hex");
|
|
292
|
+
const s = "0x" + sigBytes.subarray(32, 64).toString("hex");
|
|
293
|
+
const v = sigBytes[64];
|
|
294
|
+
return {
|
|
295
|
+
nonce: prepare.nonce,
|
|
296
|
+
deadline: prepare.deadline,
|
|
297
|
+
v,
|
|
298
|
+
r,
|
|
299
|
+
s,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
// ── Auth headers ──────────────────────────────────────────────
|
|
303
|
+
async authHeaders(method, path) {
|
|
304
|
+
if (!this._authConfig)
|
|
305
|
+
return null;
|
|
306
|
+
// Sign only the path portion (no query string) — server verifies against uri.path().
|
|
307
|
+
// e.g., basePath="/api/v1" + path="/status" → "/api/v1/status"
|
|
308
|
+
const fullPath = this._basePath + path.split("?")[0];
|
|
309
|
+
if (this._privateKey) {
|
|
310
|
+
return buildAuthHeaders(this._privateKey, method, fullPath, this._authConfig);
|
|
311
|
+
}
|
|
312
|
+
if (this.signer.address) {
|
|
313
|
+
return buildAuthHeadersWithSigner(this.signer, method, fullPath, this._authConfig);
|
|
314
|
+
}
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
// ── HTTP helpers ────────────────────────────────────────────────
|
|
318
|
+
async get(path) {
|
|
319
|
+
let resp;
|
|
320
|
+
try {
|
|
321
|
+
const auth = await this.authHeaders("GET", path);
|
|
322
|
+
resp = await fetch(`${this.apiUrl}${path}`, {
|
|
323
|
+
method: "GET",
|
|
324
|
+
headers: {
|
|
325
|
+
"Content-Type": "application/json",
|
|
326
|
+
...auth,
|
|
327
|
+
},
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
catch (e) {
|
|
331
|
+
throw new PayNetworkError(String(e));
|
|
332
|
+
}
|
|
333
|
+
return this.handleResponse(resp);
|
|
334
|
+
}
|
|
335
|
+
async post(path, payload) {
|
|
336
|
+
let resp;
|
|
337
|
+
try {
|
|
338
|
+
const auth = await this.authHeaders("POST", path);
|
|
339
|
+
resp = await fetch(`${this.apiUrl}${path}`, {
|
|
340
|
+
method: "POST",
|
|
341
|
+
headers: {
|
|
342
|
+
"Content-Type": "application/json",
|
|
343
|
+
...auth,
|
|
344
|
+
},
|
|
345
|
+
body: JSON.stringify(payload),
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
catch (e) {
|
|
349
|
+
throw new PayNetworkError(String(e));
|
|
350
|
+
}
|
|
351
|
+
return this.handleResponse(resp);
|
|
352
|
+
}
|
|
353
|
+
async del(path) {
|
|
354
|
+
let resp;
|
|
355
|
+
try {
|
|
356
|
+
const auth = await this.authHeaders("DELETE", path);
|
|
357
|
+
resp = await fetch(`${this.apiUrl}${path}`, {
|
|
358
|
+
method: "DELETE",
|
|
359
|
+
headers: {
|
|
360
|
+
"Content-Type": "application/json",
|
|
361
|
+
...auth,
|
|
362
|
+
},
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
catch (e) {
|
|
366
|
+
throw new PayNetworkError(String(e));
|
|
367
|
+
}
|
|
368
|
+
if (resp.status >= 400) {
|
|
369
|
+
const text = await resp.text();
|
|
370
|
+
throw new PayServerError(text, resp.status);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
async handleResponse(resp) {
|
|
374
|
+
if (resp.status >= 400) {
|
|
375
|
+
let msg;
|
|
376
|
+
try {
|
|
377
|
+
const body = (await resp.json());
|
|
378
|
+
msg = body.error ?? (await resp.text());
|
|
379
|
+
}
|
|
380
|
+
catch {
|
|
381
|
+
msg = await resp.text();
|
|
382
|
+
}
|
|
383
|
+
throw new PayServerError(msg, resp.status);
|
|
384
|
+
}
|
|
385
|
+
if (resp.status === 204) {
|
|
386
|
+
return undefined;
|
|
387
|
+
}
|
|
388
|
+
return (await resp.json());
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH,OAAO,EACL,eAAe,EACf,cAAc,EACd,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EACL,gBAAgB,EAChB,0BAA0B,GAG3B,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAErE,MAAM,UAAU,GAAG,qBAAqB,CAAC;AACzC,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,aAAa;AAC3C,MAAM,OAAO,GAAG,SAAS,CAAC,CAAC,aAAa;AAExC,MAAM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
|
1
|
+
/** Base error for all pay SDK errors. */
|
|
2
|
+
export declare class PayError extends Error {
|
|
3
|
+
readonly code: string;
|
|
4
|
+
constructor(message: string, code?: string);
|
|
5
|
+
}
|
|
6
|
+
/** Input validation failed. */
|
|
7
|
+
export declare class PayValidationError extends PayError {
|
|
8
|
+
readonly field?: string;
|
|
9
|
+
constructor(message: string, field?: string);
|
|
10
|
+
}
|
|
11
|
+
/** Network or server communication failed. */
|
|
12
|
+
export declare class PayNetworkError extends PayError {
|
|
13
|
+
constructor(message: string);
|
|
14
|
+
}
|
|
15
|
+
/** Server returned an error response. */
|
|
16
|
+
export declare class PayServerError extends PayError {
|
|
17
|
+
readonly statusCode: number;
|
|
18
|
+
constructor(message: string, statusCode: number);
|
|
19
|
+
}
|
|
20
|
+
/** Insufficient USDC balance. */
|
|
21
|
+
export declare class PayInsufficientFundsError extends PayError {
|
|
22
|
+
constructor(message?: string);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,qBAAa,QAAS,SAAQ,KAAK;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,OAAO,EAAE,MAAM,EAAE,IAAI,SAAc;CAKhD;AAED,+BAA+B;AAC/B,qBAAa,kBAAmB,SAAQ,QAAQ;IAC9C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;gBAEZ,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;CAK5C;AAED,8CAA8C;AAC9C,qBAAa,eAAgB,SAAQ,QAAQ;gBAC/B,OAAO,EAAE,MAAM;CAI5B;AAED,yCAAyC;AACzC,qBAAa,cAAe,SAAQ,QAAQ;IAC1C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;gBAEhB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;CAKhD;AAED,iCAAiC;AACjC,qBAAa,yBAA0B,SAAQ,QAAQ;gBACzC,OAAO,SAA8B;CAIlD"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** Base error for all pay SDK errors. */
|
|
2
|
+
export class PayError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(message, code = "pay_error") {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "PayError";
|
|
7
|
+
this.code = code;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/** Input validation failed. */
|
|
11
|
+
export class PayValidationError extends PayError {
|
|
12
|
+
field;
|
|
13
|
+
constructor(message, field) {
|
|
14
|
+
super(message, "validation_error");
|
|
15
|
+
this.name = "PayValidationError";
|
|
16
|
+
this.field = field;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Network or server communication failed. */
|
|
20
|
+
export class PayNetworkError extends PayError {
|
|
21
|
+
constructor(message) {
|
|
22
|
+
super(message, "network_error");
|
|
23
|
+
this.name = "PayNetworkError";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Server returned an error response. */
|
|
27
|
+
export class PayServerError extends PayError {
|
|
28
|
+
statusCode;
|
|
29
|
+
constructor(message, statusCode) {
|
|
30
|
+
super(message, "server_error");
|
|
31
|
+
this.name = "PayServerError";
|
|
32
|
+
this.statusCode = statusCode;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** Insufficient USDC balance. */
|
|
36
|
+
export class PayInsufficientFundsError extends PayError {
|
|
37
|
+
constructor(message = "Insufficient USDC balance") {
|
|
38
|
+
super(message, "insufficient_funds");
|
|
39
|
+
this.name = "PayInsufficientFundsError";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mapp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API_URL } from "./client.js";
|
|
2
|
+
export type { PayClientOptions } from "./client.js";
|
|
3
|
+
export { PayError, PayValidationError, PayNetworkError, PayServerError, PayInsufficientFundsError, } from "./errors.js";
|
|
4
|
+
export type { DirectPaymentResult, PaymentRequired, PaymentRequirementsV2, Tab, TabStatus, StatusResponse, WebhookRegistration, } from "./models.js";
|
|
5
|
+
export type { Signer } from "./signer.js";
|
|
6
|
+
export { CliSigner, RawKeySigner, CallbackSigner, createSigner, } from "./signer.js";
|
|
7
|
+
export { OwsSigner } from "./ows-signer.js";
|
|
8
|
+
export type { OwsSignerOptions } from "./ows-signer.js";
|
|
9
|
+
export { Wallet, PrivateKeySigner } from "./wallet.js";
|
|
10
|
+
export type { WalletOptions, FundLinkOptions, PermitResult, } from "./wallet.js";
|
|
11
|
+
export { buildAuthHeaders, buildAuthHeadersWithSigner, computeEip712Hash, } from "./auth.js";
|
|
12
|
+
export type { AuthConfig, AuthHeaders } from "./auth.js";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACzD,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,OAAO,EACL,QAAQ,EACR,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,mBAAmB,EACnB,eAAe,EACf,qBAAqB,EACrB,GAAG,EACH,SAAS,EACT,cAAc,EACd,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAErB,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EACL,SAAS,EACT,YAAY,EACZ,cAAc,EACd,YAAY,GACb,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACvD,YAAY,EACV,aAAa,EACb,eAAe,EACf,YAAY,GACb,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,iBAAiB,GAClB,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { PayClient, DEFAULT_API_URL } from "./client.js";
|
|
2
|
+
export { PayError, PayValidationError, PayNetworkError, PayServerError, PayInsufficientFundsError, } from "./errors.js";
|
|
3
|
+
export { CliSigner, RawKeySigner, CallbackSigner, createSigner, } from "./signer.js";
|
|
4
|
+
export { OwsSigner } from "./ows-signer.js";
|
|
5
|
+
export { Wallet, PrivateKeySigner } from "./wallet.js";
|
|
6
|
+
export { buildAuthHeaders, buildAuthHeadersWithSigner, computeEip712Hash, } from "./auth.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGzD,OAAO,EACL,QAAQ,EACR,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AAarB,OAAO,EACL,SAAS,EACT,YAAY,EACZ,cAAc,EACd,YAAY,GACb,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAOvD,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,iBAAiB,GAClB,MAAM,WAAW,CAAC"}
|
package/dist/models.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** Tab lifecycle states. */
|
|
2
|
+
export type TabStatus = "open" | "closed";
|
|
3
|
+
/** Result of a direct payment. */
|
|
4
|
+
export interface DirectPaymentResult {
|
|
5
|
+
txHash: string;
|
|
6
|
+
status: string;
|
|
7
|
+
/** Amount in USDC micro-units (6 decimals). */
|
|
8
|
+
amount: number;
|
|
9
|
+
/** Fee deducted in USDC micro-units. */
|
|
10
|
+
fee: number;
|
|
11
|
+
}
|
|
12
|
+
/** Tab state. */
|
|
13
|
+
export interface Tab {
|
|
14
|
+
tabId: string;
|
|
15
|
+
provider: string;
|
|
16
|
+
/** Total locked amount in USDC micro-units. */
|
|
17
|
+
amount: number;
|
|
18
|
+
/** Remaining balance in USDC micro-units. */
|
|
19
|
+
balanceRemaining: number;
|
|
20
|
+
/** Total charged so far in USDC micro-units. */
|
|
21
|
+
totalCharged: number;
|
|
22
|
+
/** Number of charges made. */
|
|
23
|
+
chargeCount: number;
|
|
24
|
+
/** Max per-charge limit in USDC micro-units. */
|
|
25
|
+
maxChargePerCall: number;
|
|
26
|
+
/** Total withdrawn so far in USDC micro-units. */
|
|
27
|
+
totalWithdrawn: number;
|
|
28
|
+
status: TabStatus;
|
|
29
|
+
}
|
|
30
|
+
/** Wallet status. */
|
|
31
|
+
export interface StatusResponse {
|
|
32
|
+
address: string;
|
|
33
|
+
/** USDC balance in micro-units. */
|
|
34
|
+
balance: number;
|
|
35
|
+
openTabs: Tab[];
|
|
36
|
+
}
|
|
37
|
+
/** Registered webhook. */
|
|
38
|
+
export interface WebhookRegistration {
|
|
39
|
+
webhookId: string;
|
|
40
|
+
url: string;
|
|
41
|
+
events: string[];
|
|
42
|
+
}
|
|
43
|
+
/** A single payment option in a v2 402 response. */
|
|
44
|
+
export interface PaymentRequirementsV2 {
|
|
45
|
+
scheme: string;
|
|
46
|
+
network: string;
|
|
47
|
+
amount: string;
|
|
48
|
+
asset: string;
|
|
49
|
+
payTo: string;
|
|
50
|
+
maxTimeoutSeconds: number;
|
|
51
|
+
extra?: {
|
|
52
|
+
name?: string;
|
|
53
|
+
version?: string;
|
|
54
|
+
facilitator?: string;
|
|
55
|
+
settlement?: string;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Top-level v2 PAYMENT-REQUIRED header (base64-encoded). */
|
|
59
|
+
export interface PaymentRequired {
|
|
60
|
+
x402Version: number;
|
|
61
|
+
resource: {
|
|
62
|
+
url: string;
|
|
63
|
+
description?: string;
|
|
64
|
+
mimeType?: string;
|
|
65
|
+
};
|
|
66
|
+
accepts: PaymentRequirementsV2[];
|
|
67
|
+
extensions: Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE1C,kCAAkC;AAClC,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,iBAAiB;AACjB,MAAM,WAAW,GAAG;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,6CAA6C;IAC7C,gBAAgB,EAAE,MAAM,CAAC;IACzB,gDAAgD;IAChD,YAAY,EAAE,MAAM,CAAC;IACrB,8BAA8B;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,gDAAgD;IAChD,gBAAgB,EAAE,MAAM,CAAC;IACzB,kDAAkD;IAClD,cAAc,EAA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