@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.
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,367 @@
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 walletUtils_exports = {};
39
+ __export(walletUtils_exports, {
40
+ ed25519Keygen: () => ed25519Keygen,
41
+ ed25519PreKeygen: () => ed25519PreKeygen,
42
+ ed25519Sign: () => ed25519Sign,
43
+ getPrivateKey: () => getPrivateKey,
44
+ keygen: () => keygen,
45
+ preKeygen: () => preKeygen,
46
+ refresh: () => refresh,
47
+ sendTransaction: () => sendTransaction,
48
+ signMessage: () => signMessage,
49
+ signTransaction: () => signTransaction
50
+ });
51
+ module.exports = __toCommonJS(walletUtils_exports);
52
+ var import_core_sdk = require("@getpara/core-sdk");
53
+ const configCGGMPBase = (serverUrl, walletId, id) => `{"ServerUrl":"${serverUrl}", "WalletId": "${walletId}", "Id":"${id}", "Ids":["USER","CAPSULE"], "Threshold":1}`;
54
+ const configDKLSBase = (walletId, id, disableWebSockets) => `{"walletId": "${walletId}", "id":"${id}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${disableWebSockets}}`;
55
+ function keygenRequest(ctx, userId, walletId, protocolId) {
56
+ return __async(this, null, function* () {
57
+ const { data } = yield ctx.mpcComputationClient.post("/wallets", {
58
+ userId,
59
+ walletId,
60
+ protocolId
61
+ });
62
+ return data;
63
+ });
64
+ }
65
+ function signMessageRequest(ctx, userId, walletId, protocolId, message, signer) {
66
+ return __async(this, null, function* () {
67
+ const { data } = yield ctx.mpcComputationClient.post(`/wallets/${walletId}/messages/sign`, {
68
+ userId,
69
+ protocolId,
70
+ message,
71
+ signer
72
+ });
73
+ return data;
74
+ });
75
+ }
76
+ function sendTransactionRequest(ctx, userId, walletId, protocolId, transaction, signer, chainId) {
77
+ return __async(this, null, function* () {
78
+ const { data } = yield ctx.mpcComputationClient.post(`/wallets/${walletId}/transactions/send`, {
79
+ userId,
80
+ protocolId,
81
+ transaction,
82
+ signer,
83
+ chainId
84
+ });
85
+ return data;
86
+ });
87
+ }
88
+ function ed25519Keygen(ctx, userId) {
89
+ return __async(this, null, function* () {
90
+ const { walletId, protocolId } = yield ctx.client.createWallet(userId, {
91
+ scheme: "ED25519",
92
+ type: "SOLANA"
93
+ });
94
+ const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
95
+ try {
96
+ const newSigner = yield new Promise(
97
+ (resolve, reject) => global.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
98
+ if (err) {
99
+ reject(err);
100
+ }
101
+ resolve(result);
102
+ })
103
+ );
104
+ return { signer: newSigner, walletId };
105
+ } catch (e) {
106
+ throw new Error(`error creating account of type SOLANA with userId ${userId} and walletId ${walletId}`);
107
+ }
108
+ });
109
+ }
110
+ function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType) {
111
+ return __async(this, null, function* () {
112
+ const { walletId, protocolId } = yield ctx.client.createPregenWallet({
113
+ pregenIdentifier,
114
+ pregenIdentifierType,
115
+ scheme: "ED25519",
116
+ type: "SOLANA"
117
+ });
118
+ const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
119
+ try {
120
+ const newSigner = yield new Promise(
121
+ (resolve, reject) => global.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
122
+ if (err) {
123
+ reject(err);
124
+ }
125
+ resolve(result);
126
+ })
127
+ );
128
+ return { signer: newSigner, walletId };
129
+ } catch (e) {
130
+ throw new Error(`error creating account of type SOLANA with walletId ${walletId}`);
131
+ }
132
+ });
133
+ }
134
+ function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
135
+ return __async(this, null, function* () {
136
+ const { protocolId } = yield ctx.client.preSignMessage(userId, walletId, base64Bytes, "ED25519");
137
+ try {
138
+ const base64Sig = yield new Promise(
139
+ (resolve, reject) => global.ed25519Sign(share, protocolId, base64Bytes, (err, result) => {
140
+ if (err) {
141
+ reject(err);
142
+ }
143
+ resolve(result);
144
+ })
145
+ );
146
+ return { signature: base64Sig };
147
+ } catch (e) {
148
+ throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
149
+ }
150
+ });
151
+ }
152
+ function keygen(ctx, userId, type, secretKey) {
153
+ return __async(this, null, function* () {
154
+ const { walletId, protocolId } = yield ctx.client.createWallet(userId, {
155
+ useTwoSigners: true,
156
+ scheme: ctx.useDKLS ? "DKLS" : "CGGMP",
157
+ type,
158
+ cosmosPrefix: type === "COSMOS" ? ctx.cosmosPrefix : void 0
159
+ });
160
+ if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
161
+ return {
162
+ signer: (yield keygenRequest(ctx, userId, walletId, protocolId)).signer,
163
+ walletId
164
+ };
165
+ }
166
+ const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
167
+ const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
168
+ const createAccountFn = ctx.useDKLS ? global.dklsCreateAccount : global.createAccountV2;
169
+ try {
170
+ const newSigner = yield new Promise(
171
+ (resolve, reject) => createAccountFn(
172
+ signerConfigUser,
173
+ serverUrl,
174
+ protocolId,
175
+ secretKey,
176
+ () => {
177
+ },
178
+ // no-op for deprecated callback to update progress percentage
179
+ (err, result) => {
180
+ if (err) {
181
+ reject(err);
182
+ }
183
+ resolve(result);
184
+ }
185
+ )
186
+ );
187
+ return { signer: newSigner, walletId };
188
+ } catch (e) {
189
+ throw new Error(`error creating account of type ${type} with userId ${userId} and walletId ${walletId}`);
190
+ }
191
+ });
192
+ }
193
+ function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey) {
194
+ return __async(this, null, function* () {
195
+ const { walletId, protocolId } = yield ctx.client.createPregenWallet({
196
+ pregenIdentifier,
197
+ pregenIdentifierType,
198
+ type,
199
+ cosmosPrefix: type === "COSMOS" ? ctx.cosmosPrefix : void 0
200
+ });
201
+ if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
202
+ return {
203
+ signer: (yield keygenRequest(ctx, partnerId, walletId, protocolId)).signer,
204
+ walletId
205
+ };
206
+ }
207
+ const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
208
+ const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
209
+ const createAccountFn = ctx.useDKLS ? global.dklsCreateAccount : global.createAccountV2;
210
+ try {
211
+ const newSigner = yield new Promise(
212
+ (resolve, reject) => createAccountFn(
213
+ signerConfigUser,
214
+ serverUrl,
215
+ protocolId,
216
+ secretKey,
217
+ () => {
218
+ },
219
+ // no-op for deprecated callback to update progress percentage
220
+ (err, result) => {
221
+ if (err) {
222
+ reject(err);
223
+ }
224
+ resolve(result);
225
+ }
226
+ )
227
+ );
228
+ return { signer: newSigner, walletId };
229
+ } catch (e) {
230
+ throw new Error(`error creating account of type ${type} with walletId ${walletId}`);
231
+ }
232
+ });
233
+ }
234
+ function signMessage(ctx, share, walletId, userId, message) {
235
+ return __async(this, null, function* () {
236
+ const { protocolId, pendingTransactionId } = yield ctx.client.preSignMessage(userId, walletId, message);
237
+ if (pendingTransactionId) {
238
+ return { pendingTransactionId };
239
+ }
240
+ if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
241
+ return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
242
+ }
243
+ const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
244
+ const signMessageFn = ctx.useDKLS ? global.dklsSignMessage : global.signMessage;
245
+ try {
246
+ return yield new Promise(
247
+ (resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
248
+ if (err) {
249
+ reject(err);
250
+ }
251
+ resolve({ signature: result });
252
+ })
253
+ );
254
+ } catch (e) {
255
+ throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
256
+ }
257
+ });
258
+ }
259
+ function signTransaction(ctx, share, walletId, userId, tx, chainId) {
260
+ return __async(this, null, function* () {
261
+ const {
262
+ data: { protocolId, pendingTransactionId }
263
+ } = yield ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId });
264
+ if (pendingTransactionId) {
265
+ return { pendingTransactionId };
266
+ }
267
+ if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
268
+ return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
269
+ }
270
+ const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
271
+ const signTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
272
+ try {
273
+ return yield new Promise(
274
+ (resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
275
+ if (err) {
276
+ reject(err);
277
+ }
278
+ resolve({ signature: result });
279
+ })
280
+ );
281
+ } catch (e) {
282
+ throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
283
+ }
284
+ });
285
+ }
286
+ function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
287
+ return __async(this, null, function* () {
288
+ const {
289
+ data: { protocolId, pendingTransactionId }
290
+ } = yield ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId });
291
+ if (pendingTransactionId) {
292
+ return { pendingTransactionId };
293
+ }
294
+ if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
295
+ return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
296
+ }
297
+ const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
298
+ const sendTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
299
+ try {
300
+ return yield new Promise(
301
+ (resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
302
+ if (err) {
303
+ reject(err);
304
+ }
305
+ resolve({ signature: result });
306
+ })
307
+ );
308
+ } catch (e) {
309
+ throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
310
+ }
311
+ });
312
+ }
313
+ function refresh(ctx, share, walletId, userId) {
314
+ return __async(this, null, function* () {
315
+ const {
316
+ data: { protocolId }
317
+ } = yield ctx.client.refreshKeys(userId, walletId);
318
+ const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
319
+ const refreshFn = ctx.useDKLS ? global.dklsRefresh : global.refresh;
320
+ try {
321
+ return yield new Promise(
322
+ (resolve, reject) => refreshFn(share, serverUrl, protocolId, (err, result) => {
323
+ if (err) {
324
+ reject(err);
325
+ }
326
+ resolve(result);
327
+ })
328
+ );
329
+ } catch (e) {
330
+ throw new Error(`error refreshing keys for account with userId ${userId} and walletId ${walletId}`);
331
+ }
332
+ });
333
+ }
334
+ function getPrivateKey(ctx, share, walletId, userId) {
335
+ return __async(this, null, function* () {
336
+ const paraShare = yield ctx.client.getParaShare(userId, walletId);
337
+ if (!paraShare) {
338
+ console.error("unable to retrieve Para share");
339
+ return "";
340
+ }
341
+ try {
342
+ return yield new Promise(
343
+ (resolve, reject) => global.getPrivateKey(share, paraShare, (err, result) => {
344
+ if (err) {
345
+ reject(err);
346
+ }
347
+ resolve(result);
348
+ })
349
+ );
350
+ } catch (e) {
351
+ throw new Error(`error getting private key for account with userId ${userId} and walletId ${walletId}`);
352
+ }
353
+ });
354
+ }
355
+ // Annotate the CommonJS export names for ESM import in node:
356
+ 0 && (module.exports = {
357
+ ed25519Keygen,
358
+ ed25519PreKeygen,
359
+ ed25519Sign,
360
+ getPrivateKey,
361
+ keygen,
362
+ preKeygen,
363
+ refresh,
364
+ sendTransaction,
365
+ signMessage,
366
+ signTransaction
367
+ });