@getpara/server-sdk 2.0.0-alpha.3 → 2.0.0-alpha.6
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 +91 -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 +229 -0
- package/dist/cjs/wallet/privateKey.js +86 -0
- package/dist/cjs/wallet/signing.js +172 -0
- package/dist/cjs/wasm/wasm_exec.js +589 -0
- package/dist/cjs/workers/walletUtils.js +367 -0
- package/dist/cjs/workers/worker.js +24 -906
- package/dist/cjs/workers/workerWrapper.js +88 -0
- package/dist/esm/ParaServer.js +39 -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 -468
- package/dist/esm/package.json +6 -0
- package/dist/esm/wallet/keygen.js +160 -0
- package/dist/esm/wallet/privateKey.js +32 -0
- package/dist/esm/wallet/signing.js +109 -0
- package/dist/esm/{workers/wasm_exec-CFNSOXDO.js → wasm/wasm_exec.js} +68 -74
- package/dist/esm/workers/walletUtils.js +290 -0
- package/dist/esm/workers/worker.js +41 -336
- package/dist/esm/workers/workerWrapper.js +44 -0
- package/dist/types/ServerUtils.d.ts +5 -4
- package/dist/types/wallet/keygen.d.ts +5 -3
- package/dist/types/workers/walletUtils.d.ts +3 -3
- package/dist/types/workers/worker.d.ts +2 -1
- package/package.json +5 -5
- 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
|
@@ -1,325 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var configDKLSBase = (walletId, id, disableWebSockets) => `{"walletId": "${walletId}", "id":"${id}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${disableWebSockets}}`;
|
|
20
|
-
function keygenRequest(ctx, userId, walletId, protocolId) {
|
|
21
|
-
return __async(this, null, function* () {
|
|
22
|
-
const { data } = yield ctx.mpcComputationClient.post("/wallets", {
|
|
23
|
-
userId,
|
|
24
|
-
walletId,
|
|
25
|
-
protocolId
|
|
26
|
-
});
|
|
27
|
-
return data;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
function signMessageRequest(ctx, userId, walletId, protocolId, message, signer) {
|
|
31
|
-
return __async(this, null, function* () {
|
|
32
|
-
const { data } = yield ctx.mpcComputationClient.post(`/wallets/${walletId}/messages/sign`, {
|
|
33
|
-
userId,
|
|
34
|
-
protocolId,
|
|
35
|
-
message,
|
|
36
|
-
signer
|
|
37
|
-
});
|
|
38
|
-
return data;
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
function sendTransactionRequest(ctx, userId, walletId, protocolId, transaction, signer, chainId) {
|
|
42
|
-
return __async(this, null, function* () {
|
|
43
|
-
const { data } = yield ctx.mpcComputationClient.post(`/wallets/${walletId}/transactions/send`, {
|
|
44
|
-
userId,
|
|
45
|
-
protocolId,
|
|
46
|
-
transaction,
|
|
47
|
-
signer,
|
|
48
|
-
chainId
|
|
49
|
-
});
|
|
50
|
-
return data;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
function ed25519Keygen(ctx, userId) {
|
|
54
|
-
return __async(this, null, function* () {
|
|
55
|
-
const { walletId, protocolId } = yield ctx.client.createWallet(userId, {
|
|
56
|
-
scheme: WalletScheme.ED25519,
|
|
57
|
-
type: WalletType.SOLANA
|
|
58
|
-
});
|
|
59
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
60
|
-
try {
|
|
61
|
-
const newSigner = yield 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 userId ${userId} and walletId ${walletId}`);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType) {
|
|
76
|
-
return __async(this, null, function* () {
|
|
77
|
-
const { walletId, protocolId } = yield ctx.client.createPregenWallet({
|
|
78
|
-
pregenIdentifier,
|
|
79
|
-
pregenIdentifierType,
|
|
80
|
-
scheme: WalletScheme.ED25519,
|
|
81
|
-
type: WalletType.SOLANA
|
|
82
|
-
});
|
|
83
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
84
|
-
try {
|
|
85
|
-
const newSigner = yield new Promise(
|
|
86
|
-
(resolve, reject) => global.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
|
|
87
|
-
if (err) {
|
|
88
|
-
reject(err);
|
|
89
|
-
}
|
|
90
|
-
resolve(result);
|
|
91
|
-
})
|
|
92
|
-
);
|
|
93
|
-
return { signer: newSigner, walletId };
|
|
94
|
-
} catch (e) {
|
|
95
|
-
throw new Error(`error creating account of type SOLANA with walletId ${walletId}`);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
|
|
100
|
-
return __async(this, null, function* () {
|
|
101
|
-
const { protocolId } = yield ctx.client.preSignMessage(userId, walletId, base64Bytes, WalletScheme.ED25519);
|
|
102
|
-
try {
|
|
103
|
-
const base64Sig = yield new Promise(
|
|
104
|
-
(resolve, reject) => global.ed25519Sign(share, protocolId, base64Bytes, (err, result) => {
|
|
105
|
-
if (err) {
|
|
106
|
-
reject(err);
|
|
107
|
-
}
|
|
108
|
-
resolve(result);
|
|
109
|
-
})
|
|
110
|
-
);
|
|
111
|
-
return { signature: base64Sig };
|
|
112
|
-
} catch (e) {
|
|
113
|
-
throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
function keygen(ctx, userId, type, secretKey) {
|
|
118
|
-
return __async(this, null, function* () {
|
|
119
|
-
const { walletId, protocolId } = yield ctx.client.createWallet(userId, {
|
|
120
|
-
useTwoSigners: true,
|
|
121
|
-
scheme: ctx.useDKLS ? WalletScheme.DKLS : WalletScheme.CGGMP,
|
|
122
|
-
type,
|
|
123
|
-
cosmosPrefix: type === WalletType.COSMOS ? ctx.cosmosPrefix : void 0
|
|
124
|
-
});
|
|
125
|
-
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
126
|
-
return {
|
|
127
|
-
signer: (yield keygenRequest(ctx, userId, walletId, protocolId)).signer,
|
|
128
|
-
walletId
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
132
|
-
const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
|
|
133
|
-
const createAccountFn = ctx.useDKLS ? global.dklsCreateAccount : global.createAccountV2;
|
|
134
|
-
try {
|
|
135
|
-
const newSigner = yield new Promise(
|
|
136
|
-
(resolve, reject) => createAccountFn(
|
|
137
|
-
signerConfigUser,
|
|
138
|
-
serverUrl,
|
|
139
|
-
protocolId,
|
|
140
|
-
secretKey,
|
|
141
|
-
() => {
|
|
142
|
-
},
|
|
143
|
-
// no-op for deprecated callback to update progress percentage
|
|
144
|
-
(err, result) => {
|
|
145
|
-
if (err) {
|
|
146
|
-
reject(err);
|
|
147
|
-
}
|
|
148
|
-
resolve(result);
|
|
149
|
-
}
|
|
150
|
-
)
|
|
151
|
-
);
|
|
152
|
-
return { signer: newSigner, walletId };
|
|
153
|
-
} catch (e) {
|
|
154
|
-
throw new Error(`error creating account of type ${type} with userId ${userId} and walletId ${walletId}`);
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey) {
|
|
159
|
-
return __async(this, null, function* () {
|
|
160
|
-
const { walletId, protocolId } = yield ctx.client.createPregenWallet({
|
|
161
|
-
pregenIdentifier,
|
|
162
|
-
pregenIdentifierType,
|
|
163
|
-
type,
|
|
164
|
-
cosmosPrefix: type === WalletType.COSMOS ? ctx.cosmosPrefix : void 0
|
|
165
|
-
});
|
|
166
|
-
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
167
|
-
return {
|
|
168
|
-
signer: (yield keygenRequest(ctx, partnerId, walletId, protocolId)).signer,
|
|
169
|
-
walletId
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
173
|
-
const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
|
|
174
|
-
const createAccountFn = ctx.useDKLS ? global.dklsCreateAccount : global.createAccountV2;
|
|
175
|
-
try {
|
|
176
|
-
const newSigner = yield new Promise(
|
|
177
|
-
(resolve, reject) => createAccountFn(
|
|
178
|
-
signerConfigUser,
|
|
179
|
-
serverUrl,
|
|
180
|
-
protocolId,
|
|
181
|
-
secretKey,
|
|
182
|
-
() => {
|
|
183
|
-
},
|
|
184
|
-
// no-op for deprecated callback to update progress percentage
|
|
185
|
-
(err, result) => {
|
|
186
|
-
if (err) {
|
|
187
|
-
reject(err);
|
|
188
|
-
}
|
|
189
|
-
resolve(result);
|
|
190
|
-
}
|
|
191
|
-
)
|
|
192
|
-
);
|
|
193
|
-
return { signer: newSigner, walletId };
|
|
194
|
-
} catch (e) {
|
|
195
|
-
throw new Error(`error creating account of type ${type} with walletId ${walletId}`);
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
function signMessage(ctx, share, walletId, userId, message) {
|
|
200
|
-
return __async(this, null, function* () {
|
|
201
|
-
const { protocolId, pendingTransactionId } = yield ctx.client.preSignMessage(userId, walletId, message);
|
|
202
|
-
if (pendingTransactionId) {
|
|
203
|
-
return { pendingTransactionId };
|
|
204
|
-
}
|
|
205
|
-
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
206
|
-
return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
|
|
207
|
-
}
|
|
208
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
209
|
-
const signMessageFn = ctx.useDKLS ? global.dklsSignMessage : global.signMessage;
|
|
210
|
-
try {
|
|
211
|
-
return new Promise(
|
|
212
|
-
(resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
|
|
213
|
-
if (err) {
|
|
214
|
-
reject(err);
|
|
215
|
-
}
|
|
216
|
-
resolve({ signature: result });
|
|
217
|
-
})
|
|
218
|
-
);
|
|
219
|
-
} catch (e) {
|
|
220
|
-
throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
function signTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
225
|
-
return __async(this, null, function* () {
|
|
226
|
-
const {
|
|
227
|
-
data: { protocolId, pendingTransactionId }
|
|
228
|
-
} = yield ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId });
|
|
229
|
-
if (pendingTransactionId) {
|
|
230
|
-
return { pendingTransactionId };
|
|
231
|
-
}
|
|
232
|
-
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
233
|
-
return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
|
|
234
|
-
}
|
|
235
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
236
|
-
const signTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
|
|
237
|
-
try {
|
|
238
|
-
return new Promise(
|
|
239
|
-
(resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
240
|
-
if (err) {
|
|
241
|
-
reject(err);
|
|
242
|
-
}
|
|
243
|
-
resolve({ signature: result });
|
|
244
|
-
})
|
|
245
|
-
);
|
|
246
|
-
} catch (e) {
|
|
247
|
-
throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
252
|
-
return __async(this, null, function* () {
|
|
253
|
-
const {
|
|
254
|
-
data: { protocolId, pendingTransactionId }
|
|
255
|
-
} = yield ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId });
|
|
256
|
-
if (pendingTransactionId) {
|
|
257
|
-
return { pendingTransactionId };
|
|
258
|
-
}
|
|
259
|
-
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
260
|
-
return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
|
|
261
|
-
}
|
|
262
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
263
|
-
const sendTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
|
|
264
|
-
try {
|
|
265
|
-
return new Promise(
|
|
266
|
-
(resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
267
|
-
if (err) {
|
|
268
|
-
reject(err);
|
|
269
|
-
}
|
|
270
|
-
resolve({ signature: result });
|
|
271
|
-
})
|
|
272
|
-
);
|
|
273
|
-
} catch (e) {
|
|
274
|
-
throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
function refresh(ctx, share, walletId, userId) {
|
|
279
|
-
return __async(this, null, function* () {
|
|
280
|
-
const {
|
|
281
|
-
data: { protocolId }
|
|
282
|
-
} = yield ctx.client.refreshKeys(userId, walletId);
|
|
283
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
284
|
-
const refreshFn = ctx.useDKLS ? global.dklsRefresh : global.refresh;
|
|
285
|
-
try {
|
|
286
|
-
return new Promise(
|
|
287
|
-
(resolve, reject) => refreshFn(share, serverUrl, protocolId, (err, result) => {
|
|
288
|
-
if (err) {
|
|
289
|
-
reject(err);
|
|
290
|
-
}
|
|
291
|
-
resolve(result);
|
|
292
|
-
})
|
|
293
|
-
);
|
|
294
|
-
} catch (e) {
|
|
295
|
-
throw new Error(`error refreshing keys for account with userId ${userId} and walletId ${walletId}`);
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
function getPrivateKey(ctx, share, walletId, userId) {
|
|
300
|
-
return __async(this, null, function* () {
|
|
301
|
-
const paraShare = yield ctx.client.getParaShare(userId, walletId);
|
|
302
|
-
if (!paraShare) {
|
|
303
|
-
console.error("unable to retrieve Para share");
|
|
304
|
-
return "";
|
|
305
|
-
}
|
|
306
|
-
try {
|
|
307
|
-
return new Promise(
|
|
308
|
-
(resolve, reject) => global.getPrivateKey(share, paraShare, (err, result) => {
|
|
309
|
-
if (err) {
|
|
310
|
-
reject(err);
|
|
311
|
-
}
|
|
312
|
-
resolve(result);
|
|
313
|
-
})
|
|
314
|
-
);
|
|
315
|
-
} catch (e) {
|
|
316
|
-
throw new Error(`error getting private key for account with userId ${userId} and walletId ${walletId}`);
|
|
317
|
-
}
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
318
19
|
});
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
20
|
+
};
|
|
21
|
+
import axios from "axios";
|
|
22
|
+
import { getPortalBaseURL, initClient, mpcComputationClient, paraVersion } from "@getpara/core-sdk";
|
|
23
|
+
import * as walletUtils from "./walletUtils.js";
|
|
24
|
+
let rawWasm;
|
|
323
25
|
function requestWasmWithRetries(ctx, retries = 3) {
|
|
324
26
|
return __async(this, null, function* () {
|
|
325
27
|
for (let i = 0; i < retries; i++) {
|
|
@@ -335,8 +37,8 @@ function requestWasmWithRetries(ctx, retries = 3) {
|
|
|
335
37
|
}
|
|
336
38
|
function loadWasm(ctx) {
|
|
337
39
|
return __async(this, null, function* () {
|
|
338
|
-
yield import("
|
|
339
|
-
global.WebSocket =
|
|
40
|
+
yield import("../wasm/wasm_exec.js");
|
|
41
|
+
global.WebSocket = require("ws");
|
|
340
42
|
const goWasm = new global.Go();
|
|
341
43
|
if (!rawWasm) {
|
|
342
44
|
rawWasm = (yield requestWasmWithRetries(ctx)).data;
|
|
@@ -351,46 +53,48 @@ function executeMessage(ctx, message) {
|
|
|
351
53
|
const { functionType, params } = message;
|
|
352
54
|
switch (functionType) {
|
|
353
55
|
case "KEYGEN": {
|
|
354
|
-
const { userId, secretKey, type =
|
|
355
|
-
return keygen(ctx, userId, type, secretKey);
|
|
56
|
+
const { userId, secretKey, type = "EVM" } = params;
|
|
57
|
+
return walletUtils.keygen(ctx, userId, type, secretKey);
|
|
356
58
|
}
|
|
357
59
|
case "SIGN_TRANSACTION": {
|
|
358
60
|
const { share, walletId, userId, tx, chainId } = params;
|
|
359
|
-
return signTransaction(ctx, share, walletId, userId, tx, chainId);
|
|
61
|
+
return walletUtils.signTransaction(ctx, share, walletId, userId, tx, chainId);
|
|
360
62
|
}
|
|
361
63
|
case "SEND_TRANSACTION": {
|
|
362
64
|
const { share, walletId, userId, tx, chainId } = params;
|
|
363
|
-
return sendTransaction(ctx, share, walletId, userId, tx, chainId);
|
|
65
|
+
return walletUtils.sendTransaction(ctx, share, walletId, userId, tx, chainId);
|
|
364
66
|
}
|
|
365
67
|
case "SIGN_MESSAGE": {
|
|
366
68
|
const { share, walletId, userId, message: message2 } = params;
|
|
367
|
-
return signMessage(ctx, share, walletId, userId, message2);
|
|
69
|
+
return walletUtils.signMessage(ctx, share, walletId, userId, message2);
|
|
368
70
|
}
|
|
369
71
|
case "REFRESH": {
|
|
370
72
|
const { share, walletId, userId } = params;
|
|
371
|
-
|
|
73
|
+
const signer = yield walletUtils.refresh(ctx, share, walletId, userId);
|
|
74
|
+
return { signer };
|
|
372
75
|
}
|
|
373
76
|
case "PREKEYGEN": {
|
|
374
|
-
const { email, partnerId, secretKey, type =
|
|
77
|
+
const { email, partnerId, secretKey, type = "EVM" } = params;
|
|
375
78
|
let { pregenIdentifier, pregenIdentifierType } = params;
|
|
376
79
|
if (email !== "null" && email !== "undefined" && email !== "" && email != null) {
|
|
377
80
|
pregenIdentifier = email;
|
|
378
81
|
pregenIdentifierType = "EMAIL";
|
|
379
82
|
}
|
|
380
|
-
const keygenRes = yield preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey);
|
|
83
|
+
const keygenRes = yield walletUtils.preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey);
|
|
381
84
|
return keygenRes;
|
|
382
85
|
}
|
|
383
86
|
case "GET_PRIVATE_KEY": {
|
|
384
87
|
const { share, walletId, userId } = params;
|
|
385
|
-
|
|
88
|
+
const privateKey = yield walletUtils.getPrivateKey(ctx, share, walletId, userId);
|
|
89
|
+
return { privateKey };
|
|
386
90
|
}
|
|
387
91
|
case "ED25519_KEYGEN": {
|
|
388
92
|
const { userId } = params;
|
|
389
|
-
return ed25519Keygen(ctx, userId);
|
|
93
|
+
return walletUtils.ed25519Keygen(ctx, userId);
|
|
390
94
|
}
|
|
391
95
|
case "ED25519_SIGN": {
|
|
392
96
|
const { share, walletId, userId, base64Bytes } = params;
|
|
393
|
-
return ed25519Sign(ctx, share, userId, walletId, base64Bytes);
|
|
97
|
+
return walletUtils.ed25519Sign(ctx, share, userId, walletId, base64Bytes);
|
|
394
98
|
}
|
|
395
99
|
case "ED25519_PREKEYGEN": {
|
|
396
100
|
const { email } = params;
|
|
@@ -399,7 +103,7 @@ function executeMessage(ctx, message) {
|
|
|
399
103
|
pregenIdentifier = email;
|
|
400
104
|
pregenIdentifierType = "EMAIL";
|
|
401
105
|
}
|
|
402
|
-
return ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType);
|
|
106
|
+
return walletUtils.ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType);
|
|
403
107
|
}
|
|
404
108
|
default: {
|
|
405
109
|
throw new Error(`functionType: ${functionType} not supported`);
|
|
@@ -439,5 +143,6 @@ function handleMessage(e) {
|
|
|
439
143
|
});
|
|
440
144
|
}
|
|
441
145
|
export {
|
|
442
|
-
handleMessage
|
|
146
|
+
handleMessage,
|
|
147
|
+
requestWasmWithRetries
|
|
443
148
|
};
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
};
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import type { Ctx, SignatureRes, PlatformUtils, TPregenIdentifierType,
|
|
4
|
-
import { BackupKitEmailProps } from '@getpara/user-management-client';
|
|
3
|
+
import type { Ctx, SignatureRes, PlatformUtils, TPregenIdentifierType, TWalletType } from '@getpara/core-sdk';
|
|
4
|
+
import { BackupKitEmailProps, SDKType } from '@getpara/user-management-client';
|
|
5
5
|
import { ServerLocalStorage } from './ServerLocalStorage.js';
|
|
6
6
|
import { ServerSessionStorage } from './ServerSessionStorage.js';
|
|
7
7
|
export declare class ServerUtils implements PlatformUtils {
|
|
8
|
+
sdkType: SDKType;
|
|
8
9
|
getPrivateKey(ctx: Ctx, userId: string, walletId: string, share: string, sessionCookie: string): Promise<string>;
|
|
9
|
-
keygen(ctx: Ctx, userId: string, type: Exclude<
|
|
10
|
+
keygen(ctx: Ctx, userId: string, type: Exclude<TWalletType, 'SOLANA'>, secretKey: string | null, sessionCookie: string, emailProps?: BackupKitEmailProps): Promise<{
|
|
10
11
|
signer: string;
|
|
11
12
|
walletId: string;
|
|
12
13
|
}>;
|
|
13
14
|
refresh(_ctx: Ctx, _sessionCookie: string, _userId: string, _walletId: string, _share: string, _oldPartnerId?: string, _newPartnerId?: string): Promise<{
|
|
14
15
|
signer: string;
|
|
15
16
|
}>;
|
|
16
|
-
preKeygen(ctx: Ctx, partnerId: string, pregenIdentifier: string, pregenIdentifierType: TPregenIdentifierType, type: Exclude<
|
|
17
|
+
preKeygen(ctx: Ctx, partnerId: string, pregenIdentifier: string, pregenIdentifierType: TPregenIdentifierType, type: Exclude<TWalletType, 'SOLANA'>, secretKey: string | null, // should be acceptable as null in RN as we don't pre-gen them
|
|
17
18
|
sessionCookie: string): Promise<{
|
|
18
19
|
signer: string;
|
|
19
20
|
walletId: string;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Ctx, TPregenIdentifierType } from '@getpara/core-sdk';
|
|
2
|
-
import { BackupKitEmailProps,
|
|
3
|
-
export declare function
|
|
2
|
+
import { BackupKitEmailProps, TWalletType } from '@getpara/user-management-client';
|
|
3
|
+
export declare function isKeygenComplete(ctx: Ctx, userId: string, walletId: string): Promise<boolean>;
|
|
4
|
+
export declare function isPreKeygenComplete(ctx: Ctx, pregenIdentifier: string, pregenIdentifierType: TPregenIdentifierType, walletId: string): Promise<boolean>;
|
|
5
|
+
export declare function keygen(ctx: Ctx, userId: string, type: TWalletType, secretKey: string | null, sessionCookie?: string, _emailProps?: BackupKitEmailProps): Promise<{
|
|
4
6
|
signer: string;
|
|
5
7
|
walletId: string;
|
|
6
8
|
recoveryShare: string | null;
|
|
7
9
|
}>;
|
|
8
|
-
export declare function preKeygen(ctx: Ctx, pregenIdentifier: string, pregenIdentifierType: TPregenIdentifierType, type:
|
|
10
|
+
export declare function preKeygen(ctx: Ctx, pregenIdentifier: string, pregenIdentifierType: TPregenIdentifierType, type: TWalletType, secretKey: string | null, _skipDistribute: boolean, partnerId: string, sessionCookie?: string): Promise<{
|
|
9
11
|
signer: string;
|
|
10
12
|
walletId: string;
|
|
11
13
|
recoveryShare: string | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Ctx, TPregenIdentifierType, SignatureRes,
|
|
1
|
+
import { Ctx, TPregenIdentifierType, SignatureRes, TWalletType } from '@getpara/core-sdk';
|
|
2
2
|
export declare function ed25519Keygen(ctx: Ctx, userId: string): Promise<{
|
|
3
3
|
signer: string;
|
|
4
4
|
walletId: string;
|
|
@@ -10,11 +10,11 @@ export declare function ed25519PreKeygen(ctx: Ctx, pregenIdentifier: string, pre
|
|
|
10
10
|
export declare function ed25519Sign(ctx: Ctx, share: string, userId: string, walletId: string, base64Bytes: string): Promise<{
|
|
11
11
|
signature: string;
|
|
12
12
|
}>;
|
|
13
|
-
export declare function keygen(ctx: Ctx, userId: string, type: Exclude<
|
|
13
|
+
export declare function keygen(ctx: Ctx, userId: string, type: Exclude<TWalletType, 'SOLANA'>, secretKey: string | null): Promise<{
|
|
14
14
|
signer: string;
|
|
15
15
|
walletId: string;
|
|
16
16
|
}>;
|
|
17
|
-
export declare function preKeygen(ctx: Ctx, partnerId: string, pregenIdentifier: string, pregenIdentifierType: TPregenIdentifierType, type: Exclude<
|
|
17
|
+
export declare function preKeygen(ctx: Ctx, partnerId: string, pregenIdentifier: string, pregenIdentifierType: TPregenIdentifierType, type: Exclude<TWalletType, 'SOLANA'>, secretKey: string | null): Promise<{
|
|
18
18
|
signer: string;
|
|
19
19
|
walletId: string;
|
|
20
20
|
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Environment } from '@getpara/core-sdk';
|
|
1
|
+
import { Ctx, Environment } from '@getpara/core-sdk';
|
|
2
2
|
interface Message {
|
|
3
3
|
env: Environment;
|
|
4
4
|
apiKey: string;
|
|
@@ -12,6 +12,7 @@ interface Message {
|
|
|
12
12
|
disableWebSockets?: boolean;
|
|
13
13
|
workId: string;
|
|
14
14
|
}
|
|
15
|
+
export declare function requestWasmWithRetries(ctx: Ctx, retries?: number): Promise<import("axios").AxiosResponse<any, any>>;
|
|
15
16
|
export declare function handleMessage(e: {
|
|
16
17
|
data: Message;
|
|
17
18
|
}): Promise<any>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/server-sdk",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.6",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
"wasm_exec.js"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@getpara/core-sdk": "2.0.0-alpha.
|
|
13
|
-
"@getpara/user-management-client": "2.0.0-alpha.
|
|
12
|
+
"@getpara/core-sdk": "2.0.0-alpha.6",
|
|
13
|
+
"@getpara/user-management-client": "2.0.0-alpha.6",
|
|
14
14
|
"@sentry/node": "^9.1.0",
|
|
15
|
-
"uuid": "^
|
|
15
|
+
"uuid": "^11.1.0",
|
|
16
16
|
"ws": "^8.14.2"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"dist",
|
|
32
32
|
"package.json"
|
|
33
33
|
],
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "d3b01a8fb475c2af9bf255800bc10d05e011b2eb"
|
|
35
35
|
}
|
package/dist/cjs/index.js.br
DELETED
|
Binary file
|
package/dist/cjs/index.js.gz
DELETED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/esm/index.js.br
DELETED
|
Binary file
|
package/dist/esm/index.js.gz
DELETED
|
Binary file
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
-
}) : x)(function(x) {
|
|
5
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
-
});
|
|
8
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
9
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
-
};
|
|
11
|
-
var __async = (__this, __arguments, generator) => {
|
|
12
|
-
return new Promise((resolve, reject) => {
|
|
13
|
-
var fulfilled = (value) => {
|
|
14
|
-
try {
|
|
15
|
-
step(generator.next(value));
|
|
16
|
-
} catch (e) {
|
|
17
|
-
reject(e);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
var rejected = (value) => {
|
|
21
|
-
try {
|
|
22
|
-
step(generator.throw(value));
|
|
23
|
-
} catch (e) {
|
|
24
|
-
reject(e);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
28
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export {
|
|
33
|
-
__require,
|
|
34
|
-
__commonJS,
|
|
35
|
-
__async
|
|
36
|
-
};
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|