@aptos-labs/wallet-adapter-core 0.1.4 → 0.1.6
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/package.json +11 -11
- package/src/WalletCore.ts +60 -1
- package/.eslintrc.js +0 -4
- package/dist/index.d.ts +0 -137
- package/dist/index.js +0 -362
- package/dist/index.mjs +0 -333
- package/tsconfig.json +0 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aptos-labs/wallet-adapter-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Aptos Wallet Adapter Core",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -27,21 +27,21 @@
|
|
|
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
|
+
"lint": "TIMING=1 eslint \"src/**/*.ts*\"",
|
|
34
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
35
|
+
},
|
|
30
36
|
"devDependencies": {
|
|
37
|
+
"@aptos-labs/wallet-adapter-tsconfig": "workspace:*",
|
|
31
38
|
"eslint": "^8.15.0",
|
|
39
|
+
"@aptos-labs/eslint-config-adapter": "workspace:*",
|
|
32
40
|
"tsup": "^5.10.1",
|
|
33
|
-
"typescript": "^4.5.3"
|
|
34
|
-
"@aptos-labs/wallet-adapter-tsconfig": "0.0.0",
|
|
35
|
-
"@aptos-labs/eslint-config-adapter": "0.0.0"
|
|
41
|
+
"typescript": "^4.5.3"
|
|
36
42
|
},
|
|
37
43
|
"dependencies": {
|
|
38
44
|
"aptos": "^1.3.17",
|
|
39
45
|
"eventemitter3": "^4.0.7"
|
|
40
|
-
},
|
|
41
|
-
"scripts": {
|
|
42
|
-
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
43
|
-
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
|
|
44
|
-
"lint": "TIMING=1 eslint \"src/**/*.ts*\"",
|
|
45
|
-
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
46
46
|
}
|
|
47
|
-
}
|
|
47
|
+
}
|
package/src/WalletCore.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Types } from "aptos";
|
|
2
|
-
import
|
|
2
|
+
import EventEmitter from "eventemitter3";
|
|
3
3
|
|
|
4
4
|
import { WalletReadyState } from "./constants";
|
|
5
5
|
import {
|
|
@@ -108,6 +108,11 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
108
108
|
return this._wallets;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Getter for the current connected wallet
|
|
113
|
+
* @return wallet info
|
|
114
|
+
* @throws WalletNotSelectedError
|
|
115
|
+
*/
|
|
111
116
|
get wallet(): WalletInfo | null {
|
|
112
117
|
try {
|
|
113
118
|
if (!this._wallet) return null;
|
|
@@ -121,6 +126,11 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
121
126
|
}
|
|
122
127
|
}
|
|
123
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Getter for the current connected account
|
|
131
|
+
* @return account info
|
|
132
|
+
* @throws WalletAccountError
|
|
133
|
+
*/
|
|
124
134
|
get account(): AccountInfo | null {
|
|
125
135
|
try {
|
|
126
136
|
return this._account;
|
|
@@ -129,6 +139,11 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
129
139
|
}
|
|
130
140
|
}
|
|
131
141
|
|
|
142
|
+
/**
|
|
143
|
+
* Getter for the current wallet network
|
|
144
|
+
* @return network info
|
|
145
|
+
* @throws WalletGetNetworkError
|
|
146
|
+
*/
|
|
132
147
|
get network(): NetworkInfo | null {
|
|
133
148
|
try {
|
|
134
149
|
return this._network;
|
|
@@ -137,6 +152,16 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
137
152
|
}
|
|
138
153
|
}
|
|
139
154
|
|
|
155
|
+
/**
|
|
156
|
+
Connects a wallet to the app. If a wallet is already connected,
|
|
157
|
+
we first disconnect the current connected wallet and then connect the selected wallet.
|
|
158
|
+
On connect success, we set the current account and the network, and keeping the selected wallet
|
|
159
|
+
name in LocalStorage to support autoConnect function.
|
|
160
|
+
|
|
161
|
+
@param walletName. The wallet name we want to connect as a WalletName type.
|
|
162
|
+
@emit emits "connect" event
|
|
163
|
+
@throws WalletConnectionError
|
|
164
|
+
*/
|
|
140
165
|
async connect(walletName: WalletName): Promise<void> {
|
|
141
166
|
try {
|
|
142
167
|
const selectedWallet = this._wallets?.find(
|
|
@@ -164,6 +189,12 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
164
189
|
}
|
|
165
190
|
}
|
|
166
191
|
|
|
192
|
+
/**
|
|
193
|
+
Disconnect the exisitng wallet. On success, we clear the
|
|
194
|
+
current account, current network and LocalStorage data.
|
|
195
|
+
@emit emits "disconnect" event
|
|
196
|
+
@throws WalletDisconnectionError
|
|
197
|
+
*/
|
|
167
198
|
async disconnect(): Promise<void> {
|
|
168
199
|
try {
|
|
169
200
|
this.isWalletExists();
|
|
@@ -175,6 +206,12 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
175
206
|
}
|
|
176
207
|
}
|
|
177
208
|
|
|
209
|
+
/**
|
|
210
|
+
Sign and submit transaction to chain.
|
|
211
|
+
@param transaction
|
|
212
|
+
@return response from the wallet's signAndSubmitTransaction function
|
|
213
|
+
@throws WalletSignAndSubmitMessageError
|
|
214
|
+
*/
|
|
178
215
|
async signAndSubmitTransaction(
|
|
179
216
|
transaction: Types.TransactionPayload
|
|
180
217
|
): Promise<any> {
|
|
@@ -191,6 +228,12 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
191
228
|
}
|
|
192
229
|
}
|
|
193
230
|
|
|
231
|
+
/**
|
|
232
|
+
Sign transaction (doesnt submit to chain).
|
|
233
|
+
@param transaction
|
|
234
|
+
@return response from the wallet's signTransaction function
|
|
235
|
+
@throws WalletSignTransactionError
|
|
236
|
+
*/
|
|
194
237
|
async signTransaction(
|
|
195
238
|
transaction: Types.TransactionPayload
|
|
196
239
|
): Promise<Uint8Array | null> {
|
|
@@ -206,6 +249,12 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
206
249
|
}
|
|
207
250
|
}
|
|
208
251
|
|
|
252
|
+
/**
|
|
253
|
+
Sign message (doesnt submit to chain).
|
|
254
|
+
@param message
|
|
255
|
+
@return response from the wallet's signMessage function
|
|
256
|
+
@throws WalletSignMessageError
|
|
257
|
+
*/
|
|
209
258
|
async signMessage(
|
|
210
259
|
message: SignMessagePayload
|
|
211
260
|
): Promise<SignMessageResponse | null> {
|
|
@@ -221,6 +270,11 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
221
270
|
}
|
|
222
271
|
}
|
|
223
272
|
|
|
273
|
+
/**
|
|
274
|
+
Event for when account has changed on the wallet
|
|
275
|
+
@return the new account info
|
|
276
|
+
@throws WalletAccountChangeError
|
|
277
|
+
*/
|
|
224
278
|
async onAccountChange(): Promise<void> {
|
|
225
279
|
try {
|
|
226
280
|
this.isWalletExists();
|
|
@@ -235,6 +289,11 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
|
235
289
|
}
|
|
236
290
|
}
|
|
237
291
|
|
|
292
|
+
/**
|
|
293
|
+
Event for when network has changed on the wallet
|
|
294
|
+
@return the new network info
|
|
295
|
+
@throws WalletNetworkChangeError
|
|
296
|
+
*/
|
|
238
297
|
async onNetworkChange(): Promise<void> {
|
|
239
298
|
try {
|
|
240
299
|
this.isWalletExists();
|
package/.eslintrc.js
DELETED
package/dist/index.d.ts
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { Types } from 'aptos';
|
|
2
|
-
import { EventEmitter } from 'eventemitter3';
|
|
3
|
-
|
|
4
|
-
declare enum WalletReadyState {
|
|
5
|
-
/**
|
|
6
|
-
* User-installable wallets can typically be detected by scanning for an API
|
|
7
|
-
* that they've injected into the global context. If such an API is present,
|
|
8
|
-
* we consider the wallet to have been installed.
|
|
9
|
-
*/
|
|
10
|
-
Installed = "Installed",
|
|
11
|
-
NotDetected = "NotDetected",
|
|
12
|
-
/**
|
|
13
|
-
* Loadable wallets are always available to you. Since you can load them at
|
|
14
|
-
* any time, it's meaningless to say that they have been detected.
|
|
15
|
-
*/
|
|
16
|
-
Loadable = "Loadable",
|
|
17
|
-
/**
|
|
18
|
-
* If a wallet is not supported on a given platform (eg. server-rendering, or
|
|
19
|
-
* mobile) then it will stay in the `Unsupported` state.
|
|
20
|
-
*/
|
|
21
|
-
Unsupported = "Unsupported"
|
|
22
|
-
}
|
|
23
|
-
declare enum NetworkName {
|
|
24
|
-
Mainnet = "mainnet",
|
|
25
|
-
Testnet = "testnet",
|
|
26
|
-
Devnet = "devnet"
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
declare type WalletName<T extends string = string> = T & {
|
|
30
|
-
__brand__: "WalletName";
|
|
31
|
-
};
|
|
32
|
-
declare type NetworkInfo = {
|
|
33
|
-
name: NetworkName | undefined;
|
|
34
|
-
};
|
|
35
|
-
declare type AccountInfo = {
|
|
36
|
-
address: string;
|
|
37
|
-
publicKey: string;
|
|
38
|
-
};
|
|
39
|
-
interface AptosWalletErrorResult {
|
|
40
|
-
code: number;
|
|
41
|
-
name: string;
|
|
42
|
-
message: string;
|
|
43
|
-
}
|
|
44
|
-
interface PluginProvider {
|
|
45
|
-
connect: () => Promise<AccountInfo>;
|
|
46
|
-
account: () => Promise<AccountInfo>;
|
|
47
|
-
disconnect: () => Promise<void>;
|
|
48
|
-
signAndSubmitTransaction: (transaction: any, options?: any) => Promise<{
|
|
49
|
-
hash: Types.HexEncodedBytes;
|
|
50
|
-
} | AptosWalletErrorResult>;
|
|
51
|
-
signMessage: (message: SignMessagePayload) => Promise<SignMessageResponse>;
|
|
52
|
-
network: () => Promise<NetworkName>;
|
|
53
|
-
onAccountChange: (listener: (newAddress: AccountInfo) => Promise<void>) => Promise<void>;
|
|
54
|
-
onNetworkChange: (listener: (network: {
|
|
55
|
-
networkName: NetworkInfo;
|
|
56
|
-
}) => Promise<void>) => Promise<void>;
|
|
57
|
-
}
|
|
58
|
-
interface AdapterPluginEvents {
|
|
59
|
-
onNetworkChange(callback: any): Promise<any>;
|
|
60
|
-
onAccountChange(callback: any): Promise<any>;
|
|
61
|
-
}
|
|
62
|
-
interface AdapterPluginProps<Name extends string = string> {
|
|
63
|
-
name: WalletName<Name>;
|
|
64
|
-
url: string;
|
|
65
|
-
icon: `data:image/${"svg+xml" | "webp" | "png" | "gif"};base64,${string}`;
|
|
66
|
-
provider: any;
|
|
67
|
-
connect(): Promise<any>;
|
|
68
|
-
disconnect: () => Promise<any>;
|
|
69
|
-
network: () => Promise<any>;
|
|
70
|
-
signAndSubmitTransaction<T extends Types.TransactionPayload, V>(transaction: T, options?: V): Promise<{
|
|
71
|
-
hash: Types.HexEncodedBytes;
|
|
72
|
-
}>;
|
|
73
|
-
signMessage<T extends SignMessagePayload>(message: T): Promise<SignMessageResponse>;
|
|
74
|
-
}
|
|
75
|
-
declare type AdapterPlugin<Name extends string = string> = AdapterPluginProps<Name> & AdapterPluginEvents;
|
|
76
|
-
declare type Wallet<Name extends string = string> = AdapterPlugin<Name> & {
|
|
77
|
-
readyState?: WalletReadyState;
|
|
78
|
-
};
|
|
79
|
-
declare type WalletInfo = {
|
|
80
|
-
name: WalletName;
|
|
81
|
-
icon: string;
|
|
82
|
-
url: string;
|
|
83
|
-
};
|
|
84
|
-
declare interface WalletCoreEvents {
|
|
85
|
-
connect(account: AccountInfo | null): void;
|
|
86
|
-
disconnect(): void;
|
|
87
|
-
readyStateChange(wallet: Wallet): void;
|
|
88
|
-
networkChange(network: NetworkInfo | null): void;
|
|
89
|
-
accountChange(account: AccountInfo | null): void;
|
|
90
|
-
}
|
|
91
|
-
interface SignMessagePayload {
|
|
92
|
-
address?: boolean;
|
|
93
|
-
application?: boolean;
|
|
94
|
-
chainId?: boolean;
|
|
95
|
-
message: string;
|
|
96
|
-
nonce: string;
|
|
97
|
-
}
|
|
98
|
-
interface SignMessageResponse {
|
|
99
|
-
address: string;
|
|
100
|
-
application: string;
|
|
101
|
-
chainId: number;
|
|
102
|
-
fullMessage: string;
|
|
103
|
-
message: string;
|
|
104
|
-
nonce: string;
|
|
105
|
-
prefix: "APTOS";
|
|
106
|
-
signature: string;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
declare class WalletCore extends EventEmitter<WalletCoreEvents> {
|
|
110
|
-
private _wallets;
|
|
111
|
-
private _wallet;
|
|
112
|
-
private _account;
|
|
113
|
-
private _network;
|
|
114
|
-
private _connecting;
|
|
115
|
-
private _connected;
|
|
116
|
-
constructor(plugins: Wallet[]);
|
|
117
|
-
private scopePollingDetectionStrategy;
|
|
118
|
-
private isWalletExists;
|
|
119
|
-
private clearData;
|
|
120
|
-
setWallet(wallet: Wallet | null): void;
|
|
121
|
-
setAccount(account: AccountInfo | null): void;
|
|
122
|
-
setNetwork(network: NetworkInfo | null): void;
|
|
123
|
-
isConnected(): boolean;
|
|
124
|
-
get wallets(): Wallet[];
|
|
125
|
-
get wallet(): WalletInfo | null;
|
|
126
|
-
get account(): AccountInfo | null;
|
|
127
|
-
get network(): NetworkInfo | null;
|
|
128
|
-
connect(walletName: WalletName): Promise<void>;
|
|
129
|
-
disconnect(): Promise<void>;
|
|
130
|
-
signAndSubmitTransaction(transaction: Types.TransactionPayload): Promise<any>;
|
|
131
|
-
signTransaction(transaction: Types.TransactionPayload): Promise<Uint8Array | null>;
|
|
132
|
-
signMessage(message: SignMessagePayload): Promise<SignMessageResponse | null>;
|
|
133
|
-
onAccountChange(): Promise<void>;
|
|
134
|
-
onNetworkChange(): Promise<void>;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export { AccountInfo, AdapterPlugin, AdapterPluginEvents, AdapterPluginProps, AptosWalletErrorResult, NetworkInfo, NetworkName, PluginProvider, SignMessagePayload, SignMessageResponse, Wallet, WalletCore, WalletCoreEvents, WalletInfo, WalletName, WalletReadyState };
|
package/dist/index.js
DELETED
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
NetworkName: () => NetworkName,
|
|
24
|
-
WalletCore: () => WalletCore,
|
|
25
|
-
WalletReadyState: () => WalletReadyState
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(src_exports);
|
|
28
|
-
|
|
29
|
-
// src/WalletCore.ts
|
|
30
|
-
var import_eventemitter3 = require("eventemitter3");
|
|
31
|
-
|
|
32
|
-
// src/constants.ts
|
|
33
|
-
var WalletReadyState = /* @__PURE__ */ ((WalletReadyState2) => {
|
|
34
|
-
WalletReadyState2["Installed"] = "Installed";
|
|
35
|
-
WalletReadyState2["NotDetected"] = "NotDetected";
|
|
36
|
-
WalletReadyState2["Loadable"] = "Loadable";
|
|
37
|
-
WalletReadyState2["Unsupported"] = "Unsupported";
|
|
38
|
-
return WalletReadyState2;
|
|
39
|
-
})(WalletReadyState || {});
|
|
40
|
-
var NetworkName = /* @__PURE__ */ ((NetworkName2) => {
|
|
41
|
-
NetworkName2["Mainnet"] = "mainnet";
|
|
42
|
-
NetworkName2["Testnet"] = "testnet";
|
|
43
|
-
NetworkName2["Devnet"] = "devnet";
|
|
44
|
-
return NetworkName2;
|
|
45
|
-
})(NetworkName || {});
|
|
46
|
-
|
|
47
|
-
// src/error/index.ts
|
|
48
|
-
var WalletError = class extends Error {
|
|
49
|
-
constructor(message, error) {
|
|
50
|
-
super(message);
|
|
51
|
-
this.error = error;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
var WalletNotSelectedError = class extends WalletError {
|
|
55
|
-
constructor() {
|
|
56
|
-
super(...arguments);
|
|
57
|
-
this.name = "WalletNotSelectedError";
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
var WalletNotReadyError = class extends WalletError {
|
|
61
|
-
constructor() {
|
|
62
|
-
super(...arguments);
|
|
63
|
-
this.name = "WalletNotReadyError";
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
var WalletConnectionError = class extends WalletError {
|
|
67
|
-
constructor() {
|
|
68
|
-
super(...arguments);
|
|
69
|
-
this.name = "WalletConnectionError";
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
var WalletDisconnectionError = class extends WalletError {
|
|
73
|
-
constructor() {
|
|
74
|
-
super(...arguments);
|
|
75
|
-
this.name = "WalletDisconnectionError";
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
var WalletAccountError = class extends WalletError {
|
|
79
|
-
constructor() {
|
|
80
|
-
super(...arguments);
|
|
81
|
-
this.name = "WalletAccountError";
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
var WalletGetNetworkError = class extends WalletError {
|
|
85
|
-
constructor() {
|
|
86
|
-
super(...arguments);
|
|
87
|
-
this.name = "WalletGetNetworkError";
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
var WalletAccountChangeError = class extends WalletError {
|
|
91
|
-
constructor() {
|
|
92
|
-
super(...arguments);
|
|
93
|
-
this.name = "WalletAccountChangeError";
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
var WalletNetworkChangeError = class extends WalletError {
|
|
97
|
-
constructor() {
|
|
98
|
-
super(...arguments);
|
|
99
|
-
this.name = "WalletNetworkChangeError";
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
var WalletNotConnectedError = class extends WalletError {
|
|
103
|
-
constructor() {
|
|
104
|
-
super(...arguments);
|
|
105
|
-
this.name = "WalletNotConnectedError";
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
var WalletSignMessageError = class extends WalletError {
|
|
109
|
-
constructor() {
|
|
110
|
-
super(...arguments);
|
|
111
|
-
this.name = "WalletSignMessageError";
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
var WalletSignAndSubmitMessageError = class extends WalletError {
|
|
115
|
-
constructor() {
|
|
116
|
-
super(...arguments);
|
|
117
|
-
this.name = "WalletSignAndSubmitMessageError";
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
var WalletSignTransactionError = class extends WalletError {
|
|
121
|
-
constructor() {
|
|
122
|
-
super(...arguments);
|
|
123
|
-
this.name = "WalletSignTransactionError";
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
// src/utils/scopePollingDetectionStrategy.ts
|
|
128
|
-
function scopePollingDetectionStrategy(detect) {
|
|
129
|
-
if (typeof window === "undefined" || typeof document === "undefined")
|
|
130
|
-
return;
|
|
131
|
-
const disposers = [];
|
|
132
|
-
function detectAndDispose() {
|
|
133
|
-
const detected = detect();
|
|
134
|
-
if (detected) {
|
|
135
|
-
for (const dispose of disposers) {
|
|
136
|
-
dispose();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
const interval = setInterval(detectAndDispose, 1e3);
|
|
141
|
-
disposers.push(() => clearInterval(interval));
|
|
142
|
-
if (document.readyState === "loading") {
|
|
143
|
-
document.addEventListener("DOMContentLoaded", detectAndDispose, {
|
|
144
|
-
once: true
|
|
145
|
-
});
|
|
146
|
-
disposers.push(
|
|
147
|
-
() => document.removeEventListener("DOMContentLoaded", detectAndDispose)
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
if (document.readyState !== "complete") {
|
|
151
|
-
window.addEventListener("load", detectAndDispose, { once: true });
|
|
152
|
-
disposers.push(() => window.removeEventListener("load", detectAndDispose));
|
|
153
|
-
}
|
|
154
|
-
detectAndDispose();
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// src/utils/localStorage.ts
|
|
158
|
-
var LOCAL_STORAGE_ITEM_KEY = "AptosWalletName";
|
|
159
|
-
function setLocalStorage(walletName) {
|
|
160
|
-
localStorage.setItem(LOCAL_STORAGE_ITEM_KEY, walletName);
|
|
161
|
-
}
|
|
162
|
-
function removeLocalStorage() {
|
|
163
|
-
localStorage.removeItem(LOCAL_STORAGE_ITEM_KEY);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// src/WalletCore.ts
|
|
167
|
-
var WalletCore = class extends import_eventemitter3.EventEmitter {
|
|
168
|
-
constructor(plugins) {
|
|
169
|
-
super();
|
|
170
|
-
this._wallets = [];
|
|
171
|
-
this._wallet = null;
|
|
172
|
-
this._account = null;
|
|
173
|
-
this._network = null;
|
|
174
|
-
this._connecting = false;
|
|
175
|
-
this._connected = false;
|
|
176
|
-
this._wallets = plugins;
|
|
177
|
-
this.scopePollingDetectionStrategy();
|
|
178
|
-
}
|
|
179
|
-
scopePollingDetectionStrategy() {
|
|
180
|
-
var _a;
|
|
181
|
-
(_a = this._wallets) == null ? void 0 : _a.forEach((wallet) => {
|
|
182
|
-
wallet.readyState = typeof window === "undefined" || typeof document === "undefined" ? "Unsupported" /* Unsupported */ : "NotDetected" /* NotDetected */;
|
|
183
|
-
if (typeof window !== "undefined") {
|
|
184
|
-
scopePollingDetectionStrategy(() => {
|
|
185
|
-
if (Object.keys(window).includes(wallet.name.toLowerCase())) {
|
|
186
|
-
wallet.readyState = "Installed" /* Installed */;
|
|
187
|
-
wallet.provider = window[wallet.name.toLowerCase()];
|
|
188
|
-
this.emit("readyStateChange", wallet);
|
|
189
|
-
return true;
|
|
190
|
-
}
|
|
191
|
-
return false;
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
isWalletExists() {
|
|
197
|
-
if (!this._connected || this._connecting || !this._wallet)
|
|
198
|
-
throw new WalletNotConnectedError().name;
|
|
199
|
-
if (!(this._wallet.readyState === "Loadable" /* Loadable */ || this._wallet.readyState === "Installed" /* Installed */))
|
|
200
|
-
throw new WalletNotReadyError().name;
|
|
201
|
-
return true;
|
|
202
|
-
}
|
|
203
|
-
clearData() {
|
|
204
|
-
this._connected = false;
|
|
205
|
-
this.setWallet(null);
|
|
206
|
-
this.setAccount(null);
|
|
207
|
-
this.setNetwork(null);
|
|
208
|
-
removeLocalStorage();
|
|
209
|
-
}
|
|
210
|
-
setWallet(wallet) {
|
|
211
|
-
this._wallet = wallet;
|
|
212
|
-
}
|
|
213
|
-
setAccount(account) {
|
|
214
|
-
this._account = account;
|
|
215
|
-
}
|
|
216
|
-
setNetwork(network) {
|
|
217
|
-
this._network = network;
|
|
218
|
-
}
|
|
219
|
-
isConnected() {
|
|
220
|
-
return this._connected;
|
|
221
|
-
}
|
|
222
|
-
get wallets() {
|
|
223
|
-
return this._wallets;
|
|
224
|
-
}
|
|
225
|
-
get wallet() {
|
|
226
|
-
try {
|
|
227
|
-
if (!this._wallet)
|
|
228
|
-
return null;
|
|
229
|
-
return {
|
|
230
|
-
name: this._wallet.name,
|
|
231
|
-
icon: this._wallet.icon,
|
|
232
|
-
url: this._wallet.url
|
|
233
|
-
};
|
|
234
|
-
} catch (error) {
|
|
235
|
-
throw new WalletNotSelectedError(error).message;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
get account() {
|
|
239
|
-
try {
|
|
240
|
-
return this._account;
|
|
241
|
-
} catch (error) {
|
|
242
|
-
throw new WalletAccountError(error).message;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
get network() {
|
|
246
|
-
try {
|
|
247
|
-
return this._network;
|
|
248
|
-
} catch (error) {
|
|
249
|
-
throw new WalletGetNetworkError(error).message;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
async connect(walletName) {
|
|
253
|
-
var _a;
|
|
254
|
-
try {
|
|
255
|
-
const selectedWallet = (_a = this._wallets) == null ? void 0 : _a.find(
|
|
256
|
-
(wallet) => wallet.name === walletName
|
|
257
|
-
);
|
|
258
|
-
if (!selectedWallet)
|
|
259
|
-
return;
|
|
260
|
-
if (selectedWallet.readyState !== "Installed" /* Installed */)
|
|
261
|
-
return;
|
|
262
|
-
if (this._connected) {
|
|
263
|
-
await this.disconnect();
|
|
264
|
-
}
|
|
265
|
-
this._connecting = true;
|
|
266
|
-
this.setWallet(selectedWallet);
|
|
267
|
-
const account = await selectedWallet.connect();
|
|
268
|
-
this.setAccount({ ...account });
|
|
269
|
-
const network = await selectedWallet.network();
|
|
270
|
-
this.setNetwork({ ...network });
|
|
271
|
-
setLocalStorage(selectedWallet.name);
|
|
272
|
-
this._connected = true;
|
|
273
|
-
this.emit("connect", account);
|
|
274
|
-
} catch (error) {
|
|
275
|
-
this.clearData();
|
|
276
|
-
throw new WalletConnectionError(error).message;
|
|
277
|
-
} finally {
|
|
278
|
-
this._connecting = false;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
async disconnect() {
|
|
282
|
-
var _a;
|
|
283
|
-
try {
|
|
284
|
-
this.isWalletExists();
|
|
285
|
-
await ((_a = this._wallet) == null ? void 0 : _a.disconnect());
|
|
286
|
-
this.clearData();
|
|
287
|
-
this.emit("disconnect");
|
|
288
|
-
} catch (error) {
|
|
289
|
-
throw new WalletDisconnectionError(error).message;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
async signAndSubmitTransaction(transaction) {
|
|
293
|
-
var _a;
|
|
294
|
-
try {
|
|
295
|
-
this.isWalletExists();
|
|
296
|
-
const response = await ((_a = this._wallet) == null ? void 0 : _a.signAndSubmitTransaction(
|
|
297
|
-
transaction
|
|
298
|
-
));
|
|
299
|
-
return response;
|
|
300
|
-
} catch (error) {
|
|
301
|
-
const errMsg = typeof error == "object" && "message" in error ? error.message : error;
|
|
302
|
-
throw new WalletSignAndSubmitMessageError(errMsg).message;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
async signTransaction(transaction) {
|
|
306
|
-
try {
|
|
307
|
-
if (this._wallet && !("signTransaction" in this._wallet))
|
|
308
|
-
return null;
|
|
309
|
-
this.isWalletExists();
|
|
310
|
-
const response = await this._wallet.signTransaction(transaction);
|
|
311
|
-
return response;
|
|
312
|
-
} catch (error) {
|
|
313
|
-
const errMsg = typeof error == "object" && "message" in error ? error.message : error;
|
|
314
|
-
throw new WalletSignTransactionError(errMsg).message;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
async signMessage(message) {
|
|
318
|
-
var _a;
|
|
319
|
-
try {
|
|
320
|
-
this.isWalletExists();
|
|
321
|
-
if (!this._wallet)
|
|
322
|
-
return null;
|
|
323
|
-
const response = await ((_a = this._wallet) == null ? void 0 : _a.signMessage(message));
|
|
324
|
-
return response;
|
|
325
|
-
} catch (error) {
|
|
326
|
-
const errMsg = typeof error == "object" && "message" in error ? error.message : error;
|
|
327
|
-
throw new WalletSignMessageError(errMsg).message;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
async onAccountChange() {
|
|
331
|
-
var _a;
|
|
332
|
-
try {
|
|
333
|
-
this.isWalletExists();
|
|
334
|
-
await ((_a = this._wallet) == null ? void 0 : _a.onAccountChange((data) => {
|
|
335
|
-
this.setAccount({ ...data });
|
|
336
|
-
this.emit("accountChange", this._account);
|
|
337
|
-
}));
|
|
338
|
-
} catch (error) {
|
|
339
|
-
const errMsg = typeof error == "object" && "message" in error ? error.message : error;
|
|
340
|
-
throw new WalletAccountChangeError(errMsg).message;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
async onNetworkChange() {
|
|
344
|
-
var _a;
|
|
345
|
-
try {
|
|
346
|
-
this.isWalletExists();
|
|
347
|
-
await ((_a = this._wallet) == null ? void 0 : _a.onNetworkChange((data) => {
|
|
348
|
-
this.setNetwork({ ...data });
|
|
349
|
-
this.emit("networkChange", this._network);
|
|
350
|
-
}));
|
|
351
|
-
} catch (error) {
|
|
352
|
-
const errMsg = typeof error == "object" && "message" in error ? error.message : error;
|
|
353
|
-
throw new WalletNetworkChangeError(errMsg).message;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
};
|
|
357
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
358
|
-
0 && (module.exports = {
|
|
359
|
-
NetworkName,
|
|
360
|
-
WalletCore,
|
|
361
|
-
WalletReadyState
|
|
362
|
-
});
|
package/dist/index.mjs
DELETED
|
@@ -1,333 +0,0 @@
|
|
|
1
|
-
// src/WalletCore.ts
|
|
2
|
-
import { EventEmitter } from "eventemitter3";
|
|
3
|
-
|
|
4
|
-
// src/constants.ts
|
|
5
|
-
var WalletReadyState = /* @__PURE__ */ ((WalletReadyState2) => {
|
|
6
|
-
WalletReadyState2["Installed"] = "Installed";
|
|
7
|
-
WalletReadyState2["NotDetected"] = "NotDetected";
|
|
8
|
-
WalletReadyState2["Loadable"] = "Loadable";
|
|
9
|
-
WalletReadyState2["Unsupported"] = "Unsupported";
|
|
10
|
-
return WalletReadyState2;
|
|
11
|
-
})(WalletReadyState || {});
|
|
12
|
-
var NetworkName = /* @__PURE__ */ ((NetworkName2) => {
|
|
13
|
-
NetworkName2["Mainnet"] = "mainnet";
|
|
14
|
-
NetworkName2["Testnet"] = "testnet";
|
|
15
|
-
NetworkName2["Devnet"] = "devnet";
|
|
16
|
-
return NetworkName2;
|
|
17
|
-
})(NetworkName || {});
|
|
18
|
-
|
|
19
|
-
// src/error/index.ts
|
|
20
|
-
var WalletError = class extends Error {
|
|
21
|
-
constructor(message, error) {
|
|
22
|
-
super(message);
|
|
23
|
-
this.error = error;
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
var WalletNotSelectedError = class extends WalletError {
|
|
27
|
-
constructor() {
|
|
28
|
-
super(...arguments);
|
|
29
|
-
this.name = "WalletNotSelectedError";
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
var WalletNotReadyError = class extends WalletError {
|
|
33
|
-
constructor() {
|
|
34
|
-
super(...arguments);
|
|
35
|
-
this.name = "WalletNotReadyError";
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var WalletConnectionError = class extends WalletError {
|
|
39
|
-
constructor() {
|
|
40
|
-
super(...arguments);
|
|
41
|
-
this.name = "WalletConnectionError";
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
var WalletDisconnectionError = class extends WalletError {
|
|
45
|
-
constructor() {
|
|
46
|
-
super(...arguments);
|
|
47
|
-
this.name = "WalletDisconnectionError";
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
var WalletAccountError = class extends WalletError {
|
|
51
|
-
constructor() {
|
|
52
|
-
super(...arguments);
|
|
53
|
-
this.name = "WalletAccountError";
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
var WalletGetNetworkError = class extends WalletError {
|
|
57
|
-
constructor() {
|
|
58
|
-
super(...arguments);
|
|
59
|
-
this.name = "WalletGetNetworkError";
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
var WalletAccountChangeError = class extends WalletError {
|
|
63
|
-
constructor() {
|
|
64
|
-
super(...arguments);
|
|
65
|
-
this.name = "WalletAccountChangeError";
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
var WalletNetworkChangeError = class extends WalletError {
|
|
69
|
-
constructor() {
|
|
70
|
-
super(...arguments);
|
|
71
|
-
this.name = "WalletNetworkChangeError";
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
var WalletNotConnectedError = class extends WalletError {
|
|
75
|
-
constructor() {
|
|
76
|
-
super(...arguments);
|
|
77
|
-
this.name = "WalletNotConnectedError";
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
var WalletSignMessageError = class extends WalletError {
|
|
81
|
-
constructor() {
|
|
82
|
-
super(...arguments);
|
|
83
|
-
this.name = "WalletSignMessageError";
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
var WalletSignAndSubmitMessageError = class extends WalletError {
|
|
87
|
-
constructor() {
|
|
88
|
-
super(...arguments);
|
|
89
|
-
this.name = "WalletSignAndSubmitMessageError";
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
var WalletSignTransactionError = class extends WalletError {
|
|
93
|
-
constructor() {
|
|
94
|
-
super(...arguments);
|
|
95
|
-
this.name = "WalletSignTransactionError";
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
// src/utils/scopePollingDetectionStrategy.ts
|
|
100
|
-
function scopePollingDetectionStrategy(detect) {
|
|
101
|
-
if (typeof window === "undefined" || typeof document === "undefined")
|
|
102
|
-
return;
|
|
103
|
-
const disposers = [];
|
|
104
|
-
function detectAndDispose() {
|
|
105
|
-
const detected = detect();
|
|
106
|
-
if (detected) {
|
|
107
|
-
for (const dispose of disposers) {
|
|
108
|
-
dispose();
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
const interval = setInterval(detectAndDispose, 1e3);
|
|
113
|
-
disposers.push(() => clearInterval(interval));
|
|
114
|
-
if (document.readyState === "loading") {
|
|
115
|
-
document.addEventListener("DOMContentLoaded", detectAndDispose, {
|
|
116
|
-
once: true
|
|
117
|
-
});
|
|
118
|
-
disposers.push(
|
|
119
|
-
() => document.removeEventListener("DOMContentLoaded", detectAndDispose)
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
if (document.readyState !== "complete") {
|
|
123
|
-
window.addEventListener("load", detectAndDispose, { once: true });
|
|
124
|
-
disposers.push(() => window.removeEventListener("load", detectAndDispose));
|
|
125
|
-
}
|
|
126
|
-
detectAndDispose();
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// src/utils/localStorage.ts
|
|
130
|
-
var LOCAL_STORAGE_ITEM_KEY = "AptosWalletName";
|
|
131
|
-
function setLocalStorage(walletName) {
|
|
132
|
-
localStorage.setItem(LOCAL_STORAGE_ITEM_KEY, walletName);
|
|
133
|
-
}
|
|
134
|
-
function removeLocalStorage() {
|
|
135
|
-
localStorage.removeItem(LOCAL_STORAGE_ITEM_KEY);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// src/WalletCore.ts
|
|
139
|
-
var WalletCore = class extends EventEmitter {
|
|
140
|
-
constructor(plugins) {
|
|
141
|
-
super();
|
|
142
|
-
this._wallets = [];
|
|
143
|
-
this._wallet = null;
|
|
144
|
-
this._account = null;
|
|
145
|
-
this._network = null;
|
|
146
|
-
this._connecting = false;
|
|
147
|
-
this._connected = false;
|
|
148
|
-
this._wallets = plugins;
|
|
149
|
-
this.scopePollingDetectionStrategy();
|
|
150
|
-
}
|
|
151
|
-
scopePollingDetectionStrategy() {
|
|
152
|
-
var _a;
|
|
153
|
-
(_a = this._wallets) == null ? void 0 : _a.forEach((wallet) => {
|
|
154
|
-
wallet.readyState = typeof window === "undefined" || typeof document === "undefined" ? "Unsupported" /* Unsupported */ : "NotDetected" /* NotDetected */;
|
|
155
|
-
if (typeof window !== "undefined") {
|
|
156
|
-
scopePollingDetectionStrategy(() => {
|
|
157
|
-
if (Object.keys(window).includes(wallet.name.toLowerCase())) {
|
|
158
|
-
wallet.readyState = "Installed" /* Installed */;
|
|
159
|
-
wallet.provider = window[wallet.name.toLowerCase()];
|
|
160
|
-
this.emit("readyStateChange", wallet);
|
|
161
|
-
return true;
|
|
162
|
-
}
|
|
163
|
-
return false;
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
isWalletExists() {
|
|
169
|
-
if (!this._connected || this._connecting || !this._wallet)
|
|
170
|
-
throw new WalletNotConnectedError().name;
|
|
171
|
-
if (!(this._wallet.readyState === "Loadable" /* Loadable */ || this._wallet.readyState === "Installed" /* Installed */))
|
|
172
|
-
throw new WalletNotReadyError().name;
|
|
173
|
-
return true;
|
|
174
|
-
}
|
|
175
|
-
clearData() {
|
|
176
|
-
this._connected = false;
|
|
177
|
-
this.setWallet(null);
|
|
178
|
-
this.setAccount(null);
|
|
179
|
-
this.setNetwork(null);
|
|
180
|
-
removeLocalStorage();
|
|
181
|
-
}
|
|
182
|
-
setWallet(wallet) {
|
|
183
|
-
this._wallet = wallet;
|
|
184
|
-
}
|
|
185
|
-
setAccount(account) {
|
|
186
|
-
this._account = account;
|
|
187
|
-
}
|
|
188
|
-
setNetwork(network) {
|
|
189
|
-
this._network = network;
|
|
190
|
-
}
|
|
191
|
-
isConnected() {
|
|
192
|
-
return this._connected;
|
|
193
|
-
}
|
|
194
|
-
get wallets() {
|
|
195
|
-
return this._wallets;
|
|
196
|
-
}
|
|
197
|
-
get wallet() {
|
|
198
|
-
try {
|
|
199
|
-
if (!this._wallet)
|
|
200
|
-
return null;
|
|
201
|
-
return {
|
|
202
|
-
name: this._wallet.name,
|
|
203
|
-
icon: this._wallet.icon,
|
|
204
|
-
url: this._wallet.url
|
|
205
|
-
};
|
|
206
|
-
} catch (error) {
|
|
207
|
-
throw new WalletNotSelectedError(error).message;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
get account() {
|
|
211
|
-
try {
|
|
212
|
-
return this._account;
|
|
213
|
-
} catch (error) {
|
|
214
|
-
throw new WalletAccountError(error).message;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
get network() {
|
|
218
|
-
try {
|
|
219
|
-
return this._network;
|
|
220
|
-
} catch (error) {
|
|
221
|
-
throw new WalletGetNetworkError(error).message;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
async connect(walletName) {
|
|
225
|
-
var _a;
|
|
226
|
-
try {
|
|
227
|
-
const selectedWallet = (_a = this._wallets) == null ? void 0 : _a.find(
|
|
228
|
-
(wallet) => wallet.name === walletName
|
|
229
|
-
);
|
|
230
|
-
if (!selectedWallet)
|
|
231
|
-
return;
|
|
232
|
-
if (selectedWallet.readyState !== "Installed" /* Installed */)
|
|
233
|
-
return;
|
|
234
|
-
if (this._connected) {
|
|
235
|
-
await this.disconnect();
|
|
236
|
-
}
|
|
237
|
-
this._connecting = true;
|
|
238
|
-
this.setWallet(selectedWallet);
|
|
239
|
-
const account = await selectedWallet.connect();
|
|
240
|
-
this.setAccount({ ...account });
|
|
241
|
-
const network = await selectedWallet.network();
|
|
242
|
-
this.setNetwork({ ...network });
|
|
243
|
-
setLocalStorage(selectedWallet.name);
|
|
244
|
-
this._connected = true;
|
|
245
|
-
this.emit("connect", account);
|
|
246
|
-
} catch (error) {
|
|
247
|
-
this.clearData();
|
|
248
|
-
throw new WalletConnectionError(error).message;
|
|
249
|
-
} finally {
|
|
250
|
-
this._connecting = false;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
async disconnect() {
|
|
254
|
-
var _a;
|
|
255
|
-
try {
|
|
256
|
-
this.isWalletExists();
|
|
257
|
-
await ((_a = this._wallet) == null ? void 0 : _a.disconnect());
|
|
258
|
-
this.clearData();
|
|
259
|
-
this.emit("disconnect");
|
|
260
|
-
} catch (error) {
|
|
261
|
-
throw new WalletDisconnectionError(error).message;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
async signAndSubmitTransaction(transaction) {
|
|
265
|
-
var _a;
|
|
266
|
-
try {
|
|
267
|
-
this.isWalletExists();
|
|
268
|
-
const response = await ((_a = this._wallet) == null ? void 0 : _a.signAndSubmitTransaction(
|
|
269
|
-
transaction
|
|
270
|
-
));
|
|
271
|
-
return response;
|
|
272
|
-
} catch (error) {
|
|
273
|
-
const errMsg = typeof error == "object" && "message" in error ? error.message : error;
|
|
274
|
-
throw new WalletSignAndSubmitMessageError(errMsg).message;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
async signTransaction(transaction) {
|
|
278
|
-
try {
|
|
279
|
-
if (this._wallet && !("signTransaction" in this._wallet))
|
|
280
|
-
return null;
|
|
281
|
-
this.isWalletExists();
|
|
282
|
-
const response = await this._wallet.signTransaction(transaction);
|
|
283
|
-
return response;
|
|
284
|
-
} catch (error) {
|
|
285
|
-
const errMsg = typeof error == "object" && "message" in error ? error.message : error;
|
|
286
|
-
throw new WalletSignTransactionError(errMsg).message;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
async signMessage(message) {
|
|
290
|
-
var _a;
|
|
291
|
-
try {
|
|
292
|
-
this.isWalletExists();
|
|
293
|
-
if (!this._wallet)
|
|
294
|
-
return null;
|
|
295
|
-
const response = await ((_a = this._wallet) == null ? void 0 : _a.signMessage(message));
|
|
296
|
-
return response;
|
|
297
|
-
} catch (error) {
|
|
298
|
-
const errMsg = typeof error == "object" && "message" in error ? error.message : error;
|
|
299
|
-
throw new WalletSignMessageError(errMsg).message;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
async onAccountChange() {
|
|
303
|
-
var _a;
|
|
304
|
-
try {
|
|
305
|
-
this.isWalletExists();
|
|
306
|
-
await ((_a = this._wallet) == null ? void 0 : _a.onAccountChange((data) => {
|
|
307
|
-
this.setAccount({ ...data });
|
|
308
|
-
this.emit("accountChange", this._account);
|
|
309
|
-
}));
|
|
310
|
-
} catch (error) {
|
|
311
|
-
const errMsg = typeof error == "object" && "message" in error ? error.message : error;
|
|
312
|
-
throw new WalletAccountChangeError(errMsg).message;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
async onNetworkChange() {
|
|
316
|
-
var _a;
|
|
317
|
-
try {
|
|
318
|
-
this.isWalletExists();
|
|
319
|
-
await ((_a = this._wallet) == null ? void 0 : _a.onNetworkChange((data) => {
|
|
320
|
-
this.setNetwork({ ...data });
|
|
321
|
-
this.emit("networkChange", this._network);
|
|
322
|
-
}));
|
|
323
|
-
} catch (error) {
|
|
324
|
-
const errMsg = typeof error == "object" && "message" in error ? error.message : error;
|
|
325
|
-
throw new WalletNetworkChangeError(errMsg).message;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
export {
|
|
330
|
-
NetworkName,
|
|
331
|
-
WalletCore,
|
|
332
|
-
WalletReadyState
|
|
333
|
-
};
|