@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 @@
1
+ {"version":3,"sources":["../../src/integrations/ap2.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — AP2 (Agent Payments Protocol) Integration\n//\n// AP2 is an open agent-payments standard (announced by Google in Sept 2025,\n// donated to the FIDO Alliance in April 2026). It defines cryptographically\n// signed \"mandates\" that authorize an agent to buy and to pay:\n// • Checkout Mandate — proof the agent is authorized to buy the assembled cart\n// • Payment Mandate — proof the agent is authorized to pay for that checkout\n// Mandates are SD-JWT Verifiable Credentials (ES256), chained to a merchant-\n// signed Checkout JWT. AP2 is the authorization layer; it does not move money.\n//\n// This integration adds Vorim's identity, permission, and audit layer AROUND\n// an AP2 mandate flow: before an agent presents or signs a mandate, it verifies\n// the agent holds `transact`, is active, and clears a trust threshold, and it\n// records the mandate + receipt lifecycle on a signed, tamper-evident audit\n// trail — with the AP2 checkout/mandate hashes captured so the two evidence\n// trails line up. It does NOT sign AP2 mandates or hold keys; that stays with\n// the AP2 SDK and the user's trusted surface.\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimAP2 } from '@vorim/sdk/integrations/ap2';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const ap2 = createVorimAP2(vorim, { minTrustScore: 60 });\n//\n// // Before the agent presents/signs a mandate for a cart:\n// const auth = await ap2.authorizeMandate({\n// agentId: 'agid_abc123',\n// mandateType: 'payment',\n// merchant: 'acme-store',\n// amount: 9999,\n// currency: 'usd',\n// checkoutHash: 'sha256:...', // hash of the merchant-signed Checkout JWT\n// });\n// if (auth.authorized) {\n// // ... present/sign the AP2 mandate via the AP2 SDK, then:\n// await ap2.logMandatePresented(auth.agentId, mandateId, { checkoutHash });\n// }\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\n\nexport type AP2MandateType = 'checkout' | 'payment';\n\nexport interface AP2Config {\n apiKey: string;\n baseUrl?: string;\n minTrustScore?: number;\n requiredScope?: string;\n}\n\nexport interface AP2MandateRequest {\n /** The Vorim agent id presenting/signing the mandate. */\n agentId: string;\n /** Which AP2 mandate is being authorized. */\n mandateType?: AP2MandateType;\n /** The merchant the cart/checkout belongs to. */\n merchant?: string;\n /** Amount in the smallest currency unit. */\n amount?: number;\n /** Currency / instrument code (e.g. 'usd', 'USDC'). */\n currency?: string;\n /**\n * Hash of the merchant-signed AP2 Checkout JWT that the mandate binds to.\n * Recorded so the Vorim audit trail and the AP2 mandate chain reconcile.\n */\n checkoutHash?: string;\n /** AP2 mode: user present (Direct) or not present (Autonomous). Informational. */\n mode?: 'direct' | 'autonomous';\n /** Per-call override of the trust threshold. */\n minTrustScore?: number;\n}\n\nexport interface AP2Authorization {\n authorized: boolean;\n agentId: string;\n trustScore: number;\n status: string;\n reason?: string;\n scopeVerified: boolean;\n}\n\nexport class VorimAP2 {\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<AP2Config>) {\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 present/sign an AP2 mandate. Same gate as\n * the other payment integrations: transact scope → active status → trust\n * threshold. Every outcome (allow or deny) is recorded on the audit trail,\n * carrying the AP2 checkout hash so the evidence trails reconcile.\n */\n async authorizeMandate(req: AP2MandateRequest): Promise<AP2Authorization> {\n const threshold = req.minTrustScore ?? this.minTrustScore;\n const action = `ap2.${req.mandateType ?? 'payment'}_mandate.authorize`;\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, action, '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, action, '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, action, '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, action, '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, action, '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 an AP2 mandate was presented/signed. */\n async logMandatePresented(agentId: string, mandateId: string, req?: Partial<AP2MandateRequest>): Promise<void> {\n await this.logEvent(agentId, `ap2.${req?.mandateType ?? 'payment'}_mandate.presented`, 'success', req, { mandate_id: mandateId });\n }\n\n /** Log that an AP2 payment receipt was issued and verified (payment settled). */\n async logReceiptVerified(agentId: string, receiptId: string, req?: Partial<AP2MandateRequest>): Promise<void> {\n await this.logEvent(agentId, 'ap2.receipt.verified', 'success', req, { receipt_id: receiptId });\n }\n\n /** Log that an AP2 mandate/payment was rejected or failed downstream. */\n async logMandateRejected(agentId: string, mandateId: string, reason?: string, req?: Partial<AP2MandateRequest>): Promise<void> {\n await this.logEvent(agentId, `ap2.${req?.mandateType ?? 'payment'}_mandate.rejected`, 'error', req, { mandate_id: mandateId, reject_reason: reason });\n }\n\n /**\n * Express/Connect middleware for a merchant/processor endpoint that gates an\n * AP2 mandate presentation 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, and it does\n * NOT itself verify the AP2 mandate's cryptographic signature (do that with\n * the AP2 SDK). Authenticate the caller-to-agent binding upstream, or pass\n * `authenticate`. When omitted, a 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 && !VorimAP2._warnedNoAuth) {\n VorimAP2._warnedNoAuth = true;\n // eslint-disable-next-line no-console\n console.warn(\n '[vorim] VorimAP2.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), and it does not ' +\n 'verify the AP2 mandate signature. Authenticate the caller-to-agent ' +\n '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.authorizeMandate({\n agentId,\n mandateType: (req.body?.mandateType as AP2MandateType) || 'payment',\n merchant: req.body?.merchant || '',\n amount: req.body?.amount || 0,\n currency: req.body?.currency || 'usd',\n checkoutHash: req.body?.checkoutHash || '',\n minTrustScore: threshold,\n });\n\n if (!auth.authorized) {\n res.status(403).json({\n error: {\n code: 'UNAUTHORIZED_AGENT',\n message: auth.reason || 'Agent not authorized to present an AP2 mandate',\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<AP2MandateRequest>,\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?.merchant || '',\n metadata: {\n mandate_type: req?.mandateType || '',\n merchant: req?.merchant || '',\n amount: req?.amount || 0,\n currency: req?.currency || '',\n checkout_hash: req?.checkoutHash || '',\n mode: req?.mode || '',\n ...metadata,\n },\n });\n } catch {\n // Never block the payment flow on an audit hiccup.\n }\n }\n}\n\n/**\n * Create a VorimAP2 instance.\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimAP2 } from '@vorim/sdk/integrations/ap2';\n *\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const ap2 = createVorimAP2(vorim, { minTrustScore: 70 });\n *\n * const auth = await ap2.authorizeMandate({ agentId: 'agid_abc123', mandateType: 'payment', merchant: 'shop', amount: 4999 });\n *\n * app.post('/ap2/mandate', ap2.middleware(), presentMandateHandler);\n * ```\n */\nexport function createVorimAP2(sdk: VorimSDK, config?: Partial<AP2Config>): VorimAP2 {\n return new VorimAP2(sdk, config);\n}\n"],"mappings":";AAmFO,IAAM,WAAN,MAAM,UAAS;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAER,OAAe,gBAAgB;AAAA,EAE/B,YAAY,KAAe,QAA6B;AACtD,SAAK,MAAM;AACX,SAAK,gBAAgB,QAAQ,iBAAiB;AAC9C,SAAK,gBAAgB,QAAQ,i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Ac,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,cAAc,KAAK,eAAe;AAAA,UAClC,UAAU,KAAK,YAAY;AAAA,UAC3B,QAAQ,KAAK,UAAU;AAAA,UACvB,UAAU,KAAK,YAAY;AAAA,UAC3B,eAAe,KAAK,gBAAgB;AAAA,UACpC,MAAM,KAAK,QAAQ;AAAA,UACnB,GAAG;AAAA,QACL;AAAA,MACF,CAAC;AAAA,IACH,QAAQ;AAAA,IAER;AAAA,EACF;AACF;AAkBO,SAAS,eAAe,KAAe,QAAuC;AACnF,SAAO,IAAI,SAAS,KAAK,MAAM;AACjC;","names":[]}
@@ -0,0 +1,173 @@
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/bank-rails.ts
21
+ var bank_rails_exports = {};
22
+ __export(bank_rails_exports, {
23
+ VorimBankRails: () => VorimBankRails,
24
+ createVorimBankRails: () => createVorimBankRails
25
+ });
26
+ module.exports = __toCommonJS(bank_rails_exports);
27
+ var VorimBankRails = class _VorimBankRails {
28
+ sdk;
29
+ minTrustScore;
30
+ requiredScope;
31
+ provider;
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
+ this.provider = config?.provider ?? "generic";
38
+ }
39
+ /**
40
+ * Verify an agent is authorized to initiate a bank transfer. Given these move
41
+ * real money, callers typically set a higher minTrustScore. Same gate: scope
42
+ * → active status → trust.
43
+ */
44
+ async authorizeTransfer(req) {
45
+ const threshold = req.minTrustScore ?? this.minTrustScore;
46
+ try {
47
+ const perm = await this.sdk.check(req.agentId, this.requiredScope);
48
+ if (!perm.allowed) {
49
+ await this.logEvent(req.agentId, "bank.transfer.authorize", "denied", req, { reason: `Missing ${this.requiredScope}` });
50
+ return { authorized: false, agentId: req.agentId, trustScore: 0, status: "unknown", reason: `Agent does not have ${this.requiredScope} permission`, scopeVerified: false };
51
+ }
52
+ } catch (e) {
53
+ await this.logEvent(req.agentId, "bank.transfer.authorize", "denied", req, { reason: e.message });
54
+ return { authorized: false, agentId: req.agentId, trustScore: 0, status: "unknown", reason: `Permission check failed: ${e.message}`, scopeVerified: false };
55
+ }
56
+ let score = 0;
57
+ let status = "unknown";
58
+ try {
59
+ const trust = await this.sdk.verify(req.agentId);
60
+ score = trust.trust_score ?? 0;
61
+ status = trust.status ?? "unknown";
62
+ } catch {
63
+ }
64
+ if (status !== "active") {
65
+ await this.logEvent(req.agentId, "bank.transfer.authorize", "denied", req, { reason: `Status: ${status}` });
66
+ return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Agent is ${status}, not active`, scopeVerified: true };
67
+ }
68
+ if (score < threshold) {
69
+ await this.logEvent(req.agentId, "bank.transfer.authorize", "denied", req, { reason: `Score ${score} < ${threshold}` });
70
+ return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Trust score ${score} is below minimum ${threshold}`, scopeVerified: true };
71
+ }
72
+ await this.logEvent(req.agentId, "bank.transfer.authorize", "success", req, { trust_score: score });
73
+ return { authorized: true, agentId: req.agentId, trustScore: score, status, scopeVerified: true };
74
+ }
75
+ /** Log that a bank transfer was initiated (created, possibly pending approval). */
76
+ async logTransferInitiated(agentId, transferId, req) {
77
+ await this.logEvent(agentId, "bank.transfer.initiated", "success", req, { transfer_id: transferId });
78
+ }
79
+ /** Log that a transfer was approved (e.g. Increase's require_approval → approve). */
80
+ async logTransferApproved(agentId, transferId, approver, req) {
81
+ await this.logEvent(agentId, "bank.transfer.approved", "success", req, { transfer_id: transferId, approver });
82
+ }
83
+ /** Log that a transfer settled on the rail. */
84
+ async logTransferSettled(agentId, transferId, req) {
85
+ await this.logEvent(agentId, "bank.transfer.settled", "success", req, { transfer_id: transferId });
86
+ }
87
+ /** Log that a transfer was returned, declined, or failed. */
88
+ async logTransferFailed(agentId, transferId, reason, req) {
89
+ await this.logEvent(agentId, "bank.transfer.failed", "error", req, { transfer_id: transferId, fail_reason: reason });
90
+ }
91
+ /**
92
+ * Express/Connect middleware that gates a transfer-initiation endpoint on
93
+ * agent authorization.
94
+ *
95
+ * ⚠️ CONFUSED-DEPUTY WARNING. Evaluates the *named* agent only; pass
96
+ * `authenticate` to verify the caller-to-agent binding. When omitted, a
97
+ * one-time warning is logged. For money movement, wiring `authenticate` is
98
+ * strongly recommended.
99
+ */
100
+ middleware(options) {
101
+ const header = options?.agentIdHeader ?? "x-vorim-agent-id";
102
+ const threshold = options?.minTrustScore ?? this.minTrustScore;
103
+ const authenticate = options?.authenticate;
104
+ if (!authenticate && !_VorimBankRails._warnedNoAuth) {
105
+ _VorimBankRails._warnedNoAuth = true;
106
+ console.warn(
107
+ "[vorim] VorimBankRails.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). This gates real money movement \u2014 pass `authenticate`."
108
+ );
109
+ }
110
+ return async (req, res, next) => {
111
+ const agentId = req.headers?.[header] || req.headers?.[header.toLowerCase()] || "";
112
+ if (!agentId) {
113
+ res.status(401).json({ error: { code: "MISSING_AGENT_ID", message: `Agent ID required in ${header} header` } });
114
+ return;
115
+ }
116
+ if (authenticate) {
117
+ let bound = false;
118
+ try {
119
+ bound = await authenticate(agentId, req);
120
+ } catch {
121
+ bound = false;
122
+ }
123
+ if (!bound) {
124
+ res.status(401).json({ error: { code: "AGENT_BINDING_UNVERIFIED", message: "Caller is not authenticated as the named agent" } });
125
+ return;
126
+ }
127
+ }
128
+ const auth = await this.authorizeTransfer({
129
+ agentId,
130
+ rail: req.body?.rail || "ach",
131
+ amount: req.body?.amount || 0,
132
+ currency: req.body?.currency || "usd",
133
+ counterparty: req.body?.counterparty || "",
134
+ minTrustScore: threshold
135
+ });
136
+ if (!auth.authorized) {
137
+ res.status(403).json({ error: { code: "UNAUTHORIZED_AGENT", message: auth.reason || "Agent not authorized to move money", trust_score: auth.trustScore, status: auth.status } });
138
+ return;
139
+ }
140
+ req.vorimAuthorization = auth;
141
+ next();
142
+ };
143
+ }
144
+ async logEvent(agentId, action, result, req, metadata) {
145
+ try {
146
+ await this.sdk.emit({
147
+ agent_id: agentId,
148
+ event_type: "api_request",
149
+ action,
150
+ result,
151
+ resource: req?.counterparty || "",
152
+ metadata: {
153
+ provider: this.provider,
154
+ rail: req?.rail || "",
155
+ amount: req?.amount || 0,
156
+ currency: req?.currency || "",
157
+ counterparty: req?.counterparty || "",
158
+ ...metadata
159
+ }
160
+ });
161
+ } catch {
162
+ }
163
+ }
164
+ };
165
+ function createVorimBankRails(sdk, config) {
166
+ return new VorimBankRails(sdk, config);
167
+ }
168
+ // Annotate the CommonJS export names for ESM import in node:
169
+ 0 && (module.exports = {
170
+ VorimBankRails,
171
+ createVorimBankRails
172
+ });
173
+ //# sourceMappingURL=bank-rails.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/integrations/bank-rails.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — Bank Rails Integration (ACH / wire / RTP)\n//\n// Provider-neutral wrapper for agent-initiated bank money movement over\n// developer-bank APIs such as Increase (`POST /ach_transfers`, with a native\n// require_approval → approve state machine) and Column\n// (`POST /transfers/ach|wire`). These rails move real money over ACH, wire, or\n// RTP, so \"which agent may move money, and prove what it did\" is acute.\n//\n// This integration adds Vorim's identity, permission, and audit layer IN FRONT\n// of a transfer: before an agent initiates one, it verifies the agent holds\n// `transact`, is active, and clears a trust threshold, then records the\n// initiate → approve → settle/return lifecycle on a signed, tamper-evident\n// audit trail. It does NOT move money or hold bank credentials — the bank API\n// does the transfer; Vorim authorizes and attests. Pair it with the bank's own\n// approval controls, not instead of them.\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimBankRails } from '@vorim/sdk/integrations/bank-rails';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const bank = createVorimBankRails(vorim, { provider: 'increase', minTrustScore: 70 });\n//\n// const auth = await bank.authorizeTransfer({\n// agentId: 'agid_abc123',\n// rail: 'ach',\n// amount: 250000, // smallest unit (cents)\n// currency: 'usd',\n// counterparty: 'acct_...',\n// });\n// if (auth.authorized) {\n// // ... create the transfer via Increase/Column, then:\n// await bank.logTransferInitiated(auth.agentId, transferId, { rail: 'ach', amount: 250000 });\n// }\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\n\nexport type BankRail = 'ach' | 'wire' | 'rtp' | 'book';\nexport type BankProvider = 'increase' | 'column' | 'generic';\n\nexport interface BankRailsConfig {\n apiKey: string;\n baseUrl?: string;\n minTrustScore?: number;\n requiredScope?: string;\n /** Which bank provider this instance fronts (informational, recorded in audit). */\n provider?: BankProvider;\n}\n\nexport interface BankTransferRequest {\n /** The Vorim agent id initiating the transfer. */\n agentId: string;\n /** Payment rail. */\n rail?: BankRail;\n /** Amount in the smallest currency unit (cents). */\n amount?: number;\n /** Currency code. */\n currency?: string;\n /** The destination account / counterparty reference. */\n counterparty?: string;\n /** Per-call override of the trust threshold. */\n minTrustScore?: number;\n}\n\nexport interface BankTransferAuthorization {\n authorized: boolean;\n agentId: string;\n trustScore: number;\n status: string;\n reason?: string;\n scopeVerified: boolean;\n}\n\nexport class VorimBankRails {\n private sdk: VorimSDK;\n private minTrustScore: number;\n private requiredScope: string;\n private provider: BankProvider;\n private static _warnedNoAuth = false;\n\n constructor(sdk: VorimSDK, config?: Partial<BankRailsConfig>) {\n this.sdk = sdk;\n this.minTrustScore = config?.minTrustScore ?? 50;\n this.requiredScope = config?.requiredScope ?? 'agent:transact';\n this.provider = config?.provider ?? 'generic';\n }\n\n /**\n * Verify an agent is authorized to initiate a bank transfer. Given these move\n * real money, callers typically set a higher minTrustScore. Same gate: scope\n * → active status → trust.\n */\n async authorizeTransfer(req: BankTransferRequest): Promise<BankTransferAuthorization> {\n const threshold = req.minTrustScore ?? this.minTrustScore;\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, 'bank.transfer.authorize', '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, 'bank.transfer.authorize', '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, 'bank.transfer.authorize', '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, 'bank.transfer.authorize', '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, 'bank.transfer.authorize', 'success', req, { trust_score: score });\n return { authorized: true, agentId: req.agentId, trustScore: score, status, scopeVerified: true };\n }\n\n /** Log that a bank transfer was initiated (created, possibly pending approval). */\n async logTransferInitiated(agentId: string, transferId: string, req?: Partial<BankTransferRequest>): Promise<void> {\n await this.logEvent(agentId, 'bank.transfer.initiated', 'success', req, { transfer_id: transferId });\n }\n\n /** Log that a transfer was approved (e.g. Increase's require_approval → approve). */\n async logTransferApproved(agentId: string, transferId: string, approver?: string, req?: Partial<BankTransferRequest>): Promise<void> {\n await this.logEvent(agentId, 'bank.transfer.approved', 'success', req, { transfer_id: transferId, approver });\n }\n\n /** Log that a transfer settled on the rail. */\n async logTransferSettled(agentId: string, transferId: string, req?: Partial<BankTransferRequest>): Promise<void> {\n await this.logEvent(agentId, 'bank.transfer.settled', 'success', req, { transfer_id: transferId });\n }\n\n /** Log that a transfer was returned, declined, or failed. */\n async logTransferFailed(agentId: string, transferId: string, reason?: string, req?: Partial<BankTransferRequest>): Promise<void> {\n await this.logEvent(agentId, 'bank.transfer.failed', 'error', req, { transfer_id: transferId, fail_reason: reason });\n }\n\n /**\n * Express/Connect middleware that gates a transfer-initiation endpoint on\n * agent 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. For money movement, wiring `authenticate` is\n * strongly recommended.\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 && !VorimBankRails._warnedNoAuth) {\n VorimBankRails._warnedNoAuth = true;\n // eslint-disable-next-line no-console\n console.warn(\n '[vorim] VorimBankRails.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). This gates real ' +\n 'money movement — 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.authorizeTransfer({\n agentId,\n rail: (req.body?.rail as BankRail) || 'ach',\n amount: req.body?.amount || 0,\n currency: req.body?.currency || 'usd',\n counterparty: req.body?.counterparty || '',\n minTrustScore: threshold,\n });\n if (!auth.authorized) {\n res.status(403).json({ error: { code: 'UNAUTHORIZED_AGENT', message: auth.reason || 'Agent not authorized to move money', 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<BankTransferRequest>,\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?.counterparty || '',\n metadata: {\n provider: this.provider,\n rail: req?.rail || '',\n amount: req?.amount || 0,\n currency: req?.currency || '',\n counterparty: req?.counterparty || '',\n ...metadata,\n },\n });\n } catch { /* never block the payment flow */ }\n }\n}\n\n/**\n * Create a VorimBankRails instance.\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimBankRails } from '@vorim/sdk/integrations/bank-rails';\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const bank = createVorimBankRails(vorim, { provider: 'increase', minTrustScore: 80 });\n * const auth = await bank.authorizeTransfer({ agentId: 'agid_abc', rail: 'ach', amount: 250000, counterparty: 'acct_1' });\n * ```\n */\nexport function createVorimBankRails(sdk: VorimSDK, config?: Partial<BankRailsConfig>): VorimBankRails {\n return new VorimBankRails(sdk, config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA2EO,IAAM,iBAAN,MAAM,gBAAe;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACR,OAAe,gBAAgB;AAAA,EAE/B,YAAY,KAAe,QAAmC;AAC5D,SAAK,MAAM;AACX,SAAK,gBAAgB,QAAQ,iBAAiB;AAC9C,SAAK,gBAAgB,QAAQ,iBAAiB;AAC9C,SAAK,WAAW,QAAQ,YAAY;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,kBAAkB,KAA8D;AACpF,UAAM,YAAY,IAAI,iBAAiB,KAAK;AAE5C,QAAI;AACF,YAAM,OAAO,MAAM,KAAK,IAAI,MAAM,IAAI,SAAS,KAAK,aAAoB;AACxE,UAAI,CAAE,KAAa,SAAS;AAC1B,cAAM,KAAK,SAAS,IAAI,SAAS,2BAA2B,UAAU,KAAK,EAAE,QAAQ,WAAW,KAAK,aAAa,GAAG,CAAC;AACtH,eAAO,EAAE,YAAY,OAAO,SAAS,IAAI,SAAS,YAAY,GAAG,QAAQ,WAAW,QAAQ,uBAAuB,KAAK,aAAa,eAAe,eAAe,MAAM;AAAA,MAC3K;AAAA,IACF,SAAS,GAAQ;AACf,YAAM,KAAK,SAAS,IAAI,SAAS,2BAA2B,UAAU,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC;AAChG,aAAO,EAAE,YAAY,OAAO,SAAS,IAAI,SAAS,YAAY,GAAG,QAAQ,WAAW,QAAQ,4BAA4B,EAAE,OAAO,IAAI,eAAe,MAAM;AAAA,IAC5J;AAEA,QAA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,MAAM,gBAAgB;AAAA,QACxC,eAAe;AAAA,MACjB,CAAC;AACD,UAAI,CAAC,KAAK,YAAY;AACpB,YAAI,OAAO,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,SAAS,KAAK,UAAU,sCAAsC,aAAa,KAAK,YAAY,QAAQ,KAAK,OAAO,EAAE,CAAC;AAC/K;AAAA,MACF;AACA,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,gBAAgB;AAAA,QAC/B,UAAU;AAAA,UACR,UAAU,KAAK;AAAA,UACf,MAAM,KAAK,QAAQ;AAAA,UACnB,QAAQ,KAAK,UAAU;AAAA,UACvB,UAAU,KAAK,YAAY;AAAA,UAC3B,cAAc,KAAK,gBAAgB;AAAA,UACnC,GAAG;AAAA,QACL;AAAA,MACF,CAAC;AAAA,IACH,QAAQ;AAAA,IAAqC;AAAA,EAC/C;AACF;AAcO,SAAS,qBAAqB,KAAe,QAAmD;AACrG,SAAO,IAAI,eAAe,KAAK,MAAM;AACvC;","names":[]}
@@ -0,0 +1,87 @@
1
+ import { VorimSDK } from '../index.cjs';
2
+ import '../types-zzK9YOoa.cjs';
3
+
4
+ type BankRail = 'ach' | 'wire' | 'rtp' | 'book';
5
+ type BankProvider = 'increase' | 'column' | 'generic';
6
+ interface BankRailsConfig {
7
+ apiKey: string;
8
+ baseUrl?: string;
9
+ minTrustScore?: number;
10
+ requiredScope?: string;
11
+ /** Which bank provider this instance fronts (informational, recorded in audit). */
12
+ provider?: BankProvider;
13
+ }
14
+ interface BankTransferRequest {
15
+ /** The Vorim agent id initiating the transfer. */
16
+ agentId: string;
17
+ /** Payment rail. */
18
+ rail?: BankRail;
19
+ /** Amount in the smallest currency unit (cents). */
20
+ amount?: number;
21
+ /** Currency code. */
22
+ currency?: string;
23
+ /** The destination account / counterparty reference. */
24
+ counterparty?: string;
25
+ /** Per-call override of the trust threshold. */
26
+ minTrustScore?: number;
27
+ }
28
+ interface BankTransferAuthorization {
29
+ authorized: boolean;
30
+ agentId: string;
31
+ trustScore: number;
32
+ status: string;
33
+ reason?: string;
34
+ scopeVerified: boolean;
35
+ }
36
+ declare class VorimBankRails {
37
+ private sdk;
38
+ private minTrustScore;
39
+ private requiredScope;
40
+ private provider;
41
+ private static _warnedNoAuth;
42
+ constructor(sdk: VorimSDK, config?: Partial<BankRailsConfig>);
43
+ /**
44
+ * Verify an agent is authorized to initiate a bank transfer. Given these move
45
+ * real money, callers typically set a higher minTrustScore. Same gate: scope
46
+ * → active status → trust.
47
+ */
48
+ authorizeTransfer(req: BankTransferRequest): Promise<BankTransferAuthorization>;
49
+ /** Log that a bank transfer was initiated (created, possibly pending approval). */
50
+ logTransferInitiated(agentId: string, transferId: string, req?: Partial<BankTransferRequest>): Promise<void>;
51
+ /** Log that a transfer was approved (e.g. Increase's require_approval → approve). */
52
+ logTransferApproved(agentId: string, transferId: string, approver?: string, req?: Partial<BankTransferRequest>): Promise<void>;
53
+ /** Log that a transfer settled on the rail. */
54
+ logTransferSettled(agentId: string, transferId: string, req?: Partial<BankTransferRequest>): Promise<void>;
55
+ /** Log that a transfer was returned, declined, or failed. */
56
+ logTransferFailed(agentId: string, transferId: string, reason?: string, req?: Partial<BankTransferRequest>): Promise<void>;
57
+ /**
58
+ * Express/Connect middleware that gates a transfer-initiation endpoint on
59
+ * agent authorization.
60
+ *
61
+ * ⚠️ CONFUSED-DEPUTY WARNING. Evaluates the *named* agent only; pass
62
+ * `authenticate` to verify the caller-to-agent binding. When omitted, a
63
+ * one-time warning is logged. For money movement, wiring `authenticate` is
64
+ * strongly recommended.
65
+ */
66
+ middleware(options?: {
67
+ agentIdHeader?: string;
68
+ minTrustScore?: number;
69
+ authenticate?: (agentId: string, req: any) => boolean | Promise<boolean>;
70
+ }): (req: any, res: any, next: any) => Promise<void>;
71
+ private logEvent;
72
+ }
73
+ /**
74
+ * Create a VorimBankRails instance.
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * import createVorim from '@vorim/sdk';
79
+ * import { createVorimBankRails } from '@vorim/sdk/integrations/bank-rails';
80
+ * const vorim = createVorim({ apiKey: 'agid_sk_...' });
81
+ * const bank = createVorimBankRails(vorim, { provider: 'increase', minTrustScore: 80 });
82
+ * const auth = await bank.authorizeTransfer({ agentId: 'agid_abc', rail: 'ach', amount: 250000, counterparty: 'acct_1' });
83
+ * ```
84
+ */
85
+ declare function createVorimBankRails(sdk: VorimSDK, config?: Partial<BankRailsConfig>): VorimBankRails;
86
+
87
+ export { type BankProvider, type BankRail, type BankRailsConfig, type BankTransferAuthorization, type BankTransferRequest, VorimBankRails, createVorimBankRails };
@@ -0,0 +1,87 @@
1
+ import { VorimSDK } from '../index.js';
2
+ import '../types-zzK9YOoa.js';
3
+
4
+ type BankRail = 'ach' | 'wire' | 'rtp' | 'book';
5
+ type BankProvider = 'increase' | 'column' | 'generic';
6
+ interface BankRailsConfig {
7
+ apiKey: string;
8
+ baseUrl?: string;
9
+ minTrustScore?: number;
10
+ requiredScope?: string;
11
+ /** Which bank provider this instance fronts (informational, recorded in audit). */
12
+ provider?: BankProvider;
13
+ }
14
+ interface BankTransferRequest {
15
+ /** The Vorim agent id initiating the transfer. */
16
+ agentId: string;
17
+ /** Payment rail. */
18
+ rail?: BankRail;
19
+ /** Amount in the smallest currency unit (cents). */
20
+ amount?: number;
21
+ /** Currency code. */
22
+ currency?: string;
23
+ /** The destination account / counterparty reference. */
24
+ counterparty?: string;
25
+ /** Per-call override of the trust threshold. */
26
+ minTrustScore?: number;
27
+ }
28
+ interface BankTransferAuthorization {
29
+ authorized: boolean;
30
+ agentId: string;
31
+ trustScore: number;
32
+ status: string;
33
+ reason?: string;
34
+ scopeVerified: boolean;
35
+ }
36
+ declare class VorimBankRails {
37
+ private sdk;
38
+ private minTrustScore;
39
+ private requiredScope;
40
+ private provider;
41
+ private static _warnedNoAuth;
42
+ constructor(sdk: VorimSDK, config?: Partial<BankRailsConfig>);
43
+ /**
44
+ * Verify an agent is authorized to initiate a bank transfer. Given these move
45
+ * real money, callers typically set a higher minTrustScore. Same gate: scope
46
+ * → active status → trust.
47
+ */
48
+ authorizeTransfer(req: BankTransferRequest): Promise<BankTransferAuthorization>;
49
+ /** Log that a bank transfer was initiated (created, possibly pending approval). */
50
+ logTransferInitiated(agentId: string, transferId: string, req?: Partial<BankTransferRequest>): Promise<void>;
51
+ /** Log that a transfer was approved (e.g. Increase's require_approval → approve). */
52
+ logTransferApproved(agentId: string, transferId: string, approver?: string, req?: Partial<BankTransferRequest>): Promise<void>;
53
+ /** Log that a transfer settled on the rail. */
54
+ logTransferSettled(agentId: string, transferId: string, req?: Partial<BankTransferRequest>): Promise<void>;
55
+ /** Log that a transfer was returned, declined, or failed. */
56
+ logTransferFailed(agentId: string, transferId: string, reason?: string, req?: Partial<BankTransferRequest>): Promise<void>;
57
+ /**
58
+ * Express/Connect middleware that gates a transfer-initiation endpoint on
59
+ * agent authorization.
60
+ *
61
+ * ⚠️ CONFUSED-DEPUTY WARNING. Evaluates the *named* agent only; pass
62
+ * `authenticate` to verify the caller-to-agent binding. When omitted, a
63
+ * one-time warning is logged. For money movement, wiring `authenticate` is
64
+ * strongly recommended.
65
+ */
66
+ middleware(options?: {
67
+ agentIdHeader?: string;
68
+ minTrustScore?: number;
69
+ authenticate?: (agentId: string, req: any) => boolean | Promise<boolean>;
70
+ }): (req: any, res: any, next: any) => Promise<void>;
71
+ private logEvent;
72
+ }
73
+ /**
74
+ * Create a VorimBankRails instance.
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * import createVorim from '@vorim/sdk';
79
+ * import { createVorimBankRails } from '@vorim/sdk/integrations/bank-rails';
80
+ * const vorim = createVorim({ apiKey: 'agid_sk_...' });
81
+ * const bank = createVorimBankRails(vorim, { provider: 'increase', minTrustScore: 80 });
82
+ * const auth = await bank.authorizeTransfer({ agentId: 'agid_abc', rail: 'ach', amount: 250000, counterparty: 'acct_1' });
83
+ * ```
84
+ */
85
+ declare function createVorimBankRails(sdk: VorimSDK, config?: Partial<BankRailsConfig>): VorimBankRails;
86
+
87
+ export { type BankProvider, type BankRail, type BankRailsConfig, type BankTransferAuthorization, type BankTransferRequest, VorimBankRails, createVorimBankRails };
@@ -0,0 +1,147 @@
1
+ // src/integrations/bank-rails.ts
2
+ var VorimBankRails = class _VorimBankRails {
3
+ sdk;
4
+ minTrustScore;
5
+ requiredScope;
6
+ provider;
7
+ static _warnedNoAuth = false;
8
+ constructor(sdk, config) {
9
+ this.sdk = sdk;
10
+ this.minTrustScore = config?.minTrustScore ?? 50;
11
+ this.requiredScope = config?.requiredScope ?? "agent:transact";
12
+ this.provider = config?.provider ?? "generic";
13
+ }
14
+ /**
15
+ * Verify an agent is authorized to initiate a bank transfer. Given these move
16
+ * real money, callers typically set a higher minTrustScore. Same gate: scope
17
+ * → active status → trust.
18
+ */
19
+ async authorizeTransfer(req) {
20
+ const threshold = req.minTrustScore ?? this.minTrustScore;
21
+ try {
22
+ const perm = await this.sdk.check(req.agentId, this.requiredScope);
23
+ if (!perm.allowed) {
24
+ await this.logEvent(req.agentId, "bank.transfer.authorize", "denied", req, { reason: `Missing ${this.requiredScope}` });
25
+ return { authorized: false, agentId: req.agentId, trustScore: 0, status: "unknown", reason: `Agent does not have ${this.requiredScope} permission`, scopeVerified: false };
26
+ }
27
+ } catch (e) {
28
+ await this.logEvent(req.agentId, "bank.transfer.authorize", "denied", req, { reason: e.message });
29
+ return { authorized: false, agentId: req.agentId, trustScore: 0, status: "unknown", reason: `Permission check failed: ${e.message}`, scopeVerified: false };
30
+ }
31
+ let score = 0;
32
+ let status = "unknown";
33
+ try {
34
+ const trust = await this.sdk.verify(req.agentId);
35
+ score = trust.trust_score ?? 0;
36
+ status = trust.status ?? "unknown";
37
+ } catch {
38
+ }
39
+ if (status !== "active") {
40
+ await this.logEvent(req.agentId, "bank.transfer.authorize", "denied", req, { reason: `Status: ${status}` });
41
+ return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Agent is ${status}, not active`, scopeVerified: true };
42
+ }
43
+ if (score < threshold) {
44
+ await this.logEvent(req.agentId, "bank.transfer.authorize", "denied", req, { reason: `Score ${score} < ${threshold}` });
45
+ return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Trust score ${score} is below minimum ${threshold}`, scopeVerified: true };
46
+ }
47
+ await this.logEvent(req.agentId, "bank.transfer.authorize", "success", req, { trust_score: score });
48
+ return { authorized: true, agentId: req.agentId, trustScore: score, status, scopeVerified: true };
49
+ }
50
+ /** Log that a bank transfer was initiated (created, possibly pending approval). */
51
+ async logTransferInitiated(agentId, transferId, req) {
52
+ await this.logEvent(agentId, "bank.transfer.initiated", "success", req, { transfer_id: transferId });
53
+ }
54
+ /** Log that a transfer was approved (e.g. Increase's require_approval → approve). */
55
+ async logTransferApproved(agentId, transferId, approver, req) {
56
+ await this.logEvent(agentId, "bank.transfer.approved", "success", req, { transfer_id: transferId, approver });
57
+ }
58
+ /** Log that a transfer settled on the rail. */
59
+ async logTransferSettled(agentId, transferId, req) {
60
+ await this.logEvent(agentId, "bank.transfer.settled", "success", req, { transfer_id: transferId });
61
+ }
62
+ /** Log that a transfer was returned, declined, or failed. */
63
+ async logTransferFailed(agentId, transferId, reason, req) {
64
+ await this.logEvent(agentId, "bank.transfer.failed", "error", req, { transfer_id: transferId, fail_reason: reason });
65
+ }
66
+ /**
67
+ * Express/Connect middleware that gates a transfer-initiation endpoint on
68
+ * agent authorization.
69
+ *
70
+ * ⚠️ CONFUSED-DEPUTY WARNING. Evaluates the *named* agent only; pass
71
+ * `authenticate` to verify the caller-to-agent binding. When omitted, a
72
+ * one-time warning is logged. For money movement, wiring `authenticate` is
73
+ * strongly recommended.
74
+ */
75
+ middleware(options) {
76
+ const header = options?.agentIdHeader ?? "x-vorim-agent-id";
77
+ const threshold = options?.minTrustScore ?? this.minTrustScore;
78
+ const authenticate = options?.authenticate;
79
+ if (!authenticate && !_VorimBankRails._warnedNoAuth) {
80
+ _VorimBankRails._warnedNoAuth = true;
81
+ console.warn(
82
+ "[vorim] VorimBankRails.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). This gates real money movement \u2014 pass `authenticate`."
83
+ );
84
+ }
85
+ return async (req, res, next) => {
86
+ const agentId = req.headers?.[header] || req.headers?.[header.toLowerCase()] || "";
87
+ if (!agentId) {
88
+ res.status(401).json({ error: { code: "MISSING_AGENT_ID", message: `Agent ID required in ${header} header` } });
89
+ return;
90
+ }
91
+ if (authenticate) {
92
+ let bound = false;
93
+ try {
94
+ bound = await authenticate(agentId, req);
95
+ } catch {
96
+ bound = false;
97
+ }
98
+ if (!bound) {
99
+ res.status(401).json({ error: { code: "AGENT_BINDING_UNVERIFIED", message: "Caller is not authenticated as the named agent" } });
100
+ return;
101
+ }
102
+ }
103
+ const auth = await this.authorizeTransfer({
104
+ agentId,
105
+ rail: req.body?.rail || "ach",
106
+ amount: req.body?.amount || 0,
107
+ currency: req.body?.currency || "usd",
108
+ counterparty: req.body?.counterparty || "",
109
+ minTrustScore: threshold
110
+ });
111
+ if (!auth.authorized) {
112
+ res.status(403).json({ error: { code: "UNAUTHORIZED_AGENT", message: auth.reason || "Agent not authorized to move money", trust_score: auth.trustScore, status: auth.status } });
113
+ return;
114
+ }
115
+ req.vorimAuthorization = auth;
116
+ next();
117
+ };
118
+ }
119
+ async logEvent(agentId, action, result, req, metadata) {
120
+ try {
121
+ await this.sdk.emit({
122
+ agent_id: agentId,
123
+ event_type: "api_request",
124
+ action,
125
+ result,
126
+ resource: req?.counterparty || "",
127
+ metadata: {
128
+ provider: this.provider,
129
+ rail: req?.rail || "",
130
+ amount: req?.amount || 0,
131
+ currency: req?.currency || "",
132
+ counterparty: req?.counterparty || "",
133
+ ...metadata
134
+ }
135
+ });
136
+ } catch {
137
+ }
138
+ }
139
+ };
140
+ function createVorimBankRails(sdk, config) {
141
+ return new VorimBankRails(sdk, config);
142
+ }
143
+ export {
144
+ VorimBankRails,
145
+ createVorimBankRails
146
+ };
147
+ //# sourceMappingURL=bank-rails.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/integrations/bank-rails.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — Bank Rails Integration (ACH / wire / RTP)\n//\n// Provider-neutral wrapper for agent-initiated bank money movement over\n// developer-bank APIs such as Increase (`POST /ach_transfers`, with a native\n// require_approval → approve state machine) and Column\n// (`POST /transfers/ach|wire`). These rails move real money over ACH, wire, or\n// RTP, so \"which agent may move money, and prove what it did\" is acute.\n//\n// This integration adds Vorim's identity, permission, and audit layer IN FRONT\n// of a transfer: before an agent initiates one, it verifies the agent holds\n// `transact`, is active, and clears a trust threshold, then records the\n// initiate → approve → settle/return lifecycle on a signed, tamper-evident\n// audit trail. It does NOT move money or hold bank credentials — the bank API\n// does the transfer; Vorim authorizes and attests. Pair it with the bank's own\n// approval controls, not instead of them.\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimBankRails } from '@vorim/sdk/integrations/bank-rails';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const bank = createVorimBankRails(vorim, { provider: 'increase', minTrustScore: 70 });\n//\n// const auth = await bank.authorizeTransfer({\n// agentId: 'agid_abc123',\n// rail: 'ach',\n// amount: 250000, // smallest unit (cents)\n// currency: 'usd',\n// counterparty: 'acct_...',\n// });\n// if (auth.authorized) {\n// // ... create the transfer via Increase/Column, then:\n// await bank.logTransferInitiated(auth.agentId, transferId, { rail: 'ach', amount: 250000 });\n// }\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\n\nexport type BankRail = 'ach' | 'wire' | 'rtp' | 'book';\nexport type BankProvider = 'increase' | 'column' | 'generic';\n\nexport interface BankRailsConfig {\n apiKey: string;\n baseUrl?: string;\n minTrustScore?: number;\n requiredScope?: string;\n /** Which bank provider this instance fronts (informational, recorded in audit). */\n provider?: BankProvider;\n}\n\nexport interface BankTransferRequest {\n /** The Vorim agent id initiating the transfer. */\n agentId: string;\n /** Payment rail. */\n rail?: BankRail;\n /** Amount in the smallest currency unit (cents). */\n amount?: number;\n /** Currency code. */\n currency?: string;\n /** The destination account / counterparty reference. */\n counterparty?: string;\n /** Per-call override of the trust threshold. */\n minTrustScore?: number;\n}\n\nexport interface BankTransferAuthorization {\n authorized: boolean;\n agentId: string;\n trustScore: number;\n status: string;\n reason?: string;\n scopeVerified: boolean;\n}\n\nexport class VorimBankRails {\n private sdk: VorimSDK;\n private minTrustScore: number;\n private requiredScope: string;\n private provider: BankProvider;\n private static _warnedNoAuth = false;\n\n constructor(sdk: VorimSDK, config?: Partial<BankRailsConfig>) {\n this.sdk = sdk;\n this.minTrustScore = config?.minTrustScore ?? 50;\n this.requiredScope = config?.requiredScope ?? 'agent:transact';\n this.provider = config?.provider ?? 'generic';\n }\n\n /**\n * Verify an agent is authorized to initiate a bank transfer. Given these move\n * real money, callers typically set a higher minTrustScore. Same gate: scope\n * → active status → trust.\n */\n async authorizeTransfer(req: BankTransferRequest): Promise<BankTransferAuthorization> {\n const threshold = req.minTrustScore ?? this.minTrustScore;\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, 'bank.transfer.authorize', '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, 'bank.transfer.authorize', '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, 'bank.transfer.authorize', '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, 'bank.transfer.authorize', '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, 'bank.transfer.authorize', 'success', req, { trust_score: score });\n return { authorized: true, agentId: req.agentId, trustScore: score, status, scopeVerified: true };\n }\n\n /** Log that a bank transfer was initiated (created, possibly pending approval). */\n async logTransferInitiated(agentId: string, transferId: string, req?: Partial<BankTransferRequest>): Promise<void> {\n await this.logEvent(agentId, 'bank.transfer.initiated', 'success', req, { transfer_id: transferId });\n }\n\n /** Log that a transfer was approved (e.g. Increase's require_approval → approve). */\n async logTransferApproved(agentId: string, transferId: string, approver?: string, req?: Partial<BankTransferRequest>): Promise<void> {\n await this.logEvent(agentId, 'bank.transfer.approved', 'success', req, { transfer_id: transferId, approver });\n }\n\n /** Log that a transfer settled on the rail. */\n async logTransferSettled(agentId: string, transferId: string, req?: Partial<BankTransferRequest>): Promise<void> {\n await this.logEvent(agentId, 'bank.transfer.settled', 'success', req, { transfer_id: transferId });\n }\n\n /** Log that a transfer was returned, declined, or failed. */\n async logTransferFailed(agentId: string, transferId: string, reason?: string, req?: Partial<BankTransferRequest>): Promise<void> {\n await this.logEvent(agentId, 'bank.transfer.failed', 'error', req, { transfer_id: transferId, fail_reason: reason });\n }\n\n /**\n * Express/Connect middleware that gates a transfer-initiation endpoint on\n * agent 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. For money movement, wiring `authenticate` is\n * strongly recommended.\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 && !VorimBankRails._warnedNoAuth) {\n VorimBankRails._warnedNoAuth = true;\n // eslint-disable-next-line no-console\n console.warn(\n '[vorim] VorimBankRails.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). This gates real ' +\n 'money movement — 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.authorizeTransfer({\n agentId,\n rail: (req.body?.rail as BankRail) || 'ach',\n amount: req.body?.amount || 0,\n currency: req.body?.currency || 'usd',\n counterparty: req.body?.counterparty || '',\n minTrustScore: threshold,\n });\n if (!auth.authorized) {\n res.status(403).json({ error: { code: 'UNAUTHORIZED_AGENT', message: auth.reason || 'Agent not authorized to move money', 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<BankTransferRequest>,\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?.counterparty || '',\n metadata: {\n provider: this.provider,\n rail: req?.rail || '',\n amount: req?.amount || 0,\n currency: req?.currency || '',\n counterparty: req?.counterparty || '',\n ...metadata,\n },\n });\n } catch { /* never block the payment flow */ }\n }\n}\n\n/**\n * Create a VorimBankRails instance.\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimBankRails } from '@vorim/sdk/integrations/bank-rails';\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const bank = createVorimBankRails(vorim, { provider: 'increase', minTrustScore: 80 });\n * const auth = await bank.authorizeTransfer({ agentId: 'agid_abc', rail: 'ach', amount: 250000, counterparty: 'acct_1' });\n * ```\n */\nexport function createVorimBankRails(sdk: VorimSDK, config?: Partial<BankRailsConfig>): VorimBankRails {\n return new VorimBankRails(sdk, config);\n}\n"],"mappings":";AA2EO,IAAM,iBAAN,MAAM,gBAAe;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACR,OAAe,gBAAgB;AAAA,EAE/B,YAAY,KAAe,QAAmC;AAC5D,SAAK,MAAM;AACX,SAAK,gBAAgB,QAAQ,iBAAiB;AAC9C,SAAK,gBAAgB,QAAQ,iBAAiB;AAC9C,SAAK,WAAW,QAAQ,YAAY;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,kBAAkB,KAA8D;AACpF,UAAM,YAAY,IAAI,iBAAiB,KAAK;AAE5C,QAAI;AACF,YAAM,OAAO,MAAM,KAAK,IAAI,MAAM,IAAI,SAAS,KAAK,aAAoB;AACxE,UAAI,CAAE,KAAa,SAAS;AAC1B,cAAM,KAAK,SAAS,IAAI,SAAS,2BAA2B,UAAU,KAAK,EAAE,QAAQ,WAAW,KAAK,aAAa,GAAG,CAAC;AACtH,eAAO,EAAE,YAAY,OAAO,SAAS,IAAI,SAAS,YAAY,GAAG,QAAQ,WAAW,QAAQ,uBAAuB,KAAK,aAAa,eAAe,eAAe,MAAM;AAAA,MAC3K;AAAA,IACF,SAAS,GAAQ;AACf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