@getpara/server-sdk 1.7.1 → 1.9.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/cjs/ParaServer.js +91 -0
- package/dist/cjs/ServerLocalStorage.js +48 -0
- package/dist/cjs/ServerSessionStorage.js +48 -0
- package/dist/cjs/ServerUtils.js +76 -0
- package/dist/cjs/index.js +3 -523
- package/dist/cjs/wallet/keygen.js +227 -0
- package/dist/cjs/wallet/privateKey.js +86 -0
- package/dist/cjs/wallet/signing.js +172 -0
- package/dist/cjs/wasm/wasm_exec.js +589 -0
- package/dist/cjs/workers/walletUtils.js +367 -0
- package/dist/cjs/workers/worker.js +18 -904
- package/dist/cjs/workers/workerWrapper.js +88 -0
- package/dist/esm/ParaServer.js +37 -0
- package/dist/esm/ServerLocalStorage.js +26 -0
- package/dist/esm/ServerSessionStorage.js +26 -0
- package/dist/esm/ServerUtils.js +54 -0
- package/dist/esm/chunk-FTA5RKYX.js +8 -0
- package/dist/esm/index.js +4 -466
- package/dist/esm/package.json +3 -1
- package/dist/esm/wallet/keygen.js +160 -0
- package/dist/esm/wallet/privateKey.js +32 -0
- package/dist/esm/wallet/signing.js +109 -0
- package/dist/esm/{workers/wasm_exec-CFNSOXDO.js → wasm/wasm_exec.js} +68 -74
- package/dist/esm/workers/walletUtils.js +290 -0
- package/dist/esm/workers/worker.js +37 -329
- package/dist/esm/workers/workerWrapper.js +44 -0
- package/package.json +4 -4
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/cjs/workers/worker.js.br +0 -0
- package/dist/cjs/workers/worker.js.gz +0 -0
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
- package/dist/esm/workers/chunk-ILICZWQV.js +0 -36
- package/dist/esm/workers/chunk-ILICZWQV.js.br +0 -0
- package/dist/esm/workers/chunk-ILICZWQV.js.gz +0 -0
- package/dist/esm/workers/wasm_exec-CFNSOXDO.js.br +0 -0
- package/dist/esm/workers/wasm_exec-CFNSOXDO.js.gz +0 -0
- package/dist/esm/workers/worker.js.br +0 -0
- package/dist/esm/workers/worker.js.gz +0 -0
|
@@ -1,325 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
7
21
|
import axios from "axios";
|
|
8
22
|
import {
|
|
9
23
|
getPortalBaseURL,
|
|
10
24
|
initClient,
|
|
11
25
|
mpcComputationClient,
|
|
12
26
|
paraVersion,
|
|
13
|
-
WalletType
|
|
27
|
+
WalletType
|
|
14
28
|
} from "@getpara/core-sdk";
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
import { getBaseMPCNetworkUrl, WalletScheme, WalletType } from "@getpara/core-sdk";
|
|
18
|
-
var configCGGMPBase = (serverUrl, walletId, id) => `{"ServerUrl":"${serverUrl}", "WalletId": "${walletId}", "Id":"${id}", "Ids":["USER","CAPSULE"], "Threshold":1}`;
|
|
19
|
-
var configDKLSBase = (walletId, id, disableWebSockets) => `{"walletId": "${walletId}", "id":"${id}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${disableWebSockets}}`;
|
|
20
|
-
function keygenRequest(ctx, userId, walletId, protocolId) {
|
|
21
|
-
return __async(this, null, function* () {
|
|
22
|
-
const { data } = yield ctx.mpcComputationClient.post("/wallets", {
|
|
23
|
-
userId,
|
|
24
|
-
walletId,
|
|
25
|
-
protocolId
|
|
26
|
-
});
|
|
27
|
-
return data;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
function signMessageRequest(ctx, userId, walletId, protocolId, message, signer) {
|
|
31
|
-
return __async(this, null, function* () {
|
|
32
|
-
const { data } = yield ctx.mpcComputationClient.post(`/wallets/${walletId}/messages/sign`, {
|
|
33
|
-
userId,
|
|
34
|
-
protocolId,
|
|
35
|
-
message,
|
|
36
|
-
signer
|
|
37
|
-
});
|
|
38
|
-
return data;
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
function sendTransactionRequest(ctx, userId, walletId, protocolId, transaction, signer, chainId) {
|
|
42
|
-
return __async(this, null, function* () {
|
|
43
|
-
const { data } = yield ctx.mpcComputationClient.post(`/wallets/${walletId}/transactions/send`, {
|
|
44
|
-
userId,
|
|
45
|
-
protocolId,
|
|
46
|
-
transaction,
|
|
47
|
-
signer,
|
|
48
|
-
chainId
|
|
49
|
-
});
|
|
50
|
-
return data;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
function ed25519Keygen(ctx, userId) {
|
|
54
|
-
return __async(this, null, function* () {
|
|
55
|
-
const { walletId, protocolId } = yield ctx.client.createWallet(userId, {
|
|
56
|
-
scheme: WalletScheme.ED25519,
|
|
57
|
-
type: WalletType.SOLANA
|
|
58
|
-
});
|
|
59
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
60
|
-
try {
|
|
61
|
-
const newSigner = yield new Promise(
|
|
62
|
-
(resolve, reject) => global.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
|
|
63
|
-
if (err) {
|
|
64
|
-
reject(err);
|
|
65
|
-
}
|
|
66
|
-
resolve(result);
|
|
67
|
-
})
|
|
68
|
-
);
|
|
69
|
-
return { signer: newSigner, walletId };
|
|
70
|
-
} catch (e) {
|
|
71
|
-
throw new Error(`error creating account of type SOLANA with userId ${userId} and walletId ${walletId}`);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType) {
|
|
76
|
-
return __async(this, null, function* () {
|
|
77
|
-
const { walletId, protocolId } = yield ctx.client.createPregenWallet({
|
|
78
|
-
pregenIdentifier,
|
|
79
|
-
pregenIdentifierType,
|
|
80
|
-
scheme: WalletScheme.ED25519,
|
|
81
|
-
type: WalletType.SOLANA
|
|
82
|
-
});
|
|
83
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
84
|
-
try {
|
|
85
|
-
const newSigner = yield new Promise(
|
|
86
|
-
(resolve, reject) => global.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
|
|
87
|
-
if (err) {
|
|
88
|
-
reject(err);
|
|
89
|
-
}
|
|
90
|
-
resolve(result);
|
|
91
|
-
})
|
|
92
|
-
);
|
|
93
|
-
return { signer: newSigner, walletId };
|
|
94
|
-
} catch (e) {
|
|
95
|
-
throw new Error(`error creating account of type SOLANA with walletId ${walletId}`);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
|
|
100
|
-
return __async(this, null, function* () {
|
|
101
|
-
const { protocolId } = yield ctx.client.preSignMessage(userId, walletId, base64Bytes, WalletScheme.ED25519);
|
|
102
|
-
try {
|
|
103
|
-
const base64Sig = yield new Promise(
|
|
104
|
-
(resolve, reject) => global.ed25519Sign(share, protocolId, base64Bytes, (err, result) => {
|
|
105
|
-
if (err) {
|
|
106
|
-
reject(err);
|
|
107
|
-
}
|
|
108
|
-
resolve(result);
|
|
109
|
-
})
|
|
110
|
-
);
|
|
111
|
-
return { signature: base64Sig };
|
|
112
|
-
} catch (e) {
|
|
113
|
-
throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
function keygen(ctx, userId, type, secretKey) {
|
|
118
|
-
return __async(this, null, function* () {
|
|
119
|
-
const { walletId, protocolId } = yield ctx.client.createWallet(userId, {
|
|
120
|
-
useTwoSigners: true,
|
|
121
|
-
scheme: ctx.useDKLS ? WalletScheme.DKLS : WalletScheme.CGGMP,
|
|
122
|
-
type,
|
|
123
|
-
cosmosPrefix: type === WalletType.COSMOS ? ctx.cosmosPrefix : void 0
|
|
124
|
-
});
|
|
125
|
-
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
126
|
-
return {
|
|
127
|
-
signer: (yield keygenRequest(ctx, userId, walletId, protocolId)).signer,
|
|
128
|
-
walletId
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
132
|
-
const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
|
|
133
|
-
const createAccountFn = ctx.useDKLS ? global.dklsCreateAccount : global.createAccountV2;
|
|
134
|
-
try {
|
|
135
|
-
const newSigner = yield new Promise(
|
|
136
|
-
(resolve, reject) => createAccountFn(
|
|
137
|
-
signerConfigUser,
|
|
138
|
-
serverUrl,
|
|
139
|
-
protocolId,
|
|
140
|
-
secretKey,
|
|
141
|
-
() => {
|
|
142
|
-
},
|
|
143
|
-
// no-op for deprecated callback to update progress percentage
|
|
144
|
-
(err, result) => {
|
|
145
|
-
if (err) {
|
|
146
|
-
reject(err);
|
|
147
|
-
}
|
|
148
|
-
resolve(result);
|
|
149
|
-
}
|
|
150
|
-
)
|
|
151
|
-
);
|
|
152
|
-
return { signer: newSigner, walletId };
|
|
153
|
-
} catch (e) {
|
|
154
|
-
throw new Error(`error creating account of type ${type} with userId ${userId} and walletId ${walletId}`);
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey) {
|
|
159
|
-
return __async(this, null, function* () {
|
|
160
|
-
const { walletId, protocolId } = yield ctx.client.createPregenWallet({
|
|
161
|
-
pregenIdentifier,
|
|
162
|
-
pregenIdentifierType,
|
|
163
|
-
type,
|
|
164
|
-
cosmosPrefix: type === WalletType.COSMOS ? ctx.cosmosPrefix : void 0
|
|
165
|
-
});
|
|
166
|
-
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
167
|
-
return {
|
|
168
|
-
signer: (yield keygenRequest(ctx, partnerId, walletId, protocolId)).signer,
|
|
169
|
-
walletId
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
173
|
-
const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
|
|
174
|
-
const createAccountFn = ctx.useDKLS ? global.dklsCreateAccount : global.createAccountV2;
|
|
175
|
-
try {
|
|
176
|
-
const newSigner = yield new Promise(
|
|
177
|
-
(resolve, reject) => createAccountFn(
|
|
178
|
-
signerConfigUser,
|
|
179
|
-
serverUrl,
|
|
180
|
-
protocolId,
|
|
181
|
-
secretKey,
|
|
182
|
-
() => {
|
|
183
|
-
},
|
|
184
|
-
// no-op for deprecated callback to update progress percentage
|
|
185
|
-
(err, result) => {
|
|
186
|
-
if (err) {
|
|
187
|
-
reject(err);
|
|
188
|
-
}
|
|
189
|
-
resolve(result);
|
|
190
|
-
}
|
|
191
|
-
)
|
|
192
|
-
);
|
|
193
|
-
return { signer: newSigner, walletId };
|
|
194
|
-
} catch (e) {
|
|
195
|
-
throw new Error(`error creating account of type ${type} with walletId ${walletId}`);
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
function signMessage(ctx, share, walletId, userId, message) {
|
|
200
|
-
return __async(this, null, function* () {
|
|
201
|
-
const { protocolId, pendingTransactionId } = yield ctx.client.preSignMessage(userId, walletId, message);
|
|
202
|
-
if (pendingTransactionId) {
|
|
203
|
-
return { pendingTransactionId };
|
|
204
|
-
}
|
|
205
|
-
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
206
|
-
return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
|
|
207
|
-
}
|
|
208
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
209
|
-
const signMessageFn = ctx.useDKLS ? global.dklsSignMessage : global.signMessage;
|
|
210
|
-
try {
|
|
211
|
-
return new Promise(
|
|
212
|
-
(resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
|
|
213
|
-
if (err) {
|
|
214
|
-
reject(err);
|
|
215
|
-
}
|
|
216
|
-
resolve({ signature: result });
|
|
217
|
-
})
|
|
218
|
-
);
|
|
219
|
-
} catch (e) {
|
|
220
|
-
throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
function signTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
225
|
-
return __async(this, null, function* () {
|
|
226
|
-
const {
|
|
227
|
-
data: { protocolId, pendingTransactionId }
|
|
228
|
-
} = yield ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId });
|
|
229
|
-
if (pendingTransactionId) {
|
|
230
|
-
return { pendingTransactionId };
|
|
231
|
-
}
|
|
232
|
-
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
233
|
-
return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
|
|
234
|
-
}
|
|
235
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
236
|
-
const signTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
|
|
237
|
-
try {
|
|
238
|
-
return new Promise(
|
|
239
|
-
(resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
240
|
-
if (err) {
|
|
241
|
-
reject(err);
|
|
242
|
-
}
|
|
243
|
-
resolve({ signature: result });
|
|
244
|
-
})
|
|
245
|
-
);
|
|
246
|
-
} catch (e) {
|
|
247
|
-
throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
252
|
-
return __async(this, null, function* () {
|
|
253
|
-
const {
|
|
254
|
-
data: { protocolId, pendingTransactionId }
|
|
255
|
-
} = yield ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId });
|
|
256
|
-
if (pendingTransactionId) {
|
|
257
|
-
return { pendingTransactionId };
|
|
258
|
-
}
|
|
259
|
-
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
260
|
-
return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
|
|
261
|
-
}
|
|
262
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
263
|
-
const sendTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
|
|
264
|
-
try {
|
|
265
|
-
return new Promise(
|
|
266
|
-
(resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
267
|
-
if (err) {
|
|
268
|
-
reject(err);
|
|
269
|
-
}
|
|
270
|
-
resolve({ signature: result });
|
|
271
|
-
})
|
|
272
|
-
);
|
|
273
|
-
} catch (e) {
|
|
274
|
-
throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
function refresh(ctx, share, walletId, userId) {
|
|
279
|
-
return __async(this, null, function* () {
|
|
280
|
-
const {
|
|
281
|
-
data: { protocolId }
|
|
282
|
-
} = yield ctx.client.refreshKeys(userId, walletId);
|
|
283
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
284
|
-
const refreshFn = ctx.useDKLS ? global.dklsRefresh : global.refresh;
|
|
285
|
-
try {
|
|
286
|
-
return new Promise(
|
|
287
|
-
(resolve, reject) => refreshFn(share, serverUrl, protocolId, (err, result) => {
|
|
288
|
-
if (err) {
|
|
289
|
-
reject(err);
|
|
290
|
-
}
|
|
291
|
-
resolve(result);
|
|
292
|
-
})
|
|
293
|
-
);
|
|
294
|
-
} catch (e) {
|
|
295
|
-
throw new Error(`error refreshing keys for account with userId ${userId} and walletId ${walletId}`);
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
function getPrivateKey(ctx, share, walletId, userId) {
|
|
300
|
-
return __async(this, null, function* () {
|
|
301
|
-
const paraShare = yield ctx.client.getParaShare(userId, walletId);
|
|
302
|
-
if (!paraShare) {
|
|
303
|
-
console.error("unable to retrieve Para share");
|
|
304
|
-
return "";
|
|
305
|
-
}
|
|
306
|
-
try {
|
|
307
|
-
return new Promise(
|
|
308
|
-
(resolve, reject) => global.getPrivateKey(share, paraShare, (err, result) => {
|
|
309
|
-
if (err) {
|
|
310
|
-
reject(err);
|
|
311
|
-
}
|
|
312
|
-
resolve(result);
|
|
313
|
-
})
|
|
314
|
-
);
|
|
315
|
-
} catch (e) {
|
|
316
|
-
throw new Error(`error getting private key for account with userId ${userId} and walletId ${walletId}`);
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// src/workers/worker.ts
|
|
322
|
-
var rawWasm;
|
|
29
|
+
import * as walletUtils from "./walletUtils.js";
|
|
30
|
+
let rawWasm;
|
|
323
31
|
function requestWasmWithRetries(ctx, retries = 3) {
|
|
324
32
|
return __async(this, null, function* () {
|
|
325
33
|
for (let i = 0; i < retries; i++) {
|
|
@@ -335,8 +43,8 @@ function requestWasmWithRetries(ctx, retries = 3) {
|
|
|
335
43
|
}
|
|
336
44
|
function loadWasm(ctx) {
|
|
337
45
|
return __async(this, null, function* () {
|
|
338
|
-
yield import("
|
|
339
|
-
global.WebSocket =
|
|
46
|
+
yield import("../wasm/wasm_exec.js");
|
|
47
|
+
global.WebSocket = require("ws");
|
|
340
48
|
const goWasm = new global.Go();
|
|
341
49
|
if (!rawWasm) {
|
|
342
50
|
rawWasm = (yield requestWasmWithRetries(ctx)).data;
|
|
@@ -351,46 +59,46 @@ function executeMessage(ctx, message) {
|
|
|
351
59
|
const { functionType, params } = message;
|
|
352
60
|
switch (functionType) {
|
|
353
61
|
case "KEYGEN": {
|
|
354
|
-
const { userId, secretKey, type =
|
|
355
|
-
return keygen(ctx, userId, type, secretKey);
|
|
62
|
+
const { userId, secretKey, type = WalletType.EVM } = params;
|
|
63
|
+
return walletUtils.keygen(ctx, userId, type, secretKey);
|
|
356
64
|
}
|
|
357
65
|
case "SIGN_TRANSACTION": {
|
|
358
66
|
const { share, walletId, userId, tx, chainId } = params;
|
|
359
|
-
return signTransaction(ctx, share, walletId, userId, tx, chainId);
|
|
67
|
+
return walletUtils.signTransaction(ctx, share, walletId, userId, tx, chainId);
|
|
360
68
|
}
|
|
361
69
|
case "SEND_TRANSACTION": {
|
|
362
70
|
const { share, walletId, userId, tx, chainId } = params;
|
|
363
|
-
return sendTransaction(ctx, share, walletId, userId, tx, chainId);
|
|
71
|
+
return walletUtils.sendTransaction(ctx, share, walletId, userId, tx, chainId);
|
|
364
72
|
}
|
|
365
73
|
case "SIGN_MESSAGE": {
|
|
366
74
|
const { share, walletId, userId, message: message2 } = params;
|
|
367
|
-
return signMessage(ctx, share, walletId, userId, message2);
|
|
75
|
+
return walletUtils.signMessage(ctx, share, walletId, userId, message2);
|
|
368
76
|
}
|
|
369
77
|
case "REFRESH": {
|
|
370
78
|
const { share, walletId, userId } = params;
|
|
371
|
-
return refresh(ctx, share, walletId, userId);
|
|
79
|
+
return walletUtils.refresh(ctx, share, walletId, userId);
|
|
372
80
|
}
|
|
373
81
|
case "PREKEYGEN": {
|
|
374
|
-
const { email, partnerId, secretKey, type =
|
|
82
|
+
const { email, partnerId, secretKey, type = WalletType.EVM } = params;
|
|
375
83
|
let { pregenIdentifier, pregenIdentifierType } = params;
|
|
376
84
|
if (email !== "null" && email !== "undefined" && email !== "" && email != null) {
|
|
377
85
|
pregenIdentifier = email;
|
|
378
86
|
pregenIdentifierType = "EMAIL";
|
|
379
87
|
}
|
|
380
|
-
const keygenRes = yield preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey);
|
|
88
|
+
const keygenRes = yield walletUtils.preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey);
|
|
381
89
|
return keygenRes;
|
|
382
90
|
}
|
|
383
91
|
case "GET_PRIVATE_KEY": {
|
|
384
92
|
const { share, walletId, userId } = params;
|
|
385
|
-
return yield getPrivateKey(ctx, share, walletId, userId);
|
|
93
|
+
return yield walletUtils.getPrivateKey(ctx, share, walletId, userId);
|
|
386
94
|
}
|
|
387
95
|
case "ED25519_KEYGEN": {
|
|
388
96
|
const { userId } = params;
|
|
389
|
-
return ed25519Keygen(ctx, userId);
|
|
97
|
+
return walletUtils.ed25519Keygen(ctx, userId);
|
|
390
98
|
}
|
|
391
99
|
case "ED25519_SIGN": {
|
|
392
100
|
const { share, walletId, userId, base64Bytes } = params;
|
|
393
|
-
return ed25519Sign(ctx, share, userId, walletId, base64Bytes);
|
|
101
|
+
return walletUtils.ed25519Sign(ctx, share, userId, walletId, base64Bytes);
|
|
394
102
|
}
|
|
395
103
|
case "ED25519_PREKEYGEN": {
|
|
396
104
|
const { email } = params;
|
|
@@ -399,7 +107,7 @@ function executeMessage(ctx, message) {
|
|
|
399
107
|
pregenIdentifier = email;
|
|
400
108
|
pregenIdentifierType = "EMAIL";
|
|
401
109
|
}
|
|
402
|
-
return ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType);
|
|
110
|
+
return walletUtils.ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType);
|
|
403
111
|
}
|
|
404
112
|
default: {
|
|
405
113
|
throw new Error(`functionType: ${functionType} not supported`);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import "../chunk-FTA5RKYX.js";
|
|
2
|
+
import { Worker } from "worker_threads";
|
|
3
|
+
import { getPortalBaseURL } from "@getpara/core-sdk";
|
|
4
|
+
const CLEAR_WORKER_TIMEOUT_MS = 1e3 * 90;
|
|
5
|
+
let worker;
|
|
6
|
+
const resFunctionMap = {};
|
|
7
|
+
function removeWorkId(workId, skipClearTimeout) {
|
|
8
|
+
const { timeoutId } = resFunctionMap[workId];
|
|
9
|
+
delete resFunctionMap[workId];
|
|
10
|
+
if (skipClearTimeout) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
clearTimeout(timeoutId);
|
|
14
|
+
}
|
|
15
|
+
async function setupWorker(ctx, resFunction, workId) {
|
|
16
|
+
const timeoutId = setTimeout(() => {
|
|
17
|
+
removeWorkId(workId, true);
|
|
18
|
+
}, CLEAR_WORKER_TIMEOUT_MS);
|
|
19
|
+
resFunctionMap[workId] = {
|
|
20
|
+
fn: resFunction,
|
|
21
|
+
timeoutId
|
|
22
|
+
};
|
|
23
|
+
if (!worker || !worker.threadId) {
|
|
24
|
+
const workerRes = await fetch(`${getPortalBaseURL(ctx)}/static/js/mpcWorkerServer-bundle.js`);
|
|
25
|
+
worker = new Worker(await workerRes.text(), { eval: true });
|
|
26
|
+
const onmessage = async (message) => {
|
|
27
|
+
const { workId: messageWorkId } = message;
|
|
28
|
+
delete message.workId;
|
|
29
|
+
await resFunctionMap[messageWorkId].fn(message);
|
|
30
|
+
removeWorkId(messageWorkId);
|
|
31
|
+
};
|
|
32
|
+
worker.on("message", onmessage);
|
|
33
|
+
worker.on("error", (err) => {
|
|
34
|
+
throw err;
|
|
35
|
+
});
|
|
36
|
+
worker.on("exit", (code) => {
|
|
37
|
+
console.error(`worker stopped with exit code ${code}`);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return worker;
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
setupWorker
|
|
44
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/server-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"wasm_exec.js"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@getpara/core-sdk": "1.
|
|
13
|
-
"@getpara/user-management-client": "1.
|
|
12
|
+
"@getpara/core-sdk": "1.9.0",
|
|
13
|
+
"@getpara/user-management-client": "1.9.0",
|
|
14
14
|
"@sentry/node": "^9.1.0",
|
|
15
15
|
"uuid": "^9.0.1",
|
|
16
16
|
"ws": "^8.14.2"
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"dist",
|
|
32
32
|
"package.json"
|
|
33
33
|
],
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "3d749844bf071e2c8de2769dd16e17c026951109"
|
|
35
35
|
}
|
package/dist/cjs/index.js.br
DELETED
|
Binary file
|
package/dist/cjs/index.js.gz
DELETED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/esm/index.js.br
DELETED
|
Binary file
|
package/dist/esm/index.js.gz
DELETED
|
Binary file
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
-
}) : x)(function(x) {
|
|
5
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
-
});
|
|
8
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
9
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
-
};
|
|
11
|
-
var __async = (__this, __arguments, generator) => {
|
|
12
|
-
return new Promise((resolve, reject) => {
|
|
13
|
-
var fulfilled = (value) => {
|
|
14
|
-
try {
|
|
15
|
-
step(generator.next(value));
|
|
16
|
-
} catch (e) {
|
|
17
|
-
reject(e);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
var rejected = (value) => {
|
|
21
|
-
try {
|
|
22
|
-
step(generator.throw(value));
|
|
23
|
-
} catch (e) {
|
|
24
|
-
reject(e);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
28
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export {
|
|
33
|
-
__require,
|
|
34
|
-
__commonJS,
|
|
35
|
-
__async
|
|
36
|
-
};
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|