@getpara/server-sdk 1.11.0 → 1.13.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 +0 -7
- package/dist/cjs/ServerUtils.js +1 -0
- package/dist/cjs/wallet/keygen.js +214 -128
- package/dist/cjs/wallet/privateKey.js +35 -22
- package/dist/cjs/wallet/signing.js +136 -84
- package/dist/cjs/workers/workerWrapper.js +38 -6
- package/dist/esm/ParaServer.js +1 -8
- package/dist/esm/ServerUtils.js +1 -0
- package/dist/esm/wallet/keygen.js +190 -120
- package/dist/esm/wallet/privateKey.js +35 -22
- package/dist/esm/wallet/signing.js +136 -84
- package/dist/esm/workers/workerWrapper.js +38 -6
- package/dist/types/ServerUtils.d.ts +2 -1
- package/dist/types/workers/workerWrapper.d.ts +1 -1
- package/package.json +5 -6
|
@@ -57,109 +57,161 @@ var uuid = __toESM(require("uuid"));
|
|
|
57
57
|
var import_workerWrapper = require("../workers/workerWrapper.js");
|
|
58
58
|
function signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
|
|
59
59
|
return __async(this, null, function* () {
|
|
60
|
-
return
|
|
60
|
+
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
61
61
|
const workId = uuid.v4();
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
62
|
+
try {
|
|
63
|
+
const worker = yield (0, import_workerWrapper.setupWorker)(
|
|
64
|
+
ctx,
|
|
65
|
+
(sendTransactionRes) => __async(this, null, function* () {
|
|
66
|
+
resolve(sendTransactionRes);
|
|
67
|
+
}),
|
|
68
|
+
(error) => {
|
|
69
|
+
reject(error);
|
|
70
|
+
},
|
|
71
|
+
workId,
|
|
72
|
+
{
|
|
73
|
+
params: { walletId, userId, tx, chainId },
|
|
74
|
+
functionType: "SIGN_TRANSACTION",
|
|
75
|
+
disableWorkers: ctx.disableWorkers,
|
|
76
|
+
disableWebSockets: ctx.disableWebSockets
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
worker.postMessage({
|
|
80
|
+
env: ctx.env,
|
|
81
|
+
apiKey: ctx.apiKey,
|
|
82
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
83
|
+
params: { share, walletId, userId, tx, chainId },
|
|
84
|
+
functionType: "SIGN_TRANSACTION",
|
|
85
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
86
|
+
disableWorkers: ctx.disableWorkers,
|
|
87
|
+
sessionCookie,
|
|
88
|
+
useDKLS: isDKLS,
|
|
89
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
90
|
+
wasmOverride: ctx.wasmOverride,
|
|
91
|
+
workId
|
|
92
|
+
});
|
|
93
|
+
} catch (error) {
|
|
94
|
+
reject(error);
|
|
95
|
+
}
|
|
83
96
|
}));
|
|
84
97
|
});
|
|
85
98
|
}
|
|
86
99
|
function sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
|
|
87
100
|
return __async(this, null, function* () {
|
|
88
|
-
return
|
|
101
|
+
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
89
102
|
const workId = uuid.v4();
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
103
|
+
try {
|
|
104
|
+
const worker = yield (0, import_workerWrapper.setupWorker)(
|
|
105
|
+
ctx,
|
|
106
|
+
(sendTransactionRes) => __async(this, null, function* () {
|
|
107
|
+
resolve(sendTransactionRes);
|
|
108
|
+
}),
|
|
109
|
+
(error) => {
|
|
110
|
+
reject(error);
|
|
111
|
+
},
|
|
112
|
+
workId,
|
|
113
|
+
{
|
|
114
|
+
params: { walletId, userId, tx, chainId },
|
|
115
|
+
functionType: "SEND_TRANSACTION",
|
|
116
|
+
disableWorkers: ctx.disableWorkers,
|
|
117
|
+
disableWebSockets: ctx.disableWebSockets
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
worker.postMessage({
|
|
121
|
+
env: ctx.env,
|
|
122
|
+
apiKey: ctx.apiKey,
|
|
123
|
+
params: { share, walletId, userId, tx, chainId },
|
|
124
|
+
functionType: "SEND_TRANSACTION",
|
|
125
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
126
|
+
disableWorkers: ctx.disableWorkers,
|
|
127
|
+
sessionCookie,
|
|
128
|
+
useDKLS: isDKLS,
|
|
129
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
130
|
+
wasmOverride: ctx.wasmOverride,
|
|
131
|
+
workId
|
|
132
|
+
});
|
|
133
|
+
} catch (error) {
|
|
134
|
+
reject(error);
|
|
135
|
+
}
|
|
110
136
|
}));
|
|
111
137
|
});
|
|
112
138
|
}
|
|
113
139
|
function signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS) {
|
|
114
140
|
return __async(this, null, function* () {
|
|
115
|
-
return
|
|
141
|
+
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
116
142
|
const workId = uuid.v4();
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
143
|
+
try {
|
|
144
|
+
const worker = yield (0, import_workerWrapper.setupWorker)(
|
|
145
|
+
ctx,
|
|
146
|
+
(signMessageRes) => __async(this, null, function* () {
|
|
147
|
+
resolve(signMessageRes);
|
|
148
|
+
}),
|
|
149
|
+
(error) => {
|
|
150
|
+
reject(error);
|
|
151
|
+
},
|
|
152
|
+
workId,
|
|
153
|
+
{
|
|
154
|
+
params: { walletId, userId, message },
|
|
155
|
+
functionType: "SIGN_MESSAGE",
|
|
156
|
+
disableWorkers: ctx.disableWorkers,
|
|
157
|
+
disableWebSockets: ctx.disableWebSockets
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
worker.postMessage({
|
|
161
|
+
env: ctx.env,
|
|
162
|
+
apiKey: ctx.apiKey,
|
|
163
|
+
params: { share, walletId, userId, message },
|
|
164
|
+
functionType: "SIGN_MESSAGE",
|
|
165
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
166
|
+
disableWorkers: ctx.disableWorkers,
|
|
167
|
+
sessionCookie,
|
|
168
|
+
useDKLS: isDKLS,
|
|
169
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
170
|
+
wasmOverride: ctx.wasmOverride,
|
|
171
|
+
workId
|
|
172
|
+
});
|
|
173
|
+
} catch (error) {
|
|
174
|
+
reject(error);
|
|
175
|
+
}
|
|
137
176
|
}));
|
|
138
177
|
});
|
|
139
178
|
}
|
|
140
179
|
function ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
|
|
141
180
|
return __async(this, null, function* () {
|
|
142
|
-
return
|
|
181
|
+
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
143
182
|
const workId = uuid.v4();
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
183
|
+
try {
|
|
184
|
+
const worker = yield (0, import_workerWrapper.setupWorker)(
|
|
185
|
+
ctx,
|
|
186
|
+
(signMessageRes) => __async(this, null, function* () {
|
|
187
|
+
resolve(signMessageRes);
|
|
188
|
+
}),
|
|
189
|
+
(error) => {
|
|
190
|
+
reject(error);
|
|
191
|
+
},
|
|
192
|
+
workId,
|
|
193
|
+
{
|
|
194
|
+
params: { walletId, userId, base64Bytes },
|
|
195
|
+
functionType: "ED25519_SIGN",
|
|
196
|
+
disableWorkers: ctx.disableWorkers,
|
|
197
|
+
disableWebSockets: ctx.disableWebSockets
|
|
198
|
+
}
|
|
199
|
+
);
|
|
200
|
+
worker.postMessage({
|
|
201
|
+
env: ctx.env,
|
|
202
|
+
apiKey: ctx.apiKey,
|
|
203
|
+
params: { share, walletId, userId, base64Bytes },
|
|
204
|
+
functionType: "ED25519_SIGN",
|
|
205
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
206
|
+
disableWorkers: ctx.disableWorkers,
|
|
207
|
+
sessionCookie,
|
|
208
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
209
|
+
wasmOverride: ctx.wasmOverride,
|
|
210
|
+
workId
|
|
211
|
+
});
|
|
212
|
+
} catch (error) {
|
|
213
|
+
reject(error);
|
|
214
|
+
}
|
|
163
215
|
}));
|
|
164
216
|
});
|
|
165
217
|
}
|
|
@@ -53,30 +53,62 @@ function removeWorkId(workId, skipClearTimeout) {
|
|
|
53
53
|
}
|
|
54
54
|
clearTimeout(timeoutId);
|
|
55
55
|
}
|
|
56
|
-
function setupWorker(ctx, resFunction, workId) {
|
|
56
|
+
function setupWorker(ctx, resFunction, errorFunction, workId, errorContext) {
|
|
57
57
|
return __async(this, null, function* () {
|
|
58
58
|
const timeoutId = setTimeout(() => {
|
|
59
|
-
|
|
59
|
+
if (resFunctionMap[workId]) {
|
|
60
|
+
const errorMsg = `worker operation timed out after ${CLEAR_WORKER_TIMEOUT_MS}ms for workId ${workId} and opts ${JSON.stringify(resFunctionMap[workId].errorContext)}`;
|
|
61
|
+
resFunctionMap[workId].errorFn(new Error(errorMsg));
|
|
62
|
+
removeWorkId(workId, true);
|
|
63
|
+
}
|
|
60
64
|
}, CLEAR_WORKER_TIMEOUT_MS);
|
|
61
65
|
resFunctionMap[workId] = {
|
|
62
66
|
fn: resFunction,
|
|
63
|
-
|
|
67
|
+
errorFn: errorFunction,
|
|
68
|
+
timeoutId,
|
|
69
|
+
errorContext
|
|
64
70
|
};
|
|
65
71
|
if (!worker || !worker.threadId) {
|
|
66
72
|
const workerRes = yield fetch(`${(0, import_core_sdk.getPortalBaseURL)(ctx)}/static/js/mpcWorkerServer-bundle.js`);
|
|
67
73
|
worker = new import_worker_threads.Worker(yield workerRes.text(), { eval: true });
|
|
68
74
|
const onmessage = (message) => __async(this, null, function* () {
|
|
69
75
|
const { workId: messageWorkId } = message;
|
|
76
|
+
if (!resFunctionMap[messageWorkId]) {
|
|
77
|
+
console.warn(`received message for unknown workId: ${messageWorkId}`);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
70
80
|
delete message.workId;
|
|
71
|
-
|
|
72
|
-
|
|
81
|
+
try {
|
|
82
|
+
yield resFunctionMap[messageWorkId].fn(message);
|
|
83
|
+
removeWorkId(messageWorkId);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.error(`error in worker message handler for workId ${messageWorkId}:`, error);
|
|
86
|
+
if (resFunctionMap[messageWorkId]) {
|
|
87
|
+
resFunctionMap[messageWorkId].errorFn(error);
|
|
88
|
+
removeWorkId(messageWorkId);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
73
91
|
});
|
|
74
92
|
worker.on("message", onmessage);
|
|
75
93
|
worker.on("error", (err) => {
|
|
76
|
-
|
|
94
|
+
console.error("worker error:", err);
|
|
95
|
+
Object.keys(resFunctionMap).forEach((id) => {
|
|
96
|
+
if (resFunctionMap[id]) {
|
|
97
|
+
const errorMsg = `worker error with workId ${id} and opts ${JSON.stringify(resFunctionMap[id].errorContext)}: ${err.message}`;
|
|
98
|
+
resFunctionMap[id].errorFn(new Error(errorMsg));
|
|
99
|
+
removeWorkId(id);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
77
102
|
});
|
|
78
103
|
worker.on("exit", (code) => {
|
|
79
104
|
console.error(`worker stopped with exit code ${code}`);
|
|
105
|
+
Object.keys(resFunctionMap).forEach((id) => {
|
|
106
|
+
if (resFunctionMap[id]) {
|
|
107
|
+
resFunctionMap[id].errorFn(new Error(`worker exited unexpectedly with code ${code}`));
|
|
108
|
+
removeWorkId(id);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
worker = void 0;
|
|
80
112
|
});
|
|
81
113
|
}
|
|
82
114
|
return worker;
|
package/dist/esm/ParaServer.js
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
import "./chunk-FTA5RKYX.js";
|
|
2
|
-
import ParaCore
|
|
3
|
-
import * as Sentry from "@sentry/node";
|
|
2
|
+
import ParaCore from "@getpara/core-sdk";
|
|
4
3
|
import { ServerUtils } from "./ServerUtils.js";
|
|
5
4
|
class Para extends ParaCore {
|
|
6
5
|
constructor(env, apiKey, opts) {
|
|
7
6
|
super(env, apiKey, opts);
|
|
8
|
-
if (env !== Environment.PROD && env !== Environment.DEV) {
|
|
9
|
-
Sentry.init({
|
|
10
|
-
environment: env.toLowerCase(),
|
|
11
|
-
dsn: "https://2a26842d951255c2721fde5c1dd2b252@o4504568036720640.ingest.us.sentry.io/4508850906791936"
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
7
|
}
|
|
15
8
|
getPlatformUtils() {
|
|
16
9
|
return new ServerUtils();
|
package/dist/esm/ServerUtils.js
CHANGED
|
@@ -6,6 +6,7 @@ import { signMessage, sendTransaction, signTransaction, ed25519Sign } from "./wa
|
|
|
6
6
|
import { getPrivateKey } from "./wallet/privateKey.js";
|
|
7
7
|
class ServerUtils {
|
|
8
8
|
constructor() {
|
|
9
|
+
this.sdkType = "SERVER";
|
|
9
10
|
this.localStorage = new ServerLocalStorage();
|
|
10
11
|
this.sessionStorage = new ServerSessionStorage();
|
|
11
12
|
this.secureStorage = void 0;
|
|
@@ -13,141 +13,211 @@ async function isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType,
|
|
|
13
13
|
return !!wallet?.address;
|
|
14
14
|
}
|
|
15
15
|
function keygen(ctx, userId, type, secretKey, sessionCookie, _emailProps = {}) {
|
|
16
|
-
return new Promise(async (resolve) => {
|
|
16
|
+
return new Promise(async (resolve, reject) => {
|
|
17
17
|
const workId = uuid.v4();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
18
|
+
try {
|
|
19
|
+
const worker = await setupWorker(
|
|
20
|
+
ctx,
|
|
21
|
+
async (res) => {
|
|
22
|
+
try {
|
|
23
|
+
await waitUntilTrue(async () => isKeygenComplete(ctx, userId, res.walletId), 15e3, 1e3);
|
|
24
|
+
resolve({
|
|
25
|
+
signer: res.signer,
|
|
26
|
+
walletId: res.walletId,
|
|
27
|
+
recoveryShare: null
|
|
28
|
+
});
|
|
29
|
+
} catch (error) {
|
|
30
|
+
reject(error);
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
(error) => {
|
|
34
|
+
reject(error);
|
|
35
|
+
},
|
|
36
|
+
workId,
|
|
37
|
+
{
|
|
38
|
+
userId,
|
|
39
|
+
type,
|
|
40
|
+
functionType: "KEYGEN",
|
|
41
|
+
disableWorkers: ctx.disableWorkers,
|
|
42
|
+
disableWebSockets: ctx.disableWebSockets
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
worker.postMessage({
|
|
46
|
+
env: ctx.env,
|
|
47
|
+
apiKey: ctx.apiKey,
|
|
48
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
49
|
+
params: { userId, secretKey, type },
|
|
50
|
+
functionType: "KEYGEN",
|
|
51
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
52
|
+
disableWorkers: ctx.disableWorkers,
|
|
53
|
+
sessionCookie,
|
|
54
|
+
useDKLS: ctx.useDKLS,
|
|
55
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
56
|
+
wasmOverride: ctx.wasmOverride,
|
|
57
|
+
workId
|
|
58
|
+
});
|
|
59
|
+
} catch (error) {
|
|
60
|
+
reject(error);
|
|
61
|
+
}
|
|
44
62
|
});
|
|
45
63
|
}
|
|
46
64
|
function preKeygen(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey, _skipDistribute = false, partnerId, sessionCookie) {
|
|
47
|
-
return new Promise(async (resolve) => {
|
|
65
|
+
return new Promise(async (resolve, reject) => {
|
|
48
66
|
const workId = uuid.v4();
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
try {
|
|
68
|
+
const email = void 0;
|
|
69
|
+
const params = { pregenIdentifier, pregenIdentifierType, secretKey, partnerId, email, type };
|
|
70
|
+
if (pregenIdentifierType === "EMAIL") {
|
|
71
|
+
params.email = pregenIdentifier;
|
|
72
|
+
}
|
|
73
|
+
const worker = await setupWorker(
|
|
74
|
+
ctx,
|
|
75
|
+
async (res) => {
|
|
76
|
+
try {
|
|
77
|
+
await waitUntilTrue(
|
|
78
|
+
async () => isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId),
|
|
79
|
+
15e3,
|
|
80
|
+
1e3
|
|
81
|
+
);
|
|
82
|
+
resolve({
|
|
83
|
+
signer: res.signer,
|
|
84
|
+
walletId: res.walletId,
|
|
85
|
+
recoveryShare: null
|
|
86
|
+
});
|
|
87
|
+
} catch (error) {
|
|
88
|
+
reject(error);
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
(error) => {
|
|
92
|
+
reject(error);
|
|
93
|
+
},
|
|
94
|
+
workId,
|
|
95
|
+
{
|
|
96
|
+
...params,
|
|
97
|
+
secretKey: null,
|
|
98
|
+
functionType: "PREKEYGEN",
|
|
99
|
+
disableWorkers: ctx.disableWorkers,
|
|
100
|
+
disableWebSockets: ctx.disableWebSockets
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
worker.postMessage({
|
|
104
|
+
env: ctx.env,
|
|
105
|
+
apiKey: ctx.apiKey,
|
|
106
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
107
|
+
params,
|
|
108
|
+
functionType: "PREKEYGEN",
|
|
109
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
110
|
+
disableWorkers: ctx.disableWorkers,
|
|
111
|
+
sessionCookie,
|
|
112
|
+
useDKLS: ctx.useDKLS,
|
|
113
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
114
|
+
wasmOverride: ctx.wasmOverride,
|
|
115
|
+
workId
|
|
116
|
+
});
|
|
117
|
+
} catch (error) {
|
|
118
|
+
reject(error);
|
|
69
119
|
}
|
|
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
120
|
});
|
|
85
121
|
}
|
|
86
122
|
function ed25519Keygen(ctx, userId, sessionCookie, _emailProps = {}) {
|
|
87
|
-
return new Promise(async (resolve) => {
|
|
123
|
+
return new Promise(async (resolve, reject) => {
|
|
88
124
|
const workId = uuid.v4();
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
125
|
+
try {
|
|
126
|
+
const worker = await setupWorker(
|
|
127
|
+
ctx,
|
|
128
|
+
async (res) => {
|
|
129
|
+
try {
|
|
130
|
+
await waitUntilTrue(async () => isKeygenComplete(ctx, userId, res.walletId), 15e3, 1e3);
|
|
131
|
+
resolve({
|
|
132
|
+
signer: res.signer,
|
|
133
|
+
walletId: res.walletId,
|
|
134
|
+
recoveryShare: null
|
|
135
|
+
});
|
|
136
|
+
} catch (error) {
|
|
137
|
+
reject(error);
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
(error) => {
|
|
141
|
+
reject(error);
|
|
142
|
+
},
|
|
143
|
+
workId,
|
|
144
|
+
{
|
|
145
|
+
userId,
|
|
146
|
+
functionType: "ED25519_KEYGEN",
|
|
147
|
+
disableWorkers: ctx.disableWorkers,
|
|
148
|
+
disableWebSockets: ctx.disableWebSockets
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
worker.postMessage({
|
|
152
|
+
env: ctx.env,
|
|
153
|
+
apiKey: ctx.apiKey,
|
|
154
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
155
|
+
params: { userId },
|
|
156
|
+
functionType: "ED25519_KEYGEN",
|
|
157
|
+
disableWorkers: ctx.disableWorkers,
|
|
158
|
+
sessionCookie,
|
|
159
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
160
|
+
wasmOverride: ctx.wasmOverride,
|
|
161
|
+
workId
|
|
162
|
+
});
|
|
163
|
+
} catch (error) {
|
|
164
|
+
reject(error);
|
|
165
|
+
}
|
|
113
166
|
});
|
|
114
167
|
}
|
|
115
168
|
function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie) {
|
|
116
|
-
return new Promise(async (resolve) => {
|
|
169
|
+
return new Promise(async (resolve, reject) => {
|
|
117
170
|
const workId = uuid.v4();
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
171
|
+
try {
|
|
172
|
+
const email = void 0;
|
|
173
|
+
const params = { pregenIdentifier, pregenIdentifierType, email };
|
|
174
|
+
if (pregenIdentifierType === "EMAIL") {
|
|
175
|
+
params.email = pregenIdentifier;
|
|
176
|
+
}
|
|
177
|
+
const worker = await setupWorker(
|
|
178
|
+
ctx,
|
|
179
|
+
async (res) => {
|
|
180
|
+
try {
|
|
181
|
+
await waitUntilTrue(
|
|
182
|
+
async () => isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId),
|
|
183
|
+
15e3,
|
|
184
|
+
1e3
|
|
185
|
+
);
|
|
186
|
+
resolve({
|
|
187
|
+
signer: res.signer,
|
|
188
|
+
walletId: res.walletId,
|
|
189
|
+
recoveryShare: null
|
|
190
|
+
});
|
|
191
|
+
} catch (error) {
|
|
192
|
+
reject(error);
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
(error) => {
|
|
196
|
+
reject(error);
|
|
197
|
+
},
|
|
198
|
+
workId,
|
|
199
|
+
{
|
|
200
|
+
params,
|
|
201
|
+
functionType: "ED25519_PREKEYGEN",
|
|
202
|
+
disableWorkers: ctx.disableWorkers,
|
|
203
|
+
disableWebSockets: ctx.disableWebSockets
|
|
204
|
+
}
|
|
205
|
+
);
|
|
206
|
+
worker.postMessage({
|
|
207
|
+
env: ctx.env,
|
|
208
|
+
apiKey: ctx.apiKey,
|
|
209
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
210
|
+
params,
|
|
211
|
+
functionType: "ED25519_PREKEYGEN",
|
|
212
|
+
disableWorkers: ctx.disableWorkers,
|
|
213
|
+
sessionCookie,
|
|
214
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
215
|
+
wasmOverride: ctx.wasmOverride,
|
|
216
|
+
workId
|
|
217
|
+
});
|
|
218
|
+
} catch (error) {
|
|
219
|
+
reject(error);
|
|
138
220
|
}
|
|
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
221
|
});
|
|
152
222
|
}
|
|
153
223
|
export {
|