@tenuo/core 0.2.5-beta.0 → 0.3.1-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 (52) hide show
  1. package/README.md +18 -6
  2. package/dist/api.d.ts +32 -5
  3. package/dist/api.js.map +1 -1
  4. package/dist/build-info.json +8 -0
  5. package/dist/client.d.ts +7 -1
  6. package/dist/client.js +32 -22
  7. package/dist/client.js.map +1 -1
  8. package/dist/connect.d.ts +53 -0
  9. package/dist/connect.js +177 -0
  10. package/dist/connect.js.map +1 -0
  11. package/dist/constraints.d.ts +29 -2
  12. package/dist/constraints.js +68 -19
  13. package/dist/constraints.js.map +1 -1
  14. package/dist/errors.d.ts +0 -1
  15. package/dist/errors.js.map +1 -1
  16. package/dist/generated/tenuo_wasm.d.ts +31 -4
  17. package/dist/generated/tenuo_wasm.js +65 -4
  18. package/dist/generated/tenuo_wasm_bg.wasm +0 -0
  19. package/dist/generated/tenuo_wasm_bg.wasm.d.ts +3 -0
  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 +3 -4
  27. package/dist/mcp.js +11 -20
  28. package/dist/mcp.js.map +1 -1
  29. package/dist/nonce.d.ts +0 -1
  30. package/dist/nonce.js.map +1 -1
  31. package/dist/receipts.d.ts +27 -0
  32. package/dist/receipts.js +128 -0
  33. package/dist/receipts.js.map +1 -0
  34. package/dist/runtime.d.ts +51 -0
  35. package/dist/runtime.js +102 -0
  36. package/dist/runtime.js.map +1 -0
  37. package/dist/session.d.ts +7 -1
  38. package/dist/session.js +14 -0
  39. package/dist/session.js.map +1 -1
  40. package/dist/wasm.d.ts +49 -4
  41. package/dist/wasm.js +53 -6
  42. package/dist/wasm.js.map +1 -1
  43. package/package.json +2 -2
  44. package/dist/api.d.ts.map +0 -1
  45. package/dist/client.d.ts.map +0 -1
  46. package/dist/constraints.d.ts.map +0 -1
  47. package/dist/errors.d.ts.map +0 -1
  48. package/dist/index.d.ts.map +0 -1
  49. package/dist/mcp.d.ts.map +0 -1
  50. package/dist/nonce.d.ts.map +0 -1
  51. package/dist/session.d.ts.map +0 -1
  52. package/dist/wasm.d.ts.map +0 -1
package/dist/mcp.js CHANGED
@@ -1,18 +1,19 @@
1
1
  import { AuthorizationDeniedError, TenuoConfigurationError, TenuoError } from "./errors.js";
2
+ import { collectReceipt, emitIsolatedReceipt } from "./receipts.js";
2
3
  import { nativeSession } from "./session.js";
3
4
  /**
4
5
  * Transport-agnostic half of `attach`: authorize locally, then sign
5
6
  * proof-of-possession over the call. Shared by `tenuo.present()` and
6
7
  * `tenuo.mcp.attach()`.
7
8
  */
8
- export function presentCall(context, decide, session, name, args, options, label) {
9
+ export function presentCall(context, decide, session, name, args, options, label, host) {
9
10
  if (options !== undefined) {
10
11
  assertKnownKeys(options, ATTACH_OPTION_KEYS, `${label} options`);
11
12
  }
12
13
  const native = nativeSession(session);
13
14
  const wireArgs = stripNulls(args);
14
15
  const local = context.authorize(native, name, wireArgs, options?.approvals, undefined, options?.requestId);
15
- emitReceipt(options?.onReceipt, local.receipt);
16
+ emitReceipt(options?.onReceipt, local.receipt, session, host);
16
17
  decide(local, name, native, wireArgs);
17
18
  const signature = context.signPop(native, name, wireArgs);
18
19
  const warrant = stackWire(native);
@@ -29,7 +30,7 @@ export function presentCall(context, decide, session, name, args, options, label
29
30
  * proof-of-possession, then apply the host ceiling. Shared by
30
31
  * `tenuo.verify()` and `tenuo.mcp.verify()`.
31
32
  */
32
- export async function verifyPresented(context, decide, presented, name, args, options, label) {
33
+ export async function verifyPresented(context, decide, presented, name, args, options, label, host) {
33
34
  if (options !== undefined) {
34
35
  assertKnownKeys(options, VERIFY_OPTION_KEYS, `${label} options`);
35
36
  }
@@ -40,17 +41,17 @@ export async function verifyPresented(context, decide, presented, name, args, op
40
41
  const decision = context.authorizePresented(envelope.warrant, name, stripNulls(args), envelope.signature, envelope.approvals, options?.allow, options?.requestId);
41
42
  // Rust already signed this envelope. Emit before the nonce store can
42
43
  // refuse a replay — otherwise an attacker leaves no audit artifact.
43
- emitReceipt(options?.onReceipt, decision.receipt);
44
+ emitReceipt(options?.onReceipt, decision.receipt, undefined, host);
44
45
  if (decision.outcome === "allow") {
45
46
  await admitPop(options?.nonceStore, envelope.signature, options?.onNonceStoreError);
46
47
  }
47
48
  decide(decision, name);
48
49
  return plainArgs(decision.args);
49
50
  }
50
- export function createMcp(context, decide) {
51
+ export function createMcp(context, decide, host) {
51
52
  const mcp = {
52
53
  attach(session, name, args, options) {
53
- const { presented, wireArgs } = presentCall(context, decide, session, name, args, options, "mcp.attach()");
54
+ const { presented, wireArgs } = presentCall(context, decide, session, name, args, options, "mcp.attach()", host);
54
55
  return { name, arguments: wireArgs, _meta: { tenuo: presented } };
55
56
  },
56
57
  async verify(name, args, meta, options) {
@@ -58,7 +59,7 @@ export function createMcp(context, decide) {
58
59
  if (envelope === undefined) {
59
60
  throw new TenuoConfigurationError("MCP call is missing _meta.tenuo. The client must call tenuo.mcp.attach().");
60
61
  }
61
- return verifyPresented(context, decide, envelope, name, args, options, "mcp.verify()");
62
+ return verifyPresented(context, decide, envelope, name, args, options, "mcp.verify()", host);
62
63
  },
63
64
  handler(name, policyOrExecute, maybeExecute) {
64
65
  const policy = isHandlerPolicy(policyOrExecute) ? policyOrExecute : undefined;
@@ -209,19 +210,9 @@ function emitIsolated(hook, error) {
209
210
  function isThenable(value) {
210
211
  return value !== null && typeof value === "object" && "then" in value && typeof value.then === "function";
211
212
  }
212
- function emitReceipt(onReceipt, receipt) {
213
- if (onReceipt === undefined || receipt === undefined) {
214
- return;
215
- }
216
- try {
217
- const result = onReceipt(receipt);
218
- if (isThenable(result)) {
219
- void Promise.resolve(result).catch(() => undefined);
220
- }
221
- }
222
- catch {
223
- // Receipt hooks must not deny or fail the tool.
224
- }
213
+ function emitReceipt(onReceipt, receipt, session, host) {
214
+ collectReceipt(receipt, session, host);
215
+ emitIsolatedReceipt(onReceipt, receipt);
225
216
  }
226
217
  function plainArgs(value) {
227
218
  if (value instanceof Map) {
package/dist/mcp.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mcp.js","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC5F,OAAO,EAAE,aAAa,EAAgB,MAAM,cAAc,CAAC;AAK3D;;;;GAIG;AACH,MAAM,UAAU,WAAW,CACzB,OAAoB,EACpB,MAAc,EACd,OAAwB,EACxB,IAAY,EACZ,IAAuC,EACvC,OAAqC,EACrC,KAAa;IAEb,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,eAAe,CAAC,OAAO,EAAE,kBAAkB,EAAE,GAAG,KAAK,UAAU,CAAC,CAAC;IACnE,CAAC;IACD,MAAM,MAAM,GAAG,aAAa,CAAC,OAAkB,CAAC,CAAC;IACjD,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAC7B,MAAM,EACN,IAAI,EACJ,QAAQ,EACR,OAAO,EAAE,SAAS,EAClB,SAAS,EACT,OAAO,EAAE,SAAS,CACnB,CAAC;IACF,WAAW,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC/C,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IACtC,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;IAClC,IAAI,OAAO,EAAE,SAAS,KAAK,SAAS,IAAI,OAAO,CAAC,SAAS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AA8C,CAAC,CAAC;IACpF,CAAC;IACD,MAAM,OAAO,GAAc,EAAE,CAAC;IAC9B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACxC,SAAS;QACX,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;QAChC,MAAM,IAAI,GAAmB,KAAK,CAAC,IAAI,CAAC;QACxC,MAAM,GAAG,GAAG,IAAI,KAAK,yBAAyB,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,wBAAwB,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAC9G,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IAC1E,CAAC;IACD,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,OAAO,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import type {\n McpAttachOptions,\n McpCallParams,\n McpHandlerPolicy,\n McpJsonRpcError,\n McpVerifyOptions,\n PresentedCall,\n Session as SessionContract,\n TenuoErrorCode,\n TenuoMcp,\n} from \"./api.ts\";\nimport { AuthorizationDeniedError, TenuoConfigurationError, TenuoError } from \"./errors.ts\";\nimport { collectReceipt, emitIsolatedReceipt } from \"./receipts.ts\";\nimport { nativeSession, type Session } from \"./session.ts\";\nimport type { WasmContext, WasmDecision } from \"./wasm.ts\";\n\nexport type Decide = (decision: WasmDecision, tool: string, native?: object, args?: Record<string, unknown>) => void;\n\n/**\n * Transport-agnostic half of `attach`: authorize locally, then sign\n * proof-of-possession over the call. Shared by `tenuo.present()` and\n * `tenuo.mcp.attach()`.\n */\nexport function presentCall(\n context: WasmContext,\n decide: Decide,\n session: SessionContract,\n name: string,\n args: Readonly<Record<string, unknown>>,\n options: McpAttachOptions | undefined,\n label: string,\n host?: object,\n): { readonly presented: PresentedCall; readonly wireArgs: Record<string, unknown> } {\n if (options !== undefined) {\n assertKnownKeys(options, ATTACH_OPTION_KEYS, `${label} options`);\n }\n const native = nativeSession(session as Session);\n const wireArgs = stripNulls(args);\n const local = context.authorize(\n native,\n name,\n wireArgs,\n options?.approvals,\n undefined,\n options?.requestId,\n );\n emitReceipt(options?.onReceipt, local.receipt, session, host);\n decide(local, name, native, wireArgs);\n const signature = context.signPop(native, name, wireArgs);\n const warrant = stackWire(native);\n if (options?.approvals !== undefined && options.approvals.length > 0) {\n return {\n presented: { warrant, signature, approvals: options.approvals.map(approvalWire) },\n wireArgs,\n };\n }\n return { presented: { warrant, signature }, wireArgs };\n}\n\n/**\n * Transport-agnostic half of `verify`: check a presented warrant chain and\n * proof-of-possession, then apply the host ceiling. Shared by\n * `tenuo.verify()` and `tenuo.mcp.verify()`.\n */\nexport async function verifyPresented(\n context: WasmContext,\n decide: Decide,\n presented: PresentedCall,\n name: string,\n args: Readonly<Record<string, unknown>>,\n options: McpVerifyOptions | undefined,\n label: string,\n host?: object,\n): Promise<Readonly<Record<string, unknown>>> {\n if (options !== undefined) {\n assertKnownKeys(options, VERIFY_OPTION_KEYS, `${label} options`);\n }\n const envelope = presentedEnvelope(presented);\n if (envelope === undefined) {\n throw new TenuoConfigurationError(\n `${label} needs { warrant, signature } from tenuo.present() or tenuo.mcp.attach()`,\n );\n }\n const decision = context.authorizePresented(\n envelope.warrant,\n name,\n stripNulls(args),\n envelope.signature,\n envelope.approvals,\n options?.allow,\n options?.requestId,\n );\n // Rust already signed this envelope. Emit before the nonce store can\n // refuse a replay — otherwise an attacker leaves no audit artifact.\n emitReceipt(options?.onReceipt, decision.receipt, undefined, host);\n if (decision.outcome === \"allow\") {\n await admitPop(options?.nonceStore, envelope.signature, options?.onNonceStoreError);\n }\n decide(decision, name);\n return plainArgs(decision.args);\n}\n\nexport function createMcp(context: WasmContext, decide: Decide, host?: object): TenuoMcp {\n const mcp: TenuoMcp = {\n attach(session, name, args, options) {\n const { presented, wireArgs } = presentCall(\n context,\n decide,\n session,\n name,\n args,\n options,\n \"mcp.attach()\",\n host,\n );\n return { name, arguments: wireArgs, _meta: { tenuo: presented } };\n },\n\n async verify(name, args, meta, options) {\n const envelope = tenuoEnvelope(meta);\n if (envelope === undefined) {\n throw new TenuoConfigurationError(\n \"MCP call is missing _meta.tenuo. The client must call tenuo.mcp.attach().\",\n );\n }\n return verifyPresented(context, decide, envelope, name, args, options, \"mcp.verify()\", host);\n },\n\n handler(name, policyOrExecute, maybeExecute?) {\n const policy = isHandlerPolicy(policyOrExecute) ? policyOrExecute : undefined;\n const execute = isHandlerPolicy(policyOrExecute) ? maybeExecute : policyOrExecute;\n if (typeof execute !== \"function\") {\n throw new TenuoConfigurationError(\"mcp.handler() requires an execute function\");\n }\n return async (args, extra) => {\n const authorized = await mcp.verify(name, args, extra?._meta ?? extra?.meta, {\n ...(policy?.allow !== undefined ? { allow: policy.allow } : {}),\n ...(policy?.onReceipt !== undefined ? { onReceipt: policy.onReceipt } : {}),\n ...(policy?.nonceStore !== undefined ? { nonceStore: policy.nonceStore } : {}),\n ...(policy?.onNonceStoreError !== undefined ? { onNonceStoreError: policy.onNonceStoreError } : {}),\n });\n return execute(authorized as never);\n };\n },\n\n jsonRpcError(error) {\n return jsonRpcError(error);\n },\n };\n return mcp;\n}\n\nfunction stackWire(native: object): string {\n const session = native as { toStackWire?: () => unknown };\n if (typeof session.toStackWire !== \"function\") {\n throw new TenuoConfigurationError(\"session is not bound to the WASM core\");\n }\n const wire = session.toStackWire();\n if (typeof wire !== \"string\" || wire.length === 0) {\n throw new TenuoConfigurationError(\"toStackWire() did not return a warrant stack\");\n }\n return wire;\n}\n\nfunction approvalWire(value: string | Uint8Array): string {\n if (typeof value === \"string\") {\n return value;\n }\n return Buffer.from(value).toString(\"base64\");\n}\n\nfunction presentedEnvelope(\n value: unknown,\n): { warrant: string; signature: string; approvals?: string[] } | undefined {\n if (value === null || typeof value !== \"object\") {\n return undefined;\n }\n const tenuo = value as { warrant?: unknown; signature?: unknown; approvals?: unknown };\n if (typeof tenuo.warrant !== \"string\" || tenuo.warrant.length === 0) {\n return undefined;\n }\n if (typeof tenuo.signature !== \"string\" || tenuo.signature.length === 0) {\n return undefined;\n }\n const approvals = Array.isArray(tenuo.approvals)\n ? tenuo.approvals.filter((item): item is string => typeof item === \"string\")\n : undefined;\n return {\n warrant: tenuo.warrant,\n signature: tenuo.signature,\n ...(approvals !== undefined && approvals.length > 0 ? { approvals } : {}),\n };\n}\n\nfunction tenuoEnvelope(\n meta: unknown,\n): { warrant: string; signature: string; approvals?: string[] } | undefined {\n if (meta === null || typeof meta !== \"object\") {\n return undefined;\n }\n const root = meta as { tenuo?: unknown; _meta?: unknown };\n const block = root.tenuo ?? (root._meta as { tenuo?: unknown } | undefined)?.tenuo;\n return presentedEnvelope(block);\n}\n\nconst HANDLER_POLICY_KEYS = new Set([\"allow\", \"onReceipt\", \"nonceStore\", \"onNonceStoreError\"]);\nconst VERIFY_OPTION_KEYS = new Set([\n \"allow\",\n \"onReceipt\",\n \"nonceStore\",\n \"onNonceStoreError\",\n \"requestId\",\n]);\nconst REPLAY_STORE_UNAVAILABLE = \"Replay store unavailable\";\nconst ATTACH_OPTION_KEYS = new Set([\"approvals\", \"onReceipt\", \"requestId\"]);\nconst MAX_STRIP_DEPTH = 32;\nconst MAX_STRIP_LEN = 1024;\n\nfunction assertKnownKeys(value: object, known: ReadonlySet<string>, label: string): void {\n const unknown = Object.keys(value).filter((key) => !known.has(key));\n if (unknown[0] !== undefined) {\n throw new TenuoConfigurationError(\n `${label} has unknown key '${unknown[0]}'. Use ${[...known].join(\", \")}.`,\n );\n }\n}\n\nfunction isHandlerPolicy(value: unknown): value is McpHandlerPolicy {\n if (value === null || typeof value !== \"object\" || Array.isArray(value) || typeof value === \"function\") {\n return false;\n }\n const keys = Object.keys(value);\n assertKnownKeys(value, HANDLER_POLICY_KEYS, \"mcp.handler() policy\");\n const record = value as {\n allow?: unknown;\n onReceipt?: unknown;\n nonceStore?: unknown;\n onNonceStoreError?: unknown;\n };\n const hasAllow =\n \"allow\" in record && record.allow !== null && typeof record.allow === \"object\" && !Array.isArray(record.allow);\n const hasReceipt = \"onReceipt\" in record && typeof record.onReceipt === \"function\";\n const hasNonce = \"nonceStore\" in record && record.nonceStore !== null && typeof record.nonceStore === \"object\";\n const hasStoreError = \"onNonceStoreError\" in record && typeof record.onNonceStoreError === \"function\";\n return keys.length === 0 || hasAllow || hasReceipt || hasNonce || hasStoreError;\n}\n\nasync function admitPop(\n store: { checkAndRecord(popSignature: string): boolean | Promise<boolean> } | undefined,\n signature: string,\n onNonceStoreError?: (error: unknown) => void | Promise<void>,\n): Promise<void> {\n if (store === undefined) {\n return;\n }\n let admitted: boolean | Promise<boolean>;\n try {\n admitted = store.checkAndRecord(signature);\n } catch (error) {\n throw replayStoreUnavailable(error, onNonceStoreError);\n }\n if (isThenable(admitted)) {\n try {\n admitted = await admitted;\n } catch (error) {\n throw replayStoreUnavailable(error, onNonceStoreError);\n }\n }\n if (typeof admitted !== \"boolean\") {\n throw replayStoreUnavailable(\n new TenuoConfigurationError(\"NonceStore.checkAndRecord() must return boolean or Promise<boolean>\"),\n onNonceStoreError,\n );\n }\n if (!admitted) {\n throw new AuthorizationDeniedError(\n \"TENUO_INVALID_POP\",\n \"PoP replay detected — this exact authorization token was already consumed.\",\n );\n }\n}\n\nfunction replayStoreUnavailable(\n cause: unknown,\n onNonceStoreError?: (error: unknown) => void | Promise<void>,\n): TenuoConfigurationError {\n emitIsolated(onNonceStoreError, cause);\n const error = new TenuoConfigurationError(REPLAY_STORE_UNAVAILABLE);\n if (cause !== undefined) {\n error.cause = cause;\n }\n return error;\n}\n\nfunction emitIsolated(\n hook: ((error: unknown) => void | Promise<void>) | undefined,\n error: unknown,\n): void {\n if (hook === undefined) {\n return;\n }\n try {\n const result = hook(error);\n if (isThenable(result)) {\n void Promise.resolve(result).catch(() => undefined);\n }\n } catch {\n // Isolated — must not change the public error.\n }\n}\n\nfunction isThenable(value: unknown): value is Promise<boolean> {\n return value !== null && typeof value === \"object\" && \"then\" in value && typeof value.then === \"function\";\n}\n\nfunction emitReceipt(\n onReceipt: ((receipt: string) => void | Promise<void>) | undefined,\n receipt: string | undefined,\n session?: SessionContract,\n host?: object,\n): void {\n collectReceipt(receipt, session, host);\n emitIsolatedReceipt(onReceipt, receipt);\n}\n\nfunction plainArgs(value: unknown): Record<string, unknown> {\n if (value instanceof Map) {\n return Object.fromEntries(value);\n }\n if (value !== null && typeof value === \"object\" && !Array.isArray(value)) {\n return { ...(value as Record<string, unknown>) };\n }\n return {};\n}\n\n/** Same rule as Python `strip_none_values`: drop null so optional MCP args do not break PoP. */\nfunction stripNulls(args: Readonly<Record<string, unknown>>): Record<string, unknown> {\n const keys = Object.keys(args);\n if (keys.length > MAX_STRIP_LEN) {\n throw new TenuoConfigurationError(\"arguments exceed the TypeScript input budget\");\n }\n const out: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(args)) {\n if (value === null || value === undefined) {\n continue;\n }\n out[key] = Array.isArray(value) ? cleanList(value, 1) : value;\n }\n return out;\n}\n\nfunction cleanList(value: readonly unknown[], depth: number): unknown[] {\n if (depth > MAX_STRIP_DEPTH) {\n throw new TenuoConfigurationError(\"arguments exceed the TypeScript nesting budget\");\n }\n if (value.length > MAX_STRIP_LEN) {\n throw new TenuoConfigurationError(\"arguments exceed the TypeScript input budget\");\n }\n const cleaned: unknown[] = [];\n for (const item of value) {\n if (item === null || item === undefined) {\n continue;\n }\n cleaned.push(Array.isArray(item) ? cleanList(item, depth + 1) : item);\n }\n return cleaned;\n}\n\nfunction jsonRpcError(error: unknown): McpJsonRpcError {\n if (error instanceof TenuoError) {\n const code: TenuoErrorCode = error.code;\n const rpc = code === \"TENUO_APPROVAL_REQUIRED\" ? -32002 : code === \"TENUO_CANONICALIZATION\" ? -32602 : -32001;\n return { code: rpc, message: error.message, data: { tenuo: { code } } };\n }\n const message = error instanceof Error ? error.message : String(error);\n return { code: -32001, message };\n}\n"]}
package/dist/nonce.d.ts CHANGED
@@ -14,4 +14,3 @@ import type { NonceStore } from "./api.ts";
14
14
  export declare function memoryNonceStore(options?: {
15
15
  readonly ttlSeconds?: number;
16
16
  }): NonceStore;
17
- //# sourceMappingURL=nonce.d.ts.map
package/dist/nonce.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"nonce.js","sourceRoot":"","sources":["../src/nonce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAA0C;IACzE,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,GAAG,CAAC;IAC9C,MAAM,KAAK,GAAG,UAAU,GAAG,IAAI,CAAC;IAChC,IAAI,UAAU,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/E,MAAM,IAAI,uBAAuB,CAC/B,2FAA2F,CAC5F,CAAC;IACJ,CAAC;IACD,MAAM,IAAI,GAAG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EAAkB,CAAC;IACvC,OAAO;QACL,cAAc,CAAC,YAAoB;YACjC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACvB,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;gBACjC,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;oBAClB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBACnB,CAAC;YACH,CAAC;YACD,MAAM,GAAG,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACpE,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBAClB,OAAO,KAAK,CAAC;YACf,CAAC;YACD,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,KAAK,CAAC,CAAC;YAC3B,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { NonceStore } from \"./api.ts\";\nimport { TenuoConfigurationError } from \"./errors.ts\";\n\n/**\n * In-process PoP replay store. Same shape as Python `NonceStore`.\n * Not on by default. Does not work across processes — implement\n * `NonceStore` with an async Redis `checkAndRecord` (return\n * `Promise<boolean>`). A rejected Promise fails closed.\n *\n * `ttlSeconds` defaults to 180 and must be greater than zero and finite.\n * Values too large to convert to milliseconds are also rejected.\n *\n * @throws {TenuoConfigurationError} If `ttlSeconds` is not a supported\n * positive, finite duration.\n */\nexport function memoryNonceStore(options?: { readonly ttlSeconds?: number }): NonceStore {\n const ttlSeconds = options?.ttlSeconds ?? 180;\n const ttlMs = ttlSeconds * 1000;\n if (ttlSeconds <= 0 || !Number.isFinite(ttlSeconds) || !Number.isFinite(ttlMs)) {\n throw new TenuoConfigurationError(\n \"memoryNonceStore() ttlSeconds must be positive, finite, and representable in milliseconds\",\n );\n }\n const seen = new Map<string, number>();\n return {\n checkAndRecord(popSignature: string): boolean {\n const now = Date.now();\n for (const [key, expiry] of seen) {\n if (expiry <= now) {\n seen.delete(key);\n }\n }\n const key = createHash(\"sha256\").update(popSignature).digest(\"hex\");\n if (seen.has(key)) {\n return false;\n }\n seen.set(key, now + ttlMs);\n return true;\n },\n };\n}\n"]}
@@ -0,0 +1,27 @@
1
+ import type { Session as SessionContract } from "./api.ts";
2
+ /**
3
+ * In-memory receipt buffer containing only unacknowledged receipts.
4
+ *
5
+ * Delivery: receipts are appended in emission order. `peek()` and `drain()`
6
+ * are the same non-consuming snapshot. Only `acknowledge()` removes items.
7
+ */
8
+ export declare class ReceiptCollector {
9
+ #private;
10
+ constructor(max?: number);
11
+ get overflowed(): number;
12
+ push(receipt: string): void;
13
+ peek(): string[];
14
+ drain(): string[];
15
+ acknowledge(count: number): number;
16
+ /** Remove receipts by wire identity, preserving remaining order. */
17
+ removeMatching(wires: readonly string[]): number;
18
+ }
19
+ export declare function bindSessionCollector(session: object, collector: ReceiptCollector, host?: ReceiptCollector): void;
20
+ /** Derived sessions share the parent's outbox so acknowledge frees both. */
21
+ export declare function inheritSessionCollector(parent: object, child: object): void;
22
+ export declare function bindHostCollector(host: object, collector: ReceiptCollector): void;
23
+ export declare function sessionCollector(session: object | undefined): ReceiptCollector | undefined;
24
+ export declare function hostCollector(host: object | undefined): ReceiptCollector | undefined;
25
+ export declare function linkedHostCollector(session: object | undefined): ReceiptCollector | undefined;
26
+ export declare function collectReceipt(receipt: string | undefined, session?: SessionContract, host?: object): void;
27
+ export declare function emitIsolatedReceipt(onReceipt: ((receipt: string) => void | Promise<void>) | undefined, receipt: string | undefined): void;
@@ -0,0 +1,128 @@
1
+ /**
2
+ * In-memory receipt buffer containing only unacknowledged receipts.
3
+ *
4
+ * Delivery: receipts are appended in emission order. `peek()` and `drain()`
5
+ * are the same non-consuming snapshot. Only `acknowledge()` removes items.
6
+ */
7
+ export class ReceiptCollector {
8
+ #items = [];
9
+ #max;
10
+ #overflowed = 0;
11
+ constructor(max = 10_000) {
12
+ this.#max = Number.isInteger(max) && max > 0 ? max : 10_000;
13
+ }
14
+ get overflowed() {
15
+ return this.#overflowed;
16
+ }
17
+ push(receipt) {
18
+ if (this.#items.length >= this.#max) {
19
+ this.#overflowed += 1;
20
+ return;
21
+ }
22
+ this.#items.push(receipt);
23
+ }
24
+ peek() {
25
+ return [...this.#items];
26
+ }
27
+ drain() {
28
+ return this.peek();
29
+ }
30
+ acknowledge(count) {
31
+ if (!Number.isInteger(count) || count < 0) {
32
+ return 0;
33
+ }
34
+ const n = Math.min(count, this.#items.length);
35
+ this.#items.splice(0, n);
36
+ return n;
37
+ }
38
+ /** Remove receipts by wire identity, preserving remaining order. */
39
+ removeMatching(wires) {
40
+ if (wires.length === 0) {
41
+ return 0;
42
+ }
43
+ const drop = new Set(wires);
44
+ const kept = [];
45
+ let removed = 0;
46
+ for (const item of this.#items) {
47
+ if (drop.has(item)) {
48
+ removed += 1;
49
+ }
50
+ else {
51
+ kept.push(item);
52
+ }
53
+ }
54
+ this.#items.length = 0;
55
+ this.#items.push(...kept);
56
+ return removed;
57
+ }
58
+ }
59
+ const sessionCollectors = new WeakMap();
60
+ const hostCollectors = new WeakMap();
61
+ const linkedHostCollectors = new WeakMap();
62
+ export function bindSessionCollector(session, collector, host) {
63
+ sessionCollectors.set(session, collector);
64
+ if (host !== undefined) {
65
+ linkedHostCollectors.set(session, host);
66
+ }
67
+ }
68
+ /** Derived sessions share the parent's outbox so acknowledge frees both. */
69
+ export function inheritSessionCollector(parent, child) {
70
+ const parentCollector = sessionCollectors.get(parent);
71
+ if (parentCollector !== undefined) {
72
+ sessionCollectors.set(child, parentCollector);
73
+ }
74
+ const host = linkedHostCollectors.get(parent);
75
+ if (host !== undefined) {
76
+ linkedHostCollectors.set(child, host);
77
+ }
78
+ }
79
+ export function bindHostCollector(host, collector) {
80
+ hostCollectors.set(host, collector);
81
+ }
82
+ export function sessionCollector(session) {
83
+ if (session === undefined) {
84
+ return undefined;
85
+ }
86
+ return sessionCollectors.get(session);
87
+ }
88
+ export function hostCollector(host) {
89
+ if (host === undefined) {
90
+ return undefined;
91
+ }
92
+ return hostCollectors.get(host);
93
+ }
94
+ export function linkedHostCollector(session) {
95
+ if (session === undefined) {
96
+ return undefined;
97
+ }
98
+ return linkedHostCollectors.get(session);
99
+ }
100
+ export function collectReceipt(receipt, session, host) {
101
+ if (receipt === undefined) {
102
+ return;
103
+ }
104
+ sessionCollector(session)?.push(receipt);
105
+ const linked = linkedHostCollector(session);
106
+ const hosted = hostCollector(host);
107
+ if (linked !== undefined) {
108
+ linked.push(receipt);
109
+ }
110
+ if (hosted !== undefined && hosted !== linked) {
111
+ hosted.push(receipt);
112
+ }
113
+ }
114
+ export function emitIsolatedReceipt(onReceipt, receipt) {
115
+ if (onReceipt === undefined || receipt === undefined) {
116
+ return;
117
+ }
118
+ try {
119
+ const result = onReceipt(receipt);
120
+ if (result !== null && typeof result === "object" && "then" in result && typeof result.then === "function") {
121
+ void Promise.resolve(result).catch(() => undefined);
122
+ }
123
+ }
124
+ catch {
125
+ // Explicit onReceipt remains isolated. Collectors are sync and do not use this path.
126
+ }
127
+ }
128
+ //# sourceMappingURL=receipts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"receipts.js","sourceRoot":"","sources":["../src/receipts.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IAClB,MAAM,GAAa,EAAE,CAAC;IACtB,IAAI,CAAS;IACtB,WAAW,GAAG,CAAC,CAAC;IAEhB,YAAY,GAAG,GAAG,MAAM;QACtB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC;IAC9D,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,IAAI,CAAC,O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MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAC3G,KAAK,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,qFAAqF;IACvF,CAAC;AACH,CAAC","sourcesContent":["import type { Session as SessionContract } from \"./api.ts\";\n\n/**\n * In-memory receipt buffer containing only unacknowledged receipts.\n *\n * Delivery: receipts are appended in emission order. `peek()` and `drain()`\n * are the same non-consuming snapshot. Only `acknowledge()` removes items.\n */\nexport class ReceiptCollector {\n readonly #items: string[] = [];\n readonly #max: number;\n #overflowed = 0;\n\n constructor(max = 10_000) {\n this.#max = Number.isInteger(max) && max > 0 ? max : 10_000;\n }\n\n get overflowed(): number {\n return this.#overflowed;\n }\n\n push(receipt: string): void {\n if (this.#items.length >= this.#max) {\n this.#overflowed += 1;\n return;\n }\n this.#items.push(receipt);\n }\n\n peek(): string[] {\n return [...this.#items];\n }\n\n drain(): string[] {\n return this.peek();\n }\n\n acknowledge(count: number): number {\n if (!Number.isInteger(count) || count < 0) {\n return 0;\n }\n const n = Math.min(count, this.#items.length);\n this.#items.splice(0, n);\n return n;\n }\n\n /** Remove receipts by wire identity, preserving remaining order. */\n removeMatching(wires: readonly string[]): number {\n if (wires.length === 0) {\n return 0;\n }\n const drop = new Set(wires);\n const kept: string[] = [];\n let removed = 0;\n for (const item of this.#items) {\n if (drop.has(item)) {\n removed += 1;\n } else {\n kept.push(item);\n }\n }\n this.#items.length = 0;\n this.#items.push(...kept);\n return removed;\n }\n}\n\nconst sessionCollectors = new WeakMap<object, ReceiptCollector>();\nconst hostCollectors = new WeakMap<object, ReceiptCollector>();\nconst linkedHostCollectors = new WeakMap<object, ReceiptCollector>();\n\nexport function bindSessionCollector(\n session: object,\n collector: ReceiptCollector,\n host?: ReceiptCollector,\n): void {\n sessionCollectors.set(session, collector);\n if (host !== undefined) {\n linkedHostCollectors.set(session, host);\n }\n}\n\n/** Derived sessions share the parent's outbox so acknowledge frees both. */\nexport function inheritSessionCollector(parent: object, child: object): void {\n const parentCollector = sessionCollectors.get(parent);\n if (parentCollector !== undefined) {\n sessionCollectors.set(child, parentCollector);\n }\n const host = linkedHostCollectors.get(parent);\n if (host !== undefined) {\n linkedHostCollectors.set(child, host);\n }\n}\n\nexport function bindHostCollector(host: object, collector: ReceiptCollector): void {\n hostCollectors.set(host, collector);\n}\n\nexport function sessionCollector(session: object | undefined): ReceiptCollector | undefined {\n if (session === undefined) {\n return undefined;\n }\n return sessionCollectors.get(session);\n}\n\nexport function hostCollector(host: object | undefined): ReceiptCollector | undefined {\n if (host === undefined) {\n return undefined;\n }\n return hostCollectors.get(host);\n}\n\nexport function linkedHostCollector(session: object | undefined): ReceiptCollector | undefined {\n if (session === undefined) {\n return undefined;\n }\n return linkedHostCollectors.get(session);\n}\n\nexport function collectReceipt(\n receipt: string | undefined,\n session?: SessionContract,\n host?: object,\n): void {\n if (receipt === undefined) {\n return;\n }\n sessionCollector(session)?.push(receipt);\n const linked = linkedHostCollector(session);\n const hosted = hostCollector(host);\n if (linked !== undefined) {\n linked.push(receipt);\n }\n if (hosted !== undefined && hosted !== linked) {\n hosted.push(receipt);\n }\n}\n\nexport function emitIsolatedReceipt(\n onReceipt: ((receipt: string) => void | Promise<void>) | undefined,\n receipt: string | undefined,\n): void {\n if (onReceipt === undefined || receipt === undefined) {\n return;\n }\n try {\n const result = onReceipt(receipt);\n if (result !== null && typeof result === \"object\" && \"then\" in result && typeof result.then === \"function\") {\n void Promise.resolve(result).catch(() => undefined);\n }\n } catch {\n // Explicit onReceipt remains isolated. Collectors are sync and do not use this path.\n }\n}\n"]}
@@ -0,0 +1,51 @@
1
+ import type { PublicKeyHandle, Session, Tenuo, WarrantPart } from "./api.ts";
2
+ import type { HolderIdentity } from "./identity.ts";
3
+ export type ReceiptsMode = "collect" | "off";
4
+ export type RuntimeOptions = {
5
+ readonly identity: HolderIdentity;
6
+ readonly trustedRoots: readonly PublicKeyHandle[];
7
+ /** Published SignedRevocationList. Fetching it is the caller's job. */
8
+ readonly revocationList?: string | Uint8Array;
9
+ /**
10
+ * `collect` retains receipts produced through this runtime's sessions
11
+ * (tools, present, MCP attach) and through this runtime's tenuo
12
+ * (verify, MCP verify/handler) until `acknowledgeReceipts()`.
13
+ * `drainReceipts()` is a snapshot. Default `off`.
14
+ */
15
+ readonly receipts?: ReceiptsMode;
16
+ /** Bound on each receipt outbox. Default 10_000. */
17
+ readonly receiptMax?: number;
18
+ };
19
+ export type SessionWarrant = string | readonly string[] | readonly WarrantPart[];
20
+ /**
21
+ * Long-lived holder runtime. Owns identity, trusted roots, the current
22
+ * revocation list, and optional receipt collection. Does not perform
23
+ * network I/O or invent hosted-service defaults.
24
+ */
25
+ export declare class Runtime {
26
+ #private;
27
+ readonly identity: HolderIdentity;
28
+ readonly tenuo: Tenuo;
29
+ constructor(tenuo: Tenuo, identity: HolderIdentity, collect: boolean, max?: number);
30
+ applyRevocationList(list: string | Uint8Array): void;
31
+ sessionFromWire(warrant: SessionWarrant): Session;
32
+ /** Undrained receipts from every session and presented call handled by this runtime. */
33
+ peekReceipts(): string[];
34
+ /**
35
+ * Snapshot of receipts across holder sessions and presented-path
36
+ * verification. Same as `peekReceipts`; nothing is removed until
37
+ * `acknowledgeReceipts`.
38
+ */
39
+ drainReceipts(): string[];
40
+ acknowledgeReceipts(count: number): number;
41
+ /** Receipts dropped because the shared outbox was full. */
42
+ receiptOverflows(): number;
43
+ }
44
+ export declare function createRuntime(createTenuo: (options: {
45
+ trustedRoots: readonly PublicKeyHandle[];
46
+ revocationList?: string | Uint8Array;
47
+ receiptSigner?: Uint8Array;
48
+ }) => Tenuo, options: RuntimeOptions): Runtime;
49
+ export declare function drainSessionReceipts(session: object): string[];
50
+ export declare function peekSessionReceipts(session: object): string[];
51
+ export declare function acknowledgeSessionReceipts(session: object, count: number): number;
@@ -0,0 +1,102 @@
1
+ import { TenuoConfigurationError } from "./errors.js";
2
+ import { bindHostCollector, bindSessionCollector, hostCollector, linkedHostCollector, ReceiptCollector, sessionCollector, } from "./receipts.js";
3
+ /**
4
+ * Long-lived holder runtime. Owns identity, trusted roots, the current
5
+ * revocation list, and optional receipt collection. Does not perform
6
+ * network I/O or invent hosted-service defaults.
7
+ */
8
+ export class Runtime {
9
+ identity;
10
+ tenuo;
11
+ #collect;
12
+ #max;
13
+ #sessionCollectors = [];
14
+ constructor(tenuo, identity, collect, max = 10_000) {
15
+ this.tenuo = tenuo;
16
+ this.identity = identity;
17
+ this.#collect = collect;
18
+ this.#max = max;
19
+ if (collect) {
20
+ bindHostCollector(tenuo, new ReceiptCollector(max));
21
+ }
22
+ }
23
+ applyRevocationList(list) {
24
+ this.tenuo.revoke(list);
25
+ }
26
+ sessionFromWire(warrant) {
27
+ const session = this.tenuo.sessionFromWire({
28
+ warrant,
29
+ holderKey: this.identity.holderKey,
30
+ });
31
+ if (this.#collect) {
32
+ const collector = new ReceiptCollector(this.#max);
33
+ this.#sessionCollectors.push(collector);
34
+ bindSessionCollector(session, collector, hostCollector(this.tenuo));
35
+ }
36
+ return session;
37
+ }
38
+ /** Undrained receipts from every session and presented call handled by this runtime. */
39
+ peekReceipts() {
40
+ return hostCollector(this.tenuo)?.peek() ?? [];
41
+ }
42
+ /**
43
+ * Snapshot of receipts across holder sessions and presented-path
44
+ * verification. Same as `peekReceipts`; nothing is removed until
45
+ * `acknowledgeReceipts`.
46
+ */
47
+ drainReceipts() {
48
+ return this.peekReceipts();
49
+ }
50
+ acknowledgeReceipts(count) {
51
+ const host = hostCollector(this.tenuo);
52
+ if (host === undefined) {
53
+ return 0;
54
+ }
55
+ const taken = host.peek().slice(0, count);
56
+ const removed = host.acknowledge(count);
57
+ const acked = taken.slice(0, removed);
58
+ for (const collector of this.#sessionCollectors) {
59
+ collector.removeMatching(acked);
60
+ }
61
+ return removed;
62
+ }
63
+ /** Receipts dropped because the shared outbox was full. */
64
+ receiptOverflows() {
65
+ return hostCollector(this.tenuo)?.overflowed ?? 0;
66
+ }
67
+ }
68
+ export function createRuntime(createTenuo, options) {
69
+ if (options.trustedRoots.length === 0) {
70
+ throw new TenuoConfigurationError("createTenuo.runtime() requires at least one trusted root.");
71
+ }
72
+ const tenuoOptions = { trustedRoots: options.trustedRoots };
73
+ if (options.revocationList !== undefined) {
74
+ tenuoOptions.revocationList = options.revocationList;
75
+ }
76
+ const tenuo = createTenuo({
77
+ ...tenuoOptions,
78
+ receiptSigner: options.identity.holderKey,
79
+ });
80
+ if (options.receiptMax !== undefined &&
81
+ (!Number.isInteger(options.receiptMax) || options.receiptMax <= 0)) {
82
+ throw new TenuoConfigurationError("createTenuo.runtime() receiptMax must be a positive integer.");
83
+ }
84
+ return new Runtime(tenuo, options.identity, options.receipts === "collect", options.receiptMax ?? 10_000);
85
+ }
86
+ export function drainSessionReceipts(session) {
87
+ return sessionCollector(session)?.drain() ?? [];
88
+ }
89
+ export function peekSessionReceipts(session) {
90
+ return sessionCollector(session)?.peek() ?? [];
91
+ }
92
+ export function acknowledgeSessionReceipts(session, count) {
93
+ const collector = sessionCollector(session);
94
+ if (collector === undefined) {
95
+ return 0;
96
+ }
97
+ const taken = collector.peek().slice(0, count);
98
+ const removed = collector.acknowledge(count);
99
+ linkedHostCollector(session)?.removeMatching(taken.slice(0, removed));
100
+ return removed;
101
+ }
102
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,eAAe,CAAC;AAsBvB;;;;GAIG;A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C;IACH,IACE,OAAO,CAAC,UAAU,KAAK,SAAS;QAChC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC,EAClE,CAAC;QACD,MAAM,IAAI,uBAAuB,CAAC,8DAA8D,CAAC,CAAC;IACpG,CAAC;IACD,OAAO,IAAI,OAAO,CAChB,KAAK,EACL,OAAO,CAAC,QAAQ,EAChB,OAAO,CAAC,QAAQ,KAAK,SAAS,EAC9B,OAAO,CAAC,UAAU,IAAI,MAAM,CAC7B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,OAAe;IAClD,OAAO,gBAAgB,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,OAAe;IACjD,OAAO,gBAAgB,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,OAAe,EAAE,KAAa;IACvE,MAAM,SAAS,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC5C,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC5B,OAAO,CAAC,CAAC;IACX,CAAC;IACD,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAC/C,MAAM,OAAO,GAAG,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAC7C,mBAAmB,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IACtE,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { PublicKeyHandle, Session, Tenuo, WarrantPart } from \"./api.ts\";\nimport { TenuoConfigurationError } from \"./errors.ts\";\nimport type { HolderIdentity } from \"./identity.ts\";\nimport {\n bindHostCollector,\n bindSessionCollector,\n hostCollector,\n linkedHostCollector,\n ReceiptCollector,\n sessionCollector,\n} from \"./receipts.ts\";\n\nexport type ReceiptsMode = \"collect\" | \"off\";\n\nexport type RuntimeOptions = {\n readonly identity: HolderIdentity;\n readonly trustedRoots: readonly PublicKeyHandle[];\n /** Published SignedRevocationList. Fetching it is the caller's job. */\n readonly revocationList?: string | Uint8Array;\n /**\n * `collect` retains receipts produced through this runtime's sessions\n * (tools, present, MCP attach) and through this runtime's tenuo\n * (verify, MCP verify/handler) until `acknowledgeReceipts()`.\n * `drainReceipts()` is a snapshot. Default `off`.\n */\n readonly receipts?: ReceiptsMode;\n /** Bound on each receipt outbox. Default 10_000. */\n readonly receiptMax?: number;\n};\n\nexport type SessionWarrant = string | readonly string[] | readonly WarrantPart[];\n\n/**\n * Long-lived holder runtime. Owns identity, trusted roots, the current\n * revocation list, and optional receipt collection. Does not perform\n * network I/O or invent hosted-service defaults.\n */\nexport class Runtime {\n readonly identity: HolderIdentity;\n readonly tenuo: Tenuo;\n readonly #collect: boolean;\n readonly #max: number;\n readonly #sessionCollectors: ReceiptCollector[] = [];\n\n constructor(\n tenuo: Tenuo,\n identity: HolderIdentity,\n collect: boolean,\n max = 10_000,\n ) {\n this.tenuo = tenuo;\n this.identity = identity;\n this.#collect = collect;\n this.#max = max;\n if (collect) {\n bindHostCollector(tenuo, new ReceiptCollector(max));\n }\n }\n\n applyRevocationList(list: string | Uint8Array): void {\n this.tenuo.revoke(list);\n }\n\n sessionFromWire(warrant: SessionWarrant): Session {\n const session = this.tenuo.sessionFromWire({\n warrant,\n holderKey: this.identity.holderKey,\n });\n if (this.#collect) {\n const collector = new ReceiptCollector(this.#max);\n this.#sessionCollectors.push(collector);\n bindSessionCollector(session, collector, hostCollector(this.tenuo));\n }\n return session;\n }\n\n /** Undrained receipts from every session and presented call handled by this runtime. */\n peekReceipts(): string[] {\n return hostCollector(this.tenuo)?.peek() ?? [];\n }\n\n /**\n * Snapshot of receipts across holder sessions and presented-path\n * verification. Same as `peekReceipts`; nothing is removed until\n * `acknowledgeReceipts`.\n */\n drainReceipts(): string[] {\n return this.peekReceipts();\n }\n\n acknowledgeReceipts(count: number): number {\n const host = hostCollector(this.tenuo);\n if (host === undefined) {\n return 0;\n }\n const taken = host.peek().slice(0, count);\n const removed = host.acknowledge(count);\n const acked = taken.slice(0, removed);\n for (const collector of this.#sessionCollectors) {\n collector.removeMatching(acked);\n }\n return removed;\n }\n\n /** Receipts dropped because the shared outbox was full. */\n receiptOverflows(): number {\n return hostCollector(this.tenuo)?.overflowed ?? 0;\n }\n}\n\nexport function createRuntime(\n createTenuo: (options: {\n trustedRoots: readonly PublicKeyHandle[];\n revocationList?: string | Uint8Array;\n receiptSigner?: Uint8Array;\n }) => Tenuo,\n options: RuntimeOptions,\n): Runtime {\n if (options.trustedRoots.length === 0) {\n throw new TenuoConfigurationError(\n \"createTenuo.runtime() requires at least one trusted root.\",\n );\n }\n const tenuoOptions: {\n trustedRoots: readonly PublicKeyHandle[];\n revocationList?: string | Uint8Array;\n receiptSigner?: Uint8Array;\n } = { trustedRoots: options.trustedRoots };\n if (options.revocationList !== undefined) {\n tenuoOptions.revocationList = options.revocationList;\n }\n const tenuo = createTenuo({\n ...tenuoOptions,\n receiptSigner: options.identity.holderKey,\n });\n if (\n options.receiptMax !== undefined &&\n (!Number.isInteger(options.receiptMax) || options.receiptMax <= 0)\n ) {\n throw new TenuoConfigurationError(\"createTenuo.runtime() receiptMax must be a positive integer.\");\n }\n return new Runtime(\n tenuo,\n options.identity,\n options.receipts === \"collect\",\n options.receiptMax ?? 10_000,\n );\n}\n\nexport function drainSessionReceipts(session: object): string[] {\n return sessionCollector(session)?.drain() ?? [];\n}\n\nexport function peekSessionReceipts(session: object): string[] {\n return sessionCollector(session)?.peek() ?? [];\n}\n\nexport function acknowledgeSessionReceipts(session: object, count: number): number {\n const collector = sessionCollector(session);\n if (collector === undefined) {\n return 0;\n }\n const taken = collector.peek().slice(0, count);\n const removed = collector.acknowledge(count);\n linkedHostCollector(session)?.removeMatching(taken.slice(0, removed));\n return removed;\n}\n"]}
package/dist/session.d.ts CHANGED
@@ -13,8 +13,14 @@ export declare class Session implements SessionContract {
13
13
  toWire(): string[];
14
14
  dedupKey(tool: string, args: Readonly<Record<string, unknown>>): string;
15
15
  inspect(): SessionInfo;
16
+ /**
17
+ * Snapshot of collected receipts. Same as `drainReceipts`; nothing is
18
+ * removed until `acknowledgeReceipts`.
19
+ */
20
+ peekReceipts(): string[];
21
+ drainReceipts(): string[];
22
+ acknowledgeReceipts(count: number): number;
16
23
  }
17
24
  export declare function isSession(value: unknown): value is Session;
18
25
  export declare function nativeSession(session: Session): WasmSession;
19
26
  export {};
20
- //# sourceMappingURL=session.d.ts.map
package/dist/session.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { TenuoConfigurationError } from "./errors.js";
2
+ import { acknowledgeSessionReceipts, drainSessionReceipts, peekSessionReceipts, } from "./runtime.js";
2
3
  const inspect = Symbol.for("nodejs.util.inspect.custom");
3
4
  const nativeSessions = new WeakMap();
4
5
  /**
@@ -78,6 +79,19 @@ export class Session {
78
79
  }
79
80
  return out;
80
81
  }
82
+ /**
83
+ * Snapshot of collected receipts. Same as `drainReceipts`; nothing is
84
+ * removed until `acknowledgeReceipts`.
85
+ */
86
+ peekReceipts() {
87
+ return peekSessionReceipts(this);
88
+ }
89
+ drainReceipts() {
90
+ return drainSessionReceipts(this);
91
+ }
92
+ acknowledgeReceipts(count) {
93
+ return acknowledgeSessionReceipts(this, count);
94
+ }
81
95
  }
82
96
  export function isSession(value) {
83
97
  return value instanceof Session;
@@ -1 +1 @@
1
- {"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAGtD,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AACzD,MAA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G,CAAC,GAAG,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACvD,CAAC;QACD,IAAI,IAAI,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;YACrC,GAAG,CAAC,YAAY,GAAG,IAAI,CAAC,aAAa,CAAC;QACxC,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAED;;;OAGG;IACH,YAAY;QACV,OAAO,mBAAmB,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,aAAa;QACX,OAAO,oBAAoB,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,mBAAmB,CAAC,KAAa;QAC/B,OAAO,0BAA0B,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACjD,CAAC;CACF;AAED,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,OAAO,KAAK,YAAY,OAAO,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAgB;IAC5C,MAAM,MAAM,GAAG,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC3C,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,uBAAuB,CAAC,uCAAuC,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { Session as SessionContract, SessionInfo } from \"./api.ts\";\nimport { TenuoConfigurationError } from \"./errors.ts\";\nimport {\n acknowledgeSessionReceipts,\n drainSessionReceipts,\n peekSessionReceipts,\n} from \"./runtime.ts\";\nimport type { WasmSession, WasmSessionInfo } from \"./wasm.ts\";\n\nconst inspect = Symbol.for(\"nodejs.util.inspect.custom\");\nconst nativeSessions = new WeakMap<Session, WasmSession>();\n\n/**\n * Opaque session handle. Structural clones and JSON are not sessions.\n */\nexport class Session implements SessionContract {\n readonly [Symbol.toStringTag] = \"TenuoSession\" as const;\n\n constructor(native: WasmSession) {\n nativeSessions.set(this, native);\n }\n\n toJSON(): string {\n return \"[TenuoSession]\";\n }\n\n toString(): string {\n return \"[TenuoSession]\";\n }\n\n [inspect](): string {\n return \"[TenuoSession]\";\n }\n\n toWire(): string[] {\n const native = nativeSessions.get(this) as { toWire?: () => unknown } | undefined;\n if (native?.toWire === undefined) {\n throw new TenuoConfigurationError(\"session is not bound to the WASM core\");\n }\n const tokens = native.toWire();\n if (!Array.isArray(tokens) || tokens.some((token) => typeof token !== \"string\")) {\n throw new TenuoConfigurationError(\"toWire() did not return warrant tokens\");\n }\n return tokens;\n }\n\n dedupKey(tool: string, args: Readonly<Record<string, unknown>>): string {\n const native = nativeSessions.get(this) as\n | { dedupKey?: (tool: string, args: unknown) => string }\n | undefined;\n if (typeof native?.dedupKey !== \"function\") {\n throw new TenuoConfigurationError(\"session is not bound to the WASM core\");\n }\n return native.dedupKey(tool, args);\n }\n\n inspect(): SessionInfo {\n const native = nativeSessions.get(this) as { describe?: () => unknown } | undefined;\n if (typeof native?.describe !== \"function\") {\n throw new TenuoConfigurationError(\"session is not bound to the WASM core\");\n }\n const info = native.describe() as WasmSessionInfo;\n const out: {\n -readonly [K in keyof SessionInfo]: SessionInfo[K];\n } = {\n kind: info.kind,\n holderPublicKey: info.holder_public_key,\n rootPublicKey: info.root_public_key,\n depth: info.depth,\n maxDepth: info.max_depth,\n terminal: info.terminal,\n expiresAt: info.expires_at,\n tools: [...info.tools],\n warrantIds: [...info.warrant_ids],\n canAuthorize: info.can_authorize,\n approvalGatedTools: [...info.approval_gated_tools],\n };\n if (info.clearance !== undefined) {\n out.clearance = info.clearance;\n }\n if (info.session_id !== undefined) {\n out.sessionId = info.session_id;\n }\n if (info.agent_id !== undefined) {\n out.agentId = info.agent_id;\n }\n if (info.issuable_tools !== undefined) {\n out.issuableTools = [...info.issuable_tools];\n }\n if (info.max_issue_depth !== undefined) {\n out.maxIssueDepth = info.max_issue_depth;\n }\n if (info.required_approvers !== undefined) {\n out.requiredApprovers = [...info.required_approvers];\n }\n if (info.min_approvals !== undefined) {\n out.minApprovals = info.min_approvals;\n }\n return out;\n }\n\n /**\n * Snapshot of collected receipts. Same as `drainReceipts`; nothing is\n * removed until `acknowledgeReceipts`.\n */\n peekReceipts(): string[] {\n return peekSessionReceipts(this);\n }\n\n drainReceipts(): string[] {\n return drainSessionReceipts(this);\n }\n\n acknowledgeReceipts(count: number): number {\n return acknowledgeSessionReceipts(this, count);\n }\n}\n\nexport function isSession(value: unknown): value is Session {\n return value instanceof Session;\n}\n\nexport function nativeSession(session: Session): WasmSession {\n const native = nativeSessions.get(session);\n if (!native) {\n throw new TenuoConfigurationError(\"session is not bound to the WASM core\");\n }\n return native;\n}\n"]}