@getpara/web-sdk 1.1.0 → 1.3.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/index.js +4 -9
- package/dist/index.js.br +0 -0
- package/dist/index.js.gz +0 -0
- package/dist/workers/worker.js +3 -128
- package/dist/workers/worker.js.br +0 -0
- package/dist/workers/worker.js.gz +0 -0
- package/package.json +7 -5
- package/dist/LocalStorage.js +0 -34
- package/dist/ParaWeb.js +0 -7
- package/dist/SessionStorage.js +0 -38
- package/dist/WebUtils.js +0 -113
- package/dist/cryptography/webAuth.js +0 -167
- package/dist/errors.js +0 -7
- package/dist/utils/emailUtils.js +0 -5
- package/dist/utils/formattingUtils.js +0 -28
- package/dist/utils/isMobile.js +0 -39
- package/dist/utils/truncateEthAddress.js +0 -8
- package/dist/wallet/keygen.js +0 -185
- package/dist/wallet/privateKey.js +0 -33
- package/dist/wallet/signing.js +0 -100
- package/dist/wasm/wasm_exec.js +0 -513
- package/dist/workers/walletUtils.js +0 -244
- package/dist/workers/workerWrapper.js +0 -50
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { getBaseMPCNetworkUrl, WalletScheme, WalletType } from '@getpara/core-sdk';
|
|
11
|
-
const configCGGMPBase = (serverUrl, walletId, id) => `{"ServerUrl":"${serverUrl}", "WalletId": "${walletId}", "Id":"${id}", "Ids":["USER","CAPSULE"], "Threshold":1}`;
|
|
12
|
-
const configDKLSBase = (walletId, id, disableWebSockets) => `{"walletId": "${walletId}", "id":"${id}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${disableWebSockets}}`;
|
|
13
|
-
function keygenRequest(ctx, userId, walletId, protocolId) {
|
|
14
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
const { data } = yield ctx.mpcComputationClient.post('/wallets', {
|
|
16
|
-
userId,
|
|
17
|
-
walletId,
|
|
18
|
-
protocolId,
|
|
19
|
-
});
|
|
20
|
-
return data;
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
function signMessageRequest(ctx, userId, walletId, protocolId, message, signer) {
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
const { data } = yield ctx.mpcComputationClient.post(`/wallets/${walletId}/messages/sign`, {
|
|
26
|
-
userId,
|
|
27
|
-
protocolId,
|
|
28
|
-
message,
|
|
29
|
-
signer,
|
|
30
|
-
});
|
|
31
|
-
return data;
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
function sendTransactionRequest(ctx, userId, walletId, protocolId, transaction, signer, chainId) {
|
|
35
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
const { data } = yield ctx.mpcComputationClient.post(`/wallets/${walletId}/transactions/send`, {
|
|
37
|
-
userId,
|
|
38
|
-
protocolId,
|
|
39
|
-
transaction,
|
|
40
|
-
signer,
|
|
41
|
-
chainId,
|
|
42
|
-
});
|
|
43
|
-
return data;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
export function ed25519Keygen(ctx, userId) {
|
|
47
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
const { walletId, protocolId } = yield ctx.client.createWallet(userId, {
|
|
49
|
-
scheme: WalletScheme.ED25519,
|
|
50
|
-
type: WalletType.SOLANA,
|
|
51
|
-
});
|
|
52
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
53
|
-
const newSigner = (yield new Promise((resolve, reject) => global.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
|
|
54
|
-
if (err) {
|
|
55
|
-
reject(err);
|
|
56
|
-
}
|
|
57
|
-
resolve(result);
|
|
58
|
-
})));
|
|
59
|
-
return { signer: newSigner, walletId };
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
export function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType) {
|
|
63
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
const { walletId, protocolId } = yield ctx.client.createPregenWallet({
|
|
65
|
-
pregenIdentifier,
|
|
66
|
-
pregenIdentifierType,
|
|
67
|
-
scheme: WalletScheme.ED25519,
|
|
68
|
-
type: WalletType.SOLANA,
|
|
69
|
-
});
|
|
70
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
71
|
-
const newSigner = (yield new Promise((resolve, reject) => global.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
|
|
72
|
-
if (err) {
|
|
73
|
-
reject(err);
|
|
74
|
-
}
|
|
75
|
-
resolve(result);
|
|
76
|
-
})));
|
|
77
|
-
return { signer: newSigner, walletId };
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
export function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
|
|
81
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
-
const { protocolId } = yield ctx.client.preSignMessage(userId, walletId, base64Bytes, WalletScheme.ED25519);
|
|
83
|
-
const base64Sig = (yield new Promise((resolve, reject) => global.ed25519Sign(share, protocolId, base64Bytes, (err, result) => {
|
|
84
|
-
if (err) {
|
|
85
|
-
reject(err);
|
|
86
|
-
}
|
|
87
|
-
resolve(result);
|
|
88
|
-
})));
|
|
89
|
-
return { signature: base64Sig };
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
export function keygen(ctx, userId, type, secretKey) {
|
|
93
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
const { walletId, protocolId } = yield ctx.client.createWallet(userId, {
|
|
95
|
-
useTwoSigners: true,
|
|
96
|
-
scheme: ctx.useDKLS ? WalletScheme.DKLS : WalletScheme.CGGMP,
|
|
97
|
-
type,
|
|
98
|
-
cosmosPrefix: type === WalletType.COSMOS ? ctx.cosmosPrefix : undefined,
|
|
99
|
-
});
|
|
100
|
-
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
101
|
-
return {
|
|
102
|
-
signer: (yield keygenRequest(ctx, userId, walletId, protocolId)).signer,
|
|
103
|
-
walletId,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
107
|
-
const signerConfigUser = ctx.useDKLS
|
|
108
|
-
? configDKLSBase(walletId, 'USER', ctx.disableWebSockets)
|
|
109
|
-
: configCGGMPBase(serverUrl, walletId, 'USER');
|
|
110
|
-
const createAccountFn = ctx.useDKLS ? global.dklsCreateAccount : global.createAccountV2;
|
|
111
|
-
const newSigner = (yield new Promise((resolve, reject) => createAccountFn(signerConfigUser, serverUrl, protocolId, secretKey, () => { }, // no-op for deprecated callback to update progress percentage
|
|
112
|
-
(err, result) => {
|
|
113
|
-
if (err) {
|
|
114
|
-
reject(err);
|
|
115
|
-
}
|
|
116
|
-
resolve(result);
|
|
117
|
-
})));
|
|
118
|
-
return { signer: newSigner, walletId };
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
export function preKeygen(ctx, _partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey) {
|
|
122
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
-
const { walletId, protocolId } = yield ctx.client.createPregenWallet({
|
|
124
|
-
pregenIdentifier,
|
|
125
|
-
pregenIdentifierType,
|
|
126
|
-
type,
|
|
127
|
-
cosmosPrefix: type === WalletType.COSMOS ? ctx.cosmosPrefix : undefined,
|
|
128
|
-
});
|
|
129
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
130
|
-
const signerConfigUser = configDKLSBase(walletId, 'USER', ctx.disableWebSockets);
|
|
131
|
-
const newSigner = (yield new Promise((resolve, reject) => global.dklsCreateAccount(signerConfigUser, serverUrl, protocolId, secretKey, () => { }, // no-op for deprecated callback to update progress percentage
|
|
132
|
-
(err, result) => {
|
|
133
|
-
if (err) {
|
|
134
|
-
reject(err);
|
|
135
|
-
}
|
|
136
|
-
resolve(result);
|
|
137
|
-
})));
|
|
138
|
-
return { signer: newSigner, walletId };
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
export function signMessage(ctx, share, walletId, userId, message, cosmosSignDoc) {
|
|
142
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
-
const { protocolId, pendingTransactionId } = yield ctx.client.preSignMessage(userId, walletId, message, null, cosmosSignDoc);
|
|
144
|
-
if (pendingTransactionId) {
|
|
145
|
-
return { pendingTransactionId };
|
|
146
|
-
}
|
|
147
|
-
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
148
|
-
return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
|
|
149
|
-
}
|
|
150
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
151
|
-
const signMessageFn = ctx.useDKLS ? global.dklsSignMessage : global.signMessage;
|
|
152
|
-
const parsedShare = JSON.parse(share);
|
|
153
|
-
if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
|
|
154
|
-
parsedShare.disableWebSockets = ctx.disableWebSockets;
|
|
155
|
-
}
|
|
156
|
-
share = JSON.stringify(parsedShare);
|
|
157
|
-
return new Promise((resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
|
|
158
|
-
if (err) {
|
|
159
|
-
reject(err);
|
|
160
|
-
}
|
|
161
|
-
resolve({ signature: result });
|
|
162
|
-
}));
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
export function signTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
166
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
167
|
-
const { data: { protocolId, pendingTransactionId }, } = yield ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId });
|
|
168
|
-
if (pendingTransactionId) {
|
|
169
|
-
return { pendingTransactionId };
|
|
170
|
-
}
|
|
171
|
-
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
172
|
-
return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
|
|
173
|
-
}
|
|
174
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
175
|
-
const signTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
|
|
176
|
-
const parsedShare = JSON.parse(share);
|
|
177
|
-
if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
|
|
178
|
-
parsedShare.disableWebSockets = ctx.disableWebSockets;
|
|
179
|
-
}
|
|
180
|
-
share = JSON.stringify(parsedShare);
|
|
181
|
-
return new Promise((resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
182
|
-
if (err) {
|
|
183
|
-
reject(err);
|
|
184
|
-
}
|
|
185
|
-
resolve({ signature: result });
|
|
186
|
-
}));
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
export function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
|
|
190
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
-
const { data: { protocolId, pendingTransactionId }, } = yield ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId });
|
|
192
|
-
if (pendingTransactionId) {
|
|
193
|
-
return { pendingTransactionId };
|
|
194
|
-
}
|
|
195
|
-
if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
|
|
196
|
-
return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
|
|
197
|
-
}
|
|
198
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
199
|
-
const sendTransactionFn = ctx.useDKLS ? global.dklsSendTransaction : global.sendTransaction;
|
|
200
|
-
const parsedShare = JSON.parse(share);
|
|
201
|
-
if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
|
|
202
|
-
parsedShare.disableWebSockets = ctx.disableWebSockets;
|
|
203
|
-
}
|
|
204
|
-
share = JSON.stringify(parsedShare);
|
|
205
|
-
return new Promise((resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
|
|
206
|
-
if (err) {
|
|
207
|
-
reject(err);
|
|
208
|
-
}
|
|
209
|
-
resolve({ signature: result });
|
|
210
|
-
}));
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
export function refresh(ctx, share, walletId, userId, oldPartnerId, newPartnerId, keyShareProtocolId) {
|
|
214
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
215
|
-
const { data: { protocolId }, } = yield ctx.client.refreshKeys(userId, walletId, oldPartnerId, newPartnerId, keyShareProtocolId);
|
|
216
|
-
const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
|
|
217
|
-
const refreshFn = ctx.useDKLS ? global.dklsRefresh : global.refresh;
|
|
218
|
-
const parsedShare = JSON.parse(share);
|
|
219
|
-
if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
|
|
220
|
-
parsedShare.disableWebSockets = ctx.disableWebSockets;
|
|
221
|
-
}
|
|
222
|
-
share = JSON.stringify(parsedShare);
|
|
223
|
-
return new Promise((resolve, reject) => refreshFn(share, serverUrl, protocolId, (err, result) => {
|
|
224
|
-
if (err) {
|
|
225
|
-
reject(err);
|
|
226
|
-
}
|
|
227
|
-
resolve({ protocolId, signer: result });
|
|
228
|
-
}));
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
export function getPrivateKey(ctx, share, walletId, userId) {
|
|
232
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
-
const paraShare = yield ctx.client.getParaShare(userId, walletId);
|
|
234
|
-
if (!paraShare) {
|
|
235
|
-
return '';
|
|
236
|
-
}
|
|
237
|
-
return new Promise((resolve, reject) => global.getPrivateKey(share, paraShare, (err, result) => {
|
|
238
|
-
if (err) {
|
|
239
|
-
reject(err);
|
|
240
|
-
}
|
|
241
|
-
resolve(result);
|
|
242
|
-
}));
|
|
243
|
-
});
|
|
244
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { getPortalBaseURL } from '@getpara/core-sdk';
|
|
11
|
-
import { handleMessage } from './worker.js';
|
|
12
|
-
export function setupWorker(ctx, resFunction) {
|
|
13
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
-
const onmessage = event => {
|
|
15
|
-
if (event.data.functionType === 'CUSTOM') {
|
|
16
|
-
// safe to remove this block once this code is live in prod!
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
resFunction(event.data);
|
|
20
|
-
};
|
|
21
|
-
if (ctx.disableWorkers) {
|
|
22
|
-
const syncWorker = {
|
|
23
|
-
postMessage: function (message) {
|
|
24
|
-
(function () {
|
|
25
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
yield handleMessage({ data: message }, data => onmessage({ data }), ctx.disableWorkers);
|
|
27
|
-
});
|
|
28
|
-
})();
|
|
29
|
-
},
|
|
30
|
-
terminate: () => {
|
|
31
|
-
return;
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
return syncWorker;
|
|
35
|
-
}
|
|
36
|
-
let worker;
|
|
37
|
-
if (ctx.useLocalFiles) {
|
|
38
|
-
// worker = new Worker(new URL('./worker.js', import.meta.url));
|
|
39
|
-
throw new Error('useLocalFiles only supported locally');
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
const workerRes = yield fetch(`${getPortalBaseURL(ctx)}/static/js/mpcWorker-bundle.js`);
|
|
43
|
-
const workerBlob = new Blob([yield workerRes.text()], { type: 'application/javascript' });
|
|
44
|
-
const workerScriptURL = URL.createObjectURL(workerBlob);
|
|
45
|
-
worker = new Worker(workerScriptURL);
|
|
46
|
-
}
|
|
47
|
-
worker.onmessage = onmessage;
|
|
48
|
-
return worker;
|
|
49
|
-
});
|
|
50
|
-
}
|