@aptos-labs/wallet-adapter-core 2.6.0 → 3.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/CHANGELOG.md +23 -0
- package/dist/index.d.ts +71 -85
- package/dist/index.js +169 -66
- package/dist/index.mjs +182 -71
- package/package.json +3 -3
- package/src/WalletCore.ts +184 -120
- package/src/WalletCoreV1.ts +85 -0
- package/src/conversion.ts +49 -16
- package/src/types.ts +76 -61
- package/src/utils/helpers.ts +7 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @aptos-labs/wallet-adapter-core
|
|
2
2
|
|
|
3
|
+
## 3.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 6257015: [deps] Updated aptos and @aptos-labs/ts-sdk dependencies to latest versions
|
|
8
|
+
- aa3d15a: Make sender optional when sign and submit single signer transaction
|
|
9
|
+
|
|
10
|
+
## 3.0.0
|
|
11
|
+
|
|
12
|
+
### Major Changes
|
|
13
|
+
|
|
14
|
+
- 31e0084: Support TypeScript SDK V2. Fully compatible with existing SDK V1 and Wallet Adapter V1
|
|
15
|
+
but with a full SDK V2 support for the dapp.
|
|
16
|
+
|
|
17
|
+
- Add support for SDK V2 input types
|
|
18
|
+
- `signAndSubmitTransaction()` accept only SDK V2 transaction input type
|
|
19
|
+
- Implement a `submitTransaction()` function for multi signers transactions
|
|
20
|
+
- `signTransaction()` to support both SDK V1 and V2 versions
|
|
21
|
+
- Convert wallet `SignedTransaction` response from `signTransaction()` to TS SDK V2 `AccountAuthenticator`
|
|
22
|
+
- Demo app to demonstrate different trnsaction flows - single signer, sponsor and multi agent transactions
|
|
23
|
+
- Reject promise on core and/or provider errors instead of just returning `false`
|
|
24
|
+
- Use `@aptos-labs/ts-sdk@experimental` version `0.0.7`
|
|
25
|
+
|
|
3
26
|
## 2.6.0
|
|
4
27
|
|
|
5
28
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Types
|
|
1
|
+
import { Types } from 'aptos';
|
|
2
2
|
export { TxnBuilderTypes, Types } from 'aptos';
|
|
3
|
-
import { InputGenerateTransactionData } from '@aptos-labs/ts-sdk';
|
|
4
|
-
export { InputGenerateTransactionData } from '@aptos-labs/ts-sdk';
|
|
3
|
+
import { Network, InputGenerateTransactionData, InputGenerateTransactionOptions, PendingTransactionResponse, InputSubmitTransactionData, AccountAddressInput, AnyRawTransaction, AccountAuthenticator } from '@aptos-labs/ts-sdk';
|
|
4
|
+
export { AccountAuthenticator, AnyRawTransaction, InputGenerateTransactionData, InputGenerateTransactionOptions, InputSubmitTransactionData, PendingTransactionResponse } from '@aptos-labs/ts-sdk';
|
|
5
5
|
import EventEmitter from 'eventemitter3';
|
|
6
6
|
|
|
7
7
|
declare enum WalletReadyState {
|
|
@@ -33,10 +33,15 @@ type WalletName<T extends string = string> = T & {
|
|
|
33
33
|
__brand__: "WalletName";
|
|
34
34
|
};
|
|
35
35
|
type NetworkInfo = {
|
|
36
|
-
name:
|
|
36
|
+
name: Network;
|
|
37
37
|
chainId?: string;
|
|
38
38
|
url?: string;
|
|
39
39
|
};
|
|
40
|
+
type WalletInfo = {
|
|
41
|
+
name: WalletName;
|
|
42
|
+
icon: string;
|
|
43
|
+
url: string;
|
|
44
|
+
};
|
|
40
45
|
type AccountInfo = {
|
|
41
46
|
address: string;
|
|
42
47
|
publicKey: string | string[];
|
|
@@ -48,50 +53,6 @@ interface AptosWalletErrorResult {
|
|
|
48
53
|
name: string;
|
|
49
54
|
message: string;
|
|
50
55
|
}
|
|
51
|
-
type OnNetworkChange = (callBack: (networkInfo: NetworkInfo) => Promise<void>) => Promise<void>;
|
|
52
|
-
interface PluginProvider {
|
|
53
|
-
connect: () => Promise<AccountInfo>;
|
|
54
|
-
account: () => Promise<AccountInfo>;
|
|
55
|
-
disconnect: () => Promise<void>;
|
|
56
|
-
signAndSubmitTransaction: (transaction: any, options?: any) => Promise<{
|
|
57
|
-
hash: Types.HexEncodedBytes;
|
|
58
|
-
} | AptosWalletErrorResult>;
|
|
59
|
-
signMessage: (message: SignMessagePayload) => Promise<SignMessageResponse>;
|
|
60
|
-
network: () => Promise<NetworkName>;
|
|
61
|
-
onAccountChange: (listener: (newAddress: AccountInfo) => Promise<void>) => Promise<void>;
|
|
62
|
-
onNetworkChange: OnNetworkChange;
|
|
63
|
-
signMultiAgentTransaction: (rawTxn: TxnBuilderTypes.MultiAgentRawTransaction | TxnBuilderTypes.FeePayerRawTransaction) => Promise<string>;
|
|
64
|
-
}
|
|
65
|
-
interface AdapterPluginEvents {
|
|
66
|
-
onNetworkChange: OnNetworkChange;
|
|
67
|
-
onAccountChange(callback: any): Promise<any>;
|
|
68
|
-
}
|
|
69
|
-
interface AdapterPluginProps<Name extends string = string> {
|
|
70
|
-
name: WalletName<Name>;
|
|
71
|
-
url: string;
|
|
72
|
-
icon: `data:image/${"svg+xml" | "webp" | "png" | "gif"};base64,${string}`;
|
|
73
|
-
providerName?: string;
|
|
74
|
-
provider: any;
|
|
75
|
-
deeplinkProvider?: (data: {
|
|
76
|
-
url: string;
|
|
77
|
-
}) => string;
|
|
78
|
-
connect(): Promise<any>;
|
|
79
|
-
disconnect: () => Promise<any>;
|
|
80
|
-
network: () => Promise<any>;
|
|
81
|
-
signAndSubmitTransaction<T extends Types.TransactionPayload, V>(transaction: T, options?: V): Promise<{
|
|
82
|
-
hash: Types.HexEncodedBytes;
|
|
83
|
-
}>;
|
|
84
|
-
signMessage<T extends SignMessagePayload>(message: T): Promise<SignMessageResponse>;
|
|
85
|
-
}
|
|
86
|
-
type AdapterPlugin<Name extends string = string> = AdapterPluginProps<Name> & AdapterPluginEvents;
|
|
87
|
-
type Wallet<Name extends string = string> = AdapterPlugin<Name> & {
|
|
88
|
-
readyState?: WalletReadyState;
|
|
89
|
-
};
|
|
90
|
-
type WalletInfo = {
|
|
91
|
-
name: WalletName;
|
|
92
|
-
icon: string;
|
|
93
|
-
url: string;
|
|
94
|
-
};
|
|
95
56
|
declare interface WalletCoreEvents {
|
|
96
57
|
connect(account: AccountInfo | null): void;
|
|
97
58
|
disconnect(): void;
|
|
@@ -117,16 +78,50 @@ interface SignMessageResponse {
|
|
|
117
78
|
signature: string | string[];
|
|
118
79
|
bitmap?: Uint8Array;
|
|
119
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
|
+
};
|
|
120
111
|
interface TransactionOptions {
|
|
121
112
|
max_gas_amount?: bigint;
|
|
122
113
|
gas_unit_price?: bigint;
|
|
123
114
|
}
|
|
115
|
+
type InputTransactionData = Omit<InputGenerateTransactionData, "sender"> & {
|
|
116
|
+
sender?: AccountAddressInput;
|
|
117
|
+
};
|
|
124
118
|
|
|
125
119
|
declare class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
126
120
|
private _wallets;
|
|
127
121
|
private _wallet;
|
|
128
122
|
private _account;
|
|
129
123
|
private _network;
|
|
124
|
+
private readonly waletCoreV1;
|
|
130
125
|
private _connecting;
|
|
131
126
|
private _connected;
|
|
132
127
|
constructor(plugins: ReadonlyArray<Wallet>);
|
|
@@ -162,7 +157,7 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
162
157
|
* If all good, we connect the wallet by calling `this.connectWallet`
|
|
163
158
|
* @param walletName. The wallet name we want to connect.
|
|
164
159
|
*/
|
|
165
|
-
connect(walletName:
|
|
160
|
+
connect(walletName: string): Promise<void | string>;
|
|
166
161
|
/**
|
|
167
162
|
* Connects a wallet to the dapp.
|
|
168
163
|
* On connect success, we set the current account and the network, and keeping the selected wallet
|
|
@@ -181,50 +176,35 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
181
176
|
*/
|
|
182
177
|
disconnect(): Promise<void>;
|
|
183
178
|
/**
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
*/
|
|
190
|
-
signAndSubmitTransaction(transaction: Types.TransactionPayload, options?: TransactionOptions): Promise<any>;
|
|
191
|
-
/**
|
|
192
|
-
Sign and submit a bsc serialized transaction type to chain.
|
|
193
|
-
@param transaction a bcs serialized transaction
|
|
194
|
-
@param options max_gas_amount and gas_unit_limit
|
|
195
|
-
@return response from the wallet's signAndSubmitBCSTransaction function
|
|
196
|
-
@throws WalletSignAndSubmitMessageError
|
|
179
|
+
* Signs and submits a transaction to chain
|
|
180
|
+
*
|
|
181
|
+
* @param transactionInput InputTransactionData
|
|
182
|
+
* @param options optional. A configuration object to generate a transaction by
|
|
183
|
+
* @returns The pending transaction hash (V1 output) | PendingTransactionResponse (V2 output)
|
|
197
184
|
*/
|
|
198
|
-
|
|
185
|
+
signAndSubmitTransaction(transactionInput: InputTransactionData, options?: InputGenerateTransactionOptions): Promise<{
|
|
186
|
+
hash: Types.HexEncodedBytes;
|
|
187
|
+
output?: any;
|
|
188
|
+
} | PendingTransactionResponse>;
|
|
199
189
|
/**
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
@
|
|
190
|
+
* Signs a transaction
|
|
191
|
+
*
|
|
192
|
+
* To support both existing wallet adapter V1 and V2, we support 2 input types
|
|
193
|
+
*
|
|
194
|
+
* @param transactionOrPayload AnyRawTransaction - V2 input | Types.TransactionPayload - V1 input
|
|
195
|
+
* @param options optional. V1 input
|
|
196
|
+
*
|
|
197
|
+
* @returns AccountAuthenticator
|
|
205
198
|
*/
|
|
206
|
-
signTransaction(
|
|
199
|
+
signTransaction(transactionOrPayload: AnyRawTransaction | Types.TransactionPayload, asFeePayer?: boolean, options?: InputGenerateTransactionOptions): Promise<AccountAuthenticator>;
|
|
207
200
|
/**
|
|
208
201
|
Sign message (doesnt submit to chain).
|
|
209
202
|
@param message
|
|
210
203
|
@return response from the wallet's signMessage function
|
|
211
204
|
@throws WalletSignMessageError
|
|
212
205
|
*/
|
|
213
|
-
signMessage(message: SignMessagePayload): Promise<SignMessageResponse
|
|
214
|
-
|
|
215
|
-
* This function is for signing and submitting a transaction using the `@aptos-labs/ts-sdk` (aka the v2 SDK)
|
|
216
|
-
* input types. It's internally converting the input types to the old SDK input types and then calling
|
|
217
|
-
* the v1 SDK's `signAndSubmitBCSTransaction` with it.
|
|
218
|
-
*
|
|
219
|
-
* @param transactionInput the transaction input
|
|
220
|
-
* @param options max_gas_amount and gas_unit_limit
|
|
221
|
-
* @returns the response from the wallet's signAndSubmitBCSTransaction function
|
|
222
|
-
*/
|
|
223
|
-
submitTransaction(transactionInput: InputGenerateTransactionData, options?: TransactionOptions): Promise<{
|
|
224
|
-
hash: string;
|
|
225
|
-
output?: any;
|
|
226
|
-
}>;
|
|
227
|
-
signMultiAgentTransaction(transaction: TxnBuilderTypes.MultiAgentRawTransaction | TxnBuilderTypes.FeePayerRawTransaction): Promise<string | null>;
|
|
206
|
+
signMessage(message: SignMessagePayload): Promise<SignMessageResponse>;
|
|
207
|
+
submitTransaction(transaction: InputSubmitTransactionData): Promise<PendingTransactionResponse>;
|
|
228
208
|
/**
|
|
229
209
|
Event for when account has changed on the wallet
|
|
230
210
|
@return the new account info
|
|
@@ -237,6 +217,11 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
237
217
|
@throws WalletNetworkChangeError
|
|
238
218
|
*/
|
|
239
219
|
onNetworkChange(): Promise<void>;
|
|
220
|
+
/**
|
|
221
|
+
* Signs a message and verifies the signer
|
|
222
|
+
* @param message SignMessagePayload
|
|
223
|
+
* @returns boolean
|
|
224
|
+
*/
|
|
240
225
|
signMessageAndVerify(message: SignMessagePayload): Promise<boolean>;
|
|
241
226
|
}
|
|
242
227
|
|
|
@@ -249,5 +234,6 @@ declare function getLocalStorage(): void;
|
|
|
249
234
|
declare function isMobile(): boolean;
|
|
250
235
|
declare function isInAppBrowser(): boolean;
|
|
251
236
|
declare function isRedirectable(): boolean;
|
|
237
|
+
declare function generalizedErrorMessage(error: any): string;
|
|
252
238
|
|
|
253
|
-
export { AccountInfo, AdapterPlugin, AdapterPluginEvents, AdapterPluginProps, AptosWalletErrorResult, NetworkInfo, NetworkName,
|
|
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 };
|
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
|
+
generalizedErrorMessage: () => generalizedErrorMessage,
|
|
34
35
|
getLocalStorage: () => getLocalStorage,
|
|
35
36
|
isInAppBrowser: () => isInAppBrowser,
|
|
36
37
|
isMobile: () => isMobile,
|
|
@@ -44,7 +45,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
44
45
|
// src/WalletCore.ts
|
|
45
46
|
var import_aptos2 = require("aptos");
|
|
46
47
|
var import_ts_sdk2 = require("@aptos-labs/ts-sdk");
|
|
47
|
-
var
|
|
48
|
+
var import_eventemitter32 = __toESM(require("eventemitter3"));
|
|
48
49
|
var import_tweetnacl = __toESM(require("tweetnacl"));
|
|
49
50
|
var import_buffer = require("buffer");
|
|
50
51
|
|
|
@@ -217,6 +218,9 @@ function isRedirectable() {
|
|
|
217
218
|
return false;
|
|
218
219
|
return isMobile() && !isInAppBrowser();
|
|
219
220
|
}
|
|
221
|
+
function generalizedErrorMessage(error) {
|
|
222
|
+
return typeof error === "object" && "message" in error ? error.message : error;
|
|
223
|
+
}
|
|
220
224
|
|
|
221
225
|
// src/ans.ts
|
|
222
226
|
var ChainIdToAnsContractAddressMap = {
|
|
@@ -253,19 +257,83 @@ function convertNetwork(networkInfo) {
|
|
|
253
257
|
throw new Error("Invalid network name");
|
|
254
258
|
}
|
|
255
259
|
}
|
|
256
|
-
function
|
|
260
|
+
function convertV2TransactionPayloadToV1BCSPayload(payload) {
|
|
257
261
|
const deserializer = new import_aptos.BCS.Deserializer(payload.bcsToBytes());
|
|
258
262
|
return import_aptos.TxnBuilderTypes.TransactionPayload.deserialize(deserializer);
|
|
259
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
|
+
};
|
|
260
327
|
|
|
261
328
|
// src/WalletCore.ts
|
|
262
|
-
var WalletCore = class extends
|
|
329
|
+
var WalletCore = class extends import_eventemitter32.default {
|
|
263
330
|
constructor(plugins) {
|
|
264
331
|
super();
|
|
265
332
|
this._wallets = [];
|
|
266
333
|
this._wallet = null;
|
|
267
334
|
this._account = null;
|
|
268
335
|
this._network = null;
|
|
336
|
+
this.waletCoreV1 = new WalletCoreV1();
|
|
269
337
|
this._connecting = false;
|
|
270
338
|
this._connected = false;
|
|
271
339
|
this._wallets = plugins;
|
|
@@ -396,7 +464,7 @@ var WalletCore = class extends import_eventemitter3.default {
|
|
|
396
464
|
this.emit("connect", account);
|
|
397
465
|
} catch (error) {
|
|
398
466
|
this.clearData();
|
|
399
|
-
const errMsg =
|
|
467
|
+
const errMsg = generalizedErrorMessage(error);
|
|
400
468
|
throw new WalletConnectionError(errMsg).message;
|
|
401
469
|
} finally {
|
|
402
470
|
this._connecting = false;
|
|
@@ -410,99 +478,133 @@ var WalletCore = class extends import_eventemitter3.default {
|
|
|
410
478
|
this.clearData();
|
|
411
479
|
this.emit("disconnect");
|
|
412
480
|
} catch (error) {
|
|
413
|
-
const errMsg =
|
|
481
|
+
const errMsg = generalizedErrorMessage(error);
|
|
414
482
|
throw new WalletDisconnectionError(errMsg).message;
|
|
415
483
|
}
|
|
416
484
|
}
|
|
417
|
-
async signAndSubmitTransaction(
|
|
418
|
-
var _a;
|
|
419
|
-
try {
|
|
420
|
-
this.doesWalletExist();
|
|
421
|
-
const response = await ((_a = this._wallet) == null ? void 0 : _a.signAndSubmitTransaction(
|
|
422
|
-
transaction,
|
|
423
|
-
options
|
|
424
|
-
));
|
|
425
|
-
return response;
|
|
426
|
-
} catch (error) {
|
|
427
|
-
const errMsg = typeof error == "object" && "message" in error ? error.message : error;
|
|
428
|
-
throw new WalletSignAndSubmitMessageError(errMsg).message;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
async signAndSubmitBCSTransaction(transaction, options) {
|
|
432
|
-
var _a;
|
|
433
|
-
if (this._wallet && !("signAndSubmitBCSTransaction" in this._wallet)) {
|
|
434
|
-
throw new WalletNotSupportedMethod(
|
|
435
|
-
`Submit a BCS Transaction is not supported by ${(_a = this.wallet) == null ? void 0 : _a.name}`
|
|
436
|
-
).message;
|
|
437
|
-
}
|
|
485
|
+
async signAndSubmitTransaction(transactionInput, options) {
|
|
486
|
+
var _a, _b;
|
|
438
487
|
try {
|
|
439
488
|
this.doesWalletExist();
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
489
|
+
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
|
+
);
|
|
497
|
+
return response2;
|
|
498
|
+
}
|
|
499
|
+
const payloadData = transactionInput.data;
|
|
500
|
+
if (typeof payloadData.functionArguments[0] === "object") {
|
|
501
|
+
const aptosConfig = new import_ts_sdk2.AptosConfig({
|
|
502
|
+
network: convertNetwork(this._network)
|
|
503
|
+
});
|
|
504
|
+
const newPayload = await (0, import_ts_sdk2.generateTransactionPayload)({
|
|
505
|
+
...payloadData,
|
|
506
|
+
aptosConfig
|
|
507
|
+
});
|
|
508
|
+
const oldTransactionPayload2 = convertV2TransactionPayloadToV1BCSPayload(newPayload);
|
|
509
|
+
const response2 = await this.waletCoreV1.signAndSubmitBCSTransaction(
|
|
510
|
+
oldTransactionPayload2,
|
|
511
|
+
this._wallet,
|
|
512
|
+
{
|
|
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
|
+
}
|
|
516
|
+
);
|
|
517
|
+
const { hash: hash2, ...output2 } = response2;
|
|
518
|
+
return { hash: hash2, output: output2 };
|
|
519
|
+
}
|
|
520
|
+
const oldTransactionPayload = convertV2PayloadToV1JSONPayload(payloadData);
|
|
521
|
+
const response = await this.waletCoreV1.signAndSubmitTransaction(
|
|
522
|
+
oldTransactionPayload,
|
|
523
|
+
this._wallet,
|
|
524
|
+
{
|
|
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
|
+
}
|
|
443
528
|
);
|
|
444
|
-
|
|
529
|
+
const { hash, ...output } = response;
|
|
530
|
+
return { hash, output };
|
|
445
531
|
} catch (error) {
|
|
446
|
-
const errMsg =
|
|
532
|
+
const errMsg = generalizedErrorMessage(error);
|
|
447
533
|
throw new WalletSignAndSubmitMessageError(errMsg).message;
|
|
448
534
|
}
|
|
449
535
|
}
|
|
450
|
-
async signTransaction(
|
|
451
|
-
var _a;
|
|
452
|
-
if (this._wallet && !("signTransaction" in this._wallet)) {
|
|
453
|
-
throw new WalletNotSupportedMethod(
|
|
454
|
-
`Sign Transaction is not supported by ${(_a = this.wallet) == null ? void 0 : _a.name}`
|
|
455
|
-
).message;
|
|
456
|
-
}
|
|
536
|
+
async signTransaction(transactionOrPayload, asFeePayer, options) {
|
|
537
|
+
var _a, _b, _c;
|
|
457
538
|
try {
|
|
458
539
|
this.doesWalletExist();
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
540
|
+
if ("rawTransaction" in transactionOrPayload) {
|
|
541
|
+
if (((_a = this._wallet) == null ? void 0 : _a.version) !== "v2") {
|
|
542
|
+
throw new WalletNotSupportedMethod(
|
|
543
|
+
`Sign Transaction V2 is not supported by ${(_b = this.wallet) == null ? void 0 : _b.name}`
|
|
544
|
+
).message;
|
|
545
|
+
}
|
|
546
|
+
const accountAuthenticator2 = this._wallet.signTransaction(
|
|
547
|
+
transactionOrPayload,
|
|
548
|
+
asFeePayer
|
|
549
|
+
);
|
|
550
|
+
return accountAuthenticator2;
|
|
551
|
+
}
|
|
552
|
+
if (this._wallet && !("signTransaction" in this._wallet)) {
|
|
553
|
+
throw new WalletNotSupportedMethod(
|
|
554
|
+
`Sign Transaction is not supported by ${(_c = this.wallet) == null ? void 0 : _c.name}`
|
|
555
|
+
).message;
|
|
556
|
+
}
|
|
557
|
+
const response = await this.waletCoreV1.signTransaction(
|
|
558
|
+
transactionOrPayload,
|
|
559
|
+
this._wallet,
|
|
560
|
+
{
|
|
561
|
+
max_gas_amount: (options == null ? void 0 : options.maxGasAmount) ? BigInt(options == null ? void 0 : options.maxGasAmount) : void 0,
|
|
562
|
+
gas_unit_price: (options == null ? void 0 : options.gasUnitPrice) ? BigInt(options == null ? void 0 : options.gasUnitPrice) : void 0
|
|
563
|
+
}
|
|
462
564
|
);
|
|
463
|
-
|
|
565
|
+
if (!response) {
|
|
566
|
+
throw new Error("error");
|
|
567
|
+
}
|
|
568
|
+
const deserializer1 = new import_aptos2.BCS.Deserializer(response);
|
|
569
|
+
const deserializedSignature = import_aptos2.TxnBuilderTypes.SignedTransaction.deserialize(deserializer1);
|
|
570
|
+
const transactionAuthenticator = deserializedSignature.authenticator;
|
|
571
|
+
const publicKey = transactionAuthenticator.public_key.value;
|
|
572
|
+
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)
|
|
576
|
+
);
|
|
577
|
+
return accountAuthenticator;
|
|
464
578
|
} catch (error) {
|
|
465
|
-
const errMsg =
|
|
579
|
+
const errMsg = generalizedErrorMessage(error);
|
|
466
580
|
throw new WalletSignTransactionError(errMsg).message;
|
|
467
581
|
}
|
|
468
582
|
}
|
|
469
583
|
async signMessage(message) {
|
|
470
|
-
var _a;
|
|
471
584
|
try {
|
|
472
585
|
this.doesWalletExist();
|
|
473
|
-
|
|
474
|
-
return null;
|
|
475
|
-
const response = await ((_a = this._wallet) == null ? void 0 : _a.signMessage(message));
|
|
586
|
+
const response = await this._wallet.signMessage(message);
|
|
476
587
|
return response;
|
|
477
588
|
} catch (error) {
|
|
478
|
-
const errMsg =
|
|
589
|
+
const errMsg = generalizedErrorMessage(error);
|
|
479
590
|
throw new WalletSignMessageError(errMsg).message;
|
|
480
591
|
}
|
|
481
592
|
}
|
|
482
|
-
async submitTransaction(
|
|
483
|
-
const payloadData = transactionInput.data;
|
|
484
|
-
const aptosConfig = new import_ts_sdk2.AptosConfig({ network: convertNetwork(this._network) });
|
|
485
|
-
const newPayload = await (0, import_ts_sdk2.generateTransactionPayload)({ ...payloadData, aptosConfig });
|
|
486
|
-
const oldTransactionPayload = convertToBCSPayload(newPayload);
|
|
487
|
-
const response = await this.signAndSubmitBCSTransaction(oldTransactionPayload, options);
|
|
488
|
-
const { hash, ...output } = response;
|
|
489
|
-
return { hash, output };
|
|
490
|
-
}
|
|
491
|
-
async signMultiAgentTransaction(transaction) {
|
|
593
|
+
async submitTransaction(transaction) {
|
|
492
594
|
var _a;
|
|
493
|
-
if (this._wallet && !("
|
|
595
|
+
if (this._wallet && !("submitTransaction" in this._wallet)) {
|
|
494
596
|
throw new WalletNotSupportedMethod(
|
|
495
|
-
`
|
|
597
|
+
`Submit Transaction is not supported by ${(_a = this.wallet) == null ? void 0 : _a.name}`
|
|
496
598
|
).message;
|
|
497
599
|
}
|
|
498
600
|
try {
|
|
499
601
|
this.doesWalletExist();
|
|
500
|
-
const
|
|
602
|
+
const pendingTransaction = this._wallet.submitTransaction(
|
|
501
603
|
transaction
|
|
502
604
|
);
|
|
503
|
-
return
|
|
605
|
+
return pendingTransaction;
|
|
504
606
|
} catch (error) {
|
|
505
|
-
const errMsg =
|
|
607
|
+
const errMsg = generalizedErrorMessage(error);
|
|
506
608
|
throw new WalletSignTransactionError(errMsg).message;
|
|
507
609
|
}
|
|
508
610
|
}
|
|
@@ -516,7 +618,7 @@ var WalletCore = class extends import_eventemitter3.default {
|
|
|
516
618
|
this.emit("accountChange", this._account);
|
|
517
619
|
}));
|
|
518
620
|
} catch (error) {
|
|
519
|
-
const errMsg =
|
|
621
|
+
const errMsg = generalizedErrorMessage(error);
|
|
520
622
|
throw new WalletAccountChangeError(errMsg).message;
|
|
521
623
|
}
|
|
522
624
|
}
|
|
@@ -530,7 +632,7 @@ var WalletCore = class extends import_eventemitter3.default {
|
|
|
530
632
|
this.emit("networkChange", this._network);
|
|
531
633
|
}));
|
|
532
634
|
} catch (error) {
|
|
533
|
-
const errMsg =
|
|
635
|
+
const errMsg = generalizedErrorMessage(error);
|
|
534
636
|
throw new WalletNetworkChangeError(errMsg).message;
|
|
535
637
|
}
|
|
536
638
|
}
|
|
@@ -588,7 +690,7 @@ var WalletCore = class extends import_eventemitter3.default {
|
|
|
588
690
|
}
|
|
589
691
|
return verified;
|
|
590
692
|
} catch (error) {
|
|
591
|
-
const errMsg =
|
|
693
|
+
const errMsg = generalizedErrorMessage(error);
|
|
592
694
|
throw new WalletSignMessageAndVerifyError(errMsg).message;
|
|
593
695
|
}
|
|
594
696
|
}
|
|
@@ -603,6 +705,7 @@ var import_aptos3 = require("aptos");
|
|
|
603
705
|
Types,
|
|
604
706
|
WalletCore,
|
|
605
707
|
WalletReadyState,
|
|
708
|
+
generalizedErrorMessage,
|
|
606
709
|
getLocalStorage,
|
|
607
710
|
isInAppBrowser,
|
|
608
711
|
isMobile,
|