@coinbase/cdp-hooks 0.0.74 → 0.0.75

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.
Files changed (108) hide show
  1. package/dist/esm/index177.js +3 -3
  2. package/dist/esm/index206.js +2 -2
  3. package/dist/esm/index209.js +2 -2
  4. package/dist/esm/index210.js +1 -1
  5. package/dist/esm/index214.js +3 -3
  6. package/dist/esm/index217.js +1 -1
  7. package/dist/esm/index220.js +2 -41
  8. package/dist/esm/index221.js +41 -2
  9. package/dist/esm/index222.js +2 -5
  10. package/dist/esm/index223.js +4 -10
  11. package/dist/esm/index224.js +9 -18
  12. package/dist/esm/index225.js +19 -7
  13. package/dist/esm/index226.js +7 -11
  14. package/dist/esm/index227.js +11 -66
  15. package/dist/esm/index228.js +65 -64
  16. package/dist/esm/index229.js +60 -180
  17. package/dist/esm/index230.js +183 -20
  18. package/dist/esm/index231.js +21 -41
  19. package/dist/esm/index232.js +20 -54
  20. package/dist/esm/index233.js +54 -18
  21. package/dist/esm/index234.js +34 -10
  22. package/dist/esm/index235.js +10 -7
  23. package/dist/esm/index236.js +13 -7
  24. package/dist/esm/index237.js +7 -6
  25. package/dist/esm/index238.js +6 -36
  26. package/dist/esm/index239.js +35 -14
  27. package/dist/esm/index240.js +15 -8
  28. package/dist/esm/index241.js +7 -11
  29. package/dist/esm/index242.js +12 -9
  30. package/dist/esm/index243.js +9 -16
  31. package/dist/esm/index244.js +15 -21
  32. package/dist/esm/index245.js +22 -30
  33. package/dist/esm/index246.js +31 -2
  34. package/dist/esm/index247.js +2 -14
  35. package/dist/esm/index248.js +13 -12
  36. package/dist/esm/index249.js +10 -45
  37. package/dist/esm/index250.js +47 -9
  38. package/dist/esm/index251.js +8 -12
  39. package/dist/esm/index252.js +13 -14
  40. package/dist/esm/index253.js +14 -8
  41. package/dist/esm/index254.js +6 -13
  42. package/dist/esm/index255.js +15 -24
  43. package/dist/esm/index256.js +24 -11
  44. package/dist/esm/index257.js +10 -23
  45. package/dist/esm/index258.js +24 -51
  46. package/dist/esm/index259.js +51 -17
  47. package/dist/esm/index260.js +17 -14
  48. package/dist/esm/index261.js +14 -11
  49. package/dist/esm/index262.js +11 -103
  50. package/dist/esm/index263.js +103 -5
  51. package/dist/esm/index264.js +5 -223
  52. package/dist/esm/index265.js +223 -6
  53. package/dist/esm/index266.js +7 -7
  54. package/dist/esm/index267.js +7 -27
  55. package/dist/esm/index268.js +25 -18
  56. package/dist/esm/index269.js +18 -144
  57. package/dist/esm/index270.js +145 -12
  58. package/dist/esm/index271.js +12 -35
  59. package/dist/esm/index272.js +35 -41
  60. package/dist/esm/index273.js +42 -2
  61. package/dist/esm/index275.js +3 -136
  62. package/dist/esm/index276.js +136 -3
  63. package/dist/esm/index280.js +2 -2
  64. package/dist/esm/index282.js +1 -1
  65. package/dist/esm/index284.js +2 -2
  66. package/dist/esm/index285.js +2 -2
  67. package/dist/esm/index286.js +1 -1
  68. package/dist/esm/index287.js +1 -1
  69. package/dist/esm/index3.js +1 -1
  70. package/dist/esm/index40.js +1 -1
  71. package/dist/esm/index41.js +1 -1
  72. package/dist/esm/index44.js +3 -3
  73. package/dist/esm/index45.js +2 -2
  74. package/dist/esm/index46.js +3 -3
  75. package/dist/esm/index47.js +2 -2
  76. package/dist/esm/index48.js +3 -3
  77. package/dist/esm/index49.js +6 -6
  78. package/dist/esm/index50.js +2 -2
  79. package/dist/esm/index51.js +1 -1
  80. package/dist/esm/index52.js +1 -1
  81. package/dist/esm/index53.js +1 -1
  82. package/dist/esm/index54.js +1 -1
  83. package/dist/esm/index55.js +1 -1
  84. package/dist/esm/index56.js +1 -1
  85. package/dist/esm/index57.js +4 -4
  86. package/dist/esm/index58.js +1 -1
  87. package/dist/esm/index66.js +1 -1
  88. package/dist/esm/index67.js +2 -2
  89. package/dist/esm/index68.js +1 -1
  90. package/dist/esm/index73.js +1 -1
  91. package/dist/esm/index76.js +1 -1
  92. package/dist/esm/index79.js +1 -1
  93. package/dist/esm/index80.js +1 -1
  94. package/dist/esm/index81.js +3 -3
  95. package/dist/esm/index82.js +2 -2
  96. package/dist/esm/index83.js +1 -1
  97. package/dist/esm/index85.js +1 -1
  98. package/dist/esm/index86.js +1 -1
  99. package/dist/esm/index87.js +3 -3
  100. package/dist/esm/index88.js +3 -3
  101. package/dist/esm/index89.js +3 -3
  102. package/dist/esm/index90.js +3 -3
  103. package/dist/esm/index91.js +3 -3
  104. package/dist/esm/index92.js +3 -3
  105. package/dist/esm/index93.js +3 -3
  106. package/dist/esm/index94.js +1 -1
  107. package/dist/esm/index96.js +1 -1
  108. package/package.json +3 -3
@@ -1,106 +1,14 @@
1
- import { HashMD as D, SHA256_IV as b, Chi as g, Maj as p } from "./index282.js";
2
- import { createHasher as u, clean as C, rotr as i } from "./index269.js";
3
- const B = /* @__PURE__ */ Uint32Array.from([
4
- 1116352408,
5
- 1899447441,
6
- 3049323471,
7
- 3921009573,
8
- 961987163,
9
- 1508970993,
10
- 2453635748,
11
- 2870763221,
12
- 3624381080,
13
- 310598401,
14
- 607225278,
15
- 1426881987,
16
- 1925078388,
17
- 2162078206,
18
- 2614888103,
19
- 3248222580,
20
- 3835390401,
21
- 4022224774,
22
- 264347078,
23
- 604807628,
24
- 770255983,
25
- 1249150122,
26
- 1555081692,
27
- 1996064986,
28
- 2554220882,
29
- 2821834349,
30
- 2952996808,
31
- 3210313671,
32
- 3336571891,
33
- 3584528711,
34
- 113926993,
35
- 338241895,
36
- 666307205,
37
- 773529912,
38
- 1294757372,
39
- 1396182291,
40
- 1695183700,
41
- 1986661051,
42
- 2177026350,
43
- 2456956037,
44
- 2730485921,
45
- 2820302411,
46
- 3259730800,
47
- 3345764771,
48
- 3516065817,
49
- 3600352804,
50
- 4094571909,
51
- 275423344,
52
- 430227734,
53
- 506948616,
54
- 659060556,
55
- 883997877,
56
- 958139571,
57
- 1322822218,
58
- 1537002063,
59
- 1747873779,
60
- 1955562222,
61
- 2024104815,
62
- 2227730452,
63
- 2361852424,
64
- 2428436474,
65
- 2756734187,
66
- 3204031479,
67
- 3329325298
68
- ]), h = /* @__PURE__ */ new Uint32Array(64);
69
- class E extends D {
70
- constructor(o = 32) {
71
- super(64, o, 8, !1), this.A = b[0] | 0, this.B = b[1] | 0, this.C = b[2] | 0, this.D = b[3] | 0, this.E = b[4] | 0, this.F = b[5] | 0, this.G = b[6] | 0, this.H = b[7] | 0;
72
- }
73
- get() {
74
- const { A: o, B: r, C: t, D: s, E: a, F: f, G: c, H: e } = this;
75
- return [o, r, t, s, a, f, c, e];
76
- }
77
- // prettier-ignore
78
- set(o, r, t, s, a, f, c, e) {
79
- this.A = o | 0, this.B = r | 0, this.C = t | 0, this.D = s | 0, this.E = a | 0, this.F = f | 0, this.G = c | 0, this.H = e | 0;
80
- }
81
- process(o, r) {
82
- for (let x = 0; x < 16; x++, r += 4)
83
- h[x] = o.getUint32(r, !1);
84
- for (let x = 16; x < 64; x++) {
85
- const H = h[x - 15], d = h[x - 2], m = i(H, 7) ^ i(H, 18) ^ H >>> 3, l = i(d, 17) ^ i(d, 19) ^ d >>> 10;
86
- h[x] = l + h[x - 7] + m + h[x - 16] | 0;
87
- }
88
- let { A: t, B: s, C: a, D: f, E: c, F: e, G: n, H: A } = this;
89
- for (let x = 0; x < 64; x++) {
90
- const H = i(c, 6) ^ i(c, 11) ^ i(c, 25), d = A + H + g(c, e, n) + B[x] + h[x] | 0, l = (i(t, 2) ^ i(t, 13) ^ i(t, 22)) + p(t, s, a) | 0;
91
- A = n, n = e, e = c, c = f + d | 0, f = a, a = s, s = t, t = d + l | 0;
92
- }
93
- t = t + this.A | 0, s = s + this.B | 0, a = a + this.C | 0, f = f + this.D | 0, c = c + this.E | 0, e = e + this.F | 0, n = n + this.G | 0, A = A + this.H | 0, this.set(t, s, a, f, c, e, n, A);
94
- }
95
- roundClean() {
96
- C(h);
97
- }
98
- destroy() {
99
- this.set(0, 0, 0, 0, 0, 0, 0, 0), C(this.buffer);
100
- }
1
+ import { LruMap as u } from "./index204.js";
2
+ const t = /* @__PURE__ */ new u(8192);
3
+ function s(r, { enabled: o = !0, id: e }) {
4
+ if (!o || !e)
5
+ return r();
6
+ if (t.get(e))
7
+ return t.get(e);
8
+ const n = r().finally(() => t.delete(e));
9
+ return t.set(e, n), n;
101
10
  }
102
- const y = /* @__PURE__ */ u(() => new E());
103
11
  export {
104
- E as SHA256,
105
- y as sha256
12
+ t as promiseCache,
13
+ s as withDedupe
106
14
  };
@@ -1,8 +1,106 @@
1
- import { weierstrass as s } from "./index284.js";
2
- function c(e, t) {
3
- const r = (o) => s({ ...e, hash: o });
4
- return { ...r(t), create: r };
1
+ import { HashMD as D, SHA256_IV as b, Chi as g, Maj as p } from "./index282.js";
2
+ import { createHasher as u, clean as C, rotr as i } from "./index270.js";
3
+ const B = /* @__PURE__ */ Uint32Array.from([
4
+ 1116352408,
5
+ 1899447441,
6
+ 3049323471,
7
+ 3921009573,
8
+ 961987163,
9
+ 1508970993,
10
+ 2453635748,
11
+ 2870763221,
12
+ 3624381080,
13
+ 310598401,
14
+ 607225278,
15
+ 1426881987,
16
+ 1925078388,
17
+ 2162078206,
18
+ 2614888103,
19
+ 3248222580,
20
+ 3835390401,
21
+ 4022224774,
22
+ 264347078,
23
+ 604807628,
24
+ 770255983,
25
+ 1249150122,
26
+ 1555081692,
27
+ 1996064986,
28
+ 2554220882,
29
+ 2821834349,
30
+ 2952996808,
31
+ 3210313671,
32
+ 3336571891,
33
+ 3584528711,
34
+ 113926993,
35
+ 338241895,
36
+ 666307205,
37
+ 773529912,
38
+ 1294757372,
39
+ 1396182291,
40
+ 1695183700,
41
+ 1986661051,
42
+ 2177026350,
43
+ 2456956037,
44
+ 2730485921,
45
+ 2820302411,
46
+ 3259730800,
47
+ 3345764771,
48
+ 3516065817,
49
+ 3600352804,
50
+ 4094571909,
51
+ 275423344,
52
+ 430227734,
53
+ 506948616,
54
+ 659060556,
55
+ 883997877,
56
+ 958139571,
57
+ 1322822218,
58
+ 1537002063,
59
+ 1747873779,
60
+ 1955562222,
61
+ 2024104815,
62
+ 2227730452,
63
+ 2361852424,
64
+ 2428436474,
65
+ 2756734187,
66
+ 3204031479,
67
+ 3329325298
68
+ ]), h = /* @__PURE__ */ new Uint32Array(64);
69
+ class E extends D {
70
+ constructor(o = 32) {
71
+ super(64, o, 8, !1), this.A = b[0] | 0, this.B = b[1] | 0, this.C = b[2] | 0, this.D = b[3] | 0, this.E = b[4] | 0, this.F = b[5] | 0, this.G = b[6] | 0, this.H = b[7] | 0;
72
+ }
73
+ get() {
74
+ const { A: o, B: r, C: t, D: s, E: a, F: f, G: c, H: e } = this;
75
+ return [o, r, t, s, a, f, c, e];
76
+ }
77
+ // prettier-ignore
78
+ set(o, r, t, s, a, f, c, e) {
79
+ this.A = o | 0, this.B = r | 0, this.C = t | 0, this.D = s | 0, this.E = a | 0, this.F = f | 0, this.G = c | 0, this.H = e | 0;
80
+ }
81
+ process(o, r) {
82
+ for (let x = 0; x < 16; x++, r += 4)
83
+ h[x] = o.getUint32(r, !1);
84
+ for (let x = 16; x < 64; x++) {
85
+ const H = h[x - 15], d = h[x - 2], m = i(H, 7) ^ i(H, 18) ^ H >>> 3, l = i(d, 17) ^ i(d, 19) ^ d >>> 10;
86
+ h[x] = l + h[x - 7] + m + h[x - 16] | 0;
87
+ }
88
+ let { A: t, B: s, C: a, D: f, E: c, F: e, G: n, H: A } = this;
89
+ for (let x = 0; x < 64; x++) {
90
+ const H = i(c, 6) ^ i(c, 11) ^ i(c, 25), d = A + H + g(c, e, n) + B[x] + h[x] | 0, l = (i(t, 2) ^ i(t, 13) ^ i(t, 22)) + p(t, s, a) | 0;
91
+ A = n, n = e, e = c, c = f + d | 0, f = a, a = s, s = t, t = d + l | 0;
92
+ }
93
+ t = t + this.A | 0, s = s + this.B | 0, a = a + this.C | 0, f = f + this.D | 0, c = c + this.E | 0, e = e + this.F | 0, n = n + this.G | 0, A = A + this.H | 0, this.set(t, s, a, f, c, e, n, A);
94
+ }
95
+ roundClean() {
96
+ C(h);
97
+ }
98
+ destroy() {
99
+ this.set(0, 0, 0, 0, 0, 0, 0, 0), C(this.buffer);
100
+ }
5
101
  }
102
+ const y = /* @__PURE__ */ u(() => new E());
6
103
  export {
7
- c as createCurve
104
+ E as SHA256,
105
+ y as sha256
8
106
  };
@@ -1,226 +1,8 @@
1
- import { numberToBytesLE as y, numberToBytesBE as I, bitMask as Z, bytesToNumberLE as S, bytesToNumberBE as _, _validateObject as j } from "./index285.js";
2
- import { anumber as z } from "./index269.js";
3
- const g = BigInt(0), d = BigInt(1), q = /* @__PURE__ */ BigInt(2), V = /* @__PURE__ */ BigInt(3), x = /* @__PURE__ */ BigInt(4), T = /* @__PURE__ */ BigInt(5), L = /* @__PURE__ */ BigInt(8);
4
- function h(t, n) {
5
- const o = t % n;
6
- return o >= g ? o : n + o;
7
- }
8
- function O(t, n, o) {
9
- let r = t;
10
- for (; n-- > g; )
11
- r *= r, r %= o;
12
- return r;
13
- }
14
- function B(t, n) {
15
- if (t === g)
16
- throw new Error("invert: expected non-zero number");
17
- if (n <= g)
18
- throw new Error("invert: expected positive modulus, got " + n);
19
- let o = h(t, n), r = n, s = g, f = d;
20
- for (; o !== g; ) {
21
- const u = r / o, i = r % o, w = s - f * u;
22
- r = o, o = i, s = f, f = w;
23
- }
24
- if (r !== d)
25
- throw new Error("invert: does not exist");
26
- return h(s, n);
27
- }
28
- function M(t, n) {
29
- const o = (t.ORDER + d) / x, r = t.pow(n, o);
30
- if (!t.eql(t.sqr(r), n))
31
- throw new Error("Cannot find square root");
32
- return r;
33
- }
34
- function H(t, n) {
35
- const o = (t.ORDER - T) / L, r = t.mul(n, q), s = t.pow(r, o), f = t.mul(n, s), c = t.mul(t.mul(f, q), s), u = t.mul(f, t.sub(c, t.ONE));
36
- if (!t.eql(t.sqr(u), n))
37
- throw new Error("Cannot find square root");
38
- return u;
39
- }
40
- function K(t) {
41
- if (t < BigInt(3))
42
- throw new Error("sqrt is not defined for small field");
43
- let n = t - d, o = 0;
44
- for (; n % q === g; )
45
- n /= q, o++;
46
- let r = q;
47
- const s = U(t);
48
- for (; N(s, r) === 1; )
49
- if (r++ > 1e3)
50
- throw new Error("Cannot find square root: probably non-prime P");
51
- if (o === 1)
52
- return M;
53
- let f = s.pow(r, n);
54
- const c = (n + d) / q;
55
- return function(i, w) {
56
- if (i.is0(w))
57
- return w;
58
- if (N(i, w) !== 1)
59
- throw new Error("Cannot find square root");
60
- let e = o, l = i.mul(i.ONE, f), a = i.pow(w, n), b = i.pow(w, c);
61
- for (; !i.eql(a, i.ONE); ) {
62
- if (i.is0(a))
63
- return i.ZERO;
64
- let m = 1, E = i.sqr(a);
65
- for (; !i.eql(E, i.ONE); )
66
- if (m++, E = i.sqr(E), m === e)
67
- throw new Error("Cannot find square root");
68
- const C = d << BigInt(e - m - 1), v = i.pow(l, C);
69
- e = m, l = i.sqr(v), a = i.mul(a, l), b = i.mul(b, v);
70
- }
71
- return b;
72
- };
73
- }
74
- function Q(t) {
75
- return t % x === V ? M : t % L === T ? H : K(t);
76
- }
77
- const Y = [
78
- "create",
79
- "isValid",
80
- "is0",
81
- "neg",
82
- "inv",
83
- "sqrt",
84
- "sqr",
85
- "eql",
86
- "add",
87
- "sub",
88
- "mul",
89
- "pow",
90
- "div",
91
- "addN",
92
- "subN",
93
- "mulN",
94
- "sqrN"
95
- ];
96
- function P(t) {
97
- const n = {
98
- ORDER: "bigint",
99
- MASK: "bigint",
100
- BYTES: "number",
101
- BITS: "number"
102
- }, o = Y.reduce((r, s) => (r[s] = "function", r), n);
103
- return j(t, o), t;
104
- }
105
- function k(t, n, o) {
106
- if (o < g)
107
- throw new Error("invalid exponent, negatives unsupported");
108
- if (o === g)
109
- return t.ONE;
110
- if (o === d)
111
- return n;
112
- let r = t.ONE, s = n;
113
- for (; o > g; )
114
- o & d && (r = t.mul(r, s)), s = t.sqr(s), o >>= d;
115
- return r;
116
- }
117
- function G(t, n, o = !1) {
118
- const r = new Array(n.length).fill(o ? t.ZERO : void 0), s = n.reduce((c, u, i) => t.is0(u) ? c : (r[i] = c, t.mul(c, u)), t.ONE), f = t.inv(s);
119
- return n.reduceRight((c, u, i) => t.is0(u) ? c : (r[i] = t.mul(c, r[i]), t.mul(c, u)), f), r;
120
- }
121
- function N(t, n) {
122
- const o = (t.ORDER - d) / q, r = t.pow(n, o), s = t.eql(r, t.ONE), f = t.eql(r, t.ZERO), c = t.eql(r, t.neg(t.ONE));
123
- if (!s && !f && !c)
124
- throw new Error("invalid Legendre symbol result");
125
- return s ? 1 : f ? 0 : -1;
126
- }
127
- function J(t, n) {
128
- n !== void 0 && z(n);
129
- const o = n !== void 0 ? n : t.toString(2).length, r = Math.ceil(o / 8);
130
- return { nBitLength: o, nByteLength: r };
131
- }
132
- function U(t, n, o = !1, r = {}) {
133
- if (t <= g)
134
- throw new Error("invalid field: expected ORDER > 0, got " + t);
135
- let s, f;
136
- if (typeof n == "object" && n != null) {
137
- if (r.sqrt || o)
138
- throw new Error("cannot specify opts in two arguments");
139
- const e = n;
140
- e.BITS && (s = e.BITS), e.sqrt && (f = e.sqrt), typeof e.isLE == "boolean" && (o = e.isLE);
141
- } else
142
- typeof n == "number" && (s = n), r.sqrt && (f = r.sqrt);
143
- const { nBitLength: c, nByteLength: u } = J(t, s);
144
- if (u > 2048)
145
- throw new Error("invalid field: expected ORDER of <= 2048 bytes");
146
- let i;
147
- const w = Object.freeze({
148
- ORDER: t,
149
- isLE: o,
150
- BITS: c,
151
- BYTES: u,
152
- MASK: Z(c),
153
- ZERO: g,
154
- ONE: d,
155
- create: (e) => h(e, t),
156
- isValid: (e) => {
157
- if (typeof e != "bigint")
158
- throw new Error("invalid field element: expected bigint, got " + typeof e);
159
- return g <= e && e < t;
160
- },
161
- is0: (e) => e === g,
162
- // is valid and invertible
163
- isValidNot0: (e) => !w.is0(e) && w.isValid(e),
164
- isOdd: (e) => (e & d) === d,
165
- neg: (e) => h(-e, t),
166
- eql: (e, l) => e === l,
167
- sqr: (e) => h(e * e, t),
168
- add: (e, l) => h(e + l, t),
169
- sub: (e, l) => h(e - l, t),
170
- mul: (e, l) => h(e * l, t),
171
- pow: (e, l) => k(w, e, l),
172
- div: (e, l) => h(e * B(l, t), t),
173
- // Same as above, but doesn't normalize
174
- sqrN: (e) => e * e,
175
- addN: (e, l) => e + l,
176
- subN: (e, l) => e - l,
177
- mulN: (e, l) => e * l,
178
- inv: (e) => B(e, t),
179
- sqrt: f || ((e) => (i || (i = Q(t)), i(w, e))),
180
- toBytes: (e) => o ? y(e, u) : I(e, u),
181
- fromBytes: (e) => {
182
- if (e.length !== u)
183
- throw new Error("Field.fromBytes: expected " + u + " bytes, got " + e.length);
184
- return o ? S(e) : _(e);
185
- },
186
- // TODO: we don't need it here, move out to separate fn
187
- invertBatch: (e) => G(w, e),
188
- // We can't move this out because Fp6, Fp12 implement it
189
- // and it's unclear what to return in there.
190
- cmov: (e, l, a) => a ? l : e
191
- });
192
- return Object.freeze(w);
193
- }
194
- function A(t) {
195
- if (typeof t != "bigint")
196
- throw new Error("field order must be bigint");
197
- const n = t.toString(2).length;
198
- return Math.ceil(n / 8);
199
- }
200
- function W(t) {
201
- const n = A(t);
202
- return n + Math.ceil(n / 2);
203
- }
204
- function D(t, n, o = !1) {
205
- const r = t.length, s = A(n), f = W(n);
206
- if (r < 16 || r < f || r > 1024)
207
- throw new Error("expected " + f + "-1024 bytes of input, got " + r);
208
- const c = o ? S(t) : _(t), u = h(c, n - d) + d;
209
- return o ? y(u, s) : I(u, s);
1
+ import { weierstrass as s } from "./index284.js";
2
+ function c(e, t) {
3
+ const r = (o) => s({ ...e, hash: o });
4
+ return { ...r(t), create: r };
210
5
  }
211
6
  export {
212
- U as Field,
213
- G as FpInvertBatch,
214
- N as FpLegendre,
215
- k as FpPow,
216
- Q as FpSqrt,
217
- A as getFieldBytesLength,
218
- W as getMinHashLength,
219
- B as invert,
220
- D as mapHashToField,
221
- h as mod,
222
- J as nLength,
223
- O as pow2,
224
- K as tonelliShanks,
225
- P as validateField
7
+ c as createCurve
226
8
  };
@@ -1,9 +1,226 @@
1
- import { toBytes as o } from "./index133.js";
2
- import { keccak256 as r } from "./index135.js";
3
- const e = (t) => r(o(t));
4
- function c(t) {
5
- return e(t);
1
+ import { numberToBytesLE as y, numberToBytesBE as I, bitMask as Z, bytesToNumberLE as S, bytesToNumberBE as _, _validateObject as j } from "./index285.js";
2
+ import { anumber as z } from "./index270.js";
3
+ const g = BigInt(0), d = BigInt(1), q = /* @__PURE__ */ BigInt(2), V = /* @__PURE__ */ BigInt(3), x = /* @__PURE__ */ BigInt(4), T = /* @__PURE__ */ BigInt(5), L = /* @__PURE__ */ BigInt(8);
4
+ function h(t, n) {
5
+ const o = t % n;
6
+ return o >= g ? o : n + o;
7
+ }
8
+ function O(t, n, o) {
9
+ let r = t;
10
+ for (; n-- > g; )
11
+ r *= r, r %= o;
12
+ return r;
13
+ }
14
+ function B(t, n) {
15
+ if (t === g)
16
+ throw new Error("invert: expected non-zero number");
17
+ if (n <= g)
18
+ throw new Error("invert: expected positive modulus, got " + n);
19
+ let o = h(t, n), r = n, s = g, f = d;
20
+ for (; o !== g; ) {
21
+ const u = r / o, i = r % o, w = s - f * u;
22
+ r = o, o = i, s = f, f = w;
23
+ }
24
+ if (r !== d)
25
+ throw new Error("invert: does not exist");
26
+ return h(s, n);
27
+ }
28
+ function M(t, n) {
29
+ const o = (t.ORDER + d) / x, r = t.pow(n, o);
30
+ if (!t.eql(t.sqr(r), n))
31
+ throw new Error("Cannot find square root");
32
+ return r;
33
+ }
34
+ function H(t, n) {
35
+ const o = (t.ORDER - T) / L, r = t.mul(n, q), s = t.pow(r, o), f = t.mul(n, s), c = t.mul(t.mul(f, q), s), u = t.mul(f, t.sub(c, t.ONE));
36
+ if (!t.eql(t.sqr(u), n))
37
+ throw new Error("Cannot find square root");
38
+ return u;
39
+ }
40
+ function K(t) {
41
+ if (t < BigInt(3))
42
+ throw new Error("sqrt is not defined for small field");
43
+ let n = t - d, o = 0;
44
+ for (; n % q === g; )
45
+ n /= q, o++;
46
+ let r = q;
47
+ const s = U(t);
48
+ for (; N(s, r) === 1; )
49
+ if (r++ > 1e3)
50
+ throw new Error("Cannot find square root: probably non-prime P");
51
+ if (o === 1)
52
+ return M;
53
+ let f = s.pow(r, n);
54
+ const c = (n + d) / q;
55
+ return function(i, w) {
56
+ if (i.is0(w))
57
+ return w;
58
+ if (N(i, w) !== 1)
59
+ throw new Error("Cannot find square root");
60
+ let e = o, l = i.mul(i.ONE, f), a = i.pow(w, n), b = i.pow(w, c);
61
+ for (; !i.eql(a, i.ONE); ) {
62
+ if (i.is0(a))
63
+ return i.ZERO;
64
+ let m = 1, E = i.sqr(a);
65
+ for (; !i.eql(E, i.ONE); )
66
+ if (m++, E = i.sqr(E), m === e)
67
+ throw new Error("Cannot find square root");
68
+ const C = d << BigInt(e - m - 1), v = i.pow(l, C);
69
+ e = m, l = i.sqr(v), a = i.mul(a, l), b = i.mul(b, v);
70
+ }
71
+ return b;
72
+ };
73
+ }
74
+ function Q(t) {
75
+ return t % x === V ? M : t % L === T ? H : K(t);
76
+ }
77
+ const Y = [
78
+ "create",
79
+ "isValid",
80
+ "is0",
81
+ "neg",
82
+ "inv",
83
+ "sqrt",
84
+ "sqr",
85
+ "eql",
86
+ "add",
87
+ "sub",
88
+ "mul",
89
+ "pow",
90
+ "div",
91
+ "addN",
92
+ "subN",
93
+ "mulN",
94
+ "sqrN"
95
+ ];
96
+ function P(t) {
97
+ const n = {
98
+ ORDER: "bigint",
99
+ MASK: "bigint",
100
+ BYTES: "number",
101
+ BITS: "number"
102
+ }, o = Y.reduce((r, s) => (r[s] = "function", r), n);
103
+ return j(t, o), t;
104
+ }
105
+ function k(t, n, o) {
106
+ if (o < g)
107
+ throw new Error("invalid exponent, negatives unsupported");
108
+ if (o === g)
109
+ return t.ONE;
110
+ if (o === d)
111
+ return n;
112
+ let r = t.ONE, s = n;
113
+ for (; o > g; )
114
+ o & d && (r = t.mul(r, s)), s = t.sqr(s), o >>= d;
115
+ return r;
116
+ }
117
+ function G(t, n, o = !1) {
118
+ const r = new Array(n.length).fill(o ? t.ZERO : void 0), s = n.reduce((c, u, i) => t.is0(u) ? c : (r[i] = c, t.mul(c, u)), t.ONE), f = t.inv(s);
119
+ return n.reduceRight((c, u, i) => t.is0(u) ? c : (r[i] = t.mul(c, r[i]), t.mul(c, u)), f), r;
120
+ }
121
+ function N(t, n) {
122
+ const o = (t.ORDER - d) / q, r = t.pow(n, o), s = t.eql(r, t.ONE), f = t.eql(r, t.ZERO), c = t.eql(r, t.neg(t.ONE));
123
+ if (!s && !f && !c)
124
+ throw new Error("invalid Legendre symbol result");
125
+ return s ? 1 : f ? 0 : -1;
126
+ }
127
+ function J(t, n) {
128
+ n !== void 0 && z(n);
129
+ const o = n !== void 0 ? n : t.toString(2).length, r = Math.ceil(o / 8);
130
+ return { nBitLength: o, nByteLength: r };
131
+ }
132
+ function U(t, n, o = !1, r = {}) {
133
+ if (t <= g)
134
+ throw new Error("invalid field: expected ORDER > 0, got " + t);
135
+ let s, f;
136
+ if (typeof n == "object" && n != null) {
137
+ if (r.sqrt || o)
138
+ throw new Error("cannot specify opts in two arguments");
139
+ const e = n;
140
+ e.BITS && (s = e.BITS), e.sqrt && (f = e.sqrt), typeof e.isLE == "boolean" && (o = e.isLE);
141
+ } else
142
+ typeof n == "number" && (s = n), r.sqrt && (f = r.sqrt);
143
+ const { nBitLength: c, nByteLength: u } = J(t, s);
144
+ if (u > 2048)
145
+ throw new Error("invalid field: expected ORDER of <= 2048 bytes");
146
+ let i;
147
+ const w = Object.freeze({
148
+ ORDER: t,
149
+ isLE: o,
150
+ BITS: c,
151
+ BYTES: u,
152
+ MASK: Z(c),
153
+ ZERO: g,
154
+ ONE: d,
155
+ create: (e) => h(e, t),
156
+ isValid: (e) => {
157
+ if (typeof e != "bigint")
158
+ throw new Error("invalid field element: expected bigint, got " + typeof e);
159
+ return g <= e && e < t;
160
+ },
161
+ is0: (e) => e === g,
162
+ // is valid and invertible
163
+ isValidNot0: (e) => !w.is0(e) && w.isValid(e),
164
+ isOdd: (e) => (e & d) === d,
165
+ neg: (e) => h(-e, t),
166
+ eql: (e, l) => e === l,
167
+ sqr: (e) => h(e * e, t),
168
+ add: (e, l) => h(e + l, t),
169
+ sub: (e, l) => h(e - l, t),
170
+ mul: (e, l) => h(e * l, t),
171
+ pow: (e, l) => k(w, e, l),
172
+ div: (e, l) => h(e * B(l, t), t),
173
+ // Same as above, but doesn't normalize
174
+ sqrN: (e) => e * e,
175
+ addN: (e, l) => e + l,
176
+ subN: (e, l) => e - l,
177
+ mulN: (e, l) => e * l,
178
+ inv: (e) => B(e, t),
179
+ sqrt: f || ((e) => (i || (i = Q(t)), i(w, e))),
180
+ toBytes: (e) => o ? y(e, u) : I(e, u),
181
+ fromBytes: (e) => {
182
+ if (e.length !== u)
183
+ throw new Error("Field.fromBytes: expected " + u + " bytes, got " + e.length);
184
+ return o ? S(e) : _(e);
185
+ },
186
+ // TODO: we don't need it here, move out to separate fn
187
+ invertBatch: (e) => G(w, e),
188
+ // We can't move this out because Fp6, Fp12 implement it
189
+ // and it's unclear what to return in there.
190
+ cmov: (e, l, a) => a ? l : e
191
+ });
192
+ return Object.freeze(w);
193
+ }
194
+ function A(t) {
195
+ if (typeof t != "bigint")
196
+ throw new Error("field order must be bigint");
197
+ const n = t.toString(2).length;
198
+ return Math.ceil(n / 8);
199
+ }
200
+ function W(t) {
201
+ const n = A(t);
202
+ return n + Math.ceil(n / 2);
203
+ }
204
+ function D(t, n, o = !1) {
205
+ const r = t.length, s = A(n), f = W(n);
206
+ if (r < 16 || r < f || r > 1024)
207
+ throw new Error("expected " + f + "-1024 bytes of input, got " + r);
208
+ const c = o ? S(t) : _(t), u = h(c, n - d) + d;
209
+ return o ? y(u, s) : I(u, s);
6
210
  }
7
211
  export {
8
- c as hashSignature
212
+ U as Field,
213
+ G as FpInvertBatch,
214
+ N as FpLegendre,
215
+ k as FpPow,
216
+ Q as FpSqrt,
217
+ A as getFieldBytesLength,
218
+ W as getMinHashLength,
219
+ B as invert,
220
+ D as mapHashToField,
221
+ h as mod,
222
+ J as nLength,
223
+ O as pow2,
224
+ K as tonelliShanks,
225
+ P as validateField
9
226
  };
@@ -1,9 +1,9 @@
1
- import { normalizeSignature as o } from "./index267.js";
2
- import { formatAbiItem as n } from "./index222.js";
3
- const m = (r) => {
4
- const t = typeof r == "string" ? r : n(r);
5
- return o(t);
6
- };
1
+ import { toBytes as o } from "./index133.js";
2
+ import { keccak256 as r } from "./index135.js";
3
+ const e = (t) => r(o(t));
4
+ function c(t) {
5
+ return e(t);
6
+ }
7
7
  export {
8
- m as toSignature
8
+ c as hashSignature
9
9
  };