@getpara/server-sdk 2.0.0-dev.0 → 2.0.0-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ParaServer.js +101 -0
- package/dist/cjs/ServerLocalStorage.js +48 -0
- package/dist/cjs/ServerSessionStorage.js +48 -0
- package/dist/cjs/ServerUtils.js +77 -0
- package/dist/cjs/index.js +3 -523
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/wallet/keygen.js +315 -0
- package/dist/cjs/wallet/privateKey.js +99 -0
- package/dist/cjs/wallet/signing.js +224 -0
- package/dist/cjs/wasm/wasm_exec.js +589 -0
- package/dist/cjs/workers/walletUtils.js +409 -0
- package/dist/cjs/workers/worker.js +62 -907
- package/dist/cjs/workers/workerWrapper.js +130 -0
- package/dist/esm/ParaServer.js +45 -0
- package/dist/esm/ServerLocalStorage.js +26 -0
- package/dist/esm/ServerSessionStorage.js +26 -0
- package/dist/esm/ServerUtils.js +55 -0
- package/dist/esm/chunk-FTA5RKYX.js +8 -0
- package/dist/esm/index.js +4 -466
- package/dist/esm/package.json +6 -0
- package/dist/esm/wallet/keygen.js +230 -0
- package/dist/esm/wallet/privateKey.js +45 -0
- package/dist/esm/wallet/signing.js +161 -0
- package/dist/esm/{workers/wasm_exec-CFNSOXDO.js → wasm/wasm_exec.js} +68 -74
- package/dist/esm/workers/walletUtils.js +314 -0
- package/dist/esm/workers/worker.js +78 -337
- package/dist/esm/workers/workerWrapper.js +85 -0
- package/dist/types/ParaServer.d.ts +4 -5
- package/dist/types/ServerUtils.d.ts +5 -6
- package/dist/types/wallet/keygen.d.ts +5 -3
- package/dist/types/workers/walletUtils.d.ts +4 -6
- package/dist/types/workers/worker.d.ts +10 -1
- package/dist/types/workers/workerWrapper.d.ts +2 -2
- package/package.json +20 -20
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/cjs/workers/worker.js.br +0 -0
- package/dist/cjs/workers/worker.js.gz +0 -0
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
- package/dist/esm/workers/chunk-ILICZWQV.js +0 -36
- package/dist/esm/workers/chunk-ILICZWQV.js.br +0 -0
- package/dist/esm/workers/chunk-ILICZWQV.js.gz +0 -0
- package/dist/esm/workers/wasm_exec-CFNSOXDO.js.br +0 -0
- package/dist/esm/workers/wasm_exec-CFNSOXDO.js.gz +0 -0
- package/dist/esm/workers/worker.js.br +0 -0
- package/dist/esm/workers/worker.js.gz +0 -0
|
@@ -0,0 +1,409 @@
|
|
|
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 walletUtils_exports = {};
|
|
49
|
+
__export(walletUtils_exports, {
|
|
50
|
+
ed25519Keygen: () => ed25519Keygen,
|
|
51
|
+
ed25519PreKeygen: () => ed25519PreKeygen,
|
|
52
|
+
ed25519Sign: () => ed25519Sign,
|
|
53
|
+
getPrivateKey: () => getPrivateKey,
|
|
54
|
+
keygen: () => keygen,
|
|
55
|
+
preKeygen: () => preKeygen,
|
|
56
|
+
refresh: () => refresh,
|
|
57
|
+
sendTransaction: () => sendTransaction,
|
|
58
|
+
signMessage: () => signMessage,
|
|
59
|
+
signTransaction: () => signTransaction
|
|
60
|
+
});
|
|
61
|
+
module.exports = __toCommonJS(walletUtils_exports);
|
|
62
|
+
var import_core_sdk = require("@getpara/core-sdk");
|
|
63
|
+
var uuid = __toESM(require("uuid"));
|
|
64
|
+
const configCGGMPBase = (serverUrl, walletId, id) => `{"ServerUrl":"${serverUrl}", "WalletId": "${walletId}", "Id":"${id}", "Ids":["USER","CAPSULE"], "Threshold":1}`;
|
|
65
|
+
const configDKLSBase = (walletId, id, disableWebSockets) => `{"walletId": "${walletId}", "id":"${id}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${disableWebSockets}}`;
|
|
66
|
+
function keygenRequest(ctx, userId, walletId, protocolId) {
|
|
67
|
+
return __async(this, null, function* () {
|
|
68
|
+
const { data } = yield ctx.mpcComputationClient.post("/wallets", {
|
|
69
|
+
userId,
|
|
70
|
+
walletId,
|
|
71
|
+
protocolId
|
|
72
|
+
});
|
|
73
|
+
return data;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function signMessageRequest(ctx, userId, walletId, protocolId, message, signer) {
|
|
77
|
+
return __async(this, null, function* () {
|
|
78
|
+
const { data } = yield ctx.mpcComputationClient.post(`/wallets/${walletId}/messages/sign`, {
|
|
79
|
+
userId,
|
|
80
|
+
protocolId,
|
|
81
|
+
message,
|
|
82
|
+
signer
|
|
83
|
+
});
|
|
84
|
+
return data;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function sendTransactionRequest(ctx, userId, walletId, protocolId, transaction, signer, chainId) {
|
|
88
|
+
return __async(this, null, function* () {
|
|
89
|
+
const { data } = yield ctx.mpcComputationClient.post(`/wallets/${walletId}/transactions/send`, {
|
|
90
|
+
userId,
|
|
91
|
+
protocolId,
|
|
92
|
+
transaction,
|
|
93
|
+
signer,
|
|
94
|
+
chainId
|
|
95
|
+
});
|
|
96
|
+
return data;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function ed25519Keygen(ctx, userId) {
|
|
100
|
+
return __async(this, null, function* () {
|
|
101
|
+
const { walletId, protocolId } = yield ctx.client.createWallet(userId, {
|
|
102
|
+
scheme: "ED25519",
|
|
103
|
+
type: "SOLANA"
|
|
104
|
+
});
|
|
105
|
+
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
106
|
+
try {
|
|
107
|
+
const newSigner = yield new Promise(
|
|
108
|
+
(resolve, reject) => global.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
|
|
109
|
+
if (err) {
|
|
110
|
+
reject(err);
|
|
111
|
+
}
|
|
112
|
+
resolve(result);
|
|
113
|
+
})
|
|
114
|
+
);
|
|
115
|
+
return { signer: newSigner, walletId };
|
|
116
|
+
} catch (e) {
|
|
117
|
+
throw new Error(`error creating account of type SOLANA with userId ${userId} and walletId ${walletId}`);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType) {
|
|
122
|
+
return __async(this, null, function* () {
|
|
123
|
+
const { walletId, protocolId } = yield ctx.client.createPregenWallet({
|
|
124
|
+
pregenIdentifier,
|
|
125
|
+
pregenIdentifierType,
|
|
126
|
+
scheme: "ED25519",
|
|
127
|
+
type: "SOLANA"
|
|
128
|
+
});
|
|
129
|
+
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
130
|
+
try {
|
|
131
|
+
const newSigner = yield new Promise(
|
|
132
|
+
(resolve, reject) => global.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
|
|
133
|
+
if (err) {
|
|
134
|
+
reject(err);
|
|
135
|
+
}
|
|
136
|
+
resolve(result);
|
|
137
|
+
})
|
|
138
|
+
);
|
|
139
|
+
return { signer: newSigner, walletId };
|
|
140
|
+
} catch (e) {
|
|
141
|
+
throw new Error(`error creating account of type SOLANA with walletId ${walletId}`);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
|
|
146
|
+
return __async(this, null, function* () {
|
|
147
|
+
const protocolId = uuid.v4();
|
|
148
|
+
const preSignMessageRes = ctx.client.preSignMessage(userId, walletId, base64Bytes, "ED25519", void 0, protocolId);
|
|
149
|
+
const signRes = function() {
|
|
150
|
+
return __async(this, null, function* () {
|
|
151
|
+
try {
|
|
152
|
+
const base64Sig = yield new Promise(
|
|
153
|
+
(resolve, reject) => global.ed25519Sign(share, protocolId, base64Bytes, (err, result) => {
|
|
154
|
+
if (err) {
|
|
155
|
+
reject(err);
|
|
156
|
+
}
|
|
157
|
+
resolve(result);
|
|
158
|
+
})
|
|
159
|
+
);
|
|
160
|
+
return { signature: base64Sig };
|
|
161
|
+
} catch (e) {
|
|
162
|
+
throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}();
|
|
166
|
+
const { pendingTransactionId } = yield preSignMessageRes;
|
|
167
|
+
if (pendingTransactionId) {
|
|
168
|
+
return { pendingTransactionId };
|
|
169
|
+
}
|
|
170
|
+
return yield signRes;
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
function keygen(ctx, userId, type, secretKey) {
|
|
174
|
+
return __async(this, null, function* () {
|
|
175
|
+
const { walletId, protocolId } = yield ctx.client.createWallet(userId, {
|
|
176
|
+
useTwoSigners: true,
|
|
177
|
+
scheme: ctx.useDKLS ? "DKLS" : "CGGMP",
|
|
178
|
+
type,
|
|
179
|
+
cosmosPrefix: type === "COSMOS" ? ctx.cosmosPrefix : void 0
|
|
180
|
+
});
|
|
181
|
+
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
182
|
+
return {
|
|
183
|
+
signer: (yield keygenRequest(ctx, userId, walletId, protocolId)).signer,
|
|
184
|
+
walletId
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
188
|
+
const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
|
|
189
|
+
const createAccountFn = ctx.useDKLS ? global.dklsCreateAccount : global.createAccountV2;
|
|
190
|
+
try {
|
|
191
|
+
const newSigner = yield new Promise(
|
|
192
|
+
(resolve, reject) => createAccountFn(
|
|
193
|
+
signerConfigUser,
|
|
194
|
+
serverUrl,
|
|
195
|
+
protocolId,
|
|
196
|
+
secretKey,
|
|
197
|
+
() => {
|
|
198
|
+
},
|
|
199
|
+
// no-op for deprecated callback to update progress percentage
|
|
200
|
+
(err, result) => {
|
|
201
|
+
if (err) {
|
|
202
|
+
reject(err);
|
|
203
|
+
}
|
|
204
|
+
resolve(result);
|
|
205
|
+
}
|
|
206
|
+
)
|
|
207
|
+
);
|
|
208
|
+
return { signer: newSigner, walletId };
|
|
209
|
+
} catch (e) {
|
|
210
|
+
throw new Error(`error creating account of type ${type} with userId ${userId} and walletId ${walletId}`);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
function preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey) {
|
|
215
|
+
return __async(this, null, function* () {
|
|
216
|
+
const { walletId, protocolId } = yield ctx.client.createPregenWallet({
|
|
217
|
+
pregenIdentifier,
|
|
218
|
+
pregenIdentifierType,
|
|
219
|
+
type,
|
|
220
|
+
cosmosPrefix: type === "COSMOS" ? ctx.cosmosPrefix : void 0
|
|
221
|
+
});
|
|
222
|
+
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
223
|
+
return {
|
|
224
|
+
signer: (yield keygenRequest(ctx, partnerId, walletId, protocolId)).signer,
|
|
225
|
+
walletId
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
229
|
+
const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
|
|
230
|
+
const createAccountFn = ctx.useDKLS ? global.dklsCreateAccount : global.createAccountV2;
|
|
231
|
+
try {
|
|
232
|
+
const newSigner = yield new Promise(
|
|
233
|
+
(resolve, reject) => createAccountFn(
|
|
234
|
+
signerConfigUser,
|
|
235
|
+
serverUrl,
|
|
236
|
+
protocolId,
|
|
237
|
+
secretKey,
|
|
238
|
+
() => {
|
|
239
|
+
},
|
|
240
|
+
// no-op for deprecated callback to update progress percentage
|
|
241
|
+
(err, result) => {
|
|
242
|
+
if (err) {
|
|
243
|
+
reject(err);
|
|
244
|
+
}
|
|
245
|
+
resolve(result);
|
|
246
|
+
}
|
|
247
|
+
)
|
|
248
|
+
);
|
|
249
|
+
return { signer: newSigner, walletId };
|
|
250
|
+
} catch (e) {
|
|
251
|
+
throw new Error(`error creating account of type ${type} with walletId ${walletId}`);
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
function signMessage(ctx, share, walletId, userId, message) {
|
|
256
|
+
return __async(this, null, function* () {
|
|
257
|
+
const protocolId = uuid.v4();
|
|
258
|
+
const preSignMessageRes = ctx.client.preSignMessage(userId, walletId, message, null, null, protocolId);
|
|
259
|
+
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
260
|
+
return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
|
|
261
|
+
}
|
|
262
|
+
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
263
|
+
const signMessageFn = ctx.useDKLS ? global.dklsSignMessage : global.signMessage;
|
|
264
|
+
const signMessageRes = function() {
|
|
265
|
+
return __async(this, null, function* () {
|
|
266
|
+
try {
|
|
267
|
+
return yield new Promise(
|
|
268
|
+
(resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
|
|
269
|
+
if (err) {
|
|
270
|
+
reject(err);
|
|
271
|
+
}
|
|
272
|
+
resolve({ signature: result });
|
|
273
|
+
})
|
|
274
|
+
);
|
|
275
|
+
} catch (e) {
|
|
276
|
+
throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
}();
|
|
280
|
+
const { pendingTransactionId } = yield preSignMessageRes;
|
|
281
|
+
if (pendingTransactionId) {
|
|
282
|
+
return { pendingTransactionId };
|
|
283
|
+
}
|
|
284
|
+
return yield signMessageRes;
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
function signTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
288
|
+
return __async(this, null, function* () {
|
|
289
|
+
const protocolId = uuid.v4();
|
|
290
|
+
const signTransactionRes = ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId, protocolId });
|
|
291
|
+
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
292
|
+
return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
|
|
293
|
+
}
|
|
294
|
+
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
295
|
+
const signTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
|
|
296
|
+
const signTxRes = function() {
|
|
297
|
+
return __async(this, null, function* () {
|
|
298
|
+
try {
|
|
299
|
+
return yield new Promise(
|
|
300
|
+
(resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
301
|
+
if (err) {
|
|
302
|
+
reject(err);
|
|
303
|
+
}
|
|
304
|
+
resolve({ signature: result });
|
|
305
|
+
})
|
|
306
|
+
);
|
|
307
|
+
} catch (e) {
|
|
308
|
+
throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
}();
|
|
312
|
+
const {
|
|
313
|
+
data: { pendingTransactionId }
|
|
314
|
+
} = yield signTransactionRes;
|
|
315
|
+
if (pendingTransactionId) {
|
|
316
|
+
return { pendingTransactionId };
|
|
317
|
+
}
|
|
318
|
+
return yield signTxRes;
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
322
|
+
return __async(this, null, function* () {
|
|
323
|
+
const protocolId = uuid.v4();
|
|
324
|
+
const sendTransactionRes = ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId, protocolId });
|
|
325
|
+
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
326
|
+
return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
|
|
327
|
+
}
|
|
328
|
+
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
329
|
+
const sendTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
|
|
330
|
+
const sendTxRes = function() {
|
|
331
|
+
return __async(this, null, function* () {
|
|
332
|
+
try {
|
|
333
|
+
return yield new Promise(
|
|
334
|
+
(resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
335
|
+
if (err) {
|
|
336
|
+
reject(err);
|
|
337
|
+
}
|
|
338
|
+
resolve({ signature: result });
|
|
339
|
+
})
|
|
340
|
+
);
|
|
341
|
+
} catch (e) {
|
|
342
|
+
throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
}();
|
|
346
|
+
const {
|
|
347
|
+
data: { pendingTransactionId }
|
|
348
|
+
} = yield sendTransactionRes;
|
|
349
|
+
if (pendingTransactionId) {
|
|
350
|
+
return { pendingTransactionId };
|
|
351
|
+
}
|
|
352
|
+
return yield sendTxRes;
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
function refresh(ctx, share, walletId, userId) {
|
|
356
|
+
return __async(this, null, function* () {
|
|
357
|
+
const {
|
|
358
|
+
data: { protocolId }
|
|
359
|
+
} = yield ctx.client.refreshKeys(userId, walletId);
|
|
360
|
+
const serverUrl = (0, import_core_sdk.getBaseMPCNetworkUrl)(ctx.env, !ctx.disableWebSockets);
|
|
361
|
+
const refreshFn = ctx.useDKLS ? global.dklsRefresh : global.refresh;
|
|
362
|
+
try {
|
|
363
|
+
return yield new Promise(
|
|
364
|
+
(resolve, reject) => refreshFn(share, serverUrl, protocolId, (err, result) => {
|
|
365
|
+
if (err) {
|
|
366
|
+
reject(err);
|
|
367
|
+
}
|
|
368
|
+
resolve(result);
|
|
369
|
+
})
|
|
370
|
+
);
|
|
371
|
+
} catch (e) {
|
|
372
|
+
throw new Error(`error refreshing keys for account with userId ${userId} and walletId ${walletId}`);
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
function getPrivateKey(ctx, share, walletId, userId) {
|
|
377
|
+
return __async(this, null, function* () {
|
|
378
|
+
const paraShare = yield ctx.client.getParaShare(userId, walletId);
|
|
379
|
+
if (!paraShare) {
|
|
380
|
+
console.error("unable to retrieve Para share");
|
|
381
|
+
return "";
|
|
382
|
+
}
|
|
383
|
+
try {
|
|
384
|
+
return yield new Promise(
|
|
385
|
+
(resolve, reject) => global.getPrivateKey(share, paraShare, (err, result) => {
|
|
386
|
+
if (err) {
|
|
387
|
+
reject(err);
|
|
388
|
+
}
|
|
389
|
+
resolve(result);
|
|
390
|
+
})
|
|
391
|
+
);
|
|
392
|
+
} catch (e) {
|
|
393
|
+
throw new Error(`error getting private key for account with userId ${userId} and walletId ${walletId}`);
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
398
|
+
0 && (module.exports = {
|
|
399
|
+
ed25519Keygen,
|
|
400
|
+
ed25519PreKeygen,
|
|
401
|
+
ed25519Sign,
|
|
402
|
+
getPrivateKey,
|
|
403
|
+
keygen,
|
|
404
|
+
preKeygen,
|
|
405
|
+
refresh,
|
|
406
|
+
sendTransaction,
|
|
407
|
+
signMessage,
|
|
408
|
+
signTransaction
|
|
409
|
+
});
|