@getpara/server-sdk 1.4.3 → 1.4.4

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.
@@ -1 +1,408 @@
1
- import{a as $}from"./chunk-NEJSZOZX.js";import G from"axios";import{getPortalBaseURL as O,initClient as _,mpcComputationClient as F,paraVersion as V,WalletType as M}from"@getpara/core-sdk";import{getBaseMPCNetworkUrl as w,WalletScheme as p,WalletType as S}from"@getpara/core-sdk";var C=(e,a,r)=>`{"ServerUrl":"${e}", "WalletId": "${a}", "Id":"${r}", "Ids":["USER","CAPSULE"], "Threshold":1}`,b=(e,a,r)=>`{"walletId": "${e}", "id":"${a}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${r}}`;async function P(e,a,r,t){let{data:n}=await e.mpcComputationClient.post("/wallets",{userId:a,walletId:r,protocolId:t});return n}async function D(e,a,r,t,n,i){let{data:s}=await e.mpcComputationClient.post(`/wallets/${r}/messages/sign`,{userId:a,protocolId:t,message:n,signer:i});return s}async function h(e,a,r,t,n,i,s){let{data:o}=await e.mpcComputationClient.post(`/wallets/${r}/transactions/send`,{userId:a,protocolId:t,transaction:n,signer:i,chainId:s});return o}async function I(e,a){let{walletId:r,protocolId:t}=await e.client.createWallet(a,{scheme:p.ED25519,type:S.SOLANA}),n=w(e.env,!e.disableWebSockets);try{return{signer:await new Promise((s,o)=>global.ed25519CreateAccount(n,r,t,(l,g)=>{l&&o(l),s(g)})),walletId:r}}catch{throw new Error(`error creating account of type SOLANA with userId ${a} and walletId ${r}`)}}async function E(e,a,r){let{walletId:t,protocolId:n}=await e.client.createPregenWallet({pregenIdentifier:a,pregenIdentifierType:r,scheme:p.ED25519,type:S.SOLANA}),i=w(e.env,!e.disableWebSockets);try{return{signer:await new Promise((o,l)=>global.ed25519CreateAccount(i,t,n,(g,c)=>{g&&l(g),o(c)})),walletId:t}}catch{throw new Error(`error creating account of type SOLANA with walletId ${t}`)}}async function T(e,a,r,t,n){let{protocolId:i}=await e.client.preSignMessage(r,t,n,p.ED25519);try{return{signature:await new Promise((o,l)=>global.ed25519Sign(a,i,n,(g,c)=>{g&&l(g),o(c)}))}}catch{throw new Error(`error signing for account of type SOLANA with userId ${r} and walletId ${t}`)}}async function U(e,a,r,t){let{walletId:n,protocolId:i}=await e.client.createWallet(a,{useTwoSigners:!0,scheme:e.useDKLS?p.DKLS:p.CGGMP,type:r,cosmosPrefix:r===S.COSMOS?e.cosmosPrefix:void 0});if(e.offloadMPCComputationURL&&!e.useDKLS)return{signer:(await P(e,a,n,i)).signer,walletId:n};let s=w(e.env,!e.disableWebSockets),o=e.useDKLS?b(n,"USER",e.disableWebSockets):C(s,n,"USER"),l=e.useDKLS?global.dklsCreateAccount:global.createAccountV2;try{return{signer:await new Promise((c,u)=>l(o,s,i,t,()=>{},(d,f)=>{d&&u(d),c(f)})),walletId:n}}catch{throw new Error(`error creating account of type ${r} with userId ${a} and walletId ${n}`)}}async function L(e,a,r,t,n,i){let{walletId:s,protocolId:o}=await e.client.createPregenWallet({pregenIdentifier:r,pregenIdentifierType:t,type:n,cosmosPrefix:n===S.COSMOS?e.cosmosPrefix:void 0});if(e.offloadMPCComputationURL&&!e.useDKLS)return{signer:(await P(e,a,s,o)).signer,walletId:s};let l=w(e.env,!e.disableWebSockets),g=e.useDKLS?b(s,"USER",e.disableWebSockets):C(l,s,"USER"),c=e.useDKLS?global.dklsCreateAccount:global.createAccountV2;try{return{signer:await new Promise((d,f)=>c(g,l,o,i,()=>{},(y,v)=>{y&&f(y),d(v)})),walletId:s}}catch{throw new Error(`error creating account of type ${n} with walletId ${s}`)}}async function K(e,a,r,t,n){let{protocolId:i,pendingTransactionId:s}=await e.client.preSignMessage(t,r,n);if(s)return{pendingTransactionId:s};if(e.offloadMPCComputationURL&&!e.useDKLS)return D(e,t,r,i,n,a);let o=w(e.env,!e.disableWebSockets),l=e.useDKLS?global.dklsSignMessage:global.signMessage;try{return new Promise((g,c)=>l(a,o,n,i,(u,d)=>{u&&c(u),g({signature:d})}))}catch{throw new Error(`error signing for account with userId ${t} and walletId ${r}`)}}async function k(e,a,r,t,n,i){let{data:{protocolId:s,pendingTransactionId:o}}=await e.client.signTransaction(t,r,{transaction:n,chainId:i});if(o)return{pendingTransactionId:o};if(e.offloadMPCComputationURL&&!e.useDKLS)return h(e,t,r,s,n,a,i);let l=w(e.env,!e.disableWebSockets),g=e.useDKLS?global.dklsSendTransaction:global.sendTransaction;try{return new Promise((c,u)=>g(a,l,n,i,s,(d,f)=>{d&&u(d),c({signature:f})}))}catch{throw new Error(`error signing transaction for account with userId ${t} and walletId ${r}`)}}async function A(e,a,r,t,n,i){let{data:{protocolId:s,pendingTransactionId:o}}=await e.client.sendTransaction(t,r,{transaction:n,chainId:i});if(o)return{pendingTransactionId:o};if(e.offloadMPCComputationURL&&!e.useDKLS)return h(e,t,r,s,n,a,i);let l=w(e.env,!e.disableWebSockets),g=e.useDKLS?global.dklsSendTransaction:global.sendTransaction;try{return new Promise((c,u)=>g(a,l,n,i,s,(d,f)=>{d&&u(d),c({signature:f})}))}catch{throw new Error(`error signing transaction to send for account with userId ${t} and walletId ${r}`)}}async function R(e,a,r,t){let{data:{protocolId:n}}=await e.client.refreshKeys(t,r),i=w(e.env,!e.disableWebSockets),s=e.useDKLS?global.dklsRefresh:global.refresh;try{return new Promise((o,l)=>s(a,i,n,(g,c)=>{g&&l(g),o(c)}))}catch{throw new Error(`error refreshing keys for account with userId ${t} and walletId ${r}`)}}async function W(e,a,r,t){let n=await e.client.getParaShare(t,r);if(!n)return console.error("unable to retrieve Para share"),"";try{return new Promise((i,s)=>global.getPrivateKey(a,n,(o,l)=>{o&&s(o),i(l)}))}catch{throw new Error(`error getting private key for account with userId ${t} and walletId ${r}`)}}var m;async function q(e,a=3){for(let r=0;r<a;r++)try{return await G.get(`${O(e,!0,!0)}/static/js/main.wasm`,{responseType:"arraybuffer"})}catch(t){if(r===a-1)throw t}}async function B(e){await import("./wasm_exec-TBSO5IWG.js"),global.WebSocket=$("ws");let a=new global.Go;m||(m=(await q(e)).data);let r=new Uint8Array(m),t=await WebAssembly.instantiate(r,a.importObject);a.run(t.instance)}async function Y(e,a){let{functionType:r,params:t}=a;switch(r){case"KEYGEN":{let{userId:n,secretKey:i,type:s=M.EVM}=t;return U(e,n,s,i)}case"SIGN_TRANSACTION":{let{share:n,walletId:i,userId:s,tx:o,chainId:l}=t;return k(e,n,i,s,o,l)}case"SEND_TRANSACTION":{let{share:n,walletId:i,userId:s,tx:o,chainId:l}=t;return A(e,n,i,s,o,l)}case"SIGN_MESSAGE":{let{share:n,walletId:i,userId:s,message:o}=t;return K(e,n,i,s,o)}case"REFRESH":{let{share:n,walletId:i,userId:s}=t;return R(e,n,i,s)}case"PREKEYGEN":{let{email:n,partnerId:i,secretKey:s,type:o=M.EVM}=t,{pregenIdentifier:l,pregenIdentifierType:g}=t;return n!=="null"&&n!=="undefined"&&n!==""&&n!=null&&(l=n,g="EMAIL"),await L(e,i,l,g,o,s)}case"GET_PRIVATE_KEY":{let{share:n,walletId:i,userId:s}=t;return await W(e,n,i,s)}case"ED25519_KEYGEN":{let{userId:n}=t;return I(e,n)}case"ED25519_SIGN":{let{share:n,walletId:i,userId:s,base64Bytes:o}=t;return T(e,n,s,i,o)}case"ED25519_PREKEYGEN":{let{email:n}=t,{pregenIdentifier:i,pregenIdentifierType:s}=t;return n!=="null"&&n!=="undefined"&&n!==""&&n!=null&&(i=n,s="EMAIL"),E(e,i,s)}default:throw new Error(`functionType: ${r} not supported`)}}async function ee(e){let{env:a,apiKey:r,cosmosPrefix:t="cosmos",offloadMPCComputationURL:n,disableWorkers:i,sessionCookie:s,useDKLS:o,disableWebSockets:l,workId:g}=e.data,c={env:a,apiKey:r,client:_({env:a,version:V,apiKey:r,retrieveSessionCookie:()=>s}),offloadMPCComputationURL:n,mpcComputationClient:n?F.initClient(n,!!i):void 0,useDKLS:o,disableWebSockets:!!l,cosmosPrefix:t};(!c.offloadMPCComputationURL||c.useDKLS)&&await B(c);let u=await Y(c,e.data);return u.workId=g,u}export{ee as handleMessage};
1
+ import {
2
+ __require
3
+ } from "./chunk-MCKGQKYU.js";
4
+
5
+ // src/workers/worker.ts
6
+ import axios from "axios";
7
+ import {
8
+ getPortalBaseURL,
9
+ initClient,
10
+ mpcComputationClient,
11
+ paraVersion,
12
+ WalletType as WalletType2
13
+ } from "@getpara/core-sdk";
14
+
15
+ // src/workers/walletUtils.ts
16
+ import { getBaseMPCNetworkUrl, WalletScheme, WalletType } from "@getpara/core-sdk";
17
+ var configCGGMPBase = (serverUrl, walletId, id) => `{"ServerUrl":"${serverUrl}", "WalletId": "${walletId}", "Id":"${id}", "Ids":["USER","CAPSULE"], "Threshold":1}`;
18
+ var configDKLSBase = (walletId, id, disableWebSockets) => `{"walletId": "${walletId}", "id":"${id}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${disableWebSockets}}`;
19
+ async function keygenRequest(ctx, userId, walletId, protocolId) {
20
+ const { data } = await ctx.mpcComputationClient.post("/wallets", {
21
+ userId,
22
+ walletId,
23
+ protocolId
24
+ });
25
+ return data;
26
+ }
27
+ async function signMessageRequest(ctx, userId, walletId, protocolId, message, signer) {
28
+ const { data } = await ctx.mpcComputationClient.post(`/wallets/${walletId}/messages/sign`, {
29
+ userId,
30
+ protocolId,
31
+ message,
32
+ signer
33
+ });
34
+ return data;
35
+ }
36
+ async function sendTransactionRequest(ctx, userId, walletId, protocolId, transaction, signer, chainId) {
37
+ const { data } = await ctx.mpcComputationClient.post(`/wallets/${walletId}/transactions/send`, {
38
+ userId,
39
+ protocolId,
40
+ transaction,
41
+ signer,
42
+ chainId
43
+ });
44
+ return data;
45
+ }
46
+ async function ed25519Keygen(ctx, userId) {
47
+ const { walletId, protocolId } = await ctx.client.createWallet(userId, {
48
+ scheme: WalletScheme.ED25519,
49
+ type: WalletType.SOLANA
50
+ });
51
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
52
+ try {
53
+ const newSigner = await new Promise(
54
+ (resolve, reject) => global.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
55
+ if (err) {
56
+ reject(err);
57
+ }
58
+ resolve(result);
59
+ })
60
+ );
61
+ return { signer: newSigner, walletId };
62
+ } catch (e) {
63
+ throw new Error(`error creating account of type SOLANA with userId ${userId} and walletId ${walletId}`);
64
+ }
65
+ }
66
+ async function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType) {
67
+ const { walletId, protocolId } = await ctx.client.createPregenWallet({
68
+ pregenIdentifier,
69
+ pregenIdentifierType,
70
+ scheme: WalletScheme.ED25519,
71
+ type: WalletType.SOLANA
72
+ });
73
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
74
+ try {
75
+ const newSigner = await new Promise(
76
+ (resolve, reject) => global.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
77
+ if (err) {
78
+ reject(err);
79
+ }
80
+ resolve(result);
81
+ })
82
+ );
83
+ return { signer: newSigner, walletId };
84
+ } catch (e) {
85
+ throw new Error(`error creating account of type SOLANA with walletId ${walletId}`);
86
+ }
87
+ }
88
+ async function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
89
+ const { protocolId } = await ctx.client.preSignMessage(userId, walletId, base64Bytes, WalletScheme.ED25519);
90
+ try {
91
+ const base64Sig = await new Promise(
92
+ (resolve, reject) => global.ed25519Sign(share, protocolId, base64Bytes, (err, result) => {
93
+ if (err) {
94
+ reject(err);
95
+ }
96
+ resolve(result);
97
+ })
98
+ );
99
+ return { signature: base64Sig };
100
+ } catch (e) {
101
+ throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
102
+ }
103
+ }
104
+ async function keygen(ctx, userId, type, secretKey) {
105
+ const { walletId, protocolId } = await ctx.client.createWallet(userId, {
106
+ useTwoSigners: true,
107
+ scheme: ctx.useDKLS ? WalletScheme.DKLS : WalletScheme.CGGMP,
108
+ type,
109
+ cosmosPrefix: type === WalletType.COSMOS ? ctx.cosmosPrefix : void 0
110
+ });
111
+ if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
112
+ return {
113
+ signer: (await keygenRequest(ctx, userId, walletId, protocolId)).signer,
114
+ walletId
115
+ };
116
+ }
117
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
118
+ const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
119
+ const createAccountFn = ctx.useDKLS ? global.dklsCreateAccount : global.createAccountV2;
120
+ try {
121
+ const newSigner = await new Promise(
122
+ (resolve, reject) => createAccountFn(
123
+ signerConfigUser,
124
+ serverUrl,
125
+ protocolId,
126
+ secretKey,
127
+ () => {
128
+ },
129
+ // no-op for deprecated callback to update progress percentage
130
+ (err, result) => {
131
+ if (err) {
132
+ reject(err);
133
+ }
134
+ resolve(result);
135
+ }
136
+ )
137
+ );
138
+ return { signer: newSigner, walletId };
139
+ } catch (e) {
140
+ throw new Error(`error creating account of type ${type} with userId ${userId} and walletId ${walletId}`);
141
+ }
142
+ }
143
+ async function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey) {
144
+ const { walletId, protocolId } = await ctx.client.createPregenWallet({
145
+ pregenIdentifier,
146
+ pregenIdentifierType,
147
+ type,
148
+ cosmosPrefix: type === WalletType.COSMOS ? ctx.cosmosPrefix : void 0
149
+ });
150
+ if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
151
+ return {
152
+ signer: (await keygenRequest(ctx, partnerId, walletId, protocolId)).signer,
153
+ walletId
154
+ };
155
+ }
156
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
157
+ const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
158
+ const createAccountFn = ctx.useDKLS ? global.dklsCreateAccount : global.createAccountV2;
159
+ try {
160
+ const newSigner = await new Promise(
161
+ (resolve, reject) => createAccountFn(
162
+ signerConfigUser,
163
+ serverUrl,
164
+ protocolId,
165
+ secretKey,
166
+ () => {
167
+ },
168
+ // no-op for deprecated callback to update progress percentage
169
+ (err, result) => {
170
+ if (err) {
171
+ reject(err);
172
+ }
173
+ resolve(result);
174
+ }
175
+ )
176
+ );
177
+ return { signer: newSigner, walletId };
178
+ } catch (e) {
179
+ throw new Error(`error creating account of type ${type} with walletId ${walletId}`);
180
+ }
181
+ }
182
+ async function signMessage(ctx, share, walletId, userId, message) {
183
+ const { protocolId, pendingTransactionId } = await ctx.client.preSignMessage(userId, walletId, message);
184
+ if (pendingTransactionId) {
185
+ return { pendingTransactionId };
186
+ }
187
+ if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
188
+ return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
189
+ }
190
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
191
+ const signMessageFn = ctx.useDKLS ? global.dklsSignMessage : global.signMessage;
192
+ try {
193
+ return new Promise(
194
+ (resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
195
+ if (err) {
196
+ reject(err);
197
+ }
198
+ resolve({ signature: result });
199
+ })
200
+ );
201
+ } catch (e) {
202
+ throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
203
+ }
204
+ }
205
+ async function signTransaction(ctx, share, walletId, userId, tx, chainId) {
206
+ const {
207
+ data: { protocolId, pendingTransactionId }
208
+ } = await ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId });
209
+ if (pendingTransactionId) {
210
+ return { pendingTransactionId };
211
+ }
212
+ if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
213
+ return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
214
+ }
215
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
216
+ const signTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
217
+ try {
218
+ return new Promise(
219
+ (resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
220
+ if (err) {
221
+ reject(err);
222
+ }
223
+ resolve({ signature: result });
224
+ })
225
+ );
226
+ } catch (e) {
227
+ throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
228
+ }
229
+ }
230
+ async function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
231
+ const {
232
+ data: { protocolId, pendingTransactionId }
233
+ } = await ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId });
234
+ if (pendingTransactionId) {
235
+ return { pendingTransactionId };
236
+ }
237
+ if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
238
+ return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
239
+ }
240
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
241
+ const sendTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
242
+ try {
243
+ return new Promise(
244
+ (resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
245
+ if (err) {
246
+ reject(err);
247
+ }
248
+ resolve({ signature: result });
249
+ })
250
+ );
251
+ } catch (e) {
252
+ throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
253
+ }
254
+ }
255
+ async function refresh(ctx, share, walletId, userId) {
256
+ const {
257
+ data: { protocolId }
258
+ } = await ctx.client.refreshKeys(userId, walletId);
259
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
260
+ const refreshFn = ctx.useDKLS ? global.dklsRefresh : global.refresh;
261
+ try {
262
+ return new Promise(
263
+ (resolve, reject) => refreshFn(share, serverUrl, protocolId, (err, result) => {
264
+ if (err) {
265
+ reject(err);
266
+ }
267
+ resolve(result);
268
+ })
269
+ );
270
+ } catch (e) {
271
+ throw new Error(`error refreshing keys for account with userId ${userId} and walletId ${walletId}`);
272
+ }
273
+ }
274
+ async function getPrivateKey(ctx, share, walletId, userId) {
275
+ const paraShare = await ctx.client.getParaShare(userId, walletId);
276
+ if (!paraShare) {
277
+ console.error("unable to retrieve Para share");
278
+ return "";
279
+ }
280
+ try {
281
+ return new Promise(
282
+ (resolve, reject) => global.getPrivateKey(share, paraShare, (err, result) => {
283
+ if (err) {
284
+ reject(err);
285
+ }
286
+ resolve(result);
287
+ })
288
+ );
289
+ } catch (e) {
290
+ throw new Error(`error getting private key for account with userId ${userId} and walletId ${walletId}`);
291
+ }
292
+ }
293
+
294
+ // src/workers/worker.ts
295
+ var rawWasm;
296
+ async function requestWasmWithRetries(ctx, retries = 3) {
297
+ for (let i = 0; i < retries; i++) {
298
+ try {
299
+ return await axios.get(`${getPortalBaseURL(ctx, true, true)}/static/js/main.wasm`, { responseType: "arraybuffer" });
300
+ } catch (e) {
301
+ if (i === retries - 1) {
302
+ throw e;
303
+ }
304
+ }
305
+ }
306
+ }
307
+ async function loadWasm(ctx) {
308
+ await import("./wasm_exec-UV7SYRZI.js");
309
+ global.WebSocket = __require("ws");
310
+ const goWasm = new global.Go();
311
+ if (!rawWasm) {
312
+ rawWasm = (await requestWasmWithRetries(ctx)).data;
313
+ }
314
+ const wasmBuffer = new Uint8Array(rawWasm);
315
+ const webAssemblySource = await WebAssembly.instantiate(wasmBuffer, goWasm.importObject);
316
+ goWasm.run(webAssemblySource.instance);
317
+ }
318
+ async function executeMessage(ctx, message) {
319
+ const { functionType, params } = message;
320
+ switch (functionType) {
321
+ case "KEYGEN": {
322
+ const { userId, secretKey, type = WalletType2.EVM } = params;
323
+ return keygen(ctx, userId, type, secretKey);
324
+ }
325
+ case "SIGN_TRANSACTION": {
326
+ const { share, walletId, userId, tx, chainId } = params;
327
+ return signTransaction(ctx, share, walletId, userId, tx, chainId);
328
+ }
329
+ case "SEND_TRANSACTION": {
330
+ const { share, walletId, userId, tx, chainId } = params;
331
+ return sendTransaction(ctx, share, walletId, userId, tx, chainId);
332
+ }
333
+ case "SIGN_MESSAGE": {
334
+ const { share, walletId, userId, message: message2 } = params;
335
+ return signMessage(ctx, share, walletId, userId, message2);
336
+ }
337
+ case "REFRESH": {
338
+ const { share, walletId, userId } = params;
339
+ return refresh(ctx, share, walletId, userId);
340
+ }
341
+ case "PREKEYGEN": {
342
+ const { email, partnerId, secretKey, type = WalletType2.EVM } = params;
343
+ let { pregenIdentifier, pregenIdentifierType } = params;
344
+ if (email !== "null" && email !== "undefined" && email !== "" && email != null) {
345
+ pregenIdentifier = email;
346
+ pregenIdentifierType = "EMAIL";
347
+ }
348
+ const keygenRes = await preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey);
349
+ return keygenRes;
350
+ }
351
+ case "GET_PRIVATE_KEY": {
352
+ const { share, walletId, userId } = params;
353
+ return await getPrivateKey(ctx, share, walletId, userId);
354
+ }
355
+ case "ED25519_KEYGEN": {
356
+ const { userId } = params;
357
+ return ed25519Keygen(ctx, userId);
358
+ }
359
+ case "ED25519_SIGN": {
360
+ const { share, walletId, userId, base64Bytes } = params;
361
+ return ed25519Sign(ctx, share, userId, walletId, base64Bytes);
362
+ }
363
+ case "ED25519_PREKEYGEN": {
364
+ const { email } = params;
365
+ let { pregenIdentifier, pregenIdentifierType } = params;
366
+ if (email !== "null" && email !== "undefined" && email !== "" && email != null) {
367
+ pregenIdentifier = email;
368
+ pregenIdentifierType = "EMAIL";
369
+ }
370
+ return ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType);
371
+ }
372
+ default: {
373
+ throw new Error(`functionType: ${functionType} not supported`);
374
+ }
375
+ }
376
+ }
377
+ async function handleMessage(e) {
378
+ const {
379
+ env,
380
+ apiKey,
381
+ cosmosPrefix = "cosmos",
382
+ offloadMPCComputationURL,
383
+ disableWorkers,
384
+ sessionCookie,
385
+ useDKLS,
386
+ disableWebSockets,
387
+ workId
388
+ } = e.data;
389
+ const ctx = {
390
+ env,
391
+ apiKey,
392
+ client: initClient({ env, version: paraVersion, apiKey, retrieveSessionCookie: () => sessionCookie }),
393
+ offloadMPCComputationURL,
394
+ mpcComputationClient: offloadMPCComputationURL ? mpcComputationClient.initClient(offloadMPCComputationURL, !!disableWorkers) : void 0,
395
+ useDKLS,
396
+ disableWebSockets: !!disableWebSockets,
397
+ cosmosPrefix
398
+ };
399
+ if (!ctx.offloadMPCComputationURL || ctx.useDKLS) {
400
+ await loadWasm(ctx);
401
+ }
402
+ const result = await executeMessage(ctx, e.data);
403
+ result.workId = workId;
404
+ return result;
405
+ }
406
+ export {
407
+ handleMessage
408
+ };
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getpara/server-sdk",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -9,8 +9,8 @@
9
9
  "wasm_exec.js"
10
10
  ],
11
11
  "dependencies": {
12
- "@getpara/core-sdk": "1.4.3",
13
- "@getpara/user-management-client": "1.4.3",
12
+ "@getpara/core-sdk": "1.4.4",
13
+ "@getpara/user-management-client": "1.4.4",
14
14
  "@sentry/node": "^9.1.0",
15
15
  "uuid": "^9.0.1",
16
16
  "ws": "^8.14.2"
@@ -31,5 +31,5 @@
31
31
  "dist",
32
32
  "package.json"
33
33
  ],
34
- "gitHead": "1af7abd51e994057ff4afc90bd13650a47f6b26e"
34
+ "gitHead": "9a4086c4b352fff2143d3b931d288c5ebaf127fb"
35
35
  }
@@ -1 +0,0 @@
1
- var d=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(b,c)=>(typeof require<"u"?require:b)[c]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var e=(a,b)=>()=>(b||a((b={exports:{}}).exports,b),b.exports);export{d as a,e as b};
@@ -1,2 +0,0 @@
1
- import{a as b,b as x}from"./chunk-NEJSZOZX.js";var v=x((U,w)=>{var g=global;g.crypto||(g.crypto=b("crypto"));var T=g.crypto;(()=>{let o=()=>{let h=new Error("not implemented");return h.code="ENOSYS",h};if(!globalThis.fs){let h="";globalThis.fs={constants:{O_WRONLY:-1,O_RDWR:-1,O_CREAT:-1,O_TRUNC:-1,O_APPEND:-1,O_EXCL:-1},writeSync(n,s){h+=_.decode(s);let i=h.lastIndexOf(`
2
- `);return i!=-1&&(console.log(h.substring(0,i)),h=h.substring(i+1)),s.length},write(n,s,i,r,f,u){if(i!==0||r!==s.length||f!==null){u(o());return}let d=this.writeSync(n,s);u(null,d)},chmod(n,s,i){i(o())},chown(n,s,i,r){r(o())},close(n,s){s(o())},fchmod(n,s,i){i(o())},fchown(n,s,i,r){r(o())},fstat(n,s){s(o())},fsync(n,s){s(null)},ftruncate(n,s,i){i(o())},lchown(n,s,i,r){r(o())},link(n,s,i){i(o())},lstat(n,s){s(o())},mkdir(n,s,i){i(o())},open(n,s,i,r){r(o())},read(n,s,i,r,f,u){u(o())},readdir(n,s){s(o())},readlink(n,s){s(o())},rename(n,s,i){i(o())},rmdir(n,s){s(o())},stat(n,s){s(o())},symlink(n,s,i){i(o())},truncate(n,s,i){i(o())},unlink(n,s){s(o())},utimes(n,s,i,r){r(o())}}}if(globalThis.process||(globalThis.process={getuid(){return-1},getgid(){return-1},geteuid(){return-1},getegid(){return-1},getgroups(){throw o()},pid:-1,ppid:-1,umask(){throw o()},cwd(){throw o()},chdir(){throw o()}}),!globalThis.crypto)throw new Error("globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)");if(!globalThis.performance)throw new Error("globalThis.performance is not available, polyfill required (performance.now only)");if(!globalThis.TextEncoder)throw new Error("globalThis.TextEncoder is not available, polyfill required");if(!globalThis.TextDecoder)throw new Error("globalThis.TextDecoder is not available, polyfill required");let y=new TextEncoder("utf-8"),_=new TextDecoder("utf-8");globalThis.Go=class{constructor(){this.argv=["js"],this.env={},this.exit=t=>{t!==0&&console.warn("exit code:",t)},this._exitPromise=new Promise(t=>{this._resolveExitPromise=t}),this._pendingEvent=null,this._scheduledTimeouts=new Map,this._nextCallbackTimeoutID=1;let h=(t,e)=>{this.mem.setUint32(t+0,e,!0),this.mem.setUint32(t+4,Math.floor(e/4294967296),!0)},n=(t,e)=>{this.mem.setUint32(t+0,e,!0)},s=t=>{let e=this.mem.getUint32(t+0,!0),l=this.mem.getInt32(t+4,!0);return e+l*4294967296},i=t=>{let e=this.mem.getFloat64(t,!0);if(e===0)return;if(!isNaN(e))return e;let l=this.mem.getUint32(t,!0);return this._values[l]},r=(t,e)=>{if(typeof e=="number"&&e!==0){if(isNaN(e)){this.mem.setUint32(t+4,2146959360,!0),this.mem.setUint32(t,0,!0);return}this.mem.setFloat64(t,e,!0);return}if(e===void 0){this.mem.setFloat64(t,0,!0);return}let a=this._ids.get(e);a===void 0&&(a=this._idPool.pop(),a===void 0&&(a=this._values.length),this._values[a]=e,this._goRefCounts[a]=0,this._ids.set(e,a)),this._goRefCounts[a]++;let c=0;switch(typeof e){case"object":e!==null&&(c=1);break;case"string":c=2;break;case"symbol":c=3;break;case"function":c=4;break}this.mem.setUint32(t+4,2146959360|c,!0),this.mem.setUint32(t,a,!0)},f=t=>{let e=s(t+0),l=s(t+8);return new Uint8Array(this._inst.exports.mem.buffer,e,l)},u=t=>{let e=s(t+0),l=s(t+8),a=new Array(l);for(let c=0;c<l;c++)a[c]=i(e+c*8);return a},d=t=>{let e=s(t+0),l=s(t+8);return _.decode(new DataView(this._inst.exports.mem.buffer,e,l))},m=Date.now()-performance.now();this.importObject={_gotest:{add:(t,e)=>t+e},gojs:{"runtime.wasmExit":t=>{t>>>=0;let e=this.mem.getInt32(t+8,!0);this.exited=!0,delete this._inst,delete this._values,delete this._goRefCounts,delete this._ids,delete this._idPool,this.exit(e)},"runtime.wasmWrite":t=>{t>>>=0;let e=s(t+8),l=s(t+16),a=this.mem.getInt32(t+24,!0);fs.writeSync(e,new Uint8Array(this._inst.exports.mem.buffer,l,a))},"runtime.resetMemoryDataView":t=>{t>>>=0,this.mem=new DataView(this._inst.exports.mem.buffer)},"runtime.nanotime1":t=>{t>>>=0,h(t+8,(m+performance.now())*1e6)},"runtime.walltime":t=>{t>>>=0;let e=new Date().getTime();h(t+8,e/1e3),this.mem.setInt32(t+16,e%1e3*1e6,!0)},"runtime.scheduleTimeoutEvent":t=>{t>>>=0;let e=this._nextCallbackTimeoutID;this._nextCallbackTimeoutID++,this._scheduledTimeouts.set(e,setTimeout(()=>{for(this._resume();this._scheduledTimeouts.has(e);)console.warn("scheduleTimeoutEvent: missed timeout event"),this._resume()},s(t+8))),this.mem.setInt32(t+16,e,!0)},"runtime.clearTimeoutEvent":t=>{t>>>=0;let e=this.mem.getInt32(t+8,!0);clearTimeout(this._scheduledTimeouts.get(e)),this._scheduledTimeouts.delete(e)},"runtime.getRandomData":t=>{t>>>=0,T.getRandomValues(f(t+8))},"syscall/js.finalizeRef":t=>{t>>>=0;let e=this.mem.getUint32(t+8,!0);if(this._goRefCounts[e]--,this._goRefCounts[e]===0){let l=this._values[e];this._values[e]=null,this._ids.delete(l),this._idPool.push(e)}},"syscall/js.stringVal":t=>{t>>>=0,r(t+24,d(t+8))},"syscall/js.valueGet":t=>{t>>>=0;let e=Reflect.get(i(t+8),d(t+16));t=this._inst.exports.getsp()>>>0,r(t+32,e)},"syscall/js.valueSet":t=>{t>>>=0,Reflect.set(i(t+8),d(t+16),i(t+32))},"syscall/js.valueDelete":t=>{t>>>=0,Reflect.deleteProperty(i(t+8),d(t+16))},"syscall/js.valueIndex":t=>{t>>>=0,r(t+24,Reflect.get(i(t+8),s(t+16)))},"syscall/js.valueSetIndex":t=>{t>>>=0,Reflect.set(i(t+8),s(t+16),i(t+24))},"syscall/js.valueCall":t=>{t>>>=0;try{let e=i(t+8),l=Reflect.get(e,d(t+16)),a=u(t+32),c=Reflect.apply(l,e,a);t=this._inst.exports.getsp()>>>0,r(t+56,c),this.mem.setUint8(t+64,1)}catch(e){t=this._inst.exports.getsp()>>>0,r(t+56,e),this.mem.setUint8(t+64,0)}},"syscall/js.valueInvoke":t=>{t>>>=0;try{let e=i(t+8),l=u(t+16),a=Reflect.apply(e,void 0,l);t=this._inst.exports.getsp()>>>0,r(t+40,a),this.mem.setUint8(t+48,1)}catch(e){t=this._inst.exports.getsp()>>>0,r(t+40,e),this.mem.setUint8(t+48,0)}},"syscall/js.valueNew":t=>{t>>>=0;try{let e=i(t+8),l=u(t+16),a=Reflect.construct(e,l);t=this._inst.exports.getsp()>>>0,r(t+40,a),this.mem.setUint8(t+48,1)}catch(e){t=this._inst.exports.getsp()>>>0,r(t+40,e),this.mem.setUint8(t+48,0)}},"syscall/js.valueLength":t=>{t>>>=0,h(t+16,parseInt(i(t+8).length))},"syscall/js.valuePrepareString":t=>{t>>>=0;let e=y.encode(String(i(t+8)));r(t+16,e),h(t+24,e.length)},"syscall/js.valueLoadString":t=>{t>>>=0;let e=i(t+8);f(t+16).set(e)},"syscall/js.valueInstanceOf":t=>{t>>>=0,this.mem.setUint8(t+24,i(t+8)instanceof i(t+16)?1:0)},"syscall/js.copyBytesToGo":t=>{t>>>=0;let e=f(t+8),l=i(t+32);if(!(l instanceof Uint8Array||l instanceof Uint8ClampedArray)){this.mem.setUint8(t+48,0);return}let a=l.subarray(0,e.length);e.set(a),h(t+40,a.length),this.mem.setUint8(t+48,1)},"syscall/js.copyBytesToJS":t=>{t>>>=0;let e=i(t+8),l=f(t+16);if(!(e instanceof Uint8Array||e instanceof Uint8ClampedArray)){this.mem.setUint8(t+48,0);return}let a=l.subarray(0,e.length);e.set(a),h(t+40,a.length),this.mem.setUint8(t+48,1)},debug:t=>{console.log(t)}}}}async run(h){if(!(h instanceof WebAssembly.Instance))throw new Error("Go.run: WebAssembly.Instance expected");this._inst=h,this.mem=new DataView(this._inst.exports.mem.buffer),this._values=[NaN,0,null,!0,!1,globalThis,this],this._goRefCounts=new Array(this._values.length).fill(1/0),this._ids=new Map([[0,1],[null,2],[!0,3],[!1,4],[globalThis,5],[this,6]]),this._idPool=[],this.exited=!1;let n=4096,s=m=>{let t=n,e=y.encode(m+"\0");return new Uint8Array(this.mem.buffer,n,e.length).set(e),n+=e.length,n%8!==0&&(n+=8-n%8),t},i=this.argv.length,r=[];this.argv.forEach(m=>{r.push(s(m))}),r.push(0),Object.keys(this.env).sort().forEach(m=>{r.push(s(`${m}=${this.env[m]}`))}),r.push(0);let u=n;if(r.forEach(m=>{this.mem.setUint32(n,m,!0),this.mem.setUint32(n+4,0,!0),n+=8}),n>=12288)throw new Error("total length of command line and environment variables exceeds limit");this._inst.exports.run(i,u),this.exited&&this._resolveExitPromise(),await this._exitPromise}_resume(){if(this.exited)throw new Error("Go program has already exited");this._inst.exports.resume(),this.exited&&this._resolveExitPromise()}_makeFuncWrapper(h){let n=this;return function(){let s={id:h,this:this,args:arguments};return n._pendingEvent=s,n._resume(),s.result}}}})();w.exports={globalThisCopy:g}});export default v();