@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.
- package/dist/common/{accountAddress-B3Y4WI-E.d.ts → accountAddress-D0xKX-UM.d.ts} +11 -47
- package/dist/common/chunk-ZMDE3DNL.js +4 -0
- package/dist/common/chunk-ZMDE3DNL.js.map +1 -0
- package/dist/common/cli/index.d.ts +1 -1
- package/dist/common/cli/index.js +1 -1
- package/dist/common/cli/index.js.map +1 -1
- package/dist/common/index.d.ts +9 -121
- package/dist/common/index.js +31 -52
- package/dist/common/index.js.map +1 -1
- package/dist/esm/{Ed25519Account-D2MdV8Av.d.mts → Ed25519Account-D9XrCLfE.d.mts} +2 -2
- package/dist/esm/account/AbstractKeylessAccount.d.mts +2 -2
- package/dist/esm/account/AbstractKeylessAccount.mjs +1 -1
- package/dist/esm/account/AbstractedAccount.d.mts +1 -1
- package/dist/esm/account/AbstractedAccount.mjs +1 -1
- package/dist/esm/account/Account.d.mts +1 -1
- package/dist/esm/account/Account.mjs +1 -1
- package/dist/esm/account/AccountUtils.d.mts +2 -2
- package/dist/esm/account/AccountUtils.mjs +1 -1
- package/dist/esm/account/DerivableAbstractedAccount.d.mts +1 -1
- package/dist/esm/account/DerivableAbstractedAccount.mjs +1 -1
- package/dist/esm/account/Ed25519Account.d.mts +1 -1
- package/dist/esm/account/Ed25519Account.mjs +1 -1
- package/dist/esm/account/EphemeralKeyPair.mjs +1 -1
- package/dist/esm/account/FederatedKeylessAccount.d.mts +2 -3
- package/dist/esm/account/FederatedKeylessAccount.mjs +1 -1
- package/dist/esm/account/KeylessAccount.d.mts +2 -3
- package/dist/esm/account/KeylessAccount.mjs +1 -1
- package/dist/esm/account/MultiEd25519Account.d.mts +1 -1
- package/dist/esm/account/MultiEd25519Account.mjs +1 -1
- package/dist/esm/account/MultiKeyAccount.d.mts +2 -2
- package/dist/esm/account/MultiKeyAccount.mjs +1 -1
- package/dist/esm/account/SingleKeyAccount.d.mts +1 -1
- package/dist/esm/account/SingleKeyAccount.mjs +1 -1
- package/dist/esm/account/index.d.mts +2 -2
- package/dist/esm/account/index.mjs +1 -1
- package/dist/esm/account/utils.mjs +1 -1
- package/dist/esm/api/account/abstraction.mjs +1 -1
- package/dist/esm/api/account.d.mts +6 -97
- package/dist/esm/api/account.mjs +1 -1
- package/dist/esm/api/ans.d.mts +1 -1
- package/dist/esm/api/ans.mjs +1 -1
- package/dist/esm/api/aptos.d.mts +6 -7
- package/dist/esm/api/aptos.mjs +1 -1
- package/dist/esm/api/aptosConfig.mjs +1 -1
- package/dist/esm/api/coin.mjs +1 -1
- package/dist/esm/api/digitalAsset.d.mts +1 -1
- package/dist/esm/api/digitalAsset.mjs +1 -1
- package/dist/esm/api/event.mjs +1 -1
- package/dist/esm/api/faucet.mjs +1 -1
- package/dist/esm/api/fungibleAsset.d.mts +1 -1
- package/dist/esm/api/fungibleAsset.mjs +1 -1
- package/dist/esm/api/general.mjs +1 -1
- package/dist/esm/api/index.d.mts +6 -7
- package/dist/esm/api/index.mjs +1 -1
- package/dist/esm/api/keyless.d.mts +2 -2
- package/dist/esm/api/keyless.mjs +1 -1
- package/dist/esm/api/object.mjs +1 -1
- package/dist/esm/api/staking.mjs +1 -1
- package/dist/esm/api/table.mjs +1 -1
- package/dist/esm/api/transaction.d.mts +1 -2
- package/dist/esm/api/transaction.mjs +1 -1
- package/dist/esm/api/transactionSubmission/build.mjs +1 -1
- package/dist/esm/api/transactionSubmission/management.d.mts +1 -1
- package/dist/esm/api/transactionSubmission/management.mjs +1 -1
- package/dist/esm/api/transactionSubmission/sign.d.mts +1 -1
- package/dist/esm/api/transactionSubmission/sign.mjs +1 -1
- package/dist/esm/api/transactionSubmission/sign.mjs.map +1 -1
- package/dist/esm/api/transactionSubmission/simulate.mjs +1 -1
- package/dist/esm/api/transactionSubmission/submit.mjs +1 -1
- package/dist/esm/api/utils.mjs +1 -1
- package/dist/esm/bcs/deserializer.mjs +1 -1
- package/dist/esm/bcs/index.mjs +1 -1
- package/dist/esm/bcs/serializable/movePrimitives.d.mts +1 -1
- package/dist/esm/bcs/serializable/movePrimitives.mjs +1 -1
- package/dist/esm/bcs/serializable/moveStructs.mjs +1 -1
- package/dist/esm/{chunk-4F5EECVQ.mjs → chunk-2UBI3AZJ.mjs} +2 -2
- package/dist/esm/{chunk-CO67Y6YE.mjs → chunk-4JT5AESZ.mjs} +2 -2
- package/dist/esm/chunk-5YLNYSBT.mjs +4 -0
- package/dist/esm/chunk-5YLNYSBT.mjs.map +1 -0
- package/dist/esm/{chunk-XTOIL6MB.mjs → chunk-DLIBG6H7.mjs} +2 -2
- package/dist/esm/{chunk-XTOIL6MB.mjs.map → chunk-DLIBG6H7.mjs.map} +1 -1
- package/dist/esm/{chunk-RQX6JOEN.mjs → chunk-EF4FA5I6.mjs} +2 -2
- package/dist/esm/{chunk-N4VVDQA5.mjs → chunk-G6HENV5D.mjs} +2 -2
- package/dist/esm/{chunk-CQJLK4WE.mjs → chunk-G7WH6GQP.mjs} +2 -2
- package/dist/esm/{chunk-UQWF24SS.mjs → chunk-K43K3YG7.mjs} +2 -2
- package/dist/esm/{chunk-2DYSBAZ7.mjs → chunk-MA4QUN6P.mjs} +2 -2
- package/dist/esm/chunk-ODAAZLPK.mjs +2 -0
- package/dist/esm/chunk-ODAAZLPK.mjs.map +1 -0
- package/dist/esm/chunk-RIRJNQ7B.mjs +2 -0
- package/dist/esm/chunk-RJ7F4JDV.mjs +2 -0
- package/dist/esm/{chunk-JCFTAG5Z.mjs.map → chunk-RJ7F4JDV.mjs.map} +1 -1
- package/dist/esm/{chunk-V7NWNNBI.mjs → chunk-SE2VS7WM.mjs} +2 -2
- package/dist/esm/{chunk-3BUKTQDX.mjs → chunk-TLFZOAAB.mjs} +2 -2
- package/dist/esm/{chunk-GPNNEHW4.mjs → chunk-USB3LA6B.mjs} +2 -2
- package/dist/esm/{chunk-UL777LTI.mjs → chunk-VHNX2NUR.mjs} +26 -47
- package/dist/esm/chunk-VHNX2NUR.mjs.map +1 -0
- package/dist/esm/{chunk-SVMCNLFC.mjs → chunk-ZNLOQO4Q.mjs} +2 -2
- package/dist/esm/cli/index.mjs +1 -1
- package/dist/esm/cli/localNode.mjs +1 -1
- package/dist/esm/client/core.mjs +1 -1
- package/dist/esm/client/get.mjs +1 -1
- package/dist/esm/client/index.mjs +1 -1
- package/dist/esm/client/post.mjs +1 -1
- package/dist/esm/core/account/index.mjs +1 -1
- package/dist/esm/core/account/utils/address.mjs +1 -1
- package/dist/esm/core/account/utils/index.mjs +1 -1
- package/dist/esm/core/accountAddress.mjs +1 -1
- package/dist/esm/core/authenticationKey.mjs +1 -1
- package/dist/esm/core/crypto/abstraction.mjs +1 -1
- package/dist/esm/core/crypto/ed25519.d.mts +1 -1
- package/dist/esm/core/crypto/ed25519.mjs +1 -1
- package/dist/esm/core/crypto/ephemeral.mjs +1 -1
- package/dist/esm/core/crypto/federatedKeyless.d.mts +1 -1
- package/dist/esm/core/crypto/federatedKeyless.mjs +1 -1
- package/dist/esm/core/crypto/index.d.mts +1 -2
- package/dist/esm/core/crypto/index.mjs +1 -1
- package/dist/esm/core/crypto/keyless.d.mts +1 -1
- package/dist/esm/core/crypto/keyless.mjs +1 -1
- package/dist/esm/core/crypto/multiEd25519.d.mts +0 -10
- package/dist/esm/core/crypto/multiEd25519.mjs +1 -1
- package/dist/esm/core/crypto/multiKey.d.mts +0 -2
- package/dist/esm/core/crypto/multiKey.mjs +1 -1
- package/dist/esm/core/crypto/privateKey.mjs +1 -1
- package/dist/esm/core/crypto/proof.mjs +1 -1
- package/dist/esm/core/crypto/publicKey.mjs +1 -1
- package/dist/esm/core/crypto/secp256k1.d.mts +1 -1
- package/dist/esm/core/crypto/secp256k1.mjs +1 -1
- package/dist/esm/core/crypto/signature.mjs +1 -1
- package/dist/esm/core/crypto/singleKey.mjs +1 -1
- package/dist/esm/core/index.d.mts +1 -2
- package/dist/esm/core/index.mjs +1 -1
- package/dist/esm/errors/index.mjs +1 -1
- package/dist/esm/{federatedKeyless-BelAZrlM.d.mts → federatedKeyless-DAYXjY2Y.d.mts} +2 -2
- package/dist/esm/index.d.mts +4 -5
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/internal/abstraction.mjs +1 -1
- package/dist/esm/internal/account.d.mts +14 -43
- package/dist/esm/internal/account.mjs +1 -1
- package/dist/esm/internal/ans.d.mts +2 -2
- package/dist/esm/internal/ans.mjs +1 -1
- package/dist/esm/internal/coin.mjs +1 -1
- package/dist/esm/internal/digitalAsset.d.mts +2 -2
- package/dist/esm/internal/digitalAsset.mjs +1 -1
- package/dist/esm/internal/event.mjs +1 -1
- package/dist/esm/internal/faucet.mjs +1 -1
- package/dist/esm/internal/fungibleAsset.d.mts +1 -1
- package/dist/esm/internal/fungibleAsset.mjs +1 -1
- package/dist/esm/internal/general.mjs +1 -1
- package/dist/esm/internal/keyless.d.mts +2 -11
- package/dist/esm/internal/keyless.mjs +1 -1
- package/dist/esm/internal/object.mjs +1 -1
- package/dist/esm/internal/staking.mjs +1 -1
- package/dist/esm/internal/table.mjs +1 -1
- package/dist/esm/internal/transaction.mjs +1 -1
- package/dist/esm/internal/transactionSubmission.d.mts +1 -1
- package/dist/esm/internal/transactionSubmission.mjs +1 -1
- package/dist/esm/internal/utils/index.mjs +1 -1
- package/dist/esm/internal/utils/utils.mjs +1 -1
- package/dist/esm/internal/view.mjs +1 -1
- package/dist/esm/transactions/authenticator/account.mjs +1 -1
- package/dist/esm/transactions/authenticator/index.mjs +1 -1
- package/dist/esm/transactions/authenticator/transaction.mjs +1 -1
- package/dist/esm/transactions/index.mjs +1 -1
- package/dist/esm/transactions/instances/index.mjs +1 -1
- package/dist/esm/transactions/instances/moduleId.mjs +1 -1
- package/dist/esm/transactions/instances/multiAgentTransaction.mjs +1 -1
- package/dist/esm/transactions/instances/rawTransaction.mjs +1 -1
- package/dist/esm/transactions/instances/rotationProofChallenge.mjs +1 -1
- package/dist/esm/transactions/instances/signedTransaction.mjs +1 -1
- package/dist/esm/transactions/instances/simpleTransaction.mjs +1 -1
- package/dist/esm/transactions/instances/transactionPayload.d.mts +1 -1
- package/dist/esm/transactions/instances/transactionPayload.mjs +1 -1
- package/dist/esm/transactions/management/accountSequenceNumber.d.mts +1 -1
- package/dist/esm/transactions/management/accountSequenceNumber.mjs +1 -1
- package/dist/esm/transactions/management/index.d.mts +1 -1
- package/dist/esm/transactions/management/index.mjs +1 -1
- package/dist/esm/transactions/management/transactionWorker.d.mts +1 -1
- package/dist/esm/transactions/management/transactionWorker.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/helpers.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/index.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/remoteAbi.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/signingMessage.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/transactionBuilder.d.mts +2 -2
- package/dist/esm/transactions/transactionBuilder/transactionBuilder.mjs +1 -1
- package/dist/esm/transactions/typeTag/index.mjs +1 -1
- package/dist/esm/transactions/typeTag/parser.mjs +1 -1
- package/dist/esm/transactions/types.d.mts +1 -1
- package/dist/esm/types/generated/operations.d.mts +10 -37
- package/dist/esm/types/generated/queries.d.mts +2 -6
- package/dist/esm/types/generated/queries.mjs +1 -1
- package/dist/esm/types/generated/types.d.mts +1172 -584
- package/dist/esm/types/generated/types.mjs +1 -1
- package/dist/esm/types/generated/types.mjs.map +1 -1
- package/dist/esm/types/index.d.mts +2 -2
- package/dist/esm/types/index.mjs +1 -1
- package/dist/esm/types/indexer.d.mts +2 -8
- package/dist/esm/types/types.d.mts +3 -25
- package/dist/esm/types/types.mjs +1 -1
- package/dist/esm/utils/const.d.mts +0 -1
- package/dist/esm/utils/const.mjs +1 -1
- package/dist/esm/utils/helpers.mjs +1 -1
- package/dist/esm/utils/index.mjs +1 -1
- package/dist/esm/utils/normalizeBundle.mjs +1 -1
- package/package.json +2 -2
- package/src/account/FederatedKeylessAccount.ts +1 -7
- package/src/account/KeylessAccount.ts +2 -17
- package/src/api/account.ts +2 -122
- package/src/api/transaction.ts +0 -1
- package/src/core/crypto/index.ts +0 -1
- package/src/core/crypto/multiEd25519.ts +0 -26
- package/src/core/crypto/multiKey.ts +0 -6
- package/src/internal/account.ts +53 -523
- package/src/internal/keyless.ts +0 -10
- package/src/types/codegen.yaml +1 -1
- package/src/types/generated/operations.ts +8 -39
- package/src/types/generated/queries.ts +0 -53
- package/src/types/generated/types.ts +1240 -621
- package/src/types/indexer.ts +0 -8
- package/src/types/types.ts +3 -40
- package/src/utils/const.ts +0 -1
- package/dist/common/chunk-BNN2XWNR.js +0 -4
- package/dist/common/chunk-BNN2XWNR.js.map +0 -1
- package/dist/esm/chunk-3FEFJIVT.mjs +0 -2
- package/dist/esm/chunk-3FEFJIVT.mjs.map +0 -1
- package/dist/esm/chunk-4YLUM62M.mjs +0 -2
- package/dist/esm/chunk-5HXLZHDW.mjs +0 -1
- package/dist/esm/chunk-5HXLZHDW.mjs.map +0 -1
- package/dist/esm/chunk-GRPSFJ3N.mjs +0 -4
- package/dist/esm/chunk-GRPSFJ3N.mjs.map +0 -1
- package/dist/esm/chunk-JCFTAG5Z.mjs +0 -2
- package/dist/esm/chunk-UL777LTI.mjs.map +0 -1
- package/dist/esm/core/crypto/types.d.mts +0 -25
- package/dist/esm/core/crypto/types.mjs +0 -2
- package/dist/esm/core/crypto/types.mjs.map +0 -1
- package/src/core/crypto/types.ts +0 -9
- package/src/internal/queries/getAccountAddressesForAuthKey.graphql +0 -8
- package/src/internal/queries/getAuthKeysForPublicKey.graphql +0 -11
- /package/dist/esm/{chunk-4F5EECVQ.mjs.map → chunk-2UBI3AZJ.mjs.map} +0 -0
- /package/dist/esm/{chunk-CO67Y6YE.mjs.map → chunk-4JT5AESZ.mjs.map} +0 -0
- /package/dist/esm/{chunk-RQX6JOEN.mjs.map → chunk-EF4FA5I6.mjs.map} +0 -0
- /package/dist/esm/{chunk-N4VVDQA5.mjs.map → chunk-G6HENV5D.mjs.map} +0 -0
- /package/dist/esm/{chunk-CQJLK4WE.mjs.map → chunk-G7WH6GQP.mjs.map} +0 -0
- /package/dist/esm/{chunk-UQWF24SS.mjs.map → chunk-K43K3YG7.mjs.map} +0 -0
- /package/dist/esm/{chunk-2DYSBAZ7.mjs.map → chunk-MA4QUN6P.mjs.map} +0 -0
- /package/dist/esm/{chunk-4YLUM62M.mjs.map → chunk-RIRJNQ7B.mjs.map} +0 -0
- /package/dist/esm/{chunk-V7NWNNBI.mjs.map → chunk-SE2VS7WM.mjs.map} +0 -0
- /package/dist/esm/{chunk-3BUKTQDX.mjs.map → chunk-TLFZOAAB.mjs.map} +0 -0
- /package/dist/esm/{chunk-GPNNEHW4.mjs.map → chunk-USB3LA6B.mjs.map} +0 -0
- /package/dist/esm/{chunk-SVMCNLFC.mjs.map → chunk-ZNLOQO4Q.mjs.map} +0 -0
package/src/internal/account.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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<
|
|
186
|
+
}): Promise<TransactionResponse[]> {
|
|
217
187
|
const { aptosConfig, accountAddress, options } = args;
|
|
218
|
-
return paginateWithCursor<{},
|
|
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
|
-
*
|
|
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
|
|
763
|
+
* we’ll 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:
|
|
810
|
-
options?: {
|
|
811
|
-
throwIfNoAccountFound?: boolean;
|
|
812
|
-
};
|
|
775
|
+
privateKey: PrivateKey;
|
|
813
776
|
}): Promise<Account> {
|
|
814
|
-
const { aptosConfig, privateKey
|
|
815
|
-
const
|
|
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
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
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
|
-
|
|
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
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
}
|