@getpara/web-sdk 3.5.0 → 3.6.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/dist/index.js +2 -2
- package/dist/utils/isPasskeySupported.js +1 -1
- package/dist/wallet/keygen.js +18 -18
- package/dist/wallet/privateKey.js +4 -4
- package/dist/wallet/signing.js +8 -8
- package/dist/workers/walletUtils.js +16 -16
- package/dist/workers/worker.d.ts +15 -0
- package/dist/workers/worker.js +44 -2
- package/dist/workers/workerWrapper.js +52 -5
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -10,13 +10,13 @@ import { createCredential, generateSignature, parseCredentialCreationRes } from
|
|
|
10
10
|
import { truncateEthAddress, isPasskeySupported, offRampSend, getChainLogoUrl, getCurrencyLogoUrl } from "./utils/index.js";
|
|
11
11
|
export * from "./utils/isMobile.js";
|
|
12
12
|
export * from "./types/index.js";
|
|
13
|
-
var
|
|
13
|
+
var index_default = ParaWeb;
|
|
14
14
|
export {
|
|
15
15
|
Environment,
|
|
16
16
|
ParaCore,
|
|
17
17
|
ParaWeb,
|
|
18
18
|
createCredential,
|
|
19
|
-
|
|
19
|
+
index_default as default,
|
|
20
20
|
generateSignature,
|
|
21
21
|
getChainLogoUrl,
|
|
22
22
|
getCurrencyLogoUrl,
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
__async
|
|
4
4
|
} from "../chunk-YJOFEY2L.js";
|
|
5
5
|
import { UAParser } from "ua-parser-js";
|
|
6
|
-
const isPasskeySupported = (userAgent) => __async(
|
|
6
|
+
const isPasskeySupported = (userAgent) => __async(null, null, function* () {
|
|
7
7
|
var _a, _b, _c;
|
|
8
8
|
const directPasskeyCheck = yield (_b = (_a = window == null ? void 0 : window.PublicKeyCredential) == null ? void 0 : _a.isUserVerifyingPlatformAuthenticatorAvailable) == null ? void 0 : _b.call(_a);
|
|
9
9
|
if (directPasskeyCheck === true || directPasskeyCheck === false) {
|
package/dist/wallet/keygen.js
CHANGED
|
@@ -17,7 +17,7 @@ function captureTraceCarrier() {
|
|
|
17
17
|
}
|
|
18
18
|
function bindCallbackToActiveContext(fn) {
|
|
19
19
|
const captured = context.active();
|
|
20
|
-
return (...args) => context.with(captured, () => fn(...args));
|
|
20
|
+
return ((...args) => context.with(captured, () => fn(...args)));
|
|
21
21
|
}
|
|
22
22
|
function isKeygenComplete(ctx, userId, walletId) {
|
|
23
23
|
return __async(this, null, function* () {
|
|
@@ -40,15 +40,15 @@ function isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, wallet
|
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
function keygen(ctx, userId, type, secretKey, skipDistribute = false, sessionCookie, emailProps = {}) {
|
|
43
|
-
return new Promise((resolve, reject) => __async(
|
|
43
|
+
return new Promise((resolve, reject) => __async(null, null, function* () {
|
|
44
44
|
const workId = uuid.v4();
|
|
45
45
|
let worker = null;
|
|
46
46
|
worker = yield setupWorker(
|
|
47
47
|
ctx,
|
|
48
|
-
bindCallbackToActiveContext((res) => __async(
|
|
48
|
+
bindCallbackToActiveContext((res) => __async(null, null, function* () {
|
|
49
49
|
yield wrapWithSpan(
|
|
50
50
|
"mpc.keygen.poll_for_address",
|
|
51
|
-
() => waitUntilTrue(() => __async(
|
|
51
|
+
() => waitUntilTrue(() => __async(null, null, function* () {
|
|
52
52
|
return isKeygenComplete(ctx, userId, res.walletId);
|
|
53
53
|
}), 15e3, 1e3)
|
|
54
54
|
);
|
|
@@ -102,16 +102,16 @@ function keygen(ctx, userId, type, secretKey, skipDistribute = false, sessionCoo
|
|
|
102
102
|
}));
|
|
103
103
|
}
|
|
104
104
|
function preKeygen(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey, _skipDistribute = false, partnerId, sessionCookie) {
|
|
105
|
-
return new Promise((resolve, reject) => __async(
|
|
105
|
+
return new Promise((resolve, reject) => __async(null, null, function* () {
|
|
106
106
|
const workId = uuid.v4();
|
|
107
107
|
let worker = null;
|
|
108
108
|
worker = yield setupWorker(
|
|
109
109
|
ctx,
|
|
110
|
-
bindCallbackToActiveContext((res) => __async(
|
|
110
|
+
bindCallbackToActiveContext((res) => __async(null, null, function* () {
|
|
111
111
|
yield wrapWithSpan(
|
|
112
112
|
"mpc.prekeygen.poll_for_address",
|
|
113
113
|
() => waitUntilTrue(
|
|
114
|
-
() => __async(
|
|
114
|
+
() => __async(null, null, function* () {
|
|
115
115
|
return isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId);
|
|
116
116
|
}),
|
|
117
117
|
15e3,
|
|
@@ -152,15 +152,15 @@ function preKeygen(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey,
|
|
|
152
152
|
}));
|
|
153
153
|
}
|
|
154
154
|
function refresh(ctx, sessionCookie, userId, walletId, share, oldPartnerId, newPartnerId, keyShareProtocolId) {
|
|
155
|
-
return new Promise((resolve, reject) => __async(
|
|
155
|
+
return new Promise((resolve, reject) => __async(null, null, function* () {
|
|
156
156
|
const workId = uuid.v4();
|
|
157
157
|
let worker = null;
|
|
158
158
|
worker = yield setupWorker(
|
|
159
159
|
ctx,
|
|
160
|
-
bindCallbackToActiveContext((res) => __async(
|
|
160
|
+
bindCallbackToActiveContext((res) => __async(null, null, function* () {
|
|
161
161
|
const refreshDone = yield wrapWithSpan(
|
|
162
162
|
"mpc.refresh.poll_for_done",
|
|
163
|
-
() => waitUntilTrue(() => __async(
|
|
163
|
+
() => waitUntilTrue(() => __async(null, null, function* () {
|
|
164
164
|
return isRefreshComplete(ctx, userId, walletId, newPartnerId);
|
|
165
165
|
}), 15e3, 1e3)
|
|
166
166
|
);
|
|
@@ -195,15 +195,15 @@ function refresh(ctx, sessionCookie, userId, walletId, share, oldPartnerId, newP
|
|
|
195
195
|
}));
|
|
196
196
|
}
|
|
197
197
|
function ed25519Keygen(ctx, userId, sessionCookie, _emailProps = {}, type) {
|
|
198
|
-
return new Promise((resolve, reject) => __async(
|
|
198
|
+
return new Promise((resolve, reject) => __async(null, null, function* () {
|
|
199
199
|
const workId = uuid.v4();
|
|
200
200
|
let worker = null;
|
|
201
201
|
worker = yield setupWorker(
|
|
202
202
|
ctx,
|
|
203
|
-
bindCallbackToActiveContext((res) => __async(
|
|
203
|
+
bindCallbackToActiveContext((res) => __async(null, null, function* () {
|
|
204
204
|
yield wrapWithSpan(
|
|
205
205
|
"mpc.ed25519_keygen.poll_for_address",
|
|
206
|
-
() => waitUntilTrue(() => __async(
|
|
206
|
+
() => waitUntilTrue(() => __async(null, null, function* () {
|
|
207
207
|
return isKeygenComplete(ctx, userId, res.walletId);
|
|
208
208
|
}), 15e3, 1e3)
|
|
209
209
|
);
|
|
@@ -234,16 +234,16 @@ function ed25519Keygen(ctx, userId, sessionCookie, _emailProps = {}, type) {
|
|
|
234
234
|
}));
|
|
235
235
|
}
|
|
236
236
|
function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie, type) {
|
|
237
|
-
return new Promise((resolve, reject) => __async(
|
|
237
|
+
return new Promise((resolve, reject) => __async(null, null, function* () {
|
|
238
238
|
const workId = uuid.v4();
|
|
239
239
|
let worker = null;
|
|
240
240
|
worker = yield setupWorker(
|
|
241
241
|
ctx,
|
|
242
|
-
bindCallbackToActiveContext((res) => __async(
|
|
242
|
+
bindCallbackToActiveContext((res) => __async(null, null, function* () {
|
|
243
243
|
yield wrapWithSpan(
|
|
244
244
|
"mpc.ed25519_prekeygen.poll_for_address",
|
|
245
245
|
() => waitUntilTrue(
|
|
246
|
-
() => __async(
|
|
246
|
+
() => __async(null, null, function* () {
|
|
247
247
|
return isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId);
|
|
248
248
|
}),
|
|
249
249
|
15e3,
|
|
@@ -283,12 +283,12 @@ function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCo
|
|
|
283
283
|
}
|
|
284
284
|
function initializeWorker(ctx) {
|
|
285
285
|
return __async(this, null, function* () {
|
|
286
|
-
return new Promise((resolve, reject) => __async(
|
|
286
|
+
return new Promise((resolve, reject) => __async(null, null, function* () {
|
|
287
287
|
try {
|
|
288
288
|
const workId = uuid.v4();
|
|
289
289
|
const worker = yield setupWorker(
|
|
290
290
|
ctx,
|
|
291
|
-
() => __async(
|
|
291
|
+
() => __async(null, null, function* () {
|
|
292
292
|
resolve();
|
|
293
293
|
}),
|
|
294
294
|
(error) => {
|
|
@@ -6,12 +6,12 @@ import { setupWorker } from "../workers/workerWrapper.js";
|
|
|
6
6
|
import * as uuid from "uuid";
|
|
7
7
|
function getPrivateKey(ctx, userId, walletId, share, sessionCookie) {
|
|
8
8
|
return __async(this, null, function* () {
|
|
9
|
-
return new Promise((resolve, reject) => __async(
|
|
9
|
+
return new Promise((resolve, reject) => __async(null, null, function* () {
|
|
10
10
|
const workId = uuid.v4();
|
|
11
11
|
let worker = null;
|
|
12
12
|
worker = yield setupWorker(
|
|
13
13
|
ctx,
|
|
14
|
-
(res) => __async(
|
|
14
|
+
(res) => __async(null, null, function* () {
|
|
15
15
|
resolve((res == null ? void 0 : res.privateKey) || res);
|
|
16
16
|
}),
|
|
17
17
|
(error) => {
|
|
@@ -38,12 +38,12 @@ function getPrivateKey(ctx, userId, walletId, share, sessionCookie) {
|
|
|
38
38
|
}
|
|
39
39
|
function getED25519PrivateKey(ctx, userId, walletId, share, sessionCookie) {
|
|
40
40
|
return __async(this, null, function* () {
|
|
41
|
-
return new Promise((resolve, reject) => __async(
|
|
41
|
+
return new Promise((resolve, reject) => __async(null, null, function* () {
|
|
42
42
|
const workId = uuid.v4();
|
|
43
43
|
let worker = null;
|
|
44
44
|
worker = yield setupWorker(
|
|
45
45
|
ctx,
|
|
46
|
-
(res) => __async(
|
|
46
|
+
(res) => __async(null, null, function* () {
|
|
47
47
|
resolve((res == null ? void 0 : res.privateKey) || res);
|
|
48
48
|
}),
|
|
49
49
|
(error) => {
|
package/dist/wallet/signing.js
CHANGED
|
@@ -16,12 +16,12 @@ function captureTraceCarrier() {
|
|
|
16
16
|
}
|
|
17
17
|
function signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
|
|
18
18
|
return __async(this, null, function* () {
|
|
19
|
-
return new Promise((resolve, reject) => __async(
|
|
19
|
+
return new Promise((resolve, reject) => __async(null, null, function* () {
|
|
20
20
|
const workId = uuid.v4();
|
|
21
21
|
let worker = null;
|
|
22
22
|
worker = yield setupWorker(
|
|
23
23
|
ctx,
|
|
24
|
-
(sendTransactionRes) => __async(
|
|
24
|
+
(sendTransactionRes) => __async(null, null, function* () {
|
|
25
25
|
resolve(sendTransactionRes);
|
|
26
26
|
}),
|
|
27
27
|
(error) => {
|
|
@@ -49,12 +49,12 @@ function signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCooki
|
|
|
49
49
|
}
|
|
50
50
|
function sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
|
|
51
51
|
return __async(this, null, function* () {
|
|
52
|
-
return new Promise((resolve, reject) => __async(
|
|
52
|
+
return new Promise((resolve, reject) => __async(null, null, function* () {
|
|
53
53
|
const workId = uuid.v4();
|
|
54
54
|
let worker = null;
|
|
55
55
|
worker = yield setupWorker(
|
|
56
56
|
ctx,
|
|
57
|
-
(sendTransactionRes) => __async(
|
|
57
|
+
(sendTransactionRes) => __async(null, null, function* () {
|
|
58
58
|
resolve(sendTransactionRes);
|
|
59
59
|
}),
|
|
60
60
|
(error) => {
|
|
@@ -82,12 +82,12 @@ function sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCooki
|
|
|
82
82
|
}
|
|
83
83
|
function signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS, cosmosSignDoc) {
|
|
84
84
|
return __async(this, null, function* () {
|
|
85
|
-
return new Promise((resolve, reject) => __async(
|
|
85
|
+
return new Promise((resolve, reject) => __async(null, null, function* () {
|
|
86
86
|
const workId = uuid.v4();
|
|
87
87
|
let worker = null;
|
|
88
88
|
worker = yield setupWorker(
|
|
89
89
|
ctx,
|
|
90
|
-
(signMessageRes) => __async(
|
|
90
|
+
(signMessageRes) => __async(null, null, function* () {
|
|
91
91
|
resolve(signMessageRes);
|
|
92
92
|
}),
|
|
93
93
|
(error) => {
|
|
@@ -116,12 +116,12 @@ function signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKL
|
|
|
116
116
|
}
|
|
117
117
|
function ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
|
|
118
118
|
return __async(this, null, function* () {
|
|
119
|
-
return new Promise((resolve, reject) => __async(
|
|
119
|
+
return new Promise((resolve, reject) => __async(null, null, function* () {
|
|
120
120
|
const workId = uuid.v4();
|
|
121
121
|
let worker = null;
|
|
122
122
|
worker = yield setupWorker(
|
|
123
123
|
ctx,
|
|
124
|
-
(signMessageRes) => __async(
|
|
124
|
+
(signMessageRes) => __async(null, null, function* () {
|
|
125
125
|
resolve(signMessageRes);
|
|
126
126
|
}),
|
|
127
127
|
(error) => {
|
|
@@ -46,7 +46,7 @@ function ed25519Keygen(ctx, userId, _sessionCookie, _emailProps, type = "SOLANA"
|
|
|
46
46
|
scheme: "ED25519",
|
|
47
47
|
type
|
|
48
48
|
});
|
|
49
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
49
|
+
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets, ctx.mpcNetworkUrlOverride);
|
|
50
50
|
try {
|
|
51
51
|
const newSigner = yield new Promise(
|
|
52
52
|
(resolve, reject) => globalThis.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
|
|
@@ -73,7 +73,7 @@ function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, _sessionC
|
|
|
73
73
|
scheme: "ED25519",
|
|
74
74
|
type
|
|
75
75
|
});
|
|
76
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
76
|
+
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets, ctx.mpcNetworkUrlOverride);
|
|
77
77
|
try {
|
|
78
78
|
const newSigner = yield new Promise(
|
|
79
79
|
(resolve, reject) => globalThis.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
|
|
@@ -93,7 +93,7 @@ function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
|
|
|
93
93
|
return __async(this, null, function* () {
|
|
94
94
|
const protocolId = uuid.v4();
|
|
95
95
|
const preSignMessageRes = ctx.client.preSignMessage(userId, walletId, base64Bytes, "ED25519", void 0, protocolId);
|
|
96
|
-
const signRes = function() {
|
|
96
|
+
const signRes = (function() {
|
|
97
97
|
return __async(this, null, function* () {
|
|
98
98
|
try {
|
|
99
99
|
const base64Sig = yield new Promise(
|
|
@@ -111,7 +111,7 @@ function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
|
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
113
|
});
|
|
114
|
-
}();
|
|
114
|
+
})();
|
|
115
115
|
signRes.catch(() => {
|
|
116
116
|
});
|
|
117
117
|
const { pendingTransactionId } = yield preSignMessageRes;
|
|
@@ -137,7 +137,7 @@ function keygen(ctx, userId, type, secretKey) {
|
|
|
137
137
|
walletId
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
140
|
+
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets, ctx.mpcNetworkUrlOverride);
|
|
141
141
|
const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
|
|
142
142
|
const createAccountFn = ctx.useDKLS ? globalThis.dklsCreateAccount : globalThis.createAccountV2;
|
|
143
143
|
try {
|
|
@@ -175,7 +175,7 @@ function preKeygen(ctx, _partnerId, pregenIdentifier, pregenIdentifierType, type
|
|
|
175
175
|
type,
|
|
176
176
|
cosmosPrefix: type === "COSMOS" ? ctx.cosmosPrefix : void 0
|
|
177
177
|
});
|
|
178
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
178
|
+
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets, ctx.mpcNetworkUrlOverride);
|
|
179
179
|
const signerConfigUser = configDKLSBase(walletId, "USER", ctx.disableWebSockets);
|
|
180
180
|
try {
|
|
181
181
|
const newSigner = yield new Promise(
|
|
@@ -208,14 +208,14 @@ function signMessage(ctx, share, walletId, userId, message, cosmosSignDoc) {
|
|
|
208
208
|
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
209
209
|
return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
|
|
210
210
|
}
|
|
211
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
211
|
+
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets, ctx.mpcNetworkUrlOverride);
|
|
212
212
|
const signMessageFn = ctx.useDKLS ? globalThis.dklsSignMessage : globalThis.signMessage;
|
|
213
213
|
const parsedShare = JSON.parse(share);
|
|
214
214
|
if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
|
|
215
215
|
parsedShare.disableWebSockets = ctx.disableWebSockets;
|
|
216
216
|
}
|
|
217
217
|
share = JSON.stringify(parsedShare);
|
|
218
|
-
const signMessageRes = function() {
|
|
218
|
+
const signMessageRes = (function() {
|
|
219
219
|
return __async(this, null, function* () {
|
|
220
220
|
try {
|
|
221
221
|
return yield new Promise(
|
|
@@ -230,7 +230,7 @@ function signMessage(ctx, share, walletId, userId, message, cosmosSignDoc) {
|
|
|
230
230
|
throw wrapMpcError(`error signing for account with userId ${userId} and walletId ${walletId}`, mpcErr, { protocolId });
|
|
231
231
|
}
|
|
232
232
|
});
|
|
233
|
-
}();
|
|
233
|
+
})();
|
|
234
234
|
signMessageRes.catch(() => {
|
|
235
235
|
});
|
|
236
236
|
const { pendingTransactionId } = yield preSignMessageRes;
|
|
@@ -252,14 +252,14 @@ function signTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
|
252
252
|
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
253
253
|
return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
|
|
254
254
|
}
|
|
255
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
255
|
+
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets, ctx.mpcNetworkUrlOverride);
|
|
256
256
|
const signTransactionFn = ctx.useDKLS ? globalThis.dklsSendTransaction : globalThis.sendTransaction;
|
|
257
257
|
const parsedShare = JSON.parse(share);
|
|
258
258
|
if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
|
|
259
259
|
parsedShare.disableWebSockets = ctx.disableWebSockets;
|
|
260
260
|
}
|
|
261
261
|
share = JSON.stringify(parsedShare);
|
|
262
|
-
const signTxRes = function() {
|
|
262
|
+
const signTxRes = (function() {
|
|
263
263
|
return __async(this, null, function* () {
|
|
264
264
|
try {
|
|
265
265
|
return yield new Promise(
|
|
@@ -276,7 +276,7 @@ function signTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
|
276
276
|
});
|
|
277
277
|
}
|
|
278
278
|
});
|
|
279
|
-
}();
|
|
279
|
+
})();
|
|
280
280
|
signTxRes.catch(() => {
|
|
281
281
|
});
|
|
282
282
|
const {
|
|
@@ -300,14 +300,14 @@ function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
|
300
300
|
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
301
301
|
return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
|
|
302
302
|
}
|
|
303
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
303
|
+
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets, ctx.mpcNetworkUrlOverride);
|
|
304
304
|
const sendTransactionFn = ctx.useDKLS ? globalThis.dklsSendTransaction : globalThis.sendTransaction;
|
|
305
305
|
const parsedShare = JSON.parse(share);
|
|
306
306
|
if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
|
|
307
307
|
parsedShare.disableWebSockets = ctx.disableWebSockets;
|
|
308
308
|
}
|
|
309
309
|
share = JSON.stringify(parsedShare);
|
|
310
|
-
const sendTxRes = function() {
|
|
310
|
+
const sendTxRes = (function() {
|
|
311
311
|
return __async(this, null, function* () {
|
|
312
312
|
try {
|
|
313
313
|
return yield new Promise(
|
|
@@ -326,7 +326,7 @@ function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
|
326
326
|
);
|
|
327
327
|
}
|
|
328
328
|
});
|
|
329
|
-
}();
|
|
329
|
+
})();
|
|
330
330
|
sendTxRes.catch(() => {
|
|
331
331
|
});
|
|
332
332
|
const {
|
|
@@ -343,7 +343,7 @@ function refresh(ctx, share, walletId, userId, oldPartnerId, newPartnerId, keySh
|
|
|
343
343
|
const {
|
|
344
344
|
data: { protocolId }
|
|
345
345
|
} = yield ctx.client.refreshKeys(userId, walletId, oldPartnerId, newPartnerId, keyShareProtocolId, true);
|
|
346
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
346
|
+
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets, ctx.mpcNetworkUrlOverride);
|
|
347
347
|
const refreshFn = ctx.useDKLS ? globalThis.dklsRefresh : globalThis.refresh;
|
|
348
348
|
const parsedShare = JSON.parse(share);
|
|
349
349
|
if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
|
package/dist/workers/worker.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ export interface Message {
|
|
|
3
3
|
env: Environment;
|
|
4
4
|
apiKey?: string;
|
|
5
5
|
cosmosPrefix?: string;
|
|
6
|
+
apiBaseUrlOverride?: string;
|
|
7
|
+
portalUrlOverride?: string;
|
|
8
|
+
mpcNetworkUrlOverride?: string;
|
|
6
9
|
offloadMPCComputationURL?: string;
|
|
7
10
|
disableWorkers?: boolean;
|
|
8
11
|
functionType: string;
|
|
@@ -15,6 +18,18 @@ export interface Message {
|
|
|
15
18
|
workId?: string;
|
|
16
19
|
__otel?: Record<string, string>;
|
|
17
20
|
}
|
|
21
|
+
export declare const WORKER_ERROR_RESPONSE_KEY = "__paraWorkerError";
|
|
22
|
+
export interface SerializedWorkerError {
|
|
23
|
+
message: string;
|
|
24
|
+
name: string;
|
|
25
|
+
code?: string;
|
|
26
|
+
status?: number;
|
|
27
|
+
responseURL?: string;
|
|
28
|
+
data?: object;
|
|
29
|
+
stack?: string;
|
|
30
|
+
isParaApiError?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export declare function serializeWorkerError(error: object | string | null | undefined): SerializedWorkerError;
|
|
18
33
|
/**
|
|
19
34
|
* Executes an operation with retry capabilities
|
|
20
35
|
* @param operation The function to execute
|
package/dist/workers/worker.js
CHANGED
|
@@ -44,7 +44,40 @@ import {
|
|
|
44
44
|
paraVersion
|
|
45
45
|
} from "@getpara/core-sdk";
|
|
46
46
|
import { classifyMpcError, unwrapMpcError } from "./mpcWorkerError.js";
|
|
47
|
+
const WORKER_ERROR_RESPONSE_KEY = "__paraWorkerError";
|
|
47
48
|
let wasmLoaded = false;
|
|
49
|
+
function getSerializableError(error) {
|
|
50
|
+
if (error && typeof error === "object") {
|
|
51
|
+
return error;
|
|
52
|
+
}
|
|
53
|
+
return void 0;
|
|
54
|
+
}
|
|
55
|
+
function serializeWorkerError(error) {
|
|
56
|
+
const errorFields = getSerializableError(error);
|
|
57
|
+
if (!errorFields) {
|
|
58
|
+
return {
|
|
59
|
+
message: typeof error === "string" && error ? error : "Worker operation failed",
|
|
60
|
+
name: "Error"
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
64
|
+
message: typeof errorFields.message === "string" && errorFields.message ? errorFields.message : "Worker operation failed",
|
|
65
|
+
name: typeof errorFields.name === "string" && errorFields.name ? errorFields.name : "Error"
|
|
66
|
+
}, typeof errorFields.code === "string" && { code: errorFields.code }), typeof errorFields.status === "number" && { status: errorFields.status }), typeof errorFields.responseURL === "string" && { responseURL: errorFields.responseURL }), typeof errorFields.data === "object" && errorFields.data !== null && { data: errorFields.data }), typeof errorFields.stack === "string" && { stack: errorFields.stack }), typeof errorFields.isParaApiError === "boolean" && { isParaApiError: errorFields.isParaApiError });
|
|
67
|
+
}
|
|
68
|
+
function isRetryableError(error) {
|
|
69
|
+
const errorFields = getSerializableError(error);
|
|
70
|
+
if (!errorFields) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
if (errorFields.code === "POLICY_DENIED") {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
if (typeof errorFields.status === "number" && errorFields.status >= 400 && errorFields.status < 500) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
48
81
|
function tryFetchWasm(url) {
|
|
49
82
|
return __async(this, null, function* () {
|
|
50
83
|
const response = yield fetch(url, { mode: "cors" });
|
|
@@ -174,7 +207,7 @@ function withRetry(operation, maxRetries = 2, timeoutMs = 1e4) {
|
|
|
174
207
|
}
|
|
175
208
|
} catch (error) {
|
|
176
209
|
retries++;
|
|
177
|
-
if (retries > maxRetries) {
|
|
210
|
+
if (!isRetryableError(error) || retries > maxRetries) {
|
|
178
211
|
throw error;
|
|
179
212
|
}
|
|
180
213
|
console.warn(`Operation failed (attempt ${retries}/${maxRetries}), retrying...`, error);
|
|
@@ -213,6 +246,9 @@ function handleMessage(e, postMessage, useFetchAdapter) {
|
|
|
213
246
|
env,
|
|
214
247
|
apiKey,
|
|
215
248
|
cosmosPrefix = "cosmos",
|
|
249
|
+
apiBaseUrlOverride,
|
|
250
|
+
portalUrlOverride,
|
|
251
|
+
mpcNetworkUrlOverride,
|
|
216
252
|
offloadMPCComputationURL,
|
|
217
253
|
disableWorkers,
|
|
218
254
|
sessionCookie,
|
|
@@ -234,6 +270,7 @@ function handleMessage(e, postMessage, useFetchAdapter) {
|
|
|
234
270
|
version: paraVersion,
|
|
235
271
|
apiKey,
|
|
236
272
|
useFetchAdapter,
|
|
273
|
+
apiBaseUrlOverride,
|
|
237
274
|
retrieveSessionCookie: () => sessionCookie,
|
|
238
275
|
// Threading the parent's W3C trace context through so the worker's UMC
|
|
239
276
|
// requests carry the same traceparent the FE's mpc.* span would generate
|
|
@@ -241,6 +278,9 @@ function handleMessage(e, postMessage, useFetchAdapter) {
|
|
|
241
278
|
// mpc.* span, completing the FE → worker → BE waterfall.
|
|
242
279
|
staticTraceContext: __otel
|
|
243
280
|
}),
|
|
281
|
+
apiBaseUrlOverride,
|
|
282
|
+
portalUrlOverride,
|
|
283
|
+
mpcNetworkUrlOverride,
|
|
244
284
|
offloadMPCComputationURL,
|
|
245
285
|
mpcComputationClient: offloadMPCComputationURL ? mpcComputationClient.initClient(offloadMPCComputationURL, !!disableWorkers) : void 0,
|
|
246
286
|
useDKLS,
|
|
@@ -251,7 +291,7 @@ function handleMessage(e, postMessage, useFetchAdapter) {
|
|
|
251
291
|
try {
|
|
252
292
|
if (!wasmLoaded && (!ctx.offloadMPCComputationURL || ctx.useDKLS)) {
|
|
253
293
|
yield loadWasm(ctx, wasmOverride);
|
|
254
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
294
|
+
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets, ctx.mpcNetworkUrlOverride);
|
|
255
295
|
if (globalThis.initWasm) {
|
|
256
296
|
yield new Promise(
|
|
257
297
|
(resolve, reject) => {
|
|
@@ -280,6 +320,8 @@ function handleMessage(e, postMessage, useFetchAdapter) {
|
|
|
280
320
|
});
|
|
281
321
|
}
|
|
282
322
|
export {
|
|
323
|
+
WORKER_ERROR_RESPONSE_KEY,
|
|
283
324
|
handleMessage,
|
|
325
|
+
serializeWorkerError,
|
|
284
326
|
withRetry
|
|
285
327
|
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
|
-
__async
|
|
3
|
+
__async,
|
|
4
|
+
__spreadValues
|
|
4
5
|
} from "../chunk-YJOFEY2L.js";
|
|
5
6
|
import { getPortalBaseURL } from "@getpara/core-sdk";
|
|
6
|
-
import { handleMessage } from "./worker.js";
|
|
7
|
+
import { handleMessage, WORKER_ERROR_RESPONSE_KEY } from "./worker.js";
|
|
7
8
|
const CLEAR_WORKER_TIMEOUT_MS = 1e3 * 90;
|
|
8
9
|
let workerInstance;
|
|
9
10
|
const resFunctionMap = {};
|
|
@@ -15,6 +16,37 @@ function removeWorkId(workId, skipClearTimeout) {
|
|
|
15
16
|
}
|
|
16
17
|
clearTimeout(timeoutId);
|
|
17
18
|
}
|
|
19
|
+
function withLocalDevUrlOverrides(ctx, message) {
|
|
20
|
+
const overrides = __spreadValues(__spreadValues(__spreadValues({}, ctx.apiBaseUrlOverride ? { apiBaseUrlOverride: ctx.apiBaseUrlOverride } : {}), ctx.portalUrlOverride ? { portalUrlOverride: ctx.portalUrlOverride } : {}), ctx.mpcNetworkUrlOverride ? { mpcNetworkUrlOverride: ctx.mpcNetworkUrlOverride } : {});
|
|
21
|
+
return Object.keys(overrides).length > 0 ? __spreadValues(__spreadValues({}, message), overrides) : message;
|
|
22
|
+
}
|
|
23
|
+
function deserializeWorkerError(serializedError) {
|
|
24
|
+
const error = new Error(serializedError.message);
|
|
25
|
+
error.name = serializedError.name;
|
|
26
|
+
if (serializedError.stack) {
|
|
27
|
+
error.stack = serializedError.stack;
|
|
28
|
+
}
|
|
29
|
+
if (serializedError.code) {
|
|
30
|
+
error.code = serializedError.code;
|
|
31
|
+
}
|
|
32
|
+
if (typeof serializedError.status === "number") {
|
|
33
|
+
error.status = serializedError.status;
|
|
34
|
+
}
|
|
35
|
+
if (serializedError.responseURL) {
|
|
36
|
+
error.responseURL = serializedError.responseURL;
|
|
37
|
+
}
|
|
38
|
+
if (serializedError.data) {
|
|
39
|
+
error.data = serializedError.data;
|
|
40
|
+
}
|
|
41
|
+
if (typeof serializedError.isParaApiError === "boolean") {
|
|
42
|
+
Object.defineProperty(error, "isParaApiError", {
|
|
43
|
+
value: serializedError.isParaApiError,
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: true
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return error;
|
|
49
|
+
}
|
|
18
50
|
function setupWorker(ctx, resFunction, errorFunction, workId, errorContext) {
|
|
19
51
|
return __async(this, null, function* () {
|
|
20
52
|
if (ctx.disableWorkers) {
|
|
@@ -23,10 +55,11 @@ function setupWorker(ctx, resFunction, errorFunction, workId, errorContext) {
|
|
|
23
55
|
(function() {
|
|
24
56
|
return __async(this, null, function* () {
|
|
25
57
|
try {
|
|
58
|
+
const messageWithOverrides = withLocalDevUrlOverrides(ctx, message);
|
|
26
59
|
const onmessage = (event) => {
|
|
27
60
|
resFunction(event.data);
|
|
28
61
|
};
|
|
29
|
-
yield handleMessage({ data:
|
|
62
|
+
yield handleMessage({ data: messageWithOverrides }, (data) => onmessage({ data }), ctx.disableWorkers);
|
|
30
63
|
} catch (error) {
|
|
31
64
|
errorFunction(error);
|
|
32
65
|
}
|
|
@@ -58,10 +91,17 @@ function setupWorker(ctx, resFunction, errorFunction, workId, errorContext) {
|
|
|
58
91
|
const workerBlob = new Blob([yield workerRes.text()], { type: "application/javascript" });
|
|
59
92
|
const workerScriptURL = URL.createObjectURL(workerBlob);
|
|
60
93
|
workerInstance = new Worker(workerScriptURL);
|
|
61
|
-
const onmessage = (event) => __async(
|
|
94
|
+
const onmessage = (event) => __async(null, null, function* () {
|
|
95
|
+
var _a, _b;
|
|
62
96
|
const { workId: messageWorkId } = event.data;
|
|
63
97
|
delete event.data.workId;
|
|
64
98
|
if (messageWorkId && resFunctionMap[messageWorkId]) {
|
|
99
|
+
const workerError = event.data[WORKER_ERROR_RESPONSE_KEY];
|
|
100
|
+
if (workerError) {
|
|
101
|
+
(_b = (_a = resFunctionMap[messageWorkId]).errorFn) == null ? void 0 : _b.call(_a, deserializeWorkerError(workerError));
|
|
102
|
+
removeWorkId(messageWorkId);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
65
105
|
yield resFunctionMap[messageWorkId].fn(event.data);
|
|
66
106
|
removeWorkId(messageWorkId);
|
|
67
107
|
}
|
|
@@ -80,7 +120,14 @@ function setupWorker(ctx, resFunction, errorFunction, workId, errorContext) {
|
|
|
80
120
|
workerInstance = void 0;
|
|
81
121
|
};
|
|
82
122
|
}
|
|
83
|
-
return workerInstance
|
|
123
|
+
return new Proxy(workerInstance, {
|
|
124
|
+
get(target, prop, receiver) {
|
|
125
|
+
if (prop === "postMessage") {
|
|
126
|
+
return (message) => target.postMessage(withLocalDevUrlOverrides(ctx, message));
|
|
127
|
+
}
|
|
128
|
+
return Reflect.get(target, prop, receiver);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
84
131
|
});
|
|
85
132
|
}
|
|
86
133
|
export {
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/web-sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@getpara/core-sdk": "3.
|
|
6
|
-
"@getpara/user-management-client": "3.
|
|
5
|
+
"@getpara/core-sdk": "3.6.0",
|
|
6
|
+
"@getpara/user-management-client": "3.6.0",
|
|
7
7
|
"@opentelemetry/api": "^1.9.1",
|
|
8
8
|
"base64url": "^3.0.1",
|
|
9
9
|
"buffer": "6.0.3",
|
|
10
10
|
"cbor-web": "^9.0.2",
|
|
11
11
|
"node-forge": "^1.3.1",
|
|
12
12
|
"ua-parser-js": "^2.0.2",
|
|
13
|
-
"uuid": "^11.1.
|
|
13
|
+
"uuid": "^11.1.1"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@types/node-forge": "^1.3.11",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dist",
|
|
31
31
|
"package.json"
|
|
32
32
|
],
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "565535ab0cf38d65f6996fc9f1ede52d133ddac0",
|
|
34
34
|
"main": "dist/index.js",
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "rm -rf dist && yarn typegen && node ./scripts/build.mjs && yarn post-build",
|