@openfort/openfort-js 0.7.14 → 0.7.16
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/dist/index.cjs +300 -272
- package/dist/index.d.ts +32 -13
- package/dist/index.js +290 -262
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3195,57 +3195,6 @@ var CodeChallengeMethodEnum;
|
|
|
3195
3195
|
CodeChallengeMethodEnum["S256"] = "S256";
|
|
3196
3196
|
})(CodeChallengeMethodEnum || (CodeChallengeMethodEnum = {}));
|
|
3197
3197
|
|
|
3198
|
-
var OpenfortErrorType;
|
|
3199
|
-
(function (OpenfortErrorType) {
|
|
3200
|
-
OpenfortErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
|
|
3201
|
-
OpenfortErrorType["INVALID_CONFIGURATION"] = "INVALID_CONFIGURATION";
|
|
3202
|
-
OpenfortErrorType["NOT_LOGGED_IN_ERROR"] = "NOT_LOGGED_IN_ERROR";
|
|
3203
|
-
OpenfortErrorType["REFRESH_TOKEN_ERROR"] = "REFRESH_TOKEN_ERROR";
|
|
3204
|
-
OpenfortErrorType["USER_REGISTRATION_ERROR"] = "USER_REGISTRATION_ERROR";
|
|
3205
|
-
OpenfortErrorType["LOGOUT_ERROR"] = "LOGOUT_ERROR";
|
|
3206
|
-
OpenfortErrorType["OPERATION_NOT_SUPPORTED_ERROR"] = "OPERATION_NOT_SUPPORTED_ERROR";
|
|
3207
|
-
OpenfortErrorType["MISSING_SESSION_SIGNER_ERROR"] = "MISSING_SESSION_SIGNER_ERROR";
|
|
3208
|
-
OpenfortErrorType["MISSING_EMBEDDED_SIGNER_ERROR"] = "MISSING_EMBEDDED_SIGNER_ERROR";
|
|
3209
|
-
OpenfortErrorType["MISSING_SIGNER_ERROR"] = "MISSING_SIGNER_ERROR";
|
|
3210
|
-
})(OpenfortErrorType || (OpenfortErrorType = {}));
|
|
3211
|
-
function isAPIError(error) {
|
|
3212
|
-
return 'type' in error && 'message' in error;
|
|
3213
|
-
}
|
|
3214
|
-
class OpenfortError extends Error {
|
|
3215
|
-
type;
|
|
3216
|
-
constructor(message, type) {
|
|
3217
|
-
super(message);
|
|
3218
|
-
this.type = type;
|
|
3219
|
-
}
|
|
3220
|
-
}
|
|
3221
|
-
const withOpenfortError = async (fn, customErrorType) => {
|
|
3222
|
-
try {
|
|
3223
|
-
return await fn();
|
|
3224
|
-
}
|
|
3225
|
-
catch (error) {
|
|
3226
|
-
let errorMessage;
|
|
3227
|
-
if (globalAxios.isAxiosError(error) && error.response?.data && isAPIError(error.response.data)) {
|
|
3228
|
-
errorMessage = error.response.data.message;
|
|
3229
|
-
}
|
|
3230
|
-
else {
|
|
3231
|
-
errorMessage = error.message;
|
|
3232
|
-
}
|
|
3233
|
-
throw new OpenfortError(errorMessage, customErrorType);
|
|
3234
|
-
}
|
|
3235
|
-
};
|
|
3236
|
-
|
|
3237
|
-
const validateConfiguration = (configuration, requiredKeys, prefix) => {
|
|
3238
|
-
const missingKeys = requiredKeys
|
|
3239
|
-
.map((key) => !configuration[key] && key)
|
|
3240
|
-
.filter((n) => n)
|
|
3241
|
-
.join(', ');
|
|
3242
|
-
if (missingKeys !== '') {
|
|
3243
|
-
const errorMessage = prefix
|
|
3244
|
-
? `${prefix} - ${missingKeys} cannot be null`
|
|
3245
|
-
: `${missingKeys} cannot be null`;
|
|
3246
|
-
throw new OpenfortError(errorMessage, OpenfortErrorType.INVALID_CONFIGURATION);
|
|
3247
|
-
}
|
|
3248
|
-
};
|
|
3249
3198
|
class OpenfortConfiguration {
|
|
3250
3199
|
publishableKey;
|
|
3251
3200
|
constructor(options) {
|
|
@@ -3273,17 +3222,12 @@ class SDKConfiguration {
|
|
|
3273
3222
|
this.shieldConfiguration = shieldConfiguration;
|
|
3274
3223
|
this.baseConfiguration = baseConfiguration;
|
|
3275
3224
|
if (overrides) {
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
'shieldUrl',
|
|
3280
|
-
], 'overrides');
|
|
3281
|
-
this.backendUrl = overrides.backendUrl;
|
|
3282
|
-
this.iframeUrl = overrides.iframeUrl;
|
|
3283
|
-
this.shieldUrl = overrides.shieldUrl;
|
|
3225
|
+
this.backendUrl = overrides.backendUrl || 'https://api.openfort.xyz';
|
|
3226
|
+
this.iframeUrl = overrides.iframeUrl || 'https://iframe.openfort.xyz';
|
|
3227
|
+
this.shieldUrl = overrides.shieldUrl || 'https://shield.openfort.xyz';
|
|
3284
3228
|
this.openfortAPIConfig = {
|
|
3285
3229
|
backend: createConfig({
|
|
3286
|
-
basePath: overrides.backendUrl,
|
|
3230
|
+
basePath: overrides.backendUrl || 'https://api.openfort.xyz',
|
|
3287
3231
|
accessToken: baseConfiguration.publishableKey,
|
|
3288
3232
|
}),
|
|
3289
3233
|
};
|
|
@@ -4742,6 +4686,69 @@ function announceProvider(detail) {
|
|
|
4742
4686
|
window.addEventListener('eip6963:requestProvider', handler);
|
|
4743
4687
|
}
|
|
4744
4688
|
|
|
4689
|
+
exports.OpenfortErrorType = void 0;
|
|
4690
|
+
(function (OpenfortErrorType) {
|
|
4691
|
+
OpenfortErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
|
|
4692
|
+
OpenfortErrorType["INVALID_CONFIGURATION"] = "INVALID_CONFIGURATION";
|
|
4693
|
+
OpenfortErrorType["NOT_LOGGED_IN_ERROR"] = "NOT_LOGGED_IN_ERROR";
|
|
4694
|
+
OpenfortErrorType["REFRESH_TOKEN_ERROR"] = "REFRESH_TOKEN_ERROR";
|
|
4695
|
+
OpenfortErrorType["USER_REGISTRATION_ERROR"] = "USER_REGISTRATION_ERROR";
|
|
4696
|
+
OpenfortErrorType["LOGOUT_ERROR"] = "LOGOUT_ERROR";
|
|
4697
|
+
OpenfortErrorType["OPERATION_NOT_SUPPORTED_ERROR"] = "OPERATION_NOT_SUPPORTED_ERROR";
|
|
4698
|
+
OpenfortErrorType["MISSING_SESSION_SIGNER_ERROR"] = "MISSING_SESSION_SIGNER_ERROR";
|
|
4699
|
+
OpenfortErrorType["MISSING_EMBEDDED_SIGNER_ERROR"] = "MISSING_EMBEDDED_SIGNER_ERROR";
|
|
4700
|
+
OpenfortErrorType["MISSING_SIGNER_ERROR"] = "MISSING_SIGNER_ERROR";
|
|
4701
|
+
OpenfortErrorType["USER_NOT_AUTHORIZED_ON_ECOSYSTEM"] = "USER_NOT_AUTHORIZED_ON_ECOSYSTEM";
|
|
4702
|
+
})(exports.OpenfortErrorType || (exports.OpenfortErrorType = {}));
|
|
4703
|
+
function isAPIError(error) {
|
|
4704
|
+
return 'type' in error && 'message' in error;
|
|
4705
|
+
}
|
|
4706
|
+
class OpenfortError extends Error {
|
|
4707
|
+
type;
|
|
4708
|
+
data;
|
|
4709
|
+
constructor(message, type, data = {}) {
|
|
4710
|
+
super(message);
|
|
4711
|
+
this.type = type;
|
|
4712
|
+
this.data = data;
|
|
4713
|
+
}
|
|
4714
|
+
}
|
|
4715
|
+
const withOpenfortError = async (fn, customErrorType) => {
|
|
4716
|
+
try {
|
|
4717
|
+
return await fn();
|
|
4718
|
+
}
|
|
4719
|
+
catch (error) {
|
|
4720
|
+
let errorMessage;
|
|
4721
|
+
const data = {};
|
|
4722
|
+
let errorType = customErrorType.default;
|
|
4723
|
+
if (globalAxios.isAxiosError(error)) {
|
|
4724
|
+
const statusCode = error.response?.status;
|
|
4725
|
+
errorType = statusCode ? customErrorType[statusCode] || customErrorType.default : customErrorType.default;
|
|
4726
|
+
if (error.response?.data && error.response.data.error) {
|
|
4727
|
+
const jsonData = JSON.parse(JSON.stringify(error.response.data.error));
|
|
4728
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
4729
|
+
for (const key in jsonData) {
|
|
4730
|
+
if (key !== 'message' && key !== 'type') {
|
|
4731
|
+
data[key] = jsonData[key];
|
|
4732
|
+
}
|
|
4733
|
+
}
|
|
4734
|
+
if (isAPIError(error.response.data)) {
|
|
4735
|
+
errorMessage = error.response.data.message;
|
|
4736
|
+
}
|
|
4737
|
+
else {
|
|
4738
|
+
errorMessage = error.message;
|
|
4739
|
+
}
|
|
4740
|
+
}
|
|
4741
|
+
else {
|
|
4742
|
+
errorMessage = error.message;
|
|
4743
|
+
}
|
|
4744
|
+
}
|
|
4745
|
+
else {
|
|
4746
|
+
errorMessage = error.message;
|
|
4747
|
+
}
|
|
4748
|
+
throw new OpenfortError(errorMessage, errorType, data);
|
|
4749
|
+
}
|
|
4750
|
+
};
|
|
4751
|
+
|
|
4745
4752
|
var SignerType;
|
|
4746
4753
|
(function (SignerType) {
|
|
4747
4754
|
SignerType["EMBEDDED"] = "embedded";
|
|
@@ -4787,7 +4794,7 @@ class AuthManager {
|
|
|
4787
4794
|
this.backendApiClients = backendApiClients;
|
|
4788
4795
|
this.instanceManager = instanceManager;
|
|
4789
4796
|
}
|
|
4790
|
-
async initOAuth(provider, options) {
|
|
4797
|
+
async initOAuth(provider, options, ecosystemGame) {
|
|
4791
4798
|
const usePooling = options?.usePooling ?? false;
|
|
4792
4799
|
// eslint-disable-next-line no-param-reassign
|
|
4793
4800
|
delete options?.usePooling;
|
|
@@ -4798,7 +4805,7 @@ class AuthManager {
|
|
|
4798
4805
|
usePooling,
|
|
4799
4806
|
},
|
|
4800
4807
|
};
|
|
4801
|
-
const result = await this.backendApiClients.authenticationApi.initOAuth(request);
|
|
4808
|
+
const result = await this.backendApiClients.authenticationApi.initOAuth(request, AuthManager.getEcosystemGameOptsOrUndefined(ecosystemGame));
|
|
4802
4809
|
if (isBrowser() && options?.skipBrowserRedirect) {
|
|
4803
4810
|
window.location.assign(result.data.url);
|
|
4804
4811
|
}
|
|
@@ -4839,7 +4846,7 @@ class AuthManager {
|
|
|
4839
4846
|
}
|
|
4840
4847
|
throw new Error('Failed to pool OAuth, try again later');
|
|
4841
4848
|
}
|
|
4842
|
-
async authenticateThirdParty(provider, token, tokenType) {
|
|
4849
|
+
async authenticateThirdParty(provider, token, tokenType, ecosystemGame) {
|
|
4843
4850
|
const request = {
|
|
4844
4851
|
thirdPartyOAuthRequest: {
|
|
4845
4852
|
provider,
|
|
@@ -4848,17 +4855,17 @@ class AuthManager {
|
|
|
4848
4855
|
},
|
|
4849
4856
|
};
|
|
4850
4857
|
return withOpenfortError(async () => {
|
|
4851
|
-
const response = await this.backendApiClients.authenticationApi.thirdParty(request);
|
|
4858
|
+
const response = await this.backendApiClients.authenticationApi.thirdParty(request, AuthManager.getEcosystemGameOptsOrUndefined(ecosystemGame));
|
|
4852
4859
|
return response.data;
|
|
4853
|
-
}, OpenfortErrorType.AUTHENTICATION_ERROR);
|
|
4860
|
+
}, { default: exports.OpenfortErrorType.AUTHENTICATION_ERROR });
|
|
4854
4861
|
}
|
|
4855
|
-
async initSIWE(address) {
|
|
4862
|
+
async initSIWE(address, ecosystemGame) {
|
|
4856
4863
|
const request = {
|
|
4857
4864
|
sIWERequest: {
|
|
4858
4865
|
address,
|
|
4859
4866
|
},
|
|
4860
4867
|
};
|
|
4861
|
-
const result = await this.backendApiClients.authenticationApi.initSIWE(request);
|
|
4868
|
+
const result = await this.backendApiClients.authenticationApi.initSIWE(request, AuthManager.getEcosystemGameOptsOrUndefined(ecosystemGame));
|
|
4862
4869
|
return {
|
|
4863
4870
|
address: result.data.address,
|
|
4864
4871
|
nonce: result.data.nonce,
|
|
@@ -4877,9 +4884,20 @@ class AuthManager {
|
|
|
4877
4884
|
return withOpenfortError(async () => {
|
|
4878
4885
|
const response = await this.backendApiClients.authenticationApi.authenticateSIWE(request);
|
|
4879
4886
|
return response.data;
|
|
4880
|
-
}, OpenfortErrorType.AUTHENTICATION_ERROR);
|
|
4887
|
+
}, { default: exports.OpenfortErrorType.AUTHENTICATION_ERROR });
|
|
4888
|
+
}
|
|
4889
|
+
static getEcosystemGameOptsOrUndefined(ecosystemGame) {
|
|
4890
|
+
if (ecosystemGame) {
|
|
4891
|
+
return {
|
|
4892
|
+
headers: {
|
|
4893
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
4894
|
+
'x-game': ecosystemGame,
|
|
4895
|
+
},
|
|
4896
|
+
};
|
|
4897
|
+
}
|
|
4898
|
+
return undefined;
|
|
4881
4899
|
}
|
|
4882
|
-
async loginEmailPassword(email, password) {
|
|
4900
|
+
async loginEmailPassword(email, password, ecosystemGame) {
|
|
4883
4901
|
const request = {
|
|
4884
4902
|
loginRequest: {
|
|
4885
4903
|
email,
|
|
@@ -4887,9 +4905,10 @@ class AuthManager {
|
|
|
4887
4905
|
},
|
|
4888
4906
|
};
|
|
4889
4907
|
return withOpenfortError(async () => {
|
|
4890
|
-
const response = await this.backendApiClients.authenticationApi.loginEmailPassword(request);
|
|
4908
|
+
const response = await this.backendApiClients.authenticationApi.loginEmailPassword(request, AuthManager.getEcosystemGameOptsOrUndefined(ecosystemGame));
|
|
4891
4909
|
return response.data;
|
|
4892
|
-
|
|
4910
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
4911
|
+
}, { default: exports.OpenfortErrorType.AUTHENTICATION_ERROR, 403: exports.OpenfortErrorType.USER_NOT_AUTHORIZED_ON_ECOSYSTEM });
|
|
4893
4912
|
}
|
|
4894
4913
|
async requestResetPassword(email, redirectUrl) {
|
|
4895
4914
|
const verifier = base64URLEncode(crypto__namespace.randomBytes(32));
|
|
@@ -4926,7 +4945,7 @@ class AuthManager {
|
|
|
4926
4945
|
},
|
|
4927
4946
|
};
|
|
4928
4947
|
await this.backendApiClients.authenticationApi.resetPassword(request);
|
|
4929
|
-
}, OpenfortErrorType.AUTHENTICATION_ERROR);
|
|
4948
|
+
}, { default: exports.OpenfortErrorType.AUTHENTICATION_ERROR });
|
|
4930
4949
|
}
|
|
4931
4950
|
async requestEmailVerification(email, redirectUrl) {
|
|
4932
4951
|
const verifier = base64URLEncode(crypto__namespace.randomBytes(32));
|
|
@@ -4962,9 +4981,9 @@ class AuthManager {
|
|
|
4962
4981
|
},
|
|
4963
4982
|
};
|
|
4964
4983
|
await this.backendApiClients.authenticationApi.verifyEmail(request);
|
|
4965
|
-
}, OpenfortErrorType.AUTHENTICATION_ERROR);
|
|
4984
|
+
}, { default: exports.OpenfortErrorType.AUTHENTICATION_ERROR });
|
|
4966
4985
|
}
|
|
4967
|
-
async signupEmailPassword(email, password, name) {
|
|
4986
|
+
async signupEmailPassword(email, password, name, ecosystemGame) {
|
|
4968
4987
|
const request = {
|
|
4969
4988
|
signupRequest: {
|
|
4970
4989
|
email,
|
|
@@ -4973,16 +4992,16 @@ class AuthManager {
|
|
|
4973
4992
|
},
|
|
4974
4993
|
};
|
|
4975
4994
|
return withOpenfortError(async () => {
|
|
4976
|
-
const response = await this.backendApiClients.authenticationApi.signupEmailPassword(request);
|
|
4995
|
+
const response = await this.backendApiClients.authenticationApi.signupEmailPassword(request, AuthManager.getEcosystemGameOptsOrUndefined(ecosystemGame));
|
|
4977
4996
|
return response.data;
|
|
4978
|
-
}, OpenfortErrorType.USER_REGISTRATION_ERROR);
|
|
4997
|
+
}, { default: exports.OpenfortErrorType.USER_REGISTRATION_ERROR });
|
|
4979
4998
|
}
|
|
4980
4999
|
async validateCredentials(forceRefresh) {
|
|
4981
5000
|
const jwk = await this.instanceManager.getJWK();
|
|
4982
5001
|
const accessToken = this.instanceManager.getAccessToken()?.token;
|
|
4983
5002
|
const refreshToken = this.instanceManager.getRefreshToken();
|
|
4984
5003
|
if (!accessToken || !refreshToken || !jwk) {
|
|
4985
|
-
throw new OpenfortError('Must be logged in to validate and refresh token', OpenfortErrorType.NOT_LOGGED_IN_ERROR);
|
|
5004
|
+
throw new OpenfortError('Must be logged in to validate and refresh token', exports.OpenfortErrorType.NOT_LOGGED_IN_ERROR);
|
|
4986
5005
|
}
|
|
4987
5006
|
if (forceRefresh) {
|
|
4988
5007
|
return this.refreshTokens(refreshToken, forceRefresh);
|
|
@@ -5022,7 +5041,7 @@ class AuthManager {
|
|
|
5022
5041
|
accessToken: response.data.token,
|
|
5023
5042
|
refreshToken: response.data.refreshToken,
|
|
5024
5043
|
};
|
|
5025
|
-
}, OpenfortErrorType.REFRESH_TOKEN_ERROR);
|
|
5044
|
+
}, { default: exports.OpenfortErrorType.REFRESH_TOKEN_ERROR });
|
|
5026
5045
|
}
|
|
5027
5046
|
async logout(accessToken, refreshToken) {
|
|
5028
5047
|
const request = {
|
|
@@ -5038,7 +5057,7 @@ class AuthManager {
|
|
|
5038
5057
|
'x-player-token': accessToken,
|
|
5039
5058
|
},
|
|
5040
5059
|
});
|
|
5041
|
-
}, OpenfortErrorType.LOGOUT_ERROR);
|
|
5060
|
+
}, { default: exports.OpenfortErrorType.LOGOUT_ERROR });
|
|
5042
5061
|
}
|
|
5043
5062
|
async getUser(accessToken) {
|
|
5044
5063
|
// TODO: Add storage of user info
|
|
@@ -5051,7 +5070,7 @@ class AuthManager {
|
|
|
5051
5070
|
});
|
|
5052
5071
|
return response.data;
|
|
5053
5072
|
}
|
|
5054
|
-
async linkOAuth(provider, playerToken, options) {
|
|
5073
|
+
async linkOAuth(provider, playerToken, options, ecosystemGame) {
|
|
5055
5074
|
const request = {
|
|
5056
5075
|
oAuthInitRequest: {
|
|
5057
5076
|
provider,
|
|
@@ -5064,6 +5083,8 @@ class AuthManager {
|
|
|
5064
5083
|
authorization: `Bearer ${this.config.baseConfiguration.publishableKey}`,
|
|
5065
5084
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
5066
5085
|
'x-player-token': playerToken,
|
|
5086
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
5087
|
+
'x-game': ecosystemGame || undefined,
|
|
5067
5088
|
},
|
|
5068
5089
|
});
|
|
5069
5090
|
if (isBrowser() && !options?.skipBrowserRedirect) {
|
|
@@ -5137,7 +5158,7 @@ class AuthManager {
|
|
|
5137
5158
|
});
|
|
5138
5159
|
return authPlayerResponse.data;
|
|
5139
5160
|
}
|
|
5140
|
-
async linkEmail(email, password, accessToken) {
|
|
5161
|
+
async linkEmail(email, password, accessToken, ecosystemGame) {
|
|
5141
5162
|
const request = {
|
|
5142
5163
|
loginRequest: {
|
|
5143
5164
|
email,
|
|
@@ -5149,12 +5170,161 @@ class AuthManager {
|
|
|
5149
5170
|
authorization: `Bearer ${this.config.baseConfiguration.publishableKey}`,
|
|
5150
5171
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
5151
5172
|
'x-player-token': accessToken,
|
|
5173
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
5174
|
+
'x-game': ecosystemGame || undefined,
|
|
5152
5175
|
},
|
|
5153
5176
|
});
|
|
5154
5177
|
return authPlayerResponse.data;
|
|
5155
5178
|
}
|
|
5156
5179
|
}
|
|
5157
5180
|
|
|
5181
|
+
var Event;
|
|
5182
|
+
(function (Event) {
|
|
5183
|
+
Event["LOADED"] = "loaded";
|
|
5184
|
+
Event["CONFIGURE"] = "configure";
|
|
5185
|
+
Event["CONFIGURED"] = "configured";
|
|
5186
|
+
Event["UPDATE_AUTHENTICATION"] = "update-authentication";
|
|
5187
|
+
Event["AUTHENTICATION_UPDATED"] = "authentication-updated";
|
|
5188
|
+
Event["SIGN"] = "sign";
|
|
5189
|
+
Event["SIGNED"] = "signed";
|
|
5190
|
+
Event["LOGOUT"] = "logout";
|
|
5191
|
+
Event["LOGGED_OUT"] = "logged-out";
|
|
5192
|
+
Event["GET_CURRENT_DEVICE"] = "get-current-device";
|
|
5193
|
+
Event["CURRENT_DEVICE"] = "current-device";
|
|
5194
|
+
Event["PING"] = "ping";
|
|
5195
|
+
Event["PONG"] = "pong";
|
|
5196
|
+
})(Event || (Event = {}));
|
|
5197
|
+
const NOT_CONFIGURED_ERROR = 'not-configured-error';
|
|
5198
|
+
const MISSING_USER_ENTROPY_ERROR = 'missing-user-entropy-error';
|
|
5199
|
+
const INCORRECT_USER_ENTROPY_ERROR = 'incorrect-user-entropy-error';
|
|
5200
|
+
class GetCurrentDeviceRequest {
|
|
5201
|
+
uuid;
|
|
5202
|
+
action = Event.GET_CURRENT_DEVICE;
|
|
5203
|
+
playerID;
|
|
5204
|
+
constructor(uuid, playerId) {
|
|
5205
|
+
this.uuid = uuid;
|
|
5206
|
+
this.playerID = playerId;
|
|
5207
|
+
}
|
|
5208
|
+
}
|
|
5209
|
+
class PingRequest {
|
|
5210
|
+
uuid;
|
|
5211
|
+
action = Event.PING;
|
|
5212
|
+
constructor(uuid) {
|
|
5213
|
+
this.uuid = uuid;
|
|
5214
|
+
}
|
|
5215
|
+
}
|
|
5216
|
+
class GetCurrentDeviceResponse {
|
|
5217
|
+
uuid;
|
|
5218
|
+
success;
|
|
5219
|
+
action = Event.CURRENT_DEVICE;
|
|
5220
|
+
deviceID;
|
|
5221
|
+
accountType;
|
|
5222
|
+
version = null;
|
|
5223
|
+
chainId;
|
|
5224
|
+
address;
|
|
5225
|
+
constructor(uuid, deviceID, accountType, chainId, address) {
|
|
5226
|
+
this.uuid = uuid;
|
|
5227
|
+
this.success = true;
|
|
5228
|
+
this.deviceID = deviceID;
|
|
5229
|
+
this.accountType = accountType;
|
|
5230
|
+
this.chainId = chainId;
|
|
5231
|
+
this.address = address;
|
|
5232
|
+
}
|
|
5233
|
+
}
|
|
5234
|
+
class LogoutRequest {
|
|
5235
|
+
uuid;
|
|
5236
|
+
action = Event.LOGOUT;
|
|
5237
|
+
constructor(uuid) {
|
|
5238
|
+
this.uuid = uuid;
|
|
5239
|
+
}
|
|
5240
|
+
}
|
|
5241
|
+
class SignRequest {
|
|
5242
|
+
uuid;
|
|
5243
|
+
action = Event.SIGN;
|
|
5244
|
+
message;
|
|
5245
|
+
requireArrayify;
|
|
5246
|
+
requireHash;
|
|
5247
|
+
requestConfiguration;
|
|
5248
|
+
constructor(uuid, message, requireArrayify, requireHash, requestConfiguration) {
|
|
5249
|
+
this.uuid = uuid;
|
|
5250
|
+
this.message = message;
|
|
5251
|
+
this.requireArrayify = requireArrayify;
|
|
5252
|
+
this.requireHash = requireHash;
|
|
5253
|
+
this.requestConfiguration = requestConfiguration;
|
|
5254
|
+
}
|
|
5255
|
+
}
|
|
5256
|
+
function isErrorResponse(response) {
|
|
5257
|
+
return 'error' in response;
|
|
5258
|
+
}
|
|
5259
|
+
class ConfigureResponse {
|
|
5260
|
+
uuid;
|
|
5261
|
+
success;
|
|
5262
|
+
deviceID;
|
|
5263
|
+
address;
|
|
5264
|
+
chainId;
|
|
5265
|
+
accountType;
|
|
5266
|
+
action = Event.CONFIGURED;
|
|
5267
|
+
version;
|
|
5268
|
+
constructor(uuid, deviceID, accountType, chainId, address) {
|
|
5269
|
+
this.success = true;
|
|
5270
|
+
this.deviceID = deviceID;
|
|
5271
|
+
this.uuid = uuid;
|
|
5272
|
+
this.accountType = accountType;
|
|
5273
|
+
this.chainId = chainId;
|
|
5274
|
+
this.address = address;
|
|
5275
|
+
this.version = null;
|
|
5276
|
+
}
|
|
5277
|
+
}
|
|
5278
|
+
class UpdateAuthenticationResponse {
|
|
5279
|
+
uuid;
|
|
5280
|
+
success;
|
|
5281
|
+
action = Event.AUTHENTICATION_UPDATED;
|
|
5282
|
+
version;
|
|
5283
|
+
constructor(uuid) {
|
|
5284
|
+
this.success = true;
|
|
5285
|
+
this.uuid = uuid;
|
|
5286
|
+
this.version = null;
|
|
5287
|
+
}
|
|
5288
|
+
}
|
|
5289
|
+
class SignResponse {
|
|
5290
|
+
uuid;
|
|
5291
|
+
success;
|
|
5292
|
+
signature;
|
|
5293
|
+
action = Event.SIGNED;
|
|
5294
|
+
version;
|
|
5295
|
+
constructor(uuid, signature) {
|
|
5296
|
+
this.success = true;
|
|
5297
|
+
this.signature = signature;
|
|
5298
|
+
this.uuid = uuid;
|
|
5299
|
+
this.version = null;
|
|
5300
|
+
}
|
|
5301
|
+
}
|
|
5302
|
+
class LogoutResponse {
|
|
5303
|
+
uuid;
|
|
5304
|
+
success;
|
|
5305
|
+
action = Event.LOGGED_OUT;
|
|
5306
|
+
constructor(uuid) {
|
|
5307
|
+
this.success = true;
|
|
5308
|
+
this.uuid = uuid;
|
|
5309
|
+
}
|
|
5310
|
+
}
|
|
5311
|
+
class UpdateAuthenticationRequest {
|
|
5312
|
+
uuid;
|
|
5313
|
+
action = Event.UPDATE_AUTHENTICATION;
|
|
5314
|
+
accessToken;
|
|
5315
|
+
recovery;
|
|
5316
|
+
constructor(uuid, accessToken, recovery) {
|
|
5317
|
+
this.uuid = uuid;
|
|
5318
|
+
this.accessToken = accessToken;
|
|
5319
|
+
this.recovery = recovery;
|
|
5320
|
+
}
|
|
5321
|
+
}
|
|
5322
|
+
exports.ShieldAuthType = void 0;
|
|
5323
|
+
(function (ShieldAuthType) {
|
|
5324
|
+
ShieldAuthType["OPENFORT"] = "openfort";
|
|
5325
|
+
ShieldAuthType["CUSTOM"] = "custom";
|
|
5326
|
+
})(exports.ShieldAuthType || (exports.ShieldAuthType = {}));
|
|
5327
|
+
|
|
5158
5328
|
const authTokenStorageKey = 'openfort.auth_token';
|
|
5159
5329
|
const thirdPartyProviderStorageKey = 'openfort.third_party_provider';
|
|
5160
5330
|
const thirdPartyProviderTokenTypeStorageKey = 'openfort.third_party_provider_token_type';
|
|
@@ -5404,6 +5574,11 @@ class InstanceManager {
|
|
|
5404
5574
|
getShieldAuthType() {
|
|
5405
5575
|
if (!this.accountType) {
|
|
5406
5576
|
this.accountType = this.persistentStorage.get(shieldAuthTypeStorageKey);
|
|
5577
|
+
if (this.accountType === null) {
|
|
5578
|
+
// TODO: remove, this is for backward compatibility
|
|
5579
|
+
this.setShieldAuthType(exports.ShieldAuthType.OPENFORT);
|
|
5580
|
+
this.accountType = exports.ShieldAuthType.OPENFORT;
|
|
5581
|
+
}
|
|
5407
5582
|
}
|
|
5408
5583
|
return this.accountType;
|
|
5409
5584
|
}
|
|
@@ -5554,7 +5729,8 @@ class EmbeddedSigner {
|
|
|
5554
5729
|
if (!accessToken) {
|
|
5555
5730
|
return;
|
|
5556
5731
|
}
|
|
5557
|
-
|
|
5732
|
+
const shieldAuthType = this.instanceManager.getShieldAuthType();
|
|
5733
|
+
await this.iframeManager.updateAuthentication(this.iframeConfiguration, accessToken.token, shieldAuthType);
|
|
5558
5734
|
}
|
|
5559
5735
|
// eslint-disable-next-line class-methods-use-this
|
|
5560
5736
|
getSingerType() {
|
|
@@ -5629,153 +5805,6 @@ class SessionStorage {
|
|
|
5629
5805
|
}
|
|
5630
5806
|
}
|
|
5631
5807
|
|
|
5632
|
-
var Event;
|
|
5633
|
-
(function (Event) {
|
|
5634
|
-
Event["LOADED"] = "loaded";
|
|
5635
|
-
Event["CONFIGURE"] = "configure";
|
|
5636
|
-
Event["CONFIGURED"] = "configured";
|
|
5637
|
-
Event["UPDATE_AUTHENTICATION"] = "update-authentication";
|
|
5638
|
-
Event["AUTHENTICATION_UPDATED"] = "authentication-updated";
|
|
5639
|
-
Event["SIGN"] = "sign";
|
|
5640
|
-
Event["SIGNED"] = "signed";
|
|
5641
|
-
Event["LOGOUT"] = "logout";
|
|
5642
|
-
Event["LOGGED_OUT"] = "logged-out";
|
|
5643
|
-
Event["GET_CURRENT_DEVICE"] = "get-current-device";
|
|
5644
|
-
Event["CURRENT_DEVICE"] = "current-device";
|
|
5645
|
-
Event["PING"] = "ping";
|
|
5646
|
-
Event["PONG"] = "pong";
|
|
5647
|
-
})(Event || (Event = {}));
|
|
5648
|
-
const NOT_CONFIGURED_ERROR = 'not-configured-error';
|
|
5649
|
-
const MISSING_USER_ENTROPY_ERROR = 'missing-user-entropy-error';
|
|
5650
|
-
const INCORRECT_USER_ENTROPY_ERROR = 'incorrect-user-entropy-error';
|
|
5651
|
-
class GetCurrentDeviceRequest {
|
|
5652
|
-
uuid;
|
|
5653
|
-
action = Event.GET_CURRENT_DEVICE;
|
|
5654
|
-
playerID;
|
|
5655
|
-
constructor(uuid, playerId) {
|
|
5656
|
-
this.uuid = uuid;
|
|
5657
|
-
this.playerID = playerId;
|
|
5658
|
-
}
|
|
5659
|
-
}
|
|
5660
|
-
class PingRequest {
|
|
5661
|
-
uuid;
|
|
5662
|
-
action = Event.PING;
|
|
5663
|
-
constructor(uuid) {
|
|
5664
|
-
this.uuid = uuid;
|
|
5665
|
-
}
|
|
5666
|
-
}
|
|
5667
|
-
class GetCurrentDeviceResponse {
|
|
5668
|
-
uuid;
|
|
5669
|
-
success;
|
|
5670
|
-
action = Event.CURRENT_DEVICE;
|
|
5671
|
-
deviceID;
|
|
5672
|
-
accountType;
|
|
5673
|
-
version = null;
|
|
5674
|
-
chainId;
|
|
5675
|
-
address;
|
|
5676
|
-
constructor(uuid, deviceID, accountType, chainId, address) {
|
|
5677
|
-
this.uuid = uuid;
|
|
5678
|
-
this.success = true;
|
|
5679
|
-
this.deviceID = deviceID;
|
|
5680
|
-
this.accountType = accountType;
|
|
5681
|
-
this.chainId = chainId;
|
|
5682
|
-
this.address = address;
|
|
5683
|
-
}
|
|
5684
|
-
}
|
|
5685
|
-
class LogoutRequest {
|
|
5686
|
-
uuid;
|
|
5687
|
-
action = Event.LOGOUT;
|
|
5688
|
-
constructor(uuid) {
|
|
5689
|
-
this.uuid = uuid;
|
|
5690
|
-
}
|
|
5691
|
-
}
|
|
5692
|
-
class SignRequest {
|
|
5693
|
-
uuid;
|
|
5694
|
-
action = Event.SIGN;
|
|
5695
|
-
message;
|
|
5696
|
-
requireArrayify;
|
|
5697
|
-
requireHash;
|
|
5698
|
-
requestConfiguration;
|
|
5699
|
-
constructor(uuid, message, requireArrayify, requireHash, requestConfiguration) {
|
|
5700
|
-
this.uuid = uuid;
|
|
5701
|
-
this.message = message;
|
|
5702
|
-
this.requireArrayify = requireArrayify;
|
|
5703
|
-
this.requireHash = requireHash;
|
|
5704
|
-
this.requestConfiguration = requestConfiguration;
|
|
5705
|
-
}
|
|
5706
|
-
}
|
|
5707
|
-
function isErrorResponse(response) {
|
|
5708
|
-
return 'error' in response;
|
|
5709
|
-
}
|
|
5710
|
-
class ConfigureResponse {
|
|
5711
|
-
uuid;
|
|
5712
|
-
success;
|
|
5713
|
-
deviceID;
|
|
5714
|
-
address;
|
|
5715
|
-
chainId;
|
|
5716
|
-
accountType;
|
|
5717
|
-
action = Event.CONFIGURED;
|
|
5718
|
-
version;
|
|
5719
|
-
constructor(uuid, deviceID, accountType, chainId, address) {
|
|
5720
|
-
this.success = true;
|
|
5721
|
-
this.deviceID = deviceID;
|
|
5722
|
-
this.uuid = uuid;
|
|
5723
|
-
this.accountType = accountType;
|
|
5724
|
-
this.chainId = chainId;
|
|
5725
|
-
this.address = address;
|
|
5726
|
-
this.version = null;
|
|
5727
|
-
}
|
|
5728
|
-
}
|
|
5729
|
-
class UpdateAuthenticationResponse {
|
|
5730
|
-
uuid;
|
|
5731
|
-
success;
|
|
5732
|
-
action = Event.AUTHENTICATION_UPDATED;
|
|
5733
|
-
version;
|
|
5734
|
-
constructor(uuid) {
|
|
5735
|
-
this.success = true;
|
|
5736
|
-
this.uuid = uuid;
|
|
5737
|
-
this.version = null;
|
|
5738
|
-
}
|
|
5739
|
-
}
|
|
5740
|
-
class SignResponse {
|
|
5741
|
-
uuid;
|
|
5742
|
-
success;
|
|
5743
|
-
signature;
|
|
5744
|
-
action = Event.SIGNED;
|
|
5745
|
-
version;
|
|
5746
|
-
constructor(uuid, signature) {
|
|
5747
|
-
this.success = true;
|
|
5748
|
-
this.signature = signature;
|
|
5749
|
-
this.uuid = uuid;
|
|
5750
|
-
this.version = null;
|
|
5751
|
-
}
|
|
5752
|
-
}
|
|
5753
|
-
class LogoutResponse {
|
|
5754
|
-
uuid;
|
|
5755
|
-
success;
|
|
5756
|
-
action = Event.LOGGED_OUT;
|
|
5757
|
-
constructor(uuid) {
|
|
5758
|
-
this.success = true;
|
|
5759
|
-
this.uuid = uuid;
|
|
5760
|
-
}
|
|
5761
|
-
}
|
|
5762
|
-
class UpdateAuthenticationRequest {
|
|
5763
|
-
uuid;
|
|
5764
|
-
action = Event.UPDATE_AUTHENTICATION;
|
|
5765
|
-
accessToken;
|
|
5766
|
-
recovery;
|
|
5767
|
-
constructor(uuid, accessToken, recovery) {
|
|
5768
|
-
this.uuid = uuid;
|
|
5769
|
-
this.accessToken = accessToken;
|
|
5770
|
-
this.recovery = recovery;
|
|
5771
|
-
}
|
|
5772
|
-
}
|
|
5773
|
-
exports.ShieldAuthType = void 0;
|
|
5774
|
-
(function (ShieldAuthType) {
|
|
5775
|
-
ShieldAuthType["OPENFORT"] = "openfort";
|
|
5776
|
-
ShieldAuthType["CUSTOM"] = "custom";
|
|
5777
|
-
})(exports.ShieldAuthType || (exports.ShieldAuthType = {}));
|
|
5778
|
-
|
|
5779
5808
|
class MissingRecoveryPasswordError extends Error {
|
|
5780
5809
|
constructor() {
|
|
5781
5810
|
super('This embedded signer requires a password to be recovered');
|
|
@@ -5979,9 +6008,13 @@ class IframeManager {
|
|
|
5979
6008
|
this.iframe?.contentWindow?.postMessage(request, '*');
|
|
5980
6009
|
await this.waitForResponse(uuid);
|
|
5981
6010
|
}
|
|
5982
|
-
async updateAuthentication(iframeConfiguration, token) {
|
|
6011
|
+
async updateAuthentication(iframeConfiguration, token, shieldAuthType) {
|
|
5983
6012
|
// eslint-disable-next-line no-param-reassign
|
|
5984
6013
|
iframeConfiguration.accessToken = token;
|
|
6014
|
+
if (shieldAuthType === exports.ShieldAuthType.OPENFORT && iframeConfiguration.recovery) {
|
|
6015
|
+
// eslint-disable-next-line no-param-reassign
|
|
6016
|
+
iframeConfiguration.recovery.token = token;
|
|
6017
|
+
}
|
|
5985
6018
|
await this.waitForIframeLoad();
|
|
5986
6019
|
const uuid = this.generateShortUUID();
|
|
5987
6020
|
const request = new UpdateAuthenticationRequest(uuid, token);
|
|
@@ -5992,7 +6025,7 @@ class IframeManager {
|
|
|
5992
6025
|
catch (e) {
|
|
5993
6026
|
if (e instanceof NotConfiguredError) {
|
|
5994
6027
|
await this.configure(iframeConfiguration);
|
|
5995
|
-
await this.updateAuthentication(iframeConfiguration, token);
|
|
6028
|
+
await this.updateAuthentication(iframeConfiguration, token, shieldAuthType);
|
|
5996
6029
|
return;
|
|
5997
6030
|
}
|
|
5998
6031
|
throw e;
|
|
@@ -6068,7 +6101,7 @@ class Openfort {
|
|
|
6068
6101
|
*/
|
|
6069
6102
|
getEthereumProvider(options = { announceProvider: true }) {
|
|
6070
6103
|
if (!(this.signer instanceof EmbeddedSigner)) {
|
|
6071
|
-
throw new OpenfortError('Embedded signer must be configured to get Ethereum provider', OpenfortErrorType.NOT_LOGGED_IN_ERROR);
|
|
6104
|
+
throw new OpenfortError('Embedded signer must be configured to get Ethereum provider', exports.OpenfortErrorType.NOT_LOGGED_IN_ERROR);
|
|
6072
6105
|
}
|
|
6073
6106
|
const address = this.instanceManager.getAccountAddress();
|
|
6074
6107
|
const provider = new EvmProvider({
|
|
@@ -6094,7 +6127,7 @@ class Openfort {
|
|
|
6094
6127
|
*/
|
|
6095
6128
|
configureSessionKey() {
|
|
6096
6129
|
if (this.instanceManager.getSignerType() === SignerType.EMBEDDED) {
|
|
6097
|
-
throw new OpenfortError('Session signer must be configured to sign a session', OpenfortErrorType.MISSING_SESSION_SIGNER_ERROR);
|
|
6130
|
+
throw new OpenfortError('Session signer must be configured to sign a session', exports.OpenfortErrorType.MISSING_SESSION_SIGNER_ERROR);
|
|
6098
6131
|
}
|
|
6099
6132
|
const signer = new SessionSigner(this.instanceManager);
|
|
6100
6133
|
this.signer = signer;
|
|
@@ -6131,11 +6164,12 @@ class Openfort {
|
|
|
6131
6164
|
*
|
|
6132
6165
|
* @param email - User's email.
|
|
6133
6166
|
* @param password - User's password.
|
|
6167
|
+
* @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
|
|
6134
6168
|
* @returns An AuthResponse object containing authentication details.
|
|
6135
6169
|
*/
|
|
6136
|
-
async logInWithEmailPassword({ email, password }) {
|
|
6170
|
+
async logInWithEmailPassword({ email, password, ecosystemGame }) {
|
|
6137
6171
|
this.logout();
|
|
6138
|
-
const result = await this.authManager.loginEmailPassword(email, password);
|
|
6172
|
+
const result = await this.authManager.loginEmailPassword(email, password, ecosystemGame);
|
|
6139
6173
|
this.storeCredentials({
|
|
6140
6174
|
player: result.player.id,
|
|
6141
6175
|
accessToken: result.token,
|
|
@@ -6149,11 +6183,12 @@ class Openfort {
|
|
|
6149
6183
|
* @param email - User's email.
|
|
6150
6184
|
* @param password - User's password.
|
|
6151
6185
|
* @param options - Additional options for the sign-up process.
|
|
6186
|
+
* @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
|
|
6152
6187
|
* @returns An AuthResponse object containing authentication details.
|
|
6153
6188
|
*/
|
|
6154
|
-
async signUpWithEmailPassword({ email, password, options }) {
|
|
6189
|
+
async signUpWithEmailPassword({ email, password, options, ecosystemGame, }) {
|
|
6155
6190
|
this.logout();
|
|
6156
|
-
const result = await this.authManager.signupEmailPassword(email, password, options?.data.name);
|
|
6191
|
+
const result = await this.authManager.signupEmailPassword(email, password, options?.data.name, ecosystemGame);
|
|
6157
6192
|
this.storeCredentials({
|
|
6158
6193
|
player: result.player.id,
|
|
6159
6194
|
accessToken: result.token,
|
|
@@ -6167,11 +6202,11 @@ class Openfort {
|
|
|
6167
6202
|
* @param email - User's email.
|
|
6168
6203
|
* @param password - User's password.
|
|
6169
6204
|
* @param authToken - Authentication token.
|
|
6205
|
+
* @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
|
|
6170
6206
|
* @returns An AuthPlayerResponse object.
|
|
6171
6207
|
*/
|
|
6172
|
-
async linkEmailPassword({ email, password, authToken }) {
|
|
6173
|
-
|
|
6174
|
-
return result;
|
|
6208
|
+
async linkEmailPassword({ email, password, authToken, ecosystemGame, }) {
|
|
6209
|
+
return await this.authManager.linkEmail(email, password, authToken, ecosystemGame);
|
|
6175
6210
|
}
|
|
6176
6211
|
/**
|
|
6177
6212
|
* Unlinks an email and password from an existing account using an authentication token.
|
|
@@ -6181,8 +6216,7 @@ class Openfort {
|
|
|
6181
6216
|
* @returns An AuthPlayerResponse object.
|
|
6182
6217
|
*/
|
|
6183
6218
|
async unlinkEmailPassword({ email, authToken }) {
|
|
6184
|
-
|
|
6185
|
-
return result;
|
|
6219
|
+
return await this.authManager.unlinkEmail(email, authToken);
|
|
6186
6220
|
}
|
|
6187
6221
|
/**
|
|
6188
6222
|
* Requests an email verification link.
|
|
@@ -6226,12 +6260,12 @@ class Openfort {
|
|
|
6226
6260
|
*
|
|
6227
6261
|
* @param provider - OAuth provider.
|
|
6228
6262
|
* @param options - Additional options for initialization.
|
|
6263
|
+
* @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
|
|
6229
6264
|
* @returns An InitAuthResponse object.
|
|
6230
6265
|
*/
|
|
6231
|
-
async initOAuth({ provider, options }) {
|
|
6266
|
+
async initOAuth({ provider, options, ecosystemGame }) {
|
|
6232
6267
|
this.logout();
|
|
6233
|
-
|
|
6234
|
-
return authResponse;
|
|
6268
|
+
return await this.authManager.initOAuth(provider, options, ecosystemGame);
|
|
6235
6269
|
}
|
|
6236
6270
|
/**
|
|
6237
6271
|
* Initializes an OAuth linking process.
|
|
@@ -6239,10 +6273,11 @@ class Openfort {
|
|
|
6239
6273
|
* @param provider - OAuth provider.
|
|
6240
6274
|
* @param authToken - Authentication token.
|
|
6241
6275
|
* @param options - Additional options for initialization.
|
|
6276
|
+
* @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
|
|
6242
6277
|
* @returns An InitAuthResponse object.
|
|
6243
6278
|
*/
|
|
6244
|
-
async initLinkOAuth({ provider, authToken, options }) {
|
|
6245
|
-
return await this.authManager.linkOAuth(provider, authToken, options);
|
|
6279
|
+
async initLinkOAuth({ provider, authToken, options, ecosystemGame, }) {
|
|
6280
|
+
return await this.authManager.linkOAuth(provider, authToken, options, ecosystemGame);
|
|
6246
6281
|
}
|
|
6247
6282
|
/**
|
|
6248
6283
|
* Unlinks an OAuth provider from the account.
|
|
@@ -6252,8 +6287,7 @@ class Openfort {
|
|
|
6252
6287
|
* @returns An AuthPlayerResponse object.
|
|
6253
6288
|
*/
|
|
6254
6289
|
async unlinkOAuth({ provider, authToken }) {
|
|
6255
|
-
|
|
6256
|
-
return result;
|
|
6290
|
+
return await this.authManager.unlinkOAuth(provider, authToken);
|
|
6257
6291
|
}
|
|
6258
6292
|
/**
|
|
6259
6293
|
* Polls for OAuth authentication completion.
|
|
@@ -6270,10 +6304,11 @@ class Openfort {
|
|
|
6270
6304
|
* @param provider - Third-party OAuth provider.
|
|
6271
6305
|
* @param token - OAuth token.
|
|
6272
6306
|
* @param tokenType - Type of the OAuth token.
|
|
6307
|
+
* @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
|
|
6273
6308
|
* @returns An AuthPlayerResponse object.
|
|
6274
6309
|
*/
|
|
6275
|
-
async authenticateWithThirdPartyProvider({ provider, token, tokenType }) {
|
|
6276
|
-
const result = await this.authManager.authenticateThirdParty(provider, token, tokenType);
|
|
6310
|
+
async authenticateWithThirdPartyProvider({ provider, token, tokenType, ecosystemGame, }) {
|
|
6311
|
+
const result = await this.authManager.authenticateThirdParty(provider, token, tokenType, ecosystemGame);
|
|
6277
6312
|
this.instanceManager.setAccessToken({
|
|
6278
6313
|
token,
|
|
6279
6314
|
thirdPartyProvider: provider,
|
|
@@ -6289,10 +6324,11 @@ class Openfort {
|
|
|
6289
6324
|
* Initializes Sign-In with Ethereum (SIWE).
|
|
6290
6325
|
*
|
|
6291
6326
|
* @param address - Ethereum address.
|
|
6327
|
+
* @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
|
|
6292
6328
|
* @returns A SIWEInitResponse object.
|
|
6293
6329
|
*/
|
|
6294
|
-
async initSIWE({ address }) {
|
|
6295
|
-
return await this.authManager.initSIWE(address);
|
|
6330
|
+
async initSIWE({ address, ecosystemGame }) {
|
|
6331
|
+
return await this.authManager.initSIWE(address, ecosystemGame);
|
|
6296
6332
|
}
|
|
6297
6333
|
/**
|
|
6298
6334
|
* Authenticates using Sign-In with Ethereum (SIWE).
|
|
@@ -6326,8 +6362,7 @@ class Openfort {
|
|
|
6326
6362
|
* @returns An AuthPlayerResponse object.
|
|
6327
6363
|
*/
|
|
6328
6364
|
async linkWallet({ signature, message, walletClientType, connectorType, authToken, }) {
|
|
6329
|
-
|
|
6330
|
-
return result;
|
|
6365
|
+
return await this.authManager.linkWallet(signature, message, walletClientType, connectorType, authToken);
|
|
6331
6366
|
}
|
|
6332
6367
|
/**
|
|
6333
6368
|
* Unlinks a wallet.
|
|
@@ -6337,8 +6372,7 @@ class Openfort {
|
|
|
6337
6372
|
* @returns An AuthPlayerResponse object.
|
|
6338
6373
|
*/
|
|
6339
6374
|
async unlinkWallet({ address, authToken }) {
|
|
6340
|
-
|
|
6341
|
-
return result;
|
|
6375
|
+
return await this.authManager.unlinkWallet(address, authToken);
|
|
6342
6376
|
}
|
|
6343
6377
|
/**
|
|
6344
6378
|
* Stores authentication credentials.
|
|
@@ -6369,11 +6403,11 @@ class Openfort {
|
|
|
6369
6403
|
let newSignature = signature;
|
|
6370
6404
|
if (!newSignature) {
|
|
6371
6405
|
if (!userOperationHash) {
|
|
6372
|
-
throw new OpenfortError('No userOperationHash or signature provided', OpenfortErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
6406
|
+
throw new OpenfortError('No userOperationHash or signature provided', exports.OpenfortErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
6373
6407
|
}
|
|
6374
6408
|
await this.recoverSigner();
|
|
6375
6409
|
if (!this.signer) {
|
|
6376
|
-
throw new OpenfortError('In order to sign a transaction intent, a signer must be configured', OpenfortErrorType.MISSING_SIGNER_ERROR);
|
|
6410
|
+
throw new OpenfortError('In order to sign a transaction intent, a signer must be configured', exports.OpenfortErrorType.MISSING_SIGNER_ERROR);
|
|
6377
6411
|
}
|
|
6378
6412
|
if (this.signer.useCredentials()) {
|
|
6379
6413
|
await this.validateAndRefreshToken();
|
|
@@ -6401,7 +6435,7 @@ class Openfort {
|
|
|
6401
6435
|
async signMessage(message, options) {
|
|
6402
6436
|
await this.recoverSigner();
|
|
6403
6437
|
if (!this.signer) {
|
|
6404
|
-
throw new OpenfortError('In order to sign a message, an embedded signer must be configured', OpenfortErrorType.MISSING_EMBEDDED_SIGNER_ERROR);
|
|
6438
|
+
throw new OpenfortError('In order to sign a message, an embedded signer must be configured', exports.OpenfortErrorType.MISSING_EMBEDDED_SIGNER_ERROR);
|
|
6405
6439
|
}
|
|
6406
6440
|
if (this.signer.useCredentials()) {
|
|
6407
6441
|
await this.validateAndRefreshToken();
|
|
@@ -6421,7 +6455,7 @@ class Openfort {
|
|
|
6421
6455
|
async signTypedData(domain, types, value) {
|
|
6422
6456
|
await this.recoverSigner();
|
|
6423
6457
|
if (!this.signer) {
|
|
6424
|
-
throw new OpenfortError('In order to sign a message, an embedded signer must be configured', OpenfortErrorType.MISSING_EMBEDDED_SIGNER_ERROR);
|
|
6458
|
+
throw new OpenfortError('In order to sign a message, an embedded signer must be configured', exports.OpenfortErrorType.MISSING_EMBEDDED_SIGNER_ERROR);
|
|
6425
6459
|
}
|
|
6426
6460
|
if (this.signer.useCredentials()) {
|
|
6427
6461
|
await this.validateAndRefreshToken();
|
|
@@ -6508,7 +6542,7 @@ class Openfort {
|
|
|
6508
6542
|
await this.validateAndRefreshToken();
|
|
6509
6543
|
const accessToken = this.instanceManager.getAccessToken();
|
|
6510
6544
|
if (!accessToken) {
|
|
6511
|
-
throw new OpenfortError('No accessToken found', OpenfortErrorType.NOT_LOGGED_IN_ERROR);
|
|
6545
|
+
throw new OpenfortError('No accessToken found', exports.OpenfortErrorType.NOT_LOGGED_IN_ERROR);
|
|
6512
6546
|
}
|
|
6513
6547
|
return await this.authManager.getUser(accessToken.token);
|
|
6514
6548
|
}
|
|
@@ -6518,7 +6552,7 @@ class Openfort {
|
|
|
6518
6552
|
async validateAndRefreshToken(forceRefresh) {
|
|
6519
6553
|
const authType = this.credentialsProvided();
|
|
6520
6554
|
if (!authType) {
|
|
6521
|
-
throw new OpenfortError('Must be logged in to validate and refresh token', OpenfortErrorType.NOT_LOGGED_IN_ERROR);
|
|
6555
|
+
throw new OpenfortError('Must be logged in to validate and refresh token', exports.OpenfortErrorType.NOT_LOGGED_IN_ERROR);
|
|
6522
6556
|
}
|
|
6523
6557
|
if (authType === exports.AuthType.OPENFORT) {
|
|
6524
6558
|
const auth = await this.authManager.validateCredentials(forceRefresh);
|
|
@@ -6577,20 +6611,14 @@ class Openfort {
|
|
|
6577
6611
|
}
|
|
6578
6612
|
newEmbeddedSigner(chainId) {
|
|
6579
6613
|
if (!this.credentialsProvided()) {
|
|
6580
|
-
throw new OpenfortError('Must be logged in to configure embedded signer', OpenfortErrorType.NOT_LOGGED_IN_ERROR);
|
|
6581
|
-
}
|
|
6582
|
-
let shieldAuthType = this.instanceManager.getShieldAuthType();
|
|
6583
|
-
if (!shieldAuthType) {
|
|
6584
|
-
// TODO: remove, this is for backward compatibility
|
|
6585
|
-
this.instanceManager.setShieldAuthType(exports.ShieldAuthType.OPENFORT);
|
|
6586
|
-
shieldAuthType = exports.ShieldAuthType.OPENFORT;
|
|
6587
|
-
// throw new OpenfortError('Shield auth type is not set', OpenfortErrorType.INVALID_CONFIGURATION);
|
|
6614
|
+
throw new OpenfortError('Must be logged in to configure embedded signer', exports.OpenfortErrorType.NOT_LOGGED_IN_ERROR);
|
|
6588
6615
|
}
|
|
6616
|
+
const shieldAuthType = this.instanceManager.getShieldAuthType();
|
|
6589
6617
|
const token = shieldAuthType === exports.ShieldAuthType.OPENFORT
|
|
6590
6618
|
? this.instanceManager.getAccessToken()?.token
|
|
6591
6619
|
: this.instanceManager.getShieldAuthToken();
|
|
6592
6620
|
if (!token) {
|
|
6593
|
-
throw new OpenfortError('Shield auth token is not set', OpenfortErrorType.INVALID_CONFIGURATION);
|
|
6621
|
+
throw new OpenfortError('Shield auth token is not set', exports.OpenfortErrorType.INVALID_CONFIGURATION);
|
|
6594
6622
|
}
|
|
6595
6623
|
const shieldAuth = {
|
|
6596
6624
|
auth: shieldAuthType,
|