@aptos-labs/ts-sdk 7.0.1 → 7.1.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/account/AbstractKeylessAccount.d.ts.map +1 -1
- package/dist/account/AbstractKeylessAccount.js +3 -0
- package/dist/account/AbstractKeylessAccount.js.map +1 -1
- package/dist/account/EphemeralKeyPair.d.ts +29 -6
- package/dist/account/EphemeralKeyPair.d.ts.map +1 -1
- package/dist/account/EphemeralKeyPair.js +35 -8
- package/dist/account/EphemeralKeyPair.js.map +1 -1
- package/dist/bcs/deserializer.d.ts.map +1 -1
- package/dist/bcs/deserializer.js +15 -0
- package/dist/bcs/deserializer.js.map +1 -1
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +1 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/localNode.d.ts.map +1 -1
- package/dist/cli/localNode.js +6 -0
- package/dist/cli/localNode.js.map +1 -1
- package/dist/cli/move.d.ts.map +1 -1
- package/dist/cli/move.js +8 -0
- package/dist/cli/move.js.map +1 -1
- package/dist/cli/spawnArgs.d.ts +12 -0
- package/dist/cli/spawnArgs.d.ts.map +1 -0
- package/dist/cli/spawnArgs.js +51 -0
- package/dist/cli/spawnArgs.js.map +1 -0
- package/dist/core/crypto/ed25519.d.ts +117 -4
- package/dist/core/crypto/ed25519.d.ts.map +1 -1
- package/dist/core/crypto/ed25519.js +128 -14
- package/dist/core/crypto/ed25519.js.map +1 -1
- package/dist/core/crypto/keyless.d.ts +14 -0
- package/dist/core/crypto/keyless.d.ts.map +1 -1
- package/dist/core/crypto/keyless.js +22 -3
- package/dist/core/crypto/keyless.js.map +1 -1
- package/dist/core/crypto/poseidon.js +5 -5
- package/dist/core/crypto/poseidon.js.map +1 -1
- package/dist/core/crypto/secp256k1.d.ts +123 -5
- package/dist/core/crypto/secp256k1.d.ts.map +1 -1
- package/dist/core/crypto/secp256k1.js +137 -13
- package/dist/core/crypto/secp256k1.js.map +1 -1
- package/dist/core/crypto/secp256r1.d.ts +121 -1
- package/dist/core/crypto/secp256r1.d.ts.map +1 -1
- package/dist/core/crypto/secp256r1.js +156 -9
- package/dist/core/crypto/secp256r1.js.map +1 -1
- package/dist/core/crypto/utils.d.ts +28 -1
- package/dist/core/crypto/utils.d.ts.map +1 -1
- package/dist/core/crypto/utils.js +28 -1
- package/dist/core/crypto/utils.js.map +1 -1
- package/dist/errors/index.d.ts +19 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +35 -0
- package/dist/errors/index.js.map +1 -1
- package/dist/internal/account.d.ts +17 -0
- package/dist/internal/account.d.ts.map +1 -1
- package/dist/internal/account.js +66 -17
- package/dist/internal/account.js.map +1 -1
- package/dist/internal/keyless.d.ts.map +1 -1
- package/dist/internal/keyless.js +86 -2
- package/dist/internal/keyless.js.map +1 -1
- package/dist/internal/transaction.d.ts.map +1 -1
- package/dist/internal/transaction.js +20 -3
- package/dist/internal/transaction.js.map +1 -1
- package/dist/transactions/transactionBuilder/encryptPayload.d.ts.map +1 -1
- package/dist/transactions/transactionBuilder/encryptPayload.js +37 -38
- package/dist/transactions/transactionBuilder/encryptPayload.js.map +1 -1
- package/dist/transactions/types.d.ts +17 -13
- package/dist/transactions/types.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +16 -0
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/helpers.js +29 -0
- package/dist/utils/helpers.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -2
- package/src/account/AbstractKeylessAccount.ts +3 -0
- package/src/account/EphemeralKeyPair.ts +35 -8
- package/src/bcs/deserializer.ts +16 -0
- package/src/cli/index.ts +1 -0
- package/src/cli/localNode.ts +7 -0
- package/src/cli/move.ts +9 -0
- package/src/cli/spawnArgs.ts +55 -0
- package/src/core/crypto/ed25519.ts +132 -15
- package/src/core/crypto/keyless.ts +22 -3
- package/src/core/crypto/poseidon.ts +5 -5
- package/src/core/crypto/secp256k1.ts +141 -13
- package/src/core/crypto/secp256r1.ts +164 -11
- package/src/core/crypto/utils.ts +28 -1
- package/src/errors/index.ts +37 -0
- package/src/internal/account.ts +73 -17
- package/src/internal/keyless.ts +88 -2
- package/src/internal/transaction.ts +22 -3
- package/src/transactions/transactionBuilder/encryptPayload.ts +51 -45
- package/src/transactions/types.ts +17 -13
- package/src/utils/helpers.ts +33 -0
- package/src/version.ts +1 -1
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { AptosConfig } from "../../api/aptosConfig.js";
|
|
5
5
|
import { AccountAddress, AccountAddressInput } from "../../core/index.js";
|
|
6
6
|
import { AuthenticationKey } from "../../core/authenticationKey.js";
|
|
7
|
-
import {
|
|
7
|
+
import { fetchAndCacheAuthKeyForAddress } from "../../internal/account.js";
|
|
8
8
|
import { fetchAndCacheEncryptionKey } from "../../internal/encryptionKey.js";
|
|
9
9
|
import {
|
|
10
10
|
ClaimedEntryFunction,
|
|
@@ -103,76 +103,81 @@ function resolveClaimedEntryFun(args: {
|
|
|
103
103
|
return undefined;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
function resolveAuthKey(input:
|
|
107
|
-
if (input instanceof
|
|
108
|
-
return input
|
|
106
|
+
function resolveAuthKey(input: AuthenticationKey | HexInput): AuthenticationKey {
|
|
107
|
+
if (input instanceof AuthenticationKey) {
|
|
108
|
+
return input;
|
|
109
109
|
}
|
|
110
110
|
return new AuthenticationKey({ data: input });
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
114
|
+
* Assembles `(address, authenticationKey)` pairs in `TransactionAuthenticator::all_signer_auth_keys` order
|
|
115
|
+
* (sender, secondaries, fee payer last). Auth keys not supplied in `options` are fetched from chain via
|
|
116
|
+
* `fetchAndCacheAuthKeyForAddress`, which caches per `(network, address)` for ~1 hour.
|
|
116
117
|
*/
|
|
117
|
-
function buildSignerAuthKeys(args: {
|
|
118
|
+
async function buildSignerAuthKeys(args: {
|
|
119
|
+
aptosConfig: AptosConfig;
|
|
118
120
|
sender: AccountAddress;
|
|
119
121
|
options: InputGenerateTransactionOptions;
|
|
120
122
|
feePayerAddress?: AccountAddressInput;
|
|
121
123
|
secondarySignerAddresses?: AccountAddressInput[];
|
|
122
|
-
}): { sender: SignerAuthKeyPair; additional: SignerAuthKeyPair[] | undefined } {
|
|
123
|
-
const { sender, options, feePayerAddress, secondarySignerAddresses } = args;
|
|
124
|
+
}): Promise<{ sender: SignerAuthKeyPair; additional: SignerAuthKeyPair[] | undefined }> {
|
|
125
|
+
const { aptosConfig, sender, options, feePayerAddress, secondarySignerAddresses } = args;
|
|
124
126
|
|
|
125
|
-
|
|
127
|
+
const secondaryAddrs = secondarySignerAddresses ?? [];
|
|
128
|
+
const secondaryAuthInputs = options.secondarySignerAuthenticationKeys;
|
|
129
|
+
if (secondaryAddrs.length === 0 && secondaryAuthInputs !== undefined && secondaryAuthInputs.length > 0) {
|
|
126
130
|
throw new Error(
|
|
127
|
-
"options.
|
|
128
|
-
"Pass the sender's AccountPublicKey or a raw 32-byte auth key hex string.",
|
|
131
|
+
"options.secondarySignerAuthenticationKeys was set but no secondarySignerAddresses were provided to generateRawTransaction.",
|
|
129
132
|
);
|
|
130
133
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
"Encrypted multi-agent transactions require options.secondarySignerAuthenticationKeys with one entry per secondarySignerAddresses entry, in the same order. " +
|
|
137
|
-
"Each entry may be an AccountPublicKey or a raw 32-byte auth key hex string.",
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
} else if (secondaryAuthHex !== undefined && secondaryAuthHex.length > 0) {
|
|
134
|
+
if (
|
|
135
|
+
secondaryAddrs.length > 0 &&
|
|
136
|
+
secondaryAuthInputs !== undefined &&
|
|
137
|
+
secondaryAuthInputs.length !== secondaryAddrs.length
|
|
138
|
+
) {
|
|
141
139
|
throw new Error(
|
|
142
|
-
"options.secondarySignerAuthenticationKeys
|
|
140
|
+
"Encrypted multi-agent transactions require options.secondarySignerAuthenticationKeys (when provided) to have one entry per secondarySignerAddresses entry, in the same order. " +
|
|
141
|
+
"Leave individual entries undefined to fetch them from chain.",
|
|
143
142
|
);
|
|
144
143
|
}
|
|
145
144
|
|
|
146
145
|
const feePayerAddr = feePayerAddress !== undefined ? AccountAddress.from(feePayerAddress) : undefined;
|
|
147
146
|
const hasNonZeroFeePayer = feePayerAddr !== undefined && !feePayerAddr.equals(AccountAddress.ZERO);
|
|
148
|
-
if (hasNonZeroFeePayer && options.feePayerAuthenticationKey === undefined) {
|
|
149
|
-
throw new Error(
|
|
150
|
-
"options.feePayerAuthenticationKey is required when options.encrypted is true and feePayerAddress is a non-zero sponsor. " +
|
|
151
|
-
"Must match the fee payer authenticator; AAD order is sender, then secondaries, then fee payer (aptos-core `all_signer_auth_keys`).",
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
147
|
if (options.feePayerAuthenticationKey !== undefined && !hasNonZeroFeePayer) {
|
|
155
148
|
throw new Error(
|
|
156
149
|
"options.feePayerAuthenticationKey was set but feePayerAddress is missing or the zero address (no on-chain fee payer for AAD).",
|
|
157
150
|
);
|
|
158
151
|
}
|
|
159
152
|
|
|
160
|
-
const
|
|
161
|
-
address:
|
|
162
|
-
|
|
153
|
+
const resolveFor = async (
|
|
154
|
+
address: AccountAddress,
|
|
155
|
+
input: AuthenticationKey | HexInput | undefined,
|
|
156
|
+
): Promise<AuthenticationKey> => {
|
|
157
|
+
if (input !== undefined) {
|
|
158
|
+
return resolveAuthKey(input);
|
|
159
|
+
}
|
|
160
|
+
return fetchAndCacheAuthKeyForAddress({ aptosConfig, accountAddress: address });
|
|
163
161
|
};
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
162
|
+
|
|
163
|
+
const secondaryPairsPromise = Promise.all(
|
|
164
|
+
secondaryAddrs.map(async (addr, i) => {
|
|
165
|
+
const address = AccountAddress.from(addr);
|
|
166
|
+
const authenticationKey = await resolveFor(address, secondaryAuthInputs?.[i]);
|
|
167
|
+
return { address, authenticationKey };
|
|
168
|
+
}),
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
const [senderAuthKey, secondaryPairs, feePayerAuthKey] = await Promise.all([
|
|
172
|
+
resolveFor(sender, options.senderAuthenticationKey),
|
|
173
|
+
secondaryPairsPromise,
|
|
174
|
+
hasNonZeroFeePayer ? resolveFor(feePayerAddr, options.feePayerAuthenticationKey) : Promise.resolve(undefined),
|
|
175
|
+
]);
|
|
176
|
+
|
|
177
|
+
const senderPair: SignerAuthKeyPair = { address: sender, authenticationKey: senderAuthKey };
|
|
178
|
+
const additional: SignerAuthKeyPair[] = [...secondaryPairs];
|
|
179
|
+
if (hasNonZeroFeePayer && feePayerAuthKey !== undefined) {
|
|
180
|
+
additional.push({ address: feePayerAddr, authenticationKey: feePayerAuthKey });
|
|
176
181
|
}
|
|
177
182
|
return { sender: senderPair, additional: additional.length > 0 ? additional : undefined };
|
|
178
183
|
}
|
|
@@ -197,7 +202,8 @@ export async function buildEncryptedPayload(args: {
|
|
|
197
202
|
args;
|
|
198
203
|
|
|
199
204
|
const senderAddr = AccountAddress.from(sender);
|
|
200
|
-
const { sender: senderPair, additional } = buildSignerAuthKeys({
|
|
205
|
+
const { sender: senderPair, additional } = await buildSignerAuthKeys({
|
|
206
|
+
aptosConfig,
|
|
201
207
|
sender: senderAddr,
|
|
202
208
|
options,
|
|
203
209
|
feePayerAddress,
|
|
@@ -19,8 +19,8 @@ import {
|
|
|
19
19
|
U8,
|
|
20
20
|
} from "../bcs/serializable/movePrimitives.js";
|
|
21
21
|
import { FixedBytes } from "../bcs/serializable/fixedBytes.js";
|
|
22
|
-
import { AccountAddress, AccountAddressInput } from "../core/index.js";
|
|
23
|
-
import {
|
|
22
|
+
import { AccountAddress, AccountAddressInput, AuthenticationKey } from "../core/index.js";
|
|
23
|
+
import { PublicKey } from "../core/crypto/index.js";
|
|
24
24
|
import {
|
|
25
25
|
MultiAgentRawTransaction,
|
|
26
26
|
FeePayerRawTransaction,
|
|
@@ -182,23 +182,27 @@ export type InputEncryptedTransactionBuildOptions = {
|
|
|
182
182
|
*/
|
|
183
183
|
encrypted?: boolean;
|
|
184
184
|
/**
|
|
185
|
-
* Authentication key for the primary sender.
|
|
186
|
-
*
|
|
187
|
-
*
|
|
185
|
+
* Authentication key for the primary sender. Optional: when omitted (and `encrypted` is true), the SDK fetches
|
|
186
|
+
* the sender's `authentication_key` from the fullnode and caches it for ~1 hour. Pass it explicitly to skip the
|
|
187
|
+
* lookup (useful right after a key rotation). Accepts an `AuthenticationKey` or a raw 32-byte hex string /
|
|
188
|
+
* `Uint8Array`. Must match the on-chain authenticator identity (aptos-core
|
|
189
|
+
* `PayloadAssociatedData::V1.signer_auth_keys`).
|
|
188
190
|
*/
|
|
189
|
-
|
|
191
|
+
senderAuthenticationKey?: AuthenticationKey | HexInput;
|
|
190
192
|
/**
|
|
191
193
|
* For encrypted **multi-agent** transactions: each secondary signer's authentication key, in the same order
|
|
192
|
-
* as `secondarySignerAddresses` on the transaction build input.
|
|
194
|
+
* as `secondarySignerAddresses` on the transaction build input. Any entry left undefined (or the entire array
|
|
195
|
+
* omitted) will be fetched from chain and cached. Accepts `AuthenticationKey` or a raw 32-byte hex string /
|
|
196
|
+
* `Uint8Array`.
|
|
193
197
|
*/
|
|
194
|
-
secondarySignerAuthenticationKeys?: (HexInput |
|
|
198
|
+
secondarySignerAuthenticationKeys?: (AuthenticationKey | HexInput | undefined)[];
|
|
195
199
|
/**
|
|
196
|
-
* For encrypted **fee-payer** transactions: the fee payer's authentication key.
|
|
197
|
-
*
|
|
198
|
-
* matching aptos-core `TransactionAuthenticator::all_signer_auth_keys` (after sender and
|
|
199
|
-
* Accepts `
|
|
200
|
+
* For encrypted **fee-payer** transactions: the fee payer's authentication key. Optional when `feePayerAddress`
|
|
201
|
+
* is a **non-zero** sponsor — omitted values are fetched from chain and cached. Appended **last** in AAD
|
|
202
|
+
* `signer_auth_keys`, matching aptos-core `TransactionAuthenticator::all_signer_auth_keys` (after sender and
|
|
203
|
+
* secondaries). Accepts `AuthenticationKey` or a raw 32-byte hex string / `Uint8Array`.
|
|
200
204
|
*/
|
|
201
|
-
feePayerAuthenticationKey?:
|
|
205
|
+
feePayerAuthenticationKey?: AuthenticationKey | HexInput;
|
|
202
206
|
/**
|
|
203
207
|
* Overrides `claimed_entry_fun` for encrypted transactions when a fee payer is set, the payload is multisig, or the
|
|
204
208
|
* payload is `TransactionInnerPayload` with a multisig address in `TransactionExtraConfigV1`.
|
package/src/utils/helpers.ts
CHANGED
|
@@ -6,6 +6,39 @@ import { AccountAddress } from "../core/accountAddress.js";
|
|
|
6
6
|
import { createObjectAddress } from "../core/account/utils/address.js";
|
|
7
7
|
import { TEXT_ENCODER } from "./const.js";
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Maximum bigint value that can be losslessly converted to a JS `number`.
|
|
11
|
+
* Equal to `BigInt(Number.MAX_SAFE_INTEGER)` (2^53 - 1).
|
|
12
|
+
*/
|
|
13
|
+
const MAX_SAFE_U64 = BigInt(Number.MAX_SAFE_INTEGER);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Narrows a u64 (`bigint`) into a JS `number` with an explicit safety check.
|
|
17
|
+
*
|
|
18
|
+
* The `deserializeU64` reader returns `bigint`, but several keyless code
|
|
19
|
+
* paths historically narrowed the value with `Number(value)` to fit existing
|
|
20
|
+
* `number`-typed fields (expiry timestamps, expiry horizons). For values
|
|
21
|
+
* larger than `Number.MAX_SAFE_INTEGER` (~9 × 10^15), `Number(bigint)`
|
|
22
|
+
* silently loses precision — comparisons against `Date.now() / 1000` then
|
|
23
|
+
* return wrong results.
|
|
24
|
+
*
|
|
25
|
+
* Real-world expiry values are far below the unsafe range (year ~285 million
|
|
26
|
+
* AD as a Unix timestamp), so this check is effectively a guard against
|
|
27
|
+
* corrupted or malicious BCS data rather than a precision concern in normal
|
|
28
|
+
* operation. Throwing is correct behavior at the BCS/JSON boundary.
|
|
29
|
+
*/
|
|
30
|
+
export function u64ToNumberSafe(value: bigint, fieldName: string): number {
|
|
31
|
+
if (value < 0n) {
|
|
32
|
+
throw new RangeError(`${fieldName} is negative (${value}); expected an unsigned u64`);
|
|
33
|
+
}
|
|
34
|
+
if (value > MAX_SAFE_U64) {
|
|
35
|
+
throw new RangeError(
|
|
36
|
+
`${fieldName} (${value}) exceeds Number.MAX_SAFE_INTEGER (${MAX_SAFE_U64}); refusing to silently lose precision`,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
return Number(value);
|
|
40
|
+
}
|
|
41
|
+
|
|
9
42
|
/**
|
|
10
43
|
* Checks if the current runtime environment is Bun.
|
|
11
44
|
* This is useful for detecting Bun-specific compatibility issues.
|
package/src/version.ts
CHANGED