@aptos-labs/wallet-adapter-core 2.5.1 → 3.0.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,31 @@
1
1
  # @aptos-labs/wallet-adapter-core
2
2
 
3
+ ## 3.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 31e0084: Support TypeScript SDK V2. Fully compatible with existing SDK V1 and Wallet Adapter V1
8
+ but with a full SDK V2 support for the dapp.
9
+
10
+ - Add support for SDK V2 input types
11
+ - `signAndSubmitTransaction()` accept only SDK V2 transaction input type
12
+ - Implement a `submitTransaction()` function for multi signers transactions
13
+ - `signTransaction()` to support both SDK V1 and V2 versions
14
+ - Convert wallet `SignedTransaction` response from `signTransaction()` to TS SDK V2 `AccountAuthenticator`
15
+ - Demo app to demonstrate different trnsaction flows - single signer, sponsor and multi agent transactions
16
+ - Reject promise on core and/or provider errors instead of just returning `false`
17
+ - Use `@aptos-labs/ts-sdk@experimental` version `0.0.7`
18
+
19
+ ## 2.6.0
20
+
21
+ ### Minor Changes
22
+
23
+ - 7acfa69: Adding support for the new Typescript SDK in the package `@aptos-labs/ts-sdk`. The wallet adapter now supports submitting a basic transaction with the new SDK types.
24
+
25
+ ### Patch Changes
26
+
27
+ - dd6e1ed: Moves dependencies to peer dependencies as needed
28
+
3
29
  ## 2.5.1
4
30
 
5
31
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
- import { Types, TxnBuilderTypes } from 'aptos';
1
+ import { Types } from 'aptos';
2
2
  export { TxnBuilderTypes, Types } from 'aptos';
3
+ import { Network, InputGenerateTransactionData, InputGenerateTransactionOptions, PendingTransactionResponse, InputSubmitTransactionData, AnyRawTransaction, AccountAuthenticator } from '@aptos-labs/ts-sdk';
4
+ export { AccountAuthenticator, AnyRawTransaction, InputGenerateTransactionData, InputGenerateTransactionOptions, InputSubmitTransactionData, PendingTransactionResponse } from '@aptos-labs/ts-sdk';
3
5
  import EventEmitter from 'eventemitter3';
4
6
 
5
7
  declare enum WalletReadyState {
@@ -27,15 +29,20 @@ declare enum NetworkName {
27
29
  Devnet = "devnet"
28
30
  }
29
31
 
30
- declare type WalletName<T extends string = string> = T & {
32
+ type WalletName<T extends string = string> = T & {
31
33
  __brand__: "WalletName";
32
34
  };
33
- declare type NetworkInfo = {
34
- name: NetworkName;
35
+ type NetworkInfo = {
36
+ name: Network;
35
37
  chainId?: string;
36
38
  url?: string;
37
39
  };
38
- declare type AccountInfo = {
40
+ type WalletInfo = {
41
+ name: WalletName;
42
+ icon: string;
43
+ url: string;
44
+ };
45
+ type AccountInfo = {
39
46
  address: string;
40
47
  publicKey: string | string[];
41
48
  minKeysRequired?: number;
@@ -46,49 +53,6 @@ interface AptosWalletErrorResult {
46
53
  name: string;
47
54
  message: string;
48
55
  }
49
- declare type OnNetworkChange = (callBack: (networkInfo: NetworkInfo) => Promise<void>) => Promise<void>;
50
- interface PluginProvider {
51
- connect: () => Promise<AccountInfo>;
52
- account: () => Promise<AccountInfo>;
53
- disconnect: () => Promise<void>;
54
- signAndSubmitTransaction: (transaction: any, options?: any) => Promise<{
55
- hash: Types.HexEncodedBytes;
56
- } | AptosWalletErrorResult>;
57
- signMessage: (message: SignMessagePayload) => Promise<SignMessageResponse>;
58
- network: () => Promise<NetworkName>;
59
- onAccountChange: (listener: (newAddress: AccountInfo) => Promise<void>) => Promise<void>;
60
- onNetworkChange: OnNetworkChange;
61
- }
62
- interface AdapterPluginEvents {
63
- onNetworkChange: OnNetworkChange;
64
- onAccountChange(callback: any): Promise<any>;
65
- }
66
- interface AdapterPluginProps<Name extends string = string> {
67
- name: WalletName<Name>;
68
- url: string;
69
- icon: `data:image/${"svg+xml" | "webp" | "png" | "gif"};base64,${string}`;
70
- providerName?: string;
71
- provider: any;
72
- deeplinkProvider?: (data: {
73
- url: string;
74
- }) => string;
75
- connect(): Promise<any>;
76
- disconnect: () => Promise<any>;
77
- network: () => Promise<any>;
78
- signAndSubmitTransaction<T extends Types.TransactionPayload, V>(transaction: T, options?: V): Promise<{
79
- hash: Types.HexEncodedBytes;
80
- }>;
81
- signMessage<T extends SignMessagePayload>(message: T): Promise<SignMessageResponse>;
82
- }
83
- declare type AdapterPlugin<Name extends string = string> = AdapterPluginProps<Name> & AdapterPluginEvents;
84
- declare type Wallet<Name extends string = string> = AdapterPlugin<Name> & {
85
- readyState?: WalletReadyState;
86
- };
87
- declare type WalletInfo = {
88
- name: WalletName;
89
- icon: string;
90
- url: string;
91
- };
92
56
  declare interface WalletCoreEvents {
93
57
  connect(account: AccountInfo | null): void;
94
58
  disconnect(): void;
@@ -114,6 +78,36 @@ interface SignMessageResponse {
114
78
  signature: string | string[];
115
79
  bitmap?: Uint8Array;
116
80
  }
81
+ type OnNetworkChange = (callBack: (networkInfo: NetworkInfo) => Promise<void>) => Promise<void>;
82
+ type OnAccountChange = (callBack: (accountInfo: AccountInfo) => Promise<any>) => Promise<void>;
83
+ interface AdapterPluginEvents {
84
+ onNetworkChange: OnNetworkChange;
85
+ onAccountChange: OnAccountChange;
86
+ }
87
+ interface AdapterPluginProps<Name extends string = string> {
88
+ name: WalletName<Name>;
89
+ url: string;
90
+ icon: `data:image/${"svg+xml" | "webp" | "png" | "gif"};base64,${string}`;
91
+ version?: "v1" | "v2";
92
+ providerName?: string;
93
+ provider: any;
94
+ deeplinkProvider?: (data: {
95
+ url: string;
96
+ }) => string;
97
+ connect(): Promise<any>;
98
+ disconnect: () => Promise<any>;
99
+ network: () => Promise<any>;
100
+ signAndSubmitTransaction<V>(transaction: Types.TransactionPayload | InputGenerateTransactionData, options?: InputGenerateTransactionOptions): Promise<{
101
+ hash: Types.HexEncodedBytes;
102
+ output?: any;
103
+ } | PendingTransactionResponse>;
104
+ submitTransaction?(transaction: InputSubmitTransactionData): Promise<PendingTransactionResponse>;
105
+ signMessage<T extends SignMessagePayload>(message: T): Promise<SignMessageResponse>;
106
+ }
107
+ type AdapterPlugin<Name extends string = string> = AdapterPluginProps<Name> & AdapterPluginEvents;
108
+ type Wallet<Name extends string = string> = AdapterPlugin<Name> & {
109
+ readyState?: WalletReadyState;
110
+ };
117
111
  interface TransactionOptions {
118
112
  max_gas_amount?: bigint;
119
113
  gas_unit_price?: bigint;
@@ -124,6 +118,7 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
124
118
  private _wallet;
125
119
  private _account;
126
120
  private _network;
121
+ private readonly waletCoreV1;
127
122
  private _connecting;
128
123
  private _connected;
129
124
  constructor(plugins: ReadonlyArray<Wallet>);
@@ -159,7 +154,7 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
159
154
  * If all good, we connect the wallet by calling `this.connectWallet`
160
155
  * @param walletName. The wallet name we want to connect.
161
156
  */
162
- connect(walletName: WalletName): Promise<void | string>;
157
+ connect(walletName: string): Promise<void | string>;
163
158
  /**
164
159
  * Connects a wallet to the dapp.
165
160
  * On connect success, we set the current account and the network, and keeping the selected wallet
@@ -178,36 +173,35 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
178
173
  */
179
174
  disconnect(): Promise<void>;
180
175
  /**
181
- Sign and submit an entry (not bcs serialized) transaction type to chain.
182
- @param transaction a non-bcs serialized transaction
183
- @param options max_gas_amount and gas_unit_limit
184
- @return response from the wallet's signAndSubmitTransaction function
185
- @throws WalletSignAndSubmitMessageError
186
- */
187
- signAndSubmitTransaction(transaction: Types.TransactionPayload, options?: TransactionOptions): Promise<any>;
188
- /**
189
- Sign and submit a bsc serialized transaction type to chain.
190
- @param transaction a bcs serialized transaction
191
- @param options max_gas_amount and gas_unit_limit
192
- @return response from the wallet's signAndSubmitBCSTransaction function
193
- @throws WalletSignAndSubmitMessageError
194
- */
195
- signAndSubmitBCSTransaction(transaction: TxnBuilderTypes.TransactionPayload, options?: TransactionOptions): Promise<any>;
176
+ * Signs and submits a transaction to chain
177
+ *
178
+ * @param transactionInput InputGenerateTransactionData
179
+ * @param options optional. A configuration object to generate a transaction by
180
+ * @returns The pending transaction hash (V1 output) | PendingTransactionResponse (V2 output)
181
+ */
182
+ signAndSubmitTransaction(transactionInput: InputGenerateTransactionData, options?: InputGenerateTransactionOptions): Promise<{
183
+ hash: Types.HexEncodedBytes;
184
+ output?: any;
185
+ } | PendingTransactionResponse>;
196
186
  /**
197
- Sign transaction (doesnt submit to chain).
198
- @param transaction
199
- @param options max_gas_amount and gas_unit_limit
200
- @return response from the wallet's signTransaction function
201
- @throws WalletSignTransactionError
202
- */
203
- signTransaction(transaction: Types.TransactionPayload, options?: TransactionOptions): Promise<Uint8Array | null>;
187
+ * Signs a transaction
188
+ *
189
+ * To support both existing wallet adapter V1 and V2, we support 2 input types
190
+ *
191
+ * @param transactionOrPayload AnyRawTransaction - V2 input | Types.TransactionPayload - V1 input
192
+ * @param options optional. V1 input
193
+ *
194
+ * @returns AccountAuthenticator
195
+ */
196
+ signTransaction(transactionOrPayload: AnyRawTransaction | Types.TransactionPayload, asFeePayer?: boolean, options?: InputGenerateTransactionOptions): Promise<AccountAuthenticator>;
204
197
  /**
205
- Sign message (doesnt submit to chain).
206
- @param message
207
- @return response from the wallet's signMessage function
208
- @throws WalletSignMessageError
209
- */
210
- signMessage(message: SignMessagePayload): Promise<SignMessageResponse | null>;
198
+ Sign message (doesnt submit to chain).
199
+ @param message
200
+ @return response from the wallet's signMessage function
201
+ @throws WalletSignMessageError
202
+ */
203
+ signMessage(message: SignMessagePayload): Promise<SignMessageResponse>;
204
+ submitTransaction(transaction: InputSubmitTransactionData): Promise<PendingTransactionResponse>;
211
205
  /**
212
206
  Event for when account has changed on the wallet
213
207
  @return the new account info
@@ -220,6 +214,11 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
220
214
  @throws WalletNetworkChangeError
221
215
  */
222
216
  onNetworkChange(): Promise<void>;
217
+ /**
218
+ * Signs a message and verifies the signer
219
+ * @param message SignMessagePayload
220
+ * @returns boolean
221
+ */
223
222
  signMessageAndVerify(message: SignMessagePayload): Promise<boolean>;
224
223
  }
225
224
 
@@ -232,5 +231,6 @@ declare function getLocalStorage(): void;
232
231
  declare function isMobile(): boolean;
233
232
  declare function isInAppBrowser(): boolean;
234
233
  declare function isRedirectable(): boolean;
234
+ declare function generalizedErrorMessage(error: any): string;
235
235
 
236
- export { AccountInfo, AdapterPlugin, AdapterPluginEvents, AdapterPluginProps, AptosWalletErrorResult, NetworkInfo, NetworkName, OnNetworkChange, PluginProvider, SignMessagePayload, SignMessageResponse, TransactionOptions, Wallet, WalletCore, WalletCoreEvents, WalletInfo, WalletName, WalletReadyState, getLocalStorage, isInAppBrowser, isMobile, isRedirectable, removeLocalStorage, scopePollingDetectionStrategy, setLocalStorage };
236
+ export { AccountInfo, AdapterPlugin, AdapterPluginEvents, AdapterPluginProps, AptosWalletErrorResult, NetworkInfo, NetworkName, OnAccountChange, OnNetworkChange, SignMessagePayload, SignMessageResponse, TransactionOptions, Wallet, WalletCore, WalletCoreEvents, WalletInfo, WalletName, WalletReadyState, generalizedErrorMessage, getLocalStorage, isInAppBrowser, isMobile, isRedirectable, removeLocalStorage, scopePollingDetectionStrategy, setLocalStorage };
package/dist/index.js CHANGED
@@ -27,10 +27,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
27
27
  var src_exports = {};
28
28
  __export(src_exports, {
29
29
  NetworkName: () => NetworkName,
30
- TxnBuilderTypes: () => import_aptos2.TxnBuilderTypes,
31
- Types: () => import_aptos2.Types,
30
+ TxnBuilderTypes: () => import_aptos3.TxnBuilderTypes,
31
+ Types: () => import_aptos3.Types,
32
32
  WalletCore: () => WalletCore,
33
33
  WalletReadyState: () => WalletReadyState,
34
+ generalizedErrorMessage: () => generalizedErrorMessage,
34
35
  getLocalStorage: () => getLocalStorage,
35
36
  isInAppBrowser: () => isInAppBrowser,
36
37
  isMobile: () => isMobile,
@@ -42,8 +43,9 @@ __export(src_exports, {
42
43
  module.exports = __toCommonJS(src_exports);
43
44
 
44
45
  // src/WalletCore.ts
45
- var import_aptos = require("aptos");
46
- var import_eventemitter3 = __toESM(require("eventemitter3"));
46
+ var import_aptos2 = require("aptos");
47
+ var import_ts_sdk2 = require("@aptos-labs/ts-sdk");
48
+ var import_eventemitter32 = __toESM(require("eventemitter3"));
47
49
  var import_tweetnacl = __toESM(require("tweetnacl"));
48
50
  var import_buffer = require("buffer");
49
51
 
@@ -216,6 +218,9 @@ function isRedirectable() {
216
218
  return false;
217
219
  return isMobile() && !isInAppBrowser();
218
220
  }
221
+ function generalizedErrorMessage(error) {
222
+ return typeof error === "object" && "message" in error ? error.message : error;
223
+ }
219
224
 
220
225
  // src/ans.ts
221
226
  var ChainIdToAnsContractAddressMap = {
@@ -237,14 +242,98 @@ var getNameByAddress = async (chainId, address) => {
237
242
  }
238
243
  };
239
244
 
245
+ // src/conversion.ts
246
+ var import_ts_sdk = require("@aptos-labs/ts-sdk");
247
+ var import_aptos = require("aptos");
248
+ function convertNetwork(networkInfo) {
249
+ switch (networkInfo == null ? void 0 : networkInfo.name.toLowerCase()) {
250
+ case "mainnet":
251
+ return import_ts_sdk.Network.MAINNET;
252
+ case "testnet":
253
+ return import_ts_sdk.Network.TESTNET;
254
+ case "devnet":
255
+ return import_ts_sdk.Network.DEVNET;
256
+ default:
257
+ throw new Error("Invalid network name");
258
+ }
259
+ }
260
+ function convertV2TransactionPayloadToV1BCSPayload(payload) {
261
+ const deserializer = new import_aptos.BCS.Deserializer(payload.bcsToBytes());
262
+ return import_aptos.TxnBuilderTypes.TransactionPayload.deserialize(deserializer);
263
+ }
264
+ function convertV2PayloadToV1JSONPayload(payload) {
265
+ var _a;
266
+ if ("bytecode" in payload) {
267
+ throw new Error("script payload not supported");
268
+ } else {
269
+ const stringTypeTags = (_a = payload.typeArguments) == null ? void 0 : _a.map(
270
+ (typeTag) => {
271
+ if (typeTag instanceof import_ts_sdk.TypeTag) {
272
+ return typeTag.toString();
273
+ }
274
+ return typeTag;
275
+ }
276
+ );
277
+ const newPayload = {
278
+ type: "entry_function_payload",
279
+ function: payload.function,
280
+ type_arguments: stringTypeTags || [],
281
+ arguments: payload.functionArguments
282
+ };
283
+ return newPayload;
284
+ }
285
+ }
286
+
287
+ // src/WalletCoreV1.ts
288
+ var import_eventemitter3 = __toESM(require("eventemitter3"));
289
+ var WalletCoreV1 = class extends import_eventemitter3.default {
290
+ async signAndSubmitTransaction(transaction, wallet, options) {
291
+ try {
292
+ const response = await wallet.signAndSubmitTransaction(
293
+ transaction,
294
+ options
295
+ );
296
+ return response;
297
+ } catch (error) {
298
+ const errMsg = typeof error == "object" && "message" in error ? error.message : error;
299
+ throw new WalletSignAndSubmitMessageError(errMsg).message;
300
+ }
301
+ }
302
+ async signAndSubmitBCSTransaction(transaction, wallet, options) {
303
+ try {
304
+ const response = await wallet.signAndSubmitBCSTransaction(
305
+ transaction,
306
+ options
307
+ );
308
+ return response;
309
+ } catch (error) {
310
+ const errMsg = typeof error == "object" && "message" in error ? error.message : error;
311
+ throw new WalletSignAndSubmitMessageError(errMsg).message;
312
+ }
313
+ }
314
+ async signTransaction(transaction, wallet, options) {
315
+ try {
316
+ const response = await wallet.signTransaction(
317
+ transaction,
318
+ options
319
+ );
320
+ return response;
321
+ } catch (error) {
322
+ const errMsg = typeof error == "object" && "message" in error ? error.message : error;
323
+ throw new WalletSignTransactionError(errMsg).message;
324
+ }
325
+ }
326
+ };
327
+
240
328
  // src/WalletCore.ts
241
- var WalletCore = class extends import_eventemitter3.default {
329
+ var WalletCore = class extends import_eventemitter32.default {
242
330
  constructor(plugins) {
243
331
  super();
244
332
  this._wallets = [];
245
333
  this._wallet = null;
246
334
  this._account = null;
247
335
  this._network = null;
336
+ this.waletCoreV1 = new WalletCoreV1();
248
337
  this._connecting = false;
249
338
  this._connected = false;
250
339
  this._wallets = plugins;
@@ -375,7 +464,7 @@ var WalletCore = class extends import_eventemitter3.default {
375
464
  this.emit("connect", account);
376
465
  } catch (error) {
377
466
  this.clearData();
378
- const errMsg = typeof error == "object" && "message" in error ? error.message : error;
467
+ const errMsg = generalizedErrorMessage(error);
379
468
  throw new WalletConnectionError(errMsg).message;
380
469
  } finally {
381
470
  this._connecting = false;
@@ -389,73 +478,131 @@ var WalletCore = class extends import_eventemitter3.default {
389
478
  this.clearData();
390
479
  this.emit("disconnect");
391
480
  } catch (error) {
392
- const errMsg = typeof error == "object" && "message" in error ? error.message : error;
481
+ const errMsg = generalizedErrorMessage(error);
393
482
  throw new WalletDisconnectionError(errMsg).message;
394
483
  }
395
484
  }
396
- async signAndSubmitTransaction(transaction, options) {
485
+ async signAndSubmitTransaction(transactionInput, options) {
397
486
  var _a;
398
487
  try {
399
488
  this.doesWalletExist();
400
- const response = await ((_a = this._wallet) == null ? void 0 : _a.signAndSubmitTransaction(
401
- transaction,
402
- options
403
- ));
404
- return response;
489
+ if (((_a = this._wallet) == null ? void 0 : _a.version) === "v2") {
490
+ const response2 = await this._wallet.signAndSubmitTransaction(
491
+ transactionInput,
492
+ options
493
+ );
494
+ return response2;
495
+ }
496
+ const payloadData = transactionInput.data;
497
+ if (typeof payloadData.functionArguments[0] === "object") {
498
+ const aptosConfig = new import_ts_sdk2.AptosConfig({
499
+ network: convertNetwork(this._network)
500
+ });
501
+ const newPayload = await (0, import_ts_sdk2.generateTransactionPayload)({
502
+ ...payloadData,
503
+ aptosConfig
504
+ });
505
+ const oldTransactionPayload2 = convertV2TransactionPayloadToV1BCSPayload(newPayload);
506
+ const response2 = await this.waletCoreV1.signAndSubmitBCSTransaction(
507
+ oldTransactionPayload2,
508
+ this._wallet,
509
+ {
510
+ max_gas_amount: (options == null ? void 0 : options.maxGasAmount) ? BigInt(options == null ? void 0 : options.maxGasAmount) : void 0,
511
+ gas_unit_price: (options == null ? void 0 : options.gasUnitPrice) ? BigInt(options == null ? void 0 : options.gasUnitPrice) : void 0
512
+ }
513
+ );
514
+ const { hash: hash2, ...output2 } = response2;
515
+ return { hash: hash2, output: output2 };
516
+ }
517
+ const oldTransactionPayload = convertV2PayloadToV1JSONPayload(payloadData);
518
+ const response = await this.waletCoreV1.signAndSubmitTransaction(
519
+ oldTransactionPayload,
520
+ this._wallet,
521
+ {
522
+ max_gas_amount: (options == null ? void 0 : options.maxGasAmount) ? BigInt(options == null ? void 0 : options.maxGasAmount) : void 0,
523
+ gas_unit_price: (options == null ? void 0 : options.gasUnitPrice) ? BigInt(options == null ? void 0 : options.gasUnitPrice) : void 0
524
+ }
525
+ );
526
+ const { hash, ...output } = response;
527
+ return { hash, output };
405
528
  } catch (error) {
406
- const errMsg = typeof error == "object" && "message" in error ? error.message : error;
529
+ const errMsg = generalizedErrorMessage(error);
407
530
  throw new WalletSignAndSubmitMessageError(errMsg).message;
408
531
  }
409
532
  }
410
- async signAndSubmitBCSTransaction(transaction, options) {
411
- var _a;
412
- if (this._wallet && !("signAndSubmitBCSTransaction" in this._wallet)) {
413
- throw new WalletNotSupportedMethod(
414
- `Submit a BCS Transaction is not supported by ${(_a = this.wallet) == null ? void 0 : _a.name}`
415
- ).message;
416
- }
533
+ async signTransaction(transactionOrPayload, asFeePayer, options) {
534
+ var _a, _b, _c;
417
535
  try {
418
536
  this.doesWalletExist();
419
- const response = await this._wallet.signAndSubmitBCSTransaction(
420
- transaction,
421
- options
537
+ if ("rawTransaction" in transactionOrPayload) {
538
+ if (((_a = this._wallet) == null ? void 0 : _a.version) !== "v2") {
539
+ throw new WalletNotSupportedMethod(
540
+ `Sign Transaction V2 is not supported by ${(_b = this.wallet) == null ? void 0 : _b.name}`
541
+ ).message;
542
+ }
543
+ const accountAuthenticator2 = this._wallet.signTransaction(
544
+ transactionOrPayload,
545
+ asFeePayer
546
+ );
547
+ return accountAuthenticator2;
548
+ }
549
+ if (this._wallet && !("signTransaction" in this._wallet)) {
550
+ throw new WalletNotSupportedMethod(
551
+ `Sign Transaction is not supported by ${(_c = this.wallet) == null ? void 0 : _c.name}`
552
+ ).message;
553
+ }
554
+ const response = await this.waletCoreV1.signTransaction(
555
+ transactionOrPayload,
556
+ this._wallet,
557
+ {
558
+ max_gas_amount: (options == null ? void 0 : options.maxGasAmount) ? BigInt(options == null ? void 0 : options.maxGasAmount) : void 0,
559
+ gas_unit_price: (options == null ? void 0 : options.gasUnitPrice) ? BigInt(options == null ? void 0 : options.gasUnitPrice) : void 0
560
+ }
422
561
  );
423
- return response;
562
+ if (!response) {
563
+ throw new Error("error");
564
+ }
565
+ const deserializer1 = new import_aptos2.BCS.Deserializer(response);
566
+ const deserializedSignature = import_aptos2.TxnBuilderTypes.SignedTransaction.deserialize(deserializer1);
567
+ const transactionAuthenticator = deserializedSignature.authenticator;
568
+ const publicKey = transactionAuthenticator.public_key.value;
569
+ const signature = transactionAuthenticator.signature.value;
570
+ const accountAuthenticator = new import_ts_sdk2.AccountAuthenticatorEd25519(
571
+ new import_ts_sdk2.Ed25519PublicKey(publicKey),
572
+ new import_ts_sdk2.Ed25519Signature(signature)
573
+ );
574
+ return accountAuthenticator;
424
575
  } catch (error) {
425
- const errMsg = typeof error == "object" && "message" in error ? error.message : error;
426
- throw new WalletSignAndSubmitMessageError(errMsg).message;
576
+ const errMsg = generalizedErrorMessage(error);
577
+ throw new WalletSignTransactionError(errMsg).message;
427
578
  }
428
579
  }
429
- async signTransaction(transaction, options) {
430
- var _a;
431
- if (this._wallet && !("signTransaction" in this._wallet)) {
432
- throw new WalletNotSupportedMethod(
433
- `Sign Transaction is not supported by ${(_a = this.wallet) == null ? void 0 : _a.name}`
434
- ).message;
435
- }
580
+ async signMessage(message) {
436
581
  try {
437
582
  this.doesWalletExist();
438
- const response = await this._wallet.signTransaction(
439
- transaction,
440
- options
441
- );
583
+ const response = await this._wallet.signMessage(message);
442
584
  return response;
443
585
  } catch (error) {
444
- const errMsg = typeof error == "object" && "message" in error ? error.message : error;
445
- throw new WalletSignTransactionError(errMsg).message;
586
+ const errMsg = generalizedErrorMessage(error);
587
+ throw new WalletSignMessageError(errMsg).message;
446
588
  }
447
589
  }
448
- async signMessage(message) {
590
+ async submitTransaction(transaction) {
449
591
  var _a;
592
+ if (this._wallet && !("submitTransaction" in this._wallet)) {
593
+ throw new WalletNotSupportedMethod(
594
+ `Submit Transaction is not supported by ${(_a = this.wallet) == null ? void 0 : _a.name}`
595
+ ).message;
596
+ }
450
597
  try {
451
598
  this.doesWalletExist();
452
- if (!this._wallet)
453
- return null;
454
- const response = await ((_a = this._wallet) == null ? void 0 : _a.signMessage(message));
455
- return response;
599
+ const pendingTransaction = this._wallet.submitTransaction(
600
+ transaction
601
+ );
602
+ return pendingTransaction;
456
603
  } catch (error) {
457
- const errMsg = typeof error == "object" && "message" in error ? error.message : error;
458
- throw new WalletSignMessageError(errMsg).message;
604
+ const errMsg = generalizedErrorMessage(error);
605
+ throw new WalletSignTransactionError(errMsg).message;
459
606
  }
460
607
  }
461
608
  async onAccountChange() {
@@ -468,7 +615,7 @@ var WalletCore = class extends import_eventemitter3.default {
468
615
  this.emit("accountChange", this._account);
469
616
  }));
470
617
  } catch (error) {
471
- const errMsg = typeof error == "object" && "message" in error ? error.message : error;
618
+ const errMsg = generalizedErrorMessage(error);
472
619
  throw new WalletAccountChangeError(errMsg).message;
473
620
  }
474
621
  }
@@ -482,7 +629,7 @@ var WalletCore = class extends import_eventemitter3.default {
482
629
  this.emit("networkChange", this._network);
483
630
  }));
484
631
  } catch (error) {
485
- const errMsg = typeof error == "object" && "message" in error ? error.message : error;
632
+ const errMsg = generalizedErrorMessage(error);
486
633
  throw new WalletNetworkChangeError(errMsg).message;
487
634
  }
488
635
  }
@@ -528,10 +675,10 @@ var WalletCore = class extends import_eventemitter3.default {
528
675
  throw new WalletSignMessageAndVerifyError("Failed to get a bitmap").message;
529
676
  }
530
677
  } else {
531
- const currentAccountPublicKey = new import_aptos.HexString(
678
+ const currentAccountPublicKey = new import_aptos2.HexString(
532
679
  this._account.publicKey
533
680
  );
534
- const signature = new import_aptos.HexString(response.signature);
681
+ const signature = new import_aptos2.HexString(response.signature);
535
682
  verified = import_tweetnacl.default.sign.detached.verify(
536
683
  import_buffer.Buffer.from(response.fullMessage),
537
684
  import_buffer.Buffer.from(signature.noPrefix(), "hex"),
@@ -540,14 +687,14 @@ var WalletCore = class extends import_eventemitter3.default {
540
687
  }
541
688
  return verified;
542
689
  } catch (error) {
543
- const errMsg = typeof error == "object" && "message" in error ? error.message : error;
690
+ const errMsg = generalizedErrorMessage(error);
544
691
  throw new WalletSignMessageAndVerifyError(errMsg).message;
545
692
  }
546
693
  }
547
694
  };
548
695
 
549
696
  // src/types.ts
550
- var import_aptos2 = require("aptos");
697
+ var import_aptos3 = require("aptos");
551
698
  // Annotate the CommonJS export names for ESM import in node:
552
699
  0 && (module.exports = {
553
700
  NetworkName,
@@ -555,6 +702,7 @@ var import_aptos2 = require("aptos");
555
702
  Types,
556
703
  WalletCore,
557
704
  WalletReadyState,
705
+ generalizedErrorMessage,
558
706
  getLocalStorage,
559
707
  isInAppBrowser,
560
708
  isMobile,