@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.
- package/dist/cjs/index.js +523 -3
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/cjs/workers/worker.js +904 -18
- package/dist/cjs/workers/worker.js.br +0 -0
- package/dist/cjs/workers/worker.js.gz +0 -0
- package/dist/esm/index.js +468 -4
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
- package/dist/esm/workers/chunk-ILICZWQV.js +36 -0
- package/dist/esm/workers/chunk-ILICZWQV.js.br +0 -0
- package/dist/esm/workers/chunk-ILICZWQV.js.gz +0 -0
- package/dist/esm/{wasm/wasm_exec.js → workers/wasm_exec-CFNSOXDO.js} +74 -68
- 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 +329 -37
- package/dist/esm/workers/worker.js.br +0 -0
- package/dist/esm/workers/worker.js.gz +0 -0
- package/dist/types/ParaServer.d.ts +2 -5
- package/dist/types/workers/worker.d.ts +1 -1
- package/package.json +4 -4
- package/dist/cjs/ParaServer.js +0 -91
- package/dist/cjs/ServerLocalStorage.js +0 -48
- package/dist/cjs/ServerSessionStorage.js +0 -48
- package/dist/cjs/ServerUtils.js +0 -76
- package/dist/cjs/package.json +0 -3
- package/dist/cjs/wallet/keygen.js +0 -227
- package/dist/cjs/wallet/privateKey.js +0 -86
- package/dist/cjs/wallet/signing.js +0 -172
- package/dist/cjs/wasm/wasm_exec.js +0 -589
- package/dist/cjs/workers/walletUtils.js +0 -367
- package/dist/cjs/workers/workerWrapper.js +0 -88
- package/dist/esm/ParaServer.js +0 -37
- package/dist/esm/ServerLocalStorage.js +0 -26
- package/dist/esm/ServerSessionStorage.js +0 -26
- package/dist/esm/ServerUtils.js +0 -54
- package/dist/esm/chunk-FTA5RKYX.js +0 -8
- package/dist/esm/package.json +0 -6
- package/dist/esm/wallet/keygen.js +0 -160
- package/dist/esm/wallet/privateKey.js +0 -32
- package/dist/esm/wallet/signing.js +0 -109
- package/dist/esm/workers/walletUtils.js +0 -290
- package/dist/esm/workers/workerWrapper.js +0 -44
|
@@ -1,33 +1,325 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
__async,
|
|
3
|
+
__require
|
|
4
|
+
} from "./chunk-ILICZWQV.js";
|
|
5
|
+
|
|
6
|
+
// src/workers/worker.ts
|
|
21
7
|
import axios from "axios";
|
|
22
8
|
import {
|
|
23
9
|
getPortalBaseURL,
|
|
24
10
|
initClient,
|
|
25
11
|
mpcComputationClient,
|
|
26
12
|
paraVersion,
|
|
27
|
-
WalletType
|
|
13
|
+
WalletType as WalletType2
|
|
28
14
|
} from "@getpara/core-sdk";
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
|
|
16
|
+
// src/workers/walletUtils.ts
|
|
17
|
+
import { getBaseMPCNetworkUrl, WalletScheme, WalletType } from "@getpara/core-sdk";
|
|
18
|
+
var configCGGMPBase = (serverUrl, walletId, id) => `{"ServerUrl":"${serverUrl}", "WalletId": "${walletId}", "Id":"${id}", "Ids":["USER","CAPSULE"], "Threshold":1}`;
|
|
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
|
+
}
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// src/workers/worker.ts
|
|
322
|
+
var rawWasm;
|
|
31
323
|
function requestWasmWithRetries(ctx, retries = 3) {
|
|
32
324
|
return __async(this, null, function* () {
|
|
33
325
|
for (let i = 0; i < retries; i++) {
|
|
@@ -43,8 +335,8 @@ function requestWasmWithRetries(ctx, retries = 3) {
|
|
|
43
335
|
}
|
|
44
336
|
function loadWasm(ctx) {
|
|
45
337
|
return __async(this, null, function* () {
|
|
46
|
-
yield import("
|
|
47
|
-
global.WebSocket =
|
|
338
|
+
yield import("./wasm_exec-CFNSOXDO.js");
|
|
339
|
+
global.WebSocket = __require("ws");
|
|
48
340
|
const goWasm = new global.Go();
|
|
49
341
|
if (!rawWasm) {
|
|
50
342
|
rawWasm = (yield requestWasmWithRetries(ctx)).data;
|
|
@@ -59,46 +351,46 @@ function executeMessage(ctx, message) {
|
|
|
59
351
|
const { functionType, params } = message;
|
|
60
352
|
switch (functionType) {
|
|
61
353
|
case "KEYGEN": {
|
|
62
|
-
const { userId, secretKey, type =
|
|
63
|
-
return
|
|
354
|
+
const { userId, secretKey, type = WalletType2.EVM } = params;
|
|
355
|
+
return keygen(ctx, userId, type, secretKey);
|
|
64
356
|
}
|
|
65
357
|
case "SIGN_TRANSACTION": {
|
|
66
358
|
const { share, walletId, userId, tx, chainId } = params;
|
|
67
|
-
return
|
|
359
|
+
return signTransaction(ctx, share, walletId, userId, tx, chainId);
|
|
68
360
|
}
|
|
69
361
|
case "SEND_TRANSACTION": {
|
|
70
362
|
const { share, walletId, userId, tx, chainId } = params;
|
|
71
|
-
return
|
|
363
|
+
return sendTransaction(ctx, share, walletId, userId, tx, chainId);
|
|
72
364
|
}
|
|
73
365
|
case "SIGN_MESSAGE": {
|
|
74
366
|
const { share, walletId, userId, message: message2 } = params;
|
|
75
|
-
return
|
|
367
|
+
return signMessage(ctx, share, walletId, userId, message2);
|
|
76
368
|
}
|
|
77
369
|
case "REFRESH": {
|
|
78
370
|
const { share, walletId, userId } = params;
|
|
79
|
-
return
|
|
371
|
+
return refresh(ctx, share, walletId, userId);
|
|
80
372
|
}
|
|
81
373
|
case "PREKEYGEN": {
|
|
82
|
-
const { email, partnerId, secretKey, type =
|
|
374
|
+
const { email, partnerId, secretKey, type = WalletType2.EVM } = params;
|
|
83
375
|
let { pregenIdentifier, pregenIdentifierType } = params;
|
|
84
376
|
if (email !== "null" && email !== "undefined" && email !== "" && email != null) {
|
|
85
377
|
pregenIdentifier = email;
|
|
86
378
|
pregenIdentifierType = "EMAIL";
|
|
87
379
|
}
|
|
88
|
-
const keygenRes = yield
|
|
380
|
+
const keygenRes = yield preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey);
|
|
89
381
|
return keygenRes;
|
|
90
382
|
}
|
|
91
383
|
case "GET_PRIVATE_KEY": {
|
|
92
384
|
const { share, walletId, userId } = params;
|
|
93
|
-
return yield
|
|
385
|
+
return yield getPrivateKey(ctx, share, walletId, userId);
|
|
94
386
|
}
|
|
95
387
|
case "ED25519_KEYGEN": {
|
|
96
388
|
const { userId } = params;
|
|
97
|
-
return
|
|
389
|
+
return ed25519Keygen(ctx, userId);
|
|
98
390
|
}
|
|
99
391
|
case "ED25519_SIGN": {
|
|
100
392
|
const { share, walletId, userId, base64Bytes } = params;
|
|
101
|
-
return
|
|
393
|
+
return ed25519Sign(ctx, share, userId, walletId, base64Bytes);
|
|
102
394
|
}
|
|
103
395
|
case "ED25519_PREKEYGEN": {
|
|
104
396
|
const { email } = params;
|
|
@@ -107,7 +399,7 @@ function executeMessage(ctx, message) {
|
|
|
107
399
|
pregenIdentifier = email;
|
|
108
400
|
pregenIdentifierType = "EMAIL";
|
|
109
401
|
}
|
|
110
|
-
return
|
|
402
|
+
return ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType);
|
|
111
403
|
}
|
|
112
404
|
default: {
|
|
113
405
|
throw new Error(`functionType: ${functionType} not supported`);
|
|
Binary file
|
|
Binary file
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ParaCore, { PlatformUtils, ConstructorOpts, Environment,
|
|
1
|
+
import ParaCore, { PlatformUtils, ConstructorOpts, Environment, CoreMethodParams, CoreMethodResponse } from '@getpara/core-sdk';
|
|
2
2
|
export declare class Para extends ParaCore {
|
|
3
3
|
constructor(env: Environment, apiKey?: string, opts?: ConstructorOpts);
|
|
4
4
|
protected getPlatformUtils(): PlatformUtils;
|
|
@@ -13,8 +13,5 @@ export declare class Para extends ParaCore {
|
|
|
13
13
|
* @param {TPregenIdentifierType} opts.pregenIdentifierType - the type of the identifier.
|
|
14
14
|
* @returns {Promise<string | undefined>} A promise that rejects with an error.
|
|
15
15
|
*/
|
|
16
|
-
claimPregenWallets(
|
|
17
|
-
pregenIdentifier?: string;
|
|
18
|
-
pregenIdentifierType?: TPregenIdentifierType;
|
|
19
|
-
}): Promise<string | undefined>;
|
|
16
|
+
claimPregenWallets(_: CoreMethodParams<'claimPregenWallets'>): CoreMethodResponse<'claimPregenWallets'>;
|
|
20
17
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/server-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.3",
|
|
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": "
|
|
13
|
-
"@getpara/user-management-client": "
|
|
12
|
+
"@getpara/core-sdk": "2.0.0-alpha.3",
|
|
13
|
+
"@getpara/user-management-client": "2.0.0-alpha.3",
|
|
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": "
|
|
34
|
+
"gitHead": "77a1e04b06258842ca9c81e3db2a2b0092517659"
|
|
35
35
|
}
|
package/dist/cjs/ParaServer.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var __async = (__this, __arguments, generator) => {
|
|
29
|
-
return new Promise((resolve, reject) => {
|
|
30
|
-
var fulfilled = (value) => {
|
|
31
|
-
try {
|
|
32
|
-
step(generator.next(value));
|
|
33
|
-
} catch (e) {
|
|
34
|
-
reject(e);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
var rejected = (value) => {
|
|
38
|
-
try {
|
|
39
|
-
step(generator.throw(value));
|
|
40
|
-
} catch (e) {
|
|
41
|
-
reject(e);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
45
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
var ParaServer_exports = {};
|
|
49
|
-
__export(ParaServer_exports, {
|
|
50
|
-
Para: () => Para
|
|
51
|
-
});
|
|
52
|
-
module.exports = __toCommonJS(ParaServer_exports);
|
|
53
|
-
var import_core_sdk = __toESM(require("@getpara/core-sdk"));
|
|
54
|
-
var Sentry = __toESM(require("@sentry/node"));
|
|
55
|
-
var import_ServerUtils = require("./ServerUtils.js");
|
|
56
|
-
class Para extends import_core_sdk.default {
|
|
57
|
-
constructor(env, apiKey, opts) {
|
|
58
|
-
super(env, apiKey, opts);
|
|
59
|
-
if (env !== import_core_sdk.Environment.PROD && env !== import_core_sdk.Environment.DEV) {
|
|
60
|
-
Sentry.init({
|
|
61
|
-
environment: env.toLowerCase(),
|
|
62
|
-
dsn: "https://2a26842d951255c2721fde5c1dd2b252@o4504568036720640.ingest.us.sentry.io/4508850906791936"
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
getPlatformUtils() {
|
|
67
|
-
return new import_ServerUtils.ServerUtils();
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Claims a pregenerated wallet.
|
|
71
|
-
*
|
|
72
|
-
* NOTE: This function is only available on the client side.
|
|
73
|
-
* When called from the server SDK, it throws an error.
|
|
74
|
-
*
|
|
75
|
-
* @param {Object} opts the options object.
|
|
76
|
-
* @param {string} opts.pregenIdentifier - the identifier of the user claiming the wallet.
|
|
77
|
-
* @param {TPregenIdentifierType} opts.pregenIdentifierType - the type of the identifier.
|
|
78
|
-
* @returns {Promise<string | undefined>} A promise that rejects with an error.
|
|
79
|
-
*/
|
|
80
|
-
claimPregenWallets() {
|
|
81
|
-
return __async(this, arguments, function* ({} = {}) {
|
|
82
|
-
throw new Error(
|
|
83
|
-
"claimPregenWallets is not available in the server SDK. This function is only supported on the client side. Please ensure you are using the client SDK to call this method."
|
|
84
|
-
);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
-
0 && (module.exports = {
|
|
90
|
-
Para
|
|
91
|
-
});
|
|
@@ -1,48 +0,0 @@
|
|
|
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 ServerLocalStorage_exports = {};
|
|
19
|
-
__export(ServerLocalStorage_exports, {
|
|
20
|
-
ServerLocalStorage: () => ServerLocalStorage
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(ServerLocalStorage_exports);
|
|
23
|
-
class ServerLocalStorage {
|
|
24
|
-
constructor() {
|
|
25
|
-
this.localStorage = {};
|
|
26
|
-
this.get = (key) => {
|
|
27
|
-
return this.localStorage[key] || null;
|
|
28
|
-
};
|
|
29
|
-
this.set = (key, value) => {
|
|
30
|
-
this.localStorage[key] = value;
|
|
31
|
-
};
|
|
32
|
-
this.removeItem = (key) => {
|
|
33
|
-
delete this.localStorage[key];
|
|
34
|
-
};
|
|
35
|
-
this.clear = (prefix) => {
|
|
36
|
-
const keys = Object.keys(this.localStorage);
|
|
37
|
-
for (let key in keys) {
|
|
38
|
-
if (key && key.startsWith(prefix)) {
|
|
39
|
-
this.removeItem(key);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
-
0 && (module.exports = {
|
|
47
|
-
ServerLocalStorage
|
|
48
|
-
});
|
|
@@ -1,48 +0,0 @@
|
|
|
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 ServerSessionStorage_exports = {};
|
|
19
|
-
__export(ServerSessionStorage_exports, {
|
|
20
|
-
ServerSessionStorage: () => ServerSessionStorage
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(ServerSessionStorage_exports);
|
|
23
|
-
class ServerSessionStorage {
|
|
24
|
-
constructor() {
|
|
25
|
-
this.sessionStorage = {};
|
|
26
|
-
this.get = (key) => {
|
|
27
|
-
return this.sessionStorage[key] || null;
|
|
28
|
-
};
|
|
29
|
-
this.set = (key, value) => {
|
|
30
|
-
this.sessionStorage[key] = value;
|
|
31
|
-
};
|
|
32
|
-
this.removeItem = (key) => {
|
|
33
|
-
delete this.sessionStorage[key];
|
|
34
|
-
};
|
|
35
|
-
this.clear = (prefix) => {
|
|
36
|
-
const keys = Object.keys(this.sessionStorage);
|
|
37
|
-
for (let key in keys) {
|
|
38
|
-
if (key && key.startsWith(prefix)) {
|
|
39
|
-
this.removeItem(key);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
-
0 && (module.exports = {
|
|
47
|
-
ServerSessionStorage
|
|
48
|
-
});
|