@aptos-labs/ts-sdk 0.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 (110) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +144 -0
  3. package/dist/browser/index.global.js +410 -0
  4. package/dist/browser/index.global.js.map +1 -0
  5. package/dist/cjs/index.d.ts +4965 -0
  6. package/dist/cjs/index.js +4762 -0
  7. package/dist/cjs/index.js.map +1 -0
  8. package/dist/esm/index.d.ts +4965 -0
  9. package/dist/esm/index.mjs +4645 -0
  10. package/dist/esm/index.mjs.map +1 -0
  11. package/dist/types/index.d.ts +1247 -0
  12. package/dist/types/index.js +151 -0
  13. package/dist/types/index.js.map +1 -0
  14. package/package.json +79 -0
  15. package/src/api/account.ts +360 -0
  16. package/src/api/aptos.ts +103 -0
  17. package/src/api/aptosConfig.ts +77 -0
  18. package/src/api/coin.ts +39 -0
  19. package/src/api/digitalAsset.ts +192 -0
  20. package/src/api/event.ts +78 -0
  21. package/src/api/faucet.ts +30 -0
  22. package/src/api/fungibleAsset.ts +82 -0
  23. package/src/api/general.ts +188 -0
  24. package/src/api/index.ts +5 -0
  25. package/src/api/staking.ts +58 -0
  26. package/src/api/transaction.ts +135 -0
  27. package/src/api/transactionSubmission.ts +168 -0
  28. package/src/bcs/consts.ts +12 -0
  29. package/src/bcs/deserializer.ts +248 -0
  30. package/src/bcs/index.ts +9 -0
  31. package/src/bcs/serializable/entryFunctionBytes.ts +61 -0
  32. package/src/bcs/serializable/fixedBytes.ts +65 -0
  33. package/src/bcs/serializable/movePrimitives.ts +211 -0
  34. package/src/bcs/serializable/moveStructs.ts +462 -0
  35. package/src/bcs/serializer.ts +353 -0
  36. package/src/client/core.ts +106 -0
  37. package/src/client/get.ts +109 -0
  38. package/src/client/index.ts +7 -0
  39. package/src/client/post.ts +90 -0
  40. package/src/client/types.ts +58 -0
  41. package/src/core/account.ts +180 -0
  42. package/src/core/accountAddress.ts +407 -0
  43. package/src/core/authenticationKey.ts +102 -0
  44. package/src/core/common.ts +40 -0
  45. package/src/core/crypto/asymmetricCrypto.ts +77 -0
  46. package/src/core/crypto/ed25519.ts +224 -0
  47. package/src/core/crypto/index.ts +7 -0
  48. package/src/core/crypto/multiEd25519.ts +251 -0
  49. package/src/core/crypto/secp256k1.ts +227 -0
  50. package/src/core/hex.ts +177 -0
  51. package/src/core/index.ts +9 -0
  52. package/src/index.ts +12 -0
  53. package/src/internal/account.ts +484 -0
  54. package/src/internal/coin.ts +32 -0
  55. package/src/internal/digitalAsset.ts +302 -0
  56. package/src/internal/event.ts +88 -0
  57. package/src/internal/faucet.ts +41 -0
  58. package/src/internal/fungibleAsset.ts +114 -0
  59. package/src/internal/general.ts +160 -0
  60. package/src/internal/queries/TokenActivitiesFieldsFragment.graphql +17 -0
  61. package/src/internal/queries/currentTokenOwnershipFieldsFragment.graphql +45 -0
  62. package/src/internal/queries/getAccountCoinCount.graphql +7 -0
  63. package/src/internal/queries/getAccountCoinsData.graphql +32 -0
  64. package/src/internal/queries/getAccountCollectionsWithOwnedTokens.graphql +33 -0
  65. package/src/internal/queries/getAccountOwnedObjects.graphql +16 -0
  66. package/src/internal/queries/getAccountOwnedTokens.graphql +11 -0
  67. package/src/internal/queries/getAccountOwnedTokensByTokenData.graphql +11 -0
  68. package/src/internal/queries/getAccountOwnedTokensFromCollectionAddress.graphql +11 -0
  69. package/src/internal/queries/getAccountTokensCount.graphql +7 -0
  70. package/src/internal/queries/getAccountTransactionsCount.graphql +7 -0
  71. package/src/internal/queries/getChainTopUserTransactions.graphql +5 -0
  72. package/src/internal/queries/getCollectionData.graphql +20 -0
  73. package/src/internal/queries/getCurrentFungibleAssetBalances.graphql +17 -0
  74. package/src/internal/queries/getDelegatedStakingActivities.graphql +12 -0
  75. package/src/internal/queries/getEvents.graphql +12 -0
  76. package/src/internal/queries/getFungibleAssetActivities.graphql +20 -0
  77. package/src/internal/queries/getFungibleAssetMetadata.graphql +16 -0
  78. package/src/internal/queries/getNumberOfDelegatorsQuery.graphql +9 -0
  79. package/src/internal/queries/getProcessorStatus.graphql +7 -0
  80. package/src/internal/queries/getTokenActivity.graphql +11 -0
  81. package/src/internal/queries/getTokenCurrentOwner.graphql +11 -0
  82. package/src/internal/queries/getTokenData.graphql +38 -0
  83. package/src/internal/staking.ts +68 -0
  84. package/src/internal/transaction.ts +245 -0
  85. package/src/internal/transactionSubmission.ts +162 -0
  86. package/src/transactions/authenticator/account.ts +121 -0
  87. package/src/transactions/authenticator/transaction.ts +222 -0
  88. package/src/transactions/instances/chainId.ts +26 -0
  89. package/src/transactions/instances/identifier.ts +28 -0
  90. package/src/transactions/instances/index.ts +9 -0
  91. package/src/transactions/instances/moduleId.ts +53 -0
  92. package/src/transactions/instances/rawTransaction.ts +199 -0
  93. package/src/transactions/instances/signedTransaction.ts +43 -0
  94. package/src/transactions/instances/transactionArgument.ts +37 -0
  95. package/src/transactions/instances/transactionPayload.ts +407 -0
  96. package/src/transactions/transaction_builder/transaction_builder.ts +541 -0
  97. package/src/transactions/typeTag/typeTag.ts +487 -0
  98. package/src/transactions/types.ts +262 -0
  99. package/src/types/codegen.yaml +33 -0
  100. package/src/types/generated/operations.ts +623 -0
  101. package/src/types/generated/queries.ts +737 -0
  102. package/src/types/generated/types.ts +10387 -0
  103. package/src/types/index.ts +944 -0
  104. package/src/types/indexer.ts +93 -0
  105. package/src/utils/apiEndpoints.ts +36 -0
  106. package/src/utils/const.ts +51 -0
  107. package/src/utils/hdKey.ts +113 -0
  108. package/src/utils/helpers.ts +12 -0
  109. package/src/utils/memoize.ts +68 -0
  110. package/src/version.ts +9 -0
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/types/index.ts
21
+ var types_exports = {};
22
+ __export(types_exports, {
23
+ AccountAuthenticatorVariant: () => AccountAuthenticatorVariant,
24
+ DeriveScheme: () => DeriveScheme,
25
+ MimeType: () => MimeType,
26
+ MoveAbility: () => MoveAbility,
27
+ MoveFunctionVisibility: () => MoveFunctionVisibility,
28
+ RoleType: () => RoleType,
29
+ ScriptTransactionArgumentVariants: () => ScriptTransactionArgumentVariants,
30
+ SigningScheme: () => SigningScheme,
31
+ TransactionAuthenticatorVariant: () => TransactionAuthenticatorVariant,
32
+ TransactionPayloadVariants: () => TransactionPayloadVariants,
33
+ TransactionResponseType: () => TransactionResponseType,
34
+ TransactionVariants: () => TransactionVariants,
35
+ TypeTagVariants: () => TypeTagVariants
36
+ });
37
+ module.exports = __toCommonJS(types_exports);
38
+ var MimeType = /* @__PURE__ */ ((MimeType2) => {
39
+ MimeType2["JSON"] = "application/json";
40
+ MimeType2["BCS"] = "application/x-bcs";
41
+ MimeType2["BCS_SIGNED_TRANSACTION"] = "application/x.aptos.signed_transaction+bcs";
42
+ return MimeType2;
43
+ })(MimeType || {});
44
+ var TypeTagVariants = /* @__PURE__ */ ((TypeTagVariants2) => {
45
+ TypeTagVariants2[TypeTagVariants2["Bool"] = 0] = "Bool";
46
+ TypeTagVariants2[TypeTagVariants2["U8"] = 1] = "U8";
47
+ TypeTagVariants2[TypeTagVariants2["U64"] = 2] = "U64";
48
+ TypeTagVariants2[TypeTagVariants2["U128"] = 3] = "U128";
49
+ TypeTagVariants2[TypeTagVariants2["Address"] = 4] = "Address";
50
+ TypeTagVariants2[TypeTagVariants2["Signer"] = 5] = "Signer";
51
+ TypeTagVariants2[TypeTagVariants2["Vector"] = 6] = "Vector";
52
+ TypeTagVariants2[TypeTagVariants2["Struct"] = 7] = "Struct";
53
+ TypeTagVariants2[TypeTagVariants2["U16"] = 8] = "U16";
54
+ TypeTagVariants2[TypeTagVariants2["U32"] = 9] = "U32";
55
+ TypeTagVariants2[TypeTagVariants2["U256"] = 10] = "U256";
56
+ return TypeTagVariants2;
57
+ })(TypeTagVariants || {});
58
+ var ScriptTransactionArgumentVariants = /* @__PURE__ */ ((ScriptTransactionArgumentVariants2) => {
59
+ ScriptTransactionArgumentVariants2[ScriptTransactionArgumentVariants2["U8"] = 0] = "U8";
60
+ ScriptTransactionArgumentVariants2[ScriptTransactionArgumentVariants2["U64"] = 1] = "U64";
61
+ ScriptTransactionArgumentVariants2[ScriptTransactionArgumentVariants2["U128"] = 2] = "U128";
62
+ ScriptTransactionArgumentVariants2[ScriptTransactionArgumentVariants2["Address"] = 3] = "Address";
63
+ ScriptTransactionArgumentVariants2[ScriptTransactionArgumentVariants2["U8Vector"] = 4] = "U8Vector";
64
+ ScriptTransactionArgumentVariants2[ScriptTransactionArgumentVariants2["Bool"] = 5] = "Bool";
65
+ ScriptTransactionArgumentVariants2[ScriptTransactionArgumentVariants2["U16"] = 6] = "U16";
66
+ ScriptTransactionArgumentVariants2[ScriptTransactionArgumentVariants2["U32"] = 7] = "U32";
67
+ ScriptTransactionArgumentVariants2[ScriptTransactionArgumentVariants2["U256"] = 8] = "U256";
68
+ return ScriptTransactionArgumentVariants2;
69
+ })(ScriptTransactionArgumentVariants || {});
70
+ var TransactionPayloadVariants = /* @__PURE__ */ ((TransactionPayloadVariants2) => {
71
+ TransactionPayloadVariants2[TransactionPayloadVariants2["Script"] = 0] = "Script";
72
+ TransactionPayloadVariants2[TransactionPayloadVariants2["EntryFunction"] = 2] = "EntryFunction";
73
+ TransactionPayloadVariants2[TransactionPayloadVariants2["Multisig"] = 3] = "Multisig";
74
+ return TransactionPayloadVariants2;
75
+ })(TransactionPayloadVariants || {});
76
+ var TransactionVariants = /* @__PURE__ */ ((TransactionVariants2) => {
77
+ TransactionVariants2[TransactionVariants2["MultiAgentTransaction"] = 0] = "MultiAgentTransaction";
78
+ TransactionVariants2[TransactionVariants2["FeePayerTransaction"] = 1] = "FeePayerTransaction";
79
+ return TransactionVariants2;
80
+ })(TransactionVariants || {});
81
+ var TransactionAuthenticatorVariant = /* @__PURE__ */ ((TransactionAuthenticatorVariant2) => {
82
+ TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["Ed25519"] = 0] = "Ed25519";
83
+ TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["MultiEd25519"] = 1] = "MultiEd25519";
84
+ TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["MultiAgent"] = 2] = "MultiAgent";
85
+ TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["FeePayer"] = 3] = "FeePayer";
86
+ TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["Secp256k1Ecdsa"] = 4] = "Secp256k1Ecdsa";
87
+ return TransactionAuthenticatorVariant2;
88
+ })(TransactionAuthenticatorVariant || {});
89
+ var AccountAuthenticatorVariant = /* @__PURE__ */ ((AccountAuthenticatorVariant2) => {
90
+ AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["Ed25519"] = 0] = "Ed25519";
91
+ AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["MultiEd25519"] = 1] = "MultiEd25519";
92
+ AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["Secp256k1"] = 2] = "Secp256k1";
93
+ return AccountAuthenticatorVariant2;
94
+ })(AccountAuthenticatorVariant || {});
95
+ var TransactionResponseType = /* @__PURE__ */ ((TransactionResponseType2) => {
96
+ TransactionResponseType2["Pending"] = "pending_transaction";
97
+ TransactionResponseType2["User"] = "user_transaction";
98
+ TransactionResponseType2["Genesis"] = "genesis_transaction";
99
+ TransactionResponseType2["BlockMetadata"] = "block_metadata_transaction";
100
+ TransactionResponseType2["StateCheckpoint"] = "state_checkpoint_transaction";
101
+ return TransactionResponseType2;
102
+ })(TransactionResponseType || {});
103
+ var MoveFunctionVisibility = /* @__PURE__ */ ((MoveFunctionVisibility2) => {
104
+ MoveFunctionVisibility2["PRIVATE"] = "private";
105
+ MoveFunctionVisibility2["PUBLIC"] = "public";
106
+ MoveFunctionVisibility2["FRIEND"] = "friend";
107
+ return MoveFunctionVisibility2;
108
+ })(MoveFunctionVisibility || {});
109
+ var MoveAbility = /* @__PURE__ */ ((MoveAbility2) => {
110
+ MoveAbility2["STORE"] = "store";
111
+ MoveAbility2["DROP"] = "drop";
112
+ MoveAbility2["KEY"] = "key";
113
+ MoveAbility2["COPY"] = "copy";
114
+ return MoveAbility2;
115
+ })(MoveAbility || {});
116
+ var RoleType = /* @__PURE__ */ ((RoleType2) => {
117
+ RoleType2["VALIDATOR"] = "validator";
118
+ RoleType2["FULL_NODE"] = "full_node";
119
+ return RoleType2;
120
+ })(RoleType || {});
121
+ var SigningScheme = /* @__PURE__ */ ((SigningScheme2) => {
122
+ SigningScheme2[SigningScheme2["Ed25519"] = 0] = "Ed25519";
123
+ SigningScheme2[SigningScheme2["MultiEd25519"] = 1] = "MultiEd25519";
124
+ SigningScheme2[SigningScheme2["Secp256k1Ecdsa"] = 2] = "Secp256k1Ecdsa";
125
+ return SigningScheme2;
126
+ })(SigningScheme || {});
127
+ var DeriveScheme = /* @__PURE__ */ ((DeriveScheme2) => {
128
+ DeriveScheme2[DeriveScheme2["DeriveAuid"] = 251] = "DeriveAuid";
129
+ DeriveScheme2[DeriveScheme2["DeriveObjectAddressFromObject"] = 252] = "DeriveObjectAddressFromObject";
130
+ DeriveScheme2[DeriveScheme2["DeriveObjectAddressFromGuid"] = 253] = "DeriveObjectAddressFromGuid";
131
+ DeriveScheme2[DeriveScheme2["DeriveObjectAddressFromSeed"] = 254] = "DeriveObjectAddressFromSeed";
132
+ DeriveScheme2[DeriveScheme2["DeriveResourceAccountAddress"] = 255] = "DeriveResourceAccountAddress";
133
+ return DeriveScheme2;
134
+ })(DeriveScheme || {});
135
+ // Annotate the CommonJS export names for ESM import in node:
136
+ 0 && (module.exports = {
137
+ AccountAuthenticatorVariant,
138
+ DeriveScheme,
139
+ MimeType,
140
+ MoveAbility,
141
+ MoveFunctionVisibility,
142
+ RoleType,
143
+ ScriptTransactionArgumentVariants,
144
+ SigningScheme,
145
+ TransactionAuthenticatorVariant,
146
+ TransactionPayloadVariants,
147
+ TransactionResponseType,
148
+ TransactionVariants,
149
+ TypeTagVariants
150
+ });
151
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Network } from \"../utils/apiEndpoints\";\n\nexport * from \"./indexer\";\n\nexport enum MimeType {\n /**\n * JSON representation, used for transaction submission and accept type JSON output\n */\n JSON = \"application/json\",\n /**\n * BCS representation, used for accept type BCS output\n */\n BCS = \"application/x-bcs\",\n /**\n * BCS representation, used for transaction submission in BCS input\n */\n BCS_SIGNED_TRANSACTION = \"application/x.aptos.signed_transaction+bcs\",\n}\n\n/**\n * Hex data as input to a function\n */\nexport type HexInput = string | Uint8Array;\n\n/**\n * Script transaction arguments enum as they are represented in Rust\n * {@link https://github.com/aptos-labs/aptos-core/blob/main/third_party/move/move-core/types/src/language_storage.rs#L27}\n */\nexport enum TypeTagVariants {\n Bool = 0,\n U8 = 1,\n U64 = 2,\n U128 = 3,\n Address = 4,\n Signer = 5,\n Vector = 6,\n Struct = 7,\n U16 = 8,\n U32 = 9,\n U256 = 10,\n}\n\n/**\n * Script transaction arguments enum as they are represented in Rust\n * {@link https://github.com/aptos-labs/aptos-core/blob/main/third_party/move/move-core/types/src/transaction_argument.rs#L11}\n */\nexport enum ScriptTransactionArgumentVariants {\n U8 = 0,\n U64 = 1,\n U128 = 2,\n Address = 3,\n U8Vector = 4,\n Bool = 5,\n U16 = 6,\n U32 = 7,\n U256 = 8,\n}\n\n/**\n * Transaction payload enum as they are represented in Rust\n * {@link https://github.com/aptos-labs/aptos-core/blob/main/types/src/transaction/mod.rs#L478}\n */\nexport enum TransactionPayloadVariants {\n Script = 0,\n EntryFunction = 2,\n Multisig = 3,\n}\n\n/**\n * Transaction variants enum as they are represented in Rust\n * {@link https://github.com/aptos-labs/aptos-core/blob/main/types/src/transaction/mod.rs#L440}\n */\nexport enum TransactionVariants {\n MultiAgentTransaction = 0,\n FeePayerTransaction = 1,\n}\n\n/**\n * Transaction Authenticator enum as they are represented in Rust\n * {@link https://github.com/aptos-labs/aptos-core/blob/main/types/src/transaction/authenticator.rs#L44}\n */\nexport enum TransactionAuthenticatorVariant {\n Ed25519 = 0,\n MultiEd25519 = 1,\n MultiAgent = 2,\n FeePayer = 3,\n Secp256k1Ecdsa = 4,\n}\n\n/**\n * Transaction Authenticator enum as they are represented in Rust\n * {@link https://github.com/aptos-labs/aptos-core/blob/main/types/src/transaction/authenticator.rs#L414}\n */\nexport enum AccountAuthenticatorVariant {\n Ed25519 = 0,\n MultiEd25519 = 1,\n Secp256k1 = 2,\n}\n\n/**\n * BCS types\n */\nexport type Uint8 = number;\nexport type Uint16 = number;\nexport type Uint32 = number;\nexport type Uint64 = bigint;\nexport type Uint128 = bigint;\nexport type Uint256 = bigint;\nexport type AnyNumber = number | bigint;\n\n/**\n * Set of configuration options that can be provided when initializing the SDK.\n * The purpose of these options is to configure various aspects of the SDK's\n * behavior and interaction with the Aptos network\n */\nexport type AptosSettings = {\n readonly network: Network;\n\n readonly fullnode?: string;\n\n readonly faucet?: string;\n\n readonly indexer?: string;\n\n readonly clientConfig?: ClientConfig;\n};\n\n/**\n *\n * Controls the number of results that are returned and the starting position of those results.\n * @param offset parameter specifies the starting position of the query result within the set of data. Default is 0.\n * @param limit specifies the maximum number of items or records to return in a query result. Default is 25.\n */\nexport interface PaginationArgs {\n offset?: AnyNumber;\n limit?: number;\n}\n\n/**\n * QUERY TYPES\n */\n\n/**\n * A configuration object we can pass with the request to the server.\n *\n * @param TOKEN - an auth token to send with the request\n * @param HEADERS - extra headers we want to send with the request\n * @param WITH_CREDENTIALS - whether to carry cookies. By default, it is set to true and cookies will be sent\n */\nexport type ClientConfig = {\n TOKEN?: string;\n HEADERS?: Record<string, string | number | boolean>;\n WITH_CREDENTIALS?: boolean;\n};\n\n/**\n * The API request type\n *\n * @param url - the url to make the request to, i.e https://fullnode.aptoslabs.devnet.com/v1\n * @param method - the request method \"GET\" | \"POST\"\n * @param endpoint (optional) - the endpoint to make the request to, i.e transactions\n * @param body (optional) - the body of the request\n * @param contentType (optional) - the content type to set the `content-type` header to,\n * by default is set to `application/json`\n * @param params (optional) - query params to add to the request\n * @param originMethod (optional) - the local method the request came from\n * @param overrides (optional) - a `ClientConfig` object type to override request data\n */\nexport type AptosRequest = {\n url: string;\n method: \"GET\" | \"POST\";\n path?: string;\n body?: any;\n contentType?: string;\n acceptType?: string;\n params?: Record<string, string | AnyNumber | boolean | undefined>;\n originMethod?: string;\n overrides?: ClientConfig;\n};\n\n/**\n * Specifies ledger version of transactions. By default latest version will be used\n */\nexport type LedgerVersion = {\n ledgerVersion?: AnyNumber;\n};\n\n/**\n * RESPONSE TYPES\n */\n\n/**\n * Type holding the outputs of the estimate gas API\n */\nexport type GasEstimation = {\n /**\n * The deprioritized estimate for the gas unit price\n */\n deprioritized_gas_estimate?: number;\n /**\n * The current estimate for the gas unit price\n */\n gas_estimate: number;\n /**\n * The prioritized estimate for the gas unit price\n */\n prioritized_gas_estimate?: number;\n};\n\nexport type MoveResource = {\n type: MoveResourceType;\n data: {};\n};\n\nexport type AccountData = {\n sequence_number: string;\n authentication_key: string;\n};\n\nexport type MoveModuleBytecode = {\n bytecode: string;\n abi?: MoveModule;\n};\n\n/**\n * TRANSACTION TYPES\n */\n\nexport enum TransactionResponseType {\n Pending = \"pending_transaction\",\n User = \"user_transaction\",\n Genesis = \"genesis_transaction\",\n BlockMetadata = \"block_metadata_transaction\",\n StateCheckpoint = \"state_checkpoint_transaction\",\n}\n\nexport type TransactionResponse =\n | PendingTransactionResponse\n | UserTransactionResponse\n | GenesisTransactionResponse\n | BlockMetadataTransactionResponse\n | StateCheckpointTransactionResponse;\n\nexport type PendingTransactionResponse = {\n type: TransactionResponseType.Pending;\n hash: string;\n sender: string;\n sequence_number: string;\n max_gas_amount: string;\n gas_unit_price: string;\n expiration_timestamp_secs: string;\n payload: TransactionPayloadResponse;\n signature?: TransactionSignature;\n};\n\nexport type UserTransactionResponse = {\n type: TransactionResponseType.User;\n version: string;\n hash: string;\n state_change_hash: string;\n event_root_hash: string;\n state_checkpoint_hash?: string;\n gas_used: string;\n /**\n * Whether the transaction was successful\n */\n success: boolean;\n /**\n * The VM status of the transaction, can tell useful information in a failure\n */\n vm_status: string;\n accumulator_root_hash: string;\n /**\n * Final state of resources changed by the transaction\n */\n changes: Array<WriteSetChange>;\n sender: string;\n sequence_number: string;\n max_gas_amount: string;\n gas_unit_price: string;\n expiration_timestamp_secs: string;\n payload: TransactionPayloadResponse;\n signature?: TransactionSignature;\n /**\n * Events generated by the transaction\n */\n events: Array<Event>;\n timestamp: string;\n};\n\nexport type GenesisTransactionResponse = {\n type: TransactionResponseType.Genesis;\n version: string;\n hash: string;\n state_change_hash: string;\n event_root_hash: string;\n state_checkpoint_hash?: string;\n gas_used: string;\n /**\n * Whether the transaction was successful\n */\n success: boolean;\n /**\n * The VM status of the transaction, can tell useful information in a failure\n */\n vm_status: string;\n accumulator_root_hash: string;\n /**\n * Final state of resources changed by the transaction\n */\n changes: Array<WriteSetChange>;\n payload: GenesisPayload;\n /**\n * Events emitted during genesis\n */\n events: Array<Event>;\n};\n\nexport type BlockMetadataTransactionResponse = {\n type: TransactionResponseType.BlockMetadata;\n version: string;\n hash: string;\n state_change_hash: string;\n event_root_hash: string;\n state_checkpoint_hash?: string;\n gas_used: string;\n /**\n * Whether the transaction was successful\n */\n success: boolean;\n /**\n * The VM status of the transaction, can tell useful information in a failure\n */\n vm_status: string;\n accumulator_root_hash: string;\n /**\n * Final state of resources changed by the transaction\n */\n changes: Array<WriteSetChange>;\n id: string;\n epoch: string;\n round: string;\n /**\n * The events emitted at the block creation\n */\n events: Array<Event>;\n /**\n * Previous block votes\n */\n previous_block_votes_bitvec: Array<number>;\n proposer: string;\n /**\n * The indices of the proposers who failed to propose\n */\n failed_proposer_indices: Array<number>;\n timestamp: string;\n};\n\nexport type StateCheckpointTransactionResponse = {\n type: TransactionResponseType.StateCheckpoint;\n version: string;\n hash: string;\n state_change_hash: string;\n event_root_hash: string;\n state_checkpoint_hash?: string;\n gas_used: string;\n /**\n * Whether the transaction was successful\n */\n success: boolean;\n /**\n * The VM status of the transaction, can tell useful information in a failure\n */\n vm_status: string;\n accumulator_root_hash: string;\n /**\n * Final state of resources changed by the transaction\n */\n changes: Array<WriteSetChange>;\n timestamp: string;\n};\n\n/**\n * WRITESET CHANGE TYPES\n */\n\nexport type WriteSetChange =\n | WriteSetChangeDeleteModule\n | WriteSetChangeDeleteResource\n | WriteSetChangeDeleteTableItem\n | WriteSetChangeWriteModule\n | WriteSetChangeWriteResource\n | WriteSetChangeWriteTableItem;\n\nexport type WriteSetChangeDeleteModule = {\n type: string;\n address: string;\n /**\n * State key hash\n */\n state_key_hash: string;\n module: MoveModuleId;\n};\n\nexport type WriteSetChangeDeleteResource = {\n type: string;\n address: string;\n state_key_hash: string;\n resource: string;\n};\n\nexport type WriteSetChangeDeleteTableItem = {\n type: string;\n state_key_hash: string;\n handle: string;\n key: string;\n data?: DeletedTableData;\n};\n\nexport type WriteSetChangeWriteModule = {\n type: string;\n address: string;\n state_key_hash: string;\n data: MoveModuleBytecode;\n};\n\nexport type WriteSetChangeWriteResource = {\n type: string;\n address: string;\n state_key_hash: string;\n data: MoveResource;\n};\n\nexport type WriteSetChangeWriteTableItem = {\n type: string;\n state_key_hash: string;\n handle: string;\n key: string;\n value: string;\n data?: DecodedTableData;\n};\n\nexport type DecodedTableData = {\n /**\n * Key of table in JSON\n */\n key: any;\n /**\n * Type of key\n */\n key_type: string;\n /**\n * Value of table in JSON\n */\n value: any;\n /**\n * Type of value\n */\n value_type: string;\n};\n\n/**\n * Deleted table data\n */\nexport type DeletedTableData = {\n /**\n * Deleted key\n */\n key: any;\n /**\n * Deleted key type\n */\n key_type: string;\n};\n\nexport type TransactionPayloadResponse = EntryFunctionPayloadResponse | ScriptPayloadResponse | MultisigPayloadResponse;\n\nexport type EntryFunctionPayloadResponse = {\n type: string;\n function: MoveResourceType;\n /**\n * Type arguments of the function\n */\n type_arguments: Array<string>;\n /**\n * Arguments of the function\n */\n arguments: Array<any>;\n};\n\nexport type ScriptPayloadResponse = {\n type: string;\n code: MoveScriptBytecode;\n /**\n * Type arguments of the function\n */\n type_arguments: Array<string>;\n /**\n * Arguments of the function\n */\n arguments: Array<any>;\n};\n\nexport type MultisigPayloadResponse = {\n type: string;\n multisig_address: string;\n transaction_payload?: EntryFunctionPayloadResponse;\n};\n\nexport type GenesisPayload = {\n type: string;\n write_set: WriteSet;\n};\n\n/**\n * Move script bytecode\n */\nexport type MoveScriptBytecode = {\n bytecode: string;\n abi?: MoveFunction;\n};\n\n/**\n * These are the JSON representations of transaction signatures returned from the node API.\n */\nexport type TransactionSignature =\n | TransactionEd25519Signature\n | TransactionSecp256k1Signature\n | TransactionMultiEd25519Signature\n | TransactionMultiAgentSignature\n | TransactionFeePayerSignature;\n\nexport type TransactionEd25519Signature = {\n type: string;\n public_key: string;\n signature: \"ed25519_signature\";\n};\n\nexport type TransactionSecp256k1Signature = {\n type: string;\n public_key: string;\n signature: \"secp256k1_ecdsa_signature\";\n};\n\nexport type TransactionMultiEd25519Signature = {\n type: \"multi_ed25519_signature\";\n /**\n * The public keys for the Ed25519 signature\n */\n public_keys: Array<string>;\n /**\n * Signature associated with the public keys in the same order\n */\n signatures: Array<string>;\n /**\n * The number of signatures required for a successful transaction\n */\n threshold: number;\n bitmap: string;\n};\n\nexport type TransactionMultiAgentSignature = {\n type: \"multi_agent_signature\";\n sender: AccountSignature;\n /**\n * The other involved parties' addresses\n */\n secondary_signer_addresses: Array<string>;\n /**\n * The associated signatures, in the same order as the secondary addresses\n */\n secondary_signers: Array<AccountSignature>;\n};\n\nexport type TransactionFeePayerSignature = {\n type: \"fee_payer_signature\";\n sender: AccountSignature;\n /**\n * The other involved parties' addresses\n */\n secondary_signer_addresses: Array<string>;\n /**\n * The associated signatures, in the same order as the secondary addresses\n */\n secondary_signers: Array<AccountSignature>;\n fee_payer_address: string;\n fee_payer_signer: AccountSignature;\n};\n\n/**\n * The union of all single account signatures.\n */\nexport type AccountSignature = AccountEd25519Signature | AccountSecp256k1Signature | AccountMultiEd25519Signature;\n\nexport type AccountEd25519Signature = TransactionEd25519Signature;\n\nexport type AccountSecp256k1Signature = TransactionSecp256k1Signature;\n\nexport type AccountMultiEd25519Signature = TransactionMultiEd25519Signature;\n\nexport type WriteSet = ScriptWriteSet | DirectWriteSet;\n\nexport type ScriptWriteSet = {\n type: string;\n execute_as: string;\n script: ScriptPayloadResponse;\n};\n\nexport type DirectWriteSet = {\n type: string;\n changes: Array<WriteSetChange>;\n events: Array<Event>;\n};\n\nexport type EventGuid = {\n creation_number: string;\n account_address: string;\n};\n\nexport type Event = {\n guid: EventGuid;\n sequence_number: string;\n type: string;\n /**\n * The JSON representation of the event\n */\n data: any;\n};\n\n/**\n * Map of Move types to local TypeScript types\n */\nexport type MoveUint8Type = number;\nexport type MoveUint16Type = number;\nexport type MoveUint32Type = number;\nexport type MoveUint64Type = string;\nexport type MoveUint128Type = string;\nexport type MoveUint256Type = string;\nexport type MoveAddressType = `0x${string}`;\nexport type MoveObjectType = `0x${string}`;\nexport type MoveStructType = `0x${string}::${string}::${string}`;\nexport type MoveOptionType = MoveType | null | undefined;\n/**\n * String representation of a on-chain Move struct type.\n */\nexport type MoveResourceType = `${string}::${string}::${string}`;\n\nexport type MoveType =\n | boolean\n | string\n | MoveUint8Type\n | MoveUint16Type\n | MoveUint32Type\n | MoveUint64Type\n | MoveUint128Type\n | MoveUint256Type\n | MoveAddressType\n | MoveObjectType\n | MoveStructType\n | Array<MoveType>;\n\n/**\n * Possible Move values acceptable by move functions (entry, view)\n *\n * Map of a Move value to the corresponding TypeScript value\n *\n * `Bool -> boolean`\n *\n * `u8, u16, u32 -> number`\n *\n * `u64, u128, u256 -> string`\n *\n * `String -> string`\n *\n * `Address -> 0x${string}`\n *\n * `Struct - 0x${string}::${string}::${string}`\n *\n * `Object -> 0x${string}`\n *\n * `Vector -> Array<MoveValue>`\n *\n * `Option -> MoveValue | null | undefined`\n */\nexport type MoveValue =\n | boolean\n | string\n | MoveUint8Type\n | MoveUint16Type\n | MoveUint32Type\n | MoveUint64Type\n | MoveUint128Type\n | MoveUint256Type\n | MoveAddressType\n | MoveObjectType\n | MoveStructType\n | MoveOptionType\n | Array<MoveValue>;\n\n/**\n * Move module id is a string representation of Move module.\n * Module name is case-sensitive.\n */\nexport type MoveModuleId = `${string}::${string}`;\n\n/**\n * Move function visibility\n */\nexport enum MoveFunctionVisibility {\n PRIVATE = \"private\",\n PUBLIC = \"public\",\n FRIEND = \"friend\",\n}\n\n/**\n * Move function ability\n */\nexport enum MoveAbility {\n STORE = \"store\",\n DROP = \"drop\",\n KEY = \"key\",\n COPY = \"copy\",\n}\n\n/**\n * Move abilities tied to the generic type param and associated with the function that uses it\n */\nexport type MoveFunctionGenericTypeParam = {\n constraints: Array<MoveAbility>;\n};\n\n/**\n * Move struct field\n */\nexport type MoveStructField = {\n name: string;\n type: string;\n};\n\n/**\n * A Move module\n */\nexport type MoveModule = {\n address: string;\n name: string;\n /**\n * Friends of the module\n */\n friends: Array<MoveModuleId>;\n /**\n * Public functions of the module\n */\n exposed_functions: Array<MoveFunction>;\n /**\n * Structs of the module\n */\n structs: Array<MoveStruct>;\n};\n\n/**\n * A move struct\n */\nexport type MoveStruct = {\n name: string;\n /**\n * Whether the struct is a native struct of Move\n */\n is_native: boolean;\n /**\n * Abilities associated with the struct\n */\n abilities: Array<MoveAbility>;\n /**\n * Generic types associated with the struct\n */\n generic_type_params: Array<MoveFunctionGenericTypeParam>;\n /**\n * Fields associated with the struct\n */\n fields: Array<MoveStructField>;\n};\n\n/**\n * Move function\n */\nexport type MoveFunction = {\n name: string;\n visibility: MoveFunctionVisibility;\n /**\n * Whether the function can be called as an entry function directly in a transaction\n */\n is_entry: boolean;\n /**\n * Whether the function is a view function or not\n */\n is_view: boolean;\n /**\n * Generic type params associated with the Move function\n */\n generic_type_params: Array<MoveFunctionGenericTypeParam>;\n /**\n * Parameters associated with the move function\n */\n params: Array<string>;\n /**\n * Return type of the function\n */\n return: Array<string>;\n};\n\nexport enum RoleType {\n VALIDATOR = \"validator\",\n FULL_NODE = \"full_node\",\n}\n\nexport type LedgerInfo = {\n /**\n * Chain ID of the current chain\n */\n chain_id: number;\n epoch: string;\n ledger_version: string;\n oldest_ledger_version: string;\n ledger_timestamp: string;\n node_role: RoleType;\n oldest_block_height: string;\n block_height: string;\n /**\n * Git hash of the build of the API endpoint. Can be used to determine the exact\n * software version used by the API endpoint.\n */\n git_hash?: string;\n};\n\n/**\n * A Block type\n */\nexport type Block = {\n block_height: string;\n block_hash: `0x${string}`;\n block_timestamp: string;\n first_version: string;\n last_version: string;\n /**\n * The transactions in the block in sequential order\n */\n transactions?: Array<TransactionResponse>;\n};\n\n/**\n * The data needed to generate a View Request payload\n */\nexport type ViewRequestData = {\n function: MoveStructType;\n typeArguments?: Array<MoveResourceType>;\n arguments?: Array<MoveValue>;\n};\n\n// REQUEST TYPES\n\n/**\n * View request for the Move view function API\n *\n * `type MoveResourceType = ${string}::${string}::${string}`;\n */\nexport type ViewRequest = {\n function: MoveResourceType;\n /**\n * Type arguments of the function\n */\n type_arguments: Array<MoveResourceType>;\n /**\n * Arguments of the function\n */\n arguments: Array<MoveValue>;\n};\n\n/**\n * Table Item request for the GetTableItem API\n */\nexport type TableItemRequest = {\n key_type: MoveValue;\n value_type: MoveValue;\n /**\n * The value of the table item's key\n */\n key: any;\n};\n\n/**\n * A list of Authentication Key schemes that are supported by Aptos.\n *\n * They are combinations of signing schemes and derive schemes.\n */\nexport type AuthenticationKeyScheme = SigningScheme | DeriveScheme;\n\n/**\n * A list of signing schemes that are supported by Aptos.\n *\n * https://github.com/aptos-labs/aptos-core/blob/main/types/src/transaction/authenticator.rs#L375-L378\n */\nexport enum SigningScheme {\n /**\n * For Ed25519PublicKey\n */\n Ed25519 = 0,\n /**\n * For MultiEd25519PublicKey\n */\n MultiEd25519 = 1,\n /**\n * For Secp256k1 ecdsa\n */\n Secp256k1Ecdsa = 2,\n}\n\n/**\n * Scheme used for deriving account addresses from other data\n */\nexport enum DeriveScheme {\n /**\n * Derives an address using an AUID, used for objects\n */\n DeriveAuid = 251,\n /**\n * Derives an address from another object address\n */\n DeriveObjectAddressFromObject = 252,\n /**\n * Derives an address from a GUID, used for objects\n */\n DeriveObjectAddressFromGuid = 253,\n /**\n * Derives an address from seed bytes, used for named objects\n */\n DeriveObjectAddressFromSeed = 254,\n /**\n * Derives an address from seed bytes, used for resource accounts\n */\n DeriveResourceAccountAddress = 255,\n}\n"],"mappings":"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","names":["MimeType","TypeTagVariants","ScriptTransactionArgumentVariants","TransactionPayloadVariants","TransactionVariants","TransactionAuthenticatorVariant","AccountAuthenticatorVariant","TransactionResponseType","MoveFunctionVisibility","MoveAbility","RoleType","SigningScheme","DeriveScheme"]}
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@aptos-labs/ts-sdk",
3
+ "description": "Aptos TypeScript SDK",
4
+ "packageManager": "pnpm@8.9.0",
5
+ "license": "Apache-2.0",
6
+ "engines": {
7
+ "node": ">=11.0.0"
8
+ },
9
+ "bugs": {
10
+ "url": "https://github.com/aptos-labs/aptos-ts-sdk/issues/new/choose"
11
+ },
12
+ "homepage": "https://aptos-labs.github.io/aptos-ts-sdk/",
13
+ "main": "dist/cjs/index.js",
14
+ "module": "dist/esm/index.mjs",
15
+ "exports": {
16
+ ".": {
17
+ "import": "./dist/esm/index.mjs",
18
+ "require": "./dist/cjs/index.js",
19
+ "types": "./dist/types/index.d.ts"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "src"
25
+ ],
26
+ "scripts": {
27
+ "build:clean": "rm -rf dist",
28
+ "build": "pnpm build:clean && pnpm run _build:types && pnpm _build:esm && pnpm _build:cjs && pnpm _build:browser",
29
+ "_build:browser": "tsup src/index.ts --platform browser --format iife --global-name aptosSDK --minify --out-dir dist/browser",
30
+ "_build:esm": "tsup src/index.ts --platform node --format esm --dts --out-dir dist/esm",
31
+ "_build:cjs": "tsup src/index.ts --platform node --format cjs --dts --out-dir dist/cjs",
32
+ "_build:types": "tsup src/types/index.ts --dts --out-dir dist/types",
33
+ "_fmt": "prettier 'src/**/*.ts' 'tests/**/*.ts' 'examples/**/*.js' 'examples/**/*.ts' '.eslintrc.js'",
34
+ "fmt": "pnpm _fmt --write",
35
+ "lint": "eslint 'src/**/*.ts' 'tests/**/*.ts'",
36
+ "test": "pnpm jest",
37
+ "unit-test": "pnpm jest tests/unit",
38
+ "e2e-test": "pnpm jest tests/e2e",
39
+ "indexer-codegen": "graphql-codegen --config ./src/types/codegen.yaml && pnpm fmt",
40
+ "doc": "scripts/generateDocs.sh"
41
+ },
42
+ "dependencies": {
43
+ "@aptos-labs/aptos-client": "^0.0.2",
44
+ "@noble/curves": "^1.2.0",
45
+ "@noble/hashes": "1.1.3",
46
+ "@scure/bip39": "1.1.0",
47
+ "form-data": "4.0.0",
48
+ "tweetnacl": "1.0.3"
49
+ },
50
+ "devDependencies": {
51
+ "@graphql-codegen/cli": "^2.13.5",
52
+ "@graphql-codegen/import-types-preset": "^2.2.3",
53
+ "@graphql-codegen/typescript": "^2.7.3",
54
+ "@graphql-codegen/typescript-graphql-request": "^4.5.8",
55
+ "@graphql-codegen/typescript-operations": "^2.5.3",
56
+ "@types/jest": "28.1.8",
57
+ "@types/node": "18.6.2",
58
+ "@typescript-eslint/eslint-plugin": "5.36.2",
59
+ "@typescript-eslint/parser": "5.36.2",
60
+ "cross-var": "^1.1.0",
61
+ "dotenv": "16.0.2",
62
+ "eslint": "8.23.0",
63
+ "eslint-config-airbnb-base": "15.0.0",
64
+ "eslint-config-airbnb-typescript": "17.0.0",
65
+ "eslint-config-prettier": "8.5.0",
66
+ "eslint-plugin-import": "2.26.0",
67
+ "graphql": "^16.5.0",
68
+ "graphql-request": "5.1.0",
69
+ "jest": "28.1.3",
70
+ "prettier": "2.6.2",
71
+ "ts-jest": "28.0.8",
72
+ "ts-loader": "9.3.1",
73
+ "ts-node": "10.9.1",
74
+ "tsup": "6.2.3",
75
+ "typedoc": "^0.23.20",
76
+ "typescript": "4.8.2"
77
+ },
78
+ "version": "0.0.0"
79
+ }
@@ -0,0 +1,360 @@
1
+ // Copyright © Aptos Foundation
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { AptosConfig } from "./aptosConfig";
5
+ import { AccountAddress } from "../core";
6
+ import {
7
+ AccountData,
8
+ GetAccountCoinsDataResponse,
9
+ GetAccountCollectionsWithOwnedTokenResponse,
10
+ GetAccountOwnedObjectsResponse,
11
+ GetAccountOwnedTokensFromCollectionResponse,
12
+ GetAccountOwnedTokensQueryResponse,
13
+ HexInput,
14
+ LedgerVersion,
15
+ MoveModuleBytecode,
16
+ MoveResource,
17
+ MoveResourceType,
18
+ OrderBy,
19
+ PaginationArgs,
20
+ TokenStandard,
21
+ TransactionResponse,
22
+ } from "../types";
23
+ import {
24
+ getAccountCoinsCount,
25
+ getAccountCoinsData,
26
+ getAccountCollectionsWithOwnedTokens,
27
+ getAccountOwnedObjects,
28
+ getAccountOwnedTokens,
29
+ getAccountOwnedTokensFromCollectionAddress,
30
+ getAccountTokensCount,
31
+ getAccountTransactionsCount,
32
+ getInfo,
33
+ getModule,
34
+ getModules,
35
+ getResource,
36
+ getResources,
37
+ getTransactions,
38
+ lookupOriginalAccountAddress,
39
+ } from "../internal/account";
40
+
41
+ /**
42
+ * A class to query all `Account` related queries on Aptos.
43
+ */
44
+ export class Account {
45
+ readonly config: AptosConfig;
46
+
47
+ constructor(config: AptosConfig) {
48
+ this.config = config;
49
+ }
50
+
51
+ /**
52
+ * Queries the current state for an Aptos account given its account address
53
+ *
54
+ * @param args.accountAddress Aptos account address
55
+ *
56
+ * @returns The account data
57
+ *
58
+ * @example An example of the returned account
59
+ * ```
60
+ * {
61
+ * sequence_number: "1",
62
+ * authentication_key: "0x5307b5f4bc67829097a8ba9b43dba3b88261eeccd1f709d9bde240fc100fbb69"
63
+ * }
64
+ * ```
65
+ */
66
+ async getAccountInfo(args: { accountAddress: HexInput }): Promise<AccountData> {
67
+ return getInfo({ aptosConfig: this.config, ...args });
68
+ }
69
+
70
+ /**
71
+ * Queries for all modules in an account given an account address
72
+ *
73
+ * Note: In order to get all account modules, this function may call the API
74
+ * multiple times as it auto paginates.
75
+ *
76
+ * @param args.accountAddress Aptos account address
77
+ * @param args.options.offset The number module to start returning results from
78
+ * @param args.options.limit The number of results to return
79
+ * @param args.options.ledgerVersion The ledger version to query, if not provided it will get the latest version
80
+ *
81
+ * @returns Account modules
82
+ */
83
+
84
+ async getAccountModules(args: {
85
+ accountAddress: HexInput;
86
+ options?: PaginationArgs & LedgerVersion;
87
+ }): Promise<MoveModuleBytecode[]> {
88
+ return getModules({ aptosConfig: this.config, ...args });
89
+ }
90
+
91
+ /**
92
+ * Queries for a specific account module given account address and module name
93
+ *
94
+ * @param args.accountAddress Aptos account address
95
+ * @param args.moduleName The name of the module
96
+ * @param args.options.ledgerVersion The ledger version to query, if not provided it will get the latest version
97
+ *
98
+ * @returns Account module
99
+ *
100
+ * @example An example of an account module
101
+ * ```
102
+ * {
103
+ * bytecode: "0xa11ceb0b0600000006010002030206050807070f0d081c200",
104
+ * abi: { address: "0x1" }
105
+ * }
106
+ * ```
107
+ */
108
+ async getAccountModule(args: {
109
+ accountAddress: HexInput;
110
+ moduleName: string;
111
+ options?: LedgerVersion;
112
+ }): Promise<MoveModuleBytecode> {
113
+ return getModule({ aptosConfig: this.config, ...args });
114
+ }
115
+
116
+ /**
117
+ * Queries account transactions given an account address
118
+ *
119
+ * Note: In order to get all account transactions, this function may call the API
120
+ * multiple times as it auto paginates.
121
+ *
122
+ * @param args.accountAddress Aptos account address
123
+ * @param args.options.offset The number transaction to start returning results from
124
+ * @param args.options.limit The number of results to return
125
+ *
126
+ * @returns The account transactions
127
+ */
128
+ async getAccountTransactions(args: {
129
+ accountAddress: HexInput;
130
+ options?: PaginationArgs;
131
+ }): Promise<TransactionResponse[]> {
132
+ return getTransactions({
133
+ aptosConfig: this.config,
134
+ ...args,
135
+ });
136
+ }
137
+
138
+ /**
139
+ * Queries all account resources given an account address
140
+ *
141
+ * Note: In order to get all account resources, this function may call the API
142
+ * multiple times as it auto paginates.
143
+ *
144
+ * @param args.accountAddress Aptos account address
145
+ * @param args.options.offset The number resource to start returning results from
146
+ * @param args.options.limit The number of results to return
147
+ * @param args.options.ledgerVersion The ledger version to query, if not provided it will get the latest version
148
+ * @returns Account resources
149
+ */
150
+ async getAccountResources(args: {
151
+ accountAddress: HexInput;
152
+ options?: PaginationArgs & LedgerVersion;
153
+ }): Promise<MoveResource[]> {
154
+ return getResources({ aptosConfig: this.config, ...args });
155
+ }
156
+
157
+ /**
158
+ * Queries a specific account resource given account address and resource type
159
+ *
160
+ * @param args.accountAddress Aptos account address
161
+ * @param args.resourceType String representation of an on-chain Move struct type, i.e "0x1::aptos_coin::AptosCoin"
162
+ * @param args.options.ledgerVersion The ledger version to query, if not provided it will get the latest version
163
+ *
164
+ * @returns Account resource
165
+ *
166
+ * @example An example of an account resource
167
+ * ```
168
+ * {
169
+ * type: "0x1::aptos_coin::AptosCoin",
170
+ * data: { value: 6 }
171
+ * }
172
+ * ```
173
+ */
174
+ async getAccountResource(args: {
175
+ accountAddress: HexInput;
176
+ resourceType: MoveResourceType;
177
+ options?: LedgerVersion;
178
+ }): Promise<MoveResource> {
179
+ return getResource({ aptosConfig: this.config, ...args });
180
+ }
181
+
182
+ /**
183
+ * Looks up the account address for a given authentication key
184
+ *
185
+ * This handles both if the account's authentication key has been rotated or not.
186
+ *
187
+ * @param args.authenticationKey The authentication key
188
+ * @param args.options.ledgerVersion The ledger version to query, if not provided it will get the latest version
189
+ * @returns Promise<AccountAddress> The accountAddress associated with the authentication key
190
+ */
191
+ async lookupOriginalAccountAddress(args: {
192
+ authenticationKey: HexInput;
193
+ options?: LedgerVersion;
194
+ }): Promise<AccountAddress> {
195
+ return lookupOriginalAccountAddress({ aptosConfig: this.config, ...args });
196
+ }
197
+
198
+ /**
199
+ * Queries the current count of tokens owned by an account
200
+ *
201
+ * @param args.accountAddress The account address
202
+ * @returns Current count of tokens owned by the account
203
+ */
204
+ async getAccountTokensCount(args: { accountAddress: HexInput }): Promise<number> {
205
+ return getAccountTokensCount({
206
+ aptosConfig: this.config,
207
+ ...args,
208
+ });
209
+ }
210
+
211
+ /**
212
+ * Queries the account's current owned tokens.
213
+ *
214
+ * This query returns all tokens (v1 and v2 standards) an account owns, including NFTs, fungible, soulbound, etc.
215
+ * If you want to get only the token from a specific standard, you can pass an optional tokenStandard param
216
+ *
217
+ * @param args.accountAddress The account address we want to get the tokens for
218
+ * @param args.options.tokenStandard The NFT standard to query for
219
+ * @param args.options.pagination.offset The number token to start returning results from
220
+ * @param args.options.pagination.limit The number of results to return
221
+ * @param args.options.orderBy The order to sort the tokens by
222
+ * @returns Tokens array with the token data
223
+ */
224
+ async getAccountOwnedTokens(args: {
225
+ accountAddress: HexInput;
226
+ options?: {
227
+ tokenStandard?: TokenStandard;
228
+ pagination?: PaginationArgs;
229
+ orderBy?: OrderBy<GetAccountOwnedTokensQueryResponse[0]>;
230
+ };
231
+ }): Promise<GetAccountOwnedTokensQueryResponse> {
232
+ return getAccountOwnedTokens({
233
+ aptosConfig: this.config,
234
+ ...args,
235
+ });
236
+ }
237
+
238
+ /**
239
+ * Queries all current tokens of a specific collection that an account owns by the collection address
240
+ *
241
+ * This query returns all tokens (v1 and v2 standards) an account owns, including NFTs, fungible, soulbound, etc.
242
+ * If you want to get only the token from a specific standard, you can pass an optional tokenStandard param
243
+ *
244
+ * @param args.accountAddress The account address we want to get the tokens for
245
+ * @param args.collectionAddress The address of the collection being queried
246
+ * @param args.options.tokenStandard The NFT standard to query for
247
+ * @param args.options.pagination.offset The number token to start returning results from
248
+ * @param args.options.pagination.limit The number of results to return
249
+ * @param args.options.orderBy The order to sort the tokens by
250
+ * @returns Tokens array with the token data
251
+ */
252
+ async getAccountOwnedTokensFromCollectionAddress(args: {
253
+ accountAddress: HexInput;
254
+ collectionAddress: HexInput;
255
+ options?: {
256
+ tokenStandard?: TokenStandard;
257
+ pagination?: PaginationArgs;
258
+ orderBy?: OrderBy<GetAccountOwnedTokensFromCollectionResponse[0]>;
259
+ };
260
+ }): Promise<GetAccountOwnedTokensFromCollectionResponse> {
261
+ return getAccountOwnedTokensFromCollectionAddress({
262
+ aptosConfig: this.config,
263
+ ...args,
264
+ });
265
+ }
266
+
267
+ /**
268
+ * Queries for all collections that an account currently has tokens for.
269
+ *
270
+ * This query returns all tokens (v1 and v2 standards) an account owns, including NFTs, fungible, soulbound, etc.
271
+ * If you want to get only the token from a specific standard, you can pass an optional tokenStandard param
272
+ *
273
+ * @param args.accountAddress The account address we want to get the collections for
274
+ * @param args.options.tokenStandard The NFT standard to query for
275
+ * @param args.options.pagination.offset The number collection to start returning results from
276
+ * @param args.options.pagination.limit The number of results to return
277
+ * @param args.options.orderBy The order to sort the tokens by
278
+ * @returns Collections array with the collections data
279
+ */
280
+ async getAccountCollectionsWithOwnedTokens(args: {
281
+ accountAddress: HexInput;
282
+ options?: {
283
+ tokenStandard?: TokenStandard;
284
+ pagination?: PaginationArgs;
285
+ orderBy?: OrderBy<GetAccountCollectionsWithOwnedTokenResponse[0]>;
286
+ };
287
+ }): Promise<GetAccountCollectionsWithOwnedTokenResponse> {
288
+ return getAccountCollectionsWithOwnedTokens({
289
+ aptosConfig: this.config,
290
+ ...args,
291
+ });
292
+ }
293
+
294
+ /**
295
+ * Queries the current count of transactions submitted by an account
296
+ *
297
+ * @param args.accountAddress The account address we want to get the total count for
298
+ * @returns Current count of transactions made by an account
299
+ */
300
+ async getAccountTransactionsCount(args: { accountAddress: HexInput }): Promise<number> {
301
+ return getAccountTransactionsCount({
302
+ aptosConfig: this.config,
303
+ ...args,
304
+ });
305
+ }
306
+
307
+ /**
308
+ * Queries an account's coins data
309
+ *
310
+ * @param args.accountAddress The account address we want to get the coins data for
311
+ * @param args.options.pagination.offset The number coin to start returning results from
312
+ * @param args.options.pagination.limit The number of results to return
313
+ * @param args.options.orderBy The order to sort the coins by
314
+ * @returns Array with the coins data
315
+ */
316
+ async getAccountCoinsData(args: {
317
+ accountAddress: HexInput;
318
+ options?: {
319
+ pagination?: PaginationArgs;
320
+ orderBy?: OrderBy<GetAccountCoinsDataResponse[0]>;
321
+ };
322
+ }): Promise<GetAccountCoinsDataResponse> {
323
+ return getAccountCoinsData({
324
+ aptosConfig: this.config,
325
+ ...args,
326
+ });
327
+ }
328
+
329
+ /**
330
+ * Queries the current count of an account's coins aggregated
331
+ *
332
+ * @param args.accountAddress The account address we want to get the total count for
333
+ * @returns Current count of the aggregated count of all account's coins
334
+ */
335
+ async getAccountCoinsCount(args: { accountAddress: HexInput }): Promise<number> {
336
+ return getAccountCoinsCount({ aptosConfig: this.config, ...args });
337
+ }
338
+
339
+ /**
340
+ * Queries an account's owned objects
341
+ *
342
+ * @param args.accountAddress The account address we want to get the objects for
343
+ * @param args.options.pagination.offset The number coin to start returning results from
344
+ * @param args.options.pagination.limit The number of results to return
345
+ * @param args.options.orderBy The order to sort the coins by
346
+ * @returns Objects array with the object data
347
+ */
348
+ async getAccountOwnedObjects(args: {
349
+ accountAddress: HexInput;
350
+ options?: {
351
+ pagination?: PaginationArgs;
352
+ orderBy?: OrderBy<GetAccountOwnedObjectsResponse[0]>;
353
+ };
354
+ }): Promise<GetAccountOwnedObjectsResponse> {
355
+ return getAccountOwnedObjects({
356
+ aptosConfig: this.config,
357
+ ...args,
358
+ });
359
+ }
360
+ }