@portal-hq/web 3.3.4-beta.1 → 3.3.5-alpha
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/lib/commonjs/index.js +29 -1
- package/lib/commonjs/index.test.js +52 -0
- package/lib/commonjs/mpc/index.js +30 -1
- package/lib/commonjs/mpc/index.test.js +532 -244
- package/lib/esm/index.js +29 -1
- package/lib/esm/index.test.js +53 -1
- package/lib/esm/mpc/index.js +30 -1
- package/lib/esm/mpc/index.test.js +537 -249
- package/package.json +1 -1
- package/src/__mocks/constants.ts +10 -2
- package/src/__mocks/portal/mpc.ts +4 -0
- package/src/index.test.ts +124 -0
- package/src/index.ts +39 -2
- package/src/mpc/index.test.ts +883 -608
- package/src/mpc/index.ts +39 -2
- package/types.d.ts +13 -0
package/lib/esm/index.js
CHANGED
|
@@ -166,7 +166,7 @@ class Portal {
|
|
|
166
166
|
throw new Error('orgBackupShare cannot be empty string.');
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
|
-
const { SECP256K1
|
|
169
|
+
const { SECP256K1 } = yield this.mpc.eject({
|
|
170
170
|
cipherText: clientBackupCipherText,
|
|
171
171
|
backupMethod,
|
|
172
172
|
backupConfigs,
|
|
@@ -175,6 +175,34 @@ class Portal {
|
|
|
175
175
|
mpcVersion: this.mpcVersion,
|
|
176
176
|
featureFlags: this.featureFlags,
|
|
177
177
|
});
|
|
178
|
+
return {
|
|
179
|
+
SECP256K1,
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
ejectPrivateKeys(backupMethod, backupConfigs = {}, orgBackupShares, clientBackupCipherText = '') {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
const client = yield this.mpc.getClient();
|
|
186
|
+
if (!client) {
|
|
187
|
+
throw new Error('Client not found.');
|
|
188
|
+
}
|
|
189
|
+
if (!client.environment.backupWithPortalEnabled) {
|
|
190
|
+
if (clientBackupCipherText === '') {
|
|
191
|
+
throw new Error('clientBackupCipherText cannot be empty string.');
|
|
192
|
+
}
|
|
193
|
+
if (orgBackupShares.SECP256K1 === '') {
|
|
194
|
+
throw new Error('SECP256K1 orgBackupShare cannot be empty string.');
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const { SECP256K1, ED25519 } = yield this.mpc.ejectPrivateKeys({
|
|
198
|
+
cipherText: clientBackupCipherText,
|
|
199
|
+
backupMethod,
|
|
200
|
+
backupConfigs,
|
|
201
|
+
organizationBackupShares: orgBackupShares,
|
|
202
|
+
host: this.host,
|
|
203
|
+
mpcVersion: this.mpcVersion,
|
|
204
|
+
featureFlags: this.featureFlags,
|
|
205
|
+
});
|
|
178
206
|
return {
|
|
179
207
|
SECP256K1,
|
|
180
208
|
ED25519,
|
package/lib/esm/index.test.js
CHANGED
|
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
});
|
|
12
12
|
};
|
|
13
13
|
import Portal, { BackupMethods, GetTransactionsOrder } from '.';
|
|
14
|
-
import { mockAddress, mockBackupConfig, mockBlockHashResponse, mockCipherText, mockClientResponse, mockEip155Address, mockEjectResult, mockEthRpcUrl, mockEthTransaction, mockMpcBackupResponse, mockOrgBackupShare, mockQuoteArgs, mockRpcConfig, mockSharesOnDevice, mockSignedHash, mockSolanaAddress, mockSolRpcUrl, } from './__mocks/constants';
|
|
14
|
+
import { mockAddress, mockBackupConfig, mockBlockHashResponse, mockCipherText, mockClientResponse, mockEip155Address, mockEjectResult, mockEjectPrivateKeysResult, mockEthRpcUrl, mockEthTransaction, mockMpcBackupResponse, mockOrgBackupShare, mockOrgBackupShares, mockQuoteArgs, mockRpcConfig, mockSharesOnDevice, mockSignedHash, mockSolanaAddress, mockSolRpcUrl, } from './__mocks/constants';
|
|
15
15
|
import mpcMock from './__mocks/portal/mpc';
|
|
16
16
|
import providerMock from './__mocks/portal/provider';
|
|
17
17
|
/**
|
|
@@ -233,6 +233,58 @@ describe('Portal', () => {
|
|
|
233
233
|
yield expect(portal.eject(BackupMethods.password, mockBackupConfig, '', mockCipherText)).rejects.toThrowError(new Error('orgBackupShare cannot be empty string.'));
|
|
234
234
|
}));
|
|
235
235
|
});
|
|
236
|
+
describe('ejectPrivateKeys', () => {
|
|
237
|
+
it('should successfully eject a wallet when backup with portal is enabled', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
238
|
+
const res = yield portal.ejectPrivateKeys(BackupMethods.password, mockBackupConfig, {
|
|
239
|
+
SECP256K1: '',
|
|
240
|
+
ED25519: '',
|
|
241
|
+
});
|
|
242
|
+
expect(res).toEqual(mockEjectPrivateKeysResult);
|
|
243
|
+
expect(portal.mpc.ejectPrivateKeys).toHaveBeenCalledTimes(1);
|
|
244
|
+
expect(portal.mpc.ejectPrivateKeys).toHaveBeenCalledWith({
|
|
245
|
+
cipherText: '',
|
|
246
|
+
backupMethod: BackupMethods.password,
|
|
247
|
+
backupConfigs: mockBackupConfig,
|
|
248
|
+
organizationBackupShares: {
|
|
249
|
+
SECP256K1: '',
|
|
250
|
+
ED25519: '',
|
|
251
|
+
},
|
|
252
|
+
host: 'web.portalhq.io',
|
|
253
|
+
mpcVersion: 'v6',
|
|
254
|
+
featureFlags: {},
|
|
255
|
+
});
|
|
256
|
+
}));
|
|
257
|
+
it('should successfully eject a wallet when backup with portal is not enabled', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
258
|
+
portal.mpc.getClient = portal.mpc.getClient.mockResolvedValueOnce(Object.assign(Object.assign({}, mockClientResponse), { environment: Object.assign(Object.assign({}, mockClientResponse.environment), { backupWithPortalEnabled: false }) }));
|
|
259
|
+
const res = yield portal.ejectPrivateKeys(BackupMethods.password, mockBackupConfig, mockOrgBackupShares, mockCipherText);
|
|
260
|
+
expect(res).toEqual(mockEjectPrivateKeysResult);
|
|
261
|
+
expect(portal.mpc.ejectPrivateKeys).toHaveBeenCalledTimes(1);
|
|
262
|
+
expect(portal.mpc.ejectPrivateKeys).toHaveBeenCalledWith({
|
|
263
|
+
cipherText: mockCipherText,
|
|
264
|
+
organizationBackupShares: mockOrgBackupShares,
|
|
265
|
+
backupMethod: BackupMethods.password,
|
|
266
|
+
backupConfigs: mockBackupConfig,
|
|
267
|
+
host: 'web.portalhq.io',
|
|
268
|
+
mpcVersion: 'v6',
|
|
269
|
+
featureFlags: {},
|
|
270
|
+
});
|
|
271
|
+
}));
|
|
272
|
+
it('should error out if client could not be found', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
273
|
+
portal.mpc.getClient = portal.mpc.getClient.mockResolvedValueOnce(null);
|
|
274
|
+
yield expect(portal.ejectPrivateKeys(BackupMethods.password, mockBackupConfig, mockOrgBackupShares, mockCipherText)).rejects.toThrowError(new Error('Client not found.'));
|
|
275
|
+
}));
|
|
276
|
+
it('should error if clientBackupCipherText was not supplied when backup with portal is not enabled', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
277
|
+
portal.mpc.getClient = portal.mpc.getClient.mockResolvedValueOnce(Object.assign(Object.assign({}, mockClientResponse), { environment: Object.assign(Object.assign({}, mockClientResponse.environment), { backupWithPortalEnabled: false }) }));
|
|
278
|
+
yield expect(portal.ejectPrivateKeys(BackupMethods.password, mockBackupConfig, mockOrgBackupShares)).rejects.toThrowError(new Error('clientBackupCipherText cannot be empty string.'));
|
|
279
|
+
}));
|
|
280
|
+
it('should error if orgBackupShare was empty when backup with portal is not enabled', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
281
|
+
portal.mpc.getClient = portal.mpc.getClient.mockResolvedValueOnce(Object.assign(Object.assign({}, mockClientResponse), { environment: Object.assign(Object.assign({}, mockClientResponse.environment), { backupWithPortalEnabled: false }) }));
|
|
282
|
+
yield expect(portal.ejectPrivateKeys(BackupMethods.password, mockBackupConfig, {
|
|
283
|
+
SECP256K1: '',
|
|
284
|
+
ED25519: '',
|
|
285
|
+
}, mockCipherText)).rejects.toThrowError(new Error('SECP256K1 orgBackupShare cannot be empty string.'));
|
|
286
|
+
}));
|
|
287
|
+
});
|
|
236
288
|
describe('getEip155Address', () => {
|
|
237
289
|
it("should return the wallet's eip155 address correctly", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
238
290
|
const res = yield portal.getEip155Address();
|
package/lib/esm/mpc/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { PortalMpcError } from './errors';
|
|
11
11
|
import { BackupMethods, } from '../index';
|
|
12
|
-
const WEB_SDK_VERSION = '3.3.
|
|
12
|
+
const WEB_SDK_VERSION = '3.3.5-alpha';
|
|
13
13
|
class Mpc {
|
|
14
14
|
get ready() {
|
|
15
15
|
return this._ready;
|
|
@@ -288,6 +288,35 @@ class Mpc {
|
|
|
288
288
|
});
|
|
289
289
|
});
|
|
290
290
|
}
|
|
291
|
+
ejectPrivateKeys(data) {
|
|
292
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
293
|
+
return new Promise((resolve, reject) => {
|
|
294
|
+
const handleEject = (message) => {
|
|
295
|
+
const { type, data: result } = message.data;
|
|
296
|
+
const { origin } = message;
|
|
297
|
+
// ignore any broadcast postMessages
|
|
298
|
+
if (origin !== this.getOrigin()) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (type === 'portal:wasm:ejectPrivateKeysError') {
|
|
302
|
+
// Remove the event listeners
|
|
303
|
+
window.removeEventListener('message', handleEject);
|
|
304
|
+
reject(new PortalMpcError(result));
|
|
305
|
+
}
|
|
306
|
+
else if (type === 'portal:wasm:ejectPrivateKeysResult') {
|
|
307
|
+
// Remove the event listeners
|
|
308
|
+
window.removeEventListener('message', handleEject);
|
|
309
|
+
resolve(result);
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
window.addEventListener('message', handleEject);
|
|
313
|
+
this.postMessage({
|
|
314
|
+
type: 'portal:wasm:ejectPrivateKeys',
|
|
315
|
+
data,
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
}
|
|
291
320
|
rawSign(curve, param) {
|
|
292
321
|
return __awaiter(this, void 0, void 0, function* () {
|
|
293
322
|
return new Promise((resolve, reject) => {
|