@limrun/ui 0.14.0-rc.4 → 0.14.0
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/README.md +9 -26
- package/dist/components/remote-control.d.ts +36 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1189 -1089
- package/package.json +10 -51
- package/src/components/remote-control.tsx +267 -0
- package/src/index.ts +1 -1
- package/vite.config.ts +0 -9
- package/dist/app-store-relay/index.cjs +0 -9
- package/dist/app-store-relay/index.d.ts +0 -100
- package/dist/app-store-relay/index.js +0 -484
- package/dist/app-store-relay/react.cjs +0 -1
- package/dist/app-store-relay/react.d.ts +0 -15
- package/dist/app-store-relay/react.js +0 -69
- package/dist/apple-credentials/index.cjs +0 -1
- package/dist/apple-credentials/index.d.ts +0 -59
- package/dist/apple-credentials/index.js +0 -227
- package/dist/browser-storage-BnO-Ma-e.mjs +0 -219
- package/dist/browser-storage-DLxIqZk5.js +0 -1
- package/dist/client-D1drDXxE.js +0 -1
- package/dist/client-DSuNtWDv.mjs +0 -184
- package/dist/core/device-install/apple/client.d.ts +0 -18
- package/dist/core/device-install/apple/crypto.d.ts +0 -20
- package/dist/core/device-install/apple/gsa-srp.d.ts +0 -26
- package/dist/core/device-install/apple/index.d.ts +0 -5
- package/dist/core/device-install/apple/provisioning.d.ts +0 -212
- package/dist/core/device-install/apple/relay.d.ts +0 -40
- package/dist/core/device-install/index.d.ts +0 -4
- package/dist/core/device-install/operations/index.d.ts +0 -6
- package/dist/core/device-install/operations/limbuild-client.d.ts +0 -43
- package/dist/core/device-install/operations/operations.d.ts +0 -47
- package/dist/core/device-install/operations/relay-client.d.ts +0 -26
- package/dist/core/device-install/operations/relay-protocol.d.ts +0 -27
- package/dist/core/device-install/operations/usbmux.d.ts +0 -32
- package/dist/core/device-install/operations/webusb.d.ts +0 -21
- package/dist/core/device-install/storage/browser-storage.d.ts +0 -56
- package/dist/core/device-install/storage/index.d.ts +0 -2
- package/dist/core/device-install/storage/secret-store.d.ts +0 -101
- package/dist/core/device-install/types.d.ts +0 -57
- package/dist/core/errors.d.ts +0 -1
- package/dist/core/play-publish/google.d.ts +0 -13
- package/dist/core/play-publish/publish.d.ts +0 -34
- package/dist/device-build/index.cjs +0 -1
- package/dist/device-build/index.d.ts +0 -4
- package/dist/device-build/index.js +0 -85
- package/dist/device-build/react.cjs +0 -1
- package/dist/device-build/react.d.ts +0 -21
- package/dist/device-build/react.js +0 -68
- package/dist/device-build/signing.d.ts +0 -20
- package/dist/device-install/demo/demo.d.ts +0 -0
- package/dist/device-install/index.cjs +0 -1
- package/dist/device-install/index.d.ts +0 -18
- package/dist/device-install/index.js +0 -591
- package/dist/device-install/react.cjs +0 -1
- package/dist/device-install/react.d.ts +0 -24
- package/dist/device-install/react.js +0 -105
- package/dist/errors-BSkqS7U-.js +0 -1
- package/dist/errors-gy8yQJos.mjs +0 -6
- package/dist/gsa-srp-Bme3JLEi.mjs +0 -266
- package/dist/gsa-srp-CCIfUz7Y.js +0 -1
- package/dist/index-ChhtuQ7e.js +0 -22
- package/dist/index-YDu8K9a4.mjs +0 -11279
- package/dist/limbuild-client-BagK_FWE.mjs +0 -83
- package/dist/limbuild-client-CVDwq54z.js +0 -1
- package/dist/play-publish/index.cjs +0 -1
- package/dist/play-publish/index.d.ts +0 -2
- package/dist/play-publish/index.js +0 -109
- package/dist/play-publish/react.cjs +0 -1
- package/dist/play-publish/react.d.ts +0 -31
- package/dist/play-publish/react.js +0 -91
- package/dist/provisioning-B_DefBEp.mjs +0 -239
- package/dist/provisioning-BlQMccX_.js +0 -1
- package/src/app-store-relay/index.test.ts +0 -60
- package/src/app-store-relay/index.ts +0 -511
- package/src/app-store-relay/react.ts +0 -131
- package/src/apple-credentials/index.test.ts +0 -158
- package/src/apple-credentials/index.ts +0 -241
- package/src/core/device-install/apple/client.ts +0 -143
- package/src/core/device-install/apple/crypto.ts +0 -205
- package/src/core/device-install/apple/gsa-srp.ts +0 -123
- package/src/core/device-install/apple/index.ts +0 -5
- package/src/core/device-install/apple/provisioning.test.ts +0 -84
- package/src/core/device-install/apple/provisioning.ts +0 -380
- package/src/core/device-install/apple/relay.ts +0 -182
- package/src/core/device-install/index.ts +0 -4
- package/src/core/device-install/operations/index.ts +0 -6
- package/src/core/device-install/operations/limbuild-client.ts +0 -144
- package/src/core/device-install/operations/operations.ts +0 -234
- package/src/core/device-install/operations/relay-client.ts +0 -286
- package/src/core/device-install/operations/relay-protocol.ts +0 -71
- package/src/core/device-install/operations/usbmux.ts +0 -270
- package/src/core/device-install/operations/webusb-dom.d.ts +0 -54
- package/src/core/device-install/operations/webusb.ts +0 -110
- package/src/core/device-install/storage/browser-storage.test.ts +0 -65
- package/src/core/device-install/storage/browser-storage.ts +0 -325
- package/src/core/device-install/storage/index.ts +0 -2
- package/src/core/device-install/storage/secret-store.ts +0 -298
- package/src/core/device-install/types.ts +0 -69
- package/src/core/errors.ts +0 -3
- package/src/core/play-publish/google.ts +0 -113
- package/src/core/play-publish/publish.test.ts +0 -68
- package/src/core/play-publish/publish.ts +0 -89
- package/src/device-build/index.ts +0 -42
- package/src/device-build/react.ts +0 -130
- package/src/device-build/signing.ts +0 -94
- package/src/device-install/README.md +0 -423
- package/src/device-install/demo/demo.css +0 -493
- package/src/device-install/demo/demo.tsx +0 -1061
- package/src/device-install/demo/index.html +0 -12
- package/src/device-install/index.ts +0 -50
- package/src/device-install/react.ts +0 -195
- package/src/play-publish/README.md +0 -66
- package/src/play-publish/index.ts +0 -12
- package/src/play-publish/react.ts +0 -208
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { useState as u, useRef as R, useCallback as l, useEffect as b } from "react";
|
|
2
|
-
import { closeDeviceRelayTarget as d, requestUSBAccess as C, pairDevice as I, startDeviceInstall as T } from "./index.js";
|
|
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,
|
|
7
|
-
token: v,
|
|
8
|
-
organizationId: f,
|
|
9
|
-
log: m = L
|
|
10
|
-
}) {
|
|
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);
|
|
12
|
-
r.current = m;
|
|
13
|
-
const c = l(async () => {
|
|
14
|
-
y.current?.close(), y.current = void 0, await d(P.current, r.current);
|
|
15
|
-
}, []);
|
|
16
|
-
b(() => {
|
|
17
|
-
P.current = e;
|
|
18
|
-
}, [e]), b(() => () => {
|
|
19
|
-
c();
|
|
20
|
-
}, [c]);
|
|
21
|
-
const B = l(async () => {
|
|
22
|
-
n("usb"), i(void 0), w(!1);
|
|
23
|
-
let t;
|
|
24
|
-
try {
|
|
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",
|
|
29
|
-
t.hello.serialNumber
|
|
30
|
-
), t;
|
|
31
|
-
} catch (a) {
|
|
32
|
-
await d(t, r.current), D(void 0), p(void 0), i(g(a));
|
|
33
|
-
return;
|
|
34
|
-
} finally {
|
|
35
|
-
n(void 0);
|
|
36
|
-
}
|
|
37
|
-
}, [c]), E = l(async () => {
|
|
38
|
-
if (!o || !e)
|
|
39
|
-
throw new Error("Select a USB device before pairing.");
|
|
40
|
-
n("pair"), i(void 0), w(!1);
|
|
41
|
-
try {
|
|
42
|
-
await c();
|
|
43
|
-
const t = await I({
|
|
44
|
-
registryApiUrl: o,
|
|
45
|
-
token: v,
|
|
46
|
-
organizationId: f,
|
|
47
|
-
log: r.current,
|
|
48
|
-
target: e
|
|
49
|
-
}), a = await x(t.pairRecord, {
|
|
50
|
-
productName: e.hello.productName
|
|
51
|
-
});
|
|
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;
|
|
53
|
-
} catch (t) {
|
|
54
|
-
await d(e, r.current), w(!0), i(g(t));
|
|
55
|
-
return;
|
|
56
|
-
} finally {
|
|
57
|
-
n(void 0);
|
|
58
|
-
}
|
|
59
|
-
}, [o, c, e, f, v]), N = l(
|
|
60
|
-
async (t) => {
|
|
61
|
-
if (!o || !e || !s)
|
|
62
|
-
throw new Error("Select and pair a USB device before starting installation.");
|
|
63
|
-
n("install"), i(void 0);
|
|
64
|
-
try {
|
|
65
|
-
return await c(), y.current = await T({
|
|
66
|
-
registryApiUrl: o,
|
|
67
|
-
token: v,
|
|
68
|
-
organizationId: f,
|
|
69
|
-
log: r.current,
|
|
70
|
-
target: e,
|
|
71
|
-
pairRecord: s,
|
|
72
|
-
installSource: t
|
|
73
|
-
}), r.current("Device install started", "Installation will continue through the connected iPhone."), y.current;
|
|
74
|
-
} catch (a) {
|
|
75
|
-
await d(e, r.current), i(g(a));
|
|
76
|
-
return;
|
|
77
|
-
} finally {
|
|
78
|
-
n(void 0);
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
[o, c, e, f, s, v]
|
|
82
|
-
), q = l(() => {
|
|
83
|
-
c(), r.current("Device relay stopped");
|
|
84
|
-
}, [c]);
|
|
85
|
-
return {
|
|
86
|
-
device: e,
|
|
87
|
-
pairRecord: s,
|
|
88
|
-
busyAction: h,
|
|
89
|
-
error: S,
|
|
90
|
-
pairConfirmationRequired: A,
|
|
91
|
-
hasPairRecord: !!s,
|
|
92
|
-
canPair: !!o && !h && !!e,
|
|
93
|
-
canInstall: !!o && !h && !!e && !!s,
|
|
94
|
-
requestUSBAccess: B,
|
|
95
|
-
pairBrowser: E,
|
|
96
|
-
startInstallation: N,
|
|
97
|
-
stopRelay: q,
|
|
98
|
-
clearError: () => i(void 0)
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
function L() {
|
|
102
|
-
}
|
|
103
|
-
export {
|
|
104
|
-
J as useDeviceInstallRelay
|
|
105
|
-
};
|
package/dist/errors-BSkqS7U-.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";function s(e){return e instanceof Error?e.message:String(e)}exports.errorMessage=s;
|
package/dist/errors-gy8yQJos.mjs
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/gsa-srp-CCIfUz7Y.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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=$;
|