@getpara/server-sdk 2.0.0-dev.0 → 2.0.0-dev.2
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 +101 -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 +315 -0
- package/dist/cjs/wallet/privateKey.js +99 -0
- package/dist/cjs/wallet/signing.js +224 -0
- package/dist/cjs/wasm/wasm_exec.js +589 -0
- package/dist/cjs/workers/walletUtils.js +409 -0
- package/dist/cjs/workers/worker.js +62 -907
- package/dist/cjs/workers/workerWrapper.js +130 -0
- package/dist/esm/ParaServer.js +45 -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 -466
- package/dist/esm/package.json +6 -0
- package/dist/esm/wallet/keygen.js +230 -0
- package/dist/esm/wallet/privateKey.js +45 -0
- package/dist/esm/wallet/signing.js +161 -0
- package/dist/esm/{workers/wasm_exec-CFNSOXDO.js → wasm/wasm_exec.js} +68 -74
- package/dist/esm/workers/walletUtils.js +314 -0
- package/dist/esm/workers/worker.js +78 -337
- package/dist/esm/workers/workerWrapper.js +85 -0
- package/dist/types/ParaServer.d.ts +4 -5
- package/dist/types/ServerUtils.d.ts +5 -6
- package/dist/types/wallet/keygen.d.ts +5 -3
- package/dist/types/workers/walletUtils.d.ts +4 -6
- package/dist/types/workers/worker.d.ts +10 -1
- package/dist/types/workers/workerWrapper.d.ts +2 -2
- package/package.json +20 -20
- 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
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
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
|
+
};
|
|
38
|
+
var workerWrapper_exports = {};
|
|
39
|
+
__export(workerWrapper_exports, {
|
|
40
|
+
resetWorker: () => resetWorker,
|
|
41
|
+
setupWorker: () => setupWorker
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(workerWrapper_exports);
|
|
44
|
+
var import_worker_threads = require("worker_threads");
|
|
45
|
+
var import_core_sdk = require("@getpara/core-sdk");
|
|
46
|
+
const CLEAR_WORKER_TIMEOUT_MS = 1e3 * 90;
|
|
47
|
+
let worker;
|
|
48
|
+
const resFunctionMap = {};
|
|
49
|
+
function removeWorkId(workId, skipClearTimeout) {
|
|
50
|
+
const { timeoutId } = resFunctionMap[workId];
|
|
51
|
+
delete resFunctionMap[workId];
|
|
52
|
+
if (skipClearTimeout) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
clearTimeout(timeoutId);
|
|
56
|
+
}
|
|
57
|
+
function resetWorker() {
|
|
58
|
+
if (worker) {
|
|
59
|
+
worker.terminate();
|
|
60
|
+
worker = void 0;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function setupWorker(ctx, resFunction, errorFunction, workId, errorContext) {
|
|
64
|
+
return __async(this, null, function* () {
|
|
65
|
+
const timeoutId = setTimeout(() => {
|
|
66
|
+
if (resFunctionMap[workId]) {
|
|
67
|
+
const errorMsg = `worker operation timed out after ${CLEAR_WORKER_TIMEOUT_MS}ms for workId ${workId} and opts ${JSON.stringify(resFunctionMap[workId].errorContext)}`;
|
|
68
|
+
resFunctionMap[workId].errorFn(new Error(errorMsg));
|
|
69
|
+
removeWorkId(workId, true);
|
|
70
|
+
}
|
|
71
|
+
}, CLEAR_WORKER_TIMEOUT_MS);
|
|
72
|
+
resFunctionMap[workId] = {
|
|
73
|
+
fn: resFunction,
|
|
74
|
+
errorFn: errorFunction,
|
|
75
|
+
timeoutId,
|
|
76
|
+
errorContext
|
|
77
|
+
};
|
|
78
|
+
if (!worker || !worker.threadId) {
|
|
79
|
+
const isDeno = typeof (globalThis == null ? void 0 : globalThis.Deno) !== "undefined";
|
|
80
|
+
const workerFileName = isDeno ? "mpcWorkerServer-esm.js" : "mpcWorkerServer-bundle.js";
|
|
81
|
+
const workerRes = yield fetch(`${(0, import_core_sdk.getPortalBaseURL)(ctx)}/static/js/${workerFileName}`);
|
|
82
|
+
worker = new import_worker_threads.Worker(yield workerRes.text(), { eval: true });
|
|
83
|
+
const onmessage = (message) => __async(this, null, function* () {
|
|
84
|
+
const { workId: messageWorkId } = message;
|
|
85
|
+
if (!resFunctionMap[messageWorkId]) {
|
|
86
|
+
console.warn(`received message for unknown workId: ${messageWorkId}`);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
delete message.workId;
|
|
90
|
+
try {
|
|
91
|
+
yield resFunctionMap[messageWorkId].fn(message);
|
|
92
|
+
removeWorkId(messageWorkId);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error(`error in worker message handler for workId ${messageWorkId}:`, error);
|
|
95
|
+
if (resFunctionMap[messageWorkId]) {
|
|
96
|
+
resFunctionMap[messageWorkId].errorFn(error);
|
|
97
|
+
removeWorkId(messageWorkId);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
worker.on("message", onmessage);
|
|
102
|
+
worker.on("error", (err) => {
|
|
103
|
+
console.error("worker error:", err);
|
|
104
|
+
Object.keys(resFunctionMap).forEach((id) => {
|
|
105
|
+
if (resFunctionMap[id]) {
|
|
106
|
+
const errorMsg = `worker error with workId ${id} and opts ${JSON.stringify(resFunctionMap[id].errorContext)}: ${err.message}`;
|
|
107
|
+
resFunctionMap[id].errorFn(new Error(errorMsg));
|
|
108
|
+
removeWorkId(id);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
worker.on("exit", (code) => {
|
|
113
|
+
console.error(`worker stopped with exit code ${code}`);
|
|
114
|
+
Object.keys(resFunctionMap).forEach((id) => {
|
|
115
|
+
if (resFunctionMap[id]) {
|
|
116
|
+
resFunctionMap[id].errorFn(new Error(`worker exited unexpectedly with code ${code}`));
|
|
117
|
+
removeWorkId(id);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
worker = void 0;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return worker;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
127
|
+
0 && (module.exports = {
|
|
128
|
+
resetWorker,
|
|
129
|
+
setupWorker
|
|
130
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import "./chunk-FTA5RKYX.js";
|
|
2
|
+
import ParaCore, {
|
|
3
|
+
Environment
|
|
4
|
+
} from "@getpara/core-sdk";
|
|
5
|
+
import * as Sentry from "@sentry/node";
|
|
6
|
+
import { ServerUtils } from "./ServerUtils.js";
|
|
7
|
+
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
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async ready() {
|
|
18
|
+
this.isReady = true;
|
|
19
|
+
}
|
|
20
|
+
getPlatformUtils() {
|
|
21
|
+
return new ServerUtils();
|
|
22
|
+
}
|
|
23
|
+
async isPasskeySupported() {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Claims a pregenerated wallet.
|
|
28
|
+
*
|
|
29
|
+
* NOTE: This function is only available on the client side.
|
|
30
|
+
* When called from the server SDK, it throws an error.
|
|
31
|
+
*
|
|
32
|
+
* @param {Object} opts the options object.
|
|
33
|
+
* @param {string} opts.pregenIdentifier - the identifier of the user claiming the wallet.
|
|
34
|
+
* @param {TPregenIdentifierType} opts.pregenIdentifierType - the type of the identifier.
|
|
35
|
+
* @returns {Promise<string | undefined>} A promise that rejects with an error.
|
|
36
|
+
*/
|
|
37
|
+
async claimPregenWallets(_) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
"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."
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
Para
|
|
45
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import "./chunk-FTA5RKYX.js";
|
|
2
|
+
class ServerLocalStorage {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.localStorage = {};
|
|
5
|
+
this.get = (key) => {
|
|
6
|
+
return this.localStorage[key] || null;
|
|
7
|
+
};
|
|
8
|
+
this.set = (key, value) => {
|
|
9
|
+
this.localStorage[key] = value;
|
|
10
|
+
};
|
|
11
|
+
this.removeItem = (key) => {
|
|
12
|
+
delete this.localStorage[key];
|
|
13
|
+
};
|
|
14
|
+
this.clear = (prefix) => {
|
|
15
|
+
const keys = Object.keys(this.localStorage);
|
|
16
|
+
for (const key of keys) {
|
|
17
|
+
if (key && key.startsWith(prefix)) {
|
|
18
|
+
this.removeItem(key);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
ServerLocalStorage
|
|
26
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import "./chunk-FTA5RKYX.js";
|
|
2
|
+
class ServerSessionStorage {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.sessionStorage = {};
|
|
5
|
+
this.get = (key) => {
|
|
6
|
+
return this.sessionStorage[key] || null;
|
|
7
|
+
};
|
|
8
|
+
this.set = (key, value) => {
|
|
9
|
+
this.sessionStorage[key] = value;
|
|
10
|
+
};
|
|
11
|
+
this.removeItem = (key) => {
|
|
12
|
+
delete this.sessionStorage[key];
|
|
13
|
+
};
|
|
14
|
+
this.clear = (prefix) => {
|
|
15
|
+
const keys = Object.keys(this.sessionStorage);
|
|
16
|
+
for (const key of keys) {
|
|
17
|
+
if (key && key.startsWith(prefix)) {
|
|
18
|
+
this.removeItem(key);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
ServerSessionStorage
|
|
26
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import "./chunk-FTA5RKYX.js";
|
|
2
|
+
import { ServerLocalStorage } from "./ServerLocalStorage.js";
|
|
3
|
+
import { ServerSessionStorage } from "./ServerSessionStorage.js";
|
|
4
|
+
import { keygen, preKeygen, ed25519Keygen, ed25519PreKeygen } from "./wallet/keygen.js";
|
|
5
|
+
import { signMessage, sendTransaction, signTransaction, ed25519Sign } from "./wallet/signing.js";
|
|
6
|
+
import { getPrivateKey } from "./wallet/privateKey.js";
|
|
7
|
+
class ServerUtils {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.sdkType = "SERVER";
|
|
10
|
+
this.localStorage = new ServerLocalStorage();
|
|
11
|
+
this.sessionStorage = new ServerSessionStorage();
|
|
12
|
+
this.secureStorage = void 0;
|
|
13
|
+
this.isSyncStorage = true;
|
|
14
|
+
this.disableProviderModal = true;
|
|
15
|
+
}
|
|
16
|
+
getPrivateKey(ctx, userId, walletId, share, sessionCookie) {
|
|
17
|
+
return getPrivateKey(ctx, userId, walletId, share, sessionCookie);
|
|
18
|
+
}
|
|
19
|
+
keygen(ctx, userId, type, secretKey, sessionCookie, emailProps) {
|
|
20
|
+
return keygen(ctx, userId, type, secretKey, sessionCookie, emailProps);
|
|
21
|
+
}
|
|
22
|
+
refresh(_ctx, _sessionCookie, _userId, _walletId, _share, _oldPartnerId, _newPartnerId) {
|
|
23
|
+
throw new Error("Refresh function is not implemented in the ServerUtils class.");
|
|
24
|
+
}
|
|
25
|
+
preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey, sessionCookie) {
|
|
26
|
+
return preKeygen(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey, false, partnerId, sessionCookie);
|
|
27
|
+
}
|
|
28
|
+
signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS) {
|
|
29
|
+
return signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS);
|
|
30
|
+
}
|
|
31
|
+
signTransaction(ctx, userId, walletId, share, message, chainId, sessionCookie, isDKLS) {
|
|
32
|
+
return signTransaction(ctx, userId, walletId, share, message, chainId, sessionCookie, isDKLS);
|
|
33
|
+
}
|
|
34
|
+
sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
|
|
35
|
+
return sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS);
|
|
36
|
+
}
|
|
37
|
+
signHash(_address, _hash) {
|
|
38
|
+
throw new Error("SignHash is not implemented in the ServerUtils class.");
|
|
39
|
+
}
|
|
40
|
+
ed25519Keygen(ctx, userId, sessionCookie, emailProps) {
|
|
41
|
+
return ed25519Keygen(ctx, userId, sessionCookie, emailProps);
|
|
42
|
+
}
|
|
43
|
+
ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie) {
|
|
44
|
+
return ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie);
|
|
45
|
+
}
|
|
46
|
+
ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
|
|
47
|
+
return ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie);
|
|
48
|
+
}
|
|
49
|
+
openPopup(_popupUrl) {
|
|
50
|
+
throw new Error("OpenPopup is not implemented in the ServerUtils class.");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
ServerUtils
|
|
55
|
+
};
|