@getpara/web-sdk 2.0.0-alpha.6 → 2.0.0-alpha.61
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/dist/LocalStorage.js +1 -1
- package/dist/ParaWeb.d.ts +13 -1
- package/dist/ParaWeb.js +149 -9
- package/dist/SessionStorage.js +1 -1
- package/dist/WebUtils.d.ts +2 -2
- package/dist/WebUtils.js +62 -50
- package/dist/chunk-YJOFEY2L.js +52 -0
- package/dist/cryptography/webAuth.js +1 -1
- package/dist/errors.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -3
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/onRamp.d.ts +66 -0
- package/dist/types/onRamp.js +1 -0
- package/dist/utils/emailUtils.js +1 -1
- package/dist/utils/formattingUtils.js +1 -1
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/isMobile.js +1 -1
- package/dist/utils/isPasskeySupported.js +1 -1
- package/dist/utils/offrampSend.d.ts +5 -0
- package/dist/utils/offrampSend.js +67 -0
- package/dist/utils/truncateEthAddress.js +1 -1
- package/dist/wallet/keygen.d.ts +1 -0
- package/dist/wallet/keygen.js +161 -88
- package/dist/wallet/privateKey.js +17 -7
- package/dist/wallet/signing.js +64 -25
- package/dist/wasm/wasm_exec.js +1 -1
- package/dist/workers/walletUtils.d.ts +1 -3
- package/dist/workers/walletUtils.js +95 -69
- package/dist/workers/worker.d.ts +9 -1
- package/dist/workers/worker.js +65 -11
- package/dist/workers/workerWrapper.d.ts +1 -1
- package/dist/workers/workerWrapper.js +54 -14
- package/package.json +30 -25
- package/dist/chunk-M66XENHI.js +0 -25
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
__async
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-YJOFEY2L.js";
|
|
5
5
|
import { getBaseMPCNetworkUrl } from "@getpara/core-sdk";
|
|
6
|
+
import * as uuid from "uuid";
|
|
6
7
|
const configCGGMPBase = (serverUrl, walletId, id) => `{"ServerUrl":"${serverUrl}", "WalletId": "${walletId}", "Id":"${id}", "Ids":["USER","CAPSULE"], "Threshold":1}`;
|
|
7
8
|
const configDKLSBase = (walletId, id, disableWebSockets) => `{"walletId": "${walletId}", "id":"${id}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${disableWebSockets}}`;
|
|
8
9
|
function keygenRequest(ctx, userId, walletId, protocolId) {
|
|
@@ -86,20 +87,30 @@ function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType) {
|
|
|
86
87
|
}
|
|
87
88
|
function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
|
|
88
89
|
return __async(this, null, function* () {
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
90
|
+
const protocolId = uuid.v4();
|
|
91
|
+
const preSignMessageRes = ctx.client.preSignMessage(userId, walletId, base64Bytes, "ED25519", void 0, protocolId);
|
|
92
|
+
const signRes = function() {
|
|
93
|
+
return __async(this, null, function* () {
|
|
94
|
+
try {
|
|
95
|
+
const base64Sig = yield new Promise(
|
|
96
|
+
(resolve, reject) => globalThis.ed25519Sign(share, protocolId, base64Bytes, (err, result) => {
|
|
97
|
+
if (err) {
|
|
98
|
+
reject(err);
|
|
99
|
+
}
|
|
100
|
+
resolve(result);
|
|
101
|
+
})
|
|
102
|
+
);
|
|
103
|
+
return { signature: base64Sig };
|
|
104
|
+
} catch (e) {
|
|
105
|
+
throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}();
|
|
109
|
+
const { pendingTransactionId } = yield preSignMessageRes;
|
|
110
|
+
if (pendingTransactionId) {
|
|
111
|
+
return { pendingTransactionId };
|
|
102
112
|
}
|
|
113
|
+
return yield signRes;
|
|
103
114
|
});
|
|
104
115
|
}
|
|
105
116
|
function keygen(ctx, userId, type, secretKey) {
|
|
@@ -179,16 +190,8 @@ function preKeygen(ctx, _partnerId, pregenIdentifier, pregenIdentifierType, type
|
|
|
179
190
|
}
|
|
180
191
|
function signMessage(ctx, share, walletId, userId, message, cosmosSignDoc) {
|
|
181
192
|
return __async(this, null, function* () {
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
walletId,
|
|
185
|
-
message,
|
|
186
|
-
null,
|
|
187
|
-
cosmosSignDoc
|
|
188
|
-
);
|
|
189
|
-
if (pendingTransactionId) {
|
|
190
|
-
return { pendingTransactionId };
|
|
191
|
-
}
|
|
193
|
+
const protocolId = uuid.v4();
|
|
194
|
+
const preSignMessageRes = ctx.client.preSignMessage(userId, walletId, message, null, cosmosSignDoc, protocolId);
|
|
192
195
|
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
193
196
|
return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
|
|
194
197
|
}
|
|
@@ -199,28 +202,33 @@ function signMessage(ctx, share, walletId, userId, message, cosmosSignDoc) {
|
|
|
199
202
|
parsedShare.disableWebSockets = ctx.disableWebSockets;
|
|
200
203
|
}
|
|
201
204
|
share = JSON.stringify(parsedShare);
|
|
202
|
-
|
|
203
|
-
return
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
reject(err)
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
205
|
+
const signMessageRes = function() {
|
|
206
|
+
return __async(this, null, function* () {
|
|
207
|
+
try {
|
|
208
|
+
return yield new Promise(
|
|
209
|
+
(resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
|
|
210
|
+
if (err) {
|
|
211
|
+
reject(err);
|
|
212
|
+
}
|
|
213
|
+
resolve({ signature: result });
|
|
214
|
+
})
|
|
215
|
+
);
|
|
216
|
+
} catch (e) {
|
|
217
|
+
throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}();
|
|
221
|
+
const { pendingTransactionId } = yield preSignMessageRes;
|
|
222
|
+
if (pendingTransactionId) {
|
|
223
|
+
return { pendingTransactionId };
|
|
213
224
|
}
|
|
225
|
+
return yield signMessageRes;
|
|
214
226
|
});
|
|
215
227
|
}
|
|
216
228
|
function signTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
217
229
|
return __async(this, null, function* () {
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
} = yield ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId });
|
|
221
|
-
if (pendingTransactionId) {
|
|
222
|
-
return { pendingTransactionId };
|
|
223
|
-
}
|
|
230
|
+
const protocolId = uuid.v4();
|
|
231
|
+
const signTransactionRes = ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId, protocolId });
|
|
224
232
|
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
225
233
|
return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
|
|
226
234
|
}
|
|
@@ -231,28 +239,35 @@ function signTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
|
231
239
|
parsedShare.disableWebSockets = ctx.disableWebSockets;
|
|
232
240
|
}
|
|
233
241
|
share = JSON.stringify(parsedShare);
|
|
234
|
-
|
|
235
|
-
return
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
reject(err)
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
242
|
+
const signTxRes = function() {
|
|
243
|
+
return __async(this, null, function* () {
|
|
244
|
+
try {
|
|
245
|
+
return yield new Promise(
|
|
246
|
+
(resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
247
|
+
if (err) {
|
|
248
|
+
reject(err);
|
|
249
|
+
}
|
|
250
|
+
resolve({ signature: result });
|
|
251
|
+
})
|
|
252
|
+
);
|
|
253
|
+
} catch (e) {
|
|
254
|
+
throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}();
|
|
258
|
+
const {
|
|
259
|
+
data: { pendingTransactionId }
|
|
260
|
+
} = yield signTransactionRes;
|
|
261
|
+
if (pendingTransactionId) {
|
|
262
|
+
return { pendingTransactionId };
|
|
245
263
|
}
|
|
264
|
+
return yield signTxRes;
|
|
246
265
|
});
|
|
247
266
|
}
|
|
248
267
|
function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
249
268
|
return __async(this, null, function* () {
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
} = yield ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId });
|
|
253
|
-
if (pendingTransactionId) {
|
|
254
|
-
return { pendingTransactionId };
|
|
255
|
-
}
|
|
269
|
+
const protocolId = uuid.v4();
|
|
270
|
+
const sendTransactionRes = ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId, protocolId });
|
|
256
271
|
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
257
272
|
return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
|
|
258
273
|
}
|
|
@@ -263,18 +278,29 @@ function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
|
263
278
|
parsedShare.disableWebSockets = ctx.disableWebSockets;
|
|
264
279
|
}
|
|
265
280
|
share = JSON.stringify(parsedShare);
|
|
266
|
-
|
|
267
|
-
return
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
reject(err)
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
281
|
+
const sendTxRes = function() {
|
|
282
|
+
return __async(this, null, function* () {
|
|
283
|
+
try {
|
|
284
|
+
return yield new Promise(
|
|
285
|
+
(resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
286
|
+
if (err) {
|
|
287
|
+
reject(err);
|
|
288
|
+
}
|
|
289
|
+
resolve({ signature: result });
|
|
290
|
+
})
|
|
291
|
+
);
|
|
292
|
+
} catch (e) {
|
|
293
|
+
throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}();
|
|
297
|
+
const {
|
|
298
|
+
data: { pendingTransactionId }
|
|
299
|
+
} = yield sendTransactionRes;
|
|
300
|
+
if (pendingTransactionId) {
|
|
301
|
+
return { pendingTransactionId };
|
|
277
302
|
}
|
|
303
|
+
return yield sendTxRes;
|
|
278
304
|
});
|
|
279
305
|
}
|
|
280
306
|
function refresh(ctx, share, walletId, userId, oldPartnerId, newPartnerId, keyShareProtocolId) {
|
package/dist/workers/worker.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import '../wasm/wasm_exec.js';
|
|
2
1
|
import { Environment } from '@getpara/core-sdk';
|
|
3
2
|
export interface Message {
|
|
4
3
|
env: Environment;
|
|
@@ -13,7 +12,16 @@ export interface Message {
|
|
|
13
12
|
disableWebSockets?: boolean;
|
|
14
13
|
wasmOverride?: ArrayBuffer;
|
|
15
14
|
returnObject?: boolean;
|
|
15
|
+
workId?: string;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Executes an operation with retry capabilities
|
|
19
|
+
* @param operation The function to execute
|
|
20
|
+
* @param maxRetries Maximum number of retries (default: 2)
|
|
21
|
+
* @param timeoutMs Timeout in milliseconds (default: 10000)
|
|
22
|
+
* @returns The result of the operation
|
|
23
|
+
*/
|
|
24
|
+
export declare function withRetry<T>(operation: () => Promise<T>, maxRetries?: number, timeoutMs?: number): Promise<T>;
|
|
17
25
|
export declare function handleMessage(e: {
|
|
18
26
|
data: Message;
|
|
19
27
|
}, postMessage: (message: any) => void, useFetchAdapter?: boolean): Promise<boolean>;
|
package/dist/workers/worker.js
CHANGED
|
@@ -19,14 +19,21 @@ var __async = (__this, __arguments, generator) => {
|
|
|
19
19
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
|
-
import "../wasm/wasm_exec.js";
|
|
23
22
|
import * as walletUtils from "./walletUtils.js";
|
|
24
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
getBaseMPCNetworkUrl,
|
|
25
|
+
getPortalBaseURL,
|
|
26
|
+
initClient,
|
|
27
|
+
mpcComputationClient,
|
|
28
|
+
paraVersion
|
|
29
|
+
} from "@getpara/core-sdk";
|
|
30
|
+
let wasmLoaded = false;
|
|
25
31
|
function loadWasm(ctx, wasmOverride) {
|
|
26
32
|
return __async(this, null, function* () {
|
|
27
33
|
if (typeof self === "undefined") {
|
|
28
34
|
return;
|
|
29
35
|
}
|
|
36
|
+
yield import("../wasm/wasm_exec.js");
|
|
30
37
|
const goWasm = new self.Go();
|
|
31
38
|
let wasmArrayBuffer = wasmOverride;
|
|
32
39
|
if (!wasmArrayBuffer) {
|
|
@@ -44,6 +51,9 @@ function executeMessage(ctx, message) {
|
|
|
44
51
|
return __async(this, null, function* () {
|
|
45
52
|
const { functionType, params, returnObject } = message;
|
|
46
53
|
switch (functionType) {
|
|
54
|
+
case "INIT": {
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
47
57
|
case "KEYGEN": {
|
|
48
58
|
const { userId, secretKey, type = "EVM" } = params;
|
|
49
59
|
const keygenRes = yield walletUtils.keygen(ctx, userId, type, secretKey);
|
|
@@ -51,15 +61,15 @@ function executeMessage(ctx, message) {
|
|
|
51
61
|
}
|
|
52
62
|
case "SIGN_TRANSACTION": {
|
|
53
63
|
const { share, walletId, userId, tx, chainId } = params;
|
|
54
|
-
return walletUtils.signTransaction(ctx, share, walletId, userId, tx, chainId);
|
|
64
|
+
return withRetry(() => walletUtils.signTransaction(ctx, share, walletId, userId, tx, chainId));
|
|
55
65
|
}
|
|
56
66
|
case "SEND_TRANSACTION": {
|
|
57
67
|
const { share, walletId, userId, tx, chainId } = params;
|
|
58
|
-
return walletUtils.sendTransaction(ctx, share, walletId, userId, tx, chainId);
|
|
68
|
+
return withRetry(() => walletUtils.sendTransaction(ctx, share, walletId, userId, tx, chainId));
|
|
59
69
|
}
|
|
60
70
|
case "SIGN_MESSAGE": {
|
|
61
71
|
const { share, walletId, userId, message: message2, cosmosSignDoc } = params;
|
|
62
|
-
return walletUtils.signMessage(ctx, share, walletId, userId, message2, cosmosSignDoc);
|
|
72
|
+
return withRetry(() => walletUtils.signMessage(ctx, share, walletId, userId, message2, cosmosSignDoc));
|
|
63
73
|
}
|
|
64
74
|
case "REFRESH": {
|
|
65
75
|
const { share, walletId, userId, oldPartnerId, newPartnerId, keyShareProtocolId } = params;
|
|
@@ -86,7 +96,8 @@ function executeMessage(ctx, message) {
|
|
|
86
96
|
}
|
|
87
97
|
case "GET_PRIVATE_KEY": {
|
|
88
98
|
const { share, walletId, userId } = params;
|
|
89
|
-
|
|
99
|
+
const privateKey = yield walletUtils.getPrivateKey(ctx, share, walletId, userId);
|
|
100
|
+
return { privateKey };
|
|
90
101
|
}
|
|
91
102
|
case "ED25519_KEYGEN": {
|
|
92
103
|
const { userId } = params;
|
|
@@ -94,7 +105,7 @@ function executeMessage(ctx, message) {
|
|
|
94
105
|
}
|
|
95
106
|
case "ED25519_SIGN": {
|
|
96
107
|
const { share, walletId, userId, base64Bytes } = params;
|
|
97
|
-
return walletUtils.ed25519Sign(ctx, share, userId, walletId, base64Bytes);
|
|
108
|
+
return withRetry(() => walletUtils.ed25519Sign(ctx, share, userId, walletId, base64Bytes));
|
|
98
109
|
}
|
|
99
110
|
case "ED25519_PREKEYGEN": {
|
|
100
111
|
const { email } = params;
|
|
@@ -111,6 +122,29 @@ function executeMessage(ctx, message) {
|
|
|
111
122
|
}
|
|
112
123
|
});
|
|
113
124
|
}
|
|
125
|
+
function withRetry(operation, maxRetries = 2, timeoutMs = 1e4) {
|
|
126
|
+
return __async(this, null, function* () {
|
|
127
|
+
let retries = 0;
|
|
128
|
+
while (true) {
|
|
129
|
+
try {
|
|
130
|
+
const operationPromise = operation();
|
|
131
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
132
|
+
const timeoutId = setTimeout(() => {
|
|
133
|
+
reject(new Error(`Operation timed out after ${timeoutMs}ms`));
|
|
134
|
+
}, timeoutMs);
|
|
135
|
+
operationPromise.finally(() => clearTimeout(timeoutId));
|
|
136
|
+
});
|
|
137
|
+
return yield Promise.race([operationPromise, timeoutPromise]);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
retries++;
|
|
140
|
+
if (retries > maxRetries) {
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
console.warn(`Operation failed (attempt ${retries}/${maxRetries}), retrying...`, error);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
114
148
|
function handleMessage(e, postMessage, useFetchAdapter) {
|
|
115
149
|
return __async(this, null, function* () {
|
|
116
150
|
const {
|
|
@@ -122,7 +156,8 @@ function handleMessage(e, postMessage, useFetchAdapter) {
|
|
|
122
156
|
sessionCookie,
|
|
123
157
|
useDKLS,
|
|
124
158
|
disableWebSockets,
|
|
125
|
-
wasmOverride
|
|
159
|
+
wasmOverride,
|
|
160
|
+
workId
|
|
126
161
|
} = e.data;
|
|
127
162
|
if (!env) {
|
|
128
163
|
return true;
|
|
@@ -144,14 +179,33 @@ function handleMessage(e, postMessage, useFetchAdapter) {
|
|
|
144
179
|
disableWebSockets: !!disableWebSockets,
|
|
145
180
|
wasmOverride
|
|
146
181
|
};
|
|
147
|
-
if (!ctx.offloadMPCComputationURL || ctx.useDKLS) {
|
|
182
|
+
if (!wasmLoaded && (!ctx.offloadMPCComputationURL || ctx.useDKLS)) {
|
|
148
183
|
yield loadWasm(ctx, wasmOverride);
|
|
184
|
+
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
185
|
+
if (globalThis.initWasm) {
|
|
186
|
+
yield new Promise(
|
|
187
|
+
(resolve, reject) => {
|
|
188
|
+
var _a;
|
|
189
|
+
return (_a = globalThis.initWasm) == null ? void 0 : _a.call(globalThis, (err, result2) => {
|
|
190
|
+
if (err) {
|
|
191
|
+
reject(err);
|
|
192
|
+
}
|
|
193
|
+
resolve(result2);
|
|
194
|
+
}, serverUrl);
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
wasmLoaded = true;
|
|
149
199
|
}
|
|
150
200
|
const result = yield executeMessage(ctx, e.data);
|
|
201
|
+
if (workId) {
|
|
202
|
+
result.workId = workId;
|
|
203
|
+
}
|
|
151
204
|
postMessage(result);
|
|
152
|
-
return
|
|
205
|
+
return !!workId;
|
|
153
206
|
});
|
|
154
207
|
}
|
|
155
208
|
export {
|
|
156
|
-
handleMessage
|
|
209
|
+
handleMessage,
|
|
210
|
+
withRetry
|
|
157
211
|
};
|
|
@@ -3,4 +3,4 @@ export interface SyncWorker {
|
|
|
3
3
|
postMessage: (message: any) => void;
|
|
4
4
|
terminate: () => void;
|
|
5
5
|
}
|
|
6
|
-
export declare function setupWorker(ctx: Ctx, resFunction: (arg: any) => void): Promise<Worker | SyncWorker>;
|
|
6
|
+
export declare function setupWorker(ctx: Ctx, resFunction: (arg: any) => Promise<void>, errorFunction: (err: Error) => void, workId: string, errorContext?: object): Promise<Worker | SyncWorker>;
|
|
@@ -1,23 +1,35 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
__async
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-YJOFEY2L.js";
|
|
5
5
|
import { getPortalBaseURL } from "@getpara/core-sdk";
|
|
6
6
|
import { handleMessage } from "./worker.js";
|
|
7
|
-
|
|
7
|
+
const CLEAR_WORKER_TIMEOUT_MS = 1e3 * 90;
|
|
8
|
+
let workerInstance;
|
|
9
|
+
const resFunctionMap = {};
|
|
10
|
+
function removeWorkId(workId, skipClearTimeout) {
|
|
11
|
+
const { timeoutId } = resFunctionMap[workId];
|
|
12
|
+
delete resFunctionMap[workId];
|
|
13
|
+
if (skipClearTimeout) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
clearTimeout(timeoutId);
|
|
17
|
+
}
|
|
18
|
+
function setupWorker(ctx, resFunction, errorFunction, workId, errorContext) {
|
|
8
19
|
return __async(this, null, function* () {
|
|
9
|
-
const onmessage = (event) => {
|
|
10
|
-
if (event.data.functionType === "CUSTOM") {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
resFunction(event.data);
|
|
14
|
-
};
|
|
15
20
|
if (ctx.disableWorkers) {
|
|
16
21
|
const syncWorker = {
|
|
17
22
|
postMessage: function(message) {
|
|
18
23
|
(function() {
|
|
19
24
|
return __async(this, null, function* () {
|
|
20
|
-
|
|
25
|
+
try {
|
|
26
|
+
const onmessage = (event) => {
|
|
27
|
+
resFunction(event.data);
|
|
28
|
+
};
|
|
29
|
+
yield handleMessage({ data: message }, (data) => onmessage({ data }), ctx.disableWorkers);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
errorFunction(error);
|
|
32
|
+
}
|
|
21
33
|
});
|
|
22
34
|
})();
|
|
23
35
|
},
|
|
@@ -27,17 +39,45 @@ function setupWorker(ctx, resFunction) {
|
|
|
27
39
|
};
|
|
28
40
|
return syncWorker;
|
|
29
41
|
}
|
|
30
|
-
|
|
42
|
+
const timeoutId = setTimeout(() => {
|
|
43
|
+
removeWorkId(workId, true);
|
|
44
|
+
}, CLEAR_WORKER_TIMEOUT_MS);
|
|
45
|
+
resFunctionMap[workId] = {
|
|
46
|
+
fn: resFunction,
|
|
47
|
+
timeoutId,
|
|
48
|
+
errorFn: errorFunction,
|
|
49
|
+
errorContext: errorContext || {}
|
|
50
|
+
};
|
|
31
51
|
if (ctx.useLocalFiles) {
|
|
32
52
|
throw new Error("useLocalFiles only supported locally");
|
|
33
|
-
} else {
|
|
53
|
+
} else if (!workerInstance) {
|
|
34
54
|
const workerRes = yield fetch(`${getPortalBaseURL(ctx)}/static/js/mpcWorker-bundle.js`);
|
|
35
55
|
const workerBlob = new Blob([yield workerRes.text()], { type: "application/javascript" });
|
|
36
56
|
const workerScriptURL = URL.createObjectURL(workerBlob);
|
|
37
|
-
|
|
57
|
+
workerInstance = new Worker(workerScriptURL);
|
|
58
|
+
const onmessage = (event) => __async(this, null, function* () {
|
|
59
|
+
const { workId: messageWorkId } = event.data;
|
|
60
|
+
delete event.data.workId;
|
|
61
|
+
if (messageWorkId && resFunctionMap[messageWorkId]) {
|
|
62
|
+
yield resFunctionMap[messageWorkId].fn(event.data);
|
|
63
|
+
removeWorkId(messageWorkId);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
workerInstance.onmessage = onmessage;
|
|
67
|
+
workerInstance.onerror = (err) => {
|
|
68
|
+
console.error("worker error:", err);
|
|
69
|
+
Object.keys(resFunctionMap).forEach((id) => {
|
|
70
|
+
if (resFunctionMap[id]) {
|
|
71
|
+
const errorMsg = `worker error with workId ${id} and opts ${JSON.stringify(resFunctionMap[id].errorContext)}: ${err.message}`;
|
|
72
|
+
resFunctionMap[id].errorFn(new Error(errorMsg));
|
|
73
|
+
removeWorkId(id);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
workerInstance == null ? void 0 : workerInstance.terminate();
|
|
77
|
+
workerInstance = void 0;
|
|
78
|
+
};
|
|
38
79
|
}
|
|
39
|
-
|
|
40
|
-
return worker;
|
|
80
|
+
return workerInstance;
|
|
41
81
|
});
|
|
42
82
|
}
|
|
43
83
|
export {
|
package/package.json
CHANGED
|
@@ -1,40 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/web-sdk",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"sideEffects": [
|
|
8
|
-
"wasm_exec.js"
|
|
9
|
-
],
|
|
3
|
+
"version": "2.0.0-alpha.61",
|
|
10
4
|
"dependencies": {
|
|
11
|
-
"@getpara/core-sdk": "2.0.0-alpha.
|
|
12
|
-
"@getpara/user-management-client": "2.0.0-alpha.
|
|
13
|
-
"
|
|
14
|
-
"base64url": "3.0.1",
|
|
5
|
+
"@getpara/core-sdk": "2.0.0-alpha.61",
|
|
6
|
+
"@getpara/user-management-client": "2.0.0-alpha.61",
|
|
7
|
+
"base64url": "^3.0.1",
|
|
15
8
|
"buffer": "6.0.3",
|
|
16
|
-
"cbor-web": "
|
|
9
|
+
"cbor-web": "^9.0.2",
|
|
17
10
|
"node-forge": "1.3.1",
|
|
18
11
|
"ua-parser-js": "^2.0.2"
|
|
19
12
|
},
|
|
20
|
-
"scripts": {
|
|
21
|
-
"build": "rm -rf dist && yarn typegen && node ./scripts/build.mjs && yarn post-build",
|
|
22
|
-
"typegen": "tsc --emitDeclarationOnly",
|
|
23
|
-
"old-build": "rm -rf dist && tsc && yarn post-build",
|
|
24
|
-
"post-build": "./scripts/post-build.sh",
|
|
25
|
-
"test": "vitest run --coverage"
|
|
26
|
-
},
|
|
27
13
|
"devDependencies": {
|
|
28
14
|
"@types/node-forge": "1.3.1",
|
|
29
|
-
"crypto-browserify": "3.12.0",
|
|
30
|
-
"stream-browserify": "3.0.0",
|
|
31
|
-
"typescript": "5.
|
|
32
|
-
|
|
33
|
-
|
|
15
|
+
"crypto-browserify": "^3.12.0",
|
|
16
|
+
"stream-browserify": "^3.0.0",
|
|
17
|
+
"typescript": "^5.8.3"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"@farcaster/miniapp-sdk": "^0.1.2"
|
|
21
|
+
},
|
|
22
|
+
"peerDependenciesMeta": {
|
|
23
|
+
"@farcaster/miniapp-sdk": {
|
|
24
|
+
"optional": true
|
|
25
|
+
}
|
|
34
26
|
},
|
|
35
27
|
"files": [
|
|
36
28
|
"dist",
|
|
37
29
|
"package.json"
|
|
38
30
|
],
|
|
39
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "3a84954ff65c95d95fa96794bf0b0d4dc646c624",
|
|
32
|
+
"main": "dist/index.js",
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "rm -rf dist && yarn typegen && node ./scripts/build.mjs && yarn post-build",
|
|
35
|
+
"old-build": "rm -rf dist && tsc && yarn post-build",
|
|
36
|
+
"post-build": "./scripts/post-build.sh",
|
|
37
|
+
"test": "vitest run --coverage",
|
|
38
|
+
"typegen": "tsc --emitDeclarationOnly"
|
|
39
|
+
},
|
|
40
|
+
"sideEffects": [
|
|
41
|
+
"wasm_exec.js"
|
|
42
|
+
],
|
|
43
|
+
"type": "module",
|
|
44
|
+
"types": "dist/index.d.ts"
|
|
40
45
|
}
|
package/dist/chunk-M66XENHI.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
var __async = (__this, __arguments, generator) => {
|
|
3
|
-
return new Promise((resolve, reject) => {
|
|
4
|
-
var fulfilled = (value) => {
|
|
5
|
-
try {
|
|
6
|
-
step(generator.next(value));
|
|
7
|
-
} catch (e) {
|
|
8
|
-
reject(e);
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
var rejected = (value) => {
|
|
12
|
-
try {
|
|
13
|
-
step(generator.throw(value));
|
|
14
|
-
} catch (e) {
|
|
15
|
-
reject(e);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
19
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export {
|
|
24
|
-
__async
|
|
25
|
-
};
|