@astrasyncai/verification-gateway 5.4.0 → 5.4.2
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/adapter-interface/interface.d.mts +2 -3
- package/dist/adapter-interface/interface.d.ts +2 -3
- package/dist/adapters/express.d.mts +63 -4
- package/dist/adapters/express.d.ts +63 -4
- package/dist/adapters/express.js +9 -2
- package/dist/adapters/express.js.map +1 -1
- package/dist/adapters/express.mjs +9 -2
- package/dist/adapters/express.mjs.map +1 -1
- package/dist/adapters/mcp.d.mts +396 -4
- package/dist/adapters/mcp.d.ts +396 -4
- package/dist/adapters/mcp.js +9 -2
- package/dist/adapters/mcp.js.map +1 -1
- package/dist/adapters/mcp.mjs +9 -2
- package/dist/adapters/mcp.mjs.map +1 -1
- package/dist/adapters/nextjs.d.mts +22 -4
- package/dist/adapters/nextjs.d.ts +22 -4
- package/dist/adapters/nextjs.js +9 -2
- package/dist/adapters/nextjs.js.map +1 -1
- package/dist/adapters/nextjs.mjs +9 -2
- package/dist/adapters/nextjs.mjs.map +1 -1
- package/dist/adapters/sdk.d.mts +157 -3
- package/dist/adapters/sdk.d.ts +157 -3
- package/dist/adapters/sdk.js +35 -15
- package/dist/adapters/sdk.js.map +1 -1
- package/dist/adapters/sdk.mjs +35 -15
- package/dist/adapters/sdk.mjs.map +1 -1
- package/dist/agent/index.d.mts +224 -3
- package/dist/agent/index.d.ts +224 -3
- package/dist/agent/index.js +1 -1
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/index.mjs +1 -1
- package/dist/agent/index.mjs.map +1 -1
- package/dist/bin/astrasync-claude-hook.js +9 -2
- package/dist/bin/astrasync-codex-hook.js +9 -2
- package/dist/bin/astrasync-guard.js +9 -2
- package/dist/bin/astrasync.js +9 -2
- package/dist/browser/background.js +9 -2
- package/dist/browser/background.js.map +1 -1
- package/dist/browser/background.mjs +9 -2
- package/dist/browser/background.mjs.map +1 -1
- package/dist/browser/browser-adapter.d.mts +1 -5
- package/dist/browser/browser-adapter.d.ts +1 -5
- package/dist/claude-code/claude-code-adapter.d.mts +1 -5
- package/dist/claude-code/claude-code-adapter.d.ts +1 -5
- package/dist/cli/index.d.mts +1 -5
- package/dist/cli/index.d.ts +1 -5
- package/dist/cli/index.js +1 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/index.mjs.map +1 -1
- package/dist/codex/index.d.mts +1 -5
- package/dist/codex/index.d.ts +1 -5
- package/dist/codex/index.js +9 -2
- package/dist/codex/index.js.map +1 -1
- package/dist/codex/index.mjs +9 -2
- package/dist/codex/index.mjs.map +1 -1
- package/dist/cursor/cursor-adapter.d.mts +1 -5
- package/dist/cursor/cursor-adapter.d.ts +1 -5
- package/dist/cursor/extension.d.mts +1 -5
- package/dist/cursor/extension.d.ts +1 -5
- package/dist/cursor/extension.js +9 -2
- package/dist/cursor/extension.js.map +1 -1
- package/dist/cursor/extension.mjs +9 -2
- package/dist/cursor/extension.mjs.map +1 -1
- package/dist/edge-config.d.mts +1 -1
- package/dist/edge-config.d.ts +1 -1
- package/dist/edge-config.js +1 -1
- package/dist/edge-config.js.map +1 -1
- package/dist/edge-config.mjs +1 -1
- package/dist/edge-config.mjs.map +1 -1
- package/dist/edge-core/index.d.mts +1 -1
- package/dist/edge-core/index.d.ts +1 -1
- package/dist/edge-core/index.js +9 -2
- package/dist/edge-core/index.js.map +1 -1
- package/dist/edge-core/index.mjs +9 -2
- package/dist/edge-core/index.mjs.map +1 -1
- package/dist/gateway/gateway.d.mts +2 -3
- package/dist/gateway/gateway.d.ts +2 -3
- package/dist/gateway/gateway.js +9 -2
- package/dist/gateway/gateway.js.map +1 -1
- package/dist/gateway/gateway.mjs +9 -2
- package/dist/gateway/gateway.mjs.map +1 -1
- package/dist/git-trigger/git-hooks.d.mts +253 -3
- package/dist/git-trigger/git-hooks.d.ts +253 -3
- package/dist/index.d.mts +4506 -42
- package/dist/index.d.ts +4506 -42
- package/dist/index.js +35 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -15
- package/dist/index.mjs.map +1 -1
- package/dist/interface-q1WrMsB1.d.mts +365 -0
- package/dist/interface-q1WrMsB1.d.ts +365 -0
- package/dist/local-evaluator/evaluator.d.mts +2 -3
- package/dist/local-evaluator/evaluator.d.ts +2 -3
- package/dist/registration/index.js +1 -1
- package/dist/registration/index.js.map +1 -1
- package/dist/registration/index.mjs +1 -1
- package/dist/registration/index.mjs.map +1 -1
- package/dist/transport/index.d.mts +1324 -4
- package/dist/transport/index.d.ts +1324 -4
- package/dist/transport/index.js +1 -1
- package/dist/transport/index.js.map +1 -1
- package/dist/transport/index.mjs +1 -1
- package/dist/transport/index.mjs.map +1 -1
- package/dist/{types-DGh2akuh.d.ts → types-BRz2U0Pn.d.ts} +2 -2
- package/dist/{types-76TB0fxW.d.ts → types-BU04qAAR.d.mts} +59 -213
- package/dist/{types-CD1F9fmp.d.mts → types-BU04qAAR.d.ts} +59 -213
- package/dist/types-Bd2O3eX1.d.mts +769 -0
- package/dist/types-BfILnheI.d.mts +189 -0
- package/dist/types-BfILnheI.d.ts +189 -0
- package/dist/{types-z_RNjHWm.d.mts → types-CfBpm3w5.d.mts} +2 -2
- package/dist/types-DMChboN_.d.ts +769 -0
- package/dist/ui/index.d.mts +1 -2
- package/dist/ui/index.d.ts +1 -2
- package/dist/verify.d.mts +1 -1
- package/dist/verify.d.ts +1 -1
- package/dist/verify.js +9 -2
- package/dist/verify.js.map +1 -1
- package/dist/verify.mjs +9 -2
- package/dist/verify.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/express-BIAT2pe0.d.mts +0 -69
- package/dist/express-D3Tf-b23.d.ts +0 -69
- package/dist/index-BVJkTyIF.d.mts +0 -248
- package/dist/index-By021oSN.d.mts +0 -1469
- package/dist/index-DaMXZabg.d.ts +0 -248
- package/dist/index-iJ9_DdLk.d.ts +0 -1469
- package/dist/mcp-BqfTDZLh.d.mts +0 -397
- package/dist/mcp-OrVOrH-s.d.ts +0 -397
- package/dist/nextjs-DGJXzWst.d.mts +0 -28
- package/dist/nextjs-xM-jdNrX.d.ts +0 -28
- package/dist/sdk-C1IOA5LE.d.ts +0 -173
- package/dist/sdk-C6_-6D-9.d.mts +0 -173
|
@@ -1,4 +1,1324 @@
|
|
|
1
|
-
import '../types-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { A as AstraSyncCredentials, P as ProtocolTransport } from '../types-BfILnheI.mjs';
|
|
2
|
+
import { JWK } from 'jose';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* HTTP Transport Adapter
|
|
6
|
+
*
|
|
7
|
+
* Maps AstraSync credentials to/from HTTP headers (X-Astra-* convention).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Inject AstraSync credentials into HTTP headers.
|
|
12
|
+
*/
|
|
13
|
+
declare function setHttpHeaders(headers: Record<string, string>, credentials: AstraSyncCredentials): Record<string, string>;
|
|
14
|
+
/**
|
|
15
|
+
* Extract AstraSync credentials from HTTP headers.
|
|
16
|
+
*/
|
|
17
|
+
declare function extractHttpCredentials(headers: Record<string, string | string[] | undefined>): AstraSyncCredentials | null;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A2A (Agent-to-Agent) Transport Adapter
|
|
21
|
+
*
|
|
22
|
+
* Maps AstraSync credentials to/from A2A task metadata.astrasync block.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
interface A2ATask {
|
|
26
|
+
metadata?: Record<string, unknown>;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Add AstraSync credentials to an A2A task's metadata block.
|
|
31
|
+
*/
|
|
32
|
+
declare function setA2AMetadata(task: A2ATask, credentials: AstraSyncCredentials): A2ATask;
|
|
33
|
+
/**
|
|
34
|
+
* Extract AstraSync credentials from an A2A task's metadata block.
|
|
35
|
+
*/
|
|
36
|
+
declare function extractA2ACredentials(task: A2ATask): AstraSyncCredentials | null;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* MCP (Model Context Protocol) Transport Adapter
|
|
40
|
+
*
|
|
41
|
+
* Maps AstraSync credentials to/from MCP params._meta.astrasync block.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
interface McpParams {
|
|
45
|
+
_meta?: Record<string, unknown>;
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Add AstraSync credentials to MCP params' _meta block.
|
|
50
|
+
*/
|
|
51
|
+
declare function setMcpMeta(params: McpParams, credentials: AstraSyncCredentials): McpParams;
|
|
52
|
+
/**
|
|
53
|
+
* Extract AstraSync credentials from MCP params' _meta block.
|
|
54
|
+
*/
|
|
55
|
+
declare function extractMcpCredentials(params: McpParams): AstraSyncCredentials | null;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Protocol request -> AstraSync PDLSS purpose category mapping.
|
|
59
|
+
*
|
|
60
|
+
* Commerce purpose mapping table, extended with MPP + x402
|
|
61
|
+
* entries (April 2026 protocol landscape).
|
|
62
|
+
*/
|
|
63
|
+
type CommercePurpose = 'commerce.checkout.create' | 'commerce.checkout.update' | 'commerce.checkout.confirm' | 'commerce.checkout.cancel' | 'commerce.payment.execute' | 'commerce.payment.stream' | 'commerce.delegation.intent' | 'commerce.delegation.checkout' | 'commerce.delegation.payment' | 'commerce.identity_probe' | 'commerce.browsing';
|
|
64
|
+
declare function mapUCPRequestToPurpose(method: string, path: string): CommercePurpose | null;
|
|
65
|
+
declare function mapACPRequestToPurpose(method: string, path: string): CommercePurpose | null;
|
|
66
|
+
type AP2MandateType = 'intent_mandate' | 'cart_mandate' | 'payment_mandate';
|
|
67
|
+
declare function mapAP2MandateToPurpose(mandateType: AP2MandateType): CommercePurpose;
|
|
68
|
+
type VIMandateType = 'checkout' | 'payment' | 'checkout.open' | 'payment.open';
|
|
69
|
+
declare function mapVIMandateToPurpose(mandateType: VIMandateType): CommercePurpose;
|
|
70
|
+
type RFC9421Tag = 'browse' | 'purchase' | undefined;
|
|
71
|
+
declare function mapRFC9421TagToPurpose(tag: RFC9421Tag): CommercePurpose;
|
|
72
|
+
type MPPIntent = 'charge' | 'session';
|
|
73
|
+
declare function mapMPPRequestToPurpose(intent: MPPIntent | undefined, amount: number | undefined): CommercePurpose;
|
|
74
|
+
declare function mapX402RequestToPurpose(amount: number | undefined): CommercePurpose;
|
|
75
|
+
/**
|
|
76
|
+
* Informational Stripe webhook events surfaced as trust signals on
|
|
77
|
+
* `CommerceContext.trustSignals` but NOT routed to a PDLSS purpose.
|
|
78
|
+
*/
|
|
79
|
+
declare const STRIPE_WEBHOOK_INFORMATIONAL_EVENTS: readonly ["payment_intent.succeeded", "payment_intent.payment_failed", "charge.refunded", "checkout.session.completed", "customer.subscription.created"];
|
|
80
|
+
type StripeWebhookInformationalEvent = (typeof STRIPE_WEBHOOK_INFORMATIONAL_EVENTS)[number];
|
|
81
|
+
declare function isStripeWebhookInformational(eventType: string): boolean;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Per-protocol transaction-value normalization.
|
|
85
|
+
*
|
|
86
|
+
* Each protocol encodes amount/currency differently. This module produces a
|
|
87
|
+
* uniform `TransactionValueContext` with `source` recording the extraction
|
|
88
|
+
* path so trace logs can show where the value came from.
|
|
89
|
+
*
|
|
90
|
+
* Amount unit: "major units" (dollars/euros/etc. for fiat; native unit for
|
|
91
|
+
* tokens — we do NOT convert across currencies). UCP/ACP totals are in
|
|
92
|
+
* cents, so we divide by 100. MPP/x402/VI pass through as declared.
|
|
93
|
+
*/
|
|
94
|
+
interface TransactionValueContext {
|
|
95
|
+
protocol: 'vi' | 'ap2' | 'ucp' | 'acp' | 'mpp' | 'x402' | 'agentpay' | 'tap';
|
|
96
|
+
amount: number;
|
|
97
|
+
currency: string;
|
|
98
|
+
source: string;
|
|
99
|
+
/** When true, the amount is in raw atomic/minor units and could NOT be
|
|
100
|
+
* converted to major units (unknown token decimals). The limit engine
|
|
101
|
+
* must fail-closed — never compare raw units against major-unit limits. */
|
|
102
|
+
rawUnits?: boolean;
|
|
103
|
+
}
|
|
104
|
+
declare function extractUCPTransactionValue(input: {
|
|
105
|
+
totals?: Array<{
|
|
106
|
+
type?: string;
|
|
107
|
+
amount?: number;
|
|
108
|
+
currency?: string;
|
|
109
|
+
}>;
|
|
110
|
+
}): TransactionValueContext | null;
|
|
111
|
+
declare function extractACPTransactionValue(input: {
|
|
112
|
+
totals?: Array<{
|
|
113
|
+
type?: string;
|
|
114
|
+
amount?: number;
|
|
115
|
+
currency?: string;
|
|
116
|
+
}>;
|
|
117
|
+
}): TransactionValueContext | null;
|
|
118
|
+
interface VIClaimsForValue {
|
|
119
|
+
constraints?: {
|
|
120
|
+
paymentAmount?: {
|
|
121
|
+
currency?: string;
|
|
122
|
+
min?: number;
|
|
123
|
+
max?: number;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
l3aPaymentAmount?: {
|
|
127
|
+
currency?: string;
|
|
128
|
+
amount?: number;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
declare function extractVITransactionValue(claims: VIClaimsForValue): TransactionValueContext | null;
|
|
132
|
+
interface AP2PaymentMandateForValue {
|
|
133
|
+
payment_details_total?: {
|
|
134
|
+
amount?: {
|
|
135
|
+
value?: string | number;
|
|
136
|
+
currency?: string;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
declare function extractAP2TransactionValue(mandate: AP2PaymentMandateForValue | undefined): TransactionValueContext | null;
|
|
141
|
+
interface MPPChallengeForValue {
|
|
142
|
+
method?: string;
|
|
143
|
+
request?: {
|
|
144
|
+
amount?: number;
|
|
145
|
+
currency?: string;
|
|
146
|
+
} & Record<string, unknown>;
|
|
147
|
+
}
|
|
148
|
+
declare function extractMPPTransactionValue(challenge: MPPChallengeForValue): TransactionValueContext | null;
|
|
149
|
+
interface X402RequestForValue {
|
|
150
|
+
maxAmountRequired?: number;
|
|
151
|
+
amount?: number;
|
|
152
|
+
asset?: string;
|
|
153
|
+
currency?: string;
|
|
154
|
+
}
|
|
155
|
+
declare function extractX402TransactionValue(req: X402RequestForValue): TransactionValueContext | null;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* RFC 9421 HTTP Message Signatures parser.
|
|
159
|
+
*
|
|
160
|
+
* Wraps `structured-headers` (transitive dep of http-message-signatures) to
|
|
161
|
+
* parse the Signature-Input and Signature Dictionary headers per RFC 9421
|
|
162
|
+
* Section 2.
|
|
163
|
+
*
|
|
164
|
+
* Produces structured metadata (kid, algorithm, covered components, tag,
|
|
165
|
+
* created/expires/nonce, signature bytes) without verifying the signature —
|
|
166
|
+
* verification lives in rfc9421-verify.ts.
|
|
167
|
+
*
|
|
168
|
+
* Shared by:
|
|
169
|
+
* - Agent Pay (Mastercard) — kid resolves via Mastercard Agent Registry
|
|
170
|
+
* - TAP (Visa) — kid resolves via Visa JWKS
|
|
171
|
+
* - Web Bot Auth (generic transport substrate) — kid resolves via
|
|
172
|
+
* /.well-known/http-message-signatures-directory
|
|
173
|
+
*/
|
|
174
|
+
interface RFC9421SignatureParams {
|
|
175
|
+
/** The label identifying the signature in the Dictionary header (e.g. "sig1"). */
|
|
176
|
+
label: string;
|
|
177
|
+
/** Key ID used to look up the verifying key in the relevant registry. */
|
|
178
|
+
kid: string;
|
|
179
|
+
/** Algorithm declared in the Signature-Input params (e.g. "ecdsa-p256-sha256", "ed25519"). */
|
|
180
|
+
alg?: string;
|
|
181
|
+
/** Covered components, in order, per RFC 9421 Section 2.1. */
|
|
182
|
+
covered: string[];
|
|
183
|
+
/** Base64url-encoded signature bytes extracted from the paired Signature header. */
|
|
184
|
+
signatureBase64: string;
|
|
185
|
+
/** Unix seconds when the signature was created. */
|
|
186
|
+
created?: number;
|
|
187
|
+
/** Unix seconds when the signature expires. */
|
|
188
|
+
expires?: number;
|
|
189
|
+
/** Nonce (opaque string) for replay protection. */
|
|
190
|
+
nonce?: string;
|
|
191
|
+
/** Tag parameter. For Agent Pay/TAP this is "browse" or "purchase"; undefined otherwise. */
|
|
192
|
+
tag?: 'browse' | 'purchase' | string;
|
|
193
|
+
}
|
|
194
|
+
interface ParsedRFC9421 {
|
|
195
|
+
signatures: RFC9421SignatureParams[];
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Parse the RFC 9421 Signature-Input and Signature headers from a request or response.
|
|
199
|
+
* Returns all signatures present (a single message may carry multiple labelled signatures).
|
|
200
|
+
*
|
|
201
|
+
* Returns null if either header is missing or malformed.
|
|
202
|
+
*/
|
|
203
|
+
declare function parseRFC9421(headers: Record<string, string | string[] | undefined>): ParsedRFC9421 | null;
|
|
204
|
+
|
|
205
|
+
type RegistryName = 'mastercard' | 'visa' | 'web-bot-auth';
|
|
206
|
+
interface RegistryResolver {
|
|
207
|
+
readonly name: RegistryName;
|
|
208
|
+
resolve(kid: string, context?: ResolveContext): Promise<JWK | null>;
|
|
209
|
+
}
|
|
210
|
+
interface ResolveContext {
|
|
211
|
+
origin?: string;
|
|
212
|
+
algorithm?: string;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Shared nonce/signature replay-protection store for transport verifiers.
|
|
217
|
+
*
|
|
218
|
+
* Rationale: every transport-signature verifier (RFC9421, VI, AP2, ACP,
|
|
219
|
+
* MPP) validates a created/expires window, but without a seen-nonce
|
|
220
|
+
* cache any captured signed request can be replayed within the (default
|
|
221
|
+
* 300s, now tightened to 60s) tolerance window.
|
|
222
|
+
*
|
|
223
|
+
* This module ships a bounded in-memory LRU as the default. Production
|
|
224
|
+
* deployments with multi-pod horizontal scaling SHOULD pass a shared store
|
|
225
|
+
* (Redis-backed) via the verifier options to make replay protection global
|
|
226
|
+
* rather than per-pod.
|
|
227
|
+
*
|
|
228
|
+
* The store interface is intentionally minimal: a single `seen(key,
|
|
229
|
+
* expiresAt)` method that returns true iff the key was already recorded
|
|
230
|
+
* (i.e. caller should reject as a replay). Callers compose the key from
|
|
231
|
+
* whichever identifiers are unique to the signature (kid + nonce + sig
|
|
232
|
+
* digest, typically).
|
|
233
|
+
*/
|
|
234
|
+
interface NonceStore {
|
|
235
|
+
/**
|
|
236
|
+
* Record `key` as seen. Returns true iff the key was ALREADY present —
|
|
237
|
+
* i.e. caller should reject the request as a replay. Returns false on
|
|
238
|
+
* first sighting (caller should proceed).
|
|
239
|
+
*
|
|
240
|
+
* `expiresAtMs` is a hint for the store to evict entries that can no
|
|
241
|
+
* longer cause harm (their signature window has elapsed).
|
|
242
|
+
*/
|
|
243
|
+
seen(key: string, expiresAtMs: number): boolean;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* RFC 9421 HTTP Message Signatures verification.
|
|
248
|
+
*
|
|
249
|
+
* Wraps http-message-signatures (dhensby) verifyMessage() with a RegistryResolver
|
|
250
|
+
* hook for kid → JWK lookup. Library handles canonicalization + ES256/EdDSA/
|
|
251
|
+
* HMAC/RSA verification; we supply the key-finding callback and policy around
|
|
252
|
+
* clock skew.
|
|
253
|
+
*
|
|
254
|
+
* Shared by:
|
|
255
|
+
* - Agent Pay (Mastercard) — resolver = createMastercardRegistry
|
|
256
|
+
* - TAP (Visa) — resolver = createVisaRegistry
|
|
257
|
+
* - Web Bot Auth (generic) — resolver = createWebBotAuthRegistry
|
|
258
|
+
*/
|
|
259
|
+
|
|
260
|
+
interface RFC9421VerifyRequest {
|
|
261
|
+
method: string;
|
|
262
|
+
url: string;
|
|
263
|
+
headers: Record<string, string | string[]>;
|
|
264
|
+
body?: string;
|
|
265
|
+
}
|
|
266
|
+
interface RFC9421VerifyOptions {
|
|
267
|
+
resolver: RegistryResolver;
|
|
268
|
+
/** Seconds of tolerance around created/expires. Default 60 (tightened from 300). */
|
|
269
|
+
clockSkewSec?: number;
|
|
270
|
+
/** Injectable for deterministic tests. */
|
|
271
|
+
now?: () => number;
|
|
272
|
+
/** Optional replay-protection store. Defaults to in-process LRU. */
|
|
273
|
+
nonceStore?: NonceStore;
|
|
274
|
+
}
|
|
275
|
+
interface RFC9421VerifyResult {
|
|
276
|
+
ok: boolean;
|
|
277
|
+
kid?: string;
|
|
278
|
+
registry?: RegistryResolver['name'];
|
|
279
|
+
algorithm?: string;
|
|
280
|
+
error?: string;
|
|
281
|
+
}
|
|
282
|
+
declare function verifyRFC9421(request: RFC9421VerifyRequest, options: RFC9421VerifyOptions): Promise<RFC9421VerifyResult>;
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* UCP (Universal Commerce Protocol) checkout session extractor.
|
|
286
|
+
*
|
|
287
|
+
* Google + Shopify spec (ucp.dev). Extracts checkout session context from
|
|
288
|
+
* incoming HTTP requests and, at registration time, validates the
|
|
289
|
+
* `/.well-known/ucp` manifest via AJV against the mirrored JSON schema.
|
|
290
|
+
*/
|
|
291
|
+
|
|
292
|
+
interface UCPTotal {
|
|
293
|
+
type?: string;
|
|
294
|
+
amount?: number;
|
|
295
|
+
currency?: string;
|
|
296
|
+
}
|
|
297
|
+
interface UCPCheckoutContext {
|
|
298
|
+
sessionId?: string;
|
|
299
|
+
endpoint: string;
|
|
300
|
+
purpose: CommercePurpose | null;
|
|
301
|
+
merchantDomain?: string;
|
|
302
|
+
totals?: UCPTotal[];
|
|
303
|
+
paymentMethod?: string;
|
|
304
|
+
manifestUrl?: string;
|
|
305
|
+
}
|
|
306
|
+
interface UCPRequestLike {
|
|
307
|
+
method: string;
|
|
308
|
+
url: string;
|
|
309
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
310
|
+
body?: unknown;
|
|
311
|
+
}
|
|
312
|
+
declare function extractUCPContext(request: UCPRequestLike): UCPCheckoutContext | null;
|
|
313
|
+
/**
|
|
314
|
+
* Fetch and parse a UCP manifest at registration time. Returns parsed JSON
|
|
315
|
+
* on success, null on any failure (network, parse, timeout). Does NOT throw.
|
|
316
|
+
*
|
|
317
|
+
* Schema validation is a separate step — see `validateUCPManifest`.
|
|
318
|
+
*/
|
|
319
|
+
declare function fetchUCPManifest(manifestUrl: string, options?: {
|
|
320
|
+
timeoutMs?: number;
|
|
321
|
+
}): Promise<unknown | null>;
|
|
322
|
+
/**
|
|
323
|
+
* Validate a UCP manifest against the minimal shape we care about.
|
|
324
|
+
*
|
|
325
|
+
* The full UCP manifest schema lives upstream (ucp.dev) and is out of scope
|
|
326
|
+
* to mirror here exhaustively. This function checks the structural guarantees
|
|
327
|
+
* we depend on: required top-level fields (version, capabilities, endpoints).
|
|
328
|
+
*
|
|
329
|
+
* For full schema validation, consumers can pass their own AJV compiled
|
|
330
|
+
* validator via `options.validator`.
|
|
331
|
+
*/
|
|
332
|
+
interface UCPManifestValidationResult {
|
|
333
|
+
ok: boolean;
|
|
334
|
+
errors: string[];
|
|
335
|
+
}
|
|
336
|
+
declare function validateUCPManifest(manifest: unknown, options?: {
|
|
337
|
+
validator?: (m: unknown) => {
|
|
338
|
+
ok: boolean;
|
|
339
|
+
errors: string[];
|
|
340
|
+
};
|
|
341
|
+
}): UCPManifestValidationResult;
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* ACP (Agentic Commerce Protocol) request extractor.
|
|
345
|
+
*
|
|
346
|
+
* Co-maintained by OpenAI + Stripe. Spec at agenticcommerce.dev.
|
|
347
|
+
*
|
|
348
|
+
* Extracts ACP request context from HTTP requests:
|
|
349
|
+
* - Multi-header parsing: Signature, Timestamp, Idempotency-Key,
|
|
350
|
+
* Authorization: Bearer, API-Version
|
|
351
|
+
* - Endpoint classification: Agentic Checkout (checkout_sessions.*) vs
|
|
352
|
+
* Delegate Payment (agentic_commerce/delegate_payment)
|
|
353
|
+
* - Payment token detection: spt_* (Stripe SharedPaymentToken),
|
|
354
|
+
* vt_* (ACP vault token), unknown
|
|
355
|
+
* - Totals + merchant extraction from body
|
|
356
|
+
*
|
|
357
|
+
* No signature verification here — see acp-verify.ts.
|
|
358
|
+
*/
|
|
359
|
+
|
|
360
|
+
type ACPEndpoint = 'checkout_sessions.create' | 'checkout_sessions.update' | 'checkout_sessions.complete' | 'checkout_sessions.cancel' | 'delegate_payment' | 'unknown';
|
|
361
|
+
type ACPPaymentTokenType = 'stripe-spt' | 'acp-vt' | 'other' | null;
|
|
362
|
+
interface ACPTotal {
|
|
363
|
+
type?: string;
|
|
364
|
+
amount?: number;
|
|
365
|
+
currency?: string;
|
|
366
|
+
}
|
|
367
|
+
interface ACPRequestContext {
|
|
368
|
+
endpoint: ACPEndpoint;
|
|
369
|
+
purpose: CommercePurpose | null;
|
|
370
|
+
sessionId?: string;
|
|
371
|
+
merchantId?: string;
|
|
372
|
+
apiVersion?: string;
|
|
373
|
+
bearer?: string;
|
|
374
|
+
signatureHeader?: string;
|
|
375
|
+
timestampHeader?: string;
|
|
376
|
+
idempotencyKey?: string;
|
|
377
|
+
paymentToken?: {
|
|
378
|
+
raw?: string;
|
|
379
|
+
type: ACPPaymentTokenType;
|
|
380
|
+
provider?: string;
|
|
381
|
+
};
|
|
382
|
+
totals?: ACPTotal[];
|
|
383
|
+
fulfillmentOption?: string;
|
|
384
|
+
rawBody?: string;
|
|
385
|
+
}
|
|
386
|
+
interface ACPRequestLike {
|
|
387
|
+
method: string;
|
|
388
|
+
url: string;
|
|
389
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
390
|
+
body?: unknown;
|
|
391
|
+
rawBody?: string;
|
|
392
|
+
}
|
|
393
|
+
declare function extractACPContext(request: ACPRequestLike): ACPRequestContext | null;
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* VI (Verifiable Intent) SD-JWT extraction.
|
|
397
|
+
*
|
|
398
|
+
* Open-sourced 5 March 2026 by Mastercard + Google (v0.1-draft).
|
|
399
|
+
* VI is a 3-layer SD-JWT chain:
|
|
400
|
+
* L1 — issuer → wallet (credential provider)
|
|
401
|
+
* L2 — user → agent (cnf.jwk binding to L3 agent key)
|
|
402
|
+
* L3 — agent → merchant (payment or checkout mandate, split into L3a / L3b
|
|
403
|
+
* cross-referenced via transaction_id)
|
|
404
|
+
*
|
|
405
|
+
* This module does EXTRACTION ONLY — it decodes SD-JWT structure and pulls
|
|
406
|
+
* out the mandate type, kid, executionMode, 8 constraint types, checkoutHash
|
|
407
|
+
* (constraint type 8), transactionId, and raw layers for later verification.
|
|
408
|
+
*
|
|
409
|
+
* Signature verification lives in vi-verify.ts; this module uses @sd-jwt's
|
|
410
|
+
* sync decoder with a SHA-256 hasher for structural parsing only.
|
|
411
|
+
*/
|
|
412
|
+
|
|
413
|
+
type VIExecutionMode = 'Immediate' | 'Autonomous' | 'Both';
|
|
414
|
+
interface VIAllowedParty {
|
|
415
|
+
id?: string;
|
|
416
|
+
name?: string;
|
|
417
|
+
website?: string;
|
|
418
|
+
}
|
|
419
|
+
interface VILineItem {
|
|
420
|
+
id?: string;
|
|
421
|
+
acceptableItems?: string[];
|
|
422
|
+
quantity?: number;
|
|
423
|
+
}
|
|
424
|
+
interface VIPaymentAmount {
|
|
425
|
+
currency?: string;
|
|
426
|
+
min?: number;
|
|
427
|
+
max?: number;
|
|
428
|
+
}
|
|
429
|
+
interface VIBudgetLimit {
|
|
430
|
+
currency?: string;
|
|
431
|
+
max?: number;
|
|
432
|
+
}
|
|
433
|
+
interface VIRecurrence {
|
|
434
|
+
frequency?: string;
|
|
435
|
+
startDate?: string;
|
|
436
|
+
endDate?: string;
|
|
437
|
+
maxOccurrences?: number;
|
|
438
|
+
}
|
|
439
|
+
interface VIConstraints {
|
|
440
|
+
allowedMerchants?: VIAllowedParty[];
|
|
441
|
+
allowedPayees?: VIAllowedParty[];
|
|
442
|
+
lineItems?: VILineItem[];
|
|
443
|
+
paymentAmount?: VIPaymentAmount;
|
|
444
|
+
budgetLimit?: VIBudgetLimit;
|
|
445
|
+
recurrence?: VIRecurrence;
|
|
446
|
+
agentRecurrence?: VIRecurrence;
|
|
447
|
+
}
|
|
448
|
+
interface VIExtractedClaims {
|
|
449
|
+
mandateType: VIMandateType;
|
|
450
|
+
kid?: string;
|
|
451
|
+
executionMode?: VIExecutionMode;
|
|
452
|
+
credentialProvider?: string;
|
|
453
|
+
constraints: VIConstraints;
|
|
454
|
+
/** VI constraint type 8 — SHA-256 of the paired L2 checkout disclosure. */
|
|
455
|
+
checkoutHash?: string;
|
|
456
|
+
transactionId?: string;
|
|
457
|
+
rawLayers: {
|
|
458
|
+
l1?: string;
|
|
459
|
+
l2?: string;
|
|
460
|
+
l3?: string;
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Extract VI claims from a compact SD-JWT string.
|
|
465
|
+
*
|
|
466
|
+
* Input shape:
|
|
467
|
+
* <jwt>~<disclosure1>~<disclosure2>~...~<kbJwt?>
|
|
468
|
+
*
|
|
469
|
+
* Returns null if parsing fails at any layer. Does not verify signatures.
|
|
470
|
+
*/
|
|
471
|
+
declare function extractVIClaims(sdJwtCompact: string): VIExtractedClaims | null;
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Stripe webhook HMAC-SHA256 verifier (inline).
|
|
475
|
+
*
|
|
476
|
+
* Stripe-Signature header format: "t=TIMESTAMP,v1=HEX_SIGNATURE"
|
|
477
|
+
* - t: unix seconds when Stripe signed the webhook
|
|
478
|
+
* - v1: HMAC-SHA256(webhook_secret, `${t}.${payload}`) as hex
|
|
479
|
+
*
|
|
480
|
+
* Multiple v1 signatures can coexist during secret rotation; any match wins.
|
|
481
|
+
* Default tolerance on timestamp age: 300s (matches Stripe's own default).
|
|
482
|
+
*
|
|
483
|
+
* Documented at docs.stripe.com — we intentionally inline ~25 LOC rather
|
|
484
|
+
* than pull in the full stripe npm package (MIT but 600KB+ with deps).
|
|
485
|
+
*/
|
|
486
|
+
interface VerifyStripeWebhookResult {
|
|
487
|
+
ok: boolean;
|
|
488
|
+
timestamp?: number;
|
|
489
|
+
error?: string;
|
|
490
|
+
}
|
|
491
|
+
interface VerifyStripeWebhookOptions {
|
|
492
|
+
toleranceSec?: number;
|
|
493
|
+
/** Injectable for deterministic tests. */
|
|
494
|
+
now?: () => number;
|
|
495
|
+
}
|
|
496
|
+
declare function verifyStripeWebhook(payload: string, signatureHeader: string | undefined, secret: string, options?: VerifyStripeWebhookOptions): VerifyStripeWebhookResult;
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* PDLSS constraint evaluation.
|
|
500
|
+
*
|
|
501
|
+
* Evaluates VI constraint types 1-4 (merchant/payee allowlists, line items,
|
|
502
|
+
* payment amount) + MPP/x402 payment-method allowlist + spending-limit
|
|
503
|
+
* against a transaction context.
|
|
504
|
+
*
|
|
505
|
+
* Types 5/6/7 (budget, recurrence, agent_recurrence) extract through but
|
|
506
|
+
* enforcement is deferred to the cross-merchant budget service.
|
|
507
|
+
* This module returns per-constraint {ok, reason} results
|
|
508
|
+
* so a policy layer can decide hard-deny vs trust-signal.
|
|
509
|
+
*/
|
|
510
|
+
|
|
511
|
+
interface TransactionContext {
|
|
512
|
+
amount?: number;
|
|
513
|
+
currency?: string;
|
|
514
|
+
merchant?: {
|
|
515
|
+
id?: string;
|
|
516
|
+
website?: string;
|
|
517
|
+
};
|
|
518
|
+
payee?: {
|
|
519
|
+
id?: string;
|
|
520
|
+
website?: string;
|
|
521
|
+
};
|
|
522
|
+
lineItems?: Array<{
|
|
523
|
+
id?: string;
|
|
524
|
+
quantity?: number;
|
|
525
|
+
}>;
|
|
526
|
+
/** For MPP / x402 payment-method enforcement. */
|
|
527
|
+
paymentMethod?: string;
|
|
528
|
+
}
|
|
529
|
+
type ConstraintKey = 'merchant' | 'payee' | 'lineItems' | 'amount' | 'paymentMethod';
|
|
530
|
+
interface ConstraintResult {
|
|
531
|
+
ok: boolean;
|
|
532
|
+
reason?: string;
|
|
533
|
+
}
|
|
534
|
+
interface ConstraintEvalResult {
|
|
535
|
+
ok: boolean;
|
|
536
|
+
results: Record<string, ConstraintResult>;
|
|
537
|
+
reasons: string[];
|
|
538
|
+
}
|
|
539
|
+
interface VIConstraintEvalInput {
|
|
540
|
+
constraints: VIConstraints;
|
|
541
|
+
transaction: TransactionContext;
|
|
542
|
+
}
|
|
543
|
+
declare function evaluateVIConstraints(input: VIConstraintEvalInput): ConstraintEvalResult;
|
|
544
|
+
interface PaymentMethodAllowlistInput {
|
|
545
|
+
allowedMethods?: string[];
|
|
546
|
+
requestedMethod?: string;
|
|
547
|
+
}
|
|
548
|
+
declare function evaluatePaymentMethodAllowlist(input: PaymentMethodAllowlistInput): ConstraintResult;
|
|
549
|
+
interface SpendingLimitInput {
|
|
550
|
+
limit?: {
|
|
551
|
+
amount?: number;
|
|
552
|
+
currency?: string;
|
|
553
|
+
};
|
|
554
|
+
requested?: {
|
|
555
|
+
amount?: number;
|
|
556
|
+
currency?: string;
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
declare function evaluateSpendingLimit(input: SpendingLimitInput): ConstraintResult;
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Cross-protocol agent identity binding.
|
|
563
|
+
*
|
|
564
|
+
* Every commerce layer claims an agent identity differently:
|
|
565
|
+
* - VI L3 kid (SD-JWT header)
|
|
566
|
+
* - AP2 agent_id (mandate payload)
|
|
567
|
+
* - ACP Authorization: Bearer token (merchant-issued pre-shared)
|
|
568
|
+
* - MPP Credential `source` field (DID or chain-native key)
|
|
569
|
+
* - x402 client wallet address
|
|
570
|
+
* - RFC 9421 kid (Agent Pay / TAP / Web Bot Auth)
|
|
571
|
+
*
|
|
572
|
+
* This module maps any such claim to a single AstraSync agent via a
|
|
573
|
+
* caller-supplied resolver (typically delegates to the counterparty service),
|
|
574
|
+
* then flags whether multiple claims on the same request resolve to different
|
|
575
|
+
* agents (a trust signal for PDLSS).
|
|
576
|
+
*
|
|
577
|
+
* This is AstraSync whitespace — no vendor owns multi-protocol identity
|
|
578
|
+
* unification.
|
|
579
|
+
*/
|
|
580
|
+
interface IdentityClaim {
|
|
581
|
+
/** Originating protocol label: 'vi' | 'ap2' | 'acp' | 'mpp' | 'x402' | 'agentpay' | 'tap' | 'webbotauth' */
|
|
582
|
+
protocol: string;
|
|
583
|
+
/** Claim field name, e.g. 'kid', 'agent_id', 'source', 'bearer'. */
|
|
584
|
+
field: string;
|
|
585
|
+
/** Claim value as presented on the wire. */
|
|
586
|
+
value: string;
|
|
587
|
+
}
|
|
588
|
+
interface IdentityBindingResult {
|
|
589
|
+
claims: IdentityClaim[];
|
|
590
|
+
mappedAstraSyncAgentId?: string;
|
|
591
|
+
/**
|
|
592
|
+
* True when two or more claims resolve to different AstraSync agents.
|
|
593
|
+
* Surfaced as a trust signal rather than an auto-deny — legitimate flows
|
|
594
|
+
* (e.g. delegate payments) can legitimately carry multiple identities.
|
|
595
|
+
*/
|
|
596
|
+
mismatchAcrossLayers: boolean;
|
|
597
|
+
/** Per-claim resolution result for audit / debugging. */
|
|
598
|
+
resolutions: Array<{
|
|
599
|
+
claim: IdentityClaim;
|
|
600
|
+
agentId: string | null;
|
|
601
|
+
}>;
|
|
602
|
+
}
|
|
603
|
+
type IdentityResolver = (claim: IdentityClaim) => Promise<string | null>;
|
|
604
|
+
declare function bindIdentity(claims: IdentityClaim[], resolver: IdentityResolver): Promise<IdentityBindingResult>;
|
|
605
|
+
/**
|
|
606
|
+
* Helper constructors — keep protocol/field strings consistent across the
|
|
607
|
+
* codebase and make tests readable.
|
|
608
|
+
*/
|
|
609
|
+
declare const claim: {
|
|
610
|
+
viKid: (value: string) => IdentityClaim;
|
|
611
|
+
ap2AgentId: (value: string) => IdentityClaim;
|
|
612
|
+
acpBearer: (value: string) => IdentityClaim;
|
|
613
|
+
mppSource: (value: string) => IdentityClaim;
|
|
614
|
+
x402Wallet: (value: string) => IdentityClaim;
|
|
615
|
+
agentPayKid: (value: string) => IdentityClaim;
|
|
616
|
+
tapKid: (value: string) => IdentityClaim;
|
|
617
|
+
webBotAuthKid: (value: string) => IdentityClaim;
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* AP2 (Agent Payments Protocol) mandate extraction.
|
|
622
|
+
*
|
|
623
|
+
* Google-led, launched 3 April 2026 with 60+ partners (Mastercard, PayPal,
|
|
624
|
+
* Coinbase, AmEx, Revolut, UnionPay, ...). AP2 ships three mandate types as
|
|
625
|
+
* SD-JWTs in series:
|
|
626
|
+
* - intent_mandate — user declares intent (amount, merchant category, etc.)
|
|
627
|
+
* - cart_mandate — user approves a cart (specific items, totals)
|
|
628
|
+
* - payment_mandate — authorizes the actual payment rail
|
|
629
|
+
*
|
|
630
|
+
* Mandates are cross-referenced via ids; each is an SD-JWT over ES256 (or
|
|
631
|
+
* equivalent). We decode via @sd-jwt/core and extract the AP2-specific
|
|
632
|
+
* shape — verification lives in ap2-verify.ts.
|
|
633
|
+
*/
|
|
634
|
+
|
|
635
|
+
interface AP2PaymentDetailsTotal {
|
|
636
|
+
amount?: {
|
|
637
|
+
value?: string | number;
|
|
638
|
+
currency?: string;
|
|
639
|
+
};
|
|
640
|
+
label?: string;
|
|
641
|
+
}
|
|
642
|
+
interface AP2IntentMandateClaims {
|
|
643
|
+
type: 'intent_mandate';
|
|
644
|
+
agent_id?: string;
|
|
645
|
+
user_id?: string;
|
|
646
|
+
merchant_category?: string;
|
|
647
|
+
allowedMerchantDomains?: string[];
|
|
648
|
+
paymentMethods?: string[];
|
|
649
|
+
expires?: string;
|
|
650
|
+
payment_details_total?: AP2PaymentDetailsTotal;
|
|
651
|
+
raw: Record<string, unknown>;
|
|
652
|
+
}
|
|
653
|
+
interface AP2CartMandateClaims {
|
|
654
|
+
type: 'cart_mandate';
|
|
655
|
+
agent_id?: string;
|
|
656
|
+
intent_mandate_id?: string;
|
|
657
|
+
merchant_id?: string;
|
|
658
|
+
line_items?: Array<{
|
|
659
|
+
id?: string;
|
|
660
|
+
quantity?: number;
|
|
661
|
+
price?: {
|
|
662
|
+
value?: string | number;
|
|
663
|
+
currency?: string;
|
|
664
|
+
};
|
|
665
|
+
}>;
|
|
666
|
+
payment_details_total?: AP2PaymentDetailsTotal;
|
|
667
|
+
expires?: string;
|
|
668
|
+
raw: Record<string, unknown>;
|
|
669
|
+
}
|
|
670
|
+
interface AP2PaymentMandateClaims {
|
|
671
|
+
type: 'payment_mandate';
|
|
672
|
+
agent_id?: string;
|
|
673
|
+
cart_mandate_id?: string;
|
|
674
|
+
payment_method?: string;
|
|
675
|
+
payment_details_total?: AP2PaymentDetailsTotal;
|
|
676
|
+
credential_provider?: string;
|
|
677
|
+
raw: Record<string, unknown>;
|
|
678
|
+
}
|
|
679
|
+
type AP2MandateClaims = AP2IntentMandateClaims | AP2CartMandateClaims | AP2PaymentMandateClaims;
|
|
680
|
+
interface AP2MandateTriple {
|
|
681
|
+
intent?: AP2IntentMandateClaims;
|
|
682
|
+
cart?: AP2CartMandateClaims;
|
|
683
|
+
payment?: AP2PaymentMandateClaims;
|
|
684
|
+
rawLayers: {
|
|
685
|
+
intentJwt?: string;
|
|
686
|
+
cartJwt?: string;
|
|
687
|
+
paymentJwt?: string;
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Extract a single AP2 mandate from a compact SD-JWT.
|
|
692
|
+
* Returns null if the SD-JWT is malformed or lacks a recognized type field.
|
|
693
|
+
*/
|
|
694
|
+
declare function extractAP2Mandate(sdJwtCompact: string): AP2MandateClaims | null;
|
|
695
|
+
interface AP2MandateTripleInput {
|
|
696
|
+
intent?: string;
|
|
697
|
+
cart?: string;
|
|
698
|
+
payment?: string;
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Extract an intent / cart / payment triple, returning whichever are present.
|
|
702
|
+
* Does NOT enforce cross-reference consistency — that's ap2-verify.ts's job.
|
|
703
|
+
*/
|
|
704
|
+
declare function extractAP2Mandates(input: AP2MandateTripleInput): AP2MandateTriple;
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* AP2 mandate chain verification.
|
|
708
|
+
*
|
|
709
|
+
* Checks the cross-reference consistency of an intent → cart → payment
|
|
710
|
+
* triple. Does NOT verify cryptographic signatures here (that's a call to
|
|
711
|
+
* @sd-jwt/core which needs the agent's / CP's public key; expose via a
|
|
712
|
+
* verifier callback so pipeline can plug in the right resolver).
|
|
713
|
+
*
|
|
714
|
+
* Rules (per AP2 spec v0.1-draft):
|
|
715
|
+
* - cart.intent_mandate_id must equal the intent mandate's canonical id (if present)
|
|
716
|
+
* - payment.cart_mandate_id must equal the cart mandate's canonical id (if present)
|
|
717
|
+
* - agent_id must match across all three layers
|
|
718
|
+
* - payment_method in payment mandate must be in intent.paymentMethods (if declared)
|
|
719
|
+
* - cart totals must not exceed intent totals (if both declared in same currency)
|
|
720
|
+
* - no mandate may be expired (beyond clock skew)
|
|
721
|
+
*/
|
|
722
|
+
|
|
723
|
+
interface AP2VerifyInput {
|
|
724
|
+
triple: AP2MandateTriple;
|
|
725
|
+
/**
|
|
726
|
+
* Clock skew tolerance in seconds for expiry checks. Default 60s
|
|
727
|
+
* (tightened from the previous 300s default).
|
|
728
|
+
*/
|
|
729
|
+
clockSkewSec?: number;
|
|
730
|
+
now?: () => number;
|
|
731
|
+
/**
|
|
732
|
+
* Optional replay-protection store. Defaults to in-process LRU. When the
|
|
733
|
+
* payment mandate carries an id, this verifier registers it as seen so
|
|
734
|
+
* the same payment mandate replayed within the expiry window is rejected.
|
|
735
|
+
*/
|
|
736
|
+
nonceStore?: NonceStore;
|
|
737
|
+
}
|
|
738
|
+
interface AP2ChainResult {
|
|
739
|
+
ok: boolean;
|
|
740
|
+
checks: {
|
|
741
|
+
intentPresent: boolean;
|
|
742
|
+
cartRefOk: boolean;
|
|
743
|
+
paymentRefOk: boolean;
|
|
744
|
+
agentIdContinuity: boolean;
|
|
745
|
+
paymentMethodAllowed: boolean;
|
|
746
|
+
totalsConsistent: boolean;
|
|
747
|
+
expiryOk: boolean;
|
|
748
|
+
};
|
|
749
|
+
agentId?: string;
|
|
750
|
+
errors: string[];
|
|
751
|
+
}
|
|
752
|
+
declare function verifyAP2Chain(input: AP2VerifyInput): AP2ChainResult;
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* ACP detached-JSON-signature verifier.
|
|
756
|
+
*
|
|
757
|
+
* ACP (Agentic Commerce Protocol, OpenAI + Stripe) uses detached JSON
|
|
758
|
+
* signatures over request bodies. The public signature algorithm is NOT
|
|
759
|
+
* specified in open docs as of April 2026 (docs.stripe.com/agentic-commerce/*
|
|
760
|
+
* is Private Preview). We implement Ed25519 and ES256 candidates against
|
|
761
|
+
* whichever public key the caller supplies, and report algorithm-unsupported
|
|
762
|
+
* as a trust signal rather than a hard fail so policy can weight it.
|
|
763
|
+
*
|
|
764
|
+
* Timestamp freshness (>300s default) IS a hard fail — prevents replay.
|
|
765
|
+
*
|
|
766
|
+
* Bearer-token → AstraSync agent binding is delegated to caller-supplied
|
|
767
|
+
* resolver (typically the counterparty service).
|
|
768
|
+
*/
|
|
769
|
+
|
|
770
|
+
type ACPSignatureAlgorithm = 'ed25519' | 'es256' | 'unsupported';
|
|
771
|
+
interface ACPVerifyInput {
|
|
772
|
+
/** Raw request body over which the signature was computed. */
|
|
773
|
+
rawBody: string;
|
|
774
|
+
/** Value of the Signature header. Expected to be base64 (either standard or url). */
|
|
775
|
+
signatureHeader?: string;
|
|
776
|
+
/** Value of the Timestamp header (unix seconds as string, or ISO 8601). */
|
|
777
|
+
timestampHeader?: string;
|
|
778
|
+
/** Candidate public keys to try. First matching algorithm wins. */
|
|
779
|
+
candidateKeys: Array<{
|
|
780
|
+
jwk: JWK;
|
|
781
|
+
alg?: ACPSignatureAlgorithm | string;
|
|
782
|
+
}>;
|
|
783
|
+
/** Clock skew tolerance in seconds (default 60, tightened from 300). */
|
|
784
|
+
clockSkewSec?: number;
|
|
785
|
+
/** Injectable now for tests. */
|
|
786
|
+
now?: () => number;
|
|
787
|
+
/** Optional replay-protection store. Defaults to in-process LRU. */
|
|
788
|
+
nonceStore?: NonceStore;
|
|
789
|
+
}
|
|
790
|
+
interface ACPVerifyResult {
|
|
791
|
+
ok: boolean;
|
|
792
|
+
algorithm?: ACPSignatureAlgorithm;
|
|
793
|
+
error?: string;
|
|
794
|
+
/** True when timestamp is outside tolerance. */
|
|
795
|
+
timestampStale?: boolean;
|
|
796
|
+
}
|
|
797
|
+
declare function verifyACPSignature(input: ACPVerifyInput): Promise<ACPVerifyResult>;
|
|
798
|
+
|
|
799
|
+
/**
|
|
800
|
+
* MPP (Machine Payments Protocol) extractor.
|
|
801
|
+
*
|
|
802
|
+
* Wraps mppx (wevm) — pinned to 0.5.13, wrapped behind this adapter so
|
|
803
|
+
* upgrades localise here. MPP launched March 18 2026 (Stripe + Tempo +
|
|
804
|
+
* Paradigm), IETF draft-ryan-httpauth-payment-01.
|
|
805
|
+
*
|
|
806
|
+
* Flow:
|
|
807
|
+
* Client → GET /resource
|
|
808
|
+
* Server → 402 + WWW-Authenticate: Payment id=..., realm=..., method=tempo|stripe|...
|
|
809
|
+
* Client → GET /resource with Authorization: Payment <base64url-json credential>
|
|
810
|
+
* Server → 200 + Payment-Receipt: <base64url-json receipt>
|
|
811
|
+
*
|
|
812
|
+
* What we extract:
|
|
813
|
+
* - Challenge: id, realm, method, intent, request{amount,currency,...}, expires, digest
|
|
814
|
+
* - Credential: challenge + source (DID/chain-key) + payload (method-specific)
|
|
815
|
+
* - Receipt: challengeId, method, reference (tx hash / pi_... ID), settlement
|
|
816
|
+
* - Multi-method 402 offers (may be multiple WWW-Authenticate headers)
|
|
817
|
+
*
|
|
818
|
+
* What we do NOT verify here (pass-through):
|
|
819
|
+
* - HMAC challenge binding (requires merchant's MPP_SECRET_KEY)
|
|
820
|
+
* - Payment proof cryptography (Tempo tx sig, Stripe SPT, Lightning preimage)
|
|
821
|
+
* — each requires upstream connectivity
|
|
822
|
+
*
|
|
823
|
+
* Verification (expiry + BodyDigest + source extraction) in mpp-verify.ts.
|
|
824
|
+
*/
|
|
825
|
+
interface MPPChallengeSummary {
|
|
826
|
+
id: string;
|
|
827
|
+
realm: string;
|
|
828
|
+
method: string;
|
|
829
|
+
intent: string;
|
|
830
|
+
/** Method-specific request data (amount, currency, recipient, etc.) */
|
|
831
|
+
request: Record<string, unknown>;
|
|
832
|
+
expires?: string;
|
|
833
|
+
digest?: string;
|
|
834
|
+
description?: string;
|
|
835
|
+
opaque?: Record<string, string>;
|
|
836
|
+
}
|
|
837
|
+
interface MPPCredentialSummary {
|
|
838
|
+
challenge: MPPChallengeSummary;
|
|
839
|
+
/** DID or chain-native key identifying the payer. */
|
|
840
|
+
source?: string;
|
|
841
|
+
/** Method-specific payment proof (Tempo tx, SPT, Lightning preimage, etc.). */
|
|
842
|
+
payload: unknown;
|
|
843
|
+
}
|
|
844
|
+
interface MPPReceiptSummary {
|
|
845
|
+
method?: string;
|
|
846
|
+
reference?: string;
|
|
847
|
+
externalId?: string;
|
|
848
|
+
status?: string;
|
|
849
|
+
timestamp?: string;
|
|
850
|
+
raw: Record<string, unknown>;
|
|
851
|
+
}
|
|
852
|
+
type MPPKind = 'challenge' | 'credential' | 'receipt' | 'error' | 'unknown';
|
|
853
|
+
interface MPPRequestContext {
|
|
854
|
+
kind: MPPKind;
|
|
855
|
+
/** For 402 responses: one or more challenge offers. */
|
|
856
|
+
challenges?: MPPChallengeSummary[];
|
|
857
|
+
/** For requests with Authorization: Payment header. */
|
|
858
|
+
credential?: MPPCredentialSummary;
|
|
859
|
+
/** For 200 responses with Payment-Receipt header. */
|
|
860
|
+
receipt?: MPPReceiptSummary;
|
|
861
|
+
/** For problem+json error responses. */
|
|
862
|
+
error?: {
|
|
863
|
+
type?: string;
|
|
864
|
+
title?: string;
|
|
865
|
+
detail?: string;
|
|
866
|
+
};
|
|
867
|
+
/** Detected payment methods offered (for multi-method 402). */
|
|
868
|
+
offeredMethods?: string[];
|
|
869
|
+
/** Raw body captured for BodyDigest verification in mpp-verify.ts. */
|
|
870
|
+
rawBody?: string;
|
|
871
|
+
}
|
|
872
|
+
interface MPPRequestLike {
|
|
873
|
+
method: string;
|
|
874
|
+
url: string;
|
|
875
|
+
headers: Record<string, string | string[] | undefined>;
|
|
876
|
+
body?: unknown;
|
|
877
|
+
rawBody?: string;
|
|
878
|
+
}
|
|
879
|
+
interface MPPResponseLike {
|
|
880
|
+
status: number;
|
|
881
|
+
headers: Record<string, string | string[] | undefined>;
|
|
882
|
+
body?: unknown;
|
|
883
|
+
rawBody?: string;
|
|
884
|
+
}
|
|
885
|
+
/**
|
|
886
|
+
* Extract MPP context from an agent → merchant request.
|
|
887
|
+
* Looks for `Authorization: Payment <credential>` header.
|
|
888
|
+
*/
|
|
889
|
+
declare function extractMPPFromRequest(request: MPPRequestLike): MPPRequestContext | null;
|
|
890
|
+
/**
|
|
891
|
+
* Extract MPP context from a merchant → agent response.
|
|
892
|
+
* Handles 402 (challenge offers), 200 (receipt), 4xx (problem+json errors).
|
|
893
|
+
*/
|
|
894
|
+
declare function extractMPPFromResponse(response: MPPResponseLike): MPPRequestContext | null;
|
|
895
|
+
/**
|
|
896
|
+
* Extract from either a request OR a response, auto-detecting which has MPP
|
|
897
|
+
* artifacts. Convenience for pipeline callers.
|
|
898
|
+
*/
|
|
899
|
+
declare function extractMPPContext(message: {
|
|
900
|
+
request: MPPRequestLike;
|
|
901
|
+
} | {
|
|
902
|
+
response: MPPResponseLike;
|
|
903
|
+
} | (MPPRequestLike & Partial<MPPResponseLike>)): MPPRequestContext | null;
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* MPP verification — expiry + optional BodyDigest + source extraction.
|
|
907
|
+
*
|
|
908
|
+
* We do NOT verify the challenge's HMAC binding (needs merchant's secret)
|
|
909
|
+
* or the cryptographic payment proof (per-method, requires upstream
|
|
910
|
+
* connectivity). Those are the merchant's / settlement layer's job.
|
|
911
|
+
*
|
|
912
|
+
* Our job: structural correctness, expiry policy, tamper detection via
|
|
913
|
+
* optional BodyDigest, and identity extraction for PDLSS binding.
|
|
914
|
+
*/
|
|
915
|
+
|
|
916
|
+
interface MPPVerifyInput {
|
|
917
|
+
context: MPPRequestContext;
|
|
918
|
+
/** Raw request body to validate BodyDigest against, if the challenge declares one. */
|
|
919
|
+
rawBody?: string;
|
|
920
|
+
/** Seconds of clock-skew tolerance on challenge.expires. Default 60. */
|
|
921
|
+
clockSkewSec?: number;
|
|
922
|
+
/** Injectable for deterministic tests. */
|
|
923
|
+
now?: () => number;
|
|
924
|
+
/** Optional replay-protection store. Defaults to in-process LRU. */
|
|
925
|
+
nonceStore?: NonceStore;
|
|
926
|
+
}
|
|
927
|
+
interface MPPVerifyResult {
|
|
928
|
+
ok: boolean;
|
|
929
|
+
expiryOk: boolean;
|
|
930
|
+
bodyDigestOk: boolean | null;
|
|
931
|
+
source?: string;
|
|
932
|
+
method?: string;
|
|
933
|
+
error?: string;
|
|
934
|
+
}
|
|
935
|
+
declare function verifyMPP(input: MPPVerifyInput): MPPVerifyResult;
|
|
936
|
+
|
|
937
|
+
/**
|
|
938
|
+
* x402 (Coinbase / Linux Foundation x402 Foundation) extractor.
|
|
939
|
+
*
|
|
940
|
+
* Wraps @x402/core's schema parsers. x402 Foundation launched April 2 2026
|
|
941
|
+
* with v2 adding network-agnostic identifiers + multiple facilitators +
|
|
942
|
+
* Bazaar discovery. MPP (Machine Payments Protocol) is the IETF-formalised
|
|
943
|
+
* superset of x402; this module normalizes x402 output to MPP-shape so
|
|
944
|
+
* downstream pipeline code is uniform.
|
|
945
|
+
*
|
|
946
|
+
* Where x402 lives on the wire:
|
|
947
|
+
* - 402 response body (v2) OR `X-PAYMENT-REQUIRED` header (v1) — PaymentRequired
|
|
948
|
+
* - Request body (v2) OR `X-PAYMENT` header (v1, base64) — PaymentPayload
|
|
949
|
+
*/
|
|
950
|
+
type X402Kind = 'required' | 'payload' | 'error' | 'unknown';
|
|
951
|
+
interface X402RequirementsSummary {
|
|
952
|
+
scheme: string;
|
|
953
|
+
network: string;
|
|
954
|
+
asset: string;
|
|
955
|
+
/** Normalized to string for v1/v2 compat — v1 uses maxAmountRequired, v2 uses amount. */
|
|
956
|
+
amount: string;
|
|
957
|
+
payTo: string;
|
|
958
|
+
maxTimeoutSeconds?: number;
|
|
959
|
+
resource?: string;
|
|
960
|
+
description?: string;
|
|
961
|
+
}
|
|
962
|
+
interface X402RequestContext {
|
|
963
|
+
kind: X402Kind;
|
|
964
|
+
version: 1 | 2 | null;
|
|
965
|
+
/** For 402 responses: the PaymentRequired body. */
|
|
966
|
+
paymentRequired?: {
|
|
967
|
+
resource: string;
|
|
968
|
+
accepts: X402RequirementsSummary[];
|
|
969
|
+
extensions?: Record<string, unknown>;
|
|
970
|
+
error?: string;
|
|
971
|
+
};
|
|
972
|
+
/** For request body (v2) or X-PAYMENT header (v1 base64): the PaymentPayload. */
|
|
973
|
+
paymentPayload?: {
|
|
974
|
+
scheme: string;
|
|
975
|
+
network: string;
|
|
976
|
+
/** Free-form per-scheme payload (e.g. EIP-3009 authorization, Solana tx). */
|
|
977
|
+
payload: Record<string, unknown>;
|
|
978
|
+
extensions?: Record<string, unknown>;
|
|
979
|
+
};
|
|
980
|
+
error?: {
|
|
981
|
+
type: string;
|
|
982
|
+
detail?: string;
|
|
983
|
+
};
|
|
984
|
+
/** Whether this was parsed from a header (v1 back-compat) or body (v2). */
|
|
985
|
+
source: 'header' | 'body' | null;
|
|
986
|
+
}
|
|
987
|
+
interface X402RequestLike {
|
|
988
|
+
method?: string;
|
|
989
|
+
url?: string;
|
|
990
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
991
|
+
body?: unknown;
|
|
992
|
+
}
|
|
993
|
+
interface X402ResponseLike {
|
|
994
|
+
status?: number;
|
|
995
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
996
|
+
body?: unknown;
|
|
997
|
+
}
|
|
998
|
+
/**
|
|
999
|
+
* Extract x402 PaymentPayload from an agent → merchant request.
|
|
1000
|
+
* Checks v2 body (if it parses as PaymentPayload) and v1 X-PAYMENT header.
|
|
1001
|
+
*/
|
|
1002
|
+
declare function extractX402FromRequest(request: X402RequestLike): X402RequestContext | null;
|
|
1003
|
+
/**
|
|
1004
|
+
* Extract x402 PaymentRequired from a merchant → agent 402 response.
|
|
1005
|
+
*/
|
|
1006
|
+
declare function extractX402FromResponse(response: X402ResponseLike): X402RequestContext | null;
|
|
1007
|
+
declare function extractX402Context(message: {
|
|
1008
|
+
request: X402RequestLike;
|
|
1009
|
+
} | {
|
|
1010
|
+
response: X402ResponseLike;
|
|
1011
|
+
} | (X402RequestLike & Partial<X402ResponseLike>)): X402RequestContext | null;
|
|
1012
|
+
|
|
1013
|
+
/**
|
|
1014
|
+
* VI (Verifiable Intent) 3-layer SD-JWT chain verification.
|
|
1015
|
+
*
|
|
1016
|
+
* VI chains: L1 (credential provider → wallet) → L2 (user → agent) → L3
|
|
1017
|
+
* (agent → merchant). L3 itself can split into L3a (payment mandate) + L3b
|
|
1018
|
+
* (checkout mandate) cross-referenced via transaction_id, with L3b carrying
|
|
1019
|
+
* a checkout_hash (VI constraint type 8) that must match SHA-256 of the L2
|
|
1020
|
+
* checkout disclosure.
|
|
1021
|
+
*
|
|
1022
|
+
* Signature primitives are delegated to @sd-jwt/core (via our extractor);
|
|
1023
|
+
* cnf.jwk chain-walking + cross-references + checkout_hash binding is
|
|
1024
|
+
* AstraSync-specific composition logic — that's the whitespace here.
|
|
1025
|
+
*
|
|
1026
|
+
* This module does NOT re-verify selective-disclosure hashes (the extractor
|
|
1027
|
+
* already applied them via @sd-jwt/core). It DOES verify:
|
|
1028
|
+
* - cnf.jwk in L1 payload points to L2's signing key (thumbprint match)
|
|
1029
|
+
* - cnf.jwk in L2 payload points to L3's signing key
|
|
1030
|
+
* - L3a.transaction_id === L3b.transaction_id (when both present)
|
|
1031
|
+
* - L3b.checkout_hash === SHA-256(L2 canonical checkout disclosure) — type 8
|
|
1032
|
+
* - mandate-level `exp` is not in the past (beyond clock skew)
|
|
1033
|
+
*
|
|
1034
|
+
* Cryptographic signature verification on each layer uses the verifier
|
|
1035
|
+
* callback the caller supplies (e.g. resolves via @sd-jwt/core with the
|
|
1036
|
+
* right JWK from the L1 issuer's JWKS).
|
|
1037
|
+
*/
|
|
1038
|
+
|
|
1039
|
+
interface VILayer {
|
|
1040
|
+
/** Compact SD-JWT / JWS for this layer. */
|
|
1041
|
+
compact: string;
|
|
1042
|
+
/** Decoded JWT payload (already disclosure-merged). */
|
|
1043
|
+
payload: Record<string, unknown>;
|
|
1044
|
+
/** Decoded JWT header. */
|
|
1045
|
+
header: Record<string, unknown>;
|
|
1046
|
+
}
|
|
1047
|
+
interface VIVerifyInput {
|
|
1048
|
+
/**
|
|
1049
|
+
* Layers in chain order. L1 is REQUIRED by default —
|
|
1050
|
+
* without L1 there is no chain root and L2 can be verified against any
|
|
1051
|
+
* attacker-supplied key. Callers who have resolved L2's signing key by
|
|
1052
|
+
* a trusted out-of-band mechanism (wallet binding, prior protocol step)
|
|
1053
|
+
* MUST set `allowUnboundChain: true` AND supply `expectedL2Key`.
|
|
1054
|
+
*/
|
|
1055
|
+
layers: {
|
|
1056
|
+
l1?: VILayer;
|
|
1057
|
+
l2: VILayer;
|
|
1058
|
+
l3a?: VILayer;
|
|
1059
|
+
l3b?: VILayer;
|
|
1060
|
+
};
|
|
1061
|
+
/**
|
|
1062
|
+
* Verifier callback invoked per layer. Should return true iff the layer's
|
|
1063
|
+
* JWS signature verifies against the resolved public key (for L2 this is
|
|
1064
|
+
* L1's cnf.jwk; for L3 this is L2's cnf.jwk; for L1 this is the issuer's
|
|
1065
|
+
* JWKS per `iss` claim).
|
|
1066
|
+
*/
|
|
1067
|
+
verifySignature: (layer: VILayer, expectedKey: JWK | null) => Promise<boolean>;
|
|
1068
|
+
/**
|
|
1069
|
+
* Clock skew tolerance in seconds for expiry checks. Default 60s
|
|
1070
|
+
* (tightened from the previous 300s default).
|
|
1071
|
+
*/
|
|
1072
|
+
clockSkewSec?: number;
|
|
1073
|
+
now?: () => number;
|
|
1074
|
+
/**
|
|
1075
|
+
* Explicit opt-in to verify a chain with L1 omitted.
|
|
1076
|
+
* Defaults to false. When true, `expectedL2Key` MUST also be supplied
|
|
1077
|
+
* (used as the expected signing key for L2 verification).
|
|
1078
|
+
*/
|
|
1079
|
+
allowUnboundChain?: boolean;
|
|
1080
|
+
/** Required when allowUnboundChain === true. */
|
|
1081
|
+
expectedL2Key?: JWK;
|
|
1082
|
+
/** Optional replay-protection store. Defaults to in-process LRU. */
|
|
1083
|
+
nonceStore?: NonceStore;
|
|
1084
|
+
}
|
|
1085
|
+
interface VIVerifyResult {
|
|
1086
|
+
ok: boolean;
|
|
1087
|
+
checks: {
|
|
1088
|
+
l1SigOk: boolean | null;
|
|
1089
|
+
l2SigOk: boolean;
|
|
1090
|
+
l3aSigOk: boolean | null;
|
|
1091
|
+
l3bSigOk: boolean | null;
|
|
1092
|
+
l1BindsL2: boolean;
|
|
1093
|
+
l2BindsL3: boolean;
|
|
1094
|
+
l3aL3bTxnIdMatch: boolean | null;
|
|
1095
|
+
checkoutHashOk: boolean | null;
|
|
1096
|
+
expiryOk: boolean;
|
|
1097
|
+
};
|
|
1098
|
+
errors: string[];
|
|
1099
|
+
}
|
|
1100
|
+
declare function verifyVIChain(input: VIVerifyInput): Promise<VIVerifyResult>;
|
|
1101
|
+
|
|
1102
|
+
/**
|
|
1103
|
+
* Commerce pipeline orchestrator.
|
|
1104
|
+
*
|
|
1105
|
+
* Ties together extractors + verifiers + identity binding + constraint
|
|
1106
|
+
* evaluation + trust signals into a single CommerceContext result.
|
|
1107
|
+
*
|
|
1108
|
+
* This is AstraSync whitespace: the orchestration over the library-backed
|
|
1109
|
+
* primitives. The backend verify-access service is the sole per-request
|
|
1110
|
+
* caller — the edge adapters forward raw artifacts to verify-access and
|
|
1111
|
+
* never call this module directly. The admin transport playground also
|
|
1112
|
+
* calls it ad-hoc.
|
|
1113
|
+
*
|
|
1114
|
+
* Policy:
|
|
1115
|
+
* - Hard-deny (ok=false) on bad signatures, expired mandates, constraint
|
|
1116
|
+
* failures, identity cannot be bound.
|
|
1117
|
+
* - Trust signal (ok remains policy-driven) on ACP algorithm unsupported,
|
|
1118
|
+
* Stripe webhook HMAC fail, payment-token type unknown, cross-layer
|
|
1119
|
+
* identity mismatch.
|
|
1120
|
+
*/
|
|
1121
|
+
|
|
1122
|
+
type CommerceProtocol = 'vi' | 'ap2' | 'ucp' | 'acp' | 'agentpay' | 'tap' | 'mpp' | 'x402';
|
|
1123
|
+
interface CommercePipelineInput {
|
|
1124
|
+
protocol: CommerceProtocol;
|
|
1125
|
+
vi?: {
|
|
1126
|
+
claims: VIExtractedClaims;
|
|
1127
|
+
verifyInput?: VIVerifyInput;
|
|
1128
|
+
};
|
|
1129
|
+
ap2?: {
|
|
1130
|
+
triple: AP2MandateTriple;
|
|
1131
|
+
};
|
|
1132
|
+
ucp?: UCPCheckoutContext;
|
|
1133
|
+
acp?: {
|
|
1134
|
+
context: ACPRequestContext;
|
|
1135
|
+
verifyInput?: Parameters<typeof verifyACPSignature>[0];
|
|
1136
|
+
};
|
|
1137
|
+
rfc9421?: {
|
|
1138
|
+
request: RFC9421VerifyRequest;
|
|
1139
|
+
tag?: 'browse' | 'purchase' | string;
|
|
1140
|
+
verifyOptions: Parameters<typeof verifyRFC9421>[1];
|
|
1141
|
+
};
|
|
1142
|
+
mpp?: {
|
|
1143
|
+
context: MPPRequestContext;
|
|
1144
|
+
rawBody?: string;
|
|
1145
|
+
};
|
|
1146
|
+
x402?: X402RequestContext;
|
|
1147
|
+
stripeWebhook?: {
|
|
1148
|
+
payload: string;
|
|
1149
|
+
signatureHeader: string;
|
|
1150
|
+
secret: string;
|
|
1151
|
+
};
|
|
1152
|
+
transaction?: TransactionContext;
|
|
1153
|
+
registeredConstraints?: {
|
|
1154
|
+
allowedPaymentMethods?: string[];
|
|
1155
|
+
spendingLimit?: {
|
|
1156
|
+
amount?: number;
|
|
1157
|
+
currency?: string;
|
|
1158
|
+
};
|
|
1159
|
+
};
|
|
1160
|
+
identityResolver?: IdentityResolver;
|
|
1161
|
+
clockSkewSec?: number;
|
|
1162
|
+
now?: () => number;
|
|
1163
|
+
}
|
|
1164
|
+
interface CommerceSignatureStack {
|
|
1165
|
+
vi?: VIVerifyResult;
|
|
1166
|
+
ap2?: AP2ChainResult;
|
|
1167
|
+
acp?: ACPVerifyResult;
|
|
1168
|
+
rfc9421?: RFC9421VerifyResult;
|
|
1169
|
+
mpp?: MPPVerifyResult;
|
|
1170
|
+
stripeWebhook?: VerifyStripeWebhookResult;
|
|
1171
|
+
}
|
|
1172
|
+
interface CommerceContext {
|
|
1173
|
+
protocol: CommerceProtocol;
|
|
1174
|
+
purpose: CommercePurpose | null;
|
|
1175
|
+
transactionValue?: TransactionValueContext;
|
|
1176
|
+
signatures: CommerceSignatureStack;
|
|
1177
|
+
identity?: {
|
|
1178
|
+
claims: IdentityClaim[];
|
|
1179
|
+
mappedAstraSyncAgentId?: string;
|
|
1180
|
+
mismatchAcrossLayers: boolean;
|
|
1181
|
+
};
|
|
1182
|
+
paymentToken?: {
|
|
1183
|
+
present: boolean;
|
|
1184
|
+
type: 'stripe-spt' | 'acp-vt' | 'tempo-tx' | 'other' | null;
|
|
1185
|
+
};
|
|
1186
|
+
mppMethodsOffered?: string[];
|
|
1187
|
+
constraints?: ConstraintEvalResult;
|
|
1188
|
+
receipt?: {
|
|
1189
|
+
method?: string;
|
|
1190
|
+
reference?: string;
|
|
1191
|
+
status?: string;
|
|
1192
|
+
timestamp?: string;
|
|
1193
|
+
};
|
|
1194
|
+
trustSignals: string[];
|
|
1195
|
+
timings: {
|
|
1196
|
+
extractMs: number;
|
|
1197
|
+
verifyMs: number;
|
|
1198
|
+
evalMs: number;
|
|
1199
|
+
};
|
|
1200
|
+
/** False when any hard-deny rule fires. */
|
|
1201
|
+
ok: boolean;
|
|
1202
|
+
}
|
|
1203
|
+
declare function runCommercePipeline(input: CommercePipelineInput): Promise<CommerceContext>;
|
|
1204
|
+
|
|
1205
|
+
/**
|
|
1206
|
+
* Pluggable extractor registry for the Trusted Agent Gateway edge
|
|
1207
|
+
* adapters and other callers that need a curated extractor set.
|
|
1208
|
+
*
|
|
1209
|
+
* Built-in extractors (VI, UCP, ACP, RFC 9421, MPP, x402, Stripe webhook)
|
|
1210
|
+
* are NOT auto-registered. A caller imports this module, picks the set
|
|
1211
|
+
* it wants, and calls registerTransportExtractor() for each.
|
|
1212
|
+
*
|
|
1213
|
+
* Re-registering by name replaces the prior extractor (idempotent).
|
|
1214
|
+
*/
|
|
1215
|
+
interface ExtractorRequestLike {
|
|
1216
|
+
method?: string;
|
|
1217
|
+
url?: string;
|
|
1218
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
1219
|
+
body?: unknown;
|
|
1220
|
+
}
|
|
1221
|
+
interface TransportExtractor<T = unknown> {
|
|
1222
|
+
readonly name: string;
|
|
1223
|
+
match(request: ExtractorRequestLike): boolean;
|
|
1224
|
+
extract(request: ExtractorRequestLike): T | Promise<T> | null;
|
|
1225
|
+
}
|
|
1226
|
+
declare function registerTransportExtractor<T>(extractor: TransportExtractor<T>): void;
|
|
1227
|
+
declare function getTransportExtractors(): ReadonlyArray<TransportExtractor>;
|
|
1228
|
+
declare function getTransportExtractor(name: string): TransportExtractor | undefined;
|
|
1229
|
+
declare function clearTransportExtractors(): void;
|
|
1230
|
+
/**
|
|
1231
|
+
* Helper: run all matching extractors against a request and return their
|
|
1232
|
+
* extracted contexts keyed by extractor name. Skips extractors whose
|
|
1233
|
+
* `match()` returns false.
|
|
1234
|
+
*/
|
|
1235
|
+
declare function runMatchingExtractors(request: ExtractorRequestLike): Promise<Record<string, unknown>>;
|
|
1236
|
+
|
|
1237
|
+
/**
|
|
1238
|
+
* Visa JWKS registry resolver.
|
|
1239
|
+
*
|
|
1240
|
+
* Default endpoint: https://mcp.visa.com/.well-known/jwks (per Visa TAP spec).
|
|
1241
|
+
* Wraps jose.createRemoteJWKSet which handles caching + rotation natively.
|
|
1242
|
+
*/
|
|
1243
|
+
|
|
1244
|
+
interface VisaRegistryOptions {
|
|
1245
|
+
jwksUrl?: string;
|
|
1246
|
+
cacheMaxAge?: number;
|
|
1247
|
+
cooldownDuration?: number;
|
|
1248
|
+
}
|
|
1249
|
+
declare function createVisaRegistry(options?: VisaRegistryOptions): RegistryResolver;
|
|
1250
|
+
|
|
1251
|
+
/**
|
|
1252
|
+
* Mastercard Agent Registry resolver — STUB.
|
|
1253
|
+
*
|
|
1254
|
+
* Mastercard Agent Pay is behind partnership (pilots Feb 2026, GA Q2 2026).
|
|
1255
|
+
* No public Agent Registry URL or open-source resolver exists as of April
|
|
1256
|
+
* 2026. This resolver accepts an optional `registryUrl` and, when absent,
|
|
1257
|
+
* returns null with a single one-time console.warn so callers can plumb
|
|
1258
|
+
* the flow end-to-end without a live registry.
|
|
1259
|
+
*
|
|
1260
|
+
* When Mastercard ships a public resolver or when a commercial relationship
|
|
1261
|
+
* provides a registry URL, pass it via `MastercardRegistryOptions.registryUrl`.
|
|
1262
|
+
* Response shape expected: { keys: JWK[] } (JWKS-style).
|
|
1263
|
+
*/
|
|
1264
|
+
|
|
1265
|
+
interface MastercardRegistryOptions {
|
|
1266
|
+
/** Partnership-provided registry URL. Without it, the resolver is inert. */
|
|
1267
|
+
registryUrl?: string;
|
|
1268
|
+
/** Cache TTL in seconds. Default 3600. */
|
|
1269
|
+
cacheTtlSec?: number;
|
|
1270
|
+
/** Fetch fn override for testing. */
|
|
1271
|
+
fetch?: typeof fetch;
|
|
1272
|
+
/** Silence the one-time warn (testing only). */
|
|
1273
|
+
silent?: boolean;
|
|
1274
|
+
}
|
|
1275
|
+
declare function createMastercardRegistry(options?: MastercardRegistryOptions): RegistryResolver;
|
|
1276
|
+
|
|
1277
|
+
/**
|
|
1278
|
+
* Web Bot Auth registry resolver.
|
|
1279
|
+
*
|
|
1280
|
+
* IETF draft-meunier-web-bot-auth-architecture-05 + draft-meunier-http-
|
|
1281
|
+
* message-signatures-directory-01. Shared transport substrate under TAP,
|
|
1282
|
+
* Agent Pay, and Cloudflare Pay Per Crawl.
|
|
1283
|
+
*
|
|
1284
|
+
* Fetches a Web Bot Auth signature directory
|
|
1285
|
+
* (default: `<origin>/.well-known/http-message-signatures-directory`).
|
|
1286
|
+
* Shape per spec is a JWKS with Ed25519 keys.
|
|
1287
|
+
*
|
|
1288
|
+
* Wraps Cloudflare's `web-bot-auth` npm package where feasible; for raw
|
|
1289
|
+
* directory fetch + kid matching we use fetch + JSON since web-bot-auth's
|
|
1290
|
+
* higher-level API assumes a full request to verify.
|
|
1291
|
+
*/
|
|
1292
|
+
|
|
1293
|
+
interface WebBotAuthRegistryOptions {
|
|
1294
|
+
/**
|
|
1295
|
+
* Optional explicit directory URL. When omitted, the resolver derives one
|
|
1296
|
+
* from `ResolveContext.origin` (e.g. the request URL's origin at verify time).
|
|
1297
|
+
*/
|
|
1298
|
+
directoryUrl?: string;
|
|
1299
|
+
cacheTtlSec?: number;
|
|
1300
|
+
fetch?: typeof fetch;
|
|
1301
|
+
}
|
|
1302
|
+
declare function createWebBotAuthRegistry(options?: WebBotAuthRegistryOptions): RegistryResolver;
|
|
1303
|
+
|
|
1304
|
+
/**
|
|
1305
|
+
* Cross-Protocol Transport Module
|
|
1306
|
+
*
|
|
1307
|
+
* Provides adapters for injecting/extracting AstraSync credentials
|
|
1308
|
+
* across HTTP, A2A, and MCP protocols.
|
|
1309
|
+
*/
|
|
1310
|
+
|
|
1311
|
+
/**
|
|
1312
|
+
* Auto-detect protocol from request/context shape.
|
|
1313
|
+
*/
|
|
1314
|
+
declare function detectProtocol(context: Record<string, unknown>): ProtocolTransport;
|
|
1315
|
+
/**
|
|
1316
|
+
* Apply credentials to any protocol target.
|
|
1317
|
+
*/
|
|
1318
|
+
declare function applyCredentials(protocol: ProtocolTransport, target: Record<string, unknown>, credentials: AstraSyncCredentials): Record<string, unknown>;
|
|
1319
|
+
/**
|
|
1320
|
+
* Extract credentials from any protocol context.
|
|
1321
|
+
*/
|
|
1322
|
+
declare function extractCredentialsFromProtocol(protocol: ProtocolTransport, context: Record<string, unknown>): AstraSyncCredentials | null;
|
|
1323
|
+
|
|
1324
|
+
export { type ACPEndpoint, type ACPPaymentTokenType, type ACPRequestContext, type ACPRequestLike, type ACPSignatureAlgorithm, type ACPTotal, type ACPVerifyInput, type ACPVerifyResult, type AP2CartMandateClaims, type AP2ChainResult, type AP2IntentMandateClaims, type AP2MandateClaims, type AP2MandateTriple, type AP2MandateTripleInput, type AP2MandateType, type AP2PaymentDetailsTotal, type AP2PaymentMandateClaims, type AP2PaymentMandateForValue, type AP2VerifyInput, type CommerceContext, type CommercePipelineInput, type CommerceProtocol, type CommercePurpose, type CommerceSignatureStack, type ConstraintEvalResult, type ConstraintKey, type ConstraintResult, type ExtractorRequestLike, type IdentityBindingResult, type IdentityClaim, type IdentityResolver, type MPPChallengeForValue, type MPPChallengeSummary, type MPPCredentialSummary, type MPPIntent, type MPPKind, type MPPReceiptSummary, type MPPRequestContext, type MPPRequestLike, type MPPResponseLike, type MPPVerifyInput, type MPPVerifyResult, type ParsedRFC9421, type PaymentMethodAllowlistInput, type RFC9421SignatureParams, type RFC9421Tag, type RFC9421VerifyOptions, type RFC9421VerifyRequest, type RFC9421VerifyResult, type RegistryName, type RegistryResolver, type ResolveContext, STRIPE_WEBHOOK_INFORMATIONAL_EVENTS, type SpendingLimitInput, type StripeWebhookInformationalEvent, type TransactionContext, type TransactionValueContext, type TransportExtractor, type UCPCheckoutContext, type UCPManifestValidationResult, type UCPRequestLike, type UCPTotal, type VIAllowedParty, type VIBudgetLimit, type VIClaimsForValue, type VIConstraintEvalInput, type VIConstraints, type VIExecutionMode, type VIExtractedClaims, type VILayer, type VILineItem, type VIMandateType, type VIPaymentAmount, type VIRecurrence, type VIVerifyInput, type VIVerifyResult, type VerifyStripeWebhookOptions, type VerifyStripeWebhookResult, type X402Kind, type X402RequestContext, type X402RequestForValue, type X402RequestLike, type X402RequirementsSummary, type X402ResponseLike, applyCredentials, bindIdentity, claim, clearTransportExtractors, createMastercardRegistry, createVisaRegistry, createWebBotAuthRegistry, detectProtocol, evaluatePaymentMethodAllowlist, evaluateSpendingLimit, evaluateVIConstraints, extractA2ACredentials, extractACPContext, extractACPTransactionValue, extractAP2Mandate, extractAP2Mandates, extractAP2TransactionValue, extractCredentialsFromProtocol, extractHttpCredentials, extractMPPContext, extractMPPFromRequest, extractMPPFromResponse, extractMPPTransactionValue, extractMcpCredentials, extractUCPContext, extractUCPTransactionValue, extractVIClaims, extractVITransactionValue, extractX402Context, extractX402FromRequest, extractX402FromResponse, extractX402TransactionValue, fetchUCPManifest, getTransportExtractor, getTransportExtractors, isStripeWebhookInformational, mapACPRequestToPurpose, mapAP2MandateToPurpose, mapMPPRequestToPurpose, mapRFC9421TagToPurpose, mapUCPRequestToPurpose, mapVIMandateToPurpose, mapX402RequestToPurpose, parseRFC9421, registerTransportExtractor, runCommercePipeline, runMatchingExtractors, setA2AMetadata, setHttpHeaders, setMcpMeta, validateUCPManifest, verifyACPSignature, verifyAP2Chain, verifyMPP, verifyRFC9421, verifyStripeWebhook, verifyVIChain };
|