@aptos-labs/ts-sdk 7.2.0-beta.0 → 7.3.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 (148) hide show
  1. package/README.md +17 -0
  2. package/dist/account/AbstractKeylessAccount.d.ts.map +1 -1
  3. package/dist/account/AbstractKeylessAccount.js.map +1 -1
  4. package/dist/account/AbstractedAccount.d.ts.map +1 -1
  5. package/dist/account/Account.d.ts.map +1 -1
  6. package/dist/account/Account.js.map +1 -1
  7. package/dist/account/AccountUtils.js.map +1 -1
  8. package/dist/account/DerivableAbstractedAccount.d.ts.map +1 -1
  9. package/dist/account/DerivableAbstractedAccount.js.map +1 -1
  10. package/dist/account/Ed25519Account.d.ts.map +1 -1
  11. package/dist/account/EphemeralKeyPair.d.ts.map +1 -1
  12. package/dist/account/EphemeralKeyPair.js.map +1 -1
  13. package/dist/account/FederatedKeylessAccount.d.ts.map +1 -1
  14. package/dist/account/KeylessAccount.d.ts.map +1 -1
  15. package/dist/account/MultiEd25519Account.d.ts.map +1 -1
  16. package/dist/account/MultiKeyAccount.d.ts.map +1 -1
  17. package/dist/account/SingleKeyAccount.d.ts.map +1 -1
  18. package/dist/account/SingleKeyAccount.js.map +1 -1
  19. package/dist/api/account/abstraction.d.ts.map +1 -1
  20. package/dist/api/account/abstraction.js.map +1 -1
  21. package/dist/api/account.d.ts.map +1 -1
  22. package/dist/api/account.js.map +1 -1
  23. package/dist/api/ans.d.ts.map +1 -1
  24. package/dist/api/ans.js.map +1 -1
  25. package/dist/api/aptos.d.ts.map +1 -1
  26. package/dist/api/aptosConfig.d.ts +12 -0
  27. package/dist/api/aptosConfig.d.ts.map +1 -1
  28. package/dist/api/aptosConfig.js +13 -0
  29. package/dist/api/aptosConfig.js.map +1 -1
  30. package/dist/api/coin.d.ts.map +1 -1
  31. package/dist/api/coin.js.map +1 -1
  32. package/dist/api/digitalAsset.d.ts.map +1 -1
  33. package/dist/api/digitalAsset.js.map +1 -1
  34. package/dist/api/faucet.d.ts.map +1 -1
  35. package/dist/api/faucet.js.map +1 -1
  36. package/dist/api/fungibleAsset.d.ts.map +1 -1
  37. package/dist/api/fungibleAsset.js.map +1 -1
  38. package/dist/api/general.d.ts.map +1 -1
  39. package/dist/api/keyless.d.ts.map +1 -1
  40. package/dist/api/keyless.js.map +1 -1
  41. package/dist/api/object.d.ts.map +1 -1
  42. package/dist/api/object.js.map +1 -1
  43. package/dist/api/staking.d.ts.map +1 -1
  44. package/dist/api/staking.js.map +1 -1
  45. package/dist/api/table.d.ts.map +1 -1
  46. package/dist/api/transaction.d.ts.map +1 -1
  47. package/dist/api/transactionSubmission/build.d.ts.map +1 -1
  48. package/dist/api/transactionSubmission/management.d.ts.map +1 -1
  49. package/dist/api/transactionSubmission/sign.d.ts.map +1 -1
  50. package/dist/api/transactionSubmission/simulate.d.ts.map +1 -1
  51. package/dist/api/transactionSubmission/submit.d.ts.map +1 -1
  52. package/dist/bcs/deserializer.d.ts.map +1 -1
  53. package/dist/bcs/serializable/entryFunctionBytes.d.ts.map +1 -1
  54. package/dist/bcs/serializable/fixedBytes.d.ts.map +1 -1
  55. package/dist/bcs/serializable/movePrimitives.d.ts.map +1 -1
  56. package/dist/bcs/serializable/moveStructs.d.ts.map +1 -1
  57. package/dist/bcs/serializer.d.ts.map +1 -1
  58. package/dist/bcs/serializer.js.map +1 -1
  59. package/dist/cli/localNode.d.ts.map +1 -1
  60. package/dist/cli/localNode.js +16 -3
  61. package/dist/cli/localNode.js.map +1 -1
  62. package/dist/cli/move.d.ts.map +1 -1
  63. package/dist/cli/move.js.map +1 -1
  64. package/dist/client/core.d.ts +3 -0
  65. package/dist/client/core.d.ts.map +1 -1
  66. package/dist/client/core.js +116 -9
  67. package/dist/client/core.js.map +1 -1
  68. package/dist/core/account/utils/address.d.ts.map +1 -1
  69. package/dist/core/accountAddress.d.ts.map +1 -1
  70. package/dist/core/accountAddress.js.map +1 -1
  71. package/dist/core/authenticationKey.d.ts.map +1 -1
  72. package/dist/core/authenticationKey.js.map +1 -1
  73. package/dist/core/common.d.ts.map +1 -1
  74. package/dist/core/crypto/abstraction.d.ts.map +1 -1
  75. package/dist/core/crypto/ed25519.d.ts.map +1 -1
  76. package/dist/core/crypto/ed25519.js.map +1 -1
  77. package/dist/core/crypto/encryption/ciphertext.d.ts.map +1 -1
  78. package/dist/core/crypto/encryption/symmetric.d.ts.map +1 -1
  79. package/dist/core/crypto/encryption/symmetric.js.map +1 -1
  80. package/dist/core/crypto/ephemeral.d.ts.map +1 -1
  81. package/dist/core/crypto/federatedKeyless.d.ts.map +1 -1
  82. package/dist/core/crypto/hdKey.d.ts.map +1 -1
  83. package/dist/core/crypto/keyless.d.ts.map +1 -1
  84. package/dist/core/crypto/keyless.js.map +1 -1
  85. package/dist/core/crypto/multiEd25519.d.ts.map +1 -1
  86. package/dist/core/crypto/multiEd25519.js.map +1 -1
  87. package/dist/core/crypto/multiKey.d.ts.map +1 -1
  88. package/dist/core/crypto/multiKey.js.map +1 -1
  89. package/dist/core/crypto/privateKey.d.ts.map +1 -1
  90. package/dist/core/crypto/privateKey.js.map +1 -1
  91. package/dist/core/crypto/publicKey.d.ts.map +1 -1
  92. package/dist/core/crypto/secp256k1.d.ts.map +1 -1
  93. package/dist/core/crypto/secp256k1.js.map +1 -1
  94. package/dist/core/crypto/secp256r1.d.ts.map +1 -1
  95. package/dist/core/crypto/secp256r1.js.map +1 -1
  96. package/dist/core/crypto/signature.d.ts.map +1 -1
  97. package/dist/core/crypto/singleKey.d.ts.map +1 -1
  98. package/dist/core/crypto/singleKey.js.map +1 -1
  99. package/dist/core/crypto/utils.d.ts.map +1 -1
  100. package/dist/core/hex.d.ts.map +1 -1
  101. package/dist/errors/index.d.ts.map +1 -1
  102. package/dist/internal/digitalAsset.d.ts.map +1 -1
  103. package/dist/internal/transaction.d.ts.map +1 -1
  104. package/dist/transactions/authenticator/account.d.ts.map +1 -1
  105. package/dist/transactions/authenticator/transaction.d.ts.map +1 -1
  106. package/dist/transactions/instances/chainId.d.ts.map +1 -1
  107. package/dist/transactions/instances/encryptedPayload.d.ts.map +1 -1
  108. package/dist/transactions/instances/encryptedPayload.js.map +1 -1
  109. package/dist/transactions/instances/identifier.d.ts.map +1 -1
  110. package/dist/transactions/instances/moduleId.d.ts.map +1 -1
  111. package/dist/transactions/instances/multiAgentTransaction.d.ts.map +1 -1
  112. package/dist/transactions/instances/rawTransaction.d.ts.map +1 -1
  113. package/dist/transactions/instances/rotationProofChallenge.d.ts.map +1 -1
  114. package/dist/transactions/instances/signedTransaction.d.ts.map +1 -1
  115. package/dist/transactions/instances/simpleTransaction.d.ts.map +1 -1
  116. package/dist/transactions/instances/transactionPayload.d.ts.map +1 -1
  117. package/dist/transactions/management/accountSequenceNumber.d.ts.map +1 -1
  118. package/dist/transactions/management/asyncQueue.d.ts.map +1 -1
  119. package/dist/transactions/management/transactionWorker.d.ts.map +1 -1
  120. package/dist/transactions/management/transactionWorker.js.map +1 -1
  121. package/dist/transactions/transactionBuilder/structEnumParser.d.ts.map +1 -1
  122. package/dist/transactions/transactionBuilder/structEnumParser.js.map +1 -1
  123. package/dist/transactions/transactionBuilder/transactionBuilder.d.ts +7 -2
  124. package/dist/transactions/transactionBuilder/transactionBuilder.d.ts.map +1 -1
  125. package/dist/transactions/transactionBuilder/transactionBuilder.js.map +1 -1
  126. package/dist/transactions/typeTag/index.d.ts.map +1 -1
  127. package/dist/transactions/typeTag/index.js.map +1 -1
  128. package/dist/transactions/typeTag/parser.d.ts.map +1 -1
  129. package/dist/transactions/typeTag/parser.js.map +1 -1
  130. package/dist/types/generated/queries.d.ts.map +1 -1
  131. package/dist/types/generated/queries.js.map +1 -1
  132. package/dist/types/types.d.ts +5 -0
  133. package/dist/types/types.d.ts.map +1 -1
  134. package/dist/types/types.js.map +1 -1
  135. package/dist/utils/helpers.d.ts.map +1 -1
  136. package/dist/utils/helpers.js.map +1 -1
  137. package/dist/utils/runtime.js.map +1 -1
  138. package/dist/version.d.ts +1 -1
  139. package/dist/version.d.ts.map +1 -1
  140. package/dist/version.js +1 -1
  141. package/dist/version.js.map +1 -1
  142. package/package.json +28 -29
  143. package/src/api/aptosConfig.ts +14 -0
  144. package/src/cli/localNode.ts +17 -3
  145. package/src/client/core.ts +150 -10
  146. package/src/transactions/transactionBuilder/transactionBuilder.ts +6 -0
  147. package/src/types/types.ts +6 -0
  148. package/src/version.ts +1 -1
@@ -68,26 +68,107 @@ export async function request<Req, Res>(options: ClientRequest<Req>, client: Cli
68
68
  });
69
69
  }
70
70
 
71
+ const HTTP_STATUS_GONE = 410;
72
+
73
+ const CREDENTIAL_HEADERS = new Set(["authorization", "cookie", "x-api-key"]);
74
+
75
+ const warnedArchivalEndpoints = new Set<string>();
76
+
77
+ type ArchivalRetryTarget = {
78
+ url: string;
79
+ forwardCredentials: boolean;
80
+ };
81
+
71
82
  /**
72
- * The main function to use when making an API request, returning the response or throwing an AptosApiError on failure.
83
+ * Registrable domain, approximated as the last two labels.
84
+ * Hosts under a multi-part suffix like `co.uk` compare equal.
85
+ */
86
+ function siteOf(hostname: string): string {
87
+ return hostname.toLowerCase().split(".").slice(-2).join(".");
88
+ }
89
+
90
+ /**
91
+ * Validates the archival endpoint advertised in a pruning error, returning undefined if it is unusable.
73
92
  *
74
- * @param aptosRequestOpts - Options for the Aptos request, including the URL and path.
75
- * @param aptosConfig - The configuration information for the SDK client instance.
76
- * @param apiType - The type of API being accessed, which determines how the response is handled.
77
- * @returns The response from the API request or throws an AptosApiError if the request fails.
78
- * @group Implementation
79
- * @category Client
93
+ * The endpoint is chosen by the node rather than the caller, so it must be an absolute http(s) URL that does
94
+ * not downgrade an https request, and credentials are only forwarded to it when it is same-site.
80
95
  */
81
- export async function aptosRequest<Req extends {}, Res extends {}>(
96
+ function resolveArchivalRetryTarget(originalUrl: string, responseData: any): ArchivalRetryTarget | undefined {
97
+ const advertisedEndpoint = responseData?.archival_endpoint;
98
+ if (typeof advertisedEndpoint !== "string" || advertisedEndpoint.length === 0) {
99
+ return undefined;
100
+ }
101
+
102
+ let archivalUrl: URL;
103
+ let originUrl: URL;
104
+ try {
105
+ archivalUrl = new URL(advertisedEndpoint);
106
+ originUrl = new URL(originalUrl);
107
+ } catch {
108
+ return undefined;
109
+ }
110
+
111
+ if (archivalUrl.protocol !== "https:" && archivalUrl.protocol !== "http:") {
112
+ return undefined;
113
+ }
114
+ if (originUrl.protocol === "https:" && archivalUrl.protocol !== "https:") {
115
+ return undefined;
116
+ }
117
+
118
+ return {
119
+ url: advertisedEndpoint.replace(/\/+$/, ""),
120
+ forwardCredentials: siteOf(archivalUrl.hostname) === siteOf(originUrl.hostname),
121
+ };
122
+ }
123
+
124
+ function hasCredentials(overrides: AptosRequest["overrides"]): boolean {
125
+ if (!overrides) {
126
+ return false;
127
+ }
128
+ if (overrides.API_KEY || overrides.AUTH_TOKEN) {
129
+ return true;
130
+ }
131
+ return Object.keys(overrides.HEADERS ?? {}).some((name) => CREDENTIAL_HEADERS.has(name.toLowerCase()));
132
+ }
133
+
134
+ function withoutCredentials(overrides: AptosRequest["overrides"]): AptosRequest["overrides"] {
135
+ if (!overrides) {
136
+ return overrides;
137
+ }
138
+ const { API_KEY, AUTH_TOKEN, HEADERS, ...rest } = overrides;
139
+ if (!HEADERS) {
140
+ return rest;
141
+ }
142
+ return {
143
+ ...rest,
144
+ HEADERS: Object.fromEntries(
145
+ Object.entries(HEADERS).filter(([name]) => !CREDENTIAL_HEADERS.has(name.toLowerCase())),
146
+ ),
147
+ };
148
+ }
149
+
150
+ function warnOnceAboutDroppedCredentials(originalUrl: string, archivalUrl: string): void {
151
+ if (warnedArchivalEndpoints.has(archivalUrl)) {
152
+ return;
153
+ }
154
+ warnedArchivalEndpoints.add(archivalUrl);
155
+ console.warn(
156
+ `[Aptos SDK] ${originalUrl} reported pruned data and advertised the archival endpoint ${archivalUrl}. ` +
157
+ "Retrying there without credentials because it is not on the same site. If that endpoint requires " +
158
+ "authentication, set it as your `fullnode` URL, or disable this retry with `archivalFallback: false`.",
159
+ );
160
+ }
161
+
162
+ /** Sends a request and shapes the client response into an `AptosResponse`, without interpreting the status. */
163
+ async function sendAptosRequest<Req extends {}, Res extends {}>(
82
164
  aptosRequestOpts: AptosRequest,
83
165
  aptosConfig: AptosConfig,
84
- apiType: AptosApiType,
85
166
  ): Promise<AptosResponse<Req, Res>> {
86
167
  const { url, path } = aptosRequestOpts;
87
168
  const fullUrl = path ? `${url}/${path}` : url;
88
169
  const clientResponse = await request<Req, Res>({ ...aptosRequestOpts, url: fullUrl }, aptosConfig.client);
89
170
 
90
- const aptosResponse: AptosResponse<Req, Res> = {
171
+ return {
91
172
  status: clientResponse.status,
92
173
  statusText: clientResponse.statusText ?? "No status text provided",
93
174
  data: clientResponse.data,
@@ -96,7 +177,14 @@ export async function aptosRequest<Req extends {}, Res extends {}>(
96
177
  request: clientResponse.request,
97
178
  url: fullUrl,
98
179
  };
180
+ }
99
181
 
182
+ /** Returns the response on success, or throws an `AptosApiError` describing the failure. */
183
+ function handleAptosResponse<Req extends {}, Res extends {}>(
184
+ aptosResponse: AptosResponse<Req, Res>,
185
+ aptosRequestOpts: AptosRequest,
186
+ apiType: AptosApiType,
187
+ ): AptosResponse<Req, Res> {
100
188
  // Handle case for `Unauthorized` error (i.e. API_KEY error)
101
189
  if (aptosResponse.status === 401) {
102
190
  throw new AptosApiError({ apiType, aptosRequest: aptosRequestOpts, aptosResponse });
@@ -135,3 +223,55 @@ export async function aptosRequest<Req extends {}, Res extends {}>(
135
223
  // comes from an indexer request (e.g. 404), we'll need to mention it appropriately
136
224
  throw new AptosApiError({ apiType, aptosRequest: aptosRequestOpts, aptosResponse });
137
225
  }
226
+
227
+ /**
228
+ * The main function to use when making an API request, returning the response or throwing an AptosApiError on failure.
229
+ *
230
+ * A Node API read of pruned data answers `410 Gone` with an `archival_endpoint`. Such requests are replayed
231
+ * once against that endpoint and the result returned transparently. Opt out with `archivalFallback: false`.
232
+ *
233
+ * @param aptosRequestOpts - Options for the Aptos request, including the URL and path.
234
+ * @param aptosConfig - The configuration information for the SDK client instance.
235
+ * @param apiType - The type of API being accessed, which determines how the response is handled.
236
+ * @returns The response from the API request or throws an AptosApiError if the request fails.
237
+ * @group Implementation
238
+ * @category Client
239
+ */
240
+ export async function aptosRequest<Req extends {}, Res extends {}>(
241
+ aptosRequestOpts: AptosRequest,
242
+ aptosConfig: AptosConfig,
243
+ apiType: AptosApiType,
244
+ ): Promise<AptosResponse<Req, Res>> {
245
+ const aptosResponse = await sendAptosRequest<Req, Res>(aptosRequestOpts, aptosConfig);
246
+
247
+ const archivalTarget =
248
+ apiType === AptosApiType.FULLNODE && aptosResponse.status === HTTP_STATUS_GONE && aptosConfig.archivalFallback
249
+ ? resolveArchivalRetryTarget(aptosResponse.url, aptosResponse.data)
250
+ : undefined;
251
+
252
+ if (archivalTarget === undefined) {
253
+ return handleAptosResponse<Req, Res>(aptosResponse, aptosRequestOpts, apiType);
254
+ }
255
+
256
+ if (!archivalTarget.forwardCredentials && hasCredentials(aptosRequestOpts.overrides)) {
257
+ warnOnceAboutDroppedCredentials(aptosResponse.url, archivalTarget.url);
258
+ }
259
+
260
+ const archivalRequestOpts: AptosRequest = {
261
+ ...aptosRequestOpts,
262
+ url: archivalTarget.url,
263
+ overrides: archivalTarget.forwardCredentials
264
+ ? aptosRequestOpts.overrides
265
+ : withoutCredentials(aptosRequestOpts.overrides),
266
+ };
267
+
268
+ let archivalResponse: AptosResponse<Req, Res>;
269
+ try {
270
+ archivalResponse = await sendAptosRequest<Req, Res>(archivalRequestOpts, aptosConfig);
271
+ } catch {
272
+ // Archival was unreachable, so the pruning error remains the more useful one to surface.
273
+ throw new AptosApiError({ apiType, aptosRequest: aptosRequestOpts, aptosResponse });
274
+ }
275
+
276
+ return handleAptosResponse<Req, Res>(archivalResponse, archivalRequestOpts, apiType);
277
+ }
@@ -65,6 +65,7 @@ import {
65
65
  InputGenerateSingleSignerRawTransactionArgs,
66
66
  InputGenerateTransactionOptions,
67
67
  InputScriptData,
68
+ InputMultiSigScriptData,
68
69
  InputSimulateTransactionData,
69
70
  InputMultiSigDataWithRemoteABI,
70
71
  InputEntryFunctionDataWithRemoteABI,
@@ -110,6 +111,11 @@ import { buildEncryptedPayload } from "./encryptPayload.js";
110
111
  * @group Implementation
111
112
  * @category Transactions
112
113
  */
114
+ export async function generateTransactionPayload(args: InputMultiSigScriptData): Promise<TransactionPayloadMultiSig>;
115
+ /**
116
+ * @group Implementation
117
+ * @category Transactions
118
+ */
113
119
  export async function generateTransactionPayload(args: InputScriptData): Promise<TransactionPayloadScript>;
114
120
  /**
115
121
  * @group Implementation
@@ -346,6 +346,12 @@ export type AptosSettings = {
346
346
  readonly transactionGenerationConfig?: TransactionGenerationConfig;
347
347
 
348
348
  readonly pluginSettings?: PluginSettings;
349
+
350
+ /**
351
+ * Whether reads of pruned history are retried against the archival endpoint the node advertises.
352
+ * Defaults to `true`.
353
+ */
354
+ readonly archivalFallback?: boolean;
349
355
  };
350
356
 
351
357
  /**
package/src/version.ts CHANGED
@@ -6,4 +6,4 @@
6
6
  *
7
7
  * hardcoded for now, we would want to have it injected dynamically
8
8
  */
9
- export const VERSION = "7.2.0-beta.0";
9
+ export const VERSION = "7.3.0";