@aptos-labs/ts-sdk 3.0.0 → 3.1.1

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 (336) hide show
  1. package/dist/common/{account-CEmLe1wW.d.ts → account-Bb5REyaT.d.ts} +60 -11
  2. package/dist/common/chunk-6MMUUJHX.js +4 -0
  3. package/dist/common/{chunk-5JIJXVJ5.js.map → chunk-6MMUUJHX.js.map} +1 -1
  4. package/dist/common/cli/index.d.ts +1 -1
  5. package/dist/common/cli/index.js +1 -1
  6. package/dist/common/index.d.ts +121 -9
  7. package/dist/common/index.js +55 -34
  8. package/dist/common/index.js.map +1 -1
  9. package/dist/esm/{Ed25519Account-Ccxj1zdx.d.mts → Ed25519Account-ndmdpFe9.d.mts} +1 -1
  10. package/dist/esm/account/AbstractKeylessAccount.d.mts +3 -3
  11. package/dist/esm/account/AbstractKeylessAccount.mjs +1 -1
  12. package/dist/esm/account/AbstractedAccount.d.mts +2 -2
  13. package/dist/esm/account/AbstractedAccount.mjs +1 -1
  14. package/dist/esm/account/Account.d.mts +2 -2
  15. package/dist/esm/account/Account.mjs +1 -1
  16. package/dist/esm/account/AccountUtils.d.mts +3 -3
  17. package/dist/esm/account/AccountUtils.mjs +1 -1
  18. package/dist/esm/account/DerivableAbstractedAccount.d.mts +2 -2
  19. package/dist/esm/account/DerivableAbstractedAccount.mjs +1 -1
  20. package/dist/esm/account/Ed25519Account.d.mts +2 -2
  21. package/dist/esm/account/Ed25519Account.mjs +1 -1
  22. package/dist/esm/account/EphemeralKeyPair.d.mts +1 -1
  23. package/dist/esm/account/EphemeralKeyPair.mjs +1 -1
  24. package/dist/esm/account/FederatedKeylessAccount.d.mts +4 -3
  25. package/dist/esm/account/FederatedKeylessAccount.mjs +1 -1
  26. package/dist/esm/account/KeylessAccount.d.mts +4 -3
  27. package/dist/esm/account/KeylessAccount.mjs +1 -1
  28. package/dist/esm/account/MultiEd25519Account.d.mts +2 -2
  29. package/dist/esm/account/MultiEd25519Account.mjs +1 -1
  30. package/dist/esm/account/MultiKeyAccount.d.mts +3 -3
  31. package/dist/esm/account/MultiKeyAccount.mjs +1 -1
  32. package/dist/esm/account/SingleKeyAccount.d.mts +2 -2
  33. package/dist/esm/account/SingleKeyAccount.mjs +1 -1
  34. package/dist/esm/account/index.d.mts +3 -3
  35. package/dist/esm/account/index.mjs +1 -1
  36. package/dist/esm/account/utils.d.mts +1 -1
  37. package/dist/esm/account/utils.mjs +1 -1
  38. package/dist/esm/{account-9G6tix5T.d.mts → account--Q9z_xMN.d.mts} +37 -3
  39. package/dist/esm/api/account/abstraction.d.mts +1 -1
  40. package/dist/esm/api/account/abstraction.mjs +1 -1
  41. package/dist/esm/api/account.d.mts +94 -3
  42. package/dist/esm/api/account.mjs +1 -1
  43. package/dist/esm/api/ans.d.mts +2 -2
  44. package/dist/esm/api/ans.mjs +1 -1
  45. package/dist/esm/api/aptos.d.mts +6 -4
  46. package/dist/esm/api/aptos.mjs +1 -1
  47. package/dist/esm/api/aptosConfig.d.mts +1 -1
  48. package/dist/esm/api/aptosConfig.mjs +1 -1
  49. package/dist/esm/api/coin.d.mts +1 -1
  50. package/dist/esm/api/coin.mjs +1 -1
  51. package/dist/esm/api/digitalAsset.d.mts +2 -2
  52. package/dist/esm/api/digitalAsset.mjs +1 -1
  53. package/dist/esm/api/event.d.mts +1 -1
  54. package/dist/esm/api/event.mjs +1 -1
  55. package/dist/esm/api/faucet.d.mts +1 -1
  56. package/dist/esm/api/faucet.mjs +1 -1
  57. package/dist/esm/api/fungibleAsset.d.mts +2 -2
  58. package/dist/esm/api/fungibleAsset.mjs +1 -1
  59. package/dist/esm/api/general.d.mts +1 -1
  60. package/dist/esm/api/general.mjs +1 -1
  61. package/dist/esm/api/index.d.mts +6 -4
  62. package/dist/esm/api/index.mjs +1 -1
  63. package/dist/esm/api/keyless.d.mts +3 -3
  64. package/dist/esm/api/keyless.mjs +1 -1
  65. package/dist/esm/api/object.d.mts +1 -1
  66. package/dist/esm/api/object.mjs +1 -1
  67. package/dist/esm/api/staking.d.mts +1 -1
  68. package/dist/esm/api/staking.mjs +1 -1
  69. package/dist/esm/api/table.d.mts +1 -1
  70. package/dist/esm/api/table.mjs +1 -1
  71. package/dist/esm/api/transaction.d.mts +3 -2
  72. package/dist/esm/api/transaction.mjs +1 -1
  73. package/dist/esm/api/transactionSubmission/build.d.mts +1 -1
  74. package/dist/esm/api/transactionSubmission/build.mjs +1 -1
  75. package/dist/esm/api/transactionSubmission/helpers.d.mts +22 -9
  76. package/dist/esm/api/transactionSubmission/helpers.mjs +1 -1
  77. package/dist/esm/api/transactionSubmission/management.d.mts +2 -2
  78. package/dist/esm/api/transactionSubmission/management.mjs +1 -1
  79. package/dist/esm/api/transactionSubmission/sign.d.mts +2 -2
  80. package/dist/esm/api/transactionSubmission/sign.mjs +1 -1
  81. package/dist/esm/api/transactionSubmission/sign.mjs.map +1 -1
  82. package/dist/esm/api/transactionSubmission/simulate.d.mts +1 -1
  83. package/dist/esm/api/transactionSubmission/simulate.mjs +1 -1
  84. package/dist/esm/api/transactionSubmission/submit.d.mts +1 -1
  85. package/dist/esm/api/transactionSubmission/submit.mjs +1 -1
  86. package/dist/esm/api/utils.d.mts +1 -1
  87. package/dist/esm/api/utils.mjs +1 -1
  88. package/dist/esm/bcs/consts.d.mts +1 -1
  89. package/dist/esm/bcs/deserializer.d.mts +1 -1
  90. package/dist/esm/bcs/index.d.mts +1 -1
  91. package/dist/esm/bcs/index.mjs +1 -1
  92. package/dist/esm/bcs/serializable/entryFunctionBytes.d.mts +1 -1
  93. package/dist/esm/bcs/serializable/fixedBytes.d.mts +1 -1
  94. package/dist/esm/bcs/serializable/movePrimitives.d.mts +1 -1
  95. package/dist/esm/bcs/serializable/movePrimitives.mjs +1 -1
  96. package/dist/esm/bcs/serializable/moveStructs.d.mts +1 -1
  97. package/dist/esm/bcs/serializable/moveStructs.mjs +1 -1
  98. package/dist/esm/bcs/serializer.d.mts +1 -1
  99. package/dist/esm/{chunk-YHGGNYYL.mjs → chunk-2PF7UFKU.mjs} +2 -2
  100. package/dist/esm/chunk-5HXLZHDW.mjs +1 -0
  101. package/dist/esm/chunk-5HXLZHDW.mjs.map +1 -0
  102. package/dist/esm/chunk-75NVN2CG.mjs +2 -0
  103. package/dist/esm/{chunk-HMUIOIBG.mjs.map → chunk-75NVN2CG.mjs.map} +1 -1
  104. package/dist/esm/chunk-IJE2LVZG.mjs +2 -0
  105. package/dist/esm/chunk-IJE2LVZG.mjs.map +1 -0
  106. package/dist/esm/chunk-JCFTAG5Z.mjs +2 -0
  107. package/dist/esm/{chunk-RJ7F4JDV.mjs.map → chunk-JCFTAG5Z.mjs.map} +1 -1
  108. package/dist/esm/{chunk-FSP4QM2T.mjs → chunk-JL6RR7ML.mjs} +2 -2
  109. package/dist/esm/chunk-L3GEIX2R.mjs +6 -0
  110. package/dist/esm/chunk-L3GEIX2R.mjs.map +1 -0
  111. package/dist/esm/{chunk-WOTQ7227.mjs → chunk-LIS2GDBI.mjs} +2 -2
  112. package/dist/esm/{chunk-7T62PEFI.mjs → chunk-LJEERFEH.mjs} +2 -2
  113. package/dist/esm/{chunk-IDHVW7HS.mjs → chunk-O7WBNU4J.mjs} +2 -2
  114. package/dist/esm/{chunk-SAMHWS73.mjs → chunk-PXQPKCDD.mjs} +2 -2
  115. package/dist/esm/chunk-QREVMGQZ.mjs +2 -0
  116. package/dist/esm/chunk-QREVMGQZ.mjs.map +1 -0
  117. package/dist/esm/{chunk-R7NQJWDG.mjs → chunk-S335GK43.mjs} +2 -2
  118. package/dist/esm/{chunk-PFXXFUBL.mjs → chunk-SZE4RT4B.mjs} +2 -2
  119. package/dist/esm/{chunk-VHNX2NUR.mjs → chunk-UL777LTI.mjs} +47 -26
  120. package/dist/esm/chunk-UL777LTI.mjs.map +1 -0
  121. package/dist/esm/{chunk-2XQKGWHQ.mjs → chunk-V74WPKSY.mjs} +2 -2
  122. package/dist/esm/{chunk-5ZRPV4YI.mjs → chunk-VW26RFJ7.mjs} +2 -2
  123. package/dist/esm/{chunk-UIVX6WSC.mjs → chunk-Y7ZQTLH4.mjs} +2 -2
  124. package/dist/esm/cli/index.d.mts +1 -1
  125. package/dist/esm/cli/index.mjs +1 -1
  126. package/dist/esm/cli/localNode.mjs +1 -1
  127. package/dist/esm/cli/move.d.mts +1 -1
  128. package/dist/esm/client/core.d.mts +1 -1
  129. package/dist/esm/client/core.mjs +1 -1
  130. package/dist/esm/client/get.d.mts +1 -1
  131. package/dist/esm/client/get.mjs +1 -1
  132. package/dist/esm/client/index.d.mts +1 -1
  133. package/dist/esm/client/index.mjs +1 -1
  134. package/dist/esm/client/post.d.mts +1 -1
  135. package/dist/esm/client/post.mjs +1 -1
  136. package/dist/esm/core/account/index.d.mts +1 -1
  137. package/dist/esm/core/account/index.mjs +1 -1
  138. package/dist/esm/core/account/utils/address.d.mts +1 -1
  139. package/dist/esm/core/account/utils/address.mjs +1 -1
  140. package/dist/esm/core/account/utils/index.d.mts +1 -1
  141. package/dist/esm/core/account/utils/index.mjs +1 -1
  142. package/dist/esm/core/accountAddress.d.mts +1 -1
  143. package/dist/esm/core/accountAddress.mjs +1 -1
  144. package/dist/esm/core/authenticationKey.d.mts +1 -1
  145. package/dist/esm/core/authenticationKey.mjs +1 -1
  146. package/dist/esm/core/crypto/abstraction.d.mts +1 -1
  147. package/dist/esm/core/crypto/abstraction.mjs +1 -1
  148. package/dist/esm/core/crypto/deserializationUtils.d.mts +1 -1
  149. package/dist/esm/core/crypto/deserializationUtils.mjs +1 -1
  150. package/dist/esm/core/crypto/ed25519.d.mts +1 -1
  151. package/dist/esm/core/crypto/ed25519.mjs +1 -1
  152. package/dist/esm/core/crypto/ephemeral.d.mts +1 -1
  153. package/dist/esm/core/crypto/ephemeral.mjs +1 -1
  154. package/dist/esm/core/crypto/federatedKeyless.d.mts +2 -2
  155. package/dist/esm/core/crypto/federatedKeyless.mjs +1 -1
  156. package/dist/esm/core/crypto/index.d.mts +3 -2
  157. package/dist/esm/core/crypto/index.mjs +1 -1
  158. package/dist/esm/core/crypto/keyless.d.mts +2 -2
  159. package/dist/esm/core/crypto/keyless.mjs +1 -1
  160. package/dist/esm/core/crypto/multiEd25519.d.mts +1 -1
  161. package/dist/esm/core/crypto/multiEd25519.mjs +1 -1
  162. package/dist/esm/core/crypto/multiKey.d.mts +1 -1
  163. package/dist/esm/core/crypto/multiKey.mjs +1 -1
  164. package/dist/esm/core/crypto/privateKey.d.mts +1 -1
  165. package/dist/esm/core/crypto/privateKey.mjs +1 -1
  166. package/dist/esm/core/crypto/proof.d.mts +1 -1
  167. package/dist/esm/core/crypto/proof.mjs +1 -1
  168. package/dist/esm/core/crypto/publicKey.d.mts +1 -1
  169. package/dist/esm/core/crypto/publicKey.mjs +1 -1
  170. package/dist/esm/core/crypto/secp256k1.d.mts +1 -1
  171. package/dist/esm/core/crypto/secp256k1.mjs +1 -1
  172. package/dist/esm/core/crypto/signature.d.mts +1 -1
  173. package/dist/esm/core/crypto/signature.mjs +1 -1
  174. package/dist/esm/core/crypto/singleKey.d.mts +1 -1
  175. package/dist/esm/core/crypto/singleKey.mjs +1 -1
  176. package/dist/esm/core/crypto/types.d.mts +11 -0
  177. package/dist/esm/core/crypto/types.mjs +2 -0
  178. package/dist/esm/core/crypto/types.mjs.map +1 -0
  179. package/dist/esm/core/crypto/utils.d.mts +1 -1
  180. package/dist/esm/core/hex.d.mts +1 -1
  181. package/dist/esm/core/index.d.mts +3 -2
  182. package/dist/esm/core/index.mjs +1 -1
  183. package/dist/esm/errors/index.d.mts +1 -1
  184. package/dist/esm/errors/index.mjs +1 -1
  185. package/dist/esm/{federatedKeyless-CVKW5pnz.d.mts → federatedKeyless-CiyplsOB.d.mts} +1 -1
  186. package/dist/esm/index.d.mts +6 -4
  187. package/dist/esm/index.mjs +1 -1
  188. package/dist/esm/internal/abstraction.d.mts +1 -1
  189. package/dist/esm/internal/abstraction.mjs +1 -1
  190. package/dist/esm/internal/account.d.mts +38 -8
  191. package/dist/esm/internal/account.mjs +1 -1
  192. package/dist/esm/internal/ans.d.mts +2 -2
  193. package/dist/esm/internal/ans.mjs +1 -1
  194. package/dist/esm/internal/coin.d.mts +1 -1
  195. package/dist/esm/internal/coin.mjs +1 -1
  196. package/dist/esm/internal/digitalAsset.d.mts +2 -2
  197. package/dist/esm/internal/digitalAsset.mjs +1 -1
  198. package/dist/esm/internal/event.d.mts +1 -1
  199. package/dist/esm/internal/event.mjs +1 -1
  200. package/dist/esm/internal/faucet.d.mts +1 -1
  201. package/dist/esm/internal/faucet.mjs +1 -1
  202. package/dist/esm/internal/fungibleAsset.d.mts +2 -2
  203. package/dist/esm/internal/fungibleAsset.mjs +1 -1
  204. package/dist/esm/internal/general.d.mts +1 -1
  205. package/dist/esm/internal/general.mjs +1 -1
  206. package/dist/esm/internal/keyless.d.mts +12 -3
  207. package/dist/esm/internal/keyless.mjs +1 -1
  208. package/dist/esm/internal/object.d.mts +1 -1
  209. package/dist/esm/internal/object.mjs +1 -1
  210. package/dist/esm/internal/staking.d.mts +1 -1
  211. package/dist/esm/internal/staking.mjs +1 -1
  212. package/dist/esm/internal/table.d.mts +1 -1
  213. package/dist/esm/internal/table.mjs +1 -1
  214. package/dist/esm/internal/transaction.d.mts +1 -1
  215. package/dist/esm/internal/transaction.mjs +1 -1
  216. package/dist/esm/internal/transactionSubmission.d.mts +2 -2
  217. package/dist/esm/internal/transactionSubmission.mjs +1 -1
  218. package/dist/esm/internal/utils/index.d.mts +1 -1
  219. package/dist/esm/internal/utils/index.mjs +1 -1
  220. package/dist/esm/internal/utils/utils.d.mts +1 -1
  221. package/dist/esm/internal/utils/utils.mjs +1 -1
  222. package/dist/esm/internal/view.d.mts +1 -1
  223. package/dist/esm/internal/view.mjs +1 -1
  224. package/dist/esm/transactions/authenticator/account.d.mts +1 -1
  225. package/dist/esm/transactions/authenticator/account.mjs +1 -1
  226. package/dist/esm/transactions/authenticator/index.d.mts +1 -1
  227. package/dist/esm/transactions/authenticator/index.mjs +1 -1
  228. package/dist/esm/transactions/authenticator/transaction.d.mts +1 -1
  229. package/dist/esm/transactions/authenticator/transaction.mjs +1 -1
  230. package/dist/esm/transactions/index.d.mts +1 -1
  231. package/dist/esm/transactions/index.mjs +1 -1
  232. package/dist/esm/transactions/instances/chainId.d.mts +1 -1
  233. package/dist/esm/transactions/instances/identifier.d.mts +1 -1
  234. package/dist/esm/transactions/instances/index.d.mts +1 -1
  235. package/dist/esm/transactions/instances/index.mjs +1 -1
  236. package/dist/esm/transactions/instances/moduleId.d.mts +1 -1
  237. package/dist/esm/transactions/instances/moduleId.mjs +1 -1
  238. package/dist/esm/transactions/instances/multiAgentTransaction.d.mts +1 -1
  239. package/dist/esm/transactions/instances/multiAgentTransaction.mjs +1 -1
  240. package/dist/esm/transactions/instances/rawTransaction.d.mts +1 -1
  241. package/dist/esm/transactions/instances/rawTransaction.mjs +1 -1
  242. package/dist/esm/transactions/instances/rotationProofChallenge.d.mts +1 -1
  243. package/dist/esm/transactions/instances/rotationProofChallenge.mjs +1 -1
  244. package/dist/esm/transactions/instances/signedTransaction.d.mts +1 -1
  245. package/dist/esm/transactions/instances/signedTransaction.mjs +1 -1
  246. package/dist/esm/transactions/instances/simpleTransaction.d.mts +1 -1
  247. package/dist/esm/transactions/instances/simpleTransaction.mjs +1 -1
  248. package/dist/esm/transactions/instances/transactionArgument.d.mts +1 -1
  249. package/dist/esm/transactions/instances/transactionPayload.d.mts +1 -1
  250. package/dist/esm/transactions/instances/transactionPayload.mjs +1 -1
  251. package/dist/esm/transactions/management/accountSequenceNumber.d.mts +2 -2
  252. package/dist/esm/transactions/management/accountSequenceNumber.mjs +1 -1
  253. package/dist/esm/transactions/management/index.d.mts +2 -2
  254. package/dist/esm/transactions/management/index.mjs +1 -1
  255. package/dist/esm/transactions/management/transactionWorker.d.mts +2 -2
  256. package/dist/esm/transactions/management/transactionWorker.mjs +1 -1
  257. package/dist/esm/transactions/transactionBuilder/helpers.d.mts +1 -1
  258. package/dist/esm/transactions/transactionBuilder/helpers.mjs +1 -1
  259. package/dist/esm/transactions/transactionBuilder/index.d.mts +1 -1
  260. package/dist/esm/transactions/transactionBuilder/index.mjs +1 -1
  261. package/dist/esm/transactions/transactionBuilder/remoteAbi.d.mts +1 -1
  262. package/dist/esm/transactions/transactionBuilder/remoteAbi.mjs +1 -1
  263. package/dist/esm/transactions/transactionBuilder/signingMessage.d.mts +1 -1
  264. package/dist/esm/transactions/transactionBuilder/signingMessage.mjs +1 -1
  265. package/dist/esm/transactions/transactionBuilder/transactionBuilder.d.mts +1 -1
  266. package/dist/esm/transactions/transactionBuilder/transactionBuilder.mjs +1 -1
  267. package/dist/esm/transactions/typeTag/index.d.mts +1 -1
  268. package/dist/esm/transactions/typeTag/index.mjs +1 -1
  269. package/dist/esm/transactions/typeTag/parser.d.mts +1 -1
  270. package/dist/esm/transactions/typeTag/parser.mjs +1 -1
  271. package/dist/esm/transactions/types.d.mts +1 -1
  272. package/dist/esm/types/generated/operations.d.mts +37 -10
  273. package/dist/esm/types/generated/queries.d.mts +6 -2
  274. package/dist/esm/types/generated/queries.mjs +1 -1
  275. package/dist/esm/types/generated/types.d.mts +584 -1172
  276. package/dist/esm/types/generated/types.mjs +1 -1
  277. package/dist/esm/types/generated/types.mjs.map +1 -1
  278. package/dist/esm/types/index.d.mts +2 -2
  279. package/dist/esm/types/index.mjs +1 -1
  280. package/dist/esm/types/indexer.d.mts +8 -2
  281. package/dist/esm/types/types.d.mts +1 -1
  282. package/dist/esm/types/types.mjs +1 -1
  283. package/dist/esm/utils/const.d.mts +1 -0
  284. package/dist/esm/utils/const.mjs +1 -1
  285. package/dist/esm/utils/helpers.d.mts +1 -1
  286. package/dist/esm/utils/helpers.mjs +1 -1
  287. package/dist/esm/utils/index.d.mts +1 -1
  288. package/dist/esm/utils/index.mjs +1 -1
  289. package/dist/esm/utils/normalizeBundle.d.mts +1 -1
  290. package/dist/esm/utils/normalizeBundle.mjs +1 -1
  291. package/dist/esm/version.d.mts +1 -1
  292. package/dist/esm/version.mjs +1 -1
  293. package/package.json +1 -1
  294. package/src/account/FederatedKeylessAccount.ts +7 -1
  295. package/src/account/KeylessAccount.ts +17 -2
  296. package/src/api/account.ts +135 -2
  297. package/src/api/transaction.ts +1 -0
  298. package/src/api/transactionSubmission/helpers.ts +26 -20
  299. package/src/api/transactionSubmission/submit.ts +3 -3
  300. package/src/core/crypto/index.ts +1 -0
  301. package/src/core/crypto/multiEd25519.ts +26 -0
  302. package/src/core/crypto/multiKey.ts +6 -0
  303. package/src/core/crypto/types.ts +9 -0
  304. package/src/internal/account.ts +526 -59
  305. package/src/internal/keyless.ts +10 -0
  306. package/src/internal/queries/getAccountAddressesForAuthKey.graphql +8 -0
  307. package/src/internal/queries/getAuthKeysForPublicKey.graphql +11 -0
  308. package/src/types/codegen.yaml +1 -1
  309. package/src/types/generated/operations.ts +39 -8
  310. package/src/types/generated/queries.ts +53 -0
  311. package/src/types/generated/types.ts +620 -1239
  312. package/src/types/indexer.ts +8 -0
  313. package/src/types/types.ts +40 -3
  314. package/src/utils/const.ts +1 -0
  315. package/src/version.ts +1 -1
  316. package/dist/common/chunk-5JIJXVJ5.js +0 -4
  317. package/dist/esm/chunk-4H2RMR7D.mjs +0 -2
  318. package/dist/esm/chunk-4H2RMR7D.mjs.map +0 -1
  319. package/dist/esm/chunk-GMDBBVDH.mjs +0 -6
  320. package/dist/esm/chunk-GMDBBVDH.mjs.map +0 -1
  321. package/dist/esm/chunk-HMUIOIBG.mjs +0 -2
  322. package/dist/esm/chunk-RJ7F4JDV.mjs +0 -2
  323. package/dist/esm/chunk-VHNX2NUR.mjs.map +0 -1
  324. package/dist/esm/chunk-W4BSN6SK.mjs +0 -2
  325. package/dist/esm/chunk-W4BSN6SK.mjs.map +0 -1
  326. /package/dist/esm/{chunk-YHGGNYYL.mjs.map → chunk-2PF7UFKU.mjs.map} +0 -0
  327. /package/dist/esm/{chunk-FSP4QM2T.mjs.map → chunk-JL6RR7ML.mjs.map} +0 -0
  328. /package/dist/esm/{chunk-WOTQ7227.mjs.map → chunk-LIS2GDBI.mjs.map} +0 -0
  329. /package/dist/esm/{chunk-7T62PEFI.mjs.map → chunk-LJEERFEH.mjs.map} +0 -0
  330. /package/dist/esm/{chunk-IDHVW7HS.mjs.map → chunk-O7WBNU4J.mjs.map} +0 -0
  331. /package/dist/esm/{chunk-SAMHWS73.mjs.map → chunk-PXQPKCDD.mjs.map} +0 -0
  332. /package/dist/esm/{chunk-R7NQJWDG.mjs.map → chunk-S335GK43.mjs.map} +0 -0
  333. /package/dist/esm/{chunk-PFXXFUBL.mjs.map → chunk-SZE4RT4B.mjs.map} +0 -0
  334. /package/dist/esm/{chunk-2XQKGWHQ.mjs.map → chunk-V74WPKSY.mjs.map} +0 -0
  335. /package/dist/esm/{chunk-5ZRPV4YI.mjs.map → chunk-VW26RFJ7.mjs.map} +0 -0
  336. /package/dist/esm/{chunk-UIVX6WSC.mjs.map → chunk-Y7ZQTLH4.mjs.map} +0 -0
@@ -17,6 +17,9 @@ import {
17
17
  } from "../client";
18
18
  import {
19
19
  AccountData,
20
+ AnyNumber,
21
+ anyPublicKeyVariantToString,
22
+ CommittedTransactionResponse,
20
23
  CursorPaginationArgs,
21
24
  GetAccountCoinsDataResponse,
22
25
  GetAccountCollectionsWithOwnedTokenResponse,
@@ -31,12 +34,28 @@ import {
31
34
  PaginationArgs,
32
35
  PendingTransactionResponse,
33
36
  TokenStandardArg,
34
- TransactionResponse,
35
37
  WhereArg,
36
38
  } from "../types";
37
39
  import { AccountAddress, AccountAddressInput } from "../core/accountAddress";
38
- import { Account, Ed25519Account, MultiEd25519Account } from "../account";
39
- import { AnyPublicKey, Ed25519PublicKey, PrivateKey } from "../core/crypto";
40
+ import {
41
+ Account,
42
+ Ed25519Account,
43
+ FederatedKeylessAccount,
44
+ KeylessAccount,
45
+ MultiEd25519Account,
46
+ MultiKeyAccount,
47
+ SingleKeyAccount,
48
+ } from "../account";
49
+ import {
50
+ AbstractMultiKey,
51
+ AccountPublicKey,
52
+ AnyPublicKey,
53
+ BaseAccountPublicKey,
54
+ Ed25519PublicKey,
55
+ MultiEd25519PublicKey,
56
+ MultiKey,
57
+ PrivateKeyInput,
58
+ } from "../core/crypto";
40
59
  import { queryIndexer } from "./general";
41
60
  import { getModule as getModuleUtil, getInfo as getInfoUtil } from "./utils";
42
61
  import {
@@ -48,6 +67,8 @@ import {
48
67
  GetAccountOwnedTokensQuery,
49
68
  GetAccountTokensCountQuery,
50
69
  GetAccountTransactionsCountQuery,
70
+ GetAuthKeysForPublicKeyQuery,
71
+ GetAccountAddressesForAuthKeyQuery,
51
72
  } from "../types/generated/operations";
52
73
  import {
53
74
  GetAccountCoinsCount,
@@ -58,16 +79,27 @@ import {
58
79
  GetAccountOwnedTokensFromCollection,
59
80
  GetAccountTokensCount,
60
81
  GetAccountTransactionsCount,
82
+ GetAuthKeysForPublicKey,
83
+ GetAccountAddressesForAuthKey,
61
84
  } from "../types/generated/queries";
62
- import { Secp256k1PrivateKey, AuthenticationKey, Ed25519PrivateKey, createObjectAddress } from "../core";
85
+ import { Secp256k1PrivateKey, AuthenticationKey, Ed25519PrivateKey, createObjectAddress, Hex } from "../core";
63
86
  import { CurrentFungibleAssetBalancesBoolExp } from "../types/generated/types";
64
87
  import { getTableItem } from "./table";
65
88
  import { APTOS_COIN } from "../utils";
66
89
  import { AptosApiError } from "../errors";
90
+ import { Deserializer } from "../bcs";
67
91
  import { signAndSubmitTransaction, generateTransaction } from "./transactionSubmission";
68
- import { EntryFunctionABI, RotationProofChallenge, TypeTagU8, TypeTagVector } from "../transactions";
92
+ import {
93
+ EntryFunctionABI,
94
+ InputGenerateTransactionOptions,
95
+ RotationProofChallenge,
96
+ TypeTagU8,
97
+ TypeTagVector,
98
+ } from "../transactions";
69
99
  import { U8, MoveVector } from "../bcs";
70
- import { waitForTransaction } from "./transaction";
100
+ import { waitForTransaction, waitForIndexer } from "./transaction";
101
+ import { view } from "./view";
102
+ import { getLedgerInfo } from "./general";
71
103
 
72
104
  /**
73
105
  * Retrieves account information for a specified account address.
@@ -183,9 +215,9 @@ export async function getTransactions(args: {
183
215
  aptosConfig: AptosConfig;
184
216
  accountAddress: AccountAddressInput;
185
217
  options?: PaginationArgs;
186
- }): Promise<TransactionResponse[]> {
218
+ }): Promise<CommittedTransactionResponse[]> {
187
219
  const { aptosConfig, accountAddress, options } = args;
188
- return paginateWithCursor<{}, TransactionResponse[]>({
220
+ return paginateWithCursor<{}, CommittedTransactionResponse[]>({
189
221
  aptosConfig,
190
222
  originMethod: "getTransactions",
191
223
  path: `accounts/${AccountAddress.from(accountAddress).toString()}/transactions`,
@@ -755,61 +787,44 @@ export async function getAccountOwnedObjects(args: {
755
787
 
756
788
  /**
757
789
  * Derives an account from the provided private key and Aptos configuration.
758
- * This function helps in obtaining the account details associated with a given private key,
759
- * considering both unified and legacy authentication schemes.
790
+ *
791
+ * This function queries all owned accounts for the provided private key and returns the most
792
+ * recently used account. If no account is found, it will throw an error unless `throwIfNoAccountFound` is set to false.
793
+ *
794
+ * If `throwIfNoAccountFound` is set to false, the function will return the default account for the private key via `Account.fromPrivateKey`.
760
795
  *
761
796
  * NOTE: There is a potential issue once the unified single signer scheme is adopted by the community.
762
797
  * Because one could create two accounts with the same private key with this new authenticator type,
763
- * well need to determine the order in which we look up the accounts: first unified scheme and then legacy scheme,
798
+ * we'll need to determine the order in which we look up the accounts: first unified scheme and then legacy scheme,
764
799
  * or first legacy scheme and then unified scheme.
765
800
  *
766
801
  * @param args - The arguments for deriving the account.
767
802
  * @param args.aptosConfig - The Aptos configuration used for account lookup.
768
803
  * @param args.privateKey - The private key used to derive the account.
804
+ * @param args.options.throwIfNoAccountFound - If true, throw an error if no existing account is found on chain. Default is false.
769
805
  * @throws Error if the account cannot be derived from the private key.
770
806
  * @group Implementation
771
807
  * @deprecated Note that more inspection is needed by the user to determine which account exists on-chain
772
808
  */
773
809
  export async function deriveAccountFromPrivateKey(args: {
774
810
  aptosConfig: AptosConfig;
775
- privateKey: PrivateKey;
811
+ privateKey: PrivateKeyInput;
812
+ options?: {
813
+ throwIfNoAccountFound?: boolean;
814
+ };
776
815
  }): Promise<Account> {
777
- const { aptosConfig, privateKey } = args;
778
- const publicKey = new AnyPublicKey(privateKey.publicKey());
779
-
780
- if (privateKey instanceof Secp256k1PrivateKey) {
781
- // private key is secp256k1, therefore we know it for sure uses a single signer key
782
- const authKey = AuthenticationKey.fromPublicKey({ publicKey });
783
- const address = authKey.derivedAddress();
784
- return Account.fromPrivateKey({ privateKey, address });
785
- }
816
+ const { aptosConfig, privateKey, options } = args;
817
+ const throwIfNoAccountFound = options?.throwIfNoAccountFound ?? false;
786
818
 
787
- if (privateKey instanceof Ed25519PrivateKey) {
788
- // lookup legacy ed25519
789
- const legacyAuthKey = AuthenticationKey.fromPublicKey({
790
- publicKey: publicKey.publicKey as Ed25519PublicKey,
791
- });
792
- const isLegacyEd25519 = await isAccountExist({ authKey: legacyAuthKey, aptosConfig });
793
- if (isLegacyEd25519) {
794
- const address = legacyAuthKey.derivedAddress();
795
- return Account.fromPrivateKey({ privateKey, address, legacy: true });
796
- }
797
- // lookup single sender ed25519
798
- const singleSenderTransactionAuthenticatorAuthKey = AuthenticationKey.fromPublicKey({
799
- publicKey,
800
- });
801
- const isSingleSenderTransactionAuthenticator = await isAccountExist({
802
- authKey: singleSenderTransactionAuthenticatorAuthKey,
803
- aptosConfig,
804
- });
805
- if (isSingleSenderTransactionAuthenticator) {
806
- const address = singleSenderTransactionAuthenticatorAuthKey.derivedAddress();
807
- return Account.fromPrivateKey({ privateKey, address, legacy: false });
819
+ const accounts = await deriveOwnedAccountsFromPrivateKey({ aptosConfig, privateKey });
820
+ if (accounts.length === 0) {
821
+ if (throwIfNoAccountFound) {
822
+ throw new Error(`No existing account found for private key.`);
808
823
  }
824
+ // If no account is found, return the default account. This is a legacy account for Ed25519 private keys.
825
+ return Account.fromPrivateKey({ privateKey });
809
826
  }
810
- // if we are here, it means we couldn't find an address with an
811
- // auth key that matches the provided private key
812
- throw new Error(`Can't derive account from private key ${privateKey}`);
827
+ return accounts[0];
813
828
  }
814
829
 
815
830
  /**
@@ -830,18 +845,73 @@ export async function isAccountExist(args: { aptosConfig: AptosConfig; authKey:
830
845
  authenticationKey: authKey.derivedAddress(),
831
846
  });
832
847
 
848
+ return doesAccountExistAtAddress({ aptosConfig, accountAddress });
849
+ }
850
+
851
+ /**
852
+ * Checks if an account exists at a given address.
853
+ *
854
+ * @param args - The arguments for checking account existence.
855
+ * @param args.aptosConfig - The configuration for the Aptos client.
856
+ * @param args.accountAddress - The address of the account to check.
857
+ * @param args.options.withAuthKey - An optional authentication key which will also be checked against if provided.
858
+ * @returns A promise that resolves to a boolean indicating whether the account exists.
859
+ * @group Implementation
860
+ */
861
+ async function doesAccountExistAtAddress(args: {
862
+ aptosConfig: AptosConfig;
863
+ accountAddress: AccountAddress;
864
+ options?: { withAuthKey?: AuthenticationKey };
865
+ }): Promise<boolean> {
866
+ const { aptosConfig, accountAddress, options } = args;
833
867
  try {
834
- await getInfo({
835
- aptosConfig,
836
- accountAddress,
837
- });
838
- return true;
839
- } catch (error: any) {
840
- // account not found
841
- if (error.status === 404) {
868
+ // Get the account resources and the balance of the account. We need to check both because
869
+ // an account resource can exist with 0 balance and a balance can exist without an account resource (light accounts).
870
+ const [resources, ownedObjects] = await Promise.all([
871
+ getResources({
872
+ aptosConfig,
873
+ accountAddress,
874
+ }),
875
+ getAccountOwnedObjects({
876
+ aptosConfig,
877
+ accountAddress,
878
+ options: {
879
+ limit: 1,
880
+ },
881
+ }),
882
+ ]);
883
+
884
+ const accountResource: MoveResource<{ authentication_key: string }> | undefined = resources.find(
885
+ (r) => r.type === "0x1::account::Account",
886
+ ) as MoveResource<{ authentication_key: string }> | undefined;
887
+
888
+ // If the account resource is not found and the balance is 0, then the account does not exist.
889
+ if (!accountResource && ownedObjects.length === 0) {
842
890
  return false;
843
891
  }
844
- throw new Error(`Error while looking for an account info ${accountAddress.toString()}`);
892
+
893
+ // If no auth key is provided as an argument, return true.
894
+ if (!options?.withAuthKey) {
895
+ return true;
896
+ }
897
+
898
+ // Get the auth key from the account resource if it exists. If the account resource does not exist,
899
+ // then the auth key is the account address by default.
900
+ let authKey;
901
+ if (accountResource) {
902
+ authKey = accountResource.data.authentication_key;
903
+ } else {
904
+ authKey = accountAddress.toStringLong();
905
+ }
906
+
907
+ if (authKey !== options.withAuthKey.toString()) {
908
+ return false;
909
+ }
910
+
911
+ // Else the account exists and the auth key matches.
912
+ return true;
913
+ } catch (error: any) {
914
+ throw new Error(`Error while checking if account exists at ${accountAddress.toString()}: ${error}`);
845
915
  }
846
916
  }
847
917
 
@@ -888,27 +958,34 @@ export async function rotateAuthKey(
888
958
  args: {
889
959
  aptosConfig: AptosConfig;
890
960
  fromAccount: Account;
961
+ options?: InputGenerateTransactionOptions;
891
962
  } & (
892
963
  | { toAccount: Account; dangerouslySkipVerification?: never }
893
964
  | { toNewPrivateKey: Ed25519PrivateKey; dangerouslySkipVerification?: never }
894
965
  | { toAuthKey: AuthenticationKey; dangerouslySkipVerification: true }
895
966
  ),
896
967
  ): Promise<PendingTransactionResponse> {
897
- const { aptosConfig, fromAccount, dangerouslySkipVerification } = args;
968
+ const { aptosConfig, fromAccount, dangerouslySkipVerification, options } = args;
898
969
  if ("toNewPrivateKey" in args) {
899
970
  return rotateAuthKeyWithChallenge({
900
971
  aptosConfig,
901
972
  fromAccount,
902
973
  toNewPrivateKey: args.toNewPrivateKey,
974
+ options,
903
975
  });
904
976
  }
905
977
  let authKey: AuthenticationKey;
906
978
  if ("toAccount" in args) {
907
979
  if (args.toAccount instanceof Ed25519Account) {
908
- return rotateAuthKeyWithChallenge({ aptosConfig, fromAccount, toNewPrivateKey: args.toAccount.privateKey });
980
+ return rotateAuthKeyWithChallenge({
981
+ aptosConfig,
982
+ fromAccount,
983
+ toNewPrivateKey: args.toAccount.privateKey,
984
+ options,
985
+ });
909
986
  }
910
987
  if (args.toAccount instanceof MultiEd25519Account) {
911
- return rotateAuthKeyWithChallenge({ aptosConfig, fromAccount, toAccount: args.toAccount });
988
+ return rotateAuthKeyWithChallenge({ aptosConfig, fromAccount, toAccount: args.toAccount, options });
912
989
  }
913
990
  authKey = args.toAccount.publicKey.authKey();
914
991
  } else if ("toAuthKey" in args) {
@@ -921,6 +998,7 @@ export async function rotateAuthKey(
921
998
  aptosConfig,
922
999
  fromAccount,
923
1000
  toAuthKey: authKey,
1001
+ options,
924
1002
  });
925
1003
 
926
1004
  if (dangerouslySkipVerification === true) {
@@ -957,9 +1035,10 @@ async function rotateAuthKeyWithChallenge(
957
1035
  args: {
958
1036
  aptosConfig: AptosConfig;
959
1037
  fromAccount: Account;
1038
+ options?: InputGenerateTransactionOptions;
960
1039
  } & ({ toNewPrivateKey: Ed25519PrivateKey } | { toAccount: MultiEd25519Account }),
961
1040
  ): Promise<PendingTransactionResponse> {
962
- const { aptosConfig, fromAccount } = args;
1041
+ const { aptosConfig, fromAccount, options } = args;
963
1042
  const accountInfo = await getInfo({
964
1043
  aptosConfig,
965
1044
  accountAddress: fromAccount.accountAddress,
@@ -1000,6 +1079,7 @@ async function rotateAuthKeyWithChallenge(
1000
1079
  ],
1001
1080
  abi: rotateAuthKeyAbi,
1002
1081
  },
1082
+ options,
1003
1083
  });
1004
1084
  return signAndSubmitTransaction({
1005
1085
  aptosConfig,
@@ -1017,8 +1097,9 @@ async function rotateAuthKeyUnverified(args: {
1017
1097
  aptosConfig: AptosConfig;
1018
1098
  fromAccount: Account;
1019
1099
  toAuthKey: AuthenticationKey;
1100
+ options?: InputGenerateTransactionOptions;
1020
1101
  }): Promise<PendingTransactionResponse> {
1021
- const { aptosConfig, fromAccount, toAuthKey } = args;
1102
+ const { aptosConfig, fromAccount, toAuthKey, options } = args;
1022
1103
  const authKey = toAuthKey;
1023
1104
  const rawTxn = await generateTransaction({
1024
1105
  aptosConfig,
@@ -1028,6 +1109,7 @@ async function rotateAuthKeyUnverified(args: {
1028
1109
  functionArguments: [MoveVector.U8(authKey.toUint8Array())],
1029
1110
  abi: rotateAuthKeyUnverifiedAbi,
1030
1111
  },
1112
+ options,
1031
1113
  });
1032
1114
  return signAndSubmitTransaction({
1033
1115
  aptosConfig,
@@ -1035,3 +1117,388 @@ async function rotateAuthKeyUnverified(args: {
1035
1117
  transaction: rawTxn,
1036
1118
  });
1037
1119
  }
1120
+
1121
+ export type AccountInfo = {
1122
+ accountAddress: AccountAddress;
1123
+ publicKey: BaseAccountPublicKey;
1124
+ lastTransactionVersion: number;
1125
+ };
1126
+
1127
+ export async function getAccountsForPublicKey(args: {
1128
+ aptosConfig: AptosConfig;
1129
+ publicKey: BaseAccountPublicKey;
1130
+ options?: { includeUnverified?: boolean; noMultiKey?: boolean };
1131
+ }): Promise<AccountInfo[]> {
1132
+ const { aptosConfig, publicKey, options } = args;
1133
+ const noMultiKey = options?.noMultiKey ?? false;
1134
+ if (noMultiKey && publicKey instanceof AbstractMultiKey) {
1135
+ throw new Error("Multi-key accounts are not supported when noMultiKey is true.");
1136
+ }
1137
+ const allPublicKeys: BaseAccountPublicKey[] = [publicKey];
1138
+
1139
+ // For Ed25519, we add the both the legacy Ed25519PublicKey and the new AnyPublicKey form.
1140
+ if (publicKey instanceof AnyPublicKey && publicKey.publicKey instanceof Ed25519PublicKey) {
1141
+ allPublicKeys.push(publicKey.publicKey);
1142
+ } else if (publicKey instanceof Ed25519PublicKey) {
1143
+ allPublicKeys.push(new AnyPublicKey(publicKey));
1144
+ }
1145
+
1146
+ // Run both operations in parallel
1147
+ const [defaultAccountData, multiPublicKeys] = await Promise.all([
1148
+ // Check the provided public key for the default account. In the case of Ed25519, this will check both the legacy Ed25519PublicKey
1149
+ // and the AnyPublicKey form and may an existing account for each.
1150
+ Promise.all(
1151
+ allPublicKeys.map(async (publicKey) => {
1152
+ const addressAndLastTxnVersion = await getDefaultAccountInfoForPublicKey({ aptosConfig, publicKey });
1153
+ if (addressAndLastTxnVersion) {
1154
+ return { ...addressAndLastTxnVersion, publicKey };
1155
+ }
1156
+ return undefined;
1157
+ }),
1158
+ ),
1159
+ // Get multi-keys for the provided public key if not already a multi-key.
1160
+ !(publicKey instanceof AbstractMultiKey) && !noMultiKey
1161
+ ? getMultiKeysForPublicKey({ aptosConfig, publicKey, options })
1162
+ : Promise.resolve([]),
1163
+ ]);
1164
+
1165
+ const result: {
1166
+ accountAddress: AccountAddress;
1167
+ publicKey: BaseAccountPublicKey;
1168
+ lastTransactionVersion: number;
1169
+ }[] = [];
1170
+
1171
+ // Add any default accounts that exist to the result.
1172
+ for (const data of defaultAccountData) {
1173
+ if (data) {
1174
+ result.push(data);
1175
+ }
1176
+ }
1177
+
1178
+ // Add any multi-keys to allPublicKeys
1179
+ allPublicKeys.push(...multiPublicKeys);
1180
+
1181
+ // Get a map of the auth key to the public key for all public keys.
1182
+ const authKeyToPublicKey = new Map(allPublicKeys.map((key) => [key.authKey().toString(), key]));
1183
+
1184
+ // Get the account addresses for the auth keys.
1185
+ const authKeyAccountAddressPairs = await getAccountAddressesForAuthKeys({
1186
+ aptosConfig,
1187
+ authKeys: allPublicKeys.map((key) => key.authKey()),
1188
+ options,
1189
+ });
1190
+
1191
+ for (const authKeyAccountAddressPair of authKeyAccountAddressPairs) {
1192
+ // Skip if the account address is already in the result.
1193
+ // This can happen in the rare edge case where the default account has been rotated but has been rotated back to the original auth key.
1194
+ if (result.find((r) => r.accountAddress === authKeyAccountAddressPair.accountAddress)) {
1195
+ continue;
1196
+ }
1197
+ // Get the public key for the auth key using the map we created earlier.
1198
+ const publicKey = authKeyToPublicKey.get(authKeyAccountAddressPair.authKey.toString());
1199
+ if (!publicKey) {
1200
+ throw new Error(
1201
+ `No publicKey found for authentication key ${authKeyAccountAddressPair.authKey}. This should never happen.`,
1202
+ );
1203
+ }
1204
+ result.push({
1205
+ accountAddress: authKeyAccountAddressPair.accountAddress,
1206
+ publicKey,
1207
+ lastTransactionVersion: authKeyAccountAddressPair.lastTransactionVersion,
1208
+ });
1209
+ }
1210
+ // Sort the result by the last transaction version in descending order (most recent first).
1211
+ return result.sort((a, b) => b.lastTransactionVersion - a.lastTransactionVersion);
1212
+ }
1213
+
1214
+ export async function deriveOwnedAccountsFromSigner(args: {
1215
+ aptosConfig: AptosConfig;
1216
+ signer: Account | PrivateKeyInput;
1217
+ options?: { includeUnverified?: boolean; noMultiKey?: boolean };
1218
+ }): Promise<Account[]> {
1219
+ const { aptosConfig, signer, options } = args;
1220
+
1221
+ if (signer instanceof Ed25519PrivateKey || signer instanceof Secp256k1PrivateKey) {
1222
+ return deriveOwnedAccountsFromPrivateKey({ aptosConfig, privateKey: signer, options });
1223
+ }
1224
+
1225
+ if (signer instanceof Ed25519Account || signer instanceof SingleKeyAccount) {
1226
+ return deriveOwnedAccountsFromPrivateKey({ aptosConfig, privateKey: signer.privateKey, options });
1227
+ }
1228
+
1229
+ if (signer instanceof KeylessAccount || signer instanceof FederatedKeylessAccount) {
1230
+ return deriveOwnedAccountsFromKeylessSigner({ aptosConfig, keylessAccount: signer, options });
1231
+ }
1232
+
1233
+ if (signer instanceof MultiKeyAccount) {
1234
+ if (signer.signers.length === 1) {
1235
+ return deriveOwnedAccountsFromSigner({ aptosConfig, signer: signer.signers[0], options });
1236
+ }
1237
+ }
1238
+
1239
+ if (signer instanceof MultiEd25519Account) {
1240
+ if (signer.signers.length === 1) {
1241
+ return deriveOwnedAccountsFromPrivateKey({ aptosConfig, privateKey: signer.signers[0], options });
1242
+ }
1243
+ }
1244
+
1245
+ throw new Error("Unknown signer type");
1246
+ }
1247
+
1248
+ async function deriveOwnedAccountsFromKeylessSigner(args: {
1249
+ aptosConfig: AptosConfig;
1250
+ keylessAccount: KeylessAccount | FederatedKeylessAccount;
1251
+ options?: { includeUnverified?: boolean; noMultiKey?: boolean };
1252
+ }): Promise<Account[]> {
1253
+ const { aptosConfig, keylessAccount, options } = args;
1254
+ const addressesAndPublicKeys = await getAccountsForPublicKey({
1255
+ aptosConfig,
1256
+ publicKey: keylessAccount.getAnyPublicKey(),
1257
+ options,
1258
+ });
1259
+
1260
+ const keylessAccountParams = {
1261
+ proof: keylessAccount.proofOrPromise,
1262
+ jwt: keylessAccount.jwt,
1263
+ ephemeralKeyPair: keylessAccount.ephemeralKeyPair,
1264
+ pepper: keylessAccount.pepper,
1265
+ verificationKeyHash: keylessAccount.verificationKeyHash,
1266
+ };
1267
+
1268
+ const accounts: Account[] = [];
1269
+ for (const { accountAddress, publicKey } of addressesAndPublicKeys) {
1270
+ if (publicKey instanceof AbstractMultiKey) {
1271
+ if (publicKey.getSignaturesRequired() > 1) {
1272
+ continue;
1273
+ }
1274
+ if (publicKey instanceof MultiEd25519PublicKey) {
1275
+ throw new Error("Keyless authentication cannot be used for multi-ed25519 accounts. This should never happen.");
1276
+ } else if (publicKey instanceof MultiKey) {
1277
+ accounts.push(new MultiKeyAccount({ multiKey: publicKey, signers: [keylessAccount], address: accountAddress }));
1278
+ }
1279
+ } else {
1280
+ if (keylessAccount instanceof FederatedKeylessAccount) {
1281
+ accounts.push(
1282
+ FederatedKeylessAccount.create({
1283
+ ...keylessAccountParams,
1284
+ address: accountAddress,
1285
+ jwkAddress: keylessAccount.publicKey.jwkAddress,
1286
+ }),
1287
+ );
1288
+ } else {
1289
+ accounts.push(
1290
+ KeylessAccount.create({
1291
+ ...keylessAccountParams,
1292
+ address: accountAddress,
1293
+ }),
1294
+ );
1295
+ }
1296
+ }
1297
+ }
1298
+ return accounts;
1299
+ }
1300
+
1301
+ async function deriveOwnedAccountsFromPrivateKey(args: {
1302
+ aptosConfig: AptosConfig;
1303
+ privateKey: Ed25519PrivateKey | Secp256k1PrivateKey;
1304
+ options?: { includeUnverified?: boolean; noMultiKey?: boolean };
1305
+ }): Promise<Account[]> {
1306
+ const { aptosConfig, privateKey, options } = args;
1307
+ const singleKeyAccount = Account.fromPrivateKey({ privateKey, legacy: false });
1308
+ const addressesAndPublicKeys = await getAccountsForPublicKey({
1309
+ aptosConfig,
1310
+ publicKey: new AnyPublicKey(privateKey.publicKey()),
1311
+ options,
1312
+ });
1313
+
1314
+ const accounts: Account[] = [];
1315
+
1316
+ // Iterate through the addressesAndPublicKeys and construct the accounts.
1317
+ for (const { accountAddress, publicKey } of addressesAndPublicKeys) {
1318
+ if (publicKey instanceof AbstractMultiKey) {
1319
+ // Skip multi-key accounts with more than 1 signature required as the user does not have full ownership with just 1 private key.
1320
+ if (publicKey.getSignaturesRequired() > 1) {
1321
+ continue;
1322
+ }
1323
+ // Construct the appropriate multi-key type.
1324
+ if (publicKey instanceof MultiEd25519PublicKey) {
1325
+ accounts.push(
1326
+ new MultiEd25519Account({ publicKey, signers: [privateKey as Ed25519PrivateKey], address: accountAddress }),
1327
+ );
1328
+ } else if (publicKey instanceof MultiKey) {
1329
+ accounts.push(
1330
+ new MultiKeyAccount({ multiKey: publicKey, signers: [singleKeyAccount], address: accountAddress }),
1331
+ );
1332
+ }
1333
+ } else {
1334
+ // Check if the public key is a legacy Ed25519PublicKey, if so, we need to use the legacy account constructor.
1335
+ const isLegacy = publicKey instanceof Ed25519PublicKey;
1336
+ accounts.push(Account.fromPrivateKey({ privateKey, address: accountAddress, legacy: isLegacy }));
1337
+ }
1338
+ }
1339
+ return accounts;
1340
+ }
1341
+
1342
+ /**
1343
+ * Gets the multi-keys for a given public key.
1344
+ *
1345
+ * This function retrieves the multi-keys that contain the provided public key.
1346
+ * It performs the following steps:
1347
+ * 1. Constructs a where condition for the public key where the public key matches the provided public key.
1348
+ * 2. Queries the indexer for the multi-keys.
1349
+ * 3. Returns the multi-keys.
1350
+ *
1351
+ * @param args.aptosConfig - The configuration settings for the Aptos network.
1352
+ * @param args.publicKey - The public key to get the multi-keys for. This public key cannot itself be a multi-key.
1353
+ * @returns The multi-keys (MultiKey or MultiEd25519PublicKey) that contain the given public key.
1354
+ */
1355
+ async function getMultiKeysForPublicKey(args: {
1356
+ aptosConfig: AptosConfig;
1357
+ publicKey: Ed25519PublicKey | AnyPublicKey;
1358
+ options?: { includeUnverified?: boolean };
1359
+ }): Promise<(MultiKey | MultiEd25519PublicKey)[]> {
1360
+ const { aptosConfig, publicKey, options } = args;
1361
+ if (publicKey instanceof AbstractMultiKey) {
1362
+ throw new Error("Public key is a multi-key.");
1363
+ }
1364
+ const includeUnverified = options?.includeUnverified ?? false;
1365
+ const anyPublicKey = publicKey instanceof AnyPublicKey ? publicKey : new AnyPublicKey(publicKey);
1366
+ const baseKey = anyPublicKey.publicKey;
1367
+ const variant = anyPublicKeyVariantToString(anyPublicKey.variant);
1368
+
1369
+ const whereCondition: any = {
1370
+ public_key: { _eq: baseKey.toString() },
1371
+ public_key_type: { _eq: variant },
1372
+ ...(includeUnverified ? {} : { is_public_key_used: { _eq: true } }),
1373
+ };
1374
+
1375
+ const graphqlQuery = {
1376
+ query: GetAuthKeysForPublicKey,
1377
+ variables: {
1378
+ where_condition: whereCondition,
1379
+ },
1380
+ };
1381
+
1382
+ const { public_key_auth_keys: data } = await queryIndexer<GetAuthKeysForPublicKeyQuery>({
1383
+ aptosConfig,
1384
+ query: graphqlQuery,
1385
+ originMethod: "getMultiKeysForPublicKey",
1386
+ });
1387
+
1388
+ const authKeys = data.map((entry) => {
1389
+ switch (entry.signature_type) {
1390
+ case "multi_ed25519_signature":
1391
+ return MultiEd25519PublicKey.deserializeWithoutLength(Deserializer.fromHex(entry.account_public_key!));
1392
+ case "multi_key_signature":
1393
+ return MultiKey.deserialize(Deserializer.fromHex(entry.account_public_key!));
1394
+ default:
1395
+ throw new Error(`Unknown multi-signature type: ${entry.signature_type}`);
1396
+ }
1397
+ });
1398
+ return authKeys;
1399
+ }
1400
+
1401
+ /**
1402
+ * Gets the account addresses for the given authentication keys.
1403
+ *
1404
+ * This function retrieves the account addresses that are associated with the provided authentication keys.
1405
+ * It performs the following steps:
1406
+ * 1. Constructs a where condition for the authentication keys where auth key matches any of the provided auth keys.
1407
+ * 2. Queries the indexer for the account addresses and gets the results ordered by the last transaction version (most recent first).
1408
+ * 3. Returns the account addresses.
1409
+ *
1410
+ * @param args.aptosConfig - The configuration settings for the Aptos network.
1411
+ * @param args.authKeys - The authentication keys to get the account addresses for.
1412
+ * @param args.options.includeUnverified - Whether to include unverified accounts in the results. Unverified accounts
1413
+ * are accounts that can be authenticated with the signer, but there is no history of the signer using the account.
1414
+ * Default is false.
1415
+ * @returns The account addresses associated with the given authentication keys.
1416
+ */
1417
+ async function getAccountAddressesForAuthKeys(args: {
1418
+ aptosConfig: AptosConfig;
1419
+ authKeys: AuthenticationKey[];
1420
+ options?: { includeUnverified?: boolean };
1421
+ }): Promise<{ authKey: AuthenticationKey; accountAddress: AccountAddress; lastTransactionVersion: number }[]> {
1422
+ const { aptosConfig, authKeys, options } = args;
1423
+ const includeUnverified = options?.includeUnverified ?? false;
1424
+ if (authKeys.length === 0) {
1425
+ throw new Error("No authentication keys provided");
1426
+ }
1427
+ const whereCondition: any = {
1428
+ auth_key: { _in: authKeys.map((authKey) => authKey.toString()) },
1429
+ ...(includeUnverified ? {} : { is_auth_key_used: { _eq: true } }),
1430
+ };
1431
+
1432
+ const graphqlQuery = {
1433
+ query: GetAccountAddressesForAuthKey,
1434
+ variables: {
1435
+ where_condition: whereCondition,
1436
+ order_by: [{ last_transaction_version: "desc" }],
1437
+ },
1438
+ };
1439
+ const { auth_key_account_addresses: data } = await queryIndexer<GetAccountAddressesForAuthKeyQuery>({
1440
+ aptosConfig,
1441
+ query: graphqlQuery,
1442
+ originMethod: "getAccountAddressesForAuthKeys",
1443
+ });
1444
+ return data.map((entry) => ({
1445
+ authKey: new AuthenticationKey({ data: entry.auth_key }),
1446
+ accountAddress: new AccountAddress(Hex.hexInputToUint8Array(entry.account_address)),
1447
+ lastTransactionVersion: Number(entry.last_transaction_version),
1448
+ }));
1449
+ }
1450
+
1451
+ /**
1452
+ * Returns the last transaction version that was signed by an account.
1453
+ *
1454
+ * If an account was created but has not signed any transactions, the last transaction version will be 0.
1455
+ *
1456
+ * @param args.aptosConfig - The configuration settings for the Aptos network.
1457
+ * @param args.accountAddress - The account address to get the latest transaction version for.
1458
+ * @returns The last transaction version that was signed by the account.
1459
+ */
1460
+ async function getLatestTransactionVersionForAddress(args: {
1461
+ aptosConfig: AptosConfig;
1462
+ accountAddress: AccountAddressInput;
1463
+ }): Promise<number> {
1464
+ const { aptosConfig, accountAddress } = args;
1465
+ const transactions = await getTransactions({ aptosConfig, accountAddress, options: { limit: 1 } });
1466
+ if (transactions.length === 0) {
1467
+ return 0;
1468
+ }
1469
+ return Number(transactions[0].version);
1470
+ }
1471
+
1472
+ /**
1473
+ * Gets the default account info for a given public key. 'Default account' means the account
1474
+ * is address is the same as the auth key derived from the public key and the account auth key has
1475
+ * not been rotated.
1476
+ *
1477
+ * @param args - The arguments for getting the default account info for a given public key.
1478
+ * @param args.aptosConfig - The configuration settings for the Aptos network.
1479
+ * @param args.publicKey - The public key to use to derive the address.
1480
+ * @returns An object containing the account address and the last transaction version, or undefined if the account does not exist.
1481
+ */
1482
+ async function getDefaultAccountInfoForPublicKey(args: {
1483
+ aptosConfig: AptosConfig;
1484
+ publicKey: AccountPublicKey;
1485
+ }): Promise<{ accountAddress: AccountAddress; lastTransactionVersion: number } | undefined> {
1486
+ const { aptosConfig, publicKey } = args;
1487
+ const derivedAddress = publicKey.authKey().derivedAddress();
1488
+
1489
+ const [lastTransactionVersion, exists] = await Promise.all([
1490
+ getLatestTransactionVersionForAddress({
1491
+ aptosConfig,
1492
+ accountAddress: derivedAddress,
1493
+ }),
1494
+ doesAccountExistAtAddress({
1495
+ aptosConfig,
1496
+ accountAddress: derivedAddress,
1497
+ options: { withAuthKey: publicKey.authKey() },
1498
+ }),
1499
+ ]);
1500
+ if (exists) {
1501
+ return { accountAddress: derivedAddress, lastTransactionVersion };
1502
+ }
1503
+ return undefined;
1504
+ }