@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.
Files changed (93) hide show
  1. package/dist/account/AbstractKeylessAccount.d.ts.map +1 -1
  2. package/dist/account/AbstractKeylessAccount.js +3 -0
  3. package/dist/account/AbstractKeylessAccount.js.map +1 -1
  4. package/dist/account/EphemeralKeyPair.d.ts +29 -6
  5. package/dist/account/EphemeralKeyPair.d.ts.map +1 -1
  6. package/dist/account/EphemeralKeyPair.js +35 -8
  7. package/dist/account/EphemeralKeyPair.js.map +1 -1
  8. package/dist/bcs/deserializer.d.ts.map +1 -1
  9. package/dist/bcs/deserializer.js +15 -0
  10. package/dist/bcs/deserializer.js.map +1 -1
  11. package/dist/cli/index.d.ts +1 -0
  12. package/dist/cli/index.d.ts.map +1 -1
  13. package/dist/cli/index.js +1 -0
  14. package/dist/cli/index.js.map +1 -1
  15. package/dist/cli/localNode.d.ts.map +1 -1
  16. package/dist/cli/localNode.js +6 -0
  17. package/dist/cli/localNode.js.map +1 -1
  18. package/dist/cli/move.d.ts.map +1 -1
  19. package/dist/cli/move.js +8 -0
  20. package/dist/cli/move.js.map +1 -1
  21. package/dist/cli/spawnArgs.d.ts +12 -0
  22. package/dist/cli/spawnArgs.d.ts.map +1 -0
  23. package/dist/cli/spawnArgs.js +51 -0
  24. package/dist/cli/spawnArgs.js.map +1 -0
  25. package/dist/core/crypto/ed25519.d.ts +117 -4
  26. package/dist/core/crypto/ed25519.d.ts.map +1 -1
  27. package/dist/core/crypto/ed25519.js +128 -14
  28. package/dist/core/crypto/ed25519.js.map +1 -1
  29. package/dist/core/crypto/keyless.d.ts +14 -0
  30. package/dist/core/crypto/keyless.d.ts.map +1 -1
  31. package/dist/core/crypto/keyless.js +22 -3
  32. package/dist/core/crypto/keyless.js.map +1 -1
  33. package/dist/core/crypto/poseidon.js +5 -5
  34. package/dist/core/crypto/poseidon.js.map +1 -1
  35. package/dist/core/crypto/secp256k1.d.ts +123 -5
  36. package/dist/core/crypto/secp256k1.d.ts.map +1 -1
  37. package/dist/core/crypto/secp256k1.js +137 -13
  38. package/dist/core/crypto/secp256k1.js.map +1 -1
  39. package/dist/core/crypto/secp256r1.d.ts +121 -1
  40. package/dist/core/crypto/secp256r1.d.ts.map +1 -1
  41. package/dist/core/crypto/secp256r1.js +156 -9
  42. package/dist/core/crypto/secp256r1.js.map +1 -1
  43. package/dist/core/crypto/utils.d.ts +28 -1
  44. package/dist/core/crypto/utils.d.ts.map +1 -1
  45. package/dist/core/crypto/utils.js +28 -1
  46. package/dist/core/crypto/utils.js.map +1 -1
  47. package/dist/errors/index.d.ts +19 -0
  48. package/dist/errors/index.d.ts.map +1 -1
  49. package/dist/errors/index.js +35 -0
  50. package/dist/errors/index.js.map +1 -1
  51. package/dist/internal/account.d.ts +17 -0
  52. package/dist/internal/account.d.ts.map +1 -1
  53. package/dist/internal/account.js +66 -17
  54. package/dist/internal/account.js.map +1 -1
  55. package/dist/internal/keyless.d.ts.map +1 -1
  56. package/dist/internal/keyless.js +86 -2
  57. package/dist/internal/keyless.js.map +1 -1
  58. package/dist/internal/transaction.d.ts.map +1 -1
  59. package/dist/internal/transaction.js +20 -3
  60. package/dist/internal/transaction.js.map +1 -1
  61. package/dist/transactions/transactionBuilder/encryptPayload.d.ts.map +1 -1
  62. package/dist/transactions/transactionBuilder/encryptPayload.js +37 -38
  63. package/dist/transactions/transactionBuilder/encryptPayload.js.map +1 -1
  64. package/dist/transactions/types.d.ts +17 -13
  65. package/dist/transactions/types.d.ts.map +1 -1
  66. package/dist/utils/helpers.d.ts +16 -0
  67. package/dist/utils/helpers.d.ts.map +1 -1
  68. package/dist/utils/helpers.js +29 -0
  69. package/dist/utils/helpers.js.map +1 -1
  70. package/dist/version.d.ts +1 -1
  71. package/dist/version.js +1 -1
  72. package/package.json +3 -2
  73. package/src/account/AbstractKeylessAccount.ts +3 -0
  74. package/src/account/EphemeralKeyPair.ts +35 -8
  75. package/src/bcs/deserializer.ts +16 -0
  76. package/src/cli/index.ts +1 -0
  77. package/src/cli/localNode.ts +7 -0
  78. package/src/cli/move.ts +9 -0
  79. package/src/cli/spawnArgs.ts +55 -0
  80. package/src/core/crypto/ed25519.ts +132 -15
  81. package/src/core/crypto/keyless.ts +22 -3
  82. package/src/core/crypto/poseidon.ts +5 -5
  83. package/src/core/crypto/secp256k1.ts +141 -13
  84. package/src/core/crypto/secp256r1.ts +164 -11
  85. package/src/core/crypto/utils.ts +28 -1
  86. package/src/errors/index.ts +37 -0
  87. package/src/internal/account.ts +73 -17
  88. package/src/internal/keyless.ts +88 -2
  89. package/src/internal/transaction.ts +22 -3
  90. package/src/transactions/transactionBuilder/encryptPayload.ts +51 -45
  91. package/src/transactions/types.ts +17 -13
  92. package/src/utils/helpers.ts +33 -0
  93. 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 { AccountPublicKey } from "../../core/crypto/index.js";
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: HexInput | AccountPublicKey): AuthenticationKey {
107
- if (input instanceof AccountPublicKey) {
108
- return input.authKey();
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
- * Validates auth-key options and assembles `(address, authenticationKey)` pairs in
115
- * `TransactionAuthenticator::all_signer_auth_keys` order: sender, secondaries, fee payer last.
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
- if (options.authenticationKey === undefined) {
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.authenticationKey is required when options.encrypted is true. " +
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
- const secondaryAddrs = secondarySignerAddresses ?? [];
132
- const secondaryAuthHex = options.secondarySignerAuthenticationKeys;
133
- if (secondaryAddrs.length > 0) {
134
- if (!secondaryAuthHex || secondaryAuthHex.length !== secondaryAddrs.length) {
135
- throw new Error(
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 was set but no secondarySignerAddresses were provided to generateRawTransaction.",
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 senderPair: SignerAuthKeyPair = {
161
- address: sender,
162
- authenticationKey: resolveAuthKey(options.authenticationKey),
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
- const additional: SignerAuthKeyPair[] =
165
- secondaryAddrs.length > 0 && secondaryAuthHex
166
- ? secondaryAddrs.map((addr, i) => ({
167
- address: AccountAddress.from(addr),
168
- authenticationKey: resolveAuthKey(secondaryAuthHex[i]!),
169
- }))
170
- : [];
171
- if (hasNonZeroFeePayer && options.feePayerAuthenticationKey !== undefined) {
172
- additional.push({
173
- address: feePayerAddr,
174
- authenticationKey: resolveAuthKey(options.feePayerAuthenticationKey),
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 { AccountPublicKey, PublicKey } from "../core/crypto/index.js";
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. Required when `encrypted` is true.
186
- * Accept either an `AccountPublicKey` (auth key is derived automatically via `.authKey()`) or a raw 32-byte hex
187
- * string. Must match the on-chain authenticator identity (aptos-core `PayloadAssociatedData::V1.signer_auth_keys`).
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
- authenticationKey?: HexInput | AccountPublicKey;
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. Accepts `AccountPublicKey` or raw 32-byte hex.
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 | AccountPublicKey)[];
198
+ secondarySignerAuthenticationKeys?: (AuthenticationKey | HexInput | undefined)[];
195
199
  /**
196
- * For encrypted **fee-payer** transactions: the fee payer's authentication key. Required when `encrypted` is true
197
- * and `feePayerAddress` is set to a **non-zero** sponsor address. Appended **last** in AAD `signer_auth_keys`,
198
- * matching aptos-core `TransactionAuthenticator::all_signer_auth_keys` (after sender and secondaries).
199
- * Accepts `AccountPublicKey` or raw 32-byte hex.
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?: HexInput | AccountPublicKey;
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`.
@@ -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
@@ -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.0.1";
9
+ export const VERSION = "7.1.0";