@getpara/server-sdk 2.0.0-alpha.7 → 2.0.0-alpha.71
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 +12 -9
- package/dist/cjs/ServerUtils.js +28 -1
- package/dist/cjs/wallet/keygen.js +246 -126
- package/dist/cjs/wallet/privateKey.js +35 -22
- package/dist/cjs/wallet/signing.js +136 -84
- package/dist/cjs/workers/walletUtils.js +104 -62
- package/dist/cjs/workers/worker.js +47 -6
- package/dist/cjs/workers/workerWrapper.js +49 -7
- package/dist/esm/ParaServer.js +9 -12
- package/dist/esm/ServerUtils.js +5 -2
- package/dist/esm/wallet/keygen.js +221 -120
- package/dist/esm/wallet/privateKey.js +35 -22
- package/dist/esm/wallet/signing.js +136 -84
- package/dist/esm/workers/walletUtils.js +91 -67
- package/dist/esm/workers/worker.js +52 -6
- package/dist/esm/workers/workerWrapper.js +48 -7
- package/dist/types/ParaServer.d.ts +4 -1
- package/dist/types/ServerUtils.d.ts +2 -3
- package/dist/types/wallet/keygen.d.ts +1 -0
- package/dist/types/workers/walletUtils.d.ts +1 -3
- package/dist/types/workers/worker.d.ts +8 -0
- package/dist/types/workers/workerWrapper.d.ts +2 -2
- package/package.json +19 -20
package/dist/esm/ParaServer.js
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
import "./chunk-FTA5RKYX.js";
|
|
2
|
-
import ParaCore
|
|
3
|
-
Environment
|
|
4
|
-
} from "@getpara/core-sdk";
|
|
5
|
-
import * as Sentry from "@sentry/node";
|
|
2
|
+
import ParaCore from "@getpara/core-sdk";
|
|
6
3
|
import { ServerUtils } from "./ServerUtils.js";
|
|
7
4
|
class Para extends ParaCore {
|
|
8
|
-
constructor(
|
|
9
|
-
super(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
dsn: "https://2a26842d951255c2721fde5c1dd2b252@o4504568036720640.ingest.us.sentry.io/4508850906791936"
|
|
14
|
-
});
|
|
15
|
-
}
|
|
5
|
+
constructor(envOrApiKey, apiKeyOrOpts, opts) {
|
|
6
|
+
super(envOrApiKey, apiKeyOrOpts, opts);
|
|
7
|
+
}
|
|
8
|
+
async ready() {
|
|
9
|
+
this.isReady = true;
|
|
16
10
|
}
|
|
17
11
|
getPlatformUtils() {
|
|
18
12
|
return new ServerUtils();
|
|
19
13
|
}
|
|
14
|
+
async isPasskeySupported() {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
20
17
|
/**
|
|
21
18
|
* Claims a pregenerated wallet.
|
|
22
19
|
*
|
package/dist/esm/ServerUtils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "./chunk-FTA5RKYX.js";
|
|
2
2
|
import { ServerLocalStorage } from "./ServerLocalStorage.js";
|
|
3
3
|
import { ServerSessionStorage } from "./ServerSessionStorage.js";
|
|
4
|
-
import { keygen, preKeygen, ed25519Keygen, ed25519PreKeygen } from "./wallet/keygen.js";
|
|
4
|
+
import { keygen, preKeygen, ed25519Keygen, ed25519PreKeygen, initializeWorker } from "./wallet/keygen.js";
|
|
5
5
|
import { signMessage, sendTransaction, signTransaction, ed25519Sign } from "./wallet/signing.js";
|
|
6
6
|
import { getPrivateKey } from "./wallet/privateKey.js";
|
|
7
7
|
class ServerUtils {
|
|
@@ -46,9 +46,12 @@ class ServerUtils {
|
|
|
46
46
|
ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
|
|
47
47
|
return ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie);
|
|
48
48
|
}
|
|
49
|
-
openPopup(_popupUrl) {
|
|
49
|
+
async openPopup(_popupUrl) {
|
|
50
50
|
throw new Error("OpenPopup is not implemented in the ServerUtils class.");
|
|
51
51
|
}
|
|
52
|
+
async initializeWorker(ctx) {
|
|
53
|
+
return initializeWorker(ctx);
|
|
54
|
+
}
|
|
52
55
|
}
|
|
53
56
|
export {
|
|
54
57
|
ServerUtils
|
|
@@ -13,146 +13,247 @@ 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) => {
|
|
170
|
+
const workId = uuid.v4();
|
|
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);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
async function initializeWorker(ctx) {
|
|
224
|
+
return new Promise(async (resolve, reject) => {
|
|
117
225
|
const workId = uuid.v4();
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
226
|
+
try {
|
|
227
|
+
const worker = await setupWorker(
|
|
228
|
+
ctx,
|
|
229
|
+
async () => {
|
|
230
|
+
resolve();
|
|
231
|
+
},
|
|
232
|
+
(error) => {
|
|
233
|
+
reject(error);
|
|
234
|
+
},
|
|
235
|
+
workId,
|
|
236
|
+
{
|
|
237
|
+
functionType: "INIT",
|
|
238
|
+
disableWorkers: ctx.disableWorkers,
|
|
239
|
+
disableWebSockets: ctx.disableWebSockets
|
|
240
|
+
}
|
|
241
|
+
);
|
|
242
|
+
worker.postMessage({
|
|
243
|
+
env: ctx.env,
|
|
244
|
+
apiKey: ctx.apiKey,
|
|
245
|
+
functionType: "INIT",
|
|
246
|
+
workId
|
|
247
|
+
});
|
|
248
|
+
} catch (error) {
|
|
249
|
+
reject(error);
|
|
138
250
|
}
|
|
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
251
|
});
|
|
152
252
|
}
|
|
153
253
|
export {
|
|
154
254
|
ed25519Keygen,
|
|
155
255
|
ed25519PreKeygen,
|
|
256
|
+
initializeWorker,
|
|
156
257
|
isKeygenComplete,
|
|
157
258
|
isPreKeygenComplete,
|
|
158
259
|
keygen,
|
|
@@ -2,29 +2,42 @@ import "../chunk-FTA5RKYX.js";
|
|
|
2
2
|
import * as uuid from "uuid";
|
|
3
3
|
import { setupWorker } from "../workers/workerWrapper.js";
|
|
4
4
|
async function getPrivateKey(ctx, userId, walletId, share, sessionCookie) {
|
|
5
|
-
return
|
|
5
|
+
return new Promise(async (resolve, reject) => {
|
|
6
6
|
const workId = uuid.v4();
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
7
|
+
try {
|
|
8
|
+
const worker = await setupWorker(
|
|
9
|
+
ctx,
|
|
10
|
+
async (res) => {
|
|
11
|
+
resolve(res.privateKey);
|
|
12
|
+
},
|
|
13
|
+
(error) => {
|
|
14
|
+
reject(error);
|
|
15
|
+
},
|
|
16
|
+
workId,
|
|
17
|
+
{
|
|
18
|
+
params: { walletId, userId },
|
|
19
|
+
functionType: "GET_PRIVATE_KEY",
|
|
20
|
+
disableWorkers: ctx.disableWorkers,
|
|
21
|
+
disableWebSockets: ctx.disableWebSockets
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
worker.postMessage({
|
|
25
|
+
env: ctx.env,
|
|
26
|
+
apiKey: ctx.apiKey,
|
|
27
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
28
|
+
params: { share, walletId, userId },
|
|
29
|
+
functionType: "GET_PRIVATE_KEY",
|
|
30
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
31
|
+
disableWorkers: ctx.disableWorkers,
|
|
32
|
+
sessionCookie,
|
|
33
|
+
useDKLS: ctx.useDKLS,
|
|
34
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
35
|
+
wasmOverride: ctx.wasmOverride,
|
|
36
|
+
workId
|
|
37
|
+
});
|
|
38
|
+
} catch (error) {
|
|
39
|
+
reject(error);
|
|
40
|
+
}
|
|
28
41
|
});
|
|
29
42
|
}
|
|
30
43
|
export {
|