@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.
- package/README.md +17 -0
- package/dist/account/AbstractKeylessAccount.d.ts.map +1 -1
- package/dist/account/AbstractKeylessAccount.js.map +1 -1
- package/dist/account/AbstractedAccount.d.ts.map +1 -1
- package/dist/account/Account.d.ts.map +1 -1
- package/dist/account/Account.js.map +1 -1
- package/dist/account/AccountUtils.js.map +1 -1
- package/dist/account/DerivableAbstractedAccount.d.ts.map +1 -1
- package/dist/account/DerivableAbstractedAccount.js.map +1 -1
- package/dist/account/Ed25519Account.d.ts.map +1 -1
- package/dist/account/EphemeralKeyPair.d.ts.map +1 -1
- package/dist/account/EphemeralKeyPair.js.map +1 -1
- package/dist/account/FederatedKeylessAccount.d.ts.map +1 -1
- package/dist/account/KeylessAccount.d.ts.map +1 -1
- package/dist/account/MultiEd25519Account.d.ts.map +1 -1
- package/dist/account/MultiKeyAccount.d.ts.map +1 -1
- package/dist/account/SingleKeyAccount.d.ts.map +1 -1
- package/dist/account/SingleKeyAccount.js.map +1 -1
- package/dist/api/account/abstraction.d.ts.map +1 -1
- package/dist/api/account/abstraction.js.map +1 -1
- package/dist/api/account.d.ts.map +1 -1
- package/dist/api/account.js.map +1 -1
- package/dist/api/ans.d.ts.map +1 -1
- package/dist/api/ans.js.map +1 -1
- package/dist/api/aptos.d.ts.map +1 -1
- package/dist/api/aptosConfig.d.ts +12 -0
- package/dist/api/aptosConfig.d.ts.map +1 -1
- package/dist/api/aptosConfig.js +13 -0
- package/dist/api/aptosConfig.js.map +1 -1
- package/dist/api/coin.d.ts.map +1 -1
- package/dist/api/coin.js.map +1 -1
- package/dist/api/digitalAsset.d.ts.map +1 -1
- package/dist/api/digitalAsset.js.map +1 -1
- package/dist/api/faucet.d.ts.map +1 -1
- package/dist/api/faucet.js.map +1 -1
- package/dist/api/fungibleAsset.d.ts.map +1 -1
- package/dist/api/fungibleAsset.js.map +1 -1
- package/dist/api/general.d.ts.map +1 -1
- package/dist/api/keyless.d.ts.map +1 -1
- package/dist/api/keyless.js.map +1 -1
- package/dist/api/object.d.ts.map +1 -1
- package/dist/api/object.js.map +1 -1
- package/dist/api/staking.d.ts.map +1 -1
- package/dist/api/staking.js.map +1 -1
- package/dist/api/table.d.ts.map +1 -1
- package/dist/api/transaction.d.ts.map +1 -1
- package/dist/api/transactionSubmission/build.d.ts.map +1 -1
- package/dist/api/transactionSubmission/management.d.ts.map +1 -1
- package/dist/api/transactionSubmission/sign.d.ts.map +1 -1
- package/dist/api/transactionSubmission/simulate.d.ts.map +1 -1
- package/dist/api/transactionSubmission/submit.d.ts.map +1 -1
- package/dist/bcs/deserializer.d.ts.map +1 -1
- package/dist/bcs/serializable/entryFunctionBytes.d.ts.map +1 -1
- package/dist/bcs/serializable/fixedBytes.d.ts.map +1 -1
- package/dist/bcs/serializable/movePrimitives.d.ts.map +1 -1
- package/dist/bcs/serializable/moveStructs.d.ts.map +1 -1
- package/dist/bcs/serializer.d.ts.map +1 -1
- package/dist/bcs/serializer.js.map +1 -1
- package/dist/cli/localNode.d.ts.map +1 -1
- package/dist/cli/localNode.js +16 -3
- package/dist/cli/localNode.js.map +1 -1
- package/dist/cli/move.d.ts.map +1 -1
- package/dist/cli/move.js.map +1 -1
- package/dist/client/core.d.ts +3 -0
- package/dist/client/core.d.ts.map +1 -1
- package/dist/client/core.js +116 -9
- package/dist/client/core.js.map +1 -1
- package/dist/core/account/utils/address.d.ts.map +1 -1
- package/dist/core/accountAddress.d.ts.map +1 -1
- package/dist/core/accountAddress.js.map +1 -1
- package/dist/core/authenticationKey.d.ts.map +1 -1
- package/dist/core/authenticationKey.js.map +1 -1
- package/dist/core/common.d.ts.map +1 -1
- package/dist/core/crypto/abstraction.d.ts.map +1 -1
- package/dist/core/crypto/ed25519.d.ts.map +1 -1
- package/dist/core/crypto/ed25519.js.map +1 -1
- package/dist/core/crypto/encryption/ciphertext.d.ts.map +1 -1
- package/dist/core/crypto/encryption/symmetric.d.ts.map +1 -1
- package/dist/core/crypto/encryption/symmetric.js.map +1 -1
- package/dist/core/crypto/ephemeral.d.ts.map +1 -1
- package/dist/core/crypto/federatedKeyless.d.ts.map +1 -1
- package/dist/core/crypto/hdKey.d.ts.map +1 -1
- package/dist/core/crypto/keyless.d.ts.map +1 -1
- package/dist/core/crypto/keyless.js.map +1 -1
- package/dist/core/crypto/multiEd25519.d.ts.map +1 -1
- package/dist/core/crypto/multiEd25519.js.map +1 -1
- package/dist/core/crypto/multiKey.d.ts.map +1 -1
- package/dist/core/crypto/multiKey.js.map +1 -1
- package/dist/core/crypto/privateKey.d.ts.map +1 -1
- package/dist/core/crypto/privateKey.js.map +1 -1
- package/dist/core/crypto/publicKey.d.ts.map +1 -1
- package/dist/core/crypto/secp256k1.d.ts.map +1 -1
- package/dist/core/crypto/secp256k1.js.map +1 -1
- package/dist/core/crypto/secp256r1.d.ts.map +1 -1
- package/dist/core/crypto/secp256r1.js.map +1 -1
- package/dist/core/crypto/signature.d.ts.map +1 -1
- package/dist/core/crypto/singleKey.d.ts.map +1 -1
- package/dist/core/crypto/singleKey.js.map +1 -1
- package/dist/core/crypto/utils.d.ts.map +1 -1
- package/dist/core/hex.d.ts.map +1 -1
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/internal/digitalAsset.d.ts.map +1 -1
- package/dist/internal/transaction.d.ts.map +1 -1
- package/dist/transactions/authenticator/account.d.ts.map +1 -1
- package/dist/transactions/authenticator/transaction.d.ts.map +1 -1
- package/dist/transactions/instances/chainId.d.ts.map +1 -1
- package/dist/transactions/instances/encryptedPayload.d.ts.map +1 -1
- package/dist/transactions/instances/encryptedPayload.js.map +1 -1
- package/dist/transactions/instances/identifier.d.ts.map +1 -1
- package/dist/transactions/instances/moduleId.d.ts.map +1 -1
- package/dist/transactions/instances/multiAgentTransaction.d.ts.map +1 -1
- package/dist/transactions/instances/rawTransaction.d.ts.map +1 -1
- package/dist/transactions/instances/rotationProofChallenge.d.ts.map +1 -1
- package/dist/transactions/instances/signedTransaction.d.ts.map +1 -1
- package/dist/transactions/instances/simpleTransaction.d.ts.map +1 -1
- package/dist/transactions/instances/transactionPayload.d.ts.map +1 -1
- package/dist/transactions/management/accountSequenceNumber.d.ts.map +1 -1
- package/dist/transactions/management/asyncQueue.d.ts.map +1 -1
- package/dist/transactions/management/transactionWorker.d.ts.map +1 -1
- package/dist/transactions/management/transactionWorker.js.map +1 -1
- package/dist/transactions/transactionBuilder/structEnumParser.d.ts.map +1 -1
- package/dist/transactions/transactionBuilder/structEnumParser.js.map +1 -1
- package/dist/transactions/transactionBuilder/transactionBuilder.d.ts +7 -2
- package/dist/transactions/transactionBuilder/transactionBuilder.d.ts.map +1 -1
- package/dist/transactions/transactionBuilder/transactionBuilder.js.map +1 -1
- package/dist/transactions/typeTag/index.d.ts.map +1 -1
- package/dist/transactions/typeTag/index.js.map +1 -1
- package/dist/transactions/typeTag/parser.d.ts.map +1 -1
- package/dist/transactions/typeTag/parser.js.map +1 -1
- package/dist/types/generated/queries.d.ts.map +1 -1
- package/dist/types/generated/queries.js.map +1 -1
- package/dist/types/types.d.ts +5 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js.map +1 -1
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/helpers.js.map +1 -1
- package/dist/utils/runtime.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +28 -29
- package/src/api/aptosConfig.ts +14 -0
- package/src/cli/localNode.ts +17 -3
- package/src/client/core.ts +150 -10
- package/src/transactions/transactionBuilder/transactionBuilder.ts +6 -0
- package/src/types/types.ts +6 -0
- package/src/version.ts +1 -1
package/src/client/core.ts
CHANGED
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
75
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
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
|
package/src/types/types.ts
CHANGED
|
@@ -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