@trust402/sdk 0.3.2 → 0.4.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/dist/create.d.ts +15 -0
- package/dist/create.d.ts.map +1 -0
- package/dist/create.js +18 -0
- package/dist/create.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/pay-fetch.d.ts +26 -0
- package/dist/pay-fetch.d.ts.map +1 -0
- package/dist/pay-fetch.js +189 -0
- package/dist/pay-fetch.js.map +1 -0
- package/dist/pay-types.d.ts +38 -0
- package/dist/pay-types.d.ts.map +1 -0
- package/dist/pay-types.js +7 -0
- package/dist/pay-types.js.map +1 -0
- package/package.json +1 -1
package/dist/create.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LemmaClient, LemmaClientConfig } from "@lemmaoracle/spec";
|
|
2
|
+
import type { Signer } from "./pay-fetch.js";
|
|
3
|
+
export type ClientConfig = LemmaClientConfig & Readonly<{
|
|
4
|
+
/** EIP-1193 signer provider (browser wallet or viem WalletClient). */
|
|
5
|
+
getSigner?: () => Promise<Signer>;
|
|
6
|
+
/** Called when a 402 payment is initiated. */
|
|
7
|
+
onPayment?: (info: Readonly<{
|
|
8
|
+
amount: string;
|
|
9
|
+
resource: string;
|
|
10
|
+
}>) => void;
|
|
11
|
+
/** Max payment in micro-USDC the fetcher will accept (default 5000 = $0.005). */
|
|
12
|
+
maxAmountMicroUsdc?: number;
|
|
13
|
+
}>;
|
|
14
|
+
export declare const create: (config: ClientConfig) => LemmaClient;
|
|
15
|
+
//# sourceMappingURL=create.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAG7C,MAAM,MAAM,YAAY,GAAG,iBAAiB,GAC1C,QAAQ,CAAC;IACP,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,8CAA8C;IAC9C,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,KAAK,IAAI,CAAC;IAC3E,iFAAiF;IACjF,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC,CAAC;AAIL,eAAO,MAAM,MAAM,GAAI,QAAQ,YAAY,KAAG,WAkB7C,CAAC"}
|
package/dist/create.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trust402 client factory — wraps @lemmaoracle/sdk's create() with:
|
|
3
|
+
* - default apiBase = https://trust402.lemma.workers.dev
|
|
4
|
+
* - automatic x402 payment handling when getSigner is provided
|
|
5
|
+
*
|
|
6
|
+
* When getSigner is omitted, the client uses plain fetch (no x402).
|
|
7
|
+
*/
|
|
8
|
+
import { create as lemmaCreate } from "@lemmaoracle/sdk";
|
|
9
|
+
import { payFetch } from "./pay-fetch.js";
|
|
10
|
+
const DEFAULT_API_BASE = "https://trust402.lemma.workers.dev";
|
|
11
|
+
export const create = (config) => {
|
|
12
|
+
const { getSigner, onPayment, maxAmountMicroUsdc, apiBase, ...rest } = config;
|
|
13
|
+
const fetcher = getSigner !== undefined
|
|
14
|
+
? payFetch({ getSigner, onPayment, maxAmountMicroUsdc })
|
|
15
|
+
: undefined;
|
|
16
|
+
return lemmaCreate({ ...rest, apiBase: apiBase ?? DEFAULT_API_BASE }, fetcher);
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,MAAM,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGzD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAY1C,MAAM,gBAAgB,GAAG,oCAAoC,CAAC;AAE9D,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,MAAoB,EAAe,EAAE;IAC1D,MAAM,EACJ,SAAS,EACT,SAAS,EACT,kBAAkB,EAClB,OAAO,EACP,GAAG,IAAI,EACR,GAAG,MAAM,CAAC;IAEX,MAAM,OAAO,GACX,SAAS,KAAK,SAAS;QACrB,CAAC,CAAC,QAAQ,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC;QACxD,CAAC,CAAC,SAAS,CAAC;IAEhB,OAAO,WAAW,CAChB,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,EACjD,OAAO,CACR,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type Eip1193Provider = Readonly<{
|
|
2
|
+
request: (args: Readonly<{
|
|
3
|
+
method: string;
|
|
4
|
+
params?: readonly unknown[];
|
|
5
|
+
}>) => Promise<unknown>;
|
|
6
|
+
}>;
|
|
7
|
+
export type Signer = Readonly<{
|
|
8
|
+
provider: Eip1193Provider;
|
|
9
|
+
address: string;
|
|
10
|
+
}>;
|
|
11
|
+
export type PayFetchOptions = Readonly<{
|
|
12
|
+
getSigner: () => Promise<Signer>;
|
|
13
|
+
maxAmountMicroUsdc?: number;
|
|
14
|
+
onPayment?: (info: Readonly<{
|
|
15
|
+
amount: string;
|
|
16
|
+
resource: string;
|
|
17
|
+
}>) => void;
|
|
18
|
+
}>;
|
|
19
|
+
export type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
20
|
+
/**
|
|
21
|
+
* Wrap fetch with x402 payment handling: on a 402 challenge that passes all
|
|
22
|
+
* guardrails, sign an EIP-3009 TransferWithAuthorization and retry exactly
|
|
23
|
+
* once with the X-PAYMENT header. Anything else passes through untouched.
|
|
24
|
+
*/
|
|
25
|
+
export declare const payFetch: (options: PayFetchOptions) => FetchLike;
|
|
26
|
+
//# sourceMappingURL=pay-fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pay-fetch.d.ts","sourceRoot":"","sources":["../src/pay-fetch.ts"],"names":[],"mappings":"AAmDA,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;IACrC,OAAO,EAAE,CACP,IAAI,EAAE,QAAQ,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,CAAA;KAAE,CAAC,KAC5D,OAAO,CAAC,OAAO,CAAC,CAAC;CACvB,CAAC,CAAC;AAEH,MAAM,MAAM,MAAM,GAAG,QAAQ,CAAC;IAAE,QAAQ,EAAE,eAAe,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAE9E,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;IACrC,SAAS,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IACjC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,KAAK,IAAI,CAAC;CAC5E,CAAC,CAAC;AAEH,MAAM,MAAM,SAAS,GAAG,CACtB,KAAK,EAAE,WAAW,GAAG,GAAG,EACxB,IAAI,CAAC,EAAE,WAAW,KACf,OAAO,CAAC,QAAQ,CAAC,CAAC;AA+IvB;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAI,SAAS,eAAe,KAAG,SA8DjD,CAAC"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/* ------------------------------------------------------------------ */
|
|
2
|
+
/* Constants */
|
|
3
|
+
/* ------------------------------------------------------------------ */
|
|
4
|
+
const USDC_ADDRESSES = Object.freeze({
|
|
5
|
+
"base-sepolia": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
|
|
6
|
+
base: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
7
|
+
});
|
|
8
|
+
const X402_CHAIN_IDS = Object.freeze({
|
|
9
|
+
"base-sepolia": 84532,
|
|
10
|
+
base: 8453,
|
|
11
|
+
});
|
|
12
|
+
const DEFAULT_MAX_AMOUNT_MICRO_USDC = 5000;
|
|
13
|
+
const CHAIN_METADATA = Object.freeze({
|
|
14
|
+
"base-sepolia": {
|
|
15
|
+
chainName: "Base Sepolia",
|
|
16
|
+
nativeCurrency: { name: "Sepolia Ether", symbol: "ETH", decimals: 18 },
|
|
17
|
+
rpcUrls: ["https://sepolia.base.org"],
|
|
18
|
+
blockExplorerUrls: ["https://sepolia.basescan.org"],
|
|
19
|
+
},
|
|
20
|
+
base: {
|
|
21
|
+
chainName: "Base",
|
|
22
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
23
|
+
rpcUrls: ["https://mainnet.base.org"],
|
|
24
|
+
blockExplorerUrls: ["https://basescan.org"],
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
/* ------------------------------------------------------------------ */
|
|
28
|
+
/* Helpers */
|
|
29
|
+
/* ------------------------------------------------------------------ */
|
|
30
|
+
const requestUrl = (input) => {
|
|
31
|
+
const raw = typeof input === "string"
|
|
32
|
+
? input
|
|
33
|
+
: input instanceof URL
|
|
34
|
+
? input.href
|
|
35
|
+
: input.url;
|
|
36
|
+
try {
|
|
37
|
+
return new URL(raw, typeof location !== "undefined" ? location.href : undefined);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const requestMethod = (input, init) => {
|
|
44
|
+
const method = init?.method ??
|
|
45
|
+
(typeof Request !== "undefined" && input instanceof Request
|
|
46
|
+
? input.method
|
|
47
|
+
: "GET");
|
|
48
|
+
return method.toUpperCase();
|
|
49
|
+
};
|
|
50
|
+
/** Requirements come from the X-PAYMENT-REQUIREMENTS header, falling back to the body's accepts. */
|
|
51
|
+
const parseRequirements = async (res) => {
|
|
52
|
+
const header = res.headers.get("X-PAYMENT-REQUIREMENTS");
|
|
53
|
+
if (header !== null) {
|
|
54
|
+
try {
|
|
55
|
+
return JSON.parse(header);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// fall through to the body
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const body = (await res.clone().json());
|
|
63
|
+
return body.accepts?.find((r) => r.scheme === "exact") ?? null;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const isKnownNetwork = (network) => network in X402_CHAIN_IDS;
|
|
70
|
+
const isPayable = (url, method, body, reqs, maxAmountMicroUsdc) => typeof location !== "undefined" &&
|
|
71
|
+
url.origin === location.origin &&
|
|
72
|
+
url.pathname.startsWith("/v1/") &&
|
|
73
|
+
method === "POST" &&
|
|
74
|
+
(body === undefined || typeof body === "string") &&
|
|
75
|
+
Number(reqs.maxAmountRequired) <= maxAmountMicroUsdc &&
|
|
76
|
+
isKnownNetwork(reqs.network) &&
|
|
77
|
+
reqs.asset === USDC_ADDRESSES[reqs.network] &&
|
|
78
|
+
Boolean(reqs.extra?.name) &&
|
|
79
|
+
Boolean(reqs.extra?.version);
|
|
80
|
+
const randomNonce = () => {
|
|
81
|
+
const bytes = new Uint8Array(32);
|
|
82
|
+
crypto.getRandomValues(bytes);
|
|
83
|
+
return `0x${Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("")}`;
|
|
84
|
+
};
|
|
85
|
+
const ensureChain = async (provider, network) => {
|
|
86
|
+
const chainId = `0x${X402_CHAIN_IDS[network].toString(16)}`;
|
|
87
|
+
try {
|
|
88
|
+
await provider.request({
|
|
89
|
+
method: "wallet_switchEthereumChain",
|
|
90
|
+
params: [{ chainId }],
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
const code = e?.code;
|
|
95
|
+
if (code === 4902 || code === -32603) {
|
|
96
|
+
const meta = CHAIN_METADATA[network];
|
|
97
|
+
await provider.request({
|
|
98
|
+
method: "wallet_addEthereumChain",
|
|
99
|
+
params: [{ chainId, ...meta }],
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
throw e;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const transferWithAuthorizationTypedData = (reqs, network, authorization) => ({
|
|
108
|
+
types: {
|
|
109
|
+
EIP712Domain: [
|
|
110
|
+
{ name: "name", type: "string" },
|
|
111
|
+
{ name: "version", type: "string" },
|
|
112
|
+
{ name: "chainId", type: "uint256" },
|
|
113
|
+
{ name: "verifyingContract", type: "address" },
|
|
114
|
+
],
|
|
115
|
+
TransferWithAuthorization: [
|
|
116
|
+
{ name: "from", type: "address" },
|
|
117
|
+
{ name: "to", type: "address" },
|
|
118
|
+
{ name: "value", type: "uint256" },
|
|
119
|
+
{ name: "validAfter", type: "uint256" },
|
|
120
|
+
{ name: "validBefore", type: "uint256" },
|
|
121
|
+
{ name: "nonce", type: "bytes32" },
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
primaryType: "TransferWithAuthorization",
|
|
125
|
+
domain: {
|
|
126
|
+
name: reqs.extra.name,
|
|
127
|
+
version: reqs.extra.version,
|
|
128
|
+
chainId: X402_CHAIN_IDS[network],
|
|
129
|
+
verifyingContract: reqs.asset,
|
|
130
|
+
},
|
|
131
|
+
message: { ...authorization },
|
|
132
|
+
});
|
|
133
|
+
/* ------------------------------------------------------------------ */
|
|
134
|
+
/* payFetch */
|
|
135
|
+
/* ------------------------------------------------------------------ */
|
|
136
|
+
/**
|
|
137
|
+
* Wrap fetch with x402 payment handling: on a 402 challenge that passes all
|
|
138
|
+
* guardrails, sign an EIP-3009 TransferWithAuthorization and retry exactly
|
|
139
|
+
* once with the X-PAYMENT header. Anything else passes through untouched.
|
|
140
|
+
*/
|
|
141
|
+
export const payFetch = (options) => async (input, init) => {
|
|
142
|
+
const res = await fetch(input, init);
|
|
143
|
+
if (res.status !== 402)
|
|
144
|
+
return res;
|
|
145
|
+
const url = requestUrl(input);
|
|
146
|
+
if (url === null)
|
|
147
|
+
return res;
|
|
148
|
+
const reqs = await parseRequirements(res);
|
|
149
|
+
if (reqs === null)
|
|
150
|
+
return res;
|
|
151
|
+
const maxAmount = options.maxAmountMicroUsdc ?? DEFAULT_MAX_AMOUNT_MICRO_USDC;
|
|
152
|
+
if (!isPayable(url, requestMethod(input, init), init?.body, reqs, maxAmount)) {
|
|
153
|
+
return res;
|
|
154
|
+
}
|
|
155
|
+
const network = reqs.network;
|
|
156
|
+
options.onPayment?.({
|
|
157
|
+
amount: reqs.maxAmountRequired,
|
|
158
|
+
resource: reqs.resource,
|
|
159
|
+
});
|
|
160
|
+
const signer = await options.getSigner();
|
|
161
|
+
await ensureChain(signer.provider, network);
|
|
162
|
+
// Re-resolve signer after chain switch — wallet providers (MetaMask)
|
|
163
|
+
// may reset internal state during network transitions, making the
|
|
164
|
+
// pre-switch provider reference stale for eth_signTypedData_v4.
|
|
165
|
+
const freshSigner = await options.getSigner();
|
|
166
|
+
const authorization = {
|
|
167
|
+
from: freshSigner.address,
|
|
168
|
+
to: reqs.payTo,
|
|
169
|
+
value: reqs.maxAmountRequired,
|
|
170
|
+
validAfter: "0",
|
|
171
|
+
validBefore: String(Math.floor(Date.now() / 1000) + reqs.maxTimeoutSeconds),
|
|
172
|
+
nonce: randomNonce(),
|
|
173
|
+
};
|
|
174
|
+
const typedData = transferWithAuthorizationTypedData(reqs, network, authorization);
|
|
175
|
+
const signature = String(await freshSigner.provider.request({
|
|
176
|
+
method: "eth_signTypedData_v4",
|
|
177
|
+
params: [freshSigner.address, JSON.stringify(typedData)],
|
|
178
|
+
}));
|
|
179
|
+
const payment = {
|
|
180
|
+
x402Version: 1,
|
|
181
|
+
scheme: "exact",
|
|
182
|
+
network,
|
|
183
|
+
payload: { signature, authorization },
|
|
184
|
+
};
|
|
185
|
+
const headers = new Headers(init?.headers);
|
|
186
|
+
headers.set("X-PAYMENT", btoa(JSON.stringify(payment)));
|
|
187
|
+
return fetch(input, { ...init, headers });
|
|
188
|
+
};
|
|
189
|
+
//# sourceMappingURL=pay-fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pay-fetch.js","sourceRoot":"","sources":["../src/pay-fetch.ts"],"names":[],"mappings":"AAcA,wEAAwE;AACxE,yEAAyE;AACzE,wEAAwE;AAExE,MAAM,cAAc,GA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-0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* x402 payment types — inlined to avoid a dependency on @lemmaoracle/workers-shared.
|
|
3
|
+
* Server-side x402 gate logic (facilitator, settle/verify) lives in workers-shared;
|
|
4
|
+
* the SDK only needs the client-side types for signing payments.
|
|
5
|
+
*/
|
|
6
|
+
export type X402Network = "base-sepolia" | "base";
|
|
7
|
+
export type Eip712Domain = Readonly<{
|
|
8
|
+
name: string;
|
|
9
|
+
version: string;
|
|
10
|
+
}>;
|
|
11
|
+
export type ExactEvmAuthorization = Readonly<{
|
|
12
|
+
from: string;
|
|
13
|
+
to: string;
|
|
14
|
+
value: string;
|
|
15
|
+
validAfter: string;
|
|
16
|
+
validBefore: string;
|
|
17
|
+
nonce: string;
|
|
18
|
+
}>;
|
|
19
|
+
export type PaymentPayload = Readonly<{
|
|
20
|
+
x402Version: number;
|
|
21
|
+
scheme: string;
|
|
22
|
+
network: X402Network | string;
|
|
23
|
+
payload: Readonly<Record<string, unknown>>;
|
|
24
|
+
}>;
|
|
25
|
+
/** x402 v1 requirements (used by x402.org facilitator). */
|
|
26
|
+
export type PaymentRequirements = Readonly<{
|
|
27
|
+
scheme: string;
|
|
28
|
+
network: X402Network;
|
|
29
|
+
maxAmountRequired: string;
|
|
30
|
+
payTo: string;
|
|
31
|
+
asset: string;
|
|
32
|
+
resource: string;
|
|
33
|
+
description: string;
|
|
34
|
+
mimeType: string;
|
|
35
|
+
maxTimeoutSeconds: number;
|
|
36
|
+
extra?: Eip712Domain;
|
|
37
|
+
}>;
|
|
38
|
+
//# sourceMappingURL=pay-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pay-types.d.ts","sourceRoot":"","sources":["../src/pay-types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,WAAW,GAAG,cAAc,GAAG,MAAM,CAAC;AAElD,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CAAC;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,WAAW,GAAG,MAAM,CAAC;IAC9B,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC5C,CAAC,CAAC;AAEH,2DAA2D;AAC3D,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,WAAW,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* x402 payment types — inlined to avoid a dependency on @lemmaoracle/workers-shared.
|
|
3
|
+
* Server-side x402 gate logic (facilitator, settle/verify) lives in workers-shared;
|
|
4
|
+
* the SDK only needs the client-side types for signing payments.
|
|
5
|
+
*/
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=pay-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pay-types.js","sourceRoot":"","sources":["../src/pay-types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|