@portal-hq/web 0.0.8 → 0.1.1

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.
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.BackupMethods = exports.MpcStatuses = exports.MpcErrorCodes = exports.MpcError = void 0;
15
+ exports.GetTransactionsOrder = exports.BackupMethods = exports.MpcStatuses = exports.MpcErrorCodes = exports.MpcError = void 0;
16
16
  const mpc_1 = __importDefault(require("./mpc"));
17
17
  const provider_1 = __importDefault(require("./provider"));
18
18
  class Portal {
@@ -20,7 +20,7 @@ class Portal {
20
20
  // Required
21
21
  gatewayConfig,
22
22
  // Optional
23
- apiKey, authToken, authUrl, autoApprove = false, chainId = 1, gdrive, host = 'web.portalhq.io', mpcVersion = 'v5', featureFlags = {
23
+ apiKey, authToken, authUrl, autoApprove = false, chainId = 1, gdrive, passkey, host = 'web.portalhq.io', mpcVersion = 'v5', featureFlags = {
24
24
  optimized: false,
25
25
  }, }) {
26
26
  this.ready = false;
@@ -38,6 +38,9 @@ class Portal {
38
38
  if (gdrive) {
39
39
  this.gDriveConfig = gdrive;
40
40
  }
41
+ else if (passkey) {
42
+ this.passkeyConfig = passkey;
43
+ }
41
44
  this.mpc = new mpc_1.default({
42
45
  portal: this,
43
46
  });
@@ -117,7 +120,7 @@ class Portal {
117
120
  return cipherText;
118
121
  });
119
122
  }
120
- recoverWallet(cipherText, backupMethod, backupConfigs, progress = () => {
123
+ recoverWallet(cipherText, backupMethod, backupConfigs = {}, progress = () => {
121
124
  // Noop
122
125
  }) {
123
126
  return __awaiter(this, void 0, void 0, function* () {
@@ -129,6 +132,7 @@ class Portal {
129
132
  mpcVersion: this.mpcVersion,
130
133
  featureFlags: this.featureFlags,
131
134
  }, progress);
135
+ this.address = address;
132
136
  return address;
133
137
  });
134
138
  }
@@ -157,6 +161,26 @@ class Portal {
157
161
  return this.recoverWallet(cipherText, backupMethod, backupConfigs, progress);
158
162
  });
159
163
  }
164
+ ejectPrivateKey(clientBackupCiphertext, backupMethod, backupConfigs, orgBackupShare) {
165
+ return __awaiter(this, void 0, void 0, function* () {
166
+ if (clientBackupCiphertext === '') {
167
+ throw new Error('clientBackupCiphertext cannot be empty string.');
168
+ }
169
+ if (orgBackupShare === '') {
170
+ throw new Error('orgBackupShare cannot be empty string.');
171
+ }
172
+ const privateKey = yield this.mpc.eject({
173
+ cipherText: clientBackupCiphertext,
174
+ backupMethod,
175
+ backupConfigs,
176
+ organizationBackupShare: orgBackupShare,
177
+ host: this.host,
178
+ mpcVersion: this.mpcVersion,
179
+ featureFlags: this.featureFlags,
180
+ });
181
+ return privateKey;
182
+ });
183
+ }
160
184
  /****************************
161
185
  * Provider Methods
162
186
  ****************************/
@@ -354,5 +378,11 @@ var BackupMethods;
354
378
  (function (BackupMethods) {
355
379
  BackupMethods["gdrive"] = "GDRIVE";
356
380
  BackupMethods["password"] = "PASSWORD";
381
+ BackupMethods["passkey"] = "PASSKEY";
357
382
  })(BackupMethods = exports.BackupMethods || (exports.BackupMethods = {}));
383
+ var GetTransactionsOrder;
384
+ (function (GetTransactionsOrder) {
385
+ GetTransactionsOrder["ASC"] = "asc";
386
+ GetTransactionsOrder["DESC"] = "desc";
387
+ })(GetTransactionsOrder = exports.GetTransactionsOrder || (exports.GetTransactionsOrder = {}));
358
388
  exports.default = Portal;
@@ -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.8';
15
+ const WEB_SDK_VERSION = '0.1.1';
16
16
  class Mpc {
17
17
  constructor({ portal }) {
18
18
  this.configureIframe = () => {
@@ -23,6 +23,7 @@ class Mpc {
23
23
  autoApprove: this.portal.autoApprove,
24
24
  chainId: this.portal.chainId,
25
25
  gdrive: this.portal.gDriveConfig,
26
+ passkey: this.portal.passkeyConfig,
26
27
  host: this.portal.host,
27
28
  rpcUrl: this.portal.getRpcUrl(),
28
29
  featureFlags: this.portal.featureFlags,
@@ -248,6 +249,35 @@ class Mpc {
248
249
  });
249
250
  });
250
251
  }
252
+ eject(data) {
253
+ return __awaiter(this, void 0, void 0, function* () {
254
+ return new Promise((resolve, reject) => {
255
+ const handleEject = (message) => {
256
+ const { type, data } = message.data;
257
+ const { origin } = message;
258
+ // ignore any broadcast postMessages
259
+ if (origin !== this.getOrigin()) {
260
+ return;
261
+ }
262
+ if (type === 'portal:wasm:ejectError') {
263
+ // Remove the event listeners
264
+ window.removeEventListener('message', handleEject);
265
+ reject(new errors_1.PortalMpcError(data));
266
+ }
267
+ else if (type === 'portal:wasm:ejectResult') {
268
+ // Remove the event listeners
269
+ window.removeEventListener('message', handleEject);
270
+ resolve(data);
271
+ }
272
+ };
273
+ window.addEventListener('message', handleEject);
274
+ this.postMessage({
275
+ type: 'portal:wasm:eject',
276
+ data,
277
+ });
278
+ });
279
+ });
280
+ }
251
281
  legacyRecover(data, progress = () => {
252
282
  // Noop
253
283
  }) {
package/lib/esm/index.js CHANGED
@@ -14,7 +14,7 @@ class Portal {
14
14
  // Required
15
15
  gatewayConfig,
16
16
  // Optional
17
- apiKey, authToken, authUrl, autoApprove = false, chainId = 1, gdrive, host = 'web.portalhq.io', mpcVersion = 'v5', featureFlags = {
17
+ apiKey, authToken, authUrl, autoApprove = false, chainId = 1, gdrive, passkey, host = 'web.portalhq.io', mpcVersion = 'v5', featureFlags = {
18
18
  optimized: false,
19
19
  }, }) {
20
20
  this.ready = false;
@@ -32,6 +32,9 @@ class Portal {
32
32
  if (gdrive) {
33
33
  this.gDriveConfig = gdrive;
34
34
  }
35
+ else if (passkey) {
36
+ this.passkeyConfig = passkey;
37
+ }
35
38
  this.mpc = new Mpc({
36
39
  portal: this,
37
40
  });
@@ -111,7 +114,7 @@ class Portal {
111
114
  return cipherText;
112
115
  });
113
116
  }
114
- recoverWallet(cipherText, backupMethod, backupConfigs, progress = () => {
117
+ recoverWallet(cipherText, backupMethod, backupConfigs = {}, progress = () => {
115
118
  // Noop
116
119
  }) {
117
120
  return __awaiter(this, void 0, void 0, function* () {
@@ -123,6 +126,7 @@ class Portal {
123
126
  mpcVersion: this.mpcVersion,
124
127
  featureFlags: this.featureFlags,
125
128
  }, progress);
129
+ this.address = address;
126
130
  return address;
127
131
  });
128
132
  }
@@ -151,6 +155,26 @@ class Portal {
151
155
  return this.recoverWallet(cipherText, backupMethod, backupConfigs, progress);
152
156
  });
153
157
  }
158
+ ejectPrivateKey(clientBackupCiphertext, backupMethod, backupConfigs, orgBackupShare) {
159
+ return __awaiter(this, void 0, void 0, function* () {
160
+ if (clientBackupCiphertext === '') {
161
+ throw new Error('clientBackupCiphertext cannot be empty string.');
162
+ }
163
+ if (orgBackupShare === '') {
164
+ throw new Error('orgBackupShare cannot be empty string.');
165
+ }
166
+ const privateKey = yield this.mpc.eject({
167
+ cipherText: clientBackupCiphertext,
168
+ backupMethod,
169
+ backupConfigs,
170
+ organizationBackupShare: orgBackupShare,
171
+ host: this.host,
172
+ mpcVersion: this.mpcVersion,
173
+ featureFlags: this.featureFlags,
174
+ });
175
+ return privateKey;
176
+ });
177
+ }
154
178
  /****************************
155
179
  * Provider Methods
156
180
  ****************************/
@@ -346,5 +370,11 @@ export var BackupMethods;
346
370
  (function (BackupMethods) {
347
371
  BackupMethods["gdrive"] = "GDRIVE";
348
372
  BackupMethods["password"] = "PASSWORD";
373
+ BackupMethods["passkey"] = "PASSKEY";
349
374
  })(BackupMethods || (BackupMethods = {}));
375
+ export var GetTransactionsOrder;
376
+ (function (GetTransactionsOrder) {
377
+ GetTransactionsOrder["ASC"] = "asc";
378
+ GetTransactionsOrder["DESC"] = "desc";
379
+ })(GetTransactionsOrder || (GetTransactionsOrder = {}));
350
380
  export default Portal;
@@ -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.8';
12
+ const WEB_SDK_VERSION = '0.1.1';
13
13
  class Mpc {
14
14
  constructor({ portal }) {
15
15
  this.configureIframe = () => {
@@ -20,6 +20,7 @@ class Mpc {
20
20
  autoApprove: this.portal.autoApprove,
21
21
  chainId: this.portal.chainId,
22
22
  gdrive: this.portal.gDriveConfig,
23
+ passkey: this.portal.passkeyConfig,
23
24
  host: this.portal.host,
24
25
  rpcUrl: this.portal.getRpcUrl(),
25
26
  featureFlags: this.portal.featureFlags,
@@ -245,6 +246,35 @@ class Mpc {
245
246
  });
246
247
  });
247
248
  }
249
+ eject(data) {
250
+ return __awaiter(this, void 0, void 0, function* () {
251
+ return new Promise((resolve, reject) => {
252
+ const handleEject = (message) => {
253
+ const { type, data } = message.data;
254
+ const { origin } = message;
255
+ // ignore any broadcast postMessages
256
+ if (origin !== this.getOrigin()) {
257
+ return;
258
+ }
259
+ if (type === 'portal:wasm:ejectError') {
260
+ // Remove the event listeners
261
+ window.removeEventListener('message', handleEject);
262
+ reject(new PortalMpcError(data));
263
+ }
264
+ else if (type === 'portal:wasm:ejectResult') {
265
+ // Remove the event listeners
266
+ window.removeEventListener('message', handleEject);
267
+ resolve(data);
268
+ }
269
+ };
270
+ window.addEventListener('message', handleEject);
271
+ this.postMessage({
272
+ type: 'portal:wasm:eject',
273
+ data,
274
+ });
275
+ });
276
+ });
277
+ }
248
278
  legacyRecover(data, progress = () => {
249
279
  // Noop
250
280
  }) {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Portal MPC Support for Web",
4
4
  "author": "Portal Labs, Inc.",
5
5
  "homepage": "https://portalhq.io/",
6
- "version": "0.0.8",
6
+ "version": "0.1.1",
7
7
  "license": "MIT",
8
8
  "main": "lib/commonjs/index",
9
9
  "module": "lib/esm/index",
package/src/index.ts CHANGED
@@ -6,9 +6,9 @@ import type {
6
6
  FeatureFlags,
7
7
  GDriveConfig,
8
8
  GatewayLike,
9
- GetTransactionsOrder,
10
9
  NFT,
11
10
  PortalOptions,
11
+ PasskeyConfig,
12
12
  ProgressCallback,
13
13
  QuoteArgs,
14
14
  QuoteResponse,
@@ -28,6 +28,7 @@ class Portal {
28
28
  public autoApprove: boolean
29
29
  public chainId: number
30
30
  public gDriveConfig?: GDriveConfig
31
+ public passkeyConfig?: PasskeyConfig
31
32
  public host: string
32
33
  public mpc: Mpc
33
34
  public mpcVersion: string
@@ -50,6 +51,7 @@ class Portal {
50
51
  autoApprove = false,
51
52
  chainId = 1,
52
53
  gdrive,
54
+ passkey,
53
55
  host = 'web.portalhq.io',
54
56
  mpcVersion = 'v5',
55
57
  featureFlags = {
@@ -68,6 +70,8 @@ class Portal {
68
70
 
69
71
  if (gdrive) {
70
72
  this.gDriveConfig = gdrive
73
+ } else if (passkey) {
74
+ this.passkeyConfig = passkey
71
75
  }
72
76
 
73
77
  this.mpc = new Mpc({
@@ -176,7 +180,7 @@ class Portal {
176
180
  public async recoverWallet(
177
181
  cipherText: string,
178
182
  backupMethod: BackupMethods,
179
- backupConfigs: BackupConfigs,
183
+ backupConfigs: BackupConfigs = {},
180
184
  progress: ProgressCallback = () => {
181
185
  // Noop
182
186
  },
@@ -193,6 +197,8 @@ class Portal {
193
197
  progress,
194
198
  )
195
199
 
200
+ this.address = address
201
+
196
202
  return address
197
203
  }
198
204
 
@@ -232,6 +238,35 @@ class Portal {
232
238
  return this.recoverWallet(cipherText, backupMethod, backupConfigs, progress)
233
239
  }
234
240
 
241
+ public async ejectPrivateKey(
242
+ clientBackupCiphertext: string,
243
+ backupMethod: BackupMethods,
244
+ backupConfigs: BackupConfigs,
245
+ orgBackupShare: string,
246
+ ): Promise<string> {
247
+ if (clientBackupCiphertext === '') {
248
+ throw new Error('clientBackupCiphertext cannot be empty string.')
249
+ }
250
+
251
+ if (orgBackupShare === '') {
252
+ throw new Error('orgBackupShare cannot be empty string.')
253
+ }
254
+
255
+ const privateKey = await this.mpc.eject(
256
+ {
257
+ cipherText: clientBackupCiphertext,
258
+ backupMethod,
259
+ backupConfigs,
260
+ organizationBackupShare: orgBackupShare,
261
+ host: this.host,
262
+ mpcVersion: this.mpcVersion,
263
+ featureFlags: this.featureFlags,
264
+ }
265
+ )
266
+
267
+ return privateKey
268
+ }
269
+
235
270
  /****************************
236
271
  * Provider Methods
237
272
  ****************************/
@@ -440,6 +475,12 @@ export enum MpcStatuses {
440
475
  export enum BackupMethods {
441
476
  gdrive = 'GDRIVE',
442
477
  password = 'PASSWORD',
478
+ passkey = 'PASSKEY',
479
+ }
480
+
481
+ export enum GetTransactionsOrder {
482
+ ASC = 'asc',
483
+ DESC = 'desc',
443
484
  }
444
485
 
445
486
  export default Portal
package/src/mpc/index.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { PortalMpcError } from './errors'
2
2
 
3
- import Portal, { BackupMethods } from '../index'
3
+ import Portal, { BackupMethods, GetTransactionsOrder } from '../index'
4
4
  import type {
5
5
  BackupArgs,
6
6
  Balance,
7
7
  ClientWithCustodianData,
8
+ EjectArgs,
8
9
  GenerateArgs,
9
- GetTransactionsOrder,
10
10
  IframeConfigurationOptions,
11
11
  LegacyRecoverArgs,
12
12
  MpcOptions,
@@ -24,7 +24,7 @@ import type {
24
24
  WorkerResult,
25
25
  } from '../../types'
26
26
 
27
- const WEB_SDK_VERSION = '0.0.8'
27
+ const WEB_SDK_VERSION = '0.1.1'
28
28
 
29
29
  class Mpc {
30
30
  public iframe?: HTMLIFrameElement
@@ -294,6 +294,42 @@ class Mpc {
294
294
  })
295
295
  }
296
296
 
297
+
298
+ public async eject(
299
+ data: EjectArgs,
300
+ ): Promise<string> {
301
+ return new Promise((resolve, reject) => {
302
+ const handleEject = (message: MessageEvent<WorkerResult>) => {
303
+ const { type, data } = message.data
304
+ const { origin } = message
305
+
306
+ // ignore any broadcast postMessages
307
+ if (origin !== this.getOrigin()) {
308
+ return
309
+ }
310
+
311
+ if (type === 'portal:wasm:ejectError') {
312
+ // Remove the event listeners
313
+ window.removeEventListener('message', handleEject)
314
+
315
+ reject(new PortalMpcError(data as PortalError))
316
+ } else if (type === 'portal:wasm:ejectResult') {
317
+ // Remove the event listeners
318
+ window.removeEventListener('message', handleEject)
319
+
320
+ resolve(data as string)
321
+ }
322
+ }
323
+
324
+ window.addEventListener('message', handleEject)
325
+
326
+ this.postMessage({
327
+ type: 'portal:wasm:eject',
328
+ data,
329
+ })
330
+ })
331
+ }
332
+
297
333
  public async legacyRecover(
298
334
  data: LegacyRecoverArgs,
299
335
  progress: ProgressCallback = () => {
@@ -764,6 +800,7 @@ class Mpc {
764
800
  autoApprove: this.portal.autoApprove,
765
801
  chainId: this.portal.chainId,
766
802
  gdrive: this.portal.gDriveConfig,
803
+ passkey: this.portal.passkeyConfig,
767
804
  host: this.portal.host,
768
805
  rpcUrl: this.portal.getRpcUrl(),
769
806
  featureFlags: this.portal.featureFlags,
package/types.d.ts CHANGED
@@ -18,7 +18,7 @@ export type MessageData =
18
18
  | SignArgs
19
19
  export type ProgressCallback = (status: MpcStatus) => void | Promise<void>
20
20
  export type ValidRpcErrorCodes = 4001 | 4100 | 4200 | 4900 | 4901
21
-
21
+ export type PasskeyConfig = PasskeyConfig
22
22
  // Interfaces
23
23
 
24
24
  export interface FeatureFlags {
@@ -178,6 +178,14 @@ export interface GDriveStorageOptions {
178
178
 
179
179
  export type GenerateArgs = MpcOperationArgs
180
180
 
181
+ export interface PasskeyConfig {
182
+ relyingParty?: string = 'backup.web.portalhq.io'
183
+ }
184
+
185
+ export interface PasskeyStatusResponse {
186
+ status: PasskeyStatus
187
+ }
188
+
181
189
  export interface GenerateData {
182
190
  address: string
183
191
  dkgResult: DkgData
@@ -199,6 +207,7 @@ export interface IframeConfigurationOptions {
199
207
  chainId: number
200
208
  featureFlags?: FeatureFlags
201
209
  gdrive?: GDriveConfig
210
+ passkey?: PasskeyConfig
202
211
  host: string
203
212
  rpcUrl: string
204
213
 
@@ -293,6 +302,7 @@ export interface PortalOptions {
293
302
  autoApprove?: boolean
294
303
  chainId?: number
295
304
  gdrive?: GDriveConfig
305
+ passkey?: PasskeyConfig
296
306
  host?: string
297
307
  keychain?: KeychainAdapter
298
308
  mpcVersion?: string
@@ -354,6 +364,15 @@ export interface RecoverArgs extends MpcOperationArgs {
354
364
  featureFlags?: FeatureFlags // TODO: Remove this
355
365
  }
356
366
 
367
+ export interface EjectArgs extends RecoverArgs {
368
+ organizationBackupShare: string
369
+ }
370
+
371
+ export interface EjectWorkerArgs extends MpcOperationArgs {
372
+ clientShare: string
373
+ organizationBackupShare: string
374
+ }
375
+
357
376
  export interface RotateResult {
358
377
  data: RotateData
359
378
  error: PortalError
@@ -429,11 +448,6 @@ export interface SimulatedTransaction {
429
448
  requestError?: SimulatedTransactionError
430
449
  }
431
450
 
432
- export enum GetTransactionsOrder {
433
- ASC = 'asc',
434
- DESC = 'desc',
435
- }
436
-
437
451
  export interface Transaction {
438
452
  asset: string
439
453
  blockNum: string