@getpara/server-sdk 2.0.0-alpha.3 → 2.0.0-alpha.5

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.
Files changed (45) hide show
  1. package/dist/cjs/ParaServer.js +91 -0
  2. package/dist/cjs/ServerLocalStorage.js +48 -0
  3. package/dist/cjs/ServerSessionStorage.js +48 -0
  4. package/dist/cjs/ServerUtils.js +77 -0
  5. package/dist/cjs/index.js +3 -523
  6. package/dist/cjs/package.json +3 -0
  7. package/dist/cjs/wallet/keygen.js +229 -0
  8. package/dist/cjs/wallet/privateKey.js +86 -0
  9. package/dist/cjs/wallet/signing.js +172 -0
  10. package/dist/cjs/wasm/wasm_exec.js +589 -0
  11. package/dist/cjs/workers/walletUtils.js +367 -0
  12. package/dist/cjs/workers/worker.js +24 -906
  13. package/dist/cjs/workers/workerWrapper.js +88 -0
  14. package/dist/esm/ParaServer.js +39 -0
  15. package/dist/esm/ServerLocalStorage.js +26 -0
  16. package/dist/esm/ServerSessionStorage.js +26 -0
  17. package/dist/esm/ServerUtils.js +55 -0
  18. package/dist/esm/chunk-FTA5RKYX.js +8 -0
  19. package/dist/esm/index.js +4 -468
  20. package/dist/esm/package.json +6 -0
  21. package/dist/esm/wallet/keygen.js +160 -0
  22. package/dist/esm/wallet/privateKey.js +32 -0
  23. package/dist/esm/wallet/signing.js +109 -0
  24. package/dist/esm/{workers/wasm_exec-CFNSOXDO.js → wasm/wasm_exec.js} +68 -74
  25. package/dist/esm/workers/walletUtils.js +290 -0
  26. package/dist/esm/workers/worker.js +41 -336
  27. package/dist/esm/workers/workerWrapper.js +44 -0
  28. package/dist/types/ServerUtils.d.ts +5 -4
  29. package/dist/types/wallet/keygen.d.ts +5 -3
  30. package/dist/types/workers/walletUtils.d.ts +3 -3
  31. package/dist/types/workers/worker.d.ts +2 -1
  32. package/package.json +5 -5
  33. package/dist/cjs/index.js.br +0 -0
  34. package/dist/cjs/index.js.gz +0 -0
  35. package/dist/cjs/workers/worker.js.br +0 -0
  36. package/dist/cjs/workers/worker.js.gz +0 -0
  37. package/dist/esm/index.js.br +0 -0
  38. package/dist/esm/index.js.gz +0 -0
  39. package/dist/esm/workers/chunk-ILICZWQV.js +0 -36
  40. package/dist/esm/workers/chunk-ILICZWQV.js.br +0 -0
  41. package/dist/esm/workers/chunk-ILICZWQV.js.gz +0 -0
  42. package/dist/esm/workers/wasm_exec-CFNSOXDO.js.br +0 -0
  43. package/dist/esm/workers/wasm_exec-CFNSOXDO.js.gz +0 -0
  44. package/dist/esm/workers/worker.js.br +0 -0
  45. package/dist/esm/workers/worker.js.gz +0 -0
@@ -0,0 +1,88 @@
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
+ setupWorker: () => setupWorker
41
+ });
42
+ module.exports = __toCommonJS(workerWrapper_exports);
43
+ var import_worker_threads = require("worker_threads");
44
+ var import_core_sdk = require("@getpara/core-sdk");
45
+ const CLEAR_WORKER_TIMEOUT_MS = 1e3 * 90;
46
+ let worker;
47
+ const resFunctionMap = {};
48
+ function removeWorkId(workId, skipClearTimeout) {
49
+ const { timeoutId } = resFunctionMap[workId];
50
+ delete resFunctionMap[workId];
51
+ if (skipClearTimeout) {
52
+ return;
53
+ }
54
+ clearTimeout(timeoutId);
55
+ }
56
+ function setupWorker(ctx, resFunction, workId) {
57
+ return __async(this, null, function* () {
58
+ const timeoutId = setTimeout(() => {
59
+ removeWorkId(workId, true);
60
+ }, CLEAR_WORKER_TIMEOUT_MS);
61
+ resFunctionMap[workId] = {
62
+ fn: resFunction,
63
+ timeoutId
64
+ };
65
+ if (!worker || !worker.threadId) {
66
+ const workerRes = yield fetch(`${(0, import_core_sdk.getPortalBaseURL)(ctx)}/static/js/mpcWorkerServer-bundle.js`);
67
+ worker = new import_worker_threads.Worker(yield workerRes.text(), { eval: true });
68
+ const onmessage = (message) => __async(this, null, function* () {
69
+ const { workId: messageWorkId } = message;
70
+ delete message.workId;
71
+ yield resFunctionMap[messageWorkId].fn(message);
72
+ removeWorkId(messageWorkId);
73
+ });
74
+ worker.on("message", onmessage);
75
+ worker.on("error", (err) => {
76
+ throw err;
77
+ });
78
+ worker.on("exit", (code) => {
79
+ console.error(`worker stopped with exit code ${code}`);
80
+ });
81
+ }
82
+ return worker;
83
+ });
84
+ }
85
+ // Annotate the CommonJS export names for ESM import in node:
86
+ 0 && (module.exports = {
87
+ setupWorker
88
+ });
@@ -0,0 +1,39 @@
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
+ getPlatformUtils() {
18
+ return new ServerUtils();
19
+ }
20
+ /**
21
+ * Claims a pregenerated wallet.
22
+ *
23
+ * NOTE: This function is only available on the client side.
24
+ * When called from the server SDK, it throws an error.
25
+ *
26
+ * @param {Object} opts the options object.
27
+ * @param {string} opts.pregenIdentifier - the identifier of the user claiming the wallet.
28
+ * @param {TPregenIdentifierType} opts.pregenIdentifierType - the type of the identifier.
29
+ * @returns {Promise<string | undefined>} A promise that rejects with an error.
30
+ */
31
+ async claimPregenWallets(_) {
32
+ throw new Error(
33
+ "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."
34
+ );
35
+ }
36
+ }
37
+ export {
38
+ Para
39
+ };
@@ -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
+ };
@@ -0,0 +1,8 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __commonJS = (cb, mod) => function __require() {
3
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
+ };
5
+
6
+ export {
7
+ __commonJS
8
+ };