@aptos-labs/wallet-adapter-core 2.0.1 → 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 +10 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.js +21 -1
- package/dist/index.mjs +21 -1
- package/package.json +12 -12
- package/src/WalletCore.ts +34 -3
- package/dist/index.global.js +0 -93
- package/dist/index.global.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @aptos-labs/wallet-adapter-core
|
|
2
2
|
|
|
3
|
+
## 2.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 50968c4: Support to submit bcs serialized transactions
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 8dea640: Fix wallet adapter auto reconnect on page refresh
|
|
12
|
+
|
|
3
13
|
## 1.0.0
|
|
4
14
|
|
|
5
15
|
### Major Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Types } from 'aptos';
|
|
1
|
+
import { Types, TxnBuilderTypes } from 'aptos';
|
|
2
2
|
import EventEmitter from 'eventemitter3';
|
|
3
3
|
|
|
4
4
|
declare enum WalletReadyState {
|
|
@@ -166,13 +166,20 @@ declare class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
166
166
|
*/
|
|
167
167
|
disconnect(): Promise<void>;
|
|
168
168
|
/**
|
|
169
|
-
Sign and submit transaction to chain.
|
|
170
|
-
@param transaction
|
|
169
|
+
Sign and submit an entry (not bcs serialized) transaction type to chain.
|
|
170
|
+
@param transaction a non-bcs serialized transaction
|
|
171
171
|
@return response from the wallet's signAndSubmitTransaction function
|
|
172
172
|
@throws WalletSignAndSubmitMessageError
|
|
173
173
|
*/
|
|
174
174
|
signAndSubmitTransaction(transaction: Types.TransactionPayload): Promise<any>;
|
|
175
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>;
|
|
182
|
+
/**
|
|
176
183
|
Sign transaction (doesnt submit to chain).
|
|
177
184
|
@param transaction
|
|
178
185
|
@return response from the wallet's signTransaction function
|
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aptos-labs/wallet-adapter-core",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Aptos Wallet Adapter Core",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -27,27 +27,27 @@
|
|
|
27
27
|
"Wallet Adapter",
|
|
28
28
|
"Aptos Wallet"
|
|
29
29
|
],
|
|
30
|
-
"scripts": {
|
|
31
|
-
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
32
|
-
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
|
|
33
|
-
"test": "jest",
|
|
34
|
-
"lint": "TIMING=1 eslint \"src/**/*.ts*\"",
|
|
35
|
-
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
36
|
-
},
|
|
37
30
|
"devDependencies": {
|
|
38
|
-
"@aptos-labs/eslint-config-adapter": "workspace:*",
|
|
39
|
-
"@aptos-labs/wallet-adapter-tsconfig": "workspace:*",
|
|
40
31
|
"@types/jest": "^29.2.4",
|
|
41
32
|
"eslint": "^8.15.0",
|
|
42
33
|
"jest": "^29.3.1",
|
|
43
34
|
"ts-jest": "^29.0.3",
|
|
44
35
|
"tsup": "^5.10.1",
|
|
45
|
-
"typescript": "^4.5.3"
|
|
36
|
+
"typescript": "^4.5.3",
|
|
37
|
+
"@aptos-labs/eslint-config-adapter": "0.0.0",
|
|
38
|
+
"@aptos-labs/wallet-adapter-tsconfig": "0.0.0"
|
|
46
39
|
},
|
|
47
40
|
"dependencies": {
|
|
48
41
|
"aptos": "^1.3.17",
|
|
49
42
|
"buffer": "^6.0.3",
|
|
50
43
|
"eventemitter3": "^4.0.7",
|
|
51
44
|
"tweetnacl": "^1.0.3"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
48
|
+
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
|
|
49
|
+
"test": "jest",
|
|
50
|
+
"lint": "TIMING=1 eslint \"src/**/*.ts*\"",
|
|
51
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
52
52
|
}
|
|
53
|
-
}
|
|
53
|
+
}
|
package/src/WalletCore.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HexString, Types } 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";
|
|
@@ -195,6 +195,9 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
195
195
|
}
|
|
196
196
|
|
|
197
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
|
+
|
|
198
201
|
await this.disconnect();
|
|
199
202
|
}
|
|
200
203
|
this._connecting = true;
|
|
@@ -233,8 +236,8 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
233
236
|
}
|
|
234
237
|
|
|
235
238
|
/**
|
|
236
|
-
Sign and submit transaction to chain.
|
|
237
|
-
@param transaction
|
|
239
|
+
Sign and submit an entry (not bcs serialized) transaction type to chain.
|
|
240
|
+
@param transaction a non-bcs serialized transaction
|
|
238
241
|
@return response from the wallet's signAndSubmitTransaction function
|
|
239
242
|
@throws WalletSignAndSubmitMessageError
|
|
240
243
|
*/
|
|
@@ -254,6 +257,34 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
254
257
|
}
|
|
255
258
|
}
|
|
256
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
|
+
|
|
257
288
|
/**
|
|
258
289
|
Sign transaction (doesnt submit to chain).
|
|
259
290
|
@param transaction
|