@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.
@@ -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(env, apiKey, opts) {
9
- super(env, apiKey, opts);
10
- if (env !== Environment.PROD && env !== Environment.DEV) {
11
- Sentry.init({
12
- environment: env.toLowerCase(),
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
  *
@@ -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
- 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
- });
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
- 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;
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
- 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
- });
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
- 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;
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 await new Promise(async (resolve) => {
5
+ return new Promise(async (resolve, reject) => {
6
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
- });
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 {