@manahippo/aptos-wallet-adapter 1.0.0 → 1.0.2
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/README.md +4 -2
- package/dist/WalletAdapters/Coin98Wallet.d.ts +61 -0
- package/dist/WalletAdapters/Coin98Wallet.d.ts.map +1 -0
- package/dist/WalletAdapters/Coin98Wallet.js +245 -0
- package/dist/WalletAdapters/Coin98Wallet.js.map +1 -0
- package/dist/WalletAdapters/MartianWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/MartianWallet.js +5 -3
- package/dist/WalletAdapters/MartianWallet.js.map +1 -1
- package/dist/WalletAdapters/SafePalWallet.d.ts +65 -0
- package/dist/WalletAdapters/SafePalWallet.d.ts.map +1 -0
- package/dist/WalletAdapters/SafePalWallet.js +245 -0
- package/dist/WalletAdapters/SafePalWallet.js.map +1 -0
- package/dist/WalletAdapters/index.d.ts +2 -0
- package/dist/WalletAdapters/index.d.ts.map +1 -1
- package/dist/WalletAdapters/index.js +2 -0
- package/dist/WalletAdapters/index.js.map +1 -1
- package/package.json +1 -1
- package/src/WalletAdapters/Coin98Wallet.ts +310 -0
- package/src/WalletAdapters/MartianWallet.ts +6 -3
- package/src/WalletAdapters/SafePalWallet.ts +319 -0
- package/src/WalletAdapters/index.ts +2 -0
@@ -0,0 +1,245 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
exports.SafePalWalletAdapter = exports.SafePalWalletName = void 0;
|
13
|
+
const errors_1 = require("../WalletProviders/errors");
|
14
|
+
const BaseAdapter_1 = require("./BaseAdapter");
|
15
|
+
exports.SafePalWalletName = 'SafePal';
|
16
|
+
class SafePalWalletAdapter extends BaseAdapter_1.BaseWalletAdapter {
|
17
|
+
constructor({
|
18
|
+
// provider,
|
19
|
+
// network = WalletAdapterNetwork.Testnet,
|
20
|
+
timeout = 10000 } = {}) {
|
21
|
+
super();
|
22
|
+
this.name = exports.SafePalWalletName;
|
23
|
+
this.url = 'https://chrome.google.com/webstore/detail/safepal-extension-wallet/lgmpcpglpngdoalbgeoldeajfclnhafa';
|
24
|
+
this.icon = 'https://raw.githubusercontent.com/hippospace/aptos-wallet-adapter/main/logos/safePal.png';
|
25
|
+
this._readyState = typeof window === 'undefined' || typeof document === 'undefined'
|
26
|
+
? BaseAdapter_1.WalletReadyState.Unsupported
|
27
|
+
: BaseAdapter_1.WalletReadyState.NotDetected;
|
28
|
+
this._provider = typeof window !== 'undefined' ? window.safePal : undefined;
|
29
|
+
this._network = undefined;
|
30
|
+
this._timeout = timeout;
|
31
|
+
this._connecting = false;
|
32
|
+
this._wallet = null;
|
33
|
+
if (typeof window !== 'undefined' && this._readyState !== BaseAdapter_1.WalletReadyState.Unsupported) {
|
34
|
+
(0, BaseAdapter_1.scopePollingDetectionStrategy)(() => {
|
35
|
+
this._provider = typeof window !== 'undefined' ? window.safePal : undefined;
|
36
|
+
if (this._provider) {
|
37
|
+
this._readyState = BaseAdapter_1.WalletReadyState.Installed;
|
38
|
+
this.emit('readyStateChange', this._readyState);
|
39
|
+
return true;
|
40
|
+
}
|
41
|
+
return false;
|
42
|
+
});
|
43
|
+
}
|
44
|
+
}
|
45
|
+
get publicAccount() {
|
46
|
+
var _a, _b, _c;
|
47
|
+
return {
|
48
|
+
publicKey: ((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.publicKey) || null,
|
49
|
+
address: ((_b = this._wallet) === null || _b === void 0 ? void 0 : _b.address) || null,
|
50
|
+
authKey: ((_c = this._wallet) === null || _c === void 0 ? void 0 : _c.authKey) || null
|
51
|
+
};
|
52
|
+
}
|
53
|
+
get network() {
|
54
|
+
return {
|
55
|
+
name: this._network,
|
56
|
+
api: this._api,
|
57
|
+
chainId: this._chainId
|
58
|
+
};
|
59
|
+
}
|
60
|
+
get connecting() {
|
61
|
+
return this._connecting;
|
62
|
+
}
|
63
|
+
get connected() {
|
64
|
+
var _a;
|
65
|
+
return !!((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.isConnected);
|
66
|
+
}
|
67
|
+
get readyState() {
|
68
|
+
return this._readyState;
|
69
|
+
}
|
70
|
+
connect() {
|
71
|
+
var _a;
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
73
|
+
try {
|
74
|
+
if (this.connected || this.connecting)
|
75
|
+
return;
|
76
|
+
if (!(this._readyState === BaseAdapter_1.WalletReadyState.Loadable ||
|
77
|
+
this._readyState === BaseAdapter_1.WalletReadyState.Installed))
|
78
|
+
throw new errors_1.WalletNotReadyError();
|
79
|
+
this._connecting = true;
|
80
|
+
const provider = this._provider || window.safePal;
|
81
|
+
const isConnected = yield (provider === null || provider === void 0 ? void 0 : provider.isConnected());
|
82
|
+
if (isConnected) {
|
83
|
+
yield (provider === null || provider === void 0 ? void 0 : provider.disconnect());
|
84
|
+
}
|
85
|
+
const response = yield (provider === null || provider === void 0 ? void 0 : provider.connect());
|
86
|
+
if (!response) {
|
87
|
+
throw new errors_1.WalletNotConnectedError('No connect response');
|
88
|
+
}
|
89
|
+
const walletAccount = yield (provider === null || provider === void 0 ? void 0 : provider.account());
|
90
|
+
if (walletAccount) {
|
91
|
+
this._wallet = Object.assign(Object.assign({}, walletAccount), { isConnected: true });
|
92
|
+
try {
|
93
|
+
const name = yield (provider === null || provider === void 0 ? void 0 : provider.network());
|
94
|
+
const { chainId } = yield (provider === null || provider === void 0 ? void 0 : provider.getChainId());
|
95
|
+
const api = null;
|
96
|
+
this._network = name;
|
97
|
+
this._chainId = chainId.toString();
|
98
|
+
this._api = api;
|
99
|
+
}
|
100
|
+
catch (error) {
|
101
|
+
const errMsg = error.message;
|
102
|
+
this.emit('error', new errors_1.WalletGetNetworkError(errMsg));
|
103
|
+
throw error;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
this.emit('connect', ((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.address) || '');
|
107
|
+
}
|
108
|
+
catch (error) {
|
109
|
+
this.emit('error', new Error(error));
|
110
|
+
throw error;
|
111
|
+
}
|
112
|
+
finally {
|
113
|
+
this._connecting = false;
|
114
|
+
}
|
115
|
+
});
|
116
|
+
}
|
117
|
+
disconnect() {
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
119
|
+
const wallet = this._wallet;
|
120
|
+
const provider = this._provider || window.safePal;
|
121
|
+
if (wallet) {
|
122
|
+
this._wallet = null;
|
123
|
+
try {
|
124
|
+
yield (provider === null || provider === void 0 ? void 0 : provider.disconnect());
|
125
|
+
}
|
126
|
+
catch (error) {
|
127
|
+
this.emit('error', new errors_1.WalletDisconnectionError(error === null || error === void 0 ? void 0 : error.message, error));
|
128
|
+
}
|
129
|
+
}
|
130
|
+
this.emit('disconnect');
|
131
|
+
});
|
132
|
+
}
|
133
|
+
signTransaction(transactionPyld, options) {
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
135
|
+
try {
|
136
|
+
const wallet = this._wallet;
|
137
|
+
const provider = this._provider || window.safePal;
|
138
|
+
if (!wallet || !provider)
|
139
|
+
throw new errors_1.WalletNotConnectedError();
|
140
|
+
const tx = yield provider.generateTransaction(wallet.address || '', transactionPyld, options);
|
141
|
+
if (!tx)
|
142
|
+
throw new Error('Cannot generate transaction');
|
143
|
+
const response = yield (provider === null || provider === void 0 ? void 0 : provider.signTransaction(tx));
|
144
|
+
if (!response) {
|
145
|
+
throw new Error('No response');
|
146
|
+
}
|
147
|
+
return response;
|
148
|
+
}
|
149
|
+
catch (error) {
|
150
|
+
this.emit('error', new errors_1.WalletSignTransactionError(error));
|
151
|
+
throw error;
|
152
|
+
}
|
153
|
+
});
|
154
|
+
}
|
155
|
+
signAndSubmitTransaction(transactionPyld, options) {
|
156
|
+
return __awaiter(this, void 0, void 0, function* () {
|
157
|
+
try {
|
158
|
+
const wallet = this._wallet;
|
159
|
+
const provider = this._provider || window.safePal;
|
160
|
+
if (!wallet || !provider)
|
161
|
+
throw new errors_1.WalletNotConnectedError();
|
162
|
+
const tx = yield provider.generateTransaction(wallet.address || '', transactionPyld, options);
|
163
|
+
if (!tx)
|
164
|
+
throw new Error('Cannot generate transaction');
|
165
|
+
const response = yield (provider === null || provider === void 0 ? void 0 : provider.signAndSubmitTransaction(tx));
|
166
|
+
if (!response) {
|
167
|
+
throw new Error('No response');
|
168
|
+
}
|
169
|
+
return { hash: response };
|
170
|
+
}
|
171
|
+
catch (error) {
|
172
|
+
this.emit('error', new errors_1.WalletSignAndSubmitMessageError(error));
|
173
|
+
throw error;
|
174
|
+
}
|
175
|
+
});
|
176
|
+
}
|
177
|
+
signMessage(msgPayload) {
|
178
|
+
return __awaiter(this, void 0, void 0, function* () {
|
179
|
+
try {
|
180
|
+
const wallet = this._wallet;
|
181
|
+
const provider = this._provider || window.safePal;
|
182
|
+
if (!wallet || !provider)
|
183
|
+
throw new errors_1.WalletNotConnectedError();
|
184
|
+
if (typeof msgPayload !== 'object' || !msgPayload.nonce) {
|
185
|
+
throw new errors_1.WalletSignMessageError('Invalid signMessage Payload');
|
186
|
+
}
|
187
|
+
const response = yield (provider === null || provider === void 0 ? void 0 : provider.signMessage(msgPayload));
|
188
|
+
if (response) {
|
189
|
+
return response;
|
190
|
+
}
|
191
|
+
else {
|
192
|
+
throw new Error('Sign Message failed');
|
193
|
+
}
|
194
|
+
}
|
195
|
+
catch (error) {
|
196
|
+
const errMsg = error.message;
|
197
|
+
this.emit('error', new errors_1.WalletSignMessageError(errMsg));
|
198
|
+
throw error;
|
199
|
+
}
|
200
|
+
});
|
201
|
+
}
|
202
|
+
onAccountChange() {
|
203
|
+
return __awaiter(this, void 0, void 0, function* () {
|
204
|
+
try {
|
205
|
+
const wallet = this._wallet;
|
206
|
+
const provider = this._provider || window.safePal;
|
207
|
+
if (!wallet || !provider)
|
208
|
+
throw new errors_1.WalletNotConnectedError();
|
209
|
+
const handleChangeAccount = (newAccount) => __awaiter(this, void 0, void 0, function* () {
|
210
|
+
const { publicKey } = yield (provider === null || provider === void 0 ? void 0 : provider.account());
|
211
|
+
this._wallet = Object.assign(Object.assign({}, this._wallet), { address: newAccount, publicKey });
|
212
|
+
this.emit('accountChange', newAccount);
|
213
|
+
});
|
214
|
+
yield (provider === null || provider === void 0 ? void 0 : provider.onAccountChange(handleChangeAccount));
|
215
|
+
}
|
216
|
+
catch (error) {
|
217
|
+
const errMsg = error.message;
|
218
|
+
this.emit('error', new errors_1.WalletAccountChangeError(errMsg));
|
219
|
+
throw error;
|
220
|
+
}
|
221
|
+
});
|
222
|
+
}
|
223
|
+
onNetworkChange() {
|
224
|
+
return __awaiter(this, void 0, void 0, function* () {
|
225
|
+
try {
|
226
|
+
const wallet = this._wallet;
|
227
|
+
const provider = this._provider || window.safePal;
|
228
|
+
if (!wallet || !provider)
|
229
|
+
throw new errors_1.WalletNotConnectedError();
|
230
|
+
const handleNetworkChange = (newNetwork) => __awaiter(this, void 0, void 0, function* () {
|
231
|
+
this._network = newNetwork;
|
232
|
+
this.emit('networkChange', this._network);
|
233
|
+
});
|
234
|
+
yield (provider === null || provider === void 0 ? void 0 : provider.onNetworkChange(handleNetworkChange));
|
235
|
+
}
|
236
|
+
catch (error) {
|
237
|
+
const errMsg = error.message;
|
238
|
+
this.emit('error', new errors_1.WalletNetworkChangeError(errMsg));
|
239
|
+
throw error;
|
240
|
+
}
|
241
|
+
});
|
242
|
+
}
|
243
|
+
}
|
244
|
+
exports.SafePalWalletAdapter = SafePal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,CAAC;aACtD;YAAC,OAAO,KAAU,EAAE;gBACnB,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC;gBAC7B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,iCAAwB,CAAC,MAAM,CAAC,CAAC,CAAC;gBACzD,MAAM,KAAK,CAAC;aACb;QACH,CAAC;KAAA;CACF;AA5PD,oDA4PC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/WalletAdapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/WalletAdapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC"}
|
@@ -31,4 +31,6 @@ __exportStar(require("./BitkeepWallet"), exports);
|
|
31
31
|
__exportStar(require("./TokenPocketWallet"), exports);
|
32
32
|
__exportStar(require("./ONTOWallet"), exports);
|
33
33
|
__exportStar(require("./BloctoWallet"), exports);
|
34
|
+
__exportStar(require("./Coin98Wallet"), exports);
|
35
|
+
__exportStar(require("./SafePalWallet"), exports);
|
34
36
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/WalletAdapters/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,gDAA8B;AAC9B,yDAAuC;AACvC,gDAA8B;AAC9B,kDAAgC;AAChC,iDAA+B;AAC/B,iDAA+B;AAC/B,kDAAgC;AAChC,+CAA6B;AAC7B,gDAA8B;AAC9B,mDAAiC;AACjC,iDAA+B;AAC/B,8CAA4B;AAC5B,kDAAgC;AAChC,sDAAoC;AACpC,+CAA6B;AAC7B,iDAA+B"}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/WalletAdapters/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,gDAA8B;AAC9B,yDAAuC;AACvC,gDAA8B;AAC9B,kDAAgC;AAChC,iDAA+B;AAC/B,iDAA+B;AAC/B,kDAAgC;AAChC,+CAA6B;AAC7B,gDAA8B;AAC9B,mDAAiC;AACjC,iDAA+B;AAC/B,8CAA4B;AAC5B,kDAAgC;AAChC,sDAAoC;AACpC,+CAA6B;AAC7B,iDAA+B;AAC/B,iDAA+B;AAC/B,kDAAgC"}
|
package/package.json
CHANGED
@@ -0,0 +1,310 @@
|
|
1
|
+
import { Types } from 'aptos';
|
2
|
+
import {
|
3
|
+
WalletAccountChangeError,
|
4
|
+
WalletDisconnectionError,
|
5
|
+
WalletGetNetworkError,
|
6
|
+
WalletNetworkChangeError,
|
7
|
+
WalletNotConnectedError,
|
8
|
+
WalletNotReadyError,
|
9
|
+
WalletSignAndSubmitMessageError,
|
10
|
+
WalletSignMessageError,
|
11
|
+
WalletSignTransactionError
|
12
|
+
} from '../WalletProviders/errors';
|
13
|
+
import {
|
14
|
+
AccountKeys,
|
15
|
+
BaseWalletAdapter,
|
16
|
+
NetworkInfo,
|
17
|
+
scopePollingDetectionStrategy,
|
18
|
+
SignMessagePayload,
|
19
|
+
SignMessageResponse,
|
20
|
+
WalletAdapterNetwork,
|
21
|
+
WalletName,
|
22
|
+
WalletReadyState
|
23
|
+
} from './BaseAdapter';
|
24
|
+
|
25
|
+
interface IApotsErrorResult {
|
26
|
+
code: number;
|
27
|
+
message: string;
|
28
|
+
}
|
29
|
+
|
30
|
+
type AddressInfo = { address: string; publicKey: string };
|
31
|
+
|
32
|
+
interface IConnectOptions {
|
33
|
+
network: string;
|
34
|
+
}
|
35
|
+
|
36
|
+
interface ICoin98Wallet {
|
37
|
+
connect: (options?: IConnectOptions) => Promise<AddressInfo>;
|
38
|
+
account: () => Promise<AddressInfo>;
|
39
|
+
isConnected: () => Promise<boolean>;
|
40
|
+
signAndSubmitTransaction(
|
41
|
+
transaction: any,
|
42
|
+
options?: any
|
43
|
+
): Promise<{ hash: Types.HexEncodedBytes } | IApotsErrorResult>;
|
44
|
+
signTransaction(transaction: any, options?: any): Promise<Uint8Array | IApotsErrorResult>;
|
45
|
+
signMessage(message: SignMessagePayload): Promise<SignMessageResponse>;
|
46
|
+
disconnect(): Promise<void>;
|
47
|
+
on: (eventName: string, callback: Function) => void;
|
48
|
+
}
|
49
|
+
|
50
|
+
interface AptosWindow extends Window {
|
51
|
+
coin98?: {
|
52
|
+
aptos: ICoin98Wallet;
|
53
|
+
};
|
54
|
+
}
|
55
|
+
|
56
|
+
declare const window: AptosWindow;
|
57
|
+
|
58
|
+
export const Coin98WalletName = 'Coin98' as WalletName<'Coin98'>;
|
59
|
+
|
60
|
+
export interface Coin98WalletAdapterConfig {
|
61
|
+
provider?: ICoin98Wallet;
|
62
|
+
network?: WalletAdapterNetwork;
|
63
|
+
timeout?: number;
|
64
|
+
}
|
65
|
+
|
66
|
+
export class Coin98WalletAdapter extends BaseWalletAdapter {
|
67
|
+
name = Coin98WalletName;
|
68
|
+
|
69
|
+
url = 'https://chrome.google.com/webstore/detail/coin98-wallet/aeachknmefphepccionboohckonoeemg';
|
70
|
+
|
71
|
+
icon = 'https://coin98.s3.ap-southeast-1.amazonaws.com/Coin/c98wallet.png';
|
72
|
+
|
73
|
+
protected _provider: ICoin98Wallet | undefined;
|
74
|
+
|
75
|
+
protected _network: WalletAdapterNetwork;
|
76
|
+
|
77
|
+
protected _chainId: string;
|
78
|
+
|
79
|
+
protected _api: string;
|
80
|
+
|
81
|
+
protected _timeout: number;
|
82
|
+
|
83
|
+
protected _readyState: WalletReadyState =
|
84
|
+
typeof window === 'undefined' || typeof document === 'undefined'
|
85
|
+
? WalletReadyState.Unsupported
|
86
|
+
: WalletReadyState.NotDetected;
|
87
|
+
|
88
|
+
protected _connecting: boolean;
|
89
|
+
|
90
|
+
protected _wallet: any | null;
|
91
|
+
|
92
|
+
constructor({
|
93
|
+
// provider,
|
94
|
+
// network = WalletAdapterNetwork.Mainnet,
|
95
|
+
timeout = 10000
|
96
|
+
}: Coin98WalletAdapterConfig = {}) {
|
97
|
+
super();
|
98
|
+
|
99
|
+
this._provider = typeof window !== 'undefined' ? window.coin98?.aptos : undefined;
|
100
|
+
this._network = undefined;
|
101
|
+
this._timeout = timeout;
|
102
|
+
this._connecting = false;
|
103
|
+
this._wallet = null;
|
104
|
+
|
105
|
+
if (typeof window !== 'undefined' && this._readyState !== WalletReadyState.Unsupported) {
|
106
|
+
scopePollingDetectionStrategy(() => {
|
107
|
+
if (window.coin98?.aptos) {
|
108
|
+
this._readyState = WalletReadyState.Installed;
|
109
|
+
this.emit('readyStateChange', this._readyState);
|
110
|
+
return true;
|
111
|
+
}
|
112
|
+
return false;
|
113
|
+
});
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
get publicAccount(): AccountKeys {
|
118
|
+
return {
|
119
|
+
publicKey: this._wallet?.publicKey || null,
|
120
|
+
address: this._wallet?.address || null,
|
121
|
+
authKey: this._wallet?.authKey || null
|
122
|
+
};
|
123
|
+
}
|
124
|
+
|
125
|
+
get network(): NetworkInfo {
|
126
|
+
return {
|
127
|
+
name: this._network,
|
128
|
+
api: this._api,
|
129
|
+
chainId: this._chainId
|
130
|
+
};
|
131
|
+
}
|
132
|
+
|
133
|
+
get connecting(): boolean {
|
134
|
+
return this._connecting;
|
135
|
+
}
|
136
|
+
|
137
|
+
get connected(): boolean {
|
138
|
+
return !!this._wallet?.isConnected;
|
139
|
+
}
|
140
|
+
|
141
|
+
get readyState(): WalletReadyState {
|
142
|
+
return this._readyState;
|
143
|
+
}
|
144
|
+
|
145
|
+
async connect(): Promise<void> {
|
146
|
+
try {
|
147
|
+
if (this.connected || this.connecting) return;
|
148
|
+
if (
|
149
|
+
!(
|
150
|
+
this._readyState === WalletReadyState.Loadable ||
|
151
|
+
this._readyState === WalletReadyState.Installed
|
152
|
+
)
|
153
|
+
)
|
154
|
+
throw new WalletNotReadyError();
|
155
|
+
this._connecting = true;
|
156
|
+
|
157
|
+
const provider = this._provider || window.coin98?.aptos;
|
158
|
+
let response = await provider?.connect({ network: this._network });
|
159
|
+
|
160
|
+
if (typeof response === 'boolean') {
|
161
|
+
response = await provider?.account();
|
162
|
+
}
|
163
|
+
|
164
|
+
this._wallet = {
|
165
|
+
address: response?.address,
|
166
|
+
publicKey: response?.publicKey,
|
167
|
+
isConnected: true
|
168
|
+
};
|
169
|
+
|
170
|
+
try {
|
171
|
+
const chainId = null;
|
172
|
+
const api = null;
|
173
|
+
|
174
|
+
this._chainId = chainId;
|
175
|
+
this._api = api;
|
176
|
+
} catch (error: any) {
|
177
|
+
const errMsg = error.message;
|
178
|
+
this.emit('error', new WalletGetNetworkError(errMsg));
|
179
|
+
throw error;
|
180
|
+
}
|
181
|
+
|
182
|
+
this.emit('connect', this._wallet.publicKey);
|
183
|
+
} catch (error: any) {
|
184
|
+
this.emit('error', error);
|
185
|
+
throw error;
|
186
|
+
} finally {
|
187
|
+
this._connecting = false;
|
188
|
+
}
|
189
|
+
}
|
190
|
+
|
191
|
+
async disconnect(): Promise<void> {
|
192
|
+
const wallet = this._wallet;
|
193
|
+
const provider = this._provider || window.coin98?.aptos;
|
194
|
+
if (wallet) {
|
195
|
+
this._wallet = null;
|
196
|
+
|
197
|
+
try {
|
198
|
+
await provider?.disconnect();
|
199
|
+
} catch (error: any) {
|
200
|
+
this.emit('error', new WalletDisconnectionError(error?.message, error));
|
201
|
+
}
|
202
|
+
}
|
203
|
+
|
204
|
+
this.emit('disconnect');
|
205
|
+
}
|
206
|
+
|
207
|
+
async signTransaction(transaction: Types.TransactionPayload, options?: any): Promise<Uint8Array> {
|
208
|
+
try {
|
209
|
+
const wallet = this._wallet;
|
210
|
+
const provider = this._provider || window.coin98?.aptos;
|
211
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
212
|
+
|
213
|
+
const response = await provider.signTransaction(transaction, options);
|
214
|
+
if ((response as IApotsErrorResult).code) {
|
215
|
+
throw new Error((response as IApotsErrorResult).message);
|
216
|
+
}
|
217
|
+
return response as Uint8Array;
|
218
|
+
} catch (error: any) {
|
219
|
+
const errMsg = error.message;
|
220
|
+
this.emit('error', new WalletSignTransactionError(errMsg));
|
221
|
+
throw error;
|
222
|
+
}
|
223
|
+
}
|
224
|
+
|
225
|
+
async signAndSubmitTransaction(
|
226
|
+
transaction: Types.TransactionPayload,
|
227
|
+
options?: any
|
228
|
+
): Promise<{ hash: Types.HexEncodedBytes }> {
|
229
|
+
try {
|
230
|
+
const wallet = this._wallet;
|
231
|
+
const provider = this._provider || window.coin98?.aptos;
|
232
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
233
|
+
|
234
|
+
const response = await provider.signAndSubmitTransaction(transaction, options);
|
235
|
+
if ((response as IApotsErrorResult).code) {
|
236
|
+
throw new Error((response as IApotsErrorResult).message);
|
237
|
+
}
|
238
|
+
return response as { hash: Types.HexEncodedBytes };
|
239
|
+
} catch (error: any) {
|
240
|
+
const errMsg = error.message;
|
241
|
+
this.emit('error', new WalletSignAndSubmitMessageError(errMsg));
|
242
|
+
throw error;
|
243
|
+
}
|
244
|
+
}
|
245
|
+
|
246
|
+
async signMessage(msgPayload: SignMessagePayload): Promise<SignMessageResponse> {
|
247
|
+
try {
|
248
|
+
const wallet = this._wallet;
|
249
|
+
const provider = this._provider || window.coin98?.aptos;
|
250
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
251
|
+
if (typeof msgPayload !== 'object' || !msgPayload.nonce) {
|
252
|
+
throw new WalletSignMessageError('Invalid signMessage Payload');
|
253
|
+
}
|
254
|
+
const response = await provider?.signMessage(msgPayload);
|
255
|
+
if (response) {
|
256
|
+
return response;
|
257
|
+
} else {
|
258
|
+
throw new Error('Sign Message failed');
|
259
|
+
}
|
260
|
+
} catch (error: any) {
|
261
|
+
const errMsg = error.message;
|
262
|
+
this.emit('error', new WalletSignMessageError(errMsg));
|
263
|
+
throw error;
|
264
|
+
}
|
265
|
+
}
|
266
|
+
|
267
|
+
async onAccountChange(): Promise<void> {
|
268
|
+
try {
|
269
|
+
const wallet = this._wallet;
|
270
|
+
const provider = this._provider || window.coin98?.aptos;
|
271
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
272
|
+
const handleAccountChange = async (newAccount: AddressInfo) => {
|
273
|
+
if (newAccount?.publicKey) {
|
274
|
+
this._wallet = {
|
275
|
+
...this._wallet,
|
276
|
+
publicKey: newAccount.publicKey || this._wallet?.publicKey,
|
277
|
+
address: newAccount.address || this._wallet?.address
|
278
|
+
};
|
279
|
+
} else {
|
280
|
+
const response = await provider?.connect();
|
281
|
+
this._wallet = {
|
282
|
+
...this._wallet,
|
283
|
+
address: response?.address || this._wallet?.address,
|
284
|
+
publicKey: response?.publicKey || this._wallet?.publicKey
|
285
|
+
};
|
286
|
+
}
|
287
|
+
this.emit('accountChange', newAccount.publicKey);
|
288
|
+
};
|
289
|
+
|
290
|
+
provider.on('accountChange', handleAccountChange);
|
291
|
+
} catch (error: any) {
|
292
|
+
const errMsg = error.message;
|
293
|
+
this.emit('error', new WalletAccountChangeError(errMsg));
|
294
|
+
throw error;
|
295
|
+
}
|
296
|
+
}
|
297
|
+
|
298
|
+
async onNetworkChange(): Promise<void> {
|
299
|
+
try {
|
300
|
+
const wallet = this._wallet;
|
301
|
+
const provider = this._provider || window.coin98?.aptos;
|
302
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
303
|
+
//To be implemented
|
304
|
+
} catch (error: any) {
|
305
|
+
const errMsg = error.message;
|
306
|
+
this.emit('error', new WalletNetworkChangeError(errMsg));
|
307
|
+
throw error;
|
308
|
+
}
|
309
|
+
}
|
310
|
+
}
|
@@ -282,13 +282,16 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
|
|
282
282
|
const wallet = this._wallet;
|
283
283
|
const provider = this._provider || window.martian;
|
284
284
|
if (!wallet || !provider) throw new WalletNotConnectedError();
|
285
|
-
|
285
|
+
const handleChangeAccount = async (newAccount: string) => {
|
286
|
+
const { publicKey } = await provider?.account();
|
286
287
|
this._wallet = {
|
287
288
|
...this._wallet,
|
288
|
-
address: newAccount
|
289
|
+
address: newAccount,
|
290
|
+
publicKey
|
289
291
|
};
|
290
292
|
this.emit('accountChange', newAccount);
|
291
|
-
}
|
293
|
+
};
|
294
|
+
await provider?.onAccountChange(handleChangeAccount);
|
292
295
|
} catch (error: any) {
|
293
296
|
const errMsg = error.message;
|
294
297
|
this.emit('error', new WalletAccountChangeError(errMsg));
|