@cedros/login-react 0.0.1 → 0.0.2
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 +142 -2
- package/dist/AuthenticationSettings-CMQhep61.js +9 -0
- package/dist/AuthenticationSettings-CMQhep61.js.map +1 -0
- package/dist/AuthenticationSettings-Cro76kIC.cjs +1 -0
- package/dist/AuthenticationSettings-Cro76kIC.cjs.map +1 -0
- package/dist/CreditSystemSettings-AM7qDk1E.js +9 -0
- package/dist/CreditSystemSettings-AM7qDk1E.js.map +1 -0
- package/dist/CreditSystemSettings-CGR-uzuh.cjs +1 -0
- package/dist/CreditSystemSettings-CGR-uzuh.cjs.map +1 -0
- package/dist/DepositsSection-BVNd63B7.js +47 -0
- package/dist/DepositsSection-BVNd63B7.js.map +1 -0
- package/dist/DepositsSection-Ct1gjgIg.cjs +1 -0
- package/dist/DepositsSection-Ct1gjgIg.cjs.map +1 -0
- package/dist/EmailRegisterForm-B-ys4E3C.cjs +1 -0
- package/dist/EmailRegisterForm-B-ys4E3C.cjs.map +1 -0
- package/dist/EmailRegisterForm-BChCiZ5B.js +961 -0
- package/dist/EmailRegisterForm-BChCiZ5B.js.map +1 -0
- package/dist/EmailSettings-DFZ13JbX.cjs +1 -0
- package/dist/EmailSettings-DFZ13JbX.cjs.map +1 -0
- package/dist/EmailSettings-Di4GSWgb.js +9 -0
- package/dist/EmailSettings-Di4GSWgb.js.map +1 -0
- package/dist/EmbeddedWalletSettings-Cmn_aVL7.js +9 -0
- package/dist/EmbeddedWalletSettings-Cmn_aVL7.js.map +1 -0
- package/dist/EmbeddedWalletSettings-DRWeIJKb.cjs +1 -0
- package/dist/EmbeddedWalletSettings-DRWeIJKb.cjs.map +1 -0
- package/dist/{ErrorMessage-Bm1j5mBT.js → ErrorMessage-C8vKB0JG.js} +9 -9
- package/dist/ErrorMessage-C8vKB0JG.js.map +1 -0
- package/dist/ErrorMessage-CntMyn93.cjs.map +1 -1
- package/dist/{GoogleLoginButton-CvDoOc-0.js → GoogleLoginButton-Ceo2sYvX.js} +1 -1
- package/dist/{GoogleLoginButton-CvDoOc-0.js.map → GoogleLoginButton-Ceo2sYvX.js.map} +1 -1
- package/dist/ServerSettings-D8w8EpoE.cjs +1 -0
- package/dist/ServerSettings-D8w8EpoE.cjs.map +1 -0
- package/dist/ServerSettings-Wg_odW46.js +9 -0
- package/dist/ServerSettings-Wg_odW46.js.map +1 -0
- package/dist/{SolanaLoginButton-h32xN2PQ.js → SolanaLoginButton-CqVOcPa7.js} +1 -1
- package/dist/{SolanaLoginButton-h32xN2PQ.js.map → SolanaLoginButton-CqVOcPa7.js.map} +1 -1
- package/dist/TeamSection-Bj89WSC0.js +128 -0
- package/dist/TeamSection-Bj89WSC0.js.map +1 -0
- package/dist/TeamSection-DQ4nfUHN.cjs +1 -0
- package/dist/TeamSection-DQ4nfUHN.cjs.map +1 -0
- package/dist/UsersSection-BiZceDV3.cjs +1 -0
- package/dist/UsersSection-BiZceDV3.cjs.map +1 -0
- package/dist/UsersSection-W19ddPsw.js +81 -0
- package/dist/UsersSection-W19ddPsw.js.map +1 -0
- package/dist/WebhookSettings-a1c4iMvr.js +9 -0
- package/dist/WebhookSettings-a1c4iMvr.js.map +1 -0
- package/dist/WebhookSettings-onJWLytD.cjs +1 -0
- package/dist/WebhookSettings-onJWLytD.cjs.map +1 -0
- package/dist/WithdrawalsSection-BBw9gWMR.js +20 -0
- package/dist/WithdrawalsSection-BBw9gWMR.js.map +1 -0
- package/dist/WithdrawalsSection-Cws8inf6.cjs +1 -0
- package/dist/WithdrawalsSection-Cws8inf6.cjs.map +1 -0
- package/dist/admin/AdminShell.d.ts +38 -0
- package/dist/admin/icons.d.ts +2 -0
- package/dist/admin/index.d.ts +10 -0
- package/dist/admin/plugin.d.ts +3 -0
- package/dist/admin/sections/AuthenticationSettings.d.ts +3 -0
- package/dist/admin/sections/CreditSystemSettings.d.ts +3 -0
- package/dist/admin/sections/DepositsSection.d.ts +3 -0
- package/dist/admin/sections/EmailSettings.d.ts +3 -0
- package/dist/admin/sections/EmbeddedWalletSettings.d.ts +3 -0
- package/dist/admin/sections/FeatureSettings.d.ts +3 -0
- package/dist/admin/sections/InvitesSection.d.ts +3 -0
- package/dist/admin/sections/MembersSection.d.ts +3 -0
- package/dist/admin/sections/ServerSettings.d.ts +3 -0
- package/dist/admin/sections/SettingsSections.d.ts +7 -0
- package/dist/admin/sections/TeamSection.d.ts +3 -0
- package/dist/admin/sections/UsersSection.d.ts +3 -0
- package/dist/admin/sections/WebhookSettings.d.ts +3 -0
- package/dist/admin/sections/WithdrawalsSection.d.ts +3 -0
- package/dist/admin/types.d.ts +167 -0
- package/dist/components/admin/AdminUserDetail.d.ts +3 -1
- package/dist/components/admin/AdminUserList.d.ts +3 -7
- package/dist/components/admin/CedrosAdminDashboard.d.ts +7 -3
- package/dist/components/admin/PermissionsSection.d.ts +7 -0
- package/dist/components/admin/ProfileDropdown.d.ts +34 -0
- package/dist/components/admin/SetupWizard.d.ts +30 -0
- package/dist/components/admin/StatsBar.d.ts +17 -0
- package/dist/components/admin/settings/AuthenticationSettings.d.ts +4 -0
- package/dist/components/admin/settings/AutosaveStatus.d.ts +6 -0
- package/dist/components/admin/settings/CreditSystemSettings.d.ts +6 -0
- package/dist/components/admin/settings/EmailSettings.d.ts +4 -0
- package/dist/components/admin/settings/EmbeddedWalletSettings.d.ts +4 -0
- package/dist/components/admin/settings/FeatureSettings.d.ts +4 -0
- package/dist/components/admin/settings/MessagingSettings.d.ts +4 -0
- package/dist/components/admin/settings/SecuritySettings.d.ts +4 -0
- package/dist/components/admin/settings/ServerSettings.d.ts +4 -0
- package/dist/components/admin/settings/SettingsPageLayout.d.ts +16 -0
- package/dist/components/admin/settings/SsoProvidersSettings.d.ts +4 -0
- package/dist/components/admin/settings/WebhookSettings.d.ts +4 -0
- package/dist/components/admin/settings/index.d.ts +31 -0
- package/dist/components/admin/settings/settingsInputs.d.ts +79 -0
- package/dist/components/admin/settings/settingsMetadata.d.ts +18 -0
- package/dist/components/deposit/admin/AdminWithdrawalStats.d.ts +10 -0
- package/dist/components/deposit/admin/FeatureDisabledMessage.d.ts +15 -0
- package/dist/components/deposit/admin/featureDisabled.d.ts +9 -0
- package/dist/components/deposit/admin/index.d.ts +5 -0
- package/dist/components/invites/InviteForm.d.ts +1 -1
- package/dist/components/org/OrgSelector.d.ts +2 -1
- package/dist/components/profile/UserProfileSettings.d.ts +35 -0
- package/dist/components/profile/index.d.ts +2 -0
- package/dist/crypto/secureWipe.d.ts +0 -19
- package/dist/crypto/webauthnPrf.d.ts +0 -10
- package/dist/email-only.cjs +1 -1
- package/dist/email-only.js +2 -2
- package/dist/google-only.js +2 -2
- package/dist/hooks/useDashboardPermissions.d.ts +45 -0
- package/dist/hooks/useProfile.d.ts +35 -0
- package/dist/hooks/useServerFeatures.d.ts +55 -0
- package/dist/hooks/useSettingsAutosave.d.ts +29 -0
- package/dist/hooks/useSetup.d.ts +25 -0
- package/dist/hooks/useSsoProviders.d.ts +52 -0
- package/dist/index-BHR_WTP2.js +19636 -0
- package/dist/index-BHR_WTP2.js.map +1 -0
- package/dist/index-JsIJkPin.cjs +2061 -0
- package/dist/index-JsIJkPin.cjs.map +1 -0
- package/dist/index.cjs +1 -2061
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +21 -3
- package/dist/index.js +117 -14908
- package/dist/index.js.map +1 -1
- package/dist/login-react.css +1 -1
- package/dist/silentWalletEnroll-CQK5i65l.js +42 -0
- package/dist/silentWalletEnroll-CQK5i65l.js.map +1 -0
- package/dist/silentWalletEnroll-DBfS2sLe.cjs +1 -0
- package/dist/silentWalletEnroll-DBfS2sLe.cjs.map +1 -0
- package/dist/solana-only.js +2 -2
- package/dist/solanaKeypair-BD7Kq1Mw.js +1932 -0
- package/dist/solanaKeypair-BD7Kq1Mw.js.map +1 -0
- package/dist/solanaKeypair-CBQxm2hw.cjs +1 -0
- package/dist/solanaKeypair-CBQxm2hw.cjs.map +1 -0
- package/dist/types/adminUser.d.ts +56 -0
- package/dist/types/deposit.d.ts +2 -0
- package/dist/types/index.d.ts +4 -2
- package/dist/types/org.d.ts +34 -2
- package/dist/types/profile.d.ts +56 -0
- package/dist/types/setup.d.ts +45 -0
- package/dist/types/systemSettings.d.ts +5 -1
- package/dist/utils/adminUserApi.d.ts +10 -1
- package/dist/utils/profileApi.d.ts +26 -0
- package/dist/utils/setupApi.d.ts +21 -0
- package/package.json +1 -1
- package/dist/EmailRegisterForm-D_uCEdX9.cjs +0 -1
- package/dist/EmailRegisterForm-D_uCEdX9.cjs.map +0 -1
- package/dist/EmailRegisterForm-m3rX3A6X.js +0 -2923
- package/dist/EmailRegisterForm-m3rX3A6X.js.map +0 -1
- package/dist/ErrorMessage-Bm1j5mBT.js.map +0 -1
|
@@ -0,0 +1,1932 @@
|
|
|
1
|
+
import { D as Be, e as Se, f as ht, i as ve, j as te } from "./ErrorMessage-C8vKB0JG.js";
|
|
2
|
+
let P = null, Ae = 0;
|
|
3
|
+
const et = /* @__PURE__ */ new Map();
|
|
4
|
+
function Re() {
|
|
5
|
+
return typeof Worker > "u" ? null : (P || (P = new Worker(new URL(
|
|
6
|
+
/* @vite-ignore */
|
|
7
|
+
"" + new URL("assets/argon2Worker-Bi5TuQvD.js", import.meta.url).href,
|
|
8
|
+
import.meta.url
|
|
9
|
+
), {
|
|
10
|
+
type: "module"
|
|
11
|
+
}), P.onmessage = (e) => {
|
|
12
|
+
const { id: t, key: n, error: o } = e.data, r = et.get(t);
|
|
13
|
+
if (r) {
|
|
14
|
+
if (et.delete(t), o) {
|
|
15
|
+
r.reject(new Error(o));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (!n) {
|
|
19
|
+
r.reject(new Error("Argon2 worker returned no key"));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
r.resolve(n);
|
|
23
|
+
}
|
|
24
|
+
}, P.onerror = (e) => {
|
|
25
|
+
const t = e instanceof ErrorEvent ? e.error : new Error("Argon2 worker error");
|
|
26
|
+
for (const n of et.values())
|
|
27
|
+
n.reject(t instanceof Error ? t : new Error(String(t)));
|
|
28
|
+
et.clear(), P?.terminate(), P = null;
|
|
29
|
+
}), P);
|
|
30
|
+
}
|
|
31
|
+
async function rr(e, t, n = Be) {
|
|
32
|
+
const o = Re();
|
|
33
|
+
return o ? new Promise((r, s) => {
|
|
34
|
+
const a = Ae++;
|
|
35
|
+
et.set(a, { resolve: r, reject: s });
|
|
36
|
+
const u = {
|
|
37
|
+
id: a,
|
|
38
|
+
password: e,
|
|
39
|
+
salt: t,
|
|
40
|
+
params: n
|
|
41
|
+
};
|
|
42
|
+
o.postMessage(u);
|
|
43
|
+
}) : Se(e, t, n);
|
|
44
|
+
}
|
|
45
|
+
function Ie(e) {
|
|
46
|
+
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
47
|
+
}
|
|
48
|
+
function _e(e) {
|
|
49
|
+
if (Object.prototype.hasOwnProperty.call(e, "__esModule")) return e;
|
|
50
|
+
var t = e.default;
|
|
51
|
+
if (typeof t == "function") {
|
|
52
|
+
var n = function o() {
|
|
53
|
+
var r = !1;
|
|
54
|
+
try {
|
|
55
|
+
r = this instanceof o;
|
|
56
|
+
} catch {
|
|
57
|
+
}
|
|
58
|
+
return r ? Reflect.construct(t, arguments, this.constructor) : t.apply(this, arguments);
|
|
59
|
+
};
|
|
60
|
+
n.prototype = t.prototype;
|
|
61
|
+
} else n = {};
|
|
62
|
+
return Object.defineProperty(n, "__esModule", { value: !0 }), Object.keys(e).forEach(function(o) {
|
|
63
|
+
var r = Object.getOwnPropertyDescriptor(e, o);
|
|
64
|
+
Object.defineProperty(n, o, r.get ? r : {
|
|
65
|
+
enumerable: !0,
|
|
66
|
+
get: function() {
|
|
67
|
+
return e[o];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}), n;
|
|
71
|
+
}
|
|
72
|
+
var it = { exports: {} };
|
|
73
|
+
const Ne = globalThis.crypto, Oe = globalThis.crypto, Te = globalThis.crypto.subtle, Ce = globalThis.crypto.getRandomValues.bind(globalThis.crypto), Le = globalThis.crypto.randomUUID.bind(globalThis.crypto), Ue = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
74
|
+
__proto__: null,
|
|
75
|
+
default: Ne,
|
|
76
|
+
getRandomValues: Ce,
|
|
77
|
+
randomUUID: Le,
|
|
78
|
+
subtle: Te,
|
|
79
|
+
webcrypto: Oe
|
|
80
|
+
}, Symbol.toStringTag, { value: "Module" })), He = /* @__PURE__ */ _e(Ue);
|
|
81
|
+
var De = it.exports, Ut;
|
|
82
|
+
function qe() {
|
|
83
|
+
return Ut || (Ut = 1, (function(e, t) {
|
|
84
|
+
(function(n, o) {
|
|
85
|
+
e.exports = o(He);
|
|
86
|
+
})(De, function(n) {
|
|
87
|
+
var o, r, s, a, u;
|
|
88
|
+
function i() {
|
|
89
|
+
o = {
|
|
90
|
+
bits: 8,
|
|
91
|
+
// default number of bits
|
|
92
|
+
radix: 16,
|
|
93
|
+
// work with HEX by default
|
|
94
|
+
minBits: 3,
|
|
95
|
+
maxBits: 20,
|
|
96
|
+
// this permits 1,048,575 shares, though going this high is NOT recommended in JS!
|
|
97
|
+
bytesPerChar: 2,
|
|
98
|
+
maxBytesPerChar: 6,
|
|
99
|
+
// Math.pow(256,7) > Math.pow(2,53)
|
|
100
|
+
// Primitive polynomials (in decimal form) for Galois Fields GF(2^n), for 2 <= n <= 30
|
|
101
|
+
// The index of each term in the array corresponds to the n for that polynomial
|
|
102
|
+
// i.e. to get the polynomial for n=16, use primitivePolynomials[16]
|
|
103
|
+
primitivePolynomials: [
|
|
104
|
+
null,
|
|
105
|
+
null,
|
|
106
|
+
1,
|
|
107
|
+
3,
|
|
108
|
+
3,
|
|
109
|
+
5,
|
|
110
|
+
3,
|
|
111
|
+
3,
|
|
112
|
+
29,
|
|
113
|
+
17,
|
|
114
|
+
9,
|
|
115
|
+
5,
|
|
116
|
+
83,
|
|
117
|
+
27,
|
|
118
|
+
43,
|
|
119
|
+
3,
|
|
120
|
+
45,
|
|
121
|
+
9,
|
|
122
|
+
39,
|
|
123
|
+
39,
|
|
124
|
+
9,
|
|
125
|
+
5,
|
|
126
|
+
3,
|
|
127
|
+
33,
|
|
128
|
+
27,
|
|
129
|
+
9,
|
|
130
|
+
71,
|
|
131
|
+
39,
|
|
132
|
+
9,
|
|
133
|
+
5,
|
|
134
|
+
83
|
|
135
|
+
]
|
|
136
|
+
}, r = {}, s = new Array(1024).join("0"), a = !0, u = [
|
|
137
|
+
"nodeCryptoRandomBytes",
|
|
138
|
+
"browserCryptoGetRandomValues",
|
|
139
|
+
"testRandom"
|
|
140
|
+
];
|
|
141
|
+
}
|
|
142
|
+
function x() {
|
|
143
|
+
return !!(r && r.rng && typeof r.rng == "function");
|
|
144
|
+
}
|
|
145
|
+
function y(f, h) {
|
|
146
|
+
var c;
|
|
147
|
+
if (h === 0 || h === 1)
|
|
148
|
+
return f;
|
|
149
|
+
if (h && h > 1024)
|
|
150
|
+
throw new Error(
|
|
151
|
+
"Padding must be multiples of no larger than 1024 bits."
|
|
152
|
+
);
|
|
153
|
+
return h = h || r.bits, f && (c = f.length % h), c ? (s + f).slice(
|
|
154
|
+
-(h - c + f.length)
|
|
155
|
+
) : f;
|
|
156
|
+
}
|
|
157
|
+
function w(f) {
|
|
158
|
+
var h = "", c, l;
|
|
159
|
+
for (l = f.length - 1; l >= 0; l--) {
|
|
160
|
+
if (c = parseInt(f[l], 16), isNaN(c))
|
|
161
|
+
throw new Error("Invalid hex character.");
|
|
162
|
+
h = y(c.toString(2), 4) + h;
|
|
163
|
+
}
|
|
164
|
+
return h;
|
|
165
|
+
}
|
|
166
|
+
function S(f) {
|
|
167
|
+
var h = "", c, l;
|
|
168
|
+
for (f = y(f, 4), l = f.length; l >= 4; l -= 4) {
|
|
169
|
+
if (c = parseInt(f.slice(l - 4, l), 2), isNaN(c))
|
|
170
|
+
throw new Error("Invalid binary character.");
|
|
171
|
+
h = c.toString(16) + h;
|
|
172
|
+
}
|
|
173
|
+
return h;
|
|
174
|
+
}
|
|
175
|
+
function I() {
|
|
176
|
+
return !!(n && typeof n == "object" && (typeof n.getRandomValues == "function" || typeof n.getRandomValues == "object") && (typeof Uint32Array == "function" || typeof Uint32Array == "object"));
|
|
177
|
+
}
|
|
178
|
+
function v() {
|
|
179
|
+
return typeof n == "object" && typeof n.randomBytes == "function";
|
|
180
|
+
}
|
|
181
|
+
function O(f) {
|
|
182
|
+
function h(b, g, m, B) {
|
|
183
|
+
var R = 0, C, L = "", q;
|
|
184
|
+
for (g && (C = g.length - 1); R < C || L.length < b; )
|
|
185
|
+
q = Math.abs(parseInt(g[R], m)), L = L + y(q.toString(2), B), R++;
|
|
186
|
+
return L = L.substr(-b), (L.match(/0/g) || []).length === L.length ? null : L;
|
|
187
|
+
}
|
|
188
|
+
function c(b) {
|
|
189
|
+
var g, m, B, R, C = null;
|
|
190
|
+
for (B = 16, R = 4, m = Math.ceil(b / 8); C === null; )
|
|
191
|
+
g = n.randomBytes(m), C = h(b, g.toString("hex"), B, R);
|
|
192
|
+
return C;
|
|
193
|
+
}
|
|
194
|
+
function l(b) {
|
|
195
|
+
var g, m, B, R = null;
|
|
196
|
+
for (m = 10, B = 32, g = Math.ceil(b / 32); R === null; )
|
|
197
|
+
R = h(
|
|
198
|
+
b,
|
|
199
|
+
n.getRandomValues(new Uint32Array(g)),
|
|
200
|
+
m,
|
|
201
|
+
B
|
|
202
|
+
);
|
|
203
|
+
return R;
|
|
204
|
+
}
|
|
205
|
+
function d(b) {
|
|
206
|
+
var g, m, B, R, C, L = null;
|
|
207
|
+
R = 10, C = 32, m = Math.ceil(b / 32), B = 123456789, g = new Uint32Array(m);
|
|
208
|
+
for (var q = 0; q < g.length; q++)
|
|
209
|
+
g[q] = B;
|
|
210
|
+
for (; L === null; )
|
|
211
|
+
L = h(b, g, R, C);
|
|
212
|
+
return L;
|
|
213
|
+
}
|
|
214
|
+
if (f && f === "testRandom")
|
|
215
|
+
return r.typeCSPRNG = f, d;
|
|
216
|
+
if (f && f === "nodeCryptoRandomBytes")
|
|
217
|
+
return r.typeCSPRNG = f, c;
|
|
218
|
+
if (f && f === "browserCryptoGetRandomValues")
|
|
219
|
+
return r.typeCSPRNG = f, l;
|
|
220
|
+
if (v())
|
|
221
|
+
return r.typeCSPRNG = "nodeCryptoRandomBytes", c;
|
|
222
|
+
if (I())
|
|
223
|
+
return r.typeCSPRNG = "browserCryptoGetRandomValues", l;
|
|
224
|
+
}
|
|
225
|
+
function _(f, h) {
|
|
226
|
+
var c = [], l;
|
|
227
|
+
for (h && (f = y(f, h)), l = f.length; l > r.bits; l -= r.bits)
|
|
228
|
+
c.push(parseInt(f.slice(l - r.bits, l), 2));
|
|
229
|
+
return c.push(parseInt(f.slice(0, l), 2)), c;
|
|
230
|
+
}
|
|
231
|
+
function E(f, h) {
|
|
232
|
+
var c = r.logs[f], l = 0, d;
|
|
233
|
+
for (d = h.length - 1; d >= 0; d--)
|
|
234
|
+
l !== 0 ? l = r.exps[(c + r.logs[l]) % r.maxShares] ^ h[d] : l = h[d];
|
|
235
|
+
return l;
|
|
236
|
+
}
|
|
237
|
+
function A(f, h, c) {
|
|
238
|
+
var l = 0, d, b, g, m;
|
|
239
|
+
for (g = 0, d = h.length; g < d; g++)
|
|
240
|
+
if (c[g]) {
|
|
241
|
+
for (b = r.logs[c[g]], m = 0; m < d; m++)
|
|
242
|
+
if (g !== m) {
|
|
243
|
+
if (f === h[m]) {
|
|
244
|
+
b = -1;
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
b = (b + r.logs[f ^ h[m]] - r.logs[h[g] ^ h[m]] + r.maxShares) % r.maxShares;
|
|
248
|
+
}
|
|
249
|
+
l = b === -1 ? l : l ^ r.exps[b];
|
|
250
|
+
}
|
|
251
|
+
return l;
|
|
252
|
+
}
|
|
253
|
+
function p(f, h, c) {
|
|
254
|
+
var l = [], d = [f], b, g;
|
|
255
|
+
for (b = 1; b < c; b++)
|
|
256
|
+
d[b] = parseInt(r.rng(r.bits), 2);
|
|
257
|
+
for (b = 1, g = h + 1; b < g; b++)
|
|
258
|
+
l[b - 1] = {
|
|
259
|
+
x: b,
|
|
260
|
+
y: E(b, d)
|
|
261
|
+
};
|
|
262
|
+
return l;
|
|
263
|
+
}
|
|
264
|
+
function N(f, h, c) {
|
|
265
|
+
var l, d, b, g, m;
|
|
266
|
+
if (h = parseInt(h, r.radix), f = parseInt(f, 10) || r.bits, l = f.toString(36).toUpperCase(), b = Math.pow(2, f) - 1, g = b.toString(r.radix).length, d = y(h.toString(r.radix), g), typeof h != "number" || h % 1 !== 0 || h < 1 || h > b)
|
|
267
|
+
throw new Error(
|
|
268
|
+
"Share id must be an integer between 1 and " + b + ", inclusive."
|
|
269
|
+
);
|
|
270
|
+
return m = l + d + c, m;
|
|
271
|
+
}
|
|
272
|
+
var T = {
|
|
273
|
+
init: function(f, h) {
|
|
274
|
+
var c = [], l = [], d = 1, b, g;
|
|
275
|
+
if (i(), f && (typeof f != "number" || f % 1 !== 0 || f < o.minBits || f > o.maxBits))
|
|
276
|
+
throw new Error(
|
|
277
|
+
"Number of bits must be an integer between " + o.minBits + " and " + o.maxBits + ", inclusive."
|
|
278
|
+
);
|
|
279
|
+
if (h && u.indexOf(h) === -1)
|
|
280
|
+
throw new Error("Invalid RNG type argument : '" + h + "'");
|
|
281
|
+
for (r.radix = o.radix, r.bits = f || o.bits, r.size = Math.pow(2, r.bits), r.maxShares = r.size - 1, b = o.primitivePolynomials[r.bits], g = 0; g < r.size; g++)
|
|
282
|
+
l[g] = d, c[d] = g, d = d << 1, d >= r.size && (d = d ^ b, d = d & r.maxShares);
|
|
283
|
+
if (r.logs = c, r.exps = l, h && this.setRNG(h), x() || this.setRNG(), !x() || !r.bits || !r.size || !r.maxShares || !r.logs || !r.exps || r.logs.length !== r.size || r.exps.length !== r.size)
|
|
284
|
+
throw new Error("Initialization failed.");
|
|
285
|
+
},
|
|
286
|
+
// Evaluates the Lagrange interpolation polynomial at x=`at` for
|
|
287
|
+
// individual config.bits-length segments of each share in the `shares`
|
|
288
|
+
// Array. Each share is expressed in base `inputRadix`. The output
|
|
289
|
+
// is expressed in base `outputRadix'.
|
|
290
|
+
combine: function(f, h) {
|
|
291
|
+
var c, l, d, b, g = "", m, B, R, C = [], L = [];
|
|
292
|
+
for (h = h || 0, c = 0, d = f.length; c < d; c++) {
|
|
293
|
+
if (B = this.extractShareComponents(f[c]), m === void 0)
|
|
294
|
+
m = B.bits;
|
|
295
|
+
else if (B.bits !== m)
|
|
296
|
+
throw new Error(
|
|
297
|
+
"Mismatched shares: Different bit settings."
|
|
298
|
+
);
|
|
299
|
+
if (r.bits !== m && this.init(m), C.indexOf(B.id) === -1)
|
|
300
|
+
for (C.push(B.id), R = _(w(B.data)), l = 0, b = R.length; l < b; l++)
|
|
301
|
+
L[l] = L[l] || [], L[l][C.length - 1] = R[l];
|
|
302
|
+
}
|
|
303
|
+
for (c = 0, d = L.length; c < d; c++)
|
|
304
|
+
g = y(A(h, C, L[c]).toString(2)) + g;
|
|
305
|
+
return S(
|
|
306
|
+
h >= 1 ? g : g.slice(g.indexOf("1") + 1)
|
|
307
|
+
);
|
|
308
|
+
},
|
|
309
|
+
getConfig: function() {
|
|
310
|
+
var f = {};
|
|
311
|
+
return f.radix = r.radix, f.bits = r.bits, f.maxShares = r.maxShares, f.hasCSPRNG = x(), f.typeCSPRNG = r.typeCSPRNG, f;
|
|
312
|
+
},
|
|
313
|
+
// Given a public share, extract the bits (Integer), share ID (Integer), and share data (Hex)
|
|
314
|
+
// and return an Object containing those components.
|
|
315
|
+
extractShareComponents: function(f) {
|
|
316
|
+
var h, c, l, d, b = {}, g, m;
|
|
317
|
+
if (h = parseInt(f.substr(0, 1), 36), h && (typeof h != "number" || h % 1 !== 0 || h < o.minBits || h > o.maxBits))
|
|
318
|
+
throw new Error(
|
|
319
|
+
"Invalid share : Number of bits must be an integer between " + o.minBits + " and " + o.maxBits + ", inclusive."
|
|
320
|
+
);
|
|
321
|
+
if (d = Math.pow(2, h) - 1, l = (Math.pow(2, h) - 1).toString(r.radix).length, g = "^([a-kA-K3-9]{1})([a-fA-F0-9]{" + l + "})([a-fA-F0-9]+)$", m = new RegExp(g).exec(f), m && (c = parseInt(m[2], r.radix)), typeof c != "number" || c % 1 !== 0 || c < 1 || c > d)
|
|
322
|
+
throw new Error(
|
|
323
|
+
"Invalid share : Share id must be an integer between 1 and " + r.maxShares + ", inclusive."
|
|
324
|
+
);
|
|
325
|
+
if (m && m[3])
|
|
326
|
+
return b.bits = h, b.id = c, b.data = m[3], b;
|
|
327
|
+
throw new Error("The share data provided is invalid : " + f);
|
|
328
|
+
},
|
|
329
|
+
// Set the PRNG to use. If no RNG function is supplied, pick a default using getRNG()
|
|
330
|
+
setRNG: function(f) {
|
|
331
|
+
var h = "Random number generator is invalid ", c = " Supply an CSPRNG of the form function(bits){} that returns a string containing 'bits' number of random 1's and 0's.";
|
|
332
|
+
if (f && typeof f == "string" && u.indexOf(f) === -1)
|
|
333
|
+
throw new Error("Invalid RNG type argument : '" + f + "'");
|
|
334
|
+
if (f || (f = O()), f && typeof f == "string" && (f = O(f)), a) {
|
|
335
|
+
if (f && typeof f != "function")
|
|
336
|
+
throw new Error(h + "(Not a function)." + c);
|
|
337
|
+
if (f && typeof f(r.bits) != "string")
|
|
338
|
+
throw new Error(
|
|
339
|
+
h + "(Output is not a string)." + c
|
|
340
|
+
);
|
|
341
|
+
if (f && !parseInt(f(r.bits), 2))
|
|
342
|
+
throw new Error(
|
|
343
|
+
h + "(Binary string output not parseable to an Integer)." + c
|
|
344
|
+
);
|
|
345
|
+
if (f && f(r.bits).length > r.bits)
|
|
346
|
+
throw new Error(
|
|
347
|
+
h + "(Output length is greater than config.bits)." + c
|
|
348
|
+
);
|
|
349
|
+
if (f && f(r.bits).length < r.bits)
|
|
350
|
+
throw new Error(
|
|
351
|
+
h + "(Output length is less than config.bits)." + c
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
return r.rng = f, !0;
|
|
355
|
+
},
|
|
356
|
+
// Converts a given UTF16 character string to the HEX representation.
|
|
357
|
+
// Each character of the input string is represented by
|
|
358
|
+
// `bytesPerChar` bytes in the output string which defaults to 2.
|
|
359
|
+
str2hex: function(f, h) {
|
|
360
|
+
var c, l, d = "", b, g, m, B;
|
|
361
|
+
if (typeof f != "string")
|
|
362
|
+
throw new Error("Input must be a character string.");
|
|
363
|
+
if (h || (h = o.bytesPerChar), typeof h != "number" || h < 1 || h > o.maxBytesPerChar || h % 1 !== 0)
|
|
364
|
+
throw new Error(
|
|
365
|
+
"Bytes per character must be an integer between 1 and " + o.maxBytesPerChar + ", inclusive."
|
|
366
|
+
);
|
|
367
|
+
for (c = 2 * h, l = Math.pow(16, c) - 1, m = 0, B = f.length; m < B; m++) {
|
|
368
|
+
if (g = f[m].charCodeAt(), isNaN(g))
|
|
369
|
+
throw new Error("Invalid character: " + f[m]);
|
|
370
|
+
if (g > l)
|
|
371
|
+
throw b = Math.ceil(Math.log(g + 1) / Math.log(256)), new Error(
|
|
372
|
+
"Invalid character code (" + g + "). Maximum allowable is 256^bytes-1 (" + l + "). To convert this character, use at least " + b + " bytes."
|
|
373
|
+
);
|
|
374
|
+
d = y(g.toString(16), c) + d;
|
|
375
|
+
}
|
|
376
|
+
return d;
|
|
377
|
+
},
|
|
378
|
+
// Converts a given HEX number string to a UTF16 character string.
|
|
379
|
+
hex2str: function(f, h) {
|
|
380
|
+
var c, l = "", d, b;
|
|
381
|
+
if (typeof f != "string")
|
|
382
|
+
throw new Error("Input must be a hexadecimal string.");
|
|
383
|
+
if (h = h || o.bytesPerChar, typeof h != "number" || h % 1 !== 0 || h < 1 || h > o.maxBytesPerChar)
|
|
384
|
+
throw new Error(
|
|
385
|
+
"Bytes per character must be an integer between 1 and " + o.maxBytesPerChar + ", inclusive."
|
|
386
|
+
);
|
|
387
|
+
for (c = 2 * h, f = y(f, c), d = 0, b = f.length; d < b; d += c)
|
|
388
|
+
l = String.fromCharCode(
|
|
389
|
+
parseInt(f.slice(d, d + c), 16)
|
|
390
|
+
) + l;
|
|
391
|
+
return l;
|
|
392
|
+
},
|
|
393
|
+
// Generates a random bits-length number string using the PRNG
|
|
394
|
+
random: function(f) {
|
|
395
|
+
if (typeof f != "number" || f % 1 !== 0 || f < 2 || f > 65536)
|
|
396
|
+
throw new Error(
|
|
397
|
+
"Number of bits must be an Integer between 1 and 65536."
|
|
398
|
+
);
|
|
399
|
+
return S(r.rng(f));
|
|
400
|
+
},
|
|
401
|
+
// Divides a `secret` number String str expressed in radix `inputRadix` (optional, default 16)
|
|
402
|
+
// into `numShares` shares, each expressed in radix `outputRadix` (optional, default to `inputRadix`),
|
|
403
|
+
// requiring `threshold` number of shares to reconstruct the secret.
|
|
404
|
+
// Optionally, zero-pads the secret to a length that is a multiple of padLength before sharing.
|
|
405
|
+
share: function(f, h, c, l) {
|
|
406
|
+
var d, b, g = new Array(h), m = new Array(h), B, R, C;
|
|
407
|
+
if (l = l || 128, typeof f != "string")
|
|
408
|
+
throw new Error("Secret must be a string.");
|
|
409
|
+
if (typeof h != "number" || h % 1 !== 0 || h < 2)
|
|
410
|
+
throw new Error(
|
|
411
|
+
"Number of shares must be an integer between 2 and 2^bits-1 (" + r.maxShares + "), inclusive."
|
|
412
|
+
);
|
|
413
|
+
if (h > r.maxShares)
|
|
414
|
+
throw d = Math.ceil(Math.log(h + 1) / Math.LN2), new Error(
|
|
415
|
+
"Number of shares must be an integer between 2 and 2^bits-1 (" + r.maxShares + "), inclusive. To create " + h + " shares, use at least " + d + " bits."
|
|
416
|
+
);
|
|
417
|
+
if (typeof c != "number" || c % 1 !== 0 || c < 2)
|
|
418
|
+
throw new Error(
|
|
419
|
+
"Threshold number of shares must be an integer between 2 and 2^bits-1 (" + r.maxShares + "), inclusive."
|
|
420
|
+
);
|
|
421
|
+
if (c > r.maxShares)
|
|
422
|
+
throw d = Math.ceil(Math.log(c + 1) / Math.LN2), new Error(
|
|
423
|
+
"Threshold number of shares must be an integer between 2 and 2^bits-1 (" + r.maxShares + "), inclusive. To use a threshold of " + c + ", use at least " + d + " bits."
|
|
424
|
+
);
|
|
425
|
+
if (c > h)
|
|
426
|
+
throw new Error(
|
|
427
|
+
"Threshold number of shares was " + c + " but must be less than or equal to the " + h + " shares specified as the total to generate."
|
|
428
|
+
);
|
|
429
|
+
if (typeof l != "number" || l % 1 !== 0 || l < 0 || l > 1024)
|
|
430
|
+
throw new Error(
|
|
431
|
+
"Zero-pad length must be an integer between 0 and 1024 inclusive."
|
|
432
|
+
);
|
|
433
|
+
for (f = "1" + w(f), f = _(f, l), B = 0, C = f.length; B < C; B++)
|
|
434
|
+
for (b = p(f[B], h, c), R = 0; R < h; R++)
|
|
435
|
+
g[R] = g[R] || b[R].x.toString(r.radix), m[R] = y(b[R].y.toString(2)) + (m[R] || "");
|
|
436
|
+
for (B = 0; B < h; B++)
|
|
437
|
+
g[B] = N(
|
|
438
|
+
r.bits,
|
|
439
|
+
g[B],
|
|
440
|
+
S(m[B])
|
|
441
|
+
);
|
|
442
|
+
return g;
|
|
443
|
+
},
|
|
444
|
+
// Generate a new share with id `id` (a number between 1 and 2^bits-1)
|
|
445
|
+
// `id` can be a Number or a String in the default radix (16)
|
|
446
|
+
newShare: function(f, h) {
|
|
447
|
+
var c, l;
|
|
448
|
+
if (f && typeof f == "string" && (f = parseInt(f, r.radix)), l = f.toString(r.radix), f && l && h && h[0])
|
|
449
|
+
return c = this.extractShareComponents(h[0]), N(
|
|
450
|
+
c.bits,
|
|
451
|
+
l,
|
|
452
|
+
this.combine(h, f)
|
|
453
|
+
);
|
|
454
|
+
throw new Error(
|
|
455
|
+
"Invalid 'id' or 'shares' Array argument to newShare()."
|
|
456
|
+
);
|
|
457
|
+
},
|
|
458
|
+
/* test-code */
|
|
459
|
+
// export private functions so they can be unit tested directly.
|
|
460
|
+
_reset: i,
|
|
461
|
+
_padLeft: y,
|
|
462
|
+
_hex2bin: w,
|
|
463
|
+
_bin2hex: S,
|
|
464
|
+
_hasCryptoGetRandomValues: I,
|
|
465
|
+
_hasCryptoRandomBytes: v,
|
|
466
|
+
_getRNG: O,
|
|
467
|
+
_isSetRNG: x,
|
|
468
|
+
_splitNumStringToIntArray: _,
|
|
469
|
+
_horner: E,
|
|
470
|
+
_lagrange: A,
|
|
471
|
+
_getShares: p,
|
|
472
|
+
_constructPublicShareString: N
|
|
473
|
+
/* end-test-code */
|
|
474
|
+
};
|
|
475
|
+
return T.init(), T;
|
|
476
|
+
});
|
|
477
|
+
})(it)), it.exports;
|
|
478
|
+
}
|
|
479
|
+
var Me = qe();
|
|
480
|
+
const ee = /* @__PURE__ */ Ie(Me), Ge = 2, $e = 3;
|
|
481
|
+
function or(e) {
|
|
482
|
+
if (e.length !== 16)
|
|
483
|
+
throw new Error(`Invalid seed length: expected 16, got ${e.length}`);
|
|
484
|
+
const t = ne(e), n = ee.share(t, $e, Ge);
|
|
485
|
+
if (n.length !== 3)
|
|
486
|
+
throw new Error(`Unexpected share count: ${n.length}`);
|
|
487
|
+
const o = lt(n[0]), r = lt(n[1]), s = lt(n[2]);
|
|
488
|
+
return {
|
|
489
|
+
shareA: ht(o),
|
|
490
|
+
shareB: ht(r),
|
|
491
|
+
shareC: ht(s)
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
function sr(e, t) {
|
|
495
|
+
const n = Ht(e), o = Ht(t);
|
|
496
|
+
try {
|
|
497
|
+
const r = ee.combine([n, o]), s = re(r);
|
|
498
|
+
if (s.length !== 16)
|
|
499
|
+
throw new Error(`Reconstructed seed has wrong length: ${s.length}`);
|
|
500
|
+
return ve(s);
|
|
501
|
+
} catch {
|
|
502
|
+
throw new Error("Failed to reconstruct seed from shares");
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
function ne(e) {
|
|
506
|
+
return Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
507
|
+
}
|
|
508
|
+
function re(e) {
|
|
509
|
+
if (!/^[0-9a-fA-F]*$/.test(e))
|
|
510
|
+
throw new Error("Invalid hex string: contains non-hex characters");
|
|
511
|
+
if (e.length % 2 !== 0)
|
|
512
|
+
throw new Error(`Invalid hex string: length ${e.length} is odd (must be even)`);
|
|
513
|
+
const t = new Uint8Array(e.length / 2);
|
|
514
|
+
for (let n = 0; n < t.length; n++)
|
|
515
|
+
t[n] = parseInt(e.substr(n * 2, 2), 16);
|
|
516
|
+
return t;
|
|
517
|
+
}
|
|
518
|
+
function lt(e) {
|
|
519
|
+
const t = e.length % 2 === 0 ? e : "0" + e;
|
|
520
|
+
return re(t);
|
|
521
|
+
}
|
|
522
|
+
function Ht(e) {
|
|
523
|
+
const t = ne(e);
|
|
524
|
+
return t.startsWith("0") && !t.startsWith("00") ? t.substring(1) : t;
|
|
525
|
+
}
|
|
526
|
+
function Ze(e) {
|
|
527
|
+
return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
|
|
528
|
+
}
|
|
529
|
+
function At(e, ...t) {
|
|
530
|
+
if (!Ze(e))
|
|
531
|
+
throw new Error("Uint8Array expected");
|
|
532
|
+
if (t.length > 0 && !t.includes(e.length))
|
|
533
|
+
throw new Error("Uint8Array expected of length " + t + ", got length=" + e.length);
|
|
534
|
+
}
|
|
535
|
+
function Dt(e, t = !0) {
|
|
536
|
+
if (e.destroyed)
|
|
537
|
+
throw new Error("Hash instance has been destroyed");
|
|
538
|
+
if (t && e.finished)
|
|
539
|
+
throw new Error("Hash#digest() has already been called");
|
|
540
|
+
}
|
|
541
|
+
function je(e, t) {
|
|
542
|
+
At(e);
|
|
543
|
+
const n = t.outputLen;
|
|
544
|
+
if (e.length < n)
|
|
545
|
+
throw new Error("digestInto() expects output buffer of length at least " + n);
|
|
546
|
+
}
|
|
547
|
+
function yt(...e) {
|
|
548
|
+
for (let t = 0; t < e.length; t++)
|
|
549
|
+
e[t].fill(0);
|
|
550
|
+
}
|
|
551
|
+
function dt(e) {
|
|
552
|
+
return new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
553
|
+
}
|
|
554
|
+
function Z(e, t) {
|
|
555
|
+
return e << 32 - t | e >>> t;
|
|
556
|
+
}
|
|
557
|
+
function Ve(e) {
|
|
558
|
+
if (typeof e != "string")
|
|
559
|
+
throw new Error("string expected");
|
|
560
|
+
return new Uint8Array(new TextEncoder().encode(e));
|
|
561
|
+
}
|
|
562
|
+
function oe(e) {
|
|
563
|
+
return typeof e == "string" && (e = Ve(e)), At(e), e;
|
|
564
|
+
}
|
|
565
|
+
class ke {
|
|
566
|
+
}
|
|
567
|
+
function Ye(e) {
|
|
568
|
+
const t = (o) => e().update(oe(o)).digest(), n = e();
|
|
569
|
+
return t.outputLen = n.outputLen, t.blockLen = n.blockLen, t.create = () => e(), t;
|
|
570
|
+
}
|
|
571
|
+
function ze(e, t, n, o) {
|
|
572
|
+
if (typeof e.setBigUint64 == "function")
|
|
573
|
+
return e.setBigUint64(t, n, o);
|
|
574
|
+
const r = BigInt(32), s = BigInt(4294967295), a = Number(n >> r & s), u = Number(n & s), i = o ? 4 : 0, x = o ? 0 : 4;
|
|
575
|
+
e.setUint32(t + i, a, o), e.setUint32(t + x, u, o);
|
|
576
|
+
}
|
|
577
|
+
function Ke(e, t, n) {
|
|
578
|
+
return e & t ^ ~e & n;
|
|
579
|
+
}
|
|
580
|
+
function Xe(e, t, n) {
|
|
581
|
+
return e & t ^ e & n ^ t & n;
|
|
582
|
+
}
|
|
583
|
+
let We = class extends ke {
|
|
584
|
+
constructor(t, n, o, r) {
|
|
585
|
+
super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = t, this.outputLen = n, this.padOffset = o, this.isLE = r, this.buffer = new Uint8Array(t), this.view = dt(this.buffer);
|
|
586
|
+
}
|
|
587
|
+
update(t) {
|
|
588
|
+
Dt(this), t = oe(t), At(t);
|
|
589
|
+
const { view: n, buffer: o, blockLen: r } = this, s = t.length;
|
|
590
|
+
for (let a = 0; a < s; ) {
|
|
591
|
+
const u = Math.min(r - this.pos, s - a);
|
|
592
|
+
if (u === r) {
|
|
593
|
+
const i = dt(t);
|
|
594
|
+
for (; r <= s - a; a += r)
|
|
595
|
+
this.process(i, a);
|
|
596
|
+
continue;
|
|
597
|
+
}
|
|
598
|
+
o.set(t.subarray(a, a + u), this.pos), this.pos += u, a += u, this.pos === r && (this.process(n, 0), this.pos = 0);
|
|
599
|
+
}
|
|
600
|
+
return this.length += t.length, this.roundClean(), this;
|
|
601
|
+
}
|
|
602
|
+
digestInto(t) {
|
|
603
|
+
Dt(this), je(t, this), this.finished = !0;
|
|
604
|
+
const { buffer: n, view: o, blockLen: r, isLE: s } = this;
|
|
605
|
+
let { pos: a } = this;
|
|
606
|
+
n[a++] = 128, yt(this.buffer.subarray(a)), this.padOffset > r - a && (this.process(o, 0), a = 0);
|
|
607
|
+
for (let w = a; w < r; w++)
|
|
608
|
+
n[w] = 0;
|
|
609
|
+
ze(o, r - 8, BigInt(this.length * 8), s), this.process(o, 0);
|
|
610
|
+
const u = dt(t), i = this.outputLen;
|
|
611
|
+
if (i % 4)
|
|
612
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
613
|
+
const x = i / 4, y = this.get();
|
|
614
|
+
if (x > y.length)
|
|
615
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
616
|
+
for (let w = 0; w < x; w++)
|
|
617
|
+
u.setUint32(4 * w, y[w], s);
|
|
618
|
+
}
|
|
619
|
+
digest() {
|
|
620
|
+
const { buffer: t, outputLen: n } = this;
|
|
621
|
+
this.digestInto(t);
|
|
622
|
+
const o = t.slice(0, n);
|
|
623
|
+
return this.destroy(), o;
|
|
624
|
+
}
|
|
625
|
+
_cloneInto(t) {
|
|
626
|
+
t || (t = new this.constructor()), t.set(...this.get());
|
|
627
|
+
const { blockLen: n, buffer: o, length: r, finished: s, destroyed: a, pos: u } = this;
|
|
628
|
+
return t.destroyed = a, t.finished = s, t.length = r, t.pos = u, r % n && t.buffer.set(o), t;
|
|
629
|
+
}
|
|
630
|
+
clone() {
|
|
631
|
+
return this._cloneInto();
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
const Y = /* @__PURE__ */ Uint32Array.from([
|
|
635
|
+
1779033703,
|
|
636
|
+
3144134277,
|
|
637
|
+
1013904242,
|
|
638
|
+
2773480762,
|
|
639
|
+
1359893119,
|
|
640
|
+
2600822924,
|
|
641
|
+
528734635,
|
|
642
|
+
1541459225
|
|
643
|
+
]), Pe = /* @__PURE__ */ Uint32Array.from([
|
|
644
|
+
1116352408,
|
|
645
|
+
1899447441,
|
|
646
|
+
3049323471,
|
|
647
|
+
3921009573,
|
|
648
|
+
961987163,
|
|
649
|
+
1508970993,
|
|
650
|
+
2453635748,
|
|
651
|
+
2870763221,
|
|
652
|
+
3624381080,
|
|
653
|
+
310598401,
|
|
654
|
+
607225278,
|
|
655
|
+
1426881987,
|
|
656
|
+
1925078388,
|
|
657
|
+
2162078206,
|
|
658
|
+
2614888103,
|
|
659
|
+
3248222580,
|
|
660
|
+
3835390401,
|
|
661
|
+
4022224774,
|
|
662
|
+
264347078,
|
|
663
|
+
604807628,
|
|
664
|
+
770255983,
|
|
665
|
+
1249150122,
|
|
666
|
+
1555081692,
|
|
667
|
+
1996064986,
|
|
668
|
+
2554220882,
|
|
669
|
+
2821834349,
|
|
670
|
+
2952996808,
|
|
671
|
+
3210313671,
|
|
672
|
+
3336571891,
|
|
673
|
+
3584528711,
|
|
674
|
+
113926993,
|
|
675
|
+
338241895,
|
|
676
|
+
666307205,
|
|
677
|
+
773529912,
|
|
678
|
+
1294757372,
|
|
679
|
+
1396182291,
|
|
680
|
+
1695183700,
|
|
681
|
+
1986661051,
|
|
682
|
+
2177026350,
|
|
683
|
+
2456956037,
|
|
684
|
+
2730485921,
|
|
685
|
+
2820302411,
|
|
686
|
+
3259730800,
|
|
687
|
+
3345764771,
|
|
688
|
+
3516065817,
|
|
689
|
+
3600352804,
|
|
690
|
+
4094571909,
|
|
691
|
+
275423344,
|
|
692
|
+
430227734,
|
|
693
|
+
506948616,
|
|
694
|
+
659060556,
|
|
695
|
+
883997877,
|
|
696
|
+
958139571,
|
|
697
|
+
1322822218,
|
|
698
|
+
1537002063,
|
|
699
|
+
1747873779,
|
|
700
|
+
1955562222,
|
|
701
|
+
2024104815,
|
|
702
|
+
2227730452,
|
|
703
|
+
2361852424,
|
|
704
|
+
2428436474,
|
|
705
|
+
2756734187,
|
|
706
|
+
3204031479,
|
|
707
|
+
3329325298
|
|
708
|
+
]), z = /* @__PURE__ */ new Uint32Array(64);
|
|
709
|
+
class Fe extends We {
|
|
710
|
+
constructor(t = 32) {
|
|
711
|
+
super(64, t, 8, !1), this.A = Y[0] | 0, this.B = Y[1] | 0, this.C = Y[2] | 0, this.D = Y[3] | 0, this.E = Y[4] | 0, this.F = Y[5] | 0, this.G = Y[6] | 0, this.H = Y[7] | 0;
|
|
712
|
+
}
|
|
713
|
+
get() {
|
|
714
|
+
const { A: t, B: n, C: o, D: r, E: s, F: a, G: u, H: i } = this;
|
|
715
|
+
return [t, n, o, r, s, a, u, i];
|
|
716
|
+
}
|
|
717
|
+
// prettier-ignore
|
|
718
|
+
set(t, n, o, r, s, a, u, i) {
|
|
719
|
+
this.A = t | 0, this.B = n | 0, this.C = o | 0, this.D = r | 0, this.E = s | 0, this.F = a | 0, this.G = u | 0, this.H = i | 0;
|
|
720
|
+
}
|
|
721
|
+
process(t, n) {
|
|
722
|
+
for (let w = 0; w < 16; w++, n += 4)
|
|
723
|
+
z[w] = t.getUint32(n, !1);
|
|
724
|
+
for (let w = 16; w < 64; w++) {
|
|
725
|
+
const S = z[w - 15], I = z[w - 2], v = Z(S, 7) ^ Z(S, 18) ^ S >>> 3, O = Z(I, 17) ^ Z(I, 19) ^ I >>> 10;
|
|
726
|
+
z[w] = O + z[w - 7] + v + z[w - 16] | 0;
|
|
727
|
+
}
|
|
728
|
+
let { A: o, B: r, C: s, D: a, E: u, F: i, G: x, H: y } = this;
|
|
729
|
+
for (let w = 0; w < 64; w++) {
|
|
730
|
+
const S = Z(u, 6) ^ Z(u, 11) ^ Z(u, 25), I = y + S + Ke(u, i, x) + Pe[w] + z[w] | 0, O = (Z(o, 2) ^ Z(o, 13) ^ Z(o, 22)) + Xe(o, r, s) | 0;
|
|
731
|
+
y = x, x = i, i = u, u = a + I | 0, a = s, s = r, r = o, o = I + O | 0;
|
|
732
|
+
}
|
|
733
|
+
o = o + this.A | 0, r = r + this.B | 0, s = s + this.C | 0, a = a + this.D | 0, u = u + this.E | 0, i = i + this.F | 0, x = x + this.G | 0, y = y + this.H | 0, this.set(o, r, s, a, u, i, x, y);
|
|
734
|
+
}
|
|
735
|
+
roundClean() {
|
|
736
|
+
yt(z);
|
|
737
|
+
}
|
|
738
|
+
destroy() {
|
|
739
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0), yt(this.buffer);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
const Qe = /* @__PURE__ */ Ye(() => new Fe());
|
|
743
|
+
function se(e) {
|
|
744
|
+
return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
|
|
745
|
+
}
|
|
746
|
+
function Rt(e, t = "") {
|
|
747
|
+
if (!Number.isSafeInteger(e) || e < 0) {
|
|
748
|
+
const n = t && `"${t}" `;
|
|
749
|
+
throw new Error(`${n}expected integer >= 0, got ${e}`);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
function D(e, t, n = "") {
|
|
753
|
+
const o = se(e), r = e?.length, s = t !== void 0;
|
|
754
|
+
if (!o || s && r !== t) {
|
|
755
|
+
const a = n && `"${n}" `, u = s ? ` of length ${t}` : "", i = o ? `length=${r}` : `type=${typeof e}`;
|
|
756
|
+
throw new Error(a + "expected Uint8Array" + u + ", got " + i);
|
|
757
|
+
}
|
|
758
|
+
return e;
|
|
759
|
+
}
|
|
760
|
+
function qt(e, t = !0) {
|
|
761
|
+
if (e.destroyed)
|
|
762
|
+
throw new Error("Hash instance has been destroyed");
|
|
763
|
+
if (t && e.finished)
|
|
764
|
+
throw new Error("Hash#digest() has already been called");
|
|
765
|
+
}
|
|
766
|
+
function Je(e, t) {
|
|
767
|
+
D(e, void 0, "digestInto() output");
|
|
768
|
+
const n = t.outputLen;
|
|
769
|
+
if (e.length < n)
|
|
770
|
+
throw new Error('"digestInto() output" expected to be of length >=' + n);
|
|
771
|
+
}
|
|
772
|
+
function Et(...e) {
|
|
773
|
+
for (let t = 0; t < e.length; t++)
|
|
774
|
+
e[t].fill(0);
|
|
775
|
+
}
|
|
776
|
+
function bt(e) {
|
|
777
|
+
return new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
778
|
+
}
|
|
779
|
+
const ie = /* @ts-ignore */ typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", tn = /* @__PURE__ */ Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
|
|
780
|
+
function It(e) {
|
|
781
|
+
if (D(e), ie)
|
|
782
|
+
return e.toHex();
|
|
783
|
+
let t = "";
|
|
784
|
+
for (let n = 0; n < e.length; n++)
|
|
785
|
+
t += tn[e[n]];
|
|
786
|
+
return t;
|
|
787
|
+
}
|
|
788
|
+
const V = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
789
|
+
function Mt(e) {
|
|
790
|
+
if (e >= V._0 && e <= V._9)
|
|
791
|
+
return e - V._0;
|
|
792
|
+
if (e >= V.A && e <= V.F)
|
|
793
|
+
return e - (V.A - 10);
|
|
794
|
+
if (e >= V.a && e <= V.f)
|
|
795
|
+
return e - (V.a - 10);
|
|
796
|
+
}
|
|
797
|
+
function ce(e) {
|
|
798
|
+
if (typeof e != "string")
|
|
799
|
+
throw new Error("hex string expected, got " + typeof e);
|
|
800
|
+
if (ie)
|
|
801
|
+
return Uint8Array.fromHex(e);
|
|
802
|
+
const t = e.length, n = t / 2;
|
|
803
|
+
if (t % 2)
|
|
804
|
+
throw new Error("hex string expected, got unpadded hex of length " + t);
|
|
805
|
+
const o = new Uint8Array(n);
|
|
806
|
+
for (let r = 0, s = 0; r < n; r++, s += 2) {
|
|
807
|
+
const a = Mt(e.charCodeAt(s)), u = Mt(e.charCodeAt(s + 1));
|
|
808
|
+
if (a === void 0 || u === void 0) {
|
|
809
|
+
const i = e[s] + e[s + 1];
|
|
810
|
+
throw new Error('hex string expected, got non-hex character "' + i + '" at index ' + s);
|
|
811
|
+
}
|
|
812
|
+
o[r] = a * 16 + u;
|
|
813
|
+
}
|
|
814
|
+
return o;
|
|
815
|
+
}
|
|
816
|
+
function Gt(...e) {
|
|
817
|
+
let t = 0;
|
|
818
|
+
for (let o = 0; o < e.length; o++) {
|
|
819
|
+
const r = e[o];
|
|
820
|
+
D(r), t += r.length;
|
|
821
|
+
}
|
|
822
|
+
const n = new Uint8Array(t);
|
|
823
|
+
for (let o = 0, r = 0; o < e.length; o++) {
|
|
824
|
+
const s = e[o];
|
|
825
|
+
n.set(s, r), r += s.length;
|
|
826
|
+
}
|
|
827
|
+
return n;
|
|
828
|
+
}
|
|
829
|
+
function en(e, t = {}) {
|
|
830
|
+
const n = (r, s) => e(s).update(r).digest(), o = e(void 0);
|
|
831
|
+
return n.outputLen = o.outputLen, n.blockLen = o.blockLen, n.create = (r) => e(r), Object.assign(n, t), Object.freeze(n);
|
|
832
|
+
}
|
|
833
|
+
function nn(e = 32) {
|
|
834
|
+
const t = typeof globalThis == "object" ? globalThis.crypto : null;
|
|
835
|
+
if (typeof t?.getRandomValues != "function")
|
|
836
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
837
|
+
return t.getRandomValues(new Uint8Array(e));
|
|
838
|
+
}
|
|
839
|
+
const rn = (e) => ({
|
|
840
|
+
oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, e])
|
|
841
|
+
});
|
|
842
|
+
class on {
|
|
843
|
+
blockLen;
|
|
844
|
+
outputLen;
|
|
845
|
+
padOffset;
|
|
846
|
+
isLE;
|
|
847
|
+
// For partial updates less than block size
|
|
848
|
+
buffer;
|
|
849
|
+
view;
|
|
850
|
+
finished = !1;
|
|
851
|
+
length = 0;
|
|
852
|
+
pos = 0;
|
|
853
|
+
destroyed = !1;
|
|
854
|
+
constructor(t, n, o, r) {
|
|
855
|
+
this.blockLen = t, this.outputLen = n, this.padOffset = o, this.isLE = r, this.buffer = new Uint8Array(t), this.view = bt(this.buffer);
|
|
856
|
+
}
|
|
857
|
+
update(t) {
|
|
858
|
+
qt(this), D(t);
|
|
859
|
+
const { view: n, buffer: o, blockLen: r } = this, s = t.length;
|
|
860
|
+
for (let a = 0; a < s; ) {
|
|
861
|
+
const u = Math.min(r - this.pos, s - a);
|
|
862
|
+
if (u === r) {
|
|
863
|
+
const i = bt(t);
|
|
864
|
+
for (; r <= s - a; a += r)
|
|
865
|
+
this.process(i, a);
|
|
866
|
+
continue;
|
|
867
|
+
}
|
|
868
|
+
o.set(t.subarray(a, a + u), this.pos), this.pos += u, a += u, this.pos === r && (this.process(n, 0), this.pos = 0);
|
|
869
|
+
}
|
|
870
|
+
return this.length += t.length, this.roundClean(), this;
|
|
871
|
+
}
|
|
872
|
+
digestInto(t) {
|
|
873
|
+
qt(this), Je(t, this), this.finished = !0;
|
|
874
|
+
const { buffer: n, view: o, blockLen: r, isLE: s } = this;
|
|
875
|
+
let { pos: a } = this;
|
|
876
|
+
n[a++] = 128, Et(this.buffer.subarray(a)), this.padOffset > r - a && (this.process(o, 0), a = 0);
|
|
877
|
+
for (let w = a; w < r; w++)
|
|
878
|
+
n[w] = 0;
|
|
879
|
+
o.setBigUint64(r - 8, BigInt(this.length * 8), s), this.process(o, 0);
|
|
880
|
+
const u = bt(t), i = this.outputLen;
|
|
881
|
+
if (i % 4)
|
|
882
|
+
throw new Error("_sha2: outputLen must be aligned to 32bit");
|
|
883
|
+
const x = i / 4, y = this.get();
|
|
884
|
+
if (x > y.length)
|
|
885
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
886
|
+
for (let w = 0; w < x; w++)
|
|
887
|
+
u.setUint32(4 * w, y[w], s);
|
|
888
|
+
}
|
|
889
|
+
digest() {
|
|
890
|
+
const { buffer: t, outputLen: n } = this;
|
|
891
|
+
this.digestInto(t);
|
|
892
|
+
const o = t.slice(0, n);
|
|
893
|
+
return this.destroy(), o;
|
|
894
|
+
}
|
|
895
|
+
_cloneInto(t) {
|
|
896
|
+
t ||= new this.constructor(), t.set(...this.get());
|
|
897
|
+
const { blockLen: n, buffer: o, length: r, finished: s, destroyed: a, pos: u } = this;
|
|
898
|
+
return t.destroyed = a, t.finished = s, t.length = r, t.pos = u, r % n && t.buffer.set(o), t;
|
|
899
|
+
}
|
|
900
|
+
clone() {
|
|
901
|
+
return this._cloneInto();
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
const M = /* @__PURE__ */ Uint32Array.from([
|
|
905
|
+
1779033703,
|
|
906
|
+
4089235720,
|
|
907
|
+
3144134277,
|
|
908
|
+
2227873595,
|
|
909
|
+
1013904242,
|
|
910
|
+
4271175723,
|
|
911
|
+
2773480762,
|
|
912
|
+
1595750129,
|
|
913
|
+
1359893119,
|
|
914
|
+
2917565137,
|
|
915
|
+
2600822924,
|
|
916
|
+
725511199,
|
|
917
|
+
528734635,
|
|
918
|
+
4215389547,
|
|
919
|
+
1541459225,
|
|
920
|
+
327033209
|
|
921
|
+
]), rt = /* @__PURE__ */ BigInt(2 ** 32 - 1), $t = /* @__PURE__ */ BigInt(32);
|
|
922
|
+
function sn(e, t = !1) {
|
|
923
|
+
return t ? { h: Number(e & rt), l: Number(e >> $t & rt) } : { h: Number(e >> $t & rt) | 0, l: Number(e & rt) | 0 };
|
|
924
|
+
}
|
|
925
|
+
function cn(e, t = !1) {
|
|
926
|
+
const n = e.length;
|
|
927
|
+
let o = new Uint32Array(n), r = new Uint32Array(n);
|
|
928
|
+
for (let s = 0; s < n; s++) {
|
|
929
|
+
const { h: a, l: u } = sn(e[s], t);
|
|
930
|
+
[o[s], r[s]] = [a, u];
|
|
931
|
+
}
|
|
932
|
+
return [o, r];
|
|
933
|
+
}
|
|
934
|
+
const Zt = (e, t, n) => e >>> n, jt = (e, t, n) => e << 32 - n | t >>> n, J = (e, t, n) => e >>> n | t << 32 - n, tt = (e, t, n) => e << 32 - n | t >>> n, ot = (e, t, n) => e << 64 - n | t >>> n - 32, st = (e, t, n) => e >>> n - 32 | t << 64 - n;
|
|
935
|
+
function k(e, t, n, o) {
|
|
936
|
+
const r = (t >>> 0) + (o >>> 0);
|
|
937
|
+
return { h: e + n + (r / 2 ** 32 | 0) | 0, l: r | 0 };
|
|
938
|
+
}
|
|
939
|
+
const fn = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), an = (e, t, n, o) => t + n + o + (e / 2 ** 32 | 0) | 0, un = (e, t, n, o) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (o >>> 0), hn = (e, t, n, o, r) => t + n + o + r + (e / 2 ** 32 | 0) | 0, ln = (e, t, n, o, r) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (o >>> 0) + (r >>> 0), dn = (e, t, n, o, r, s) => t + n + o + r + s + (e / 2 ** 32 | 0) | 0, fe = cn([
|
|
940
|
+
"0x428a2f98d728ae22",
|
|
941
|
+
"0x7137449123ef65cd",
|
|
942
|
+
"0xb5c0fbcfec4d3b2f",
|
|
943
|
+
"0xe9b5dba58189dbbc",
|
|
944
|
+
"0x3956c25bf348b538",
|
|
945
|
+
"0x59f111f1b605d019",
|
|
946
|
+
"0x923f82a4af194f9b",
|
|
947
|
+
"0xab1c5ed5da6d8118",
|
|
948
|
+
"0xd807aa98a3030242",
|
|
949
|
+
"0x12835b0145706fbe",
|
|
950
|
+
"0x243185be4ee4b28c",
|
|
951
|
+
"0x550c7dc3d5ffb4e2",
|
|
952
|
+
"0x72be5d74f27b896f",
|
|
953
|
+
"0x80deb1fe3b1696b1",
|
|
954
|
+
"0x9bdc06a725c71235",
|
|
955
|
+
"0xc19bf174cf692694",
|
|
956
|
+
"0xe49b69c19ef14ad2",
|
|
957
|
+
"0xefbe4786384f25e3",
|
|
958
|
+
"0x0fc19dc68b8cd5b5",
|
|
959
|
+
"0x240ca1cc77ac9c65",
|
|
960
|
+
"0x2de92c6f592b0275",
|
|
961
|
+
"0x4a7484aa6ea6e483",
|
|
962
|
+
"0x5cb0a9dcbd41fbd4",
|
|
963
|
+
"0x76f988da831153b5",
|
|
964
|
+
"0x983e5152ee66dfab",
|
|
965
|
+
"0xa831c66d2db43210",
|
|
966
|
+
"0xb00327c898fb213f",
|
|
967
|
+
"0xbf597fc7beef0ee4",
|
|
968
|
+
"0xc6e00bf33da88fc2",
|
|
969
|
+
"0xd5a79147930aa725",
|
|
970
|
+
"0x06ca6351e003826f",
|
|
971
|
+
"0x142929670a0e6e70",
|
|
972
|
+
"0x27b70a8546d22ffc",
|
|
973
|
+
"0x2e1b21385c26c926",
|
|
974
|
+
"0x4d2c6dfc5ac42aed",
|
|
975
|
+
"0x53380d139d95b3df",
|
|
976
|
+
"0x650a73548baf63de",
|
|
977
|
+
"0x766a0abb3c77b2a8",
|
|
978
|
+
"0x81c2c92e47edaee6",
|
|
979
|
+
"0x92722c851482353b",
|
|
980
|
+
"0xa2bfe8a14cf10364",
|
|
981
|
+
"0xa81a664bbc423001",
|
|
982
|
+
"0xc24b8b70d0f89791",
|
|
983
|
+
"0xc76c51a30654be30",
|
|
984
|
+
"0xd192e819d6ef5218",
|
|
985
|
+
"0xd69906245565a910",
|
|
986
|
+
"0xf40e35855771202a",
|
|
987
|
+
"0x106aa07032bbd1b8",
|
|
988
|
+
"0x19a4c116b8d2d0c8",
|
|
989
|
+
"0x1e376c085141ab53",
|
|
990
|
+
"0x2748774cdf8eeb99",
|
|
991
|
+
"0x34b0bcb5e19b48a8",
|
|
992
|
+
"0x391c0cb3c5c95a63",
|
|
993
|
+
"0x4ed8aa4ae3418acb",
|
|
994
|
+
"0x5b9cca4f7763e373",
|
|
995
|
+
"0x682e6ff3d6b2b8a3",
|
|
996
|
+
"0x748f82ee5defb2fc",
|
|
997
|
+
"0x78a5636f43172f60",
|
|
998
|
+
"0x84c87814a1f0ab72",
|
|
999
|
+
"0x8cc702081a6439ec",
|
|
1000
|
+
"0x90befffa23631e28",
|
|
1001
|
+
"0xa4506cebde82bde9",
|
|
1002
|
+
"0xbef9a3f7b2c67915",
|
|
1003
|
+
"0xc67178f2e372532b",
|
|
1004
|
+
"0xca273eceea26619c",
|
|
1005
|
+
"0xd186b8c721c0c207",
|
|
1006
|
+
"0xeada7dd6cde0eb1e",
|
|
1007
|
+
"0xf57d4f7fee6ed178",
|
|
1008
|
+
"0x06f067aa72176fba",
|
|
1009
|
+
"0x0a637dc5a2c898a6",
|
|
1010
|
+
"0x113f9804bef90dae",
|
|
1011
|
+
"0x1b710b35131c471b",
|
|
1012
|
+
"0x28db77f523047d84",
|
|
1013
|
+
"0x32caab7b40c72493",
|
|
1014
|
+
"0x3c9ebe0a15c9bebc",
|
|
1015
|
+
"0x431d67c49c100d4c",
|
|
1016
|
+
"0x4cc5d4becb3e42b6",
|
|
1017
|
+
"0x597f299cfc657e2a",
|
|
1018
|
+
"0x5fcb6fab3ad6faec",
|
|
1019
|
+
"0x6c44198c4a475817"
|
|
1020
|
+
].map((e) => BigInt(e))), bn = fe[0], gn = fe[1], K = /* @__PURE__ */ new Uint32Array(80), X = /* @__PURE__ */ new Uint32Array(80);
|
|
1021
|
+
class wn extends on {
|
|
1022
|
+
constructor(t) {
|
|
1023
|
+
super(128, t, 16, !1);
|
|
1024
|
+
}
|
|
1025
|
+
// prettier-ignore
|
|
1026
|
+
get() {
|
|
1027
|
+
const { Ah: t, Al: n, Bh: o, Bl: r, Ch: s, Cl: a, Dh: u, Dl: i, Eh: x, El: y, Fh: w, Fl: S, Gh: I, Gl: v, Hh: O, Hl: _ } = this;
|
|
1028
|
+
return [t, n, o, r, s, a, u, i, x, y, w, S, I, v, O, _];
|
|
1029
|
+
}
|
|
1030
|
+
// prettier-ignore
|
|
1031
|
+
set(t, n, o, r, s, a, u, i, x, y, w, S, I, v, O, _) {
|
|
1032
|
+
this.Ah = t | 0, this.Al = n | 0, this.Bh = o | 0, this.Bl = r | 0, this.Ch = s | 0, this.Cl = a | 0, this.Dh = u | 0, this.Dl = i | 0, this.Eh = x | 0, this.El = y | 0, this.Fh = w | 0, this.Fl = S | 0, this.Gh = I | 0, this.Gl = v | 0, this.Hh = O | 0, this.Hl = _ | 0;
|
|
1033
|
+
}
|
|
1034
|
+
process(t, n) {
|
|
1035
|
+
for (let p = 0; p < 16; p++, n += 4)
|
|
1036
|
+
K[p] = t.getUint32(n), X[p] = t.getUint32(n += 4);
|
|
1037
|
+
for (let p = 16; p < 80; p++) {
|
|
1038
|
+
const N = K[p - 15] | 0, T = X[p - 15] | 0, f = J(N, T, 1) ^ J(N, T, 8) ^ Zt(N, T, 7), h = tt(N, T, 1) ^ tt(N, T, 8) ^ jt(N, T, 7), c = K[p - 2] | 0, l = X[p - 2] | 0, d = J(c, l, 19) ^ ot(c, l, 61) ^ Zt(c, l, 6), b = tt(c, l, 19) ^ st(c, l, 61) ^ jt(c, l, 6), g = un(h, b, X[p - 7], X[p - 16]), m = hn(g, f, d, K[p - 7], K[p - 16]);
|
|
1039
|
+
K[p] = m | 0, X[p] = g | 0;
|
|
1040
|
+
}
|
|
1041
|
+
let { Ah: o, Al: r, Bh: s, Bl: a, Ch: u, Cl: i, Dh: x, Dl: y, Eh: w, El: S, Fh: I, Fl: v, Gh: O, Gl: _, Hh: E, Hl: A } = this;
|
|
1042
|
+
for (let p = 0; p < 80; p++) {
|
|
1043
|
+
const N = J(w, S, 14) ^ J(w, S, 18) ^ ot(w, S, 41), T = tt(w, S, 14) ^ tt(w, S, 18) ^ st(w, S, 41), f = w & I ^ ~w & O, h = S & v ^ ~S & _, c = ln(A, T, h, gn[p], X[p]), l = dn(c, E, N, f, bn[p], K[p]), d = c | 0, b = J(o, r, 28) ^ ot(o, r, 34) ^ ot(o, r, 39), g = tt(o, r, 28) ^ st(o, r, 34) ^ st(o, r, 39), m = o & s ^ o & u ^ s & u, B = r & a ^ r & i ^ a & i;
|
|
1044
|
+
E = O | 0, A = _ | 0, O = I | 0, _ = v | 0, I = w | 0, v = S | 0, { h: w, l: S } = k(x | 0, y | 0, l | 0, d | 0), x = u | 0, y = i | 0, u = s | 0, i = a | 0, s = o | 0, a = r | 0;
|
|
1045
|
+
const R = fn(d, g, B);
|
|
1046
|
+
o = an(R, l, b, m), r = R | 0;
|
|
1047
|
+
}
|
|
1048
|
+
({ h: o, l: r } = k(this.Ah | 0, this.Al | 0, o | 0, r | 0)), { h: s, l: a } = k(this.Bh | 0, this.Bl | 0, s | 0, a | 0), { h: u, l: i } = k(this.Ch | 0, this.Cl | 0, u | 0, i | 0), { h: x, l: y } = k(this.Dh | 0, this.Dl | 0, x | 0, y | 0), { h: w, l: S } = k(this.Eh | 0, this.El | 0, w | 0, S | 0), { h: I, l: v } = k(this.Fh | 0, this.Fl | 0, I | 0, v | 0), { h: O, l: _ } = k(this.Gh | 0, this.Gl | 0, O | 0, _ | 0), { h: E, l: A } = k(this.Hh | 0, this.Hl | 0, E | 0, A | 0), this.set(o, r, s, a, u, i, x, y, w, S, I, v, O, _, E, A);
|
|
1049
|
+
}
|
|
1050
|
+
roundClean() {
|
|
1051
|
+
Et(K, X);
|
|
1052
|
+
}
|
|
1053
|
+
destroy() {
|
|
1054
|
+
Et(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
class xn extends wn {
|
|
1058
|
+
Ah = M[0] | 0;
|
|
1059
|
+
Al = M[1] | 0;
|
|
1060
|
+
Bh = M[2] | 0;
|
|
1061
|
+
Bl = M[3] | 0;
|
|
1062
|
+
Ch = M[4] | 0;
|
|
1063
|
+
Cl = M[5] | 0;
|
|
1064
|
+
Dh = M[6] | 0;
|
|
1065
|
+
Dl = M[7] | 0;
|
|
1066
|
+
Eh = M[8] | 0;
|
|
1067
|
+
El = M[9] | 0;
|
|
1068
|
+
Fh = M[10] | 0;
|
|
1069
|
+
Fl = M[11] | 0;
|
|
1070
|
+
Gh = M[12] | 0;
|
|
1071
|
+
Gl = M[13] | 0;
|
|
1072
|
+
Hh = M[14] | 0;
|
|
1073
|
+
Hl = M[15] | 0;
|
|
1074
|
+
constructor() {
|
|
1075
|
+
super(64);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
const pn = /* @__PURE__ */ en(
|
|
1079
|
+
() => new xn(),
|
|
1080
|
+
/* @__PURE__ */ rn(3)
|
|
1081
|
+
);
|
|
1082
|
+
const ae = /* @__PURE__ */ BigInt(0), Vt = /* @__PURE__ */ BigInt(1);
|
|
1083
|
+
function Bt(e, t = "") {
|
|
1084
|
+
if (typeof e != "boolean") {
|
|
1085
|
+
const n = t && `"${t}" `;
|
|
1086
|
+
throw new Error(n + "expected boolean, got type=" + typeof e);
|
|
1087
|
+
}
|
|
1088
|
+
return e;
|
|
1089
|
+
}
|
|
1090
|
+
function mn(e) {
|
|
1091
|
+
if (typeof e == "bigint") {
|
|
1092
|
+
if (!ct(e))
|
|
1093
|
+
throw new Error("positive bigint expected, got " + e);
|
|
1094
|
+
} else
|
|
1095
|
+
Rt(e);
|
|
1096
|
+
return e;
|
|
1097
|
+
}
|
|
1098
|
+
function ue(e) {
|
|
1099
|
+
if (typeof e != "string")
|
|
1100
|
+
throw new Error("hex string expected, got " + typeof e);
|
|
1101
|
+
return e === "" ? ae : BigInt("0x" + e);
|
|
1102
|
+
}
|
|
1103
|
+
function yn(e) {
|
|
1104
|
+
return ue(It(e));
|
|
1105
|
+
}
|
|
1106
|
+
function ft(e) {
|
|
1107
|
+
return ue(It(St(D(e)).reverse()));
|
|
1108
|
+
}
|
|
1109
|
+
function he(e, t) {
|
|
1110
|
+
Rt(t), e = mn(e);
|
|
1111
|
+
const n = ce(e.toString(16).padStart(t * 2, "0"));
|
|
1112
|
+
if (n.length !== t)
|
|
1113
|
+
throw new Error("number too large");
|
|
1114
|
+
return n;
|
|
1115
|
+
}
|
|
1116
|
+
function En(e, t) {
|
|
1117
|
+
return he(e, t).reverse();
|
|
1118
|
+
}
|
|
1119
|
+
function St(e) {
|
|
1120
|
+
return Uint8Array.from(e);
|
|
1121
|
+
}
|
|
1122
|
+
const ct = (e) => typeof e == "bigint" && ae <= e;
|
|
1123
|
+
function Bn(e, t, n) {
|
|
1124
|
+
return ct(e) && ct(t) && ct(n) && t <= e && e < n;
|
|
1125
|
+
}
|
|
1126
|
+
function kt(e, t, n, o) {
|
|
1127
|
+
if (!Bn(t, n, o))
|
|
1128
|
+
throw new Error("expected valid " + e + ": " + n + " <= n < " + o + ", got " + t);
|
|
1129
|
+
}
|
|
1130
|
+
const Sn = (e) => (Vt << BigInt(e)) - Vt;
|
|
1131
|
+
function _t(e, t = {}, n = {}) {
|
|
1132
|
+
if (!e || typeof e != "object")
|
|
1133
|
+
throw new Error("expected valid options object");
|
|
1134
|
+
function o(s, a, u) {
|
|
1135
|
+
const i = e[s];
|
|
1136
|
+
if (u && i === void 0)
|
|
1137
|
+
return;
|
|
1138
|
+
const x = typeof i;
|
|
1139
|
+
if (x !== a || i === null)
|
|
1140
|
+
throw new Error(`param "${s}" is invalid: expected ${a}, got ${x}`);
|
|
1141
|
+
}
|
|
1142
|
+
const r = (s, a) => Object.entries(s).forEach(([u, i]) => o(u, i, a));
|
|
1143
|
+
r(t, !1), r(n, !0);
|
|
1144
|
+
}
|
|
1145
|
+
function Yt(e) {
|
|
1146
|
+
const t = /* @__PURE__ */ new WeakMap();
|
|
1147
|
+
return (n, ...o) => {
|
|
1148
|
+
const r = t.get(n);
|
|
1149
|
+
if (r !== void 0)
|
|
1150
|
+
return r;
|
|
1151
|
+
const s = e(n, ...o);
|
|
1152
|
+
return t.set(n, s), s;
|
|
1153
|
+
};
|
|
1154
|
+
}
|
|
1155
|
+
const $ = /* @__PURE__ */ BigInt(0), G = /* @__PURE__ */ BigInt(1), F = /* @__PURE__ */ BigInt(2), le = /* @__PURE__ */ BigInt(3), de = /* @__PURE__ */ BigInt(4), be = /* @__PURE__ */ BigInt(5), vn = /* @__PURE__ */ BigInt(7), ge = /* @__PURE__ */ BigInt(8), An = /* @__PURE__ */ BigInt(9), we = /* @__PURE__ */ BigInt(16);
|
|
1156
|
+
function U(e, t) {
|
|
1157
|
+
const n = e % t;
|
|
1158
|
+
return n >= $ ? n : t + n;
|
|
1159
|
+
}
|
|
1160
|
+
function j(e, t, n) {
|
|
1161
|
+
let o = e;
|
|
1162
|
+
for (; t-- > $; )
|
|
1163
|
+
o *= o, o %= n;
|
|
1164
|
+
return o;
|
|
1165
|
+
}
|
|
1166
|
+
function zt(e, t) {
|
|
1167
|
+
if (e === $)
|
|
1168
|
+
throw new Error("invert: expected non-zero number");
|
|
1169
|
+
if (t <= $)
|
|
1170
|
+
throw new Error("invert: expected positive modulus, got " + t);
|
|
1171
|
+
let n = U(e, t), o = t, r = $, s = G;
|
|
1172
|
+
for (; n !== $; ) {
|
|
1173
|
+
const u = o / n, i = o % n, x = r - s * u;
|
|
1174
|
+
o = n, n = i, r = s, s = x;
|
|
1175
|
+
}
|
|
1176
|
+
if (o !== G)
|
|
1177
|
+
throw new Error("invert: does not exist");
|
|
1178
|
+
return U(r, t);
|
|
1179
|
+
}
|
|
1180
|
+
function Nt(e, t, n) {
|
|
1181
|
+
if (!e.eql(e.sqr(t), n))
|
|
1182
|
+
throw new Error("Cannot find square root");
|
|
1183
|
+
}
|
|
1184
|
+
function xe(e, t) {
|
|
1185
|
+
const n = (e.ORDER + G) / de, o = e.pow(t, n);
|
|
1186
|
+
return Nt(e, o, t), o;
|
|
1187
|
+
}
|
|
1188
|
+
function Rn(e, t) {
|
|
1189
|
+
const n = (e.ORDER - be) / ge, o = e.mul(t, F), r = e.pow(o, n), s = e.mul(t, r), a = e.mul(e.mul(s, F), r), u = e.mul(s, e.sub(a, e.ONE));
|
|
1190
|
+
return Nt(e, u, t), u;
|
|
1191
|
+
}
|
|
1192
|
+
function In(e) {
|
|
1193
|
+
const t = Ot(e), n = pe(e), o = n(t, t.neg(t.ONE)), r = n(t, o), s = n(t, t.neg(o)), a = (e + vn) / we;
|
|
1194
|
+
return (u, i) => {
|
|
1195
|
+
let x = u.pow(i, a), y = u.mul(x, o);
|
|
1196
|
+
const w = u.mul(x, r), S = u.mul(x, s), I = u.eql(u.sqr(y), i), v = u.eql(u.sqr(w), i);
|
|
1197
|
+
x = u.cmov(x, y, I), y = u.cmov(S, w, v);
|
|
1198
|
+
const O = u.eql(u.sqr(y), i), _ = u.cmov(x, y, O);
|
|
1199
|
+
return Nt(u, _, i), _;
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
function pe(e) {
|
|
1203
|
+
if (e < le)
|
|
1204
|
+
throw new Error("sqrt is not defined for small field");
|
|
1205
|
+
let t = e - G, n = 0;
|
|
1206
|
+
for (; t % F === $; )
|
|
1207
|
+
t /= F, n++;
|
|
1208
|
+
let o = F;
|
|
1209
|
+
const r = Ot(e);
|
|
1210
|
+
for (; Kt(r, o) === 1; )
|
|
1211
|
+
if (o++ > 1e3)
|
|
1212
|
+
throw new Error("Cannot find square root: probably non-prime P");
|
|
1213
|
+
if (n === 1)
|
|
1214
|
+
return xe;
|
|
1215
|
+
let s = r.pow(o, t);
|
|
1216
|
+
const a = (t + G) / F;
|
|
1217
|
+
return function(i, x) {
|
|
1218
|
+
if (i.is0(x))
|
|
1219
|
+
return x;
|
|
1220
|
+
if (Kt(i, x) !== 1)
|
|
1221
|
+
throw new Error("Cannot find square root");
|
|
1222
|
+
let y = n, w = i.mul(i.ONE, s), S = i.pow(x, t), I = i.pow(x, a);
|
|
1223
|
+
for (; !i.eql(S, i.ONE); ) {
|
|
1224
|
+
if (i.is0(S))
|
|
1225
|
+
return i.ZERO;
|
|
1226
|
+
let v = 1, O = i.sqr(S);
|
|
1227
|
+
for (; !i.eql(O, i.ONE); )
|
|
1228
|
+
if (v++, O = i.sqr(O), v === y)
|
|
1229
|
+
throw new Error("Cannot find square root");
|
|
1230
|
+
const _ = G << BigInt(y - v - 1), E = i.pow(w, _);
|
|
1231
|
+
y = v, w = i.sqr(E), S = i.mul(S, w), I = i.mul(I, E);
|
|
1232
|
+
}
|
|
1233
|
+
return I;
|
|
1234
|
+
};
|
|
1235
|
+
}
|
|
1236
|
+
function _n(e) {
|
|
1237
|
+
return e % de === le ? xe : e % ge === be ? Rn : e % we === An ? In(e) : pe(e);
|
|
1238
|
+
}
|
|
1239
|
+
const Nn = (e, t) => (U(e, t) & G) === G, On = [
|
|
1240
|
+
"create",
|
|
1241
|
+
"isValid",
|
|
1242
|
+
"is0",
|
|
1243
|
+
"neg",
|
|
1244
|
+
"inv",
|
|
1245
|
+
"sqrt",
|
|
1246
|
+
"sqr",
|
|
1247
|
+
"eql",
|
|
1248
|
+
"add",
|
|
1249
|
+
"sub",
|
|
1250
|
+
"mul",
|
|
1251
|
+
"pow",
|
|
1252
|
+
"div",
|
|
1253
|
+
"addN",
|
|
1254
|
+
"subN",
|
|
1255
|
+
"mulN",
|
|
1256
|
+
"sqrN"
|
|
1257
|
+
];
|
|
1258
|
+
function Tn(e) {
|
|
1259
|
+
const t = {
|
|
1260
|
+
ORDER: "bigint",
|
|
1261
|
+
BYTES: "number",
|
|
1262
|
+
BITS: "number"
|
|
1263
|
+
}, n = On.reduce((o, r) => (o[r] = "function", o), t);
|
|
1264
|
+
return _t(e, n), e;
|
|
1265
|
+
}
|
|
1266
|
+
function Cn(e, t, n) {
|
|
1267
|
+
if (n < $)
|
|
1268
|
+
throw new Error("invalid exponent, negatives unsupported");
|
|
1269
|
+
if (n === $)
|
|
1270
|
+
return e.ONE;
|
|
1271
|
+
if (n === G)
|
|
1272
|
+
return t;
|
|
1273
|
+
let o = e.ONE, r = t;
|
|
1274
|
+
for (; n > $; )
|
|
1275
|
+
n & G && (o = e.mul(o, r)), r = e.sqr(r), n >>= G;
|
|
1276
|
+
return o;
|
|
1277
|
+
}
|
|
1278
|
+
function me(e, t, n = !1) {
|
|
1279
|
+
const o = new Array(t.length).fill(n ? e.ZERO : void 0), r = t.reduce((a, u, i) => e.is0(u) ? a : (o[i] = a, e.mul(a, u)), e.ONE), s = e.inv(r);
|
|
1280
|
+
return t.reduceRight((a, u, i) => e.is0(u) ? a : (o[i] = e.mul(a, o[i]), e.mul(a, u)), s), o;
|
|
1281
|
+
}
|
|
1282
|
+
function Kt(e, t) {
|
|
1283
|
+
const n = (e.ORDER - G) / F, o = e.pow(t, n), r = e.eql(o, e.ONE), s = e.eql(o, e.ZERO), a = e.eql(o, e.neg(e.ONE));
|
|
1284
|
+
if (!r && !s && !a)
|
|
1285
|
+
throw new Error("invalid Legendre symbol result");
|
|
1286
|
+
return r ? 1 : s ? 0 : -1;
|
|
1287
|
+
}
|
|
1288
|
+
function Ln(e, t) {
|
|
1289
|
+
t !== void 0 && Rt(t);
|
|
1290
|
+
const n = t !== void 0 ? t : e.toString(2).length, o = Math.ceil(n / 8);
|
|
1291
|
+
return { nBitLength: n, nByteLength: o };
|
|
1292
|
+
}
|
|
1293
|
+
class Un {
|
|
1294
|
+
ORDER;
|
|
1295
|
+
BITS;
|
|
1296
|
+
BYTES;
|
|
1297
|
+
isLE;
|
|
1298
|
+
ZERO = $;
|
|
1299
|
+
ONE = G;
|
|
1300
|
+
_lengths;
|
|
1301
|
+
_sqrt;
|
|
1302
|
+
// cached sqrt
|
|
1303
|
+
_mod;
|
|
1304
|
+
constructor(t, n = {}) {
|
|
1305
|
+
if (t <= $)
|
|
1306
|
+
throw new Error("invalid field: expected ORDER > 0, got " + t);
|
|
1307
|
+
let o;
|
|
1308
|
+
this.isLE = !1, n != null && typeof n == "object" && (typeof n.BITS == "number" && (o = n.BITS), typeof n.sqrt == "function" && (this.sqrt = n.sqrt), typeof n.isLE == "boolean" && (this.isLE = n.isLE), n.allowedLengths && (this._lengths = n.allowedLengths?.slice()), typeof n.modFromBytes == "boolean" && (this._mod = n.modFromBytes));
|
|
1309
|
+
const { nBitLength: r, nByteLength: s } = Ln(t, o);
|
|
1310
|
+
if (s > 2048)
|
|
1311
|
+
throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
1312
|
+
this.ORDER = t, this.BITS = r, this.BYTES = s, this._sqrt = void 0, Object.preventExtensions(this);
|
|
1313
|
+
}
|
|
1314
|
+
create(t) {
|
|
1315
|
+
return U(t, this.ORDER);
|
|
1316
|
+
}
|
|
1317
|
+
isValid(t) {
|
|
1318
|
+
if (typeof t != "bigint")
|
|
1319
|
+
throw new Error("invalid field element: expected bigint, got " + typeof t);
|
|
1320
|
+
return $ <= t && t < this.ORDER;
|
|
1321
|
+
}
|
|
1322
|
+
is0(t) {
|
|
1323
|
+
return t === $;
|
|
1324
|
+
}
|
|
1325
|
+
// is valid and invertible
|
|
1326
|
+
isValidNot0(t) {
|
|
1327
|
+
return !this.is0(t) && this.isValid(t);
|
|
1328
|
+
}
|
|
1329
|
+
isOdd(t) {
|
|
1330
|
+
return (t & G) === G;
|
|
1331
|
+
}
|
|
1332
|
+
neg(t) {
|
|
1333
|
+
return U(-t, this.ORDER);
|
|
1334
|
+
}
|
|
1335
|
+
eql(t, n) {
|
|
1336
|
+
return t === n;
|
|
1337
|
+
}
|
|
1338
|
+
sqr(t) {
|
|
1339
|
+
return U(t * t, this.ORDER);
|
|
1340
|
+
}
|
|
1341
|
+
add(t, n) {
|
|
1342
|
+
return U(t + n, this.ORDER);
|
|
1343
|
+
}
|
|
1344
|
+
sub(t, n) {
|
|
1345
|
+
return U(t - n, this.ORDER);
|
|
1346
|
+
}
|
|
1347
|
+
mul(t, n) {
|
|
1348
|
+
return U(t * n, this.ORDER);
|
|
1349
|
+
}
|
|
1350
|
+
pow(t, n) {
|
|
1351
|
+
return Cn(this, t, n);
|
|
1352
|
+
}
|
|
1353
|
+
div(t, n) {
|
|
1354
|
+
return U(t * zt(n, this.ORDER), this.ORDER);
|
|
1355
|
+
}
|
|
1356
|
+
// Same as above, but doesn't normalize
|
|
1357
|
+
sqrN(t) {
|
|
1358
|
+
return t * t;
|
|
1359
|
+
}
|
|
1360
|
+
addN(t, n) {
|
|
1361
|
+
return t + n;
|
|
1362
|
+
}
|
|
1363
|
+
subN(t, n) {
|
|
1364
|
+
return t - n;
|
|
1365
|
+
}
|
|
1366
|
+
mulN(t, n) {
|
|
1367
|
+
return t * n;
|
|
1368
|
+
}
|
|
1369
|
+
inv(t) {
|
|
1370
|
+
return zt(t, this.ORDER);
|
|
1371
|
+
}
|
|
1372
|
+
sqrt(t) {
|
|
1373
|
+
return this._sqrt || (this._sqrt = _n(this.ORDER)), this._sqrt(this, t);
|
|
1374
|
+
}
|
|
1375
|
+
toBytes(t) {
|
|
1376
|
+
return this.isLE ? En(t, this.BYTES) : he(t, this.BYTES);
|
|
1377
|
+
}
|
|
1378
|
+
fromBytes(t, n = !1) {
|
|
1379
|
+
D(t);
|
|
1380
|
+
const { _lengths: o, BYTES: r, isLE: s, ORDER: a, _mod: u } = this;
|
|
1381
|
+
if (o) {
|
|
1382
|
+
if (!o.includes(t.length) || t.length > r)
|
|
1383
|
+
throw new Error("Field.fromBytes: expected " + o + " bytes, got " + t.length);
|
|
1384
|
+
const x = new Uint8Array(r);
|
|
1385
|
+
x.set(t, s ? 0 : x.length - t.length), t = x;
|
|
1386
|
+
}
|
|
1387
|
+
if (t.length !== r)
|
|
1388
|
+
throw new Error("Field.fromBytes: expected " + r + " bytes, got " + t.length);
|
|
1389
|
+
let i = s ? ft(t) : yn(t);
|
|
1390
|
+
if (u && (i = U(i, a)), !n && !this.isValid(i))
|
|
1391
|
+
throw new Error("invalid field element: outside of range 0..ORDER");
|
|
1392
|
+
return i;
|
|
1393
|
+
}
|
|
1394
|
+
// TODO: we don't need it here, move out to separate fn
|
|
1395
|
+
invertBatch(t) {
|
|
1396
|
+
return me(this, t);
|
|
1397
|
+
}
|
|
1398
|
+
// We can't move this out because Fp6, Fp12 implement it
|
|
1399
|
+
// and it's unclear what to return in there.
|
|
1400
|
+
cmov(t, n, o) {
|
|
1401
|
+
return o ? n : t;
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
function Ot(e, t = {}) {
|
|
1405
|
+
return new Un(e, t);
|
|
1406
|
+
}
|
|
1407
|
+
const at = /* @__PURE__ */ BigInt(0), vt = /* @__PURE__ */ BigInt(1);
|
|
1408
|
+
function Xt(e, t) {
|
|
1409
|
+
const n = t.negate();
|
|
1410
|
+
return e ? n : t;
|
|
1411
|
+
}
|
|
1412
|
+
function gt(e, t) {
|
|
1413
|
+
const n = me(e.Fp, t.map((o) => o.Z));
|
|
1414
|
+
return t.map((o, r) => e.fromAffine(o.toAffine(n[r])));
|
|
1415
|
+
}
|
|
1416
|
+
function ye(e, t) {
|
|
1417
|
+
if (!Number.isSafeInteger(e) || e <= 0 || e > t)
|
|
1418
|
+
throw new Error("invalid window size, expected [1.." + t + "], got W=" + e);
|
|
1419
|
+
}
|
|
1420
|
+
function wt(e, t) {
|
|
1421
|
+
ye(e, t);
|
|
1422
|
+
const n = Math.ceil(t / e) + 1, o = 2 ** (e - 1), r = 2 ** e, s = Sn(e), a = BigInt(e);
|
|
1423
|
+
return { windows: n, windowSize: o, mask: s, maxNumber: r, shiftBy: a };
|
|
1424
|
+
}
|
|
1425
|
+
function Wt(e, t, n) {
|
|
1426
|
+
const { windowSize: o, mask: r, maxNumber: s, shiftBy: a } = n;
|
|
1427
|
+
let u = Number(e & r), i = e >> a;
|
|
1428
|
+
u > o && (u -= s, i += vt);
|
|
1429
|
+
const x = t * o, y = x + Math.abs(u) - 1, w = u === 0, S = u < 0, I = t % 2 !== 0;
|
|
1430
|
+
return { nextN: i, offset: y, isZero: w, isNeg: S, isNegF: I, offsetF: x };
|
|
1431
|
+
}
|
|
1432
|
+
const xt = /* @__PURE__ */ new WeakMap(), Ee = /* @__PURE__ */ new WeakMap();
|
|
1433
|
+
function pt(e) {
|
|
1434
|
+
return Ee.get(e) || 1;
|
|
1435
|
+
}
|
|
1436
|
+
function Pt(e) {
|
|
1437
|
+
if (e !== at)
|
|
1438
|
+
throw new Error("invalid wNAF");
|
|
1439
|
+
}
|
|
1440
|
+
class Hn {
|
|
1441
|
+
BASE;
|
|
1442
|
+
ZERO;
|
|
1443
|
+
Fn;
|
|
1444
|
+
bits;
|
|
1445
|
+
// Parametrized with a given Point class (not individual point)
|
|
1446
|
+
constructor(t, n) {
|
|
1447
|
+
this.BASE = t.BASE, this.ZERO = t.ZERO, this.Fn = t.Fn, this.bits = n;
|
|
1448
|
+
}
|
|
1449
|
+
// non-const time multiplication ladder
|
|
1450
|
+
_unsafeLadder(t, n, o = this.ZERO) {
|
|
1451
|
+
let r = t;
|
|
1452
|
+
for (; n > at; )
|
|
1453
|
+
n & vt && (o = o.add(r)), r = r.double(), n >>= vt;
|
|
1454
|
+
return o;
|
|
1455
|
+
}
|
|
1456
|
+
/**
|
|
1457
|
+
* Creates a wNAF precomputation window. Used for caching.
|
|
1458
|
+
* Default window size is set by `utils.precompute()` and is equal to 8.
|
|
1459
|
+
* Number of precomputed points depends on the curve size:
|
|
1460
|
+
* 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
|
|
1461
|
+
* - 𝑊 is the window size
|
|
1462
|
+
* - 𝑛 is the bitlength of the curve order.
|
|
1463
|
+
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
|
1464
|
+
* @param point Point instance
|
|
1465
|
+
* @param W window size
|
|
1466
|
+
* @returns precomputed point tables flattened to a single array
|
|
1467
|
+
*/
|
|
1468
|
+
precomputeWindow(t, n) {
|
|
1469
|
+
const { windows: o, windowSize: r } = wt(n, this.bits), s = [];
|
|
1470
|
+
let a = t, u = a;
|
|
1471
|
+
for (let i = 0; i < o; i++) {
|
|
1472
|
+
u = a, s.push(u);
|
|
1473
|
+
for (let x = 1; x < r; x++)
|
|
1474
|
+
u = u.add(a), s.push(u);
|
|
1475
|
+
a = u.double();
|
|
1476
|
+
}
|
|
1477
|
+
return s;
|
|
1478
|
+
}
|
|
1479
|
+
/**
|
|
1480
|
+
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
1481
|
+
* More compact implementation:
|
|
1482
|
+
* https://github.com/paulmillr/noble-secp256k1/blob/47cb1669b6e506ad66b35fe7d76132ae97465da2/index.ts#L502-L541
|
|
1483
|
+
* @returns real and fake (for const-time) points
|
|
1484
|
+
*/
|
|
1485
|
+
wNAF(t, n, o) {
|
|
1486
|
+
if (!this.Fn.isValid(o))
|
|
1487
|
+
throw new Error("invalid scalar");
|
|
1488
|
+
let r = this.ZERO, s = this.BASE;
|
|
1489
|
+
const a = wt(t, this.bits);
|
|
1490
|
+
for (let u = 0; u < a.windows; u++) {
|
|
1491
|
+
const { nextN: i, offset: x, isZero: y, isNeg: w, isNegF: S, offsetF: I } = Wt(o, u, a);
|
|
1492
|
+
o = i, y ? s = s.add(Xt(S, n[I])) : r = r.add(Xt(w, n[x]));
|
|
1493
|
+
}
|
|
1494
|
+
return Pt(o), { p: r, f: s };
|
|
1495
|
+
}
|
|
1496
|
+
/**
|
|
1497
|
+
* Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
|
|
1498
|
+
* @param acc accumulator point to add result of multiplication
|
|
1499
|
+
* @returns point
|
|
1500
|
+
*/
|
|
1501
|
+
wNAFUnsafe(t, n, o, r = this.ZERO) {
|
|
1502
|
+
const s = wt(t, this.bits);
|
|
1503
|
+
for (let a = 0; a < s.windows && o !== at; a++) {
|
|
1504
|
+
const { nextN: u, offset: i, isZero: x, isNeg: y } = Wt(o, a, s);
|
|
1505
|
+
if (o = u, !x) {
|
|
1506
|
+
const w = n[i];
|
|
1507
|
+
r = r.add(y ? w.negate() : w);
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
return Pt(o), r;
|
|
1511
|
+
}
|
|
1512
|
+
getPrecomputes(t, n, o) {
|
|
1513
|
+
let r = xt.get(n);
|
|
1514
|
+
return r || (r = this.precomputeWindow(n, t), t !== 1 && (typeof o == "function" && (r = o(r)), xt.set(n, r))), r;
|
|
1515
|
+
}
|
|
1516
|
+
cached(t, n, o) {
|
|
1517
|
+
const r = pt(t);
|
|
1518
|
+
return this.wNAF(r, this.getPrecomputes(r, t, o), n);
|
|
1519
|
+
}
|
|
1520
|
+
unsafe(t, n, o, r) {
|
|
1521
|
+
const s = pt(t);
|
|
1522
|
+
return s === 1 ? this._unsafeLadder(t, n, r) : this.wNAFUnsafe(s, this.getPrecomputes(s, t, o), n, r);
|
|
1523
|
+
}
|
|
1524
|
+
// We calculate precomputes for elliptic curve point multiplication
|
|
1525
|
+
// using windowed method. This specifies window size and
|
|
1526
|
+
// stores precomputed values. Usually only base point would be precomputed.
|
|
1527
|
+
createCache(t, n) {
|
|
1528
|
+
ye(n, this.bits), Ee.set(t, n), xt.delete(t);
|
|
1529
|
+
}
|
|
1530
|
+
hasCache(t) {
|
|
1531
|
+
return pt(t) !== 1;
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
function Ft(e, t, n) {
|
|
1535
|
+
if (t) {
|
|
1536
|
+
if (t.ORDER !== e)
|
|
1537
|
+
throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
|
|
1538
|
+
return Tn(t), t;
|
|
1539
|
+
} else
|
|
1540
|
+
return Ot(e, { isLE: n });
|
|
1541
|
+
}
|
|
1542
|
+
function Dn(e, t, n = {}, o) {
|
|
1543
|
+
if (o === void 0 && (o = e === "edwards"), !t || typeof t != "object")
|
|
1544
|
+
throw new Error(`expected valid ${e} CURVE object`);
|
|
1545
|
+
for (const i of ["p", "n", "h"]) {
|
|
1546
|
+
const x = t[i];
|
|
1547
|
+
if (!(typeof x == "bigint" && x > at))
|
|
1548
|
+
throw new Error(`CURVE.${i} must be positive bigint`);
|
|
1549
|
+
}
|
|
1550
|
+
const r = Ft(t.p, n.Fp, o), s = Ft(t.n, n.Fn, o), u = ["Gx", "Gy", "a", "d"];
|
|
1551
|
+
for (const i of u)
|
|
1552
|
+
if (!r.isValid(t[i]))
|
|
1553
|
+
throw new Error(`CURVE.${i} must be valid field element of CURVE.Fp`);
|
|
1554
|
+
return t = Object.freeze(Object.assign({}, t)), { CURVE: t, Fp: r, Fn: s };
|
|
1555
|
+
}
|
|
1556
|
+
function qn(e, t) {
|
|
1557
|
+
return function(o) {
|
|
1558
|
+
const r = e(o);
|
|
1559
|
+
return { secretKey: r, publicKey: t(r) };
|
|
1560
|
+
};
|
|
1561
|
+
}
|
|
1562
|
+
const W = BigInt(0), H = BigInt(1), mt = BigInt(2), Mn = BigInt(8);
|
|
1563
|
+
function Gn(e, t, n, o) {
|
|
1564
|
+
const r = e.sqr(n), s = e.sqr(o), a = e.add(e.mul(t.a, r), s), u = e.add(e.ONE, e.mul(t.d, e.mul(r, s)));
|
|
1565
|
+
return e.eql(a, u);
|
|
1566
|
+
}
|
|
1567
|
+
function $n(e, t = {}) {
|
|
1568
|
+
const n = Dn("edwards", e, t, t.FpFnLE), { Fp: o, Fn: r } = n;
|
|
1569
|
+
let s = n.CURVE;
|
|
1570
|
+
const { h: a } = s;
|
|
1571
|
+
_t(t, {}, { uvRatio: "function" });
|
|
1572
|
+
const u = mt << BigInt(r.BYTES * 8) - H, i = (_) => o.create(_), x = t.uvRatio || ((_, E) => {
|
|
1573
|
+
try {
|
|
1574
|
+
return { isValid: !0, value: o.sqrt(o.div(_, E)) };
|
|
1575
|
+
} catch {
|
|
1576
|
+
return { isValid: !1, value: W };
|
|
1577
|
+
}
|
|
1578
|
+
});
|
|
1579
|
+
if (!Gn(o, s, s.Gx, s.Gy))
|
|
1580
|
+
throw new Error("bad curve params: generator point");
|
|
1581
|
+
function y(_, E, A = !1) {
|
|
1582
|
+
const p = A ? H : W;
|
|
1583
|
+
return kt("coordinate " + _, E, p, u), E;
|
|
1584
|
+
}
|
|
1585
|
+
function w(_) {
|
|
1586
|
+
if (!(_ instanceof v))
|
|
1587
|
+
throw new Error("EdwardsPoint expected");
|
|
1588
|
+
}
|
|
1589
|
+
const S = Yt((_, E) => {
|
|
1590
|
+
const { X: A, Y: p, Z: N } = _, T = _.is0();
|
|
1591
|
+
E == null && (E = T ? Mn : o.inv(N));
|
|
1592
|
+
const f = i(A * E), h = i(p * E), c = o.mul(N, E);
|
|
1593
|
+
if (T)
|
|
1594
|
+
return { x: W, y: H };
|
|
1595
|
+
if (c !== H)
|
|
1596
|
+
throw new Error("invZ was invalid");
|
|
1597
|
+
return { x: f, y: h };
|
|
1598
|
+
}), I = Yt((_) => {
|
|
1599
|
+
const { a: E, d: A } = s;
|
|
1600
|
+
if (_.is0())
|
|
1601
|
+
throw new Error("bad point: ZERO");
|
|
1602
|
+
const { X: p, Y: N, Z: T, T: f } = _, h = i(p * p), c = i(N * N), l = i(T * T), d = i(l * l), b = i(h * E), g = i(l * i(b + c)), m = i(d + i(A * i(h * c)));
|
|
1603
|
+
if (g !== m)
|
|
1604
|
+
throw new Error("bad point: equation left != right (1)");
|
|
1605
|
+
const B = i(p * N), R = i(T * f);
|
|
1606
|
+
if (B !== R)
|
|
1607
|
+
throw new Error("bad point: equation left != right (2)");
|
|
1608
|
+
return !0;
|
|
1609
|
+
});
|
|
1610
|
+
class v {
|
|
1611
|
+
// base / generator point
|
|
1612
|
+
static BASE = new v(s.Gx, s.Gy, H, i(s.Gx * s.Gy));
|
|
1613
|
+
// zero / infinity / identity point
|
|
1614
|
+
static ZERO = new v(W, H, H, W);
|
|
1615
|
+
// 0, 1, 1, 0
|
|
1616
|
+
// math field
|
|
1617
|
+
static Fp = o;
|
|
1618
|
+
// scalar field
|
|
1619
|
+
static Fn = r;
|
|
1620
|
+
X;
|
|
1621
|
+
Y;
|
|
1622
|
+
Z;
|
|
1623
|
+
T;
|
|
1624
|
+
constructor(E, A, p, N) {
|
|
1625
|
+
this.X = y("x", E), this.Y = y("y", A), this.Z = y("z", p, !0), this.T = y("t", N), Object.freeze(this);
|
|
1626
|
+
}
|
|
1627
|
+
static CURVE() {
|
|
1628
|
+
return s;
|
|
1629
|
+
}
|
|
1630
|
+
static fromAffine(E) {
|
|
1631
|
+
if (E instanceof v)
|
|
1632
|
+
throw new Error("extended point not allowed");
|
|
1633
|
+
const { x: A, y: p } = E || {};
|
|
1634
|
+
return y("x", A), y("y", p), new v(A, p, H, i(A * p));
|
|
1635
|
+
}
|
|
1636
|
+
// Uses algo from RFC8032 5.1.3.
|
|
1637
|
+
static fromBytes(E, A = !1) {
|
|
1638
|
+
const p = o.BYTES, { a: N, d: T } = s;
|
|
1639
|
+
E = St(D(E, p, "point")), Bt(A, "zip215");
|
|
1640
|
+
const f = St(E), h = E[p - 1];
|
|
1641
|
+
f[p - 1] = h & -129;
|
|
1642
|
+
const c = ft(f), l = A ? u : o.ORDER;
|
|
1643
|
+
kt("point.y", c, W, l);
|
|
1644
|
+
const d = i(c * c), b = i(d - H), g = i(T * d - N);
|
|
1645
|
+
let { isValid: m, value: B } = x(b, g);
|
|
1646
|
+
if (!m)
|
|
1647
|
+
throw new Error("bad point: invalid y coordinate");
|
|
1648
|
+
const R = (B & H) === H, C = (h & 128) !== 0;
|
|
1649
|
+
if (!A && B === W && C)
|
|
1650
|
+
throw new Error("bad point: x=0 and x_0=1");
|
|
1651
|
+
return C !== R && (B = i(-B)), v.fromAffine({ x: B, y: c });
|
|
1652
|
+
}
|
|
1653
|
+
static fromHex(E, A = !1) {
|
|
1654
|
+
return v.fromBytes(ce(E), A);
|
|
1655
|
+
}
|
|
1656
|
+
get x() {
|
|
1657
|
+
return this.toAffine().x;
|
|
1658
|
+
}
|
|
1659
|
+
get y() {
|
|
1660
|
+
return this.toAffine().y;
|
|
1661
|
+
}
|
|
1662
|
+
precompute(E = 8, A = !0) {
|
|
1663
|
+
return O.createCache(this, E), A || this.multiply(mt), this;
|
|
1664
|
+
}
|
|
1665
|
+
// Useful in fromAffine() - not for fromBytes(), which always created valid points.
|
|
1666
|
+
assertValidity() {
|
|
1667
|
+
I(this);
|
|
1668
|
+
}
|
|
1669
|
+
// Compare one point to another.
|
|
1670
|
+
equals(E) {
|
|
1671
|
+
w(E);
|
|
1672
|
+
const { X: A, Y: p, Z: N } = this, { X: T, Y: f, Z: h } = E, c = i(A * h), l = i(T * N), d = i(p * h), b = i(f * N);
|
|
1673
|
+
return c === l && d === b;
|
|
1674
|
+
}
|
|
1675
|
+
is0() {
|
|
1676
|
+
return this.equals(v.ZERO);
|
|
1677
|
+
}
|
|
1678
|
+
negate() {
|
|
1679
|
+
return new v(i(-this.X), this.Y, this.Z, i(-this.T));
|
|
1680
|
+
}
|
|
1681
|
+
// Fast algo for doubling Extended Point.
|
|
1682
|
+
// https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#doubling-dbl-2008-hwcd
|
|
1683
|
+
// Cost: 4M + 4S + 1*a + 6add + 1*2.
|
|
1684
|
+
double() {
|
|
1685
|
+
const { a: E } = s, { X: A, Y: p, Z: N } = this, T = i(A * A), f = i(p * p), h = i(mt * i(N * N)), c = i(E * T), l = A + p, d = i(i(l * l) - T - f), b = c + f, g = b - h, m = c - f, B = i(d * g), R = i(b * m), C = i(d * m), L = i(g * b);
|
|
1686
|
+
return new v(B, R, L, C);
|
|
1687
|
+
}
|
|
1688
|
+
// Fast algo for adding 2 Extended Points.
|
|
1689
|
+
// https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#addition-add-2008-hwcd
|
|
1690
|
+
// Cost: 9M + 1*a + 1*d + 7add.
|
|
1691
|
+
add(E) {
|
|
1692
|
+
w(E);
|
|
1693
|
+
const { a: A, d: p } = s, { X: N, Y: T, Z: f, T: h } = this, { X: c, Y: l, Z: d, T: b } = E, g = i(N * c), m = i(T * l), B = i(h * p * b), R = i(f * d), C = i((N + T) * (c + l) - g - m), L = R - B, q = R + B, Q = i(m - A * g), nt = i(C * L), ut = i(q * Q), Ct = i(C * Q), Lt = i(L * q);
|
|
1694
|
+
return new v(nt, ut, Lt, Ct);
|
|
1695
|
+
}
|
|
1696
|
+
subtract(E) {
|
|
1697
|
+
return this.add(E.negate());
|
|
1698
|
+
}
|
|
1699
|
+
// Constant-time multiplication.
|
|
1700
|
+
multiply(E) {
|
|
1701
|
+
if (!r.isValidNot0(E))
|
|
1702
|
+
throw new Error("invalid scalar: expected 1 <= sc < curve.n");
|
|
1703
|
+
const { p: A, f: p } = O.cached(this, E, (N) => gt(v, N));
|
|
1704
|
+
return gt(v, [A, p])[0];
|
|
1705
|
+
}
|
|
1706
|
+
// Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
1707
|
+
// It's faster, but should only be used when you don't care about
|
|
1708
|
+
// an exposed private key e.g. sig verification.
|
|
1709
|
+
// Does NOT allow scalars higher than CURVE.n.
|
|
1710
|
+
// Accepts optional accumulator to merge with multiply (important for sparse scalars)
|
|
1711
|
+
multiplyUnsafe(E, A = v.ZERO) {
|
|
1712
|
+
if (!r.isValid(E))
|
|
1713
|
+
throw new Error("invalid scalar: expected 0 <= sc < curve.n");
|
|
1714
|
+
return E === W ? v.ZERO : this.is0() || E === H ? this : O.unsafe(this, E, (p) => gt(v, p), A);
|
|
1715
|
+
}
|
|
1716
|
+
// Checks if point is of small order.
|
|
1717
|
+
// If you add something to small order point, you will have "dirty"
|
|
1718
|
+
// point with torsion component.
|
|
1719
|
+
// Multiplies point by cofactor and checks if the result is 0.
|
|
1720
|
+
isSmallOrder() {
|
|
1721
|
+
return this.multiplyUnsafe(a).is0();
|
|
1722
|
+
}
|
|
1723
|
+
// Multiplies point by curve order and checks if the result is 0.
|
|
1724
|
+
// Returns `false` is the point is dirty.
|
|
1725
|
+
isTorsionFree() {
|
|
1726
|
+
return O.unsafe(this, s.n).is0();
|
|
1727
|
+
}
|
|
1728
|
+
// Converts Extended point to default (x, y) coordinates.
|
|
1729
|
+
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
|
1730
|
+
toAffine(E) {
|
|
1731
|
+
return S(this, E);
|
|
1732
|
+
}
|
|
1733
|
+
clearCofactor() {
|
|
1734
|
+
return a === H ? this : this.multiplyUnsafe(a);
|
|
1735
|
+
}
|
|
1736
|
+
toBytes() {
|
|
1737
|
+
const { x: E, y: A } = this.toAffine(), p = o.toBytes(A);
|
|
1738
|
+
return p[p.length - 1] |= E & H ? 128 : 0, p;
|
|
1739
|
+
}
|
|
1740
|
+
toHex() {
|
|
1741
|
+
return It(this.toBytes());
|
|
1742
|
+
}
|
|
1743
|
+
toString() {
|
|
1744
|
+
return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
const O = new Hn(v, r.BITS);
|
|
1748
|
+
return v.BASE.precompute(8), v;
|
|
1749
|
+
}
|
|
1750
|
+
function Zn(e, t, n = {}) {
|
|
1751
|
+
if (typeof t != "function")
|
|
1752
|
+
throw new Error('"hash" function param is required');
|
|
1753
|
+
_t(n, {}, {
|
|
1754
|
+
adjustScalarBytes: "function",
|
|
1755
|
+
randomBytes: "function",
|
|
1756
|
+
domain: "function",
|
|
1757
|
+
prehash: "function",
|
|
1758
|
+
mapToCurve: "function"
|
|
1759
|
+
});
|
|
1760
|
+
const { prehash: o } = n, { BASE: r, Fp: s, Fn: a } = e, u = n.randomBytes || nn, i = n.adjustScalarBytes || ((c) => c), x = n.domain || ((c, l, d) => {
|
|
1761
|
+
if (Bt(d, "phflag"), l.length || d)
|
|
1762
|
+
throw new Error("Contexts/pre-hash are not supported");
|
|
1763
|
+
return c;
|
|
1764
|
+
});
|
|
1765
|
+
function y(c) {
|
|
1766
|
+
return a.create(ft(c));
|
|
1767
|
+
}
|
|
1768
|
+
function w(c) {
|
|
1769
|
+
const l = p.secretKey;
|
|
1770
|
+
D(c, p.secretKey, "secretKey");
|
|
1771
|
+
const d = D(t(c), 2 * l, "hashedSecretKey"), b = i(d.slice(0, l)), g = d.slice(l, 2 * l), m = y(b);
|
|
1772
|
+
return { head: b, prefix: g, scalar: m };
|
|
1773
|
+
}
|
|
1774
|
+
function S(c) {
|
|
1775
|
+
const { head: l, prefix: d, scalar: b } = w(c), g = r.multiply(b), m = g.toBytes();
|
|
1776
|
+
return { head: l, prefix: d, scalar: b, point: g, pointBytes: m };
|
|
1777
|
+
}
|
|
1778
|
+
function I(c) {
|
|
1779
|
+
return S(c).pointBytes;
|
|
1780
|
+
}
|
|
1781
|
+
function v(c = Uint8Array.of(), ...l) {
|
|
1782
|
+
const d = Gt(...l);
|
|
1783
|
+
return y(t(x(d, D(c, void 0, "context"), !!o)));
|
|
1784
|
+
}
|
|
1785
|
+
function O(c, l, d = {}) {
|
|
1786
|
+
c = D(c, void 0, "message"), o && (c = o(c));
|
|
1787
|
+
const { prefix: b, scalar: g, pointBytes: m } = S(l), B = v(d.context, b, c), R = r.multiply(B).toBytes(), C = v(d.context, R, m, c), L = a.create(B + C * g);
|
|
1788
|
+
if (!a.isValid(L))
|
|
1789
|
+
throw new Error("sign failed: invalid s");
|
|
1790
|
+
const q = Gt(R, a.toBytes(L));
|
|
1791
|
+
return D(q, p.signature, "result");
|
|
1792
|
+
}
|
|
1793
|
+
const _ = { zip215: !0 };
|
|
1794
|
+
function E(c, l, d, b = _) {
|
|
1795
|
+
const { context: g, zip215: m } = b, B = p.signature;
|
|
1796
|
+
c = D(c, B, "signature"), l = D(l, void 0, "message"), d = D(d, p.publicKey, "publicKey"), m !== void 0 && Bt(m, "zip215"), o && (l = o(l));
|
|
1797
|
+
const R = B / 2, C = c.subarray(0, R), L = ft(c.subarray(R, B));
|
|
1798
|
+
let q, Q, nt;
|
|
1799
|
+
try {
|
|
1800
|
+
q = e.fromBytes(d, m), Q = e.fromBytes(C, m), nt = r.multiplyUnsafe(L);
|
|
1801
|
+
} catch {
|
|
1802
|
+
return !1;
|
|
1803
|
+
}
|
|
1804
|
+
if (!m && q.isSmallOrder())
|
|
1805
|
+
return !1;
|
|
1806
|
+
const ut = v(g, Q.toBytes(), q.toBytes(), l);
|
|
1807
|
+
return Q.add(q.multiplyUnsafe(ut)).subtract(nt).clearCofactor().is0();
|
|
1808
|
+
}
|
|
1809
|
+
const A = s.BYTES, p = {
|
|
1810
|
+
secretKey: A,
|
|
1811
|
+
publicKey: A,
|
|
1812
|
+
signature: 2 * A,
|
|
1813
|
+
seed: A
|
|
1814
|
+
};
|
|
1815
|
+
function N(c = u(p.seed)) {
|
|
1816
|
+
return D(c, p.seed, "seed");
|
|
1817
|
+
}
|
|
1818
|
+
function T(c) {
|
|
1819
|
+
return se(c) && c.length === a.BYTES;
|
|
1820
|
+
}
|
|
1821
|
+
function f(c, l) {
|
|
1822
|
+
try {
|
|
1823
|
+
return !!e.fromBytes(c, l);
|
|
1824
|
+
} catch {
|
|
1825
|
+
return !1;
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
const h = {
|
|
1829
|
+
getExtendedPublicKey: S,
|
|
1830
|
+
randomSecretKey: N,
|
|
1831
|
+
isValidSecretKey: T,
|
|
1832
|
+
isValidPublicKey: f,
|
|
1833
|
+
/**
|
|
1834
|
+
* Converts ed public key to x public key. Uses formula:
|
|
1835
|
+
* - ed25519:
|
|
1836
|
+
* - `(u, v) = ((1+y)/(1-y), sqrt(-486664)*u/x)`
|
|
1837
|
+
* - `(x, y) = (sqrt(-486664)*u/v, (u-1)/(u+1))`
|
|
1838
|
+
* - ed448:
|
|
1839
|
+
* - `(u, v) = ((y-1)/(y+1), sqrt(156324)*u/x)`
|
|
1840
|
+
* - `(x, y) = (sqrt(156324)*u/v, (1+u)/(1-u))`
|
|
1841
|
+
*/
|
|
1842
|
+
toMontgomery(c) {
|
|
1843
|
+
const { y: l } = e.fromBytes(c), d = p.publicKey, b = d === 32;
|
|
1844
|
+
if (!b && d !== 57)
|
|
1845
|
+
throw new Error("only defined for 25519 and 448");
|
|
1846
|
+
const g = b ? s.div(H + l, H - l) : s.div(l - H, l + H);
|
|
1847
|
+
return s.toBytes(g);
|
|
1848
|
+
},
|
|
1849
|
+
toMontgomerySecret(c) {
|
|
1850
|
+
const l = p.secretKey;
|
|
1851
|
+
D(c, l);
|
|
1852
|
+
const d = t(c.subarray(0, l));
|
|
1853
|
+
return i(d).subarray(0, l);
|
|
1854
|
+
}
|
|
1855
|
+
};
|
|
1856
|
+
return Object.freeze({
|
|
1857
|
+
keygen: qn(N, I),
|
|
1858
|
+
getPublicKey: I,
|
|
1859
|
+
sign: O,
|
|
1860
|
+
verify: E,
|
|
1861
|
+
utils: h,
|
|
1862
|
+
Point: e,
|
|
1863
|
+
lengths: p
|
|
1864
|
+
});
|
|
1865
|
+
}
|
|
1866
|
+
const jn = BigInt(1), Qt = BigInt(2), Vn = BigInt(5), kn = BigInt(8), Tt = BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"), Yn = {
|
|
1867
|
+
p: Tt,
|
|
1868
|
+
n: BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),
|
|
1869
|
+
h: kn,
|
|
1870
|
+
a: BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),
|
|
1871
|
+
d: BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),
|
|
1872
|
+
Gx: BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),
|
|
1873
|
+
Gy: BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")
|
|
1874
|
+
};
|
|
1875
|
+
function zn(e) {
|
|
1876
|
+
const t = BigInt(10), n = BigInt(20), o = BigInt(40), r = BigInt(80), s = Tt, u = e * e % s * e % s, i = j(u, Qt, s) * u % s, x = j(i, jn, s) * e % s, y = j(x, Vn, s) * x % s, w = j(y, t, s) * y % s, S = j(w, n, s) * w % s, I = j(S, o, s) * S % s, v = j(I, r, s) * I % s, O = j(v, r, s) * I % s, _ = j(O, t, s) * y % s;
|
|
1877
|
+
return { pow_p_5_8: j(_, Qt, s) * e % s, b2: u };
|
|
1878
|
+
}
|
|
1879
|
+
function Kn(e) {
|
|
1880
|
+
return e[0] &= 248, e[31] &= 127, e[31] |= 64, e;
|
|
1881
|
+
}
|
|
1882
|
+
const Jt = /* @__PURE__ */ BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");
|
|
1883
|
+
function Xn(e, t) {
|
|
1884
|
+
const n = Tt, o = U(t * t * t, n), r = U(o * o * t, n), s = zn(e * r).pow_p_5_8;
|
|
1885
|
+
let a = U(e * o * s, n);
|
|
1886
|
+
const u = U(t * a * a, n), i = a, x = U(a * Jt, n), y = u === e, w = u === U(-e, n), S = u === U(-e * Jt, n);
|
|
1887
|
+
return y && (a = i), (w || S) && (a = x), Nn(a, n) && (a = U(-a, n)), { isValid: y || w, value: a };
|
|
1888
|
+
}
|
|
1889
|
+
const Wn = /* @__PURE__ */ $n(Yn, { uvRatio: Xn });
|
|
1890
|
+
function Pn(e) {
|
|
1891
|
+
return Zn(Wn, pn, Object.assign({ adjustScalarBytes: Kn }, e));
|
|
1892
|
+
}
|
|
1893
|
+
const Fn = /* @__PURE__ */ Pn({}), Qn = Qe, Jn = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
1894
|
+
function tr(e) {
|
|
1895
|
+
if (e.length !== 16)
|
|
1896
|
+
throw new Error(`Invalid seed length: expected 16, got ${e.length}`);
|
|
1897
|
+
const t = Qn(e), n = Fn.getPublicKey(t), o = new Uint8Array(64);
|
|
1898
|
+
return o.set(t, 0), o.set(n, 32), te(t), { publicKey: n, secretKey: o };
|
|
1899
|
+
}
|
|
1900
|
+
function cr(e) {
|
|
1901
|
+
const t = tr(e), n = t.publicKey;
|
|
1902
|
+
return te(t.secretKey), n;
|
|
1903
|
+
}
|
|
1904
|
+
function fr(e) {
|
|
1905
|
+
if (e.length !== 32)
|
|
1906
|
+
throw new Error(`Invalid public key length: expected 32, got ${e.length}`);
|
|
1907
|
+
return er(e);
|
|
1908
|
+
}
|
|
1909
|
+
function er(e) {
|
|
1910
|
+
let t = 0;
|
|
1911
|
+
for (let r = 0; r < e.length && e[r] === 0; r++)
|
|
1912
|
+
t++;
|
|
1913
|
+
let n = 0n;
|
|
1914
|
+
for (let r = 0; r < e.length; r++)
|
|
1915
|
+
n = n * 256n + BigInt(e[r]);
|
|
1916
|
+
let o = "";
|
|
1917
|
+
for (; n > 0n; ) {
|
|
1918
|
+
const r = Number(n % 58n);
|
|
1919
|
+
o = Jn[r] + o, n = n / 58n;
|
|
1920
|
+
}
|
|
1921
|
+
return "1".repeat(t) + o;
|
|
1922
|
+
}
|
|
1923
|
+
export {
|
|
1924
|
+
rr as a,
|
|
1925
|
+
At as b,
|
|
1926
|
+
Qe as c,
|
|
1927
|
+
sr as d,
|
|
1928
|
+
Ie as e,
|
|
1929
|
+
cr as g,
|
|
1930
|
+
fr as p,
|
|
1931
|
+
or as s
|
|
1932
|
+
};
|