OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-identity commits / 85c124d

Add browser identity module (BrowserIdentity class)
Self-contained browser auth: keypair management, challenge-response signing, token storage, user fetch. No dependency on other packages. Export: import { BrowserIdentity } from 'hyper-identity/browser' Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
85c124d6729b84f8fa473d3ea71ef80cae9131e7
by plankatron <fleeky@gmail.com> · 2026-03-30T22:02:24.000Z

Changed files (6) +214 -374

lib/anproto-client.js +9 -0
……@@ -9,6 +9,15 @@
99 */
1010
1111import * as ed from './vendor/noble-ed25519.js'
12import { sha512 } from './vendor/noble-sha512.js'
13
14// Wire pure-JS SHA-512 into noble-ed25519 (replaces crypto.subtle dependency)
15ed.etc.sha512Sync = (...msgs) => {
16 const h = sha512.create()
17 for (const m of msgs) h.update(m)
18 return h.digest()
19}
20ed.etc.sha512Async = async (...msgs) => ed.etc.sha512Sync(...msgs)
1221
1322export const ANProtoClient = {
1423 /**
lib/browser-identity.js +179 -0
……@@ -0,0 +1,179 @@
1/**
2 * Browser Identity — complete browser-side authentication module
3 *
4 * Self-contained: uses ANProtoClient for crypto, does its own fetch calls.
5 * No dependency on hyper-web-ui or any other package.
6 *
7 * Usage:
8 * import { BrowserIdentity } from 'hyper-identity/browser'
9 * const identity = new BrowserIdentity()
10 * await identity.authenticate()
11 * const me = await identity.getMe()
12 */
13
14import { ANProtoClient } from './anproto-client.js'
15
16const DEFAULT_KEYPAIR_KEY = 'hyper-identity-keypair'
17const DEFAULT_TOKEN_KEY = 'hyper-identity-token'
18
19export class BrowserIdentity {
20 constructor (opts = {}) {
21 this._keypairKey = opts.storageKey || DEFAULT_KEYPAIR_KEY
22 this._tokenKey = opts.tokenKey || DEFAULT_TOKEN_KEY
23 this._baseUrl = opts.baseUrl || ''
24 this._keypair = null
25 }
26
27 /**
28 * Get or create Ed25519 keypair (stored in localStorage)
29 */
30 async getKeypair () {
31 if (this._keypair) return this._keypair
32
33 const stored = typeof localStorage !== 'undefined' && localStorage.getItem(this._keypairKey)
34 if (stored && stored.length === 132) {
35 this._keypair = stored
36 return this._keypair
37 }
38
39 this._keypair = await ANProtoClient.gen()
40 if (typeof localStorage !== 'undefined') {
41 localStorage.setItem(this._keypairKey, this._keypair)
42 }
43 return this._keypair
44 }
45
46 /**
47 * Get public key as hex (for API calls)
48 */
49 async getPublicKeyHex () {
50 const kp = await this.getKeypair()
51 return ANProtoClient.getPublicKeyHex(kp)
52 }
53
54 /**
55 * Get public key as base64 (for display)
56 */
57 async getPublicKeyB64 () {
58 const kp = await this.getKeypair()
59 return ANProtoClient.getPublicKey(kp)
60 }
61
62 /**
63 * Sign a challenge string
64 */
65 async sign (challenge) {
66 const kp = await this.getKeypair()
67 return ANProtoClient.sign(challenge, kp)
68 }
69
70 /**
71 * Full authentication flow: challenge → sign → verify → token
72 */
73 async authenticate () {
74 const publicKey = await this.getPublicKeyHex()
75
76 // 1. Get challenge
77 const challengeRes = await this._fetch('/api/auth/challenge')
78 const { challengeId, challenge } = challengeRes
79
80 // 2. Sign it
81 const signature = await this.sign(challenge)
82
83 // 3. Verify with server
84 const result = await this._fetch('/api/auth/verify', {
85 method: 'POST',
86 body: { publicKey, signature, challengeId }
87 })
88
89 // 4. Store token
90 this.storeToken(result.token)
91
92 return result
93 }
94
95 /**
96 * Store auth token
97 */
98 storeToken (token) {
99 if (typeof localStorage !== 'undefined') {
100 localStorage.setItem(this._tokenKey, token)
101 }
102 }
103
104 /**
105 * Get stored token
106 */
107 getToken () {
108 if (typeof localStorage === 'undefined') return null
109 return localStorage.getItem(this._tokenKey)
110 }
111
112 /**
113 * Check if authenticated
114 */
115 isAuthenticated () {
116 return !!this.getToken()
117 }
118
119 /**
120 * Fetch current user from server
121 */
122 async getMe () {
123 const token = this.getToken()
124 if (!token) return null
125
126 try {
127 return await this._fetch('/api/users/me')
128 } catch {
129 return null
130 }
131 }
132
133 /**
134 * Logout — clear token (keeps keypair)
135 */
136 logout () {
137 if (typeof localStorage !== 'undefined') {
138 localStorage.removeItem(this._tokenKey)
139 }
140 }
141
142 /**
143 * Clear everything — keypair + token
144 */
145 clearIdentity () {
146 this.logout()
147 if (typeof localStorage !== 'undefined') {
148 localStorage.removeItem(this._keypairKey)
149 }
150 this._keypair = null
151 }
152
153 /**
154 * Internal fetch with auth header
155 */
156 async _fetch (path, opts = {}) {
157 const url = this._baseUrl + path
158 const headers = { Accept: 'application/json' }
159 const token = this.getToken()
160 if (token) headers.Authorization = `Bearer ${token}`
161
162 const fetchOpts = { headers }
163 if (opts.method) fetchOpts.method = opts.method
164 if (opts.body) {
165 fetchOpts.method = fetchOpts.method || 'POST'
166 headers['Content-Type'] = 'application/json'
167 fetchOpts.body = JSON.stringify(opts.body)
168 }
169
170 const res = await fetch(url, fetchOpts)
171 if (!res.ok) {
172 const text = await res.text()
173 throw new Error(`${res.status} ${text}`)
174 }
175 return res.json()
176 }
177}
178
179export default BrowserIdentity
lib/vendor/noble-crypto.js +8 -0
……@@ -0,0 +1,8 @@
1/**
2 * Bundled by jsDelivr using Rollup v2.79.2 and Terser v5.39.0.
3 * Original file: /npm/@noble/hashes@1.3.0/esm/crypto.js
4 *
5 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
6 */
7const o="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;export{o as crypto};export default null;
8//# sourceMappingURL=/sm/c89c3eead1f3ff4004cc3626795fb3273c573384fdf3d96f44a89e5143a967f7.map
lib/vendor/noble-ed25519.js +8 -373
……@@ -1,374 +1,9 @@
1/**
2 * Bundled by jsDelivr using Rollup v2.79.2 and Terser v5.39.0.
3 * Original file: /npm/@noble/ed25519@2.0.0/index.js
4 *
5 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
6 */
17/*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
2const P = 2n ** 255n - 19n; // ed25519 is twisted edwards curve
3const N = 2n ** 252n + 27742317777372353535851937790883648493n; // curve's (group) order
4const Gx = 0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an; // base point x
5const Gy = 0x6666666666666666666666666666666666666666666666666666666666666658n; // base point y
6const CURVE = {
7 a: -1n,
8 d: 37095705934669439343138083508754565189542113879843219016388785533085940283555n,
9 p: P, n: N, h: 8, Gx, Gy // field prime, curve (group) order, cofactor
10};
11const err = (m = '') => { throw new Error(m); }; // error helper, messes-up stack trace
12const str = (s) => typeof s === 'string'; // is string
13const au8 = (a, l) => // is Uint8Array (of specific length)
14 !(a instanceof Uint8Array) || (typeof l === 'number' && l > 0 && a.length !== l) ?
15 err('Uint8Array expected') : a;
16const u8n = (data) => new Uint8Array(data); // creates Uint8Array
17const toU8 = (a, len) => au8(str(a) ? h2b(a) : u8n(a), len); // norm(hex/u8a) to u8a
18const mod = (a, b = P) => { let r = a % b; return r >= 0n ? r : b + r; }; // mod division
19const isPoint = (p) => (p instanceof Point ? p : err('Point expected')); // is xyzt point
20let Gpows = undefined; // precomputes for base point G
21class Point {
22 constructor(ex, ey, ez, et) {
23 this.ex = ex;
24 this.ey = ey;
25 this.ez = ez;
26 this.et = et;
27 }
28 static fromAffine(p) { return new Point(p.x, p.y, 1n, mod(p.x * p.y)); }
29 static fromHex(hex, strict = true) {
30 const { d } = CURVE;
31 hex = toU8(hex, 32);
32 const normed = hex.slice(); // copy the array to not mess it up
33 normed[31] = hex[31] & ~0x80; // adjust first LE byte = last BE byte
34 const y = b2n_LE(normed); // decode as little-endian, convert to num
35 if (y === 0n) { // y=0 is valid, proceed
36 }
37 else {
38 if (strict && !(0n < y && y < P))
39 err('bad y coord 1'); // strict=true [1..P-1]
40 if (!strict && !(0n < y && y < 2n ** 256n))
41 err('bad y coord 2'); // strict=false [1..2^256-1]
42 }
43 const y2 = mod(y * y); // y²
44 const u = mod(y2 - 1n); // u=y²-1
45 const v = mod(d * y2 + 1n); // v=dy²+1
46 let { isValid, value: x } = uvRatio(u, v); // (uv³)(uv⁷)^(p-5)/8; square root
47 if (!isValid)
48 err('bad y coordinate 3'); // not square root: bad point
49 const isXOdd = (x & 1n) === 1n; // adjust sign of x coordinate
50 const isHeadOdd = (hex[31] & 0x80) !== 0;
51 if (isHeadOdd !== isXOdd)
52 x = mod(-x);
53 return new Point(x, y, 1n, mod(x * y)); // Z=1, T=xy
54 }
55 get x() { return this.toAffine().x; } // .x, .y will call expensive toAffine.
56 get y() { return this.toAffine().y; } // Should be used with care.
57 equals(other) {
58 const { ex: X1, ey: Y1, ez: Z1 } = this;
59 const { ex: X2, ey: Y2, ez: Z2 } = isPoint(other); // isPoint() checks class equality
60 const X1Z2 = mod(X1 * Z2), X2Z1 = mod(X2 * Z1);
61 const Y1Z2 = mod(Y1 * Z2), Y2Z1 = mod(Y2 * Z1);
62 return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
63 }
64 is0() { return this.equals(I); }
65 negate() {
66 return new Point(mod(-this.ex), this.ey, this.ez, mod(-this.et));
67 }
68 double() {
69 const { ex: X1, ey: Y1, ez: Z1 } = this; // Cost: 4M + 4S + 1*a + 6add + 1*2
70 const { a } = CURVE; // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#doubling-dbl-2008-hwcd
71 const A = mod(X1 * X1);
72 const B = mod(Y1 * Y1);
73 const C = mod(2n * mod(Z1 * Z1));
74 const D = mod(a * A);
75 const x1y1 = X1 + Y1;
76 const E = mod(mod(x1y1 * x1y1) - A - B);
77 const G = D + B;
78 const F = G - C;
79 const H = D - B;
80 const X3 = mod(E * F);
81 const Y3 = mod(G * H);
82 const T3 = mod(E * H);
83 const Z3 = mod(F * G);
84 return new Point(X3, Y3, Z3, T3);
85 }
86 add(other) {
87 const { ex: X1, ey: Y1, ez: Z1, et: T1 } = this; // Cost: 8M + 1*k + 8add + 1*2.
88 const { ex: X2, ey: Y2, ez: Z2, et: T2 } = isPoint(other); // doesn't check if other on-curve
89 const { a, d } = CURVE; // http://hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html#addition-add-2008-hwcd-3
90 const A = mod(X1 * X2);
91 const B = mod(Y1 * Y2);
92 const C = mod(T1 * d * T2);
93 const D = mod(Z1 * Z2);
94 const E = mod((X1 + Y1) * (X2 + Y2) - A - B);
95 const F = mod(D - C);
96 const G = mod(D + C);
97 const H = mod(B - a * A);
98 const X3 = mod(E * F);
99 const Y3 = mod(G * H);
100 const T3 = mod(E * H);
101 const Z3 = mod(F * G);
102 return new Point(X3, Y3, Z3, T3);
103 }
104 mul(n, safe = true) {
105 if (n === 0n)
106 return safe === true ? err('cannot multiply by 0') : I;
107 if (!(typeof n === 'bigint' && 0n < n && n < N))
108 err('invalid scalar, must be < L');
109 if (!safe && this.is0() || n === 1n)
110 return this; // safe=true bans 0. safe=false allows 0.
111 if (this.equals(G))
112 return wNAF(n).p; // use wNAF precomputes for base points
113 let p = I, f = G; // init result point & fake point
114 for (let d = this; n > 0n; d = d.double(), n >>= 1n) { // double-and-add ladder
115 if (n & 1n)
116 p = p.add(d); // if bit is present, add to point
117 else if (safe)
118 f = f.add(d); // if not, add to fake for timing safety
119 }
120 return p;
121 }
122 multiply(scalar) { return this.mul(scalar); } // Aliases for compatibilty
123 clearCofactor() { return this.mul(BigInt(CURVE.h), false); } // multiply by cofactor
124 isSmallOrder() { return this.clearCofactor().is0(); } // check if P is small order
125 isTorsionFree() {
126 let p = this.mul(N / 2n, false).double(); // ensures the point is not "bad".
127 if (N % 2n)
128 p = p.add(this); // P^(N+1) // P*N == (P*(N/2))*2+P
129 return p.is0();
130 }
131 toAffine() {
132 const { ex: x, ey: y, ez: z } = this; // (x, y, z, t) ∋ (x=x/z, y=y/z, t=xy)
133 if (this.is0())
134 return { x: 0n, y: 0n }; // fast-path for zero point
135 const iz = invert(z); // z^-1: invert z
136 if (mod(z * iz) !== 1n)
137 err('invalid inverse'); // (z * z^-1) must be 1, otherwise bad math
138 return { x: mod(x * iz), y: mod(y * iz) }; // x = x*z^-1; y = y*z^-1
139 }
140 toRawBytes() {
141 const { x, y } = this.toAffine(); // convert to affine 2d point
142 const b = n2b_32LE(y); // encode number to 32 bytes
143 b[31] |= x & 1n ? 0x80 : 0; // store sign in first LE byte
144 return b;
145 }
146 toHex() { return b2h(this.toRawBytes()); } // encode to hex string
147}
148Point.BASE = new Point(Gx, Gy, 1n, mod(Gx * Gy)); // Generator / Base point
149Point.ZERO = new Point(0n, 1n, 1n, 0n); // Identity / Zero point
150const { BASE: G, ZERO: I } = Point; // Generator, identity points
151const padh = (num, pad) => num.toString(16).padStart(pad, '0');
152const b2h = (b) => Array.from(b).map(e => padh(e, 2)).join(''); // bytes to hex
153const h2b = (hex) => {
154 const l = hex.length; // error if not string,
155 if (!str(hex) || l % 2)
156 err('hex invalid 1'); // or has odd length like 3, 5.
157 const arr = u8n(l / 2); // create result array
158 for (let i = 0; i < arr.length; i++) {
159 const j = i * 2;
160 const h = hex.slice(j, j + 2); // hexByte. slice is faster than substr
161 const b = Number.parseInt(h, 16); // byte, created from string part
162 if (Number.isNaN(b) || b < 0)
163 err('hex invalid 2'); // byte must be valid 0 <= byte < 256
164 arr[i] = b;
165 }
166 return arr;
167};
168const n2b_32LE = (num) => h2b(padh(num, 32 * 2)).reverse(); // number to bytes LE
169const b2n_LE = (b) => BigInt('0x' + b2h(u8n(au8(b)).reverse())); // bytes LE to num
170const concatB = (...arrs) => {
171 const r = u8n(arrs.reduce((sum, a) => sum + au8(a).length, 0)); // create u8a of summed length
172 let pad = 0; // walk through each array,
173 arrs.forEach(a => { r.set(a, pad); pad += a.length; }); // ensure they have proper type
174 return r;
175};
176const invert = (num, md = P) => {
177 if (num === 0n || md <= 0n)
178 err('no inverse n=' + num + ' mod=' + md); // no neg exponent for now
179 let a = mod(num, md), b = md, x = 0n, y = 1n, u = 1n, v = 0n;
180 while (a !== 0n) { // uses euclidean gcd algorithm
181 const q = b / a, r = b % a; // not constant-time
182 const m = x - u * q, n = y - v * q;
183 b = a, a = r, x = u, y = v, u = m, v = n;
184 }
185 return b === 1n ? mod(x, md) : err('no inverse'); // b is gcd at this point
186};
187const pow2 = (x, power) => {
188 let r = x;
189 while (power-- > 0n) {
190 r *= r;
191 r %= P;
192 }
193 return r;
194};
195const pow_2_252_3 = (x) => {
196 const x2 = (x * x) % P; // x^2, bits 1
197 const b2 = (x2 * x) % P; // x^3, bits 11
198 const b4 = (pow2(b2, 2n) * b2) % P; // x^(2^4-1), bits 1111
199 const b5 = (pow2(b4, 1n) * x) % P; // x^(2^5-1), bits 11111
200 const b10 = (pow2(b5, 5n) * b5) % P; // x^(2^10)
201 const b20 = (pow2(b10, 10n) * b10) % P; // x^(2^20)
202 const b40 = (pow2(b20, 20n) * b20) % P; // x^(2^40)
203 const b80 = (pow2(b40, 40n) * b40) % P; // x^(2^80)
204 const b160 = (pow2(b80, 80n) * b80) % P; // x^(2^160)
205 const b240 = (pow2(b160, 80n) * b80) % P; // x^(2^240)
206 const b250 = (pow2(b240, 10n) * b10) % P; // x^(2^250)
207 const pow_p_5_8 = (pow2(b250, 2n) * x) % P; // < To pow to (p+3)/8, multiply it by x.
208 return { pow_p_5_8, b2 };
209};
210const RM1 = 19681161376707505956807079304988542015446066515923890162744021073123829784752n; // √-1
211const uvRatio = (u, v) => {
212 const v3 = mod(v * v * v); // v³
213 const v7 = mod(v3 * v3 * v); // v⁷
214 const pow = pow_2_252_3(u * v7).pow_p_5_8; // (uv⁷)^(p-5)/8
215 let x = mod(u * v3 * pow); // (uv³)(uv⁷)^(p-5)/8
216 const vx2 = mod(v * x * x); // vx²
217 const root1 = x; // First root candidate
218 const root2 = mod(x * RM1); // Second root candidate; RM1 is √-1
219 const useRoot1 = vx2 === u; // If vx² = u (mod p), x is a square root
220 const useRoot2 = vx2 === mod(-u); // If vx² = -u, set x <-- x * 2^((p-1)/4)
221 const noRoot = vx2 === mod(-u * RM1); // There is no valid root, vx² = -u√-1
222 if (useRoot1)
223 x = root1;
224 if (useRoot2 || noRoot)
225 x = root2; // We return root2 anyway, for const-time
226 if ((mod(x) & 1n) === 1n)
227 x = mod(-x); // edIsNegative
228 return { isValid: useRoot1 || useRoot2, value: x };
229};
230const modL_LE = (hash) => mod(b2n_LE(hash), N); // modulo L; but little-endian
231let _shaS;
232const sha512a = (...m) => etc.sha512Async(...m); // Async SHA512
233const sha512s = (...m) => // Sync SHA512, not set by default
234 typeof _shaS === 'function' ? _shaS(...m) : err('etc.sha512Sync not set');
235const hash2extK = (hashed) => {
236 const head = hashed.slice(0, 32); // slice creates a copy, unlike subarray
237 head[0] &= 248; // Clamp bits: 0b1111_1000,
238 head[31] &= 127; // 0b0111_1111,
239 head[31] |= 64; // 0b0100_0000
240 const prefix = hashed.slice(32, 64); // private key "prefix"
241 const scalar = modL_LE(head); // modular division over curve order
242 const point = G.mul(scalar); // public key point
243 const pointBytes = point.toRawBytes(); // point serialized to Uint8Array
244 return { head, prefix, scalar, point, pointBytes };
245};
246// RFC8032 5.1.5; getPublicKey async, sync. Hash priv key and extract point.
247const getExtendedPublicKeyAsync = (priv) => sha512a(toU8(priv, 32)).then(hash2extK);
248const getExtendedPublicKey = (priv) => hash2extK(sha512s(toU8(priv, 32)));
249const getPublicKeyAsync = (priv) => getExtendedPublicKeyAsync(priv).then(p => p.pointBytes);
250const getPublicKey = (priv) => getExtendedPublicKey(priv).pointBytes;
251function hashFinish(asynchronous, res) {
252 if (asynchronous)
253 return sha512a(res.hashable).then(res.finish);
254 return res.finish(sha512s(res.hashable));
255}
256const _sign = (e, rBytes, msg) => {
257 const { pointBytes: P, scalar: s } = e;
258 const r = modL_LE(rBytes); // r was created outside, reduce it modulo L
259 const R = G.mul(r).toRawBytes(); // R = [r]B
260 const hashable = concatB(R, P, msg); // dom2(F, C) || R || A || PH(M)
261 const finish = (hashed) => {
262 const S = mod(r + modL_LE(hashed) * s, N); // S = (r + k * s) mod L; 0 <= s < l
263 return au8(concatB(R, n2b_32LE(S)), 64); // 64-byte sig: 32b R.x + 32b LE(S)
264 };
265 return { hashable, finish };
266};
267const signAsync = async (msg, privKey) => {
268 const m = toU8(msg); // RFC8032 5.1.6: sign msg with key async
269 const e = await getExtendedPublicKeyAsync(privKey); // pub,prfx
270 const rBytes = await sha512a(e.prefix, m); // r = SHA512(dom2(F, C) || prefix || PH(M))
271 return hashFinish(true, _sign(e, rBytes, m)); // gen R, k, S, then 64-byte signature
272};
273const sign = (msg, privKey) => {
274 const m = toU8(msg); // RFC8032 5.1.6: sign msg with key sync
275 const e = getExtendedPublicKey(privKey); // pub,prfx
276 const rBytes = sha512s(e.prefix, m); // r = SHA512(dom2(F, C) || prefix || PH(M))
277 return hashFinish(false, _sign(e, rBytes, m)); // gen R, k, S, then 64-byte signature
278};
279const _verify = (sig, msg, pub) => {
280 msg = toU8(msg); // Message hex str/Bytes
281 sig = toU8(sig, 64); // Signature hex str/Bytes, must be 64 bytes
282 const A = Point.fromHex(pub, false); // public key A decoded
283 const R = Point.fromHex(sig.slice(0, 32), false); // 0 <= R < 2^256: ZIP215 R can be >= P
284 const s = b2n_LE(sig.slice(32, 64)); // Decode second half as an integer S
285 const SB = G.mul(s, false); // in the range 0 <= s < L
286 const hashable = concatB(R.toRawBytes(), A.toRawBytes(), msg); // dom2(F, C) || R || A || PH(M)
287 const finish = (hashed) => {
288 const k = modL_LE(hashed); // decode in little-endian, modulo L
289 const RkA = R.add(A.mul(k, false)); // [8]R + [8][k]A'
290 return RkA.add(SB.negate()).clearCofactor().is0(); // [8][S]B = [8]R + [8][k]A'
291 };
292 return { hashable, finish };
293};
294// RFC8032 5.1.7: verification async, sync
295const verifyAsync = async (s, m, p) => hashFinish(true, _verify(s, m, p));
296const verify = (s, m, p) => hashFinish(false, _verify(s, m, p));
297const cr = () => // We support: 1) browsers 2) node.js 19+
298 typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined;
299const etc = {
300 bytesToHex: b2h, hexToBytes: h2b, concatBytes: concatB,
301 mod, invert,
302 randomBytes: (len) => {
303 const crypto = cr(); // Can be shimmed in node.js <= 18 to prevent error:
304 // import { webcrypto } from 'node:crypto';
305 // if (!globalThis.crypto) globalThis.crypto = webcrypto;
306 if (!crypto)
307 err('crypto.getRandomValues must be defined');
308 return crypto.getRandomValues(u8n(len));
309 },
310 sha512Async: async (...messages) => {
311 const crypto = cr();
312 if (!crypto)
313 err('crypto.subtle or etc.sha512Async must be defined');
314 const m = concatB(...messages);
315 return u8n(await crypto.subtle.digest('SHA-512', m.buffer));
316 },
317 sha512Sync: undefined, // Actual logic below
318};
319Object.defineProperties(etc, { sha512Sync: {
320 configurable: false, get() { return _shaS; }, set(f) { if (!_shaS)
321 _shaS = f; },
322 } });
323const utils = {
324 getExtendedPublicKeyAsync, getExtendedPublicKey,
325 randomPrivateKey: () => etc.randomBytes(32),
326 precompute(w = 8, p = G) { p.multiply(3n); return p; }, // no-op
327};
328const W = 8; // Precomputes-related code. W = window size
329const precompute = () => {
330 const points = []; // 10x sign(), 2x verify(). To achieve this,
331 const windows = 256 / W + 1; // app needs to spend 40ms+ to calculate
332 let p = G, b = p; // a lot of points related to base point G.
333 for (let w = 0; w < windows; w++) { // Points are stored in array and used
334 b = p; // any time Gx multiplication is done.
335 points.push(b); // They consume 16-32 MiB of RAM.
336 for (let i = 1; i < 2 ** (W - 1); i++) {
337 b = b.add(p);
338 points.push(b);
339 }
340 p = b.double(); // Precomputes don't speed-up getSharedKey,
341 } // which multiplies user point by scalar,
342 return points; // when precomputes are using base point
343};
344const wNAF = (n) => {
345 // Compared to other point mult methods,
346 const comp = Gpows || (Gpows = precompute()); // stores 2x less points using subtraction
347 const neg = (cnd, p) => { let n = p.negate(); return cnd ? n : p; }; // negate
348 let p = I, f = G; // f must be G, or could become I in the end
349 const windows = 1 + 256 / W; // W=8 17 windows
350 const wsize = 2 ** (W - 1); // W=8 128 window size
351 const mask = BigInt(2 ** W - 1); // W=8 will create mask 0b11111111
352 const maxNum = 2 ** W; // W=8 256
353 const shiftBy = BigInt(W); // W=8 8
354 for (let w = 0; w < windows; w++) {
355 const off = w * wsize;
356 let wbits = Number(n & mask); // extract W bits.
357 n >>= shiftBy; // shift number by W bits.
358 if (wbits > wsize) {
359 wbits -= maxNum;
360 n += 1n;
361 } // split if bits > max: +224 => 256-32
362 const off1 = off, off2 = off + Math.abs(wbits) - 1; // offsets, evaluate both
363 const cnd1 = w % 2 !== 0, cnd2 = wbits < 0; // conditions, evaluate both
364 if (wbits === 0) {
365 f = f.add(neg(cnd1, comp[off1])); // bits are 0: add garbage to fake point
366 }
367 else { // ^ can't add off2, off2 = I
368 p = p.add(neg(cnd2, comp[off2])); // bits are 1: add to result point
369 }
370 }
371 return { p, f }; // return both real and fake points for JIT
372}; // !! you can disable precomputes by commenting-out call of the wNAF() inside Point#mul()
373export { getPublicKey, getPublicKeyAsync, sign, verify, // Remove the export to easily use in REPL
374signAsync, verifyAsync, CURVE, etc, utils, Point as ExtendedPoint }; // envs like browser console
8const t=2n**255n-19n,e=2n**252n+27742317777372353535851937790883648493n,n=0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,r=0x6666666666666666666666666666666666666666666666666666666666666658n,s={a:-1n,d:37095705934669439343138083508754565189542113879843219016388785533085940283555n,p:t,n:e,h:8,Gx:n,Gy:r},o=(t="")=>{throw new Error(t)},i=t=>"string"==typeof t,a=(t,e)=>!(t instanceof Uint8Array)||"number"==typeof e&&e>0&&t.length!==e?o("Uint8Array expected"):t,c=t=>new Uint8Array(t),l=(t,e)=>a(i(t)?m(t):c(t),e),u=(e,n=t)=>{let r=e%n;return r>=0n?r:n+r},d=t=>t instanceof y?t:o("Point expected");let h;class y{constructor(t,e,n,r){this.ex=t,this.ey=e,this.ez=n,this.et=r}static fromAffine(t){return new y(t.x,t.y,1n,u(t.x*t.y))}static fromHex(e,n=!0){const{d:r}=s,i=(e=l(e,32)).slice();i[31]=-129&e[31];const a=w(i);0n===a||(!n||0n<a&&a<t||o("bad y coord 1"),n||0n<a&&a<2n**256n||o("bad y coord 2"));const c=u(a*a),d=u(c-1n),h=u(r*c+1n);let{isValid:f,value:p}=E(d,h);f||o("bad y coordinate 3");const x=1n===(1n&p);return!!(128&e[31])!==x&&(p=u(-p)),new y(p,a,1n,u(p*a))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}equals(t){const{ex:e,ey:n,ez:r}=this,{ex:s,ey:o,ez:i}=d(t),a=u(e*i),c=u(s*r),l=u(n*i),h=u(o*r);return a===c&&l===h}is0(){return this.equals(p)}negate(){return new y(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){const{ex:t,ey:e,ez:n}=this,{a:r}=s,o=u(t*t),i=u(e*e),a=u(2n*u(n*n)),c=u(r*o),l=t+e,d=u(u(l*l)-o-i),h=c+i,f=h-a,p=c-i,x=u(d*f),b=u(h*p),m=u(d*p),g=u(f*h);return new y(x,b,g,m)}add(t){const{ex:e,ey:n,ez:r,et:o}=this,{ex:i,ey:a,ez:c,et:l}=d(t),{a:h,d:f}=s,p=u(e*i),x=u(n*a),b=u(o*f*l),m=u(r*c),g=u((e+n)*(i+a)-p-x),w=u(m-b),B=u(m+b),A=u(x-h*p),v=u(g*w),R=u(B*A),E=u(g*A),S=u(w*B);return new y(v,R,S,E)}mul(t,n=!0){if(0n===t)return!0===n?o("cannot multiply by 0"):p;if("bigint"==typeof t&&0n<t&&t<e||o("invalid scalar, must be < L"),!n&&this.is0()||1n===t)return this;if(this.equals(f))return M(t).p;let r=p,s=f;for(let e=this;t>0n;e=e.double(),t>>=1n)1n&t?r=r.add(e):n&&(s=s.add(e));return r}multiply(t){return this.mul(t)}clearCofactor(){return this.mul(BigInt(s.h),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let t=this.mul(e/2n,!1).double();return t=t.add(this),t.is0()}toAffine(){const{ex:t,ey:e,ez:n}=this;if(this.is0())return{x:0n,y:0n};const r=A(n);return 1n!==u(n*r)&&o("invalid inverse"),{x:u(t*r),y:u(e*r)}}toRawBytes(){const{x:t,y:e}=this.toAffine(),n=g(e);return n[31]|=1n&t?128:0,n}toHex(){return b(this.toRawBytes())}}y.BASE=new y(n,r,1n,u(n*r)),y.ZERO=new y(0n,1n,1n,0n);const{BASE:f,ZERO:p}=y,x=(t,e)=>t.toString(16).padStart(e,"0"),b=t=>Array.from(t).map((t=>x(t,2))).join(""),m=t=>{const e=t.length;(!i(t)||e%2)&&o("hex invalid 1");const n=c(e/2);for(let e=0;e<n.length;e++){const r=2*e,s=t.slice(r,r+2),i=Number.parseInt(s,16);(Number.isNaN(i)||i<0)&&o("hex invalid 2"),n[e]=i}return n},g=t=>m(x(t,64)).reverse(),w=t=>BigInt("0x"+b(c(a(t)).reverse())),B=(...t)=>{const e=c(t.reduce(((t,e)=>t+a(e).length),0));let n=0;return t.forEach((t=>{e.set(t,n),n+=t.length})),e},A=(e,n=t)=>{(0n===e||n<=0n)&&o("no inverse n="+e+" mod="+n);let r=u(e,n),s=n,i=0n,a=1n;for(;0n!==r;){const t=s%r,e=i-a*(s/r);s=r,r=t,i=a,a=e}return 1n===s?u(i,n):o("no inverse")},v=(e,n)=>{let r=e;for(;n-- >0n;)r*=r,r%=t;return r},R=19681161376707505956807079304988542015446066515923890162744021073123829784752n,E=(e,n)=>{const r=u(n*n*n),s=(e=>{const n=e*e%t*e%t,r=v(n,2n)*n%t,s=v(r,1n)*e%t,o=v(s,5n)*s%t,i=v(o,10n)*o%t,a=v(i,20n)*i%t,c=v(a,40n)*a%t,l=v(c,80n)*c%t,u=v(l,80n)*c%t,d=v(u,10n)*o%t;return{pow_p_5_8:v(d,2n)*e%t,b2:n}})(e*u(r*r*n)).pow_p_5_8;let o=u(e*r*s);const i=u(n*o*o),a=o,c=u(o*R),l=i===e,d=i===u(-e),h=i===u(-e*R);return l&&(o=a),(d||h)&&(o=c),1n===(1n&u(o))&&(o=u(-o)),{isValid:l||d,value:o}},S=t=>u(w(t),e);let z;const H=(...t)=>F.sha512Async(...t),P=(...t)=>"function"==typeof z?z(...t):o("etc.sha512Sync not set"),T=t=>{const e=t.slice(0,32);e[0]&=248,e[31]&=127,e[31]|=64;const n=t.slice(32,64),r=S(e),s=f.mul(r),o=s.toRawBytes();return{head:e,prefix:n,scalar:r,point:s,pointBytes:o}},_=t=>H(l(t,32)).then(T),I=t=>T(P(l(t,32))),N=t=>_(t).then((t=>t.pointBytes)),O=t=>I(t).pointBytes;function V(t,e){return t?H(e.hashable).then(e.finish):e.finish(P(e.hashable))}const j=(t,n,r)=>{const{pointBytes:s,scalar:o}=t,i=S(n),c=f.mul(i).toRawBytes();return{hashable:B(c,s,r),finish:t=>{const n=u(i+S(t)*o,e);return a(B(c,g(n)),64)}}},q=async(t,e)=>{const n=l(t),r=await _(e),s=await H(r.prefix,n);return V(!0,j(r,s,n))},C=(t,e)=>{const n=l(t),r=I(e),s=P(r.prefix,n);return V(!1,j(r,s,n))},K=(t,e,n)=>{e=l(e),t=l(t,64);const r=y.fromHex(n,!1),s=y.fromHex(t.slice(0,32),!1),o=w(t.slice(32,64)),i=f.mul(o,!1);return{hashable:B(s.toRawBytes(),r.toRawBytes(),e),finish:t=>{const e=S(t);return s.add(r.mul(e,!1)).add(i.negate()).clearCofactor().is0()}}},U=async(t,e,n)=>V(!0,K(t,e,n)),G=(t,e,n)=>V(!1,K(t,e,n)),Z=()=>"object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,F={bytesToHex:b,hexToBytes:m,concatBytes:B,mod:u,invert:A,randomBytes:t=>{const e=Z();return e||o("crypto.getRandomValues must be defined"),e.getRandomValues(c(t))},sha512Async:async(...t)=>{const e=Z();e||o("crypto.subtle or etc.sha512Async must be defined");const n=B(...t);return c(await e.subtle.digest("SHA-512",n.buffer))},sha512Sync:void 0};Object.defineProperties(F,{sha512Sync:{configurable:!1,get:()=>z,set(t){z||(z=t)}}});const L={getExtendedPublicKeyAsync:_,getExtendedPublicKey:I,randomPrivateKey:()=>F.randomBytes(32),precompute:(t=8,e=f)=>(e.multiply(3n),e)},M=t=>{const e=h||(h=(()=>{const t=[];let e=f,n=e;for(let r=0;r<33;r++){n=e,t.push(n);for(let r=1;r<128;r++)n=n.add(e),t.push(n);e=n.double()}return t})()),n=(t,e)=>{let n=e.negate();return t?n:e};let r=p,s=f;const o=BigInt(255),i=BigInt(8);for(let a=0;a<33;a++){const c=128*a;let l=Number(t&o);t>>=i,l>128&&(l-=256,t+=1n);const u=c,d=c+Math.abs(l)-1,h=a%2!=0,y=l<0;0===l?s=s.add(n(h,e[u])):r=r.add(n(y,e[d]))}return{p:r,f:s}};export{s as CURVE,y as ExtendedPoint,F as etc,O as getPublicKey,N as getPublicKeyAsync,C as sign,q as signAsync,L as utils,G as verify,U as verifyAsync};export default null;
9//# sourceMappingURL=/sm/cd01a92102818c7c46dbe0b9ea67492dd1f0856266ce83a45f80684e6e019347.map
lib/vendor/noble-sha512.js +8 -0
……@@ -0,0 +1,8 @@
1/**
2 * Bundled by jsDelivr using Rollup v2.79.2 and Terser v5.39.0.
3 * Original file: /npm/@noble/hashes@1.3.0/esm/sha512.js
4 *
5 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
6 */
7import"./noble-crypto.js";function t(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function e(t,...e){if(!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new TypeError(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}const s={number:t,bool:function(t){if("boolean"!=typeof t)throw new Error(`Expected boolean, not ${t}`)},bytes:e,hash:function(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");t(e.outputLen),t(e.blockLen)},exists:function(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")},output:function(t,s){e(t);const h=s.outputLen;if(t.length<h)throw new Error(`digestInto() expects output buffer of length at least ${h}`)}},h=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);if(!(68===new Uint8Array(new Uint32Array([287454020]).buffer)[0]))throw new Error("Non little-endian hardware is not supported");function i(t){if("string"==typeof t&&(t=function(t){if("string"!=typeof t)throw new TypeError("utf8ToBytes expected string, got "+typeof t);return(new TextEncoder).encode(t)}(t)),!(t instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof t})`);return t}Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));class r{clone(){return this._cloneInto()}}function n(t){const e=e=>t().update(i(e)).digest(),s=t();return e.outputLen=s.outputLen,e.blockLen=s.blockLen,e.create=()=>t(),e}class o extends r{constructor(t,e,s,i){super(),this.blockLen=t,this.outputLen=e,this.padOffset=s,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=h(this.buffer)}update(t){s.exists(this);const{view:e,buffer:r,blockLen:n}=this,o=(t=i(t)).length;for(let s=0;s<o;){const i=Math.min(n-this.pos,o-s);if(i!==n)r.set(t.subarray(s,s+i),this.pos),this.pos+=i,s+=i,this.pos===n&&(this.process(e,0),this.pos=0);else{const e=h(t);for(;n<=o-s;s+=n)this.process(e,s)}}return this.length+=t.length,this.roundClean(),this}digestInto(t){s.exists(this),s.output(t,this),this.finished=!0;const{buffer:e,view:i,blockLen:r,isLE:n}=this;let{pos:o}=this;e[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>r-o&&(this.process(i,0),o=0);for(let t=o;t<r;t++)e[t]=0;!function(t,e,s,h){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,s,h);const i=BigInt(32),r=BigInt(4294967295),n=Number(s>>i&r),o=Number(s&r),c=h?4:0,a=h?0:4;t.setUint32(e+c,n,h),t.setUint32(e+a,o,h)}(i,r-8,BigInt(8*this.length),n),this.process(i,0);const c=h(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=a/4,d=this.get();if(f>d.length)throw new Error("_sha2: outputLen bigger than state");for(let t=0;t<f;t++)c.setUint32(4*t,d[t],n)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const s=t.slice(0,e);return this.destroy(),s}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:e,buffer:s,length:h,finished:i,destroyed:r,pos:n}=this;return t.length=h,t.pos=n,t.finished=i,t.destroyed=r,h%e&&t.buffer.set(s),t}}const c=BigInt(2**32-1),a=BigInt(32);function f(t,e=!1){return e?{h:Number(t&c),l:Number(t>>a&c)}:{h:0|Number(t>>a&c),l:0|Number(t&c)}}const d={fromBig:f,split:function(t,e=!1){let s=new Uint32Array(t.length),h=new Uint32Array(t.length);for(let i=0;i<t.length;i++){const{h:r,l:n}=f(t[i],e);[s[i],h[i]]=[r,n]}return[s,h]},toBig:(t,e)=>BigInt(t>>>0)<<a|BigInt(e>>>0),shrSH:(t,e,s)=>t>>>s,shrSL:(t,e,s)=>t<<32-s|e>>>s,rotrSH:(t,e,s)=>t>>>s|e<<32-s,rotrSL:(t,e,s)=>t<<32-s|e>>>s,rotrBH:(t,e,s)=>t<<64-s|e>>>s-32,rotrBL:(t,e,s)=>t>>>s-32|e<<64-s,rotr32H:(t,e)=>e,rotr32L:(t,e)=>t,rotlSH:(t,e,s)=>t<<s|e>>>32-s,rotlSL:(t,e,s)=>e<<s|t>>>32-s,rotlBH:(t,e,s)=>e<<s-32|t>>>64-s,rotlBL:(t,e,s)=>t<<s-32|e>>>64-s,add:function(t,e,s,h){const i=(e>>>0)+(h>>>0);return{h:t+s+(i/2**32|0)|0,l:0|i}},add3L:(t,e,s)=>(t>>>0)+(e>>>0)+(s>>>0),add3H:(t,e,s,h)=>e+s+h+(t/2**32|0)|0,add4L:(t,e,s,h)=>(t>>>0)+(e>>>0)+(s>>>0)+(h>>>0),add4H:(t,e,s,h,i)=>e+s+h+i+(t/2**32|0)|0,add5H:(t,e,s,h,i,r)=>e+s+h+i+r+(t/2**32|0)|0,add5L:(t,e,s,h,i)=>(t>>>0)+(e>>>0)+(s>>>0)+(h>>>0)+(i>>>0)},[l,b]=d.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map((t=>BigInt(t)))),u=new Uint32Array(80),x=new Uint32Array(80);class p extends o{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:t,Al:e,Bh:s,Bl:h,Ch:i,Cl:r,Dh:n,Dl:o,Eh:c,El:a,Fh:f,Fl:d,Gh:l,Gl:b,Hh:u,Hl:x}=this;return[t,e,s,h,i,r,n,o,c,a,f,d,l,b,u,x]}set(t,e,s,h,i,r,n,o,c,a,f,d,l,b,u,x){this.Ah=0|t,this.Al=0|e,this.Bh=0|s,this.Bl=0|h,this.Ch=0|i,this.Cl=0|r,this.Dh=0|n,this.Dl=0|o,this.Eh=0|c,this.El=0|a,this.Fh=0|f,this.Fl=0|d,this.Gh=0|l,this.Gl=0|b,this.Hh=0|u,this.Hl=0|x}process(t,e){for(let s=0;s<16;s++,e+=4)u[s]=t.getUint32(e),x[s]=t.getUint32(e+=4);for(let t=16;t<80;t++){const e=0|u[t-15],s=0|x[t-15],h=d.rotrSH(e,s,1)^d.rotrSH(e,s,8)^d.shrSH(e,s,7),i=d.rotrSL(e,s,1)^d.rotrSL(e,s,8)^d.shrSL(e,s,7),r=0|u[t-2],n=0|x[t-2],o=d.rotrSH(r,n,19)^d.rotrBH(r,n,61)^d.shrSH(r,n,6),c=d.rotrSL(r,n,19)^d.rotrBL(r,n,61)^d.shrSL(r,n,6),a=d.add4L(i,c,x[t-7],x[t-16]),f=d.add4H(a,h,o,u[t-7],u[t-16]);u[t]=0|f,x[t]=0|a}let{Ah:s,Al:h,Bh:i,Bl:r,Ch:n,Cl:o,Dh:c,Dl:a,Eh:f,El:p,Fh:g,Fl:w,Gh:L,Gl:H,Hh:y,Hl:B}=this;for(let t=0;t<80;t++){const e=d.rotrSH(f,p,14)^d.rotrSH(f,p,18)^d.rotrBH(f,p,41),E=d.rotrSL(f,p,14)^d.rotrSL(f,p,18)^d.rotrBL(f,p,41),A=f&g^~f&L,S=p&w^~p&H,C=d.add5L(B,E,S,b[t],x[t]),U=d.add5H(C,y,e,A,l[t],u[t]),D=0|C,F=d.rotrSH(s,h,28)^d.rotrBH(s,h,34)^d.rotrBH(s,h,39),G=d.rotrSL(s,h,28)^d.rotrBL(s,h,34)^d.rotrBL(s,h,39),m=s&i^s&n^i&n,I=h&r^h&o^r&o;y=0|L,B=0|H,L=0|g,H=0|w,g=0|f,w=0|p,({h:f,l:p}=d.add(0|c,0|a,0|U,0|D)),c=0|n,a=0|o,n=0|i,o=0|r,i=0|s,r=0|h;const N=d.add3L(D,G,I);s=d.add3H(N,U,F,m),h=0|N}({h:s,l:h}=d.add(0|this.Ah,0|this.Al,0|s,0|h)),({h:i,l:r}=d.add(0|this.Bh,0|this.Bl,0|i,0|r)),({h:n,l:o}=d.add(0|this.Ch,0|this.Cl,0|n,0|o)),({h:c,l:a}=d.add(0|this.Dh,0|this.Dl,0|c,0|a)),({h:f,l:p}=d.add(0|this.Eh,0|this.El,0|f,0|p)),({h:g,l:w}=d.add(0|this.Fh,0|this.Fl,0|g,0|w)),({h:L,l:H}=d.add(0|this.Gh,0|this.Gl,0|L,0|H)),({h:y,l:B}=d.add(0|this.Hh,0|this.Hl,0|y,0|B)),this.set(s,h,i,r,n,o,c,a,f,p,g,w,L,H,y,B)}roundClean(){u.fill(0),x.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class g extends p{constructor(){super(),this.Ah=-1942145080,this.Al=424955298,this.Bh=1944164710,this.Bl=-1982016298,this.Ch=502970286,this.Cl=855612546,this.Dh=1738396948,this.Dl=1479516111,this.Eh=258812777,this.El=2077511080,this.Fh=2011393907,this.Fl=79989058,this.Gh=1067287976,this.Gl=1780299464,this.Hh=286451373,this.Hl=-1848208735,this.outputLen=28}}class w extends p{constructor(){super(),this.Ah=573645204,this.Al=-64227540,this.Bh=-1621794909,this.Bl=-934517566,this.Ch=596883563,this.Cl=1867755857,this.Dh=-1774684391,this.Dl=1497426621,this.Eh=-1775747358,this.El=-1467023389,this.Fh=-1101128155,this.Fl=1401305490,this.Gh=721525244,this.Gl=746961066,this.Hh=246885852,this.Hl=-2117784414,this.outputLen=32}}class L extends p{constructor(){super(),this.Ah=-876896931,this.Al=-1056596264,this.Bh=1654270250,this.Bl=914150663,this.Ch=-1856437926,this.Cl=812702999,this.Dh=355462360,this.Dl=-150054599,this.Eh=1731405415,this.El=-4191439,this.Fh=-1900787065,this.Fl=1750603025,this.Gh=-619958771,this.Gl=1694076839,this.Hh=1203062813,this.Hl=-1090891868,this.outputLen=48}}const H=n((()=>new p)),y=n((()=>new g)),B=n((()=>new w)),E=n((()=>new L));export{p as SHA512,E as sha384,H as sha512,y as sha512_224,B as sha512_256};export default null;
8//# sourceMappingURL=/sm/25ef7ec32d52ab376d05edb8d663f6f9885235f7c4d8ebc8cb0aab306fd143bb.map
package.json +2 -1
……@@ -21,7 +21,8 @@
2121 "./auth/providers/web-identity": "./lib/auth/providers/web-identity.js",
2222 "./auth/providers/keet-identity": "./lib/auth/providers/keet-identity.js",
2323 "./auth/providers/bearer-token": "./lib/auth/providers/bearer-token.js",
24 "./auth/providers/ssh-key": "./lib/auth/providers/ssh-key.js"
24 "./auth/providers/ssh-key": "./lib/auth/providers/ssh-key.js",
25 "./browser": "./lib/browser-identity.js"
2526 },
2627 "dependencies": {
2728 "autobase": "^7.25.1",