@elizaos/plugin-elizacloud 2.0.0-beta.1 → 2.0.11-beta.7

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 (285) hide show
  1. package/README.md +20 -44
  2. package/auto-enable.ts +10 -5
  3. package/dist/browser/index.browser.js +2 -2
  4. package/dist/browser/index.browser.js.map +4 -4
  5. package/dist/cjs/index.node.cjs +2874 -5915
  6. package/dist/cjs/index.node.js.map +47 -116
  7. package/dist/cloud/auth-service-types.d.ts +8 -0
  8. package/dist/cloud/auth-service-types.d.ts.map +1 -0
  9. package/dist/cloud/auth-service-types.js +36 -0
  10. package/dist/cloud/auth-service-types.js.map +10 -0
  11. package/dist/cloud/auth.js +4 -51
  12. package/dist/cloud/auth.js.map +4 -4
  13. package/dist/cloud/base-url.d.ts +6 -2
  14. package/dist/cloud/base-url.d.ts.map +1 -1
  15. package/dist/cloud/base-url.js +3 -51
  16. package/dist/cloud/base-url.js.map +3 -3
  17. package/dist/cloud/bridge-client.d.ts +3 -3
  18. package/dist/cloud/bridge-client.d.ts.map +1 -1
  19. package/dist/cloud/bridge-client.js +3 -51
  20. package/dist/cloud/bridge-client.js.map +3 -3
  21. package/dist/cloud/clack-observer.d.ts +35 -0
  22. package/dist/cloud/clack-observer.d.ts.map +1 -0
  23. package/dist/cloud/clack-observer.js +143 -0
  24. package/dist/cloud/clack-observer.js.map +10 -0
  25. package/dist/cloud/cloud-manager.js +45 -92
  26. package/dist/cloud/cloud-manager.js.map +6 -6
  27. package/dist/cloud/cloud-wallet.js +2 -4835
  28. package/dist/cloud/cloud-wallet.js.map +3 -82
  29. package/dist/cloud/duffel-client.d.ts +181 -0
  30. package/dist/cloud/duffel-client.d.ts.map +1 -0
  31. package/dist/cloud/duffel-client.js +506 -0
  32. package/dist/cloud/duffel-client.js.map +11 -0
  33. package/dist/cloud/index.d.ts +6 -0
  34. package/dist/cloud/index.d.ts.map +1 -1
  35. package/dist/cloud/index.js +1782 -1
  36. package/dist/cloud/index.js.map +18 -3
  37. package/dist/cloud/lifeops-schedule-sync-client.d.ts +43 -0
  38. package/dist/cloud/lifeops-schedule-sync-client.d.ts.map +1 -0
  39. package/dist/cloud/lifeops-schedule-sync-client.js +180 -0
  40. package/dist/cloud/lifeops-schedule-sync-client.js.map +11 -0
  41. package/dist/cloud/lifeops-schedule-sync-contracts.d.ts +89 -0
  42. package/dist/cloud/lifeops-schedule-sync-contracts.d.ts.map +1 -0
  43. package/dist/cloud/lifeops-schedule-sync-contracts.js +39 -0
  44. package/dist/cloud/lifeops-schedule-sync-contracts.js.map +10 -0
  45. package/dist/cloud/managed-payment-clients.d.ts +166 -0
  46. package/dist/cloud/managed-payment-clients.d.ts.map +1 -0
  47. package/dist/cloud/managed-payment-clients.js +238 -0
  48. package/dist/cloud/managed-payment-clients.js.map +11 -0
  49. package/dist/cloud/null-observer.d.ts +35 -0
  50. package/dist/cloud/null-observer.d.ts.map +1 -0
  51. package/dist/cloud/null-observer.js +45 -0
  52. package/dist/cloud/null-observer.js.map +10 -0
  53. package/dist/cloud/setup-observer.d.ts +98 -0
  54. package/dist/cloud/setup-observer.d.ts.map +1 -0
  55. package/dist/cloud/setup-observer.js +2 -0
  56. package/dist/cloud/setup-observer.js.map +9 -0
  57. package/dist/cloud/validate-url.d.ts.map +1 -1
  58. package/dist/cloud/validate-url.js +2 -1
  59. package/dist/cloud/validate-url.js.map +3 -3
  60. package/dist/cloud/x402-payment-handler.d.ts +85 -0
  61. package/dist/cloud/x402-payment-handler.d.ts.map +1 -0
  62. package/dist/cloud/x402-payment-handler.js +119 -0
  63. package/dist/cloud/x402-payment-handler.js.map +10 -0
  64. package/dist/cloud-setup.d.ts +36 -0
  65. package/dist/cloud-setup.d.ts.map +1 -0
  66. package/dist/{onboarding.js → cloud-setup.js} +139 -139
  67. package/dist/cloud-setup.js.map +14 -0
  68. package/dist/cloud-voice-catalog.d.ts +65 -0
  69. package/dist/cloud-voice-catalog.d.ts.map +1 -0
  70. package/dist/cloud-voice-catalog.js +278 -0
  71. package/dist/cloud-voice-catalog.js.map +12 -0
  72. package/dist/index.browser.d.ts +11 -0
  73. package/dist/index.browser.d.ts.map +1 -1
  74. package/dist/index.d.ts +7 -1
  75. package/dist/index.d.ts.map +1 -1
  76. package/dist/index.js +5416 -8405
  77. package/dist/index.js.map +48 -116
  78. package/dist/index.node.d.ts +8 -1
  79. package/dist/index.node.d.ts.map +1 -1
  80. package/dist/init.js +17 -4
  81. package/dist/init.js.map +4 -4
  82. package/dist/lib/cloud-connection.d.ts +0 -1
  83. package/dist/lib/cloud-connection.d.ts.map +1 -1
  84. package/dist/lib/cloud-connection.js +14 -91
  85. package/dist/lib/cloud-connection.js.map +7 -7
  86. package/dist/lib/cloud-secrets.d.ts +5 -18
  87. package/dist/lib/cloud-secrets.d.ts.map +1 -1
  88. package/dist/lib/cloud-secrets.js +8 -36
  89. package/dist/lib/cloud-secrets.js.map +3 -3
  90. package/dist/lib/config-like.d.ts +1 -1
  91. package/dist/lib/config-like.d.ts.map +1 -1
  92. package/dist/lib/config-like.js +3 -3
  93. package/dist/lib/config-like.js.map +3 -3
  94. package/dist/lib/credential-type-map.d.ts +1 -1
  95. package/dist/lib/credential-type-map.js.map +1 -1
  96. package/dist/lib/http.d.ts +0 -11
  97. package/dist/lib/http.d.ts.map +1 -1
  98. package/dist/lib/http.js.map +2 -2
  99. package/dist/lib/server-cloud-tts.d.ts +12 -25
  100. package/dist/lib/server-cloud-tts.d.ts.map +1 -1
  101. package/dist/lib/server-cloud-tts.js +31 -329
  102. package/dist/lib/server-cloud-tts.js.map +4 -7
  103. package/dist/lib/tts-debug.d.ts +5 -3
  104. package/dist/lib/tts-debug.d.ts.map +1 -1
  105. package/dist/lib/tts-debug.js +1 -34
  106. package/dist/lib/tts-debug.js.map +3 -4
  107. package/dist/models/embeddings.d.ts.map +1 -1
  108. package/dist/models/embeddings.js +79 -69
  109. package/dist/models/embeddings.js.map +6 -6
  110. package/dist/models/image.d.ts.map +1 -1
  111. package/dist/models/image.js +42 -15
  112. package/dist/models/image.js.map +6 -6
  113. package/dist/models/index.js +676 -166
  114. package/dist/models/index.js.map +11 -12
  115. package/dist/models/research.d.ts.map +1 -1
  116. package/dist/models/research.js +24 -7
  117. package/dist/models/research.js.map +6 -6
  118. package/dist/models/speech.d.ts +61 -3
  119. package/dist/models/speech.d.ts.map +1 -1
  120. package/dist/models/speech.js +173 -17
  121. package/dist/models/speech.js.map +5 -5
  122. package/dist/models/text.d.ts +106 -1
  123. package/dist/models/text.d.ts.map +1 -1
  124. package/dist/models/text.js +452 -82
  125. package/dist/models/text.js.map +7 -8
  126. package/dist/models/tokenization.d.ts.map +1 -1
  127. package/dist/models/tokenization.js.map +2 -2
  128. package/dist/models/transcription.d.ts.map +1 -1
  129. package/dist/models/transcription.js +20 -6
  130. package/dist/models/transcription.js.map +5 -5
  131. package/dist/node/index.node.js +2828 -5838
  132. package/dist/node/index.node.js.map +47 -116
  133. package/dist/plugin.d.ts.map +1 -1
  134. package/dist/plugin.js +376 -5050
  135. package/dist/plugin.js.map +16 -92
  136. package/dist/providers/openai.js +11 -2
  137. package/dist/providers/openai.js.map +3 -3
  138. package/dist/register-routes.js +376 -5050
  139. package/dist/register-routes.js.map +16 -92
  140. package/dist/routes/cloud-billing-routes.d.ts.map +1 -1
  141. package/dist/routes/cloud-billing-routes.js +17 -60
  142. package/dist/routes/cloud-billing-routes.js.map +8 -7
  143. package/dist/routes/cloud-coding-container-routes.d.ts +8 -0
  144. package/dist/routes/cloud-coding-container-routes.d.ts.map +1 -0
  145. package/dist/routes/cloud-coding-container-routes.js +214 -0
  146. package/dist/routes/cloud-coding-container-routes.js.map +11 -0
  147. package/dist/routes/cloud-compat-routes.d.ts.map +1 -1
  148. package/dist/routes/cloud-compat-routes.js +17 -60
  149. package/dist/routes/cloud-compat-routes.js.map +8 -7
  150. package/dist/routes/cloud-features-routes.js +2 -2
  151. package/dist/routes/cloud-features-routes.js.map +4 -4
  152. package/dist/routes/cloud-relay-routes.d.ts +2 -1
  153. package/dist/routes/cloud-relay-routes.d.ts.map +1 -1
  154. package/dist/routes/cloud-relay-routes.js +84 -2
  155. package/dist/routes/cloud-relay-routes.js.map +5 -4
  156. package/dist/routes/cloud-routes-autonomous.d.ts +3 -4
  157. package/dist/routes/cloud-routes-autonomous.d.ts.map +1 -1
  158. package/dist/routes/cloud-routes-autonomous.js +11 -4893
  159. package/dist/routes/cloud-routes-autonomous.js.map +8 -87
  160. package/dist/routes/cloud-routes.d.ts +2 -2
  161. package/dist/routes/cloud-routes.d.ts.map +1 -1
  162. package/dist/routes/cloud-routes.js +343 -5058
  163. package/dist/routes/cloud-routes.js.map +13 -90
  164. package/dist/routes/cloud-status-routes-autonomous.d.ts +1 -2
  165. package/dist/routes/cloud-status-routes-autonomous.d.ts.map +1 -1
  166. package/dist/routes/cloud-status-routes-autonomous.js +4 -51
  167. package/dist/routes/cloud-status-routes-autonomous.js.map +5 -5
  168. package/dist/routes/cloud-status-routes.js +14 -90
  169. package/dist/routes/cloud-status-routes.js.map +7 -7
  170. package/dist/routes/home-remote-runner-access-url.d.ts +16 -0
  171. package/dist/routes/home-remote-runner-access-url.d.ts.map +1 -0
  172. package/dist/routes/home-remote-runner-access-url.js +91 -0
  173. package/dist/routes/home-remote-runner-access-url.js.map +10 -0
  174. package/dist/routes/travel-provider-relay-routes.d.ts +9 -0
  175. package/dist/routes/travel-provider-relay-routes.d.ts.map +1 -0
  176. package/dist/routes/travel-provider-relay-routes.js +358 -0
  177. package/dist/routes/travel-provider-relay-routes.js.map +14 -0
  178. package/dist/services/cloud-auth.d.ts +1 -1
  179. package/dist/services/cloud-auth.d.ts.map +1 -1
  180. package/dist/services/cloud-auth.js +7 -2
  181. package/dist/services/cloud-auth.js.map +4 -4
  182. package/dist/services/cloud-backup.js.map +2 -2
  183. package/dist/services/cloud-bootstrap.d.ts.map +1 -1
  184. package/dist/services/cloud-bootstrap.js.map +2 -2
  185. package/dist/services/cloud-bridge.js.map +3 -3
  186. package/dist/services/cloud-container.d.ts +5 -1
  187. package/dist/services/cloud-container.d.ts.map +1 -1
  188. package/dist/services/cloud-container.js +52 -1
  189. package/dist/services/cloud-container.js.map +4 -4
  190. package/dist/services/cloud-credential-provider.js.map +2 -2
  191. package/dist/services/cloud-model-registry.js.map +2 -2
  192. package/dist/types/cloud.d.ts +1 -0
  193. package/dist/types/cloud.d.ts.map +1 -1
  194. package/dist/types/cloud.js.map +2 -2
  195. package/dist/types/index.d.ts +1 -1
  196. package/dist/types/index.d.ts.map +1 -1
  197. package/dist/utils/cloud-sdk/client.d.ts.map +1 -1
  198. package/dist/utils/cloud-sdk/client.js +136 -4
  199. package/dist/utils/cloud-sdk/client.js.map +5 -5
  200. package/dist/utils/cloud-sdk/http.js.map +1 -1
  201. package/dist/utils/cloud-sdk/public-routes.d.ts +186 -0
  202. package/dist/utils/cloud-sdk/public-routes.d.ts.map +1 -1
  203. package/dist/utils/cloud-sdk/public-routes.js +99 -1
  204. package/dist/utils/cloud-sdk/public-routes.js.map +3 -3
  205. package/dist/utils/cloud-sdk/types.d.ts +0 -2
  206. package/dist/utils/cloud-sdk/types.d.ts.map +1 -1
  207. package/dist/utils/cloud-sdk/types.js.map +1 -1
  208. package/dist/utils/config.d.ts +10 -1
  209. package/dist/utils/config.d.ts.map +1 -1
  210. package/dist/utils/config.js +12 -2
  211. package/dist/utils/config.js.map +3 -3
  212. package/dist/utils/events.d.ts +23 -2
  213. package/dist/utils/events.d.ts.map +1 -1
  214. package/dist/utils/events.js +5 -3
  215. package/dist/utils/events.js.map +3 -3
  216. package/dist/utils/sdk-client.d.ts.map +1 -1
  217. package/dist/utils/sdk-client.js +17 -4
  218. package/dist/utils/sdk-client.js.map +4 -4
  219. package/dist/utils/waifu-metering.d.ts +108 -0
  220. package/dist/utils/waifu-metering.d.ts.map +1 -0
  221. package/dist/utils/waifu-metering.js +166 -0
  222. package/dist/utils/waifu-metering.js.map +10 -0
  223. package/package.json +51 -22
  224. package/src/cloud/auth-service-types.ts +24 -0
  225. package/src/cloud/base-url.ts +6 -62
  226. package/src/cloud/clack-observer.ts +189 -0
  227. package/src/cloud/duffel-client.ts +847 -0
  228. package/src/cloud/index.ts +10 -0
  229. package/src/cloud/lifeops-schedule-sync-client.ts +245 -0
  230. package/src/cloud/lifeops-schedule-sync-contracts.ts +124 -0
  231. package/src/cloud/managed-payment-clients.ts +374 -0
  232. package/src/cloud/null-observer.ts +45 -0
  233. package/src/cloud/setup-observer.ts +125 -0
  234. package/src/cloud/validate-url.ts +7 -1
  235. package/src/cloud/x402-payment-handler.ts +215 -0
  236. package/src/cloud-setup.ts +531 -0
  237. package/src/cloud-voice-catalog.test.ts +254 -0
  238. package/src/cloud-voice-catalog.ts +246 -0
  239. package/src/index.browser.ts +29 -0
  240. package/src/index.node.ts +31 -1
  241. package/src/index.ts +76 -4
  242. package/src/lib/cloud-connection.ts +2 -4
  243. package/src/lib/cloud-secrets.ts +10 -54
  244. package/src/lib/config-like.ts +1 -1
  245. package/src/lib/credential-type-map.ts +2 -2
  246. package/src/lib/http.ts +0 -17
  247. package/src/lib/server-cloud-tts.ts +33 -341
  248. package/src/lib/tts-debug.ts +5 -34
  249. package/src/models/embeddings.ts +140 -76
  250. package/src/models/image.ts +29 -14
  251. package/src/models/research.ts +11 -1
  252. package/src/models/speech.ts +269 -23
  253. package/src/models/text.ts +704 -110
  254. package/src/models/tokenization.ts +2 -2
  255. package/src/models/transcription.ts +7 -3
  256. package/src/plugin.ts +38 -0
  257. package/src/routes/cloud-billing-routes.ts +4 -14
  258. package/src/routes/cloud-coding-container-routes.ts +198 -0
  259. package/src/routes/cloud-compat-routes.ts +4 -14
  260. package/src/routes/cloud-features-routes.ts +1 -1
  261. package/src/routes/cloud-relay-routes.ts +47 -1
  262. package/src/routes/cloud-routes-autonomous.ts +7 -10
  263. package/src/routes/cloud-routes.ts +68 -7
  264. package/src/routes/cloud-status-routes-autonomous.ts +6 -2
  265. package/src/routes/home-remote-runner-access-url.ts +83 -0
  266. package/src/routes/travel-provider-relay-routes.ts +193 -0
  267. package/src/services/cloud-auth.ts +9 -2
  268. package/src/services/cloud-bootstrap.ts +1 -3
  269. package/src/services/cloud-bridge.ts +1 -1
  270. package/src/services/cloud-container.ts +93 -0
  271. package/src/services/cloud-credential-provider.ts +1 -1
  272. package/src/services/cloud-model-registry.ts +1 -1
  273. package/src/types/cloud.ts +22 -0
  274. package/src/types/index.ts +19 -0
  275. package/src/utils/cloud-sdk/client.ts +42 -3
  276. package/src/utils/cloud-sdk/public-routes.ts +168 -0
  277. package/src/utils/cloud-sdk/types.ts +0 -2
  278. package/src/utils/config.ts +20 -1
  279. package/src/utils/events.ts +30 -2
  280. package/src/utils/sdk-client.ts +5 -1
  281. package/src/utils/waifu-metering.ts +302 -0
  282. package/dist/onboarding.d.ts +0 -35
  283. package/dist/onboarding.d.ts.map +0 -1
  284. package/dist/onboarding.js.map +0 -14
  285. package/src/onboarding.ts +0 -396
@@ -201,4840 +201,8 @@ function isCloudWalletEnabled() {
201
201
  return readBoolFlag("ENABLE_CLOUD_WALLET");
202
202
  }
203
203
 
204
- // ../../node_modules/.bun/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/cryptoNode.js
205
- import * as nc from "node:crypto";
206
- var crypto;
207
- var init_cryptoNode = __esm(() => {
208
- crypto = nc && typeof nc === "object" && "webcrypto" in nc ? nc.webcrypto : nc && typeof nc === "object" && ("randomBytes" in nc) ? nc : undefined;
209
- });
210
-
211
- // ../../node_modules/.bun/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/utils.js
212
- function isBytes(a) {
213
- return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
214
- }
215
- function anumber(n) {
216
- if (!Number.isSafeInteger(n) || n < 0)
217
- throw new Error("positive integer expected, got " + n);
218
- }
219
- function abytes(b, ...lengths) {
220
- if (!isBytes(b))
221
- throw new Error("Uint8Array expected");
222
- if (lengths.length > 0 && !lengths.includes(b.length))
223
- throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
224
- }
225
- function ahash(h) {
226
- if (typeof h !== "function" || typeof h.create !== "function")
227
- throw new Error("Hash should be wrapped by utils.createHasher");
228
- anumber(h.outputLen);
229
- anumber(h.blockLen);
230
- }
231
- function aexists(instance, checkFinished = true) {
232
- if (instance.destroyed)
233
- throw new Error("Hash instance has been destroyed");
234
- if (checkFinished && instance.finished)
235
- throw new Error("Hash#digest() has already been called");
236
- }
237
- function aoutput(out, instance) {
238
- abytes(out);
239
- const min = instance.outputLen;
240
- if (out.length < min) {
241
- throw new Error("digestInto() expects output buffer of length at least " + min);
242
- }
243
- }
244
- function u32(arr) {
245
- return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
246
- }
247
- function clean(...arrays) {
248
- for (let i = 0;i < arrays.length; i++) {
249
- arrays[i].fill(0);
250
- }
251
- }
252
- function createView(arr) {
253
- return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
254
- }
255
- function rotr(word, shift) {
256
- return word << 32 - shift | word >>> shift;
257
- }
258
- function byteSwap(word) {
259
- return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
260
- }
261
- function byteSwap32(arr) {
262
- for (let i = 0;i < arr.length; i++) {
263
- arr[i] = byteSwap(arr[i]);
264
- }
265
- return arr;
266
- }
267
- function utf8ToBytes(str) {
268
- if (typeof str !== "string")
269
- throw new Error("string expected");
270
- return new Uint8Array(new TextEncoder().encode(str));
271
- }
272
- function toBytes(data) {
273
- if (typeof data === "string")
274
- data = utf8ToBytes(data);
275
- abytes(data);
276
- return data;
277
- }
278
- function concatBytes(...arrays) {
279
- let sum = 0;
280
- for (let i = 0;i < arrays.length; i++) {
281
- const a = arrays[i];
282
- abytes(a);
283
- sum += a.length;
284
- }
285
- const res = new Uint8Array(sum);
286
- for (let i = 0, pad = 0;i < arrays.length; i++) {
287
- const a = arrays[i];
288
- res.set(a, pad);
289
- pad += a.length;
290
- }
291
- return res;
292
- }
293
-
294
- class Hash {
295
- }
296
- function createHasher(hashCons) {
297
- const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
298
- const tmp = hashCons();
299
- hashC.outputLen = tmp.outputLen;
300
- hashC.blockLen = tmp.blockLen;
301
- hashC.create = () => hashCons();
302
- return hashC;
303
- }
304
- function randomBytes(bytesLength = 32) {
305
- if (crypto && typeof crypto.getRandomValues === "function") {
306
- return crypto.getRandomValues(new Uint8Array(bytesLength));
307
- }
308
- if (crypto && typeof crypto.randomBytes === "function") {
309
- return Uint8Array.from(crypto.randomBytes(bytesLength));
310
- }
311
- throw new Error("crypto.getRandomValues must be defined");
312
- }
313
- var isLE, swap32IfBE;
314
- var init_utils = __esm(() => {
315
- init_cryptoNode();
316
- /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
317
- isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
318
- swap32IfBE = isLE ? (u) => u : byteSwap32;
319
- });
320
-
321
- // ../../node_modules/.bun/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_md.js
322
- function setBigUint64(view, byteOffset, value, isLE2) {
323
- if (typeof view.setBigUint64 === "function")
324
- return view.setBigUint64(byteOffset, value, isLE2);
325
- const _32n = BigInt(32);
326
- const _u32_max = BigInt(4294967295);
327
- const wh = Number(value >> _32n & _u32_max);
328
- const wl = Number(value & _u32_max);
329
- const h = isLE2 ? 4 : 0;
330
- const l = isLE2 ? 0 : 4;
331
- view.setUint32(byteOffset + h, wh, isLE2);
332
- view.setUint32(byteOffset + l, wl, isLE2);
333
- }
334
- function Chi(a, b, c) {
335
- return a & b ^ ~a & c;
336
- }
337
- function Maj(a, b, c) {
338
- return a & b ^ a & c ^ b & c;
339
- }
340
- var HashMD, SHA256_IV;
341
- var init__md = __esm(() => {
342
- init_utils();
343
- HashMD = class HashMD extends Hash {
344
- constructor(blockLen, outputLen, padOffset, isLE2) {
345
- super();
346
- this.finished = false;
347
- this.length = 0;
348
- this.pos = 0;
349
- this.destroyed = false;
350
- this.blockLen = blockLen;
351
- this.outputLen = outputLen;
352
- this.padOffset = padOffset;
353
- this.isLE = isLE2;
354
- this.buffer = new Uint8Array(blockLen);
355
- this.view = createView(this.buffer);
356
- }
357
- update(data) {
358
- aexists(this);
359
- data = toBytes(data);
360
- abytes(data);
361
- const { view, buffer, blockLen } = this;
362
- const len = data.length;
363
- for (let pos = 0;pos < len; ) {
364
- const take = Math.min(blockLen - this.pos, len - pos);
365
- if (take === blockLen) {
366
- const dataView = createView(data);
367
- for (;blockLen <= len - pos; pos += blockLen)
368
- this.process(dataView, pos);
369
- continue;
370
- }
371
- buffer.set(data.subarray(pos, pos + take), this.pos);
372
- this.pos += take;
373
- pos += take;
374
- if (this.pos === blockLen) {
375
- this.process(view, 0);
376
- this.pos = 0;
377
- }
378
- }
379
- this.length += data.length;
380
- this.roundClean();
381
- return this;
382
- }
383
- digestInto(out) {
384
- aexists(this);
385
- aoutput(out, this);
386
- this.finished = true;
387
- const { buffer, view, blockLen, isLE: isLE2 } = this;
388
- let { pos } = this;
389
- buffer[pos++] = 128;
390
- clean(this.buffer.subarray(pos));
391
- if (this.padOffset > blockLen - pos) {
392
- this.process(view, 0);
393
- pos = 0;
394
- }
395
- for (let i = pos;i < blockLen; i++)
396
- buffer[i] = 0;
397
- setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE2);
398
- this.process(view, 0);
399
- const oview = createView(out);
400
- const len = this.outputLen;
401
- if (len % 4)
402
- throw new Error("_sha2: outputLen should be aligned to 32bit");
403
- const outLen = len / 4;
404
- const state = this.get();
405
- if (outLen > state.length)
406
- throw new Error("_sha2: outputLen bigger than state");
407
- for (let i = 0;i < outLen; i++)
408
- oview.setUint32(4 * i, state[i], isLE2);
409
- }
410
- digest() {
411
- const { buffer, outputLen } = this;
412
- this.digestInto(buffer);
413
- const res = buffer.slice(0, outputLen);
414
- this.destroy();
415
- return res;
416
- }
417
- _cloneInto(to) {
418
- to || (to = new this.constructor);
419
- to.set(...this.get());
420
- const { blockLen, buffer, length, finished, destroyed, pos } = this;
421
- to.destroyed = destroyed;
422
- to.finished = finished;
423
- to.length = length;
424
- to.pos = pos;
425
- if (length % blockLen)
426
- to.buffer.set(buffer);
427
- return to;
428
- }
429
- clone() {
430
- return this._cloneInto();
431
- }
432
- };
433
- SHA256_IV = /* @__PURE__ */ Uint32Array.from([
434
- 1779033703,
435
- 3144134277,
436
- 1013904242,
437
- 2773480762,
438
- 1359893119,
439
- 2600822924,
440
- 528734635,
441
- 1541459225
442
- ]);
443
- });
444
-
445
- // ../../node_modules/.bun/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_u64.js
446
- function fromBig(n, le = false) {
447
- if (le)
448
- return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
449
- return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
450
- }
451
- function split(lst, le = false) {
452
- const len = lst.length;
453
- let Ah = new Uint32Array(len);
454
- let Al = new Uint32Array(len);
455
- for (let i = 0;i < len; i++) {
456
- const { h, l } = fromBig(lst[i], le);
457
- [Ah[i], Al[i]] = [h, l];
458
- }
459
- return [Ah, Al];
460
- }
461
- var U32_MASK64, _32n, rotlSH = (h, l, s) => h << s | l >>> 32 - s, rotlSL = (h, l, s) => l << s | h >>> 32 - s, rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s, rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
462
- var init__u64 = __esm(() => {
463
- U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
464
- _32n = /* @__PURE__ */ BigInt(32);
465
- });
466
-
467
- // ../../node_modules/.bun/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/sha2.js
468
- var SHA256_K, SHA256_W, SHA256, sha256;
469
- var init_sha2 = __esm(() => {
470
- init__md();
471
- init_utils();
472
- SHA256_K = /* @__PURE__ */ Uint32Array.from([
473
- 1116352408,
474
- 1899447441,
475
- 3049323471,
476
- 3921009573,
477
- 961987163,
478
- 1508970993,
479
- 2453635748,
480
- 2870763221,
481
- 3624381080,
482
- 310598401,
483
- 607225278,
484
- 1426881987,
485
- 1925078388,
486
- 2162078206,
487
- 2614888103,
488
- 3248222580,
489
- 3835390401,
490
- 4022224774,
491
- 264347078,
492
- 604807628,
493
- 770255983,
494
- 1249150122,
495
- 1555081692,
496
- 1996064986,
497
- 2554220882,
498
- 2821834349,
499
- 2952996808,
500
- 3210313671,
501
- 3336571891,
502
- 3584528711,
503
- 113926993,
504
- 338241895,
505
- 666307205,
506
- 773529912,
507
- 1294757372,
508
- 1396182291,
509
- 1695183700,
510
- 1986661051,
511
- 2177026350,
512
- 2456956037,
513
- 2730485921,
514
- 2820302411,
515
- 3259730800,
516
- 3345764771,
517
- 3516065817,
518
- 3600352804,
519
- 4094571909,
520
- 275423344,
521
- 430227734,
522
- 506948616,
523
- 659060556,
524
- 883997877,
525
- 958139571,
526
- 1322822218,
527
- 1537002063,
528
- 1747873779,
529
- 1955562222,
530
- 2024104815,
531
- 2227730452,
532
- 2361852424,
533
- 2428436474,
534
- 2756734187,
535
- 3204031479,
536
- 3329325298
537
- ]);
538
- SHA256_W = /* @__PURE__ */ new Uint32Array(64);
539
- SHA256 = class SHA256 extends HashMD {
540
- constructor(outputLen = 32) {
541
- super(64, outputLen, 8, false);
542
- this.A = SHA256_IV[0] | 0;
543
- this.B = SHA256_IV[1] | 0;
544
- this.C = SHA256_IV[2] | 0;
545
- this.D = SHA256_IV[3] | 0;
546
- this.E = SHA256_IV[4] | 0;
547
- this.F = SHA256_IV[5] | 0;
548
- this.G = SHA256_IV[6] | 0;
549
- this.H = SHA256_IV[7] | 0;
550
- }
551
- get() {
552
- const { A, B, C, D, E, F, G, H } = this;
553
- return [A, B, C, D, E, F, G, H];
554
- }
555
- set(A, B, C, D, E, F, G, H) {
556
- this.A = A | 0;
557
- this.B = B | 0;
558
- this.C = C | 0;
559
- this.D = D | 0;
560
- this.E = E | 0;
561
- this.F = F | 0;
562
- this.G = G | 0;
563
- this.H = H | 0;
564
- }
565
- process(view, offset) {
566
- for (let i = 0;i < 16; i++, offset += 4)
567
- SHA256_W[i] = view.getUint32(offset, false);
568
- for (let i = 16;i < 64; i++) {
569
- const W15 = SHA256_W[i - 15];
570
- const W2 = SHA256_W[i - 2];
571
- const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
572
- const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
573
- SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
574
- }
575
- let { A, B, C, D, E, F, G, H } = this;
576
- for (let i = 0;i < 64; i++) {
577
- const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
578
- const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
579
- const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
580
- const T2 = sigma0 + Maj(A, B, C) | 0;
581
- H = G;
582
- G = F;
583
- F = E;
584
- E = D + T1 | 0;
585
- D = C;
586
- C = B;
587
- B = A;
588
- A = T1 + T2 | 0;
589
- }
590
- A = A + this.A | 0;
591
- B = B + this.B | 0;
592
- C = C + this.C | 0;
593
- D = D + this.D | 0;
594
- E = E + this.E | 0;
595
- F = F + this.F | 0;
596
- G = G + this.G | 0;
597
- H = H + this.H | 0;
598
- this.set(A, B, C, D, E, F, G, H);
599
- }
600
- roundClean() {
601
- clean(SHA256_W);
602
- }
603
- destroy() {
604
- this.set(0, 0, 0, 0, 0, 0, 0, 0);
605
- clean(this.buffer);
606
- }
607
- };
608
- sha256 = /* @__PURE__ */ createHasher(() => new SHA256);
609
- });
610
-
611
- // ../../node_modules/.bun/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/hmac.js
612
- var HMAC, hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest();
613
- var init_hmac = __esm(() => {
614
- init_utils();
615
- HMAC = class HMAC extends Hash {
616
- constructor(hash, _key) {
617
- super();
618
- this.finished = false;
619
- this.destroyed = false;
620
- ahash(hash);
621
- const key = toBytes(_key);
622
- this.iHash = hash.create();
623
- if (typeof this.iHash.update !== "function")
624
- throw new Error("Expected instance of class which extends utils.Hash");
625
- this.blockLen = this.iHash.blockLen;
626
- this.outputLen = this.iHash.outputLen;
627
- const blockLen = this.blockLen;
628
- const pad = new Uint8Array(blockLen);
629
- pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
630
- for (let i = 0;i < pad.length; i++)
631
- pad[i] ^= 54;
632
- this.iHash.update(pad);
633
- this.oHash = hash.create();
634
- for (let i = 0;i < pad.length; i++)
635
- pad[i] ^= 54 ^ 92;
636
- this.oHash.update(pad);
637
- clean(pad);
638
- }
639
- update(buf) {
640
- aexists(this);
641
- this.iHash.update(buf);
642
- return this;
643
- }
644
- digestInto(out) {
645
- aexists(this);
646
- abytes(out, this.outputLen);
647
- this.finished = true;
648
- this.iHash.digestInto(out);
649
- this.oHash.update(out);
650
- this.oHash.digestInto(out);
651
- this.destroy();
652
- }
653
- digest() {
654
- const out = new Uint8Array(this.oHash.outputLen);
655
- this.digestInto(out);
656
- return out;
657
- }
658
- _cloneInto(to) {
659
- to || (to = Object.create(Object.getPrototypeOf(this), {}));
660
- const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
661
- to = to;
662
- to.finished = finished;
663
- to.destroyed = destroyed;
664
- to.blockLen = blockLen;
665
- to.outputLen = outputLen;
666
- to.oHash = oHash._cloneInto(to.oHash);
667
- to.iHash = iHash._cloneInto(to.iHash);
668
- return to;
669
- }
670
- clone() {
671
- return this._cloneInto();
672
- }
673
- destroy() {
674
- this.destroyed = true;
675
- this.oHash.destroy();
676
- this.iHash.destroy();
677
- }
678
- };
679
- hmac.create = (hash, key) => new HMAC(hash, key);
680
- });
681
-
682
- // ../../node_modules/.bun/@noble+curves@1.9.1/node_modules/@noble/curves/esm/abstract/utils.js
683
- function isBytes2(a) {
684
- return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
685
- }
686
- function abytes2(item) {
687
- if (!isBytes2(item))
688
- throw new Error("Uint8Array expected");
689
- }
690
- function abool(title, value) {
691
- if (typeof value !== "boolean")
692
- throw new Error(title + " boolean expected, got " + value);
693
- }
694
- function numberToHexUnpadded(num) {
695
- const hex = num.toString(16);
696
- return hex.length & 1 ? "0" + hex : hex;
697
- }
698
- function hexToNumber(hex) {
699
- if (typeof hex !== "string")
700
- throw new Error("hex string expected, got " + typeof hex);
701
- return hex === "" ? _0n : BigInt("0x" + hex);
702
- }
703
- function bytesToHex(bytes) {
704
- abytes2(bytes);
705
- if (hasHexBuiltin)
706
- return bytes.toHex();
707
- let hex = "";
708
- for (let i = 0;i < bytes.length; i++) {
709
- hex += hexes[bytes[i]];
710
- }
711
- return hex;
712
- }
713
- function asciiToBase16(ch) {
714
- if (ch >= asciis._0 && ch <= asciis._9)
715
- return ch - asciis._0;
716
- if (ch >= asciis.A && ch <= asciis.F)
717
- return ch - (asciis.A - 10);
718
- if (ch >= asciis.a && ch <= asciis.f)
719
- return ch - (asciis.a - 10);
720
- return;
721
- }
722
- function hexToBytes(hex) {
723
- if (typeof hex !== "string")
724
- throw new Error("hex string expected, got " + typeof hex);
725
- if (hasHexBuiltin)
726
- return Uint8Array.fromHex(hex);
727
- const hl = hex.length;
728
- const al = hl / 2;
729
- if (hl % 2)
730
- throw new Error("hex string expected, got unpadded hex of length " + hl);
731
- const array = new Uint8Array(al);
732
- for (let ai = 0, hi = 0;ai < al; ai++, hi += 2) {
733
- const n1 = asciiToBase16(hex.charCodeAt(hi));
734
- const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
735
- if (n1 === undefined || n2 === undefined) {
736
- const char = hex[hi] + hex[hi + 1];
737
- throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
738
- }
739
- array[ai] = n1 * 16 + n2;
740
- }
741
- return array;
742
- }
743
- function bytesToNumberBE(bytes) {
744
- return hexToNumber(bytesToHex(bytes));
745
- }
746
- function bytesToNumberLE(bytes) {
747
- abytes2(bytes);
748
- return hexToNumber(bytesToHex(Uint8Array.from(bytes).reverse()));
749
- }
750
- function numberToBytesBE(n, len) {
751
- return hexToBytes(n.toString(16).padStart(len * 2, "0"));
752
- }
753
- function numberToBytesLE(n, len) {
754
- return numberToBytesBE(n, len).reverse();
755
- }
756
- function ensureBytes(title, hex, expectedLength) {
757
- let res;
758
- if (typeof hex === "string") {
759
- try {
760
- res = hexToBytes(hex);
761
- } catch (e) {
762
- throw new Error(title + " must be hex string or Uint8Array, cause: " + e);
763
- }
764
- } else if (isBytes2(hex)) {
765
- res = Uint8Array.from(hex);
766
- } else {
767
- throw new Error(title + " must be hex string or Uint8Array");
768
- }
769
- const len = res.length;
770
- if (typeof expectedLength === "number" && len !== expectedLength)
771
- throw new Error(title + " of length " + expectedLength + " expected, got " + len);
772
- return res;
773
- }
774
- function concatBytes2(...arrays) {
775
- let sum = 0;
776
- for (let i = 0;i < arrays.length; i++) {
777
- const a = arrays[i];
778
- abytes2(a);
779
- sum += a.length;
780
- }
781
- const res = new Uint8Array(sum);
782
- for (let i = 0, pad = 0;i < arrays.length; i++) {
783
- const a = arrays[i];
784
- res.set(a, pad);
785
- pad += a.length;
786
- }
787
- return res;
788
- }
789
- function inRange(n, min, max) {
790
- return isPosBig(n) && isPosBig(min) && isPosBig(max) && min <= n && n < max;
791
- }
792
- function aInRange(title, n, min, max) {
793
- if (!inRange(n, min, max))
794
- throw new Error("expected valid " + title + ": " + min + " <= n < " + max + ", got " + n);
795
- }
796
- function bitLen(n) {
797
- let len;
798
- for (len = 0;n > _0n; n >>= _1n, len += 1)
799
- ;
800
- return len;
801
- }
802
- function createHmacDrbg(hashLen, qByteLen, hmacFn) {
803
- if (typeof hashLen !== "number" || hashLen < 2)
804
- throw new Error("hashLen must be a number");
805
- if (typeof qByteLen !== "number" || qByteLen < 2)
806
- throw new Error("qByteLen must be a number");
807
- if (typeof hmacFn !== "function")
808
- throw new Error("hmacFn must be a function");
809
- let v = u8n(hashLen);
810
- let k = u8n(hashLen);
811
- let i = 0;
812
- const reset = () => {
813
- v.fill(1);
814
- k.fill(0);
815
- i = 0;
816
- };
817
- const h = (...b) => hmacFn(k, v, ...b);
818
- const reseed = (seed = u8n(0)) => {
819
- k = h(u8fr([0]), seed);
820
- v = h();
821
- if (seed.length === 0)
822
- return;
823
- k = h(u8fr([1]), seed);
824
- v = h();
825
- };
826
- const gen = () => {
827
- if (i++ >= 1000)
828
- throw new Error("drbg: tried 1000 values");
829
- let len = 0;
830
- const out = [];
831
- while (len < qByteLen) {
832
- v = h();
833
- const sl = v.slice();
834
- out.push(sl);
835
- len += v.length;
836
- }
837
- return concatBytes2(...out);
838
- };
839
- const genUntil = (seed, pred) => {
840
- reset();
841
- reseed(seed);
842
- let res = undefined;
843
- while (!(res = pred(gen())))
844
- reseed();
845
- reset();
846
- return res;
847
- };
848
- return genUntil;
849
- }
850
- function validateObject(object, validators, optValidators = {}) {
851
- const checkField = (fieldName, type, isOptional) => {
852
- const checkVal = validatorFns[type];
853
- if (typeof checkVal !== "function")
854
- throw new Error("invalid validator function");
855
- const val = object[fieldName];
856
- if (isOptional && val === undefined)
857
- return;
858
- if (!checkVal(val, object)) {
859
- throw new Error("param " + String(fieldName) + " is invalid. Expected " + type + ", got " + val);
860
- }
861
- };
862
- for (const [fieldName, type] of Object.entries(validators))
863
- checkField(fieldName, type, false);
864
- for (const [fieldName, type] of Object.entries(optValidators))
865
- checkField(fieldName, type, true);
866
- return object;
867
- }
868
- function memoized(fn) {
869
- const map = new WeakMap;
870
- return (arg, ...args) => {
871
- const val = map.get(arg);
872
- if (val !== undefined)
873
- return val;
874
- const computed = fn(arg, ...args);
875
- map.set(arg, computed);
876
- return computed;
877
- };
878
- }
879
- var _0n, _1n, hasHexBuiltin, hexes, asciis, isPosBig = (n) => typeof n === "bigint" && _0n <= n, bitMask = (n) => (_1n << BigInt(n)) - _1n, u8n = (len) => new Uint8Array(len), u8fr = (arr) => Uint8Array.from(arr), validatorFns;
880
- var init_utils2 = __esm(() => {
881
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
882
- _0n = /* @__PURE__ */ BigInt(0);
883
- _1n = /* @__PURE__ */ BigInt(1);
884
- hasHexBuiltin = typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function";
885
- hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
886
- asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
887
- validatorFns = {
888
- bigint: (val) => typeof val === "bigint",
889
- function: (val) => typeof val === "function",
890
- boolean: (val) => typeof val === "boolean",
891
- string: (val) => typeof val === "string",
892
- stringOrUint8Array: (val) => typeof val === "string" || isBytes2(val),
893
- isSafeInteger: (val) => Number.isSafeInteger(val),
894
- array: (val) => Array.isArray(val),
895
- field: (val, object) => object.Fp.isValid(val),
896
- hash: (val) => typeof val === "function" && Number.isSafeInteger(val.outputLen)
897
- };
898
- });
899
-
900
- // ../../node_modules/.bun/@noble+curves@1.9.1/node_modules/@noble/curves/esm/abstract/modular.js
901
- function mod(a, b) {
902
- const result = a % b;
903
- return result >= _0n2 ? result : b + result;
904
- }
905
- function pow2(x, power, modulo) {
906
- let res = x;
907
- while (power-- > _0n2) {
908
- res *= res;
909
- res %= modulo;
910
- }
911
- return res;
912
- }
913
- function invert(number, modulo) {
914
- if (number === _0n2)
915
- throw new Error("invert: expected non-zero number");
916
- if (modulo <= _0n2)
917
- throw new Error("invert: expected positive modulus, got " + modulo);
918
- let a = mod(number, modulo);
919
- let b = modulo;
920
- let x = _0n2, y = _1n2, u = _1n2, v = _0n2;
921
- while (a !== _0n2) {
922
- const q = b / a;
923
- const r = b % a;
924
- const m = x - u * q;
925
- const n = y - v * q;
926
- b = a, a = r, x = u, y = v, u = m, v = n;
927
- }
928
- const gcd = b;
929
- if (gcd !== _1n2)
930
- throw new Error("invert: does not exist");
931
- return mod(x, modulo);
932
- }
933
- function sqrt3mod4(Fp, n) {
934
- const p1div4 = (Fp.ORDER + _1n2) / _4n;
935
- const root = Fp.pow(n, p1div4);
936
- if (!Fp.eql(Fp.sqr(root), n))
937
- throw new Error("Cannot find square root");
938
- return root;
939
- }
940
- function sqrt5mod8(Fp, n) {
941
- const p5div8 = (Fp.ORDER - _5n) / _8n;
942
- const n2 = Fp.mul(n, _2n);
943
- const v = Fp.pow(n2, p5div8);
944
- const nv = Fp.mul(n, v);
945
- const i = Fp.mul(Fp.mul(nv, _2n), v);
946
- const root = Fp.mul(nv, Fp.sub(i, Fp.ONE));
947
- if (!Fp.eql(Fp.sqr(root), n))
948
- throw new Error("Cannot find square root");
949
- return root;
950
- }
951
- function tonelliShanks(P) {
952
- if (P < BigInt(3))
953
- throw new Error("sqrt is not defined for small field");
954
- let Q = P - _1n2;
955
- let S = 0;
956
- while (Q % _2n === _0n2) {
957
- Q /= _2n;
958
- S++;
959
- }
960
- let Z = _2n;
961
- const _Fp = Field(P);
962
- while (FpLegendre(_Fp, Z) === 1) {
963
- if (Z++ > 1000)
964
- throw new Error("Cannot find square root: probably non-prime P");
965
- }
966
- if (S === 1)
967
- return sqrt3mod4;
968
- let cc = _Fp.pow(Z, Q);
969
- const Q1div2 = (Q + _1n2) / _2n;
970
- return function tonelliSlow(Fp, n) {
971
- if (Fp.is0(n))
972
- return n;
973
- if (FpLegendre(Fp, n) !== 1)
974
- throw new Error("Cannot find square root");
975
- let M = S;
976
- let c = Fp.mul(Fp.ONE, cc);
977
- let t = Fp.pow(n, Q);
978
- let R = Fp.pow(n, Q1div2);
979
- while (!Fp.eql(t, Fp.ONE)) {
980
- if (Fp.is0(t))
981
- return Fp.ZERO;
982
- let i = 1;
983
- let t_tmp = Fp.sqr(t);
984
- while (!Fp.eql(t_tmp, Fp.ONE)) {
985
- i++;
986
- t_tmp = Fp.sqr(t_tmp);
987
- if (i === M)
988
- throw new Error("Cannot find square root");
989
- }
990
- const exponent = _1n2 << BigInt(M - i - 1);
991
- const b = Fp.pow(c, exponent);
992
- M = i;
993
- c = Fp.sqr(b);
994
- t = Fp.mul(t, c);
995
- R = Fp.mul(R, b);
996
- }
997
- return R;
998
- };
999
- }
1000
- function FpSqrt(P) {
1001
- if (P % _4n === _3n)
1002
- return sqrt3mod4;
1003
- if (P % _8n === _5n)
1004
- return sqrt5mod8;
1005
- return tonelliShanks(P);
1006
- }
1007
- function validateField(field) {
1008
- const initial = {
1009
- ORDER: "bigint",
1010
- MASK: "bigint",
1011
- BYTES: "isSafeInteger",
1012
- BITS: "isSafeInteger"
1013
- };
1014
- const opts = FIELD_FIELDS.reduce((map, val) => {
1015
- map[val] = "function";
1016
- return map;
1017
- }, initial);
1018
- return validateObject(field, opts);
1019
- }
1020
- function FpPow(Fp, num, power) {
1021
- if (power < _0n2)
1022
- throw new Error("invalid exponent, negatives unsupported");
1023
- if (power === _0n2)
1024
- return Fp.ONE;
1025
- if (power === _1n2)
1026
- return num;
1027
- let p = Fp.ONE;
1028
- let d = num;
1029
- while (power > _0n2) {
1030
- if (power & _1n2)
1031
- p = Fp.mul(p, d);
1032
- d = Fp.sqr(d);
1033
- power >>= _1n2;
1034
- }
1035
- return p;
1036
- }
1037
- function FpInvertBatch(Fp, nums, passZero = false) {
1038
- const inverted = new Array(nums.length).fill(passZero ? Fp.ZERO : undefined);
1039
- const multipliedAcc = nums.reduce((acc, num, i) => {
1040
- if (Fp.is0(num))
1041
- return acc;
1042
- inverted[i] = acc;
1043
- return Fp.mul(acc, num);
1044
- }, Fp.ONE);
1045
- const invertedAcc = Fp.inv(multipliedAcc);
1046
- nums.reduceRight((acc, num, i) => {
1047
- if (Fp.is0(num))
1048
- return acc;
1049
- inverted[i] = Fp.mul(acc, inverted[i]);
1050
- return Fp.mul(acc, num);
1051
- }, invertedAcc);
1052
- return inverted;
1053
- }
1054
- function FpLegendre(Fp, n) {
1055
- const p1mod2 = (Fp.ORDER - _1n2) / _2n;
1056
- const powered = Fp.pow(n, p1mod2);
1057
- const yes = Fp.eql(powered, Fp.ONE);
1058
- const zero = Fp.eql(powered, Fp.ZERO);
1059
- const no = Fp.eql(powered, Fp.neg(Fp.ONE));
1060
- if (!yes && !zero && !no)
1061
- throw new Error("invalid Legendre symbol result");
1062
- return yes ? 1 : zero ? 0 : -1;
1063
- }
1064
- function nLength(n, nBitLength) {
1065
- if (nBitLength !== undefined)
1066
- anumber(nBitLength);
1067
- const _nBitLength = nBitLength !== undefined ? nBitLength : n.toString(2).length;
1068
- const nByteLength = Math.ceil(_nBitLength / 8);
1069
- return { nBitLength: _nBitLength, nByteLength };
1070
- }
1071
- function Field(ORDER, bitLen2, isLE2 = false, redef = {}) {
1072
- if (ORDER <= _0n2)
1073
- throw new Error("invalid field: expected ORDER > 0, got " + ORDER);
1074
- const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, bitLen2);
1075
- if (BYTES > 2048)
1076
- throw new Error("invalid field: expected ORDER of <= 2048 bytes");
1077
- let sqrtP;
1078
- const f = Object.freeze({
1079
- ORDER,
1080
- isLE: isLE2,
1081
- BITS,
1082
- BYTES,
1083
- MASK: bitMask(BITS),
1084
- ZERO: _0n2,
1085
- ONE: _1n2,
1086
- create: (num) => mod(num, ORDER),
1087
- isValid: (num) => {
1088
- if (typeof num !== "bigint")
1089
- throw new Error("invalid field element: expected bigint, got " + typeof num);
1090
- return _0n2 <= num && num < ORDER;
1091
- },
1092
- is0: (num) => num === _0n2,
1093
- isOdd: (num) => (num & _1n2) === _1n2,
1094
- neg: (num) => mod(-num, ORDER),
1095
- eql: (lhs, rhs) => lhs === rhs,
1096
- sqr: (num) => mod(num * num, ORDER),
1097
- add: (lhs, rhs) => mod(lhs + rhs, ORDER),
1098
- sub: (lhs, rhs) => mod(lhs - rhs, ORDER),
1099
- mul: (lhs, rhs) => mod(lhs * rhs, ORDER),
1100
- pow: (num, power) => FpPow(f, num, power),
1101
- div: (lhs, rhs) => mod(lhs * invert(rhs, ORDER), ORDER),
1102
- sqrN: (num) => num * num,
1103
- addN: (lhs, rhs) => lhs + rhs,
1104
- subN: (lhs, rhs) => lhs - rhs,
1105
- mulN: (lhs, rhs) => lhs * rhs,
1106
- inv: (num) => invert(num, ORDER),
1107
- sqrt: redef.sqrt || ((n) => {
1108
- if (!sqrtP)
1109
- sqrtP = FpSqrt(ORDER);
1110
- return sqrtP(f, n);
1111
- }),
1112
- toBytes: (num) => isLE2 ? numberToBytesLE(num, BYTES) : numberToBytesBE(num, BYTES),
1113
- fromBytes: (bytes) => {
1114
- if (bytes.length !== BYTES)
1115
- throw new Error("Field.fromBytes: expected " + BYTES + " bytes, got " + bytes.length);
1116
- return isLE2 ? bytesToNumberLE(bytes) : bytesToNumberBE(bytes);
1117
- },
1118
- invertBatch: (lst) => FpInvertBatch(f, lst),
1119
- cmov: (a, b, c) => c ? b : a
1120
- });
1121
- return Object.freeze(f);
1122
- }
1123
- function getFieldBytesLength(fieldOrder) {
1124
- if (typeof fieldOrder !== "bigint")
1125
- throw new Error("field order must be bigint");
1126
- const bitLength = fieldOrder.toString(2).length;
1127
- return Math.ceil(bitLength / 8);
1128
- }
1129
- function getMinHashLength(fieldOrder) {
1130
- const length = getFieldBytesLength(fieldOrder);
1131
- return length + Math.ceil(length / 2);
1132
- }
1133
- function mapHashToField(key, fieldOrder, isLE2 = false) {
1134
- const len = key.length;
1135
- const fieldLen = getFieldBytesLength(fieldOrder);
1136
- const minLen = getMinHashLength(fieldOrder);
1137
- if (len < 16 || len < minLen || len > 1024)
1138
- throw new Error("expected " + minLen + "-1024 bytes of input, got " + len);
1139
- const num = isLE2 ? bytesToNumberLE(key) : bytesToNumberBE(key);
1140
- const reduced = mod(num, fieldOrder - _1n2) + _1n2;
1141
- return isLE2 ? numberToBytesLE(reduced, fieldLen) : numberToBytesBE(reduced, fieldLen);
1142
- }
1143
- var _0n2, _1n2, _2n, _3n, _4n, _5n, _8n, FIELD_FIELDS;
1144
- var init_modular = __esm(() => {
1145
- init_utils();
1146
- init_utils2();
1147
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1148
- _0n2 = BigInt(0);
1149
- _1n2 = BigInt(1);
1150
- _2n = /* @__PURE__ */ BigInt(2);
1151
- _3n = /* @__PURE__ */ BigInt(3);
1152
- _4n = /* @__PURE__ */ BigInt(4);
1153
- _5n = /* @__PURE__ */ BigInt(5);
1154
- _8n = /* @__PURE__ */ BigInt(8);
1155
- FIELD_FIELDS = [
1156
- "create",
1157
- "isValid",
1158
- "is0",
1159
- "neg",
1160
- "inv",
1161
- "sqrt",
1162
- "sqr",
1163
- "eql",
1164
- "add",
1165
- "sub",
1166
- "mul",
1167
- "pow",
1168
- "div",
1169
- "addN",
1170
- "subN",
1171
- "mulN",
1172
- "sqrN"
1173
- ];
1174
- });
1175
-
1176
- // ../../node_modules/.bun/@noble+curves@1.9.1/node_modules/@noble/curves/esm/abstract/curve.js
1177
- function constTimeNegate(condition, item) {
1178
- const neg = item.negate();
1179
- return condition ? neg : item;
1180
- }
1181
- function validateW(W, bits) {
1182
- if (!Number.isSafeInteger(W) || W <= 0 || W > bits)
1183
- throw new Error("invalid window size, expected [1.." + bits + "], got W=" + W);
1184
- }
1185
- function calcWOpts(W, scalarBits) {
1186
- validateW(W, scalarBits);
1187
- const windows = Math.ceil(scalarBits / W) + 1;
1188
- const windowSize = 2 ** (W - 1);
1189
- const maxNumber = 2 ** W;
1190
- const mask = bitMask(W);
1191
- const shiftBy = BigInt(W);
1192
- return { windows, windowSize, mask, maxNumber, shiftBy };
1193
- }
1194
- function calcOffsets(n, window, wOpts) {
1195
- const { windowSize, mask, maxNumber, shiftBy } = wOpts;
1196
- let wbits = Number(n & mask);
1197
- let nextN = n >> shiftBy;
1198
- if (wbits > windowSize) {
1199
- wbits -= maxNumber;
1200
- nextN += _1n3;
1201
- }
1202
- const offsetStart = window * windowSize;
1203
- const offset = offsetStart + Math.abs(wbits) - 1;
1204
- const isZero = wbits === 0;
1205
- const isNeg = wbits < 0;
1206
- const isNegF = window % 2 !== 0;
1207
- const offsetF = offsetStart;
1208
- return { nextN, offset, isZero, isNeg, isNegF, offsetF };
1209
- }
1210
- function validateMSMPoints(points, c) {
1211
- if (!Array.isArray(points))
1212
- throw new Error("array expected");
1213
- points.forEach((p, i) => {
1214
- if (!(p instanceof c))
1215
- throw new Error("invalid point at index " + i);
1216
- });
1217
- }
1218
- function validateMSMScalars(scalars, field) {
1219
- if (!Array.isArray(scalars))
1220
- throw new Error("array of scalars expected");
1221
- scalars.forEach((s, i) => {
1222
- if (!field.isValid(s))
1223
- throw new Error("invalid scalar at index " + i);
1224
- });
1225
- }
1226
- function getW(P) {
1227
- return pointWindowSizes.get(P) || 1;
1228
- }
1229
- function wNAF(c, bits) {
1230
- return {
1231
- constTimeNegate,
1232
- hasPrecomputes(elm) {
1233
- return getW(elm) !== 1;
1234
- },
1235
- unsafeLadder(elm, n, p = c.ZERO) {
1236
- let d = elm;
1237
- while (n > _0n3) {
1238
- if (n & _1n3)
1239
- p = p.add(d);
1240
- d = d.double();
1241
- n >>= _1n3;
1242
- }
1243
- return p;
1244
- },
1245
- precomputeWindow(elm, W) {
1246
- const { windows, windowSize } = calcWOpts(W, bits);
1247
- const points = [];
1248
- let p = elm;
1249
- let base = p;
1250
- for (let window = 0;window < windows; window++) {
1251
- base = p;
1252
- points.push(base);
1253
- for (let i = 1;i < windowSize; i++) {
1254
- base = base.add(p);
1255
- points.push(base);
1256
- }
1257
- p = base.double();
1258
- }
1259
- return points;
1260
- },
1261
- wNAF(W, precomputes, n) {
1262
- let p = c.ZERO;
1263
- let f = c.BASE;
1264
- const wo = calcWOpts(W, bits);
1265
- for (let window = 0;window < wo.windows; window++) {
1266
- const { nextN, offset, isZero, isNeg, isNegF, offsetF } = calcOffsets(n, window, wo);
1267
- n = nextN;
1268
- if (isZero) {
1269
- f = f.add(constTimeNegate(isNegF, precomputes[offsetF]));
1270
- } else {
1271
- p = p.add(constTimeNegate(isNeg, precomputes[offset]));
1272
- }
1273
- }
1274
- return { p, f };
1275
- },
1276
- wNAFUnsafe(W, precomputes, n, acc = c.ZERO) {
1277
- const wo = calcWOpts(W, bits);
1278
- for (let window = 0;window < wo.windows; window++) {
1279
- if (n === _0n3)
1280
- break;
1281
- const { nextN, offset, isZero, isNeg } = calcOffsets(n, window, wo);
1282
- n = nextN;
1283
- if (isZero) {
1284
- continue;
1285
- } else {
1286
- const item = precomputes[offset];
1287
- acc = acc.add(isNeg ? item.negate() : item);
1288
- }
1289
- }
1290
- return acc;
1291
- },
1292
- getPrecomputes(W, P, transform) {
1293
- let comp = pointPrecomputes.get(P);
1294
- if (!comp) {
1295
- comp = this.precomputeWindow(P, W);
1296
- if (W !== 1)
1297
- pointPrecomputes.set(P, transform(comp));
1298
- }
1299
- return comp;
1300
- },
1301
- wNAFCached(P, n, transform) {
1302
- const W = getW(P);
1303
- return this.wNAF(W, this.getPrecomputes(W, P, transform), n);
1304
- },
1305
- wNAFCachedUnsafe(P, n, transform, prev) {
1306
- const W = getW(P);
1307
- if (W === 1)
1308
- return this.unsafeLadder(P, n, prev);
1309
- return this.wNAFUnsafe(W, this.getPrecomputes(W, P, transform), n, prev);
1310
- },
1311
- setWindowSize(P, W) {
1312
- validateW(W, bits);
1313
- pointWindowSizes.set(P, W);
1314
- pointPrecomputes.delete(P);
1315
- }
1316
- };
1317
- }
1318
- function pippenger(c, fieldN, points, scalars) {
1319
- validateMSMPoints(points, c);
1320
- validateMSMScalars(scalars, fieldN);
1321
- const plength = points.length;
1322
- const slength = scalars.length;
1323
- if (plength !== slength)
1324
- throw new Error("arrays of points and scalars must have equal length");
1325
- const zero = c.ZERO;
1326
- const wbits = bitLen(BigInt(plength));
1327
- let windowSize = 1;
1328
- if (wbits > 12)
1329
- windowSize = wbits - 3;
1330
- else if (wbits > 4)
1331
- windowSize = wbits - 2;
1332
- else if (wbits > 0)
1333
- windowSize = 2;
1334
- const MASK = bitMask(windowSize);
1335
- const buckets = new Array(Number(MASK) + 1).fill(zero);
1336
- const lastBits = Math.floor((fieldN.BITS - 1) / windowSize) * windowSize;
1337
- let sum = zero;
1338
- for (let i = lastBits;i >= 0; i -= windowSize) {
1339
- buckets.fill(zero);
1340
- for (let j = 0;j < slength; j++) {
1341
- const scalar = scalars[j];
1342
- const wbits2 = Number(scalar >> BigInt(i) & MASK);
1343
- buckets[wbits2] = buckets[wbits2].add(points[j]);
1344
- }
1345
- let resI = zero;
1346
- for (let j = buckets.length - 1, sumI = zero;j > 0; j--) {
1347
- sumI = sumI.add(buckets[j]);
1348
- resI = resI.add(sumI);
1349
- }
1350
- sum = sum.add(resI);
1351
- if (i !== 0)
1352
- for (let j = 0;j < windowSize; j++)
1353
- sum = sum.double();
1354
- }
1355
- return sum;
1356
- }
1357
- function validateBasic(curve) {
1358
- validateField(curve.Fp);
1359
- validateObject(curve, {
1360
- n: "bigint",
1361
- h: "bigint",
1362
- Gx: "field",
1363
- Gy: "field"
1364
- }, {
1365
- nBitLength: "isSafeInteger",
1366
- nByteLength: "isSafeInteger"
1367
- });
1368
- return Object.freeze({
1369
- ...nLength(curve.n, curve.nBitLength),
1370
- ...curve,
1371
- ...{ p: curve.Fp.ORDER }
1372
- });
1373
- }
1374
- var _0n3, _1n3, pointPrecomputes, pointWindowSizes;
1375
- var init_curve = __esm(() => {
1376
- init_modular();
1377
- init_utils2();
1378
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1379
- _0n3 = BigInt(0);
1380
- _1n3 = BigInt(1);
1381
- pointPrecomputes = new WeakMap;
1382
- pointWindowSizes = new WeakMap;
1383
- });
1384
-
1385
- // ../../node_modules/.bun/@noble+curves@1.9.1/node_modules/@noble/curves/esm/abstract/weierstrass.js
1386
- function validateSigVerOpts(opts) {
1387
- if (opts.lowS !== undefined)
1388
- abool("lowS", opts.lowS);
1389
- if (opts.prehash !== undefined)
1390
- abool("prehash", opts.prehash);
1391
- }
1392
- function validatePointOpts(curve) {
1393
- const opts = validateBasic(curve);
1394
- validateObject(opts, {
1395
- a: "field",
1396
- b: "field"
1397
- }, {
1398
- allowInfinityPoint: "boolean",
1399
- allowedPrivateKeyLengths: "array",
1400
- clearCofactor: "function",
1401
- fromBytes: "function",
1402
- isTorsionFree: "function",
1403
- toBytes: "function",
1404
- wrapPrivateKey: "boolean"
1405
- });
1406
- const { endo, Fp, a } = opts;
1407
- if (endo) {
1408
- if (!Fp.eql(a, Fp.ZERO)) {
1409
- throw new Error("invalid endo: CURVE.a must be 0");
1410
- }
1411
- if (typeof endo !== "object" || typeof endo.beta !== "bigint" || typeof endo.splitScalar !== "function") {
1412
- throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');
1413
- }
1414
- }
1415
- return Object.freeze({ ...opts });
1416
- }
1417
- function numToSizedHex(num, size) {
1418
- return bytesToHex(numberToBytesBE(num, size));
1419
- }
1420
- function weierstrassPoints(opts) {
1421
- const CURVE = validatePointOpts(opts);
1422
- const { Fp } = CURVE;
1423
- const Fn = Field(CURVE.n, CURVE.nBitLength);
1424
- const toBytes2 = CURVE.toBytes || ((_c, point, _isCompressed) => {
1425
- const a = point.toAffine();
1426
- return concatBytes2(Uint8Array.from([4]), Fp.toBytes(a.x), Fp.toBytes(a.y));
1427
- });
1428
- const fromBytes = CURVE.fromBytes || ((bytes) => {
1429
- const tail = bytes.subarray(1);
1430
- const x = Fp.fromBytes(tail.subarray(0, Fp.BYTES));
1431
- const y = Fp.fromBytes(tail.subarray(Fp.BYTES, 2 * Fp.BYTES));
1432
- return { x, y };
1433
- });
1434
- function weierstrassEquation(x) {
1435
- const { a, b } = CURVE;
1436
- const x2 = Fp.sqr(x);
1437
- const x3 = Fp.mul(x2, x);
1438
- return Fp.add(Fp.add(x3, Fp.mul(x, a)), b);
1439
- }
1440
- function isValidXY(x, y) {
1441
- const left = Fp.sqr(y);
1442
- const right = weierstrassEquation(x);
1443
- return Fp.eql(left, right);
1444
- }
1445
- if (!isValidXY(CURVE.Gx, CURVE.Gy))
1446
- throw new Error("bad curve params: generator point");
1447
- const _4a3 = Fp.mul(Fp.pow(CURVE.a, _3n2), _4n2);
1448
- const _27b2 = Fp.mul(Fp.sqr(CURVE.b), BigInt(27));
1449
- if (Fp.is0(Fp.add(_4a3, _27b2)))
1450
- throw new Error("bad curve params: a or b");
1451
- function isWithinCurveOrder(num) {
1452
- return inRange(num, _1n4, CURVE.n);
1453
- }
1454
- function normPrivateKeyToScalar(key) {
1455
- const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n: N } = CURVE;
1456
- if (lengths && typeof key !== "bigint") {
1457
- if (isBytes2(key))
1458
- key = bytesToHex(key);
1459
- if (typeof key !== "string" || !lengths.includes(key.length))
1460
- throw new Error("invalid private key");
1461
- key = key.padStart(nByteLength * 2, "0");
1462
- }
1463
- let num;
1464
- try {
1465
- num = typeof key === "bigint" ? key : bytesToNumberBE(ensureBytes("private key", key, nByteLength));
1466
- } catch (error) {
1467
- throw new Error("invalid private key, expected hex or " + nByteLength + " bytes, got " + typeof key);
1468
- }
1469
- if (wrapPrivateKey)
1470
- num = mod(num, N);
1471
- aInRange("private key", num, _1n4, N);
1472
- return num;
1473
- }
1474
- function aprjpoint(other) {
1475
- if (!(other instanceof Point))
1476
- throw new Error("ProjectivePoint expected");
1477
- }
1478
- const toAffineMemo = memoized((p, iz) => {
1479
- const { px: x, py: y, pz: z } = p;
1480
- if (Fp.eql(z, Fp.ONE))
1481
- return { x, y };
1482
- const is0 = p.is0();
1483
- if (iz == null)
1484
- iz = is0 ? Fp.ONE : Fp.inv(z);
1485
- const ax = Fp.mul(x, iz);
1486
- const ay = Fp.mul(y, iz);
1487
- const zz = Fp.mul(z, iz);
1488
- if (is0)
1489
- return { x: Fp.ZERO, y: Fp.ZERO };
1490
- if (!Fp.eql(zz, Fp.ONE))
1491
- throw new Error("invZ was invalid");
1492
- return { x: ax, y: ay };
1493
- });
1494
- const assertValidMemo = memoized((p) => {
1495
- if (p.is0()) {
1496
- if (CURVE.allowInfinityPoint && !Fp.is0(p.py))
1497
- return;
1498
- throw new Error("bad point: ZERO");
1499
- }
1500
- const { x, y } = p.toAffine();
1501
- if (!Fp.isValid(x) || !Fp.isValid(y))
1502
- throw new Error("bad point: x or y not FE");
1503
- if (!isValidXY(x, y))
1504
- throw new Error("bad point: equation left != right");
1505
- if (!p.isTorsionFree())
1506
- throw new Error("bad point: not in prime-order subgroup");
1507
- return true;
1508
- });
1509
-
1510
- class Point {
1511
- constructor(px, py, pz) {
1512
- if (px == null || !Fp.isValid(px))
1513
- throw new Error("x required");
1514
- if (py == null || !Fp.isValid(py) || Fp.is0(py))
1515
- throw new Error("y required");
1516
- if (pz == null || !Fp.isValid(pz))
1517
- throw new Error("z required");
1518
- this.px = px;
1519
- this.py = py;
1520
- this.pz = pz;
1521
- Object.freeze(this);
1522
- }
1523
- static fromAffine(p) {
1524
- const { x, y } = p || {};
1525
- if (!p || !Fp.isValid(x) || !Fp.isValid(y))
1526
- throw new Error("invalid affine point");
1527
- if (p instanceof Point)
1528
- throw new Error("projective point not allowed");
1529
- const is0 = (i) => Fp.eql(i, Fp.ZERO);
1530
- if (is0(x) && is0(y))
1531
- return Point.ZERO;
1532
- return new Point(x, y, Fp.ONE);
1533
- }
1534
- get x() {
1535
- return this.toAffine().x;
1536
- }
1537
- get y() {
1538
- return this.toAffine().y;
1539
- }
1540
- static normalizeZ(points) {
1541
- const toInv = FpInvertBatch(Fp, points.map((p) => p.pz));
1542
- return points.map((p, i) => p.toAffine(toInv[i])).map(Point.fromAffine);
1543
- }
1544
- static fromHex(hex) {
1545
- const P = Point.fromAffine(fromBytes(ensureBytes("pointHex", hex)));
1546
- P.assertValidity();
1547
- return P;
1548
- }
1549
- static fromPrivateKey(privateKey) {
1550
- return Point.BASE.multiply(normPrivateKeyToScalar(privateKey));
1551
- }
1552
- static msm(points, scalars) {
1553
- return pippenger(Point, Fn, points, scalars);
1554
- }
1555
- _setWindowSize(windowSize) {
1556
- wnaf.setWindowSize(this, windowSize);
1557
- }
1558
- assertValidity() {
1559
- assertValidMemo(this);
1560
- }
1561
- hasEvenY() {
1562
- const { y } = this.toAffine();
1563
- if (Fp.isOdd)
1564
- return !Fp.isOdd(y);
1565
- throw new Error("Field doesn't support isOdd");
1566
- }
1567
- equals(other) {
1568
- aprjpoint(other);
1569
- const { px: X1, py: Y1, pz: Z1 } = this;
1570
- const { px: X2, py: Y2, pz: Z2 } = other;
1571
- const U1 = Fp.eql(Fp.mul(X1, Z2), Fp.mul(X2, Z1));
1572
- const U2 = Fp.eql(Fp.mul(Y1, Z2), Fp.mul(Y2, Z1));
1573
- return U1 && U2;
1574
- }
1575
- negate() {
1576
- return new Point(this.px, Fp.neg(this.py), this.pz);
1577
- }
1578
- double() {
1579
- const { a, b } = CURVE;
1580
- const b3 = Fp.mul(b, _3n2);
1581
- const { px: X1, py: Y1, pz: Z1 } = this;
1582
- let { ZERO: X3, ZERO: Y3, ZERO: Z3 } = Fp;
1583
- let t0 = Fp.mul(X1, X1);
1584
- let t1 = Fp.mul(Y1, Y1);
1585
- let t2 = Fp.mul(Z1, Z1);
1586
- let t3 = Fp.mul(X1, Y1);
1587
- t3 = Fp.add(t3, t3);
1588
- Z3 = Fp.mul(X1, Z1);
1589
- Z3 = Fp.add(Z3, Z3);
1590
- X3 = Fp.mul(a, Z3);
1591
- Y3 = Fp.mul(b3, t2);
1592
- Y3 = Fp.add(X3, Y3);
1593
- X3 = Fp.sub(t1, Y3);
1594
- Y3 = Fp.add(t1, Y3);
1595
- Y3 = Fp.mul(X3, Y3);
1596
- X3 = Fp.mul(t3, X3);
1597
- Z3 = Fp.mul(b3, Z3);
1598
- t2 = Fp.mul(a, t2);
1599
- t3 = Fp.sub(t0, t2);
1600
- t3 = Fp.mul(a, t3);
1601
- t3 = Fp.add(t3, Z3);
1602
- Z3 = Fp.add(t0, t0);
1603
- t0 = Fp.add(Z3, t0);
1604
- t0 = Fp.add(t0, t2);
1605
- t0 = Fp.mul(t0, t3);
1606
- Y3 = Fp.add(Y3, t0);
1607
- t2 = Fp.mul(Y1, Z1);
1608
- t2 = Fp.add(t2, t2);
1609
- t0 = Fp.mul(t2, t3);
1610
- X3 = Fp.sub(X3, t0);
1611
- Z3 = Fp.mul(t2, t1);
1612
- Z3 = Fp.add(Z3, Z3);
1613
- Z3 = Fp.add(Z3, Z3);
1614
- return new Point(X3, Y3, Z3);
1615
- }
1616
- add(other) {
1617
- aprjpoint(other);
1618
- const { px: X1, py: Y1, pz: Z1 } = this;
1619
- const { px: X2, py: Y2, pz: Z2 } = other;
1620
- let { ZERO: X3, ZERO: Y3, ZERO: Z3 } = Fp;
1621
- const a = CURVE.a;
1622
- const b3 = Fp.mul(CURVE.b, _3n2);
1623
- let t0 = Fp.mul(X1, X2);
1624
- let t1 = Fp.mul(Y1, Y2);
1625
- let t2 = Fp.mul(Z1, Z2);
1626
- let t3 = Fp.add(X1, Y1);
1627
- let t4 = Fp.add(X2, Y2);
1628
- t3 = Fp.mul(t3, t4);
1629
- t4 = Fp.add(t0, t1);
1630
- t3 = Fp.sub(t3, t4);
1631
- t4 = Fp.add(X1, Z1);
1632
- let t5 = Fp.add(X2, Z2);
1633
- t4 = Fp.mul(t4, t5);
1634
- t5 = Fp.add(t0, t2);
1635
- t4 = Fp.sub(t4, t5);
1636
- t5 = Fp.add(Y1, Z1);
1637
- X3 = Fp.add(Y2, Z2);
1638
- t5 = Fp.mul(t5, X3);
1639
- X3 = Fp.add(t1, t2);
1640
- t5 = Fp.sub(t5, X3);
1641
- Z3 = Fp.mul(a, t4);
1642
- X3 = Fp.mul(b3, t2);
1643
- Z3 = Fp.add(X3, Z3);
1644
- X3 = Fp.sub(t1, Z3);
1645
- Z3 = Fp.add(t1, Z3);
1646
- Y3 = Fp.mul(X3, Z3);
1647
- t1 = Fp.add(t0, t0);
1648
- t1 = Fp.add(t1, t0);
1649
- t2 = Fp.mul(a, t2);
1650
- t4 = Fp.mul(b3, t4);
1651
- t1 = Fp.add(t1, t2);
1652
- t2 = Fp.sub(t0, t2);
1653
- t2 = Fp.mul(a, t2);
1654
- t4 = Fp.add(t4, t2);
1655
- t0 = Fp.mul(t1, t4);
1656
- Y3 = Fp.add(Y3, t0);
1657
- t0 = Fp.mul(t5, t4);
1658
- X3 = Fp.mul(t3, X3);
1659
- X3 = Fp.sub(X3, t0);
1660
- t0 = Fp.mul(t3, t1);
1661
- Z3 = Fp.mul(t5, Z3);
1662
- Z3 = Fp.add(Z3, t0);
1663
- return new Point(X3, Y3, Z3);
1664
- }
1665
- subtract(other) {
1666
- return this.add(other.negate());
1667
- }
1668
- is0() {
1669
- return this.equals(Point.ZERO);
1670
- }
1671
- wNAF(n) {
1672
- return wnaf.wNAFCached(this, n, Point.normalizeZ);
1673
- }
1674
- multiplyUnsafe(sc) {
1675
- const { endo: endo2, n: N } = CURVE;
1676
- aInRange("scalar", sc, _0n4, N);
1677
- const I = Point.ZERO;
1678
- if (sc === _0n4)
1679
- return I;
1680
- if (this.is0() || sc === _1n4)
1681
- return this;
1682
- if (!endo2 || wnaf.hasPrecomputes(this))
1683
- return wnaf.wNAFCachedUnsafe(this, sc, Point.normalizeZ);
1684
- let { k1neg, k1, k2neg, k2 } = endo2.splitScalar(sc);
1685
- let k1p = I;
1686
- let k2p = I;
1687
- let d = this;
1688
- while (k1 > _0n4 || k2 > _0n4) {
1689
- if (k1 & _1n4)
1690
- k1p = k1p.add(d);
1691
- if (k2 & _1n4)
1692
- k2p = k2p.add(d);
1693
- d = d.double();
1694
- k1 >>= _1n4;
1695
- k2 >>= _1n4;
1696
- }
1697
- if (k1neg)
1698
- k1p = k1p.negate();
1699
- if (k2neg)
1700
- k2p = k2p.negate();
1701
- k2p = new Point(Fp.mul(k2p.px, endo2.beta), k2p.py, k2p.pz);
1702
- return k1p.add(k2p);
1703
- }
1704
- multiply(scalar) {
1705
- const { endo: endo2, n: N } = CURVE;
1706
- aInRange("scalar", scalar, _1n4, N);
1707
- let point, fake;
1708
- if (endo2) {
1709
- const { k1neg, k1, k2neg, k2 } = endo2.splitScalar(scalar);
1710
- let { p: k1p, f: f1p } = this.wNAF(k1);
1711
- let { p: k2p, f: f2p } = this.wNAF(k2);
1712
- k1p = wnaf.constTimeNegate(k1neg, k1p);
1713
- k2p = wnaf.constTimeNegate(k2neg, k2p);
1714
- k2p = new Point(Fp.mul(k2p.px, endo2.beta), k2p.py, k2p.pz);
1715
- point = k1p.add(k2p);
1716
- fake = f1p.add(f2p);
1717
- } else {
1718
- const { p, f } = this.wNAF(scalar);
1719
- point = p;
1720
- fake = f;
1721
- }
1722
- return Point.normalizeZ([point, fake])[0];
1723
- }
1724
- multiplyAndAddUnsafe(Q, a, b) {
1725
- const G = Point.BASE;
1726
- const mul = (P, a2) => a2 === _0n4 || a2 === _1n4 || !P.equals(G) ? P.multiplyUnsafe(a2) : P.multiply(a2);
1727
- const sum = mul(this, a).add(mul(Q, b));
1728
- return sum.is0() ? undefined : sum;
1729
- }
1730
- toAffine(iz) {
1731
- return toAffineMemo(this, iz);
1732
- }
1733
- isTorsionFree() {
1734
- const { h: cofactor, isTorsionFree } = CURVE;
1735
- if (cofactor === _1n4)
1736
- return true;
1737
- if (isTorsionFree)
1738
- return isTorsionFree(Point, this);
1739
- throw new Error("isTorsionFree() has not been declared for the elliptic curve");
1740
- }
1741
- clearCofactor() {
1742
- const { h: cofactor, clearCofactor } = CURVE;
1743
- if (cofactor === _1n4)
1744
- return this;
1745
- if (clearCofactor)
1746
- return clearCofactor(Point, this);
1747
- return this.multiplyUnsafe(CURVE.h);
1748
- }
1749
- toRawBytes(isCompressed = true) {
1750
- abool("isCompressed", isCompressed);
1751
- this.assertValidity();
1752
- return toBytes2(Point, this, isCompressed);
1753
- }
1754
- toHex(isCompressed = true) {
1755
- abool("isCompressed", isCompressed);
1756
- return bytesToHex(this.toRawBytes(isCompressed));
1757
- }
1758
- }
1759
- Point.BASE = new Point(CURVE.Gx, CURVE.Gy, Fp.ONE);
1760
- Point.ZERO = new Point(Fp.ZERO, Fp.ONE, Fp.ZERO);
1761
- const { endo, nBitLength } = CURVE;
1762
- const wnaf = wNAF(Point, endo ? Math.ceil(nBitLength / 2) : nBitLength);
1763
- return {
1764
- CURVE,
1765
- ProjectivePoint: Point,
1766
- normPrivateKeyToScalar,
1767
- weierstrassEquation,
1768
- isWithinCurveOrder
1769
- };
1770
- }
1771
- function validateOpts(curve) {
1772
- const opts = validateBasic(curve);
1773
- validateObject(opts, {
1774
- hash: "hash",
1775
- hmac: "function",
1776
- randomBytes: "function"
1777
- }, {
1778
- bits2int: "function",
1779
- bits2int_modN: "function",
1780
- lowS: "boolean"
1781
- });
1782
- return Object.freeze({ lowS: true, ...opts });
1783
- }
1784
- function weierstrass(curveDef) {
1785
- const CURVE = validateOpts(curveDef);
1786
- const { Fp, n: CURVE_ORDER, nByteLength, nBitLength } = CURVE;
1787
- const compressedLen = Fp.BYTES + 1;
1788
- const uncompressedLen = 2 * Fp.BYTES + 1;
1789
- function modN(a) {
1790
- return mod(a, CURVE_ORDER);
1791
- }
1792
- function invN(a) {
1793
- return invert(a, CURVE_ORDER);
1794
- }
1795
- const { ProjectivePoint: Point, normPrivateKeyToScalar, weierstrassEquation, isWithinCurveOrder } = weierstrassPoints({
1796
- ...CURVE,
1797
- toBytes(_c, point, isCompressed) {
1798
- const a = point.toAffine();
1799
- const x = Fp.toBytes(a.x);
1800
- const cat = concatBytes2;
1801
- abool("isCompressed", isCompressed);
1802
- if (isCompressed) {
1803
- return cat(Uint8Array.from([point.hasEvenY() ? 2 : 3]), x);
1804
- } else {
1805
- return cat(Uint8Array.from([4]), x, Fp.toBytes(a.y));
1806
- }
1807
- },
1808
- fromBytes(bytes) {
1809
- const len = bytes.length;
1810
- const head = bytes[0];
1811
- const tail = bytes.subarray(1);
1812
- if (len === compressedLen && (head === 2 || head === 3)) {
1813
- const x = bytesToNumberBE(tail);
1814
- if (!inRange(x, _1n4, Fp.ORDER))
1815
- throw new Error("Point is not on curve");
1816
- const y2 = weierstrassEquation(x);
1817
- let y;
1818
- try {
1819
- y = Fp.sqrt(y2);
1820
- } catch (sqrtError) {
1821
- const suffix = sqrtError instanceof Error ? ": " + sqrtError.message : "";
1822
- throw new Error("Point is not on curve" + suffix);
1823
- }
1824
- const isYOdd = (y & _1n4) === _1n4;
1825
- const isHeadOdd = (head & 1) === 1;
1826
- if (isHeadOdd !== isYOdd)
1827
- y = Fp.neg(y);
1828
- return { x, y };
1829
- } else if (len === uncompressedLen && head === 4) {
1830
- const x = Fp.fromBytes(tail.subarray(0, Fp.BYTES));
1831
- const y = Fp.fromBytes(tail.subarray(Fp.BYTES, 2 * Fp.BYTES));
1832
- return { x, y };
1833
- } else {
1834
- const cl = compressedLen;
1835
- const ul = uncompressedLen;
1836
- throw new Error("invalid Point, expected length of " + cl + ", or uncompressed " + ul + ", got " + len);
1837
- }
1838
- }
1839
- });
1840
- function isBiggerThanHalfOrder(number) {
1841
- const HALF = CURVE_ORDER >> _1n4;
1842
- return number > HALF;
1843
- }
1844
- function normalizeS(s) {
1845
- return isBiggerThanHalfOrder(s) ? modN(-s) : s;
1846
- }
1847
- const slcNum = (b, from, to) => bytesToNumberBE(b.slice(from, to));
1848
-
1849
- class Signature {
1850
- constructor(r, s, recovery) {
1851
- aInRange("r", r, _1n4, CURVE_ORDER);
1852
- aInRange("s", s, _1n4, CURVE_ORDER);
1853
- this.r = r;
1854
- this.s = s;
1855
- if (recovery != null)
1856
- this.recovery = recovery;
1857
- Object.freeze(this);
1858
- }
1859
- static fromCompact(hex) {
1860
- const l = nByteLength;
1861
- hex = ensureBytes("compactSignature", hex, l * 2);
1862
- return new Signature(slcNum(hex, 0, l), slcNum(hex, l, 2 * l));
1863
- }
1864
- static fromDER(hex) {
1865
- const { r, s } = DER.toSig(ensureBytes("DER", hex));
1866
- return new Signature(r, s);
1867
- }
1868
- assertValidity() {}
1869
- addRecoveryBit(recovery) {
1870
- return new Signature(this.r, this.s, recovery);
1871
- }
1872
- recoverPublicKey(msgHash) {
1873
- const { r, s, recovery: rec } = this;
1874
- const h = bits2int_modN(ensureBytes("msgHash", msgHash));
1875
- if (rec == null || ![0, 1, 2, 3].includes(rec))
1876
- throw new Error("recovery id invalid");
1877
- const radj = rec === 2 || rec === 3 ? r + CURVE.n : r;
1878
- if (radj >= Fp.ORDER)
1879
- throw new Error("recovery id 2 or 3 invalid");
1880
- const prefix = (rec & 1) === 0 ? "02" : "03";
1881
- const R = Point.fromHex(prefix + numToSizedHex(radj, Fp.BYTES));
1882
- const ir = invN(radj);
1883
- const u1 = modN(-h * ir);
1884
- const u2 = modN(s * ir);
1885
- const Q = Point.BASE.multiplyAndAddUnsafe(R, u1, u2);
1886
- if (!Q)
1887
- throw new Error("point at infinify");
1888
- Q.assertValidity();
1889
- return Q;
1890
- }
1891
- hasHighS() {
1892
- return isBiggerThanHalfOrder(this.s);
1893
- }
1894
- normalizeS() {
1895
- return this.hasHighS() ? new Signature(this.r, modN(-this.s), this.recovery) : this;
1896
- }
1897
- toDERRawBytes() {
1898
- return hexToBytes(this.toDERHex());
1899
- }
1900
- toDERHex() {
1901
- return DER.hexFromSig(this);
1902
- }
1903
- toCompactRawBytes() {
1904
- return hexToBytes(this.toCompactHex());
1905
- }
1906
- toCompactHex() {
1907
- const l = nByteLength;
1908
- return numToSizedHex(this.r, l) + numToSizedHex(this.s, l);
1909
- }
1910
- }
1911
- const utils = {
1912
- isValidPrivateKey(privateKey) {
1913
- try {
1914
- normPrivateKeyToScalar(privateKey);
1915
- return true;
1916
- } catch (error) {
1917
- return false;
1918
- }
1919
- },
1920
- normPrivateKeyToScalar,
1921
- randomPrivateKey: () => {
1922
- const length = getMinHashLength(CURVE.n);
1923
- return mapHashToField(CURVE.randomBytes(length), CURVE.n);
1924
- },
1925
- precompute(windowSize = 8, point = Point.BASE) {
1926
- point._setWindowSize(windowSize);
1927
- point.multiply(BigInt(3));
1928
- return point;
1929
- }
1930
- };
1931
- function getPublicKey(privateKey, isCompressed = true) {
1932
- return Point.fromPrivateKey(privateKey).toRawBytes(isCompressed);
1933
- }
1934
- function isProbPub(item) {
1935
- if (typeof item === "bigint")
1936
- return false;
1937
- if (item instanceof Point)
1938
- return true;
1939
- const arr = ensureBytes("key", item);
1940
- const len = arr.length;
1941
- const fpl = Fp.BYTES;
1942
- const compLen = fpl + 1;
1943
- const uncompLen = 2 * fpl + 1;
1944
- if (CURVE.allowedPrivateKeyLengths || nByteLength === compLen) {
1945
- return;
1946
- } else {
1947
- return len === compLen || len === uncompLen;
1948
- }
1949
- }
1950
- function getSharedSecret(privateA, publicB, isCompressed = true) {
1951
- if (isProbPub(privateA) === true)
1952
- throw new Error("first arg must be private key");
1953
- if (isProbPub(publicB) === false)
1954
- throw new Error("second arg must be public key");
1955
- const b = Point.fromHex(publicB);
1956
- return b.multiply(normPrivateKeyToScalar(privateA)).toRawBytes(isCompressed);
1957
- }
1958
- const bits2int = CURVE.bits2int || function(bytes) {
1959
- if (bytes.length > 8192)
1960
- throw new Error("input is too large");
1961
- const num = bytesToNumberBE(bytes);
1962
- const delta = bytes.length * 8 - nBitLength;
1963
- return delta > 0 ? num >> BigInt(delta) : num;
1964
- };
1965
- const bits2int_modN = CURVE.bits2int_modN || function(bytes) {
1966
- return modN(bits2int(bytes));
1967
- };
1968
- const ORDER_MASK = bitMask(nBitLength);
1969
- function int2octets(num) {
1970
- aInRange("num < 2^" + nBitLength, num, _0n4, ORDER_MASK);
1971
- return numberToBytesBE(num, nByteLength);
1972
- }
1973
- function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
1974
- if (["recovered", "canonical"].some((k) => (k in opts)))
1975
- throw new Error("sign() legacy options not supported");
1976
- const { hash, randomBytes: randomBytes2 } = CURVE;
1977
- let { lowS, prehash, extraEntropy: ent } = opts;
1978
- if (lowS == null)
1979
- lowS = true;
1980
- msgHash = ensureBytes("msgHash", msgHash);
1981
- validateSigVerOpts(opts);
1982
- if (prehash)
1983
- msgHash = ensureBytes("prehashed msgHash", hash(msgHash));
1984
- const h1int = bits2int_modN(msgHash);
1985
- const d = normPrivateKeyToScalar(privateKey);
1986
- const seedArgs = [int2octets(d), int2octets(h1int)];
1987
- if (ent != null && ent !== false) {
1988
- const e = ent === true ? randomBytes2(Fp.BYTES) : ent;
1989
- seedArgs.push(ensureBytes("extraEntropy", e));
1990
- }
1991
- const seed = concatBytes2(...seedArgs);
1992
- const m = h1int;
1993
- function k2sig(kBytes) {
1994
- const k = bits2int(kBytes);
1995
- if (!isWithinCurveOrder(k))
1996
- return;
1997
- const ik = invN(k);
1998
- const q = Point.BASE.multiply(k).toAffine();
1999
- const r = modN(q.x);
2000
- if (r === _0n4)
2001
- return;
2002
- const s = modN(ik * modN(m + r * d));
2003
- if (s === _0n4)
2004
- return;
2005
- let recovery = (q.x === r ? 0 : 2) | Number(q.y & _1n4);
2006
- let normS = s;
2007
- if (lowS && isBiggerThanHalfOrder(s)) {
2008
- normS = normalizeS(s);
2009
- recovery ^= 1;
2010
- }
2011
- return new Signature(r, normS, recovery);
2012
- }
2013
- return { seed, k2sig };
2014
- }
2015
- const defaultSigOpts = { lowS: CURVE.lowS, prehash: false };
2016
- const defaultVerOpts = { lowS: CURVE.lowS, prehash: false };
2017
- function sign(msgHash, privKey, opts = defaultSigOpts) {
2018
- const { seed, k2sig } = prepSig(msgHash, privKey, opts);
2019
- const C = CURVE;
2020
- const drbg = createHmacDrbg(C.hash.outputLen, C.nByteLength, C.hmac);
2021
- return drbg(seed, k2sig);
2022
- }
2023
- Point.BASE._setWindowSize(8);
2024
- function verify(signature, msgHash, publicKey, opts = defaultVerOpts) {
2025
- const sg = signature;
2026
- msgHash = ensureBytes("msgHash", msgHash);
2027
- publicKey = ensureBytes("publicKey", publicKey);
2028
- const { lowS, prehash, format } = opts;
2029
- validateSigVerOpts(opts);
2030
- if ("strict" in opts)
2031
- throw new Error("options.strict was renamed to lowS");
2032
- if (format !== undefined && format !== "compact" && format !== "der")
2033
- throw new Error("format must be compact or der");
2034
- const isHex = typeof sg === "string" || isBytes2(sg);
2035
- const isObj = !isHex && !format && typeof sg === "object" && sg !== null && typeof sg.r === "bigint" && typeof sg.s === "bigint";
2036
- if (!isHex && !isObj)
2037
- throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
2038
- let _sig = undefined;
2039
- let P;
2040
- try {
2041
- if (isObj)
2042
- _sig = new Signature(sg.r, sg.s);
2043
- if (isHex) {
2044
- try {
2045
- if (format !== "compact")
2046
- _sig = Signature.fromDER(sg);
2047
- } catch (derError) {
2048
- if (!(derError instanceof DER.Err))
2049
- throw derError;
2050
- }
2051
- if (!_sig && format !== "der")
2052
- _sig = Signature.fromCompact(sg);
2053
- }
2054
- P = Point.fromHex(publicKey);
2055
- } catch (error) {
2056
- return false;
2057
- }
2058
- if (!_sig)
2059
- return false;
2060
- if (lowS && _sig.hasHighS())
2061
- return false;
2062
- if (prehash)
2063
- msgHash = CURVE.hash(msgHash);
2064
- const { r, s } = _sig;
2065
- const h = bits2int_modN(msgHash);
2066
- const is = invN(s);
2067
- const u1 = modN(h * is);
2068
- const u2 = modN(r * is);
2069
- const R = Point.BASE.multiplyAndAddUnsafe(P, u1, u2)?.toAffine();
2070
- if (!R)
2071
- return false;
2072
- const v = modN(R.x);
2073
- return v === r;
2074
- }
2075
- return {
2076
- CURVE,
2077
- getPublicKey,
2078
- getSharedSecret,
2079
- sign,
2080
- verify,
2081
- ProjectivePoint: Point,
2082
- Signature,
2083
- utils
2084
- };
2085
- }
2086
- var DERErr, DER, _0n4, _1n4, _2n2, _3n2, _4n2;
2087
- var init_weierstrass = __esm(() => {
2088
- init_curve();
2089
- init_modular();
2090
- init_utils2();
2091
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2092
- DERErr = class DERErr extends Error {
2093
- constructor(m = "") {
2094
- super(m);
2095
- }
2096
- };
2097
- DER = {
2098
- Err: DERErr,
2099
- _tlv: {
2100
- encode: (tag, data) => {
2101
- const { Err: E } = DER;
2102
- if (tag < 0 || tag > 256)
2103
- throw new E("tlv.encode: wrong tag");
2104
- if (data.length & 1)
2105
- throw new E("tlv.encode: unpadded data");
2106
- const dataLen = data.length / 2;
2107
- const len = numberToHexUnpadded(dataLen);
2108
- if (len.length / 2 & 128)
2109
- throw new E("tlv.encode: long form length too big");
2110
- const lenLen = dataLen > 127 ? numberToHexUnpadded(len.length / 2 | 128) : "";
2111
- const t = numberToHexUnpadded(tag);
2112
- return t + lenLen + len + data;
2113
- },
2114
- decode(tag, data) {
2115
- const { Err: E } = DER;
2116
- let pos = 0;
2117
- if (tag < 0 || tag > 256)
2118
- throw new E("tlv.encode: wrong tag");
2119
- if (data.length < 2 || data[pos++] !== tag)
2120
- throw new E("tlv.decode: wrong tlv");
2121
- const first = data[pos++];
2122
- const isLong = !!(first & 128);
2123
- let length = 0;
2124
- if (!isLong)
2125
- length = first;
2126
- else {
2127
- const lenLen = first & 127;
2128
- if (!lenLen)
2129
- throw new E("tlv.decode(long): indefinite length not supported");
2130
- if (lenLen > 4)
2131
- throw new E("tlv.decode(long): byte length is too big");
2132
- const lengthBytes = data.subarray(pos, pos + lenLen);
2133
- if (lengthBytes.length !== lenLen)
2134
- throw new E("tlv.decode: length bytes not complete");
2135
- if (lengthBytes[0] === 0)
2136
- throw new E("tlv.decode(long): zero leftmost byte");
2137
- for (const b of lengthBytes)
2138
- length = length << 8 | b;
2139
- pos += lenLen;
2140
- if (length < 128)
2141
- throw new E("tlv.decode(long): not minimal encoding");
2142
- }
2143
- const v = data.subarray(pos, pos + length);
2144
- if (v.length !== length)
2145
- throw new E("tlv.decode: wrong value length");
2146
- return { v, l: data.subarray(pos + length) };
2147
- }
2148
- },
2149
- _int: {
2150
- encode(num) {
2151
- const { Err: E } = DER;
2152
- if (num < _0n4)
2153
- throw new E("integer: negative integers are not allowed");
2154
- let hex = numberToHexUnpadded(num);
2155
- if (Number.parseInt(hex[0], 16) & 8)
2156
- hex = "00" + hex;
2157
- if (hex.length & 1)
2158
- throw new E("unexpected DER parsing assertion: unpadded hex");
2159
- return hex;
2160
- },
2161
- decode(data) {
2162
- const { Err: E } = DER;
2163
- if (data[0] & 128)
2164
- throw new E("invalid signature integer: negative");
2165
- if (data[0] === 0 && !(data[1] & 128))
2166
- throw new E("invalid signature integer: unnecessary leading zero");
2167
- return bytesToNumberBE(data);
2168
- }
2169
- },
2170
- toSig(hex) {
2171
- const { Err: E, _int: int, _tlv: tlv } = DER;
2172
- const data = ensureBytes("signature", hex);
2173
- const { v: seqBytes, l: seqLeftBytes } = tlv.decode(48, data);
2174
- if (seqLeftBytes.length)
2175
- throw new E("invalid signature: left bytes after parsing");
2176
- const { v: rBytes, l: rLeftBytes } = tlv.decode(2, seqBytes);
2177
- const { v: sBytes, l: sLeftBytes } = tlv.decode(2, rLeftBytes);
2178
- if (sLeftBytes.length)
2179
- throw new E("invalid signature: left bytes after parsing");
2180
- return { r: int.decode(rBytes), s: int.decode(sBytes) };
2181
- },
2182
- hexFromSig(sig) {
2183
- const { _tlv: tlv, _int: int } = DER;
2184
- const rs = tlv.encode(2, int.encode(sig.r));
2185
- const ss = tlv.encode(2, int.encode(sig.s));
2186
- const seq = rs + ss;
2187
- return tlv.encode(48, seq);
2188
- }
2189
- };
2190
- _0n4 = BigInt(0);
2191
- _1n4 = BigInt(1);
2192
- _2n2 = BigInt(2);
2193
- _3n2 = BigInt(3);
2194
- _4n2 = BigInt(4);
2195
- });
2196
-
2197
- // ../../node_modules/.bun/@noble+curves@1.9.1/node_modules/@noble/curves/esm/_shortw_utils.js
2198
- function getHash(hash) {
2199
- return {
2200
- hash,
2201
- hmac: (key, ...msgs) => hmac(hash, key, concatBytes(...msgs)),
2202
- randomBytes
2203
- };
2204
- }
2205
- function createCurve(curveDef, defHash) {
2206
- const create = (hash) => weierstrass({ ...curveDef, ...getHash(hash) });
2207
- return { ...create(defHash), create };
2208
- }
2209
- var init__shortw_utils = __esm(() => {
2210
- init_hmac();
2211
- init_utils();
2212
- init_weierstrass();
2213
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2214
- });
2215
-
2216
- // ../../node_modules/.bun/@noble+curves@1.9.1/node_modules/@noble/curves/esm/secp256k1.js
2217
- function sqrtMod(y) {
2218
- const P = secp256k1P;
2219
- const _3n3 = BigInt(3), _6n = BigInt(6), _11n = BigInt(11), _22n = BigInt(22);
2220
- const _23n = BigInt(23), _44n = BigInt(44), _88n = BigInt(88);
2221
- const b2 = y * y * y % P;
2222
- const b3 = b2 * b2 * y % P;
2223
- const b6 = pow2(b3, _3n3, P) * b3 % P;
2224
- const b9 = pow2(b6, _3n3, P) * b3 % P;
2225
- const b11 = pow2(b9, _2n3, P) * b2 % P;
2226
- const b22 = pow2(b11, _11n, P) * b11 % P;
2227
- const b44 = pow2(b22, _22n, P) * b22 % P;
2228
- const b88 = pow2(b44, _44n, P) * b44 % P;
2229
- const b176 = pow2(b88, _88n, P) * b88 % P;
2230
- const b220 = pow2(b176, _44n, P) * b44 % P;
2231
- const b223 = pow2(b220, _3n3, P) * b3 % P;
2232
- const t1 = pow2(b223, _23n, P) * b22 % P;
2233
- const t2 = pow2(t1, _6n, P) * b2 % P;
2234
- const root = pow2(t2, _2n3, P);
2235
- if (!Fpk1.eql(Fpk1.sqr(root), y))
2236
- throw new Error("Cannot find square root");
2237
- return root;
2238
- }
2239
- var secp256k1P, secp256k1N, _0n5, _1n5, _2n3, divNearest = (a, b) => (a + b / _2n3) / b, Fpk1, secp256k1;
2240
- var init_secp256k1 = __esm(() => {
2241
- init_sha2();
2242
- init__shortw_utils();
2243
- init_modular();
2244
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2245
- secp256k1P = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f");
2246
- secp256k1N = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");
2247
- _0n5 = BigInt(0);
2248
- _1n5 = BigInt(1);
2249
- _2n3 = BigInt(2);
2250
- Fpk1 = Field(secp256k1P, undefined, undefined, { sqrt: sqrtMod });
2251
- secp256k1 = createCurve({
2252
- a: _0n5,
2253
- b: BigInt(7),
2254
- Fp: Fpk1,
2255
- n: secp256k1N,
2256
- Gx: BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),
2257
- Gy: BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),
2258
- h: BigInt(1),
2259
- lowS: true,
2260
- endo: {
2261
- beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
2262
- splitScalar: (k) => {
2263
- const n = secp256k1N;
2264
- const a1 = BigInt("0x3086d221a7d46bcde86c90e49284eb15");
2265
- const b1 = -_1n5 * BigInt("0xe4437ed6010e88286f547fa90abfe4c3");
2266
- const a2 = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8");
2267
- const b2 = a1;
2268
- const POW_2_128 = BigInt("0x100000000000000000000000000000000");
2269
- const c1 = divNearest(b2 * k, n);
2270
- const c2 = divNearest(-b1 * k, n);
2271
- let k1 = mod(k - c1 * a1 - c2 * a2, n);
2272
- let k2 = mod(-c1 * b1 - c2 * b2, n);
2273
- const k1neg = k1 > POW_2_128;
2274
- const k2neg = k2 > POW_2_128;
2275
- if (k1neg)
2276
- k1 = n - k1;
2277
- if (k2neg)
2278
- k2 = n - k2;
2279
- if (k1 > POW_2_128 || k2 > POW_2_128) {
2280
- throw new Error("splitScalar: Endomorphism failed, k=" + k);
2281
- }
2282
- return { k1neg, k1, k2neg, k2 };
2283
- }
2284
- }
2285
- }, sha256);
2286
- });
2287
-
2288
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/errors/version.js
2289
- var version = "2.48.8";
2290
-
2291
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/errors/base.js
2292
- function walk(err, fn) {
2293
- if (fn?.(err))
2294
- return err;
2295
- if (err && typeof err === "object" && "cause" in err && err.cause !== undefined)
2296
- return walk(err.cause, fn);
2297
- return fn ? null : err;
2298
- }
2299
- var errorConfig, BaseError;
2300
- var init_base = __esm(() => {
2301
- errorConfig = {
2302
- getDocsUrl: ({ docsBaseUrl, docsPath = "", docsSlug }) => docsPath ? `${docsBaseUrl ?? "https://viem.sh"}${docsPath}${docsSlug ? `#${docsSlug}` : ""}` : undefined,
2303
- version: `viem@${version}`
2304
- };
2305
- BaseError = class BaseError extends Error {
2306
- constructor(shortMessage, args = {}) {
2307
- const details = (() => {
2308
- if (args.cause instanceof BaseError)
2309
- return args.cause.details;
2310
- if (args.cause?.message)
2311
- return args.cause.message;
2312
- return args.details;
2313
- })();
2314
- const docsPath = (() => {
2315
- if (args.cause instanceof BaseError)
2316
- return args.cause.docsPath || args.docsPath;
2317
- return args.docsPath;
2318
- })();
2319
- const docsUrl = errorConfig.getDocsUrl?.({ ...args, docsPath });
2320
- const message = [
2321
- shortMessage || "An error occurred.",
2322
- "",
2323
- ...args.metaMessages ? [...args.metaMessages, ""] : [],
2324
- ...docsUrl ? [`Docs: ${docsUrl}`] : [],
2325
- ...details ? [`Details: ${details}`] : [],
2326
- ...errorConfig.version ? [`Version: ${errorConfig.version}`] : []
2327
- ].join(`
2328
- `);
2329
- super(message, args.cause ? { cause: args.cause } : undefined);
2330
- Object.defineProperty(this, "details", {
2331
- enumerable: true,
2332
- configurable: true,
2333
- writable: true,
2334
- value: undefined
2335
- });
2336
- Object.defineProperty(this, "docsPath", {
2337
- enumerable: true,
2338
- configurable: true,
2339
- writable: true,
2340
- value: undefined
2341
- });
2342
- Object.defineProperty(this, "metaMessages", {
2343
- enumerable: true,
2344
- configurable: true,
2345
- writable: true,
2346
- value: undefined
2347
- });
2348
- Object.defineProperty(this, "shortMessage", {
2349
- enumerable: true,
2350
- configurable: true,
2351
- writable: true,
2352
- value: undefined
2353
- });
2354
- Object.defineProperty(this, "version", {
2355
- enumerable: true,
2356
- configurable: true,
2357
- writable: true,
2358
- value: undefined
2359
- });
2360
- Object.defineProperty(this, "name", {
2361
- enumerable: true,
2362
- configurable: true,
2363
- writable: true,
2364
- value: "BaseError"
2365
- });
2366
- this.details = details;
2367
- this.docsPath = docsPath;
2368
- this.metaMessages = args.metaMessages;
2369
- this.name = args.name ?? this.name;
2370
- this.shortMessage = shortMessage;
2371
- this.version = version;
2372
- }
2373
- walk(fn) {
2374
- return walk(this, fn);
2375
- }
2376
- };
2377
- });
2378
-
2379
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/errors/encoding.js
2380
- var IntegerOutOfRangeError, SizeOverflowError;
2381
- var init_encoding = __esm(() => {
2382
- init_base();
2383
- IntegerOutOfRangeError = class IntegerOutOfRangeError extends BaseError {
2384
- constructor({ max, min, signed, size, value }) {
2385
- super(`Number "${value}" is not in safe ${size ? `${size * 8}-bit ${signed ? "signed" : "unsigned"} ` : ""}integer range ${max ? `(${min} to ${max})` : `(above ${min})`}`, { name: "IntegerOutOfRangeError" });
2386
- }
2387
- };
2388
- SizeOverflowError = class SizeOverflowError extends BaseError {
2389
- constructor({ givenSize, maxSize }) {
2390
- super(`Size cannot exceed ${maxSize} bytes. Given size: ${givenSize} bytes.`, { name: "SizeOverflowError" });
2391
- }
2392
- };
2393
- });
2394
-
2395
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/errors/data.js
2396
- var SliceOffsetOutOfBoundsError, SizeExceedsPaddingSizeError;
2397
- var init_data = __esm(() => {
2398
- init_base();
2399
- SliceOffsetOutOfBoundsError = class SliceOffsetOutOfBoundsError extends BaseError {
2400
- constructor({ offset, position, size }) {
2401
- super(`Slice ${position === "start" ? "starting" : "ending"} at offset "${offset}" is out-of-bounds (size: ${size}).`, { name: "SliceOffsetOutOfBoundsError" });
2402
- }
2403
- };
2404
- SizeExceedsPaddingSizeError = class SizeExceedsPaddingSizeError extends BaseError {
2405
- constructor({ size, targetSize, type }) {
2406
- super(`${type.charAt(0).toUpperCase()}${type.slice(1).toLowerCase()} size (${size}) exceeds padding size (${targetSize}).`, { name: "SizeExceedsPaddingSizeError" });
2407
- }
2408
- };
2409
- });
2410
-
2411
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/data/pad.js
2412
- function pad(hexOrBytes, { dir, size = 32 } = {}) {
2413
- if (typeof hexOrBytes === "string")
2414
- return padHex(hexOrBytes, { dir, size });
2415
- return padBytes(hexOrBytes, { dir, size });
2416
- }
2417
- function padHex(hex_, { dir, size = 32 } = {}) {
2418
- if (size === null)
2419
- return hex_;
2420
- const hex = hex_.replace("0x", "");
2421
- if (hex.length > size * 2)
2422
- throw new SizeExceedsPaddingSizeError({
2423
- size: Math.ceil(hex.length / 2),
2424
- targetSize: size,
2425
- type: "hex"
2426
- });
2427
- return `0x${hex[dir === "right" ? "padEnd" : "padStart"](size * 2, "0")}`;
2428
- }
2429
- function padBytes(bytes, { dir, size = 32 } = {}) {
2430
- if (size === null)
2431
- return bytes;
2432
- if (bytes.length > size)
2433
- throw new SizeExceedsPaddingSizeError({
2434
- size: bytes.length,
2435
- targetSize: size,
2436
- type: "bytes"
2437
- });
2438
- const paddedBytes = new Uint8Array(size);
2439
- for (let i = 0;i < size; i++) {
2440
- const padEnd = dir === "right";
2441
- paddedBytes[padEnd ? i : size - i - 1] = bytes[padEnd ? i : bytes.length - i - 1];
2442
- }
2443
- return paddedBytes;
2444
- }
2445
- var init_pad = __esm(() => {
2446
- init_data();
2447
- });
2448
-
2449
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/data/isHex.js
2450
- function isHex(value, { strict = true } = {}) {
2451
- if (!value)
2452
- return false;
2453
- if (typeof value !== "string")
2454
- return false;
2455
- return strict ? /^0x[0-9a-fA-F]*$/.test(value) : value.startsWith("0x");
2456
- }
2457
-
2458
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/data/size.js
2459
- function size(value) {
2460
- if (isHex(value, { strict: false }))
2461
- return Math.ceil((value.length - 2) / 2);
2462
- return value.length;
2463
- }
2464
- var init_size = () => {};
2465
-
2466
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/data/trim.js
2467
- function trim(hexOrBytes, { dir = "left" } = {}) {
2468
- let data = typeof hexOrBytes === "string" ? hexOrBytes.replace("0x", "") : hexOrBytes;
2469
- let sliceLength = 0;
2470
- for (let i = 0;i < data.length - 1; i++) {
2471
- if (data[dir === "left" ? i : data.length - i - 1].toString() === "0")
2472
- sliceLength++;
2473
- else
2474
- break;
2475
- }
2476
- data = dir === "left" ? data.slice(sliceLength) : data.slice(0, data.length - sliceLength);
2477
- if (typeof hexOrBytes === "string") {
2478
- if (data.length === 1 && dir === "right")
2479
- data = `${data}0`;
2480
- return `0x${data.length % 2 === 1 ? `0${data}` : data}`;
2481
- }
2482
- return data;
2483
- }
2484
-
2485
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/encoding/toBytes.js
2486
- function toBytes2(value, opts = {}) {
2487
- if (typeof value === "number" || typeof value === "bigint")
2488
- return numberToBytes(value, opts);
2489
- if (typeof value === "boolean")
2490
- return boolToBytes(value, opts);
2491
- if (isHex(value))
2492
- return hexToBytes2(value, opts);
2493
- return stringToBytes(value, opts);
2494
- }
2495
- function boolToBytes(value, opts = {}) {
2496
- const bytes = new Uint8Array(1);
2497
- bytes[0] = Number(value);
2498
- if (typeof opts.size === "number") {
2499
- assertSize(bytes, { size: opts.size });
2500
- return pad(bytes, { size: opts.size });
2501
- }
2502
- return bytes;
2503
- }
2504
- function charCodeToBase16(char) {
2505
- if (char >= charCodeMap.zero && char <= charCodeMap.nine)
2506
- return char - charCodeMap.zero;
2507
- if (char >= charCodeMap.A && char <= charCodeMap.F)
2508
- return char - (charCodeMap.A - 10);
2509
- if (char >= charCodeMap.a && char <= charCodeMap.f)
2510
- return char - (charCodeMap.a - 10);
2511
- return;
2512
- }
2513
- function hexToBytes2(hex_, opts = {}) {
2514
- let hex = hex_;
2515
- if (opts.size) {
2516
- assertSize(hex, { size: opts.size });
2517
- hex = pad(hex, { dir: "right", size: opts.size });
2518
- }
2519
- let hexString = hex.slice(2);
2520
- if (hexString.length % 2)
2521
- hexString = `0${hexString}`;
2522
- const length = hexString.length / 2;
2523
- const bytes = new Uint8Array(length);
2524
- for (let index = 0, j = 0;index < length; index++) {
2525
- const nibbleLeft = charCodeToBase16(hexString.charCodeAt(j++));
2526
- const nibbleRight = charCodeToBase16(hexString.charCodeAt(j++));
2527
- if (nibbleLeft === undefined || nibbleRight === undefined) {
2528
- throw new BaseError(`Invalid byte sequence ("${hexString[j - 2]}${hexString[j - 1]}" in "${hexString}").`);
2529
- }
2530
- bytes[index] = nibbleLeft * 16 + nibbleRight;
2531
- }
2532
- return bytes;
2533
- }
2534
- function numberToBytes(value, opts) {
2535
- const hex = numberToHex(value, opts);
2536
- return hexToBytes2(hex);
2537
- }
2538
- function stringToBytes(value, opts = {}) {
2539
- const bytes = encoder.encode(value);
2540
- if (typeof opts.size === "number") {
2541
- assertSize(bytes, { size: opts.size });
2542
- return pad(bytes, { dir: "right", size: opts.size });
2543
- }
2544
- return bytes;
2545
- }
2546
- var encoder, charCodeMap;
2547
- var init_toBytes = __esm(() => {
2548
- init_base();
2549
- init_pad();
2550
- init_fromHex();
2551
- init_toHex();
2552
- encoder = /* @__PURE__ */ new TextEncoder;
2553
- charCodeMap = {
2554
- zero: 48,
2555
- nine: 57,
2556
- A: 65,
2557
- F: 70,
2558
- a: 97,
2559
- f: 102
2560
- };
2561
- });
2562
-
2563
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/encoding/fromHex.js
2564
- function assertSize(hexOrBytes, { size: size2 }) {
2565
- if (size(hexOrBytes) > size2)
2566
- throw new SizeOverflowError({
2567
- givenSize: size(hexOrBytes),
2568
- maxSize: size2
2569
- });
2570
- }
2571
- function hexToBigInt(hex, opts = {}) {
2572
- const { signed } = opts;
2573
- if (opts.size)
2574
- assertSize(hex, { size: opts.size });
2575
- const value = BigInt(hex);
2576
- if (!signed)
2577
- return value;
2578
- const size2 = (hex.length - 2) / 2;
2579
- const max = (1n << BigInt(size2) * 8n - 1n) - 1n;
2580
- if (value <= max)
2581
- return value;
2582
- return value - BigInt(`0x${"f".padStart(size2 * 2, "f")}`) - 1n;
2583
- }
2584
- function hexToNumber2(hex, opts = {}) {
2585
- const value = hexToBigInt(hex, opts);
2586
- const number = Number(value);
2587
- if (!Number.isSafeInteger(number))
2588
- throw new IntegerOutOfRangeError({
2589
- max: `${Number.MAX_SAFE_INTEGER}`,
2590
- min: `${Number.MIN_SAFE_INTEGER}`,
2591
- signed: opts.signed,
2592
- size: opts.size,
2593
- value: `${value}n`
2594
- });
2595
- return number;
2596
- }
2597
- var init_fromHex = __esm(() => {
2598
- init_encoding();
2599
- init_size();
2600
- });
2601
-
2602
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/encoding/toHex.js
2603
- function toHex(value, opts = {}) {
2604
- if (typeof value === "number" || typeof value === "bigint")
2605
- return numberToHex(value, opts);
2606
- if (typeof value === "string") {
2607
- return stringToHex(value, opts);
2608
- }
2609
- if (typeof value === "boolean")
2610
- return boolToHex(value, opts);
2611
- return bytesToHex2(value, opts);
2612
- }
2613
- function boolToHex(value, opts = {}) {
2614
- const hex = `0x${Number(value)}`;
2615
- if (typeof opts.size === "number") {
2616
- assertSize(hex, { size: opts.size });
2617
- return pad(hex, { size: opts.size });
2618
- }
2619
- return hex;
2620
- }
2621
- function bytesToHex2(value, opts = {}) {
2622
- let string = "";
2623
- for (let i = 0;i < value.length; i++) {
2624
- string += hexes2[value[i]];
2625
- }
2626
- const hex = `0x${string}`;
2627
- if (typeof opts.size === "number") {
2628
- assertSize(hex, { size: opts.size });
2629
- return pad(hex, { dir: "right", size: opts.size });
2630
- }
2631
- return hex;
2632
- }
2633
- function numberToHex(value_, opts = {}) {
2634
- const { signed, size: size2 } = opts;
2635
- const value = BigInt(value_);
2636
- let maxValue;
2637
- if (size2) {
2638
- if (signed)
2639
- maxValue = (1n << BigInt(size2) * 8n - 1n) - 1n;
2640
- else
2641
- maxValue = 2n ** (BigInt(size2) * 8n) - 1n;
2642
- } else if (typeof value_ === "number") {
2643
- maxValue = BigInt(Number.MAX_SAFE_INTEGER);
2644
- }
2645
- const minValue = typeof maxValue === "bigint" && signed ? -maxValue - 1n : 0;
2646
- if (maxValue && value > maxValue || value < minValue) {
2647
- const suffix = typeof value_ === "bigint" ? "n" : "";
2648
- throw new IntegerOutOfRangeError({
2649
- max: maxValue ? `${maxValue}${suffix}` : undefined,
2650
- min: `${minValue}${suffix}`,
2651
- signed,
2652
- size: size2,
2653
- value: `${value_}${suffix}`
2654
- });
2655
- }
2656
- const hex = `0x${(signed && value < 0 ? (1n << BigInt(size2 * 8)) + BigInt(value) : value).toString(16)}`;
2657
- if (size2)
2658
- return pad(hex, { size: size2 });
2659
- return hex;
2660
- }
2661
- function stringToHex(value_, opts = {}) {
2662
- const value = encoder2.encode(value_);
2663
- return bytesToHex2(value, opts);
2664
- }
2665
- var hexes2, encoder2;
2666
- var init_toHex = __esm(() => {
2667
- init_encoding();
2668
- init_pad();
2669
- init_fromHex();
2670
- hexes2 = /* @__PURE__ */ Array.from({ length: 256 }, (_v, i) => i.toString(16).padStart(2, "0"));
2671
- encoder2 = /* @__PURE__ */ new TextEncoder;
2672
- });
2673
-
2674
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/accounts/generatePrivateKey.js
2675
- function generatePrivateKey() {
2676
- return toHex(secp256k1.utils.randomPrivateKey());
2677
- }
2678
- var init_generatePrivateKey = __esm(() => {
2679
- init_secp256k1();
2680
- init_toHex();
2681
- });
2682
-
2683
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/errors/address.js
2684
- var InvalidAddressError;
2685
- var init_address = __esm(() => {
2686
- init_base();
2687
- InvalidAddressError = class InvalidAddressError extends BaseError {
2688
- constructor({ address }) {
2689
- super(`Address "${address}" is invalid.`, {
2690
- metaMessages: [
2691
- "- Address must be a hex value of 20 bytes (40 hex characters).",
2692
- "- Address must match its checksum counterpart."
2693
- ],
2694
- name: "InvalidAddressError"
2695
- });
2696
- }
2697
- };
2698
- });
2699
-
2700
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/lru.js
2701
- var LruMap;
2702
- var init_lru = __esm(() => {
2703
- LruMap = class LruMap extends Map {
2704
- constructor(size2) {
2705
- super();
2706
- Object.defineProperty(this, "maxSize", {
2707
- enumerable: true,
2708
- configurable: true,
2709
- writable: true,
2710
- value: undefined
2711
- });
2712
- this.maxSize = size2;
2713
- }
2714
- get(key) {
2715
- const value = super.get(key);
2716
- if (super.has(key)) {
2717
- super.delete(key);
2718
- super.set(key, value);
2719
- }
2720
- return value;
2721
- }
2722
- set(key, value) {
2723
- if (super.has(key))
2724
- super.delete(key);
2725
- super.set(key, value);
2726
- if (this.maxSize && this.size > this.maxSize) {
2727
- const firstKey = super.keys().next().value;
2728
- if (firstKey !== undefined)
2729
- super.delete(firstKey);
2730
- }
2731
- return this;
2732
- }
2733
- };
2734
- });
2735
-
2736
- // ../../node_modules/.bun/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/sha3.js
2737
- function keccakP(s, rounds = 24) {
2738
- const B = new Uint32Array(5 * 2);
2739
- for (let round = 24 - rounds;round < 24; round++) {
2740
- for (let x = 0;x < 10; x++)
2741
- B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
2742
- for (let x = 0;x < 10; x += 2) {
2743
- const idx1 = (x + 8) % 10;
2744
- const idx0 = (x + 2) % 10;
2745
- const B0 = B[idx0];
2746
- const B1 = B[idx0 + 1];
2747
- const Th = rotlH(B0, B1, 1) ^ B[idx1];
2748
- const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
2749
- for (let y = 0;y < 50; y += 10) {
2750
- s[x + y] ^= Th;
2751
- s[x + y + 1] ^= Tl;
2752
- }
2753
- }
2754
- let curH = s[2];
2755
- let curL = s[3];
2756
- for (let t = 0;t < 24; t++) {
2757
- const shift = SHA3_ROTL[t];
2758
- const Th = rotlH(curH, curL, shift);
2759
- const Tl = rotlL(curH, curL, shift);
2760
- const PI = SHA3_PI[t];
2761
- curH = s[PI];
2762
- curL = s[PI + 1];
2763
- s[PI] = Th;
2764
- s[PI + 1] = Tl;
2765
- }
2766
- for (let y = 0;y < 50; y += 10) {
2767
- for (let x = 0;x < 10; x++)
2768
- B[x] = s[y + x];
2769
- for (let x = 0;x < 10; x++)
2770
- s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
2771
- }
2772
- s[0] ^= SHA3_IOTA_H[round];
2773
- s[1] ^= SHA3_IOTA_L[round];
2774
- }
2775
- clean(B);
2776
- }
2777
- var _0n6, _1n6, _2n4, _7n, _256n, _0x71n, SHA3_PI, SHA3_ROTL, _SHA3_IOTA, IOTAS, SHA3_IOTA_H, SHA3_IOTA_L, rotlH = (h, l, s) => s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s), rotlL = (h, l, s) => s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s), Keccak, gen = (suffix, blockLen, outputLen) => createHasher(() => new Keccak(blockLen, suffix, outputLen)), keccak_256;
2778
- var init_sha3 = __esm(() => {
2779
- init__u64();
2780
- init_utils();
2781
- _0n6 = BigInt(0);
2782
- _1n6 = BigInt(1);
2783
- _2n4 = BigInt(2);
2784
- _7n = BigInt(7);
2785
- _256n = BigInt(256);
2786
- _0x71n = BigInt(113);
2787
- SHA3_PI = [];
2788
- SHA3_ROTL = [];
2789
- _SHA3_IOTA = [];
2790
- for (let round = 0, R = _1n6, x = 1, y = 0;round < 24; round++) {
2791
- [x, y] = [y, (2 * x + 3 * y) % 5];
2792
- SHA3_PI.push(2 * (5 * y + x));
2793
- SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64);
2794
- let t = _0n6;
2795
- for (let j = 0;j < 7; j++) {
2796
- R = (R << _1n6 ^ (R >> _7n) * _0x71n) % _256n;
2797
- if (R & _2n4)
2798
- t ^= _1n6 << (_1n6 << /* @__PURE__ */ BigInt(j)) - _1n6;
2799
- }
2800
- _SHA3_IOTA.push(t);
2801
- }
2802
- IOTAS = split(_SHA3_IOTA, true);
2803
- SHA3_IOTA_H = IOTAS[0];
2804
- SHA3_IOTA_L = IOTAS[1];
2805
- Keccak = class Keccak extends Hash {
2806
- constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
2807
- super();
2808
- this.pos = 0;
2809
- this.posOut = 0;
2810
- this.finished = false;
2811
- this.destroyed = false;
2812
- this.enableXOF = false;
2813
- this.blockLen = blockLen;
2814
- this.suffix = suffix;
2815
- this.outputLen = outputLen;
2816
- this.enableXOF = enableXOF;
2817
- this.rounds = rounds;
2818
- anumber(outputLen);
2819
- if (!(0 < blockLen && blockLen < 200))
2820
- throw new Error("only keccak-f1600 function is supported");
2821
- this.state = new Uint8Array(200);
2822
- this.state32 = u32(this.state);
2823
- }
2824
- clone() {
2825
- return this._cloneInto();
2826
- }
2827
- keccak() {
2828
- swap32IfBE(this.state32);
2829
- keccakP(this.state32, this.rounds);
2830
- swap32IfBE(this.state32);
2831
- this.posOut = 0;
2832
- this.pos = 0;
2833
- }
2834
- update(data) {
2835
- aexists(this);
2836
- data = toBytes(data);
2837
- abytes(data);
2838
- const { blockLen, state } = this;
2839
- const len = data.length;
2840
- for (let pos = 0;pos < len; ) {
2841
- const take = Math.min(blockLen - this.pos, len - pos);
2842
- for (let i = 0;i < take; i++)
2843
- state[this.pos++] ^= data[pos++];
2844
- if (this.pos === blockLen)
2845
- this.keccak();
2846
- }
2847
- return this;
2848
- }
2849
- finish() {
2850
- if (this.finished)
2851
- return;
2852
- this.finished = true;
2853
- const { state, suffix, pos, blockLen } = this;
2854
- state[pos] ^= suffix;
2855
- if ((suffix & 128) !== 0 && pos === blockLen - 1)
2856
- this.keccak();
2857
- state[blockLen - 1] ^= 128;
2858
- this.keccak();
2859
- }
2860
- writeInto(out) {
2861
- aexists(this, false);
2862
- abytes(out);
2863
- this.finish();
2864
- const bufferOut = this.state;
2865
- const { blockLen } = this;
2866
- for (let pos = 0, len = out.length;pos < len; ) {
2867
- if (this.posOut >= blockLen)
2868
- this.keccak();
2869
- const take = Math.min(blockLen - this.posOut, len - pos);
2870
- out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
2871
- this.posOut += take;
2872
- pos += take;
2873
- }
2874
- return out;
2875
- }
2876
- xofInto(out) {
2877
- if (!this.enableXOF)
2878
- throw new Error("XOF is not possible for this instance");
2879
- return this.writeInto(out);
2880
- }
2881
- xof(bytes) {
2882
- anumber(bytes);
2883
- return this.xofInto(new Uint8Array(bytes));
2884
- }
2885
- digestInto(out) {
2886
- aoutput(out, this);
2887
- if (this.finished)
2888
- throw new Error("digest() was already called");
2889
- this.writeInto(out);
2890
- this.destroy();
2891
- return out;
2892
- }
2893
- digest() {
2894
- return this.digestInto(new Uint8Array(this.outputLen));
2895
- }
2896
- destroy() {
2897
- this.destroyed = true;
2898
- clean(this.state);
2899
- }
2900
- _cloneInto(to) {
2901
- const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
2902
- to || (to = new Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
2903
- to.state32.set(this.state32);
2904
- to.pos = this.pos;
2905
- to.posOut = this.posOut;
2906
- to.finished = this.finished;
2907
- to.rounds = rounds;
2908
- to.suffix = suffix;
2909
- to.outputLen = outputLen;
2910
- to.enableXOF = enableXOF;
2911
- to.destroyed = this.destroyed;
2912
- return to;
2913
- }
2914
- };
2915
- keccak_256 = /* @__PURE__ */ (() => gen(1, 136, 256 / 8))();
2916
- });
2917
-
2918
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/hash/keccak256.js
2919
- function keccak256(value, to_) {
2920
- const to = to_ || "hex";
2921
- const bytes = keccak_256(isHex(value, { strict: false }) ? toBytes2(value) : value);
2922
- if (to === "bytes")
2923
- return bytes;
2924
- return toHex(bytes);
2925
- }
2926
- var init_keccak256 = __esm(() => {
2927
- init_sha3();
2928
- init_toBytes();
2929
- init_toHex();
2930
- });
2931
-
2932
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/address/getAddress.js
2933
- function checksumAddress(address_, chainId) {
2934
- if (checksumAddressCache.has(`${address_}.${chainId}`))
2935
- return checksumAddressCache.get(`${address_}.${chainId}`);
2936
- const hexAddress = chainId ? `${chainId}${address_.toLowerCase()}` : address_.substring(2).toLowerCase();
2937
- const hash = keccak256(stringToBytes(hexAddress), "bytes");
2938
- const address = (chainId ? hexAddress.substring(`${chainId}0x`.length) : hexAddress).split("");
2939
- for (let i = 0;i < 40; i += 2) {
2940
- if (hash[i >> 1] >> 4 >= 8 && address[i]) {
2941
- address[i] = address[i].toUpperCase();
2942
- }
2943
- if ((hash[i >> 1] & 15) >= 8 && address[i + 1]) {
2944
- address[i + 1] = address[i + 1].toUpperCase();
2945
- }
2946
- }
2947
- const result = `0x${address.join("")}`;
2948
- checksumAddressCache.set(`${address_}.${chainId}`, result);
2949
- return result;
2950
- }
2951
- var checksumAddressCache;
2952
- var init_getAddress = __esm(() => {
2953
- init_toBytes();
2954
- init_keccak256();
2955
- init_lru();
2956
- checksumAddressCache = /* @__PURE__ */ new LruMap(8192);
2957
- });
2958
-
2959
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/address/isAddress.js
2960
- function isAddress(address, options) {
2961
- const { strict = true } = options ?? {};
2962
- const cacheKey = `${address}.${strict}`;
2963
- if (isAddressCache.has(cacheKey))
2964
- return isAddressCache.get(cacheKey);
2965
- const result = (() => {
2966
- if (!addressRegex.test(address))
2967
- return false;
2968
- if (address.toLowerCase() === address)
2969
- return true;
2970
- if (strict)
2971
- return checksumAddress(address) === address;
2972
- return true;
2973
- })();
2974
- isAddressCache.set(cacheKey, result);
2975
- return result;
2976
- }
2977
- var addressRegex, isAddressCache;
2978
- var init_isAddress = __esm(() => {
2979
- init_lru();
2980
- init_getAddress();
2981
- addressRegex = /^0x[a-fA-F0-9]{40}$/;
2982
- isAddressCache = /* @__PURE__ */ new LruMap(8192);
2983
- });
2984
-
2985
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/accounts/toAccount.js
2986
- function toAccount(source) {
2987
- if (typeof source === "string") {
2988
- if (!isAddress(source, { strict: false }))
2989
- throw new InvalidAddressError({ address: source });
2990
- return {
2991
- address: source,
2992
- type: "json-rpc"
2993
- };
2994
- }
2995
- if (!isAddress(source.address, { strict: false }))
2996
- throw new InvalidAddressError({ address: source.address });
2997
- return {
2998
- address: source.address,
2999
- nonceManager: source.nonceManager,
3000
- sign: source.sign,
3001
- signAuthorization: source.signAuthorization,
3002
- signMessage: source.signMessage,
3003
- signTransaction: source.signTransaction,
3004
- signTypedData: source.signTypedData,
3005
- source: "custom",
3006
- type: "local"
3007
- };
3008
- }
3009
- var init_toAccount = __esm(() => {
3010
- init_address();
3011
- init_isAddress();
3012
- });
3013
-
3014
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/accounts/utils/publicKeyToAddress.js
3015
- function publicKeyToAddress(publicKey) {
3016
- const address = keccak256(`0x${publicKey.substring(4)}`).substring(26);
3017
- return checksumAddress(`0x${address}`);
3018
- }
3019
- var init_publicKeyToAddress = __esm(() => {
3020
- init_getAddress();
3021
- init_keccak256();
3022
- });
3023
-
3024
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/signature/serializeSignature.js
3025
- function serializeSignature({ r, s, to = "hex", v, yParity }) {
3026
- const yParity_ = (() => {
3027
- if (yParity === 0 || yParity === 1)
3028
- return yParity;
3029
- if (v && (v === 27n || v === 28n || v >= 35n))
3030
- return v % 2n === 0n ? 1 : 0;
3031
- throw new Error("Invalid `v` or `yParity` value");
3032
- })();
3033
- const signature = `0x${new secp256k1.Signature(hexToBigInt(r), hexToBigInt(s)).toCompactHex()}${yParity_ === 0 ? "1b" : "1c"}`;
3034
- if (to === "hex")
3035
- return signature;
3036
- return hexToBytes2(signature);
3037
- }
3038
- var init_serializeSignature = __esm(() => {
3039
- init_secp256k1();
3040
- init_fromHex();
3041
- init_toBytes();
3042
- });
3043
-
3044
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/accounts/utils/sign.js
3045
- async function sign({ hash, privateKey, to = "object" }) {
3046
- const { r, s, recovery } = secp256k1.sign(hash.slice(2), privateKey.slice(2), {
3047
- lowS: true,
3048
- extraEntropy: isHex(extraEntropy, { strict: false }) ? hexToBytes2(extraEntropy) : extraEntropy
3049
- });
3050
- const signature = {
3051
- r: numberToHex(r, { size: 32 }),
3052
- s: numberToHex(s, { size: 32 }),
3053
- v: recovery ? 28n : 27n,
3054
- yParity: recovery
3055
- };
3056
- return (() => {
3057
- if (to === "bytes" || to === "hex")
3058
- return serializeSignature({ ...signature, to });
3059
- return signature;
3060
- })();
3061
- }
3062
- var extraEntropy = false;
3063
- var init_sign = __esm(() => {
3064
- init_secp256k1();
3065
- init_toBytes();
3066
- init_toHex();
3067
- init_serializeSignature();
3068
- });
3069
-
3070
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/data/concat.js
3071
- function concat(values) {
3072
- if (typeof values[0] === "string")
3073
- return concatHex(values);
3074
- return concatBytes3(values);
3075
- }
3076
- function concatBytes3(values) {
3077
- let length = 0;
3078
- for (const arr of values) {
3079
- length += arr.length;
3080
- }
3081
- const result = new Uint8Array(length);
3082
- let offset = 0;
3083
- for (const arr of values) {
3084
- result.set(arr, offset);
3085
- offset += arr.length;
3086
- }
3087
- return result;
3088
- }
3089
- function concatHex(values) {
3090
- return `0x${values.reduce((acc, x) => acc + x.replace("0x", ""), "")}`;
3091
- }
3092
-
3093
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/errors/cursor.js
3094
- var NegativeOffsetError, PositionOutOfBoundsError, RecursiveReadLimitExceededError;
3095
- var init_cursor = __esm(() => {
3096
- init_base();
3097
- NegativeOffsetError = class NegativeOffsetError extends BaseError {
3098
- constructor({ offset }) {
3099
- super(`Offset \`${offset}\` cannot be negative.`, {
3100
- name: "NegativeOffsetError"
3101
- });
3102
- }
3103
- };
3104
- PositionOutOfBoundsError = class PositionOutOfBoundsError extends BaseError {
3105
- constructor({ length, position }) {
3106
- super(`Position \`${position}\` is out of bounds (\`0 < position < ${length}\`).`, { name: "PositionOutOfBoundsError" });
3107
- }
3108
- };
3109
- RecursiveReadLimitExceededError = class RecursiveReadLimitExceededError extends BaseError {
3110
- constructor({ count, limit }) {
3111
- super(`Recursive read limit of \`${limit}\` exceeded (recursive read count: \`${count}\`).`, { name: "RecursiveReadLimitExceededError" });
3112
- }
3113
- };
3114
- });
3115
-
3116
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/cursor.js
3117
- function createCursor(bytes, { recursiveReadLimit = 8192 } = {}) {
3118
- const cursor = Object.create(staticCursor);
3119
- cursor.bytes = bytes;
3120
- cursor.dataView = new DataView(bytes.buffer ?? bytes, bytes.byteOffset, bytes.byteLength);
3121
- cursor.positionReadCount = new Map;
3122
- cursor.recursiveReadLimit = recursiveReadLimit;
3123
- return cursor;
3124
- }
3125
- var staticCursor;
3126
- var init_cursor2 = __esm(() => {
3127
- init_cursor();
3128
- staticCursor = {
3129
- bytes: new Uint8Array,
3130
- dataView: new DataView(new ArrayBuffer(0)),
3131
- position: 0,
3132
- positionReadCount: new Map,
3133
- recursiveReadCount: 0,
3134
- recursiveReadLimit: Number.POSITIVE_INFINITY,
3135
- assertReadLimit() {
3136
- if (this.recursiveReadCount >= this.recursiveReadLimit)
3137
- throw new RecursiveReadLimitExceededError({
3138
- count: this.recursiveReadCount + 1,
3139
- limit: this.recursiveReadLimit
3140
- });
3141
- },
3142
- assertPosition(position) {
3143
- if (position < 0 || position > this.bytes.length - 1)
3144
- throw new PositionOutOfBoundsError({
3145
- length: this.bytes.length,
3146
- position
3147
- });
3148
- },
3149
- decrementPosition(offset) {
3150
- if (offset < 0)
3151
- throw new NegativeOffsetError({ offset });
3152
- const position = this.position - offset;
3153
- this.assertPosition(position);
3154
- this.position = position;
3155
- },
3156
- getReadCount(position) {
3157
- return this.positionReadCount.get(position || this.position) || 0;
3158
- },
3159
- incrementPosition(offset) {
3160
- if (offset < 0)
3161
- throw new NegativeOffsetError({ offset });
3162
- const position = this.position + offset;
3163
- this.assertPosition(position);
3164
- this.position = position;
3165
- },
3166
- inspectByte(position_) {
3167
- const position = position_ ?? this.position;
3168
- this.assertPosition(position);
3169
- return this.bytes[position];
3170
- },
3171
- inspectBytes(length, position_) {
3172
- const position = position_ ?? this.position;
3173
- this.assertPosition(position + length - 1);
3174
- return this.bytes.subarray(position, position + length);
3175
- },
3176
- inspectUint8(position_) {
3177
- const position = position_ ?? this.position;
3178
- this.assertPosition(position);
3179
- return this.bytes[position];
3180
- },
3181
- inspectUint16(position_) {
3182
- const position = position_ ?? this.position;
3183
- this.assertPosition(position + 1);
3184
- return this.dataView.getUint16(position);
3185
- },
3186
- inspectUint24(position_) {
3187
- const position = position_ ?? this.position;
3188
- this.assertPosition(position + 2);
3189
- return (this.dataView.getUint16(position) << 8) + this.dataView.getUint8(position + 2);
3190
- },
3191
- inspectUint32(position_) {
3192
- const position = position_ ?? this.position;
3193
- this.assertPosition(position + 3);
3194
- return this.dataView.getUint32(position);
3195
- },
3196
- pushByte(byte) {
3197
- this.assertPosition(this.position);
3198
- this.bytes[this.position] = byte;
3199
- this.position++;
3200
- },
3201
- pushBytes(bytes) {
3202
- this.assertPosition(this.position + bytes.length - 1);
3203
- this.bytes.set(bytes, this.position);
3204
- this.position += bytes.length;
3205
- },
3206
- pushUint8(value) {
3207
- this.assertPosition(this.position);
3208
- this.bytes[this.position] = value;
3209
- this.position++;
3210
- },
3211
- pushUint16(value) {
3212
- this.assertPosition(this.position + 1);
3213
- this.dataView.setUint16(this.position, value);
3214
- this.position += 2;
3215
- },
3216
- pushUint24(value) {
3217
- this.assertPosition(this.position + 2);
3218
- this.dataView.setUint16(this.position, value >> 8);
3219
- this.dataView.setUint8(this.position + 2, value & ~4294967040);
3220
- this.position += 3;
3221
- },
3222
- pushUint32(value) {
3223
- this.assertPosition(this.position + 3);
3224
- this.dataView.setUint32(this.position, value);
3225
- this.position += 4;
3226
- },
3227
- readByte() {
3228
- this.assertReadLimit();
3229
- this._touch();
3230
- const value = this.inspectByte();
3231
- this.position++;
3232
- return value;
3233
- },
3234
- readBytes(length, size2) {
3235
- this.assertReadLimit();
3236
- this._touch();
3237
- const value = this.inspectBytes(length);
3238
- this.position += size2 ?? length;
3239
- return value;
3240
- },
3241
- readUint8() {
3242
- this.assertReadLimit();
3243
- this._touch();
3244
- const value = this.inspectUint8();
3245
- this.position += 1;
3246
- return value;
3247
- },
3248
- readUint16() {
3249
- this.assertReadLimit();
3250
- this._touch();
3251
- const value = this.inspectUint16();
3252
- this.position += 2;
3253
- return value;
3254
- },
3255
- readUint24() {
3256
- this.assertReadLimit();
3257
- this._touch();
3258
- const value = this.inspectUint24();
3259
- this.position += 3;
3260
- return value;
3261
- },
3262
- readUint32() {
3263
- this.assertReadLimit();
3264
- this._touch();
3265
- const value = this.inspectUint32();
3266
- this.position += 4;
3267
- return value;
3268
- },
3269
- get remaining() {
3270
- return this.bytes.length - this.position;
3271
- },
3272
- setPosition(position) {
3273
- const oldPosition = this.position;
3274
- this.assertPosition(position);
3275
- this.position = position;
3276
- return () => this.position = oldPosition;
3277
- },
3278
- _touch() {
3279
- if (this.recursiveReadLimit === Number.POSITIVE_INFINITY)
3280
- return;
3281
- const count = this.getReadCount();
3282
- this.positionReadCount.set(this.position, count + 1);
3283
- if (count > 0)
3284
- this.recursiveReadCount++;
3285
- }
3286
- };
3287
- });
3288
-
3289
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/encoding/toRlp.js
3290
- function toRlp(bytes, to = "hex") {
3291
- const encodable = getEncodable(bytes);
3292
- const cursor = createCursor(new Uint8Array(encodable.length));
3293
- encodable.encode(cursor);
3294
- if (to === "hex")
3295
- return bytesToHex2(cursor.bytes);
3296
- return cursor.bytes;
3297
- }
3298
- function getEncodable(bytes) {
3299
- if (Array.isArray(bytes))
3300
- return getEncodableList(bytes.map((x) => getEncodable(x)));
3301
- return getEncodableBytes(bytes);
3302
- }
3303
- function getEncodableList(list) {
3304
- const bodyLength = list.reduce((acc, x) => acc + x.length, 0);
3305
- const sizeOfBodyLength = getSizeOfLength(bodyLength);
3306
- const length = (() => {
3307
- if (bodyLength <= 55)
3308
- return 1 + bodyLength;
3309
- return 1 + sizeOfBodyLength + bodyLength;
3310
- })();
3311
- return {
3312
- length,
3313
- encode(cursor) {
3314
- if (bodyLength <= 55) {
3315
- cursor.pushByte(192 + bodyLength);
3316
- } else {
3317
- cursor.pushByte(192 + 55 + sizeOfBodyLength);
3318
- if (sizeOfBodyLength === 1)
3319
- cursor.pushUint8(bodyLength);
3320
- else if (sizeOfBodyLength === 2)
3321
- cursor.pushUint16(bodyLength);
3322
- else if (sizeOfBodyLength === 3)
3323
- cursor.pushUint24(bodyLength);
3324
- else
3325
- cursor.pushUint32(bodyLength);
3326
- }
3327
- for (const { encode } of list) {
3328
- encode(cursor);
3329
- }
3330
- }
3331
- };
3332
- }
3333
- function getEncodableBytes(bytesOrHex) {
3334
- const bytes = typeof bytesOrHex === "string" ? hexToBytes2(bytesOrHex) : bytesOrHex;
3335
- const sizeOfBytesLength = getSizeOfLength(bytes.length);
3336
- const length = (() => {
3337
- if (bytes.length === 1 && bytes[0] < 128)
3338
- return 1;
3339
- if (bytes.length <= 55)
3340
- return 1 + bytes.length;
3341
- return 1 + sizeOfBytesLength + bytes.length;
3342
- })();
3343
- return {
3344
- length,
3345
- encode(cursor) {
3346
- if (bytes.length === 1 && bytes[0] < 128) {
3347
- cursor.pushBytes(bytes);
3348
- } else if (bytes.length <= 55) {
3349
- cursor.pushByte(128 + bytes.length);
3350
- cursor.pushBytes(bytes);
3351
- } else {
3352
- cursor.pushByte(128 + 55 + sizeOfBytesLength);
3353
- if (sizeOfBytesLength === 1)
3354
- cursor.pushUint8(bytes.length);
3355
- else if (sizeOfBytesLength === 2)
3356
- cursor.pushUint16(bytes.length);
3357
- else if (sizeOfBytesLength === 3)
3358
- cursor.pushUint24(bytes.length);
3359
- else
3360
- cursor.pushUint32(bytes.length);
3361
- cursor.pushBytes(bytes);
3362
- }
3363
- }
3364
- };
3365
- }
3366
- function getSizeOfLength(length) {
3367
- if (length < 2 ** 8)
3368
- return 1;
3369
- if (length < 2 ** 16)
3370
- return 2;
3371
- if (length < 2 ** 24)
3372
- return 3;
3373
- if (length < 2 ** 32)
3374
- return 4;
3375
- throw new BaseError("Length is too large.");
3376
- }
3377
- var init_toRlp = __esm(() => {
3378
- init_base();
3379
- init_cursor2();
3380
- init_toBytes();
3381
- init_toHex();
3382
- });
3383
-
3384
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/authorization/hashAuthorization.js
3385
- function hashAuthorization(parameters) {
3386
- const { chainId, nonce, to } = parameters;
3387
- const address = parameters.contractAddress ?? parameters.address;
3388
- const hash = keccak256(concatHex([
3389
- "0x05",
3390
- toRlp([
3391
- chainId ? numberToHex(chainId) : "0x",
3392
- address,
3393
- nonce ? numberToHex(nonce) : "0x"
3394
- ])
3395
- ]));
3396
- if (to === "bytes")
3397
- return hexToBytes2(hash);
3398
- return hash;
3399
- }
3400
- var init_hashAuthorization = __esm(() => {
3401
- init_toBytes();
3402
- init_toHex();
3403
- init_toRlp();
3404
- init_keccak256();
3405
- });
3406
-
3407
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/accounts/utils/signAuthorization.js
3408
- async function signAuthorization(parameters) {
3409
- const { chainId, nonce, privateKey, to = "object" } = parameters;
3410
- const address = parameters.contractAddress ?? parameters.address;
3411
- const signature = await sign({
3412
- hash: hashAuthorization({ address, chainId, nonce }),
3413
- privateKey,
3414
- to
3415
- });
3416
- if (to === "object")
3417
- return {
3418
- address,
3419
- chainId,
3420
- nonce,
3421
- ...signature
3422
- };
3423
- return signature;
3424
- }
3425
- var init_signAuthorization = __esm(() => {
3426
- init_hashAuthorization();
3427
- init_sign();
3428
- });
3429
-
3430
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/constants/strings.js
3431
- var presignMessagePrefix = `\x19Ethereum Signed Message:
3432
- `;
3433
-
3434
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/signature/toPrefixedMessage.js
3435
- function toPrefixedMessage(message_) {
3436
- const message = (() => {
3437
- if (typeof message_ === "string")
3438
- return stringToHex(message_);
3439
- if (typeof message_.raw === "string")
3440
- return message_.raw;
3441
- return bytesToHex2(message_.raw);
3442
- })();
3443
- const prefix = stringToHex(`${presignMessagePrefix}${size(message)}`);
3444
- return concat([prefix, message]);
3445
- }
3446
- var init_toPrefixedMessage = __esm(() => {
3447
- init_size();
3448
- init_toHex();
3449
- });
3450
-
3451
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/signature/hashMessage.js
3452
- function hashMessage(message, to_) {
3453
- return keccak256(toPrefixedMessage(message), to_);
3454
- }
3455
- var init_hashMessage = __esm(() => {
3456
- init_keccak256();
3457
- init_toPrefixedMessage();
3458
- });
3459
-
3460
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/accounts/utils/signMessage.js
3461
- async function signMessage({ message, privateKey }) {
3462
- return await sign({ hash: hashMessage(message), privateKey, to: "hex" });
3463
- }
3464
- var init_signMessage = __esm(() => {
3465
- init_hashMessage();
3466
- init_sign();
3467
- });
3468
-
3469
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/constants/unit.js
3470
- var gweiUnits;
3471
- var init_unit = __esm(() => {
3472
- gweiUnits = {
3473
- ether: -9,
3474
- wei: 9
3475
- };
3476
- });
3477
-
3478
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/unit/formatUnits.js
3479
- function formatUnits(value, decimals) {
3480
- let display = value.toString();
3481
- const negative = display.startsWith("-");
3482
- if (negative)
3483
- display = display.slice(1);
3484
- display = display.padStart(decimals, "0");
3485
- let [integer, fraction] = [
3486
- display.slice(0, display.length - decimals),
3487
- display.slice(display.length - decimals)
3488
- ];
3489
- fraction = fraction.replace(/(0+)$/, "");
3490
- return `${negative ? "-" : ""}${integer || "0"}${fraction ? `.${fraction}` : ""}`;
3491
- }
3492
-
3493
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/unit/formatGwei.js
3494
- function formatGwei(wei, unit = "wei") {
3495
- return formatUnits(wei, gweiUnits[unit]);
3496
- }
3497
- var init_formatGwei = __esm(() => {
3498
- init_unit();
3499
- });
3500
-
3501
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/errors/transaction.js
3502
- function prettyPrint(args) {
3503
- const entries = Object.entries(args).map(([key, value]) => {
3504
- if (value === undefined || value === false)
3505
- return null;
3506
- return [key, value];
3507
- }).filter(Boolean);
3508
- const maxLength = entries.reduce((acc, [key]) => Math.max(acc, key.length), 0);
3509
- return entries.map(([key, value]) => ` ${`${key}:`.padEnd(maxLength + 1)} ${value}`).join(`
3510
- `);
3511
- }
3512
- var InvalidLegacyVError, InvalidSerializableTransactionError, InvalidStorageKeySizeError;
3513
- var init_transaction = __esm(() => {
3514
- init_base();
3515
- InvalidLegacyVError = class InvalidLegacyVError extends BaseError {
3516
- constructor({ v }) {
3517
- super(`Invalid \`v\` value "${v}". Expected 27 or 28.`, {
3518
- name: "InvalidLegacyVError"
3519
- });
3520
- }
3521
- };
3522
- InvalidSerializableTransactionError = class InvalidSerializableTransactionError extends BaseError {
3523
- constructor({ transaction }) {
3524
- super("Cannot infer a transaction type from provided transaction.", {
3525
- metaMessages: [
3526
- "Provided Transaction:",
3527
- "{",
3528
- prettyPrint(transaction),
3529
- "}",
3530
- "",
3531
- "To infer the type, either provide:",
3532
- "- a `type` to the Transaction, or",
3533
- "- an EIP-1559 Transaction with `maxFeePerGas`, or",
3534
- "- an EIP-2930 Transaction with `gasPrice` & `accessList`, or",
3535
- "- an EIP-4844 Transaction with `blobs`, `blobVersionedHashes`, `sidecars`, or",
3536
- "- an EIP-7702 Transaction with `authorizationList`, or",
3537
- "- a Legacy Transaction with `gasPrice`"
3538
- ],
3539
- name: "InvalidSerializableTransactionError"
3540
- });
3541
- }
3542
- };
3543
- InvalidStorageKeySizeError = class InvalidStorageKeySizeError extends BaseError {
3544
- constructor({ storageKey }) {
3545
- super(`Size for storage key "${storageKey}" is invalid. Expected 32 bytes. Got ${Math.floor((storageKey.length - 2) / 2)} bytes.`, { name: "InvalidStorageKeySizeError" });
3546
- }
3547
- };
3548
- });
3549
-
3550
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/authorization/serializeAuthorizationList.js
3551
- function serializeAuthorizationList(authorizationList) {
3552
- if (!authorizationList || authorizationList.length === 0)
3553
- return [];
3554
- const serializedAuthorizationList = [];
3555
- for (const authorization of authorizationList) {
3556
- const { chainId, nonce, ...signature } = authorization;
3557
- const contractAddress = authorization.address;
3558
- serializedAuthorizationList.push([
3559
- chainId ? toHex(chainId) : "0x",
3560
- contractAddress,
3561
- nonce ? toHex(nonce) : "0x",
3562
- ...toYParitySignatureArray({}, signature)
3563
- ]);
3564
- }
3565
- return serializedAuthorizationList;
3566
- }
3567
- var init_serializeAuthorizationList = __esm(() => {
3568
- init_toHex();
3569
- init_serializeTransaction();
3570
- });
3571
-
3572
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/blob/blobsToCommitments.js
3573
- function blobsToCommitments(parameters) {
3574
- const { kzg } = parameters;
3575
- const to = parameters.to ?? (typeof parameters.blobs[0] === "string" ? "hex" : "bytes");
3576
- const blobs = typeof parameters.blobs[0] === "string" ? parameters.blobs.map((x) => hexToBytes2(x)) : parameters.blobs;
3577
- const commitments = [];
3578
- for (const blob of blobs)
3579
- commitments.push(Uint8Array.from(kzg.blobToKzgCommitment(blob)));
3580
- return to === "bytes" ? commitments : commitments.map((x) => bytesToHex2(x));
3581
- }
3582
- var init_blobsToCommitments = __esm(() => {
3583
- init_toBytes();
3584
- init_toHex();
3585
- });
3586
-
3587
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/blob/blobsToProofs.js
3588
- function blobsToProofs(parameters) {
3589
- const { kzg } = parameters;
3590
- const to = parameters.to ?? (typeof parameters.blobs[0] === "string" ? "hex" : "bytes");
3591
- const blobs = typeof parameters.blobs[0] === "string" ? parameters.blobs.map((x) => hexToBytes2(x)) : parameters.blobs;
3592
- const commitments = typeof parameters.commitments[0] === "string" ? parameters.commitments.map((x) => hexToBytes2(x)) : parameters.commitments;
3593
- const proofs = [];
3594
- for (let i = 0;i < blobs.length; i++) {
3595
- const blob = blobs[i];
3596
- const commitment = commitments[i];
3597
- proofs.push(Uint8Array.from(kzg.computeBlobKzgProof(blob, commitment)));
3598
- }
3599
- return to === "bytes" ? proofs : proofs.map((x) => bytesToHex2(x));
3600
- }
3601
- var init_blobsToProofs = __esm(() => {
3602
- init_toBytes();
3603
- init_toHex();
3604
- });
3605
-
3606
- // ../../node_modules/.bun/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/sha256.js
3607
- var sha2562;
3608
- var init_sha256 = __esm(() => {
3609
- init_sha2();
3610
- sha2562 = sha256;
3611
- });
3612
-
3613
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/hash/sha256.js
3614
- function sha2563(value, to_) {
3615
- const to = to_ || "hex";
3616
- const bytes = sha2562(isHex(value, { strict: false }) ? toBytes2(value) : value);
3617
- if (to === "bytes")
3618
- return bytes;
3619
- return toHex(bytes);
3620
- }
3621
- var init_sha2562 = __esm(() => {
3622
- init_sha256();
3623
- init_toBytes();
3624
- init_toHex();
3625
- });
3626
-
3627
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/blob/commitmentToVersionedHash.js
3628
- function commitmentToVersionedHash(parameters) {
3629
- const { commitment, version: version2 = 1 } = parameters;
3630
- const to = parameters.to ?? (typeof commitment === "string" ? "hex" : "bytes");
3631
- const versionedHash = sha2563(commitment, "bytes");
3632
- versionedHash.set([version2], 0);
3633
- return to === "bytes" ? versionedHash : bytesToHex2(versionedHash);
3634
- }
3635
- var init_commitmentToVersionedHash = __esm(() => {
3636
- init_toHex();
3637
- init_sha2562();
3638
- });
3639
-
3640
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/blob/commitmentsToVersionedHashes.js
3641
- function commitmentsToVersionedHashes(parameters) {
3642
- const { commitments, version: version2 } = parameters;
3643
- const to = parameters.to ?? (typeof commitments[0] === "string" ? "hex" : "bytes");
3644
- const hashes = [];
3645
- for (const commitment of commitments) {
3646
- hashes.push(commitmentToVersionedHash({
3647
- commitment,
3648
- to,
3649
- version: version2
3650
- }));
3651
- }
3652
- return hashes;
3653
- }
3654
- var init_commitmentsToVersionedHashes = __esm(() => {
3655
- init_commitmentToVersionedHash();
3656
- });
3657
-
3658
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/constants/blob.js
3659
- var blobsPerTransaction = 6, bytesPerFieldElement = 32, fieldElementsPerBlob = 4096, bytesPerBlob, maxBytesPerTransaction;
3660
- var init_blob = __esm(() => {
3661
- bytesPerBlob = bytesPerFieldElement * fieldElementsPerBlob;
3662
- maxBytesPerTransaction = bytesPerBlob * blobsPerTransaction - 1 - 1 * fieldElementsPerBlob * blobsPerTransaction;
3663
- });
3664
-
3665
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/constants/kzg.js
3666
- var versionedHashVersionKzg = 1;
3667
-
3668
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/errors/blob.js
3669
- var BlobSizeTooLargeError, EmptyBlobError, InvalidVersionedHashSizeError, InvalidVersionedHashVersionError;
3670
- var init_blob2 = __esm(() => {
3671
- init_base();
3672
- BlobSizeTooLargeError = class BlobSizeTooLargeError extends BaseError {
3673
- constructor({ maxSize, size: size2 }) {
3674
- super("Blob size is too large.", {
3675
- metaMessages: [`Max: ${maxSize} bytes`, `Given: ${size2} bytes`],
3676
- name: "BlobSizeTooLargeError"
3677
- });
3678
- }
3679
- };
3680
- EmptyBlobError = class EmptyBlobError extends BaseError {
3681
- constructor() {
3682
- super("Blob data must not be empty.", { name: "EmptyBlobError" });
3683
- }
3684
- };
3685
- InvalidVersionedHashSizeError = class InvalidVersionedHashSizeError extends BaseError {
3686
- constructor({ hash, size: size2 }) {
3687
- super(`Versioned hash "${hash}" size is invalid.`, {
3688
- metaMessages: ["Expected: 32", `Received: ${size2}`],
3689
- name: "InvalidVersionedHashSizeError"
3690
- });
3691
- }
3692
- };
3693
- InvalidVersionedHashVersionError = class InvalidVersionedHashVersionError extends BaseError {
3694
- constructor({ hash, version: version2 }) {
3695
- super(`Versioned hash "${hash}" version is invalid.`, {
3696
- metaMessages: [
3697
- `Expected: ${versionedHashVersionKzg}`,
3698
- `Received: ${version2}`
3699
- ],
3700
- name: "InvalidVersionedHashVersionError"
3701
- });
3702
- }
3703
- };
3704
- });
3705
-
3706
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/blob/toBlobs.js
3707
- function toBlobs(parameters) {
3708
- const to = parameters.to ?? (typeof parameters.data === "string" ? "hex" : "bytes");
3709
- const data = typeof parameters.data === "string" ? hexToBytes2(parameters.data) : parameters.data;
3710
- const size_ = size(data);
3711
- if (!size_)
3712
- throw new EmptyBlobError;
3713
- if (size_ > maxBytesPerTransaction)
3714
- throw new BlobSizeTooLargeError({
3715
- maxSize: maxBytesPerTransaction,
3716
- size: size_
3717
- });
3718
- const blobs = [];
3719
- let active = true;
3720
- let position = 0;
3721
- while (active) {
3722
- const blob = createCursor(new Uint8Array(bytesPerBlob));
3723
- let size2 = 0;
3724
- while (size2 < fieldElementsPerBlob) {
3725
- const bytes = data.slice(position, position + (bytesPerFieldElement - 1));
3726
- blob.pushByte(0);
3727
- blob.pushBytes(bytes);
3728
- if (bytes.length < 31) {
3729
- blob.pushByte(128);
3730
- active = false;
3731
- break;
3732
- }
3733
- size2++;
3734
- position += 31;
3735
- }
3736
- blobs.push(blob);
3737
- }
3738
- return to === "bytes" ? blobs.map((x) => x.bytes) : blobs.map((x) => bytesToHex2(x.bytes));
3739
- }
3740
- var init_toBlobs = __esm(() => {
3741
- init_blob();
3742
- init_blob2();
3743
- init_cursor2();
3744
- init_size();
3745
- init_toBytes();
3746
- init_toHex();
3747
- });
3748
-
3749
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/blob/toBlobSidecars.js
3750
- function toBlobSidecars(parameters) {
3751
- const { data, kzg, to } = parameters;
3752
- const blobs = parameters.blobs ?? toBlobs({ data, to });
3753
- const commitments = parameters.commitments ?? blobsToCommitments({ blobs, kzg, to });
3754
- const proofs = parameters.proofs ?? blobsToProofs({ blobs, commitments, kzg, to });
3755
- const sidecars = [];
3756
- for (let i = 0;i < blobs.length; i++)
3757
- sidecars.push({
3758
- blob: blobs[i],
3759
- commitment: commitments[i],
3760
- proof: proofs[i]
3761
- });
3762
- return sidecars;
3763
- }
3764
- var init_toBlobSidecars = __esm(() => {
3765
- init_blobsToCommitments();
3766
- init_blobsToProofs();
3767
- init_toBlobs();
3768
- });
3769
-
3770
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/constants/number.js
3771
- var maxInt8, maxInt16, maxInt24, maxInt32, maxInt40, maxInt48, maxInt56, maxInt64, maxInt72, maxInt80, maxInt88, maxInt96, maxInt104, maxInt112, maxInt120, maxInt128, maxInt136, maxInt144, maxInt152, maxInt160, maxInt168, maxInt176, maxInt184, maxInt192, maxInt200, maxInt208, maxInt216, maxInt224, maxInt232, maxInt240, maxInt248, maxInt256, minInt8, minInt16, minInt24, minInt32, minInt40, minInt48, minInt56, minInt64, minInt72, minInt80, minInt88, minInt96, minInt104, minInt112, minInt120, minInt128, minInt136, minInt144, minInt152, minInt160, minInt168, minInt176, minInt184, minInt192, minInt200, minInt208, minInt216, minInt224, minInt232, minInt240, minInt248, minInt256, maxUint8, maxUint16, maxUint24, maxUint32, maxUint40, maxUint48, maxUint56, maxUint64, maxUint72, maxUint80, maxUint88, maxUint96, maxUint104, maxUint112, maxUint120, maxUint128, maxUint136, maxUint144, maxUint152, maxUint160, maxUint168, maxUint176, maxUint184, maxUint192, maxUint200, maxUint208, maxUint216, maxUint224, maxUint232, maxUint240, maxUint248, maxUint256;
3772
- var init_number = __esm(() => {
3773
- maxInt8 = 2n ** (8n - 1n) - 1n;
3774
- maxInt16 = 2n ** (16n - 1n) - 1n;
3775
- maxInt24 = 2n ** (24n - 1n) - 1n;
3776
- maxInt32 = 2n ** (32n - 1n) - 1n;
3777
- maxInt40 = 2n ** (40n - 1n) - 1n;
3778
- maxInt48 = 2n ** (48n - 1n) - 1n;
3779
- maxInt56 = 2n ** (56n - 1n) - 1n;
3780
- maxInt64 = 2n ** (64n - 1n) - 1n;
3781
- maxInt72 = 2n ** (72n - 1n) - 1n;
3782
- maxInt80 = 2n ** (80n - 1n) - 1n;
3783
- maxInt88 = 2n ** (88n - 1n) - 1n;
3784
- maxInt96 = 2n ** (96n - 1n) - 1n;
3785
- maxInt104 = 2n ** (104n - 1n) - 1n;
3786
- maxInt112 = 2n ** (112n - 1n) - 1n;
3787
- maxInt120 = 2n ** (120n - 1n) - 1n;
3788
- maxInt128 = 2n ** (128n - 1n) - 1n;
3789
- maxInt136 = 2n ** (136n - 1n) - 1n;
3790
- maxInt144 = 2n ** (144n - 1n) - 1n;
3791
- maxInt152 = 2n ** (152n - 1n) - 1n;
3792
- maxInt160 = 2n ** (160n - 1n) - 1n;
3793
- maxInt168 = 2n ** (168n - 1n) - 1n;
3794
- maxInt176 = 2n ** (176n - 1n) - 1n;
3795
- maxInt184 = 2n ** (184n - 1n) - 1n;
3796
- maxInt192 = 2n ** (192n - 1n) - 1n;
3797
- maxInt200 = 2n ** (200n - 1n) - 1n;
3798
- maxInt208 = 2n ** (208n - 1n) - 1n;
3799
- maxInt216 = 2n ** (216n - 1n) - 1n;
3800
- maxInt224 = 2n ** (224n - 1n) - 1n;
3801
- maxInt232 = 2n ** (232n - 1n) - 1n;
3802
- maxInt240 = 2n ** (240n - 1n) - 1n;
3803
- maxInt248 = 2n ** (248n - 1n) - 1n;
3804
- maxInt256 = 2n ** (256n - 1n) - 1n;
3805
- minInt8 = -(2n ** (8n - 1n));
3806
- minInt16 = -(2n ** (16n - 1n));
3807
- minInt24 = -(2n ** (24n - 1n));
3808
- minInt32 = -(2n ** (32n - 1n));
3809
- minInt40 = -(2n ** (40n - 1n));
3810
- minInt48 = -(2n ** (48n - 1n));
3811
- minInt56 = -(2n ** (56n - 1n));
3812
- minInt64 = -(2n ** (64n - 1n));
3813
- minInt72 = -(2n ** (72n - 1n));
3814
- minInt80 = -(2n ** (80n - 1n));
3815
- minInt88 = -(2n ** (88n - 1n));
3816
- minInt96 = -(2n ** (96n - 1n));
3817
- minInt104 = -(2n ** (104n - 1n));
3818
- minInt112 = -(2n ** (112n - 1n));
3819
- minInt120 = -(2n ** (120n - 1n));
3820
- minInt128 = -(2n ** (128n - 1n));
3821
- minInt136 = -(2n ** (136n - 1n));
3822
- minInt144 = -(2n ** (144n - 1n));
3823
- minInt152 = -(2n ** (152n - 1n));
3824
- minInt160 = -(2n ** (160n - 1n));
3825
- minInt168 = -(2n ** (168n - 1n));
3826
- minInt176 = -(2n ** (176n - 1n));
3827
- minInt184 = -(2n ** (184n - 1n));
3828
- minInt192 = -(2n ** (192n - 1n));
3829
- minInt200 = -(2n ** (200n - 1n));
3830
- minInt208 = -(2n ** (208n - 1n));
3831
- minInt216 = -(2n ** (216n - 1n));
3832
- minInt224 = -(2n ** (224n - 1n));
3833
- minInt232 = -(2n ** (232n - 1n));
3834
- minInt240 = -(2n ** (240n - 1n));
3835
- minInt248 = -(2n ** (248n - 1n));
3836
- minInt256 = -(2n ** (256n - 1n));
3837
- maxUint8 = 2n ** 8n - 1n;
3838
- maxUint16 = 2n ** 16n - 1n;
3839
- maxUint24 = 2n ** 24n - 1n;
3840
- maxUint32 = 2n ** 32n - 1n;
3841
- maxUint40 = 2n ** 40n - 1n;
3842
- maxUint48 = 2n ** 48n - 1n;
3843
- maxUint56 = 2n ** 56n - 1n;
3844
- maxUint64 = 2n ** 64n - 1n;
3845
- maxUint72 = 2n ** 72n - 1n;
3846
- maxUint80 = 2n ** 80n - 1n;
3847
- maxUint88 = 2n ** 88n - 1n;
3848
- maxUint96 = 2n ** 96n - 1n;
3849
- maxUint104 = 2n ** 104n - 1n;
3850
- maxUint112 = 2n ** 112n - 1n;
3851
- maxUint120 = 2n ** 120n - 1n;
3852
- maxUint128 = 2n ** 128n - 1n;
3853
- maxUint136 = 2n ** 136n - 1n;
3854
- maxUint144 = 2n ** 144n - 1n;
3855
- maxUint152 = 2n ** 152n - 1n;
3856
- maxUint160 = 2n ** 160n - 1n;
3857
- maxUint168 = 2n ** 168n - 1n;
3858
- maxUint176 = 2n ** 176n - 1n;
3859
- maxUint184 = 2n ** 184n - 1n;
3860
- maxUint192 = 2n ** 192n - 1n;
3861
- maxUint200 = 2n ** 200n - 1n;
3862
- maxUint208 = 2n ** 208n - 1n;
3863
- maxUint216 = 2n ** 216n - 1n;
3864
- maxUint224 = 2n ** 224n - 1n;
3865
- maxUint232 = 2n ** 232n - 1n;
3866
- maxUint240 = 2n ** 240n - 1n;
3867
- maxUint248 = 2n ** 248n - 1n;
3868
- maxUint256 = 2n ** 256n - 1n;
3869
- });
3870
-
3871
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/errors/chain.js
3872
- var InvalidChainIdError;
3873
- var init_chain = __esm(() => {
3874
- init_base();
3875
- InvalidChainIdError = class InvalidChainIdError extends BaseError {
3876
- constructor({ chainId }) {
3877
- super(typeof chainId === "number" ? `Chain ID "${chainId}" is invalid.` : "Chain ID is invalid.", { name: "InvalidChainIdError" });
3878
- }
3879
- };
3880
- });
3881
-
3882
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/errors/node.js
3883
- var ExecutionRevertedError, FeeCapTooHighError, FeeCapTooLowError, NonceTooHighError, NonceTooLowError, NonceMaxValueError, InsufficientFundsError, IntrinsicGasTooHighError, IntrinsicGasTooLowError, TransactionTypeNotSupportedError, TipAboveFeeCapError;
3884
- var init_node = __esm(() => {
3885
- init_formatGwei();
3886
- init_base();
3887
- ExecutionRevertedError = class ExecutionRevertedError extends BaseError {
3888
- constructor({ cause, message } = {}) {
3889
- const reason = message?.replace("execution reverted: ", "")?.replace("execution reverted", "");
3890
- super(`Execution reverted ${reason ? `with reason: ${reason}` : "for an unknown reason"}.`, {
3891
- cause,
3892
- name: "ExecutionRevertedError"
3893
- });
3894
- }
3895
- };
3896
- Object.defineProperty(ExecutionRevertedError, "code", {
3897
- enumerable: true,
3898
- configurable: true,
3899
- writable: true,
3900
- value: 3
3901
- });
3902
- Object.defineProperty(ExecutionRevertedError, "nodeMessage", {
3903
- enumerable: true,
3904
- configurable: true,
3905
- writable: true,
3906
- value: /execution reverted|gas required exceeds allowance/
3907
- });
3908
- FeeCapTooHighError = class FeeCapTooHighError extends BaseError {
3909
- constructor({ cause, maxFeePerGas } = {}) {
3910
- super(`The fee cap (\`maxFeePerGas\`${maxFeePerGas ? ` = ${formatGwei(maxFeePerGas)} gwei` : ""}) cannot be higher than the maximum allowed value (2^256-1).`, {
3911
- cause,
3912
- name: "FeeCapTooHighError"
3913
- });
3914
- }
3915
- };
3916
- Object.defineProperty(FeeCapTooHighError, "nodeMessage", {
3917
- enumerable: true,
3918
- configurable: true,
3919
- writable: true,
3920
- value: /max fee per gas higher than 2\^256-1|fee cap higher than 2\^256-1/
3921
- });
3922
- FeeCapTooLowError = class FeeCapTooLowError extends BaseError {
3923
- constructor({ cause, maxFeePerGas } = {}) {
3924
- super(`The fee cap (\`maxFeePerGas\`${maxFeePerGas ? ` = ${formatGwei(maxFeePerGas)}` : ""} gwei) cannot be lower than the block base fee.`, {
3925
- cause,
3926
- name: "FeeCapTooLowError"
3927
- });
3928
- }
3929
- };
3930
- Object.defineProperty(FeeCapTooLowError, "nodeMessage", {
3931
- enumerable: true,
3932
- configurable: true,
3933
- writable: true,
3934
- value: /max fee per gas less than block base fee|fee cap less than block base fee|transaction is outdated/
3935
- });
3936
- NonceTooHighError = class NonceTooHighError extends BaseError {
3937
- constructor({ cause, nonce } = {}) {
3938
- super(`Nonce provided for the transaction ${nonce ? `(${nonce}) ` : ""}is higher than the next one expected.`, { cause, name: "NonceTooHighError" });
3939
- }
3940
- };
3941
- Object.defineProperty(NonceTooHighError, "nodeMessage", {
3942
- enumerable: true,
3943
- configurable: true,
3944
- writable: true,
3945
- value: /nonce too high/
3946
- });
3947
- NonceTooLowError = class NonceTooLowError extends BaseError {
3948
- constructor({ cause, nonce } = {}) {
3949
- super([
3950
- `Nonce provided for the transaction ${nonce ? `(${nonce}) ` : ""}is lower than the current nonce of the account.`,
3951
- "Try increasing the nonce or find the latest nonce with `getTransactionCount`."
3952
- ].join(`
3953
- `), { cause, name: "NonceTooLowError" });
3954
- }
3955
- };
3956
- Object.defineProperty(NonceTooLowError, "nodeMessage", {
3957
- enumerable: true,
3958
- configurable: true,
3959
- writable: true,
3960
- value: /nonce too low|transaction already imported|already known/
3961
- });
3962
- NonceMaxValueError = class NonceMaxValueError extends BaseError {
3963
- constructor({ cause, nonce } = {}) {
3964
- super(`Nonce provided for the transaction ${nonce ? `(${nonce}) ` : ""}exceeds the maximum allowed nonce.`, { cause, name: "NonceMaxValueError" });
3965
- }
3966
- };
3967
- Object.defineProperty(NonceMaxValueError, "nodeMessage", {
3968
- enumerable: true,
3969
- configurable: true,
3970
- writable: true,
3971
- value: /nonce has max value/
3972
- });
3973
- InsufficientFundsError = class InsufficientFundsError extends BaseError {
3974
- constructor({ cause } = {}) {
3975
- super([
3976
- "The total cost (gas * gas fee + value) of executing this transaction exceeds the balance of the account."
3977
- ].join(`
3978
- `), {
3979
- cause,
3980
- metaMessages: [
3981
- "This error could arise when the account does not have enough funds to:",
3982
- " - pay for the total gas fee,",
3983
- " - pay for the value to send.",
3984
- " ",
3985
- "The cost of the transaction is calculated as `gas * gas fee + value`, where:",
3986
- " - `gas` is the amount of gas needed for transaction to execute,",
3987
- " - `gas fee` is the gas fee,",
3988
- " - `value` is the amount of ether to send to the recipient."
3989
- ],
3990
- name: "InsufficientFundsError"
3991
- });
3992
- }
3993
- };
3994
- Object.defineProperty(InsufficientFundsError, "nodeMessage", {
3995
- enumerable: true,
3996
- configurable: true,
3997
- writable: true,
3998
- value: /insufficient funds|exceeds transaction sender account balance/
3999
- });
4000
- IntrinsicGasTooHighError = class IntrinsicGasTooHighError extends BaseError {
4001
- constructor({ cause, gas } = {}) {
4002
- super(`The amount of gas ${gas ? `(${gas}) ` : ""}provided for the transaction exceeds the limit allowed for the block.`, {
4003
- cause,
4004
- name: "IntrinsicGasTooHighError"
4005
- });
4006
- }
4007
- };
4008
- Object.defineProperty(IntrinsicGasTooHighError, "nodeMessage", {
4009
- enumerable: true,
4010
- configurable: true,
4011
- writable: true,
4012
- value: /intrinsic gas too high|gas limit reached/
4013
- });
4014
- IntrinsicGasTooLowError = class IntrinsicGasTooLowError extends BaseError {
4015
- constructor({ cause, gas } = {}) {
4016
- super(`The amount of gas ${gas ? `(${gas}) ` : ""}provided for the transaction is too low.`, {
4017
- cause,
4018
- name: "IntrinsicGasTooLowError"
4019
- });
4020
- }
4021
- };
4022
- Object.defineProperty(IntrinsicGasTooLowError, "nodeMessage", {
4023
- enumerable: true,
4024
- configurable: true,
4025
- writable: true,
4026
- value: /intrinsic gas too low/
4027
- });
4028
- TransactionTypeNotSupportedError = class TransactionTypeNotSupportedError extends BaseError {
4029
- constructor({ cause }) {
4030
- super("The transaction type is not supported for this chain.", {
4031
- cause,
4032
- name: "TransactionTypeNotSupportedError"
4033
- });
4034
- }
4035
- };
4036
- Object.defineProperty(TransactionTypeNotSupportedError, "nodeMessage", {
4037
- enumerable: true,
4038
- configurable: true,
4039
- writable: true,
4040
- value: /transaction type not valid/
4041
- });
4042
- TipAboveFeeCapError = class TipAboveFeeCapError extends BaseError {
4043
- constructor({ cause, maxPriorityFeePerGas, maxFeePerGas } = {}) {
4044
- super([
4045
- `The provided tip (\`maxPriorityFeePerGas\`${maxPriorityFeePerGas ? ` = ${formatGwei(maxPriorityFeePerGas)} gwei` : ""}) cannot be higher than the fee cap (\`maxFeePerGas\`${maxFeePerGas ? ` = ${formatGwei(maxFeePerGas)} gwei` : ""}).`
4046
- ].join(`
4047
- `), {
4048
- cause,
4049
- name: "TipAboveFeeCapError"
4050
- });
4051
- }
4052
- };
4053
- Object.defineProperty(TipAboveFeeCapError, "nodeMessage", {
4054
- enumerable: true,
4055
- configurable: true,
4056
- writable: true,
4057
- value: /max priority fee per gas higher than max fee per gas|tip higher than fee cap/
4058
- });
4059
- });
4060
-
4061
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/data/slice.js
4062
- function slice(value, start, end, { strict } = {}) {
4063
- if (isHex(value, { strict: false }))
4064
- return sliceHex(value, start, end, {
4065
- strict
4066
- });
4067
- return sliceBytes(value, start, end, {
4068
- strict
4069
- });
4070
- }
4071
- function assertStartOffset(value, start) {
4072
- if (typeof start === "number" && start > 0 && start > size(value) - 1)
4073
- throw new SliceOffsetOutOfBoundsError({
4074
- offset: start,
4075
- position: "start",
4076
- size: size(value)
4077
- });
4078
- }
4079
- function assertEndOffset(value, start, end) {
4080
- if (typeof start === "number" && typeof end === "number" && size(value) !== end - start) {
4081
- throw new SliceOffsetOutOfBoundsError({
4082
- offset: end,
4083
- position: "end",
4084
- size: size(value)
4085
- });
4086
- }
4087
- }
4088
- function sliceBytes(value_, start, end, { strict } = {}) {
4089
- assertStartOffset(value_, start);
4090
- const value = value_.slice(start, end);
4091
- if (strict)
4092
- assertEndOffset(value, start, end);
4093
- return value;
4094
- }
4095
- function sliceHex(value_, start, end, { strict } = {}) {
4096
- assertStartOffset(value_, start);
4097
- const value = `0x${value_.replace("0x", "").slice((start ?? 0) * 2, (end ?? value_.length) * 2)}`;
4098
- if (strict)
4099
- assertEndOffset(value, start, end);
4100
- return value;
4101
- }
4102
- var init_slice = __esm(() => {
4103
- init_data();
4104
- init_size();
4105
- });
4106
-
4107
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/transaction/assertTransaction.js
4108
- function assertTransactionEIP7702(transaction) {
4109
- const { authorizationList } = transaction;
4110
- if (authorizationList) {
4111
- for (const authorization of authorizationList) {
4112
- const { chainId } = authorization;
4113
- const address = authorization.address;
4114
- if (!isAddress(address))
4115
- throw new InvalidAddressError({ address });
4116
- if (chainId < 0)
4117
- throw new InvalidChainIdError({ chainId });
4118
- }
4119
- }
4120
- assertTransactionEIP1559(transaction);
4121
- }
4122
- function assertTransactionEIP4844(transaction) {
4123
- const { blobVersionedHashes } = transaction;
4124
- if (blobVersionedHashes) {
4125
- if (blobVersionedHashes.length === 0)
4126
- throw new EmptyBlobError;
4127
- for (const hash of blobVersionedHashes) {
4128
- const size_ = size(hash);
4129
- const version2 = hexToNumber2(slice(hash, 0, 1));
4130
- if (size_ !== 32)
4131
- throw new InvalidVersionedHashSizeError({ hash, size: size_ });
4132
- if (version2 !== versionedHashVersionKzg)
4133
- throw new InvalidVersionedHashVersionError({
4134
- hash,
4135
- version: version2
4136
- });
4137
- }
4138
- }
4139
- assertTransactionEIP1559(transaction);
4140
- }
4141
- function assertTransactionEIP1559(transaction) {
4142
- const { chainId, maxPriorityFeePerGas, maxFeePerGas, to } = transaction;
4143
- if (chainId <= 0)
4144
- throw new InvalidChainIdError({ chainId });
4145
- if (to && !isAddress(to))
4146
- throw new InvalidAddressError({ address: to });
4147
- if (maxFeePerGas && maxFeePerGas > maxUint256)
4148
- throw new FeeCapTooHighError({ maxFeePerGas });
4149
- if (maxPriorityFeePerGas && maxFeePerGas && maxPriorityFeePerGas > maxFeePerGas)
4150
- throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas });
4151
- }
4152
- function assertTransactionEIP2930(transaction) {
4153
- const { chainId, maxPriorityFeePerGas, gasPrice, maxFeePerGas, to } = transaction;
4154
- if (chainId <= 0)
4155
- throw new InvalidChainIdError({ chainId });
4156
- if (to && !isAddress(to))
4157
- throw new InvalidAddressError({ address: to });
4158
- if (maxPriorityFeePerGas || maxFeePerGas)
4159
- throw new BaseError("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.");
4160
- if (gasPrice && gasPrice > maxUint256)
4161
- throw new FeeCapTooHighError({ maxFeePerGas: gasPrice });
4162
- }
4163
- function assertTransactionLegacy(transaction) {
4164
- const { chainId, maxPriorityFeePerGas, gasPrice, maxFeePerGas, to } = transaction;
4165
- if (to && !isAddress(to))
4166
- throw new InvalidAddressError({ address: to });
4167
- if (typeof chainId !== "undefined" && chainId <= 0)
4168
- throw new InvalidChainIdError({ chainId });
4169
- if (maxPriorityFeePerGas || maxFeePerGas)
4170
- throw new BaseError("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.");
4171
- if (gasPrice && gasPrice > maxUint256)
4172
- throw new FeeCapTooHighError({ maxFeePerGas: gasPrice });
4173
- }
4174
- var init_assertTransaction = __esm(() => {
4175
- init_number();
4176
- init_address();
4177
- init_base();
4178
- init_blob2();
4179
- init_chain();
4180
- init_node();
4181
- init_isAddress();
4182
- init_size();
4183
- init_slice();
4184
- init_fromHex();
4185
- });
4186
-
4187
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/transaction/getTransactionType.js
4188
- function getTransactionType(transaction) {
4189
- if (transaction.type)
4190
- return transaction.type;
4191
- if (typeof transaction.authorizationList !== "undefined")
4192
- return "eip7702";
4193
- if (typeof transaction.blobs !== "undefined" || typeof transaction.blobVersionedHashes !== "undefined" || typeof transaction.maxFeePerBlobGas !== "undefined" || typeof transaction.sidecars !== "undefined")
4194
- return "eip4844";
4195
- if (typeof transaction.maxFeePerGas !== "undefined" || typeof transaction.maxPriorityFeePerGas !== "undefined") {
4196
- return "eip1559";
4197
- }
4198
- if (typeof transaction.gasPrice !== "undefined") {
4199
- if (typeof transaction.accessList !== "undefined")
4200
- return "eip2930";
4201
- return "legacy";
4202
- }
4203
- throw new InvalidSerializableTransactionError({ transaction });
4204
- }
4205
- var init_getTransactionType = __esm(() => {
4206
- init_transaction();
4207
- });
4208
-
4209
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/transaction/serializeAccessList.js
4210
- function serializeAccessList(accessList) {
4211
- if (!accessList || accessList.length === 0)
4212
- return [];
4213
- const serializedAccessList = [];
4214
- for (let i = 0;i < accessList.length; i++) {
4215
- const { address, storageKeys } = accessList[i];
4216
- for (let j = 0;j < storageKeys.length; j++) {
4217
- if (storageKeys[j].length - 2 !== 64) {
4218
- throw new InvalidStorageKeySizeError({ storageKey: storageKeys[j] });
4219
- }
4220
- }
4221
- if (!isAddress(address, { strict: false })) {
4222
- throw new InvalidAddressError({ address });
4223
- }
4224
- serializedAccessList.push([address, storageKeys]);
4225
- }
4226
- return serializedAccessList;
4227
- }
4228
- var init_serializeAccessList = __esm(() => {
4229
- init_address();
4230
- init_transaction();
4231
- init_isAddress();
4232
- });
4233
-
4234
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/transaction/serializeTransaction.js
4235
- function serializeTransaction(transaction, signature) {
4236
- const type = getTransactionType(transaction);
4237
- if (type === "eip1559")
4238
- return serializeTransactionEIP1559(transaction, signature);
4239
- if (type === "eip2930")
4240
- return serializeTransactionEIP2930(transaction, signature);
4241
- if (type === "eip4844")
4242
- return serializeTransactionEIP4844(transaction, signature);
4243
- if (type === "eip7702")
4244
- return serializeTransactionEIP7702(transaction, signature);
4245
- return serializeTransactionLegacy(transaction, signature);
4246
- }
4247
- function serializeTransactionEIP7702(transaction, signature) {
4248
- const { authorizationList, chainId, gas, nonce, to, value, maxFeePerGas, maxPriorityFeePerGas, accessList, data } = transaction;
4249
- assertTransactionEIP7702(transaction);
4250
- const serializedAccessList = serializeAccessList(accessList);
4251
- const serializedAuthorizationList = serializeAuthorizationList(authorizationList);
4252
- return concatHex([
4253
- "0x04",
4254
- toRlp([
4255
- numberToHex(chainId),
4256
- nonce ? numberToHex(nonce) : "0x",
4257
- maxPriorityFeePerGas ? numberToHex(maxPriorityFeePerGas) : "0x",
4258
- maxFeePerGas ? numberToHex(maxFeePerGas) : "0x",
4259
- gas ? numberToHex(gas) : "0x",
4260
- to ?? "0x",
4261
- value ? numberToHex(value) : "0x",
4262
- data ?? "0x",
4263
- serializedAccessList,
4264
- serializedAuthorizationList,
4265
- ...toYParitySignatureArray(transaction, signature)
4266
- ])
4267
- ]);
4268
- }
4269
- function serializeTransactionEIP4844(transaction, signature) {
4270
- const { chainId, gas, nonce, to, value, maxFeePerBlobGas, maxFeePerGas, maxPriorityFeePerGas, accessList, data } = transaction;
4271
- assertTransactionEIP4844(transaction);
4272
- let blobVersionedHashes = transaction.blobVersionedHashes;
4273
- let sidecars = transaction.sidecars;
4274
- if (transaction.blobs && (typeof blobVersionedHashes === "undefined" || typeof sidecars === "undefined")) {
4275
- const blobs2 = typeof transaction.blobs[0] === "string" ? transaction.blobs : transaction.blobs.map((x) => bytesToHex2(x));
4276
- const kzg = transaction.kzg;
4277
- const commitments2 = blobsToCommitments({
4278
- blobs: blobs2,
4279
- kzg
4280
- });
4281
- if (typeof blobVersionedHashes === "undefined")
4282
- blobVersionedHashes = commitmentsToVersionedHashes({
4283
- commitments: commitments2
4284
- });
4285
- if (typeof sidecars === "undefined") {
4286
- const proofs2 = blobsToProofs({ blobs: blobs2, commitments: commitments2, kzg });
4287
- sidecars = toBlobSidecars({ blobs: blobs2, commitments: commitments2, proofs: proofs2 });
4288
- }
4289
- }
4290
- const serializedAccessList = serializeAccessList(accessList);
4291
- const serializedTransaction = [
4292
- numberToHex(chainId),
4293
- nonce ? numberToHex(nonce) : "0x",
4294
- maxPriorityFeePerGas ? numberToHex(maxPriorityFeePerGas) : "0x",
4295
- maxFeePerGas ? numberToHex(maxFeePerGas) : "0x",
4296
- gas ? numberToHex(gas) : "0x",
4297
- to ?? "0x",
4298
- value ? numberToHex(value) : "0x",
4299
- data ?? "0x",
4300
- serializedAccessList,
4301
- maxFeePerBlobGas ? numberToHex(maxFeePerBlobGas) : "0x",
4302
- blobVersionedHashes ?? [],
4303
- ...toYParitySignatureArray(transaction, signature)
4304
- ];
4305
- const blobs = [];
4306
- const commitments = [];
4307
- const proofs = [];
4308
- if (sidecars)
4309
- for (let i = 0;i < sidecars.length; i++) {
4310
- const { blob, commitment, proof } = sidecars[i];
4311
- blobs.push(blob);
4312
- commitments.push(commitment);
4313
- proofs.push(proof);
4314
- }
4315
- return concatHex([
4316
- "0x03",
4317
- sidecars ? toRlp([serializedTransaction, blobs, commitments, proofs]) : toRlp(serializedTransaction)
4318
- ]);
4319
- }
4320
- function serializeTransactionEIP1559(transaction, signature) {
4321
- const { chainId, gas, nonce, to, value, maxFeePerGas, maxPriorityFeePerGas, accessList, data } = transaction;
4322
- assertTransactionEIP1559(transaction);
4323
- const serializedAccessList = serializeAccessList(accessList);
4324
- const serializedTransaction = [
4325
- numberToHex(chainId),
4326
- nonce ? numberToHex(nonce) : "0x",
4327
- maxPriorityFeePerGas ? numberToHex(maxPriorityFeePerGas) : "0x",
4328
- maxFeePerGas ? numberToHex(maxFeePerGas) : "0x",
4329
- gas ? numberToHex(gas) : "0x",
4330
- to ?? "0x",
4331
- value ? numberToHex(value) : "0x",
4332
- data ?? "0x",
4333
- serializedAccessList,
4334
- ...toYParitySignatureArray(transaction, signature)
4335
- ];
4336
- return concatHex([
4337
- "0x02",
4338
- toRlp(serializedTransaction)
4339
- ]);
4340
- }
4341
- function serializeTransactionEIP2930(transaction, signature) {
4342
- const { chainId, gas, data, nonce, to, value, accessList, gasPrice } = transaction;
4343
- assertTransactionEIP2930(transaction);
4344
- const serializedAccessList = serializeAccessList(accessList);
4345
- const serializedTransaction = [
4346
- numberToHex(chainId),
4347
- nonce ? numberToHex(nonce) : "0x",
4348
- gasPrice ? numberToHex(gasPrice) : "0x",
4349
- gas ? numberToHex(gas) : "0x",
4350
- to ?? "0x",
4351
- value ? numberToHex(value) : "0x",
4352
- data ?? "0x",
4353
- serializedAccessList,
4354
- ...toYParitySignatureArray(transaction, signature)
4355
- ];
4356
- return concatHex([
4357
- "0x01",
4358
- toRlp(serializedTransaction)
4359
- ]);
4360
- }
4361
- function serializeTransactionLegacy(transaction, signature) {
4362
- const { chainId = 0, gas, data, nonce, to, value, gasPrice } = transaction;
4363
- assertTransactionLegacy(transaction);
4364
- let serializedTransaction = [
4365
- nonce ? numberToHex(nonce) : "0x",
4366
- gasPrice ? numberToHex(gasPrice) : "0x",
4367
- gas ? numberToHex(gas) : "0x",
4368
- to ?? "0x",
4369
- value ? numberToHex(value) : "0x",
4370
- data ?? "0x"
4371
- ];
4372
- if (signature) {
4373
- const v = (() => {
4374
- if (signature.v >= 35n) {
4375
- const inferredChainId = (signature.v - 35n) / 2n;
4376
- if (inferredChainId > 0)
4377
- return signature.v;
4378
- return 27n + (signature.v === 35n ? 0n : 1n);
4379
- }
4380
- if (chainId > 0)
4381
- return BigInt(chainId * 2) + BigInt(35n + signature.v - 27n);
4382
- const v2 = 27n + (signature.v === 27n ? 0n : 1n);
4383
- if (signature.v !== v2)
4384
- throw new InvalidLegacyVError({ v: signature.v });
4385
- return v2;
4386
- })();
4387
- const r = trim(signature.r);
4388
- const s = trim(signature.s);
4389
- serializedTransaction = [
4390
- ...serializedTransaction,
4391
- numberToHex(v),
4392
- r === "0x00" ? "0x" : r,
4393
- s === "0x00" ? "0x" : s
4394
- ];
4395
- } else if (chainId > 0) {
4396
- serializedTransaction = [
4397
- ...serializedTransaction,
4398
- numberToHex(chainId),
4399
- "0x",
4400
- "0x"
4401
- ];
4402
- }
4403
- return toRlp(serializedTransaction);
4404
- }
4405
- function toYParitySignatureArray(transaction, signature_) {
4406
- const signature = signature_ ?? transaction;
4407
- const { v, yParity } = signature;
4408
- if (typeof signature.r === "undefined")
4409
- return [];
4410
- if (typeof signature.s === "undefined")
4411
- return [];
4412
- if (typeof v === "undefined" && typeof yParity === "undefined")
4413
- return [];
4414
- const r = trim(signature.r);
4415
- const s = trim(signature.s);
4416
- const yParity_ = (() => {
4417
- if (typeof yParity === "number")
4418
- return yParity ? numberToHex(1) : "0x";
4419
- if (v === 0n)
4420
- return "0x";
4421
- if (v === 1n)
4422
- return numberToHex(1);
4423
- return v === 27n ? "0x" : numberToHex(1);
4424
- })();
4425
- return [yParity_, r === "0x00" ? "0x" : r, s === "0x00" ? "0x" : s];
4426
- }
4427
- var init_serializeTransaction = __esm(() => {
4428
- init_transaction();
4429
- init_serializeAuthorizationList();
4430
- init_blobsToCommitments();
4431
- init_blobsToProofs();
4432
- init_commitmentsToVersionedHashes();
4433
- init_toBlobSidecars();
4434
- init_toHex();
4435
- init_toRlp();
4436
- init_assertTransaction();
4437
- init_getTransactionType();
4438
- init_serializeAccessList();
4439
- });
4440
-
4441
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/accounts/utils/signTransaction.js
4442
- async function signTransaction(parameters) {
4443
- const { privateKey, transaction, serializer = serializeTransaction } = parameters;
4444
- const signableTransaction = (() => {
4445
- if (transaction.type === "eip4844")
4446
- return {
4447
- ...transaction,
4448
- sidecars: false
4449
- };
4450
- return transaction;
4451
- })();
4452
- const signature = await sign({
4453
- hash: keccak256(await serializer(signableTransaction)),
4454
- privateKey
4455
- });
4456
- return await serializer(transaction, signature);
4457
- }
4458
- var init_signTransaction = __esm(() => {
4459
- init_keccak256();
4460
- init_serializeTransaction();
4461
- init_sign();
4462
- });
4463
-
4464
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/errors/abi.js
4465
- var AbiEncodingArrayLengthMismatchError, AbiEncodingBytesSizeMismatchError, AbiEncodingLengthMismatchError, BytesSizeMismatchError, InvalidAbiEncodingTypeError, InvalidArrayError;
4466
- var init_abi = __esm(() => {
4467
- init_size();
4468
- init_base();
4469
- AbiEncodingArrayLengthMismatchError = class AbiEncodingArrayLengthMismatchError extends BaseError {
4470
- constructor({ expectedLength, givenLength, type }) {
4471
- super([
4472
- `ABI encoding array length mismatch for type ${type}.`,
4473
- `Expected length: ${expectedLength}`,
4474
- `Given length: ${givenLength}`
4475
- ].join(`
4476
- `), { name: "AbiEncodingArrayLengthMismatchError" });
4477
- }
4478
- };
4479
- AbiEncodingBytesSizeMismatchError = class AbiEncodingBytesSizeMismatchError extends BaseError {
4480
- constructor({ expectedSize, value }) {
4481
- super(`Size of bytes "${value}" (bytes${size(value)}) does not match expected size (bytes${expectedSize}).`, { name: "AbiEncodingBytesSizeMismatchError" });
4482
- }
4483
- };
4484
- AbiEncodingLengthMismatchError = class AbiEncodingLengthMismatchError extends BaseError {
4485
- constructor({ expectedLength, givenLength }) {
4486
- super([
4487
- "ABI encoding params/values length mismatch.",
4488
- `Expected length (params): ${expectedLength}`,
4489
- `Given length (values): ${givenLength}`
4490
- ].join(`
4491
- `), { name: "AbiEncodingLengthMismatchError" });
4492
- }
4493
- };
4494
- BytesSizeMismatchError = class BytesSizeMismatchError extends BaseError {
4495
- constructor({ expectedSize, givenSize }) {
4496
- super(`Expected bytes${expectedSize}, got bytes${givenSize}.`, {
4497
- name: "BytesSizeMismatchError"
4498
- });
4499
- }
4500
- };
4501
- InvalidAbiEncodingTypeError = class InvalidAbiEncodingTypeError extends BaseError {
4502
- constructor(type, { docsPath }) {
4503
- super([
4504
- `Type "${type}" is not a valid encoding type.`,
4505
- "Please provide a valid ABI type."
4506
- ].join(`
4507
- `), { docsPath, name: "InvalidAbiEncodingType" });
4508
- }
4509
- };
4510
- InvalidArrayError = class InvalidArrayError extends BaseError {
4511
- constructor(value) {
4512
- super([`Value "${value}" is not a valid array.`].join(`
4513
- `), {
4514
- name: "InvalidArrayError"
4515
- });
4516
- }
4517
- };
4518
- });
4519
-
4520
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/regex.js
4521
- var bytesRegex, integerRegex;
4522
- var init_regex = __esm(() => {
4523
- bytesRegex = /^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/;
4524
- integerRegex = /^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/;
4525
- });
4526
-
4527
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/abi/encodeAbiParameters.js
4528
- function encodeAbiParameters(params, values) {
4529
- if (params.length !== values.length)
4530
- throw new AbiEncodingLengthMismatchError({
4531
- expectedLength: params.length,
4532
- givenLength: values.length
4533
- });
4534
- const preparedParams = prepareParams({
4535
- params,
4536
- values
4537
- });
4538
- const data = encodeParams(preparedParams);
4539
- if (data.length === 0)
4540
- return "0x";
4541
- return data;
4542
- }
4543
- function prepareParams({ params, values }) {
4544
- const preparedParams = [];
4545
- for (let i = 0;i < params.length; i++) {
4546
- preparedParams.push(prepareParam({ param: params[i], value: values[i] }));
4547
- }
4548
- return preparedParams;
4549
- }
4550
- function prepareParam({ param, value }) {
4551
- const arrayComponents = getArrayComponents(param.type);
4552
- if (arrayComponents) {
4553
- const [length, type] = arrayComponents;
4554
- return encodeArray(value, { length, param: { ...param, type } });
4555
- }
4556
- if (param.type === "tuple") {
4557
- return encodeTuple(value, {
4558
- param
4559
- });
4560
- }
4561
- if (param.type === "address") {
4562
- return encodeAddress(value);
4563
- }
4564
- if (param.type === "bool") {
4565
- return encodeBool(value);
4566
- }
4567
- if (param.type.startsWith("uint") || param.type.startsWith("int")) {
4568
- const signed = param.type.startsWith("int");
4569
- const [, , size2 = "256"] = integerRegex.exec(param.type) ?? [];
4570
- return encodeNumber(value, {
4571
- signed,
4572
- size: Number(size2)
4573
- });
4574
- }
4575
- if (param.type.startsWith("bytes")) {
4576
- return encodeBytes(value, { param });
4577
- }
4578
- if (param.type === "string") {
4579
- return encodeString(value);
4580
- }
4581
- throw new InvalidAbiEncodingTypeError(param.type, {
4582
- docsPath: "/docs/contract/encodeAbiParameters"
4583
- });
4584
- }
4585
- function encodeParams(preparedParams) {
4586
- let staticSize = 0;
4587
- for (let i = 0;i < preparedParams.length; i++) {
4588
- const { dynamic, encoded } = preparedParams[i];
4589
- if (dynamic)
4590
- staticSize += 32;
4591
- else
4592
- staticSize += size(encoded);
4593
- }
4594
- const staticParams = [];
4595
- const dynamicParams = [];
4596
- let dynamicSize = 0;
4597
- for (let i = 0;i < preparedParams.length; i++) {
4598
- const { dynamic, encoded } = preparedParams[i];
4599
- if (dynamic) {
4600
- staticParams.push(numberToHex(staticSize + dynamicSize, { size: 32 }));
4601
- dynamicParams.push(encoded);
4602
- dynamicSize += size(encoded);
4603
- } else {
4604
- staticParams.push(encoded);
4605
- }
4606
- }
4607
- return concat([...staticParams, ...dynamicParams]);
4608
- }
4609
- function encodeAddress(value) {
4610
- if (!isAddress(value))
4611
- throw new InvalidAddressError({ address: value });
4612
- return { dynamic: false, encoded: padHex(value.toLowerCase()) };
4613
- }
4614
- function encodeArray(value, { length, param }) {
4615
- const dynamic = length === null;
4616
- if (!Array.isArray(value))
4617
- throw new InvalidArrayError(value);
4618
- if (!dynamic && value.length !== length)
4619
- throw new AbiEncodingArrayLengthMismatchError({
4620
- expectedLength: length,
4621
- givenLength: value.length,
4622
- type: `${param.type}[${length}]`
4623
- });
4624
- let dynamicChild = false;
4625
- const preparedParams = [];
4626
- for (let i = 0;i < value.length; i++) {
4627
- const preparedParam = prepareParam({ param, value: value[i] });
4628
- if (preparedParam.dynamic)
4629
- dynamicChild = true;
4630
- preparedParams.push(preparedParam);
4631
- }
4632
- if (dynamic || dynamicChild) {
4633
- const data = encodeParams(preparedParams);
4634
- if (dynamic) {
4635
- const length2 = numberToHex(preparedParams.length, { size: 32 });
4636
- return {
4637
- dynamic: true,
4638
- encoded: preparedParams.length > 0 ? concat([length2, data]) : length2
4639
- };
4640
- }
4641
- if (dynamicChild)
4642
- return { dynamic: true, encoded: data };
4643
- }
4644
- return {
4645
- dynamic: false,
4646
- encoded: concat(preparedParams.map(({ encoded }) => encoded))
4647
- };
4648
- }
4649
- function encodeBytes(value, { param }) {
4650
- const [, paramSize] = param.type.split("bytes");
4651
- const bytesSize = size(value);
4652
- if (!paramSize) {
4653
- let value_ = value;
4654
- if (bytesSize % 32 !== 0)
4655
- value_ = padHex(value_, {
4656
- dir: "right",
4657
- size: Math.ceil((value.length - 2) / 2 / 32) * 32
4658
- });
4659
- return {
4660
- dynamic: true,
4661
- encoded: concat([padHex(numberToHex(bytesSize, { size: 32 })), value_])
4662
- };
4663
- }
4664
- if (bytesSize !== Number.parseInt(paramSize, 10))
4665
- throw new AbiEncodingBytesSizeMismatchError({
4666
- expectedSize: Number.parseInt(paramSize, 10),
4667
- value
4668
- });
4669
- return { dynamic: false, encoded: padHex(value, { dir: "right" }) };
4670
- }
4671
- function encodeBool(value) {
4672
- if (typeof value !== "boolean")
4673
- throw new BaseError(`Invalid boolean value: "${value}" (type: ${typeof value}). Expected: \`true\` or \`false\`.`);
4674
- return { dynamic: false, encoded: padHex(boolToHex(value)) };
4675
- }
4676
- function encodeNumber(value, { signed, size: size2 = 256 }) {
4677
- if (typeof size2 === "number") {
4678
- const max = 2n ** (BigInt(size2) - (signed ? 1n : 0n)) - 1n;
4679
- const min = signed ? -max - 1n : 0n;
4680
- if (value > max || value < min)
4681
- throw new IntegerOutOfRangeError({
4682
- max: max.toString(),
4683
- min: min.toString(),
4684
- signed,
4685
- size: size2 / 8,
4686
- value: value.toString()
4687
- });
4688
- }
4689
- return {
4690
- dynamic: false,
4691
- encoded: numberToHex(value, {
4692
- size: 32,
4693
- signed
4694
- })
4695
- };
4696
- }
4697
- function encodeString(value) {
4698
- const hexValue = stringToHex(value);
4699
- const partsLength = Math.ceil(size(hexValue) / 32);
4700
- const parts = [];
4701
- for (let i = 0;i < partsLength; i++) {
4702
- parts.push(padHex(slice(hexValue, i * 32, (i + 1) * 32), {
4703
- dir: "right"
4704
- }));
4705
- }
4706
- return {
4707
- dynamic: true,
4708
- encoded: concat([
4709
- padHex(numberToHex(size(hexValue), { size: 32 })),
4710
- ...parts
4711
- ])
4712
- };
4713
- }
4714
- function encodeTuple(value, { param }) {
4715
- let dynamic = false;
4716
- const preparedParams = [];
4717
- for (let i = 0;i < param.components.length; i++) {
4718
- const param_ = param.components[i];
4719
- const index = Array.isArray(value) ? i : param_.name;
4720
- const preparedParam = prepareParam({
4721
- param: param_,
4722
- value: value[index]
4723
- });
4724
- preparedParams.push(preparedParam);
4725
- if (preparedParam.dynamic)
4726
- dynamic = true;
4727
- }
4728
- return {
4729
- dynamic,
4730
- encoded: dynamic ? encodeParams(preparedParams) : concat(preparedParams.map(({ encoded }) => encoded))
4731
- };
4732
- }
4733
- function getArrayComponents(type) {
4734
- const matches = type.match(/^(.*)\[(\d+)?\]$/);
4735
- return matches ? [matches[2] ? Number(matches[2]) : null, matches[1]] : undefined;
4736
- }
4737
- var init_encodeAbiParameters = __esm(() => {
4738
- init_abi();
4739
- init_address();
4740
- init_base();
4741
- init_encoding();
4742
- init_isAddress();
4743
- init_pad();
4744
- init_size();
4745
- init_slice();
4746
- init_toHex();
4747
- init_regex();
4748
- });
4749
-
4750
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/stringify.js
4751
- var stringify = (value, replacer, space) => JSON.stringify(value, (key, value_) => {
4752
- const value2 = typeof value_ === "bigint" ? value_.toString() : value_;
4753
- return typeof replacer === "function" ? replacer(key, value2) : value2;
4754
- }, space);
4755
-
4756
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/errors/typedData.js
4757
- var InvalidDomainError, InvalidPrimaryTypeError, InvalidStructTypeError;
4758
- var init_typedData = __esm(() => {
4759
- init_base();
4760
- InvalidDomainError = class InvalidDomainError extends BaseError {
4761
- constructor({ domain }) {
4762
- super(`Invalid domain "${stringify(domain)}".`, {
4763
- metaMessages: ["Must be a valid EIP-712 domain."]
4764
- });
4765
- }
4766
- };
4767
- InvalidPrimaryTypeError = class InvalidPrimaryTypeError extends BaseError {
4768
- constructor({ primaryType, types }) {
4769
- super(`Invalid primary type \`${primaryType}\` must be one of \`${JSON.stringify(Object.keys(types))}\`.`, {
4770
- docsPath: "/api/glossary/Errors#typeddatainvalidprimarytypeerror",
4771
- metaMessages: ["Check that the primary type is a key in `types`."]
4772
- });
4773
- }
4774
- };
4775
- InvalidStructTypeError = class InvalidStructTypeError extends BaseError {
4776
- constructor({ type }) {
4777
- super(`Struct type "${type}" is invalid.`, {
4778
- metaMessages: ["Struct type must not be a Solidity type."],
4779
- name: "InvalidStructTypeError"
4780
- });
4781
- }
4782
- };
4783
- });
4784
-
4785
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/typedData.js
4786
- function validateTypedData(parameters) {
4787
- const { domain, message, primaryType, types } = parameters;
4788
- const validateData = (struct, data) => {
4789
- for (const param of struct) {
4790
- const { name, type } = param;
4791
- const value = data[name];
4792
- const integerMatch = type.match(integerRegex);
4793
- if (integerMatch && (typeof value === "number" || typeof value === "bigint")) {
4794
- const [_type, base, size_] = integerMatch;
4795
- numberToHex(value, {
4796
- signed: base === "int",
4797
- size: Number.parseInt(size_, 10) / 8
4798
- });
4799
- }
4800
- if (type === "address" && typeof value === "string" && !isAddress(value))
4801
- throw new InvalidAddressError({ address: value });
4802
- const bytesMatch = type.match(bytesRegex);
4803
- if (bytesMatch) {
4804
- const [_type, size_] = bytesMatch;
4805
- if (size_ && size(value) !== Number.parseInt(size_, 10))
4806
- throw new BytesSizeMismatchError({
4807
- expectedSize: Number.parseInt(size_, 10),
4808
- givenSize: size(value)
4809
- });
4810
- }
4811
- const struct2 = types[type];
4812
- if (struct2) {
4813
- validateReference(type);
4814
- validateData(struct2, value);
4815
- }
4816
- }
4817
- };
4818
- if (types.EIP712Domain && domain) {
4819
- if (typeof domain !== "object")
4820
- throw new InvalidDomainError({ domain });
4821
- validateData(types.EIP712Domain, domain);
4822
- }
4823
- if (primaryType !== "EIP712Domain") {
4824
- if (types[primaryType])
4825
- validateData(types[primaryType], message);
4826
- else
4827
- throw new InvalidPrimaryTypeError({ primaryType, types });
4828
- }
4829
- }
4830
- function getTypesForEIP712Domain({ domain }) {
4831
- return [
4832
- typeof domain?.name === "string" && { name: "name", type: "string" },
4833
- domain?.version && { name: "version", type: "string" },
4834
- (typeof domain?.chainId === "number" || typeof domain?.chainId === "bigint") && {
4835
- name: "chainId",
4836
- type: "uint256"
4837
- },
4838
- domain?.verifyingContract && {
4839
- name: "verifyingContract",
4840
- type: "address"
4841
- },
4842
- domain?.salt && { name: "salt", type: "bytes32" }
4843
- ].filter(Boolean);
4844
- }
4845
- function validateReference(type) {
4846
- if (type === "address" || type === "bool" || type === "string" || type.startsWith("bytes") || type.startsWith("uint") || type.startsWith("int"))
4847
- throw new InvalidStructTypeError({ type });
4848
- }
4849
- var init_typedData2 = __esm(() => {
4850
- init_abi();
4851
- init_address();
4852
- init_typedData();
4853
- init_isAddress();
4854
- init_size();
4855
- init_toHex();
4856
- init_regex();
4857
- });
4858
-
4859
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/utils/signature/hashTypedData.js
4860
- function hashTypedData(parameters) {
4861
- const { domain = {}, message, primaryType } = parameters;
4862
- const types = {
4863
- EIP712Domain: getTypesForEIP712Domain({ domain }),
4864
- ...parameters.types
4865
- };
4866
- validateTypedData({
4867
- domain,
4868
- message,
4869
- primaryType,
4870
- types
4871
- });
4872
- const parts = ["0x1901"];
4873
- if (domain)
4874
- parts.push(hashDomain({
4875
- domain,
4876
- types
4877
- }));
4878
- if (primaryType !== "EIP712Domain")
4879
- parts.push(hashStruct({
4880
- data: message,
4881
- primaryType,
4882
- types
4883
- }));
4884
- return keccak256(concat(parts));
4885
- }
4886
- function hashDomain({ domain, types }) {
4887
- return hashStruct({
4888
- data: domain,
4889
- primaryType: "EIP712Domain",
4890
- types
4891
- });
4892
- }
4893
- function hashStruct({ data, primaryType, types }) {
4894
- const encoded = encodeData({
4895
- data,
4896
- primaryType,
4897
- types
4898
- });
4899
- return keccak256(encoded);
4900
- }
4901
- function encodeData({ data, primaryType, types }) {
4902
- const encodedTypes = [{ type: "bytes32" }];
4903
- const encodedValues = [hashType({ primaryType, types })];
4904
- for (const field of types[primaryType]) {
4905
- const [type, value] = encodeField({
4906
- types,
4907
- name: field.name,
4908
- type: field.type,
4909
- value: data[field.name]
4910
- });
4911
- encodedTypes.push(type);
4912
- encodedValues.push(value);
4913
- }
4914
- return encodeAbiParameters(encodedTypes, encodedValues);
4915
- }
4916
- function hashType({ primaryType, types }) {
4917
- const encodedHashType = toHex(encodeType({ primaryType, types }));
4918
- return keccak256(encodedHashType);
4919
- }
4920
- function encodeType({ primaryType, types }) {
4921
- let result = "";
4922
- const unsortedDeps = findTypeDependencies({ primaryType, types });
4923
- unsortedDeps.delete(primaryType);
4924
- const deps = [primaryType, ...Array.from(unsortedDeps).sort()];
4925
- for (const type of deps) {
4926
- result += `${type}(${types[type].map(({ name, type: t }) => `${t} ${name}`).join(",")})`;
4927
- }
4928
- return result;
4929
- }
4930
- function findTypeDependencies({ primaryType: primaryType_, types }, results = new Set) {
4931
- const match = primaryType_.match(/^\w*/u);
4932
- const primaryType = match?.[0];
4933
- if (results.has(primaryType) || types[primaryType] === undefined) {
4934
- return results;
4935
- }
4936
- results.add(primaryType);
4937
- for (const field of types[primaryType]) {
4938
- findTypeDependencies({ primaryType: field.type, types }, results);
4939
- }
4940
- return results;
4941
- }
4942
- function encodeField({ types, name, type, value }) {
4943
- if (types[type] !== undefined) {
4944
- return [
4945
- { type: "bytes32" },
4946
- keccak256(encodeData({ data: value, primaryType: type, types }))
4947
- ];
4948
- }
4949
- if (type === "bytes")
4950
- return [{ type: "bytes32" }, keccak256(value)];
4951
- if (type === "string")
4952
- return [{ type: "bytes32" }, keccak256(toHex(value))];
4953
- if (type.lastIndexOf("]") === type.length - 1) {
4954
- const parsedType = type.slice(0, type.lastIndexOf("["));
4955
- const typeValuePairs = value.map((item) => encodeField({
4956
- name,
4957
- type: parsedType,
4958
- types,
4959
- value: item
4960
- }));
4961
- return [
4962
- { type: "bytes32" },
4963
- keccak256(encodeAbiParameters(typeValuePairs.map(([t]) => t), typeValuePairs.map(([, v]) => v)))
4964
- ];
4965
- }
4966
- return [{ type }, value];
4967
- }
4968
- var init_hashTypedData = __esm(() => {
4969
- init_encodeAbiParameters();
4970
- init_toHex();
4971
- init_keccak256();
4972
- init_typedData2();
4973
- });
4974
-
4975
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/accounts/utils/signTypedData.js
4976
- async function signTypedData(parameters) {
4977
- const { privateKey, ...typedData } = parameters;
4978
- return await sign({
4979
- hash: hashTypedData(typedData),
4980
- privateKey,
4981
- to: "hex"
4982
- });
4983
- }
4984
- var init_signTypedData = __esm(() => {
4985
- init_hashTypedData();
4986
- init_sign();
4987
- });
4988
-
4989
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/accounts/privateKeyToAccount.js
4990
- function privateKeyToAccount(privateKey, options = {}) {
4991
- const { nonceManager } = options;
4992
- const publicKey = toHex(secp256k1.getPublicKey(privateKey.slice(2), false));
4993
- const address = publicKeyToAddress(publicKey);
4994
- const account = toAccount({
4995
- address,
4996
- nonceManager,
4997
- async sign({ hash }) {
4998
- return sign({ hash, privateKey, to: "hex" });
4999
- },
5000
- async signAuthorization(authorization) {
5001
- return signAuthorization({ ...authorization, privateKey });
5002
- },
5003
- async signMessage({ message }) {
5004
- return signMessage({ message, privateKey });
5005
- },
5006
- async signTransaction(transaction, { serializer } = {}) {
5007
- return signTransaction({ privateKey, transaction, serializer });
5008
- },
5009
- async signTypedData(typedData) {
5010
- return signTypedData({ ...typedData, privateKey });
5011
- }
5012
- });
5013
- return {
5014
- ...account,
5015
- publicKey,
5016
- source: "privateKey"
5017
- };
5018
- }
5019
- var init_privateKeyToAccount = __esm(() => {
5020
- init_secp256k1();
5021
- init_toHex();
5022
- init_toAccount();
5023
- init_publicKeyToAddress();
5024
- init_sign();
5025
- init_signAuthorization();
5026
- init_signMessage();
5027
- init_signTransaction();
5028
- init_signTypedData();
5029
- });
5030
-
5031
- // ../../node_modules/.bun/viem@2.48.8+c6bb0886e91180fe/node_modules/viem/_esm/accounts/index.js
5032
- var init_accounts = __esm(() => {
5033
- init_generatePrivateKey();
5034
- init_privateKeyToAccount();
5035
- });
5036
-
5037
204
  // src/cloud/cloud-wallet.ts
205
+ import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
5038
206
  function ensureFlag() {
5039
207
  if (!isCloudWalletEnabled()) {
5040
208
  throw new CloudWalletFlagDisabledError;
@@ -5170,7 +338,6 @@ function __resetCloudWalletModuleForTests() {
5170
338
  }
5171
339
  var ELIZA_CLOUD_CLIENT_ADDRESS_KEY_ENV = "ELIZA_CLOUD_CLIENT_ADDRESS_KEY", CloudWalletFlagDisabledError, inflight;
5172
340
  var init_cloud_wallet = __esm(() => {
5173
- init_accounts();
5174
341
  init_config_env();
5175
342
  CloudWalletFlagDisabledError = class CloudWalletFlagDisabledError extends Error {
5176
343
  constructor() {
@@ -5192,4 +359,4 @@ export {
5192
359
  CloudWalletFlagDisabledError
5193
360
  };
5194
361
 
5195
- //# debugId=FF59B298EABCBF5564756E2164756E21
362
+ //# debugId=B0EB8E1A353E263464756E2164756E21