@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
@@ -9965,13 +9965,402 @@ async function openBytes(token, key, aad, version, field = "opaque data") {
9965
9965
  }
9966
9966
  }
9967
9967
 
9968
+ // src/attach-secret-options.ts
9969
+ init_arrow();
9970
+
9971
+ // src/attach-secret-keyfile.ts
9972
+ function builtins() {
9973
+ const proc = globalThis.process;
9974
+ const get = proc?.getBuiltinModule?.bind(proc);
9975
+ const fs = get?.("node:fs");
9976
+ const os = get?.("node:os");
9977
+ const path = get?.("node:path");
9978
+ if (!fs || !os || !path)
9979
+ throw new Error("this runtime has no filesystem for the host-local attach secret key file.");
9980
+ return { fs, os, path };
9981
+ }
9982
+ var ATTACH_SECRET_KEY_FILE_ENV = "VGI_ATTACH_SECRET_KEY_FILE";
9983
+ var KEY_LEN = 32;
9984
+ var FILE_NAME = "attach-secret-options.key";
9985
+ var REMEDY = "Set VGI_SIGNING_KEY (or configure attachSecretKey), or point VGI_ATTACH_SECRET_KEY_FILE at a valid key file.";
9986
+ function username() {
9987
+ try {
9988
+ const name = builtins().os.userInfo().username;
9989
+ if (name)
9990
+ return name;
9991
+ } catch {}
9992
+ return process.env.USER || process.env.USERNAME || String(process.getuid?.() ?? "user");
9993
+ }
9994
+ function isDirectory(path) {
9995
+ try {
9996
+ return builtins().fs.statSync(path).isDirectory();
9997
+ } catch {
9998
+ return false;
9999
+ }
10000
+ }
10001
+ function hostLocalAttachSecretKeyPath(env = globalThis.process?.env ?? {}) {
10002
+ const { os, path: { join } } = builtins();
10003
+ const explicit = env[ATTACH_SECRET_KEY_FILE_ENV];
10004
+ if (explicit)
10005
+ return explicit;
10006
+ const xdg = env.XDG_RUNTIME_DIR;
10007
+ if (xdg && isDirectory(xdg))
10008
+ return join(xdg, "vgi", FILE_NAME);
10009
+ return join(os.tmpdir(), `vgi-${username()}`, FILE_NAME);
10010
+ }
10011
+ var POSIX = typeof process === "undefined" || process.platform !== "win32";
10012
+ function checkOwnedPrivate(path, mode, uid, what) {
10013
+ if (!POSIX)
10014
+ return;
10015
+ const me = process.getuid?.();
10016
+ if (me !== undefined && uid !== me) {
10017
+ throw new Error(`attach secret key ${what} ${path} is not owned by the current user. ${REMEDY}`);
10018
+ }
10019
+ if ((mode & 63) !== 0) {
10020
+ 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}`);
10021
+ }
10022
+ }
10023
+ function ensureDir(dir) {
10024
+ const { mkdirSync, lstatSync } = builtins().fs;
10025
+ try {
10026
+ mkdirSync(dir, { recursive: true, mode: 448 });
10027
+ } catch (e) {
10028
+ if (e.code !== "EEXIST")
10029
+ throw e;
10030
+ }
10031
+ const st = lstatSync(dir);
10032
+ if (!st.isDirectory())
10033
+ throw new Error(`attach secret key directory ${dir} is not a directory. ${REMEDY}`);
10034
+ checkOwnedPrivate(dir, st.mode, st.uid, "directory");
10035
+ }
10036
+ function readKey(path) {
10037
+ const { openSync, fstatSync, readSync, closeSync, constants } = builtins().fs;
10038
+ let fd;
10039
+ try {
10040
+ fd = openSync(path, constants.O_RDONLY | (POSIX ? constants.O_NOFOLLOW : 0));
10041
+ } catch (e) {
10042
+ if (e.code === "ENOENT")
10043
+ return null;
10044
+ throw new Error(`attach secret key file ${path} cannot be opened (${e.code}). ${REMEDY}`);
10045
+ }
10046
+ try {
10047
+ const st = fstatSync(fd);
10048
+ if (!st.isFile())
10049
+ throw new Error(`attach secret key file ${path} is not a regular file. ${REMEDY}`);
10050
+ checkOwnedPrivate(path, st.mode, st.uid, "file");
10051
+ const buf = new Uint8Array(KEY_LEN + 1);
10052
+ let n = 0;
10053
+ for (;; ) {
10054
+ const got = readSync(fd, buf, n, buf.length - n, null);
10055
+ if (got <= 0)
10056
+ break;
10057
+ n += got;
10058
+ if (n === buf.length)
10059
+ break;
10060
+ }
10061
+ if (n !== KEY_LEN || st.size !== KEY_LEN) {
10062
+ throw new Error(`attach secret key file ${path} must contain exactly ${KEY_LEN} raw bytes (found ${st.size}). ${REMEDY}`);
10063
+ }
10064
+ return buf.subarray(0, KEY_LEN);
10065
+ } finally {
10066
+ closeSync(fd);
10067
+ }
10068
+ }
10069
+ function createKey(path) {
10070
+ const { openSync, writeSync, fsyncSync, closeSync, linkSync, unlinkSync, constants } = builtins().fs;
10071
+ const { dirname, join } = builtins().path;
10072
+ const tmp = join(dirname(path), `.${FILE_NAME}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`);
10073
+ const fd = openSync(tmp, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL, 384);
10074
+ try {
10075
+ const key = crypto.getRandomValues(new Uint8Array(KEY_LEN));
10076
+ let off = 0;
10077
+ while (off < KEY_LEN)
10078
+ off += writeSync(fd, key, off, KEY_LEN - off);
10079
+ fsyncSync(fd);
10080
+ } finally {
10081
+ closeSync(fd);
10082
+ }
10083
+ try {
10084
+ linkSync(tmp, path);
10085
+ } catch (e) {
10086
+ if (e.code !== "EEXIST") {
10087
+ unlinkSync(tmp);
10088
+ throw e;
10089
+ }
10090
+ }
10091
+ unlinkSync(tmp);
10092
+ }
10093
+ function loadHostLocalAttachSecretKey(path = hostLocalAttachSecretKeyPath()) {
10094
+ ensureDir(builtins().path.dirname(path));
10095
+ const existing = readKey(path);
10096
+ if (existing)
10097
+ return existing;
10098
+ createKey(path);
10099
+ const created = readKey(path);
10100
+ if (!created)
10101
+ throw new Error(`attach secret key file ${path} vanished after creation. ${REMEDY}`);
10102
+ return created;
10103
+ }
10104
+ var cached;
10105
+ async function hostLocalAttachSecretKey() {
10106
+ const path = hostLocalAttachSecretKeyPath();
10107
+ if (cached?.path === path)
10108
+ return cached.key;
10109
+ const key = loadHostLocalAttachSecretKey(path);
10110
+ cached = { path, key };
10111
+ return key;
10112
+ }
10113
+
10114
+ // src/attach-secret-options.ts
10115
+ var UTF82 = new TextEncoder;
10116
+ var ATTACH_SECRET_OPTIONS_INFO = "vgi.attach_secret_options.v1";
10117
+ var ATTACH_SECRET_OPTIONS_VERSION = 1;
10118
+ var TRAILER_MAGIC = Uint8Array.of(0, 86, 71, 73, 65, 79, 1, 255);
10119
+ var TRAILER_FIXED = 4 + TRAILER_MAGIC.length;
10120
+ var NONCE_LEN2 = 24;
10121
+ var TAG_LEN2 = 16;
10122
+ var AAD_PREFIX = UTF82.encode(`${ATTACH_SECRET_OPTIONS_INFO}\x00`);
10123
+ var UUID_LEN = 16;
10124
+ var FIELD = "attach_opaque_data";
10125
+
10126
+ class AttachSecretKeyUnavailableError extends Error {
10127
+ constructor(message) {
10128
+ super(message);
10129
+ this.name = "AttachSecretKeyUnavailableError";
10130
+ }
10131
+ }
10132
+
10133
+ class AttachOptionsUnavailableError extends Error {
10134
+ constructor() {
10135
+ super("attachOptions(): these bytes are not an attach_opaque_data value the framework handed to this call. " + "Pass the attach value exactly as received (bindCall.attach_opaque_data, a TableBuffering attachId, or a " + "catalog method's attachOpaqueData argument, or a subarray of it), not a copy.");
10136
+ this.name = "AttachOptionsUnavailableError";
10137
+ }
10138
+ }
10139
+ var subkeys = new Map;
10140
+ function hexOf(b) {
10141
+ let s = "";
10142
+ for (let i = 0;i < b.length; i++)
10143
+ s += b[i].toString(16).padStart(2, "0");
10144
+ return s;
10145
+ }
10146
+ function deriveAttachSecretKey(root) {
10147
+ const id = hexOf(root);
10148
+ let derived = subkeys.get(id);
10149
+ if (!derived) {
10150
+ derived = (async () => {
10151
+ const ikm = await crypto.subtle.importKey("raw", root, "HKDF", false, ["deriveBits"]);
10152
+ const bits = await crypto.subtle.deriveBits({ name: "HKDF", hash: "SHA-256", salt: new Uint8Array(0), info: UTF82.encode(ATTACH_SECRET_OPTIONS_INFO) }, ikm, 256);
10153
+ return new Uint8Array(bits);
10154
+ })();
10155
+ subkeys.set(id, derived);
10156
+ derived.catch(() => subkeys.delete(id));
10157
+ }
10158
+ return derived;
10159
+ }
10160
+ function defaultHostLocal() {
10161
+ return hostLocalAttachSecretKey();
10162
+ }
10163
+ function noKeyMessage() {
10164
+ 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.";
10165
+ }
10166
+ async function rootKey(source) {
10167
+ if (source.explicit && source.explicit.length > 0)
10168
+ return source.explicit;
10169
+ if (source.signingKey && source.signingKey.length > 0)
10170
+ return source.signingKey;
10171
+ return (source.hostLocal ?? defaultHostLocal)();
10172
+ }
10173
+ function aadFor(uuid) {
10174
+ const out = new Uint8Array(AAD_PREFIX.length + uuid.length);
10175
+ out.set(AAD_PREFIX, 0);
10176
+ out.set(uuid, AAD_PREFIX.length);
10177
+ return out;
10178
+ }
10179
+ function u32le(n) {
10180
+ const b = new Uint8Array(4);
10181
+ new DataView(b.buffer).setUint32(0, n, true);
10182
+ return b;
10183
+ }
10184
+ function readU32le(b, off) {
10185
+ return new DataView(b.buffer, b.byteOffset, b.byteLength).getUint32(off, true);
10186
+ }
10187
+ function concat2(...parts) {
10188
+ let total = 0;
10189
+ for (const p of parts)
10190
+ total += p.length;
10191
+ const out = new Uint8Array(total);
10192
+ let off = 0;
10193
+ for (const p of parts) {
10194
+ out.set(p, off);
10195
+ off += p.length;
10196
+ }
10197
+ return out;
10198
+ }
10199
+ function splitOptions(optionsIpc, secretNames) {
10200
+ if (!optionsIpc || optionsIpc.length === 0)
10201
+ return null;
10202
+ const batch = deserializeBatch(optionsIpc);
10203
+ if (batch.numRows === 0 || batch.schema.fields.length === 0)
10204
+ return null;
10205
+ const row = iterRows(batch).next().value ?? {};
10206
+ const plainFields = [];
10207
+ const secretFields = [];
10208
+ const plainCols = {};
10209
+ const secretCols = {};
10210
+ for (const f of batch.schema.fields) {
10211
+ const value = row[f.name];
10212
+ if (secretNames.has(f.name.toLowerCase()) && value !== null && value !== undefined) {
10213
+ secretFields.push(f);
10214
+ secretCols[f.name] = [value];
10215
+ } else {
10216
+ plainFields.push(f);
10217
+ plainCols[f.name] = [value ?? null];
10218
+ }
10219
+ }
10220
+ return {
10221
+ plain: plainFields.length ? serializeBatch(batchFromColumns(plainCols, schema2(plainFields))) : null,
10222
+ secret: secretFields.length ? serializeBatch(batchFromColumns(secretCols, schema2(secretFields))) : null
10223
+ };
10224
+ }
10225
+ async function packAttachOptionsTrailer(uuid, optionsIpc, secretNames, keys, fixedNonce) {
10226
+ const split = splitOptions(optionsIpc, secretNames);
10227
+ if (split === null)
10228
+ return new Uint8Array(0);
10229
+ const plain = split.plain ?? new Uint8Array(0);
10230
+ let secret = new Uint8Array(0);
10231
+ if (split.secret) {
10232
+ let root;
10233
+ try {
10234
+ root = await rootKey(keys);
10235
+ } catch (e) {
10236
+ if (e instanceof AttachSecretKeyUnavailableError)
10237
+ throw e;
10238
+ throw new AttachSecretKeyUnavailableError(`${noKeyMessage()} ${e.message}`);
10239
+ }
10240
+ const key = await deriveAttachSecretKey(root);
10241
+ const nonce = fixedNonce ?? crypto.getRandomValues(new Uint8Array(NONCE_LEN2));
10242
+ const ct = xchacha20poly1305(key, nonce, aadFor(uuid)).encrypt(split.secret);
10243
+ secret = concat2(Uint8Array.of(ATTACH_SECRET_OPTIONS_VERSION), nonce, ct);
10244
+ }
10245
+ const body = concat2(u32le(plain.length), plain, secret);
10246
+ return concat2(body, u32le(body.length), TRAILER_MAGIC);
10247
+ }
10248
+ function endsWithMagic(b) {
10249
+ if (b.length < TRAILER_MAGIC.length)
10250
+ return false;
10251
+ const off = b.length - TRAILER_MAGIC.length;
10252
+ for (let i = 0;i < TRAILER_MAGIC.length; i++)
10253
+ if (b[off + i] !== TRAILER_MAGIC[i])
10254
+ return false;
10255
+ return true;
10256
+ }
10257
+ function decodeOptions(ipc) {
10258
+ const batch = deserializeBatch(ipc);
10259
+ if (batch.numRows === 0)
10260
+ return {};
10261
+ return { ...iterRows(batch).next().value ?? {} };
10262
+ }
10263
+ var registry = new WeakMap;
10264
+ var EMPTY = Object.freeze({});
10265
+ async function openFrameworkAttach(full, keys) {
10266
+ if (full.length < UUID_LEN)
10267
+ return full;
10268
+ const copy = full.slice();
10269
+ let end = copy.length;
10270
+ let options = EMPTY;
10271
+ if (copy.length >= UUID_LEN + TRAILER_FIXED && endsWithMagic(copy)) {
10272
+ const bodyLen = readU32le(copy, copy.length - TRAILER_FIXED);
10273
+ const bodyStart = copy.length - TRAILER_FIXED - bodyLen;
10274
+ if (bodyLen < 4 || bodyStart < UUID_LEN)
10275
+ throw new OpaqueDataRejectedError(FIELD);
10276
+ const body = copy.subarray(bodyStart, copy.length - TRAILER_FIXED);
10277
+ const plainLen = readU32le(body, 0);
10278
+ if (4 + plainLen > body.length)
10279
+ throw new OpaqueDataRejectedError(FIELD);
10280
+ const plain = body.subarray(4, 4 + plainLen);
10281
+ const secret = body.subarray(4 + plainLen);
10282
+ const values = {};
10283
+ try {
10284
+ if (plain.length)
10285
+ Object.assign(values, decodeOptions(plain));
10286
+ } catch {
10287
+ throw new OpaqueDataRejectedError(FIELD);
10288
+ }
10289
+ if (secret.length) {
10290
+ if (secret.length < 1 + NONCE_LEN2 + TAG_LEN2 || secret[0] !== ATTACH_SECRET_OPTIONS_VERSION) {
10291
+ throw new OpaqueDataRejectedError(FIELD);
10292
+ }
10293
+ let opened;
10294
+ try {
10295
+ const key = await deriveAttachSecretKey(await rootKey(keys));
10296
+ const nonce = secret.subarray(1, 1 + NONCE_LEN2);
10297
+ opened = xchacha20poly1305(key, nonce, aadFor(copy.subarray(0, UUID_LEN))).decrypt(secret.subarray(1 + NONCE_LEN2));
10298
+ } catch {
10299
+ throw new OpaqueDataRejectedError(FIELD);
10300
+ }
10301
+ try {
10302
+ Object.assign(values, decodeOptions(opened));
10303
+ } catch {
10304
+ throw new OpaqueDataRejectedError(FIELD);
10305
+ }
10306
+ }
10307
+ options = Object.freeze(values);
10308
+ end = bodyStart;
10309
+ }
10310
+ registry.set(copy.buffer, options);
10311
+ return copy.subarray(UUID_LEN, end);
10312
+ }
10313
+ function attachOptions(attachOpaqueData) {
10314
+ if (attachOpaqueData == null)
10315
+ return EMPTY;
10316
+ const found = registry.get(attachOpaqueData.buffer);
10317
+ if (found !== undefined)
10318
+ return found;
10319
+ if (attachOpaqueData.length === 0)
10320
+ return EMPTY;
10321
+ throw new AttachOptionsUnavailableError;
10322
+ }
10323
+ async function secretAttachOptionNames(catalog, name, deserialize) {
10324
+ const names = new Set;
10325
+ if (typeof catalog.attachOptionSpecs === "function") {
10326
+ for (const spec of catalog.attachOptionSpecs(name) ?? [])
10327
+ if (spec.secret)
10328
+ names.add(spec.name.toLowerCase());
10329
+ }
10330
+ if (typeof catalog.catalogsInfo === "function") {
10331
+ let infos;
10332
+ try {
10333
+ infos = await catalog.catalogsInfo();
10334
+ } catch {
10335
+ infos = [];
10336
+ }
10337
+ for (const info of infos ?? []) {
10338
+ if (info.name !== name)
10339
+ continue;
10340
+ for (const raw of info.attach_option_specs ?? []) {
10341
+ try {
10342
+ const spec = deserialize(raw);
10343
+ if (spec.secret)
10344
+ names.add(spec.name.toLowerCase());
10345
+ } catch {}
10346
+ }
10347
+ }
10348
+ }
10349
+ return names;
10350
+ }
10351
+
9968
10352
  // src/protocol/handlers/catalog/shared.ts
9969
- async function sealAttach(plaintext, auth, signingKey) {
10353
+ async function sealAttach(plaintext, auth, signingKey, options) {
9970
10354
  const uuid = new Uint8Array(ATTACH_UUID_LEN);
9971
10355
  crypto.getRandomValues(uuid);
9972
- const minted = new Uint8Array(ATTACH_UUID_LEN + plaintext.length);
10356
+ const trailer = options ? await packAttachOptionsTrailer(uuid, options.optionsIpc, options.secretNames, {
10357
+ explicit: options.attachSecretKey,
10358
+ signingKey
10359
+ }) : new Uint8Array(0);
10360
+ const minted = new Uint8Array(ATTACH_UUID_LEN + plaintext.length + trailer.length);
9973
10361
  minted.set(uuid, 0);
9974
10362
  minted.set(plaintext, ATTACH_UUID_LEN);
10363
+ minted.set(trailer, ATTACH_UUID_LEN + plaintext.length);
9975
10364
  if (!signingKey)
9976
10365
  return minted;
9977
10366
  return sealBytes(minted, signingKey, attachAad(auth), ATTACH_ENVELOPE_VERSION);
@@ -9981,9 +10370,9 @@ async function openAttachFull(envelope, auth, signingKey) {
9981
10370
  return envelope;
9982
10371
  return openBytes(envelope, signingKey, attachAad(auth), ATTACH_ENVELOPE_VERSION, "attach_opaque_data");
9983
10372
  }
9984
- async function openAttach(envelope, auth, signingKey) {
10373
+ async function openAttach(envelope, auth, signingKey, attachSecretKey) {
9985
10374
  const full = await openAttachFull(envelope, auth, signingKey);
9986
- return full.length < ATTACH_UUID_LEN ? full : full.subarray(ATTACH_UUID_LEN);
10375
+ return openFrameworkAttach(full, { explicit: attachSecretKey, signingKey });
9987
10376
  }
9988
10377
  async function sealTransaction(plaintext, attachEnvelope, auth, signingKey) {
9989
10378
  if (!signingKey)
@@ -9995,7 +10384,8 @@ async function openTransaction(envelope, attachEnvelope, auth, signingKey) {
9995
10384
  return envelope;
9996
10385
  return openBytes(envelope, signingKey, transactionAad(auth, attachEnvelope), TRANSACTION_ENVELOPE_VERSION, "transaction_opaque_data");
9997
10386
  }
9998
- async function unwrapParamsOpaque(params, ctx, signingKey) {
10387
+ async function unwrapParamsOpaque(params, ctx, keys) {
10388
+ const { signingKey, attachSecretKey } = keys;
9999
10389
  const auth = ctx?.auth;
10000
10390
  let sealedAttach = new Uint8Array(0);
10001
10391
  if (params.attach_opaque_data != null) {
@@ -10003,7 +10393,7 @@ async function unwrapParamsOpaque(params, ctx, signingKey) {
10003
10393
  if (env.length > 0) {
10004
10394
  sealedAttach = env;
10005
10395
  const full = signingKey ? await openBytes(env, signingKey, attachAad(auth), ATTACH_ENVELOPE_VERSION, "attach_opaque_data") : env;
10006
- params.attach_opaque_data = full.length < ATTACH_UUID_LEN ? full : full.subarray(ATTACH_UUID_LEN);
10396
+ params.attach_opaque_data = await openFrameworkAttach(full, { explicit: attachSecretKey, signingKey });
10007
10397
  }
10008
10398
  }
10009
10399
  if (signingKey && params.transaction_opaque_data != null) {
@@ -10013,14 +10403,15 @@ async function unwrapParamsOpaque(params, ctx, signingKey) {
10013
10403
  }
10014
10404
  }
10015
10405
  }
10016
- function catalogHandler(signingKey, handler) {
10406
+ function catalogHandler(keysOrSigningKey, handler) {
10407
+ const keys = keysOrSigningKey instanceof Uint8Array || keysOrSigningKey === undefined ? { signingKey: keysOrSigningKey } : keysOrSigningKey;
10017
10408
  return async (wire, ctx) => {
10018
10409
  let params = wire;
10019
10410
  if (params.request != null && params.attach_opaque_data === undefined && params.name === undefined) {
10020
10411
  params = unwrapRequest(params.request);
10021
10412
  }
10022
10413
  normalizeRequestSchemaPaths(params);
10023
- await unwrapParamsOpaque(params, ctx, signingKey);
10414
+ await unwrapParamsOpaque(params, ctx, keys);
10024
10415
  return handler(params, ctx);
10025
10416
  };
10026
10417
  }
@@ -10162,7 +10553,7 @@ var RESERVED_FLAGS_MASK = 254;
10162
10553
  var FINGERPRINT_LEN = 16;
10163
10554
  var HEADER_LEN = 4 + FINGERPRINT_LEN;
10164
10555
  var SEAL_VERSION = 1;
10165
- var AAD_PREFIX = new TextEncoder().encode("vgi.split_token.v1\x00");
10556
+ var AAD_PREFIX2 = new TextEncoder().encode("vgi.split_token.v1\x00");
10166
10557
  var SPLIT_TOKEN_INVALID = "SPLIT_TOKEN_INVALID";
10167
10558
  var SPLIT_SNAPSHOT_EXPIRED = "SPLIT_SNAPSHOT_EXPIRED";
10168
10559
  class SplitTokenError extends Error {
@@ -10173,7 +10564,7 @@ class SplitTokenError extends Error {
10173
10564
  this.kind = kind;
10174
10565
  }
10175
10566
  }
10176
- function concat2(...parts) {
10567
+ function concat3(...parts) {
10177
10568
  const total = parts.reduce((n, p) => n + p.length, 0);
10178
10569
  const out = new Uint8Array(total);
10179
10570
  let at = 0;
@@ -10194,13 +10585,13 @@ function equalBytes2(a, b) {
10194
10585
  async function bindFingerprint(schemaPath, functionName, args, settings, projection) {
10195
10586
  const enc = new TextEncoder;
10196
10587
  const zero = Uint8Array.of(0);
10197
- const field = (label, value) => concat2(enc.encode(label), zero, value, zero);
10198
- 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));
10588
+ const field = (label, value) => concat3(enc.encode(label), zero, value, zero);
10589
+ 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));
10199
10590
  const digest = await crypto.subtle.digest("SHA-256", message);
10200
10591
  return new Uint8Array(digest).slice(0, FINGERPRINT_LEN);
10201
10592
  }
10202
10593
  function splitTokenAad(header, auth) {
10203
- return concat2(header, identityTail(auth));
10594
+ return concat3(header, identityTail(auth));
10204
10595
  }
10205
10596
  function splitAnchor(catalogVersion) {
10206
10597
  const out = new Uint8Array(8);
@@ -10219,11 +10610,11 @@ async function buildSplitToken(opts) {
10219
10610
  head[0] = SPLIT_TOKEN_FORMAT_VERSION;
10220
10611
  head[1] = signingKey ? FLAG_PAYLOAD_SEALED : 0;
10221
10612
  new DataView(head.buffer).setUint16(2, anchor.length, true);
10222
- const body = concat2(head, fingerprint, anchor);
10613
+ const body = concat3(head, fingerprint, anchor);
10223
10614
  if (!signingKey)
10224
- return concat2(body, payload);
10615
+ return concat3(body, payload);
10225
10616
  const sealed = await sealBytes(payload, signingKey, splitTokenAad(body, auth), SEAL_VERSION);
10226
- return concat2(body, sealed);
10617
+ return concat3(body, sealed);
10227
10618
  }
10228
10619
  async function openSplitToken(token, opts = {}) {
10229
10620
  const { signingKey, auth, expectedFingerprint, currentAnchor } = opts;
@@ -10271,7 +10662,7 @@ async function openSplitToken(token, opts = {}) {
10271
10662
  }
10272
10663
 
10273
10664
  // src/protocol/handlers/function.ts
10274
- async function liveSplitAnchor(catalogInterface, bindCall, auth, signingKey) {
10665
+ async function liveSplitAnchor(catalogInterface, bindCall, auth, signingKey, attachSecretKey) {
10275
10666
  if (!catalogInterface?.version || bindCall.attach_opaque_data == null)
10276
10667
  return;
10277
10668
  const raw = toUint8Array(bindCall.attach_opaque_data);
@@ -10283,7 +10674,7 @@ async function liveSplitAnchor(catalogInterface, bindCall, auth, signingKey) {
10283
10674
  }
10284
10675
  const forms = [
10285
10676
  async () => raw,
10286
- async () => openAttach(raw, auth, signingKey)
10677
+ async () => openAttach(raw, auth, signingKey, attachSecretKey)
10287
10678
  ];
10288
10679
  for (const form of forms) {
10289
10680
  try {
@@ -10297,7 +10688,7 @@ async function resolveSplitPayloads(request, innerParams, opts) {
10297
10688
  return;
10298
10689
  const fp = fingerprintInputs(toUint8Array(innerParams.bind_call));
10299
10690
  const expected = await bindFingerprint(fp.schemaPath, fp.functionName, fp.args, fp.settings, new Uint8Array(0));
10300
- const currentAnchor = opts.checkAnchor ? await liveSplitAnchor(opts.catalogInterface, request.bind_call, opts.auth, opts.signingKey) : undefined;
10691
+ const currentAnchor = opts.checkAnchor ? await liveSplitAnchor(opts.catalogInterface, request.bind_call, opts.auth, opts.signingKey, opts.attachSecretKey) : undefined;
10301
10692
  request.split_payloads = [];
10302
10693
  for (const token of request.split_tokens) {
10303
10694
  request.split_payloads.push(await openSplitToken(token, {
@@ -10309,14 +10700,14 @@ async function resolveSplitPayloads(request, innerParams, opts) {
10309
10700
  }
10310
10701
  }
10311
10702
  function functionHandlers(config) {
10312
- const { registry, signingKey, catalogInterface } = config;
10703
+ const { registry, signingKey, catalogInterface, attachSecretKey } = config;
10313
10704
  async function stripAttach(attach, ctx) {
10314
10705
  if (attach == null)
10315
10706
  return null;
10316
10707
  const env = toUint8Array(attach);
10317
10708
  if (env.length === 0)
10318
10709
  return env;
10319
- return openAttach(env, ctx?.auth ?? currentRequestAuth(), signingKey);
10710
+ return openAttach(env, ctx?.auth ?? currentRequestAuth(), signingKey, attachSecretKey);
10320
10711
  }
10321
10712
  async function openOpaque(bindCall, ctx) {
10322
10713
  const sealedAttach = bindCall.attach_opaque_data != null ? toUint8Array(bindCall.attach_opaque_data) : new Uint8Array(0);
@@ -10361,6 +10752,7 @@ function functionHandlers(config) {
10361
10752
  await resolveSplitPayloads(request, innerParams, {
10362
10753
  auth,
10363
10754
  signingKey,
10755
+ attachSecretKey,
10364
10756
  catalogInterface,
10365
10757
  checkAnchor: true
10366
10758
  });
@@ -10406,6 +10798,7 @@ function functionHandlers(config) {
10406
10798
  await resolveSplitPayloads(request, { bind_call: carried.bindCallIpc }, {
10407
10799
  auth: currentRequestAuth(),
10408
10800
  signingKey,
10801
+ attachSecretKey,
10409
10802
  catalogInterface,
10410
10803
  checkAnchor: false
10411
10804
  });
@@ -10477,7 +10870,7 @@ function functionHandlers(config) {
10477
10870
  const plan = func.plan ? await func.plan(request) : { splits: [{ payload: new Uint8Array(0) }] };
10478
10871
  const fp = fingerprintInputs(toUint8Array(innerParams.bind_call));
10479
10872
  const fingerprint = await bindFingerprint(fp.schemaPath, fp.functionName, fp.args, fp.settings, new Uint8Array(0));
10480
- const anchor = plan.catalogVersion != null ? splitAnchor(plan.catalogVersion) : await liveSplitAnchor(catalogInterface, request.bind_call, ctx?.auth, signingKey) ?? splitAnchor(0);
10873
+ const anchor = plan.catalogVersion != null ? splitAnchor(plan.catalogVersion) : await liveSplitAnchor(catalogInterface, request.bind_call, ctx?.auth, signingKey, attachSecretKey) ?? splitAnchor(0);
10481
10874
  const blobs = [];
10482
10875
  for (const split of plan.splits) {
10483
10876
  const token = await buildSplitToken({
@@ -11338,7 +11731,7 @@ function splitLenPrefixed(buf, count) {
11338
11731
  }
11339
11732
 
11340
11733
  // src/protocol/handlers/table-buffering.ts
11341
- function tableBufferingHandlers(registry, signingKey) {
11734
+ function tableBufferingHandlers(registry, signingKey, attachSecretKey) {
11342
11735
  function resolveBuffering(name, schemaPath) {
11343
11736
  const func = registry.get(name, {
11344
11737
  arguments: new Arguments,
@@ -11355,7 +11748,7 @@ function tableBufferingHandlers(registry, signingKey) {
11355
11748
  const functionName = inner.function_name;
11356
11749
  const executionId = toUint8Array(inner.execution_id);
11357
11750
  const rawAttach = inner.attach_opaque_data ? toUint8Array(inner.attach_opaque_data) : null;
11358
- const attach = rawAttach && rawAttach.length > 0 ? await openAttach(rawAttach, ctx?.auth, signingKey) : rawAttach;
11751
+ const attach = rawAttach && rawAttach.length > 0 ? await openAttach(rawAttach, ctx?.auth, signingKey, attachSecretKey) : rawAttach;
11359
11752
  const transactionId = inner.transaction_id ? toUint8Array(inner.transaction_id) : null;
11360
11753
  const func = resolveBuffering(functionName, inner.schema_path ?? null);
11361
11754
  const bound = new BoundStorage(storage, executionId);
@@ -12946,6 +13339,9 @@ class CatalogInterface {
12946
13339
  catalogContentsOwner(_attachOpaqueData) {
12947
13340
  return this;
12948
13341
  }
13342
+ attachOptions(attachOpaqueData) {
13343
+ return attachOptions(attachOpaqueData);
13344
+ }
12949
13345
  transactionBegin(attachOpaqueData) {
12950
13346
  return null;
12951
13347
  }
@@ -13107,9 +13503,9 @@ var TICKET_ENVELOPE_VERSION = 1;
13107
13503
  var MAX_OPTIONS_BYTES = 16 * 1024;
13108
13504
  var MAX_TICKET_CHARS = 32 * 1024;
13109
13505
  var CLOCK_SKEW_SECONDS = 60;
13110
- var UTF82 = new TextEncoder;
13506
+ var UTF83 = new TextEncoder;
13111
13507
  var STRICT_UTF8 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
13112
- var TICKET_AAD_DOMAIN = UTF82.encode("vgi.attach_ticket.v1\x00");
13508
+ var TICKET_AAD_DOMAIN = UTF83.encode("vgi.attach_ticket.v1\x00");
13113
13509
  var TICKET_ID = /^[0-9a-f]{32}$/;
13114
13510
  var B64URL = /^[A-Za-z0-9_-]+$/;
13115
13511
  var MAX_TEXT = 65535;
@@ -13163,14 +13559,14 @@ class SealAttachDeniedError extends Error {
13163
13559
  }
13164
13560
  }
13165
13561
  function attachTicketAad(principal) {
13166
- const p = UTF82.encode(principal);
13562
+ const p = UTF83.encode(principal);
13167
13563
  const out = new Uint8Array(TICKET_AAD_DOMAIN.length + p.length);
13168
13564
  out.set(TICKET_AAD_DOMAIN, 0);
13169
13565
  out.set(p, TICKET_AAD_DOMAIN.length);
13170
13566
  return out;
13171
13567
  }
13172
13568
  function packText(value, name) {
13173
- const raw = UTF82.encode(value);
13569
+ const raw = UTF83.encode(value);
13174
13570
  if (raw.length > MAX_TEXT)
13175
13571
  throw new Error(`${name} is longer than 65535 bytes`);
13176
13572
  const out = new Uint8Array(2 + raw.length);
@@ -13494,8 +13890,9 @@ function buildAttachTicketsProtocol(config) {
13494
13890
  }
13495
13891
 
13496
13892
  // src/protocol/handlers/catalog/admin.ts
13497
- function catalogAdminHandlers(getCatalog, signingKey) {
13498
- const catalogCatalogs = catalogHandler(signingKey, async () => {
13893
+ function catalogAdminHandlers(getCatalog, signingKey, attachSecretKey) {
13894
+ const keys = { signingKey, attachSecretKey };
13895
+ const catalogCatalogs = catalogHandler(keys, async () => {
13499
13896
  const cat = getCatalog();
13500
13897
  const infos = cat.catalogsInfo ? await cat.catalogsInfo() : cat.catalogs().map((name) => ({
13501
13898
  name,
@@ -13526,29 +13923,31 @@ function catalogAdminHandlers(getCatalog, signingKey) {
13526
13923
  result.catalog_capabilities = encodeCatalogCapabilities(catalogCapabilities(advertised));
13527
13924
  result.selected_capabilities = encodeCatalogCapabilities(selectCatalogCapabilities(advertised, clientCapabilities, result.supports_transactions ?? false));
13528
13925
  }
13529
- const sealedAttach = await sealAttach(toUint8Array(result.attach_opaque_data), ctx?.auth, signingKey);
13926
+ const optionsIpc = innerParams.options == null ? null : toUint8Array(innerParams.options);
13927
+ const secretNames = optionsIpc && optionsIpc.length > 0 ? await secretAttachOptionNames(cat, innerParams.name, deserializeAttachOptionSpec) : new Set;
13928
+ const sealedAttach = await sealAttach(toUint8Array(result.attach_opaque_data), ctx?.auth, signingKey, { optionsIpc, secretNames, attachSecretKey });
13530
13929
  return wrapResult(buildCatalogAttachResult({
13531
13930
  ...result,
13532
13931
  attach_opaque_data: sealedAttach,
13533
13932
  supports_column_statistics: result.supports_column_statistics ?? true
13534
13933
  }), CatalogAttachResultSchema);
13535
13934
  };
13536
- const catalogDetach = catalogHandler(signingKey, async (params) => {
13935
+ const catalogDetach = catalogHandler(keys, async (params) => {
13537
13936
  const cat = getCatalog();
13538
13937
  await cat.detach(toUint8Array(params.attach_opaque_data));
13539
13938
  return {};
13540
13939
  });
13541
- const catalogCreate = catalogHandler(signingKey, async (params) => {
13940
+ const catalogCreate = catalogHandler(keys, async (params) => {
13542
13941
  const cat = getCatalog();
13543
13942
  await cat.create(params.name, params.on_conflict, params.options);
13544
13943
  return {};
13545
13944
  });
13546
- const catalogDrop = catalogHandler(signingKey, async (params) => {
13945
+ const catalogDrop = catalogHandler(keys, async (params) => {
13547
13946
  const cat = getCatalog();
13548
13947
  await cat.drop(params.name);
13549
13948
  return {};
13550
13949
  });
13551
- const catalogVersion = catalogHandler(signingKey, async (params) => {
13950
+ const catalogVersion = catalogHandler(keys, async (params) => {
13552
13951
  const cat = getCatalog();
13553
13952
  const version = await cat.version(toUint8Array(params.attach_opaque_data), params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
13554
13953
  return wrapResult({ version }, CatalogVersionResultSchema);
@@ -13556,23 +13955,23 @@ function catalogAdminHandlers(getCatalog, signingKey) {
13556
13955
  const catalogTransactionBegin = async (params, ctx) => {
13557
13956
  const auth = ctx?.auth;
13558
13957
  const sealedAttach = params.attach_opaque_data != null ? toUint8Array(params.attach_opaque_data) : new Uint8Array(0);
13559
- const attachPlain = await openAttach(sealedAttach, auth, signingKey);
13958
+ const attachPlain = await openAttach(sealedAttach, auth, signingKey, attachSecretKey);
13560
13959
  const cat = getCatalog();
13561
13960
  const txPlain = await cat.transactionBegin(attachPlain);
13562
13961
  const transaction_opaque_data = txPlain != null ? await sealTransaction(toUint8Array(txPlain), sealedAttach, auth, signingKey) : null;
13563
13962
  return wrapResult({ transaction_opaque_data }, CatalogTransactionBeginResultSchema);
13564
13963
  };
13565
- const catalogTransactionCommit = catalogHandler(signingKey, async (params) => {
13964
+ const catalogTransactionCommit = catalogHandler(keys, async (params) => {
13566
13965
  const cat = getCatalog();
13567
13966
  await cat.transactionCommit(toUint8Array(params.attach_opaque_data), toUint8Array(params.transaction_opaque_data));
13568
13967
  return {};
13569
13968
  });
13570
- const catalogTransactionRollback = catalogHandler(signingKey, async (params) => {
13969
+ const catalogTransactionRollback = catalogHandler(keys, async (params) => {
13571
13970
  const cat = getCatalog();
13572
13971
  await cat.transactionRollback(toUint8Array(params.attach_opaque_data), toUint8Array(params.transaction_opaque_data));
13573
13972
  return {};
13574
13973
  });
13575
- const catalogSchemas = catalogHandler(signingKey, async (params) => {
13974
+ const catalogSchemas = catalogHandler(keys, async (params) => {
13576
13975
  const cat = getCatalog();
13577
13976
  const schemas = await cat.schemas(toUint8Array(params.attach_opaque_data), params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
13578
13977
  return wrapResult({
@@ -13581,52 +13980,52 @@ function catalogAdminHandlers(getCatalog, signingKey) {
13581
13980
  });
13582
13981
  const catalogContents = async (params, ctx) => {
13583
13982
  const sealedAttach = toUint8Array(params.attach_opaque_data).slice();
13584
- return catalogHandler(signingKey, async (opened, context) => {
13983
+ return catalogHandler(keys, async (opened, context) => {
13585
13984
  const ifNoneMatch = opened.if_none_match == null ? null : String(opened.if_none_match);
13586
13985
  return serveCatalogContents(getCatalog(), toUint8Array(opened.attach_opaque_data), ifNoneMatch, context, sealedAttach);
13587
13986
  })(params, ctx);
13588
13987
  };
13589
- const catalogCopyFromFormats = catalogHandler(signingKey, async (params) => {
13988
+ const catalogCopyFromFormats = catalogHandler(keys, async (params) => {
13590
13989
  const cat = getCatalog();
13591
13990
  const formats = await cat.copyFromFormats(toUint8Array(params.attach_opaque_data), params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
13592
13991
  return wrapResult({
13593
13992
  items: formats.map((f) => encodeCopyFromFormatInfo(f))
13594
13993
  }, CatalogCopyFromFormatsResultSchema);
13595
13994
  });
13596
- const catalogSchemaGet = catalogHandler(signingKey, async (params) => {
13995
+ const catalogSchemaGet = catalogHandler(keys, async (params) => {
13597
13996
  const cat = getCatalog();
13598
13997
  const info = await cat.schemaGet(toUint8Array(params.attach_opaque_data), params.path, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
13599
13998
  return wrapResult({
13600
13999
  items: info ? [encodeSchemaInfo(info)] : []
13601
14000
  }, CatalogSchemaGetResultSchema);
13602
14001
  });
13603
- const catalogSchemaCreate = catalogHandler(signingKey, async (params) => {
14002
+ const catalogSchemaCreate = catalogHandler(keys, async (params) => {
13604
14003
  if (params.options != null)
13605
14004
  throw new MethodNotImplementedError2("catalog_schema_create requires negotiated vgi.schema.options.create.v1");
13606
14005
  const cat = getCatalog();
13607
14006
  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));
13608
14007
  return {};
13609
14008
  });
13610
- const catalogSchemaDrop = catalogHandler(signingKey, async (params) => {
14009
+ const catalogSchemaDrop = catalogHandler(keys, async (params) => {
13611
14010
  const cat = getCatalog();
13612
14011
  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);
13613
14012
  return {};
13614
14013
  });
13615
- const catalogSchemaContentsTables = catalogHandler(signingKey, async (params) => {
14014
+ const catalogSchemaContentsTables = catalogHandler(keys, async (params) => {
13616
14015
  const cat = getCatalog();
13617
14016
  const tables = await cat.schemaContentsTables(toUint8Array(params.attach_opaque_data), params.path, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
13618
14017
  return wrapResult({
13619
14018
  items: tables.map((t) => encodeValidatedTableInfo(t))
13620
14019
  }, CatalogSchemaContentsTablesResultSchema);
13621
14020
  });
13622
- const catalogSchemaContentsViews = catalogHandler(signingKey, async (params) => {
14021
+ const catalogSchemaContentsViews = catalogHandler(keys, async (params) => {
13623
14022
  const cat = getCatalog();
13624
14023
  const views = await cat.schemaContentsViews(toUint8Array(params.attach_opaque_data), params.path, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
13625
14024
  return wrapResult({
13626
14025
  items: views.map((v) => encodeViewInfo(v))
13627
14026
  }, CatalogSchemaContentsViewsResultSchema);
13628
14027
  });
13629
- const catalogSchemaContentsFunctions = catalogHandler(signingKey, async (params) => {
14028
+ const catalogSchemaContentsFunctions = catalogHandler(keys, async (params) => {
13630
14029
  const cat = getCatalog();
13631
14030
  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);
13632
14031
  return wrapResult({
@@ -13704,15 +14103,16 @@ function requireFlatColumnPath(value, operation) {
13704
14103
  }
13705
14104
  return path;
13706
14105
  }
13707
- function catalogTableHandlers(getCatalog, signingKey) {
13708
- const catalogTableGet = catalogHandler(signingKey, async (params) => {
14106
+ function catalogTableHandlers(getCatalog, signingKey, attachSecretKey) {
14107
+ const keys = { signingKey, attachSecretKey };
14108
+ const catalogTableGet = catalogHandler(keys, async (params) => {
13709
14109
  const cat = getCatalog();
13710
14110
  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);
13711
14111
  return wrapResult({
13712
14112
  items: info ? [encodeValidatedTableInfo(info)] : []
13713
14113
  }, CatalogTableGetResultSchema);
13714
14114
  });
13715
- const catalogTableCreate = catalogHandler(signingKey, async (params) => {
14115
+ const catalogTableCreate = catalogHandler(keys, async (params) => {
13716
14116
  if (params.constraint_definitions == null)
13717
14117
  throw new Error("constraint_definitions is required");
13718
14118
  const definitions = Array.from(params.constraint_definitions, (d) => toUint8Array(d));
@@ -13733,7 +14133,7 @@ function catalogTableHandlers(getCatalog, signingKey) {
13733
14133
  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);
13734
14134
  return {};
13735
14135
  });
13736
- const catalogTableConstraintsApply = catalogHandler(signingKey, async (params) => {
14136
+ const catalogTableConstraintsApply = catalogHandler(keys, async (params) => {
13737
14137
  const attach = toUint8Array(params.attach_opaque_data);
13738
14138
  const cat = getCatalog();
13739
14139
  const caps = await cat.catalogCapabilities(attach);
@@ -13766,50 +14166,50 @@ function catalogTableHandlers(getCatalog, signingKey) {
13766
14166
  }
13767
14167
  return wrapResult({ table, definition_revision: revision, constraints: snapshot.constraints.map((c) => toUint8Array(c)) }, CatalogTableConstraintsApplyResultSchema);
13768
14168
  });
13769
- const catalogTableDrop = catalogHandler(signingKey, async (params) => {
14169
+ const catalogTableDrop = catalogHandler(keys, async (params) => {
13770
14170
  const cat = getCatalog();
13771
14171
  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);
13772
14172
  return {};
13773
14173
  });
13774
- const catalogTableColumnStatisticsGet = catalogHandler(signingKey, async (params) => {
14174
+ const catalogTableColumnStatisticsGet = catalogHandler(keys, async (params) => {
13775
14175
  const cat = getCatalog();
13776
14176
  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);
13777
14177
  return { result: stats?.bytes ?? null };
13778
14178
  });
13779
- const catalogTableScanFunctionGet = catalogHandler(signingKey, async (params) => {
14179
+ const catalogTableScanFunctionGet = catalogHandler(keys, async (params) => {
13780
14180
  const cat = getCatalog();
13781
14181
  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);
13782
14182
  return wrapResult(scanResult, ScanFunctionResultSchema);
13783
14183
  });
13784
14184
  const optionalTx = (params) => params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined;
13785
- const catalogTableInsertFunctionGet = catalogHandler(signingKey, async (params) => {
14185
+ const catalogTableInsertFunctionGet = catalogHandler(keys, async (params) => {
13786
14186
  const result = await getCatalog().tableInsertFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, optionalTx(params), params.writable_branch_function_name ?? null);
13787
14187
  return wrapResult(result, ScanFunctionResultSchema);
13788
14188
  });
13789
- const catalogTableUpdateFunctionGet = catalogHandler(signingKey, async (params) => {
14189
+ const catalogTableUpdateFunctionGet = catalogHandler(keys, async (params) => {
13790
14190
  const result = await getCatalog().tableUpdateFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, optionalTx(params));
13791
14191
  return wrapResult(result, ScanFunctionResultSchema);
13792
14192
  });
13793
- const catalogTableDeleteFunctionGet = catalogHandler(signingKey, async (params) => {
14193
+ const catalogTableDeleteFunctionGet = catalogHandler(keys, async (params) => {
13794
14194
  const result = await getCatalog().tableDeleteFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, optionalTx(params));
13795
14195
  return wrapResult(result, ScanFunctionResultSchema);
13796
14196
  });
13797
- const catalogTableScanBranchesGet = catalogHandler(signingKey, async (params) => {
14197
+ const catalogTableScanBranchesGet = catalogHandler(keys, async (params) => {
13798
14198
  const cat = getCatalog();
13799
14199
  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);
13800
14200
  return wrapResult(branchesResult, ScanBranchesResultSchema);
13801
14201
  });
13802
- const catalogTableCommentSet = catalogHandler(signingKey, async (params) => {
14202
+ const catalogTableCommentSet = catalogHandler(keys, async (params) => {
13803
14203
  const cat = getCatalog();
13804
14204
  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);
13805
14205
  return {};
13806
14206
  });
13807
- const catalogTableRename = catalogHandler(signingKey, async (params) => {
14207
+ const catalogTableRename = catalogHandler(keys, async (params) => {
13808
14208
  const cat = getCatalog();
13809
14209
  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);
13810
14210
  return {};
13811
14211
  });
13812
- const catalogTableColumnAdd = catalogHandler(signingKey, async (params) => {
14212
+ const catalogTableColumnAdd = catalogHandler(keys, async (params) => {
13813
14213
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_add");
13814
14214
  validateColumnMetadataIpc(toUint8Array(params.column_definition));
13815
14215
  validateColumnExpressionsIpc(toUint8Array(params.column_definition), params.schema_path);
@@ -13817,49 +14217,49 @@ function catalogTableHandlers(getCatalog, signingKey) {
13817
14217
  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);
13818
14218
  return {};
13819
14219
  });
13820
- const catalogTableColumnDrop = catalogHandler(signingKey, async (params) => {
14220
+ const catalogTableColumnDrop = catalogHandler(keys, async (params) => {
13821
14221
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_drop");
13822
14222
  const cat = getCatalog();
13823
14223
  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);
13824
14224
  return {};
13825
14225
  });
13826
- const catalogTableColumnRename = catalogHandler(signingKey, async (params) => {
14226
+ const catalogTableColumnRename = catalogHandler(keys, async (params) => {
13827
14227
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_rename");
13828
14228
  const cat = getCatalog();
13829
14229
  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);
13830
14230
  return {};
13831
14231
  });
13832
- const catalogTableColumnCommentSet = catalogHandler(signingKey, async (params) => {
14232
+ const catalogTableColumnCommentSet = catalogHandler(keys, async (params) => {
13833
14233
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_comment_set");
13834
14234
  const cat = getCatalog();
13835
14235
  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);
13836
14236
  return {};
13837
14237
  });
13838
- const catalogTableColumnDefaultSet = catalogHandler(signingKey, async (params) => {
14238
+ const catalogTableColumnDefaultSet = catalogHandler(keys, async (params) => {
13839
14239
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_default_set");
13840
14240
  const cat = getCatalog();
13841
14241
  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);
13842
14242
  return {};
13843
14243
  });
13844
- const catalogTableColumnDefaultDrop = catalogHandler(signingKey, async (params) => {
14244
+ const catalogTableColumnDefaultDrop = catalogHandler(keys, async (params) => {
13845
14245
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_default_drop");
13846
14246
  const cat = getCatalog();
13847
14247
  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);
13848
14248
  return {};
13849
14249
  });
13850
- const catalogTableColumnTypeChange = catalogHandler(signingKey, async (params) => {
14250
+ const catalogTableColumnTypeChange = catalogHandler(keys, async (params) => {
13851
14251
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_column_type_change");
13852
14252
  const cat = getCatalog();
13853
14253
  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);
13854
14254
  return {};
13855
14255
  });
13856
- const catalogTableNotNullSet = catalogHandler(signingKey, async (params) => {
14256
+ const catalogTableNotNullSet = catalogHandler(keys, async (params) => {
13857
14257
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_not_null_set");
13858
14258
  const cat = getCatalog();
13859
14259
  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);
13860
14260
  return {};
13861
14261
  });
13862
- const catalogTableNotNullDrop = catalogHandler(signingKey, async (params) => {
14262
+ const catalogTableNotNullDrop = catalogHandler(keys, async (params) => {
13863
14263
  params.column_path = requireFlatColumnPath(params.column_path, "catalog_table_not_null_drop");
13864
14264
  const cat = getCatalog();
13865
14265
  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);
@@ -13891,15 +14291,16 @@ function catalogTableHandlers(getCatalog, signingKey) {
13891
14291
  }
13892
14292
 
13893
14293
  // src/protocol/handlers/catalog/view.ts
13894
- function catalogViewHandlers(getCatalog, signingKey) {
13895
- const catalogViewGet = catalogHandler(signingKey, async (params) => {
14294
+ function catalogViewHandlers(getCatalog, signingKey, attachSecretKey) {
14295
+ const keys = { signingKey, attachSecretKey };
14296
+ const catalogViewGet = catalogHandler(keys, async (params) => {
13896
14297
  const cat = getCatalog();
13897
14298
  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);
13898
14299
  return wrapResult({
13899
14300
  items: info ? [encodeViewInfo(info)] : []
13900
14301
  }, CatalogViewGetResultSchema);
13901
14302
  });
13902
- const catalogViewCreate = catalogHandler(signingKey, async (params) => {
14303
+ const catalogViewCreate = catalogHandler(keys, async (params) => {
13903
14304
  if (params.security !== "regular")
13904
14305
  throw new Error(`view security mode ${params.security} is unsupported`);
13905
14306
  const tags = catalogStringMap(params.tags);
@@ -13910,22 +14311,22 @@ function catalogViewHandlers(getCatalog, signingKey) {
13910
14311
  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);
13911
14312
  return {};
13912
14313
  });
13913
- const catalogViewDrop = catalogHandler(signingKey, async (params) => {
14314
+ const catalogViewDrop = catalogHandler(keys, async (params) => {
13914
14315
  const cat = getCatalog();
13915
14316
  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);
13916
14317
  return {};
13917
14318
  });
13918
- const catalogViewRename = catalogHandler(signingKey, async (params) => {
14319
+ const catalogViewRename = catalogHandler(keys, async (params) => {
13919
14320
  const cat = getCatalog();
13920
14321
  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);
13921
14322
  return {};
13922
14323
  });
13923
- const catalogViewCommentSet = catalogHandler(signingKey, async (params) => {
14324
+ const catalogViewCommentSet = catalogHandler(keys, async (params) => {
13924
14325
  const cat = getCatalog();
13925
14326
  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);
13926
14327
  return {};
13927
14328
  });
13928
- const catalogViewColumnCommentSet = catalogHandler(signingKey, async (params) => {
14329
+ const catalogViewColumnCommentSet = catalogHandler(keys, async (params) => {
13929
14330
  const path = Array.from(params.column_path);
13930
14331
  if (path.length !== 1 || !path[0] || path[0].includes("\x00"))
13931
14332
  throw new Error("view column comments require one raw output identifier");
@@ -13936,15 +14337,16 @@ function catalogViewHandlers(getCatalog, signingKey) {
13936
14337
  }
13937
14338
 
13938
14339
  // src/protocol/handlers/catalog/macro.ts
13939
- function catalogMacroHandlers(getCatalog, signingKey) {
13940
- const catalogMacroGet = catalogHandler(signingKey, async (params) => {
14340
+ function catalogMacroHandlers(getCatalog, signingKey, attachSecretKey) {
14341
+ const keys = { signingKey, attachSecretKey };
14342
+ const catalogMacroGet = catalogHandler(keys, async (params) => {
13941
14343
  const cat = getCatalog();
13942
14344
  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);
13943
14345
  return wrapResult({
13944
14346
  items: info ? [encodeMacroInfo(info)] : []
13945
14347
  }, CatalogMacroGetResultSchema);
13946
14348
  });
13947
- const catalogMacroCreate = catalogHandler(signingKey, async (params) => {
14349
+ const catalogMacroCreate = catalogHandler(keys, async (params) => {
13948
14350
  const cat = getCatalog();
13949
14351
  const innerParams = decodeASD(MacroCreateRequestSchema, encodeASD(MacroCreateRequestSchema, params));
13950
14352
  if (!innerParams.overloads?.length)
@@ -13952,12 +14354,12 @@ function catalogMacroHandlers(getCatalog, signingKey) {
13952
14354
  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);
13953
14355
  return {};
13954
14356
  });
13955
- const catalogMacroDrop = catalogHandler(signingKey, async (params) => {
14357
+ const catalogMacroDrop = catalogHandler(keys, async (params) => {
13956
14358
  const cat = getCatalog();
13957
14359
  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);
13958
14360
  return {};
13959
14361
  });
13960
- const catalogSchemaContentsMacros = catalogHandler(signingKey, async (params) => {
14362
+ const catalogSchemaContentsMacros = catalogHandler(keys, async (params) => {
13961
14363
  const cat = getCatalog();
13962
14364
  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);
13963
14365
  return wrapResult({
@@ -13968,15 +14370,16 @@ function catalogMacroHandlers(getCatalog, signingKey) {
13968
14370
  }
13969
14371
 
13970
14372
  // src/protocol/handlers/catalog/index_methods.ts
13971
- function catalogIndexHandlers(getCatalog, signingKey) {
13972
- const catalogSchemaContentsIndexes = catalogHandler(signingKey, async (params) => {
14373
+ function catalogIndexHandlers(getCatalog, signingKey, attachSecretKey) {
14374
+ const keys = { signingKey, attachSecretKey };
14375
+ const catalogSchemaContentsIndexes = catalogHandler(keys, async (params) => {
13973
14376
  const cat = getCatalog();
13974
14377
  const indexes = await cat.schemaContentsIndexes(toUint8Array(params.attach_opaque_data), params.path, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
13975
14378
  return wrapResult({
13976
14379
  items: indexes.map((i) => encodeIndexInfo(i))
13977
14380
  }, CatalogSchemaContentsIndexesResultSchema);
13978
14381
  });
13979
- const catalogIndexGet = catalogHandler(signingKey, async (params) => {
14382
+ const catalogIndexGet = catalogHandler(keys, async (params) => {
13980
14383
  const cat = getCatalog();
13981
14384
  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);
13982
14385
  return wrapResult({
@@ -13987,14 +14390,14 @@ function catalogIndexHandlers(getCatalog, signingKey) {
13987
14390
  }
13988
14391
 
13989
14392
  // src/protocol/handlers/catalog/index.ts
13990
- function catalogHandlers(catalog, signingKey) {
14393
+ function catalogHandlers(catalog, signingKey, attachSecretKey) {
13991
14394
  const getCatalog = makeGetCatalog(catalog);
13992
14395
  return {
13993
- ...catalogAdminHandlers(getCatalog, signingKey),
13994
- ...catalogTableHandlers(getCatalog, signingKey),
13995
- ...catalogViewHandlers(getCatalog, signingKey),
13996
- ...catalogMacroHandlers(getCatalog, signingKey),
13997
- ...catalogIndexHandlers(getCatalog, signingKey)
14396
+ ...catalogAdminHandlers(getCatalog, signingKey, attachSecretKey),
14397
+ ...catalogTableHandlers(getCatalog, signingKey, attachSecretKey),
14398
+ ...catalogViewHandlers(getCatalog, signingKey, attachSecretKey),
14399
+ ...catalogMacroHandlers(getCatalog, signingKey, attachSecretKey),
14400
+ ...catalogIndexHandlers(getCatalog, signingKey, attachSecretKey)
13998
14401
  };
13999
14402
  }
14000
14403
 
@@ -14005,11 +14408,12 @@ function buildVgiService(config) {
14005
14408
  ...functionHandlers({
14006
14409
  registry: config.registry,
14007
14410
  signingKey: config.signingKey,
14411
+ attachSecretKey: config.attachSecretKey,
14008
14412
  catalogInterface: config.catalogInterface
14009
14413
  }),
14010
14414
  ...aggregateHandlers(config.registry),
14011
- ...tableBufferingHandlers(config.registry, config.signingKey),
14012
- ...catalogHandlers(config.catalogInterface, config.signingKey)
14415
+ ...tableBufferingHandlers(config.registry, config.signingKey, config.attachSecretKey),
14416
+ ...catalogHandlers(config.catalogInterface, config.signingKey, config.attachSecretKey)
14013
14417
  };
14014
14418
  }
14015
14419
  function buildVgiProtocol(config) {
@@ -17160,4 +17564,4 @@ export {
17160
17564
  validateTableConstraints
17161
17565
  };
17162
17566
 
17163
- //# debugId=FAC9CCEE4111237264756E2164756E21
17567
+ //# debugId=1A848F9DA6F0C91464756E2164756E21