@vorim/sdk 3.19.0 → 3.22.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 +49 -0
- package/README.md +73 -1
- package/dist/index.cjs +261 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +140 -3
- package/dist/index.d.ts +140 -3
- package/dist/index.js +253 -9
- package/dist/index.js.map +1 -1
- package/dist/integrations/anthropic.d.cts +2 -1
- package/dist/integrations/anthropic.d.ts +2 -1
- package/dist/integrations/ap2.d.cts +2 -1
- package/dist/integrations/ap2.d.ts +2 -1
- package/dist/integrations/aws-iam.d.cts +2 -1
- package/dist/integrations/aws-iam.d.ts +2 -1
- package/dist/integrations/bank-rails.d.cts +2 -1
- package/dist/integrations/bank-rails.d.ts +2 -1
- package/dist/integrations/circle.d.cts +2 -1
- package/dist/integrations/circle.d.ts +2 -1
- package/dist/integrations/cloudflare.d.cts +2 -1
- package/dist/integrations/cloudflare.d.ts +2 -1
- package/dist/integrations/coinbase-cdp.d.cts +2 -1
- package/dist/integrations/coinbase-cdp.d.ts +2 -1
- package/dist/integrations/commerce-agents.cjs +467 -0
- package/dist/integrations/commerce-agents.cjs.map +1 -0
- package/dist/integrations/commerce-agents.d.cts +200 -0
- package/dist/integrations/commerce-agents.d.ts +200 -0
- package/dist/integrations/commerce-agents.js +429 -0
- package/dist/integrations/commerce-agents.js.map +1 -0
- package/dist/integrations/crewai.d.cts +2 -1
- package/dist/integrations/crewai.d.ts +2 -1
- package/dist/integrations/entra.d.cts +2 -1
- package/dist/integrations/entra.d.ts +2 -1
- package/dist/integrations/fhir.d.cts +2 -1
- package/dist/integrations/fhir.d.ts +2 -1
- package/dist/integrations/grok.d.cts +2 -1
- package/dist/integrations/grok.d.ts +2 -1
- package/dist/integrations/guidewire.d.cts +2 -1
- package/dist/integrations/guidewire.d.ts +2 -1
- package/dist/integrations/hermes.d.cts +2 -1
- package/dist/integrations/hermes.d.ts +2 -1
- package/dist/integrations/jira.d.cts +2 -1
- package/dist/integrations/jira.d.ts +2 -1
- package/dist/integrations/langchain.d.cts +2 -1
- package/dist/integrations/langchain.d.ts +2 -1
- package/dist/integrations/langgraph.d.cts +2 -1
- package/dist/integrations/langgraph.d.ts +2 -1
- package/dist/integrations/legal.d.cts +2 -1
- package/dist/integrations/legal.d.ts +2 -1
- package/dist/integrations/life-sciences.d.cts +2 -1
- package/dist/integrations/life-sciences.d.ts +2 -1
- package/dist/integrations/linear.d.cts +2 -1
- package/dist/integrations/linear.d.ts +2 -1
- package/dist/integrations/lithic.d.cts +2 -1
- package/dist/integrations/lithic.d.ts +2 -1
- package/dist/integrations/llamaindex.d.cts +2 -1
- package/dist/integrations/llamaindex.d.ts +2 -1
- package/dist/integrations/marqeta.d.cts +2 -1
- package/dist/integrations/marqeta.d.ts +2 -1
- package/dist/integrations/modern-treasury.d.cts +2 -1
- package/dist/integrations/modern-treasury.d.ts +2 -1
- package/dist/integrations/muse.cjs +437 -0
- package/dist/integrations/muse.cjs.map +1 -0
- package/dist/integrations/muse.d.cts +72 -0
- package/dist/integrations/muse.d.ts +72 -0
- package/dist/integrations/muse.js +394 -0
- package/dist/integrations/muse.js.map +1 -0
- package/dist/integrations/nekuda.d.cts +2 -1
- package/dist/integrations/nekuda.d.ts +2 -1
- package/dist/integrations/okta.d.cts +2 -1
- package/dist/integrations/okta.d.ts +2 -1
- package/dist/integrations/openai.d.cts +2 -1
- package/dist/integrations/openai.d.ts +2 -1
- package/dist/integrations/openrouter.d.cts +2 -1
- package/dist/integrations/openrouter.d.ts +2 -1
- package/dist/integrations/paypal-agent.d.cts +2 -1
- package/dist/integrations/paypal-agent.d.ts +2 -1
- package/dist/integrations/perplexity.d.cts +2 -1
- package/dist/integrations/perplexity.d.ts +2 -1
- package/dist/integrations/plaid.d.cts +2 -1
- package/dist/integrations/plaid.d.ts +2 -1
- package/dist/integrations/ramp.d.cts +2 -1
- package/dist/integrations/ramp.d.ts +2 -1
- package/dist/integrations/shopify.d.cts +2 -1
- package/dist/integrations/shopify.d.ts +2 -1
- package/dist/integrations/siem.d.cts +1 -1
- package/dist/integrations/siem.d.ts +1 -1
- package/dist/integrations/skyfire.d.cts +2 -1
- package/dist/integrations/skyfire.d.ts +2 -1
- package/dist/integrations/stripe-acp.d.cts +2 -1
- package/dist/integrations/stripe-acp.d.ts +2 -1
- package/dist/integrations/stripe-issuing.d.cts +2 -1
- package/dist/integrations/stripe-issuing.d.ts +2 -1
- package/dist/integrations/truanon.d.cts +2 -1
- package/dist/integrations/truanon.d.ts +2 -1
- package/dist/integrations/typesafe.cjs +268 -0
- package/dist/integrations/typesafe.cjs.map +1 -0
- package/dist/integrations/typesafe.d.cts +145 -0
- package/dist/integrations/typesafe.d.ts +145 -0
- package/dist/integrations/typesafe.js +221 -0
- package/dist/integrations/typesafe.js.map +1 -0
- package/dist/integrations/ucp.d.cts +2 -1
- package/dist/integrations/ucp.d.ts +2 -1
- package/dist/integrations/vercel-ai.d.cts +2 -1
- package/dist/integrations/vercel-ai.d.ts +2 -1
- package/dist/integrations/x402.d.cts +2 -1
- package/dist/integrations/x402.d.ts +2 -1
- package/dist/{types-BmeluKHI.d.cts → types-BrDQAJdl.d.cts} +36 -1
- package/dist/{types-BmeluKHI.d.ts → types-BrDQAJdl.d.ts} +36 -1
- package/package.json +31 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
# Changelog — @vorim/sdk
|
|
2
2
|
|
|
3
|
+
## 3.20.0
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- **Anthropic commerce-agents integration**
|
|
8
|
+
(`import { createVorimCommerceGuard, guardStorefrontBackend, guardMerchantBackend }
|
|
9
|
+
from '@vorim/sdk/integrations/commerce-agents'`) — guards an agent built on
|
|
10
|
+
Anthropic's [commerce-agents](https://github.com/anthropics/commerce-agents)
|
|
11
|
+
blueprint. That blueprint plugs in through two contracts, `StorefrontBackend`
|
|
12
|
+
and `MerchantBackend`, and every tool the model calls lands in one of their
|
|
13
|
+
methods, so the guard wraps the backend rather than any of its three runtimes.
|
|
14
|
+
Catalogue, order, policy and analytics reads require `agent:read`; cart writes
|
|
15
|
+
and staged merchant changes `agent:write`; `checkout_handoff`, which produces a
|
|
16
|
+
payable cart, `agent:transact`; and `apply_change`, the irreversible live-store
|
|
17
|
+
write, `agent:elevate` plus a named human. `approveChange()` bridges a resolved
|
|
18
|
+
Vorim escalation into the blueprint's `approved_change_ids`, so the mark it
|
|
19
|
+
applies on is backed by a signed human decision rather than host code that
|
|
20
|
+
trusted the conversation. Nothing imports commerce-agents: the wrappers proxy
|
|
21
|
+
the backend structurally, a denial throws before the store is called, and
|
|
22
|
+
`onDenied` maps it onto the blueprint's own `NotOffered` / `Unavailable`
|
|
23
|
+
wording. Method names match in either spelling (`searchProducts` or
|
|
24
|
+
`search_products`). Parity with `vorim.integrations.commerce_agents` in the
|
|
25
|
+
Python SDK.
|
|
26
|
+
|
|
27
|
+
- **`eventDigest(event)`** — the stable content digest of an audit event,
|
|
28
|
+
`sha256:<hex>` over the same canonical bytes the signature covers, dispatched
|
|
29
|
+
on `canonical_form`. Not a new primitive: this is the value `prev_event_hash`
|
|
30
|
+
has always referenced, promoted to a named export so a downstream evidence
|
|
31
|
+
layer can bind to a reference without reimplementing the dispatch. Byte-identical
|
|
32
|
+
to `eventDigest` in `@vorim/verify`, `event_digest` in the Python SDK, and the
|
|
33
|
+
digest the server now returns from `POST /v1/audit/events`. Locked by
|
|
34
|
+
`scripts/check-replay-parity.sh`.
|
|
35
|
+
|
|
36
|
+
- **Payload commitments** (`commitPayload`, `hashPayload`, `isKeyedCommitment`,
|
|
37
|
+
`isDigest`). `input_hash` and `output_hash` always let you send a digest
|
|
38
|
+
instead of a prompt, but the format was a bare `sha256:`, and a bare SHA-256
|
|
39
|
+
of a prompt is a lookup key rather than a commitment — prompts are low-entropy
|
|
40
|
+
and templated, so a holder of the digest recovers the content by trying
|
|
41
|
+
candidates. `commitPayload(content, key)` produces `hmac-sha256:<hex>` under a
|
|
42
|
+
key you hold and never send us. `hashPayload` is unchanged and still correct
|
|
43
|
+
for content that is already high-entropy.
|
|
44
|
+
|
|
45
|
+
- **`noPayload` mode** (`createVorim({ noPayload: true })`). Throws before
|
|
46
|
+
anything is transmitted when an event would carry content: non-scalar metadata,
|
|
47
|
+
metadata strings over `maxMetadataChars` (256 by default), or a hash field that
|
|
48
|
+
is not a well-formed digest. Distinct from the server-side Zero Data Retention
|
|
49
|
+
setting, which drops `metadata` at persistence after it has already crossed the
|
|
50
|
+
network. `noPayload` means it never left your process. Off by default.
|
|
51
|
+
|
|
3
52
|
## 3.11.0
|
|
4
53
|
|
|
5
54
|
### Added
|
package/README.md
CHANGED
|
@@ -411,10 +411,82 @@ const vorim = createVorim({
|
|
|
411
411
|
|
|
412
412
|
| Option | Type | Default | Description |
|
|
413
413
|
|--------|------|---------|-------------|
|
|
414
|
-
| `apiKey` | `string` | — | Your Vorim API key (`agid_sk_live_...`
|
|
414
|
+
| `apiKey` | `string` | — | Your Vorim API key (`agid_sk_live_...`) |
|
|
415
415
|
| `baseUrl` | `string` | `https://api.vorim.ai` | API base URL (override for self-hosted) |
|
|
416
416
|
| `timeout` | `number` | `10000` | Request timeout in milliseconds |
|
|
417
417
|
| `autoSign` | `boolean` | `true` | Sign every audit event at source with the agent's Ed25519 key |
|
|
418
|
+
| `noPayload` | `boolean \| { maxMetadataChars?: number }` | `false` | Refuse to transmit agent content. Throws before sending on non-scalar metadata, over-long metadata strings, or a hash field that is not a well-formed digest |
|
|
419
|
+
|
|
420
|
+
---
|
|
421
|
+
|
|
422
|
+
## Payload Privacy
|
|
423
|
+
|
|
424
|
+
Your prompts and model outputs never have to reach Vorim. The audit event
|
|
425
|
+
carries a digest of them, computed in your process.
|
|
426
|
+
|
|
427
|
+
### Commit, don't just hash
|
|
428
|
+
|
|
429
|
+
A bare SHA-256 of a prompt is not a commitment, it is a lookup key. Prompts are
|
|
430
|
+
low-entropy and usually templated, so anyone holding the digest and the template
|
|
431
|
+
recovers the content by trying candidates until a hash matches. That includes us,
|
|
432
|
+
and anyone who obtains an export.
|
|
433
|
+
|
|
434
|
+
```typescript
|
|
435
|
+
import { commitPayload, hashPayload } from "@vorim/sdk";
|
|
436
|
+
|
|
437
|
+
const key = process.env.VORIM_COMMITMENT_KEY!; // never sent to Vorim
|
|
438
|
+
|
|
439
|
+
await vorim.emit({
|
|
440
|
+
agent_id: agent.agent_id,
|
|
441
|
+
event_type: "tool_call",
|
|
442
|
+
action: "invoice.refund",
|
|
443
|
+
result: "success",
|
|
444
|
+
input_hash: await commitPayload(prompt, key), // hmac-sha256:...
|
|
445
|
+
output_hash: await commitPayload(completion, key),
|
|
446
|
+
});
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
Keep `hashPayload` for content that is already high-entropy, such as a file
|
|
450
|
+
digest or a random identifier.
|
|
451
|
+
|
|
452
|
+
To disclose later, hand the verifier the content and the key; they recompute and
|
|
453
|
+
compare. Rotating the key does not invalidate past events, so retain the key you
|
|
454
|
+
used for as long as you might need to prove the events it covers.
|
|
455
|
+
|
|
456
|
+
### Refuse to send content at all
|
|
457
|
+
|
|
458
|
+
```typescript
|
|
459
|
+
const vorim = createVorim({ apiKey: process.env.VORIM_API_KEY!, noPayload: true });
|
|
460
|
+
|
|
461
|
+
await vorim.emit({ ...event, metadata: { tool: "stripe.refunds.create" } }); // ok
|
|
462
|
+
await vorim.emit({ ...event, metadata: { prompt: fullPrompt } }); // throws
|
|
463
|
+
// VorimError PAYLOAD_BLOCKED — nothing was sent
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
Not the same as the server-side Zero Data Retention setting, which drops metadata
|
|
467
|
+
when we persist it, by which point the content has crossed the network. This mode
|
|
468
|
+
means it never left your process.
|
|
469
|
+
|
|
470
|
+
`action` and `resource` are left alone: both are short structural identifiers
|
|
471
|
+
covered by the signature.
|
|
472
|
+
|
|
473
|
+
### Referencing an event
|
|
474
|
+
|
|
475
|
+
Every emit returns a stable content digest beside the event id, computed over
|
|
476
|
+
exactly the bytes the signature covers. You can recompute it yourself, and it is
|
|
477
|
+
the same value `prev_event_hash` references on the next event.
|
|
478
|
+
|
|
479
|
+
```typescript
|
|
480
|
+
const { events } = await vorim.emit({ /* ... */ });
|
|
481
|
+
// events: [{ event_id: "evt_...", digest: "sha256:..." }]
|
|
482
|
+
|
|
483
|
+
import { eventDigest } from "@vorim/sdk";
|
|
484
|
+
await eventDigest(sentEvent) === events[0].digest; // true
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
Byte-identical in `@vorim/verify` and the Python SDK. A content digest, not an
|
|
488
|
+
identity: two byte-identical events share one, which is why the event id sits
|
|
489
|
+
beside it.
|
|
418
490
|
|
|
419
491
|
---
|
|
420
492
|
|
package/dist/index.cjs
CHANGED
|
@@ -31,18 +31,26 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
CANONICAL_TOOL_CATALOGUE_VERSION: () => CANONICAL_TOOL_CATALOGUE_VERSION,
|
|
34
|
+
HMAC_SHA256_PREFIX: () => HMAC_SHA256_PREFIX,
|
|
35
|
+
SHA256_PREFIX: () => SHA256_PREFIX,
|
|
34
36
|
VorimDeniedError: () => VorimDeniedError,
|
|
35
37
|
VorimError: () => VorimError,
|
|
36
38
|
VorimSDK: () => VorimSDK,
|
|
37
39
|
canonicalPayloadV0: () => canonicalPayloadV0,
|
|
38
40
|
canonicalPayloadV1: () => canonicalPayloadV1,
|
|
41
|
+
commitPayload: () => commitPayload,
|
|
39
42
|
default: () => createVorim,
|
|
40
43
|
deviceLogin: () => deviceLogin,
|
|
44
|
+
eventDigest: () => eventDigest,
|
|
45
|
+
hashPayload: () => hashPayload,
|
|
41
46
|
hashPreviousEvent: () => hashPreviousEvent,
|
|
42
47
|
hashSystemPrompt: () => hashSystemPrompt,
|
|
43
48
|
hashTool: () => hashTool,
|
|
44
49
|
hashToolCatalogue: () => hashToolCatalogue,
|
|
50
|
+
isDigest: () => isDigest,
|
|
51
|
+
isKeyedCommitment: () => isKeyedCommitment,
|
|
45
52
|
jcsCanonicalise: () => jcsCanonicalise,
|
|
53
|
+
portableReceiptCanonicalBytes: () => portableReceiptCanonicalBytes,
|
|
46
54
|
prepareReplayContext: () => prepareReplayContext
|
|
47
55
|
});
|
|
48
56
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -123,8 +131,122 @@ async function prepareReplayContext(inputs) {
|
|
|
123
131
|
return ctx;
|
|
124
132
|
}
|
|
125
133
|
|
|
134
|
+
// ../shared-types/src/index.ts
|
|
135
|
+
function jcsCanonicalise2(value) {
|
|
136
|
+
if (value === null) return "null";
|
|
137
|
+
if (value === true) return "true";
|
|
138
|
+
if (value === false) return "false";
|
|
139
|
+
if (typeof value === "number") {
|
|
140
|
+
if (!Number.isFinite(value)) {
|
|
141
|
+
throw new Error("jcsCanonicalise: NaN and Infinity are not JCS-valid");
|
|
142
|
+
}
|
|
143
|
+
const abs = Math.abs(value);
|
|
144
|
+
if (value !== 0 && (abs >= 1e21 || abs < 1e-4 || Number.isInteger(value) && abs > 2 ** 53)) {
|
|
145
|
+
throw new Error(
|
|
146
|
+
`jcsCanonicalise: numbers in the ranges where JS and Python formatting diverge (|x| >= 1e21, |x| < 1e-4, or integer |x| > 2^53) are not supported in signed metadata. Use a string instead of ${value}.`
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
return value.toString();
|
|
150
|
+
}
|
|
151
|
+
if (typeof value === "string") {
|
|
152
|
+
return JSON.stringify(value);
|
|
153
|
+
}
|
|
154
|
+
if (Array.isArray(value)) {
|
|
155
|
+
return "[" + value.map(jcsCanonicalise2).join(",") + "]";
|
|
156
|
+
}
|
|
157
|
+
if (typeof value === "object") {
|
|
158
|
+
const obj = value;
|
|
159
|
+
const keys = Object.keys(obj).filter((k) => obj[k] !== void 0).sort();
|
|
160
|
+
const parts = keys.map((k) => JSON.stringify(k) + ":" + jcsCanonicalise2(obj[k]));
|
|
161
|
+
return "{" + parts.join(",") + "}";
|
|
162
|
+
}
|
|
163
|
+
throw new Error(`jcsCanonicalise: unsupported value type: ${typeof value}`);
|
|
164
|
+
}
|
|
165
|
+
function portableReceiptCanonicalBytes(receipt) {
|
|
166
|
+
return jcsCanonicalise2({
|
|
167
|
+
version: receipt.version,
|
|
168
|
+
org_id: receipt.org_id,
|
|
169
|
+
issued_at: receipt.issued_at,
|
|
170
|
+
canonical_form: receipt.canonical_form,
|
|
171
|
+
decision: {
|
|
172
|
+
decision_id: receipt.decision.decision_id,
|
|
173
|
+
verdict: receipt.decision.verdict,
|
|
174
|
+
agent_id: receipt.decision.agent_id,
|
|
175
|
+
required_scope: receipt.decision.required_scope,
|
|
176
|
+
action_type: receipt.decision.action_type,
|
|
177
|
+
action_target: receipt.decision.action_target,
|
|
178
|
+
policy_version: receipt.decision.policy_version,
|
|
179
|
+
decision_rule_id: receipt.decision.decision_rule_id,
|
|
180
|
+
requested_at: receipt.decision.requested_at,
|
|
181
|
+
expires_at: receipt.decision.expires_at
|
|
182
|
+
},
|
|
183
|
+
binding: {
|
|
184
|
+
original_intent_hash: receipt.binding.original_intent_hash,
|
|
185
|
+
effective_intent_hash: receipt.binding.effective_intent_hash,
|
|
186
|
+
policy_modified: receipt.binding.policy_modified
|
|
187
|
+
},
|
|
188
|
+
approval: receipt.approval === null ? null : {
|
|
189
|
+
resolution: receipt.approval.resolution,
|
|
190
|
+
resolved_at: receipt.approval.resolved_at,
|
|
191
|
+
approver_ref: receipt.approval.approver_ref,
|
|
192
|
+
alg: receipt.approval.alg,
|
|
193
|
+
kid: receipt.approval.kid,
|
|
194
|
+
signature: receipt.approval.signature
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// src/commit.ts
|
|
200
|
+
var HMAC_SHA256_PREFIX = "hmac-sha256:";
|
|
201
|
+
var SHA256_PREFIX = "sha256:";
|
|
202
|
+
function toBytes(v) {
|
|
203
|
+
return typeof v === "string" ? new TextEncoder().encode(v) : v;
|
|
204
|
+
}
|
|
205
|
+
function toHex(buf) {
|
|
206
|
+
return Array.from(buf instanceof Uint8Array ? buf : new Uint8Array(buf)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
207
|
+
}
|
|
208
|
+
async function hashPayload(content) {
|
|
209
|
+
const bytes = toBytes(content);
|
|
210
|
+
const subtle = globalThis.crypto?.subtle;
|
|
211
|
+
if (subtle) {
|
|
212
|
+
return SHA256_PREFIX + toHex(await subtle.digest("SHA-256", bytes));
|
|
213
|
+
}
|
|
214
|
+
const nodeCrypto = await import("crypto");
|
|
215
|
+
return SHA256_PREFIX + nodeCrypto.createHash("sha256").update(bytes).digest("hex");
|
|
216
|
+
}
|
|
217
|
+
async function commitPayload(content, key) {
|
|
218
|
+
const keyBytes = toBytes(key);
|
|
219
|
+
if (keyBytes.length === 0) {
|
|
220
|
+
throw new Error(
|
|
221
|
+
"commitPayload: key must not be empty. An empty key makes the commitment no stronger than hashPayload while labelling it as keyed."
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
const bytes = toBytes(content);
|
|
225
|
+
const subtle = globalThis.crypto?.subtle;
|
|
226
|
+
if (subtle) {
|
|
227
|
+
const cryptoKey = await subtle.importKey(
|
|
228
|
+
"raw",
|
|
229
|
+
keyBytes,
|
|
230
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
231
|
+
false,
|
|
232
|
+
["sign"]
|
|
233
|
+
);
|
|
234
|
+
const sig = await subtle.sign("HMAC", cryptoKey, bytes);
|
|
235
|
+
return HMAC_SHA256_PREFIX + toHex(sig);
|
|
236
|
+
}
|
|
237
|
+
const nodeCrypto = await import("crypto");
|
|
238
|
+
return HMAC_SHA256_PREFIX + nodeCrypto.createHmac("sha256", keyBytes).update(bytes).digest("hex");
|
|
239
|
+
}
|
|
240
|
+
function isKeyedCommitment(digest) {
|
|
241
|
+
return typeof digest === "string" && digest.startsWith(HMAC_SHA256_PREFIX);
|
|
242
|
+
}
|
|
243
|
+
var DIGEST_RE = /^(?:sha256|hmac-sha256):[0-9a-f]{64}$/;
|
|
244
|
+
function isDigest(digest) {
|
|
245
|
+
return typeof digest === "string" && DIGEST_RE.test(digest);
|
|
246
|
+
}
|
|
247
|
+
|
|
126
248
|
// src/index.ts
|
|
127
|
-
var SDK_VERSION = true ? "3.
|
|
249
|
+
var SDK_VERSION = true ? "3.22.0" : "0.0.0";
|
|
128
250
|
var USER_AGENT = `vorim-sdk/${SDK_VERSION}`;
|
|
129
251
|
function sleep(ms) {
|
|
130
252
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -143,6 +265,30 @@ function canonicalPayloadV1(event) {
|
|
|
143
265
|
const { signature: _sig, canonical_form: _cf, ...rest } = event;
|
|
144
266
|
return jcsCanonicalise(rest);
|
|
145
267
|
}
|
|
268
|
+
async function eventDigest(event) {
|
|
269
|
+
const form = event.canonical_form ?? "v0";
|
|
270
|
+
const bytes = form === "v1" ? canonicalPayloadV1(event) : canonicalPayloadV0(event);
|
|
271
|
+
return hashPreviousEvent(bytes);
|
|
272
|
+
}
|
|
273
|
+
function idempotencyHeader(key) {
|
|
274
|
+
return key ? { "Idempotency-Key": key } : void 0;
|
|
275
|
+
}
|
|
276
|
+
function toApprovalAttestation(raw) {
|
|
277
|
+
if (!raw || typeof raw !== "object") return null;
|
|
278
|
+
if (raw.resolution !== "approved") return null;
|
|
279
|
+
if (raw.alg !== "Ed25519") return null;
|
|
280
|
+
if (typeof raw.kid !== "string" || !raw.kid) return null;
|
|
281
|
+
if (typeof raw.signature !== "string" || !raw.signature.startsWith("ed25519:")) return null;
|
|
282
|
+
if (typeof raw.resolved_at !== "string" || Number.isNaN(Date.parse(raw.resolved_at))) return null;
|
|
283
|
+
return {
|
|
284
|
+
resolution: "approved",
|
|
285
|
+
resolvedAt: raw.resolved_at,
|
|
286
|
+
approverRef: typeof raw.approver_ref === "string" ? raw.approver_ref : null,
|
|
287
|
+
alg: "Ed25519",
|
|
288
|
+
kid: raw.kid,
|
|
289
|
+
signature: raw.signature
|
|
290
|
+
};
|
|
291
|
+
}
|
|
146
292
|
var VorimSDK = class _VorimSDK {
|
|
147
293
|
apiKey;
|
|
148
294
|
baseUrl;
|
|
@@ -151,6 +297,8 @@ var VorimSDK = class _VorimSDK {
|
|
|
151
297
|
canonicalForm;
|
|
152
298
|
chainEvents;
|
|
153
299
|
runtimeFailOpen;
|
|
300
|
+
noPayload;
|
|
301
|
+
maxMetadataChars;
|
|
154
302
|
/**
|
|
155
303
|
* In-memory keyring mapping agent_id -> PEM-encoded Ed25519 private key.
|
|
156
304
|
* Populated automatically by register() and registerEphemeral(), or
|
|
@@ -197,6 +345,8 @@ var VorimSDK = class _VorimSDK {
|
|
|
197
345
|
}
|
|
198
346
|
this.chainEvents = config.chainEvents ?? false;
|
|
199
347
|
this.runtimeFailOpen = config.runtimeFailOpen ?? true;
|
|
348
|
+
this.noPayload = config.noPayload !== void 0 && config.noPayload !== false;
|
|
349
|
+
this.maxMetadataChars = typeof config.noPayload === "object" && typeof config.noPayload.maxMetadataChars === "number" ? config.noPayload.maxMetadataChars : 256;
|
|
200
350
|
}
|
|
201
351
|
/**
|
|
202
352
|
* Register a previously-issued agent keypair so this SDK instance can
|
|
@@ -708,7 +858,8 @@ var VorimSDK = class _VorimSDK {
|
|
|
708
858
|
latencyMs: 0,
|
|
709
859
|
isFallback: true,
|
|
710
860
|
policyVersion: 0,
|
|
711
|
-
escalationResolution: null
|
|
861
|
+
escalationResolution: null,
|
|
862
|
+
approval: null
|
|
712
863
|
};
|
|
713
864
|
}
|
|
714
865
|
throw err;
|
|
@@ -781,6 +932,35 @@ var VorimSDK = class _VorimSDK {
|
|
|
781
932
|
{ decisionId }
|
|
782
933
|
);
|
|
783
934
|
}
|
|
935
|
+
/**
|
|
936
|
+
* Mint a portable signed receipt for a decision: a self-contained,
|
|
937
|
+
* offline-verifiable statement that Vorim authorised this action.
|
|
938
|
+
*
|
|
939
|
+
* Use it when something OUTSIDE Vorim has to be convinced — a settlement
|
|
940
|
+
* layer, a downstream anchor, a counterparty's auditor. Verification needs
|
|
941
|
+
* the receipt and the public key from `GET /trust/keys`: no call back to
|
|
942
|
+
* Vorim, no chain, no network.
|
|
943
|
+
*
|
|
944
|
+
* Reproduce the signed bytes with `portableReceiptCanonicalBytes` from
|
|
945
|
+
* `@vorim/shared-types` (also re-exported here), then check `signature`
|
|
946
|
+
* against the key matching `kid`. Never re-derive those bytes by hand: the
|
|
947
|
+
* canonical form is defined once precisely so two implementations cannot
|
|
948
|
+
* drift into signatures that do not verify.
|
|
949
|
+
*
|
|
950
|
+
* Throws 409 when the decision is not an authorisation — a denial, a
|
|
951
|
+
* fail-open fallback, an unresolved escalation, or one a human refused.
|
|
952
|
+
* A receipt only ever means yes, so there is nothing to return for a no.
|
|
953
|
+
*
|
|
954
|
+
* @example
|
|
955
|
+
* const d = await vorim.beforeAction({ ... });
|
|
956
|
+
* if (d.decision === 'allow') {
|
|
957
|
+
* const receipt = await vorim.mintPortableSignedReceipt(d.decisionId);
|
|
958
|
+
* await settleWith(receipt); // the counterparty verifies it alone
|
|
959
|
+
* }
|
|
960
|
+
*/
|
|
961
|
+
async mintPortableSignedReceipt(decisionId) {
|
|
962
|
+
return this.get(`/runtime/decisions/${decisionId}/receipt`);
|
|
963
|
+
}
|
|
784
964
|
/**
|
|
785
965
|
* Map a snake_case decision row (from POST or GET) to the camelCase
|
|
786
966
|
* {@link RuntimeDecision}. The SDK has no generic camelizer, so the
|
|
@@ -819,7 +999,8 @@ var VorimSDK = class _VorimSDK {
|
|
|
819
999
|
latencyMs: raw?.latency_ms ?? 0,
|
|
820
1000
|
isFallback: raw?.is_fallback ?? !hasVerdict,
|
|
821
1001
|
policyVersion: raw?.policy_version ?? 0,
|
|
822
|
-
escalationResolution: resolution
|
|
1002
|
+
escalationResolution: resolution,
|
|
1003
|
+
approval: toApprovalAttestation(raw?.approval)
|
|
823
1004
|
};
|
|
824
1005
|
}
|
|
825
1006
|
// ─── Audit ────────────────────────────────────────────────────────
|
|
@@ -836,7 +1017,11 @@ var VorimSDK = class _VorimSDK {
|
|
|
836
1017
|
*/
|
|
837
1018
|
async emit(event, options) {
|
|
838
1019
|
const prepared = await this.prepareEvent(event, options?.sign);
|
|
839
|
-
const result = await this.post(
|
|
1020
|
+
const result = await this.post(
|
|
1021
|
+
"/audit/events",
|
|
1022
|
+
{ events: [prepared] },
|
|
1023
|
+
idempotencyHeader(options?.idempotencyKey)
|
|
1024
|
+
);
|
|
840
1025
|
this.warnOnPartialIngest(1, result?.ingested ?? 0);
|
|
841
1026
|
return result;
|
|
842
1027
|
}
|
|
@@ -852,7 +1037,11 @@ var VorimSDK = class _VorimSDK {
|
|
|
852
1037
|
*/
|
|
853
1038
|
async emitBatch(events, options) {
|
|
854
1039
|
const prepared = await Promise.all(events.map((e) => this.prepareEvent(e, options?.sign)));
|
|
855
|
-
const result = await this.post(
|
|
1040
|
+
const result = await this.post(
|
|
1041
|
+
"/audit/events",
|
|
1042
|
+
{ events: prepared },
|
|
1043
|
+
idempotencyHeader(options?.idempotencyKey)
|
|
1044
|
+
);
|
|
856
1045
|
this.warnOnPartialIngest(events.length, result?.ingested ?? 0);
|
|
857
1046
|
return result;
|
|
858
1047
|
}
|
|
@@ -889,7 +1078,61 @@ var VorimSDK = class _VorimSDK {
|
|
|
889
1078
|
* - Chain ops are serialised per-agent via `chainLocks` so
|
|
890
1079
|
* concurrent emits to the same agent build a deterministic chain.
|
|
891
1080
|
*/
|
|
1081
|
+
/**
|
|
1082
|
+
* Fail closed when `noPayload` is on and an event would carry content.
|
|
1083
|
+
*
|
|
1084
|
+
* Runs before signing and before any network call, so a rejected event is
|
|
1085
|
+
* one Vorim never saw. Throwing rather than stripping is deliberate: a
|
|
1086
|
+
* silent strip would leave the caller believing they had logged something
|
|
1087
|
+
* they had not, and would change the bytes after they were signed.
|
|
1088
|
+
*/
|
|
1089
|
+
assertNoPayload(event) {
|
|
1090
|
+
if (!this.noPayload) return;
|
|
1091
|
+
for (const field of ["input_hash", "output_hash", "system_prompt_hash", "tool_catalogue_hash"]) {
|
|
1092
|
+
const value = event[field];
|
|
1093
|
+
if (value === void 0 || value === null) continue;
|
|
1094
|
+
if (!isDigest(value)) {
|
|
1095
|
+
throw new VorimError(
|
|
1096
|
+
0,
|
|
1097
|
+
"PAYLOAD_BLOCKED",
|
|
1098
|
+
`noPayload: ${field} must be a sha256: or hmac-sha256: digest, got ${typeof value === "string" ? `${value.length} chars` : typeof value}. Hash it locally first \u2014 commitPayload() for anything a human or a model wrote, hashPayload() only for content that is already high-entropy.`,
|
|
1099
|
+
{ field }
|
|
1100
|
+
);
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
const metadata = event.metadata;
|
|
1104
|
+
if (metadata === void 0 || metadata === null) return;
|
|
1105
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
1106
|
+
if (value === null) continue;
|
|
1107
|
+
const t = typeof value;
|
|
1108
|
+
if (t === "object") {
|
|
1109
|
+
throw new VorimError(
|
|
1110
|
+
0,
|
|
1111
|
+
"PAYLOAD_BLOCKED",
|
|
1112
|
+
`noPayload: metadata.${key} is ${Array.isArray(value) ? "an array" : "an object"}. Nested values can carry arbitrary content, so only string, number, boolean and null are allowed. Summarise it, or commit to it with commitPayload() and send the digest.`,
|
|
1113
|
+
{ field: `metadata.${key}` }
|
|
1114
|
+
);
|
|
1115
|
+
}
|
|
1116
|
+
if (t !== "string" && t !== "number" && t !== "boolean") {
|
|
1117
|
+
throw new VorimError(
|
|
1118
|
+
0,
|
|
1119
|
+
"PAYLOAD_BLOCKED",
|
|
1120
|
+
`noPayload: metadata.${key} is ${t}, which is not a permitted metadata type.`,
|
|
1121
|
+
{ field: `metadata.${key}` }
|
|
1122
|
+
);
|
|
1123
|
+
}
|
|
1124
|
+
if (t === "string" && value.length > this.maxMetadataChars) {
|
|
1125
|
+
throw new VorimError(
|
|
1126
|
+
0,
|
|
1127
|
+
"PAYLOAD_BLOCKED",
|
|
1128
|
+
`noPayload: metadata.${key} is ${value.length} chars, over the ${this.maxMetadataChars} limit. A value this long is content, not a label. Raise the limit with noPayload: { maxMetadataChars } if this really is a label.`,
|
|
1129
|
+
{ field: `metadata.${key}`, length: value.length }
|
|
1130
|
+
);
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
892
1134
|
async prepareEvent(event, signOverride) {
|
|
1135
|
+
this.assertNoPayload(event);
|
|
893
1136
|
const shouldSign = signOverride ?? this.autoSign;
|
|
894
1137
|
if (!shouldSign && !this.chainEvents) return event;
|
|
895
1138
|
if (this.chainEvents) {
|
|
@@ -1094,8 +1337,8 @@ var VorimSDK = class _VorimSDK {
|
|
|
1094
1337
|
async get(path) {
|
|
1095
1338
|
return this.request("GET", path);
|
|
1096
1339
|
}
|
|
1097
|
-
async post(path, body) {
|
|
1098
|
-
return this.request("POST", path, body);
|
|
1340
|
+
async post(path, body, headers) {
|
|
1341
|
+
return this.request("POST", path, body, true, headers);
|
|
1099
1342
|
}
|
|
1100
1343
|
async patch(path, body) {
|
|
1101
1344
|
return this.request("PATCH", path, body);
|
|
@@ -1111,7 +1354,7 @@ var VorimSDK = class _VorimSDK {
|
|
|
1111
1354
|
async requestEnvelope(method, path, body) {
|
|
1112
1355
|
return this.request(method, path, body, false);
|
|
1113
1356
|
}
|
|
1114
|
-
async request(method, path, body, unwrap = true) {
|
|
1357
|
+
async request(method, path, body, unwrap = true, extraHeaders) {
|
|
1115
1358
|
const controller = new AbortController();
|
|
1116
1359
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
1117
1360
|
try {
|
|
@@ -1120,7 +1363,8 @@ var VorimSDK = class _VorimSDK {
|
|
|
1120
1363
|
headers: {
|
|
1121
1364
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1122
1365
|
"Content-Type": "application/json",
|
|
1123
|
-
"User-Agent": USER_AGENT
|
|
1366
|
+
"User-Agent": USER_AGENT,
|
|
1367
|
+
...extraHeaders
|
|
1124
1368
|
},
|
|
1125
1369
|
body: body ? JSON.stringify(body) : void 0,
|
|
1126
1370
|
signal: controller.signal
|
|
@@ -1249,17 +1493,25 @@ async function deviceLogin(opts) {
|
|
|
1249
1493
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1250
1494
|
0 && (module.exports = {
|
|
1251
1495
|
CANONICAL_TOOL_CATALOGUE_VERSION,
|
|
1496
|
+
HMAC_SHA256_PREFIX,
|
|
1497
|
+
SHA256_PREFIX,
|
|
1252
1498
|
VorimDeniedError,
|
|
1253
1499
|
VorimError,
|
|
1254
1500
|
VorimSDK,
|
|
1255
1501
|
canonicalPayloadV0,
|
|
1256
1502
|
canonicalPayloadV1,
|
|
1503
|
+
commitPayload,
|
|
1257
1504
|
deviceLogin,
|
|
1505
|
+
eventDigest,
|
|
1506
|
+
hashPayload,
|
|
1258
1507
|
hashPreviousEvent,
|
|
1259
1508
|
hashSystemPrompt,
|
|
1260
1509
|
hashTool,
|
|
1261
1510
|
hashToolCatalogue,
|
|
1511
|
+
isDigest,
|
|
1512
|
+
isKeyedCommitment,
|
|
1262
1513
|
jcsCanonicalise,
|
|
1514
|
+
portableReceiptCanonicalBytes,
|
|
1263
1515
|
prepareReplayContext
|
|
1264
1516
|
});
|
|
1265
1517
|
//# sourceMappingURL=index.cjs.map
|