@query-farm/vgi 0.48.4 → 0.48.5

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 (44) 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/client-entry.js +1 -1
  7. package/dist/client-entry.js.map +4 -4
  8. package/dist/index.core.d.ts +2 -0
  9. package/dist/index.js +5700 -5276
  10. package/dist/index.js.map +24 -22
  11. package/dist/protocol/dispatch.d.ts +11 -0
  12. package/dist/protocol/handlers/catalog/admin.d.ts +1 -1
  13. package/dist/protocol/handlers/catalog/index.d.ts +1 -1
  14. package/dist/protocol/handlers/catalog/index_methods.d.ts +1 -1
  15. package/dist/protocol/handlers/catalog/macro.d.ts +1 -1
  16. package/dist/protocol/handlers/catalog/shared.d.ts +28 -3
  17. package/dist/protocol/handlers/catalog/table.d.ts +1 -1
  18. package/dist/protocol/handlers/catalog/view.d.ts +1 -1
  19. package/dist/protocol/handlers/function.d.ts +2 -0
  20. package/dist/protocol/handlers/table-buffering.d.ts +1 -1
  21. package/dist/serve-entry.d.ts +5 -0
  22. package/dist/serve-entry.js +475 -94
  23. package/dist/serve-entry.js.map +18 -16
  24. package/dist/worker-cf-entry.js +497 -93
  25. package/dist/worker-cf-entry.js.map +18 -16
  26. package/dist/worker.d.ts +10 -0
  27. package/package.json +1 -1
  28. package/src/attach-secret-keyfile.ts +185 -0
  29. package/src/attach-secret-options.ts +418 -0
  30. package/src/catalog/attach-option.ts +6 -0
  31. package/src/catalog/interface.ts +19 -0
  32. package/src/index.core.ts +10 -0
  33. package/src/protocol/dispatch.ts +14 -2
  34. package/src/protocol/handlers/catalog/admin.ts +33 -18
  35. package/src/protocol/handlers/catalog/index.ts +6 -5
  36. package/src/protocol/handlers/catalog/index_methods.ts +5 -3
  37. package/src/protocol/handlers/catalog/macro.ts +7 -5
  38. package/src/protocol/handlers/catalog/shared.ts +52 -6
  39. package/src/protocol/handlers/catalog/table.ts +24 -22
  40. package/src/protocol/handlers/catalog/view.ts +9 -7
  41. package/src/protocol/handlers/function.ts +11 -5
  42. package/src/protocol/handlers/table-buffering.ts +2 -1
  43. package/src/serve-entry.ts +6 -1
  44. package/src/worker.ts +12 -0
@@ -8270,13 +8270,382 @@ async function openBytes(token, key, aad, version, field = "opaque data") {
8270
8270
  }
8271
8271
  }
8272
8272
 
8273
+ // src/attach-secret-keyfile.ts
8274
+ function builtins() {
8275
+ const proc = globalThis.process;
8276
+ const get = proc?.getBuiltinModule?.bind(proc);
8277
+ const fs = get?.("node:fs");
8278
+ const os = get?.("node:os");
8279
+ const path = get?.("node:path");
8280
+ if (!fs || !os || !path)
8281
+ throw new Error("this runtime has no filesystem for the host-local attach secret key file.");
8282
+ return { fs, os, path };
8283
+ }
8284
+ var ATTACH_SECRET_KEY_FILE_ENV = "VGI_ATTACH_SECRET_KEY_FILE";
8285
+ var KEY_LEN = 32;
8286
+ var FILE_NAME = "attach-secret-options.key";
8287
+ var REMEDY = "Set VGI_SIGNING_KEY (or configure attachSecretKey), or point VGI_ATTACH_SECRET_KEY_FILE at a valid key file.";
8288
+ function username() {
8289
+ try {
8290
+ const name = builtins().os.userInfo().username;
8291
+ if (name)
8292
+ return name;
8293
+ } catch {}
8294
+ return process.env.USER || process.env.USERNAME || String(process.getuid?.() ?? "user");
8295
+ }
8296
+ function isDirectory(path) {
8297
+ try {
8298
+ return builtins().fs.statSync(path).isDirectory();
8299
+ } catch {
8300
+ return false;
8301
+ }
8302
+ }
8303
+ function hostLocalAttachSecretKeyPath(env = globalThis.process?.env ?? {}) {
8304
+ const { os, path: { join } } = builtins();
8305
+ const explicit = env[ATTACH_SECRET_KEY_FILE_ENV];
8306
+ if (explicit)
8307
+ return explicit;
8308
+ const xdg = env.XDG_RUNTIME_DIR;
8309
+ if (xdg && isDirectory(xdg))
8310
+ return join(xdg, "vgi", FILE_NAME);
8311
+ return join(os.tmpdir(), `vgi-${username()}`, FILE_NAME);
8312
+ }
8313
+ var POSIX = typeof process === "undefined" || process.platform !== "win32";
8314
+ function checkOwnedPrivate(path, mode, uid, what) {
8315
+ if (!POSIX)
8316
+ return;
8317
+ const me = process.getuid?.();
8318
+ if (me !== undefined && uid !== me) {
8319
+ throw new Error(`attach secret key ${what} ${path} is not owned by the current user. ${REMEDY}`);
8320
+ }
8321
+ if ((mode & 63) !== 0) {
8322
+ throw new Error(`attach secret key ${what} ${path} is accessible by group/other (mode ${(mode & 511).toString(8)}); ` + `it must be ${what === "directory" ? "0700" : "0600"}. ${REMEDY}`);
8323
+ }
8324
+ }
8325
+ function ensureDir(dir) {
8326
+ const { mkdirSync, lstatSync } = builtins().fs;
8327
+ try {
8328
+ mkdirSync(dir, { recursive: true, mode: 448 });
8329
+ } catch (e) {
8330
+ if (e.code !== "EEXIST")
8331
+ throw e;
8332
+ }
8333
+ const st = lstatSync(dir);
8334
+ if (!st.isDirectory())
8335
+ throw new Error(`attach secret key directory ${dir} is not a directory. ${REMEDY}`);
8336
+ checkOwnedPrivate(dir, st.mode, st.uid, "directory");
8337
+ }
8338
+ function readKey(path) {
8339
+ const { openSync, fstatSync, readSync, closeSync, constants } = builtins().fs;
8340
+ let fd;
8341
+ try {
8342
+ fd = openSync(path, constants.O_RDONLY | (POSIX ? constants.O_NOFOLLOW : 0));
8343
+ } catch (e) {
8344
+ if (e.code === "ENOENT")
8345
+ return null;
8346
+ throw new Error(`attach secret key file ${path} cannot be opened (${e.code}). ${REMEDY}`);
8347
+ }
8348
+ try {
8349
+ const st = fstatSync(fd);
8350
+ if (!st.isFile())
8351
+ throw new Error(`attach secret key file ${path} is not a regular file. ${REMEDY}`);
8352
+ checkOwnedPrivate(path, st.mode, st.uid, "file");
8353
+ const buf = new Uint8Array(KEY_LEN + 1);
8354
+ let n = 0;
8355
+ for (;; ) {
8356
+ const got = readSync(fd, buf, n, buf.length - n, null);
8357
+ if (got <= 0)
8358
+ break;
8359
+ n += got;
8360
+ if (n === buf.length)
8361
+ break;
8362
+ }
8363
+ if (n !== KEY_LEN || st.size !== KEY_LEN) {
8364
+ throw new Error(`attach secret key file ${path} must contain exactly ${KEY_LEN} raw bytes (found ${st.size}). ${REMEDY}`);
8365
+ }
8366
+ return buf.subarray(0, KEY_LEN);
8367
+ } finally {
8368
+ closeSync(fd);
8369
+ }
8370
+ }
8371
+ function createKey(path) {
8372
+ const { openSync, writeSync, fsyncSync, closeSync, linkSync, unlinkSync, constants } = builtins().fs;
8373
+ const { dirname, join } = builtins().path;
8374
+ const tmp = join(dirname(path), `.${FILE_NAME}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`);
8375
+ const fd = openSync(tmp, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL, 384);
8376
+ try {
8377
+ const key = crypto.getRandomValues(new Uint8Array(KEY_LEN));
8378
+ let off = 0;
8379
+ while (off < KEY_LEN)
8380
+ off += writeSync(fd, key, off, KEY_LEN - off);
8381
+ fsyncSync(fd);
8382
+ } finally {
8383
+ closeSync(fd);
8384
+ }
8385
+ try {
8386
+ linkSync(tmp, path);
8387
+ } catch (e) {
8388
+ if (e.code !== "EEXIST") {
8389
+ unlinkSync(tmp);
8390
+ throw e;
8391
+ }
8392
+ }
8393
+ unlinkSync(tmp);
8394
+ }
8395
+ function loadHostLocalAttachSecretKey(path = hostLocalAttachSecretKeyPath()) {
8396
+ ensureDir(builtins().path.dirname(path));
8397
+ const existing = readKey(path);
8398
+ if (existing)
8399
+ return existing;
8400
+ createKey(path);
8401
+ const created = readKey(path);
8402
+ if (!created)
8403
+ throw new Error(`attach secret key file ${path} vanished after creation. ${REMEDY}`);
8404
+ return created;
8405
+ }
8406
+ var cached;
8407
+ async function hostLocalAttachSecretKey() {
8408
+ const path = hostLocalAttachSecretKeyPath();
8409
+ if (cached?.path === path)
8410
+ return cached.key;
8411
+ const key = loadHostLocalAttachSecretKey(path);
8412
+ cached = { path, key };
8413
+ return key;
8414
+ }
8415
+
8416
+ // src/attach-secret-options.ts
8417
+ var UTF82 = new TextEncoder;
8418
+ var ATTACH_SECRET_OPTIONS_INFO = "vgi.attach_secret_options.v1";
8419
+ var ATTACH_SECRET_OPTIONS_VERSION = 1;
8420
+ var TRAILER_MAGIC = Uint8Array.of(0, 86, 71, 73, 65, 79, 1, 255);
8421
+ var TRAILER_FIXED = 4 + TRAILER_MAGIC.length;
8422
+ var NONCE_LEN2 = 24;
8423
+ var TAG_LEN2 = 16;
8424
+ var AAD_PREFIX = UTF82.encode(`${ATTACH_SECRET_OPTIONS_INFO}\x00`);
8425
+ var UUID_LEN = 16;
8426
+ var FIELD = "attach_opaque_data";
8427
+
8428
+ class AttachSecretKeyUnavailableError extends Error {
8429
+ constructor(message) {
8430
+ super(message);
8431
+ this.name = "AttachSecretKeyUnavailableError";
8432
+ }
8433
+ }
8434
+ var subkeys = new Map;
8435
+ function hexOf(b) {
8436
+ let s = "";
8437
+ for (let i = 0;i < b.length; i++)
8438
+ s += b[i].toString(16).padStart(2, "0");
8439
+ return s;
8440
+ }
8441
+ function deriveAttachSecretKey(root) {
8442
+ const id = hexOf(root);
8443
+ let derived = subkeys.get(id);
8444
+ if (!derived) {
8445
+ derived = (async () => {
8446
+ const ikm = await crypto.subtle.importKey("raw", root, "HKDF", false, ["deriveBits"]);
8447
+ const bits = await crypto.subtle.deriveBits({ name: "HKDF", hash: "SHA-256", salt: new Uint8Array(0), info: UTF82.encode(ATTACH_SECRET_OPTIONS_INFO) }, ikm, 256);
8448
+ return new Uint8Array(bits);
8449
+ })();
8450
+ subkeys.set(id, derived);
8451
+ derived.catch(() => subkeys.delete(id));
8452
+ }
8453
+ return derived;
8454
+ }
8455
+ function defaultHostLocal() {
8456
+ return hostLocalAttachSecretKey();
8457
+ }
8458
+ function noKeyMessage() {
8459
+ return "A secret ATTACH option has a value but this worker has no key to encrypt it with: configure " + "`attachSecretKey`, run with a signing key (VGI_SIGNING_KEY), or run where the host-local key file " + "(VGI_ATTACH_SECRET_KEY_FILE) can be used.";
8460
+ }
8461
+ async function rootKey(source) {
8462
+ if (source.explicit && source.explicit.length > 0)
8463
+ return source.explicit;
8464
+ if (source.signingKey && source.signingKey.length > 0)
8465
+ return source.signingKey;
8466
+ return (source.hostLocal ?? defaultHostLocal)();
8467
+ }
8468
+ function aadFor(uuid) {
8469
+ const out = new Uint8Array(AAD_PREFIX.length + uuid.length);
8470
+ out.set(AAD_PREFIX, 0);
8471
+ out.set(uuid, AAD_PREFIX.length);
8472
+ return out;
8473
+ }
8474
+ function u32le(n) {
8475
+ const b = new Uint8Array(4);
8476
+ new DataView(b.buffer).setUint32(0, n, true);
8477
+ return b;
8478
+ }
8479
+ function readU32le(b, off) {
8480
+ return new DataView(b.buffer, b.byteOffset, b.byteLength).getUint32(off, true);
8481
+ }
8482
+ function concat2(...parts) {
8483
+ let total = 0;
8484
+ for (const p of parts)
8485
+ total += p.length;
8486
+ const out = new Uint8Array(total);
8487
+ let off = 0;
8488
+ for (const p of parts) {
8489
+ out.set(p, off);
8490
+ off += p.length;
8491
+ }
8492
+ return out;
8493
+ }
8494
+ function splitOptions(optionsIpc, secretNames) {
8495
+ if (!optionsIpc || optionsIpc.length === 0)
8496
+ return null;
8497
+ const batch = deserializeBatch(optionsIpc);
8498
+ if (batch.numRows === 0 || batch.schema.fields.length === 0)
8499
+ return null;
8500
+ const row = iterRows(batch).next().value ?? {};
8501
+ const plainFields = [];
8502
+ const secretFields = [];
8503
+ const plainCols = {};
8504
+ const secretCols = {};
8505
+ for (const f of batch.schema.fields) {
8506
+ const value = row[f.name];
8507
+ if (secretNames.has(f.name.toLowerCase()) && value !== null && value !== undefined) {
8508
+ secretFields.push(f);
8509
+ secretCols[f.name] = [value];
8510
+ } else {
8511
+ plainFields.push(f);
8512
+ plainCols[f.name] = [value ?? null];
8513
+ }
8514
+ }
8515
+ return {
8516
+ plain: plainFields.length ? serializeBatch(batchFromColumns(plainCols, schema2(plainFields))) : null,
8517
+ secret: secretFields.length ? serializeBatch(batchFromColumns(secretCols, schema2(secretFields))) : null
8518
+ };
8519
+ }
8520
+ async function packAttachOptionsTrailer(uuid, optionsIpc, secretNames, keys, fixedNonce) {
8521
+ const split = splitOptions(optionsIpc, secretNames);
8522
+ if (split === null)
8523
+ return new Uint8Array(0);
8524
+ const plain = split.plain ?? new Uint8Array(0);
8525
+ let secret = new Uint8Array(0);
8526
+ if (split.secret) {
8527
+ let root;
8528
+ try {
8529
+ root = await rootKey(keys);
8530
+ } catch (e) {
8531
+ if (e instanceof AttachSecretKeyUnavailableError)
8532
+ throw e;
8533
+ throw new AttachSecretKeyUnavailableError(`${noKeyMessage()} ${e.message}`);
8534
+ }
8535
+ const key = await deriveAttachSecretKey(root);
8536
+ const nonce = fixedNonce ?? crypto.getRandomValues(new Uint8Array(NONCE_LEN2));
8537
+ const ct = xchacha20poly1305(key, nonce, aadFor(uuid)).encrypt(split.secret);
8538
+ secret = concat2(Uint8Array.of(ATTACH_SECRET_OPTIONS_VERSION), nonce, ct);
8539
+ }
8540
+ const body = concat2(u32le(plain.length), plain, secret);
8541
+ return concat2(body, u32le(body.length), TRAILER_MAGIC);
8542
+ }
8543
+ function endsWithMagic(b) {
8544
+ if (b.length < TRAILER_MAGIC.length)
8545
+ return false;
8546
+ const off = b.length - TRAILER_MAGIC.length;
8547
+ for (let i = 0;i < TRAILER_MAGIC.length; i++)
8548
+ if (b[off + i] !== TRAILER_MAGIC[i])
8549
+ return false;
8550
+ return true;
8551
+ }
8552
+ function decodeOptions(ipc) {
8553
+ const batch = deserializeBatch(ipc);
8554
+ if (batch.numRows === 0)
8555
+ return {};
8556
+ return { ...iterRows(batch).next().value ?? {} };
8557
+ }
8558
+ var registry = new WeakMap;
8559
+ var EMPTY = Object.freeze({});
8560
+ async function openFrameworkAttach(full, keys) {
8561
+ if (full.length < UUID_LEN)
8562
+ return full;
8563
+ const copy = full.slice();
8564
+ let end = copy.length;
8565
+ let options = EMPTY;
8566
+ if (copy.length >= UUID_LEN + TRAILER_FIXED && endsWithMagic(copy)) {
8567
+ const bodyLen = readU32le(copy, copy.length - TRAILER_FIXED);
8568
+ const bodyStart = copy.length - TRAILER_FIXED - bodyLen;
8569
+ if (bodyLen < 4 || bodyStart < UUID_LEN)
8570
+ throw new OpaqueDataRejectedError(FIELD);
8571
+ const body = copy.subarray(bodyStart, copy.length - TRAILER_FIXED);
8572
+ const plainLen = readU32le(body, 0);
8573
+ if (4 + plainLen > body.length)
8574
+ throw new OpaqueDataRejectedError(FIELD);
8575
+ const plain = body.subarray(4, 4 + plainLen);
8576
+ const secret = body.subarray(4 + plainLen);
8577
+ const values = {};
8578
+ try {
8579
+ if (plain.length)
8580
+ Object.assign(values, decodeOptions(plain));
8581
+ } catch {
8582
+ throw new OpaqueDataRejectedError(FIELD);
8583
+ }
8584
+ if (secret.length) {
8585
+ if (secret.length < 1 + NONCE_LEN2 + TAG_LEN2 || secret[0] !== ATTACH_SECRET_OPTIONS_VERSION) {
8586
+ throw new OpaqueDataRejectedError(FIELD);
8587
+ }
8588
+ let opened;
8589
+ try {
8590
+ const key = await deriveAttachSecretKey(await rootKey(keys));
8591
+ const nonce = secret.subarray(1, 1 + NONCE_LEN2);
8592
+ opened = xchacha20poly1305(key, nonce, aadFor(copy.subarray(0, UUID_LEN))).decrypt(secret.subarray(1 + NONCE_LEN2));
8593
+ } catch {
8594
+ throw new OpaqueDataRejectedError(FIELD);
8595
+ }
8596
+ try {
8597
+ Object.assign(values, decodeOptions(opened));
8598
+ } catch {
8599
+ throw new OpaqueDataRejectedError(FIELD);
8600
+ }
8601
+ }
8602
+ options = Object.freeze(values);
8603
+ end = bodyStart;
8604
+ }
8605
+ registry.set(copy.buffer, options);
8606
+ return copy.subarray(UUID_LEN, end);
8607
+ }
8608
+ async function secretAttachOptionNames(catalog, name, deserialize) {
8609
+ const names = new Set;
8610
+ if (typeof catalog.attachOptionSpecs === "function") {
8611
+ for (const spec of catalog.attachOptionSpecs(name) ?? [])
8612
+ if (spec.secret)
8613
+ names.add(spec.name.toLowerCase());
8614
+ }
8615
+ if (typeof catalog.catalogsInfo === "function") {
8616
+ let infos;
8617
+ try {
8618
+ infos = await catalog.catalogsInfo();
8619
+ } catch {
8620
+ infos = [];
8621
+ }
8622
+ for (const info of infos ?? []) {
8623
+ if (info.name !== name)
8624
+ continue;
8625
+ for (const raw of info.attach_option_specs ?? []) {
8626
+ try {
8627
+ const spec = deserialize(raw);
8628
+ if (spec.secret)
8629
+ names.add(spec.name.toLowerCase());
8630
+ } catch {}
8631
+ }
8632
+ }
8633
+ }
8634
+ return names;
8635
+ }
8636
+
8273
8637
  // src/protocol/handlers/catalog/shared.ts
8274
- async function sealAttach(plaintext, auth, signingKey) {
8638
+ async function sealAttach(plaintext, auth, signingKey, options) {
8275
8639
  const uuid = new Uint8Array(ATTACH_UUID_LEN);
8276
8640
  crypto.getRandomValues(uuid);
8277
- const minted = new Uint8Array(ATTACH_UUID_LEN + plaintext.length);
8641
+ const trailer = options ? await packAttachOptionsTrailer(uuid, options.optionsIpc, options.secretNames, {
8642
+ explicit: options.attachSecretKey,
8643
+ signingKey
8644
+ }) : new Uint8Array(0);
8645
+ const minted = new Uint8Array(ATTACH_UUID_LEN + plaintext.length + trailer.length);
8278
8646
  minted.set(uuid, 0);
8279
8647
  minted.set(plaintext, ATTACH_UUID_LEN);
8648
+ minted.set(trailer, ATTACH_UUID_LEN + plaintext.length);
8280
8649
  if (!signingKey)
8281
8650
  return minted;
8282
8651
  return sealBytes(minted, signingKey, attachAad(auth), ATTACH_ENVELOPE_VERSION);
@@ -8286,9 +8655,9 @@ async function openAttachFull(envelope, auth, signingKey) {
8286
8655
  return envelope;
8287
8656
  return openBytes(envelope, signingKey, attachAad(auth), ATTACH_ENVELOPE_VERSION, "attach_opaque_data");
8288
8657
  }
8289
- async function openAttach(envelope, auth, signingKey) {
8658
+ async function openAttach(envelope, auth, signingKey, attachSecretKey) {
8290
8659
  const full = await openAttachFull(envelope, auth, signingKey);
8291
- return full.length < ATTACH_UUID_LEN ? full : full.subarray(ATTACH_UUID_LEN);
8660
+ return openFrameworkAttach(full, { explicit: attachSecretKey, signingKey });
8292
8661
  }
8293
8662
  async function sealTransaction(plaintext, attachEnvelope, auth, signingKey) {
8294
8663
  if (!signingKey)
@@ -8300,7 +8669,8 @@ async function openTransaction(envelope, attachEnvelope, auth, signingKey) {
8300
8669
  return envelope;
8301
8670
  return openBytes(envelope, signingKey, transactionAad(auth, attachEnvelope), TRANSACTION_ENVELOPE_VERSION, "transaction_opaque_data");
8302
8671
  }
8303
- async function unwrapParamsOpaque(params, ctx, signingKey) {
8672
+ async function unwrapParamsOpaque(params, ctx, keys) {
8673
+ const { signingKey, attachSecretKey } = keys;
8304
8674
  const auth = ctx?.auth;
8305
8675
  let sealedAttach = new Uint8Array(0);
8306
8676
  if (params.attach_opaque_data != null) {
@@ -8308,7 +8678,7 @@ async function unwrapParamsOpaque(params, ctx, signingKey) {
8308
8678
  if (env.length > 0) {
8309
8679
  sealedAttach = env;
8310
8680
  const full = signingKey ? await openBytes(env, signingKey, attachAad(auth), ATTACH_ENVELOPE_VERSION, "attach_opaque_data") : env;
8311
- params.attach_opaque_data = full.length < ATTACH_UUID_LEN ? full : full.subarray(ATTACH_UUID_LEN);
8681
+ params.attach_opaque_data = await openFrameworkAttach(full, { explicit: attachSecretKey, signingKey });
8312
8682
  }
8313
8683
  }
8314
8684
  if (signingKey && params.transaction_opaque_data != null) {
@@ -8318,14 +8688,15 @@ async function unwrapParamsOpaque(params, ctx, signingKey) {
8318
8688
  }
8319
8689
  }
8320
8690
  }
8321
- function catalogHandler(signingKey, handler) {
8691
+ function catalogHandler(keysOrSigningKey, handler) {
8692
+ const keys = keysOrSigningKey instanceof Uint8Array || keysOrSigningKey === undefined ? { signingKey: keysOrSigningKey } : keysOrSigningKey;
8322
8693
  return async (wire, ctx) => {
8323
8694
  let params = wire;
8324
8695
  if (params.request != null && params.attach_opaque_data === undefined && params.name === undefined) {
8325
8696
  params = unwrapRequest(params.request);
8326
8697
  }
8327
8698
  normalizeRequestSchemaPaths(params);
8328
- await unwrapParamsOpaque(params, ctx, signingKey);
8699
+ await unwrapParamsOpaque(params, ctx, keys);
8329
8700
  return handler(params, ctx);
8330
8701
  };
8331
8702
  }
@@ -8467,7 +8838,7 @@ var RESERVED_FLAGS_MASK = 254;
8467
8838
  var FINGERPRINT_LEN = 16;
8468
8839
  var HEADER_LEN = 4 + FINGERPRINT_LEN;
8469
8840
  var SEAL_VERSION = 1;
8470
- var AAD_PREFIX = new TextEncoder().encode("vgi.split_token.v1\x00");
8841
+ var AAD_PREFIX2 = new TextEncoder().encode("vgi.split_token.v1\x00");
8471
8842
  var SPLIT_TOKEN_INVALID = "SPLIT_TOKEN_INVALID";
8472
8843
  var SPLIT_SNAPSHOT_EXPIRED = "SPLIT_SNAPSHOT_EXPIRED";
8473
8844
  class SplitTokenError extends Error {
@@ -8478,7 +8849,7 @@ class SplitTokenError extends Error {
8478
8849
  this.kind = kind;
8479
8850
  }
8480
8851
  }
8481
- function concat2(...parts) {
8852
+ function concat3(...parts) {
8482
8853
  const total = parts.reduce((n, p) => n + p.length, 0);
8483
8854
  const out = new Uint8Array(total);
8484
8855
  let at = 0;
@@ -8499,13 +8870,13 @@ function equalBytes2(a, b) {
8499
8870
  async function bindFingerprint(schemaPath, functionName, args, settings, projection) {
8500
8871
  const enc = new TextEncoder;
8501
8872
  const zero = Uint8Array.of(0);
8502
- const field = (label, value) => concat2(enc.encode(label), zero, value, zero);
8503
- const message = concat2(AAD_PREFIX, field("schema_path", enc.encode(JSON.stringify(schemaPath))), field("function_name", enc.encode(functionName)), field("arguments", args), field("settings", settings), field("projection_ids", projection));
8873
+ const field = (label, value) => concat3(enc.encode(label), zero, value, zero);
8874
+ const message = concat3(AAD_PREFIX2, field("schema_path", enc.encode(JSON.stringify(schemaPath))), field("function_name", enc.encode(functionName)), field("arguments", args), field("settings", settings), field("projection_ids", projection));
8504
8875
  const digest = await crypto.subtle.digest("SHA-256", message);
8505
8876
  return new Uint8Array(digest).slice(0, FINGERPRINT_LEN);
8506
8877
  }
8507
8878
  function splitTokenAad(header, auth) {
8508
- return concat2(header, identityTail(auth));
8879
+ return concat3(header, identityTail(auth));
8509
8880
  }
8510
8881
  function splitAnchor(catalogVersion) {
8511
8882
  const out = new Uint8Array(8);
@@ -8524,11 +8895,11 @@ async function buildSplitToken(opts) {
8524
8895
  head[0] = SPLIT_TOKEN_FORMAT_VERSION;
8525
8896
  head[1] = signingKey ? FLAG_PAYLOAD_SEALED : 0;
8526
8897
  new DataView(head.buffer).setUint16(2, anchor.length, true);
8527
- const body = concat2(head, fingerprint, anchor);
8898
+ const body = concat3(head, fingerprint, anchor);
8528
8899
  if (!signingKey)
8529
- return concat2(body, payload);
8900
+ return concat3(body, payload);
8530
8901
  const sealed = await sealBytes(payload, signingKey, splitTokenAad(body, auth), SEAL_VERSION);
8531
- return concat2(body, sealed);
8902
+ return concat3(body, sealed);
8532
8903
  }
8533
8904
  async function openSplitToken(token, opts = {}) {
8534
8905
  const { signingKey, auth, expectedFingerprint, currentAnchor } = opts;
@@ -8576,7 +8947,7 @@ async function openSplitToken(token, opts = {}) {
8576
8947
  }
8577
8948
 
8578
8949
  // src/protocol/handlers/function.ts
8579
- async function liveSplitAnchor(catalogInterface, bindCall, auth, signingKey) {
8950
+ async function liveSplitAnchor(catalogInterface, bindCall, auth, signingKey, attachSecretKey) {
8580
8951
  if (!catalogInterface?.version || bindCall.attach_opaque_data == null)
8581
8952
  return;
8582
8953
  const raw = toUint8Array(bindCall.attach_opaque_data);
@@ -8588,7 +8959,7 @@ async function liveSplitAnchor(catalogInterface, bindCall, auth, signingKey) {
8588
8959
  }
8589
8960
  const forms = [
8590
8961
  async () => raw,
8591
- async () => openAttach(raw, auth, signingKey)
8962
+ async () => openAttach(raw, auth, signingKey, attachSecretKey)
8592
8963
  ];
8593
8964
  for (const form of forms) {
8594
8965
  try {
@@ -8602,7 +8973,7 @@ async function resolveSplitPayloads(request, innerParams, opts) {
8602
8973
  return;
8603
8974
  const fp = fingerprintInputs(toUint8Array(innerParams.bind_call));
8604
8975
  const expected = await bindFingerprint(fp.schemaPath, fp.functionName, fp.args, fp.settings, new Uint8Array(0));
8605
- const currentAnchor = opts.checkAnchor ? await liveSplitAnchor(opts.catalogInterface, request.bind_call, opts.auth, opts.signingKey) : undefined;
8976
+ const currentAnchor = opts.checkAnchor ? await liveSplitAnchor(opts.catalogInterface, request.bind_call, opts.auth, opts.signingKey, opts.attachSecretKey) : undefined;
8606
8977
  request.split_payloads = [];
8607
8978
  for (const token of request.split_tokens) {
8608
8979
  request.split_payloads.push(await openSplitToken(token, {
@@ -8614,14 +8985,14 @@ async function resolveSplitPayloads(request, innerParams, opts) {
8614
8985
  }
8615
8986
  }
8616
8987
  function functionHandlers(config) {
8617
- const { registry, signingKey, catalogInterface } = config;
8988
+ const { registry, signingKey, catalogInterface, attachSecretKey } = config;
8618
8989
  async function stripAttach(attach, ctx) {
8619
8990
  if (attach == null)
8620
8991
  return null;
8621
8992
  const env = toUint8Array(attach);
8622
8993
  if (env.length === 0)
8623
8994
  return env;
8624
- return openAttach(env, ctx?.auth ?? currentRequestAuth(), signingKey);
8995
+ return openAttach(env, ctx?.auth ?? currentRequestAuth(), signingKey, attachSecretKey);
8625
8996
  }
8626
8997
  async function openOpaque(bindCall, ctx) {
8627
8998
  const sealedAttach = bindCall.attach_opaque_data != null ? toUint8Array(bindCall.attach_opaque_data) : new Uint8Array(0);
@@ -8666,6 +9037,7 @@ function functionHandlers(config) {
8666
9037
  await resolveSplitPayloads(request, innerParams, {
8667
9038
  auth,
8668
9039
  signingKey,
9040
+ attachSecretKey,
8669
9041
  catalogInterface,
8670
9042
  checkAnchor: true
8671
9043
  });
@@ -8711,6 +9083,7 @@ function functionHandlers(config) {
8711
9083
  await resolveSplitPayloads(request, { bind_call: carried.bindCallIpc }, {
8712
9084
  auth: currentRequestAuth(),
8713
9085
  signingKey,
9086
+ attachSecretKey,
8714
9087
  catalogInterface,
8715
9088
  checkAnchor: false
8716
9089
  });
@@ -8782,7 +9155,7 @@ function functionHandlers(config) {
8782
9155
  const plan = func.plan ? await func.plan(request) : { splits: [{ payload: new Uint8Array(0) }] };
8783
9156
  const fp = fingerprintInputs(toUint8Array(innerParams.bind_call));
8784
9157
  const fingerprint = await bindFingerprint(fp.schemaPath, fp.functionName, fp.args, fp.settings, new Uint8Array(0));
8785
- const anchor = plan.catalogVersion != null ? splitAnchor(plan.catalogVersion) : await liveSplitAnchor(catalogInterface, request.bind_call, ctx?.auth, signingKey) ?? splitAnchor(0);
9158
+ const anchor = plan.catalogVersion != null ? splitAnchor(plan.catalogVersion) : await liveSplitAnchor(catalogInterface, request.bind_call, ctx?.auth, signingKey, attachSecretKey) ?? splitAnchor(0);
8786
9159
  const blobs = [];
8787
9160
  for (const split of plan.splits) {
8788
9161
  const token = await buildSplitToken({
@@ -9308,7 +9681,7 @@ function splitLenPrefixed(buf, count) {
9308
9681
  }
9309
9682
 
9310
9683
  // src/protocol/handlers/table-buffering.ts
9311
- function tableBufferingHandlers(registry, signingKey) {
9684
+ function tableBufferingHandlers(registry, signingKey, attachSecretKey) {
9312
9685
  function resolveBuffering(name, schemaPath) {
9313
9686
  const func = registry.get(name, {
9314
9687
  arguments: new Arguments,
@@ -9325,7 +9698,7 @@ function tableBufferingHandlers(registry, signingKey) {
9325
9698
  const functionName = inner.function_name;
9326
9699
  const executionId = toUint8Array(inner.execution_id);
9327
9700
  const rawAttach = inner.attach_opaque_data ? toUint8Array(inner.attach_opaque_data) : null;
9328
- const attach = rawAttach && rawAttach.length > 0 ? await openAttach(rawAttach, ctx?.auth, signingKey) : rawAttach;
9701
+ const attach = rawAttach && rawAttach.length > 0 ? await openAttach(rawAttach, ctx?.auth, signingKey, attachSecretKey) : rawAttach;
9329
9702
  const transactionId = inner.transaction_id ? toUint8Array(inner.transaction_id) : null;
9330
9703
  const func = resolveBuffering(functionName, inner.schema_path ?? null);
9331
9704
  const bound = new BoundStorage(storage, executionId);
@@ -10595,9 +10968,9 @@ var TICKET_ENVELOPE_VERSION = 1;
10595
10968
  var MAX_OPTIONS_BYTES = 16 * 1024;
10596
10969
  var MAX_TICKET_CHARS = 32 * 1024;
10597
10970
  var CLOCK_SKEW_SECONDS = 60;
10598
- var UTF82 = new TextEncoder;
10971
+ var UTF83 = new TextEncoder;
10599
10972
  var STRICT_UTF8 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
10600
- var TICKET_AAD_DOMAIN = UTF82.encode("vgi.attach_ticket.v1\x00");
10973
+ var TICKET_AAD_DOMAIN = UTF83.encode("vgi.attach_ticket.v1\x00");
10601
10974
  var TICKET_ID = /^[0-9a-f]{32}$/;
10602
10975
  var B64URL = /^[A-Za-z0-9_-]+$/;
10603
10976
  var MAX_TEXT = 65535;
@@ -10651,14 +11024,14 @@ class SealAttachDeniedError extends Error {
10651
11024
  }
10652
11025
  }
10653
11026
  function attachTicketAad(principal) {
10654
- const p = UTF82.encode(principal);
11027
+ const p = UTF83.encode(principal);
10655
11028
  const out = new Uint8Array(TICKET_AAD_DOMAIN.length + p.length);
10656
11029
  out.set(TICKET_AAD_DOMAIN, 0);
10657
11030
  out.set(p, TICKET_AAD_DOMAIN.length);
10658
11031
  return out;
10659
11032
  }
10660
11033
  function packText(value, name) {
10661
- const raw = UTF82.encode(value);
11034
+ const raw = UTF83.encode(value);
10662
11035
  if (raw.length > MAX_TEXT)
10663
11036
  throw new Error(`${name} is longer than 65535 bytes`);
10664
11037
  const out = new Uint8Array(2 + raw.length);
@@ -10982,8 +11355,9 @@ function buildAttachTicketsProtocol(config) {
10982
11355
  }
10983
11356
 
10984
11357
  // src/protocol/handlers/catalog/admin.ts
10985
- function catalogAdminHandlers(getCatalog, signingKey) {
10986
- const catalogCatalogs = catalogHandler(signingKey, async () => {
11358
+ function catalogAdminHandlers(getCatalog, signingKey, attachSecretKey) {
11359
+ const keys = { signingKey, attachSecretKey };
11360
+ const catalogCatalogs = catalogHandler(keys, async () => {
10987
11361
  const cat = getCatalog();
10988
11362
  const infos = cat.catalogsInfo ? await cat.catalogsInfo() : cat.catalogs().map((name) => ({
10989
11363
  name,
@@ -11014,29 +11388,31 @@ function catalogAdminHandlers(getCatalog, signingKey) {
11014
11388
  result.catalog_capabilities = encodeCatalogCapabilities(catalogCapabilities(advertised));
11015
11389
  result.selected_capabilities = encodeCatalogCapabilities(selectCatalogCapabilities(advertised, clientCapabilities, result.supports_transactions ?? false));
11016
11390
  }
11017
- const sealedAttach = await sealAttach(toUint8Array(result.attach_opaque_data), ctx?.auth, signingKey);
11391
+ const optionsIpc = innerParams.options == null ? null : toUint8Array(innerParams.options);
11392
+ const secretNames = optionsIpc && optionsIpc.length > 0 ? await secretAttachOptionNames(cat, innerParams.name, deserializeAttachOptionSpec) : new Set;
11393
+ const sealedAttach = await sealAttach(toUint8Array(result.attach_opaque_data), ctx?.auth, signingKey, { optionsIpc, secretNames, attachSecretKey });
11018
11394
  return wrapResult(buildCatalogAttachResult({
11019
11395
  ...result,
11020
11396
  attach_opaque_data: sealedAttach,
11021
11397
  supports_column_statistics: result.supports_column_statistics ?? true
11022
11398
  }), CatalogAttachResultSchema);
11023
11399
  };
11024
- const catalogDetach = catalogHandler(signingKey, async (params) => {
11400
+ const catalogDetach = catalogHandler(keys, async (params) => {
11025
11401
  const cat = getCatalog();
11026
11402
  await cat.detach(toUint8Array(params.attach_opaque_data));
11027
11403
  return {};
11028
11404
  });
11029
- const catalogCreate = catalogHandler(signingKey, async (params) => {
11405
+ const catalogCreate = catalogHandler(keys, async (params) => {
11030
11406
  const cat = getCatalog();
11031
11407
  await cat.create(params.name, params.on_conflict, params.options);
11032
11408
  return {};
11033
11409
  });
11034
- const catalogDrop = catalogHandler(signingKey, async (params) => {
11410
+ const catalogDrop = catalogHandler(keys, async (params) => {
11035
11411
  const cat = getCatalog();
11036
11412
  await cat.drop(params.name);
11037
11413
  return {};
11038
11414
  });
11039
- const catalogVersion = catalogHandler(signingKey, async (params) => {
11415
+ const catalogVersion = catalogHandler(keys, async (params) => {
11040
11416
  const cat = getCatalog();
11041
11417
  const version = await cat.version(toUint8Array(params.attach_opaque_data), params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11042
11418
  return wrapResult({ version }, CatalogVersionResultSchema);
@@ -11044,23 +11420,23 @@ function catalogAdminHandlers(getCatalog, signingKey) {
11044
11420
  const catalogTransactionBegin = async (params, ctx) => {
11045
11421
  const auth = ctx?.auth;
11046
11422
  const sealedAttach = params.attach_opaque_data != null ? toUint8Array(params.attach_opaque_data) : new Uint8Array(0);
11047
- const attachPlain = await openAttach(sealedAttach, auth, signingKey);
11423
+ const attachPlain = await openAttach(sealedAttach, auth, signingKey, attachSecretKey);
11048
11424
  const cat = getCatalog();
11049
11425
  const txPlain = await cat.transactionBegin(attachPlain);
11050
11426
  const transaction_opaque_data = txPlain != null ? await sealTransaction(toUint8Array(txPlain), sealedAttach, auth, signingKey) : null;
11051
11427
  return wrapResult({ transaction_opaque_data }, CatalogTransactionBeginResultSchema);
11052
11428
  };
11053
- const catalogTransactionCommit = catalogHandler(signingKey, async (params) => {
11429
+ const catalogTransactionCommit = catalogHandler(keys, async (params) => {
11054
11430
  const cat = getCatalog();
11055
11431
  await cat.transactionCommit(toUint8Array(params.attach_opaque_data), toUint8Array(params.transaction_opaque_data));
11056
11432
  return {};
11057
11433
  });
11058
- const catalogTransactionRollback = catalogHandler(signingKey, async (params) => {
11434
+ const catalogTransactionRollback = catalogHandler(keys, async (params) => {
11059
11435
  const cat = getCatalog();
11060
11436
  await cat.transactionRollback(toUint8Array(params.attach_opaque_data), toUint8Array(params.transaction_opaque_data));
11061
11437
  return {};
11062
11438
  });
11063
- const catalogSchemas = catalogHandler(signingKey, async (params) => {
11439
+ const catalogSchemas = catalogHandler(keys, async (params) => {
11064
11440
  const cat = getCatalog();
11065
11441
  const schemas = await cat.schemas(toUint8Array(params.attach_opaque_data), params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11066
11442
  return wrapResult({
@@ -11069,52 +11445,52 @@ function catalogAdminHandlers(getCatalog, signingKey) {
11069
11445
  });
11070
11446
  const catalogContents = async (params, ctx) => {
11071
11447
  const sealedAttach = toUint8Array(params.attach_opaque_data).slice();
11072
- return catalogHandler(signingKey, async (opened, context) => {
11448
+ return catalogHandler(keys, async (opened, context) => {
11073
11449
  const ifNoneMatch = opened.if_none_match == null ? null : String(opened.if_none_match);
11074
11450
  return serveCatalogContents(getCatalog(), toUint8Array(opened.attach_opaque_data), ifNoneMatch, context, sealedAttach);
11075
11451
  })(params, ctx);
11076
11452
  };
11077
- const catalogCopyFromFormats = catalogHandler(signingKey, async (params) => {
11453
+ const catalogCopyFromFormats = catalogHandler(keys, async (params) => {
11078
11454
  const cat = getCatalog();
11079
11455
  const formats = await cat.copyFromFormats(toUint8Array(params.attach_opaque_data), params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11080
11456
  return wrapResult({
11081
11457
  items: formats.map((f) => encodeCopyFromFormatInfo(f))
11082
11458
  }, CatalogCopyFromFormatsResultSchema);
11083
11459
  });
11084
- const catalogSchemaGet = catalogHandler(signingKey, async (params) => {
11460
+ const catalogSchemaGet = catalogHandler(keys, async (params) => {
11085
11461
  const cat = getCatalog();
11086
11462
  const info = await cat.schemaGet(toUint8Array(params.attach_opaque_data), params.path, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11087
11463
  return wrapResult({
11088
11464
  items: info ? [encodeSchemaInfo(info)] : []
11089
11465
  }, CatalogSchemaGetResultSchema);
11090
11466
  });
11091
- const catalogSchemaCreate = catalogHandler(signingKey, async (params) => {
11467
+ const catalogSchemaCreate = catalogHandler(keys, async (params) => {
11092
11468
  if (params.options != null)
11093
11469
  throw new MethodNotImplementedError2("catalog_schema_create requires negotiated vgi.schema.options.create.v1");
11094
11470
  const cat = getCatalog();
11095
11471
  await cat.schemaCreate(toUint8Array(params.attach_opaque_data), Array.from(params.path), params.comment, catalogStringMap(params.tags), params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined, decodeDictValue(params.on_conflict));
11096
11472
  return {};
11097
11473
  });
11098
- const catalogSchemaDrop = catalogHandler(signingKey, async (params) => {
11474
+ const catalogSchemaDrop = catalogHandler(keys, async (params) => {
11099
11475
  const cat = getCatalog();
11100
11476
  await cat.schemaDrop(toUint8Array(params.attach_opaque_data), params.path, params.ignore_not_found, params.cascade, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11101
11477
  return {};
11102
11478
  });
11103
- const catalogSchemaContentsTables = catalogHandler(signingKey, async (params) => {
11479
+ const catalogSchemaContentsTables = catalogHandler(keys, async (params) => {
11104
11480
  const cat = getCatalog();
11105
11481
  const tables = await cat.schemaContentsTables(toUint8Array(params.attach_opaque_data), params.path, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11106
11482
  return wrapResult({
11107
11483
  items: tables.map((t) => encodeValidatedTableInfo(t))
11108
11484
  }, CatalogSchemaContentsTablesResultSchema);
11109
11485
  });
11110
- const catalogSchemaContentsViews = catalogHandler(signingKey, async (params) => {
11486
+ const catalogSchemaContentsViews = catalogHandler(keys, async (params) => {
11111
11487
  const cat = getCatalog();
11112
11488
  const views = await cat.schemaContentsViews(toUint8Array(params.attach_opaque_data), params.path, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11113
11489
  return wrapResult({
11114
11490
  items: views.map((v) => encodeViewInfo(v))
11115
11491
  }, CatalogSchemaContentsViewsResultSchema);
11116
11492
  });
11117
- const catalogSchemaContentsFunctions = catalogHandler(signingKey, async (params) => {
11493
+ const catalogSchemaContentsFunctions = catalogHandler(keys, async (params) => {
11118
11494
  const cat = getCatalog();
11119
11495
  const funcs = await cat.schemaContentsFunctions(toUint8Array(params.attach_opaque_data), params.path, decodeDictValue(params.type), params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11120
11496
  return wrapResult({
@@ -11191,15 +11567,16 @@ function requireFlatColumnPath(value, operation) {
11191
11567
  }
11192
11568
  return path;
11193
11569
  }
11194
- function catalogTableHandlers(getCatalog, signingKey) {
11195
- const catalogTableGet = catalogHandler(signingKey, async (params) => {
11570
+ function catalogTableHandlers(getCatalog, signingKey, attachSecretKey) {
11571
+ const keys = { signingKey, attachSecretKey };
11572
+ const catalogTableGet = catalogHandler(keys, async (params) => {
11196
11573
  const cat = getCatalog();
11197
11574
  const info = await cat.tableGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.at_unit, params.at_value, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11198
11575
  return wrapResult({
11199
11576
  items: info ? [encodeValidatedTableInfo(info)] : []
11200
11577
  }, CatalogTableGetResultSchema);
11201
11578
  });
11202
- const catalogTableCreate = catalogHandler(signingKey, async (params) => {
11579
+ const catalogTableCreate = catalogHandler(keys, async (params) => {
11203
11580
  if (params.constraint_definitions == null)
11204
11581
  throw new Error("constraint_definitions is required");
11205
11582
  const definitions = Array.from(params.constraint_definitions, (d) => toUint8Array(d));
@@ -11220,7 +11597,7 @@ function catalogTableHandlers(getCatalog, signingKey) {
11220
11597
  await cat.tableCreate(attach, params.schema_path, params.name, toUint8Array(params.columns), params.on_conflict, definitions, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11221
11598
  return {};
11222
11599
  });
11223
- const catalogTableConstraintsApply = catalogHandler(signingKey, async (params) => {
11600
+ const catalogTableConstraintsApply = catalogHandler(keys, async (params) => {
11224
11601
  const attach = toUint8Array(params.attach_opaque_data);
11225
11602
  const cat = getCatalog();
11226
11603
  const caps = await cat.catalogCapabilities(attach);
@@ -11253,50 +11630,50 @@ function catalogTableHandlers(getCatalog, signingKey) {
11253
11630
  }
11254
11631
  return wrapResult({ table, definition_revision: revision, constraints: snapshot.constraints.map((c) => toUint8Array(c)) }, CatalogTableConstraintsApplyResultSchema);
11255
11632
  });
11256
- const catalogTableDrop = catalogHandler(signingKey, async (params) => {
11633
+ const catalogTableDrop = catalogHandler(keys, async (params) => {
11257
11634
  const cat = getCatalog();
11258
11635
  await cat.tableDrop(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11259
11636
  return {};
11260
11637
  });
11261
- const catalogTableColumnStatisticsGet = catalogHandler(signingKey, async (params) => {
11638
+ const catalogTableColumnStatisticsGet = catalogHandler(keys, async (params) => {
11262
11639
  const cat = getCatalog();
11263
11640
  const stats = await cat.tableColumnStatisticsGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11264
11641
  return { result: stats?.bytes ?? null };
11265
11642
  });
11266
- const catalogTableScanFunctionGet = catalogHandler(signingKey, async (params) => {
11643
+ const catalogTableScanFunctionGet = catalogHandler(keys, async (params) => {
11267
11644
  const cat = getCatalog();
11268
11645
  const scanResult = await cat.tableScanFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.at_unit, params.at_value, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11269
11646
  return wrapResult(scanResult, ScanFunctionResultSchema);
11270
11647
  });
11271
11648
  const optionalTx = (params) => params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined;
11272
- const catalogTableInsertFunctionGet = catalogHandler(signingKey, async (params) => {
11649
+ const catalogTableInsertFunctionGet = catalogHandler(keys, async (params) => {
11273
11650
  const result = await getCatalog().tableInsertFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, optionalTx(params), params.writable_branch_function_name ?? null);
11274
11651
  return wrapResult(result, ScanFunctionResultSchema);
11275
11652
  });
11276
- const catalogTableUpdateFunctionGet = catalogHandler(signingKey, async (params) => {
11653
+ const catalogTableUpdateFunctionGet = catalogHandler(keys, async (params) => {
11277
11654
  const result = await getCatalog().tableUpdateFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, optionalTx(params));
11278
11655
  return wrapResult(result, ScanFunctionResultSchema);
11279
11656
  });
11280
- const catalogTableDeleteFunctionGet = catalogHandler(signingKey, async (params) => {
11657
+ const catalogTableDeleteFunctionGet = catalogHandler(keys, async (params) => {
11281
11658
  const result = await getCatalog().tableDeleteFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, optionalTx(params));
11282
11659
  return wrapResult(result, ScanFunctionResultSchema);
11283
11660
  });
11284
- const catalogTableScanBranchesGet = catalogHandler(signingKey, async (params) => {
11661
+ const catalogTableScanBranchesGet = catalogHandler(keys, async (params) => {
11285
11662
  const cat = getCatalog();
11286
11663
  const branchesResult = await cat.tableScanBranchesGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.at_unit, params.at_value, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11287
11664
  return wrapResult(branchesResult, ScanBranchesResultSchema);
11288
11665
  });
11289
- const catalogTableCommentSet = catalogHandler(signingKey, async (params) => {
11666
+ const catalogTableCommentSet = catalogHandler(keys, async (params) => {
11290
11667
  const cat = getCatalog();
11291
11668
  await cat.tableCommentSet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.comment, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11292
11669
  return {};
11293
11670
  });
11294
- const catalogTableRename = catalogHandler(signingKey, async (params) => {
11671
+ const catalogTableRename = catalogHandler(keys, async (params) => {
11295
11672
  const cat = getCatalog();
11296
11673
  await cat.tableRename(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.new_name, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11297
11674
  return {};
11298
11675
  });
11299
- const catalogTableColumnAdd = catalogHandler(signingKey, async (params) => {
11676
+ const catalogTableColumnAdd = catalogHandler(keys, async (params) => {
11300
11677
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_add");
11301
11678
  validateColumnMetadataIpc(toUint8Array(params.column_definition));
11302
11679
  validateColumnExpressionsIpc(toUint8Array(params.column_definition), params.schema_path);
@@ -11304,49 +11681,49 @@ function catalogTableHandlers(getCatalog, signingKey) {
11304
11681
  await cat.tableColumnAdd(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.column_path, toUint8Array(params.column_definition), params.ignore_not_found, params.if_column_not_exists, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11305
11682
  return {};
11306
11683
  });
11307
- const catalogTableColumnDrop = catalogHandler(signingKey, async (params) => {
11684
+ const catalogTableColumnDrop = catalogHandler(keys, async (params) => {
11308
11685
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_drop");
11309
11686
  const cat = getCatalog();
11310
11687
  await cat.tableColumnDrop(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.column_path, params.ignore_not_found, params.if_column_exists, params.cascade, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11311
11688
  return {};
11312
11689
  });
11313
- const catalogTableColumnRename = catalogHandler(signingKey, async (params) => {
11690
+ const catalogTableColumnRename = catalogHandler(keys, async (params) => {
11314
11691
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_rename");
11315
11692
  const cat = getCatalog();
11316
11693
  await cat.tableColumnRename(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.column_path, params.new_column_name, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11317
11694
  return {};
11318
11695
  });
11319
- const catalogTableColumnCommentSet = catalogHandler(signingKey, async (params) => {
11696
+ const catalogTableColumnCommentSet = catalogHandler(keys, async (params) => {
11320
11697
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_comment_set");
11321
11698
  const cat = getCatalog();
11322
11699
  await cat.tableColumnCommentSet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.column_path, params.comment, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11323
11700
  return {};
11324
11701
  });
11325
- const catalogTableColumnDefaultSet = catalogHandler(signingKey, async (params) => {
11702
+ const catalogTableColumnDefaultSet = catalogHandler(keys, async (params) => {
11326
11703
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_default_set");
11327
11704
  const cat = getCatalog();
11328
11705
  await cat.tableColumnDefaultSet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.column_path, toUint8Array(params.expression), params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11329
11706
  return {};
11330
11707
  });
11331
- const catalogTableColumnDefaultDrop = catalogHandler(signingKey, async (params) => {
11708
+ const catalogTableColumnDefaultDrop = catalogHandler(keys, async (params) => {
11332
11709
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_default_drop");
11333
11710
  const cat = getCatalog();
11334
11711
  await cat.tableColumnDefaultDrop(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.column_path, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11335
11712
  return {};
11336
11713
  });
11337
- const catalogTableColumnTypeChange = catalogHandler(signingKey, async (params) => {
11714
+ const catalogTableColumnTypeChange = catalogHandler(keys, async (params) => {
11338
11715
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_type_change");
11339
11716
  const cat = getCatalog();
11340
11717
  await cat.tableColumnTypeChange(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.column_path, toUint8Array(params.column_definition), params.expression == null ? null : toUint8Array(params.expression), params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11341
11718
  return {};
11342
11719
  });
11343
- const catalogTableNotNullSet = catalogHandler(signingKey, async (params) => {
11720
+ const catalogTableNotNullSet = catalogHandler(keys, async (params) => {
11344
11721
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_not_null_set");
11345
11722
  const cat = getCatalog();
11346
11723
  await cat.tableNotNullSet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.column_path, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11347
11724
  return {};
11348
11725
  });
11349
- const catalogTableNotNullDrop = catalogHandler(signingKey, async (params) => {
11726
+ const catalogTableNotNullDrop = catalogHandler(keys, async (params) => {
11350
11727
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_not_null_drop");
11351
11728
  const cat = getCatalog();
11352
11729
  await cat.tableNotNullDrop(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.column_path, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
@@ -11378,15 +11755,16 @@ function catalogTableHandlers(getCatalog, signingKey) {
11378
11755
  }
11379
11756
 
11380
11757
  // src/protocol/handlers/catalog/view.ts
11381
- function catalogViewHandlers(getCatalog, signingKey) {
11382
- const catalogViewGet = catalogHandler(signingKey, async (params) => {
11758
+ function catalogViewHandlers(getCatalog, signingKey, attachSecretKey) {
11759
+ const keys = { signingKey, attachSecretKey };
11760
+ const catalogViewGet = catalogHandler(keys, async (params) => {
11383
11761
  const cat = getCatalog();
11384
11762
  const info = await cat.viewGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11385
11763
  return wrapResult({
11386
11764
  items: info ? [encodeViewInfo(info)] : []
11387
11765
  }, CatalogViewGetResultSchema);
11388
11766
  });
11389
- const catalogViewCreate = catalogHandler(signingKey, async (params) => {
11767
+ const catalogViewCreate = catalogHandler(keys, async (params) => {
11390
11768
  if (params.security !== "regular")
11391
11769
  throw new Error(`view security mode ${params.security} is unsupported`);
11392
11770
  const tags = catalogStringMap(params.tags);
@@ -11397,22 +11775,22 @@ function catalogViewHandlers(getCatalog, signingKey) {
11397
11775
  await cat.viewCreate(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.definition, decodeDictValue(params.on_conflict), params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined, params.aliases ?? [], params.comment, tags, columnComments);
11398
11776
  return {};
11399
11777
  });
11400
- const catalogViewDrop = catalogHandler(signingKey, async (params) => {
11778
+ const catalogViewDrop = catalogHandler(keys, async (params) => {
11401
11779
  const cat = getCatalog();
11402
11780
  await cat.viewDrop(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11403
11781
  return {};
11404
11782
  });
11405
- const catalogViewRename = catalogHandler(signingKey, async (params) => {
11783
+ const catalogViewRename = catalogHandler(keys, async (params) => {
11406
11784
  const cat = getCatalog();
11407
11785
  await cat.viewRename(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.new_name, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11408
11786
  return {};
11409
11787
  });
11410
- const catalogViewCommentSet = catalogHandler(signingKey, async (params) => {
11788
+ const catalogViewCommentSet = catalogHandler(keys, async (params) => {
11411
11789
  const cat = getCatalog();
11412
11790
  await cat.viewCommentSet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.comment, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11413
11791
  return {};
11414
11792
  });
11415
- const catalogViewColumnCommentSet = catalogHandler(signingKey, async (params) => {
11793
+ const catalogViewColumnCommentSet = catalogHandler(keys, async (params) => {
11416
11794
  const path = Array.from(params.column_path);
11417
11795
  if (path.length !== 1 || !path[0] || path[0].includes("\x00"))
11418
11796
  throw new Error("view column comments require one raw output identifier");
@@ -11423,15 +11801,16 @@ function catalogViewHandlers(getCatalog, signingKey) {
11423
11801
  }
11424
11802
 
11425
11803
  // src/protocol/handlers/catalog/macro.ts
11426
- function catalogMacroHandlers(getCatalog, signingKey) {
11427
- const catalogMacroGet = catalogHandler(signingKey, async (params) => {
11804
+ function catalogMacroHandlers(getCatalog, signingKey, attachSecretKey) {
11805
+ const keys = { signingKey, attachSecretKey };
11806
+ const catalogMacroGet = catalogHandler(keys, async (params) => {
11428
11807
  const cat = getCatalog();
11429
11808
  const info = await cat.macroGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11430
11809
  return wrapResult({
11431
11810
  items: info ? [encodeMacroInfo(info)] : []
11432
11811
  }, CatalogMacroGetResultSchema);
11433
11812
  });
11434
- const catalogMacroCreate = catalogHandler(signingKey, async (params) => {
11813
+ const catalogMacroCreate = catalogHandler(keys, async (params) => {
11435
11814
  const cat = getCatalog();
11436
11815
  const innerParams = decodeASD(MacroCreateRequestSchema, encodeASD(MacroCreateRequestSchema, params));
11437
11816
  if (!innerParams.overloads?.length)
@@ -11439,12 +11818,12 @@ function catalogMacroHandlers(getCatalog, signingKey) {
11439
11818
  await cat.macroCreate(toUint8Array(innerParams.attach_opaque_data), innerParams.schema_path, innerParams.name, innerParams.macro_type, innerParams.overloads, innerParams.on_conflict, innerParams.transaction_opaque_data ? toUint8Array(innerParams.transaction_opaque_data) : undefined);
11440
11819
  return {};
11441
11820
  });
11442
- const catalogMacroDrop = catalogHandler(signingKey, async (params) => {
11821
+ const catalogMacroDrop = catalogHandler(keys, async (params) => {
11443
11822
  const cat = getCatalog();
11444
11823
  await cat.macroDrop(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.ignore_not_found, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11445
11824
  return {};
11446
11825
  });
11447
- const catalogSchemaContentsMacros = catalogHandler(signingKey, async (params) => {
11826
+ const catalogSchemaContentsMacros = catalogHandler(keys, async (params) => {
11448
11827
  const cat = getCatalog();
11449
11828
  const macros = await cat.schemaContentsMacros(toUint8Array(params.attach_opaque_data), params.path, decodeDictValue(params.type), params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11450
11829
  return wrapResult({
@@ -11455,15 +11834,16 @@ function catalogMacroHandlers(getCatalog, signingKey) {
11455
11834
  }
11456
11835
 
11457
11836
  // src/protocol/handlers/catalog/index_methods.ts
11458
- function catalogIndexHandlers(getCatalog, signingKey) {
11459
- const catalogSchemaContentsIndexes = catalogHandler(signingKey, async (params) => {
11837
+ function catalogIndexHandlers(getCatalog, signingKey, attachSecretKey) {
11838
+ const keys = { signingKey, attachSecretKey };
11839
+ const catalogSchemaContentsIndexes = catalogHandler(keys, async (params) => {
11460
11840
  const cat = getCatalog();
11461
11841
  const indexes = await cat.schemaContentsIndexes(toUint8Array(params.attach_opaque_data), params.path, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11462
11842
  return wrapResult({
11463
11843
  items: indexes.map((i) => encodeIndexInfo(i))
11464
11844
  }, CatalogSchemaContentsIndexesResultSchema);
11465
11845
  });
11466
- const catalogIndexGet = catalogHandler(signingKey, async (params) => {
11846
+ const catalogIndexGet = catalogHandler(keys, async (params) => {
11467
11847
  const cat = getCatalog();
11468
11848
  const info = await cat.indexGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
11469
11849
  return wrapResult({
@@ -11474,14 +11854,14 @@ function catalogIndexHandlers(getCatalog, signingKey) {
11474
11854
  }
11475
11855
 
11476
11856
  // src/protocol/handlers/catalog/index.ts
11477
- function catalogHandlers(catalog, signingKey) {
11857
+ function catalogHandlers(catalog, signingKey, attachSecretKey) {
11478
11858
  const getCatalog = makeGetCatalog(catalog);
11479
11859
  return {
11480
- ...catalogAdminHandlers(getCatalog, signingKey),
11481
- ...catalogTableHandlers(getCatalog, signingKey),
11482
- ...catalogViewHandlers(getCatalog, signingKey),
11483
- ...catalogMacroHandlers(getCatalog, signingKey),
11484
- ...catalogIndexHandlers(getCatalog, signingKey)
11860
+ ...catalogAdminHandlers(getCatalog, signingKey, attachSecretKey),
11861
+ ...catalogTableHandlers(getCatalog, signingKey, attachSecretKey),
11862
+ ...catalogViewHandlers(getCatalog, signingKey, attachSecretKey),
11863
+ ...catalogMacroHandlers(getCatalog, signingKey, attachSecretKey),
11864
+ ...catalogIndexHandlers(getCatalog, signingKey, attachSecretKey)
11485
11865
  };
11486
11866
  }
11487
11867
 
@@ -11492,11 +11872,12 @@ function buildVgiService(config) {
11492
11872
  ...functionHandlers({
11493
11873
  registry: config.registry,
11494
11874
  signingKey: config.signingKey,
11875
+ attachSecretKey: config.attachSecretKey,
11495
11876
  catalogInterface: config.catalogInterface
11496
11877
  }),
11497
11878
  ...aggregateHandlers(config.registry),
11498
- ...tableBufferingHandlers(config.registry, config.signingKey),
11499
- ...catalogHandlers(config.catalogInterface, config.signingKey)
11879
+ ...tableBufferingHandlers(config.registry, config.signingKey, config.attachSecretKey),
11880
+ ...catalogHandlers(config.catalogInterface, config.signingKey, config.attachSecretKey)
11500
11881
  };
11501
11882
  }
11502
11883
  function buildVgiProtocol(config) {
@@ -11877,7 +12258,7 @@ function createVgiWorkerFetch(opts) {
11877
12258
  }
11878
12259
  const trustedProxyAddresses = bridge?.trustedProxyAddresses ?? ["127.0.0.1"];
11879
12260
  return createVgiFetch({
11880
- protocol: { registry: opts.registry, catalogInterface: opts.catalogInterface },
12261
+ protocol: { registry: opts.registry, catalogInterface: opts.catalogInterface, attachSecretKey: opts.attachSecretKey },
11881
12262
  signingKey,
11882
12263
  signingKeyConfigured,
11883
12264
  tokenTtl,
@@ -11943,4 +12324,4 @@ export {
11943
12324
  serveVgiWorker
11944
12325
  };
11945
12326
 
11946
- //# debugId=448535FCB65D277D64756E2164756E21
12327
+ //# debugId=421A831E60B471AC64756E2164756E21