@vitia.ai/secure-api-client-vue 0.1.0 → 0.1.1

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.
package/dist/index.mjs CHANGED
@@ -157,8 +157,8 @@ function ns(n) {
157
157
  const e = Ce(n), t = At(n), r = t(e, e.neg(e.ONE)), s = t(e, r), i = t(e, e.neg(r)), o = (n + ts) / kt;
158
158
  return (c, a) => {
159
159
  let u = c.pow(a, o), f = c.mul(u, r);
160
- const h = c.mul(u, s), l = c.mul(u, i), g = c.eql(c.sqr(f), a), B = c.eql(c.sqr(h), a);
161
- u = c.cmov(u, f, g), f = c.cmov(l, h, B);
160
+ const h = c.mul(u, s), l = c.mul(u, i), g = c.eql(c.sqr(f), a), w = c.eql(c.sqr(h), a);
161
+ u = c.cmov(u, f, g), f = c.cmov(l, h, w);
162
162
  const m = c.eql(c.sqr(f), a), b = c.cmov(u, f, m);
163
163
  return Te(c, b, a), b;
164
164
  };
@@ -187,12 +187,12 @@ function At(n) {
187
187
  for (; !a.eql(l, a.ONE); ) {
188
188
  if (a.is0(l))
189
189
  return a.ZERO;
190
- let B = 1, m = a.sqr(l);
190
+ let w = 1, m = a.sqr(l);
191
191
  for (; !a.eql(m, a.ONE); )
192
- if (B++, m = a.sqr(m), B === f)
192
+ if (w++, m = a.sqr(m), w === f)
193
193
  throw new Error("Cannot find square root");
194
- const b = p << BigInt(f - B - 1), D = a.pow(h, b);
195
- f = B, h = a.sqr(D), l = a.mul(l, h), g = a.mul(g, D);
194
+ const b = p << BigInt(f - w - 1), D = a.pow(h, b);
195
+ f = w, h = a.sqr(D), l = a.mul(l, h), g = a.mul(g, D);
196
196
  }
197
197
  return g;
198
198
  };
@@ -286,16 +286,16 @@ function Ce(n, e, t = !1, r = {}) {
286
286
  }
287
287
  if (l.length !== u)
288
288
  throw new Error("Field.fromBytes: expected " + u + " bytes, got " + l.length);
289
- let B = t ? pe(l) : Xr(l);
290
- if (o && (B = I(B, n)), !g && !h.isValid(B))
289
+ let w = t ? pe(l) : Xr(l);
290
+ if (o && (w = I(w, n)), !g && !h.isValid(w))
291
291
  throw new Error("invalid field element: outside of range 0..ORDER");
292
- return B;
292
+ return w;
293
293
  },
294
294
  // TODO: we don't need it here, move out to separate fn
295
295
  invertBatch: (l) => cs(h, l),
296
296
  // We can't move this out because Fp6, Fp12 implement it
297
297
  // and it's unclear what to return in there.
298
- cmov: (l, g, B) => B ? g : l
298
+ cmov: (l, g, w) => w ? g : l
299
299
  });
300
300
  return Object.freeze(h);
301
301
  }
@@ -311,7 +311,7 @@ function us(n) {
311
311
  const e = ls(n), { P: t, type: r, adjustScalarBytes: s, powPminus2: i, randomBytes: o } = e, c = r === "x25519";
312
312
  if (!c && r !== "x448")
313
313
  throw new Error("invalid type");
314
- const a = o || zr, u = c ? 255 : 448, f = c ? 32 : 56, h = BigInt(c ? 9 : 5), l = BigInt(c ? 121665 : 39081), g = c ? fe ** BigInt(254) : fe ** BigInt(447), B = c ? BigInt(8) * fe ** BigInt(251) - z : BigInt(4) * fe ** BigInt(445) - z, m = g + B + z, b = (y) => I(y, t), D = le(h);
314
+ const a = o || zr, u = c ? 255 : 448, f = c ? 32 : 56, h = BigInt(c ? 9 : 5), l = BigInt(c ? 121665 : 39081), g = c ? fe ** BigInt(254) : fe ** BigInt(447), w = c ? BigInt(8) * fe ** BigInt(251) - z : BigInt(4) * fe ** BigInt(445) - z, m = g + w + z, b = (y) => I(y, t), D = le(h);
315
315
  function le(y) {
316
316
  return wt(b(y), f);
317
317
  }
@@ -383,7 +383,7 @@ const hs = BigInt(1), rt = BigInt(2), fs = BigInt(3), ds = BigInt(5), gs = BigIn
383
383
  Gy: BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")
384
384
  };
385
385
  function Bs(n) {
386
- const e = BigInt(10), t = BigInt(20), r = BigInt(40), s = BigInt(80), i = xt, c = n * n % i * n % i, a = U(c, rt, i) * c % i, u = U(a, hs, i) * n % i, f = U(u, ds, i) * u % i, h = U(f, e, i) * f % i, l = U(h, t, i) * h % i, g = U(l, r, i) * l % i, B = U(g, s, i) * g % i, m = U(B, s, i) * g % i, b = U(m, e, i) * f % i;
386
+ const e = BigInt(10), t = BigInt(20), r = BigInt(40), s = BigInt(80), i = xt, c = n * n % i * n % i, a = U(c, rt, i) * c % i, u = U(a, hs, i) * n % i, f = U(u, ds, i) * u % i, h = U(f, e, i) * f % i, l = U(h, t, i) * h % i, g = U(l, r, i) * l % i, w = U(g, s, i) * g % i, m = U(w, s, i) * g % i, b = U(m, e, i) * f % i;
387
387
  return { pow_p_5_8: U(b, rt, i) * n % i, b2: c };
388
388
  }
389
389
  function ys(n) {
@@ -426,7 +426,7 @@ const bs = Ce(ws.p, { isLE: !0 }), Se = /* @__PURE__ */ (() => {
426
426
  *
427
427
  */
428
428
  const vs = "[object ArrayBuffer]";
429
- class w {
429
+ class B {
430
430
  static isArrayBuffer(e) {
431
431
  return Object.prototype.toString.call(e) === vs;
432
432
  }
@@ -452,7 +452,7 @@ class w {
452
452
  return ArrayBuffer.isView(e) || e && this.isArrayBuffer(e.buffer);
453
453
  }
454
454
  static isEqual(e, t) {
455
- const r = w.toUint8Array(e), s = w.toUint8Array(t);
455
+ const r = B.toUint8Array(e), s = B.toUint8Array(t);
456
456
  if (r.length !== s.byteLength)
457
457
  return !1;
458
458
  for (let i = 0; i < r.length; i++)
@@ -484,7 +484,7 @@ class st {
484
484
  return r.buffer;
485
485
  }
486
486
  static toString(e) {
487
- const t = w.toUint8Array(e);
487
+ const t = B.toUint8Array(e);
488
488
  let r = "";
489
489
  for (let i = 0; i < t.length; i++)
490
490
  r += String.fromCharCode(t[i]);
@@ -493,7 +493,7 @@ class st {
493
493
  }
494
494
  class V {
495
495
  static toString(e, t = !1) {
496
- const r = w.toArrayBuffer(e), s = new DataView(r);
496
+ const r = B.toArrayBuffer(e), s = new DataView(r);
497
497
  let i = "";
498
498
  for (let o = 0; o < r.byteLength; o += 2) {
499
499
  const c = s.getUint16(o, t);
@@ -519,7 +519,7 @@ class v {
519
519
  return typeof e === Ee && As.test(e);
520
520
  }
521
521
  static ToString(e, t = "utf8") {
522
- const r = w.toUint8Array(e);
522
+ const r = B.toUint8Array(e);
523
523
  switch (t.toLowerCase()) {
524
524
  case "utf8":
525
525
  return this.ToUtf8String(r);
@@ -564,7 +564,7 @@ class v {
564
564
  }
565
565
  }
566
566
  static ToBase64(e) {
567
- const t = w.toUint8Array(e);
567
+ const t = B.toUint8Array(e);
568
568
  if (typeof btoa < "u") {
569
569
  const r = this.ToString(t, "binary");
570
570
  return btoa(r);
@@ -629,14 +629,14 @@ class v {
629
629
  return r.buffer;
630
630
  }
631
631
  static ToBinary(e) {
632
- const t = w.toUint8Array(e);
632
+ const t = B.toUint8Array(e);
633
633
  let r = "";
634
634
  for (let s = 0; s < t.length; s++)
635
635
  r += String.fromCharCode(t[s]);
636
636
  return r;
637
637
  }
638
638
  static ToHex(e) {
639
- const t = w.toUint8Array(e);
639
+ const t = B.toUint8Array(e);
640
640
  let r = "";
641
641
  const s = t.length;
642
642
  for (let i = 0; i < s; i++) {
@@ -855,7 +855,7 @@ function L(n) {
855
855
  var s;
856
856
  super(...r);
857
857
  const i = r[0] || {};
858
- this.isHexOnly = (s = i.isHexOnly) !== null && s !== void 0 ? s : !1, this.valueHexView = i.valueHex ? w.toUint8Array(i.valueHex) : Le;
858
+ this.isHexOnly = (s = i.isHexOnly) !== null && s !== void 0 ? s : !1, this.valueHexView = i.valueHex ? B.toUint8Array(i.valueHex) : Le;
859
859
  }
860
860
  fromBER(r, s, i) {
861
861
  const o = r instanceof ArrayBuffer ? new Uint8Array(r) : r;
@@ -887,7 +887,7 @@ class q {
887
887
  this.valueBeforeDecodeView = new Uint8Array(e);
888
888
  }
889
889
  constructor({ blockLength: e = 0, error: t = Y, warnings: r = [], valueBeforeDecode: s = Le } = {}) {
890
- this.blockLength = e, this.error = t, this.warnings = r, this.valueBeforeDecodeView = w.toUint8Array(s);
890
+ this.blockLength = e, this.error = t, this.warnings = r, this.valueBeforeDecodeView = B.toUint8Array(s);
891
891
  }
892
892
  toJSON() {
893
893
  return {
@@ -912,7 +912,7 @@ S.NAME = "valueBlock";
912
912
  class Nt extends L(q) {
913
913
  constructor({ idBlock: e = {} } = {}) {
914
914
  var t, r, s, i;
915
- super(), e ? (this.isHexOnly = (t = e.isHexOnly) !== null && t !== void 0 ? t : !1, this.valueHexView = e.valueHex ? w.toUint8Array(e.valueHex) : Le, this.tagClass = (r = e.tagClass) !== null && r !== void 0 ? r : -1, this.tagNumber = (s = e.tagNumber) !== null && s !== void 0 ? s : -1, this.isConstructed = (i = e.isConstructed) !== null && i !== void 0 ? i : !1) : (this.tagClass = -1, this.tagNumber = -1, this.isConstructed = !1);
915
+ super(), e ? (this.isHexOnly = (t = e.isHexOnly) !== null && t !== void 0 ? t : !1, this.valueHexView = e.valueHex ? B.toUint8Array(e.valueHex) : Le, this.tagClass = (r = e.tagClass) !== null && r !== void 0 ? r : -1, this.tagNumber = (s = e.tagNumber) !== null && s !== void 0 ? s : -1, this.isConstructed = (i = e.isConstructed) !== null && i !== void 0 ? i : !1) : (this.tagClass = -1, this.tagNumber = -1, this.isConstructed = !1);
916
916
  }
917
917
  toBER(e = !1) {
918
918
  let t = 0;
@@ -959,7 +959,7 @@ class Nt extends L(q) {
959
959
  return r.buffer;
960
960
  }
961
961
  fromBER(e, t, r) {
962
- const s = w.toUint8Array(e);
962
+ const s = B.toUint8Array(e);
963
963
  if (!H(this, s, t, r))
964
964
  return -1;
965
965
  const i = s.subarray(t, t + r);
@@ -1039,7 +1039,7 @@ class It extends q {
1039
1039
  super(), this.isIndefiniteForm = (t = e.isIndefiniteForm) !== null && t !== void 0 ? t : !1, this.longFormUsed = (r = e.longFormUsed) !== null && r !== void 0 ? r : !1, this.length = (s = e.length) !== null && s !== void 0 ? s : 0;
1040
1040
  }
1041
1041
  fromBER(e, t, r) {
1042
- const s = w.toUint8Array(e);
1042
+ const s = B.toUint8Array(e);
1043
1043
  if (!H(this, s, t, r))
1044
1044
  return -1;
1045
1045
  const i = s.subarray(t, t + r);
@@ -1349,7 +1349,7 @@ function ps(n) {
1349
1349
  result: e
1350
1350
  };
1351
1351
  }
1352
- return we(w.toUint8Array(n).slice(), 0, n.byteLength);
1352
+ return we(B.toUint8Array(n).slice(), 0, n.byteLength);
1353
1353
  }
1354
1354
  function Ns(n, e) {
1355
1355
  return n ? 1 : e;
@@ -1359,7 +1359,7 @@ class O extends S {
1359
1359
  super(r), this.value = e, this.isIndefiniteForm = t;
1360
1360
  }
1361
1361
  fromBER(e, t, r) {
1362
- const s = w.toUint8Array(e);
1362
+ const s = B.toUint8Array(e);
1363
1363
  if (!H(this, s, t, r))
1364
1364
  return -1;
1365
1365
  if (this.valueBeforeDecodeView = s.subarray(t, t + r), this.valueBeforeDecodeView.length === 0)
@@ -1469,10 +1469,10 @@ class $t extends L(S) {
1469
1469
  this.valueHexView[0] = e ? 255 : 0;
1470
1470
  }
1471
1471
  constructor({ value: e, ...t } = {}) {
1472
- super(t), t.valueHex ? this.valueHexView = w.toUint8Array(t.valueHex) : this.valueHexView = new Uint8Array(1), e && (this.value = e);
1472
+ super(t), t.valueHex ? this.valueHexView = B.toUint8Array(t.valueHex) : this.valueHexView = new Uint8Array(1), e && (this.value = e);
1473
1473
  }
1474
1474
  fromBER(e, t, r) {
1475
- const s = w.toUint8Array(e);
1475
+ const s = B.toUint8Array(e);
1476
1476
  return H(this, s, t, r) ? (this.valueHexView = s.subarray(t, t + r), r > 1 && this.warnings.push("Boolean value encoded in more then 1 octet"), this.isHexOnly = !0, St.call(this), this.blockLength = r, t + r) : -1;
1477
1477
  }
1478
1478
  toBER() {
@@ -1581,7 +1581,7 @@ class qt extends A {
1581
1581
  const e = [];
1582
1582
  for (const t of this.valueBlock.value)
1583
1583
  t instanceof Re && e.push(t.valueBlock.valueHexView);
1584
- return w.concat(e);
1584
+ return B.concat(e);
1585
1585
  }
1586
1586
  }
1587
1587
  Re = qt;
@@ -1614,7 +1614,7 @@ class Gt extends L(O) {
1614
1614
  }
1615
1615
  return s;
1616
1616
  }
1617
- const i = w.toUint8Array(e);
1617
+ const i = B.toUint8Array(e);
1618
1618
  if (!H(this, i, t, r))
1619
1619
  return -1;
1620
1620
  const o = i.subarray(t, t + r);
@@ -1844,7 +1844,7 @@ class De extends A {
1844
1844
  if (t < 0) {
1845
1845
  const c = new Uint8Array(i.length + (i[0] & 128 ? 1 : 0));
1846
1846
  c[0] |= 128;
1847
- const u = BigInt(`0x${v.ToHex(c)}`) + t, f = w.toUint8Array(v.FromHex(u.toString(16)));
1847
+ const u = BigInt(`0x${v.ToHex(c)}`) + t, f = B.toUint8Array(v.FromHex(u.toString(16)));
1848
1848
  f[0] |= 128, r.write(f);
1849
1849
  } else
1850
1850
  i[0] & 128 && r.write(new Uint8Array([0])), r.write(i);
@@ -1882,7 +1882,7 @@ class Ie extends L(S) {
1882
1882
  fromBER(e, t, r) {
1883
1883
  if (!r)
1884
1884
  return t;
1885
- const s = w.toUint8Array(e);
1885
+ const s = B.toUint8Array(e);
1886
1886
  if (!H(this, s, t, r))
1887
1887
  return -1;
1888
1888
  const i = s.subarray(t, t + r);
@@ -2057,7 +2057,7 @@ class Ue extends L(q) {
2057
2057
  fromBER(e, t, r) {
2058
2058
  if (r === 0)
2059
2059
  return t;
2060
- const s = w.toUint8Array(e);
2060
+ const s = B.toUint8Array(e);
2061
2061
  if (!H(this, s, t, r))
2062
2062
  return -1;
2063
2063
  const i = s.subarray(t, t + r);
@@ -2221,7 +2221,7 @@ class N extends Vt {
2221
2221
  super(e, ir);
2222
2222
  }
2223
2223
  fromBuffer(e) {
2224
- this.valueBlock.value = String.fromCharCode.apply(null, w.toUint8Array(e));
2224
+ this.valueBlock.value = String.fromCharCode.apply(null, B.toUint8Array(e));
2225
2225
  }
2226
2226
  fromString(e) {
2227
2227
  const t = e.length, r = this.valueBlock.valueHexView = new Uint8Array(t);
@@ -2233,7 +2233,7 @@ class N extends Vt {
2233
2233
  N.NAME = "SIMPLE STRING";
2234
2234
  class or extends N {
2235
2235
  fromBuffer(e) {
2236
- this.valueBlock.valueHexView = w.toUint8Array(e);
2236
+ this.valueBlock.valueHexView = B.toUint8Array(e);
2237
2237
  try {
2238
2238
  this.valueBlock.value = v.ToUtf8String(e);
2239
2239
  } catch (t) {
@@ -2256,7 +2256,7 @@ d.Utf8String = cr;
2256
2256
  G.NAME = "UTF8String";
2257
2257
  class ar extends N {
2258
2258
  fromBuffer(e) {
2259
- this.valueBlock.value = v.ToUtf16String(e), this.valueBlock.valueHexView = w.toUint8Array(e);
2259
+ this.valueBlock.value = v.ToUtf16String(e), this.valueBlock.valueHexView = B.toUint8Array(e);
2260
2260
  }
2261
2261
  fromString(e) {
2262
2262
  this.valueBlock.value = e, this.valueBlock.valueHexView = new Uint8Array(v.FromUtf16String(e));
@@ -2394,7 +2394,7 @@ class Fe extends Pe {
2394
2394
  t && (this.fromDate(t), this.valueBlock.valueHexView = new Uint8Array(this.toBuffer())), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 23;
2395
2395
  }
2396
2396
  fromBuffer(e) {
2397
- this.fromString(String.fromCharCode.apply(null, w.toUint8Array(e)));
2397
+ this.fromString(String.fromCharCode.apply(null, B.toUint8Array(e)));
2398
2398
  }
2399
2399
  toBuffer() {
2400
2400
  const e = this.toString(), t = new ArrayBuffer(e.length), r = new Uint8Array(t);
@@ -2475,13 +2475,13 @@ class _r extends Fe {
2475
2475
  if (l === -1 && (l = r.indexOf("-"), h = -1), l !== -1) {
2476
2476
  if (g = r.substring(l + 1), r = r.substring(0, l), g.length !== 2 && g.length !== 4)
2477
2477
  throw new Error("Wrong input string for conversion");
2478
- let B = parseInt(g.substring(0, 2), 10);
2479
- if (isNaN(B.valueOf()))
2478
+ let w = parseInt(g.substring(0, 2), 10);
2479
+ if (isNaN(w.valueOf()))
2480
2480
  throw new Error("Wrong input string for conversion");
2481
- if (c = h * B, g.length === 4) {
2482
- if (B = parseInt(g.substring(2, 4), 10), isNaN(B.valueOf()))
2481
+ if (c = h * w, g.length === 4) {
2482
+ if (w = parseInt(g.substring(2, 4), 10), isNaN(w.valueOf()))
2483
2483
  throw new Error("Wrong input string for conversion");
2484
- a = h * B;
2484
+ a = h * w;
2485
2485
  }
2486
2486
  }
2487
2487
  }
@@ -2860,7 +2860,7 @@ class Os {
2860
2860
  });
2861
2861
  if (!u.ok)
2862
2862
  throw new Error(`Handshake failed: ${u.status} ${u.statusText}`);
2863
- const f = await u.json(), { session_id: h, server_pub: l, server_sig: g, session_expires_at: B } = f;
2863
+ const f = await u.json(), { session_id: h, server_pub: l, server_sig: g, session_expires_at: w } = f;
2864
2864
  if (window.__akv = { server_pub: l, server_sig: g }, !h || !l || !g)
2865
2865
  throw new Error("Handshake response missing fields");
2866
2866
  const m = ie(l), b = ie(g);
@@ -2881,7 +2881,7 @@ class Os {
2881
2881
  sessionId: h,
2882
2882
  encKey: ue,
2883
2883
  macKey: te,
2884
- sessionExpiresAt: B
2884
+ sessionExpiresAt: w
2885
2885
  });
2886
2886
  }
2887
2887
  getUserId() {
@@ -2919,17 +2919,20 @@ class Os {
2919
2919
  }
2920
2920
  async signRequest(e, t, r) {
2921
2921
  await this.ensureSession();
2922
- const { sessionId: s, macKey: i } = this.session, o = e.toUpperCase() === "GET" ? "" : { data: Array.isArray(r) ? r : [r] }, { ciphertextB64: c, ivB64: a } = await this.encryptBody(o), u = Math.floor(Date.now() / 1e3).toString(), f = `${e.toUpperCase()} ${t}
2922
+ const { sessionId: s, macKey: i } = this.session, o = e.toUpperCase() === "GET" ? "" : { data: Array.isArray(r) ? r : [r] }, { ciphertextB64: c, ivB64: a } = await this.encryptBody(o), u = Math.floor(Date.now() / 1e3).toString();
2923
+ let f = t;
2924
+ f.includes("?") && (f = f.split("?")[0]);
2925
+ const h = `${e.toUpperCase()} ${f}
2923
2926
  ${u}
2924
- ${c}`, h = await Hs(i, new TextEncoder().encode(f)), l = ne(h), g = new Headers({
2927
+ ${c}`, l = await Hs(i, new TextEncoder().encode(h)), g = ne(l), w = new Headers({
2925
2928
  "X-Session-Id": s,
2926
2929
  "X-Client-Id": this.clientId,
2927
2930
  "X-Timestamp": u,
2928
- "X-Signature": l,
2931
+ "X-Signature": g,
2929
2932
  "Content-Type": "application/json"
2930
2933
  });
2931
- return this.getUserId() && g.append("X-User-Id", this.getUserId()), this.getAccessToken() && !this.isTokenExpired() && g.append("Authorization", `Bearer ${this.getAccessToken()}`), {
2932
- headers: g,
2934
+ return this.getUserId() && w.append("X-User-Id", this.getUserId()), this.getAccessToken() && !this.isTokenExpired() && w.append("Authorization", `Bearer ${this.getAccessToken()}`), {
2935
+ headers: w,
2933
2936
  payload: {
2934
2937
  content: c,
2935
2938
  iv: a