@belticlabs/agent-risk-sdk 0.2.0 → 0.4.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.
@@ -1,45 +1,30 @@
1
- export { A as AttachOptions, b as AttachedX402, C as CorrelationContext, a as attachX402 } from '../adapter-CF-cUYSA.js';
2
- import { S as Session } from '../session-5TClPLI4.js';
3
- import { v as DeclaredIntent, P as PaymentMomentPayload, J as JsonObject, a as PaymentSummary } from '../index-Bjs3BPPU.js';
1
+ export { A as AttachOptions, b as AttachedX402, C as CorrelationContext, a as attachX402 } from '../adapter-CLy44CD2.js';
2
+ import { S as SessionSource } from '../session-gK51QVAM.js';
3
+ import { r as DeclaredIntent, P as PaymentMomentPayload, J as JsonObject, a as PaymentSummary } from '../verdict-CDAsxktI.js';
4
4
  import '@x402/core/server';
5
- import '../client-C-mV_3A0.js';
6
- import '../verdict-BAahb5po.js';
7
5
  import 'zod';
8
6
 
9
7
  /**
10
8
  * Session binding on the x402 rail (Fraud SDK RFC › Protocol Adapter — x402:
11
9
  * "`PAYMENT-SIGNATURE` extension `beltic.sessionId`"). Where exactly it
12
10
  * lives is GAP-30; that it is outside the wallet-signed payload is GAP-56.
11
+ * A presentation the buyer had evaluated first also carries the
12
+ * `decisionId` the platform answered with, next to the session (GAP-80).
13
13
  */
14
14
  declare const SESSION_EXTENSION = "beltic.sessionId";
15
15
  declare const SESSION_HEADER = "Beltic-Session-Id";
16
+ declare const DECISION_EXTENSION = "beltic.decisionId";
16
17
  declare function sessionIdOf(extensions: Readonly<Record<string, unknown>> | undefined): string | null;
18
+ declare function decisionIdOf(extensions: Readonly<Record<string, unknown>> | undefined): string | null;
17
19
 
18
20
  /**
19
- * Buyer half the x402 fetch wrapper. Sits *inside* the agent's paying
20
- * fetch (e.g. `wrapFetchWithPayment(belticFetch(session))`), so it sees the
21
- * 402 challenge `payment.requested`, and the retry carrying the payment
22
- * `payment.presented`, into which it injects the session binding
23
- * (GAP-30). It never pays and never decides.
24
- *
25
- * Before a request that presents payment leaves, the buffered evidence is
26
- * flushed: the seller will evaluate as soon as it sees the payment, and
27
- * the platform must already hold the buyer's side of the story (GAP-66).
28
- *
29
- * Both x402 generations are read: v2 (`PAYMENT-REQUIRED` header,
30
- * `PAYMENT-SIGNATURE` retry, binding in `extensions`) and v1 (challenge in
31
- * the 402 body, `X-PAYMENT` retry, binding by header only — a v1 payload
32
- * has no extensions and names no asset, so the challenge this wrapper saw
33
- * for the same URL supplies it; GAP-72). The header codec is base64 JSON,
34
- * kept here so a buyer needs no `@x402/*` package to be observed.
21
+ * The paying fetch, observed. Takes a session or the run that owns one;
22
+ * without either (the evidence stream is not configured, or the platform
23
+ * refused to open one) the inner fetch is returned as is — or runs as is
24
+ * per request when the run has no session yet — so a host wires it
25
+ * unconditionally.
35
26
  */
36
-
37
- /**
38
- * The paying fetch, observed. Without a session (the evidence stream is
39
- * not configured, or the platform refused to open one) the inner fetch is
40
- * returned as is, so a host wires it unconditionally.
41
- */
42
- declare function belticFetch(session: Session | null | undefined, inner?: typeof globalThis.fetch): typeof globalThis.fetch;
27
+ declare function belticFetch(source: SessionSource, inner?: typeof globalThis.fetch): typeof globalThis.fetch;
43
28
 
44
29
  /**
45
30
  * The declared intent for an x402 mandate (Fraud SDK RFC › Session ›
@@ -73,20 +58,19 @@ declare function x402Intent(input: X402IntentInput): DeclaredIntent;
73
58
  declare function x402Currency(network: string, asset: string): string;
74
59
  /**
75
60
  * The minimum an `accepts` entry needs to become a moment; unknown parts
76
- * are named, never dropped. v1 spells the amount `maxAmountRequired`.
61
+ * are named, never dropped.
77
62
  */
78
63
  interface AcceptsLike {
79
64
  payTo?: string | undefined;
80
65
  amount?: string | undefined;
81
- maxAmountRequired?: string | undefined;
82
66
  network?: string | undefined;
83
67
  asset?: string | undefined;
84
68
  }
85
69
  /**
86
- * A 402 challenge and a presented payment of either generation, as far as
87
- * a moment needs them. `@x402/core`'s `PaymentRequired` and
88
- * `PaymentPayload` satisfy these structurally, so the seller adapter
89
- * passes its typed values through and the buyer needs no `@x402/*` types.
70
+ * A 402 challenge and a presented payment, as far as a moment needs them.
71
+ * `@x402/core`'s `PaymentRequired` and `PaymentPayload` satisfy these
72
+ * structurally, so the seller adapter passes its typed values through and
73
+ * the buyer needs no `@x402/*` types.
90
74
  */
91
75
  interface PaymentRequiredLike {
92
76
  x402Version?: number | undefined;
@@ -95,8 +79,6 @@ interface PaymentRequiredLike {
95
79
  interface PaymentPayloadLike {
96
80
  x402Version?: number | undefined;
97
81
  accepted?: AcceptsLike | undefined;
98
- /** v1 names the network here, beside the payload, and nowhere else. */
99
- network?: string | undefined;
100
82
  payload?: Readonly<Record<string, unknown>> | undefined;
101
83
  extensions?: Readonly<Record<string, unknown>> | undefined;
102
84
  }
@@ -111,20 +93,14 @@ declare function x402Summary(accepts: AcceptsLike | undefined, opts?: {
111
93
  /** The payer is scheme-specific; the common EVM shapes are read, anything else stays in `raw`. */
112
94
  declare function payerOf(payload: PaymentPayloadLike): string | undefined;
113
95
  declare const x402Moments: {
114
- /** The 402 challenge as the buyer saw it, v2 header or v1 body. */
96
+ /** The 402 challenge as the buyer saw it, from the `PAYMENT-REQUIRED` header. */
115
97
  required(required: PaymentRequiredLike): PaymentMomentPayload;
116
98
  /** The requirements the seller's resource server resolved for a request. */
117
99
  requirements(req: AcceptsLike): PaymentMomentPayload;
118
100
  /** A route's static `accepts` config, before any payment header exists. */
119
101
  route(route: unknown, raw: JsonObject): PaymentMomentPayload;
120
- /** An in-band ask (MRTR `input_required` or a `_meta` envelope) carrying an x402-style `accepts`. */
121
- ask(first: AcceptsLike, raw: JsonObject): PaymentMomentPayload;
122
- /**
123
- * The signed payment the buyer presented. A v2 payload carries the
124
- * requirement it accepted; a v1 payload does not, so the caller passes
125
- * the `accepts` entry it answered.
126
- */
127
- payload(payload: PaymentPayloadLike, accepts?: AcceptsLike | undefined): PaymentMomentPayload;
102
+ /** The signed payment the buyer presented, with the requirement it accepted. */
103
+ payload(payload: PaymentPayloadLike): PaymentMomentPayload;
128
104
  };
129
105
 
130
- export { type AcceptsLike, type PaymentPayloadLike, type PaymentRequiredLike, SESSION_EXTENSION, SESSION_HEADER, type X402IntentInput, belticFetch, payerOf, sessionIdOf, x402Currency, x402Intent, x402Moments, x402Summary };
106
+ export { type AcceptsLike, DECISION_EXTENSION, type PaymentPayloadLike, type PaymentRequiredLike, SESSION_EXTENSION, SESSION_HEADER, type X402IntentInput, belticFetch, decisionIdOf, payerOf, sessionIdOf, x402Currency, x402Intent, x402Moments, x402Summary };
@@ -1,51 +1,55 @@
1
1
  import {
2
- attachX402
3
- } from "../chunk-SO6HPRJT.js";
2
+ Session,
3
+ Sessions
4
+ } from "../chunk-4MG6VNAU.js";
4
5
  import {
6
+ DECISION_EXTENSION,
5
7
  SESSION_EXTENSION,
6
8
  SESSION_HEADER,
7
- sessionIdOf
8
- } from "../chunk-VM7MK43J.js";
9
- import "../chunk-SFGM7KOG.js";
10
- import "../chunk-46QN2KEZ.js";
11
- import {
9
+ attachX402,
10
+ decisionIdOf,
12
11
  payerOf,
12
+ sessionIdOf,
13
13
  x402Currency,
14
14
  x402Moments,
15
15
  x402Summary
16
- } from "../chunk-LM4NIYE5.js";
16
+ } from "../chunk-WY5ZX4BD.js";
17
17
  import "../chunk-FQDHFTVR.js";
18
+ import "../chunk-X3W2Z5GC.js";
18
19
 
19
20
  // src/x402/fetch.ts
20
21
  var BASE64 = /^[A-Za-z0-9+/]*={0,2}$/;
21
- var CHALLENGE_MEMORY = 32;
22
- function belticFetch(session, inner = globalThis.fetch) {
23
- if (!session) return inner;
24
- const challenges = /* @__PURE__ */ new Map();
22
+ function belticFetch(source, inner = globalThis.fetch) {
23
+ if (!source) return inner;
24
+ const run = source instanceof Session ? null : source;
25
25
  return async (input, init) => {
26
- const url = urlOf(input);
26
+ const session = await Sessions.resolve(source);
27
+ if (!session) return inner(input, init);
27
28
  const headers = new Headers(
28
29
  init?.headers ?? (input instanceof Request ? input.headers : void 0)
29
30
  );
30
31
  headers.set(SESSION_HEADER, session.id);
31
32
  const signature = headers.get("PAYMENT-SIGNATURE");
32
- const presented = signature ?? headers.get("X-PAYMENT");
33
- const payload = presented ? decodeHeader(presented) : null;
33
+ const payload = signature ? decodeHeader(signature) : null;
34
34
  if (payload) {
35
- const bound = signature ? { ...payload, extensions: { ...payload.extensions, [SESSION_EXTENSION]: session.id } } : payload;
36
- if (signature) headers.set("PAYMENT-SIGNATURE", encodeHeader(bound));
37
- const accepts = bound.accepted ?? answeredAccepts(challenges.get(url), bound);
38
- await session.emit("payment.presented", x402Moments.payload(bound, accepts));
35
+ const decision = run?.decisionFor(x402Moments.payload(payload));
36
+ const decisionId = decision && !decision.absent ? decision.decisionId : null;
37
+ const bound = {
38
+ ...payload,
39
+ extensions: {
40
+ ...payload.extensions,
41
+ [SESSION_EXTENSION]: session.id,
42
+ ...decisionId ? { [DECISION_EXTENSION]: decisionId } : {}
43
+ }
44
+ };
45
+ headers.set("PAYMENT-SIGNATURE", encodeHeader(bound));
46
+ await session.emit("payment.presented", x402Moments.payload(bound));
39
47
  await session.flush();
40
48
  }
41
49
  const res = await inner(input, { ...init, headers });
42
50
  if (res.status !== 402) return res;
43
- const required = await challengeOf(res);
44
- if (required) {
45
- challenges.set(url, required);
46
- if (challenges.size > CHALLENGE_MEMORY) challenges.delete(challenges.keys().next().value);
47
- await session.emit("payment.requested", x402Moments.required(required));
48
- }
51
+ const required = challengeOf(res);
52
+ if (required) await session.emit("payment.requested", x402Moments.required(required));
49
53
  return res;
50
54
  };
51
55
  }
@@ -61,35 +65,9 @@ function decodeHeader(value) {
61
65
  function encodeHeader(value) {
62
66
  return Buffer.from(JSON.stringify(value), "utf8").toString("base64");
63
67
  }
64
- function urlOf(input) {
65
- return typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
66
- }
67
- async function challengeOf(res) {
68
+ function challengeOf(res) {
68
69
  const header = res.headers.get("PAYMENT-REQUIRED");
69
- if (header) return decodeHeader(header);
70
- if (!/json/i.test(res.headers.get("content-type") ?? "")) return null;
71
- try {
72
- const body = await res.clone().json();
73
- return Array.isArray(body?.accepts) ? body : null;
74
- } catch {
75
- return null;
76
- }
77
- }
78
- function answeredAccepts(required, payload) {
79
- const auth = payload.payload?.authorization;
80
- const payTo = typeof auth?.to === "string" ? auth.to : void 0;
81
- const amount = typeof auth?.value === "string" ? auth.value : void 0;
82
- const options = required?.accepts ?? [];
83
- const answered = options.find(
84
- (a) => a.payTo?.toLowerCase() === payTo?.toLowerCase() && (a.amount ?? a.maxAmountRequired) === amount
85
- ) ?? options[0];
86
- if (answered) return answered;
87
- if (!payTo && !amount) return void 0;
88
- return {
89
- ...payTo ? { payTo } : {},
90
- ...amount ? { amount } : {},
91
- ...payload.network ? { network: payload.network } : {}
92
- };
70
+ return header ? decodeHeader(header) : null;
93
71
  }
94
72
 
95
73
  // src/x402/intent.ts
@@ -105,10 +83,12 @@ function x402Intent(input) {
105
83
  };
106
84
  }
107
85
  export {
86
+ DECISION_EXTENSION,
108
87
  SESSION_EXTENSION,
109
88
  SESSION_HEADER,
110
89
  attachX402,
111
90
  belticFetch,
91
+ decisionIdOf,
112
92
  payerOf,
113
93
  sessionIdOf,
114
94
  x402Currency,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@belticlabs/agent-risk-sdk",
3
- "version": "0.2.0",
4
- "description": "The Beltic Agent Risk SDK — one client, two halves: instrument the buyer agent (AI SDK, x402 fetch, MCP client) and guard the seller boundary (x402, MCP server, evaluate).",
3
+ "version": "0.4.0",
4
+ "description": "The Beltic Agent Risk SDK — one client, two halves: instrument the buyer agent (AI SDK, x402 fetch) and guard the seller boundary (x402 over hono, evaluate).",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
7
7
  "type": "git",
@@ -32,18 +32,6 @@
32
32
  "types": "./dist/x402/hono.d.ts",
33
33
  "default": "./dist/x402/hono.js"
34
34
  },
35
- "./express": {
36
- "types": "./dist/x402/express.d.ts",
37
- "default": "./dist/x402/express.js"
38
- },
39
- "./mcp": {
40
- "types": "./dist/mcp/index.d.ts",
41
- "default": "./dist/mcp/index.js"
42
- },
43
- "./platform-adapter": {
44
- "types": "./dist/seller/anti-fraud-gateway.d.ts",
45
- "default": "./dist/seller/anti-fraud-gateway.js"
46
- },
47
35
  "./package.json": "./package.json"
48
36
  },
49
37
  "files": [
@@ -57,45 +45,29 @@
57
45
  "zod": "^4.6.5"
58
46
  },
59
47
  "peerDependencies": {
60
- "@modelcontextprotocol/sdk": "^1.30.0",
61
48
  "@x402/core": "^2.25.0",
62
- "@x402/express": "^2.25.0",
63
49
  "@x402/hono": "^2.25.0",
64
50
  "ai": "^7.0.0",
65
- "express": "^5.0.0",
66
51
  "hono": "^4.0.0"
67
52
  },
68
53
  "peerDependenciesMeta": {
69
- "@modelcontextprotocol/sdk": {
70
- "optional": true
71
- },
72
54
  "@x402/core": {
73
55
  "optional": true
74
56
  },
75
- "@x402/express": {
76
- "optional": true
77
- },
78
57
  "@x402/hono": {
79
58
  "optional": true
80
59
  },
81
60
  "ai": {
82
61
  "optional": true
83
62
  },
84
- "express": {
85
- "optional": true
86
- },
87
63
  "hono": {
88
64
  "optional": true
89
65
  }
90
66
  },
91
67
  "devDependencies": {
92
- "@modelcontextprotocol/sdk": "^1.30.0",
93
- "@types/express": "^5.0.6",
94
68
  "@x402/core": "^2.25.0",
95
- "@x402/express": "^2.25.0",
96
69
  "@x402/hono": "^2.25.0",
97
70
  "ai": "^7.0.100",
98
- "express": "^5.2.1",
99
71
  "hono": "^4.13.7",
100
72
  "tsup": "8.5.1",
101
73
  "typescript": "5.9.3",
@@ -1,17 +0,0 @@
1
- // src/core/payment-moment.ts
2
- function summaryOf(m) {
3
- return {
4
- protocol: m.protocol,
5
- payee: m.payee,
6
- amount: { value: m.amount.value, currency: m.amount.currency },
7
- ...m.payer ? { payer: m.payer } : {}
8
- };
9
- }
10
- function presentedFrom(summary, raw) {
11
- return { ...summary, artifact: "payment-signature", raw };
12
- }
13
-
14
- export {
15
- summaryOf,
16
- presentedFrom
17
- };
@@ -1,39 +0,0 @@
1
- // src/core/record.ts
2
- function errorOf(err) {
3
- const e = err;
4
- return { name: String(e?.name ?? "Error"), message: String(e?.message ?? err) };
5
- }
6
- function openCall(session, kind, callId, start) {
7
- const started = Date.now();
8
- const opened = session.emit(`${kind}.start`, { callId, ...start });
9
- const close = async (outcome) => {
10
- await opened;
11
- return session.emit(
12
- `${kind}.end`,
13
- { callId, ...outcome, durationMs: Date.now() - started }
14
- );
15
- };
16
- return {
17
- callId,
18
- opened,
19
- end: (outcome = {}) => close(outcome),
20
- fail: (error, outcome = {}) => close({ error: errorOf(error), ...outcome })
21
- };
22
- }
23
- async function recordCall(session, kind, callId, start, run, end = () => ({})) {
24
- const span = openCall(session, kind, callId, start);
25
- await span.opened;
26
- try {
27
- const result = await run();
28
- await span.end(await end(result));
29
- return result;
30
- } catch (err) {
31
- await span.fail(err);
32
- throw err;
33
- }
34
- }
35
-
36
- export {
37
- openCall,
38
- recordCall
39
- };
@@ -1,92 +0,0 @@
1
- import {
2
- toJsonObject
3
- } from "./chunk-FQDHFTVR.js";
4
-
5
- // src/x402/moments.ts
6
- function x402Currency(network, asset) {
7
- return `${network}/${asset}`;
8
- }
9
- function x402Summary(accepts, opts = {}) {
10
- const payer = opts.payer?.toLowerCase();
11
- return {
12
- protocol: "x402",
13
- payee: accepts?.payTo ?? "unknown",
14
- amount: {
15
- value: accepts?.amount ?? accepts?.maxAmountRequired ?? "0",
16
- currency: accepts ? x402Currency(accepts.network ?? "unknown", accepts.asset ?? "unknown") : "unknown"
17
- },
18
- ...payer ? { payer } : {}
19
- };
20
- }
21
- function fromAccepts(a, artifact, raw, payer) {
22
- return { ...x402Summary(a, { payer }), artifact, raw };
23
- }
24
- function payerOf(payload) {
25
- const p = payload.payload ?? {};
26
- const auth = p.authorization;
27
- const candidates = [
28
- auth?.from,
29
- p.from,
30
- p.payer,
31
- p.signer,
32
- p.permit?.owner
33
- ];
34
- const hit = candidates.find((c) => typeof c === "string" && c.length > 0);
35
- return typeof hit === "string" ? hit.toLowerCase() : void 0;
36
- }
37
- var x402Moments = {
38
- /** The 402 challenge as the buyer saw it, v2 header or v1 body. */
39
- required(required) {
40
- return fromAccepts(required.accepts?.[0], "http-402", toJsonObject(required));
41
- },
42
- /** The requirements the seller's resource server resolved for a request. */
43
- requirements(req) {
44
- return fromAccepts(req, "http-402", toJsonObject(req));
45
- },
46
- /** A route's static `accepts` config, before any payment header exists. */
47
- route(route, raw) {
48
- const accepts = route ?? {};
49
- const extra = accepts.extra;
50
- return fromAccepts(
51
- {
52
- payTo: typeof accepts.payTo === "string" ? accepts.payTo : "dynamic",
53
- amount: priceValue(accepts.price),
54
- network: accepts.network,
55
- asset: extra?.asset ?? "route"
56
- },
57
- "http-402",
58
- raw
59
- );
60
- },
61
- /** An in-band ask (MRTR `input_required` or a `_meta` envelope) carrying an x402-style `accepts`. */
62
- ask(first, raw) {
63
- return fromAccepts(first, "mrtr-input-required", raw);
64
- },
65
- /**
66
- * The signed payment the buyer presented. A v2 payload carries the
67
- * requirement it accepted; a v1 payload does not, so the caller passes
68
- * the `accepts` entry it answered.
69
- */
70
- payload(payload, accepts) {
71
- return fromAccepts(
72
- accepts ?? payload.accepted,
73
- "payment-signature",
74
- toJsonObject(payload),
75
- payerOf(payload)
76
- );
77
- }
78
- };
79
- function priceValue(price) {
80
- if (typeof price === "string") return price.replace(/[^0-9.]/g, "") || "0";
81
- if (typeof price === "number") return String(price);
82
- if (price && typeof price === "object" && typeof price.amount === "string")
83
- return price.amount;
84
- return "0";
85
- }
86
-
87
- export {
88
- x402Currency,
89
- x402Summary,
90
- payerOf,
91
- x402Moments
92
- };
@@ -1,82 +0,0 @@
1
- import {
2
- SESSION_HEADER,
3
- sessionIdOf
4
- } from "./chunk-VM7MK43J.js";
5
- import {
6
- payloadDigest
7
- } from "./chunk-SFGM7KOG.js";
8
- import {
9
- x402Moments
10
- } from "./chunk-LM4NIYE5.js";
11
-
12
- // src/x402/adapter.ts
13
- function attachX402(beltic, server, http, opts = {}) {
14
- const inFlight = /* @__PURE__ */ new Map();
15
- const resolveSession = async (bound, ctx) => {
16
- const key = opts.correlate?.(ctx) ?? null;
17
- return bound ?? (key ? await beltic.correlation.resolve(key) : null);
18
- };
19
- http?.onProtectedRequest(async (ctx, route) => {
20
- if (ctx.paymentHeader) return;
21
- const bound = ctx.adapter.getHeader(SESSION_HEADER) ?? ctx.adapter.getHeader(SESSION_HEADER.toLowerCase());
22
- const sessionId = await resolveSession(bound ?? null, {
23
- path: ctx.path,
24
- method: ctx.method,
25
- header: (n) => ctx.adapter.getHeader(n)
26
- });
27
- if (!sessionId) return;
28
- const session = await beltic.sessions.ensure(sessionId);
29
- const accepts = Array.isArray(route.accepts) ? route.accepts[0] : route.accepts;
30
- await session.emit(
31
- "payment.requested",
32
- x402Moments.route(accepts, {
33
- path: ctx.path,
34
- method: ctx.method,
35
- route: JSON.parse(JSON.stringify(route))
36
- })
37
- );
38
- });
39
- server.onBeforeVerify(async (ctx) => {
40
- const payload = ctx.paymentPayload;
41
- const requirements = ctx.requirements;
42
- const sessionId = await resolveSession(sessionIdOf(payload.extensions), {
43
- path: payload.resource?.url ?? "",
44
- method: "PAY",
45
- header: () => void 0
46
- });
47
- const session = await beltic.sessions.ensure(sessionId);
48
- if (session.born === "seller")
49
- await session.emit("payment.requested", x402Moments.requirements(requirements));
50
- const presented = x402Moments.payload(payload);
51
- await session.emit("payment.presented", presented);
52
- inFlight.set(payloadDigest(payload), session);
53
- const out = await beltic.evaluate(session.id, presented);
54
- if (!out) return;
55
- opts.onDecision?.({
56
- sessionId: session.id,
57
- decision: out.decision,
58
- reasonCodes: out.reasonCodes,
59
- born: session.born
60
- });
61
- if (out.verdict.blocks(beltic.onReview)) {
62
- return {
63
- abort: true,
64
- reason: `BELTIC_${out.verdict.value}`,
65
- message: out.reasonCodes.join(",")
66
- };
67
- }
68
- return;
69
- });
70
- server.onAfterSettle(async (ctx) => {
71
- const key = payloadDigest(ctx.paymentPayload);
72
- const session = inFlight.get(key);
73
- if (!session) return;
74
- inFlight.delete(key);
75
- if (ctx.result.success) await session.close("settled", { transaction: ctx.result.transaction });
76
- });
77
- return { inFlight };
78
- }
79
-
80
- export {
81
- attachX402
82
- };
@@ -1,17 +0,0 @@
1
- import {
2
- attachX402
3
- } from "./chunk-SO6HPRJT.js";
4
-
5
- // src/x402/middleware.ts
6
- import {
7
- x402HTTPResourceServer
8
- } from "@x402/core/server";
9
- function guardedPaymentMiddleware(fromHTTPServer, beltic, routes, server, opts = {}) {
10
- const http = new x402HTTPResourceServer(server, routes);
11
- attachX402(beltic, server, http, opts);
12
- return fromHTTPServer(http, opts.paywall);
13
- }
14
-
15
- export {
16
- guardedPaymentMiddleware
17
- };
@@ -1,13 +0,0 @@
1
- // src/x402/binding.ts
2
- var SESSION_EXTENSION = "beltic.sessionId";
3
- var SESSION_HEADER = "Beltic-Session-Id";
4
- function sessionIdOf(extensions) {
5
- const v = extensions?.[SESSION_EXTENSION];
6
- return typeof v === "string" && v.length > 0 ? v : null;
7
- }
8
-
9
- export {
10
- SESSION_EXTENSION,
11
- SESSION_HEADER,
12
- sessionIdOf
13
- };