@moveindustries/ts-sdk 5.1.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 (729) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +66 -0
  3. package/dist/common/accountAddress-DoqkxUqw.d.ts +7769 -0
  4. package/dist/common/chunk-56DGDNEY.js +4 -0
  5. package/dist/common/chunk-56DGDNEY.js.map +1 -0
  6. package/dist/common/cli/index.d.ts +316 -0
  7. package/dist/common/cli/index.js +2 -0
  8. package/dist/common/cli/index.js.map +1 -0
  9. package/dist/common/index.d.ts +10643 -0
  10. package/dist/common/index.js +482 -0
  11. package/dist/common/index.js.map +1 -0
  12. package/dist/esm/Ed25519Account-DsqenvLJ.d.mts +628 -0
  13. package/dist/esm/account/AbstractKeylessAccount.d.mts +336 -0
  14. package/dist/esm/account/AbstractKeylessAccount.mjs +2 -0
  15. package/dist/esm/account/AbstractKeylessAccount.mjs.map +1 -0
  16. package/dist/esm/account/AbstractedAccount.d.mts +64 -0
  17. package/dist/esm/account/AbstractedAccount.mjs +2 -0
  18. package/dist/esm/account/AbstractedAccount.mjs.map +1 -0
  19. package/dist/esm/account/Account.d.mts +8 -0
  20. package/dist/esm/account/Account.mjs +2 -0
  21. package/dist/esm/account/Account.mjs.map +1 -0
  22. package/dist/esm/account/AccountUtils.d.mts +38 -0
  23. package/dist/esm/account/AccountUtils.mjs +2 -0
  24. package/dist/esm/account/AccountUtils.mjs.map +1 -0
  25. package/dist/esm/account/DerivableAbstractedAccount.d.mts +59 -0
  26. package/dist/esm/account/DerivableAbstractedAccount.mjs +2 -0
  27. package/dist/esm/account/DerivableAbstractedAccount.mjs.map +1 -0
  28. package/dist/esm/account/Ed25519Account.d.mts +8 -0
  29. package/dist/esm/account/Ed25519Account.mjs +2 -0
  30. package/dist/esm/account/Ed25519Account.mjs.map +1 -0
  31. package/dist/esm/account/EphemeralKeyPair.d.mts +141 -0
  32. package/dist/esm/account/EphemeralKeyPair.mjs +2 -0
  33. package/dist/esm/account/EphemeralKeyPair.mjs.map +1 -0
  34. package/dist/esm/account/FederatedKeylessAccount.d.mts +118 -0
  35. package/dist/esm/account/FederatedKeylessAccount.mjs +2 -0
  36. package/dist/esm/account/FederatedKeylessAccount.mjs.map +1 -0
  37. package/dist/esm/account/KeylessAccount.d.mts +124 -0
  38. package/dist/esm/account/KeylessAccount.mjs +2 -0
  39. package/dist/esm/account/KeylessAccount.mjs.map +1 -0
  40. package/dist/esm/account/MultiEd25519Account.d.mts +102 -0
  41. package/dist/esm/account/MultiEd25519Account.mjs +2 -0
  42. package/dist/esm/account/MultiEd25519Account.mjs.map +1 -0
  43. package/dist/esm/account/MultiKeyAccount.d.mts +206 -0
  44. package/dist/esm/account/MultiKeyAccount.mjs +2 -0
  45. package/dist/esm/account/MultiKeyAccount.mjs.map +1 -0
  46. package/dist/esm/account/SingleKeyAccount.d.mts +8 -0
  47. package/dist/esm/account/SingleKeyAccount.mjs +2 -0
  48. package/dist/esm/account/SingleKeyAccount.mjs.map +1 -0
  49. package/dist/esm/account/index.d.mts +24 -0
  50. package/dist/esm/account/index.mjs +2 -0
  51. package/dist/esm/account/index.mjs.map +1 -0
  52. package/dist/esm/account/utils.d.mts +14 -0
  53. package/dist/esm/account/utils.mjs +2 -0
  54. package/dist/esm/account/utils.mjs.map +1 -0
  55. package/dist/esm/accountAddress-CNXtapt1.d.mts +6979 -0
  56. package/dist/esm/api/account/abstraction.d.mts +181 -0
  57. package/dist/esm/api/account/abstraction.mjs +2 -0
  58. package/dist/esm/api/account/abstraction.mjs.map +1 -0
  59. package/dist/esm/api/account.d.mts +852 -0
  60. package/dist/esm/api/account.mjs +2 -0
  61. package/dist/esm/api/account.mjs.map +1 -0
  62. package/dist/esm/api/ans.d.mts +504 -0
  63. package/dist/esm/api/ans.mjs +2 -0
  64. package/dist/esm/api/ans.mjs.map +1 -0
  65. package/dist/esm/api/coin.d.mts +81 -0
  66. package/dist/esm/api/coin.mjs +2 -0
  67. package/dist/esm/api/coin.mjs.map +1 -0
  68. package/dist/esm/api/digitalAsset.d.mts +1030 -0
  69. package/dist/esm/api/digitalAsset.mjs +2 -0
  70. package/dist/esm/api/digitalAsset.mjs.map +1 -0
  71. package/dist/esm/api/faucet.d.mts +80 -0
  72. package/dist/esm/api/faucet.mjs +2 -0
  73. package/dist/esm/api/faucet.mjs.map +1 -0
  74. package/dist/esm/api/fungibleAsset.d.mts +288 -0
  75. package/dist/esm/api/fungibleAsset.mjs +2 -0
  76. package/dist/esm/api/fungibleAsset.mjs.map +1 -0
  77. package/dist/esm/api/general.d.mts +303 -0
  78. package/dist/esm/api/general.mjs +2 -0
  79. package/dist/esm/api/general.mjs.map +1 -0
  80. package/dist/esm/api/index.d.mts +46 -0
  81. package/dist/esm/api/index.mjs +2 -0
  82. package/dist/esm/api/index.mjs.map +1 -0
  83. package/dist/esm/api/keyless.d.mts +170 -0
  84. package/dist/esm/api/keyless.mjs +2 -0
  85. package/dist/esm/api/keyless.mjs.map +1 -0
  86. package/dist/esm/api/movement.d.mts +113 -0
  87. package/dist/esm/api/movement.mjs +2 -0
  88. package/dist/esm/api/movement.mjs.map +1 -0
  89. package/dist/esm/api/movementConfig.d.mts +7 -0
  90. package/dist/esm/api/movementConfig.mjs +2 -0
  91. package/dist/esm/api/movementConfig.mjs.map +1 -0
  92. package/dist/esm/api/object.d.mts +80 -0
  93. package/dist/esm/api/object.mjs +2 -0
  94. package/dist/esm/api/object.mjs.map +1 -0
  95. package/dist/esm/api/staking.d.mts +134 -0
  96. package/dist/esm/api/staking.mjs +2 -0
  97. package/dist/esm/api/staking.mjs.map +1 -0
  98. package/dist/esm/api/table.d.mts +169 -0
  99. package/dist/esm/api/table.mjs +2 -0
  100. package/dist/esm/api/table.mjs.map +1 -0
  101. package/dist/esm/api/transaction.d.mts +679 -0
  102. package/dist/esm/api/transaction.mjs +2 -0
  103. package/dist/esm/api/transaction.mjs.map +1 -0
  104. package/dist/esm/api/transactionSubmission/build.d.mts +141 -0
  105. package/dist/esm/api/transactionSubmission/build.mjs +2 -0
  106. package/dist/esm/api/transactionSubmission/build.mjs.map +1 -0
  107. package/dist/esm/api/transactionSubmission/helpers.d.mts +98 -0
  108. package/dist/esm/api/transactionSubmission/helpers.mjs +2 -0
  109. package/dist/esm/api/transactionSubmission/helpers.mjs.map +1 -0
  110. package/dist/esm/api/transactionSubmission/management.d.mts +168 -0
  111. package/dist/esm/api/transactionSubmission/management.mjs +2 -0
  112. package/dist/esm/api/transactionSubmission/management.mjs.map +1 -0
  113. package/dist/esm/api/transactionSubmission/sign.d.mts +124 -0
  114. package/dist/esm/api/transactionSubmission/sign.mjs +2 -0
  115. package/dist/esm/api/transactionSubmission/sign.mjs.map +1 -0
  116. package/dist/esm/api/transactionSubmission/simulate.d.mts +181 -0
  117. package/dist/esm/api/transactionSubmission/simulate.mjs +2 -0
  118. package/dist/esm/api/transactionSubmission/simulate.mjs.map +1 -0
  119. package/dist/esm/api/transactionSubmission/submit.d.mts +142 -0
  120. package/dist/esm/api/transactionSubmission/submit.mjs +2 -0
  121. package/dist/esm/api/transactionSubmission/submit.mjs.map +1 -0
  122. package/dist/esm/api/utils.d.mts +45 -0
  123. package/dist/esm/api/utils.mjs +2 -0
  124. package/dist/esm/api/utils.mjs.map +1 -0
  125. package/dist/esm/bcs/consts.d.mts +28 -0
  126. package/dist/esm/bcs/consts.mjs +2 -0
  127. package/dist/esm/bcs/consts.mjs.map +1 -0
  128. package/dist/esm/bcs/deserializer.d.mts +7 -0
  129. package/dist/esm/bcs/deserializer.mjs +2 -0
  130. package/dist/esm/bcs/deserializer.mjs.map +1 -0
  131. package/dist/esm/bcs/index.d.mts +8 -0
  132. package/dist/esm/bcs/index.mjs +2 -0
  133. package/dist/esm/bcs/index.mjs.map +1 -0
  134. package/dist/esm/bcs/serializable/entryFunctionBytes.d.mts +65 -0
  135. package/dist/esm/bcs/serializable/entryFunctionBytes.mjs +2 -0
  136. package/dist/esm/bcs/serializable/entryFunctionBytes.mjs.map +1 -0
  137. package/dist/esm/bcs/serializable/fixedBytes.d.mts +7 -0
  138. package/dist/esm/bcs/serializable/fixedBytes.mjs +2 -0
  139. package/dist/esm/bcs/serializable/fixedBytes.mjs.map +1 -0
  140. package/dist/esm/bcs/serializable/movePrimitives.d.mts +7 -0
  141. package/dist/esm/bcs/serializable/movePrimitives.mjs +2 -0
  142. package/dist/esm/bcs/serializable/movePrimitives.mjs.map +1 -0
  143. package/dist/esm/bcs/serializable/moveStructs.d.mts +7 -0
  144. package/dist/esm/bcs/serializable/moveStructs.mjs +2 -0
  145. package/dist/esm/bcs/serializable/moveStructs.mjs.map +1 -0
  146. package/dist/esm/bcs/serializer.d.mts +7 -0
  147. package/dist/esm/bcs/serializer.mjs +2 -0
  148. package/dist/esm/bcs/serializer.mjs.map +1 -0
  149. package/dist/esm/chunk-2KDUIZKB.mjs +2 -0
  150. package/dist/esm/chunk-2KDUIZKB.mjs.map +1 -0
  151. package/dist/esm/chunk-2QTV4AOE.mjs +2 -0
  152. package/dist/esm/chunk-2QTV4AOE.mjs.map +1 -0
  153. package/dist/esm/chunk-47V7UGV5.mjs +4 -0
  154. package/dist/esm/chunk-47V7UGV5.mjs.map +1 -0
  155. package/dist/esm/chunk-4QMXOWHP.mjs +1 -0
  156. package/dist/esm/chunk-4QMXOWHP.mjs.map +1 -0
  157. package/dist/esm/chunk-4WPQQPUF.mjs +1 -0
  158. package/dist/esm/chunk-4WPQQPUF.mjs.map +1 -0
  159. package/dist/esm/chunk-5HXLZHDW.mjs +1 -0
  160. package/dist/esm/chunk-5HXLZHDW.mjs.map +1 -0
  161. package/dist/esm/chunk-5IMQPJ6J.mjs +2 -0
  162. package/dist/esm/chunk-5IMQPJ6J.mjs.map +1 -0
  163. package/dist/esm/chunk-5ZKA765G.mjs +2 -0
  164. package/dist/esm/chunk-5ZKA765G.mjs.map +1 -0
  165. package/dist/esm/chunk-6NO4QKAO.mjs +2 -0
  166. package/dist/esm/chunk-6NO4QKAO.mjs.map +1 -0
  167. package/dist/esm/chunk-7ECCT6PK.mjs +1 -0
  168. package/dist/esm/chunk-7ECCT6PK.mjs.map +1 -0
  169. package/dist/esm/chunk-7TTTMBAK.mjs +2 -0
  170. package/dist/esm/chunk-7TTTMBAK.mjs.map +1 -0
  171. package/dist/esm/chunk-A5L76YP7.mjs +2 -0
  172. package/dist/esm/chunk-A5L76YP7.mjs.map +1 -0
  173. package/dist/esm/chunk-ANTEUWH6.mjs +2 -0
  174. package/dist/esm/chunk-ANTEUWH6.mjs.map +1 -0
  175. package/dist/esm/chunk-CHWDP6AR.mjs +2 -0
  176. package/dist/esm/chunk-CHWDP6AR.mjs.map +1 -0
  177. package/dist/esm/chunk-CRCE7R4D.mjs +2 -0
  178. package/dist/esm/chunk-CRCE7R4D.mjs.map +1 -0
  179. package/dist/esm/chunk-D6HPXGEP.mjs +2 -0
  180. package/dist/esm/chunk-D6HPXGEP.mjs.map +1 -0
  181. package/dist/esm/chunk-DS6QB6HG.mjs +4 -0
  182. package/dist/esm/chunk-DS6QB6HG.mjs.map +1 -0
  183. package/dist/esm/chunk-FD6FGKYY.mjs +1 -0
  184. package/dist/esm/chunk-FD6FGKYY.mjs.map +1 -0
  185. package/dist/esm/chunk-FJRPU2NH.mjs +2 -0
  186. package/dist/esm/chunk-FJRPU2NH.mjs.map +1 -0
  187. package/dist/esm/chunk-FS5ZJKO7.mjs +2 -0
  188. package/dist/esm/chunk-FS5ZJKO7.mjs.map +1 -0
  189. package/dist/esm/chunk-FZY4PMEE.mjs +1 -0
  190. package/dist/esm/chunk-FZY4PMEE.mjs.map +1 -0
  191. package/dist/esm/chunk-G3MHXDYA.mjs +1 -0
  192. package/dist/esm/chunk-G3MHXDYA.mjs.map +1 -0
  193. package/dist/esm/chunk-GOXRBEIJ.mjs +2 -0
  194. package/dist/esm/chunk-GOXRBEIJ.mjs.map +1 -0
  195. package/dist/esm/chunk-HGLO5LDS.mjs +1 -0
  196. package/dist/esm/chunk-HGLO5LDS.mjs.map +1 -0
  197. package/dist/esm/chunk-HL2JMZ7N.mjs +2 -0
  198. package/dist/esm/chunk-HL2JMZ7N.mjs.map +1 -0
  199. package/dist/esm/chunk-I6YGBK5S.mjs +2 -0
  200. package/dist/esm/chunk-I6YGBK5S.mjs.map +1 -0
  201. package/dist/esm/chunk-K4NT6TTN.mjs +2 -0
  202. package/dist/esm/chunk-K4NT6TTN.mjs.map +1 -0
  203. package/dist/esm/chunk-KDMSOCZY.mjs +2 -0
  204. package/dist/esm/chunk-KDMSOCZY.mjs.map +1 -0
  205. package/dist/esm/chunk-KPJGWDSQ.mjs +7 -0
  206. package/dist/esm/chunk-KPJGWDSQ.mjs.map +1 -0
  207. package/dist/esm/chunk-MEWW7VTQ.mjs +2 -0
  208. package/dist/esm/chunk-MEWW7VTQ.mjs.map +1 -0
  209. package/dist/esm/chunk-NECL5FCQ.mjs +1 -0
  210. package/dist/esm/chunk-NECL5FCQ.mjs.map +1 -0
  211. package/dist/esm/chunk-NMFJJOGW.mjs +2 -0
  212. package/dist/esm/chunk-NMFJJOGW.mjs.map +1 -0
  213. package/dist/esm/chunk-NQUZ4UHR.mjs +2 -0
  214. package/dist/esm/chunk-NQUZ4UHR.mjs.map +1 -0
  215. package/dist/esm/chunk-NUB6KE73.mjs +2 -0
  216. package/dist/esm/chunk-NUB6KE73.mjs.map +1 -0
  217. package/dist/esm/chunk-OOOAVIMQ.mjs +2 -0
  218. package/dist/esm/chunk-OOOAVIMQ.mjs.map +1 -0
  219. package/dist/esm/chunk-PCESRJYO.mjs +2 -0
  220. package/dist/esm/chunk-PCESRJYO.mjs.map +1 -0
  221. package/dist/esm/chunk-PHRRBT44.mjs +2 -0
  222. package/dist/esm/chunk-PHRRBT44.mjs.map +1 -0
  223. package/dist/esm/chunk-PZ233FIY.mjs +2 -0
  224. package/dist/esm/chunk-PZ233FIY.mjs.map +1 -0
  225. package/dist/esm/chunk-R2G23RIY.mjs +2 -0
  226. package/dist/esm/chunk-R2G23RIY.mjs.map +1 -0
  227. package/dist/esm/chunk-RL4YPMN4.mjs +2 -0
  228. package/dist/esm/chunk-RL4YPMN4.mjs.map +1 -0
  229. package/dist/esm/chunk-RUIFVDWM.mjs +2 -0
  230. package/dist/esm/chunk-RUIFVDWM.mjs.map +1 -0
  231. package/dist/esm/chunk-RXHPS4IU.mjs +2 -0
  232. package/dist/esm/chunk-RXHPS4IU.mjs.map +1 -0
  233. package/dist/esm/chunk-S4D2KBYN.mjs +2 -0
  234. package/dist/esm/chunk-S4D2KBYN.mjs.map +1 -0
  235. package/dist/esm/chunk-SRXFRTHK.mjs +2 -0
  236. package/dist/esm/chunk-SRXFRTHK.mjs.map +1 -0
  237. package/dist/esm/chunk-SYXDZA4K.mjs +2 -0
  238. package/dist/esm/chunk-SYXDZA4K.mjs.map +1 -0
  239. package/dist/esm/chunk-UI4OF6CP.mjs +2 -0
  240. package/dist/esm/chunk-UI4OF6CP.mjs.map +1 -0
  241. package/dist/esm/chunk-UL777LTI.mjs +494 -0
  242. package/dist/esm/chunk-UL777LTI.mjs.map +1 -0
  243. package/dist/esm/chunk-UVP74ONT.mjs +2 -0
  244. package/dist/esm/chunk-UVP74ONT.mjs.map +1 -0
  245. package/dist/esm/chunk-UYVPNUH3.mjs +1 -0
  246. package/dist/esm/chunk-UYVPNUH3.mjs.map +1 -0
  247. package/dist/esm/chunk-V3MBJJTL.mjs +1 -0
  248. package/dist/esm/chunk-V3MBJJTL.mjs.map +1 -0
  249. package/dist/esm/chunk-V3O2SBO4.mjs +2 -0
  250. package/dist/esm/chunk-V3O2SBO4.mjs.map +1 -0
  251. package/dist/esm/chunk-VEZCMPUG.mjs +2 -0
  252. package/dist/esm/chunk-VEZCMPUG.mjs.map +1 -0
  253. package/dist/esm/chunk-VW3WBAAD.mjs +2 -0
  254. package/dist/esm/chunk-VW3WBAAD.mjs.map +1 -0
  255. package/dist/esm/chunk-WFAH73WN.mjs +2 -0
  256. package/dist/esm/chunk-WFAH73WN.mjs.map +1 -0
  257. package/dist/esm/chunk-WVDICMU4.mjs +2 -0
  258. package/dist/esm/chunk-WVDICMU4.mjs.map +1 -0
  259. package/dist/esm/chunk-XCURF77K.mjs +2 -0
  260. package/dist/esm/chunk-XCURF77K.mjs.map +1 -0
  261. package/dist/esm/chunk-Y6YW4BAZ.mjs +2 -0
  262. package/dist/esm/chunk-Y6YW4BAZ.mjs.map +1 -0
  263. package/dist/esm/chunk-YFFYA5U3.mjs +2 -0
  264. package/dist/esm/chunk-YFFYA5U3.mjs.map +1 -0
  265. package/dist/esm/chunk-YOHEYPDP.mjs +2 -0
  266. package/dist/esm/chunk-YOHEYPDP.mjs.map +1 -0
  267. package/dist/esm/chunk-ZP4DWSQA.mjs +2 -0
  268. package/dist/esm/chunk-ZP4DWSQA.mjs.map +1 -0
  269. package/dist/esm/cli/index.d.mts +10 -0
  270. package/dist/esm/cli/index.mjs +2 -0
  271. package/dist/esm/cli/index.mjs.map +1 -0
  272. package/dist/esm/cli/localNode.d.mts +67 -0
  273. package/dist/esm/cli/localNode.mjs +2 -0
  274. package/dist/esm/cli/localNode.mjs.map +1 -0
  275. package/dist/esm/cli/move.d.mts +257 -0
  276. package/dist/esm/cli/move.mjs +2 -0
  277. package/dist/esm/cli/move.mjs.map +1 -0
  278. package/dist/esm/client/core.d.mts +42 -0
  279. package/dist/esm/client/core.mjs +2 -0
  280. package/dist/esm/client/core.mjs.map +1 -0
  281. package/dist/esm/client/get.d.mts +125 -0
  282. package/dist/esm/client/get.mjs +2 -0
  283. package/dist/esm/client/get.mjs.map +1 -0
  284. package/dist/esm/client/index.d.mts +10 -0
  285. package/dist/esm/client/index.mjs +2 -0
  286. package/dist/esm/client/index.mjs.map +1 -0
  287. package/dist/esm/client/post.d.mts +158 -0
  288. package/dist/esm/client/post.mjs +2 -0
  289. package/dist/esm/client/post.mjs.map +1 -0
  290. package/dist/esm/core/account/index.d.mts +8 -0
  291. package/dist/esm/core/account/index.mjs +2 -0
  292. package/dist/esm/core/account/index.mjs.map +1 -0
  293. package/dist/esm/core/account/utils/address.d.mts +55 -0
  294. package/dist/esm/core/account/utils/address.mjs +2 -0
  295. package/dist/esm/core/account/utils/address.mjs.map +1 -0
  296. package/dist/esm/core/account/utils/index.d.mts +8 -0
  297. package/dist/esm/core/account/utils/index.mjs +2 -0
  298. package/dist/esm/core/account/utils/index.mjs.map +1 -0
  299. package/dist/esm/core/accountAddress.d.mts +7 -0
  300. package/dist/esm/core/accountAddress.mjs +2 -0
  301. package/dist/esm/core/accountAddress.mjs.map +1 -0
  302. package/dist/esm/core/authenticationKey.d.mts +7 -0
  303. package/dist/esm/core/authenticationKey.mjs +2 -0
  304. package/dist/esm/core/authenticationKey.mjs.map +1 -0
  305. package/dist/esm/core/common.d.mts +52 -0
  306. package/dist/esm/core/common.mjs +2 -0
  307. package/dist/esm/core/common.mjs.map +1 -0
  308. package/dist/esm/core/crypto/abstraction.d.mts +24 -0
  309. package/dist/esm/core/crypto/abstraction.mjs +2 -0
  310. package/dist/esm/core/crypto/abstraction.mjs.map +1 -0
  311. package/dist/esm/core/crypto/deserializationUtils.d.mts +28 -0
  312. package/dist/esm/core/crypto/deserializationUtils.mjs +2 -0
  313. package/dist/esm/core/crypto/deserializationUtils.mjs.map +1 -0
  314. package/dist/esm/core/crypto/ed25519.d.mts +7 -0
  315. package/dist/esm/core/crypto/ed25519.mjs +2 -0
  316. package/dist/esm/core/crypto/ed25519.mjs.map +1 -0
  317. package/dist/esm/core/crypto/ephemeral.d.mts +116 -0
  318. package/dist/esm/core/crypto/ephemeral.mjs +2 -0
  319. package/dist/esm/core/crypto/ephemeral.mjs.map +1 -0
  320. package/dist/esm/core/crypto/federatedKeyless.d.mts +13 -0
  321. package/dist/esm/core/crypto/federatedKeyless.mjs +2 -0
  322. package/dist/esm/core/crypto/federatedKeyless.mjs.map +1 -0
  323. package/dist/esm/core/crypto/hdKey.d.mts +95 -0
  324. package/dist/esm/core/crypto/hdKey.mjs +2 -0
  325. package/dist/esm/core/crypto/hdKey.mjs.map +1 -0
  326. package/dist/esm/core/crypto/index.d.mts +19 -0
  327. package/dist/esm/core/crypto/index.mjs +2 -0
  328. package/dist/esm/core/crypto/index.mjs.map +1 -0
  329. package/dist/esm/core/crypto/keyless.d.mts +13 -0
  330. package/dist/esm/core/crypto/keyless.mjs +2 -0
  331. package/dist/esm/core/crypto/keyless.mjs.map +1 -0
  332. package/dist/esm/core/crypto/multiEd25519.d.mts +7 -0
  333. package/dist/esm/core/crypto/multiEd25519.mjs +2 -0
  334. package/dist/esm/core/crypto/multiEd25519.mjs.map +1 -0
  335. package/dist/esm/core/crypto/multiKey.d.mts +7 -0
  336. package/dist/esm/core/crypto/multiKey.mjs +2 -0
  337. package/dist/esm/core/crypto/multiKey.mjs.map +1 -0
  338. package/dist/esm/core/crypto/poseidon.d.mts +59 -0
  339. package/dist/esm/core/crypto/poseidon.mjs +2 -0
  340. package/dist/esm/core/crypto/poseidon.mjs.map +1 -0
  341. package/dist/esm/core/crypto/privateKey.d.mts +7 -0
  342. package/dist/esm/core/crypto/privateKey.mjs +2 -0
  343. package/dist/esm/core/crypto/privateKey.mjs.map +1 -0
  344. package/dist/esm/core/crypto/proof.d.mts +18 -0
  345. package/dist/esm/core/crypto/proof.mjs +2 -0
  346. package/dist/esm/core/crypto/proof.mjs.map +1 -0
  347. package/dist/esm/core/crypto/publicKey.d.mts +7 -0
  348. package/dist/esm/core/crypto/publicKey.mjs +2 -0
  349. package/dist/esm/core/crypto/publicKey.mjs.map +1 -0
  350. package/dist/esm/core/crypto/secp256k1.d.mts +7 -0
  351. package/dist/esm/core/crypto/secp256k1.mjs +2 -0
  352. package/dist/esm/core/crypto/secp256k1.mjs.map +1 -0
  353. package/dist/esm/core/crypto/secp256r1.d.mts +306 -0
  354. package/dist/esm/core/crypto/secp256r1.mjs +2 -0
  355. package/dist/esm/core/crypto/secp256r1.mjs.map +1 -0
  356. package/dist/esm/core/crypto/signature.d.mts +7 -0
  357. package/dist/esm/core/crypto/signature.mjs +2 -0
  358. package/dist/esm/core/crypto/signature.mjs.map +1 -0
  359. package/dist/esm/core/crypto/singleKey.d.mts +7 -0
  360. package/dist/esm/core/crypto/singleKey.mjs +2 -0
  361. package/dist/esm/core/crypto/singleKey.mjs.map +1 -0
  362. package/dist/esm/core/crypto/types.d.mts +11 -0
  363. package/dist/esm/core/crypto/types.mjs +2 -0
  364. package/dist/esm/core/crypto/types.mjs.map +1 -0
  365. package/dist/esm/core/crypto/utils.d.mts +23 -0
  366. package/dist/esm/core/crypto/utils.mjs +2 -0
  367. package/dist/esm/core/crypto/utils.mjs.map +1 -0
  368. package/dist/esm/core/hex.d.mts +7 -0
  369. package/dist/esm/core/hex.mjs +2 -0
  370. package/dist/esm/core/hex.mjs.map +1 -0
  371. package/dist/esm/core/index.d.mts +20 -0
  372. package/dist/esm/core/index.mjs +2 -0
  373. package/dist/esm/core/index.mjs.map +1 -0
  374. package/dist/esm/errors/index.d.mts +131 -0
  375. package/dist/esm/errors/index.mjs +2 -0
  376. package/dist/esm/errors/index.mjs.map +1 -0
  377. package/dist/esm/federatedKeyless-D-d9d5aC.d.mts +869 -0
  378. package/dist/esm/index.d.mts +71 -0
  379. package/dist/esm/index.mjs +2 -0
  380. package/dist/esm/index.mjs.map +1 -0
  381. package/dist/esm/internal/abstraction.d.mts +27 -0
  382. package/dist/esm/internal/abstraction.mjs +2 -0
  383. package/dist/esm/internal/abstraction.mjs.map +1 -0
  384. package/dist/esm/internal/account.d.mts +453 -0
  385. package/dist/esm/internal/account.mjs +2 -0
  386. package/dist/esm/internal/account.mjs.map +1 -0
  387. package/dist/esm/internal/ans.d.mts +365 -0
  388. package/dist/esm/internal/ans.mjs +2 -0
  389. package/dist/esm/internal/ans.mjs.map +1 -0
  390. package/dist/esm/internal/coin.d.mts +31 -0
  391. package/dist/esm/internal/coin.mjs +2 -0
  392. package/dist/esm/internal/coin.mjs.map +1 -0
  393. package/dist/esm/internal/digitalAsset.d.mts +580 -0
  394. package/dist/esm/internal/digitalAsset.mjs +2 -0
  395. package/dist/esm/internal/digitalAsset.mjs.map +1 -0
  396. package/dist/esm/internal/faucet.d.mts +39 -0
  397. package/dist/esm/internal/faucet.mjs +2 -0
  398. package/dist/esm/internal/faucet.mjs.map +1 -0
  399. package/dist/esm/internal/fungibleAsset.d.mts +112 -0
  400. package/dist/esm/internal/fungibleAsset.mjs +2 -0
  401. package/dist/esm/internal/fungibleAsset.mjs.map +1 -0
  402. package/dist/esm/internal/general.d.mts +92 -0
  403. package/dist/esm/internal/general.mjs +2 -0
  404. package/dist/esm/internal/general.mjs.map +1 -0
  405. package/dist/esm/internal/keyless.d.mts +111 -0
  406. package/dist/esm/internal/keyless.mjs +2 -0
  407. package/dist/esm/internal/keyless.mjs.map +1 -0
  408. package/dist/esm/internal/object.d.mts +42 -0
  409. package/dist/esm/internal/object.mjs +2 -0
  410. package/dist/esm/internal/object.mjs.map +1 -0
  411. package/dist/esm/internal/staking.d.mts +60 -0
  412. package/dist/esm/internal/staking.mjs +2 -0
  413. package/dist/esm/internal/staking.mjs.map +1 -0
  414. package/dist/esm/internal/table.d.mts +66 -0
  415. package/dist/esm/internal/table.mjs +2 -0
  416. package/dist/esm/internal/table.mjs.map +1 -0
  417. package/dist/esm/internal/transaction.d.mts +199 -0
  418. package/dist/esm/internal/transaction.mjs +2 -0
  419. package/dist/esm/internal/transaction.mjs.map +1 -0
  420. package/dist/esm/internal/transactionSubmission.d.mts +165 -0
  421. package/dist/esm/internal/transactionSubmission.mjs +2 -0
  422. package/dist/esm/internal/transactionSubmission.mjs.map +1 -0
  423. package/dist/esm/internal/utils/index.d.mts +8 -0
  424. package/dist/esm/internal/utils/index.mjs +2 -0
  425. package/dist/esm/internal/utils/index.mjs.map +1 -0
  426. package/dist/esm/internal/utils/utils.d.mts +41 -0
  427. package/dist/esm/internal/utils/utils.mjs +2 -0
  428. package/dist/esm/internal/utils/utils.mjs.map +1 -0
  429. package/dist/esm/internal/view.d.mts +20 -0
  430. package/dist/esm/internal/view.mjs +2 -0
  431. package/dist/esm/internal/view.mjs.map +1 -0
  432. package/dist/esm/transactions/authenticator/account.d.mts +7 -0
  433. package/dist/esm/transactions/authenticator/account.mjs +2 -0
  434. package/dist/esm/transactions/authenticator/account.mjs.map +1 -0
  435. package/dist/esm/transactions/authenticator/index.d.mts +8 -0
  436. package/dist/esm/transactions/authenticator/index.mjs +2 -0
  437. package/dist/esm/transactions/authenticator/index.mjs.map +1 -0
  438. package/dist/esm/transactions/authenticator/transaction.d.mts +152 -0
  439. package/dist/esm/transactions/authenticator/transaction.mjs +2 -0
  440. package/dist/esm/transactions/authenticator/transaction.mjs.map +1 -0
  441. package/dist/esm/transactions/index.d.mts +15 -0
  442. package/dist/esm/transactions/index.mjs +2 -0
  443. package/dist/esm/transactions/index.mjs.map +1 -0
  444. package/dist/esm/transactions/instances/chainId.d.mts +7 -0
  445. package/dist/esm/transactions/instances/chainId.mjs +2 -0
  446. package/dist/esm/transactions/instances/chainId.mjs.map +1 -0
  447. package/dist/esm/transactions/instances/identifier.d.mts +7 -0
  448. package/dist/esm/transactions/instances/identifier.mjs +2 -0
  449. package/dist/esm/transactions/instances/identifier.mjs.map +1 -0
  450. package/dist/esm/transactions/instances/index.d.mts +10 -0
  451. package/dist/esm/transactions/instances/index.mjs +2 -0
  452. package/dist/esm/transactions/instances/index.mjs.map +1 -0
  453. package/dist/esm/transactions/instances/moduleId.d.mts +7 -0
  454. package/dist/esm/transactions/instances/moduleId.mjs +2 -0
  455. package/dist/esm/transactions/instances/moduleId.mjs.map +1 -0
  456. package/dist/esm/transactions/instances/multiAgentTransaction.d.mts +7 -0
  457. package/dist/esm/transactions/instances/multiAgentTransaction.mjs +2 -0
  458. package/dist/esm/transactions/instances/multiAgentTransaction.mjs.map +1 -0
  459. package/dist/esm/transactions/instances/rawTransaction.d.mts +7 -0
  460. package/dist/esm/transactions/instances/rawTransaction.mjs +2 -0
  461. package/dist/esm/transactions/instances/rawTransaction.mjs.map +1 -0
  462. package/dist/esm/transactions/instances/rotationProofChallenge.d.mts +58 -0
  463. package/dist/esm/transactions/instances/rotationProofChallenge.mjs +2 -0
  464. package/dist/esm/transactions/instances/rotationProofChallenge.mjs.map +1 -0
  465. package/dist/esm/transactions/instances/signedTransaction.d.mts +59 -0
  466. package/dist/esm/transactions/instances/signedTransaction.mjs +2 -0
  467. package/dist/esm/transactions/instances/signedTransaction.mjs.map +1 -0
  468. package/dist/esm/transactions/instances/simpleTransaction.d.mts +7 -0
  469. package/dist/esm/transactions/instances/simpleTransaction.mjs +2 -0
  470. package/dist/esm/transactions/instances/simpleTransaction.mjs.map +1 -0
  471. package/dist/esm/transactions/instances/transactionArgument.d.mts +7 -0
  472. package/dist/esm/transactions/instances/transactionArgument.mjs +2 -0
  473. package/dist/esm/transactions/instances/transactionArgument.mjs.map +1 -0
  474. package/dist/esm/transactions/instances/transactionPayload.d.mts +7 -0
  475. package/dist/esm/transactions/instances/transactionPayload.mjs +2 -0
  476. package/dist/esm/transactions/instances/transactionPayload.mjs.map +1 -0
  477. package/dist/esm/transactions/management/accountSequenceNumber.d.mts +123 -0
  478. package/dist/esm/transactions/management/accountSequenceNumber.mjs +2 -0
  479. package/dist/esm/transactions/management/accountSequenceNumber.mjs.map +1 -0
  480. package/dist/esm/transactions/management/asyncQueue.d.mts +77 -0
  481. package/dist/esm/transactions/management/asyncQueue.mjs +2 -0
  482. package/dist/esm/transactions/management/asyncQueue.mjs.map +1 -0
  483. package/dist/esm/transactions/management/index.d.mts +12 -0
  484. package/dist/esm/transactions/management/index.mjs +2 -0
  485. package/dist/esm/transactions/management/index.mjs.map +1 -0
  486. package/dist/esm/transactions/management/transactionWorker.d.mts +210 -0
  487. package/dist/esm/transactions/management/transactionWorker.mjs +2 -0
  488. package/dist/esm/transactions/management/transactionWorker.mjs.map +1 -0
  489. package/dist/esm/transactions/transactionBuilder/helpers.d.mts +159 -0
  490. package/dist/esm/transactions/transactionBuilder/helpers.mjs +2 -0
  491. package/dist/esm/transactions/transactionBuilder/helpers.mjs.map +1 -0
  492. package/dist/esm/transactions/transactionBuilder/index.d.mts +11 -0
  493. package/dist/esm/transactions/transactionBuilder/index.mjs +2 -0
  494. package/dist/esm/transactions/transactionBuilder/index.mjs.map +1 -0
  495. package/dist/esm/transactions/transactionBuilder/remoteAbi.d.mts +104 -0
  496. package/dist/esm/transactions/transactionBuilder/remoteAbi.mjs +2 -0
  497. package/dist/esm/transactions/transactionBuilder/remoteAbi.mjs.map +1 -0
  498. package/dist/esm/transactions/transactionBuilder/signingMessage.d.mts +62 -0
  499. package/dist/esm/transactions/transactionBuilder/signingMessage.mjs +2 -0
  500. package/dist/esm/transactions/transactionBuilder/signingMessage.mjs.map +1 -0
  501. package/dist/esm/transactions/transactionBuilder/transactionBuilder.d.mts +192 -0
  502. package/dist/esm/transactions/transactionBuilder/transactionBuilder.mjs +2 -0
  503. package/dist/esm/transactions/transactionBuilder/transactionBuilder.mjs.map +1 -0
  504. package/dist/esm/transactions/typeTag/index.d.mts +7 -0
  505. package/dist/esm/transactions/typeTag/index.mjs +2 -0
  506. package/dist/esm/transactions/typeTag/index.mjs.map +1 -0
  507. package/dist/esm/transactions/typeTag/parser.d.mts +81 -0
  508. package/dist/esm/transactions/typeTag/parser.mjs +2 -0
  509. package/dist/esm/transactions/typeTag/parser.mjs.map +1 -0
  510. package/dist/esm/transactions/types.d.mts +7 -0
  511. package/dist/esm/transactions/types.mjs +2 -0
  512. package/dist/esm/transactions/types.mjs.map +1 -0
  513. package/dist/esm/types/abstraction.d.mts +15 -0
  514. package/dist/esm/types/abstraction.mjs +2 -0
  515. package/dist/esm/types/abstraction.mjs.map +1 -0
  516. package/dist/esm/types/generated/operations.d.mts +709 -0
  517. package/dist/esm/types/generated/operations.mjs +1 -0
  518. package/dist/esm/types/generated/operations.mjs.map +1 -0
  519. package/dist/esm/types/generated/queries.d.mts +66 -0
  520. package/dist/esm/types/generated/queries.mjs +2 -0
  521. package/dist/esm/types/generated/queries.mjs.map +1 -0
  522. package/dist/esm/types/generated/types.d.mts +9495 -0
  523. package/dist/esm/types/generated/types.mjs +2 -0
  524. package/dist/esm/types/generated/types.mjs.map +1 -0
  525. package/dist/esm/types/index.d.mts +7 -0
  526. package/dist/esm/types/index.mjs +2 -0
  527. package/dist/esm/types/index.mjs.map +1 -0
  528. package/dist/esm/types/indexer.d.mts +186 -0
  529. package/dist/esm/types/indexer.mjs +2 -0
  530. package/dist/esm/types/indexer.mjs.map +1 -0
  531. package/dist/esm/types/keyless.d.mts +102 -0
  532. package/dist/esm/types/keyless.mjs +1 -0
  533. package/dist/esm/types/keyless.mjs.map +1 -0
  534. package/dist/esm/types/types.d.mts +7 -0
  535. package/dist/esm/types/types.mjs +2 -0
  536. package/dist/esm/types/types.mjs.map +1 -0
  537. package/dist/esm/utils/apiEndpoints.d.mts +51 -0
  538. package/dist/esm/utils/apiEndpoints.mjs +2 -0
  539. package/dist/esm/utils/apiEndpoints.mjs.map +1 -0
  540. package/dist/esm/utils/const.d.mts +90 -0
  541. package/dist/esm/utils/const.mjs +2 -0
  542. package/dist/esm/utils/const.mjs.map +1 -0
  543. package/dist/esm/utils/helpers.d.mts +174 -0
  544. package/dist/esm/utils/helpers.mjs +2 -0
  545. package/dist/esm/utils/helpers.mjs.map +1 -0
  546. package/dist/esm/utils/index.d.mts +9 -0
  547. package/dist/esm/utils/index.mjs +2 -0
  548. package/dist/esm/utils/index.mjs.map +1 -0
  549. package/dist/esm/utils/memoize.d.mts +26 -0
  550. package/dist/esm/utils/memoize.mjs +2 -0
  551. package/dist/esm/utils/memoize.mjs.map +1 -0
  552. package/dist/esm/utils/normalizeBundle.d.mts +35 -0
  553. package/dist/esm/utils/normalizeBundle.mjs +2 -0
  554. package/dist/esm/utils/normalizeBundle.mjs.map +1 -0
  555. package/dist/esm/version.d.mts +8 -0
  556. package/dist/esm/version.mjs +2 -0
  557. package/dist/esm/version.mjs.map +1 -0
  558. package/package.json +98 -0
  559. package/src/account/AbstractKeylessAccount.ts +579 -0
  560. package/src/account/AbstractedAccount.ts +124 -0
  561. package/src/account/Account.ts +354 -0
  562. package/src/account/AccountUtils.ts +216 -0
  563. package/src/account/DerivableAbstractedAccount.ts +103 -0
  564. package/src/account/Ed25519Account.ts +210 -0
  565. package/src/account/EphemeralKeyPair.ts +222 -0
  566. package/src/account/FederatedKeylessAccount.ts +178 -0
  567. package/src/account/KeylessAccount.ts +179 -0
  568. package/src/account/MultiEd25519Account.ts +181 -0
  569. package/src/account/MultiKeyAccount.ts +296 -0
  570. package/src/account/SingleKeyAccount.ts +277 -0
  571. package/src/account/index.ts +12 -0
  572. package/src/account/utils.ts +16 -0
  573. package/src/api/account/abstraction.ts +239 -0
  574. package/src/api/account.ts +1128 -0
  575. package/src/api/ans.ts +550 -0
  576. package/src/api/coin.ts +83 -0
  577. package/src/api/digitalAsset.ts +1203 -0
  578. package/src/api/faucet.ts +94 -0
  579. package/src/api/fungibleAsset.ts +371 -0
  580. package/src/api/general.ts +351 -0
  581. package/src/api/index.ts +6 -0
  582. package/src/api/keyless.ts +227 -0
  583. package/src/api/movement.ts +171 -0
  584. package/src/api/movementConfig.ts +334 -0
  585. package/src/api/object.ts +90 -0
  586. package/src/api/staking.ts +161 -0
  587. package/src/api/table.ts +193 -0
  588. package/src/api/transaction.ts +784 -0
  589. package/src/api/transactionSubmission/build.ts +153 -0
  590. package/src/api/transactionSubmission/helpers.ts +112 -0
  591. package/src/api/transactionSubmission/management.ts +211 -0
  592. package/src/api/transactionSubmission/sign.ts +142 -0
  593. package/src/api/transactionSubmission/simulate.ts +192 -0
  594. package/src/api/transactionSubmission/submit.ts +156 -0
  595. package/src/api/utils.ts +48 -0
  596. package/src/bcs/consts.ts +28 -0
  597. package/src/bcs/deserializer.ts +550 -0
  598. package/src/bcs/index.ts +10 -0
  599. package/src/bcs/serializable/entryFunctionBytes.ts +92 -0
  600. package/src/bcs/serializable/fixedBytes.ts +107 -0
  601. package/src/bcs/serializable/movePrimitives.ts +564 -0
  602. package/src/bcs/serializable/moveStructs.ts +619 -0
  603. package/src/bcs/serializer.ts +641 -0
  604. package/src/cli/index.ts +2 -0
  605. package/src/cli/localNode.ts +169 -0
  606. package/src/cli/move.ts +474 -0
  607. package/src/client/core.ts +120 -0
  608. package/src/client/get.ts +262 -0
  609. package/src/client/index.ts +7 -0
  610. package/src/client/post.ts +245 -0
  611. package/src/core/account/index.ts +1 -0
  612. package/src/core/account/utils/address.ts +85 -0
  613. package/src/core/account/utils/index.ts +1 -0
  614. package/src/core/accountAddress.ts +524 -0
  615. package/src/core/authenticationKey.ts +157 -0
  616. package/src/core/common.ts +60 -0
  617. package/src/core/crypto/abstraction.ts +52 -0
  618. package/src/core/crypto/deserializationUtils.ts +106 -0
  619. package/src/core/crypto/ed25519.ts +493 -0
  620. package/src/core/crypto/ephemeral.ts +185 -0
  621. package/src/core/crypto/federatedKeyless.ts +169 -0
  622. package/src/core/crypto/hdKey.ts +136 -0
  623. package/src/core/crypto/index.ts +21 -0
  624. package/src/core/crypto/keyless.ts +1700 -0
  625. package/src/core/crypto/multiEd25519.ts +434 -0
  626. package/src/core/crypto/multiKey.ts +498 -0
  627. package/src/core/crypto/poseidon.ts +231 -0
  628. package/src/core/crypto/privateKey.ts +115 -0
  629. package/src/core/crypto/proof.ts +9 -0
  630. package/src/core/crypto/publicKey.ts +106 -0
  631. package/src/core/crypto/secp256k1.ts +451 -0
  632. package/src/core/crypto/secp256r1.ts +495 -0
  633. package/src/core/crypto/signature.ts +57 -0
  634. package/src/core/crypto/singleKey.ts +351 -0
  635. package/src/core/crypto/types.ts +9 -0
  636. package/src/core/crypto/utils.ts +63 -0
  637. package/src/core/hex.ts +241 -0
  638. package/src/core/index.ts +10 -0
  639. package/src/errors/index.ts +457 -0
  640. package/src/index.ts +14 -0
  641. package/src/internal/abstraction.ts +79 -0
  642. package/src/internal/account.ts +1484 -0
  643. package/src/internal/ans.ts +853 -0
  644. package/src/internal/coin.ts +49 -0
  645. package/src/internal/digitalAsset.ts +1291 -0
  646. package/src/internal/faucet.ts +71 -0
  647. package/src/internal/fungibleAsset.ts +233 -0
  648. package/src/internal/general.ts +161 -0
  649. package/src/internal/keyless.ts +297 -0
  650. package/src/internal/object.ts +68 -0
  651. package/src/internal/queries/TokenActivitiesFieldsFragment.graphql +17 -0
  652. package/src/internal/queries/ansTokenFragment.graphql +11 -0
  653. package/src/internal/queries/currentTokenOwnershipFieldsFragment.graphql +46 -0
  654. package/src/internal/queries/getAccountAddressesForAuthKey.graphql +8 -0
  655. package/src/internal/queries/getAccountCoinCount.graphql +7 -0
  656. package/src/internal/queries/getAccountCoinsData.graphql +32 -0
  657. package/src/internal/queries/getAccountCollectionsWithOwnedTokens.graphql +33 -0
  658. package/src/internal/queries/getAccountOwnedTokens.graphql +11 -0
  659. package/src/internal/queries/getAccountOwnedTokensByTokenData.graphql +11 -0
  660. package/src/internal/queries/getAccountOwnedTokensFromCollectionAddress.graphql +11 -0
  661. package/src/internal/queries/getAccountTokensCount.graphql +7 -0
  662. package/src/internal/queries/getAccountTransactionsCount.graphql +7 -0
  663. package/src/internal/queries/getAuthKeysForPublicKey.graphql +11 -0
  664. package/src/internal/queries/getChainTopUserTransactions.graphql +5 -0
  665. package/src/internal/queries/getCollectionData.graphql +29 -0
  666. package/src/internal/queries/getCurrentFungibleAssetBalances.graphql +17 -0
  667. package/src/internal/queries/getDelegatedStakingActivities.graphql +12 -0
  668. package/src/internal/queries/getEvents.graphql +13 -0
  669. package/src/internal/queries/getFungibleAssetActivities.graphql +20 -0
  670. package/src/internal/queries/getFungibleAssetMetadata.graphql +18 -0
  671. package/src/internal/queries/getNames.graphql +11 -0
  672. package/src/internal/queries/getNumberOfDelegatorsQuery.graphql +9 -0
  673. package/src/internal/queries/getObjectData.graphql +16 -0
  674. package/src/internal/queries/getProcessorStatus.graphql +7 -0
  675. package/src/internal/queries/getTableItemsData.graphql +15 -0
  676. package/src/internal/queries/getTableItemsMetadata.graphql +12 -0
  677. package/src/internal/queries/getTokenActivity.graphql +11 -0
  678. package/src/internal/queries/getTokenCurrentOwner.graphql +11 -0
  679. package/src/internal/queries/getTokenData.graphql +39 -0
  680. package/src/internal/staking.ts +96 -0
  681. package/src/internal/table.ts +117 -0
  682. package/src/internal/transaction.ts +503 -0
  683. package/src/internal/transactionSubmission.ts +454 -0
  684. package/src/internal/utils/index.ts +4 -0
  685. package/src/internal/utils/utils.ts +86 -0
  686. package/src/internal/view.ts +61 -0
  687. package/src/transactions/authenticator/account.ts +405 -0
  688. package/src/transactions/authenticator/index.ts +6 -0
  689. package/src/transactions/authenticator/transaction.ts +288 -0
  690. package/src/transactions/index.ts +10 -0
  691. package/src/transactions/instances/chainId.ts +53 -0
  692. package/src/transactions/instances/identifier.ts +54 -0
  693. package/src/transactions/instances/index.ts +14 -0
  694. package/src/transactions/instances/moduleId.ts +77 -0
  695. package/src/transactions/instances/multiAgentTransaction.ts +92 -0
  696. package/src/transactions/instances/rawTransaction.ts +256 -0
  697. package/src/transactions/instances/rotationProofChallenge.ts +86 -0
  698. package/src/transactions/instances/signedTransaction.ts +73 -0
  699. package/src/transactions/instances/simpleTransaction.ts +83 -0
  700. package/src/transactions/instances/transactionArgument.ts +79 -0
  701. package/src/transactions/instances/transactionPayload.ts +676 -0
  702. package/src/transactions/management/accountSequenceNumber.ts +226 -0
  703. package/src/transactions/management/asyncQueue.ts +126 -0
  704. package/src/transactions/management/index.ts +2 -0
  705. package/src/transactions/management/transactionWorker.ts +396 -0
  706. package/src/transactions/transactionBuilder/helpers.ts +319 -0
  707. package/src/transactions/transactionBuilder/index.ts +8 -0
  708. package/src/transactions/transactionBuilder/remoteAbi.ts +655 -0
  709. package/src/transactions/transactionBuilder/signingMessage.ts +111 -0
  710. package/src/transactions/transactionBuilder/transactionBuilder.ts +863 -0
  711. package/src/transactions/typeTag/index.ts +926 -0
  712. package/src/transactions/typeTag/parser.ts +434 -0
  713. package/src/transactions/types.ts +518 -0
  714. package/src/types/abstraction.ts +14 -0
  715. package/src/types/codegen.yaml +33 -0
  716. package/src/types/generated/operations.ts +738 -0
  717. package/src/types/generated/queries.ts +926 -0
  718. package/src/types/generated/types.ts +10421 -0
  719. package/src/types/index.ts +2 -0
  720. package/src/types/indexer.ts +240 -0
  721. package/src/types/keyless.ts +94 -0
  722. package/src/types/types.ts +1713 -0
  723. package/src/utils/apiEndpoints.ts +107 -0
  724. package/src/utils/const.ts +100 -0
  725. package/src/utils/helpers.ts +287 -0
  726. package/src/utils/index.ts +4 -0
  727. package/src/utils/memoize.ts +76 -0
  728. package/src/utils/normalizeBundle.ts +34 -0
  729. package/src/version.ts +9 -0
@@ -0,0 +1,1700 @@
1
+ // Copyright © Move Industries
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // eslint-disable-next-line max-classes-per-file
5
+ import { Fp2 } from "@noble/curves/abstract/tower";
6
+ import { bytesToNumberBE } from "@noble/curves/abstract/utils";
7
+ import { ProjPointType } from "@noble/curves/abstract/weierstrass";
8
+ import { bn254 } from "@noble/curves/bn254";
9
+ import { sha3_256 } from "@noble/hashes/sha3";
10
+ import { encode } from "js-base64";
11
+ import { JwtPayload, jwtDecode } from "jwt-decode";
12
+ import { generateSigningMessage } from "../..";
13
+ import type { MovementConfig } from "../../api/movementConfig";
14
+ import { Deserializer, Serializable, Serializer } from "../../bcs";
15
+ import { getAptosFullNode } from "../../client";
16
+ import { KeylessError, KeylessErrorType } from "../../errors";
17
+ import {
18
+ AnyPublicKeyVariant,
19
+ EphemeralCertificateVariant,
20
+ HexInput,
21
+ LedgerVersionArg,
22
+ MoveResource,
23
+ SigningScheme,
24
+ ZkpVariant,
25
+ } from "../../types";
26
+ import {
27
+ Groth16VerificationKeyResponse,
28
+ KeylessConfigurationResponse,
29
+ MoveAnyStruct,
30
+ PatchedJWKsResponse,
31
+ } from "../../types/keyless";
32
+ import { base64UrlToBytes, getErrorMessage, nowInSeconds } from "../../utils";
33
+ import { memoizeAsync } from "../../utils/memoize";
34
+ import { AccountAddress, AccountAddressInput } from "../accountAddress";
35
+ import { AuthenticationKey } from "../authenticationKey";
36
+ import { Hex, hexToAsciiString } from "../hex";
37
+ import { Ed25519PublicKey, Ed25519Signature } from "./ed25519";
38
+ import { EphemeralPublicKey, EphemeralSignature } from "./ephemeral";
39
+ import { FederatedKeylessPublicKey } from "./federatedKeyless";
40
+ import { bigIntToBytesLE, bytesToBigIntLE, hashStrToField, padAndPackBytesWithLen, poseidonHash } from "./poseidon";
41
+ import { Proof } from "./proof";
42
+ import { AccountPublicKey, PublicKey } from "./publicKey";
43
+ import { Signature } from "./signature";
44
+
45
+ /**
46
+ * @group Implementation
47
+ * @category Serialization
48
+ */
49
+ export const EPK_HORIZON_SECS = 10000000;
50
+ /**
51
+ * @group Implementation
52
+ * @category Serialization
53
+ */
54
+ export const MAX_AUD_VAL_BYTES = 120;
55
+ /**
56
+ * @group Implementation
57
+ * @category Serialization
58
+ */
59
+ export const MAX_UID_KEY_BYTES = 30;
60
+ /**
61
+ * @group Implementation
62
+ * @category Serialization
63
+ */
64
+ export const MAX_UID_VAL_BYTES = 330;
65
+ /**
66
+ * @group Implementation
67
+ * @category Serialization
68
+ */
69
+ export const MAX_ISS_VAL_BYTES = 120;
70
+ /**
71
+ * @group Implementation
72
+ * @category Serialization
73
+ */
74
+ export const MAX_EXTRA_FIELD_BYTES = 350;
75
+ /**
76
+ * @group Implementation
77
+ * @category Serialization
78
+ */
79
+ export const MAX_JWT_HEADER_B64_BYTES = 300;
80
+ /**
81
+ * @group Implementation
82
+ * @category Serialization
83
+ */
84
+ export const MAX_COMMITED_EPK_BYTES = 93;
85
+
86
+ /**
87
+ * Represents a Keyless Public Key used for authentication.
88
+ *
89
+ * This class encapsulates the public key functionality for keyless authentication,
90
+ * including methods for generating and verifying signatures, as well as serialization
91
+ * and deserialization of the key. The KeylessPublicKey is represented in the SDK
92
+ * as `AnyPublicKey`.
93
+ * @group Implementation
94
+ * @category Serialization
95
+ */
96
+ export class KeylessPublicKey extends AccountPublicKey {
97
+ /**
98
+ * The number of bytes that `idCommitment` should be
99
+ * @group Implementation
100
+ * @category Serialization
101
+ */
102
+ static readonly ID_COMMITMENT_LENGTH: number = 32;
103
+
104
+ /**
105
+ * The value of the 'iss' claim on the JWT which identifies the OIDC provider.
106
+ * @group Implementation
107
+ * @category Serialization
108
+ */
109
+ readonly iss: string;
110
+
111
+ /**
112
+ * A value representing a cryptographic commitment to a user identity.
113
+ *
114
+ * It is calculated from the aud, uidKey, uidVal, pepper.
115
+ * @group Implementation
116
+ * @category Serialization
117
+ */
118
+ readonly idCommitment: Uint8Array;
119
+
120
+ /**
121
+ * Constructs an instance with the specified parameters for cryptographic operations.
122
+ *
123
+ * @param args - The parameters required to initialize the instance.
124
+ * @param args.alphaG1 - The hex representation of the alpha G1 value.
125
+ * @param args.betaG2 - The hex representation of the beta G2 value.
126
+ * @param args.deltaG2 - The hex representation of the delta G2 value.
127
+ * @param args.gammaAbcG1 - An array containing two hex representations for gamma ABC G1 values.
128
+ * @param args.gammaG2 - The hex representation of the gamma G2 value.
129
+ * @group Implementation
130
+ * @category Serialization
131
+ */
132
+ // TODO: Fix the JSDoc for the below values
133
+ constructor(iss: string, idCommitment: HexInput) {
134
+ super();
135
+ const idcBytes = Hex.fromHexInput(idCommitment).toUint8Array();
136
+ if (idcBytes.length !== KeylessPublicKey.ID_COMMITMENT_LENGTH) {
137
+ throw new Error(`Id Commitment length in bytes should be ${KeylessPublicKey.ID_COMMITMENT_LENGTH}`);
138
+ }
139
+ this.iss = iss;
140
+ this.idCommitment = idcBytes;
141
+ }
142
+
143
+ /**
144
+ * Get the authentication key for the keyless public key.
145
+ *
146
+ * @returns AuthenticationKey - The authentication key derived from the keyless public key.
147
+ * @group Implementation
148
+ * @category Serialization
149
+ */
150
+ authKey(): AuthenticationKey {
151
+ const serializer = new Serializer();
152
+ serializer.serializeU32AsUleb128(AnyPublicKeyVariant.Keyless);
153
+ serializer.serializeFixedBytes(this.bcsToBytes());
154
+ return AuthenticationKey.fromSchemeAndBytes({
155
+ scheme: SigningScheme.SingleKey,
156
+ input: serializer.toUint8Array(),
157
+ });
158
+ }
159
+
160
+ /**
161
+ * Verifies the validity of a signature for a given message.
162
+ *
163
+ * @param args - The arguments for signature verification.
164
+ * @param args.message - The message that was signed.
165
+ * @param args.signature - The signature to verify against the message.
166
+ * @param args.jwk - The JWK to use for verification.
167
+ * @param args.keylessConfig - The keyless configuration to use for verification.
168
+ * @returns true if the signature is valid; otherwise, false.
169
+ * @group Implementation
170
+ * @category Serialization
171
+ */
172
+ verifySignature(args: {
173
+ message: HexInput;
174
+ signature: Signature;
175
+ jwk: MoveJWK;
176
+ keylessConfig: KeylessConfiguration;
177
+ }): boolean {
178
+ try {
179
+ verifyKeylessSignatureWithJwkAndConfig({ ...args, publicKey: this });
180
+ return true;
181
+ } catch (error) {
182
+ if (error instanceof KeylessError) {
183
+ return false;
184
+ }
185
+ throw error;
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Verifies a keyless signature for a given message. It will fetch the keyless configuration and the JWK to
191
+ * use for verification from the appropriate network as defined by the movementConfig.
192
+ *
193
+ * @param args.movementConfig The aptos config to use for fetching the keyless configuration.
194
+ * @param args.message The message to verify the signature against.
195
+ * @param args.signature The signature to verify.
196
+ * @param args.options.throwErrorWithReason Whether to throw an error with the reason for the failure instead of returning false.
197
+ * @returns true if the signature is valid
198
+ */
199
+ async verifySignatureAsync(args: {
200
+ movementConfig: MovementConfig;
201
+ message: HexInput;
202
+ signature: Signature;
203
+ options?: { throwErrorWithReason?: boolean };
204
+ }): Promise<boolean> {
205
+ return verifyKeylessSignature({
206
+ ...args,
207
+ publicKey: this,
208
+ });
209
+ }
210
+
211
+ /**
212
+ * Serializes the current instance into a format suitable for transmission or storage.
213
+ * This function ensures that all relevant fields are properly serialized, including the proof and optional fields.
214
+ *
215
+ * @param serializer - The serializer instance used to perform the serialization.
216
+ * @param serializer.proof - The proof to be serialized.
217
+ * @param serializer.expHorizonSecs - The expiration horizon in seconds.
218
+ * @param serializer.extraField - An optional additional field for serialization.
219
+ * @param serializer.overrideAudVal - An optional override value for auditing.
220
+ * @param serializer.trainingWheelsSignature - An optional signature for training wheels.
221
+ * @group Implementation
222
+ * @category Serialization
223
+ */
224
+ serialize(serializer: Serializer): void {
225
+ serializer.serializeStr(this.iss);
226
+ serializer.serializeBytes(this.idCommitment);
227
+ }
228
+
229
+ /**
230
+ * Deserializes a ZeroKnowledgeSig object from the provided deserializer.
231
+ * This function allows you to reconstruct a ZeroKnowledgeSig instance from its serialized form.
232
+ *
233
+ * @param deserializer - The deserializer instance used to read the serialized data.
234
+ * @returns A new instance of ZeroKnowledgeSig.
235
+ * @group Implementation
236
+ * @category Serialization
237
+ */
238
+ static deserialize(deserializer: Deserializer): KeylessPublicKey {
239
+ const iss = deserializer.deserializeStr();
240
+ const addressSeed = deserializer.deserializeBytes();
241
+ return new KeylessPublicKey(iss, addressSeed);
242
+ }
243
+
244
+ /**
245
+ * Loads a KeylessPublicKey instance from the provided deserializer.
246
+ * This function is used to deserialize the necessary components to create a KeylessPublicKey.
247
+ *
248
+ * @param deserializer - The deserializer used to extract the string and byte data.
249
+ * @param deserializer.deserializeStr - A method to deserialize a string value.
250
+ * @param deserializer.deserializeBytes - A method to deserialize byte data.
251
+ * @returns A new instance of KeylessPublicKey.
252
+ * @group Implementation
253
+ * @category Serialization
254
+ */
255
+ static load(deserializer: Deserializer): KeylessPublicKey {
256
+ const iss = deserializer.deserializeStr();
257
+ const addressSeed = deserializer.deserializeBytes();
258
+ return new KeylessPublicKey(iss, addressSeed);
259
+ }
260
+
261
+ /**
262
+ * Determines if the provided public key is an instance of KeylessPublicKey.
263
+ *
264
+ * @param publicKey - The public key to check.
265
+ * @returns A boolean indicating whether the public key is a KeylessPublicKey instance.
266
+ * @group Implementation
267
+ * @category Serialization
268
+ */
269
+ static isPublicKey(publicKey: PublicKey): publicKey is KeylessPublicKey {
270
+ return publicKey instanceof KeylessPublicKey;
271
+ }
272
+
273
+ /**
274
+ * Creates a KeylessPublicKey from the JWT components plus pepper
275
+ *
276
+ * @param args.iss the iss of the identity
277
+ * @param args.uidKey the key to use to get the uidVal in the JWT token
278
+ * @param args.uidVal the value of the uidKey in the JWT token
279
+ * @param args.aud the client ID of the application
280
+ * @param args.pepper The pepper used to maintain privacy of the account
281
+ * @returns KeylessPublicKey
282
+ * @group Implementation
283
+ * @category Serialization
284
+ */
285
+ static create(args: {
286
+ iss: string;
287
+ uidKey: string;
288
+ uidVal: string;
289
+ aud: string;
290
+ pepper: HexInput;
291
+ }): KeylessPublicKey {
292
+ computeIdCommitment(args);
293
+ return new KeylessPublicKey(args.iss, computeIdCommitment(args));
294
+ }
295
+
296
+ /**
297
+ * Creates a KeylessPublicKey instance from a JWT and a pepper value.
298
+ * This function is useful for generating a public key that can be used for authentication based on the provided JWT claims and pepper.
299
+ *
300
+ * @param args - The arguments for creating the KeylessPublicKey.
301
+ * @param args.jwt - The JSON Web Token to decode.
302
+ * @param args.pepper - The pepper value used in the key creation process.
303
+ * @param args.uidKey - An optional key to retrieve the unique identifier from the JWT payload, defaults to "sub".
304
+ * @returns A KeylessPublicKey instance created from the provided JWT and pepper.
305
+ * @group Implementation
306
+ * @category Serialization
307
+ */
308
+ static fromJwtAndPepper(args: { jwt: string; pepper: HexInput; uidKey?: string }): KeylessPublicKey {
309
+ const { jwt, pepper, uidKey = "sub" } = args;
310
+ const jwtPayload = jwtDecode<JwtPayload & { [key: string]: string }>(jwt);
311
+ if (typeof jwtPayload.iss !== "string") {
312
+ throw new Error("iss was not found");
313
+ }
314
+ if (typeof jwtPayload.aud !== "string") {
315
+ throw new Error("aud was not found or an array of values");
316
+ }
317
+ const uidVal = jwtPayload[uidKey];
318
+ return KeylessPublicKey.create({ iss: jwtPayload.iss, uidKey, uidVal, aud: jwtPayload.aud, pepper });
319
+ }
320
+
321
+ /**
322
+ * Checks if the provided public key is a valid instance by verifying its structure and types.
323
+ *
324
+ * @param publicKey - The public key to validate.
325
+ * @returns A boolean indicating whether the public key is a valid instance.
326
+ * @group Implementation
327
+ * @category Serialization
328
+ */
329
+ static isInstance(publicKey: PublicKey) {
330
+ return (
331
+ "iss" in publicKey &&
332
+ typeof publicKey.iss === "string" &&
333
+ "idCommitment" in publicKey &&
334
+ publicKey.idCommitment instanceof Uint8Array
335
+ );
336
+ }
337
+ }
338
+
339
+ export async function verifyKeylessSignature(args: {
340
+ publicKey: KeylessPublicKey | FederatedKeylessPublicKey;
341
+ movementConfig: MovementConfig;
342
+ message: HexInput;
343
+ signature: Signature;
344
+ keylessConfig?: KeylessConfiguration;
345
+ jwk?: MoveJWK;
346
+ options?: { throwErrorWithReason?: boolean };
347
+ }): Promise<boolean> {
348
+ const {
349
+ movementConfig,
350
+ publicKey,
351
+ message,
352
+ signature,
353
+ jwk,
354
+ keylessConfig = await getKeylessConfig({ movementConfig }),
355
+ options,
356
+ } = args;
357
+ try {
358
+ if (!(signature instanceof KeylessSignature)) {
359
+ throw KeylessError.fromErrorType({
360
+ type: KeylessErrorType.SIGNATURE_TYPE_INVALID,
361
+ details: "Not a keyless signature",
362
+ });
363
+ }
364
+ verifyKeylessSignatureWithJwkAndConfig({
365
+ message,
366
+ publicKey,
367
+ signature,
368
+ jwk: jwk ? jwk : await fetchJWK({ movementConfig, publicKey, kid: signature.getJwkKid() }),
369
+ keylessConfig,
370
+ });
371
+ return true;
372
+ } catch (error) {
373
+ if (options?.throwErrorWithReason) {
374
+ throw error;
375
+ }
376
+ return false;
377
+ }
378
+ }
379
+
380
+ /**
381
+ * Syncronously verifies a keyless signature for a given message. You need to provide the keyless configuration and the
382
+ * JWK to use for verification.
383
+ *
384
+ * @param args.message The message to verify the signature against.
385
+ * @param args.signature The signature to verify.
386
+ * @param args.keylessConfig The keyless configuration.
387
+ * @param args.jwk The JWK to use for verification.
388
+ * @returns true if the signature is valid
389
+ * @throws KeylessError if the signature is invalid
390
+ */
391
+ export function verifyKeylessSignatureWithJwkAndConfig(args: {
392
+ publicKey: KeylessPublicKey | FederatedKeylessPublicKey;
393
+ message: HexInput;
394
+ signature: Signature;
395
+ keylessConfig: KeylessConfiguration;
396
+ jwk: MoveJWK;
397
+ }): void {
398
+ const { publicKey, message, signature, keylessConfig, jwk } = args;
399
+ const { verificationKey, maxExpHorizonSecs, trainingWheelsPubkey } = keylessConfig;
400
+ if (!(signature instanceof KeylessSignature)) {
401
+ throw KeylessError.fromErrorType({
402
+ type: KeylessErrorType.SIGNATURE_TYPE_INVALID,
403
+ details: "Not a keyless signature",
404
+ });
405
+ }
406
+ if (!(signature.ephemeralCertificate.signature instanceof ZeroKnowledgeSig)) {
407
+ throw KeylessError.fromErrorType({
408
+ type: KeylessErrorType.SIGNATURE_TYPE_INVALID,
409
+ details: "Unsupported ephemeral certificate variant",
410
+ });
411
+ }
412
+ const zkSig = signature.ephemeralCertificate.signature;
413
+ if (!(zkSig.proof.proof instanceof Groth16Zkp)) {
414
+ throw KeylessError.fromErrorType({
415
+ type: KeylessErrorType.SIGNATURE_TYPE_INVALID,
416
+ details: "Unsupported proof variant for ZeroKnowledgeSig",
417
+ });
418
+ }
419
+ const groth16Proof = zkSig.proof.proof;
420
+ if (signature.expiryDateSecs < nowInSeconds()) {
421
+ throw KeylessError.fromErrorType({
422
+ type: KeylessErrorType.SIGNATURE_EXPIRED,
423
+ details: "The expiryDateSecs is in the past",
424
+ });
425
+ }
426
+ if (zkSig.expHorizonSecs > maxExpHorizonSecs) {
427
+ throw KeylessError.fromErrorType({
428
+ type: KeylessErrorType.MAX_EXPIRY_HORIZON_EXCEEDED,
429
+ });
430
+ }
431
+ if (!signature.ephemeralPublicKey.verifySignature({ message, signature: signature.ephemeralSignature })) {
432
+ throw KeylessError.fromErrorType({
433
+ type: KeylessErrorType.EPHEMERAL_SIGNATURE_VERIFICATION_FAILED,
434
+ });
435
+ }
436
+ const publicInputsHash = getPublicInputsHash({ publicKey, signature, jwk, keylessConfig });
437
+ if (!verificationKey.verifyProof({ publicInputsHash, groth16Proof })) {
438
+ throw KeylessError.fromErrorType({
439
+ type: KeylessErrorType.PROOF_VERIFICATION_FAILED,
440
+ });
441
+ }
442
+ if (trainingWheelsPubkey) {
443
+ if (!zkSig.trainingWheelsSignature) {
444
+ throw KeylessError.fromErrorType({
445
+ type: KeylessErrorType.TRAINING_WHEELS_SIGNATURE_MISSING,
446
+ });
447
+ }
448
+ const proofAndStatement = new Groth16ProofAndStatement(groth16Proof, publicInputsHash);
449
+ if (
450
+ !trainingWheelsPubkey.verifySignature({
451
+ message: proofAndStatement.hash(),
452
+ signature: zkSig.trainingWheelsSignature,
453
+ })
454
+ ) {
455
+ throw KeylessError.fromErrorType({
456
+ type: KeylessErrorType.TRAINING_WHEELS_SIGNATURE_VERIFICATION_FAILED,
457
+ });
458
+ }
459
+ }
460
+ }
461
+
462
+ /**
463
+ * Get the public inputs hash for the keyless signature.
464
+ *
465
+ * @param args.signature The signature
466
+ * @param args.jwk The JWK to use for the public inputs hash
467
+ * @param args.keylessConfig The keyless configuration which defines the byte lengths to use when hashing fields.
468
+ * @returns The public inputs hash
469
+ */
470
+ function getPublicInputsHash(args: {
471
+ publicKey: KeylessPublicKey | FederatedKeylessPublicKey;
472
+ signature: KeylessSignature;
473
+ jwk: MoveJWK;
474
+ keylessConfig: KeylessConfiguration;
475
+ }): bigint {
476
+ const { publicKey, signature, jwk, keylessConfig } = args;
477
+ const innerKeylessPublicKey = publicKey instanceof KeylessPublicKey ? publicKey : publicKey.keylessPublicKey;
478
+ if (!(signature.ephemeralCertificate.signature instanceof ZeroKnowledgeSig)) {
479
+ throw new Error("Signature is not a ZeroKnowledgeSig");
480
+ }
481
+ const proof = signature.ephemeralCertificate.signature;
482
+ const fields = [];
483
+ fields.push(
484
+ ...padAndPackBytesWithLen(signature.ephemeralPublicKey.toUint8Array(), keylessConfig.maxCommitedEpkBytes),
485
+ );
486
+ fields.push(bytesToBigIntLE(innerKeylessPublicKey.idCommitment));
487
+ fields.push(signature.expiryDateSecs);
488
+ fields.push(proof.expHorizonSecs);
489
+ fields.push(hashStrToField(innerKeylessPublicKey.iss, keylessConfig.maxIssValBytes));
490
+ if (!proof.extraField) {
491
+ fields.push(0n);
492
+ fields.push(hashStrToField(" ", keylessConfig.maxExtraFieldBytes));
493
+ } else {
494
+ fields.push(1n);
495
+ fields.push(hashStrToField(proof.extraField, keylessConfig.maxExtraFieldBytes));
496
+ }
497
+ fields.push(hashStrToField(encode(signature.jwtHeader, true) + ".", keylessConfig.maxJwtHeaderB64Bytes));
498
+ fields.push(jwk.toScalar());
499
+ if (!proof.overrideAudVal) {
500
+ fields.push(hashStrToField("", MAX_AUD_VAL_BYTES));
501
+ fields.push(0n);
502
+ } else {
503
+ fields.push(hashStrToField(proof.overrideAudVal, MAX_AUD_VAL_BYTES));
504
+ fields.push(1n);
505
+ }
506
+ return poseidonHash(fields);
507
+ }
508
+
509
+ /**
510
+ * Fetches the JWK from the issuer's well-known JWKS endpoint.
511
+ *
512
+ * @param args.publicKey The keyless public key which contains the issuer the address to fetch the JWK from (0x1 if not federated).
513
+ * @param args.kid The kid of the JWK to fetch
514
+ * @returns A JWK matching the `kid` in the JWT header.
515
+ * @throws {KeylessError} If the JWK cannot be fetched
516
+ */
517
+ export async function fetchJWK(args: {
518
+ movementConfig: MovementConfig;
519
+ publicKey: KeylessPublicKey | FederatedKeylessPublicKey;
520
+ kid: string;
521
+ }): Promise<MoveJWK> {
522
+ const { movementConfig, publicKey, kid } = args;
523
+ const keylessPubKey = publicKey instanceof KeylessPublicKey ? publicKey : publicKey.keylessPublicKey;
524
+ const { iss } = keylessPubKey;
525
+
526
+ let allJWKs: Map<string, MoveJWK[]>;
527
+ const jwkAddr = publicKey instanceof FederatedKeylessPublicKey ? publicKey.jwkAddress : undefined;
528
+ try {
529
+ allJWKs = await getKeylessJWKs({ movementConfig, jwkAddr });
530
+ } catch (error) {
531
+ throw KeylessError.fromErrorType({
532
+ type: KeylessErrorType.FULL_NODE_JWKS_LOOKUP_ERROR,
533
+ error,
534
+ details: `Failed to fetch ${jwkAddr ? "Federated" : "Patched"}JWKs ${jwkAddr ? `for address ${jwkAddr}` : "0x1"}`,
535
+ });
536
+ }
537
+
538
+ // Find the corresponding JWK set by `iss`
539
+ const jwksForIssuer = allJWKs.get(iss);
540
+
541
+ if (jwksForIssuer === undefined) {
542
+ throw KeylessError.fromErrorType({
543
+ type: KeylessErrorType.INVALID_JWT_ISS_NOT_RECOGNIZED,
544
+ details: `JWKs for issuer ${iss} not found.`,
545
+ });
546
+ }
547
+
548
+ // Find the corresponding JWK by `kid`
549
+ const jwk = jwksForIssuer.find((key) => key.kid === kid);
550
+
551
+ if (jwk === undefined) {
552
+ throw KeylessError.fromErrorType({
553
+ type: KeylessErrorType.INVALID_JWT_JWK_NOT_FOUND,
554
+ details: `JWK with kid '${kid}' for issuer '${iss}' not found.`,
555
+ });
556
+ }
557
+
558
+ return jwk;
559
+ }
560
+
561
+ function computeIdCommitment(args: { uidKey: string; uidVal: string; aud: string; pepper: HexInput }): Uint8Array {
562
+ const { uidKey, uidVal, aud, pepper } = args;
563
+
564
+ const fields = [
565
+ bytesToBigIntLE(Hex.fromHexInput(pepper).toUint8Array()),
566
+ hashStrToField(aud, MAX_AUD_VAL_BYTES),
567
+ hashStrToField(uidVal, MAX_UID_VAL_BYTES),
568
+ hashStrToField(uidKey, MAX_UID_KEY_BYTES),
569
+ ];
570
+
571
+ return bigIntToBytesLE(poseidonHash(fields), KeylessPublicKey.ID_COMMITMENT_LENGTH);
572
+ }
573
+
574
+ /**
575
+ * Represents a signature of a message signed via a Keyless Account, utilizing proofs or a JWT token for authentication.
576
+ * @group Implementation
577
+ * @category Serialization
578
+ */
579
+ export class KeylessSignature extends Signature {
580
+ /**
581
+ * The inner signature ZeroKnowledgeSignature or OpenIdSignature
582
+ * @group Implementation
583
+ * @category Serialization
584
+ */
585
+ readonly ephemeralCertificate: EphemeralCertificate;
586
+
587
+ /**
588
+ * The jwt header in the token used to create the proof/signature. In json string representation.
589
+ * @group Implementation
590
+ * @category Serialization
591
+ */
592
+ readonly jwtHeader: string;
593
+
594
+ /**
595
+ * The expiry timestamp in seconds of the EphemeralKeyPair used to sign
596
+ * @group Implementation
597
+ * @category Serialization
598
+ */
599
+ readonly expiryDateSecs: number;
600
+
601
+ /**
602
+ * The ephemeral public key used to verify the signature
603
+ * @group Implementation
604
+ * @category Serialization
605
+ */
606
+ readonly ephemeralPublicKey: EphemeralPublicKey;
607
+
608
+ /**
609
+ * The signature resulting from signing with the private key of the EphemeralKeyPair
610
+ * @group Implementation
611
+ * @category Serialization
612
+ */
613
+ readonly ephemeralSignature: EphemeralSignature;
614
+
615
+ constructor(args: {
616
+ jwtHeader: string;
617
+ ephemeralCertificate: EphemeralCertificate;
618
+ expiryDateSecs: number;
619
+ ephemeralPublicKey: EphemeralPublicKey;
620
+ ephemeralSignature: EphemeralSignature;
621
+ }) {
622
+ super();
623
+ const { jwtHeader, ephemeralCertificate, expiryDateSecs, ephemeralPublicKey, ephemeralSignature } = args;
624
+ this.jwtHeader = jwtHeader;
625
+ this.ephemeralCertificate = ephemeralCertificate;
626
+ this.expiryDateSecs = expiryDateSecs;
627
+ this.ephemeralPublicKey = ephemeralPublicKey;
628
+ this.ephemeralSignature = ephemeralSignature;
629
+ }
630
+
631
+ /**
632
+ * Get the kid of the JWT used to derive the Keyless Account used to sign.
633
+ *
634
+ * @returns the kid as a string
635
+ */
636
+ getJwkKid(): string {
637
+ return parseJwtHeader(this.jwtHeader).kid;
638
+ }
639
+
640
+ serialize(serializer: Serializer): void {
641
+ this.ephemeralCertificate.serialize(serializer);
642
+ serializer.serializeStr(this.jwtHeader);
643
+ serializer.serializeU64(this.expiryDateSecs);
644
+ this.ephemeralPublicKey.serialize(serializer);
645
+ this.ephemeralSignature.serialize(serializer);
646
+ }
647
+
648
+ static deserialize(deserializer: Deserializer): KeylessSignature {
649
+ const ephemeralCertificate = EphemeralCertificate.deserialize(deserializer);
650
+ const jwtHeader = deserializer.deserializeStr();
651
+ const expiryDateSecs = deserializer.deserializeU64();
652
+ const ephemeralPublicKey = EphemeralPublicKey.deserialize(deserializer);
653
+ const ephemeralSignature = EphemeralSignature.deserialize(deserializer);
654
+ return new KeylessSignature({
655
+ jwtHeader,
656
+ expiryDateSecs: Number(expiryDateSecs),
657
+ ephemeralCertificate,
658
+ ephemeralPublicKey,
659
+ ephemeralSignature,
660
+ });
661
+ }
662
+
663
+ static getSimulationSignature(): KeylessSignature {
664
+ return new KeylessSignature({
665
+ jwtHeader: "{}",
666
+ ephemeralCertificate: new EphemeralCertificate(
667
+ new ZeroKnowledgeSig({
668
+ proof: new ZkProof(
669
+ new Groth16Zkp({ a: new Uint8Array(32), b: new Uint8Array(64), c: new Uint8Array(32) }),
670
+ ZkpVariant.Groth16,
671
+ ),
672
+ expHorizonSecs: 0,
673
+ }),
674
+ EphemeralCertificateVariant.ZkProof,
675
+ ),
676
+ expiryDateSecs: 0,
677
+ ephemeralPublicKey: new EphemeralPublicKey(new Ed25519PublicKey(new Uint8Array(32))),
678
+ ephemeralSignature: new EphemeralSignature(new Ed25519Signature(new Uint8Array(64))),
679
+ });
680
+ }
681
+
682
+ static isSignature(signature: Signature): signature is KeylessSignature {
683
+ return signature instanceof KeylessSignature;
684
+ }
685
+ }
686
+
687
+ /**
688
+ * Represents an ephemeral certificate containing a signature, specifically a ZeroKnowledgeSig.
689
+ * This class can be extended to support additional signature types, such as OpenIdSignature.
690
+ *
691
+ * @extends Signature
692
+ * @group Implementation
693
+ * @category Serialization
694
+ */
695
+ export class EphemeralCertificate extends Signature {
696
+ public readonly signature: Signature;
697
+
698
+ /**
699
+ * Index of the underlying enum variant
700
+ * @group Implementation
701
+ * @category Serialization
702
+ */
703
+ readonly variant: EphemeralCertificateVariant;
704
+
705
+ constructor(signature: Signature, variant: EphemeralCertificateVariant) {
706
+ super();
707
+ this.signature = signature;
708
+ this.variant = variant;
709
+ }
710
+
711
+ /**
712
+ * Get the public key in bytes (Uint8Array).
713
+ *
714
+ * @returns Uint8Array representation of the public key
715
+ * @group Implementation
716
+ * @category Serialization
717
+ */
718
+ toUint8Array(): Uint8Array {
719
+ return this.signature.toUint8Array();
720
+ }
721
+
722
+ serialize(serializer: Serializer): void {
723
+ serializer.serializeU32AsUleb128(this.variant);
724
+ this.signature.serialize(serializer);
725
+ }
726
+
727
+ static deserialize(deserializer: Deserializer): EphemeralCertificate {
728
+ const variant = deserializer.deserializeUleb128AsU32();
729
+ switch (variant) {
730
+ case EphemeralCertificateVariant.ZkProof:
731
+ return new EphemeralCertificate(ZeroKnowledgeSig.deserialize(deserializer), variant);
732
+ default:
733
+ throw new Error(`Unknown variant index for EphemeralCertificate: ${variant}`);
734
+ }
735
+ }
736
+ }
737
+
738
+ /**
739
+ * Represents a fixed-size byte array of 32 bytes, extending the Serializable class.
740
+ * This class is used for handling and serializing G1 bytes in cryptographic operations.
741
+ *
742
+ * @extends Serializable
743
+ * @group Implementation
744
+ * @category Serialization
745
+ */
746
+ class G1Bytes extends Serializable {
747
+ private static readonly B = bn254.fields.Fp.create(3n);
748
+
749
+ data: Uint8Array;
750
+
751
+ constructor(data: HexInput) {
752
+ super();
753
+ this.data = Hex.fromHexInput(data).toUint8Array();
754
+ if (this.data.length !== 32) {
755
+ throw new Error("Input needs to be 32 bytes");
756
+ }
757
+ }
758
+
759
+ serialize(serializer: Serializer): void {
760
+ serializer.serializeFixedBytes(this.data);
761
+ }
762
+
763
+ static deserialize(deserializer: Deserializer): G1Bytes {
764
+ const bytes = deserializer.deserializeFixedBytes(32);
765
+ return new G1Bytes(bytes);
766
+ }
767
+
768
+ // Convert the projective coordinates to strings
769
+ toArray(): string[] {
770
+ const point = this.toProjectivePoint();
771
+ return [point.x.toString(), point.y.toString(), point.pz.toString()];
772
+ }
773
+
774
+ /**
775
+ * Converts the G1 bytes to a projective point.
776
+ * @returns The projective point.
777
+ */
778
+ toProjectivePoint(): ProjPointType<bigint> {
779
+ const bytes = new Uint8Array(this.data);
780
+ // Reverse the bytes to convert from little-endian to big-endian.
781
+ bytes.reverse();
782
+ // This gets the flag bit to determine which y to use.
783
+ const yFlag = (bytes[0] & 0x80) >> 7;
784
+ const { Fp } = bn254.fields;
785
+ const x = Fp.create(bytesToBn254FpBE(bytes));
786
+ const y = Fp.sqrt(Fp.add(Fp.pow(x, 3n), G1Bytes.B));
787
+ const negY = Fp.neg(y);
788
+ const yToUse = y > negY === (yFlag === 1) ? y : negY;
789
+ return bn254.G1.ProjectivePoint.fromAffine({
790
+ x: x,
791
+ y: yToUse,
792
+ });
793
+ }
794
+ }
795
+
796
+ function bytesToBn254FpBE(bytes: Uint8Array): bigint {
797
+ if (bytes.length !== 32) {
798
+ throw new Error("Input should be 32 bytes");
799
+ }
800
+ // Clear the first two bits of the first byte which removes any flags.
801
+ const result = new Uint8Array(bytes);
802
+ result[0] = result[0] & 0x3f; // 0x3F = 00111111 in binary
803
+ return bytesToNumberBE(result);
804
+ }
805
+
806
+ /**
807
+ * Represents a 64-byte G2 element in a cryptographic context.
808
+ * This class provides methods for serialization and deserialization of G2 bytes.
809
+ *
810
+ * @extends Serializable
811
+ * @group Implementation
812
+ * @category Serialization
813
+ */
814
+ class G2Bytes extends Serializable {
815
+ /**
816
+ * The constant b value used in G2 point calculations
817
+ */
818
+ private static readonly B = bn254.fields.Fp2.fromBigTuple([
819
+ 19485874751759354771024239261021720505790618469301721065564631296452457478373n,
820
+ 266929791119991161246907387137283842545076965332900288569378510910307636690n,
821
+ ]);
822
+
823
+ data: Uint8Array;
824
+
825
+ constructor(data: HexInput) {
826
+ super();
827
+ this.data = Hex.fromHexInput(data).toUint8Array();
828
+ if (this.data.length !== 64) {
829
+ throw new Error("Input needs to be 64 bytes");
830
+ }
831
+ }
832
+
833
+ serialize(serializer: Serializer): void {
834
+ serializer.serializeFixedBytes(this.data);
835
+ }
836
+
837
+ static deserialize(deserializer: Deserializer): G2Bytes {
838
+ const bytes = deserializer.deserializeFixedBytes(64);
839
+ return new G2Bytes(bytes);
840
+ }
841
+
842
+ // Convert the projective coordinates to strings
843
+ toArray(): [string, string][] {
844
+ const point = this.toProjectivePoint();
845
+ return [
846
+ [
847
+ point.x.c0.toString(), // x real part
848
+ point.x.c1.toString(),
849
+ ], // x imaginary part
850
+ [
851
+ point.y.c0.toString(), // y real part
852
+ point.y.c1.toString(),
853
+ ], // y imaginary part
854
+ [
855
+ point.pz.c0.toString(), // z real part
856
+ point.pz.c1.toString(),
857
+ ], // z imaginary part
858
+ ];
859
+ }
860
+
861
+ toProjectivePoint(): ProjPointType<Fp2> {
862
+ const bytes = new Uint8Array(this.data);
863
+ // Reverse the bytes to convert from little-endian to big-endian for each part of x.
864
+ const x0 = bytes.slice(0, 32).reverse();
865
+ const x1 = bytes.slice(32, 64).reverse();
866
+ // This gets the flag bit to determine which y to use.
867
+ const yFlag = (x1[0] & 0x80) >> 7;
868
+ const { Fp2 } = bn254.fields;
869
+ const x = Fp2.fromBigTuple([bytesToBn254FpBE(x0), bytesToBn254FpBE(x1)]);
870
+ const y = Fp2.sqrt(Fp2.add(Fp2.pow(x, 3n), G2Bytes.B));
871
+ const negY = Fp2.neg(y);
872
+ const isYGreaterThanNegY = y.c1 > negY.c1 || (y.c1 === negY.c1 && y.c0 > negY.c0);
873
+ const yToUse = isYGreaterThanNegY === (yFlag === 1) ? y : negY;
874
+ return bn254.G2.ProjectivePoint.fromAffine({
875
+ x: x,
876
+ y: yToUse,
877
+ });
878
+ }
879
+ }
880
+
881
+ /**
882
+ * Represents a Groth16 zero-knowledge proof, consisting of three proof points in compressed serialization format.
883
+ * The points are the compressed serialization of affine representation of the proof.
884
+ *
885
+ * @extends Proof
886
+ * @group Implementation
887
+ * @category Serialization
888
+ */
889
+ export class Groth16Zkp extends Proof {
890
+ /**
891
+ * The bytes of G1 proof point a
892
+ * @group Implementation
893
+ * @category Serialization
894
+ */
895
+ a: G1Bytes;
896
+
897
+ /**
898
+ * The bytes of G2 proof point b
899
+ * @group Implementation
900
+ * @category Serialization
901
+ */
902
+ b: G2Bytes;
903
+
904
+ /**
905
+ * The bytes of G1 proof point c
906
+ * @group Implementation
907
+ * @category Serialization
908
+ */
909
+ c: G1Bytes;
910
+
911
+ constructor(args: { a: HexInput; b: HexInput; c: HexInput }) {
912
+ super();
913
+ const { a, b, c } = args;
914
+ this.a = new G1Bytes(a);
915
+ this.b = new G2Bytes(b);
916
+ this.c = new G1Bytes(c);
917
+ }
918
+
919
+ serialize(serializer: Serializer): void {
920
+ this.a.serialize(serializer);
921
+ this.b.serialize(serializer);
922
+ this.c.serialize(serializer);
923
+ }
924
+
925
+ static deserialize(deserializer: Deserializer): Groth16Zkp {
926
+ const a = G1Bytes.deserialize(deserializer).bcsToBytes();
927
+ const b = G2Bytes.deserialize(deserializer).bcsToBytes();
928
+ const c = G1Bytes.deserialize(deserializer).bcsToBytes();
929
+ return new Groth16Zkp({ a, b, c });
930
+ }
931
+
932
+ toSnarkJsJson() {
933
+ return {
934
+ protocol: "groth16",
935
+ curve: "bn128",
936
+ pi_a: this.a.toArray(),
937
+ pi_b: this.b.toArray(),
938
+ pi_c: this.c.toArray(),
939
+ };
940
+ }
941
+ }
942
+
943
+ /**
944
+ * Represents a Groth16 proof and statement, consisting of a Groth16 proof and a public inputs hash.
945
+ * This is used to generate the signing message for the training wheels signature.
946
+ *
947
+ * @extends Serializable
948
+ * @group Implementation
949
+ * @category Serialization
950
+ */
951
+ export class Groth16ProofAndStatement extends Serializable {
952
+ /**
953
+ * The Groth16 proof
954
+ * @group Implementation
955
+ * @category Serialization
956
+ */
957
+ proof: Groth16Zkp;
958
+
959
+ /**
960
+ * The public inputs hash as a 32 byte Uint8Array
961
+ * @group Implementation
962
+ * @category Serialization
963
+ */
964
+ publicInputsHash: Uint8Array;
965
+
966
+ /**
967
+ * The domain separator prefix used when hashing.
968
+ * @group Implementation
969
+ * @category Account (On-Chain Model)
970
+ */
971
+ readonly domainSeparator = "APTOS::Groth16ProofAndStatement";
972
+
973
+ constructor(proof: Groth16Zkp, publicInputsHash: HexInput | bigint) {
974
+ super();
975
+ this.proof = proof;
976
+ this.publicInputsHash =
977
+ typeof publicInputsHash === "bigint"
978
+ ? bigIntToBytesLE(publicInputsHash, 32)
979
+ : Hex.fromHexInput(publicInputsHash).toUint8Array();
980
+ if (this.publicInputsHash.length !== 32) {
981
+ throw new Error("Invalid public inputs hash");
982
+ }
983
+ }
984
+
985
+ serialize(serializer: Serializer): void {
986
+ this.proof.serialize(serializer);
987
+ serializer.serializeFixedBytes(this.publicInputsHash);
988
+ }
989
+
990
+ static deserialize(deserializer: Deserializer): Groth16ProofAndStatement {
991
+ return new Groth16ProofAndStatement(Groth16Zkp.deserialize(deserializer), deserializer.deserializeFixedBytes(32));
992
+ }
993
+
994
+ hash(): Uint8Array {
995
+ return generateSigningMessage(this.bcsToBytes(), this.domainSeparator);
996
+ }
997
+ }
998
+
999
+ /**
1000
+ * Represents a container for different types of zero-knowledge proofs.
1001
+ *
1002
+ * @extends Serializable
1003
+ * @group Implementation
1004
+ * @category Serialization
1005
+ */
1006
+ export class ZkProof extends Serializable {
1007
+ public readonly proof: Proof;
1008
+
1009
+ /**
1010
+ * Index of the underlying enum variant
1011
+ * @group Implementation
1012
+ * @category Serialization
1013
+ */
1014
+ readonly variant: ZkpVariant;
1015
+
1016
+ constructor(proof: Proof, variant: ZkpVariant) {
1017
+ super();
1018
+ this.proof = proof;
1019
+ this.variant = variant;
1020
+ }
1021
+
1022
+ serialize(serializer: Serializer): void {
1023
+ serializer.serializeU32AsUleb128(this.variant);
1024
+ this.proof.serialize(serializer);
1025
+ }
1026
+
1027
+ static deserialize(deserializer: Deserializer): ZkProof {
1028
+ const variant = deserializer.deserializeUleb128AsU32();
1029
+ switch (variant) {
1030
+ case ZkpVariant.Groth16:
1031
+ return new ZkProof(Groth16Zkp.deserialize(deserializer), variant);
1032
+ default:
1033
+ throw new Error(`Unknown variant index for ZkProof: ${variant}`);
1034
+ }
1035
+ }
1036
+ }
1037
+
1038
+ /**
1039
+ * Represents a zero-knowledge signature, encapsulating the proof and its associated metadata.
1040
+ *
1041
+ * @extends Signature
1042
+ * @group Implementation
1043
+ * @category Serialization
1044
+ */
1045
+ export class ZeroKnowledgeSig extends Signature {
1046
+ /**
1047
+ * The proof
1048
+ * @group Implementation
1049
+ * @category Serialization
1050
+ */
1051
+ readonly proof: ZkProof;
1052
+
1053
+ /**
1054
+ * The max lifespan of the proof
1055
+ * @group Implementation
1056
+ * @category Serialization
1057
+ */
1058
+ readonly expHorizonSecs: number;
1059
+
1060
+ /**
1061
+ * A key value pair on the JWT token that can be specified on the signature which would reveal the value on chain.
1062
+ * Can be used to assert identity or other attributes.
1063
+ * @group Implementation
1064
+ * @category Serialization
1065
+ */
1066
+ readonly extraField?: string;
1067
+
1068
+ /**
1069
+ * The 'aud' value of the recovery service which is set when recovering an account.
1070
+ * @group Implementation
1071
+ * @category Serialization
1072
+ */
1073
+ readonly overrideAudVal?: string;
1074
+
1075
+ /**
1076
+ * The training wheels signature
1077
+ * @group Implementation
1078
+ * @category Serialization
1079
+ */
1080
+ readonly trainingWheelsSignature?: EphemeralSignature;
1081
+
1082
+ constructor(args: {
1083
+ proof: ZkProof;
1084
+ expHorizonSecs: number;
1085
+ extraField?: string;
1086
+ overrideAudVal?: string;
1087
+ trainingWheelsSignature?: EphemeralSignature;
1088
+ }) {
1089
+ super();
1090
+ const { proof, expHorizonSecs, trainingWheelsSignature, extraField, overrideAudVal } = args;
1091
+ this.proof = proof;
1092
+ this.expHorizonSecs = expHorizonSecs;
1093
+ this.trainingWheelsSignature = trainingWheelsSignature;
1094
+ this.extraField = extraField;
1095
+ this.overrideAudVal = overrideAudVal;
1096
+ }
1097
+
1098
+ /**
1099
+ * Deserialize a ZeroKnowledgeSig object from its BCS serialization in bytes.
1100
+ *
1101
+ * @param bytes - The bytes representing the serialized ZeroKnowledgeSig.
1102
+ * @returns ZeroKnowledgeSig - The deserialized ZeroKnowledgeSig object.
1103
+ * @group Implementation
1104
+ * @category Serialization
1105
+ */
1106
+ static fromBytes(bytes: Uint8Array): ZeroKnowledgeSig {
1107
+ return ZeroKnowledgeSig.deserialize(new Deserializer(bytes));
1108
+ }
1109
+
1110
+ serialize(serializer: Serializer): void {
1111
+ this.proof.serialize(serializer);
1112
+ serializer.serializeU64(this.expHorizonSecs);
1113
+ serializer.serializeOption(this.extraField);
1114
+ serializer.serializeOption(this.overrideAudVal);
1115
+ serializer.serializeOption(this.trainingWheelsSignature);
1116
+ }
1117
+
1118
+ static deserialize(deserializer: Deserializer): ZeroKnowledgeSig {
1119
+ const proof = ZkProof.deserialize(deserializer);
1120
+ const expHorizonSecs = Number(deserializer.deserializeU64());
1121
+ const extraField = deserializer.deserializeOption("string");
1122
+ const overrideAudVal = deserializer.deserializeOption("string");
1123
+ const trainingWheelsSignature = deserializer.deserializeOption(EphemeralSignature);
1124
+ return new ZeroKnowledgeSig({ proof, expHorizonSecs, trainingWheelsSignature, extraField, overrideAudVal });
1125
+ }
1126
+ }
1127
+
1128
+ /**
1129
+ * Represents the on-chain configuration for how Keyless accounts operate.
1130
+ *
1131
+ * @remarks
1132
+ * This class encapsulates the verification key and the maximum lifespan of ephemeral key pairs,
1133
+ * which are essential for the functionality of Keyless accounts.
1134
+ * @group Implementation
1135
+ * @category Serialization
1136
+ */
1137
+ export class KeylessConfiguration {
1138
+ /**
1139
+ * The verification key used to verify Groth16 proofs on chain
1140
+ * @group Implementation
1141
+ * @category Serialization
1142
+ */
1143
+ readonly verificationKey: Groth16VerificationKey;
1144
+
1145
+ /**
1146
+ * The maximum lifespan of an ephemeral key pair. This is configured on chain.
1147
+ * @group Implementation
1148
+ * @category Serialization
1149
+ */
1150
+ readonly maxExpHorizonSecs: number;
1151
+
1152
+ /**
1153
+ * The public key of the training wheels account.
1154
+ * @group Implementation
1155
+ * @category Serialization
1156
+ */
1157
+ readonly trainingWheelsPubkey?: EphemeralPublicKey;
1158
+
1159
+ /**
1160
+ * The maximum number of bytes that can be used for the extra field.
1161
+ * @group Implementation
1162
+ * @category Serialization
1163
+ */
1164
+ readonly maxExtraFieldBytes: number;
1165
+
1166
+ /**
1167
+ * The maximum number of bytes that can be used for the JWT header.
1168
+ * @group Implementation
1169
+ * @category Serialization
1170
+ */
1171
+ readonly maxJwtHeaderB64Bytes: number;
1172
+
1173
+ /**
1174
+ * The maximum number of bytes that can be used for the issuer value.
1175
+ * @group Implementation
1176
+ * @category Serialization
1177
+ */
1178
+ readonly maxIssValBytes: number;
1179
+
1180
+ /**
1181
+ * The maximum number of bytes that can be used for the committed ephemeral public key.
1182
+ * @group Implementation
1183
+ * @category Serialization
1184
+ */
1185
+ readonly maxCommitedEpkBytes: number;
1186
+
1187
+ constructor(args: {
1188
+ verificationKey: Groth16VerificationKey;
1189
+ trainingWheelsPubkey?: HexInput;
1190
+ maxExpHorizonSecs?: number;
1191
+ maxExtraFieldBytes?: number;
1192
+ maxJwtHeaderB64Bytes?: number;
1193
+ maxIssValBytes?: number;
1194
+ maxCommitedEpkBytes?: number;
1195
+ }) {
1196
+ const {
1197
+ verificationKey,
1198
+ trainingWheelsPubkey,
1199
+ maxExpHorizonSecs = EPK_HORIZON_SECS,
1200
+ maxExtraFieldBytes = MAX_EXTRA_FIELD_BYTES,
1201
+ maxJwtHeaderB64Bytes = MAX_JWT_HEADER_B64_BYTES,
1202
+ maxIssValBytes = MAX_ISS_VAL_BYTES,
1203
+ maxCommitedEpkBytes = MAX_COMMITED_EPK_BYTES,
1204
+ } = args;
1205
+
1206
+ this.verificationKey = verificationKey;
1207
+ this.maxExpHorizonSecs = maxExpHorizonSecs;
1208
+ if (trainingWheelsPubkey) {
1209
+ this.trainingWheelsPubkey = new EphemeralPublicKey(new Ed25519PublicKey(trainingWheelsPubkey));
1210
+ }
1211
+ this.maxExtraFieldBytes = maxExtraFieldBytes;
1212
+ this.maxJwtHeaderB64Bytes = maxJwtHeaderB64Bytes;
1213
+ this.maxIssValBytes = maxIssValBytes;
1214
+ this.maxCommitedEpkBytes = maxCommitedEpkBytes;
1215
+ }
1216
+
1217
+ /**
1218
+ * Creates a new KeylessConfiguration instance from a Groth16VerificationKeyResponse and a KeylessConfigurationResponse.
1219
+ * @param res - The Groth16VerificationKeyResponse object containing the verification key data.
1220
+ * @param config - The KeylessConfigurationResponse object containing the configuration data.
1221
+ * @returns A new KeylessConfiguration instance.
1222
+ */
1223
+ static create(res: Groth16VerificationKeyResponse, config: KeylessConfigurationResponse): KeylessConfiguration {
1224
+ return new KeylessConfiguration({
1225
+ verificationKey: new Groth16VerificationKey({
1226
+ alphaG1: res.alpha_g1,
1227
+ betaG2: res.beta_g2,
1228
+ deltaG2: res.delta_g2,
1229
+ gammaAbcG1: res.gamma_abc_g1,
1230
+ gammaG2: res.gamma_g2,
1231
+ }),
1232
+ maxExpHorizonSecs: Number(config.max_exp_horizon_secs),
1233
+ trainingWheelsPubkey: config.training_wheels_pubkey.vec[0],
1234
+ maxExtraFieldBytes: config.max_extra_field_bytes,
1235
+ maxJwtHeaderB64Bytes: config.max_jwt_header_b64_bytes,
1236
+ maxIssValBytes: config.max_iss_val_bytes,
1237
+ maxCommitedEpkBytes: config.max_commited_epk_bytes,
1238
+ });
1239
+ }
1240
+ }
1241
+
1242
+ /**
1243
+ * Represents the verification key stored on-chain used to verify Groth16 proofs.
1244
+ * @group Implementation
1245
+ * @category Serialization
1246
+ */
1247
+ export class Groth16VerificationKey {
1248
+ // The docstrings below are borrowed from ark-groth16
1249
+
1250
+ /**
1251
+ * The `alpha * G`, where `G` is the generator of G1
1252
+ * @group Implementation
1253
+ * @category Serialization
1254
+ */
1255
+ readonly alphaG1: G1Bytes;
1256
+
1257
+ /**
1258
+ * The `alpha * H`, where `H` is the generator of G2
1259
+ * @group Implementation
1260
+ * @category Serialization
1261
+ */
1262
+ readonly betaG2: G2Bytes;
1263
+
1264
+ /**
1265
+ * The `delta * H`, where `H` is the generator of G2
1266
+ * @group Implementation
1267
+ * @category Serialization
1268
+ */
1269
+ readonly deltaG2: G2Bytes;
1270
+
1271
+ /**
1272
+ * The `gamma^{-1} * (beta * a_i + alpha * b_i + c_i) * H`, where H is the generator of G1
1273
+ * @group Implementation
1274
+ * @category Serialization
1275
+ */
1276
+ readonly gammaAbcG1: [G1Bytes, G1Bytes];
1277
+
1278
+ /**
1279
+ * The `gamma * H`, where `H` is the generator of G2
1280
+ * @group Implementation
1281
+ * @category Serialization
1282
+ */
1283
+ readonly gammaG2: G2Bytes;
1284
+
1285
+ constructor(args: {
1286
+ alphaG1: HexInput;
1287
+ betaG2: HexInput;
1288
+ deltaG2: HexInput;
1289
+ gammaAbcG1: [HexInput, HexInput];
1290
+ gammaG2: HexInput;
1291
+ }) {
1292
+ const { alphaG1, betaG2, deltaG2, gammaAbcG1, gammaG2 } = args;
1293
+ this.alphaG1 = new G1Bytes(alphaG1);
1294
+ this.betaG2 = new G2Bytes(betaG2);
1295
+ this.deltaG2 = new G2Bytes(deltaG2);
1296
+ this.gammaAbcG1 = [new G1Bytes(gammaAbcG1[0]), new G1Bytes(gammaAbcG1[1])];
1297
+ this.gammaG2 = new G2Bytes(gammaG2);
1298
+ }
1299
+
1300
+ /**
1301
+ * Calculates the hash of the serialized form of the verification key.
1302
+ * This is useful for comparing verification keys or using them as unique identifiers.
1303
+ *
1304
+ * @returns The SHA3-256 hash of the serialized verification key as a Uint8Array
1305
+ */
1306
+ public hash(): Uint8Array {
1307
+ const serializer = new Serializer();
1308
+ this.serialize(serializer);
1309
+ return sha3_256.create().update(serializer.toUint8Array()).digest();
1310
+ }
1311
+
1312
+ serialize(serializer: Serializer): void {
1313
+ this.alphaG1.serialize(serializer);
1314
+ this.betaG2.serialize(serializer);
1315
+ this.deltaG2.serialize(serializer);
1316
+ this.gammaAbcG1[0].serialize(serializer);
1317
+ this.gammaAbcG1[1].serialize(serializer);
1318
+ this.gammaG2.serialize(serializer);
1319
+ }
1320
+
1321
+ /**
1322
+ * Converts a Groth16VerificationKeyResponse object into a Groth16VerificationKey instance.
1323
+ *
1324
+ * @param res - The Groth16VerificationKeyResponse object containing the verification key data.
1325
+ * @param res.alpha_g1 - The alpha G1 value from the response.
1326
+ * @param res.beta_g2 - The beta G2 value from the response.
1327
+ * @param res.delta_g2 - The delta G2 value from the response.
1328
+ * @param res.gamma_abc_g1 - The gamma ABC G1 value from the response.
1329
+ * @param res.gamma_g2 - The gamma G2 value from the response.
1330
+ * @returns A Groth16VerificationKey instance constructed from the provided response data.
1331
+ * @group Implementation
1332
+ * @category Serialization
1333
+ */
1334
+ static fromGroth16VerificationKeyResponse(res: Groth16VerificationKeyResponse): Groth16VerificationKey {
1335
+ return new Groth16VerificationKey({
1336
+ alphaG1: res.alpha_g1,
1337
+ betaG2: res.beta_g2,
1338
+ deltaG2: res.delta_g2,
1339
+ gammaAbcG1: res.gamma_abc_g1,
1340
+ gammaG2: res.gamma_g2,
1341
+ });
1342
+ }
1343
+
1344
+ /**
1345
+ * Verifies a Groth16 proof using the verification key given the public inputs hash and the proof.
1346
+ *
1347
+ * @param args.publicInputsHash The public inputs hash
1348
+ * @param args.groth16Proof The Groth16 proof
1349
+ * @returns true if the proof is valid
1350
+ */
1351
+ verifyProof(args: { publicInputsHash: bigint; groth16Proof: Groth16Zkp }): boolean {
1352
+ const { publicInputsHash, groth16Proof } = args;
1353
+
1354
+ try {
1355
+ // Get proof points
1356
+ const proofA = groth16Proof.a.toProjectivePoint();
1357
+ const proofB = groth16Proof.b.toProjectivePoint();
1358
+ const proofC = groth16Proof.c.toProjectivePoint();
1359
+
1360
+ // Get verification key points
1361
+ const vkAlpha1 = this.alphaG1.toProjectivePoint();
1362
+ const vkBeta2 = this.betaG2.toProjectivePoint();
1363
+ const vkGamma2 = this.gammaG2.toProjectivePoint();
1364
+ const vkDelta2 = this.deltaG2.toProjectivePoint();
1365
+ const vkIC = this.gammaAbcG1.map((g1) => g1.toProjectivePoint());
1366
+
1367
+ const { Fp12 } = bn254.fields;
1368
+
1369
+ // Check that the following pairing equation holds:
1370
+ // e(A_1, B_2) = e(\alpha_1, \beta_2) + e(\ic_0 + public_inputs_hash \ic_1, \gamma_2) + e(C_1, \delta_2)
1371
+ // Where A_1, B_2, C_1 are the proof points and \alpha_1, \beta_2, \gamma_2, \delta_2, \ic_0, \ic_1
1372
+ // are the verification key points
1373
+
1374
+ // \ic_0 + public_inputs_hash \ic_1
1375
+ let accum = vkIC[0].add(vkIC[1].multiply(publicInputsHash));
1376
+ // e(\ic_0 + public_inputs_hash \ic_1, \gamma_2)
1377
+ const pairingAccumGamma = bn254.pairing(accum, vkGamma2);
1378
+ // e(A_1, B_2)
1379
+ const pairingAB = bn254.pairing(proofA, proofB);
1380
+ // e(\alpha_1, \beta_2)
1381
+ const pairingAlphaBeta = bn254.pairing(vkAlpha1, vkBeta2);
1382
+ // e(C_1, \delta_2)
1383
+ const pairingCDelta = bn254.pairing(proofC, vkDelta2);
1384
+ // Get the result of the right hand side of the pairing equation
1385
+ const product = Fp12.mul(pairingAlphaBeta, Fp12.mul(pairingAccumGamma, pairingCDelta));
1386
+ // Check if the left hand side equals the right hand side
1387
+ return Fp12.eql(pairingAB, product);
1388
+ } catch (error) {
1389
+ throw KeylessError.fromErrorType({
1390
+ type: KeylessErrorType.PROOF_VERIFICATION_FAILED,
1391
+ error,
1392
+ details: "Error encountered when checking zero knowledge relation",
1393
+ });
1394
+ }
1395
+ }
1396
+
1397
+ /**
1398
+ * Converts the verification key to a JSON format compatible with snarkjs groth16.verify
1399
+ *
1400
+ * @returns An object containing the verification key in snarkjs format
1401
+ * @group Implementation
1402
+ * @category Serialization
1403
+ */
1404
+ toSnarkJsJson() {
1405
+ return {
1406
+ protocol: "groth16",
1407
+ curve: "bn128",
1408
+ nPublic: 1,
1409
+ vk_alpha_1: this.alphaG1.toArray(),
1410
+ vk_beta_2: this.betaG2.toArray(),
1411
+ vk_gamma_2: this.gammaG2.toArray(),
1412
+ vk_delta_2: this.deltaG2.toArray(),
1413
+ IC: this.gammaAbcG1.map((g1) => g1.toArray()),
1414
+ };
1415
+ }
1416
+ }
1417
+
1418
+ /**
1419
+ * Retrieves the configuration parameters for Keyless Accounts on the blockchain, including the verifying key and the maximum
1420
+ * expiry horizon.
1421
+ *
1422
+ * @param args - The arguments for retrieving the keyless configuration.
1423
+ * @param args.movementConfig - The Movement configuration object containing network details.
1424
+ * @param args.options - Optional parameters for the request.
1425
+ * @param args.options.ledgerVersion - The ledger version to query; if not provided, the latest version will be used.
1426
+ * @returns KeylessConfiguration - The configuration object containing the verifying key and maximum expiry horizon.
1427
+ * @group Implementation
1428
+ * @category Serialization
1429
+ */
1430
+ export async function getKeylessConfig(args: {
1431
+ movementConfig: MovementConfig;
1432
+ options?: LedgerVersionArg;
1433
+ }): Promise<KeylessConfiguration> {
1434
+ const { movementConfig } = args;
1435
+ try {
1436
+ return await memoizeAsync(
1437
+ async () => {
1438
+ const [config, vk] = await Promise.all([
1439
+ getKeylessConfigurationResource(args),
1440
+ getGroth16VerificationKeyResource(args),
1441
+ ]);
1442
+ return KeylessConfiguration.create(vk, config);
1443
+ },
1444
+ `keyless-configuration-${movementConfig.network}`,
1445
+ 1000 * 60 * 5, // 5 minutes
1446
+ )();
1447
+ } catch (error) {
1448
+ if (error instanceof KeylessError) {
1449
+ throw error;
1450
+ }
1451
+ throw KeylessError.fromErrorType({
1452
+ type: KeylessErrorType.FULL_NODE_OTHER,
1453
+ error,
1454
+ });
1455
+ }
1456
+ }
1457
+
1458
+ /**
1459
+ * Parses a JWT and returns the 'iss', 'aud', and 'uid' values.
1460
+ *
1461
+ * @param args - The arguments for parsing the JWT.
1462
+ * @param args.jwt - The JWT to parse.
1463
+ * @param args.uidKey - The key to use for the 'uid' value; defaults to 'sub'.
1464
+ * @returns The 'iss', 'aud', and 'uid' values from the JWT.
1465
+ */
1466
+ export function getIssAudAndUidVal(args: { jwt: string; uidKey?: string }): {
1467
+ iss: string;
1468
+ aud: string;
1469
+ uidVal: string;
1470
+ } {
1471
+ const { jwt, uidKey = "sub" } = args;
1472
+ let jwtPayload: JwtPayload & { [key: string]: string };
1473
+ try {
1474
+ jwtPayload = jwtDecode<JwtPayload & { [key: string]: string }>(jwt);
1475
+ } catch (error) {
1476
+ throw KeylessError.fromErrorType({
1477
+ type: KeylessErrorType.JWT_PARSING_ERROR,
1478
+ details: `Failed to parse JWT - ${getErrorMessage(error)}`,
1479
+ });
1480
+ }
1481
+ if (typeof jwtPayload.iss !== "string") {
1482
+ throw KeylessError.fromErrorType({
1483
+ type: KeylessErrorType.JWT_PARSING_ERROR,
1484
+ details: "JWT is missing 'iss' in the payload. This should never happen.",
1485
+ });
1486
+ }
1487
+ if (typeof jwtPayload.aud !== "string") {
1488
+ throw KeylessError.fromErrorType({
1489
+ type: KeylessErrorType.JWT_PARSING_ERROR,
1490
+ details: "JWT is missing 'aud' in the payload or 'aud' is an array of values.",
1491
+ });
1492
+ }
1493
+ const uidVal = jwtPayload[uidKey];
1494
+ return { iss: jwtPayload.iss, aud: jwtPayload.aud, uidVal };
1495
+ }
1496
+
1497
+ /**
1498
+ * Retrieves the KeylessConfiguration set on chain.
1499
+ *
1500
+ * @param args - The arguments for retrieving the configuration.
1501
+ * @param args.movementConfig - The configuration for connecting to the Movement network.
1502
+ * @param args.options - Optional parameters for the request.
1503
+ * @param args.options.ledgerVersion - The ledger version to query; if not provided, it will get the latest version.
1504
+ * @returns KeylessConfigurationResponse - The response containing the keyless configuration data.
1505
+ * @group Implementation
1506
+ * @category Serialization
1507
+ */
1508
+ async function getKeylessConfigurationResource(args: {
1509
+ movementConfig: MovementConfig;
1510
+ options?: LedgerVersionArg;
1511
+ }): Promise<KeylessConfigurationResponse> {
1512
+ const { movementConfig, options } = args;
1513
+ const resourceType = "0x1::keyless_account::Configuration";
1514
+ try {
1515
+ const { data } = await getAptosFullNode<{}, MoveResource<KeylessConfigurationResponse>>({
1516
+ movementConfig,
1517
+ originMethod: "getKeylessConfigurationResource",
1518
+ path: `accounts/${AccountAddress.from("0x1").toString()}/resource/${resourceType}`,
1519
+ params: { ledger_version: options?.ledgerVersion },
1520
+ });
1521
+ return data.data;
1522
+ } catch (error) {
1523
+ throw KeylessError.fromErrorType({
1524
+ type: KeylessErrorType.FULL_NODE_CONFIG_LOOKUP_ERROR,
1525
+ error,
1526
+ });
1527
+ }
1528
+ }
1529
+
1530
+ /**
1531
+ * Retrieves the Groth16VerificationKey set on the blockchain.
1532
+ *
1533
+ * @param args - The arguments for retrieving the verification key.
1534
+ * @param args.movementConfig - The Movement configuration object.
1535
+ * @param args.options - Optional parameters for the request.
1536
+ * @param args.options.ledgerVersion - The ledger version to query; if not provided, it will get the latest version.
1537
+ * @returns Groth16VerificationKeyResponse - The response containing the Groth16 verification key data.
1538
+ * @group Implementation
1539
+ * @category Serialization
1540
+ */
1541
+ async function getGroth16VerificationKeyResource(args: {
1542
+ movementConfig: MovementConfig;
1543
+ options?: LedgerVersionArg;
1544
+ }): Promise<Groth16VerificationKeyResponse> {
1545
+ const { movementConfig, options } = args;
1546
+ const resourceType = "0x1::keyless_account::Groth16VerificationKey";
1547
+ try {
1548
+ const { data } = await getAptosFullNode<{}, MoveResource<Groth16VerificationKeyResponse>>({
1549
+ movementConfig,
1550
+ originMethod: "getGroth16VerificationKeyResource",
1551
+ path: `accounts/${AccountAddress.from("0x1").toString()}/resource/${resourceType}`,
1552
+ params: { ledger_version: options?.ledgerVersion },
1553
+ });
1554
+ return data.data;
1555
+ } catch (error) {
1556
+ throw KeylessError.fromErrorType({
1557
+ type: KeylessErrorType.FULL_NODE_VERIFICATION_KEY_LOOKUP_ERROR,
1558
+ error,
1559
+ });
1560
+ }
1561
+ }
1562
+
1563
+ export async function getKeylessJWKs(args: {
1564
+ movementConfig: MovementConfig;
1565
+ jwkAddr?: AccountAddressInput;
1566
+ options?: LedgerVersionArg;
1567
+ }): Promise<Map<string, MoveJWK[]>> {
1568
+ const { movementConfig, jwkAddr, options } = args;
1569
+ let resource: MoveResource<PatchedJWKsResponse>;
1570
+ if (!jwkAddr) {
1571
+ const resourceType = "0x1::jwks::PatchedJWKs";
1572
+ const { data } = await getAptosFullNode<{}, MoveResource<PatchedJWKsResponse>>({
1573
+ movementConfig,
1574
+ originMethod: "getKeylessJWKs",
1575
+ path: `accounts/0x1/resource/${resourceType}`,
1576
+ params: { ledger_version: options?.ledgerVersion },
1577
+ });
1578
+ resource = data;
1579
+ } else {
1580
+ const resourceType = "0x1::jwks::FederatedJWKs";
1581
+ const { data } = await getAptosFullNode<{}, MoveResource<PatchedJWKsResponse>>({
1582
+ movementConfig,
1583
+ originMethod: "getKeylessJWKs",
1584
+ path: `accounts/${AccountAddress.from(jwkAddr).toString()}/resource/${resourceType}`,
1585
+ params: { ledger_version: options?.ledgerVersion },
1586
+ });
1587
+ resource = data;
1588
+ }
1589
+
1590
+ // Create a map of issuer to JWK arrays
1591
+ const jwkMap = new Map<string, MoveJWK[]>();
1592
+ for (const entry of resource.data.jwks.entries) {
1593
+ const jwks: MoveJWK[] = [];
1594
+ for (const jwkStruct of entry.jwks) {
1595
+ const { data: jwkData } = jwkStruct.variant;
1596
+ const deserializer = new Deserializer(Hex.fromHexInput(jwkData).toUint8Array());
1597
+ const jwk = MoveJWK.deserialize(deserializer);
1598
+ jwks.push(jwk);
1599
+ }
1600
+ jwkMap.set(hexToAsciiString(entry.issuer), jwks);
1601
+ }
1602
+
1603
+ return jwkMap;
1604
+ }
1605
+
1606
+ export class MoveJWK extends Serializable {
1607
+ public kid: string;
1608
+
1609
+ public kty: string;
1610
+
1611
+ public alg: string;
1612
+
1613
+ public e: string;
1614
+
1615
+ public n: string;
1616
+
1617
+ constructor(args: { kid: string; kty: string; alg: string; e: string; n: string }) {
1618
+ super();
1619
+ const { kid, kty, alg, e, n } = args;
1620
+ this.kid = kid;
1621
+ this.kty = kty;
1622
+ this.alg = alg;
1623
+ this.e = e;
1624
+ this.n = n;
1625
+ }
1626
+
1627
+ serialize(serializer: Serializer): void {
1628
+ serializer.serializeStr(this.kid);
1629
+ serializer.serializeStr(this.kty);
1630
+ serializer.serializeStr(this.alg);
1631
+ serializer.serializeStr(this.e);
1632
+ serializer.serializeStr(this.n);
1633
+ }
1634
+
1635
+ static fromMoveStruct(struct: MoveAnyStruct): MoveJWK {
1636
+ const { data } = struct.variant;
1637
+ const deserializer = new Deserializer(Hex.fromHexInput(data).toUint8Array());
1638
+ return MoveJWK.deserialize(deserializer);
1639
+ }
1640
+
1641
+ toScalar(): bigint {
1642
+ if (this.alg !== "RS256") {
1643
+ throw KeylessError.fromErrorType({
1644
+ type: KeylessErrorType.PROOF_VERIFICATION_FAILED,
1645
+ details:
1646
+ "Failed to convert JWK to scalar when calculating the public inputs hash. Only RSA 256 is supported currently",
1647
+ });
1648
+ }
1649
+ const uint8Array = base64UrlToBytes(this.n);
1650
+ const chunks = chunkInto24Bytes(uint8Array.reverse());
1651
+ const scalars = chunks.map((chunk) => bytesToBigIntLE(chunk));
1652
+ scalars.push(256n); // Add the modulus size
1653
+ return poseidonHash(scalars);
1654
+ }
1655
+
1656
+ static deserialize(deserializer: Deserializer): MoveJWK {
1657
+ const kid = deserializer.deserializeStr();
1658
+ const kty = deserializer.deserializeStr();
1659
+ const alg = deserializer.deserializeStr();
1660
+ const e = deserializer.deserializeStr();
1661
+ const n = deserializer.deserializeStr();
1662
+ return new MoveJWK({ kid, kty, alg, n, e });
1663
+ }
1664
+ }
1665
+
1666
+ function chunkInto24Bytes(data: Uint8Array): Uint8Array[] {
1667
+ const chunks: Uint8Array[] = [];
1668
+ for (let i = 0; i < data.length; i += 24) {
1669
+ const chunk = data.slice(i, Math.min(i + 24, data.length));
1670
+ // Pad last chunk with zeros if needed
1671
+ if (chunk.length < 24) {
1672
+ const paddedChunk = new Uint8Array(24);
1673
+ paddedChunk.set(chunk);
1674
+ chunks.push(paddedChunk);
1675
+ } else {
1676
+ chunks.push(chunk);
1677
+ }
1678
+ }
1679
+ return chunks;
1680
+ }
1681
+
1682
+ interface JwtHeader {
1683
+ kid: string; // Key ID
1684
+ }
1685
+ /**
1686
+ * Safely parses the JWT header.
1687
+ * @param jwtHeader The JWT header string
1688
+ * @returns Parsed JWT header as an object.
1689
+ */
1690
+ export function parseJwtHeader(jwtHeader: string): JwtHeader {
1691
+ try {
1692
+ const header = JSON.parse(jwtHeader);
1693
+ if (header.kid === undefined) {
1694
+ throw new Error("JWT header missing kid");
1695
+ }
1696
+ return header;
1697
+ } catch (error) {
1698
+ throw new Error("Failed to parse JWT header.");
1699
+ }
1700
+ }