@getpara/server-sdk 2.0.0-fc.3 → 2.1.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 +2 -9
- package/dist/cjs/ServerUtils.js +28 -1
- package/dist/cjs/wallet/keygen.js +34 -0
- package/dist/cjs/workers/worker.js +5 -1
- package/dist/esm/ParaServer.js +3 -12
- package/dist/esm/ServerUtils.js +5 -2
- package/dist/esm/wallet/keygen.js +31 -0
- package/dist/esm/workers/walletUtils.js +10 -10
- package/dist/esm/workers/worker.js +12 -2
- package/dist/types/ParaServer.d.ts +3 -2
- package/dist/types/ServerUtils.d.ts +2 -1
- package/dist/types/wallet/keygen.d.ts +1 -0
- package/package.json +4 -5
package/dist/cjs/ParaServer.js
CHANGED
|
@@ -51,17 +51,10 @@ __export(ParaServer_exports, {
|
|
|
51
51
|
});
|
|
52
52
|
module.exports = __toCommonJS(ParaServer_exports);
|
|
53
53
|
var import_core_sdk = __toESM(require("@getpara/core-sdk"));
|
|
54
|
-
var Sentry = __toESM(require("@sentry/node"));
|
|
55
54
|
var import_ServerUtils = require("./ServerUtils.js");
|
|
56
55
|
class Para extends import_core_sdk.default {
|
|
57
|
-
constructor(
|
|
58
|
-
super(
|
|
59
|
-
if (env !== import_core_sdk.Environment.PROD && env !== import_core_sdk.Environment.DEV) {
|
|
60
|
-
Sentry.init({
|
|
61
|
-
environment: env.toLowerCase(),
|
|
62
|
-
dsn: "https://2a26842d951255c2721fde5c1dd2b252@o4504568036720640.ingest.us.sentry.io/4508850906791936"
|
|
63
|
-
});
|
|
64
|
-
}
|
|
56
|
+
constructor(envOrApiKey, apiKeyOrOpts, opts) {
|
|
57
|
+
super(envOrApiKey, apiKeyOrOpts, opts);
|
|
65
58
|
}
|
|
66
59
|
ready() {
|
|
67
60
|
return __async(this, null, function* () {
|
package/dist/cjs/ServerUtils.js
CHANGED
|
@@ -15,6 +15,26 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var __async = (__this, __arguments, generator) => {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
var fulfilled = (value) => {
|
|
21
|
+
try {
|
|
22
|
+
step(generator.next(value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var rejected = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.throw(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
+
});
|
|
37
|
+
};
|
|
18
38
|
var ServerUtils_exports = {};
|
|
19
39
|
__export(ServerUtils_exports, {
|
|
20
40
|
ServerUtils: () => ServerUtils
|
|
@@ -68,7 +88,14 @@ class ServerUtils {
|
|
|
68
88
|
return (0, import_signing.ed25519Sign)(ctx, userId, walletId, share, base64Bytes, sessionCookie);
|
|
69
89
|
}
|
|
70
90
|
openPopup(_popupUrl) {
|
|
71
|
-
|
|
91
|
+
return __async(this, null, function* () {
|
|
92
|
+
throw new Error("OpenPopup is not implemented in the ServerUtils class.");
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
initializeWorker(ctx) {
|
|
96
|
+
return __async(this, null, function* () {
|
|
97
|
+
return (0, import_keygen.initializeWorker)(ctx);
|
|
98
|
+
});
|
|
72
99
|
}
|
|
73
100
|
}
|
|
74
101
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -66,6 +66,7 @@ var keygen_exports = {};
|
|
|
66
66
|
__export(keygen_exports, {
|
|
67
67
|
ed25519Keygen: () => ed25519Keygen,
|
|
68
68
|
ed25519PreKeygen: () => ed25519PreKeygen,
|
|
69
|
+
initializeWorker: () => initializeWorker,
|
|
69
70
|
isKeygenComplete: () => isKeygenComplete,
|
|
70
71
|
isPreKeygenComplete: () => isPreKeygenComplete,
|
|
71
72
|
keygen: () => keygen,
|
|
@@ -304,10 +305,43 @@ function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCo
|
|
|
304
305
|
}
|
|
305
306
|
}));
|
|
306
307
|
}
|
|
308
|
+
function initializeWorker(ctx) {
|
|
309
|
+
return __async(this, null, function* () {
|
|
310
|
+
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
311
|
+
const workId = uuid.v4();
|
|
312
|
+
try {
|
|
313
|
+
const worker = yield (0, import_workerWrapper.setupWorker)(
|
|
314
|
+
ctx,
|
|
315
|
+
() => __async(this, null, function* () {
|
|
316
|
+
resolve();
|
|
317
|
+
}),
|
|
318
|
+
(error) => {
|
|
319
|
+
reject(error);
|
|
320
|
+
},
|
|
321
|
+
workId,
|
|
322
|
+
{
|
|
323
|
+
functionType: "INIT",
|
|
324
|
+
disableWorkers: ctx.disableWorkers,
|
|
325
|
+
disableWebSockets: ctx.disableWebSockets
|
|
326
|
+
}
|
|
327
|
+
);
|
|
328
|
+
worker.postMessage({
|
|
329
|
+
env: ctx.env,
|
|
330
|
+
apiKey: ctx.apiKey,
|
|
331
|
+
functionType: "INIT",
|
|
332
|
+
workId
|
|
333
|
+
});
|
|
334
|
+
} catch (error) {
|
|
335
|
+
reject(error);
|
|
336
|
+
}
|
|
337
|
+
}));
|
|
338
|
+
});
|
|
339
|
+
}
|
|
307
340
|
// Annotate the CommonJS export names for ESM import in node:
|
|
308
341
|
0 && (module.exports = {
|
|
309
342
|
ed25519Keygen,
|
|
310
343
|
ed25519PreKeygen,
|
|
344
|
+
initializeWorker,
|
|
311
345
|
isKeygenComplete,
|
|
312
346
|
isPreKeygenComplete,
|
|
313
347
|
keygen,
|
|
@@ -87,6 +87,9 @@ function executeMessage(ctx, message) {
|
|
|
87
87
|
return __async(this, null, function* () {
|
|
88
88
|
const { functionType, params } = message;
|
|
89
89
|
switch (functionType) {
|
|
90
|
+
case "INIT": {
|
|
91
|
+
return {};
|
|
92
|
+
}
|
|
90
93
|
case "KEYGEN": {
|
|
91
94
|
const { userId, secretKey, type = "EVM" } = params;
|
|
92
95
|
return walletUtils.keygen(ctx, userId, type, secretKey);
|
|
@@ -195,13 +198,14 @@ function handleMessage(e) {
|
|
|
195
198
|
if (!wasmLoaded && (!ctx.offloadMPCComputationURL || ctx.useDKLS)) {
|
|
196
199
|
yield loadWasm(ctx);
|
|
197
200
|
if (global.initWasm) {
|
|
201
|
+
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
198
202
|
yield new Promise(
|
|
199
203
|
(resolve, reject) => global.initWasm((err, result2) => {
|
|
200
204
|
if (err) {
|
|
201
205
|
reject(err);
|
|
202
206
|
}
|
|
203
207
|
resolve(result2);
|
|
204
|
-
})
|
|
208
|
+
}, serverUrl)
|
|
205
209
|
);
|
|
206
210
|
}
|
|
207
211
|
wasmLoaded = true;
|
package/dist/esm/ParaServer.js
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
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
|
-
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);
|
|
16
7
|
}
|
|
17
8
|
async ready() {
|
|
18
9
|
this.isReady = true;
|
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
|
|
@@ -220,9 +220,40 @@ function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCo
|
|
|
220
220
|
}
|
|
221
221
|
});
|
|
222
222
|
}
|
|
223
|
+
async function initializeWorker(ctx) {
|
|
224
|
+
return new Promise(async (resolve, reject) => {
|
|
225
|
+
const workId = uuid.v4();
|
|
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);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
223
253
|
export {
|
|
224
254
|
ed25519Keygen,
|
|
225
255
|
ed25519PreKeygen,
|
|
256
|
+
initializeWorker,
|
|
226
257
|
isKeygenComplete,
|
|
227
258
|
isPreKeygenComplete,
|
|
228
259
|
keygen,
|
|
@@ -46,7 +46,7 @@ async function ed25519Keygen(ctx, userId) {
|
|
|
46
46
|
})
|
|
47
47
|
);
|
|
48
48
|
return { signer: newSigner, walletId };
|
|
49
|
-
} catch
|
|
49
|
+
} catch {
|
|
50
50
|
throw new Error(`error creating account of type SOLANA with userId ${userId} and walletId ${walletId}`);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -68,7 +68,7 @@ async function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType) {
|
|
|
68
68
|
})
|
|
69
69
|
);
|
|
70
70
|
return { signer: newSigner, walletId };
|
|
71
|
-
} catch
|
|
71
|
+
} catch {
|
|
72
72
|
throw new Error(`error creating account of type SOLANA with walletId ${walletId}`);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
@@ -86,7 +86,7 @@ async function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
|
|
|
86
86
|
})
|
|
87
87
|
);
|
|
88
88
|
return { signature: base64Sig };
|
|
89
|
-
} catch
|
|
89
|
+
} catch {
|
|
90
90
|
throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
|
|
91
91
|
}
|
|
92
92
|
}();
|
|
@@ -131,7 +131,7 @@ async function keygen(ctx, userId, type, secretKey) {
|
|
|
131
131
|
)
|
|
132
132
|
);
|
|
133
133
|
return { signer: newSigner, walletId };
|
|
134
|
-
} catch
|
|
134
|
+
} catch {
|
|
135
135
|
throw new Error(`error creating account of type ${type} with userId ${userId} and walletId ${walletId}`);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
@@ -170,7 +170,7 @@ async function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType,
|
|
|
170
170
|
)
|
|
171
171
|
);
|
|
172
172
|
return { signer: newSigner, walletId };
|
|
173
|
-
} catch
|
|
173
|
+
} catch {
|
|
174
174
|
throw new Error(`error creating account of type ${type} with walletId ${walletId}`);
|
|
175
175
|
}
|
|
176
176
|
}
|
|
@@ -192,7 +192,7 @@ async function signMessage(ctx, share, walletId, userId, message) {
|
|
|
192
192
|
resolve({ signature: result });
|
|
193
193
|
})
|
|
194
194
|
);
|
|
195
|
-
} catch
|
|
195
|
+
} catch {
|
|
196
196
|
throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
|
|
197
197
|
}
|
|
198
198
|
}();
|
|
@@ -220,7 +220,7 @@ async function signTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
|
220
220
|
resolve({ signature: result });
|
|
221
221
|
})
|
|
222
222
|
);
|
|
223
|
-
} catch
|
|
223
|
+
} catch {
|
|
224
224
|
throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
|
|
225
225
|
}
|
|
226
226
|
}();
|
|
@@ -250,7 +250,7 @@ async function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
|
250
250
|
resolve({ signature: result });
|
|
251
251
|
})
|
|
252
252
|
);
|
|
253
|
-
} catch
|
|
253
|
+
} catch {
|
|
254
254
|
throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
|
|
255
255
|
}
|
|
256
256
|
}();
|
|
@@ -277,7 +277,7 @@ async function refresh(ctx, share, walletId, userId) {
|
|
|
277
277
|
resolve(result);
|
|
278
278
|
})
|
|
279
279
|
);
|
|
280
|
-
} catch
|
|
280
|
+
} catch {
|
|
281
281
|
throw new Error(`error refreshing keys for account with userId ${userId} and walletId ${walletId}`);
|
|
282
282
|
}
|
|
283
283
|
}
|
|
@@ -296,7 +296,7 @@ async function getPrivateKey(ctx, share, walletId, userId) {
|
|
|
296
296
|
resolve(result);
|
|
297
297
|
})
|
|
298
298
|
);
|
|
299
|
-
} catch
|
|
299
|
+
} catch {
|
|
300
300
|
throw new Error(`error getting private key for account with userId ${userId} and walletId ${walletId}`);
|
|
301
301
|
}
|
|
302
302
|
}
|
|
@@ -19,7 +19,13 @@ var __async = (__this, __arguments, generator) => {
|
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
21
|
import axios from "axios";
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
getBaseMPCNetworkUrl,
|
|
24
|
+
getPortalBaseURL,
|
|
25
|
+
initClient,
|
|
26
|
+
mpcComputationClient,
|
|
27
|
+
paraVersion
|
|
28
|
+
} from "@getpara/core-sdk";
|
|
23
29
|
import * as walletUtils from "./walletUtils.js";
|
|
24
30
|
let rawWasm;
|
|
25
31
|
let wasmLoaded = false;
|
|
@@ -53,6 +59,9 @@ function executeMessage(ctx, message) {
|
|
|
53
59
|
return __async(this, null, function* () {
|
|
54
60
|
const { functionType, params } = message;
|
|
55
61
|
switch (functionType) {
|
|
62
|
+
case "INIT": {
|
|
63
|
+
return {};
|
|
64
|
+
}
|
|
56
65
|
case "KEYGEN": {
|
|
57
66
|
const { userId, secretKey, type = "EVM" } = params;
|
|
58
67
|
return walletUtils.keygen(ctx, userId, type, secretKey);
|
|
@@ -161,13 +170,14 @@ function handleMessage(e) {
|
|
|
161
170
|
if (!wasmLoaded && (!ctx.offloadMPCComputationURL || ctx.useDKLS)) {
|
|
162
171
|
yield loadWasm(ctx);
|
|
163
172
|
if (global.initWasm) {
|
|
173
|
+
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
164
174
|
yield new Promise(
|
|
165
175
|
(resolve, reject) => global.initWasm((err, result2) => {
|
|
166
176
|
if (err) {
|
|
167
177
|
reject(err);
|
|
168
178
|
}
|
|
169
179
|
resolve(result2);
|
|
170
|
-
})
|
|
180
|
+
}, serverUrl)
|
|
171
181
|
);
|
|
172
182
|
}
|
|
173
183
|
wasmLoaded = true;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import ParaCore, { PlatformUtils, ConstructorOpts, Environment, CoreMethodParams, CoreMethodResponse } from '@getpara/core-sdk';
|
|
2
2
|
export declare class Para extends ParaCore {
|
|
3
|
-
constructor(env: Environment, apiKey
|
|
4
|
-
|
|
3
|
+
constructor(env: Environment | undefined, apiKey: string, opts?: ConstructorOpts);
|
|
4
|
+
constructor(apiKey: string, opts?: ConstructorOpts);
|
|
5
|
+
ready(): Promise<void>;
|
|
5
6
|
protected getPlatformUtils(): PlatformUtils;
|
|
6
7
|
isPasskeySupported(): Promise<boolean>;
|
|
7
8
|
/**
|
|
@@ -39,5 +39,6 @@ export declare class ServerUtils implements PlatformUtils {
|
|
|
39
39
|
secureStorage: any;
|
|
40
40
|
isSyncStorage: boolean;
|
|
41
41
|
disableProviderModal: boolean;
|
|
42
|
-
openPopup(_popupUrl: string): Window
|
|
42
|
+
openPopup(_popupUrl: string): Promise<Window>;
|
|
43
|
+
initializeWorker(ctx: Ctx): Promise<void>;
|
|
43
44
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/server-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@getpara/core-sdk": "2.
|
|
6
|
-
"@getpara/user-management-client": "2.
|
|
7
|
-
"@sentry/node": "^9.1.0",
|
|
5
|
+
"@getpara/core-sdk": "2.1.0",
|
|
6
|
+
"@getpara/user-management-client": "2.1.0",
|
|
8
7
|
"uuid": "^11.1.0",
|
|
9
8
|
"ws": "^8.14.2"
|
|
10
9
|
},
|
|
@@ -16,7 +15,7 @@
|
|
|
16
15
|
"dist",
|
|
17
16
|
"package.json"
|
|
18
17
|
],
|
|
19
|
-
"gitHead": "
|
|
18
|
+
"gitHead": "3ae7f836324a3a2a8a57156e16304aeaf0d37b42",
|
|
20
19
|
"main": "dist/cjs/index.js",
|
|
21
20
|
"module": "dist/esm/index.js",
|
|
22
21
|
"scripts": {
|