@aptos-labs/ts-sdk 2.0.0-zeta.0 → 2.0.0

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