@nihilium/client-sdk 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{browser.esm-kreqNYRZ-BLoDyLFh.js → browser.esm-kreqNYRZ-7qAQ13Pg.js} +18 -17
- package/dist/{browser.esm-kreqNYRZ-CV3K9CfO-DeSbuL7e.js → browser.esm-kreqNYRZ-CV3K9CfO-Crj74K-4.js} +1 -1
- package/dist/index-3PKMWW6b.js +48913 -0
- package/dist/{index-C3cHMpbE-BjZqbn-8.js → index-DEtC2xfH-DOqvYJY5.js} +97 -96
- package/dist/{index-DFD-0QrS-BD9Z8naZ.js → index-DFD-0QrS-CQSN52v_.js} +15 -14
- package/dist/{index-DFD-0QrS-DqRwsoRk-DaSQ-uF-.js → index-DFD-0QrS-T8cg-3OU-Dqbi8PAZ.js} +118 -118
- package/dist/index.d.ts +1616 -1631
- package/dist/index.mjs +34 -38
- package/dist/types-C-XvYweP.js +78196 -0
- package/dist/types.d.ts +989 -0
- package/dist/types.mjs +29 -0
- package/package.json +5 -1
- package/dist/index-78RSe_cY.js +0 -126823
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as tt, P as O, a as R, Q as et, H as I, h as Ut, K as x, N as z, z as nt, l as St, B as vt } from "./types-C-XvYweP.js";
|
|
2
2
|
/**
|
|
3
3
|
* @module @zk-kit/utils
|
|
4
4
|
* @version 1.2.1
|
|
@@ -14,14 +14,14 @@ function xt(t, e) {
|
|
|
14
14
|
if (!Et(t))
|
|
15
15
|
throw new TypeError(`Parameter '${e}' is not a Buffer instance`);
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function Pt(t) {
|
|
18
18
|
if (t <= 0)
|
|
19
19
|
throw Error(`size ${t} is too small, need at least 1`);
|
|
20
20
|
return crypto.getRandomValues(new Uint8Array(t));
|
|
21
21
|
}
|
|
22
|
-
var
|
|
22
|
+
var Kt = /* @__PURE__ */ Object.freeze({
|
|
23
23
|
__proto__: null,
|
|
24
|
-
getRandomValues:
|
|
24
|
+
getRandomValues: Pt
|
|
25
25
|
});
|
|
26
26
|
/**
|
|
27
27
|
* @module @zk-kit/utils
|
|
@@ -48,7 +48,7 @@ const Ot = [
|
|
|
48
48
|
function gt(t) {
|
|
49
49
|
return typeof t == "number";
|
|
50
50
|
}
|
|
51
|
-
function
|
|
51
|
+
function Z(t) {
|
|
52
52
|
return typeof t == "string";
|
|
53
53
|
}
|
|
54
54
|
function Rt(t) {
|
|
@@ -60,17 +60,17 @@ function G(t) {
|
|
|
60
60
|
function dt(t) {
|
|
61
61
|
return G(t) && Array.isArray(t);
|
|
62
62
|
}
|
|
63
|
-
function
|
|
63
|
+
function J(t) {
|
|
64
64
|
return t instanceof Uint8Array;
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function W(t) {
|
|
67
67
|
return I.Buffer.isBuffer(t);
|
|
68
68
|
}
|
|
69
|
-
function
|
|
69
|
+
function j(t) {
|
|
70
70
|
return typeof t == "bigint";
|
|
71
71
|
}
|
|
72
|
-
function
|
|
73
|
-
if (!
|
|
72
|
+
function X(t) {
|
|
73
|
+
if (!Z(t))
|
|
74
74
|
return !1;
|
|
75
75
|
try {
|
|
76
76
|
return BigInt(t), !0;
|
|
@@ -79,40 +79,40 @@ function Y(t) {
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
function pt(t, e = !0) {
|
|
82
|
-
return
|
|
82
|
+
return Z(t) ? e ? /^(0x|0X)[0-9a-fA-F]+$/.test(t) : /^[0-9a-fA-F]+$/.test(t) : !1;
|
|
83
83
|
}
|
|
84
|
-
function
|
|
85
|
-
return
|
|
84
|
+
function H(t) {
|
|
85
|
+
return j(t) || X(t);
|
|
86
86
|
}
|
|
87
|
-
function
|
|
88
|
-
return gt(t) ||
|
|
87
|
+
function Y(t) {
|
|
88
|
+
return gt(t) || j(t) || X(t) || pt(t) || W(t) || J(t);
|
|
89
89
|
}
|
|
90
90
|
function zt(t, e) {
|
|
91
91
|
switch (e) {
|
|
92
92
|
case "number":
|
|
93
93
|
return gt(t);
|
|
94
94
|
case "string":
|
|
95
|
-
return
|
|
95
|
+
return Z(t);
|
|
96
96
|
case "function":
|
|
97
97
|
return Rt(t);
|
|
98
98
|
case "Array":
|
|
99
99
|
return dt(t);
|
|
100
100
|
case "Uint8Array":
|
|
101
|
-
return
|
|
101
|
+
return J(t);
|
|
102
102
|
case "Buffer":
|
|
103
|
-
return
|
|
103
|
+
return W(t);
|
|
104
104
|
case "object":
|
|
105
105
|
return G(t);
|
|
106
106
|
case "bigint":
|
|
107
|
-
return
|
|
107
|
+
return j(t);
|
|
108
108
|
case "stringified-bigint":
|
|
109
|
-
return
|
|
109
|
+
return X(t);
|
|
110
110
|
case "hexadecimal":
|
|
111
111
|
return pt(t);
|
|
112
112
|
case "bignumber":
|
|
113
|
-
return
|
|
113
|
+
return H(t);
|
|
114
114
|
case "bignumberish":
|
|
115
|
-
return
|
|
115
|
+
return Y(t);
|
|
116
116
|
default:
|
|
117
117
|
return !1;
|
|
118
118
|
}
|
|
@@ -128,12 +128,12 @@ function $t(t) {
|
|
|
128
128
|
* @license MIT
|
|
129
129
|
* @see [Github]{@link https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/utils}
|
|
130
130
|
*/
|
|
131
|
-
function
|
|
132
|
-
if (!
|
|
131
|
+
function Ht(t, e) {
|
|
132
|
+
if (!j(t))
|
|
133
133
|
throw new TypeError(`Parameter '${e}' is not a bigint, received type: ${typeof t}`);
|
|
134
134
|
}
|
|
135
135
|
function wt(t, e) {
|
|
136
|
-
if (!
|
|
136
|
+
if (!Y(t))
|
|
137
137
|
throw new TypeError(`Parameter '${e}' is not a bignumber-ish`);
|
|
138
138
|
}
|
|
139
139
|
function F(t, e, r) {
|
|
@@ -153,29 +153,29 @@ function F(t, e, r) {
|
|
|
153
153
|
* @license MIT
|
|
154
154
|
* @see [Github]{@link https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/utils}
|
|
155
155
|
*/
|
|
156
|
-
function
|
|
157
|
-
|
|
156
|
+
function jt(t) {
|
|
157
|
+
Ht(t, "value");
|
|
158
158
|
let e = t.toString(16);
|
|
159
159
|
return e.length % 2 !== 0 && (e = `0${e}`), e;
|
|
160
160
|
}
|
|
161
161
|
function Ft(t) {
|
|
162
162
|
return F(t, "value", ["Buffer", "Uint8Array"]), BigInt(`0x${I.Buffer.from(t).toString("hex")}`);
|
|
163
163
|
}
|
|
164
|
-
function
|
|
164
|
+
function P(t) {
|
|
165
165
|
return F(t, "value", ["Buffer", "Uint8Array"]), BigInt(`0x${I.Buffer.from(t).reverse().toString("hex")}`);
|
|
166
166
|
}
|
|
167
167
|
function yt(t) {
|
|
168
168
|
return Ft(t);
|
|
169
169
|
}
|
|
170
170
|
function T(t, e) {
|
|
171
|
-
const r =
|
|
171
|
+
const r = jt(t), n = Math.ceil(r.length / 2);
|
|
172
172
|
if (e < n)
|
|
173
173
|
throw Error(`Size ${e} is too small, need at least ${n} bytes`);
|
|
174
174
|
const g = I.Buffer.alloc(e, 0);
|
|
175
175
|
return I.Buffer.from(r, "hex").reverse().copy(g, 0), g;
|
|
176
176
|
}
|
|
177
|
-
function
|
|
178
|
-
return wt(t, "value"),
|
|
177
|
+
function _t(t) {
|
|
178
|
+
return wt(t, "value"), W(t) || J(t) ? yt(t) : BigInt(t);
|
|
179
179
|
}
|
|
180
180
|
/**
|
|
181
181
|
* @module @zk-kit/utils
|
|
@@ -191,7 +191,7 @@ function Tt(t) {
|
|
|
191
191
|
function rt(t, e) {
|
|
192
192
|
return t >> e;
|
|
193
193
|
}
|
|
194
|
-
function
|
|
194
|
+
function Nt(t, e) {
|
|
195
195
|
return t * e;
|
|
196
196
|
}
|
|
197
197
|
function Dt(t) {
|
|
@@ -366,9 +366,9 @@ class Mt {
|
|
|
366
366
|
return g;
|
|
367
367
|
}
|
|
368
368
|
}
|
|
369
|
-
var it =
|
|
370
|
-
function
|
|
371
|
-
if (ot) return
|
|
369
|
+
var it = Ut(), N, ot;
|
|
370
|
+
function kt() {
|
|
371
|
+
if (ot) return N;
|
|
372
372
|
ot = 1;
|
|
373
373
|
const t = "Input must be an string, Buffer or Uint8Array";
|
|
374
374
|
function e(f) {
|
|
@@ -390,64 +390,64 @@ function _t() {
|
|
|
390
390
|
return (4294967296 + f).toString(16).substring(1);
|
|
391
391
|
}
|
|
392
392
|
function g(f, a, u) {
|
|
393
|
-
let
|
|
393
|
+
let _ = `
|
|
394
394
|
` + f + " = ";
|
|
395
395
|
for (let b = 0; b < a.length; b += 2) {
|
|
396
396
|
if (u === 32)
|
|
397
|
-
|
|
397
|
+
_ += n(a[b]).toUpperCase(), _ += " ", _ += n(a[b + 1]).toUpperCase();
|
|
398
398
|
else if (u === 64)
|
|
399
|
-
|
|
399
|
+
_ += n(a[b + 1]).toUpperCase(), _ += n(a[b]).toUpperCase();
|
|
400
400
|
else throw new Error("Invalid size " + u);
|
|
401
|
-
b % 6 === 4 ?
|
|
402
|
-
` + new Array(f.length + 4).join(" ") : b < a.length - 2 && (
|
|
401
|
+
b % 6 === 4 ? _ += `
|
|
402
|
+
` + new Array(f.length + 4).join(" ") : b < a.length - 2 && (_ += " ");
|
|
403
403
|
}
|
|
404
|
-
console.log(
|
|
404
|
+
console.log(_);
|
|
405
405
|
}
|
|
406
406
|
function h(f, a, u) {
|
|
407
|
-
let
|
|
407
|
+
let _ = (/* @__PURE__ */ new Date()).getTime();
|
|
408
408
|
const b = new Uint8Array(a);
|
|
409
409
|
for (let y = 0; y < a; y++)
|
|
410
410
|
b[y] = y % 256;
|
|
411
411
|
const l = (/* @__PURE__ */ new Date()).getTime();
|
|
412
|
-
console.log("Generated random input in " + (l -
|
|
412
|
+
console.log("Generated random input in " + (l - _) + "ms"), _ = l;
|
|
413
413
|
for (let y = 0; y < u; y++) {
|
|
414
|
-
const B = f(b), c = (/* @__PURE__ */ new Date()).getTime(), p = c -
|
|
415
|
-
|
|
414
|
+
const B = f(b), c = (/* @__PURE__ */ new Date()).getTime(), p = c - _;
|
|
415
|
+
_ = c, console.log("Hashed in " + p + "ms: " + B.substring(0, 20) + "..."), console.log(
|
|
416
416
|
Math.round(a / (1 << 20) / (p / 1e3) * 100) / 100 + " MB PER SECOND"
|
|
417
417
|
);
|
|
418
418
|
}
|
|
419
419
|
}
|
|
420
|
-
return
|
|
420
|
+
return N = {
|
|
421
421
|
normalizeInput: e,
|
|
422
422
|
toHex: r,
|
|
423
423
|
debugPrint: g,
|
|
424
424
|
testSpeed: h
|
|
425
|
-
},
|
|
425
|
+
}, N;
|
|
426
426
|
}
|
|
427
427
|
var D, st;
|
|
428
|
-
function
|
|
428
|
+
function qt() {
|
|
429
429
|
if (st) return D;
|
|
430
430
|
st = 1;
|
|
431
|
-
const t =
|
|
431
|
+
const t = kt();
|
|
432
432
|
function e(i, d, o) {
|
|
433
433
|
const w = i[d] + i[o];
|
|
434
|
-
let
|
|
435
|
-
w >= 4294967296 &&
|
|
434
|
+
let k = i[d + 1] + i[o + 1];
|
|
435
|
+
w >= 4294967296 && k++, i[d] = w, i[d + 1] = k;
|
|
436
436
|
}
|
|
437
437
|
function r(i, d, o, w) {
|
|
438
|
-
let
|
|
439
|
-
o < 0 && (
|
|
438
|
+
let k = i[d] + o;
|
|
439
|
+
o < 0 && (k += 4294967296);
|
|
440
440
|
let m = i[d + 1] + w;
|
|
441
|
-
|
|
441
|
+
k >= 4294967296 && m++, i[d] = k, i[d + 1] = m;
|
|
442
442
|
}
|
|
443
443
|
function n(i, d) {
|
|
444
444
|
return i[d] ^ i[d + 1] << 8 ^ i[d + 2] << 16 ^ i[d + 3] << 24;
|
|
445
445
|
}
|
|
446
|
-
function g(i, d, o, w,
|
|
447
|
-
const Bt = k
|
|
446
|
+
function g(i, d, o, w, k, m) {
|
|
447
|
+
const Bt = _[k], mt = _[k + 1], It = _[m], At = _[m + 1];
|
|
448
448
|
e(u, i, d), r(u, i, Bt, mt);
|
|
449
|
-
let A = u[w] ^ u[i],
|
|
450
|
-
u[w] =
|
|
449
|
+
let A = u[w] ^ u[i], U = u[w + 1] ^ u[i + 1];
|
|
450
|
+
u[w] = U, u[w + 1] = A, e(u, o, w), A = u[d] ^ u[o], U = u[d + 1] ^ u[o + 1], u[d] = A >>> 24 ^ U << 8, u[d + 1] = U >>> 24 ^ A << 8, e(u, i, d), r(u, i, It, At), A = u[w] ^ u[i], U = u[w + 1] ^ u[i + 1], u[w] = A >>> 16 ^ U << 16, u[w + 1] = U >>> 16 ^ A << 16, e(u, o, w), A = u[d] ^ u[o], U = u[d + 1] ^ u[o + 1], u[d] = U >>> 31 ^ A << 1, u[d + 1] = A >>> 31 ^ U << 1;
|
|
451
451
|
}
|
|
452
452
|
const h = new Uint32Array([
|
|
453
453
|
4089235720,
|
|
@@ -663,13 +663,13 @@ function Ct() {
|
|
|
663
663
|
f.map(function(i) {
|
|
664
664
|
return i * 2;
|
|
665
665
|
})
|
|
666
|
-
), u = new Uint32Array(32),
|
|
666
|
+
), u = new Uint32Array(32), _ = new Uint32Array(32);
|
|
667
667
|
function b(i, d) {
|
|
668
668
|
let o = 0;
|
|
669
669
|
for (o = 0; o < 16; o++)
|
|
670
670
|
u[o] = i.h[o], u[o + 16] = h[o];
|
|
671
671
|
for (u[24] = u[24] ^ i.t, u[25] = u[25] ^ i.t / 4294967296, d && (u[28] = ~u[28], u[29] = ~u[29]), o = 0; o < 32; o++)
|
|
672
|
-
|
|
672
|
+
_[o] = n(i.b, 4 * o);
|
|
673
673
|
for (o = 0; o < 12; o++)
|
|
674
674
|
g(0, 8, 16, 24, a[o * 16 + 0], a[o * 16 + 1]), g(2, 10, 18, 26, a[o * 16 + 2], a[o * 16 + 3]), g(4, 12, 20, 28, a[o * 16 + 4], a[o * 16 + 5]), g(6, 14, 22, 30, a[o * 16 + 6], a[o * 16 + 7]), g(0, 10, 20, 30, a[o * 16 + 8], a[o * 16 + 9]), g(2, 12, 22, 24, a[o * 16 + 10], a[o * 16 + 11]), g(4, 14, 16, 26, a[o * 16 + 12], a[o * 16 + 13]), g(6, 8, 18, 28, a[o * 16 + 14], a[o * 16 + 15]);
|
|
675
675
|
for (o = 0; o < 16; o++)
|
|
@@ -766,7 +766,7 @@ function Ct() {
|
|
|
766
766
|
throw new Error("Illegal salt, expected Uint8Array with length is 16");
|
|
767
767
|
if (w && w.length !== 16)
|
|
768
768
|
throw new Error("Illegal personal, expected Uint8Array with length is 16");
|
|
769
|
-
const
|
|
769
|
+
const k = {
|
|
770
770
|
b: new Uint8Array(128),
|
|
771
771
|
h: new Uint32Array(16),
|
|
772
772
|
t: 0,
|
|
@@ -778,8 +778,8 @@ function Ct() {
|
|
|
778
778
|
};
|
|
779
779
|
l.fill(0), l[0] = i, d && (l[1] = d.length), l[2] = 1, l[3] = 1, o && l.set(o, 32), w && l.set(w, 48);
|
|
780
780
|
for (let m = 0; m < 16; m++)
|
|
781
|
-
|
|
782
|
-
return d && (B(
|
|
781
|
+
k.h[m] = h[m] ^ n(l, m * 4);
|
|
782
|
+
return d && (B(k, d), k.c = 128), k;
|
|
783
783
|
}
|
|
784
784
|
function B(i, d) {
|
|
785
785
|
for (let o = 0; o < d.length; o++)
|
|
@@ -794,13 +794,13 @@ function Ct() {
|
|
|
794
794
|
d[o] = i.h[o >> 2] >> 8 * (o & 3);
|
|
795
795
|
return d;
|
|
796
796
|
}
|
|
797
|
-
function p(i, d, o, w,
|
|
798
|
-
o = o || 64, i = t.normalizeInput(i), w && (w = t.normalizeInput(w)),
|
|
799
|
-
const m = y(o, d, w,
|
|
797
|
+
function p(i, d, o, w, k) {
|
|
798
|
+
o = o || 64, i = t.normalizeInput(i), w && (w = t.normalizeInput(w)), k && (k = t.normalizeInput(k));
|
|
799
|
+
const m = y(o, d, w, k);
|
|
800
800
|
return B(m, i), c(m);
|
|
801
801
|
}
|
|
802
|
-
function s(i, d, o, w,
|
|
803
|
-
const m = p(i, d, o, w,
|
|
802
|
+
function s(i, d, o, w, k) {
|
|
803
|
+
const m = p(i, d, o, w, k);
|
|
804
804
|
return t.toHex(m);
|
|
805
805
|
}
|
|
806
806
|
return D = {
|
|
@@ -812,10 +812,10 @@ function Ct() {
|
|
|
812
812
|
}, D;
|
|
813
813
|
}
|
|
814
814
|
var M, ut;
|
|
815
|
-
function
|
|
815
|
+
function Ct() {
|
|
816
816
|
if (ut) return M;
|
|
817
817
|
ut = 1;
|
|
818
|
-
const t =
|
|
818
|
+
const t = kt();
|
|
819
819
|
function e(c, p) {
|
|
820
820
|
return c[p] ^ c[p + 1] << 8 ^ c[p + 2] << 16 ^ c[p + 3] << 24;
|
|
821
821
|
}
|
|
@@ -1007,7 +1007,7 @@ function Lt() {
|
|
|
1007
1007
|
for (s = 0; s < 8; s++)
|
|
1008
1008
|
c.h[s] ^= f[s] ^ f[s + 8];
|
|
1009
1009
|
}
|
|
1010
|
-
function
|
|
1010
|
+
function _(c, p) {
|
|
1011
1011
|
if (!(c > 0 && c <= 32))
|
|
1012
1012
|
throw new Error("Incorrect output length, should be in [1, 32]");
|
|
1013
1013
|
const s = p ? p.length : 0;
|
|
@@ -1042,7 +1042,7 @@ function Lt() {
|
|
|
1042
1042
|
}
|
|
1043
1043
|
function y(c, p, s) {
|
|
1044
1044
|
s = s || 32, c = t.normalizeInput(c);
|
|
1045
|
-
const i =
|
|
1045
|
+
const i = _(s, p);
|
|
1046
1046
|
return b(i, c), l(i);
|
|
1047
1047
|
}
|
|
1048
1048
|
function B(c, p, s) {
|
|
@@ -1052,17 +1052,17 @@ function Lt() {
|
|
|
1052
1052
|
return M = {
|
|
1053
1053
|
blake2s: y,
|
|
1054
1054
|
blake2sHex: B,
|
|
1055
|
-
blake2sInit:
|
|
1055
|
+
blake2sInit: _,
|
|
1056
1056
|
blake2sUpdate: b,
|
|
1057
1057
|
blake2sFinal: l
|
|
1058
1058
|
}, M;
|
|
1059
1059
|
}
|
|
1060
|
-
var
|
|
1061
|
-
function
|
|
1062
|
-
if (at) return
|
|
1060
|
+
var q, at;
|
|
1061
|
+
function Lt() {
|
|
1062
|
+
if (at) return q;
|
|
1063
1063
|
at = 1;
|
|
1064
|
-
const t =
|
|
1065
|
-
return
|
|
1064
|
+
const t = qt(), e = Ct();
|
|
1065
|
+
return q = {
|
|
1066
1066
|
blake2b: t.blake2b,
|
|
1067
1067
|
blake2bHex: t.blake2bHex,
|
|
1068
1068
|
blake2bInit: t.blake2bInit,
|
|
@@ -1073,9 +1073,9 @@ function Vt() {
|
|
|
1073
1073
|
blake2sInit: e.blake2sInit,
|
|
1074
1074
|
blake2sUpdate: e.blake2sUpdate,
|
|
1075
1075
|
blake2sFinal: e.blake2sFinal
|
|
1076
|
-
},
|
|
1076
|
+
}, q;
|
|
1077
1077
|
}
|
|
1078
|
-
var
|
|
1078
|
+
var C = Lt();
|
|
1079
1079
|
/**
|
|
1080
1080
|
* @module @zk-kit/eddsa-poseidon
|
|
1081
1081
|
* @version 1.1.0
|
|
@@ -1084,7 +1084,7 @@ var L = Vt();
|
|
|
1084
1084
|
* @license MIT
|
|
1085
1085
|
* @see [Github]{@link https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/eddsa-poseidon}
|
|
1086
1086
|
*/
|
|
1087
|
-
const
|
|
1087
|
+
const Vt = I.Buffer.from([1]), Qt = I.Buffer.from([129]), S = [
|
|
1088
1088
|
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
|
1089
1089
|
[14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3],
|
|
1090
1090
|
[11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4],
|
|
@@ -1134,7 +1134,7 @@ const Zt = I.Buffer.from([1]), Wt = I.Buffer.from([129]), U = [
|
|
|
1134
1134
|
2240740374,
|
|
1135
1135
|
1667834072,
|
|
1136
1136
|
1901547113
|
|
1137
|
-
],
|
|
1137
|
+
], L = I.Buffer.from([
|
|
1138
1138
|
128,
|
|
1139
1139
|
0,
|
|
1140
1140
|
0,
|
|
@@ -1269,15 +1269,15 @@ function $(t, e, r, n) {
|
|
|
1269
1269
|
let g = t[e * 2] ^ t[r * 2], h = t[e * 2 + 1] ^ t[r * 2 + 1];
|
|
1270
1270
|
n >= 32 && (h ^= g, g ^= h, h ^= g, n -= 32), n === 0 ? (t[e * 2] = g >>> 0, t[e * 2 + 1] = h >>> 0) : (t[e * 2] = (g >>> n | h << 32 - n) >>> 0, t[e * 2 + 1] = (h >>> n | g << 32 - n) >>> 0);
|
|
1271
1271
|
}
|
|
1272
|
-
function
|
|
1272
|
+
function v(t, e, r, n, g, h, f, a) {
|
|
1273
1273
|
let u;
|
|
1274
|
-
u = t[n * 2 + 1] + ((e[
|
|
1274
|
+
u = t[n * 2 + 1] + ((e[S[r][a] * 2 + 1] ^ E[S[r][a + 1] * 2 + 1]) >>> 0) + t[g * 2 + 1], t[n * 2] = t[n * 2] + ((e[S[r][a] * 2] ^ E[S[r][a + 1] * 2]) >>> 0) + t[g * 2] + ~~(u / 4294967296) >>> 0, t[n * 2 + 1] = u >>> 0, $(t, f, n, 32), u = t[h * 2 + 1] + t[f * 2 + 1], t[h * 2] = t[h * 2] + t[f * 2] + ~~(u / 4294967296) >>> 0, t[h * 2 + 1] = u >>> 0, $(t, g, h, 25), u = t[n * 2 + 1] + ((e[S[r][a + 1] * 2 + 1] ^ E[S[r][a] * 2 + 1]) >>> 0) + t[g * 2 + 1], t[n * 2] = t[n * 2] + ((e[S[r][a + 1] * 2] ^ E[S[r][a] * 2]) >>> 0) + t[g * 2] + ~~(u / 4294967296) >>> 0, t[n * 2 + 1] = u >>> 0, $(t, f, n, 16), u = t[h * 2 + 1] + t[f * 2 + 1], t[h * 2] = t[h * 2] + t[f * 2] + ~~(u / 4294967296) >>> 0, t[h * 2 + 1] = u >>> 0, $(t, g, h, 11);
|
|
1275
1275
|
}
|
|
1276
1276
|
function ct(t) {
|
|
1277
1277
|
for (let e = 0; e < t.length && !(t[e] < 4294967296); e += 1)
|
|
1278
1278
|
t[e] -= 4294967296, t[e + 1] += 1;
|
|
1279
1279
|
}
|
|
1280
|
-
class
|
|
1280
|
+
class Zt {
|
|
1281
1281
|
/**
|
|
1282
1282
|
* Initializes a new Blake-512 hash instance with the default parameters.
|
|
1283
1283
|
*/
|
|
@@ -1299,7 +1299,7 @@ class Xt {
|
|
|
1299
1299
|
4215389547,
|
|
1300
1300
|
1541459225,
|
|
1301
1301
|
327033209
|
|
1302
|
-
], this._s = [0, 0, 0, 0, 0, 0, 0, 0], this._block = I.Buffer.alloc(128), this._blockOffset = 0, this._length = [0, 0, 0, 0], this._nullt = !1, this._zo =
|
|
1302
|
+
], this._s = [0, 0, 0, 0, 0, 0, 0, 0], this._block = I.Buffer.alloc(128), this._blockOffset = 0, this._length = [0, 0, 0, 0], this._nullt = !1, this._zo = Vt, this._oo = Qt;
|
|
1303
1303
|
}
|
|
1304
1304
|
/**
|
|
1305
1305
|
* The core compression function for Blake-512. It transforms the internal
|
|
@@ -1317,7 +1317,7 @@ class Xt {
|
|
|
1317
1317
|
for (n = 24; n < 32; n += 1)
|
|
1318
1318
|
e[n] = E[n - 16];
|
|
1319
1319
|
for (this._nullt || (e[24] = (e[24] ^ this._length[1]) >>> 0, e[25] = (e[25] ^ this._length[0]) >>> 0, e[26] = (e[26] ^ this._length[1]) >>> 0, e[27] = (e[27] ^ this._length[0]) >>> 0, e[28] = (e[28] ^ this._length[3]) >>> 0, e[29] = (e[29] ^ this._length[2]) >>> 0, e[30] = (e[30] ^ this._length[3]) >>> 0, e[31] = (e[31] ^ this._length[2]) >>> 0), n = 0; n < 16; n += 1)
|
|
1320
|
-
|
|
1320
|
+
v(e, r, n, 0, 4, 8, 12, 0), v(e, r, n, 1, 5, 9, 13, 2), v(e, r, n, 2, 6, 10, 14, 4), v(e, r, n, 3, 7, 11, 15, 6), v(e, r, n, 0, 5, 10, 15, 8), v(e, r, n, 1, 6, 11, 12, 10), v(e, r, n, 2, 7, 8, 13, 12), v(e, r, n, 3, 4, 9, 14, 14);
|
|
1321
1321
|
for (n = 0; n < 16; n += 1)
|
|
1322
1322
|
this._h[n % 8 * 2] = (this._h[n % 8 * 2] ^ e[n * 2]) >>> 0, this._h[n % 8 * 2 + 1] = (this._h[n % 8 * 2 + 1] ^ e[n * 2 + 1]) >>> 0;
|
|
1323
1323
|
for (n = 0; n < 8; n += 1)
|
|
@@ -1333,7 +1333,7 @@ class Xt {
|
|
|
1333
1333
|
const r = I.Buffer.alloc(16);
|
|
1334
1334
|
for (let n = 0; n < 4; n += 1)
|
|
1335
1335
|
r.writeUInt32BE(e[3 - n], n * 4);
|
|
1336
|
-
this._blockOffset === 111 ? (this._length[0] -= 8, this.update(this._oo)) : (this._blockOffset < 111 ? (this._blockOffset === 0 && (this._nullt = !0), this._length[0] -= (111 - this._blockOffset) * 8, this.update(
|
|
1336
|
+
this._blockOffset === 111 ? (this._length[0] -= 8, this.update(this._oo)) : (this._blockOffset < 111 ? (this._blockOffset === 0 && (this._nullt = !0), this._length[0] -= (111 - this._blockOffset) * 8, this.update(L.subarray(0, 111 - this._blockOffset))) : (this._length[0] -= (128 - this._blockOffset) * 8, this.update(L.subarray(0, 128 - this._blockOffset)), this._length[0] -= 111 * 8, this.update(L.subarray(1, 112)), this._nullt = !0), this.update(this._zo), this._length[0] -= 8), this._length[0] -= 128, this.update(r);
|
|
1337
1337
|
}
|
|
1338
1338
|
/**
|
|
1339
1339
|
* Completes the hash computation and returns the final hash value.
|
|
@@ -1377,7 +1377,7 @@ class Gt {
|
|
|
1377
1377
|
constructor(e = 64, r) {
|
|
1378
1378
|
if (this.key = null, this.outlen = 64, r && (this.key = r), e <= 0 || e > 64)
|
|
1379
1379
|
throw new Error("Illegal output length, expected 0 < length <= 64");
|
|
1380
|
-
this.outlen = e, this.context =
|
|
1380
|
+
this.outlen = e, this.context = C.blake2bInit(this.outlen, r);
|
|
1381
1381
|
}
|
|
1382
1382
|
/**
|
|
1383
1383
|
* Updates the hash with new data. This method can be called multiple
|
|
@@ -1386,7 +1386,7 @@ class Gt {
|
|
|
1386
1386
|
* @returns The instance, to allow method chaining.
|
|
1387
1387
|
*/
|
|
1388
1388
|
update(e) {
|
|
1389
|
-
return
|
|
1389
|
+
return C.blake2bUpdate(this.context, e), this;
|
|
1390
1390
|
}
|
|
1391
1391
|
/**
|
|
1392
1392
|
* Completes the hash computation and returns the final hash value.
|
|
@@ -1395,32 +1395,32 @@ class Gt {
|
|
|
1395
1395
|
* @returns The Blake2b hash of the input data.
|
|
1396
1396
|
*/
|
|
1397
1397
|
digest() {
|
|
1398
|
-
return
|
|
1398
|
+
return vt.from(C.blake2bFinal(this.context));
|
|
1399
1399
|
}
|
|
1400
1400
|
}
|
|
1401
1401
|
function ft(t) {
|
|
1402
1402
|
return t[0] &= 248, t[31] &= 127, t[31] |= 64, t;
|
|
1403
1403
|
}
|
|
1404
|
-
function
|
|
1405
|
-
return dt(t) && t.length === 2 &&
|
|
1404
|
+
function Q(t) {
|
|
1405
|
+
return dt(t) && t.length === 2 && H(t[0]) && H(t[1]);
|
|
1406
1406
|
}
|
|
1407
1407
|
function lt(t) {
|
|
1408
|
-
return G(t) && Object.prototype.hasOwnProperty.call(t, "R8") && Object.prototype.hasOwnProperty.call(t, "S") &&
|
|
1408
|
+
return G(t) && Object.prototype.hasOwnProperty.call(t, "R8") && Object.prototype.hasOwnProperty.call(t, "S") && Q(t.R8) && H(t.S);
|
|
1409
1409
|
}
|
|
1410
1410
|
function ht(t) {
|
|
1411
1411
|
return F(t, "privateKey", ["Buffer", "Uint8Array", "string"]), I.Buffer.from(t);
|
|
1412
1412
|
}
|
|
1413
1413
|
function bt(t) {
|
|
1414
|
-
return F(t, "message", ["bignumberish", "string"]),
|
|
1414
|
+
return F(t, "message", ["bignumberish", "string"]), Y(t) ? _t(t) : yt(I.Buffer.from(t));
|
|
1415
1415
|
}
|
|
1416
|
-
function
|
|
1416
|
+
function V(t, e) {
|
|
1417
1417
|
let r;
|
|
1418
1418
|
switch (e) {
|
|
1419
|
-
case
|
|
1420
|
-
r = new
|
|
1419
|
+
case K.BLAKE1: {
|
|
1420
|
+
r = new Zt();
|
|
1421
1421
|
break;
|
|
1422
1422
|
}
|
|
1423
|
-
case
|
|
1423
|
+
case K.BLAKE2b: {
|
|
1424
1424
|
r = new Gt();
|
|
1425
1425
|
break;
|
|
1426
1426
|
}
|
|
@@ -1429,15 +1429,15 @@ function Z(t, e) {
|
|
|
1429
1429
|
}
|
|
1430
1430
|
return r.update(I.Buffer.from(t)), r.digest();
|
|
1431
1431
|
}
|
|
1432
|
-
var
|
|
1432
|
+
var K;
|
|
1433
1433
|
(function(t) {
|
|
1434
1434
|
t.BLAKE1 = "blake-1", t.BLAKE2b = "blake-2b";
|
|
1435
|
-
})(
|
|
1436
|
-
const
|
|
1435
|
+
})(K || (K = {}));
|
|
1436
|
+
const Jt = (t) => {
|
|
1437
1437
|
const e = (b) => {
|
|
1438
1438
|
b = ht(b);
|
|
1439
|
-
let l =
|
|
1440
|
-
return l = l.slice(0, 32), l = ft(l), rt(
|
|
1439
|
+
let l = V(b, t);
|
|
1440
|
+
return l = l.slice(0, 32), l = ft(l), rt(P(l), BigInt(3)) % R;
|
|
1441
1441
|
};
|
|
1442
1442
|
function r(b) {
|
|
1443
1443
|
const l = e(b);
|
|
@@ -1445,29 +1445,29 @@ const Nt = (t) => {
|
|
|
1445
1445
|
}
|
|
1446
1446
|
function n(b, l) {
|
|
1447
1447
|
b = ht(b), l = bt(l);
|
|
1448
|
-
const y =
|
|
1448
|
+
const y = V(b, t), B = ft(y.slice(0, 32)), c = P(B), p = x(z, rt(c, BigInt(3))), s = T(l, 32), i = V(I.Buffer.concat([y.slice(32, 64), s]), t), d = new Mt(R), o = d.e(P(i)), w = x(z, o), k = it.poseidon5([w[0], w[1], p[0], p[1], l]), m = d.add(o, d.mul(k, c));
|
|
1449
1449
|
return { R8: w, S: m };
|
|
1450
1450
|
}
|
|
1451
1451
|
function g(b, l, y) {
|
|
1452
|
-
if (!
|
|
1452
|
+
if (!Q(y) || !lt(l) || !O(l.R8) || !O(y) || BigInt(l.S) >= R)
|
|
1453
1453
|
return !1;
|
|
1454
1454
|
b = bt(b);
|
|
1455
1455
|
const B = {
|
|
1456
1456
|
R8: [BigInt(l.R8[0]), BigInt(l.R8[1])],
|
|
1457
1457
|
S: BigInt(l.S)
|
|
1458
1458
|
}, c = [BigInt(y[0]), BigInt(y[1])], p = it.poseidon5([l.R8[0], l.R8[1], y[0], y[1], b]), s = x(z, BigInt(l.S));
|
|
1459
|
-
let i = x(c,
|
|
1460
|
-
return i =
|
|
1459
|
+
let i = x(c, Nt(p, BigInt(8)));
|
|
1460
|
+
return i = St(B.R8, i), nt.eq(s[0], i[0]) && nt.eq(s[1], i[1]);
|
|
1461
1461
|
}
|
|
1462
1462
|
function h(b) {
|
|
1463
|
-
if (!
|
|
1463
|
+
if (!Q(b) || !O(b))
|
|
1464
1464
|
throw new Error("Invalid public key");
|
|
1465
1465
|
const l = [BigInt(b[0]), BigInt(b[1])];
|
|
1466
1466
|
return et(l);
|
|
1467
1467
|
}
|
|
1468
1468
|
function f(b) {
|
|
1469
1469
|
wt(b, "publicKey");
|
|
1470
|
-
const l = tt(
|
|
1470
|
+
const l = tt(_t(b));
|
|
1471
1471
|
if (l === null)
|
|
1472
1472
|
throw new Error("Invalid public key");
|
|
1473
1473
|
return l;
|
|
@@ -1484,15 +1484,15 @@ const Nt = (t) => {
|
|
|
1484
1484
|
function u(b) {
|
|
1485
1485
|
if (xt(b, "packedSignature"), b.length !== 64)
|
|
1486
1486
|
throw new Error("Packed signature must be 64 bytes");
|
|
1487
|
-
const l = b.subarray(0, 32), y = b.subarray(32, 64), B = tt(
|
|
1487
|
+
const l = b.subarray(0, 32), y = b.subarray(32, 64), B = tt(P(l));
|
|
1488
1488
|
if (B === null)
|
|
1489
1489
|
throw new Error(`Invalid packed signature point ${y.toString("hex")}.`);
|
|
1490
1490
|
return {
|
|
1491
1491
|
R8: B,
|
|
1492
|
-
S:
|
|
1492
|
+
S: P(y)
|
|
1493
1493
|
};
|
|
1494
1494
|
}
|
|
1495
|
-
class
|
|
1495
|
+
class _ {
|
|
1496
1496
|
/**
|
|
1497
1497
|
* Initializes a new instance, deriving necessary cryptographic parameters from the provided private key.
|
|
1498
1498
|
* If the private key is not passed as a parameter, a random 32-byte hexadecimal key is generated.
|
|
@@ -1505,7 +1505,7 @@ const Nt = (t) => {
|
|
|
1505
1505
|
*
|
|
1506
1506
|
* @param privateKey The private key used for signing and public key derivation.
|
|
1507
1507
|
*/
|
|
1508
|
-
constructor(l =
|
|
1508
|
+
constructor(l = Kt.getRandomValues(32)) {
|
|
1509
1509
|
this.privateKey = l, this.secretScalar = e(l), this.publicKey = r(l), this.packedPublicKey = h(this.publicKey);
|
|
1510
1510
|
}
|
|
1511
1511
|
/**
|
|
@@ -1535,12 +1535,12 @@ const Nt = (t) => {
|
|
|
1535
1535
|
unpackPublicKey: f,
|
|
1536
1536
|
packSignature: a,
|
|
1537
1537
|
unpackSignature: u,
|
|
1538
|
-
EdDSAPoseidon:
|
|
1538
|
+
EdDSAPoseidon: _
|
|
1539
1539
|
};
|
|
1540
|
-
}, { EdDSAPoseidon:
|
|
1540
|
+
}, { EdDSAPoseidon: Xt, derivePublicKey: Yt, deriveSecretScalar: te, packPublicKey: ee, packSignature: ne, signMessage: re, unpackPublicKey: ie, unpackSignature: oe, verifySignature: se } = Jt(K.BLAKE1);
|
|
1541
1541
|
export {
|
|
1542
|
-
|
|
1543
|
-
|
|
1542
|
+
Xt as EdDSAPoseidon,
|
|
1543
|
+
Yt as derivePublicKey,
|
|
1544
1544
|
te as deriveSecretScalar,
|
|
1545
1545
|
ee as packPublicKey,
|
|
1546
1546
|
ne as packSignature,
|