@openfort/openfort-js 0.7.6 → 0.7.8
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/README.md +1 -1
- package/dist/index.cjs +721 -353
- package/dist/index.d.ts +308 -21
- package/dist/index.js +722 -355
- package/package.json +4 -1
package/dist/index.cjs
CHANGED
|
@@ -1034,15 +1034,15 @@ const AuthenticationApiAxiosParamCreator = function (configuration) {
|
|
|
1034
1034
|
},
|
|
1035
1035
|
/**
|
|
1036
1036
|
*
|
|
1037
|
-
* @summary Initialize
|
|
1037
|
+
* @summary Initialize OAuth.
|
|
1038
1038
|
* @param {OAuthInitRequest} oAuthInitRequest
|
|
1039
1039
|
* @param {*} [options] Override http request option.
|
|
1040
1040
|
* @throws {RequiredError}
|
|
1041
1041
|
*/
|
|
1042
|
-
|
|
1042
|
+
initOAuth: async (oAuthInitRequest, options = {}) => {
|
|
1043
1043
|
// verify required parameter 'oAuthInitRequest' is not null or undefined
|
|
1044
|
-
assertParamExists('
|
|
1045
|
-
const localVarPath = `/iam/v1/oauth/
|
|
1044
|
+
assertParamExists('initOAuth', 'oAuthInitRequest', oAuthInitRequest);
|
|
1045
|
+
const localVarPath = `/iam/v1/oauth/init`;
|
|
1046
1046
|
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
1047
1047
|
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
1048
1048
|
let baseOptions;
|
|
@@ -1052,6 +1052,9 @@ const AuthenticationApiAxiosParamCreator = function (configuration) {
|
|
|
1052
1052
|
const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
|
|
1053
1053
|
const localVarHeaderParameter = {};
|
|
1054
1054
|
const localVarQueryParameter = {};
|
|
1055
|
+
// authentication pk required
|
|
1056
|
+
// http bearer authentication required
|
|
1057
|
+
await setBearerAuthToObject(localVarHeaderParameter, configuration);
|
|
1055
1058
|
localVarHeaderParameter['Content-Type'] = 'application/json';
|
|
1056
1059
|
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
1057
1060
|
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
@@ -1063,16 +1066,16 @@ const AuthenticationApiAxiosParamCreator = function (configuration) {
|
|
|
1063
1066
|
};
|
|
1064
1067
|
},
|
|
1065
1068
|
/**
|
|
1066
|
-
*
|
|
1067
|
-
* @summary Initialize
|
|
1068
|
-
* @param {
|
|
1069
|
+
* Create a challenge to link external wallet to the player.
|
|
1070
|
+
* @summary Initialize SIWE.
|
|
1071
|
+
* @param {SIWERequest} sIWERequest
|
|
1069
1072
|
* @param {*} [options] Override http request option.
|
|
1070
1073
|
* @throws {RequiredError}
|
|
1071
1074
|
*/
|
|
1072
|
-
|
|
1073
|
-
// verify required parameter '
|
|
1074
|
-
assertParamExists('
|
|
1075
|
-
const localVarPath = `/iam/v1/
|
|
1075
|
+
initSIWE: async (sIWERequest, options = {}) => {
|
|
1076
|
+
// verify required parameter 'sIWERequest' is not null or undefined
|
|
1077
|
+
assertParamExists('initSIWE', 'sIWERequest', sIWERequest);
|
|
1078
|
+
const localVarPath = `/iam/v1/siwe/init`;
|
|
1076
1079
|
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
1077
1080
|
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
1078
1081
|
let baseOptions;
|
|
@@ -1089,23 +1092,22 @@ const AuthenticationApiAxiosParamCreator = function (configuration) {
|
|
|
1089
1092
|
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
1090
1093
|
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
1091
1094
|
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
1092
|
-
localVarRequestOptions.data = serializeDataIfNeeded(
|
|
1095
|
+
localVarRequestOptions.data = serializeDataIfNeeded(sIWERequest, localVarRequestOptions, configuration);
|
|
1093
1096
|
return {
|
|
1094
1097
|
url: toPathString(localVarUrlObj),
|
|
1095
1098
|
options: localVarRequestOptions,
|
|
1096
1099
|
};
|
|
1097
1100
|
},
|
|
1098
1101
|
/**
|
|
1099
|
-
*
|
|
1100
|
-
* @
|
|
1101
|
-
* @param {SIWERequest} sIWERequest
|
|
1102
|
+
*
|
|
1103
|
+
* @param {LoginRequest} loginRequest
|
|
1102
1104
|
* @param {*} [options] Override http request option.
|
|
1103
1105
|
* @throws {RequiredError}
|
|
1104
1106
|
*/
|
|
1105
|
-
|
|
1106
|
-
// verify required parameter '
|
|
1107
|
-
assertParamExists('
|
|
1108
|
-
const localVarPath = `/iam/v1/
|
|
1107
|
+
linkEmail: async (loginRequest, options = {}) => {
|
|
1108
|
+
// verify required parameter 'loginRequest' is not null or undefined
|
|
1109
|
+
assertParamExists('linkEmail', 'loginRequest', loginRequest);
|
|
1110
|
+
const localVarPath = `/iam/v1/password/link`;
|
|
1109
1111
|
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
1110
1112
|
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
1111
1113
|
let baseOptions;
|
|
@@ -1115,14 +1117,41 @@ const AuthenticationApiAxiosParamCreator = function (configuration) {
|
|
|
1115
1117
|
const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
|
|
1116
1118
|
const localVarHeaderParameter = {};
|
|
1117
1119
|
const localVarQueryParameter = {};
|
|
1118
|
-
// authentication pk required
|
|
1119
|
-
// http bearer authentication required
|
|
1120
|
-
await setBearerAuthToObject(localVarHeaderParameter, configuration);
|
|
1121
1120
|
localVarHeaderParameter['Content-Type'] = 'application/json';
|
|
1122
1121
|
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
1123
1122
|
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
1124
1123
|
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
1125
|
-
localVarRequestOptions.data = serializeDataIfNeeded(
|
|
1124
|
+
localVarRequestOptions.data = serializeDataIfNeeded(loginRequest, localVarRequestOptions, configuration);
|
|
1125
|
+
return {
|
|
1126
|
+
url: toPathString(localVarUrlObj),
|
|
1127
|
+
options: localVarRequestOptions,
|
|
1128
|
+
};
|
|
1129
|
+
},
|
|
1130
|
+
/**
|
|
1131
|
+
*
|
|
1132
|
+
* @summary Initialize Link OAuth.
|
|
1133
|
+
* @param {OAuthInitRequest} oAuthInitRequest
|
|
1134
|
+
* @param {*} [options] Override http request option.
|
|
1135
|
+
* @throws {RequiredError}
|
|
1136
|
+
*/
|
|
1137
|
+
linkOAuth: async (oAuthInitRequest, options = {}) => {
|
|
1138
|
+
// verify required parameter 'oAuthInitRequest' is not null or undefined
|
|
1139
|
+
assertParamExists('linkOAuth', 'oAuthInitRequest', oAuthInitRequest);
|
|
1140
|
+
const localVarPath = `/iam/v1/oauth/init_link`;
|
|
1141
|
+
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
1142
|
+
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
1143
|
+
let baseOptions;
|
|
1144
|
+
if (configuration) {
|
|
1145
|
+
baseOptions = configuration.baseOptions;
|
|
1146
|
+
}
|
|
1147
|
+
const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
|
|
1148
|
+
const localVarHeaderParameter = {};
|
|
1149
|
+
const localVarQueryParameter = {};
|
|
1150
|
+
localVarHeaderParameter['Content-Type'] = 'application/json';
|
|
1151
|
+
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
1152
|
+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
1153
|
+
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
1154
|
+
localVarRequestOptions.data = serializeDataIfNeeded(oAuthInitRequest, localVarRequestOptions, configuration);
|
|
1126
1155
|
return {
|
|
1127
1156
|
url: toPathString(localVarUrlObj),
|
|
1128
1157
|
options: localVarRequestOptions,
|
|
@@ -1319,7 +1348,7 @@ const AuthenticationApiAxiosParamCreator = function (configuration) {
|
|
|
1319
1348
|
requestEmailVerification: async (requestVerifyEmailRequest, options = {}) => {
|
|
1320
1349
|
// verify required parameter 'requestVerifyEmailRequest' is not null or undefined
|
|
1321
1350
|
assertParamExists('requestEmailVerification', 'requestVerifyEmailRequest', requestVerifyEmailRequest);
|
|
1322
|
-
const localVarPath = `/iam/v1/password/
|
|
1351
|
+
const localVarPath = `/iam/v1/password/request_email_verification`;
|
|
1323
1352
|
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
1324
1353
|
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
1325
1354
|
let baseOptions;
|
|
@@ -1352,7 +1381,7 @@ const AuthenticationApiAxiosParamCreator = function (configuration) {
|
|
|
1352
1381
|
requestResetPassword: async (requestResetPasswordRequest, options = {}) => {
|
|
1353
1382
|
// verify required parameter 'requestResetPasswordRequest' is not null or undefined
|
|
1354
1383
|
assertParamExists('requestResetPassword', 'requestResetPasswordRequest', requestResetPasswordRequest);
|
|
1355
|
-
const localVarPath = `/iam/v1/password/
|
|
1384
|
+
const localVarPath = `/iam/v1/password/request_reset`;
|
|
1356
1385
|
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
1357
1386
|
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
1358
1387
|
let baseOptions;
|
|
@@ -1385,7 +1414,7 @@ const AuthenticationApiAxiosParamCreator = function (configuration) {
|
|
|
1385
1414
|
resetPassword: async (resetPasswordRequest, options = {}) => {
|
|
1386
1415
|
// verify required parameter 'resetPasswordRequest' is not null or undefined
|
|
1387
1416
|
assertParamExists('resetPassword', 'resetPasswordRequest', resetPasswordRequest);
|
|
1388
|
-
const localVarPath = `/iam/v1/password/
|
|
1417
|
+
const localVarPath = `/iam/v1/password/reset`;
|
|
1389
1418
|
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
1390
1419
|
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
1391
1420
|
let baseOptions;
|
|
@@ -1474,16 +1503,45 @@ const AuthenticationApiAxiosParamCreator = function (configuration) {
|
|
|
1474
1503
|
options: localVarRequestOptions,
|
|
1475
1504
|
};
|
|
1476
1505
|
},
|
|
1506
|
+
/**
|
|
1507
|
+
*
|
|
1508
|
+
* @param {UnlinkEmailRequest} unlinkEmailRequest
|
|
1509
|
+
* @param {*} [options] Override http request option.
|
|
1510
|
+
* @throws {RequiredError}
|
|
1511
|
+
*/
|
|
1512
|
+
unlinkEmail: async (unlinkEmailRequest, options = {}) => {
|
|
1513
|
+
// verify required parameter 'unlinkEmailRequest' is not null or undefined
|
|
1514
|
+
assertParamExists('unlinkEmail', 'unlinkEmailRequest', unlinkEmailRequest);
|
|
1515
|
+
const localVarPath = `/iam/v1/password/unlink`;
|
|
1516
|
+
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
1517
|
+
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
1518
|
+
let baseOptions;
|
|
1519
|
+
if (configuration) {
|
|
1520
|
+
baseOptions = configuration.baseOptions;
|
|
1521
|
+
}
|
|
1522
|
+
const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
|
|
1523
|
+
const localVarHeaderParameter = {};
|
|
1524
|
+
const localVarQueryParameter = {};
|
|
1525
|
+
localVarHeaderParameter['Content-Type'] = 'application/json';
|
|
1526
|
+
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
1527
|
+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
1528
|
+
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
1529
|
+
localVarRequestOptions.data = serializeDataIfNeeded(unlinkEmailRequest, localVarRequestOptions, configuration);
|
|
1530
|
+
return {
|
|
1531
|
+
url: toPathString(localVarUrlObj),
|
|
1532
|
+
options: localVarRequestOptions,
|
|
1533
|
+
};
|
|
1534
|
+
},
|
|
1477
1535
|
/**
|
|
1478
1536
|
*
|
|
1479
1537
|
* @summary Unlink OAuth account
|
|
1480
|
-
* @param {
|
|
1538
|
+
* @param {UnlinkOAuthRequest} unlinkOAuthRequest
|
|
1481
1539
|
* @param {*} [options] Override http request option.
|
|
1482
1540
|
* @throws {RequiredError}
|
|
1483
1541
|
*/
|
|
1484
|
-
unlinkOAuth: async (
|
|
1485
|
-
// verify required parameter '
|
|
1486
|
-
assertParamExists('unlinkOAuth', '
|
|
1542
|
+
unlinkOAuth: async (unlinkOAuthRequest, options = {}) => {
|
|
1543
|
+
// verify required parameter 'unlinkOAuthRequest' is not null or undefined
|
|
1544
|
+
assertParamExists('unlinkOAuth', 'unlinkOAuthRequest', unlinkOAuthRequest);
|
|
1487
1545
|
const localVarPath = `/iam/v1/oauth/unlink`;
|
|
1488
1546
|
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
1489
1547
|
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
@@ -1498,7 +1556,7 @@ const AuthenticationApiAxiosParamCreator = function (configuration) {
|
|
|
1498
1556
|
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
1499
1557
|
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
1500
1558
|
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
1501
|
-
localVarRequestOptions.data = serializeDataIfNeeded(
|
|
1559
|
+
localVarRequestOptions.data = serializeDataIfNeeded(unlinkOAuthRequest, localVarRequestOptions, configuration);
|
|
1502
1560
|
return {
|
|
1503
1561
|
url: toPathString(localVarUrlObj),
|
|
1504
1562
|
options: localVarRequestOptions,
|
|
@@ -1544,7 +1602,7 @@ const AuthenticationApiAxiosParamCreator = function (configuration) {
|
|
|
1544
1602
|
verifyEmail: async (verifyEmailRequest, options = {}) => {
|
|
1545
1603
|
// verify required parameter 'verifyEmailRequest' is not null or undefined
|
|
1546
1604
|
assertParamExists('verifyEmail', 'verifyEmailRequest', verifyEmailRequest);
|
|
1547
|
-
const localVarPath = `/iam/v1/password/
|
|
1605
|
+
const localVarPath = `/iam/v1/password/verify_email`;
|
|
1548
1606
|
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
1549
1607
|
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
1550
1608
|
let baseOptions;
|
|
@@ -1693,17 +1751,6 @@ const AuthenticationApiFp = function (configuration) {
|
|
|
1693
1751
|
const localVarAxiosArgs = await localVarAxiosParamCreator.getJwks(publishableKey, options);
|
|
1694
1752
|
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
1695
1753
|
},
|
|
1696
|
-
/**
|
|
1697
|
-
*
|
|
1698
|
-
* @summary Initialize Link OAuth.
|
|
1699
|
-
* @param {OAuthInitRequest} oAuthInitRequest
|
|
1700
|
-
* @param {*} [options] Override http request option.
|
|
1701
|
-
* @throws {RequiredError}
|
|
1702
|
-
*/
|
|
1703
|
-
async initLinkOAuth(oAuthInitRequest, options) {
|
|
1704
|
-
const localVarAxiosArgs = await localVarAxiosParamCreator.initLinkOAuth(oAuthInitRequest, options);
|
|
1705
|
-
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
1706
|
-
},
|
|
1707
1754
|
/**
|
|
1708
1755
|
*
|
|
1709
1756
|
* @summary Initialize OAuth.
|
|
@@ -1726,6 +1773,27 @@ const AuthenticationApiFp = function (configuration) {
|
|
|
1726
1773
|
const localVarAxiosArgs = await localVarAxiosParamCreator.initSIWE(sIWERequest, options);
|
|
1727
1774
|
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
1728
1775
|
},
|
|
1776
|
+
/**
|
|
1777
|
+
*
|
|
1778
|
+
* @param {LoginRequest} loginRequest
|
|
1779
|
+
* @param {*} [options] Override http request option.
|
|
1780
|
+
* @throws {RequiredError}
|
|
1781
|
+
*/
|
|
1782
|
+
async linkEmail(loginRequest, options) {
|
|
1783
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.linkEmail(loginRequest, options);
|
|
1784
|
+
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
1785
|
+
},
|
|
1786
|
+
/**
|
|
1787
|
+
*
|
|
1788
|
+
* @summary Initialize Link OAuth.
|
|
1789
|
+
* @param {OAuthInitRequest} oAuthInitRequest
|
|
1790
|
+
* @param {*} [options] Override http request option.
|
|
1791
|
+
* @throws {RequiredError}
|
|
1792
|
+
*/
|
|
1793
|
+
async linkOAuth(oAuthInitRequest, options) {
|
|
1794
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.linkOAuth(oAuthInitRequest, options);
|
|
1795
|
+
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
1796
|
+
},
|
|
1729
1797
|
/**
|
|
1730
1798
|
*
|
|
1731
1799
|
* @summary Link external wallet.
|
|
@@ -1845,15 +1913,25 @@ const AuthenticationApiFp = function (configuration) {
|
|
|
1845
1913
|
const localVarAxiosArgs = await localVarAxiosParamCreator.thirdParty(thirdPartyOAuthRequest, options);
|
|
1846
1914
|
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
1847
1915
|
},
|
|
1916
|
+
/**
|
|
1917
|
+
*
|
|
1918
|
+
* @param {UnlinkEmailRequest} unlinkEmailRequest
|
|
1919
|
+
* @param {*} [options] Override http request option.
|
|
1920
|
+
* @throws {RequiredError}
|
|
1921
|
+
*/
|
|
1922
|
+
async unlinkEmail(unlinkEmailRequest, options) {
|
|
1923
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.unlinkEmail(unlinkEmailRequest, options);
|
|
1924
|
+
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
1925
|
+
},
|
|
1848
1926
|
/**
|
|
1849
1927
|
*
|
|
1850
1928
|
* @summary Unlink OAuth account
|
|
1851
|
-
* @param {
|
|
1929
|
+
* @param {UnlinkOAuthRequest} unlinkOAuthRequest
|
|
1852
1930
|
* @param {*} [options] Override http request option.
|
|
1853
1931
|
* @throws {RequiredError}
|
|
1854
1932
|
*/
|
|
1855
|
-
async unlinkOAuth(
|
|
1856
|
-
const localVarAxiosArgs = await localVarAxiosParamCreator.unlinkOAuth(
|
|
1933
|
+
async unlinkOAuth(unlinkOAuthRequest, options) {
|
|
1934
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.unlinkOAuth(unlinkOAuthRequest, options);
|
|
1857
1935
|
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
1858
1936
|
},
|
|
1859
1937
|
/**
|
|
@@ -1956,17 +2034,6 @@ class AuthenticationApi extends BaseAPI {
|
|
|
1956
2034
|
getJwks(requestParameters, options) {
|
|
1957
2035
|
return AuthenticationApiFp(this.configuration).getJwks(requestParameters.publishableKey, options).then((request) => request(this.axios, this.basePath));
|
|
1958
2036
|
}
|
|
1959
|
-
/**
|
|
1960
|
-
*
|
|
1961
|
-
* @summary Initialize Link OAuth.
|
|
1962
|
-
* @param {AuthenticationApiInitLinkOAuthRequest} requestParameters Request parameters.
|
|
1963
|
-
* @param {*} [options] Override http request option.
|
|
1964
|
-
* @throws {RequiredError}
|
|
1965
|
-
* @memberof AuthenticationApi
|
|
1966
|
-
*/
|
|
1967
|
-
initLinkOAuth(requestParameters, options) {
|
|
1968
|
-
return AuthenticationApiFp(this.configuration).initLinkOAuth(requestParameters.oAuthInitRequest, options).then((request) => request(this.axios, this.basePath));
|
|
1969
|
-
}
|
|
1970
2037
|
/**
|
|
1971
2038
|
*
|
|
1972
2039
|
* @summary Initialize OAuth.
|
|
@@ -1989,6 +2056,27 @@ class AuthenticationApi extends BaseAPI {
|
|
|
1989
2056
|
initSIWE(requestParameters, options) {
|
|
1990
2057
|
return AuthenticationApiFp(this.configuration).initSIWE(requestParameters.sIWERequest, options).then((request) => request(this.axios, this.basePath));
|
|
1991
2058
|
}
|
|
2059
|
+
/**
|
|
2060
|
+
*
|
|
2061
|
+
* @param {AuthenticationApiLinkEmailRequest} requestParameters Request parameters.
|
|
2062
|
+
* @param {*} [options] Override http request option.
|
|
2063
|
+
* @throws {RequiredError}
|
|
2064
|
+
* @memberof AuthenticationApi
|
|
2065
|
+
*/
|
|
2066
|
+
linkEmail(requestParameters, options) {
|
|
2067
|
+
return AuthenticationApiFp(this.configuration).linkEmail(requestParameters.loginRequest, options).then((request) => request(this.axios, this.basePath));
|
|
2068
|
+
}
|
|
2069
|
+
/**
|
|
2070
|
+
*
|
|
2071
|
+
* @summary Initialize Link OAuth.
|
|
2072
|
+
* @param {AuthenticationApiLinkOAuthRequest} requestParameters Request parameters.
|
|
2073
|
+
* @param {*} [options] Override http request option.
|
|
2074
|
+
* @throws {RequiredError}
|
|
2075
|
+
* @memberof AuthenticationApi
|
|
2076
|
+
*/
|
|
2077
|
+
linkOAuth(requestParameters, options) {
|
|
2078
|
+
return AuthenticationApiFp(this.configuration).linkOAuth(requestParameters.oAuthInitRequest, options).then((request) => request(this.axios, this.basePath));
|
|
2079
|
+
}
|
|
1992
2080
|
/**
|
|
1993
2081
|
*
|
|
1994
2082
|
* @summary Link external wallet.
|
|
@@ -2108,6 +2196,16 @@ class AuthenticationApi extends BaseAPI {
|
|
|
2108
2196
|
thirdParty(requestParameters, options) {
|
|
2109
2197
|
return AuthenticationApiFp(this.configuration).thirdParty(requestParameters.thirdPartyOAuthRequest, options).then((request) => request(this.axios, this.basePath));
|
|
2110
2198
|
}
|
|
2199
|
+
/**
|
|
2200
|
+
*
|
|
2201
|
+
* @param {AuthenticationApiUnlinkEmailRequest} requestParameters Request parameters.
|
|
2202
|
+
* @param {*} [options] Override http request option.
|
|
2203
|
+
* @throws {RequiredError}
|
|
2204
|
+
* @memberof AuthenticationApi
|
|
2205
|
+
*/
|
|
2206
|
+
unlinkEmail(requestParameters, options) {
|
|
2207
|
+
return AuthenticationApiFp(this.configuration).unlinkEmail(requestParameters.unlinkEmailRequest, options).then((request) => request(this.axios, this.basePath));
|
|
2208
|
+
}
|
|
2111
2209
|
/**
|
|
2112
2210
|
*
|
|
2113
2211
|
* @summary Unlink OAuth account
|
|
@@ -2117,7 +2215,7 @@ class AuthenticationApi extends BaseAPI {
|
|
|
2117
2215
|
* @memberof AuthenticationApi
|
|
2118
2216
|
*/
|
|
2119
2217
|
unlinkOAuth(requestParameters, options) {
|
|
2120
|
-
return AuthenticationApiFp(this.configuration).unlinkOAuth(requestParameters.
|
|
2218
|
+
return AuthenticationApiFp(this.configuration).unlinkOAuth(requestParameters.unlinkOAuthRequest, options).then((request) => request(this.axios, this.basePath));
|
|
2121
2219
|
}
|
|
2122
2220
|
/**
|
|
2123
2221
|
*
|
|
@@ -2996,16 +3094,18 @@ var OpenfortErrorType;
|
|
|
2996
3094
|
(function (OpenfortErrorType) {
|
|
2997
3095
|
OpenfortErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
|
|
2998
3096
|
OpenfortErrorType["INVALID_CONFIGURATION"] = "INVALID_CONFIGURATION";
|
|
2999
|
-
OpenfortErrorType["WALLET_CONNECTION_ERROR"] = "WALLET_CONNECTION_ERROR";
|
|
3000
3097
|
OpenfortErrorType["NOT_LOGGED_IN_ERROR"] = "NOT_LOGGED_IN_ERROR";
|
|
3001
|
-
OpenfortErrorType["SILENT_LOGIN_ERROR"] = "SILENT_LOGIN_ERROR";
|
|
3002
3098
|
OpenfortErrorType["REFRESH_TOKEN_ERROR"] = "REFRESH_TOKEN_ERROR";
|
|
3003
3099
|
OpenfortErrorType["USER_REGISTRATION_ERROR"] = "USER_REGISTRATION_ERROR";
|
|
3004
|
-
OpenfortErrorType["USER_NOT_REGISTERED_ERROR"] = "USER_NOT_REGISTERED_ERROR";
|
|
3005
3100
|
OpenfortErrorType["LOGOUT_ERROR"] = "LOGOUT_ERROR";
|
|
3006
|
-
OpenfortErrorType["TRANSFER_ERROR"] = "TRANSFER_ERROR";
|
|
3007
3101
|
OpenfortErrorType["OPERATION_NOT_SUPPORTED_ERROR"] = "OPERATION_NOT_SUPPORTED_ERROR";
|
|
3102
|
+
OpenfortErrorType["MISSING_SESSION_SIGNER_ERROR"] = "MISSING_SESSION_SIGNER_ERROR";
|
|
3103
|
+
OpenfortErrorType["MISSING_EMBEDDED_SIGNER_ERROR"] = "MISSING_EMBEDDED_SIGNER_ERROR";
|
|
3104
|
+
OpenfortErrorType["MISSING_SIGNER_ERROR"] = "MISSING_SIGNER_ERROR";
|
|
3008
3105
|
})(OpenfortErrorType || (OpenfortErrorType = {}));
|
|
3106
|
+
function isAPIError(error) {
|
|
3107
|
+
return 'code' in error && 'message' in error;
|
|
3108
|
+
}
|
|
3009
3109
|
class OpenfortError extends Error {
|
|
3010
3110
|
type;
|
|
3011
3111
|
constructor(message, type) {
|
|
@@ -3013,6 +3113,21 @@ class OpenfortError extends Error {
|
|
|
3013
3113
|
this.type = type;
|
|
3014
3114
|
}
|
|
3015
3115
|
}
|
|
3116
|
+
const withOpenfortError = async (fn, customErrorType) => {
|
|
3117
|
+
try {
|
|
3118
|
+
return await fn();
|
|
3119
|
+
}
|
|
3120
|
+
catch (error) {
|
|
3121
|
+
let errorMessage;
|
|
3122
|
+
if (globalAxios.isAxiosError(error) && error.response?.data && isAPIError(error.response.data)) {
|
|
3123
|
+
errorMessage = error.response.data.message;
|
|
3124
|
+
}
|
|
3125
|
+
else {
|
|
3126
|
+
errorMessage = error.message;
|
|
3127
|
+
}
|
|
3128
|
+
throw new OpenfortError(errorMessage, customErrorType);
|
|
3129
|
+
}
|
|
3130
|
+
};
|
|
3016
3131
|
|
|
3017
3132
|
const validateConfiguration = (configuration, requiredKeys, prefix) => {
|
|
3018
3133
|
const missingKeys = requiredKeys
|
|
@@ -4567,12 +4682,12 @@ class AuthManager {
|
|
|
4567
4682
|
this.backendApiClients = backendApiClients;
|
|
4568
4683
|
this.instanceManager = instanceManager;
|
|
4569
4684
|
}
|
|
4570
|
-
async initOAuth(provider,
|
|
4685
|
+
async initOAuth(provider, options) {
|
|
4571
4686
|
const request = {
|
|
4572
4687
|
oAuthInitRequest: {
|
|
4573
4688
|
provider,
|
|
4574
4689
|
options,
|
|
4575
|
-
usePooling: usePooling || false,
|
|
4690
|
+
usePooling: options?.usePooling || false,
|
|
4576
4691
|
},
|
|
4577
4692
|
};
|
|
4578
4693
|
const result = await this.backendApiClients.authenticationApi.initOAuth(request);
|
|
@@ -4584,26 +4699,6 @@ class AuthManager {
|
|
|
4584
4699
|
key: result.data.key,
|
|
4585
4700
|
};
|
|
4586
4701
|
}
|
|
4587
|
-
async initLinkOAuth(provider, playerToken, usePooling, options) {
|
|
4588
|
-
const request = {
|
|
4589
|
-
oAuthInitRequest: {
|
|
4590
|
-
provider,
|
|
4591
|
-
options,
|
|
4592
|
-
usePooling: usePooling || false,
|
|
4593
|
-
},
|
|
4594
|
-
};
|
|
4595
|
-
const result = await this.backendApiClients.authenticationApi.initLinkOAuth(request, {
|
|
4596
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
4597
|
-
headers: { 'x-player-token': playerToken },
|
|
4598
|
-
});
|
|
4599
|
-
if (isBrowser() && !options?.skipBrowserRedirect) {
|
|
4600
|
-
window.location.assign(result.data.url);
|
|
4601
|
-
}
|
|
4602
|
-
return {
|
|
4603
|
-
url: result.data.url,
|
|
4604
|
-
key: result.data.key,
|
|
4605
|
-
};
|
|
4606
|
-
}
|
|
4607
4702
|
async poolOAuth(key) {
|
|
4608
4703
|
const request = {
|
|
4609
4704
|
key,
|
|
@@ -4636,18 +4731,6 @@ class AuthManager {
|
|
|
4636
4731
|
}
|
|
4637
4732
|
throw new Error('Failed to pool OAuth, try again later');
|
|
4638
4733
|
}
|
|
4639
|
-
// @deprecated
|
|
4640
|
-
async authenticateOAuth(provider, token, tokenType) {
|
|
4641
|
-
const request = {
|
|
4642
|
-
authenticateOAuthRequest: {
|
|
4643
|
-
provider,
|
|
4644
|
-
token,
|
|
4645
|
-
tokenType,
|
|
4646
|
-
},
|
|
4647
|
-
};
|
|
4648
|
-
const response = await this.backendApiClients.authenticationApi.authenticateOAuth(request);
|
|
4649
|
-
return response.data;
|
|
4650
|
-
}
|
|
4651
4734
|
async authenticateThirdParty(provider, token, tokenType) {
|
|
4652
4735
|
const request = {
|
|
4653
4736
|
thirdPartyOAuthRequest: {
|
|
@@ -4656,8 +4739,10 @@ class AuthManager {
|
|
|
4656
4739
|
tokenType,
|
|
4657
4740
|
},
|
|
4658
4741
|
};
|
|
4659
|
-
|
|
4660
|
-
|
|
4742
|
+
return withOpenfortError(async () => {
|
|
4743
|
+
const response = await this.backendApiClients.authenticationApi.thirdParty(request);
|
|
4744
|
+
return response.data;
|
|
4745
|
+
}, OpenfortErrorType.AUTHENTICATION_ERROR);
|
|
4661
4746
|
}
|
|
4662
4747
|
async initSIWE(address) {
|
|
4663
4748
|
const request = {
|
|
@@ -4681,8 +4766,10 @@ class AuthManager {
|
|
|
4681
4766
|
connectorType,
|
|
4682
4767
|
},
|
|
4683
4768
|
};
|
|
4684
|
-
|
|
4685
|
-
|
|
4769
|
+
return withOpenfortError(async () => {
|
|
4770
|
+
const response = await this.backendApiClients.authenticationApi.authenticateSIWE(request);
|
|
4771
|
+
return response.data;
|
|
4772
|
+
}, OpenfortErrorType.AUTHENTICATION_ERROR);
|
|
4686
4773
|
}
|
|
4687
4774
|
async loginEmailPassword(email, password) {
|
|
4688
4775
|
const request = {
|
|
@@ -4691,8 +4778,10 @@ class AuthManager {
|
|
|
4691
4778
|
password,
|
|
4692
4779
|
},
|
|
4693
4780
|
};
|
|
4694
|
-
|
|
4695
|
-
|
|
4781
|
+
return withOpenfortError(async () => {
|
|
4782
|
+
const response = await this.backendApiClients.authenticationApi.loginEmailPassword(request);
|
|
4783
|
+
return response.data;
|
|
4784
|
+
}, OpenfortErrorType.AUTHENTICATION_ERROR);
|
|
4696
4785
|
}
|
|
4697
4786
|
async requestResetPassword(email, redirectUrl) {
|
|
4698
4787
|
const verifier = base64URLEncode(crypto__namespace.randomBytes(32));
|
|
@@ -4713,25 +4802,23 @@ class AuthManager {
|
|
|
4713
4802
|
await this.backendApiClients.authenticationApi.requestResetPassword(request);
|
|
4714
4803
|
}
|
|
4715
4804
|
async resetPassword(email, password, state) {
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
codeVerifier: pkceData.verifier,
|
|
4730
|
-
method: CodeChallengeMethodEnum.S256,
|
|
4805
|
+
return withOpenfortError(async () => {
|
|
4806
|
+
const pkceData = this.deviceCredentialsManager.getPKCEData();
|
|
4807
|
+
if (!pkceData) {
|
|
4808
|
+
throw new Error('No code verifier or state for PKCE');
|
|
4809
|
+
}
|
|
4810
|
+
const request = {
|
|
4811
|
+
resetPasswordRequest: {
|
|
4812
|
+
email,
|
|
4813
|
+
password,
|
|
4814
|
+
state,
|
|
4815
|
+
challenge: {
|
|
4816
|
+
codeVerifier: pkceData.verifier,
|
|
4817
|
+
},
|
|
4731
4818
|
},
|
|
4732
|
-
}
|
|
4733
|
-
|
|
4734
|
-
|
|
4819
|
+
};
|
|
4820
|
+
await this.backendApiClients.authenticationApi.resetPassword(request);
|
|
4821
|
+
}, OpenfortErrorType.AUTHENTICATION_ERROR);
|
|
4735
4822
|
}
|
|
4736
4823
|
async requestEmailVerification(email, redirectUrl) {
|
|
4737
4824
|
const verifier = base64URLEncode(crypto__namespace.randomBytes(32));
|
|
@@ -4752,24 +4839,22 @@ class AuthManager {
|
|
|
4752
4839
|
await this.backendApiClients.authenticationApi.requestEmailVerification(request);
|
|
4753
4840
|
}
|
|
4754
4841
|
async verifyEmail(email, state) {
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
codeVerifier: pkceData.verifier,
|
|
4768
|
-
method: CodeChallengeMethodEnum.S256,
|
|
4842
|
+
return withOpenfortError(async () => {
|
|
4843
|
+
const pkceData = this.deviceCredentialsManager.getPKCEData();
|
|
4844
|
+
if (!pkceData) {
|
|
4845
|
+
throw new Error('No code verifier or state for PKCE');
|
|
4846
|
+
}
|
|
4847
|
+
const request = {
|
|
4848
|
+
verifyEmailRequest: {
|
|
4849
|
+
email,
|
|
4850
|
+
token: state,
|
|
4851
|
+
challenge: {
|
|
4852
|
+
codeVerifier: pkceData.verifier,
|
|
4853
|
+
},
|
|
4769
4854
|
},
|
|
4770
|
-
}
|
|
4771
|
-
|
|
4772
|
-
|
|
4855
|
+
};
|
|
4856
|
+
await this.backendApiClients.authenticationApi.verifyEmail(request);
|
|
4857
|
+
}, OpenfortErrorType.AUTHENTICATION_ERROR);
|
|
4773
4858
|
}
|
|
4774
4859
|
async signupEmailPassword(email, password, name) {
|
|
4775
4860
|
const request = {
|
|
@@ -4779,8 +4864,10 @@ class AuthManager {
|
|
|
4779
4864
|
name,
|
|
4780
4865
|
},
|
|
4781
4866
|
};
|
|
4782
|
-
|
|
4783
|
-
|
|
4867
|
+
return withOpenfortError(async () => {
|
|
4868
|
+
const response = await this.backendApiClients.authenticationApi.signupEmailPassword(request);
|
|
4869
|
+
return response.data;
|
|
4870
|
+
}, OpenfortErrorType.USER_REGISTRATION_ERROR);
|
|
4784
4871
|
}
|
|
4785
4872
|
async validateCredentials(accessToken, refreshToken, jwk) {
|
|
4786
4873
|
try {
|
|
@@ -4804,12 +4891,14 @@ class AuthManager {
|
|
|
4804
4891
|
refreshToken,
|
|
4805
4892
|
},
|
|
4806
4893
|
};
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4894
|
+
return withOpenfortError(async () => {
|
|
4895
|
+
const newToken = await this.backendApiClients.authenticationApi.refresh(request);
|
|
4896
|
+
return {
|
|
4897
|
+
player: newToken.data.player.id,
|
|
4898
|
+
accessToken: newToken.data.token,
|
|
4899
|
+
refreshToken: newToken.data.refreshToken,
|
|
4900
|
+
};
|
|
4901
|
+
}, OpenfortErrorType.REFRESH_TOKEN_ERROR);
|
|
4813
4902
|
}
|
|
4814
4903
|
throw error;
|
|
4815
4904
|
}
|
|
@@ -4820,57 +4909,172 @@ class AuthManager {
|
|
|
4820
4909
|
refreshToken,
|
|
4821
4910
|
},
|
|
4822
4911
|
};
|
|
4823
|
-
|
|
4912
|
+
withOpenfortError(async () => {
|
|
4913
|
+
await this.backendApiClients.authenticationApi.logout(request, {
|
|
4914
|
+
headers: {
|
|
4915
|
+
authorization: `Bearer ${this.config.baseConfiguration.publishableKey}`,
|
|
4916
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
4917
|
+
'x-player-token': accessToken,
|
|
4918
|
+
},
|
|
4919
|
+
});
|
|
4920
|
+
}, OpenfortErrorType.LOGOUT_ERROR);
|
|
4921
|
+
}
|
|
4922
|
+
async getUser(accessToken) {
|
|
4923
|
+
// TODO: Add storage of user info
|
|
4924
|
+
const response = await this.backendApiClients.authenticationApi.me({
|
|
4824
4925
|
headers: {
|
|
4825
4926
|
authorization: `Bearer ${this.config.baseConfiguration.publishableKey}`,
|
|
4826
4927
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
4827
4928
|
'x-player-token': accessToken,
|
|
4828
4929
|
},
|
|
4829
4930
|
});
|
|
4931
|
+
return response.data;
|
|
4932
|
+
}
|
|
4933
|
+
async linkOAuth(provider, playerToken, options) {
|
|
4934
|
+
const request = {
|
|
4935
|
+
oAuthInitRequest: {
|
|
4936
|
+
provider,
|
|
4937
|
+
options,
|
|
4938
|
+
usePooling: options?.usePooling || false,
|
|
4939
|
+
},
|
|
4940
|
+
};
|
|
4941
|
+
const result = await this.backendApiClients.authenticationApi.linkOAuth(request, {
|
|
4942
|
+
headers: {
|
|
4943
|
+
authorization: `Bearer ${this.config.baseConfiguration.publishableKey}`,
|
|
4944
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
4945
|
+
'x-player-token': playerToken,
|
|
4946
|
+
},
|
|
4947
|
+
});
|
|
4948
|
+
if (isBrowser() && !options?.skipBrowserRedirect) {
|
|
4949
|
+
window.location.assign(result.data.url);
|
|
4950
|
+
}
|
|
4951
|
+
return {
|
|
4952
|
+
url: result.data.url,
|
|
4953
|
+
key: result.data.key,
|
|
4954
|
+
};
|
|
4955
|
+
}
|
|
4956
|
+
async unlinkOAuth(provider, accessToken) {
|
|
4957
|
+
const request = {
|
|
4958
|
+
unlinkOAuthRequest: {
|
|
4959
|
+
provider,
|
|
4960
|
+
},
|
|
4961
|
+
};
|
|
4962
|
+
const authPlayerResponse = await this.backendApiClients.authenticationApi.unlinkOAuth(request, {
|
|
4963
|
+
headers: {
|
|
4964
|
+
authorization: `Bearer ${this.config.baseConfiguration.publishableKey}`,
|
|
4965
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
4966
|
+
'x-player-token': accessToken,
|
|
4967
|
+
},
|
|
4968
|
+
});
|
|
4969
|
+
return authPlayerResponse.data;
|
|
4970
|
+
}
|
|
4971
|
+
async unlinkWallet(address, accessToken) {
|
|
4972
|
+
const request = {
|
|
4973
|
+
sIWERequest: {
|
|
4974
|
+
address,
|
|
4975
|
+
},
|
|
4976
|
+
};
|
|
4977
|
+
const authPlayerResponse = await this.backendApiClients.authenticationApi.unlinkSIWE(request, {
|
|
4978
|
+
headers: {
|
|
4979
|
+
authorization: `Bearer ${this.config.baseConfiguration.publishableKey}`,
|
|
4980
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
4981
|
+
'x-player-token': accessToken,
|
|
4982
|
+
},
|
|
4983
|
+
});
|
|
4984
|
+
return authPlayerResponse.data;
|
|
4985
|
+
}
|
|
4986
|
+
async linkWallet(signature, message, walletClientType, connectorType, accessToken) {
|
|
4987
|
+
const request = {
|
|
4988
|
+
sIWEAuthenticateRequest: {
|
|
4989
|
+
signature,
|
|
4990
|
+
message,
|
|
4991
|
+
walletClientType,
|
|
4992
|
+
connectorType,
|
|
4993
|
+
},
|
|
4994
|
+
};
|
|
4995
|
+
const authPlayerResponse = await this.backendApiClients.authenticationApi.linkSIWE(request, {
|
|
4996
|
+
headers: {
|
|
4997
|
+
authorization: `Bearer ${this.config.baseConfiguration.publishableKey}`,
|
|
4998
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
4999
|
+
'x-player-token': accessToken,
|
|
5000
|
+
},
|
|
5001
|
+
});
|
|
5002
|
+
return authPlayerResponse.data;
|
|
5003
|
+
}
|
|
5004
|
+
async unlinkEmail(email, accessToken) {
|
|
5005
|
+
const request = {
|
|
5006
|
+
unlinkEmailRequest: {
|
|
5007
|
+
email,
|
|
5008
|
+
},
|
|
5009
|
+
};
|
|
5010
|
+
const authPlayerResponse = await this.backendApiClients.authenticationApi.unlinkEmail(request, {
|
|
5011
|
+
headers: {
|
|
5012
|
+
authorization: `Bearer ${this.config.baseConfiguration.publishableKey}`,
|
|
5013
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
5014
|
+
'x-player-token': accessToken,
|
|
5015
|
+
},
|
|
5016
|
+
});
|
|
5017
|
+
return authPlayerResponse.data;
|
|
5018
|
+
}
|
|
5019
|
+
async linkEmail(email, password, accessToken) {
|
|
5020
|
+
const request = {
|
|
5021
|
+
loginRequest: {
|
|
5022
|
+
email,
|
|
5023
|
+
password,
|
|
5024
|
+
},
|
|
5025
|
+
};
|
|
5026
|
+
const authPlayerResponse = await this.backendApiClients.authenticationApi.linkEmail(request, {
|
|
5027
|
+
headers: {
|
|
5028
|
+
authorization: `Bearer ${this.config.baseConfiguration.publishableKey}`,
|
|
5029
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
5030
|
+
'x-player-token': accessToken,
|
|
5031
|
+
},
|
|
5032
|
+
});
|
|
5033
|
+
return authPlayerResponse.data;
|
|
5034
|
+
}
|
|
5035
|
+
}
|
|
5036
|
+
|
|
5037
|
+
const authTokenStorageKey = 'openfort.auth_token';
|
|
5038
|
+
const thirdPartyProviderStorageKey = 'openfort.third_party_provider';
|
|
5039
|
+
const thirdPartyProviderTokenTypeStorageKey = 'openfort.third_party_provider_token_type';
|
|
5040
|
+
const refreshTokenStorageKey = 'openfort.refresh_token';
|
|
5041
|
+
const playerIDStorageKey = 'openfort.player_id';
|
|
5042
|
+
const sessionKeyStorageKey = 'openfort.session_key';
|
|
5043
|
+
const signerTypeStorageKey = 'openfort.signer_type';
|
|
5044
|
+
const chainIDStorageKey = 'openfort.chain_id';
|
|
5045
|
+
const jwksStorageKey = 'openfort.jwk';
|
|
5046
|
+
const deviceIDStorageKey = 'openfort.device_id';
|
|
5047
|
+
const accountTypeStorageKey = 'openfort.account_type';
|
|
5048
|
+
const accountAddressStorageKey = 'openfort.account_address';
|
|
5049
|
+
|
|
5050
|
+
class InstanceManager {
|
|
5051
|
+
authToken = null;
|
|
5052
|
+
refreshToken = null;
|
|
5053
|
+
signerType = null;
|
|
5054
|
+
jwk = null;
|
|
5055
|
+
sessionKey = null;
|
|
5056
|
+
deviceID = null;
|
|
5057
|
+
chainId = null;
|
|
5058
|
+
accountAddress = null;
|
|
5059
|
+
accountType = null;
|
|
5060
|
+
temporalStorage;
|
|
5061
|
+
persistentStorage;
|
|
5062
|
+
secureStorage;
|
|
5063
|
+
config;
|
|
5064
|
+
backendApiClients;
|
|
5065
|
+
playerId = null;
|
|
5066
|
+
constructor(temporalStorage, persistentStorage, secureStorage, config, backendApiClients) {
|
|
5067
|
+
this.temporalStorage = temporalStorage;
|
|
5068
|
+
this.persistentStorage = persistentStorage;
|
|
5069
|
+
this.secureStorage = secureStorage;
|
|
5070
|
+
this.config = config;
|
|
5071
|
+
this.backendApiClients = backendApiClients;
|
|
4830
5072
|
}
|
|
4831
|
-
}
|
|
4832
|
-
|
|
4833
|
-
const authTokenStorageKey = 'openfort.auth_token';
|
|
4834
|
-
const thirdPartyProviderStorageKey = 'openfort.third_party_provider';
|
|
4835
|
-
const thirdPartyProviderTokenTypeStorageKey = 'openfort.third_party_provider_token_type';
|
|
4836
|
-
const refreshTokenStorageKey = 'openfort.refresh_token';
|
|
4837
|
-
const playerIDStorageKey = 'openfort.player_id';
|
|
4838
|
-
const sessionKeyStorageKey = 'openfort.session_key';
|
|
4839
|
-
const signerTypeStorageKey = 'openfort.signer_type';
|
|
4840
|
-
const chainIDStorageKey = 'openfort.chain_id';
|
|
4841
|
-
const jwksStorageKey = 'openfort.jwk';
|
|
4842
|
-
const deviceIDStorageKey = 'openfort.device_id';
|
|
4843
|
-
const accountTypeStorageKey = 'openfort.account_type';
|
|
4844
|
-
const accountAddressStorageKey = 'openfort.account_address';
|
|
4845
|
-
|
|
4846
|
-
class InstanceManager {
|
|
4847
|
-
authToken = null;
|
|
4848
|
-
refreshToken = null;
|
|
4849
|
-
signerType = null;
|
|
4850
|
-
jwk = null;
|
|
4851
|
-
sessionKey = null;
|
|
4852
|
-
deviceID = null;
|
|
4853
|
-
chainId = null;
|
|
4854
|
-
accountAddress = null;
|
|
4855
|
-
accountType = null;
|
|
4856
|
-
temporalStorage;
|
|
4857
|
-
persistentStorage;
|
|
4858
|
-
secureStorage;
|
|
4859
|
-
config;
|
|
4860
|
-
backendApiClients;
|
|
4861
|
-
playerId = null;
|
|
4862
|
-
constructor(temporalStorage, persistentStorage, secureStorage, config, backendApiClients) {
|
|
4863
|
-
this.temporalStorage = temporalStorage;
|
|
4864
|
-
this.persistentStorage = persistentStorage;
|
|
4865
|
-
this.secureStorage = secureStorage;
|
|
4866
|
-
this.config = config;
|
|
4867
|
-
this.backendApiClients = backendApiClients;
|
|
4868
|
-
}
|
|
4869
5073
|
getAccessToken() {
|
|
4870
5074
|
if (!this.authToken) {
|
|
4871
5075
|
const token = this.secureStorage.get(authTokenStorageKey);
|
|
4872
5076
|
if (token === null)
|
|
4873
|
-
return null;
|
|
5077
|
+
return null;
|
|
4874
5078
|
this.authToken = {
|
|
4875
5079
|
token,
|
|
4876
5080
|
thirdPartyProvider: this.secureStorage.get(thirdPartyProviderStorageKey),
|
|
@@ -5652,34 +5856,6 @@ class IframeManager {
|
|
|
5652
5856
|
}
|
|
5653
5857
|
}
|
|
5654
5858
|
|
|
5655
|
-
class NotLoggedIn extends Error {
|
|
5656
|
-
constructor(message) {
|
|
5657
|
-
super(message);
|
|
5658
|
-
this.name = 'NotLoggedIn';
|
|
5659
|
-
Object.setPrototypeOf(this, NotLoggedIn.prototype);
|
|
5660
|
-
}
|
|
5661
|
-
}
|
|
5662
|
-
class EmbeddedNotConfigured extends Error {
|
|
5663
|
-
constructor(message) {
|
|
5664
|
-
super(message);
|
|
5665
|
-
this.name = 'EmbeddedNotConfigured';
|
|
5666
|
-
Object.setPrototypeOf(this, EmbeddedNotConfigured.prototype);
|
|
5667
|
-
}
|
|
5668
|
-
}
|
|
5669
|
-
class NoSignerConfigured extends Error {
|
|
5670
|
-
constructor(message) {
|
|
5671
|
-
super(message);
|
|
5672
|
-
this.name = 'NoSignerConfigured';
|
|
5673
|
-
Object.setPrototypeOf(this, NoSignerConfigured.prototype);
|
|
5674
|
-
}
|
|
5675
|
-
}
|
|
5676
|
-
class NothingToSign extends Error {
|
|
5677
|
-
constructor(message) {
|
|
5678
|
-
super(message);
|
|
5679
|
-
this.name = 'NothingToSign';
|
|
5680
|
-
Object.setPrototypeOf(this, NothingToSign.prototype);
|
|
5681
|
-
}
|
|
5682
|
-
}
|
|
5683
5859
|
class Openfort {
|
|
5684
5860
|
signer;
|
|
5685
5861
|
authManager;
|
|
@@ -5696,6 +5872,9 @@ class Openfort {
|
|
|
5696
5872
|
this.openfortEventEmitter = new TypedEventEmitter();
|
|
5697
5873
|
this.iframeManager = new IframeManager(this.config);
|
|
5698
5874
|
}
|
|
5875
|
+
/**
|
|
5876
|
+
* Logs the user out by flushing the signer and removing credentials.
|
|
5877
|
+
*/
|
|
5699
5878
|
async logout() {
|
|
5700
5879
|
await this.flushSigner();
|
|
5701
5880
|
if (this.credentialsProvided()) {
|
|
@@ -5725,11 +5904,16 @@ class Openfort {
|
|
|
5725
5904
|
this.instanceManager.removeJWK();
|
|
5726
5905
|
}
|
|
5727
5906
|
}
|
|
5728
|
-
|
|
5729
|
-
|
|
5730
|
-
|
|
5907
|
+
/**
|
|
5908
|
+
* Returns an Ethereum provider using the configured signer.
|
|
5909
|
+
*
|
|
5910
|
+
* @param options - Configuration options for the Ethereum provider.
|
|
5911
|
+
* @returns A Provider instance.
|
|
5912
|
+
* @throws {OpenfortError} If the signer is not an EmbeddedSigner.
|
|
5913
|
+
*/
|
|
5914
|
+
getEthereumProvider(options = { announceProvider: true }) {
|
|
5731
5915
|
if (!(this.signer instanceof EmbeddedSigner)) {
|
|
5732
|
-
throw new
|
|
5916
|
+
throw new OpenfortError('Embedded signer must be configured to get Ethereum provider', OpenfortErrorType.NOT_LOGGED_IN_ERROR);
|
|
5733
5917
|
}
|
|
5734
5918
|
const address = this.instanceManager.getAccountAddress();
|
|
5735
5919
|
const provider = new EvmProvider({
|
|
@@ -5748,32 +5932,11 @@ class Openfort {
|
|
|
5748
5932
|
}
|
|
5749
5933
|
return provider;
|
|
5750
5934
|
}
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
|
|
5756
|
-
}
|
|
5757
|
-
const signerType = this.instanceManager.getSignerType();
|
|
5758
|
-
switch (signerType) {
|
|
5759
|
-
case SignerType.EMBEDDED: {
|
|
5760
|
-
const iframeConfiguration = {
|
|
5761
|
-
accessToken: this.instanceManager.getAccessToken()?.token ?? null,
|
|
5762
|
-
thirdPartyProvider: this.instanceManager.getAccessToken()?.thirdPartyProvider ?? null,
|
|
5763
|
-
thirdPartyTokenType: this.instanceManager.getAccessToken()?.thirdPartyTokenType ?? null,
|
|
5764
|
-
chainId: null,
|
|
5765
|
-
recovery: null,
|
|
5766
|
-
};
|
|
5767
|
-
const embeddedSigner = new EmbeddedSigner(this.iframeManager, this.instanceManager, iframeConfiguration);
|
|
5768
|
-
await embeddedSigner.logout();
|
|
5769
|
-
break;
|
|
5770
|
-
}
|
|
5771
|
-
case SignerType.SESSION:
|
|
5772
|
-
this.configureSessionKey();
|
|
5773
|
-
break;
|
|
5774
|
-
}
|
|
5775
|
-
this.instanceManager.removeSignerType();
|
|
5776
|
-
}
|
|
5935
|
+
/**
|
|
5936
|
+
* Configures a session key and returns the session key details.
|
|
5937
|
+
*
|
|
5938
|
+
* @returns A SessionKey object containing the address and registration status.
|
|
5939
|
+
*/
|
|
5777
5940
|
configureSessionKey() {
|
|
5778
5941
|
const signer = new SessionSigner(this.instanceManager);
|
|
5779
5942
|
this.signer = signer;
|
|
@@ -5785,6 +5948,13 @@ class Openfort {
|
|
|
5785
5948
|
this.instanceManager.setSignerType(SignerType.SESSION);
|
|
5786
5949
|
return { address: publicKey, isRegistered: true };
|
|
5787
5950
|
}
|
|
5951
|
+
/**
|
|
5952
|
+
* Configures an embedded signer.
|
|
5953
|
+
*
|
|
5954
|
+
* @param chainId - The chain ID for the embedded signer.
|
|
5955
|
+
* @param shieldAuthentication - Shield authentication details.
|
|
5956
|
+
* @param recoveryPassword - Recovery password.
|
|
5957
|
+
*/
|
|
5788
5958
|
async configureEmbeddedSigner(chainId, shieldAuthentication, recoveryPassword) {
|
|
5789
5959
|
const signer = this.newEmbeddedSigner(chainId, shieldAuthentication);
|
|
5790
5960
|
await this.validateAndRefreshToken();
|
|
@@ -5792,20 +5962,14 @@ class Openfort {
|
|
|
5792
5962
|
this.signer = signer;
|
|
5793
5963
|
this.instanceManager.setSignerType(SignerType.EMBEDDED);
|
|
5794
5964
|
}
|
|
5795
|
-
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
chainId: chainId ?? null,
|
|
5804
|
-
recovery: shieldAuthentication ?? null,
|
|
5805
|
-
};
|
|
5806
|
-
return new EmbeddedSigner(this.iframeManager, this.instanceManager, iframeConfiguration);
|
|
5807
|
-
}
|
|
5808
|
-
async loginWithEmailPassword(email, password) {
|
|
5965
|
+
/**
|
|
5966
|
+
* Logs in a user with email and password.
|
|
5967
|
+
*
|
|
5968
|
+
* @param email - User's email.
|
|
5969
|
+
* @param password - User's password.
|
|
5970
|
+
* @returns An AuthResponse object containing authentication details.
|
|
5971
|
+
*/
|
|
5972
|
+
async loginWithEmailPassword({ email, password }) {
|
|
5809
5973
|
this.instanceManager.removeAccessToken();
|
|
5810
5974
|
this.instanceManager.removeRefreshToken();
|
|
5811
5975
|
this.instanceManager.removePlayerID();
|
|
@@ -5817,11 +5981,19 @@ class Openfort {
|
|
|
5817
5981
|
});
|
|
5818
5982
|
return result;
|
|
5819
5983
|
}
|
|
5820
|
-
|
|
5984
|
+
/**
|
|
5985
|
+
* Signs up a new user with email and password.
|
|
5986
|
+
*
|
|
5987
|
+
* @param email - User's email.
|
|
5988
|
+
* @param password - User's password.
|
|
5989
|
+
* @param options - Additional options for the sign-up process.
|
|
5990
|
+
* @returns An AuthResponse object containing authentication details.
|
|
5991
|
+
*/
|
|
5992
|
+
async signUpWithEmailPassword({ email, password, options }) {
|
|
5821
5993
|
this.instanceManager.removeAccessToken();
|
|
5822
5994
|
this.instanceManager.removeRefreshToken();
|
|
5823
5995
|
this.instanceManager.removePlayerID();
|
|
5824
|
-
const result = await this.authManager.signupEmailPassword(email, password, name);
|
|
5996
|
+
const result = await this.authManager.signupEmailPassword(email, password, options?.data.name);
|
|
5825
5997
|
this.storeCredentials({
|
|
5826
5998
|
player: result.player.id,
|
|
5827
5999
|
accessToken: result.token,
|
|
@@ -5829,45 +6001,117 @@ class Openfort {
|
|
|
5829
6001
|
});
|
|
5830
6002
|
return result;
|
|
5831
6003
|
}
|
|
5832
|
-
|
|
6004
|
+
/**
|
|
6005
|
+
* Links an email and password to an existing account using an authentication token.
|
|
6006
|
+
*
|
|
6007
|
+
* @param email - User's email.
|
|
6008
|
+
* @param password - User's password.
|
|
6009
|
+
* @param authToken - Authentication token.
|
|
6010
|
+
* @returns An AuthPlayerResponse object.
|
|
6011
|
+
*/
|
|
6012
|
+
async linkEmailPassword({ email, password, authToken }) {
|
|
6013
|
+
const result = await this.authManager.linkEmail(email, password, authToken);
|
|
6014
|
+
return result;
|
|
6015
|
+
}
|
|
6016
|
+
/**
|
|
6017
|
+
* Unlinks an email and password from an existing account using an authentication token.
|
|
6018
|
+
*
|
|
6019
|
+
* @param email - User's email.
|
|
6020
|
+
* @param authToken - Authentication token.
|
|
6021
|
+
* @returns An AuthPlayerResponse object.
|
|
6022
|
+
*/
|
|
6023
|
+
async unlinkEmailPassword({ email, authToken }) {
|
|
6024
|
+
const result = await this.authManager.unlinkEmail(email, authToken);
|
|
6025
|
+
return result;
|
|
6026
|
+
}
|
|
6027
|
+
/**
|
|
6028
|
+
* Requests an email verification link.
|
|
6029
|
+
*
|
|
6030
|
+
* @param email - User's email.
|
|
6031
|
+
* @param redirectUrl - Redirect URL after verification.
|
|
6032
|
+
*/
|
|
6033
|
+
async requestEmailVerification({ email, redirectUrl }) {
|
|
5833
6034
|
await this.authManager.requestEmailVerification(email, redirectUrl);
|
|
5834
6035
|
}
|
|
5835
|
-
|
|
6036
|
+
/**
|
|
6037
|
+
* Resets the user's password.
|
|
6038
|
+
*
|
|
6039
|
+
* @param email - User's email.
|
|
6040
|
+
* @param password - New password.
|
|
6041
|
+
* @param state - Verification state.
|
|
6042
|
+
*/
|
|
6043
|
+
async resetPassword({ email, password, state }) {
|
|
5836
6044
|
await this.authManager.resetPassword(email, password, state);
|
|
5837
6045
|
}
|
|
5838
|
-
|
|
6046
|
+
/**
|
|
6047
|
+
* Requests a password reset link.
|
|
6048
|
+
*
|
|
6049
|
+
* @param email - User's email.
|
|
6050
|
+
* @param redirectUrl - Redirect URL after resetting password.
|
|
6051
|
+
*/
|
|
6052
|
+
async requestResetPassword({ email, redirectUrl }) {
|
|
5839
6053
|
await this.authManager.requestResetPassword(email, redirectUrl);
|
|
5840
6054
|
}
|
|
5841
|
-
|
|
6055
|
+
/**
|
|
6056
|
+
* Verifies the user's email.
|
|
6057
|
+
*
|
|
6058
|
+
* @param email - User's email.
|
|
6059
|
+
* @param state - Verification state.
|
|
6060
|
+
*/
|
|
6061
|
+
async verifyEmail({ email, state }) {
|
|
5842
6062
|
await this.authManager.verifyEmail(email, state);
|
|
5843
6063
|
}
|
|
5844
|
-
|
|
5845
|
-
|
|
6064
|
+
/**
|
|
6065
|
+
* Initializes an OAuth authentication process.
|
|
6066
|
+
*
|
|
6067
|
+
* @param provider - OAuth provider.
|
|
6068
|
+
* @param options - Additional options for initialization.
|
|
6069
|
+
* @returns An InitAuthResponse object.
|
|
6070
|
+
*/
|
|
6071
|
+
async initOAuth({ provider, options }) {
|
|
6072
|
+
const authResponse = await this.authManager.initOAuth(provider, options);
|
|
5846
6073
|
return authResponse;
|
|
5847
6074
|
}
|
|
5848
|
-
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
|
|
5852
|
-
|
|
6075
|
+
/**
|
|
6076
|
+
* Initializes an OAuth linking process.
|
|
6077
|
+
*
|
|
6078
|
+
* @param provider - OAuth provider.
|
|
6079
|
+
* @param authToken - Authentication token.
|
|
6080
|
+
* @param options - Additional options for initialization.
|
|
6081
|
+
* @returns An InitAuthResponse object.
|
|
6082
|
+
*/
|
|
6083
|
+
async initLinkOAuth({ provider, authToken, options }) {
|
|
6084
|
+
return await this.authManager.linkOAuth(provider, authToken, options);
|
|
5853
6085
|
}
|
|
5854
|
-
|
|
5855
|
-
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
refreshToken: result.refreshToken,
|
|
5864
|
-
});
|
|
6086
|
+
/**
|
|
6087
|
+
* Unlinks an OAuth provider from the account.
|
|
6088
|
+
*
|
|
6089
|
+
* @param provider - OAuth provider.
|
|
6090
|
+
* @param authToken - Authentication token.
|
|
6091
|
+
* @returns An AuthPlayerResponse object.
|
|
6092
|
+
*/
|
|
6093
|
+
async unlinkOAuth({ provider, authToken }) {
|
|
6094
|
+
const result = await this.authManager.unlinkOAuth(provider, authToken);
|
|
5865
6095
|
return result;
|
|
5866
6096
|
}
|
|
5867
|
-
|
|
5868
|
-
|
|
6097
|
+
/**
|
|
6098
|
+
* Polls for OAuth authentication completion.
|
|
6099
|
+
*
|
|
6100
|
+
* @param key - OAuth polling key.
|
|
6101
|
+
* @returns An AuthResponse object.
|
|
6102
|
+
*/
|
|
6103
|
+
async poolOAuth(key) {
|
|
6104
|
+
return await this.authManager.poolOAuth(key);
|
|
5869
6105
|
}
|
|
5870
|
-
|
|
6106
|
+
/**
|
|
6107
|
+
* Authenticates using a third-party OAuth provider.
|
|
6108
|
+
*
|
|
6109
|
+
* @param provider - Third-party OAuth provider.
|
|
6110
|
+
* @param token - OAuth token.
|
|
6111
|
+
* @param tokenType - Type of the OAuth token.
|
|
6112
|
+
* @returns An AuthPlayerResponse object.
|
|
6113
|
+
*/
|
|
6114
|
+
async authenticateWithThirdPartyProvider({ provider, token, tokenType }) {
|
|
5871
6115
|
const result = await this.authManager.authenticateThirdParty(provider, token, tokenType);
|
|
5872
6116
|
this.instanceManager.setAccessToken({
|
|
5873
6117
|
token,
|
|
@@ -5880,7 +6124,25 @@ class Openfort {
|
|
|
5880
6124
|
}
|
|
5881
6125
|
return result;
|
|
5882
6126
|
}
|
|
5883
|
-
|
|
6127
|
+
/**
|
|
6128
|
+
* Initializes Sign-In with Ethereum (SIWE).
|
|
6129
|
+
*
|
|
6130
|
+
* @param address - Ethereum address.
|
|
6131
|
+
* @returns A SIWEInitResponse object.
|
|
6132
|
+
*/
|
|
6133
|
+
async initSIWE({ address }) {
|
|
6134
|
+
return await this.authManager.initSIWE(address);
|
|
6135
|
+
}
|
|
6136
|
+
/**
|
|
6137
|
+
* Authenticates using Sign-In with Ethereum (SIWE).
|
|
6138
|
+
*
|
|
6139
|
+
* @param signature - SIWE signature.
|
|
6140
|
+
* @param message - SIWE message.
|
|
6141
|
+
* @param walletClientType - Wallet client type.
|
|
6142
|
+
* @param connectorType - Connector type.
|
|
6143
|
+
* @returns An AuthResponse object.
|
|
6144
|
+
*/
|
|
6145
|
+
async authenticateWithSIWE({ signature, message, walletClientType, connectorType, }) {
|
|
5884
6146
|
this.instanceManager.removeAccessToken();
|
|
5885
6147
|
this.instanceManager.removeRefreshToken();
|
|
5886
6148
|
this.instanceManager.removePlayerID();
|
|
@@ -5892,6 +6154,36 @@ class Openfort {
|
|
|
5892
6154
|
});
|
|
5893
6155
|
return result;
|
|
5894
6156
|
}
|
|
6157
|
+
/**
|
|
6158
|
+
* Links a wallet using SIWE.
|
|
6159
|
+
*
|
|
6160
|
+
* @param signature - SIWE signature.
|
|
6161
|
+
* @param message - SIWE message.
|
|
6162
|
+
* @param walletClientType - Wallet client type.
|
|
6163
|
+
* @param connectorType - Connector type.
|
|
6164
|
+
* @param authToken - Authentication token.
|
|
6165
|
+
* @returns An AuthPlayerResponse object.
|
|
6166
|
+
*/
|
|
6167
|
+
async linkWallet({ signature, message, walletClientType, connectorType, authToken, }) {
|
|
6168
|
+
const result = await this.authManager.linkWallet(signature, message, walletClientType, connectorType, authToken);
|
|
6169
|
+
return result;
|
|
6170
|
+
}
|
|
6171
|
+
/**
|
|
6172
|
+
* Unlinks a wallet.
|
|
6173
|
+
*
|
|
6174
|
+
* @param address - Wallet address.
|
|
6175
|
+
* @param authToken - Authentication token.
|
|
6176
|
+
* @returns An AuthPlayerResponse object.
|
|
6177
|
+
*/
|
|
6178
|
+
async unlinkWallet({ address, authToken }) {
|
|
6179
|
+
const result = await this.authManager.unlinkWallet(address, authToken);
|
|
6180
|
+
return result;
|
|
6181
|
+
}
|
|
6182
|
+
/**
|
|
6183
|
+
* Stores authentication credentials.
|
|
6184
|
+
*
|
|
6185
|
+
* @param auth - Authentication details.
|
|
6186
|
+
*/
|
|
5895
6187
|
storeCredentials(auth) {
|
|
5896
6188
|
this.instanceManager.setAccessToken({
|
|
5897
6189
|
token: auth.accessToken,
|
|
@@ -5901,15 +6193,24 @@ class Openfort {
|
|
|
5901
6193
|
this.instanceManager.setRefreshToken(auth.refreshToken);
|
|
5902
6194
|
this.instanceManager.setPlayerID(auth.player);
|
|
5903
6195
|
}
|
|
6196
|
+
/**
|
|
6197
|
+
* Sends a signature transaction intent request.
|
|
6198
|
+
*
|
|
6199
|
+
* @param transactionIntentId - Transaction intent ID.
|
|
6200
|
+
* @param userOperationHash - User operation hash.
|
|
6201
|
+
* @param signature - Transaction signature.
|
|
6202
|
+
* @returns A TransactionIntentResponse object.
|
|
6203
|
+
* @throws {OpenfortError} If no userOperationHash or signature is provided.
|
|
6204
|
+
*/
|
|
5904
6205
|
async sendSignatureTransactionIntentRequest(transactionIntentId, userOperationHash = null, signature = null) {
|
|
5905
6206
|
let newSignature = signature;
|
|
5906
6207
|
if (!newSignature) {
|
|
5907
6208
|
if (!userOperationHash) {
|
|
5908
|
-
throw new
|
|
6209
|
+
throw new OpenfortError('No userOperationHash or signature provided', OpenfortErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
5909
6210
|
}
|
|
5910
6211
|
await this.recoverSigner();
|
|
5911
6212
|
if (!this.signer) {
|
|
5912
|
-
throw new
|
|
6213
|
+
throw new OpenfortError('In order to sign a transaction intent, a signer must be configured', OpenfortErrorType.MISSING_SIGNER_ERROR);
|
|
5913
6214
|
}
|
|
5914
6215
|
if (this.signer.useCredentials()) {
|
|
5915
6216
|
await this.validateAndRefreshToken();
|
|
@@ -5925,10 +6226,18 @@ class Openfort {
|
|
|
5925
6226
|
const result = await this.backendApiClients.transactionIntentsApi.signature(request);
|
|
5926
6227
|
return result.data;
|
|
5927
6228
|
}
|
|
6229
|
+
/**
|
|
6230
|
+
* Signs a message.
|
|
6231
|
+
*
|
|
6232
|
+
* @param message - Message to sign.
|
|
6233
|
+
* @param options - Additional options for signing.
|
|
6234
|
+
* @returns The signature.
|
|
6235
|
+
* @throws {OpenfortError} If no signer is configured.
|
|
6236
|
+
*/
|
|
5928
6237
|
async signMessage(message, options) {
|
|
5929
6238
|
await this.recoverSigner();
|
|
5930
6239
|
if (!this.signer) {
|
|
5931
|
-
throw new
|
|
6240
|
+
throw new OpenfortError('In order to sign a message, an embedded signer must be configured', OpenfortErrorType.MISSING_EMBEDDED_SIGNER_ERROR);
|
|
5932
6241
|
}
|
|
5933
6242
|
if (this.signer.useCredentials()) {
|
|
5934
6243
|
await this.validateAndRefreshToken();
|
|
@@ -5936,10 +6245,19 @@ class Openfort {
|
|
|
5936
6245
|
const { hashMessage = true, arrayifyMessage = false } = options || {};
|
|
5937
6246
|
return await this.signer.sign(message, arrayifyMessage, hashMessage);
|
|
5938
6247
|
}
|
|
6248
|
+
/**
|
|
6249
|
+
* Signs typed data.
|
|
6250
|
+
*
|
|
6251
|
+
* @param domain - EIP-712 domain.
|
|
6252
|
+
* @param types - Typed data types.
|
|
6253
|
+
* @param value - Typed data value.
|
|
6254
|
+
* @returns The signature.
|
|
6255
|
+
* @throws {OpenfortError} If no signer is configured.
|
|
6256
|
+
*/
|
|
5939
6257
|
async signTypedData(domain, types, value) {
|
|
5940
6258
|
await this.recoverSigner();
|
|
5941
6259
|
if (!this.signer) {
|
|
5942
|
-
throw new
|
|
6260
|
+
throw new OpenfortError('In order to sign a message, an embedded signer must be configured', OpenfortErrorType.MISSING_EMBEDDED_SIGNER_ERROR);
|
|
5943
6261
|
}
|
|
5944
6262
|
if (this.signer.useCredentials()) {
|
|
5945
6263
|
await this.validateAndRefreshToken();
|
|
@@ -5969,13 +6287,23 @@ class Openfort {
|
|
|
5969
6287
|
}
|
|
5970
6288
|
return await this.signer.sign(hash$1, false, false);
|
|
5971
6289
|
}
|
|
6290
|
+
/**
|
|
6291
|
+
* Sends a session registration request.
|
|
6292
|
+
*
|
|
6293
|
+
* @param sessionId - Session ID.
|
|
6294
|
+
* @param signature - Session signature.
|
|
6295
|
+
* @param optimistic - Whether the request is optimistic.
|
|
6296
|
+
* @returns A SessionResponse object.
|
|
6297
|
+
* @throws {OpenfortError} If no signer is configured.
|
|
6298
|
+
* @throws {OpenfortError} If the signer is not a SessionSigner.
|
|
6299
|
+
*/
|
|
5972
6300
|
async sendRegisterSessionRequest(sessionId, signature, optimistic) {
|
|
5973
6301
|
await this.recoverSigner();
|
|
5974
6302
|
if (!this.signer) {
|
|
5975
|
-
throw new
|
|
6303
|
+
throw new OpenfortError('No signer configured nor signature provided', OpenfortErrorType.MISSING_SIGNER_ERROR);
|
|
5976
6304
|
}
|
|
5977
6305
|
if (this.signer.getSingerType() !== SignerType.SESSION) {
|
|
5978
|
-
throw new
|
|
6306
|
+
throw new OpenfortError('Session signer must be configured to sign a session', OpenfortErrorType.MISSING_SESSION_SIGNER_ERROR);
|
|
5979
6307
|
}
|
|
5980
6308
|
const request = {
|
|
5981
6309
|
id: sessionId,
|
|
@@ -5987,6 +6315,75 @@ class Openfort {
|
|
|
5987
6315
|
const result = await this.backendApiClients.sessionsApi.signatureSession(request);
|
|
5988
6316
|
return result.data;
|
|
5989
6317
|
}
|
|
6318
|
+
/**
|
|
6319
|
+
* Gets the embedded state of the current session.
|
|
6320
|
+
*
|
|
6321
|
+
* @returns The embedded state.
|
|
6322
|
+
*/
|
|
6323
|
+
getEmbeddedState() {
|
|
6324
|
+
if (!this.credentialsProvided()) {
|
|
6325
|
+
return exports.EmbeddedState.UNAUTHENTICATED;
|
|
6326
|
+
}
|
|
6327
|
+
if (this.instanceManager.getSignerType() !== SignerType.EMBEDDED) {
|
|
6328
|
+
return exports.EmbeddedState.EMBEDDED_SIGNER_NOT_CONFIGURED;
|
|
6329
|
+
}
|
|
6330
|
+
if (!this.signer) {
|
|
6331
|
+
this.signer = this.newEmbeddedSigner();
|
|
6332
|
+
}
|
|
6333
|
+
if (!this.instanceManager.getDeviceID()) {
|
|
6334
|
+
return exports.EmbeddedState.CREATING_ACCOUNT;
|
|
6335
|
+
}
|
|
6336
|
+
return exports.EmbeddedState.READY;
|
|
6337
|
+
}
|
|
6338
|
+
/**
|
|
6339
|
+
* Gets the current access token.
|
|
6340
|
+
*
|
|
6341
|
+
* @returns The access token, or null if not available.
|
|
6342
|
+
*/
|
|
6343
|
+
getAccessToken() {
|
|
6344
|
+
return this.instanceManager.getAccessToken()?.token ?? null;
|
|
6345
|
+
}
|
|
6346
|
+
/**
|
|
6347
|
+
* Retrieves the user details.
|
|
6348
|
+
*
|
|
6349
|
+
* @returns An AuthPlayerResponse object.
|
|
6350
|
+
* @throws {OpenfortError} If no access token is found.
|
|
6351
|
+
*/
|
|
6352
|
+
async getUser() {
|
|
6353
|
+
await this.validateAndRefreshToken();
|
|
6354
|
+
const accessToken = this.instanceManager.getAccessToken();
|
|
6355
|
+
if (!accessToken) {
|
|
6356
|
+
throw new OpenfortError('No accessToken found', OpenfortErrorType.NOT_LOGGED_IN_ERROR);
|
|
6357
|
+
}
|
|
6358
|
+
return await this.authManager.getUser(accessToken.token);
|
|
6359
|
+
}
|
|
6360
|
+
/**
|
|
6361
|
+
* Validates and refreshes the access token if needed.
|
|
6362
|
+
*/
|
|
6363
|
+
async validateAndRefreshToken() {
|
|
6364
|
+
if (!this.credentialsProvided()) {
|
|
6365
|
+
return;
|
|
6366
|
+
}
|
|
6367
|
+
const accessToken = this.instanceManager.getAccessToken();
|
|
6368
|
+
const refreshToken = this.instanceManager.getRefreshToken();
|
|
6369
|
+
const jwk = await this.instanceManager.getJWK();
|
|
6370
|
+
if (!accessToken || !refreshToken || !jwk) {
|
|
6371
|
+
return;
|
|
6372
|
+
}
|
|
6373
|
+
const auth = await this.authManager.validateCredentials(accessToken.token, refreshToken, jwk);
|
|
6374
|
+
if (auth.accessToken !== accessToken.token) {
|
|
6375
|
+
this.storeCredentials(auth);
|
|
6376
|
+
}
|
|
6377
|
+
if (this.signer && this.signer.useCredentials()) {
|
|
6378
|
+
await this.signer.updateAuthentication();
|
|
6379
|
+
}
|
|
6380
|
+
}
|
|
6381
|
+
credentialsProvided() {
|
|
6382
|
+
const token = this.instanceManager.getAccessToken();
|
|
6383
|
+
const refreshToken = this.instanceManager.getRefreshToken();
|
|
6384
|
+
return token && ((token.token && token.thirdPartyProvider && token.thirdPartyTokenType)
|
|
6385
|
+
|| (token.token && refreshToken));
|
|
6386
|
+
}
|
|
5990
6387
|
async recoverSigner() {
|
|
5991
6388
|
if (this.signer) {
|
|
5992
6389
|
return;
|
|
@@ -6020,78 +6417,49 @@ class Openfort {
|
|
|
6020
6417
|
};
|
|
6021
6418
|
await checkSignerType(0);
|
|
6022
6419
|
}
|
|
6023
|
-
|
|
6024
|
-
if (!this.credentialsProvided()) {
|
|
6025
|
-
return exports.EmbeddedState.UNAUTHENTICATED;
|
|
6026
|
-
}
|
|
6027
|
-
if (this.instanceManager.getSignerType() !== SignerType.EMBEDDED) {
|
|
6028
|
-
return exports.EmbeddedState.EMBEDDED_SIGNER_NOT_CONFIGURED;
|
|
6029
|
-
}
|
|
6030
|
-
if (!this.signer) {
|
|
6031
|
-
this.signer = this.newEmbeddedSigner();
|
|
6032
|
-
}
|
|
6033
|
-
if (!this.instanceManager.getDeviceID()) {
|
|
6034
|
-
return exports.EmbeddedState.CREATING_ACCOUNT;
|
|
6035
|
-
}
|
|
6036
|
-
return exports.EmbeddedState.READY;
|
|
6037
|
-
}
|
|
6038
|
-
credentialsProvided() {
|
|
6039
|
-
const token = this.instanceManager.getAccessToken();
|
|
6040
|
-
const refreshToken = this.instanceManager.getRefreshToken();
|
|
6041
|
-
return (token
|
|
6042
|
-
&& ((token.token && token.thirdPartyProvider && token.thirdPartyTokenType)
|
|
6043
|
-
|| (token.token && refreshToken)));
|
|
6044
|
-
}
|
|
6045
|
-
async isAuthenticated() {
|
|
6420
|
+
newEmbeddedSigner(chainId, shieldAuthentication) {
|
|
6046
6421
|
if (!this.credentialsProvided()) {
|
|
6047
|
-
|
|
6422
|
+
throw new OpenfortError('Must be logged in to configure embedded signer', OpenfortErrorType.NOT_LOGGED_IN_ERROR);
|
|
6048
6423
|
}
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
if (this.signer.getSingerType() !== SignerType.EMBEDDED) {
|
|
6058
|
-
return false;
|
|
6059
|
-
}
|
|
6060
|
-
return await this.signer.isLoaded();
|
|
6061
|
-
}
|
|
6062
|
-
getAccessToken() {
|
|
6063
|
-
return this.instanceManager.getAccessToken()?.token ?? null;
|
|
6064
|
-
}
|
|
6065
|
-
isLoaded() {
|
|
6066
|
-
if (!this.instanceManager.getJWK()) {
|
|
6067
|
-
return false;
|
|
6068
|
-
}
|
|
6069
|
-
if (this.signer && this.signer.getSingerType() === SignerType.EMBEDDED) {
|
|
6070
|
-
return this.signer.iFrameLoaded();
|
|
6071
|
-
}
|
|
6072
|
-
return true;
|
|
6424
|
+
const iframeConfiguration = {
|
|
6425
|
+
accessToken: this.instanceManager.getAccessToken()?.token ?? null,
|
|
6426
|
+
thirdPartyProvider: this.instanceManager.getAccessToken()?.thirdPartyProvider ?? null,
|
|
6427
|
+
thirdPartyTokenType: this.instanceManager.getAccessToken()?.thirdPartyTokenType ?? null,
|
|
6428
|
+
chainId: !chainId ? Number(this.instanceManager.getChainID()) ?? null : chainId,
|
|
6429
|
+
recovery: shieldAuthentication ?? null,
|
|
6430
|
+
};
|
|
6431
|
+
return new EmbeddedSigner(this.iframeManager, this.instanceManager, iframeConfiguration);
|
|
6073
6432
|
}
|
|
6074
|
-
async
|
|
6075
|
-
if (
|
|
6076
|
-
|
|
6077
|
-
|
|
6078
|
-
const accessToken = this.instanceManager.getAccessToken();
|
|
6079
|
-
const refreshToken = this.instanceManager.getRefreshToken();
|
|
6080
|
-
const jwk = await this.instanceManager.getJWK();
|
|
6081
|
-
if (!accessToken || !refreshToken || !jwk) {
|
|
6433
|
+
async flushSigner() {
|
|
6434
|
+
if (this.signer) {
|
|
6435
|
+
await this.signer.logout();
|
|
6436
|
+
this.instanceManager.removeSignerType();
|
|
6082
6437
|
return;
|
|
6083
6438
|
}
|
|
6084
|
-
const
|
|
6085
|
-
|
|
6086
|
-
|
|
6087
|
-
|
|
6088
|
-
|
|
6089
|
-
|
|
6439
|
+
const signerType = this.instanceManager.getSignerType();
|
|
6440
|
+
switch (signerType) {
|
|
6441
|
+
case SignerType.EMBEDDED: {
|
|
6442
|
+
const iframeConfiguration = {
|
|
6443
|
+
accessToken: this.instanceManager.getAccessToken()?.token ?? null,
|
|
6444
|
+
thirdPartyProvider: this.instanceManager.getAccessToken()?.thirdPartyProvider ?? null,
|
|
6445
|
+
thirdPartyTokenType: this.instanceManager.getAccessToken()?.thirdPartyTokenType ?? null,
|
|
6446
|
+
chainId: null,
|
|
6447
|
+
recovery: null,
|
|
6448
|
+
};
|
|
6449
|
+
const embeddedSigner = new EmbeddedSigner(this.iframeManager, this.instanceManager, iframeConfiguration);
|
|
6450
|
+
await embeddedSigner.logout();
|
|
6451
|
+
break;
|
|
6452
|
+
}
|
|
6453
|
+
case SignerType.SESSION:
|
|
6454
|
+
this.configureSessionKey();
|
|
6455
|
+
break;
|
|
6090
6456
|
}
|
|
6457
|
+
this.instanceManager.removeSignerType();
|
|
6091
6458
|
}
|
|
6092
6459
|
}
|
|
6093
6460
|
|
|
6094
6461
|
exports.OpenfortConfiguration = OpenfortConfiguration;
|
|
6462
|
+
exports.OpenfortError = OpenfortError;
|
|
6095
6463
|
exports.SDKConfiguration = SDKConfiguration;
|
|
6096
6464
|
exports.ShieldConfiguration = ShieldConfiguration;
|
|
6097
6465
|
exports.default = Openfort;
|