@limrun/ui 0.14.0-rc.3 → 0.14.0-rc.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.
Files changed (67) hide show
  1. package/dist/app-store-relay/index.cjs +3 -3
  2. package/dist/app-store-relay/index.js +5 -5
  3. package/dist/app-store-relay/react.cjs +1 -1
  4. package/dist/app-store-relay/react.js +32 -33
  5. package/dist/apple-credentials/index.cjs +1 -0
  6. package/dist/apple-credentials/index.d.ts +59 -0
  7. package/dist/apple-credentials/index.js +227 -0
  8. package/dist/browser-storage-BnO-Ma-e.mjs +219 -0
  9. package/dist/browser-storage-DLxIqZk5.js +1 -0
  10. package/dist/client-D1drDXxE.js +1 -0
  11. package/dist/{client-C8ZDEjtD.mjs → client-DSuNtWDv.mjs} +1 -1
  12. package/dist/components/remote-control.d.ts +156 -0
  13. package/dist/core/device-install/storage/browser-storage.d.ts +8 -0
  14. package/dist/core/device-install/storage/index.d.ts +1 -0
  15. package/dist/core/device-install/storage/secret-store.d.ts +101 -0
  16. package/dist/core/device-install/types.d.ts +6 -0
  17. package/dist/core/errors.d.ts +1 -0
  18. package/dist/core/play-publish/google.d.ts +1 -1
  19. package/dist/device-build/index.cjs +1 -1
  20. package/dist/device-build/index.js +21 -20
  21. package/dist/device-build/react.cjs +1 -1
  22. package/dist/device-build/react.js +42 -43
  23. package/dist/device-install/index.cjs +1 -1
  24. package/dist/device-install/index.js +159 -161
  25. package/dist/device-install/react.cjs +1 -1
  26. package/dist/device-install/react.js +47 -49
  27. package/dist/errors-BSkqS7U-.js +1 -0
  28. package/dist/errors-gy8yQJos.mjs +6 -0
  29. package/dist/gsa-srp-Bme3JLEi.mjs +266 -0
  30. package/dist/gsa-srp-CCIfUz7Y.js +1 -0
  31. package/dist/index-ChhtuQ7e.js +22 -0
  32. package/dist/index-YDu8K9a4.mjs +11279 -0
  33. package/dist/index.cjs +1 -1
  34. package/dist/index.css +1 -1
  35. package/dist/index.js +1405 -1125
  36. package/dist/play-publish/index.cjs +1 -1
  37. package/dist/play-publish/index.js +27 -24
  38. package/dist/play-publish/react.cjs +1 -1
  39. package/dist/play-publish/react.d.ts +12 -2
  40. package/dist/play-publish/react.js +70 -60
  41. package/dist/{provisioning-BmsEnF6X.mjs → provisioning-B_DefBEp.mjs} +1 -1
  42. package/dist/{provisioning-Va0PH4Kk.js → provisioning-BlQMccX_.js} +1 -1
  43. package/package.json +6 -1
  44. package/src/app-store-relay/react.ts +1 -4
  45. package/src/apple-credentials/index.test.ts +158 -0
  46. package/src/apple-credentials/index.ts +241 -0
  47. package/src/components/remote-control.css +32 -0
  48. package/src/components/remote-control.tsx +865 -5
  49. package/src/core/device-install/operations/operations.ts +1 -4
  50. package/src/core/device-install/storage/browser-storage.test.ts +65 -0
  51. package/src/core/device-install/storage/browser-storage.ts +33 -0
  52. package/src/core/device-install/storage/index.ts +1 -0
  53. package/src/core/device-install/storage/secret-store.ts +298 -0
  54. package/src/core/device-install/types.ts +6 -0
  55. package/src/core/errors.ts +3 -0
  56. package/src/core/play-publish/google.ts +11 -2
  57. package/src/device-build/react.ts +1 -4
  58. package/src/device-install/demo/demo.tsx +1 -4
  59. package/src/device-install/react.ts +1 -4
  60. package/src/play-publish/README.md +5 -4
  61. package/src/play-publish/react.ts +72 -32
  62. package/vite.config.ts +1 -0
  63. package/dist/browser-storage-Cx9eW-bm.mjs +0 -205
  64. package/dist/browser-storage-jJaIht4K.js +0 -1
  65. package/dist/client-BtC4n_qf.js +0 -1
  66. package/dist/index-CMeQfhYy.js +0 -22
  67. package/dist/index-DFdCvi2_.mjs +0 -11543
@@ -1,95 +1,96 @@
1
- import { useState as u, useRef as g, useCallback as l, useEffect as S } from "react";
1
+ import { useState as u, useRef as R, useCallback as l, useEffect as b } from "react";
2
2
  import { closeDeviceRelayTarget as d, requestUSBAccess as C, pairDevice as I, startDeviceInstall as T } from "./index.js";
3
- import { j, k as x } from "../browser-storage-Cx9eW-bm.mjs";
4
- function H({
5
- apiUrl: c,
3
+ import { e as g } from "../errors-gy8yQJos.mjs";
4
+ import { j, k as x } from "../browser-storage-BnO-Ma-e.mjs";
5
+ function J({
6
+ apiUrl: o,
6
7
  token: v,
7
8
  organizationId: f,
8
9
  log: m = L
9
10
  }) {
10
- const [e, D] = u(), [n, h] = u(), [p, s] = u(), [b, i] = u(), [A, w] = u(!1), y = g(void 0), P = g(void 0), r = g(m);
11
+ const [e, D] = u(), [s, p] = u(), [h, n] = u(), [S, i] = u(), [A, w] = u(!1), y = R(void 0), P = R(void 0), r = R(m);
11
12
  r.current = m;
12
- const a = l(async () => {
13
+ const c = l(async () => {
13
14
  y.current?.close(), y.current = void 0, await d(P.current, r.current);
14
15
  }, []);
15
- S(() => {
16
+ b(() => {
16
17
  P.current = e;
17
- }, [e]), S(() => () => {
18
- a();
19
- }, [a]);
18
+ }, [e]), b(() => () => {
19
+ c();
20
+ }, [c]);
20
21
  const B = l(async () => {
21
- s("usb"), i(void 0), w(!1);
22
+ n("usb"), i(void 0), w(!1);
22
23
  let t;
23
24
  try {
24
- await a(), t = await C({ log: r.current });
25
- const o = await j(t.hello.serialNumber);
26
- return D(t), h(o), r.current(
27
- o ? "Pair record found" : "No pair record found",
25
+ await c(), t = await C({ log: r.current });
26
+ const a = await j(t.hello.serialNumber);
27
+ return D(t), p(a), r.current(
28
+ a ? "Pair record found" : "No pair record found",
28
29
  t.hello.serialNumber
29
30
  ), t;
30
- } catch (o) {
31
- await d(t, r.current), D(void 0), h(void 0), i(R(o));
31
+ } catch (a) {
32
+ await d(t, r.current), D(void 0), p(void 0), i(g(a));
32
33
  return;
33
34
  } finally {
34
- s(void 0);
35
+ n(void 0);
35
36
  }
36
- }, [a]), E = l(async () => {
37
- if (!c || !e)
37
+ }, [c]), E = l(async () => {
38
+ if (!o || !e)
38
39
  throw new Error("Select a USB device before pairing.");
39
- s("pair"), i(void 0), w(!1);
40
+ n("pair"), i(void 0), w(!1);
40
41
  try {
41
- await a();
42
+ await c();
42
43
  const t = await I({
43
- registryApiUrl: c,
44
+ registryApiUrl: o,
44
45
  token: v,
45
46
  organizationId: f,
46
47
  log: r.current,
47
48
  target: e
48
- }), o = await x(t.pairRecord, {
49
+ }), a = await x(t.pairRecord, {
49
50
  productName: e.hello.productName
50
51
  });
51
- return t.relay.close(), await d(e, r.current), h(o), w(!1), r.current("Device paired", "The pair record was stored locally in this browser."), o;
52
+ return t.relay.close(), await d(e, r.current), p(a), w(!1), r.current("Device paired", "The pair record was stored locally in this browser."), a;
52
53
  } catch (t) {
53
- await d(e, r.current), w(!0), i(R(t));
54
+ await d(e, r.current), w(!0), i(g(t));
54
55
  return;
55
56
  } finally {
56
- s(void 0);
57
+ n(void 0);
57
58
  }
58
- }, [c, a, e, f, v]), N = l(
59
+ }, [o, c, e, f, v]), N = l(
59
60
  async (t) => {
60
- if (!c || !e || !n)
61
+ if (!o || !e || !s)
61
62
  throw new Error("Select and pair a USB device before starting installation.");
62
- s("install"), i(void 0);
63
+ n("install"), i(void 0);
63
64
  try {
64
- return await a(), y.current = await T({
65
- registryApiUrl: c,
65
+ return await c(), y.current = await T({
66
+ registryApiUrl: o,
66
67
  token: v,
67
68
  organizationId: f,
68
69
  log: r.current,
69
70
  target: e,
70
- pairRecord: n,
71
+ pairRecord: s,
71
72
  installSource: t
72
73
  }), r.current("Device install started", "Installation will continue through the connected iPhone."), y.current;
73
- } catch (o) {
74
- await d(e, r.current), i(R(o));
74
+ } catch (a) {
75
+ await d(e, r.current), i(g(a));
75
76
  return;
76
77
  } finally {
77
- s(void 0);
78
+ n(void 0);
78
79
  }
79
80
  },
80
- [c, a, e, f, n, v]
81
+ [o, c, e, f, s, v]
81
82
  ), q = l(() => {
82
- a(), r.current("Device relay stopped");
83
- }, [a]);
83
+ c(), r.current("Device relay stopped");
84
+ }, [c]);
84
85
  return {
85
86
  device: e,
86
- pairRecord: n,
87
- busyAction: p,
88
- error: b,
87
+ pairRecord: s,
88
+ busyAction: h,
89
+ error: S,
89
90
  pairConfirmationRequired: A,
90
- hasPairRecord: !!n,
91
- canPair: !!c && !p && !!e,
92
- canInstall: !!c && !p && !!e && !!n,
91
+ hasPairRecord: !!s,
92
+ canPair: !!o && !h && !!e,
93
+ canInstall: !!o && !h && !!e && !!s,
93
94
  requestUSBAccess: B,
94
95
  pairBrowser: E,
95
96
  startInstallation: N,
@@ -99,9 +100,6 @@ function H({
99
100
  }
100
101
  function L() {
101
102
  }
102
- function R(c) {
103
- return c instanceof Error ? c.message : String(c);
104
- }
105
103
  export {
106
- H as useDeviceInstallRelay
104
+ J as useDeviceInstallRelay
107
105
  };
@@ -0,0 +1 @@
1
+ "use strict";function s(e){return e instanceof Error?e.message:String(e)}exports.errorMessage=s;
@@ -0,0 +1,6 @@
1
+ function n(e) {
2
+ return e instanceof Error ? e.message : String(e);
3
+ }
4
+ export {
5
+ n as e
6
+ };
@@ -0,0 +1,266 @@
1
+ var P = Object.defineProperty, K = (e, a) => {
2
+ for (var f in a) P(e, f, { get: a[f], enumerable: !0 });
3
+ }, y = self.crypto, A = {};
4
+ K(A, { Hash: () => H, bigintFromBytes: () => p, bitLength: () => C, byteLength: () => B, bytesFromBigint: () => n, concatBytes: () => s, constantTimeCompare: () => k, fromHex: () => N, hash: () => d, hashInterleave: () => M, modPow: () => w, randomBytes: () => S, toHex: () => l, xorBytes: () => E });
5
+ function C(e) {
6
+ return e.toString(2).length;
7
+ }
8
+ function B(e) {
9
+ return (C(e) + 7) / 8 | 0;
10
+ }
11
+ function p(e) {
12
+ let a = 0n;
13
+ for (let f of e.values()) a = (a << 8n) + BigInt(f);
14
+ return a;
15
+ }
16
+ function n(e) {
17
+ let a = new Uint8Array(B(e));
18
+ for (let f = a.length - 1; e > 0; f--, e >>= 8n) a[f] = Number(e & 0xffn);
19
+ return a;
20
+ }
21
+ function S(e) {
22
+ if (e < 1) throw new RangeError("numBytes must be >= 1");
23
+ let a = new Uint8Array(e);
24
+ return y.getRandomValues(a), a;
25
+ }
26
+ function v(e, a) {
27
+ if (a < 1n) throw new RangeError("n must be > 0");
28
+ let f = e % a;
29
+ return f < 0n ? f + a : f;
30
+ }
31
+ function L(e, a) {
32
+ if (e < 1n || a < 1n) throw new RangeError("a and b must be > 0");
33
+ let f = 0n, c = 1n, t = 1n, b = 0n;
34
+ for (; e !== 0n; ) {
35
+ let r = a / e, h = a % e, u = f - t * r, o = c - b * r;
36
+ a = e, e = h, f = t, c = b, t = u, b = o;
37
+ }
38
+ return { g: a, x: f, y: c };
39
+ }
40
+ function F(e, a) {
41
+ let f = L(v(e, a), a);
42
+ if (f.g !== 1n) throw new RangeError();
43
+ return v(f.x, a);
44
+ }
45
+ function w(e, a, f) {
46
+ if (f < 1n) throw new RangeError("n must be > 0");
47
+ if (f === 1n) return 0n;
48
+ if (e = v(e, f), a < 0n) return F(w(e, a >= 0 ? a : -a, f), f);
49
+ let c = 1n;
50
+ for (; a > 0; ) a % 2n === 1n && (c = c * e % f), a = a / 2n, e = e ** 2n % f;
51
+ return c;
52
+ }
53
+ function s(...e) {
54
+ let a = 0;
55
+ for (let t of e) a += t.byteLength;
56
+ let f = new Uint8Array(a), c = 0;
57
+ for (let t of e) f.set(t, c), c += t.byteLength;
58
+ return f;
59
+ }
60
+ function E(e, a) {
61
+ if (e.length !== a.length) throw new Error("xorBytes: buffers must be same length");
62
+ let f = e.length, c = new Uint8Array(f);
63
+ for (let t = 0; t < f; t++) c[t] = e[t] ^ a[t];
64
+ return c;
65
+ }
66
+ function l(e) {
67
+ return [...e].map((a) => a.toString(16).padStart(2, "0")).join("");
68
+ }
69
+ function N(e) {
70
+ return Uint8Array.from(e.match(/.{2}/g)?.map((a) => parseInt(a, 16)) ?? []);
71
+ }
72
+ function k(e, a) {
73
+ if (e.length !== a.length) return !1;
74
+ let f = e.length, c = 0;
75
+ for (let t = 0; t < f; t++) c |= e[t] ^ a[t];
76
+ return c === 0;
77
+ }
78
+ var H = ((e) => (e[e.SHA1 = 3] = "SHA1", e[e.SHA256 = 5] = "SHA256", e[e.SHA384 = 6] = "SHA384", e[e.SHA512 = 7] = "SHA512", e))(H || {});
79
+ function d(e, a) {
80
+ switch (e) {
81
+ case 3:
82
+ return y.subtle.digest("SHA-1", a);
83
+ case 5:
84
+ return y.subtle.digest("SHA-256", a);
85
+ case 6:
86
+ return y.subtle.digest("SHA-384", a);
87
+ case 7:
88
+ return y.subtle.digest("SHA-512", a);
89
+ }
90
+ }
91
+ async function M(e, a) {
92
+ let f = new Uint8Array(a, 0, a.byteLength);
93
+ for (var c = 0; c < f.length; c++) if (f[c] !== 0) {
94
+ (a.byteLength - c) % 2 === 1 && c++, f = new Uint8Array(a, c, a.byteLength - c);
95
+ break;
96
+ }
97
+ let t = f.length / 2, b = new Uint8Array(t), r = new Uint8Array(t);
98
+ for (let i = 0; i < f.length; i++) b[i] = f[i * 2], r[i] = f[i * 2 + 1];
99
+ let h = new Uint8Array(await d(e, b)), u = new Uint8Array(await d(e, r)), o = new Uint8Array(h.byteLength * 2);
100
+ for (let i = 0; i < h.byteLength; i++) o[i * 2] = h[i], o[i * 2 + 1] = u[i];
101
+ return o;
102
+ }
103
+ var R = ((e) => (e[e.RFC2945 = 0] = "RFC2945", e[e.SRPTools = 1] = "SRPTools", e[e.GoSRP = 2] = "GoSRP", e[e.GSA = 3] = "GSA", e))(R || {}), T = /* @__PURE__ */ new Map([[1024, { g: 2n, N: 0xeeaf0ab9adb38dd69c33f80afa8fc5e86072618775ff3c0b9ea2314c9c256576d674df7496ea81d3383b4813d692c6e0e0d5d8e250b98be48e495c1d6089dad15dc7d7b46154d6b6ce8ef4ad69b15d4982559b297bcf1885c529f566660e57ec68edbc3c05726cc02fd4cbf4976eaa9afd5138fe8376435b9fc61d2fc0eb06e3n, n: 128 }], [1536, { g: 2n, N: 0x9def3cafb939277ab1f12a8617a47bbbdba51df499ac4c80beeea9614b19cc4d5f4f5f556e27cbde51c6a94be4607a291558903ba0d0f84380b655bb9a22e8dcdf028a7cec67f0d08134b1c8b97989149b609e0be3bab63d47548381dbc5b1fc764e3f4b53dd9da1158bfd3e2b9c8cf56edf019539349627db2fd53d24b7c48665772e437d6c7f8ce442734af7ccb7ae837c264ae3a9beb87f8a2fe9b8b5292e5a021fff5e91479e8ce7a28c2442c6f315180f93499a234dcf76e3fed135f9bbn, n: 192 }], [2048, { g: 2n, N: 0xac6bdb41324a9a9bf166de5e1389582faf72b6651987ee07fc3192943db56050a37329cbb4a099ed8193e0757767a13dd52312ab4b03310dcd7f48a9da04fd50e8083969edb767b0cf6095179a163ab3661a05fbd5faaae82918a9962f0b93b855f97993ec975eeaa80d740adbf4ff747359d041d5c33ea71d281e446b14773bca97b43a23fb801676bd207a436c6481f1d2b9078717461a5b9d32e688f87748544523b524b0d57d5ea77a2775d2ecfa032cfbdbf52fb3786160279004e57ae6af874e7303ce53299ccc041c7bc308d82a5698f3a8d0c38271ae35f8e9dbfbb694b5c803d89f7ae435de236d525f54759b65e372fcd68ef20fa7111f9e4aff73n, n: 256 }], [3072, { g: 5n, N: 0xffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a93ad2caffffffffffffffffn, n: 384 }], [4096, { g: 5n, N: 0xffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c934063199ffffffffffffffffn, n: 512 }], [6144, { g: 5n, N: 0xffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dcc4024ffffffffffffffffn, n: 768 }], [8192, { g: 19n, N: 0xffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dbe115974a3926f12fee5e438777cb6a932df8cd8bec4d073b931ba3bc832b68d9dd300741fa7bf8afc47ed2576f6936ba424663aab639c5ae4f5683423b4742bf1c978238f16cbe39d652de3fdb8befc848ad922222e04a4037c0713eb57a81a23f0c73473fc646cea306b4bcbc8862f8385ddfa9d4b7fa2c087e879683303ed5bdd3a062b3cf5b3a278a66d2a13f83f44f82ddf310ee074ab6a364597e899a0255dc164f31cc50846851df9ab48195ded7ea1b1d510bd7ee74d73faf36bc31ecfa268359046f4eb879f924009438b481c6cd7889a002ed5ee382bc9190da6fc026e479558e4475677e9aa9e3050e2765694dfc81f56e880b96e7160c980dd98edd3dfffffffffffffffffn, n: 1024 }]]);
104
+ function G(e = 0) {
105
+ e === 0 && (e = 2048);
106
+ let a = T.get(e);
107
+ if (!a) throw new Error(`Invalid prime field size ${e}`);
108
+ return a;
109
+ }
110
+ function g(e, a) {
111
+ let f = n(e);
112
+ if (f.length >= a) return f;
113
+ let c = a - f.length, t = new Uint8Array(a);
114
+ for (let b = 0; b < c; b++) t[b] = 0;
115
+ return t.set(f, c), t;
116
+ }
117
+ var j = class {
118
+ constructor(e, a, f = 0) {
119
+ this.m = e, this.h = a, this.pf = G(f);
120
+ }
121
+ pf;
122
+ async hashInt(e) {
123
+ return p(new Uint8Array(await d(this.h, e)));
124
+ }
125
+ async verifier(e, a, f) {
126
+ let c = this.m === 2 ? new Uint8Array(await d(this.h, e)) : e, t = this.m === 2 ? new Uint8Array(await d(this.h, a)) : a, b = this.pf;
127
+ f || (f = S(b.n));
128
+ let r = this.m === 2 ? await this.hashInt(s(c, t, f)) : await this.hashInt(s(f, new Uint8Array(await d(this.h, s(c, new Uint8Array([58]), t))))), h = w(b.g, r, b.N);
129
+ return new z({ i: c, s: f, v: n(h), h: this.h, pf: b });
130
+ }
131
+ async newClient(e, a, f) {
132
+ let c = this.pf;
133
+ return f || (f = p(S(c.n))), new O({ s: this, i: this.m === 2 ? new Uint8Array(await d(this.h, e)) : e, p: this.m === 2 ? new Uint8Array(await d(this.h, a)) : a, a: f, A: w(c.g, f, c.N), k: await this.hashInt(s(n(c.N), g(c.g, Number(c.n)))) });
134
+ }
135
+ }, z = class {
136
+ i;
137
+ s;
138
+ v;
139
+ h;
140
+ pf;
141
+ constructor(e) {
142
+ this.i = e.i, this.s = e.s, this.v = e.v, this.h = e.h, this.pf = e.pf;
143
+ }
144
+ encode() {
145
+ let e = l(this.i), a = [this.pf.n.toString(10), this.pf.N.toString(16), this.pf.g.toString(16), this.h.toString(10), e, l(this.s), l(this.v)].join(":");
146
+ return [e, a];
147
+ }
148
+ }, O = class {
149
+ s;
150
+ i;
151
+ p;
152
+ a;
153
+ A;
154
+ k;
155
+ _K;
156
+ _M;
157
+ get K() {
158
+ return this._K;
159
+ }
160
+ get M() {
161
+ return this._M;
162
+ }
163
+ constructor(e) {
164
+ this.s = e.s, this.i = e.i, this.p = e.p, this.a = e.a, this.A = e.A, this.k = e.k, this._K = new Uint8Array(), this._M = new Uint8Array();
165
+ }
166
+ credentials() {
167
+ return [l(this.i), l(n(this.A))].join(":");
168
+ }
169
+ parseServerCredentials(e) {
170
+ let a = e.split(":");
171
+ if (!a[0] || !a[1]) throw new Error("Invalid server public key");
172
+ let f = N(a[0]), c = N(a[1]);
173
+ return [f, c];
174
+ }
175
+ async generate(e, a) {
176
+ let f = p(a), c = this.s.pf;
177
+ if (f % c.N === 0n) throw new Error("Invalid server public key");
178
+ let t = await this.s.hashInt(s(g(this.A, c.n), g(f, c.n)));
179
+ if (t === 0n) throw new Error("Invalid server public key");
180
+ let b = this.s.m === 2 ? await this.s.hashInt(s(this.i, this.p, e)) : await this.s.hashInt(s(e, new Uint8Array(await d(this.s.h, s(this.s.m == 3 ? new Uint8Array([]) : this.i, new Uint8Array([58]), this.p))))), r = w(c.g, b, c.N) * this.k, h = f - r, u = this.a + t * b, o = w(h, u, c.N);
181
+ return this._K = this.s.m === 0 ? new Uint8Array(await M(this.s.h, n(o))) : new Uint8Array(await d(this.s.h, n(o))), this.s.m === 2 ? this._M = new Uint8Array(await d(this.s.h, s(this._K, n(this.A), n(f), this.i, e, n(c.N), n(c.g)))) : this._M = new Uint8Array(await d(this.s.h, s(E(new Uint8Array(await d(this.s.h, n(c.N))), new Uint8Array(await d(this.s.h, this.s.m == 3 ? g(c.g, c.n) : n(c.g)))), new Uint8Array(await d(this.s.h, this.i)), e, n(this.A), n(f), this._K))), l(this._M);
182
+ }
183
+ async generateM2() {
184
+ if (!this.M) throw new Error("M not generated");
185
+ return new Uint8Array(await d(this.s.h, s(n(this.A), this._M, this._K)));
186
+ }
187
+ async serverOk(e) {
188
+ let a = new TextEncoder(), f = a.encode(l(new Uint8Array(await d(this.s.h, s(this._K, this.M))))), c = a.encode(e);
189
+ return k(f, c);
190
+ }
191
+ };
192
+ const I = new j(R.GSA, H.SHA256, 2048);
193
+ class V {
194
+ constructor(a) {
195
+ this.accountName = a;
196
+ }
197
+ srpClient;
198
+ async init() {
199
+ if (this.srpClient)
200
+ throw new Error("SRP client is already initialized.");
201
+ return this.srpClient = await I.newClient(x(this.accountName), new Uint8Array()), {
202
+ accountName: this.accountName,
203
+ protocols: ["s2k", "s2k_fo"],
204
+ a: m(A.bytesFromBigint(this.srpClient.A))
205
+ };
206
+ }
207
+ async complete(a, f) {
208
+ if (!this.srpClient)
209
+ throw new Error("SRP client is not initialized.");
210
+ if (f.protocol !== "s2k" && f.protocol !== "s2k_fo")
211
+ throw new Error(`Unsupported Apple SRP protocol ${f.protocol}.`);
212
+ const c = _(f.salt), t = _(f.b), b = await $(
213
+ f.protocol,
214
+ a,
215
+ c,
216
+ f.iteration
217
+ );
218
+ this.srpClient.p = b, await this.srpClient.generate(c, t);
219
+ const r = await this.srpClient.generateM2();
220
+ return {
221
+ accountName: this.accountName,
222
+ c: f.c,
223
+ m1: m(this.srpClient._M),
224
+ m2: m(r)
225
+ };
226
+ }
227
+ }
228
+ async function $(e, a, f, c) {
229
+ let t = new Uint8Array(await A.hash(I.h, U(x(a))));
230
+ e === "s2k_fo" && (t = x(A.toHex(t)));
231
+ const b = await crypto.subtle.importKey("raw", U(t), { name: "PBKDF2" }, !1, [
232
+ "deriveBits"
233
+ ]), r = await crypto.subtle.deriveBits(
234
+ {
235
+ name: "PBKDF2",
236
+ hash: { name: "SHA-256" },
237
+ iterations: c,
238
+ salt: U(f)
239
+ },
240
+ b,
241
+ 256
242
+ );
243
+ return new Uint8Array(r);
244
+ }
245
+ function x(e) {
246
+ return new TextEncoder().encode(e);
247
+ }
248
+ function m(e) {
249
+ let a = "";
250
+ for (const f of e)
251
+ a += String.fromCharCode(f);
252
+ return btoa(a);
253
+ }
254
+ function _(e) {
255
+ const a = atob(e), f = new Uint8Array(a.length);
256
+ for (let c = 0; c < a.length; c += 1)
257
+ f[c] = a.charCodeAt(c);
258
+ return f;
259
+ }
260
+ function U(e) {
261
+ const a = new Uint8Array(e.byteLength);
262
+ return a.set(e), a.buffer;
263
+ }
264
+ export {
265
+ V as A
266
+ };
@@ -0,0 +1 @@
1
+ "use strict";var P=Object.defineProperty,K=(e,a)=>{for(var f in a)P(e,f,{get:a[f],enumerable:!0})},y=self.crypto,A={};K(A,{Hash:()=>H,bigintFromBytes:()=>p,bitLength:()=>x,byteLength:()=>B,bytesFromBigint:()=>n,concatBytes:()=>s,constantTimeCompare:()=>k,fromHex:()=>N,hash:()=>d,hashInterleave:()=>M,modPow:()=>w,randomBytes:()=>S,toHex:()=>l,xorBytes:()=>E});function x(e){return e.toString(2).length}function B(e){return(x(e)+7)/8|0}function p(e){let a=0n;for(let f of e.values())a=(a<<8n)+BigInt(f);return a}function n(e){let a=new Uint8Array(B(e));for(let f=a.length-1;e>0;f--,e>>=8n)a[f]=Number(e&0xffn);return a}function S(e){if(e<1)throw new RangeError("numBytes must be >= 1");let a=new Uint8Array(e);return y.getRandomValues(a),a}function v(e,a){if(a<1n)throw new RangeError("n must be > 0");let f=e%a;return f<0n?f+a:f}function L(e,a){if(e<1n||a<1n)throw new RangeError("a and b must be > 0");let f=0n,c=1n,t=1n,b=0n;for(;e!==0n;){let r=a/e,h=a%e,u=f-t*r,o=c-b*r;a=e,e=h,f=t,c=b,t=u,b=o}return{g:a,x:f,y:c}}function F(e,a){let f=L(v(e,a),a);if(f.g!==1n)throw new RangeError;return v(f.x,a)}function w(e,a,f){if(f<1n)throw new RangeError("n must be > 0");if(f===1n)return 0n;if(e=v(e,f),a<0n)return F(w(e,a>=0?a:-a,f),f);let c=1n;for(;a>0;)a%2n===1n&&(c=c*e%f),a=a/2n,e=e**2n%f;return c}function s(...e){let a=0;for(let t of e)a+=t.byteLength;let f=new Uint8Array(a),c=0;for(let t of e)f.set(t,c),c+=t.byteLength;return f}function E(e,a){if(e.length!==a.length)throw new Error("xorBytes: buffers must be same length");let f=e.length,c=new Uint8Array(f);for(let t=0;t<f;t++)c[t]=e[t]^a[t];return c}function l(e){return[...e].map(a=>a.toString(16).padStart(2,"0")).join("")}function N(e){return Uint8Array.from(e.match(/.{2}/g)?.map(a=>parseInt(a,16))??[])}function k(e,a){if(e.length!==a.length)return!1;let f=e.length,c=0;for(let t=0;t<f;t++)c|=e[t]^a[t];return c===0}var H=(e=>(e[e.SHA1=3]="SHA1",e[e.SHA256=5]="SHA256",e[e.SHA384=6]="SHA384",e[e.SHA512=7]="SHA512",e))(H||{});function d(e,a){switch(e){case 3:return y.subtle.digest("SHA-1",a);case 5:return y.subtle.digest("SHA-256",a);case 6:return y.subtle.digest("SHA-384",a);case 7:return y.subtle.digest("SHA-512",a)}}async function M(e,a){let f=new Uint8Array(a,0,a.byteLength);for(var c=0;c<f.length;c++)if(f[c]!==0){(a.byteLength-c)%2===1&&c++,f=new Uint8Array(a,c,a.byteLength-c);break}let t=f.length/2,b=new Uint8Array(t),r=new Uint8Array(t);for(let i=0;i<f.length;i++)b[i]=f[i*2],r[i]=f[i*2+1];let h=new Uint8Array(await d(e,b)),u=new Uint8Array(await d(e,r)),o=new Uint8Array(h.byteLength*2);for(let i=0;i<h.byteLength;i++)o[i*2]=h[i],o[i*2+1]=u[i];return o}var R=(e=>(e[e.RFC2945=0]="RFC2945",e[e.SRPTools=1]="SRPTools",e[e.GoSRP=2]="GoSRP",e[e.GSA=3]="GSA",e))(R||{}),G=new Map([[1024,{g:2n,N:0xeeaf0ab9adb38dd69c33f80afa8fc5e86072618775ff3c0b9ea2314c9c256576d674df7496ea81d3383b4813d692c6e0e0d5d8e250b98be48e495c1d6089dad15dc7d7b46154d6b6ce8ef4ad69b15d4982559b297bcf1885c529f566660e57ec68edbc3c05726cc02fd4cbf4976eaa9afd5138fe8376435b9fc61d2fc0eb06e3n,n:128}],[1536,{g:2n,N:0x9def3cafb939277ab1f12a8617a47bbbdba51df499ac4c80beeea9614b19cc4d5f4f5f556e27cbde51c6a94be4607a291558903ba0d0f84380b655bb9a22e8dcdf028a7cec67f0d08134b1c8b97989149b609e0be3bab63d47548381dbc5b1fc764e3f4b53dd9da1158bfd3e2b9c8cf56edf019539349627db2fd53d24b7c48665772e437d6c7f8ce442734af7ccb7ae837c264ae3a9beb87f8a2fe9b8b5292e5a021fff5e91479e8ce7a28c2442c6f315180f93499a234dcf76e3fed135f9bbn,n:192}],[2048,{g:2n,N:0xac6bdb41324a9a9bf166de5e1389582faf72b6651987ee07fc3192943db56050a37329cbb4a099ed8193e0757767a13dd52312ab4b03310dcd7f48a9da04fd50e8083969edb767b0cf6095179a163ab3661a05fbd5faaae82918a9962f0b93b855f97993ec975eeaa80d740adbf4ff747359d041d5c33ea71d281e446b14773bca97b43a23fb801676bd207a436c6481f1d2b9078717461a5b9d32e688f87748544523b524b0d57d5ea77a2775d2ecfa032cfbdbf52fb3786160279004e57ae6af874e7303ce53299ccc041c7bc308d82a5698f3a8d0c38271ae35f8e9dbfbb694b5c803d89f7ae435de236d525f54759b65e372fcd68ef20fa7111f9e4aff73n,n:256}],[3072,{g:5n,N:0xffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a93ad2caffffffffffffffffn,n:384}],[4096,{g:5n,N:0xffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c934063199ffffffffffffffffn,n:512}],[6144,{g:5n,N:0xffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dcc4024ffffffffffffffffn,n:768}],[8192,{g:19n,N:0xffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dbe115974a3926f12fee5e438777cb6a932df8cd8bec4d073b931ba3bc832b68d9dd300741fa7bf8afc47ed2576f6936ba424663aab639c5ae4f5683423b4742bf1c978238f16cbe39d652de3fdb8befc848ad922222e04a4037c0713eb57a81a23f0c73473fc646cea306b4bcbc8862f8385ddfa9d4b7fa2c087e879683303ed5bdd3a062b3cf5b3a278a66d2a13f83f44f82ddf310ee074ab6a364597e899a0255dc164f31cc50846851df9ab48195ded7ea1b1d510bd7ee74d73faf36bc31ecfa268359046f4eb879f924009438b481c6cd7889a002ed5ee382bc9190da6fc026e479558e4475677e9aa9e3050e2765694dfc81f56e880b96e7160c980dd98edd3dfffffffffffffffffn,n:1024}]]);function T(e=0){e===0&&(e=2048);let a=G.get(e);if(!a)throw new Error(`Invalid prime field size ${e}`);return a}function g(e,a){let f=n(e);if(f.length>=a)return f;let c=a-f.length,t=new Uint8Array(a);for(let b=0;b<c;b++)t[b]=0;return t.set(f,c),t}var j=class{constructor(e,a,f=0){this.m=e,this.h=a,this.pf=T(f)}pf;async hashInt(e){return p(new Uint8Array(await d(this.h,e)))}async verifier(e,a,f){let c=this.m===2?new Uint8Array(await d(this.h,e)):e,t=this.m===2?new Uint8Array(await d(this.h,a)):a,b=this.pf;f||(f=S(b.n));let r=this.m===2?await this.hashInt(s(c,t,f)):await this.hashInt(s(f,new Uint8Array(await d(this.h,s(c,new Uint8Array([58]),t))))),h=w(b.g,r,b.N);return new z({i:c,s:f,v:n(h),h:this.h,pf:b})}async newClient(e,a,f){let c=this.pf;return f||(f=p(S(c.n))),new O({s:this,i:this.m===2?new Uint8Array(await d(this.h,e)):e,p:this.m===2?new Uint8Array(await d(this.h,a)):a,a:f,A:w(c.g,f,c.N),k:await this.hashInt(s(n(c.N),g(c.g,Number(c.n))))})}},z=class{i;s;v;h;pf;constructor(e){this.i=e.i,this.s=e.s,this.v=e.v,this.h=e.h,this.pf=e.pf}encode(){let e=l(this.i),a=[this.pf.n.toString(10),this.pf.N.toString(16),this.pf.g.toString(16),this.h.toString(10),e,l(this.s),l(this.v)].join(":");return[e,a]}},O=class{s;i;p;a;A;k;_K;_M;get K(){return this._K}get M(){return this._M}constructor(e){this.s=e.s,this.i=e.i,this.p=e.p,this.a=e.a,this.A=e.A,this.k=e.k,this._K=new Uint8Array,this._M=new Uint8Array}credentials(){return[l(this.i),l(n(this.A))].join(":")}parseServerCredentials(e){let a=e.split(":");if(!a[0]||!a[1])throw new Error("Invalid server public key");let f=N(a[0]),c=N(a[1]);return[f,c]}async generate(e,a){let f=p(a),c=this.s.pf;if(f%c.N===0n)throw new Error("Invalid server public key");let t=await this.s.hashInt(s(g(this.A,c.n),g(f,c.n)));if(t===0n)throw new Error("Invalid server public key");let b=this.s.m===2?await this.s.hashInt(s(this.i,this.p,e)):await this.s.hashInt(s(e,new Uint8Array(await d(this.s.h,s(this.s.m==3?new Uint8Array([]):this.i,new Uint8Array([58]),this.p))))),r=w(c.g,b,c.N)*this.k,h=f-r,u=this.a+t*b,o=w(h,u,c.N);return this._K=this.s.m===0?new Uint8Array(await M(this.s.h,n(o))):new Uint8Array(await d(this.s.h,n(o))),this.s.m===2?this._M=new Uint8Array(await d(this.s.h,s(this._K,n(this.A),n(f),this.i,e,n(c.N),n(c.g)))):this._M=new Uint8Array(await d(this.s.h,s(E(new Uint8Array(await d(this.s.h,n(c.N))),new Uint8Array(await d(this.s.h,this.s.m==3?g(c.g,c.n):n(c.g)))),new Uint8Array(await d(this.s.h,this.i)),e,n(this.A),n(f),this._K))),l(this._M)}async generateM2(){if(!this.M)throw new Error("M not generated");return new Uint8Array(await d(this.s.h,s(n(this.A),this._M,this._K)))}async serverOk(e){let a=new TextEncoder,f=a.encode(l(new Uint8Array(await d(this.s.h,s(this._K,this.M))))),c=a.encode(e);return k(f,c)}};const I=new j(R.GSA,H.SHA256,2048);class ${constructor(a){this.accountName=a}srpClient;async init(){if(this.srpClient)throw new Error("SRP client is already initialized.");return this.srpClient=await I.newClient(C(this.accountName),new Uint8Array),{accountName:this.accountName,protocols:["s2k","s2k_fo"],a:m(A.bytesFromBigint(this.srpClient.A))}}async complete(a,f){if(!this.srpClient)throw new Error("SRP client is not initialized.");if(f.protocol!=="s2k"&&f.protocol!=="s2k_fo")throw new Error(`Unsupported Apple SRP protocol ${f.protocol}.`);const c=_(f.salt),t=_(f.b),b=await V(f.protocol,a,c,f.iteration);this.srpClient.p=b,await this.srpClient.generate(c,t);const r=await this.srpClient.generateM2();return{accountName:this.accountName,c:f.c,m1:m(this.srpClient._M),m2:m(r)}}}async function V(e,a,f,c){let t=new Uint8Array(await A.hash(I.h,U(C(a))));e==="s2k_fo"&&(t=C(A.toHex(t)));const b=await crypto.subtle.importKey("raw",U(t),{name:"PBKDF2"},!1,["deriveBits"]),r=await crypto.subtle.deriveBits({name:"PBKDF2",hash:{name:"SHA-256"},iterations:c,salt:U(f)},b,256);return new Uint8Array(r)}function C(e){return new TextEncoder().encode(e)}function m(e){let a="";for(const f of e)a+=String.fromCharCode(f);return btoa(a)}function _(e){const a=atob(e),f=new Uint8Array(a.length);for(let c=0;c<a.length;c+=1)f[c]=a.charCodeAt(c);return f}function U(e){const a=new Uint8Array(e.byteLength);return a.set(e),a.buffer}exports.AppleGsaSrpClient=$;