@getpara/server-sdk 2.0.0-alpha.3 → 2.0.0-alpha.6
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 +77 -0
- package/dist/cjs/index.js +3 -523
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/wallet/keygen.js +229 -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 +24 -906
- package/dist/cjs/workers/workerWrapper.js +88 -0
- package/dist/esm/ParaServer.js +39 -0
- package/dist/esm/ServerLocalStorage.js +26 -0
- package/dist/esm/ServerSessionStorage.js +26 -0
- package/dist/esm/ServerUtils.js +55 -0
- package/dist/esm/chunk-FTA5RKYX.js +8 -0
- package/dist/esm/index.js +4 -468
- package/dist/esm/package.json +6 -0
- 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 +41 -336
- package/dist/esm/workers/workerWrapper.js +44 -0
- package/dist/types/ServerUtils.d.ts +5 -4
- package/dist/types/wallet/keygen.d.ts +5 -3
- package/dist/types/workers/walletUtils.d.ts +3 -3
- package/dist/types/workers/worker.d.ts +2 -1
- package/package.json +5 -5
- 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
package/dist/esm/index.js
CHANGED
|
@@ -1,472 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import "./chunk-FTA5RKYX.js";
|
|
2
2
|
export * from "@getpara/core-sdk";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import ParaCore, {
|
|
6
|
-
Environment
|
|
7
|
-
} from "@getpara/core-sdk";
|
|
8
|
-
import * as Sentry from "@sentry/node";
|
|
9
|
-
|
|
10
|
-
// src/ServerLocalStorage.ts
|
|
11
|
-
var ServerLocalStorage = class {
|
|
12
|
-
constructor() {
|
|
13
|
-
this.localStorage = {};
|
|
14
|
-
this.get = (key) => {
|
|
15
|
-
return this.localStorage[key] || null;
|
|
16
|
-
};
|
|
17
|
-
this.set = (key, value) => {
|
|
18
|
-
this.localStorage[key] = value;
|
|
19
|
-
};
|
|
20
|
-
this.removeItem = (key) => {
|
|
21
|
-
delete this.localStorage[key];
|
|
22
|
-
};
|
|
23
|
-
this.clear = (prefix) => {
|
|
24
|
-
const keys = Object.keys(this.localStorage);
|
|
25
|
-
for (let key in keys) {
|
|
26
|
-
if (key && key.startsWith(prefix)) {
|
|
27
|
-
this.removeItem(key);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// src/ServerSessionStorage.ts
|
|
35
|
-
var ServerSessionStorage = class {
|
|
36
|
-
constructor() {
|
|
37
|
-
this.sessionStorage = {};
|
|
38
|
-
this.get = (key) => {
|
|
39
|
-
return this.sessionStorage[key] || null;
|
|
40
|
-
};
|
|
41
|
-
this.set = (key, value) => {
|
|
42
|
-
this.sessionStorage[key] = value;
|
|
43
|
-
};
|
|
44
|
-
this.removeItem = (key) => {
|
|
45
|
-
delete this.sessionStorage[key];
|
|
46
|
-
};
|
|
47
|
-
this.clear = (prefix) => {
|
|
48
|
-
const keys = Object.keys(this.sessionStorage);
|
|
49
|
-
for (let key in keys) {
|
|
50
|
-
if (key && key.startsWith(prefix)) {
|
|
51
|
-
this.removeItem(key);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// src/wallet/keygen.ts
|
|
59
|
-
import * as uuid from "uuid";
|
|
60
|
-
import { waitUntilTrue } from "@getpara/core-sdk";
|
|
61
|
-
|
|
62
|
-
// src/workers/workerWrapper.ts
|
|
63
|
-
import { Worker } from "worker_threads";
|
|
64
|
-
import { getPortalBaseURL } from "@getpara/core-sdk";
|
|
65
|
-
var CLEAR_WORKER_TIMEOUT_MS = 1e3 * 90;
|
|
66
|
-
var worker;
|
|
67
|
-
var resFunctionMap = {};
|
|
68
|
-
function removeWorkId(workId, skipClearTimeout) {
|
|
69
|
-
const { timeoutId } = resFunctionMap[workId];
|
|
70
|
-
delete resFunctionMap[workId];
|
|
71
|
-
if (skipClearTimeout) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
clearTimeout(timeoutId);
|
|
75
|
-
}
|
|
76
|
-
async function setupWorker(ctx, resFunction, workId) {
|
|
77
|
-
const timeoutId = setTimeout(() => {
|
|
78
|
-
removeWorkId(workId, true);
|
|
79
|
-
}, CLEAR_WORKER_TIMEOUT_MS);
|
|
80
|
-
resFunctionMap[workId] = {
|
|
81
|
-
fn: resFunction,
|
|
82
|
-
timeoutId
|
|
83
|
-
};
|
|
84
|
-
if (!worker || !worker.threadId) {
|
|
85
|
-
const workerRes = await fetch(`${getPortalBaseURL(ctx)}/static/js/mpcWorkerServer-bundle.js`);
|
|
86
|
-
worker = new Worker(await workerRes.text(), { eval: true });
|
|
87
|
-
const onmessage = async (message) => {
|
|
88
|
-
const { workId: messageWorkId } = message;
|
|
89
|
-
delete message.workId;
|
|
90
|
-
await resFunctionMap[messageWorkId].fn(message);
|
|
91
|
-
removeWorkId(messageWorkId);
|
|
92
|
-
};
|
|
93
|
-
worker.on("message", onmessage);
|
|
94
|
-
worker.on("error", (err) => {
|
|
95
|
-
throw err;
|
|
96
|
-
});
|
|
97
|
-
worker.on("exit", (code) => {
|
|
98
|
-
console.error(`worker stopped with exit code ${code}`);
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
return worker;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// src/wallet/keygen.ts
|
|
105
|
-
async function isKeygenComplete(ctx, userId, walletId) {
|
|
106
|
-
const wallets = await ctx.client.getWallets(userId);
|
|
107
|
-
const wallet = wallets.data.wallets.find((w) => w.id === walletId);
|
|
108
|
-
return !!wallet.address;
|
|
109
|
-
}
|
|
110
|
-
async function isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, walletId) {
|
|
111
|
-
const wallets = await ctx.client.getPregenWallets({ [pregenIdentifierType]: [pregenIdentifier] });
|
|
112
|
-
const wallet = wallets.wallets.find((w) => w.id === walletId);
|
|
113
|
-
return !!wallet?.address;
|
|
114
|
-
}
|
|
115
|
-
function keygen(ctx, userId, type, secretKey, skipDistribute = false, sessionCookie, _emailProps = {}) {
|
|
116
|
-
return new Promise(async (resolve) => {
|
|
117
|
-
const workId = uuid.v4();
|
|
118
|
-
const worker2 = await setupWorker(
|
|
119
|
-
ctx,
|
|
120
|
-
async (res) => {
|
|
121
|
-
await waitUntilTrue(async () => isKeygenComplete(ctx, userId, res.walletId), 15e3, 1e3);
|
|
122
|
-
if (skipDistribute) {
|
|
123
|
-
resolve({
|
|
124
|
-
signer: res.signer,
|
|
125
|
-
walletId: res.walletId,
|
|
126
|
-
recoveryShare: null
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
workId
|
|
131
|
-
);
|
|
132
|
-
worker2.postMessage({
|
|
133
|
-
env: ctx.env,
|
|
134
|
-
apiKey: ctx.apiKey,
|
|
135
|
-
cosmosPrefix: ctx.cosmosPrefix,
|
|
136
|
-
params: { userId, secretKey, type },
|
|
137
|
-
functionType: "KEYGEN",
|
|
138
|
-
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
139
|
-
disableWorkers: ctx.disableWorkers,
|
|
140
|
-
sessionCookie,
|
|
141
|
-
useDKLS: ctx.useDKLS,
|
|
142
|
-
disableWebSockets: ctx.disableWebSockets,
|
|
143
|
-
wasmOverride: ctx.wasmOverride,
|
|
144
|
-
workId
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
function preKeygen(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey, _skipDistribute = false, partnerId, sessionCookie) {
|
|
149
|
-
return new Promise(async (resolve) => {
|
|
150
|
-
const workId = uuid.v4();
|
|
151
|
-
const worker2 = await setupWorker(
|
|
152
|
-
ctx,
|
|
153
|
-
async (res) => {
|
|
154
|
-
await waitUntilTrue(
|
|
155
|
-
async () => isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId),
|
|
156
|
-
15e3,
|
|
157
|
-
1e3
|
|
158
|
-
);
|
|
159
|
-
resolve({
|
|
160
|
-
signer: res.signer,
|
|
161
|
-
walletId: res.walletId,
|
|
162
|
-
recoveryShare: null
|
|
163
|
-
});
|
|
164
|
-
},
|
|
165
|
-
workId
|
|
166
|
-
);
|
|
167
|
-
const email = void 0;
|
|
168
|
-
const params = { pregenIdentifier, pregenIdentifierType, secretKey, partnerId, email, type };
|
|
169
|
-
if (pregenIdentifierType === "EMAIL") {
|
|
170
|
-
params.email = pregenIdentifier;
|
|
171
|
-
}
|
|
172
|
-
worker2.postMessage({
|
|
173
|
-
env: ctx.env,
|
|
174
|
-
apiKey: ctx.apiKey,
|
|
175
|
-
cosmosPrefix: ctx.cosmosPrefix,
|
|
176
|
-
params,
|
|
177
|
-
functionType: "PREKEYGEN",
|
|
178
|
-
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
179
|
-
disableWorkers: ctx.disableWorkers,
|
|
180
|
-
sessionCookie,
|
|
181
|
-
useDKLS: ctx.useDKLS,
|
|
182
|
-
disableWebSockets: ctx.disableWebSockets,
|
|
183
|
-
wasmOverride: ctx.wasmOverride,
|
|
184
|
-
workId
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
function ed25519Keygen(ctx, userId, sessionCookie, _emailProps = {}) {
|
|
189
|
-
return new Promise(async (resolve) => {
|
|
190
|
-
const workId = uuid.v4();
|
|
191
|
-
const worker2 = await setupWorker(
|
|
192
|
-
ctx,
|
|
193
|
-
async (res) => {
|
|
194
|
-
await waitUntilTrue(async () => isKeygenComplete(ctx, userId, res.walletId), 15e3, 1e3);
|
|
195
|
-
resolve({
|
|
196
|
-
signer: res.signer,
|
|
197
|
-
walletId: res.walletId,
|
|
198
|
-
recoveryShare: null
|
|
199
|
-
});
|
|
200
|
-
},
|
|
201
|
-
workId
|
|
202
|
-
);
|
|
203
|
-
worker2.postMessage({
|
|
204
|
-
env: ctx.env,
|
|
205
|
-
apiKey: ctx.apiKey,
|
|
206
|
-
cosmosPrefix: ctx.cosmosPrefix,
|
|
207
|
-
params: { userId },
|
|
208
|
-
functionType: "ED25519_KEYGEN",
|
|
209
|
-
disableWorkers: ctx.disableWorkers,
|
|
210
|
-
sessionCookie,
|
|
211
|
-
disableWebSockets: ctx.disableWebSockets,
|
|
212
|
-
wasmOverride: ctx.wasmOverride,
|
|
213
|
-
workId
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie) {
|
|
218
|
-
return new Promise(async (resolve) => {
|
|
219
|
-
const workId = uuid.v4();
|
|
220
|
-
const worker2 = await setupWorker(
|
|
221
|
-
ctx,
|
|
222
|
-
async (res) => {
|
|
223
|
-
await waitUntilTrue(
|
|
224
|
-
async () => isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId),
|
|
225
|
-
15e3,
|
|
226
|
-
1e3
|
|
227
|
-
);
|
|
228
|
-
resolve({
|
|
229
|
-
signer: res.signer,
|
|
230
|
-
walletId: res.walletId,
|
|
231
|
-
recoveryShare: null
|
|
232
|
-
});
|
|
233
|
-
},
|
|
234
|
-
workId
|
|
235
|
-
);
|
|
236
|
-
const email = void 0;
|
|
237
|
-
const params = { pregenIdentifier, pregenIdentifierType, email };
|
|
238
|
-
if (pregenIdentifierType === "EMAIL") {
|
|
239
|
-
params.email = pregenIdentifier;
|
|
240
|
-
}
|
|
241
|
-
worker2.postMessage({
|
|
242
|
-
env: ctx.env,
|
|
243
|
-
apiKey: ctx.apiKey,
|
|
244
|
-
cosmosPrefix: ctx.cosmosPrefix,
|
|
245
|
-
params,
|
|
246
|
-
functionType: "ED25519_PREKEYGEN",
|
|
247
|
-
disableWorkers: ctx.disableWorkers,
|
|
248
|
-
sessionCookie,
|
|
249
|
-
disableWebSockets: ctx.disableWebSockets,
|
|
250
|
-
wasmOverride: ctx.wasmOverride,
|
|
251
|
-
workId
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// src/wallet/signing.ts
|
|
257
|
-
import * as uuid2 from "uuid";
|
|
258
|
-
async function signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
|
|
259
|
-
return await new Promise(async (resolve) => {
|
|
260
|
-
const workId = uuid2.v4();
|
|
261
|
-
const worker2 = await setupWorker(
|
|
262
|
-
ctx,
|
|
263
|
-
async (sendTransactionRes) => {
|
|
264
|
-
resolve(sendTransactionRes);
|
|
265
|
-
},
|
|
266
|
-
workId
|
|
267
|
-
);
|
|
268
|
-
worker2.postMessage({
|
|
269
|
-
env: ctx.env,
|
|
270
|
-
apiKey: ctx.apiKey,
|
|
271
|
-
cosmosPrefix: ctx.cosmosPrefix,
|
|
272
|
-
params: { share, walletId, userId, tx, chainId },
|
|
273
|
-
functionType: "SIGN_TRANSACTION",
|
|
274
|
-
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
275
|
-
disableWorkers: ctx.disableWorkers,
|
|
276
|
-
sessionCookie,
|
|
277
|
-
useDKLS: isDKLS,
|
|
278
|
-
disableWebSockets: ctx.disableWebSockets,
|
|
279
|
-
wasmOverride: ctx.wasmOverride,
|
|
280
|
-
workId
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
async function sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
|
|
285
|
-
return await new Promise(async (resolve) => {
|
|
286
|
-
const workId = uuid2.v4();
|
|
287
|
-
const worker2 = await setupWorker(
|
|
288
|
-
ctx,
|
|
289
|
-
async (sendTransactionRes) => {
|
|
290
|
-
resolve(sendTransactionRes);
|
|
291
|
-
},
|
|
292
|
-
workId
|
|
293
|
-
);
|
|
294
|
-
worker2.postMessage({
|
|
295
|
-
env: ctx.env,
|
|
296
|
-
apiKey: ctx.apiKey,
|
|
297
|
-
params: { share, walletId, userId, tx, chainId },
|
|
298
|
-
functionType: "SEND_TRANSACTION",
|
|
299
|
-
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
300
|
-
disableWorkers: ctx.disableWorkers,
|
|
301
|
-
sessionCookie,
|
|
302
|
-
useDKLS: isDKLS,
|
|
303
|
-
disableWebSockets: ctx.disableWebSockets,
|
|
304
|
-
wasmOverride: ctx.wasmOverride,
|
|
305
|
-
workId
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
async function signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS) {
|
|
310
|
-
return await new Promise(async (resolve) => {
|
|
311
|
-
const workId = uuid2.v4();
|
|
312
|
-
const worker2 = await setupWorker(
|
|
313
|
-
ctx,
|
|
314
|
-
async (signMessageRes) => {
|
|
315
|
-
resolve(signMessageRes);
|
|
316
|
-
},
|
|
317
|
-
workId
|
|
318
|
-
);
|
|
319
|
-
worker2.postMessage({
|
|
320
|
-
env: ctx.env,
|
|
321
|
-
apiKey: ctx.apiKey,
|
|
322
|
-
params: { share, walletId, userId, message },
|
|
323
|
-
functionType: "SIGN_MESSAGE",
|
|
324
|
-
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
325
|
-
disableWorkers: ctx.disableWorkers,
|
|
326
|
-
sessionCookie,
|
|
327
|
-
useDKLS: isDKLS,
|
|
328
|
-
disableWebSockets: ctx.disableWebSockets,
|
|
329
|
-
wasmOverride: ctx.wasmOverride,
|
|
330
|
-
workId
|
|
331
|
-
});
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
async function ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
|
|
335
|
-
return await new Promise(async (resolve) => {
|
|
336
|
-
const workId = uuid2.v4();
|
|
337
|
-
const worker2 = await setupWorker(
|
|
338
|
-
ctx,
|
|
339
|
-
async (signMessageRes) => {
|
|
340
|
-
resolve(signMessageRes);
|
|
341
|
-
},
|
|
342
|
-
workId
|
|
343
|
-
);
|
|
344
|
-
worker2.postMessage({
|
|
345
|
-
env: ctx.env,
|
|
346
|
-
apiKey: ctx.apiKey,
|
|
347
|
-
params: { share, walletId, userId, base64Bytes },
|
|
348
|
-
functionType: "ED25519_SIGN",
|
|
349
|
-
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
350
|
-
disableWorkers: ctx.disableWorkers,
|
|
351
|
-
sessionCookie,
|
|
352
|
-
disableWebSockets: ctx.disableWebSockets,
|
|
353
|
-
wasmOverride: ctx.wasmOverride,
|
|
354
|
-
workId
|
|
355
|
-
});
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
// src/wallet/privateKey.ts
|
|
360
|
-
import * as uuid3 from "uuid";
|
|
361
|
-
async function getPrivateKey(ctx, userId, walletId, share, sessionCookie) {
|
|
362
|
-
return await new Promise(async (resolve) => {
|
|
363
|
-
const workId = uuid3.v4();
|
|
364
|
-
const worker2 = await setupWorker(
|
|
365
|
-
ctx,
|
|
366
|
-
async (res) => {
|
|
367
|
-
resolve(res);
|
|
368
|
-
},
|
|
369
|
-
workId
|
|
370
|
-
);
|
|
371
|
-
worker2.postMessage({
|
|
372
|
-
env: ctx.env,
|
|
373
|
-
apiKey: ctx.apiKey,
|
|
374
|
-
cosmosPrefix: ctx.cosmosPrefix,
|
|
375
|
-
params: { share, walletId, userId },
|
|
376
|
-
functionType: "GET_PRIVATE_KEY",
|
|
377
|
-
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
378
|
-
disableWorkers: ctx.disableWorkers,
|
|
379
|
-
sessionCookie,
|
|
380
|
-
useDKLS: ctx.useDKLS,
|
|
381
|
-
disableWebSockets: ctx.disableWebSockets,
|
|
382
|
-
wasmOverride: ctx.wasmOverride,
|
|
383
|
-
workId
|
|
384
|
-
});
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
// src/ServerUtils.ts
|
|
389
|
-
var ServerUtils = class {
|
|
390
|
-
constructor() {
|
|
391
|
-
this.localStorage = new ServerLocalStorage();
|
|
392
|
-
this.sessionStorage = new ServerSessionStorage();
|
|
393
|
-
this.secureStorage = void 0;
|
|
394
|
-
this.isSyncStorage = true;
|
|
395
|
-
this.disableProviderModal = true;
|
|
396
|
-
}
|
|
397
|
-
getPrivateKey(ctx, userId, walletId, share, sessionCookie) {
|
|
398
|
-
return getPrivateKey(ctx, userId, walletId, share, sessionCookie);
|
|
399
|
-
}
|
|
400
|
-
keygen(ctx, userId, type, secretKey, sessionCookie, emailProps) {
|
|
401
|
-
return keygen(ctx, userId, type, secretKey, true, sessionCookie, emailProps);
|
|
402
|
-
}
|
|
403
|
-
refresh(_ctx, _sessionCookie, _userId, _walletId, _share, _oldPartnerId, _newPartnerId) {
|
|
404
|
-
throw new Error("Refresh function is not implemented in the ServerUtils class.");
|
|
405
|
-
}
|
|
406
|
-
preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey, sessionCookie) {
|
|
407
|
-
return preKeygen(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey, false, partnerId, sessionCookie);
|
|
408
|
-
}
|
|
409
|
-
signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS) {
|
|
410
|
-
return signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS);
|
|
411
|
-
}
|
|
412
|
-
signTransaction(ctx, userId, walletId, share, message, chainId, sessionCookie, isDKLS) {
|
|
413
|
-
return signTransaction(ctx, userId, walletId, share, message, chainId, sessionCookie, isDKLS);
|
|
414
|
-
}
|
|
415
|
-
sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
|
|
416
|
-
return sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS);
|
|
417
|
-
}
|
|
418
|
-
signHash(_address, _hash) {
|
|
419
|
-
throw new Error("SignHash is not implemented in the ServerUtils class.");
|
|
420
|
-
}
|
|
421
|
-
ed25519Keygen(ctx, userId, sessionCookie, emailProps) {
|
|
422
|
-
return ed25519Keygen(ctx, userId, sessionCookie, emailProps);
|
|
423
|
-
}
|
|
424
|
-
ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie) {
|
|
425
|
-
return ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie);
|
|
426
|
-
}
|
|
427
|
-
ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
|
|
428
|
-
return ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie);
|
|
429
|
-
}
|
|
430
|
-
openPopup(_popupUrl) {
|
|
431
|
-
throw new Error("OpenPopup is not implemented in the ServerUtils class.");
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
|
|
435
|
-
// src/ParaServer.ts
|
|
436
|
-
var Para = class extends ParaCore {
|
|
437
|
-
constructor(env, apiKey, opts) {
|
|
438
|
-
super(env, apiKey, opts);
|
|
439
|
-
if (env !== Environment.PROD && env !== Environment.DEV) {
|
|
440
|
-
Sentry.init({
|
|
441
|
-
environment: env.toLowerCase(),
|
|
442
|
-
dsn: "https://2a26842d951255c2721fde5c1dd2b252@o4504568036720640.ingest.us.sentry.io/4508850906791936"
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
getPlatformUtils() {
|
|
447
|
-
return new ServerUtils();
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* Claims a pregenerated wallet.
|
|
451
|
-
*
|
|
452
|
-
* NOTE: This function is only available on the client side.
|
|
453
|
-
* When called from the server SDK, it throws an error.
|
|
454
|
-
*
|
|
455
|
-
* @param {Object} opts the options object.
|
|
456
|
-
* @param {string} opts.pregenIdentifier - the identifier of the user claiming the wallet.
|
|
457
|
-
* @param {TPregenIdentifierType} opts.pregenIdentifierType - the type of the identifier.
|
|
458
|
-
* @returns {Promise<string | undefined>} A promise that rejects with an error.
|
|
459
|
-
*/
|
|
460
|
-
async claimPregenWallets(_) {
|
|
461
|
-
throw new Error(
|
|
462
|
-
"claimPregenWallets is not available in the server SDK. This function is only supported on the client side. Please ensure you are using the client SDK to call this method."
|
|
463
|
-
);
|
|
464
|
-
}
|
|
465
|
-
};
|
|
466
|
-
|
|
467
|
-
// src/index.ts
|
|
468
|
-
var src_default = Para;
|
|
3
|
+
import { Para as ParaServer } from "./ParaServer.js";
|
|
4
|
+
var src_default = ParaServer;
|
|
469
5
|
export {
|
|
470
|
-
Para,
|
|
6
|
+
ParaServer as Para,
|
|
471
7
|
src_default as default
|
|
472
8
|
};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import "../chunk-FTA5RKYX.js";
|
|
2
|
+
import * as uuid from "uuid";
|
|
3
|
+
import { waitUntilTrue } from "@getpara/core-sdk";
|
|
4
|
+
import { setupWorker } from "../workers/workerWrapper.js";
|
|
5
|
+
async function isKeygenComplete(ctx, userId, walletId) {
|
|
6
|
+
const wallets = await ctx.client.getWallets(userId);
|
|
7
|
+
const wallet = wallets.data.wallets.find((w) => w.id === walletId);
|
|
8
|
+
return !!wallet?.address;
|
|
9
|
+
}
|
|
10
|
+
async function isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, walletId) {
|
|
11
|
+
const wallets = await ctx.client.getPregenWallets({ [pregenIdentifierType]: [pregenIdentifier] });
|
|
12
|
+
const wallet = wallets.wallets.find((w) => w.id === walletId);
|
|
13
|
+
return !!wallet?.address;
|
|
14
|
+
}
|
|
15
|
+
function keygen(ctx, userId, type, secretKey, sessionCookie, _emailProps = {}) {
|
|
16
|
+
return new Promise(async (resolve) => {
|
|
17
|
+
const workId = uuid.v4();
|
|
18
|
+
const worker = await setupWorker(
|
|
19
|
+
ctx,
|
|
20
|
+
async (res) => {
|
|
21
|
+
await waitUntilTrue(async () => isKeygenComplete(ctx, userId, res.walletId), 15e3, 1e3);
|
|
22
|
+
resolve({
|
|
23
|
+
signer: res.signer,
|
|
24
|
+
walletId: res.walletId,
|
|
25
|
+
recoveryShare: null
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
workId
|
|
29
|
+
);
|
|
30
|
+
worker.postMessage({
|
|
31
|
+
env: ctx.env,
|
|
32
|
+
apiKey: ctx.apiKey,
|
|
33
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
34
|
+
params: { userId, secretKey, type },
|
|
35
|
+
functionType: "KEYGEN",
|
|
36
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
37
|
+
disableWorkers: ctx.disableWorkers,
|
|
38
|
+
sessionCookie,
|
|
39
|
+
useDKLS: ctx.useDKLS,
|
|
40
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
41
|
+
wasmOverride: ctx.wasmOverride,
|
|
42
|
+
workId
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function preKeygen(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey, _skipDistribute = false, partnerId, sessionCookie) {
|
|
47
|
+
return new Promise(async (resolve) => {
|
|
48
|
+
const workId = uuid.v4();
|
|
49
|
+
const worker = await setupWorker(
|
|
50
|
+
ctx,
|
|
51
|
+
async (res) => {
|
|
52
|
+
await waitUntilTrue(
|
|
53
|
+
async () => isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId),
|
|
54
|
+
15e3,
|
|
55
|
+
1e3
|
|
56
|
+
);
|
|
57
|
+
resolve({
|
|
58
|
+
signer: res.signer,
|
|
59
|
+
walletId: res.walletId,
|
|
60
|
+
recoveryShare: null
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
workId
|
|
64
|
+
);
|
|
65
|
+
const email = void 0;
|
|
66
|
+
const params = { pregenIdentifier, pregenIdentifierType, secretKey, partnerId, email, type };
|
|
67
|
+
if (pregenIdentifierType === "EMAIL") {
|
|
68
|
+
params.email = pregenIdentifier;
|
|
69
|
+
}
|
|
70
|
+
worker.postMessage({
|
|
71
|
+
env: ctx.env,
|
|
72
|
+
apiKey: ctx.apiKey,
|
|
73
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
74
|
+
params,
|
|
75
|
+
functionType: "PREKEYGEN",
|
|
76
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
77
|
+
disableWorkers: ctx.disableWorkers,
|
|
78
|
+
sessionCookie,
|
|
79
|
+
useDKLS: ctx.useDKLS,
|
|
80
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
81
|
+
wasmOverride: ctx.wasmOverride,
|
|
82
|
+
workId
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function ed25519Keygen(ctx, userId, sessionCookie, _emailProps = {}) {
|
|
87
|
+
return new Promise(async (resolve) => {
|
|
88
|
+
const workId = uuid.v4();
|
|
89
|
+
const worker = await setupWorker(
|
|
90
|
+
ctx,
|
|
91
|
+
async (res) => {
|
|
92
|
+
await waitUntilTrue(async () => isKeygenComplete(ctx, userId, res.walletId), 15e3, 1e3);
|
|
93
|
+
resolve({
|
|
94
|
+
signer: res.signer,
|
|
95
|
+
walletId: res.walletId,
|
|
96
|
+
recoveryShare: null
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
workId
|
|
100
|
+
);
|
|
101
|
+
worker.postMessage({
|
|
102
|
+
env: ctx.env,
|
|
103
|
+
apiKey: ctx.apiKey,
|
|
104
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
105
|
+
params: { userId },
|
|
106
|
+
functionType: "ED25519_KEYGEN",
|
|
107
|
+
disableWorkers: ctx.disableWorkers,
|
|
108
|
+
sessionCookie,
|
|
109
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
110
|
+
wasmOverride: ctx.wasmOverride,
|
|
111
|
+
workId
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie) {
|
|
116
|
+
return new Promise(async (resolve) => {
|
|
117
|
+
const workId = uuid.v4();
|
|
118
|
+
const worker = await setupWorker(
|
|
119
|
+
ctx,
|
|
120
|
+
async (res) => {
|
|
121
|
+
await waitUntilTrue(
|
|
122
|
+
async () => isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId),
|
|
123
|
+
15e3,
|
|
124
|
+
1e3
|
|
125
|
+
);
|
|
126
|
+
resolve({
|
|
127
|
+
signer: res.signer,
|
|
128
|
+
walletId: res.walletId,
|
|
129
|
+
recoveryShare: null
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
workId
|
|
133
|
+
);
|
|
134
|
+
const email = void 0;
|
|
135
|
+
const params = { pregenIdentifier, pregenIdentifierType, email };
|
|
136
|
+
if (pregenIdentifierType === "EMAIL") {
|
|
137
|
+
params.email = pregenIdentifier;
|
|
138
|
+
}
|
|
139
|
+
worker.postMessage({
|
|
140
|
+
env: ctx.env,
|
|
141
|
+
apiKey: ctx.apiKey,
|
|
142
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
143
|
+
params,
|
|
144
|
+
functionType: "ED25519_PREKEYGEN",
|
|
145
|
+
disableWorkers: ctx.disableWorkers,
|
|
146
|
+
sessionCookie,
|
|
147
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
148
|
+
wasmOverride: ctx.wasmOverride,
|
|
149
|
+
workId
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
export {
|
|
154
|
+
ed25519Keygen,
|
|
155
|
+
ed25519PreKeygen,
|
|
156
|
+
isKeygenComplete,
|
|
157
|
+
isPreKeygenComplete,
|
|
158
|
+
keygen,
|
|
159
|
+
preKeygen
|
|
160
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import "../chunk-FTA5RKYX.js";
|
|
2
|
+
import * as uuid from "uuid";
|
|
3
|
+
import { setupWorker } from "../workers/workerWrapper.js";
|
|
4
|
+
async function getPrivateKey(ctx, userId, walletId, share, sessionCookie) {
|
|
5
|
+
return await new Promise(async (resolve) => {
|
|
6
|
+
const workId = uuid.v4();
|
|
7
|
+
const worker = await setupWorker(
|
|
8
|
+
ctx,
|
|
9
|
+
async (res) => {
|
|
10
|
+
resolve(res.privateKey);
|
|
11
|
+
},
|
|
12
|
+
workId
|
|
13
|
+
);
|
|
14
|
+
worker.postMessage({
|
|
15
|
+
env: ctx.env,
|
|
16
|
+
apiKey: ctx.apiKey,
|
|
17
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
18
|
+
params: { share, walletId, userId },
|
|
19
|
+
functionType: "GET_PRIVATE_KEY",
|
|
20
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
21
|
+
disableWorkers: ctx.disableWorkers,
|
|
22
|
+
sessionCookie,
|
|
23
|
+
useDKLS: ctx.useDKLS,
|
|
24
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
25
|
+
wasmOverride: ctx.wasmOverride,
|
|
26
|
+
workId
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
getPrivateKey
|
|
32
|
+
};
|