@aptos-labs/wallet-adapter-core 2.0.0 → 2.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 +7 -3
- package/dist/index.d.ts +14 -8
- package/dist/index.js +21 -1
- package/dist/index.mjs +21 -1
- package/package.json +1 -1
- package/src/WalletCore.ts +36 -6
- package/src/types.ts +3 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
# @aptos-labs/wallet-adapter-core
|
|
2
2
|
|
|
3
|
-
## 2.
|
|
3
|
+
## 2.1.0
|
|
4
4
|
|
|
5
|
-
###
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 50968c4: Support to submit bcs serialized transactions
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
6
10
|
|
|
7
|
-
-
|
|
11
|
+
- 8dea640: Fix wallet adapter auto reconnect on page refresh
|
|
8
12
|
|
|
9
13
|
## 1.0.0
|
|
10
14
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import EventEmitter from 'eventemitter3';
|
|
2
1
|
import { Types, TxnBuilderTypes } from 'aptos';
|
|
2
|
+
import EventEmitter from 'eventemitter3';
|
|
3
3
|
|
|
4
4
|
declare enum WalletReadyState {
|
|
5
5
|
/**
|
|
@@ -63,7 +63,6 @@ interface AdapterPluginEvents {
|
|
|
63
63
|
onNetworkChange(callback: any): Promise<any>;
|
|
64
64
|
onAccountChange(callback: any): Promise<any>;
|
|
65
65
|
}
|
|
66
|
-
declare type TransactionPayload = Types.TransactionPayload | TxnBuilderTypes.TransactionPayload;
|
|
67
66
|
interface AdapterPluginProps<Name extends string = string> {
|
|
68
67
|
name: WalletName<Name>;
|
|
69
68
|
url: string;
|
|
@@ -73,7 +72,7 @@ interface AdapterPluginProps<Name extends string = string> {
|
|
|
73
72
|
connect(): Promise<any>;
|
|
74
73
|
disconnect: () => Promise<any>;
|
|
75
74
|
network: () => Promise<any>;
|
|
76
|
-
signAndSubmitTransaction<T extends TransactionPayload, V>(transaction: T, options?: V): Promise<{
|
|
75
|
+
signAndSubmitTransaction<T extends Types.TransactionPayload, V>(transaction: T, options?: V): Promise<{
|
|
77
76
|
hash: Types.HexEncodedBytes;
|
|
78
77
|
}>;
|
|
79
78
|
signMessage<T extends SignMessagePayload>(message: T): Promise<SignMessageResponse>;
|
|
@@ -167,19 +166,26 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
167
166
|
*/
|
|
168
167
|
disconnect(): Promise<void>;
|
|
169
168
|
/**
|
|
170
|
-
Sign and submit transaction to chain.
|
|
171
|
-
@param transaction
|
|
169
|
+
Sign and submit an entry (not bcs serialized) transaction type to chain.
|
|
170
|
+
@param transaction a non-bcs serialized transaction
|
|
172
171
|
@return response from the wallet's signAndSubmitTransaction function
|
|
173
172
|
@throws WalletSignAndSubmitMessageError
|
|
174
173
|
*/
|
|
175
|
-
signAndSubmitTransaction(transaction: TransactionPayload): Promise<any>;
|
|
174
|
+
signAndSubmitTransaction(transaction: Types.TransactionPayload): Promise<any>;
|
|
175
|
+
/**
|
|
176
|
+
Sign and submit a bsc serialized transaction type to chain.
|
|
177
|
+
@param transaction a bcs serialized transaction
|
|
178
|
+
@return response from the wallet's signAndSubmitBCSTransaction function
|
|
179
|
+
@throws WalletSignAndSubmitMessageError
|
|
180
|
+
*/
|
|
181
|
+
signAndSubmitBCSTransaction(transaction: TxnBuilderTypes.TransactionPayload): Promise<any>;
|
|
176
182
|
/**
|
|
177
183
|
Sign transaction (doesnt submit to chain).
|
|
178
184
|
@param transaction
|
|
179
185
|
@return response from the wallet's signTransaction function
|
|
180
186
|
@throws WalletSignTransactionError
|
|
181
187
|
*/
|
|
182
|
-
signTransaction(transaction: TransactionPayload): Promise<Uint8Array | null>;
|
|
188
|
+
signTransaction(transaction: Types.TransactionPayload): Promise<Uint8Array | null>;
|
|
183
189
|
/**
|
|
184
190
|
Sign message (doesnt submit to chain).
|
|
185
191
|
@param message
|
|
@@ -202,4 +208,4 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
202
208
|
signMessageAndVerify(message: SignMessagePayload): Promise<boolean>;
|
|
203
209
|
}
|
|
204
210
|
|
|
205
|
-
export { AccountInfo, AdapterPlugin, AdapterPluginEvents, AdapterPluginProps, AptosWalletErrorResult, NetworkInfo, NetworkName, PluginProvider, SignMessagePayload, SignMessageResponse,
|
|
211
|
+
export { AccountInfo, AdapterPlugin, AdapterPluginEvents, AdapterPluginProps, AptosWalletErrorResult, NetworkInfo, NetworkName, PluginProvider, SignMessagePayload, SignMessageResponse, Wallet, WalletCore, WalletCoreEvents, WalletInfo, WalletName, WalletReadyState };
|
package/dist/index.js
CHANGED
|
@@ -304,7 +304,7 @@ var WalletCore = class extends import_eventemitter3.default {
|
|
|
304
304
|
}
|
|
305
305
|
}
|
|
306
306
|
async connect(walletName) {
|
|
307
|
-
var _a;
|
|
307
|
+
var _a, _b;
|
|
308
308
|
try {
|
|
309
309
|
const selectedWallet = (_a = this._wallets) == null ? void 0 : _a.find(
|
|
310
310
|
(wallet) => wallet.name === walletName
|
|
@@ -313,6 +313,8 @@ var WalletCore = class extends import_eventemitter3.default {
|
|
|
313
313
|
return;
|
|
314
314
|
}
|
|
315
315
|
if (this._connected) {
|
|
316
|
+
if (((_b = this.wallet) == null ? void 0 : _b.name) === walletName)
|
|
317
|
+
return;
|
|
316
318
|
await this.disconnect();
|
|
317
319
|
}
|
|
318
320
|
this._connecting = true;
|
|
@@ -356,6 +358,24 @@ var WalletCore = class extends import_eventemitter3.default {
|
|
|
356
358
|
throw new WalletSignAndSubmitMessageError(errMsg).message;
|
|
357
359
|
}
|
|
358
360
|
}
|
|
361
|
+
async signAndSubmitBCSTransaction(transaction) {
|
|
362
|
+
var _a;
|
|
363
|
+
if (this._wallet && !("signAndSubmitBCSTransaction" in this._wallet)) {
|
|
364
|
+
throw new WalletNotSupportedMethod(
|
|
365
|
+
`Submit a BCS Transaction is not supported by ${(_a = this.wallet) == null ? void 0 : _a.name}`
|
|
366
|
+
).message;
|
|
367
|
+
}
|
|
368
|
+
try {
|
|
369
|
+
this.doesWalletExist();
|
|
370
|
+
const response = await this._wallet.signAndSubmitBCSTransaction(
|
|
371
|
+
transaction
|
|
372
|
+
);
|
|
373
|
+
return response;
|
|
374
|
+
} catch (error) {
|
|
375
|
+
const errMsg = typeof error == "object" && "message" in error ? error.message : error;
|
|
376
|
+
throw new WalletSignAndSubmitMessageError(errMsg).message;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
359
379
|
async signTransaction(transaction) {
|
|
360
380
|
var _a;
|
|
361
381
|
if (this._wallet && !("signTransaction" in this._wallet)) {
|
package/dist/index.mjs
CHANGED
|
@@ -270,7 +270,7 @@ var WalletCore = class extends EventEmitter {
|
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
272
|
async connect(walletName) {
|
|
273
|
-
var _a;
|
|
273
|
+
var _a, _b;
|
|
274
274
|
try {
|
|
275
275
|
const selectedWallet = (_a = this._wallets) == null ? void 0 : _a.find(
|
|
276
276
|
(wallet) => wallet.name === walletName
|
|
@@ -279,6 +279,8 @@ var WalletCore = class extends EventEmitter {
|
|
|
279
279
|
return;
|
|
280
280
|
}
|
|
281
281
|
if (this._connected) {
|
|
282
|
+
if (((_b = this.wallet) == null ? void 0 : _b.name) === walletName)
|
|
283
|
+
return;
|
|
282
284
|
await this.disconnect();
|
|
283
285
|
}
|
|
284
286
|
this._connecting = true;
|
|
@@ -322,6 +324,24 @@ var WalletCore = class extends EventEmitter {
|
|
|
322
324
|
throw new WalletSignAndSubmitMessageError(errMsg).message;
|
|
323
325
|
}
|
|
324
326
|
}
|
|
327
|
+
async signAndSubmitBCSTransaction(transaction) {
|
|
328
|
+
var _a;
|
|
329
|
+
if (this._wallet && !("signAndSubmitBCSTransaction" in this._wallet)) {
|
|
330
|
+
throw new WalletNotSupportedMethod(
|
|
331
|
+
`Submit a BCS Transaction is not supported by ${(_a = this.wallet) == null ? void 0 : _a.name}`
|
|
332
|
+
).message;
|
|
333
|
+
}
|
|
334
|
+
try {
|
|
335
|
+
this.doesWalletExist();
|
|
336
|
+
const response = await this._wallet.signAndSubmitBCSTransaction(
|
|
337
|
+
transaction
|
|
338
|
+
);
|
|
339
|
+
return response;
|
|
340
|
+
} catch (error) {
|
|
341
|
+
const errMsg = typeof error == "object" && "message" in error ? error.message : error;
|
|
342
|
+
throw new WalletSignAndSubmitMessageError(errMsg).message;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
325
345
|
async signTransaction(transaction) {
|
|
326
346
|
var _a;
|
|
327
347
|
if (this._wallet && !("signTransaction" in this._wallet)) {
|
package/package.json
CHANGED
package/src/WalletCore.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HexString } from "aptos";
|
|
1
|
+
import { HexString, TxnBuilderTypes, Types } from "aptos";
|
|
2
2
|
import EventEmitter from "eventemitter3";
|
|
3
3
|
import nacl from "tweetnacl";
|
|
4
4
|
import { Buffer } from "buffer";
|
|
@@ -29,7 +29,6 @@ import {
|
|
|
29
29
|
Wallet,
|
|
30
30
|
WalletInfo,
|
|
31
31
|
WalletCoreEvents,
|
|
32
|
-
TransactionPayload,
|
|
33
32
|
} from "./types";
|
|
34
33
|
import {
|
|
35
34
|
removeLocalStorage,
|
|
@@ -196,6 +195,9 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
196
195
|
}
|
|
197
196
|
|
|
198
197
|
if (this._connected) {
|
|
198
|
+
// if the selected wallet is already connected, we don't need to connect again
|
|
199
|
+
if (this.wallet?.name === walletName) return;
|
|
200
|
+
|
|
199
201
|
await this.disconnect();
|
|
200
202
|
}
|
|
201
203
|
this._connecting = true;
|
|
@@ -234,13 +236,13 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
234
236
|
}
|
|
235
237
|
|
|
236
238
|
/**
|
|
237
|
-
Sign and submit transaction to chain.
|
|
238
|
-
@param transaction
|
|
239
|
+
Sign and submit an entry (not bcs serialized) transaction type to chain.
|
|
240
|
+
@param transaction a non-bcs serialized transaction
|
|
239
241
|
@return response from the wallet's signAndSubmitTransaction function
|
|
240
242
|
@throws WalletSignAndSubmitMessageError
|
|
241
243
|
*/
|
|
242
244
|
async signAndSubmitTransaction(
|
|
243
|
-
transaction: TransactionPayload
|
|
245
|
+
transaction: Types.TransactionPayload
|
|
244
246
|
): Promise<any> {
|
|
245
247
|
try {
|
|
246
248
|
this.doesWalletExist();
|
|
@@ -255,6 +257,34 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
255
257
|
}
|
|
256
258
|
}
|
|
257
259
|
|
|
260
|
+
/**
|
|
261
|
+
Sign and submit a bsc serialized transaction type to chain.
|
|
262
|
+
@param transaction a bcs serialized transaction
|
|
263
|
+
@return response from the wallet's signAndSubmitBCSTransaction function
|
|
264
|
+
@throws WalletSignAndSubmitMessageError
|
|
265
|
+
*/
|
|
266
|
+
async signAndSubmitBCSTransaction(
|
|
267
|
+
transaction: TxnBuilderTypes.TransactionPayload
|
|
268
|
+
): Promise<any> {
|
|
269
|
+
if (this._wallet && !("signAndSubmitBCSTransaction" in this._wallet)) {
|
|
270
|
+
throw new WalletNotSupportedMethod(
|
|
271
|
+
`Submit a BCS Transaction is not supported by ${this.wallet?.name}`
|
|
272
|
+
).message;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
try {
|
|
276
|
+
this.doesWalletExist();
|
|
277
|
+
const response = await (this._wallet as any).signAndSubmitBCSTransaction(
|
|
278
|
+
transaction
|
|
279
|
+
);
|
|
280
|
+
return response;
|
|
281
|
+
} catch (error: any) {
|
|
282
|
+
const errMsg =
|
|
283
|
+
typeof error == "object" && "message" in error ? error.message : error;
|
|
284
|
+
throw new WalletSignAndSubmitMessageError(errMsg).message;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
258
288
|
/**
|
|
259
289
|
Sign transaction (doesnt submit to chain).
|
|
260
290
|
@param transaction
|
|
@@ -262,7 +292,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
262
292
|
@throws WalletSignTransactionError
|
|
263
293
|
*/
|
|
264
294
|
async signTransaction(
|
|
265
|
-
transaction: TransactionPayload
|
|
295
|
+
transaction: Types.TransactionPayload
|
|
266
296
|
): Promise<Uint8Array | null> {
|
|
267
297
|
if (this._wallet && !("signTransaction" in this._wallet)) {
|
|
268
298
|
throw new WalletNotSupportedMethod(
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Types } from "aptos";
|
|
2
2
|
import { NetworkName, WalletReadyState } from "./constants";
|
|
3
3
|
|
|
4
4
|
// WalletName is a nominal type that wallet adapters should use, e.g. `'MyCryptoWallet' as WalletName<'MyCryptoWallet'>`
|
|
@@ -23,6 +23,7 @@ export interface AptosWalletErrorResult {
|
|
|
23
23
|
name: string;
|
|
24
24
|
message: string;
|
|
25
25
|
}
|
|
26
|
+
|
|
26
27
|
export interface PluginProvider {
|
|
27
28
|
connect: () => Promise<AccountInfo>;
|
|
28
29
|
account: () => Promise<AccountInfo>;
|
|
@@ -46,10 +47,6 @@ export interface AdapterPluginEvents {
|
|
|
46
47
|
onAccountChange(callback: any): Promise<any>;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
export type TransactionPayload =
|
|
50
|
-
| Types.TransactionPayload
|
|
51
|
-
| TxnBuilderTypes.TransactionPayload;
|
|
52
|
-
|
|
53
50
|
export interface AdapterPluginProps<Name extends string = string> {
|
|
54
51
|
name: WalletName<Name>;
|
|
55
52
|
url: string;
|
|
@@ -59,7 +56,7 @@ export interface AdapterPluginProps<Name extends string = string> {
|
|
|
59
56
|
connect(): Promise<any>;
|
|
60
57
|
disconnect: () => Promise<any>;
|
|
61
58
|
network: () => Promise<any>;
|
|
62
|
-
signAndSubmitTransaction<T extends TransactionPayload, V>(
|
|
59
|
+
signAndSubmitTransaction<T extends Types.TransactionPayload, V>(
|
|
63
60
|
transaction: T,
|
|
64
61
|
options?: V
|
|
65
62
|
): Promise<{ hash: Types.HexEncodedBytes }>;
|