@aptos-labs/wallet-adapter-core 3.1.0 → 3.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @aptos-labs/wallet-adapter-core
2
2
 
3
+ ## 3.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 12163ca: Updated SDK dependencies
8
+
9
+ ### Patch Changes
10
+
11
+ - a6f0e46: Fix is bcs argument types check
12
+
13
+ ## 3.1.1
14
+
15
+ ### Patch Changes
16
+
17
+ - 6266a29: Consolidate options argument on signAndSubmitTransaction
18
+
3
19
  ## 3.1.0
4
20
 
5
21
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Types } from 'aptos';
2
2
  export { TxnBuilderTypes, Types } from 'aptos';
3
- import { Network, InputGenerateTransactionData, InputGenerateTransactionOptions, PendingTransactionResponse, InputSubmitTransactionData, AccountAddressInput, AnyRawTransaction, AccountAuthenticator } from '@aptos-labs/ts-sdk';
3
+ import { Network, InputGenerateTransactionData, InputGenerateTransactionOptions, PendingTransactionResponse, InputSubmitTransactionData, AccountAddressInput, InputGenerateTransactionPayloadData, AnyRawTransaction, AccountAuthenticator } from '@aptos-labs/ts-sdk';
4
4
  export { AccountAuthenticator, AnyRawTransaction, InputGenerateTransactionData, InputGenerateTransactionOptions, InputSubmitTransactionData, PendingTransactionResponse } from '@aptos-labs/ts-sdk';
5
5
  import EventEmitter from 'eventemitter3';
6
6
 
@@ -112,8 +112,10 @@ interface TransactionOptions {
112
112
  max_gas_amount?: bigint;
113
113
  gas_unit_price?: bigint;
114
114
  }
115
- type InputTransactionData = Omit<InputGenerateTransactionData, "sender"> & {
115
+ type InputTransactionData = {
116
116
  sender?: AccountAddressInput;
117
+ data: InputGenerateTransactionPayloadData;
118
+ options?: InputGenerateTransactionOptions;
117
119
  };
118
120
 
119
121
  declare class WalletCore extends EventEmitter<WalletCoreEvents> {
@@ -182,7 +184,7 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
182
184
  * @param options optional. A configuration object to generate a transaction by
183
185
  * @returns The pending transaction hash (V1 output) | PendingTransactionResponse (V2 output)
184
186
  */
185
- signAndSubmitTransaction(transactionInput: InputTransactionData, options?: InputGenerateTransactionOptions): Promise<{
187
+ signAndSubmitTransaction(transactionInput: InputTransactionData): Promise<{
186
188
  hash: Types.HexEncodedBytes;
187
189
  output?: any;
188
190
  } | PendingTransactionResponse>;
@@ -235,5 +237,6 @@ declare function isMobile(): boolean;
235
237
  declare function isInAppBrowser(): boolean;
236
238
  declare function isRedirectable(): boolean;
237
239
  declare function generalizedErrorMessage(error: any): string;
240
+ declare const areBCSArguments: (args: any) => boolean;
238
241
 
239
- export { AccountInfo, AdapterPlugin, AdapterPluginEvents, AdapterPluginProps, AptosWalletErrorResult, InputTransactionData, NetworkInfo, NetworkName, OnAccountChange, OnNetworkChange, SignMessagePayload, SignMessageResponse, TransactionOptions, Wallet, WalletCore, WalletCoreEvents, WalletInfo, WalletName, WalletReadyState, generalizedErrorMessage, getLocalStorage, isInAppBrowser, isMobile, isRedirectable, removeLocalStorage, scopePollingDetectionStrategy, setLocalStorage };
242
+ export { AccountInfo, AdapterPlugin, AdapterPluginEvents, AdapterPluginProps, AptosWalletErrorResult, InputTransactionData, NetworkInfo, NetworkName, OnAccountChange, OnNetworkChange, SignMessagePayload, SignMessageResponse, TransactionOptions, Wallet, WalletCore, WalletCoreEvents, WalletInfo, WalletName, WalletReadyState, areBCSArguments, generalizedErrorMessage, getLocalStorage, isInAppBrowser, isMobile, isRedirectable, removeLocalStorage, scopePollingDetectionStrategy, setLocalStorage };
package/dist/index.js CHANGED
@@ -31,6 +31,7 @@ __export(src_exports, {
31
31
  Types: () => import_aptos3.Types,
32
32
  WalletCore: () => WalletCore,
33
33
  WalletReadyState: () => WalletReadyState,
34
+ areBCSArguments: () => areBCSArguments,
34
35
  generalizedErrorMessage: () => generalizedErrorMessage,
35
36
  getLocalStorage: () => getLocalStorage,
36
37
  isInAppBrowser: () => isInAppBrowser,
@@ -44,7 +45,7 @@ module.exports = __toCommonJS(src_exports);
44
45
 
45
46
  // src/WalletCore.ts
46
47
  var import_aptos2 = require("aptos");
47
- var import_ts_sdk2 = require("@aptos-labs/ts-sdk");
48
+ var import_ts_sdk3 = require("@aptos-labs/ts-sdk");
48
49
  var import_eventemitter32 = __toESM(require("eventemitter3"));
49
50
  var import_tweetnacl = __toESM(require("tweetnacl"));
50
51
  var import_buffer = require("buffer");
@@ -199,6 +200,7 @@ function getLocalStorage() {
199
200
  }
200
201
 
201
202
  // src/utils/helpers.ts
203
+ var import_ts_sdk = require("@aptos-labs/ts-sdk");
202
204
  function isMobile() {
203
205
  return /Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/i.test(
204
206
  navigator.userAgent
@@ -221,6 +223,9 @@ function isRedirectable() {
221
223
  function generalizedErrorMessage(error) {
222
224
  return typeof error === "object" && "message" in error ? error.message : error;
223
225
  }
226
+ var areBCSArguments = (args) => {
227
+ return args.every((arg) => arg instanceof import_ts_sdk.Serializable);
228
+ };
224
229
 
225
230
  // src/ans.ts
226
231
  var ChainIdToAnsContractAddressMap = {
@@ -243,16 +248,16 @@ var getNameByAddress = async (chainId, address) => {
243
248
  };
244
249
 
245
250
  // src/conversion.ts
246
- var import_ts_sdk = require("@aptos-labs/ts-sdk");
251
+ var import_ts_sdk2 = require("@aptos-labs/ts-sdk");
247
252
  var import_aptos = require("aptos");
248
253
  function convertNetwork(networkInfo) {
249
254
  switch (networkInfo == null ? void 0 : networkInfo.name.toLowerCase()) {
250
255
  case "mainnet":
251
- return import_ts_sdk.Network.MAINNET;
256
+ return import_ts_sdk2.Network.MAINNET;
252
257
  case "testnet":
253
- return import_ts_sdk.Network.TESTNET;
258
+ return import_ts_sdk2.Network.TESTNET;
254
259
  case "devnet":
255
- return import_ts_sdk.Network.DEVNET;
260
+ return import_ts_sdk2.Network.DEVNET;
256
261
  default:
257
262
  throw new Error("Invalid network name");
258
263
  }
@@ -268,7 +273,7 @@ function convertV2PayloadToV1JSONPayload(payload) {
268
273
  } else {
269
274
  const stringTypeTags = (_a = payload.typeArguments) == null ? void 0 : _a.map(
270
275
  (typeTag) => {
271
- if (typeTag instanceof import_ts_sdk.TypeTag) {
276
+ if (typeTag instanceof import_ts_sdk2.TypeTag) {
272
277
  return typeTag.toString();
273
278
  }
274
279
  return typeTag;
@@ -482,26 +487,23 @@ var WalletCore = class extends import_eventemitter32.default {
482
487
  throw new WalletDisconnectionError(errMsg).message;
483
488
  }
484
489
  }
485
- async signAndSubmitTransaction(transactionInput, options) {
486
- var _a, _b;
490
+ async signAndSubmitTransaction(transactionInput) {
491
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
487
492
  try {
488
493
  this.doesWalletExist();
489
494
  if (((_a = this._wallet) == null ? void 0 : _a.version) === "v2") {
490
- const response2 = await this._wallet.signAndSubmitTransaction(
491
- {
492
- ...transactionInput,
493
- sender: (_b = transactionInput.sender) != null ? _b : this._account.address
494
- },
495
- options
496
- );
495
+ const response2 = await this._wallet.signAndSubmitTransaction({
496
+ ...transactionInput,
497
+ sender: (_b = transactionInput.sender) != null ? _b : this._account.address
498
+ });
497
499
  return response2;
498
500
  }
499
501
  const payloadData = transactionInput.data;
500
- if (typeof payloadData.functionArguments[0] === "object") {
501
- const aptosConfig = new import_ts_sdk2.AptosConfig({
502
+ if (areBCSArguments(payloadData.functionArguments)) {
503
+ const aptosConfig = new import_ts_sdk3.AptosConfig({
502
504
  network: convertNetwork(this._network)
503
505
  });
504
- const newPayload = await (0, import_ts_sdk2.generateTransactionPayload)({
506
+ const newPayload = await (0, import_ts_sdk3.generateTransactionPayload)({
505
507
  ...payloadData,
506
508
  aptosConfig
507
509
  });
@@ -510,8 +512,8 @@ var WalletCore = class extends import_eventemitter32.default {
510
512
  oldTransactionPayload2,
511
513
  this._wallet,
512
514
  {
513
- max_gas_amount: (options == null ? void 0 : options.maxGasAmount) ? BigInt(options == null ? void 0 : options.maxGasAmount) : void 0,
514
- gas_unit_price: (options == null ? void 0 : options.gasUnitPrice) ? BigInt(options == null ? void 0 : options.gasUnitPrice) : void 0
515
+ max_gas_amount: ((_c = transactionInput.options) == null ? void 0 : _c.maxGasAmount) ? BigInt((_d = transactionInput.options) == null ? void 0 : _d.maxGasAmount) : void 0,
516
+ gas_unit_price: ((_e = transactionInput.options) == null ? void 0 : _e.gasUnitPrice) ? BigInt((_f = transactionInput.options) == null ? void 0 : _f.gasUnitPrice) : void 0
515
517
  }
516
518
  );
517
519
  const { hash: hash2, ...output2 } = response2;
@@ -522,8 +524,8 @@ var WalletCore = class extends import_eventemitter32.default {
522
524
  oldTransactionPayload,
523
525
  this._wallet,
524
526
  {
525
- max_gas_amount: (options == null ? void 0 : options.maxGasAmount) ? BigInt(options == null ? void 0 : options.maxGasAmount) : void 0,
526
- gas_unit_price: (options == null ? void 0 : options.gasUnitPrice) ? BigInt(options == null ? void 0 : options.gasUnitPrice) : void 0
527
+ max_gas_amount: ((_g = transactionInput.options) == null ? void 0 : _g.maxGasAmount) ? BigInt((_h = transactionInput.options) == null ? void 0 : _h.maxGasAmount) : void 0,
528
+ gas_unit_price: ((_i = transactionInput.options) == null ? void 0 : _i.gasUnitPrice) ? BigInt((_j = transactionInput.options) == null ? void 0 : _j.gasUnitPrice) : void 0
527
529
  }
528
530
  );
529
531
  const { hash, ...output } = response;
@@ -570,9 +572,9 @@ var WalletCore = class extends import_eventemitter32.default {
570
572
  const transactionAuthenticator = deserializedSignature.authenticator;
571
573
  const publicKey = transactionAuthenticator.public_key.value;
572
574
  const signature = transactionAuthenticator.signature.value;
573
- const accountAuthenticator = new import_ts_sdk2.AccountAuthenticatorEd25519(
574
- new import_ts_sdk2.Ed25519PublicKey(publicKey),
575
- new import_ts_sdk2.Ed25519Signature(signature)
575
+ const accountAuthenticator = new import_ts_sdk3.AccountAuthenticatorEd25519(
576
+ new import_ts_sdk3.Ed25519PublicKey(publicKey),
577
+ new import_ts_sdk3.Ed25519Signature(signature)
576
578
  );
577
579
  return accountAuthenticator;
578
580
  } catch (error) {
@@ -705,6 +707,7 @@ var import_aptos3 = require("aptos");
705
707
  Types,
706
708
  WalletCore,
707
709
  WalletReadyState,
710
+ areBCSArguments,
708
711
  generalizedErrorMessage,
709
712
  getLocalStorage,
710
713
  isInAppBrowser,
package/dist/index.mjs CHANGED
@@ -161,6 +161,7 @@ function getLocalStorage() {
161
161
  }
162
162
 
163
163
  // src/utils/helpers.ts
164
+ import { Serializable } from "@aptos-labs/ts-sdk";
164
165
  function isMobile() {
165
166
  return /Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/i.test(
166
167
  navigator.userAgent
@@ -183,6 +184,9 @@ function isRedirectable() {
183
184
  function generalizedErrorMessage(error) {
184
185
  return typeof error === "object" && "message" in error ? error.message : error;
185
186
  }
187
+ var areBCSArguments = (args) => {
188
+ return args.every((arg) => arg instanceof Serializable);
189
+ };
186
190
 
187
191
  // src/ans.ts
188
192
  var ChainIdToAnsContractAddressMap = {
@@ -447,22 +451,19 @@ var WalletCore = class extends EventEmitter2 {
447
451
  throw new WalletDisconnectionError(errMsg).message;
448
452
  }
449
453
  }
450
- async signAndSubmitTransaction(transactionInput, options) {
451
- var _a, _b;
454
+ async signAndSubmitTransaction(transactionInput) {
455
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
452
456
  try {
453
457
  this.doesWalletExist();
454
458
  if (((_a = this._wallet) == null ? void 0 : _a.version) === "v2") {
455
- const response2 = await this._wallet.signAndSubmitTransaction(
456
- {
457
- ...transactionInput,
458
- sender: (_b = transactionInput.sender) != null ? _b : this._account.address
459
- },
460
- options
461
- );
459
+ const response2 = await this._wallet.signAndSubmitTransaction({
460
+ ...transactionInput,
461
+ sender: (_b = transactionInput.sender) != null ? _b : this._account.address
462
+ });
462
463
  return response2;
463
464
  }
464
465
  const payloadData = transactionInput.data;
465
- if (typeof payloadData.functionArguments[0] === "object") {
466
+ if (areBCSArguments(payloadData.functionArguments)) {
466
467
  const aptosConfig = new AptosConfig({
467
468
  network: convertNetwork(this._network)
468
469
  });
@@ -475,8 +476,8 @@ var WalletCore = class extends EventEmitter2 {
475
476
  oldTransactionPayload2,
476
477
  this._wallet,
477
478
  {
478
- max_gas_amount: (options == null ? void 0 : options.maxGasAmount) ? BigInt(options == null ? void 0 : options.maxGasAmount) : void 0,
479
- gas_unit_price: (options == null ? void 0 : options.gasUnitPrice) ? BigInt(options == null ? void 0 : options.gasUnitPrice) : void 0
479
+ max_gas_amount: ((_c = transactionInput.options) == null ? void 0 : _c.maxGasAmount) ? BigInt((_d = transactionInput.options) == null ? void 0 : _d.maxGasAmount) : void 0,
480
+ gas_unit_price: ((_e = transactionInput.options) == null ? void 0 : _e.gasUnitPrice) ? BigInt((_f = transactionInput.options) == null ? void 0 : _f.gasUnitPrice) : void 0
480
481
  }
481
482
  );
482
483
  const { hash: hash2, ...output2 } = response2;
@@ -487,8 +488,8 @@ var WalletCore = class extends EventEmitter2 {
487
488
  oldTransactionPayload,
488
489
  this._wallet,
489
490
  {
490
- max_gas_amount: (options == null ? void 0 : options.maxGasAmount) ? BigInt(options == null ? void 0 : options.maxGasAmount) : void 0,
491
- gas_unit_price: (options == null ? void 0 : options.gasUnitPrice) ? BigInt(options == null ? void 0 : options.gasUnitPrice) : void 0
491
+ max_gas_amount: ((_g = transactionInput.options) == null ? void 0 : _g.maxGasAmount) ? BigInt((_h = transactionInput.options) == null ? void 0 : _h.maxGasAmount) : void 0,
492
+ gas_unit_price: ((_i = transactionInput.options) == null ? void 0 : _i.gasUnitPrice) ? BigInt((_j = transactionInput.options) == null ? void 0 : _j.gasUnitPrice) : void 0
492
493
  }
493
494
  );
494
495
  const { hash, ...output } = response;
@@ -669,6 +670,7 @@ export {
669
670
  Types3 as Types,
670
671
  WalletCore,
671
672
  WalletReadyState,
673
+ areBCSArguments,
672
674
  generalizedErrorMessage,
673
675
  getLocalStorage,
674
676
  isInAppBrowser,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aptos-labs/wallet-adapter-core",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "Aptos Wallet Adapter Core",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -43,8 +43,8 @@
43
43
  "tweetnacl": "^1.0.3"
44
44
  },
45
45
  "peerDependencies": {
46
- "aptos": "^1.20.0",
47
- "@aptos-labs/ts-sdk": "^1.0.0"
46
+ "aptos": "^1.21.0",
47
+ "@aptos-labs/ts-sdk": "^1.2.0"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "tsup src/index.ts --format esm,cjs --dts",
package/src/WalletCore.ts CHANGED
@@ -49,6 +49,7 @@ import {
49
49
  scopePollingDetectionStrategy,
50
50
  isRedirectable,
51
51
  generalizedErrorMessage,
52
+ areBCSArguments,
52
53
  } from "./utils";
53
54
  import { getNameByAddress } from "./ans";
54
55
  import {
@@ -290,8 +291,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
290
291
  * @returns The pending transaction hash (V1 output) | PendingTransactionResponse (V2 output)
291
292
  */
292
293
  async signAndSubmitTransaction(
293
- transactionInput: InputTransactionData,
294
- options?: InputGenerateTransactionOptions
294
+ transactionInput: InputTransactionData
295
295
  ): Promise<
296
296
  { hash: Types.HexEncodedBytes; output?: any } | PendingTransactionResponse
297
297
  > {
@@ -300,13 +300,10 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
300
300
 
301
301
  // wallet supports sdk v2
302
302
  if (this._wallet?.version === "v2") {
303
- const response = await this._wallet.signAndSubmitTransaction(
304
- {
305
- ...transactionInput,
306
- sender: transactionInput.sender ?? this._account!.address,
307
- },
308
- options
309
- );
303
+ const response = await this._wallet.signAndSubmitTransaction({
304
+ ...transactionInput,
305
+ sender: transactionInput.sender ?? this._account!.address,
306
+ });
310
307
  // response should be PendingTransactionResponse
311
308
  return response;
312
309
  }
@@ -314,9 +311,8 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
314
311
  // get the payload piece from the input
315
312
  const payloadData = transactionInput.data;
316
313
 
317
- // if first function arguments is an object (i.e a bcs serialized argument)
318
- // we assume the transaction should be a bcs serialized transaction
319
- if (typeof payloadData.functionArguments[0] === "object") {
314
+ // first check if each argument is a BCS serialized argument
315
+ if (areBCSArguments(payloadData.functionArguments)) {
320
316
  const aptosConfig = new AptosConfig({
321
317
  network: convertNetwork(this._network),
322
318
  });
@@ -330,18 +326,17 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
330
326
  oldTransactionPayload,
331
327
  this._wallet!,
332
328
  {
333
- max_gas_amount: options?.maxGasAmount
334
- ? BigInt(options?.maxGasAmount)
329
+ max_gas_amount: transactionInput.options?.maxGasAmount
330
+ ? BigInt(transactionInput.options?.maxGasAmount)
335
331
  : undefined,
336
- gas_unit_price: options?.gasUnitPrice
337
- ? BigInt(options?.gasUnitPrice)
332
+ gas_unit_price: transactionInput.options?.gasUnitPrice
333
+ ? BigInt(transactionInput.options?.gasUnitPrice)
338
334
  : undefined,
339
335
  }
340
336
  );
341
337
  const { hash, ...output } = response;
342
338
  return { hash, output };
343
339
  }
344
-
345
340
  // if it is not a bcs serialized arguments transaction, convert to the old
346
341
  // json format
347
342
  const oldTransactionPayload =
@@ -350,11 +345,11 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
350
345
  oldTransactionPayload,
351
346
  this._wallet!,
352
347
  {
353
- max_gas_amount: options?.maxGasAmount
354
- ? BigInt(options?.maxGasAmount)
348
+ max_gas_amount: transactionInput.options?.maxGasAmount
349
+ ? BigInt(transactionInput.options?.maxGasAmount)
355
350
  : undefined,
356
- gas_unit_price: options?.gasUnitPrice
357
- ? BigInt(options?.gasUnitPrice)
351
+ gas_unit_price: transactionInput.options?.gasUnitPrice
352
+ ? BigInt(transactionInput.options?.gasUnitPrice)
358
353
  : undefined,
359
354
  }
360
355
  );
package/src/types.ts CHANGED
@@ -6,6 +6,7 @@ import {
6
6
  InputSubmitTransactionData,
7
7
  PendingTransactionResponse,
8
8
  AccountAddressInput,
9
+ InputGenerateTransactionPayloadData,
9
10
  } from "@aptos-labs/ts-sdk";
10
11
  import { WalletReadyState } from "./constants";
11
12
 
@@ -128,8 +129,8 @@ export interface TransactionOptions {
128
129
  gas_unit_price?: bigint;
129
130
  }
130
131
 
131
- // Omit the ts-sdk InputGenerateTransactionData type to make "sender" optional
132
- export type InputTransactionData = Omit<
133
- InputGenerateTransactionData,
134
- "sender"
135
- > & { sender?: AccountAddressInput };
132
+ export type InputTransactionData = {
133
+ sender?: AccountAddressInput;
134
+ data: InputGenerateTransactionPayloadData;
135
+ options?: InputGenerateTransactionOptions;
136
+ };
@@ -1,3 +1,5 @@
1
+ import { Serializable } from "@aptos-labs/ts-sdk";
2
+
1
3
  export function isMobile(): boolean {
2
4
  return /Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/i.test(
3
5
  navigator.userAgent
@@ -30,3 +32,11 @@ export function generalizedErrorMessage(error: any): string {
30
32
  ? error.message
31
33
  : error;
32
34
  }
35
+
36
+ // Helper function to check if input arguments are BCS serialized arguments.
37
+ // In @aptos-labs/ts-sdk each move representative class extends
38
+ // Serializable, so if each argument is of an instance of a class
39
+ // the extends Serializable - we know these are BCS arguments
40
+ export const areBCSArguments = (args: any): boolean => {
41
+ return args.every((arg: any) => arg instanceof Serializable);
42
+ };