@megaeth-labs/wallet-sdk 0.1.0-beta.1
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 +42 -0
- package/dist/index.cjs +319 -0
- package/dist/index.d.cts +157 -0
- package/dist/index.d.ts +157 -0
- package/dist/index.js +282 -0
- package/package.json +68 -0
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# MegaETH Wallet SDK
|
|
2
|
+
|
|
3
|
+
Distributed to partners to work with the MegaETH wallet. Is responsible for loading the wallet inside an iFrame and
|
|
4
|
+
communicating with it.
|
|
5
|
+
|
|
6
|
+
## Setup
|
|
7
|
+
|
|
8
|
+
Install dependencies: `pnpm i`
|
|
9
|
+
|
|
10
|
+
Link package locally so other packages can use it: `pnpm dev:link`
|
|
11
|
+
|
|
12
|
+
Auto build during dev: `pnpm dev`
|
|
13
|
+
|
|
14
|
+
Build once: `pnpm build`
|
|
15
|
+
|
|
16
|
+
## How It Works
|
|
17
|
+
|
|
18
|
+
The bulk of the logic can be found in the `src/wallet.ts` file. It handles the initialization of the wallet,
|
|
19
|
+
communication with the iframe, and event handling. It exposes a object `mega` which contains all the methods to initialise and communicate with the iFrame.
|
|
20
|
+
|
|
21
|
+
Communication is handled using the `penpal` library which ensures that messages are sent and received securely and reliably between the parent window and the iframe.
|
|
22
|
+
|
|
23
|
+
**Initialisation Flow**
|
|
24
|
+
Calling `mega.initialise()` triggers the following steps:
|
|
25
|
+
1. iFrame is created and loaded
|
|
26
|
+
2. Penpal is initialised to handle communication with the iFrame
|
|
27
|
+
3. A method `ready` is exposed to the iFrame
|
|
28
|
+
4. The iFrame loads and checks wallet status and then calls `ready` in the parent window
|
|
29
|
+
|
|
30
|
+
**Methods**
|
|
31
|
+
Each of the available methods can be found in the `src/outbound-methods` folder and follow the same pattern:
|
|
32
|
+
1. Validate the request
|
|
33
|
+
2. Use `Remote.remote.methodName` to call the method in the iFrame
|
|
34
|
+
3. The promise remains open until the iFrame responds
|
|
35
|
+
4. Result is returned
|
|
36
|
+
|
|
37
|
+
For example:
|
|
38
|
+
```typescript
|
|
39
|
+
const {signature, status} = await mega.signMessage('Hello World');
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
All request and return types are defined in the `src/types.ts` file.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
mega: () => mega
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
|
|
37
|
+
// src/wallet.ts
|
|
38
|
+
var Penpal = __toESM(require("penpal"), 1);
|
|
39
|
+
|
|
40
|
+
// src/callbacks.ts
|
|
41
|
+
var onStatusChange;
|
|
42
|
+
var callbacks_default = {
|
|
43
|
+
onStatusChange
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// src/events.ts
|
|
47
|
+
var onStatusChange2 = (callback) => {
|
|
48
|
+
callbacks_default.onStatusChange = callback;
|
|
49
|
+
};
|
|
50
|
+
var events = {
|
|
51
|
+
onStatusChange: onStatusChange2
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// src/consts.ts
|
|
55
|
+
var WALLET_URL = "https://account.megaeth.com";
|
|
56
|
+
var LOCAL_WALLET_URL = "http://localhost:4000";
|
|
57
|
+
|
|
58
|
+
// src/helpers.ts
|
|
59
|
+
var getWalletUrl = (config) => {
|
|
60
|
+
const origin = config.devMode ? LOCAL_WALLET_URL : WALLET_URL;
|
|
61
|
+
const params = [
|
|
62
|
+
`network=${config.network}`,
|
|
63
|
+
...config.sponsorUrl ? [`sponsorUrl=${config.sponsorUrl}`] : [],
|
|
64
|
+
...config.debug ? [`debug=${config.debug}`] : [],
|
|
65
|
+
...config.logging ? [`logging=${config.logging}`] : []
|
|
66
|
+
];
|
|
67
|
+
return {
|
|
68
|
+
origin,
|
|
69
|
+
uiUrl: `${origin}?${params.join("&")}`
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// src/state.ts
|
|
74
|
+
var State = class {
|
|
75
|
+
constructor() {
|
|
76
|
+
this.initialised = false;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
var state_default = new State();
|
|
80
|
+
|
|
81
|
+
// src/inbound-methods/hide.ts
|
|
82
|
+
var hide = () => {
|
|
83
|
+
state_default.iframe.style.display = "none";
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// src/inbound-methods/setStatus.ts
|
|
87
|
+
var setStatus = (status2) => {
|
|
88
|
+
callbacks_default.onStatusChange?.(status2);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// src/inbound-methods/show.ts
|
|
92
|
+
var show = () => {
|
|
93
|
+
state_default.iframe.style.display = "block";
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// src/inbound-methods/index.ts
|
|
97
|
+
var inboundMethods = {
|
|
98
|
+
show,
|
|
99
|
+
hide,
|
|
100
|
+
setStatus
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// src/logger.ts
|
|
104
|
+
var _Logger = class _Logger {
|
|
105
|
+
static setLogLevel(level) {
|
|
106
|
+
_Logger.logLevel = level;
|
|
107
|
+
}
|
|
108
|
+
static debug(module2, message, data) {
|
|
109
|
+
_Logger.log("debug", module2, message, data);
|
|
110
|
+
}
|
|
111
|
+
static info(module2, message, data) {
|
|
112
|
+
_Logger.log("info", module2, message, data);
|
|
113
|
+
}
|
|
114
|
+
static warn(module2, message, data) {
|
|
115
|
+
_Logger.log("warn", module2, message, data);
|
|
116
|
+
}
|
|
117
|
+
static error(module2, message, data) {
|
|
118
|
+
_Logger.log("error", module2, message, data);
|
|
119
|
+
}
|
|
120
|
+
static shouldLog(level) {
|
|
121
|
+
switch (_Logger.logLevel) {
|
|
122
|
+
case "debug":
|
|
123
|
+
return true;
|
|
124
|
+
case "info":
|
|
125
|
+
return ["info", "warn", "error"].includes(level);
|
|
126
|
+
case "warn":
|
|
127
|
+
return ["warn", "error"].includes(level);
|
|
128
|
+
case "error":
|
|
129
|
+
return level === "error";
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
static getMessage(module2, message) {
|
|
133
|
+
return `[${module2}] ${message}`;
|
|
134
|
+
}
|
|
135
|
+
static log(level, module2, message, data) {
|
|
136
|
+
if (!_Logger.shouldLog(level)) return;
|
|
137
|
+
const formattedMessage = _Logger.getMessage(module2, message);
|
|
138
|
+
const params = [formattedMessage];
|
|
139
|
+
if (data) {
|
|
140
|
+
params.push(data);
|
|
141
|
+
}
|
|
142
|
+
switch (level) {
|
|
143
|
+
case "debug":
|
|
144
|
+
console.debug(...params);
|
|
145
|
+
break;
|
|
146
|
+
case "info":
|
|
147
|
+
console.info(...params);
|
|
148
|
+
break;
|
|
149
|
+
case "warn":
|
|
150
|
+
console.warn(...params);
|
|
151
|
+
break;
|
|
152
|
+
case "error":
|
|
153
|
+
console.error(...params);
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
_Logger.logLevel = "error";
|
|
159
|
+
var Logger = _Logger;
|
|
160
|
+
|
|
161
|
+
// src/outbound-methods/balances.ts
|
|
162
|
+
var balances = async (request) => {
|
|
163
|
+
return state_default.remote.balances(request);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// src/outbound-methods/callContract.ts
|
|
167
|
+
var callContract = (request) => {
|
|
168
|
+
return state_default.remote.callContract(request);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// src/outbound-methods/connect.ts
|
|
172
|
+
var connect = async () => {
|
|
173
|
+
Logger.debug("connect", "Connect wallet triggered...");
|
|
174
|
+
const result = await state_default.remote.connect();
|
|
175
|
+
Logger.debug("connect", "Connect resolved", result);
|
|
176
|
+
return result;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// src/outbound-methods/deposit.ts
|
|
180
|
+
var deposit = () => {
|
|
181
|
+
return state_default.remote.deposit();
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// src/outbound-methods/disconnect.ts
|
|
185
|
+
var disconnect = async () => {
|
|
186
|
+
Logger.debug("disconnect", "Disconnect wallet triggered...");
|
|
187
|
+
const result = await state_default.remote.disconnect();
|
|
188
|
+
Logger.debug("disconnect", "Disconnect resolved");
|
|
189
|
+
return result;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// src/outbound-methods/getFromContract.ts
|
|
193
|
+
var getFromContract = async (request) => {
|
|
194
|
+
const result = await state_default.remote.getFromContract(request);
|
|
195
|
+
return result;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
// src/outbound-methods/getPermissions.ts
|
|
199
|
+
var getPermissions = (address) => {
|
|
200
|
+
return state_default.remote.getPermissions(address);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// src/outbound-methods/grantPermissions.ts
|
|
204
|
+
var grantPermissions = (request) => {
|
|
205
|
+
return state_default.remote.grantPermissions(request);
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// src/outbound-methods/open.ts
|
|
209
|
+
var open = async () => {
|
|
210
|
+
return state_default.remote.open();
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// src/outbound-methods/revokePermissions.ts
|
|
214
|
+
var revokePermissions = () => {
|
|
215
|
+
return state_default.remote.revokePermissions();
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// src/outbound-methods/signData.ts
|
|
219
|
+
var signData = (request) => {
|
|
220
|
+
return state_default.remote.signData(request);
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// src/outbound-methods/signMessage.ts
|
|
224
|
+
var signMessage = (message) => {
|
|
225
|
+
return state_default.remote.signMessage(message);
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// src/outbound-methods/status.ts
|
|
229
|
+
var status = () => {
|
|
230
|
+
return state_default.remote.status();
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// src/outbound-methods/transfer.ts
|
|
234
|
+
var transfer = (request) => {
|
|
235
|
+
return state_default.remote.transfer(request);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
// src/outbound-methods/index.ts
|
|
239
|
+
var outboundMethods = {
|
|
240
|
+
status,
|
|
241
|
+
callContract,
|
|
242
|
+
connect,
|
|
243
|
+
disconnect,
|
|
244
|
+
transfer,
|
|
245
|
+
signMessage,
|
|
246
|
+
grantPermissions,
|
|
247
|
+
revokePermissions,
|
|
248
|
+
getPermissions,
|
|
249
|
+
deposit,
|
|
250
|
+
balances,
|
|
251
|
+
open,
|
|
252
|
+
signData,
|
|
253
|
+
getFromContract
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// src/wallet.ts
|
|
257
|
+
var createIFrame = (url) => {
|
|
258
|
+
const iframe = document.createElement("iframe");
|
|
259
|
+
iframe.style.position = "fixed";
|
|
260
|
+
iframe.style.top = "0";
|
|
261
|
+
iframe.style.left = "0";
|
|
262
|
+
iframe.style.height = "100vh";
|
|
263
|
+
iframe.style.width = "100vw";
|
|
264
|
+
iframe.style.border = "none";
|
|
265
|
+
iframe.style.zIndex = "9999";
|
|
266
|
+
iframe.style.display = "none";
|
|
267
|
+
iframe.setAttribute(
|
|
268
|
+
"allow",
|
|
269
|
+
"clipboard-write; publickey-credentials-get *; publickey-credentials-create *"
|
|
270
|
+
);
|
|
271
|
+
iframe.src = url;
|
|
272
|
+
document.body.appendChild(iframe);
|
|
273
|
+
return iframe;
|
|
274
|
+
};
|
|
275
|
+
var initialise = async (config) => {
|
|
276
|
+
if (state_default.initialised) return;
|
|
277
|
+
state_default.initialised = true;
|
|
278
|
+
state_default.network = config?.network || "mainnet";
|
|
279
|
+
Logger.setLogLevel(config?.logging || "error");
|
|
280
|
+
Logger.debug("SDK", "Initialising...");
|
|
281
|
+
const { origin, uiUrl } = getWalletUrl(config);
|
|
282
|
+
state_default.iframe = createIFrame(uiUrl);
|
|
283
|
+
const messenger = new Penpal.WindowMessenger({
|
|
284
|
+
remoteWindow: state_default.iframe.contentWindow,
|
|
285
|
+
allowedOrigins: [origin]
|
|
286
|
+
});
|
|
287
|
+
return new Promise((resolve, reject) => {
|
|
288
|
+
try {
|
|
289
|
+
const connection = Penpal.connect({
|
|
290
|
+
messenger,
|
|
291
|
+
log: config?.debug ? Penpal.debug("SDK") : void 0,
|
|
292
|
+
methods: {
|
|
293
|
+
ready: async () => {
|
|
294
|
+
Logger.debug("SDK", "Initialised");
|
|
295
|
+
const status2 = await state_default.remote.status();
|
|
296
|
+
Logger.debug("SDK", `Status: ${status2.status}, Address: ${status2.address}`);
|
|
297
|
+
callbacks_default.onStatusChange?.(status2);
|
|
298
|
+
resolve(status2);
|
|
299
|
+
},
|
|
300
|
+
...inboundMethods
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
connection.promise.then((_remote) => {
|
|
304
|
+
state_default.remote = _remote;
|
|
305
|
+
});
|
|
306
|
+
} catch (e) {
|
|
307
|
+
reject(e);
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
};
|
|
311
|
+
var mega = {
|
|
312
|
+
initialise,
|
|
313
|
+
events,
|
|
314
|
+
...outboundMethods
|
|
315
|
+
};
|
|
316
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
317
|
+
0 && (module.exports = {
|
|
318
|
+
mega
|
|
319
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
type Network = 'mainnet' | 'testnet';
|
|
2
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
3
|
+
interface Config {
|
|
4
|
+
network: Network;
|
|
5
|
+
logging?: LogLevel;
|
|
6
|
+
devMode?: boolean;
|
|
7
|
+
debug?: boolean;
|
|
8
|
+
sponsorUrl?: string;
|
|
9
|
+
}
|
|
10
|
+
type ConnectionStatus = {
|
|
11
|
+
status: 'connected' | 'disconnected' | 'cancelled';
|
|
12
|
+
address?: `0x${string}`;
|
|
13
|
+
};
|
|
14
|
+
interface TransferRequest {
|
|
15
|
+
amount: string;
|
|
16
|
+
to: `0x${string}`;
|
|
17
|
+
type: 'native' | 'erc20' | 'erc721' | 'erc1155';
|
|
18
|
+
contractAddress?: string;
|
|
19
|
+
tokenId?: number;
|
|
20
|
+
silent?: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface CallContractRequest {
|
|
23
|
+
address: `0x${string}`;
|
|
24
|
+
abi: any;
|
|
25
|
+
functionName: string;
|
|
26
|
+
args: any[];
|
|
27
|
+
silent?: boolean;
|
|
28
|
+
}
|
|
29
|
+
interface GetFromContractRequest {
|
|
30
|
+
address: `0x${string}`;
|
|
31
|
+
abi: any;
|
|
32
|
+
functionName: string;
|
|
33
|
+
args: any[];
|
|
34
|
+
}
|
|
35
|
+
interface TransactionResult {
|
|
36
|
+
status: 'approved' | 'cancelled' | 'error';
|
|
37
|
+
receipt?: {
|
|
38
|
+
hash: string;
|
|
39
|
+
};
|
|
40
|
+
error?: string;
|
|
41
|
+
}
|
|
42
|
+
interface SignMessageResponse {
|
|
43
|
+
status: 'success' | 'cancelled' | 'error';
|
|
44
|
+
error?: string;
|
|
45
|
+
signature?: `0x${string}`;
|
|
46
|
+
}
|
|
47
|
+
interface GetPermissionsResponse {
|
|
48
|
+
permissions?: {
|
|
49
|
+
expiry: number;
|
|
50
|
+
permissions: {
|
|
51
|
+
calls: {
|
|
52
|
+
signature: string;
|
|
53
|
+
to?: `0x${string}`;
|
|
54
|
+
}[];
|
|
55
|
+
spend: {
|
|
56
|
+
limit: bigint;
|
|
57
|
+
period: 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year';
|
|
58
|
+
token?: `0x${string}`;
|
|
59
|
+
}[];
|
|
60
|
+
};
|
|
61
|
+
} | null;
|
|
62
|
+
}
|
|
63
|
+
interface RemoteAPI {
|
|
64
|
+
status: () => ConnectionStatus;
|
|
65
|
+
connect: () => Promise<ConnectionStatus>;
|
|
66
|
+
disconnect: () => Promise<ConnectionStatus>;
|
|
67
|
+
transfer: (request: TransferRequest) => Promise<TransactionResult>;
|
|
68
|
+
callContract: (request: CallContractRequest) => Promise<TransactionResult>;
|
|
69
|
+
getFromContract: <T>(request: GetFromContractRequest) => Promise<T>;
|
|
70
|
+
signMessage: (message: string) => Promise<SignMessageResponse>;
|
|
71
|
+
grantPermissions: (request: GrantPermissionsRequest) => Promise<GrantPermissionsResponse>;
|
|
72
|
+
revokePermissions: () => Promise<void>;
|
|
73
|
+
getPermissions: (address?: string) => Promise<GetPermissionsResponse | undefined>;
|
|
74
|
+
deposit: () => Promise<void>;
|
|
75
|
+
balances: (request: BalancesRequest) => Promise<OwnedTokenResponse[]>;
|
|
76
|
+
signData: (request: SignDataRequest) => Promise<SignDataResponse>;
|
|
77
|
+
open: () => Promise<void>;
|
|
78
|
+
[key: string]: any;
|
|
79
|
+
}
|
|
80
|
+
interface Permission {
|
|
81
|
+
id?: string;
|
|
82
|
+
expiry: number;
|
|
83
|
+
feeToken: {
|
|
84
|
+
limit: string;
|
|
85
|
+
symbol?: string;
|
|
86
|
+
};
|
|
87
|
+
permissions: {
|
|
88
|
+
calls: {
|
|
89
|
+
signature?: string;
|
|
90
|
+
to?: string;
|
|
91
|
+
}[];
|
|
92
|
+
spend: {
|
|
93
|
+
limit: bigint;
|
|
94
|
+
period: 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year';
|
|
95
|
+
token?: `0x${string}`;
|
|
96
|
+
}[];
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
interface GrantPermissionsRequest {
|
|
100
|
+
permissions: Permission;
|
|
101
|
+
externalAddress?: `0x${string}`;
|
|
102
|
+
}
|
|
103
|
+
type GrantPermissionsResponse = {
|
|
104
|
+
status: 'approved' | 'cancelled';
|
|
105
|
+
};
|
|
106
|
+
interface BalancesRequest {
|
|
107
|
+
tokens?: string[];
|
|
108
|
+
}
|
|
109
|
+
interface BaseTokenResponse {
|
|
110
|
+
name: string;
|
|
111
|
+
symbol: string;
|
|
112
|
+
decimals: number;
|
|
113
|
+
address: string;
|
|
114
|
+
image?: string;
|
|
115
|
+
usdPrice?: string;
|
|
116
|
+
}
|
|
117
|
+
interface OwnedTokenResponse extends BaseTokenResponse {
|
|
118
|
+
balance: string;
|
|
119
|
+
displayBalance: string;
|
|
120
|
+
usdPrice?: string;
|
|
121
|
+
usdBalance?: string;
|
|
122
|
+
marketCap?: string;
|
|
123
|
+
volume?: string;
|
|
124
|
+
holders?: number;
|
|
125
|
+
percentChange?: number;
|
|
126
|
+
}
|
|
127
|
+
interface SignDataRequest {
|
|
128
|
+
data: any;
|
|
129
|
+
}
|
|
130
|
+
interface SignDataResponse {
|
|
131
|
+
status: 'success' | 'cancelled' | 'error';
|
|
132
|
+
error?: string;
|
|
133
|
+
signature?: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
declare const mega: {
|
|
137
|
+
status: () => Promise<ConnectionStatus>;
|
|
138
|
+
callContract: (request: CallContractRequest) => Promise<TransactionResult>;
|
|
139
|
+
connect: () => Promise<ConnectionStatus>;
|
|
140
|
+
disconnect: () => Promise<ConnectionStatus>;
|
|
141
|
+
transfer: (request: TransferRequest) => Promise<TransactionResult>;
|
|
142
|
+
signMessage: (message: string) => Promise<SignMessageResponse>;
|
|
143
|
+
grantPermissions: (request: GrantPermissionsRequest) => Promise<GrantPermissionsResponse>;
|
|
144
|
+
revokePermissions: () => Promise<void>;
|
|
145
|
+
getPermissions: (address?: string) => Promise<GetPermissionsResponse | undefined>;
|
|
146
|
+
deposit: () => Promise<void>;
|
|
147
|
+
balances: (request: BalancesRequest) => Promise<OwnedTokenResponse[]>;
|
|
148
|
+
open: () => Promise<void>;
|
|
149
|
+
signData: (request: SignDataRequest) => Promise<SignDataResponse>;
|
|
150
|
+
getFromContract: <T>(request: GetFromContractRequest) => Promise<T>;
|
|
151
|
+
initialise: (config: Config) => Promise<ConnectionStatus | undefined>;
|
|
152
|
+
events: {
|
|
153
|
+
onStatusChange: (callback: (status: ConnectionStatus) => void) => void;
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export { type BalancesRequest, type BaseTokenResponse, type CallContractRequest, type Config, type ConnectionStatus, type GetFromContractRequest, type GetPermissionsResponse, type GrantPermissionsRequest, type GrantPermissionsResponse, type LogLevel, type Network, type OwnedTokenResponse, type Permission, type RemoteAPI, type SignDataRequest, type SignDataResponse, type SignMessageResponse, type TransactionResult, type TransferRequest, mega };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
type Network = 'mainnet' | 'testnet';
|
|
2
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
3
|
+
interface Config {
|
|
4
|
+
network: Network;
|
|
5
|
+
logging?: LogLevel;
|
|
6
|
+
devMode?: boolean;
|
|
7
|
+
debug?: boolean;
|
|
8
|
+
sponsorUrl?: string;
|
|
9
|
+
}
|
|
10
|
+
type ConnectionStatus = {
|
|
11
|
+
status: 'connected' | 'disconnected' | 'cancelled';
|
|
12
|
+
address?: `0x${string}`;
|
|
13
|
+
};
|
|
14
|
+
interface TransferRequest {
|
|
15
|
+
amount: string;
|
|
16
|
+
to: `0x${string}`;
|
|
17
|
+
type: 'native' | 'erc20' | 'erc721' | 'erc1155';
|
|
18
|
+
contractAddress?: string;
|
|
19
|
+
tokenId?: number;
|
|
20
|
+
silent?: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface CallContractRequest {
|
|
23
|
+
address: `0x${string}`;
|
|
24
|
+
abi: any;
|
|
25
|
+
functionName: string;
|
|
26
|
+
args: any[];
|
|
27
|
+
silent?: boolean;
|
|
28
|
+
}
|
|
29
|
+
interface GetFromContractRequest {
|
|
30
|
+
address: `0x${string}`;
|
|
31
|
+
abi: any;
|
|
32
|
+
functionName: string;
|
|
33
|
+
args: any[];
|
|
34
|
+
}
|
|
35
|
+
interface TransactionResult {
|
|
36
|
+
status: 'approved' | 'cancelled' | 'error';
|
|
37
|
+
receipt?: {
|
|
38
|
+
hash: string;
|
|
39
|
+
};
|
|
40
|
+
error?: string;
|
|
41
|
+
}
|
|
42
|
+
interface SignMessageResponse {
|
|
43
|
+
status: 'success' | 'cancelled' | 'error';
|
|
44
|
+
error?: string;
|
|
45
|
+
signature?: `0x${string}`;
|
|
46
|
+
}
|
|
47
|
+
interface GetPermissionsResponse {
|
|
48
|
+
permissions?: {
|
|
49
|
+
expiry: number;
|
|
50
|
+
permissions: {
|
|
51
|
+
calls: {
|
|
52
|
+
signature: string;
|
|
53
|
+
to?: `0x${string}`;
|
|
54
|
+
}[];
|
|
55
|
+
spend: {
|
|
56
|
+
limit: bigint;
|
|
57
|
+
period: 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year';
|
|
58
|
+
token?: `0x${string}`;
|
|
59
|
+
}[];
|
|
60
|
+
};
|
|
61
|
+
} | null;
|
|
62
|
+
}
|
|
63
|
+
interface RemoteAPI {
|
|
64
|
+
status: () => ConnectionStatus;
|
|
65
|
+
connect: () => Promise<ConnectionStatus>;
|
|
66
|
+
disconnect: () => Promise<ConnectionStatus>;
|
|
67
|
+
transfer: (request: TransferRequest) => Promise<TransactionResult>;
|
|
68
|
+
callContract: (request: CallContractRequest) => Promise<TransactionResult>;
|
|
69
|
+
getFromContract: <T>(request: GetFromContractRequest) => Promise<T>;
|
|
70
|
+
signMessage: (message: string) => Promise<SignMessageResponse>;
|
|
71
|
+
grantPermissions: (request: GrantPermissionsRequest) => Promise<GrantPermissionsResponse>;
|
|
72
|
+
revokePermissions: () => Promise<void>;
|
|
73
|
+
getPermissions: (address?: string) => Promise<GetPermissionsResponse | undefined>;
|
|
74
|
+
deposit: () => Promise<void>;
|
|
75
|
+
balances: (request: BalancesRequest) => Promise<OwnedTokenResponse[]>;
|
|
76
|
+
signData: (request: SignDataRequest) => Promise<SignDataResponse>;
|
|
77
|
+
open: () => Promise<void>;
|
|
78
|
+
[key: string]: any;
|
|
79
|
+
}
|
|
80
|
+
interface Permission {
|
|
81
|
+
id?: string;
|
|
82
|
+
expiry: number;
|
|
83
|
+
feeToken: {
|
|
84
|
+
limit: string;
|
|
85
|
+
symbol?: string;
|
|
86
|
+
};
|
|
87
|
+
permissions: {
|
|
88
|
+
calls: {
|
|
89
|
+
signature?: string;
|
|
90
|
+
to?: string;
|
|
91
|
+
}[];
|
|
92
|
+
spend: {
|
|
93
|
+
limit: bigint;
|
|
94
|
+
period: 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year';
|
|
95
|
+
token?: `0x${string}`;
|
|
96
|
+
}[];
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
interface GrantPermissionsRequest {
|
|
100
|
+
permissions: Permission;
|
|
101
|
+
externalAddress?: `0x${string}`;
|
|
102
|
+
}
|
|
103
|
+
type GrantPermissionsResponse = {
|
|
104
|
+
status: 'approved' | 'cancelled';
|
|
105
|
+
};
|
|
106
|
+
interface BalancesRequest {
|
|
107
|
+
tokens?: string[];
|
|
108
|
+
}
|
|
109
|
+
interface BaseTokenResponse {
|
|
110
|
+
name: string;
|
|
111
|
+
symbol: string;
|
|
112
|
+
decimals: number;
|
|
113
|
+
address: string;
|
|
114
|
+
image?: string;
|
|
115
|
+
usdPrice?: string;
|
|
116
|
+
}
|
|
117
|
+
interface OwnedTokenResponse extends BaseTokenResponse {
|
|
118
|
+
balance: string;
|
|
119
|
+
displayBalance: string;
|
|
120
|
+
usdPrice?: string;
|
|
121
|
+
usdBalance?: string;
|
|
122
|
+
marketCap?: string;
|
|
123
|
+
volume?: string;
|
|
124
|
+
holders?: number;
|
|
125
|
+
percentChange?: number;
|
|
126
|
+
}
|
|
127
|
+
interface SignDataRequest {
|
|
128
|
+
data: any;
|
|
129
|
+
}
|
|
130
|
+
interface SignDataResponse {
|
|
131
|
+
status: 'success' | 'cancelled' | 'error';
|
|
132
|
+
error?: string;
|
|
133
|
+
signature?: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
declare const mega: {
|
|
137
|
+
status: () => Promise<ConnectionStatus>;
|
|
138
|
+
callContract: (request: CallContractRequest) => Promise<TransactionResult>;
|
|
139
|
+
connect: () => Promise<ConnectionStatus>;
|
|
140
|
+
disconnect: () => Promise<ConnectionStatus>;
|
|
141
|
+
transfer: (request: TransferRequest) => Promise<TransactionResult>;
|
|
142
|
+
signMessage: (message: string) => Promise<SignMessageResponse>;
|
|
143
|
+
grantPermissions: (request: GrantPermissionsRequest) => Promise<GrantPermissionsResponse>;
|
|
144
|
+
revokePermissions: () => Promise<void>;
|
|
145
|
+
getPermissions: (address?: string) => Promise<GetPermissionsResponse | undefined>;
|
|
146
|
+
deposit: () => Promise<void>;
|
|
147
|
+
balances: (request: BalancesRequest) => Promise<OwnedTokenResponse[]>;
|
|
148
|
+
open: () => Promise<void>;
|
|
149
|
+
signData: (request: SignDataRequest) => Promise<SignDataResponse>;
|
|
150
|
+
getFromContract: <T>(request: GetFromContractRequest) => Promise<T>;
|
|
151
|
+
initialise: (config: Config) => Promise<ConnectionStatus | undefined>;
|
|
152
|
+
events: {
|
|
153
|
+
onStatusChange: (callback: (status: ConnectionStatus) => void) => void;
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export { type BalancesRequest, type BaseTokenResponse, type CallContractRequest, type Config, type ConnectionStatus, type GetFromContractRequest, type GetPermissionsResponse, type GrantPermissionsRequest, type GrantPermissionsResponse, type LogLevel, type Network, type OwnedTokenResponse, type Permission, type RemoteAPI, type SignDataRequest, type SignDataResponse, type SignMessageResponse, type TransactionResult, type TransferRequest, mega };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
// src/wallet.ts
|
|
2
|
+
import * as Penpal from "penpal";
|
|
3
|
+
|
|
4
|
+
// src/callbacks.ts
|
|
5
|
+
var onStatusChange;
|
|
6
|
+
var callbacks_default = {
|
|
7
|
+
onStatusChange
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// src/events.ts
|
|
11
|
+
var onStatusChange2 = (callback) => {
|
|
12
|
+
callbacks_default.onStatusChange = callback;
|
|
13
|
+
};
|
|
14
|
+
var events = {
|
|
15
|
+
onStatusChange: onStatusChange2
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// src/consts.ts
|
|
19
|
+
var WALLET_URL = "https://account.megaeth.com";
|
|
20
|
+
var LOCAL_WALLET_URL = "http://localhost:4000";
|
|
21
|
+
|
|
22
|
+
// src/helpers.ts
|
|
23
|
+
var getWalletUrl = (config) => {
|
|
24
|
+
const origin = config.devMode ? LOCAL_WALLET_URL : WALLET_URL;
|
|
25
|
+
const params = [
|
|
26
|
+
`network=${config.network}`,
|
|
27
|
+
...config.sponsorUrl ? [`sponsorUrl=${config.sponsorUrl}`] : [],
|
|
28
|
+
...config.debug ? [`debug=${config.debug}`] : [],
|
|
29
|
+
...config.logging ? [`logging=${config.logging}`] : []
|
|
30
|
+
];
|
|
31
|
+
return {
|
|
32
|
+
origin,
|
|
33
|
+
uiUrl: `${origin}?${params.join("&")}`
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// src/state.ts
|
|
38
|
+
var State = class {
|
|
39
|
+
constructor() {
|
|
40
|
+
this.initialised = false;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var state_default = new State();
|
|
44
|
+
|
|
45
|
+
// src/inbound-methods/hide.ts
|
|
46
|
+
var hide = () => {
|
|
47
|
+
state_default.iframe.style.display = "none";
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/inbound-methods/setStatus.ts
|
|
51
|
+
var setStatus = (status2) => {
|
|
52
|
+
callbacks_default.onStatusChange?.(status2);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// src/inbound-methods/show.ts
|
|
56
|
+
var show = () => {
|
|
57
|
+
state_default.iframe.style.display = "block";
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/inbound-methods/index.ts
|
|
61
|
+
var inboundMethods = {
|
|
62
|
+
show,
|
|
63
|
+
hide,
|
|
64
|
+
setStatus
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// src/logger.ts
|
|
68
|
+
var _Logger = class _Logger {
|
|
69
|
+
static setLogLevel(level) {
|
|
70
|
+
_Logger.logLevel = level;
|
|
71
|
+
}
|
|
72
|
+
static debug(module, message, data) {
|
|
73
|
+
_Logger.log("debug", module, message, data);
|
|
74
|
+
}
|
|
75
|
+
static info(module, message, data) {
|
|
76
|
+
_Logger.log("info", module, message, data);
|
|
77
|
+
}
|
|
78
|
+
static warn(module, message, data) {
|
|
79
|
+
_Logger.log("warn", module, message, data);
|
|
80
|
+
}
|
|
81
|
+
static error(module, message, data) {
|
|
82
|
+
_Logger.log("error", module, message, data);
|
|
83
|
+
}
|
|
84
|
+
static shouldLog(level) {
|
|
85
|
+
switch (_Logger.logLevel) {
|
|
86
|
+
case "debug":
|
|
87
|
+
return true;
|
|
88
|
+
case "info":
|
|
89
|
+
return ["info", "warn", "error"].includes(level);
|
|
90
|
+
case "warn":
|
|
91
|
+
return ["warn", "error"].includes(level);
|
|
92
|
+
case "error":
|
|
93
|
+
return level === "error";
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
static getMessage(module, message) {
|
|
97
|
+
return `[${module}] ${message}`;
|
|
98
|
+
}
|
|
99
|
+
static log(level, module, message, data) {
|
|
100
|
+
if (!_Logger.shouldLog(level)) return;
|
|
101
|
+
const formattedMessage = _Logger.getMessage(module, message);
|
|
102
|
+
const params = [formattedMessage];
|
|
103
|
+
if (data) {
|
|
104
|
+
params.push(data);
|
|
105
|
+
}
|
|
106
|
+
switch (level) {
|
|
107
|
+
case "debug":
|
|
108
|
+
console.debug(...params);
|
|
109
|
+
break;
|
|
110
|
+
case "info":
|
|
111
|
+
console.info(...params);
|
|
112
|
+
break;
|
|
113
|
+
case "warn":
|
|
114
|
+
console.warn(...params);
|
|
115
|
+
break;
|
|
116
|
+
case "error":
|
|
117
|
+
console.error(...params);
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
_Logger.logLevel = "error";
|
|
123
|
+
var Logger = _Logger;
|
|
124
|
+
|
|
125
|
+
// src/outbound-methods/balances.ts
|
|
126
|
+
var balances = async (request) => {
|
|
127
|
+
return state_default.remote.balances(request);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// src/outbound-methods/callContract.ts
|
|
131
|
+
var callContract = (request) => {
|
|
132
|
+
return state_default.remote.callContract(request);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// src/outbound-methods/connect.ts
|
|
136
|
+
var connect = async () => {
|
|
137
|
+
Logger.debug("connect", "Connect wallet triggered...");
|
|
138
|
+
const result = await state_default.remote.connect();
|
|
139
|
+
Logger.debug("connect", "Connect resolved", result);
|
|
140
|
+
return result;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// src/outbound-methods/deposit.ts
|
|
144
|
+
var deposit = () => {
|
|
145
|
+
return state_default.remote.deposit();
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// src/outbound-methods/disconnect.ts
|
|
149
|
+
var disconnect = async () => {
|
|
150
|
+
Logger.debug("disconnect", "Disconnect wallet triggered...");
|
|
151
|
+
const result = await state_default.remote.disconnect();
|
|
152
|
+
Logger.debug("disconnect", "Disconnect resolved");
|
|
153
|
+
return result;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// src/outbound-methods/getFromContract.ts
|
|
157
|
+
var getFromContract = async (request) => {
|
|
158
|
+
const result = await state_default.remote.getFromContract(request);
|
|
159
|
+
return result;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// src/outbound-methods/getPermissions.ts
|
|
163
|
+
var getPermissions = (address) => {
|
|
164
|
+
return state_default.remote.getPermissions(address);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// src/outbound-methods/grantPermissions.ts
|
|
168
|
+
var grantPermissions = (request) => {
|
|
169
|
+
return state_default.remote.grantPermissions(request);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// src/outbound-methods/open.ts
|
|
173
|
+
var open = async () => {
|
|
174
|
+
return state_default.remote.open();
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// src/outbound-methods/revokePermissions.ts
|
|
178
|
+
var revokePermissions = () => {
|
|
179
|
+
return state_default.remote.revokePermissions();
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// src/outbound-methods/signData.ts
|
|
183
|
+
var signData = (request) => {
|
|
184
|
+
return state_default.remote.signData(request);
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// src/outbound-methods/signMessage.ts
|
|
188
|
+
var signMessage = (message) => {
|
|
189
|
+
return state_default.remote.signMessage(message);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// src/outbound-methods/status.ts
|
|
193
|
+
var status = () => {
|
|
194
|
+
return state_default.remote.status();
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// src/outbound-methods/transfer.ts
|
|
198
|
+
var transfer = (request) => {
|
|
199
|
+
return state_default.remote.transfer(request);
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// src/outbound-methods/index.ts
|
|
203
|
+
var outboundMethods = {
|
|
204
|
+
status,
|
|
205
|
+
callContract,
|
|
206
|
+
connect,
|
|
207
|
+
disconnect,
|
|
208
|
+
transfer,
|
|
209
|
+
signMessage,
|
|
210
|
+
grantPermissions,
|
|
211
|
+
revokePermissions,
|
|
212
|
+
getPermissions,
|
|
213
|
+
deposit,
|
|
214
|
+
balances,
|
|
215
|
+
open,
|
|
216
|
+
signData,
|
|
217
|
+
getFromContract
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
// src/wallet.ts
|
|
221
|
+
var createIFrame = (url) => {
|
|
222
|
+
const iframe = document.createElement("iframe");
|
|
223
|
+
iframe.style.position = "fixed";
|
|
224
|
+
iframe.style.top = "0";
|
|
225
|
+
iframe.style.left = "0";
|
|
226
|
+
iframe.style.height = "100vh";
|
|
227
|
+
iframe.style.width = "100vw";
|
|
228
|
+
iframe.style.border = "none";
|
|
229
|
+
iframe.style.zIndex = "9999";
|
|
230
|
+
iframe.style.display = "none";
|
|
231
|
+
iframe.setAttribute(
|
|
232
|
+
"allow",
|
|
233
|
+
"clipboard-write; publickey-credentials-get *; publickey-credentials-create *"
|
|
234
|
+
);
|
|
235
|
+
iframe.src = url;
|
|
236
|
+
document.body.appendChild(iframe);
|
|
237
|
+
return iframe;
|
|
238
|
+
};
|
|
239
|
+
var initialise = async (config) => {
|
|
240
|
+
if (state_default.initialised) return;
|
|
241
|
+
state_default.initialised = true;
|
|
242
|
+
state_default.network = config?.network || "mainnet";
|
|
243
|
+
Logger.setLogLevel(config?.logging || "error");
|
|
244
|
+
Logger.debug("SDK", "Initialising...");
|
|
245
|
+
const { origin, uiUrl } = getWalletUrl(config);
|
|
246
|
+
state_default.iframe = createIFrame(uiUrl);
|
|
247
|
+
const messenger = new Penpal.WindowMessenger({
|
|
248
|
+
remoteWindow: state_default.iframe.contentWindow,
|
|
249
|
+
allowedOrigins: [origin]
|
|
250
|
+
});
|
|
251
|
+
return new Promise((resolve, reject) => {
|
|
252
|
+
try {
|
|
253
|
+
const connection = Penpal.connect({
|
|
254
|
+
messenger,
|
|
255
|
+
log: config?.debug ? Penpal.debug("SDK") : void 0,
|
|
256
|
+
methods: {
|
|
257
|
+
ready: async () => {
|
|
258
|
+
Logger.debug("SDK", "Initialised");
|
|
259
|
+
const status2 = await state_default.remote.status();
|
|
260
|
+
Logger.debug("SDK", `Status: ${status2.status}, Address: ${status2.address}`);
|
|
261
|
+
callbacks_default.onStatusChange?.(status2);
|
|
262
|
+
resolve(status2);
|
|
263
|
+
},
|
|
264
|
+
...inboundMethods
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
connection.promise.then((_remote) => {
|
|
268
|
+
state_default.remote = _remote;
|
|
269
|
+
});
|
|
270
|
+
} catch (e) {
|
|
271
|
+
reject(e);
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
};
|
|
275
|
+
var mega = {
|
|
276
|
+
initialise,
|
|
277
|
+
events,
|
|
278
|
+
...outboundMethods
|
|
279
|
+
};
|
|
280
|
+
export {
|
|
281
|
+
mega
|
|
282
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@megaeth-labs/wallet-sdk",
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
|
+
"description": "MegaETH Wallet SDK for web applications",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"keywords": [
|
|
20
|
+
"megaeth",
|
|
21
|
+
"wallet",
|
|
22
|
+
"sdk",
|
|
23
|
+
"web3"
|
|
24
|
+
],
|
|
25
|
+
"author": "",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/megaeth-labs/wallet-sdk.git"
|
|
30
|
+
},
|
|
31
|
+
"sideEffects": false,
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"registry": "https://registry.npmjs.org/",
|
|
34
|
+
"access": "restricted"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"penpal": "7.0.6"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@biomejs/biome": "2.4.6",
|
|
41
|
+
"@types/node": "25.3.5",
|
|
42
|
+
"@vitest/coverage-v8": "4.0.18",
|
|
43
|
+
"@vitest/ui": "4.0.18",
|
|
44
|
+
"husky": "^9.1.7",
|
|
45
|
+
"jsdom": "28.1.0",
|
|
46
|
+
"lint-staged": "^16.4.0",
|
|
47
|
+
"tsup": "8.5.1",
|
|
48
|
+
"typescript": "5.9.3",
|
|
49
|
+
"vitest": "4.0.18"
|
|
50
|
+
},
|
|
51
|
+
"lint-staged": {
|
|
52
|
+
"src/**/*.{ts,js,json}": [
|
|
53
|
+
"pnpm format"
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
58
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
59
|
+
"dev:link": "pnpm build && pnpm link --global",
|
|
60
|
+
"test": "vitest",
|
|
61
|
+
"test:ui": "vitest --ui",
|
|
62
|
+
"test:coverage": "vitest --coverage",
|
|
63
|
+
"lint": "biome lint ./src",
|
|
64
|
+
"format": "biome format --write ./src",
|
|
65
|
+
"check": "biome check ./src",
|
|
66
|
+
"typecheck": "tsc --noEmit"
|
|
67
|
+
}
|
|
68
|
+
}
|