@dynamic-labs-wallet/core 0.0.42 → 0.0.43

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/index.cjs.js CHANGED
@@ -268,6 +268,42 @@ class BaseClient {
268
268
  }
269
269
  }
270
270
 
271
+ /**
272
+ * Creates a promise that resolves when a specific event is received from an event stream.
273
+ * Adds a timeout to prevent hanging and races the two promises.
274
+ *
275
+ * @template T The expected type of the response data
276
+ * @param apiClient The axios instance to use for API calls
277
+ * @param options The configuration options
278
+ * @returns A promise that resolves with the event data or rejects on timeout
279
+ */ const createEventStreamPromise = ({ apiClient, endpoint, body, successEventType, timeoutMs = 30000, timeoutMessage, onError })=>{
280
+ // Create a promise that will resolve when the success event is received
281
+ const eventPromise = new Promise((resolve, reject)=>{
282
+ apiClient.post(endpoint, body, {
283
+ responseType: 'stream',
284
+ headers: {
285
+ Accept: 'text/event-stream',
286
+ 'Cache-Control': 'no-cache',
287
+ Connection: 'keep-alive'
288
+ },
289
+ adapter: 'fetch'
290
+ }).then(createSuccessErrorEventStreamHandler({
291
+ onError,
292
+ reject,
293
+ resolve,
294
+ successEventType
295
+ })).catch(reject);
296
+ });
297
+ // Add a timeout to prevent hanging
298
+ const timeoutPromise = new Promise((_, reject)=>{
299
+ setTimeout(()=>reject(new Error(timeoutMessage)), timeoutMs);
300
+ });
301
+ // Return the event data as soon as it's available
302
+ return Promise.race([
303
+ eventPromise,
304
+ timeoutPromise
305
+ ]);
306
+ };
271
307
  /**
272
308
  * Creates a handler function for processing server-sent events (SSE) streams.
273
309
  * This utility manages asynchronous event-based communication with the server,
@@ -301,7 +337,6 @@ class BaseClient {
301
337
  onError == null ? void 0 : onError(createErrorFromEventData(event.data));
302
338
  }
303
339
  }
304
- // Continue reading if no conclusive event was found
305
340
  processStream();
306
341
  } catch (err) {
307
342
  reject(err instanceof Error ? err : new Error(String(err)));
@@ -359,62 +394,74 @@ class BaseClient {
359
394
  return events;
360
395
  };
361
396
 
397
+ var SuccessEventType = /*#__PURE__*/ function(SuccessEventType) {
398
+ SuccessEventType["KeygenComplete"] = "keygen_complete";
399
+ SuccessEventType["RoomCreated"] = "room_created";
400
+ return SuccessEventType;
401
+ }({});
402
+
362
403
  class DynamicApiClient extends BaseClient {
363
404
  async createWalletAccount({ chainName, clientKeygenIds, thresholdSignatureScheme, onError }) {
364
- // Create a promise that will resolve when the keygen_complete event is received
365
- const keygenCompletePromise = new Promise((resolve, reject)=>{
366
- this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/create`, {
405
+ return createEventStreamPromise({
406
+ apiClient: this.apiClient,
407
+ endpoint: `/api/v0/sdk/${this.environmentId}/waas/create`,
408
+ body: {
367
409
  chain: chainName,
368
410
  clientKeygenIds,
369
411
  thresholdSignatureScheme
370
- }, {
371
- responseType: 'stream',
372
- headers: {
373
- Accept: 'text/event-stream',
374
- 'Cache-Control': 'no-cache',
375
- Connection: 'keep-alive'
376
- },
377
- adapter: 'fetch'
378
- }).then(createSuccessErrorEventStreamHandler({
379
- onError,
380
- reject,
381
- resolve,
382
- successEventType: 'keygen_complete'
383
- })).catch(reject);
384
- });
385
- // Add a timeout to prevent hanging
386
- const timeoutPromise = new Promise((_, reject)=>{
387
- setTimeout(()=>reject(new Error('Wallet creation timed out')), 30000);
412
+ },
413
+ successEventType: SuccessEventType.KeygenComplete,
414
+ timeoutMessage: 'Wallet creation timed out',
415
+ onError
388
416
  });
389
- // Return the keygen complete data as soon as it's available
390
- return Promise.race([
391
- keygenCompletePromise,
392
- timeoutPromise
393
- ]);
394
417
  }
395
- async signMessage({ walletId, message }) {
396
- const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/signMessage`, {
397
- message
418
+ async signMessage({ walletId, message, onError }) {
419
+ return createEventStreamPromise({
420
+ apiClient: this.apiClient,
421
+ endpoint: `/api/v0/sdk/${this.environmentId}/waas/${walletId}/signMessage`,
422
+ body: {
423
+ message
424
+ },
425
+ successEventType: SuccessEventType.RoomCreated,
426
+ timeoutMessage: 'Message signing timed out',
427
+ onError
398
428
  });
399
- return data;
400
429
  }
401
- async refreshWalletAccountShares({ walletId }) {
402
- const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/refresh`);
403
- return data;
430
+ async refreshWalletAccountShares({ walletId, onError }) {
431
+ return createEventStreamPromise({
432
+ apiClient: this.apiClient,
433
+ endpoint: `/api/v0/sdk/${this.environmentId}/waas/${walletId}/refresh`,
434
+ body: undefined,
435
+ successEventType: SuccessEventType.RoomCreated,
436
+ timeoutMessage: 'Refresh timed out',
437
+ onError
438
+ });
404
439
  }
405
- async reshare({ walletId, clientKeygenIds, oldThresholdSignatureScheme, newThresholdSignatureScheme }) {
406
- const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/reshare`, {
407
- clientKeygenIds,
408
- oldThresholdSignatureScheme,
409
- newThresholdSignatureScheme
440
+ async reshare({ walletId, clientKeygenIds, oldThresholdSignatureScheme, newThresholdSignatureScheme, onError }) {
441
+ return createEventStreamPromise({
442
+ apiClient: this.apiClient,
443
+ endpoint: `/api/v0/sdk/${this.environmentId}/waas/${walletId}/reshare`,
444
+ body: {
445
+ clientKeygenIds,
446
+ oldThresholdSignatureScheme,
447
+ newThresholdSignatureScheme
448
+ },
449
+ successEventType: SuccessEventType.RoomCreated,
450
+ timeoutMessage: 'Reshare timed out',
451
+ onError
410
452
  });
411
- return data;
412
453
  }
413
- async exportKey({ walletId, exportId }) {
414
- const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/privateKey/export`, {
415
- exportId
454
+ async exportKey({ walletId, exportId, onError }) {
455
+ return createEventStreamPromise({
456
+ apiClient: this.apiClient,
457
+ endpoint: `/api/v0/sdk/${this.environmentId}/waas/${walletId}/privateKey/export`,
458
+ body: {
459
+ exportId
460
+ },
461
+ successEventType: SuccessEventType.RoomCreated,
462
+ timeoutMessage: 'Key export timed out',
463
+ onError
416
464
  });
417
- return data;
418
465
  }
419
466
  async storeEncryptedBackupByWallet({ walletId, encryptedKeyShares, passwordEncrypted }) {
420
467
  const { data } = await this.clientRelayApiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/keyShares/backup`, {
@@ -440,13 +487,19 @@ class DynamicApiClient extends BaseClient {
440
487
  return data.accessToken;
441
488
  }
442
489
  // TODO: return array instead considering cases where server has multiple parties
443
- async importPrivateKey({ chainName, clientKeygenIds, thresholdSignatureScheme }) {
444
- const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/privateKey/import`, {
445
- chain: chainName,
446
- clientKeygenIds,
447
- thresholdSignatureScheme
490
+ async importPrivateKey({ chainName, clientKeygenIds, thresholdSignatureScheme, onError }) {
491
+ return createEventStreamPromise({
492
+ apiClient: this.apiClient,
493
+ endpoint: `/api/v0/sdk/${this.environmentId}/waas/privateKey/import`,
494
+ body: {
495
+ chain: chainName,
496
+ clientKeygenIds,
497
+ thresholdSignatureScheme
498
+ },
499
+ successEventType: SuccessEventType.KeygenComplete,
500
+ timeoutMessage: 'Key import timed out',
501
+ onError
448
502
  });
449
- return data;
450
503
  }
451
504
  // TODO: consider removing the retry logics if we switch to server-sent events
452
505
  async getUser() {
package/index.esm.js CHANGED
@@ -266,6 +266,42 @@ class BaseClient {
266
266
  }
267
267
  }
268
268
 
269
+ /**
270
+ * Creates a promise that resolves when a specific event is received from an event stream.
271
+ * Adds a timeout to prevent hanging and races the two promises.
272
+ *
273
+ * @template T The expected type of the response data
274
+ * @param apiClient The axios instance to use for API calls
275
+ * @param options The configuration options
276
+ * @returns A promise that resolves with the event data or rejects on timeout
277
+ */ const createEventStreamPromise = ({ apiClient, endpoint, body, successEventType, timeoutMs = 30000, timeoutMessage, onError })=>{
278
+ // Create a promise that will resolve when the success event is received
279
+ const eventPromise = new Promise((resolve, reject)=>{
280
+ apiClient.post(endpoint, body, {
281
+ responseType: 'stream',
282
+ headers: {
283
+ Accept: 'text/event-stream',
284
+ 'Cache-Control': 'no-cache',
285
+ Connection: 'keep-alive'
286
+ },
287
+ adapter: 'fetch'
288
+ }).then(createSuccessErrorEventStreamHandler({
289
+ onError,
290
+ reject,
291
+ resolve,
292
+ successEventType
293
+ })).catch(reject);
294
+ });
295
+ // Add a timeout to prevent hanging
296
+ const timeoutPromise = new Promise((_, reject)=>{
297
+ setTimeout(()=>reject(new Error(timeoutMessage)), timeoutMs);
298
+ });
299
+ // Return the event data as soon as it's available
300
+ return Promise.race([
301
+ eventPromise,
302
+ timeoutPromise
303
+ ]);
304
+ };
269
305
  /**
270
306
  * Creates a handler function for processing server-sent events (SSE) streams.
271
307
  * This utility manages asynchronous event-based communication with the server,
@@ -299,7 +335,6 @@ class BaseClient {
299
335
  onError == null ? void 0 : onError(createErrorFromEventData(event.data));
300
336
  }
301
337
  }
302
- // Continue reading if no conclusive event was found
303
338
  processStream();
304
339
  } catch (err) {
305
340
  reject(err instanceof Error ? err : new Error(String(err)));
@@ -357,62 +392,74 @@ class BaseClient {
357
392
  return events;
358
393
  };
359
394
 
395
+ var SuccessEventType = /*#__PURE__*/ function(SuccessEventType) {
396
+ SuccessEventType["KeygenComplete"] = "keygen_complete";
397
+ SuccessEventType["RoomCreated"] = "room_created";
398
+ return SuccessEventType;
399
+ }({});
400
+
360
401
  class DynamicApiClient extends BaseClient {
361
402
  async createWalletAccount({ chainName, clientKeygenIds, thresholdSignatureScheme, onError }) {
362
- // Create a promise that will resolve when the keygen_complete event is received
363
- const keygenCompletePromise = new Promise((resolve, reject)=>{
364
- this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/create`, {
403
+ return createEventStreamPromise({
404
+ apiClient: this.apiClient,
405
+ endpoint: `/api/v0/sdk/${this.environmentId}/waas/create`,
406
+ body: {
365
407
  chain: chainName,
366
408
  clientKeygenIds,
367
409
  thresholdSignatureScheme
368
- }, {
369
- responseType: 'stream',
370
- headers: {
371
- Accept: 'text/event-stream',
372
- 'Cache-Control': 'no-cache',
373
- Connection: 'keep-alive'
374
- },
375
- adapter: 'fetch'
376
- }).then(createSuccessErrorEventStreamHandler({
377
- onError,
378
- reject,
379
- resolve,
380
- successEventType: 'keygen_complete'
381
- })).catch(reject);
382
- });
383
- // Add a timeout to prevent hanging
384
- const timeoutPromise = new Promise((_, reject)=>{
385
- setTimeout(()=>reject(new Error('Wallet creation timed out')), 30000);
410
+ },
411
+ successEventType: SuccessEventType.KeygenComplete,
412
+ timeoutMessage: 'Wallet creation timed out',
413
+ onError
386
414
  });
387
- // Return the keygen complete data as soon as it's available
388
- return Promise.race([
389
- keygenCompletePromise,
390
- timeoutPromise
391
- ]);
392
415
  }
393
- async signMessage({ walletId, message }) {
394
- const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/signMessage`, {
395
- message
416
+ async signMessage({ walletId, message, onError }) {
417
+ return createEventStreamPromise({
418
+ apiClient: this.apiClient,
419
+ endpoint: `/api/v0/sdk/${this.environmentId}/waas/${walletId}/signMessage`,
420
+ body: {
421
+ message
422
+ },
423
+ successEventType: SuccessEventType.RoomCreated,
424
+ timeoutMessage: 'Message signing timed out',
425
+ onError
396
426
  });
397
- return data;
398
427
  }
399
- async refreshWalletAccountShares({ walletId }) {
400
- const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/refresh`);
401
- return data;
428
+ async refreshWalletAccountShares({ walletId, onError }) {
429
+ return createEventStreamPromise({
430
+ apiClient: this.apiClient,
431
+ endpoint: `/api/v0/sdk/${this.environmentId}/waas/${walletId}/refresh`,
432
+ body: undefined,
433
+ successEventType: SuccessEventType.RoomCreated,
434
+ timeoutMessage: 'Refresh timed out',
435
+ onError
436
+ });
402
437
  }
403
- async reshare({ walletId, clientKeygenIds, oldThresholdSignatureScheme, newThresholdSignatureScheme }) {
404
- const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/reshare`, {
405
- clientKeygenIds,
406
- oldThresholdSignatureScheme,
407
- newThresholdSignatureScheme
438
+ async reshare({ walletId, clientKeygenIds, oldThresholdSignatureScheme, newThresholdSignatureScheme, onError }) {
439
+ return createEventStreamPromise({
440
+ apiClient: this.apiClient,
441
+ endpoint: `/api/v0/sdk/${this.environmentId}/waas/${walletId}/reshare`,
442
+ body: {
443
+ clientKeygenIds,
444
+ oldThresholdSignatureScheme,
445
+ newThresholdSignatureScheme
446
+ },
447
+ successEventType: SuccessEventType.RoomCreated,
448
+ timeoutMessage: 'Reshare timed out',
449
+ onError
408
450
  });
409
- return data;
410
451
  }
411
- async exportKey({ walletId, exportId }) {
412
- const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/privateKey/export`, {
413
- exportId
452
+ async exportKey({ walletId, exportId, onError }) {
453
+ return createEventStreamPromise({
454
+ apiClient: this.apiClient,
455
+ endpoint: `/api/v0/sdk/${this.environmentId}/waas/${walletId}/privateKey/export`,
456
+ body: {
457
+ exportId
458
+ },
459
+ successEventType: SuccessEventType.RoomCreated,
460
+ timeoutMessage: 'Key export timed out',
461
+ onError
414
462
  });
415
- return data;
416
463
  }
417
464
  async storeEncryptedBackupByWallet({ walletId, encryptedKeyShares, passwordEncrypted }) {
418
465
  const { data } = await this.clientRelayApiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/keyShares/backup`, {
@@ -438,13 +485,19 @@ class DynamicApiClient extends BaseClient {
438
485
  return data.accessToken;
439
486
  }
440
487
  // TODO: return array instead considering cases where server has multiple parties
441
- async importPrivateKey({ chainName, clientKeygenIds, thresholdSignatureScheme }) {
442
- const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/privateKey/import`, {
443
- chain: chainName,
444
- clientKeygenIds,
445
- thresholdSignatureScheme
488
+ async importPrivateKey({ chainName, clientKeygenIds, thresholdSignatureScheme, onError }) {
489
+ return createEventStreamPromise({
490
+ apiClient: this.apiClient,
491
+ endpoint: `/api/v0/sdk/${this.environmentId}/waas/privateKey/import`,
492
+ body: {
493
+ chain: chainName,
494
+ clientKeygenIds,
495
+ thresholdSignatureScheme
496
+ },
497
+ successEventType: SuccessEventType.KeygenComplete,
498
+ timeoutMessage: 'Key import timed out',
499
+ onError
446
500
  });
447
- return data;
448
501
  }
449
502
  // TODO: consider removing the retry logics if we switch to server-sent events
450
503
  async getUser() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs-wallet/core",
3
- "version": "0.0.42",
3
+ "version": "0.0.43",
4
4
  "license": "MIT",
5
5
  "dependencies": {
6
6
  "axios": "1.7.9"
package/src/api/api.d.ts CHANGED
@@ -1,10 +1,6 @@
1
1
  import type { ThresholdSignatureScheme } from '../mpc/constants';
2
2
  import { BaseClient } from './client';
3
- type KeygenCompleteResponse = {
4
- walletId: string;
5
- roomId: string;
6
- serverKeygenIds: string[];
7
- };
3
+ import { type KeygenCompleteResponse, type OpenRoomResponse, type ReshareResponse } from '../types';
8
4
  export declare class DynamicApiClient extends BaseClient {
9
5
  constructor({ environmentId, authToken, baseApiUrl, }: {
10
6
  environmentId: string;
@@ -17,23 +13,30 @@ export declare class DynamicApiClient extends BaseClient {
17
13
  thresholdSignatureScheme: ThresholdSignatureScheme;
18
14
  onError?: (error: Error) => void;
19
15
  }): Promise<KeygenCompleteResponse>;
20
- signMessage({ walletId, message, }: {
16
+ signMessage({ walletId, message, onError, }: {
21
17
  walletId: string;
22
18
  message: string;
23
- }): Promise<any>;
24
- refreshWalletAccountShares({ walletId }: {
19
+ onError?: (error: Error) => void;
20
+ }): Promise<OpenRoomResponse>;
21
+ refreshWalletAccountShares({ walletId, onError }: {
25
22
  walletId: string;
26
- }): Promise<any>;
27
- reshare({ walletId, clientKeygenIds, oldThresholdSignatureScheme, newThresholdSignatureScheme, }: {
23
+ onError?: (error: Error) => void;
24
+ }): Promise<{
25
+ roomId: string;
26
+ serverKeygenIds: string[];
27
+ }>;
28
+ reshare({ walletId, clientKeygenIds, oldThresholdSignatureScheme, newThresholdSignatureScheme, onError, }: {
28
29
  walletId: string;
29
30
  clientKeygenIds: string[];
30
31
  oldThresholdSignatureScheme: ThresholdSignatureScheme;
31
32
  newThresholdSignatureScheme: ThresholdSignatureScheme;
32
- }): Promise<any>;
33
- exportKey({ walletId, exportId, }: {
33
+ onError?: (error: Error) => void;
34
+ }): Promise<ReshareResponse>;
35
+ exportKey({ walletId, exportId, onError, }: {
34
36
  walletId: string;
35
37
  exportId: string;
36
- }): Promise<any>;
38
+ onError?: (error: Error) => void;
39
+ }): Promise<OpenRoomResponse>;
37
40
  storeEncryptedBackupByWallet({ walletId, encryptedKeyShares, passwordEncrypted, }: {
38
41
  walletId: string;
39
42
  encryptedKeyShares: string[];
@@ -49,16 +52,13 @@ export declare class DynamicApiClient extends BaseClient {
49
52
  getAccessToken({ oauthAccountId }: {
50
53
  oauthAccountId: string;
51
54
  }): Promise<any>;
52
- importPrivateKey({ chainName, clientKeygenIds, thresholdSignatureScheme, }: {
55
+ importPrivateKey({ chainName, clientKeygenIds, thresholdSignatureScheme, onError, }: {
53
56
  chainName: string;
54
57
  clientKeygenIds: string[];
55
58
  thresholdSignatureScheme: ThresholdSignatureScheme;
56
- }): Promise<{
57
- roomId: string;
58
- serverKeygenIds: string[];
59
- }>;
59
+ onError?: (error: Error) => void;
60
+ }): Promise<KeygenCompleteResponse>;
60
61
  getUser(): Promise<any>;
61
62
  refreshUser(): Promise<any>;
62
63
  }
63
- export {};
64
64
  //# sourceMappingURL=api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGtC,KAAK,sBAAsB,GAAG;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B,CA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E,MAAM,CAAA;KAAE;IASrE,8BAA8B,CAAC,EACnC,QAAQ,EACR,WAAW,GACZ,EAAE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;KACxB;IAQK,cAAc,CAAC,EAAE,cAAc,EAAE,EAAE;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE;IAS7D,gBAAgB,CAAC,EACrB,SAAS,EACT,eAAe,EACf,wBAAwB,EACxB,OAAO,GACR,EAAE;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,eAAe,EAAE,MAAM,EAAE,CAAC;QAC1B,wBAAwB,EAAE,wBAAwB,CAAC;QACnD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;KAClC;IAgBK,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC;IAsBvB,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC;CAqBlC"}
@@ -1,3 +1,23 @@
1
+ import type { AxiosInstance } from 'axios';
2
+ import type { SuccessEventType } from '../types';
3
+ /**
4
+ * Creates a promise that resolves when a specific event is received from an event stream.
5
+ * Adds a timeout to prevent hanging and races the two promises.
6
+ *
7
+ * @template T The expected type of the response data
8
+ * @param apiClient The axios instance to use for API calls
9
+ * @param options The configuration options
10
+ * @returns A promise that resolves with the event data or rejects on timeout
11
+ */
12
+ export declare const createEventStreamPromise: <T>({ apiClient, endpoint, body, successEventType, timeoutMs, timeoutMessage, onError, }: {
13
+ apiClient: AxiosInstance;
14
+ endpoint: string;
15
+ body: Record<string, unknown> | undefined;
16
+ successEventType: SuccessEventType;
17
+ timeoutMs?: number;
18
+ timeoutMessage: string;
19
+ onError?: (error: Error) => void;
20
+ }) => Promise<T>;
1
21
  /**
2
22
  * Creates a handler function for processing server-sent events (SSE) streams.
3
23
  * This utility manages asynchronous event-based communication with the server,
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/eventStream/utils.ts"],"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IAAI,CAAC;IAC3B,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAC/B,gBAAgB,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC,gBACmB;IAChB,IAAI,EAAE;QACJ,SAAS,EAAE,MAAM;YACf,IAAI,EAAE,MAAM,OAAO,CAAC;gBAAE,KAAK,EAAE,UAAU,CAAC;gBAAC,IAAI,EAAE,OAAO,CAAA;aAAE,CAAC,CAAC;SAC3D,CAAC;KACH,CAAC;CACH,SAgCF,CAAC"}
package/src/types.d.ts CHANGED
@@ -6,4 +6,22 @@ export type KeygenResult = {
6
6
  pubkey: string;
7
7
  secretShare: string;
8
8
  };
9
+ export type KeygenCompleteResponse = {
10
+ walletId: string;
11
+ roomId: string;
12
+ serverKeygenIds: string[];
13
+ };
14
+ export type OpenRoomResponse = {
15
+ roomId: string;
16
+ serverKeygenIds: string[];
17
+ };
18
+ export type ReshareResponse = {
19
+ roomId: string;
20
+ serverKeygenIds: string[];
21
+ newServerKeygenIds: string[];
22
+ };
23
+ export declare enum SuccessEventType {
24
+ KeygenComplete = "keygen_complete",
25
+ RoomCreated = "room_created"
26
+ }
9
27
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../packages/src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../packages/src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,kBAAkB,EAAE,MAAM,EAAE,CAAC;CAC9B,CAAC;AAEF,oBAAY,gBAAgB;IAC1B,cAAc,oBAAoB;IAClC,WAAW,iBAAiB;CAC7B"}