@dynamic-labs-wallet/core 0.0.0-preview.160.0 → 0.0.1-paolo-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.
- package/index.cjs.js +503 -86
- package/index.esm.js +470 -81
- package/package.json +11 -3
- package/src/api/api.d.ts +108 -17
- package/src/api/api.d.ts.map +1 -1
- package/src/api/client.d.ts +12 -4
- package/src/api/client.d.ts.map +1 -1
- package/src/api/index.d.ts +1 -1
- package/src/api/index.d.ts.map +1 -1
- package/src/constants.d.ts +78 -17
- package/src/constants.d.ts.map +1 -1
- package/src/eventStream/utils.d.ts +7 -2
- package/src/eventStream/utils.d.ts.map +1 -1
- package/src/index.d.ts +6 -4
- package/src/index.d.ts.map +1 -1
- package/src/mpc/index.d.ts +2 -2
- package/src/mpc/index.d.ts.map +1 -1
- package/src/mpc/utils.d.ts +3 -3
- package/src/mpc/utils.d.ts.map +1 -1
- package/src/services/axiosErrorResponse.d.ts +5 -0
- package/src/services/axiosErrorResponse.d.ts.map +1 -0
- package/src/types.d.ts +277 -10
- package/src/types.d.ts.map +1 -1
- package/src/utils/index.d.ts +3 -0
- package/src/utils/index.d.ts.map +1 -0
- package/src/utils/messageSerialization.d.ts +6 -0
- package/src/utils/messageSerialization.d.ts.map +1 -0
- package/src/utils/sdkVersion.d.ts +38 -0
- package/src/utils/sdkVersion.d.ts.map +1 -0
package/index.cjs.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var axios = require('axios');
|
|
4
3
|
var uuid = require('uuid');
|
|
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";
|
|
@@ -13,26 +12,63 @@ var ENVIRONMENT_ENUM = /*#__PURE__*/ function(ENVIRONMENT_ENUM) {
|
|
|
13
12
|
return ENVIRONMENT_ENUM;
|
|
14
13
|
}({});
|
|
15
14
|
const DynamicRequestIdHeader = 'x-dyn-request-id';
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
15
|
+
const DynamicClientSessionSignature = 'x-dyn-client-session-signature';
|
|
16
|
+
const DynamicMfaTokenHeader = 'x-mfa-auth-token';
|
|
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';
|
|
19
26
|
const DYNAMIC_AUTH_BASE_API_URL_MAP = {
|
|
20
27
|
["production"]: DYNAMIC_AUTH_PROD_BASE_API_URL,
|
|
21
28
|
["preprod"]: DYNAMIC_AUTH_PREPROD_BASE_API_URL,
|
|
22
29
|
["development"]: DYNAMIC_AUTH_DEV_BASE_API_URL
|
|
23
30
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
28
40
|
};
|
|
29
|
-
|
|
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';
|
|
30
44
|
const MPC_RELAY_PREPROD_API_URL = 'relay.dynamic-preprod.xyz';
|
|
31
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
|
+
};
|
|
51
|
+
const RELAY_APP_ID_HEADER = 'X-Evervault-App-Id';
|
|
52
|
+
const PROD_RELAY_APP_ID = 'app_6e12fc400995';
|
|
53
|
+
const PREPROD_RELAY_APP_ID = 'app_32d15525a875';
|
|
54
|
+
const DYNAMIC_CLIENT_RELAY_REDCOAST_APP_ID_MAP = {
|
|
55
|
+
["production"]: PROD_RELAY_APP_ID,
|
|
56
|
+
["preprod"]: PREPROD_RELAY_APP_ID,
|
|
57
|
+
["development"]: undefined
|
|
58
|
+
};
|
|
59
|
+
const RELAY_API_KEY_HEADER = 'X-Evervault-Api-Key';
|
|
60
|
+
// This is the API key for the relay API. Its must be public to use MTLs
|
|
61
|
+
const PROD_RELAY_API_KEY = 'ev:key:1:7kRuVm1sE1J5FjGz2ijufy0IkATzrBKEvde0IMLW1dt3xbFcdTdOKHO0vNnJeAjAD:YmAPOP:Jh7DdD';
|
|
62
|
+
const PREPROD_RELAY_API_KEY = 'ev:key:1:7j2jIPMzlcKlpDz1RTV6Vadsm8sgmj1VHZzJXqW9ie1dgmyzKmccEGI8BBWU0PaXv:XfF7Ri:ivvRp1';
|
|
63
|
+
const DYNAMIC_CLIENT_RELAY_REDCOAST_API_KEY_MAP = {
|
|
64
|
+
["production"]: PROD_RELAY_API_KEY,
|
|
65
|
+
["preprod"]: PREPROD_RELAY_API_KEY,
|
|
66
|
+
["development"]: undefined
|
|
67
|
+
};
|
|
32
68
|
const SOLANA_RPC_URL = 'https://api.devnet.solana.com';
|
|
33
69
|
const chain = {
|
|
34
70
|
EVM: 'EVM',
|
|
35
|
-
|
|
71
|
+
SVM: 'SVM',
|
|
36
72
|
COSMOS: 'COSMOS',
|
|
37
73
|
BTC: 'BTC',
|
|
38
74
|
FLOW: 'FLOW',
|
|
@@ -55,23 +91,49 @@ var BackupLocation = /*#__PURE__*/ function(BackupLocation) {
|
|
|
55
91
|
BackupLocation["ICLOUD"] = "iCloud";
|
|
56
92
|
BackupLocation["USER"] = "user";
|
|
57
93
|
BackupLocation["EXTERNAL"] = "external";
|
|
94
|
+
BackupLocation["DELEGATED"] = "delegated";
|
|
58
95
|
return BackupLocation;
|
|
59
96
|
}({});
|
|
60
97
|
const IFRAME_DOMAIN_MAP = {
|
|
61
|
-
development: 'http://localhost:
|
|
62
|
-
preprod: 'https://
|
|
63
|
-
production: 'https://
|
|
98
|
+
development: 'http://localhost:4200',
|
|
99
|
+
preprod: 'https://app.dynamic-preprod.xyz',
|
|
100
|
+
production: 'https://app.dynamicauth.com'
|
|
64
101
|
};
|
|
65
|
-
const
|
|
102
|
+
const chainEnumToVerifiedCredentialName = {
|
|
66
103
|
BTC: 'bip122',
|
|
67
104
|
EVM: 'eip155',
|
|
68
105
|
FLOW: 'flow',
|
|
69
|
-
|
|
106
|
+
SVM: 'solana'
|
|
70
107
|
};
|
|
71
|
-
const
|
|
108
|
+
const verifiedCredentialNameToChainEnum = {
|
|
72
109
|
bip122: 'BTC',
|
|
73
110
|
eip155: 'EVM',
|
|
74
|
-
solana: '
|
|
111
|
+
solana: 'SVM',
|
|
112
|
+
sui: 'SUI'
|
|
113
|
+
};
|
|
114
|
+
const DELEGATED_SHARE_COUNT = 1;
|
|
115
|
+
const FEATURE_FLAGS = {
|
|
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
|
|
75
137
|
};
|
|
76
138
|
|
|
77
139
|
var SigningAlgorithm = /*#__PURE__*/ function(SigningAlgorithm) {
|
|
@@ -117,7 +179,7 @@ const MPC_CHAIN_CONFIG = {
|
|
|
117
179
|
],
|
|
118
180
|
signingAlgorithm: "ECDSA"
|
|
119
181
|
},
|
|
120
|
-
|
|
182
|
+
SVM: {
|
|
121
183
|
// Uses Ed25519
|
|
122
184
|
derivationPath: [
|
|
123
185
|
44,
|
|
@@ -413,7 +475,7 @@ const getDynamicServerThreshold = (thresholdSignatureScheme)=>{
|
|
|
413
475
|
};
|
|
414
476
|
const URL_PATTERNS = {
|
|
415
477
|
[ENVIRONMENT_ENUM.development]: /^http:\/\/localhost:\d+$/,
|
|
416
|
-
[ENVIRONMENT_ENUM.preprod]:
|
|
478
|
+
[ENVIRONMENT_ENUM.preprod]: /-preprod/,
|
|
417
479
|
[ENVIRONMENT_ENUM.production]: /^(?!.*dynamic-preprod)(?!http:\/\/localhost:\d+).*/
|
|
418
480
|
};
|
|
419
481
|
function getEnvironmentFromUrl(url) {
|
|
@@ -429,25 +491,22 @@ function getEnvironmentFromUrl(url) {
|
|
|
429
491
|
return ENVIRONMENT_ENUM.production;
|
|
430
492
|
}
|
|
431
493
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
headers
|
|
442
|
-
});
|
|
443
|
-
this.clientRelayBaseApiUrl = baseClientRelayApiUrl != null ? baseClientRelayApiUrl : DYNAMIC_CLIENT_RELAY_MAP[environment];
|
|
444
|
-
this.clientRelayApiClient = axios.create({
|
|
445
|
-
baseURL: this.clientRelayBaseApiUrl,
|
|
446
|
-
headers
|
|
447
|
-
});
|
|
448
|
-
}
|
|
494
|
+
function _extends() {
|
|
495
|
+
_extends = Object.assign || function assign(target) {
|
|
496
|
+
for(var i = 1; i < arguments.length; i++){
|
|
497
|
+
var source = arguments[i];
|
|
498
|
+
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
499
|
+
}
|
|
500
|
+
return target;
|
|
501
|
+
};
|
|
502
|
+
return _extends.apply(this, arguments);
|
|
449
503
|
}
|
|
450
504
|
|
|
505
|
+
var AuthMode = /*#__PURE__*/ function(AuthMode) {
|
|
506
|
+
AuthMode["HEADER"] = "header";
|
|
507
|
+
AuthMode["COOKIE"] = "cookie";
|
|
508
|
+
return AuthMode;
|
|
509
|
+
}({});
|
|
451
510
|
var SuccessEventType = /*#__PURE__*/ function(SuccessEventType) {
|
|
452
511
|
SuccessEventType["KeygenComplete"] = "keygen_complete";
|
|
453
512
|
SuccessEventType["RoomCreated"] = "room_created";
|
|
@@ -455,6 +514,9 @@ var SuccessEventType = /*#__PURE__*/ function(SuccessEventType) {
|
|
|
455
514
|
return SuccessEventType;
|
|
456
515
|
}({});
|
|
457
516
|
|
|
517
|
+
const getElapsedTime = (startTime)=>{
|
|
518
|
+
return startTime ? (Date.now() - startTime).toString() : undefined;
|
|
519
|
+
};
|
|
458
520
|
/**
|
|
459
521
|
* Creates a promise that resolves when a specific event is received from an event stream.
|
|
460
522
|
* Adds a timeout to prevent hanging and races the two promises.
|
|
@@ -463,17 +525,22 @@ var SuccessEventType = /*#__PURE__*/ function(SuccessEventType) {
|
|
|
463
525
|
* @param apiClient The axios instance to use for API calls
|
|
464
526
|
* @param options The configuration options
|
|
465
527
|
* @returns A promise that resolves with the event data or rejects on timeout
|
|
466
|
-
*/ const createEventStreamPromise = ({ apiClient, endpoint, body, successEventType, timeoutMs = 30000, timeoutMessage, onError, onCeremonyComplete })=>{
|
|
528
|
+
*/ const createEventStreamPromise = ({ apiClient, dynamicRequestId, endpoint, body, successEventType, timeoutMs = 30000, timeoutMessage, onError, onCeremonyComplete, mfaToken, forwardMPCClientEnabled, traceContext })=>{
|
|
529
|
+
const headers = {
|
|
530
|
+
Accept: 'text/event-stream',
|
|
531
|
+
'Cache-Control': 'no-cache',
|
|
532
|
+
Connection: 'keep-alive',
|
|
533
|
+
[DynamicRequestIdHeader]: dynamicRequestId,
|
|
534
|
+
[DynamicMfaTokenHeader]: mfaToken,
|
|
535
|
+
[DynamicForwardMPCHeader]: forwardMPCClientEnabled,
|
|
536
|
+
[DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
|
|
537
|
+
[DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
|
|
538
|
+
};
|
|
467
539
|
// Create a promise that will resolve when the success event is received
|
|
468
540
|
const eventPromise = new Promise((resolve, reject)=>{
|
|
469
541
|
apiClient.post(endpoint, body, {
|
|
470
542
|
responseType: 'stream',
|
|
471
|
-
headers: {
|
|
472
|
-
Accept: 'text/event-stream',
|
|
473
|
-
'Cache-Control': 'no-cache',
|
|
474
|
-
Connection: 'keep-alive',
|
|
475
|
-
[DynamicRequestIdHeader]: uuid.v4().replace('-', '')
|
|
476
|
-
},
|
|
543
|
+
headers: _extends({}, headers),
|
|
477
544
|
adapter: 'fetch'
|
|
478
545
|
}).then(createSuccessErrorEventStreamHandler({
|
|
479
546
|
onError,
|
|
@@ -526,8 +593,9 @@ var SuccessEventType = /*#__PURE__*/ function(SuccessEventType) {
|
|
|
526
593
|
onCeremonyComplete == null ? void 0 : onCeremonyComplete(accountAddress, walletId);
|
|
527
594
|
}
|
|
528
595
|
if (event.type === 'error') {
|
|
529
|
-
|
|
530
|
-
|
|
596
|
+
const error = createErrorFromEventData(event.data);
|
|
597
|
+
reject(error);
|
|
598
|
+
onError == null ? void 0 : onError(error);
|
|
531
599
|
}
|
|
532
600
|
}
|
|
533
601
|
processStream();
|
|
@@ -587,6 +655,78 @@ var SuccessEventType = /*#__PURE__*/ function(SuccessEventType) {
|
|
|
587
655
|
return events;
|
|
588
656
|
};
|
|
589
657
|
|
|
658
|
+
var version = "0.0.1";
|
|
659
|
+
|
|
660
|
+
class BaseClient {
|
|
661
|
+
syncAuthToken(authToken) {
|
|
662
|
+
if (this.authMode === AuthMode.COOKIE) {
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
if (!authToken) {
|
|
666
|
+
throw new Error('Auth token is required for header authentication');
|
|
667
|
+
}
|
|
668
|
+
const authHeader = `Bearer ${authToken}`;
|
|
669
|
+
this.apiClient.defaults.headers['Authorization'] = authHeader;
|
|
670
|
+
this.clientRelayApiClient.defaults.headers['Authorization'] = authHeader;
|
|
671
|
+
this.apiClient.defaults.headers.common['Authorization'] = authHeader;
|
|
672
|
+
this.clientRelayApiClient.defaults.headers.common['Authorization'] = authHeader;
|
|
673
|
+
if (this.apiClient.defaults.headers['Authorization'] !== authHeader || this.clientRelayApiClient.defaults.headers['Authorization'] !== authHeader) {
|
|
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');
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
constructor({ environmentId, baseApiUrl, authToken, baseClientKeysharesRelayApiUrl, authMode = AuthMode.HEADER, // Represents the version of the client SDK used by developer
|
|
678
|
+
sdkVersion, forwardMPCClient }){
|
|
679
|
+
const headers = {};
|
|
680
|
+
// Only set Authorization header if using header auth mode and token is provided
|
|
681
|
+
if (authMode === AuthMode.HEADER && authToken) {
|
|
682
|
+
headers['Authorization'] = `Bearer ${authToken}`;
|
|
683
|
+
}
|
|
684
|
+
headers['x-dyn-wallet-sdk-version'] = version;
|
|
685
|
+
headers['x-dyn-version'] = sdkVersion;
|
|
686
|
+
this.environmentId = environmentId;
|
|
687
|
+
this.authMode = authMode;
|
|
688
|
+
const environment = getEnvironmentFromUrl(baseApiUrl);
|
|
689
|
+
this.baseApiUrl = baseApiUrl != null ? baseApiUrl : DYNAMIC_AUTH_BASE_API_URL_MAP[environment];
|
|
690
|
+
// Configure axios to include credentials for cookie auth
|
|
691
|
+
const axiosConfig = _extends({
|
|
692
|
+
baseURL: this.baseApiUrl,
|
|
693
|
+
headers
|
|
694
|
+
}, authMode === AuthMode.COOKIE ? {
|
|
695
|
+
withCredentials: true
|
|
696
|
+
} : {});
|
|
697
|
+
this.apiClient = axios.create(axiosConfig);
|
|
698
|
+
this.clientKeysharesRelayBaseApiUrl = baseClientKeysharesRelayApiUrl != null ? baseClientKeysharesRelayApiUrl : DYNAMIC_KEYSHARES_RELAY_MAP[environment];
|
|
699
|
+
this.clientRelayApiClient = axios.create({
|
|
700
|
+
baseURL: this.clientKeysharesRelayBaseApiUrl,
|
|
701
|
+
headers: _extends({}, headers, {
|
|
702
|
+
['x-dyn-environment']: environment,
|
|
703
|
+
['x-dyn-client-keyshare-relay-api-url']: baseClientKeysharesRelayApiUrl,
|
|
704
|
+
[RELAY_API_KEY_HEADER]: DYNAMIC_CLIENT_RELAY_REDCOAST_API_KEY_MAP[environment],
|
|
705
|
+
[RELAY_APP_ID_HEADER]: DYNAMIC_CLIENT_RELAY_REDCOAST_APP_ID_MAP[environment]
|
|
706
|
+
})
|
|
707
|
+
});
|
|
708
|
+
console.log('--------------------------------');
|
|
709
|
+
console.log('clientKeysharesRelayBaseApiUrl', this.clientKeysharesRelayBaseApiUrl);
|
|
710
|
+
console.log('environment', environment);
|
|
711
|
+
console.log('baseClientKeysharesRelayApiUrl', baseClientKeysharesRelayApiUrl);
|
|
712
|
+
console.log('--------------------------------');
|
|
713
|
+
// Use provided ForwardMPCClient or create a new one
|
|
714
|
+
if (forwardMPCClient) {
|
|
715
|
+
this.forwardMPCClient = forwardMPCClient;
|
|
716
|
+
} else {
|
|
717
|
+
const forwardMPCEnclaveUrl = DYNAMIC_FORWARD_MPC_ENCLAVE_URL_MAP[environment];
|
|
718
|
+
const attestationConfig = DYNAMIC_FORWARD_MPC_ENCLAVE_ATTESTATION_CONFIG_MAP[environment];
|
|
719
|
+
this.forwardMPCClient = new forwardMpcClient.ForwardMPCClient(forwardMPCEnclaveUrl != null ? forwardMPCEnclaveUrl : '', {
|
|
720
|
+
reconnectInterval: 5000,
|
|
721
|
+
reconnectAttempts: 5,
|
|
722
|
+
connectionTimeout: 10000,
|
|
723
|
+
heartbeatInterval: 30000,
|
|
724
|
+
attestationConfig
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
|
|
590
730
|
class DynamicApiClient extends BaseClient {
|
|
591
731
|
async authenticateApiToken({ environmentId }) {
|
|
592
732
|
return this.apiClient.post(`/api/v0/environments/${environmentId}/waas/authenticate`, undefined, {
|
|
@@ -595,82 +735,141 @@ class DynamicApiClient extends BaseClient {
|
|
|
595
735
|
}
|
|
596
736
|
});
|
|
597
737
|
}
|
|
598
|
-
async createWalletAccount({ chainName, clientKeygenIds, thresholdSignatureScheme, onError, onCeremonyComplete }) {
|
|
738
|
+
async createWalletAccount({ chainName, clientKeygenIds, dynamicRequestId, thresholdSignatureScheme, skipLock, onError, onCeremonyComplete, traceContext }) {
|
|
599
739
|
return createEventStreamPromise({
|
|
600
740
|
apiClient: this.apiClient,
|
|
741
|
+
dynamicRequestId,
|
|
601
742
|
endpoint: `/api/v0/sdk/${this.environmentId}/waas/create`,
|
|
602
|
-
body: {
|
|
743
|
+
body: _extends({
|
|
603
744
|
chain: chainName,
|
|
604
745
|
clientKeygenIds,
|
|
605
746
|
thresholdSignatureScheme
|
|
606
|
-
},
|
|
747
|
+
}, skipLock ? {
|
|
748
|
+
skipLock
|
|
749
|
+
} : {}),
|
|
607
750
|
successEventType: SuccessEventType.KeygenComplete,
|
|
608
751
|
timeoutMessage: 'Wallet creation timed out',
|
|
609
752
|
onError,
|
|
610
|
-
onCeremonyComplete
|
|
753
|
+
onCeremonyComplete,
|
|
754
|
+
traceContext
|
|
611
755
|
});
|
|
612
756
|
}
|
|
613
|
-
async signMessage({ walletId, message, onError, isFormatted }) {
|
|
757
|
+
async signMessage({ dynamicRequestId, walletId, message, onError, isFormatted, mfaToken, context, forwardMPCClientEnabled, traceContext }) {
|
|
614
758
|
return createEventStreamPromise({
|
|
615
759
|
apiClient: this.apiClient,
|
|
760
|
+
dynamicRequestId,
|
|
616
761
|
endpoint: `/api/v0/sdk/${this.environmentId}/waas/${walletId}/signMessage`,
|
|
617
762
|
body: {
|
|
618
763
|
message,
|
|
619
|
-
isFormatted
|
|
764
|
+
isFormatted,
|
|
765
|
+
context
|
|
620
766
|
},
|
|
621
767
|
successEventType: SuccessEventType.RoomCreated,
|
|
622
768
|
timeoutMessage: 'Message signing timed out',
|
|
623
|
-
onError
|
|
769
|
+
onError,
|
|
770
|
+
mfaToken,
|
|
771
|
+
forwardMPCClientEnabled,
|
|
772
|
+
traceContext
|
|
624
773
|
});
|
|
625
774
|
}
|
|
626
|
-
async refreshWalletAccountShares({ walletId, onError }) {
|
|
775
|
+
async refreshWalletAccountShares({ dynamicRequestId, walletId, onError, mfaToken, traceContext }) {
|
|
627
776
|
return createEventStreamPromise({
|
|
628
777
|
apiClient: this.apiClient,
|
|
778
|
+
dynamicRequestId,
|
|
629
779
|
endpoint: `/api/v0/sdk/${this.environmentId}/waas/${walletId}/refresh`,
|
|
630
780
|
body: undefined,
|
|
631
781
|
successEventType: SuccessEventType.RoomCreated,
|
|
632
782
|
timeoutMessage: 'Refresh timed out',
|
|
633
|
-
onError
|
|
783
|
+
onError,
|
|
784
|
+
mfaToken,
|
|
785
|
+
traceContext
|
|
634
786
|
});
|
|
635
787
|
}
|
|
636
|
-
async reshare({ walletId, clientKeygenIds, oldThresholdSignatureScheme, newThresholdSignatureScheme, onError }) {
|
|
788
|
+
async reshare({ walletId, dynamicRequestId, clientKeygenIds, oldThresholdSignatureScheme, newThresholdSignatureScheme, delegateToProjectEnvironment, revokeDelegation, mfaToken, onError, traceContext }) {
|
|
637
789
|
return createEventStreamPromise({
|
|
638
790
|
apiClient: this.apiClient,
|
|
791
|
+
dynamicRequestId,
|
|
639
792
|
endpoint: `/api/v0/sdk/${this.environmentId}/waas/${walletId}/reshare`,
|
|
640
793
|
body: {
|
|
641
794
|
clientKeygenIds,
|
|
795
|
+
delegateToProjectEnvironment,
|
|
796
|
+
newThresholdSignatureScheme,
|
|
642
797
|
oldThresholdSignatureScheme,
|
|
643
|
-
|
|
798
|
+
revokeDelegation
|
|
644
799
|
},
|
|
645
800
|
successEventType: SuccessEventType.RoomCreated,
|
|
646
801
|
timeoutMessage: 'Reshare timed out',
|
|
647
|
-
onError
|
|
802
|
+
onError,
|
|
803
|
+
mfaToken,
|
|
804
|
+
traceContext
|
|
648
805
|
});
|
|
649
806
|
}
|
|
650
|
-
async exportKey({ walletId, exportId, onError }) {
|
|
807
|
+
async exportKey({ mfaToken, dynamicRequestId, walletId, exportId, onError, traceContext }) {
|
|
651
808
|
return createEventStreamPromise({
|
|
652
809
|
apiClient: this.apiClient,
|
|
810
|
+
dynamicRequestId,
|
|
653
811
|
endpoint: `/api/v0/sdk/${this.environmentId}/waas/${walletId}/privateKey/export`,
|
|
654
812
|
body: {
|
|
655
813
|
exportId
|
|
656
814
|
},
|
|
657
815
|
successEventType: SuccessEventType.RoomCreated,
|
|
658
816
|
timeoutMessage: 'Key export timed out',
|
|
659
|
-
onError
|
|
817
|
+
onError,
|
|
818
|
+
mfaToken,
|
|
819
|
+
traceContext
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
async getDelegatedEncryptionKey({ environmentId, traceContext }) {
|
|
823
|
+
const { data } = await this.apiClient.get(`/api/v0/sdk/${environmentId}/waas/delegatedAccess/encryptionPublicKey`, {
|
|
824
|
+
headers: {
|
|
825
|
+
[DynamicRequestIdHeader]: uuid.v4().replace('-', ''),
|
|
826
|
+
[DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
|
|
827
|
+
[DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
|
|
828
|
+
}
|
|
829
|
+
});
|
|
830
|
+
return data;
|
|
831
|
+
}
|
|
832
|
+
async publishDelegatedKeyShare({ walletId, encryptedKeyShare, signedSessionId, requiresSignedSessionId = false, dynamicRequestId, traceContext }) {
|
|
833
|
+
if (requiresSignedSessionId && !signedSessionId) {
|
|
834
|
+
throw new Error('Signed session ID is required');
|
|
835
|
+
}
|
|
836
|
+
const apiClient = this.apiClient;
|
|
837
|
+
const { data, status } = await apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/delegatedAccess/delivery`, {
|
|
838
|
+
encryptedDelegatedShare: encryptedKeyShare
|
|
839
|
+
}, {
|
|
840
|
+
headers: {
|
|
841
|
+
[DynamicRequestIdHeader]: dynamicRequestId,
|
|
842
|
+
[DynamicClientSessionSignature]: signedSessionId,
|
|
843
|
+
[DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
|
|
844
|
+
[DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
|
|
845
|
+
}
|
|
660
846
|
});
|
|
847
|
+
return {
|
|
848
|
+
data,
|
|
849
|
+
status
|
|
850
|
+
};
|
|
661
851
|
}
|
|
662
|
-
async storeEncryptedBackupByWallet({ walletId, encryptedKeyShares, passwordEncrypted }) {
|
|
852
|
+
async storeEncryptedBackupByWallet({ walletId, encryptedKeyShares, passwordEncrypted, signedSessionId, encryptionVersion, requiresSignedSessionId = false, authMode = AuthMode.HEADER, dynamicRequestId, traceContext }) {
|
|
853
|
+
if (requiresSignedSessionId && !signedSessionId) {
|
|
854
|
+
throw new Error('Signed session ID is required');
|
|
855
|
+
}
|
|
663
856
|
const { data } = await this.clientRelayApiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/keyShares/backup`, {
|
|
664
857
|
// TODO: decide on whether to store encryptedAccountCredentials or encryptedKeyShares as backup
|
|
665
858
|
encryptedAccountCredentials: encryptedKeyShares,
|
|
666
|
-
passwordEncrypted
|
|
859
|
+
passwordEncrypted,
|
|
860
|
+
encryptionVersion
|
|
667
861
|
}, {
|
|
668
862
|
headers: {
|
|
669
|
-
[DynamicRequestIdHeader]:
|
|
670
|
-
|
|
863
|
+
[DynamicRequestIdHeader]: dynamicRequestId,
|
|
864
|
+
[DynamicClientSessionSignature]: signedSessionId,
|
|
865
|
+
[DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
|
|
866
|
+
[DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
|
|
867
|
+
},
|
|
868
|
+
withCredentials: authMode === AuthMode.COOKIE ? true : undefined
|
|
671
869
|
});
|
|
672
870
|
return data;
|
|
673
871
|
}
|
|
872
|
+
// TODO: is this still used? if not, remove it
|
|
674
873
|
async markKeySharesAsBackedUpGoogleDrive({ walletId }) {
|
|
675
874
|
const { data } = await this.clientRelayApiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/keyShares/backup/googleDrive`, {}, {
|
|
676
875
|
headers: {
|
|
@@ -679,28 +878,52 @@ class DynamicApiClient extends BaseClient {
|
|
|
679
878
|
});
|
|
680
879
|
return data;
|
|
681
880
|
}
|
|
682
|
-
async
|
|
881
|
+
async markKeySharesAsBackedUp({ walletId, locations, dynamicRequestId, traceContext }) {
|
|
882
|
+
const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/keyShares/backup/locations`, {
|
|
883
|
+
locations
|
|
884
|
+
}, {
|
|
885
|
+
headers: {
|
|
886
|
+
[DynamicRequestIdHeader]: dynamicRequestId,
|
|
887
|
+
[DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
|
|
888
|
+
[DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
|
|
889
|
+
}
|
|
890
|
+
});
|
|
891
|
+
return data;
|
|
892
|
+
}
|
|
893
|
+
async recoverEncryptedBackupByWallet({ walletId, keyShareIds, signedSessionId, mfaToken, requiresSignedSessionId = false, authMode = AuthMode.HEADER, traceContext }) {
|
|
894
|
+
if (requiresSignedSessionId && !signedSessionId) {
|
|
895
|
+
throw new Error('Signed session ID is required');
|
|
896
|
+
}
|
|
897
|
+
// TODO: add signed messsage to body?
|
|
683
898
|
const { data } = await this.clientRelayApiClient.post(`/api/v0/sdk/${this.environmentId}/waas/${walletId}/keyShares/recover`, keyShareIds ? {
|
|
684
899
|
keyShareIds
|
|
685
900
|
} : undefined, {
|
|
686
901
|
headers: {
|
|
687
|
-
[DynamicRequestIdHeader]: uuid.v4().replace('-', '')
|
|
688
|
-
|
|
902
|
+
[DynamicRequestIdHeader]: uuid.v4().replace('-', ''),
|
|
903
|
+
[DynamicClientSessionSignature]: signedSessionId,
|
|
904
|
+
[DynamicMfaTokenHeader]: mfaToken,
|
|
905
|
+
[DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
|
|
906
|
+
[DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
|
|
907
|
+
},
|
|
908
|
+
withCredentials: authMode === AuthMode.COOKIE ? true : undefined
|
|
689
909
|
});
|
|
690
910
|
return data;
|
|
691
911
|
}
|
|
692
|
-
async getAccessToken({ oauthAccountId }) {
|
|
912
|
+
async getAccessToken({ oauthAccountId, traceContext }) {
|
|
693
913
|
const { data } = await this.apiClient.get(`/api/v0/sdk/${this.environmentId}/oauthAccounts/${oauthAccountId}/accessToken`, {
|
|
694
914
|
headers: {
|
|
695
|
-
[DynamicRequestIdHeader]: uuid.v4().replace('-', '')
|
|
915
|
+
[DynamicRequestIdHeader]: uuid.v4().replace('-', ''),
|
|
916
|
+
[DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
|
|
917
|
+
[DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
|
|
696
918
|
}
|
|
697
919
|
});
|
|
698
920
|
return data.accessToken;
|
|
699
921
|
}
|
|
700
922
|
// TODO: return array instead considering cases where server has multiple parties
|
|
701
|
-
async importPrivateKey({ chainName, clientKeygenIds, thresholdSignatureScheme, onError, onCeremonyComplete }) {
|
|
923
|
+
async importPrivateKey({ chainName, dynamicRequestId, clientKeygenIds, thresholdSignatureScheme, onError, onCeremonyComplete, traceContext }) {
|
|
702
924
|
return createEventStreamPromise({
|
|
703
925
|
apiClient: this.apiClient,
|
|
926
|
+
dynamicRequestId,
|
|
704
927
|
endpoint: `/api/v0/sdk/${this.environmentId}/waas/privateKey/import`,
|
|
705
928
|
body: {
|
|
706
929
|
chain: chainName,
|
|
@@ -710,11 +933,12 @@ class DynamicApiClient extends BaseClient {
|
|
|
710
933
|
successEventType: SuccessEventType.KeygenComplete,
|
|
711
934
|
timeoutMessage: 'Key import timed out',
|
|
712
935
|
onError,
|
|
713
|
-
onCeremonyComplete
|
|
936
|
+
onCeremonyComplete,
|
|
937
|
+
traceContext
|
|
714
938
|
});
|
|
715
939
|
}
|
|
716
940
|
// TODO: consider removing the retry logics if we switch to server-sent events
|
|
717
|
-
async getUser() {
|
|
941
|
+
async getUser(dynamicRequestId, traceContext) {
|
|
718
942
|
let attempts = 0;
|
|
719
943
|
const maxAttempts = 5;
|
|
720
944
|
const retryInterval = 1000; // 1 second interval for each retry
|
|
@@ -722,7 +946,9 @@ class DynamicApiClient extends BaseClient {
|
|
|
722
946
|
try {
|
|
723
947
|
const { data } = await this.apiClient.get(`/api/v0/sdk/${this.environmentId}/users`, {
|
|
724
948
|
headers: {
|
|
725
|
-
[DynamicRequestIdHeader]:
|
|
949
|
+
[DynamicRequestIdHeader]: dynamicRequestId,
|
|
950
|
+
[DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
|
|
951
|
+
[DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
|
|
726
952
|
}
|
|
727
953
|
});
|
|
728
954
|
return data;
|
|
@@ -736,7 +962,7 @@ class DynamicApiClient extends BaseClient {
|
|
|
736
962
|
}
|
|
737
963
|
}
|
|
738
964
|
// TODO: consider removing the retry logics if we switch to server-sent events
|
|
739
|
-
async refreshUser() {
|
|
965
|
+
async refreshUser(traceContext) {
|
|
740
966
|
let attempts = 0;
|
|
741
967
|
const maxAttempts = 5;
|
|
742
968
|
const retryInterval = 1000; // 1 second interval for each retry
|
|
@@ -744,7 +970,9 @@ class DynamicApiClient extends BaseClient {
|
|
|
744
970
|
try {
|
|
745
971
|
const { data } = await this.apiClient.post(`/api/v0/sdk/${this.environmentId}/refresh`, undefined, {
|
|
746
972
|
headers: {
|
|
747
|
-
[DynamicRequestIdHeader]: uuid.v4().replace('-', '')
|
|
973
|
+
[DynamicRequestIdHeader]: uuid.v4().replace('-', ''),
|
|
974
|
+
[DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
|
|
975
|
+
[DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
|
|
748
976
|
}
|
|
749
977
|
});
|
|
750
978
|
return data;
|
|
@@ -757,44 +985,227 @@ class DynamicApiClient extends BaseClient {
|
|
|
757
985
|
}
|
|
758
986
|
}
|
|
759
987
|
}
|
|
760
|
-
|
|
988
|
+
async getEnvironmentSettings(traceContext) {
|
|
989
|
+
const { data } = await this.apiClient.get(`/api/v0/sdk/${this.environmentId}/settings`, {
|
|
990
|
+
headers: {
|
|
991
|
+
[DynamicRequestIdHeader]: uuid.v4().replace('-', ''),
|
|
992
|
+
[DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
|
|
993
|
+
[DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
return data;
|
|
997
|
+
}
|
|
998
|
+
async getWaasWalletById({ walletId, traceContext }) {
|
|
999
|
+
const { data } = await this.apiClient.get(`/api/v0/environments/${this.environmentId}/waas/${walletId}`, {
|
|
1000
|
+
headers: {
|
|
1001
|
+
[DynamicRequestIdHeader]: uuid.v4().replace('-', ''),
|
|
1002
|
+
[DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
|
|
1003
|
+
[DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
|
|
1004
|
+
}
|
|
1005
|
+
});
|
|
1006
|
+
return data;
|
|
1007
|
+
}
|
|
1008
|
+
/**
|
|
1009
|
+
* Fetch a single WaaS wallet by ID using the /sdk/{environmentId}/waas/{walletId} endpoint.
|
|
1010
|
+
* This endpoint returns user information with verified credentials filtered to only include the specified WaaS wallet.
|
|
1011
|
+
*/ async getWaasWalletByAddress({ walletAddress, traceContext }) {
|
|
1012
|
+
const { data } = await this.apiClient.get(`/api/v0/sdk/${this.environmentId}/waas/byWalletAddress/${walletAddress}`, {
|
|
1013
|
+
headers: {
|
|
1014
|
+
[DynamicRequestIdHeader]: uuid.v4().replace('-', ''),
|
|
1015
|
+
[DynamicTraceIdHeader]: traceContext == null ? void 0 : traceContext.traceId,
|
|
1016
|
+
[DynamicTraceElapsedTimeHeader]: getElapsedTime(traceContext == null ? void 0 : traceContext.startTime)
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
return data;
|
|
1020
|
+
}
|
|
1021
|
+
async delegatedSignMessage({ walletId, message, isFormatted, dynamicRequestId, onError, context, traceContext }) {
|
|
1022
|
+
return createEventStreamPromise({
|
|
1023
|
+
apiClient: this.apiClient,
|
|
1024
|
+
dynamicRequestId,
|
|
1025
|
+
endpoint: `/api/v0/environments/${this.environmentId}/waas/${walletId}/delegatedAccess/signMessage`,
|
|
1026
|
+
body: {
|
|
1027
|
+
message,
|
|
1028
|
+
isFormatted,
|
|
1029
|
+
context
|
|
1030
|
+
},
|
|
1031
|
+
successEventType: SuccessEventType.RoomCreated,
|
|
1032
|
+
timeoutMessage: 'Delegated sign message timed out',
|
|
1033
|
+
onError,
|
|
1034
|
+
traceContext
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
constructor({ environmentId, authToken, baseApiUrl, authMode = AuthMode.HEADER, // Represents the version of the client SDK used by developer
|
|
1038
|
+
sdkVersion, forwardMPCClient, baseClientKeysharesRelayApiUrl }){
|
|
761
1039
|
super({
|
|
762
1040
|
environmentId,
|
|
763
|
-
authToken,
|
|
764
|
-
baseApiUrl
|
|
1041
|
+
authToken: authToken || '',
|
|
1042
|
+
baseApiUrl,
|
|
1043
|
+
authMode,
|
|
1044
|
+
sdkVersion,
|
|
1045
|
+
forwardMPCClient,
|
|
1046
|
+
baseClientKeysharesRelayApiUrl
|
|
765
1047
|
});
|
|
766
1048
|
}
|
|
767
1049
|
}
|
|
768
1050
|
|
|
1051
|
+
const SDK_NAMESPACE = {
|
|
1052
|
+
REACT: 'WalletKit',
|
|
1053
|
+
CLIENT: 'ClientSDK'
|
|
1054
|
+
};
|
|
1055
|
+
/**
|
|
1056
|
+
* Parses a potentially namespaced SDK version string
|
|
1057
|
+
* @param sdkVersion - The SDK version string, optionally namespaced
|
|
1058
|
+
* @returns Parsed SDK version with namespace and version
|
|
1059
|
+
* @example
|
|
1060
|
+
* parseNamespacedVersion("WalletKit/1.0.0") // { namespace: "WalletKit", version: "1.0.0", raw: "WalletKit/1.0.0" }
|
|
1061
|
+
* parseNamespacedVersion("1.0.0") // { namespace: "WalletKit", version: "1.0.0", raw: "1.0.0" }
|
|
1062
|
+
*/ function parseNamespacedVersion(sdkVersion) {
|
|
1063
|
+
if (!sdkVersion || sdkVersion === '') {
|
|
1064
|
+
return null;
|
|
1065
|
+
}
|
|
1066
|
+
// Check if the version contains a namespace
|
|
1067
|
+
const colonIndex = sdkVersion.indexOf('/');
|
|
1068
|
+
if (colonIndex !== -1) {
|
|
1069
|
+
const namespace = sdkVersion.substring(0, colonIndex);
|
|
1070
|
+
const version = sdkVersion.substring(colonIndex + 1);
|
|
1071
|
+
// Validate namespace
|
|
1072
|
+
if (!Object.values(SDK_NAMESPACE).includes(namespace)) {
|
|
1073
|
+
return {
|
|
1074
|
+
namespace: SDK_NAMESPACE.REACT,
|
|
1075
|
+
version,
|
|
1076
|
+
raw: sdkVersion
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
return {
|
|
1080
|
+
namespace: namespace,
|
|
1081
|
+
version,
|
|
1082
|
+
raw: sdkVersion
|
|
1083
|
+
};
|
|
1084
|
+
}
|
|
1085
|
+
// No namespace found, default to react-sdk for backward compatibility
|
|
1086
|
+
return {
|
|
1087
|
+
namespace: 'WalletKit',
|
|
1088
|
+
version: sdkVersion,
|
|
1089
|
+
raw: sdkVersion
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* Formats a parsed SDK version back to string format
|
|
1094
|
+
* @param parsedVersion - The parsed SDK version object
|
|
1095
|
+
* @returns Formatted SDK version string
|
|
1096
|
+
*/ function formatNamespacedVersion(parsedVersion) {
|
|
1097
|
+
return `${parsedVersion.namespace}/${parsedVersion.version}`;
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* Gets the version string without namespace
|
|
1101
|
+
* @param sdkVersion - The SDK version string, optionally namespaced
|
|
1102
|
+
* @returns Version string without namespace
|
|
1103
|
+
*/ function getVersionWithoutNamespace(sdkVersion) {
|
|
1104
|
+
const parsed = parseNamespacedVersion(sdkVersion);
|
|
1105
|
+
return parsed ? parsed.version : null;
|
|
1106
|
+
}
|
|
1107
|
+
/**
|
|
1108
|
+
* Gets the namespace from a potentially namespaced SDK version
|
|
1109
|
+
* @param sdkVersion - The SDK version string, optionally namespaced
|
|
1110
|
+
* @returns The namespace or default namespace
|
|
1111
|
+
*/ function getVersionNamespace(sdkVersion) {
|
|
1112
|
+
const parsed = parseNamespacedVersion(sdkVersion);
|
|
1113
|
+
return parsed ? parsed.namespace : null;
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
const serializeMessageForForwardMPC = ({ message, isFormatted = false, chainName })=>{
|
|
1117
|
+
let serializedMessage = message;
|
|
1118
|
+
if (isFormatted && chainName === 'EVM') {
|
|
1119
|
+
if (typeof message === 'string') {
|
|
1120
|
+
// Handle hex string (with or without 0x prefix)
|
|
1121
|
+
const cleanHex = message.startsWith('0x') ? message.slice(2) : message;
|
|
1122
|
+
serializedMessage = cleanHex;
|
|
1123
|
+
} else if (message instanceof Uint8Array) {
|
|
1124
|
+
serializedMessage = Buffer.from(message).toString('hex');
|
|
1125
|
+
} else if (message instanceof MessageHash) {
|
|
1126
|
+
serializedMessage = message.toHex();
|
|
1127
|
+
} else {
|
|
1128
|
+
throw new Error('Unsupported formatted message format');
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
return serializedMessage;
|
|
1132
|
+
};
|
|
1133
|
+
|
|
1134
|
+
const handleAxiosError = (error, message, context, logger)=>{
|
|
1135
|
+
var _error_response, _error_response1, _error_response2;
|
|
1136
|
+
logger.error('[DynamicWaasWalletClient] Axios error: ', {
|
|
1137
|
+
message,
|
|
1138
|
+
error: (_error_response = error.response) == null ? void 0 : _error_response.data,
|
|
1139
|
+
status: (_error_response1 = error.response) == null ? void 0 : _error_response1.status,
|
|
1140
|
+
context
|
|
1141
|
+
});
|
|
1142
|
+
switch((_error_response2 = error.response) == null ? void 0 : _error_response2.status){
|
|
1143
|
+
case 400:
|
|
1144
|
+
throw createHttpError(400, 'Invalid request');
|
|
1145
|
+
case 401:
|
|
1146
|
+
throw createHttpError(401, 'Authorization header or cookie is required');
|
|
1147
|
+
case 403:
|
|
1148
|
+
throw createHttpError(403, 'Forbidden');
|
|
1149
|
+
case 422:
|
|
1150
|
+
throw createHttpError(422, 'Unprocessable content');
|
|
1151
|
+
case 500:
|
|
1152
|
+
throw createHttpError(500, 'Internal server error');
|
|
1153
|
+
default:
|
|
1154
|
+
throw createHttpError(500, 'Internal server error');
|
|
1155
|
+
}
|
|
1156
|
+
};
|
|
1157
|
+
|
|
1158
|
+
exports.AuthMode = AuthMode;
|
|
769
1159
|
exports.BITCOIN_DERIVATION_PATHS = BITCOIN_DERIVATION_PATHS;
|
|
770
1160
|
exports.BackupLocation = BackupLocation;
|
|
771
|
-
exports.ChainEnumToVerifiedCredentialName = ChainEnumToVerifiedCredentialName;
|
|
772
1161
|
exports.CreateRoomPartiesOptions = CreateRoomPartiesOptions;
|
|
1162
|
+
exports.DELEGATED_SHARE_COUNT = DELEGATED_SHARE_COUNT;
|
|
773
1163
|
exports.DYNAMIC_AUTH_BASE_API_URL_MAP = DYNAMIC_AUTH_BASE_API_URL_MAP;
|
|
774
1164
|
exports.DYNAMIC_AUTH_DEV_BASE_API_URL = DYNAMIC_AUTH_DEV_BASE_API_URL;
|
|
775
1165
|
exports.DYNAMIC_AUTH_PREPROD_BASE_API_URL = DYNAMIC_AUTH_PREPROD_BASE_API_URL;
|
|
776
1166
|
exports.DYNAMIC_AUTH_PROD_BASE_API_URL = DYNAMIC_AUTH_PROD_BASE_API_URL;
|
|
777
|
-
exports.
|
|
778
|
-
exports.
|
|
779
|
-
exports.
|
|
780
|
-
exports.
|
|
1167
|
+
exports.DYNAMIC_CLIENT_RELAY_REDCOAST_API_KEY_MAP = DYNAMIC_CLIENT_RELAY_REDCOAST_API_KEY_MAP;
|
|
1168
|
+
exports.DYNAMIC_CLIENT_RELAY_REDCOAST_APP_ID_MAP = DYNAMIC_CLIENT_RELAY_REDCOAST_APP_ID_MAP;
|
|
1169
|
+
exports.DYNAMIC_FORWARD_MPC_DEV_ENCLAVE_URL = DYNAMIC_FORWARD_MPC_DEV_ENCLAVE_URL;
|
|
1170
|
+
exports.DYNAMIC_FORWARD_MPC_ENCLAVE_ATTESTATION_CONFIG_MAP = DYNAMIC_FORWARD_MPC_ENCLAVE_ATTESTATION_CONFIG_MAP;
|
|
1171
|
+
exports.DYNAMIC_FORWARD_MPC_ENCLAVE_URL_MAP = DYNAMIC_FORWARD_MPC_ENCLAVE_URL_MAP;
|
|
1172
|
+
exports.DYNAMIC_FORWARD_MPC_PREPROD_ENCLAVE_URL = DYNAMIC_FORWARD_MPC_PREPROD_ENCLAVE_URL;
|
|
1173
|
+
exports.DYNAMIC_FORWARD_MPC_PROD_ENCLAVE_URL = DYNAMIC_FORWARD_MPC_PROD_ENCLAVE_URL;
|
|
1174
|
+
exports.DYNAMIC_KEYSHARES_RELAY_MAP = DYNAMIC_KEYSHARES_RELAY_MAP;
|
|
1175
|
+
exports.DYNAMIC_KEYSHARES_RELAY_PREPROD_BASE_API_URL = DYNAMIC_KEYSHARES_RELAY_PREPROD_BASE_API_URL;
|
|
1176
|
+
exports.DYNAMIC_KEYSHARES_RELAY_PROD_BASE_API_URL = DYNAMIC_KEYSHARES_RELAY_PROD_BASE_API_URL;
|
|
781
1177
|
exports.DynamicApiClient = DynamicApiClient;
|
|
1178
|
+
exports.DynamicClientSessionSignature = DynamicClientSessionSignature;
|
|
1179
|
+
exports.DynamicForwardMPCHeader = DynamicForwardMPCHeader;
|
|
1180
|
+
exports.DynamicMfaTokenHeader = DynamicMfaTokenHeader;
|
|
782
1181
|
exports.DynamicRequestIdHeader = DynamicRequestIdHeader;
|
|
1182
|
+
exports.DynamicTraceElapsedTimeHeader = DynamicTraceElapsedTimeHeader;
|
|
1183
|
+
exports.DynamicTraceIdHeader = DynamicTraceIdHeader;
|
|
783
1184
|
exports.ENVIRONMENT_ENUM = ENVIRONMENT_ENUM;
|
|
1185
|
+
exports.FEATURE_FLAGS = FEATURE_FLAGS;
|
|
784
1186
|
exports.IFRAME_DOMAIN_MAP = IFRAME_DOMAIN_MAP;
|
|
785
1187
|
exports.MPC_CHAIN_CONFIG = MPC_CHAIN_CONFIG;
|
|
786
1188
|
exports.MPC_CONFIG = MPC_CONFIG;
|
|
787
1189
|
exports.MPC_RELAY_DEV_API_URL = MPC_RELAY_DEV_API_URL;
|
|
788
1190
|
exports.MPC_RELAY_PREPROD_API_URL = MPC_RELAY_PREPROD_API_URL;
|
|
789
1191
|
exports.MPC_RELAY_PROD_API_URL = MPC_RELAY_PROD_API_URL;
|
|
1192
|
+
exports.MPC_RELAY_URL_MAP = MPC_RELAY_URL_MAP;
|
|
1193
|
+
exports.PREPROD_RELAY_API_KEY = PREPROD_RELAY_API_KEY;
|
|
1194
|
+
exports.PREPROD_RELAY_APP_ID = PREPROD_RELAY_APP_ID;
|
|
1195
|
+
exports.PROD_RELAY_API_KEY = PROD_RELAY_API_KEY;
|
|
1196
|
+
exports.PROD_RELAY_APP_ID = PROD_RELAY_APP_ID;
|
|
1197
|
+
exports.RELAY_API_KEY_HEADER = RELAY_API_KEY_HEADER;
|
|
1198
|
+
exports.RELAY_APP_ID_HEADER = RELAY_APP_ID_HEADER;
|
|
1199
|
+
exports.SDK_NAMESPACE = SDK_NAMESPACE;
|
|
790
1200
|
exports.SOLANA_RPC_URL = SOLANA_RPC_URL;
|
|
791
1201
|
exports.SigningAlgorithm = SigningAlgorithm;
|
|
792
1202
|
exports.SuccessEventType = SuccessEventType;
|
|
793
1203
|
exports.ThresholdSignatureScheme = ThresholdSignatureScheme;
|
|
794
1204
|
exports.URL_PATTERNS = URL_PATTERNS;
|
|
795
|
-
exports.VerifiedCredentialNameToChainEnum = VerifiedCredentialNameToChainEnum;
|
|
796
1205
|
exports.WalletOperation = WalletOperation;
|
|
797
1206
|
exports.chain = chain;
|
|
1207
|
+
exports.chainEnumToVerifiedCredentialName = chainEnumToVerifiedCredentialName;
|
|
1208
|
+
exports.formatNamespacedVersion = formatNamespacedVersion;
|
|
798
1209
|
exports.getClientThreshold = getClientThreshold;
|
|
799
1210
|
exports.getDynamicServerThreshold = getDynamicServerThreshold;
|
|
800
1211
|
exports.getEnvironmentFromUrl = getEnvironmentFromUrl;
|
|
@@ -802,3 +1213,9 @@ exports.getMPCChainConfig = getMPCChainConfig;
|
|
|
802
1213
|
exports.getReshareConfig = getReshareConfig;
|
|
803
1214
|
exports.getServerWalletReshareConfig = getServerWalletReshareConfig;
|
|
804
1215
|
exports.getTSSConfig = getTSSConfig;
|
|
1216
|
+
exports.getVersionNamespace = getVersionNamespace;
|
|
1217
|
+
exports.getVersionWithoutNamespace = getVersionWithoutNamespace;
|
|
1218
|
+
exports.handleAxiosError = handleAxiosError;
|
|
1219
|
+
exports.parseNamespacedVersion = parseNamespacedVersion;
|
|
1220
|
+
exports.serializeMessageForForwardMPC = serializeMessageForForwardMPC;
|
|
1221
|
+
exports.verifiedCredentialNameToChainEnum = verifiedCredentialNameToChainEnum;
|