@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.
@@ -195,7 +195,7 @@ class Portal {
195
195
  throw new Error('orgBackupShare cannot be empty string.');
196
196
  }
197
197
  }
198
- const { SECP256K1, ED25519 } = yield this.mpc.eject({
198
+ const { SECP256K1 } = yield this.mpc.eject({
199
199
  cipherText: clientBackupCipherText,
200
200
  backupMethod,
201
201
  backupConfigs,
@@ -204,6 +204,34 @@ class Portal {
204
204
  mpcVersion: this.mpcVersion,
205
205
  featureFlags: this.featureFlags,
206
206
  });
207
+ return {
208
+ SECP256K1,
209
+ };
210
+ });
211
+ }
212
+ ejectPrivateKeys(backupMethod, backupConfigs = {}, orgBackupShares, clientBackupCipherText = '') {
213
+ return __awaiter(this, void 0, void 0, function* () {
214
+ const client = yield this.mpc.getClient();
215
+ if (!client) {
216
+ throw new Error('Client not found.');
217
+ }
218
+ if (!client.environment.backupWithPortalEnabled) {
219
+ if (clientBackupCipherText === '') {
220
+ throw new Error('clientBackupCipherText cannot be empty string.');
221
+ }
222
+ if (orgBackupShares.SECP256K1 === '') {
223
+ throw new Error('SECP256K1 orgBackupShare cannot be empty string.');
224
+ }
225
+ }
226
+ const { SECP256K1, ED25519 } = yield this.mpc.ejectPrivateKeys({
227
+ cipherText: clientBackupCipherText,
228
+ backupMethod,
229
+ backupConfigs,
230
+ organizationBackupShares: orgBackupShares,
231
+ host: this.host,
232
+ mpcVersion: this.mpcVersion,
233
+ featureFlags: this.featureFlags,
234
+ });
207
235
  return {
208
236
  SECP256K1,
209
237
  ED25519,
@@ -261,6 +261,58 @@ describe('Portal', () => {
261
261
  yield expect(portal.eject(_1.BackupMethods.password, constants_1.mockBackupConfig, '', constants_1.mockCipherText)).rejects.toThrowError(new Error('orgBackupShare cannot be empty string.'));
262
262
  }));
263
263
  });
264
+ describe('ejectPrivateKeys', () => {
265
+ it('should successfully eject a wallet when backup with portal is enabled', () => __awaiter(void 0, void 0, void 0, function* () {
266
+ const res = yield portal.ejectPrivateKeys(_1.BackupMethods.password, constants_1.mockBackupConfig, {
267
+ SECP256K1: '',
268
+ ED25519: '',
269
+ });
270
+ expect(res).toEqual(constants_1.mockEjectPrivateKeysResult);
271
+ expect(portal.mpc.ejectPrivateKeys).toHaveBeenCalledTimes(1);
272
+ expect(portal.mpc.ejectPrivateKeys).toHaveBeenCalledWith({
273
+ cipherText: '',
274
+ backupMethod: _1.BackupMethods.password,
275
+ backupConfigs: constants_1.mockBackupConfig,
276
+ organizationBackupShares: {
277
+ SECP256K1: '',
278
+ ED25519: '',
279
+ },
280
+ host: 'web.portalhq.io',
281
+ mpcVersion: 'v6',
282
+ featureFlags: {},
283
+ });
284
+ }));
285
+ it('should successfully eject a wallet when backup with portal is not enabled', () => __awaiter(void 0, void 0, void 0, function* () {
286
+ portal.mpc.getClient = portal.mpc.getClient.mockResolvedValueOnce(Object.assign(Object.assign({}, constants_1.mockClientResponse), { environment: Object.assign(Object.assign({}, constants_1.mockClientResponse.environment), { backupWithPortalEnabled: false }) }));
287
+ const res = yield portal.ejectPrivateKeys(_1.BackupMethods.password, constants_1.mockBackupConfig, constants_1.mockOrgBackupShares, constants_1.mockCipherText);
288
+ expect(res).toEqual(constants_1.mockEjectPrivateKeysResult);
289
+ expect(portal.mpc.ejectPrivateKeys).toHaveBeenCalledTimes(1);
290
+ expect(portal.mpc.ejectPrivateKeys).toHaveBeenCalledWith({
291
+ cipherText: constants_1.mockCipherText,
292
+ organizationBackupShares: constants_1.mockOrgBackupShares,
293
+ backupMethod: _1.BackupMethods.password,
294
+ backupConfigs: constants_1.mockBackupConfig,
295
+ host: 'web.portalhq.io',
296
+ mpcVersion: 'v6',
297
+ featureFlags: {},
298
+ });
299
+ }));
300
+ it('should error out if client could not be found', () => __awaiter(void 0, void 0, void 0, function* () {
301
+ portal.mpc.getClient = portal.mpc.getClient.mockResolvedValueOnce(null);
302
+ yield expect(portal.ejectPrivateKeys(_1.BackupMethods.password, constants_1.mockBackupConfig, constants_1.mockOrgBackupShares, constants_1.mockCipherText)).rejects.toThrowError(new Error('Client not found.'));
303
+ }));
304
+ it('should error if clientBackupCipherText was not supplied when backup with portal is not enabled', () => __awaiter(void 0, void 0, void 0, function* () {
305
+ portal.mpc.getClient = portal.mpc.getClient.mockResolvedValueOnce(Object.assign(Object.assign({}, constants_1.mockClientResponse), { environment: Object.assign(Object.assign({}, constants_1.mockClientResponse.environment), { backupWithPortalEnabled: false }) }));
306
+ yield expect(portal.ejectPrivateKeys(_1.BackupMethods.password, constants_1.mockBackupConfig, constants_1.mockOrgBackupShares)).rejects.toThrowError(new Error('clientBackupCipherText cannot be empty string.'));
307
+ }));
308
+ it('should error if orgBackupShare was empty when backup with portal is not enabled', () => __awaiter(void 0, void 0, void 0, function* () {
309
+ portal.mpc.getClient = portal.mpc.getClient.mockResolvedValueOnce(Object.assign(Object.assign({}, constants_1.mockClientResponse), { environment: Object.assign(Object.assign({}, constants_1.mockClientResponse.environment), { backupWithPortalEnabled: false }) }));
310
+ yield expect(portal.ejectPrivateKeys(_1.BackupMethods.password, constants_1.mockBackupConfig, {
311
+ SECP256K1: '',
312
+ ED25519: '',
313
+ }, constants_1.mockCipherText)).rejects.toThrowError(new Error('SECP256K1 orgBackupShare cannot be empty string.'));
314
+ }));
315
+ });
264
316
  describe('getEip155Address', () => {
265
317
  it("should return the wallet's eip155 address correctly", () => __awaiter(void 0, void 0, void 0, function* () {
266
318
  const res = yield portal.getEip155Address();
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MpcErrorCodes = exports.MpcError = void 0;
13
13
  const errors_1 = require("./errors");
14
14
  const index_1 = require("../index");
15
- const WEB_SDK_VERSION = '3.3.4-beta.1';
15
+ const WEB_SDK_VERSION = '3.3.5-alpha';
16
16
  class Mpc {
17
17
  get ready() {
18
18
  return this._ready;
@@ -291,6 +291,35 @@ class Mpc {
291
291
  });
292
292
  });
293
293
  }
294
+ ejectPrivateKeys(data) {
295
+ return __awaiter(this, void 0, void 0, function* () {
296
+ return new Promise((resolve, reject) => {
297
+ const handleEject = (message) => {
298
+ const { type, data: result } = message.data;
299
+ const { origin } = message;
300
+ // ignore any broadcast postMessages
301
+ if (origin !== this.getOrigin()) {
302
+ return;
303
+ }
304
+ if (type === 'portal:wasm:ejectPrivateKeysError') {
305
+ // Remove the event listeners
306
+ window.removeEventListener('message', handleEject);
307
+ reject(new errors_1.PortalMpcError(result));
308
+ }
309
+ else if (type === 'portal:wasm:ejectPrivateKeysResult') {
310
+ // Remove the event listeners
311
+ window.removeEventListener('message', handleEject);
312
+ resolve(result);
313
+ }
314
+ };
315
+ window.addEventListener('message', handleEject);
316
+ this.postMessage({
317
+ type: 'portal:wasm:ejectPrivateKeys',
318
+ data,
319
+ });
320
+ });
321
+ });
322
+ }
294
323
  rawSign(curve, param) {
295
324
  return __awaiter(this, void 0, void 0, function* () {
296
325
  return new Promise((resolve, reject) => {