@query-farm/vgi 0.48.4 → 0.48.6

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 (46) hide show
  1. package/README.md +51 -0
  2. package/dist/attach-secret-keyfile.d.ts +11 -0
  3. package/dist/attach-secret-options.d.ts +96 -0
  4. package/dist/catalog/attach-option.d.ts +6 -0
  5. package/dist/catalog/interface.d.ts +15 -0
  6. package/dist/catalog/read-only.d.ts +6 -4
  7. package/dist/client-entry.js +1 -1
  8. package/dist/client-entry.js.map +4 -4
  9. package/dist/index.core.d.ts +2 -0
  10. package/dist/index.js +5701 -5277
  11. package/dist/index.js.map +25 -23
  12. package/dist/protocol/dispatch.d.ts +11 -0
  13. package/dist/protocol/handlers/catalog/admin.d.ts +1 -1
  14. package/dist/protocol/handlers/catalog/index.d.ts +1 -1
  15. package/dist/protocol/handlers/catalog/index_methods.d.ts +1 -1
  16. package/dist/protocol/handlers/catalog/macro.d.ts +1 -1
  17. package/dist/protocol/handlers/catalog/shared.d.ts +28 -3
  18. package/dist/protocol/handlers/catalog/table.d.ts +1 -1
  19. package/dist/protocol/handlers/catalog/view.d.ts +1 -1
  20. package/dist/protocol/handlers/function.d.ts +2 -0
  21. package/dist/protocol/handlers/table-buffering.d.ts +1 -1
  22. package/dist/serve-entry.d.ts +5 -0
  23. package/dist/serve-entry.js +475 -94
  24. package/dist/serve-entry.js.map +18 -16
  25. package/dist/worker-cf-entry.js +499 -95
  26. package/dist/worker-cf-entry.js.map +19 -17
  27. package/dist/worker.d.ts +10 -0
  28. package/package.json +3 -3
  29. package/src/attach-secret-keyfile.ts +185 -0
  30. package/src/attach-secret-options.ts +418 -0
  31. package/src/catalog/attach-option.ts +6 -0
  32. package/src/catalog/interface.ts +19 -0
  33. package/src/catalog/read-only.ts +11 -6
  34. package/src/index.core.ts +10 -0
  35. package/src/protocol/dispatch.ts +14 -2
  36. package/src/protocol/handlers/catalog/admin.ts +33 -18
  37. package/src/protocol/handlers/catalog/index.ts +6 -5
  38. package/src/protocol/handlers/catalog/index_methods.ts +5 -3
  39. package/src/protocol/handlers/catalog/macro.ts +7 -5
  40. package/src/protocol/handlers/catalog/shared.ts +52 -6
  41. package/src/protocol/handlers/catalog/table.ts +24 -22
  42. package/src/protocol/handlers/catalog/view.ts +9 -7
  43. package/src/protocol/handlers/function.ts +11 -5
  44. package/src/protocol/handlers/table-buffering.ts +2 -1
  45. package/src/serve-entry.ts +6 -1
  46. package/src/worker.ts +12 -0
@@ -22,6 +22,7 @@ import {
22
22
  import {
23
23
  type GetCatalog,
24
24
  catalogHandler,
25
+ type OpaqueKeys,
25
26
  } from "./shared.js";
26
27
 
27
28
  function requireFlatColumnPath(value: unknown, operation: string): string[] {
@@ -35,9 +36,10 @@ function requireFlatColumnPath(value: unknown, operation: string): string[] {
35
36
  return path as string[];
36
37
  }
37
38
 
38
- export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array): Partial<VgiService> {
39
+ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array, attachSecretKey?: Uint8Array): Partial<VgiService> {
40
+ const keys: OpaqueKeys = { signingKey, attachSecretKey };
39
41
  // catalog_table_get
40
- const catalogTableGet = catalogHandler(signingKey, async (params) => {
42
+ const catalogTableGet = catalogHandler(keys, async (params) => {
41
43
  const cat = getCatalog();
42
44
  const info = await cat.tableGet(
43
45
  toUint8Array(params.attach_opaque_data),
@@ -53,7 +55,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
53
55
  });
54
56
 
55
57
  // catalog_table_create
56
- const catalogTableCreate = catalogHandler(signingKey, async (params) => {
58
+ const catalogTableCreate = catalogHandler(keys, async (params) => {
57
59
  if (params.constraint_definitions == null) throw new Error("constraint_definitions is required");
58
60
  const definitions = Array.from(params.constraint_definitions as Iterable<unknown>, (d) => toUint8Array(d as Uint8Array));
59
61
  if (params.comment != null || params.tags != null || params.options != null || params.layout != null) {
@@ -89,7 +91,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
89
91
 
90
92
  // catalog_table_constraints_apply (ALTER TABLE ... SET/DROP NOT NULL and
91
93
  // every other canonical constraint change).
92
- const catalogTableConstraintsApply = catalogHandler(signingKey, async (params) => {
94
+ const catalogTableConstraintsApply = catalogHandler(keys, async (params) => {
93
95
  const attach = toUint8Array(params.attach_opaque_data);
94
96
  const cat = getCatalog();
95
97
  const caps = await cat.catalogCapabilities(attach);
@@ -124,7 +126,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
124
126
  });
125
127
 
126
128
  // catalog_table_drop
127
- const catalogTableDrop = catalogHandler(signingKey, async (params) => {
129
+ const catalogTableDrop = catalogHandler(keys, async (params) => {
128
130
  const cat = getCatalog();
129
131
  await cat.tableDrop(
130
132
  toUint8Array(params.attach_opaque_data),
@@ -137,7 +139,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
137
139
  });
138
140
 
139
141
  // catalog_table_column_statistics_get
140
- const catalogTableColumnStatisticsGet = catalogHandler(signingKey, async (params) => {
142
+ const catalogTableColumnStatisticsGet = catalogHandler(keys, async (params) => {
141
143
  const cat = getCatalog();
142
144
  const stats = await cat.tableColumnStatisticsGet(
143
145
  toUint8Array(params.attach_opaque_data),
@@ -149,7 +151,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
149
151
  });
150
152
 
151
153
  // catalog_table_scan_function_get
152
- const catalogTableScanFunctionGet = catalogHandler(signingKey, async (params) => {
154
+ const catalogTableScanFunctionGet = catalogHandler(keys, async (params) => {
153
155
  const cat = getCatalog();
154
156
  const scanResult = await cat.tableScanFunctionGet(
155
157
  toUint8Array(params.attach_opaque_data),
@@ -167,7 +169,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
167
169
  // into TableInfo is only asked when the client skipped the inline value.
168
170
  const optionalTx = (params: Record<string, any>): Uint8Array | undefined =>
169
171
  params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined;
170
- const catalogTableInsertFunctionGet = catalogHandler(signingKey, async (params) => {
172
+ const catalogTableInsertFunctionGet = catalogHandler(keys, async (params) => {
171
173
  const result = await getCatalog().tableInsertFunctionGet(
172
174
  toUint8Array(params.attach_opaque_data),
173
175
  params.schema_path,
@@ -177,7 +179,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
177
179
  );
178
180
  return wrapResult(result, ScanFunctionResultSchema);
179
181
  });
180
- const catalogTableUpdateFunctionGet = catalogHandler(signingKey, async (params) => {
182
+ const catalogTableUpdateFunctionGet = catalogHandler(keys, async (params) => {
181
183
  const result = await getCatalog().tableUpdateFunctionGet(
182
184
  toUint8Array(params.attach_opaque_data),
183
185
  params.schema_path,
@@ -186,7 +188,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
186
188
  );
187
189
  return wrapResult(result, ScanFunctionResultSchema);
188
190
  });
189
- const catalogTableDeleteFunctionGet = catalogHandler(signingKey, async (params) => {
191
+ const catalogTableDeleteFunctionGet = catalogHandler(keys, async (params) => {
190
192
  const result = await getCatalog().tableDeleteFunctionGet(
191
193
  toUint8Array(params.attach_opaque_data),
192
194
  params.schema_path,
@@ -199,7 +201,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
199
201
  // catalog_table_scan_branches_get — branches-aware variant of
200
202
  // scan_function_get. The branches-aware C++ extension calls this for every
201
203
  // table scan; single-source catalogs synthesise a one-branch result.
202
- const catalogTableScanBranchesGet = catalogHandler(signingKey, async (params) => {
204
+ const catalogTableScanBranchesGet = catalogHandler(keys, async (params) => {
203
205
  const cat = getCatalog();
204
206
  const branchesResult = await cat.tableScanBranchesGet(
205
207
  toUint8Array(params.attach_opaque_data),
@@ -213,7 +215,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
213
215
  });
214
216
 
215
217
  // catalog_table_comment_set
216
- const catalogTableCommentSet = catalogHandler(signingKey, async (params) => {
218
+ const catalogTableCommentSet = catalogHandler(keys, async (params) => {
217
219
  const cat = getCatalog();
218
220
  await cat.tableCommentSet(
219
221
  toUint8Array(params.attach_opaque_data),
@@ -227,7 +229,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
227
229
  });
228
230
 
229
231
  // catalog_table_rename
230
- const catalogTableRename = catalogHandler(signingKey, async (params) => {
232
+ const catalogTableRename = catalogHandler(keys, async (params) => {
231
233
  const cat = getCatalog();
232
234
  await cat.tableRename(
233
235
  toUint8Array(params.attach_opaque_data),
@@ -241,7 +243,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
241
243
  });
242
244
 
243
245
  // catalog_table_column_add
244
- const catalogTableColumnAdd = catalogHandler(signingKey, async (params) => {
246
+ const catalogTableColumnAdd = catalogHandler(keys, async (params) => {
245
247
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_add");
246
248
  validateColumnMetadataIpc(toUint8Array(params.column_definition));
247
249
  validateColumnExpressionsIpc(toUint8Array(params.column_definition), params.schema_path);
@@ -259,7 +261,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
259
261
  return {};
260
262
  });
261
263
  // catalog_table_column_drop
262
- const catalogTableColumnDrop = catalogHandler(signingKey, async (params) => {
264
+ const catalogTableColumnDrop = catalogHandler(keys, async (params) => {
263
265
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_drop");
264
266
  const cat = getCatalog();
265
267
  await cat.tableColumnDrop(
@@ -275,7 +277,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
275
277
  return {};
276
278
  });
277
279
  // catalog_table_column_rename
278
- const catalogTableColumnRename = catalogHandler(signingKey, async (params) => {
280
+ const catalogTableColumnRename = catalogHandler(keys, async (params) => {
279
281
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_rename");
280
282
  const cat = getCatalog();
281
283
  await cat.tableColumnRename(
@@ -290,7 +292,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
290
292
  return {};
291
293
  });
292
294
  // catalog_table_column_comment_set
293
- const catalogTableColumnCommentSet = catalogHandler(signingKey, async (params) => {
295
+ const catalogTableColumnCommentSet = catalogHandler(keys, async (params) => {
294
296
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_comment_set");
295
297
  const cat = getCatalog();
296
298
  await cat.tableColumnCommentSet(
@@ -305,7 +307,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
305
307
  return {};
306
308
  });
307
309
  // catalog_table_column_default_set
308
- const catalogTableColumnDefaultSet = catalogHandler(signingKey, async (params) => {
310
+ const catalogTableColumnDefaultSet = catalogHandler(keys, async (params) => {
309
311
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_default_set");
310
312
  const cat = getCatalog();
311
313
  await cat.tableColumnDefaultSet(
@@ -320,7 +322,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
320
322
  return {};
321
323
  });
322
324
  // catalog_table_column_default_drop
323
- const catalogTableColumnDefaultDrop = catalogHandler(signingKey, async (params) => {
325
+ const catalogTableColumnDefaultDrop = catalogHandler(keys, async (params) => {
324
326
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_default_drop");
325
327
  const cat = getCatalog();
326
328
  await cat.tableColumnDefaultDrop(
@@ -334,7 +336,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
334
336
  return {};
335
337
  });
336
338
  // catalog_table_column_type_change
337
- const catalogTableColumnTypeChange = catalogHandler(signingKey, async (params) => {
339
+ const catalogTableColumnTypeChange = catalogHandler(keys, async (params) => {
338
340
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_type_change");
339
341
  const cat = getCatalog();
340
342
  await cat.tableColumnTypeChange(
@@ -350,7 +352,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
350
352
  return {};
351
353
  });
352
354
  // catalog_table_not_null_set
353
- const catalogTableNotNullSet = catalogHandler(signingKey, async (params) => {
355
+ const catalogTableNotNullSet = catalogHandler(keys, async (params) => {
354
356
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_not_null_set");
355
357
  const cat = getCatalog();
356
358
  await cat.tableNotNullSet(
@@ -364,7 +366,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
364
366
  return {};
365
367
  });
366
368
  // catalog_table_not_null_drop
367
- const catalogTableNotNullDrop = catalogHandler(signingKey, async (params) => {
369
+ const catalogTableNotNullDrop = catalogHandler(keys, async (params) => {
368
370
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_not_null_drop");
369
371
  const cat = getCatalog();
370
372
  await cat.tableNotNullDrop(
@@ -15,11 +15,13 @@ import {
15
15
  import {
16
16
  type GetCatalog,
17
17
  catalogHandler,
18
+ type OpaqueKeys,
18
19
  } from "./shared.js";
19
20
 
20
- export function catalogViewHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array): Partial<VgiService> {
21
+ export function catalogViewHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array, attachSecretKey?: Uint8Array): Partial<VgiService> {
22
+ const keys: OpaqueKeys = { signingKey, attachSecretKey };
21
23
  // catalog_view_get
22
- const catalogViewGet = catalogHandler(signingKey, async (params) => {
24
+ const catalogViewGet = catalogHandler(keys, async (params) => {
23
25
  const cat = getCatalog();
24
26
  const info = await cat.viewGet(
25
27
  toUint8Array(params.attach_opaque_data),
@@ -33,7 +35,7 @@ export function catalogViewHandlers(getCatalog: GetCatalog, signingKey?: Uint8Ar
33
35
  });
34
36
 
35
37
  // catalog_view_create
36
- const catalogViewCreate = catalogHandler(signingKey, async (params) => {
38
+ const catalogViewCreate = catalogHandler(keys, async (params) => {
37
39
  if (params.security !== "regular") throw new Error(`view security mode ${params.security} is unsupported`);
38
40
  const tags = catalogStringMap(params.tags);
39
41
  const columnComments = catalogStringMap(params.column_comments);
@@ -55,7 +57,7 @@ export function catalogViewHandlers(getCatalog: GetCatalog, signingKey?: Uint8Ar
55
57
  });
56
58
 
57
59
  // catalog_view_drop
58
- const catalogViewDrop = catalogHandler(signingKey, async (params) => {
60
+ const catalogViewDrop = catalogHandler(keys, async (params) => {
59
61
  const cat = getCatalog();
60
62
  await cat.viewDrop(
61
63
  toUint8Array(params.attach_opaque_data),
@@ -68,7 +70,7 @@ export function catalogViewHandlers(getCatalog: GetCatalog, signingKey?: Uint8Ar
68
70
  });
69
71
 
70
72
  // catalog_view_rename
71
- const catalogViewRename = catalogHandler(signingKey, async (params) => {
73
+ const catalogViewRename = catalogHandler(keys, async (params) => {
72
74
  const cat = getCatalog();
73
75
  await cat.viewRename(
74
76
  toUint8Array(params.attach_opaque_data),
@@ -82,7 +84,7 @@ export function catalogViewHandlers(getCatalog: GetCatalog, signingKey?: Uint8Ar
82
84
  });
83
85
 
84
86
  // catalog_view_comment_set
85
- const catalogViewCommentSet = catalogHandler(signingKey, async (params) => {
87
+ const catalogViewCommentSet = catalogHandler(keys, async (params) => {
86
88
  const cat = getCatalog();
87
89
  await cat.viewCommentSet(
88
90
  toUint8Array(params.attach_opaque_data),
@@ -95,7 +97,7 @@ export function catalogViewHandlers(getCatalog: GetCatalog, signingKey?: Uint8Ar
95
97
  return {};
96
98
  });
97
99
 
98
- const catalogViewColumnCommentSet = catalogHandler(signingKey, async (params) => {
100
+ const catalogViewColumnCommentSet = catalogHandler(keys, async (params) => {
99
101
  const path: string[] = Array.from(params.column_path);
100
102
  if (path.length !== 1 || !path[0] || path[0].includes("\0")) throw new Error("view column comments require one raw output identifier");
101
103
  await getCatalog().viewColumnCommentSet(
@@ -56,6 +56,8 @@ import {
56
56
  export interface FunctionHandlerConfig {
57
57
  registry: FunctionRegistry;
58
58
  signingKey?: Uint8Array | undefined;
59
+ /** Explicit root key for secret ATTACH options (see attach-secret-options.ts). */
60
+ attachSecretKey?: Uint8Array | undefined;
59
61
  /**
60
62
  * Used to map a bind's `attach_opaque_data` to its catalog, so resolution can
61
63
  * be scoped when two catalogs declare the same schema and function name.
@@ -90,6 +92,7 @@ async function liveSplitAnchor(
90
92
  bindCall: { attach_opaque_data?: Uint8Array | null; transaction_opaque_data?: Uint8Array | null },
91
93
  auth: AuthContext | undefined,
92
94
  signingKey: Uint8Array | undefined,
95
+ attachSecretKey?: Uint8Array,
93
96
  ): Promise<Uint8Array | undefined> {
94
97
  if (!catalogInterface?.version || bindCall.attach_opaque_data == null) return undefined;
95
98
  const raw = toUint8Array(bindCall.attach_opaque_data);
@@ -123,7 +126,7 @@ async function liveSplitAnchor(
123
126
  // every non-HTTP transport).
124
127
  const forms: Array<() => Promise<Uint8Array>> = [
125
128
  async () => raw,
126
- async () => openAttach(raw, auth, signingKey),
129
+ async () => openAttach(raw, auth, signingKey, attachSecretKey),
127
130
  ];
128
131
  for (const form of forms) {
129
132
  try {
@@ -168,6 +171,7 @@ async function resolveSplitPayloads(
168
171
  opts: {
169
172
  auth: any;
170
173
  signingKey: Uint8Array | undefined;
174
+ attachSecretKey?: Uint8Array | undefined;
171
175
  catalogInterface: any;
172
176
  checkAnchor: boolean;
173
177
  },
@@ -182,7 +186,7 @@ async function resolveSplitPayloads(
182
186
  new Uint8Array(0),
183
187
  );
184
188
  const currentAnchor = opts.checkAnchor
185
- ? await liveSplitAnchor(opts.catalogInterface, request.bind_call as any, opts.auth, opts.signingKey)
189
+ ? await liveSplitAnchor(opts.catalogInterface, request.bind_call as any, opts.auth, opts.signingKey, opts.attachSecretKey)
186
190
  : undefined;
187
191
  request.split_payloads = [];
188
192
  for (const token of request.split_tokens) {
@@ -202,7 +206,7 @@ async function resolveSplitPayloads(
202
206
 
203
207
  /** The per-function lifecycle's `vgi.v3` handlers. */
204
208
  export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiService> {
205
- const { registry, signingKey, catalogInterface } = config;
209
+ const { registry, signingKey, catalogInterface, attachSecretKey } = config;
206
210
 
207
211
  // The framework mints every attach as uuid(16) || catalog_bytes (sealed on
208
212
  // HTTP, plaintext on subprocess). Function bodies — like catalog bodies —
@@ -218,7 +222,7 @@ export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiServ
218
222
  if (attach == null) return null;
219
223
  const env = toUint8Array(attach);
220
224
  if (env.length === 0) return env;
221
- return openAttach(env, ctx?.auth ?? currentRequestAuth(), signingKey);
225
+ return openAttach(env, ctx?.auth ?? currentRequestAuth(), signingKey, attachSecretKey);
222
226
  }
223
227
 
224
228
  // Unseal a bind call's opaque values in place, as the catalog handlers do:
@@ -318,6 +322,7 @@ export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiServ
318
322
  await resolveSplitPayloads(request, innerParams, {
319
323
  auth,
320
324
  signingKey,
325
+ attachSecretKey,
321
326
  catalogInterface,
322
327
  checkAnchor: true,
323
328
  });
@@ -429,6 +434,7 @@ export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiServ
429
434
  // authentication for every authenticated caller's own tokens.
430
435
  auth: currentRequestAuth(),
431
436
  signingKey,
437
+ attachSecretKey,
432
438
  catalogInterface,
433
439
  checkAnchor: false,
434
440
  });
@@ -568,7 +574,7 @@ export function functionHandlers(config: FunctionHandlerConfig): Partial<VgiServ
568
574
  const anchor =
569
575
  plan.catalogVersion != null
570
576
  ? splitAnchor(plan.catalogVersion)
571
- : ((await liveSplitAnchor(catalogInterface, request.bind_call as any, ctx?.auth, signingKey)) ??
577
+ : ((await liveSplitAnchor(catalogInterface, request.bind_call as any, ctx?.auth, signingKey, attachSecretKey)) ??
572
578
  splitAnchor(0));
573
579
 
574
580
  const blobs: Uint8Array[] = [];
@@ -37,6 +37,7 @@ import { Arguments } from "../../arguments/arguments.js";
37
37
  export function tableBufferingHandlers(
38
38
  registry: FunctionRegistry,
39
39
  signingKey?: Uint8Array,
40
+ attachSecretKey?: Uint8Array,
40
41
  ): Partial<VgiService> {
41
42
  // `schemaPath` scopes resolution to the schema the caller named. The
42
43
  // buffering process/combine RPCs carry it (protocol 1.2.0), so a name
@@ -74,7 +75,7 @@ export function tableBufferingHandlers(
74
75
  const rawAttach = inner.attach_opaque_data ? toUint8Array(inner.attach_opaque_data) : null;
75
76
  const attach =
76
77
  rawAttach && rawAttach.length > 0
77
- ? await openAttach(rawAttach, ctx?.auth, signingKey)
78
+ ? await openAttach(rawAttach, ctx?.auth, signingKey, attachSecretKey)
78
79
  : rawAttach;
79
80
  const transactionId = inner.transaction_id ? toUint8Array(inner.transaction_id) : null;
80
81
 
@@ -91,6 +91,11 @@ export interface ServeVgiWorkerOptions extends HostingOptions {
91
91
  hostname?: string | undefined;
92
92
  /** Overrides `$VGI_SIGNING_KEY`. 32 bytes. */
93
93
  signingKey?: Uint8Array | undefined;
94
+ /**
95
+ * Optional root key for secret ATTACH options (encrypted inside
96
+ * `attach_opaque_data` for `attachOptions()`). Defaults to the signing key.
97
+ */
98
+ attachSecretKey?: Uint8Array | undefined;
94
99
  /** Overrides `$VGI_TOKEN_TTL` (default 3600 seconds). */
95
100
  tokenTtl?: number | undefined;
96
101
  /** Overrides `$CORS_ORIGINS` (default "*"). Pass `null` to disable CORS. */
@@ -242,7 +247,7 @@ export function createVgiWorkerFetch(
242
247
  const trustedProxyAddresses = bridge?.trustedProxyAddresses ?? ["127.0.0.1"];
243
248
 
244
249
  return createVgiFetch({
245
- protocol: { registry: opts.registry, catalogInterface: opts.catalogInterface },
250
+ protocol: { registry: opts.registry, catalogInterface: opts.catalogInterface, attachSecretKey: opts.attachSecretKey },
246
251
  signingKey,
247
252
  signingKeyConfigured,
248
253
  tokenTtl,
package/src/worker.ts CHANGED
@@ -123,6 +123,15 @@ export interface WorkerConfig extends HostingOptions {
123
123
  * dispatches on. Omit to have the worker create its own.
124
124
  */
125
125
  registry?: FunctionRegistry;
126
+ /**
127
+ * Optional root key for secret ATTACH options (`AttachOptionSpec.secret`),
128
+ * which the framework encrypts inside `attach_opaque_data` for
129
+ * `attachOptions()`. Defaults to the host-local key file
130
+ * (`$VGI_ATTACH_SECRET_KEY_FILE`, else `vgi/attach-secret-options.key` under
131
+ * `$XDG_RUNTIME_DIR` or the per-user temp dir). Every worker process that may
132
+ * receive a given attach must use the same key.
133
+ */
134
+ attachSecretKey?: Uint8Array;
126
135
  }
127
136
 
128
137
  export class Worker {
@@ -130,8 +139,10 @@ export class Worker {
130
139
  private _hosting: HostingOptions;
131
140
  private _catalogInterface: CatalogInterface | undefined;
132
141
  private _catalogName: string | undefined;
142
+ private _attachSecretKey: Uint8Array | undefined;
133
143
 
134
144
  constructor(config: WorkerConfig) {
145
+ this._attachSecretKey = config.attachSecretKey;
135
146
  // Reuse the caller's registry when given: a catalogInterface built
136
147
  // elsewhere recorded its per-schema function ownership there, and that
137
148
  // index is what makes a schema-qualified bind resolve correctly.
@@ -297,6 +308,7 @@ export class Worker {
297
308
  registry: this._registry,
298
309
  catalogInterface: this._catalogInterface,
299
310
  catalogName: this._catalogName,
311
+ attachSecretKey: this._attachSecretKey,
300
312
  });
301
313
  }
302
314