@aptos-labs/ts-sdk 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (335) hide show
  1. package/dist/browser/index.d.ts +1131 -989
  2. package/dist/browser/index.global.js +30 -30
  3. package/dist/browser/index.global.js.map +1 -1
  4. package/dist/common/index.d.ts +1131 -989
  5. package/dist/common/index.js +25 -25
  6. package/dist/common/index.js.map +1 -1
  7. package/dist/esm/api/account.d.mts +12 -6
  8. package/dist/esm/api/account.mjs +1 -1
  9. package/dist/esm/api/ans.d.mts +11 -12
  10. package/dist/esm/api/ans.mjs +1 -1
  11. package/dist/esm/api/aptos.d.mts +13 -14
  12. package/dist/esm/api/aptos.mjs +1 -1
  13. package/dist/esm/api/aptosConfig.mjs +1 -1
  14. package/dist/esm/api/coin.d.mts +13 -13
  15. package/dist/esm/api/coin.mjs +1 -1
  16. package/dist/esm/api/digitalAsset.d.mts +20 -10
  17. package/dist/esm/api/digitalAsset.mjs +1 -1
  18. package/dist/esm/api/event.mjs +1 -1
  19. package/dist/esm/api/faucet.mjs +1 -1
  20. package/dist/esm/api/fungibleAsset.d.mts +9 -10
  21. package/dist/esm/api/fungibleAsset.mjs +1 -1
  22. package/dist/esm/api/general.mjs +1 -1
  23. package/dist/esm/api/index.d.mts +13 -14
  24. package/dist/esm/api/index.mjs +1 -1
  25. package/dist/esm/api/staking.mjs +1 -1
  26. package/dist/esm/api/transaction.d.mts +5 -6
  27. package/dist/esm/api/transaction.mjs +1 -1
  28. package/dist/esm/api/transactionSubmission/build.d.mts +8 -8
  29. package/dist/esm/api/transactionSubmission/build.mjs +1 -1
  30. package/dist/esm/api/transactionSubmission/management.d.mts +11 -12
  31. package/dist/esm/api/transactionSubmission/management.mjs +1 -1
  32. package/dist/esm/api/transactionSubmission/sign.d.mts +11 -12
  33. package/dist/esm/api/transactionSubmission/sign.mjs +1 -1
  34. package/dist/esm/api/transactionSubmission/sign.mjs.map +1 -1
  35. package/dist/esm/api/transactionSubmission/simulate.d.mts +11 -11
  36. package/dist/esm/api/transactionSubmission/simulate.mjs +1 -1
  37. package/dist/esm/api/transactionSubmission/submit.d.mts +6 -6
  38. package/dist/esm/api/transactionSubmission/submit.mjs +1 -1
  39. package/dist/esm/api/utils.mjs +1 -1
  40. package/dist/esm/{chunk-S64WKSMI.mjs → chunk-2E2JOGE5.mjs} +2 -2
  41. package/dist/esm/chunk-3EUOBVCT.mjs +2 -0
  42. package/dist/esm/{chunk-SRZTA6QH.mjs.map → chunk-3EUOBVCT.mjs.map} +1 -1
  43. package/dist/esm/{chunk-4OI7MPFH.mjs → chunk-52RTAMN7.mjs} +2 -2
  44. package/dist/esm/chunk-7BDYKJXX.mjs +2 -0
  45. package/dist/esm/chunk-7BDYKJXX.mjs.map +1 -0
  46. package/dist/esm/{chunk-R56OJ4XC.mjs → chunk-7U36LMP4.mjs} +2 -2
  47. package/dist/esm/{chunk-NWRKJFHV.mjs → chunk-ARIC32W7.mjs} +2 -2
  48. package/dist/esm/{chunk-SPOHAEHR.mjs → chunk-B7M3OWHV.mjs} +2 -2
  49. package/dist/esm/{chunk-6SRENFWH.mjs → chunk-BBUAAJRA.mjs} +2 -2
  50. package/dist/esm/chunk-C3HM7HQP.mjs +2 -0
  51. package/dist/esm/chunk-C3HM7HQP.mjs.map +1 -0
  52. package/dist/esm/{chunk-PMWH5IGI.mjs → chunk-CHA5DSSD.mjs} +2 -2
  53. package/dist/esm/chunk-DE5OOOVY.mjs +2 -0
  54. package/dist/esm/{chunk-MEPX7Z2Z.mjs.map → chunk-DE5OOOVY.mjs.map} +1 -1
  55. package/dist/esm/{chunk-JJ6Y35DF.mjs → chunk-DGOT2VR5.mjs} +2 -2
  56. package/dist/esm/{chunk-EUHPML5E.mjs → chunk-EF2F7NWO.mjs} +2 -2
  57. package/dist/esm/{chunk-FRLPX47J.mjs → chunk-EQZ757ES.mjs} +2 -2
  58. package/dist/esm/{chunk-Y4AKS4CY.mjs → chunk-F67Y7YH6.mjs} +2 -2
  59. package/dist/esm/{chunk-KJGQ4ILY.mjs → chunk-FVMVV4V3.mjs} +2 -2
  60. package/dist/esm/chunk-FWDKABRW.mjs +2 -0
  61. package/dist/esm/chunk-FWDKABRW.mjs.map +1 -0
  62. package/dist/esm/chunk-G62HQC77.mjs +2 -0
  63. package/dist/esm/chunk-G62HQC77.mjs.map +1 -0
  64. package/dist/esm/{chunk-V2FPYAK7.mjs → chunk-GQOOXOTN.mjs} +2 -2
  65. package/dist/esm/chunk-GRJJBGHT.mjs +2 -0
  66. package/dist/esm/chunk-GRJJBGHT.mjs.map +1 -0
  67. package/dist/esm/chunk-HEPV52CH.mjs +2 -0
  68. package/dist/esm/chunk-HEPV52CH.mjs.map +1 -0
  69. package/dist/esm/{chunk-GD4ULEBC.mjs → chunk-I3TCHVQQ.mjs} +2 -2
  70. package/dist/esm/{chunk-JQVT2K7G.mjs → chunk-ILJWEPDW.mjs} +2 -2
  71. package/dist/esm/{chunk-Q3HAJVCM.mjs → chunk-INORE66K.mjs} +2 -2
  72. package/dist/esm/{chunk-PIXE7MN5.mjs → chunk-J6MWD4XN.mjs} +2 -2
  73. package/dist/esm/{chunk-ENKMOALS.mjs → chunk-JEHR6GKW.mjs} +2 -2
  74. package/dist/esm/chunk-JEHR6GKW.mjs.map +1 -0
  75. package/dist/esm/chunk-KUX6GQ2E.mjs +1 -0
  76. package/dist/esm/{chunk-ENDUXRTK.mjs → chunk-KWJTVJ7C.mjs} +2 -2
  77. package/dist/esm/{chunk-W4UDMBMU.mjs → chunk-LLL2LFYH.mjs} +2 -2
  78. package/dist/esm/chunk-LMXP3JUU.mjs +2 -0
  79. package/dist/esm/chunk-LMXP3JUU.mjs.map +1 -0
  80. package/dist/esm/{chunk-2WFMD6C6.mjs → chunk-N65SOKJQ.mjs} +2 -2
  81. package/dist/esm/{chunk-Q5HK3U64.mjs → chunk-NL3XVNS5.mjs} +2 -2
  82. package/dist/esm/{chunk-M3WNE7MU.mjs → chunk-NURFZOR4.mjs} +2 -2
  83. package/dist/esm/{chunk-AFPJ2XXN.mjs → chunk-OG56TYZE.mjs} +2 -2
  84. package/dist/esm/chunk-Q6WOHF4A.mjs +2 -0
  85. package/dist/esm/chunk-Q6WOHF4A.mjs.map +1 -0
  86. package/dist/esm/chunk-QA4XWNIH.mjs +2 -0
  87. package/dist/esm/chunk-QA4XWNIH.mjs.map +1 -0
  88. package/dist/esm/chunk-QE4ASJ5K.mjs +1 -0
  89. package/dist/esm/chunk-QR72RXBS.mjs +2 -0
  90. package/dist/esm/chunk-QR72RXBS.mjs.map +1 -0
  91. package/dist/esm/{chunk-XBVORX5O.mjs → chunk-R4VJDSIP.mjs} +2 -2
  92. package/dist/esm/{chunk-O57QZZF2.mjs → chunk-S2F6CSH4.mjs} +2 -2
  93. package/dist/esm/chunk-S2F6CSH4.mjs.map +1 -0
  94. package/dist/esm/{chunk-2H5Z5EHH.mjs → chunk-TN5BUH4F.mjs} +2 -2
  95. package/dist/esm/chunk-TNVR7SNR.mjs +2 -0
  96. package/dist/esm/chunk-TNVR7SNR.mjs.map +1 -0
  97. package/dist/esm/chunk-TX7UK75Q.mjs +2 -0
  98. package/dist/esm/chunk-TX7UK75Q.mjs.map +1 -0
  99. package/dist/esm/{chunk-VPQ46CAO.mjs → chunk-UIUSDBCL.mjs} +2 -2
  100. package/dist/esm/{chunk-4M46AWXX.mjs → chunk-UMLDKLDL.mjs} +2 -2
  101. package/dist/esm/chunk-UVSRX4SV.mjs +1 -0
  102. package/dist/esm/{chunk-2DNPRIS5.mjs → chunk-VEVBHH3M.mjs} +2 -2
  103. package/dist/esm/{chunk-QGIJNA37.mjs → chunk-VMXBMAYK.mjs} +2 -2
  104. package/dist/esm/chunk-WKUXBIYB.mjs +2 -0
  105. package/dist/esm/chunk-WKUXBIYB.mjs.map +1 -0
  106. package/dist/esm/chunk-WME5D6YR.mjs +2 -0
  107. package/dist/esm/chunk-WME5D6YR.mjs.map +1 -0
  108. package/dist/esm/chunk-WTHNSNAX.mjs +2 -0
  109. package/dist/esm/chunk-WTHNSNAX.mjs.map +1 -0
  110. package/dist/esm/{chunk-GD5TZLBF.mjs → chunk-X5C3LYI7.mjs} +2 -2
  111. package/dist/esm/chunk-XKD7W5NO.mjs +2 -0
  112. package/dist/esm/{chunk-XZYPAQCU.mjs.map → chunk-XKD7W5NO.mjs.map} +1 -1
  113. package/dist/esm/{chunk-QRQAR6XO.mjs → chunk-XTPFQ4MH.mjs} +2 -2
  114. package/dist/esm/{chunk-LATJGGVX.mjs → chunk-Y5AJLNUD.mjs} +2 -2
  115. package/dist/esm/chunk-YDAA4RG4.mjs +2 -0
  116. package/dist/esm/chunk-YDAA4RG4.mjs.map +1 -0
  117. package/dist/esm/{chunk-VKZCIGKY.mjs → chunk-YR2R3LW4.mjs} +2 -2
  118. package/dist/esm/chunk-YZZO6VDC.mjs +2 -0
  119. package/dist/esm/chunk-YZZO6VDC.mjs.map +1 -0
  120. package/dist/esm/client/core.mjs +1 -1
  121. package/dist/esm/client/get.mjs +1 -1
  122. package/dist/esm/client/index.mjs +1 -1
  123. package/dist/esm/client/post.mjs +1 -1
  124. package/dist/esm/core/account/Account.d.mts +20 -0
  125. package/dist/esm/core/account/Account.mjs +2 -0
  126. package/dist/esm/core/account/Ed25519Account.d.mts +20 -0
  127. package/dist/esm/core/account/Ed25519Account.mjs +2 -0
  128. package/dist/esm/core/account/SingleKeyAccount.d.mts +20 -0
  129. package/dist/esm/core/account/SingleKeyAccount.mjs +2 -0
  130. package/dist/esm/core/account/SingleKeyAccount.mjs.map +1 -0
  131. package/dist/esm/core/account/index.d.mts +305 -0
  132. package/dist/esm/core/account/index.mjs +2 -0
  133. package/dist/esm/core/account/index.mjs.map +1 -0
  134. package/dist/esm/core/authenticationKey.d.mts +7 -68
  135. package/dist/esm/core/authenticationKey.mjs +1 -1
  136. package/dist/esm/core/crypto/ed25519.d.mts +49 -61
  137. package/dist/esm/core/crypto/ed25519.mjs +1 -1
  138. package/dist/esm/core/crypto/index.d.mts +9 -6
  139. package/dist/esm/core/crypto/index.mjs +1 -1
  140. package/dist/esm/core/crypto/multiEd25519.d.mts +17 -14
  141. package/dist/esm/core/crypto/multiEd25519.mjs +1 -1
  142. package/dist/esm/core/crypto/multiKey.d.mts +70 -17
  143. package/dist/esm/core/crypto/multiKey.mjs +1 -1
  144. package/dist/esm/core/crypto/privateKey.d.mts +35 -0
  145. package/dist/esm/core/crypto/privateKey.mjs +2 -0
  146. package/dist/esm/core/crypto/privateKey.mjs.map +1 -0
  147. package/dist/esm/core/crypto/publicKey.d.mts +13 -0
  148. package/dist/esm/core/crypto/publicKey.mjs +2 -0
  149. package/dist/esm/core/crypto/publicKey.mjs.map +1 -0
  150. package/dist/esm/core/crypto/secp256k1.d.mts +43 -67
  151. package/dist/esm/core/crypto/secp256k1.mjs +1 -1
  152. package/dist/esm/core/crypto/signature.d.mts +28 -0
  153. package/dist/esm/core/crypto/signature.mjs +2 -0
  154. package/dist/esm/core/crypto/signature.mjs.map +1 -0
  155. package/dist/esm/core/crypto/singleKey.d.mts +68 -0
  156. package/dist/esm/core/crypto/singleKey.mjs +2 -0
  157. package/dist/esm/core/crypto/singleKey.mjs.map +1 -0
  158. package/dist/esm/core/index.d.mts +9 -8
  159. package/dist/esm/core/index.mjs +1 -1
  160. package/dist/esm/index.d.mts +8 -8
  161. package/dist/esm/index.mjs +1 -1
  162. package/dist/esm/internal/account.d.mts +10 -4
  163. package/dist/esm/internal/account.mjs +1 -1
  164. package/dist/esm/internal/ans.d.mts +11 -12
  165. package/dist/esm/internal/ans.mjs +1 -1
  166. package/dist/esm/internal/coin.d.mts +12 -12
  167. package/dist/esm/internal/coin.mjs +1 -1
  168. package/dist/esm/internal/digitalAsset.d.mts +17 -14
  169. package/dist/esm/internal/digitalAsset.mjs +1 -1
  170. package/dist/esm/internal/event.d.mts +2 -2
  171. package/dist/esm/internal/event.mjs +1 -1
  172. package/dist/esm/internal/faucet.d.mts +4 -4
  173. package/dist/esm/internal/faucet.mjs +1 -1
  174. package/dist/esm/internal/fungibleAsset.d.mts +10 -11
  175. package/dist/esm/internal/fungibleAsset.mjs +1 -1
  176. package/dist/esm/internal/general.mjs +1 -1
  177. package/dist/esm/internal/staking.d.mts +3 -3
  178. package/dist/esm/internal/staking.mjs +1 -1
  179. package/dist/esm/internal/transaction.mjs +1 -1
  180. package/dist/esm/internal/transactionSubmission.d.mts +12 -13
  181. package/dist/esm/internal/transactionSubmission.mjs +1 -1
  182. package/dist/esm/publicKey-lq5djCIY.d.mts +113 -0
  183. package/dist/esm/transactions/authenticator/account.d.mts +6 -4
  184. package/dist/esm/transactions/authenticator/account.mjs +1 -1
  185. package/dist/esm/transactions/authenticator/index.d.mts +6 -6
  186. package/dist/esm/transactions/authenticator/index.mjs +1 -1
  187. package/dist/esm/transactions/authenticator/transaction.d.mts +5 -5
  188. package/dist/esm/transactions/authenticator/transaction.mjs +1 -1
  189. package/dist/esm/transactions/index.d.mts +6 -7
  190. package/dist/esm/transactions/index.mjs +1 -1
  191. package/dist/esm/transactions/instances/index.d.mts +4 -4
  192. package/dist/esm/transactions/instances/index.mjs +1 -1
  193. package/dist/esm/transactions/instances/moduleId.d.mts +1 -1
  194. package/dist/esm/transactions/instances/moduleId.mjs +1 -1
  195. package/dist/esm/transactions/instances/rawTransaction.mjs +1 -1
  196. package/dist/esm/transactions/instances/rotationProofChallenge.d.mts +2 -1
  197. package/dist/esm/transactions/instances/rotationProofChallenge.mjs +1 -1
  198. package/dist/esm/transactions/instances/signedTransaction.d.mts +8 -8
  199. package/dist/esm/transactions/instances/signedTransaction.mjs +1 -1
  200. package/dist/esm/transactions/instances/transactionPayload.d.mts +1 -1
  201. package/dist/esm/transactions/instances/transactionPayload.mjs +1 -1
  202. package/dist/esm/transactions/management/accountSequenceNumber.d.mts +11 -5
  203. package/dist/esm/transactions/management/accountSequenceNumber.mjs +1 -1
  204. package/dist/esm/transactions/management/index.d.mts +11 -12
  205. package/dist/esm/transactions/management/index.mjs +1 -1
  206. package/dist/esm/transactions/management/transactionWorker.d.mts +11 -12
  207. package/dist/esm/transactions/management/transactionWorker.mjs +1 -1
  208. package/dist/esm/transactions/transactionBuilder/helpers.d.mts +10 -10
  209. package/dist/esm/transactions/transactionBuilder/helpers.mjs +1 -1
  210. package/dist/esm/transactions/transactionBuilder/index.d.mts +9 -10
  211. package/dist/esm/transactions/transactionBuilder/index.mjs +1 -1
  212. package/dist/esm/transactions/transactionBuilder/remoteAbi.d.mts +8 -8
  213. package/dist/esm/transactions/transactionBuilder/remoteAbi.mjs +1 -1
  214. package/dist/esm/transactions/transactionBuilder/transactionBuilder.d.mts +9 -10
  215. package/dist/esm/transactions/transactionBuilder/transactionBuilder.mjs +1 -1
  216. package/dist/esm/transactions/typeTag/index.mjs +1 -1
  217. package/dist/esm/transactions/typeTag/parser.mjs +1 -1
  218. package/dist/esm/transactions/types.d.mts +9 -9
  219. package/dist/esm/utils/const.d.mts +1 -2
  220. package/dist/esm/utils/const.mjs +1 -1
  221. package/dist/esm/utils/index.d.mts +1 -1
  222. package/dist/esm/utils/index.mjs +1 -1
  223. package/dist/esm/version.d.mts +1 -1
  224. package/dist/esm/version.mjs +1 -1
  225. package/package.json +1 -1
  226. package/src/api/aptosConfig.ts +2 -2
  227. package/src/api/digitalAsset.ts +20 -0
  228. package/src/core/account/Account.ts +245 -0
  229. package/src/core/account/Ed25519Account.ts +88 -0
  230. package/src/core/account/SingleKeyAccount.ts +120 -0
  231. package/src/core/account/index.ts +3 -0
  232. package/src/core/authenticationKey.ts +18 -52
  233. package/src/core/crypto/ed25519.ts +118 -104
  234. package/src/core/crypto/index.ts +6 -5
  235. package/src/core/crypto/multiEd25519.ts +98 -44
  236. package/src/core/crypto/multiKey.ts +192 -34
  237. package/src/core/crypto/privateKey.ts +25 -0
  238. package/src/core/crypto/publicKey.ts +52 -0
  239. package/src/core/crypto/secp256k1.ts +108 -111
  240. package/src/core/crypto/signature.ts +46 -0
  241. package/src/core/crypto/singleKey.ts +180 -0
  242. package/src/internal/account.ts +5 -3
  243. package/src/internal/digitalAsset.ts +26 -0
  244. package/src/transactions/authenticator/account.ts +1 -2
  245. package/src/transactions/instances/rotationProofChallenge.ts +1 -1
  246. package/src/transactions/transactionBuilder/transactionBuilder.ts +3 -21
  247. package/src/transactions/types.ts +1 -1
  248. package/src/utils/const.ts +0 -4
  249. package/src/version.ts +1 -1
  250. package/dist/esm/chunk-2QV6HI3M.mjs +0 -2
  251. package/dist/esm/chunk-2QV6HI3M.mjs.map +0 -1
  252. package/dist/esm/chunk-7IGH7N52.mjs +0 -2
  253. package/dist/esm/chunk-7IGH7N52.mjs.map +0 -1
  254. package/dist/esm/chunk-CCUD52OF.mjs +0 -2
  255. package/dist/esm/chunk-CCUD52OF.mjs.map +0 -1
  256. package/dist/esm/chunk-ENKMOALS.mjs.map +0 -1
  257. package/dist/esm/chunk-ERWQOVBF.mjs +0 -2
  258. package/dist/esm/chunk-ERWQOVBF.mjs.map +0 -1
  259. package/dist/esm/chunk-FBFMQZTM.mjs +0 -2
  260. package/dist/esm/chunk-FBFMQZTM.mjs.map +0 -1
  261. package/dist/esm/chunk-FP5DPRYL.mjs +0 -2
  262. package/dist/esm/chunk-FP5DPRYL.mjs.map +0 -1
  263. package/dist/esm/chunk-HHJBCGAQ.mjs +0 -2
  264. package/dist/esm/chunk-HHJBCGAQ.mjs.map +0 -1
  265. package/dist/esm/chunk-I7WRJY7K.mjs +0 -2
  266. package/dist/esm/chunk-I7WRJY7K.mjs.map +0 -1
  267. package/dist/esm/chunk-LHJSG5NE.mjs +0 -2
  268. package/dist/esm/chunk-LHJSG5NE.mjs.map +0 -1
  269. package/dist/esm/chunk-MEPX7Z2Z.mjs +0 -2
  270. package/dist/esm/chunk-O57QZZF2.mjs.map +0 -1
  271. package/dist/esm/chunk-S3FBGS3W.mjs +0 -2
  272. package/dist/esm/chunk-S3FBGS3W.mjs.map +0 -1
  273. package/dist/esm/chunk-SBMJNU2O.mjs +0 -2
  274. package/dist/esm/chunk-SBMJNU2O.mjs.map +0 -1
  275. package/dist/esm/chunk-SRZTA6QH.mjs +0 -2
  276. package/dist/esm/chunk-UCHGKGCF.mjs +0 -2
  277. package/dist/esm/chunk-UCHGKGCF.mjs.map +0 -1
  278. package/dist/esm/chunk-UIVJXLRM.mjs +0 -1
  279. package/dist/esm/chunk-V6JFR2CB.mjs +0 -2
  280. package/dist/esm/chunk-V6JFR2CB.mjs.map +0 -1
  281. package/dist/esm/chunk-XZYPAQCU.mjs +0 -2
  282. package/dist/esm/chunk-YL2EDK5M.mjs +0 -2
  283. package/dist/esm/chunk-YL2EDK5M.mjs.map +0 -1
  284. package/dist/esm/chunk-ZFIMVSCR.mjs +0 -2
  285. package/dist/esm/chunk-ZFIMVSCR.mjs.map +0 -1
  286. package/dist/esm/core/account.d.mts +0 -184
  287. package/dist/esm/core/account.mjs +0 -2
  288. package/dist/esm/core/crypto/anyPublicKey.d.mts +0 -59
  289. package/dist/esm/core/crypto/anyPublicKey.mjs +0 -2
  290. package/dist/esm/core/crypto/anySignature.d.mts +0 -31
  291. package/dist/esm/core/crypto/anySignature.mjs +0 -2
  292. package/dist/esm/core/crypto/asymmetricCrypto.d.mts +0 -74
  293. package/dist/esm/core/crypto/asymmetricCrypto.mjs +0 -2
  294. package/src/core/account.ts +0 -282
  295. package/src/core/crypto/anyPublicKey.ts +0 -92
  296. package/src/core/crypto/anySignature.ts +0 -56
  297. package/src/core/crypto/asymmetricCrypto.ts +0 -77
  298. /package/dist/esm/{chunk-S64WKSMI.mjs.map → chunk-2E2JOGE5.mjs.map} +0 -0
  299. /package/dist/esm/{chunk-4OI7MPFH.mjs.map → chunk-52RTAMN7.mjs.map} +0 -0
  300. /package/dist/esm/{chunk-R56OJ4XC.mjs.map → chunk-7U36LMP4.mjs.map} +0 -0
  301. /package/dist/esm/{chunk-NWRKJFHV.mjs.map → chunk-ARIC32W7.mjs.map} +0 -0
  302. /package/dist/esm/{chunk-SPOHAEHR.mjs.map → chunk-B7M3OWHV.mjs.map} +0 -0
  303. /package/dist/esm/{chunk-6SRENFWH.mjs.map → chunk-BBUAAJRA.mjs.map} +0 -0
  304. /package/dist/esm/{chunk-PMWH5IGI.mjs.map → chunk-CHA5DSSD.mjs.map} +0 -0
  305. /package/dist/esm/{chunk-JJ6Y35DF.mjs.map → chunk-DGOT2VR5.mjs.map} +0 -0
  306. /package/dist/esm/{chunk-EUHPML5E.mjs.map → chunk-EF2F7NWO.mjs.map} +0 -0
  307. /package/dist/esm/{chunk-FRLPX47J.mjs.map → chunk-EQZ757ES.mjs.map} +0 -0
  308. /package/dist/esm/{chunk-Y4AKS4CY.mjs.map → chunk-F67Y7YH6.mjs.map} +0 -0
  309. /package/dist/esm/{chunk-KJGQ4ILY.mjs.map → chunk-FVMVV4V3.mjs.map} +0 -0
  310. /package/dist/esm/{chunk-V2FPYAK7.mjs.map → chunk-GQOOXOTN.mjs.map} +0 -0
  311. /package/dist/esm/{chunk-GD4ULEBC.mjs.map → chunk-I3TCHVQQ.mjs.map} +0 -0
  312. /package/dist/esm/{chunk-JQVT2K7G.mjs.map → chunk-ILJWEPDW.mjs.map} +0 -0
  313. /package/dist/esm/{chunk-Q3HAJVCM.mjs.map → chunk-INORE66K.mjs.map} +0 -0
  314. /package/dist/esm/{chunk-PIXE7MN5.mjs.map → chunk-J6MWD4XN.mjs.map} +0 -0
  315. /package/dist/esm/{chunk-UIVJXLRM.mjs.map → chunk-KUX6GQ2E.mjs.map} +0 -0
  316. /package/dist/esm/{chunk-ENDUXRTK.mjs.map → chunk-KWJTVJ7C.mjs.map} +0 -0
  317. /package/dist/esm/{chunk-W4UDMBMU.mjs.map → chunk-LLL2LFYH.mjs.map} +0 -0
  318. /package/dist/esm/{chunk-2WFMD6C6.mjs.map → chunk-N65SOKJQ.mjs.map} +0 -0
  319. /package/dist/esm/{chunk-Q5HK3U64.mjs.map → chunk-NL3XVNS5.mjs.map} +0 -0
  320. /package/dist/esm/{chunk-M3WNE7MU.mjs.map → chunk-NURFZOR4.mjs.map} +0 -0
  321. /package/dist/esm/{chunk-AFPJ2XXN.mjs.map → chunk-OG56TYZE.mjs.map} +0 -0
  322. /package/dist/esm/{core/account.mjs.map → chunk-QE4ASJ5K.mjs.map} +0 -0
  323. /package/dist/esm/{chunk-XBVORX5O.mjs.map → chunk-R4VJDSIP.mjs.map} +0 -0
  324. /package/dist/esm/{chunk-2H5Z5EHH.mjs.map → chunk-TN5BUH4F.mjs.map} +0 -0
  325. /package/dist/esm/{chunk-VPQ46CAO.mjs.map → chunk-UIUSDBCL.mjs.map} +0 -0
  326. /package/dist/esm/{chunk-4M46AWXX.mjs.map → chunk-UMLDKLDL.mjs.map} +0 -0
  327. /package/dist/esm/{core/crypto/anyPublicKey.mjs.map → chunk-UVSRX4SV.mjs.map} +0 -0
  328. /package/dist/esm/{chunk-2DNPRIS5.mjs.map → chunk-VEVBHH3M.mjs.map} +0 -0
  329. /package/dist/esm/{chunk-QGIJNA37.mjs.map → chunk-VMXBMAYK.mjs.map} +0 -0
  330. /package/dist/esm/{chunk-GD5TZLBF.mjs.map → chunk-X5C3LYI7.mjs.map} +0 -0
  331. /package/dist/esm/{chunk-QRQAR6XO.mjs.map → chunk-XTPFQ4MH.mjs.map} +0 -0
  332. /package/dist/esm/{chunk-LATJGGVX.mjs.map → chunk-Y5AJLNUD.mjs.map} +0 -0
  333. /package/dist/esm/{chunk-VKZCIGKY.mjs.map → chunk-YR2R3LW4.mjs.map} +0 -0
  334. /package/dist/esm/core/{crypto/anySignature.mjs.map → account/Account.mjs.map} +0 -0
  335. /package/dist/esm/core/{crypto/asymmetricCrypto.mjs.map → account/Ed25519Account.mjs.map} +0 -0
@@ -1,12 +1,30 @@
1
- import { Hex } from "../hex";
2
- import { HexInput } from "../../types";
1
+ import { SigningScheme as AuthenticationKeyScheme } from "../../types";
3
2
  import { Deserializer } from "../../bcs/deserializer";
4
3
  import { Serializer } from "../../bcs/serializer";
5
- import { AnyPublicKey } from "./anyPublicKey";
6
- import { AnySignature } from "./anySignature";
7
- import { PublicKey } from "./asymmetricCrypto";
4
+ import { AuthenticationKey } from "../authenticationKey";
5
+ import { AccountPublicKey, PublicKey, VerifySignatureArgs } from "./publicKey";
6
+ import { Signature } from "./signature";
7
+ import { AnyPublicKey, AnySignature } from "./singleKey";
8
8
 
9
- export class MultiKey extends PublicKey {
9
+ /* eslint-disable no-bitwise */
10
+
11
+ function bitCount(byte: number) {
12
+ let n = byte;
13
+ n -= (n >> 1) & 0x55555555;
14
+ n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
15
+ return (((n + (n >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24;
16
+ }
17
+
18
+ /* eslint-enable no-bitwise */
19
+
20
+ /**
21
+ * Represents the public key of a multi-agent account.
22
+ *
23
+ * The public keys of each individual agent can be any type of public key supported by Aptos.
24
+ * Since [AIP-55](https://github.com/aptos-foundation/AIPs/pull/263) Aptos supports
25
+ * `Legacy` and `Unified` authentication keys.
26
+ */
27
+ export class MultiKey extends AccountPublicKey {
10
28
  /**
11
29
  * List of any public keys
12
30
  */
@@ -17,13 +35,15 @@ export class MultiKey extends PublicKey {
17
35
  */
18
36
  public readonly signaturesRequired: number;
19
37
 
20
- constructor(args: { publicKeys: PublicKey[]; signaturesRequired: number }) {
38
+ // region Constructors
39
+
40
+ constructor(args: { publicKeys: Array<PublicKey>; signaturesRequired: number }) {
21
41
  super();
22
42
  const { publicKeys, signaturesRequired } = args;
23
43
 
24
44
  // Validate number of public keys is greater than signature required
25
45
  if (signaturesRequired < 1) {
26
- throw new Error("The number of required signatures needs to be greater then 0");
46
+ throw new Error("The number of required signatures needs to be greater than 0");
27
47
  }
28
48
 
29
49
  // Validate number of public keys is greater than signature required
@@ -33,25 +53,52 @@ export class MultiKey extends PublicKey {
33
53
  );
34
54
  }
35
55
 
36
- const keys: AnyPublicKey[] = [];
37
- publicKeys.forEach((publicKey) => {
38
- if (publicKey instanceof AnyPublicKey) {
39
- keys.push(publicKey);
40
- } else {
41
- // if public key is instance of a legacy authentication key, i.e
42
- // Legacy Ed25519, convert it into AnyPublicKey
43
- keys.push(new AnyPublicKey(publicKey));
44
- }
45
- });
56
+ // Make sure that all keys are normalized to the SingleKey authentication scheme
57
+ this.publicKeys = publicKeys.map((publicKey) =>
58
+ publicKey instanceof AnyPublicKey ? publicKey : new AnyPublicKey(publicKey),
59
+ );
46
60
 
47
- this.publicKeys = keys;
48
61
  this.signaturesRequired = signaturesRequired;
49
62
  }
50
63
 
64
+ // endregion
65
+
66
+ // region AccountPublicKey
67
+
68
+ // eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
69
+ verifySignature(args: VerifySignatureArgs): boolean {
70
+ throw new Error("not implemented");
71
+ }
72
+
73
+ authKey(): AuthenticationKey {
74
+ return AuthenticationKey.fromSchemeAndBytes({
75
+ scheme: AuthenticationKeyScheme.MultiKey,
76
+ input: this.toUint8Array(),
77
+ });
78
+ }
79
+
51
80
  toUint8Array(): Uint8Array {
52
81
  return this.bcsToBytes();
53
82
  }
54
83
 
84
+ // endregion
85
+
86
+ // region Serializable
87
+
88
+ serialize(serializer: Serializer): void {
89
+ serializer.serializeVector(this.publicKeys);
90
+ serializer.serializeU8(this.signaturesRequired);
91
+ }
92
+
93
+ static deserialize(deserializer: Deserializer): MultiKey {
94
+ const keys = deserializer.deserializeVector(AnyPublicKey);
95
+ const signaturesRequired = deserializer.deserializeU8();
96
+
97
+ return new MultiKey({ publicKeys: keys, signaturesRequired });
98
+ }
99
+
100
+ // endregion
101
+
55
102
  /**
56
103
  * Create a bitmap that holds the mapping from the original public keys
57
104
  * to the signatures passed in
@@ -92,31 +139,142 @@ export class MultiKey extends PublicKey {
92
139
 
93
140
  return bitmap;
94
141
  }
142
+ }
143
+
144
+ export class MultiKeySignature extends Signature {
145
+ /**
146
+ * Number of bytes in the bitmap representing who signed the transaction (32-bits)
147
+ */
148
+ static BITMAP_LEN: number = 4;
149
+
150
+ /**
151
+ * Maximum number of Ed25519 signatures supported
152
+ */
153
+ static MAX_SIGNATURES_SUPPORTED = MultiKeySignature.BITMAP_LEN * 8;
154
+
155
+ /**
156
+ * The list of underlying Ed25519 signatures
157
+ */
158
+ public readonly signatures: AnySignature[];
159
+
160
+ /**
161
+ * 32-bit Bitmap representing who signed the transaction
162
+ *
163
+ * This is represented where each public key can be masked to determine whether the message was signed by that key.
164
+ */
165
+ public readonly bitmap: Uint8Array;
166
+
167
+ /**
168
+ * Signature for a K-of-N multi-sig transaction.
169
+ *
170
+ * @see {@link
171
+ * https://aptos.dev/integration/creating-a-signed-transaction/#multisignature-transactions | Creating a Signed Transaction}
172
+ *
173
+ * @param args.signatures A list of signatures
174
+ * @param args.bitmap 4 bytes, at most 32 signatures are supported. If Nth bit value is `1`, the Nth
175
+ * signature should be provided in `signatures`. Bits are read from left to right
176
+ */
177
+ constructor(args: { signatures: Array<Signature | AnySignature>; bitmap: Uint8Array | number[] }) {
178
+ super();
179
+ const { signatures, bitmap } = args;
180
+
181
+ if (signatures.length > MultiKeySignature.MAX_SIGNATURES_SUPPORTED) {
182
+ throw new Error(`The number of signatures cannot be greater than ${MultiKeySignature.MAX_SIGNATURES_SUPPORTED}`);
183
+ }
184
+
185
+ // Make sure that all signatures are normalized to the SingleKey authentication scheme
186
+ this.signatures = signatures.map((signature) =>
187
+ signature instanceof AnySignature ? signature : new AnySignature(signature),
188
+ );
189
+
190
+ if (!(bitmap instanceof Uint8Array)) {
191
+ this.bitmap = MultiKeySignature.createBitmap({ bits: bitmap });
192
+ } else if (bitmap.length !== MultiKeySignature.BITMAP_LEN) {
193
+ throw new Error(`"bitmap" length should be ${MultiKeySignature.BITMAP_LEN}`);
194
+ } else {
195
+ this.bitmap = bitmap;
196
+ }
197
+
198
+ const nSignatures = this.bitmap.reduce((acc, byte) => acc + bitCount(byte), 0);
199
+ if (nSignatures !== this.signatures.length) {
200
+ throw new Error(`Expecting ${nSignatures} signatures from the bitmap, but got ${this.signatures.length}`);
201
+ }
202
+ }
95
203
 
96
204
  /**
97
- * Hex string representation the multi key bytes
205
+ * Helper method to create a bitmap out of the specified bit positions
206
+ * @param args.bits The bitmap positions that should be set. A position starts at index 0.
207
+ * Valid position should range between 0 and 31.
208
+ * @example
209
+ * Here's an example of valid `bits`
210
+ * ```
211
+ * [0, 2, 31]
212
+ * ```
213
+ * `[0, 2, 31]` means the 1st, 3rd and 32nd bits should be set in the bitmap.
214
+ * The result bitmap should be 0b1010000000000000000000000000001
98
215
  *
99
- * @returns string
216
+ * @returns bitmap that is 32bit long
100
217
  */
101
- toString(): string {
102
- return Hex.fromHexInput(this.toUint8Array()).toString();
218
+ static createBitmap(args: { bits: number[] }): Uint8Array {
219
+ const { bits } = args;
220
+ // Bits are read from left to right. e.g. 0b10000000 represents the first bit is set in one byte.
221
+ // The decimal value of 0b10000000 is 128.
222
+ const firstBitInByte = 128;
223
+ const bitmap = new Uint8Array([0, 0, 0, 0]);
224
+
225
+ // Check if duplicates exist in bits
226
+ const dupCheckSet = new Set();
227
+
228
+ bits.forEach((bit: number) => {
229
+ if (bit >= MultiKeySignature.MAX_SIGNATURES_SUPPORTED) {
230
+ throw new Error(`Cannot have a signature larger than ${MultiKeySignature.MAX_SIGNATURES_SUPPORTED - 1}.`);
231
+ }
232
+
233
+ if (dupCheckSet.has(bit)) {
234
+ throw new Error("Duplicate bits detected.");
235
+ }
236
+
237
+ dupCheckSet.add(bit);
238
+
239
+ const byteOffset = Math.floor(bit / 8);
240
+
241
+ let byte = bitmap[byteOffset];
242
+
243
+ // eslint-disable-next-line no-bitwise
244
+ byte |= firstBitInByte >> bit % 8;
245
+
246
+ bitmap[byteOffset] = byte;
247
+ });
248
+
249
+ return bitmap;
103
250
  }
104
251
 
105
- // TODO
106
- // eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
107
- verifySignature(args: { message: HexInput; signature: AnySignature }): boolean {
108
- throw new Error("not implemented");
252
+ // region Signature
253
+
254
+ toUint8Array(): Uint8Array {
255
+ return this.bcsToBytes();
109
256
  }
110
257
 
258
+ // endregion
259
+
260
+ // region Serializable
261
+
111
262
  serialize(serializer: Serializer): void {
112
- serializer.serializeVector(this.publicKeys);
113
- serializer.serializeU8(this.signaturesRequired);
263
+ // Note: we should not need to serialize the vector length, as it can be derived from the bitmap
264
+ serializer.serializeVector(this.signatures);
265
+ serializer.serializeBytes(this.bitmap);
114
266
  }
115
267
 
116
- static deserialize(deserializer: Deserializer): MultiKey {
117
- const keys = deserializer.deserializeVector(AnyPublicKey);
118
- const signaturesRequired = deserializer.deserializeU8();
119
-
120
- return new MultiKey({ publicKeys: keys, signaturesRequired });
268
+ static deserialize(deserializer: Deserializer): MultiKeySignature {
269
+ const bitmap = deserializer.deserializeBytes();
270
+ const nSignatures = bitmap.reduce((acc, byte) => acc + bitCount(byte), 0);
271
+ const signatures: AnySignature[] = [];
272
+ for (let i = 0; i < nSignatures; i += 1) {
273
+ const signature = AnySignature.deserialize(deserializer);
274
+ signatures.push(signature);
275
+ }
276
+ return new MultiKeySignature({ signatures, bitmap });
121
277
  }
278
+
279
+ // endregion
122
280
  }
@@ -0,0 +1,25 @@
1
+ import { HexInput } from "../../types";
2
+ import { PublicKey } from "./publicKey";
3
+ import { Signature } from "./signature";
4
+
5
+ /**
6
+ * An abstract representation of a private key.
7
+ * It is associated to a signature scheme and provides signing capabilities.
8
+ */
9
+ export interface PrivateKey {
10
+ /**
11
+ * Sign the given message with the private key.
12
+ * @param message in HexInput format
13
+ */
14
+ sign(message: HexInput): Signature;
15
+
16
+ /**
17
+ * Derive the public key associated with the private key
18
+ */
19
+ publicKey(): PublicKey;
20
+
21
+ /**
22
+ * Get the private key in bytes (Uint8Array).
23
+ */
24
+ toUint8Array(): Uint8Array;
25
+ }
@@ -0,0 +1,52 @@
1
+ import { Serializable } from "../../bcs";
2
+ import { HexInput } from "../../types";
3
+ import { AuthenticationKey } from "../authenticationKey";
4
+ import { Hex } from "../hex";
5
+ import { Signature } from "./signature";
6
+
7
+ /**
8
+ * Arguments for verifying a signature
9
+ */
10
+ export interface VerifySignatureArgs {
11
+ message: HexInput;
12
+ signature: Signature;
13
+ }
14
+
15
+ /**
16
+ * An abstract representation of a public key.
17
+ *
18
+ * Provides a common interface for verifying any signature.
19
+ */
20
+ export abstract class PublicKey extends Serializable {
21
+ /**
22
+ * Verifies that the private key associated with this public key signed the message with the given signature.
23
+ * @param args.message The message that was signed
24
+ * @param args.signature The signature to verify
25
+ */
26
+ abstract verifySignature(args: VerifySignatureArgs): boolean;
27
+
28
+ /**
29
+ * Get the raw public key bytes
30
+ */
31
+ abstract toUint8Array(): Uint8Array;
32
+
33
+ /**
34
+ * Get the public key as a hex string with a 0x prefix e.g. 0x123456...
35
+ */
36
+ toString(): string {
37
+ const bytes = this.toUint8Array();
38
+ return Hex.fromHexInput(bytes).toString();
39
+ }
40
+ }
41
+
42
+ /**
43
+ * An abstract representation of an account public key.
44
+ *
45
+ * Provides a common interface for deriving an authentication key.
46
+ */
47
+ export abstract class AccountPublicKey extends PublicKey {
48
+ /**
49
+ * Get the authentication key associated with this public key
50
+ */
51
+ abstract authKey(): AuthenticationKey;
52
+ }
@@ -4,11 +4,13 @@
4
4
  import { sha3_256 } from "@noble/hashes/sha3";
5
5
  import { secp256k1 } from "@noble/curves/secp256k1";
6
6
  import { HDKey } from "@scure/bip32";
7
- import { PrivateKey, PublicKey, Signature } from "./asymmetricCrypto";
8
- import { Deserializer, Serializer } from "../../bcs";
7
+ import { Serializable, Deserializer, Serializer } from "../../bcs";
9
8
  import { Hex } from "../hex";
10
9
  import { HexInput } from "../../types";
11
10
  import { isValidBIP44Path, mnemonicToSeed } from "./hdKey";
11
+ import { PrivateKey } from "./privateKey";
12
+ import { PublicKey, VerifySignatureArgs } from "./publicKey";
13
+ import { Signature } from "./signature";
12
14
 
13
15
  /**
14
16
  * Represents the Secp256k1 ecdsa public key
@@ -37,38 +39,27 @@ export class Secp256k1PublicKey extends PublicKey {
37
39
  this.key = hex;
38
40
  }
39
41
 
40
- /**
41
- * Get the public key in bytes (Uint8Array).
42
- *
43
- * @returns Uint8Array representation of the public key
44
- */
42
+ // region PublicKey
43
+
44
+ verifySignature(args: VerifySignatureArgs): boolean {
45
+ const { message, signature } = args;
46
+ if (!(signature instanceof Secp256k1Signature)) {
47
+ return false;
48
+ }
49
+
50
+ const messageBytes = Hex.fromHexInput(message).toUint8Array();
51
+ const messageSha3Bytes = sha3_256(messageBytes);
52
+ const signatureBytes = signature.toUint8Array();
53
+ return secp256k1.verify(signatureBytes, messageSha3Bytes, this.key.toUint8Array());
54
+ }
55
+
45
56
  toUint8Array(): Uint8Array {
46
57
  return this.key.toUint8Array();
47
58
  }
48
59
 
49
- /**
50
- * Get the public key as a hex string with the 0x prefix.
51
- *
52
- * @returns string representation of the public key
53
- */
54
- toString(): string {
55
- return this.key.toString();
56
- }
60
+ // endregion
57
61
 
58
- /**
59
- * Verifies a signed data with a public key
60
- *
61
- * @param args.message message
62
- * @param args.signature The signature
63
- * @returns true if the signature is valid
64
- */
65
- verifySignature(args: { message: HexInput; signature: Secp256k1Signature }): boolean {
66
- const { message, signature } = args;
67
- const msgHex = Hex.fromHexInput(message).toUint8Array();
68
- const sha3Message = sha3_256(msgHex);
69
- const rawSignature = signature.toUint8Array();
70
- return secp256k1.verify(rawSignature, sha3Message, this.toUint8Array());
71
- }
62
+ // region Serializable
72
63
 
73
64
  serialize(serializer: Serializer): void {
74
65
  serializer.serializeBytes(this.key.toUint8Array());
@@ -79,11 +70,12 @@ export class Secp256k1PublicKey extends PublicKey {
79
70
  return new Secp256k1PublicKey(bytes);
80
71
  }
81
72
 
82
- static load(deserializer: Deserializer): Secp256k1PublicKey {
83
- const bytes = deserializer.deserializeBytes();
84
- return new Secp256k1PublicKey(bytes);
85
- }
73
+ // endregion
86
74
 
75
+ /**
76
+ * @deprecated use `instanceof Secp256k1PublicKey` instead
77
+ * @param publicKey
78
+ */
87
79
  static isPublicKey(publicKey: PublicKey): publicKey is Secp256k1PublicKey {
88
80
  return publicKey instanceof Secp256k1PublicKey;
89
81
  }
@@ -92,7 +84,7 @@ export class Secp256k1PublicKey extends PublicKey {
92
84
  /**
93
85
  * A Secp256k1 ecdsa private key
94
86
  */
95
- export class Secp256k1PrivateKey extends PrivateKey {
87
+ export class Secp256k1PrivateKey extends Serializable implements PrivateKey {
96
88
  /**
97
89
  * Length of Secp256k1 ecdsa private key
98
90
  */
@@ -104,6 +96,8 @@ export class Secp256k1PrivateKey extends PrivateKey {
104
96
  */
105
97
  private readonly key: Hex;
106
98
 
99
+ // region Constructors
100
+
107
101
  /**
108
102
  * Create a new PrivateKey instance from a Uint8Array or String.
109
103
  *
@@ -120,46 +114,6 @@ export class Secp256k1PrivateKey extends PrivateKey {
120
114
  this.key = privateKeyHex;
121
115
  }
122
116
 
123
- /**
124
- * Get the private key in bytes (Uint8Array).
125
- *
126
- * @returns
127
- */
128
- toUint8Array(): Uint8Array {
129
- return this.key.toUint8Array();
130
- }
131
-
132
- /**
133
- * Get the private key as a hex string with the 0x prefix.
134
- *
135
- * @returns string representation of the private key
136
- */
137
- toString(): string {
138
- return this.key.toString();
139
- }
140
-
141
- /**
142
- * Sign the given message with the private key.
143
- *
144
- * @param message in HexInput format
145
- * @returns Signature
146
- */
147
- sign(message: HexInput): Secp256k1Signature {
148
- const msgHex = Hex.fromHexInput(message);
149
- const sha3Message = sha3_256(msgHex.toUint8Array());
150
- const signature = secp256k1.sign(sha3Message, this.key.toUint8Array());
151
- return new Secp256k1Signature(signature.toCompactRawBytes());
152
- }
153
-
154
- serialize(serializer: Serializer): void {
155
- serializer.serializeBytes(this.toUint8Array());
156
- }
157
-
158
- static deserialize(deserializer: Deserializer): Secp256k1PrivateKey {
159
- const bytes = deserializer.deserializeBytes();
160
- return new Secp256k1PrivateKey(bytes);
161
- }
162
-
163
117
  /**
164
118
  * Generate a new random private key.
165
119
  *
@@ -170,16 +124,6 @@ export class Secp256k1PrivateKey extends PrivateKey {
170
124
  return new Secp256k1PrivateKey(hexInput);
171
125
  }
172
126
 
173
- /**
174
- * Derive the Secp256k1PublicKey from this private key.
175
- *
176
- * @returns Secp256k1PublicKey
177
- */
178
- publicKey(): Secp256k1PublicKey {
179
- const bytes = secp256k1.getPublicKey(this.key.toUint8Array(), false);
180
- return new Secp256k1PublicKey(bytes);
181
- }
182
-
183
127
  /**
184
128
  * Derives a private key from a mnemonic seed phrase.
185
129
  *
@@ -214,13 +158,76 @@ export class Secp256k1PrivateKey extends PrivateKey {
214
158
  return new Secp256k1PrivateKey(privateKey);
215
159
  }
216
160
 
161
+ // endregion
162
+
163
+ // region PrivateKey
164
+
165
+ /**
166
+ * Sign the given message with the private key.
167
+ *
168
+ * @param message in HexInput format
169
+ * @returns Signature
170
+ */
171
+ sign(message: HexInput): Secp256k1Signature {
172
+ const messageBytes = Hex.fromHexInput(message);
173
+ const messageHashBytes = sha3_256(messageBytes.toUint8Array());
174
+ const signature = secp256k1.sign(messageHashBytes, this.key.toUint8Array());
175
+ return new Secp256k1Signature(signature.toCompactRawBytes());
176
+ }
177
+
178
+ /**
179
+ * Derive the Secp256k1PublicKey from this private key.
180
+ *
181
+ * @returns Secp256k1PublicKey
182
+ */
183
+ publicKey(): Secp256k1PublicKey {
184
+ const bytes = secp256k1.getPublicKey(this.key.toUint8Array(), false);
185
+ return new Secp256k1PublicKey(bytes);
186
+ }
187
+
188
+ /**
189
+ * Get the private key in bytes (Uint8Array).
190
+ *
191
+ * @returns
192
+ */
193
+ toUint8Array(): Uint8Array {
194
+ return this.key.toUint8Array();
195
+ }
196
+
197
+ /**
198
+ * Get the private key as a hex string with the 0x prefix.
199
+ *
200
+ * @returns string representation of the private key
201
+ */
202
+ toString(): string {
203
+ return this.key.toString();
204
+ }
205
+
206
+ // endregion
207
+
208
+ // region Serializable
209
+
210
+ serialize(serializer: Serializer): void {
211
+ serializer.serializeBytes(this.toUint8Array());
212
+ }
213
+
214
+ static deserialize(deserializer: Deserializer): Secp256k1PrivateKey {
215
+ const bytes = deserializer.deserializeBytes();
216
+ return new Secp256k1PrivateKey(bytes);
217
+ }
218
+
219
+ // endregion
220
+
221
+ /**
222
+ * @deprecated use `instanceof Secp256k1PrivateKey` instead
223
+ */
217
224
  static isPrivateKey(privateKey: PrivateKey): privateKey is Secp256k1PrivateKey {
218
225
  return privateKey instanceof Secp256k1PrivateKey;
219
226
  }
220
227
  }
221
228
 
222
229
  /**
223
- * A signature of a message signed using an Secp256k1 ecdsa private key
230
+ * A signature of a message signed using a Secp256k1 ecdsa private key
224
231
  */
225
232
  export class Secp256k1Signature extends Signature {
226
233
  /**
@@ -234,6 +241,8 @@ export class Secp256k1Signature extends Signature {
234
241
  */
235
242
  private readonly data: Hex;
236
243
 
244
+ // region Constructors
245
+
237
246
  /**
238
247
  * Create a new Signature instance from a Uint8Array or String.
239
248
  *
@@ -241,31 +250,26 @@ export class Secp256k1Signature extends Signature {
241
250
  */
242
251
  constructor(hexInput: HexInput) {
243
252
  super();
244
-
245
- const hex = Hex.fromHexInput(hexInput);
246
- if (hex.toUint8Array().length !== Secp256k1Signature.LENGTH) {
247
- throw new Error(`Signature length should be ${Secp256k1Signature.LENGTH}, recieved ${hex.toUint8Array().length}`);
253
+ const data = Hex.fromHexInput(hexInput);
254
+ if (data.toUint8Array().length !== Secp256k1Signature.LENGTH) {
255
+ throw new Error(
256
+ `Signature length should be ${Secp256k1Signature.LENGTH}, received ${data.toUint8Array().length}`,
257
+ );
248
258
  }
249
- this.data = hex;
259
+ this.data = data;
250
260
  }
251
261
 
252
- /**
253
- * Get the signature in bytes (Uint8Array).
254
- *
255
- * @returns Uint8Array representation of the signature
256
- */
262
+ // endregion
263
+
264
+ // region Signature
265
+
257
266
  toUint8Array(): Uint8Array {
258
267
  return this.data.toUint8Array();
259
268
  }
260
269
 
261
- /**
262
- * Get the signature as a hex string with the 0x prefix.
263
- *
264
- * @returns string representation of the signature
265
- */
266
- toString(): string {
267
- return this.data.toString();
268
- }
270
+ // endregion
271
+
272
+ // region Serializable
269
273
 
270
274
  serialize(serializer: Serializer): void {
271
275
  serializer.serializeBytes(this.data.toUint8Array());
@@ -276,12 +280,5 @@ export class Secp256k1Signature extends Signature {
276
280
  return new Secp256k1Signature(hex);
277
281
  }
278
282
 
279
- static load(deserializer: Deserializer): Secp256k1Signature {
280
- const bytes = deserializer.deserializeBytes();
281
- return new Secp256k1Signature(bytes);
282
- }
283
-
284
- static isSignature(signature: Signature): signature is Secp256k1Signature {
285
- return signature instanceof Secp256k1Signature;
286
- }
283
+ // endregion
287
284
  }