@vorim/sdk 3.8.1 → 3.10.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.
- package/dist/index.cjs +208 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +133 -3
- package/dist/index.d.ts +133 -3
- package/dist/index.js +208 -1
- package/dist/index.js.map +1 -1
- package/dist/integrations/anthropic.d.cts +1 -1
- package/dist/integrations/anthropic.d.ts +1 -1
- package/dist/integrations/ap2.cjs +218 -0
- package/dist/integrations/ap2.cjs.map +1 -0
- package/dist/integrations/ap2.d.cts +95 -0
- package/dist/integrations/ap2.d.ts +95 -0
- package/dist/integrations/ap2.js +192 -0
- package/dist/integrations/ap2.js.map +1 -0
- package/dist/integrations/bank-rails.cjs +173 -0
- package/dist/integrations/bank-rails.cjs.map +1 -0
- package/dist/integrations/bank-rails.d.cts +87 -0
- package/dist/integrations/bank-rails.d.ts +87 -0
- package/dist/integrations/bank-rails.js +147 -0
- package/dist/integrations/bank-rails.js.map +1 -0
- package/dist/integrations/circle.cjs +159 -0
- package/dist/integrations/circle.cjs.map +1 -0
- package/dist/integrations/circle.d.cts +75 -0
- package/dist/integrations/circle.d.ts +75 -0
- package/dist/integrations/circle.js +133 -0
- package/dist/integrations/circle.js.map +1 -0
- package/dist/integrations/crewai.d.cts +1 -1
- package/dist/integrations/crewai.d.ts +1 -1
- package/dist/integrations/hermes.d.cts +1 -1
- package/dist/integrations/hermes.d.ts +1 -1
- package/dist/integrations/langchain.d.cts +1 -1
- package/dist/integrations/langchain.d.ts +1 -1
- package/dist/integrations/langgraph.d.cts +1 -1
- package/dist/integrations/langgraph.d.ts +1 -1
- package/dist/integrations/llamaindex.d.cts +1 -1
- package/dist/integrations/llamaindex.d.ts +1 -1
- package/dist/integrations/modern-treasury.cjs +178 -0
- package/dist/integrations/modern-treasury.cjs.map +1 -0
- package/dist/integrations/modern-treasury.d.cts +90 -0
- package/dist/integrations/modern-treasury.d.ts +90 -0
- package/dist/integrations/modern-treasury.js +152 -0
- package/dist/integrations/modern-treasury.js.map +1 -0
- package/dist/integrations/nekuda.cjs +165 -0
- package/dist/integrations/nekuda.cjs.map +1 -0
- package/dist/integrations/nekuda.d.cts +79 -0
- package/dist/integrations/nekuda.d.ts +79 -0
- package/dist/integrations/nekuda.js +139 -0
- package/dist/integrations/nekuda.js.map +1 -0
- package/dist/integrations/openai.d.cts +1 -1
- package/dist/integrations/openai.d.ts +1 -1
- package/dist/integrations/paypal-agent.cjs +215 -0
- package/dist/integrations/paypal-agent.cjs.map +1 -0
- package/dist/integrations/paypal-agent.d.cts +87 -0
- package/dist/integrations/paypal-agent.d.ts +87 -0
- package/dist/integrations/paypal-agent.js +189 -0
- package/dist/integrations/paypal-agent.js.map +1 -0
- package/dist/integrations/plaid.cjs +174 -0
- package/dist/integrations/plaid.cjs.map +1 -0
- package/dist/integrations/plaid.d.cts +86 -0
- package/dist/integrations/plaid.d.ts +86 -0
- package/dist/integrations/plaid.js +148 -0
- package/dist/integrations/plaid.js.map +1 -0
- package/dist/integrations/siem.d.cts +1 -1
- package/dist/integrations/siem.d.ts +1 -1
- package/dist/integrations/skyfire.cjs +166 -0
- package/dist/integrations/skyfire.cjs.map +1 -0
- package/dist/integrations/skyfire.d.cts +80 -0
- package/dist/integrations/skyfire.d.ts +80 -0
- package/dist/integrations/skyfire.js +140 -0
- package/dist/integrations/skyfire.js.map +1 -0
- package/dist/integrations/stripe-acp.d.cts +1 -1
- package/dist/integrations/stripe-acp.d.ts +1 -1
- package/dist/integrations/ucp.d.cts +1 -1
- package/dist/integrations/ucp.d.ts +1 -1
- package/dist/integrations/vercel-ai.d.cts +1 -1
- package/dist/integrations/vercel-ai.d.ts +1 -1
- package/dist/integrations/x402.cjs +211 -0
- package/dist/integrations/x402.cjs.map +1 -0
- package/dist/integrations/x402.d.cts +87 -0
- package/dist/integrations/x402.d.ts +87 -0
- package/dist/integrations/x402.js +185 -0
- package/dist/integrations/x402.js.map +1 -0
- package/dist/{types-Cb6V-boJ.d.cts → types-zzK9YOoa.d.cts} +86 -1
- package/dist/{types-Cb6V-boJ.d.ts → types-zzK9YOoa.d.ts} +86 -1
- package/package.json +91 -1
|
@@ -0,0 +1,165 @@
|
|
|
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/nekuda.ts
|
|
21
|
+
var nekuda_exports = {};
|
|
22
|
+
__export(nekuda_exports, {
|
|
23
|
+
VorimNekuda: () => VorimNekuda,
|
|
24
|
+
createVorimNekuda: () => createVorimNekuda
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(nekuda_exports);
|
|
27
|
+
var VorimNekuda = class _VorimNekuda {
|
|
28
|
+
sdk;
|
|
29
|
+
minTrustScore;
|
|
30
|
+
requiredScope;
|
|
31
|
+
static _warnedNoAuth = false;
|
|
32
|
+
constructor(sdk, config) {
|
|
33
|
+
this.sdk = sdk;
|
|
34
|
+
this.minTrustScore = config?.minTrustScore ?? 50;
|
|
35
|
+
this.requiredScope = config?.requiredScope ?? "agent:transact";
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Verify an agent is authorized to create a Nekuda mandate. The mandate is
|
|
39
|
+
* the purchase-intent authorization step (before any card reveal), so it is
|
|
40
|
+
* the right chokepoint. Same gate: scope → active status → trust.
|
|
41
|
+
*/
|
|
42
|
+
async authorizeMandate(req) {
|
|
43
|
+
const threshold = req.minTrustScore ?? this.minTrustScore;
|
|
44
|
+
try {
|
|
45
|
+
const perm = await this.sdk.check(req.agentId, this.requiredScope);
|
|
46
|
+
if (!perm.allowed) {
|
|
47
|
+
await this.logEvent(req.agentId, "nekuda.mandate.authorize", "denied", req, { reason: `Missing ${this.requiredScope}` });
|
|
48
|
+
return { authorized: false, agentId: req.agentId, trustScore: 0, status: "unknown", reason: `Agent does not have ${this.requiredScope} permission`, scopeVerified: false };
|
|
49
|
+
}
|
|
50
|
+
} catch (e) {
|
|
51
|
+
await this.logEvent(req.agentId, "nekuda.mandate.authorize", "denied", req, { reason: e.message });
|
|
52
|
+
return { authorized: false, agentId: req.agentId, trustScore: 0, status: "unknown", reason: `Permission check failed: ${e.message}`, scopeVerified: false };
|
|
53
|
+
}
|
|
54
|
+
let score = 0;
|
|
55
|
+
let status = "unknown";
|
|
56
|
+
try {
|
|
57
|
+
const trust = await this.sdk.verify(req.agentId);
|
|
58
|
+
score = trust.trust_score ?? 0;
|
|
59
|
+
status = trust.status ?? "unknown";
|
|
60
|
+
} catch {
|
|
61
|
+
}
|
|
62
|
+
if (status !== "active") {
|
|
63
|
+
await this.logEvent(req.agentId, "nekuda.mandate.authorize", "denied", req, { reason: `Status: ${status}` });
|
|
64
|
+
return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Agent is ${status}, not active`, scopeVerified: true };
|
|
65
|
+
}
|
|
66
|
+
if (score < threshold) {
|
|
67
|
+
await this.logEvent(req.agentId, "nekuda.mandate.authorize", "denied", req, { reason: `Score ${score} < ${threshold}` });
|
|
68
|
+
return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Trust score ${score} is below minimum ${threshold}`, scopeVerified: true };
|
|
69
|
+
}
|
|
70
|
+
await this.logEvent(req.agentId, "nekuda.mandate.authorize", "success", req, { trust_score: score });
|
|
71
|
+
return { authorized: true, agentId: req.agentId, trustScore: score, status, scopeVerified: true };
|
|
72
|
+
}
|
|
73
|
+
/** Log that a Nekuda mandate was created. */
|
|
74
|
+
async logMandateCreated(agentId, mandateId, req) {
|
|
75
|
+
await this.logEvent(agentId, "nekuda.mandate.created", "success", req, { mandate_id: mandateId });
|
|
76
|
+
}
|
|
77
|
+
/** Log that a card-reveal token was requested against a mandate (card injected at checkout). */
|
|
78
|
+
async logCardRevealed(agentId, mandateId, req) {
|
|
79
|
+
await this.logEvent(agentId, "nekuda.card.revealed", "success", req, { mandate_id: mandateId });
|
|
80
|
+
}
|
|
81
|
+
/** Log that a Nekuda purchase/charge failed. */
|
|
82
|
+
async logMandateFailed(agentId, mandateId, reason, req) {
|
|
83
|
+
await this.logEvent(agentId, "nekuda.mandate.failed", "error", req, { mandate_id: mandateId, fail_reason: reason });
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Express/Connect middleware that gates a mandate-creation endpoint on agent
|
|
87
|
+
* authorization.
|
|
88
|
+
*
|
|
89
|
+
* ⚠️ CONFUSED-DEPUTY WARNING. Evaluates the *named* agent only; pass
|
|
90
|
+
* `authenticate` to verify the caller-to-agent binding. When omitted, a
|
|
91
|
+
* one-time warning is logged.
|
|
92
|
+
*/
|
|
93
|
+
middleware(options) {
|
|
94
|
+
const header = options?.agentIdHeader ?? "x-vorim-agent-id";
|
|
95
|
+
const threshold = options?.minTrustScore ?? this.minTrustScore;
|
|
96
|
+
const authenticate = options?.authenticate;
|
|
97
|
+
if (!authenticate && !_VorimNekuda._warnedNoAuth) {
|
|
98
|
+
_VorimNekuda._warnedNoAuth = true;
|
|
99
|
+
console.warn(
|
|
100
|
+
"[vorim] VorimNekuda.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`."
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
return async (req, res, next) => {
|
|
104
|
+
const agentId = req.headers?.[header] || req.headers?.[header.toLowerCase()] || "";
|
|
105
|
+
if (!agentId) {
|
|
106
|
+
res.status(401).json({ error: { code: "MISSING_AGENT_ID", message: `Agent ID required in ${header} header` } });
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (authenticate) {
|
|
110
|
+
let bound = false;
|
|
111
|
+
try {
|
|
112
|
+
bound = await authenticate(agentId, req);
|
|
113
|
+
} catch {
|
|
114
|
+
bound = false;
|
|
115
|
+
}
|
|
116
|
+
if (!bound) {
|
|
117
|
+
res.status(401).json({ error: { code: "AGENT_BINDING_UNVERIFIED", message: "Caller is not authenticated as the named agent" } });
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const auth = await this.authorizeMandate({
|
|
122
|
+
agentId,
|
|
123
|
+
merchant: req.body?.merchant || "",
|
|
124
|
+
product: req.body?.product || "",
|
|
125
|
+
amount: req.body?.amount || 0,
|
|
126
|
+
currency: req.body?.currency || "usd",
|
|
127
|
+
minTrustScore: threshold
|
|
128
|
+
});
|
|
129
|
+
if (!auth.authorized) {
|
|
130
|
+
res.status(403).json({ error: { code: "UNAUTHORIZED_AGENT", message: auth.reason || "Agent not authorized to create a Nekuda mandate", trust_score: auth.trustScore, status: auth.status } });
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
req.vorimAuthorization = auth;
|
|
134
|
+
next();
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
async logEvent(agentId, action, result, req, metadata) {
|
|
138
|
+
try {
|
|
139
|
+
await this.sdk.emit({
|
|
140
|
+
agent_id: agentId,
|
|
141
|
+
event_type: "api_request",
|
|
142
|
+
action,
|
|
143
|
+
result,
|
|
144
|
+
resource: req?.merchant || "",
|
|
145
|
+
metadata: {
|
|
146
|
+
merchant: req?.merchant || "",
|
|
147
|
+
product: req?.product || "",
|
|
148
|
+
amount: req?.amount || 0,
|
|
149
|
+
currency: req?.currency || "",
|
|
150
|
+
...metadata
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
} catch {
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
function createVorimNekuda(sdk, config) {
|
|
158
|
+
return new VorimNekuda(sdk, config);
|
|
159
|
+
}
|
|
160
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
161
|
+
0 && (module.exports = {
|
|
162
|
+
VorimNekuda,
|
|
163
|
+
createVorimNekuda
|
|
164
|
+
});
|
|
165
|
+
//# sourceMappingURL=nekuda.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/nekuda.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — Nekuda Integration\n//\n// Nekuda gives an AI agent a secure wallet + payment SDK: a user delegates\n// payment credentials, and the agent creates a \"mandate\" (purchase intent:\n// product / price / currency / merchant) which is then used to request a\n// just-in-time card-reveal token at checkout.\n//\n// This integration adds Vorim's identity, permission, and audit layer IN FRONT\n// of a Nekuda mandate: before an agent creates a mandate or requests a card\n// reveal, it verifies the agent holds `transact`, is active, and clears a trust\n// threshold, then records the mandate + reveal + charge lifecycle on a signed,\n// tamper-evident audit trail. It does NOT create Nekuda mandates or handle card\n// data — Nekuda does the payment; Vorim authorizes and attests.\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimNekuda } from '@vorim/sdk/integrations/nekuda';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const nekuda = createVorimNekuda(vorim, { minTrustScore: 60 });\n//\n// const auth = await nekuda.authorizeMandate({\n// agentId: 'agid_abc123',\n// merchant: 'acme-store',\n// product: 'running-shoes',\n// amount: 8999,\n// currency: 'usd',\n// });\n// if (auth.authorized) {\n// // ... create the Nekuda mandate, then:\n// await nekuda.logMandateCreated(auth.agentId, mandateId, { merchant, amount });\n// }\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\n\nexport interface NekudaConfig {\n apiKey: string;\n baseUrl?: string;\n minTrustScore?: number;\n requiredScope?: string;\n}\n\nexport interface NekudaMandateRequest {\n /** The Vorim agent id creating the mandate. */\n agentId: string;\n /** The merchant the purchase is with. */\n merchant?: string;\n /** The product / item being purchased. */\n product?: string;\n /** Amount in the smallest currency unit. */\n amount?: number;\n /** Currency code. */\n currency?: string;\n /** Per-call override of the trust threshold. */\n minTrustScore?: number;\n}\n\nexport interface NekudaAuthorization {\n authorized: boolean;\n agentId: string;\n trustScore: number;\n status: string;\n reason?: string;\n scopeVerified: boolean;\n}\n\nexport class VorimNekuda {\n private sdk: VorimSDK;\n private minTrustScore: number;\n private requiredScope: string;\n private static _warnedNoAuth = false;\n\n constructor(sdk: VorimSDK, config?: Partial<NekudaConfig>) {\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 create a Nekuda mandate. The mandate is\n * the purchase-intent authorization step (before any card reveal), so it is\n * the right chokepoint. Same gate: scope → active status → trust.\n */\n async authorizeMandate(req: NekudaMandateRequest): Promise<NekudaAuthorization> {\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, 'nekuda.mandate.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, 'nekuda.mandate.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, 'nekuda.mandate.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, 'nekuda.mandate.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, 'nekuda.mandate.authorize', 'success', req, { trust_score: score });\n return { authorized: true, agentId: req.agentId, trustScore: score, status, scopeVerified: true };\n }\n\n /** Log that a Nekuda mandate was created. */\n async logMandateCreated(agentId: string, mandateId: string, req?: Partial<NekudaMandateRequest>): Promise<void> {\n await this.logEvent(agentId, 'nekuda.mandate.created', 'success', req, { mandate_id: mandateId });\n }\n\n /** Log that a card-reveal token was requested against a mandate (card injected at checkout). */\n async logCardRevealed(agentId: string, mandateId: string, req?: Partial<NekudaMandateRequest>): Promise<void> {\n await this.logEvent(agentId, 'nekuda.card.revealed', 'success', req, { mandate_id: mandateId });\n }\n\n /** Log that a Nekuda purchase/charge failed. */\n async logMandateFailed(agentId: string, mandateId: string, reason?: string, req?: Partial<NekudaMandateRequest>): Promise<void> {\n await this.logEvent(agentId, 'nekuda.mandate.failed', 'error', req, { mandate_id: mandateId, fail_reason: reason });\n }\n\n /**\n * Express/Connect middleware that gates a mandate-creation 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 && !VorimNekuda._warnedNoAuth) {\n VorimNekuda._warnedNoAuth = true;\n // eslint-disable-next-line no-console\n console.warn(\n '[vorim] VorimNekuda.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.authorizeMandate({\n agentId,\n merchant: req.body?.merchant || '',\n product: req.body?.product || '',\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 create a Nekuda mandate', 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<NekudaMandateRequest>,\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 merchant: req?.merchant || '',\n product: req?.product || '',\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 VorimNekuda instance.\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimNekuda } from '@vorim/sdk/integrations/nekuda';\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const nekuda = createVorimNekuda(vorim, { minTrustScore: 70 });\n * const auth = await nekuda.authorizeMandate({ agentId: 'agid_abc', merchant: 'shop', amount: 8999 });\n * ```\n */\nexport function createVorimNekuda(sdk: VorimSDK, config?: Partial<NekudaConfig>): VorimNekuda {\n return new VorimNekuda(sdk, config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoEO,IAAM,cAAN,MAAM,aAAY;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACR,OAAe,gBAAgB;AAAA,EAE/B,YAAY,KAAe,QAAgC;AACzD,SAAK,MAAM;AACX,SAAK,gBAAgB,QAAQ,iBAAiB;AAC9C,SAAK,gBAAgB,QAAQ,iBAAiB;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,iBAAiB,KAAyD;AAC9E,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,4BAA4B,UAAU,KAAK,EAAE,QAAQ,WAAW,KAAK,aAAa,GAAG,CAAC;AACvH,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,4BAA4B,UAAU,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC;AACjG,aAAO,EAAE,YAAY,OAAO,SAAS,IAAI,SAAS,YAAY,GAAG,QAAQ,WAAW,Q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AO,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,SAAS,KAAK,UAAU,mDAAmD,aAAa,KAAK,YAAY,QAAQ,KAAK,OAAO,EAAE,CAAC;AAC5L;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,YAAY;AAAA,QAC3B,UAAU;AAAA,UACR,UAAU,KAAK,YAAY;AAAA,UAC3B,SAAS,KAAK,WAAW;AAAA,UACzB,QAAQ,KAAK,UAAU;AAAA,UACvB,UAAU,KAAK,YAAY;AAAA,UAC3B,GAAG;AAAA,QACL;AAAA,MACF,CAAC;AAAA,IACH,QAAQ;AAAA,IAAqC;AAAA,EAC/C;AACF;AAcO,SAAS,kBAAkB,KAAe,QAA6C;AAC5F,SAAO,IAAI,YAAY,KAAK,MAAM;AACpC;","names":[]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { VorimSDK } from '../index.cjs';
|
|
2
|
+
import '../types-zzK9YOoa.cjs';
|
|
3
|
+
|
|
4
|
+
interface NekudaConfig {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
minTrustScore?: number;
|
|
8
|
+
requiredScope?: string;
|
|
9
|
+
}
|
|
10
|
+
interface NekudaMandateRequest {
|
|
11
|
+
/** The Vorim agent id creating the mandate. */
|
|
12
|
+
agentId: string;
|
|
13
|
+
/** The merchant the purchase is with. */
|
|
14
|
+
merchant?: string;
|
|
15
|
+
/** The product / item being purchased. */
|
|
16
|
+
product?: string;
|
|
17
|
+
/** Amount in the smallest currency unit. */
|
|
18
|
+
amount?: number;
|
|
19
|
+
/** Currency code. */
|
|
20
|
+
currency?: string;
|
|
21
|
+
/** Per-call override of the trust threshold. */
|
|
22
|
+
minTrustScore?: number;
|
|
23
|
+
}
|
|
24
|
+
interface NekudaAuthorization {
|
|
25
|
+
authorized: boolean;
|
|
26
|
+
agentId: string;
|
|
27
|
+
trustScore: number;
|
|
28
|
+
status: string;
|
|
29
|
+
reason?: string;
|
|
30
|
+
scopeVerified: boolean;
|
|
31
|
+
}
|
|
32
|
+
declare class VorimNekuda {
|
|
33
|
+
private sdk;
|
|
34
|
+
private minTrustScore;
|
|
35
|
+
private requiredScope;
|
|
36
|
+
private static _warnedNoAuth;
|
|
37
|
+
constructor(sdk: VorimSDK, config?: Partial<NekudaConfig>);
|
|
38
|
+
/**
|
|
39
|
+
* Verify an agent is authorized to create a Nekuda mandate. The mandate is
|
|
40
|
+
* the purchase-intent authorization step (before any card reveal), so it is
|
|
41
|
+
* the right chokepoint. Same gate: scope → active status → trust.
|
|
42
|
+
*/
|
|
43
|
+
authorizeMandate(req: NekudaMandateRequest): Promise<NekudaAuthorization>;
|
|
44
|
+
/** Log that a Nekuda mandate was created. */
|
|
45
|
+
logMandateCreated(agentId: string, mandateId: string, req?: Partial<NekudaMandateRequest>): Promise<void>;
|
|
46
|
+
/** Log that a card-reveal token was requested against a mandate (card injected at checkout). */
|
|
47
|
+
logCardRevealed(agentId: string, mandateId: string, req?: Partial<NekudaMandateRequest>): Promise<void>;
|
|
48
|
+
/** Log that a Nekuda purchase/charge failed. */
|
|
49
|
+
logMandateFailed(agentId: string, mandateId: string, reason?: string, req?: Partial<NekudaMandateRequest>): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Express/Connect middleware that gates a mandate-creation endpoint on agent
|
|
52
|
+
* authorization.
|
|
53
|
+
*
|
|
54
|
+
* ⚠️ CONFUSED-DEPUTY WARNING. Evaluates the *named* agent only; pass
|
|
55
|
+
* `authenticate` to verify the caller-to-agent binding. When omitted, a
|
|
56
|
+
* one-time warning is logged.
|
|
57
|
+
*/
|
|
58
|
+
middleware(options?: {
|
|
59
|
+
agentIdHeader?: string;
|
|
60
|
+
minTrustScore?: number;
|
|
61
|
+
authenticate?: (agentId: string, req: any) => boolean | Promise<boolean>;
|
|
62
|
+
}): (req: any, res: any, next: any) => Promise<void>;
|
|
63
|
+
private logEvent;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create a VorimNekuda instance.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* import createVorim from '@vorim/sdk';
|
|
71
|
+
* import { createVorimNekuda } from '@vorim/sdk/integrations/nekuda';
|
|
72
|
+
* const vorim = createVorim({ apiKey: 'agid_sk_...' });
|
|
73
|
+
* const nekuda = createVorimNekuda(vorim, { minTrustScore: 70 });
|
|
74
|
+
* const auth = await nekuda.authorizeMandate({ agentId: 'agid_abc', merchant: 'shop', amount: 8999 });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare function createVorimNekuda(sdk: VorimSDK, config?: Partial<NekudaConfig>): VorimNekuda;
|
|
78
|
+
|
|
79
|
+
export { type NekudaAuthorization, type NekudaConfig, type NekudaMandateRequest, VorimNekuda, createVorimNekuda };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { VorimSDK } from '../index.js';
|
|
2
|
+
import '../types-zzK9YOoa.js';
|
|
3
|
+
|
|
4
|
+
interface NekudaConfig {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
minTrustScore?: number;
|
|
8
|
+
requiredScope?: string;
|
|
9
|
+
}
|
|
10
|
+
interface NekudaMandateRequest {
|
|
11
|
+
/** The Vorim agent id creating the mandate. */
|
|
12
|
+
agentId: string;
|
|
13
|
+
/** The merchant the purchase is with. */
|
|
14
|
+
merchant?: string;
|
|
15
|
+
/** The product / item being purchased. */
|
|
16
|
+
product?: string;
|
|
17
|
+
/** Amount in the smallest currency unit. */
|
|
18
|
+
amount?: number;
|
|
19
|
+
/** Currency code. */
|
|
20
|
+
currency?: string;
|
|
21
|
+
/** Per-call override of the trust threshold. */
|
|
22
|
+
minTrustScore?: number;
|
|
23
|
+
}
|
|
24
|
+
interface NekudaAuthorization {
|
|
25
|
+
authorized: boolean;
|
|
26
|
+
agentId: string;
|
|
27
|
+
trustScore: number;
|
|
28
|
+
status: string;
|
|
29
|
+
reason?: string;
|
|
30
|
+
scopeVerified: boolean;
|
|
31
|
+
}
|
|
32
|
+
declare class VorimNekuda {
|
|
33
|
+
private sdk;
|
|
34
|
+
private minTrustScore;
|
|
35
|
+
private requiredScope;
|
|
36
|
+
private static _warnedNoAuth;
|
|
37
|
+
constructor(sdk: VorimSDK, config?: Partial<NekudaConfig>);
|
|
38
|
+
/**
|
|
39
|
+
* Verify an agent is authorized to create a Nekuda mandate. The mandate is
|
|
40
|
+
* the purchase-intent authorization step (before any card reveal), so it is
|
|
41
|
+
* the right chokepoint. Same gate: scope → active status → trust.
|
|
42
|
+
*/
|
|
43
|
+
authorizeMandate(req: NekudaMandateRequest): Promise<NekudaAuthorization>;
|
|
44
|
+
/** Log that a Nekuda mandate was created. */
|
|
45
|
+
logMandateCreated(agentId: string, mandateId: string, req?: Partial<NekudaMandateRequest>): Promise<void>;
|
|
46
|
+
/** Log that a card-reveal token was requested against a mandate (card injected at checkout). */
|
|
47
|
+
logCardRevealed(agentId: string, mandateId: string, req?: Partial<NekudaMandateRequest>): Promise<void>;
|
|
48
|
+
/** Log that a Nekuda purchase/charge failed. */
|
|
49
|
+
logMandateFailed(agentId: string, mandateId: string, reason?: string, req?: Partial<NekudaMandateRequest>): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Express/Connect middleware that gates a mandate-creation endpoint on agent
|
|
52
|
+
* authorization.
|
|
53
|
+
*
|
|
54
|
+
* ⚠️ CONFUSED-DEPUTY WARNING. Evaluates the *named* agent only; pass
|
|
55
|
+
* `authenticate` to verify the caller-to-agent binding. When omitted, a
|
|
56
|
+
* one-time warning is logged.
|
|
57
|
+
*/
|
|
58
|
+
middleware(options?: {
|
|
59
|
+
agentIdHeader?: string;
|
|
60
|
+
minTrustScore?: number;
|
|
61
|
+
authenticate?: (agentId: string, req: any) => boolean | Promise<boolean>;
|
|
62
|
+
}): (req: any, res: any, next: any) => Promise<void>;
|
|
63
|
+
private logEvent;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create a VorimNekuda instance.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* import createVorim from '@vorim/sdk';
|
|
71
|
+
* import { createVorimNekuda } from '@vorim/sdk/integrations/nekuda';
|
|
72
|
+
* const vorim = createVorim({ apiKey: 'agid_sk_...' });
|
|
73
|
+
* const nekuda = createVorimNekuda(vorim, { minTrustScore: 70 });
|
|
74
|
+
* const auth = await nekuda.authorizeMandate({ agentId: 'agid_abc', merchant: 'shop', amount: 8999 });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare function createVorimNekuda(sdk: VorimSDK, config?: Partial<NekudaConfig>): VorimNekuda;
|
|
78
|
+
|
|
79
|
+
export { type NekudaAuthorization, type NekudaConfig, type NekudaMandateRequest, VorimNekuda, createVorimNekuda };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// src/integrations/nekuda.ts
|
|
2
|
+
var VorimNekuda = class _VorimNekuda {
|
|
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 create a Nekuda mandate. The mandate is
|
|
14
|
+
* the purchase-intent authorization step (before any card reveal), so it is
|
|
15
|
+
* the right chokepoint. Same gate: scope → active status → trust.
|
|
16
|
+
*/
|
|
17
|
+
async authorizeMandate(req) {
|
|
18
|
+
const threshold = req.minTrustScore ?? this.minTrustScore;
|
|
19
|
+
try {
|
|
20
|
+
const perm = await this.sdk.check(req.agentId, this.requiredScope);
|
|
21
|
+
if (!perm.allowed) {
|
|
22
|
+
await this.logEvent(req.agentId, "nekuda.mandate.authorize", "denied", req, { reason: `Missing ${this.requiredScope}` });
|
|
23
|
+
return { authorized: false, agentId: req.agentId, trustScore: 0, status: "unknown", reason: `Agent does not have ${this.requiredScope} permission`, scopeVerified: false };
|
|
24
|
+
}
|
|
25
|
+
} catch (e) {
|
|
26
|
+
await this.logEvent(req.agentId, "nekuda.mandate.authorize", "denied", req, { reason: e.message });
|
|
27
|
+
return { authorized: false, agentId: req.agentId, trustScore: 0, status: "unknown", reason: `Permission check failed: ${e.message}`, scopeVerified: false };
|
|
28
|
+
}
|
|
29
|
+
let score = 0;
|
|
30
|
+
let status = "unknown";
|
|
31
|
+
try {
|
|
32
|
+
const trust = await this.sdk.verify(req.agentId);
|
|
33
|
+
score = trust.trust_score ?? 0;
|
|
34
|
+
status = trust.status ?? "unknown";
|
|
35
|
+
} catch {
|
|
36
|
+
}
|
|
37
|
+
if (status !== "active") {
|
|
38
|
+
await this.logEvent(req.agentId, "nekuda.mandate.authorize", "denied", req, { reason: `Status: ${status}` });
|
|
39
|
+
return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Agent is ${status}, not active`, scopeVerified: true };
|
|
40
|
+
}
|
|
41
|
+
if (score < threshold) {
|
|
42
|
+
await this.logEvent(req.agentId, "nekuda.mandate.authorize", "denied", req, { reason: `Score ${score} < ${threshold}` });
|
|
43
|
+
return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Trust score ${score} is below minimum ${threshold}`, scopeVerified: true };
|
|
44
|
+
}
|
|
45
|
+
await this.logEvent(req.agentId, "nekuda.mandate.authorize", "success", req, { trust_score: score });
|
|
46
|
+
return { authorized: true, agentId: req.agentId, trustScore: score, status, scopeVerified: true };
|
|
47
|
+
}
|
|
48
|
+
/** Log that a Nekuda mandate was created. */
|
|
49
|
+
async logMandateCreated(agentId, mandateId, req) {
|
|
50
|
+
await this.logEvent(agentId, "nekuda.mandate.created", "success", req, { mandate_id: mandateId });
|
|
51
|
+
}
|
|
52
|
+
/** Log that a card-reveal token was requested against a mandate (card injected at checkout). */
|
|
53
|
+
async logCardRevealed(agentId, mandateId, req) {
|
|
54
|
+
await this.logEvent(agentId, "nekuda.card.revealed", "success", req, { mandate_id: mandateId });
|
|
55
|
+
}
|
|
56
|
+
/** Log that a Nekuda purchase/charge failed. */
|
|
57
|
+
async logMandateFailed(agentId, mandateId, reason, req) {
|
|
58
|
+
await this.logEvent(agentId, "nekuda.mandate.failed", "error", req, { mandate_id: mandateId, fail_reason: reason });
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Express/Connect middleware that gates a mandate-creation endpoint on agent
|
|
62
|
+
* authorization.
|
|
63
|
+
*
|
|
64
|
+
* ⚠️ CONFUSED-DEPUTY WARNING. Evaluates the *named* agent only; pass
|
|
65
|
+
* `authenticate` to verify the caller-to-agent binding. When omitted, a
|
|
66
|
+
* one-time warning is logged.
|
|
67
|
+
*/
|
|
68
|
+
middleware(options) {
|
|
69
|
+
const header = options?.agentIdHeader ?? "x-vorim-agent-id";
|
|
70
|
+
const threshold = options?.minTrustScore ?? this.minTrustScore;
|
|
71
|
+
const authenticate = options?.authenticate;
|
|
72
|
+
if (!authenticate && !_VorimNekuda._warnedNoAuth) {
|
|
73
|
+
_VorimNekuda._warnedNoAuth = true;
|
|
74
|
+
console.warn(
|
|
75
|
+
"[vorim] VorimNekuda.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`."
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
return async (req, res, next) => {
|
|
79
|
+
const agentId = req.headers?.[header] || req.headers?.[header.toLowerCase()] || "";
|
|
80
|
+
if (!agentId) {
|
|
81
|
+
res.status(401).json({ error: { code: "MISSING_AGENT_ID", message: `Agent ID required in ${header} header` } });
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (authenticate) {
|
|
85
|
+
let bound = false;
|
|
86
|
+
try {
|
|
87
|
+
bound = await authenticate(agentId, req);
|
|
88
|
+
} catch {
|
|
89
|
+
bound = false;
|
|
90
|
+
}
|
|
91
|
+
if (!bound) {
|
|
92
|
+
res.status(401).json({ error: { code: "AGENT_BINDING_UNVERIFIED", message: "Caller is not authenticated as the named agent" } });
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const auth = await this.authorizeMandate({
|
|
97
|
+
agentId,
|
|
98
|
+
merchant: req.body?.merchant || "",
|
|
99
|
+
product: req.body?.product || "",
|
|
100
|
+
amount: req.body?.amount || 0,
|
|
101
|
+
currency: req.body?.currency || "usd",
|
|
102
|
+
minTrustScore: threshold
|
|
103
|
+
});
|
|
104
|
+
if (!auth.authorized) {
|
|
105
|
+
res.status(403).json({ error: { code: "UNAUTHORIZED_AGENT", message: auth.reason || "Agent not authorized to create a Nekuda mandate", trust_score: auth.trustScore, status: auth.status } });
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
req.vorimAuthorization = auth;
|
|
109
|
+
next();
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
async logEvent(agentId, action, result, req, metadata) {
|
|
113
|
+
try {
|
|
114
|
+
await this.sdk.emit({
|
|
115
|
+
agent_id: agentId,
|
|
116
|
+
event_type: "api_request",
|
|
117
|
+
action,
|
|
118
|
+
result,
|
|
119
|
+
resource: req?.merchant || "",
|
|
120
|
+
metadata: {
|
|
121
|
+
merchant: req?.merchant || "",
|
|
122
|
+
product: req?.product || "",
|
|
123
|
+
amount: req?.amount || 0,
|
|
124
|
+
currency: req?.currency || "",
|
|
125
|
+
...metadata
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
} catch {
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
function createVorimNekuda(sdk, config) {
|
|
133
|
+
return new VorimNekuda(sdk, config);
|
|
134
|
+
}
|
|
135
|
+
export {
|
|
136
|
+
VorimNekuda,
|
|
137
|
+
createVorimNekuda
|
|
138
|
+
};
|
|
139
|
+
//# sourceMappingURL=nekuda.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/nekuda.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — Nekuda Integration\n//\n// Nekuda gives an AI agent a secure wallet + payment SDK: a user delegates\n// payment credentials, and the agent creates a \"mandate\" (purchase intent:\n// product / price / currency / merchant) which is then used to request a\n// just-in-time card-reveal token at checkout.\n//\n// This integration adds Vorim's identity, permission, and audit layer IN FRONT\n// of a Nekuda mandate: before an agent creates a mandate or requests a card\n// reveal, it verifies the agent holds `transact`, is active, and clears a trust\n// threshold, then records the mandate + reveal + charge lifecycle on a signed,\n// tamper-evident audit trail. It does NOT create Nekuda mandates or handle card\n// data — Nekuda does the payment; Vorim authorizes and attests.\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimNekuda } from '@vorim/sdk/integrations/nekuda';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const nekuda = createVorimNekuda(vorim, { minTrustScore: 60 });\n//\n// const auth = await nekuda.authorizeMandate({\n// agentId: 'agid_abc123',\n// merchant: 'acme-store',\n// product: 'running-shoes',\n// amount: 8999,\n// currency: 'usd',\n// });\n// if (auth.authorized) {\n// // ... create the Nekuda mandate, then:\n// await nekuda.logMandateCreated(auth.agentId, mandateId, { merchant, amount });\n// }\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\n\nexport interface NekudaConfig {\n apiKey: string;\n baseUrl?: string;\n minTrustScore?: number;\n requiredScope?: string;\n}\n\nexport interface NekudaMandateRequest {\n /** The Vorim agent id creating the mandate. */\n agentId: string;\n /** The merchant the purchase is with. */\n merchant?: string;\n /** The product / item being purchased. */\n product?: string;\n /** Amount in the smallest currency unit. */\n amount?: number;\n /** Currency code. */\n currency?: string;\n /** Per-call override of the trust threshold. */\n minTrustScore?: number;\n}\n\nexport interface NekudaAuthorization {\n authorized: boolean;\n agentId: string;\n trustScore: number;\n status: string;\n reason?: string;\n scopeVerified: boolean;\n}\n\nexport class VorimNekuda {\n private sdk: VorimSDK;\n private minTrustScore: number;\n private requiredScope: string;\n private static _warnedNoAuth = false;\n\n constructor(sdk: VorimSDK, config?: Partial<NekudaConfig>) {\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 create a Nekuda mandate. The mandate is\n * the purchase-intent authorization step (before any card reveal), so it is\n * the right chokepoint. Same gate: scope → active status → trust.\n */\n async authorizeMandate(req: NekudaMandateRequest): Promise<NekudaAuthorization> {\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, 'nekuda.mandate.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, 'nekuda.mandate.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, 'nekuda.mandate.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, 'nekuda.mandate.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, 'nekuda.mandate.authorize', 'success', req, { trust_score: score });\n return { authorized: true, agentId: req.agentId, trustScore: score, status, scopeVerified: true };\n }\n\n /** Log that a Nekuda mandate was created. */\n async logMandateCreated(agentId: string, mandateId: string, req?: Partial<NekudaMandateRequest>): Promise<void> {\n await this.logEvent(agentId, 'nekuda.mandate.created', 'success', req, { mandate_id: mandateId });\n }\n\n /** Log that a card-reveal token was requested against a mandate (card injected at checkout). */\n async logCardRevealed(agentId: string, mandateId: string, req?: Partial<NekudaMandateRequest>): Promise<void> {\n await this.logEvent(agentId, 'nekuda.card.revealed', 'success', req, { mandate_id: mandateId });\n }\n\n /** Log that a Nekuda purchase/charge failed. */\n async logMandateFailed(agentId: string, mandateId: string, reason?: string, req?: Partial<NekudaMandateRequest>): Promise<void> {\n await this.logEvent(agentId, 'nekuda.mandate.failed', 'error', req, { mandate_id: mandateId, fail_reason: reason });\n }\n\n /**\n * Express/Connect middleware that gates a mandate-creation 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 && !VorimNekuda._warnedNoAuth) {\n VorimNekuda._warnedNoAuth = true;\n // eslint-disable-next-line no-console\n console.warn(\n '[vorim] VorimNekuda.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.authorizeMandate({\n agentId,\n merchant: req.body?.merchant || '',\n product: req.body?.product || '',\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 create a Nekuda mandate', 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<NekudaMandateRequest>,\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 merchant: req?.merchant || '',\n product: req?.product || '',\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 VorimNekuda instance.\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimNekuda } from '@vorim/sdk/integrations/nekuda';\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const nekuda = createVorimNekuda(vorim, { minTrustScore: 70 });\n * const auth = await nekuda.authorizeMandate({ agentId: 'agid_abc', merchant: 'shop', amount: 8999 });\n * ```\n */\nexport function createVorimNekuda(sdk: VorimSDK, config?: Partial<NekudaConfig>): Vor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ACZ;AAAA,QACA;AAAA,QACA,UAAU,KAAK,YAAY;AAAA,QAC3B,UAAU;AAAA,UACR,UAAU,KAAK,YAAY;AAAA,UAC3B,SAAS,KAAK,WAAW;AAAA,UACzB,QAAQ,KAAK,UAAU;AAAA,UACvB,UAAU,KAAK,YAAY;AAAA,UAC3B,GAAG;AAAA,QACL;AAAA,MACF,CAAC;AAAA,IACH,QAAQ;AAAA,IAAqC;AAAA,EAC/C;AACF;AAcO,SAAS,kBAAkB,KAAe,QAA6C;AAC5F,SAAO,IAAI,YAAY,KAAK,MAAM;AACpC;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as PermissionScope, A as AgentRegistrationResult } from '../types-
|
|
1
|
+
import { P as PermissionScope, A as AgentRegistrationResult } from '../types-zzK9YOoa.cjs';
|
|
2
2
|
import { VorimSDK, ReplayInputs } from '../index.cjs';
|
|
3
3
|
import { E as EscalationPolicy, T as TransportFailurePolicy } from '../_runtime-gate-DOJUKJBu.cjs';
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as PermissionScope, A as AgentRegistrationResult } from '../types-
|
|
1
|
+
import { P as PermissionScope, A as AgentRegistrationResult } from '../types-zzK9YOoa.js';
|
|
2
2
|
import { VorimSDK, ReplayInputs } from '../index.js';
|
|
3
3
|
import { E as EscalationPolicy, T as TransportFailurePolicy } from '../_runtime-gate-DOJUKJBu.js';
|
|
4
4
|
|