@tenuo/core 0.2.4-beta.0 → 0.3.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +49 -5
  2. package/dist/api.d.ts +416 -17
  3. package/dist/api.js.map +1 -1
  4. package/dist/client.d.ts +59 -2
  5. package/dist/client.js +700 -70
  6. package/dist/client.js.map +1 -1
  7. package/dist/connect.d.ts +53 -0
  8. package/dist/connect.js +177 -0
  9. package/dist/connect.js.map +1 -0
  10. package/dist/constraints.d.ts +54 -3
  11. package/dist/constraints.js +154 -6
  12. package/dist/constraints.js.map +1 -1
  13. package/dist/errors.d.ts +8 -3
  14. package/dist/errors.js +10 -1
  15. package/dist/errors.js.map +1 -1
  16. package/dist/generated/tenuo_wasm.d.ts +136 -7
  17. package/dist/generated/tenuo_wasm.js +398 -9
  18. package/dist/generated/tenuo_wasm_bg.wasm +0 -0
  19. package/dist/generated/tenuo_wasm_bg.wasm.d.ts +40 -22
  20. package/dist/identity.d.ts +25 -0
  21. package/dist/identity.js +61 -0
  22. package/dist/identity.js.map +1 -0
  23. package/dist/index.d.ts +9 -3
  24. package/dist/index.js +5 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/mcp.d.ts +18 -3
  27. package/dist/mcp.js +67 -59
  28. package/dist/mcp.js.map +1 -1
  29. package/dist/nonce.d.ts +6 -1
  30. package/dist/nonce.js +12 -1
  31. package/dist/nonce.js.map +1 -1
  32. package/dist/receipts.d.ts +27 -0
  33. package/dist/receipts.js +128 -0
  34. package/dist/receipts.js.map +1 -0
  35. package/dist/runtime.d.ts +51 -0
  36. package/dist/runtime.js +102 -0
  37. package/dist/runtime.js.map +1 -0
  38. package/dist/session.d.ts +9 -2
  39. package/dist/session.js +56 -0
  40. package/dist/session.js.map +1 -1
  41. package/dist/wasm.d.ts +207 -5
  42. package/dist/wasm.js +62 -4
  43. package/dist/wasm.js.map +1 -1
  44. package/package.json +3 -2
  45. package/dist/api.d.ts.map +0 -1
  46. package/dist/client.d.ts.map +0 -1
  47. package/dist/constraints.d.ts.map +0 -1
  48. package/dist/errors.d.ts.map +0 -1
  49. package/dist/index.d.ts.map +0 -1
  50. package/dist/mcp.d.ts.map +0 -1
  51. package/dist/nonce.d.ts.map +0 -1
  52. package/dist/session.d.ts.map +0 -1
  53. package/dist/wasm.d.ts.map +0 -1
package/README.md CHANGED
@@ -38,18 +38,60 @@ ceiling. `devRoot()` requires `NODE_ENV=development` or `test`,
38
38
  `devRoot({ allowInProduction: true })`, or `TENUO_ALLOW_DEV=1`. Unset
39
39
  `NODE_ENV` is not treated as development.
40
40
 
41
- Production loads an issued warrant and a trusted root:
41
+ Production loads an issued warrant and a trusted root. Prefer `Runtime` when
42
+ the same holder identity, roots, revocation list, and receipt buffer should
43
+ outlive a single call:
42
44
 
43
45
  ```ts
44
- const tenuo = createTenuo({
46
+ const identity = createTenuo.identity(createTenuo.holderKeyFromEnv("TENUO_HOLDER_SECRET"));
47
+ const runtime = createTenuo.runtime({
48
+ identity,
45
49
  trustedRoots: [createTenuo.publicKeyFromEnv("TENUO_ROOT_PUBLIC_KEY")],
50
+ receipts: "collect",
46
51
  });
47
- const session = tenuo.sessionFromWire({
48
- warrant: process.env.TENUO_WARRANT!,
49
- holderKey: createTenuo.holderKeyFromEnv("TENUO_HOLDER_SECRET"),
52
+ const session = runtime.sessionFromWire(process.env.TENUO_WARRANT!);
53
+ await readFile.execute({ path: "/data/q3.pdf" }, { session });
54
+ const receipts = session.drainReceipts(); // persist, then upload
55
+ ```
56
+
57
+ `createTenuo.parseConnectToken(raw)` decodes a `tenuo_ct_…` token. It does not
58
+ read environment variables or invent an origin. Relative `/v1` endpoints need
59
+ `token.resolveEndpoint({ localBase })`. Callers append `/v1/…` to the bare
60
+ origin.
61
+
62
+ See [Receipt delivery](../../README.md#receipt-delivery) for peek / drain / ack
63
+ guarantees. This package does not perform HTTP, discovery, or upload.
64
+
65
+ Delegation to another agent rebinds a narrower child to that agent's key. The
66
+ current holder signs; core refuses any child that is not within its parent
67
+ before a token exists; a copied chain fails `TENUO_INVALID_POP` under any other
68
+ key:
69
+
70
+ ```ts
71
+ const holderKey = createTenuo.generateHolderKey(); // in the worker, once
72
+ const workerPublicKey = createTenuo.publicKeyFromHolderKey(holderKey);
73
+
74
+ const handed = tenuo.narrow(session, { path: under("/data/reports") }, {
75
+ holder: workerPublicKey,
76
+ ttlSeconds: 300,
77
+ terminal: true, // the worker cannot hand it on
50
78
  });
79
+ // worker: tenuo.sessionFromWire({ warrant: handed.toWire(), holderKey })
51
80
  ```
52
81
 
82
+ `session({ holder, maxDepth })` issues straight to an agent's key and caps how
83
+ far the chain may go; `issuerPublicKey()` is what agents put in `trustedRoots`;
84
+ `session.inspect()` shows depth, ceiling, tools, and holder public key.
85
+
86
+ The rest of the protocol is here too: a stable issuer key
87
+ (`createTenuo({ root: createTenuo.issuerKeyFromEnv("TENUO_ISSUER_SECRET") })`),
88
+ issuer sessions and `tenuo.issue()`, clearance / session id / agent id, the
89
+ full constraint set (`range`, `regex`, `cidr`, `urlSafe`, `shlex`, `anyOf`,
90
+ `cel`, ...), approval gates with `ApprovalRequiredError.request`,
91
+ `createTenuo.signApproval()` and the control-plane v1 wire shape, revocation
92
+ lists (`tenuo.revocationList()`), public receipt verification, `tenuo.explain()`,
93
+ and `tenuo.present()` / `tenuo.verify()` for boundaries that are not MCP.
94
+
53
95
  MCP wire helpers live on `tenuo.mcp` (`attach` / `verify` / `handler`). They do
54
96
  not depend on an MCP framework. For the official v2 server, use `@tenuo/mcp`.
55
97
  For `@modelcontextprotocol/sdk` v1, copy the recipe in `examples/mcp/host.ts`.
@@ -57,6 +99,8 @@ For `@modelcontextprotocol/sdk` v1, copy the recipe in `examples/mcp/host.ts`.
57
99
  or an async Redis `checkAndRecord`) to reject an exact replayed PoP; that is
58
100
  opt-in. PoP v1 is otherwise replayable in-window, including approval-gated
59
101
  calls. Pass `nonceStore` on those tools if an approval must be one-use.
102
+ `memoryNonceStore({ ttlSeconds })` defaults to 180 seconds; an explicit TTL must
103
+ be positive, finite, and small enough to represent in milliseconds.
60
104
 
61
105
  See the [workspace README](../../README.md) for the full API, refuse list, and
62
106
  how to rebuild WASM from this monorepo.
package/dist/api.d.ts CHANGED
@@ -4,11 +4,19 @@
4
4
  * Names and shapes here are the review surface — do not grow this file with
5
5
  * protocol vocabulary (`Warrant`, `mint`, `guard`) as the lead API.
6
6
  */
7
- export type TenuoErrorCode = "TENUO_NOT_READY" | "TENUO_CONFIGURATION" | "TENUO_CONSTRAINT_VIOLATION" | "TENUO_TOOL_NOT_AUTHORIZED" | "TENUO_WARRANT_EXPIRED" | "TENUO_UNTRUSTED_ROOT" | "TENUO_INVALID_POP" | "TENUO_SIGNATURE_INVALID" | "TENUO_CHAIN_INVALID" | "TENUO_REVOKED" | "TENUO_APPROVAL_REQUIRED" | "TENUO_INSUFFICIENT_APPROVALS" | "TENUO_CANONICALIZATION" | "TENUO_NOT_IMPLEMENTED";
7
+ /** Canonical kebab-case codes from Rust `ErrorCode::name()` / `Denial::code()`. */
8
+ export type ProtocolDenialCode = "signature-invalid" | "untrusted-root" | "chain-broken" | "depth-exceeded" | "warrant-expired" | "tool-not-authorized" | "constraint-violation" | "pop-signature-invalid" | "approval-required" | "insufficient-approvals" | "warrant-revoked";
9
+ /** Legacy SCREAMING_SNAKE aliases accepted by existing TypeScript callers. */
10
+ export type LegacyTenuoErrorCode = "TENUO_NOT_READY" | "TENUO_CONFIGURATION" | "TENUO_CONSTRAINT_VIOLATION" | "TENUO_TOOL_NOT_AUTHORIZED" | "TENUO_WARRANT_EXPIRED" | "TENUO_UNTRUSTED_ROOT" | "TENUO_INVALID_POP" | "TENUO_SIGNATURE_INVALID" | "TENUO_CHAIN_INVALID" | "TENUO_DEPTH_EXCEEDED" | "TENUO_REVOKED" | "TENUO_APPROVAL_REQUIRED" | "TENUO_INSUFFICIENT_APPROVALS" | "TENUO_CANONICALIZATION" | "TENUO_NOT_IMPLEMENTED";
11
+ export type TenuoErrorCode = ProtocolDenialCode | LegacyTenuoErrorCode;
8
12
  /** Path-traversal-safe prefix. Core evaluates this; TypeScript does not. */
9
13
  export type UnderConstraint = {
10
14
  readonly kind: "under";
11
15
  readonly root: string;
16
+ /** Default true. */
17
+ readonly caseSensitive?: boolean;
18
+ /** Whether the root itself is allowed. Default true. */
19
+ readonly allowEqual?: boolean;
12
20
  };
13
21
  export type EmailConstraint = {
14
22
  readonly kind: "email";
@@ -18,19 +26,83 @@ export type MaxConstraint = {
18
26
  readonly kind: "max";
19
27
  readonly value: number;
20
28
  };
29
+ export type MinConstraint = {
30
+ readonly kind: "min";
31
+ readonly value: number;
32
+ };
33
+ export type RangeConstraint = {
34
+ readonly kind: "range";
35
+ readonly min?: number;
36
+ readonly max?: number;
37
+ readonly minExclusive?: boolean;
38
+ readonly maxExclusive?: boolean;
39
+ };
21
40
  export type OneOfConstraint = {
22
41
  readonly kind: "oneOf";
23
42
  readonly values: readonly string[];
24
43
  };
44
+ export type NotOneOfConstraint = {
45
+ readonly kind: "notOneOf";
46
+ readonly values: readonly string[];
47
+ };
25
48
  export type PatternConstraint = {
26
49
  readonly kind: "pattern";
27
50
  readonly pattern: string;
28
51
  };
52
+ export type RegexConstraint = {
53
+ readonly kind: "regex";
54
+ readonly source: string;
55
+ };
29
56
  export type ExactConstraint = {
30
57
  readonly kind: "exact";
31
58
  readonly value: string | number | boolean;
32
59
  };
33
- export type ConstraintExpr = UnderConstraint | EmailConstraint | MaxConstraint | OneOfConstraint | PatternConstraint | ExactConstraint;
60
+ export type WildcardConstraint = {
61
+ readonly kind: "wildcard";
62
+ };
63
+ export type CidrConstraint = {
64
+ readonly kind: "cidr";
65
+ readonly network: string;
66
+ };
67
+ export type UrlPatternConstraint = {
68
+ readonly kind: "urlPattern";
69
+ readonly pattern: string;
70
+ };
71
+ export type UrlSafeConstraint = {
72
+ readonly kind: "urlSafe";
73
+ readonly schemes?: readonly string[];
74
+ readonly allowDomains?: readonly string[];
75
+ readonly denyDomains?: readonly string[];
76
+ };
77
+ export type ShlexConstraint = {
78
+ readonly kind: "shlex";
79
+ readonly allow: readonly string[];
80
+ };
81
+ export type ContainsConstraint = {
82
+ readonly kind: "contains";
83
+ readonly values: readonly (string | number | boolean)[];
84
+ };
85
+ export type SubsetConstraint = {
86
+ readonly kind: "subset";
87
+ readonly values: readonly (string | number | boolean)[];
88
+ };
89
+ export type AnyOfConstraint = {
90
+ readonly kind: "anyOf";
91
+ readonly constraints: readonly ConstraintExpr[];
92
+ };
93
+ export type AllConstraint = {
94
+ readonly kind: "all";
95
+ readonly constraints: readonly ConstraintExpr[];
96
+ };
97
+ export type NotConstraint = {
98
+ readonly kind: "not";
99
+ readonly constraint: ConstraintExpr;
100
+ };
101
+ export type CelConstraint = {
102
+ readonly kind: "cel";
103
+ readonly expression: string;
104
+ };
105
+ export type ConstraintExpr = UnderConstraint | EmailConstraint | MaxConstraint | MinConstraint | RangeConstraint | OneOfConstraint | NotOneOfConstraint | PatternConstraint | RegexConstraint | ExactConstraint | WildcardConstraint | CidrConstraint | UrlPatternConstraint | UrlSafeConstraint | ShlexConstraint | ContainsConstraint | SubsetConstraint | AnyOfConstraint | AllConstraint | NotConstraint | CelConstraint;
34
106
  /** Per-argument allow policy. Not a Zod schema. */
35
107
  export type AllowPolicy = {
36
108
  readonly [field: string]: ConstraintExpr;
@@ -44,13 +116,16 @@ export type ToolLike<TArgs extends Record<string, unknown> = Record<string, unkn
44
116
  readonly parameters?: unknown;
45
117
  execute: (args: TArgs, options?: unknown) => TResult | Promise<TResult>;
46
118
  };
47
- export type ToolPolicy = {
119
+ type KeysOfUnion<T> = T extends unknown ? keyof T : never;
120
+ export type ToolPolicy<TArgs = undefined> = {
48
121
  /**
49
122
  * Host ceiling. AND'd with the session in Rust.
50
123
  * Non-empty maps are zero-trust: every call argument must be named here.
51
124
  * `{}` means no extra ceiling (session/warrant only).
52
125
  */
53
- readonly allow: AllowPolicy;
126
+ readonly allow: [NonNullable<TArgs>] extends [object] ? [KeysOfUnion<NonNullable<TArgs>>] extends [never] ? AllowPolicy : string extends KeysOfUnion<NonNullable<TArgs>> ? AllowPolicy : number extends KeysOfUnion<NonNullable<TArgs>> ? AllowPolicy : symbol extends KeysOfUnion<NonNullable<TArgs>> ? AllowPolicy : {
127
+ readonly [Field in KeysOfUnion<NonNullable<TArgs>>]?: ConstraintExpr;
128
+ } : AllowPolicy;
54
129
  readonly capability?: string;
55
130
  };
56
131
  /** Compile-time brand only — never assigned at runtime. Do not `in`/`has` this key. */
@@ -83,22 +158,246 @@ export type ProtectedTool<T extends {
83
158
  execute: (args: Parameters<T["execute"]>[0], options?: ExecuteOptions & ExtraExecuteOptions<T>) => Promise<Awaited<ReturnType<T["execute"]>>>;
84
159
  readonly [protectedBrand]: true;
85
160
  };
86
- /** Whole-tool approval gate. Host collects SignedApproval bytes; Rust decides. */
161
+ /** Per-argument trigger for an approval gate. */
162
+ export type ArgApprovalGate =
163
+ /** Every value of this argument fires the gate. */
164
+ "all"
165
+ /** Only values satisfying the constraint fire the gate. */
166
+ | {
167
+ readonly when: ConstraintExpr;
168
+ }
169
+ /** Every value except those satisfying the constraint fires the gate. Narrowable across delegation. */
170
+ | {
171
+ readonly exempt: ConstraintExpr;
172
+ };
173
+ /** Gate on one tool: a message for the approver and optional per-argument triggers. */
174
+ export type ToolApprovalGate = {
175
+ readonly message?: string;
176
+ /** Absent: the whole tool is gated. */
177
+ readonly args?: {
178
+ readonly [field: string]: ArgApprovalGate;
179
+ };
180
+ };
181
+ /** Approval requirement. Host collects SignedApproval envelopes; Rust decides. */
87
182
  export type RequireApproval = {
88
183
  readonly approvers: readonly PublicKeyHandle[];
89
184
  readonly min: number;
185
+ /** Whole-tool gates. Defaults to every tool in the session when `gates` is absent too. */
90
186
  readonly tools?: readonly string[];
187
+ /** Per-tool gates with messages and per-argument triggers. */
188
+ readonly gates?: {
189
+ readonly [tool: string]: ToolApprovalGate;
190
+ };
191
+ };
192
+ /** What an approval service needs to present a call to a human. Not a signed artifact. */
193
+ export type ApprovalRequest = {
194
+ readonly requestId: string;
195
+ readonly warrantId: string;
196
+ readonly tool: string;
197
+ readonly args: Readonly<Record<string, unknown>>;
198
+ /** Hex SHA-256 committing to warrant id, tool, canonical args, and holder. */
199
+ readonly requestHash: string;
200
+ readonly holderPublicKey: string;
201
+ readonly requiredApprovers: readonly string[];
202
+ readonly minApprovals: number;
203
+ /** Unix seconds. An approval cannot outlive the warrant. */
204
+ readonly warrantExpiresAt: number;
205
+ readonly createdAt: number;
206
+ readonly message: string;
207
+ };
208
+ /** Holder-signed statement that it is the one asking. Carried in a control-plane request. */
209
+ export type ApprovalContextAttestation = {
210
+ readonly version: number;
211
+ readonly canonicalization: string;
212
+ readonly warrantId: string;
213
+ readonly tool: string;
214
+ readonly requestHash: string;
215
+ readonly holderKeyHex: string;
216
+ readonly argsCanonicalCborB64: string;
217
+ readonly signerKeyHex: string;
218
+ readonly signatureB64: string;
219
+ };
220
+ /** Wire body for a control-plane approval API. Field names are the wire names. */
221
+ export type ControlPlaneApprovalRequestV1 = {
222
+ readonly schema_version: 1;
223
+ readonly request_id_hex: string;
224
+ readonly warrant_id: string;
225
+ readonly tool: string;
226
+ readonly arguments: Readonly<Record<string, unknown>>;
227
+ readonly request_hash_hex: string;
228
+ readonly holder_public_key_hex: string;
229
+ readonly required_approver_keys_hex: readonly string[];
230
+ readonly min_approvals: number;
231
+ readonly warrant_expires_at_unix: number;
232
+ readonly created_at_unix: number;
233
+ readonly attestation?: Readonly<Record<string, unknown>>;
234
+ readonly temporal?: Readonly<Record<string, string>>;
235
+ readonly message?: string;
236
+ };
237
+ export type ControlPlaneApprovalResponseV1 = {
238
+ readonly status: string;
239
+ readonly signed_approvals_b64?: readonly string[];
240
+ readonly error?: string;
241
+ readonly server_request_id?: string;
242
+ };
243
+ export type SignApprovalOptions = {
244
+ /** Who approved, in the approver system's own terms. Required. */
245
+ readonly externalId: string;
246
+ /** Approval lifetime. Default one hour, always clamped to the warrant's expiry when given. */
247
+ readonly ttlSeconds?: number;
248
+ readonly warrantExpiresAt?: number;
249
+ };
250
+ /** Decoded approval envelope. Not authorization. */
251
+ export type ApprovalInfo = {
252
+ readonly approverPublicKey: string;
253
+ readonly requestHash: string;
254
+ readonly externalId: string;
255
+ readonly approvedAt: number;
256
+ readonly expiresAt: number;
257
+ readonly expired: boolean;
258
+ readonly signatureValid: boolean;
259
+ readonly error?: string;
91
260
  };
92
261
  export type SessionAllow = {
93
262
  readonly [capability: string]: AllowPolicy;
94
263
  };
264
+ /** Named level or a number 0-255. Delegation can only lower it. */
265
+ export type Clearance = number | "untrusted" | "external" | "partner" | "internal" | "privileged" | "system";
95
266
  export type SessionInput = {
96
- /** Capability map. Optional when `tools` is set. */
267
+ /** Capability map. Optional when `tools` is set. Issuer sessions may omit it. */
97
268
  readonly allow?: SessionAllow;
98
269
  /** Wrapped tools from `tenuo.tool()`. Their `allow` is minted into the session. */
99
270
  readonly tools?: readonly object[];
100
271
  readonly ttlSeconds?: number;
101
272
  readonly requireApproval?: RequireApproval;
273
+ /**
274
+ * Issue to another agent's key instead of a fresh local holder. The
275
+ * returned session cannot authorize here (it has no holder secret); send
276
+ * `toWire()` to that agent, which imports it with `sessionFromWire()`.
277
+ */
278
+ readonly holder?: PublicKeyHandle;
279
+ /**
280
+ * How many times this authority may be delegated below the root.
281
+ * `0` makes the session terminal. Omit for the protocol maximum.
282
+ * Delegation can lower this ceiling and never raise it.
283
+ */
284
+ readonly maxDepth?: number;
285
+ /**
286
+ * `"execution"` (default) can call tools. `"issuer"` cannot call tools; its
287
+ * holder can mint execution sessions with `tenuo.issue()` for the tools in
288
+ * `issuableTools`, within `constraintBounds`, without the root key.
289
+ */
290
+ readonly kind?: "execution" | "issuer";
291
+ readonly clearance?: Clearance;
292
+ /** Free-form task correlation id. Inherited unchanged through delegation. */
293
+ readonly sessionId?: string;
294
+ /** Free-form agent label. Delegation may change it. */
295
+ readonly agentId?: string;
296
+ /** Issuer sessions only. */
297
+ readonly issuableTools?: readonly string[];
298
+ /** Issuer sessions only: ceiling on the constraints of anything issued, by field. */
299
+ readonly constraintBounds?: AllowPolicy;
300
+ /** Issuer sessions only: how deep issued sessions may themselves delegate. */
301
+ readonly maxIssueDepth?: number;
302
+ };
303
+ /** Options for `tenuo.narrow()`. All optional; the default keeps the holder. */
304
+ export type NarrowOptions = {
305
+ /**
306
+ * Bind the child to another agent's key. This is delegation: the current
307
+ * holder signs, the child belongs to `holder`, and the returned session
308
+ * cannot authorize here. Hand `toWire()` to that agent.
309
+ */
310
+ readonly holder?: PublicKeyHandle;
311
+ /** Child lifetime. Clamped to what the parent has left. */
312
+ readonly ttlSeconds?: number;
313
+ /** The child's holder cannot delegate further. */
314
+ readonly terminal?: boolean;
315
+ /** Lower the delegation ceiling. Cannot exceed the parent's. */
316
+ readonly maxDepth?: number;
317
+ /** Lower the clearance. Cannot exceed the parent's. */
318
+ readonly clearance?: Clearance;
319
+ readonly agentId?: string;
320
+ /** Approvers can only be added. */
321
+ readonly addApprovers?: readonly PublicKeyHandle[];
322
+ /** The threshold can only go up. */
323
+ readonly minApprovals?: number;
324
+ };
325
+ /** Options for `tenuo.issue()`: an execution session minted from an issuer session. */
326
+ export type IssueInput = {
327
+ readonly allow: SessionAllow;
328
+ /** The distinct agent that will use it. Issuer/holder separation is enforced. */
329
+ readonly holder: PublicKeyHandle;
330
+ readonly ttlSeconds?: number;
331
+ readonly maxDepth?: number;
332
+ readonly clearance?: Clearance;
333
+ readonly sessionId?: string;
334
+ readonly agentId?: string;
335
+ /** Approval policy for the issued execution session. Defaults to gating every issued tool. */
336
+ readonly requireApproval?: RequireApproval;
337
+ };
338
+ /** Public view of a session's leaf. Never includes the holder secret. */
339
+ export type SessionInfo = {
340
+ readonly kind: "execution" | "issuer";
341
+ /** Hex public key the leaf is bound to. */
342
+ readonly holderPublicKey: string;
343
+ /** Hex public key that signed the root of the chain. */
344
+ readonly rootPublicKey: string;
345
+ /** 0 for a root session, +1 per delegation. */
346
+ readonly depth: number;
347
+ /** Delegation ceiling in force for this leaf. */
348
+ readonly maxDepth: number;
349
+ /** True when `depth >= maxDepth`: cannot be narrowed further. */
350
+ readonly terminal: boolean;
351
+ /** Unix seconds. */
352
+ readonly expiresAt: number;
353
+ readonly tools: readonly string[];
354
+ /** Warrant ids, root first. */
355
+ readonly warrantIds: readonly string[];
356
+ /**
357
+ * True when this process holds the leaf's holder secret. False for a
358
+ * session issued or delegated to another agent: `toWire()` works,
359
+ * `execute` and `narrow` do not.
360
+ */
361
+ readonly canAuthorize: boolean;
362
+ readonly clearance?: number;
363
+ readonly sessionId?: string;
364
+ readonly agentId?: string;
365
+ readonly issuableTools?: readonly string[];
366
+ readonly maxIssueDepth?: number;
367
+ readonly requiredApprovers?: readonly string[];
368
+ readonly minApprovals?: number;
369
+ readonly approvalGatedTools: readonly string[];
370
+ };
371
+ /** One constrained argument in an `explain()` result. */
372
+ export type ExplainedField = {
373
+ readonly field: string;
374
+ /** Core constraint type name, e.g. `"Subpath"`, `"Range"`. */
375
+ readonly kind: string;
376
+ /** The constraint as core serializes it. */
377
+ readonly constraint: unknown;
378
+ /** Absent when the argument was not supplied. */
379
+ readonly value?: unknown;
380
+ readonly satisfied: boolean;
381
+ readonly reason?: string;
382
+ };
383
+ /** What a session would decide for `tool(args)`, field by field. No proof-of-possession involved. */
384
+ export type Explanation = {
385
+ readonly tool: string;
386
+ readonly kind: "execution" | "issuer";
387
+ readonly outcome: "allow" | "deny";
388
+ readonly code?: TenuoErrorCode;
389
+ readonly field?: string;
390
+ readonly message?: string;
391
+ readonly toolGranted: boolean;
392
+ readonly fields: readonly ExplainedField[];
393
+ /** Arguments the session does not name. Zero-trust policies reject these. */
394
+ readonly unknownFields: readonly string[];
395
+ /** Constrained arguments the call did not supply. */
396
+ readonly missingFields: readonly string[];
397
+ readonly expired: boolean;
398
+ readonly expiresAt: number;
399
+ readonly chainValid: boolean;
400
+ readonly chainError?: TenuoErrorCode;
102
401
  };
103
402
  export type DevRoot = {
104
403
  readonly kind: "dev-root";
@@ -108,6 +407,11 @@ export type DevRoot = {
108
407
  */
109
408
  readonly allowInProduction?: boolean;
110
409
  };
410
+ /** A stable issuer secret: this process is a control plane. */
411
+ export type IssuerKey = {
412
+ readonly kind: "issuer-key";
413
+ readonly secret: Uint8Array;
414
+ };
111
415
  export type PublicKeyHandle = {
112
416
  readonly kind: "public-key";
113
417
  readonly source: "env" | "hex" | "bytes";
@@ -125,11 +429,18 @@ export type SessionFromWireInput = {
125
429
  export type NarrowInput = AllowPolicy | SessionAllow;
126
430
  export type CreateTenuoOptions = {
127
431
  readonly trustedRoots?: readonly PublicKeyHandle[];
128
- readonly root?: DevRoot | PublicKeyHandle;
432
+ /**
433
+ * `devRoot()` for development; an `issuerKey*` for a control plane that
434
+ * mints with a stable key; a public key for a verifier. An issuer key
435
+ * trusts itself plus `trustedRoots`.
436
+ */
437
+ readonly root?: DevRoot | IssuerKey | PublicKeyHandle;
129
438
  /** Published SignedRevocationList (hex or standard base64). Verified against a trusted root. */
130
439
  readonly revocationList?: string | Uint8Array;
440
+ /** 32-byte holder seed used to sign verifier receipts. Runtime supplies this. */
441
+ readonly receiptSigner?: Uint8Array;
131
442
  };
132
- export type ApprovalRequest = {
443
+ export type ApprovalRequestSummary = {
133
444
  readonly tool: string;
134
445
  readonly required: number;
135
446
  readonly received: number;
@@ -143,7 +454,53 @@ export type Decision = {
143
454
  readonly field?: string;
144
455
  } | {
145
456
  readonly outcome: "approval_required";
146
- readonly request: ApprovalRequest;
457
+ readonly request: ApprovalRequestSummary;
458
+ };
459
+ export type RevocationListInput = {
460
+ readonly revoke: readonly string[];
461
+ /** Monotonic; verifiers refuse an older version. Default 1. */
462
+ readonly version?: number;
463
+ };
464
+ export type RevocationListInfo = {
465
+ readonly version: number;
466
+ readonly issuedAt: number;
467
+ readonly issuerPublicKey: string;
468
+ readonly revokedIds: readonly string[];
469
+ readonly signatureValid: boolean;
470
+ };
471
+ /** Signature authenticity of a receipt. Not authorization. */
472
+ export type ReceiptInfo = {
473
+ readonly authentic: true;
474
+ /** Hex key the receipt is signed under — resolve against your own authorizer set. */
475
+ readonly signerKey: string;
476
+ readonly outcome: "allow" | "deny";
477
+ readonly action: string;
478
+ readonly decisionCode?: string;
479
+ readonly requestId: string;
480
+ readonly srlVersion?: number;
481
+ readonly srlHash?: string;
482
+ readonly requestHash?: string;
483
+ readonly policyDefinitionHash?: string;
484
+ readonly prevReceiptHash?: string;
485
+ readonly trustedRootsHash?: string;
486
+ };
487
+ /** Root-anchored receipt check: the embedded chain against trusted roots at decision time. */
488
+ export type ReceiptChainInfo = {
489
+ readonly signerKey: string;
490
+ readonly outcome: "allow" | "deny";
491
+ readonly decisionCode?: string;
492
+ readonly timestamp: number;
493
+ readonly chainValid: boolean;
494
+ readonly chainError?: string;
495
+ readonly corroboratesDenial?: boolean;
496
+ readonly rootIssuer?: string;
497
+ readonly leafHolder?: string;
498
+ };
499
+ /** Warrant chain plus proof-of-possession for one call. Transport-agnostic. */
500
+ export type PresentedCall = {
501
+ readonly warrant: string;
502
+ readonly signature: string;
503
+ readonly approvals?: readonly string[];
147
504
  };
148
505
  export interface Session {
149
506
  readonly [Symbol.toStringTag]: "TenuoSession";
@@ -151,6 +508,25 @@ export interface Session {
151
508
  toWire(): readonly string[];
152
509
  /** SHA-256 of `(warrant_id, tool, canonical args)`. App-level idempotency, not PoP. */
153
510
  dedupKey(tool: string, args: Readonly<Record<string, unknown>>): string;
511
+ /** Holder public key, depth, ceiling, lifetime, tools. Never the secret. */
512
+ inspect(): SessionInfo;
513
+ /**
514
+ * Receipt helpers below are required for `createTenuo.runtime({ receipts:
515
+ * "collect" })`. Implementers that are not runtime sessions can return
516
+ * empty snapshots and `0` from acknowledge.
517
+ */
518
+ /**
519
+ * Receipts collected for this session and not yet drained. Empty when the
520
+ * session was not created by a Runtime with `receipts: "collect"`.
521
+ */
522
+ peekReceipts(): readonly string[];
523
+ /**
524
+ * Snapshot of collected receipts. Same as `peekReceipts`; nothing is removed
525
+ * until `acknowledgeReceipts`.
526
+ */
527
+ drainReceipts(): readonly string[];
528
+ /** Remove the first `count` pending receipts. */
529
+ acknowledgeReceipts(count: number): number;
154
530
  }
155
531
  export interface Tenuo {
156
532
  /**
@@ -159,12 +535,40 @@ export interface Tenuo {
159
535
  */
160
536
  tool<T extends {
161
537
  execute: (args: never) => unknown;
162
- }>(inner: T, policy: ToolPolicy): ProtectedTool<T>;
538
+ }>(inner: T, policy: ToolPolicy<Parameters<T["execute"]>[0]>): ProtectedTool<T>;
163
539
  session(input: SessionInput): Session;
164
540
  /** Import a warrant minted elsewhere (Rust / Python / another process). */
165
541
  sessionFromWire(input: SessionFromWireInput): Session;
166
542
  withSession<R>(session: Session, fn: () => R): R;
167
- narrow(session: Session, allow: NarrowInput): Session;
543
+ /**
544
+ * Child session with less authority. Without options the same holder keeps
545
+ * it; with `options.holder` it is delegated to another agent's key. Core
546
+ * rejects any child that is not within its parent before a token exists.
547
+ */
548
+ narrow(session: Session, allow: NarrowInput, options?: NarrowOptions): Session;
549
+ /**
550
+ * Mint an execution session from an issuer session, signed by the issuer
551
+ * session's holder. Core checks tools against `issuableTools`, constraints
552
+ * against `constraintBounds`, clearance, and issue depth. No root key.
553
+ */
554
+ issue(issuer: Session, input: IssueInput): Session;
555
+ /**
556
+ * Public key of the local issuer (dev root or issuer key). Other processes
557
+ * put it in `trustedRoots` to accept warrants this context mints.
558
+ */
559
+ issuerPublicKey(): PublicKeyHandle;
560
+ /** What the session would decide for `tool(args)`, field by field. Never runs the tool. */
561
+ explain(session: Session, tool: string, args: Readonly<Record<string, unknown>>): Explanation;
562
+ /** Everything an approval service needs to present `tool(args)` to a human. */
563
+ approvalRequest(session: Session, tool: string, args: Readonly<Record<string, unknown>>): ApprovalRequest;
564
+ /** Holder-signed proof that this session is the one asking for `tool(args)`. */
565
+ attestApprovalRequest(session: Session, tool: string, args: Readonly<Record<string, unknown>>): ApprovalContextAttestation;
566
+ /** Authorize locally, then produce warrant + proof-of-possession for another boundary to verify. */
567
+ present(session: Session, tool: string, args: Readonly<Record<string, unknown>>, options?: McpAttachOptions): PresentedCall;
568
+ /** Verify a presented call at any boundary. Resolves with the authorized arguments; the tool must not run otherwise. */
569
+ verify(presented: PresentedCall, tool: string, args: Readonly<Record<string, unknown>>, options?: McpVerifyOptions): Promise<Readonly<Record<string, unknown>>>;
570
+ /** Sign a revocation list with this context's issuer key. Load it with `revoke()` where this issuer is trusted. */
571
+ revocationList(input: RevocationListInput): string;
168
572
  /** Load a published SignedRevocationList. Rust verifies the issuer against trusted roots. */
169
573
  revoke(list: string | Uint8Array): void;
170
574
  /** MCP `_meta.tenuo` attach / verify. No MCP SDK dependency. */
@@ -173,11 +577,7 @@ export interface Tenuo {
173
577
  }
174
578
  /** Wire envelope Python and TypeScript both read from `params._meta`. */
175
579
  export type TenuoMcpMeta = {
176
- readonly tenuo: {
177
- readonly warrant: string;
178
- readonly signature: string;
179
- readonly approvals?: readonly string[];
180
- };
580
+ readonly tenuo: PresentedCall;
181
581
  };
182
582
  export type McpAttachOptions = {
183
583
  readonly approvals?: readonly (string | Uint8Array)[];
@@ -267,4 +667,3 @@ export interface TenuoMcp {
267
667
  jsonRpcError(error: unknown): McpJsonRpcError;
268
668
  }
269
669
  export {};
270
- //# sourceMappingURL=api.d.ts.map