@moon-x/react-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +241 -0
- package/dist/assets/Sons-Black.ttf +0 -0
- package/dist/assets/Sons-Bold.ttf +0 -0
- package/dist/assets/Sons-Extrabold.ttf +0 -0
- package/dist/assets/Sons-Light.ttf +0 -0
- package/dist/assets/Sons-Medium.ttf +0 -0
- package/dist/assets/Sons-Regular.ttf +0 -0
- package/dist/assets/Sons-Semibold.ttf +0 -0
- package/dist/assets/Sons-Thin.ttf +0 -0
- package/dist/base-wallet-CzJLpndu.d.mts +119 -0
- package/dist/base-wallet-CzJLpndu.d.ts +119 -0
- package/dist/chunk-73TEXNFX.js +1018 -0
- package/dist/chunk-7BCQAHO6.mjs +1561 -0
- package/dist/chunk-CDSNBPXB.js +1988 -0
- package/dist/chunk-MYWXMCMO.mjs +662 -0
- package/dist/chunk-PCEN5CH6.mjs +169 -0
- package/dist/chunk-SPXMMQ7Z.js +248 -0
- package/dist/ethereum-BRGKpUFH.d.ts +311 -0
- package/dist/ethereum-DobH9IQl.d.mts +311 -0
- package/dist/index.css +169 -0
- package/dist/index.d.mts +298 -0
- package/dist/index.d.ts +298 -0
- package/dist/index.js +24365 -0
- package/dist/index.mjs +18194 -0
- package/dist/solana-CzXRbze_.d.mts +236 -0
- package/dist/solana-D7BgQ4c0.d.ts +236 -0
- package/dist/style.css +169 -0
- package/dist/wallets/ethereum.d.mts +4 -0
- package/dist/wallets/ethereum.d.ts +4 -0
- package/dist/wallets/ethereum.js +21 -0
- package/dist/wallets/ethereum.mjs +4 -0
- package/dist/wallets/solana.d.mts +4 -0
- package/dist/wallets/solana.d.ts +4 -0
- package/dist/wallets/solana.js +17 -0
- package/dist/wallets/solana.mjs +4 -0
- package/package.json +70 -0
|
@@ -0,0 +1,1561 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
function _array_like_to_array(arr, len) {
|
|
3
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
4
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
5
|
+
return arr2;
|
|
6
|
+
}
|
|
7
|
+
function _array_with_holes(arr) {
|
|
8
|
+
if (Array.isArray(arr)) return arr;
|
|
9
|
+
}
|
|
10
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
11
|
+
try {
|
|
12
|
+
var info = gen[key](arg);
|
|
13
|
+
var value = info.value;
|
|
14
|
+
} catch (error) {
|
|
15
|
+
reject(error);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (info.done) {
|
|
19
|
+
resolve(value);
|
|
20
|
+
} else {
|
|
21
|
+
Promise.resolve(value).then(_next, _throw);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function _async_to_generator(fn) {
|
|
25
|
+
return function() {
|
|
26
|
+
var self = this, args = arguments;
|
|
27
|
+
return new Promise(function(resolve, reject) {
|
|
28
|
+
var gen = fn.apply(self, args);
|
|
29
|
+
function _next(value) {
|
|
30
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
31
|
+
}
|
|
32
|
+
function _throw(err) {
|
|
33
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
34
|
+
}
|
|
35
|
+
_next(undefined);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function _define_property(obj, key, value) {
|
|
40
|
+
if (key in obj) {
|
|
41
|
+
Object.defineProperty(obj, key, {
|
|
42
|
+
value: value,
|
|
43
|
+
enumerable: true,
|
|
44
|
+
configurable: true,
|
|
45
|
+
writable: true
|
|
46
|
+
});
|
|
47
|
+
} else {
|
|
48
|
+
obj[key] = value;
|
|
49
|
+
}
|
|
50
|
+
return obj;
|
|
51
|
+
}
|
|
52
|
+
function _instanceof(left, right) {
|
|
53
|
+
"@swc/helpers - instanceof";
|
|
54
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
55
|
+
return !!right[Symbol.hasInstance](left);
|
|
56
|
+
} else {
|
|
57
|
+
return left instanceof right;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function _iterable_to_array_limit(arr, i) {
|
|
61
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
62
|
+
if (_i == null) return;
|
|
63
|
+
var _arr = [];
|
|
64
|
+
var _n = true;
|
|
65
|
+
var _d = false;
|
|
66
|
+
var _s, _e;
|
|
67
|
+
try {
|
|
68
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
69
|
+
_arr.push(_s.value);
|
|
70
|
+
if (i && _arr.length === i) break;
|
|
71
|
+
}
|
|
72
|
+
} catch (err) {
|
|
73
|
+
_d = true;
|
|
74
|
+
_e = err;
|
|
75
|
+
} finally{
|
|
76
|
+
try {
|
|
77
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
78
|
+
} finally{
|
|
79
|
+
if (_d) throw _e;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return _arr;
|
|
83
|
+
}
|
|
84
|
+
function _non_iterable_rest() {
|
|
85
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
86
|
+
}
|
|
87
|
+
function _object_spread(target) {
|
|
88
|
+
for(var i = 1; i < arguments.length; i++){
|
|
89
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
90
|
+
var ownKeys = Object.keys(source);
|
|
91
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
92
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
93
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
ownKeys.forEach(function(key) {
|
|
97
|
+
_define_property(target, key, source[key]);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return target;
|
|
101
|
+
}
|
|
102
|
+
function ownKeys(object, enumerableOnly) {
|
|
103
|
+
var keys = Object.keys(object);
|
|
104
|
+
if (Object.getOwnPropertySymbols) {
|
|
105
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
106
|
+
if (enumerableOnly) {
|
|
107
|
+
symbols = symbols.filter(function(sym) {
|
|
108
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
keys.push.apply(keys, symbols);
|
|
112
|
+
}
|
|
113
|
+
return keys;
|
|
114
|
+
}
|
|
115
|
+
function _object_spread_props(target, source) {
|
|
116
|
+
source = source != null ? source : {};
|
|
117
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
118
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
119
|
+
} else {
|
|
120
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
121
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return target;
|
|
125
|
+
}
|
|
126
|
+
function _object_without_properties(source, excluded) {
|
|
127
|
+
if (source == null) return {};
|
|
128
|
+
var target = {}, sourceKeys, key, i;
|
|
129
|
+
if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
|
|
130
|
+
sourceKeys = Reflect.ownKeys(Object(source));
|
|
131
|
+
for(i = 0; i < sourceKeys.length; i++){
|
|
132
|
+
key = sourceKeys[i];
|
|
133
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
134
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
135
|
+
target[key] = source[key];
|
|
136
|
+
}
|
|
137
|
+
return target;
|
|
138
|
+
}
|
|
139
|
+
target = _object_without_properties_loose(source, excluded);
|
|
140
|
+
if (Object.getOwnPropertySymbols) {
|
|
141
|
+
sourceKeys = Object.getOwnPropertySymbols(source);
|
|
142
|
+
for(i = 0; i < sourceKeys.length; i++){
|
|
143
|
+
key = sourceKeys[i];
|
|
144
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
145
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
146
|
+
target[key] = source[key];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return target;
|
|
150
|
+
}
|
|
151
|
+
function _object_without_properties_loose(source, excluded) {
|
|
152
|
+
if (source == null) return {};
|
|
153
|
+
var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
|
|
154
|
+
for(i = 0; i < sourceKeys.length; i++){
|
|
155
|
+
key = sourceKeys[i];
|
|
156
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
157
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
158
|
+
target[key] = source[key];
|
|
159
|
+
}
|
|
160
|
+
return target;
|
|
161
|
+
}
|
|
162
|
+
function _sliced_to_array(arr, i) {
|
|
163
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
164
|
+
}
|
|
165
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
166
|
+
if (!o) return;
|
|
167
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
168
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
169
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
170
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
171
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
172
|
+
}
|
|
173
|
+
function _ts_generator(thisArg, body) {
|
|
174
|
+
var f, y, t, _ = {
|
|
175
|
+
label: 0,
|
|
176
|
+
sent: function() {
|
|
177
|
+
if (t[0] & 1) throw t[1];
|
|
178
|
+
return t[1];
|
|
179
|
+
},
|
|
180
|
+
trys: [],
|
|
181
|
+
ops: []
|
|
182
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
183
|
+
return d(g, "next", {
|
|
184
|
+
value: verb(0)
|
|
185
|
+
}), d(g, "throw", {
|
|
186
|
+
value: verb(1)
|
|
187
|
+
}), d(g, "return", {
|
|
188
|
+
value: verb(2)
|
|
189
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
190
|
+
value: function() {
|
|
191
|
+
return this;
|
|
192
|
+
}
|
|
193
|
+
}), g;
|
|
194
|
+
function verb(n) {
|
|
195
|
+
return function(v) {
|
|
196
|
+
return step([
|
|
197
|
+
n,
|
|
198
|
+
v
|
|
199
|
+
]);
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function step(op) {
|
|
203
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
204
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
205
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
206
|
+
if (y = 0, t) op = [
|
|
207
|
+
op[0] & 2,
|
|
208
|
+
t.value
|
|
209
|
+
];
|
|
210
|
+
switch(op[0]){
|
|
211
|
+
case 0:
|
|
212
|
+
case 1:
|
|
213
|
+
t = op;
|
|
214
|
+
break;
|
|
215
|
+
case 4:
|
|
216
|
+
_.label++;
|
|
217
|
+
return {
|
|
218
|
+
value: op[1],
|
|
219
|
+
done: false
|
|
220
|
+
};
|
|
221
|
+
case 5:
|
|
222
|
+
_.label++;
|
|
223
|
+
y = op[1];
|
|
224
|
+
op = [
|
|
225
|
+
0
|
|
226
|
+
];
|
|
227
|
+
continue;
|
|
228
|
+
case 7:
|
|
229
|
+
op = _.ops.pop();
|
|
230
|
+
_.trys.pop();
|
|
231
|
+
continue;
|
|
232
|
+
default:
|
|
233
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
234
|
+
_ = 0;
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
238
|
+
_.label = op[1];
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
242
|
+
_.label = t[1];
|
|
243
|
+
t = op;
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
if (t && _.label < t[2]) {
|
|
247
|
+
_.label = t[2];
|
|
248
|
+
_.ops.push(op);
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
if (t[2]) _.ops.pop();
|
|
252
|
+
_.trys.pop();
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
op = body.call(thisArg, _);
|
|
256
|
+
} catch (e) {
|
|
257
|
+
op = [
|
|
258
|
+
6,
|
|
259
|
+
e
|
|
260
|
+
];
|
|
261
|
+
y = 0;
|
|
262
|
+
} finally{
|
|
263
|
+
f = t = 0;
|
|
264
|
+
}
|
|
265
|
+
if (op[0] & 5) throw op[1];
|
|
266
|
+
return {
|
|
267
|
+
value: op[0] ? op[1] : void 0,
|
|
268
|
+
done: true
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
import { __export, dispatchSignOp, shouldShowWalletUI, useAuthSDK } from "./chunk-PCEN5CH6.mjs";
|
|
273
|
+
// src/wallets/ethereum.ts
|
|
274
|
+
var ethereum_exports = {};
|
|
275
|
+
__export(ethereum_exports, {
|
|
276
|
+
useCreateWallet: function useCreateWallet1() {
|
|
277
|
+
return useCreateWallet;
|
|
278
|
+
},
|
|
279
|
+
useEthereumProvider: function useEthereumProvider1() {
|
|
280
|
+
return useEthereumProvider;
|
|
281
|
+
},
|
|
282
|
+
useExportKey: function useExportKey1() {
|
|
283
|
+
return useExportKey;
|
|
284
|
+
},
|
|
285
|
+
useFundWallet: function useFundWallet1() {
|
|
286
|
+
return useFundWallet;
|
|
287
|
+
},
|
|
288
|
+
useGetBalance: function useGetBalance1() {
|
|
289
|
+
return useGetBalance;
|
|
290
|
+
},
|
|
291
|
+
useGetEthereumProvider: function useGetEthereumProvider1() {
|
|
292
|
+
return useGetEthereumProvider;
|
|
293
|
+
},
|
|
294
|
+
useImportKey: function useImportKey1() {
|
|
295
|
+
return useImportKey;
|
|
296
|
+
},
|
|
297
|
+
useSendTransaction: function useSendTransaction1() {
|
|
298
|
+
return useSendTransaction;
|
|
299
|
+
},
|
|
300
|
+
useSign7702Authorization: function useSign7702Authorization1() {
|
|
301
|
+
return useSign7702Authorization;
|
|
302
|
+
},
|
|
303
|
+
useSignHash: function useSignHash1() {
|
|
304
|
+
return useSignHash;
|
|
305
|
+
},
|
|
306
|
+
useSignMessage: function useSignMessage1() {
|
|
307
|
+
return useSignMessage;
|
|
308
|
+
},
|
|
309
|
+
useSignTransaction: function useSignTransaction1() {
|
|
310
|
+
return useSignTransaction;
|
|
311
|
+
},
|
|
312
|
+
useSignTypedData: function useSignTypedData1() {
|
|
313
|
+
return useSignTypedData;
|
|
314
|
+
},
|
|
315
|
+
useWallets: function useWallets1() {
|
|
316
|
+
return useWallets;
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
import { useSignMessage as useSharedEthSignMessage, useSignTransaction as useSharedEthSignTransaction, useSignTypedData as useSharedEthSignTypedData, useSignHash as useSharedEthSignHash, useSign7702Authorization as useSharedEthSign7702Authorization, useSendTransaction as useSharedEthSendTransaction, useGetBalance as useSharedEthGetBalance } from "@moon-x/core/react/ethereum";
|
|
320
|
+
import { useWallets as useSharedWallets, useCreateWallet as useSharedCreateWallet, useImportKey as useSharedImportKey } from "@moon-x/core/react";
|
|
321
|
+
import { useCallback } from "react";
|
|
322
|
+
import { getChainById as getChainById2, getRpcUrl as getRpcUrl2, prepareEvmSendTransaction, prepareEvmSignTransaction } from "@moon-x/core/lib";
|
|
323
|
+
// src/wallets/ethereum-provider.ts
|
|
324
|
+
import { getChainById, getRpcUrl } from "@moon-x/core/lib";
|
|
325
|
+
var useEthereumProvider = function useEthereumProvider(wallet) {
|
|
326
|
+
var coreSDK = useAuthSDK();
|
|
327
|
+
var currentChainId = wallet.chainId || 1;
|
|
328
|
+
var request = function request(args) {
|
|
329
|
+
return _async_to_generator(function() {
|
|
330
|
+
var method, _args_params, params, message, messageText, response, _coreSDK_config_ethereum, _coreSDK_config, _params, transaction, defaultChain, sendRpcUrl, sendResponse, _params1, txToSign, signResponse, _params2, typedData, accountAddr, typedDataResponse, _params3, typedDataV4, accountAddrV4, typedDataV4Response, _params4, hash, secp256k1Response, _coreSDK_config_ethereum1, _coreSDK_config1, supportedChains, rpcUrl, chain, _coreSDK_config_ethereum2, _coreSDK_config2, fallbackChain, response2, data, error;
|
|
331
|
+
return _ts_generator(this, function(_state) {
|
|
332
|
+
switch(_state.label){
|
|
333
|
+
case 0:
|
|
334
|
+
method = args.method, _args_params = args.params, params = _args_params === void 0 ? [] : _args_params;
|
|
335
|
+
switch(method){
|
|
336
|
+
case "eth_requestAccounts":
|
|
337
|
+
return [
|
|
338
|
+
3,
|
|
339
|
+
1
|
|
340
|
+
];
|
|
341
|
+
case "eth_accounts":
|
|
342
|
+
return [
|
|
343
|
+
3,
|
|
344
|
+
2
|
|
345
|
+
];
|
|
346
|
+
case "eth_chainId":
|
|
347
|
+
return [
|
|
348
|
+
3,
|
|
349
|
+
3
|
|
350
|
+
];
|
|
351
|
+
case "personal_sign":
|
|
352
|
+
return [
|
|
353
|
+
3,
|
|
354
|
+
4
|
|
355
|
+
];
|
|
356
|
+
case "eth_sendTransaction":
|
|
357
|
+
return [
|
|
358
|
+
3,
|
|
359
|
+
6
|
|
360
|
+
];
|
|
361
|
+
case "eth_signTransaction":
|
|
362
|
+
return [
|
|
363
|
+
3,
|
|
364
|
+
8
|
|
365
|
+
];
|
|
366
|
+
case "eth_signTypedData":
|
|
367
|
+
return [
|
|
368
|
+
3,
|
|
369
|
+
10
|
|
370
|
+
];
|
|
371
|
+
case "eth_signTypedData_v4":
|
|
372
|
+
return [
|
|
373
|
+
3,
|
|
374
|
+
12
|
|
375
|
+
];
|
|
376
|
+
case "secp256k1_sign":
|
|
377
|
+
return [
|
|
378
|
+
3,
|
|
379
|
+
14
|
|
380
|
+
];
|
|
381
|
+
}
|
|
382
|
+
return [
|
|
383
|
+
3,
|
|
384
|
+
16
|
|
385
|
+
];
|
|
386
|
+
case 1:
|
|
387
|
+
return [
|
|
388
|
+
2,
|
|
389
|
+
[
|
|
390
|
+
wallet.public_address
|
|
391
|
+
]
|
|
392
|
+
];
|
|
393
|
+
case 2:
|
|
394
|
+
return [
|
|
395
|
+
2,
|
|
396
|
+
[
|
|
397
|
+
wallet.public_address
|
|
398
|
+
]
|
|
399
|
+
];
|
|
400
|
+
case 3:
|
|
401
|
+
return [
|
|
402
|
+
2,
|
|
403
|
+
"0x1"
|
|
404
|
+
];
|
|
405
|
+
case 4:
|
|
406
|
+
if (params.length < 1) {
|
|
407
|
+
throw new Error("personal_sign requires message parameter");
|
|
408
|
+
}
|
|
409
|
+
message = params[0];
|
|
410
|
+
messageText = message;
|
|
411
|
+
if (message.startsWith("0x")) {
|
|
412
|
+
try {
|
|
413
|
+
messageText = new TextDecoder().decode(new Uint8Array(message.match(/.{1,2}/g).map(function(byte) {
|
|
414
|
+
return parseInt(byte, 16);
|
|
415
|
+
})));
|
|
416
|
+
} catch (unused) {
|
|
417
|
+
messageText = message;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return [
|
|
421
|
+
4,
|
|
422
|
+
coreSDK.signEthereumMessageHeadless({
|
|
423
|
+
message: messageText,
|
|
424
|
+
wallet: wallet,
|
|
425
|
+
options: {}
|
|
426
|
+
})
|
|
427
|
+
];
|
|
428
|
+
case 5:
|
|
429
|
+
response = _state.sent();
|
|
430
|
+
return [
|
|
431
|
+
2,
|
|
432
|
+
response.signature
|
|
433
|
+
];
|
|
434
|
+
case 6:
|
|
435
|
+
if (params.length < 1) {
|
|
436
|
+
throw new Error("eth_sendTransaction requires transaction parameter");
|
|
437
|
+
}
|
|
438
|
+
_params = _sliced_to_array(params, 1), transaction = _params[0];
|
|
439
|
+
defaultChain = (_coreSDK_config = coreSDK.config) === null || _coreSDK_config === void 0 ? void 0 : (_coreSDK_config_ethereum = _coreSDK_config.ethereum) === null || _coreSDK_config_ethereum === void 0 ? void 0 : _coreSDK_config_ethereum.defaultChain;
|
|
440
|
+
if (!defaultChain) {
|
|
441
|
+
throw new Error("No defaultChain configured. Please set ethereum.defaultChain in MoonKeyProvider config.");
|
|
442
|
+
}
|
|
443
|
+
sendRpcUrl = getRpcUrl(defaultChain);
|
|
444
|
+
if (!sendRpcUrl) {
|
|
445
|
+
throw new Error("No RPC URL found for chain ".concat(defaultChain.name));
|
|
446
|
+
}
|
|
447
|
+
return [
|
|
448
|
+
4,
|
|
449
|
+
coreSDK.sendEthereumTransactionHeadless({
|
|
450
|
+
transaction: transaction,
|
|
451
|
+
wallet: wallet,
|
|
452
|
+
rpcUrl: sendRpcUrl,
|
|
453
|
+
options: {}
|
|
454
|
+
})
|
|
455
|
+
];
|
|
456
|
+
case 7:
|
|
457
|
+
sendResponse = _state.sent();
|
|
458
|
+
return [
|
|
459
|
+
2,
|
|
460
|
+
sendResponse.hash
|
|
461
|
+
];
|
|
462
|
+
case 8:
|
|
463
|
+
if (params.length < 1) {
|
|
464
|
+
throw new Error("eth_signTransaction requires transaction parameter");
|
|
465
|
+
}
|
|
466
|
+
_params1 = _sliced_to_array(params, 1), txToSign = _params1[0];
|
|
467
|
+
return [
|
|
468
|
+
4,
|
|
469
|
+
coreSDK.signEthereumTransactionHeadless({
|
|
470
|
+
transaction: txToSign,
|
|
471
|
+
wallet: wallet,
|
|
472
|
+
options: {}
|
|
473
|
+
})
|
|
474
|
+
];
|
|
475
|
+
case 9:
|
|
476
|
+
signResponse = _state.sent();
|
|
477
|
+
return [
|
|
478
|
+
2,
|
|
479
|
+
signResponse.signature
|
|
480
|
+
];
|
|
481
|
+
case 10:
|
|
482
|
+
if (params.length < 2) {
|
|
483
|
+
throw new Error("eth_signTypedData requires typedData and account parameters");
|
|
484
|
+
}
|
|
485
|
+
_params2 = _sliced_to_array(params, 2), typedData = _params2[0], accountAddr = _params2[1];
|
|
486
|
+
return [
|
|
487
|
+
4,
|
|
488
|
+
coreSDK.signEthereumTypedDataHeadless({
|
|
489
|
+
domain: typedData.domain,
|
|
490
|
+
types: typedData.types,
|
|
491
|
+
primaryType: typedData.primaryType,
|
|
492
|
+
message: typedData.message,
|
|
493
|
+
wallet: wallet,
|
|
494
|
+
options: {}
|
|
495
|
+
})
|
|
496
|
+
];
|
|
497
|
+
case 11:
|
|
498
|
+
typedDataResponse = _state.sent();
|
|
499
|
+
return [
|
|
500
|
+
2,
|
|
501
|
+
typedDataResponse.signature
|
|
502
|
+
];
|
|
503
|
+
case 12:
|
|
504
|
+
if (params.length < 2) {
|
|
505
|
+
throw new Error("eth_signTypedData_v4 requires typedData and account parameters");
|
|
506
|
+
}
|
|
507
|
+
_params3 = _sliced_to_array(params, 2), typedDataV4 = _params3[0], accountAddrV4 = _params3[1];
|
|
508
|
+
return [
|
|
509
|
+
4,
|
|
510
|
+
coreSDK.signEthereumTypedDataHeadless({
|
|
511
|
+
domain: typedDataV4.domain,
|
|
512
|
+
types: typedDataV4.types,
|
|
513
|
+
primaryType: typedDataV4.primaryType,
|
|
514
|
+
message: typedDataV4.message,
|
|
515
|
+
wallet: wallet,
|
|
516
|
+
options: {}
|
|
517
|
+
})
|
|
518
|
+
];
|
|
519
|
+
case 13:
|
|
520
|
+
typedDataV4Response = _state.sent();
|
|
521
|
+
return [
|
|
522
|
+
2,
|
|
523
|
+
typedDataV4Response.signature
|
|
524
|
+
];
|
|
525
|
+
case 14:
|
|
526
|
+
if (params.length < 1) {
|
|
527
|
+
throw new Error("secp256k1_sign requires hash parameter");
|
|
528
|
+
}
|
|
529
|
+
_params4 = _sliced_to_array(params, 1), hash = _params4[0];
|
|
530
|
+
return [
|
|
531
|
+
4,
|
|
532
|
+
coreSDK.signEthereumMessageHeadless({
|
|
533
|
+
message: hash,
|
|
534
|
+
wallet: wallet,
|
|
535
|
+
options: {}
|
|
536
|
+
})
|
|
537
|
+
];
|
|
538
|
+
case 15:
|
|
539
|
+
secp256k1Response = _state.sent();
|
|
540
|
+
return [
|
|
541
|
+
2,
|
|
542
|
+
secp256k1Response.signature
|
|
543
|
+
];
|
|
544
|
+
case 16:
|
|
545
|
+
supportedChains = (_coreSDK_config1 = coreSDK.config) === null || _coreSDK_config1 === void 0 ? void 0 : (_coreSDK_config_ethereum1 = _coreSDK_config1.ethereum) === null || _coreSDK_config_ethereum1 === void 0 ? void 0 : _coreSDK_config_ethereum1.supportedChains;
|
|
546
|
+
if (supportedChains && supportedChains.length > 0) {
|
|
547
|
+
chain = getChainById(supportedChains, currentChainId);
|
|
548
|
+
if (chain) {
|
|
549
|
+
rpcUrl = getRpcUrl(chain);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
if (!rpcUrl) {
|
|
553
|
+
;
|
|
554
|
+
fallbackChain = (_coreSDK_config2 = coreSDK.config) === null || _coreSDK_config2 === void 0 ? void 0 : (_coreSDK_config_ethereum2 = _coreSDK_config2.ethereum) === null || _coreSDK_config_ethereum2 === void 0 ? void 0 : _coreSDK_config_ethereum2.defaultChain;
|
|
555
|
+
if (fallbackChain) {
|
|
556
|
+
rpcUrl = getRpcUrl(fallbackChain);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
if (!rpcUrl) {
|
|
560
|
+
throw new Error("Unsupported method: ".concat(method, ". No RPC configured for chain ID ").concat(currentChainId, ". Please configure 'defaultChain' and 'supportedChains' in MoonKeyProvider."));
|
|
561
|
+
}
|
|
562
|
+
_state.label = 17;
|
|
563
|
+
case 17:
|
|
564
|
+
_state.trys.push([
|
|
565
|
+
17,
|
|
566
|
+
20,
|
|
567
|
+
,
|
|
568
|
+
21
|
|
569
|
+
]);
|
|
570
|
+
return [
|
|
571
|
+
4,
|
|
572
|
+
fetch(rpcUrl, {
|
|
573
|
+
method: "POST",
|
|
574
|
+
headers: {
|
|
575
|
+
"Content-Type": "application/json"
|
|
576
|
+
},
|
|
577
|
+
body: JSON.stringify({
|
|
578
|
+
jsonrpc: "2.0",
|
|
579
|
+
id: Date.now(),
|
|
580
|
+
method: method,
|
|
581
|
+
params: params || []
|
|
582
|
+
})
|
|
583
|
+
})
|
|
584
|
+
];
|
|
585
|
+
case 18:
|
|
586
|
+
response2 = _state.sent();
|
|
587
|
+
return [
|
|
588
|
+
4,
|
|
589
|
+
response2.json()
|
|
590
|
+
];
|
|
591
|
+
case 19:
|
|
592
|
+
data = _state.sent();
|
|
593
|
+
if (data.error) {
|
|
594
|
+
throw new Error(data.error.message || "RPC request failed");
|
|
595
|
+
}
|
|
596
|
+
return [
|
|
597
|
+
2,
|
|
598
|
+
data.result
|
|
599
|
+
];
|
|
600
|
+
case 20:
|
|
601
|
+
error = _state.sent();
|
|
602
|
+
throw new Error("RPC request failed: ".concat(error.message));
|
|
603
|
+
case 21:
|
|
604
|
+
return [
|
|
605
|
+
2
|
|
606
|
+
];
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
})();
|
|
610
|
+
};
|
|
611
|
+
return {
|
|
612
|
+
request: request,
|
|
613
|
+
requestAccounts: function requestAccounts() {
|
|
614
|
+
return request({
|
|
615
|
+
method: "eth_requestAccounts"
|
|
616
|
+
});
|
|
617
|
+
},
|
|
618
|
+
personalSign: function personalSign(message, account) {
|
|
619
|
+
return request({
|
|
620
|
+
method: "personal_sign",
|
|
621
|
+
params: [
|
|
622
|
+
message,
|
|
623
|
+
account
|
|
624
|
+
]
|
|
625
|
+
});
|
|
626
|
+
},
|
|
627
|
+
ethSendTransaction: function ethSendTransaction(transaction) {
|
|
628
|
+
return request({
|
|
629
|
+
method: "eth_sendTransaction",
|
|
630
|
+
params: [
|
|
631
|
+
transaction
|
|
632
|
+
]
|
|
633
|
+
});
|
|
634
|
+
},
|
|
635
|
+
ethSignTransaction: function ethSignTransaction(transaction) {
|
|
636
|
+
return request({
|
|
637
|
+
method: "eth_signTransaction",
|
|
638
|
+
params: [
|
|
639
|
+
transaction
|
|
640
|
+
]
|
|
641
|
+
});
|
|
642
|
+
},
|
|
643
|
+
ethSignTypedData: function ethSignTypedData(params) {
|
|
644
|
+
return request({
|
|
645
|
+
method: "eth_signTypedData",
|
|
646
|
+
params: params
|
|
647
|
+
});
|
|
648
|
+
},
|
|
649
|
+
ethSignTypedDataV4: function ethSignTypedDataV4(params) {
|
|
650
|
+
return request({
|
|
651
|
+
method: "eth_signTypedData_v4",
|
|
652
|
+
params: params
|
|
653
|
+
});
|
|
654
|
+
},
|
|
655
|
+
secp256k1Sign: function secp256k1Sign(hash) {
|
|
656
|
+
return request({
|
|
657
|
+
method: "secp256k1_sign",
|
|
658
|
+
params: [
|
|
659
|
+
hash
|
|
660
|
+
]
|
|
661
|
+
});
|
|
662
|
+
},
|
|
663
|
+
switchChain: function switchChain(chainId) {
|
|
664
|
+
return request({
|
|
665
|
+
method: "wallet_switchEthereumChain",
|
|
666
|
+
params: [
|
|
667
|
+
chainId
|
|
668
|
+
]
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
};
|
|
673
|
+
var useGetEthereumProvider = function useGetEthereumProvider() {
|
|
674
|
+
return function(wallet) {
|
|
675
|
+
return useEthereumProvider(wallet);
|
|
676
|
+
};
|
|
677
|
+
};
|
|
678
|
+
var createEthereumProvider = function createEthereumProvider(wallet, coreSDK) {
|
|
679
|
+
var currentChainId = wallet.chainId || 1;
|
|
680
|
+
var request = function request(args) {
|
|
681
|
+
return _async_to_generator(function() {
|
|
682
|
+
var method, _args_params, params, message, messageText, response, _coreSDK_config_ethereum, _coreSDK_config, _params, transaction, defaultChain, sendTxRpcUrl, txResponse, _params1, txToSign, signResponse, _params2, typedData, typedDataResponse, _coreSDK_config_ethereum1, _coreSDK_config1, supportedChains, chain, rpcUrl, _coreSDK_config_ethereum2, _coreSDK_config2, defaultChain2, rpcResponse, rpcResult;
|
|
683
|
+
return _ts_generator(this, function(_state) {
|
|
684
|
+
switch(_state.label){
|
|
685
|
+
case 0:
|
|
686
|
+
method = args.method, _args_params = args.params, params = _args_params === void 0 ? [] : _args_params;
|
|
687
|
+
switch(method){
|
|
688
|
+
case "eth_requestAccounts":
|
|
689
|
+
return [
|
|
690
|
+
3,
|
|
691
|
+
1
|
|
692
|
+
];
|
|
693
|
+
case "eth_accounts":
|
|
694
|
+
return [
|
|
695
|
+
3,
|
|
696
|
+
2
|
|
697
|
+
];
|
|
698
|
+
case "eth_chainId":
|
|
699
|
+
return [
|
|
700
|
+
3,
|
|
701
|
+
3
|
|
702
|
+
];
|
|
703
|
+
case "personal_sign":
|
|
704
|
+
return [
|
|
705
|
+
3,
|
|
706
|
+
4
|
|
707
|
+
];
|
|
708
|
+
case "eth_sendTransaction":
|
|
709
|
+
return [
|
|
710
|
+
3,
|
|
711
|
+
6
|
|
712
|
+
];
|
|
713
|
+
case "eth_signTransaction":
|
|
714
|
+
return [
|
|
715
|
+
3,
|
|
716
|
+
8
|
|
717
|
+
];
|
|
718
|
+
case "eth_signTypedData":
|
|
719
|
+
return [
|
|
720
|
+
3,
|
|
721
|
+
10
|
|
722
|
+
];
|
|
723
|
+
case "eth_signTypedData_v4":
|
|
724
|
+
return [
|
|
725
|
+
3,
|
|
726
|
+
10
|
|
727
|
+
];
|
|
728
|
+
}
|
|
729
|
+
return [
|
|
730
|
+
3,
|
|
731
|
+
12
|
|
732
|
+
];
|
|
733
|
+
case 1:
|
|
734
|
+
return [
|
|
735
|
+
2,
|
|
736
|
+
[
|
|
737
|
+
wallet.public_address
|
|
738
|
+
]
|
|
739
|
+
];
|
|
740
|
+
case 2:
|
|
741
|
+
return [
|
|
742
|
+
2,
|
|
743
|
+
[
|
|
744
|
+
wallet.public_address
|
|
745
|
+
]
|
|
746
|
+
];
|
|
747
|
+
case 3:
|
|
748
|
+
return [
|
|
749
|
+
2,
|
|
750
|
+
"0x" + currentChainId.toString(16)
|
|
751
|
+
];
|
|
752
|
+
case 4:
|
|
753
|
+
if (params.length < 1) {
|
|
754
|
+
throw new Error("personal_sign requires message parameter");
|
|
755
|
+
}
|
|
756
|
+
message = params[0];
|
|
757
|
+
messageText = message;
|
|
758
|
+
if (message.startsWith("0x")) {
|
|
759
|
+
try {
|
|
760
|
+
messageText = new TextDecoder().decode(new Uint8Array(message.match(/.{1,2}/g).map(function(byte) {
|
|
761
|
+
return parseInt(byte, 16);
|
|
762
|
+
})));
|
|
763
|
+
} catch (unused) {
|
|
764
|
+
messageText = message;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
return [
|
|
768
|
+
4,
|
|
769
|
+
coreSDK.signEthereumMessageHeadless({
|
|
770
|
+
message: messageText,
|
|
771
|
+
wallet: wallet,
|
|
772
|
+
options: {}
|
|
773
|
+
})
|
|
774
|
+
];
|
|
775
|
+
case 5:
|
|
776
|
+
response = _state.sent();
|
|
777
|
+
return [
|
|
778
|
+
2,
|
|
779
|
+
response.signature
|
|
780
|
+
];
|
|
781
|
+
case 6:
|
|
782
|
+
if (params.length < 1) {
|
|
783
|
+
throw new Error("eth_sendTransaction requires transaction parameter");
|
|
784
|
+
}
|
|
785
|
+
_params = _sliced_to_array(params, 1), transaction = _params[0];
|
|
786
|
+
defaultChain = (_coreSDK_config = coreSDK.config) === null || _coreSDK_config === void 0 ? void 0 : (_coreSDK_config_ethereum = _coreSDK_config.ethereum) === null || _coreSDK_config_ethereum === void 0 ? void 0 : _coreSDK_config_ethereum.defaultChain;
|
|
787
|
+
if (!defaultChain) {
|
|
788
|
+
throw new Error("No default chain configured");
|
|
789
|
+
}
|
|
790
|
+
sendTxRpcUrl = getRpcUrl(defaultChain);
|
|
791
|
+
return [
|
|
792
|
+
4,
|
|
793
|
+
coreSDK.sendEthereumTransactionHeadless({
|
|
794
|
+
transaction: transaction,
|
|
795
|
+
wallet: wallet,
|
|
796
|
+
rpcUrl: sendTxRpcUrl,
|
|
797
|
+
options: {}
|
|
798
|
+
})
|
|
799
|
+
];
|
|
800
|
+
case 7:
|
|
801
|
+
txResponse = _state.sent();
|
|
802
|
+
return [
|
|
803
|
+
2,
|
|
804
|
+
txResponse.hash
|
|
805
|
+
];
|
|
806
|
+
case 8:
|
|
807
|
+
if (params.length < 1) {
|
|
808
|
+
throw new Error("eth_signTransaction requires transaction parameter");
|
|
809
|
+
}
|
|
810
|
+
_params1 = _sliced_to_array(params, 1), txToSign = _params1[0];
|
|
811
|
+
return [
|
|
812
|
+
4,
|
|
813
|
+
coreSDK.signEthereumTransactionHeadless({
|
|
814
|
+
transaction: txToSign,
|
|
815
|
+
wallet: wallet,
|
|
816
|
+
options: {}
|
|
817
|
+
})
|
|
818
|
+
];
|
|
819
|
+
case 9:
|
|
820
|
+
signResponse = _state.sent();
|
|
821
|
+
return [
|
|
822
|
+
2,
|
|
823
|
+
signResponse.signedTransaction
|
|
824
|
+
];
|
|
825
|
+
case 10:
|
|
826
|
+
if (params.length < 2) {
|
|
827
|
+
throw new Error("eth_signTypedData requires address and typedData parameters");
|
|
828
|
+
}
|
|
829
|
+
_params2 = _sliced_to_array(params, 2), typedData = _params2[1];
|
|
830
|
+
return [
|
|
831
|
+
4,
|
|
832
|
+
coreSDK.signEthereumTypedDataHeadless({
|
|
833
|
+
typedData: typeof typedData === "string" ? JSON.parse(typedData) : typedData,
|
|
834
|
+
wallet: wallet,
|
|
835
|
+
options: {}
|
|
836
|
+
})
|
|
837
|
+
];
|
|
838
|
+
case 11:
|
|
839
|
+
typedDataResponse = _state.sent();
|
|
840
|
+
return [
|
|
841
|
+
2,
|
|
842
|
+
typedDataResponse.signature
|
|
843
|
+
];
|
|
844
|
+
case 12:
|
|
845
|
+
supportedChains = ((_coreSDK_config1 = coreSDK.config) === null || _coreSDK_config1 === void 0 ? void 0 : (_coreSDK_config_ethereum1 = _coreSDK_config1.ethereum) === null || _coreSDK_config_ethereum1 === void 0 ? void 0 : _coreSDK_config_ethereum1.supportedChains) || [];
|
|
846
|
+
chain = getChainById(supportedChains, currentChainId);
|
|
847
|
+
rpcUrl = chain ? getRpcUrl(chain) : void 0;
|
|
848
|
+
if (!rpcUrl) {
|
|
849
|
+
;
|
|
850
|
+
defaultChain2 = (_coreSDK_config2 = coreSDK.config) === null || _coreSDK_config2 === void 0 ? void 0 : (_coreSDK_config_ethereum2 = _coreSDK_config2.ethereum) === null || _coreSDK_config_ethereum2 === void 0 ? void 0 : _coreSDK_config_ethereum2.defaultChain;
|
|
851
|
+
if (defaultChain2) {
|
|
852
|
+
rpcUrl = getRpcUrl(defaultChain2);
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
if (!rpcUrl) {
|
|
856
|
+
throw new Error("Unsupported method: ".concat(method, ". No RPC URL found for chain ").concat(currentChainId));
|
|
857
|
+
}
|
|
858
|
+
return [
|
|
859
|
+
4,
|
|
860
|
+
fetch(rpcUrl, {
|
|
861
|
+
method: "POST",
|
|
862
|
+
headers: {
|
|
863
|
+
"Content-Type": "application/json"
|
|
864
|
+
},
|
|
865
|
+
body: JSON.stringify({
|
|
866
|
+
jsonrpc: "2.0",
|
|
867
|
+
id: 1,
|
|
868
|
+
method: method,
|
|
869
|
+
params: params
|
|
870
|
+
})
|
|
871
|
+
})
|
|
872
|
+
];
|
|
873
|
+
case 13:
|
|
874
|
+
rpcResponse = _state.sent();
|
|
875
|
+
return [
|
|
876
|
+
4,
|
|
877
|
+
rpcResponse.json()
|
|
878
|
+
];
|
|
879
|
+
case 14:
|
|
880
|
+
rpcResult = _state.sent();
|
|
881
|
+
if (rpcResult.error) {
|
|
882
|
+
throw new Error(rpcResult.error.message || "RPC request failed");
|
|
883
|
+
}
|
|
884
|
+
return [
|
|
885
|
+
2,
|
|
886
|
+
rpcResult.result
|
|
887
|
+
];
|
|
888
|
+
case 15:
|
|
889
|
+
return [
|
|
890
|
+
2
|
|
891
|
+
];
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
})();
|
|
895
|
+
};
|
|
896
|
+
return {
|
|
897
|
+
request: request,
|
|
898
|
+
requestAccounts: function requestAccounts() {
|
|
899
|
+
return request({
|
|
900
|
+
method: "eth_requestAccounts"
|
|
901
|
+
});
|
|
902
|
+
},
|
|
903
|
+
personalSign: function personalSign(message, account) {
|
|
904
|
+
return request({
|
|
905
|
+
method: "personal_sign",
|
|
906
|
+
params: [
|
|
907
|
+
message,
|
|
908
|
+
account
|
|
909
|
+
]
|
|
910
|
+
});
|
|
911
|
+
},
|
|
912
|
+
ethSendTransaction: function ethSendTransaction(transaction) {
|
|
913
|
+
return request({
|
|
914
|
+
method: "eth_sendTransaction",
|
|
915
|
+
params: [
|
|
916
|
+
transaction
|
|
917
|
+
]
|
|
918
|
+
});
|
|
919
|
+
},
|
|
920
|
+
ethSignTransaction: function ethSignTransaction(transaction) {
|
|
921
|
+
return request({
|
|
922
|
+
method: "eth_signTransaction",
|
|
923
|
+
params: [
|
|
924
|
+
transaction
|
|
925
|
+
]
|
|
926
|
+
});
|
|
927
|
+
},
|
|
928
|
+
ethSignTypedData: function ethSignTypedData(params) {
|
|
929
|
+
return request({
|
|
930
|
+
method: "eth_signTypedData",
|
|
931
|
+
params: params
|
|
932
|
+
});
|
|
933
|
+
},
|
|
934
|
+
ethSignTypedDataV4: function ethSignTypedDataV4(params) {
|
|
935
|
+
return request({
|
|
936
|
+
method: "eth_signTypedData_v4",
|
|
937
|
+
params: params
|
|
938
|
+
});
|
|
939
|
+
},
|
|
940
|
+
secp256k1Sign: function secp256k1Sign(hash) {
|
|
941
|
+
return request({
|
|
942
|
+
method: "secp256k1_sign",
|
|
943
|
+
params: [
|
|
944
|
+
hash
|
|
945
|
+
]
|
|
946
|
+
});
|
|
947
|
+
},
|
|
948
|
+
switchChain: function switchChain(chainId) {
|
|
949
|
+
return request({
|
|
950
|
+
method: "wallet_switchEthereumChain",
|
|
951
|
+
params: [
|
|
952
|
+
chainId
|
|
953
|
+
]
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
};
|
|
957
|
+
};
|
|
958
|
+
// src/wallets/ethereum/use-fund-wallet.ts
|
|
959
|
+
var useFundWallet = function useFundWallet() {
|
|
960
|
+
var sdk = useAuthSDK();
|
|
961
|
+
var fundWallet = function fundWallet(address, options) {
|
|
962
|
+
return _async_to_generator(function() {
|
|
963
|
+
return _ts_generator(this, function(_state) {
|
|
964
|
+
if (!sdk.fundWallet) {
|
|
965
|
+
throw new Error("fundWallet method not available in SDK");
|
|
966
|
+
}
|
|
967
|
+
return [
|
|
968
|
+
2,
|
|
969
|
+
sdk.fundWallet({
|
|
970
|
+
address: address,
|
|
971
|
+
options: options
|
|
972
|
+
})
|
|
973
|
+
];
|
|
974
|
+
});
|
|
975
|
+
})();
|
|
976
|
+
};
|
|
977
|
+
return {
|
|
978
|
+
fundWallet: fundWallet
|
|
979
|
+
};
|
|
980
|
+
};
|
|
981
|
+
// src/wallets/ethereum.ts
|
|
982
|
+
var stripWalletMethods = function stripWalletMethods(wallet) {
|
|
983
|
+
var switchChain = wallet.switchChain, getEthereumProvider = wallet.getEthereumProvider, walletData = _object_without_properties(wallet, [
|
|
984
|
+
"switchChain",
|
|
985
|
+
"getEthereumProvider"
|
|
986
|
+
]);
|
|
987
|
+
return walletData;
|
|
988
|
+
};
|
|
989
|
+
var useCreateWallet = function useCreateWallet(callbacks) {
|
|
990
|
+
var _useSharedCreateWallet = useSharedCreateWallet(), sharedCreateWallet = _useSharedCreateWallet.createWallet;
|
|
991
|
+
return {
|
|
992
|
+
createWallet: function createWallet(options) {
|
|
993
|
+
return _async_to_generator(function() {
|
|
994
|
+
var _callbacks_onSuccess, payload, error, _callbacks_onError, errorObj;
|
|
995
|
+
return _ts_generator(this, function(_state) {
|
|
996
|
+
switch(_state.label){
|
|
997
|
+
case 0:
|
|
998
|
+
_state.trys.push([
|
|
999
|
+
0,
|
|
1000
|
+
2,
|
|
1001
|
+
,
|
|
1002
|
+
3
|
|
1003
|
+
]);
|
|
1004
|
+
return [
|
|
1005
|
+
4,
|
|
1006
|
+
sharedCreateWallet("ethereum", options)
|
|
1007
|
+
];
|
|
1008
|
+
case 1:
|
|
1009
|
+
payload = _state.sent();
|
|
1010
|
+
callbacks === null || callbacks === void 0 ? void 0 : (_callbacks_onSuccess = callbacks.onSuccess) === null || _callbacks_onSuccess === void 0 ? void 0 : _callbacks_onSuccess.call(callbacks, payload);
|
|
1011
|
+
return [
|
|
1012
|
+
2,
|
|
1013
|
+
payload
|
|
1014
|
+
];
|
|
1015
|
+
case 2:
|
|
1016
|
+
error = _state.sent();
|
|
1017
|
+
errorObj = _instanceof(error, Error) ? error : new Error("Unknown error");
|
|
1018
|
+
callbacks === null || callbacks === void 0 ? void 0 : (_callbacks_onError = callbacks.onError) === null || _callbacks_onError === void 0 ? void 0 : _callbacks_onError.call(callbacks, errorObj);
|
|
1019
|
+
throw errorObj;
|
|
1020
|
+
case 3:
|
|
1021
|
+
return [
|
|
1022
|
+
2
|
|
1023
|
+
];
|
|
1024
|
+
}
|
|
1025
|
+
});
|
|
1026
|
+
})();
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
};
|
|
1030
|
+
var useWallets = function useWallets() {
|
|
1031
|
+
var _shared_error;
|
|
1032
|
+
var coreSDK = useAuthSDK();
|
|
1033
|
+
var shared = useSharedWallets("ethereum");
|
|
1034
|
+
var enhanceWallet = useCallback(function(wallet) {
|
|
1035
|
+
var _coreSDK_config_ethereum_defaultChain, _coreSDK_config_ethereum, _coreSDK_config;
|
|
1036
|
+
var ethereumWallet = _object_spread_props(_object_spread({}, wallet), {
|
|
1037
|
+
chainId: wallet.chainId || ((_coreSDK_config = coreSDK.config) === null || _coreSDK_config === void 0 ? void 0 : (_coreSDK_config_ethereum = _coreSDK_config.ethereum) === null || _coreSDK_config_ethereum === void 0 ? void 0 : (_coreSDK_config_ethereum_defaultChain = _coreSDK_config_ethereum.defaultChain) === null || _coreSDK_config_ethereum_defaultChain === void 0 ? void 0 : _coreSDK_config_ethereum_defaultChain.id),
|
|
1038
|
+
switchChain: function switchChain(chainId) {
|
|
1039
|
+
return _async_to_generator(function() {
|
|
1040
|
+
return _ts_generator(this, function(_state) {
|
|
1041
|
+
try {
|
|
1042
|
+
wallet.chainId = chainId;
|
|
1043
|
+
ethereumWallet.chainId = chainId;
|
|
1044
|
+
} catch (error) {
|
|
1045
|
+
throw new Error("Switch chain failed: ".concat(_instanceof(error, Error) ? error.message : "Unknown error"));
|
|
1046
|
+
}
|
|
1047
|
+
return [
|
|
1048
|
+
2
|
|
1049
|
+
];
|
|
1050
|
+
});
|
|
1051
|
+
})();
|
|
1052
|
+
},
|
|
1053
|
+
getEthereumProvider: function getEthereumProvider() {
|
|
1054
|
+
return _async_to_generator(function() {
|
|
1055
|
+
return _ts_generator(this, function(_state) {
|
|
1056
|
+
return [
|
|
1057
|
+
2,
|
|
1058
|
+
createEthereumProvider(wallet, coreSDK)
|
|
1059
|
+
];
|
|
1060
|
+
});
|
|
1061
|
+
})();
|
|
1062
|
+
}
|
|
1063
|
+
});
|
|
1064
|
+
return ethereumWallet;
|
|
1065
|
+
}, [
|
|
1066
|
+
coreSDK
|
|
1067
|
+
]);
|
|
1068
|
+
var enhancedWallets = shared.wallets.map(enhanceWallet);
|
|
1069
|
+
return {
|
|
1070
|
+
wallets: enhancedWallets,
|
|
1071
|
+
loading: shared.loading,
|
|
1072
|
+
error: (_shared_error = shared.error) !== null && _shared_error !== void 0 ? _shared_error : void 0,
|
|
1073
|
+
refetch: shared.refetch
|
|
1074
|
+
};
|
|
1075
|
+
};
|
|
1076
|
+
var useSignMessage = function useSignMessage() {
|
|
1077
|
+
var coreSDK = useAuthSDK();
|
|
1078
|
+
var shared = useSharedEthSignMessage();
|
|
1079
|
+
return {
|
|
1080
|
+
signMessage: function signMessage(params) {
|
|
1081
|
+
return _async_to_generator(function() {
|
|
1082
|
+
var _params_options, _coreSDK_config_signMessageConfig, _coreSDK_config, showWalletUI, error;
|
|
1083
|
+
return _ts_generator(this, function(_state) {
|
|
1084
|
+
switch(_state.label){
|
|
1085
|
+
case 0:
|
|
1086
|
+
_state.trys.push([
|
|
1087
|
+
0,
|
|
1088
|
+
2,
|
|
1089
|
+
,
|
|
1090
|
+
3
|
|
1091
|
+
]);
|
|
1092
|
+
showWalletUI = shouldShowWalletUI((_params_options = params.options) === null || _params_options === void 0 ? void 0 : _params_options.uiOptions, (_coreSDK_config = coreSDK.config) === null || _coreSDK_config === void 0 ? void 0 : (_coreSDK_config_signMessageConfig = _coreSDK_config.signMessageConfig) === null || _coreSDK_config_signMessageConfig === void 0 ? void 0 : _coreSDK_config_signMessageConfig.uiConfig);
|
|
1093
|
+
return [
|
|
1094
|
+
4,
|
|
1095
|
+
dispatchSignOp({
|
|
1096
|
+
params: _object_spread_props(_object_spread({}, params), {
|
|
1097
|
+
wallet: stripWalletMethods(params.wallet)
|
|
1098
|
+
}),
|
|
1099
|
+
showWalletUI: showWalletUI,
|
|
1100
|
+
headless: shared.signMessage,
|
|
1101
|
+
withUI: coreSDK.signEthereumMessageWithUI
|
|
1102
|
+
})
|
|
1103
|
+
];
|
|
1104
|
+
case 1:
|
|
1105
|
+
return [
|
|
1106
|
+
2,
|
|
1107
|
+
_state.sent()
|
|
1108
|
+
];
|
|
1109
|
+
case 2:
|
|
1110
|
+
error = _state.sent();
|
|
1111
|
+
throw new Error("Sign message failed: ".concat(_instanceof(error, Error) ? error.message : "Unknown error"));
|
|
1112
|
+
case 3:
|
|
1113
|
+
return [
|
|
1114
|
+
2
|
|
1115
|
+
];
|
|
1116
|
+
}
|
|
1117
|
+
});
|
|
1118
|
+
})();
|
|
1119
|
+
},
|
|
1120
|
+
loading: false,
|
|
1121
|
+
error: void 0
|
|
1122
|
+
};
|
|
1123
|
+
};
|
|
1124
|
+
var useSignTransaction = function useSignTransaction() {
|
|
1125
|
+
var coreSDK = useAuthSDK();
|
|
1126
|
+
var shared = useSharedEthSignTransaction();
|
|
1127
|
+
return {
|
|
1128
|
+
signTransaction: function signTransaction(param) {
|
|
1129
|
+
var transaction = param.transaction, wallet = param.wallet, requireFreshAssertion = param.requireFreshAssertion, options = param.options;
|
|
1130
|
+
return _async_to_generator(function() {
|
|
1131
|
+
var _coreSDK_config_ethereum, _coreSDK_config, _coreSDK_config_ethereum1, _coreSDK_config1, _coreSDK_config_signTransactionConfig, _coreSDK_config2, serializedTransaction, showWalletUI, error;
|
|
1132
|
+
return _ts_generator(this, function(_state) {
|
|
1133
|
+
switch(_state.label){
|
|
1134
|
+
case 0:
|
|
1135
|
+
_state.trys.push([
|
|
1136
|
+
0,
|
|
1137
|
+
3,
|
|
1138
|
+
,
|
|
1139
|
+
4
|
|
1140
|
+
]);
|
|
1141
|
+
return [
|
|
1142
|
+
4,
|
|
1143
|
+
prepareEvmSignTransaction({
|
|
1144
|
+
transaction: transaction,
|
|
1145
|
+
wallet: {
|
|
1146
|
+
public_address: wallet.public_address,
|
|
1147
|
+
chainId: wallet.chainId
|
|
1148
|
+
},
|
|
1149
|
+
supportedChains: (_coreSDK_config = coreSDK.config) === null || _coreSDK_config === void 0 ? void 0 : (_coreSDK_config_ethereum = _coreSDK_config.ethereum) === null || _coreSDK_config_ethereum === void 0 ? void 0 : _coreSDK_config_ethereum.supportedChains,
|
|
1150
|
+
defaultChain: (_coreSDK_config1 = coreSDK.config) === null || _coreSDK_config1 === void 0 ? void 0 : (_coreSDK_config_ethereum1 = _coreSDK_config1.ethereum) === null || _coreSDK_config_ethereum1 === void 0 ? void 0 : _coreSDK_config_ethereum1.defaultChain
|
|
1151
|
+
})
|
|
1152
|
+
];
|
|
1153
|
+
case 1:
|
|
1154
|
+
serializedTransaction = _state.sent().serializedTransaction;
|
|
1155
|
+
showWalletUI = shouldShowWalletUI(options === null || options === void 0 ? void 0 : options.uiOptions, (_coreSDK_config2 = coreSDK.config) === null || _coreSDK_config2 === void 0 ? void 0 : (_coreSDK_config_signTransactionConfig = _coreSDK_config2.signTransactionConfig) === null || _coreSDK_config_signTransactionConfig === void 0 ? void 0 : _coreSDK_config_signTransactionConfig.uiConfig);
|
|
1156
|
+
return [
|
|
1157
|
+
4,
|
|
1158
|
+
dispatchSignOp({
|
|
1159
|
+
params: {
|
|
1160
|
+
transaction: serializedTransaction,
|
|
1161
|
+
wallet: stripWalletMethods(wallet),
|
|
1162
|
+
requireFreshAssertion: requireFreshAssertion,
|
|
1163
|
+
options: {
|
|
1164
|
+
uiOptions: options === null || options === void 0 ? void 0 : options.uiOptions
|
|
1165
|
+
}
|
|
1166
|
+
},
|
|
1167
|
+
showWalletUI: showWalletUI,
|
|
1168
|
+
headless: shared.signTransaction,
|
|
1169
|
+
withUI: coreSDK.signEthereumTransactionWithUI
|
|
1170
|
+
})
|
|
1171
|
+
];
|
|
1172
|
+
case 2:
|
|
1173
|
+
return [
|
|
1174
|
+
2,
|
|
1175
|
+
_state.sent()
|
|
1176
|
+
];
|
|
1177
|
+
case 3:
|
|
1178
|
+
error = _state.sent();
|
|
1179
|
+
throw new Error("Sign transaction failed: ".concat(_instanceof(error, Error) ? error.message : "Unknown error"));
|
|
1180
|
+
case 4:
|
|
1181
|
+
return [
|
|
1182
|
+
2
|
|
1183
|
+
];
|
|
1184
|
+
}
|
|
1185
|
+
});
|
|
1186
|
+
})();
|
|
1187
|
+
},
|
|
1188
|
+
loading: false,
|
|
1189
|
+
error: void 0
|
|
1190
|
+
};
|
|
1191
|
+
};
|
|
1192
|
+
var useSignHash = function useSignHash() {
|
|
1193
|
+
var shared = useSharedEthSignHash();
|
|
1194
|
+
return {
|
|
1195
|
+
signHash: function signHash(params) {
|
|
1196
|
+
return _async_to_generator(function() {
|
|
1197
|
+
var response, error;
|
|
1198
|
+
return _ts_generator(this, function(_state) {
|
|
1199
|
+
switch(_state.label){
|
|
1200
|
+
case 0:
|
|
1201
|
+
_state.trys.push([
|
|
1202
|
+
0,
|
|
1203
|
+
2,
|
|
1204
|
+
,
|
|
1205
|
+
3
|
|
1206
|
+
]);
|
|
1207
|
+
return [
|
|
1208
|
+
4,
|
|
1209
|
+
shared.signHash(_object_spread_props(_object_spread({}, params), {
|
|
1210
|
+
wallet: stripWalletMethods(params.wallet)
|
|
1211
|
+
}))
|
|
1212
|
+
];
|
|
1213
|
+
case 1:
|
|
1214
|
+
response = _state.sent();
|
|
1215
|
+
return [
|
|
1216
|
+
2,
|
|
1217
|
+
{
|
|
1218
|
+
signature: response.signature
|
|
1219
|
+
}
|
|
1220
|
+
];
|
|
1221
|
+
case 2:
|
|
1222
|
+
error = _state.sent();
|
|
1223
|
+
throw new Error("Sign hash failed: ".concat(_instanceof(error, Error) ? error.message : "Unknown error"));
|
|
1224
|
+
case 3:
|
|
1225
|
+
return [
|
|
1226
|
+
2
|
|
1227
|
+
];
|
|
1228
|
+
}
|
|
1229
|
+
});
|
|
1230
|
+
})();
|
|
1231
|
+
},
|
|
1232
|
+
loading: false,
|
|
1233
|
+
error: void 0
|
|
1234
|
+
};
|
|
1235
|
+
};
|
|
1236
|
+
var useSignTypedData = function useSignTypedData() {
|
|
1237
|
+
var coreSDK = useAuthSDK();
|
|
1238
|
+
var shared = useSharedEthSignTypedData();
|
|
1239
|
+
return {
|
|
1240
|
+
signTypedData: function signTypedData(params) {
|
|
1241
|
+
return _async_to_generator(function() {
|
|
1242
|
+
var _params_options, _coreSDK_config_signMessageConfig, _coreSDK_config, showWalletUI, error;
|
|
1243
|
+
return _ts_generator(this, function(_state) {
|
|
1244
|
+
switch(_state.label){
|
|
1245
|
+
case 0:
|
|
1246
|
+
_state.trys.push([
|
|
1247
|
+
0,
|
|
1248
|
+
2,
|
|
1249
|
+
,
|
|
1250
|
+
3
|
|
1251
|
+
]);
|
|
1252
|
+
showWalletUI = shouldShowWalletUI((_params_options = params.options) === null || _params_options === void 0 ? void 0 : _params_options.uiOptions, (_coreSDK_config = coreSDK.config) === null || _coreSDK_config === void 0 ? void 0 : (_coreSDK_config_signMessageConfig = _coreSDK_config.signMessageConfig) === null || _coreSDK_config_signMessageConfig === void 0 ? void 0 : _coreSDK_config_signMessageConfig.uiConfig);
|
|
1253
|
+
return [
|
|
1254
|
+
4,
|
|
1255
|
+
dispatchSignOp({
|
|
1256
|
+
params: _object_spread_props(_object_spread({}, params), {
|
|
1257
|
+
wallet: stripWalletMethods(params.wallet)
|
|
1258
|
+
}),
|
|
1259
|
+
showWalletUI: showWalletUI,
|
|
1260
|
+
headless: shared.signTypedData,
|
|
1261
|
+
withUI: coreSDK.signEthereumTypedDataWithUI
|
|
1262
|
+
})
|
|
1263
|
+
];
|
|
1264
|
+
case 1:
|
|
1265
|
+
return [
|
|
1266
|
+
2,
|
|
1267
|
+
_state.sent()
|
|
1268
|
+
];
|
|
1269
|
+
case 2:
|
|
1270
|
+
error = _state.sent();
|
|
1271
|
+
throw new Error("Sign typed data failed: ".concat(_instanceof(error, Error) ? error.message : "Unknown error"));
|
|
1272
|
+
case 3:
|
|
1273
|
+
return [
|
|
1274
|
+
2
|
|
1275
|
+
];
|
|
1276
|
+
}
|
|
1277
|
+
});
|
|
1278
|
+
})();
|
|
1279
|
+
},
|
|
1280
|
+
loading: false,
|
|
1281
|
+
error: void 0
|
|
1282
|
+
};
|
|
1283
|
+
};
|
|
1284
|
+
var useSign7702Authorization = function useSign7702Authorization() {
|
|
1285
|
+
var shared = useSharedEthSign7702Authorization();
|
|
1286
|
+
var coreSDK = useAuthSDK();
|
|
1287
|
+
return {
|
|
1288
|
+
signAuthorization: function signAuthorization(param) {
|
|
1289
|
+
var contractAddress = param.contractAddress, nonce = param.nonce, executor = param.executor, wallet = param.wallet, requireFreshAssertion = param.requireFreshAssertion, options = param.options;
|
|
1290
|
+
return _async_to_generator(function() {
|
|
1291
|
+
var _coreSDK_config_ethereum, _coreSDK_config, walletChainId, targetChain, _coreSDK_config_ethereum1, _coreSDK_config1, derivedChainId, _coreSDK_config_signMessageConfig, _coreSDK_config2, showWalletUI, error;
|
|
1292
|
+
return _ts_generator(this, function(_state) {
|
|
1293
|
+
switch(_state.label){
|
|
1294
|
+
case 0:
|
|
1295
|
+
walletChainId = wallet.chainId;
|
|
1296
|
+
if (walletChainId && ((_coreSDK_config = coreSDK.config) === null || _coreSDK_config === void 0 ? void 0 : (_coreSDK_config_ethereum = _coreSDK_config.ethereum) === null || _coreSDK_config_ethereum === void 0 ? void 0 : _coreSDK_config_ethereum.supportedChains)) {
|
|
1297
|
+
targetChain = getChainById2(coreSDK.config.ethereum.supportedChains, walletChainId);
|
|
1298
|
+
}
|
|
1299
|
+
if (!targetChain) {
|
|
1300
|
+
;
|
|
1301
|
+
targetChain = (_coreSDK_config1 = coreSDK.config) === null || _coreSDK_config1 === void 0 ? void 0 : (_coreSDK_config_ethereum1 = _coreSDK_config1.ethereum) === null || _coreSDK_config_ethereum1 === void 0 ? void 0 : _coreSDK_config_ethereum1.defaultChain;
|
|
1302
|
+
}
|
|
1303
|
+
if (!targetChain) {
|
|
1304
|
+
throw new Error("No chain configured. Please set ethereum.defaultChain in MoonKeyProvider config.");
|
|
1305
|
+
}
|
|
1306
|
+
derivedChainId = targetChain.id;
|
|
1307
|
+
_state.label = 1;
|
|
1308
|
+
case 1:
|
|
1309
|
+
_state.trys.push([
|
|
1310
|
+
1,
|
|
1311
|
+
3,
|
|
1312
|
+
,
|
|
1313
|
+
4
|
|
1314
|
+
]);
|
|
1315
|
+
showWalletUI = shouldShowWalletUI(options === null || options === void 0 ? void 0 : options.uiOptions, (_coreSDK_config2 = coreSDK.config) === null || _coreSDK_config2 === void 0 ? void 0 : (_coreSDK_config_signMessageConfig = _coreSDK_config2.signMessageConfig) === null || _coreSDK_config_signMessageConfig === void 0 ? void 0 : _coreSDK_config_signMessageConfig.uiConfig);
|
|
1316
|
+
return [
|
|
1317
|
+
4,
|
|
1318
|
+
dispatchSignOp({
|
|
1319
|
+
params: {
|
|
1320
|
+
contractAddress: contractAddress,
|
|
1321
|
+
chainId: derivedChainId,
|
|
1322
|
+
nonce: nonce,
|
|
1323
|
+
executor: executor,
|
|
1324
|
+
wallet: stripWalletMethods(wallet),
|
|
1325
|
+
requireFreshAssertion: requireFreshAssertion,
|
|
1326
|
+
options: {
|
|
1327
|
+
uiOptions: options === null || options === void 0 ? void 0 : options.uiOptions
|
|
1328
|
+
}
|
|
1329
|
+
},
|
|
1330
|
+
showWalletUI: showWalletUI,
|
|
1331
|
+
headless: shared.signAuthorization,
|
|
1332
|
+
withUI: coreSDK.signEthereum7702AuthorizationWithUI
|
|
1333
|
+
})
|
|
1334
|
+
];
|
|
1335
|
+
case 2:
|
|
1336
|
+
return [
|
|
1337
|
+
2,
|
|
1338
|
+
_state.sent()
|
|
1339
|
+
];
|
|
1340
|
+
case 3:
|
|
1341
|
+
error = _state.sent();
|
|
1342
|
+
throw new Error("Sign EIP-7702 authorization failed: ".concat(_instanceof(error, Error) ? error.message : "Unknown error"));
|
|
1343
|
+
case 4:
|
|
1344
|
+
return [
|
|
1345
|
+
2
|
|
1346
|
+
];
|
|
1347
|
+
}
|
|
1348
|
+
});
|
|
1349
|
+
})();
|
|
1350
|
+
},
|
|
1351
|
+
loading: false,
|
|
1352
|
+
error: void 0
|
|
1353
|
+
};
|
|
1354
|
+
};
|
|
1355
|
+
var useSendTransaction = function useSendTransaction() {
|
|
1356
|
+
var coreSDK = useAuthSDK();
|
|
1357
|
+
var shared = useSharedEthSendTransaction();
|
|
1358
|
+
return {
|
|
1359
|
+
sendTransaction: function sendTransaction(param) {
|
|
1360
|
+
var transaction = param.transaction, wallet = param.wallet, requireFreshAssertion = param.requireFreshAssertion, options = param.options;
|
|
1361
|
+
return _async_to_generator(function() {
|
|
1362
|
+
var _coreSDK_config_ethereum, _coreSDK_config, _coreSDK_config_ethereum1, _coreSDK_config1, _coreSDK_config_signMessageConfig, _coreSDK_config2, _ref, preparedTx, rpcUrl, showWalletUI, response, error;
|
|
1363
|
+
return _ts_generator(this, function(_state) {
|
|
1364
|
+
switch(_state.label){
|
|
1365
|
+
case 0:
|
|
1366
|
+
_state.trys.push([
|
|
1367
|
+
0,
|
|
1368
|
+
3,
|
|
1369
|
+
,
|
|
1370
|
+
4
|
|
1371
|
+
]);
|
|
1372
|
+
return [
|
|
1373
|
+
4,
|
|
1374
|
+
prepareEvmSendTransaction({
|
|
1375
|
+
transaction: transaction,
|
|
1376
|
+
wallet: {
|
|
1377
|
+
public_address: wallet.public_address,
|
|
1378
|
+
chainId: wallet.chainId
|
|
1379
|
+
},
|
|
1380
|
+
supportedChains: (_coreSDK_config = coreSDK.config) === null || _coreSDK_config === void 0 ? void 0 : (_coreSDK_config_ethereum = _coreSDK_config.ethereum) === null || _coreSDK_config_ethereum === void 0 ? void 0 : _coreSDK_config_ethereum.supportedChains,
|
|
1381
|
+
defaultChain: (_coreSDK_config1 = coreSDK.config) === null || _coreSDK_config1 === void 0 ? void 0 : (_coreSDK_config_ethereum1 = _coreSDK_config1.ethereum) === null || _coreSDK_config_ethereum1 === void 0 ? void 0 : _coreSDK_config_ethereum1.defaultChain
|
|
1382
|
+
})
|
|
1383
|
+
];
|
|
1384
|
+
case 1:
|
|
1385
|
+
_ref = _state.sent(), preparedTx = _ref.transaction, rpcUrl = _ref.rpcUrl;
|
|
1386
|
+
showWalletUI = shouldShowWalletUI(options === null || options === void 0 ? void 0 : options.uiOptions, (_coreSDK_config2 = coreSDK.config) === null || _coreSDK_config2 === void 0 ? void 0 : (_coreSDK_config_signMessageConfig = _coreSDK_config2.signMessageConfig) === null || _coreSDK_config_signMessageConfig === void 0 ? void 0 : _coreSDK_config_signMessageConfig.uiConfig);
|
|
1387
|
+
return [
|
|
1388
|
+
4,
|
|
1389
|
+
dispatchSignOp({
|
|
1390
|
+
params: {
|
|
1391
|
+
transaction: preparedTx,
|
|
1392
|
+
wallet: stripWalletMethods(wallet),
|
|
1393
|
+
rpcUrl: rpcUrl,
|
|
1394
|
+
requireFreshAssertion: requireFreshAssertion,
|
|
1395
|
+
options: {
|
|
1396
|
+
uiOptions: options === null || options === void 0 ? void 0 : options.uiOptions
|
|
1397
|
+
}
|
|
1398
|
+
},
|
|
1399
|
+
showWalletUI: showWalletUI,
|
|
1400
|
+
headless: shared.sendTransaction,
|
|
1401
|
+
withUI: coreSDK.sendEthereumTransactionWithUI
|
|
1402
|
+
})
|
|
1403
|
+
];
|
|
1404
|
+
case 2:
|
|
1405
|
+
response = _state.sent();
|
|
1406
|
+
return [
|
|
1407
|
+
2,
|
|
1408
|
+
{
|
|
1409
|
+
hash: response.hash
|
|
1410
|
+
}
|
|
1411
|
+
];
|
|
1412
|
+
case 3:
|
|
1413
|
+
error = _state.sent();
|
|
1414
|
+
throw new Error("Send transaction failed: ".concat(_instanceof(error, Error) ? error.message : "Unknown error"));
|
|
1415
|
+
case 4:
|
|
1416
|
+
return [
|
|
1417
|
+
2
|
|
1418
|
+
];
|
|
1419
|
+
}
|
|
1420
|
+
});
|
|
1421
|
+
})();
|
|
1422
|
+
},
|
|
1423
|
+
loading: false,
|
|
1424
|
+
error: void 0
|
|
1425
|
+
};
|
|
1426
|
+
};
|
|
1427
|
+
var useGetBalance = function useGetBalance() {
|
|
1428
|
+
var coreSDK = useAuthSDK();
|
|
1429
|
+
var shared = useSharedEthGetBalance();
|
|
1430
|
+
return {
|
|
1431
|
+
getBalance: function getBalance(params) {
|
|
1432
|
+
return _async_to_generator(function() {
|
|
1433
|
+
var _coreSDK_config_ethereum, _coreSDK_config, walletChainId, targetChain, _coreSDK_config_ethereum1, _coreSDK_config1, rpcUrl, error;
|
|
1434
|
+
return _ts_generator(this, function(_state) {
|
|
1435
|
+
switch(_state.label){
|
|
1436
|
+
case 0:
|
|
1437
|
+
_state.trys.push([
|
|
1438
|
+
0,
|
|
1439
|
+
2,
|
|
1440
|
+
,
|
|
1441
|
+
3
|
|
1442
|
+
]);
|
|
1443
|
+
walletChainId = params.wallet.chainId;
|
|
1444
|
+
if (walletChainId && ((_coreSDK_config = coreSDK.config) === null || _coreSDK_config === void 0 ? void 0 : (_coreSDK_config_ethereum = _coreSDK_config.ethereum) === null || _coreSDK_config_ethereum === void 0 ? void 0 : _coreSDK_config_ethereum.supportedChains)) {
|
|
1445
|
+
targetChain = getChainById2(coreSDK.config.ethereum.supportedChains, walletChainId);
|
|
1446
|
+
}
|
|
1447
|
+
if (!targetChain) {
|
|
1448
|
+
;
|
|
1449
|
+
targetChain = (_coreSDK_config1 = coreSDK.config) === null || _coreSDK_config1 === void 0 ? void 0 : (_coreSDK_config_ethereum1 = _coreSDK_config1.ethereum) === null || _coreSDK_config_ethereum1 === void 0 ? void 0 : _coreSDK_config_ethereum1.defaultChain;
|
|
1450
|
+
}
|
|
1451
|
+
if (!targetChain) {
|
|
1452
|
+
throw new Error("No chain configured. Please set ethereum.defaultChain in MoonKeyProvider config.");
|
|
1453
|
+
}
|
|
1454
|
+
rpcUrl = getRpcUrl2(targetChain);
|
|
1455
|
+
if (!rpcUrl) {
|
|
1456
|
+
throw new Error("No RPC URL found for chain ".concat(targetChain.name, ". Chain may be missing rpcUrls configuration."));
|
|
1457
|
+
}
|
|
1458
|
+
return [
|
|
1459
|
+
4,
|
|
1460
|
+
shared.getBalance({
|
|
1461
|
+
wallet: stripWalletMethods(params.wallet),
|
|
1462
|
+
rpcUrl: rpcUrl,
|
|
1463
|
+
options: params.options
|
|
1464
|
+
})
|
|
1465
|
+
];
|
|
1466
|
+
case 1:
|
|
1467
|
+
return [
|
|
1468
|
+
2,
|
|
1469
|
+
_state.sent()
|
|
1470
|
+
];
|
|
1471
|
+
case 2:
|
|
1472
|
+
error = _state.sent();
|
|
1473
|
+
throw new Error("Get balance failed: ".concat(_instanceof(error, Error) ? error.message : "Unknown error"));
|
|
1474
|
+
case 3:
|
|
1475
|
+
return [
|
|
1476
|
+
2
|
|
1477
|
+
];
|
|
1478
|
+
}
|
|
1479
|
+
});
|
|
1480
|
+
})();
|
|
1481
|
+
},
|
|
1482
|
+
loading: false,
|
|
1483
|
+
error: void 0
|
|
1484
|
+
};
|
|
1485
|
+
};
|
|
1486
|
+
var useExportKey = function useExportKey() {
|
|
1487
|
+
var coreSDK = useAuthSDK();
|
|
1488
|
+
return {
|
|
1489
|
+
exportKey: function exportKey(param) {
|
|
1490
|
+
var wallet = param.wallet;
|
|
1491
|
+
return _async_to_generator(function() {
|
|
1492
|
+
return _ts_generator(this, function(_state) {
|
|
1493
|
+
switch(_state.label){
|
|
1494
|
+
case 0:
|
|
1495
|
+
return [
|
|
1496
|
+
4,
|
|
1497
|
+
coreSDK.exportKey(wallet)
|
|
1498
|
+
];
|
|
1499
|
+
case 1:
|
|
1500
|
+
return [
|
|
1501
|
+
2,
|
|
1502
|
+
_state.sent()
|
|
1503
|
+
];
|
|
1504
|
+
}
|
|
1505
|
+
});
|
|
1506
|
+
})();
|
|
1507
|
+
}
|
|
1508
|
+
};
|
|
1509
|
+
};
|
|
1510
|
+
var useImportKey = function useImportKey() {
|
|
1511
|
+
var coreSDK = useAuthSDK();
|
|
1512
|
+
var _useSharedImportKey = useSharedImportKey(), sharedImportKey = _useSharedImportKey.importKey;
|
|
1513
|
+
return {
|
|
1514
|
+
// Both modes are supported: pass `key` for headless (delegates to
|
|
1515
|
+
// the shared hook), omit for UI (opens the SDK's ImportWallet
|
|
1516
|
+
// modal — modal path stays on coreSDK so the override in
|
|
1517
|
+
// create-sdk-instance.ts can dispatch the WithUI flow).
|
|
1518
|
+
//
|
|
1519
|
+
// Both branches go through SDK methods that return
|
|
1520
|
+
// `{ wallet: PublicWallet }` (matching the headless contract); we
|
|
1521
|
+
// unwrap to `PublicWallet` here so consumer code can write
|
|
1522
|
+
// `const wallet = await importKey(...)` and access
|
|
1523
|
+
// `wallet.public_address` directly.
|
|
1524
|
+
importKey: function importKey(params) {
|
|
1525
|
+
return _async_to_generator(function() {
|
|
1526
|
+
var result2, result;
|
|
1527
|
+
return _ts_generator(this, function(_state) {
|
|
1528
|
+
switch(_state.label){
|
|
1529
|
+
case 0:
|
|
1530
|
+
if (!((params === null || params === void 0 ? void 0 : params.key) !== void 0)) return [
|
|
1531
|
+
3,
|
|
1532
|
+
2
|
|
1533
|
+
];
|
|
1534
|
+
return [
|
|
1535
|
+
4,
|
|
1536
|
+
sharedImportKey("ethereum", params.key)
|
|
1537
|
+
];
|
|
1538
|
+
case 1:
|
|
1539
|
+
result2 = _state.sent();
|
|
1540
|
+
return [
|
|
1541
|
+
2,
|
|
1542
|
+
result2.wallet
|
|
1543
|
+
];
|
|
1544
|
+
case 2:
|
|
1545
|
+
return [
|
|
1546
|
+
4,
|
|
1547
|
+
coreSDK.importKey("ethereum", void 0)
|
|
1548
|
+
];
|
|
1549
|
+
case 3:
|
|
1550
|
+
result = _state.sent();
|
|
1551
|
+
return [
|
|
1552
|
+
2,
|
|
1553
|
+
result.wallet
|
|
1554
|
+
];
|
|
1555
|
+
}
|
|
1556
|
+
});
|
|
1557
|
+
})();
|
|
1558
|
+
}
|
|
1559
|
+
};
|
|
1560
|
+
};
|
|
1561
|
+
export { useEthereumProvider, useGetEthereumProvider, useFundWallet, useCreateWallet, useWallets, useSignMessage, useSignTransaction, useSignHash, useSignTypedData, useSign7702Authorization, useSendTransaction, useGetBalance, useExportKey, useImportKey, ethereum_exports };
|