@vorim/sdk 3.10.0 → 3.12.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/CHANGELOG.md +13 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/integrations/cloudflare.cjs +134 -0
- package/dist/integrations/cloudflare.cjs.map +1 -0
- package/dist/integrations/cloudflare.d.cts +93 -0
- package/dist/integrations/cloudflare.d.ts +93 -0
- package/dist/integrations/cloudflare.js +108 -0
- package/dist/integrations/cloudflare.js.map +1 -0
- package/dist/integrations/shopify.cjs +203 -0
- package/dist/integrations/shopify.cjs.map +1 -0
- package/dist/integrations/shopify.d.cts +175 -0
- package/dist/integrations/shopify.d.ts +175 -0
- package/dist/integrations/shopify.js +177 -0
- package/dist/integrations/shopify.js.map +1 -0
- package/dist/integrations/truanon.cjs +188 -0
- package/dist/integrations/truanon.cjs.map +1 -0
- package/dist/integrations/truanon.d.cts +115 -0
- package/dist/integrations/truanon.d.ts +115 -0
- package/dist/integrations/truanon.js +161 -0
- package/dist/integrations/truanon.js.map +1 -0
- package/dist/integrations/web-bot-auth.cjs +143 -0
- package/dist/integrations/web-bot-auth.cjs.map +1 -0
- package/dist/integrations/web-bot-auth.d.cts +51 -0
- package/dist/integrations/web-bot-auth.d.ts +51 -0
- package/dist/integrations/web-bot-auth.js +108 -0
- package/dist/integrations/web-bot-auth.js.map +1 -0
- package/package.json +41 -1
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// src/integrations/shopify.ts
|
|
2
|
+
var OPERATION_SCOPE = {
|
|
3
|
+
read: "agent:read",
|
|
4
|
+
orderCreate: "agent:write",
|
|
5
|
+
inventoryAdjustQuantities: "agent:write",
|
|
6
|
+
fulfillmentCreate: "agent:write",
|
|
7
|
+
returnProcess: "agent:write",
|
|
8
|
+
productCreate: "agent:write",
|
|
9
|
+
productUpdate: "agent:write",
|
|
10
|
+
refundCreate: "agent:transact"
|
|
11
|
+
};
|
|
12
|
+
var VorimShopify = class {
|
|
13
|
+
sdk;
|
|
14
|
+
agentId;
|
|
15
|
+
shopDomain;
|
|
16
|
+
humanId;
|
|
17
|
+
minTrustScore;
|
|
18
|
+
maxRefundAmount;
|
|
19
|
+
onError;
|
|
20
|
+
constructor(sdk, config) {
|
|
21
|
+
if (!config?.agentId) throw new Error("[vorim] Shopify integration requires an agentId.");
|
|
22
|
+
if (!config?.shopDomain) throw new Error("[vorim] Shopify integration requires a shopDomain.");
|
|
23
|
+
this.sdk = sdk;
|
|
24
|
+
this.agentId = config.agentId;
|
|
25
|
+
this.shopDomain = config.shopDomain;
|
|
26
|
+
this.humanId = config.humanId;
|
|
27
|
+
this.minTrustScore = config.minTrustScore ?? 0;
|
|
28
|
+
this.maxRefundAmount = config.maxRefundAmount;
|
|
29
|
+
this.onError = config.onError ?? "closed";
|
|
30
|
+
}
|
|
31
|
+
/** The Vorim scope a given operation requires. Unknown mutations fall back to
|
|
32
|
+
* agent:write (a mutation is at least a write). */
|
|
33
|
+
scopeFor(operation) {
|
|
34
|
+
return OPERATION_SCOPE[operation] ?? "agent:write";
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Check whether the acting agent may run this store operation, before it
|
|
38
|
+
* runs. Enforces (in order): trust floor, refund ceiling, permission scope.
|
|
39
|
+
* Returns { authorized, reason }.
|
|
40
|
+
*/
|
|
41
|
+
async authorize(action) {
|
|
42
|
+
const scope = this.scopeFor(action.operation);
|
|
43
|
+
if (action.operation === "refundCreate" && this.maxRefundAmount != null && typeof action.amount === "number" && action.amount > this.maxRefundAmount) {
|
|
44
|
+
return {
|
|
45
|
+
authorized: false,
|
|
46
|
+
reason: `refund ${action.amount} exceeds this agent's ceiling of ${this.maxRefundAmount}`
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
if (this.minTrustScore > 0) {
|
|
51
|
+
const trust = await this.sdk.verify(this.agentId);
|
|
52
|
+
if ((trust?.trust_score ?? 0) < this.minTrustScore) {
|
|
53
|
+
return { authorized: false, reason: `trust score below ${this.minTrustScore}` };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const perm = await this.sdk.check(this.agentId, scope);
|
|
57
|
+
return perm.allowed ? { authorized: true } : { authorized: false, reason: perm.reason ?? `missing scope ${scope}` };
|
|
58
|
+
} catch (e) {
|
|
59
|
+
return this.onError === "open" ? { authorized: true, reason: "vorim unreachable, failed open" } : { authorized: false, reason: `vorim unreachable: ${e?.message ?? "error"}` };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Emit a source-signed audit event for a store operation and return whether
|
|
64
|
+
* it was recorded. Called after the mutation runs (or after a denial). The
|
|
65
|
+
* event names the agent, the shop, and the human the agent acts for, so the
|
|
66
|
+
* record is attributable and independently verifiable offline.
|
|
67
|
+
*/
|
|
68
|
+
async record(action, result, reason) {
|
|
69
|
+
const scope = this.scopeFor(action.operation);
|
|
70
|
+
try {
|
|
71
|
+
await this.sdk.emit({
|
|
72
|
+
agent_id: this.agentId,
|
|
73
|
+
event_type: "api_request",
|
|
74
|
+
action: `shopify:${action.operation}${action.resourceId ? " " + action.resourceId : ""}`,
|
|
75
|
+
resource: action.resourceId || this.shopDomain,
|
|
76
|
+
permission: scope,
|
|
77
|
+
result,
|
|
78
|
+
input_hash: action.inputHash,
|
|
79
|
+
metadata: {
|
|
80
|
+
integration: "shopify-admin",
|
|
81
|
+
shop_domain: this.shopDomain,
|
|
82
|
+
acts_for_human: this.humanId,
|
|
83
|
+
operation: action.operation,
|
|
84
|
+
...action.amount != null ? { amount: action.amount } : {},
|
|
85
|
+
...action.currency ? { currency: action.currency } : {},
|
|
86
|
+
...reason ? { reason } : {}
|
|
87
|
+
}
|
|
88
|
+
}, { sign: true });
|
|
89
|
+
return true;
|
|
90
|
+
} catch {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The full flow for one store operation: authorize, run the Admin GraphQL
|
|
96
|
+
* mutation if allowed, sign a receipt either way. If not authorized, `run` is
|
|
97
|
+
* never called (the mutation does not happen). Rethrows an error from `run`
|
|
98
|
+
* after recording it, with the receipt attached as `vorimReceipt`, so your
|
|
99
|
+
* handler still sees Shopify failures.
|
|
100
|
+
*/
|
|
101
|
+
async guard(action, run) {
|
|
102
|
+
const auth = await this.authorize(action);
|
|
103
|
+
if (!auth.authorized) {
|
|
104
|
+
const recorded = await this.record(action, "denied", auth.reason);
|
|
105
|
+
return { receipt: this.receipt(action, false, "denied", auth.reason, recorded) };
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
const value = await run();
|
|
109
|
+
const recorded = await this.record(action, "success");
|
|
110
|
+
return { receipt: this.receipt(action, true, "success", void 0, recorded), value };
|
|
111
|
+
} catch (e) {
|
|
112
|
+
const recorded = await this.record(action, "error", e?.message);
|
|
113
|
+
throw Object.assign(e ?? new Error("shopify operation failed"), {
|
|
114
|
+
vorimReceipt: this.receipt(action, true, "error", e?.message, recorded)
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// --- Named helpers for the high-risk Admin mutations -----------------------
|
|
119
|
+
// Each wraps guard() with the right operation label so the scope and receipt
|
|
120
|
+
// are correct without the caller having to remember the mapping. You pass the
|
|
121
|
+
// GraphQL call as `run`; this layer never talks to Shopify itself.
|
|
122
|
+
/** Guard an `orderCreate`. Requires agent:write. */
|
|
123
|
+
orderCreate(meta, run) {
|
|
124
|
+
return this.guard({ operation: "orderCreate", resourceId: meta.orderId, inputHash: meta.inputHash }, run);
|
|
125
|
+
}
|
|
126
|
+
/** Guard a `refundCreate`. Requires agent:transact AND stays within
|
|
127
|
+
* `maxRefundAmount` if one was configured. `amount` is in minor units. */
|
|
128
|
+
refundCreate(meta, run) {
|
|
129
|
+
return this.guard(
|
|
130
|
+
{ operation: "refundCreate", resourceId: meta.orderId, amount: meta.amount, currency: meta.currency, inputHash: meta.inputHash },
|
|
131
|
+
run
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
/** Guard an `inventoryAdjustQuantities`. Requires agent:write. */
|
|
135
|
+
inventoryAdjustQuantities(meta, run) {
|
|
136
|
+
return this.guard({ operation: "inventoryAdjustQuantities", resourceId: meta.resourceId, inputHash: meta.inputHash }, run);
|
|
137
|
+
}
|
|
138
|
+
/** Guard a `fulfillmentCreate`. Requires agent:write. */
|
|
139
|
+
fulfillmentCreate(meta, run) {
|
|
140
|
+
return this.guard({ operation: "fulfillmentCreate", resourceId: meta.orderId, inputHash: meta.inputHash }, run);
|
|
141
|
+
}
|
|
142
|
+
/** Guard a `returnProcess`. Requires agent:write. */
|
|
143
|
+
returnProcess(meta, run) {
|
|
144
|
+
return this.guard({ operation: "returnProcess", resourceId: meta.resourceId, inputHash: meta.inputHash }, run);
|
|
145
|
+
}
|
|
146
|
+
/** Guard a `productCreate` or `productUpdate`. Requires agent:write. */
|
|
147
|
+
productWrite(meta, run) {
|
|
148
|
+
return this.guard(
|
|
149
|
+
{ operation: meta.operation ?? "productUpdate", resourceId: meta.productId, inputHash: meta.inputHash },
|
|
150
|
+
run
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
receipt(action, authorized, result, reason, recorded) {
|
|
154
|
+
return {
|
|
155
|
+
authorized,
|
|
156
|
+
agentId: this.agentId,
|
|
157
|
+
humanId: this.humanId,
|
|
158
|
+
shopDomain: this.shopDomain,
|
|
159
|
+
operation: action.operation,
|
|
160
|
+
resourceId: action.resourceId,
|
|
161
|
+
amount: action.amount,
|
|
162
|
+
currency: action.currency,
|
|
163
|
+
result,
|
|
164
|
+
scope: this.scopeFor(action.operation),
|
|
165
|
+
reason,
|
|
166
|
+
recorded
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
function createVorimShopify(sdk, config) {
|
|
171
|
+
return new VorimShopify(sdk, config);
|
|
172
|
+
}
|
|
173
|
+
export {
|
|
174
|
+
VorimShopify,
|
|
175
|
+
createVorimShopify
|
|
176
|
+
};
|
|
177
|
+
//# sourceMappingURL=shopify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/shopify.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — Shopify (merchant-side store operations) Integration\n//\n// This guards an AI agent that MANAGES a Shopify store through the Admin\n// GraphQL API — creating orders, issuing refunds, adjusting inventory,\n// fulfilling, processing returns, editing products. Before each mutation runs\n// it checks the acting agent holds the right permission (and, for refunds, that\n// the amount is within a delegated ceiling), then signs a tamper-evident audit\n// record of what the agent did.\n//\n// WHY MERCHANT-SIDE, NOT CHECKOUT\n// The buyer-side purchase moment is already covered by signed rails: ACP's\n// delegated payment token + allowance, Visa's Trusted Agent Protocol and Web\n// Bot Auth (per-agent Ed25519 identity over the HTTP request — Vorim already\n// integrates Web Bot Auth), and AP2's signed mandates. Those prove identity and\n// payment authorization AT THE MOMENT OF PURCHASE and then stop at the\n// transaction boundary. None of them produce a signed, attenuated record of an\n// agent's operations ON THE STORE. On the Admin API an agent authenticates with\n// a single OAuth token and coarse write_* scopes: every agent on that token\n// looks identical, there is no way to cap a sub-agent below write_orders, and\n// nothing proves agent X (not agent Y) issued a given refundCreate. That is the\n// gap this fills. It COMPOSES WITH Web Bot Auth / TAP on the buyer side rather\n// than competing with the payment rails.\n//\n// SCOPE MAPPING (uses Vorim's three real scopes)\n// read Admin data -> agent:read\n// mutate the store -> agent:write (orders, inventory, fulfil,\n// returns, products)\n// move money back to a buyer -> agent:transact (refundCreate) + amount cap\n//\n// This layer never holds a Shopify token and never calls Shopify itself. You\n// pass it the mutation to run; it authorizes, runs it, and signs the receipt.\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimShopify } from '@vorim/sdk/integrations/shopify';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const shop = createVorimShopify(vorim, {\n// agentId: 'agid_abc123',\n// shopDomain: 'acme.myshopify.com',\n// humanId: 'user_42', // the person the agent acts for\n// maxRefundAmount: 20000, // cap this agent's refunds at $200.00 (cents)\n// });\n//\n// // Wrap the Admin GraphQL call you were going to make anyway:\n// const { receipt, value } = await shop.refundCreate(\n// { orderId: 'gid://shopify/Order/123', amount: 4999, currency: 'USD' },\n// () => adminClient.request(REFUND_CREATE_MUTATION, { input }),\n// );\n// if (!receipt.authorized) console.warn(receipt.reason);\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\nimport type { PermissionScope } from '../types.js';\n\n/** The Admin GraphQL mutations this guard knows how to classify. Any other\n * label is accepted too; it just defaults to the 'write' risk tier. */\nexport type ShopifyOperation =\n | 'orderCreate'\n | 'refundCreate'\n | 'inventoryAdjustQuantities'\n | 'fulfillmentCreate'\n | 'returnProcess'\n | 'productCreate'\n | 'productUpdate'\n | 'read';\n\n/** Map each Admin mutation to the least Vorim scope that should be required to\n * run it. Reads need read; store mutations need write; moving money back to a\n * customer (refundCreate) needs transact, the same scope Vorim requires for\n * any value-moving action. */\nconst OPERATION_SCOPE: Record<string, PermissionScope> = {\n read: 'agent:read',\n orderCreate: 'agent:write',\n inventoryAdjustQuantities: 'agent:write',\n fulfillmentCreate: 'agent:write',\n returnProcess: 'agent:write',\n productCreate: 'agent:write',\n productUpdate: 'agent:write',\n refundCreate: 'agent:transact',\n};\n\nexport interface ShopifyGuardConfig {\n /** The acting agent's Vorim id (agid_...). */\n agentId: string;\n /** The store this agent operates on, e.g. 'acme.myshopify.com'. Recorded in\n * every receipt so an action is attributable to a specific shop. */\n shopDomain: string;\n /** The human/principal the agent acts for. Recorded in every receipt so a\n * store action is attributable to a person, not just a machine. */\n humanId?: string;\n /** Minimum trust score the acting agent must hold before any mutation runs.\n * Default 0 (off). */\n minTrustScore?: number;\n /** Attenuation: cap the total this agent may refund in a single refundCreate,\n * in the currency's minor unit (e.g. cents). Shopify's coarse write_orders\n * scope cannot express this; Vorim can. Omit for no ceiling. */\n maxRefundAmount?: number;\n /** Fail closed (deny on any Vorim error) or fail open. Default 'closed'. */\n onError?: 'closed' | 'open';\n}\n\nexport interface ShopifyAction {\n /** The Admin GraphQL mutation being run, e.g. 'refundCreate'. Drives the\n * scope requirement. Unknown labels default to the 'write' tier. */\n operation: ShopifyOperation | string;\n /** The Shopify resource the action targets, e.g. an order or product GID. */\n resourceId?: string;\n /** For refundCreate: the amount moving back to the customer, in the minor\n * unit (cents). Checked against maxRefundAmount. */\n amount?: number;\n /** Currency code for `amount`, e.g. 'USD'. Informational. */\n currency?: string;\n /** Optional hash of the mutation variables so the receipt covers the exact\n * input without the guard storing it. */\n inputHash?: string;\n}\n\n/** An offline-verifiable receipt for one Shopify store operation. */\nexport interface ShopifyReceipt {\n authorized: boolean;\n agentId: string;\n humanId?: string;\n shopDomain: string;\n operation: string;\n resourceId?: string;\n amount?: number;\n currency?: string;\n result: 'success' | 'denied' | 'error';\n scope: PermissionScope;\n /** Reason a check failed, when authorized is false. */\n reason?: string;\n /** True once the audit event was signed and ingested. */\n recorded: boolean;\n}\n\nexport class VorimShopify {\n private sdk: VorimSDK;\n private agentId: string;\n private shopDomain: string;\n private humanId?: string;\n private minTrustScore: number;\n private maxRefundAmount?: number;\n private onError: 'closed' | 'open';\n\n constructor(sdk: VorimSDK, config: ShopifyGuardConfig) {\n if (!config?.agentId) throw new Error('[vorim] Shopify integration requires an agentId.');\n if (!config?.shopDomain) throw new Error('[vorim] Shopify integration requires a shopDomain.');\n this.sdk = sdk;\n this.agentId = config.agentId;\n this.shopDomain = config.shopDomain;\n this.humanId = config.humanId;\n this.minTrustScore = config.minTrustScore ?? 0;\n this.maxRefundAmount = config.maxRefundAmount;\n this.onError = config.onError ?? 'closed';\n }\n\n /** The Vorim scope a given operation requires. Unknown mutations fall back to\n * agent:write (a mutation is at least a write). */\n private scopeFor(operation: string): PermissionScope {\n return OPERATION_SCOPE[operation] ?? 'agent:write';\n }\n\n /**\n * Check whether the acting agent may run this store operation, before it\n * runs. Enforces (in order): trust floor, refund ceiling, permission scope.\n * Returns { authorized, reason }.\n */\n async authorize(action: ShopifyAction): Promise<{ authorized: boolean; reason?: string }> {\n const scope = this.scopeFor(action.operation);\n\n // Attenuation: a refund above this agent's delegated ceiling is denied\n // before any Vorim round-trip. This is the differentiator over Shopify's\n // coarse write_orders scope, which cannot bound a refund amount.\n if (\n action.operation === 'refundCreate' &&\n this.maxRefundAmount != null &&\n typeof action.amount === 'number' &&\n action.amount > this.maxRefundAmount\n ) {\n return {\n authorized: false,\n reason: `refund ${action.amount} exceeds this agent's ceiling of ${this.maxRefundAmount}`,\n };\n }\n\n try {\n // Trust floor (optional): refuse low-trust agents up front.\n if (this.minTrustScore > 0) {\n const trust = await this.sdk.verify(this.agentId);\n if ((trust?.trust_score ?? 0) < this.minTrustScore) {\n return { authorized: false, reason: `trust score below ${this.minTrustScore}` };\n }\n }\n const perm = await this.sdk.check(this.agentId, scope);\n return perm.allowed\n ? { authorized: true }\n : { authorized: false, reason: perm.reason ?? `missing scope ${scope}` };\n } catch (e: any) {\n // Fail closed by default: a check we could not complete is a deny.\n return this.onError === 'open'\n ? { authorized: true, reason: 'vorim unreachable, failed open' }\n : { authorized: false, reason: `vorim unreachable: ${e?.message ?? 'error'}` };\n }\n }\n\n /**\n * Emit a source-signed audit event for a store operation and return whether\n * it was recorded. Called after the mutation runs (or after a denial). The\n * event names the agent, the shop, and the human the agent acts for, so the\n * record is attributable and independently verifiable offline.\n */\n async record(action: ShopifyAction, result: 'success' | 'denied' | 'error', reason?: string): Promise<boolean> {\n const scope = this.scopeFor(action.operation);\n try {\n await this.sdk.emit({\n agent_id: this.agentId,\n event_type: 'api_request',\n action: `shopify:${action.operation}${action.resourceId ? ' ' + action.resourceId : ''}`,\n resource: action.resourceId || this.shopDomain,\n permission: scope,\n result,\n input_hash: action.inputHash,\n metadata: {\n integration: 'shopify-admin',\n shop_domain: this.shopDomain,\n acts_for_human: this.humanId,\n operation: action.operation,\n ...(action.amount != null ? { amount: action.amount } : {}),\n ...(action.currency ? { currency: action.currency } : {}),\n ...(reason ? { reason } : {}),\n },\n }, { sign: true }); // source-signed: the agent's key signs the record\n return true;\n } catch {\n return false;\n }\n }\n\n /**\n * The full flow for one store operation: authorize, run the Admin GraphQL\n * mutation if allowed, sign a receipt either way. If not authorized, `run` is\n * never called (the mutation does not happen). Rethrows an error from `run`\n * after recording it, with the receipt attached as `vorimReceipt`, so your\n * handler still sees Shopify failures.\n */\n async guard<T>(action: ShopifyAction, run: () => Promise<T>): Promise<{ receipt: ShopifyReceipt; value?: T }> {\n const auth = await this.authorize(action);\n if (!auth.authorized) {\n const recorded = await this.record(action, 'denied', auth.reason);\n return { receipt: this.receipt(action, false, 'denied', auth.reason, recorded) };\n }\n try {\n const value = await run();\n const recorded = await this.record(action, 'success');\n return { receipt: this.receipt(action, true, 'success', undefined, recorded), value };\n } catch (e: any) {\n const recorded = await this.record(action, 'error', e?.message);\n throw Object.assign(e ?? new Error('shopify operation failed'), {\n vorimReceipt: this.receipt(action, true, 'error', e?.message, recorded),\n });\n }\n }\n\n // --- Named helpers for the high-risk Admin mutations -----------------------\n // Each wraps guard() with the right operation label so the scope and receipt\n // are correct without the caller having to remember the mapping. You pass the\n // GraphQL call as `run`; this layer never talks to Shopify itself.\n\n /** Guard an `orderCreate`. Requires agent:write. */\n orderCreate<T>(meta: { orderId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'orderCreate', resourceId: meta.orderId, inputHash: meta.inputHash }, run);\n }\n\n /** Guard a `refundCreate`. Requires agent:transact AND stays within\n * `maxRefundAmount` if one was configured. `amount` is in minor units. */\n refundCreate<T>(meta: { orderId?: string; amount?: number; currency?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard(\n { operation: 'refundCreate', resourceId: meta.orderId, amount: meta.amount, currency: meta.currency, inputHash: meta.inputHash },\n run,\n );\n }\n\n /** Guard an `inventoryAdjustQuantities`. Requires agent:write. */\n inventoryAdjustQuantities<T>(meta: { resourceId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'inventoryAdjustQuantities', resourceId: meta.resourceId, inputHash: meta.inputHash }, run);\n }\n\n /** Guard a `fulfillmentCreate`. Requires agent:write. */\n fulfillmentCreate<T>(meta: { orderId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'fulfillmentCreate', resourceId: meta.orderId, inputHash: meta.inputHash }, run);\n }\n\n /** Guard a `returnProcess`. Requires agent:write. */\n returnProcess<T>(meta: { resourceId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'returnProcess', resourceId: meta.resourceId, inputHash: meta.inputHash }, run);\n }\n\n /** Guard a `productCreate` or `productUpdate`. Requires agent:write. */\n productWrite<T>(meta: { operation?: 'productCreate' | 'productUpdate'; productId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard(\n { operation: meta.operation ?? 'productUpdate', resourceId: meta.productId, inputHash: meta.inputHash },\n run,\n );\n }\n\n private receipt(\n action: ShopifyAction,\n authorized: boolean,\n result: 'success' | 'denied' | 'error',\n reason: string | undefined,\n recorded: boolean,\n ): ShopifyReceipt {\n return {\n authorized,\n agentId: this.agentId,\n humanId: this.humanId,\n shopDomain: this.shopDomain,\n operation: action.operation,\n resourceId: action.resourceId,\n amount: action.amount,\n currency: action.currency,\n result,\n scope: this.scopeFor(action.operation),\n reason,\n recorded,\n };\n }\n}\n\n/**\n * Create a VorimShopify guard around a Vorim SDK instance.\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimShopify } from '@vorim/sdk/integrations/shopify';\n *\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const shop = createVorimShopify(vorim, {\n * agentId: 'agid_abc123',\n * shopDomain: 'acme.myshopify.com',\n * humanId: 'user_42',\n * maxRefundAmount: 20000, // this agent can refund up to $200.00\n * });\n *\n * const { receipt, value } = await shop.refundCreate(\n * { orderId: 'gid://shopify/Order/123', amount: 4999, currency: 'USD' },\n * () => adminClient.request(REFUND_CREATE, { input }),\n * );\n * ```\n */\nexport function createVorimShopify(sdk: VorimSDK, config: ShopifyGuardConfig): VorimShopify {\n return new VorimShopify(sdk, config);\n}\n"],"mappings":";AAwEA,IAAM,kBAAmD;AAAA,EACvD,MAAM;AAAA,EACN,aAAa;AAAA,EACb,2BAA2B;AAAA,EAC3B,mBAAmB;AAAA,EACnB,eAAe;AAAA,EACf,eAAe;AAAA,EACf,eAAe;AAAA,EACf,cAAc;AAChB;AAwDO,IAAM,eAAN,MAAmB;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,KAAe,QAA4B;AACrD,QAAI,CAAC,QAAQ,QAAS,OAAM,IAAI,MAAM,kDAAkD;AACxF,QAAI,CAAC,QAAQ,WAAY,OAAM,IAAI,MAAM,oDAAoD;AAC7F,SAAK,MAAM;AACX,SAAK,UAAU,OAAO;AACtB,SAAK,aAAa,OAAO;AACzB,SAAK,UAAU,OAAO;AACtB,SAAK,gBAAgB,OAAO,iBAAiB;AAC7C,SAAK,kBAAkB,OAAO;AAC9B,SAAK,UAAU,OAAO,WAAW;AAAA,EACnC;AAAA;AAAA;AAAA,EAIQ,SAAS,WAAoC;AACnD,WAAO,gBAAgB,SAAS,KAAK;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,UAAU,QAA0E;AACxF,UAAM,QAAQ,KAAK,SAAS,OAAO,SAAS;AAK5C,QACE,OAAO,cAAc,kBACrB,KAAK,mBAAmB,QACxB,OAAO,OAAO,WAAW,YACzB,OAAO,SAAS,KAAK,iBACrB;AACA,aAAO;AAAA,QACL,YAAY;AAAA,QACZ,QAAQ,UAAU,OAAO,MAAM,oCAAoC,KAAK,eAAe;AAAA,MACzF;AAAA,IACF;AAEA,QAAI;AAEF,UAAI,KAAK,gBAAgB,GAAG;AAC1B,cAAM,QAAQ,MAAM,KAAK,IAAI,OAAO,KAAK,OAAO;AAChD,aAAK,OAAO,eAAe,KAA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AG,GAAG;AAAA,EAC3H;AAAA;AAAA,EAGA,kBAAqB,MAAgD,KAAuB;AAC1F,WAAO,KAAK,MAAM,EAAE,WAAW,qBAAqB,YAAY,KAAK,SAAS,WAAW,KAAK,UAAU,GAAG,GAAG;AAAA,EAChH;AAAA;AAAA,EAGA,cAAiB,MAAmD,KAAuB;AACzF,WAAO,KAAK,MAAM,EAAE,WAAW,iBAAiB,YAAY,KAAK,YAAY,WAAW,KAAK,UAAU,GAAG,GAAG;AAAA,EAC/G;AAAA;AAAA,EAGA,aAAgB,MAAiG,KAAuB;AACtI,WAAO,KAAK;AAAA,MACV,EAAE,WAAW,KAAK,aAAa,iBAAiB,YAAY,KAAK,WAAW,WAAW,KAAK,UAAU;AAAA,MACtG;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,QACN,QACA,YACA,QACA,QACA,UACgB;AAChB,WAAO;AAAA,MACL;AAAA,MACA,SAAS,KAAK;AAAA,MACd,SAAS,KAAK;AAAA,MACd,YAAY,KAAK;AAAA,MACjB,WAAW,OAAO;AAAA,MAClB,YAAY,OAAO;AAAA,MACnB,QAAQ,OAAO;AAAA,MACf,UAAU,OAAO;AAAA,MACjB;AAAA,MACA,OAAO,KAAK,SAAS,OAAO,SAAS;AAAA,MACrC;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAwBO,SAAS,mBAAmB,KAAe,QAA0C;AAC1F,SAAO,IAAI,aAAa,KAAK,MAAM;AACrC;","names":[]}
|
|
@@ -0,0 +1,188 @@
|
|
|
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/truanon.ts
|
|
21
|
+
var truanon_exports = {};
|
|
22
|
+
__export(truanon_exports, {
|
|
23
|
+
VorimTruAnon: () => VorimTruAnon,
|
|
24
|
+
createVorimTruAnon: () => createVorimTruAnon,
|
|
25
|
+
meetsMinimumRank: () => meetsMinimumRank
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(truanon_exports);
|
|
28
|
+
var RANK_ORDER = ["Dangerous", "Cautioned", "Credible", "Reliable", "Genuine"];
|
|
29
|
+
function meetsMinimumRank(userRank, minimumRank) {
|
|
30
|
+
if (userRank === "Unknown") return false;
|
|
31
|
+
const u = RANK_ORDER.indexOf(userRank);
|
|
32
|
+
const m = RANK_ORDER.indexOf(minimumRank);
|
|
33
|
+
return u >= 0 && m >= 0 && u >= m;
|
|
34
|
+
}
|
|
35
|
+
var VorimTruAnon = class {
|
|
36
|
+
sdk;
|
|
37
|
+
privateKey;
|
|
38
|
+
service;
|
|
39
|
+
minRank;
|
|
40
|
+
minTrustScore;
|
|
41
|
+
requiredScope;
|
|
42
|
+
truanonBaseUrl;
|
|
43
|
+
timeoutMs;
|
|
44
|
+
doFetch;
|
|
45
|
+
constructor(sdk, config) {
|
|
46
|
+
if (!config?.privateKey) throw new Error("[vorim] TruAnon integration requires a privateKey (server-side only).");
|
|
47
|
+
if (!config?.service) throw new Error("[vorim] TruAnon integration requires a service name.");
|
|
48
|
+
this.sdk = sdk;
|
|
49
|
+
this.privateKey = config.privateKey;
|
|
50
|
+
this.service = config.service;
|
|
51
|
+
this.minRank = config.minRank ?? "Credible";
|
|
52
|
+
this.minTrustScore = config.minTrustScore ?? 50;
|
|
53
|
+
this.requiredScope = config.requiredScope ?? "agent:transact";
|
|
54
|
+
this.truanonBaseUrl = (config.truanonBaseUrl ?? "https://truanon.com/api/v2").replace(/\/$/, "");
|
|
55
|
+
this.timeoutMs = config.timeoutMs ?? 3e4;
|
|
56
|
+
this.doFetch = config.fetchImpl ?? fetch;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Fetch a human's TruAnon profile (the anchor). Server-side call with your
|
|
60
|
+
* private key. Returns the rank/score/anchors; `isAnchored` is false if the
|
|
61
|
+
* lookup fails or the human has no anchor.
|
|
62
|
+
*/
|
|
63
|
+
async verifyHuman(username) {
|
|
64
|
+
const url = `${this.truanonBaseUrl}/get_profile?id=${encodeURIComponent(username)}&service=${encodeURIComponent(this.service)}`;
|
|
65
|
+
const controller = new AbortController();
|
|
66
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
67
|
+
try {
|
|
68
|
+
const res = await this.doFetch(url, {
|
|
69
|
+
method: "GET",
|
|
70
|
+
headers: { Authorization: this.privateKey, Accept: "application/json" },
|
|
71
|
+
redirect: "error",
|
|
72
|
+
signal: controller.signal
|
|
73
|
+
});
|
|
74
|
+
if (!res.ok) return this.emptyProfile();
|
|
75
|
+
const data = await res.json();
|
|
76
|
+
const rank = typeof data?.rank === "string" ? data.rank : "Unknown";
|
|
77
|
+
return {
|
|
78
|
+
rank,
|
|
79
|
+
score: typeof data?.score === "string" ? data.score : String(data?.score ?? "0"),
|
|
80
|
+
name: data?.name,
|
|
81
|
+
title: data?.title,
|
|
82
|
+
photo: data?.photo,
|
|
83
|
+
ageBadge: data?.ageBadge,
|
|
84
|
+
anchors: Array.isArray(data?.anchors) ? data.anchors : [],
|
|
85
|
+
isAnchored: rank !== "Unknown" && !!rank
|
|
86
|
+
};
|
|
87
|
+
} catch {
|
|
88
|
+
return this.emptyProfile();
|
|
89
|
+
} finally {
|
|
90
|
+
clearTimeout(timer);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The binding gate: authorize an agent to act on a human's behalf only if
|
|
95
|
+
* BOTH sides check out — the human is anchored at/above minRank (TruAnon) AND
|
|
96
|
+
* the agent holds the scope, is active, and clears trust (Vorim). Signs an
|
|
97
|
+
* audit event capturing both identities regardless of outcome.
|
|
98
|
+
*/
|
|
99
|
+
async authorizeAgentForHuman(input) {
|
|
100
|
+
const minRank = input.minRank ?? this.minRank;
|
|
101
|
+
const threshold = input.minTrustScore ?? this.minTrustScore;
|
|
102
|
+
const profile = await this.verifyHuman(input.humanUsername);
|
|
103
|
+
const rankMet = meetsMinimumRank(profile.rank, minRank);
|
|
104
|
+
const base = {
|
|
105
|
+
agentId: input.agentId,
|
|
106
|
+
humanUsername: input.humanUsername,
|
|
107
|
+
humanRank: profile.rank,
|
|
108
|
+
humanScore: profile.score,
|
|
109
|
+
humanAnchored: profile.isAnchored,
|
|
110
|
+
humanRankMet: rankMet
|
|
111
|
+
};
|
|
112
|
+
if (!profile.isAnchored) {
|
|
113
|
+
await this.logEvent(input.agentId, "truanon.bind.authorize", "denied", base, { reason: "Human is not anchored" });
|
|
114
|
+
return { ...base, authorized: false, trustScore: 0, status: "unknown", scopeVerified: false, reason: `Human ${input.humanUsername} is not anchored on TruAnon` };
|
|
115
|
+
}
|
|
116
|
+
if (!rankMet) {
|
|
117
|
+
await this.logEvent(input.agentId, "truanon.bind.authorize", "denied", base, { reason: `Rank ${profile.rank} < ${minRank}` });
|
|
118
|
+
return { ...base, authorized: false, trustScore: 0, status: "unknown", scopeVerified: false, reason: `Human rank ${profile.rank} is below the required ${minRank}` };
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
const perm = await this.sdk.check(input.agentId, this.requiredScope);
|
|
122
|
+
if (!perm.allowed) {
|
|
123
|
+
await this.logEvent(input.agentId, "truanon.bind.authorize", "denied", base, { reason: `Missing ${this.requiredScope}` });
|
|
124
|
+
return { ...base, authorized: false, trustScore: 0, status: "unknown", scopeVerified: false, reason: `Agent does not have ${this.requiredScope} permission` };
|
|
125
|
+
}
|
|
126
|
+
} catch (e) {
|
|
127
|
+
await this.logEvent(input.agentId, "truanon.bind.authorize", "denied", base, { reason: `Permission check failed: ${e.message}` });
|
|
128
|
+
return { ...base, authorized: false, trustScore: 0, status: "unknown", scopeVerified: false, reason: `Permission check failed: ${e.message}` };
|
|
129
|
+
}
|
|
130
|
+
let score = 0;
|
|
131
|
+
let status = "unknown";
|
|
132
|
+
try {
|
|
133
|
+
const trust = await this.sdk.verify(input.agentId);
|
|
134
|
+
score = trust.trust_score ?? 0;
|
|
135
|
+
status = trust.status ?? "unknown";
|
|
136
|
+
} catch {
|
|
137
|
+
}
|
|
138
|
+
if (status !== "active") {
|
|
139
|
+
await this.logEvent(input.agentId, "truanon.bind.authorize", "denied", base, { reason: `Agent status: ${status}` });
|
|
140
|
+
return { ...base, authorized: false, trustScore: score, status, scopeVerified: true, reason: `Agent is ${status}, not active` };
|
|
141
|
+
}
|
|
142
|
+
if (score < threshold) {
|
|
143
|
+
await this.logEvent(input.agentId, "truanon.bind.authorize", "denied", base, { reason: `Score ${score} < ${threshold}` });
|
|
144
|
+
return { ...base, authorized: false, trustScore: score, status, scopeVerified: true, reason: `Agent trust score ${score} is below minimum ${threshold}` };
|
|
145
|
+
}
|
|
146
|
+
await this.logEvent(input.agentId, "truanon.bind.authorize", "success", base, { trust_score: score });
|
|
147
|
+
return { ...base, authorized: true, trustScore: score, status, scopeVerified: true };
|
|
148
|
+
}
|
|
149
|
+
/** Log that an anchored-human + agent action completed (the end-to-end record). */
|
|
150
|
+
async logBoundAction(agentId, humanUsername, action, metadata) {
|
|
151
|
+
await this.logEvent(agentId, "truanon.bound_action", "success", { agentId, humanUsername }, { bound_action: action, ...metadata });
|
|
152
|
+
}
|
|
153
|
+
emptyProfile() {
|
|
154
|
+
return { rank: "Unknown", score: "0", anchors: [], isAnchored: false };
|
|
155
|
+
}
|
|
156
|
+
async logEvent(agentId, action, result, base, metadata) {
|
|
157
|
+
try {
|
|
158
|
+
await this.sdk.emit({
|
|
159
|
+
agent_id: agentId,
|
|
160
|
+
event_type: "api_request",
|
|
161
|
+
action,
|
|
162
|
+
result,
|
|
163
|
+
resource: base?.humanUsername ?? "",
|
|
164
|
+
metadata: {
|
|
165
|
+
provider: "truanon",
|
|
166
|
+
service: this.service,
|
|
167
|
+
human_username: base?.humanUsername ?? "",
|
|
168
|
+
human_rank: base?.humanRank ?? "",
|
|
169
|
+
human_score: base?.humanScore ?? "",
|
|
170
|
+
human_anchored: base?.humanAnchored ?? false,
|
|
171
|
+
human_rank_met: base?.humanRankMet ?? false,
|
|
172
|
+
...metadata
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
} catch {
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
function createVorimTruAnon(sdk, config) {
|
|
180
|
+
return new VorimTruAnon(sdk, config);
|
|
181
|
+
}
|
|
182
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
183
|
+
0 && (module.exports = {
|
|
184
|
+
VorimTruAnon,
|
|
185
|
+
createVorimTruAnon,
|
|
186
|
+
meetsMinimumRank
|
|
187
|
+
});
|
|
188
|
+
//# sourceMappingURL=truanon.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/truanon.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — TruAnon Integration\n//\n// TruAnon (truanon.com) anchors a real HUMAN to an account: a member binds their\n// profile to connections other people already know them by, without the platform\n// storing any identity documents. TruAnon returns a rank (Genuine, Reliable,\n// Credible, Cautioned, Dangerous, Unknown) and a 0-5 score for the human.\n//\n// Vorim anchors the AI AGENT: cryptographic identity, scoped permissions, and a\n// signed audit trail of what the agent did. This integration BINDS the two: it\n// verifies a human is anchored (via TruAnon) AND the acting agent is authorized\n// (via Vorim), then signs an audit event capturing BOTH identities — so you can\n// prove one accountable line from a verified human, through the platform, to the\n// specific agent and action. Protection end to end.\n//\n// It calls TruAnon's public API server-side with your private key, and Vorim's\n// verify/emit. Keep the TruAnon private key on the server — never in the browser.\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimTruAnon } from '@vorim/sdk/integrations/truanon';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const truanon = createVorimTruAnon(vorim, {\n// privateKey: process.env.VORIM_TRUANON_KEY!, // server-side only\n// service: process.env.VORIM_TRUANON_SERVICE!, // your TruAnon service name\n// minRank: 'Credible', // ID-verification-equivalent\n// });\n//\n// // Before an agent acts on a human's behalf, bind + authorize:\n// const auth = await truanon.authorizeAgentForHuman({\n// agentId: 'agid_abc123',\n// humanUsername: 'jtayler',\n// });\n// if (auth.authorized) { /* proceed; the binding is signed to the audit trail */ }\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\n\n/** TruAnon rank tiers, weakest to strongest. `Unknown` never meets a minimum. */\nexport type TruAnonRank = 'Unknown' | 'Dangerous' | 'Cautioned' | 'Credible' | 'Reliable' | 'Genuine';\n\n// Verbatim from the TruAnon API: index-based ordering, Unknown is off-axis.\nconst RANK_ORDER: TruAnonRank[] = ['Dangerous', 'Cautioned', 'Credible', 'Reliable', 'Genuine'];\n\n/** Does `userRank` meet or exceed `minimumRank`? Unknown always fails. */\nexport function meetsMinimumRank(userRank: string, minimumRank: TruAnonRank): boolean {\n if (userRank === 'Unknown') return false;\n const u = RANK_ORDER.indexOf(userRank as TruAnonRank);\n const m = RANK_ORDER.indexOf(minimumRank);\n return u >= 0 && m >= 0 && u >= m;\n}\n\nexport interface TruAnonAnchor {\n name: string;\n display: string;\n icon: string;\n type: string;\n kind: string;\n}\n\n/** The get_profile response shape (the fields TruAnon returns for a human). */\nexport interface TruAnonProfile {\n rank: string;\n score: string; // \"0\" .. \"5.0\"\n name?: string;\n title?: string;\n photo?: string;\n ageBadge?: string;\n anchors?: TruAnonAnchor[];\n isAnchored: boolean; // derived: true when TruAnon returned a real rank\n}\n\nexport interface TruAnonConfig {\n /** Vorim API key (already on the sdk instance; not used directly here). */\n apiKey?: string;\n baseUrl?: string;\n /** TruAnon private API key — SERVER-SIDE ONLY. */\n privateKey: string;\n /** Your registered TruAnon service name. */\n service: string;\n /** Minimum human rank required to authorize an agent. Default 'Credible'. */\n minRank?: TruAnonRank;\n /** Minimum agent trust score. Default 50. */\n minTrustScore?: number;\n /** Required agent scope. Default 'agent:transact'. */\n requiredScope?: string;\n /** TruAnon API base. Default 'https://truanon.com/api/v2'. */\n truanonBaseUrl?: string;\n /** Per-request timeout in ms. Default 30000 (TruAnon's guidance). */\n timeoutMs?: number;\n /** Injectable fetch (for testing). Defaults to global fetch. */\n fetchImpl?: typeof fetch;\n}\n\nexport interface HumanBindingAuthorization {\n authorized: boolean;\n agentId: string;\n humanUsername: string;\n /** The human's TruAnon rank + whether it met the minimum. */\n humanRank: string;\n humanScore: string;\n humanAnchored: boolean;\n humanRankMet: boolean;\n /** The agent's Vorim standing. */\n trustScore: number;\n status: string;\n scopeVerified: boolean;\n reason?: string;\n}\n\nexport class VorimTruAnon {\n private sdk: VorimSDK;\n private privateKey: string;\n private service: string;\n private minRank: TruAnonRank;\n private minTrustScore: number;\n private requiredScope: string;\n private truanonBaseUrl: string;\n private timeoutMs: number;\n private doFetch: typeof fetch;\n\n constructor(sdk: VorimSDK, config: TruAnonConfig) {\n if (!config?.privateKey) throw new Error('[vorim] TruAnon integration requires a privateKey (server-side only).');\n if (!config?.service) throw new Error('[vorim] TruAnon integration requires a service name.');\n this.sdk = sdk;\n this.privateKey = config.privateKey;\n this.service = config.service;\n this.minRank = config.minRank ?? 'Credible';\n this.minTrustScore = config.minTrustScore ?? 50;\n this.requiredScope = config.requiredScope ?? 'agent:transact';\n this.truanonBaseUrl = (config.truanonBaseUrl ?? 'https://truanon.com/api/v2').replace(/\\/$/, '');\n this.timeoutMs = config.timeoutMs ?? 30_000;\n this.doFetch = config.fetchImpl ?? fetch;\n }\n\n /**\n * Fetch a human's TruAnon profile (the anchor). Server-side call with your\n * private key. Returns the rank/score/anchors; `isAnchored` is false if the\n * lookup fails or the human has no anchor.\n */\n async verifyHuman(username: string): Promise<TruAnonProfile> {\n const url = `${this.truanonBaseUrl}/get_profile?id=${encodeURIComponent(username)}&service=${encodeURIComponent(this.service)}`;\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeoutMs);\n try {\n // redirect: 'error' — never replay the Authorization header to a 3xx target.\n const res = await this.doFetch(url, {\n method: 'GET',\n headers: { Authorization: this.privateKey, Accept: 'application/json' },\n redirect: 'error',\n signal: controller.signal,\n });\n if (!res.ok) return this.emptyProfile();\n const data: any = await res.json();\n const rank = typeof data?.rank === 'string' ? data.rank : 'Unknown';\n return {\n rank,\n score: typeof data?.score === 'string' ? data.score : String(data?.score ?? '0'),\n name: data?.name,\n title: data?.title,\n photo: data?.photo,\n ageBadge: data?.ageBadge,\n anchors: Array.isArray(data?.anchors) ? data.anchors : [],\n isAnchored: rank !== 'Unknown' && !!rank,\n };\n } catch {\n return this.emptyProfile();\n } finally {\n clearTimeout(timer);\n }\n }\n\n /**\n * The binding gate: authorize an agent to act on a human's behalf only if\n * BOTH sides check out — the human is anchored at/above minRank (TruAnon) AND\n * the agent holds the scope, is active, and clears trust (Vorim). Signs an\n * audit event capturing both identities regardless of outcome.\n */\n async authorizeAgentForHuman(input: {\n agentId: string;\n humanUsername: string;\n minRank?: TruAnonRank;\n minTrustScore?: number;\n }): Promise<HumanBindingAuthorization> {\n const minRank = input.minRank ?? this.minRank;\n const threshold = input.minTrustScore ?? this.minTrustScore;\n\n // 1. The human side — TruAnon anchor.\n const profile = await this.verifyHuman(input.humanUsername);\n const rankMet = meetsMinimumRank(profile.rank, minRank);\n\n const base = {\n agentId: input.agentId,\n humanUsername: input.humanUsername,\n humanRank: profile.rank,\n humanScore: profile.score,\n humanAnchored: profile.isAnchored,\n humanRankMet: rankMet,\n };\n\n if (!profile.isAnchored) {\n await this.logEvent(input.agentId, 'truanon.bind.authorize', 'denied', base, { reason: 'Human is not anchored' });\n return { ...base, authorized: false, trustScore: 0, status: 'unknown', scopeVerified: false, reason: `Human ${input.humanUsername} is not anchored on TruAnon` };\n }\n if (!rankMet) {\n await this.logEvent(input.agentId, 'truanon.bind.authorize', 'denied', base, { reason: `Rank ${profile.rank} < ${minRank}` });\n return { ...base, authorized: false, trustScore: 0, status: 'unknown', scopeVerified: false, reason: `Human rank ${profile.rank} is below the required ${minRank}` };\n }\n\n // 2. The agent side — Vorim scope + status + trust.\n try {\n const perm = await this.sdk.check(input.agentId, this.requiredScope as any);\n if (!(perm as any).allowed) {\n await this.logEvent(input.agentId, 'truanon.bind.authorize', 'denied', base, { reason: `Missing ${this.requiredScope}` });\n return { ...base, authorized: false, trustScore: 0, status: 'unknown', scopeVerified: false, reason: `Agent does not have ${this.requiredScope} permission` };\n }\n } catch (e: any) {\n await this.logEvent(input.agentId, 'truanon.bind.authorize', 'denied', base, { reason: `Permission check failed: ${e.message}` });\n return { ...base, authorized: false, trustScore: 0, status: 'unknown', scopeVerified: false, reason: `Permission check failed: ${e.message}` };\n }\n\n let score = 0;\n let status = 'unknown';\n try {\n const trust = await this.sdk.verify(input.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(input.agentId, 'truanon.bind.authorize', 'denied', base, { reason: `Agent status: ${status}` });\n return { ...base, authorized: false, trustScore: score, status, scopeVerified: true, reason: `Agent is ${status}, not active` };\n }\n if (score < threshold) {\n await this.logEvent(input.agentId, 'truanon.bind.authorize', 'denied', base, { reason: `Score ${score} < ${threshold}` });\n return { ...base, authorized: false, trustScore: score, status, scopeVerified: true, reason: `Agent trust score ${score} is below minimum ${threshold}` };\n }\n\n // Both sides pass — sign the binding.\n await this.logEvent(input.agentId, 'truanon.bind.authorize', 'success', base, { trust_score: score });\n return { ...base, authorized: true, trustScore: score, status, scopeVerified: true };\n }\n\n /** Log that an anchored-human + agent action completed (the end-to-end record). */\n async logBoundAction(agentId: string, humanUsername: string, action: string, metadata?: Record<string, any>): Promise<void> {\n await this.logEvent(agentId, 'truanon.bound_action', 'success', { agentId, humanUsername }, { bound_action: action, ...metadata });\n }\n\n private emptyProfile(): TruAnonProfile {\n return { rank: 'Unknown', score: '0', anchors: [], isAnchored: false };\n }\n\n private async logEvent(\n agentId: string,\n action: string,\n result: 'success' | 'denied' | 'error',\n base?: Partial<HumanBindingAuthorization> & { agentId?: string; humanUsername?: string },\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: base?.humanUsername ?? '',\n metadata: {\n provider: 'truanon',\n service: this.service,\n human_username: base?.humanUsername ?? '',\n human_rank: base?.humanRank ?? '',\n human_score: base?.humanScore ?? '',\n human_anchored: base?.humanAnchored ?? false,\n human_rank_met: base?.humanRankMet ?? false,\n ...metadata,\n },\n });\n } catch { /* never block the flow on an audit hiccup */ }\n }\n}\n\n/**\n * Create a VorimTruAnon instance. Bind a TruAnon-anchored human to a\n * Vorim-identified agent, with a signed record of both.\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimTruAnon } from '@vorim/sdk/integrations/truanon';\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const truanon = createVorimTruAnon(vorim, {\n * privateKey: process.env.VORIM_TRUANON_KEY!,\n * service: process.env.VORIM_TRUANON_SERVICE!,\n * minRank: 'Credible',\n * });\n * const auth = await truanon.authorizeAgentForHuman({ agentId: 'agid_abc', humanUsername: 'jtayler' });\n * ```\n */\nexport function createVorimTruAnon(sdk: VorimSDK, config: TruAnonConfig): VorimTruAnon {\n return new VorimTruAnon(sdk, config);\n}\n"],"mappings":";;;;;;;;;;;;;;;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G;AAAA,QACL;AAAA,MACF,CAAC;AAAA,IACH,QAAQ;AAAA,IAAgD;AAAA,EAC1D;AACF;AAmBO,SAAS,mBAAmB,KAAe,QAAqC;AACrF,SAAO,IAAI,aAAa,KAAK,MAAM;AACrC;","names":[]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { VorimSDK } from '../index.cjs';
|
|
2
|
+
import '../types-zzK9YOoa.cjs';
|
|
3
|
+
|
|
4
|
+
/** TruAnon rank tiers, weakest to strongest. `Unknown` never meets a minimum. */
|
|
5
|
+
type TruAnonRank = 'Unknown' | 'Dangerous' | 'Cautioned' | 'Credible' | 'Reliable' | 'Genuine';
|
|
6
|
+
/** Does `userRank` meet or exceed `minimumRank`? Unknown always fails. */
|
|
7
|
+
declare function meetsMinimumRank(userRank: string, minimumRank: TruAnonRank): boolean;
|
|
8
|
+
interface TruAnonAnchor {
|
|
9
|
+
name: string;
|
|
10
|
+
display: string;
|
|
11
|
+
icon: string;
|
|
12
|
+
type: string;
|
|
13
|
+
kind: string;
|
|
14
|
+
}
|
|
15
|
+
/** The get_profile response shape (the fields TruAnon returns for a human). */
|
|
16
|
+
interface TruAnonProfile {
|
|
17
|
+
rank: string;
|
|
18
|
+
score: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
title?: string;
|
|
21
|
+
photo?: string;
|
|
22
|
+
ageBadge?: string;
|
|
23
|
+
anchors?: TruAnonAnchor[];
|
|
24
|
+
isAnchored: boolean;
|
|
25
|
+
}
|
|
26
|
+
interface TruAnonConfig {
|
|
27
|
+
/** Vorim API key (already on the sdk instance; not used directly here). */
|
|
28
|
+
apiKey?: string;
|
|
29
|
+
baseUrl?: string;
|
|
30
|
+
/** TruAnon private API key — SERVER-SIDE ONLY. */
|
|
31
|
+
privateKey: string;
|
|
32
|
+
/** Your registered TruAnon service name. */
|
|
33
|
+
service: string;
|
|
34
|
+
/** Minimum human rank required to authorize an agent. Default 'Credible'. */
|
|
35
|
+
minRank?: TruAnonRank;
|
|
36
|
+
/** Minimum agent trust score. Default 50. */
|
|
37
|
+
minTrustScore?: number;
|
|
38
|
+
/** Required agent scope. Default 'agent:transact'. */
|
|
39
|
+
requiredScope?: string;
|
|
40
|
+
/** TruAnon API base. Default 'https://truanon.com/api/v2'. */
|
|
41
|
+
truanonBaseUrl?: string;
|
|
42
|
+
/** Per-request timeout in ms. Default 30000 (TruAnon's guidance). */
|
|
43
|
+
timeoutMs?: number;
|
|
44
|
+
/** Injectable fetch (for testing). Defaults to global fetch. */
|
|
45
|
+
fetchImpl?: typeof fetch;
|
|
46
|
+
}
|
|
47
|
+
interface HumanBindingAuthorization {
|
|
48
|
+
authorized: boolean;
|
|
49
|
+
agentId: string;
|
|
50
|
+
humanUsername: string;
|
|
51
|
+
/** The human's TruAnon rank + whether it met the minimum. */
|
|
52
|
+
humanRank: string;
|
|
53
|
+
humanScore: string;
|
|
54
|
+
humanAnchored: boolean;
|
|
55
|
+
humanRankMet: boolean;
|
|
56
|
+
/** The agent's Vorim standing. */
|
|
57
|
+
trustScore: number;
|
|
58
|
+
status: string;
|
|
59
|
+
scopeVerified: boolean;
|
|
60
|
+
reason?: string;
|
|
61
|
+
}
|
|
62
|
+
declare class VorimTruAnon {
|
|
63
|
+
private sdk;
|
|
64
|
+
private privateKey;
|
|
65
|
+
private service;
|
|
66
|
+
private minRank;
|
|
67
|
+
private minTrustScore;
|
|
68
|
+
private requiredScope;
|
|
69
|
+
private truanonBaseUrl;
|
|
70
|
+
private timeoutMs;
|
|
71
|
+
private doFetch;
|
|
72
|
+
constructor(sdk: VorimSDK, config: TruAnonConfig);
|
|
73
|
+
/**
|
|
74
|
+
* Fetch a human's TruAnon profile (the anchor). Server-side call with your
|
|
75
|
+
* private key. Returns the rank/score/anchors; `isAnchored` is false if the
|
|
76
|
+
* lookup fails or the human has no anchor.
|
|
77
|
+
*/
|
|
78
|
+
verifyHuman(username: string): Promise<TruAnonProfile>;
|
|
79
|
+
/**
|
|
80
|
+
* The binding gate: authorize an agent to act on a human's behalf only if
|
|
81
|
+
* BOTH sides check out — the human is anchored at/above minRank (TruAnon) AND
|
|
82
|
+
* the agent holds the scope, is active, and clears trust (Vorim). Signs an
|
|
83
|
+
* audit event capturing both identities regardless of outcome.
|
|
84
|
+
*/
|
|
85
|
+
authorizeAgentForHuman(input: {
|
|
86
|
+
agentId: string;
|
|
87
|
+
humanUsername: string;
|
|
88
|
+
minRank?: TruAnonRank;
|
|
89
|
+
minTrustScore?: number;
|
|
90
|
+
}): Promise<HumanBindingAuthorization>;
|
|
91
|
+
/** Log that an anchored-human + agent action completed (the end-to-end record). */
|
|
92
|
+
logBoundAction(agentId: string, humanUsername: string, action: string, metadata?: Record<string, any>): Promise<void>;
|
|
93
|
+
private emptyProfile;
|
|
94
|
+
private logEvent;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Create a VorimTruAnon instance. Bind a TruAnon-anchored human to a
|
|
98
|
+
* Vorim-identified agent, with a signed record of both.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* import createVorim from '@vorim/sdk';
|
|
103
|
+
* import { createVorimTruAnon } from '@vorim/sdk/integrations/truanon';
|
|
104
|
+
* const vorim = createVorim({ apiKey: 'agid_sk_...' });
|
|
105
|
+
* const truanon = createVorimTruAnon(vorim, {
|
|
106
|
+
* privateKey: process.env.VORIM_TRUANON_KEY!,
|
|
107
|
+
* service: process.env.VORIM_TRUANON_SERVICE!,
|
|
108
|
+
* minRank: 'Credible',
|
|
109
|
+
* });
|
|
110
|
+
* const auth = await truanon.authorizeAgentForHuman({ agentId: 'agid_abc', humanUsername: 'jtayler' });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
declare function createVorimTruAnon(sdk: VorimSDK, config: TruAnonConfig): VorimTruAnon;
|
|
114
|
+
|
|
115
|
+
export { type HumanBindingAuthorization, type TruAnonAnchor, type TruAnonConfig, type TruAnonProfile, type TruAnonRank, VorimTruAnon, createVorimTruAnon, meetsMinimumRank };
|