@dynamic-labs-wallet/core 0.0.0-pr384.2 → 0.0.0-pr526.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/index.cjs.js CHANGED
@@ -2,10 +2,9 @@
2
2
 
3
3
  var uuid = require('uuid');
4
4
  var axios = require('axios');
5
+ var forwardMpcClient = require('@dynamic-labs-wallet/forward-mpc-client');
6
+ var createHttpError = require('http-errors');
5
7
 
6
- const DYNAMIC_AUTH_PROD_BASE_API_URL = 'https://app.dynamicauth.com';
7
- const DYNAMIC_AUTH_PREPROD_BASE_API_URL = 'https://app.dynamic-preprod.xyz';
8
- const DYNAMIC_AUTH_DEV_BASE_API_URL = 'http://localhost:4200';
9
8
  var ENVIRONMENT_ENUM = /*#__PURE__*/ function(ENVIRONMENT_ENUM) {
10
9
  ENVIRONMENT_ENUM["development"] = "development";
11
10
  ENVIRONMENT_ENUM["preprod"] = "preprod";
@@ -15,30 +14,40 @@ var ENVIRONMENT_ENUM = /*#__PURE__*/ function(ENVIRONMENT_ENUM) {
15
14
  const DynamicRequestIdHeader = 'x-dyn-request-id';
16
15
  const DynamicClientSessionSignature = 'x-dyn-client-session-signature';
17
16
  const DynamicMfaTokenHeader = 'x-mfa-auth-token';
18
- const DYNAMIC_CLIENT_RELAY_PROD_BASE_API_URL = 'https://waas-keyshares-relay.dynamicauth.com';
19
- const DYNAMIC_CLIENT_RELAY_PREPROD_BASE_API_URL = 'https://waas-keyshares-dynamic-preprod-xyz-app-32d15525a875.relay.evervault.app';
20
- const DYNAMIC_CLIENT_RELAY_DEV_BASE_API_URL = 'https://waas-keyshares-dynamic-preprod-xyz-app-32d15525a875.relay.evervault.app';
21
- const DYNAMIC_CLIENT_RELAY_PROD_REDCOAST_API_URL = 'https://app-dynamicauth-com-app-6e12fc400995.relay.evervault.app';
22
- const DYNAMIC_CLIENT_RELAY_PREPROD_REDCOAST_API_URL = 'https://app-dynamic-preprod-xyz-app-32d15525a875.relay.evervault.app';
23
- const DYNAMIC_CLIENT_RELAY_DEV_REDCOAST_API_URL = 'http://localhost:4200';
17
+ const DynamicForwardMPCHeader = 'x-forward-mpc-client';
18
+ const DynamicTraceIdHeader = 'x-dyn-trace-id';
19
+ const DynamicTraceElapsedTimeHeader = 'x-dyn-trace-elapsed-time';
20
+ /**
21
+ * Dynamic auth base API URL to redcoast API
22
+ * NOTE: For coookie auth, we should use the configured baseApiUrl
23
+ */ const DYNAMIC_AUTH_PROD_BASE_API_URL = 'https://app.dynamicauth.com';
24
+ const DYNAMIC_AUTH_PREPROD_BASE_API_URL = 'https://app.dynamic-preprod.xyz';
25
+ const DYNAMIC_AUTH_DEV_BASE_API_URL = 'http://localhost:4200';
24
26
  const DYNAMIC_AUTH_BASE_API_URL_MAP = {
25
27
  ["production"]: DYNAMIC_AUTH_PROD_BASE_API_URL,
26
28
  ["preprod"]: DYNAMIC_AUTH_PREPROD_BASE_API_URL,
27
29
  ["development"]: DYNAMIC_AUTH_DEV_BASE_API_URL
28
30
  };
29
- const DYNAMIC_CLIENT_USER_SHARE_RELAY_MAP = {
30
- ["production"]: DYNAMIC_CLIENT_RELAY_PROD_BASE_API_URL,
31
- ["preprod"]: DYNAMIC_CLIENT_RELAY_PREPROD_BASE_API_URL,
32
- ["development"]: DYNAMIC_CLIENT_RELAY_PREPROD_BASE_API_URL
33
- };
34
- const DYNAMIC_CLIENT_RELAY_REDCOAST_MAP = {
35
- ["production"]: DYNAMIC_CLIENT_RELAY_PROD_REDCOAST_API_URL,
36
- ["preprod"]: DYNAMIC_CLIENT_RELAY_PREPROD_REDCOAST_API_URL,
37
- ["development"]: DYNAMIC_CLIENT_RELAY_DEV_REDCOAST_API_URL
31
+ /**
32
+ * Evervault keyshare encryption relay
33
+ * Note: Not used for cookie auth, we use the configured baseKeyshareRelayApiUrl
34
+ */ const DYNAMIC_KEYSHARES_RELAY_PROD_BASE_API_URL = 'https://waas-keyshares-relay.dynamicauth.com';
35
+ const DYNAMIC_KEYSHARES_RELAY_PREPROD_BASE_API_URL = 'https://waas-keyshares-relay.dynamic-preprod.xyz';
36
+ const DYNAMIC_KEYSHARES_RELAY_MAP = {
37
+ ["production"]: DYNAMIC_KEYSHARES_RELAY_PROD_BASE_API_URL,
38
+ ["preprod"]: DYNAMIC_KEYSHARES_RELAY_PREPROD_BASE_API_URL,
39
+ ["development"]: DYNAMIC_KEYSHARES_RELAY_PREPROD_BASE_API_URL
38
40
  };
39
- const MPC_RELAY_PROD_API_URL = 'relay.dynamicauth.com';
41
+ /**
42
+ * Dymamic MPC relay where the MPC operations are performed (NOT keyshare relay in Evervault)
43
+ */ const MPC_RELAY_PROD_API_URL = 'relay.dynamicauth.com';
40
44
  const MPC_RELAY_PREPROD_API_URL = 'relay.dynamic-preprod.xyz';
41
45
  const MPC_RELAY_DEV_API_URL = 'http://localhost:4200';
46
+ const MPC_RELAY_URL_MAP = {
47
+ ["production"]: MPC_RELAY_PROD_API_URL,
48
+ ["preprod"]: MPC_RELAY_PREPROD_API_URL,
49
+ ["development"]: MPC_RELAY_DEV_API_URL
50
+ };
42
51
  const RELAY_APP_ID_HEADER = 'X-Evervault-App-Id';
43
52
  const PROD_RELAY_APP_ID = 'app_6e12fc400995';
44
53
  const PREPROD_RELAY_APP_ID = 'app_32d15525a875';
@@ -82,6 +91,7 @@ var BackupLocation = /*#__PURE__*/ function(BackupLocation) {
82
91
  BackupLocation["ICLOUD"] = "iCloud";
83
92
  BackupLocation["USER"] = "user";
84
93
  BackupLocation["EXTERNAL"] = "external";
94
+ BackupLocation["DELEGATED"] = "delegated";
85
95
  return BackupLocation;
86
96
  }({});
87
97
  const IFRAME_DOMAIN_MAP = {
@@ -103,7 +113,27 @@ const verifiedCredentialNameToChainEnum = {
103
113
  };
104
114
  const DELEGATED_SHARE_COUNT = 1;
105
115
  const FEATURE_FLAGS = {
106
- ENABLE_DELEGATED_KEY_SHARES_FLAG: 'enable-delegated-key-shares'
116
+ ENABLE_DELEGATED_KEY_SHARES_FLAG: 'enable-delegated-key-shares',
117
+ ENABLE_FORWARD_MPC_CLIENT_FLAG: 'enable-forward-mpc-client'
118
+ };
119
+ const DYNAMIC_FORWARD_MPC_PROD_ENCLAVE_URL = 'wss://forward-mpc-client-prod.app-bf095f298b04.enclave.evervault.com/ws';
120
+ const DYNAMIC_FORWARD_MPC_PREPROD_ENCLAVE_URL = 'wss://forward-mpc-client-preprod.app-560a39ebfe3b.enclave.evervault.com/ws';
121
+ const DYNAMIC_FORWARD_MPC_DEV_ENCLAVE_URL = 'ws://localhost:8008/ws';
122
+ const DYNAMIC_FORWARD_MPC_ENCLAVE_URL_MAP = {
123
+ ["production"]: DYNAMIC_FORWARD_MPC_PROD_ENCLAVE_URL,
124
+ ["preprod"]: DYNAMIC_FORWARD_MPC_PREPROD_ENCLAVE_URL,
125
+ ["development"]: DYNAMIC_FORWARD_MPC_DEV_ENCLAVE_URL
126
+ };
127
+ const DYNAMIC_FORWARD_MPC_ENCLAVE_ATTESTATION_CONFIG_MAP = {
128
+ ["production"]: {
129
+ expectedPcr8: '484fd412249304fe7659b2a9a4869504f0e4502d8abb4f88183e65416b4f62354e4eda60e80a5b2e9d730ab0d804f83e',
130
+ strictCertValidation: true
131
+ },
132
+ ["preprod"]: {
133
+ expectedPcr8: 'acc59ec98dbf7ecb43f9a6b9890866141868c079aa879e05e3675e1a10e187259a64951e72cc531541b02dbdcd780770',
134
+ strictCertValidation: true
135
+ },
136
+ ["development"]: undefined
107
137
  };
108
138
 
109
139
  var SigningAlgorithm = /*#__PURE__*/ function(SigningAlgorithm) {
@@ -445,7 +475,7 @@ const getDynamicServerThreshold = (thresholdSignatureScheme)=>{
445
475
  };
446
476
  const URL_PATTERNS = {
447
477
  [ENVIRONMENT_ENUM.development]: /^http:\/\/localhost:\d+$/,
448
- [ENVIRONMENT_ENUM.preprod]: /dynamic-preprod/,
478
+ [ENVIRONMENT_ENUM.preprod]: /-preprod/,
449
479
  [ENVIRONMENT_ENUM.production]: /^(?!.*dynamic-preprod)(?!http:\/\/localhost:\d+).*/
450
480
  };
451
481
  function getEnvironmentFromUrl(url) {
@@ -484,6 +514,9 @@ var SuccessEventType = /*#__PURE__*/ function(SuccessEventType) {
484
514
  return SuccessEventType;
485
515
  }({});
486
516
 
517
+ const getElapsedTime = (startTime)=>{
518
+ return startTime ? (Date.now() - startTime).toString() : undefined;
519
+ };
487
520
  /**
488
521
  * Creates a promise that resolves when a specific event is received from an event stream.
489
522
  * Adds a timeout to prevent hanging and races the two promises.
@@ -492,13 +525,16 @@ var SuccessEventType = /*#__PURE__*/ function(SuccessEventType) {
492
525
  * @param apiClient The axios instance to use for API calls
493
526
  * @param options The configuration options
494
527
  * @returns A promise that resolves with the event data or rejects on timeout
495
- */ const createEventStreamPromise = ({ apiClient, dynamicRequestId, endpoint, body, successEventType, timeoutMs = 30000, timeoutMessage, onError, onCeremonyComplete, mfaToken })=>{
528
+ */ const createEventStreamPromise = ({ apiClient, dynamicRequestId, endpoint, body, successEventType, timeoutMs = 30000, timeoutMessage, onError, onCeremonyComplete, mfaToken, forwardMPCClientEnabled, traceContext })=>{
496
529
  const headers = {
497
530
  Accept: 'text/event-stream',
498
531
  'Cache-Control': 'no-cache',
499
532
  Connection: 'keep-alive',
500
533
  [DynamicRequestIdHeader]: dynamicRequestId,
501
- [DynamicMfaTokenHeader]: mfaToken
534
+ [DynamicMfaTokenHeader]: mfaToken,
535
+ [DynamicForwardMPCHeader]: forwardMPCClientEnabled,
536
+ [DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
537
+ [DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
502
538
  };
503
539
  // Create a promise that will resolve when the success event is received
504
540
  const eventPromise = new Promise((resolve, reject)=>{
@@ -638,8 +674,8 @@ class BaseClient {
638
674
  throw new Error('Failed to sync auth token, auth header is not set to the expected auth token after sync, there is likely a race condition, contact Dynamic devs to investigate');
639
675
  }
640
676
  }
641
- constructor({ environmentId, baseApiUrl, authToken, baseClientRelayApiUrl, authMode = AuthMode.HEADER, // Represents the version of the client SDK used by developer
642
- sdkVersion }){
677
+ constructor({ environmentId, baseApiUrl, authToken, baseClientKeysharesRelayApiUrl, authMode = AuthMode.HEADER, // Represents the version of the client SDK used by developer
678
+ sdkVersion, forwardMPCClient }){
643
679
  const headers = {};
644
680
  // Only set Authorization header if using header auth mode and token is provided
645
681
  if (authMode === AuthMode.HEADER && authToken) {
@@ -659,14 +695,28 @@ class BaseClient {
659
695
  withCredentials: true
660
696
  } : {});
661
697
  this.apiClient = axios.create(axiosConfig);
662
- this.clientRelayBaseApiUrl = baseClientRelayApiUrl != null ? baseClientRelayApiUrl : DYNAMIC_CLIENT_USER_SHARE_RELAY_MAP[environment];
698
+ this.clientKeysharesRelayBaseApiUrl = baseClientKeysharesRelayApiUrl != null ? baseClientKeysharesRelayApiUrl : DYNAMIC_KEYSHARES_RELAY_MAP[environment];
663
699
  this.clientRelayApiClient = axios.create({
664
- baseURL: this.clientRelayBaseApiUrl,
700
+ baseURL: this.clientKeysharesRelayBaseApiUrl,
665
701
  headers: _extends({}, headers, {
666
702
  [RELAY_API_KEY_HEADER]: DYNAMIC_CLIENT_RELAY_REDCOAST_API_KEY_MAP[environment],
667
703
  [RELAY_APP_ID_HEADER]: DYNAMIC_CLIENT_RELAY_REDCOAST_APP_ID_MAP[environment]
668
704
  })
669
705
  });
706
+ // Use provided ForwardMPCClient or create a new one
707
+ if (forwardMPCClient) {
708
+ this.forwardMPCClient = forwardMPCClient;
709
+ } else {
710
+ const forwardMPCEnclaveUrl = DYNAMIC_FORWARD_MPC_ENCLAVE_URL_MAP[environment];
711
+ const attestationConfig = DYNAMIC_FORWARD_MPC_ENCLAVE_ATTESTATION_CONFIG_MAP[environment];
712
+ this.forwardMPCClient = new forwardMpcClient.ForwardMPCClient(forwardMPCEnclaveUrl != null ? forwardMPCEnclaveUrl : '', {
713
+ reconnectInterval: 5000,
714
+ reconnectAttempts: 5,
715
+ connectionTimeout: 10000,
716
+ heartbeatInterval: 30000,
717
+ attestationConfig
718
+ });
719
+ }
670
720
  }
671
721
  }
672
722
 
@@ -678,23 +728,26 @@ class DynamicApiClient extends BaseClient {
678
728
  }
679
729
  });
680
730
  }
681
- async createWalletAccount({ chainName, clientKeygenIds, dynamicRequestId, thresholdSignatureScheme, onError, onCeremonyComplete }) {
731
+ async createWalletAccount({ chainName, clientKeygenIds, dynamicRequestId, thresholdSignatureScheme, skipLock, onError, onCeremonyComplete, traceContext }) {
682
732
  return createEventStreamPromise({
683
733
  apiClient: this.apiClient,
684
734
  dynamicRequestId,
685
735
  endpoint: `/api/v0/sdk/${this.environmentId}/waas/create`,
686
- body: {
736
+ body: _extends({
687
737
  chain: chainName,
688
738
  clientKeygenIds,
689
739
  thresholdSignatureScheme
690
- },
740
+ }, skipLock ? {
741
+ skipLock
742
+ } : {}),
691
743
  successEventType: SuccessEventType.KeygenComplete,
692
744
  timeoutMessage: 'Wallet creation timed out',
693
745
  onError,
694
- onCeremonyComplete
746
+ onCeremonyComplete,
747
+ traceContext
695
748
  });
696
749
  }
697
- async signMessage({ dynamicRequestId, walletId, message, onError, isFormatted, mfaToken, context }) {
750
+ async signMessage({ dynamicRequestId, walletId, message, onError, isFormatted, mfaToken, roomId, context, forwardMPCClientEnabled, traceContext }) {
698
751
  return createEventStreamPromise({
699
752
  apiClient: this.apiClient,
700
753
  dynamicRequestId,
@@ -702,15 +755,18 @@ class DynamicApiClient extends BaseClient {
702
755
  body: {
703
756
  message,
704
757
  isFormatted,
705
- context
758
+ context,
759
+ roomId
706
760
  },
707
761
  successEventType: SuccessEventType.RoomCreated,
708
762
  timeoutMessage: 'Message signing timed out',
709
763
  onError,
710
- mfaToken
764
+ mfaToken,
765
+ forwardMPCClientEnabled,
766
+ traceContext
711
767
  });
712
768
  }
713
- async refreshWalletAccountShares({ dynamicRequestId, walletId, onError, mfaToken }) {
769
+ async refreshWalletAccountShares({ dynamicRequestId, walletId, onError, mfaToken, traceContext }) {
714
770
  return createEventStreamPromise({
715
771
  apiClient: this.apiClient,
716
772
  dynamicRequestId,
@@ -719,27 +775,30 @@ class DynamicApiClient extends BaseClient {
719
775
  successEventType: SuccessEventType.RoomCreated,
720
776
  timeoutMessage: 'Refresh timed out',
721
777
  onError,
722
- mfaToken
778
+ mfaToken,
779
+ traceContext
723
780
  });
724
781
  }
725
- async reshare({ walletId, dynamicRequestId, clientKeygenIds, oldThresholdSignatureScheme, newThresholdSignatureScheme, delegateToProjectEnvironment, mfaToken, onError }) {
782
+ async reshare({ walletId, dynamicRequestId, clientKeygenIds, oldThresholdSignatureScheme, newThresholdSignatureScheme, delegateToProjectEnvironment, revokeDelegation, mfaToken, onError, traceContext }) {
726
783
  return createEventStreamPromise({
727
784
  apiClient: this.apiClient,
728
785
  dynamicRequestId,
729
786
  endpoint: `/api/v0/sdk/${this.environmentId}/waas/${walletId}/reshare`,
730
787
  body: {
731
788
  clientKeygenIds,
732
- oldThresholdSignatureScheme,
789
+ delegateToProjectEnvironment,
733
790
  newThresholdSignatureScheme,
734
- delegateToProjectEnvironment
791
+ oldThresholdSignatureScheme,
792
+ revokeDelegation
735
793
  },
736
794
  successEventType: SuccessEventType.RoomCreated,
737
795
  timeoutMessage: 'Reshare timed out',
738
796
  onError,
739
- mfaToken
797
+ mfaToken,
798
+ traceContext
740
799
  });
741
800
  }
742
- async exportKey({ mfaToken, dynamicRequestId, walletId, exportId, onError }) {
801
+ async exportKey({ mfaToken, dynamicRequestId, walletId, exportId, onError, traceContext }) {
743
802
  return createEventStreamPromise({
744
803
  apiClient: this.apiClient,
745
804
  dynamicRequestId,
@@ -750,18 +809,45 @@ class DynamicApiClient extends BaseClient {
750
809
  successEventType: SuccessEventType.RoomCreated,
751
810
  timeoutMessage: 'Key export timed out',
752
811
  onError,
753
- mfaToken
812
+ mfaToken,
813
+ traceContext
754
814
  });
755
815
  }
756
- async storeEncryptedBackupByWallet({ walletId, encryptedKeyShares, passwordEncrypted, signedSessionId, encryptionVersion, requiresSignedSessionId = false, authMode = AuthMode.HEADER, dynamicRequestId }) {
816
+ async getDelegatedEncryptionKey({ environmentId, traceContext }) {
817
+ const { data } = await this.apiClient.get(`/api/v0/sdk/${environmentId}/waas/delegatedAccess/encryptionPublicKey`, {
818
+ headers: {
819
+ [DynamicRequestIdHeader]: uuid.v4().replace('-', ''),
820
+ [DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
821
+ [DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
822
+ }
823
+ });
824
+ return data;
825
+ }
826
+ async publishDelegatedKeyShare({ walletId, encryptedKeyShare, signedSessionId, requiresSignedSessionId = false, dynamicRequestId, traceContext }) {
827
+ if (requiresSignedSessionId && !signedSessionId) {
828
+ throw new Error('Signed session ID is required');
829
+ }
830
+ const apiClient = this.apiClient;
831
+ const { data, status } = await apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/delegatedAccess/delivery`, {
832
+ encryptedDelegatedShare: encryptedKeyShare
833
+ }, {
834
+ headers: {
835
+ [DynamicRequestIdHeader]: dynamicRequestId,
836
+ [DynamicClientSessionSignature]: signedSessionId,
837
+ [DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
838
+ [DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
839
+ }
840
+ });
841
+ return {
842
+ data,
843
+ status
844
+ };
845
+ }
846
+ async storeEncryptedBackupByWallet({ walletId, encryptedKeyShares, passwordEncrypted, signedSessionId, encryptionVersion, requiresSignedSessionId = false, authMode = AuthMode.HEADER, dynamicRequestId, traceContext }) {
757
847
  if (requiresSignedSessionId && !signedSessionId) {
758
848
  throw new Error('Signed session ID is required');
759
849
  }
760
- // When using cookie-based authentication, use the main apiClient instead of clientRelayApiClient.
761
- // This ensures requests are sent to the same domain, allowing cookies to be included and maintaining session continuity.
762
- // For header-based auth, clientRelayApiClient is used as usual.
763
- const apiClient = authMode === AuthMode.COOKIE ? this.apiClient : this.clientRelayApiClient;
764
- const { data } = await apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/keyShares/backup`, {
850
+ const { data } = await this.clientRelayApiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/keyShares/backup`, {
765
851
  // TODO: decide on whether to store encryptedAccountCredentials or encryptedKeyShares as backup
766
852
  encryptedAccountCredentials: encryptedKeyShares,
767
853
  passwordEncrypted,
@@ -769,11 +855,15 @@ class DynamicApiClient extends BaseClient {
769
855
  }, {
770
856
  headers: {
771
857
  [DynamicRequestIdHeader]: dynamicRequestId,
772
- [DynamicClientSessionSignature]: signedSessionId
773
- }
858
+ [DynamicClientSessionSignature]: signedSessionId,
859
+ [DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
860
+ [DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
861
+ },
862
+ withCredentials: authMode === AuthMode.COOKIE ? true : undefined
774
863
  });
775
864
  return data;
776
865
  }
866
+ // TODO: is this still used? if not, remove it
777
867
  async markKeySharesAsBackedUpGoogleDrive({ walletId }) {
778
868
  const { data } = await this.clientRelayApiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/keyShares/backup/googleDrive`, {}, {
779
869
  headers: {
@@ -782,46 +872,49 @@ class DynamicApiClient extends BaseClient {
782
872
  });
783
873
  return data;
784
874
  }
785
- async markKeySharesAsBackedUp({ walletId, locations, dynamicRequestId }) {
875
+ async markKeySharesAsBackedUp({ walletId, locations, dynamicRequestId, traceContext }) {
786
876
  const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/keyShares/backup/locations`, {
787
877
  locations
788
878
  }, {
789
879
  headers: {
790
- [DynamicRequestIdHeader]: dynamicRequestId
880
+ [DynamicRequestIdHeader]: dynamicRequestId,
881
+ [DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
882
+ [DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
791
883
  }
792
884
  });
793
885
  return data;
794
886
  }
795
- async recoverEncryptedBackupByWallet({ walletId, keyShareIds, signedSessionId, mfaToken, requiresSignedSessionId = false, authMode = AuthMode.HEADER }) {
887
+ async recoverEncryptedBackupByWallet({ walletId, keyShareIds, signedSessionId, mfaToken, requiresSignedSessionId = false, authMode = AuthMode.HEADER, traceContext }) {
796
888
  if (requiresSignedSessionId && !signedSessionId) {
797
889
  throw new Error('Signed session ID is required');
798
890
  }
799
- // When using cookie-based authentication, use the main apiClient instead of clientRelayApiClient.
800
- // This ensures requests are sent to the same domain, allowing cookies to be included and maintaining session continuity.
801
- // For header-based auth, clientRelayApiClient is used as usual.
802
- const apiClient = authMode === AuthMode.COOKIE ? this.apiClient : this.clientRelayApiClient;
803
891
  // TODO: add signed messsage to body?
804
- const { data } = await apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/keyShares/recover`, keyShareIds ? {
892
+ const { data } = await this.clientRelayApiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/keyShares/recover`, keyShareIds ? {
805
893
  keyShareIds
806
894
  } : undefined, {
807
895
  headers: {
808
896
  [DynamicRequestIdHeader]: uuid.v4().replace('-', ''),
809
897
  [DynamicClientSessionSignature]: signedSessionId,
810
- [DynamicMfaTokenHeader]: mfaToken
811
- }
898
+ [DynamicMfaTokenHeader]: mfaToken,
899
+ [DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
900
+ [DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
901
+ },
902
+ withCredentials: authMode === AuthMode.COOKIE ? true : undefined
812
903
  });
813
904
  return data;
814
905
  }
815
- async getAccessToken({ oauthAccountId }) {
906
+ async getAccessToken({ oauthAccountId, traceContext }) {
816
907
  const { data } = await this.apiClient.get(`/api/v0/sdk/${this.environmentId}/oauthAccounts/${oauthAccountId}/accessToken`, {
817
908
  headers: {
818
- [DynamicRequestIdHeader]: uuid.v4().replace('-', '')
909
+ [DynamicRequestIdHeader]: uuid.v4().replace('-', ''),
910
+ [DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
911
+ [DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
819
912
  }
820
913
  });
821
914
  return data.accessToken;
822
915
  }
823
916
  // TODO: return array instead considering cases where server has multiple parties
824
- async importPrivateKey({ chainName, dynamicRequestId, clientKeygenIds, thresholdSignatureScheme, onError, onCeremonyComplete }) {
917
+ async importPrivateKey({ chainName, dynamicRequestId, clientKeygenIds, thresholdSignatureScheme, onError, onCeremonyComplete, traceContext }) {
825
918
  return createEventStreamPromise({
826
919
  apiClient: this.apiClient,
827
920
  dynamicRequestId,
@@ -834,11 +927,12 @@ class DynamicApiClient extends BaseClient {
834
927
  successEventType: SuccessEventType.KeygenComplete,
835
928
  timeoutMessage: 'Key import timed out',
836
929
  onError,
837
- onCeremonyComplete
930
+ onCeremonyComplete,
931
+ traceContext
838
932
  });
839
933
  }
840
934
  // TODO: consider removing the retry logics if we switch to server-sent events
841
- async getUser(dynamicRequestId) {
935
+ async getUser(dynamicRequestId, traceContext) {
842
936
  let attempts = 0;
843
937
  const maxAttempts = 5;
844
938
  const retryInterval = 1000; // 1 second interval for each retry
@@ -846,7 +940,9 @@ class DynamicApiClient extends BaseClient {
846
940
  try {
847
941
  const { data } = await this.apiClient.get(`/api/v0/sdk/${this.environmentId}/users`, {
848
942
  headers: {
849
- [DynamicRequestIdHeader]: dynamicRequestId
943
+ [DynamicRequestIdHeader]: dynamicRequestId,
944
+ [DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
945
+ [DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
850
946
  }
851
947
  });
852
948
  return data;
@@ -860,7 +956,7 @@ class DynamicApiClient extends BaseClient {
860
956
  }
861
957
  }
862
958
  // TODO: consider removing the retry logics if we switch to server-sent events
863
- async refreshUser() {
959
+ async refreshUser(traceContext) {
864
960
  let attempts = 0;
865
961
  const maxAttempts = 5;
866
962
  const retryInterval = 1000; // 1 second interval for each retry
@@ -868,7 +964,9 @@ class DynamicApiClient extends BaseClient {
868
964
  try {
869
965
  const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/refresh`, undefined, {
870
966
  headers: {
871
- [DynamicRequestIdHeader]: uuid.v4().replace('-', '')
967
+ [DynamicRequestIdHeader]: uuid.v4().replace('-', ''),
968
+ [DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
969
+ [DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
872
970
  }
873
971
  });
874
972
  return data;
@@ -881,22 +979,92 @@ class DynamicApiClient extends BaseClient {
881
979
  }
882
980
  }
883
981
  }
884
- async getEnvironmentSettings() {
982
+ async getEnvironmentSettings(traceContext) {
885
983
  const { data } = await this.apiClient.get(`/api/v0/sdk/${this.environmentId}/settings`, {
886
984
  headers: {
887
- [DynamicRequestIdHeader]: uuid.v4().replace('-', '')
985
+ [DynamicRequestIdHeader]: uuid.v4().replace('-', ''),
986
+ [DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
987
+ [DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
988
+ }
989
+ });
990
+ return data;
991
+ }
992
+ async getWaasWalletById({ walletId, traceContext }) {
993
+ const { data } = await this.apiClient.get(`/api/v0/environments/${this.environmentId}/waas/${walletId}`, {
994
+ headers: {
995
+ [DynamicRequestIdHeader]: uuid.v4().replace('-', ''),
996
+ [DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
997
+ [DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
998
+ }
999
+ });
1000
+ return data;
1001
+ }
1002
+ /**
1003
+ * Fetch a single WaaS wallet by ID using the /sdk/{environmentId}/waas/{walletId} endpoint.
1004
+ * This endpoint returns user information with verified credentials filtered to only include the specified WaaS wallet.
1005
+ */ async getWaasWalletByAddress({ walletAddress, traceContext }) {
1006
+ const { data } = await this.apiClient.get(`/api/v0/sdk/${this.environmentId}/waas/byWalletAddress/${walletAddress}`, {
1007
+ headers: {
1008
+ [DynamicRequestIdHeader]: uuid.v4().replace('-', ''),
1009
+ [DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
1010
+ [DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
1011
+ }
1012
+ });
1013
+ return data;
1014
+ }
1015
+ async delegatedSignMessage({ walletId, message, isFormatted, dynamicRequestId, onError, context, traceContext }) {
1016
+ return createEventStreamPromise({
1017
+ apiClient: this.apiClient,
1018
+ dynamicRequestId,
1019
+ endpoint: `/api/v0/environments/${this.environmentId}/waas/${walletId}/delegatedAccess/signMessage`,
1020
+ body: {
1021
+ message,
1022
+ isFormatted,
1023
+ context
1024
+ },
1025
+ successEventType: SuccessEventType.RoomCreated,
1026
+ timeoutMessage: 'Delegated sign message timed out',
1027
+ onError,
1028
+ traceContext
1029
+ });
1030
+ }
1031
+ async createRooms({ walletId, roomType, roomCount = 5, traceContext }) {
1032
+ const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/createRooms`, {
1033
+ roomCount,
1034
+ roomType
1035
+ }, {
1036
+ headers: {
1037
+ [DynamicRequestIdHeader]: uuid.v4().replace('-', ''),
1038
+ [DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
1039
+ [DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
1040
+ }
1041
+ });
1042
+ return data;
1043
+ }
1044
+ async createRoomsWithoutWalletId({ roomType, thresholdSignatureScheme, roomCount = 5, traceContext }) {
1045
+ const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/createRooms`, {
1046
+ roomCount,
1047
+ roomType,
1048
+ thresholdSignatureScheme
1049
+ }, {
1050
+ headers: {
1051
+ [DynamicRequestIdHeader]: uuid.v4().replace('-', ''),
1052
+ [DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
1053
+ [DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
888
1054
  }
889
1055
  });
890
1056
  return data;
891
1057
  }
892
1058
  constructor({ environmentId, authToken, baseApiUrl, authMode = AuthMode.HEADER, // Represents the version of the client SDK used by developer
893
- sdkVersion }){
1059
+ sdkVersion, forwardMPCClient, baseClientKeysharesRelayApiUrl }){
894
1060
  super({
895
1061
  environmentId,
896
1062
  authToken: authToken || '',
897
1063
  baseApiUrl,
898
1064
  authMode,
899
- sdkVersion
1065
+ sdkVersion,
1066
+ forwardMPCClient,
1067
+ baseClientKeysharesRelayApiUrl
900
1068
  });
901
1069
  }
902
1070
  }
@@ -966,6 +1134,48 @@ const SDK_NAMESPACE = {
966
1134
  return parsed ? parsed.namespace : null;
967
1135
  }
968
1136
 
1137
+ const serializeMessageForForwardMPC = ({ message, isFormatted = false, chainName })=>{
1138
+ let serializedMessage = message;
1139
+ if (isFormatted && chainName === 'EVM') {
1140
+ if (typeof message === 'string') {
1141
+ // Handle hex string (with or without 0x prefix)
1142
+ const cleanHex = message.startsWith('0x') ? message.slice(2) : message;
1143
+ serializedMessage = cleanHex;
1144
+ } else if (message instanceof Uint8Array) {
1145
+ serializedMessage = Buffer.from(message).toString('hex');
1146
+ } else if (message instanceof MessageHash) {
1147
+ serializedMessage = message.toHex();
1148
+ } else {
1149
+ throw new Error('Unsupported formatted message format');
1150
+ }
1151
+ }
1152
+ return serializedMessage;
1153
+ };
1154
+
1155
+ const handleAxiosError = (error, message, context, logger)=>{
1156
+ var _error_response, _error_response1, _error_response2;
1157
+ logger.error('[DynamicWaasWalletClient] Axios error: ', {
1158
+ message,
1159
+ error: (_error_response = error.response) == null ? void 0 : _error_response.data,
1160
+ status: (_error_response1 = error.response) == null ? void 0 : _error_response1.status,
1161
+ context
1162
+ });
1163
+ switch((_error_response2 = error.response) == null ? void 0 : _error_response2.status){
1164
+ case 400:
1165
+ throw createHttpError(400, 'Invalid request');
1166
+ case 401:
1167
+ throw createHttpError(401, 'Authorization header or cookie is required');
1168
+ case 403:
1169
+ throw createHttpError(403, 'Forbidden');
1170
+ case 422:
1171
+ throw createHttpError(422, 'Unprocessable content');
1172
+ case 500:
1173
+ throw createHttpError(500, 'Internal server error');
1174
+ default:
1175
+ throw createHttpError(500, 'Internal server error');
1176
+ }
1177
+ };
1178
+
969
1179
  exports.AuthMode = AuthMode;
970
1180
  exports.BITCOIN_DERIVATION_PATHS = BITCOIN_DERIVATION_PATHS;
971
1181
  exports.BackupLocation = BackupLocation;
@@ -975,20 +1185,23 @@ exports.DYNAMIC_AUTH_BASE_API_URL_MAP = DYNAMIC_AUTH_BASE_API_URL_MAP;
975
1185
  exports.DYNAMIC_AUTH_DEV_BASE_API_URL = DYNAMIC_AUTH_DEV_BASE_API_URL;
976
1186
  exports.DYNAMIC_AUTH_PREPROD_BASE_API_URL = DYNAMIC_AUTH_PREPROD_BASE_API_URL;
977
1187
  exports.DYNAMIC_AUTH_PROD_BASE_API_URL = DYNAMIC_AUTH_PROD_BASE_API_URL;
978
- exports.DYNAMIC_CLIENT_RELAY_DEV_BASE_API_URL = DYNAMIC_CLIENT_RELAY_DEV_BASE_API_URL;
979
- exports.DYNAMIC_CLIENT_RELAY_DEV_REDCOAST_API_URL = DYNAMIC_CLIENT_RELAY_DEV_REDCOAST_API_URL;
980
- exports.DYNAMIC_CLIENT_RELAY_PREPROD_BASE_API_URL = DYNAMIC_CLIENT_RELAY_PREPROD_BASE_API_URL;
981
- exports.DYNAMIC_CLIENT_RELAY_PREPROD_REDCOAST_API_URL = DYNAMIC_CLIENT_RELAY_PREPROD_REDCOAST_API_URL;
982
- exports.DYNAMIC_CLIENT_RELAY_PROD_BASE_API_URL = DYNAMIC_CLIENT_RELAY_PROD_BASE_API_URL;
983
- exports.DYNAMIC_CLIENT_RELAY_PROD_REDCOAST_API_URL = DYNAMIC_CLIENT_RELAY_PROD_REDCOAST_API_URL;
984
1188
  exports.DYNAMIC_CLIENT_RELAY_REDCOAST_API_KEY_MAP = DYNAMIC_CLIENT_RELAY_REDCOAST_API_KEY_MAP;
985
1189
  exports.DYNAMIC_CLIENT_RELAY_REDCOAST_APP_ID_MAP = DYNAMIC_CLIENT_RELAY_REDCOAST_APP_ID_MAP;
986
- exports.DYNAMIC_CLIENT_RELAY_REDCOAST_MAP = DYNAMIC_CLIENT_RELAY_REDCOAST_MAP;
987
- exports.DYNAMIC_CLIENT_USER_SHARE_RELAY_MAP = DYNAMIC_CLIENT_USER_SHARE_RELAY_MAP;
1190
+ exports.DYNAMIC_FORWARD_MPC_DEV_ENCLAVE_URL = DYNAMIC_FORWARD_MPC_DEV_ENCLAVE_URL;
1191
+ exports.DYNAMIC_FORWARD_MPC_ENCLAVE_ATTESTATION_CONFIG_MAP = DYNAMIC_FORWARD_MPC_ENCLAVE_ATTESTATION_CONFIG_MAP;
1192
+ exports.DYNAMIC_FORWARD_MPC_ENCLAVE_URL_MAP = DYNAMIC_FORWARD_MPC_ENCLAVE_URL_MAP;
1193
+ exports.DYNAMIC_FORWARD_MPC_PREPROD_ENCLAVE_URL = DYNAMIC_FORWARD_MPC_PREPROD_ENCLAVE_URL;
1194
+ exports.DYNAMIC_FORWARD_MPC_PROD_ENCLAVE_URL = DYNAMIC_FORWARD_MPC_PROD_ENCLAVE_URL;
1195
+ exports.DYNAMIC_KEYSHARES_RELAY_MAP = DYNAMIC_KEYSHARES_RELAY_MAP;
1196
+ exports.DYNAMIC_KEYSHARES_RELAY_PREPROD_BASE_API_URL = DYNAMIC_KEYSHARES_RELAY_PREPROD_BASE_API_URL;
1197
+ exports.DYNAMIC_KEYSHARES_RELAY_PROD_BASE_API_URL = DYNAMIC_KEYSHARES_RELAY_PROD_BASE_API_URL;
988
1198
  exports.DynamicApiClient = DynamicApiClient;
989
1199
  exports.DynamicClientSessionSignature = DynamicClientSessionSignature;
1200
+ exports.DynamicForwardMPCHeader = DynamicForwardMPCHeader;
990
1201
  exports.DynamicMfaTokenHeader = DynamicMfaTokenHeader;
991
1202
  exports.DynamicRequestIdHeader = DynamicRequestIdHeader;
1203
+ exports.DynamicTraceElapsedTimeHeader = DynamicTraceElapsedTimeHeader;
1204
+ exports.DynamicTraceIdHeader = DynamicTraceIdHeader;
992
1205
  exports.ENVIRONMENT_ENUM = ENVIRONMENT_ENUM;
993
1206
  exports.FEATURE_FLAGS = FEATURE_FLAGS;
994
1207
  exports.IFRAME_DOMAIN_MAP = IFRAME_DOMAIN_MAP;
@@ -997,6 +1210,7 @@ exports.MPC_CONFIG = MPC_CONFIG;
997
1210
  exports.MPC_RELAY_DEV_API_URL = MPC_RELAY_DEV_API_URL;
998
1211
  exports.MPC_RELAY_PREPROD_API_URL = MPC_RELAY_PREPROD_API_URL;
999
1212
  exports.MPC_RELAY_PROD_API_URL = MPC_RELAY_PROD_API_URL;
1213
+ exports.MPC_RELAY_URL_MAP = MPC_RELAY_URL_MAP;
1000
1214
  exports.PREPROD_RELAY_API_KEY = PREPROD_RELAY_API_KEY;
1001
1215
  exports.PREPROD_RELAY_APP_ID = PREPROD_RELAY_APP_ID;
1002
1216
  exports.PROD_RELAY_API_KEY = PROD_RELAY_API_KEY;
@@ -1022,5 +1236,7 @@ exports.getServerWalletReshareConfig = getServerWalletReshareConfig;
1022
1236
  exports.getTSSConfig = getTSSConfig;
1023
1237
  exports.getVersionNamespace = getVersionNamespace;
1024
1238
  exports.getVersionWithoutNamespace = getVersionWithoutNamespace;
1239
+ exports.handleAxiosError = handleAxiosError;
1025
1240
  exports.parseNamespacedVersion = parseNamespacedVersion;
1241
+ exports.serializeMessageForForwardMPC = serializeMessageForForwardMPC;
1026
1242
  exports.verifiedCredentialNameToChainEnum = verifiedCredentialNameToChainEnum;