hd-wallet-ui 2.0.21 → 2.0.27
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/LICENSE +190 -0
- package/README.md +101 -123
- package/data/common-passwords-sdn-v1.source.json +12 -0
- package/data/common-passwords-sdn-v1.txt +10000 -0
- package/dist/browser/sdn-wallet-callback.js +1 -0
- package/dist/browser/sdn-wallet-public-client.js +1 -0
- package/dist/browser/wallet-callback.html +6 -0
- package/dist/client/asset-review.d.ts +8 -0
- package/dist/client/asset-review.js +1570 -0
- package/dist/client/callback.d.ts +13 -0
- package/dist/client/callback.js +29 -0
- package/dist/client/index.d.ts +11 -0
- package/dist/client/index.js +1379 -0
- package/dist/client/sdn.d.ts +8 -0
- package/dist/client/sdn.js +1542 -0
- package/dist/client/style.css +32 -0
- package/dist/client/types.d.ts +278 -0
- package/dist/compat/index.d.ts +26 -0
- package/dist/compat/index.js +62 -0
- package/dist/wallet-origin/index.d.ts +21 -0
- package/dist/wallet-origin/index.js +4607 -0
- package/dist/wallet-origin-host/assets/wallet-origin.43cf84e0eba17742309357ec6bc2c544736e155ffd5d76d5024408e998500a57.wasm +0 -0
- package/dist/wallet-origin-host/assets/wallet-origin.4c9455f1a2618948e203f720485add9d8ebf77b5542b41f933594afcfbb34361.css +1 -0
- package/dist/wallet-origin-host/assets/wallet-origin.aedc355452e665e16c0f72a6597602873378dbc39d4cbf6104621c07579347e0.js +12463 -0
- package/dist/wallet-origin-host/index.html +10 -0
- package/dist/wallet-origin-host/integrity.json +1 -0
- package/package.json +46 -18
- package/src/address-derivation.js +0 -514
- package/src/app.js +0 -6008
- package/src/blockchain-trust.js +0 -752
- package/src/clipboard.js +0 -44
- package/src/constants.js +0 -66
- package/src/hash.js +0 -9
- package/src/lib.js +0 -66
- package/src/template.js +0 -626
- package/src/trust-ui.js +0 -745
- package/src/wallet-storage.js +0 -773
- package/styles/main.css +0 -6220
- package/styles/widget.css +0 -6212
|
@@ -0,0 +1,1542 @@
|
|
|
1
|
+
const we = Object.freeze({
|
|
2
|
+
cm: 0.01,
|
|
3
|
+
km: 1e3,
|
|
4
|
+
m: 1,
|
|
5
|
+
mm: 1e-3
|
|
6
|
+
}), ve = Object.freeze({
|
|
7
|
+
metersPerSourceUnit: we,
|
|
8
|
+
quaternionNormTolerance: 1e-6,
|
|
9
|
+
scaleComponentExclusiveMin: 0,
|
|
10
|
+
scaleComponentInclusiveMax: 1e6,
|
|
11
|
+
translationComponentAbsMax: 1e6,
|
|
12
|
+
upAxes: Object.freeze(["X_UP", "Y_UP", "Z_UP"])
|
|
13
|
+
}), Le = Object.freeze({ reviewedTransform: ve, schemaVersion: 1 }), B = new TextEncoder(), le = Object.getPrototypeOf(Uint8Array.prototype), _e = Object.getOwnPropertyDescriptor(le, "buffer").get, Ie = Object.getOwnPropertyDescriptor(le, "length").get, Te = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get, G = typeof SharedArrayBuffer > "u" ? null : Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, "byteLength").get, v = "sdn-bip32-slip10-purpose-v1", U = "password-scrypt-v2", N = "ed25519-over-sha256-jcs-v1", ee = "ed25519-raw-32-v1", W = "sdn-login:sdn.spaceaware.io", xe = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/u, P = /^[0-9a-f]{64}$/u, ue = /^[0-9a-f]{128}$/u, F = /^sha256:[0-9a-f]{64}$/u, Ce = /^[1-9A-HJ-NP-Za-km-z]+$/u, he = 131072, Ne = [
|
|
14
|
+
"accountFingerprint",
|
|
15
|
+
"accountIndex",
|
|
16
|
+
"accountLabel",
|
|
17
|
+
"accountPeerId",
|
|
18
|
+
"accountXpub",
|
|
19
|
+
"identityScheme",
|
|
20
|
+
"keys",
|
|
21
|
+
"schemaVersion",
|
|
22
|
+
"seedProfile"
|
|
23
|
+
], Pe = [
|
|
24
|
+
"bip32Fingerprint",
|
|
25
|
+
"curve",
|
|
26
|
+
"derivation",
|
|
27
|
+
"encoding",
|
|
28
|
+
"identityScheme",
|
|
29
|
+
"keyId",
|
|
30
|
+
"path",
|
|
31
|
+
"publicKeyHex",
|
|
32
|
+
"purpose",
|
|
33
|
+
"seedProfile",
|
|
34
|
+
"signatureProfile"
|
|
35
|
+
], De = [
|
|
36
|
+
"connectionExpiresAt",
|
|
37
|
+
"event",
|
|
38
|
+
"identity",
|
|
39
|
+
"schemaVersion"
|
|
40
|
+
], je = [
|
|
41
|
+
"algorithm",
|
|
42
|
+
"encoding",
|
|
43
|
+
"identityScheme",
|
|
44
|
+
"keyId",
|
|
45
|
+
"schemaVersion",
|
|
46
|
+
"signatureHex",
|
|
47
|
+
"signatureProfile"
|
|
48
|
+
], ke = [
|
|
49
|
+
"algorithm",
|
|
50
|
+
"canonicalEnvelope",
|
|
51
|
+
"encoding",
|
|
52
|
+
"identityScheme",
|
|
53
|
+
"keyId",
|
|
54
|
+
"schemaVersion",
|
|
55
|
+
"signatureHex",
|
|
56
|
+
"signatureProfile",
|
|
57
|
+
"signedDigestSha256"
|
|
58
|
+
];
|
|
59
|
+
function a(r) {
|
|
60
|
+
throw new TypeError(r);
|
|
61
|
+
}
|
|
62
|
+
function z(r) {
|
|
63
|
+
if (r === null || typeof r != "object" || Array.isArray(r)) return !1;
|
|
64
|
+
const e = Object.getPrototypeOf(r);
|
|
65
|
+
return e === Object.prototype || e === null;
|
|
66
|
+
}
|
|
67
|
+
function w(r, e) {
|
|
68
|
+
typeof r != "string" && a(`${e} must be a string`);
|
|
69
|
+
for (let t = 0; t < r.length; t += 1) {
|
|
70
|
+
const n = r.charCodeAt(t);
|
|
71
|
+
let i = n;
|
|
72
|
+
if (n >= 55296 && n <= 56319) {
|
|
73
|
+
const o = r.charCodeAt(t + 1);
|
|
74
|
+
o >= 56320 && o <= 57343 || a(`${e} contains an unpaired surrogate`), i = 65536 + (n - 55296 << 10) + (o - 56320), t += 1;
|
|
75
|
+
} else n >= 56320 && n <= 57343 && a(`${e} contains an unpaired surrogate`);
|
|
76
|
+
((i & 65535) === 65534 || (i & 65535) === 65535 || i >= 64976 && i <= 65007) && a(`${e} contains a Unicode noncharacter`);
|
|
77
|
+
}
|
|
78
|
+
return r;
|
|
79
|
+
}
|
|
80
|
+
function fe(r) {
|
|
81
|
+
typeof r != "string" && a("wire JSON must be a string"), B.encode(r).byteLength > he && a("wire JSON is too large"), r.charCodeAt(0) === 65279 && a("wire JSON must not contain a BOM");
|
|
82
|
+
let e = 0, t = 0;
|
|
83
|
+
const n = () => {
|
|
84
|
+
for (; e < r.length && /[\u0009\u000a\u000d\u0020]/u.test(r[e]); ) e += 1;
|
|
85
|
+
}, i = () => {
|
|
86
|
+
r[e] !== '"' && a("invalid JSON string");
|
|
87
|
+
const u = e;
|
|
88
|
+
for (e += 1; e < r.length; ) {
|
|
89
|
+
const l = r.charCodeAt(e);
|
|
90
|
+
if (l === 34) {
|
|
91
|
+
e += 1;
|
|
92
|
+
let f;
|
|
93
|
+
try {
|
|
94
|
+
f = JSON.parse(r.slice(u, e));
|
|
95
|
+
} catch {
|
|
96
|
+
a("invalid JSON string");
|
|
97
|
+
}
|
|
98
|
+
return w(f, "JSON string");
|
|
99
|
+
}
|
|
100
|
+
l < 32 && a("invalid JSON control character"), l === 92 && (e += 1, e >= r.length && a("unterminated JSON escape")), e += 1;
|
|
101
|
+
}
|
|
102
|
+
a("unterminated JSON string");
|
|
103
|
+
}, o = (u = 0) => {
|
|
104
|
+
u > 32 && a("wire JSON nesting is too deep"), t += 1, t > 4096 && a("wire JSON contains too many values"), n();
|
|
105
|
+
const l = r[e];
|
|
106
|
+
if (l === '"') return i();
|
|
107
|
+
if (l === "{") {
|
|
108
|
+
e += 1;
|
|
109
|
+
const d = /* @__PURE__ */ Object.create(null), p = /* @__PURE__ */ new Set();
|
|
110
|
+
if (n(), r[e] === "}")
|
|
111
|
+
return e += 1, d;
|
|
112
|
+
for (; e < r.length; ) {
|
|
113
|
+
n();
|
|
114
|
+
const m = i();
|
|
115
|
+
if (p.has(m) && a(`duplicate JSON field: ${m}`), p.add(m), n(), r[e] !== ":" && a("missing JSON object colon"), e += 1, d[m] = o(u + 1), n(), r[e] === "}")
|
|
116
|
+
return e += 1, d;
|
|
117
|
+
r[e] !== "," && a("invalid JSON object separator"), e += 1;
|
|
118
|
+
}
|
|
119
|
+
a("unterminated JSON object");
|
|
120
|
+
}
|
|
121
|
+
if (l === "[") {
|
|
122
|
+
e += 1;
|
|
123
|
+
const d = [];
|
|
124
|
+
if (n(), r[e] === "]")
|
|
125
|
+
return e += 1, d;
|
|
126
|
+
for (; e < r.length; ) {
|
|
127
|
+
if (d.push(o(u + 1)), n(), r[e] === "]")
|
|
128
|
+
return e += 1, d;
|
|
129
|
+
r[e] !== "," && a("invalid JSON array separator"), e += 1;
|
|
130
|
+
}
|
|
131
|
+
a("unterminated JSON array");
|
|
132
|
+
}
|
|
133
|
+
for (const [d, p] of [["true", !0], ["false", !1], ["null", null]])
|
|
134
|
+
if (r.startsWith(d, e))
|
|
135
|
+
return e += d.length, p;
|
|
136
|
+
const f = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/u.exec(r.slice(e));
|
|
137
|
+
f || a("invalid JSON value"), e += f[0].length;
|
|
138
|
+
const h = Number(f[0]);
|
|
139
|
+
return Number.isFinite(h) || a("wire JSON number must be finite"), h;
|
|
140
|
+
};
|
|
141
|
+
n();
|
|
142
|
+
const s = o();
|
|
143
|
+
return n(), e !== r.length && a("wire JSON contains trailing bytes"), s;
|
|
144
|
+
}
|
|
145
|
+
function Ve(r) {
|
|
146
|
+
return typeof r == "string" ? fe(r) : r;
|
|
147
|
+
}
|
|
148
|
+
function $e(r, e) {
|
|
149
|
+
if (r.byteLength !== e.byteLength) return !1;
|
|
150
|
+
let t = 0;
|
|
151
|
+
for (let n = 0; n < r.byteLength; n += 1) t |= r[n] ^ e[n];
|
|
152
|
+
return t === 0;
|
|
153
|
+
}
|
|
154
|
+
function R(r, e, t) {
|
|
155
|
+
const n = Ve(r);
|
|
156
|
+
z(n) || a(`${t} must be a JSON object`), Object.getOwnPropertySymbols(n).length !== 0 && a(`${t} has an unknown symbol field`);
|
|
157
|
+
const i = Object.getOwnPropertyNames(n).sort(), o = [...e].sort(), s = B.encode(i.join("\0")), u = B.encode(o.join("\0"));
|
|
158
|
+
$e(s, u) || a(`${t} has missing or unknown fields`);
|
|
159
|
+
for (const l of i) {
|
|
160
|
+
const f = Object.getOwnPropertyDescriptor(n, l);
|
|
161
|
+
(!f || !f.enumerable || !("value" in f)) && a(`${t}.${l} must be an enumerable data field`), f.value === void 0 && a(`${t}.${l} must not be undefined`);
|
|
162
|
+
}
|
|
163
|
+
return n;
|
|
164
|
+
}
|
|
165
|
+
function J(r) {
|
|
166
|
+
if (!r || typeof r != "object" || Object.isFrozen(r)) return r;
|
|
167
|
+
for (const e of Object.values(r)) J(e);
|
|
168
|
+
return Object.freeze(r);
|
|
169
|
+
}
|
|
170
|
+
function g(r) {
|
|
171
|
+
return J(Object.fromEntries([...r].sort(([e], [t]) => e < t ? -1 : e > t ? 1 : 0)));
|
|
172
|
+
}
|
|
173
|
+
function de(r, e, t) {
|
|
174
|
+
(!Array.isArray(r) || Object.getPrototypeOf(r) !== Array.prototype || r.length !== e) && a(`${t} must be a plain array with exactly ${e} values`);
|
|
175
|
+
const n = [...Array.from({ length: e }, (o, s) => String(s)), "length"], i = Reflect.ownKeys(r);
|
|
176
|
+
(i.length !== n.length || i.some((o, s) => o !== n[s])) && a(`${t} must be a dense plain array`);
|
|
177
|
+
for (let o = 0; o < e; o += 1) {
|
|
178
|
+
const s = Object.getOwnPropertyDescriptor(r, String(o));
|
|
179
|
+
(!s || !s.enumerable || !("value" in s) || s.value === void 0) && a(`${t} must contain enumerable data values`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function Me(r) {
|
|
183
|
+
const e = R(
|
|
184
|
+
r,
|
|
185
|
+
["reviewedTransform", "schemaVersion"],
|
|
186
|
+
"asset review protocol policy"
|
|
187
|
+
);
|
|
188
|
+
y(e.schemaVersion, 1, "asset review protocol schemaVersion");
|
|
189
|
+
const t = R(e.reviewedTransform, [
|
|
190
|
+
"metersPerSourceUnit",
|
|
191
|
+
"quaternionNormTolerance",
|
|
192
|
+
"scaleComponentExclusiveMin",
|
|
193
|
+
"scaleComponentInclusiveMax",
|
|
194
|
+
"translationComponentAbsMax",
|
|
195
|
+
"upAxes"
|
|
196
|
+
], "asset review transform policy"), n = R(
|
|
197
|
+
t.metersPerSourceUnit,
|
|
198
|
+
["cm", "km", "m", "mm"],
|
|
199
|
+
"asset review unit policy"
|
|
200
|
+
);
|
|
201
|
+
for (const [i, o] of Object.entries(n))
|
|
202
|
+
(typeof o != "number" || !Number.isFinite(o) || o <= 0) && a(`asset review unit policy ${i} must be positive and finite`);
|
|
203
|
+
for (const [i, o] of [
|
|
204
|
+
["quaternionNormTolerance", t.quaternionNormTolerance],
|
|
205
|
+
["scaleComponentExclusiveMin", t.scaleComponentExclusiveMin],
|
|
206
|
+
["scaleComponentInclusiveMax", t.scaleComponentInclusiveMax],
|
|
207
|
+
["translationComponentAbsMax", t.translationComponentAbsMax]
|
|
208
|
+
])
|
|
209
|
+
(typeof o != "number" || !Number.isFinite(o)) && a(`asset review transform policy ${i} must be finite`);
|
|
210
|
+
return (t.quaternionNormTolerance <= 0 || t.scaleComponentInclusiveMax <= t.scaleComponentExclusiveMin || t.translationComponentAbsMax <= 0) && a("asset review transform policy bounds are inconsistent"), de(t.upAxes, 3, "asset review up-axis policy"), t.upAxes.join("\0") !== "X_UP\0Y_UP\0Z_UP" && a("asset review up-axis policy is invalid"), g([
|
|
211
|
+
["metersPerSourceUnit", g(Object.entries(n))],
|
|
212
|
+
["quaternionNormTolerance", t.quaternionNormTolerance],
|
|
213
|
+
["scaleComponentExclusiveMin", t.scaleComponentExclusiveMin],
|
|
214
|
+
["scaleComponentInclusiveMax", t.scaleComponentInclusiveMax],
|
|
215
|
+
["translationComponentAbsMax", t.translationComponentAbsMax],
|
|
216
|
+
["upAxes", Object.freeze(Array.from({ length: 3 }, (i, o) => t.upAxes[o]))]
|
|
217
|
+
]);
|
|
218
|
+
}
|
|
219
|
+
Me(Le);
|
|
220
|
+
function y(r, e, t) {
|
|
221
|
+
return r !== e && a(`${t} must equal ${JSON.stringify(e)}`), r;
|
|
222
|
+
}
|
|
223
|
+
function ye(r, e, t) {
|
|
224
|
+
return e.includes(r) || a(`${t} is not an allowed value`), r;
|
|
225
|
+
}
|
|
226
|
+
function A(r, e, t) {
|
|
227
|
+
return w(r, t), e.test(r) || a(`${t} has an invalid encoding`), r;
|
|
228
|
+
}
|
|
229
|
+
function D(r, e) {
|
|
230
|
+
return w(r, e), (!xe.test(r) || new Date(r).toISOString() !== r) && a(`${e} must be exact RFC3339 milliseconds UTC`), r;
|
|
231
|
+
}
|
|
232
|
+
function pe(r, e) {
|
|
233
|
+
const t = Date.parse(r), n = Date.parse(e);
|
|
234
|
+
n > t && n - t <= 3e5 || a("request lifetime must be in (0, 300] seconds");
|
|
235
|
+
}
|
|
236
|
+
function H(r, e) {
|
|
237
|
+
(!ArrayBuffer.isView(r) || !(r instanceof Uint8Array) || Object.getPrototypeOf(r) !== Uint8Array.prototype) && a(`${e} must be a plain Uint8Array`), Ie.call(r) !== 32 && a(`${e} must be exactly 32 bytes`);
|
|
238
|
+
const n = Array.from({ length: 32 }, (h, d) => String(d)), i = Reflect.ownKeys(r);
|
|
239
|
+
(i.length !== n.length || i.some((h, d) => h !== n[d])) && a(`${e} Uint8Array must contain only 32 indexed bytes`);
|
|
240
|
+
const o = _e.call(r);
|
|
241
|
+
let s = !1;
|
|
242
|
+
if (G)
|
|
243
|
+
try {
|
|
244
|
+
G.call(o), s = !0;
|
|
245
|
+
} catch {
|
|
246
|
+
s = !1;
|
|
247
|
+
}
|
|
248
|
+
s && a(`${e} must not use SharedArrayBuffer storage`);
|
|
249
|
+
try {
|
|
250
|
+
Te.call(o);
|
|
251
|
+
} catch {
|
|
252
|
+
a(`${e} must use ArrayBuffer storage`);
|
|
253
|
+
}
|
|
254
|
+
const u = new Uint8Array(32);
|
|
255
|
+
for (let h = 0; h < 32; h += 1) {
|
|
256
|
+
const d = Object.getOwnPropertyDescriptor(r, String(h));
|
|
257
|
+
(!d || !d.enumerable || !("value" in d) || !Number.isInteger(d.value) || d.value < 0 || d.value > 255) && a(`${e} Uint8Array contains an invalid indexed byte`), u[h] = r[h];
|
|
258
|
+
}
|
|
259
|
+
let l = "";
|
|
260
|
+
for (let h = 0; h < 32; h += 1) l += String.fromCharCode(u[h]);
|
|
261
|
+
const f = globalThis.btoa(l).replace(/\+/gu, "-").replace(/\//gu, "_").replace(/=+$/gu, "");
|
|
262
|
+
return f.length !== 43 && a(`${e} did not encode to 43 base64url characters`), f;
|
|
263
|
+
}
|
|
264
|
+
function me(r, e) {
|
|
265
|
+
w(r, e), /^[A-Za-z0-9_-]{43}$/u.test(r) || a(`${e} must be canonical unpadded base64url`);
|
|
266
|
+
let t;
|
|
267
|
+
try {
|
|
268
|
+
t = globalThis.atob(`${r.replace(/-/gu, "+").replace(/_/gu, "/")}=`);
|
|
269
|
+
} catch {
|
|
270
|
+
a(`${e} must be valid base64url`);
|
|
271
|
+
}
|
|
272
|
+
const n = Uint8Array.from(t, (i) => i.charCodeAt(0));
|
|
273
|
+
return (n.byteLength !== 32 || H(n, e) !== r) && a(`${e} must canonically encode exactly 32 bytes`), r;
|
|
274
|
+
}
|
|
275
|
+
function K(r) {
|
|
276
|
+
return r === null || typeof r == "boolean" ? JSON.stringify(r) : typeof r == "string" ? (w(r, "canonical JSON string"), JSON.stringify(r)) : typeof r == "number" ? (Number.isFinite(r) || a("canonical JSON numbers must be finite"), JSON.stringify(r)) : Array.isArray(r) ? `[${r.map(K).join(",")}]` : (z(r) || a("canonical JSON contains an unsupported value"), `{${Object.keys(r).sort().map((e) => `${JSON.stringify(e)}:${K(r[e])}`).join(",")}}`);
|
|
277
|
+
}
|
|
278
|
+
function Ye(r, e) {
|
|
279
|
+
for (const t of ["identityScheme", "keyId", "signatureProfile"])
|
|
280
|
+
r[t] !== e[t] && a(`canonicalEnvelope ${t} must match the signature result`);
|
|
281
|
+
}
|
|
282
|
+
function Be(r, e) {
|
|
283
|
+
const n = R(r, [
|
|
284
|
+
"audience",
|
|
285
|
+
"challengeSha256",
|
|
286
|
+
"clientId",
|
|
287
|
+
"expiresAt",
|
|
288
|
+
"identityScheme",
|
|
289
|
+
"issuedAt",
|
|
290
|
+
"keyId",
|
|
291
|
+
"kind",
|
|
292
|
+
"nonce",
|
|
293
|
+
"protocolVersion",
|
|
294
|
+
"requestOrigin",
|
|
295
|
+
"signatureProfile"
|
|
296
|
+
], "SDN login canonicalEnvelope");
|
|
297
|
+
Ye(n, e), y(n.audience, W, "SDN login envelope audience"), A(n.challengeSha256, P, "SDN login envelope challengeSha256"), y(n.clientId, "sdn-node-console-v1", "SDN login envelope clientId"), D(n.issuedAt, "SDN login envelope issuedAt"), D(n.expiresAt, "SDN login envelope expiresAt"), pe(n.issuedAt, n.expiresAt), y(n.identityScheme, v, "SDN login envelope identityScheme"), A(n.keyId, F, "SDN login envelope keyId"), y(n.kind, "sdn-login", "SDN login envelope kind"), A(n.nonce, P, "SDN login envelope nonce"), y(n.protocolVersion, 2, "SDN login envelope protocolVersion"), y(n.requestOrigin, "https://sdn.spaceaware.io", "SDN login envelope requestOrigin"), y(n.signatureProfile, N, "SDN login envelope signatureProfile");
|
|
298
|
+
}
|
|
299
|
+
function Ue(r, e, t) {
|
|
300
|
+
w(r, "canonicalEnvelope"), B.encode(r).byteLength > he && a("canonicalEnvelope is too large");
|
|
301
|
+
const n = fe(r);
|
|
302
|
+
return (!z(n) || n.kind !== e) && a("canonicalEnvelope kind does not match the operation"), K(n) !== r && a("canonicalEnvelope must be exact JCS"), Be(n, t), r;
|
|
303
|
+
}
|
|
304
|
+
function Fe(r, e) {
|
|
305
|
+
const t = R(r, Pe, `identity key ${e.purpose}`);
|
|
306
|
+
return y(t.purpose, e.purpose, "key purpose"), y(t.identityScheme, v, "key identityScheme"), y(t.seedProfile, U, "key seedProfile"), y(t.signatureProfile, e.signatureProfile, "key signatureProfile"), y(t.curve, e.curve, "key curve"), y(t.derivation, "slip10", "key derivation"), y(t.path, e.path, "key path"), y(t.encoding, "raw", "key encoding"), A(t.publicKeyHex, P, "key publicKeyHex"), y(t.bip32Fingerprint, null, "key bip32Fingerprint"), A(t.keyId, F, "key keyId"), g([
|
|
307
|
+
["bip32Fingerprint", null],
|
|
308
|
+
["curve", t.curve],
|
|
309
|
+
["derivation", "slip10"],
|
|
310
|
+
["encoding", "raw"],
|
|
311
|
+
["identityScheme", v],
|
|
312
|
+
["keyId", t.keyId],
|
|
313
|
+
["path", t.path],
|
|
314
|
+
["publicKeyHex", t.publicKeyHex],
|
|
315
|
+
["purpose", t.purpose],
|
|
316
|
+
["seedProfile", U],
|
|
317
|
+
["signatureProfile", t.signatureProfile]
|
|
318
|
+
]);
|
|
319
|
+
}
|
|
320
|
+
function Je(r) {
|
|
321
|
+
const e = R(r, Ne, "WalletPublicIdentity");
|
|
322
|
+
y(e.schemaVersion, 1, "identity schemaVersion"), y(e.identityScheme, v, "identity identityScheme"), y(e.seedProfile, U, "identity seedProfile"), e.accountIndex !== 0 && a("public wallet identity must use account 0"), y(e.accountLabel, null, "identity accountLabel"), w(e.accountXpub, "identity accountXpub"), /^xpub[1-9A-HJ-NP-Za-km-z]{107}$/u.test(e.accountXpub) || a("identity accountXpub is invalid"), w(e.accountPeerId, "identity accountPeerId"), (!e.accountPeerId.startsWith("16Uiu2H") || e.accountPeerId.length < 40 || e.accountPeerId.length > 64 || !Ce.test(e.accountPeerId)) && a("identity accountPeerId is invalid"), A(e.accountFingerprint, /^[0-9a-f]{8}$/u, "identity accountFingerprint"), de(e.keys, 3, "public identity keys array");
|
|
323
|
+
const t = [
|
|
324
|
+
{
|
|
325
|
+
purpose: "asset-review-approval",
|
|
326
|
+
curve: "ed25519",
|
|
327
|
+
signatureProfile: N,
|
|
328
|
+
path: "m/44'/0'/0'/2'/0'"
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
purpose: "contact-encryption",
|
|
332
|
+
curve: "x25519",
|
|
333
|
+
signatureProfile: null,
|
|
334
|
+
path: "m/44'/0'/0'/1'/0'"
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
purpose: "sdn-authentication",
|
|
338
|
+
curve: "ed25519",
|
|
339
|
+
signatureProfile: N,
|
|
340
|
+
path: "m/44'/0'/0'/0'/0'"
|
|
341
|
+
}
|
|
342
|
+
], n = Array.from(
|
|
343
|
+
{ length: 3 },
|
|
344
|
+
(i, o) => Fe(e.keys[o], t[o])
|
|
345
|
+
);
|
|
346
|
+
return g([
|
|
347
|
+
["accountFingerprint", e.accountFingerprint],
|
|
348
|
+
["accountIndex", 0],
|
|
349
|
+
["accountLabel", null],
|
|
350
|
+
["accountPeerId", e.accountPeerId],
|
|
351
|
+
["accountXpub", e.accountXpub],
|
|
352
|
+
["identityScheme", v],
|
|
353
|
+
["keys", J(n)],
|
|
354
|
+
["schemaVersion", 1],
|
|
355
|
+
["seedProfile", U]
|
|
356
|
+
]);
|
|
357
|
+
}
|
|
358
|
+
function Re(r, e) {
|
|
359
|
+
const t = R(r, De, `${e} result`);
|
|
360
|
+
y(t.schemaVersion, 1, "connection result schemaVersion"), ye(t.event, ["connected", "disconnected"], "connection event"), e === "connect" && t.event !== "connected" && a("connect result must be connected");
|
|
361
|
+
let n = null, i = null;
|
|
362
|
+
return t.event === "connected" ? (n = Je(t.identity), i = D(t.connectionExpiresAt, "connectionExpiresAt")) : (t.identity !== null || t.connectionExpiresAt !== null) && a("disconnected result must clear identity and expiry"), g([
|
|
363
|
+
["connectionExpiresAt", i],
|
|
364
|
+
["event", t.event],
|
|
365
|
+
["identity", n],
|
|
366
|
+
["schemaVersion", 1]
|
|
367
|
+
]);
|
|
368
|
+
}
|
|
369
|
+
function qe(r) {
|
|
370
|
+
const e = R(r, je, "raw signature");
|
|
371
|
+
return y(e.schemaVersion, 1, "signature schemaVersion"), A(e.keyId, F, "signature keyId"), ye(e.identityScheme, [
|
|
372
|
+
"sdn-fast-password-auth-v1-legacy",
|
|
373
|
+
"sdn-bip39-auth-v1-legacy"
|
|
374
|
+
], "raw signature identityScheme"), y(e.algorithm, "ed25519", "signature algorithm"), y(e.encoding, "raw", "signature encoding"), y(e.signatureProfile, ee, "signature profile"), A(e.signatureHex, ue, "signatureHex"), g([
|
|
375
|
+
["algorithm", "ed25519"],
|
|
376
|
+
["encoding", "raw"],
|
|
377
|
+
["identityScheme", e.identityScheme],
|
|
378
|
+
["keyId", e.keyId],
|
|
379
|
+
["schemaVersion", 1],
|
|
380
|
+
["signatureHex", e.signatureHex],
|
|
381
|
+
["signatureProfile", ee]
|
|
382
|
+
]);
|
|
383
|
+
}
|
|
384
|
+
function We(r, e) {
|
|
385
|
+
const t = R(r, ke, "canonical signature");
|
|
386
|
+
return y(t.schemaVersion, 1, "signature schemaVersion"), A(t.keyId, F, "signature keyId"), y(t.identityScheme, v, "signature identityScheme"), y(t.algorithm, "ed25519", "signature algorithm"), y(t.encoding, "raw", "signature encoding"), y(t.signatureProfile, N, "signature profile"), Ue(t.canonicalEnvelope, e, t), A(t.signedDigestSha256, P, "signedDigestSha256"), A(t.signatureHex, ue, "signatureHex"), g([
|
|
387
|
+
["algorithm", "ed25519"],
|
|
388
|
+
["canonicalEnvelope", t.canonicalEnvelope],
|
|
389
|
+
["encoding", "raw"],
|
|
390
|
+
["identityScheme", v],
|
|
391
|
+
["keyId", t.keyId],
|
|
392
|
+
["schemaVersion", 1],
|
|
393
|
+
["signatureHex", t.signatureHex],
|
|
394
|
+
["signatureProfile", N],
|
|
395
|
+
["signedDigestSha256", t.signedDigestSha256]
|
|
396
|
+
]);
|
|
397
|
+
}
|
|
398
|
+
function Ke(r) {
|
|
399
|
+
const e = R(r, ["challengeBase64url", "protocolVersion"], "SDN login v1 request");
|
|
400
|
+
return y(e.protocolVersion, 1, "SDN login v1 protocolVersion"), me(e.challengeBase64url, "challengeBase64url"), g([
|
|
401
|
+
["challengeBase64url", e.challengeBase64url],
|
|
402
|
+
["protocolVersion", 1]
|
|
403
|
+
]);
|
|
404
|
+
}
|
|
405
|
+
function ze(r) {
|
|
406
|
+
const e = R(r, [
|
|
407
|
+
"audience",
|
|
408
|
+
"challengeBase64url",
|
|
409
|
+
"expiresAt",
|
|
410
|
+
"issuedAt",
|
|
411
|
+
"nonce",
|
|
412
|
+
"protocolVersion"
|
|
413
|
+
], "SDN login v2 request");
|
|
414
|
+
return y(e.protocolVersion, 2, "SDN login v2 protocolVersion"), y(e.audience, W, "SDN login v2 audience"), me(e.challengeBase64url, "challengeBase64url"), A(e.nonce, P, "SDN login nonce"), D(e.issuedAt, "SDN login issuedAt"), D(e.expiresAt, "SDN login expiresAt"), pe(e.issuedAt, e.expiresAt), g([
|
|
415
|
+
["audience", W],
|
|
416
|
+
["challengeBase64url", e.challengeBase64url],
|
|
417
|
+
["expiresAt", e.expiresAt],
|
|
418
|
+
["issuedAt", e.issuedAt],
|
|
419
|
+
["nonce", e.nonce],
|
|
420
|
+
["protocolVersion", 2]
|
|
421
|
+
]);
|
|
422
|
+
}
|
|
423
|
+
function Ae(r, e) {
|
|
424
|
+
return R(r, [], e), J({});
|
|
425
|
+
}
|
|
426
|
+
function He(r = {}) {
|
|
427
|
+
return Ae(r, "wallet connect request");
|
|
428
|
+
}
|
|
429
|
+
function Xe(r) {
|
|
430
|
+
return Re(r, "connect");
|
|
431
|
+
}
|
|
432
|
+
function Qe(r = {}) {
|
|
433
|
+
return Ae(r, "wallet account request");
|
|
434
|
+
}
|
|
435
|
+
function Ze(r) {
|
|
436
|
+
return Re(r, "account");
|
|
437
|
+
}
|
|
438
|
+
function Ge(r) {
|
|
439
|
+
const e = R(r, ["challenge", "protocolVersion"], "SDN login v1 public request");
|
|
440
|
+
return y(e.protocolVersion, 1, "SDN login v1 protocolVersion"), Ke({
|
|
441
|
+
challengeBase64url: H(e.challenge, "challenge"),
|
|
442
|
+
protocolVersion: 1
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
function et(r) {
|
|
446
|
+
return qe(r);
|
|
447
|
+
}
|
|
448
|
+
function tt(r) {
|
|
449
|
+
const e = R(r, [
|
|
450
|
+
"audience",
|
|
451
|
+
"challenge",
|
|
452
|
+
"expiresAt",
|
|
453
|
+
"issuedAt",
|
|
454
|
+
"nonce",
|
|
455
|
+
"protocolVersion"
|
|
456
|
+
], "SDN login v2 public request");
|
|
457
|
+
return ze({
|
|
458
|
+
audience: e.audience,
|
|
459
|
+
challengeBase64url: H(e.challenge, "challenge"),
|
|
460
|
+
expiresAt: e.expiresAt,
|
|
461
|
+
issuedAt: e.issuedAt,
|
|
462
|
+
nonce: e.nonce,
|
|
463
|
+
protocolVersion: e.protocolVersion
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
function rt(r) {
|
|
467
|
+
return We(r, "sdn-login");
|
|
468
|
+
}
|
|
469
|
+
const _ = "https://wallet.spacedatanetwork.org", j = "sdn.wallet.callback.v1:", T = /^[0-9a-f]{64}$/u, te = /^[A-Za-z0-9_-]{43}$/u, nt = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/u, it = 250, st = 3e4, ot = 3e5, ct = 9e5, at = 12e4, lt = 8, re = 4096, ne = 70 * 1024, ut = 64, Ee = Object.freeze({
|
|
470
|
+
CALLBACK_ERROR: "The wallet return could not be verified. Try again.",
|
|
471
|
+
CRYPTO_UNAVAILABLE: "Secure browser cryptography is unavailable.",
|
|
472
|
+
DESTROYED: "This wallet client has been destroyed.",
|
|
473
|
+
DISCONNECTED: "The wallet was disconnected.",
|
|
474
|
+
EXPIRED: "The wallet connection expired.",
|
|
475
|
+
INVALID_CLIENT: "This wallet client is not registered.",
|
|
476
|
+
INVALID_REQUEST: "The wallet request is invalid.",
|
|
477
|
+
RELAY_ERROR: "The wallet service could not complete the request. Try again.",
|
|
478
|
+
REPLACED: "A newer wallet request replaced this one.",
|
|
479
|
+
WALLET_NOT_COMPLETED: "The wallet did not complete. Check popup settings and try again."
|
|
480
|
+
}), be = new TextEncoder(), ht = new TextDecoder("utf-8", { fatal: !0 });
|
|
481
|
+
class C extends Error {
|
|
482
|
+
constructor(e) {
|
|
483
|
+
super(Ee[e]), this.name = "WalletClientError", Object.defineProperty(this, "code", {
|
|
484
|
+
configurable: !1,
|
|
485
|
+
enumerable: !0,
|
|
486
|
+
value: e,
|
|
487
|
+
writable: !1
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
function c(r) {
|
|
492
|
+
return Object.hasOwn(Ee, r) ? new C(r) : new C("RELAY_ERROR");
|
|
493
|
+
}
|
|
494
|
+
function ft(r) {
|
|
495
|
+
if (r === null || typeof r != "object" || Array.isArray(r)) return !1;
|
|
496
|
+
const e = Object.getPrototypeOf(r);
|
|
497
|
+
return e === Object.prototype || e === null;
|
|
498
|
+
}
|
|
499
|
+
function V(r, e) {
|
|
500
|
+
if (typeof r != "string" || r.length > e || be.encode(r).byteLength > e || r.charCodeAt(0) === 65279)
|
|
501
|
+
throw c("RELAY_ERROR");
|
|
502
|
+
let t = 0, n = 0;
|
|
503
|
+
const i = () => {
|
|
504
|
+
for (; t < r.length && /[\u0009\u000a\u000d\u0020]/u.test(r[t]); ) t += 1;
|
|
505
|
+
}, o = () => {
|
|
506
|
+
if (r[t] !== '"') throw c("RELAY_ERROR");
|
|
507
|
+
const l = t;
|
|
508
|
+
for (t += 1; t < r.length; ) {
|
|
509
|
+
const f = r.charCodeAt(t);
|
|
510
|
+
if (f === 34) {
|
|
511
|
+
t += 1;
|
|
512
|
+
let h;
|
|
513
|
+
try {
|
|
514
|
+
h = JSON.parse(r.slice(l, t));
|
|
515
|
+
} catch {
|
|
516
|
+
throw c("RELAY_ERROR");
|
|
517
|
+
}
|
|
518
|
+
for (let d = 0; d < h.length; d += 1) {
|
|
519
|
+
const p = h.charCodeAt(d);
|
|
520
|
+
if (p >= 55296 && p <= 56319) {
|
|
521
|
+
const m = h.charCodeAt(d + 1);
|
|
522
|
+
if (!(m >= 56320 && m <= 57343)) throw c("RELAY_ERROR");
|
|
523
|
+
d += 1;
|
|
524
|
+
} else if (p >= 56320 && p <= 57343)
|
|
525
|
+
throw c("RELAY_ERROR");
|
|
526
|
+
}
|
|
527
|
+
return h;
|
|
528
|
+
}
|
|
529
|
+
if (f < 32 || f === 92 && (t += 1, t >= r.length))
|
|
530
|
+
throw c("RELAY_ERROR");
|
|
531
|
+
t += 1;
|
|
532
|
+
}
|
|
533
|
+
throw c("RELAY_ERROR");
|
|
534
|
+
}, s = (l = 0) => {
|
|
535
|
+
if (l > 32 || ++n > 4096) throw c("RELAY_ERROR");
|
|
536
|
+
i();
|
|
537
|
+
const f = r[t];
|
|
538
|
+
if (f === '"') return o();
|
|
539
|
+
if (f === "{") {
|
|
540
|
+
t += 1;
|
|
541
|
+
const p = /* @__PURE__ */ Object.create(null), m = /* @__PURE__ */ new Set();
|
|
542
|
+
if (i(), r[t] === "}")
|
|
543
|
+
return t += 1, p;
|
|
544
|
+
for (; t < r.length; ) {
|
|
545
|
+
i();
|
|
546
|
+
const O = o();
|
|
547
|
+
if (m.has(O) || (m.add(O), i(), r[t] !== ":")) throw c("RELAY_ERROR");
|
|
548
|
+
if (t += 1, p[O] = s(l + 1), i(), r[t] === "}")
|
|
549
|
+
return t += 1, p;
|
|
550
|
+
if (r[t] !== ",") throw c("RELAY_ERROR");
|
|
551
|
+
t += 1;
|
|
552
|
+
}
|
|
553
|
+
throw c("RELAY_ERROR");
|
|
554
|
+
}
|
|
555
|
+
if (f === "[") {
|
|
556
|
+
t += 1;
|
|
557
|
+
const p = [];
|
|
558
|
+
if (i(), r[t] === "]")
|
|
559
|
+
return t += 1, p;
|
|
560
|
+
for (; t < r.length; ) {
|
|
561
|
+
if (p.push(s(l + 1)), i(), r[t] === "]")
|
|
562
|
+
return t += 1, p;
|
|
563
|
+
if (r[t] !== ",") throw c("RELAY_ERROR");
|
|
564
|
+
t += 1;
|
|
565
|
+
}
|
|
566
|
+
throw c("RELAY_ERROR");
|
|
567
|
+
}
|
|
568
|
+
for (const [p, m] of [["true", !0], ["false", !1], ["null", null]])
|
|
569
|
+
if (r.startsWith(p, t))
|
|
570
|
+
return t += p.length, m;
|
|
571
|
+
const h = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/u.exec(r.slice(t));
|
|
572
|
+
if (!h) throw c("RELAY_ERROR");
|
|
573
|
+
t += h[0].length;
|
|
574
|
+
const d = Number(h[0]);
|
|
575
|
+
if (!Number.isFinite(d)) throw c("RELAY_ERROR");
|
|
576
|
+
return d;
|
|
577
|
+
};
|
|
578
|
+
i();
|
|
579
|
+
const u = s();
|
|
580
|
+
if (i(), t !== r.length) throw c("RELAY_ERROR");
|
|
581
|
+
return u;
|
|
582
|
+
}
|
|
583
|
+
function $(r, e, t = "RELAY_ERROR") {
|
|
584
|
+
if (!ft(r) || Object.getOwnPropertySymbols(r).length !== 0)
|
|
585
|
+
throw c(t);
|
|
586
|
+
const n = Object.getOwnPropertyNames(r).sort(), i = [...e].sort();
|
|
587
|
+
if (n.length !== i.length || n.some((o, s) => o !== i[s]))
|
|
588
|
+
throw c(t);
|
|
589
|
+
for (const o of n) {
|
|
590
|
+
const s = Object.getOwnPropertyDescriptor(r, o);
|
|
591
|
+
if (!s?.enumerable || !("value" in s) || s.value === void 0)
|
|
592
|
+
throw c(t);
|
|
593
|
+
}
|
|
594
|
+
return r;
|
|
595
|
+
}
|
|
596
|
+
function M(r, e = "RELAY_ERROR") {
|
|
597
|
+
if (typeof r != "string" || !nt.test(r))
|
|
598
|
+
throw c(e);
|
|
599
|
+
const t = Date.parse(r);
|
|
600
|
+
if (!Number.isFinite(t) || new Date(t).toISOString() !== r)
|
|
601
|
+
throw c(e);
|
|
602
|
+
return t;
|
|
603
|
+
}
|
|
604
|
+
function S(r) {
|
|
605
|
+
return Array.isArray(r) ? Object.freeze(r.map(S)) : r && typeof r == "object" ? Object.freeze(Object.fromEntries(
|
|
606
|
+
Object.entries(r).map(([e, t]) => [e, S(t)])
|
|
607
|
+
)) : r;
|
|
608
|
+
}
|
|
609
|
+
function ie(r) {
|
|
610
|
+
const e = {
|
|
611
|
+
identity: r.identity === null ? null : S(r.identity),
|
|
612
|
+
status: r.status
|
|
613
|
+
};
|
|
614
|
+
return r.connectionExpiresAt !== void 0 && (e.connectionExpiresAt = r.connectionExpiresAt), r.error !== void 0 && (e.error = S(r.error)), S(e);
|
|
615
|
+
}
|
|
616
|
+
function I(r) {
|
|
617
|
+
return Object.freeze({ code: r.code, message: r.message });
|
|
618
|
+
}
|
|
619
|
+
function se(r) {
|
|
620
|
+
const e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
621
|
+
let t = 0, n = 0, i = "";
|
|
622
|
+
for (const o of r)
|
|
623
|
+
for (t = t << 8 | o, n += 8; n >= 6; )
|
|
624
|
+
n -= 6, i += e[t >>> n & 63], t &= (1 << n) - 1;
|
|
625
|
+
return n !== 0 && (i += e[t << 6 - n & 63]), i;
|
|
626
|
+
}
|
|
627
|
+
function oe(r) {
|
|
628
|
+
let e = "";
|
|
629
|
+
for (const t of r) e += t.toString(16).padStart(2, "0");
|
|
630
|
+
return e;
|
|
631
|
+
}
|
|
632
|
+
function q(r, e) {
|
|
633
|
+
const t = new Uint8Array(32);
|
|
634
|
+
return Reflect.apply(e, r, [t]), t;
|
|
635
|
+
}
|
|
636
|
+
function dt(r) {
|
|
637
|
+
const e = r?.headers?.get?.("content-type");
|
|
638
|
+
return typeof e == "string" && /^application\/json(?:\s*;\s*charset=utf-8)?$/iu.test(e.trim());
|
|
639
|
+
}
|
|
640
|
+
function X(r) {
|
|
641
|
+
try {
|
|
642
|
+
Promise.resolve(r).catch(() => {
|
|
643
|
+
});
|
|
644
|
+
} catch {
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
function x(r) {
|
|
648
|
+
try {
|
|
649
|
+
const e = r?.body, t = e?.cancel;
|
|
650
|
+
typeof t == "function" && X(Reflect.apply(t, e, []));
|
|
651
|
+
} catch {
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
function ge(r) {
|
|
655
|
+
try {
|
|
656
|
+
const e = r?.cancel;
|
|
657
|
+
typeof e == "function" && X(Reflect.apply(e, r, []));
|
|
658
|
+
} catch {
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
function yt(r) {
|
|
662
|
+
try {
|
|
663
|
+
const e = r?.releaseLock;
|
|
664
|
+
typeof e == "function" && Reflect.apply(e, r, []);
|
|
665
|
+
} catch {
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
function L(r, e, t = null) {
|
|
669
|
+
try {
|
|
670
|
+
r.abort();
|
|
671
|
+
} catch {
|
|
672
|
+
}
|
|
673
|
+
t && ge(t), x(e);
|
|
674
|
+
}
|
|
675
|
+
function Y(r, e, t = null) {
|
|
676
|
+
let n;
|
|
677
|
+
try {
|
|
678
|
+
n = Promise.resolve(r);
|
|
679
|
+
} catch (i) {
|
|
680
|
+
return Promise.reject(i);
|
|
681
|
+
}
|
|
682
|
+
return new Promise((i, o) => {
|
|
683
|
+
let s = !1;
|
|
684
|
+
const u = () => {
|
|
685
|
+
try {
|
|
686
|
+
e.removeEventListener("abort", f);
|
|
687
|
+
} catch {
|
|
688
|
+
}
|
|
689
|
+
}, l = (h, d) => s ? !1 : (s = !0, u(), h(d), !0), f = () => {
|
|
690
|
+
l(o, c("RELAY_ERROR"));
|
|
691
|
+
};
|
|
692
|
+
try {
|
|
693
|
+
e.addEventListener("abort", f, { once: !0 }), e.aborted && f();
|
|
694
|
+
} catch {
|
|
695
|
+
f();
|
|
696
|
+
}
|
|
697
|
+
n.then(
|
|
698
|
+
(h) => {
|
|
699
|
+
if (s) {
|
|
700
|
+
try {
|
|
701
|
+
t?.(h);
|
|
702
|
+
} catch {
|
|
703
|
+
}
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
l(i, h);
|
|
707
|
+
},
|
|
708
|
+
(h) => {
|
|
709
|
+
s || l(o, h);
|
|
710
|
+
}
|
|
711
|
+
);
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
async function ce(r, e, t) {
|
|
715
|
+
let n = null;
|
|
716
|
+
const i = [];
|
|
717
|
+
let o = 0;
|
|
718
|
+
try {
|
|
719
|
+
if (!dt(r) || typeof r?.body?.getReader != "function")
|
|
720
|
+
throw c("RELAY_ERROR");
|
|
721
|
+
for (n = r.body.getReader(); ; ) {
|
|
722
|
+
const l = n.read(), { done: f, value: h } = await Y(l, t.signal);
|
|
723
|
+
if (f) break;
|
|
724
|
+
if (!(h instanceof Uint8Array) || (o += h.byteLength, o > e))
|
|
725
|
+
throw c("RELAY_ERROR");
|
|
726
|
+
i.push(h);
|
|
727
|
+
}
|
|
728
|
+
const s = new Uint8Array(o);
|
|
729
|
+
let u = 0;
|
|
730
|
+
for (const l of i)
|
|
731
|
+
s.set(l, u), u += l.byteLength;
|
|
732
|
+
return ht.decode(s);
|
|
733
|
+
} catch {
|
|
734
|
+
try {
|
|
735
|
+
t.abort();
|
|
736
|
+
} catch {
|
|
737
|
+
}
|
|
738
|
+
throw n && ge(n), c("RELAY_ERROR");
|
|
739
|
+
} finally {
|
|
740
|
+
n && yt(n);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
function k(r, e) {
|
|
744
|
+
const t = {
|
|
745
|
+
body: JSON.stringify(r),
|
|
746
|
+
cache: "no-store",
|
|
747
|
+
credentials: "omit",
|
|
748
|
+
headers: { "Content-Type": "application/json" },
|
|
749
|
+
method: "POST",
|
|
750
|
+
mode: "cors",
|
|
751
|
+
redirect: "error",
|
|
752
|
+
referrerPolicy: "no-referrer"
|
|
753
|
+
};
|
|
754
|
+
return e !== void 0 && (t.signal = e), t;
|
|
755
|
+
}
|
|
756
|
+
function pt(r, e, t) {
|
|
757
|
+
let n;
|
|
758
|
+
try {
|
|
759
|
+
n = V(r, 2048), $(n, ["code", "expiresAt", "schemaVersion", "state"], "CALLBACK_ERROR");
|
|
760
|
+
} catch {
|
|
761
|
+
throw c("CALLBACK_ERROR");
|
|
762
|
+
}
|
|
763
|
+
if (n.schemaVersion !== 1 || n.state !== e || !T.test(n.code))
|
|
764
|
+
throw c("CALLBACK_ERROR");
|
|
765
|
+
const i = M(n.expiresAt, "CALLBACK_ERROR");
|
|
766
|
+
if (i <= t || i - t > at)
|
|
767
|
+
throw c("CALLBACK_ERROR");
|
|
768
|
+
return { code: n.code, expiresAt: i, state: n.state };
|
|
769
|
+
}
|
|
770
|
+
function mt() {
|
|
771
|
+
let r;
|
|
772
|
+
return { promise: new Promise((t) => {
|
|
773
|
+
r = t;
|
|
774
|
+
}), resolve: r };
|
|
775
|
+
}
|
|
776
|
+
function ae() {
|
|
777
|
+
let r, e;
|
|
778
|
+
return { promise: new Promise((n, i) => {
|
|
779
|
+
r = i, e = n;
|
|
780
|
+
}), reject: r, resolve: e };
|
|
781
|
+
}
|
|
782
|
+
function Rt() {
|
|
783
|
+
const r = globalThis.window;
|
|
784
|
+
return Object.freeze({
|
|
785
|
+
AbortController: globalThis.AbortController,
|
|
786
|
+
clearInterval: globalThis.clearInterval.bind(globalThis),
|
|
787
|
+
clearTimeout: globalThis.clearTimeout.bind(globalThis),
|
|
788
|
+
crypto: globalThis.crypto,
|
|
789
|
+
fetch: typeof globalThis.fetch == "function" ? globalThis.fetch.bind(globalThis) : void 0,
|
|
790
|
+
getStorage: () => {
|
|
791
|
+
try {
|
|
792
|
+
return r?.localStorage ?? null;
|
|
793
|
+
} catch {
|
|
794
|
+
return null;
|
|
795
|
+
}
|
|
796
|
+
},
|
|
797
|
+
now: () => Date.now(),
|
|
798
|
+
setInterval: globalThis.setInterval.bind(globalThis),
|
|
799
|
+
setTimeout: globalThis.setTimeout.bind(globalThis),
|
|
800
|
+
window: r
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
class At {
|
|
804
|
+
#k;
|
|
805
|
+
#V;
|
|
806
|
+
#T = !1;
|
|
807
|
+
#l = !1;
|
|
808
|
+
#$ = !1;
|
|
809
|
+
#s = null;
|
|
810
|
+
#O = null;
|
|
811
|
+
#E = /* @__PURE__ */ new Set();
|
|
812
|
+
#e;
|
|
813
|
+
#S = null;
|
|
814
|
+
#r = !1;
|
|
815
|
+
#m = 0;
|
|
816
|
+
#w = 0;
|
|
817
|
+
#v = /* @__PURE__ */ new Set();
|
|
818
|
+
#x = [];
|
|
819
|
+
#o = null;
|
|
820
|
+
#C = !1;
|
|
821
|
+
#y = /* @__PURE__ */ new Set();
|
|
822
|
+
#M = Object.freeze({ identity: null, status: "dormant" });
|
|
823
|
+
#u = null;
|
|
824
|
+
#L = null;
|
|
825
|
+
#b = null;
|
|
826
|
+
#R = /* @__PURE__ */ new Set();
|
|
827
|
+
#p;
|
|
828
|
+
constructor({ adapters: e, clientId: t, dependencies: n }) {
|
|
829
|
+
this.#k = e, this.#V = t, this.#e = n ?? Rt(), this.#p = this.#e.window;
|
|
830
|
+
}
|
|
831
|
+
getSnapshot() {
|
|
832
|
+
return this.#U(), ie(this.#M);
|
|
833
|
+
}
|
|
834
|
+
subscribe(e) {
|
|
835
|
+
if (typeof e != "function") throw c("INVALID_REQUEST");
|
|
836
|
+
if (this.#r) throw c("DESTROYED");
|
|
837
|
+
this.#v.add(e);
|
|
838
|
+
try {
|
|
839
|
+
e(this.getSnapshot());
|
|
840
|
+
} catch {
|
|
841
|
+
}
|
|
842
|
+
let t = !0;
|
|
843
|
+
return () => {
|
|
844
|
+
t && (t = !1, this.#v.delete(e));
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
execute(e, t) {
|
|
848
|
+
if (this.#r) return Promise.reject(c("DESTROYED"));
|
|
849
|
+
const n = this.#m, i = this.#k[e];
|
|
850
|
+
if (!i) return Promise.reject(c("INVALID_REQUEST"));
|
|
851
|
+
let o;
|
|
852
|
+
try {
|
|
853
|
+
o = i.buildRequest(t);
|
|
854
|
+
} catch {
|
|
855
|
+
const E = this.#t(n);
|
|
856
|
+
return E ? Promise.reject(E) : Promise.reject(c("INVALID_REQUEST"));
|
|
857
|
+
}
|
|
858
|
+
let s = this.#t(n);
|
|
859
|
+
if (s) return Promise.reject(s);
|
|
860
|
+
if (this.#T)
|
|
861
|
+
return this.#l = !0, Promise.reject(c("REPLACED"));
|
|
862
|
+
const u = ++this.#m;
|
|
863
|
+
if (this.#Q(), s = this.#t(u), s) return Promise.reject(s);
|
|
864
|
+
if (this.#l)
|
|
865
|
+
return Promise.reject(c("CALLBACK_ERROR"));
|
|
866
|
+
if (this.#U(), s = this.#t(u), s) return Promise.reject(s);
|
|
867
|
+
const l = this.#i();
|
|
868
|
+
if (s = this.#t(u), s) return Promise.reject(s);
|
|
869
|
+
const f = this.#s && this.#s.expiresAtMs > l ? this.#s : null;
|
|
870
|
+
if (s = this.#t(u), s) return Promise.reject(s);
|
|
871
|
+
const h = this.#o;
|
|
872
|
+
let d, p, m;
|
|
873
|
+
try {
|
|
874
|
+
const E = this.#e.crypto, b = E?.getRandomValues, Se = E?.subtle?.digest, Z = this.#p?.open;
|
|
875
|
+
if (s = this.#t(u), s) throw s;
|
|
876
|
+
if (typeof b != "function" || typeof Se != "function" || typeof Z != "function")
|
|
877
|
+
throw c("CRYPTO_UNAVAILABLE");
|
|
878
|
+
if (d = oe(q(E, b)), s = this.#t(u), s || (p = oe(q(E, b)), s = this.#t(u), s) || (m = se(q(E, b)), s = this.#t(u), s)) throw s;
|
|
879
|
+
if (!T.test(d) || !T.test(p) || !te.test(m))
|
|
880
|
+
throw c("CRYPTO_UNAVAILABLE");
|
|
881
|
+
if (Reflect.apply(Z, this.#p, [
|
|
882
|
+
`${_}/transaction/${d}`,
|
|
883
|
+
"_blank",
|
|
884
|
+
"noopener"
|
|
885
|
+
]), s = this.#t(u), s) throw s;
|
|
886
|
+
} catch (E) {
|
|
887
|
+
if (s = this.#t(u), s) return Promise.reject(s);
|
|
888
|
+
let b;
|
|
889
|
+
try {
|
|
890
|
+
b = E instanceof C ? E : c("CRYPTO_UNAVAILABLE");
|
|
891
|
+
} catch {
|
|
892
|
+
b = c("CRYPTO_UNAVAILABLE");
|
|
893
|
+
}
|
|
894
|
+
return h && (this.#_(h, "REPLACED", !1), s = this.#t(u), s) ? Promise.reject(s) : (this.#Y(null, b, f, i.kind), Promise.reject(b));
|
|
895
|
+
}
|
|
896
|
+
if (h && (this.#_(h, "REPLACED", !1), s = this.#t(u), s))
|
|
897
|
+
return Promise.reject(s);
|
|
898
|
+
const O = ae(), Oe = mt(), Q = {
|
|
899
|
+
active: !0,
|
|
900
|
+
adapter: i,
|
|
901
|
+
callbackBusy: !1,
|
|
902
|
+
challenge: null,
|
|
903
|
+
cleanup: Oe,
|
|
904
|
+
cleanupFinished: !1,
|
|
905
|
+
cleanupStarted: !1,
|
|
906
|
+
controllers: /* @__PURE__ */ new Set(),
|
|
907
|
+
expiryTimer: null,
|
|
908
|
+
generation: ++this.#w,
|
|
909
|
+
operationTimer: null,
|
|
910
|
+
phase: "hashing",
|
|
911
|
+
pollTimer: null,
|
|
912
|
+
priorConnection: f,
|
|
913
|
+
promise: O.promise,
|
|
914
|
+
registrationDeadlineMs: l + st,
|
|
915
|
+
registrationOutcome: "none",
|
|
916
|
+
reject: O.reject,
|
|
917
|
+
request: o,
|
|
918
|
+
resolve: O.resolve,
|
|
919
|
+
retryResolve: null,
|
|
920
|
+
retryTimer: null,
|
|
921
|
+
state: p,
|
|
922
|
+
transactionExpiresAtMs: null,
|
|
923
|
+
transactionId: d,
|
|
924
|
+
verifier: m
|
|
925
|
+
};
|
|
926
|
+
return this.#o = Q, this.#n({
|
|
927
|
+
...f ? {
|
|
928
|
+
connectionExpiresAt: f.expiresAt,
|
|
929
|
+
identity: f.identity
|
|
930
|
+
} : { identity: null },
|
|
931
|
+
status: "opening"
|
|
932
|
+
}), this.#q(Q), O.promise;
|
|
933
|
+
}
|
|
934
|
+
async disconnect() {
|
|
935
|
+
if (this.#r) throw c("DESTROYED");
|
|
936
|
+
const e = ++this.#m;
|
|
937
|
+
this.#f();
|
|
938
|
+
const t = this.#o;
|
|
939
|
+
let n = Promise.resolve();
|
|
940
|
+
t && (n = this.#_(t, "DISCONNECTED", !1));
|
|
941
|
+
let i = this.#t(e);
|
|
942
|
+
if (i)
|
|
943
|
+
throw await n, i;
|
|
944
|
+
if (this.#n({ identity: null, status: "dormant" }), await n, i = this.#t(e), i) throw i;
|
|
945
|
+
}
|
|
946
|
+
destroy() {
|
|
947
|
+
if (this.#S) return this.#S;
|
|
948
|
+
const e = ae();
|
|
949
|
+
this.#S = e.promise, this.#m += 1;
|
|
950
|
+
try {
|
|
951
|
+
this.#J(), e.resolve();
|
|
952
|
+
} catch {
|
|
953
|
+
e.reject(c("RELAY_ERROR"));
|
|
954
|
+
}
|
|
955
|
+
return this.#S;
|
|
956
|
+
}
|
|
957
|
+
#J() {
|
|
958
|
+
this.#r = !0, this.#w += 1, this.#f();
|
|
959
|
+
const e = [], t = this.#o;
|
|
960
|
+
t && (t.active = !1, this.#o = null, this.#I(t), t.reject(c("DESTROYED")), t.challenge && t.verifier && e.push(t));
|
|
961
|
+
for (const n of this.#y)
|
|
962
|
+
n.challenge && n.verifier && e.push(n);
|
|
963
|
+
for (const n of this.#E) n.abort();
|
|
964
|
+
this.#E.clear();
|
|
965
|
+
for (const n of this.#R)
|
|
966
|
+
this.#e.clearTimeout(n), this.#e.clearInterval(n);
|
|
967
|
+
if (this.#R.clear(), this.#b)
|
|
968
|
+
try {
|
|
969
|
+
this.#b();
|
|
970
|
+
} catch {
|
|
971
|
+
}
|
|
972
|
+
this.#L = null, this.#b = null, this.#u = null, this.#v.clear();
|
|
973
|
+
for (const n of e) this.#X(n);
|
|
974
|
+
t && this.#a(t);
|
|
975
|
+
for (const n of [...this.#y]) this.#a(n);
|
|
976
|
+
this.#n({
|
|
977
|
+
error: I(c("DESTROYED")),
|
|
978
|
+
identity: null,
|
|
979
|
+
status: "error"
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
async #q(e) {
|
|
983
|
+
if (!(!this.#c(e) || e.cleanupFinished))
|
|
984
|
+
try {
|
|
985
|
+
e.operationTimer = this.#g(() => {
|
|
986
|
+
if (!e.cleanupFinished) {
|
|
987
|
+
if (e.phase === "hashing") {
|
|
988
|
+
this.#c(e) && this.#h(e, "CRYPTO_UNAVAILABLE", !1);
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
if (e.phase === "registering")
|
|
992
|
+
for (const u of e.controllers) u.abort();
|
|
993
|
+
}
|
|
994
|
+
}, Math.max(0, e.registrationDeadlineMs - this.#i()));
|
|
995
|
+
const t = await this.#e.crypto.subtle.digest(
|
|
996
|
+
"SHA-256",
|
|
997
|
+
be.encode(e.verifier)
|
|
998
|
+
), n = se(new Uint8Array(t));
|
|
999
|
+
if (!te.test(n)) throw c("CRYPTO_UNAVAILABLE");
|
|
1000
|
+
if (!this.#c(e)) {
|
|
1001
|
+
e.registrationOutcome = "not-started", this.#a(e);
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
e.challenge = n, e.phase = "registering";
|
|
1005
|
+
const i = this.#P(e);
|
|
1006
|
+
let o, s = null;
|
|
1007
|
+
try {
|
|
1008
|
+
try {
|
|
1009
|
+
const l = this.#e.fetch(
|
|
1010
|
+
`${_}/relay/v1/transactions`,
|
|
1011
|
+
k({
|
|
1012
|
+
clientId: this.#V,
|
|
1013
|
+
codeChallenge: e.challenge,
|
|
1014
|
+
codeChallengeMethod: "S256",
|
|
1015
|
+
operation: e.adapter.operation,
|
|
1016
|
+
request: e.request,
|
|
1017
|
+
schemaVersion: 1,
|
|
1018
|
+
state: e.state,
|
|
1019
|
+
transactionId: e.transactionId
|
|
1020
|
+
}, i.signal)
|
|
1021
|
+
);
|
|
1022
|
+
s = await Y(
|
|
1023
|
+
l,
|
|
1024
|
+
i.signal,
|
|
1025
|
+
x
|
|
1026
|
+
);
|
|
1027
|
+
} catch {
|
|
1028
|
+
e.registrationOutcome = "ambiguous", e.active ? this.#h(e, "RELAY_ERROR") : this.#A(e);
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
e.registrationOutcome = "ambiguous";
|
|
1032
|
+
let u;
|
|
1033
|
+
try {
|
|
1034
|
+
u = s.status;
|
|
1035
|
+
} catch {
|
|
1036
|
+
L(i, s), e.active ? this.#h(e, "RELAY_ERROR") : this.#A(e);
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
1039
|
+
if (u !== 201) {
|
|
1040
|
+
e.registrationOutcome = "definitive-failure", L(i, s), e.active ? this.#h(e, "RELAY_ERROR", !1) : this.#a(e);
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
1043
|
+
try {
|
|
1044
|
+
const l = await ce(
|
|
1045
|
+
s,
|
|
1046
|
+
re,
|
|
1047
|
+
i
|
|
1048
|
+
), f = $(
|
|
1049
|
+
V(l, re),
|
|
1050
|
+
["expiresAt", "schemaVersion", "transactionId"]
|
|
1051
|
+
);
|
|
1052
|
+
if (f.schemaVersion !== 1 || f.transactionId !== e.transactionId)
|
|
1053
|
+
throw c("RELAY_ERROR");
|
|
1054
|
+
o = M(f.expiresAt);
|
|
1055
|
+
const h = this.#i();
|
|
1056
|
+
if (o <= h || o - h > ot)
|
|
1057
|
+
throw c("RELAY_ERROR");
|
|
1058
|
+
} catch {
|
|
1059
|
+
e.registrationOutcome = "ambiguous", L(i, s), e.active ? this.#h(e, "RELAY_ERROR") : this.#A(e);
|
|
1060
|
+
return;
|
|
1061
|
+
}
|
|
1062
|
+
} finally {
|
|
1063
|
+
try {
|
|
1064
|
+
i.abort();
|
|
1065
|
+
} catch {
|
|
1066
|
+
}
|
|
1067
|
+
this.#D(e, i), this.#d(e.operationTimer), e.operationTimer = null;
|
|
1068
|
+
}
|
|
1069
|
+
if (e.transactionExpiresAtMs = o, e.registrationOutcome = "registered", !this.#c(e)) {
|
|
1070
|
+
this.#A(e);
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
e.phase = "waiting-callback", e.expiryTimer = this.#g(() => {
|
|
1074
|
+
this.#c(e) && this.#h(e, "WALLET_NOT_COMPLETED");
|
|
1075
|
+
}, Math.max(0, e.transactionExpiresAtMs - this.#i())), e.pollTimer = this.#H(() => {
|
|
1076
|
+
this.#N(e, !1);
|
|
1077
|
+
}, it), await this.#N(e, !1);
|
|
1078
|
+
} catch (t) {
|
|
1079
|
+
if (!e.active) {
|
|
1080
|
+
e.registrationOutcome === "ambiguous" || e.registrationOutcome === "registered" ? this.#A(e) : this.#a(e);
|
|
1081
|
+
return;
|
|
1082
|
+
}
|
|
1083
|
+
const n = t instanceof C ? t.code : e.phase === "hashing" ? "CRYPTO_UNAVAILABLE" : "RELAY_ERROR";
|
|
1084
|
+
this.#h(e, n, e.registrationOutcome !== "none");
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
async #N(e, t) {
|
|
1088
|
+
if (!this.#c(e) || e.phase !== "waiting-callback" || e.callbackBusy || !this.#u) return;
|
|
1089
|
+
const n = `${j}${e.state}`;
|
|
1090
|
+
let i;
|
|
1091
|
+
try {
|
|
1092
|
+
i = this.#u.getItem(n);
|
|
1093
|
+
} catch {
|
|
1094
|
+
t && this.#h(e, "CALLBACK_ERROR");
|
|
1095
|
+
return;
|
|
1096
|
+
}
|
|
1097
|
+
if (i === null) return;
|
|
1098
|
+
e.callbackBusy = !0;
|
|
1099
|
+
let o;
|
|
1100
|
+
try {
|
|
1101
|
+
o = pt(i, e.state, this.#i()), this.#u.removeItem(n);
|
|
1102
|
+
} catch {
|
|
1103
|
+
try {
|
|
1104
|
+
this.#u.removeItem(n);
|
|
1105
|
+
} catch {
|
|
1106
|
+
}
|
|
1107
|
+
this.#h(e, "CALLBACK_ERROR");
|
|
1108
|
+
return;
|
|
1109
|
+
}
|
|
1110
|
+
if (!this.#c(e)) return;
|
|
1111
|
+
e.phase = "redeeming", this.#d(e.pollTimer, !0), e.pollTimer = null;
|
|
1112
|
+
const s = this.#P(e);
|
|
1113
|
+
let u = null;
|
|
1114
|
+
try {
|
|
1115
|
+
const l = this.#e.fetch(
|
|
1116
|
+
`${_}/relay/v1/codes/redeem`,
|
|
1117
|
+
k({
|
|
1118
|
+
code: o.code,
|
|
1119
|
+
codeVerifier: e.verifier,
|
|
1120
|
+
schemaVersion: 1,
|
|
1121
|
+
state: e.state,
|
|
1122
|
+
transactionId: e.transactionId
|
|
1123
|
+
}, s.signal)
|
|
1124
|
+
);
|
|
1125
|
+
if (u = await Y(
|
|
1126
|
+
l,
|
|
1127
|
+
s.signal,
|
|
1128
|
+
x
|
|
1129
|
+
), u.status !== 200) throw c("RELAY_ERROR");
|
|
1130
|
+
const f = await ce(
|
|
1131
|
+
u,
|
|
1132
|
+
ne,
|
|
1133
|
+
s
|
|
1134
|
+
), h = $(
|
|
1135
|
+
V(f, ne),
|
|
1136
|
+
["result", "schemaVersion", "transactionId"]
|
|
1137
|
+
);
|
|
1138
|
+
if (h.schemaVersion !== 1 || h.transactionId !== e.transactionId)
|
|
1139
|
+
throw c("RELAY_ERROR");
|
|
1140
|
+
let d;
|
|
1141
|
+
try {
|
|
1142
|
+
d = e.adapter.parseResult(h.result);
|
|
1143
|
+
} catch {
|
|
1144
|
+
throw c("RELAY_ERROR");
|
|
1145
|
+
}
|
|
1146
|
+
if (!this.#c(e)) return;
|
|
1147
|
+
this.#W(e, d);
|
|
1148
|
+
} catch (l) {
|
|
1149
|
+
if (u && L(s, u), !this.#c(e)) return;
|
|
1150
|
+
const f = l instanceof C ? l.code : "RELAY_ERROR";
|
|
1151
|
+
this.#h(e, f);
|
|
1152
|
+
} finally {
|
|
1153
|
+
try {
|
|
1154
|
+
s.abort();
|
|
1155
|
+
} catch {
|
|
1156
|
+
}
|
|
1157
|
+
this.#D(e, s);
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
#W(e, t) {
|
|
1161
|
+
if (!this.#c(e)) return;
|
|
1162
|
+
let n = null;
|
|
1163
|
+
(e.adapter.kind === "connect" || e.adapter.kind === "account" && t.event === "connected") && (n = this.#K(t)), e.active = !1, this.#o = null, this.#I(e);
|
|
1164
|
+
let i = t;
|
|
1165
|
+
e.adapter.kind === "connect" ? (this.#B(n), i = S(t.identity)) : e.adapter.kind === "account" ? (t.event === "connected" ? this.#B(n) : (this.#f(), this.#n({ identity: null, status: "dormant" })), i = void 0) : this.#z(e, void 0), e.resolve(i), this.#a(e);
|
|
1166
|
+
}
|
|
1167
|
+
#h(e, t, n = !0) {
|
|
1168
|
+
this.#c(e) && this.#_(e, t, !0, n);
|
|
1169
|
+
}
|
|
1170
|
+
#_(e, t, n, i = !0) {
|
|
1171
|
+
if (!e.active) return e.cleanup.promise;
|
|
1172
|
+
const o = this.#m;
|
|
1173
|
+
e.active = !1, this.#o === e && (this.#o = null), this.#w += 1, this.#I(e);
|
|
1174
|
+
for (const l of e.controllers)
|
|
1175
|
+
e.phase !== "registering" && l.abort();
|
|
1176
|
+
const s = this.#t(o), u = s ?? c(t);
|
|
1177
|
+
return e.reject(u), n && !s && this.#Y(e, u, e.priorConnection, e.adapter.kind), this.#r ? (e.challenge && e.verifier && this.#F(e), this.#a(e), e.cleanup.promise) : (!i || e.registrationOutcome === "definitive-failure" || e.registrationOutcome === "not-started" ? this.#a(e) : e.phase === "hashing" ? (e.registrationOutcome = "not-started", this.#a(e)) : e.phase === "registering" && e.registrationOutcome === "none" ? this.#j(e) : (this.#j(e), this.#A(e)), e.cleanup.promise);
|
|
1178
|
+
}
|
|
1179
|
+
#Y(e, t, n, i) {
|
|
1180
|
+
if (n?.expiresAtMs > this.#i()) {
|
|
1181
|
+
this.#s = n, this.#n({
|
|
1182
|
+
connectionExpiresAt: n.expiresAt,
|
|
1183
|
+
error: I(t),
|
|
1184
|
+
identity: n.identity,
|
|
1185
|
+
status: "connected"
|
|
1186
|
+
});
|
|
1187
|
+
return;
|
|
1188
|
+
}
|
|
1189
|
+
this.#f(), this.#n({
|
|
1190
|
+
error: I(t),
|
|
1191
|
+
identity: null,
|
|
1192
|
+
status: "error"
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
#K(e) {
|
|
1196
|
+
const t = M(e.connectionExpiresAt), n = this.#i();
|
|
1197
|
+
if (t <= n || t - n > ct)
|
|
1198
|
+
throw c("RELAY_ERROR");
|
|
1199
|
+
return {
|
|
1200
|
+
expiresAt: e.connectionExpiresAt,
|
|
1201
|
+
expiresAtMs: t,
|
|
1202
|
+
identity: S(e.identity)
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
#B(e) {
|
|
1206
|
+
const t = this.#i();
|
|
1207
|
+
this.#f(), this.#s = e;
|
|
1208
|
+
const n = this.#s;
|
|
1209
|
+
this.#O = this.#g(() => {
|
|
1210
|
+
this.#s === n && (this.#s = null, this.#O = null, this.#o ? this.#n({ identity: null, status: "opening" }) : this.#n({ identity: null, status: "dormant" }));
|
|
1211
|
+
}, Math.max(0, e.expiresAtMs - t)), this.#n({
|
|
1212
|
+
connectionExpiresAt: e.expiresAt,
|
|
1213
|
+
identity: this.#s.identity,
|
|
1214
|
+
status: "connected"
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1217
|
+
#z(e, t) {
|
|
1218
|
+
const n = e.priorConnection;
|
|
1219
|
+
n?.expiresAtMs > this.#i() ? (this.#s = n, this.#n({
|
|
1220
|
+
connectionExpiresAt: n.expiresAt,
|
|
1221
|
+
...t ? { error: I(t) } : {},
|
|
1222
|
+
identity: n.identity,
|
|
1223
|
+
status: "connected"
|
|
1224
|
+
})) : t ? (this.#f(), this.#n({ error: I(t), identity: null, status: "error" })) : (this.#f(), this.#n({ identity: null, status: "dormant" }));
|
|
1225
|
+
}
|
|
1226
|
+
#U() {
|
|
1227
|
+
!this.#s || this.#s.expiresAtMs > this.#i() || (this.#f(), this.#o ? this.#n({ identity: null, status: "opening" }) : this.#n({ identity: null, status: "dormant" }));
|
|
1228
|
+
}
|
|
1229
|
+
#f() {
|
|
1230
|
+
this.#s = null, this.#d(this.#O), this.#O = null;
|
|
1231
|
+
}
|
|
1232
|
+
#n(e) {
|
|
1233
|
+
const t = S(e);
|
|
1234
|
+
if (this.#M = t, this.#x.push(t), !this.#C) {
|
|
1235
|
+
this.#C = !0;
|
|
1236
|
+
try {
|
|
1237
|
+
for (; this.#x.length !== 0; ) {
|
|
1238
|
+
const n = this.#x.shift();
|
|
1239
|
+
for (const i of [...this.#v])
|
|
1240
|
+
try {
|
|
1241
|
+
i(ie(n));
|
|
1242
|
+
} catch {
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
} finally {
|
|
1246
|
+
this.#C = !1;
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
#c(e) {
|
|
1251
|
+
return !this.#r && e.active && this.#o === e && e.generation === this.#w;
|
|
1252
|
+
}
|
|
1253
|
+
#t(e) {
|
|
1254
|
+
return this.#r ? c("DESTROYED") : e !== this.#m ? c("REPLACED") : null;
|
|
1255
|
+
}
|
|
1256
|
+
#i() {
|
|
1257
|
+
return this.#e.now();
|
|
1258
|
+
}
|
|
1259
|
+
#P(e) {
|
|
1260
|
+
const t = new this.#e.AbortController();
|
|
1261
|
+
return e.controllers.add(t), this.#E.add(t), t;
|
|
1262
|
+
}
|
|
1263
|
+
#D(e, t) {
|
|
1264
|
+
e.controllers.delete(t), this.#E.delete(t);
|
|
1265
|
+
}
|
|
1266
|
+
#g(e, t) {
|
|
1267
|
+
let n;
|
|
1268
|
+
return n = this.#e.setTimeout(() => {
|
|
1269
|
+
this.#R.delete(n), e();
|
|
1270
|
+
}, Math.max(0, t)), this.#R.add(n), n;
|
|
1271
|
+
}
|
|
1272
|
+
#H(e, t) {
|
|
1273
|
+
const n = this.#e.setInterval(e, t);
|
|
1274
|
+
return this.#R.add(n), n;
|
|
1275
|
+
}
|
|
1276
|
+
#d(e, t = !1) {
|
|
1277
|
+
e != null && (t ? this.#e.clearInterval(e) : this.#e.clearTimeout(e), this.#R.delete(e));
|
|
1278
|
+
}
|
|
1279
|
+
#I(e) {
|
|
1280
|
+
this.#d(e.expiryTimer), this.#d(e.pollTimer, !0), e.expiryTimer = null, e.pollTimer = null;
|
|
1281
|
+
}
|
|
1282
|
+
#j(e) {
|
|
1283
|
+
if (!(e.cleanupFinished || this.#y.has(e)))
|
|
1284
|
+
for (this.#y.add(e); this.#y.size > lt; ) {
|
|
1285
|
+
const t = this.#y.values().next().value;
|
|
1286
|
+
for (const n of t.controllers) n.abort();
|
|
1287
|
+
this.#a(t);
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
async #A(e) {
|
|
1291
|
+
if (e.cleanupFinished || e.cleanupStarted || this.#r)
|
|
1292
|
+
return e.cleanup.promise;
|
|
1293
|
+
e.cleanupStarted = !0, this.#j(e);
|
|
1294
|
+
let t = 100, n = !0;
|
|
1295
|
+
for (; !this.#r && !e.cleanupFinished && (n || this.#i() <= e.registrationDeadlineMs); ) {
|
|
1296
|
+
n = !1;
|
|
1297
|
+
const i = await this.#F(e);
|
|
1298
|
+
if (e.cleanupFinished) return e.cleanup.promise;
|
|
1299
|
+
if (i === "done")
|
|
1300
|
+
return this.#a(e), e.cleanup.promise;
|
|
1301
|
+
const o = e.registrationDeadlineMs - this.#i();
|
|
1302
|
+
if (o <= 0) break;
|
|
1303
|
+
await new Promise((s) => {
|
|
1304
|
+
e.retryResolve = s, e.retryTimer = this.#g(() => {
|
|
1305
|
+
e.retryResolve = null, s();
|
|
1306
|
+
}, Math.min(t, o));
|
|
1307
|
+
}), e.retryResolve = null, e.retryTimer = null, t = Math.min(t * 2, 4e3);
|
|
1308
|
+
}
|
|
1309
|
+
return this.#a(e), e.cleanup.promise;
|
|
1310
|
+
}
|
|
1311
|
+
async #F(e) {
|
|
1312
|
+
if (!e.verifier || !e.challenge) return "done";
|
|
1313
|
+
const t = this.#P(e), n = e.registrationDeadlineMs - this.#i(), i = n > 0 ? Math.min(4e3, n) : 1e3, o = this.#g(() => t.abort(), Math.max(1, i));
|
|
1314
|
+
let s = null;
|
|
1315
|
+
try {
|
|
1316
|
+
const u = this.#e.fetch(
|
|
1317
|
+
`${_}/relay/v1/transactions/${e.transactionId}/cancel`,
|
|
1318
|
+
k({
|
|
1319
|
+
codeVerifier: e.verifier,
|
|
1320
|
+
schemaVersion: 1,
|
|
1321
|
+
state: e.state,
|
|
1322
|
+
transactionId: e.transactionId
|
|
1323
|
+
}, t.signal)
|
|
1324
|
+
);
|
|
1325
|
+
s = await Y(
|
|
1326
|
+
u,
|
|
1327
|
+
t.signal,
|
|
1328
|
+
x
|
|
1329
|
+
);
|
|
1330
|
+
const l = s.status;
|
|
1331
|
+
return L(t, s), s = null, l === 204 || l === 400 || l === 403 || l === 409 || l === 410 ? "done" : "retry";
|
|
1332
|
+
} catch {
|
|
1333
|
+
return s && L(t, s), "retry";
|
|
1334
|
+
} finally {
|
|
1335
|
+
try {
|
|
1336
|
+
t.abort();
|
|
1337
|
+
} catch {
|
|
1338
|
+
}
|
|
1339
|
+
this.#d(o), this.#D(e, t);
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
#X(e) {
|
|
1343
|
+
let t;
|
|
1344
|
+
try {
|
|
1345
|
+
t = this.#e.fetch(
|
|
1346
|
+
`${_}/relay/v1/transactions/${e.transactionId}/cancel`,
|
|
1347
|
+
{
|
|
1348
|
+
...k({
|
|
1349
|
+
codeVerifier: e.verifier,
|
|
1350
|
+
schemaVersion: 1,
|
|
1351
|
+
state: e.state,
|
|
1352
|
+
transactionId: e.transactionId
|
|
1353
|
+
}),
|
|
1354
|
+
// Let the browser finish the tiny revocation after local teardown or unload.
|
|
1355
|
+
keepalive: !0
|
|
1356
|
+
}
|
|
1357
|
+
);
|
|
1358
|
+
} catch {
|
|
1359
|
+
return;
|
|
1360
|
+
}
|
|
1361
|
+
X(Promise.resolve(t).then(x));
|
|
1362
|
+
}
|
|
1363
|
+
#a(e) {
|
|
1364
|
+
if (!e.cleanupFinished) {
|
|
1365
|
+
e.cleanupFinished = !0, this.#d(e.retryTimer), e.retryResolve?.(), e.retryResolve = null, e.retryTimer = null, this.#d(e.operationTimer), e.operationTimer = null, this.#I(e);
|
|
1366
|
+
for (const t of e.controllers)
|
|
1367
|
+
t.abort(), this.#E.delete(t);
|
|
1368
|
+
e.controllers.clear(), this.#y.delete(e), e.adapter = null, e.challenge = null, e.priorConnection = null, e.request = null, e.state = null, e.transactionExpiresAtMs = null, e.transactionId = null, e.verifier = null, e.cleanup.resolve();
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
#Q() {
|
|
1372
|
+
if (!(this.#$ || this.#r)) {
|
|
1373
|
+
this.#$ = !0, this.#T = !0;
|
|
1374
|
+
try {
|
|
1375
|
+
let e = null;
|
|
1376
|
+
try {
|
|
1377
|
+
const o = this.#e.getStorage;
|
|
1378
|
+
e = typeof o == "function" ? Reflect.apply(o, void 0, []) : this.#e.storage ?? null;
|
|
1379
|
+
} catch {
|
|
1380
|
+
e = null, this.#l = !0;
|
|
1381
|
+
}
|
|
1382
|
+
try {
|
|
1383
|
+
(!e || typeof e.getItem != "function" || typeof e.removeItem != "function") && (this.#l = !0);
|
|
1384
|
+
} catch {
|
|
1385
|
+
this.#l = !0;
|
|
1386
|
+
}
|
|
1387
|
+
if (this.#r || this.#l) {
|
|
1388
|
+
this.#u = null;
|
|
1389
|
+
return;
|
|
1390
|
+
}
|
|
1391
|
+
if (this.#u = e, this.#Z(), this.#r || this.#l) {
|
|
1392
|
+
this.#u = null;
|
|
1393
|
+
return;
|
|
1394
|
+
}
|
|
1395
|
+
const t = (o) => {
|
|
1396
|
+
const s = this.#o;
|
|
1397
|
+
if (!s || !this.#c(s)) return;
|
|
1398
|
+
const u = `${j}${s.state}`;
|
|
1399
|
+
o?.key === u && this.#N(s, !0);
|
|
1400
|
+
};
|
|
1401
|
+
this.#L = t;
|
|
1402
|
+
let n = !1, i = null;
|
|
1403
|
+
try {
|
|
1404
|
+
const o = this.#p?.addEventListener, s = this.#p?.removeEventListener;
|
|
1405
|
+
if (typeof o != "function" || typeof s != "function")
|
|
1406
|
+
throw new TypeError("storage events unavailable");
|
|
1407
|
+
i = () => Reflect.apply(
|
|
1408
|
+
s,
|
|
1409
|
+
this.#p,
|
|
1410
|
+
["storage", t]
|
|
1411
|
+
), this.#b = i, Reflect.apply(o, this.#p, ["storage", this.#L]), n = !0;
|
|
1412
|
+
} catch {
|
|
1413
|
+
this.#l = !0;
|
|
1414
|
+
}
|
|
1415
|
+
if (!n || this.#r || this.#l) {
|
|
1416
|
+
try {
|
|
1417
|
+
i?.();
|
|
1418
|
+
} catch {
|
|
1419
|
+
}
|
|
1420
|
+
this.#L = null, this.#b = null, this.#u = null;
|
|
1421
|
+
}
|
|
1422
|
+
} finally {
|
|
1423
|
+
this.#T = !1;
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
#Z() {
|
|
1428
|
+
const e = this.#u;
|
|
1429
|
+
if (!e) return;
|
|
1430
|
+
let t;
|
|
1431
|
+
try {
|
|
1432
|
+
t = e.length;
|
|
1433
|
+
} catch {
|
|
1434
|
+
return;
|
|
1435
|
+
}
|
|
1436
|
+
if (!Number.isSafeInteger(t) || t < 0) return;
|
|
1437
|
+
const n = Math.min(t, ut), i = [];
|
|
1438
|
+
for (let o = 0; o < n && !this.#r && !this.#l; o += 1) {
|
|
1439
|
+
let s;
|
|
1440
|
+
try {
|
|
1441
|
+
s = e.key(o);
|
|
1442
|
+
} catch {
|
|
1443
|
+
continue;
|
|
1444
|
+
}
|
|
1445
|
+
i.push(s);
|
|
1446
|
+
}
|
|
1447
|
+
for (const o of i) {
|
|
1448
|
+
if (this.#r || this.#l) return;
|
|
1449
|
+
if (typeof o != "string" || !o.startsWith(j)) continue;
|
|
1450
|
+
const s = o.slice(j.length);
|
|
1451
|
+
if (T.test(s))
|
|
1452
|
+
try {
|
|
1453
|
+
const u = e.getItem(o);
|
|
1454
|
+
if (u === null) continue;
|
|
1455
|
+
const l = $(
|
|
1456
|
+
V(u, 2048),
|
|
1457
|
+
["code", "expiresAt", "schemaVersion", "state"],
|
|
1458
|
+
"CALLBACK_ERROR"
|
|
1459
|
+
);
|
|
1460
|
+
if (l.schemaVersion !== 1 || l.state !== s || !T.test(l.code))
|
|
1461
|
+
continue;
|
|
1462
|
+
M(l.expiresAt, "CALLBACK_ERROR") <= this.#i() && e.removeItem(o);
|
|
1463
|
+
} catch {
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
function Et(r) {
|
|
1469
|
+
return new At(r);
|
|
1470
|
+
}
|
|
1471
|
+
function bt(r, e = {}) {
|
|
1472
|
+
const t = (i, o) => i !== 0 ? Promise.reject(c("INVALID_REQUEST")) : o(), n = {
|
|
1473
|
+
connect(...i) {
|
|
1474
|
+
return t(i.length, () => r.execute("connect", void 0));
|
|
1475
|
+
},
|
|
1476
|
+
destroy(...i) {
|
|
1477
|
+
return t(i.length, () => r.destroy());
|
|
1478
|
+
},
|
|
1479
|
+
disconnect(...i) {
|
|
1480
|
+
return t(i.length, () => r.disconnect());
|
|
1481
|
+
},
|
|
1482
|
+
getSnapshot(...i) {
|
|
1483
|
+
if (i.length !== 0) throw c("INVALID_REQUEST");
|
|
1484
|
+
return r.getSnapshot();
|
|
1485
|
+
},
|
|
1486
|
+
openAccount(...i) {
|
|
1487
|
+
return t(i.length, () => r.execute("account", void 0));
|
|
1488
|
+
},
|
|
1489
|
+
subscribe(i, ...o) {
|
|
1490
|
+
if (o.length !== 0) throw c("INVALID_REQUEST");
|
|
1491
|
+
return r.subscribe(i);
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1494
|
+
for (const [i, o] of Object.entries(e))
|
|
1495
|
+
n[i] = function(u, ...l) {
|
|
1496
|
+
return l.length !== 0 ? Promise.reject(c("INVALID_REQUEST")) : r.execute(o, u);
|
|
1497
|
+
};
|
|
1498
|
+
return Object.freeze(n);
|
|
1499
|
+
}
|
|
1500
|
+
const gt = Object.freeze({
|
|
1501
|
+
account: Object.freeze({
|
|
1502
|
+
buildRequest: () => Qe({}),
|
|
1503
|
+
kind: "account",
|
|
1504
|
+
operation: "sdn.wallet.account.v1",
|
|
1505
|
+
parseResult: Ze
|
|
1506
|
+
}),
|
|
1507
|
+
connect: Object.freeze({
|
|
1508
|
+
buildRequest: () => He({}),
|
|
1509
|
+
kind: "connect",
|
|
1510
|
+
operation: "sdn.wallet.connect.v1",
|
|
1511
|
+
parseResult: Xe
|
|
1512
|
+
})
|
|
1513
|
+
}), Ot = Object.freeze({
|
|
1514
|
+
...gt,
|
|
1515
|
+
sdnLoginV1: Object.freeze({
|
|
1516
|
+
buildRequest: Ge,
|
|
1517
|
+
kind: "typed",
|
|
1518
|
+
operation: "sdn.auth.raw-challenge.v1",
|
|
1519
|
+
parseResult: et
|
|
1520
|
+
}),
|
|
1521
|
+
sdnLoginV2: Object.freeze({
|
|
1522
|
+
buildRequest: tt,
|
|
1523
|
+
kind: "typed",
|
|
1524
|
+
operation: "sdn.auth.jcs-envelope.v2",
|
|
1525
|
+
parseResult: rt
|
|
1526
|
+
})
|
|
1527
|
+
});
|
|
1528
|
+
function St() {
|
|
1529
|
+
if (arguments.length !== 0) throw c("INVALID_REQUEST");
|
|
1530
|
+
const r = Et({
|
|
1531
|
+
adapters: Ot,
|
|
1532
|
+
clientId: "sdn-node-console-v1"
|
|
1533
|
+
});
|
|
1534
|
+
return bt(r, {
|
|
1535
|
+
requestSdnLoginV1: "sdnLoginV1",
|
|
1536
|
+
requestSdnLoginV2: "sdnLoginV2"
|
|
1537
|
+
});
|
|
1538
|
+
}
|
|
1539
|
+
export {
|
|
1540
|
+
Ee as WALLET_CLIENT_ERRORS,
|
|
1541
|
+
St as createSdnWalletClient
|
|
1542
|
+
};
|