@vorim/sdk 3.8.0 → 3.9.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 (77) hide show
  1. package/dist/index.cjs +208 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +133 -3
  4. package/dist/index.d.ts +133 -3
  5. package/dist/index.js +208 -1
  6. package/dist/index.js.map +1 -1
  7. package/dist/integrations/anthropic.d.cts +1 -1
  8. package/dist/integrations/anthropic.d.ts +1 -1
  9. package/dist/integrations/ap2.cjs +218 -0
  10. package/dist/integrations/ap2.cjs.map +1 -0
  11. package/dist/integrations/ap2.d.cts +95 -0
  12. package/dist/integrations/ap2.d.ts +95 -0
  13. package/dist/integrations/ap2.js +192 -0
  14. package/dist/integrations/ap2.js.map +1 -0
  15. package/dist/integrations/bank-rails.cjs +173 -0
  16. package/dist/integrations/bank-rails.cjs.map +1 -0
  17. package/dist/integrations/bank-rails.d.cts +87 -0
  18. package/dist/integrations/bank-rails.d.ts +87 -0
  19. package/dist/integrations/bank-rails.js +147 -0
  20. package/dist/integrations/bank-rails.js.map +1 -0
  21. package/dist/integrations/circle.cjs +159 -0
  22. package/dist/integrations/circle.cjs.map +1 -0
  23. package/dist/integrations/circle.d.cts +75 -0
  24. package/dist/integrations/circle.d.ts +75 -0
  25. package/dist/integrations/circle.js +133 -0
  26. package/dist/integrations/circle.js.map +1 -0
  27. package/dist/integrations/crewai.d.cts +1 -1
  28. package/dist/integrations/crewai.d.ts +1 -1
  29. package/dist/integrations/hermes.cjs +280 -0
  30. package/dist/integrations/hermes.cjs.map +1 -0
  31. package/dist/integrations/hermes.d.cts +60 -0
  32. package/dist/integrations/hermes.d.ts +60 -0
  33. package/dist/integrations/hermes.js +242 -0
  34. package/dist/integrations/hermes.js.map +1 -0
  35. package/dist/integrations/langchain.d.cts +1 -1
  36. package/dist/integrations/langchain.d.ts +1 -1
  37. package/dist/integrations/langgraph.d.cts +1 -1
  38. package/dist/integrations/langgraph.d.ts +1 -1
  39. package/dist/integrations/llamaindex.d.cts +1 -1
  40. package/dist/integrations/llamaindex.d.ts +1 -1
  41. package/dist/integrations/nekuda.cjs +165 -0
  42. package/dist/integrations/nekuda.cjs.map +1 -0
  43. package/dist/integrations/nekuda.d.cts +79 -0
  44. package/dist/integrations/nekuda.d.ts +79 -0
  45. package/dist/integrations/nekuda.js +139 -0
  46. package/dist/integrations/nekuda.js.map +1 -0
  47. package/dist/integrations/openai.d.cts +1 -1
  48. package/dist/integrations/openai.d.ts +1 -1
  49. package/dist/integrations/paypal-agent.cjs +215 -0
  50. package/dist/integrations/paypal-agent.cjs.map +1 -0
  51. package/dist/integrations/paypal-agent.d.cts +87 -0
  52. package/dist/integrations/paypal-agent.d.ts +87 -0
  53. package/dist/integrations/paypal-agent.js +189 -0
  54. package/dist/integrations/paypal-agent.js.map +1 -0
  55. package/dist/integrations/siem.d.cts +1 -1
  56. package/dist/integrations/siem.d.ts +1 -1
  57. package/dist/integrations/skyfire.cjs +166 -0
  58. package/dist/integrations/skyfire.cjs.map +1 -0
  59. package/dist/integrations/skyfire.d.cts +80 -0
  60. package/dist/integrations/skyfire.d.ts +80 -0
  61. package/dist/integrations/skyfire.js +140 -0
  62. package/dist/integrations/skyfire.js.map +1 -0
  63. package/dist/integrations/stripe-acp.d.cts +1 -1
  64. package/dist/integrations/stripe-acp.d.ts +1 -1
  65. package/dist/integrations/ucp.d.cts +1 -1
  66. package/dist/integrations/ucp.d.ts +1 -1
  67. package/dist/integrations/vercel-ai.d.cts +1 -1
  68. package/dist/integrations/vercel-ai.d.ts +1 -1
  69. package/dist/integrations/x402.cjs +211 -0
  70. package/dist/integrations/x402.cjs.map +1 -0
  71. package/dist/integrations/x402.d.cts +87 -0
  72. package/dist/integrations/x402.d.ts +87 -0
  73. package/dist/integrations/x402.js +185 -0
  74. package/dist/integrations/x402.js.map +1 -0
  75. package/dist/{types-Cb6V-boJ.d.cts → types-zzK9YOoa.d.cts} +86 -1
  76. package/dist/{types-Cb6V-boJ.d.ts → types-zzK9YOoa.d.ts} +86 -1
  77. package/package.json +83 -2
@@ -0,0 +1,80 @@
1
+ import { VorimSDK } from '../index.js';
2
+ import '../types-zzK9YOoa.js';
3
+
4
+ type SkyfireTokenType = 'kya' | 'pay' | 'kya-pay';
5
+ interface SkyfireConfig {
6
+ apiKey: string;
7
+ baseUrl?: string;
8
+ minTrustScore?: number;
9
+ requiredScope?: string;
10
+ }
11
+ interface SkyfireTokenRequest {
12
+ /** The Vorim agent id minting the token. */
13
+ agentId: string;
14
+ /** Skyfire token type: kya (identity only), pay, or kya-pay (combined). */
15
+ tokenType?: SkyfireTokenType;
16
+ /** The seller/service the token is scoped to. */
17
+ sellerServiceId?: string;
18
+ /** Token amount in the smallest currency unit (required for pay / kya-pay). */
19
+ amount?: number;
20
+ /** Currency code. */
21
+ currency?: string;
22
+ /** Per-call override of the trust threshold. */
23
+ minTrustScore?: number;
24
+ }
25
+ interface SkyfireAuthorization {
26
+ authorized: boolean;
27
+ agentId: string;
28
+ trustScore: number;
29
+ status: string;
30
+ reason?: string;
31
+ scopeVerified: boolean;
32
+ }
33
+ declare class VorimSkyfire {
34
+ private sdk;
35
+ private minTrustScore;
36
+ private requiredScope;
37
+ private static _warnedNoAuth;
38
+ constructor(sdk: VorimSDK, config?: Partial<SkyfireConfig>);
39
+ /**
40
+ * Verify an agent is authorized to mint a Skyfire token. A 'kya' (identity-
41
+ * only) token needs the scope but carries no amount; 'pay' / 'kya-pay' carry
42
+ * a spend amount. Same gate throughout: scope → active status → trust.
43
+ */
44
+ authorizeToken(req: SkyfireTokenRequest): Promise<SkyfireAuthorization>;
45
+ /** Log that a Skyfire token was minted. */
46
+ logTokenCreated(agentId: string, tokenId: string, req?: Partial<SkyfireTokenRequest>): Promise<void>;
47
+ /** Log that a seller charged a Skyfire token. */
48
+ logTokenCharged(agentId: string, tokenId: string, amountCharged?: number, req?: Partial<SkyfireTokenRequest>): Promise<void>;
49
+ /** Log that a Skyfire token charge failed or was rejected. */
50
+ logTokenRejected(agentId: string, tokenId: string, reason?: string, req?: Partial<SkyfireTokenRequest>): Promise<void>;
51
+ /**
52
+ * Express/Connect middleware that gates a token-mint endpoint on agent
53
+ * authorization.
54
+ *
55
+ * ⚠️ CONFUSED-DEPUTY WARNING. Evaluates the *named* agent only; pass
56
+ * `authenticate` to verify the caller-to-agent binding. When omitted, a
57
+ * one-time warning is logged.
58
+ */
59
+ middleware(options?: {
60
+ agentIdHeader?: string;
61
+ minTrustScore?: number;
62
+ authenticate?: (agentId: string, req: any) => boolean | Promise<boolean>;
63
+ }): (req: any, res: any, next: any) => Promise<void>;
64
+ private logEvent;
65
+ }
66
+ /**
67
+ * Create a VorimSkyfire instance.
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * import createVorim from '@vorim/sdk';
72
+ * import { createVorimSkyfire } from '@vorim/sdk/integrations/skyfire';
73
+ * const vorim = createVorim({ apiKey: 'agid_sk_...' });
74
+ * const skyfire = createVorimSkyfire(vorim, { minTrustScore: 70 });
75
+ * const auth = await skyfire.authorizeToken({ agentId: 'agid_abc', tokenType: 'pay', amount: 500 });
76
+ * ```
77
+ */
78
+ declare function createVorimSkyfire(sdk: VorimSDK, config?: Partial<SkyfireConfig>): VorimSkyfire;
79
+
80
+ export { type SkyfireAuthorization, type SkyfireConfig, type SkyfireTokenRequest, type SkyfireTokenType, VorimSkyfire, createVorimSkyfire };
@@ -0,0 +1,140 @@
1
+ // src/integrations/skyfire.ts
2
+ var VorimSkyfire = class _VorimSkyfire {
3
+ sdk;
4
+ minTrustScore;
5
+ requiredScope;
6
+ static _warnedNoAuth = false;
7
+ constructor(sdk, config) {
8
+ this.sdk = sdk;
9
+ this.minTrustScore = config?.minTrustScore ?? 50;
10
+ this.requiredScope = config?.requiredScope ?? "agent:transact";
11
+ }
12
+ /**
13
+ * Verify an agent is authorized to mint a Skyfire token. A 'kya' (identity-
14
+ * only) token needs the scope but carries no amount; 'pay' / 'kya-pay' carry
15
+ * a spend amount. Same gate throughout: scope → active status → trust.
16
+ */
17
+ async authorizeToken(req) {
18
+ const threshold = req.minTrustScore ?? this.minTrustScore;
19
+ const action = `skyfire.token.${req.tokenType ?? "kya-pay"}.authorize`;
20
+ try {
21
+ const perm = await this.sdk.check(req.agentId, this.requiredScope);
22
+ if (!perm.allowed) {
23
+ await this.logEvent(req.agentId, action, "denied", req, { reason: `Missing ${this.requiredScope}` });
24
+ return { authorized: false, agentId: req.agentId, trustScore: 0, status: "unknown", reason: `Agent does not have ${this.requiredScope} permission`, scopeVerified: false };
25
+ }
26
+ } catch (e) {
27
+ await this.logEvent(req.agentId, action, "denied", req, { reason: e.message });
28
+ return { authorized: false, agentId: req.agentId, trustScore: 0, status: "unknown", reason: `Permission check failed: ${e.message}`, scopeVerified: false };
29
+ }
30
+ let score = 0;
31
+ let status = "unknown";
32
+ try {
33
+ const trust = await this.sdk.verify(req.agentId);
34
+ score = trust.trust_score ?? 0;
35
+ status = trust.status ?? "unknown";
36
+ } catch {
37
+ }
38
+ if (status !== "active") {
39
+ await this.logEvent(req.agentId, action, "denied", req, { reason: `Status: ${status}` });
40
+ return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Agent is ${status}, not active`, scopeVerified: true };
41
+ }
42
+ if (score < threshold) {
43
+ await this.logEvent(req.agentId, action, "denied", req, { reason: `Score ${score} < ${threshold}` });
44
+ return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Trust score ${score} is below minimum ${threshold}`, scopeVerified: true };
45
+ }
46
+ await this.logEvent(req.agentId, action, "success", req, { trust_score: score });
47
+ return { authorized: true, agentId: req.agentId, trustScore: score, status, scopeVerified: true };
48
+ }
49
+ /** Log that a Skyfire token was minted. */
50
+ async logTokenCreated(agentId, tokenId, req) {
51
+ await this.logEvent(agentId, `skyfire.token.${req?.tokenType ?? "kya-pay"}.created`, "success", req, { token_id: tokenId });
52
+ }
53
+ /** Log that a seller charged a Skyfire token. */
54
+ async logTokenCharged(agentId, tokenId, amountCharged, req) {
55
+ await this.logEvent(agentId, "skyfire.token.charged", "success", req, { token_id: tokenId, amount_charged: amountCharged });
56
+ }
57
+ /** Log that a Skyfire token charge failed or was rejected. */
58
+ async logTokenRejected(agentId, tokenId, reason, req) {
59
+ await this.logEvent(agentId, "skyfire.token.rejected", "error", req, { token_id: tokenId, reject_reason: reason });
60
+ }
61
+ /**
62
+ * Express/Connect middleware that gates a token-mint endpoint on agent
63
+ * authorization.
64
+ *
65
+ * ⚠️ CONFUSED-DEPUTY WARNING. Evaluates the *named* agent only; pass
66
+ * `authenticate` to verify the caller-to-agent binding. When omitted, a
67
+ * one-time warning is logged.
68
+ */
69
+ middleware(options) {
70
+ const header = options?.agentIdHeader ?? "x-vorim-agent-id";
71
+ const threshold = options?.minTrustScore ?? this.minTrustScore;
72
+ const authenticate = options?.authenticate;
73
+ if (!authenticate && !_VorimSkyfire._warnedNoAuth) {
74
+ _VorimSkyfire._warnedNoAuth = true;
75
+ console.warn(
76
+ "[vorim] VorimSkyfire.middleware() called without an `authenticate` hook: it authorizes the agent NAMED in the header but does not verify the caller controls that agent (confused-deputy risk). Pass `authenticate`."
77
+ );
78
+ }
79
+ return async (req, res, next) => {
80
+ const agentId = req.headers?.[header] || req.headers?.[header.toLowerCase()] || "";
81
+ if (!agentId) {
82
+ res.status(401).json({ error: { code: "MISSING_AGENT_ID", message: `Agent ID required in ${header} header` } });
83
+ return;
84
+ }
85
+ if (authenticate) {
86
+ let bound = false;
87
+ try {
88
+ bound = await authenticate(agentId, req);
89
+ } catch {
90
+ bound = false;
91
+ }
92
+ if (!bound) {
93
+ res.status(401).json({ error: { code: "AGENT_BINDING_UNVERIFIED", message: "Caller is not authenticated as the named agent" } });
94
+ return;
95
+ }
96
+ }
97
+ const auth = await this.authorizeToken({
98
+ agentId,
99
+ tokenType: req.body?.tokenType || "kya-pay",
100
+ sellerServiceId: req.body?.sellerServiceId || "",
101
+ amount: req.body?.amount || 0,
102
+ currency: req.body?.currency || "usd",
103
+ minTrustScore: threshold
104
+ });
105
+ if (!auth.authorized) {
106
+ res.status(403).json({ error: { code: "UNAUTHORIZED_AGENT", message: auth.reason || "Agent not authorized to mint a Skyfire token", trust_score: auth.trustScore, status: auth.status } });
107
+ return;
108
+ }
109
+ req.vorimAuthorization = auth;
110
+ next();
111
+ };
112
+ }
113
+ async logEvent(agentId, action, result, req, metadata) {
114
+ try {
115
+ await this.sdk.emit({
116
+ agent_id: agentId,
117
+ event_type: "api_request",
118
+ action,
119
+ result,
120
+ resource: req?.sellerServiceId || "",
121
+ metadata: {
122
+ token_type: req?.tokenType || "",
123
+ seller_service_id: req?.sellerServiceId || "",
124
+ amount: req?.amount || 0,
125
+ currency: req?.currency || "",
126
+ ...metadata
127
+ }
128
+ });
129
+ } catch {
130
+ }
131
+ }
132
+ };
133
+ function createVorimSkyfire(sdk, config) {
134
+ return new VorimSkyfire(sdk, config);
135
+ }
136
+ export {
137
+ VorimSkyfire,
138
+ createVorimSkyfire
139
+ };
140
+ //# sourceMappingURL=skyfire.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/integrations/skyfire.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — Skyfire (KYA + KYAPay) Integration\n//\n// Skyfire is an agent trust + payments stack: an agent mints a token\n// (POST /api/v1/tokens) of type 'kya' (identity), 'pay' (payment), or\n// 'kya-pay' (combined), scoped to a seller + amount + expiry, then the seller\n// charges it (POST /api/v1/tokens/charge).\n//\n// This integration adds Vorim's identity, permission, and audit layer IN FRONT\n// of Skyfire token creation: before an agent mints a pay / kya-pay token, it\n// verifies the agent holds `transact`, is active, and clears a trust threshold,\n// then records the token + charge lifecycle on a signed, tamper-evident audit\n// trail. It does NOT mint Skyfire tokens or hold Skyfire keys — Skyfire does\n// the payment; Vorim authorizes and attests.\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimSkyfire } from '@vorim/sdk/integrations/skyfire';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const skyfire = createVorimSkyfire(vorim, { minTrustScore: 60 });\n//\n// const auth = await skyfire.authorizeToken({\n// agentId: 'agid_abc123',\n// tokenType: 'kya-pay',\n// sellerServiceId: 'svc_...',\n// amount: 500,\n// currency: 'usd',\n// });\n// if (auth.authorized) {\n// // ... mint the Skyfire token, then:\n// await skyfire.logTokenCreated(auth.agentId, tokenId, { tokenType: 'kya-pay' });\n// }\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\n\nexport type SkyfireTokenType = 'kya' | 'pay' | 'kya-pay';\n\nexport interface SkyfireConfig {\n apiKey: string;\n baseUrl?: string;\n minTrustScore?: number;\n requiredScope?: string;\n}\n\nexport interface SkyfireTokenRequest {\n /** The Vorim agent id minting the token. */\n agentId: string;\n /** Skyfire token type: kya (identity only), pay, or kya-pay (combined). */\n tokenType?: SkyfireTokenType;\n /** The seller/service the token is scoped to. */\n sellerServiceId?: string;\n /** Token amount in the smallest currency unit (required for pay / kya-pay). */\n amount?: number;\n /** Currency code. */\n currency?: string;\n /** Per-call override of the trust threshold. */\n minTrustScore?: number;\n}\n\nexport interface SkyfireAuthorization {\n authorized: boolean;\n agentId: string;\n trustScore: number;\n status: string;\n reason?: string;\n scopeVerified: boolean;\n}\n\nexport class VorimSkyfire {\n private sdk: VorimSDK;\n private minTrustScore: number;\n private requiredScope: string;\n private static _warnedNoAuth = false;\n\n constructor(sdk: VorimSDK, config?: Partial<SkyfireConfig>) {\n this.sdk = sdk;\n this.minTrustScore = config?.minTrustScore ?? 50;\n this.requiredScope = config?.requiredScope ?? 'agent:transact';\n }\n\n /**\n * Verify an agent is authorized to mint a Skyfire token. A 'kya' (identity-\n * only) token needs the scope but carries no amount; 'pay' / 'kya-pay' carry\n * a spend amount. Same gate throughout: scope → active status → trust.\n */\n async authorizeToken(req: SkyfireTokenRequest): Promise<SkyfireAuthorization> {\n const threshold = req.minTrustScore ?? this.minTrustScore;\n const action = `skyfire.token.${req.tokenType ?? 'kya-pay'}.authorize`;\n\n try {\n const perm = await this.sdk.check(req.agentId, this.requiredScope as any);\n if (!(perm as any).allowed) {\n await this.logEvent(req.agentId, action, 'denied', req, { reason: `Missing ${this.requiredScope}` });\n return { authorized: false, agentId: req.agentId, trustScore: 0, status: 'unknown', reason: `Agent does not have ${this.requiredScope} permission`, scopeVerified: false };\n }\n } catch (e: any) {\n await this.logEvent(req.agentId, action, 'denied', req, { reason: e.message });\n return { authorized: false, agentId: req.agentId, trustScore: 0, status: 'unknown', reason: `Permission check failed: ${e.message}`, scopeVerified: false };\n }\n\n let score = 0;\n let status = 'unknown';\n try {\n const trust = await this.sdk.verify(req.agentId);\n score = (trust as any).trust_score ?? 0;\n status = (trust as any).status ?? 'unknown';\n } catch { /* treated as not-active below */ }\n\n if (status !== 'active') {\n await this.logEvent(req.agentId, action, 'denied', req, { reason: `Status: ${status}` });\n return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Agent is ${status}, not active`, scopeVerified: true };\n }\n\n if (score < threshold) {\n await this.logEvent(req.agentId, action, 'denied', req, { reason: `Score ${score} < ${threshold}` });\n return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Trust score ${score} is below minimum ${threshold}`, scopeVerified: true };\n }\n\n await this.logEvent(req.agentId, action, 'success', req, { trust_score: score });\n return { authorized: true, agentId: req.agentId, trustScore: score, status, scopeVerified: true };\n }\n\n /** Log that a Skyfire token was minted. */\n async logTokenCreated(agentId: string, tokenId: string, req?: Partial<SkyfireTokenRequest>): Promise<void> {\n await this.logEvent(agentId, `skyfire.token.${req?.tokenType ?? 'kya-pay'}.created`, 'success', req, { token_id: tokenId });\n }\n\n /** Log that a seller charged a Skyfire token. */\n async logTokenCharged(agentId: string, tokenId: string, amountCharged?: number, req?: Partial<SkyfireTokenRequest>): Promise<void> {\n await this.logEvent(agentId, 'skyfire.token.charged', 'success', req, { token_id: tokenId, amount_charged: amountCharged });\n }\n\n /** Log that a Skyfire token charge failed or was rejected. */\n async logTokenRejected(agentId: string, tokenId: string, reason?: string, req?: Partial<SkyfireTokenRequest>): Promise<void> {\n await this.logEvent(agentId, 'skyfire.token.rejected', 'error', req, { token_id: tokenId, reject_reason: reason });\n }\n\n /**\n * Express/Connect middleware that gates a token-mint endpoint on agent\n * authorization.\n *\n * ⚠️ CONFUSED-DEPUTY WARNING. Evaluates the *named* agent only; pass\n * `authenticate` to verify the caller-to-agent binding. When omitted, a\n * one-time warning is logged.\n */\n middleware(options?: {\n agentIdHeader?: string;\n minTrustScore?: number;\n authenticate?: (agentId: string, req: any) => boolean | Promise<boolean>;\n }) {\n const header = options?.agentIdHeader ?? 'x-vorim-agent-id';\n const threshold = options?.minTrustScore ?? this.minTrustScore;\n const authenticate = options?.authenticate;\n\n if (!authenticate && !VorimSkyfire._warnedNoAuth) {\n VorimSkyfire._warnedNoAuth = true;\n // eslint-disable-next-line no-console\n console.warn(\n '[vorim] VorimSkyfire.middleware() called without an `authenticate` hook: ' +\n 'it authorizes the agent NAMED in the header but does not verify the ' +\n 'caller controls that agent (confused-deputy risk). Pass `authenticate`.'\n );\n }\n\n return async (req: any, res: any, next: any) => {\n const agentId = req.headers?.[header] || req.headers?.[header.toLowerCase()] || '';\n if (!agentId) {\n res.status(401).json({ error: { code: 'MISSING_AGENT_ID', message: `Agent ID required in ${header} header` } });\n return;\n }\n if (authenticate) {\n let bound = false;\n try { bound = await authenticate(agentId, req); } catch { bound = false; }\n if (!bound) {\n res.status(401).json({ error: { code: 'AGENT_BINDING_UNVERIFIED', message: 'Caller is not authenticated as the named agent' } });\n return;\n }\n }\n const auth = await this.authorizeToken({\n agentId,\n tokenType: (req.body?.tokenType as SkyfireTokenType) || 'kya-pay',\n sellerServiceId: req.body?.sellerServiceId || '',\n amount: req.body?.amount || 0,\n currency: req.body?.currency || 'usd',\n minTrustScore: threshold,\n });\n if (!auth.authorized) {\n res.status(403).json({ error: { code: 'UNAUTHORIZED_AGENT', message: auth.reason || 'Agent not authorized to mint a Skyfire token', trust_score: auth.trustScore, status: auth.status } });\n return;\n }\n req.vorimAuthorization = auth;\n next();\n };\n }\n\n private async logEvent(\n agentId: string,\n action: string,\n result: 'success' | 'denied' | 'error',\n req?: Partial<SkyfireTokenRequest>,\n metadata?: Record<string, any>,\n ): Promise<void> {\n try {\n await this.sdk.emit({\n agent_id: agentId,\n event_type: 'api_request',\n action,\n result,\n resource: req?.sellerServiceId || '',\n metadata: {\n token_type: req?.tokenType || '',\n seller_service_id: req?.sellerServiceId || '',\n amount: req?.amount || 0,\n currency: req?.currency || '',\n ...metadata,\n },\n });\n } catch { /* never block the payment flow */ }\n }\n}\n\n/**\n * Create a VorimSkyfire instance.\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimSkyfire } from '@vorim/sdk/integrations/skyfire';\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const skyfire = createVorimSkyfire(vorim, { minTrustScore: 70 });\n * const auth = await skyfire.authorizeToken({ agentId: 'agid_abc', tokenType: 'pay', amount: 500 });\n * ```\n */\nexport function createVorimSkyfire(sdk: VorimSDK, config?: Partial<SkyfireConfig>): VorimSkyfire {\n return new VorimSkyfire(sdk, config);\n}\n"],"mappings":";AAsEO,IAAM,eAAN,MAAM,cAAa;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACR,OAAe,gBAAgB;AAAA,EAE/B,YAAY,KAAe,QAAiC;AAC1D,SAAK,MAAM;AACX,SAAK,gBAAgB,QAAQ,iBAAiB;AAC9C,SAAK,gBAAgB,QAAQ,iBAAiB;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,eAAe,KAAyD;AAC5E,UAAM,YAAY,IAAI,iBAAiB,KAAK;AAC5C,UAAM,SAAS,iBAAiB,IAAI,aAAa,SAAS;AAE1D,QAAI;AACF,YAAM,OAAO,MAAM,KAAK,IAAI,MAAM,IAAI,SAAS,KAAK,aAAoB;AACxE,UAAI,CAAE,KAAa,SAAS;AAC1B,cAAM,KAAK,SAAS,IAAI,SAAS,QAA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
3
 
4
4
  interface ACPConfig {
5
5
  apiKey: string;
@@ -1,5 +1,5 @@
1
1
  import { VorimSDK } from '../index.js';
2
- import '../types-Cb6V-boJ.js';
2
+ import '../types-zzK9YOoa.js';
3
3
 
4
4
  interface ACPConfig {
5
5
  apiKey: string;
@@ -1,5 +1,5 @@
1
1
  import { VorimSDK } from '../index.cjs';
2
- import '../types-Cb6V-boJ.cjs';
2
+ import '../types-zzK9YOoa.cjs';
3
3
 
4
4
  interface UCPConfig {
5
5
  apiKey: string;
@@ -1,5 +1,5 @@
1
1
  import { VorimSDK } from '../index.js';
2
- import '../types-Cb6V-boJ.js';
2
+ import '../types-zzK9YOoa.js';
3
3
 
4
4
  interface UCPConfig {
5
5
  apiKey: string;
@@ -1,5 +1,5 @@
1
1
  import { VorimSDK, ReplayInputs } from '../index.cjs';
2
- import { P as PermissionScope } from '../types-Cb6V-boJ.cjs';
2
+ import { P as PermissionScope } from '../types-zzK9YOoa.cjs';
3
3
  import { E as EscalationPolicy, T as TransportFailurePolicy } from '../_runtime-gate-DOJUKJBu.cjs';
4
4
 
5
5
  interface VercelTool {
@@ -1,5 +1,5 @@
1
1
  import { VorimSDK, ReplayInputs } from '../index.js';
2
- import { P as PermissionScope } from '../types-Cb6V-boJ.js';
2
+ import { P as PermissionScope } from '../types-zzK9YOoa.js';
3
3
  import { E as EscalationPolicy, T as TransportFailurePolicy } from '../_runtime-gate-DOJUKJBu.js';
4
4
 
5
5
  interface VercelTool {
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/integrations/x402.ts
21
+ var x402_exports = {};
22
+ __export(x402_exports, {
23
+ VorimX402: () => VorimX402,
24
+ createVorimX402: () => createVorimX402
25
+ });
26
+ module.exports = __toCommonJS(x402_exports);
27
+ var VorimX402 = class _VorimX402 {
28
+ sdk;
29
+ minTrustScore;
30
+ requiredScope;
31
+ /** One-time guard so the no-auth confused-deputy warning logs at most once. */
32
+ static _warnedNoAuth = false;
33
+ constructor(sdk, config) {
34
+ this.sdk = sdk;
35
+ this.minTrustScore = config?.minTrustScore ?? 50;
36
+ this.requiredScope = config?.requiredScope ?? "agent:transact";
37
+ }
38
+ /**
39
+ * Verify an agent is authorized to settle an x402 payment. Same gate as the
40
+ * ACP integration: transact scope → active status → trust threshold. Every
41
+ * outcome (allow or deny) is recorded on the audit trail.
42
+ */
43
+ async authorizePayment(req) {
44
+ const threshold = req.minTrustScore ?? this.minTrustScore;
45
+ try {
46
+ const perm = await this.sdk.check(req.agentId, this.requiredScope);
47
+ if (!perm.allowed) {
48
+ await this.logEvent(req.agentId, "x402.authorize", "denied", req, { reason: `Missing ${this.requiredScope}` });
49
+ return {
50
+ authorized: false,
51
+ agentId: req.agentId,
52
+ trustScore: 0,
53
+ status: "unknown",
54
+ reason: `Agent does not have ${this.requiredScope} permission`,
55
+ scopeVerified: false
56
+ };
57
+ }
58
+ } catch (e) {
59
+ await this.logEvent(req.agentId, "x402.authorize", "denied", req, { reason: e.message });
60
+ return {
61
+ authorized: false,
62
+ agentId: req.agentId,
63
+ trustScore: 0,
64
+ status: "unknown",
65
+ reason: `Permission check failed: ${e.message}`,
66
+ scopeVerified: false
67
+ };
68
+ }
69
+ let score = 0;
70
+ let status = "unknown";
71
+ try {
72
+ const trust = await this.sdk.verify(req.agentId);
73
+ score = trust.trust_score ?? 0;
74
+ status = trust.status ?? "unknown";
75
+ } catch {
76
+ }
77
+ if (status !== "active") {
78
+ await this.logEvent(req.agentId, "x402.authorize", "denied", req, { reason: `Status: ${status}` });
79
+ return {
80
+ authorized: false,
81
+ agentId: req.agentId,
82
+ trustScore: score,
83
+ status,
84
+ reason: `Agent is ${status}, not active`,
85
+ scopeVerified: true
86
+ };
87
+ }
88
+ if (score < threshold) {
89
+ await this.logEvent(req.agentId, "x402.authorize", "denied", req, { reason: `Score ${score} < ${threshold}` });
90
+ return {
91
+ authorized: false,
92
+ agentId: req.agentId,
93
+ trustScore: score,
94
+ status,
95
+ reason: `Trust score ${score} is below minimum ${threshold}`,
96
+ scopeVerified: true
97
+ };
98
+ }
99
+ await this.logEvent(req.agentId, "x402.authorize", "success", req, { trust_score: score });
100
+ return {
101
+ authorized: true,
102
+ agentId: req.agentId,
103
+ trustScore: score,
104
+ status,
105
+ scopeVerified: true
106
+ };
107
+ }
108
+ /** Log that a 402 payment was settled (proof-of-payment accepted). */
109
+ async logPaymentSettled(agentId, paymentId, req) {
110
+ await this.logEvent(agentId, "x402.settled", "success", req, { payment_id: paymentId });
111
+ }
112
+ /** Log that a 402 payment failed or was rejected by the resource server. */
113
+ async logPaymentFailed(agentId, paymentId, reason, req) {
114
+ await this.logEvent(agentId, "x402.failed", "error", req, { payment_id: paymentId, fail_reason: reason });
115
+ }
116
+ /**
117
+ * Express/Connect middleware for a resource server that gates paid endpoints
118
+ * on agent authorization.
119
+ *
120
+ * ⚠️ CONFUSED-DEPUTY WARNING. This evaluates the *named* agent's standing
121
+ * only; it does NOT prove the HTTP caller controls that agent (any client can
122
+ * send any agent id in the header). Authenticate the caller-to-agent binding
123
+ * upstream, or pass `authenticate` — an async hook that returns true only if
124
+ * the request genuinely speaks for `agentId`. When omitted, a one-time
125
+ * warning is logged.
126
+ */
127
+ middleware(options) {
128
+ const header = options?.agentIdHeader ?? "x-vorim-agent-id";
129
+ const threshold = options?.minTrustScore ?? this.minTrustScore;
130
+ const authenticate = options?.authenticate;
131
+ if (!authenticate && !_VorimX402._warnedNoAuth) {
132
+ _VorimX402._warnedNoAuth = true;
133
+ console.warn(
134
+ "[vorim] VorimX402.middleware() called without an `authenticate` hook: it authorizes the agent NAMED in the header but does not verify the caller controls that agent (confused-deputy risk). Authenticate the caller-to-agent binding upstream or pass `authenticate`."
135
+ );
136
+ }
137
+ return async (req, res, next) => {
138
+ const agentId = req.headers?.[header] || req.headers?.[header.toLowerCase()] || "";
139
+ if (!agentId) {
140
+ res.status(401).json({
141
+ error: { code: "MISSING_AGENT_ID", message: `Agent ID required in ${header} header` }
142
+ });
143
+ return;
144
+ }
145
+ if (authenticate) {
146
+ let bound = false;
147
+ try {
148
+ bound = await authenticate(agentId, req);
149
+ } catch {
150
+ bound = false;
151
+ }
152
+ if (!bound) {
153
+ res.status(401).json({
154
+ error: { code: "AGENT_BINDING_UNVERIFIED", message: "Caller is not authenticated as the named agent" }
155
+ });
156
+ return;
157
+ }
158
+ }
159
+ const auth = await this.authorizePayment({
160
+ agentId,
161
+ resource: req.originalUrl || req.url || "",
162
+ amount: req.body?.amount || 0,
163
+ currency: req.body?.currency || "USDC",
164
+ payTo: req.body?.payTo || "",
165
+ minTrustScore: threshold
166
+ });
167
+ if (!auth.authorized) {
168
+ res.status(402).json({
169
+ error: {
170
+ code: "UNAUTHORIZED_AGENT",
171
+ message: auth.reason || "Agent not authorized for x402 payment",
172
+ trust_score: auth.trustScore,
173
+ status: auth.status
174
+ }
175
+ });
176
+ return;
177
+ }
178
+ req.vorimAuthorization = auth;
179
+ next();
180
+ };
181
+ }
182
+ async logEvent(agentId, action, result, req, metadata) {
183
+ try {
184
+ await this.sdk.emit({
185
+ agent_id: agentId,
186
+ event_type: "api_request",
187
+ action,
188
+ result,
189
+ resource: req?.resource || "",
190
+ metadata: {
191
+ resource: req?.resource || "",
192
+ amount: req?.amount || 0,
193
+ currency: req?.currency || "",
194
+ pay_to: req?.payTo || "",
195
+ scheme: req?.scheme || "",
196
+ ...metadata
197
+ }
198
+ });
199
+ } catch {
200
+ }
201
+ }
202
+ };
203
+ function createVorimX402(sdk, config) {
204
+ return new VorimX402(sdk, config);
205
+ }
206
+ // Annotate the CommonJS export names for ESM import in node:
207
+ 0 && (module.exports = {
208
+ VorimX402,
209
+ createVorimX402
210
+ });
211
+ //# sourceMappingURL=x402.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/integrations/x402.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — x402 Integration\n//\n// x402 is an open, HTTP-native payment standard (revived around the HTTP 402\n// \"Payment Required\" status) for machine-to-machine and agentic payments: a\n// server answers a request with 402 + payment requirements, the client pays,\n// and retries with proof of payment. It's a natural fit for AI agents paying\n// per-request for APIs, data, or compute.\n//\n// This integration adds Vorim's identity, permission, and audit layer IN FRONT\n// of an x402 payment: before an agent settles a 402 challenge, it verifies the\n// agent holds the `transact` scope, is active, and clears a trust threshold,\n// then records the payment lifecycle on a signed, tamper-evident audit trail.\n// It does NOT move money or hold keys — it authorizes and attests.\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimX402 } from '@vorim/sdk/integrations/x402';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const x402 = createVorimX402(vorim, { minTrustScore: 60 });\n//\n// // A 402 came back from a resource server. Before paying, authorize:\n// const auth = await x402.authorizePayment({\n// agentId: 'agid_abc123',\n// resource: 'https://api.example.com/v1/report',\n// amount: 1000, // smallest currency unit (e.g. 1000 = $0.01 at 6dp, or 1000 cents)\n// currency: 'USDC',\n// payTo: '0xSeller...',\n// });\n// if (auth.authorized) {\n// // ... settle the x402 challenge, then:\n// await x402.logPaymentSettled(auth.agentId, paymentId, { resource, amount });\n// }\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\n\nexport interface X402Config {\n apiKey: string;\n baseUrl?: string;\n minTrustScore?: number;\n requiredScope?: string;\n}\n\nexport interface X402PaymentRequest {\n /** The Vorim agent id that will make the payment. */\n agentId: string;\n /** The resource / endpoint being paid for (the thing behind the 402). */\n resource?: string;\n /** Amount in the smallest unit of the currency/asset. */\n amount?: number;\n /** Asset or currency code (e.g. 'USDC', 'usd'). */\n currency?: string;\n /** The recipient address / account the payment settles to. */\n payTo?: string;\n /** The x402 scheme / network hint (e.g. 'exact', 'base-sepolia'). Informational. */\n scheme?: string;\n /** Per-call override of the trust threshold. */\n minTrustScore?: number;\n}\n\nexport interface X402Authorization {\n authorized: boolean;\n agentId: string;\n trustScore: number;\n status: string;\n reason?: string;\n scopeVerified: boolean;\n}\n\nexport class VorimX402 {\n private sdk: VorimSDK;\n private minTrustScore: number;\n private requiredScope: string;\n /** One-time guard so the no-auth confused-deputy warning logs at most once. */\n private static _warnedNoAuth = false;\n\n constructor(sdk: VorimSDK, config?: Partial<X402Config>) {\n this.sdk = sdk;\n this.minTrustScore = config?.minTrustScore ?? 50;\n this.requiredScope = config?.requiredScope ?? 'agent:transact';\n }\n\n /**\n * Verify an agent is authorized to settle an x402 payment. Same gate as the\n * ACP integration: transact scope → active status → trust threshold. Every\n * outcome (allow or deny) is recorded on the audit trail.\n */\n async authorizePayment(req: X402PaymentRequest): Promise<X402Authorization> {\n const threshold = req.minTrustScore ?? this.minTrustScore;\n\n // 1. Permission: the agent must hold the transact scope.\n try {\n const perm = await this.sdk.check(req.agentId, this.requiredScope as any);\n if (!(perm as any).allowed) {\n await this.logEvent(req.agentId, 'x402.authorize', 'denied', req, { reason: `Missing ${this.requiredScope}` });\n return {\n authorized: false,\n agentId: req.agentId,\n trustScore: 0,\n status: 'unknown',\n reason: `Agent does not have ${this.requiredScope} permission`,\n scopeVerified: false,\n };\n }\n } catch (e: any) {\n await this.logEvent(req.agentId, 'x402.authorize', 'denied', req, { reason: e.message });\n return {\n authorized: false,\n agentId: req.agentId,\n trustScore: 0,\n status: 'unknown',\n reason: `Permission check failed: ${e.message}`,\n scopeVerified: false,\n };\n }\n\n // 2. Trust: verify the agent's public standing.\n let score = 0;\n let status = 'unknown';\n try {\n const trust = await this.sdk.verify(req.agentId);\n score = (trust as any).trust_score ?? 0;\n status = (trust as any).status ?? 'unknown';\n } catch {\n // Trust verification failed — treated as not-active below.\n }\n\n if (status !== 'active') {\n await this.logEvent(req.agentId, 'x402.authorize', 'denied', req, { reason: `Status: ${status}` });\n return {\n authorized: false,\n agentId: req.agentId,\n trustScore: score,\n status,\n reason: `Agent is ${status}, not active`,\n scopeVerified: true,\n };\n }\n\n if (score < threshold) {\n await this.logEvent(req.agentId, 'x402.authorize', 'denied', req, { reason: `Score ${score} < ${threshold}` });\n return {\n authorized: false,\n agentId: req.agentId,\n trustScore: score,\n status,\n reason: `Trust score ${score} is below minimum ${threshold}`,\n scopeVerified: true,\n };\n }\n\n await this.logEvent(req.agentId, 'x402.authorize', 'success', req, { trust_score: score });\n\n return {\n authorized: true,\n agentId: req.agentId,\n trustScore: score,\n status,\n scopeVerified: true,\n };\n }\n\n /** Log that a 402 payment was settled (proof-of-payment accepted). */\n async logPaymentSettled(agentId: string, paymentId: string, req?: Partial<X402PaymentRequest>): Promise<void> {\n await this.logEvent(agentId, 'x402.settled', 'success', req, { payment_id: paymentId });\n }\n\n /** Log that a 402 payment failed or was rejected by the resource server. */\n async logPaymentFailed(agentId: string, paymentId: string, reason?: string, req?: Partial<X402PaymentRequest>): Promise<void> {\n await this.logEvent(agentId, 'x402.failed', 'error', req, { payment_id: paymentId, fail_reason: reason });\n }\n\n /**\n * Express/Connect middleware for a resource server that gates paid endpoints\n * on agent authorization.\n *\n * ⚠️ CONFUSED-DEPUTY WARNING. This evaluates the *named* agent's standing\n * only; it does NOT prove the HTTP caller controls that agent (any client can\n * send any agent id in the header). Authenticate the caller-to-agent binding\n * upstream, or pass `authenticate` — an async hook that returns true only if\n * the request genuinely speaks for `agentId`. When omitted, a one-time\n * warning is logged.\n */\n middleware(options?: {\n agentIdHeader?: string;\n minTrustScore?: number;\n authenticate?: (agentId: string, req: any) => boolean | Promise<boolean>;\n }) {\n const header = options?.agentIdHeader ?? 'x-vorim-agent-id';\n const threshold = options?.minTrustScore ?? this.minTrustScore;\n const authenticate = options?.authenticate;\n\n if (!authenticate && !VorimX402._warnedNoAuth) {\n VorimX402._warnedNoAuth = true;\n // eslint-disable-next-line no-console\n console.warn(\n '[vorim] VorimX402.middleware() called without an `authenticate` hook: ' +\n 'it authorizes the agent NAMED in the header but does not verify the ' +\n 'caller controls that agent (confused-deputy risk). Authenticate the ' +\n 'caller-to-agent binding upstream or pass `authenticate`.'\n );\n }\n\n return async (req: any, res: any, next: any) => {\n const agentId = req.headers?.[header] || req.headers?.[header.toLowerCase()] || '';\n\n if (!agentId) {\n res.status(401).json({\n error: { code: 'MISSING_AGENT_ID', message: `Agent ID required in ${header} header` },\n });\n return;\n }\n\n if (authenticate) {\n let bound = false;\n try {\n bound = await authenticate(agentId, req);\n } catch {\n bound = false;\n }\n if (!bound) {\n res.status(401).json({\n error: { code: 'AGENT_BINDING_UNVERIFIED', message: 'Caller is not authenticated as the named agent' },\n });\n return;\n }\n }\n\n const auth = await this.authorizePayment({\n agentId,\n resource: req.originalUrl || req.url || '',\n amount: req.body?.amount || 0,\n currency: req.body?.currency || 'USDC',\n payTo: req.body?.payTo || '',\n minTrustScore: threshold,\n });\n\n if (!auth.authorized) {\n // 402 is the semantically correct status for x402 payment gating.\n res.status(402).json({\n error: {\n code: 'UNAUTHORIZED_AGENT',\n message: auth.reason || 'Agent not authorized for x402 payment',\n trust_score: auth.trustScore,\n status: auth.status,\n },\n });\n return;\n }\n\n req.vorimAuthorization = auth;\n next();\n };\n }\n\n private async logEvent(\n agentId: string,\n action: string,\n result: 'success' | 'denied' | 'error',\n req?: Partial<X402PaymentRequest>,\n metadata?: Record<string, any>,\n ): Promise<void> {\n try {\n await this.sdk.emit({\n agent_id: agentId,\n event_type: 'api_request',\n action,\n result,\n resource: req?.resource || '',\n metadata: {\n resource: req?.resource || '',\n amount: req?.amount || 0,\n currency: req?.currency || '',\n pay_to: req?.payTo || '',\n scheme: req?.scheme || '',\n ...metadata,\n },\n });\n } catch {\n // Never block the payment flow on an audit hiccup.\n }\n }\n}\n\n/**\n * Create a VorimX402 instance.\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimX402 } from '@vorim/sdk/integrations/x402';\n *\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const x402 = createVorimX402(vorim, { minTrustScore: 70 });\n *\n * const auth = await x402.authorizePayment({ agentId: 'agid_abc123', resource: '/report', amount: 1000, currency: 'USDC' });\n *\n * app.get('/paid-endpoint', x402.middleware(), handler);\n * ```\n */\nexport function createVorimX402(sdk: VorimSDK, config?: Partial<X402Config>): VorimX402 {\n return new VorimX402(sdk, config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuEO,IAAM,YAAN,MAAM,WAAU;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAER,OAAe,gBAAgB;AAAA,EAE/B,YAAY,KAAe,QAA8B;AACvD,SAAK,MAAM;AACX,SAAK,gBAAgB,QAAQ,iBAAiB;AAC9C,SAAK,gBAAgB,QAAQ,iBAAiB;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,iBAAiB,KAAqD;AAC1E,UAAM,YAAY,IAAI,iBAAiB,KAAK;AAG5C,QAAI;AACF,YAAM,OAAO,MAAM,KAAK,IAAI,MAAM,IAAI,SAAS,KAAK,aAAoB;AACxE,UAAI,CAAE,KAAa,SAAS;AAC1B,cAAM,KAAK,SAAS,IAAI,SAAS,kBAAkB,UAAU,KAAK,EAAE,QAAQ,WAAW,KAAK,aAAa,GAAG,CAAC;AAC7G,eAAO;AAAA,UACL,YAAY;AAAA,UACZ,SAAS,IAAI;AAAA,UACb,YAAY;AAAA,UACZ,QAAQ;AAAA,UACR,QAA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ACF;AAEA,YAAM,OAAO,MAAM,KAAK,iBAAiB;AAAA,QACvC;AAAA,QACA,UAAU,IAAI,eAAe,IAAI,OAAO;AAAA,QACxC,QAAQ,IAAI,MAAM,UAAU;AAAA,QAC5B,UAAU,IAAI,MAAM,YAAY;AAAA,QAChC,OAAO,IAAI,MAAM,SAAS;AAAA,QAC1B,eAAe;AAAA,MACjB,CAAC;AAED,UAAI,CAAC,KAAK,YAAY;AAEpB,YAAI,OAAO,GAAG,EAAE,KAAK;AAAA,UACnB,OAAO;AAAA,YACL,MAAM;AAAA,YACN,SAAS,KAAK,UAAU;AAAA,YACxB,aAAa,KAAK;AAAA,YAClB,QAAQ,KAAK;AAAA,UACf;AAAA,QACF,CAAC;AACD;AAAA,MACF;AAEA,UAAI,qBAAqB;AACzB,WAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEA,MAAc,SACZ,SACA,QACA,QACA,KACA,UACe;AACf,QAAI;AACF,YAAM,KAAK,IAAI,KAAK;AAAA,QAClB,UAAU;AAAA,QACV,YAAY;AAAA,QACZ;AAAA,QACA;AAAA,QACA,UAAU,KAAK,YAAY;AAAA,QAC3B,UAAU;AAAA,UACR,UAAU,KAAK,YAAY;AAAA,UAC3B,QAAQ,KAAK,UAAU;AAAA,UACvB,UAAU,KAAK,YAAY;AAAA,UAC3B,QAAQ,KAAK,SAAS;AAAA,UACtB,QAAQ,KAAK,UAAU;AAAA,UACvB,GAAG;AAAA,QACL;AAAA,MACF,CAAC;AAAA,IACH,QAAQ;AAAA,IAER;AAAA,EACF;AACF;AAkBO,SAAS,gBAAgB,KAAe,QAAyC;AACtF,SAAO,IAAI,UAAU,KAAK,MAAM;AAClC;","names":[]}
@@ -0,0 +1,87 @@
1
+ import { VorimSDK } from '../index.cjs';
2
+ import '../types-zzK9YOoa.cjs';
3
+
4
+ interface X402Config {
5
+ apiKey: string;
6
+ baseUrl?: string;
7
+ minTrustScore?: number;
8
+ requiredScope?: string;
9
+ }
10
+ interface X402PaymentRequest {
11
+ /** The Vorim agent id that will make the payment. */
12
+ agentId: string;
13
+ /** The resource / endpoint being paid for (the thing behind the 402). */
14
+ resource?: string;
15
+ /** Amount in the smallest unit of the currency/asset. */
16
+ amount?: number;
17
+ /** Asset or currency code (e.g. 'USDC', 'usd'). */
18
+ currency?: string;
19
+ /** The recipient address / account the payment settles to. */
20
+ payTo?: string;
21
+ /** The x402 scheme / network hint (e.g. 'exact', 'base-sepolia'). Informational. */
22
+ scheme?: string;
23
+ /** Per-call override of the trust threshold. */
24
+ minTrustScore?: number;
25
+ }
26
+ interface X402Authorization {
27
+ authorized: boolean;
28
+ agentId: string;
29
+ trustScore: number;
30
+ status: string;
31
+ reason?: string;
32
+ scopeVerified: boolean;
33
+ }
34
+ declare class VorimX402 {
35
+ private sdk;
36
+ private minTrustScore;
37
+ private requiredScope;
38
+ /** One-time guard so the no-auth confused-deputy warning logs at most once. */
39
+ private static _warnedNoAuth;
40
+ constructor(sdk: VorimSDK, config?: Partial<X402Config>);
41
+ /**
42
+ * Verify an agent is authorized to settle an x402 payment. Same gate as the
43
+ * ACP integration: transact scope → active status → trust threshold. Every
44
+ * outcome (allow or deny) is recorded on the audit trail.
45
+ */
46
+ authorizePayment(req: X402PaymentRequest): Promise<X402Authorization>;
47
+ /** Log that a 402 payment was settled (proof-of-payment accepted). */
48
+ logPaymentSettled(agentId: string, paymentId: string, req?: Partial<X402PaymentRequest>): Promise<void>;
49
+ /** Log that a 402 payment failed or was rejected by the resource server. */
50
+ logPaymentFailed(agentId: string, paymentId: string, reason?: string, req?: Partial<X402PaymentRequest>): Promise<void>;
51
+ /**
52
+ * Express/Connect middleware for a resource server that gates paid endpoints
53
+ * on agent authorization.
54
+ *
55
+ * ⚠️ CONFUSED-DEPUTY WARNING. This evaluates the *named* agent's standing
56
+ * only; it does NOT prove the HTTP caller controls that agent (any client can
57
+ * send any agent id in the header). Authenticate the caller-to-agent binding
58
+ * upstream, or pass `authenticate` — an async hook that returns true only if
59
+ * the request genuinely speaks for `agentId`. When omitted, a one-time
60
+ * warning is logged.
61
+ */
62
+ middleware(options?: {
63
+ agentIdHeader?: string;
64
+ minTrustScore?: number;
65
+ authenticate?: (agentId: string, req: any) => boolean | Promise<boolean>;
66
+ }): (req: any, res: any, next: any) => Promise<void>;
67
+ private logEvent;
68
+ }
69
+ /**
70
+ * Create a VorimX402 instance.
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * import createVorim from '@vorim/sdk';
75
+ * import { createVorimX402 } from '@vorim/sdk/integrations/x402';
76
+ *
77
+ * const vorim = createVorim({ apiKey: 'agid_sk_...' });
78
+ * const x402 = createVorimX402(vorim, { minTrustScore: 70 });
79
+ *
80
+ * const auth = await x402.authorizePayment({ agentId: 'agid_abc123', resource: '/report', amount: 1000, currency: 'USDC' });
81
+ *
82
+ * app.get('/paid-endpoint', x402.middleware(), handler);
83
+ * ```
84
+ */
85
+ declare function createVorimX402(sdk: VorimSDK, config?: Partial<X402Config>): VorimX402;
86
+
87
+ export { VorimX402, type X402Authorization, type X402Config, type X402PaymentRequest, createVorimX402 };