@gardenfi/utils 2.0.4 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +33 -24
- package/dist/index10.cjs +1 -1
- package/dist/index10.js +24 -32
- package/dist/index100.cjs +1 -0
- package/dist/index100.js +130 -0
- package/dist/index101.cjs +1 -0
- package/dist/index101.js +115 -0
- package/dist/index102.cjs +1 -0
- package/dist/index102.js +81 -0
- package/dist/index103.cjs +1 -0
- package/dist/index103.js +4 -0
- package/dist/index104.cjs +1 -0
- package/dist/index104.js +20 -0
- package/dist/index105.cjs +1 -0
- package/dist/index105.js +21 -0
- package/dist/index106.cjs +1 -0
- package/dist/index106.js +19 -0
- package/dist/index107.cjs +1 -0
- package/dist/index107.js +226 -0
- package/dist/index108.cjs +2 -0
- package/dist/index108.js +5 -0
- package/dist/index109.cjs +1 -0
- package/dist/index109.js +37 -0
- package/dist/index11.cjs +1 -1
- package/dist/index11.js +136 -14
- package/dist/index110.cjs +1 -0
- package/dist/index110.js +21 -0
- package/dist/index111.cjs +1 -0
- package/dist/index111.js +72 -0
- package/dist/index112.cjs +1 -0
- package/dist/index112.js +70 -0
- package/dist/index113.cjs +1 -0
- package/dist/index113.js +4 -0
- package/dist/index114.cjs +1 -0
- package/dist/index114.js +43 -0
- package/dist/index115.cjs +1 -0
- package/dist/index115.js +646 -0
- package/dist/index116.cjs +1 -0
- package/dist/index116.js +234 -0
- package/dist/index117.cjs +1 -0
- package/dist/index117.js +175 -0
- package/dist/index12.cjs +1 -1
- package/dist/index12.js +9 -182
- package/dist/index13.cjs +1 -1
- package/dist/index13.js +2 -94
- package/dist/index14.cjs +1 -16
- package/dist/index14.js +32 -112
- package/dist/index15.cjs +1 -1
- package/dist/index15.js +18 -31
- package/dist/index16.cjs +1 -1
- package/dist/index16.js +188 -31
- package/dist/index17.cjs +1 -1
- package/dist/index17.js +93 -17
- package/dist/index18.cjs +1 -1
- package/dist/index18.js +35 -7
- package/dist/index19.cjs +1 -1
- package/dist/index19.js +31 -20
- package/dist/index20.cjs +16 -1
- package/dist/index20.js +113 -21
- package/dist/index21.cjs +1 -1
- package/dist/index21.js +31 -9
- package/dist/index22.cjs +1 -1
- package/dist/index22.js +17 -31
- package/dist/index23.cjs +1 -1
- package/dist/index23.js +7 -26
- package/dist/index24.cjs +1 -1
- package/dist/index24.js +41 -19
- package/dist/index25.cjs +1 -1
- package/dist/index25.js +19 -49
- package/dist/index26.cjs +1 -1
- package/dist/index26.js +8 -12
- package/dist/index27.cjs +1 -1
- package/dist/index27.js +30 -23
- package/dist/index28.cjs +1 -1
- package/dist/index28.js +25 -74
- package/dist/index29.cjs +2 -1
- package/dist/index29.js +62 -20
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +30 -7
- package/dist/index30.cjs +1 -1
- package/dist/index30.js +51 -7
- package/dist/index31.cjs +1 -1
- package/dist/index31.js +12 -32
- package/dist/index32.cjs +1 -1
- package/dist/index32.js +24 -15
- package/dist/index33.cjs +1 -1
- package/dist/index33.js +76 -2
- package/dist/index34.cjs +1 -1
- package/dist/index34.js +23 -8
- package/dist/index35.cjs +1 -1
- package/dist/index35.js +7 -20
- package/dist/index36.cjs +1 -1
- package/dist/index36.js +32 -12
- package/dist/index37.cjs +1 -1
- package/dist/index37.js +15 -34
- package/dist/index38.cjs +1 -2
- package/dist/index38.js +2 -60
- package/dist/index39.cjs +1 -1
- package/dist/index39.js +9 -2
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +2 -2
- package/dist/index40.cjs +1 -1
- package/dist/index40.js +20 -4
- package/dist/index41.cjs +1 -1
- package/dist/index41.js +12 -11
- package/dist/index42.cjs +1 -1
- package/dist/index42.js +34 -3
- package/dist/index43.cjs +2 -1
- package/dist/index43.js +58 -20
- package/dist/index44.cjs +1 -1
- package/dist/index44.js +2 -13
- package/dist/index45.cjs +1 -1
- package/dist/index45.js +5 -54
- package/dist/index46.cjs +1 -1
- package/dist/index46.js +6 -6
- package/dist/index47.cjs +1 -1
- package/dist/index47.js +4 -21
- package/dist/index48.cjs +1 -1
- package/dist/index48.js +11 -11
- package/dist/index49.cjs +5 -1
- package/dist/index49.js +56 -3
- package/dist/index50.cjs +2 -1
- package/dist/index50.js +32 -9
- package/dist/index51.cjs +1 -1
- package/dist/index51.js +5 -19
- package/dist/index52.cjs +1 -1
- package/dist/index52.js +3 -6
- package/dist/index53.cjs +1 -1
- package/dist/index53.js +21 -8
- package/dist/index54.cjs +1 -1
- package/dist/index54.js +11 -103
- package/dist/index55.cjs +1 -1
- package/dist/index55.js +51 -24
- package/dist/index56.cjs +1 -1
- package/dist/index56.js +8 -18
- package/dist/index57.cjs +1 -1
- package/dist/index57.js +20 -37
- package/dist/index58.cjs +1 -0
- package/dist/index58.js +14 -0
- package/dist/index59.cjs +1 -0
- package/dist/index59.js +11 -0
- package/dist/index60.cjs +1 -0
- package/dist/index60.js +13 -0
- package/dist/index61.cjs +1 -0
- package/dist/index61.js +14 -0
- package/dist/index62.cjs +1 -0
- package/dist/index62.js +9 -0
- package/dist/index63.cjs +1 -0
- package/dist/index63.js +16 -0
- package/dist/index64.cjs +1 -0
- package/dist/index64.js +35 -0
- package/dist/index65.cjs +1 -0
- package/dist/index65.js +17 -0
- package/dist/index66.cjs +1 -0
- package/dist/index66.js +67 -0
- package/dist/index67.cjs +1 -0
- package/dist/index67.js +30 -0
- package/dist/index68.cjs +1 -0
- package/dist/index68.js +5 -0
- package/dist/index69.cjs +1 -0
- package/dist/index69.js +6 -0
- package/dist/index7.cjs +1 -1
- package/dist/index7.js +2 -109
- package/dist/index70.cjs +1 -0
- package/dist/index70.js +16 -0
- package/dist/index71.cjs +1 -0
- package/dist/index71.js +44 -0
- package/dist/index72.cjs +1 -0
- package/dist/index72.js +8 -0
- package/dist/index73.cjs +1 -0
- package/dist/index73.js +11 -0
- package/dist/index74.cjs +1 -0
- package/dist/index74.js +106 -0
- package/dist/index75.cjs +1 -0
- package/dist/index75.js +194 -0
- package/dist/index76.cjs +1 -0
- package/dist/index76.js +21 -0
- package/dist/index77.cjs +1 -0
- package/dist/index77.js +14 -0
- package/dist/index78.cjs +1 -0
- package/dist/index78.js +22 -0
- package/dist/index79.cjs +1 -0
- package/dist/index79.js +15 -0
- package/dist/index8.cjs +1 -1
- package/dist/index8.js +95 -10
- package/dist/index80.cjs +1 -0
- package/dist/index80.js +28 -0
- package/dist/index81.cjs +1 -0
- package/dist/index81.js +9 -0
- package/dist/index82.cjs +1 -0
- package/dist/index82.js +16 -0
- package/dist/index83.cjs +1 -0
- package/dist/index83.js +18 -0
- package/dist/index84.cjs +1 -0
- package/dist/index84.js +8 -0
- package/dist/index85.cjs +1 -0
- package/dist/index85.js +16 -0
- package/dist/index86.cjs +1 -0
- package/dist/index86.js +13 -0
- package/dist/index87.cjs +1 -0
- package/dist/index87.js +19 -0
- package/dist/index88.cjs +1 -0
- package/dist/index88.js +174 -0
- package/dist/index89.cjs +1 -0
- package/dist/index89.js +41 -0
- package/dist/index9.cjs +1 -1
- package/dist/index9.js +44 -2
- package/dist/index90.cjs +1 -0
- package/dist/index90.js +11 -0
- package/dist/index91.cjs +1 -0
- package/dist/index91.js +7 -0
- package/dist/index92.cjs +1 -0
- package/dist/index92.js +13 -0
- package/dist/index93.cjs +1 -0
- package/dist/index93.js +4 -0
- package/dist/index94.cjs +1 -0
- package/dist/index94.js +107 -0
- package/dist/index95.cjs +1 -0
- package/dist/index95.js +45 -0
- package/dist/index96.cjs +1 -0
- package/dist/index96.js +23 -0
- package/dist/index97.cjs +1 -0
- package/dist/index97.js +9 -0
- package/dist/index98.cjs +1 -0
- package/dist/index98.js +7 -0
- package/dist/index99.cjs +1 -0
- package/dist/index99.js +40 -0
- package/dist/src/lib/auth/apikey/apikey.d.ts +12 -0
- package/dist/src/lib/auth/auth.types.d.ts +21 -8
- package/dist/src/lib/auth/index.d.ts +5 -1
- package/dist/src/lib/auth/passkey/passkey.d.ts +10 -0
- package/dist/src/lib/auth/passkey/passkey.types.d.ts +17 -0
- package/dist/src/lib/auth/passkey/passkeyLogin.d.ts +37 -0
- package/dist/src/lib/auth/{siwe.d.ts → siwe/siwe.d.ts} +4 -15
- package/dist/src/lib/utils.d.ts +3 -0
- package/package.json +2 -1
package/dist/index107.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { bitMask as _, numberToBytesLE as S, numberToBytesBE as x, bytesToNumberLE as y, bytesToNumberBE as L, validateObject as M } from "./index116.js";
|
|
2
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
|
+
const d = BigInt(0), c = BigInt(1), w = /* @__PURE__ */ BigInt(2), C = /* @__PURE__ */ BigInt(3), b = /* @__PURE__ */ BigInt(4), N = /* @__PURE__ */ BigInt(5), m = /* @__PURE__ */ BigInt(8);
|
|
4
|
+
function g(t, i) {
|
|
5
|
+
const r = t % i;
|
|
6
|
+
return r >= d ? r : i + r;
|
|
7
|
+
}
|
|
8
|
+
function Z(t, i, r) {
|
|
9
|
+
if (i < d)
|
|
10
|
+
throw new Error("invalid exponent, negatives unsupported");
|
|
11
|
+
if (r <= d)
|
|
12
|
+
throw new Error("invalid modulus");
|
|
13
|
+
if (r === c)
|
|
14
|
+
return d;
|
|
15
|
+
let e = c;
|
|
16
|
+
for (; i > d; )
|
|
17
|
+
i & c && (e = e * t % r), t = t * t % r, i >>= c;
|
|
18
|
+
return e;
|
|
19
|
+
}
|
|
20
|
+
function V(t, i, r) {
|
|
21
|
+
let e = t;
|
|
22
|
+
for (; i-- > d; )
|
|
23
|
+
e *= e, e %= r;
|
|
24
|
+
return e;
|
|
25
|
+
}
|
|
26
|
+
function I(t, i) {
|
|
27
|
+
if (t === d)
|
|
28
|
+
throw new Error("invert: expected non-zero number");
|
|
29
|
+
if (i <= d)
|
|
30
|
+
throw new Error("invert: expected positive modulus, got " + i);
|
|
31
|
+
let r = g(t, i), e = i, s = d, u = c;
|
|
32
|
+
for (; r !== d; ) {
|
|
33
|
+
const o = e / r, n = e % r, l = s - u * o;
|
|
34
|
+
e = r, r = n, s = u, u = l;
|
|
35
|
+
}
|
|
36
|
+
if (e !== c)
|
|
37
|
+
throw new Error("invert: does not exist");
|
|
38
|
+
return g(s, i);
|
|
39
|
+
}
|
|
40
|
+
function j(t) {
|
|
41
|
+
const i = (t - c) / w;
|
|
42
|
+
let r, e, s;
|
|
43
|
+
for (r = t - c, e = 0; r % w === d; r /= w, e++)
|
|
44
|
+
;
|
|
45
|
+
for (s = w; s < t && Z(s, i, t) !== t - c; s++)
|
|
46
|
+
if (s > 1e3)
|
|
47
|
+
throw new Error("Cannot find square root: likely non-prime P");
|
|
48
|
+
if (e === 1) {
|
|
49
|
+
const f = (t + c) / b;
|
|
50
|
+
return function(n, l) {
|
|
51
|
+
const h = n.pow(l, f);
|
|
52
|
+
if (!n.eql(n.sqr(h), l))
|
|
53
|
+
throw new Error("Cannot find square root");
|
|
54
|
+
return h;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const u = (r + c) / w;
|
|
58
|
+
return function(o, n) {
|
|
59
|
+
if (o.pow(n, i) === o.neg(o.ONE))
|
|
60
|
+
throw new Error("Cannot find square root");
|
|
61
|
+
let l = e, h = o.pow(o.mul(o.ONE, s), r), v = o.pow(n, u), a = o.pow(n, r);
|
|
62
|
+
for (; !o.eql(a, o.ONE); ) {
|
|
63
|
+
if (o.eql(a, o.ZERO))
|
|
64
|
+
return o.ZERO;
|
|
65
|
+
let q = 1;
|
|
66
|
+
for (let B = o.sqr(a); q < l && !o.eql(B, o.ONE); q++)
|
|
67
|
+
B = o.sqr(B);
|
|
68
|
+
const E = o.pow(h, c << BigInt(l - q - 1));
|
|
69
|
+
h = o.sqr(E), v = o.mul(v, E), a = o.mul(a, h), l = q;
|
|
70
|
+
}
|
|
71
|
+
return v;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function z(t) {
|
|
75
|
+
if (t % b === C) {
|
|
76
|
+
const i = (t + c) / b;
|
|
77
|
+
return function(e, s) {
|
|
78
|
+
const u = e.pow(s, i);
|
|
79
|
+
if (!e.eql(e.sqr(u), s))
|
|
80
|
+
throw new Error("Cannot find square root");
|
|
81
|
+
return u;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (t % m === N) {
|
|
85
|
+
const i = (t - N) / m;
|
|
86
|
+
return function(e, s) {
|
|
87
|
+
const u = e.mul(s, w), f = e.pow(u, i), o = e.mul(s, f), n = e.mul(e.mul(o, w), f), l = e.mul(o, e.sub(n, e.ONE));
|
|
88
|
+
if (!e.eql(e.sqr(l), s))
|
|
89
|
+
throw new Error("Cannot find square root");
|
|
90
|
+
return l;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return j(t);
|
|
94
|
+
}
|
|
95
|
+
const A = [
|
|
96
|
+
"create",
|
|
97
|
+
"isValid",
|
|
98
|
+
"is0",
|
|
99
|
+
"neg",
|
|
100
|
+
"inv",
|
|
101
|
+
"sqrt",
|
|
102
|
+
"sqr",
|
|
103
|
+
"eql",
|
|
104
|
+
"add",
|
|
105
|
+
"sub",
|
|
106
|
+
"mul",
|
|
107
|
+
"pow",
|
|
108
|
+
"div",
|
|
109
|
+
"addN",
|
|
110
|
+
"subN",
|
|
111
|
+
"mulN",
|
|
112
|
+
"sqrN"
|
|
113
|
+
];
|
|
114
|
+
function Y(t) {
|
|
115
|
+
const i = {
|
|
116
|
+
ORDER: "bigint",
|
|
117
|
+
MASK: "bigint",
|
|
118
|
+
BYTES: "isSafeInteger",
|
|
119
|
+
BITS: "isSafeInteger"
|
|
120
|
+
}, r = A.reduce((e, s) => (e[s] = "function", e), i);
|
|
121
|
+
return M(t, r);
|
|
122
|
+
}
|
|
123
|
+
function k(t, i, r) {
|
|
124
|
+
if (r < d)
|
|
125
|
+
throw new Error("invalid exponent, negatives unsupported");
|
|
126
|
+
if (r === d)
|
|
127
|
+
return t.ONE;
|
|
128
|
+
if (r === c)
|
|
129
|
+
return i;
|
|
130
|
+
let e = t.ONE, s = i;
|
|
131
|
+
for (; r > d; )
|
|
132
|
+
r & c && (e = t.mul(e, s)), s = t.sqr(s), r >>= c;
|
|
133
|
+
return e;
|
|
134
|
+
}
|
|
135
|
+
function H(t, i) {
|
|
136
|
+
const r = new Array(i.length), e = i.reduce((u, f, o) => t.is0(f) ? u : (r[o] = u, t.mul(u, f)), t.ONE), s = t.inv(e);
|
|
137
|
+
return i.reduceRight((u, f, o) => t.is0(f) ? u : (r[o] = t.mul(u, r[o]), t.mul(u, f)), s), r;
|
|
138
|
+
}
|
|
139
|
+
function K(t, i) {
|
|
140
|
+
const r = i !== void 0 ? i : t.toString(2).length, e = Math.ceil(r / 8);
|
|
141
|
+
return { nBitLength: r, nByteLength: e };
|
|
142
|
+
}
|
|
143
|
+
function p(t, i, r = !1, e = {}) {
|
|
144
|
+
if (t <= d)
|
|
145
|
+
throw new Error("invalid field: expected ORDER > 0, got " + t);
|
|
146
|
+
const { nBitLength: s, nByteLength: u } = K(t, i);
|
|
147
|
+
if (u > 2048)
|
|
148
|
+
throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
149
|
+
let f;
|
|
150
|
+
const o = Object.freeze({
|
|
151
|
+
ORDER: t,
|
|
152
|
+
isLE: r,
|
|
153
|
+
BITS: s,
|
|
154
|
+
BYTES: u,
|
|
155
|
+
MASK: _(s),
|
|
156
|
+
ZERO: d,
|
|
157
|
+
ONE: c,
|
|
158
|
+
create: (n) => g(n, t),
|
|
159
|
+
isValid: (n) => {
|
|
160
|
+
if (typeof n != "bigint")
|
|
161
|
+
throw new Error("invalid field element: expected bigint, got " + typeof n);
|
|
162
|
+
return d <= n && n < t;
|
|
163
|
+
},
|
|
164
|
+
is0: (n) => n === d,
|
|
165
|
+
isOdd: (n) => (n & c) === c,
|
|
166
|
+
neg: (n) => g(-n, t),
|
|
167
|
+
eql: (n, l) => n === l,
|
|
168
|
+
sqr: (n) => g(n * n, t),
|
|
169
|
+
add: (n, l) => g(n + l, t),
|
|
170
|
+
sub: (n, l) => g(n - l, t),
|
|
171
|
+
mul: (n, l) => g(n * l, t),
|
|
172
|
+
pow: (n, l) => k(o, n, l),
|
|
173
|
+
div: (n, l) => g(n * I(l, t), t),
|
|
174
|
+
// Same as above, but doesn't normalize
|
|
175
|
+
sqrN: (n) => n * n,
|
|
176
|
+
addN: (n, l) => n + l,
|
|
177
|
+
subN: (n, l) => n - l,
|
|
178
|
+
mulN: (n, l) => n * l,
|
|
179
|
+
inv: (n) => I(n, t),
|
|
180
|
+
sqrt: e.sqrt || ((n) => (f || (f = z(t)), f(o, n))),
|
|
181
|
+
invertBatch: (n) => H(o, n),
|
|
182
|
+
// TODO: do we really need constant cmov?
|
|
183
|
+
// We don't have const-time bigints anyway, so probably will be not very useful
|
|
184
|
+
cmov: (n, l, h) => h ? l : n,
|
|
185
|
+
toBytes: (n) => r ? S(n, u) : x(n, u),
|
|
186
|
+
fromBytes: (n) => {
|
|
187
|
+
if (n.length !== u)
|
|
188
|
+
throw new Error("Field.fromBytes: expected " + u + " bytes, got " + n.length);
|
|
189
|
+
return r ? y(n) : L(n);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
return Object.freeze(o);
|
|
193
|
+
}
|
|
194
|
+
function T(t) {
|
|
195
|
+
if (typeof t != "bigint")
|
|
196
|
+
throw new Error("field order must be bigint");
|
|
197
|
+
const i = t.toString(2).length;
|
|
198
|
+
return Math.ceil(i / 8);
|
|
199
|
+
}
|
|
200
|
+
function O(t) {
|
|
201
|
+
const i = T(t);
|
|
202
|
+
return i + Math.ceil(i / 2);
|
|
203
|
+
}
|
|
204
|
+
function G(t, i, r = !1) {
|
|
205
|
+
const e = t.length, s = T(i), u = O(i);
|
|
206
|
+
if (e < 16 || e < u || e > 1024)
|
|
207
|
+
throw new Error("expected " + u + "-1024 bytes of input, got " + e);
|
|
208
|
+
const f = r ? y(t) : L(t), o = g(f, i - c) + c;
|
|
209
|
+
return r ? S(o, s) : x(o, s);
|
|
210
|
+
}
|
|
211
|
+
export {
|
|
212
|
+
p as Field,
|
|
213
|
+
H as FpInvertBatch,
|
|
214
|
+
k as FpPow,
|
|
215
|
+
z as FpSqrt,
|
|
216
|
+
T as getFieldBytesLength,
|
|
217
|
+
O as getMinHashLength,
|
|
218
|
+
I as invert,
|
|
219
|
+
G as mapHashToField,
|
|
220
|
+
g as mod,
|
|
221
|
+
K as nLength,
|
|
222
|
+
Z as pow,
|
|
223
|
+
V as pow2,
|
|
224
|
+
j as tonelliShanks,
|
|
225
|
+
Y as validateField
|
|
226
|
+
};
|
package/dist/index108.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function r(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function i(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function o(e,...t){if(!i(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function a(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");r(e.outputLen),r(e.blockLen)}function s(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function u(e,t){o(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}exports.abytes=o;exports.aexists=s;exports.ahash=a;exports.anumber=r;exports.aoutput=u;
|
package/dist/index109.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
function n(e) {
|
|
2
|
+
if (!Number.isSafeInteger(e) || e < 0)
|
|
3
|
+
throw new Error("positive integer expected, got " + e);
|
|
4
|
+
}
|
|
5
|
+
function o(e) {
|
|
6
|
+
return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
|
|
7
|
+
}
|
|
8
|
+
function i(e, ...t) {
|
|
9
|
+
if (!o(e))
|
|
10
|
+
throw new Error("Uint8Array expected");
|
|
11
|
+
if (t.length > 0 && !t.includes(e.length))
|
|
12
|
+
throw new Error("Uint8Array expected of length " + t + ", got length=" + e.length);
|
|
13
|
+
}
|
|
14
|
+
function f(e) {
|
|
15
|
+
if (typeof e != "function" || typeof e.create != "function")
|
|
16
|
+
throw new Error("Hash should be wrapped by utils.wrapConstructor");
|
|
17
|
+
n(e.outputLen), n(e.blockLen);
|
|
18
|
+
}
|
|
19
|
+
function s(e, t = !0) {
|
|
20
|
+
if (e.destroyed)
|
|
21
|
+
throw new Error("Hash instance has been destroyed");
|
|
22
|
+
if (t && e.finished)
|
|
23
|
+
throw new Error("Hash#digest() has already been called");
|
|
24
|
+
}
|
|
25
|
+
function u(e, t) {
|
|
26
|
+
i(e);
|
|
27
|
+
const r = t.outputLen;
|
|
28
|
+
if (e.length < r)
|
|
29
|
+
throw new Error("digestInto() expects output buffer of length at least " + r);
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
i as abytes,
|
|
33
|
+
s as aexists,
|
|
34
|
+
f as ahash,
|
|
35
|
+
n as anumber,
|
|
36
|
+
u as aoutput
|
|
37
|
+
};
|
package/dist/index11.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index16.cjs"),l=require("@simplewebauthn/browser");class c{constructor(r,t){if(this.storeKey="passkey-auth",!window)throw new Error("Passkey is only supported in the browser environment.");this.url=r.endpoint("passkey"),this.store=t}getPasskeyFromStore(){if(this.token&&this.userName)return e.Ok({token:this.token,gardenUserName:this.userName});const r=this.store.getItem(this.storeKey);if(r){const t=JSON.parse(r);return e.Ok(t)}return e.Err("Passkey is not set")}validateUsername(r){return!r||r.length===0?e.Err("Username cannot be empty"):r.length<3||r.length>32?e.Err("Username must be between 3 and 32 characters"):r.includes(" ")?e.Err("Username cannot contain spaces"):e.Ok(r.trim().toLowerCase())}async register(r){var i;const t=this.validateUsername(r);if(t.error)return e.Err(t.error);try{const n=await e.Fetcher.post(this.url.endpoint("register/begin"),{body:JSON.stringify({username:t}),headers:{credentials:"include","Content-Type":"application/json"}});if(n.error)return e.Err("Failed to start registration",n.error);const s=(i=n.result)==null?void 0:i.challenge;if(!s)return e.Err("No challenge found");if(!s.publicKey.authenticatorSelection)return e.Err("No authenticator selection found");s.publicKey.authenticatorSelection.requireResidentKey=!0,s.publicKey.authenticatorSelection.residentKey="required";const a=await l.startRegistration({optionsJSON:s.publicKey}),o=await e.Fetcher.post(this.url.endpoint("register/finish"),{body:JSON.stringify({username:t,credential:a}),headers:{credentials:"include","Content-Type":"application/json"}});return o.error?e.Err("Failed to verify registration: "+o.error):o.result?(this.token=o.result.token,this.userName=t.val,e.Ok(o.result)):e.Err("No verification result found")}catch(n){return e.Err("Registration error",n)}}async login(r){var i;const t=this.validateUsername(r);if(t.error)return e.Err(t.error);try{const n=await e.Fetcher.post(this.url.endpoint("login/begin"),{body:JSON.stringify({username:t}),headers:{credentials:"include","Content-Type":"application/json"}});if(n.error)return e.Err("Failed to start login",n.error);const s=(i=n.result)==null?void 0:i.challenge;if(!s)return e.Err("No challenge found");const a=await l.startAuthentication({optionsJSON:s.publicKey}),o=await e.Fetcher.post(this.url.endpoint("login/finish"),{body:JSON.stringify({username:t,credential:a}),headers:{credentials:"include","Content-Type":"application/json"}});return o.error?e.Err("Failed to verify login",o.error):o.result?(this.token=o.result.token,this.userName=t.val,e.Ok(o.result)):e.Err("No verification result found")}catch(n){return e.Err("Login error",n)}}async conditionalLogin(){var r,t;try{const i=await e.Fetcher.get(this.url.endpoint("conditional-login/begin"),{headers:{credentials:"include"}});if(i.error)return e.Err("Failed to start login",i.error);const n=(r=i.result)==null?void 0:r.challenge;if(!n)return e.Err("No challenge found");const s=await l.startAuthentication({optionsJSON:n.publicKey}),a=await e.Fetcher.post(this.url.endpoint("conditional-login/finish"),{body:JSON.stringify({login_id:(t=i.result)==null?void 0:t.login_id,credential:s}),headers:{credentials:"include","Content-Type":"application/json"}});return a.error?e.Err("Failed to verify login",a.error):a.result?(this.token=a.result.token,this.userName=a.result.gardenUserName,e.Ok(a.result)):e.Err("No verification result found")}catch(i){return e.Err("Conditional login error",i)}}}exports.PasskeyLogin=c;
|
package/dist/index11.js
CHANGED
|
@@ -1,21 +1,143 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Ok as l, Err as e, Fetcher as c } from "./index16.js";
|
|
2
|
+
import { startRegistration as d, startAuthentication as u } from "@simplewebauthn/browser";
|
|
3
|
+
class f {
|
|
4
|
+
constructor(t, r) {
|
|
5
|
+
if (this.storeKey = "passkey-auth", !window)
|
|
6
|
+
throw new Error("Passkey is only supported in the browser environment.");
|
|
7
|
+
this.url = t.endpoint("passkey"), this.store = r;
|
|
4
8
|
}
|
|
5
|
-
|
|
6
|
-
(this.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
getPasskeyFromStore() {
|
|
10
|
+
if (this.token && this.userName)
|
|
11
|
+
return l({ token: this.token, gardenUserName: this.userName });
|
|
12
|
+
const t = this.store.getItem(this.storeKey);
|
|
13
|
+
if (t) {
|
|
14
|
+
const r = JSON.parse(t);
|
|
15
|
+
return l(r);
|
|
16
|
+
}
|
|
17
|
+
return e("Passkey is not set");
|
|
9
18
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Validates the username according to predefined rules.
|
|
21
|
+
* @param username The username to validate.
|
|
22
|
+
* @returns Result<string, string> - Ok if valid, Err with message if invalid.
|
|
23
|
+
*/
|
|
24
|
+
validateUsername(t) {
|
|
25
|
+
return !t || t.length === 0 ? e("Username cannot be empty") : t.length < 3 || t.length > 32 ? e("Username must be between 3 and 32 characters") : t.includes(" ") ? e("Username cannot contain spaces") : l(t.trim().toLowerCase());
|
|
13
26
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Handles user registration using WebAuthn passkeys.
|
|
29
|
+
* @param username The username to register.
|
|
30
|
+
* @returns AsyncResult<PasskeyToken, string> - Ok if successful, Err if failed.
|
|
31
|
+
*/
|
|
32
|
+
async register(t) {
|
|
33
|
+
var i;
|
|
34
|
+
const r = this.validateUsername(t);
|
|
35
|
+
if (r.error) return e(r.error);
|
|
36
|
+
try {
|
|
37
|
+
const n = await c.post(this.url.endpoint("register/begin"), {
|
|
38
|
+
body: JSON.stringify({ username: r }),
|
|
39
|
+
headers: { credentials: "include", "Content-Type": "application/json" }
|
|
40
|
+
});
|
|
41
|
+
if (n.error)
|
|
42
|
+
return e("Failed to start registration", n.error);
|
|
43
|
+
const s = (i = n.result) == null ? void 0 : i.challenge;
|
|
44
|
+
if (!s) return e("No challenge found");
|
|
45
|
+
if (!s.publicKey.authenticatorSelection)
|
|
46
|
+
return e("No authenticator selection found");
|
|
47
|
+
s.publicKey.authenticatorSelection.requireResidentKey = !0, s.publicKey.authenticatorSelection.residentKey = "required";
|
|
48
|
+
const a = await d({
|
|
49
|
+
optionsJSON: s.publicKey
|
|
50
|
+
}), o = await c.post(
|
|
51
|
+
this.url.endpoint("register/finish"),
|
|
52
|
+
{
|
|
53
|
+
body: JSON.stringify({
|
|
54
|
+
username: r,
|
|
55
|
+
credential: a
|
|
56
|
+
}),
|
|
57
|
+
headers: {
|
|
58
|
+
credentials: "include",
|
|
59
|
+
"Content-Type": "application/json"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
return o.error ? e("Failed to verify registration: " + o.error) : o.result ? (this.token = o.result.token, this.userName = r.val, l(o.result)) : e("No verification result found");
|
|
64
|
+
} catch (n) {
|
|
65
|
+
return e("Registration error", n);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Handles user login using WebAuthn passkeys.
|
|
70
|
+
* @param username The username to log in.
|
|
71
|
+
* @returns AsyncResult<PasskeyToken, string> - Ok if successful, Err if failed.
|
|
72
|
+
*/
|
|
73
|
+
async login(t) {
|
|
74
|
+
var i;
|
|
75
|
+
const r = this.validateUsername(t);
|
|
76
|
+
if (r.error) return e(r.error);
|
|
77
|
+
try {
|
|
78
|
+
const n = await c.post(this.url.endpoint("login/begin"), {
|
|
79
|
+
body: JSON.stringify({ username: r }),
|
|
80
|
+
headers: { credentials: "include", "Content-Type": "application/json" }
|
|
81
|
+
});
|
|
82
|
+
if (n.error)
|
|
83
|
+
return e("Failed to start login", n.error);
|
|
84
|
+
const s = (i = n.result) == null ? void 0 : i.challenge;
|
|
85
|
+
if (!s) return e("No challenge found");
|
|
86
|
+
const a = await u({
|
|
87
|
+
optionsJSON: s.publicKey
|
|
88
|
+
}), o = await c.post(
|
|
89
|
+
this.url.endpoint("login/finish"),
|
|
90
|
+
{
|
|
91
|
+
body: JSON.stringify({
|
|
92
|
+
username: r,
|
|
93
|
+
credential: a
|
|
94
|
+
}),
|
|
95
|
+
headers: {
|
|
96
|
+
credentials: "include",
|
|
97
|
+
"Content-Type": "application/json"
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
return o.error ? e("Failed to verify login", o.error) : o.result ? (this.token = o.result.token, this.userName = r.val, l(o.result)) : e("No verification result found");
|
|
102
|
+
} catch (n) {
|
|
103
|
+
return e("Login error", n);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Handles conditional login (without username) for existing users.
|
|
108
|
+
* @returns AsyncResult<PasskeyToken, string> - Ok if successful, Err if failed.
|
|
109
|
+
*/
|
|
110
|
+
async conditionalLogin() {
|
|
111
|
+
var t, r;
|
|
112
|
+
try {
|
|
113
|
+
const i = await c.get(this.url.endpoint("conditional-login/begin"), {
|
|
114
|
+
headers: { credentials: "include" }
|
|
115
|
+
});
|
|
116
|
+
if (i.error)
|
|
117
|
+
return e("Failed to start login", i.error);
|
|
118
|
+
const n = (t = i.result) == null ? void 0 : t.challenge;
|
|
119
|
+
if (!n) return e("No challenge found");
|
|
120
|
+
const s = await u({
|
|
121
|
+
optionsJSON: n.publicKey
|
|
122
|
+
}), a = await c.post(
|
|
123
|
+
this.url.endpoint("conditional-login/finish"),
|
|
124
|
+
{
|
|
125
|
+
body: JSON.stringify({
|
|
126
|
+
login_id: (r = i.result) == null ? void 0 : r.login_id,
|
|
127
|
+
credential: s
|
|
128
|
+
}),
|
|
129
|
+
headers: {
|
|
130
|
+
credentials: "include",
|
|
131
|
+
"Content-Type": "application/json"
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
return a.error ? e("Failed to verify login", a.error) : a.result ? (this.token = a.result.token, this.userName = a.result.gardenUserName, l(a.result)) : e("No verification result found");
|
|
136
|
+
} catch (i) {
|
|
137
|
+
return e("Conditional login error", i);
|
|
138
|
+
}
|
|
17
139
|
}
|
|
18
140
|
}
|
|
19
141
|
export {
|
|
20
|
-
|
|
142
|
+
f as PasskeyLogin
|
|
21
143
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=BigInt(2**32-1),i=BigInt(32);function u(t,e=!1){return e?{h:Number(t&n),l:Number(t>>i&n)}:{h:Number(t>>i&n)|0,l:Number(t&n)|0}}function g(t,e=!1){let r=new Uint32Array(t.length),l=new Uint32Array(t.length);for(let o=0;o<t.length;o++){const{h:c,l:f}=u(t[o],e);[r[o],l[o]]=[c,f]}return[r,l]}const B=(t,e,r)=>t<<r|e>>>32-r,h=(t,e,r)=>e<<r|t>>>32-r,m=(t,e,r)=>e<<r-32|t>>>64-r,S=(t,e,r)=>t<<r-32|e>>>64-r;exports.fromBig=u;exports.rotlBH=m;exports.rotlBL=S;exports.rotlSH=B;exports.rotlSL=h;exports.split=g;
|
package/dist/index110.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const o = /* @__PURE__ */ BigInt(4294967295), i = /* @__PURE__ */ BigInt(32);
|
|
2
|
+
function f(t, r = !1) {
|
|
3
|
+
return r ? { h: Number(t & o), l: Number(t >> i & o) } : { h: Number(t >> i & o) | 0, l: Number(t & o) | 0 };
|
|
4
|
+
}
|
|
5
|
+
function h(t, r = !1) {
|
|
6
|
+
let n = new Uint32Array(t.length), l = new Uint32Array(t.length);
|
|
7
|
+
for (let e = 0; e < t.length; e++) {
|
|
8
|
+
const { h: c, l: u } = f(t[e], r);
|
|
9
|
+
[n[e], l[e]] = [c, u];
|
|
10
|
+
}
|
|
11
|
+
return [n, l];
|
|
12
|
+
}
|
|
13
|
+
const g = (t, r, n) => t << n | r >>> 32 - n, m = (t, r, n) => r << n | t >>> 32 - n, A = (t, r, n) => r << n - 32 | t >>> 64 - n, B = (t, r, n) => t << n - 32 | r >>> 64 - n;
|
|
14
|
+
export {
|
|
15
|
+
f as fromBig,
|
|
16
|
+
A as rotlBH,
|
|
17
|
+
B as rotlBL,
|
|
18
|
+
g as rotlSH,
|
|
19
|
+
m as rotlSL,
|
|
20
|
+
h as split
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index113.cjs"),f=require("./index109.cjs");/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function p(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function a(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function l(t,e){return t<<32-e|t>>>e}const b=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function i(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function w(t){for(let e=0;e<t.length;e++)t[e]=i(t[e])}function y(t){if(typeof t!="string")throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array(new TextEncoder().encode(t))}function s(t){return typeof t=="string"&&(t=y(t)),f.abytes(t),t}function g(...t){let e=0;for(let n=0;n<t.length;n++){const u=t[n];f.abytes(u),e+=u.length}const r=new Uint8Array(e);for(let n=0,u=0;n<t.length;n++){const c=t[n];r.set(c,u),u+=c.length}return r}class m{clone(){return this._cloneInto()}}function B(t){const e=n=>t().update(s(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function d(t=32){if(o.crypto&&typeof o.crypto.getRandomValues=="function")return o.crypto.getRandomValues(new Uint8Array(t));if(o.crypto&&typeof o.crypto.randomBytes=="function")return o.crypto.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}exports.Hash=m;exports.byteSwap=i;exports.byteSwap32=w;exports.concatBytes=g;exports.createView=a;exports.isLE=b;exports.randomBytes=d;exports.rotr=l;exports.toBytes=s;exports.u32=p;exports.utf8ToBytes=y;exports.wrapConstructor=B;
|
package/dist/index111.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { crypto as o } from "./index113.js";
|
|
2
|
+
import { abytes as i } from "./index109.js";
|
|
3
|
+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
4
|
+
function g(t) {
|
|
5
|
+
return new Uint32Array(t.buffer, t.byteOffset, Math.floor(t.byteLength / 4));
|
|
6
|
+
}
|
|
7
|
+
function m(t) {
|
|
8
|
+
return new DataView(t.buffer, t.byteOffset, t.byteLength);
|
|
9
|
+
}
|
|
10
|
+
function w(t, e) {
|
|
11
|
+
return t << 32 - e | t >>> e;
|
|
12
|
+
}
|
|
13
|
+
const b = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
14
|
+
function c(t) {
|
|
15
|
+
return t << 24 & 4278190080 | t << 8 & 16711680 | t >>> 8 & 65280 | t >>> 24 & 255;
|
|
16
|
+
}
|
|
17
|
+
function a(t) {
|
|
18
|
+
for (let e = 0; e < t.length; e++)
|
|
19
|
+
t[e] = c(t[e]);
|
|
20
|
+
}
|
|
21
|
+
function s(t) {
|
|
22
|
+
if (typeof t != "string")
|
|
23
|
+
throw new Error("utf8ToBytes expected string, got " + typeof t);
|
|
24
|
+
return new Uint8Array(new TextEncoder().encode(t));
|
|
25
|
+
}
|
|
26
|
+
function y(t) {
|
|
27
|
+
return typeof t == "string" && (t = s(t)), i(t), t;
|
|
28
|
+
}
|
|
29
|
+
function x(...t) {
|
|
30
|
+
let e = 0;
|
|
31
|
+
for (let n = 0; n < t.length; n++) {
|
|
32
|
+
const r = t[n];
|
|
33
|
+
i(r), e += r.length;
|
|
34
|
+
}
|
|
35
|
+
const f = new Uint8Array(e);
|
|
36
|
+
for (let n = 0, r = 0; n < t.length; n++) {
|
|
37
|
+
const u = t[n];
|
|
38
|
+
f.set(u, r), r += u.length;
|
|
39
|
+
}
|
|
40
|
+
return f;
|
|
41
|
+
}
|
|
42
|
+
class h {
|
|
43
|
+
// Safe version that clones internal state
|
|
44
|
+
clone() {
|
|
45
|
+
return this._cloneInto();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function B(t) {
|
|
49
|
+
const e = (n) => t().update(y(n)).digest(), f = t();
|
|
50
|
+
return e.outputLen = f.outputLen, e.blockLen = f.blockLen, e.create = () => t(), e;
|
|
51
|
+
}
|
|
52
|
+
function d(t = 32) {
|
|
53
|
+
if (o && typeof o.getRandomValues == "function")
|
|
54
|
+
return o.getRandomValues(new Uint8Array(t));
|
|
55
|
+
if (o && typeof o.randomBytes == "function")
|
|
56
|
+
return o.randomBytes(t);
|
|
57
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
h as Hash,
|
|
61
|
+
c as byteSwap,
|
|
62
|
+
a as byteSwap32,
|
|
63
|
+
x as concatBytes,
|
|
64
|
+
m as createView,
|
|
65
|
+
b as isLE,
|
|
66
|
+
d as randomBytes,
|
|
67
|
+
w as rotr,
|
|
68
|
+
y as toBytes,
|
|
69
|
+
g as u32,
|
|
70
|
+
s as utf8ToBytes,
|
|
71
|
+
B as wrapConstructor
|
|
72
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./index109.cjs"),c=require("./index111.cjs");function a(o,t,s,i){if(typeof o.setBigUint64=="function")return o.setBigUint64(t,s,i);const n=BigInt(32),r=BigInt(4294967295),e=Number(s>>n&r),h=Number(s&r),u=i?4:0,l=i?0:4;o.setUint32(t+u,e,i),o.setUint32(t+l,h,i)}function d(o,t,s){return o&t^~o&s}function b(o,t,s){return o&t^o&s^t&s}class w extends c.Hash{constructor(t,s,i,n){super(),this.blockLen=t,this.outputLen=s,this.padOffset=i,this.isLE=n,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=c.createView(this.buffer)}update(t){p.aexists(this);const{view:s,buffer:i,blockLen:n}=this;t=c.toBytes(t);const r=t.length;for(let e=0;e<r;){const h=Math.min(n-this.pos,r-e);if(h===n){const u=c.createView(t);for(;n<=r-e;e+=n)this.process(u,e);continue}i.set(t.subarray(e,e+h),this.pos),this.pos+=h,e+=h,this.pos===n&&(this.process(s,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){p.aexists(this),p.aoutput(t,this),this.finished=!0;const{buffer:s,view:i,blockLen:n,isLE:r}=this;let{pos:e}=this;s[e++]=128,this.buffer.subarray(e).fill(0),this.padOffset>n-e&&(this.process(i,0),e=0);for(let f=e;f<n;f++)s[f]=0;a(i,n-8,BigInt(this.length*8),r),this.process(i,0);const h=c.createView(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=u/4,g=this.get();if(l>g.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)h.setUint32(4*f,g[f],r)}digest(){const{buffer:t,outputLen:s}=this;this.digestInto(t);const i=t.slice(0,s);return this.destroy(),i}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:s,buffer:i,length:n,finished:r,destroyed:e,pos:h}=this;return t.length=n,t.pos=h,t.finished=r,t.destroyed=e,n%s&&t.buffer.set(i),t}}exports.Chi=d;exports.HashMD=w;exports.Maj=b;exports.setBigUint64=a;
|
package/dist/index112.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { aexists as g, aoutput as d } from "./index109.js";
|
|
2
|
+
import { Hash as b, createView as p, toBytes as a } from "./index111.js";
|
|
3
|
+
function w(o, t, s, i) {
|
|
4
|
+
if (typeof o.setBigUint64 == "function")
|
|
5
|
+
return o.setBigUint64(t, s, i);
|
|
6
|
+
const n = BigInt(32), h = BigInt(4294967295), e = Number(s >> n & h), r = Number(s & h), u = i ? 4 : 0, c = i ? 0 : 4;
|
|
7
|
+
o.setUint32(t + u, e, i), o.setUint32(t + c, r, i);
|
|
8
|
+
}
|
|
9
|
+
function B(o, t, s) {
|
|
10
|
+
return o & t ^ ~o & s;
|
|
11
|
+
}
|
|
12
|
+
function L(o, t, s) {
|
|
13
|
+
return o & t ^ o & s ^ t & s;
|
|
14
|
+
}
|
|
15
|
+
class U extends b {
|
|
16
|
+
constructor(t, s, i, n) {
|
|
17
|
+
super(), this.blockLen = t, this.outputLen = s, this.padOffset = i, this.isLE = n, this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.buffer = new Uint8Array(t), this.view = p(this.buffer);
|
|
18
|
+
}
|
|
19
|
+
update(t) {
|
|
20
|
+
g(this);
|
|
21
|
+
const { view: s, buffer: i, blockLen: n } = this;
|
|
22
|
+
t = a(t);
|
|
23
|
+
const h = t.length;
|
|
24
|
+
for (let e = 0; e < h; ) {
|
|
25
|
+
const r = Math.min(n - this.pos, h - e);
|
|
26
|
+
if (r === n) {
|
|
27
|
+
const u = p(t);
|
|
28
|
+
for (; n <= h - e; e += n)
|
|
29
|
+
this.process(u, e);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
i.set(t.subarray(e, e + r), this.pos), this.pos += r, e += r, this.pos === n && (this.process(s, 0), this.pos = 0);
|
|
33
|
+
}
|
|
34
|
+
return this.length += t.length, this.roundClean(), this;
|
|
35
|
+
}
|
|
36
|
+
digestInto(t) {
|
|
37
|
+
g(this), d(t, this), this.finished = !0;
|
|
38
|
+
const { buffer: s, view: i, blockLen: n, isLE: h } = this;
|
|
39
|
+
let { pos: e } = this;
|
|
40
|
+
s[e++] = 128, this.buffer.subarray(e).fill(0), this.padOffset > n - e && (this.process(i, 0), e = 0);
|
|
41
|
+
for (let f = e; f < n; f++)
|
|
42
|
+
s[f] = 0;
|
|
43
|
+
w(i, n - 8, BigInt(this.length * 8), h), this.process(i, 0);
|
|
44
|
+
const r = p(t), u = this.outputLen;
|
|
45
|
+
if (u % 4)
|
|
46
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
47
|
+
const c = u / 4, l = this.get();
|
|
48
|
+
if (c > l.length)
|
|
49
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
50
|
+
for (let f = 0; f < c; f++)
|
|
51
|
+
r.setUint32(4 * f, l[f], h);
|
|
52
|
+
}
|
|
53
|
+
digest() {
|
|
54
|
+
const { buffer: t, outputLen: s } = this;
|
|
55
|
+
this.digestInto(t);
|
|
56
|
+
const i = t.slice(0, s);
|
|
57
|
+
return this.destroy(), i;
|
|
58
|
+
}
|
|
59
|
+
_cloneInto(t) {
|
|
60
|
+
t || (t = new this.constructor()), t.set(...this.get());
|
|
61
|
+
const { blockLen: s, buffer: i, length: n, finished: h, destroyed: e, pos: r } = this;
|
|
62
|
+
return t.length = n, t.pos = r, t.finished = h, t.destroyed = e, n % s && t.buffer.set(i), t;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
B as Chi,
|
|
67
|
+
U as HashMD,
|
|
68
|
+
L as Maj,
|
|
69
|
+
w as setBigUint64
|
|
70
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;exports.crypto=o;
|
package/dist/index113.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index109.cjs"),c=require("./index111.cjs");class r extends c.Hash{constructor(t,i){super(),this.finished=!1,this.destroyed=!1,o.ahash(t);const h=c.toBytes(i);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const a=this.blockLen,e=new Uint8Array(a);e.set(h.length>a?t.create().update(h).digest():h);for(let s=0;s<e.length;s++)e[s]^=54;this.iHash.update(e),this.oHash=t.create();for(let s=0;s<e.length;s++)e[s]^=106;this.oHash.update(e),e.fill(0)}update(t){return o.aexists(this),this.iHash.update(t),this}digestInto(t){o.aexists(this),o.abytes(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:i,iHash:h,finished:a,destroyed:e,blockLen:s,outputLen:u}=this;return t=t,t.finished=a,t.destroyed=e,t.blockLen=s,t.outputLen=u,t.oHash=i._cloneInto(t.oHash),t.iHash=h._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const d=(n,t,i)=>new r(n,t).update(i).digest();d.create=(n,t)=>new r(n,t);exports.HMAC=r;exports.hmac=d;
|