@aptos-labs/ts-sdk 1.14.0-zeta.2 → 1.14.0-zeta.4

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 (429) hide show
  1. package/dist/common/chunk-KSEUZTKY.js +2 -0
  2. package/dist/common/chunk-KSEUZTKY.js.map +1 -0
  3. package/dist/common/cli/index.js +1 -245
  4. package/dist/common/cli/index.js.map +1 -1
  5. package/dist/common/index.js +390 -11802
  6. package/dist/common/index.js.map +1 -1
  7. package/dist/esm/account/Account.mjs +1 -55
  8. package/dist/esm/account/Ed25519Account.mjs +1 -53
  9. package/dist/esm/account/EphemeralKeyPair.mjs +1 -36
  10. package/dist/esm/account/KeylessAccount.mjs +1 -56
  11. package/dist/esm/account/MultiKeyAccount.mjs +1 -55
  12. package/dist/esm/account/SingleKeyAccount.mjs +1 -53
  13. package/dist/esm/account/index.mjs +1 -76
  14. package/dist/esm/api/account.mjs +1 -76
  15. package/dist/esm/api/ans.mjs +1 -87
  16. package/dist/esm/api/aptos.mjs +1 -116
  17. package/dist/esm/api/aptosConfig.mjs +1 -9
  18. package/dist/esm/api/coin.mjs +1 -86
  19. package/dist/esm/api/digitalAsset.mjs +1 -87
  20. package/dist/esm/api/event.mjs +1 -54
  21. package/dist/esm/api/faucet.mjs +1 -53
  22. package/dist/esm/api/fungibleAsset.mjs +1 -87
  23. package/dist/esm/api/general.mjs +1 -84
  24. package/dist/esm/api/index.mjs +1 -120
  25. package/dist/esm/api/keyless.mjs +1 -70
  26. package/dist/esm/api/staking.mjs +1 -54
  27. package/dist/esm/api/transaction.mjs +1 -94
  28. package/dist/esm/api/transactionSubmission/build.mjs +1 -85
  29. package/dist/esm/api/transactionSubmission/helpers.mjs +1 -9
  30. package/dist/esm/api/transactionSubmission/management.mjs +1 -89
  31. package/dist/esm/api/transactionSubmission/sign.mjs +1 -109
  32. package/dist/esm/api/transactionSubmission/sign.mjs.map +1 -1
  33. package/dist/esm/api/transactionSubmission/simulate.mjs +1 -86
  34. package/dist/esm/api/transactionSubmission/submit.mjs +1 -86
  35. package/dist/esm/api/utils.mjs +1 -34
  36. package/dist/esm/bcs/consts.mjs +1 -17
  37. package/dist/esm/bcs/deserializer.mjs +1 -8
  38. package/dist/esm/bcs/index.mjs +1 -57
  39. package/dist/esm/bcs/serializable/entryFunctionBytes.mjs +1 -12
  40. package/dist/esm/bcs/serializable/fixedBytes.mjs +1 -11
  41. package/dist/esm/bcs/serializable/movePrimitives.mjs +1 -25
  42. package/dist/esm/bcs/serializable/moveStructs.mjs +1 -18
  43. package/dist/esm/bcs/serializer.mjs +1 -18
  44. package/dist/esm/chunk-3COVJN6Z.mjs +2 -0
  45. package/dist/esm/{chunk-2JOCR2VL.mjs.map → chunk-3COVJN6Z.mjs.map} +1 -1
  46. package/dist/esm/chunk-3FVRXELT.mjs +2 -0
  47. package/dist/esm/{chunk-KK2BSALW.mjs.map → chunk-3FVRXELT.mjs.map} +1 -1
  48. package/dist/esm/chunk-3JPVQHOR.mjs +2 -0
  49. package/dist/esm/{chunk-GGMTQAQP.mjs.map → chunk-3JPVQHOR.mjs.map} +1 -1
  50. package/dist/esm/chunk-3VGX3TXH.mjs +2 -0
  51. package/dist/esm/{chunk-7FO3S6IZ.mjs.map → chunk-3VGX3TXH.mjs.map} +1 -1
  52. package/dist/esm/chunk-4D5QYFL7.mjs +2 -0
  53. package/dist/esm/{chunk-VZQXLVEP.mjs.map → chunk-4D5QYFL7.mjs.map} +1 -1
  54. package/dist/esm/chunk-4SZSI7QT.mjs +2 -0
  55. package/dist/esm/{chunk-2ZEGJU43.mjs.map → chunk-4SZSI7QT.mjs.map} +1 -1
  56. package/dist/esm/chunk-52ECIIIH.mjs +2 -0
  57. package/dist/esm/{chunk-U3IUCR2G.mjs.map → chunk-52ECIIIH.mjs.map} +1 -1
  58. package/dist/esm/chunk-53T2VRZA.mjs +2 -0
  59. package/dist/esm/{chunk-7IDBB4J4.mjs.map → chunk-53T2VRZA.mjs.map} +1 -1
  60. package/dist/esm/chunk-56CNRT2K.mjs +2 -0
  61. package/dist/esm/{chunk-SBB4YEPT.mjs.map → chunk-56CNRT2K.mjs.map} +1 -1
  62. package/dist/esm/chunk-56NB52W6.mjs +2 -0
  63. package/dist/esm/{chunk-VJP2VWMF.mjs.map → chunk-56NB52W6.mjs.map} +1 -1
  64. package/dist/esm/chunk-5JGWZSNG.mjs +2 -0
  65. package/dist/esm/{chunk-LYK4TQZO.mjs.map → chunk-5JGWZSNG.mjs.map} +1 -1
  66. package/dist/esm/chunk-6EMN3BOV.mjs +2 -0
  67. package/dist/esm/{chunk-SIJELMDP.mjs.map → chunk-6EMN3BOV.mjs.map} +1 -1
  68. package/dist/esm/chunk-6JT3CUFA.mjs +2 -0
  69. package/dist/esm/{chunk-ST4QXIMI.mjs.map → chunk-6JT3CUFA.mjs.map} +1 -1
  70. package/dist/esm/chunk-6KGDQGT2.mjs +2 -0
  71. package/dist/esm/{chunk-GBEVD2VM.mjs.map → chunk-6KGDQGT2.mjs.map} +1 -1
  72. package/dist/esm/chunk-6OETO7Q7.mjs +2 -0
  73. package/dist/esm/{chunk-UX5NSZEN.mjs.map → chunk-6OETO7Q7.mjs.map} +1 -1
  74. package/dist/esm/chunk-6RBUXB5I.mjs +2 -0
  75. package/dist/esm/{chunk-WK5ZSNE2.mjs.map → chunk-6RBUXB5I.mjs.map} +1 -1
  76. package/dist/esm/chunk-6YFCRKVC.mjs +2 -0
  77. package/dist/esm/{chunk-YYOPNUX5.mjs.map → chunk-6YFCRKVC.mjs.map} +1 -1
  78. package/dist/esm/chunk-7STYQ5ZE.mjs +2 -0
  79. package/dist/esm/{chunk-UEBBLQJ5.mjs.map → chunk-7STYQ5ZE.mjs.map} +1 -1
  80. package/dist/esm/chunk-7WJTKYRG.mjs +2 -0
  81. package/dist/esm/{chunk-2OQW7BMN.mjs.map → chunk-7WJTKYRG.mjs.map} +1 -1
  82. package/dist/esm/chunk-AFGTRMOR.mjs +2 -0
  83. package/dist/esm/{chunk-KMXSRHJ6.mjs.map → chunk-AFGTRMOR.mjs.map} +1 -1
  84. package/dist/esm/chunk-AH44UPM4.mjs +2 -0
  85. package/dist/esm/{chunk-EYHRMZPO.mjs.map → chunk-AH44UPM4.mjs.map} +1 -1
  86. package/dist/esm/chunk-AOCNYMMX.mjs +2 -0
  87. package/dist/esm/{chunk-YV7M4CFP.mjs.map → chunk-AOCNYMMX.mjs.map} +1 -1
  88. package/dist/esm/chunk-B3BLP5DP.mjs +2 -0
  89. package/dist/esm/{chunk-W76MGKZB.mjs.map → chunk-B3BLP5DP.mjs.map} +1 -1
  90. package/dist/esm/chunk-BTTXZYBD.mjs +2 -0
  91. package/dist/esm/{chunk-LI2QV6RU.mjs.map → chunk-BTTXZYBD.mjs.map} +1 -1
  92. package/dist/esm/chunk-C34M4T77.mjs +2 -0
  93. package/dist/esm/{chunk-UKU6A2W2.mjs.map → chunk-C34M4T77.mjs.map} +1 -1
  94. package/dist/esm/chunk-C3L4ETUF.mjs +2 -0
  95. package/dist/esm/{chunk-PIMQHG2J.mjs.map → chunk-C3L4ETUF.mjs.map} +1 -1
  96. package/dist/esm/chunk-CO53EOHE.mjs +2 -0
  97. package/dist/esm/{chunk-MZZLEY6O.mjs.map → chunk-CO53EOHE.mjs.map} +1 -1
  98. package/dist/esm/chunk-COW5IGYC.mjs +2 -0
  99. package/dist/esm/{chunk-FXKSE3ZP.mjs.map → chunk-COW5IGYC.mjs.map} +1 -1
  100. package/dist/esm/chunk-CPBGL37X.mjs +2 -0
  101. package/dist/esm/{chunk-D2BVBXWO.mjs.map → chunk-CPBGL37X.mjs.map} +1 -1
  102. package/dist/esm/chunk-CSP3V4UZ.mjs +2 -0
  103. package/dist/esm/{chunk-DGV7DYU4.mjs.map → chunk-CSP3V4UZ.mjs.map} +1 -1
  104. package/dist/esm/chunk-D4J3MCOI.mjs +2 -0
  105. package/dist/esm/{chunk-JV3GSIJW.mjs.map → chunk-D4J3MCOI.mjs.map} +1 -1
  106. package/dist/esm/chunk-EB7AI4B4.mjs +2 -0
  107. package/dist/esm/{chunk-AR7X6GWQ.mjs.map → chunk-EB7AI4B4.mjs.map} +1 -1
  108. package/dist/esm/chunk-EIXCAYQM.mjs +2 -0
  109. package/dist/esm/{chunk-O6PSHSN3.mjs.map → chunk-EIXCAYQM.mjs.map} +1 -1
  110. package/dist/esm/chunk-F3HH6U3Z.mjs +2 -0
  111. package/dist/esm/{chunk-IC56GQFJ.mjs.map → chunk-F3HH6U3Z.mjs.map} +1 -1
  112. package/dist/esm/chunk-FBPNHF54.mjs +2 -0
  113. package/dist/esm/{chunk-QMM2KL6C.mjs.map → chunk-FBPNHF54.mjs.map} +1 -1
  114. package/dist/esm/chunk-FHNW3DEN.mjs +2 -0
  115. package/dist/esm/{chunk-ATVFVXR6.mjs.map → chunk-FHNW3DEN.mjs.map} +1 -1
  116. package/dist/esm/chunk-FLYEALDB.mjs +2 -0
  117. package/dist/esm/{chunk-76TSTAU4.mjs.map → chunk-FLYEALDB.mjs.map} +1 -1
  118. package/dist/esm/chunk-FMBZNFEA.mjs +2 -0
  119. package/dist/esm/{chunk-ZAHJ7KXB.mjs.map → chunk-FMBZNFEA.mjs.map} +1 -1
  120. package/dist/esm/chunk-FVA2OPG4.mjs +2 -0
  121. package/dist/esm/chunk-GUO5GDBN.mjs +2 -0
  122. package/dist/esm/{chunk-HBNSRCZN.mjs.map → chunk-GUO5GDBN.mjs.map} +1 -1
  123. package/dist/esm/chunk-HGZGTBA4.mjs +2 -0
  124. package/dist/esm/{chunk-PYLOAMR2.mjs.map → chunk-HGZGTBA4.mjs.map} +1 -1
  125. package/dist/esm/chunk-HX5246EM.mjs +2 -0
  126. package/dist/esm/{chunk-JHDHNGJ3.mjs.map → chunk-HX5246EM.mjs.map} +1 -1
  127. package/dist/esm/chunk-HY5E66FY.mjs +2 -0
  128. package/dist/esm/{chunk-7FUHWL6A.mjs.map → chunk-HY5E66FY.mjs.map} +1 -1
  129. package/dist/esm/chunk-IBQWYF23.mjs +2 -0
  130. package/dist/esm/{chunk-WDRH2URB.mjs.map → chunk-IBQWYF23.mjs.map} +1 -1
  131. package/dist/esm/chunk-IWBLSSVA.mjs +2 -0
  132. package/dist/esm/{chunk-TBHU6ZW6.mjs.map → chunk-IWBLSSVA.mjs.map} +1 -1
  133. package/dist/esm/chunk-JJIANJE3.mjs +2 -0
  134. package/dist/esm/{chunk-GSVQ6EUD.mjs.map → chunk-JJIANJE3.mjs.map} +1 -1
  135. package/dist/esm/chunk-JM2B5E2I.mjs +2 -0
  136. package/dist/esm/{chunk-CX3NAVRD.mjs.map → chunk-JM2B5E2I.mjs.map} +1 -1
  137. package/dist/esm/chunk-JM544NRW.mjs +2 -0
  138. package/dist/esm/{chunk-7REUIYF4.mjs.map → chunk-JM544NRW.mjs.map} +1 -1
  139. package/dist/esm/chunk-JYUTX5G7.mjs +2 -0
  140. package/dist/esm/{chunk-LYMY63SO.mjs.map → chunk-JYUTX5G7.mjs.map} +1 -1
  141. package/dist/esm/chunk-K247GPES.mjs +2 -0
  142. package/dist/esm/{chunk-NYL77J4X.mjs.map → chunk-K247GPES.mjs.map} +1 -1
  143. package/dist/esm/chunk-KW2KIYJE.mjs +2 -0
  144. package/dist/esm/{chunk-BXMHDQHW.mjs.map → chunk-KW2KIYJE.mjs.map} +1 -1
  145. package/dist/esm/chunk-KYZCH7IK.mjs +2 -0
  146. package/dist/esm/{chunk-NXFO2W4G.mjs.map → chunk-KYZCH7IK.mjs.map} +1 -1
  147. package/dist/esm/chunk-L54P6EGN.mjs +2 -0
  148. package/dist/esm/{chunk-SS3NUM5L.mjs.map → chunk-L54P6EGN.mjs.map} +1 -1
  149. package/dist/esm/chunk-LDQ6JFEF.mjs +2 -0
  150. package/dist/esm/{chunk-N4WKFNQ6.mjs.map → chunk-LDQ6JFEF.mjs.map} +1 -1
  151. package/dist/esm/chunk-LR5YOJG2.mjs +2 -0
  152. package/dist/esm/{chunk-6LRQSBRH.mjs.map → chunk-LR5YOJG2.mjs.map} +1 -1
  153. package/dist/esm/chunk-LR65XHSF.mjs +2 -0
  154. package/dist/esm/{chunk-PU5AFUX3.mjs.map → chunk-LR65XHSF.mjs.map} +1 -1
  155. package/dist/esm/chunk-MC6O2XME.mjs +2 -0
  156. package/dist/esm/{chunk-RCQMWXEW.mjs.map → chunk-MC6O2XME.mjs.map} +1 -1
  157. package/dist/esm/chunk-MGOHPDX4.mjs +2 -0
  158. package/dist/esm/{chunk-2TJJWII2.mjs.map → chunk-MGOHPDX4.mjs.map} +1 -1
  159. package/dist/esm/chunk-MTLETLKV.mjs +2 -0
  160. package/dist/esm/{chunk-DIYZRGR6.mjs.map → chunk-MTLETLKV.mjs.map} +1 -1
  161. package/dist/esm/chunk-MWUJCP27.mjs +2 -0
  162. package/dist/esm/{chunk-6MSZMIFW.mjs.map → chunk-MWUJCP27.mjs.map} +1 -1
  163. package/dist/esm/chunk-N466X3S6.mjs +2 -0
  164. package/dist/esm/{chunk-WLTBF4DF.mjs.map → chunk-N466X3S6.mjs.map} +1 -1
  165. package/dist/esm/chunk-NC5HHEEM.mjs +2 -0
  166. package/dist/esm/{chunk-XANFAUBD.mjs.map → chunk-NC5HHEEM.mjs.map} +1 -1
  167. package/dist/esm/chunk-NNIHTVLA.mjs +2 -0
  168. package/dist/esm/{chunk-VPWUODU4.mjs.map → chunk-NNIHTVLA.mjs.map} +1 -1
  169. package/dist/esm/chunk-NT47KB7Y.mjs +2 -0
  170. package/dist/esm/{chunk-Y2LV3S5W.mjs.map → chunk-NT47KB7Y.mjs.map} +1 -1
  171. package/dist/esm/chunk-NWGBV3YO.mjs +2 -0
  172. package/dist/esm/{chunk-F2ZWA7B7.mjs.map → chunk-NWGBV3YO.mjs.map} +1 -1
  173. package/dist/esm/chunk-NWWXZ7EW.mjs +2 -0
  174. package/dist/esm/{chunk-B5S6DDUD.mjs.map → chunk-NWWXZ7EW.mjs.map} +1 -1
  175. package/dist/esm/chunk-NYTZPISE.mjs +2 -0
  176. package/dist/esm/{chunk-KVSQ57HU.mjs.map → chunk-NYTZPISE.mjs.map} +1 -1
  177. package/dist/esm/chunk-O6LITRY2.mjs +2 -0
  178. package/dist/esm/{chunk-CTJSZT5V.mjs.map → chunk-O6LITRY2.mjs.map} +1 -1
  179. package/dist/esm/chunk-OJFMOV2O.mjs +2 -0
  180. package/dist/esm/{chunk-TLNHRJB2.mjs.map → chunk-OJFMOV2O.mjs.map} +1 -1
  181. package/dist/esm/chunk-OMD4G3E6.mjs +2 -0
  182. package/dist/esm/{chunk-FF4JPDKD.mjs.map → chunk-OMD4G3E6.mjs.map} +1 -1
  183. package/dist/esm/chunk-PBDEW4TN.mjs +2 -0
  184. package/dist/esm/{chunk-IHNPN5CQ.mjs.map → chunk-PBDEW4TN.mjs.map} +1 -1
  185. package/dist/esm/chunk-PFFAQZHT.mjs +2 -0
  186. package/dist/esm/{chunk-DNPMS2OF.mjs.map → chunk-PFFAQZHT.mjs.map} +1 -1
  187. package/dist/esm/chunk-PTRUUJCS.mjs +2 -0
  188. package/dist/esm/{chunk-LLLQJWRZ.mjs.map → chunk-PTRUUJCS.mjs.map} +1 -1
  189. package/dist/esm/chunk-PYUU4OEL.mjs +2 -0
  190. package/dist/esm/{chunk-RX4VG2AT.mjs.map → chunk-PYUU4OEL.mjs.map} +1 -1
  191. package/dist/esm/chunk-QDJN5HCB.mjs +2 -0
  192. package/dist/esm/{chunk-CC4DQ6NH.mjs.map → chunk-QDJN5HCB.mjs.map} +1 -1
  193. package/dist/esm/chunk-QFMUMZXR.mjs +2 -0
  194. package/dist/esm/{chunk-ASF2VWOX.mjs.map → chunk-QFMUMZXR.mjs.map} +1 -1
  195. package/dist/esm/chunk-RJ4PSGZ4.mjs +2 -0
  196. package/dist/esm/{chunk-QFOG4LIN.mjs.map → chunk-RJ4PSGZ4.mjs.map} +1 -1
  197. package/dist/esm/chunk-RKHPXZM6.mjs +2 -0
  198. package/dist/esm/{chunk-PCLNX6FS.mjs.map → chunk-RKHPXZM6.mjs.map} +1 -1
  199. package/dist/esm/{chunk-4PJ5FYGQ.mjs → chunk-S4SEFF4K.mjs} +27 -302
  200. package/dist/esm/{chunk-4PJ5FYGQ.mjs.map → chunk-S4SEFF4K.mjs.map} +1 -1
  201. package/dist/esm/chunk-S4YEK4LM.mjs +2 -0
  202. package/dist/esm/{chunk-WVGO4D7K.mjs.map → chunk-S4YEK4LM.mjs.map} +1 -1
  203. package/dist/esm/chunk-STYDBDYL.mjs +2 -0
  204. package/dist/esm/{chunk-FDWJNY4U.mjs.map → chunk-STYDBDYL.mjs.map} +1 -1
  205. package/dist/esm/chunk-SXOQWGMT.mjs +2 -0
  206. package/dist/esm/{chunk-VDJBDX3A.mjs.map → chunk-SXOQWGMT.mjs.map} +1 -1
  207. package/dist/esm/chunk-T23OVRNF.mjs +2 -0
  208. package/dist/esm/{chunk-CMNJG4NN.mjs.map → chunk-T23OVRNF.mjs.map} +1 -1
  209. package/dist/esm/chunk-TBGRYIFW.mjs +2 -0
  210. package/dist/esm/{chunk-NW45SCPY.mjs.map → chunk-TBGRYIFW.mjs.map} +1 -1
  211. package/dist/esm/chunk-TICM455H.mjs +2 -0
  212. package/dist/esm/{chunk-ZMFKQUHL.mjs.map → chunk-TICM455H.mjs.map} +1 -1
  213. package/dist/esm/chunk-TJDC5PWD.mjs +2 -0
  214. package/dist/esm/{chunk-NMKCJNQM.mjs.map → chunk-TJDC5PWD.mjs.map} +1 -1
  215. package/dist/esm/chunk-TVRJ3M7B.mjs +2 -0
  216. package/dist/esm/{chunk-FQQW55X7.mjs.map → chunk-TVRJ3M7B.mjs.map} +1 -1
  217. package/dist/esm/chunk-U6Z4FNB7.mjs +2 -0
  218. package/dist/esm/{chunk-AC3OGAL6.mjs.map → chunk-U6Z4FNB7.mjs.map} +1 -1
  219. package/dist/esm/chunk-UAL7TX7O.mjs +2 -0
  220. package/dist/esm/{chunk-DVPQGCFT.mjs.map → chunk-UAL7TX7O.mjs.map} +1 -1
  221. package/dist/esm/chunk-UTXJOB3O.mjs +2 -0
  222. package/dist/esm/{chunk-QBBTUC66.mjs.map → chunk-UTXJOB3O.mjs.map} +1 -1
  223. package/dist/esm/chunk-VDMVO4R4.mjs +2 -0
  224. package/dist/esm/{chunk-4OYYOYSO.mjs.map → chunk-VDMVO4R4.mjs.map} +1 -1
  225. package/dist/esm/chunk-VT6XJSRO.mjs +2 -0
  226. package/dist/esm/{chunk-7JRMOHBP.mjs.map → chunk-VT6XJSRO.mjs.map} +1 -1
  227. package/dist/esm/chunk-VXZDDYG7.mjs +2 -0
  228. package/dist/esm/{chunk-55NODGHC.mjs.map → chunk-VXZDDYG7.mjs.map} +1 -1
  229. package/dist/esm/chunk-WOPMZAWX.mjs +2 -0
  230. package/dist/esm/{chunk-VKJQORON.mjs.map → chunk-WOPMZAWX.mjs.map} +1 -1
  231. package/dist/esm/chunk-XOTF6PQ7.mjs +2 -0
  232. package/dist/esm/{chunk-CXUGZXED.mjs.map → chunk-XOTF6PQ7.mjs.map} +1 -1
  233. package/dist/esm/chunk-YE5B2S5L.mjs +2 -0
  234. package/dist/esm/{chunk-NFJCQRVK.mjs.map → chunk-YE5B2S5L.mjs.map} +1 -1
  235. package/dist/esm/chunk-ZJDNONEP.mjs +2 -0
  236. package/dist/esm/{chunk-U7QBZ6PP.mjs.map → chunk-ZJDNONEP.mjs.map} +1 -1
  237. package/dist/esm/chunk-ZLLU4XK7.mjs +2 -0
  238. package/dist/esm/{chunk-WHBWEN6N.mjs.map → chunk-ZLLU4XK7.mjs.map} +1 -1
  239. package/dist/esm/chunk-ZNEBMSNC.mjs +2 -0
  240. package/dist/esm/{chunk-JL2JHVS4.mjs.map → chunk-ZNEBMSNC.mjs.map} +1 -1
  241. package/dist/esm/cli/index.mjs +1 -12
  242. package/dist/esm/cli/localNode.mjs +1 -8
  243. package/dist/esm/cli/move.mjs +1 -7
  244. package/dist/esm/client/core.mjs +1 -27
  245. package/dist/esm/client/get.mjs +1 -32
  246. package/dist/esm/client/index.mjs +1 -55
  247. package/dist/esm/client/post.mjs +1 -36
  248. package/dist/esm/client/types.mjs +1 -7
  249. package/dist/esm/core/account/index.mjs +1 -19
  250. package/dist/esm/core/account/utils/address.mjs +1 -18
  251. package/dist/esm/core/account/utils/index.mjs +1 -19
  252. package/dist/esm/core/accountAddress.mjs +1 -15
  253. package/dist/esm/core/authenticationKey.mjs +1 -14
  254. package/dist/esm/core/common.mjs +1 -7
  255. package/dist/esm/core/crypto/ed25519.mjs +1 -29
  256. package/dist/esm/core/crypto/ephemeral.mjs +1 -28
  257. package/dist/esm/core/crypto/hdKey.mjs +1 -25
  258. package/dist/esm/core/crypto/index.mjs +1 -124
  259. package/dist/esm/core/crypto/keyless.mjs +1 -55
  260. package/dist/esm/core/crypto/multiEd25519.mjs +1 -28
  261. package/dist/esm/core/crypto/multiKey.mjs +1 -34
  262. package/dist/esm/core/crypto/poseidon.mjs +1 -15
  263. package/dist/esm/core/crypto/privateKey.mjs +1 -1
  264. package/dist/esm/core/crypto/proof.mjs +1 -19
  265. package/dist/esm/core/crypto/publicKey.mjs +1 -21
  266. package/dist/esm/core/crypto/secp256k1.mjs +1 -27
  267. package/dist/esm/core/crypto/signature.mjs +1 -19
  268. package/dist/esm/core/crypto/singleKey.mjs +1 -33
  269. package/dist/esm/core/crypto/utils.mjs +1 -9
  270. package/dist/esm/core/hex.mjs +1 -10
  271. package/dist/esm/core/index.mjs +1 -141
  272. package/dist/esm/index.mjs +1 -635
  273. package/dist/esm/internal/account.mjs +1 -106
  274. package/dist/esm/internal/ans.mjs +1 -120
  275. package/dist/esm/internal/coin.mjs +1 -85
  276. package/dist/esm/internal/digitalAsset.mjs +1 -127
  277. package/dist/esm/internal/event.mjs +1 -55
  278. package/dist/esm/internal/faucet.mjs +1 -52
  279. package/dist/esm/internal/fungibleAsset.mjs +1 -91
  280. package/dist/esm/internal/general.mjs +1 -46
  281. package/dist/esm/internal/keyless.mjs +1 -73
  282. package/dist/esm/internal/staking.mjs +1 -53
  283. package/dist/esm/internal/transaction.mjs +1 -51
  284. package/dist/esm/internal/transactionSubmission.mjs +1 -102
  285. package/dist/esm/internal/view.mjs +1 -83
  286. package/dist/esm/transactions/authenticator/account.mjs +1 -44
  287. package/dist/esm/transactions/authenticator/index.mjs +1 -60
  288. package/dist/esm/transactions/authenticator/transaction.mjs +1 -48
  289. package/dist/esm/transactions/index.mjs +1 -284
  290. package/dist/esm/transactions/instances/chainId.mjs +1 -11
  291. package/dist/esm/transactions/instances/identifier.mjs +1 -11
  292. package/dist/esm/transactions/instances/index.mjs +1 -96
  293. package/dist/esm/transactions/instances/moduleId.mjs +1 -38
  294. package/dist/esm/transactions/instances/multiAgentTransaction.mjs +1 -43
  295. package/dist/esm/transactions/instances/rawTransaction.mjs +1 -48
  296. package/dist/esm/transactions/instances/rotationProofChallenge.mjs +1 -20
  297. package/dist/esm/transactions/instances/signedTransaction.mjs +1 -45
  298. package/dist/esm/transactions/instances/simpleTransaction.mjs +1 -43
  299. package/dist/esm/transactions/instances/transactionArgument.mjs +1 -1
  300. package/dist/esm/transactions/instances/transactionPayload.mjs +1 -56
  301. package/dist/esm/transactions/management/accountSequenceNumber.mjs +1 -74
  302. package/dist/esm/transactions/management/asyncQueue.mjs +1 -9
  303. package/dist/esm/transactions/management/index.mjs +1 -95
  304. package/dist/esm/transactions/management/transactionWorker.mjs +1 -91
  305. package/dist/esm/transactions/transactionBuilder/helpers.mjs +1 -75
  306. package/dist/esm/transactions/transactionBuilder/index.mjs +1 -162
  307. package/dist/esm/transactions/transactionBuilder/remoteAbi.mjs +1 -85
  308. package/dist/esm/transactions/transactionBuilder/signingMessage.mjs +1 -58
  309. package/dist/esm/transactions/transactionBuilder/transactionBuilder.mjs +1 -98
  310. package/dist/esm/transactions/typeTag/index.mjs +1 -74
  311. package/dist/esm/transactions/typeTag/parser.mjs +1 -43
  312. package/dist/esm/transactions/types.mjs +1 -1
  313. package/dist/esm/types/generated/queries.mjs +1 -57
  314. package/dist/esm/types/generated/types.mjs +1 -809
  315. package/dist/esm/types/generated/types.mjs.map +1 -1
  316. package/dist/esm/types/index.mjs +1 -68
  317. package/dist/esm/types/indexer.mjs +1 -1
  318. package/dist/esm/types/keyless.mjs +1 -9
  319. package/dist/esm/utils/apiEndpoints.mjs +1 -21
  320. package/dist/esm/utils/const.mjs +1 -21
  321. package/dist/esm/utils/helpers.mjs +1 -7
  322. package/dist/esm/utils/index.mjs +1 -56
  323. package/dist/esm/utils/memoize.mjs +1 -9
  324. package/dist/esm/utils/normalizeBundle.mjs +1 -19
  325. package/dist/esm/version.d.mts +1 -1
  326. package/dist/esm/version.mjs +1 -7
  327. package/package.json +1 -1
  328. package/src/version.ts +1 -1
  329. package/dist/common/chunk-QRI7EC4T.js +0 -24
  330. package/dist/common/chunk-QRI7EC4T.js.map +0 -1
  331. package/dist/esm/chunk-2JOCR2VL.mjs +0 -32
  332. package/dist/esm/chunk-2OQW7BMN.mjs +0 -129
  333. package/dist/esm/chunk-2TJJWII2.mjs +0 -23
  334. package/dist/esm/chunk-2ZEGJU43.mjs +0 -252
  335. package/dist/esm/chunk-4OYYOYSO.mjs +0 -336
  336. package/dist/esm/chunk-55NODGHC.mjs +0 -135
  337. package/dist/esm/chunk-6LRQSBRH.mjs +0 -130
  338. package/dist/esm/chunk-6MSZMIFW.mjs +0 -23
  339. package/dist/esm/chunk-76TSTAU4.mjs +0 -120
  340. package/dist/esm/chunk-7FO3S6IZ.mjs +0 -324
  341. package/dist/esm/chunk-7FUHWL6A.mjs +0 -42
  342. package/dist/esm/chunk-7IDBB4J4.mjs +0 -33
  343. package/dist/esm/chunk-7JRMOHBP.mjs +0 -247
  344. package/dist/esm/chunk-7REUIYF4.mjs +0 -63
  345. package/dist/esm/chunk-AC3OGAL6.mjs +0 -87
  346. package/dist/esm/chunk-AR7X6GWQ.mjs +0 -356
  347. package/dist/esm/chunk-ASF2VWOX.mjs +0 -142
  348. package/dist/esm/chunk-ATVFVXR6.mjs +0 -43
  349. package/dist/esm/chunk-B5S6DDUD.mjs +0 -120
  350. package/dist/esm/chunk-BXMHDQHW.mjs +0 -512
  351. package/dist/esm/chunk-CC4DQ6NH.mjs +0 -19
  352. package/dist/esm/chunk-CMNJG4NN.mjs +0 -345
  353. package/dist/esm/chunk-CTJSZT5V.mjs +0 -87
  354. package/dist/esm/chunk-CX3NAVRD.mjs +0 -205
  355. package/dist/esm/chunk-CXUGZXED.mjs +0 -307
  356. package/dist/esm/chunk-D2BVBXWO.mjs +0 -7
  357. package/dist/esm/chunk-DGV7DYU4.mjs +0 -413
  358. package/dist/esm/chunk-DIYZRGR6.mjs +0 -242
  359. package/dist/esm/chunk-DNPMS2OF.mjs +0 -236
  360. package/dist/esm/chunk-DVPQGCFT.mjs +0 -74
  361. package/dist/esm/chunk-EYHRMZPO.mjs +0 -34
  362. package/dist/esm/chunk-F2ZWA7B7.mjs +0 -412
  363. package/dist/esm/chunk-FDWJNY4U.mjs +0 -22
  364. package/dist/esm/chunk-FF4JPDKD.mjs +0 -315
  365. package/dist/esm/chunk-FQQW55X7.mjs +0 -288
  366. package/dist/esm/chunk-FXKSE3ZP.mjs +0 -25
  367. package/dist/esm/chunk-GBEVD2VM.mjs +0 -99
  368. package/dist/esm/chunk-GGMTQAQP.mjs +0 -11
  369. package/dist/esm/chunk-GSVQ6EUD.mjs +0 -649
  370. package/dist/esm/chunk-HBNSRCZN.mjs +0 -100
  371. package/dist/esm/chunk-IC56GQFJ.mjs +0 -127
  372. package/dist/esm/chunk-IHNPN5CQ.mjs +0 -256
  373. package/dist/esm/chunk-JHDHNGJ3.mjs +0 -126
  374. package/dist/esm/chunk-JL2JHVS4.mjs +0 -49
  375. package/dist/esm/chunk-JV3GSIJW.mjs +0 -268
  376. package/dist/esm/chunk-KK2BSALW.mjs +0 -32
  377. package/dist/esm/chunk-KMXSRHJ6.mjs +0 -93
  378. package/dist/esm/chunk-KVSQ57HU.mjs +0 -45
  379. package/dist/esm/chunk-LI2QV6RU.mjs +0 -129
  380. package/dist/esm/chunk-LLLQJWRZ.mjs +0 -35
  381. package/dist/esm/chunk-LYK4TQZO.mjs +0 -70
  382. package/dist/esm/chunk-LYMY63SO.mjs +0 -124
  383. package/dist/esm/chunk-MZZLEY6O.mjs +0 -92
  384. package/dist/esm/chunk-N4WKFNQ6.mjs +0 -156
  385. package/dist/esm/chunk-NFJCQRVK.mjs +0 -37
  386. package/dist/esm/chunk-NMKCJNQM.mjs +0 -20
  387. package/dist/esm/chunk-NW45SCPY.mjs +0 -36
  388. package/dist/esm/chunk-NXFO2W4G.mjs +0 -84
  389. package/dist/esm/chunk-NYL77J4X.mjs +0 -97
  390. package/dist/esm/chunk-O6PSHSN3.mjs +0 -53
  391. package/dist/esm/chunk-OR7TEZ25.mjs +0 -16
  392. package/dist/esm/chunk-PCLNX6FS.mjs +0 -17
  393. package/dist/esm/chunk-PIMQHG2J.mjs +0 -49
  394. package/dist/esm/chunk-PU5AFUX3.mjs +0 -52
  395. package/dist/esm/chunk-PYLOAMR2.mjs +0 -29
  396. package/dist/esm/chunk-QBBTUC66.mjs +0 -15
  397. package/dist/esm/chunk-QFOG4LIN.mjs +0 -319
  398. package/dist/esm/chunk-QMM2KL6C.mjs +0 -12
  399. package/dist/esm/chunk-RCQMWXEW.mjs +0 -35
  400. package/dist/esm/chunk-RX4VG2AT.mjs +0 -314
  401. package/dist/esm/chunk-SBB4YEPT.mjs +0 -17
  402. package/dist/esm/chunk-SIJELMDP.mjs +0 -29
  403. package/dist/esm/chunk-SS3NUM5L.mjs +0 -94
  404. package/dist/esm/chunk-ST4QXIMI.mjs +0 -37
  405. package/dist/esm/chunk-TBHU6ZW6.mjs +0 -215
  406. package/dist/esm/chunk-TLNHRJB2.mjs +0 -155
  407. package/dist/esm/chunk-U3IUCR2G.mjs +0 -54
  408. package/dist/esm/chunk-U7QBZ6PP.mjs +0 -400
  409. package/dist/esm/chunk-UEBBLQJ5.mjs +0 -94
  410. package/dist/esm/chunk-UKU6A2W2.mjs +0 -232
  411. package/dist/esm/chunk-UX5NSZEN.mjs +0 -134
  412. package/dist/esm/chunk-VDJBDX3A.mjs +0 -79
  413. package/dist/esm/chunk-VJP2VWMF.mjs +0 -58
  414. package/dist/esm/chunk-VKJQORON.mjs +0 -93
  415. package/dist/esm/chunk-VPWUODU4.mjs +0 -51
  416. package/dist/esm/chunk-VZQXLVEP.mjs +0 -197
  417. package/dist/esm/chunk-W76MGKZB.mjs +0 -33
  418. package/dist/esm/chunk-WDRH2URB.mjs +0 -91
  419. package/dist/esm/chunk-WHBWEN6N.mjs +0 -206
  420. package/dist/esm/chunk-WK5ZSNE2.mjs +0 -173
  421. package/dist/esm/chunk-WLTBF4DF.mjs +0 -22
  422. package/dist/esm/chunk-WVGO4D7K.mjs +0 -254
  423. package/dist/esm/chunk-XANFAUBD.mjs +0 -44
  424. package/dist/esm/chunk-Y2LV3S5W.mjs +0 -410
  425. package/dist/esm/chunk-YV7M4CFP.mjs +0 -137
  426. package/dist/esm/chunk-YYOPNUX5.mjs +0 -41
  427. package/dist/esm/chunk-ZAHJ7KXB.mjs +0 -81
  428. package/dist/esm/chunk-ZMFKQUHL.mjs +0 -117
  429. /package/dist/esm/{chunk-OR7TEZ25.mjs.map → chunk-FVA2OPG4.mjs.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/transactions/management/transactionWorker.ts"],"sourcesContent":["/* eslint-disable no-await-in-loop */\n\nimport EventEmitter from \"eventemitter3\";\nimport { AptosConfig } from \"../../api/aptosConfig\";\nimport { Account } from \"../../account\";\nimport { waitForTransaction } from \"../../internal/transaction\";\nimport { generateTransaction, signAndSubmitTransaction } from \"../../internal/transactionSubmission\";\nimport { PendingTransactionResponse, TransactionResponse } from \"../../types\";\nimport { InputGenerateTransactionOptions, InputGenerateTransactionPayloadData } from \"../types\";\nimport { AccountSequenceNumber } from \"./accountSequenceNumber\";\nimport { AsyncQueue, AsyncQueueCancelledError } from \"./asyncQueue\";\nimport { SimpleTransaction } from \"../instances/simpleTransaction\";\n\nexport const promiseFulfilledStatus = \"fulfilled\";\n\n// Event types the worker fires during execution and\n// the dapp can listen to\nexport enum TransactionWorkerEventsEnum {\n // fired after a transaction gets sent to the chain\n TransactionSent = \"transactionSent\",\n // fired if there is an error sending the transaction to the chain\n TransactionSendFailed = \"transactionSendFailed\",\n // fired when a single transaction has executed successfully\n TransactionExecuted = \"transactionExecuted\",\n // fired if a single transaction fails in execution\n TransactionExecutionFailed = \"transactionExecutionFailed\",\n // fired when the worker has finished its job / when the queue has been emptied\n ExecutionFinish = \"executionFinish\",\n}\n\n// Typed interface of the worker events\nexport interface TransactionWorkerEvents {\n transactionSent: (data: SuccessEventData) => void;\n transactionSendFailed: (data: FailureEventData) => void;\n transactionExecuted: (data: SuccessEventData) => void;\n transactionExecutionFailed: (data: FailureEventData) => void;\n executionFinish: (data: ExecutionFinishEventData) => void;\n}\n\n// Type for when the worker has finished its job\nexport type ExecutionFinishEventData = {\n message: string;\n};\n\n// Type for a success event\nexport type SuccessEventData = {\n message: string;\n transactionHash: string;\n};\n\n// Type for a failure event\nexport type FailureEventData = {\n message: string;\n error: string;\n};\n\n/**\n * TransactionWorker provides a simple framework for receiving payloads to be processed.\n *\n * Once one `start()` the process and pushes a new transaction, the worker acquires\n * the current account's next sequence number (by using the AccountSequenceNumber class),\n * generates a signed transaction and pushes an async submission process into the `outstandingTransactions` queue.\n * At the same time, the worker processes transactions by reading the `outstandingTransactions` queue\n * and submits the next transaction to chain, it\n * 1) waits for resolution of the submission process or get pre-execution validation error\n * and 2) waits for the resolution of the execution process or get an execution error.\n * The worker fires events for any submission and/or execution success and/or failure.\n */\nexport class TransactionWorker extends EventEmitter<TransactionWorkerEvents> {\n readonly aptosConfig: AptosConfig;\n\n readonly account: Account;\n\n // current account sequence number\n readonly accountSequnceNumber: AccountSequenceNumber;\n\n readonly taskQueue: AsyncQueue<() => Promise<void>> = new AsyncQueue<() => Promise<void>>();\n\n // process has started\n started: boolean;\n\n /**\n * transactions payloads waiting to be generated and signed\n *\n * TODO support entry function payload from ABI builder\n */\n transactionsQueue = new AsyncQueue<\n [InputGenerateTransactionPayloadData, InputGenerateTransactionOptions | undefined]\n >();\n\n /**\n * signed transactions waiting to be submitted\n */\n outstandingTransactions = new AsyncQueue<[Promise<PendingTransactionResponse>, bigint]>();\n\n /**\n * transactions that have been submitted to chain\n */\n sentTransactions: Array<[string, bigint, any]> = [];\n\n /**\n * transactions that have been committed to chain\n */\n executedTransactions: Array<[string, bigint, any]> = [];\n\n /**\n * Provides a simple framework for receiving payloads to be processed.\n *\n * @param aptosConfig - a config object\n * @param sender - a sender as Account\n * @param maxWaitTime - the max wait time to wait before resyncing the sequence number\n * to the current on-chain state, default to 30\n * @param maximumInFlight - submit up to `maximumInFlight` transactions per account.\n * Mempool limits the number of transactions per account to 100, hence why we default to 100.\n * @param sleepTime - If `maximumInFlight` are in flight, wait `sleepTime` seconds before re-evaluating, default to 10\n */\n constructor(\n aptosConfig: AptosConfig,\n account: Account,\n maxWaitTime: number = 30,\n maximumInFlight: number = 100,\n sleepTime: number = 10,\n ) {\n super();\n this.aptosConfig = aptosConfig;\n this.account = account;\n this.started = false;\n this.accountSequnceNumber = new AccountSequenceNumber(\n aptosConfig,\n account,\n maxWaitTime,\n maximumInFlight,\n sleepTime,\n );\n }\n\n /**\n * Gets the current account sequence number,\n * generates the transaction with the account sequence number,\n * adds the transaction to the outstanding transaction queue\n * to be processed later.\n */\n async submitNextTransaction() {\n try {\n /* eslint-disable no-constant-condition */\n while (true) {\n const sequenceNumber = await this.accountSequnceNumber.nextSequenceNumber();\n if (sequenceNumber === null) return;\n const transaction = await this.generateNextTransaction(this.account, sequenceNumber);\n if (!transaction) return;\n const pendingTransaction = signAndSubmitTransaction({\n aptosConfig: this.aptosConfig,\n transaction,\n signer: this.account,\n });\n await this.outstandingTransactions.enqueue([pendingTransaction, sequenceNumber]);\n }\n } catch (error: any) {\n if (error instanceof AsyncQueueCancelledError) {\n return;\n }\n throw new Error(`Submit transaction failed for ${this.account.accountAddress.toString()} with error ${error}`);\n }\n }\n\n /**\n * Reads the outstanding transaction queue and submits the transaction to chain.\n *\n * If the transaction has fulfilled, it pushes the transaction to the processed\n * transactions queue and fires a transactionsFulfilled event.\n *\n * If the transaction has failed, it pushes the transaction to the processed\n * transactions queue with the failure reason and fires a transactionsFailed event.\n */\n async processTransactions() {\n try {\n /* eslint-disable no-constant-condition */\n while (true) {\n const awaitingTransactions = [];\n const sequenceNumbers = [];\n let [pendingTransaction, sequenceNumber] = await this.outstandingTransactions.dequeue();\n\n awaitingTransactions.push(pendingTransaction);\n sequenceNumbers.push(sequenceNumber);\n\n while (!this.outstandingTransactions.isEmpty()) {\n [pendingTransaction, sequenceNumber] = await this.outstandingTransactions.dequeue();\n\n awaitingTransactions.push(pendingTransaction);\n sequenceNumbers.push(sequenceNumber);\n }\n // send awaiting transactions to chain\n const sentTransactions = await Promise.allSettled(awaitingTransactions);\n for (let i = 0; i < sentTransactions.length && i < sequenceNumbers.length; i += 1) {\n // check sent transaction status\n const sentTransaction = sentTransactions[i];\n sequenceNumber = sequenceNumbers[i];\n if (sentTransaction.status === promiseFulfilledStatus) {\n // transaction sent to chain\n this.sentTransactions.push([sentTransaction.value.hash, sequenceNumber, null]);\n // check sent transaction execution\n this.emit(TransactionWorkerEventsEnum.TransactionSent, {\n message: `transaction hash ${sentTransaction.value.hash} has been committed to chain`,\n transactionHash: sentTransaction.value.hash,\n });\n await this.checkTransaction(sentTransaction, sequenceNumber);\n } else {\n // send transaction failed\n this.sentTransactions.push([sentTransaction.status, sequenceNumber, sentTransaction.reason]);\n this.emit(TransactionWorkerEventsEnum.TransactionSendFailed, {\n message: `failed to commit transaction ${this.sentTransactions.length} with error ${sentTransaction.reason}`,\n error: sentTransaction.reason,\n });\n }\n }\n this.emit(TransactionWorkerEventsEnum.ExecutionFinish, {\n message: `execute ${sentTransactions.length} transactions finished`,\n });\n }\n } catch (error: any) {\n if (error instanceof AsyncQueueCancelledError) {\n return;\n }\n throw new Error(`Process execution failed for ${this.account.accountAddress.toString()} with error ${error}`);\n }\n }\n\n /**\n * Once transaction has been sent to chain, we check for its execution status.\n * @param sentTransaction transactions that were sent to chain and are now waiting to be executed\n * @param sequenceNumber the account's sequence number that was sent with the transaction\n */\n async checkTransaction(sentTransaction: PromiseFulfilledResult<PendingTransactionResponse>, sequenceNumber: bigint) {\n try {\n const waitFor: Array<Promise<TransactionResponse>> = [];\n waitFor.push(waitForTransaction({ aptosConfig: this.aptosConfig, transactionHash: sentTransaction.value.hash }));\n const sentTransactions = await Promise.allSettled(waitFor);\n\n for (let i = 0; i < sentTransactions.length; i += 1) {\n const executedTransaction = sentTransactions[i];\n if (executedTransaction.status === promiseFulfilledStatus) {\n // transaction executed to chain\n this.executedTransactions.push([executedTransaction.value.hash, sequenceNumber, null]);\n this.emit(TransactionWorkerEventsEnum.TransactionExecuted, {\n message: `transaction hash ${executedTransaction.value.hash} has been executed on chain`,\n transactionHash: sentTransaction.value.hash,\n });\n } else {\n // transaction execution failed\n this.executedTransactions.push([executedTransaction.status, sequenceNumber, executedTransaction.reason]);\n this.emit(TransactionWorkerEventsEnum.TransactionExecutionFailed, {\n message: `failed to execute transaction ${this.executedTransactions.length} with error ${executedTransaction.reason}`,\n error: executedTransaction.reason,\n });\n }\n }\n } catch (error: any) {\n throw new Error(`Check transaction failed for ${this.account.accountAddress.toString()} with error ${error}`);\n }\n }\n\n /**\n * Push transaction to the transactions queue\n *\n * @param transactionData Transaction payload\n * @param transactionData.abi For all entry function payloads, the ABI to skip remote ABI lookups\n * @param options.maxGasAmount Maximum gas amount for the transaction\n * @param options.gasUnitPrice Gas unit price for the transaction\n * @param options.expireTimestamp expiration timestamp on the transaction\n * @param options.accountSequenceNumber the sequence number for the transaction\n */\n async push(\n transactionData: InputGenerateTransactionPayloadData,\n options?: InputGenerateTransactionOptions,\n ): Promise<void> {\n this.transactionsQueue.enqueue([transactionData, options]);\n }\n\n /**\n * Generates a signed transaction that can be submitted to chain\n * @param account an Aptos account\n * @param sequenceNumber a sequence number the transaction will be generated with\n * @returns\n */\n async generateNextTransaction(account: Account, sequenceNumber: bigint): Promise<SimpleTransaction | undefined> {\n if (this.transactionsQueue.isEmpty()) return undefined;\n const [transactionData, options] = await this.transactionsQueue.dequeue();\n return generateTransaction({\n aptosConfig: this.aptosConfig,\n sender: account.accountAddress,\n data: transactionData,\n options: { ...options, accountSequenceNumber: sequenceNumber },\n });\n }\n\n /**\n * Starts transaction submission and transaction processing.\n */\n async run() {\n try {\n while (!this.taskQueue.isCancelled()) {\n const task = await this.taskQueue.dequeue();\n await task();\n }\n } catch (error: any) {\n throw new Error(`Unable to start transaction batching: ${error}`);\n }\n }\n\n /**\n * Starts the transaction management process.\n */\n start() {\n if (this.started) {\n throw new Error(\"worker has already started\");\n }\n this.started = true;\n this.taskQueue.enqueue(() => this.submitNextTransaction());\n this.taskQueue.enqueue(() => this.processTransactions());\n this.run();\n }\n\n /**\n * Stops the the transaction management process.\n */\n stop() {\n if (this.taskQueue.isCancelled()) {\n throw new Error(\"worker has already stopped\");\n }\n this.started = false;\n this.taskQueue.cancel();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAEA,OAAO,kBAAkB;AAWlB,IAAM,yBAAyB;AAI/B,IAAK,8BAAL,kBAAKA,iCAAL;AAEL,EAAAA,6BAAA,qBAAkB;AAElB,EAAAA,6BAAA,2BAAwB;AAExB,EAAAA,6BAAA,yBAAsB;AAEtB,EAAAA,6BAAA,gCAA6B;AAE7B,EAAAA,6BAAA,qBAAkB;AAVR,SAAAA;AAAA,GAAA;AAmDL,IAAM,oBAAN,cAAgC,aAAsC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgD3E,YACE,aACA,SACA,cAAsB,IACtB,kBAA0B,KAC1B,YAAoB,IACpB;AACA,UAAM;AA/CR,SAAS,YAA6C,IAAI,WAAgC;AAU1F;AAAA;AAAA;AAAA;AAAA;AAAA,6BAAoB,IAAI,WAEtB;AAKF;AAAA;AAAA;AAAA,mCAA0B,I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B,QAAQ,QAAQ;AAAA,MAChB,MAAM;AAAA,MACN,SAAS,EAAE,GAAG,SAAS,uBAAuB,eAAe;AAAA,IAC/D,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,MAAM;AACV,QAAI;AACF,aAAO,CAAC,KAAK,UAAU,YAAY,GAAG;AACpC,cAAM,OAAO,MAAM,KAAK,UAAU,QAAQ;AAC1C,cAAM,KAAK;AAAA,MACb;AAAA,IACF,SAAS,OAAY;AACnB,YAAM,IAAI,MAAM,yCAAyC,KAAK,EAAE;AAAA,IAClE;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,QAAQ;AACN,QAAI,KAAK,SAAS;AAChB,YAAM,IAAI,MAAM,4BAA4B;AAAA,IAC9C;AACA,SAAK,UAAU;AACf,SAAK,UAAU,QAAQ,MAAM,KAAK,sBAAsB,CAAC;AACzD,SAAK,UAAU,QAAQ,MAAM,KAAK,oBAAoB,CAAC;AACvD,SAAK,IAAI;AAAA,EACX;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO;AACL,QAAI,KAAK,UAAU,YAAY,GAAG;AAChC,YAAM,IAAI,MAAM,4BAA4B;AAAA,IAC9C;AACA,SAAK,UAAU;AACf,SAAK,UAAU,OAAO;AAAA,EACxB;AACF;","names":["TransactionWorkerEventsEnum"]}
1
+ {"version":3,"sources":["../../src/transactions/management/transactionWorker.ts"],"sourcesContent":["/* eslint-disable no-await-in-loop */\n\nimport EventEmitter from \"eventemitter3\";\nimport { AptosConfig } from \"../../api/aptosConfig\";\nimport { Account } from \"../../account\";\nimport { waitForTransaction } from \"../../internal/transaction\";\nimport { generateTransaction, signAndSubmitTransaction } from \"../../internal/transactionSubmission\";\nimport { PendingTransactionResponse, TransactionResponse } from \"../../types\";\nimport { InputGenerateTransactionOptions, InputGenerateTransactionPayloadData } from \"../types\";\nimport { AccountSequenceNumber } from \"./accountSequenceNumber\";\nimport { AsyncQueue, AsyncQueueCancelledError } from \"./asyncQueue\";\nimport { SimpleTransaction } from \"../instances/simpleTransaction\";\n\nexport const promiseFulfilledStatus = \"fulfilled\";\n\n// Event types the worker fires during execution and\n// the dapp can listen to\nexport enum TransactionWorkerEventsEnum {\n // fired after a transaction gets sent to the chain\n TransactionSent = \"transactionSent\",\n // fired if there is an error sending the transaction to the chain\n TransactionSendFailed = \"transactionSendFailed\",\n // fired when a single transaction has executed successfully\n TransactionExecuted = \"transactionExecuted\",\n // fired if a single transaction fails in execution\n TransactionExecutionFailed = \"transactionExecutionFailed\",\n // fired when the worker has finished its job / when the queue has been emptied\n ExecutionFinish = \"executionFinish\",\n}\n\n// Typed interface of the worker events\nexport interface TransactionWorkerEvents {\n transactionSent: (data: SuccessEventData) => void;\n transactionSendFailed: (data: FailureEventData) => void;\n transactionExecuted: (data: SuccessEventData) => void;\n transactionExecutionFailed: (data: FailureEventData) => void;\n executionFinish: (data: ExecutionFinishEventData) => void;\n}\n\n// Type for when the worker has finished its job\nexport type ExecutionFinishEventData = {\n message: string;\n};\n\n// Type for a success event\nexport type SuccessEventData = {\n message: string;\n transactionHash: string;\n};\n\n// Type for a failure event\nexport type FailureEventData = {\n message: string;\n error: string;\n};\n\n/**\n * TransactionWorker provides a simple framework for receiving payloads to be processed.\n *\n * Once one `start()` the process and pushes a new transaction, the worker acquires\n * the current account's next sequence number (by using the AccountSequenceNumber class),\n * generates a signed transaction and pushes an async submission process into the `outstandingTransactions` queue.\n * At the same time, the worker processes transactions by reading the `outstandingTransactions` queue\n * and submits the next transaction to chain, it\n * 1) waits for resolution of the submission process or get pre-execution validation error\n * and 2) waits for the resolution of the execution process or get an execution error.\n * The worker fires events for any submission and/or execution success and/or failure.\n */\nexport class TransactionWorker extends EventEmitter<TransactionWorkerEvents> {\n readonly aptosConfig: AptosConfig;\n\n readonly account: Account;\n\n // current account sequence number\n readonly accountSequnceNumber: AccountSequenceNumber;\n\n readonly taskQueue: AsyncQueue<() => Promise<void>> = new AsyncQueue<() => Promise<void>>();\n\n // process has started\n started: boolean;\n\n /**\n * transactions payloads waiting to be generated and signed\n *\n * TODO support entry function payload from ABI builder\n */\n transactionsQueue = new AsyncQueue<\n [InputGenerateTransactionPayloadData, InputGenerateTransactionOptions | undefined]\n >();\n\n /**\n * signed transactions waiting to be submitted\n */\n outstandingTransactions = new AsyncQueue<[Promise<PendingTransactionResponse>, bigint]>();\n\n /**\n * transactions that have been submitted to chain\n */\n sentTransactions: Array<[string, bigint, any]> = [];\n\n /**\n * transactions that have been committed to chain\n */\n executedTransactions: Array<[string, bigint, any]> = [];\n\n /**\n * Provides a simple framework for receiving payloads to be processed.\n *\n * @param aptosConfig - a config object\n * @param sender - a sender as Account\n * @param maxWaitTime - the max wait time to wait before resyncing the sequence number\n * to the current on-chain state, default to 30\n * @param maximumInFlight - submit up to `maximumInFlight` transactions per account.\n * Mempool limits the number of transactions per account to 100, hence why we default to 100.\n * @param sleepTime - If `maximumInFlight` are in flight, wait `sleepTime` seconds before re-evaluating, default to 10\n */\n constructor(\n aptosConfig: AptosConfig,\n account: Account,\n maxWaitTime: number = 30,\n maximumInFlight: number = 100,\n sleepTime: number = 10,\n ) {\n super();\n this.aptosConfig = aptosConfig;\n this.account = account;\n this.started = false;\n this.accountSequnceNumber = new AccountSequenceNumber(\n aptosConfig,\n account,\n maxWaitTime,\n maximumInFlight,\n sleepTime,\n );\n }\n\n /**\n * Gets the current account sequence number,\n * generates the transaction with the account sequence number,\n * adds the transaction to the outstanding transaction queue\n * to be processed later.\n */\n async submitNextTransaction() {\n try {\n /* eslint-disable no-constant-condition */\n while (true) {\n const sequenceNumber = await this.accountSequnceNumber.nextSequenceNumber();\n if (sequenceNumber === null) return;\n const transaction = await this.generateNextTransaction(this.account, sequenceNumber);\n if (!transaction) return;\n const pendingTransaction = signAndSubmitTransaction({\n aptosConfig: this.aptosConfig,\n transaction,\n signer: this.account,\n });\n await this.outstandingTransactions.enqueue([pendingTransaction, sequenceNumber]);\n }\n } catch (error: any) {\n if (error instanceof AsyncQueueCancelledError) {\n return;\n }\n throw new Error(`Submit transaction failed for ${this.account.accountAddress.toString()} with error ${error}`);\n }\n }\n\n /**\n * Reads the outstanding transaction queue and submits the transaction to chain.\n *\n * If the transaction has fulfilled, it pushes the transaction to the processed\n * transactions queue and fires a transactionsFulfilled event.\n *\n * If the transaction has failed, it pushes the transaction to the processed\n * transactions queue with the failure reason and fires a transactionsFailed event.\n */\n async processTransactions() {\n try {\n /* eslint-disable no-constant-condition */\n while (true) {\n const awaitingTransactions = [];\n const sequenceNumbers = [];\n let [pendingTransaction, sequenceNumber] = await this.outstandingTransactions.dequeue();\n\n awaitingTransactions.push(pendingTransaction);\n sequenceNumbers.push(sequenceNumber);\n\n while (!this.outstandingTransactions.isEmpty()) {\n [pendingTransaction, sequenceNumber] = await this.outstandingTransactions.dequeue();\n\n awaitingTransactions.push(pendingTransaction);\n sequenceNumbers.push(sequenceNumber);\n }\n // send awaiting transactions to chain\n const sentTransactions = await Promise.allSettled(awaitingTransactions);\n for (let i = 0; i < sentTransactions.length && i < sequenceNumbers.length; i += 1) {\n // check sent transaction status\n const sentTransaction = sentTransactions[i];\n sequenceNumber = sequenceNumbers[i];\n if (sentTransaction.status === promiseFulfilledStatus) {\n // transaction sent to chain\n this.sentTransactions.push([sentTransaction.value.hash, sequenceNumber, null]);\n // check sent transaction execution\n this.emit(TransactionWorkerEventsEnum.TransactionSent, {\n message: `transaction hash ${sentTransaction.value.hash} has been committed to chain`,\n transactionHash: sentTransaction.value.hash,\n });\n await this.checkTransaction(sentTransaction, sequenceNumber);\n } else {\n // send transaction failed\n this.sentTransactions.push([sentTransaction.status, sequenceNumber, sentTransaction.reason]);\n this.emit(TransactionWorkerEventsEnum.TransactionSendFailed, {\n message: `failed to commit transaction ${this.sentTransactions.length} with error ${sentTransaction.reason}`,\n error: sentTransaction.reason,\n });\n }\n }\n this.emit(TransactionWorkerEventsEnum.ExecutionFinish, {\n message: `execute ${sentTransactions.length} transactions finished`,\n });\n }\n } catch (error: any) {\n if (error instanceof AsyncQueueCancelledError) {\n return;\n }\n throw new Error(`Process execution failed for ${this.account.accountAddress.toString()} with error ${error}`);\n }\n }\n\n /**\n * Once transaction has been sent to chain, we check for its execution status.\n * @param sentTransaction transactions that were sent to chain and are now waiting to be executed\n * @param sequenceNumber the account's sequence number that was sent with the transaction\n */\n async checkTransaction(sentTransaction: PromiseFulfilledResult<PendingTransactionResponse>, sequenceNumber: bigint) {\n try {\n const waitFor: Array<Promise<TransactionResponse>> = [];\n waitFor.push(waitForTransaction({ aptosConfig: this.aptosConfig, transactionHash: sentTransaction.value.hash }));\n const sentTransactions = await Promise.allSettled(waitFor);\n\n for (let i = 0; i < sentTransactions.length; i += 1) {\n const executedTransaction = sentTransactions[i];\n if (executedTransaction.status === promiseFulfilledStatus) {\n // transaction executed to chain\n this.executedTransactions.push([executedTransaction.value.hash, sequenceNumber, null]);\n this.emit(TransactionWorkerEventsEnum.TransactionExecuted, {\n message: `transaction hash ${executedTransaction.value.hash} has been executed on chain`,\n transactionHash: sentTransaction.value.hash,\n });\n } else {\n // transaction execution failed\n this.executedTransactions.push([executedTransaction.status, sequenceNumber, executedTransaction.reason]);\n this.emit(TransactionWorkerEventsEnum.TransactionExecutionFailed, {\n message: `failed to execute transaction ${this.executedTransactions.length} with error ${executedTransaction.reason}`,\n error: executedTransaction.reason,\n });\n }\n }\n } catch (error: any) {\n throw new Error(`Check transaction failed for ${this.account.accountAddress.toString()} with error ${error}`);\n }\n }\n\n /**\n * Push transaction to the transactions queue\n *\n * @param transactionData Transaction payload\n * @param transactionData.abi For all entry function payloads, the ABI to skip remote ABI lookups\n * @param options.maxGasAmount Maximum gas amount for the transaction\n * @param options.gasUnitPrice Gas unit price for the transaction\n * @param options.expireTimestamp expiration timestamp on the transaction\n * @param options.accountSequenceNumber the sequence number for the transaction\n */\n async push(\n transactionData: InputGenerateTransactionPayloadData,\n options?: InputGenerateTransactionOptions,\n ): Promise<void> {\n this.transactionsQueue.enqueue([transactionData, options]);\n }\n\n /**\n * Generates a signed transaction that can be submitted to chain\n * @param account an Aptos account\n * @param sequenceNumber a sequence number the transaction will be generated with\n * @returns\n */\n async generateNextTransaction(account: Account, sequenceNumber: bigint): Promise<SimpleTransaction | undefined> {\n if (this.transactionsQueue.isEmpty()) return undefined;\n const [transactionData, options] = await this.transactionsQueue.dequeue();\n return generateTransaction({\n aptosConfig: this.aptosConfig,\n sender: account.accountAddress,\n data: transactionData,\n options: { ...options, accountSequenceNumber: sequenceNumber },\n });\n }\n\n /**\n * Starts transaction submission and transaction processing.\n */\n async run() {\n try {\n while (!this.taskQueue.isCancelled()) {\n const task = await this.taskQueue.dequeue();\n await task();\n }\n } catch (error: any) {\n throw new Error(`Unable to start transaction batching: ${error}`);\n }\n }\n\n /**\n * Starts the transaction management process.\n */\n start() {\n if (this.started) {\n throw new Error(\"worker has already started\");\n }\n this.started = true;\n this.taskQueue.enqueue(() => this.submitNextTransaction());\n this.taskQueue.enqueue(() => this.processTransactions());\n this.run();\n }\n\n /**\n * Stops the the transaction management process.\n */\n stop() {\n if (this.taskQueue.isCancelled()) {\n throw new Error(\"worker has already stopped\");\n }\n this.started = false;\n this.taskQueue.cancel();\n }\n}\n"],"mappings":"kLAEA,OAAOA,MAAkB,gBAWlB,IAAMC,EAAyB,YAI1BC,OAEVA,EAAA,gBAAkB,kBAElBA,EAAA,sBAAwB,wBAExBA,EAAA,oBAAsB,sBAEtBA,EAAA,2BAA6B,6BAE7BA,EAAA,gBAAkB,kBAVRA,OAAA,IAmDCC,EAAN,cAAgCC,CAAsC,CAgD3E,YACEC,EACAC,EACAC,EAAsB,GACtBC,EAA0B,IAC1BC,EAAoB,GACpB,CACA,MAAM,EA/CR,KAAS,UAA6C,IAAIC,EAU1D,uBAAoB,IAAIA,EAOxB,6BAA0B,IAAIA,EAK9B,sBAAiD,CAAC,EAKlD,0BAAqD,CAAC,EAqBpD,KAAK,YAAcL,EACnB,KAAK,QAAUC,EACf,KAAK,QAAU,GACf,KAAK,qBAAuB,IAAIK,EA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GACnH,MAAOA,EAAoB,MAC7B,CAAC,EAEL,CACF,OAAST,EAAY,CACnB,MAAM,IAAI,MAAM,gCAAgC,KAAK,QAAQ,eAAe,SAAS,CAAC,eAAeA,CAAK,EAAE,CAC9G,CACF,CAYA,MAAM,KACJU,EACAC,EACe,CACf,KAAK,kBAAkB,QAAQ,CAACD,EAAiBC,CAAO,CAAC,CAC3D,CAQA,MAAM,wBAAwBrB,EAAkBM,EAAgE,CAC9G,GAAI,KAAK,kBAAkB,QAAQ,EAAG,OACtC,GAAM,CAACc,EAAiBC,CAAO,EAAI,MAAM,KAAK,kBAAkB,QAAQ,EACxE,OAAOC,EAAoB,CACzB,YAAa,KAAK,YAClB,OAAQtB,EAAQ,eAChB,KAAMoB,EACN,QAAS,CAAE,GAAGC,EAAS,sBAAuBf,CAAe,CAC/D,CAAC,CACH,CAKA,MAAM,KAAM,CACV,GAAI,CACF,KAAO,CAAC,KAAK,UAAU,YAAY,GAEjC,MADa,MAAM,KAAK,UAAU,QAAQ,GAC/B,CAEf,OAASI,EAAY,CACnB,MAAM,IAAI,MAAM,yCAAyCA,CAAK,EAAE,CAClE,CACF,CAKA,OAAQ,CACN,GAAI,KAAK,QACP,MAAM,IAAI,MAAM,4BAA4B,EAE9C,KAAK,QAAU,GACf,KAAK,UAAU,QAAQ,IAAM,KAAK,sBAAsB,CAAC,EACzD,KAAK,UAAU,QAAQ,IAAM,KAAK,oBAAoB,CAAC,EACvD,KAAK,IAAI,CACX,CAKA,MAAO,CACL,GAAI,KAAK,UAAU,YAAY,EAC7B,MAAM,IAAI,MAAM,4BAA4B,EAE9C,KAAK,QAAU,GACf,KAAK,UAAU,OAAO,CACxB,CACF","names":["EventEmitter","promiseFulfilledStatus","TransactionWorkerEventsEnum","TransactionWorker","EventEmitter","aptosConfig","account","maxWaitTime","maximumInFlight","sleepTime","AsyncQueue","AccountSequenceNumber","sequenceNumber","transaction","pendingTransaction","signAndSubmitTransaction","error","AsyncQueueCancelledError","awaitingTransactions","sequenceNumbers","sentTransactions","i","sentTransaction","waitFor","waitForTransaction","executedTransaction","transactionData","options","generateTransaction"]}
@@ -0,0 +1,2 @@
1
+ import{a as r}from"./chunk-TVRJ3M7B.mjs";import{b as t}from"./chunk-AOCNYMMX.mjs";var o=class extends r{toString(){let i=this.toUint8Array();return t.fromHexInput(i).toString()}};export{o as a};
2
+ //# sourceMappingURL=chunk-STYDBDYL.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/crypto/signature.ts"],"sourcesContent":["import { Serializable } from \"../../bcs\";\nimport { Hex } from \"../hex\";\n\n/**\n * An abstract representation of a crypto signature,\n * associated to a specific signature scheme e.g. Ed25519 or Secp256k1\n *\n * This is the product of signing a message directly from a PrivateKey\n * and can be verified against a CryptoPublicKey.\n */\nexport abstract class Signature extends Serializable {\n /**\n * Get the raw signature bytes\n */\n abstract toUint8Array(): Uint8Array;\n\n /**\n * Get the signature as a hex string with a 0x prefix e.g. 0x123456...\n */\n toString(): string {\n const bytes = this.toUint8Array();\n return Hex.fromHexInput(bytes).toString();\n }\n}\n\n/**\n * An abstract representation of an account signature,\n * associated to a specific authentication scheme e.g. Ed25519 or SingleKey\n *\n * This is the product of signing a message through an account,\n * and can be verified against an AccountPublicKey.\n */\n// export abstract class AccountSignature extends Serializable {\n// /**\n// * Get the raw signature bytes\n// */\n// abstract toUint8Array(): Uint8Array;\n//\n// /**\n// * Get the signature as a hex string with a 0x prefix e.g. 0x123456...\n// */\n// toString(): string {\n// const bytes = this.toUint8Array();\n// return Hex.fromHexInput(bytes).toString();\n// }\n// }\n"],"mappings":";;;;;;;;AAUO,IAAe,YAAf,cAAiC,aAAa;AAAA;AAAA;AAAA;AAAA,EASnD,WAAmB;AACjB,UAAM,QAAQ,KAAK,aAAa;AAChC,WAAO,IAAI,aAAa,KAAK,EAAE,SAAS;AAAA,EAC1C;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/core/crypto/signature.ts"],"sourcesContent":["import { Serializable } from \"../../bcs\";\nimport { Hex } from \"../hex\";\n\n/**\n * An abstract representation of a crypto signature,\n * associated to a specific signature scheme e.g. Ed25519 or Secp256k1\n *\n * This is the product of signing a message directly from a PrivateKey\n * and can be verified against a CryptoPublicKey.\n */\nexport abstract class Signature extends Serializable {\n /**\n * Get the raw signature bytes\n */\n abstract toUint8Array(): Uint8Array;\n\n /**\n * Get the signature as a hex string with a 0x prefix e.g. 0x123456...\n */\n toString(): string {\n const bytes = this.toUint8Array();\n return Hex.fromHexInput(bytes).toString();\n }\n}\n\n/**\n * An abstract representation of an account signature,\n * associated to a specific authentication scheme e.g. Ed25519 or SingleKey\n *\n * This is the product of signing a message through an account,\n * and can be verified against an AccountPublicKey.\n */\n// export abstract class AccountSignature extends Serializable {\n// /**\n// * Get the raw signature bytes\n// */\n// abstract toUint8Array(): Uint8Array;\n//\n// /**\n// * Get the signature as a hex string with a 0x prefix e.g. 0x123456...\n// */\n// toString(): string {\n// const bytes = this.toUint8Array();\n// return Hex.fromHexInput(bytes).toString();\n// }\n// }\n"],"mappings":"kFAUO,IAAeA,EAAf,cAAiCC,CAAa,CASnD,UAAmB,CACjB,IAAMC,EAAQ,KAAK,aAAa,EAChC,OAAOC,EAAI,aAAaD,CAAK,EAAE,SAAS,CAC1C,CACF","names":["Signature","Serializable","bytes","Hex"]}
@@ -0,0 +1,2 @@
1
+ import{a as n}from"./chunk-AFGTRMOR.mjs";import{a as c}from"./chunk-HX5246EM.mjs";import{b as i}from"./chunk-PYUU4OEL.mjs";var o=class{static generate(e={}){let{scheme:t=0,legacy:r=!0}=e;return t===0&&r?n.generate():c.generate({scheme:t})}static fromPrivateKey(e){let{privateKey:t,address:r,legacy:a=!0}=e;return t instanceof i&&a?new n({privateKey:t,address:r}):new c({privateKey:t,address:r})}static fromPrivateKeyAndAddress(e){return this.fromPrivateKey(e)}static fromDerivationPath(e){let{scheme:t=0,mnemonic:r,path:a,legacy:s=!0}=e;return t===0&&s?n.fromDerivationPath({mnemonic:r,path:a}):c.fromDerivationPath({scheme:t,mnemonic:r,path:a})}static authKey(e){let{publicKey:t}=e;return t.authKey()}verifySignature(e){return this.publicKey.verifySignature(e)}};export{o as a};
2
+ //# sourceMappingURL=chunk-SXOQWGMT.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/account/Account.ts"],"sourcesContent":["import type { AccountAuthenticator } from \"../transactions/authenticator/account\";\nimport { HexInput, SigningScheme, SigningSchemeInput } from \"../types\";\nimport type { AccountAddress, AccountAddressInput } from \"../core/accountAddress\";\nimport { AuthenticationKey } from \"../core/authenticationKey\";\nimport { AccountPublicKey, Ed25519PrivateKey, PrivateKey, Signature, VerifySignatureArgs } from \"../core/crypto\";\nimport { Ed25519Account } from \"./Ed25519Account\";\nimport { SingleKeyAccount } from \"./SingleKeyAccount\";\nimport { AnyRawTransaction } from \"../transactions/types\";\n\n/**\n * Arguments for creating an `Ed25519Account` from an `Ed25519PrivateKey`.\n * This is the default input type when passing an `Ed25519PrivateKey`.\n * In order to use the SingleKey authentication scheme, `legacy` needs to be explicitly set to false.\n */\nexport interface CreateEd25519AccountFromPrivateKeyArgs {\n privateKey: Ed25519PrivateKey;\n address?: AccountAddressInput;\n legacy?: true;\n}\n\n/**\n * Arguments for creating an `SingleKeyAccount` from an `Ed25519PrivateKey`.\n * The `legacy` argument needs to be explicitly set to false in order to\n * use the `SingleKey` authentication scheme.\n */\nexport interface CreateEd25519SingleKeyAccountFromPrivateKeyArgs {\n privateKey: Ed25519PrivateKey;\n address?: AccountAddressInput;\n legacy: false;\n}\n\n/**\n * Arguments for creating an `SingleKeyAccount` from any supported private key\n * that is not an `Ed25519PrivateKey`.\n * The `legacy` argument defaults to false and cannot be explicitly set to true.\n */\nexport interface CreateSingleKeyAccountFromPrivateKeyArgs {\n privateKey: Exclude<PrivateKey, Ed25519PrivateKey>;\n address?: AccountAddressInput;\n legacy?: false;\n}\n\n/**\n * Arguments for creating an opaque `Account` from any supported private key.\n * This is used when the private key type is not known at compilation time.\n */\nexport interface CreateAccountFromPrivateKeyArgs {\n privateKey: PrivateKey;\n address?: AccountAddressInput;\n legacy?: boolean;\n}\n\n/**\n * Arguments for generating an `Ed25519Account`.\n * This is the input type used by default.\n */\nexport interface GenerateEd25519AccountArgs {\n scheme?: SigningSchemeInput.Ed25519;\n legacy?: true;\n}\n\n/**\n * Arguments for generating an `SingleKeyAccount` with ah underlying `Ed25519PrivateKey`.\n * The `legacy` argument needs to be explicitly set to false,\n * otherwise an `Ed25519Account` will be returned instead.\n */\nexport interface GenerateEd25519SingleKeyAccountArgs {\n scheme?: SigningSchemeInput.Ed25519;\n legacy: false;\n}\n\n/**\n * Arguments for generating an `SingleKeyAccount` with any supported private key\n * that is not an `Ed25519PrivateKey`.\n * The `legacy` argument defaults to false and cannot be explicitly set to true.\n */\nexport interface GenerateSingleKeyAccountArgs {\n scheme: Exclude<SigningSchemeInput, SigningSchemeInput.Ed25519>;\n legacy?: false;\n}\n\n/**\n * Arguments for generating an opaque `Account`.\n * This is used when the input signature scheme is not known at compilation time.\n */\nexport interface GenerateAccountArgs {\n scheme?: SigningSchemeInput;\n legacy?: boolean;\n}\n\n/**\n * Arguments for deriving a private key from a mnemonic phrase and a BIP44 path.\n */\nexport interface PrivateKeyFromDerivationPathArgs {\n path: string;\n mnemonic: string;\n}\n\n/**\n * Interface for a generic Aptos account.\n *\n * The interface is defined as abstract class to provide a single entrypoint for account generation,\n * either through `Account.generate()` or `Account.fromDerivationPath`.\n * Despite this being an abstract class, it should be treated as an interface and enforced using\n * the `implements` keyword.\n *\n * Note: Generating an account instance does not create the account on-chain.\n */\nexport abstract class Account {\n /**\n * Public key associated with the account\n */\n abstract readonly publicKey: AccountPublicKey;\n\n /**\n * Account address associated with the account\n */\n abstract readonly accountAddress: AccountAddress;\n\n /**\n * Signing scheme used to sign transactions\n */\n abstract signingScheme: SigningScheme;\n\n /**\n * Derives an account from a randomly generated private key.\n * @param args.scheme The signature scheme to use, to generate the private key\n * @param args.legacy Whether to use a legacy authentication scheme, when applicable\n * @returns An account compatible with the provided signature scheme\n */\n static generate(args?: GenerateEd25519AccountArgs): Ed25519Account;\n static generate(args: GenerateEd25519SingleKeyAccountArgs): SingleKeyAccount;\n static generate(args: GenerateSingleKeyAccountArgs): SingleKeyAccount;\n static generate(args: GenerateAccountArgs): Account;\n static generate(args: GenerateAccountArgs = {}) {\n const { scheme = SigningSchemeInput.Ed25519, legacy = true } = args;\n if (scheme === SigningSchemeInput.Ed25519 && legacy) {\n return Ed25519Account.generate();\n }\n return SingleKeyAccount.generate({ scheme });\n }\n\n /**\n * Creates an account from the provided private key.\n *\n * @param args.privateKey a valid private key\n * @param args.address the account's address. If not provided, it will be derived from the public key.\n * @param args.legacy Whether to use a legacy authentication scheme, when applicable\n */\n static fromPrivateKey(args: CreateEd25519AccountFromPrivateKeyArgs): Ed25519Account;\n static fromPrivateKey(args: CreateEd25519SingleKeyAccountFromPrivateKeyArgs): SingleKeyAccount;\n static fromPrivateKey(args: CreateSingleKeyAccountFromPrivateKeyArgs): SingleKeyAccount;\n static fromPrivateKey(args: CreateAccountFromPrivateKeyArgs): Account;\n static fromPrivateKey(args: CreateAccountFromPrivateKeyArgs) {\n const { privateKey, address, legacy = true } = args;\n if (privateKey instanceof Ed25519PrivateKey && legacy) {\n return new Ed25519Account({\n privateKey,\n address,\n });\n }\n return new SingleKeyAccount({ privateKey, address });\n }\n\n /**\n * @deprecated use `fromPrivateKey` instead.\n * Instantiates an account given a private key and a specified account address.\n * This is primarily used to instantiate an `Account` that has had its authentication key rotated.\n *\n * @param args.privateKey PrivateKey - the underlying private key for the account\n * @param args.address AccountAddress - The account address the `Account` will sign for\n * @param args.legacy optional. If set to false, the keypair generated is a Unified keypair. Defaults\n * to generating a Legacy Ed25519 keypair\n *\n * @returns Account\n */\n static fromPrivateKeyAndAddress(args: CreateAccountFromPrivateKeyArgs) {\n return this.fromPrivateKey(args);\n }\n\n /**\n * Derives an account with bip44 path and mnemonics\n *\n * @param args.scheme The signature scheme to derive the private key with\n * @param args.path the BIP44 derive hardened path (e.g. m/44'/637'/0'/0'/0') for Ed25519,\n * or non-hardened path (e.g. m/44'/637'/0'/0/0) for secp256k1\n * Detailed description: {@link https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki}\n * @param args.mnemonic the mnemonic seed phrase of the account\n */\n static fromDerivationPath(args: GenerateEd25519AccountArgs & PrivateKeyFromDerivationPathArgs): Ed25519Account;\n static fromDerivationPath(\n args: GenerateEd25519SingleKeyAccountArgs & PrivateKeyFromDerivationPathArgs,\n ): SingleKeyAccount;\n static fromDerivationPath(args: GenerateSingleKeyAccountArgs & PrivateKeyFromDerivationPathArgs): SingleKeyAccount;\n static fromDerivationPath(args: GenerateAccountArgs & PrivateKeyFromDerivationPathArgs): Account;\n static fromDerivationPath(args: GenerateAccountArgs & PrivateKeyFromDerivationPathArgs) {\n const { scheme = SigningSchemeInput.Ed25519, mnemonic, path, legacy = true } = args;\n if (scheme === SigningSchemeInput.Ed25519 && legacy) {\n return Ed25519Account.fromDerivationPath({ mnemonic, path });\n }\n return SingleKeyAccount.fromDerivationPath({ scheme, mnemonic, path });\n }\n\n /**\n * @deprecated use `publicKey.authKey()` instead.\n * This key enables account owners to rotate their private key(s)\n * associated with the account without changing the address that hosts their account.\n * See here for more info: {@link https://aptos.dev/concepts/accounts#single-signer-authentication}\n *\n * @param args.publicKey PublicKey - public key of the account\n * @returns The authentication key for the associated account\n */\n static authKey(args: { publicKey: AccountPublicKey }): AuthenticationKey {\n const { publicKey } = args;\n return publicKey.authKey();\n }\n\n /**\n * Sign a message using the available signing capabilities.\n * @param message the signing message, as binary input\n * @return the AccountAuthenticator containing the signature, together with the account's public key\n */\n abstract signWithAuthenticator(message: HexInput): AccountAuthenticator;\n\n /**\n * Sign a transaction using the available signing capabilities.\n * @param transaction the raw transaction\n * @return the AccountAuthenticator containing the signature of the transaction, together with the account's public key\n */\n abstract signTransactionWithAuthenticator(transaction: AnyRawTransaction): AccountAuthenticator;\n\n /**\n * Sign the given message using the available signing capabilities.\n * @param message in HexInput format\n * @returns Signature\n */\n abstract sign(message: HexInput): Signature;\n\n /**\n * Sign the given transaction using the available signing capabilities.\n * @param transaction the transaction to be signed\n * @returns Signature\n */\n abstract signTransaction(transaction: AnyRawTransaction): Signature;\n\n /**\n * Verify the given message and signature with the public key.\n * @param args.message raw message data in HexInput format\n * @param args.signature signed message Signature\n * @returns\n */\n verifySignature(args: VerifySignatureArgs): boolean {\n return this.publicKey.verifySignature(args);\n }\n}\n"],"mappings":";;;;;;;;;;;AA4GO,IAAe,UAAf,MAAuB;AAAA,EA0B5B,OAAO,SAAS,OAA4B,CAAC,GAAG;AAC9C,UAAM,EAAE,0BAAqC,SAAS,KAAK,IAAI;AAC/D,QAAI,8BAAyC,QAAQ;AACnD,aAAO,eAAe,SAAS;AAAA,IACjC;AACA,WAAO,iBAAiB,SAAS,EAAE,OAAO,CAAC;AAAA,EAC7C;AAAA,EAaA,OAAO,eAAe,MAAuC;AAC3D,UAAM,EAAE,YAAY,SAAS,SAAS,KAAK,IAAI;AAC/C,QAAI,sBAAsB,qBAAqB,QAAQ;AACrD,aAAO,IAAI,eAAe;AAAA,QACxB;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AACA,WAAO,IAAI,iBAAiB,EAAE,YAAY,QAAQ,CAAC;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,OAAO,yBAAyB,MAAuC;AACrE,WAAO,KAAK,eAAe,IAAI;AAAA,EACjC;AAAA,EAiBA,OAAO,mBAAmB,MAA8D;AACtF,UAAM,EAAE,0BAAqC,UAAU,MAAM,SAAS,KAAK,IAAI;AAC/E,QAAI,8BAAyC,QAAQ;AACnD,aAAO,eAAe,mBAAmB,EAAE,UAAU,KAAK,CAAC;AAAA,IAC7D;AACA,WAAO,iBAAiB,mBAAmB,EAAE,QAAQ,UAAU,KAAK,CAAC;AAAA,EACvE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,OAAO,QAAQ,MAA0D;AACvE,UAAM,EAAE,UAAU,IAAI;AACtB,WAAO,UAAU,QAAQ;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoCA,gBAAgB,MAAoC;AAClD,WAAO,KAAK,UAAU,gBAAgB,IAAI;AAAA,EAC5C;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/account/Account.ts"],"sourcesContent":["import type { AccountAuthenticator } from \"../transactions/authenticator/account\";\nimport { HexInput, SigningScheme, SigningSchemeInput } from \"../types\";\nimport type { AccountAddress, AccountAddressInput } from \"../core/accountAddress\";\nimport { AuthenticationKey } from \"../core/authenticationKey\";\nimport { AccountPublicKey, Ed25519PrivateKey, PrivateKey, Signature, VerifySignatureArgs } from \"../core/crypto\";\nimport { Ed25519Account } from \"./Ed25519Account\";\nimport { SingleKeyAccount } from \"./SingleKeyAccount\";\nimport { AnyRawTransaction } from \"../transactions/types\";\n\n/**\n * Arguments for creating an `Ed25519Account` from an `Ed25519PrivateKey`.\n * This is the default input type when passing an `Ed25519PrivateKey`.\n * In order to use the SingleKey authentication scheme, `legacy` needs to be explicitly set to false.\n */\nexport interface CreateEd25519AccountFromPrivateKeyArgs {\n privateKey: Ed25519PrivateKey;\n address?: AccountAddressInput;\n legacy?: true;\n}\n\n/**\n * Arguments for creating an `SingleKeyAccount` from an `Ed25519PrivateKey`.\n * The `legacy` argument needs to be explicitly set to false in order to\n * use the `SingleKey` authentication scheme.\n */\nexport interface CreateEd25519SingleKeyAccountFromPrivateKeyArgs {\n privateKey: Ed25519PrivateKey;\n address?: AccountAddressInput;\n legacy: false;\n}\n\n/**\n * Arguments for creating an `SingleKeyAccount` from any supported private key\n * that is not an `Ed25519PrivateKey`.\n * The `legacy` argument defaults to false and cannot be explicitly set to true.\n */\nexport interface CreateSingleKeyAccountFromPrivateKeyArgs {\n privateKey: Exclude<PrivateKey, Ed25519PrivateKey>;\n address?: AccountAddressInput;\n legacy?: false;\n}\n\n/**\n * Arguments for creating an opaque `Account` from any supported private key.\n * This is used when the private key type is not known at compilation time.\n */\nexport interface CreateAccountFromPrivateKeyArgs {\n privateKey: PrivateKey;\n address?: AccountAddressInput;\n legacy?: boolean;\n}\n\n/**\n * Arguments for generating an `Ed25519Account`.\n * This is the input type used by default.\n */\nexport interface GenerateEd25519AccountArgs {\n scheme?: SigningSchemeInput.Ed25519;\n legacy?: true;\n}\n\n/**\n * Arguments for generating an `SingleKeyAccount` with ah underlying `Ed25519PrivateKey`.\n * The `legacy` argument needs to be explicitly set to false,\n * otherwise an `Ed25519Account` will be returned instead.\n */\nexport interface GenerateEd25519SingleKeyAccountArgs {\n scheme?: SigningSchemeInput.Ed25519;\n legacy: false;\n}\n\n/**\n * Arguments for generating an `SingleKeyAccount` with any supported private key\n * that is not an `Ed25519PrivateKey`.\n * The `legacy` argument defaults to false and cannot be explicitly set to true.\n */\nexport interface GenerateSingleKeyAccountArgs {\n scheme: Exclude<SigningSchemeInput, SigningSchemeInput.Ed25519>;\n legacy?: false;\n}\n\n/**\n * Arguments for generating an opaque `Account`.\n * This is used when the input signature scheme is not known at compilation time.\n */\nexport interface GenerateAccountArgs {\n scheme?: SigningSchemeInput;\n legacy?: boolean;\n}\n\n/**\n * Arguments for deriving a private key from a mnemonic phrase and a BIP44 path.\n */\nexport interface PrivateKeyFromDerivationPathArgs {\n path: string;\n mnemonic: string;\n}\n\n/**\n * Interface for a generic Aptos account.\n *\n * The interface is defined as abstract class to provide a single entrypoint for account generation,\n * either through `Account.generate()` or `Account.fromDerivationPath`.\n * Despite this being an abstract class, it should be treated as an interface and enforced using\n * the `implements` keyword.\n *\n * Note: Generating an account instance does not create the account on-chain.\n */\nexport abstract class Account {\n /**\n * Public key associated with the account\n */\n abstract readonly publicKey: AccountPublicKey;\n\n /**\n * Account address associated with the account\n */\n abstract readonly accountAddress: AccountAddress;\n\n /**\n * Signing scheme used to sign transactions\n */\n abstract signingScheme: SigningScheme;\n\n /**\n * Derives an account from a randomly generated private key.\n * @param args.scheme The signature scheme to use, to generate the private key\n * @param args.legacy Whether to use a legacy authentication scheme, when applicable\n * @returns An account compatible with the provided signature scheme\n */\n static generate(args?: GenerateEd25519AccountArgs): Ed25519Account;\n static generate(args: GenerateEd25519SingleKeyAccountArgs): SingleKeyAccount;\n static generate(args: GenerateSingleKeyAccountArgs): SingleKeyAccount;\n static generate(args: GenerateAccountArgs): Account;\n static generate(args: GenerateAccountArgs = {}) {\n const { scheme = SigningSchemeInput.Ed25519, legacy = true } = args;\n if (scheme === SigningSchemeInput.Ed25519 && legacy) {\n return Ed25519Account.generate();\n }\n return SingleKeyAccount.generate({ scheme });\n }\n\n /**\n * Creates an account from the provided private key.\n *\n * @param args.privateKey a valid private key\n * @param args.address the account's address. If not provided, it will be derived from the public key.\n * @param args.legacy Whether to use a legacy authentication scheme, when applicable\n */\n static fromPrivateKey(args: CreateEd25519AccountFromPrivateKeyArgs): Ed25519Account;\n static fromPrivateKey(args: CreateEd25519SingleKeyAccountFromPrivateKeyArgs): SingleKeyAccount;\n static fromPrivateKey(args: CreateSingleKeyAccountFromPrivateKeyArgs): SingleKeyAccount;\n static fromPrivateKey(args: CreateAccountFromPrivateKeyArgs): Account;\n static fromPrivateKey(args: CreateAccountFromPrivateKeyArgs) {\n const { privateKey, address, legacy = true } = args;\n if (privateKey instanceof Ed25519PrivateKey && legacy) {\n return new Ed25519Account({\n privateKey,\n address,\n });\n }\n return new SingleKeyAccount({ privateKey, address });\n }\n\n /**\n * @deprecated use `fromPrivateKey` instead.\n * Instantiates an account given a private key and a specified account address.\n * This is primarily used to instantiate an `Account` that has had its authentication key rotated.\n *\n * @param args.privateKey PrivateKey - the underlying private key for the account\n * @param args.address AccountAddress - The account address the `Account` will sign for\n * @param args.legacy optional. If set to false, the keypair generated is a Unified keypair. Defaults\n * to generating a Legacy Ed25519 keypair\n *\n * @returns Account\n */\n static fromPrivateKeyAndAddress(args: CreateAccountFromPrivateKeyArgs) {\n return this.fromPrivateKey(args);\n }\n\n /**\n * Derives an account with bip44 path and mnemonics\n *\n * @param args.scheme The signature scheme to derive the private key with\n * @param args.path the BIP44 derive hardened path (e.g. m/44'/637'/0'/0'/0') for Ed25519,\n * or non-hardened path (e.g. m/44'/637'/0'/0/0) for secp256k1\n * Detailed description: {@link https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki}\n * @param args.mnemonic the mnemonic seed phrase of the account\n */\n static fromDerivationPath(args: GenerateEd25519AccountArgs & PrivateKeyFromDerivationPathArgs): Ed25519Account;\n static fromDerivationPath(\n args: GenerateEd25519SingleKeyAccountArgs & PrivateKeyFromDerivationPathArgs,\n ): SingleKeyAccount;\n static fromDerivationPath(args: GenerateSingleKeyAccountArgs & PrivateKeyFromDerivationPathArgs): SingleKeyAccount;\n static fromDerivationPath(args: GenerateAccountArgs & PrivateKeyFromDerivationPathArgs): Account;\n static fromDerivationPath(args: GenerateAccountArgs & PrivateKeyFromDerivationPathArgs) {\n const { scheme = SigningSchemeInput.Ed25519, mnemonic, path, legacy = true } = args;\n if (scheme === SigningSchemeInput.Ed25519 && legacy) {\n return Ed25519Account.fromDerivationPath({ mnemonic, path });\n }\n return SingleKeyAccount.fromDerivationPath({ scheme, mnemonic, path });\n }\n\n /**\n * @deprecated use `publicKey.authKey()` instead.\n * This key enables account owners to rotate their private key(s)\n * associated with the account without changing the address that hosts their account.\n * See here for more info: {@link https://aptos.dev/concepts/accounts#single-signer-authentication}\n *\n * @param args.publicKey PublicKey - public key of the account\n * @returns The authentication key for the associated account\n */\n static authKey(args: { publicKey: AccountPublicKey }): AuthenticationKey {\n const { publicKey } = args;\n return publicKey.authKey();\n }\n\n /**\n * Sign a message using the available signing capabilities.\n * @param message the signing message, as binary input\n * @return the AccountAuthenticator containing the signature, together with the account's public key\n */\n abstract signWithAuthenticator(message: HexInput): AccountAuthenticator;\n\n /**\n * Sign a transaction using the available signing capabilities.\n * @param transaction the raw transaction\n * @return the AccountAuthenticator containing the signature of the transaction, together with the account's public key\n */\n abstract signTransactionWithAuthenticator(transaction: AnyRawTransaction): AccountAuthenticator;\n\n /**\n * Sign the given message using the available signing capabilities.\n * @param message in HexInput format\n * @returns Signature\n */\n abstract sign(message: HexInput): Signature;\n\n /**\n * Sign the given transaction using the available signing capabilities.\n * @param transaction the transaction to be signed\n * @returns Signature\n */\n abstract signTransaction(transaction: AnyRawTransaction): Signature;\n\n /**\n * Verify the given message and signature with the public key.\n * @param args.message raw message data in HexInput format\n * @param args.signature signed message Signature\n * @returns\n */\n verifySignature(args: VerifySignatureArgs): boolean {\n return this.publicKey.verifySignature(args);\n }\n}\n"],"mappings":"2HA4GO,IAAeA,EAAf,KAAuB,CA0B5B,OAAO,SAASC,EAA4B,CAAC,EAAG,CAC9C,GAAM,CAAE,OAAAC,IAAqC,OAAAC,EAAS,EAAK,EAAIF,EAC/D,OAAIC,IAAW,GAA8BC,EACpCC,EAAe,SAAS,EAE1BC,EAAiB,SAAS,CAAE,OAAAH,CAAO,CAAC,CAC7C,CAaA,OAAO,eAAeD,EAAuC,CAC3D,GAAM,CAAE,WAAAK,EAAY,QAAAC,EAAS,OAAAJ,EAAS,EAAK,EAAIF,EAC/C,OAAIK,aAAsBE,GAAqBL,EACtC,IAAIC,EAAe,CACxB,WAAAE,EACA,QAAAC,CACF,CAAC,EAEI,IAAIF,EAAiB,CAAE,WAAAC,EAAY,QAAAC,CAAQ,CAAC,CACrD,CAcA,OAAO,yBAAyBN,EAAuC,CACrE,OAAO,KAAK,eAAeA,CAAI,CACjC,CAiBA,OAAO,mBAAmBA,EAA8D,CACtF,GAAM,CAAE,OAAAC,IAAqC,SAAAO,EAAU,KAAAC,EAAM,OAAAP,EAAS,EAAK,EAAIF,EAC/E,OAAIC,IAAW,GAA8BC,EACpCC,EAAe,mBAAmB,CAAE,SAAAK,EAAU,KAAAC,CAAK,CAAC,EAEtDL,EAAiB,mBAAmB,CAAE,OAAAH,EAAQ,SAAAO,EAAU,KAAAC,CAAK,CAAC,CACvE,CAWA,OAAO,QAAQT,EAA0D,CACvE,GAAM,CAAE,UAAAU,CAAU,EAAIV,EACtB,OAAOU,EAAU,QAAQ,CAC3B,CAoCA,gBAAgBV,EAAoC,CAClD,OAAO,KAAK,UAAU,gBAAgBA,CAAI,CAC5C,CACF","names":["Account","args","scheme","legacy","Ed25519Account","SingleKeyAccount","privateKey","address","Ed25519PrivateKey","mnemonic","path","publicKey"]}
@@ -0,0 +1,2 @@
1
+ import{a}from"./chunk-TVRJ3M7B.mjs";import{a as i}from"./chunk-FBPNHF54.mjs";import{bytesToHex as o,hexToBytes as l}from"@noble/hashes/utils";var h=(s=>(s.INCORRECT_NUMBER_OF_BYTES="incorrect_number_of_bytes",s.INVALID_HEX_CHARS="invalid_hex_chars",s.TOO_SHORT="too_short",s.TOO_LONG="too_long",s.LEADING_ZERO_X_REQUIRED="leading_zero_x_required",s.LONG_FORM_REQUIRED_UNLESS_SPECIAL="long_form_required_unless_special",s.INVALID_PADDING_ZEROES="INVALID_PADDING_ZEROES",s))(h||{}),r=class r extends a{constructor(t){super();if(t.length!==r.LENGTH)throw new i("AccountAddress data should be exactly 32 bytes long","incorrect_number_of_bytes");this.data=t}isSpecial(){return this.data.slice(0,this.data.length-1).every(t=>t===0)&&this.data[this.data.length-1]<16}toString(){return`0x${this.toStringWithoutPrefix()}`}toStringWithoutPrefix(){let t=o(this.data);return this.isSpecial()&&(t=t[t.length-1]),t}toStringLong(){return`0x${this.toStringLongWithoutPrefix()}`}toStringLongWithoutPrefix(){return o(this.data)}toUint8Array(){return this.data}serialize(t){t.serializeFixedBytes(this.data)}serializeForEntryFunction(t){let e=this.bcsToBytes();t.serializeBytes(e)}serializeForScriptFunction(t){t.serializeU32AsUleb128(3),t.serialize(this)}static deserialize(t){let e=t.deserializeFixedBytes(r.LENGTH);return new r(e)}static fromStringStrict(t){if(!t.startsWith("0x"))throw new i("Hex string must start with a leading 0x.","leading_zero_x_required");let e=r.fromString(t);if(t.length!==r.LONG_STRING_LENGTH+2)if(e.isSpecial()){if(t.length!==3)throw new i(`The given hex string ${t} is a special address not in LONG form, it must be 0x0 to 0xf without padding zeroes.`,"INVALID_PADDING_ZEROES")}else throw new i(`The given hex string ${t} is not a special address, it must be represented as 0x + 64 chars.`,"long_form_required_unless_special");return e}static fromString(t){let e=t;if(t.startsWith("0x")&&(e=t.slice(2)),e.length===0)throw new i("Hex string is too short, must be 1 to 64 chars long, excluding the leading 0x.","too_short");if(e.length>64)throw new i("Hex string is too long, must be 1 to 64 chars long, excluding the leading 0x.","too_long");let n;try{n=l(e.padStart(64,"0"))}catch(d){throw new i(`Hex characters are invalid: ${d?.message}`,"invalid_hex_chars")}return new r(n)}static from(t){return t instanceof r?t:t instanceof Uint8Array?new r(t):r.fromString(t)}static fromStrict(t){return t instanceof r?t:t instanceof Uint8Array?new r(t):r.fromStringStrict(t)}static isValid(t){try{return t.strict?r.fromStrict(t.input):r.from(t.input),{valid:!0}}catch(e){return{valid:!1,invalidReason:e?.invalidReason,invalidReasonMessage:e?.message}}}equals(t){return this.data.length!==t.data.length?!1:this.data.every((e,n)=>e===t.data[n])}};r.LENGTH=32,r.LONG_STRING_LENGTH=64,r.ZERO=r.from("0x0"),r.ONE=r.from("0x1"),r.TWO=r.from("0x2"),r.THREE=r.from("0x3"),r.FOUR=r.from("0x4");var c=r;export{h as a,c as b};
2
+ //# sourceMappingURL=chunk-T23OVRNF.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/accountAddress.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bytesToHex, hexToBytes } from \"@noble/hashes/utils\";\nimport { Serializable, Serializer } from \"../bcs/serializer\";\nimport { Deserializer } from \"../bcs/deserializer\";\nimport { ParsingError, ParsingResult } from \"./common\";\nimport { TransactionArgument } from \"../transactions/instances/transactionArgument\";\nimport { HexInput, ScriptTransactionArgumentVariants } from \"../types\";\n\n/**\n * This enum is used to explain why an address was invalid.\n */\nexport enum AddressInvalidReason {\n INCORRECT_NUMBER_OF_BYTES = \"incorrect_number_of_bytes\",\n INVALID_HEX_CHARS = \"invalid_hex_chars\",\n TOO_SHORT = \"too_short\",\n TOO_LONG = \"too_long\",\n LEADING_ZERO_X_REQUIRED = \"leading_zero_x_required\",\n LONG_FORM_REQUIRED_UNLESS_SPECIAL = \"long_form_required_unless_special\",\n INVALID_PADDING_ZEROES = \"INVALID_PADDING_ZEROES\",\n}\n\nexport type AccountAddressInput = HexInput | AccountAddress;\n\n/**\n * NOTE: Only use this class for account addresses. For other hex data, e.g. transaction\n * hashes, use the Hex class.\n *\n * AccountAddress is used for working with account addresses. Account addresses, when\n * represented as a string, generally look like these examples:\n * - 0x1\n * - 0xaa86fe99004361f747f91342ca13c426ca0cccb0c1217677180c9493bad6ef0c\n *\n * Proper formatting and parsing of account addresses is defined by AIP-40.\n * To learn more about the standard, read the AIP here:\n * https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md.\n *\n * The comments in this class make frequent reference to the LONG and SHORT formats,\n * as well as \"special\" addresses. To learn what these refer to see AIP-40.\n */\nexport class AccountAddress extends Serializable implements TransactionArgument {\n /**\n * This is the internal representation of an account address.\n */\n readonly data: Uint8Array;\n\n /**\n * The number of bytes that make up an account address.\n */\n static readonly LENGTH: number = 32;\n\n /**\n * The length of an address string in LONG form without a leading 0x.\n */\n static readonly LONG_STRING_LENGTH: number = 64;\n\n static ZERO: AccountAddress = AccountAddress.from(\"0x0\");\n\n static ONE: AccountAddress = AccountAddress.from(\"0x1\");\n\n static TWO: AccountAddress = AccountAddress.from(\"0x2\");\n\n static THREE: AccountAddress = AccountAddress.from(\"0x3\");\n\n static FOUR: AccountAddress = AccountAddress.from(\"0x4\");\n\n /**\n * Creates an instance of AccountAddress from a Uint8Array.\n *\n * @param args.data A Uint8Array representing an account address.\n */\n constructor(input: Uint8Array) {\n super();\n if (input.length !== AccountAddress.LENGTH) {\n throw new ParsingError(\n \"AccountAddress data should be exactly 32 bytes long\",\n AddressInvalidReason.INCORRECT_NUMBER_OF_BYTES,\n );\n }\n this.data = input;\n }\n\n /**\n * Returns whether an address is special, where special is defined as 0x0 to 0xf\n * inclusive. In other words, the last byte of the address must be < 0b10000 (16)\n * and every other byte must be zero.\n *\n * For more information on how special addresses are defined see AIP-40:\n * https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md.\n *\n * @returns true if the address is special, false if not.\n */\n isSpecial(): boolean {\n return (\n this.data.slice(0, this.data.length - 1).every((byte) => byte === 0) && this.data[this.data.length - 1] < 0b10000\n );\n }\n\n // ===\n // Methods for representing an instance of AccountAddress as other types.\n // ===\n\n /**\n * Return the AccountAddress as a string as per AIP-40.\n * https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md.\n *\n * In short, it means that special addresses are represented in SHORT form, meaning\n * 0x0 through to 0xf inclusive, and every other address is represented in LONG form,\n * meaning 0x + 64 hex characters.\n *\n * @returns AccountAddress as a string conforming to AIP-40.\n */\n toString(): `0x${string}` {\n return `0x${this.toStringWithoutPrefix()}`;\n }\n\n /**\n * NOTE: Prefer to use `toString` where possible.\n *\n * Return the AccountAddress as a string as per AIP-40 but without the leading 0x.\n *\n * Learn more by reading the docstring of `toString`.\n *\n * @returns AccountAddress as a string conforming to AIP-40 but without the leading 0x.\n */\n toStringWithoutPrefix(): string {\n let hex = bytesToHex(this.data);\n if (this.isSpecial()) {\n hex = hex[hex.length - 1];\n }\n return hex;\n }\n\n /**\n * NOTE: Prefer to use `toString` where possible.\n *\n * Whereas toString will format special addresses (as defined by isSpecial) using the\n * SHORT form (no leading 0s), this format the address in the LONG format\n * unconditionally.\n *\n * This means it will be 0x + 64 hex characters.\n *\n * @returns AccountAddress as a string in LONG form.\n */\n toStringLong(): `0x${string}` {\n return `0x${this.toStringLongWithoutPrefix()}`;\n }\n\n /**\n * NOTE: Prefer to use `toString` where possible.\n *\n * Whereas toString will format special addresses (as defined by isSpecial) using the\n * SHORT form (no leading 0s), this function will include leading zeroes. The string\n * will not have a leading zero.\n *\n * This means it will be 64 hex characters without a leading 0x.\n *\n * @returns AccountAddress as a string in LONG form without a leading 0x.\n */\n toStringLongWithoutPrefix(): string {\n return bytesToHex(this.data);\n }\n\n /**\n * Get the inner hex data. The inner data is already a Uint8Array so no conversion\n * is taking place here, it just returns the inner data.\n *\n * @returns Hex data as Uint8Array\n */\n toUint8Array(): Uint8Array {\n return this.data;\n }\n\n /**\n * Serialize the AccountAddress to a Serializer instance's data buffer.\n * @param serializer The serializer to serialize the AccountAddress to.\n * @returns void\n * @example\n * const serializer = new Serializer();\n * const address = AccountAddress.fromString(\"0x1\");\n * address.serialize(serializer);\n * const bytes = serializer.toUint8Array();\n * // `bytes` is now the BCS-serialized address.\n */\n serialize(serializer: Serializer): void {\n serializer.serializeFixedBytes(this.data);\n }\n\n serializeForEntryFunction(serializer: Serializer): void {\n const bcsBytes = this.bcsToBytes();\n serializer.serializeBytes(bcsBytes);\n }\n\n serializeForScriptFunction(serializer: Serializer): void {\n serializer.serializeU32AsUleb128(ScriptTransactionArgumentVariants.Address);\n serializer.serialize(this);\n }\n\n /**\n * Deserialize an AccountAddress from the byte buffer in a Deserializer instance.\n * @param deserializer The deserializer to deserialize the AccountAddress from.\n * @returns An instance of AccountAddress.\n * @example\n * const bytes = hexToBytes(\"0x0102030405060708091011121314151617181920212223242526272829303132\");\n * const deserializer = new Deserializer(bytes);\n * const address = AccountAddress.deserialize(deserializer);\n * // `address` is now an instance of AccountAddress.\n */\n static deserialize(deserializer: Deserializer): AccountAddress {\n const bytes = deserializer.deserializeFixedBytes(AccountAddress.LENGTH);\n return new AccountAddress(bytes);\n }\n\n // ===\n // Methods for creating an instance of AccountAddress from other types.\n // ===\n\n /**\n * NOTE: This function has strict parsing behavior. For relaxed behavior, please use\n * the `fromString` function.\n *\n * Creates an instance of AccountAddress from a hex string.\n *\n * This function allows only the strictest formats defined by AIP-40. In short this\n * means only the following formats are accepted:\n *\n * - LONG\n * - SHORT for special addresses\n *\n * Where:\n * - LONG is defined as 0x + 64 hex characters.\n * - SHORT for special addresses is 0x0 to 0xf inclusive without padding zeroes.\n *\n * This means the following are not accepted:\n * - SHORT for non-special addresses.\n * - Any address without a leading 0x.\n *\n * Learn more about the different address formats by reading AIP-40:\n * https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md.\n *\n * @param input A hex string representing an account address.\n *\n * @returns An instance of AccountAddress.\n */\n static fromStringStrict(input: string): AccountAddress {\n // Assert the string starts with 0x.\n if (!input.startsWith(\"0x\")) {\n throw new ParsingError(\"Hex string must start with a leading 0x.\", AddressInvalidReason.LEADING_ZERO_X_REQUIRED);\n }\n\n const address = AccountAddress.fromString(input);\n\n // Check if the address is in LONG form. If it is not, this is only allowed for\n // special addresses, in which case we check it is in proper SHORT form.\n if (input.length !== AccountAddress.LONG_STRING_LENGTH + 2) {\n if (!address.isSpecial()) {\n throw new ParsingError(\n `The given hex string ${input} is not a special address, it must be represented as 0x + 64 chars.`,\n AddressInvalidReason.LONG_FORM_REQUIRED_UNLESS_SPECIAL,\n );\n } else if (input.length !== 3) {\n // 0x + one hex char is the only valid SHORT form for special addresses.\n throw new ParsingError(\n // eslint-disable-next-line max-len\n `The given hex string ${input} is a special address not in LONG form, it must be 0x0 to 0xf without padding zeroes.`,\n AddressInvalidReason.INVALID_PADDING_ZEROES,\n );\n }\n }\n\n return address;\n }\n\n /**\n * NOTE: This function has relaxed parsing behavior. For strict behavior, please use\n * the `fromStringStrict` function. Where possible use `fromStringStrict` rather than this\n * function, `fromString` is only provided for backwards compatibility.\n *\n * Creates an instance of AccountAddress from a hex string.\n *\n * This function allows all formats defined by AIP-40. In short this means the\n * following formats are accepted:\n *\n * - LONG, with or without leading 0x\n * - SHORT, with or without leading 0x\n *\n * Where:\n * - LONG is 64 hex characters.\n * - SHORT is 1 to 63 hex characters inclusive.\n * - Padding zeroes are allowed, e.g. 0x0123 is valid.\n *\n * Learn more about the different address formats by reading AIP-40:\n * https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md.\n *\n * @param input A hex string representing an account address.\n *\n * @returns An instance of AccountAddress.\n */\n static fromString(input: string): AccountAddress {\n let parsedInput = input;\n // Remove leading 0x for parsing.\n if (input.startsWith(\"0x\")) {\n parsedInput = input.slice(2);\n }\n\n // Ensure the address string is at least 1 character long.\n if (parsedInput.length === 0) {\n throw new ParsingError(\n \"Hex string is too short, must be 1 to 64 chars long, excluding the leading 0x.\",\n AddressInvalidReason.TOO_SHORT,\n );\n }\n\n // Ensure the address string is not longer than 64 characters.\n if (parsedInput.length > 64) {\n throw new ParsingError(\n \"Hex string is too long, must be 1 to 64 chars long, excluding the leading 0x.\",\n AddressInvalidReason.TOO_LONG,\n );\n }\n\n let addressBytes: Uint8Array;\n try {\n // Pad the address with leading zeroes, so it is 64 chars long and then convert\n // the hex string to bytes. Every two characters in a hex string constitutes a\n // single byte. So a 64 length hex string becomes a 32 byte array.\n addressBytes = hexToBytes(parsedInput.padStart(64, \"0\"));\n } catch (error: any) {\n // At this point the only way this can fail is if the hex string contains\n // invalid characters.\n throw new ParsingError(`Hex characters are invalid: ${error?.message}`, AddressInvalidReason.INVALID_HEX_CHARS);\n }\n\n return new AccountAddress(addressBytes);\n }\n\n /**\n * Convenience method for creating an AccountAddress from all known inputs.\n *\n * This handles, Uint8array, string, and AccountAddress itself\n * @param input\n */\n static from(input: AccountAddressInput): AccountAddress {\n if (input instanceof AccountAddress) {\n return input;\n }\n if (input instanceof Uint8Array) {\n return new AccountAddress(input);\n }\n return AccountAddress.fromString(input);\n }\n\n /**\n * Convenience method for creating an AccountAddress from all known inputs.\n *\n * This handles, Uint8array, string, and AccountAddress itself\n * @param input\n */\n static fromStrict(input: AccountAddressInput): AccountAddress {\n if (input instanceof AccountAddress) {\n return input;\n }\n if (input instanceof Uint8Array) {\n return new AccountAddress(input);\n }\n return AccountAddress.fromStringStrict(input);\n }\n\n // ===\n // Methods for checking validity.\n // ===\n\n /**\n * Check if the string is a valid AccountAddress.\n *\n * @param args.input A hex string representing an account address.\n * @param args.strict If true, use strict parsing behavior. If false, use relaxed parsing behavior.\n *\n * @returns valid = true if the string is valid, valid = false if not. If the string\n * is not valid, invalidReason will be set explaining why it is invalid.\n */\n static isValid(args: { input: AccountAddressInput; strict?: boolean }): ParsingResult<AddressInvalidReason> {\n try {\n if (args.strict) {\n AccountAddress.fromStrict(args.input);\n } else {\n AccountAddress.from(args.input);\n }\n return { valid: true };\n } catch (error: any) {\n return {\n valid: false,\n invalidReason: error?.invalidReason,\n invalidReasonMessage: error?.message,\n };\n }\n }\n\n /**\n * Return whether AccountAddresses are equal. AccountAddresses are considered equal\n * if their underlying byte data is identical.\n *\n * @param other The AccountAddress to compare to.\n * @returns true if the AccountAddresses are equal, false if not.\n */\n equals(other: AccountAddress): boolean {\n if (this.data.length !== other.data.length) return false;\n return this.data.every((value, index) => value === other.data[index]);\n }\n}\n"],"mappings":";;;;;;;;AAGA,SAAS,YAAY,kBAAkB;AAUhC,IAAK,uBAAL,kBAAKA,0BAAL;AACL,EAAAA,sBAAA,+BAA4B;AAC5B,EAAAA,sBAAA,uBAAoB;AACpB,EAAAA,sBAAA,eAAY;AACZ,EAAAA,sBAAA,cAAW;AACX,EAAAA,sBAAA,6BAA0B;AAC1B,EAAAA,sBAAA,uCAAoC;AACpC,EAAAA,sBAAA,4BAAyB;AAPf,SAAAA;AAAA,GAAA;AA4BL,IAAM,kBAAN,MAAM,wBAAuB,aAA4C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA+B9E,YAAY,OAAmB;AAC7B,UAAM;AACN,QAAI,MAAM,WAAW,gBAAe,QAAQ;AAC1C,YAAM,IAAI;AAAA,QACR;AAAA,QACA;AAAA,MACF;AAAA,IACF;AACA,SAAK,OAAO;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,YAAqB;AACnB,WACE,KAAK,KAAK,MAAM,GAAG,KAAK,K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AO,UAAU,UAAU,MAAM,KAAK,KAAK,CAAC;AAAA,EACtE;AACF;AAAA;AAAA;AAAA;AAjXa,gBASK,SAAiB;AAAA;AAAA;AAAA;AATtB,gBAcK,qBAA6B;AAdlC,gBAgBJ,OAAuB,gBAAe,KAAK,KAAK;AAhB5C,gBAkBJ,MAAsB,gBAAe,KAAK,KAAK;AAlB3C,gBAoBJ,MAAsB,gBAAe,KAAK,KAAK;AApB3C,gBAsBJ,QAAwB,gBAAe,KAAK,KAAK;AAtB7C,gBAwBJ,OAAuB,gBAAe,KAAK,KAAK;AAxBlD,IAAM,iBAAN;","names":["AddressInvalidReason"]}
1
+ {"version":3,"sources":["../../src/core/accountAddress.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bytesToHex, hexToBytes } from \"@noble/hashes/utils\";\nimport { Serializable, Serializer } from \"../bcs/serializer\";\nimport { Deserializer } from \"../bcs/deserializer\";\nimport { ParsingError, ParsingResult } from \"./common\";\nimport { TransactionArgument } from \"../transactions/instances/transactionArgument\";\nimport { HexInput, ScriptTransactionArgumentVariants } from \"../types\";\n\n/**\n * This enum is used to explain why an address was invalid.\n */\nexport enum AddressInvalidReason {\n INCORRECT_NUMBER_OF_BYTES = \"incorrect_number_of_bytes\",\n INVALID_HEX_CHARS = \"invalid_hex_chars\",\n TOO_SHORT = \"too_short\",\n TOO_LONG = \"too_long\",\n LEADING_ZERO_X_REQUIRED = \"leading_zero_x_required\",\n LONG_FORM_REQUIRED_UNLESS_SPECIAL = \"long_form_required_unless_special\",\n INVALID_PADDING_ZEROES = \"INVALID_PADDING_ZEROES\",\n}\n\nexport type AccountAddressInput = HexInput | AccountAddress;\n\n/**\n * NOTE: Only use this class for account addresses. For other hex data, e.g. transaction\n * hashes, use the Hex class.\n *\n * AccountAddress is used for working with account addresses. Account addresses, when\n * represented as a string, generally look like these examples:\n * - 0x1\n * - 0xaa86fe99004361f747f91342ca13c426ca0cccb0c1217677180c9493bad6ef0c\n *\n * Proper formatting and parsing of account addresses is defined by AIP-40.\n * To learn more about the standard, read the AIP here:\n * https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md.\n *\n * The comments in this class make frequent reference to the LONG and SHORT formats,\n * as well as \"special\" addresses. To learn what these refer to see AIP-40.\n */\nexport class AccountAddress extends Serializable implements TransactionArgument {\n /**\n * This is the internal representation of an account address.\n */\n readonly data: Uint8Array;\n\n /**\n * The number of bytes that make up an account address.\n */\n static readonly LENGTH: number = 32;\n\n /**\n * The length of an address string in LONG form without a leading 0x.\n */\n static readonly LONG_STRING_LENGTH: number = 64;\n\n static ZERO: AccountAddress = AccountAddress.from(\"0x0\");\n\n static ONE: AccountAddress = AccountAddress.from(\"0x1\");\n\n static TWO: AccountAddress = AccountAddress.from(\"0x2\");\n\n static THREE: AccountAddress = AccountAddress.from(\"0x3\");\n\n static FOUR: AccountAddress = AccountAddress.from(\"0x4\");\n\n /**\n * Creates an instance of AccountAddress from a Uint8Array.\n *\n * @param args.data A Uint8Array representing an account address.\n */\n constructor(input: Uint8Array) {\n super();\n if (input.length !== AccountAddress.LENGTH) {\n throw new ParsingError(\n \"AccountAddress data should be exactly 32 bytes long\",\n AddressInvalidReason.INCORRECT_NUMBER_OF_BYTES,\n );\n }\n this.data = input;\n }\n\n /**\n * Returns whether an address is special, where special is defined as 0x0 to 0xf\n * inclusive. In other words, the last byte of the address must be < 0b10000 (16)\n * and every other byte must be zero.\n *\n * For more information on how special addresses are defined see AIP-40:\n * https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md.\n *\n * @returns true if the address is special, false if not.\n */\n isSpecial(): boolean {\n return (\n this.data.slice(0, this.data.length - 1).every((byte) => byte === 0) && this.data[this.data.length - 1] < 0b10000\n );\n }\n\n // ===\n // Methods for representing an instance of AccountAddress as other types.\n // ===\n\n /**\n * Return the AccountAddress as a string as per AIP-40.\n * https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md.\n *\n * In short, it means that special addresses are represented in SHORT form, meaning\n * 0x0 through to 0xf inclusive, and every other address is represented in LONG form,\n * meaning 0x + 64 hex characters.\n *\n * @returns AccountAddress as a string conforming to AIP-40.\n */\n toString(): `0x${string}` {\n return `0x${this.toStringWithoutPrefix()}`;\n }\n\n /**\n * NOTE: Prefer to use `toString` where possible.\n *\n * Return the AccountAddress as a string as per AIP-40 but without the leading 0x.\n *\n * Learn more by reading the docstring of `toString`.\n *\n * @returns AccountAddress as a string conforming to AIP-40 but without the leading 0x.\n */\n toStringWithoutPrefix(): string {\n let hex = bytesToHex(this.data);\n if (this.isSpecial()) {\n hex = hex[hex.length - 1];\n }\n return hex;\n }\n\n /**\n * NOTE: Prefer to use `toString` where possible.\n *\n * Whereas toString will format special addresses (as defined by isSpecial) using the\n * SHORT form (no leading 0s), this format the address in the LONG format\n * unconditionally.\n *\n * This means it will be 0x + 64 hex characters.\n *\n * @returns AccountAddress as a string in LONG form.\n */\n toStringLong(): `0x${string}` {\n return `0x${this.toStringLongWithoutPrefix()}`;\n }\n\n /**\n * NOTE: Prefer to use `toString` where possible.\n *\n * Whereas toString will format special addresses (as defined by isSpecial) using the\n * SHORT form (no leading 0s), this function will include leading zeroes. The string\n * will not have a leading zero.\n *\n * This means it will be 64 hex characters without a leading 0x.\n *\n * @returns AccountAddress as a string in LONG form without a leading 0x.\n */\n toStringLongWithoutPrefix(): string {\n return bytesToHex(this.data);\n }\n\n /**\n * Get the inner hex data. The inner data is already a Uint8Array so no conversion\n * is taking place here, it just returns the inner data.\n *\n * @returns Hex data as Uint8Array\n */\n toUint8Array(): Uint8Array {\n return this.data;\n }\n\n /**\n * Serialize the AccountAddress to a Serializer instance's data buffer.\n * @param serializer The serializer to serialize the AccountAddress to.\n * @returns void\n * @example\n * const serializer = new Serializer();\n * const address = AccountAddress.fromString(\"0x1\");\n * address.serialize(serializer);\n * const bytes = serializer.toUint8Array();\n * // `bytes` is now the BCS-serialized address.\n */\n serialize(serializer: Serializer): void {\n serializer.serializeFixedBytes(this.data);\n }\n\n serializeForEntryFunction(serializer: Serializer): void {\n const bcsBytes = this.bcsToBytes();\n serializer.serializeBytes(bcsBytes);\n }\n\n serializeForScriptFunction(serializer: Serializer): void {\n serializer.serializeU32AsUleb128(ScriptTransactionArgumentVariants.Address);\n serializer.serialize(this);\n }\n\n /**\n * Deserialize an AccountAddress from the byte buffer in a Deserializer instance.\n * @param deserializer The deserializer to deserialize the AccountAddress from.\n * @returns An instance of AccountAddress.\n * @example\n * const bytes = hexToBytes(\"0x0102030405060708091011121314151617181920212223242526272829303132\");\n * const deserializer = new Deserializer(bytes);\n * const address = AccountAddress.deserialize(deserializer);\n * // `address` is now an instance of AccountAddress.\n */\n static deserialize(deserializer: Deserializer): AccountAddress {\n const bytes = deserializer.deserializeFixedBytes(AccountAddress.LENGTH);\n return new AccountAddress(bytes);\n }\n\n // ===\n // Methods for creating an instance of AccountAddress from other types.\n // ===\n\n /**\n * NOTE: This function has strict parsing behavior. For relaxed behavior, please use\n * the `fromString` function.\n *\n * Creates an instance of AccountAddress from a hex string.\n *\n * This function allows only the strictest formats defined by AIP-40. In short this\n * means only the following formats are accepted:\n *\n * - LONG\n * - SHORT for special addresses\n *\n * Where:\n * - LONG is defined as 0x + 64 hex characters.\n * - SHORT for special addresses is 0x0 to 0xf inclusive without padding zeroes.\n *\n * This means the following are not accepted:\n * - SHORT for non-special addresses.\n * - Any address without a leading 0x.\n *\n * Learn more about the different address formats by reading AIP-40:\n * https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md.\n *\n * @param input A hex string representing an account address.\n *\n * @returns An instance of AccountAddress.\n */\n static fromStringStrict(input: string): AccountAddress {\n // Assert the string starts with 0x.\n if (!input.startsWith(\"0x\")) {\n throw new ParsingError(\"Hex string must start with a leading 0x.\", AddressInvalidReason.LEADING_ZERO_X_REQUIRED);\n }\n\n const address = AccountAddress.fromString(input);\n\n // Check if the address is in LONG form. If it is not, this is only allowed for\n // special addresses, in which case we check it is in proper SHORT form.\n if (input.length !== AccountAddress.LONG_STRING_LENGTH + 2) {\n if (!address.isSpecial()) {\n throw new ParsingError(\n `The given hex string ${input} is not a special address, it must be represented as 0x + 64 chars.`,\n AddressInvalidReason.LONG_FORM_REQUIRED_UNLESS_SPECIAL,\n );\n } else if (input.length !== 3) {\n // 0x + one hex char is the only valid SHORT form for special addresses.\n throw new ParsingError(\n // eslint-disable-next-line max-len\n `The given hex string ${input} is a special address not in LONG form, it must be 0x0 to 0xf without padding zeroes.`,\n AddressInvalidReason.INVALID_PADDING_ZEROES,\n );\n }\n }\n\n return address;\n }\n\n /**\n * NOTE: This function has relaxed parsing behavior. For strict behavior, please use\n * the `fromStringStrict` function. Where possible use `fromStringStrict` rather than this\n * function, `fromString` is only provided for backwards compatibility.\n *\n * Creates an instance of AccountAddress from a hex string.\n *\n * This function allows all formats defined by AIP-40. In short this means the\n * following formats are accepted:\n *\n * - LONG, with or without leading 0x\n * - SHORT, with or without leading 0x\n *\n * Where:\n * - LONG is 64 hex characters.\n * - SHORT is 1 to 63 hex characters inclusive.\n * - Padding zeroes are allowed, e.g. 0x0123 is valid.\n *\n * Learn more about the different address formats by reading AIP-40:\n * https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md.\n *\n * @param input A hex string representing an account address.\n *\n * @returns An instance of AccountAddress.\n */\n static fromString(input: string): AccountAddress {\n let parsedInput = input;\n // Remove leading 0x for parsing.\n if (input.startsWith(\"0x\")) {\n parsedInput = input.slice(2);\n }\n\n // Ensure the address string is at least 1 character long.\n if (parsedInput.length === 0) {\n throw new ParsingError(\n \"Hex string is too short, must be 1 to 64 chars long, excluding the leading 0x.\",\n AddressInvalidReason.TOO_SHORT,\n );\n }\n\n // Ensure the address string is not longer than 64 characters.\n if (parsedInput.length > 64) {\n throw new ParsingError(\n \"Hex string is too long, must be 1 to 64 chars long, excluding the leading 0x.\",\n AddressInvalidReason.TOO_LONG,\n );\n }\n\n let addressBytes: Uint8Array;\n try {\n // Pad the address with leading zeroes, so it is 64 chars long and then convert\n // the hex string to bytes. Every two characters in a hex string constitutes a\n // single byte. So a 64 length hex string becomes a 32 byte array.\n addressBytes = hexToBytes(parsedInput.padStart(64, \"0\"));\n } catch (error: any) {\n // At this point the only way this can fail is if the hex string contains\n // invalid characters.\n throw new ParsingError(`Hex characters are invalid: ${error?.message}`, AddressInvalidReason.INVALID_HEX_CHARS);\n }\n\n return new AccountAddress(addressBytes);\n }\n\n /**\n * Convenience method for creating an AccountAddress from all known inputs.\n *\n * This handles, Uint8array, string, and AccountAddress itself\n * @param input\n */\n static from(input: AccountAddressInput): AccountAddress {\n if (input instanceof AccountAddress) {\n return input;\n }\n if (input instanceof Uint8Array) {\n return new AccountAddress(input);\n }\n return AccountAddress.fromString(input);\n }\n\n /**\n * Convenience method for creating an AccountAddress from all known inputs.\n *\n * This handles, Uint8array, string, and AccountAddress itself\n * @param input\n */\n static fromStrict(input: AccountAddressInput): AccountAddress {\n if (input instanceof AccountAddress) {\n return input;\n }\n if (input instanceof Uint8Array) {\n return new AccountAddress(input);\n }\n return AccountAddress.fromStringStrict(input);\n }\n\n // ===\n // Methods for checking validity.\n // ===\n\n /**\n * Check if the string is a valid AccountAddress.\n *\n * @param args.input A hex string representing an account address.\n * @param args.strict If true, use strict parsing behavior. If false, use relaxed parsing behavior.\n *\n * @returns valid = true if the string is valid, valid = false if not. If the string\n * is not valid, invalidReason will be set explaining why it is invalid.\n */\n static isValid(args: { input: AccountAddressInput; strict?: boolean }): ParsingResult<AddressInvalidReason> {\n try {\n if (args.strict) {\n AccountAddress.fromStrict(args.input);\n } else {\n AccountAddress.from(args.input);\n }\n return { valid: true };\n } catch (error: any) {\n return {\n valid: false,\n invalidReason: error?.invalidReason,\n invalidReasonMessage: error?.message,\n };\n }\n }\n\n /**\n * Return whether AccountAddresses are equal. AccountAddresses are considered equal\n * if their underlying byte data is identical.\n *\n * @param other The AccountAddress to compare to.\n * @returns true if the AccountAddresses are equal, false if not.\n */\n equals(other: AccountAddress): boolean {\n if (this.data.length !== other.data.length) return false;\n return this.data.every((value, index) => value === other.data[index]);\n }\n}\n"],"mappings":"6EAGA,OAAS,cAAAA,EAAY,cAAAC,MAAkB,sBAUhC,IAAKC,OACVA,EAAA,0BAA4B,4BAC5BA,EAAA,kBAAoB,oBACpBA,EAAA,UAAY,YACZA,EAAA,SAAW,WACXA,EAAA,wBAA0B,0BAC1BA,EAAA,kCAAoC,oCACpCA,EAAA,uBAAyB,yBAPfA,OAAA,IA4BCC,EAAN,MAAMA,UAAuBC,CAA4C,CA+B9E,YAAYC,EAAmB,CAC7B,MAAM,EACF,GAAAA,EAAM,SAAWF,EAAe,OAClC,MAAM,IAAIG,EACR,sDACA,2BACF,EAEF,KAAK,KAAOD,CACd,CAYA,WAAqB,CACnB,OACE,KAAK,KAAK,MAAM,EAAG,KAAK,KAAK,OAAS,CAAC,EAAE,MAAOE,GAASA,IAAS,CAAC,GAAK,KAAK,KAAK,KAAK,KAAK,OAAS,CAAC,EAAI,EAE9G,CAgBA,UAA0B,CACxB,MAAO,KAAK,KAAK,sBAAsB,CAAC,EAC1C,CAWA,uBAAgC,CAC9B,IAAIC,EAAMC,EAAW,KAAK,IAAI,EAC9B,OAAI,KAAK,UAAU,IACjBD,EAAMA,EAAIA,EAAI,OAAS,CAAC,GAEnBA,CACT,CAaA,cAA8B,CAC5B,MAAO,KAAK,KAAK,0BAA0B,CAAC,EAC9C,CAaA,2BAAoC,CAClC,OAAOC,EAAW,KAAK,IAAI,CAC7B,CAQA,cAA2B,CACzB,OAAO,KAAK,IACd,CAaA,UAAUC,EAA8B,CACtCA,EAAW,oBAAoB,KAAK,IAAI,CAC1C,CAEA,0BAA0BA,EAA8B,CACtD,IAAMC,EAAW,KAAK,WAAW,EACjCD,EAAW,eAAeC,CAAQ,CACpC,CAEA,2BAA2BD,EAA8B,CACvDA,EAAW,uBAA+D,EAC1EA,EAAW,UAAU,IAAI,CAC3B,CAYA,OAAO,YAAYE,EAA4C,CAC7D,IAAMC,EAAQD,EAAa,sBAA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B,EAAK,KAAK,EAEzB,CAAE,MAAO,EAAK,CACvB,OAASD,EAAY,CACnB,MAAO,CACL,MAAO,GACP,cAAeA,GAAO,cACtB,qBAAsBA,GAAO,OAC/B,CACF,CACF,CASA,OAAOE,EAAgC,CACrC,OAAI,KAAK,KAAK,SAAWA,EAAM,KAAK,OAAe,GAC5C,KAAK,KAAK,MAAM,CAACC,EAAOC,IAAUD,IAAUD,EAAM,KAAKE,CAAK,CAAC,CACtE,CACF,EAjXanB,EASK,OAAiB,GATtBA,EAcK,mBAA6B,GAdlCA,EAgBJ,KAAuBA,EAAe,KAAK,KAAK,EAhB5CA,EAkBJ,IAAsBA,EAAe,KAAK,KAAK,EAlB3CA,EAoBJ,IAAsBA,EAAe,KAAK,KAAK,EApB3CA,EAsBJ,MAAwBA,EAAe,KAAK,KAAK,EAtB7CA,EAwBJ,KAAuBA,EAAe,KAAK,KAAK,EAxBlD,IAAMoB,EAANpB","names":["bytesToHex","hexToBytes","AddressInvalidReason","_AccountAddress","Serializable","input","ParsingError","byte","hex","bytesToHex","serializer","bcsBytes","deserializer","bytes","address","parsedInput","addressBytes","hexToBytes","error","args","other","value","index","AccountAddress"]}
@@ -0,0 +1,2 @@
1
+ import{a as r}from"./chunk-PBDEW4TN.mjs";import{f as t,i as o}from"./chunk-3VGX3TXH.mjs";import{e as n}from"./chunk-YE5B2S5L.mjs";var u={typeParameters:[{constraints:[]}],parameters:[new o,new t]};async function y(e){let{aptosConfig:i,sender:s,recipient:c,amount:p,coinType:a,options:m}=e;return r({aptosConfig:i,sender:s,data:{function:"0x1::aptos_account::transfer_coins",typeArguments:[a??n],functionArguments:[c,p],abi:u},options:m})}export{y as a};
2
+ //# sourceMappingURL=chunk-TBGRYIFW.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/internal/coin.ts"],"sourcesContent":["import { AptosConfig } from \"../api/aptosConfig\";\nimport { AccountAddressInput } from \"../core\";\nimport { EntryFunctionABI, InputGenerateTransactionOptions } from \"../transactions/types\";\nimport { AnyNumber, MoveStructId } from \"../types\";\nimport { APTOS_COIN } from \"../utils/const\";\nimport { generateTransaction } from \"./transactionSubmission\";\nimport { TypeTagAddress, TypeTagU64 } from \"../transactions\";\nimport { SimpleTransaction } from \"../transactions/instances/simpleTransaction\";\n\nconst coinTransferAbi: EntryFunctionABI = {\n typeParameters: [{ constraints: [] }],\n parameters: [new TypeTagAddress(), new TypeTagU64()],\n};\n\nexport async function transferCoinTransaction(args: {\n aptosConfig: AptosConfig;\n sender: AccountAddressInput;\n recipient: AccountAddressInput;\n amount: AnyNumber;\n coinType?: MoveStructId;\n options?: InputGenerateTransactionOptions;\n}): Promise<SimpleTransaction> {\n const { aptosConfig, sender, recipient, amount, coinType, options } = args;\n const coinStructType = coinType ?? APTOS_COIN;\n return generateTransaction({\n aptosConfig,\n sender,\n data: {\n function: \"0x1::aptos_account::transfer_coins\",\n typeArguments: [coinStructType],\n functionArguments: [recipient, amount],\n abi: coinTransferAbi,\n },\n options,\n });\n}\n"],"mappings":";;;;;;;;;;;;AASA,IAAM,kBAAoC;AAAA,EACxC,gBAAgB,CAAC,EAAE,aAAa,CAAC,EAAE,CAAC;AAAA,EACpC,YAAY,CAAC,IAAI,eAAe,GAAG,IAAI,WAAW,CAAC;AACrD;AAEA,eAAsB,wBAAwB,MAOf;AAC7B,QAAM,EAAE,aAAa,QAAQ,WAAW,QAAQ,UAAU,QAAQ,IAAI;AACtE,QAAM,iBAAiB,YAAY;AACnC,SAAO,oBAAoB;AAAA,IACzB;AAAA,IACA;AAAA,IACA,MAAM;AAAA,MACJ,UAAU;AAAA,MACV,eAAe,CAAC,cAAc;AAAA,MAC9B,mBAAmB,CAAC,WAAW,MAAM;AAAA,MACrC,KAAK;AAAA,IACP;AAAA,IACA;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../src/internal/coin.ts"],"sourcesContent":["import { AptosConfig } from \"../api/aptosConfig\";\nimport { AccountAddressInput } from \"../core\";\nimport { EntryFunctionABI, InputGenerateTransactionOptions } from \"../transactions/types\";\nimport { AnyNumber, MoveStructId } from \"../types\";\nimport { APTOS_COIN } from \"../utils/const\";\nimport { generateTransaction } from \"./transactionSubmission\";\nimport { TypeTagAddress, TypeTagU64 } from \"../transactions\";\nimport { SimpleTransaction } from \"../transactions/instances/simpleTransaction\";\n\nconst coinTransferAbi: EntryFunctionABI = {\n typeParameters: [{ constraints: [] }],\n parameters: [new TypeTagAddress(), new TypeTagU64()],\n};\n\nexport async function transferCoinTransaction(args: {\n aptosConfig: AptosConfig;\n sender: AccountAddressInput;\n recipient: AccountAddressInput;\n amount: AnyNumber;\n coinType?: MoveStructId;\n options?: InputGenerateTransactionOptions;\n}): Promise<SimpleTransaction> {\n const { aptosConfig, sender, recipient, amount, coinType, options } = args;\n const coinStructType = coinType ?? APTOS_COIN;\n return generateTransaction({\n aptosConfig,\n sender,\n data: {\n function: \"0x1::aptos_account::transfer_coins\",\n typeArguments: [coinStructType],\n functionArguments: [recipient, amount],\n abi: coinTransferAbi,\n },\n options,\n });\n}\n"],"mappings":"kIASA,IAAMA,EAAoC,CACxC,eAAgB,CAAC,CAAE,YAAa,CAAC,CAAE,CAAC,EACpC,WAAY,CAAC,IAAIC,EAAkB,IAAIC,CAAY,CACrD,EAEA,eAAsBC,EAAwBC,EAOf,CAC7B,GAAM,CAAE,YAAAC,EAAa,OAAAC,EAAQ,UAAAC,EAAW,OAAAC,EAAQ,SAAAC,EAAU,QAAAC,CAAQ,EAAIN,EAEtE,OAAOO,EAAoB,CACzB,YAAAN,EACA,OAAAC,EACA,KAAM,CACJ,SAAU,qCACV,cAAe,CANIG,GAAYG,CAMD,EAC9B,kBAAmB,CAACL,EAAWC,CAAM,EACrC,IAAKR,CACP,EACA,QAAAU,CACF,CAAC,CACH","names":["coinTransferAbi","TypeTagAddress","TypeTagU64","transferCoinTransaction","args","aptosConfig","sender","recipient","amount","coinType","options","generateTransaction","APTOS_COIN"]}
@@ -0,0 +1,2 @@
1
+ import{b as f}from"./chunk-T23OVRNF.mjs";import{a as m,b as a,c as g}from"./chunk-EB7AI4B4.mjs";import{a as i,b as o,c as u,d as s,e as c,f as p,g as y}from"./chunk-6RBUXB5I.mjs";import{a as r}from"./chunk-3FVRXELT.mjs";function M(n){return typeof n=="boolean"}function D(n){return typeof n=="string"}function N(n){return typeof n=="number"}function P(n){return typeof n=="number"||typeof n=="bigint"||typeof n=="string"}function w(n){return n==null}function G(n){return A(n)||x(n)||S(n)||B(n)||U(n)||I(n)||b(n)||T(n)||E(n)||d(n)||n instanceof m||n instanceof g}function A(n){return n instanceof i}function T(n){return n instanceof f}function E(n){return n instanceof a}function d(n){return n instanceof r}function x(n){return n instanceof o}function S(n){return n instanceof u}function B(n){return n instanceof s}function U(n){return n instanceof c}function I(n){return n instanceof p}function b(n){return n instanceof y}function $(n){return"bytecode"in n}function R(n,t){throw new Error(`Type mismatch for argument ${t}, expected '${n}'`)}function W(n){let t=n.params.findIndex(e=>e!=="signer"&&e!=="&signer");return t<0?n.params.length:t}function L(n){let t=n.split("::");if(t.length!==3)throw new Error(`Invalid function ${n}`);let e=t[0],F=t[1],l=t[2];return{moduleAddress:e,moduleName:F,functionName:l}}export{M as a,D as b,N as c,P as d,w as e,G as f,A as g,T as h,E as i,d as j,x as k,S as l,B as m,U as n,I as o,b as p,$ as q,R as r,W as s,L as t};
2
+ //# sourceMappingURL=chunk-TICM455H.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/transactions/transactionBuilder/helpers.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n EntryFunctionArgumentTypes,\n InputGenerateTransactionPayloadData,\n InputGenerateTransactionPayloadDataWithRemoteABI,\n InputScriptData,\n SimpleEntryFunctionArgumentTypes,\n} from \"../types\";\nimport { Bool, FixedBytes, MoveOption, MoveString, MoveVector, U128, U16, U256, U32, U64, U8 } from \"../../bcs\";\nimport { AccountAddress } from \"../../core\";\nimport { MoveFunction, MoveFunctionId } from \"../../types\";\n\nexport function isBool(arg: SimpleEntryFunctionArgumentTypes): arg is boolean {\n return typeof arg === \"boolean\";\n}\n\nexport function isString(arg: any): arg is string {\n return typeof arg === \"string\";\n}\n\nexport function isNumber(arg: SimpleEntryFunctionArgumentTypes): arg is number {\n return typeof arg === \"number\";\n}\n\nexport function isLargeNumber(arg: SimpleEntryFunctionArgumentTypes): arg is number | bigint | string {\n return typeof arg === \"number\" || typeof arg === \"bigint\" || typeof arg === \"string\";\n}\n\nexport function isNull(arg: SimpleEntryFunctionArgumentTypes): arg is null | undefined {\n return arg === null || arg === undefined;\n}\n\nexport function isEncodedEntryFunctionArgument(\n arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes,\n): arg is EntryFunctionArgumentTypes {\n return (\n isBcsBool(arg) ||\n isBcsU8(arg) ||\n isBcsU16(arg) ||\n isBcsU32(arg) ||\n isBcsU64(arg) ||\n isBcsU128(arg) ||\n isBcsU256(arg) ||\n isBcsAddress(arg) ||\n isBcsString(arg) ||\n isBcsFixedBytes(arg) ||\n arg instanceof MoveVector ||\n arg instanceof MoveOption\n );\n}\n\nexport function isBcsBool(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is Bool {\n return arg instanceof Bool;\n}\n\nexport function isBcsAddress(\n arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes,\n): arg is AccountAddress {\n return arg instanceof AccountAddress;\n}\n\nexport function isBcsString(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is MoveString {\n return arg instanceof MoveString;\n}\n\nexport function isBcsFixedBytes(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is FixedBytes {\n return arg instanceof FixedBytes;\n}\n\nexport function isBcsU8(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is U8 {\n return arg instanceof U8;\n}\n\nexport function isBcsU16(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is U16 {\n return arg instanceof U16;\n}\n\nexport function isBcsU32(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is U32 {\n return arg instanceof U32;\n}\n\nexport function isBcsU64(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is U64 {\n return arg instanceof U64;\n}\n\nexport function isBcsU128(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is U128 {\n return arg instanceof U128;\n}\n\nexport function isBcsU256(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is U256 {\n return arg instanceof U256;\n}\n\nexport function isScriptDataInput(\n arg: InputGenerateTransactionPayloadDataWithRemoteABI | InputGenerateTransactionPayloadData,\n): arg is InputScriptData {\n return \"bytecode\" in arg;\n}\n\nexport function throwTypeMismatch(expectedType: string, position: number) {\n throw new Error(`Type mismatch for argument ${position}, expected '${expectedType}'`);\n}\n\n/**\n * Finds first non-signer arg.\n *\n * A function is often defined with a `signer` or `&signer` arguments at the start, which are filled in\n * by signatures, and not by the caller.\n * @param functionAbi\n */\nexport function findFirstNonSignerArg(functionAbi: MoveFunction): number {\n const index = functionAbi.params.findIndex((param) => param !== \"signer\" && param !== \"&signer\");\n if (index < 0) {\n return functionAbi.params.length;\n }\n return index;\n}\n\nexport function getFunctionParts(functionArg: MoveFunctionId) {\n const funcNameParts = functionArg.split(\"::\");\n if (funcNameParts.length !== 3) {\n throw new Error(`Invalid function ${functionArg}`);\n }\n const moduleAddress = funcNameParts[0];\n const moduleName = funcNameParts[1];\n const functionName = funcNameParts[2];\n return { moduleAddress, moduleName, functionName };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAcO,SAAS,OAAO,KAAuD;AAC5E,SAAO,OAAO,QAAQ;AACxB;AAEO,SAAS,SAAS,KAAyB;AAChD,SAAO,OAAO,QAAQ;AACxB;AAEO,SAAS,SAAS,KAAsD;AAC7E,SAAO,OAAO,QAAQ;AACxB;AAEO,SA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A6B;AAC5D,QAAM,gBAAgB,YAAY,MAAM,IAAI;AAC5C,MAAI,cAAc,WAAW,GAAG;AAC9B,UAAM,IAAI,MAAM,oBAAoB,WAAW,EAAE;AAAA,EACnD;AACA,QAAM,gBAAgB,cAAc,CAAC;AACrC,QAAM,aAAa,cAAc,CAAC;AAClC,QAAM,eAAe,cAAc,CAAC;AACpC,SAAO,EAAE,eAAe,YAAY,aAAa;AACnD;","names":[]}
1
+ {"version":3,"sources":["../../src/transactions/transactionBuilder/helpers.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n EntryFunctionArgumentTypes,\n InputGenerateTransactionPayloadData,\n InputGenerateTransactionPayloadDataWithRemoteABI,\n InputScriptData,\n SimpleEntryFunctionArgumentTypes,\n} from \"../types\";\nimport { Bool, FixedBytes, MoveOption, MoveString, MoveVector, U128, U16, U256, U32, U64, U8 } from \"../../bcs\";\nimport { AccountAddress } from \"../../core\";\nimport { MoveFunction, MoveFunctionId } from \"../../types\";\n\nexport function isBool(arg: SimpleEntryFunctionArgumentTypes): arg is boolean {\n return typeof arg === \"boolean\";\n}\n\nexport function isString(arg: any): arg is string {\n return typeof arg === \"string\";\n}\n\nexport function isNumber(arg: SimpleEntryFunctionArgumentTypes): arg is number {\n return typeof arg === \"number\";\n}\n\nexport function isLargeNumber(arg: SimpleEntryFunctionArgumentTypes): arg is number | bigint | string {\n return typeof arg === \"number\" || typeof arg === \"bigint\" || typeof arg === \"string\";\n}\n\nexport function isNull(arg: SimpleEntryFunctionArgumentTypes): arg is null | undefined {\n return arg === null || arg === undefined;\n}\n\nexport function isEncodedEntryFunctionArgument(\n arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes,\n): arg is EntryFunctionArgumentTypes {\n return (\n isBcsBool(arg) ||\n isBcsU8(arg) ||\n isBcsU16(arg) ||\n isBcsU32(arg) ||\n isBcsU64(arg) ||\n isBcsU128(arg) ||\n isBcsU256(arg) ||\n isBcsAddress(arg) ||\n isBcsString(arg) ||\n isBcsFixedBytes(arg) ||\n arg instanceof MoveVector ||\n arg instanceof MoveOption\n );\n}\n\nexport function isBcsBool(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is Bool {\n return arg instanceof Bool;\n}\n\nexport function isBcsAddress(\n arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes,\n): arg is AccountAddress {\n return arg instanceof AccountAddress;\n}\n\nexport function isBcsString(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is MoveString {\n return arg instanceof MoveString;\n}\n\nexport function isBcsFixedBytes(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is FixedBytes {\n return arg instanceof FixedBytes;\n}\n\nexport function isBcsU8(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is U8 {\n return arg instanceof U8;\n}\n\nexport function isBcsU16(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is U16 {\n return arg instanceof U16;\n}\n\nexport function isBcsU32(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is U32 {\n return arg instanceof U32;\n}\n\nexport function isBcsU64(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is U64 {\n return arg instanceof U64;\n}\n\nexport function isBcsU128(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is U128 {\n return arg instanceof U128;\n}\n\nexport function isBcsU256(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is U256 {\n return arg instanceof U256;\n}\n\nexport function isScriptDataInput(\n arg: InputGenerateTransactionPayloadDataWithRemoteABI | InputGenerateTransactionPayloadData,\n): arg is InputScriptData {\n return \"bytecode\" in arg;\n}\n\nexport function throwTypeMismatch(expectedType: string, position: number) {\n throw new Error(`Type mismatch for argument ${position}, expected '${expectedType}'`);\n}\n\n/**\n * Finds first non-signer arg.\n *\n * A function is often defined with a `signer` or `&signer` arguments at the start, which are filled in\n * by signatures, and not by the caller.\n * @param functionAbi\n */\nexport function findFirstNonSignerArg(functionAbi: MoveFunction): number {\n const index = functionAbi.params.findIndex((param) => param !== \"signer\" && param !== \"&signer\");\n if (index < 0) {\n return functionAbi.params.length;\n }\n return index;\n}\n\nexport function getFunctionParts(functionArg: MoveFunctionId) {\n const funcNameParts = functionArg.split(\"::\");\n if (funcNameParts.length !== 3) {\n throw new Error(`Invalid function ${functionArg}`);\n }\n const moduleAddress = funcNameParts[0];\n const moduleName = funcNameParts[1];\n const functionName = funcNameParts[2];\n return { moduleAddress, moduleName, functionName };\n}\n"],"mappings":"4NAcO,SAASA,EAAOC,EAAuD,CAC5E,OAAO,OAAOA,GAAQ,SACxB,CAEO,SAASC,EAASD,EAAyB,CAChD,OAAO,OAAOA,GAAQ,QACxB,CAEO,SAASE,EAASF,EAAsD,CAC7E,OAAO,OAAOA,GAAQ,QACxB,CAEO,SAASG,EAAcH,EAAwE,CACpG,OAAO,OAAOA,GAAQ,UAAY,OAAOA,GAAQ,UAAY,OAAOA,GAAQ,QAC9E,CAEO,SAASI,EAAOJ,EAAgE,CACrF,OAAOA,GAAQ,IACjB,CAEO,SAASK,EACdL,EACmC,CACnC,OACEM,EAAUN,CAAG,GACbO,EAAQP,CAAG,GACXQ,EAASR,CAAG,GACZS,EAAST,CAAG,GACZU,EAASV,CAAG,GACZW,EAAUX,CAAG,GACbY,EAAUZ,CAAG,GACba,EAAab,CAAG,GAChBc,EAAYd,CAAG,GACfe,EAAgBf,CAAG,GACnBA,aAAegB,GACfhB,aAAeiB,CAEnB,CAEO,SAASX,EAAUN,EAAiF,CACzG,OAAOA,aAAekB,CACxB,CAEO,SAASL,EACdb,EACuB,CACvB,OAAOA,aAAemB,CACxB,CAEO,SAASL,EAAYd,EAAuF,CACjH,OAAOA,aAAeoB,CACxB,CAEO,SAASL,EAAgBf,EAAuF,CACrH,OAAOA,aAAeqB,CACxB,CAEO,SAASd,EAAQP,EAA+E,CACrG,OAAOA,aAAesB,CACxB,CAEO,SAASd,EAASR,EAAgF,CACvG,OAAOA,aAAeuB,CACxB,CAEO,SAASd,EAAST,EAAgF,CACvG,OAAOA,aAAewB,CACxB,CAEO,SAASd,EAASV,EAAgF,CACvG,OAAOA,aAAeyB,CACxB,CAEO,SAASd,EAAUX,EAAiF,CACzG,OAAOA,aAAe0B,CACxB,CAEO,SAASd,EAAUZ,EAAiF,CACzG,OAAOA,aAAe2B,CACxB,CAEO,SAASC,EACd5B,EACwB,CACxB,MAAO,aAAcA,CACvB,CAEO,SAAS6B,EAAkBC,EAAsBC,EAAkB,CACxE,MAAM,IAAI,MAAM,8BAA8BA,CAAQ,eAAeD,CAAY,GAAG,CACtF,CASO,SAASE,EAAsBC,EAAmC,CACvE,IAAMC,EAAQD,EAAY,OAAO,UAAWE,GAAUA,IAAU,UAAYA,IAAU,SAAS,EAC/F,OAAID,EAAQ,EACHD,EAAY,OAAO,OAErBC,CACT,CAEO,SAASE,EAAiBC,EAA6B,CAC5D,IAAMC,EAAgBD,EAAY,MAAM,IAAI,EAC5C,GAAIC,EAAc,SAAW,EAC3B,MAAM,IAAI,MAAM,oBAAoBD,CAAW,EAAE,EAEnD,IAAME,EAAgBD,EAAc,CAAC,EAC/BE,EAAaF,EAAc,CAAC,EAC5BG,EAAeH,EAAc,CAAC,EACpC,MAAO,CAAE,cAAAC,EAAe,WAAAC,EAAY,aAAAC,CAAa,CACnD","names":["isBool","arg","isString","isNumber","isLargeNumber","isNull","isEncodedEntryFunctionArgument","isBcsBool","isBcsU8","isBcsU16","isBcsU32","isBcsU64","isBcsU128","isBcsU256","isBcsAddress","isBcsString","isBcsFixedBytes","MoveVector","MoveOption","Bool","AccountAddress","MoveString","FixedBytes","U8","U16","U32","U64","U128","U256","isScriptDataInput","throwTypeMismatch","expectedType","position","findFirstNonSignerArg","functionAbi","index","param","getFunctionParts","functionArg","funcNameParts","moduleAddress","moduleName","functionName"]}
@@ -0,0 +1,2 @@
1
+ import{b as t}from"./chunk-AOCNYMMX.mjs";var o=r=>typeof r=="string"?t.isValid(r).valid?r:Buffer.from(r,"utf8"):r;export{o as a};
2
+ //# sourceMappingURL=chunk-TJDC5PWD.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/crypto/utils.ts"],"sourcesContent":["import { HexInput } from \"../../types\";\nimport { Hex } from \"../hex\";\n\n/**\n * Helper function to convert a message to sign or to verify to a valid message input\n *\n * @param message a message as a string or Uint8Array\n *\n * @returns a valid HexInput - string or Uint8Array\n */\nexport const convertSigningMessage = (message: HexInput): HexInput => {\n // if message is of type string, verify it is a valid Hex string\n if (typeof message === \"string\") {\n const isValid = Hex.isValid(message);\n // If message is not a valid Hex string, convert it into a Buffer\n if (!isValid.valid) {\n return Buffer.from(message, \"utf8\");\n }\n // If message is a valid Hex string, return it\n return message;\n }\n // message is a Uint8Array\n return message;\n};\n"],"mappings":";;;;;AAUO,IAAM,wBAAwB,CAAC,YAAgC;AAEpE,MAAI,OAAO,YAAY,UAAU;AAC/B,UAAM,UAAU,IAAI,QAAQ,OAAO;AAEnC,QAAI,CAAC,QAAQ,OAAO;AAClB,aAAO,OAAO,KAAK,SAAS,MAAM;AAAA,IACpC;AAEA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/core/crypto/utils.ts"],"sourcesContent":["import { HexInput } from \"../../types\";\nimport { Hex } from \"../hex\";\n\n/**\n * Helper function to convert a message to sign or to verify to a valid message input\n *\n * @param message a message as a string or Uint8Array\n *\n * @returns a valid HexInput - string or Uint8Array\n */\nexport const convertSigningMessage = (message: HexInput): HexInput => {\n // if message is of type string, verify it is a valid Hex string\n if (typeof message === \"string\") {\n const isValid = Hex.isValid(message);\n // If message is not a valid Hex string, convert it into a Buffer\n if (!isValid.valid) {\n return Buffer.from(message, \"utf8\");\n }\n // If message is a valid Hex string, return it\n return message;\n }\n // message is a Uint8Array\n return message;\n};\n"],"mappings":"yCAUO,IAAMA,EAAyBC,GAEhC,OAAOA,GAAY,SACLC,EAAI,QAAQD,CAAO,EAEtB,MAINA,EAHE,OAAO,KAAKA,EAAS,MAAM,EAM/BA","names":["convertSigningMessage","message","Hex"]}
@@ -0,0 +1,2 @@
1
+ import{b as c}from"./chunk-AOCNYMMX.mjs";import{a as U,b,c as f,d as l,e as h,f as y}from"./chunk-56CNRT2K.mjs";import{a as s}from"./chunk-FVA2OPG4.mjs";var B=class{bcsToBytes(){let e=new n;return this.serialize(e),e.toUint8Array()}bcsToHex(){let e=this.bcsToBytes();return c.fromHexInput(e)}},n=class{constructor(e=64){if(e<=0)throw new Error("Length needs to be greater than 0");this.buffer=new ArrayBuffer(e),this.offset=0}ensureBufferWillHandleSize(e){for(;this.buffer.byteLength<this.offset+e;){let t=new ArrayBuffer(this.buffer.byteLength*2);new Uint8Array(t).set(new Uint8Array(this.buffer)),this.buffer=t}}appendToBuffer(e){this.ensureBufferWillHandleSize(e.length),new Uint8Array(this.buffer,this.offset).set(e),this.offset+=e.length}serializeWithFunction(e,t,i){this.ensureBufferWillHandleSize(t);let a=new DataView(this.buffer,this.offset);e.apply(a,[0,i,!0]),this.offset+=t}serializeStr(e){let t=new TextEncoder;this.serializeBytes(t.encode(e))}serializeBytes(e){this.serializeU32AsUleb128(e.length),this.appendToBuffer(e)}serializeFixedBytes(e){this.appendToBuffer(e)}serializeBool(e){p(e);let t=e?1:0;this.appendToBuffer(new Uint8Array([t]))}serializeU8(e){this.appendToBuffer(new Uint8Array([e]))}serializeU16(e){this.serializeWithFunction(DataView.prototype.setUint16,2,e)}serializeU32(e){this.serializeWithFunction(DataView.prototype.setUint32,4,e)}serializeU64(e){let t=BigInt(e)&BigInt(f),i=BigInt(e)>>BigInt(32);this.serializeU32(Number(t)),this.serializeU32(Number(i))}serializeU128(e){let t=BigInt(e)&l,i=BigInt(e)>>BigInt(64);this.serializeU64(t),this.serializeU64(i)}serializeU256(e){let t=BigInt(e)&h,i=BigInt(e)>>BigInt(128);this.serializeU128(t),this.serializeU128(i)}serializeU32AsUleb128(e){let t=e,i=[];for(;t>>>7;)i.push(t&127|128),t>>>=7;i.push(t),this.appendToBuffer(new Uint8Array(i))}toUint8Array(){return new Uint8Array(this.buffer).slice(0,this.offset)}serialize(e){e.serialize(this)}serializeVector(e){this.serializeU32AsUleb128(e.length),e.forEach(t=>{t.serialize(this)})}serializeOption(e){e===void 0?this.serializeU32AsUleb128(0):(this.serializeU32AsUleb128(1),e.serialize(this))}serializeOptionStr(e){e===void 0?this.serializeU32AsUleb128(0):(this.serializeU32AsUleb128(1),this.serializeStr(e))}};s([o(0,U)],n.prototype,"serializeU8",1),s([o(0,b)],n.prototype,"serializeU16",1),s([o(0,f)],n.prototype,"serializeU32",1),s([o(BigInt(0),l)],n.prototype,"serializeU64",1),s([o(BigInt(0),h)],n.prototype,"serializeU128",1),s([o(BigInt(0),y)],n.prototype,"serializeU256",1),s([o(0,f)],n.prototype,"serializeU32AsUleb128",1);function p(r){if(typeof r!="boolean")throw new Error(`${r} is not a boolean value`)}var z=(r,e,t)=>`${r} is out of range: [${e}, ${t}]`;function g(r,e,t){let i=BigInt(r);if(i>BigInt(t)||i<BigInt(e))throw new Error(z(r,e,t))}function o(r,e){return(t,i,a)=>{let A=a.value;return a.value=function(u){return g(u,r,e),A.apply(this,[u])},a}}export{B as a,n as b,p as c,z as d,g as e};
2
+ //# sourceMappingURL=chunk-TVRJ3M7B.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/bcs/serializer.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\n/* eslint-disable no-bitwise */\nimport {\n MAX_U128_BIG_INT,\n MAX_U16_NUMBER,\n MAX_U32_NUMBER,\n MAX_U64_BIG_INT,\n MAX_U8_NUMBER,\n MAX_U256_BIG_INT,\n} from \"./consts\";\nimport { Hex } from \"../core/hex\";\nimport { AnyNumber, Uint16, Uint32, Uint8 } from \"../types\";\n\n// This class is intended to be used as a base class for all serializable types.\n// It can be used to facilitate composable serialization of a complex type and\n// in general to serialize a type to its BCS representation.\nexport abstract class Serializable {\n abstract serialize(serializer: Serializer): void;\n\n /**\n * Serializes a `Serializable` value to its BCS representation.\n * This function is the Typescript SDK equivalent of `bcs::to_bytes` in Move.\n * @returns the BCS representation of the Serializable instance as a byte buffer\n */\n bcsToBytes(): Uint8Array {\n const serializer = new Serializer();\n this.serialize(serializer);\n return serializer.toUint8Array();\n }\n\n /**\n * Helper function to get a value's BCS-serialized bytes as a Hex instance.\n * @returns a Hex instance with the BCS-serialized bytes loaded into its underlying Uint8Array\n */\n bcsToHex(): Hex {\n const bcsBytes = this.bcsToBytes();\n return Hex.fromHexInput(bcsBytes);\n }\n}\n\nexport class Serializer {\n private buffer: ArrayBuffer;\n\n private offset: number;\n\n // Constructs a serializer with a buffer of size `length` bytes, 64 bytes by default.\n // `length` must be greater than 0.\n constructor(length: number = 64) {\n if (length <= 0) {\n throw new Error(\"Length needs to be greater than 0\");\n }\n this.buffer = new ArrayBuffer(length);\n this.offset = 0;\n }\n\n private ensureBufferWillHandleSize(bytes: number) {\n while (this.buffer.byteLength < this.offset + bytes) {\n const newBuffer = new ArrayBuffer(this.buffer.byteLength * 2);\n new Uint8Array(newBuffer).set(new Uint8Array(this.buffer));\n this.buffer = newBuffer;\n }\n }\n\n protected appendToBuffer(values: Uint8Array) {\n this.ensureBufferWillHandleSize(values.length);\n new Uint8Array(this.buffer, this.offset).set(values);\n this.offset += values.length;\n }\n\n private serializeWithFunction(\n fn: (byteOffset: number, value: number, littleEndian?: boolean) => void,\n bytesLength: number,\n value: number,\n ) {\n this.ensureBufferWillHandleSize(bytesLength);\n const dv = new DataView(this.buffer, this.offset);\n fn.apply(dv, [0, value, true]);\n this.offset += bytesLength;\n }\n\n /**\n * Serializes a string. UTF8 string is supported.\n *\n * The number of bytes in the string content is serialized first, as a uleb128-encoded u32 integer.\n * Then the string content is serialized as UTF8 encoded bytes.\n *\n * BCS layout for \"string\": string_length | string_content\n * where string_length is a u32 integer encoded as a uleb128 integer, equal to the number of bytes in string_content.\n *\n * @example\n * ```ts\n * const serializer = new Serializer();\n * serializer.serializeStr(\"1234abcd\");\n * assert(serializer.toUint8Array() === new Uint8Array([8, 49, 50, 51, 52, 97, 98, 99, 100]));\n * ```\n */\n serializeStr(value: string) {\n const textEncoder = new TextEncoder();\n this.serializeBytes(textEncoder.encode(value));\n }\n\n /**\n * Serializes an array of bytes.\n *\n * BCS layout for \"bytes\": bytes_length | bytes\n * where bytes_length is a u32 integer encoded as a uleb128 integer, equal to the length of the bytes array.\n */\n serializeBytes(value: Uint8Array) {\n this.serializeU32AsUleb128(value.length);\n this.appendToBuffer(value);\n }\n\n /**\n * Serializes an array of bytes with known length. Therefore, length doesn't need to be\n * serialized to help deserialization.\n *\n * When deserializing, the number of bytes to deserialize needs to be passed in.\n */\n serializeFixedBytes(value: Uint8Array) {\n this.appendToBuffer(value);\n }\n\n /**\n * Serializes a boolean value.\n *\n * BCS layout for \"boolean\": One byte. \"0x01\" for true and \"0x00\" for false.\n */\n serializeBool(value: boolean) {\n ensureBoolean(value);\n const byteValue = value ? 1 : 0;\n this.appendToBuffer(new Uint8Array([byteValue]));\n }\n\n /**\n * Serializes a uint8 number.\n *\n * BCS layout for \"uint8\": One byte. Binary format in little-endian representation.\n */\n @checkNumberRange(0, MAX_U8_NUMBER)\n serializeU8(value: Uint8) {\n this.appendToBuffer(new Uint8Array([value]));\n }\n\n /**\n * Serializes a uint16 number.\n *\n * BCS layout for \"uint16\": Two bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const serializer = new Serializer();\n * serializer.serializeU16(4660);\n * assert(serializer.toUint8Array() === new Uint8Array([0x34, 0x12]));\n * ```\n */\n @checkNumberRange(0, MAX_U16_NUMBER)\n serializeU16(value: Uint16) {\n this.serializeWithFunction(DataView.prototype.setUint16, 2, value);\n }\n\n /**\n * Serializes a uint32 number.\n *\n * BCS layout for \"uint32\": Four bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const serializer = new Serializer();\n * serializer.serializeU32(305419896);\n * assert(serializer.toUint8Array() === new Uint8Array([0x78, 0x56, 0x34, 0x12]));\n * ```\n */\n @checkNumberRange(0, MAX_U32_NUMBER)\n serializeU32(value: Uint32) {\n this.serializeWithFunction(DataView.prototype.setUint32, 4, value);\n }\n\n /**\n * Serializes a uint64 number.\n *\n * BCS layout for \"uint64\": Eight bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const serializer = new Serializer();\n * serializer.serializeU64(1311768467750121216);\n * assert(serializer.toUint8Array() === new Uint8Array([0x00, 0xEF, 0xCD, 0xAB, 0x78, 0x56, 0x34, 0x12]));\n * ```\n */\n @checkNumberRange(BigInt(0), MAX_U64_BIG_INT)\n serializeU64(value: AnyNumber) {\n const low = BigInt(value) & BigInt(MAX_U32_NUMBER);\n const high = BigInt(value) >> BigInt(32);\n\n // write little endian number\n this.serializeU32(Number(low));\n this.serializeU32(Number(high));\n }\n\n /**\n * Serializes a uint128 number.\n *\n * BCS layout for \"uint128\": Sixteen bytes. Binary format in little-endian representation.\n */\n @checkNumberRange(BigInt(0), MAX_U128_BIG_INT)\n serializeU128(value: AnyNumber) {\n const low = BigInt(value) & MAX_U64_BIG_INT;\n const high = BigInt(value) >> BigInt(64);\n\n // write little endian number\n this.serializeU64(low);\n this.serializeU64(high);\n }\n\n /**\n * Serializes a uint256 number.\n *\n * BCS layout for \"uint256\": Sixteen bytes. Binary format in little-endian representation.\n */\n @checkNumberRange(BigInt(0), MAX_U256_BIG_INT)\n serializeU256(value: AnyNumber) {\n const low = BigInt(value) & MAX_U128_BIG_INT;\n const high = BigInt(value) >> BigInt(128);\n\n // write little endian number\n this.serializeU128(low);\n this.serializeU128(high);\n }\n\n /**\n * Serializes a uint32 number with uleb128.\n *\n * BCS uses uleb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values\n */\n @checkNumberRange(0, MAX_U32_NUMBER)\n serializeU32AsUleb128(val: Uint32) {\n let value = val;\n const valueArray = [];\n while (value >>> 7 !== 0) {\n valueArray.push((value & 0x7f) | 0x80);\n value >>>= 7;\n }\n valueArray.push(value);\n this.appendToBuffer(new Uint8Array(valueArray));\n }\n\n /**\n * Returns the buffered bytes\n */\n toUint8Array(): Uint8Array {\n return new Uint8Array(this.buffer).slice(0, this.offset);\n }\n\n /**\n * Serializes a `Serializable` value, facilitating composable serialization.\n *\n * @param value The Serializable value to serialize\n *\n * @example\n * // Define the MoveStruct class that implements the Serializable interface\n * class MoveStruct extends Serializable {\n * constructor(\n * public creatorAddress: AccountAddress, // where AccountAddress extends Serializable\n * public collectionName: string,\n * public tokenName: string\n * ) {}\n *\n * serialize(serializer: Serializer): void {\n * serializer.serialize(this.creatorAddress); // Composable serialization of another Serializable object\n * serializer.serializeStr(this.collectionName);\n * serializer.serializeStr(this.tokenName);\n * }\n * }\n *\n * // Construct a MoveStruct\n * const moveStruct = new MoveStruct(new AccountAddress(...), \"MyCollection\", \"TokenA\");\n *\n * // Serialize a string, a u64 number, and a MoveStruct instance.\n * const serializer = new Serializer();\n * serializer.serializeStr(\"ExampleString\");\n * serializer.serializeU64(12345678);\n * serializer.serialize(moveStruct);\n *\n * // Get the bytes from the Serializer instance\n * const serializedBytes = serializer.toUint8Array();\n *\n * @returns the serializer instance\n */\n serialize<T extends Serializable>(value: T): void {\n // NOTE: The `serialize` method called by `value` is defined in `value`'s\n // Serializable interface, not the one defined in this class.\n value.serialize(this);\n }\n\n /**\n * Serializes an array of BCS Serializable values to a serializer instance.\n * Note that this does not return anything. The bytes are added to the serializer instance's byte buffer.\n *\n * @param values The array of BCS Serializable values\n * @example\n * const addresses = new Array<AccountAddress>(\n * AccountAddress.from(\"0x1\"),\n * AccountAddress.from(\"0x2\"),\n * AccountAddress.from(\"0xa\"),\n * AccountAddress.from(\"0xb\"),\n * );\n * const serializer = new Serializer();\n * serializer.serializeVector(addresses);\n * const serializedBytes = serializer.toUint8Array();\n * // serializedBytes is now the BCS-serialized bytes\n * // The equivalent value in Move would be:\n * // `bcs::to_bytes(&vector<address> [@0x1, @0x2, @0xa, @0xb])`;\n */\n serializeVector<T extends Serializable>(values: Array<T>): void {\n this.serializeU32AsUleb128(values.length);\n values.forEach((item) => {\n item.serialize(this);\n });\n }\n\n serializeOption<T extends Serializable>(value?: T): void {\n if (value === undefined) {\n this.serializeU32AsUleb128(0);\n } else {\n this.serializeU32AsUleb128(1);\n value.serialize(this);\n }\n }\n\n serializeOptionStr(value?: string): void {\n if (value === undefined) {\n this.serializeU32AsUleb128(0);\n } else {\n this.serializeU32AsUleb128(1);\n this.serializeStr(value);\n }\n }\n}\n\nexport function ensureBoolean(value: unknown): asserts value is boolean {\n if (typeof value !== \"boolean\") {\n throw new Error(`${value} is not a boolean value`);\n }\n}\n\nexport const outOfRangeErrorMessage = (value: AnyNumber, min: AnyNumber, max: AnyNumber) =>\n `${value} is out of range: [${min}, ${max}]`;\n\nexport function validateNumberInRange<T extends AnyNumber>(value: T, minValue: T, maxValue: T) {\n const valueBigInt = BigInt(value);\n if (valueBigInt > BigInt(maxValue) || valueBigInt < BigInt(minValue)) {\n throw new Error(outOfRangeErrorMessage(value, minValue, maxValue));\n }\n}\n\n/**\n * A decorator to ensure the input argument for a function is within a range.\n * @param minValue The input argument must be >= minValue\n * @param maxValue The input argument must be <= maxValue\n */\nfunction checkNumberRange<T extends AnyNumber>(minValue: T, maxValue: T) {\n return (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => {\n const childFunction = descriptor.value;\n // eslint-disable-next-line no-param-reassign\n descriptor.value = function deco(value: AnyNumber) {\n validateNumberInRange(value, minValue, maxValue);\n return childFunction.apply(this, [value]);\n };\n\n return descriptor;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkBO,IAAe,eAAf,MAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQjC,aAAyB;AACvB,UAAM,aAAa,IAAI,WAAW;AAClC,SAAK,UAAU,UAAU;AACzB,WAAO,WAAW,a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iB,GAAG,cAAc;AAAA,GAlHxB,WAmHX;AAgBA;AAAA,EADC,iBAAiB,GAAG,cAAc;AAAA,GAlIxB,WAmIX;AAgBA;AAAA,EADC,iBAAiB,OAAO,CAAC,GAAG,eAAe;AAAA,GAlJjC,WAmJX;AAeA;AAAA,EADC,iBAAiB,OAAO,CAAC,GAAG,gBAAgB;AAAA,GAjKlC,WAkKX;AAeA;AAAA,EADC,iBAAiB,OAAO,CAAC,GAAG,gBAAgB;AAAA,GAhLlC,WAiLX;AAeA;AAAA,EADC,iBAAiB,GAAG,cAAc;AAAA,GA/LxB,WAgMX;AAwGK,SAAS,cAAc,OAA0C;AACtE,MAAI,OAAO,UAAU,WAAW;AAC9B,UAAM,IAAI,MAAM,GAAG,KAAK,yBAAyB;AAAA,EACnD;AACF;AAEO,IAAM,yBAAyB,CAAC,OAAkB,KAAgB,QACvE,GAAG,KAAK,sBAAsB,GAAG,KAAK,GAAG;AAEpC,SAAS,sBAA2C,OAAU,UAAa,UAAa;AAC7F,QAAM,cAAc,OAAO,KAAK;AAChC,MAAI,cAAc,OAAO,QAAQ,KAAK,cAAc,OAAO,QAAQ,GAAG;AACpE,UAAM,IAAI,MAAM,uBAAuB,OAAO,UAAU,QAAQ,CAAC;AAAA,EACnE;AACF;AAOA,SAAS,iBAAsC,UAAa,UAAa;AACvE,SAAO,CAAC,QAAiB,aAAqB,eAAmC;AAC/E,UAAM,gBAAgB,WAAW;AAEjC,eAAW,QAAQ,SAAS,KAAK,OAAkB;AACjD,4BAAsB,OAAO,UAAU,QAAQ;AAC/C,aAAO,cAAc,MAAM,MAAM,CAAC,KAAK,CAAC;AAAA,IAC1C;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/bcs/serializer.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\n/* eslint-disable no-bitwise */\nimport {\n MAX_U128_BIG_INT,\n MAX_U16_NUMBER,\n MAX_U32_NUMBER,\n MAX_U64_BIG_INT,\n MAX_U8_NUMBER,\n MAX_U256_BIG_INT,\n} from \"./consts\";\nimport { Hex } from \"../core/hex\";\nimport { AnyNumber, Uint16, Uint32, Uint8 } from \"../types\";\n\n// This class is intended to be used as a base class for all serializable types.\n// It can be used to facilitate composable serialization of a complex type and\n// in general to serialize a type to its BCS representation.\nexport abstract class Serializable {\n abstract serialize(serializer: Serializer): void;\n\n /**\n * Serializes a `Serializable` value to its BCS representation.\n * This function is the Typescript SDK equivalent of `bcs::to_bytes` in Move.\n * @returns the BCS representation of the Serializable instance as a byte buffer\n */\n bcsToBytes(): Uint8Array {\n const serializer = new Serializer();\n this.serialize(serializer);\n return serializer.toUint8Array();\n }\n\n /**\n * Helper function to get a value's BCS-serialized bytes as a Hex instance.\n * @returns a Hex instance with the BCS-serialized bytes loaded into its underlying Uint8Array\n */\n bcsToHex(): Hex {\n const bcsBytes = this.bcsToBytes();\n return Hex.fromHexInput(bcsBytes);\n }\n}\n\nexport class Serializer {\n private buffer: ArrayBuffer;\n\n private offset: number;\n\n // Constructs a serializer with a buffer of size `length` bytes, 64 bytes by default.\n // `length` must be greater than 0.\n constructor(length: number = 64) {\n if (length <= 0) {\n throw new Error(\"Length needs to be greater than 0\");\n }\n this.buffer = new ArrayBuffer(length);\n this.offset = 0;\n }\n\n private ensureBufferWillHandleSize(bytes: number) {\n while (this.buffer.byteLength < this.offset + bytes) {\n const newBuffer = new ArrayBuffer(this.buffer.byteLength * 2);\n new Uint8Array(newBuffer).set(new Uint8Array(this.buffer));\n this.buffer = newBuffer;\n }\n }\n\n protected appendToBuffer(values: Uint8Array) {\n this.ensureBufferWillHandleSize(values.length);\n new Uint8Array(this.buffer, this.offset).set(values);\n this.offset += values.length;\n }\n\n private serializeWithFunction(\n fn: (byteOffset: number, value: number, littleEndian?: boolean) => void,\n bytesLength: number,\n value: number,\n ) {\n this.ensureBufferWillHandleSize(bytesLength);\n const dv = new DataView(this.buffer, this.offset);\n fn.apply(dv, [0, value, true]);\n this.offset += bytesLength;\n }\n\n /**\n * Serializes a string. UTF8 string is supported.\n *\n * The number of bytes in the string content is serialized first, as a uleb128-encoded u32 integer.\n * Then the string content is serialized as UTF8 encoded bytes.\n *\n * BCS layout for \"string\": string_length | string_content\n * where string_length is a u32 integer encoded as a uleb128 integer, equal to the number of bytes in string_content.\n *\n * @example\n * ```ts\n * const serializer = new Serializer();\n * serializer.serializeStr(\"1234abcd\");\n * assert(serializer.toUint8Array() === new Uint8Array([8, 49, 50, 51, 52, 97, 98, 99, 100]));\n * ```\n */\n serializeStr(value: string) {\n const textEncoder = new TextEncoder();\n this.serializeBytes(textEncoder.encode(value));\n }\n\n /**\n * Serializes an array of bytes.\n *\n * BCS layout for \"bytes\": bytes_length | bytes\n * where bytes_length is a u32 integer encoded as a uleb128 integer, equal to the length of the bytes array.\n */\n serializeBytes(value: Uint8Array) {\n this.serializeU32AsUleb128(value.length);\n this.appendToBuffer(value);\n }\n\n /**\n * Serializes an array of bytes with known length. Therefore, length doesn't need to be\n * serialized to help deserialization.\n *\n * When deserializing, the number of bytes to deserialize needs to be passed in.\n */\n serializeFixedBytes(value: Uint8Array) {\n this.appendToBuffer(value);\n }\n\n /**\n * Serializes a boolean value.\n *\n * BCS layout for \"boolean\": One byte. \"0x01\" for true and \"0x00\" for false.\n */\n serializeBool(value: boolean) {\n ensureBoolean(value);\n const byteValue = value ? 1 : 0;\n this.appendToBuffer(new Uint8Array([byteValue]));\n }\n\n /**\n * Serializes a uint8 number.\n *\n * BCS layout for \"uint8\": One byte. Binary format in little-endian representation.\n */\n @checkNumberRange(0, MAX_U8_NUMBER)\n serializeU8(value: Uint8) {\n this.appendToBuffer(new Uint8Array([value]));\n }\n\n /**\n * Serializes a uint16 number.\n *\n * BCS layout for \"uint16\": Two bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const serializer = new Serializer();\n * serializer.serializeU16(4660);\n * assert(serializer.toUint8Array() === new Uint8Array([0x34, 0x12]));\n * ```\n */\n @checkNumberRange(0, MAX_U16_NUMBER)\n serializeU16(value: Uint16) {\n this.serializeWithFunction(DataView.prototype.setUint16, 2, value);\n }\n\n /**\n * Serializes a uint32 number.\n *\n * BCS layout for \"uint32\": Four bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const serializer = new Serializer();\n * serializer.serializeU32(305419896);\n * assert(serializer.toUint8Array() === new Uint8Array([0x78, 0x56, 0x34, 0x12]));\n * ```\n */\n @checkNumberRange(0, MAX_U32_NUMBER)\n serializeU32(value: Uint32) {\n this.serializeWithFunction(DataView.prototype.setUint32, 4, value);\n }\n\n /**\n * Serializes a uint64 number.\n *\n * BCS layout for \"uint64\": Eight bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const serializer = new Serializer();\n * serializer.serializeU64(1311768467750121216);\n * assert(serializer.toUint8Array() === new Uint8Array([0x00, 0xEF, 0xCD, 0xAB, 0x78, 0x56, 0x34, 0x12]));\n * ```\n */\n @checkNumberRange(BigInt(0), MAX_U64_BIG_INT)\n serializeU64(value: AnyNumber) {\n const low = BigInt(value) & BigInt(MAX_U32_NUMBER);\n const high = BigInt(value) >> BigInt(32);\n\n // write little endian number\n this.serializeU32(Number(low));\n this.serializeU32(Number(high));\n }\n\n /**\n * Serializes a uint128 number.\n *\n * BCS layout for \"uint128\": Sixteen bytes. Binary format in little-endian representation.\n */\n @checkNumberRange(BigInt(0), MAX_U128_BIG_INT)\n serializeU128(value: AnyNumber) {\n const low = BigInt(value) & MAX_U64_BIG_INT;\n const high = BigInt(value) >> BigInt(64);\n\n // write little endian number\n this.serializeU64(low);\n this.serializeU64(high);\n }\n\n /**\n * Serializes a uint256 number.\n *\n * BCS layout for \"uint256\": Sixteen bytes. Binary format in little-endian representation.\n */\n @checkNumberRange(BigInt(0), MAX_U256_BIG_INT)\n serializeU256(value: AnyNumber) {\n const low = BigInt(value) & MAX_U128_BIG_INT;\n const high = BigInt(value) >> BigInt(128);\n\n // write little endian number\n this.serializeU128(low);\n this.serializeU128(high);\n }\n\n /**\n * Serializes a uint32 number with uleb128.\n *\n * BCS uses uleb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values\n */\n @checkNumberRange(0, MAX_U32_NUMBER)\n serializeU32AsUleb128(val: Uint32) {\n let value = val;\n const valueArray = [];\n while (value >>> 7 !== 0) {\n valueArray.push((value & 0x7f) | 0x80);\n value >>>= 7;\n }\n valueArray.push(value);\n this.appendToBuffer(new Uint8Array(valueArray));\n }\n\n /**\n * Returns the buffered bytes\n */\n toUint8Array(): Uint8Array {\n return new Uint8Array(this.buffer).slice(0, this.offset);\n }\n\n /**\n * Serializes a `Serializable` value, facilitating composable serialization.\n *\n * @param value The Serializable value to serialize\n *\n * @example\n * // Define the MoveStruct class that implements the Serializable interface\n * class MoveStruct extends Serializable {\n * constructor(\n * public creatorAddress: AccountAddress, // where AccountAddress extends Serializable\n * public collectionName: string,\n * public tokenName: string\n * ) {}\n *\n * serialize(serializer: Serializer): void {\n * serializer.serialize(this.creatorAddress); // Composable serialization of another Serializable object\n * serializer.serializeStr(this.collectionName);\n * serializer.serializeStr(this.tokenName);\n * }\n * }\n *\n * // Construct a MoveStruct\n * const moveStruct = new MoveStruct(new AccountAddress(...), \"MyCollection\", \"TokenA\");\n *\n * // Serialize a string, a u64 number, and a MoveStruct instance.\n * const serializer = new Serializer();\n * serializer.serializeStr(\"ExampleString\");\n * serializer.serializeU64(12345678);\n * serializer.serialize(moveStruct);\n *\n * // Get the bytes from the Serializer instance\n * const serializedBytes = serializer.toUint8Array();\n *\n * @returns the serializer instance\n */\n serialize<T extends Serializable>(value: T): void {\n // NOTE: The `serialize` method called by `value` is defined in `value`'s\n // Serializable interface, not the one defined in this class.\n value.serialize(this);\n }\n\n /**\n * Serializes an array of BCS Serializable values to a serializer instance.\n * Note that this does not return anything. The bytes are added to the serializer instance's byte buffer.\n *\n * @param values The array of BCS Serializable values\n * @example\n * const addresses = new Array<AccountAddress>(\n * AccountAddress.from(\"0x1\"),\n * AccountAddress.from(\"0x2\"),\n * AccountAddress.from(\"0xa\"),\n * AccountAddress.from(\"0xb\"),\n * );\n * const serializer = new Serializer();\n * serializer.serializeVector(addresses);\n * const serializedBytes = serializer.toUint8Array();\n * // serializedBytes is now the BCS-serialized bytes\n * // The equivalent value in Move would be:\n * // `bcs::to_bytes(&vector<address> [@0x1, @0x2, @0xa, @0xb])`;\n */\n serializeVector<T extends Serializable>(values: Array<T>): void {\n this.serializeU32AsUleb128(values.length);\n values.forEach((item) => {\n item.serialize(this);\n });\n }\n\n serializeOption<T extends Serializable>(value?: T): void {\n if (value === undefined) {\n this.serializeU32AsUleb128(0);\n } else {\n this.serializeU32AsUleb128(1);\n value.serialize(this);\n }\n }\n\n serializeOptionStr(value?: string): void {\n if (value === undefined) {\n this.serializeU32AsUleb128(0);\n } else {\n this.serializeU32AsUleb128(1);\n this.serializeStr(value);\n }\n }\n}\n\nexport function ensureBoolean(value: unknown): asserts value is boolean {\n if (typeof value !== \"boolean\") {\n throw new Error(`${value} is not a boolean value`);\n }\n}\n\nexport const outOfRangeErrorMessage = (value: AnyNumber, min: AnyNumber, max: AnyNumber) =>\n `${value} is out of range: [${min}, ${max}]`;\n\nexport function validateNumberInRange<T extends AnyNumber>(value: T, minValue: T, maxValue: T) {\n const valueBigInt = BigInt(value);\n if (valueBigInt > BigInt(maxValue) || valueBigInt < BigInt(minValue)) {\n throw new Error(outOfRangeErrorMessage(value, minValue, maxValue));\n }\n}\n\n/**\n * A decorator to ensure the input argument for a function is within a range.\n * @param minValue The input argument must be >= minValue\n * @param maxValue The input argument must be <= maxValue\n */\nfunction checkNumberRange<T extends AnyNumber>(minValue: T, maxValue: T) {\n return (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => {\n const childFunction = descriptor.value;\n // eslint-disable-next-line no-param-reassign\n descriptor.value = function deco(value: AnyNumber) {\n validateNumberInRange(value, minValue, maxValue);\n return childFunction.apply(this, [value]);\n };\n\n return descriptor;\n };\n}\n"],"mappings":"yJAkBO,IAAeA,E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EAAaC,EAAa,CACvE,MAAO,CAACE,EAAiBC,EAAqBC,IAAmC,CAC/E,IAAMC,EAAgBD,EAAW,MAEjC,OAAAA,EAAW,MAAQ,SAAc3B,EAAkB,CACjD,OAAAqB,EAAsBrB,EAAOsB,EAAUC,CAAQ,EACxCK,EAAc,MAAM,KAAM,CAAC5B,CAAK,CAAC,CAC1C,EAEO2B,CACT,CACF","names":["Serializable","serializer","Serializer","bcsBytes","Hex","length","bytes","newBuffer","values","fn","bytesLength","value","dv","textEncoder","ensureBoolean","byteValue","low","MAX_U32_NUMBER","high","MAX_U64_BIG_INT","MAX_U128_BIG_INT","val","valueArray","item","__decorateClass","checkNumberRange","MAX_U8_NUMBER","MAX_U16_NUMBER","MAX_U256_BIG_INT","outOfRangeErrorMessage","min","max","validateNumberInRange","minValue","maxValue","valueBigInt","target","propertyKey","descriptor","childFunction"]}
@@ -0,0 +1,2 @@
1
+ var i=class{constructor(){this.queue=[];this.pendingDequeue=[];this.cancelled=!1}enqueue(e){if(this.cancelled=!1,this.pendingDequeue.length>0){this.pendingDequeue.shift()?.resolve(e);return}this.queue.push(e)}async dequeue(){return this.queue.length>0?Promise.resolve(this.queue.shift()):new Promise((e,u)=>{this.pendingDequeue.push({resolve:e,reject:u})})}isEmpty(){return this.queue.length===0}cancel(){this.cancelled=!0,this.pendingDequeue.forEach(async({reject:e})=>{e(new n("Task cancelled"))}),this.pendingDequeue=[],this.queue.length=0}isCancelled(){return this.cancelled}pendingDequeueLength(){return this.pendingDequeue.length}},n=class extends Error{};export{i as a,n as b};
2
+ //# sourceMappingURL=chunk-U6Z4FNB7.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/transactions/management/asyncQueue.ts"],"sourcesContent":["/**\n * The AsyncQueue class is an async-aware data structure that provides a queue-like\n * behavior for managing asynchronous tasks or operations.\n * It allows to enqueue items and dequeue them asynchronously.\n * This is not thread-safe but it is async concurrency safe and\n * it does not guarantee ordering for those that call into and await on enqueue.\n */\n\ninterface PendingDequeue<T> {\n resolve: (value: T) => void;\n reject: (reason?: AsyncQueueCancelledError) => void;\n}\n\nexport class AsyncQueue<T> {\n readonly queue: T[] = [];\n\n // The pendingDequeue is used to handle the resolution of promises when items are enqueued and dequeued.\n private pendingDequeue: PendingDequeue<T>[] = [];\n\n private cancelled: boolean = false;\n\n /**\n * The enqueue method adds an item to the queue. If there are pending dequeued promises,\n * in the pendingDequeue, it resolves the oldest promise with the enqueued item immediately.\n * Otherwise, it adds the item to the queue.\n *\n * @param item T\n */\n enqueue(item: T): void {\n this.cancelled = false;\n\n if (this.pendingDequeue.length > 0) {\n const promise = this.pendingDequeue.shift();\n\n promise?.resolve(item);\n\n return;\n }\n\n this.queue.push(item);\n }\n\n /**\n * The dequeue method returns a promise that resolves to the next item in the queue.\n * If the queue is not empty, it resolves the promise immediately with the next item.\n * Otherwise, it creates a new promise. The promise's resolve function is stored\n * in the pendingDequeue with a unique counter value as the key.\n * The newly created promise is then returned, and it will be resolved later when an item is enqueued.\n *\n * @returns Promise<T>\n */\n async dequeue(): Promise<T> {\n if (this.queue.length > 0) {\n return Promise.resolve(this.queue.shift()!);\n }\n\n return new Promise<T>((resolve, reject) => {\n this.pendingDequeue.push({ resolve, reject });\n });\n }\n\n /**\n * The isEmpty method returns whether the queue is empty or not.\n *\n * @returns boolean\n */\n isEmpty(): boolean {\n return this.queue.length === 0;\n }\n\n /**\n * The cancel method cancels all pending promises in the queue.\n * It rejects the promises with a AsyncQueueCancelledError error,\n * ensuring that any awaiting code can handle the cancellation appropriately.\n */\n cancel(): void {\n this.cancelled = true;\n\n this.pendingDequeue.forEach(async ({ reject }) => {\n reject(new AsyncQueueCancelledError(\"Task cancelled\"));\n });\n\n this.pendingDequeue = [];\n\n this.queue.length = 0;\n }\n\n /**\n * The isCancelled method returns whether the queue is cancelled or not.\n *\n * @returns boolean\n */\n isCancelled(): boolean {\n return this.cancelled;\n }\n\n /**\n * The pendingDequeueLength method returns the length of the pendingDequeue.\n *\n * @returns number\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K,eAAe;AAAA,EAC7B;AACF;AAEO,IAAM,2BAAN,cAAuC,MAAM;AAAC;","names":[]}
1
+ {"version":3,"sources":["../../src/transactions/management/asyncQueue.ts"],"sourcesContent":["/**\n * The AsyncQueue class is an async-aware data structure that provides a queue-like\n * behavior for managing asynchronous tasks or operations.\n * It allows to enqueue items and dequeue them asynchronously.\n * This is not thread-safe but it is async concurrency safe and\n * it does not guarantee ordering for those that call into and await on enqueue.\n */\n\ninterface PendingDequeue<T> {\n resolve: (value: T) => void;\n reject: (reason?: AsyncQueueCancelledError) => void;\n}\n\nexport class AsyncQueue<T> {\n readonly queue: T[] = [];\n\n // The pendingDequeue is used to handle the resolution of promises when items are enqueued and dequeued.\n private pendingDequeue: PendingDequeue<T>[] = [];\n\n private cancelled: boolean = false;\n\n /**\n * The enqueue method adds an item to the queue. If there are pending dequeued promises,\n * in the pendingDequeue, it resolves the oldest promise with the enqueued item immediately.\n * Otherwise, it adds the item to the queue.\n *\n * @param item T\n */\n enqueue(item: T): void {\n this.cancelled = false;\n\n if (this.pendingDequeue.length > 0) {\n const promise = this.pendingDequeue.shift();\n\n promise?.resolve(item);\n\n return;\n }\n\n this.queue.push(item);\n }\n\n /**\n * The dequeue method returns a promise that resolves to the next item in the queue.\n * If the queue is not empty, it resolves the promise immediately with the next item.\n * Otherwise, it creates a new promise. The promise's resolve function is stored\n * in the pendingDequeue with a unique counter value as the key.\n * The newly created promise is then returned, and it will be resolved later when an item is enqueued.\n *\n * @returns Promise<T>\n */\n async dequeue(): Promise<T> {\n if (this.queue.length > 0) {\n return Promise.resolve(this.queue.shift()!);\n }\n\n return new Promise<T>((resolve, reject) => {\n this.pendingDequeue.push({ resolve, reject });\n });\n }\n\n /**\n * The isEmpty method returns whether the queue is empty or not.\n *\n * @returns boolean\n */\n isEmpty(): boolean {\n return this.queue.length === 0;\n }\n\n /**\n * The cancel method cancels all pending promises in the queue.\n * It rejects the promises with a AsyncQueueCancelledError error,\n * ensuring that any awaiting code can handle the cancellation appropriately.\n */\n cancel(): void {\n this.cancelled = true;\n\n this.pendingDequeue.forEach(async ({ reject }) => {\n reject(new AsyncQueueCancelledError(\"Task cancelled\"));\n });\n\n this.pendingDequeue = [];\n\n this.queue.length = 0;\n }\n\n /**\n * The isCancelled method returns whether the queue is cancelled or not.\n *\n * @returns boolean\n */\n isCancelled(): boolean {\n return this.cancelled;\n }\n\n /**\n * The pendingDequeueLength method returns the length of the pendingDequeue.\n *\n * @returns number\n */\n pendingDequeueLength(): number {\n return this.pendingDequeue.length;\n }\n}\n\nexport class AsyncQueueCancelledError extends Error {}\n"],"mappings":"AAaO,IAAMA,EAAN,KAAoB,CAApB,cACL,KAAS,MAAa,CAAC,EAGvB,KAAQ,eAAsC,CAAC,EAE/C,KAAQ,UAAqB,GAS7B,QAAQC,EAAe,CAGrB,GAFA,KAAK,UAAY,GAEb,KAAK,eAAe,OAAS,EAAG,CAClB,KAAK,eAAe,MAAM,GAEjC,QAAQA,CAAI,EAErB,MACF,CAEA,KAAK,MAAM,KAAKA,CAAI,CACtB,CAWA,MAAM,SAAsB,CAC1B,OAAI,KAAK,MAAM,OAAS,EACf,QAAQ,QAAQ,KAAK,MAAM,MAAM,CAAE,EAGrC,IAAI,QAAW,CAACC,EAASC,IAAW,CACzC,KAAK,eAAe,KAAK,CAAE,QAAAD,EAAS,OAAAC,CAAO,CAAC,CAC9C,CAAC,CACH,CAOA,SAAmB,CACjB,OAAO,KAAK,MAAM,SAAW,CAC/B,CAOA,QAAe,CACb,KAAK,UAAY,GAEjB,KAAK,eAAe,QAAQ,MAAO,CAAE,OAAAA,CAAO,IAAM,CAChDA,EAAO,IAAIC,EAAyB,gBAAgB,CAAC,CACvD,CAAC,EAED,KAAK,eAAiB,CAAC,EAEvB,KAAK,MAAM,OAAS,CACtB,CAOA,aAAuB,CACrB,OAAO,KAAK,SACd,CAOA,sBAA+B,CAC7B,OAAO,KAAK,eAAe,MAC7B,CACF,EAEaA,EAAN,cAAuC,KAAM,CAAC","names":["AsyncQueue","item","resolve","reject","AsyncQueueCancelledError"]}
@@ -0,0 +1,2 @@
1
+ import{a as r,b as i,c as s}from"./chunk-EIXCAYQM.mjs";import{a as o}from"./chunk-QDJN5HCB.mjs";var t=class{constructor(e){this.config=e}async getNumberOfDelegators(e){return await o({config:this.config,minimumLedgerVersion:e?.minimumLedgerVersion,processorType:"stake_processor"}),r({aptosConfig:this.config,...e})}async getNumberOfDelegatorsForAllPools(e){return await o({config:this.config,minimumLedgerVersion:e?.minimumLedgerVersion,processorType:"stake_processor"}),i({aptosConfig:this.config,...e})}async getDelegatedStakingActivities(e){return await o({config:this.config,minimumLedgerVersion:e?.minimumLedgerVersion,processorType:"stake_processor"}),s({aptosConfig:this.config,...e})}};export{t as a};
2
+ //# sourceMappingURL=chunk-UAL7TX7O.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/api/staking.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n getDelegatedStakingActivities,\n getNumberOfDelegators,\n getNumberOfDelegatorsForAllPools,\n} from \"../internal/staking\";\nimport { AnyNumber, GetDelegatedStakingActivitiesResponse, GetNumberOfDelegatorsResponse, OrderByArg } from \"../types\";\nimport { AccountAddressInput } from \"../core\";\nimport { ProcessorType } from \"../utils/const\";\nimport { AptosConfig } from \"./aptosConfig\";\nimport { waitForIndexerOnVersion } from \"./utils\";\n\n/**\n * A class to query all `Staking` related queries on Aptos.\n */\nexport class Staking {\n constructor(readonly config: AptosConfig) {}\n\n /**\n * Queries current number of delegators in a pool. Throws an error if the pool is not found.\n *\n * @example\n * const delegators = await aptos.getNumberOfDelegators({poolAddress:\"0x123\"})\n *\n * @param args.poolAddress Pool address\n * @param args.minimumLedgerVersion Optional ledger version to sync up to, before querying\n * @returns The number of delegators for the given pool\n */\n async getNumberOfDelegators(args: {\n poolAddress: AccountAddressInput;\n minimumLedgerVersion?: AnyNumber;\n }): Promise<number> {\n await waitForIndexerOnVersion({\n config: this.config,\n minimumLedgerVersion: args?.minimumLedgerVersion,\n processorType: ProcessorType.STAKE_PROCESSOR,\n });\n return getNumberOfDelegators({ aptosConfig: this.config, ...args });\n }\n\n /**\n * Queries current number of delegators in a pool. Throws an error if the pool is not found.\n *\n * @example\n * const delegators = await aptos.getNumberOfDelegatorsForAllPools()\n *\n * @param args.minimumLedgerVersion Optional ledger version to sync up to, before querying\n * @returns GetNumberOfDelegatorsForAllPoolsResponse response type\n */\n async getNumberOfDelegatorsForAllPools(args?: {\n minimumLedgerVersion?: AnyNumber;\n options?: OrderByArg<GetNumberOfDelegatorsResponse[0]>;\n }): Promise<GetNumberOfDelegatorsResponse> {\n await waitForIndexerOnVersion({\n config: this.config,\n minimumLedgerVersion: args?.minimumLedgerVersion,\n processorType: ProcessorType.STAKE_PROCESSOR,\n });\n return getNumberOfDelegatorsForAllPools({ aptosConfig: this.config, ...args });\n }\n\n /**\n * Queries delegated staking activities\n *\n * @example\n * const delegators = await aptos.getDelegatedStakingActivities({delegatorAddress:\"0x123\",poolAddress:\"0x456\"})\n *\n * @param args.delegatorAddress Delegator address\n * @param args.poolAddress Pool address\n * @param args.minimumLedgerVersion Optional ledger version to sync up to, before querying\n * @returns GetDelegatedStakingActivitiesResponse response type\n */\n async getDelegatedStakingActivities(args: {\n delegatorAddress: AccountAddressInput;\n poolAddress: AccountAddressInput;\n minimumLedgerVersion?: AnyNumber;\n }): Promise<GetDelegatedStakingActivitiesResponse> {\n await waitForIndexerOnVersion({\n config: this.config,\n minimumLedgerVersion: args?.minimumLedgerVersion,\n processorType: ProcessorType.STAKE_PROCESSOR,\n });\n return getDelegatedStakingActivities({ aptosConfig: this.config, ...args });\n }\n}\n"],"mappings":";;;;;;;;;;AAiBO,IAAM,UAAN,MAAc;AAAA,EACnB,YAAqB,QAAqB;AAArB;AAAA,EAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAY3C,MAAM,sBAAsB,MAGR;AAClB,UAAM,wBAAwB;AAAA,MAC5B,QAAQ,KAAK;AAAA,MACb,sBAAsB,MAAM;AAAA,MAC5B;AAAA,IACF,CAAC;AACD,WAAO,sBAAsB,EAAE,aAAa,KAAK,QAAQ,GAAG,KAAK,CAAC;AAAA,EACpE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,iCAAiC,MAGI;AACzC,UAAM,wBAAwB;AAAA,MAC5B,QAAQ,KAAK;AAAA,MACb,sBAAsB,MAAM;AAAA,MAC5B;AAAA,IACF,CAAC;AACD,WAAO,iCAAiC,EAAE,aAAa,KAAK,QAAQ,GAAG,KAAK,CAAC;AAAA,EAC/E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,MAAM,8BAA8B,MAIe;AACjD,UAAM,wBAAwB;AAAA,MAC5B,QAAQ,KAAK;AAAA,MACb,sBAAsB,MAAM;AAAA,MAC5B;AAAA,IACF,CAAC;AACD,WAAO,8BAA8B,EAAE,aAAa,KAAK,QAAQ,GAAG,KAAK,CAAC;AAAA,EAC5E;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/api/staking.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n getDelegatedStakingActivities,\n getNumberOfDelegators,\n getNumberOfDelegatorsForAllPools,\n} from \"../internal/staking\";\nimport { AnyNumber, GetDelegatedStakingActivitiesResponse, GetNumberOfDelegatorsResponse, OrderByArg } from \"../types\";\nimport { AccountAddressInput } from \"../core\";\nimport { ProcessorType } from \"../utils/const\";\nimport { AptosConfig } from \"./aptosConfig\";\nimport { waitForIndexerOnVersion } from \"./utils\";\n\n/**\n * A class to query all `Staking` related queries on Aptos.\n */\nexport class Staking {\n constructor(readonly config: AptosConfig) {}\n\n /**\n * Queries current number of delegators in a pool. Throws an error if the pool is not found.\n *\n * @example\n * const delegators = await aptos.getNumberOfDelegators({poolAddress:\"0x123\"})\n *\n * @param args.poolAddress Pool address\n * @param args.minimumLedgerVersion Optional ledger version to sync up to, before querying\n * @returns The number of delegators for the given pool\n */\n async getNumberOfDelegators(args: {\n poolAddress: AccountAddressInput;\n minimumLedgerVersion?: AnyNumber;\n }): Promise<number> {\n await waitForIndexerOnVersion({\n config: this.config,\n minimumLedgerVersion: args?.minimumLedgerVersion,\n processorType: ProcessorType.STAKE_PROCESSOR,\n });\n return getNumberOfDelegators({ aptosConfig: this.config, ...args });\n }\n\n /**\n * Queries current number of delegators in a pool. Throws an error if the pool is not found.\n *\n * @example\n * const delegators = await aptos.getNumberOfDelegatorsForAllPools()\n *\n * @param args.minimumLedgerVersion Optional ledger version to sync up to, before querying\n * @returns GetNumberOfDelegatorsForAllPoolsResponse response type\n */\n async getNumberOfDelegatorsForAllPools(args?: {\n minimumLedgerVersion?: AnyNumber;\n options?: OrderByArg<GetNumberOfDelegatorsResponse[0]>;\n }): Promise<GetNumberOfDelegatorsResponse> {\n await waitForIndexerOnVersion({\n config: this.config,\n minimumLedgerVersion: args?.minimumLedgerVersion,\n processorType: ProcessorType.STAKE_PROCESSOR,\n });\n return getNumberOfDelegatorsForAllPools({ aptosConfig: this.config, ...args });\n }\n\n /**\n * Queries delegated staking activities\n *\n * @example\n * const delegators = await aptos.getDelegatedStakingActivities({delegatorAddress:\"0x123\",poolAddress:\"0x456\"})\n *\n * @param args.delegatorAddress Delegator address\n * @param args.poolAddress Pool address\n * @param args.minimumLedgerVersion Optional ledger version to sync up to, before querying\n * @returns GetDelegatedStakingActivitiesResponse response type\n */\n async getDelegatedStakingActivities(args: {\n delegatorAddress: AccountAddressInput;\n poolAddress: AccountAddressInput;\n minimumLedgerVersion?: AnyNumber;\n }): Promise<GetDelegatedStakingActivitiesResponse> {\n await waitForIndexerOnVersion({\n config: this.config,\n minimumLedgerVersion: args?.minimumLedgerVersion,\n processorType: ProcessorType.STAKE_PROCESSOR,\n });\n return getDelegatedStakingActivities({ aptosConfig: this.config, ...args });\n }\n}\n"],"mappings":"gGAiBO,IAAMA,EAAN,KAAc,CACnB,YAAqBC,EAAqB,CAArB,YAAAA,CAAsB,CAY3C,MAAM,sBAAsBC,EAGR,CAClB,aAAMC,EAAwB,CAC5B,OAAQ,KAAK,OACb,qBAAsBD,GAAM,qBAC5B,+BACF,CAAC,EACME,EAAsB,CAAE,YAAa,KAAK,OAAQ,GAAGF,CAAK,CAAC,CACpE,CAWA,MAAM,iCAAiCA,EAGI,CACzC,aAAMC,EAAwB,CAC5B,OAAQ,KAAK,OACb,qBAAsBD,GAAM,qBAC5B,+BACF,CAAC,EACMG,EAAiC,CAAE,YAAa,KAAK,OAAQ,GAAGH,CAAK,CAAC,CAC/E,CAaA,MAAM,8BAA8BA,EAIe,CACjD,aAAMC,EAAwB,CAC5B,OAAQ,KAAK,OACb,qBAAsBD,GAAM,qBAC5B,+BACF,CAAC,EACMI,EAA8B,CAAE,YAAa,KAAK,OAAQ,GAAGJ,CAAK,CAAC,CAC5E,CACF","names":["Staking","config","args","waitForIndexerOnVersion","getNumberOfDelegators","getNumberOfDelegatorsForAllPools","getDelegatedStakingActivities"]}
@@ -0,0 +1,2 @@
1
+ import{a as e}from"./chunk-VT6XJSRO.mjs";function t(i,r){let l=r.bcsToBytes(),a=new e(l);return i.deserialize(a)}export{t as a};
2
+ //# sourceMappingURL=chunk-UTXJOB3O.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/normalizeBundle.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Deserializer, Serializable } from \"../bcs\";\n\nexport type DeserializableClass<T extends Serializable> = {\n deserialize(deserializer: Deserializer): T;\n};\n\n/**\n * Utility function that serializes and deserialize an object back into the same bundle as the sdk.\n * This is a workaround to have the `instanceof` operator work when input objects come from a different\n * bundle.\n * @param cls The class of the object to normalize\n * @param value the instance to normalize\n */\nexport function normalizeBundle<T extends Serializable>(cls: DeserializableClass<T>, value: T) {\n const serializedBytes = value.bcsToBytes();\n const deserializer = new Deserializer(serializedBytes);\n return cls.deserialize(deserializer);\n}\n"],"mappings":";;;;;AAgBO,SAAS,gBAAwC,KAA6B,OAAU;AAC7F,QAAM,kBAAkB,MAAM,WAAW;AACzC,QAAM,eAAe,IAAI,aAAa,eAAe;AACrD,SAAO,IAAI,YAAY,YAAY;AACrC;","names":[]}
1
+ {"version":3,"sources":["../../src/utils/normalizeBundle.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Deserializer, Serializable } from \"../bcs\";\n\nexport type DeserializableClass<T extends Serializable> = {\n deserialize(deserializer: Deserializer): T;\n};\n\n/**\n * Utility function that serializes and deserialize an object back into the same bundle as the sdk.\n * This is a workaround to have the `instanceof` operator work when input objects come from a different\n * bundle.\n * @param cls The class of the object to normalize\n * @param value the instance to normalize\n */\nexport function normalizeBundle<T extends Serializable>(cls: DeserializableClass<T>, value: T) {\n const serializedBytes = value.bcsToBytes();\n const deserializer = new Deserializer(serializedBytes);\n return cls.deserialize(deserializer);\n}\n"],"mappings":"yCAgBO,SAASA,EAAwCC,EAA6BC,EAAU,CAC7F,IAAMC,EAAkBD,EAAM,WAAW,EACnCE,EAAe,IAAIC,EAAaF,CAAe,EACrD,OAAOF,EAAI,YAAYG,CAAY,CACrC","names":["normalizeBundle","cls","value","serializedBytes","deserializer","Deserializer"]}
@@ -0,0 +1,2 @@
1
+ import{a as I}from"./chunk-N466X3S6.mjs";import{a as S,b as p}from"./chunk-NWWXZ7EW.mjs";import{b as E}from"./chunk-COW5IGYC.mjs";import{a as u}from"./chunk-STYDBDYL.mjs";import{a as d,c as U,d as H,e as K}from"./chunk-FLYEALDB.mjs";import{a as b}from"./chunk-7STYQ5ZE.mjs";import{a as f}from"./chunk-VT6XJSRO.mjs";import{a as z,b as A}from"./chunk-TVRJ3M7B.mjs";import{b as c}from"./chunk-AOCNYMMX.mjs";var B=1e7,D=120,v=30,P=330,R=120,$=350,J=300,q=93,o=class o extends E{constructor(e,t){super();let i=c.fromHexInput(t).toUint8Array();if(i.length!==o.ID_COMMITMENT_LENGTH)throw new Error(`Address seed length in bytes should be ${o.ID_COMMITMENT_LENGTH}`);this.iss=e,this.idCommitment=i}authKey(){let e=new A;return e.serializeU32AsUleb128(3),e.serializeFixedBytes(this.bcsToBytes()),b.fromSchemeAndBytes({scheme:2,input:e.toUint8Array()})}toUint8Array(){return this.bcsToBytes()}toString(){return c.fromHexInput(this.toUint8Array()).toString()}verifySignature(e){throw new Error("Not yet implemented")}serialize(e){e.serializeStr(this.iss),e.serializeBytes(this.idCommitment)}static deserialize(e){let t=e.deserializeStr(),i=e.deserializeBytes();return new o(t,i)}static load(e){let t=e.deserializeStr(),i=e.deserializeBytes();return new o(t,i)}static isPublicKey(e){return e instanceof o}static create(e){return w(e),new o(e.iss,w(e))}};o.ID_COMMITMENT_LENGTH=32;var m=o;function w(s){let{uidKey:l,uidVal:e,aud:t,pepper:i}=s,r=[U(c.fromHexInput(i).toUint8Array()),d(t,D),d(e,P),d(l,v)];return H(K(r),m.ID_COMMITMENT_LENGTH)}var T=class s extends u{constructor(e){super();let{jwtHeader:t,ephemeralCertificate:i,expiryDateSecs:r,ephemeralPublicKey:a,ephemeralSignature:n}=e;this.jwtHeader=t,this.ephemeralCertificate=i,this.expiryDateSecs=r,this.ephemeralPublicKey=a,this.ephemeralSignature=n}toUint8Array(){return this.bcsToBytes()}serialize(e){this.ephemeralCertificate.serialize(e),e.serializeStr(this.jwtHeader),e.serializeU64(this.expiryDateSecs),this.ephemeralPublicKey.serialize(e),this.ephemeralSignature.serialize(e)}static deserialize(e){let t=h.deserialize(e),i=e.deserializeStr(),r=e.deserializeU64(),a=S.deserialize(e),n=p.deserialize(e);return new s({jwtHeader:i,expiryDateSecs:r,ephemeralCertificate:t,ephemeralPublicKey:a,ephemeralSignature:n})}static load(e){let t=h.deserialize(e),i=e.deserializeStr(),r=e.deserializeU64(),a=S.deserialize(e),n=p.deserialize(e);return new s({jwtHeader:i,expiryDateSecs:r,ephemeralCertificate:t,ephemeralPublicKey:a,ephemeralSignature:n})}static isSignature(e){return e instanceof s}},h=class s extends u{constructor(e,t){super();this.signature=e,this.variant=t}toUint8Array(){return this.signature.toUint8Array()}serialize(e){e.serializeU32AsUleb128(this.variant),this.signature.serialize(e)}static deserialize(e){let t=e.deserializeUleb128AsU32();switch(t){case 0:return new s(x.deserialize(e),t);default:throw new Error(`Unknown variant index for EphemeralCertificate: ${t}`)}}},g=class s extends I{constructor(e){super();let{a:t,b:i,c:r}=e;this.a=c.fromHexInput(t).toUint8Array(),this.b=c.fromHexInput(i).toUint8Array(),this.c=c.fromHexInput(r).toUint8Array()}serialize(e){e.serializeFixedBytes(this.a),e.serializeFixedBytes(this.b),e.serializeFixedBytes(this.c)}static deserialize(e){let t=e.deserializeFixedBytes(32),i=e.deserializeFixedBytes(64),r=e.deserializeFixedBytes(32);return new s({a:t,b:i,c:r})}},y=class s extends z{constructor(e,t){super();this.proof=e,this.variant=t}serialize(e){e.serializeU32AsUleb128(this.variant),this.proof.serialize(e)}static deserialize(e){let t=e.deserializeUleb128AsU32();switch(t){case 0:return new s(g.deserialize(e),t);default:throw new Error(`Unknown variant index for ZkProof: ${t}`)}}},x=class s extends u{constructor(e){super();let{proof:t,expHorizonSecs:i=BigInt(B),trainingWheelsSignature:r,extraField:a,overrideAudVal:n}=e;this.proof=t,this.expHorizonSecs=i,this.trainingWheelsSignature=r,this.extraField=a,this.overrideAudVal=n}toUint8Array(){return this.bcsToBytes()}static fromBytes(e){return s.deserialize(new f(e))}serialize(e){this.proof.serialize(e),e.serializeU64(this.expHorizonSecs),e.serializeOptionStr(this.extraField),e.serializeOptionStr(this.overrideAudVal),e.serializeOption(this.trainingWheelsSignature)}static deserialize(e){let t=y.deserialize(e),i=e.deserializeU64(),r=e.deserializeOptionStr(),a=e.deserializeOptionStr(),n=e.deserializeOption(p);return new s({proof:t,expHorizonSecs:i,trainingWheelsSignature:n,extraField:r,overrideAudVal:a})}static load(e){let t=y.deserialize(e),i=e.deserializeU64(),r=e.deserializeOptionStr(),a=e.deserializeOptionStr(),n=e.deserializeOption(p);return new s({proof:t,expHorizonSecs:i,trainingWheelsSignature:n,extraField:r,overrideAudVal:a})}};export{B as a,D as b,v as c,P as d,R as e,$ as f,J as g,q as h,m as i,T as j,h as k,g as l,y as m,x as n};
2
+ //# sourceMappingURL=chunk-VDMVO4R4.mjs.map