@openfort/openfort-js 0.7.7 → 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/dist/index.cjs +312 -98
- package/dist/index.d.ts +260 -15
- package/dist/index.js +312 -99
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -5872,6 +5872,9 @@ class Openfort {
|
|
|
5872
5872
|
this.openfortEventEmitter = new TypedEventEmitter();
|
|
5873
5873
|
this.iframeManager = new IframeManager(this.config);
|
|
5874
5874
|
}
|
|
5875
|
+
/**
|
|
5876
|
+
* Logs the user out by flushing the signer and removing credentials.
|
|
5877
|
+
*/
|
|
5875
5878
|
async logout() {
|
|
5876
5879
|
await this.flushSigner();
|
|
5877
5880
|
if (this.credentialsProvided()) {
|
|
@@ -5901,9 +5904,14 @@ class Openfort {
|
|
|
5901
5904
|
this.instanceManager.removeJWK();
|
|
5902
5905
|
}
|
|
5903
5906
|
}
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
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 }) {
|
|
5907
5915
|
if (!(this.signer instanceof EmbeddedSigner)) {
|
|
5908
5916
|
throw new OpenfortError('Embedded signer must be configured to get Ethereum provider', OpenfortErrorType.NOT_LOGGED_IN_ERROR);
|
|
5909
5917
|
}
|
|
@@ -5924,32 +5932,11 @@ class Openfort {
|
|
|
5924
5932
|
}
|
|
5925
5933
|
return provider;
|
|
5926
5934
|
}
|
|
5927
|
-
|
|
5928
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
}
|
|
5933
|
-
const signerType = this.instanceManager.getSignerType();
|
|
5934
|
-
switch (signerType) {
|
|
5935
|
-
case SignerType.EMBEDDED: {
|
|
5936
|
-
const iframeConfiguration = {
|
|
5937
|
-
accessToken: this.instanceManager.getAccessToken()?.token ?? null,
|
|
5938
|
-
thirdPartyProvider: this.instanceManager.getAccessToken()?.thirdPartyProvider ?? null,
|
|
5939
|
-
thirdPartyTokenType: this.instanceManager.getAccessToken()?.thirdPartyTokenType ?? null,
|
|
5940
|
-
chainId: null,
|
|
5941
|
-
recovery: null,
|
|
5942
|
-
};
|
|
5943
|
-
const embeddedSigner = new EmbeddedSigner(this.iframeManager, this.instanceManager, iframeConfiguration);
|
|
5944
|
-
await embeddedSigner.logout();
|
|
5945
|
-
break;
|
|
5946
|
-
}
|
|
5947
|
-
case SignerType.SESSION:
|
|
5948
|
-
this.configureSessionKey();
|
|
5949
|
-
break;
|
|
5950
|
-
}
|
|
5951
|
-
this.instanceManager.removeSignerType();
|
|
5952
|
-
}
|
|
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
|
+
*/
|
|
5953
5940
|
configureSessionKey() {
|
|
5954
5941
|
const signer = new SessionSigner(this.instanceManager);
|
|
5955
5942
|
this.signer = signer;
|
|
@@ -5961,6 +5948,13 @@ class Openfort {
|
|
|
5961
5948
|
this.instanceManager.setSignerType(SignerType.SESSION);
|
|
5962
5949
|
return { address: publicKey, isRegistered: true };
|
|
5963
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
|
+
*/
|
|
5964
5958
|
async configureEmbeddedSigner(chainId, shieldAuthentication, recoveryPassword) {
|
|
5965
5959
|
const signer = this.newEmbeddedSigner(chainId, shieldAuthentication);
|
|
5966
5960
|
await this.validateAndRefreshToken();
|
|
@@ -5968,20 +5962,14 @@ class Openfort {
|
|
|
5968
5962
|
this.signer = signer;
|
|
5969
5963
|
this.instanceManager.setSignerType(SignerType.EMBEDDED);
|
|
5970
5964
|
}
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
|
|
5974
|
-
|
|
5975
|
-
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
chainId: !chainId ? Number(this.instanceManager.getChainID()) ?? null : chainId,
|
|
5980
|
-
recovery: shieldAuthentication ?? null,
|
|
5981
|
-
};
|
|
5982
|
-
return new EmbeddedSigner(this.iframeManager, this.instanceManager, iframeConfiguration);
|
|
5983
|
-
}
|
|
5984
|
-
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 }) {
|
|
5985
5973
|
this.instanceManager.removeAccessToken();
|
|
5986
5974
|
this.instanceManager.removeRefreshToken();
|
|
5987
5975
|
this.instanceManager.removePlayerID();
|
|
@@ -5993,7 +5981,15 @@ class Openfort {
|
|
|
5993
5981
|
});
|
|
5994
5982
|
return result;
|
|
5995
5983
|
}
|
|
5996
|
-
|
|
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 }) {
|
|
5997
5993
|
this.instanceManager.removeAccessToken();
|
|
5998
5994
|
this.instanceManager.removeRefreshToken();
|
|
5999
5995
|
this.instanceManager.removePlayerID();
|
|
@@ -6005,31 +6001,116 @@ class Openfort {
|
|
|
6005
6001
|
});
|
|
6006
6002
|
return result;
|
|
6007
6003
|
}
|
|
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
|
+
*/
|
|
6008
6033
|
async requestEmailVerification({ email, redirectUrl }) {
|
|
6009
6034
|
await this.authManager.requestEmailVerification(email, redirectUrl);
|
|
6010
6035
|
}
|
|
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
|
+
*/
|
|
6011
6043
|
async resetPassword({ email, password, state }) {
|
|
6012
6044
|
await this.authManager.resetPassword(email, password, state);
|
|
6013
6045
|
}
|
|
6046
|
+
/**
|
|
6047
|
+
* Requests a password reset link.
|
|
6048
|
+
*
|
|
6049
|
+
* @param email - User's email.
|
|
6050
|
+
* @param redirectUrl - Redirect URL after resetting password.
|
|
6051
|
+
*/
|
|
6014
6052
|
async requestResetPassword({ email, redirectUrl }) {
|
|
6015
6053
|
await this.authManager.requestResetPassword(email, redirectUrl);
|
|
6016
6054
|
}
|
|
6055
|
+
/**
|
|
6056
|
+
* Verifies the user's email.
|
|
6057
|
+
*
|
|
6058
|
+
* @param email - User's email.
|
|
6059
|
+
* @param state - Verification state.
|
|
6060
|
+
*/
|
|
6017
6061
|
async verifyEmail({ email, state }) {
|
|
6018
6062
|
await this.authManager.verifyEmail(email, state);
|
|
6019
6063
|
}
|
|
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
|
+
*/
|
|
6020
6071
|
async initOAuth({ provider, options }) {
|
|
6021
6072
|
const authResponse = await this.authManager.initOAuth(provider, options);
|
|
6022
6073
|
return authResponse;
|
|
6023
6074
|
}
|
|
6024
|
-
|
|
6025
|
-
|
|
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);
|
|
6085
|
+
}
|
|
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);
|
|
6095
|
+
return result;
|
|
6026
6096
|
}
|
|
6097
|
+
/**
|
|
6098
|
+
* Polls for OAuth authentication completion.
|
|
6099
|
+
*
|
|
6100
|
+
* @param key - OAuth polling key.
|
|
6101
|
+
* @returns An AuthResponse object.
|
|
6102
|
+
*/
|
|
6027
6103
|
async poolOAuth(key) {
|
|
6028
6104
|
return await this.authManager.poolOAuth(key);
|
|
6029
6105
|
}
|
|
6030
|
-
|
|
6031
|
-
|
|
6032
|
-
|
|
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
|
+
*/
|
|
6033
6114
|
async authenticateWithThirdPartyProvider({ provider, token, tokenType }) {
|
|
6034
6115
|
const result = await this.authManager.authenticateThirdParty(provider, token, tokenType);
|
|
6035
6116
|
this.instanceManager.setAccessToken({
|
|
@@ -6043,6 +6124,24 @@ class Openfort {
|
|
|
6043
6124
|
}
|
|
6044
6125
|
return result;
|
|
6045
6126
|
}
|
|
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
|
+
*/
|
|
6046
6145
|
async authenticateWithSIWE({ signature, message, walletClientType, connectorType, }) {
|
|
6047
6146
|
this.instanceManager.removeAccessToken();
|
|
6048
6147
|
this.instanceManager.removeRefreshToken();
|
|
@@ -6055,6 +6154,36 @@ class Openfort {
|
|
|
6055
6154
|
});
|
|
6056
6155
|
return result;
|
|
6057
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
|
+
*/
|
|
6058
6187
|
storeCredentials(auth) {
|
|
6059
6188
|
this.instanceManager.setAccessToken({
|
|
6060
6189
|
token: auth.accessToken,
|
|
@@ -6064,6 +6193,15 @@ class Openfort {
|
|
|
6064
6193
|
this.instanceManager.setRefreshToken(auth.refreshToken);
|
|
6065
6194
|
this.instanceManager.setPlayerID(auth.player);
|
|
6066
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
|
+
*/
|
|
6067
6205
|
async sendSignatureTransactionIntentRequest(transactionIntentId, userOperationHash = null, signature = null) {
|
|
6068
6206
|
let newSignature = signature;
|
|
6069
6207
|
if (!newSignature) {
|
|
@@ -6088,6 +6226,14 @@ class Openfort {
|
|
|
6088
6226
|
const result = await this.backendApiClients.transactionIntentsApi.signature(request);
|
|
6089
6227
|
return result.data;
|
|
6090
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
|
+
*/
|
|
6091
6237
|
async signMessage(message, options) {
|
|
6092
6238
|
await this.recoverSigner();
|
|
6093
6239
|
if (!this.signer) {
|
|
@@ -6099,6 +6245,15 @@ class Openfort {
|
|
|
6099
6245
|
const { hashMessage = true, arrayifyMessage = false } = options || {};
|
|
6100
6246
|
return await this.signer.sign(message, arrayifyMessage, hashMessage);
|
|
6101
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
|
+
*/
|
|
6102
6257
|
async signTypedData(domain, types, value) {
|
|
6103
6258
|
await this.recoverSigner();
|
|
6104
6259
|
if (!this.signer) {
|
|
@@ -6132,6 +6287,16 @@ class Openfort {
|
|
|
6132
6287
|
}
|
|
6133
6288
|
return await this.signer.sign(hash$1, false, false);
|
|
6134
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
|
+
*/
|
|
6135
6300
|
async sendRegisterSessionRequest(sessionId, signature, optimistic) {
|
|
6136
6301
|
await this.recoverSigner();
|
|
6137
6302
|
if (!this.signer) {
|
|
@@ -6150,39 +6315,11 @@ class Openfort {
|
|
|
6150
6315
|
const result = await this.backendApiClients.sessionsApi.signatureSession(request);
|
|
6151
6316
|
return result.data;
|
|
6152
6317
|
}
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
|
|
6156
|
-
|
|
6157
|
-
|
|
6158
|
-
if (signerType === SignerType.EMBEDDED) {
|
|
6159
|
-
await this.configureEmbeddedSigner();
|
|
6160
|
-
return;
|
|
6161
|
-
}
|
|
6162
|
-
if (signerType === SignerType.SESSION) {
|
|
6163
|
-
this.configureSessionKey();
|
|
6164
|
-
return;
|
|
6165
|
-
}
|
|
6166
|
-
await this.waitSigner();
|
|
6167
|
-
}
|
|
6168
|
-
async waitSigner() {
|
|
6169
|
-
const retries = 100;
|
|
6170
|
-
const delay = 100;
|
|
6171
|
-
const checkSignerType = async (attempt) => {
|
|
6172
|
-
if (attempt >= retries) {
|
|
6173
|
-
return;
|
|
6174
|
-
}
|
|
6175
|
-
const signerType = this.instanceManager.getSignerType();
|
|
6176
|
-
if (signerType) {
|
|
6177
|
-
return;
|
|
6178
|
-
}
|
|
6179
|
-
await new Promise((resolve) => {
|
|
6180
|
-
setTimeout(resolve, delay);
|
|
6181
|
-
});
|
|
6182
|
-
await checkSignerType(attempt + 1);
|
|
6183
|
-
};
|
|
6184
|
-
await checkSignerType(0);
|
|
6185
|
-
}
|
|
6318
|
+
/**
|
|
6319
|
+
* Gets the embedded state of the current session.
|
|
6320
|
+
*
|
|
6321
|
+
* @returns The embedded state.
|
|
6322
|
+
*/
|
|
6186
6323
|
getEmbeddedState() {
|
|
6187
6324
|
if (!this.credentialsProvided()) {
|
|
6188
6325
|
return exports.EmbeddedState.UNAUTHENTICATED;
|
|
@@ -6198,25 +6335,20 @@ class Openfort {
|
|
|
6198
6335
|
}
|
|
6199
6336
|
return exports.EmbeddedState.READY;
|
|
6200
6337
|
}
|
|
6201
|
-
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
|| (token.token && refreshToken)));
|
|
6207
|
-
}
|
|
6338
|
+
/**
|
|
6339
|
+
* Gets the current access token.
|
|
6340
|
+
*
|
|
6341
|
+
* @returns The access token, or null if not available.
|
|
6342
|
+
*/
|
|
6208
6343
|
getAccessToken() {
|
|
6209
6344
|
return this.instanceManager.getAccessToken()?.token ?? null;
|
|
6210
6345
|
}
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
}
|
|
6218
|
-
return true;
|
|
6219
|
-
}
|
|
6346
|
+
/**
|
|
6347
|
+
* Retrieves the user details.
|
|
6348
|
+
*
|
|
6349
|
+
* @returns An AuthPlayerResponse object.
|
|
6350
|
+
* @throws {OpenfortError} If no access token is found.
|
|
6351
|
+
*/
|
|
6220
6352
|
async getUser() {
|
|
6221
6353
|
await this.validateAndRefreshToken();
|
|
6222
6354
|
const accessToken = this.instanceManager.getAccessToken();
|
|
@@ -6225,6 +6357,9 @@ class Openfort {
|
|
|
6225
6357
|
}
|
|
6226
6358
|
return await this.authManager.getUser(accessToken.token);
|
|
6227
6359
|
}
|
|
6360
|
+
/**
|
|
6361
|
+
* Validates and refreshes the access token if needed.
|
|
6362
|
+
*/
|
|
6228
6363
|
async validateAndRefreshToken() {
|
|
6229
6364
|
if (!this.credentialsProvided()) {
|
|
6230
6365
|
return;
|
|
@@ -6243,9 +6378,88 @@ class Openfort {
|
|
|
6243
6378
|
await this.signer.updateAuthentication();
|
|
6244
6379
|
}
|
|
6245
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
|
+
}
|
|
6387
|
+
async recoverSigner() {
|
|
6388
|
+
if (this.signer) {
|
|
6389
|
+
return;
|
|
6390
|
+
}
|
|
6391
|
+
const signerType = this.instanceManager.getSignerType();
|
|
6392
|
+
if (signerType === SignerType.EMBEDDED) {
|
|
6393
|
+
await this.configureEmbeddedSigner();
|
|
6394
|
+
return;
|
|
6395
|
+
}
|
|
6396
|
+
if (signerType === SignerType.SESSION) {
|
|
6397
|
+
this.configureSessionKey();
|
|
6398
|
+
return;
|
|
6399
|
+
}
|
|
6400
|
+
await this.waitSigner();
|
|
6401
|
+
}
|
|
6402
|
+
async waitSigner() {
|
|
6403
|
+
const retries = 100;
|
|
6404
|
+
const delay = 100;
|
|
6405
|
+
const checkSignerType = async (attempt) => {
|
|
6406
|
+
if (attempt >= retries) {
|
|
6407
|
+
return;
|
|
6408
|
+
}
|
|
6409
|
+
const signerType = this.instanceManager.getSignerType();
|
|
6410
|
+
if (signerType) {
|
|
6411
|
+
return;
|
|
6412
|
+
}
|
|
6413
|
+
await new Promise((resolve) => {
|
|
6414
|
+
setTimeout(resolve, delay);
|
|
6415
|
+
});
|
|
6416
|
+
await checkSignerType(attempt + 1);
|
|
6417
|
+
};
|
|
6418
|
+
await checkSignerType(0);
|
|
6419
|
+
}
|
|
6420
|
+
newEmbeddedSigner(chainId, shieldAuthentication) {
|
|
6421
|
+
if (!this.credentialsProvided()) {
|
|
6422
|
+
throw new OpenfortError('Must be logged in to configure embedded signer', OpenfortErrorType.NOT_LOGGED_IN_ERROR);
|
|
6423
|
+
}
|
|
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);
|
|
6432
|
+
}
|
|
6433
|
+
async flushSigner() {
|
|
6434
|
+
if (this.signer) {
|
|
6435
|
+
await this.signer.logout();
|
|
6436
|
+
this.instanceManager.removeSignerType();
|
|
6437
|
+
return;
|
|
6438
|
+
}
|
|
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;
|
|
6456
|
+
}
|
|
6457
|
+
this.instanceManager.removeSignerType();
|
|
6458
|
+
}
|
|
6246
6459
|
}
|
|
6247
6460
|
|
|
6248
6461
|
exports.OpenfortConfiguration = OpenfortConfiguration;
|
|
6462
|
+
exports.OpenfortError = OpenfortError;
|
|
6249
6463
|
exports.SDKConfiguration = SDKConfiguration;
|
|
6250
6464
|
exports.ShieldConfiguration = ShieldConfiguration;
|
|
6251
6465
|
exports.default = Openfort;
|