@getpara/server-sdk 1.9.0 → 1.10.0
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/ServerLocalStorage.js +1 -1
- package/dist/cjs/ServerSessionStorage.js +1 -1
- package/dist/cjs/ServerUtils.js +1 -1
- package/dist/cjs/wallet/keygen.js +11 -9
- package/dist/cjs/wallet/privateKey.js +1 -1
- package/dist/cjs/workers/walletUtils.js +6 -6
- package/dist/cjs/workers/worker.js +8 -4
- package/dist/esm/ServerLocalStorage.js +1 -1
- package/dist/esm/ServerSessionStorage.js +1 -1
- package/dist/esm/ServerUtils.js +1 -1
- package/dist/esm/wallet/keygen.js +9 -9
- package/dist/esm/wallet/privateKey.js +1 -1
- package/dist/esm/workers/walletUtils.js +6 -6
- package/dist/esm/workers/worker.js +6 -3
- package/dist/types/wallet/keygen.d.ts +3 -1
- package/dist/types/workers/worker.d.ts +2 -1
- package/package.json +4 -4
package/dist/cjs/ServerUtils.js
CHANGED
|
@@ -37,7 +37,7 @@ class ServerUtils {
|
|
|
37
37
|
return (0, import_privateKey.getPrivateKey)(ctx, userId, walletId, share, sessionCookie);
|
|
38
38
|
}
|
|
39
39
|
keygen(ctx, userId, type, secretKey, sessionCookie, emailProps) {
|
|
40
|
-
return (0, import_keygen.keygen)(ctx, userId, type, secretKey,
|
|
40
|
+
return (0, import_keygen.keygen)(ctx, userId, type, secretKey, sessionCookie, emailProps);
|
|
41
41
|
}
|
|
42
42
|
refresh(_ctx, _sessionCookie, _userId, _walletId, _share, _oldPartnerId, _newPartnerId) {
|
|
43
43
|
throw new Error("Refresh function is not implemented in the ServerUtils class.");
|
|
@@ -49,6 +49,8 @@ var keygen_exports = {};
|
|
|
49
49
|
__export(keygen_exports, {
|
|
50
50
|
ed25519Keygen: () => ed25519Keygen,
|
|
51
51
|
ed25519PreKeygen: () => ed25519PreKeygen,
|
|
52
|
+
isKeygenComplete: () => isKeygenComplete,
|
|
53
|
+
isPreKeygenComplete: () => isPreKeygenComplete,
|
|
52
54
|
keygen: () => keygen,
|
|
53
55
|
preKeygen: () => preKeygen
|
|
54
56
|
});
|
|
@@ -60,7 +62,7 @@ function isKeygenComplete(ctx, userId, walletId) {
|
|
|
60
62
|
return __async(this, null, function* () {
|
|
61
63
|
const wallets = yield ctx.client.getWallets(userId);
|
|
62
64
|
const wallet = wallets.data.wallets.find((w) => w.id === walletId);
|
|
63
|
-
return !!wallet.address;
|
|
65
|
+
return !!(wallet == null ? void 0 : wallet.address);
|
|
64
66
|
});
|
|
65
67
|
}
|
|
66
68
|
function isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, walletId) {
|
|
@@ -70,7 +72,7 @@ function isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, wallet
|
|
|
70
72
|
return !!(wallet == null ? void 0 : wallet.address);
|
|
71
73
|
});
|
|
72
74
|
}
|
|
73
|
-
function keygen(ctx, userId, type, secretKey,
|
|
75
|
+
function keygen(ctx, userId, type, secretKey, sessionCookie, _emailProps = {}) {
|
|
74
76
|
return new Promise((resolve) => __async(this, null, function* () {
|
|
75
77
|
const workId = uuid.v4();
|
|
76
78
|
const worker = yield (0, import_workerWrapper.setupWorker)(
|
|
@@ -79,13 +81,11 @@ function keygen(ctx, userId, type, secretKey, skipDistribute = false, sessionCoo
|
|
|
79
81
|
yield (0, import_core_sdk.waitUntilTrue)(() => __async(this, null, function* () {
|
|
80
82
|
return isKeygenComplete(ctx, userId, res.walletId);
|
|
81
83
|
}), 15e3, 1e3);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
});
|
|
88
|
-
}
|
|
84
|
+
resolve({
|
|
85
|
+
signer: res.signer,
|
|
86
|
+
walletId: res.walletId,
|
|
87
|
+
recoveryShare: null
|
|
88
|
+
});
|
|
89
89
|
}),
|
|
90
90
|
workId
|
|
91
91
|
);
|
|
@@ -222,6 +222,8 @@ function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCo
|
|
|
222
222
|
0 && (module.exports = {
|
|
223
223
|
ed25519Keygen,
|
|
224
224
|
ed25519PreKeygen,
|
|
225
|
+
isKeygenComplete,
|
|
226
|
+
isPreKeygenComplete,
|
|
225
227
|
keygen,
|
|
226
228
|
preKeygen
|
|
227
229
|
});
|
|
@@ -227,7 +227,7 @@ function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type,
|
|
|
227
227
|
);
|
|
228
228
|
return { signer: newSigner, walletId };
|
|
229
229
|
} catch (e) {
|
|
230
|
-
throw new Error(`error creating account of type ${type} with
|
|
230
|
+
throw new Error(`error creating account of type ${type} with walletId ${walletId}`);
|
|
231
231
|
}
|
|
232
232
|
});
|
|
233
233
|
}
|
|
@@ -243,7 +243,7 @@ function signMessage(ctx, share, walletId, userId, message) {
|
|
|
243
243
|
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
244
244
|
const signMessageFn = ctx.useDKLS ? global.dklsSignMessage : global.signMessage;
|
|
245
245
|
try {
|
|
246
|
-
return new Promise(
|
|
246
|
+
return yield new Promise(
|
|
247
247
|
(resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
|
|
248
248
|
if (err) {
|
|
249
249
|
reject(err);
|
|
@@ -270,7 +270,7 @@ function signTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
|
270
270
|
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
271
271
|
const signTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
|
|
272
272
|
try {
|
|
273
|
-
return new Promise(
|
|
273
|
+
return yield new Promise(
|
|
274
274
|
(resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
275
275
|
if (err) {
|
|
276
276
|
reject(err);
|
|
@@ -297,7 +297,7 @@ function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
|
297
297
|
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
298
298
|
const sendTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
|
|
299
299
|
try {
|
|
300
|
-
return new Promise(
|
|
300
|
+
return yield new Promise(
|
|
301
301
|
(resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
302
302
|
if (err) {
|
|
303
303
|
reject(err);
|
|
@@ -318,7 +318,7 @@ function refresh(ctx, share, walletId, userId) {
|
|
|
318
318
|
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
319
319
|
const refreshFn = ctx.useDKLS ? global.dklsRefresh : global.refresh;
|
|
320
320
|
try {
|
|
321
|
-
return new Promise(
|
|
321
|
+
return yield new Promise(
|
|
322
322
|
(resolve, reject) => refreshFn(share, serverUrl, protocolId, (err, result) => {
|
|
323
323
|
if (err) {
|
|
324
324
|
reject(err);
|
|
@@ -339,7 +339,7 @@ function getPrivateKey(ctx, share, walletId, userId) {
|
|
|
339
339
|
return "";
|
|
340
340
|
}
|
|
341
341
|
try {
|
|
342
|
-
return new Promise(
|
|
342
|
+
return yield new Promise(
|
|
343
343
|
(resolve, reject) => global.getPrivateKey(share, paraShare, (err, result) => {
|
|
344
344
|
if (err) {
|
|
345
345
|
reject(err);
|
|
@@ -47,7 +47,8 @@ var __async = (__this, __arguments, generator) => {
|
|
|
47
47
|
};
|
|
48
48
|
var worker_exports = {};
|
|
49
49
|
__export(worker_exports, {
|
|
50
|
-
handleMessage: () => handleMessage
|
|
50
|
+
handleMessage: () => handleMessage,
|
|
51
|
+
requestWasmWithRetries: () => requestWasmWithRetries
|
|
51
52
|
});
|
|
52
53
|
module.exports = __toCommonJS(worker_exports);
|
|
53
54
|
var import_axios = __toESM(require("axios"));
|
|
@@ -102,7 +103,8 @@ function executeMessage(ctx, message) {
|
|
|
102
103
|
}
|
|
103
104
|
case "REFRESH": {
|
|
104
105
|
const { share, walletId, userId } = params;
|
|
105
|
-
|
|
106
|
+
const signer = yield walletUtils.refresh(ctx, share, walletId, userId);
|
|
107
|
+
return { signer };
|
|
106
108
|
}
|
|
107
109
|
case "PREKEYGEN": {
|
|
108
110
|
const { email, partnerId, secretKey, type = import_core_sdk.WalletType.EVM } = params;
|
|
@@ -116,7 +118,8 @@ function executeMessage(ctx, message) {
|
|
|
116
118
|
}
|
|
117
119
|
case "GET_PRIVATE_KEY": {
|
|
118
120
|
const { share, walletId, userId } = params;
|
|
119
|
-
|
|
121
|
+
const privateKey = yield walletUtils.getPrivateKey(ctx, share, walletId, userId);
|
|
122
|
+
return { privateKey };
|
|
120
123
|
}
|
|
121
124
|
case "ED25519_KEYGEN": {
|
|
122
125
|
const { userId } = params;
|
|
@@ -174,5 +177,6 @@ function handleMessage(e) {
|
|
|
174
177
|
}
|
|
175
178
|
// Annotate the CommonJS export names for ESM import in node:
|
|
176
179
|
0 && (module.exports = {
|
|
177
|
-
handleMessage
|
|
180
|
+
handleMessage,
|
|
181
|
+
requestWasmWithRetries
|
|
178
182
|
});
|
package/dist/esm/ServerUtils.js
CHANGED
|
@@ -16,7 +16,7 @@ class ServerUtils {
|
|
|
16
16
|
return getPrivateKey(ctx, userId, walletId, share, sessionCookie);
|
|
17
17
|
}
|
|
18
18
|
keygen(ctx, userId, type, secretKey, sessionCookie, emailProps) {
|
|
19
|
-
return keygen(ctx, userId, type, secretKey,
|
|
19
|
+
return keygen(ctx, userId, type, secretKey, sessionCookie, emailProps);
|
|
20
20
|
}
|
|
21
21
|
refresh(_ctx, _sessionCookie, _userId, _walletId, _share, _oldPartnerId, _newPartnerId) {
|
|
22
22
|
throw new Error("Refresh function is not implemented in the ServerUtils class.");
|
|
@@ -5,27 +5,25 @@ import { setupWorker } from "../workers/workerWrapper.js";
|
|
|
5
5
|
async function isKeygenComplete(ctx, userId, walletId) {
|
|
6
6
|
const wallets = await ctx.client.getWallets(userId);
|
|
7
7
|
const wallet = wallets.data.wallets.find((w) => w.id === walletId);
|
|
8
|
-
return !!wallet
|
|
8
|
+
return !!wallet?.address;
|
|
9
9
|
}
|
|
10
10
|
async function isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, walletId) {
|
|
11
11
|
const wallets = await ctx.client.getPregenWallets({ [pregenIdentifierType]: [pregenIdentifier] });
|
|
12
12
|
const wallet = wallets.wallets.find((w) => w.id === walletId);
|
|
13
13
|
return !!wallet?.address;
|
|
14
14
|
}
|
|
15
|
-
function keygen(ctx, userId, type, secretKey,
|
|
15
|
+
function keygen(ctx, userId, type, secretKey, sessionCookie, _emailProps = {}) {
|
|
16
16
|
return new Promise(async (resolve) => {
|
|
17
17
|
const workId = uuid.v4();
|
|
18
18
|
const worker = await setupWorker(
|
|
19
19
|
ctx,
|
|
20
20
|
async (res) => {
|
|
21
21
|
await waitUntilTrue(async () => isKeygenComplete(ctx, userId, res.walletId), 15e3, 1e3);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
28
|
-
}
|
|
22
|
+
resolve({
|
|
23
|
+
signer: res.signer,
|
|
24
|
+
walletId: res.walletId,
|
|
25
|
+
recoveryShare: null
|
|
26
|
+
});
|
|
29
27
|
},
|
|
30
28
|
workId
|
|
31
29
|
);
|
|
@@ -155,6 +153,8 @@ function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCo
|
|
|
155
153
|
export {
|
|
156
154
|
ed25519Keygen,
|
|
157
155
|
ed25519PreKeygen,
|
|
156
|
+
isKeygenComplete,
|
|
157
|
+
isPreKeygenComplete,
|
|
158
158
|
keygen,
|
|
159
159
|
preKeygen
|
|
160
160
|
};
|
|
@@ -162,7 +162,7 @@ async function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType,
|
|
|
162
162
|
);
|
|
163
163
|
return { signer: newSigner, walletId };
|
|
164
164
|
} catch (e) {
|
|
165
|
-
throw new Error(`error creating account of type ${type} with
|
|
165
|
+
throw new Error(`error creating account of type ${type} with walletId ${walletId}`);
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
async function signMessage(ctx, share, walletId, userId, message) {
|
|
@@ -176,7 +176,7 @@ async function signMessage(ctx, share, walletId, userId, message) {
|
|
|
176
176
|
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
177
177
|
const signMessageFn = ctx.useDKLS ? global.dklsSignMessage : global.signMessage;
|
|
178
178
|
try {
|
|
179
|
-
return new Promise(
|
|
179
|
+
return await new Promise(
|
|
180
180
|
(resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
|
|
181
181
|
if (err) {
|
|
182
182
|
reject(err);
|
|
@@ -201,7 +201,7 @@ async function signTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
|
201
201
|
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
202
202
|
const signTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
|
|
203
203
|
try {
|
|
204
|
-
return new Promise(
|
|
204
|
+
return await new Promise(
|
|
205
205
|
(resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
206
206
|
if (err) {
|
|
207
207
|
reject(err);
|
|
@@ -226,7 +226,7 @@ async function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
|
226
226
|
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
227
227
|
const sendTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
|
|
228
228
|
try {
|
|
229
|
-
return new Promise(
|
|
229
|
+
return await new Promise(
|
|
230
230
|
(resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
231
231
|
if (err) {
|
|
232
232
|
reject(err);
|
|
@@ -245,7 +245,7 @@ async function refresh(ctx, share, walletId, userId) {
|
|
|
245
245
|
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
246
246
|
const refreshFn = ctx.useDKLS ? global.dklsRefresh : global.refresh;
|
|
247
247
|
try {
|
|
248
|
-
return new Promise(
|
|
248
|
+
return await new Promise(
|
|
249
249
|
(resolve, reject) => refreshFn(share, serverUrl, protocolId, (err, result) => {
|
|
250
250
|
if (err) {
|
|
251
251
|
reject(err);
|
|
@@ -264,7 +264,7 @@ async function getPrivateKey(ctx, share, walletId, userId) {
|
|
|
264
264
|
return "";
|
|
265
265
|
}
|
|
266
266
|
try {
|
|
267
|
-
return new Promise(
|
|
267
|
+
return await new Promise(
|
|
268
268
|
(resolve, reject) => global.getPrivateKey(share, paraShare, (err, result) => {
|
|
269
269
|
if (err) {
|
|
270
270
|
reject(err);
|
|
@@ -76,7 +76,8 @@ function executeMessage(ctx, message) {
|
|
|
76
76
|
}
|
|
77
77
|
case "REFRESH": {
|
|
78
78
|
const { share, walletId, userId } = params;
|
|
79
|
-
|
|
79
|
+
const signer = yield walletUtils.refresh(ctx, share, walletId, userId);
|
|
80
|
+
return { signer };
|
|
80
81
|
}
|
|
81
82
|
case "PREKEYGEN": {
|
|
82
83
|
const { email, partnerId, secretKey, type = WalletType.EVM } = params;
|
|
@@ -90,7 +91,8 @@ function executeMessage(ctx, message) {
|
|
|
90
91
|
}
|
|
91
92
|
case "GET_PRIVATE_KEY": {
|
|
92
93
|
const { share, walletId, userId } = params;
|
|
93
|
-
|
|
94
|
+
const privateKey = yield walletUtils.getPrivateKey(ctx, share, walletId, userId);
|
|
95
|
+
return { privateKey };
|
|
94
96
|
}
|
|
95
97
|
case "ED25519_KEYGEN": {
|
|
96
98
|
const { userId } = params;
|
|
@@ -147,5 +149,6 @@ function handleMessage(e) {
|
|
|
147
149
|
});
|
|
148
150
|
}
|
|
149
151
|
export {
|
|
150
|
-
handleMessage
|
|
152
|
+
handleMessage,
|
|
153
|
+
requestWasmWithRetries
|
|
151
154
|
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Ctx, TPregenIdentifierType } from '@getpara/core-sdk';
|
|
2
2
|
import { BackupKitEmailProps, WalletType } from '@getpara/user-management-client';
|
|
3
|
-
export declare function
|
|
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: WalletType, secretKey: string | null, sessionCookie?: string, _emailProps?: BackupKitEmailProps): Promise<{
|
|
4
6
|
signer: string;
|
|
5
7
|
walletId: string;
|
|
6
8
|
recoveryShare: string | null;
|
|
@@ -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": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
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.
|
|
13
|
-
"@getpara/user-management-client": "1.
|
|
12
|
+
"@getpara/core-sdk": "1.10.0",
|
|
13
|
+
"@getpara/user-management-client": "1.10.0",
|
|
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": "617cf0aa1307a96ec5e91d39e306e8a0b3b86b82"
|
|
35
35
|
}
|