@trust402/sdk 0.3.1 → 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 +11 -11
- package/LICENSE +0 -80
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;AAEx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CAAC"}
|
|
@@ -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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trust402/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,11 +24,17 @@
|
|
|
24
24
|
"publishConfig": {
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc -p tsconfig.json",
|
|
29
|
+
"type-check": "tsc -p tsconfig.json --noEmit",
|
|
30
|
+
"lint": "eslint 'src/**/*.ts'",
|
|
31
|
+
"test": "vitest run"
|
|
32
|
+
},
|
|
27
33
|
"dependencies": {
|
|
34
|
+
"@lemmaoracle/sdk": "^0.0.37",
|
|
35
|
+
"@lemmaoracle/spec": "^0.0.36",
|
|
28
36
|
"@noble/hashes": "^1.7.0",
|
|
29
|
-
"poseidon-lite": "^0.2.0"
|
|
30
|
-
"@lemmaoracle/sdk": "0.0.36",
|
|
31
|
-
"@lemmaoracle/spec": "0.0.35"
|
|
37
|
+
"poseidon-lite": "^0.2.0"
|
|
32
38
|
},
|
|
33
39
|
"devDependencies": {
|
|
34
40
|
"@typescript-eslint/eslint-plugin": "^8.56.1",
|
|
@@ -38,11 +44,5 @@
|
|
|
38
44
|
"eslint-plugin-functional": "^9.0.4",
|
|
39
45
|
"typescript": "^5.5.0",
|
|
40
46
|
"vitest": "^2.1.0"
|
|
41
|
-
},
|
|
42
|
-
"scripts": {
|
|
43
|
-
"build": "tsc -p tsconfig.json",
|
|
44
|
-
"type-check": "tsc -p tsconfig.json --noEmit",
|
|
45
|
-
"lint": "eslint 'src/**/*.ts'",
|
|
46
|
-
"test": "vitest run"
|
|
47
47
|
}
|
|
48
|
-
}
|
|
48
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
Business Source License 1.1
|
|
2
|
-
|
|
3
|
-
License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.
|
|
4
|
-
"Business Source License" is a trademark of MariaDB Corporation Ab.
|
|
5
|
-
|
|
6
|
-
Parameters
|
|
7
|
-
|
|
8
|
-
Licensor: FRAME00 Inc.
|
|
9
|
-
Additional Use Grant: You may use the Licensed Work for non-production
|
|
10
|
-
purposes, including but not limited to evaluation,
|
|
11
|
-
testing, research, and learning, including in
|
|
12
|
-
hackathons, academic settings, and personal projects,
|
|
13
|
-
provided that such use does not constitute a
|
|
14
|
-
competing commercial service.
|
|
15
|
-
Licensed Work: lemmaoracle/lemma
|
|
16
|
-
(the software in this repository, excluding packages
|
|
17
|
-
that contain their own LICENSE file)
|
|
18
|
-
Change Date: 2030-05-01
|
|
19
|
-
|
|
20
|
-
Change License: Apache License, Version 2.0
|
|
21
|
-
|
|
22
|
-
Notice:
|
|
23
|
-
|
|
24
|
-
The Licensed Work is provided under the Business Source License 1.1
|
|
25
|
-
(BSL 1.1). You may not use the Licensed Work except in compliance with
|
|
26
|
-
the BSL 1.1.
|
|
27
|
-
|
|
28
|
-
You may produce and distribute the Licensed Work, in whole or in part,
|
|
29
|
-
in Source or Object form, subject to the following conditions:
|
|
30
|
-
|
|
31
|
-
1. You must give any other recipients of the Licensed Work a copy of
|
|
32
|
-
this License; and
|
|
33
|
-
|
|
34
|
-
2. You must cause any modified files to carry prominent notices stating
|
|
35
|
-
that You changed the files; and
|
|
36
|
-
|
|
37
|
-
3. You must retain, in the Source form of any Licensed Work that You
|
|
38
|
-
distribute, all copyright, patent, trademark, and attribution
|
|
39
|
-
notices from the Source form of the Licensed Work, excluding those
|
|
40
|
-
notices that do not pertain to any part of the Licensed Work; and
|
|
41
|
-
|
|
42
|
-
4. You may not use the Licensed Work to create a competing commercial
|
|
43
|
-
service. A "competing commercial service" is a product or service
|
|
44
|
-
that provides substantially the same functionality as the Licensed
|
|
45
|
-
Work to third parties for commercial gain.
|
|
46
|
-
|
|
47
|
-
5. After the Change Date, the Licensed Work will be licensed under the
|
|
48
|
-
Change License indicated above, and You may exercise the rights
|
|
49
|
-
granted under the Change License without restriction.
|
|
50
|
-
|
|
51
|
-
THE LICENSED WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
52
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
53
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
54
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
55
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
56
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
57
|
-
LICENSED WORK OR THE USE OR OTHER DEALINGS IN THE LICENSED WORK.
|
|
58
|
-
|
|
59
|
-
---
|
|
60
|
-
|
|
61
|
-
This repository contains multiple packages under the `packages/` directory.
|
|
62
|
-
Each package may have its own LICENSE file. If a package contains its own
|
|
63
|
-
LICENSE file, that license takes precedence over this root LICENSE for the
|
|
64
|
-
contents of that package directory.
|
|
65
|
-
|
|
66
|
-
Package-specific licenses:
|
|
67
|
-
|
|
68
|
-
BUSL-1.1 (this license, with the same Change Date and Change License):
|
|
69
|
-
- packages/contracts
|
|
70
|
-
- packages/relay
|
|
71
|
-
- packages/passthrough
|
|
72
|
-
|
|
73
|
-
Apache-2.0:
|
|
74
|
-
- packages/sdk
|
|
75
|
-
- packages/spec
|
|
76
|
-
- packages/mcp
|
|
77
|
-
- packages/parser
|
|
78
|
-
- packages/x402
|
|
79
|
-
|
|
80
|
-
(packages/web is private and not distributed; all rights reserved.)
|