@portal-hq/web 3.1.0 → 3.2.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.GetTransactionsOrder = exports.BackupMethods = exports.MpcStatuses = exports.MpcErrorCodes = exports.MpcError = void 0;
15
+ exports.PortalCurve = exports.GetTransactionsOrder = exports.BackupMethods = exports.MpcStatuses = exports.MpcErrorCodes = exports.MpcError = void 0;
16
16
  const web3_js_1 = require("@solana/web3.js");
17
17
  const mpc_1 = __importDefault(require("./mpc"));
18
18
  const provider_1 = __importDefault(require("./provider"));
@@ -155,13 +155,19 @@ class Portal {
155
155
  return this.recoverWallet(cipherText, backupMethod, backupConfigs, progress);
156
156
  });
157
157
  }
158
- eject(clientBackupCipherText, backupMethod, backupConfigs, orgBackupShare) {
158
+ eject(backupMethod, backupConfigs, orgBackupShare = '', clientBackupCipherText = '') {
159
159
  return __awaiter(this, void 0, void 0, function* () {
160
- if (clientBackupCipherText === '') {
161
- throw new Error('clientBackupCipherText cannot be empty string.');
160
+ const client = yield this.mpc.getClient();
161
+ if (!client) {
162
+ throw new Error('Client not found.');
162
163
  }
163
- if (orgBackupShare === '') {
164
- throw new Error('orgBackupShare cannot be empty string.');
164
+ if (!client.environment.backupWithPortalEnabled) {
165
+ if (clientBackupCipherText === '') {
166
+ throw new Error('clientBackupCipherText cannot be empty string.');
167
+ }
168
+ if (orgBackupShare === '') {
169
+ throw new Error('orgBackupShare cannot be empty string.');
170
+ }
165
171
  }
166
172
  const { SECP256K1, ED25519 } = yield this.mpc.eject({
167
173
  cipherText: clientBackupCipherText,
@@ -387,6 +393,12 @@ class Portal {
387
393
  }));
388
394
  });
389
395
  }
396
+ rawSign(curve, param) {
397
+ return __awaiter(this, void 0, void 0, function* () {
398
+ const response = yield this.mpc.rawSign(curve, param);
399
+ return response;
400
+ });
401
+ }
390
402
  sendSol({ chainId, to, lamports, }) {
391
403
  var _a;
392
404
  return __awaiter(this, void 0, void 0, function* () {
@@ -585,4 +597,9 @@ var GetTransactionsOrder;
585
597
  GetTransactionsOrder["ASC"] = "asc";
586
598
  GetTransactionsOrder["DESC"] = "desc";
587
599
  })(GetTransactionsOrder = exports.GetTransactionsOrder || (exports.GetTransactionsOrder = {}));
600
+ var PortalCurve;
601
+ (function (PortalCurve) {
602
+ PortalCurve["ED25519"] = "ED25519";
603
+ PortalCurve["SECP256K1"] = "SECP256K1";
604
+ })(PortalCurve = exports.PortalCurve || (exports.PortalCurve = {}));
588
605
  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 = '3.1.0';
15
+ const WEB_SDK_VERSION = '3.2.1';
16
16
  class Mpc {
17
17
  constructor({ portal }) {
18
18
  this.configureIframe = () => {
@@ -284,6 +284,42 @@ class Mpc {
284
284
  });
285
285
  });
286
286
  }
287
+ rawSign(curve, param) {
288
+ return __awaiter(this, void 0, void 0, function* () {
289
+ return new Promise((resolve, reject) => {
290
+ const handleRawSign = (event) => {
291
+ const { type, data: result } = event.data;
292
+ const { origin } = event;
293
+ // ignore any broadcast postMessages
294
+ if (origin !== this.getOrigin()) {
295
+ return;
296
+ }
297
+ if (type === 'portal:mpc:rawSignError') {
298
+ // Remove the event listeners
299
+ window.removeEventListener('message', handleRawSign);
300
+ // Reject the promise with the error
301
+ return reject(new errors_1.PortalMpcError(result));
302
+ }
303
+ else if (type === 'portal:mpc:rawSignResult') {
304
+ // Remove the event listeners
305
+ window.removeEventListener('message', handleRawSign);
306
+ // Resolve the promise with the result
307
+ resolve(result);
308
+ }
309
+ };
310
+ // Bind the function to the message event
311
+ window.addEventListener('message', handleRawSign);
312
+ // Send the request to the iframe
313
+ this.postMessage({
314
+ type: 'portal:mpc:rawSign',
315
+ data: {
316
+ curve,
317
+ param,
318
+ },
319
+ });
320
+ });
321
+ });
322
+ }
287
323
  sign(data, progress = () => {
288
324
  // Noop
289
325
  }) {
package/lib/esm/index.js CHANGED
@@ -149,13 +149,19 @@ class Portal {
149
149
  return this.recoverWallet(cipherText, backupMethod, backupConfigs, progress);
150
150
  });
151
151
  }
152
- eject(clientBackupCipherText, backupMethod, backupConfigs, orgBackupShare) {
152
+ eject(backupMethod, backupConfigs, orgBackupShare = '', clientBackupCipherText = '') {
153
153
  return __awaiter(this, void 0, void 0, function* () {
154
- if (clientBackupCipherText === '') {
155
- throw new Error('clientBackupCipherText cannot be empty string.');
154
+ const client = yield this.mpc.getClient();
155
+ if (!client) {
156
+ throw new Error('Client not found.');
156
157
  }
157
- if (orgBackupShare === '') {
158
- throw new Error('orgBackupShare cannot be empty string.');
158
+ if (!client.environment.backupWithPortalEnabled) {
159
+ if (clientBackupCipherText === '') {
160
+ throw new Error('clientBackupCipherText cannot be empty string.');
161
+ }
162
+ if (orgBackupShare === '') {
163
+ throw new Error('orgBackupShare cannot be empty string.');
164
+ }
159
165
  }
160
166
  const { SECP256K1, ED25519 } = yield this.mpc.eject({
161
167
  cipherText: clientBackupCipherText,
@@ -381,6 +387,12 @@ class Portal {
381
387
  }));
382
388
  });
383
389
  }
390
+ rawSign(curve, param) {
391
+ return __awaiter(this, void 0, void 0, function* () {
392
+ const response = yield this.mpc.rawSign(curve, param);
393
+ return response;
394
+ });
395
+ }
384
396
  sendSol({ chainId, to, lamports, }) {
385
397
  var _a;
386
398
  return __awaiter(this, void 0, void 0, function* () {
@@ -577,4 +589,9 @@ export var GetTransactionsOrder;
577
589
  GetTransactionsOrder["ASC"] = "asc";
578
590
  GetTransactionsOrder["DESC"] = "desc";
579
591
  })(GetTransactionsOrder || (GetTransactionsOrder = {}));
592
+ export var PortalCurve;
593
+ (function (PortalCurve) {
594
+ PortalCurve["ED25519"] = "ED25519";
595
+ PortalCurve["SECP256K1"] = "SECP256K1";
596
+ })(PortalCurve || (PortalCurve = {}));
580
597
  export default Portal;
@@ -8,8 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { PortalMpcError } from './errors';
11
- import { BackupMethods } from '../index';
12
- const WEB_SDK_VERSION = '3.1.0';
11
+ import { BackupMethods, } from '../index';
12
+ const WEB_SDK_VERSION = '3.2.1';
13
13
  class Mpc {
14
14
  constructor({ portal }) {
15
15
  this.configureIframe = () => {
@@ -281,6 +281,42 @@ class Mpc {
281
281
  });
282
282
  });
283
283
  }
284
+ rawSign(curve, param) {
285
+ return __awaiter(this, void 0, void 0, function* () {
286
+ return new Promise((resolve, reject) => {
287
+ const handleRawSign = (event) => {
288
+ const { type, data: result } = event.data;
289
+ const { origin } = event;
290
+ // ignore any broadcast postMessages
291
+ if (origin !== this.getOrigin()) {
292
+ return;
293
+ }
294
+ if (type === 'portal:mpc:rawSignError') {
295
+ // Remove the event listeners
296
+ window.removeEventListener('message', handleRawSign);
297
+ // Reject the promise with the error
298
+ return reject(new PortalMpcError(result));
299
+ }
300
+ else if (type === 'portal:mpc:rawSignResult') {
301
+ // Remove the event listeners
302
+ window.removeEventListener('message', handleRawSign);
303
+ // Resolve the promise with the result
304
+ resolve(result);
305
+ }
306
+ };
307
+ // Bind the function to the message event
308
+ window.addEventListener('message', handleRawSign);
309
+ // Send the request to the iframe
310
+ this.postMessage({
311
+ type: 'portal:mpc:rawSign',
312
+ data: {
313
+ curve,
314
+ param,
315
+ },
316
+ });
317
+ });
318
+ });
319
+ }
284
320
  sign(data, progress = () => {
285
321
  // Noop
286
322
  }) {
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": "3.1.0",
6
+ "version": "3.2.1",
7
7
  "license": "MIT",
8
8
  "main": "lib/commonjs/index",
9
9
  "module": "lib/esm/index",
package/src/index.ts CHANGED
@@ -224,17 +224,23 @@ class Portal {
224
224
  }
225
225
 
226
226
  public async eject(
227
- clientBackupCipherText: string,
228
227
  backupMethod: BackupMethods,
229
228
  backupConfigs: BackupConfigs,
230
- orgBackupShare: string,
229
+ orgBackupShare: string = '',
230
+ clientBackupCipherText: string = '',
231
231
  ): Promise<EjectResult> {
232
- if (clientBackupCipherText === '') {
233
- throw new Error('clientBackupCipherText cannot be empty string.')
232
+ const client = await this.mpc.getClient()
233
+ if (!client) {
234
+ throw new Error('Client not found.')
234
235
  }
235
236
 
236
- if (orgBackupShare === '') {
237
- throw new Error('orgBackupShare cannot be empty string.')
237
+ if (!client.environment.backupWithPortalEnabled) {
238
+ if (clientBackupCipherText === '') {
239
+ throw new Error('clientBackupCipherText cannot be empty string.')
240
+ }
241
+ if (orgBackupShare === '') {
242
+ throw new Error('orgBackupShare cannot be empty string.')
243
+ }
238
244
  }
239
245
 
240
246
  const { SECP256K1, ED25519 } = await this.mpc.eject({
@@ -485,6 +491,12 @@ class Portal {
485
491
  })) as Promise<string>
486
492
  }
487
493
 
494
+ public async rawSign(curve: PortalCurve, param: string): Promise<string> {
495
+ const response = await this.mpc.rawSign(curve, param)
496
+
497
+ return response
498
+ }
499
+
488
500
  public async sendSol({
489
501
  chainId,
490
502
  to,
@@ -760,4 +772,9 @@ export enum GetTransactionsOrder {
760
772
  DESC = 'desc',
761
773
  }
762
774
 
775
+ export enum PortalCurve {
776
+ ED25519 = 'ED25519',
777
+ SECP256K1 = 'SECP256K1',
778
+ }
779
+
763
780
  export default Portal
package/src/mpc/index.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import { PortalMpcError } from './errors'
2
2
 
3
- import Portal, { BackupMethods, GetTransactionsOrder } from '../index'
3
+ import Portal, {
4
+ BackupMethods,
5
+ GetTransactionsOrder,
6
+ PortalCurve,
7
+ } from '../index'
4
8
  import type {
5
9
  BackupArgs,
6
10
  BackupResponse,
@@ -26,7 +30,7 @@ import type {
26
30
  EjectResult,
27
31
  } from '../../types'
28
32
 
29
- const WEB_SDK_VERSION = '3.1.0'
33
+ const WEB_SDK_VERSION = '3.2.1'
30
34
 
31
35
  class Mpc {
32
36
  public iframe?: HTMLIFrameElement
@@ -339,6 +343,46 @@ class Mpc {
339
343
  })
340
344
  }
341
345
 
346
+ public async rawSign(curve: PortalCurve, param: string): Promise<string> {
347
+ return new Promise((resolve, reject) => {
348
+ const handleRawSign = (event: MessageEvent<WorkerResult>) => {
349
+ const { type, data: result } = event.data
350
+ const { origin } = event
351
+
352
+ // ignore any broadcast postMessages
353
+ if (origin !== this.getOrigin()) {
354
+ return
355
+ }
356
+
357
+ if (type === 'portal:mpc:rawSignError') {
358
+ // Remove the event listeners
359
+ window.removeEventListener('message', handleRawSign)
360
+
361
+ // Reject the promise with the error
362
+ return reject(new PortalMpcError(result as PortalError))
363
+ } else if (type === 'portal:mpc:rawSignResult') {
364
+ // Remove the event listeners
365
+ window.removeEventListener('message', handleRawSign)
366
+
367
+ // Resolve the promise with the result
368
+ resolve(result as string)
369
+ }
370
+ }
371
+
372
+ // Bind the function to the message event
373
+ window.addEventListener('message', handleRawSign)
374
+
375
+ // Send the request to the iframe
376
+ this.postMessage({
377
+ type: 'portal:mpc:rawSign',
378
+ data: {
379
+ curve,
380
+ param,
381
+ },
382
+ })
383
+ })
384
+ }
385
+
342
386
  public async sign(
343
387
  data: SignArgs,
344
388
  progress: ProgressCallback = () => {
package/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { type DkgData, PortalError } from '@portal-hq/utils'
2
2
  import type { MpcErrorCodes } from './src/mpc/errors'
3
3
 
4
- import Portal from './src/index'
4
+ import Portal, { BackupMethods } from './src/index'
5
5
 
6
6
  export type EventHandler = (event: Event<any>) => void | Promise<void>
7
7
  export type EthereumTransaction = EIP1559Transaction | LegacyTransaction
@@ -78,6 +78,7 @@ export interface ClientResponse {
78
78
  address: string
79
79
  backupStatus?: string | null
80
80
  custodian: ClientResponseCustodian
81
+ environment: ClientResponseEnvironment
81
82
  ejectedAt: string | null
82
83
  isAccountAbstracted: boolean
83
84
  metadata: ClientResponseMetadata
@@ -88,6 +89,13 @@ interface ClientResponseCustodian {
88
89
  id: string
89
90
  name: string
90
91
  }
92
+
93
+ interface ClientResponseEnvironment {
94
+ id: string
95
+ name: string
96
+ backupWithPortalEnabled: boolean
97
+ }
98
+
91
99
  interface ClientResponseMetadata {
92
100
  namespaces: ClientNamespaceMetadata
93
101
  }
@@ -102,12 +110,17 @@ interface ClientResponseSharePair {
102
110
  status: SharePairStatus
103
111
  }
104
112
 
113
+ interface ClientResponseBackupSharePair extends ClientResponseSharePair {
114
+ backupMethod: BackupMethods
115
+ }
116
+
105
117
  export interface ClientResponseWallet {
106
118
  id: string
107
119
  createdAt: string
108
120
 
109
- backupSharePairs: ClientResponseSharePair[]
121
+ backupSharePairs: ClientResponseBackupSharePair[]
110
122
  curve: WalletCurve
123
+ ejectableUntil?: string
111
124
  publicKey: string
112
125
  signingSharePairs: ClientResponseShairPair[]
113
126
  }