@pufferfinance/puffer-sdk 1.4.2 → 1.5.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.
Files changed (202) hide show
  1. package/dist/api/puffer-client-helpers.cjs +2 -0
  2. package/dist/api/puffer-client-helpers.cjs.map +1 -0
  3. package/dist/api/puffer-client-helpers.d.ts +0 -1
  4. package/dist/api/puffer-client-helpers.js +142 -0
  5. package/dist/api/puffer-client-helpers.js.map +1 -0
  6. package/dist/api/puffer-client.cjs +2 -0
  7. package/dist/api/puffer-client.cjs.map +1 -0
  8. package/dist/api/puffer-client.d.ts +6 -1
  9. package/dist/api/puffer-client.js +97 -0
  10. package/dist/api/puffer-client.js.map +1 -0
  11. package/dist/{ccip-ZoYOXsGl.js → ccip-D4klNwCt.js} +28 -27
  12. package/dist/{ccip-ZoYOXsGl.js.map → ccip-D4klNwCt.js.map} +1 -1
  13. package/dist/ccip-DLDqFodf.cjs +2 -0
  14. package/dist/{ccip-Dv116NSL.cjs.map → ccip-DLDqFodf.cjs.map} +1 -1
  15. package/dist/chains/constants.cjs +2 -0
  16. package/dist/chains/constants.cjs.map +1 -0
  17. package/dist/chains/constants.d.ts +3 -2
  18. package/dist/chains/constants.js +6 -0
  19. package/dist/chains/constants.js.map +1 -0
  20. package/dist/constants-BvU-JhfL.cjs +9 -0
  21. package/dist/constants-BvU-JhfL.cjs.map +1 -0
  22. package/dist/constants-rWWWhxR_.js +2099 -0
  23. package/dist/constants-rWWWhxR_.js.map +1 -0
  24. package/dist/contracts/abis/holesky/PufferDepositor.cjs +2 -0
  25. package/dist/contracts/abis/holesky/PufferDepositor.cjs.map +1 -0
  26. package/dist/contracts/abis/holesky/PufferDepositor.js +377 -0
  27. package/dist/contracts/abis/holesky/PufferDepositor.js.map +1 -0
  28. package/dist/contracts/abis/holesky/PufferVaultV2.cjs +2 -0
  29. package/dist/contracts/abis/holesky/PufferVaultV2.cjs.map +1 -0
  30. package/dist/contracts/abis/holesky/PufferVaultV2.js +1787 -0
  31. package/dist/contracts/abis/holesky/PufferVaultV2.js.map +1 -0
  32. package/dist/contracts/abis/l1-reward-manager-abis.cjs +2 -0
  33. package/dist/contracts/abis/l1-reward-manager-abis.cjs.map +1 -0
  34. package/dist/contracts/abis/l1-reward-manager-abis.d.ts +527 -0
  35. package/dist/contracts/abis/l1-reward-manager-abis.js +9 -0
  36. package/dist/contracts/abis/l1-reward-manager-abis.js.map +1 -0
  37. package/dist/contracts/abis/l2-reward-manager-abis.cjs +2 -0
  38. package/dist/contracts/abis/l2-reward-manager-abis.cjs.map +1 -0
  39. package/dist/contracts/abis/l2-reward-manager-abis.d.ts +685 -0
  40. package/dist/contracts/abis/l2-reward-manager-abis.js +9 -0
  41. package/dist/contracts/abis/l2-reward-manager-abis.js.map +1 -0
  42. package/dist/contracts/abis/mainnet/ERC20Permit.cjs +2 -0
  43. package/dist/contracts/abis/mainnet/ERC20Permit.cjs.map +1 -0
  44. package/dist/contracts/abis/mainnet/ERC20Permit.js +524 -0
  45. package/dist/contracts/abis/mainnet/ERC20Permit.js.map +1 -0
  46. package/dist/contracts/abis/mainnet/L1RewardManager.cjs +2 -0
  47. package/dist/contracts/abis/mainnet/L1RewardManager.cjs.map +1 -0
  48. package/dist/contracts/abis/mainnet/L1RewardManager.d.ts +523 -0
  49. package/dist/contracts/abis/mainnet/L1RewardManager.js +447 -0
  50. package/dist/contracts/abis/mainnet/L1RewardManager.js.map +1 -0
  51. package/dist/contracts/abis/mainnet/L2RewardManager.cjs +2 -0
  52. package/dist/contracts/abis/mainnet/L2RewardManager.cjs.map +1 -0
  53. package/dist/contracts/abis/mainnet/L2RewardManager.d.ts +681 -0
  54. package/dist/contracts/abis/mainnet/L2RewardManager.js +538 -0
  55. package/dist/contracts/abis/mainnet/L2RewardManager.js.map +1 -0
  56. package/dist/contracts/abis/mainnet/PufLocker.cjs +2 -0
  57. package/dist/contracts/abis/mainnet/PufLocker.cjs.map +1 -0
  58. package/dist/contracts/abis/mainnet/PufLocker.js +362 -0
  59. package/dist/contracts/abis/mainnet/PufLocker.js.map +1 -0
  60. package/dist/contracts/abis/mainnet/PufToken.cjs +2 -0
  61. package/dist/contracts/abis/mainnet/PufToken.cjs.map +1 -0
  62. package/dist/contracts/abis/mainnet/PufToken.js +883 -0
  63. package/dist/contracts/abis/mainnet/PufToken.js.map +1 -0
  64. package/dist/contracts/abis/mainnet/PufferDepositor.cjs +2 -0
  65. package/dist/contracts/abis/mainnet/PufferDepositor.cjs.map +1 -0
  66. package/dist/contracts/abis/mainnet/PufferDepositor.js +377 -0
  67. package/dist/contracts/abis/mainnet/PufferDepositor.js.map +1 -0
  68. package/dist/contracts/abis/mainnet/PufferL2Depositor.cjs +2 -0
  69. package/dist/contracts/abis/mainnet/PufferL2Depositor.cjs.map +1 -0
  70. package/dist/contracts/abis/mainnet/PufferL2Depositor.js +300 -0
  71. package/dist/contracts/abis/mainnet/PufferL2Depositor.js.map +1 -0
  72. package/dist/contracts/abis/mainnet/PufferVaultV2.cjs +2 -0
  73. package/dist/contracts/abis/mainnet/PufferVaultV2.cjs.map +1 -0
  74. package/dist/contracts/abis/mainnet/PufferVaultV2.js +1864 -0
  75. package/dist/contracts/abis/mainnet/PufferVaultV2.js.map +1 -0
  76. package/dist/contracts/abis/puf-locker-abis.cjs +2 -0
  77. package/dist/contracts/abis/puf-locker-abis.cjs.map +1 -0
  78. package/dist/contracts/abis/puf-locker-abis.js +10 -0
  79. package/dist/contracts/abis/puf-locker-abis.js.map +1 -0
  80. package/dist/contracts/abis/puf-token-abis.cjs +2 -0
  81. package/dist/contracts/abis/puf-token-abis.cjs.map +1 -0
  82. package/dist/contracts/abis/puf-token-abis.js +10 -0
  83. package/dist/contracts/abis/puf-token-abis.js.map +1 -0
  84. package/dist/contracts/abis/puffer-depositor-abis.cjs +2 -0
  85. package/dist/contracts/abis/puffer-depositor-abis.cjs.map +1 -0
  86. package/dist/contracts/abis/puffer-depositor-abis.js +20 -0
  87. package/dist/contracts/abis/puffer-depositor-abis.js.map +1 -0
  88. package/dist/contracts/abis/puffer-vault-abis.cjs +2 -0
  89. package/dist/contracts/abis/puffer-vault-abis.cjs.map +1 -0
  90. package/dist/contracts/abis/puffer-vault-abis.js +15 -0
  91. package/dist/contracts/abis/puffer-vault-abis.js.map +1 -0
  92. package/dist/contracts/abis/tokens-abis.cjs +2 -0
  93. package/dist/contracts/abis/tokens-abis.cjs.map +1 -0
  94. package/dist/contracts/abis/tokens-abis.js +6 -0
  95. package/dist/contracts/abis/tokens-abis.js.map +1 -0
  96. package/dist/contracts/addresses.cjs +2 -0
  97. package/dist/contracts/addresses.cjs.map +1 -0
  98. package/dist/contracts/addresses.d.ts +23 -0
  99. package/dist/contracts/addresses.js +27 -0
  100. package/dist/contracts/addresses.js.map +1 -0
  101. package/dist/contracts/handlers/erc20-permit-handler.cjs +2 -0
  102. package/dist/contracts/handlers/erc20-permit-handler.cjs.map +1 -0
  103. package/dist/contracts/handlers/erc20-permit-handler.d.ts +579 -579
  104. package/dist/contracts/handlers/erc20-permit-handler.js +124 -0
  105. package/dist/contracts/handlers/erc20-permit-handler.js.map +1 -0
  106. package/dist/contracts/handlers/l1-reward-manager-handler.cjs +2 -0
  107. package/dist/contracts/handlers/l1-reward-manager-handler.cjs.map +1 -0
  108. package/dist/contracts/handlers/l1-reward-manager-handler.d.ts +6693 -0
  109. package/dist/contracts/handlers/l1-reward-manager-handler.js +68 -0
  110. package/dist/contracts/handlers/l1-reward-manager-handler.js.map +1 -0
  111. package/dist/contracts/handlers/l2-reward-manager-handler.cjs +2 -0
  112. package/dist/contracts/handlers/l2-reward-manager-handler.cjs.map +1 -0
  113. package/dist/contracts/handlers/l2-reward-manager-handler.d.ts +6912 -0
  114. package/dist/contracts/handlers/l2-reward-manager-handler.js +137 -0
  115. package/dist/contracts/handlers/l2-reward-manager-handler.js.map +1 -0
  116. package/dist/contracts/handlers/puf-locker-handler.cjs +2 -0
  117. package/dist/contracts/handlers/puf-locker-handler.cjs.map +1 -0
  118. package/dist/contracts/handlers/puf-locker-handler.d.ts +579 -579
  119. package/dist/contracts/handlers/puf-locker-handler.js +168 -0
  120. package/dist/contracts/handlers/puf-locker-handler.js.map +1 -0
  121. package/dist/contracts/handlers/puf-token-handler.cjs +2 -0
  122. package/dist/contracts/handlers/puf-token-handler.cjs.map +1 -0
  123. package/dist/contracts/handlers/puf-token-handler.d.ts +579 -579
  124. package/dist/contracts/handlers/puf-token-handler.js +174 -0
  125. package/dist/contracts/handlers/puf-token-handler.js.map +1 -0
  126. package/dist/contracts/handlers/puffer-depositor-handler.cjs +2 -0
  127. package/dist/contracts/handlers/puffer-depositor-handler.cjs.map +1 -0
  128. package/dist/contracts/handlers/puffer-depositor-handler.d.ts +579 -579
  129. package/dist/contracts/handlers/puffer-depositor-handler.js +113 -0
  130. package/dist/contracts/handlers/puffer-depositor-handler.js.map +1 -0
  131. package/dist/contracts/handlers/puffer-l2-depositor-handler.cjs +2 -0
  132. package/dist/contracts/handlers/puffer-l2-depositor-handler.cjs.map +1 -0
  133. package/dist/contracts/handlers/puffer-l2-depositor-handler.d.ts +579 -579
  134. package/dist/contracts/handlers/puffer-l2-depositor-handler.js +112 -0
  135. package/dist/contracts/handlers/puffer-l2-depositor-handler.js.map +1 -0
  136. package/dist/contracts/handlers/puffer-vault-handler.cjs +2 -0
  137. package/dist/contracts/handlers/puffer-vault-handler.cjs.map +1 -0
  138. package/dist/contracts/handlers/puffer-vault-handler.d.ts +579 -579
  139. package/dist/contracts/handlers/puffer-vault-handler.js +185 -0
  140. package/dist/contracts/handlers/puffer-vault-handler.js.map +1 -0
  141. package/dist/contracts/tokens.cjs +2 -0
  142. package/dist/contracts/tokens.cjs.map +1 -0
  143. package/dist/contracts/tokens.d.ts +0 -1
  144. package/dist/contracts/tokens.js +134 -0
  145. package/dist/contracts/tokens.js.map +1 -0
  146. package/dist/createWalletClient-Bmopj8MM.cjs +4 -0
  147. package/dist/createWalletClient-Bmopj8MM.cjs.map +1 -0
  148. package/dist/createWalletClient-DKcpswHR.js +2007 -0
  149. package/dist/createWalletClient-DKcpswHR.js.map +1 -0
  150. package/dist/errors/base-error.cjs +3 -0
  151. package/dist/errors/base-error.cjs.map +1 -0
  152. package/dist/errors/base-error.d.ts +0 -1
  153. package/dist/errors/base-error.js +23 -0
  154. package/dist/errors/base-error.js.map +1 -0
  155. package/dist/errors/types.cjs +2 -0
  156. package/dist/errors/types.cjs.map +1 -0
  157. package/dist/errors/types.js +2 -0
  158. package/dist/errors/types.js.map +1 -0
  159. package/dist/errors/validation-errors.cjs +2 -0
  160. package/dist/errors/validation-errors.cjs.map +1 -0
  161. package/dist/errors/validation-errors.d.ts +2 -1
  162. package/dist/errors/validation-errors.js +10 -0
  163. package/dist/errors/validation-errors.js.map +1 -0
  164. package/dist/getContract-B3Spz0SO.js +115 -0
  165. package/dist/getContract-B3Spz0SO.js.map +1 -0
  166. package/dist/getContract-MrPLx6gp.cjs +2 -0
  167. package/dist/getContract-MrPLx6gp.cjs.map +1 -0
  168. package/dist/main.cjs +1 -1
  169. package/dist/main.js +14 -10
  170. package/dist/main.js.map +1 -1
  171. package/dist/secp256k1-BLbXMlpX.js +1172 -0
  172. package/dist/secp256k1-BLbXMlpX.js.map +1 -0
  173. package/dist/secp256k1-CFnFaJ0H.cjs +2 -0
  174. package/dist/secp256k1-CFnFaJ0H.cjs.map +1 -0
  175. package/dist/utils/time.cjs +2 -0
  176. package/dist/utils/time.cjs.map +1 -0
  177. package/dist/utils/time.js +5 -0
  178. package/dist/utils/time.js.map +1 -0
  179. package/dist/utils/types.cjs +2 -0
  180. package/dist/utils/types.cjs.map +1 -0
  181. package/dist/utils/types.js +2 -0
  182. package/dist/utils/types.js.map +1 -0
  183. package/dist/utils/version.cjs +2 -0
  184. package/dist/utils/version.cjs.map +1 -0
  185. package/dist/utils/version.js +5 -0
  186. package/dist/utils/version.js.map +1 -0
  187. package/dist/writeContract-BBHpAss8.cjs +32 -0
  188. package/dist/writeContract-BBHpAss8.cjs.map +1 -0
  189. package/dist/writeContract-RluxM31W.js +3833 -0
  190. package/dist/writeContract-RluxM31W.js.map +1 -0
  191. package/package.json +22 -11
  192. package/dist/ccip-Dv116NSL.cjs +0 -2
  193. package/dist/contracts/handlers/erc20-permit-handler.test.d.ts +0 -1
  194. package/dist/contracts/handlers/puf-locker-handler.test.d.ts +0 -1
  195. package/dist/contracts/handlers/puf-token-handler.test.d.ts +0 -1
  196. package/dist/contracts/handlers/puffer-depositor-handler.test.d.ts +0 -1
  197. package/dist/contracts/handlers/puffer-l2-depositor-handler.test.d.ts +0 -1
  198. package/dist/contracts/handlers/puffer-vault-handler.test.d.ts +0 -1
  199. package/dist/main-69HiNG3t.js +0 -16001
  200. package/dist/main-69HiNG3t.js.map +0 -1
  201. package/dist/main-IyjWcdJ1.cjs +0 -41
  202. package/dist/main-IyjWcdJ1.cjs.map +0 -1
@@ -0,0 +1,1172 @@
1
+ import { H as Ft, h as Gt, t as Wt, e as qt, b as Xt, a as Dt, r as Qt, s as Jt } from "./constants-rWWWhxR_.js";
2
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
3
+ const Ut = BigInt(0), ht = BigInt(1), te = BigInt(2);
4
+ function nt(e) {
5
+ return e instanceof Uint8Array || e != null && typeof e == "object" && e.constructor.name === "Uint8Array";
6
+ }
7
+ function lt(e) {
8
+ if (!nt(e))
9
+ throw new Error("Uint8Array expected");
10
+ }
11
+ const ee = /* @__PURE__ */ Array.from({ length: 256 }, (e, n) => n.toString(16).padStart(2, "0"));
12
+ function st(e) {
13
+ lt(e);
14
+ let n = "";
15
+ for (let t = 0; t < e.length; t++)
16
+ n += ee[e[t]];
17
+ return n;
18
+ }
19
+ function Rt(e) {
20
+ const n = e.toString(16);
21
+ return n.length & 1 ? `0${n}` : n;
22
+ }
23
+ function Bt(e) {
24
+ if (typeof e != "string")
25
+ throw new Error("hex string expected, got " + typeof e);
26
+ return BigInt(e === "" ? "0" : `0x${e}`);
27
+ }
28
+ const P = { _0: 48, _9: 57, _A: 65, _F: 70, _a: 97, _f: 102 };
29
+ function Nt(e) {
30
+ if (e >= P._0 && e <= P._9)
31
+ return e - P._0;
32
+ if (e >= P._A && e <= P._F)
33
+ return e - (P._A - 10);
34
+ if (e >= P._a && e <= P._f)
35
+ return e - (P._a - 10);
36
+ }
37
+ function ct(e) {
38
+ if (typeof e != "string")
39
+ throw new Error("hex string expected, got " + typeof e);
40
+ const n = e.length, t = n / 2;
41
+ if (n % 2)
42
+ throw new Error("padded hex string expected, got unpadded hex of length " + n);
43
+ const r = new Uint8Array(t);
44
+ for (let s = 0, i = 0; s < t; s++, i += 2) {
45
+ const l = Nt(e.charCodeAt(i)), c = Nt(e.charCodeAt(i + 1));
46
+ if (l === void 0 || c === void 0) {
47
+ const o = e[i] + e[i + 1];
48
+ throw new Error('hex string expected, got non-hex character "' + o + '" at index ' + i);
49
+ }
50
+ r[s] = l * 16 + c;
51
+ }
52
+ return r;
53
+ }
54
+ function et(e) {
55
+ return Bt(st(e));
56
+ }
57
+ function xt(e) {
58
+ return lt(e), Bt(st(Uint8Array.from(e).reverse()));
59
+ }
60
+ function ft(e, n) {
61
+ return ct(e.toString(16).padStart(n * 2, "0"));
62
+ }
63
+ function vt(e, n) {
64
+ return ft(e, n).reverse();
65
+ }
66
+ function ne(e) {
67
+ return ct(Rt(e));
68
+ }
69
+ function M(e, n, t) {
70
+ let r;
71
+ if (typeof n == "string")
72
+ try {
73
+ r = ct(n);
74
+ } catch (i) {
75
+ throw new Error(`${e} must be valid hex string, got "${n}". Cause: ${i}`);
76
+ }
77
+ else if (nt(n))
78
+ r = Uint8Array.from(n);
79
+ else
80
+ throw new Error(`${e} must be hex string or Uint8Array`);
81
+ const s = r.length;
82
+ if (typeof t == "number" && s !== t)
83
+ throw new Error(`${e} expected ${t} bytes, got ${s}`);
84
+ return r;
85
+ }
86
+ function ut(...e) {
87
+ let n = 0;
88
+ for (let r = 0; r < e.length; r++) {
89
+ const s = e[r];
90
+ lt(s), n += s.length;
91
+ }
92
+ const t = new Uint8Array(n);
93
+ for (let r = 0, s = 0; r < e.length; r++) {
94
+ const i = e[r];
95
+ t.set(i, s), s += i.length;
96
+ }
97
+ return t;
98
+ }
99
+ function re(e, n) {
100
+ if (e.length !== n.length)
101
+ return !1;
102
+ let t = 0;
103
+ for (let r = 0; r < e.length; r++)
104
+ t |= e[r] ^ n[r];
105
+ return t === 0;
106
+ }
107
+ function oe(e) {
108
+ if (typeof e != "string")
109
+ throw new Error(`utf8ToBytes expected string, got ${typeof e}`);
110
+ return new Uint8Array(new TextEncoder().encode(e));
111
+ }
112
+ function ie(e) {
113
+ let n;
114
+ for (n = 0; e > Ut; e >>= ht, n += 1)
115
+ ;
116
+ return n;
117
+ }
118
+ function se(e, n) {
119
+ return e >> BigInt(n) & ht;
120
+ }
121
+ function ce(e, n, t) {
122
+ return e | (t ? ht : Ut) << BigInt(n);
123
+ }
124
+ const St = (e) => (te << BigInt(e - 1)) - ht, wt = (e) => new Uint8Array(e), _t = (e) => Uint8Array.from(e);
125
+ function zt(e, n, t) {
126
+ if (typeof e != "number" || e < 2)
127
+ throw new Error("hashLen must be a number");
128
+ if (typeof n != "number" || n < 2)
129
+ throw new Error("qByteLen must be a number");
130
+ if (typeof t != "function")
131
+ throw new Error("hmacFn must be a function");
132
+ let r = wt(e), s = wt(e), i = 0;
133
+ const l = () => {
134
+ r.fill(1), s.fill(0), i = 0;
135
+ }, c = (...w) => t(s, r, ...w), o = (w = wt()) => {
136
+ s = c(_t([0]), w), r = c(), w.length !== 0 && (s = c(_t([1]), w), r = c());
137
+ }, a = () => {
138
+ if (i++ >= 1e3)
139
+ throw new Error("drbg: tried 1000 values");
140
+ let w = 0;
141
+ const O = [];
142
+ for (; w < n; ) {
143
+ r = c();
144
+ const T = r.slice();
145
+ O.push(T), w += r.length;
146
+ }
147
+ return ut(...O);
148
+ };
149
+ return (w, O) => {
150
+ l(), o(w);
151
+ let T;
152
+ for (; !(T = O(a())); )
153
+ o();
154
+ return l(), T;
155
+ };
156
+ }
157
+ const fe = {
158
+ bigint: (e) => typeof e == "bigint",
159
+ function: (e) => typeof e == "function",
160
+ boolean: (e) => typeof e == "boolean",
161
+ string: (e) => typeof e == "string",
162
+ stringOrUint8Array: (e) => typeof e == "string" || nt(e),
163
+ isSafeInteger: (e) => Number.isSafeInteger(e),
164
+ array: (e) => Array.isArray(e),
165
+ field: (e, n) => n.Fp.isValid(e),
166
+ hash: (e) => typeof e == "function" && Number.isSafeInteger(e.outputLen)
167
+ };
168
+ function dt(e, n, t = {}) {
169
+ const r = (s, i, l) => {
170
+ const c = fe[i];
171
+ if (typeof c != "function")
172
+ throw new Error(`Invalid validator "${i}", expected function`);
173
+ const o = e[s];
174
+ if (!(l && o === void 0) && !c(o, e))
175
+ throw new Error(`Invalid param ${String(s)}=${o} (${typeof o}), expected ${i}`);
176
+ };
177
+ for (const [s, i] of Object.entries(n))
178
+ r(s, i, !1);
179
+ for (const [s, i] of Object.entries(t))
180
+ r(s, i, !0);
181
+ return e;
182
+ }
183
+ const ae = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
184
+ __proto__: null,
185
+ abytes: lt,
186
+ bitGet: se,
187
+ bitLen: ie,
188
+ bitMask: St,
189
+ bitSet: ce,
190
+ bytesToHex: st,
191
+ bytesToNumberBE: et,
192
+ bytesToNumberLE: xt,
193
+ concatBytes: ut,
194
+ createHmacDrbg: zt,
195
+ ensureBytes: M,
196
+ equalBytes: re,
197
+ hexToBytes: ct,
198
+ hexToNumber: Bt,
199
+ isBytes: nt,
200
+ numberToBytesBE: ft,
201
+ numberToBytesLE: vt,
202
+ numberToHexUnpadded: Rt,
203
+ numberToVarBytesBE: ne,
204
+ utf8ToBytes: oe,
205
+ validateObject: dt
206
+ }, Symbol.toStringTag, { value: "Module" }));
207
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
208
+ const L = BigInt(0), $ = BigInt(1), J = BigInt(2), ue = BigInt(3), yt = BigInt(4), Tt = BigInt(5), $t = BigInt(8);
209
+ BigInt(9);
210
+ BigInt(16);
211
+ function R(e, n) {
212
+ const t = e % n;
213
+ return t >= L ? t : n + t;
214
+ }
215
+ function le(e, n, t) {
216
+ if (t <= L || n < L)
217
+ throw new Error("Expected power/modulo > 0");
218
+ if (t === $)
219
+ return L;
220
+ let r = $;
221
+ for (; n > L; )
222
+ n & $ && (r = r * e % t), e = e * e % t, n >>= $;
223
+ return r;
224
+ }
225
+ function V(e, n, t) {
226
+ let r = e;
227
+ for (; n-- > L; )
228
+ r *= r, r %= t;
229
+ return r;
230
+ }
231
+ function mt(e, n) {
232
+ if (e === L || n <= L)
233
+ throw new Error(`invert: expected positive integers, got n=${e} mod=${n}`);
234
+ let t = R(e, n), r = n, s = L, i = $;
235
+ for (; t !== L; ) {
236
+ const c = r / t, o = r % t, a = s - i * c;
237
+ r = t, t = o, s = i, i = a;
238
+ }
239
+ if (r !== $)
240
+ throw new Error("invert: does not exist");
241
+ return R(s, n);
242
+ }
243
+ function de(e) {
244
+ const n = (e - $) / J;
245
+ let t, r, s;
246
+ for (t = e - $, r = 0; t % J === L; t /= J, r++)
247
+ ;
248
+ for (s = J; s < e && le(s, n, e) !== e - $; s++)
249
+ ;
250
+ if (r === 1) {
251
+ const l = (e + $) / yt;
252
+ return function(o, a) {
253
+ const y = o.pow(a, l);
254
+ if (!o.eql(o.sqr(y), a))
255
+ throw new Error("Cannot find square root");
256
+ return y;
257
+ };
258
+ }
259
+ const i = (t + $) / J;
260
+ return function(c, o) {
261
+ if (c.pow(o, n) === c.neg(c.ONE))
262
+ throw new Error("Cannot find square root");
263
+ let a = r, y = c.pow(c.mul(c.ONE, s), t), w = c.pow(o, i), O = c.pow(o, t);
264
+ for (; !c.eql(O, c.ONE); ) {
265
+ if (c.eql(O, c.ZERO))
266
+ return c.ZERO;
267
+ let T = 1;
268
+ for (let f = c.sqr(O); T < a && !c.eql(f, c.ONE); T++)
269
+ f = c.sqr(f);
270
+ const m = c.pow(y, $ << BigInt(a - T - 1));
271
+ y = c.sqr(m), w = c.mul(w, m), O = c.mul(O, y), a = T;
272
+ }
273
+ return w;
274
+ };
275
+ }
276
+ function he(e) {
277
+ if (e % yt === ue) {
278
+ const n = (e + $) / yt;
279
+ return function(r, s) {
280
+ const i = r.pow(s, n);
281
+ if (!r.eql(r.sqr(i), s))
282
+ throw new Error("Cannot find square root");
283
+ return i;
284
+ };
285
+ }
286
+ if (e % $t === Tt) {
287
+ const n = (e - Tt) / $t;
288
+ return function(r, s) {
289
+ const i = r.mul(s, J), l = r.pow(i, n), c = r.mul(s, l), o = r.mul(r.mul(c, J), l), a = r.mul(c, r.sub(o, r.ONE));
290
+ if (!r.eql(r.sqr(a), s))
291
+ throw new Error("Cannot find square root");
292
+ return a;
293
+ };
294
+ }
295
+ return de(e);
296
+ }
297
+ const ge = [
298
+ "create",
299
+ "isValid",
300
+ "is0",
301
+ "neg",
302
+ "inv",
303
+ "sqrt",
304
+ "sqr",
305
+ "eql",
306
+ "add",
307
+ "sub",
308
+ "mul",
309
+ "pow",
310
+ "div",
311
+ "addN",
312
+ "subN",
313
+ "mulN",
314
+ "sqrN"
315
+ ];
316
+ function we(e) {
317
+ const n = {
318
+ ORDER: "bigint",
319
+ MASK: "bigint",
320
+ BYTES: "isSafeInteger",
321
+ BITS: "isSafeInteger"
322
+ }, t = ge.reduce((r, s) => (r[s] = "function", r), n);
323
+ return dt(e, t);
324
+ }
325
+ function pe(e, n, t) {
326
+ if (t < L)
327
+ throw new Error("Expected power > 0");
328
+ if (t === L)
329
+ return e.ONE;
330
+ if (t === $)
331
+ return n;
332
+ let r = e.ONE, s = n;
333
+ for (; t > L; )
334
+ t & $ && (r = e.mul(r, s)), s = e.sqr(s), t >>= $;
335
+ return r;
336
+ }
337
+ function ye(e, n) {
338
+ const t = new Array(n.length), r = n.reduce((i, l, c) => e.is0(l) ? i : (t[c] = i, e.mul(i, l)), e.ONE), s = e.inv(r);
339
+ return n.reduceRight((i, l, c) => e.is0(l) ? i : (t[c] = e.mul(i, t[c]), e.mul(i, l)), s), t;
340
+ }
341
+ function Ct(e, n) {
342
+ const t = n !== void 0 ? n : e.toString(2).length, r = Math.ceil(t / 8);
343
+ return { nBitLength: t, nByteLength: r };
344
+ }
345
+ function me(e, n, t = !1, r = {}) {
346
+ if (e <= L)
347
+ throw new Error(`Expected Field ORDER > 0, got ${e}`);
348
+ const { nBitLength: s, nByteLength: i } = Ct(e, n);
349
+ if (i > 2048)
350
+ throw new Error("Field lengths over 2048 bytes are not supported");
351
+ const l = he(e), c = Object.freeze({
352
+ ORDER: e,
353
+ BITS: s,
354
+ BYTES: i,
355
+ MASK: St(s),
356
+ ZERO: L,
357
+ ONE: $,
358
+ create: (o) => R(o, e),
359
+ isValid: (o) => {
360
+ if (typeof o != "bigint")
361
+ throw new Error(`Invalid field element: expected bigint, got ${typeof o}`);
362
+ return L <= o && o < e;
363
+ },
364
+ is0: (o) => o === L,
365
+ isOdd: (o) => (o & $) === $,
366
+ neg: (o) => R(-o, e),
367
+ eql: (o, a) => o === a,
368
+ sqr: (o) => R(o * o, e),
369
+ add: (o, a) => R(o + a, e),
370
+ sub: (o, a) => R(o - a, e),
371
+ mul: (o, a) => R(o * a, e),
372
+ pow: (o, a) => pe(c, o, a),
373
+ div: (o, a) => R(o * mt(a, e), e),
374
+ // Same as above, but doesn't normalize
375
+ sqrN: (o) => o * o,
376
+ addN: (o, a) => o + a,
377
+ subN: (o, a) => o - a,
378
+ mulN: (o, a) => o * a,
379
+ inv: (o) => mt(o, e),
380
+ sqrt: r.sqrt || ((o) => l(c, o)),
381
+ invertBatch: (o) => ye(c, o),
382
+ // TODO: do we really need constant cmov?
383
+ // We don't have const-time bigints anyway, so probably will be not very useful
384
+ cmov: (o, a, y) => y ? a : o,
385
+ toBytes: (o) => t ? vt(o, i) : ft(o, i),
386
+ fromBytes: (o) => {
387
+ if (o.length !== i)
388
+ throw new Error(`Fp.fromBytes: expected ${i}, got ${o.length}`);
389
+ return t ? xt(o) : et(o);
390
+ }
391
+ });
392
+ return Object.freeze(c);
393
+ }
394
+ function kt(e) {
395
+ if (typeof e != "bigint")
396
+ throw new Error("field order must be bigint");
397
+ const n = e.toString(2).length;
398
+ return Math.ceil(n / 8);
399
+ }
400
+ function Vt(e) {
401
+ const n = kt(e);
402
+ return n + Math.ceil(n / 2);
403
+ }
404
+ function be(e, n, t = !1) {
405
+ const r = e.length, s = kt(n), i = Vt(n);
406
+ if (r < 16 || r < i || r > 1024)
407
+ throw new Error(`expected ${i}-1024 bytes of input, got ${r}`);
408
+ const l = t ? et(e) : xt(e), c = R(l, n - $) + $;
409
+ return t ? vt(c, s) : ft(c, s);
410
+ }
411
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
412
+ const Ee = BigInt(0), pt = BigInt(1);
413
+ function Be(e, n) {
414
+ const t = (s, i) => {
415
+ const l = i.negate();
416
+ return s ? l : i;
417
+ }, r = (s) => {
418
+ const i = Math.ceil(n / s) + 1, l = 2 ** (s - 1);
419
+ return { windows: i, windowSize: l };
420
+ };
421
+ return {
422
+ constTimeNegate: t,
423
+ // non-const time multiplication ladder
424
+ unsafeLadder(s, i) {
425
+ let l = e.ZERO, c = s;
426
+ for (; i > Ee; )
427
+ i & pt && (l = l.add(c)), c = c.double(), i >>= pt;
428
+ return l;
429
+ },
430
+ /**
431
+ * Creates a wNAF precomputation window. Used for caching.
432
+ * Default window size is set by `utils.precompute()` and is equal to 8.
433
+ * Number of precomputed points depends on the curve size:
434
+ * 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
435
+ * - 𝑊 is the window size
436
+ * - 𝑛 is the bitlength of the curve order.
437
+ * For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
438
+ * @returns precomputed point tables flattened to a single array
439
+ */
440
+ precomputeWindow(s, i) {
441
+ const { windows: l, windowSize: c } = r(i), o = [];
442
+ let a = s, y = a;
443
+ for (let w = 0; w < l; w++) {
444
+ y = a, o.push(y);
445
+ for (let O = 1; O < c; O++)
446
+ y = y.add(a), o.push(y);
447
+ a = y.double();
448
+ }
449
+ return o;
450
+ },
451
+ /**
452
+ * Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
453
+ * @param W window size
454
+ * @param precomputes precomputed tables
455
+ * @param n scalar (we don't check here, but should be less than curve order)
456
+ * @returns real and fake (for const-time) points
457
+ */
458
+ wNAF(s, i, l) {
459
+ const { windows: c, windowSize: o } = r(s);
460
+ let a = e.ZERO, y = e.BASE;
461
+ const w = BigInt(2 ** s - 1), O = 2 ** s, T = BigInt(s);
462
+ for (let m = 0; m < c; m++) {
463
+ const f = m * o;
464
+ let d = Number(l & w);
465
+ l >>= T, d > o && (d -= O, l += pt);
466
+ const h = f, b = f + Math.abs(d) - 1, B = m % 2 !== 0, I = d < 0;
467
+ d === 0 ? y = y.add(t(B, i[h])) : a = a.add(t(I, i[b]));
468
+ }
469
+ return { p: a, f: y };
470
+ },
471
+ wNAFCached(s, i, l, c) {
472
+ const o = s._WINDOW_SIZE || 1;
473
+ let a = i.get(s);
474
+ return a || (a = this.precomputeWindow(s, o), o !== 1 && i.set(s, c(a))), this.wNAF(o, a, l);
475
+ }
476
+ };
477
+ }
478
+ function jt(e) {
479
+ return we(e.Fp), dt(e, {
480
+ n: "bigint",
481
+ h: "bigint",
482
+ Gx: "field",
483
+ Gy: "field"
484
+ }, {
485
+ nBitLength: "isSafeInteger",
486
+ nByteLength: "isSafeInteger"
487
+ }), Object.freeze({
488
+ ...Ct(e.n, e.nBitLength),
489
+ ...e,
490
+ p: e.Fp.ORDER
491
+ });
492
+ }
493
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
494
+ function xe(e) {
495
+ const n = jt(e);
496
+ dt(n, {
497
+ a: "field",
498
+ b: "field"
499
+ }, {
500
+ allowedPrivateKeyLengths: "array",
501
+ wrapPrivateKey: "boolean",
502
+ isTorsionFree: "function",
503
+ clearCofactor: "function",
504
+ allowInfinityPoint: "boolean",
505
+ fromBytes: "function",
506
+ toBytes: "function"
507
+ });
508
+ const { endo: t, Fp: r, a: s } = n;
509
+ if (t) {
510
+ if (!r.eql(s, r.ZERO))
511
+ throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");
512
+ if (typeof t != "object" || typeof t.beta != "bigint" || typeof t.splitScalar != "function")
513
+ throw new Error("Expected endomorphism with beta: bigint and splitScalar: function");
514
+ }
515
+ return Object.freeze({ ...n });
516
+ }
517
+ const { bytesToNumberBE: ve, hexToBytes: Se } = ae, tt = {
518
+ // asn.1 DER encoding utils
519
+ Err: class extends Error {
520
+ constructor(n = "") {
521
+ super(n);
522
+ }
523
+ },
524
+ _parseInt(e) {
525
+ const { Err: n } = tt;
526
+ if (e.length < 2 || e[0] !== 2)
527
+ throw new n("Invalid signature integer tag");
528
+ const t = e[1], r = e.subarray(2, t + 2);
529
+ if (!t || r.length !== t)
530
+ throw new n("Invalid signature integer: wrong length");
531
+ if (r[0] & 128)
532
+ throw new n("Invalid signature integer: negative");
533
+ if (r[0] === 0 && !(r[1] & 128))
534
+ throw new n("Invalid signature integer: unnecessary leading zero");
535
+ return { d: ve(r), l: e.subarray(t + 2) };
536
+ },
537
+ toSig(e) {
538
+ const { Err: n } = tt, t = typeof e == "string" ? Se(e) : e;
539
+ lt(t);
540
+ let r = t.length;
541
+ if (r < 2 || t[0] != 48)
542
+ throw new n("Invalid signature tag");
543
+ if (t[1] !== r - 2)
544
+ throw new n("Invalid signature: incorrect length");
545
+ const { d: s, l: i } = tt._parseInt(t.subarray(2)), { d: l, l: c } = tt._parseInt(i);
546
+ if (c.length)
547
+ throw new n("Invalid signature: left bytes after parsing");
548
+ return { r: s, s: l };
549
+ },
550
+ hexFromSig(e) {
551
+ const n = (a) => Number.parseInt(a[0], 16) & 8 ? "00" + a : a, t = (a) => {
552
+ const y = a.toString(16);
553
+ return y.length & 1 ? `0${y}` : y;
554
+ }, r = n(t(e.s)), s = n(t(e.r)), i = r.length / 2, l = s.length / 2, c = t(i), o = t(l);
555
+ return `30${t(l + i + 4)}02${o}${s}02${c}${r}`;
556
+ }
557
+ }, F = BigInt(0), j = BigInt(1);
558
+ BigInt(2);
559
+ const Ht = BigInt(3);
560
+ BigInt(4);
561
+ function Ie(e) {
562
+ const n = xe(e), { Fp: t } = n, r = n.toBytes || ((m, f, d) => {
563
+ const h = f.toAffine();
564
+ return ut(Uint8Array.from([4]), t.toBytes(h.x), t.toBytes(h.y));
565
+ }), s = n.fromBytes || ((m) => {
566
+ const f = m.subarray(1), d = t.fromBytes(f.subarray(0, t.BYTES)), h = t.fromBytes(f.subarray(t.BYTES, 2 * t.BYTES));
567
+ return { x: d, y: h };
568
+ });
569
+ function i(m) {
570
+ const { a: f, b: d } = n, h = t.sqr(m), b = t.mul(h, m);
571
+ return t.add(t.add(b, t.mul(m, f)), d);
572
+ }
573
+ if (!t.eql(t.sqr(n.Gy), i(n.Gx)))
574
+ throw new Error("bad generator point: equation left != right");
575
+ function l(m) {
576
+ return typeof m == "bigint" && F < m && m < n.n;
577
+ }
578
+ function c(m) {
579
+ if (!l(m))
580
+ throw new Error("Expected valid bigint: 0 < bigint < curve.n");
581
+ }
582
+ function o(m) {
583
+ const { allowedPrivateKeyLengths: f, nByteLength: d, wrapPrivateKey: h, n: b } = n;
584
+ if (f && typeof m != "bigint") {
585
+ if (nt(m) && (m = st(m)), typeof m != "string" || !f.includes(m.length))
586
+ throw new Error("Invalid key");
587
+ m = m.padStart(d * 2, "0");
588
+ }
589
+ let B;
590
+ try {
591
+ B = typeof m == "bigint" ? m : et(M("private key", m, d));
592
+ } catch {
593
+ throw new Error(`private key must be ${d} bytes, hex or bigint, not ${typeof m}`);
594
+ }
595
+ return h && (B = R(B, b)), c(B), B;
596
+ }
597
+ const a = /* @__PURE__ */ new Map();
598
+ function y(m) {
599
+ if (!(m instanceof w))
600
+ throw new Error("ProjectivePoint expected");
601
+ }
602
+ class w {
603
+ constructor(f, d, h) {
604
+ if (this.px = f, this.py = d, this.pz = h, f == null || !t.isValid(f))
605
+ throw new Error("x required");
606
+ if (d == null || !t.isValid(d))
607
+ throw new Error("y required");
608
+ if (h == null || !t.isValid(h))
609
+ throw new Error("z required");
610
+ }
611
+ // Does not validate if the point is on-curve.
612
+ // Use fromHex instead, or call assertValidity() later.
613
+ static fromAffine(f) {
614
+ const { x: d, y: h } = f || {};
615
+ if (!f || !t.isValid(d) || !t.isValid(h))
616
+ throw new Error("invalid affine point");
617
+ if (f instanceof w)
618
+ throw new Error("projective point not allowed");
619
+ const b = (B) => t.eql(B, t.ZERO);
620
+ return b(d) && b(h) ? w.ZERO : new w(d, h, t.ONE);
621
+ }
622
+ get x() {
623
+ return this.toAffine().x;
624
+ }
625
+ get y() {
626
+ return this.toAffine().y;
627
+ }
628
+ /**
629
+ * Takes a bunch of Projective Points but executes only one
630
+ * inversion on all of them. Inversion is very slow operation,
631
+ * so this improves performance massively.
632
+ * Optimization: converts a list of projective points to a list of identical points with Z=1.
633
+ */
634
+ static normalizeZ(f) {
635
+ const d = t.invertBatch(f.map((h) => h.pz));
636
+ return f.map((h, b) => h.toAffine(d[b])).map(w.fromAffine);
637
+ }
638
+ /**
639
+ * Converts hash string or Uint8Array to Point.
640
+ * @param hex short/long ECDSA hex
641
+ */
642
+ static fromHex(f) {
643
+ const d = w.fromAffine(s(M("pointHex", f)));
644
+ return d.assertValidity(), d;
645
+ }
646
+ // Multiplies generator point by privateKey.
647
+ static fromPrivateKey(f) {
648
+ return w.BASE.multiply(o(f));
649
+ }
650
+ // "Private method", don't use it directly
651
+ _setWindowSize(f) {
652
+ this._WINDOW_SIZE = f, a.delete(this);
653
+ }
654
+ // A point on curve is valid if it conforms to equation.
655
+ assertValidity() {
656
+ if (this.is0()) {
657
+ if (n.allowInfinityPoint && !t.is0(this.py))
658
+ return;
659
+ throw new Error("bad point: ZERO");
660
+ }
661
+ const { x: f, y: d } = this.toAffine();
662
+ if (!t.isValid(f) || !t.isValid(d))
663
+ throw new Error("bad point: x or y not FE");
664
+ const h = t.sqr(d), b = i(f);
665
+ if (!t.eql(h, b))
666
+ throw new Error("bad point: equation left != right");
667
+ if (!this.isTorsionFree())
668
+ throw new Error("bad point: not in prime-order subgroup");
669
+ }
670
+ hasEvenY() {
671
+ const { y: f } = this.toAffine();
672
+ if (t.isOdd)
673
+ return !t.isOdd(f);
674
+ throw new Error("Field doesn't support isOdd");
675
+ }
676
+ /**
677
+ * Compare one point to another.
678
+ */
679
+ equals(f) {
680
+ y(f);
681
+ const { px: d, py: h, pz: b } = this, { px: B, py: I, pz: S } = f, p = t.eql(t.mul(d, S), t.mul(B, b)), E = t.eql(t.mul(h, S), t.mul(I, b));
682
+ return p && E;
683
+ }
684
+ /**
685
+ * Flips point to one corresponding to (x, -y) in Affine coordinates.
686
+ */
687
+ negate() {
688
+ return new w(this.px, t.neg(this.py), this.pz);
689
+ }
690
+ // Renes-Costello-Batina exception-free doubling formula.
691
+ // There is 30% faster Jacobian formula, but it is not complete.
692
+ // https://eprint.iacr.org/2015/1060, algorithm 3
693
+ // Cost: 8M + 3S + 3*a + 2*b3 + 15add.
694
+ double() {
695
+ const { a: f, b: d } = n, h = t.mul(d, Ht), { px: b, py: B, pz: I } = this;
696
+ let S = t.ZERO, p = t.ZERO, E = t.ZERO, v = t.mul(b, b), k = t.mul(B, B), _ = t.mul(I, I), A = t.mul(b, B);
697
+ return A = t.add(A, A), E = t.mul(b, I), E = t.add(E, E), S = t.mul(f, E), p = t.mul(h, _), p = t.add(S, p), S = t.sub(k, p), p = t.add(k, p), p = t.mul(S, p), S = t.mul(A, S), E = t.mul(h, E), _ = t.mul(f, _), A = t.sub(v, _), A = t.mul(f, A), A = t.add(A, E), E = t.add(v, v), v = t.add(E, v), v = t.add(v, _), v = t.mul(v, A), p = t.add(p, v), _ = t.mul(B, I), _ = t.add(_, _), v = t.mul(_, A), S = t.sub(S, v), E = t.mul(_, k), E = t.add(E, E), E = t.add(E, E), new w(S, p, E);
698
+ }
699
+ // Renes-Costello-Batina exception-free addition formula.
700
+ // There is 30% faster Jacobian formula, but it is not complete.
701
+ // https://eprint.iacr.org/2015/1060, algorithm 1
702
+ // Cost: 12M + 0S + 3*a + 3*b3 + 23add.
703
+ add(f) {
704
+ y(f);
705
+ const { px: d, py: h, pz: b } = this, { px: B, py: I, pz: S } = f;
706
+ let p = t.ZERO, E = t.ZERO, v = t.ZERO;
707
+ const k = n.a, _ = t.mul(n.b, Ht);
708
+ let A = t.mul(d, B), z = t.mul(h, I), C = t.mul(b, S), G = t.add(d, h), u = t.add(B, I);
709
+ G = t.mul(G, u), u = t.add(A, z), G = t.sub(G, u), u = t.add(d, b);
710
+ let g = t.add(B, S);
711
+ return u = t.mul(u, g), g = t.add(A, C), u = t.sub(u, g), g = t.add(h, b), p = t.add(I, S), g = t.mul(g, p), p = t.add(z, C), g = t.sub(g, p), v = t.mul(k, u), p = t.mul(_, C), v = t.add(p, v), p = t.sub(z, v), v = t.add(z, v), E = t.mul(p, v), z = t.add(A, A), z = t.add(z, A), C = t.mul(k, C), u = t.mul(_, u), z = t.add(z, C), C = t.sub(A, C), C = t.mul(k, C), u = t.add(u, C), A = t.mul(z, u), E = t.add(E, A), A = t.mul(g, u), p = t.mul(G, p), p = t.sub(p, A), A = t.mul(G, z), v = t.mul(g, v), v = t.add(v, A), new w(p, E, v);
712
+ }
713
+ subtract(f) {
714
+ return this.add(f.negate());
715
+ }
716
+ is0() {
717
+ return this.equals(w.ZERO);
718
+ }
719
+ wNAF(f) {
720
+ return T.wNAFCached(this, a, f, (d) => {
721
+ const h = t.invertBatch(d.map((b) => b.pz));
722
+ return d.map((b, B) => b.toAffine(h[B])).map(w.fromAffine);
723
+ });
724
+ }
725
+ /**
726
+ * Non-constant-time multiplication. Uses double-and-add algorithm.
727
+ * It's faster, but should only be used when you don't care about
728
+ * an exposed private key e.g. sig verification, which works over *public* keys.
729
+ */
730
+ multiplyUnsafe(f) {
731
+ const d = w.ZERO;
732
+ if (f === F)
733
+ return d;
734
+ if (c(f), f === j)
735
+ return this;
736
+ const { endo: h } = n;
737
+ if (!h)
738
+ return T.unsafeLadder(this, f);
739
+ let { k1neg: b, k1: B, k2neg: I, k2: S } = h.splitScalar(f), p = d, E = d, v = this;
740
+ for (; B > F || S > F; )
741
+ B & j && (p = p.add(v)), S & j && (E = E.add(v)), v = v.double(), B >>= j, S >>= j;
742
+ return b && (p = p.negate()), I && (E = E.negate()), E = new w(t.mul(E.px, h.beta), E.py, E.pz), p.add(E);
743
+ }
744
+ /**
745
+ * Constant time multiplication.
746
+ * Uses wNAF method. Windowed method may be 10% faster,
747
+ * but takes 2x longer to generate and consumes 2x memory.
748
+ * Uses precomputes when available.
749
+ * Uses endomorphism for Koblitz curves.
750
+ * @param scalar by which the point would be multiplied
751
+ * @returns New point
752
+ */
753
+ multiply(f) {
754
+ c(f);
755
+ let d = f, h, b;
756
+ const { endo: B } = n;
757
+ if (B) {
758
+ const { k1neg: I, k1: S, k2neg: p, k2: E } = B.splitScalar(d);
759
+ let { p: v, f: k } = this.wNAF(S), { p: _, f: A } = this.wNAF(E);
760
+ v = T.constTimeNegate(I, v), _ = T.constTimeNegate(p, _), _ = new w(t.mul(_.px, B.beta), _.py, _.pz), h = v.add(_), b = k.add(A);
761
+ } else {
762
+ const { p: I, f: S } = this.wNAF(d);
763
+ h = I, b = S;
764
+ }
765
+ return w.normalizeZ([h, b])[0];
766
+ }
767
+ /**
768
+ * Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
769
+ * Not using Strauss-Shamir trick: precomputation tables are faster.
770
+ * The trick could be useful if both P and Q are not G (not in our case).
771
+ * @returns non-zero affine point
772
+ */
773
+ multiplyAndAddUnsafe(f, d, h) {
774
+ const b = w.BASE, B = (S, p) => p === F || p === j || !S.equals(b) ? S.multiplyUnsafe(p) : S.multiply(p), I = B(this, d).add(B(f, h));
775
+ return I.is0() ? void 0 : I;
776
+ }
777
+ // Converts Projective point to affine (x, y) coordinates.
778
+ // Can accept precomputed Z^-1 - for example, from invertBatch.
779
+ // (x, y, z) ∋ (x=x/z, y=y/z)
780
+ toAffine(f) {
781
+ const { px: d, py: h, pz: b } = this, B = this.is0();
782
+ f == null && (f = B ? t.ONE : t.inv(b));
783
+ const I = t.mul(d, f), S = t.mul(h, f), p = t.mul(b, f);
784
+ if (B)
785
+ return { x: t.ZERO, y: t.ZERO };
786
+ if (!t.eql(p, t.ONE))
787
+ throw new Error("invZ was invalid");
788
+ return { x: I, y: S };
789
+ }
790
+ isTorsionFree() {
791
+ const { h: f, isTorsionFree: d } = n;
792
+ if (f === j)
793
+ return !0;
794
+ if (d)
795
+ return d(w, this);
796
+ throw new Error("isTorsionFree() has not been declared for the elliptic curve");
797
+ }
798
+ clearCofactor() {
799
+ const { h: f, clearCofactor: d } = n;
800
+ return f === j ? this : d ? d(w, this) : this.multiplyUnsafe(n.h);
801
+ }
802
+ toRawBytes(f = !0) {
803
+ return this.assertValidity(), r(w, this, f);
804
+ }
805
+ toHex(f = !0) {
806
+ return st(this.toRawBytes(f));
807
+ }
808
+ }
809
+ w.BASE = new w(n.Gx, n.Gy, t.ONE), w.ZERO = new w(t.ZERO, t.ONE, t.ZERO);
810
+ const O = n.nBitLength, T = Be(w, n.endo ? Math.ceil(O / 2) : O);
811
+ return {
812
+ CURVE: n,
813
+ ProjectivePoint: w,
814
+ normPrivateKeyToScalar: o,
815
+ weierstrassEquation: i,
816
+ isWithinCurveOrder: l
817
+ };
818
+ }
819
+ function Ae(e) {
820
+ const n = jt(e);
821
+ return dt(n, {
822
+ hash: "hash",
823
+ hmac: "function",
824
+ randomBytes: "function"
825
+ }, {
826
+ bits2int: "function",
827
+ bits2int_modN: "function",
828
+ lowS: "boolean"
829
+ }), Object.freeze({ lowS: !0, ...n });
830
+ }
831
+ function Oe(e) {
832
+ const n = Ae(e), { Fp: t, n: r } = n, s = t.BYTES + 1, i = 2 * t.BYTES + 1;
833
+ function l(u) {
834
+ return F < u && u < t.ORDER;
835
+ }
836
+ function c(u) {
837
+ return R(u, r);
838
+ }
839
+ function o(u) {
840
+ return mt(u, r);
841
+ }
842
+ const { ProjectivePoint: a, normPrivateKeyToScalar: y, weierstrassEquation: w, isWithinCurveOrder: O } = Ie({
843
+ ...n,
844
+ toBytes(u, g, x) {
845
+ const N = g.toAffine(), q = t.toBytes(N.x), H = ut;
846
+ return x ? H(Uint8Array.from([g.hasEvenY() ? 2 : 3]), q) : H(Uint8Array.from([4]), q, t.toBytes(N.y));
847
+ },
848
+ fromBytes(u) {
849
+ const g = u.length, x = u[0], N = u.subarray(1);
850
+ if (g === s && (x === 2 || x === 3)) {
851
+ const q = et(N);
852
+ if (!l(q))
853
+ throw new Error("Point is not on curve");
854
+ const H = w(q);
855
+ let Z;
856
+ try {
857
+ Z = t.sqrt(H);
858
+ } catch (Y) {
859
+ const X = Y instanceof Error ? ": " + Y.message : "";
860
+ throw new Error("Point is not on curve" + X);
861
+ }
862
+ const U = (Z & j) === j;
863
+ return (x & 1) === 1 !== U && (Z = t.neg(Z)), { x: q, y: Z };
864
+ } else if (g === i && x === 4) {
865
+ const q = t.fromBytes(N.subarray(0, t.BYTES)), H = t.fromBytes(N.subarray(t.BYTES, 2 * t.BYTES));
866
+ return { x: q, y: H };
867
+ } else
868
+ throw new Error(`Point of length ${g} was invalid. Expected ${s} compressed bytes or ${i} uncompressed bytes`);
869
+ }
870
+ }), T = (u) => st(ft(u, n.nByteLength));
871
+ function m(u) {
872
+ const g = r >> j;
873
+ return u > g;
874
+ }
875
+ function f(u) {
876
+ return m(u) ? c(-u) : u;
877
+ }
878
+ const d = (u, g, x) => et(u.slice(g, x));
879
+ class h {
880
+ constructor(g, x, N) {
881
+ this.r = g, this.s = x, this.recovery = N, this.assertValidity();
882
+ }
883
+ // pair (bytes of r, bytes of s)
884
+ static fromCompact(g) {
885
+ const x = n.nByteLength;
886
+ return g = M("compactSignature", g, x * 2), new h(d(g, 0, x), d(g, x, 2 * x));
887
+ }
888
+ // DER encoded ECDSA signature
889
+ // https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
890
+ static fromDER(g) {
891
+ const { r: x, s: N } = tt.toSig(M("DER", g));
892
+ return new h(x, N);
893
+ }
894
+ assertValidity() {
895
+ if (!O(this.r))
896
+ throw new Error("r must be 0 < r < CURVE.n");
897
+ if (!O(this.s))
898
+ throw new Error("s must be 0 < s < CURVE.n");
899
+ }
900
+ addRecoveryBit(g) {
901
+ return new h(this.r, this.s, g);
902
+ }
903
+ recoverPublicKey(g) {
904
+ const { r: x, s: N, recovery: q } = this, H = E(M("msgHash", g));
905
+ if (q == null || ![0, 1, 2, 3].includes(q))
906
+ throw new Error("recovery id invalid");
907
+ const Z = q === 2 || q === 3 ? x + n.n : x;
908
+ if (Z >= t.ORDER)
909
+ throw new Error("recovery id 2 or 3 invalid");
910
+ const U = q & 1 ? "03" : "02", W = a.fromHex(U + T(Z)), Y = o(Z), X = c(-H * Y), at = c(N * Y), D = a.BASE.multiplyAndAddUnsafe(W, X, at);
911
+ if (!D)
912
+ throw new Error("point at infinify");
913
+ return D.assertValidity(), D;
914
+ }
915
+ // Signatures should be low-s, to prevent malleability.
916
+ hasHighS() {
917
+ return m(this.s);
918
+ }
919
+ normalizeS() {
920
+ return this.hasHighS() ? new h(this.r, c(-this.s), this.recovery) : this;
921
+ }
922
+ // DER-encoded
923
+ toDERRawBytes() {
924
+ return ct(this.toDERHex());
925
+ }
926
+ toDERHex() {
927
+ return tt.hexFromSig({ r: this.r, s: this.s });
928
+ }
929
+ // padded bytes of r, then padded bytes of s
930
+ toCompactRawBytes() {
931
+ return ct(this.toCompactHex());
932
+ }
933
+ toCompactHex() {
934
+ return T(this.r) + T(this.s);
935
+ }
936
+ }
937
+ const b = {
938
+ isValidPrivateKey(u) {
939
+ try {
940
+ return y(u), !0;
941
+ } catch {
942
+ return !1;
943
+ }
944
+ },
945
+ normPrivateKeyToScalar: y,
946
+ /**
947
+ * Produces cryptographically secure private key from random of size
948
+ * (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
949
+ */
950
+ randomPrivateKey: () => {
951
+ const u = Vt(n.n);
952
+ return be(n.randomBytes(u), n.n);
953
+ },
954
+ /**
955
+ * Creates precompute table for an arbitrary EC point. Makes point "cached".
956
+ * Allows to massively speed-up `point.multiply(scalar)`.
957
+ * @returns cached point
958
+ * @example
959
+ * const fast = utils.precompute(8, ProjectivePoint.fromHex(someonesPubKey));
960
+ * fast.multiply(privKey); // much faster ECDH now
961
+ */
962
+ precompute(u = 8, g = a.BASE) {
963
+ return g._setWindowSize(u), g.multiply(BigInt(3)), g;
964
+ }
965
+ };
966
+ function B(u, g = !0) {
967
+ return a.fromPrivateKey(u).toRawBytes(g);
968
+ }
969
+ function I(u) {
970
+ const g = nt(u), x = typeof u == "string", N = (g || x) && u.length;
971
+ return g ? N === s || N === i : x ? N === 2 * s || N === 2 * i : u instanceof a;
972
+ }
973
+ function S(u, g, x = !0) {
974
+ if (I(u))
975
+ throw new Error("first arg must be private key");
976
+ if (!I(g))
977
+ throw new Error("second arg must be public key");
978
+ return a.fromHex(g).multiply(y(u)).toRawBytes(x);
979
+ }
980
+ const p = n.bits2int || function(u) {
981
+ const g = et(u), x = u.length * 8 - n.nBitLength;
982
+ return x > 0 ? g >> BigInt(x) : g;
983
+ }, E = n.bits2int_modN || function(u) {
984
+ return c(p(u));
985
+ }, v = St(n.nBitLength);
986
+ function k(u) {
987
+ if (typeof u != "bigint")
988
+ throw new Error("bigint expected");
989
+ if (!(F <= u && u < v))
990
+ throw new Error(`bigint expected < 2^${n.nBitLength}`);
991
+ return ft(u, n.nByteLength);
992
+ }
993
+ function _(u, g, x = A) {
994
+ if (["recovered", "canonical"].some((Q) => Q in x))
995
+ throw new Error("sign() legacy options not supported");
996
+ const { hash: N, randomBytes: q } = n;
997
+ let { lowS: H, prehash: Z, extraEntropy: U } = x;
998
+ H == null && (H = !0), u = M("msgHash", u), Z && (u = M("prehashed msgHash", N(u)));
999
+ const W = E(u), Y = y(g), X = [k(Y), k(W)];
1000
+ if (U != null && U !== !1) {
1001
+ const Q = U === !0 ? q(t.BYTES) : U;
1002
+ X.push(M("extraEntropy", Q));
1003
+ }
1004
+ const at = ut(...X), D = W;
1005
+ function gt(Q) {
1006
+ const rt = p(Q);
1007
+ if (!O(rt))
1008
+ return;
1009
+ const It = o(rt), ot = a.BASE.multiply(rt).toAffine(), K = c(ot.x);
1010
+ if (K === F)
1011
+ return;
1012
+ const it = c(It * c(D + K * Y));
1013
+ if (it === F)
1014
+ return;
1015
+ let At = (ot.x === K ? 0 : 2) | Number(ot.y & j), Ot = it;
1016
+ return H && m(it) && (Ot = f(it), At ^= 1), new h(K, Ot, At);
1017
+ }
1018
+ return { seed: at, k2sig: gt };
1019
+ }
1020
+ const A = { lowS: n.lowS, prehash: !1 }, z = { lowS: n.lowS, prehash: !1 };
1021
+ function C(u, g, x = A) {
1022
+ const { seed: N, k2sig: q } = _(u, g, x), H = n;
1023
+ return zt(H.hash.outputLen, H.nByteLength, H.hmac)(N, q);
1024
+ }
1025
+ a.BASE._setWindowSize(8);
1026
+ function G(u, g, x, N = z) {
1027
+ var ot;
1028
+ const q = u;
1029
+ if (g = M("msgHash", g), x = M("publicKey", x), "strict" in N)
1030
+ throw new Error("options.strict was renamed to lowS");
1031
+ const { lowS: H, prehash: Z } = N;
1032
+ let U, W;
1033
+ try {
1034
+ if (typeof q == "string" || nt(q))
1035
+ try {
1036
+ U = h.fromDER(q);
1037
+ } catch (K) {
1038
+ if (!(K instanceof tt.Err))
1039
+ throw K;
1040
+ U = h.fromCompact(q);
1041
+ }
1042
+ else if (typeof q == "object" && typeof q.r == "bigint" && typeof q.s == "bigint") {
1043
+ const { r: K, s: it } = q;
1044
+ U = new h(K, it);
1045
+ } else
1046
+ throw new Error("PARSE");
1047
+ W = a.fromHex(x);
1048
+ } catch (K) {
1049
+ if (K.message === "PARSE")
1050
+ throw new Error("signature must be Signature instance, Uint8Array or hex string");
1051
+ return !1;
1052
+ }
1053
+ if (H && U.hasHighS())
1054
+ return !1;
1055
+ Z && (g = n.hash(g));
1056
+ const { r: Y, s: X } = U, at = E(g), D = o(X), gt = c(at * D), Q = c(Y * D), rt = (ot = a.BASE.multiplyAndAddUnsafe(W, gt, Q)) == null ? void 0 : ot.toAffine();
1057
+ return rt ? c(rt.x) === Y : !1;
1058
+ }
1059
+ return {
1060
+ CURVE: n,
1061
+ getPublicKey: B,
1062
+ getSharedSecret: S,
1063
+ sign: C,
1064
+ verify: G,
1065
+ ProjectivePoint: a,
1066
+ Signature: h,
1067
+ utils: b
1068
+ };
1069
+ }
1070
+ class Yt extends Ft {
1071
+ constructor(n, t) {
1072
+ super(), this.finished = !1, this.destroyed = !1, Gt(n);
1073
+ const r = Wt(t);
1074
+ if (this.iHash = n.create(), typeof this.iHash.update != "function")
1075
+ throw new Error("Expected instance of class which extends utils.Hash");
1076
+ this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
1077
+ const s = this.blockLen, i = new Uint8Array(s);
1078
+ i.set(r.length > s ? n.create().update(r).digest() : r);
1079
+ for (let l = 0; l < i.length; l++)
1080
+ i[l] ^= 54;
1081
+ this.iHash.update(i), this.oHash = n.create();
1082
+ for (let l = 0; l < i.length; l++)
1083
+ i[l] ^= 106;
1084
+ this.oHash.update(i), i.fill(0);
1085
+ }
1086
+ update(n) {
1087
+ return qt(this), this.iHash.update(n), this;
1088
+ }
1089
+ digestInto(n) {
1090
+ qt(this), Xt(n, this.outputLen), this.finished = !0, this.iHash.digestInto(n), this.oHash.update(n), this.oHash.digestInto(n), this.destroy();
1091
+ }
1092
+ digest() {
1093
+ const n = new Uint8Array(this.oHash.outputLen);
1094
+ return this.digestInto(n), n;
1095
+ }
1096
+ _cloneInto(n) {
1097
+ n || (n = Object.create(Object.getPrototypeOf(this), {}));
1098
+ const { oHash: t, iHash: r, finished: s, destroyed: i, blockLen: l, outputLen: c } = this;
1099
+ return n = n, n.finished = s, n.destroyed = i, n.blockLen = l, n.outputLen = c, n.oHash = t._cloneInto(n.oHash), n.iHash = r._cloneInto(n.iHash), n;
1100
+ }
1101
+ destroy() {
1102
+ this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
1103
+ }
1104
+ }
1105
+ const Kt = (e, n, t) => new Yt(e, n).update(t).digest();
1106
+ Kt.create = (e, n) => new Yt(e, n);
1107
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1108
+ function qe(e) {
1109
+ return {
1110
+ hash: e,
1111
+ hmac: (n, ...t) => Kt(e, n, Dt(...t)),
1112
+ randomBytes: Qt
1113
+ };
1114
+ }
1115
+ function Ne(e, n) {
1116
+ const t = (r) => Oe({ ...e, ...qe(r) });
1117
+ return Object.freeze({ ...t(n), create: t });
1118
+ }
1119
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1120
+ const Mt = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"), Lt = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"), _e = BigInt(1), bt = BigInt(2), Zt = (e, n) => (e + n / bt) / n;
1121
+ function Te(e) {
1122
+ const n = Mt, t = BigInt(3), r = BigInt(6), s = BigInt(11), i = BigInt(22), l = BigInt(23), c = BigInt(44), o = BigInt(88), a = e * e * e % n, y = a * a * e % n, w = V(y, t, n) * y % n, O = V(w, t, n) * y % n, T = V(O, bt, n) * a % n, m = V(T, s, n) * T % n, f = V(m, i, n) * m % n, d = V(f, c, n) * f % n, h = V(d, o, n) * d % n, b = V(h, c, n) * f % n, B = V(b, t, n) * y % n, I = V(B, l, n) * m % n, S = V(I, r, n) * a % n, p = V(S, bt, n);
1123
+ if (!Et.eql(Et.sqr(p), e))
1124
+ throw new Error("Cannot find square root");
1125
+ return p;
1126
+ }
1127
+ const Et = me(Mt, void 0, void 0, { sqrt: Te }), Pt = Ne({
1128
+ a: BigInt(0),
1129
+ // equation params: a, b
1130
+ b: BigInt(7),
1131
+ // Seem to be rigid: bitcointalk.org/index.php?topic=289795.msg3183975#msg3183975
1132
+ Fp: Et,
1133
+ // Field's prime: 2n**256n - 2n**32n - 2n**9n - 2n**8n - 2n**7n - 2n**6n - 2n**4n - 1n
1134
+ n: Lt,
1135
+ // Curve order, total count of valid points in the field
1136
+ // Base point (x, y) aka generator point
1137
+ Gx: BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),
1138
+ Gy: BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),
1139
+ h: BigInt(1),
1140
+ // Cofactor
1141
+ lowS: !0,
1142
+ // Allow only low-S signatures by default in sign() and verify()
1143
+ /**
1144
+ * secp256k1 belongs to Koblitz curves: it has efficiently computable endomorphism.
1145
+ * Endomorphism uses 2x less RAM, speeds up precomputation by 2x and ECDH / key recovery by 20%.
1146
+ * For precomputed wNAF it trades off 1/2 init time & 1/3 ram for 20% perf hit.
1147
+ * Explanation: https://gist.github.com/paulmillr/eb670806793e84df628a7c434a873066
1148
+ */
1149
+ endo: {
1150
+ beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
1151
+ splitScalar: (e) => {
1152
+ const n = Lt, t = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), r = -_e * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), s = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), i = t, l = BigInt("0x100000000000000000000000000000000"), c = Zt(i * e, n), o = Zt(-r * e, n);
1153
+ let a = R(e - c * t - o * s, n), y = R(-c * r - o * i, n);
1154
+ const w = a > l, O = y > l;
1155
+ if (w && (a = n - a), O && (y = n - y), a > l || y > l)
1156
+ throw new Error("splitScalar: Endomorphism failed, k=" + e);
1157
+ return { k1neg: w, k1: a, k2neg: O, k2: y };
1158
+ }
1159
+ }
1160
+ }, Jt);
1161
+ BigInt(0);
1162
+ Pt.ProjectivePoint;
1163
+ const Le = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1164
+ __proto__: null,
1165
+ secp256k1: Pt
1166
+ }, Symbol.toStringTag, { value: "Module" }));
1167
+ export {
1168
+ Le as a,
1169
+ re as e,
1170
+ Pt as s
1171
+ };
1172
+ //# sourceMappingURL=secp256k1-BLbXMlpX.js.map