mrmainspring 0.1.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.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +47 -0
  3. package/dist/audit/service.d.ts +7 -0
  4. package/dist/audit/service.js +98 -0
  5. package/dist/audit/store.d.ts +7 -0
  6. package/dist/audit/store.js +37 -0
  7. package/dist/audit/supabase-store.d.ts +9 -0
  8. package/dist/audit/supabase-store.js +22 -0
  9. package/dist/audit/types.d.ts +31 -0
  10. package/dist/audit/types.js +1 -0
  11. package/dist/casper/anchorClient.d.ts +99 -0
  12. package/dist/casper/anchorClient.js +412 -0
  13. package/dist/config.d.ts +51 -0
  14. package/dist/config.js +215 -0
  15. package/dist/env-file.d.ts +1 -0
  16. package/dist/env-file.js +51 -0
  17. package/dist/grimoire/service.d.ts +13 -0
  18. package/dist/grimoire/service.js +199 -0
  19. package/dist/grimoire/store.d.ts +10 -0
  20. package/dist/grimoire/store.js +64 -0
  21. package/dist/grimoire/supabase-store.d.ts +13 -0
  22. package/dist/grimoire/supabase-store.js +50 -0
  23. package/dist/grimoire/types.d.ts +60 -0
  24. package/dist/grimoire/types.js +1 -0
  25. package/dist/index.d.ts +2 -0
  26. package/dist/index.js +17 -0
  27. package/dist/mcp/auditTools.d.ts +3 -0
  28. package/dist/mcp/auditTools.js +13 -0
  29. package/dist/mcp/grimoireTools.d.ts +3 -0
  30. package/dist/mcp/grimoireTools.js +91 -0
  31. package/dist/mcp/jsonResult.d.ts +2 -0
  32. package/dist/mcp/jsonResult.js +10 -0
  33. package/dist/mcp/memoryTools.d.ts +3 -0
  34. package/dist/mcp/memoryTools.js +73 -0
  35. package/dist/mcp/paymentTools.d.ts +3 -0
  36. package/dist/mcp/paymentTools.js +33 -0
  37. package/dist/memory/canonical.d.ts +4 -0
  38. package/dist/memory/canonical.js +49 -0
  39. package/dist/memory/hash.d.ts +1 -0
  40. package/dist/memory/hash.js +4 -0
  41. package/dist/memory/service.d.ts +37 -0
  42. package/dist/memory/service.js +175 -0
  43. package/dist/memory/store.d.ts +8 -0
  44. package/dist/memory/store.js +49 -0
  45. package/dist/memory/supabase-store.d.ts +10 -0
  46. package/dist/memory/supabase-store.js +30 -0
  47. package/dist/memory/types.d.ts +56 -0
  48. package/dist/memory/types.js +7 -0
  49. package/dist/payments/service.d.ts +26 -0
  50. package/dist/payments/service.js +613 -0
  51. package/dist/payments/store.d.ts +10 -0
  52. package/dist/payments/store.js +64 -0
  53. package/dist/payments/supabase-store.d.ts +13 -0
  54. package/dist/payments/supabase-store.js +51 -0
  55. package/dist/payments/types.d.ts +101 -0
  56. package/dist/payments/types.js +1 -0
  57. package/dist/server.d.ts +5 -0
  58. package/dist/server.js +68 -0
  59. package/dist/storage/json-file-store.d.ts +17 -0
  60. package/dist/storage/json-file-store.js +87 -0
  61. package/dist/storage/store-factory.d.ts +12 -0
  62. package/dist/storage/store-factory.js +26 -0
  63. package/dist/storage/supabase-rest.d.ts +26 -0
  64. package/dist/storage/supabase-rest.js +85 -0
  65. package/dist/x402/client.d.ts +44 -0
  66. package/dist/x402/client.js +95 -0
  67. package/dist/x402/facilitator.d.ts +84 -0
  68. package/dist/x402/facilitator.js +800 -0
  69. package/dist/x402/readiness.d.ts +55 -0
  70. package/dist/x402/readiness.js +433 -0
  71. package/dist/x402/redaction.d.ts +1 -0
  72. package/dist/x402/redaction.js +30 -0
  73. package/dist/x402/resource.d.ts +69 -0
  74. package/dist/x402/resource.js +325 -0
  75. package/dist/x402/settlement.d.ts +176 -0
  76. package/dist/x402/settlement.js +1210 -0
  77. package/dist/x402/signer.d.ts +71 -0
  78. package/dist/x402/signer.js +616 -0
  79. package/package.json +61 -0
@@ -0,0 +1,325 @@
1
+ import { createServer } from "node:http";
2
+ import { canonicalizeJson, toJsonObject } from "../memory/canonical.js";
3
+ import { sha256Hex } from "../memory/hash.js";
4
+ import { verifyX402SettlementResponse } from "./readiness.js";
5
+ const DEFAULT_PAYMENT_HEADER_NAME = "PAYMENT-SIGNATURE";
6
+ const MAX_SIGNATURE_HEADER_BYTES = 64 * 1024;
7
+ export class InMemoryX402PaidResourceReplayStore {
8
+ records = new Map();
9
+ reserve(input) {
10
+ const existing = this.records.get(input.replayKey);
11
+ if (!existing) {
12
+ this.records.set(input.replayKey, replayRecord(input, "settling"));
13
+ return { ok: true };
14
+ }
15
+ return {
16
+ ok: false,
17
+ reason: existing.state === "settling"
18
+ ? "payment_settlement_in_progress"
19
+ : existing.payloadHash === input.payloadHash
20
+ ? "payment_payload_replayed"
21
+ : "nonce_replayed"
22
+ };
23
+ }
24
+ complete(input) {
25
+ this.records.set(input.replayKey, replayRecord(input, "settled"));
26
+ }
27
+ release(input) {
28
+ const existing = this.records.get(input.replayKey);
29
+ if (existing?.payloadHash === input.payloadHash && existing.state === "settling") {
30
+ this.records.delete(input.replayKey);
31
+ }
32
+ }
33
+ }
34
+ export function createX402PaidResourceHttpServer(config) {
35
+ const paymentHeaderName = config.paymentHeaderName ?? DEFAULT_PAYMENT_HEADER_NAME;
36
+ const postJson = config.postJson ?? postJsonWithFetch;
37
+ const replayStore = config.replayStore ?? new InMemoryX402PaidResourceReplayStore();
38
+ return createServer(async (request, response) => {
39
+ try {
40
+ await handleX402PaidResourceRequest(request, response, {
41
+ ...config,
42
+ paymentHeaderName,
43
+ postJson,
44
+ replayStore
45
+ });
46
+ }
47
+ catch (error) {
48
+ config.logger?.error?.(`x402 paid resource failed: ${errorMessage(error)}`);
49
+ sendJson(response, 500, { error: "resource_failed" });
50
+ }
51
+ });
52
+ }
53
+ async function handleX402PaidResourceRequest(request, response, config) {
54
+ const pathname = new URL(request.url ?? "/", "http://127.0.0.1").pathname;
55
+ if (request.method !== "GET" || pathname !== config.resourcePath) {
56
+ sendJson(response, 404, { error: "not_found" });
57
+ return;
58
+ }
59
+ const paymentHeader = headerValue(request, config.paymentHeaderName);
60
+ if (!paymentHeader) {
61
+ sendPaymentRequired(response, config.paymentRequirements);
62
+ return;
63
+ }
64
+ if (Buffer.byteLength(paymentHeader, "utf8") > MAX_SIGNATURE_HEADER_BYTES) {
65
+ sendPaymentRequired(response, config.paymentRequirements, {
66
+ error: "payment_signature_too_large"
67
+ });
68
+ return;
69
+ }
70
+ const paymentPayload = parsePaymentHeader(paymentHeader);
71
+ if (!paymentPayload) {
72
+ sendPaymentRequired(response, config.paymentRequirements, {
73
+ error: "invalid_payment_signature"
74
+ });
75
+ return;
76
+ }
77
+ const payloadHash = sha256Hex(canonicalizeJson(paymentPayload));
78
+ const replayKey = replayKeyForPayload(paymentPayload, payloadHash);
79
+ const selectedRequirement = selectedRequirementForPayload(config.paymentRequirements, paymentPayload);
80
+ if (!selectedRequirement) {
81
+ config.logger?.error?.("x402 paid resource could not match selected requirement");
82
+ sendJson(response, 500, { error: "payment_requirement_mismatch" });
83
+ return;
84
+ }
85
+ const replayReservation = config.replayStore?.reserve({ replayKey, payloadHash });
86
+ if (replayReservation && !replayReservation.ok) {
87
+ config.logger?.warn?.(`x402 paid resource replay rejected reason=${replayReservation.reason} payload_hash=${payloadHash}`);
88
+ sendJson(response, 409, {
89
+ error: "payment_replayed",
90
+ reason: replayReservation.reason,
91
+ payload_hash: payloadHash
92
+ });
93
+ return;
94
+ }
95
+ const facilitatorRequest = {
96
+ paymentPayload,
97
+ paymentRequirements: config.paymentRequirements
98
+ };
99
+ const verify = await postFacilitator(config, "verify", facilitatorRequest);
100
+ if (!verify.ok || !facilitatorVerifyAccepted(verify.body)) {
101
+ config.replayStore?.release({ replayKey, payloadHash });
102
+ config.logger?.warn?.(`x402 paid resource rejected verify status=${verify.status} reason=${facilitatorReason(verify.body)}`);
103
+ sendPaymentRequired(response, config.paymentRequirements, {
104
+ error: "payment_verify_failed",
105
+ reason: facilitatorReason(verify.body),
106
+ facilitator_status: verify.status
107
+ });
108
+ return;
109
+ }
110
+ const settle = await postFacilitator(config, "settle", facilitatorRequest);
111
+ if (!settle.ok) {
112
+ config.replayStore?.release({ replayKey, payloadHash });
113
+ sendJson(response, 502, {
114
+ error: "payment_settle_failed",
115
+ reason: facilitatorReason(settle.body),
116
+ facilitator_status: settle.status
117
+ });
118
+ return;
119
+ }
120
+ let settlementBody;
121
+ try {
122
+ settlementBody = toJsonObject(settle.body, "settlement_response");
123
+ }
124
+ catch {
125
+ config.replayStore?.release({ replayKey, payloadHash });
126
+ sendJson(response, 502, {
127
+ error: "payment_settlement_not_verified",
128
+ reason: "settlement_response_not_object",
129
+ facilitator_status: settle.status
130
+ });
131
+ return;
132
+ }
133
+ const settlement = verifyX402SettlementResponse(settlementBody, {
134
+ selectedRequirement,
135
+ signedPayload: paymentPayload
136
+ });
137
+ if (!settlement.settled) {
138
+ config.replayStore?.release({ replayKey, payloadHash });
139
+ config.logger?.warn?.(`x402 paid resource settlement not verified reason=${settlement.reason}`);
140
+ sendJson(response, 502, {
141
+ error: "payment_settlement_not_verified",
142
+ reason: settlement.reason,
143
+ facilitator_status: settle.status
144
+ });
145
+ return;
146
+ }
147
+ response.setHeader("PAYMENT-RESPONSE", encodeBase64Json(settlementBody));
148
+ response.setHeader("X-PAYMENT-RESPONSE", encodeBase64Json(settlementBody));
149
+ config.replayStore?.complete({ replayKey, payloadHash });
150
+ sendJson(response, 200, await resourceBody(config, paymentPayload, settlementBody));
151
+ }
152
+ async function postFacilitator(config, path, body) {
153
+ try {
154
+ const result = await config.postJson(facilitatorEndpoint(config.facilitatorUrl, path), body);
155
+ return {
156
+ ...result,
157
+ ok: result.status >= 200 && result.status < 300
158
+ };
159
+ }
160
+ catch {
161
+ return {
162
+ status: 502,
163
+ ok: false,
164
+ body: { error: `facilitator_${path}_request_failed` }
165
+ };
166
+ }
167
+ }
168
+ function facilitatorVerifyAccepted(value) {
169
+ const body = asRecord(value);
170
+ return Boolean(body && (body.valid === true || body.success === true));
171
+ }
172
+ async function resourceBody(config, paymentPayload, settlementResponse) {
173
+ if (typeof config.resourceBody === "function") {
174
+ return config.resourceBody({ paymentPayload, settlementResponse });
175
+ }
176
+ return (config.resourceBody ?? {
177
+ weather: "sunny",
178
+ unit: "celsius",
179
+ temperature: 22,
180
+ source: "casper-x402-resource",
181
+ settlement: "settled"
182
+ });
183
+ }
184
+ function selectedRequirementForPayload(paymentRequirements, paymentPayload) {
185
+ const selectedRequirementHash = firstString(paymentPayload, [
186
+ "selectedRequirementHash",
187
+ "selected_requirement_hash"
188
+ ]);
189
+ if (!selectedRequirementHash) {
190
+ return null;
191
+ }
192
+ const accepts = paymentRequirements.accepts;
193
+ if (Array.isArray(accepts)) {
194
+ for (const candidate of accepts) {
195
+ if (!candidate || typeof candidate !== "object" || Array.isArray(candidate)) {
196
+ continue;
197
+ }
198
+ const requirement = toJsonObject(candidate, "paymentRequirements.accepts[]");
199
+ if (sha256Hex(canonicalizeJson(requirement)) === selectedRequirementHash.toLowerCase()) {
200
+ return requirement;
201
+ }
202
+ }
203
+ return null;
204
+ }
205
+ if (sha256Hex(canonicalizeJson(paymentRequirements)) === selectedRequirementHash.toLowerCase()) {
206
+ return paymentRequirements;
207
+ }
208
+ return null;
209
+ }
210
+ function replayKeyForPayload(paymentPayload, fallbackHash) {
211
+ const authorization = asRecord(paymentPayload.authorization) ?? {};
212
+ const network = firstString(paymentPayload, ["network", "networkId", "network_id"]) ??
213
+ firstString(authorization, ["network", "networkId", "network_id"]) ??
214
+ "unknown-network";
215
+ const payer = firstString(paymentPayload, ["payer", "payerAccount", "payer_account"]) ??
216
+ firstString(authorization, ["payer", "from"]) ??
217
+ "unknown-payer";
218
+ const nonce = firstString(paymentPayload, ["nonce"]) ??
219
+ firstString(authorization, ["nonce"]) ??
220
+ fallbackHash;
221
+ return sha256Hex([network.toLowerCase(), payer.toLowerCase(), nonce.toLowerCase()].join(":"));
222
+ }
223
+ function sendPaymentRequired(response, paymentRequirements, body = null) {
224
+ const encodedRequirements = encodeBase64Json(paymentRequirements);
225
+ response.setHeader("PAYMENT-REQUIRED", encodedRequirements);
226
+ response.setHeader("X-PAYMENT-REQUIRED", encodedRequirements);
227
+ sendJson(response, 402, body ?? paymentRequirements);
228
+ }
229
+ function sendJson(response, statusCode, value) {
230
+ if (response.writableEnded) {
231
+ return;
232
+ }
233
+ response.statusCode = statusCode;
234
+ response.setHeader("content-type", "application/json");
235
+ response.end(`${JSON.stringify(value)}\n`);
236
+ }
237
+ function headerValue(request, name) {
238
+ const value = request.headers[name.toLowerCase()];
239
+ if (Array.isArray(value)) {
240
+ return value[0] ?? null;
241
+ }
242
+ return value ?? null;
243
+ }
244
+ function parsePaymentHeader(value) {
245
+ for (const candidate of [decodeBase64(value), value]) {
246
+ if (!candidate) {
247
+ continue;
248
+ }
249
+ try {
250
+ return toJsonObject(JSON.parse(candidate), "payment_signature");
251
+ }
252
+ catch {
253
+ continue;
254
+ }
255
+ }
256
+ return null;
257
+ }
258
+ async function postJsonWithFetch(url, body) {
259
+ const response = await fetch(url, {
260
+ method: "POST",
261
+ headers: {
262
+ "content-type": "application/json"
263
+ },
264
+ body: JSON.stringify(body)
265
+ });
266
+ const text = await response.text();
267
+ return {
268
+ status: response.status,
269
+ body: text ? parseJsonOrRaw(text) : {}
270
+ };
271
+ }
272
+ function parseJsonOrRaw(text) {
273
+ try {
274
+ return JSON.parse(text);
275
+ }
276
+ catch {
277
+ return { raw: text };
278
+ }
279
+ }
280
+ function facilitatorEndpoint(facilitatorUrl, path) {
281
+ return new URL(path, facilitatorUrl.endsWith("/") ? facilitatorUrl : `${facilitatorUrl}/`).toString();
282
+ }
283
+ function encodeBase64Json(value) {
284
+ return Buffer.from(JSON.stringify(value), "utf8").toString("base64");
285
+ }
286
+ function decodeBase64(value) {
287
+ try {
288
+ return Buffer.from(value.trim(), "base64").toString("utf8");
289
+ }
290
+ catch {
291
+ return null;
292
+ }
293
+ }
294
+ function firstString(record, keys) {
295
+ for (const key of keys) {
296
+ const value = record[key];
297
+ if (typeof value === "string" && value.trim()) {
298
+ return value.trim();
299
+ }
300
+ }
301
+ return null;
302
+ }
303
+ function facilitatorReason(value) {
304
+ const body = asRecord(value);
305
+ if (!body) {
306
+ return null;
307
+ }
308
+ return firstString(body, ["reason", "error", "message"]);
309
+ }
310
+ function replayRecord(input, state) {
311
+ return {
312
+ replayKey: input.replayKey,
313
+ payloadHash: input.payloadHash,
314
+ state,
315
+ updatedAt: new Date().toISOString()
316
+ };
317
+ }
318
+ function asRecord(value) {
319
+ return value && typeof value === "object" && !Array.isArray(value)
320
+ ? value
321
+ : null;
322
+ }
323
+ function errorMessage(error) {
324
+ return error instanceof Error ? error.message : String(error);
325
+ }
@@ -0,0 +1,176 @@
1
+ import { type CasperCommandInvocation, type CasperCommandResult, type CasperCommandRunner } from "../casper/anchorClient.js";
2
+ import type { JsonObject } from "../memory/types.js";
3
+ export type X402SettlementBlocker = "x402_settlement_disabled" | "x402_settlement_provider_unavailable" | "x402_signing_provider_not_configured" | "x402_signer_request_failed" | "x402_signer_response_invalid" | "x402_facilitator_verify_failed" | "x402_facilitator_settle_failed" | "x402_facilitator_settlement_not_verified" | "x402_paid_resource_fetch_failed" | "x402_paid_resource_still_requires_payment" | "x402_paid_resource_settlement_not_verified" | "x402_casper_settlement_not_configured" | "x402_casper_transaction_submission_disabled" | "x402_casper_payment_payload_invalid" | "x402_casper_transaction_submission_failed" | "x402_casper_transaction_hash_missing" | "x402_casper_transaction_lookup_failed" | "x402_casper_transaction_execution_unavailable" | "x402_casper_transaction_execution_failed";
4
+ export type X402SettlementInput = {
5
+ payment_id: string;
6
+ facilitator_url: string | null;
7
+ method: string;
8
+ url: string;
9
+ selected_requirement: JsonObject;
10
+ selected_requirement_hash: string;
11
+ policy_hash: string;
12
+ };
13
+ export type X402SigningInput = X402SettlementInput;
14
+ export type X402SigningResult = {
15
+ signed: true;
16
+ signed_payload: JsonObject;
17
+ signed_payload_hash: string;
18
+ } | {
19
+ signed: false;
20
+ blocker: X402SettlementBlocker;
21
+ };
22
+ export type X402SignedPaymentProvider = {
23
+ sign(input: X402SigningInput): Promise<X402SigningResult>;
24
+ };
25
+ export type X402SettlementOutcome = {
26
+ status: "unavailable";
27
+ blocker: X402SettlementBlocker;
28
+ signed_payload_hash: string | null;
29
+ response_status: number | null;
30
+ casper_transaction_hash: null;
31
+ receipt_json: string;
32
+ } | {
33
+ status: "failed";
34
+ blocker: X402SettlementBlocker;
35
+ signed_payload_hash: string | null;
36
+ response_status: number | null;
37
+ casper_transaction_hash: string | null;
38
+ receipt_json: string;
39
+ } | {
40
+ status: "settled";
41
+ signed_payload_hash: string;
42
+ response_status: number;
43
+ casper_transaction_hash: string;
44
+ receipt_json: string;
45
+ };
46
+ export type X402SettlementProvider = {
47
+ settle(input: X402SettlementInput): Promise<X402SettlementOutcome>;
48
+ };
49
+ export type X402JsonPostResult = {
50
+ status: number;
51
+ body: unknown;
52
+ };
53
+ export type X402JsonPoster = (url: string, body: JsonObject) => Promise<X402JsonPostResult>;
54
+ export type X402HttpSigningProviderConfig = {
55
+ signerUrl: string | null;
56
+ authToken?: string | null;
57
+ timeoutMs?: number;
58
+ now?: () => Date;
59
+ maxValiditySeconds?: number | null;
60
+ };
61
+ export type X402ResourceRetrySettlementConfig = {
62
+ paymentHeaderName?: string;
63
+ now?: () => Date;
64
+ maxValiditySeconds?: number | null;
65
+ };
66
+ export type X402ResourceFetchResult = {
67
+ status: number;
68
+ headers: Headers;
69
+ bodyText: string;
70
+ };
71
+ export type X402ResourceFetcher = (url: string, init: {
72
+ method: string;
73
+ headers: Record<string, string>;
74
+ }) => Promise<X402ResourceFetchResult>;
75
+ export type X402CasperCliSettlementConfig = {
76
+ networkName: string;
77
+ caip2ChainId: string;
78
+ rpcUrl: string | null;
79
+ accountKeyPath: string | null;
80
+ submissionEnabled: boolean;
81
+ clientBin: string;
82
+ clientWslDistro: string | null;
83
+ gasPriceTolerance: string;
84
+ pricingMode: string;
85
+ paymentAmountMotes: string;
86
+ confirmationPollIntervalMs?: number;
87
+ confirmationTimeoutMs?: number;
88
+ now?: () => Date;
89
+ maxValiditySeconds?: number | null;
90
+ };
91
+ export type ValidatedX402CasperCliSettlementConfig = X402CasperCliSettlementConfig & {
92
+ rpcUrl: string;
93
+ accountKeyPath: string;
94
+ };
95
+ export type CasperX402SettlementPayment = {
96
+ settlementKind: "native-transfer";
97
+ scheme: "exact";
98
+ network: string;
99
+ assetId: "casper-native-cspr";
100
+ target: string;
101
+ amount: string;
102
+ nonce: string;
103
+ } | {
104
+ settlementKind: "cep18-transfer-with-authorization";
105
+ scheme: "exact";
106
+ network: string;
107
+ assetPackageHash: string;
108
+ from: string;
109
+ to: string;
110
+ amount: string;
111
+ validAfter: string;
112
+ validBefore: string;
113
+ nonce: string;
114
+ publicKey: string;
115
+ signature: string;
116
+ };
117
+ export declare class DisabledX402SettlementProvider implements X402SettlementProvider {
118
+ private readonly blocker;
119
+ constructor(blocker?: X402SettlementBlocker);
120
+ settle(input: X402SettlementInput): Promise<X402SettlementOutcome>;
121
+ }
122
+ export declare class DisabledX402SigningProvider implements X402SignedPaymentProvider {
123
+ sign(): Promise<X402SigningResult>;
124
+ }
125
+ export declare class HttpX402SigningProvider implements X402SignedPaymentProvider {
126
+ private readonly config;
127
+ constructor(config: X402HttpSigningProviderConfig);
128
+ sign(input: X402SigningInput): Promise<X402SigningResult>;
129
+ }
130
+ export declare class CasperCliX402SettlementProvider implements X402SettlementProvider {
131
+ private readonly signer;
132
+ private readonly config;
133
+ private readonly commandRunner;
134
+ constructor(signer: X402SignedPaymentProvider, config: X402CasperCliSettlementConfig, commandRunner?: CasperCommandRunner);
135
+ settle(input: X402SettlementInput): Promise<X402SettlementOutcome>;
136
+ private waitForExecution;
137
+ }
138
+ export declare class FacilitatorX402SettlementProvider implements X402SettlementProvider {
139
+ private readonly signer;
140
+ private readonly postJson;
141
+ private readonly config;
142
+ constructor(signer: X402SignedPaymentProvider, postJson?: X402JsonPoster, config?: {
143
+ now?: () => Date;
144
+ maxValiditySeconds?: number | null;
145
+ });
146
+ settle(input: X402SettlementInput): Promise<X402SettlementOutcome>;
147
+ }
148
+ export declare class ResourceRetryX402SettlementProvider implements X402SettlementProvider {
149
+ private readonly signer;
150
+ private readonly resourceFetch;
151
+ private readonly paymentHeaderName;
152
+ private readonly now;
153
+ private readonly maxValiditySeconds;
154
+ constructor(signer: X402SignedPaymentProvider, resourceFetch?: X402ResourceFetcher, config?: X402ResourceRetrySettlementConfig);
155
+ settle(input: X402SettlementInput): Promise<X402SettlementOutcome>;
156
+ }
157
+ export declare function createSignedPayloadHash(payload: unknown): string;
158
+ export declare function validateX402CasperCliSettlementConfig(config: X402CasperCliSettlementConfig): ValidatedX402CasperCliSettlementConfig | null;
159
+ export declare function buildCasperX402SettlementCommand(config: ValidatedX402CasperCliSettlementConfig, payment: CasperX402SettlementPayment): CasperCommandInvocation;
160
+ export declare function buildCasperGetTransactionCommand(config: ValidatedX402CasperCliSettlementConfig, transactionHash: string): CasperCommandInvocation;
161
+ export declare function verifyCasperTransactionExecution(result: CasperCommandResult): CasperX402ExecutionStatus;
162
+ type CasperX402ExecutionStatus = {
163
+ status: "success";
164
+ receipt: unknown;
165
+ } | {
166
+ status: "failed";
167
+ errorMessage: string;
168
+ receipt: unknown;
169
+ } | {
170
+ status: "not_executed";
171
+ receipt: unknown;
172
+ } | {
173
+ status: "lookup_failed";
174
+ result: CasperCommandResult;
175
+ };
176
+ export {};