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

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 (43) hide show
  1. package/dist/cjs/index.js +523 -3
  2. package/dist/cjs/index.js.br +0 -0
  3. package/dist/cjs/index.js.gz +0 -0
  4. package/dist/cjs/workers/worker.js +904 -18
  5. package/dist/cjs/workers/worker.js.br +0 -0
  6. package/dist/cjs/workers/worker.js.gz +0 -0
  7. package/dist/esm/index.js +468 -4
  8. package/dist/esm/index.js.br +0 -0
  9. package/dist/esm/index.js.gz +0 -0
  10. package/dist/esm/workers/chunk-ILICZWQV.js +36 -0
  11. package/dist/esm/workers/chunk-ILICZWQV.js.br +0 -0
  12. package/dist/esm/workers/chunk-ILICZWQV.js.gz +0 -0
  13. package/dist/esm/{wasm/wasm_exec.js → workers/wasm_exec-CFNSOXDO.js} +74 -68
  14. package/dist/esm/workers/wasm_exec-CFNSOXDO.js.br +0 -0
  15. package/dist/esm/workers/wasm_exec-CFNSOXDO.js.gz +0 -0
  16. package/dist/esm/workers/worker.js +329 -37
  17. package/dist/esm/workers/worker.js.br +0 -0
  18. package/dist/esm/workers/worker.js.gz +0 -0
  19. package/dist/types/ParaServer.d.ts +2 -5
  20. package/dist/types/workers/worker.d.ts +1 -1
  21. package/package.json +4 -4
  22. package/dist/cjs/ParaServer.js +0 -91
  23. package/dist/cjs/ServerLocalStorage.js +0 -48
  24. package/dist/cjs/ServerSessionStorage.js +0 -48
  25. package/dist/cjs/ServerUtils.js +0 -76
  26. package/dist/cjs/package.json +0 -3
  27. package/dist/cjs/wallet/keygen.js +0 -227
  28. package/dist/cjs/wallet/privateKey.js +0 -86
  29. package/dist/cjs/wallet/signing.js +0 -172
  30. package/dist/cjs/wasm/wasm_exec.js +0 -589
  31. package/dist/cjs/workers/walletUtils.js +0 -367
  32. package/dist/cjs/workers/workerWrapper.js +0 -88
  33. package/dist/esm/ParaServer.js +0 -37
  34. package/dist/esm/ServerLocalStorage.js +0 -26
  35. package/dist/esm/ServerSessionStorage.js +0 -26
  36. package/dist/esm/ServerUtils.js +0 -54
  37. package/dist/esm/chunk-FTA5RKYX.js +0 -8
  38. package/dist/esm/package.json +0 -6
  39. package/dist/esm/wallet/keygen.js +0 -160
  40. package/dist/esm/wallet/privateKey.js +0 -32
  41. package/dist/esm/wallet/signing.js +0 -109
  42. package/dist/esm/workers/walletUtils.js +0 -290
  43. package/dist/esm/workers/workerWrapper.js +0 -44
@@ -1,160 +0,0 @@
1
- import "../chunk-FTA5RKYX.js";
2
- import * as uuid from "uuid";
3
- import { waitUntilTrue } from "@getpara/core-sdk";
4
- import { setupWorker } from "../workers/workerWrapper.js";
5
- async function isKeygenComplete(ctx, userId, walletId) {
6
- const wallets = await ctx.client.getWallets(userId);
7
- const wallet = wallets.data.wallets.find((w) => w.id === walletId);
8
- return !!wallet.address;
9
- }
10
- async function isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, walletId) {
11
- const wallets = await ctx.client.getPregenWallets({ [pregenIdentifierType]: [pregenIdentifier] });
12
- const wallet = wallets.wallets.find((w) => w.id === walletId);
13
- return !!wallet?.address;
14
- }
15
- function keygen(ctx, userId, type, secretKey, skipDistribute = false, sessionCookie, _emailProps = {}) {
16
- return new Promise(async (resolve) => {
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
- if (skipDistribute) {
23
- resolve({
24
- signer: res.signer,
25
- walletId: res.walletId,
26
- recoveryShare: null
27
- });
28
- }
29
- },
30
- workId
31
- );
32
- worker.postMessage({
33
- env: ctx.env,
34
- apiKey: ctx.apiKey,
35
- cosmosPrefix: ctx.cosmosPrefix,
36
- params: { userId, secretKey, type },
37
- functionType: "KEYGEN",
38
- offloadMPCComputationURL: ctx.offloadMPCComputationURL,
39
- disableWorkers: ctx.disableWorkers,
40
- sessionCookie,
41
- useDKLS: ctx.useDKLS,
42
- disableWebSockets: ctx.disableWebSockets,
43
- wasmOverride: ctx.wasmOverride,
44
- workId
45
- });
46
- });
47
- }
48
- function preKeygen(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey, _skipDistribute = false, partnerId, sessionCookie) {
49
- return new Promise(async (resolve) => {
50
- const workId = uuid.v4();
51
- const worker = await setupWorker(
52
- ctx,
53
- async (res) => {
54
- await waitUntilTrue(
55
- async () => isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId),
56
- 15e3,
57
- 1e3
58
- );
59
- resolve({
60
- signer: res.signer,
61
- walletId: res.walletId,
62
- recoveryShare: null
63
- });
64
- },
65
- workId
66
- );
67
- const email = void 0;
68
- const params = { pregenIdentifier, pregenIdentifierType, secretKey, partnerId, email, type };
69
- if (pregenIdentifierType === "EMAIL") {
70
- params.email = pregenIdentifier;
71
- }
72
- worker.postMessage({
73
- env: ctx.env,
74
- apiKey: ctx.apiKey,
75
- cosmosPrefix: ctx.cosmosPrefix,
76
- params,
77
- functionType: "PREKEYGEN",
78
- offloadMPCComputationURL: ctx.offloadMPCComputationURL,
79
- disableWorkers: ctx.disableWorkers,
80
- sessionCookie,
81
- useDKLS: ctx.useDKLS,
82
- disableWebSockets: ctx.disableWebSockets,
83
- wasmOverride: ctx.wasmOverride,
84
- workId
85
- });
86
- });
87
- }
88
- function ed25519Keygen(ctx, userId, sessionCookie, _emailProps = {}) {
89
- return new Promise(async (resolve) => {
90
- const workId = uuid.v4();
91
- const worker = await setupWorker(
92
- ctx,
93
- async (res) => {
94
- await waitUntilTrue(async () => isKeygenComplete(ctx, userId, res.walletId), 15e3, 1e3);
95
- resolve({
96
- signer: res.signer,
97
- walletId: res.walletId,
98
- recoveryShare: null
99
- });
100
- },
101
- workId
102
- );
103
- worker.postMessage({
104
- env: ctx.env,
105
- apiKey: ctx.apiKey,
106
- cosmosPrefix: ctx.cosmosPrefix,
107
- params: { userId },
108
- functionType: "ED25519_KEYGEN",
109
- disableWorkers: ctx.disableWorkers,
110
- sessionCookie,
111
- disableWebSockets: ctx.disableWebSockets,
112
- wasmOverride: ctx.wasmOverride,
113
- workId
114
- });
115
- });
116
- }
117
- function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie) {
118
- return new Promise(async (resolve) => {
119
- const workId = uuid.v4();
120
- const worker = await setupWorker(
121
- ctx,
122
- async (res) => {
123
- await waitUntilTrue(
124
- async () => isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId),
125
- 15e3,
126
- 1e3
127
- );
128
- resolve({
129
- signer: res.signer,
130
- walletId: res.walletId,
131
- recoveryShare: null
132
- });
133
- },
134
- workId
135
- );
136
- const email = void 0;
137
- const params = { pregenIdentifier, pregenIdentifierType, email };
138
- if (pregenIdentifierType === "EMAIL") {
139
- params.email = pregenIdentifier;
140
- }
141
- worker.postMessage({
142
- env: ctx.env,
143
- apiKey: ctx.apiKey,
144
- cosmosPrefix: ctx.cosmosPrefix,
145
- params,
146
- functionType: "ED25519_PREKEYGEN",
147
- disableWorkers: ctx.disableWorkers,
148
- sessionCookie,
149
- disableWebSockets: ctx.disableWebSockets,
150
- wasmOverride: ctx.wasmOverride,
151
- workId
152
- });
153
- });
154
- }
155
- export {
156
- ed25519Keygen,
157
- ed25519PreKeygen,
158
- keygen,
159
- preKeygen
160
- };
@@ -1,32 +0,0 @@
1
- import "../chunk-FTA5RKYX.js";
2
- import * as uuid from "uuid";
3
- import { setupWorker } from "../workers/workerWrapper.js";
4
- async function getPrivateKey(ctx, userId, walletId, share, sessionCookie) {
5
- return await new Promise(async (resolve) => {
6
- const workId = uuid.v4();
7
- const worker = await setupWorker(
8
- ctx,
9
- async (res) => {
10
- resolve(res);
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
- });
28
- });
29
- }
30
- export {
31
- getPrivateKey
32
- };
@@ -1,109 +0,0 @@
1
- import "../chunk-FTA5RKYX.js";
2
- import * as uuid from "uuid";
3
- import { setupWorker } from "../workers/workerWrapper.js";
4
- async function signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
5
- return await new Promise(async (resolve) => {
6
- const workId = uuid.v4();
7
- const worker = await setupWorker(
8
- ctx,
9
- async (sendTransactionRes) => {
10
- resolve(sendTransactionRes);
11
- },
12
- workId
13
- );
14
- worker.postMessage({
15
- env: ctx.env,
16
- apiKey: ctx.apiKey,
17
- cosmosPrefix: ctx.cosmosPrefix,
18
- params: { share, walletId, userId, tx, chainId },
19
- functionType: "SIGN_TRANSACTION",
20
- offloadMPCComputationURL: ctx.offloadMPCComputationURL,
21
- disableWorkers: ctx.disableWorkers,
22
- sessionCookie,
23
- useDKLS: isDKLS,
24
- disableWebSockets: ctx.disableWebSockets,
25
- wasmOverride: ctx.wasmOverride,
26
- workId
27
- });
28
- });
29
- }
30
- async function sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
31
- return await new Promise(async (resolve) => {
32
- const workId = uuid.v4();
33
- const worker = await setupWorker(
34
- ctx,
35
- async (sendTransactionRes) => {
36
- resolve(sendTransactionRes);
37
- },
38
- workId
39
- );
40
- worker.postMessage({
41
- env: ctx.env,
42
- apiKey: ctx.apiKey,
43
- params: { share, walletId, userId, tx, chainId },
44
- functionType: "SEND_TRANSACTION",
45
- offloadMPCComputationURL: ctx.offloadMPCComputationURL,
46
- disableWorkers: ctx.disableWorkers,
47
- sessionCookie,
48
- useDKLS: isDKLS,
49
- disableWebSockets: ctx.disableWebSockets,
50
- wasmOverride: ctx.wasmOverride,
51
- workId
52
- });
53
- });
54
- }
55
- async function signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS) {
56
- return await new Promise(async (resolve) => {
57
- const workId = uuid.v4();
58
- const worker = await setupWorker(
59
- ctx,
60
- async (signMessageRes) => {
61
- resolve(signMessageRes);
62
- },
63
- workId
64
- );
65
- worker.postMessage({
66
- env: ctx.env,
67
- apiKey: ctx.apiKey,
68
- params: { share, walletId, userId, message },
69
- functionType: "SIGN_MESSAGE",
70
- offloadMPCComputationURL: ctx.offloadMPCComputationURL,
71
- disableWorkers: ctx.disableWorkers,
72
- sessionCookie,
73
- useDKLS: isDKLS,
74
- disableWebSockets: ctx.disableWebSockets,
75
- wasmOverride: ctx.wasmOverride,
76
- workId
77
- });
78
- });
79
- }
80
- async function ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
81
- return await new Promise(async (resolve) => {
82
- const workId = uuid.v4();
83
- const worker = await setupWorker(
84
- ctx,
85
- async (signMessageRes) => {
86
- resolve(signMessageRes);
87
- },
88
- workId
89
- );
90
- worker.postMessage({
91
- env: ctx.env,
92
- apiKey: ctx.apiKey,
93
- params: { share, walletId, userId, base64Bytes },
94
- functionType: "ED25519_SIGN",
95
- offloadMPCComputationURL: ctx.offloadMPCComputationURL,
96
- disableWorkers: ctx.disableWorkers,
97
- sessionCookie,
98
- disableWebSockets: ctx.disableWebSockets,
99
- wasmOverride: ctx.wasmOverride,
100
- workId
101
- });
102
- });
103
- }
104
- export {
105
- ed25519Sign,
106
- sendTransaction,
107
- signMessage,
108
- signTransaction
109
- };
@@ -1,290 +0,0 @@
1
- import "../chunk-FTA5RKYX.js";
2
- import { getBaseMPCNetworkUrl, WalletScheme, WalletType } from "@getpara/core-sdk";
3
- const configCGGMPBase = (serverUrl, walletId, id) => `{"ServerUrl":"${serverUrl}", "WalletId": "${walletId}", "Id":"${id}", "Ids":["USER","CAPSULE"], "Threshold":1}`;
4
- const configDKLSBase = (walletId, id, disableWebSockets) => `{"walletId": "${walletId}", "id":"${id}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${disableWebSockets}}`;
5
- async function keygenRequest(ctx, userId, walletId, protocolId) {
6
- const { data } = await ctx.mpcComputationClient.post("/wallets", {
7
- userId,
8
- walletId,
9
- protocolId
10
- });
11
- return data;
12
- }
13
- async function signMessageRequest(ctx, userId, walletId, protocolId, message, signer) {
14
- const { data } = await ctx.mpcComputationClient.post(`/wallets/${walletId}/messages/sign`, {
15
- userId,
16
- protocolId,
17
- message,
18
- signer
19
- });
20
- return data;
21
- }
22
- async function sendTransactionRequest(ctx, userId, walletId, protocolId, transaction, signer, chainId) {
23
- const { data } = await ctx.mpcComputationClient.post(`/wallets/${walletId}/transactions/send`, {
24
- userId,
25
- protocolId,
26
- transaction,
27
- signer,
28
- chainId
29
- });
30
- return data;
31
- }
32
- async function ed25519Keygen(ctx, userId) {
33
- const { walletId, protocolId } = await ctx.client.createWallet(userId, {
34
- scheme: WalletScheme.ED25519,
35
- type: WalletType.SOLANA
36
- });
37
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
38
- try {
39
- const newSigner = await new Promise(
40
- (resolve, reject) => global.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
41
- if (err) {
42
- reject(err);
43
- }
44
- resolve(result);
45
- })
46
- );
47
- return { signer: newSigner, walletId };
48
- } catch (e) {
49
- throw new Error(`error creating account of type SOLANA with userId ${userId} and walletId ${walletId}`);
50
- }
51
- }
52
- async function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType) {
53
- const { walletId, protocolId } = await ctx.client.createPregenWallet({
54
- pregenIdentifier,
55
- pregenIdentifierType,
56
- scheme: WalletScheme.ED25519,
57
- type: WalletType.SOLANA
58
- });
59
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
60
- try {
61
- const newSigner = await new Promise(
62
- (resolve, reject) => global.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
63
- if (err) {
64
- reject(err);
65
- }
66
- resolve(result);
67
- })
68
- );
69
- return { signer: newSigner, walletId };
70
- } catch (e) {
71
- throw new Error(`error creating account of type SOLANA with walletId ${walletId}`);
72
- }
73
- }
74
- async function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
75
- const { protocolId } = await ctx.client.preSignMessage(userId, walletId, base64Bytes, WalletScheme.ED25519);
76
- try {
77
- const base64Sig = await new Promise(
78
- (resolve, reject) => global.ed25519Sign(share, protocolId, base64Bytes, (err, result) => {
79
- if (err) {
80
- reject(err);
81
- }
82
- resolve(result);
83
- })
84
- );
85
- return { signature: base64Sig };
86
- } catch (e) {
87
- throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
88
- }
89
- }
90
- async function keygen(ctx, userId, type, secretKey) {
91
- const { walletId, protocolId } = await ctx.client.createWallet(userId, {
92
- useTwoSigners: true,
93
- scheme: ctx.useDKLS ? WalletScheme.DKLS : WalletScheme.CGGMP,
94
- type,
95
- cosmosPrefix: type === WalletType.COSMOS ? ctx.cosmosPrefix : void 0
96
- });
97
- if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
98
- return {
99
- signer: (await keygenRequest(ctx, userId, walletId, protocolId)).signer,
100
- walletId
101
- };
102
- }
103
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
104
- const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
105
- const createAccountFn = ctx.useDKLS ? global.dklsCreateAccount : global.createAccountV2;
106
- try {
107
- const newSigner = await new Promise(
108
- (resolve, reject) => createAccountFn(
109
- signerConfigUser,
110
- serverUrl,
111
- protocolId,
112
- secretKey,
113
- () => {
114
- },
115
- // no-op for deprecated callback to update progress percentage
116
- (err, result) => {
117
- if (err) {
118
- reject(err);
119
- }
120
- resolve(result);
121
- }
122
- )
123
- );
124
- return { signer: newSigner, walletId };
125
- } catch (e) {
126
- throw new Error(`error creating account of type ${type} with userId ${userId} and walletId ${walletId}`);
127
- }
128
- }
129
- async function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey) {
130
- const { walletId, protocolId } = await ctx.client.createPregenWallet({
131
- pregenIdentifier,
132
- pregenIdentifierType,
133
- type,
134
- cosmosPrefix: type === WalletType.COSMOS ? ctx.cosmosPrefix : void 0
135
- });
136
- if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
137
- return {
138
- signer: (await keygenRequest(ctx, partnerId, walletId, protocolId)).signer,
139
- walletId
140
- };
141
- }
142
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
143
- const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
144
- const createAccountFn = ctx.useDKLS ? global.dklsCreateAccount : global.createAccountV2;
145
- try {
146
- const newSigner = await new Promise(
147
- (resolve, reject) => createAccountFn(
148
- signerConfigUser,
149
- serverUrl,
150
- protocolId,
151
- secretKey,
152
- () => {
153
- },
154
- // no-op for deprecated callback to update progress percentage
155
- (err, result) => {
156
- if (err) {
157
- reject(err);
158
- }
159
- resolve(result);
160
- }
161
- )
162
- );
163
- return { signer: newSigner, walletId };
164
- } catch (e) {
165
- throw new Error(`error creating account of type ${type} with walletId ${walletId}`);
166
- }
167
- }
168
- async function signMessage(ctx, share, walletId, userId, message) {
169
- const { protocolId, pendingTransactionId } = await ctx.client.preSignMessage(userId, walletId, message);
170
- if (pendingTransactionId) {
171
- return { pendingTransactionId };
172
- }
173
- if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
174
- return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
175
- }
176
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
177
- const signMessageFn = ctx.useDKLS ? global.dklsSignMessage : global.signMessage;
178
- try {
179
- return new Promise(
180
- (resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
181
- if (err) {
182
- reject(err);
183
- }
184
- resolve({ signature: result });
185
- })
186
- );
187
- } catch (e) {
188
- throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
189
- }
190
- }
191
- async function signTransaction(ctx, share, walletId, userId, tx, chainId) {
192
- const {
193
- data: { protocolId, pendingTransactionId }
194
- } = await ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId });
195
- if (pendingTransactionId) {
196
- return { pendingTransactionId };
197
- }
198
- if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
199
- return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
200
- }
201
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
202
- const signTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
203
- try {
204
- return new Promise(
205
- (resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
206
- if (err) {
207
- reject(err);
208
- }
209
- resolve({ signature: result });
210
- })
211
- );
212
- } catch (e) {
213
- throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
214
- }
215
- }
216
- async function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
217
- const {
218
- data: { protocolId, pendingTransactionId }
219
- } = await ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId });
220
- if (pendingTransactionId) {
221
- return { pendingTransactionId };
222
- }
223
- if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
224
- return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
225
- }
226
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
227
- const sendTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
228
- try {
229
- return new Promise(
230
- (resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
231
- if (err) {
232
- reject(err);
233
- }
234
- resolve({ signature: result });
235
- })
236
- );
237
- } catch (e) {
238
- throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
239
- }
240
- }
241
- async function refresh(ctx, share, walletId, userId) {
242
- const {
243
- data: { protocolId }
244
- } = await ctx.client.refreshKeys(userId, walletId);
245
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
246
- const refreshFn = ctx.useDKLS ? global.dklsRefresh : global.refresh;
247
- try {
248
- return new Promise(
249
- (resolve, reject) => refreshFn(share, serverUrl, protocolId, (err, result) => {
250
- if (err) {
251
- reject(err);
252
- }
253
- resolve(result);
254
- })
255
- );
256
- } catch (e) {
257
- throw new Error(`error refreshing keys for account with userId ${userId} and walletId ${walletId}`);
258
- }
259
- }
260
- async function getPrivateKey(ctx, share, walletId, userId) {
261
- const paraShare = await ctx.client.getParaShare(userId, walletId);
262
- if (!paraShare) {
263
- console.error("unable to retrieve Para share");
264
- return "";
265
- }
266
- try {
267
- return new Promise(
268
- (resolve, reject) => global.getPrivateKey(share, paraShare, (err, result) => {
269
- if (err) {
270
- reject(err);
271
- }
272
- resolve(result);
273
- })
274
- );
275
- } catch (e) {
276
- throw new Error(`error getting private key for account with userId ${userId} and walletId ${walletId}`);
277
- }
278
- }
279
- export {
280
- ed25519Keygen,
281
- ed25519PreKeygen,
282
- ed25519Sign,
283
- getPrivateKey,
284
- keygen,
285
- preKeygen,
286
- refresh,
287
- sendTransaction,
288
- signMessage,
289
- signTransaction
290
- };
@@ -1,44 +0,0 @@
1
- import "../chunk-FTA5RKYX.js";
2
- import { Worker } from "worker_threads";
3
- import { getPortalBaseURL } from "@getpara/core-sdk";
4
- const CLEAR_WORKER_TIMEOUT_MS = 1e3 * 90;
5
- let worker;
6
- const resFunctionMap = {};
7
- function removeWorkId(workId, skipClearTimeout) {
8
- const { timeoutId } = resFunctionMap[workId];
9
- delete resFunctionMap[workId];
10
- if (skipClearTimeout) {
11
- return;
12
- }
13
- clearTimeout(timeoutId);
14
- }
15
- async function setupWorker(ctx, resFunction, workId) {
16
- const timeoutId = setTimeout(() => {
17
- removeWorkId(workId, true);
18
- }, CLEAR_WORKER_TIMEOUT_MS);
19
- resFunctionMap[workId] = {
20
- fn: resFunction,
21
- timeoutId
22
- };
23
- if (!worker || !worker.threadId) {
24
- const workerRes = await fetch(`${getPortalBaseURL(ctx)}/static/js/mpcWorkerServer-bundle.js`);
25
- worker = new Worker(await workerRes.text(), { eval: true });
26
- const onmessage = async (message) => {
27
- const { workId: messageWorkId } = message;
28
- delete message.workId;
29
- await resFunctionMap[messageWorkId].fn(message);
30
- removeWorkId(messageWorkId);
31
- };
32
- worker.on("message", onmessage);
33
- worker.on("error", (err) => {
34
- throw err;
35
- });
36
- worker.on("exit", (code) => {
37
- console.error(`worker stopped with exit code ${code}`);
38
- });
39
- }
40
- return worker;
41
- }
42
- export {
43
- setupWorker
44
- };