@absol-labs/agent 0.7.3 → 0.9.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 (80) hide show
  1. package/README.md +19 -4
  2. package/dist/discovery/registry.d.ts +110 -305
  3. package/dist/discovery/registry.d.ts.map +1 -1
  4. package/dist/discovery/registry.js +141 -318
  5. package/dist/discovery/registry.js.map +1 -1
  6. package/dist/frameworks/agentkit.d.ts.map +1 -1
  7. package/dist/frameworks/agentkit.js +23 -6
  8. package/dist/frameworks/agentkit.js.map +1 -1
  9. package/dist/gateway/caller-auth-gateway.d.ts +103 -2
  10. package/dist/gateway/caller-auth-gateway.d.ts.map +1 -1
  11. package/dist/gateway/caller-auth-gateway.js +176 -19
  12. package/dist/gateway/caller-auth-gateway.js.map +1 -1
  13. package/dist/gateway/http-server.d.ts +12 -0
  14. package/dist/gateway/http-server.d.ts.map +1 -1
  15. package/dist/gateway/http-server.js +45 -1
  16. package/dist/gateway/http-server.js.map +1 -1
  17. package/dist/index.d.ts +3 -3
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +3 -3
  20. package/dist/index.js.map +1 -1
  21. package/dist/wallet/autonomous-wallet-store.d.ts +123 -0
  22. package/dist/wallet/autonomous-wallet-store.d.ts.map +1 -0
  23. package/dist/wallet/autonomous-wallet-store.js +318 -0
  24. package/dist/wallet/autonomous-wallet-store.js.map +1 -0
  25. package/dist/wallet/autonomous-wallet.d.ts +14 -39
  26. package/dist/wallet/autonomous-wallet.d.ts.map +1 -1
  27. package/dist/wallet/autonomous-wallet.js +12 -145
  28. package/dist/wallet/autonomous-wallet.js.map +1 -1
  29. package/dist/wallet/cdp-sdk.d.ts +23 -0
  30. package/dist/wallet/cdp-sdk.d.ts.map +1 -0
  31. package/dist/wallet/cdp-sdk.js +27 -0
  32. package/dist/wallet/cdp-sdk.js.map +1 -0
  33. package/dist/wallet/encrypted-file-credential-store.d.ts +41 -0
  34. package/dist/wallet/encrypted-file-credential-store.d.ts.map +1 -0
  35. package/dist/wallet/encrypted-file-credential-store.js +221 -0
  36. package/dist/wallet/encrypted-file-credential-store.js.map +1 -0
  37. package/dist/wallet/provider.d.ts +1 -1
  38. package/dist/wallet/provider.d.ts.map +1 -1
  39. package/dist/wallet/provider.js +8 -3
  40. package/dist/wallet/provider.js.map +1 -1
  41. package/dist/wallet/secret-service-probe.d.ts +56 -0
  42. package/dist/wallet/secret-service-probe.d.ts.map +1 -0
  43. package/dist/wallet/secret-service-probe.js +407 -0
  44. package/dist/wallet/secret-service-probe.js.map +1 -0
  45. package/dist/zktls/reclaim-js-sdk.d.ts +24 -0
  46. package/dist/zktls/reclaim-js-sdk.d.ts.map +1 -0
  47. package/dist/zktls/reclaim-js-sdk.js +29 -0
  48. package/dist/zktls/reclaim-js-sdk.js.map +1 -0
  49. package/dist/zktls/reclaim.d.ts +14 -2
  50. package/dist/zktls/reclaim.d.ts.map +1 -1
  51. package/dist/zktls/reclaim.js +29 -6
  52. package/dist/zktls/reclaim.js.map +1 -1
  53. package/dist/zktls/t2-delivery-proof.d.ts +8 -1
  54. package/dist/zktls/t2-delivery-proof.d.ts.map +1 -1
  55. package/dist/zktls/t2-delivery-proof.js +22 -6
  56. package/dist/zktls/t2-delivery-proof.js.map +1 -1
  57. package/docs/agent-layer.md +150 -0
  58. package/docs/autonomous-privy-wallet.md +133 -0
  59. package/docs/crewai.md +70 -0
  60. package/docs/eliza.md +109 -0
  61. package/docs/langchain.md +63 -0
  62. package/docs/mcp-hosted.md +137 -0
  63. package/docs/privy-embedded-wallet.md +102 -0
  64. package/docs/quickstart.md +370 -0
  65. package/docs/threat-model.md +160 -0
  66. package/package.json +19 -6
  67. package/src/discovery/registry.ts +242 -414
  68. package/src/frameworks/agentkit.ts +24 -5
  69. package/src/gateway/caller-auth-gateway.ts +281 -15
  70. package/src/gateway/http-server.ts +64 -0
  71. package/src/index.ts +24 -0
  72. package/src/wallet/autonomous-wallet-store.ts +487 -0
  73. package/src/wallet/autonomous-wallet.ts +57 -224
  74. package/src/wallet/cdp-sdk.ts +33 -0
  75. package/src/wallet/encrypted-file-credential-store.ts +341 -0
  76. package/src/wallet/provider.ts +16 -9
  77. package/src/wallet/secret-service-probe.ts +487 -0
  78. package/src/zktls/reclaim-js-sdk.ts +50 -0
  79. package/src/zktls/reclaim.ts +57 -23
  80. package/src/zktls/t2-delivery-proof.ts +28 -10
@@ -0,0 +1,487 @@
1
+ import { existsSync } from "node:fs";
2
+ import { connect, type Socket } from "node:net";
3
+
4
+ /**
5
+ * Detects whether a freedesktop Secret Service provider (gnome-keyring,
6
+ * KeePassXC, KWallet, ...) is reachable on the D-Bus session bus.
7
+ *
8
+ * Why this exists: `@napi-rs/keyring` ships BOTH a `dbus-secret-service`
9
+ * backend and a `linux-keyutils` backend in the same native module and picks
10
+ * one at runtime. When no Secret Service provider answers on the session bus
11
+ * it silently falls through to `linux-keyutils` — the Linux *kernel* keyring,
12
+ * which lives in RAM and is destroyed on reboot. A credential written there
13
+ * looks durable (it round-trips across processes and SSH sessions) but is not,
14
+ * so an agent that provisioned a funded wallet loses its owner key on reboot.
15
+ *
16
+ * The keyring module exposes no API to report which backend it resolved, so the
17
+ * only way to know is to ask the session bus the same question it asks: does
18
+ * anyone own the well-known name `org.freedesktop.secrets`?
19
+ *
20
+ * This talks the D-Bus wire protocol directly over `node:net` (SASL EXTERNAL
21
+ * handshake, then `org.freedesktop.DBus.Hello` and `NameHasOwner`) so no extra
22
+ * dependency and no external binary is required. It is deliberately
23
+ * FAIL-CLOSED: any missing bus, malformed reply, protocol error or timeout
24
+ * reports "not available", which callers must treat as "not durable".
25
+ */
26
+
27
+ const SECRET_SERVICE_BUS_NAME = "org.freedesktop.secrets";
28
+ const DBUS_PATH = "/org/freedesktop/DBus";
29
+ const DBUS_INTERFACE = "org.freedesktop.DBus";
30
+ const DBUS_DESTINATION = "org.freedesktop.DBus";
31
+
32
+ const MESSAGE_TYPE_METHOD_RETURN = 2;
33
+ const MESSAGE_TYPE_ERROR = 3;
34
+
35
+ const HEADER_FIELD_ERROR_NAME = 4;
36
+ const HEADER_FIELD_REPLY_SERIAL = 5;
37
+ const HEADER_FIELD_SIGNATURE = 8;
38
+
39
+ const HELLO_SERIAL = 1;
40
+ const NAME_HAS_OWNER_SERIAL = 2;
41
+
42
+ export interface SecretServiceProbeResult {
43
+ readonly available: boolean;
44
+ /** Human-readable reason, safe to surface in an error message. */
45
+ readonly detail: string;
46
+ }
47
+
48
+ export interface ProbeSecretServiceOptions {
49
+ readonly env?: NodeJS.ProcessEnv;
50
+ readonly timeoutMs?: number;
51
+ readonly uid?: number;
52
+ }
53
+
54
+ function alignTo(value: number, alignment: number): number {
55
+ const remainder = value % alignment;
56
+ return remainder === 0 ? value : value + (alignment - remainder);
57
+ }
58
+
59
+ /** Minimal little-endian D-Bus marshaller. Messages here are a few dozen bytes. */
60
+ class ByteWriter {
61
+ private readonly bytes: number[] = [];
62
+
63
+ get length(): number {
64
+ return this.bytes.length;
65
+ }
66
+
67
+ byte(value: number): void {
68
+ this.bytes.push(value & 0xff);
69
+ }
70
+
71
+ align(alignment: number): void {
72
+ while (this.bytes.length % alignment !== 0) this.bytes.push(0);
73
+ }
74
+
75
+ uint32(value: number): void {
76
+ this.align(4);
77
+ this.bytes.push(
78
+ value & 0xff,
79
+ (value >>> 8) & 0xff,
80
+ (value >>> 16) & 0xff,
81
+ (value >>> 24) & 0xff,
82
+ );
83
+ }
84
+
85
+ raw(buffer: Buffer): void {
86
+ for (const byte of buffer) this.bytes.push(byte);
87
+ }
88
+
89
+ /** DBus STRING / OBJECT_PATH: uint32 length, utf8 bytes, NUL. */
90
+ string(value: string): void {
91
+ const encoded = Buffer.from(value, "utf8");
92
+ this.uint32(encoded.length);
93
+ this.raw(encoded);
94
+ this.byte(0);
95
+ }
96
+
97
+ /** DBus SIGNATURE: single length byte, ascii bytes, NUL. */
98
+ signature(value: string): void {
99
+ const encoded = Buffer.from(value, "ascii");
100
+ this.byte(encoded.length);
101
+ this.raw(encoded);
102
+ this.byte(0);
103
+ }
104
+
105
+ toBuffer(): Buffer {
106
+ return Buffer.from(this.bytes);
107
+ }
108
+ }
109
+
110
+ type HeaderFieldValue =
111
+ | { readonly type: "s" | "o" | "g"; readonly value: string }
112
+ | { readonly type: "u"; readonly value: number };
113
+
114
+ function encodeHeaderFields(
115
+ fields: ReadonlyArray<readonly [number, HeaderFieldValue]>,
116
+ ): Buffer {
117
+ const writer = new ByteWriter();
118
+ for (const [code, field] of fields) {
119
+ // Each ARRAY-of-STRUCT element is 8-byte aligned. The field array always
120
+ // starts at message offset 16, which is itself 8-aligned, so writing this
121
+ // buffer standalone produces identical padding.
122
+ writer.align(8);
123
+ writer.byte(code);
124
+ writer.signature(field.type);
125
+ if (field.type === "u") writer.uint32(field.value);
126
+ else if (field.type === "g") writer.signature(field.value);
127
+ else writer.string(field.value);
128
+ }
129
+ return writer.toBuffer();
130
+ }
131
+
132
+ export interface EncodeMethodCallInput {
133
+ readonly serial: number;
134
+ readonly path: string;
135
+ readonly interfaceName: string;
136
+ readonly member: string;
137
+ readonly destination: string;
138
+ readonly signature?: string;
139
+ readonly body?: Buffer;
140
+ }
141
+
142
+ /** Exported for unit tests: encodes one METHOD_CALL message. */
143
+ export function encodeMethodCall(input: EncodeMethodCallInput): Buffer {
144
+ const body = input.body ?? Buffer.alloc(0);
145
+ const fields: Array<readonly [number, HeaderFieldValue]> = [
146
+ [1, { type: "o", value: input.path }],
147
+ [2, { type: "s", value: input.interfaceName }],
148
+ [3, { type: "s", value: input.member }],
149
+ [6, { type: "s", value: input.destination }],
150
+ ];
151
+ if (input.signature !== undefined) {
152
+ fields.push([
153
+ HEADER_FIELD_SIGNATURE,
154
+ { type: "g", value: input.signature },
155
+ ]);
156
+ }
157
+ const encodedFields = encodeHeaderFields(fields);
158
+
159
+ const message = new ByteWriter();
160
+ message.byte(0x6c); // 'l' — little endian
161
+ message.byte(1); // METHOD_CALL
162
+ message.byte(0); // no flags
163
+ message.byte(1); // protocol version
164
+ message.uint32(body.length);
165
+ message.uint32(input.serial);
166
+ message.uint32(encodedFields.length);
167
+ message.raw(encodedFields);
168
+ message.align(8);
169
+ message.raw(body);
170
+ return message.toBuffer();
171
+ }
172
+
173
+ /** Exported for unit tests: encodes a single-STRING message body. */
174
+ export function encodeStringBody(value: string): Buffer {
175
+ const writer = new ByteWriter();
176
+ writer.string(value);
177
+ return writer.toBuffer();
178
+ }
179
+
180
+ export interface DBusMessage {
181
+ readonly type: number;
182
+ readonly serial: number;
183
+ readonly replySerial?: number;
184
+ readonly signature?: string;
185
+ readonly errorName?: string;
186
+ readonly body: Buffer;
187
+ readonly littleEndian: boolean;
188
+ }
189
+
190
+ /**
191
+ * Exported for unit tests: decodes as many complete messages as `buffer` holds
192
+ * and returns the undecoded remainder. Throws on a malformed stream.
193
+ */
194
+ export function decodeMessages(buffer: Buffer): {
195
+ readonly messages: readonly DBusMessage[];
196
+ readonly rest: Buffer;
197
+ } {
198
+ const messages: DBusMessage[] = [];
199
+ let offset = 0;
200
+ while (buffer.length - offset >= 16) {
201
+ const start = offset;
202
+ const endian = buffer[start];
203
+ if (endian !== 0x6c && endian !== 0x42) {
204
+ throw new Error("invalid D-Bus endianness marker");
205
+ }
206
+ const littleEndian = endian === 0x6c;
207
+ const readUint32 = (at: number): number =>
208
+ littleEndian ? buffer.readUInt32LE(at) : buffer.readUInt32BE(at);
209
+ const type = buffer[start + 1]!;
210
+ const bodyLength = readUint32(start + 4);
211
+ const serial = readUint32(start + 8);
212
+ const fieldsLength = readUint32(start + 12);
213
+ const bodyOffset = alignTo(16 + fieldsLength, 8);
214
+ const total = bodyOffset + bodyLength;
215
+ if (buffer.length - start < total) break;
216
+
217
+ let replySerial: number | undefined;
218
+ let signature: string | undefined;
219
+ let errorName: string | undefined;
220
+ const fieldsEnd = 16 + fieldsLength;
221
+ let cursor = 16;
222
+ while (cursor < fieldsEnd) {
223
+ cursor = alignTo(cursor, 8);
224
+ if (cursor >= fieldsEnd) break;
225
+ const code = buffer[start + cursor]!;
226
+ cursor += 1;
227
+ const typeLength = buffer[start + cursor]!;
228
+ cursor += 1;
229
+ const fieldType = buffer.toString(
230
+ "ascii",
231
+ start + cursor,
232
+ start + cursor + typeLength,
233
+ );
234
+ cursor += typeLength + 1;
235
+ if (fieldType === "u") {
236
+ cursor = alignTo(cursor, 4);
237
+ const value = readUint32(start + cursor);
238
+ cursor += 4;
239
+ if (code === HEADER_FIELD_REPLY_SERIAL) replySerial = value;
240
+ } else if (fieldType === "s" || fieldType === "o") {
241
+ cursor = alignTo(cursor, 4);
242
+ const length = readUint32(start + cursor);
243
+ cursor += 4;
244
+ const value = buffer.toString(
245
+ "utf8",
246
+ start + cursor,
247
+ start + cursor + length,
248
+ );
249
+ cursor += length + 1;
250
+ if (code === HEADER_FIELD_ERROR_NAME) errorName = value;
251
+ } else if (fieldType === "g") {
252
+ const length = buffer[start + cursor]!;
253
+ cursor += 1;
254
+ const value = buffer.toString(
255
+ "ascii",
256
+ start + cursor,
257
+ start + cursor + length,
258
+ );
259
+ cursor += length + 1;
260
+ if (code === HEADER_FIELD_SIGNATURE) signature = value;
261
+ } else {
262
+ throw new Error(`unsupported D-Bus header field type "${fieldType}"`);
263
+ }
264
+ if (cursor > fieldsEnd) {
265
+ throw new Error("malformed D-Bus header fields");
266
+ }
267
+ }
268
+
269
+ messages.push({
270
+ type,
271
+ serial,
272
+ ...(replySerial === undefined ? {} : { replySerial }),
273
+ ...(signature === undefined ? {} : { signature }),
274
+ ...(errorName === undefined ? {} : { errorName }),
275
+ body: buffer.subarray(start + bodyOffset, start + total),
276
+ littleEndian,
277
+ });
278
+ offset = start + total;
279
+ }
280
+ return { messages, rest: buffer.subarray(offset) };
281
+ }
282
+
283
+ type BusAddress =
284
+ | { readonly kind: "path"; readonly path: string }
285
+ | { readonly kind: "error"; readonly detail: string };
286
+
287
+ /** Exported for unit tests. */
288
+ export function resolveSessionBusPath(env: NodeJS.ProcessEnv): BusAddress {
289
+ const address = env.DBUS_SESSION_BUS_ADDRESS;
290
+ if (typeof address === "string" && address.trim() !== "") {
291
+ for (const entry of address.split(";")) {
292
+ const trimmed = entry.trim();
293
+ if (!trimmed.startsWith("unix:")) continue;
294
+ const parameters = new Map<string, string>();
295
+ for (const pair of trimmed.slice("unix:".length).split(",")) {
296
+ const separator = pair.indexOf("=");
297
+ if (separator > 0) {
298
+ parameters.set(pair.slice(0, separator), pair.slice(separator + 1));
299
+ }
300
+ }
301
+ const path = parameters.get("path");
302
+ if (path !== undefined && path !== "") return { kind: "path", path };
303
+ const abstract = parameters.get("abstract");
304
+ if (abstract !== undefined && abstract !== "") {
305
+ // Linux abstract namespace sockets are addressed with a leading NUL.
306
+ return { kind: "path", path: `\0${abstract}` };
307
+ }
308
+ }
309
+ return {
310
+ kind: "error",
311
+ detail: `DBUS_SESSION_BUS_ADDRESS has no usable unix transport (${address})`,
312
+ };
313
+ }
314
+ const runtimeDirectory = env.XDG_RUNTIME_DIR;
315
+ if (typeof runtimeDirectory === "string" && runtimeDirectory !== "") {
316
+ const candidate = `${runtimeDirectory.replace(/\/$/, "")}/bus`;
317
+ if (existsSync(candidate)) return { kind: "path", path: candidate };
318
+ return {
319
+ kind: "error",
320
+ detail: `no D-Bus session socket at ${candidate}`,
321
+ };
322
+ }
323
+ return {
324
+ kind: "error",
325
+ detail:
326
+ "no D-Bus session bus (DBUS_SESSION_BUS_ADDRESS and XDG_RUNTIME_DIR are unset)",
327
+ };
328
+ }
329
+
330
+ /**
331
+ * Asks the D-Bus session bus whether `org.freedesktop.secrets` has an owner.
332
+ * Never throws; every failure path resolves to `available: false`.
333
+ */
334
+ export async function probeSecretServiceAvailable(
335
+ options: ProbeSecretServiceOptions = {},
336
+ ): Promise<SecretServiceProbeResult> {
337
+ const env = options.env ?? process.env;
338
+ const timeoutMs = options.timeoutMs ?? 2_000;
339
+ const address = resolveSessionBusPath(env);
340
+ if (address.kind === "error") {
341
+ return { available: false, detail: address.detail };
342
+ }
343
+ const uid =
344
+ options.uid ??
345
+ (typeof process.getuid === "function" ? process.getuid() : 0);
346
+
347
+ return new Promise<SecretServiceProbeResult>((resolve) => {
348
+ let socket: Socket;
349
+ try {
350
+ socket = connect({ path: address.path });
351
+ } catch (error) {
352
+ resolve({
353
+ available: false,
354
+ detail: `could not connect to the D-Bus session bus: ${describe(error)}`,
355
+ });
356
+ return;
357
+ }
358
+ let settled = false;
359
+ let authenticated = false;
360
+ let buffer: Buffer<ArrayBufferLike> = Buffer.alloc(0);
361
+
362
+ const finish = (result: SecretServiceProbeResult): void => {
363
+ if (settled) return;
364
+ settled = true;
365
+ clearTimeout(timer);
366
+ socket.removeAllListeners();
367
+ socket.destroy();
368
+ resolve(result);
369
+ };
370
+ const timer = setTimeout(() => {
371
+ finish({
372
+ available: false,
373
+ detail: `D-Bus session bus did not answer within ${timeoutMs}ms`,
374
+ });
375
+ }, timeoutMs);
376
+ if (typeof timer.unref === "function") timer.unref();
377
+
378
+ socket.on("error", (error) => {
379
+ finish({
380
+ available: false,
381
+ detail: `D-Bus session bus connection failed: ${describe(error)}`,
382
+ });
383
+ });
384
+ socket.on("close", () => {
385
+ finish({
386
+ available: false,
387
+ detail: "D-Bus session bus closed the connection before replying",
388
+ });
389
+ });
390
+ socket.on("connect", () => {
391
+ // SASL EXTERNAL: the NUL byte, then the uid as ASCII hex.
392
+ const identity = Buffer.from(String(uid), "ascii").toString("hex");
393
+ socket.write(`\0AUTH EXTERNAL ${identity}\r\n`);
394
+ });
395
+ socket.on("data", (chunk: Buffer) => {
396
+ buffer = Buffer.concat([buffer, chunk]);
397
+ if (!authenticated) {
398
+ const terminator = buffer.indexOf("\r\n");
399
+ if (terminator < 0) return;
400
+ const line = buffer.toString("ascii", 0, terminator);
401
+ buffer = buffer.subarray(terminator + 2);
402
+ if (!line.startsWith("OK")) {
403
+ finish({
404
+ available: false,
405
+ detail: `D-Bus session bus rejected authentication (${line})`,
406
+ });
407
+ return;
408
+ }
409
+ authenticated = true;
410
+ socket.write("BEGIN\r\n");
411
+ socket.write(
412
+ encodeMethodCall({
413
+ serial: HELLO_SERIAL,
414
+ path: DBUS_PATH,
415
+ interfaceName: DBUS_INTERFACE,
416
+ member: "Hello",
417
+ destination: DBUS_DESTINATION,
418
+ }),
419
+ );
420
+ socket.write(
421
+ encodeMethodCall({
422
+ serial: NAME_HAS_OWNER_SERIAL,
423
+ path: DBUS_PATH,
424
+ interfaceName: DBUS_INTERFACE,
425
+ member: "NameHasOwner",
426
+ destination: DBUS_DESTINATION,
427
+ signature: "s",
428
+ body: encodeStringBody(SECRET_SERVICE_BUS_NAME),
429
+ }),
430
+ );
431
+ if (buffer.length === 0) return;
432
+ }
433
+ let decoded: ReturnType<typeof decodeMessages>;
434
+ try {
435
+ decoded = decodeMessages(buffer);
436
+ } catch (error) {
437
+ finish({
438
+ available: false,
439
+ detail: `could not decode the D-Bus reply: ${describe(error)}`,
440
+ });
441
+ return;
442
+ }
443
+ buffer = decoded.rest;
444
+ for (const message of decoded.messages) {
445
+ if (message.replySerial !== NAME_HAS_OWNER_SERIAL) continue;
446
+ if (message.type === MESSAGE_TYPE_ERROR) {
447
+ finish({
448
+ available: false,
449
+ detail: `D-Bus NameHasOwner failed (${message.errorName ?? "unknown error"})`,
450
+ });
451
+ return;
452
+ }
453
+ if (
454
+ message.type !== MESSAGE_TYPE_METHOD_RETURN ||
455
+ message.signature !== "b" ||
456
+ message.body.length < 4
457
+ ) {
458
+ finish({
459
+ available: false,
460
+ detail: "D-Bus returned an unexpected NameHasOwner reply",
461
+ });
462
+ return;
463
+ }
464
+ const owned =
465
+ (message.littleEndian
466
+ ? message.body.readUInt32LE(0)
467
+ : message.body.readUInt32BE(0)) !== 0;
468
+ finish(
469
+ owned
470
+ ? {
471
+ available: true,
472
+ detail: `${SECRET_SERVICE_BUS_NAME} is owned on the D-Bus session bus`,
473
+ }
474
+ : {
475
+ available: false,
476
+ detail: `no process owns ${SECRET_SERVICE_BUS_NAME} on the D-Bus session bus`,
477
+ },
478
+ );
479
+ return;
480
+ }
481
+ });
482
+ });
483
+ }
484
+
485
+ function describe(error: unknown): string {
486
+ return error instanceof Error ? error.message : String(error);
487
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * `@reclaimprotocol/js-sdk` is an OPTIONAL peer dependency: only consumers that
3
+ * actually generate/verify zkTLS delivery proofs (T2, issue #24) need it, and it
4
+ * carries a large transitive graph. The top-level "@absol-labs/agent" barrel
5
+ * DOES re-export the zkTLS modules, so those modules must import the SDK's
6
+ * TYPES only (`import type`, erased at compile time) and load the runtime module
7
+ * lazily through this loader at the point of first use.
8
+ *
9
+ * Deliberately NOT a top-level `await import(...)` (the pattern used by
10
+ * `../frameworks/langchain.ts`): that module is not barrel-reachable, this one
11
+ * is, and a top-level await would re-introduce the hard dependency at
12
+ * barrel-import time.
13
+ */
14
+
15
+ type ReclaimJsSdkModule = typeof import("@reclaimprotocol/js-sdk");
16
+
17
+ let modulePromise: Promise<ReclaimJsSdkModule> | undefined;
18
+
19
+ /** Memoized lazy load with an actionable missing-peer error. */
20
+ export async function loadReclaimJsSdk(): Promise<ReclaimJsSdkModule> {
21
+ modulePromise ??= import("@reclaimprotocol/js-sdk").catch(
22
+ (error: unknown) => {
23
+ throw new Error(
24
+ "@absol-labs/agent zkTLS delivery-proof support requires the optional peer dependency '@reclaimprotocol/js-sdk'. Install it with `npm install @reclaimprotocol/js-sdk`.",
25
+ { cause: error },
26
+ );
27
+ },
28
+ );
29
+ return await modulePromise;
30
+ }
31
+
32
+ /**
33
+ * `@reclaimprotocol/zk-fetch` is the companion optional peer used to PRODUCE
34
+ * proofs (the SDK above verifies them). Same contract, same actionable error.
35
+ */
36
+ type ReclaimZkFetchModule = typeof import("@reclaimprotocol/zk-fetch");
37
+
38
+ let zkFetchModulePromise: Promise<ReclaimZkFetchModule> | undefined;
39
+
40
+ export async function loadReclaimZkFetch(): Promise<ReclaimZkFetchModule> {
41
+ zkFetchModulePromise ??= import("@reclaimprotocol/zk-fetch").catch(
42
+ (error: unknown) => {
43
+ throw new Error(
44
+ "@absol-labs/agent zkTLS delivery-proof support requires the optional peer dependency '@reclaimprotocol/zk-fetch'. Install it with `npm install @reclaimprotocol/zk-fetch`.",
45
+ { cause: error },
46
+ );
47
+ },
48
+ );
49
+ return await zkFetchModulePromise;
50
+ }
@@ -1,13 +1,16 @@
1
- import {
2
- getHttpProviderClaimParamsFromProof,
3
- getProviderHashRequirementsFromSpec,
1
+ // `@reclaimprotocol/js-sdk` is an OPTIONAL peer dependency: TYPES only here
2
+ // (erased at compile time), runtime values via `loadReclaimJsSdk()` at the point
3
+ // of first use. See ./reclaim-js-sdk.ts.
4
+ import type {
4
5
  verifyProof,
5
- type Proof as ReclaimProtocolProof,
6
- type RequestSpec,
7
- type VerifyProofResult,
6
+ Proof as ReclaimProtocolProof,
7
+ RequestSpec,
8
+ VerifyProofResult,
8
9
  } from "@reclaimprotocol/js-sdk";
9
10
  import { z } from "zod";
10
11
 
12
+ import { loadReclaimJsSdk, loadReclaimZkFetch } from "./reclaim-js-sdk.js";
13
+
11
14
  const addressSchema = z.string().regex(/^0x[0-9a-fA-F]{40}$/);
12
15
  const bytes32Schema = z.string().regex(/^0x[0-9a-fA-F]{64}$/);
13
16
  const httpMethodSchema = z.enum(["GET", "POST", "PUT"]);
@@ -172,7 +175,14 @@ const reclaimProofInputSchema = z.object({
172
175
  export class ReclaimConsumerProofService implements ConsumerDeliveryProofService {
173
176
  private readonly client: ReclaimClientLike;
174
177
  private readonly config: ReclaimProofServiceConfig;
175
- private readonly verifyProofImpl: VerifyProofFn;
178
+ /**
179
+ * Caller-supplied verifier, if any. NOT defaulted in the constructor: the real
180
+ * `verifyProof` lives in the optional peer `@reclaimprotocol/js-sdk`, which is
181
+ * loaded lazily at first use so that merely constructing this service — or
182
+ * importing the package barrel — never requires the peer to be installed.
183
+ * Resolved in {@link resolveVerifyProof}.
184
+ */
185
+ private readonly verifyProofOverride: VerifyProofFn | undefined;
176
186
 
177
187
  constructor(
178
188
  config: ReclaimProofServiceConfig,
@@ -194,7 +204,16 @@ export class ReclaimConsumerProofService implements ConsumerDeliveryProofService
194
204
  this.config.applicationSecret,
195
205
  this.config.logs ?? false,
196
206
  );
197
- this.verifyProofImpl = options.verifyProof ?? verifyProof;
207
+ this.verifyProofOverride = options.verifyProof;
208
+ }
209
+
210
+ /**
211
+ * The verifier to use: a caller-supplied override, else the optional peer's
212
+ * `verifyProof`, loaded on first use with an actionable missing-peer error.
213
+ */
214
+ private async resolveVerifyProof(): Promise<VerifyProofFn> {
215
+ if (this.verifyProofOverride !== undefined) return this.verifyProofOverride;
216
+ return (await loadReclaimJsSdk()).verifyProof;
198
217
  }
199
218
 
200
219
  async proveConsumedHttpsResponse(
@@ -244,8 +263,15 @@ export class ReclaimConsumerProofService implements ConsumerDeliveryProofService
244
263
  );
245
264
  }
246
265
 
247
- const verification = await this.verifyProofImpl(proof, {
248
- ...getProviderHashRequirementsFromSpec({
266
+ // Both the verifier and the provider-hash helper live in the optional peer;
267
+ // load it once here rather than importing it at module scope.
268
+ const [verifyProofFn, reclaimSdk] = await Promise.all([
269
+ this.resolveVerifyProof(),
270
+ loadReclaimJsSdk(),
271
+ ]);
272
+
273
+ const verification = await verifyProofFn(proof, {
274
+ ...reclaimSdk.getProviderHashRequirementsFromSpec({
249
275
  requests: [toRequestSpec(parsed, method)],
250
276
  }),
251
277
  ...(parsed.useTee === true
@@ -271,25 +297,33 @@ export class ReclaimConsumerProofService implements ConsumerDeliveryProofService
271
297
  );
272
298
  }
273
299
 
274
- const request = getHttpProviderClaimParamsFromProof(proof);
300
+ // Same optional peer, already memoized by the loader above.
301
+ const request = reclaimSdk.getHttpProviderClaimParamsFromProof(proof);
302
+ type ClaimParams = ReturnType<
303
+ typeof reclaimSdk.getHttpProviderClaimParamsFromProof
304
+ >;
275
305
  return {
276
306
  proof,
277
307
  request: {
278
308
  url: request.url,
279
309
  method: request.method as "GET" | "POST" | "PUT",
280
310
  body: request.body === "" ? null : (request.body ?? null),
281
- responseMatches: request.responseMatches.map((match) => ({
282
- value: match.value,
283
- type: match.type,
284
- invert: match.invert,
285
- isOptional: match.isOptional,
286
- })),
287
- responseRedactions: request.responseRedactions.map((redaction) => ({
288
- regex: redaction.regex,
289
- jsonPath: redaction.jsonPath,
290
- xPath: redaction.xPath,
291
- hash: redaction.hash,
292
- })),
311
+ responseMatches: request.responseMatches.map(
312
+ (match: ClaimParams["responseMatches"][number]) => ({
313
+ value: match.value,
314
+ type: match.type,
315
+ invert: match.invert,
316
+ isOptional: match.isOptional,
317
+ }),
318
+ ),
319
+ responseRedactions: request.responseRedactions.map(
320
+ (redaction: ClaimParams["responseRedactions"][number]) => ({
321
+ regex: redaction.regex,
322
+ jsonPath: redaction.jsonPath,
323
+ xPath: redaction.xPath,
324
+ hash: redaction.hash,
325
+ }),
326
+ ),
293
327
  },
294
328
  verification: {
295
329
  context: trusted.context,