@manahippo/aptos-wallet-adapter 1.0.1 → 1.0.3
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 +8 -6
- package/dist/WalletAdapters/BloctoWallet.d.ts +3 -3
- package/dist/WalletAdapters/BloctoWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/BloctoWallet.js +1 -3
- package/dist/WalletAdapters/BloctoWallet.js.map +1 -1
- 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/FoxWallet.d.ts +64 -0
- package/dist/WalletAdapters/FoxWallet.d.ts.map +1 -0
- package/dist/WalletAdapters/FoxWallet.js +239 -0
- package/dist/WalletAdapters/FoxWallet.js.map +1 -0
- package/dist/WalletAdapters/HyperPayWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/HyperPayWallet.js +2 -2
- package/dist/WalletAdapters/HyperPayWallet.js.map +1 -1
- package/dist/WalletAdapters/MsafeWallet.d.ts +39 -0
- package/dist/WalletAdapters/MsafeWallet.d.ts.map +1 -0
- package/dist/WalletAdapters/MsafeWallet.js +225 -0
- package/dist/WalletAdapters/MsafeWallet.js.map +1 -0
- package/dist/WalletAdapters/NightlyWallet.js +2 -2
- package/dist/WalletAdapters/NightlyWallet.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/SpikaWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/SpikaWallet.js +1 -1
- package/dist/WalletAdapters/SpikaWallet.js.map +1 -1
- package/dist/WalletAdapters/index.d.ts +4 -0
- package/dist/WalletAdapters/index.d.ts.map +1 -1
- package/dist/WalletAdapters/index.js +4 -0
- package/dist/WalletAdapters/index.js.map +1 -1
- package/dist/WalletProviders/WalletProvider.d.ts.map +1 -1
- package/dist/WalletProviders/WalletProvider.js +35 -6
- package/dist/WalletProviders/WalletProvider.js.map +1 -1
- package/dist/utilities/util.d.ts +4 -0
- package/dist/utilities/util.d.ts.map +1 -1
- package/dist/utilities/util.js +23 -1
- package/dist/utilities/util.js.map +1 -1
- package/package.json +4 -3
- package/src/WalletAdapters/BloctoWallet.ts +7 -7
- package/src/WalletAdapters/Coin98Wallet.ts +310 -0
- package/src/WalletAdapters/FoxWallet.ts +312 -0
- package/src/WalletAdapters/HyperPayWallet.ts +2 -2
- package/src/WalletAdapters/MsafeWallet.ts +261 -0
- package/src/WalletAdapters/NightlyWallet.ts +2 -2
- package/src/WalletAdapters/SafePalWallet.ts +319 -0
- package/src/WalletAdapters/SpikaWallet.ts +1 -1
- package/src/WalletAdapters/index.ts +4 -0
- package/src/WalletProviders/WalletProvider.tsx +37 -7
- package/src/utilities/util.ts +13 -0
package/dist/utilities/util.js
CHANGED
@@ -1,6 +1,15 @@
|
|
1
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
|
+
};
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.payloadV1ToV0 = void 0;
|
12
|
+
exports.timeoutPromise = exports.payloadV1ToV0 = void 0;
|
4
13
|
const payloadV1ToV0 = (payload) => {
|
5
14
|
const v1 = payload;
|
6
15
|
return {
|
@@ -11,4 +20,17 @@ const payloadV1ToV0 = (payload) => {
|
|
11
20
|
};
|
12
21
|
};
|
13
22
|
exports.payloadV1ToV0 = payloadV1ToV0;
|
23
|
+
const timeoutPromise = (timeout) => {
|
24
|
+
let timeoutId;
|
25
|
+
const promise = new Promise((resolve, reject) => {
|
26
|
+
timeoutId = setTimeout(() => __awaiter(void 0, void 0, void 0, function* () {
|
27
|
+
reject('timeout');
|
28
|
+
}), timeout);
|
29
|
+
});
|
30
|
+
return {
|
31
|
+
timeoutId,
|
32
|
+
promise
|
33
|
+
};
|
34
|
+
};
|
35
|
+
exports.timeoutPromise = timeoutPromise;
|
14
36
|
//# sourceMappingURL=util.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/utilities/util.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/utilities/util.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEO,MAAM,aAAa,GAAG,CAAC,OAAiC,EAAE,EAAE;IACjE,MAAM,EAAE,GAAG,OAAwD,CAAC;IACpE,OAAO;QACL,IAAI,EAAE,yBAAyB;QAC/B,QAAQ,EAAE,EAAE,CAAC,QAAQ;QACrB,cAAc,EAAE,EAAE,CAAC,cAAc;QACjC,SAAS,EAAE,EAAE,CAAC,SAAS;KACxB,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,aAAa,iBAQxB;AAEK,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,EAAE;IACxC,IAAI,SAAS,CAAC;IACd,MAAM,OAAO,GAAkB,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC7D,SAAS,GAAG,UAAU,CAAC,GAAS,EAAE;YAChC,MAAM,CAAC,SAAS,CAAC,CAAC;QACpB,CAAC,CAAA,EAAE,OAAO,CAAC,CAAC;IACd,CAAC,CAAC,CAAC;IACH,OAAO;QACL,SAAS;QACT,OAAO;KACR,CAAC;AACJ,CAAC,CAAC;AAXW,QAAA,cAAc,kBAWzB"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@manahippo/aptos-wallet-adapter",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.3",
|
4
4
|
"main": "dist/index.js",
|
5
5
|
"typings": "dist/index.d.ts",
|
6
6
|
"files": [
|
@@ -28,10 +28,11 @@
|
|
28
28
|
"typescript": "^4.7.4"
|
29
29
|
},
|
30
30
|
"dependencies": {
|
31
|
-
"@blocto/sdk": "^0.3.
|
31
|
+
"@blocto/sdk": "^0.3.1",
|
32
32
|
"@fewcha/web3": "0.1.32",
|
33
33
|
"@keystonehq/aptossnap-adapter": "^0.2.8",
|
34
34
|
"eventemitter3": "^4.0.7",
|
35
|
-
"js-sha3": "^0.8.0"
|
35
|
+
"js-sha3": "^0.8.0",
|
36
|
+
"msafe-iframe": "^1.0.8"
|
36
37
|
}
|
37
38
|
}
|
@@ -26,9 +26,9 @@ export const BloctoWalletName = 'Blocto' as WalletName<'Blocto'>;
|
|
26
26
|
|
27
27
|
export interface BloctoWalletAdapterConfig {
|
28
28
|
provider?: IBloctoAptos;
|
29
|
-
network
|
29
|
+
network?: Exclude<WalletAdapterNetwork, WalletAdapterNetwork.Devnet>;
|
30
30
|
timeout?: number;
|
31
|
-
bloctoAppId
|
31
|
+
bloctoAppId: string;
|
32
32
|
}
|
33
33
|
|
34
34
|
export const APTOS_NETWORK_CHAIN_ID_MAPPING = {
|
@@ -64,11 +64,11 @@ export class BloctoWalletAdapter extends BaseWalletAdapter {
|
|
64
64
|
|
65
65
|
protected _wallet: any | null;
|
66
66
|
|
67
|
-
constructor(
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
) {
|
67
|
+
constructor({
|
68
|
+
network = WalletAdapterNetwork.Mainnet,
|
69
|
+
timeout = 10000,
|
70
|
+
bloctoAppId
|
71
|
+
}: BloctoWalletAdapterConfig) {
|
72
72
|
super();
|
73
73
|
|
74
74
|
const sdk = new BloctoSDK({
|
@@ -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
|
+
}
|