@laceio/sdk 0.1.1 → 0.1.2-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (388) hide show
  1. package/dist/{TransactionBuilder-DrB3NVTi.cjs → TransactionBuilder-CCjOn7NA.cjs} +42 -0
  2. package/dist/{TransactionBuilder-V6aLx4SV.js → TransactionBuilder-CIzdw18M.js} +1 -1
  3. package/dist/{_polyfill-buffer-patch-BnPVerlG.cjs → _polyfill-buffer-patch-CM8X7JiY.cjs} +21 -2
  4. package/dist/_polyfill-buffer-patch-yNxN4d5E.js +1467 -0
  5. package/dist/_web-crypto-random-bytes-Bo-GTcRS.js +197 -0
  6. package/dist/acc-module-4iIUv6My.cjs +27654 -0
  7. package/dist/acc-module-Cmj8EsIb.js +27624 -0
  8. package/dist/account-BOQruszJ.js +6 -0
  9. package/dist/account-BUOj4pYJ.cjs +11 -0
  10. package/dist/account-call-7wnopBq0.cjs +5 -0
  11. package/dist/account-call-B9d_2Xwi.js +4 -0
  12. package/dist/account-call-Bd4Rpbvt.cjs +323 -0
  13. package/dist/account-call-C3CkDqEC.js +276 -0
  14. package/dist/account-guards-BtjTGxDZ.cjs +42 -0
  15. package/dist/account-guards-D9Lu5T3W.js +36 -0
  16. package/dist/account-tokens-DvkOFVON.js +16 -0
  17. package/dist/account-tokens-nwcvwLu4.cjs +21 -0
  18. package/dist/{activity-type.stable-BJEfeLxL.cjs → activity-type-Ch6ljxBy.cjs} +2 -1
  19. package/dist/{activity-type.stable-C76_hWd7.js → activity-type-GsJGWs-3.js} +2 -1
  20. package/dist/address-B9ntKL8K.js +13761 -0
  21. package/dist/address-BXp-mY8H.cjs +11270 -0
  22. package/dist/{address-book-address-validator-DIUolI-s.js → address-book-address-validator-0J9XAADH.js} +2 -2
  23. package/dist/address-book-address-validator-DK0dnsRS.cjs +41 -0
  24. package/dist/address-book-address-validator-Di_ywo8M.js +39 -0
  25. package/dist/{address-book-address-validator-DNwQGlOB.cjs → address-book-address-validator-Dte_YQ2L.cjs} +2 -2
  26. package/dist/artefact-loader-BWWYAD7E.cjs +183 -0
  27. package/dist/artefact-loader-Dik4HIfv.js +160 -0
  28. package/dist/auto-dismiss-failure-on-success-C-qoJuid.cjs +37 -0
  29. package/dist/auto-dismiss-failure-on-success-s8MGDEIu.js +31 -0
  30. package/dist/bip32-D6wd_QMn.cjs +3851 -0
  31. package/dist/bitcoin-data-provider-BYPSmuZS.js +21 -0
  32. package/dist/bitcoin-data-provider-w1oEDSU3.cjs +26 -0
  33. package/dist/bitcoin.cjs +45 -0
  34. package/dist/bitcoin.d.ts +29906 -1
  35. package/dist/bitcoin.js +20 -0
  36. package/dist/{blockfrost-tx-submit-provider-DPTrapz-.js → blockfrost-tx-submit-provider-CBWQ0wK9.js} +5 -157
  37. package/dist/{blockfrost-tx-submit-provider-BAIzV5o3.cjs → blockfrost-tx-submit-provider-CLNQ5ycR.cjs} +3 -167
  38. package/dist/bn-d3nSOIf7.cjs +2553 -0
  39. package/dist/browser-B1eMbDwh.js +7468 -0
  40. package/dist/bytes.vo-BB7_4JK6.js +23 -0
  41. package/dist/bytes.vo-BNRquqaO.cjs +34 -0
  42. package/dist/cardano-DfPwhwm-.js +3 -0
  43. package/dist/{cardano-network-id.vo-DSxrFk9S.cjs → cardano-network-id.vo-BEDPn6Li.cjs} +1 -1
  44. package/dist/{cardano-network-id.vo-CK1tNQDg.js → cardano-network-id.vo-Cfpvbod9.js} +1 -1
  45. package/dist/cardano.cjs +22 -18
  46. package/dist/cardano.d.ts +16956 -1716
  47. package/dist/cardano.js +16 -11
  48. package/dist/client-DXBLHk7K.cjs +808 -0
  49. package/dist/codecs-Cswkg7Tm.cjs +4051 -0
  50. package/dist/codecs-Dc1Krpbt.js +3903 -0
  51. package/dist/{const-C84qHkjp.js → const-BJfIK_G-.js} +4 -4
  52. package/dist/const-BhYOdznB.cjs +42 -0
  53. package/dist/const-BsnjG2_Q.cjs +32071 -0
  54. package/dist/const-CUnCl5U0.js +13 -0
  55. package/dist/{const-DXk2tFyv.js → const-CjmfjBP3.js} +1 -1
  56. package/dist/{const-BDEg2Trq.cjs → const-D-eZIS4n.cjs} +4 -4
  57. package/dist/const-D0CbQlo4.js +154 -0
  58. package/dist/{const-BY8B3_0_.cjs → const-iwzZEE_w.cjs} +1 -1
  59. package/dist/contract-1R86jhSw.js +171 -0
  60. package/dist/contract-MKLzYVkW.cjs +189 -0
  61. package/dist/create-add-accounts-Brqk84vF.js +102 -0
  62. package/dist/create-add-accounts-DzXIh7Ot.cjs +114 -0
  63. package/dist/{delegation-tx-builder-CRpLP6jH.cjs → delegation-tx-builder-CCjiakoy.cjs} +6 -6
  64. package/dist/{delegation-tx-builder-CGVqlaFE.js → delegation-tx-builder-DZFjHDS8.js} +5 -5
  65. package/dist/{deregistration-tx-builder-B-CrUyX6.js → deregistration-tx-builder-Bf6xAYp4.js} +5 -5
  66. package/dist/{deregistration-tx-builder-DZGwB4cz.cjs → deregistration-tx-builder-CQP35yex.cjs} +6 -6
  67. package/dist/device-commitment-hex.vo-5wFtQvDS.js +26 -0
  68. package/dist/device-commitment-hex.vo-CT3RmAug.cjs +31 -0
  69. package/dist/device-readers-CUHYoYOH.js +145 -0
  70. package/dist/device-readers-CdxS2btd.cjs +168 -0
  71. package/dist/device-readers-D_JZeNL2.cjs +8 -0
  72. package/dist/device-readers-DwSNCGPP.js +4 -0
  73. package/dist/dist-BMi5ZjEq.cjs +43175 -0
  74. package/dist/dist-BtIq4XFn.cjs +535 -0
  75. package/dist/dist-C3SHC_Ho.cjs +1394 -0
  76. package/dist/dist-CykEjYEX.cjs +3814 -0
  77. package/dist/dist-Dcsxh3be.cjs +3452 -0
  78. package/dist/dist-DqJfSlTd.cjs +4413 -0
  79. package/dist/dist-nTZ70qj7.cjs +1306 -0
  80. package/dist/{earn-rewards-tx-builder-BDbTDZmD.js → earn-rewards-tx-builder-Bsga3yFb.js} +5 -5
  81. package/dist/{earn-rewards-tx-builder-D5sUT5v8.cjs → earn-rewards-tx-builder-GuxofYns.cjs} +6 -6
  82. package/dist/enc-key-circuits-B7BjgUL9.js +13 -0
  83. package/dist/enc-key-circuits-BLrZrBVI.cjs +24 -0
  84. package/dist/english-Byb9M0E_.cjs +2057 -0
  85. package/dist/envelopes-BGoO_v8m.js +1621 -0
  86. package/dist/envelopes-CH25R-DN.cjs +1722 -0
  87. package/dist/errors-BIftM8ZN.cjs +688 -0
  88. package/dist/errors-DSq5wUwt.js +466 -0
  89. package/dist/esm-HBSUQw3w.js +384 -0
  90. package/dist/esm-LZuaZjMf.cjs +389 -0
  91. package/dist/experimental.cjs +7349 -0
  92. package/dist/experimental.d.ts +86273 -0
  93. package/dist/experimental.js +7184 -0
  94. package/dist/gated-call-CDCVZIK-.cjs +5 -0
  95. package/dist/gated-call-D-tT7P_t.js +722 -0
  96. package/dist/gated-call-D_VT2quk.js +4 -0
  97. package/dist/gated-call-DgJm1Mi_.cjs +787 -0
  98. package/dist/grant-circuits-DswmW3nI.cjs +71 -0
  99. package/dist/grant-circuits-Jxb5y1HW.js +42 -0
  100. package/dist/grant-rules-By07_eDi.js +6824 -0
  101. package/dist/grant-rules-BzVTWXS7.cjs +7099 -0
  102. package/dist/grant-spend-B3Md9L0n.js +215 -0
  103. package/dist/grant-spend-oWmzRsjH.cjs +217 -0
  104. package/dist/grant-status-B2y49iIu.js +2688 -0
  105. package/dist/grant-status-DOr3t_u8.cjs +2820 -0
  106. package/dist/grants-2BZ-qEVQ.js +5 -0
  107. package/dist/grants-BPoLSiMt.cjs +18 -0
  108. package/dist/grants-BoI5uwSF.cjs +272 -0
  109. package/dist/grants-CtofFu-e.js +213 -0
  110. package/dist/{group-cardano-addresses-by-account-B533oVXR.cjs → group-cardano-addresses-by-account-Bp0g4wEY.cjs} +3 -39
  111. package/dist/{group-cardano-addresses-by-account-RHKoEskR.js → group-cardano-addresses-by-account-SR8MMrZf.js} +5 -35
  112. package/dist/{guarded-transaction-signer-Bxl6_XNd.cjs → guarded-transaction-signer-MFpPg98D.cjs} +17 -18
  113. package/dist/{guarded-transaction-signer-CpKLj8Kp.js → guarded-transaction-signer-P6Rp1faj.js} +8 -15
  114. package/dist/hex-D9ITYbwt.cjs +263 -0
  115. package/dist/hex-mkXcV3pN.js +191 -0
  116. package/dist/http-client-B3N-TMxu.cjs +167 -0
  117. package/dist/http-client-TRlhDZGh.js +155 -0
  118. package/dist/identity-BMLuufva.cjs +263 -0
  119. package/dist/identity-DII6f-h7.js +233 -0
  120. package/dist/in-memory-wallet-integration-B2xzxORj.cjs +20741 -0
  121. package/dist/in-memory-wallet-integration-CBRiPjLO.js +130 -0
  122. package/dist/in-memory-wallet-integration-CULUB5Tf.cjs +240 -0
  123. package/dist/{in-memory-wallet-integration-D-qn65Kx.js → in-memory-wallet-integration-ChIOirMW.js} +5 -2
  124. package/dist/{in-memory-wallet-integration-Croiuopx.js → in-memory-wallet-integration-CljprQQV.js} +7 -104
  125. package/dist/{in-memory-wallet-integration-DVh9sRXa.cjs → in-memory-wallet-integration-Cm6P8sk6.cjs} +3 -2
  126. package/dist/in-memory-wallet-integration-TM9bBphA.js +20738 -0
  127. package/dist/{in-memory-wallet-integration-CnLYeX4-.cjs → in-memory-wallet-integration-t9I00R_V.cjs} +17 -108
  128. package/dist/index.cjs +84 -47
  129. package/dist/index.d.ts +37496 -10033
  130. package/dist/index.js +52 -24
  131. package/dist/{init-CLHuAMB-.js → init-0zzs9aqU.js} +4 -4
  132. package/dist/{init-U8c9yHYx.cjs → init-5KcGcBb5.cjs} +1 -1
  133. package/dist/init-8v_n8boO.js +1177 -0
  134. package/dist/{init-CigestoM.js → init-B3-1ghyx.js} +2 -2
  135. package/dist/init-B8U3ABhS.cjs +107 -0
  136. package/dist/init-BJn-8_hf.js +141 -0
  137. package/dist/init-BPU3j8sT.cjs +6 -0
  138. package/dist/init-BRzH6xu-2.cjs +2797 -0
  139. package/dist/init-BmzfDaKL.js +1142 -0
  140. package/dist/{init-C-jErzp5.cjs → init-BopV9ed4.cjs} +2 -2
  141. package/dist/init-BpHTq2R5.js +105 -0
  142. package/dist/init-BpSITBfF.js +39 -0
  143. package/dist/{init-DX4WyB0R.cjs → init-BrdVzxei.cjs} +3 -3
  144. package/dist/{init-LfyMo-sS.cjs → init-BwkU0ruo.cjs} +2 -2
  145. package/dist/{init-CB__aLD7.cjs → init-C-G32J12.cjs} +2 -2
  146. package/dist/init-C00gw1zi.js +422 -0
  147. package/dist/{init-TkPq_Ny_.js → init-C2RgrfZe.js} +1 -1
  148. package/dist/{init-DcYY6zMD.js → init-C8URA2OX.js} +1 -1
  149. package/dist/init-CDkRynJa.js +2796 -0
  150. package/dist/{init-Cg9XdAru.js → init-CNM5m7M2.js} +4 -4
  151. package/dist/init-CR7BfztQ.cjs +18 -0
  152. package/dist/{init-CSHwHnfg.cjs → init-CSDpdu0Q.cjs} +2 -2
  153. package/dist/{init-aJHl-7AO.js → init-CX0AMQUn.js} +2 -2
  154. package/dist/{init-FMGDET-9.js → init-CfTbSEKy.js} +259 -60
  155. package/dist/{init-CR6tpw1B.js → init-Cigr_tKx.js} +47 -43
  156. package/dist/init-CuW7rHNA.js +3584 -0
  157. package/dist/{init-CFYsq82V.js → init-CyAY4Lzl.js} +1 -1
  158. package/dist/init-Cz0rz5fU.cjs +3585 -0
  159. package/dist/{init-BKhH6mVR.cjs → init-D6BxBs7e.cjs} +1 -1
  160. package/dist/init-D8OeObDF.cjs +1141 -0
  161. package/dist/init-D9g1HXYf.cjs +40 -0
  162. package/dist/{init-CNLGJJRx.js → init-DA7zmptx.js} +1 -1
  163. package/dist/{init-DkIc5nqF.cjs → init-DFMiP2ZH.cjs} +1 -1
  164. package/dist/{init-zSzCjoor.js → init-DFjT8YvT.js} +4 -4
  165. package/dist/init-DGjXwWs2.cjs +143 -0
  166. package/dist/init-DHrCbpkW.cjs +121 -0
  167. package/dist/{init-B64zCLxG.cjs → init-DUF4ar8P.cjs} +4 -4
  168. package/dist/init-DlqJuHhl.js +119 -0
  169. package/dist/{init-y2Ra0vZP.js → init-Dnsv155v.js} +3 -3
  170. package/dist/init-DrRdf5sZ.cjs +1176 -0
  171. package/dist/init-DuYENxci.js +17 -0
  172. package/dist/{init-D6DBUsD3.cjs → init-Dv3zKj0r.cjs} +4 -4
  173. package/dist/{init-BtzMZ7Pk.cjs → init-Dy-05ktr.cjs} +1 -1
  174. package/dist/{init-BsCBAGWf.cjs → init-EP0CUWNK.cjs} +2 -2
  175. package/dist/{init-BJVU54pI.cjs → init-EhzD7a8i.cjs} +1 -1
  176. package/dist/{init-w9GEs73W.js → init-Fw89ZmrR.js} +2 -2
  177. package/dist/init-GsT2AEa4.cjs +424 -0
  178. package/dist/{init-Rxohwpmu.js → init-NCjgwCZy.js} +2 -2
  179. package/dist/{init-DxUHsN53.cjs → init-NdhG_VrF.cjs} +6 -6
  180. package/dist/{init-DDdhguVC.js → init-SZ01tARX2.js} +2 -2
  181. package/dist/{init-BAJJzBza.js → init-Y3mkB4XS.js} +2 -2
  182. package/dist/init-c4l6r-o-.js +5 -0
  183. package/dist/{init-Dku4b2lG.js → init-kEfUTuG2.js} +1 -1
  184. package/dist/{init-C7IeJwQR.cjs → init-lzHt4Cli.cjs} +256 -59
  185. package/dist/{init-anYu6XB7.cjs → init-rmt7-fQE.cjs} +2 -2
  186. package/dist/{init-C4Bkib9u.cjs → init-zU-_9Gsp.cjs} +67 -65
  187. package/dist/{is-retriable-error-BU0e3hVI.js → is-retriable-error-BUiVJDwH.js} +1 -1
  188. package/dist/{is-retriable-error-CeeuHqDa.cjs → is-retriable-error-Dpt860if.cjs} +1 -1
  189. package/dist/jubjub-authoriser-D7zDXu3V.js +86 -0
  190. package/dist/jubjub-authoriser-Dgu6o3Sv.cjs +87 -0
  191. package/dist/key-source-5oUBFiC7.cjs +583 -0
  192. package/dist/key-source-B08HukZg.js +2550 -0
  193. package/dist/keyDerivation-D3k9XyHg.js +4077 -0
  194. package/dist/keyDerivation-u0nBA93T.cjs +274 -0
  195. package/dist/{lace-context-CZcNHr4M.js → lace-context-BZciB9c7.js} +4 -4
  196. package/dist/{lace-context-fJTDghdp.cjs → lace-context-DgR6vLli.cjs} +4 -4
  197. package/dist/lib--iqvW4O_.js +2354 -0
  198. package/dist/lib-Yk6Upl5D.cjs +2359 -0
  199. package/dist/{libsodium-wrappers-UH0LaOUE.js → libsodium-wrappers-BhbOA8dQ.js} +3 -1647
  200. package/dist/midnight-account-id.vo-0x9X-r3l.cjs +10 -0
  201. package/dist/midnight-account-id.vo-DjCAGcqc.js +5 -0
  202. package/dist/midnight-engine-DpemplKO.js +5 -0
  203. package/dist/midnight-engine-xU1wotne.cjs +6 -0
  204. package/dist/midnight-wallet-DIsAlSn6.js +18 -0
  205. package/dist/midnight-wallet-XTZc2li7.cjs +24 -0
  206. package/dist/midnight.cjs +1408 -0
  207. package/dist/midnight.d.ts +28934 -0
  208. package/dist/midnight.js +1352 -0
  209. package/dist/modules-cardano-B1nDUWqy.js +995 -0
  210. package/dist/modules-cardano-BYeYHrRm.cjs +1108 -0
  211. package/dist/node-relay-DWe1U0w2.cjs +49 -0
  212. package/dist/node-relay-h4i5IlAQ.js +48 -0
  213. package/dist/outputs-Bd2yZVjx.js +720 -0
  214. package/dist/outputs-CJoQBIA2.cjs +990 -0
  215. package/dist/pbkdf2-CIW-oWrm.cjs +1337 -0
  216. package/dist/pending-operation-B0_P78Jo.cjs +26 -0
  217. package/dist/pending-operation-BIS6mpjB.js +21 -0
  218. package/dist/providers-FjhM47BH.cjs +388 -0
  219. package/dist/providers-WtiSuxFu.js +365 -0
  220. package/dist/redacted-BmE2aXqr.js +81 -0
  221. package/dist/redacted-CRZJLS3w.cjs +86 -0
  222. package/dist/{retry-config-DC5IMaH7.cjs → retry-config-BaCfVC1H.cjs} +1 -1
  223. package/dist/{retry-config-BcUmMS--.js → retry-config-Dmgt28wM.js} +1 -1
  224. package/dist/safe-buffer-B_vMqJWU.js +43 -0
  225. package/dist/safe-buffer-DYOwEfHB.cjs +48 -0
  226. package/dist/sdk-Cb-gZnS9.js +1241 -0
  227. package/dist/sdk-DffwmX8b.cjs +1439 -0
  228. package/dist/sdk-init-Bln9rFtn.js +4138 -0
  229. package/dist/sdk-init-CYViTJY_.cjs +3841 -0
  230. package/dist/{seam-cardano-CATqBEyK.js → seam-cardano-B_etH4F4.js} +1 -1
  231. package/dist/{bytes.vo-TgiwogWF.js → secret-box-DUR0ACYz.js} +3 -25
  232. package/dist/{bytes.vo-Ck5u40RA.cjs → secret-box-DrjLZuS1.cjs} +1 -35
  233. package/dist/send-proof-progress-C-ljq1x5.js +30 -0
  234. package/dist/send-proof-progress-vmsaSfbz.cjs +47 -0
  235. package/dist/side-effects-BnqYz7Nl.js +768 -0
  236. package/dist/side-effects-CngaeXi0.cjs +804 -0
  237. package/dist/sign-bitcoin-transaction-with-seed-D4z62-jV.js +147 -0
  238. package/dist/sign-bitcoin-transaction-with-seed-DsLYXnCY.cjs +158 -0
  239. package/dist/signer-3fk8lZtE.cjs +7 -0
  240. package/dist/signer-CsL28DrK.cjs +121 -0
  241. package/dist/signer-DGluibtn.js +92 -0
  242. package/dist/signer-RqB5pu3K.js +2 -0
  243. package/dist/signer-factory-BA7WFJVZ.js +282 -0
  244. package/dist/signer-factory-Cwd6o-lG.cjs +281 -0
  245. package/dist/{signer-factory-9URFliA5.js → signer-factory-DObB55D4.js} +6 -3
  246. package/dist/signer-factory-DhZiE03y.cjs +149 -0
  247. package/dist/{signer-factory-BWGUmnvm.cjs → signer-factory-Ds6G2AZk.cjs} +4 -3
  248. package/dist/signer-factory-hzSRaIw2.js +148 -0
  249. package/dist/{slice-CuHUaPZx.cjs → slice-7G2xxYKJ.cjs} +3 -3
  250. package/dist/{slice-DZmQJNV8.cjs → slice-B4CdYoPu.cjs} +2 -2
  251. package/dist/slice-BPNuHKfw.js +9091 -0
  252. package/dist/{slice-DGcNrbPR.cjs → slice-Bg6HEr3K.cjs} +4 -4
  253. package/dist/{slice-DtaO72qY.cjs → slice-Bs2aMERu.cjs} +3 -3
  254. package/dist/{slice-HeHCv3bl.cjs → slice-C34iOOUH.cjs} +7 -7
  255. package/dist/{slice-Do2R2CYW.cjs → slice-C9TT5KhY.cjs} +6 -6
  256. package/dist/{slice-eIwcwKHI.js → slice-CK07EBCo.js} +4 -4
  257. package/dist/{slice-CnyWevM9.js → slice-CU80pbiu.js} +3 -3
  258. package/dist/{slice-CobanYgn.js → slice-CwyYrh1H.js} +2 -2
  259. package/dist/slice-Czfp6t84.cjs +436 -0
  260. package/dist/{slice-d0p6-xj5.js → slice-D-9aPKG-.js} +6 -6
  261. package/dist/{slice-maaskdUn.js → slice-DBpJ2QGf.js} +6 -6
  262. package/dist/{slice-mxLQ_FeY.cjs → slice-DTZTiJle.cjs} +352 -39
  263. package/dist/{slice-zJ9XVYjZ.js → slice-Da426sf9.js} +1 -1
  264. package/dist/{slice-D11m2EKl.cjs → slice-DayJvMRD.cjs} +1 -1
  265. package/dist/slice-DnBWfA-k.cjs +9109 -0
  266. package/dist/{slice-oqm_r1cS.cjs → slice-DnG-yvpI.cjs} +2 -2
  267. package/dist/{slice-BNu73oBa.js → slice-DyNs7oWp.js} +2 -2
  268. package/dist/{slice-CB4SnzMm.js → slice-GwiiJRoq.js} +3 -3
  269. package/dist/slice-oWnc7YVD.js +412 -0
  270. package/dist/{slice-B2PhoWAg.js → slice-qt0uBExh.js} +325 -37
  271. package/dist/slice-t8Gzj55G2.cjs +106 -0
  272. package/dist/slice-t8Q1cHm-.js +88 -0
  273. package/dist/src-BDzYIksE.cjs +20637 -0
  274. package/dist/src-BFoefPv_.js +20755 -0
  275. package/dist/store-B1Lq3cEf.cjs +66 -0
  276. package/dist/store-DuBG8qh5.js +37 -0
  277. package/dist/submit-Bs77dPn_.cjs +413 -0
  278. package/dist/submit-DOv8Z0Vf.js +336 -0
  279. package/dist/submit-bitcoin-tx-D6oYgH5S.js +983 -0
  280. package/dist/submit-bitcoin-tx-goFuRL7K.cjs +1049 -0
  281. package/dist/{sync-operation-utils-BYXLO80m.js → sync-operation-utils-31iFLExW.js} +2 -38
  282. package/dist/{sync-operation-utils-SdPbwFoD.cjs → sync-operation-utils-COIZ66-I.cjs} +1 -67
  283. package/dist/token-id-mapper-Bnds3xKH.cjs +18 -0
  284. package/dist/{token-id-mapper-DsPAL6Nh.cjs → token-id-mapper-CVyQJUKY.cjs} +2 -2
  285. package/dist/token-id-mapper-CnKHQ8DV.js +16 -0
  286. package/dist/{token-id-mapper-B2ivlLv3.js → token-id-mapper-D29Ggv8h.js} +2 -2
  287. package/dist/tokens-Cevp7rdU.cjs +62 -0
  288. package/dist/tokens-Diw4MLRM.js +44 -0
  289. package/dist/types-B8uiJn-X.js +12 -0
  290. package/dist/types-BHC12eSa.js +33 -0
  291. package/dist/types-CJT6XF2c.js +10 -0
  292. package/dist/types-CLRUYpfe.cjs +23 -0
  293. package/dist/types-Cc3mC8u0.cjs +50 -0
  294. package/dist/types-DWbVZpnF.cjs +15 -0
  295. package/dist/unwrap-provider-result-BZSiwabU.js +32 -0
  296. package/dist/unwrap-provider-result-ZqfBsTkk.cjs +39 -0
  297. package/dist/{util-CGzqQ8IV.cjs → util-Bu4W5lF4.cjs} +1 -1
  298. package/dist/{util-BaLzwa32.js → util-Cp5cZkfK.js} +1 -1
  299. package/dist/{utils-o8aMjfln.js → utils-BfBEUvWA.js} +2 -2
  300. package/dist/utils-DFwzEvbv.js +65 -0
  301. package/dist/{utils-5JvjbqH3.cjs → utils-DsElZgCI.cjs} +7 -1
  302. package/dist/utils-IXxR-Djh.cjs +112 -0
  303. package/dist/v8Signatures-CO_Uloy7.cjs +71 -0
  304. package/dist/{vote-delegation-tx-builder-BpEMSti4.cjs → vote-delegation-tx-builder-BUg1S2Ep.cjs} +6 -6
  305. package/dist/{vote-delegation-tx-builder-CmKv6GoG.js → vote-delegation-tx-builder-C6FiS7zI.js} +5 -5
  306. package/dist/watch-CUEvcP-V.js +21997 -0
  307. package/dist/watch-DMF2s-II.cjs +52281 -0
  308. package/package.json +96 -4
  309. package/dist/account-guards.stable-B1DSSh9D.cjs +0 -10
  310. package/dist/account-guards.stable-JRQ5qx2V.js +0 -5
  311. package/dist/codecs-B7X9pAsK.cjs +0 -1945
  312. package/dist/codecs-CC1Xjntz.js +0 -1882
  313. package/dist/init-Bv53hpLM.js +0 -19
  314. package/dist/init-CRbjI7p1.js +0 -3494
  315. package/dist/init-DAna1KCg.cjs +0 -3495
  316. package/dist/init-DGe47B22.cjs +0 -364
  317. package/dist/init-DMtyvYfC.cjs +0 -21
  318. package/dist/init-TkPDD750.js +0 -363
  319. package/dist/modules-cardano-BDvuL4Xx.js +0 -5248
  320. package/dist/modules-cardano-D2G3De2P.cjs +0 -5432
  321. package/dist/slice-CGVHXHDt.cjs +0 -125
  322. package/dist/slice-DhvF7L6X.js +0 -107
  323. /package/dist/{account-id.vo-LvCBVn5r.cjs → account-id.vo-DwqFjK5u.cjs} +0 -0
  324. /package/dist/{account-id.vo-MYSI7YFm.js → account-id.vo-OPz2v-JZ.js} +0 -0
  325. /package/dist/{actions-DdGbj7c7.cjs → actions-B2BJ4RTy.cjs} +0 -0
  326. /package/dist/{actions-9QSQR-GB.js → actions-iLXdgL5Y.js} +0 -0
  327. /package/dist/{apply-vkey-witnesses-ClZbpk5w.js → apply-vkey-witnesses-BKx3lcs0.js} +0 -0
  328. /package/dist/{apply-vkey-witnesses-CLzVSWxl.cjs → apply-vkey-witnesses-ZnFS0jnJ.cjs} +0 -0
  329. /package/dist/{asyncoption-Cw07zPH7.js → asyncoption-CruEYOBI.js} +0 -0
  330. /package/dist/{asyncoption-DYoGuQfP.cjs → asyncoption-i0VbqVTq.cjs} +0 -0
  331. /package/dist/{bignum.vo-B0rK_PQ1.js → bignum.vo-CEXOIew0.js} +0 -0
  332. /package/dist/{bignum.vo-DsG3kNiZ.cjs → bignum.vo-hx2kuqlA.cjs} +0 -0
  333. /package/dist/{bip32ed25519-1ApqeAZk.cjs → bip32ed25519-B7Yat217.cjs} +0 -0
  334. /package/dist/{bip32ed25519-DetAdGwD.js → bip32ed25519-FQ8qvdcq.js} +0 -0
  335. /package/dist/{blake2b-DOEVc57D.js → blake2b-BiQTw3GC.js} +0 -0
  336. /package/dist/{blake2b-B9tftbvG.cjs → blake2b-DEeVUdKR.cjs} +0 -0
  337. /package/dist/{blockchain-network-id.vo-BXpZhvvQ.cjs → blockchain-network-id.vo-BAKEwGjG.cjs} +0 -0
  338. /package/dist/{blockchain-network-id.vo-DNRkuT5B.js → blockchain-network-id.vo-CiVykuqG.js} +0 -0
  339. /package/dist/{blockingWithLatestFrom-C5wp_uA-.js → blockingWithLatestFrom-Cd8c8EPG.js} +0 -0
  340. /package/dist/{blockingWithLatestFrom-DY8OPg0w.cjs → blockingWithLatestFrom-D8kBPBMX.cjs} +0 -0
  341. /package/dist/{cardano-network-id-to-network-type-CrZfUcyP.js → cardano-network-id-to-network-type-BWwzeEtM.js} +0 -0
  342. /package/dist/{cardano-network-id-to-network-type-BDTF-HmK.cjs → cardano-network-id-to-network-type-C0ufJOyE.cjs} +0 -0
  343. /package/dist/{cardano-tx-id.vo-BPhV-AmZ.cjs → cardano-tx-id.vo-TLjJZHCI.cjs} +0 -0
  344. /package/dist/{cardano-tx-id.vo-DF9NzZXk.js → cardano-tx-id.vo-eVnKuzlm.js} +0 -0
  345. /package/dist/{composite-signer-factory-_46QsNBz.js → composite-signer-factory-CR8YHA1y.js} +0 -0
  346. /package/dist/{composite-signer-factory-BpF1mIYA.cjs → composite-signer-factory-m5cVs9h_.cjs} +0 -0
  347. /package/dist/{error-CNIquqT5.cjs → error-Cb3EnD0u.cjs} +0 -0
  348. /package/dist/{error-BCp9NkPi.js → error-DIZOY2Lw.js} +0 -0
  349. /package/dist/{esm-browser-C93Q-EOI.js → esm-browser-MG97cre9.js} +0 -0
  350. /package/dist/{esm-browser-DTc9IK3D.cjs → esm-browser-bweqfBlL.cjs} +0 -0
  351. /package/dist/{feature-flag-key.vo-ofrB6ZVQ.js → feature-flag-key.vo-DN_-4-sG.js} +0 -0
  352. /package/dist/{feature-flag-key.vo-BPz-ZAp6.cjs → feature-flag-key.vo-RlfHL3hq.cjs} +0 -0
  353. /package/dist/{first-state-of-status-OROkXcRv.cjs → first-state-of-status-CbT7hPa4.cjs} +0 -0
  354. /package/dist/{first-state-of-status-DQnMT3ya.js → first-state-of-status-unPynOuM.js} +0 -0
  355. /package/dist/{init-Es3wHW7D.js → init-829HRYcz.js} +0 -0
  356. /package/dist/{init-CKipPE_c.js → init-A-VyGSNW2.js} +0 -0
  357. /package/dist/{init-DFQQ9dTW.cjs → init-Atisw4x2.cjs} +0 -0
  358. /package/dist/{init-C5CEZ1m0.cjs → init-BFcvPHL-.cjs} +0 -0
  359. /package/dist/{init-IAk_CkGa.cjs → init-BgNobbNq.cjs} +0 -0
  360. /package/dist/{init-cqN3uX2j.js → init-atCFur0v.js} +0 -0
  361. /package/dist/{is-redux-persist-state-CTn3WZVh.cjs → is-redux-persist-state-BCFnSm36.cjs} +0 -0
  362. /package/dist/{is-redux-persist-state-Cxcd0_bM.js → is-redux-persist-state-yBfq0h_E.js} +0 -0
  363. /package/dist/{key-value-store-8cMzeNyG.js → key-value-store--W3SrMaw.js} +0 -0
  364. /package/dist/{key-value-store-DUAepXQf.cjs → key-value-store-C2Xt5Emp.cjs} +0 -0
  365. /package/dist/{repo-slice-WxetRhMY.cjs → repo-slice-7X4AYYVm.cjs} +0 -0
  366. /package/dist/{repo-slice-DwyMhCR1.js → repo-slice-RxFm0zDZ.js} +0 -0
  367. /package/dist/{reselect-CRDqmQY9.cjs → reselect-Bd94u0K-.cjs} +0 -0
  368. /package/dist/{reselect-C06X06oX.js → reselect-CGoLzEPv.js} +0 -0
  369. /package/dist/{serializable-B8GahgE1.js → serializable-BHdKIgk3.js} +0 -0
  370. /package/dist/{serializable-CRdnFaLZ.cjs → serializable-BxHkoPdk.cjs} +0 -0
  371. /package/dist/{slice-D11FHQuQ.cjs → slice-BiRsDKOK.cjs} +0 -0
  372. /package/dist/{slice-Be7hj4Iy.js → slice-Bk0Sv05J.js} +0 -0
  373. /package/dist/{slice-FioKeHtA.cjs → slice-Dqw1ecum.cjs} +0 -0
  374. /package/dist/{slice-B87b52iM.js → slice-obCSLm1x.js} +0 -0
  375. /package/dist/{src-vq1wS9sZ.js → src-BlxEp6Mm.js} +0 -0
  376. /package/dist/{src-BTPIvlDI.cjs → src-Cqp0B2M_.cjs} +0 -0
  377. /package/dist/{time.vo-CQ8pSXz2.cjs → time.vo-D3wWRw9L.cjs} +0 -0
  378. /package/dist/{time.vo-DkYYGYp6.js → time.vo-tNheinXm.js} +0 -0
  379. /package/dist/{toEmpty-CgAl3097.js → toEmpty-8Zax1MPd.js} +0 -0
  380. /package/dist/{toEmpty-DAMmNB5r.cjs → toEmpty-CYAbupM4.cjs} +0 -0
  381. /package/dist/{token-id.vo-ClsroxHO.js → token-id.vo-Bvwhr3ZE.js} +0 -0
  382. /package/dist/{token-id.vo-BxG9TG0O.cjs → token-id.vo-DXv5uS9n.cjs} +0 -0
  383. /package/dist/{util-DxzlYNS5.js → util-C8a4fA9p.js} +0 -0
  384. /package/dist/{util-CmdAhheh.cjs → util-CzeB3hfa.cjs} +0 -0
  385. /package/dist/{util-selector-CcK-GAdE.js → util-selector-BSTsxgne.js} +0 -0
  386. /package/dist/{util-selector-BcAncU4L.cjs → util-selector-BWPH68_l.cjs} +0 -0
  387. /package/dist/{while-active-BpppWuCs.js → while-active-B0lWy_6l.js} +0 -0
  388. /package/dist/{while-active-Dhc2LwOm.cjs → while-active-Dsowp0Fi.cjs} +0 -0
@@ -0,0 +1,3851 @@
1
+ //#region ../../node_modules/@scure/bip32/node_modules/@noble/hashes/utils.js
2
+ /**
3
+ * Utilities for hex, bytes, CSPRNG.
4
+ * @module
5
+ */
6
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
7
+ /** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
8
+ function isBytes$1(a) {
9
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
10
+ }
11
+ /** Asserts something is positive integer. */
12
+ function anumber$1(n, title = "") {
13
+ if (!Number.isSafeInteger(n) || n < 0) {
14
+ const prefix = title && `"${title}" `;
15
+ throw new Error(`${prefix}expected integer >= 0, got ${n}`);
16
+ }
17
+ }
18
+ /** Asserts something is Uint8Array. */
19
+ function abytes$1(value, length, title = "") {
20
+ const bytes = isBytes$1(value);
21
+ const len = value?.length;
22
+ const needsLen = length !== void 0;
23
+ if (!bytes || needsLen && len !== length) {
24
+ const prefix = title && `"${title}" `;
25
+ const ofLen = needsLen ? ` of length ${length}` : "";
26
+ const got = bytes ? `length=${len}` : `type=${typeof value}`;
27
+ throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
28
+ }
29
+ return value;
30
+ }
31
+ /** Asserts something is hash */
32
+ function ahash(h) {
33
+ if (typeof h !== "function" || typeof h.create !== "function") throw new Error("Hash must wrapped by utils.createHasher");
34
+ anumber$1(h.outputLen);
35
+ anumber$1(h.blockLen);
36
+ }
37
+ /** Asserts a hash instance has not been destroyed / finished */
38
+ function aexists(instance, checkFinished = true) {
39
+ if (instance.destroyed) throw new Error("Hash instance has been destroyed");
40
+ if (checkFinished && instance.finished) throw new Error("Hash#digest() has already been called");
41
+ }
42
+ /** Asserts output is properly-sized byte array */
43
+ function aoutput(out, instance) {
44
+ abytes$1(out, void 0, "digestInto() output");
45
+ const min = instance.outputLen;
46
+ if (out.length < min) throw new Error("\"digestInto() output\" expected to be of length >=" + min);
47
+ }
48
+ /** Zeroize a byte array. Warning: JS provides no guarantees. */
49
+ function clean(...arrays) {
50
+ for (let i = 0; i < arrays.length; i++) arrays[i].fill(0);
51
+ }
52
+ /** Create DataView of an array for easy byte-level manipulation. */
53
+ function createView(arr) {
54
+ return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
55
+ }
56
+ /** The rotate right (circular right shift) operation for uint32 */
57
+ function rotr(word, shift) {
58
+ return word << 32 - shift | word >>> shift;
59
+ }
60
+ /** The rotate left (circular left shift) operation for uint32 */
61
+ function rotl(word, shift) {
62
+ return word << shift | word >>> 32 - shift >>> 0;
63
+ }
64
+ new Uint8Array(new Uint32Array([287454020]).buffer)[0];
65
+ const hasHexBuiltin$1 = typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function";
66
+ const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
67
+ /**
68
+ * Convert byte array to hex string. Uses built-in function, when available.
69
+ * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
70
+ */
71
+ function bytesToHex(bytes) {
72
+ abytes$1(bytes);
73
+ if (hasHexBuiltin$1) return bytes.toHex();
74
+ let hex = "";
75
+ for (let i = 0; i < bytes.length; i++) hex += hexes[bytes[i]];
76
+ return hex;
77
+ }
78
+ const asciis = {
79
+ _0: 48,
80
+ _9: 57,
81
+ A: 65,
82
+ F: 70,
83
+ a: 97,
84
+ f: 102
85
+ };
86
+ function asciiToBase16(ch) {
87
+ if (ch >= asciis._0 && ch <= asciis._9) return ch - asciis._0;
88
+ if (ch >= asciis.A && ch <= asciis.F) return ch - (asciis.A - 10);
89
+ if (ch >= asciis.a && ch <= asciis.f) return ch - (asciis.a - 10);
90
+ }
91
+ /**
92
+ * Convert hex string to byte array. Uses built-in function, when available.
93
+ * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
94
+ */
95
+ function hexToBytes(hex) {
96
+ if (typeof hex !== "string") throw new Error("hex string expected, got " + typeof hex);
97
+ if (hasHexBuiltin$1) return Uint8Array.fromHex(hex);
98
+ const hl = hex.length;
99
+ const al = hl / 2;
100
+ if (hl % 2) throw new Error("hex string expected, got unpadded hex of length " + hl);
101
+ const array = new Uint8Array(al);
102
+ for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
103
+ const n1 = asciiToBase16(hex.charCodeAt(hi));
104
+ const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
105
+ if (n1 === void 0 || n2 === void 0) {
106
+ const char = hex[hi] + hex[hi + 1];
107
+ throw new Error("hex string expected, got non-hex character \"" + char + "\" at index " + hi);
108
+ }
109
+ array[ai] = n1 * 16 + n2;
110
+ }
111
+ return array;
112
+ }
113
+ /** Copies several Uint8Arrays into one. */
114
+ function concatBytes(...arrays) {
115
+ let sum = 0;
116
+ for (let i = 0; i < arrays.length; i++) {
117
+ const a = arrays[i];
118
+ abytes$1(a);
119
+ sum += a.length;
120
+ }
121
+ const res = new Uint8Array(sum);
122
+ for (let i = 0, pad = 0; i < arrays.length; i++) {
123
+ const a = arrays[i];
124
+ res.set(a, pad);
125
+ pad += a.length;
126
+ }
127
+ return res;
128
+ }
129
+ /** Creates function with outputLen, blockLen, create properties from a class constructor. */
130
+ function createHasher$1(hashCons, info = {}) {
131
+ const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
132
+ const tmp = hashCons(void 0);
133
+ hashC.outputLen = tmp.outputLen;
134
+ hashC.blockLen = tmp.blockLen;
135
+ hashC.create = (opts) => hashCons(opts);
136
+ Object.assign(hashC, info);
137
+ return Object.freeze(hashC);
138
+ }
139
+ /** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */
140
+ function randomBytes(bytesLength = 32) {
141
+ const cr = typeof globalThis === "object" ? globalThis.crypto : null;
142
+ if (typeof cr?.getRandomValues !== "function") throw new Error("crypto.getRandomValues must be defined");
143
+ return cr.getRandomValues(new Uint8Array(bytesLength));
144
+ }
145
+ /** Creates OID opts for NIST hashes, with prefix 06 09 60 86 48 01 65 03 04 02. */
146
+ const oidNist = (suffix) => ({ oid: Uint8Array.from([
147
+ 6,
148
+ 9,
149
+ 96,
150
+ 134,
151
+ 72,
152
+ 1,
153
+ 101,
154
+ 3,
155
+ 4,
156
+ 2,
157
+ suffix
158
+ ]) });
159
+ //#endregion
160
+ //#region ../../node_modules/@scure/bip32/node_modules/@noble/hashes/_md.js
161
+ /**
162
+ * Internal Merkle-Damgard hash utils.
163
+ * @module
164
+ */
165
+ /** Choice: a ? b : c */
166
+ function Chi(a, b, c) {
167
+ return a & b ^ ~a & c;
168
+ }
169
+ /** Majority function, true if any two inputs is true. */
170
+ function Maj(a, b, c) {
171
+ return a & b ^ a & c ^ b & c;
172
+ }
173
+ /**
174
+ * Merkle-Damgard hash construction base class.
175
+ * Could be used to create MD5, RIPEMD, SHA1, SHA2.
176
+ */
177
+ var HashMD = class {
178
+ blockLen;
179
+ outputLen;
180
+ padOffset;
181
+ isLE;
182
+ buffer;
183
+ view;
184
+ finished = false;
185
+ length = 0;
186
+ pos = 0;
187
+ destroyed = false;
188
+ constructor(blockLen, outputLen, padOffset, isLE) {
189
+ this.blockLen = blockLen;
190
+ this.outputLen = outputLen;
191
+ this.padOffset = padOffset;
192
+ this.isLE = isLE;
193
+ this.buffer = new Uint8Array(blockLen);
194
+ this.view = createView(this.buffer);
195
+ }
196
+ update(data) {
197
+ aexists(this);
198
+ abytes$1(data);
199
+ const { view, buffer, blockLen } = this;
200
+ const len = data.length;
201
+ for (let pos = 0; pos < len;) {
202
+ const take = Math.min(blockLen - this.pos, len - pos);
203
+ if (take === blockLen) {
204
+ const dataView = createView(data);
205
+ for (; blockLen <= len - pos; pos += blockLen) this.process(dataView, pos);
206
+ continue;
207
+ }
208
+ buffer.set(data.subarray(pos, pos + take), this.pos);
209
+ this.pos += take;
210
+ pos += take;
211
+ if (this.pos === blockLen) {
212
+ this.process(view, 0);
213
+ this.pos = 0;
214
+ }
215
+ }
216
+ this.length += data.length;
217
+ this.roundClean();
218
+ return this;
219
+ }
220
+ digestInto(out) {
221
+ aexists(this);
222
+ aoutput(out, this);
223
+ this.finished = true;
224
+ const { buffer, view, blockLen, isLE } = this;
225
+ let { pos } = this;
226
+ buffer[pos++] = 128;
227
+ clean(this.buffer.subarray(pos));
228
+ if (this.padOffset > blockLen - pos) {
229
+ this.process(view, 0);
230
+ pos = 0;
231
+ }
232
+ for (let i = pos; i < blockLen; i++) buffer[i] = 0;
233
+ view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE);
234
+ this.process(view, 0);
235
+ const oview = createView(out);
236
+ const len = this.outputLen;
237
+ if (len % 4) throw new Error("_sha2: outputLen must be aligned to 32bit");
238
+ const outLen = len / 4;
239
+ const state = this.get();
240
+ if (outLen > state.length) throw new Error("_sha2: outputLen bigger than state");
241
+ for (let i = 0; i < outLen; i++) oview.setUint32(4 * i, state[i], isLE);
242
+ }
243
+ digest() {
244
+ const { buffer, outputLen } = this;
245
+ this.digestInto(buffer);
246
+ const res = buffer.slice(0, outputLen);
247
+ this.destroy();
248
+ return res;
249
+ }
250
+ _cloneInto(to) {
251
+ to ||= new this.constructor();
252
+ to.set(...this.get());
253
+ const { blockLen, buffer, length, finished, destroyed, pos } = this;
254
+ to.destroyed = destroyed;
255
+ to.finished = finished;
256
+ to.length = length;
257
+ to.pos = pos;
258
+ if (length % blockLen) to.buffer.set(buffer);
259
+ return to;
260
+ }
261
+ clone() {
262
+ return this._cloneInto();
263
+ }
264
+ };
265
+ /**
266
+ * Initial SHA-2 state: fractional parts of square roots of first 16 primes 2..53.
267
+ * Check out `test/misc/sha2-gen-iv.js` for recomputation guide.
268
+ */
269
+ /** Initial SHA256 state. Bits 0..32 of frac part of sqrt of primes 2..19 */
270
+ const SHA256_IV = /* @__PURE__ */ Uint32Array.from([
271
+ 1779033703,
272
+ 3144134277,
273
+ 1013904242,
274
+ 2773480762,
275
+ 1359893119,
276
+ 2600822924,
277
+ 528734635,
278
+ 1541459225
279
+ ]);
280
+ /** Initial SHA512 state. Bits 0..64 of frac part of sqrt of primes 2..19 */
281
+ const SHA512_IV = /* @__PURE__ */ Uint32Array.from([
282
+ 1779033703,
283
+ 4089235720,
284
+ 3144134277,
285
+ 2227873595,
286
+ 1013904242,
287
+ 4271175723,
288
+ 2773480762,
289
+ 1595750129,
290
+ 1359893119,
291
+ 2917565137,
292
+ 2600822924,
293
+ 725511199,
294
+ 528734635,
295
+ 4215389547,
296
+ 1541459225,
297
+ 327033209
298
+ ]);
299
+ //#endregion
300
+ //#region ../../node_modules/@scure/bip32/node_modules/@noble/hashes/_u64.js
301
+ /**
302
+ * Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.
303
+ * @todo re-check https://issues.chromium.org/issues/42212588
304
+ * @module
305
+ */
306
+ const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
307
+ const _32n = /* @__PURE__ */ BigInt(32);
308
+ function fromBig(n, le = false) {
309
+ if (le) return {
310
+ h: Number(n & U32_MASK64),
311
+ l: Number(n >> _32n & U32_MASK64)
312
+ };
313
+ return {
314
+ h: Number(n >> _32n & U32_MASK64) | 0,
315
+ l: Number(n & U32_MASK64) | 0
316
+ };
317
+ }
318
+ function split(lst, le = false) {
319
+ const len = lst.length;
320
+ let Ah = new Uint32Array(len);
321
+ let Al = new Uint32Array(len);
322
+ for (let i = 0; i < len; i++) {
323
+ const { h, l } = fromBig(lst[i], le);
324
+ [Ah[i], Al[i]] = [h, l];
325
+ }
326
+ return [Ah, Al];
327
+ }
328
+ const shrSH = (h, _l, s) => h >>> s;
329
+ const shrSL = (h, l, s) => h << 32 - s | l >>> s;
330
+ const rotrSH = (h, l, s) => h >>> s | l << 32 - s;
331
+ const rotrSL = (h, l, s) => h << 32 - s | l >>> s;
332
+ const rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
333
+ const rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
334
+ function add(Ah, Al, Bh, Bl) {
335
+ const l = (Al >>> 0) + (Bl >>> 0);
336
+ return {
337
+ h: Ah + Bh + (l / 2 ** 32 | 0) | 0,
338
+ l: l | 0
339
+ };
340
+ }
341
+ const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
342
+ const add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
343
+ const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
344
+ const add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
345
+ const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
346
+ const add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
347
+ //#endregion
348
+ //#region ../../node_modules/@scure/bip32/node_modules/@noble/hashes/sha2.js
349
+ /**
350
+ * SHA2 hash function. A.k.a. sha256, sha384, sha512, sha512_224, sha512_256.
351
+ * SHA256 is the fastest hash implementable in JS, even faster than Blake3.
352
+ * Check out [RFC 4634](https://www.rfc-editor.org/rfc/rfc4634) and
353
+ * [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).
354
+ * @module
355
+ */
356
+ /**
357
+ * Round constants:
358
+ * First 32 bits of fractional parts of the cube roots of the first 64 primes 2..311)
359
+ */
360
+ const SHA256_K = /* @__PURE__ */ Uint32Array.from([
361
+ 1116352408,
362
+ 1899447441,
363
+ 3049323471,
364
+ 3921009573,
365
+ 961987163,
366
+ 1508970993,
367
+ 2453635748,
368
+ 2870763221,
369
+ 3624381080,
370
+ 310598401,
371
+ 607225278,
372
+ 1426881987,
373
+ 1925078388,
374
+ 2162078206,
375
+ 2614888103,
376
+ 3248222580,
377
+ 3835390401,
378
+ 4022224774,
379
+ 264347078,
380
+ 604807628,
381
+ 770255983,
382
+ 1249150122,
383
+ 1555081692,
384
+ 1996064986,
385
+ 2554220882,
386
+ 2821834349,
387
+ 2952996808,
388
+ 3210313671,
389
+ 3336571891,
390
+ 3584528711,
391
+ 113926993,
392
+ 338241895,
393
+ 666307205,
394
+ 773529912,
395
+ 1294757372,
396
+ 1396182291,
397
+ 1695183700,
398
+ 1986661051,
399
+ 2177026350,
400
+ 2456956037,
401
+ 2730485921,
402
+ 2820302411,
403
+ 3259730800,
404
+ 3345764771,
405
+ 3516065817,
406
+ 3600352804,
407
+ 4094571909,
408
+ 275423344,
409
+ 430227734,
410
+ 506948616,
411
+ 659060556,
412
+ 883997877,
413
+ 958139571,
414
+ 1322822218,
415
+ 1537002063,
416
+ 1747873779,
417
+ 1955562222,
418
+ 2024104815,
419
+ 2227730452,
420
+ 2361852424,
421
+ 2428436474,
422
+ 2756734187,
423
+ 3204031479,
424
+ 3329325298
425
+ ]);
426
+ /** Reusable temporary buffer. "W" comes straight from spec. */
427
+ const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
428
+ /** Internal 32-byte base SHA2 hash class. */
429
+ var SHA2_32B = class extends HashMD {
430
+ constructor(outputLen) {
431
+ super(64, outputLen, 8, false);
432
+ }
433
+ get() {
434
+ const { A, B, C, D, E, F, G, H } = this;
435
+ return [
436
+ A,
437
+ B,
438
+ C,
439
+ D,
440
+ E,
441
+ F,
442
+ G,
443
+ H
444
+ ];
445
+ }
446
+ set(A, B, C, D, E, F, G, H) {
447
+ this.A = A | 0;
448
+ this.B = B | 0;
449
+ this.C = C | 0;
450
+ this.D = D | 0;
451
+ this.E = E | 0;
452
+ this.F = F | 0;
453
+ this.G = G | 0;
454
+ this.H = H | 0;
455
+ }
456
+ process(view, offset) {
457
+ for (let i = 0; i < 16; i++, offset += 4) SHA256_W[i] = view.getUint32(offset, false);
458
+ for (let i = 16; i < 64; i++) {
459
+ const W15 = SHA256_W[i - 15];
460
+ const W2 = SHA256_W[i - 2];
461
+ const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
462
+ SHA256_W[i] = (rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10) + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
463
+ }
464
+ let { A, B, C, D, E, F, G, H } = this;
465
+ for (let i = 0; i < 64; i++) {
466
+ const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
467
+ const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
468
+ const T2 = (rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22)) + Maj(A, B, C) | 0;
469
+ H = G;
470
+ G = F;
471
+ F = E;
472
+ E = D + T1 | 0;
473
+ D = C;
474
+ C = B;
475
+ B = A;
476
+ A = T1 + T2 | 0;
477
+ }
478
+ A = A + this.A | 0;
479
+ B = B + this.B | 0;
480
+ C = C + this.C | 0;
481
+ D = D + this.D | 0;
482
+ E = E + this.E | 0;
483
+ F = F + this.F | 0;
484
+ G = G + this.G | 0;
485
+ H = H + this.H | 0;
486
+ this.set(A, B, C, D, E, F, G, H);
487
+ }
488
+ roundClean() {
489
+ clean(SHA256_W);
490
+ }
491
+ destroy() {
492
+ this.set(0, 0, 0, 0, 0, 0, 0, 0);
493
+ clean(this.buffer);
494
+ }
495
+ };
496
+ /** Internal SHA2-256 hash class. */
497
+ var _SHA256 = class extends SHA2_32B {
498
+ A = SHA256_IV[0] | 0;
499
+ B = SHA256_IV[1] | 0;
500
+ C = SHA256_IV[2] | 0;
501
+ D = SHA256_IV[3] | 0;
502
+ E = SHA256_IV[4] | 0;
503
+ F = SHA256_IV[5] | 0;
504
+ G = SHA256_IV[6] | 0;
505
+ H = SHA256_IV[7] | 0;
506
+ constructor() {
507
+ super(32);
508
+ }
509
+ };
510
+ const K512 = split([
511
+ "0x428a2f98d728ae22",
512
+ "0x7137449123ef65cd",
513
+ "0xb5c0fbcfec4d3b2f",
514
+ "0xe9b5dba58189dbbc",
515
+ "0x3956c25bf348b538",
516
+ "0x59f111f1b605d019",
517
+ "0x923f82a4af194f9b",
518
+ "0xab1c5ed5da6d8118",
519
+ "0xd807aa98a3030242",
520
+ "0x12835b0145706fbe",
521
+ "0x243185be4ee4b28c",
522
+ "0x550c7dc3d5ffb4e2",
523
+ "0x72be5d74f27b896f",
524
+ "0x80deb1fe3b1696b1",
525
+ "0x9bdc06a725c71235",
526
+ "0xc19bf174cf692694",
527
+ "0xe49b69c19ef14ad2",
528
+ "0xefbe4786384f25e3",
529
+ "0x0fc19dc68b8cd5b5",
530
+ "0x240ca1cc77ac9c65",
531
+ "0x2de92c6f592b0275",
532
+ "0x4a7484aa6ea6e483",
533
+ "0x5cb0a9dcbd41fbd4",
534
+ "0x76f988da831153b5",
535
+ "0x983e5152ee66dfab",
536
+ "0xa831c66d2db43210",
537
+ "0xb00327c898fb213f",
538
+ "0xbf597fc7beef0ee4",
539
+ "0xc6e00bf33da88fc2",
540
+ "0xd5a79147930aa725",
541
+ "0x06ca6351e003826f",
542
+ "0x142929670a0e6e70",
543
+ "0x27b70a8546d22ffc",
544
+ "0x2e1b21385c26c926",
545
+ "0x4d2c6dfc5ac42aed",
546
+ "0x53380d139d95b3df",
547
+ "0x650a73548baf63de",
548
+ "0x766a0abb3c77b2a8",
549
+ "0x81c2c92e47edaee6",
550
+ "0x92722c851482353b",
551
+ "0xa2bfe8a14cf10364",
552
+ "0xa81a664bbc423001",
553
+ "0xc24b8b70d0f89791",
554
+ "0xc76c51a30654be30",
555
+ "0xd192e819d6ef5218",
556
+ "0xd69906245565a910",
557
+ "0xf40e35855771202a",
558
+ "0x106aa07032bbd1b8",
559
+ "0x19a4c116b8d2d0c8",
560
+ "0x1e376c085141ab53",
561
+ "0x2748774cdf8eeb99",
562
+ "0x34b0bcb5e19b48a8",
563
+ "0x391c0cb3c5c95a63",
564
+ "0x4ed8aa4ae3418acb",
565
+ "0x5b9cca4f7763e373",
566
+ "0x682e6ff3d6b2b8a3",
567
+ "0x748f82ee5defb2fc",
568
+ "0x78a5636f43172f60",
569
+ "0x84c87814a1f0ab72",
570
+ "0x8cc702081a6439ec",
571
+ "0x90befffa23631e28",
572
+ "0xa4506cebde82bde9",
573
+ "0xbef9a3f7b2c67915",
574
+ "0xc67178f2e372532b",
575
+ "0xca273eceea26619c",
576
+ "0xd186b8c721c0c207",
577
+ "0xeada7dd6cde0eb1e",
578
+ "0xf57d4f7fee6ed178",
579
+ "0x06f067aa72176fba",
580
+ "0x0a637dc5a2c898a6",
581
+ "0x113f9804bef90dae",
582
+ "0x1b710b35131c471b",
583
+ "0x28db77f523047d84",
584
+ "0x32caab7b40c72493",
585
+ "0x3c9ebe0a15c9bebc",
586
+ "0x431d67c49c100d4c",
587
+ "0x4cc5d4becb3e42b6",
588
+ "0x597f299cfc657e2a",
589
+ "0x5fcb6fab3ad6faec",
590
+ "0x6c44198c4a475817"
591
+ ].map((n) => BigInt(n)));
592
+ const SHA512_Kh = K512[0];
593
+ const SHA512_Kl = K512[1];
594
+ const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
595
+ const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
596
+ /** Internal 64-byte base SHA2 hash class. */
597
+ var SHA2_64B = class extends HashMD {
598
+ constructor(outputLen) {
599
+ super(128, outputLen, 16, false);
600
+ }
601
+ get() {
602
+ const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
603
+ return [
604
+ Ah,
605
+ Al,
606
+ Bh,
607
+ Bl,
608
+ Ch,
609
+ Cl,
610
+ Dh,
611
+ Dl,
612
+ Eh,
613
+ El,
614
+ Fh,
615
+ Fl,
616
+ Gh,
617
+ Gl,
618
+ Hh,
619
+ Hl
620
+ ];
621
+ }
622
+ set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
623
+ this.Ah = Ah | 0;
624
+ this.Al = Al | 0;
625
+ this.Bh = Bh | 0;
626
+ this.Bl = Bl | 0;
627
+ this.Ch = Ch | 0;
628
+ this.Cl = Cl | 0;
629
+ this.Dh = Dh | 0;
630
+ this.Dl = Dl | 0;
631
+ this.Eh = Eh | 0;
632
+ this.El = El | 0;
633
+ this.Fh = Fh | 0;
634
+ this.Fl = Fl | 0;
635
+ this.Gh = Gh | 0;
636
+ this.Gl = Gl | 0;
637
+ this.Hh = Hh | 0;
638
+ this.Hl = Hl | 0;
639
+ }
640
+ process(view, offset) {
641
+ for (let i = 0; i < 16; i++, offset += 4) {
642
+ SHA512_W_H[i] = view.getUint32(offset);
643
+ SHA512_W_L[i] = view.getUint32(offset += 4);
644
+ }
645
+ for (let i = 16; i < 80; i++) {
646
+ const W15h = SHA512_W_H[i - 15] | 0;
647
+ const W15l = SHA512_W_L[i - 15] | 0;
648
+ const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
649
+ const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
650
+ const W2h = SHA512_W_H[i - 2] | 0;
651
+ const W2l = SHA512_W_L[i - 2] | 0;
652
+ const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
653
+ const SUMl = add4L(s0l, rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6), SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
654
+ SHA512_W_H[i] = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]) | 0;
655
+ SHA512_W_L[i] = SUMl | 0;
656
+ }
657
+ let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
658
+ for (let i = 0; i < 80; i++) {
659
+ const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
660
+ const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
661
+ const CHIh = Eh & Fh ^ ~Eh & Gh;
662
+ const CHIl = El & Fl ^ ~El & Gl;
663
+ const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
664
+ const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
665
+ const T1l = T1ll | 0;
666
+ const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
667
+ const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
668
+ const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
669
+ const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
670
+ Hh = Gh | 0;
671
+ Hl = Gl | 0;
672
+ Gh = Fh | 0;
673
+ Gl = Fl | 0;
674
+ Fh = Eh | 0;
675
+ Fl = El | 0;
676
+ ({h: Eh, l: El} = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
677
+ Dh = Ch | 0;
678
+ Dl = Cl | 0;
679
+ Ch = Bh | 0;
680
+ Cl = Bl | 0;
681
+ Bh = Ah | 0;
682
+ Bl = Al | 0;
683
+ const All = add3L(T1l, sigma0l, MAJl);
684
+ Ah = add3H(All, T1h, sigma0h, MAJh);
685
+ Al = All | 0;
686
+ }
687
+ ({h: Ah, l: Al} = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
688
+ ({h: Bh, l: Bl} = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
689
+ ({h: Ch, l: Cl} = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
690
+ ({h: Dh, l: Dl} = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
691
+ ({h: Eh, l: El} = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
692
+ ({h: Fh, l: Fl} = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
693
+ ({h: Gh, l: Gl} = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
694
+ ({h: Hh, l: Hl} = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
695
+ this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
696
+ }
697
+ roundClean() {
698
+ clean(SHA512_W_H, SHA512_W_L);
699
+ }
700
+ destroy() {
701
+ clean(this.buffer);
702
+ this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
703
+ }
704
+ };
705
+ /** Internal SHA2-512 hash class. */
706
+ var _SHA512 = class extends SHA2_64B {
707
+ Ah = SHA512_IV[0] | 0;
708
+ Al = SHA512_IV[1] | 0;
709
+ Bh = SHA512_IV[2] | 0;
710
+ Bl = SHA512_IV[3] | 0;
711
+ Ch = SHA512_IV[4] | 0;
712
+ Cl = SHA512_IV[5] | 0;
713
+ Dh = SHA512_IV[6] | 0;
714
+ Dl = SHA512_IV[7] | 0;
715
+ Eh = SHA512_IV[8] | 0;
716
+ El = SHA512_IV[9] | 0;
717
+ Fh = SHA512_IV[10] | 0;
718
+ Fl = SHA512_IV[11] | 0;
719
+ Gh = SHA512_IV[12] | 0;
720
+ Gl = SHA512_IV[13] | 0;
721
+ Hh = SHA512_IV[14] | 0;
722
+ Hl = SHA512_IV[15] | 0;
723
+ constructor() {
724
+ super(64);
725
+ }
726
+ };
727
+ /**
728
+ * SHA2-256 hash function from RFC 4634. In JS it's the fastest: even faster than Blake3. Some info:
729
+ *
730
+ * - Trying 2^128 hashes would get 50% chance of collision, using birthday attack.
731
+ * - BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
732
+ * - Each sha256 hash is executing 2^18 bit operations.
733
+ * - Good 2024 ASICs can do 200Th/sec with 3500 watts of power, corresponding to 2^36 hashes/joule.
734
+ */
735
+ const sha256 = /* @__PURE__ */ createHasher$1(() => new _SHA256(), /* @__PURE__ */ oidNist(1));
736
+ /** SHA2-512 hash function from RFC 4634. */
737
+ const sha512 = /* @__PURE__ */ createHasher$1(() => new _SHA512(), /* @__PURE__ */ oidNist(3));
738
+ //#endregion
739
+ //#region ../../node_modules/@scure/bip32/node_modules/@noble/curves/utils.js
740
+ /**
741
+ * Hex, bytes and number utilities.
742
+ * @module
743
+ */
744
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
745
+ const _0n$3 = /* @__PURE__ */ BigInt(0);
746
+ const _1n$3 = /* @__PURE__ */ BigInt(1);
747
+ function abool(value, title = "") {
748
+ if (typeof value !== "boolean") {
749
+ const prefix = title && `"${title}" `;
750
+ throw new Error(prefix + "expected boolean, got type=" + typeof value);
751
+ }
752
+ return value;
753
+ }
754
+ function abignumber(n) {
755
+ if (typeof n === "bigint") {
756
+ if (!isPosBig(n)) throw new Error("positive bigint expected, got " + n);
757
+ } else anumber$1(n);
758
+ return n;
759
+ }
760
+ function asafenumber(value, title = "") {
761
+ if (!Number.isSafeInteger(value)) {
762
+ const prefix = title && `"${title}" `;
763
+ throw new Error(prefix + "expected safe integer, got type=" + typeof value);
764
+ }
765
+ }
766
+ function numberToHexUnpadded(num) {
767
+ const hex = abignumber(num).toString(16);
768
+ return hex.length & 1 ? "0" + hex : hex;
769
+ }
770
+ function hexToNumber(hex) {
771
+ if (typeof hex !== "string") throw new Error("hex string expected, got " + typeof hex);
772
+ return hex === "" ? _0n$3 : BigInt("0x" + hex);
773
+ }
774
+ function bytesToNumberBE(bytes) {
775
+ return hexToNumber(bytesToHex(bytes));
776
+ }
777
+ function bytesToNumberLE(bytes) {
778
+ return hexToNumber(bytesToHex(copyBytes(abytes$1(bytes)).reverse()));
779
+ }
780
+ function numberToBytesBE(n, len) {
781
+ anumber$1(len);
782
+ n = abignumber(n);
783
+ const res = hexToBytes(n.toString(16).padStart(len * 2, "0"));
784
+ if (res.length !== len) throw new Error("number too large");
785
+ return res;
786
+ }
787
+ function numberToBytesLE(n, len) {
788
+ return numberToBytesBE(n, len).reverse();
789
+ }
790
+ /**
791
+ * Copies Uint8Array. We can't use u8a.slice(), because u8a can be Buffer,
792
+ * and Buffer#slice creates mutable copy. Never use Buffers!
793
+ */
794
+ function copyBytes(bytes) {
795
+ return Uint8Array.from(bytes);
796
+ }
797
+ /**
798
+ * Decodes 7-bit ASCII string to Uint8Array, throws on non-ascii symbols
799
+ * Should be safe to use for things expected to be ASCII.
800
+ * Returns exact same result as `TextEncoder` for ASCII or throws.
801
+ */
802
+ function asciiToBytes(ascii) {
803
+ return Uint8Array.from(ascii, (c, i) => {
804
+ const charCode = c.charCodeAt(0);
805
+ if (c.length !== 1 || charCode > 127) throw new Error(`string contains non-ASCII character "${ascii[i]}" with code ${charCode} at position ${i}`);
806
+ return charCode;
807
+ });
808
+ }
809
+ const isPosBig = (n) => typeof n === "bigint" && _0n$3 <= n;
810
+ function inRange(n, min, max) {
811
+ return isPosBig(n) && isPosBig(min) && isPosBig(max) && min <= n && n < max;
812
+ }
813
+ /**
814
+ * Asserts min <= n < max. NOTE: It's < max and not <= max.
815
+ * @example
816
+ * aInRange('x', x, 1n, 256n); // would assume x is in (1n..255n)
817
+ */
818
+ function aInRange(title, n, min, max) {
819
+ if (!inRange(n, min, max)) throw new Error("expected valid " + title + ": " + min + " <= n < " + max + ", got " + n);
820
+ }
821
+ /**
822
+ * Calculates amount of bits in a bigint.
823
+ * Same as `n.toString(2).length`
824
+ * TODO: merge with nLength in modular
825
+ */
826
+ function bitLen(n) {
827
+ let len;
828
+ for (len = 0; n > _0n$3; n >>= _1n$3, len += 1);
829
+ return len;
830
+ }
831
+ /**
832
+ * Calculate mask for N bits. Not using ** operator with bigints because of old engines.
833
+ * Same as BigInt(`0b${Array(i).fill('1').join('')}`)
834
+ */
835
+ const bitMask = (n) => (_1n$3 << BigInt(n)) - _1n$3;
836
+ /**
837
+ * Minimal HMAC-DRBG from NIST 800-90 for RFC6979 sigs.
838
+ * @returns function that will call DRBG until 2nd arg returns something meaningful
839
+ * @example
840
+ * const drbg = createHmacDRBG<Key>(32, 32, hmac);
841
+ * drbg(seed, bytesToKey); // bytesToKey must return Key or undefined
842
+ */
843
+ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
844
+ anumber$1(hashLen, "hashLen");
845
+ anumber$1(qByteLen, "qByteLen");
846
+ if (typeof hmacFn !== "function") throw new Error("hmacFn must be a function");
847
+ const u8n = (len) => new Uint8Array(len);
848
+ const NULL = Uint8Array.of();
849
+ const byte0 = Uint8Array.of(0);
850
+ const byte1 = Uint8Array.of(1);
851
+ const _maxDrbgIters = 1e3;
852
+ let v = u8n(hashLen);
853
+ let k = u8n(hashLen);
854
+ let i = 0;
855
+ const reset = () => {
856
+ v.fill(1);
857
+ k.fill(0);
858
+ i = 0;
859
+ };
860
+ const h = (...msgs) => hmacFn(k, concatBytes(v, ...msgs));
861
+ const reseed = (seed = NULL) => {
862
+ k = h(byte0, seed);
863
+ v = h();
864
+ if (seed.length === 0) return;
865
+ k = h(byte1, seed);
866
+ v = h();
867
+ };
868
+ const gen = () => {
869
+ if (i++ >= _maxDrbgIters) throw new Error("drbg: tried max amount of iterations");
870
+ let len = 0;
871
+ const out = [];
872
+ while (len < qByteLen) {
873
+ v = h();
874
+ const sl = v.slice();
875
+ out.push(sl);
876
+ len += v.length;
877
+ }
878
+ return concatBytes(...out);
879
+ };
880
+ const genUntil = (seed, pred) => {
881
+ reset();
882
+ reseed(seed);
883
+ let res = void 0;
884
+ while (!(res = pred(gen()))) reseed();
885
+ reset();
886
+ return res;
887
+ };
888
+ return genUntil;
889
+ }
890
+ function validateObject(object, fields = {}, optFields = {}) {
891
+ if (!object || typeof object !== "object") throw new Error("expected valid options object");
892
+ function checkField(fieldName, expectedType, isOpt) {
893
+ const val = object[fieldName];
894
+ if (isOpt && val === void 0) return;
895
+ const current = typeof val;
896
+ if (current !== expectedType || val === null) throw new Error(`param "${fieldName}" is invalid: expected ${expectedType}, got ${current}`);
897
+ }
898
+ const iter = (f, isOpt) => Object.entries(f).forEach(([k, v]) => checkField(k, v, isOpt));
899
+ iter(fields, false);
900
+ iter(optFields, true);
901
+ }
902
+ /**
903
+ * Memoizes (caches) computation result.
904
+ * Uses WeakMap: the value is going auto-cleaned by GC after last reference is removed.
905
+ */
906
+ function memoized(fn) {
907
+ const map = /* @__PURE__ */ new WeakMap();
908
+ return (arg, ...args) => {
909
+ const val = map.get(arg);
910
+ if (val !== void 0) return val;
911
+ const computed = fn(arg, ...args);
912
+ map.set(arg, computed);
913
+ return computed;
914
+ };
915
+ }
916
+ //#endregion
917
+ //#region ../../node_modules/@scure/bip32/node_modules/@noble/curves/abstract/modular.js
918
+ /**
919
+ * Utils for modular division and fields.
920
+ * Field over 11 is a finite (Galois) field is integer number operations `mod 11`.
921
+ * There is no division: it is replaced by modular multiplicative inverse.
922
+ * @module
923
+ */
924
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
925
+ const _0n$2 = /* @__PURE__ */ BigInt(0), _1n$2 = /* @__PURE__ */ BigInt(1), _2n$2 = /* @__PURE__ */ BigInt(2);
926
+ const _3n$1 = /* @__PURE__ */ BigInt(3), _4n$1 = /* @__PURE__ */ BigInt(4), _5n = /* @__PURE__ */ BigInt(5);
927
+ const _7n = /* @__PURE__ */ BigInt(7), _8n = /* @__PURE__ */ BigInt(8), _9n = /* @__PURE__ */ BigInt(9);
928
+ const _16n = /* @__PURE__ */ BigInt(16);
929
+ function mod(a, b) {
930
+ const result = a % b;
931
+ return result >= _0n$2 ? result : b + result;
932
+ }
933
+ /** Does `x^(2^power)` mod p. `pow2(30, 4)` == `30^(2^4)` */
934
+ function pow2(x, power, modulo) {
935
+ let res = x;
936
+ while (power-- > _0n$2) {
937
+ res *= res;
938
+ res %= modulo;
939
+ }
940
+ return res;
941
+ }
942
+ /**
943
+ * Inverses number over modulo.
944
+ * Implemented using [Euclidean GCD](https://brilliant.org/wiki/extended-euclidean-algorithm/).
945
+ */
946
+ function invert(number, modulo) {
947
+ if (number === _0n$2) throw new Error("invert: expected non-zero number");
948
+ if (modulo <= _0n$2) throw new Error("invert: expected positive modulus, got " + modulo);
949
+ let a = mod(number, modulo);
950
+ let b = modulo;
951
+ let x = _0n$2, y = _1n$2, u = _1n$2, v = _0n$2;
952
+ while (a !== _0n$2) {
953
+ const q = b / a;
954
+ const r = b % a;
955
+ const m = x - u * q;
956
+ const n = y - v * q;
957
+ b = a, a = r, x = u, y = v, u = m, v = n;
958
+ }
959
+ if (b !== _1n$2) throw new Error("invert: does not exist");
960
+ return mod(x, modulo);
961
+ }
962
+ function assertIsSquare(Fp, root, n) {
963
+ if (!Fp.eql(Fp.sqr(root), n)) throw new Error("Cannot find square root");
964
+ }
965
+ function sqrt3mod4(Fp, n) {
966
+ const p1div4 = (Fp.ORDER + _1n$2) / _4n$1;
967
+ const root = Fp.pow(n, p1div4);
968
+ assertIsSquare(Fp, root, n);
969
+ return root;
970
+ }
971
+ function sqrt5mod8(Fp, n) {
972
+ const p5div8 = (Fp.ORDER - _5n) / _8n;
973
+ const n2 = Fp.mul(n, _2n$2);
974
+ const v = Fp.pow(n2, p5div8);
975
+ const nv = Fp.mul(n, v);
976
+ const i = Fp.mul(Fp.mul(nv, _2n$2), v);
977
+ const root = Fp.mul(nv, Fp.sub(i, Fp.ONE));
978
+ assertIsSquare(Fp, root, n);
979
+ return root;
980
+ }
981
+ function sqrt9mod16(P) {
982
+ const Fp_ = Field(P);
983
+ const tn = tonelliShanks(P);
984
+ const c1 = tn(Fp_, Fp_.neg(Fp_.ONE));
985
+ const c2 = tn(Fp_, c1);
986
+ const c3 = tn(Fp_, Fp_.neg(c1));
987
+ const c4 = (P + _7n) / _16n;
988
+ return (Fp, n) => {
989
+ let tv1 = Fp.pow(n, c4);
990
+ let tv2 = Fp.mul(tv1, c1);
991
+ const tv3 = Fp.mul(tv1, c2);
992
+ const tv4 = Fp.mul(tv1, c3);
993
+ const e1 = Fp.eql(Fp.sqr(tv2), n);
994
+ const e2 = Fp.eql(Fp.sqr(tv3), n);
995
+ tv1 = Fp.cmov(tv1, tv2, e1);
996
+ tv2 = Fp.cmov(tv4, tv3, e2);
997
+ const e3 = Fp.eql(Fp.sqr(tv2), n);
998
+ const root = Fp.cmov(tv1, tv2, e3);
999
+ assertIsSquare(Fp, root, n);
1000
+ return root;
1001
+ };
1002
+ }
1003
+ /**
1004
+ * Tonelli-Shanks square root search algorithm.
1005
+ * 1. https://eprint.iacr.org/2012/685.pdf (page 12)
1006
+ * 2. Square Roots from 1; 24, 51, 10 to Dan Shanks
1007
+ * @param P field order
1008
+ * @returns function that takes field Fp (created from P) and number n
1009
+ */
1010
+ function tonelliShanks(P) {
1011
+ if (P < _3n$1) throw new Error("sqrt is not defined for small field");
1012
+ let Q = P - _1n$2;
1013
+ let S = 0;
1014
+ while (Q % _2n$2 === _0n$2) {
1015
+ Q /= _2n$2;
1016
+ S++;
1017
+ }
1018
+ let Z = _2n$2;
1019
+ const _Fp = Field(P);
1020
+ while (FpLegendre(_Fp, Z) === 1) if (Z++ > 1e3) throw new Error("Cannot find square root: probably non-prime P");
1021
+ if (S === 1) return sqrt3mod4;
1022
+ let cc = _Fp.pow(Z, Q);
1023
+ const Q1div2 = (Q + _1n$2) / _2n$2;
1024
+ return function tonelliSlow(Fp, n) {
1025
+ if (Fp.is0(n)) return n;
1026
+ if (FpLegendre(Fp, n) !== 1) throw new Error("Cannot find square root");
1027
+ let M = S;
1028
+ let c = Fp.mul(Fp.ONE, cc);
1029
+ let t = Fp.pow(n, Q);
1030
+ let R = Fp.pow(n, Q1div2);
1031
+ while (!Fp.eql(t, Fp.ONE)) {
1032
+ if (Fp.is0(t)) return Fp.ZERO;
1033
+ let i = 1;
1034
+ let t_tmp = Fp.sqr(t);
1035
+ while (!Fp.eql(t_tmp, Fp.ONE)) {
1036
+ i++;
1037
+ t_tmp = Fp.sqr(t_tmp);
1038
+ if (i === M) throw new Error("Cannot find square root");
1039
+ }
1040
+ const exponent = _1n$2 << BigInt(M - i - 1);
1041
+ const b = Fp.pow(c, exponent);
1042
+ M = i;
1043
+ c = Fp.sqr(b);
1044
+ t = Fp.mul(t, c);
1045
+ R = Fp.mul(R, b);
1046
+ }
1047
+ return R;
1048
+ };
1049
+ }
1050
+ /**
1051
+ * Square root for a finite field. Will try optimized versions first:
1052
+ *
1053
+ * 1. P ≡ 3 (mod 4)
1054
+ * 2. P ≡ 5 (mod 8)
1055
+ * 3. P ≡ 9 (mod 16)
1056
+ * 4. Tonelli-Shanks algorithm
1057
+ *
1058
+ * Different algorithms can give different roots, it is up to user to decide which one they want.
1059
+ * For example there is FpSqrtOdd/FpSqrtEven to choice root based on oddness (used for hash-to-curve).
1060
+ */
1061
+ function FpSqrt(P) {
1062
+ if (P % _4n$1 === _3n$1) return sqrt3mod4;
1063
+ if (P % _8n === _5n) return sqrt5mod8;
1064
+ if (P % _16n === _9n) return sqrt9mod16(P);
1065
+ return tonelliShanks(P);
1066
+ }
1067
+ const FIELD_FIELDS = [
1068
+ "create",
1069
+ "isValid",
1070
+ "is0",
1071
+ "neg",
1072
+ "inv",
1073
+ "sqrt",
1074
+ "sqr",
1075
+ "eql",
1076
+ "add",
1077
+ "sub",
1078
+ "mul",
1079
+ "pow",
1080
+ "div",
1081
+ "addN",
1082
+ "subN",
1083
+ "mulN",
1084
+ "sqrN"
1085
+ ];
1086
+ function validateField(field) {
1087
+ validateObject(field, FIELD_FIELDS.reduce((map, val) => {
1088
+ map[val] = "function";
1089
+ return map;
1090
+ }, {
1091
+ ORDER: "bigint",
1092
+ BYTES: "number",
1093
+ BITS: "number"
1094
+ }));
1095
+ return field;
1096
+ }
1097
+ /**
1098
+ * Same as `pow` but for Fp: non-constant-time.
1099
+ * Unsafe in some contexts: uses ladder, so can expose bigint bits.
1100
+ */
1101
+ function FpPow(Fp, num, power) {
1102
+ if (power < _0n$2) throw new Error("invalid exponent, negatives unsupported");
1103
+ if (power === _0n$2) return Fp.ONE;
1104
+ if (power === _1n$2) return num;
1105
+ let p = Fp.ONE;
1106
+ let d = num;
1107
+ while (power > _0n$2) {
1108
+ if (power & _1n$2) p = Fp.mul(p, d);
1109
+ d = Fp.sqr(d);
1110
+ power >>= _1n$2;
1111
+ }
1112
+ return p;
1113
+ }
1114
+ /**
1115
+ * Efficiently invert an array of Field elements.
1116
+ * Exception-free. Will return `undefined` for 0 elements.
1117
+ * @param passZero map 0 to 0 (instead of undefined)
1118
+ */
1119
+ function FpInvertBatch(Fp, nums, passZero = false) {
1120
+ const inverted = new Array(nums.length).fill(passZero ? Fp.ZERO : void 0);
1121
+ const multipliedAcc = nums.reduce((acc, num, i) => {
1122
+ if (Fp.is0(num)) return acc;
1123
+ inverted[i] = acc;
1124
+ return Fp.mul(acc, num);
1125
+ }, Fp.ONE);
1126
+ const invertedAcc = Fp.inv(multipliedAcc);
1127
+ nums.reduceRight((acc, num, i) => {
1128
+ if (Fp.is0(num)) return acc;
1129
+ inverted[i] = Fp.mul(acc, inverted[i]);
1130
+ return Fp.mul(acc, num);
1131
+ }, invertedAcc);
1132
+ return inverted;
1133
+ }
1134
+ /**
1135
+ * Legendre symbol.
1136
+ * Legendre constant is used to calculate Legendre symbol (a | p)
1137
+ * which denotes the value of a^((p-1)/2) (mod p).
1138
+ *
1139
+ * * (a | p) ≡ 1 if a is a square (mod p), quadratic residue
1140
+ * * (a | p) ≡ -1 if a is not a square (mod p), quadratic non residue
1141
+ * * (a | p) ≡ 0 if a ≡ 0 (mod p)
1142
+ */
1143
+ function FpLegendre(Fp, n) {
1144
+ const p1mod2 = (Fp.ORDER - _1n$2) / _2n$2;
1145
+ const powered = Fp.pow(n, p1mod2);
1146
+ const yes = Fp.eql(powered, Fp.ONE);
1147
+ const zero = Fp.eql(powered, Fp.ZERO);
1148
+ const no = Fp.eql(powered, Fp.neg(Fp.ONE));
1149
+ if (!yes && !zero && !no) throw new Error("invalid Legendre symbol result");
1150
+ return yes ? 1 : zero ? 0 : -1;
1151
+ }
1152
+ function nLength(n, nBitLength) {
1153
+ if (nBitLength !== void 0) anumber$1(nBitLength);
1154
+ const _nBitLength = nBitLength !== void 0 ? nBitLength : n.toString(2).length;
1155
+ return {
1156
+ nBitLength: _nBitLength,
1157
+ nByteLength: Math.ceil(_nBitLength / 8)
1158
+ };
1159
+ }
1160
+ var _Field = class {
1161
+ ORDER;
1162
+ BITS;
1163
+ BYTES;
1164
+ isLE;
1165
+ ZERO = _0n$2;
1166
+ ONE = _1n$2;
1167
+ _lengths;
1168
+ _sqrt;
1169
+ _mod;
1170
+ constructor(ORDER, opts = {}) {
1171
+ if (ORDER <= _0n$2) throw new Error("invalid field: expected ORDER > 0, got " + ORDER);
1172
+ let _nbitLength = void 0;
1173
+ this.isLE = false;
1174
+ if (opts != null && typeof opts === "object") {
1175
+ if (typeof opts.BITS === "number") _nbitLength = opts.BITS;
1176
+ if (typeof opts.sqrt === "function") this.sqrt = opts.sqrt;
1177
+ if (typeof opts.isLE === "boolean") this.isLE = opts.isLE;
1178
+ if (opts.allowedLengths) this._lengths = opts.allowedLengths?.slice();
1179
+ if (typeof opts.modFromBytes === "boolean") this._mod = opts.modFromBytes;
1180
+ }
1181
+ const { nBitLength, nByteLength } = nLength(ORDER, _nbitLength);
1182
+ if (nByteLength > 2048) throw new Error("invalid field: expected ORDER of <= 2048 bytes");
1183
+ this.ORDER = ORDER;
1184
+ this.BITS = nBitLength;
1185
+ this.BYTES = nByteLength;
1186
+ this._sqrt = void 0;
1187
+ Object.preventExtensions(this);
1188
+ }
1189
+ create(num) {
1190
+ return mod(num, this.ORDER);
1191
+ }
1192
+ isValid(num) {
1193
+ if (typeof num !== "bigint") throw new Error("invalid field element: expected bigint, got " + typeof num);
1194
+ return _0n$2 <= num && num < this.ORDER;
1195
+ }
1196
+ is0(num) {
1197
+ return num === _0n$2;
1198
+ }
1199
+ isValidNot0(num) {
1200
+ return !this.is0(num) && this.isValid(num);
1201
+ }
1202
+ isOdd(num) {
1203
+ return (num & _1n$2) === _1n$2;
1204
+ }
1205
+ neg(num) {
1206
+ return mod(-num, this.ORDER);
1207
+ }
1208
+ eql(lhs, rhs) {
1209
+ return lhs === rhs;
1210
+ }
1211
+ sqr(num) {
1212
+ return mod(num * num, this.ORDER);
1213
+ }
1214
+ add(lhs, rhs) {
1215
+ return mod(lhs + rhs, this.ORDER);
1216
+ }
1217
+ sub(lhs, rhs) {
1218
+ return mod(lhs - rhs, this.ORDER);
1219
+ }
1220
+ mul(lhs, rhs) {
1221
+ return mod(lhs * rhs, this.ORDER);
1222
+ }
1223
+ pow(num, power) {
1224
+ return FpPow(this, num, power);
1225
+ }
1226
+ div(lhs, rhs) {
1227
+ return mod(lhs * invert(rhs, this.ORDER), this.ORDER);
1228
+ }
1229
+ sqrN(num) {
1230
+ return num * num;
1231
+ }
1232
+ addN(lhs, rhs) {
1233
+ return lhs + rhs;
1234
+ }
1235
+ subN(lhs, rhs) {
1236
+ return lhs - rhs;
1237
+ }
1238
+ mulN(lhs, rhs) {
1239
+ return lhs * rhs;
1240
+ }
1241
+ inv(num) {
1242
+ return invert(num, this.ORDER);
1243
+ }
1244
+ sqrt(num) {
1245
+ if (!this._sqrt) this._sqrt = FpSqrt(this.ORDER);
1246
+ return this._sqrt(this, num);
1247
+ }
1248
+ toBytes(num) {
1249
+ return this.isLE ? numberToBytesLE(num, this.BYTES) : numberToBytesBE(num, this.BYTES);
1250
+ }
1251
+ fromBytes(bytes, skipValidation = false) {
1252
+ abytes$1(bytes);
1253
+ const { _lengths: allowedLengths, BYTES, isLE, ORDER, _mod: modFromBytes } = this;
1254
+ if (allowedLengths) {
1255
+ if (!allowedLengths.includes(bytes.length) || bytes.length > BYTES) throw new Error("Field.fromBytes: expected " + allowedLengths + " bytes, got " + bytes.length);
1256
+ const padded = new Uint8Array(BYTES);
1257
+ padded.set(bytes, isLE ? 0 : padded.length - bytes.length);
1258
+ bytes = padded;
1259
+ }
1260
+ if (bytes.length !== BYTES) throw new Error("Field.fromBytes: expected " + BYTES + " bytes, got " + bytes.length);
1261
+ let scalar = isLE ? bytesToNumberLE(bytes) : bytesToNumberBE(bytes);
1262
+ if (modFromBytes) scalar = mod(scalar, ORDER);
1263
+ if (!skipValidation) {
1264
+ if (!this.isValid(scalar)) throw new Error("invalid field element: outside of range 0..ORDER");
1265
+ }
1266
+ return scalar;
1267
+ }
1268
+ invertBatch(lst) {
1269
+ return FpInvertBatch(this, lst);
1270
+ }
1271
+ cmov(a, b, condition) {
1272
+ return condition ? b : a;
1273
+ }
1274
+ };
1275
+ /**
1276
+ * Creates a finite field. Major performance optimizations:
1277
+ * * 1. Denormalized operations like mulN instead of mul.
1278
+ * * 2. Identical object shape: never add or remove keys.
1279
+ * * 3. `Object.freeze`.
1280
+ * Fragile: always run a benchmark on a change.
1281
+ * Security note: operations don't check 'isValid' for all elements for performance reasons,
1282
+ * it is caller responsibility to check this.
1283
+ * This is low-level code, please make sure you know what you're doing.
1284
+ *
1285
+ * Note about field properties:
1286
+ * * CHARACTERISTIC p = prime number, number of elements in main subgroup.
1287
+ * * ORDER q = similar to cofactor in curves, may be composite `q = p^m`.
1288
+ *
1289
+ * @param ORDER field order, probably prime, or could be composite
1290
+ * @param bitLen how many bits the field consumes
1291
+ * @param isLE (default: false) if encoding / decoding should be in little-endian
1292
+ * @param redef optional faster redefinitions of sqrt and other methods
1293
+ */
1294
+ function Field(ORDER, opts = {}) {
1295
+ return new _Field(ORDER, opts);
1296
+ }
1297
+ /**
1298
+ * Returns total number of bytes consumed by the field element.
1299
+ * For example, 32 bytes for usual 256-bit weierstrass curve.
1300
+ * @param fieldOrder number of field elements, usually CURVE.n
1301
+ * @returns byte length of field
1302
+ */
1303
+ function getFieldBytesLength(fieldOrder) {
1304
+ if (typeof fieldOrder !== "bigint") throw new Error("field order must be bigint");
1305
+ const bitLength = fieldOrder.toString(2).length;
1306
+ return Math.ceil(bitLength / 8);
1307
+ }
1308
+ /**
1309
+ * Returns minimal amount of bytes that can be safely reduced
1310
+ * by field order.
1311
+ * Should be 2^-128 for 128-bit curve such as P256.
1312
+ * @param fieldOrder number of field elements, usually CURVE.n
1313
+ * @returns byte length of target hash
1314
+ */
1315
+ function getMinHashLength(fieldOrder) {
1316
+ const length = getFieldBytesLength(fieldOrder);
1317
+ return length + Math.ceil(length / 2);
1318
+ }
1319
+ /**
1320
+ * "Constant-time" private key generation utility.
1321
+ * Can take (n + n/2) or more bytes of uniform input e.g. from CSPRNG or KDF
1322
+ * and convert them into private scalar, with the modulo bias being negligible.
1323
+ * Needs at least 48 bytes of input for 32-byte private key.
1324
+ * https://research.kudelskisecurity.com/2020/07/28/the-definitive-guide-to-modulo-bias-and-how-to-avoid-it/
1325
+ * FIPS 186-5, A.2 https://csrc.nist.gov/publications/detail/fips/186/5/final
1326
+ * RFC 9380, https://www.rfc-editor.org/rfc/rfc9380#section-5
1327
+ * @param hash hash output from SHA3 or a similar function
1328
+ * @param groupOrder size of subgroup - (e.g. secp256k1.Point.Fn.ORDER)
1329
+ * @param isLE interpret hash bytes as LE num
1330
+ * @returns valid private scalar
1331
+ */
1332
+ function mapHashToField(key, fieldOrder, isLE = false) {
1333
+ abytes$1(key);
1334
+ const len = key.length;
1335
+ const fieldLen = getFieldBytesLength(fieldOrder);
1336
+ const minLen = getMinHashLength(fieldOrder);
1337
+ if (len < 16 || len < minLen || len > 1024) throw new Error("expected " + minLen + "-1024 bytes of input, got " + len);
1338
+ const reduced = mod(isLE ? bytesToNumberLE(key) : bytesToNumberBE(key), fieldOrder - _1n$2) + _1n$2;
1339
+ return isLE ? numberToBytesLE(reduced, fieldLen) : numberToBytesBE(reduced, fieldLen);
1340
+ }
1341
+ //#endregion
1342
+ //#region ../../node_modules/@scure/bip32/node_modules/@noble/curves/abstract/curve.js
1343
+ /**
1344
+ * Methods for elliptic curve multiplication by scalars.
1345
+ * Contains wNAF, pippenger.
1346
+ * @module
1347
+ */
1348
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1349
+ const _0n$1 = /* @__PURE__ */ BigInt(0);
1350
+ const _1n$1 = /* @__PURE__ */ BigInt(1);
1351
+ function negateCt(condition, item) {
1352
+ const neg = item.negate();
1353
+ return condition ? neg : item;
1354
+ }
1355
+ /**
1356
+ * Takes a bunch of Projective Points but executes only one
1357
+ * inversion on all of them. Inversion is very slow operation,
1358
+ * so this improves performance massively.
1359
+ * Optimization: converts a list of projective points to a list of identical points with Z=1.
1360
+ */
1361
+ function normalizeZ(c, points) {
1362
+ const invertedZs = FpInvertBatch(c.Fp, points.map((p) => p.Z));
1363
+ return points.map((p, i) => c.fromAffine(p.toAffine(invertedZs[i])));
1364
+ }
1365
+ function validateW(W, bits) {
1366
+ if (!Number.isSafeInteger(W) || W <= 0 || W > bits) throw new Error("invalid window size, expected [1.." + bits + "], got W=" + W);
1367
+ }
1368
+ function calcWOpts(W, scalarBits) {
1369
+ validateW(W, scalarBits);
1370
+ const windows = Math.ceil(scalarBits / W) + 1;
1371
+ const windowSize = 2 ** (W - 1);
1372
+ const maxNumber = 2 ** W;
1373
+ return {
1374
+ windows,
1375
+ windowSize,
1376
+ mask: bitMask(W),
1377
+ maxNumber,
1378
+ shiftBy: BigInt(W)
1379
+ };
1380
+ }
1381
+ function calcOffsets(n, window, wOpts) {
1382
+ const { windowSize, mask, maxNumber, shiftBy } = wOpts;
1383
+ let wbits = Number(n & mask);
1384
+ let nextN = n >> shiftBy;
1385
+ if (wbits > windowSize) {
1386
+ wbits -= maxNumber;
1387
+ nextN += _1n$1;
1388
+ }
1389
+ const offsetStart = window * windowSize;
1390
+ const offset = offsetStart + Math.abs(wbits) - 1;
1391
+ const isZero = wbits === 0;
1392
+ const isNeg = wbits < 0;
1393
+ const isNegF = window % 2 !== 0;
1394
+ return {
1395
+ nextN,
1396
+ offset,
1397
+ isZero,
1398
+ isNeg,
1399
+ isNegF,
1400
+ offsetF: offsetStart
1401
+ };
1402
+ }
1403
+ const pointPrecomputes = /* @__PURE__ */ new WeakMap();
1404
+ const pointWindowSizes = /* @__PURE__ */ new WeakMap();
1405
+ function getW(P) {
1406
+ return pointWindowSizes.get(P) || 1;
1407
+ }
1408
+ function assert0(n) {
1409
+ if (n !== _0n$1) throw new Error("invalid wNAF");
1410
+ }
1411
+ /**
1412
+ * Elliptic curve multiplication of Point by scalar. Fragile.
1413
+ * Table generation takes **30MB of ram and 10ms on high-end CPU**,
1414
+ * but may take much longer on slow devices. Actual generation will happen on
1415
+ * first call of `multiply()`. By default, `BASE` point is precomputed.
1416
+ *
1417
+ * Scalars should always be less than curve order: this should be checked inside of a curve itself.
1418
+ * Creates precomputation tables for fast multiplication:
1419
+ * - private scalar is split by fixed size windows of W bits
1420
+ * - every window point is collected from window's table & added to accumulator
1421
+ * - since windows are different, same point inside tables won't be accessed more than once per calc
1422
+ * - each multiplication is 'Math.ceil(CURVE_ORDER / 𝑊) + 1' point additions (fixed for any scalar)
1423
+ * - +1 window is neccessary for wNAF
1424
+ * - wNAF reduces table size: 2x less memory + 2x faster generation, but 10% slower multiplication
1425
+ *
1426
+ * @todo Research returning 2d JS array of windows, instead of a single window.
1427
+ * This would allow windows to be in different memory locations
1428
+ */
1429
+ var wNAF = class {
1430
+ BASE;
1431
+ ZERO;
1432
+ Fn;
1433
+ bits;
1434
+ constructor(Point, bits) {
1435
+ this.BASE = Point.BASE;
1436
+ this.ZERO = Point.ZERO;
1437
+ this.Fn = Point.Fn;
1438
+ this.bits = bits;
1439
+ }
1440
+ _unsafeLadder(elm, n, p = this.ZERO) {
1441
+ let d = elm;
1442
+ while (n > _0n$1) {
1443
+ if (n & _1n$1) p = p.add(d);
1444
+ d = d.double();
1445
+ n >>= _1n$1;
1446
+ }
1447
+ return p;
1448
+ }
1449
+ /**
1450
+ * Creates a wNAF precomputation window. Used for caching.
1451
+ * Default window size is set by `utils.precompute()` and is equal to 8.
1452
+ * Number of precomputed points depends on the curve size:
1453
+ * 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
1454
+ * - 𝑊 is the window size
1455
+ * - 𝑛 is the bitlength of the curve order.
1456
+ * For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
1457
+ * @param point Point instance
1458
+ * @param W window size
1459
+ * @returns precomputed point tables flattened to a single array
1460
+ */
1461
+ precomputeWindow(point, W) {
1462
+ const { windows, windowSize } = calcWOpts(W, this.bits);
1463
+ const points = [];
1464
+ let p = point;
1465
+ let base = p;
1466
+ for (let window = 0; window < windows; window++) {
1467
+ base = p;
1468
+ points.push(base);
1469
+ for (let i = 1; i < windowSize; i++) {
1470
+ base = base.add(p);
1471
+ points.push(base);
1472
+ }
1473
+ p = base.double();
1474
+ }
1475
+ return points;
1476
+ }
1477
+ /**
1478
+ * Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
1479
+ * More compact implementation:
1480
+ * https://github.com/paulmillr/noble-secp256k1/blob/47cb1669b6e506ad66b35fe7d76132ae97465da2/index.ts#L502-L541
1481
+ * @returns real and fake (for const-time) points
1482
+ */
1483
+ wNAF(W, precomputes, n) {
1484
+ if (!this.Fn.isValid(n)) throw new Error("invalid scalar");
1485
+ let p = this.ZERO;
1486
+ let f = this.BASE;
1487
+ const wo = calcWOpts(W, this.bits);
1488
+ for (let window = 0; window < wo.windows; window++) {
1489
+ const { nextN, offset, isZero, isNeg, isNegF, offsetF } = calcOffsets(n, window, wo);
1490
+ n = nextN;
1491
+ if (isZero) f = f.add(negateCt(isNegF, precomputes[offsetF]));
1492
+ else p = p.add(negateCt(isNeg, precomputes[offset]));
1493
+ }
1494
+ assert0(n);
1495
+ return {
1496
+ p,
1497
+ f
1498
+ };
1499
+ }
1500
+ /**
1501
+ * Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
1502
+ * @param acc accumulator point to add result of multiplication
1503
+ * @returns point
1504
+ */
1505
+ wNAFUnsafe(W, precomputes, n, acc = this.ZERO) {
1506
+ const wo = calcWOpts(W, this.bits);
1507
+ for (let window = 0; window < wo.windows; window++) {
1508
+ if (n === _0n$1) break;
1509
+ const { nextN, offset, isZero, isNeg } = calcOffsets(n, window, wo);
1510
+ n = nextN;
1511
+ if (isZero) continue;
1512
+ else {
1513
+ const item = precomputes[offset];
1514
+ acc = acc.add(isNeg ? item.negate() : item);
1515
+ }
1516
+ }
1517
+ assert0(n);
1518
+ return acc;
1519
+ }
1520
+ getPrecomputes(W, point, transform) {
1521
+ let comp = pointPrecomputes.get(point);
1522
+ if (!comp) {
1523
+ comp = this.precomputeWindow(point, W);
1524
+ if (W !== 1) {
1525
+ if (typeof transform === "function") comp = transform(comp);
1526
+ pointPrecomputes.set(point, comp);
1527
+ }
1528
+ }
1529
+ return comp;
1530
+ }
1531
+ cached(point, scalar, transform) {
1532
+ const W = getW(point);
1533
+ return this.wNAF(W, this.getPrecomputes(W, point, transform), scalar);
1534
+ }
1535
+ unsafe(point, scalar, transform, prev) {
1536
+ const W = getW(point);
1537
+ if (W === 1) return this._unsafeLadder(point, scalar, prev);
1538
+ return this.wNAFUnsafe(W, this.getPrecomputes(W, point, transform), scalar, prev);
1539
+ }
1540
+ createCache(P, W) {
1541
+ validateW(W, this.bits);
1542
+ pointWindowSizes.set(P, W);
1543
+ pointPrecomputes.delete(P);
1544
+ }
1545
+ hasCache(elm) {
1546
+ return getW(elm) !== 1;
1547
+ }
1548
+ };
1549
+ /**
1550
+ * Endomorphism-specific multiplication for Koblitz curves.
1551
+ * Cost: 128 dbl, 0-256 adds.
1552
+ */
1553
+ function mulEndoUnsafe(Point, point, k1, k2) {
1554
+ let acc = point;
1555
+ let p1 = Point.ZERO;
1556
+ let p2 = Point.ZERO;
1557
+ while (k1 > _0n$1 || k2 > _0n$1) {
1558
+ if (k1 & _1n$1) p1 = p1.add(acc);
1559
+ if (k2 & _1n$1) p2 = p2.add(acc);
1560
+ acc = acc.double();
1561
+ k1 >>= _1n$1;
1562
+ k2 >>= _1n$1;
1563
+ }
1564
+ return {
1565
+ p1,
1566
+ p2
1567
+ };
1568
+ }
1569
+ function createField(order, field, isLE) {
1570
+ if (field) {
1571
+ if (field.ORDER !== order) throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
1572
+ validateField(field);
1573
+ return field;
1574
+ } else return Field(order, { isLE });
1575
+ }
1576
+ /** Validates CURVE opts and creates fields */
1577
+ function createCurveFields(type, CURVE, curveOpts = {}, FpFnLE) {
1578
+ if (FpFnLE === void 0) FpFnLE = type === "edwards";
1579
+ if (!CURVE || typeof CURVE !== "object") throw new Error(`expected valid ${type} CURVE object`);
1580
+ for (const p of [
1581
+ "p",
1582
+ "n",
1583
+ "h"
1584
+ ]) {
1585
+ const val = CURVE[p];
1586
+ if (!(typeof val === "bigint" && val > _0n$1)) throw new Error(`CURVE.${p} must be positive bigint`);
1587
+ }
1588
+ const Fp = createField(CURVE.p, curveOpts.Fp, FpFnLE);
1589
+ const Fn = createField(CURVE.n, curveOpts.Fn, FpFnLE);
1590
+ const params = [
1591
+ "Gx",
1592
+ "Gy",
1593
+ "a",
1594
+ type === "weierstrass" ? "b" : "d"
1595
+ ];
1596
+ for (const p of params) if (!Fp.isValid(CURVE[p])) throw new Error(`CURVE.${p} must be valid field element of CURVE.Fp`);
1597
+ CURVE = Object.freeze(Object.assign({}, CURVE));
1598
+ return {
1599
+ CURVE,
1600
+ Fp,
1601
+ Fn
1602
+ };
1603
+ }
1604
+ function createKeygen(randomSecretKey, getPublicKey) {
1605
+ return function keygen(seed) {
1606
+ const secretKey = randomSecretKey(seed);
1607
+ return {
1608
+ secretKey,
1609
+ publicKey: getPublicKey(secretKey)
1610
+ };
1611
+ };
1612
+ }
1613
+ //#endregion
1614
+ //#region ../../node_modules/@scure/bip32/node_modules/@noble/curves/abstract/hash-to-curve.js
1615
+ const os2ip = bytesToNumberBE;
1616
+ function i2osp(value, length) {
1617
+ asafenumber(value);
1618
+ asafenumber(length);
1619
+ if (value < 0 || value >= 1 << 8 * length) throw new Error("invalid I2OSP input: " + value);
1620
+ const res = Array.from({ length }).fill(0);
1621
+ for (let i = length - 1; i >= 0; i--) {
1622
+ res[i] = value & 255;
1623
+ value >>>= 8;
1624
+ }
1625
+ return new Uint8Array(res);
1626
+ }
1627
+ function strxor(a, b) {
1628
+ const arr = new Uint8Array(a.length);
1629
+ for (let i = 0; i < a.length; i++) arr[i] = a[i] ^ b[i];
1630
+ return arr;
1631
+ }
1632
+ function normDST(DST) {
1633
+ if (!isBytes$1(DST) && typeof DST !== "string") throw new Error("DST must be Uint8Array or ascii string");
1634
+ return typeof DST === "string" ? asciiToBytes(DST) : DST;
1635
+ }
1636
+ /**
1637
+ * Produces a uniformly random byte string using a cryptographic hash function H that outputs b bits.
1638
+ * [RFC 9380 5.3.1](https://www.rfc-editor.org/rfc/rfc9380#section-5.3.1).
1639
+ */
1640
+ function expand_message_xmd(msg, DST, lenInBytes, H) {
1641
+ abytes$1(msg);
1642
+ asafenumber(lenInBytes);
1643
+ DST = normDST(DST);
1644
+ if (DST.length > 255) DST = H(concatBytes(asciiToBytes("H2C-OVERSIZE-DST-"), DST));
1645
+ const { outputLen: b_in_bytes, blockLen: r_in_bytes } = H;
1646
+ const ell = Math.ceil(lenInBytes / b_in_bytes);
1647
+ if (lenInBytes > 65535 || ell > 255) throw new Error("expand_message_xmd: invalid lenInBytes");
1648
+ const DST_prime = concatBytes(DST, i2osp(DST.length, 1));
1649
+ const Z_pad = i2osp(0, r_in_bytes);
1650
+ const l_i_b_str = i2osp(lenInBytes, 2);
1651
+ const b = new Array(ell);
1652
+ const b_0 = H(concatBytes(Z_pad, msg, l_i_b_str, i2osp(0, 1), DST_prime));
1653
+ b[0] = H(concatBytes(b_0, i2osp(1, 1), DST_prime));
1654
+ for (let i = 1; i <= ell; i++) b[i] = H(concatBytes(...[
1655
+ strxor(b_0, b[i - 1]),
1656
+ i2osp(i + 1, 1),
1657
+ DST_prime
1658
+ ]));
1659
+ return concatBytes(...b).slice(0, lenInBytes);
1660
+ }
1661
+ /**
1662
+ * Produces a uniformly random byte string using an extendable-output function (XOF) H.
1663
+ * 1. The collision resistance of H MUST be at least k bits.
1664
+ * 2. H MUST be an XOF that has been proved indifferentiable from
1665
+ * a random oracle under a reasonable cryptographic assumption.
1666
+ * [RFC 9380 5.3.2](https://www.rfc-editor.org/rfc/rfc9380#section-5.3.2).
1667
+ */
1668
+ function expand_message_xof(msg, DST, lenInBytes, k, H) {
1669
+ abytes$1(msg);
1670
+ asafenumber(lenInBytes);
1671
+ DST = normDST(DST);
1672
+ if (DST.length > 255) {
1673
+ const dkLen = Math.ceil(2 * k / 8);
1674
+ DST = H.create({ dkLen }).update(asciiToBytes("H2C-OVERSIZE-DST-")).update(DST).digest();
1675
+ }
1676
+ if (lenInBytes > 65535 || DST.length > 255) throw new Error("expand_message_xof: invalid lenInBytes");
1677
+ return H.create({ dkLen: lenInBytes }).update(msg).update(i2osp(lenInBytes, 2)).update(DST).update(i2osp(DST.length, 1)).digest();
1678
+ }
1679
+ /**
1680
+ * Hashes arbitrary-length byte strings to a list of one or more elements of a finite field F.
1681
+ * [RFC 9380 5.2](https://www.rfc-editor.org/rfc/rfc9380#section-5.2).
1682
+ * @param msg a byte string containing the message to hash
1683
+ * @param count the number of elements of F to output
1684
+ * @param options `{DST: string, p: bigint, m: number, k: number, expand: 'xmd' | 'xof', hash: H}`, see above
1685
+ * @returns [u_0, ..., u_(count - 1)], a list of field elements.
1686
+ */
1687
+ function hash_to_field(msg, count, options) {
1688
+ validateObject(options, {
1689
+ p: "bigint",
1690
+ m: "number",
1691
+ k: "number",
1692
+ hash: "function"
1693
+ });
1694
+ const { p, k, m, hash, expand, DST } = options;
1695
+ asafenumber(hash.outputLen, "valid hash");
1696
+ abytes$1(msg);
1697
+ asafenumber(count);
1698
+ const log2p = p.toString(2).length;
1699
+ const L = Math.ceil((log2p + k) / 8);
1700
+ const len_in_bytes = count * m * L;
1701
+ let prb;
1702
+ if (expand === "xmd") prb = expand_message_xmd(msg, DST, len_in_bytes, hash);
1703
+ else if (expand === "xof") prb = expand_message_xof(msg, DST, len_in_bytes, k, hash);
1704
+ else if (expand === "_internal_pass") prb = msg;
1705
+ else throw new Error("expand must be \"xmd\" or \"xof\"");
1706
+ const u = new Array(count);
1707
+ for (let i = 0; i < count; i++) {
1708
+ const e = new Array(m);
1709
+ for (let j = 0; j < m; j++) {
1710
+ const elm_offset = L * (j + i * m);
1711
+ e[j] = mod(os2ip(prb.subarray(elm_offset, elm_offset + L)), p);
1712
+ }
1713
+ u[i] = e;
1714
+ }
1715
+ return u;
1716
+ }
1717
+ function isogenyMap(field, map) {
1718
+ const coeff = map.map((i) => Array.from(i).reverse());
1719
+ return (x, y) => {
1720
+ const [xn, xd, yn, yd] = coeff.map((val) => val.reduce((acc, i) => field.add(field.mul(acc, x), i)));
1721
+ const [xd_inv, yd_inv] = FpInvertBatch(field, [xd, yd], true);
1722
+ x = field.mul(xn, xd_inv);
1723
+ y = field.mul(y, field.mul(yn, yd_inv));
1724
+ return {
1725
+ x,
1726
+ y
1727
+ };
1728
+ };
1729
+ }
1730
+ const _DST_scalar = asciiToBytes("HashToScalar-");
1731
+ /** Creates hash-to-curve methods from EC Point and mapToCurve function. See {@link H2CHasher}. */
1732
+ function createHasher(Point, mapToCurve, defaults) {
1733
+ if (typeof mapToCurve !== "function") throw new Error("mapToCurve() must be defined");
1734
+ function map(num) {
1735
+ return Point.fromAffine(mapToCurve(num));
1736
+ }
1737
+ function clear(initial) {
1738
+ const P = initial.clearCofactor();
1739
+ if (P.equals(Point.ZERO)) return Point.ZERO;
1740
+ P.assertValidity();
1741
+ return P;
1742
+ }
1743
+ return {
1744
+ defaults: Object.freeze(defaults),
1745
+ Point,
1746
+ hashToCurve(msg, options) {
1747
+ const u = hash_to_field(msg, 2, Object.assign({}, defaults, options));
1748
+ const u0 = map(u[0]);
1749
+ const u1 = map(u[1]);
1750
+ return clear(u0.add(u1));
1751
+ },
1752
+ encodeToCurve(msg, options) {
1753
+ const optsDst = defaults.encodeDST ? { DST: defaults.encodeDST } : {};
1754
+ return clear(map(hash_to_field(msg, 1, Object.assign({}, defaults, optsDst, options))[0]));
1755
+ },
1756
+ mapToCurve(scalars) {
1757
+ if (defaults.m === 1) {
1758
+ if (typeof scalars !== "bigint") throw new Error("expected bigint (m=1)");
1759
+ return clear(map([scalars]));
1760
+ }
1761
+ if (!Array.isArray(scalars)) throw new Error("expected array of bigints");
1762
+ for (const i of scalars) if (typeof i !== "bigint") throw new Error("expected array of bigints");
1763
+ return clear(map(scalars));
1764
+ },
1765
+ hashToScalar(msg, options) {
1766
+ const N = Point.Fn.ORDER;
1767
+ return hash_to_field(msg, 1, Object.assign({}, defaults, {
1768
+ p: N,
1769
+ m: 1,
1770
+ DST: _DST_scalar
1771
+ }, options))[0][0];
1772
+ }
1773
+ };
1774
+ }
1775
+ //#endregion
1776
+ //#region ../../node_modules/@scure/bip32/node_modules/@noble/hashes/hmac.js
1777
+ /**
1778
+ * HMAC: RFC2104 message authentication code.
1779
+ * @module
1780
+ */
1781
+ /** Internal class for HMAC. */
1782
+ var _HMAC = class {
1783
+ oHash;
1784
+ iHash;
1785
+ blockLen;
1786
+ outputLen;
1787
+ finished = false;
1788
+ destroyed = false;
1789
+ constructor(hash, key) {
1790
+ ahash(hash);
1791
+ abytes$1(key, void 0, "key");
1792
+ this.iHash = hash.create();
1793
+ if (typeof this.iHash.update !== "function") throw new Error("Expected instance of class which extends utils.Hash");
1794
+ this.blockLen = this.iHash.blockLen;
1795
+ this.outputLen = this.iHash.outputLen;
1796
+ const blockLen = this.blockLen;
1797
+ const pad = new Uint8Array(blockLen);
1798
+ pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
1799
+ for (let i = 0; i < pad.length; i++) pad[i] ^= 54;
1800
+ this.iHash.update(pad);
1801
+ this.oHash = hash.create();
1802
+ for (let i = 0; i < pad.length; i++) pad[i] ^= 106;
1803
+ this.oHash.update(pad);
1804
+ clean(pad);
1805
+ }
1806
+ update(buf) {
1807
+ aexists(this);
1808
+ this.iHash.update(buf);
1809
+ return this;
1810
+ }
1811
+ digestInto(out) {
1812
+ aexists(this);
1813
+ abytes$1(out, this.outputLen, "output");
1814
+ this.finished = true;
1815
+ this.iHash.digestInto(out);
1816
+ this.oHash.update(out);
1817
+ this.oHash.digestInto(out);
1818
+ this.destroy();
1819
+ }
1820
+ digest() {
1821
+ const out = new Uint8Array(this.oHash.outputLen);
1822
+ this.digestInto(out);
1823
+ return out;
1824
+ }
1825
+ _cloneInto(to) {
1826
+ to ||= Object.create(Object.getPrototypeOf(this), {});
1827
+ const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
1828
+ to = to;
1829
+ to.finished = finished;
1830
+ to.destroyed = destroyed;
1831
+ to.blockLen = blockLen;
1832
+ to.outputLen = outputLen;
1833
+ to.oHash = oHash._cloneInto(to.oHash);
1834
+ to.iHash = iHash._cloneInto(to.iHash);
1835
+ return to;
1836
+ }
1837
+ clone() {
1838
+ return this._cloneInto();
1839
+ }
1840
+ destroy() {
1841
+ this.destroyed = true;
1842
+ this.oHash.destroy();
1843
+ this.iHash.destroy();
1844
+ }
1845
+ };
1846
+ /**
1847
+ * HMAC: RFC2104 message authentication code.
1848
+ * @param hash - function that would be used e.g. sha256
1849
+ * @param key - message key
1850
+ * @param message - message data
1851
+ * @example
1852
+ * import { hmac } from '@noble/hashes/hmac';
1853
+ * import { sha256 } from '@noble/hashes/sha2';
1854
+ * const mac1 = hmac(sha256, 'key', 'message');
1855
+ */
1856
+ const hmac = (hash, key, message) => new _HMAC(hash, key).update(message).digest();
1857
+ hmac.create = (hash, key) => new _HMAC(hash, key);
1858
+ //#endregion
1859
+ //#region ../../node_modules/@scure/bip32/node_modules/@noble/curves/abstract/weierstrass.js
1860
+ /**
1861
+ * Short Weierstrass curve methods. The formula is: y² = x³ + ax + b.
1862
+ *
1863
+ * ### Design rationale for types
1864
+ *
1865
+ * * Interaction between classes from different curves should fail:
1866
+ * `k256.Point.BASE.add(p256.Point.BASE)`
1867
+ * * For this purpose we want to use `instanceof` operator, which is fast and works during runtime
1868
+ * * Different calls of `curve()` would return different classes -
1869
+ * `curve(params) !== curve(params)`: if somebody decided to monkey-patch their curve,
1870
+ * it won't affect others
1871
+ *
1872
+ * TypeScript can't infer types for classes created inside a function. Classes is one instance
1873
+ * of nominative types in TypeScript and interfaces only check for shape, so it's hard to create
1874
+ * unique type for every function call.
1875
+ *
1876
+ * We can use generic types via some param, like curve opts, but that would:
1877
+ * 1. Enable interaction between `curve(params)` and `curve(params)` (curves of same params)
1878
+ * which is hard to debug.
1879
+ * 2. Params can be generic and we can't enforce them to be constant value:
1880
+ * if somebody creates curve from non-constant params,
1881
+ * it would be allowed to interact with other curves with non-constant params
1882
+ *
1883
+ * @todo https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html#unique-symbol
1884
+ * @module
1885
+ */
1886
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1887
+ const divNearest = (num, den) => (num + (num >= 0 ? den : -den) / _2n$1) / den;
1888
+ /**
1889
+ * Splits scalar for GLV endomorphism.
1890
+ */
1891
+ function _splitEndoScalar(k, basis, n) {
1892
+ const [[a1, b1], [a2, b2]] = basis;
1893
+ const c1 = divNearest(b2 * k, n);
1894
+ const c2 = divNearest(-b1 * k, n);
1895
+ let k1 = k - c1 * a1 - c2 * a2;
1896
+ let k2 = -c1 * b1 - c2 * b2;
1897
+ const k1neg = k1 < _0n;
1898
+ const k2neg = k2 < _0n;
1899
+ if (k1neg) k1 = -k1;
1900
+ if (k2neg) k2 = -k2;
1901
+ const MAX_NUM = bitMask(Math.ceil(bitLen(n) / 2)) + _1n;
1902
+ if (k1 < _0n || k1 >= MAX_NUM || k2 < _0n || k2 >= MAX_NUM) throw new Error("splitScalar (endomorphism): failed, k=" + k);
1903
+ return {
1904
+ k1neg,
1905
+ k1,
1906
+ k2neg,
1907
+ k2
1908
+ };
1909
+ }
1910
+ function validateSigFormat(format) {
1911
+ if (![
1912
+ "compact",
1913
+ "recovered",
1914
+ "der"
1915
+ ].includes(format)) throw new Error("Signature format must be \"compact\", \"recovered\", or \"der\"");
1916
+ return format;
1917
+ }
1918
+ function validateSigOpts(opts, def) {
1919
+ const optsn = {};
1920
+ for (let optName of Object.keys(def)) optsn[optName] = opts[optName] === void 0 ? def[optName] : opts[optName];
1921
+ abool(optsn.lowS, "lowS");
1922
+ abool(optsn.prehash, "prehash");
1923
+ if (optsn.format !== void 0) validateSigFormat(optsn.format);
1924
+ return optsn;
1925
+ }
1926
+ var DERErr = class extends Error {
1927
+ constructor(m = "") {
1928
+ super(m);
1929
+ }
1930
+ };
1931
+ /**
1932
+ * ASN.1 DER encoding utilities. ASN is very complex & fragile. Format:
1933
+ *
1934
+ * [0x30 (SEQUENCE), bytelength, 0x02 (INTEGER), intLength, R, 0x02 (INTEGER), intLength, S]
1935
+ *
1936
+ * Docs: https://letsencrypt.org/docs/a-warm-welcome-to-asn1-and-der/, https://luca.ntop.org/Teaching/Appunti/asn1.html
1937
+ */
1938
+ const DER = {
1939
+ Err: DERErr,
1940
+ _tlv: {
1941
+ encode: (tag, data) => {
1942
+ const { Err: E } = DER;
1943
+ if (tag < 0 || tag > 256) throw new E("tlv.encode: wrong tag");
1944
+ if (data.length & 1) throw new E("tlv.encode: unpadded data");
1945
+ const dataLen = data.length / 2;
1946
+ const len = numberToHexUnpadded(dataLen);
1947
+ if (len.length / 2 & 128) throw new E("tlv.encode: long form length too big");
1948
+ const lenLen = dataLen > 127 ? numberToHexUnpadded(len.length / 2 | 128) : "";
1949
+ return numberToHexUnpadded(tag) + lenLen + len + data;
1950
+ },
1951
+ decode(tag, data) {
1952
+ const { Err: E } = DER;
1953
+ let pos = 0;
1954
+ if (tag < 0 || tag > 256) throw new E("tlv.encode: wrong tag");
1955
+ if (data.length < 2 || data[pos++] !== tag) throw new E("tlv.decode: wrong tlv");
1956
+ const first = data[pos++];
1957
+ const isLong = !!(first & 128);
1958
+ let length = 0;
1959
+ if (!isLong) length = first;
1960
+ else {
1961
+ const lenLen = first & 127;
1962
+ if (!lenLen) throw new E("tlv.decode(long): indefinite length not supported");
1963
+ if (lenLen > 4) throw new E("tlv.decode(long): byte length is too big");
1964
+ const lengthBytes = data.subarray(pos, pos + lenLen);
1965
+ if (lengthBytes.length !== lenLen) throw new E("tlv.decode: length bytes not complete");
1966
+ if (lengthBytes[0] === 0) throw new E("tlv.decode(long): zero leftmost byte");
1967
+ for (const b of lengthBytes) length = length << 8 | b;
1968
+ pos += lenLen;
1969
+ if (length < 128) throw new E("tlv.decode(long): not minimal encoding");
1970
+ }
1971
+ const v = data.subarray(pos, pos + length);
1972
+ if (v.length !== length) throw new E("tlv.decode: wrong value length");
1973
+ return {
1974
+ v,
1975
+ l: data.subarray(pos + length)
1976
+ };
1977
+ }
1978
+ },
1979
+ _int: {
1980
+ encode(num) {
1981
+ const { Err: E } = DER;
1982
+ if (num < _0n) throw new E("integer: negative integers are not allowed");
1983
+ let hex = numberToHexUnpadded(num);
1984
+ if (Number.parseInt(hex[0], 16) & 8) hex = "00" + hex;
1985
+ if (hex.length & 1) throw new E("unexpected DER parsing assertion: unpadded hex");
1986
+ return hex;
1987
+ },
1988
+ decode(data) {
1989
+ const { Err: E } = DER;
1990
+ if (data[0] & 128) throw new E("invalid signature integer: negative");
1991
+ if (data[0] === 0 && !(data[1] & 128)) throw new E("invalid signature integer: unnecessary leading zero");
1992
+ return bytesToNumberBE(data);
1993
+ }
1994
+ },
1995
+ toSig(bytes) {
1996
+ const { Err: E, _int: int, _tlv: tlv } = DER;
1997
+ const data = abytes$1(bytes, void 0, "signature");
1998
+ const { v: seqBytes, l: seqLeftBytes } = tlv.decode(48, data);
1999
+ if (seqLeftBytes.length) throw new E("invalid signature: left bytes after parsing");
2000
+ const { v: rBytes, l: rLeftBytes } = tlv.decode(2, seqBytes);
2001
+ const { v: sBytes, l: sLeftBytes } = tlv.decode(2, rLeftBytes);
2002
+ if (sLeftBytes.length) throw new E("invalid signature: left bytes after parsing");
2003
+ return {
2004
+ r: int.decode(rBytes),
2005
+ s: int.decode(sBytes)
2006
+ };
2007
+ },
2008
+ hexFromSig(sig) {
2009
+ const { _tlv: tlv, _int: int } = DER;
2010
+ const seq = tlv.encode(2, int.encode(sig.r)) + tlv.encode(2, int.encode(sig.s));
2011
+ return tlv.encode(48, seq);
2012
+ }
2013
+ };
2014
+ const _0n = BigInt(0), _1n = BigInt(1), _2n$1 = BigInt(2), _3n = BigInt(3), _4n = BigInt(4);
2015
+ /**
2016
+ * Creates weierstrass Point constructor, based on specified curve options.
2017
+ *
2018
+ * See {@link WeierstrassOpts}.
2019
+ *
2020
+ * @example
2021
+ ```js
2022
+ const opts = {
2023
+ p: 0xfffffffffffffffffffffffffffffffeffffac73n,
2024
+ n: 0x100000000000000000001b8fa16dfab9aca16b6b3n,
2025
+ h: 1n,
2026
+ a: 0n,
2027
+ b: 7n,
2028
+ Gx: 0x3b4c382ce37aa192a4019e763036f4f5dd4d7ebbn,
2029
+ Gy: 0x938cf935318fdced6bc28286531733c3f03c4feen,
2030
+ };
2031
+ const secp160k1_Point = weierstrass(opts);
2032
+ ```
2033
+ */
2034
+ function weierstrass(params, extraOpts = {}) {
2035
+ const validated = createCurveFields("weierstrass", params, extraOpts);
2036
+ const { Fp, Fn } = validated;
2037
+ let CURVE = validated.CURVE;
2038
+ const { h: cofactor, n: CURVE_ORDER } = CURVE;
2039
+ validateObject(extraOpts, {}, {
2040
+ allowInfinityPoint: "boolean",
2041
+ clearCofactor: "function",
2042
+ isTorsionFree: "function",
2043
+ fromBytes: "function",
2044
+ toBytes: "function",
2045
+ endo: "object"
2046
+ });
2047
+ const { endo } = extraOpts;
2048
+ if (endo) {
2049
+ if (!Fp.is0(CURVE.a) || typeof endo.beta !== "bigint" || !Array.isArray(endo.basises)) throw new Error("invalid endo: expected \"beta\": bigint and \"basises\": array");
2050
+ }
2051
+ const lengths = getWLengths(Fp, Fn);
2052
+ function assertCompressionIsSupported() {
2053
+ if (!Fp.isOdd) throw new Error("compression is not supported: Field does not have .isOdd()");
2054
+ }
2055
+ function pointToBytes(_c, point, isCompressed) {
2056
+ const { x, y } = point.toAffine();
2057
+ const bx = Fp.toBytes(x);
2058
+ abool(isCompressed, "isCompressed");
2059
+ if (isCompressed) {
2060
+ assertCompressionIsSupported();
2061
+ return concatBytes(pprefix(!Fp.isOdd(y)), bx);
2062
+ } else return concatBytes(Uint8Array.of(4), bx, Fp.toBytes(y));
2063
+ }
2064
+ function pointFromBytes(bytes) {
2065
+ abytes$1(bytes, void 0, "Point");
2066
+ const { publicKey: comp, publicKeyUncompressed: uncomp } = lengths;
2067
+ const length = bytes.length;
2068
+ const head = bytes[0];
2069
+ const tail = bytes.subarray(1);
2070
+ if (length === comp && (head === 2 || head === 3)) {
2071
+ const x = Fp.fromBytes(tail);
2072
+ if (!Fp.isValid(x)) throw new Error("bad point: is not on curve, wrong x");
2073
+ const y2 = weierstrassEquation(x);
2074
+ let y;
2075
+ try {
2076
+ y = Fp.sqrt(y2);
2077
+ } catch (sqrtError) {
2078
+ const err = sqrtError instanceof Error ? ": " + sqrtError.message : "";
2079
+ throw new Error("bad point: is not on curve, sqrt error" + err);
2080
+ }
2081
+ assertCompressionIsSupported();
2082
+ const evenY = Fp.isOdd(y);
2083
+ if ((head & 1) === 1 !== evenY) y = Fp.neg(y);
2084
+ return {
2085
+ x,
2086
+ y
2087
+ };
2088
+ } else if (length === uncomp && head === 4) {
2089
+ const L = Fp.BYTES;
2090
+ const x = Fp.fromBytes(tail.subarray(0, L));
2091
+ const y = Fp.fromBytes(tail.subarray(L, L * 2));
2092
+ if (!isValidXY(x, y)) throw new Error("bad point: is not on curve");
2093
+ return {
2094
+ x,
2095
+ y
2096
+ };
2097
+ } else throw new Error(`bad point: got length ${length}, expected compressed=${comp} or uncompressed=${uncomp}`);
2098
+ }
2099
+ const encodePoint = extraOpts.toBytes || pointToBytes;
2100
+ const decodePoint = extraOpts.fromBytes || pointFromBytes;
2101
+ function weierstrassEquation(x) {
2102
+ const x2 = Fp.sqr(x);
2103
+ const x3 = Fp.mul(x2, x);
2104
+ return Fp.add(Fp.add(x3, Fp.mul(x, CURVE.a)), CURVE.b);
2105
+ }
2106
+ /** Checks whether equation holds for given x, y: y² == x³ + ax + b */
2107
+ function isValidXY(x, y) {
2108
+ const left = Fp.sqr(y);
2109
+ const right = weierstrassEquation(x);
2110
+ return Fp.eql(left, right);
2111
+ }
2112
+ if (!isValidXY(CURVE.Gx, CURVE.Gy)) throw new Error("bad curve params: generator point");
2113
+ const _4a3 = Fp.mul(Fp.pow(CURVE.a, _3n), _4n);
2114
+ const _27b2 = Fp.mul(Fp.sqr(CURVE.b), BigInt(27));
2115
+ if (Fp.is0(Fp.add(_4a3, _27b2))) throw new Error("bad curve params: a or b");
2116
+ /** Asserts coordinate is valid: 0 <= n < Fp.ORDER. */
2117
+ function acoord(title, n, banZero = false) {
2118
+ if (!Fp.isValid(n) || banZero && Fp.is0(n)) throw new Error(`bad point coordinate ${title}`);
2119
+ return n;
2120
+ }
2121
+ function aprjpoint(other) {
2122
+ if (!(other instanceof Point)) throw new Error("Weierstrass Point expected");
2123
+ }
2124
+ function splitEndoScalarN(k) {
2125
+ if (!endo || !endo.basises) throw new Error("no endo");
2126
+ return _splitEndoScalar(k, endo.basises, Fn.ORDER);
2127
+ }
2128
+ const toAffineMemo = memoized((p, iz) => {
2129
+ const { X, Y, Z } = p;
2130
+ if (Fp.eql(Z, Fp.ONE)) return {
2131
+ x: X,
2132
+ y: Y
2133
+ };
2134
+ const is0 = p.is0();
2135
+ if (iz == null) iz = is0 ? Fp.ONE : Fp.inv(Z);
2136
+ const x = Fp.mul(X, iz);
2137
+ const y = Fp.mul(Y, iz);
2138
+ const zz = Fp.mul(Z, iz);
2139
+ if (is0) return {
2140
+ x: Fp.ZERO,
2141
+ y: Fp.ZERO
2142
+ };
2143
+ if (!Fp.eql(zz, Fp.ONE)) throw new Error("invZ was invalid");
2144
+ return {
2145
+ x,
2146
+ y
2147
+ };
2148
+ });
2149
+ const assertValidMemo = memoized((p) => {
2150
+ if (p.is0()) {
2151
+ if (extraOpts.allowInfinityPoint && !Fp.is0(p.Y)) return;
2152
+ throw new Error("bad point: ZERO");
2153
+ }
2154
+ const { x, y } = p.toAffine();
2155
+ if (!Fp.isValid(x) || !Fp.isValid(y)) throw new Error("bad point: x or y not field elements");
2156
+ if (!isValidXY(x, y)) throw new Error("bad point: equation left != right");
2157
+ if (!p.isTorsionFree()) throw new Error("bad point: not in prime-order subgroup");
2158
+ return true;
2159
+ });
2160
+ function finishEndo(endoBeta, k1p, k2p, k1neg, k2neg) {
2161
+ k2p = new Point(Fp.mul(k2p.X, endoBeta), k2p.Y, k2p.Z);
2162
+ k1p = negateCt(k1neg, k1p);
2163
+ k2p = negateCt(k2neg, k2p);
2164
+ return k1p.add(k2p);
2165
+ }
2166
+ /**
2167
+ * Projective Point works in 3d / projective (homogeneous) coordinates:(X, Y, Z) ∋ (x=X/Z, y=Y/Z).
2168
+ * Default Point works in 2d / affine coordinates: (x, y).
2169
+ * We're doing calculations in projective, because its operations don't require costly inversion.
2170
+ */
2171
+ class Point {
2172
+ static BASE = new Point(CURVE.Gx, CURVE.Gy, Fp.ONE);
2173
+ static ZERO = new Point(Fp.ZERO, Fp.ONE, Fp.ZERO);
2174
+ static Fp = Fp;
2175
+ static Fn = Fn;
2176
+ X;
2177
+ Y;
2178
+ Z;
2179
+ /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
2180
+ constructor(X, Y, Z) {
2181
+ this.X = acoord("x", X);
2182
+ this.Y = acoord("y", Y, true);
2183
+ this.Z = acoord("z", Z);
2184
+ Object.freeze(this);
2185
+ }
2186
+ static CURVE() {
2187
+ return CURVE;
2188
+ }
2189
+ /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
2190
+ static fromAffine(p) {
2191
+ const { x, y } = p || {};
2192
+ if (!p || !Fp.isValid(x) || !Fp.isValid(y)) throw new Error("invalid affine point");
2193
+ if (p instanceof Point) throw new Error("projective point not allowed");
2194
+ if (Fp.is0(x) && Fp.is0(y)) return Point.ZERO;
2195
+ return new Point(x, y, Fp.ONE);
2196
+ }
2197
+ static fromBytes(bytes) {
2198
+ const P = Point.fromAffine(decodePoint(abytes$1(bytes, void 0, "point")));
2199
+ P.assertValidity();
2200
+ return P;
2201
+ }
2202
+ static fromHex(hex) {
2203
+ return Point.fromBytes(hexToBytes(hex));
2204
+ }
2205
+ get x() {
2206
+ return this.toAffine().x;
2207
+ }
2208
+ get y() {
2209
+ return this.toAffine().y;
2210
+ }
2211
+ /**
2212
+ *
2213
+ * @param windowSize
2214
+ * @param isLazy true will defer table computation until the first multiplication
2215
+ * @returns
2216
+ */
2217
+ precompute(windowSize = 8, isLazy = true) {
2218
+ wnaf.createCache(this, windowSize);
2219
+ if (!isLazy) this.multiply(_3n);
2220
+ return this;
2221
+ }
2222
+ /** A point on curve is valid if it conforms to equation. */
2223
+ assertValidity() {
2224
+ assertValidMemo(this);
2225
+ }
2226
+ hasEvenY() {
2227
+ const { y } = this.toAffine();
2228
+ if (!Fp.isOdd) throw new Error("Field doesn't support isOdd");
2229
+ return !Fp.isOdd(y);
2230
+ }
2231
+ /** Compare one point to another. */
2232
+ equals(other) {
2233
+ aprjpoint(other);
2234
+ const { X: X1, Y: Y1, Z: Z1 } = this;
2235
+ const { X: X2, Y: Y2, Z: Z2 } = other;
2236
+ const U1 = Fp.eql(Fp.mul(X1, Z2), Fp.mul(X2, Z1));
2237
+ const U2 = Fp.eql(Fp.mul(Y1, Z2), Fp.mul(Y2, Z1));
2238
+ return U1 && U2;
2239
+ }
2240
+ /** Flips point to one corresponding to (x, -y) in Affine coordinates. */
2241
+ negate() {
2242
+ return new Point(this.X, Fp.neg(this.Y), this.Z);
2243
+ }
2244
+ double() {
2245
+ const { a, b } = CURVE;
2246
+ const b3 = Fp.mul(b, _3n);
2247
+ const { X: X1, Y: Y1, Z: Z1 } = this;
2248
+ let X3 = Fp.ZERO, Y3 = Fp.ZERO, Z3 = Fp.ZERO;
2249
+ let t0 = Fp.mul(X1, X1);
2250
+ let t1 = Fp.mul(Y1, Y1);
2251
+ let t2 = Fp.mul(Z1, Z1);
2252
+ let t3 = Fp.mul(X1, Y1);
2253
+ t3 = Fp.add(t3, t3);
2254
+ Z3 = Fp.mul(X1, Z1);
2255
+ Z3 = Fp.add(Z3, Z3);
2256
+ X3 = Fp.mul(a, Z3);
2257
+ Y3 = Fp.mul(b3, t2);
2258
+ Y3 = Fp.add(X3, Y3);
2259
+ X3 = Fp.sub(t1, Y3);
2260
+ Y3 = Fp.add(t1, Y3);
2261
+ Y3 = Fp.mul(X3, Y3);
2262
+ X3 = Fp.mul(t3, X3);
2263
+ Z3 = Fp.mul(b3, Z3);
2264
+ t2 = Fp.mul(a, t2);
2265
+ t3 = Fp.sub(t0, t2);
2266
+ t3 = Fp.mul(a, t3);
2267
+ t3 = Fp.add(t3, Z3);
2268
+ Z3 = Fp.add(t0, t0);
2269
+ t0 = Fp.add(Z3, t0);
2270
+ t0 = Fp.add(t0, t2);
2271
+ t0 = Fp.mul(t0, t3);
2272
+ Y3 = Fp.add(Y3, t0);
2273
+ t2 = Fp.mul(Y1, Z1);
2274
+ t2 = Fp.add(t2, t2);
2275
+ t0 = Fp.mul(t2, t3);
2276
+ X3 = Fp.sub(X3, t0);
2277
+ Z3 = Fp.mul(t2, t1);
2278
+ Z3 = Fp.add(Z3, Z3);
2279
+ Z3 = Fp.add(Z3, Z3);
2280
+ return new Point(X3, Y3, Z3);
2281
+ }
2282
+ add(other) {
2283
+ aprjpoint(other);
2284
+ const { X: X1, Y: Y1, Z: Z1 } = this;
2285
+ const { X: X2, Y: Y2, Z: Z2 } = other;
2286
+ let X3 = Fp.ZERO, Y3 = Fp.ZERO, Z3 = Fp.ZERO;
2287
+ const a = CURVE.a;
2288
+ const b3 = Fp.mul(CURVE.b, _3n);
2289
+ let t0 = Fp.mul(X1, X2);
2290
+ let t1 = Fp.mul(Y1, Y2);
2291
+ let t2 = Fp.mul(Z1, Z2);
2292
+ let t3 = Fp.add(X1, Y1);
2293
+ let t4 = Fp.add(X2, Y2);
2294
+ t3 = Fp.mul(t3, t4);
2295
+ t4 = Fp.add(t0, t1);
2296
+ t3 = Fp.sub(t3, t4);
2297
+ t4 = Fp.add(X1, Z1);
2298
+ let t5 = Fp.add(X2, Z2);
2299
+ t4 = Fp.mul(t4, t5);
2300
+ t5 = Fp.add(t0, t2);
2301
+ t4 = Fp.sub(t4, t5);
2302
+ t5 = Fp.add(Y1, Z1);
2303
+ X3 = Fp.add(Y2, Z2);
2304
+ t5 = Fp.mul(t5, X3);
2305
+ X3 = Fp.add(t1, t2);
2306
+ t5 = Fp.sub(t5, X3);
2307
+ Z3 = Fp.mul(a, t4);
2308
+ X3 = Fp.mul(b3, t2);
2309
+ Z3 = Fp.add(X3, Z3);
2310
+ X3 = Fp.sub(t1, Z3);
2311
+ Z3 = Fp.add(t1, Z3);
2312
+ Y3 = Fp.mul(X3, Z3);
2313
+ t1 = Fp.add(t0, t0);
2314
+ t1 = Fp.add(t1, t0);
2315
+ t2 = Fp.mul(a, t2);
2316
+ t4 = Fp.mul(b3, t4);
2317
+ t1 = Fp.add(t1, t2);
2318
+ t2 = Fp.sub(t0, t2);
2319
+ t2 = Fp.mul(a, t2);
2320
+ t4 = Fp.add(t4, t2);
2321
+ t0 = Fp.mul(t1, t4);
2322
+ Y3 = Fp.add(Y3, t0);
2323
+ t0 = Fp.mul(t5, t4);
2324
+ X3 = Fp.mul(t3, X3);
2325
+ X3 = Fp.sub(X3, t0);
2326
+ t0 = Fp.mul(t3, t1);
2327
+ Z3 = Fp.mul(t5, Z3);
2328
+ Z3 = Fp.add(Z3, t0);
2329
+ return new Point(X3, Y3, Z3);
2330
+ }
2331
+ subtract(other) {
2332
+ return this.add(other.negate());
2333
+ }
2334
+ is0() {
2335
+ return this.equals(Point.ZERO);
2336
+ }
2337
+ /**
2338
+ * Constant time multiplication.
2339
+ * Uses wNAF method. Windowed method may be 10% faster,
2340
+ * but takes 2x longer to generate and consumes 2x memory.
2341
+ * Uses precomputes when available.
2342
+ * Uses endomorphism for Koblitz curves.
2343
+ * @param scalar by which the point would be multiplied
2344
+ * @returns New point
2345
+ */
2346
+ multiply(scalar) {
2347
+ const { endo } = extraOpts;
2348
+ if (!Fn.isValidNot0(scalar)) throw new Error("invalid scalar: out of range");
2349
+ let point, fake;
2350
+ const mul = (n) => wnaf.cached(this, n, (p) => normalizeZ(Point, p));
2351
+ /** See docs for {@link EndomorphismOpts} */
2352
+ if (endo) {
2353
+ const { k1neg, k1, k2neg, k2 } = splitEndoScalarN(scalar);
2354
+ const { p: k1p, f: k1f } = mul(k1);
2355
+ const { p: k2p, f: k2f } = mul(k2);
2356
+ fake = k1f.add(k2f);
2357
+ point = finishEndo(endo.beta, k1p, k2p, k1neg, k2neg);
2358
+ } else {
2359
+ const { p, f } = mul(scalar);
2360
+ point = p;
2361
+ fake = f;
2362
+ }
2363
+ return normalizeZ(Point, [point, fake])[0];
2364
+ }
2365
+ /**
2366
+ * Non-constant-time multiplication. Uses double-and-add algorithm.
2367
+ * It's faster, but should only be used when you don't care about
2368
+ * an exposed secret key e.g. sig verification, which works over *public* keys.
2369
+ */
2370
+ multiplyUnsafe(sc) {
2371
+ const { endo } = extraOpts;
2372
+ const p = this;
2373
+ if (!Fn.isValid(sc)) throw new Error("invalid scalar: out of range");
2374
+ if (sc === _0n || p.is0()) return Point.ZERO;
2375
+ if (sc === _1n) return p;
2376
+ if (wnaf.hasCache(this)) return this.multiply(sc);
2377
+ if (endo) {
2378
+ const { k1neg, k1, k2neg, k2 } = splitEndoScalarN(sc);
2379
+ const { p1, p2 } = mulEndoUnsafe(Point, p, k1, k2);
2380
+ return finishEndo(endo.beta, p1, p2, k1neg, k2neg);
2381
+ } else return wnaf.unsafe(p, sc);
2382
+ }
2383
+ /**
2384
+ * Converts Projective point to affine (x, y) coordinates.
2385
+ * @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
2386
+ */
2387
+ toAffine(invertedZ) {
2388
+ return toAffineMemo(this, invertedZ);
2389
+ }
2390
+ /**
2391
+ * Checks whether Point is free of torsion elements (is in prime subgroup).
2392
+ * Always torsion-free for cofactor=1 curves.
2393
+ */
2394
+ isTorsionFree() {
2395
+ const { isTorsionFree } = extraOpts;
2396
+ if (cofactor === _1n) return true;
2397
+ if (isTorsionFree) return isTorsionFree(Point, this);
2398
+ return wnaf.unsafe(this, CURVE_ORDER).is0();
2399
+ }
2400
+ clearCofactor() {
2401
+ const { clearCofactor } = extraOpts;
2402
+ if (cofactor === _1n) return this;
2403
+ if (clearCofactor) return clearCofactor(Point, this);
2404
+ return this.multiplyUnsafe(cofactor);
2405
+ }
2406
+ isSmallOrder() {
2407
+ return this.multiplyUnsafe(cofactor).is0();
2408
+ }
2409
+ toBytes(isCompressed = true) {
2410
+ abool(isCompressed, "isCompressed");
2411
+ this.assertValidity();
2412
+ return encodePoint(Point, this, isCompressed);
2413
+ }
2414
+ toHex(isCompressed = true) {
2415
+ return bytesToHex(this.toBytes(isCompressed));
2416
+ }
2417
+ toString() {
2418
+ return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
2419
+ }
2420
+ }
2421
+ const bits = Fn.BITS;
2422
+ const wnaf = new wNAF(Point, extraOpts.endo ? Math.ceil(bits / 2) : bits);
2423
+ Point.BASE.precompute(8);
2424
+ return Point;
2425
+ }
2426
+ function pprefix(hasEvenY) {
2427
+ return Uint8Array.of(hasEvenY ? 2 : 3);
2428
+ }
2429
+ /**
2430
+ * Implementation of the Shallue and van de Woestijne method for any weierstrass curve.
2431
+ * TODO: check if there is a way to merge this with uvRatio in Edwards; move to modular.
2432
+ * b = True and y = sqrt(u / v) if (u / v) is square in F, and
2433
+ * b = False and y = sqrt(Z * (u / v)) otherwise.
2434
+ * @param Fp
2435
+ * @param Z
2436
+ * @returns
2437
+ */
2438
+ function SWUFpSqrtRatio(Fp, Z) {
2439
+ const q = Fp.ORDER;
2440
+ let l = _0n;
2441
+ for (let o = q - _1n; o % _2n$1 === _0n; o /= _2n$1) l += _1n;
2442
+ const c1 = l;
2443
+ const _2n_pow_c1_1 = _2n$1 << c1 - _1n - _1n;
2444
+ const _2n_pow_c1 = _2n_pow_c1_1 * _2n$1;
2445
+ const c2 = (q - _1n) / _2n_pow_c1;
2446
+ const c3 = (c2 - _1n) / _2n$1;
2447
+ const c4 = _2n_pow_c1 - _1n;
2448
+ const c5 = _2n_pow_c1_1;
2449
+ const c6 = Fp.pow(Z, c2);
2450
+ const c7 = Fp.pow(Z, (c2 + _1n) / _2n$1);
2451
+ let sqrtRatio = (u, v) => {
2452
+ let tv1 = c6;
2453
+ let tv2 = Fp.pow(v, c4);
2454
+ let tv3 = Fp.sqr(tv2);
2455
+ tv3 = Fp.mul(tv3, v);
2456
+ let tv5 = Fp.mul(u, tv3);
2457
+ tv5 = Fp.pow(tv5, c3);
2458
+ tv5 = Fp.mul(tv5, tv2);
2459
+ tv2 = Fp.mul(tv5, v);
2460
+ tv3 = Fp.mul(tv5, u);
2461
+ let tv4 = Fp.mul(tv3, tv2);
2462
+ tv5 = Fp.pow(tv4, c5);
2463
+ let isQR = Fp.eql(tv5, Fp.ONE);
2464
+ tv2 = Fp.mul(tv3, c7);
2465
+ tv5 = Fp.mul(tv4, tv1);
2466
+ tv3 = Fp.cmov(tv2, tv3, isQR);
2467
+ tv4 = Fp.cmov(tv5, tv4, isQR);
2468
+ for (let i = c1; i > _1n; i--) {
2469
+ let tv5 = i - _2n$1;
2470
+ tv5 = _2n$1 << tv5 - _1n;
2471
+ let tvv5 = Fp.pow(tv4, tv5);
2472
+ const e1 = Fp.eql(tvv5, Fp.ONE);
2473
+ tv2 = Fp.mul(tv3, tv1);
2474
+ tv1 = Fp.mul(tv1, tv1);
2475
+ tvv5 = Fp.mul(tv4, tv1);
2476
+ tv3 = Fp.cmov(tv2, tv3, e1);
2477
+ tv4 = Fp.cmov(tvv5, tv4, e1);
2478
+ }
2479
+ return {
2480
+ isValid: isQR,
2481
+ value: tv3
2482
+ };
2483
+ };
2484
+ if (Fp.ORDER % _4n === _3n) {
2485
+ const c1 = (Fp.ORDER - _3n) / _4n;
2486
+ const c2 = Fp.sqrt(Fp.neg(Z));
2487
+ sqrtRatio = (u, v) => {
2488
+ let tv1 = Fp.sqr(v);
2489
+ const tv2 = Fp.mul(u, v);
2490
+ tv1 = Fp.mul(tv1, tv2);
2491
+ let y1 = Fp.pow(tv1, c1);
2492
+ y1 = Fp.mul(y1, tv2);
2493
+ const y2 = Fp.mul(y1, c2);
2494
+ const tv3 = Fp.mul(Fp.sqr(y1), v);
2495
+ const isQR = Fp.eql(tv3, u);
2496
+ return {
2497
+ isValid: isQR,
2498
+ value: Fp.cmov(y2, y1, isQR)
2499
+ };
2500
+ };
2501
+ }
2502
+ return sqrtRatio;
2503
+ }
2504
+ /**
2505
+ * Simplified Shallue-van de Woestijne-Ulas Method
2506
+ * https://www.rfc-editor.org/rfc/rfc9380#section-6.6.2
2507
+ */
2508
+ function mapToCurveSimpleSWU(Fp, opts) {
2509
+ validateField(Fp);
2510
+ const { A, B, Z } = opts;
2511
+ if (!Fp.isValid(A) || !Fp.isValid(B) || !Fp.isValid(Z)) throw new Error("mapToCurveSimpleSWU: invalid opts");
2512
+ const sqrtRatio = SWUFpSqrtRatio(Fp, Z);
2513
+ if (!Fp.isOdd) throw new Error("Field does not have .isOdd()");
2514
+ return (u) => {
2515
+ let tv1, tv2, tv3, tv4, tv5, tv6, x, y;
2516
+ tv1 = Fp.sqr(u);
2517
+ tv1 = Fp.mul(tv1, Z);
2518
+ tv2 = Fp.sqr(tv1);
2519
+ tv2 = Fp.add(tv2, tv1);
2520
+ tv3 = Fp.add(tv2, Fp.ONE);
2521
+ tv3 = Fp.mul(tv3, B);
2522
+ tv4 = Fp.cmov(Z, Fp.neg(tv2), !Fp.eql(tv2, Fp.ZERO));
2523
+ tv4 = Fp.mul(tv4, A);
2524
+ tv2 = Fp.sqr(tv3);
2525
+ tv6 = Fp.sqr(tv4);
2526
+ tv5 = Fp.mul(tv6, A);
2527
+ tv2 = Fp.add(tv2, tv5);
2528
+ tv2 = Fp.mul(tv2, tv3);
2529
+ tv6 = Fp.mul(tv6, tv4);
2530
+ tv5 = Fp.mul(tv6, B);
2531
+ tv2 = Fp.add(tv2, tv5);
2532
+ x = Fp.mul(tv1, tv3);
2533
+ const { isValid, value } = sqrtRatio(tv2, tv6);
2534
+ y = Fp.mul(tv1, u);
2535
+ y = Fp.mul(y, value);
2536
+ x = Fp.cmov(x, tv3, isValid);
2537
+ y = Fp.cmov(y, value, isValid);
2538
+ const e1 = Fp.isOdd(u) === Fp.isOdd(y);
2539
+ y = Fp.cmov(Fp.neg(y), y, e1);
2540
+ const tv4_inv = FpInvertBatch(Fp, [tv4], true)[0];
2541
+ x = Fp.mul(x, tv4_inv);
2542
+ return {
2543
+ x,
2544
+ y
2545
+ };
2546
+ };
2547
+ }
2548
+ function getWLengths(Fp, Fn) {
2549
+ return {
2550
+ secretKey: Fn.BYTES,
2551
+ publicKey: 1 + Fp.BYTES,
2552
+ publicKeyUncompressed: 1 + 2 * Fp.BYTES,
2553
+ publicKeyHasPrefix: true,
2554
+ signature: 2 * Fn.BYTES
2555
+ };
2556
+ }
2557
+ /**
2558
+ * Sometimes users only need getPublicKey, getSharedSecret, and secret key handling.
2559
+ * This helper ensures no signature functionality is present. Less code, smaller bundle size.
2560
+ */
2561
+ function ecdh(Point, ecdhOpts = {}) {
2562
+ const { Fn } = Point;
2563
+ const randomBytes_ = ecdhOpts.randomBytes || randomBytes;
2564
+ const lengths = Object.assign(getWLengths(Point.Fp, Fn), { seed: getMinHashLength(Fn.ORDER) });
2565
+ function isValidSecretKey(secretKey) {
2566
+ try {
2567
+ const num = Fn.fromBytes(secretKey);
2568
+ return Fn.isValidNot0(num);
2569
+ } catch (error) {
2570
+ return false;
2571
+ }
2572
+ }
2573
+ function isValidPublicKey(publicKey, isCompressed) {
2574
+ const { publicKey: comp, publicKeyUncompressed } = lengths;
2575
+ try {
2576
+ const l = publicKey.length;
2577
+ if (isCompressed === true && l !== comp) return false;
2578
+ if (isCompressed === false && l !== publicKeyUncompressed) return false;
2579
+ return !!Point.fromBytes(publicKey);
2580
+ } catch (error) {
2581
+ return false;
2582
+ }
2583
+ }
2584
+ /**
2585
+ * Produces cryptographically secure secret key from random of size
2586
+ * (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
2587
+ */
2588
+ function randomSecretKey(seed = randomBytes_(lengths.seed)) {
2589
+ return mapHashToField(abytes$1(seed, lengths.seed, "seed"), Fn.ORDER);
2590
+ }
2591
+ /**
2592
+ * Computes public key for a secret key. Checks for validity of the secret key.
2593
+ * @param isCompressed whether to return compact (default), or full key
2594
+ * @returns Public key, full when isCompressed=false; short when isCompressed=true
2595
+ */
2596
+ function getPublicKey(secretKey, isCompressed = true) {
2597
+ return Point.BASE.multiply(Fn.fromBytes(secretKey)).toBytes(isCompressed);
2598
+ }
2599
+ /**
2600
+ * Quick and dirty check for item being public key. Does not validate hex, or being on-curve.
2601
+ */
2602
+ function isProbPub(item) {
2603
+ const { secretKey, publicKey, publicKeyUncompressed } = lengths;
2604
+ if (!isBytes$1(item)) return void 0;
2605
+ if ("_lengths" in Fn && Fn._lengths || secretKey === publicKey) return void 0;
2606
+ const l = abytes$1(item, void 0, "key").length;
2607
+ return l === publicKey || l === publicKeyUncompressed;
2608
+ }
2609
+ /**
2610
+ * ECDH (Elliptic Curve Diffie Hellman).
2611
+ * Computes shared public key from secret key A and public key B.
2612
+ * Checks: 1) secret key validity 2) shared key is on-curve.
2613
+ * Does NOT hash the result.
2614
+ * @param isCompressed whether to return compact (default), or full key
2615
+ * @returns shared public key
2616
+ */
2617
+ function getSharedSecret(secretKeyA, publicKeyB, isCompressed = true) {
2618
+ if (isProbPub(secretKeyA) === true) throw new Error("first arg must be private key");
2619
+ if (isProbPub(publicKeyB) === false) throw new Error("second arg must be public key");
2620
+ const s = Fn.fromBytes(secretKeyA);
2621
+ return Point.fromBytes(publicKeyB).multiply(s).toBytes(isCompressed);
2622
+ }
2623
+ const utils = {
2624
+ isValidSecretKey,
2625
+ isValidPublicKey,
2626
+ randomSecretKey
2627
+ };
2628
+ const keygen = createKeygen(randomSecretKey, getPublicKey);
2629
+ return Object.freeze({
2630
+ getPublicKey,
2631
+ getSharedSecret,
2632
+ keygen,
2633
+ Point,
2634
+ utils,
2635
+ lengths
2636
+ });
2637
+ }
2638
+ /**
2639
+ * Creates ECDSA signing interface for given elliptic curve `Point` and `hash` function.
2640
+ *
2641
+ * @param Point created using {@link weierstrass} function
2642
+ * @param hash used for 1) message prehash-ing 2) k generation in `sign`, using hmac_drbg(hash)
2643
+ * @param ecdsaOpts rarely needed, see {@link ECDSAOpts}
2644
+ *
2645
+ * @example
2646
+ * ```js
2647
+ * const p256_Point = weierstrass(...);
2648
+ * const p256_sha256 = ecdsa(p256_Point, sha256);
2649
+ * const p256_sha224 = ecdsa(p256_Point, sha224);
2650
+ * const p256_sha224_r = ecdsa(p256_Point, sha224, { randomBytes: (length) => { ... } });
2651
+ * ```
2652
+ */
2653
+ function ecdsa(Point, hash, ecdsaOpts = {}) {
2654
+ ahash(hash);
2655
+ validateObject(ecdsaOpts, {}, {
2656
+ hmac: "function",
2657
+ lowS: "boolean",
2658
+ randomBytes: "function",
2659
+ bits2int: "function",
2660
+ bits2int_modN: "function"
2661
+ });
2662
+ ecdsaOpts = Object.assign({}, ecdsaOpts);
2663
+ const randomBytes$1 = ecdsaOpts.randomBytes || randomBytes;
2664
+ const hmac$1 = ecdsaOpts.hmac || ((key, msg) => hmac(hash, key, msg));
2665
+ const { Fp, Fn } = Point;
2666
+ const { ORDER: CURVE_ORDER, BITS: fnBits } = Fn;
2667
+ const { keygen, getPublicKey, getSharedSecret, utils, lengths } = ecdh(Point, ecdsaOpts);
2668
+ const defaultSigOpts = {
2669
+ prehash: true,
2670
+ lowS: typeof ecdsaOpts.lowS === "boolean" ? ecdsaOpts.lowS : true,
2671
+ format: "compact",
2672
+ extraEntropy: false
2673
+ };
2674
+ const hasLargeCofactor = CURVE_ORDER * _2n$1 < Fp.ORDER;
2675
+ function isBiggerThanHalfOrder(number) {
2676
+ return number > CURVE_ORDER >> _1n;
2677
+ }
2678
+ function validateRS(title, num) {
2679
+ if (!Fn.isValidNot0(num)) throw new Error(`invalid signature ${title}: out of range 1..Point.Fn.ORDER`);
2680
+ return num;
2681
+ }
2682
+ function assertSmallCofactor() {
2683
+ if (hasLargeCofactor) throw new Error("\"recovered\" sig type is not supported for cofactor >2 curves");
2684
+ }
2685
+ function validateSigLength(bytes, format) {
2686
+ validateSigFormat(format);
2687
+ const size = lengths.signature;
2688
+ return abytes$1(bytes, format === "compact" ? size : format === "recovered" ? size + 1 : void 0);
2689
+ }
2690
+ /**
2691
+ * ECDSA signature with its (r, s) properties. Supports compact, recovered & DER representations.
2692
+ */
2693
+ class Signature {
2694
+ r;
2695
+ s;
2696
+ recovery;
2697
+ constructor(r, s, recovery) {
2698
+ this.r = validateRS("r", r);
2699
+ this.s = validateRS("s", s);
2700
+ if (recovery != null) {
2701
+ assertSmallCofactor();
2702
+ if (![
2703
+ 0,
2704
+ 1,
2705
+ 2,
2706
+ 3
2707
+ ].includes(recovery)) throw new Error("invalid recovery id");
2708
+ this.recovery = recovery;
2709
+ }
2710
+ Object.freeze(this);
2711
+ }
2712
+ static fromBytes(bytes, format = defaultSigOpts.format) {
2713
+ validateSigLength(bytes, format);
2714
+ let recid;
2715
+ if (format === "der") {
2716
+ const { r, s } = DER.toSig(abytes$1(bytes));
2717
+ return new Signature(r, s);
2718
+ }
2719
+ if (format === "recovered") {
2720
+ recid = bytes[0];
2721
+ format = "compact";
2722
+ bytes = bytes.subarray(1);
2723
+ }
2724
+ const L = lengths.signature / 2;
2725
+ const r = bytes.subarray(0, L);
2726
+ const s = bytes.subarray(L, L * 2);
2727
+ return new Signature(Fn.fromBytes(r), Fn.fromBytes(s), recid);
2728
+ }
2729
+ static fromHex(hex, format) {
2730
+ return this.fromBytes(hexToBytes(hex), format);
2731
+ }
2732
+ assertRecovery() {
2733
+ const { recovery } = this;
2734
+ if (recovery == null) throw new Error("invalid recovery id: must be present");
2735
+ return recovery;
2736
+ }
2737
+ addRecoveryBit(recovery) {
2738
+ return new Signature(this.r, this.s, recovery);
2739
+ }
2740
+ recoverPublicKey(messageHash) {
2741
+ const { r, s } = this;
2742
+ const recovery = this.assertRecovery();
2743
+ const radj = recovery === 2 || recovery === 3 ? r + CURVE_ORDER : r;
2744
+ if (!Fp.isValid(radj)) throw new Error("invalid recovery id: sig.r+curve.n != R.x");
2745
+ const x = Fp.toBytes(radj);
2746
+ const R = Point.fromBytes(concatBytes(pprefix((recovery & 1) === 0), x));
2747
+ const ir = Fn.inv(radj);
2748
+ const h = bits2int_modN(abytes$1(messageHash, void 0, "msgHash"));
2749
+ const u1 = Fn.create(-h * ir);
2750
+ const u2 = Fn.create(s * ir);
2751
+ const Q = Point.BASE.multiplyUnsafe(u1).add(R.multiplyUnsafe(u2));
2752
+ if (Q.is0()) throw new Error("invalid recovery: point at infinify");
2753
+ Q.assertValidity();
2754
+ return Q;
2755
+ }
2756
+ hasHighS() {
2757
+ return isBiggerThanHalfOrder(this.s);
2758
+ }
2759
+ toBytes(format = defaultSigOpts.format) {
2760
+ validateSigFormat(format);
2761
+ if (format === "der") return hexToBytes(DER.hexFromSig(this));
2762
+ const { r, s } = this;
2763
+ const rb = Fn.toBytes(r);
2764
+ const sb = Fn.toBytes(s);
2765
+ if (format === "recovered") {
2766
+ assertSmallCofactor();
2767
+ return concatBytes(Uint8Array.of(this.assertRecovery()), rb, sb);
2768
+ }
2769
+ return concatBytes(rb, sb);
2770
+ }
2771
+ toHex(format) {
2772
+ return bytesToHex(this.toBytes(format));
2773
+ }
2774
+ }
2775
+ const bits2int = ecdsaOpts.bits2int || function bits2int_def(bytes) {
2776
+ if (bytes.length > 8192) throw new Error("input is too large");
2777
+ const num = bytesToNumberBE(bytes);
2778
+ const delta = bytes.length * 8 - fnBits;
2779
+ return delta > 0 ? num >> BigInt(delta) : num;
2780
+ };
2781
+ const bits2int_modN = ecdsaOpts.bits2int_modN || function bits2int_modN_def(bytes) {
2782
+ return Fn.create(bits2int(bytes));
2783
+ };
2784
+ const ORDER_MASK = bitMask(fnBits);
2785
+ /** Converts to bytes. Checks if num in `[0..ORDER_MASK-1]` e.g.: `[0..2^256-1]`. */
2786
+ function int2octets(num) {
2787
+ aInRange("num < 2^" + fnBits, num, _0n, ORDER_MASK);
2788
+ return Fn.toBytes(num);
2789
+ }
2790
+ function validateMsgAndHash(message, prehash) {
2791
+ abytes$1(message, void 0, "message");
2792
+ return prehash ? abytes$1(hash(message), void 0, "prehashed message") : message;
2793
+ }
2794
+ /**
2795
+ * Steps A, D of RFC6979 3.2.
2796
+ * Creates RFC6979 seed; converts msg/privKey to numbers.
2797
+ * Used only in sign, not in verify.
2798
+ *
2799
+ * Warning: we cannot assume here that message has same amount of bytes as curve order,
2800
+ * this will be invalid at least for P521. Also it can be bigger for P224 + SHA256.
2801
+ */
2802
+ function prepSig(message, secretKey, opts) {
2803
+ const { lowS, prehash, extraEntropy } = validateSigOpts(opts, defaultSigOpts);
2804
+ message = validateMsgAndHash(message, prehash);
2805
+ const h1int = bits2int_modN(message);
2806
+ const d = Fn.fromBytes(secretKey);
2807
+ if (!Fn.isValidNot0(d)) throw new Error("invalid private key");
2808
+ const seedArgs = [int2octets(d), int2octets(h1int)];
2809
+ if (extraEntropy != null && extraEntropy !== false) {
2810
+ const e = extraEntropy === true ? randomBytes$1(lengths.secretKey) : extraEntropy;
2811
+ seedArgs.push(abytes$1(e, void 0, "extraEntropy"));
2812
+ }
2813
+ const seed = concatBytes(...seedArgs);
2814
+ const m = h1int;
2815
+ function k2sig(kBytes) {
2816
+ const k = bits2int(kBytes);
2817
+ if (!Fn.isValidNot0(k)) return;
2818
+ const ik = Fn.inv(k);
2819
+ const q = Point.BASE.multiply(k).toAffine();
2820
+ const r = Fn.create(q.x);
2821
+ if (r === _0n) return;
2822
+ const s = Fn.create(ik * Fn.create(m + r * d));
2823
+ if (s === _0n) return;
2824
+ let recovery = (q.x === r ? 0 : 2) | Number(q.y & _1n);
2825
+ let normS = s;
2826
+ if (lowS && isBiggerThanHalfOrder(s)) {
2827
+ normS = Fn.neg(s);
2828
+ recovery ^= 1;
2829
+ }
2830
+ return new Signature(r, normS, hasLargeCofactor ? void 0 : recovery);
2831
+ }
2832
+ return {
2833
+ seed,
2834
+ k2sig
2835
+ };
2836
+ }
2837
+ /**
2838
+ * Signs message hash with a secret key.
2839
+ *
2840
+ * ```
2841
+ * sign(m, d) where
2842
+ * k = rfc6979_hmac_drbg(m, d)
2843
+ * (x, y) = G × k
2844
+ * r = x mod n
2845
+ * s = (m + dr) / k mod n
2846
+ * ```
2847
+ */
2848
+ function sign(message, secretKey, opts = {}) {
2849
+ const { seed, k2sig } = prepSig(message, secretKey, opts);
2850
+ return createHmacDrbg(hash.outputLen, Fn.BYTES, hmac$1)(seed, k2sig).toBytes(opts.format);
2851
+ }
2852
+ /**
2853
+ * Verifies a signature against message and public key.
2854
+ * Rejects lowS signatures by default: see {@link ECDSAVerifyOpts}.
2855
+ * Implements section 4.1.4 from https://www.secg.org/sec1-v2.pdf:
2856
+ *
2857
+ * ```
2858
+ * verify(r, s, h, P) where
2859
+ * u1 = hs^-1 mod n
2860
+ * u2 = rs^-1 mod n
2861
+ * R = u1⋅G + u2⋅P
2862
+ * mod(R.x, n) == r
2863
+ * ```
2864
+ */
2865
+ function verify(signature, message, publicKey, opts = {}) {
2866
+ const { lowS, prehash, format } = validateSigOpts(opts, defaultSigOpts);
2867
+ publicKey = abytes$1(publicKey, void 0, "publicKey");
2868
+ message = validateMsgAndHash(message, prehash);
2869
+ if (!isBytes$1(signature)) {
2870
+ const end = signature instanceof Signature ? ", use sig.toBytes()" : "";
2871
+ throw new Error("verify expects Uint8Array signature" + end);
2872
+ }
2873
+ validateSigLength(signature, format);
2874
+ try {
2875
+ const sig = Signature.fromBytes(signature, format);
2876
+ const P = Point.fromBytes(publicKey);
2877
+ if (lowS && sig.hasHighS()) return false;
2878
+ const { r, s } = sig;
2879
+ const h = bits2int_modN(message);
2880
+ const is = Fn.inv(s);
2881
+ const u1 = Fn.create(h * is);
2882
+ const u2 = Fn.create(r * is);
2883
+ const R = Point.BASE.multiplyUnsafe(u1).add(P.multiplyUnsafe(u2));
2884
+ if (R.is0()) return false;
2885
+ return Fn.create(R.x) === r;
2886
+ } catch (e) {
2887
+ return false;
2888
+ }
2889
+ }
2890
+ function recoverPublicKey(signature, message, opts = {}) {
2891
+ const { prehash } = validateSigOpts(opts, defaultSigOpts);
2892
+ message = validateMsgAndHash(message, prehash);
2893
+ return Signature.fromBytes(signature, "recovered").recoverPublicKey(message).toBytes();
2894
+ }
2895
+ return Object.freeze({
2896
+ keygen,
2897
+ getPublicKey,
2898
+ getSharedSecret,
2899
+ utils,
2900
+ lengths,
2901
+ Point,
2902
+ sign,
2903
+ verify,
2904
+ recoverPublicKey,
2905
+ Signature,
2906
+ hash
2907
+ });
2908
+ }
2909
+ //#endregion
2910
+ //#region ../../node_modules/@scure/bip32/node_modules/@noble/curves/secp256k1.js
2911
+ /**
2912
+ * SECG secp256k1. See [pdf](https://www.secg.org/sec2-v2.pdf).
2913
+ *
2914
+ * Belongs to Koblitz curves: it has efficiently-computable GLV endomorphism ψ,
2915
+ * check out {@link EndomorphismOpts}. Seems to be rigid (not backdoored).
2916
+ * @module
2917
+ */
2918
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2919
+ const secp256k1_CURVE = {
2920
+ p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),
2921
+ n: BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
2922
+ h: BigInt(1),
2923
+ a: BigInt(0),
2924
+ b: BigInt(7),
2925
+ Gx: BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),
2926
+ Gy: BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")
2927
+ };
2928
+ const secp256k1_ENDO = {
2929
+ beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
2930
+ basises: [[BigInt("0x3086d221a7d46bcde86c90e49284eb15"), -BigInt("0xe4437ed6010e88286f547fa90abfe4c3")], [BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]
2931
+ };
2932
+ const _2n = /* @__PURE__ */ BigInt(2);
2933
+ /**
2934
+ * √n = n^((p+1)/4) for fields p = 3 mod 4. We unwrap the loop and multiply bit-by-bit.
2935
+ * (P+1n/4n).toString(2) would produce bits [223x 1, 0, 22x 1, 4x 0, 11, 00]
2936
+ */
2937
+ function sqrtMod(y) {
2938
+ const P = secp256k1_CURVE.p;
2939
+ const _3n = BigInt(3), _6n = BigInt(6), _11n = BigInt(11), _22n = BigInt(22);
2940
+ const _23n = BigInt(23), _44n = BigInt(44), _88n = BigInt(88);
2941
+ const b2 = y * y * y % P;
2942
+ const b3 = b2 * b2 * y % P;
2943
+ const b11 = pow2(pow2(pow2(b3, _3n, P) * b3 % P, _3n, P) * b3 % P, _2n, P) * b2 % P;
2944
+ const b22 = pow2(b11, _11n, P) * b11 % P;
2945
+ const b44 = pow2(b22, _22n, P) * b22 % P;
2946
+ const b88 = pow2(b44, _44n, P) * b44 % P;
2947
+ const root = pow2(pow2(pow2(pow2(pow2(pow2(b88, _88n, P) * b88 % P, _44n, P) * b44 % P, _3n, P) * b3 % P, _23n, P) * b22 % P, _6n, P) * b2 % P, _2n, P);
2948
+ if (!Fpk1.eql(Fpk1.sqr(root), y)) throw new Error("Cannot find square root");
2949
+ return root;
2950
+ }
2951
+ const Fpk1 = Field(secp256k1_CURVE.p, { sqrt: sqrtMod });
2952
+ const Pointk1 = /* @__PURE__ */ weierstrass(secp256k1_CURVE, {
2953
+ Fp: Fpk1,
2954
+ endo: secp256k1_ENDO
2955
+ });
2956
+ /**
2957
+ * secp256k1 curve: ECDSA and ECDH methods.
2958
+ *
2959
+ * Uses sha256 to hash messages. To use a different hash,
2960
+ * pass `{ prehash: false }` to sign / verify.
2961
+ *
2962
+ * @example
2963
+ * ```js
2964
+ * import { secp256k1 } from '@noble/curves/secp256k1.js';
2965
+ * const { secretKey, publicKey } = secp256k1.keygen();
2966
+ * // const publicKey = secp256k1.getPublicKey(secretKey);
2967
+ * const msg = new TextEncoder().encode('hello noble');
2968
+ * const sig = secp256k1.sign(msg, secretKey);
2969
+ * const isValid = secp256k1.verify(sig, msg, publicKey);
2970
+ * // const sigKeccak = secp256k1.sign(keccak256(msg), secretKey, { prehash: false });
2971
+ * ```
2972
+ */
2973
+ const secp256k1 = /* @__PURE__ */ ecdsa(Pointk1, sha256);
2974
+ const isoMap = isogenyMap(Fpk1, [
2975
+ [
2976
+ "0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7",
2977
+ "0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581",
2978
+ "0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262",
2979
+ "0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"
2980
+ ],
2981
+ [
2982
+ "0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b",
2983
+ "0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14",
2984
+ "0x0000000000000000000000000000000000000000000000000000000000000001"
2985
+ ],
2986
+ [
2987
+ "0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c",
2988
+ "0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3",
2989
+ "0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931",
2990
+ "0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"
2991
+ ],
2992
+ [
2993
+ "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b",
2994
+ "0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573",
2995
+ "0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f",
2996
+ "0x0000000000000000000000000000000000000000000000000000000000000001"
2997
+ ]
2998
+ ].map((i) => i.map((j) => BigInt(j))));
2999
+ const mapSWU = mapToCurveSimpleSWU(Fpk1, {
3000
+ A: BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),
3001
+ B: BigInt("1771"),
3002
+ Z: Fpk1.create(BigInt("-11"))
3003
+ });
3004
+ createHasher(Pointk1, (scalars) => {
3005
+ const { x, y } = mapSWU(Fpk1.create(scalars[0]));
3006
+ return isoMap(x, y);
3007
+ }, {
3008
+ DST: "secp256k1_XMD:SHA-256_SSWU_RO_",
3009
+ encodeDST: "secp256k1_XMD:SHA-256_SSWU_NU_",
3010
+ p: Fpk1.ORDER,
3011
+ m: 1,
3012
+ k: 128,
3013
+ expand: "xmd",
3014
+ hash: sha256
3015
+ });
3016
+ //#endregion
3017
+ //#region ../../node_modules/@scure/bip32/node_modules/@noble/hashes/legacy.js
3018
+ /**
3019
+
3020
+ SHA1 (RFC 3174), MD5 (RFC 1321) and RIPEMD160 (RFC 2286) legacy, weak hash functions.
3021
+ Don't use them in a new protocol. What "weak" means:
3022
+
3023
+ - Collisions can be made with 2^18 effort in MD5, 2^60 in SHA1, 2^80 in RIPEMD160.
3024
+ - No practical pre-image attacks (only theoretical, 2^123.4)
3025
+ - HMAC seems kinda ok: https://www.rfc-editor.org/rfc/rfc6151
3026
+ * @module
3027
+ */
3028
+ const Rho160 = /* @__PURE__ */ Uint8Array.from([
3029
+ 7,
3030
+ 4,
3031
+ 13,
3032
+ 1,
3033
+ 10,
3034
+ 6,
3035
+ 15,
3036
+ 3,
3037
+ 12,
3038
+ 0,
3039
+ 9,
3040
+ 5,
3041
+ 2,
3042
+ 14,
3043
+ 11,
3044
+ 8
3045
+ ]);
3046
+ const Id160 = Uint8Array.from(new Array(16).fill(0).map((_, i) => i));
3047
+ const Pi160 = Id160.map((i) => (9 * i + 5) % 16);
3048
+ const idxLR = /* @__PURE__ */ (() => {
3049
+ const res = [[Id160], [Pi160]];
3050
+ for (let i = 0; i < 4; i++) for (let j of res) j.push(j[i].map((k) => Rho160[k]));
3051
+ return res;
3052
+ })();
3053
+ const idxL = idxLR[0];
3054
+ const idxR = idxLR[1];
3055
+ const shifts160 = /* @__PURE__ */ [
3056
+ [
3057
+ 11,
3058
+ 14,
3059
+ 15,
3060
+ 12,
3061
+ 5,
3062
+ 8,
3063
+ 7,
3064
+ 9,
3065
+ 11,
3066
+ 13,
3067
+ 14,
3068
+ 15,
3069
+ 6,
3070
+ 7,
3071
+ 9,
3072
+ 8
3073
+ ],
3074
+ [
3075
+ 12,
3076
+ 13,
3077
+ 11,
3078
+ 15,
3079
+ 6,
3080
+ 9,
3081
+ 9,
3082
+ 7,
3083
+ 12,
3084
+ 15,
3085
+ 11,
3086
+ 13,
3087
+ 7,
3088
+ 8,
3089
+ 7,
3090
+ 7
3091
+ ],
3092
+ [
3093
+ 13,
3094
+ 15,
3095
+ 14,
3096
+ 11,
3097
+ 7,
3098
+ 7,
3099
+ 6,
3100
+ 8,
3101
+ 13,
3102
+ 14,
3103
+ 13,
3104
+ 12,
3105
+ 5,
3106
+ 5,
3107
+ 6,
3108
+ 9
3109
+ ],
3110
+ [
3111
+ 14,
3112
+ 11,
3113
+ 12,
3114
+ 14,
3115
+ 8,
3116
+ 6,
3117
+ 5,
3118
+ 5,
3119
+ 15,
3120
+ 12,
3121
+ 15,
3122
+ 14,
3123
+ 9,
3124
+ 9,
3125
+ 8,
3126
+ 6
3127
+ ],
3128
+ [
3129
+ 15,
3130
+ 12,
3131
+ 13,
3132
+ 13,
3133
+ 9,
3134
+ 5,
3135
+ 8,
3136
+ 6,
3137
+ 14,
3138
+ 11,
3139
+ 12,
3140
+ 11,
3141
+ 8,
3142
+ 6,
3143
+ 5,
3144
+ 5
3145
+ ]
3146
+ ].map((i) => Uint8Array.from(i));
3147
+ const shiftsL160 = /* @__PURE__ */ idxL.map((idx, i) => idx.map((j) => shifts160[i][j]));
3148
+ const shiftsR160 = /* @__PURE__ */ idxR.map((idx, i) => idx.map((j) => shifts160[i][j]));
3149
+ const Kl160 = /* @__PURE__ */ Uint32Array.from([
3150
+ 0,
3151
+ 1518500249,
3152
+ 1859775393,
3153
+ 2400959708,
3154
+ 2840853838
3155
+ ]);
3156
+ const Kr160 = /* @__PURE__ */ Uint32Array.from([
3157
+ 1352829926,
3158
+ 1548603684,
3159
+ 1836072691,
3160
+ 2053994217,
3161
+ 0
3162
+ ]);
3163
+ function ripemd_f(group, x, y, z) {
3164
+ if (group === 0) return x ^ y ^ z;
3165
+ if (group === 1) return x & y | ~x & z;
3166
+ if (group === 2) return (x | ~y) ^ z;
3167
+ if (group === 3) return x & z | y & ~z;
3168
+ return x ^ (y | ~z);
3169
+ }
3170
+ const BUF_160 = /* @__PURE__ */ new Uint32Array(16);
3171
+ var _RIPEMD160 = class extends HashMD {
3172
+ h0 = 1732584193;
3173
+ h1 = -271733879;
3174
+ h2 = -1732584194;
3175
+ h3 = 271733878;
3176
+ h4 = -1009589776;
3177
+ constructor() {
3178
+ super(64, 20, 8, true);
3179
+ }
3180
+ get() {
3181
+ const { h0, h1, h2, h3, h4 } = this;
3182
+ return [
3183
+ h0,
3184
+ h1,
3185
+ h2,
3186
+ h3,
3187
+ h4
3188
+ ];
3189
+ }
3190
+ set(h0, h1, h2, h3, h4) {
3191
+ this.h0 = h0 | 0;
3192
+ this.h1 = h1 | 0;
3193
+ this.h2 = h2 | 0;
3194
+ this.h3 = h3 | 0;
3195
+ this.h4 = h4 | 0;
3196
+ }
3197
+ process(view, offset) {
3198
+ for (let i = 0; i < 16; i++, offset += 4) BUF_160[i] = view.getUint32(offset, true);
3199
+ let al = this.h0 | 0, ar = al, bl = this.h1 | 0, br = bl, cl = this.h2 | 0, cr = cl, dl = this.h3 | 0, dr = dl, el = this.h4 | 0, er = el;
3200
+ for (let group = 0; group < 5; group++) {
3201
+ const rGroup = 4 - group;
3202
+ const hbl = Kl160[group], hbr = Kr160[group];
3203
+ const rl = idxL[group], rr = idxR[group];
3204
+ const sl = shiftsL160[group], sr = shiftsR160[group];
3205
+ for (let i = 0; i < 16; i++) {
3206
+ const tl = rotl(al + ripemd_f(group, bl, cl, dl) + BUF_160[rl[i]] + hbl, sl[i]) + el | 0;
3207
+ al = el, el = dl, dl = rotl(cl, 10) | 0, cl = bl, bl = tl;
3208
+ }
3209
+ for (let i = 0; i < 16; i++) {
3210
+ const tr = rotl(ar + ripemd_f(rGroup, br, cr, dr) + BUF_160[rr[i]] + hbr, sr[i]) + er | 0;
3211
+ ar = er, er = dr, dr = rotl(cr, 10) | 0, cr = br, br = tr;
3212
+ }
3213
+ }
3214
+ this.set(this.h1 + cl + dr | 0, this.h2 + dl + er | 0, this.h3 + el + ar | 0, this.h4 + al + br | 0, this.h0 + bl + cr | 0);
3215
+ }
3216
+ roundClean() {
3217
+ clean(BUF_160);
3218
+ }
3219
+ destroy() {
3220
+ this.destroyed = true;
3221
+ clean(this.buffer);
3222
+ this.set(0, 0, 0, 0, 0);
3223
+ }
3224
+ };
3225
+ /**
3226
+ * RIPEMD-160 - a legacy hash function from 1990s.
3227
+ * * https://homes.esat.kuleuven.be/~bosselae/ripemd160.html
3228
+ * * https://homes.esat.kuleuven.be/~bosselae/ripemd160/pdf/AB-9601/AB-9601.pdf
3229
+ */
3230
+ const ripemd160 = /* @__PURE__ */ createHasher$1(() => new _RIPEMD160());
3231
+ //#endregion
3232
+ //#region ../../node_modules/@scure/bip32/node_modules/@scure/base/index.js
3233
+ /*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
3234
+ function isBytes(a) {
3235
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
3236
+ }
3237
+ function isArrayOf(isString, arr) {
3238
+ if (!Array.isArray(arr)) return false;
3239
+ if (arr.length === 0) return true;
3240
+ if (isString) return arr.every((item) => typeof item === "string");
3241
+ else return arr.every((item) => Number.isSafeInteger(item));
3242
+ }
3243
+ function afn(input) {
3244
+ if (typeof input !== "function") throw new Error("function expected");
3245
+ return true;
3246
+ }
3247
+ function astr(label, input) {
3248
+ if (typeof input !== "string") throw new Error(`${label}: string expected`);
3249
+ return true;
3250
+ }
3251
+ function anumber(n) {
3252
+ if (!Number.isSafeInteger(n)) throw new Error(`invalid integer: ${n}`);
3253
+ }
3254
+ function aArr(input) {
3255
+ if (!Array.isArray(input)) throw new Error("array expected");
3256
+ }
3257
+ function astrArr(label, input) {
3258
+ if (!isArrayOf(true, input)) throw new Error(`${label}: array of strings expected`);
3259
+ }
3260
+ function anumArr(label, input) {
3261
+ if (!isArrayOf(false, input)) throw new Error(`${label}: array of numbers expected`);
3262
+ }
3263
+ /**
3264
+ * @__NO_SIDE_EFFECTS__
3265
+ */
3266
+ function chain(...args) {
3267
+ const id = (a) => a;
3268
+ const wrap = (a, b) => (c) => a(b(c));
3269
+ return {
3270
+ encode: args.map((x) => x.encode).reduceRight(wrap, id),
3271
+ decode: args.map((x) => x.decode).reduce(wrap, id)
3272
+ };
3273
+ }
3274
+ /**
3275
+ * Encodes integer radix representation to array of strings using alphabet and back.
3276
+ * Could also be array of strings.
3277
+ * @__NO_SIDE_EFFECTS__
3278
+ */
3279
+ function alphabet(letters) {
3280
+ const lettersA = typeof letters === "string" ? letters.split("") : letters;
3281
+ const len = lettersA.length;
3282
+ astrArr("alphabet", lettersA);
3283
+ const indexes = new Map(lettersA.map((l, i) => [l, i]));
3284
+ return {
3285
+ encode: (digits) => {
3286
+ aArr(digits);
3287
+ return digits.map((i) => {
3288
+ if (!Number.isSafeInteger(i) || i < 0 || i >= len) throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${letters}`);
3289
+ return lettersA[i];
3290
+ });
3291
+ },
3292
+ decode: (input) => {
3293
+ aArr(input);
3294
+ return input.map((letter) => {
3295
+ astr("alphabet.decode", letter);
3296
+ const i = indexes.get(letter);
3297
+ if (i === void 0) throw new Error(`Unknown letter: "${letter}". Allowed: ${letters}`);
3298
+ return i;
3299
+ });
3300
+ }
3301
+ };
3302
+ }
3303
+ /**
3304
+ * @__NO_SIDE_EFFECTS__
3305
+ */
3306
+ function join(separator = "") {
3307
+ astr("join", separator);
3308
+ return {
3309
+ encode: (from) => {
3310
+ astrArr("join.decode", from);
3311
+ return from.join(separator);
3312
+ },
3313
+ decode: (to) => {
3314
+ astr("join.decode", to);
3315
+ return to.split(separator);
3316
+ }
3317
+ };
3318
+ }
3319
+ /**
3320
+ * Pad strings array so it has integer number of bits
3321
+ * @__NO_SIDE_EFFECTS__
3322
+ */
3323
+ function padding(bits, chr = "=") {
3324
+ anumber(bits);
3325
+ astr("padding", chr);
3326
+ return {
3327
+ encode(data) {
3328
+ astrArr("padding.encode", data);
3329
+ while (data.length * bits % 8) data.push(chr);
3330
+ return data;
3331
+ },
3332
+ decode(input) {
3333
+ astrArr("padding.decode", input);
3334
+ let end = input.length;
3335
+ if (end * bits % 8) throw new Error("padding: invalid, string should have whole number of bytes");
3336
+ for (; end > 0 && input[end - 1] === chr; end--) if ((end - 1) * bits % 8 === 0) throw new Error("padding: invalid, string has too much padding");
3337
+ return input.slice(0, end);
3338
+ }
3339
+ };
3340
+ }
3341
+ /**
3342
+ * @__NO_SIDE_EFFECTS__
3343
+ */
3344
+ function normalize(fn) {
3345
+ afn(fn);
3346
+ return {
3347
+ encode: (from) => from,
3348
+ decode: (to) => fn(to)
3349
+ };
3350
+ }
3351
+ /**
3352
+ * Slow: O(n^2) time complexity
3353
+ */
3354
+ function convertRadix(data, from, to) {
3355
+ if (from < 2) throw new Error(`convertRadix: invalid from=${from}, base cannot be less than 2`);
3356
+ if (to < 2) throw new Error(`convertRadix: invalid to=${to}, base cannot be less than 2`);
3357
+ aArr(data);
3358
+ if (!data.length) return [];
3359
+ let pos = 0;
3360
+ const res = [];
3361
+ const digits = Array.from(data, (d) => {
3362
+ anumber(d);
3363
+ if (d < 0 || d >= from) throw new Error(`invalid integer: ${d}`);
3364
+ return d;
3365
+ });
3366
+ const dlen = digits.length;
3367
+ while (true) {
3368
+ let carry = 0;
3369
+ let done = true;
3370
+ for (let i = pos; i < dlen; i++) {
3371
+ const digit = digits[i];
3372
+ const fromCarry = from * carry;
3373
+ const digitBase = fromCarry + digit;
3374
+ if (!Number.isSafeInteger(digitBase) || fromCarry / from !== carry || digitBase - digit !== fromCarry) throw new Error("convertRadix: carry overflow");
3375
+ const div = digitBase / to;
3376
+ carry = digitBase % to;
3377
+ const rounded = Math.floor(div);
3378
+ digits[i] = rounded;
3379
+ if (!Number.isSafeInteger(rounded) || rounded * to + carry !== digitBase) throw new Error("convertRadix: carry overflow");
3380
+ if (!done) continue;
3381
+ else if (!rounded) pos = i;
3382
+ else done = false;
3383
+ }
3384
+ res.push(carry);
3385
+ if (done) break;
3386
+ }
3387
+ for (let i = 0; i < data.length - 1 && data[i] === 0; i++) res.push(0);
3388
+ return res.reverse();
3389
+ }
3390
+ const gcd = (a, b) => b === 0 ? a : gcd(b, a % b);
3391
+ const radix2carry = /* @__NO_SIDE_EFFECTS__ */ (from, to) => from + (to - gcd(from, to));
3392
+ const powers = /* @__PURE__ */ (() => {
3393
+ let res = [];
3394
+ for (let i = 0; i < 40; i++) res.push(2 ** i);
3395
+ return res;
3396
+ })();
3397
+ /**
3398
+ * Implemented with numbers, because BigInt is 5x slower
3399
+ */
3400
+ function convertRadix2(data, from, to, padding) {
3401
+ aArr(data);
3402
+ if (from <= 0 || from > 32) throw new Error(`convertRadix2: wrong from=${from}`);
3403
+ if (to <= 0 || to > 32) throw new Error(`convertRadix2: wrong to=${to}`);
3404
+ if (/* @__PURE__ */ radix2carry(from, to) > 32) throw new Error(`convertRadix2: carry overflow from=${from} to=${to} carryBits=${/* @__PURE__ */ radix2carry(from, to)}`);
3405
+ let carry = 0;
3406
+ let pos = 0;
3407
+ const max = powers[from];
3408
+ const mask = powers[to] - 1;
3409
+ const res = [];
3410
+ for (const n of data) {
3411
+ anumber(n);
3412
+ if (n >= max) throw new Error(`convertRadix2: invalid data word=${n} from=${from}`);
3413
+ carry = carry << from | n;
3414
+ if (pos + from > 32) throw new Error(`convertRadix2: carry overflow pos=${pos} from=${from}`);
3415
+ pos += from;
3416
+ for (; pos >= to; pos -= to) res.push((carry >> pos - to & mask) >>> 0);
3417
+ const pow = powers[pos];
3418
+ if (pow === void 0) throw new Error("invalid carry");
3419
+ carry &= pow - 1;
3420
+ }
3421
+ carry = carry << to - pos & mask;
3422
+ if (!padding && pos >= from) throw new Error("Excess padding");
3423
+ if (!padding && carry > 0) throw new Error(`Non-zero padding: ${carry}`);
3424
+ if (padding && pos > 0) res.push(carry >>> 0);
3425
+ return res;
3426
+ }
3427
+ /**
3428
+ * @__NO_SIDE_EFFECTS__
3429
+ */
3430
+ function radix(num) {
3431
+ anumber(num);
3432
+ const _256 = 2 ** 8;
3433
+ return {
3434
+ encode: (bytes) => {
3435
+ if (!isBytes(bytes)) throw new Error("radix.encode input should be Uint8Array");
3436
+ return convertRadix(Array.from(bytes), _256, num);
3437
+ },
3438
+ decode: (digits) => {
3439
+ anumArr("radix.decode", digits);
3440
+ return Uint8Array.from(convertRadix(digits, num, _256));
3441
+ }
3442
+ };
3443
+ }
3444
+ /**
3445
+ * If both bases are power of same number (like `2**8 <-> 2**64`),
3446
+ * there is a linear algorithm. For now we have implementation for power-of-two bases only.
3447
+ * @__NO_SIDE_EFFECTS__
3448
+ */
3449
+ function radix2(bits, revPadding = false) {
3450
+ anumber(bits);
3451
+ if (bits <= 0 || bits > 32) throw new Error("radix2: bits should be in (0..32]");
3452
+ if (/* @__PURE__ */ radix2carry(8, bits) > 32 || /* @__PURE__ */ radix2carry(bits, 8) > 32) throw new Error("radix2: carry overflow");
3453
+ return {
3454
+ encode: (bytes) => {
3455
+ if (!isBytes(bytes)) throw new Error("radix2.encode input should be Uint8Array");
3456
+ return convertRadix2(Array.from(bytes), 8, bits, !revPadding);
3457
+ },
3458
+ decode: (digits) => {
3459
+ anumArr("radix2.decode", digits);
3460
+ return Uint8Array.from(convertRadix2(digits, bits, 8, revPadding));
3461
+ }
3462
+ };
3463
+ }
3464
+ function unsafeWrapper(fn) {
3465
+ afn(fn);
3466
+ return function(...args) {
3467
+ try {
3468
+ return fn.apply(null, args);
3469
+ } catch (e) {}
3470
+ };
3471
+ }
3472
+ function checksum(len, fn) {
3473
+ anumber(len);
3474
+ afn(fn);
3475
+ return {
3476
+ encode(data) {
3477
+ if (!isBytes(data)) throw new Error("checksum.encode: input should be Uint8Array");
3478
+ const sum = fn(data).slice(0, len);
3479
+ const res = new Uint8Array(data.length + len);
3480
+ res.set(data);
3481
+ res.set(sum, data.length);
3482
+ return res;
3483
+ },
3484
+ decode(data) {
3485
+ if (!isBytes(data)) throw new Error("checksum.decode: input should be Uint8Array");
3486
+ const payload = data.slice(0, -len);
3487
+ const oldChecksum = data.slice(-len);
3488
+ const newChecksum = fn(payload).slice(0, len);
3489
+ for (let i = 0; i < len; i++) if (newChecksum[i] !== oldChecksum[i]) throw new Error("Invalid checksum");
3490
+ return payload;
3491
+ }
3492
+ };
3493
+ }
3494
+ chain(radix2(4), alphabet("0123456789ABCDEF"), join(""));
3495
+ chain(radix2(5), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), padding(5), join(""));
3496
+ chain(radix2(5), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), join(""));
3497
+ chain(radix2(5), alphabet("0123456789ABCDEFGHIJKLMNOPQRSTUV"), padding(5), join(""));
3498
+ chain(radix2(5), alphabet("0123456789ABCDEFGHIJKLMNOPQRSTUV"), join(""));
3499
+ chain(radix2(5), alphabet("0123456789ABCDEFGHJKMNPQRSTVWXYZ"), join(""), normalize((s) => s.toUpperCase().replace(/O/g, "0").replace(/[IL]/g, "1")));
3500
+ const hasBase64Builtin = typeof Uint8Array.from([]).toBase64 === "function" && typeof Uint8Array.fromBase64 === "function";
3501
+ hasBase64Builtin || chain(radix2(6), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), padding(6), join(""));
3502
+ chain(radix2(6), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), join(""));
3503
+ hasBase64Builtin || chain(radix2(6), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), padding(6), join(""));
3504
+ chain(radix2(6), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), join(""));
3505
+ const genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => chain(radix(58), alphabet(abc), join(""));
3506
+ /**
3507
+ * base58: base64 without ambigous characters +, /, 0, O, I, l.
3508
+ * Quadratic (O(n^2)) - so, can't be used on large inputs.
3509
+ * @example
3510
+ * ```js
3511
+ * base58.decode('01abcdef');
3512
+ * // => '3UhJW'
3513
+ * ```
3514
+ */
3515
+ const base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
3516
+ /**
3517
+ * Method, which creates base58check encoder.
3518
+ * Requires function, calculating sha256.
3519
+ */
3520
+ const createBase58check = (sha256) => chain(checksum(4, (data) => sha256(sha256(data))), base58);
3521
+ const BECH_ALPHABET = chain(alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), join(""));
3522
+ const POLYMOD_GENERATORS = [
3523
+ 996825010,
3524
+ 642813549,
3525
+ 513874426,
3526
+ 1027748829,
3527
+ 705979059
3528
+ ];
3529
+ function bech32Polymod(pre) {
3530
+ const b = pre >> 25;
3531
+ let chk = (pre & 33554431) << 5;
3532
+ for (let i = 0; i < POLYMOD_GENERATORS.length; i++) if ((b >> i & 1) === 1) chk ^= POLYMOD_GENERATORS[i];
3533
+ return chk;
3534
+ }
3535
+ function bechChecksum(prefix, words, encodingConst = 1) {
3536
+ const len = prefix.length;
3537
+ let chk = 1;
3538
+ for (let i = 0; i < len; i++) {
3539
+ const c = prefix.charCodeAt(i);
3540
+ if (c < 33 || c > 126) throw new Error(`Invalid prefix (${prefix})`);
3541
+ chk = bech32Polymod(chk) ^ c >> 5;
3542
+ }
3543
+ chk = bech32Polymod(chk);
3544
+ for (let i = 0; i < len; i++) chk = bech32Polymod(chk) ^ prefix.charCodeAt(i) & 31;
3545
+ for (let v of words) chk = bech32Polymod(chk) ^ v;
3546
+ for (let i = 0; i < 6; i++) chk = bech32Polymod(chk);
3547
+ chk ^= encodingConst;
3548
+ return BECH_ALPHABET.encode(convertRadix2([chk % powers[30]], 30, 5, false));
3549
+ }
3550
+ /**
3551
+ * @__NO_SIDE_EFFECTS__
3552
+ */
3553
+ function genBech32(encoding) {
3554
+ const ENCODING_CONST = encoding === "bech32" ? 1 : 734539939;
3555
+ const _words = radix2(5);
3556
+ const fromWords = _words.decode;
3557
+ const toWords = _words.encode;
3558
+ const fromWordsUnsafe = unsafeWrapper(fromWords);
3559
+ function encode(prefix, words, limit = 90) {
3560
+ astr("bech32.encode prefix", prefix);
3561
+ if (isBytes(words)) words = Array.from(words);
3562
+ anumArr("bech32.encode", words);
3563
+ const plen = prefix.length;
3564
+ if (plen === 0) throw new TypeError(`Invalid prefix length ${plen}`);
3565
+ const actualLength = plen + 7 + words.length;
3566
+ if (limit !== false && actualLength > limit) throw new TypeError(`Length ${actualLength} exceeds limit ${limit}`);
3567
+ const lowered = prefix.toLowerCase();
3568
+ const sum = bechChecksum(lowered, words, ENCODING_CONST);
3569
+ return `${lowered}1${BECH_ALPHABET.encode(words)}${sum}`;
3570
+ }
3571
+ function decode(str, limit = 90) {
3572
+ astr("bech32.decode input", str);
3573
+ const slen = str.length;
3574
+ if (slen < 8 || limit !== false && slen > limit) throw new TypeError(`invalid string length: ${slen} (${str}). Expected (8..${limit})`);
3575
+ const lowered = str.toLowerCase();
3576
+ if (str !== lowered && str !== str.toUpperCase()) throw new Error(`String must be lowercase or uppercase`);
3577
+ const sepIndex = lowered.lastIndexOf("1");
3578
+ if (sepIndex === 0 || sepIndex === -1) throw new Error(`Letter "1" must be present between prefix and data only`);
3579
+ const prefix = lowered.slice(0, sepIndex);
3580
+ const data = lowered.slice(sepIndex + 1);
3581
+ if (data.length < 6) throw new Error("Data must be at least 6 characters long");
3582
+ const words = BECH_ALPHABET.decode(data).slice(0, -6);
3583
+ const sum = bechChecksum(prefix, words, ENCODING_CONST);
3584
+ if (!data.endsWith(sum)) throw new Error(`Invalid checksum in ${str}: expected "${sum}"`);
3585
+ return {
3586
+ prefix,
3587
+ words
3588
+ };
3589
+ }
3590
+ const decodeUnsafe = unsafeWrapper(decode);
3591
+ function decodeToBytes(str) {
3592
+ const { prefix, words } = decode(str, false);
3593
+ return {
3594
+ prefix,
3595
+ words,
3596
+ bytes: fromWords(words)
3597
+ };
3598
+ }
3599
+ function encodeFromBytes(prefix, bytes) {
3600
+ return encode(prefix, toWords(bytes));
3601
+ }
3602
+ return {
3603
+ encode,
3604
+ decode,
3605
+ encodeFromBytes,
3606
+ decodeToBytes,
3607
+ decodeUnsafe,
3608
+ fromWords,
3609
+ fromWordsUnsafe,
3610
+ toWords
3611
+ };
3612
+ }
3613
+ genBech32("bech32");
3614
+ genBech32("bech32m");
3615
+ typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function" || chain(radix2(4), alphabet("0123456789abcdef"), join(""), normalize((s) => {
3616
+ if (typeof s !== "string" || s.length % 2 !== 0) throw new TypeError(`hex.decode: expected string, got ${typeof s} with length ${s.length}`);
3617
+ return s.toLowerCase();
3618
+ }));
3619
+ //#endregion
3620
+ //#region ../../node_modules/@scure/bip32/index.js
3621
+ /**
3622
+ * BIP32 hierarchical deterministic (HD) wallets over secp256k1.
3623
+ * @module
3624
+ * @example
3625
+ * ```js
3626
+ * import { HDKey } from "@scure/bip32";
3627
+ * const hdkey1 = HDKey.fromMasterSeed(seed);
3628
+ * const hdkey2 = HDKey.fromExtendedKey(base58key);
3629
+ * const hdkey3 = HDKey.fromJSON({ xpriv: string });
3630
+ *
3631
+ * // props
3632
+ * [hdkey1.depth, hdkey1.index, hdkey1.chainCode];
3633
+ * console.log(hdkey2.privateKey, hdkey2.publicKey);
3634
+ * console.log(hdkey3.derive("m/0/2147483647'/1"));
3635
+ * const sig = hdkey3.sign(hash);
3636
+ * hdkey3.verify(hash, sig);
3637
+ * ```
3638
+ */
3639
+ /*! scure-bip32 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) */
3640
+ const Point = secp256k1.Point;
3641
+ const { Fn } = Point;
3642
+ const base58check = createBase58check(sha256);
3643
+ const MASTER_SECRET = Uint8Array.from("Bitcoin seed".split(""), (char) => char.charCodeAt(0));
3644
+ const BITCOIN_VERSIONS = {
3645
+ private: 76066276,
3646
+ public: 76067358
3647
+ };
3648
+ /** Hardened offset from Bitcoin, default */
3649
+ const HARDENED_OFFSET = 2147483648;
3650
+ const hash160 = (data) => ripemd160(sha256(data));
3651
+ const fromU32 = (data) => createView(data).getUint32(0, false);
3652
+ const toU32 = (n) => {
3653
+ if (!Number.isSafeInteger(n) || n < 0 || n > 2 ** 32 - 1) throw new Error("invalid number, should be from 0 to 2**32-1, got " + n);
3654
+ const buf = new Uint8Array(4);
3655
+ createView(buf).setUint32(0, n, false);
3656
+ return buf;
3657
+ };
3658
+ /**
3659
+ * HDKey from BIP32
3660
+ * @example
3661
+ ```js
3662
+ const hdkey1 = HDKey.fromMasterSeed(seed);
3663
+ const hdkey2 = HDKey.fromExtendedKey(base58key);
3664
+ const hdkey3 = HDKey.fromJSON({ xpriv: string });
3665
+ ```
3666
+ */
3667
+ var HDKey = class HDKey {
3668
+ get fingerprint() {
3669
+ if (!this.pubHash) throw new Error("No publicKey set!");
3670
+ return fromU32(this.pubHash);
3671
+ }
3672
+ get identifier() {
3673
+ return this.pubHash;
3674
+ }
3675
+ get pubKeyHash() {
3676
+ return this.pubHash;
3677
+ }
3678
+ get privateKey() {
3679
+ return this._privateKey || null;
3680
+ }
3681
+ get publicKey() {
3682
+ return this._publicKey || null;
3683
+ }
3684
+ get privateExtendedKey() {
3685
+ const priv = this._privateKey;
3686
+ if (!priv) throw new Error("No private key");
3687
+ return base58check.encode(this.serialize(this.versions.private, concatBytes(Uint8Array.of(0), priv)));
3688
+ }
3689
+ get publicExtendedKey() {
3690
+ if (!this._publicKey) throw new Error("No public key");
3691
+ return base58check.encode(this.serialize(this.versions.public, this._publicKey));
3692
+ }
3693
+ static fromMasterSeed(seed, versions = BITCOIN_VERSIONS) {
3694
+ abytes$1(seed);
3695
+ if (8 * seed.length < 128 || 8 * seed.length > 512) throw new Error("HDKey: seed length must be between 128 and 512 bits; 256 bits is advised, got " + seed.length);
3696
+ const I = hmac(sha512, MASTER_SECRET, seed);
3697
+ const privateKey = I.slice(0, 32);
3698
+ return new HDKey({
3699
+ versions,
3700
+ chainCode: I.slice(32),
3701
+ privateKey
3702
+ });
3703
+ }
3704
+ static fromExtendedKey(base58key, versions = BITCOIN_VERSIONS) {
3705
+ const keyBuffer = base58check.decode(base58key);
3706
+ const keyView = createView(keyBuffer);
3707
+ const version = keyView.getUint32(0, false);
3708
+ const opt = {
3709
+ versions,
3710
+ depth: keyBuffer[4],
3711
+ parentFingerprint: keyView.getUint32(5, false),
3712
+ index: keyView.getUint32(9, false),
3713
+ chainCode: keyBuffer.slice(13, 45)
3714
+ };
3715
+ const key = keyBuffer.slice(45);
3716
+ const isPriv = key[0] === 0;
3717
+ if (version !== versions[isPriv ? "private" : "public"]) throw new Error("Version mismatch");
3718
+ if (isPriv) return new HDKey({
3719
+ ...opt,
3720
+ privateKey: key.slice(1)
3721
+ });
3722
+ else return new HDKey({
3723
+ ...opt,
3724
+ publicKey: key
3725
+ });
3726
+ }
3727
+ static fromJSON(json) {
3728
+ return HDKey.fromExtendedKey(json.xpriv);
3729
+ }
3730
+ versions;
3731
+ depth = 0;
3732
+ index = 0;
3733
+ chainCode = null;
3734
+ parentFingerprint = 0;
3735
+ _privateKey;
3736
+ _publicKey;
3737
+ pubHash;
3738
+ constructor(opt) {
3739
+ if (!opt || typeof opt !== "object") throw new Error("HDKey.constructor must not be called directly");
3740
+ this.versions = opt.versions || BITCOIN_VERSIONS;
3741
+ this.depth = opt.depth || 0;
3742
+ this.chainCode = opt.chainCode || null;
3743
+ this.index = opt.index || 0;
3744
+ this.parentFingerprint = opt.parentFingerprint || 0;
3745
+ if (!this.depth) {
3746
+ if (this.parentFingerprint || this.index) throw new Error("HDKey: zero depth with non-zero index/parent fingerprint");
3747
+ }
3748
+ if (this.depth > 255) throw new Error("HDKey: depth exceeds the serializable value 255");
3749
+ if (opt.publicKey && opt.privateKey) throw new Error("HDKey: publicKey and privateKey at same time.");
3750
+ if (opt.privateKey) {
3751
+ if (!secp256k1.utils.isValidSecretKey(opt.privateKey)) throw new Error("Invalid private key");
3752
+ this._privateKey = opt.privateKey;
3753
+ this._publicKey = secp256k1.getPublicKey(opt.privateKey, true);
3754
+ } else if (opt.publicKey) this._publicKey = Point.fromBytes(opt.publicKey).toBytes(true);
3755
+ else throw new Error("HDKey: no public or private key provided");
3756
+ this.pubHash = hash160(this._publicKey);
3757
+ }
3758
+ derive(path) {
3759
+ if (!/^[mM]'?/.test(path)) throw new Error("Path must start with \"m\" or \"M\"");
3760
+ if (/^[mM]'?$/.test(path)) return this;
3761
+ const parts = path.replace(/^[mM]'?\//, "").split("/");
3762
+ let child = this;
3763
+ for (const c of parts) {
3764
+ const m = /^(\d+)('?)$/.exec(c);
3765
+ const m1 = m && m[1];
3766
+ if (!m || m.length !== 3 || typeof m1 !== "string") throw new Error("invalid child index: " + c);
3767
+ let idx = +m1;
3768
+ if (!Number.isSafeInteger(idx) || idx >= 2147483648) throw new Error("Invalid index");
3769
+ if (m[2] === "'") idx += HARDENED_OFFSET;
3770
+ child = child.deriveChild(idx);
3771
+ }
3772
+ return child;
3773
+ }
3774
+ deriveChild(index) {
3775
+ if (!this._publicKey || !this.chainCode) throw new Error("No publicKey or chainCode set");
3776
+ let data = toU32(index);
3777
+ if (index >= 2147483648) {
3778
+ const priv = this._privateKey;
3779
+ if (!priv) throw new Error("Could not derive hardened child key");
3780
+ data = concatBytes(Uint8Array.of(0), priv, data);
3781
+ } else data = concatBytes(this._publicKey, data);
3782
+ const I = hmac(sha512, this.chainCode, data);
3783
+ const childTweak = I.slice(0, 32);
3784
+ const chainCode = I.slice(32);
3785
+ if (!secp256k1.utils.isValidSecretKey(childTweak)) throw new Error("Tweak bigger than curve order");
3786
+ const opt = {
3787
+ versions: this.versions,
3788
+ chainCode,
3789
+ depth: this.depth + 1,
3790
+ parentFingerprint: this.fingerprint,
3791
+ index
3792
+ };
3793
+ const ctweak = Fn.fromBytes(childTweak);
3794
+ try {
3795
+ if (this._privateKey) {
3796
+ const added = Fn.create(Fn.fromBytes(this._privateKey) + ctweak);
3797
+ if (!Fn.isValidNot0(added)) throw new Error("The tweak was out of range or the resulted private key is invalid");
3798
+ opt.privateKey = Fn.toBytes(added);
3799
+ } else {
3800
+ const added = Point.fromBytes(this._publicKey).add(Point.BASE.multiply(ctweak));
3801
+ if (added.equals(Point.ZERO)) throw new Error("The tweak was equal to negative P, which made the result key invalid");
3802
+ opt.publicKey = added.toBytes(true);
3803
+ }
3804
+ return new HDKey(opt);
3805
+ } catch (err) {
3806
+ return this.deriveChild(index + 1);
3807
+ }
3808
+ }
3809
+ sign(hash) {
3810
+ if (!this._privateKey) throw new Error("No privateKey set!");
3811
+ abytes$1(hash, 32);
3812
+ return secp256k1.sign(hash, this._privateKey, { prehash: false });
3813
+ }
3814
+ verify(hash, signature) {
3815
+ abytes$1(hash, 32);
3816
+ abytes$1(signature, 64);
3817
+ if (!this._publicKey) throw new Error("No publicKey set!");
3818
+ return secp256k1.verify(signature, hash, this._publicKey, { prehash: false });
3819
+ }
3820
+ wipePrivateData() {
3821
+ if (this._privateKey) {
3822
+ this._privateKey.fill(0);
3823
+ this._privateKey = void 0;
3824
+ }
3825
+ return this;
3826
+ }
3827
+ toJSON() {
3828
+ return {
3829
+ xpriv: this.privateExtendedKey,
3830
+ xpub: this.publicExtendedKey
3831
+ };
3832
+ }
3833
+ serialize(version, key) {
3834
+ if (!this.chainCode) throw new Error("No chainCode set");
3835
+ abytes$1(key, 33);
3836
+ return concatBytes(toU32(version), new Uint8Array([this.depth]), toU32(this.parentFingerprint), toU32(this.index), this.chainCode, key);
3837
+ }
3838
+ };
3839
+ //#endregion
3840
+ Object.defineProperty(exports, "HARDENED_OFFSET", {
3841
+ enumerable: true,
3842
+ get: function() {
3843
+ return HARDENED_OFFSET;
3844
+ }
3845
+ });
3846
+ Object.defineProperty(exports, "HDKey", {
3847
+ enumerable: true,
3848
+ get: function() {
3849
+ return HDKey;
3850
+ }
3851
+ });