@portal-hq/web 0.0.7 → 0.1.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/lib/commonjs/index.js +20 -0
- package/lib/commonjs/mpc/index.js +30 -1
- package/lib/esm/index.js +20 -0
- package/lib/esm/mpc/index.js +30 -1
- package/package.json +1 -1
- package/src/index.ts +29 -0
- package/src/mpc/index.ts +38 -1
- package/src/provider/errors/provider-rpc-error.ts +1 -1
- package/types.d.ts +9 -0
package/lib/commonjs/index.js
CHANGED
|
@@ -157,6 +157,26 @@ class Portal {
|
|
|
157
157
|
return this.recoverWallet(cipherText, backupMethod, backupConfigs, progress);
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
|
+
ejectPrivateKey(clientBackupCiphertext, backupMethod, backupConfigs, orgBackupShare) {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
if (clientBackupCiphertext === '') {
|
|
163
|
+
throw new Error('clientBackupCiphertext cannot be empty string.');
|
|
164
|
+
}
|
|
165
|
+
if (orgBackupShare === '') {
|
|
166
|
+
throw new Error('orgBackupShare cannot be empty string.');
|
|
167
|
+
}
|
|
168
|
+
const privateKey = yield this.mpc.eject({
|
|
169
|
+
cipherText: clientBackupCiphertext,
|
|
170
|
+
backupMethod,
|
|
171
|
+
backupConfigs,
|
|
172
|
+
organizationBackupShare: orgBackupShare,
|
|
173
|
+
host: this.host,
|
|
174
|
+
mpcVersion: this.mpcVersion,
|
|
175
|
+
featureFlags: this.featureFlags,
|
|
176
|
+
});
|
|
177
|
+
return privateKey;
|
|
178
|
+
});
|
|
179
|
+
}
|
|
160
180
|
/****************************
|
|
161
181
|
* Provider Methods
|
|
162
182
|
****************************/
|
|
@@ -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 = '0.0
|
|
15
|
+
const WEB_SDK_VERSION = '0.1.0';
|
|
16
16
|
class Mpc {
|
|
17
17
|
constructor({ portal }) {
|
|
18
18
|
this.configureIframe = () => {
|
|
@@ -248,6 +248,35 @@ class Mpc {
|
|
|
248
248
|
});
|
|
249
249
|
});
|
|
250
250
|
}
|
|
251
|
+
eject(data) {
|
|
252
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
253
|
+
return new Promise((resolve, reject) => {
|
|
254
|
+
const handleEject = (message) => {
|
|
255
|
+
const { type, data } = message.data;
|
|
256
|
+
const { origin } = message;
|
|
257
|
+
// ignore any broadcast postMessages
|
|
258
|
+
if (origin !== this.getOrigin()) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (type === 'portal:wasm:ejectError') {
|
|
262
|
+
// Remove the event listeners
|
|
263
|
+
window.removeEventListener('message', handleEject);
|
|
264
|
+
reject(new errors_1.PortalMpcError(data));
|
|
265
|
+
}
|
|
266
|
+
else if (type === 'portal:wasm:ejectResult') {
|
|
267
|
+
// Remove the event listeners
|
|
268
|
+
window.removeEventListener('message', handleEject);
|
|
269
|
+
resolve(data);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
window.addEventListener('message', handleEject);
|
|
273
|
+
this.postMessage({
|
|
274
|
+
type: 'portal:wasm:eject',
|
|
275
|
+
data,
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
}
|
|
251
280
|
legacyRecover(data, progress = () => {
|
|
252
281
|
// Noop
|
|
253
282
|
}) {
|
package/lib/esm/index.js
CHANGED
|
@@ -151,6 +151,26 @@ class Portal {
|
|
|
151
151
|
return this.recoverWallet(cipherText, backupMethod, backupConfigs, progress);
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
|
+
ejectPrivateKey(clientBackupCiphertext, backupMethod, backupConfigs, orgBackupShare) {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
+
if (clientBackupCiphertext === '') {
|
|
157
|
+
throw new Error('clientBackupCiphertext cannot be empty string.');
|
|
158
|
+
}
|
|
159
|
+
if (orgBackupShare === '') {
|
|
160
|
+
throw new Error('orgBackupShare cannot be empty string.');
|
|
161
|
+
}
|
|
162
|
+
const privateKey = yield this.mpc.eject({
|
|
163
|
+
cipherText: clientBackupCiphertext,
|
|
164
|
+
backupMethod,
|
|
165
|
+
backupConfigs,
|
|
166
|
+
organizationBackupShare: orgBackupShare,
|
|
167
|
+
host: this.host,
|
|
168
|
+
mpcVersion: this.mpcVersion,
|
|
169
|
+
featureFlags: this.featureFlags,
|
|
170
|
+
});
|
|
171
|
+
return privateKey;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
154
174
|
/****************************
|
|
155
175
|
* Provider Methods
|
|
156
176
|
****************************/
|
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 = '0.0
|
|
12
|
+
const WEB_SDK_VERSION = '0.1.0';
|
|
13
13
|
class Mpc {
|
|
14
14
|
constructor({ portal }) {
|
|
15
15
|
this.configureIframe = () => {
|
|
@@ -245,6 +245,35 @@ class Mpc {
|
|
|
245
245
|
});
|
|
246
246
|
});
|
|
247
247
|
}
|
|
248
|
+
eject(data) {
|
|
249
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
250
|
+
return new Promise((resolve, reject) => {
|
|
251
|
+
const handleEject = (message) => {
|
|
252
|
+
const { type, data } = message.data;
|
|
253
|
+
const { origin } = message;
|
|
254
|
+
// ignore any broadcast postMessages
|
|
255
|
+
if (origin !== this.getOrigin()) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (type === 'portal:wasm:ejectError') {
|
|
259
|
+
// Remove the event listeners
|
|
260
|
+
window.removeEventListener('message', handleEject);
|
|
261
|
+
reject(new PortalMpcError(data));
|
|
262
|
+
}
|
|
263
|
+
else if (type === 'portal:wasm:ejectResult') {
|
|
264
|
+
// Remove the event listeners
|
|
265
|
+
window.removeEventListener('message', handleEject);
|
|
266
|
+
resolve(data);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
window.addEventListener('message', handleEject);
|
|
270
|
+
this.postMessage({
|
|
271
|
+
type: 'portal:wasm:eject',
|
|
272
|
+
data,
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
}
|
|
248
277
|
legacyRecover(data, progress = () => {
|
|
249
278
|
// Noop
|
|
250
279
|
}) {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -232,6 +232,35 @@ class Portal {
|
|
|
232
232
|
return this.recoverWallet(cipherText, backupMethod, backupConfigs, progress)
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
+
public async ejectPrivateKey(
|
|
236
|
+
clientBackupCiphertext: string,
|
|
237
|
+
backupMethod: BackupMethods,
|
|
238
|
+
backupConfigs: BackupConfigs,
|
|
239
|
+
orgBackupShare: string,
|
|
240
|
+
): Promise<string> {
|
|
241
|
+
if (clientBackupCiphertext === '') {
|
|
242
|
+
throw new Error('clientBackupCiphertext cannot be empty string.')
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (orgBackupShare === '') {
|
|
246
|
+
throw new Error('orgBackupShare cannot be empty string.')
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const privateKey = await this.mpc.eject(
|
|
250
|
+
{
|
|
251
|
+
cipherText: clientBackupCiphertext,
|
|
252
|
+
backupMethod,
|
|
253
|
+
backupConfigs,
|
|
254
|
+
organizationBackupShare: orgBackupShare,
|
|
255
|
+
host: this.host,
|
|
256
|
+
mpcVersion: this.mpcVersion,
|
|
257
|
+
featureFlags: this.featureFlags,
|
|
258
|
+
}
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
return privateKey
|
|
262
|
+
}
|
|
263
|
+
|
|
235
264
|
/****************************
|
|
236
265
|
* Provider Methods
|
|
237
266
|
****************************/
|
package/src/mpc/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
BackupArgs,
|
|
6
6
|
Balance,
|
|
7
7
|
ClientWithCustodianData,
|
|
8
|
+
EjectArgs,
|
|
8
9
|
GenerateArgs,
|
|
9
10
|
GetTransactionsOrder,
|
|
10
11
|
IframeConfigurationOptions,
|
|
@@ -24,7 +25,7 @@ import type {
|
|
|
24
25
|
WorkerResult,
|
|
25
26
|
} from '../../types'
|
|
26
27
|
|
|
27
|
-
const WEB_SDK_VERSION = '0.0
|
|
28
|
+
const WEB_SDK_VERSION = '0.1.0'
|
|
28
29
|
|
|
29
30
|
class Mpc {
|
|
30
31
|
public iframe?: HTMLIFrameElement
|
|
@@ -294,6 +295,42 @@ class Mpc {
|
|
|
294
295
|
})
|
|
295
296
|
}
|
|
296
297
|
|
|
298
|
+
|
|
299
|
+
public async eject(
|
|
300
|
+
data: EjectArgs,
|
|
301
|
+
): Promise<string> {
|
|
302
|
+
return new Promise((resolve, reject) => {
|
|
303
|
+
const handleEject = (message: MessageEvent<WorkerResult>) => {
|
|
304
|
+
const { type, data } = message.data
|
|
305
|
+
const { origin } = message
|
|
306
|
+
|
|
307
|
+
// ignore any broadcast postMessages
|
|
308
|
+
if (origin !== this.getOrigin()) {
|
|
309
|
+
return
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (type === 'portal:wasm:ejectError') {
|
|
313
|
+
// Remove the event listeners
|
|
314
|
+
window.removeEventListener('message', handleEject)
|
|
315
|
+
|
|
316
|
+
reject(new PortalMpcError(data as PortalError))
|
|
317
|
+
} else if (type === 'portal:wasm:ejectResult') {
|
|
318
|
+
// Remove the event listeners
|
|
319
|
+
window.removeEventListener('message', handleEject)
|
|
320
|
+
|
|
321
|
+
resolve(data as string)
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
window.addEventListener('message', handleEject)
|
|
326
|
+
|
|
327
|
+
this.postMessage({
|
|
328
|
+
type: 'portal:wasm:eject',
|
|
329
|
+
data,
|
|
330
|
+
})
|
|
331
|
+
})
|
|
332
|
+
}
|
|
333
|
+
|
|
297
334
|
public async legacyRecover(
|
|
298
335
|
data: LegacyRecoverArgs,
|
|
299
336
|
progress: ProgressCallback = () => {
|
package/types.d.ts
CHANGED
|
@@ -354,6 +354,15 @@ export interface RecoverArgs extends MpcOperationArgs {
|
|
|
354
354
|
featureFlags?: FeatureFlags // TODO: Remove this
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
+
export interface EjectArgs extends RecoverArgs {
|
|
358
|
+
organizationBackupShare: string
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
export interface EjectWorkerArgs extends MpcOperationArgs {
|
|
362
|
+
clientShare: string
|
|
363
|
+
organizationBackupShare: string
|
|
364
|
+
}
|
|
365
|
+
|
|
357
366
|
export interface RotateResult {
|
|
358
367
|
data: RotateData
|
|
359
368
|
error: PortalError
|