@query-farm/vgi 0.25.2 → 0.25.4

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.
@@ -3916,45 +3916,48 @@ class NoCatalogError extends VgiError {
3916
3916
  function isBytes(a) {
3917
3917
  return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
3918
3918
  }
3919
- function abool(b) {
3920
- if (typeof b !== "boolean")
3921
- throw new TypeError(`boolean expected, not ${b}`);
3919
+ var atitle = (title) => title ? `"${title}" ` : "";
3920
+ function abool(value, title = "") {
3921
+ if (typeof value !== "boolean")
3922
+ throw new TypeError(atitle(title) + "expected boolean, got type=" + typeof value);
3923
+ return value;
3922
3924
  }
3923
- function anumber(n) {
3925
+ function anumber(n, title = "") {
3924
3926
  if (typeof n !== "number")
3925
- throw new TypeError("number expected, got " + typeof n);
3927
+ throw new TypeError(atitle(title) + "expected number, got " + typeof n);
3926
3928
  if (!Number.isSafeInteger(n) || n < 0)
3927
- throw new RangeError("positive integer expected, got " + n);
3929
+ throw new RangeError(atitle(title) + "expected integer >= 0, got " + n);
3930
+ return n;
3928
3931
  }
3929
3932
  function abytes(value, length, title = "") {
3933
+ if (isBytes(value) && (length === undefined || value.length === length))
3934
+ return value;
3935
+ if (length !== undefined)
3936
+ anumber(length, "length");
3930
3937
  const bytes = isBytes(value);
3931
- const len = value?.length;
3932
- const needsLen = length !== undefined;
3933
- if (!bytes || needsLen && len !== length) {
3934
- const prefix = title && `"${title}" `;
3935
- const ofLen = needsLen ? ` of length ${length}` : "";
3936
- const got = bytes ? `length=${len}` : `type=${typeof value}`;
3937
- const message = prefix + "expected Uint8Array" + ofLen + ", got " + got;
3938
- if (!bytes)
3939
- throw new TypeError(message);
3940
- throw new RangeError(message);
3941
- }
3942
- return value;
3943
- }
3938
+ const ofLen = length !== undefined ? ` of length ${length}` : "";
3939
+ const got = bytes ? `length=${value.length}` : `type=${typeof value}`;
3940
+ const message = atitle(title) + "expected Uint8Array" + ofLen + ", got " + got;
3941
+ if (!bytes)
3942
+ throw new TypeError(message);
3943
+ throw new RangeError(message);
3944
+ }
3945
+ var aobject = (value, label) => {
3946
+ if (value === null || typeof value !== "object" || Array.isArray(value))
3947
+ throw new TypeError(label === "object" ? "expected valid options object" : `"${label}" expected object, got type=${typeof value}`);
3948
+ };
3944
3949
  function aexists(instance, checkFinished = true) {
3945
3950
  if (instance.destroyed)
3946
- throw new Error("Hash instance has been destroyed");
3951
+ throw new Error("hash was destroyed");
3947
3952
  if (checkFinished && instance.finished)
3948
- throw new Error("Hash#digest() has already been called");
3953
+ throw new Error("digest() was already called");
3949
3954
  }
3950
- function aoutput(out, instance, onlyAligned = false) {
3955
+ function aoutput(out, instance) {
3951
3956
  abytes(out, undefined, "output");
3952
3957
  const min = instance.outputLen;
3953
- if (out.length < min) {
3954
- throw new RangeError("digestInto() expects output buffer of length at least " + min);
3958
+ if (!(out.length >= min)) {
3959
+ throw new RangeError('"output" expected length >= ' + min);
3955
3960
  }
3956
- if (onlyAligned && !isAligned32(out))
3957
- throw new Error("invalid output, must be aligned");
3958
3961
  }
3959
3962
  function u32(arr) {
3960
3963
  return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
@@ -3968,21 +3971,25 @@ function createView(arr) {
3968
3971
  return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
3969
3972
  }
3970
3973
  var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
3971
- var byteSwap = (word) => word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
3972
- var swap8IfBE = isLE ? (n) => n : (n) => byteSwap(n) >>> 0;
3973
- var byteSwap32 = (arr) => {
3974
- for (let i = 0;i < arr.length; i++)
3974
+ function byteSwap(word) {
3975
+ return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
3976
+ }
3977
+ function byteSwap32(arr) {
3978
+ for (let i = 0;i < arr.length; i++) {
3975
3979
  arr[i] = byteSwap(arr[i]);
3980
+ }
3976
3981
  return arr;
3977
- };
3982
+ }
3978
3983
  var swap32IfBE = isLE ? (u) => u : byteSwap32;
3979
3984
  function checkOpts(defaults, opts) {
3980
- if (opts == null || typeof opts !== "object")
3981
- throw new Error("options must be defined");
3985
+ aobject(defaults, "defaults");
3986
+ aobject(opts, "opts");
3982
3987
  const merged = Object.assign(defaults, opts);
3983
3988
  return merged;
3984
3989
  }
3985
3990
  function equalBytes(a, b) {
3991
+ a = abytes(a);
3992
+ b = abytes(b);
3986
3993
  if (a.length !== b.length)
3987
3994
  return false;
3988
3995
  let diff = 0;
@@ -4008,8 +4015,14 @@ var wrapCipher = (params, constructor) => {
4008
4015
  abytes(nonce, params.varSizeNonce ? undefined : params.nonceLength, "nonce");
4009
4016
  }
4010
4017
  const tagl = params.tagLength;
4011
- if (tagl && args[1] !== undefined)
4012
- abytes(args[1], undefined, "AAD");
4018
+ const aadStart = params.nonceLength !== undefined ? 1 : 0;
4019
+ if (!params.withAAD) {
4020
+ for (let i = aadStart;i < args.length; i++)
4021
+ if (isBytes(args[i]))
4022
+ throw new Error("AAD not supported");
4023
+ }
4024
+ if (params.withAAD && args[aadStart] !== undefined)
4025
+ abytes(args[aadStart], undefined, "AAD");
4013
4026
  const cipher = constructor(key, ...args);
4014
4027
  const checkOutput = (fnLength, output) => {
4015
4028
  if (output !== undefined) {
@@ -4024,14 +4037,14 @@ var wrapCipher = (params, constructor) => {
4024
4037
  if (called)
4025
4038
  throw new Error("cannot encrypt() twice with same key + nonce");
4026
4039
  called = true;
4027
- abytes(data);
4040
+ abytes(data, undefined, "data");
4028
4041
  checkOutput(cipher.encrypt.length, output);
4029
4042
  return cipher.encrypt(data, output);
4030
4043
  },
4031
4044
  decrypt(data, output) {
4032
- abytes(data);
4045
+ abytes(data, undefined, "data");
4033
4046
  if (tagl && data.length < tagl)
4034
- throw new Error('"ciphertext" expected length bigger than tagLength=' + tagl);
4047
+ throw new Error('"ciphertext" expected length >= tagLength=' + tagl);
4035
4048
  checkOutput(cipher.decrypt.length, output);
4036
4049
  return cipher.decrypt(data, output);
4037
4050
  }
@@ -4044,9 +4057,7 @@ var wrapCipher = (params, constructor) => {
4044
4057
  function getOutput(expectedLength, out, onlyAligned = true) {
4045
4058
  if (out === undefined)
4046
4059
  return new Uint8Array(expectedLength);
4047
- abytes(out, undefined, "output");
4048
- if (out.length !== expectedLength)
4049
- throw new Error('"output" expected Uint8Array of length ' + expectedLength + ", got: " + out.length);
4060
+ abytes(out, expectedLength, "output");
4050
4061
  if (onlyAligned && !isAligned32(out))
4051
4062
  throw new Error("invalid output, must be aligned");
4052
4063
  return out;
@@ -4163,7 +4174,7 @@ function createCipher(core, opts) {
4163
4174
  let k32 = u32(k);
4164
4175
  if (extendNonceFn) {
4165
4176
  if (nonce.length !== 24)
4166
- throw new Error(`arx: extended nonce must be 24 bytes`);
4177
+ throw new Error("arx: extended nonce must be 24 bytes");
4167
4178
  const n16 = nonce.subarray(0, 16);
4168
4179
  if (isLE)
4169
4180
  extendNonceFn(sigma, k32, u32(n16), k32);
@@ -4199,6 +4210,7 @@ function createCipher(core, opts) {
4199
4210
  function u8to16(a, i) {
4200
4211
  return a[i++] & 255 | (a[i++] & 255) << 8;
4201
4212
  }
4213
+
4202
4214
  class Poly1305 {
4203
4215
  blockLen = 16;
4204
4216
  outputLen = 16;
@@ -4533,83 +4545,24 @@ function chachaCore(s, k, n, out, cnt, rounds = 20) {
4533
4545
  out[oi++] = y15 + x15 | 0;
4534
4546
  }
4535
4547
  function hchacha(s, k, i, out) {
4536
- let x00 = swap8IfBE(s[0]), x01 = swap8IfBE(s[1]), x02 = swap8IfBE(s[2]), x03 = swap8IfBE(s[3]), x04 = swap8IfBE(k[0]), x05 = swap8IfBE(k[1]), x06 = swap8IfBE(k[2]), x07 = swap8IfBE(k[3]), x08 = swap8IfBE(k[4]), x09 = swap8IfBE(k[5]), x10 = swap8IfBE(k[6]), x11 = swap8IfBE(k[7]), x12 = swap8IfBE(i[0]), x13 = swap8IfBE(i[1]), x14 = swap8IfBE(i[2]), x15 = swap8IfBE(i[3]);
4537
- for (let r = 0;r < 20; r += 2) {
4538
- x00 = x00 + x04 | 0;
4539
- x12 = rotl(x12 ^ x00, 16);
4540
- x08 = x08 + x12 | 0;
4541
- x04 = rotl(x04 ^ x08, 12);
4542
- x00 = x00 + x04 | 0;
4543
- x12 = rotl(x12 ^ x00, 8);
4544
- x08 = x08 + x12 | 0;
4545
- x04 = rotl(x04 ^ x08, 7);
4546
- x01 = x01 + x05 | 0;
4547
- x13 = rotl(x13 ^ x01, 16);
4548
- x09 = x09 + x13 | 0;
4549
- x05 = rotl(x05 ^ x09, 12);
4550
- x01 = x01 + x05 | 0;
4551
- x13 = rotl(x13 ^ x01, 8);
4552
- x09 = x09 + x13 | 0;
4553
- x05 = rotl(x05 ^ x09, 7);
4554
- x02 = x02 + x06 | 0;
4555
- x14 = rotl(x14 ^ x02, 16);
4556
- x10 = x10 + x14 | 0;
4557
- x06 = rotl(x06 ^ x10, 12);
4558
- x02 = x02 + x06 | 0;
4559
- x14 = rotl(x14 ^ x02, 8);
4560
- x10 = x10 + x14 | 0;
4561
- x06 = rotl(x06 ^ x10, 7);
4562
- x03 = x03 + x07 | 0;
4563
- x15 = rotl(x15 ^ x03, 16);
4564
- x11 = x11 + x15 | 0;
4565
- x07 = rotl(x07 ^ x11, 12);
4566
- x03 = x03 + x07 | 0;
4567
- x15 = rotl(x15 ^ x03, 8);
4568
- x11 = x11 + x15 | 0;
4569
- x07 = rotl(x07 ^ x11, 7);
4570
- x00 = x00 + x05 | 0;
4571
- x15 = rotl(x15 ^ x00, 16);
4572
- x10 = x10 + x15 | 0;
4573
- x05 = rotl(x05 ^ x10, 12);
4574
- x00 = x00 + x05 | 0;
4575
- x15 = rotl(x15 ^ x00, 8);
4576
- x10 = x10 + x15 | 0;
4577
- x05 = rotl(x05 ^ x10, 7);
4578
- x01 = x01 + x06 | 0;
4579
- x12 = rotl(x12 ^ x01, 16);
4580
- x11 = x11 + x12 | 0;
4581
- x06 = rotl(x06 ^ x11, 12);
4582
- x01 = x01 + x06 | 0;
4583
- x12 = rotl(x12 ^ x01, 8);
4584
- x11 = x11 + x12 | 0;
4585
- x06 = rotl(x06 ^ x11, 7);
4586
- x02 = x02 + x07 | 0;
4587
- x13 = rotl(x13 ^ x02, 16);
4588
- x08 = x08 + x13 | 0;
4589
- x07 = rotl(x07 ^ x08, 12);
4590
- x02 = x02 + x07 | 0;
4591
- x13 = rotl(x13 ^ x02, 8);
4592
- x08 = x08 + x13 | 0;
4593
- x07 = rotl(x07 ^ x08, 7);
4594
- x03 = x03 + x04 | 0;
4595
- x14 = rotl(x14 ^ x03, 16);
4596
- x09 = x09 + x14 | 0;
4597
- x04 = rotl(x04 ^ x09, 12);
4598
- x03 = x03 + x04 | 0;
4599
- x14 = rotl(x14 ^ x03, 8);
4600
- x09 = x09 + x14 | 0;
4601
- x04 = rotl(x04 ^ x09, 7);
4602
- }
4548
+ const s2 = isLE ? s : swap32IfBE(s.slice(0, 4));
4549
+ const k2 = isLE ? k : swap32IfBE(k.slice(0, 8));
4550
+ const i2 = isLE ? i : swap32IfBE(i.slice(0, 4));
4551
+ const t = new Uint32Array(16);
4552
+ chachaCore(s2, k2, i2.subarray(1), t, i2[0]);
4603
4553
  let oi = 0;
4604
- out[oi++] = x00;
4605
- out[oi++] = x01;
4606
- out[oi++] = x02;
4607
- out[oi++] = x03;
4608
- out[oi++] = x12;
4609
- out[oi++] = x13;
4610
- out[oi++] = x14;
4611
- out[oi++] = x15;
4554
+ out[oi++] = t[0] - s2[0] | 0;
4555
+ out[oi++] = t[1] - s2[1] | 0;
4556
+ out[oi++] = t[2] - s2[2] | 0;
4557
+ out[oi++] = t[3] - s2[3] | 0;
4558
+ out[oi++] = t[12] - i2[0] | 0;
4559
+ out[oi++] = t[13] - i2[1] | 0;
4560
+ out[oi++] = t[14] - i2[2] | 0;
4561
+ out[oi++] = t[15] - i2[3] | 0;
4612
4562
  swap32IfBE(out);
4563
+ if (!isLE)
4564
+ clean(s2, k2, i2);
4565
+ clean(t);
4613
4566
  }
4614
4567
  var xchacha20 = /* @__PURE__ */ createCipher(chachaCore, {
4615
4568
  counterRight: false,
@@ -4669,7 +4622,7 @@ var _poly1305_aead = (xorStream) => (key, nonce, AAD) => {
4669
4622
  }
4670
4623
  };
4671
4624
  };
4672
- var xchacha20poly1305 = /* @__PURE__ */ wrapCipher({ blockSize: 64, nonceLength: 24, tagLength: 16 }, /* @__PURE__ */ _poly1305_aead(xchacha20));
4625
+ var xchacha20poly1305 = /* @__PURE__ */ wrapCipher({ blockSize: 64, nonceLength: 24, tagLength: 16, withAAD: true }, /* @__PURE__ */ _poly1305_aead(xchacha20));
4673
4626
 
4674
4627
  // src/crypto.ts
4675
4628
  var _UTF8 = new TextEncoder;
@@ -9499,4 +9452,4 @@ export {
9499
9452
  Arguments
9500
9453
  };
9501
9454
 
9502
- //# debugId=372B5FB94FE209FC64756E2164756E21
9455
+ //# debugId=F404D5F0E509901A64756E2164756E21