@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.js
CHANGED
|
@@ -5849,6 +5849,9 @@ class Openfort {
|
|
|
5849
5849
|
this.openfortEventEmitter = new TypedEventEmitter();
|
|
5850
5850
|
this.iframeManager = new IframeManager(this.config);
|
|
5851
5851
|
}
|
|
5852
|
+
/**
|
|
5853
|
+
* Logs the user out by flushing the signer and removing credentials.
|
|
5854
|
+
*/
|
|
5852
5855
|
async logout() {
|
|
5853
5856
|
await this.flushSigner();
|
|
5854
5857
|
if (this.credentialsProvided()) {
|
|
@@ -5878,9 +5881,14 @@ class Openfort {
|
|
|
5878
5881
|
this.instanceManager.removeJWK();
|
|
5879
5882
|
}
|
|
5880
5883
|
}
|
|
5881
|
-
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
+
/**
|
|
5885
|
+
* Returns an Ethereum provider using the configured signer.
|
|
5886
|
+
*
|
|
5887
|
+
* @param options - Configuration options for the Ethereum provider.
|
|
5888
|
+
* @returns A Provider instance.
|
|
5889
|
+
* @throws {OpenfortError} If the signer is not an EmbeddedSigner.
|
|
5890
|
+
*/
|
|
5891
|
+
getEthereumProvider(options = { announceProvider: true }) {
|
|
5884
5892
|
if (!(this.signer instanceof EmbeddedSigner)) {
|
|
5885
5893
|
throw new OpenfortError('Embedded signer must be configured to get Ethereum provider', OpenfortErrorType.NOT_LOGGED_IN_ERROR);
|
|
5886
5894
|
}
|
|
@@ -5901,32 +5909,11 @@ class Openfort {
|
|
|
5901
5909
|
}
|
|
5902
5910
|
return provider;
|
|
5903
5911
|
}
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
|
|
5909
|
-
}
|
|
5910
|
-
const signerType = this.instanceManager.getSignerType();
|
|
5911
|
-
switch (signerType) {
|
|
5912
|
-
case SignerType.EMBEDDED: {
|
|
5913
|
-
const iframeConfiguration = {
|
|
5914
|
-
accessToken: this.instanceManager.getAccessToken()?.token ?? null,
|
|
5915
|
-
thirdPartyProvider: this.instanceManager.getAccessToken()?.thirdPartyProvider ?? null,
|
|
5916
|
-
thirdPartyTokenType: this.instanceManager.getAccessToken()?.thirdPartyTokenType ?? null,
|
|
5917
|
-
chainId: null,
|
|
5918
|
-
recovery: null,
|
|
5919
|
-
};
|
|
5920
|
-
const embeddedSigner = new EmbeddedSigner(this.iframeManager, this.instanceManager, iframeConfiguration);
|
|
5921
|
-
await embeddedSigner.logout();
|
|
5922
|
-
break;
|
|
5923
|
-
}
|
|
5924
|
-
case SignerType.SESSION:
|
|
5925
|
-
this.configureSessionKey();
|
|
5926
|
-
break;
|
|
5927
|
-
}
|
|
5928
|
-
this.instanceManager.removeSignerType();
|
|
5929
|
-
}
|
|
5912
|
+
/**
|
|
5913
|
+
* Configures a session key and returns the session key details.
|
|
5914
|
+
*
|
|
5915
|
+
* @returns A SessionKey object containing the address and registration status.
|
|
5916
|
+
*/
|
|
5930
5917
|
configureSessionKey() {
|
|
5931
5918
|
const signer = new SessionSigner(this.instanceManager);
|
|
5932
5919
|
this.signer = signer;
|
|
@@ -5938,6 +5925,13 @@ class Openfort {
|
|
|
5938
5925
|
this.instanceManager.setSignerType(SignerType.SESSION);
|
|
5939
5926
|
return { address: publicKey, isRegistered: true };
|
|
5940
5927
|
}
|
|
5928
|
+
/**
|
|
5929
|
+
* Configures an embedded signer.
|
|
5930
|
+
*
|
|
5931
|
+
* @param chainId - The chain ID for the embedded signer.
|
|
5932
|
+
* @param shieldAuthentication - Shield authentication details.
|
|
5933
|
+
* @param recoveryPassword - Recovery password.
|
|
5934
|
+
*/
|
|
5941
5935
|
async configureEmbeddedSigner(chainId, shieldAuthentication, recoveryPassword) {
|
|
5942
5936
|
const signer = this.newEmbeddedSigner(chainId, shieldAuthentication);
|
|
5943
5937
|
await this.validateAndRefreshToken();
|
|
@@ -5945,20 +5939,14 @@ class Openfort {
|
|
|
5945
5939
|
this.signer = signer;
|
|
5946
5940
|
this.instanceManager.setSignerType(SignerType.EMBEDDED);
|
|
5947
5941
|
}
|
|
5948
|
-
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
chainId: !chainId ? Number(this.instanceManager.getChainID()) ?? null : chainId,
|
|
5957
|
-
recovery: shieldAuthentication ?? null,
|
|
5958
|
-
};
|
|
5959
|
-
return new EmbeddedSigner(this.iframeManager, this.instanceManager, iframeConfiguration);
|
|
5960
|
-
}
|
|
5961
|
-
async loginWithEmailPassword({ email, password, }) {
|
|
5942
|
+
/**
|
|
5943
|
+
* Logs in a user with email and password.
|
|
5944
|
+
*
|
|
5945
|
+
* @param email - User's email.
|
|
5946
|
+
* @param password - User's password.
|
|
5947
|
+
* @returns An AuthResponse object containing authentication details.
|
|
5948
|
+
*/
|
|
5949
|
+
async loginWithEmailPassword({ email, password }) {
|
|
5962
5950
|
this.instanceManager.removeAccessToken();
|
|
5963
5951
|
this.instanceManager.removeRefreshToken();
|
|
5964
5952
|
this.instanceManager.removePlayerID();
|
|
@@ -5970,7 +5958,15 @@ class Openfort {
|
|
|
5970
5958
|
});
|
|
5971
5959
|
return result;
|
|
5972
5960
|
}
|
|
5973
|
-
|
|
5961
|
+
/**
|
|
5962
|
+
* Signs up a new user with email and password.
|
|
5963
|
+
*
|
|
5964
|
+
* @param email - User's email.
|
|
5965
|
+
* @param password - User's password.
|
|
5966
|
+
* @param options - Additional options for the sign-up process.
|
|
5967
|
+
* @returns An AuthResponse object containing authentication details.
|
|
5968
|
+
*/
|
|
5969
|
+
async signUpWithEmailPassword({ email, password, options }) {
|
|
5974
5970
|
this.instanceManager.removeAccessToken();
|
|
5975
5971
|
this.instanceManager.removeRefreshToken();
|
|
5976
5972
|
this.instanceManager.removePlayerID();
|
|
@@ -5982,31 +5978,116 @@ class Openfort {
|
|
|
5982
5978
|
});
|
|
5983
5979
|
return result;
|
|
5984
5980
|
}
|
|
5981
|
+
/**
|
|
5982
|
+
* Links an email and password to an existing account using an authentication token.
|
|
5983
|
+
*
|
|
5984
|
+
* @param email - User's email.
|
|
5985
|
+
* @param password - User's password.
|
|
5986
|
+
* @param authToken - Authentication token.
|
|
5987
|
+
* @returns An AuthPlayerResponse object.
|
|
5988
|
+
*/
|
|
5989
|
+
async linkEmailPassword({ email, password, authToken }) {
|
|
5990
|
+
const result = await this.authManager.linkEmail(email, password, authToken);
|
|
5991
|
+
return result;
|
|
5992
|
+
}
|
|
5993
|
+
/**
|
|
5994
|
+
* Unlinks an email and password from an existing account using an authentication token.
|
|
5995
|
+
*
|
|
5996
|
+
* @param email - User's email.
|
|
5997
|
+
* @param authToken - Authentication token.
|
|
5998
|
+
* @returns An AuthPlayerResponse object.
|
|
5999
|
+
*/
|
|
6000
|
+
async unlinkEmailPassword({ email, authToken }) {
|
|
6001
|
+
const result = await this.authManager.unlinkEmail(email, authToken);
|
|
6002
|
+
return result;
|
|
6003
|
+
}
|
|
6004
|
+
/**
|
|
6005
|
+
* Requests an email verification link.
|
|
6006
|
+
*
|
|
6007
|
+
* @param email - User's email.
|
|
6008
|
+
* @param redirectUrl - Redirect URL after verification.
|
|
6009
|
+
*/
|
|
5985
6010
|
async requestEmailVerification({ email, redirectUrl }) {
|
|
5986
6011
|
await this.authManager.requestEmailVerification(email, redirectUrl);
|
|
5987
6012
|
}
|
|
6013
|
+
/**
|
|
6014
|
+
* Resets the user's password.
|
|
6015
|
+
*
|
|
6016
|
+
* @param email - User's email.
|
|
6017
|
+
* @param password - New password.
|
|
6018
|
+
* @param state - Verification state.
|
|
6019
|
+
*/
|
|
5988
6020
|
async resetPassword({ email, password, state }) {
|
|
5989
6021
|
await this.authManager.resetPassword(email, password, state);
|
|
5990
6022
|
}
|
|
6023
|
+
/**
|
|
6024
|
+
* Requests a password reset link.
|
|
6025
|
+
*
|
|
6026
|
+
* @param email - User's email.
|
|
6027
|
+
* @param redirectUrl - Redirect URL after resetting password.
|
|
6028
|
+
*/
|
|
5991
6029
|
async requestResetPassword({ email, redirectUrl }) {
|
|
5992
6030
|
await this.authManager.requestResetPassword(email, redirectUrl);
|
|
5993
6031
|
}
|
|
6032
|
+
/**
|
|
6033
|
+
* Verifies the user's email.
|
|
6034
|
+
*
|
|
6035
|
+
* @param email - User's email.
|
|
6036
|
+
* @param state - Verification state.
|
|
6037
|
+
*/
|
|
5994
6038
|
async verifyEmail({ email, state }) {
|
|
5995
6039
|
await this.authManager.verifyEmail(email, state);
|
|
5996
6040
|
}
|
|
6041
|
+
/**
|
|
6042
|
+
* Initializes an OAuth authentication process.
|
|
6043
|
+
*
|
|
6044
|
+
* @param provider - OAuth provider.
|
|
6045
|
+
* @param options - Additional options for initialization.
|
|
6046
|
+
* @returns An InitAuthResponse object.
|
|
6047
|
+
*/
|
|
5997
6048
|
async initOAuth({ provider, options }) {
|
|
5998
6049
|
const authResponse = await this.authManager.initOAuth(provider, options);
|
|
5999
6050
|
return authResponse;
|
|
6000
6051
|
}
|
|
6001
|
-
|
|
6002
|
-
|
|
6052
|
+
/**
|
|
6053
|
+
* Initializes an OAuth linking process.
|
|
6054
|
+
*
|
|
6055
|
+
* @param provider - OAuth provider.
|
|
6056
|
+
* @param authToken - Authentication token.
|
|
6057
|
+
* @param options - Additional options for initialization.
|
|
6058
|
+
* @returns An InitAuthResponse object.
|
|
6059
|
+
*/
|
|
6060
|
+
async initLinkOAuth({ provider, authToken, options }) {
|
|
6061
|
+
return await this.authManager.linkOAuth(provider, authToken, options);
|
|
6062
|
+
}
|
|
6063
|
+
/**
|
|
6064
|
+
* Unlinks an OAuth provider from the account.
|
|
6065
|
+
*
|
|
6066
|
+
* @param provider - OAuth provider.
|
|
6067
|
+
* @param authToken - Authentication token.
|
|
6068
|
+
* @returns An AuthPlayerResponse object.
|
|
6069
|
+
*/
|
|
6070
|
+
async unlinkOAuth({ provider, authToken }) {
|
|
6071
|
+
const result = await this.authManager.unlinkOAuth(provider, authToken);
|
|
6072
|
+
return result;
|
|
6003
6073
|
}
|
|
6074
|
+
/**
|
|
6075
|
+
* Polls for OAuth authentication completion.
|
|
6076
|
+
*
|
|
6077
|
+
* @param key - OAuth polling key.
|
|
6078
|
+
* @returns An AuthResponse object.
|
|
6079
|
+
*/
|
|
6004
6080
|
async poolOAuth(key) {
|
|
6005
6081
|
return await this.authManager.poolOAuth(key);
|
|
6006
6082
|
}
|
|
6007
|
-
|
|
6008
|
-
|
|
6009
|
-
|
|
6083
|
+
/**
|
|
6084
|
+
* Authenticates using a third-party OAuth provider.
|
|
6085
|
+
*
|
|
6086
|
+
* @param provider - Third-party OAuth provider.
|
|
6087
|
+
* @param token - OAuth token.
|
|
6088
|
+
* @param tokenType - Type of the OAuth token.
|
|
6089
|
+
* @returns An AuthPlayerResponse object.
|
|
6090
|
+
*/
|
|
6010
6091
|
async authenticateWithThirdPartyProvider({ provider, token, tokenType }) {
|
|
6011
6092
|
const result = await this.authManager.authenticateThirdParty(provider, token, tokenType);
|
|
6012
6093
|
this.instanceManager.setAccessToken({
|
|
@@ -6020,6 +6101,24 @@ class Openfort {
|
|
|
6020
6101
|
}
|
|
6021
6102
|
return result;
|
|
6022
6103
|
}
|
|
6104
|
+
/**
|
|
6105
|
+
* Initializes Sign-In with Ethereum (SIWE).
|
|
6106
|
+
*
|
|
6107
|
+
* @param address - Ethereum address.
|
|
6108
|
+
* @returns A SIWEInitResponse object.
|
|
6109
|
+
*/
|
|
6110
|
+
async initSIWE({ address }) {
|
|
6111
|
+
return await this.authManager.initSIWE(address);
|
|
6112
|
+
}
|
|
6113
|
+
/**
|
|
6114
|
+
* Authenticates using Sign-In with Ethereum (SIWE).
|
|
6115
|
+
*
|
|
6116
|
+
* @param signature - SIWE signature.
|
|
6117
|
+
* @param message - SIWE message.
|
|
6118
|
+
* @param walletClientType - Wallet client type.
|
|
6119
|
+
* @param connectorType - Connector type.
|
|
6120
|
+
* @returns An AuthResponse object.
|
|
6121
|
+
*/
|
|
6023
6122
|
async authenticateWithSIWE({ signature, message, walletClientType, connectorType, }) {
|
|
6024
6123
|
this.instanceManager.removeAccessToken();
|
|
6025
6124
|
this.instanceManager.removeRefreshToken();
|
|
@@ -6032,6 +6131,36 @@ class Openfort {
|
|
|
6032
6131
|
});
|
|
6033
6132
|
return result;
|
|
6034
6133
|
}
|
|
6134
|
+
/**
|
|
6135
|
+
* Links a wallet using SIWE.
|
|
6136
|
+
*
|
|
6137
|
+
* @param signature - SIWE signature.
|
|
6138
|
+
* @param message - SIWE message.
|
|
6139
|
+
* @param walletClientType - Wallet client type.
|
|
6140
|
+
* @param connectorType - Connector type.
|
|
6141
|
+
* @param authToken - Authentication token.
|
|
6142
|
+
* @returns An AuthPlayerResponse object.
|
|
6143
|
+
*/
|
|
6144
|
+
async linkWallet({ signature, message, walletClientType, connectorType, authToken, }) {
|
|
6145
|
+
const result = await this.authManager.linkWallet(signature, message, walletClientType, connectorType, authToken);
|
|
6146
|
+
return result;
|
|
6147
|
+
}
|
|
6148
|
+
/**
|
|
6149
|
+
* Unlinks a wallet.
|
|
6150
|
+
*
|
|
6151
|
+
* @param address - Wallet address.
|
|
6152
|
+
* @param authToken - Authentication token.
|
|
6153
|
+
* @returns An AuthPlayerResponse object.
|
|
6154
|
+
*/
|
|
6155
|
+
async unlinkWallet({ address, authToken }) {
|
|
6156
|
+
const result = await this.authManager.unlinkWallet(address, authToken);
|
|
6157
|
+
return result;
|
|
6158
|
+
}
|
|
6159
|
+
/**
|
|
6160
|
+
* Stores authentication credentials.
|
|
6161
|
+
*
|
|
6162
|
+
* @param auth - Authentication details.
|
|
6163
|
+
*/
|
|
6035
6164
|
storeCredentials(auth) {
|
|
6036
6165
|
this.instanceManager.setAccessToken({
|
|
6037
6166
|
token: auth.accessToken,
|
|
@@ -6041,6 +6170,15 @@ class Openfort {
|
|
|
6041
6170
|
this.instanceManager.setRefreshToken(auth.refreshToken);
|
|
6042
6171
|
this.instanceManager.setPlayerID(auth.player);
|
|
6043
6172
|
}
|
|
6173
|
+
/**
|
|
6174
|
+
* Sends a signature transaction intent request.
|
|
6175
|
+
*
|
|
6176
|
+
* @param transactionIntentId - Transaction intent ID.
|
|
6177
|
+
* @param userOperationHash - User operation hash.
|
|
6178
|
+
* @param signature - Transaction signature.
|
|
6179
|
+
* @returns A TransactionIntentResponse object.
|
|
6180
|
+
* @throws {OpenfortError} If no userOperationHash or signature is provided.
|
|
6181
|
+
*/
|
|
6044
6182
|
async sendSignatureTransactionIntentRequest(transactionIntentId, userOperationHash = null, signature = null) {
|
|
6045
6183
|
let newSignature = signature;
|
|
6046
6184
|
if (!newSignature) {
|
|
@@ -6065,6 +6203,14 @@ class Openfort {
|
|
|
6065
6203
|
const result = await this.backendApiClients.transactionIntentsApi.signature(request);
|
|
6066
6204
|
return result.data;
|
|
6067
6205
|
}
|
|
6206
|
+
/**
|
|
6207
|
+
* Signs a message.
|
|
6208
|
+
*
|
|
6209
|
+
* @param message - Message to sign.
|
|
6210
|
+
* @param options - Additional options for signing.
|
|
6211
|
+
* @returns The signature.
|
|
6212
|
+
* @throws {OpenfortError} If no signer is configured.
|
|
6213
|
+
*/
|
|
6068
6214
|
async signMessage(message, options) {
|
|
6069
6215
|
await this.recoverSigner();
|
|
6070
6216
|
if (!this.signer) {
|
|
@@ -6076,6 +6222,15 @@ class Openfort {
|
|
|
6076
6222
|
const { hashMessage = true, arrayifyMessage = false } = options || {};
|
|
6077
6223
|
return await this.signer.sign(message, arrayifyMessage, hashMessage);
|
|
6078
6224
|
}
|
|
6225
|
+
/**
|
|
6226
|
+
* Signs typed data.
|
|
6227
|
+
*
|
|
6228
|
+
* @param domain - EIP-712 domain.
|
|
6229
|
+
* @param types - Typed data types.
|
|
6230
|
+
* @param value - Typed data value.
|
|
6231
|
+
* @returns The signature.
|
|
6232
|
+
* @throws {OpenfortError} If no signer is configured.
|
|
6233
|
+
*/
|
|
6079
6234
|
async signTypedData(domain, types, value) {
|
|
6080
6235
|
await this.recoverSigner();
|
|
6081
6236
|
if (!this.signer) {
|
|
@@ -6109,6 +6264,16 @@ class Openfort {
|
|
|
6109
6264
|
}
|
|
6110
6265
|
return await this.signer.sign(hash, false, false);
|
|
6111
6266
|
}
|
|
6267
|
+
/**
|
|
6268
|
+
* Sends a session registration request.
|
|
6269
|
+
*
|
|
6270
|
+
* @param sessionId - Session ID.
|
|
6271
|
+
* @param signature - Session signature.
|
|
6272
|
+
* @param optimistic - Whether the request is optimistic.
|
|
6273
|
+
* @returns A SessionResponse object.
|
|
6274
|
+
* @throws {OpenfortError} If no signer is configured.
|
|
6275
|
+
* @throws {OpenfortError} If the signer is not a SessionSigner.
|
|
6276
|
+
*/
|
|
6112
6277
|
async sendRegisterSessionRequest(sessionId, signature, optimistic) {
|
|
6113
6278
|
await this.recoverSigner();
|
|
6114
6279
|
if (!this.signer) {
|
|
@@ -6127,39 +6292,11 @@ class Openfort {
|
|
|
6127
6292
|
const result = await this.backendApiClients.sessionsApi.signatureSession(request);
|
|
6128
6293
|
return result.data;
|
|
6129
6294
|
}
|
|
6130
|
-
|
|
6131
|
-
|
|
6132
|
-
|
|
6133
|
-
|
|
6134
|
-
|
|
6135
|
-
if (signerType === SignerType.EMBEDDED) {
|
|
6136
|
-
await this.configureEmbeddedSigner();
|
|
6137
|
-
return;
|
|
6138
|
-
}
|
|
6139
|
-
if (signerType === SignerType.SESSION) {
|
|
6140
|
-
this.configureSessionKey();
|
|
6141
|
-
return;
|
|
6142
|
-
}
|
|
6143
|
-
await this.waitSigner();
|
|
6144
|
-
}
|
|
6145
|
-
async waitSigner() {
|
|
6146
|
-
const retries = 100;
|
|
6147
|
-
const delay = 100;
|
|
6148
|
-
const checkSignerType = async (attempt) => {
|
|
6149
|
-
if (attempt >= retries) {
|
|
6150
|
-
return;
|
|
6151
|
-
}
|
|
6152
|
-
const signerType = this.instanceManager.getSignerType();
|
|
6153
|
-
if (signerType) {
|
|
6154
|
-
return;
|
|
6155
|
-
}
|
|
6156
|
-
await new Promise((resolve) => {
|
|
6157
|
-
setTimeout(resolve, delay);
|
|
6158
|
-
});
|
|
6159
|
-
await checkSignerType(attempt + 1);
|
|
6160
|
-
};
|
|
6161
|
-
await checkSignerType(0);
|
|
6162
|
-
}
|
|
6295
|
+
/**
|
|
6296
|
+
* Gets the embedded state of the current session.
|
|
6297
|
+
*
|
|
6298
|
+
* @returns The embedded state.
|
|
6299
|
+
*/
|
|
6163
6300
|
getEmbeddedState() {
|
|
6164
6301
|
if (!this.credentialsProvided()) {
|
|
6165
6302
|
return EmbeddedState.UNAUTHENTICATED;
|
|
@@ -6175,25 +6312,20 @@ class Openfort {
|
|
|
6175
6312
|
}
|
|
6176
6313
|
return EmbeddedState.READY;
|
|
6177
6314
|
}
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|| (token.token && refreshToken)));
|
|
6184
|
-
}
|
|
6315
|
+
/**
|
|
6316
|
+
* Gets the current access token.
|
|
6317
|
+
*
|
|
6318
|
+
* @returns The access token, or null if not available.
|
|
6319
|
+
*/
|
|
6185
6320
|
getAccessToken() {
|
|
6186
6321
|
return this.instanceManager.getAccessToken()?.token ?? null;
|
|
6187
6322
|
}
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
}
|
|
6195
|
-
return true;
|
|
6196
|
-
}
|
|
6323
|
+
/**
|
|
6324
|
+
* Retrieves the user details.
|
|
6325
|
+
*
|
|
6326
|
+
* @returns An AuthPlayerResponse object.
|
|
6327
|
+
* @throws {OpenfortError} If no access token is found.
|
|
6328
|
+
*/
|
|
6197
6329
|
async getUser() {
|
|
6198
6330
|
await this.validateAndRefreshToken();
|
|
6199
6331
|
const accessToken = this.instanceManager.getAccessToken();
|
|
@@ -6202,6 +6334,9 @@ class Openfort {
|
|
|
6202
6334
|
}
|
|
6203
6335
|
return await this.authManager.getUser(accessToken.token);
|
|
6204
6336
|
}
|
|
6337
|
+
/**
|
|
6338
|
+
* Validates and refreshes the access token if needed.
|
|
6339
|
+
*/
|
|
6205
6340
|
async validateAndRefreshToken() {
|
|
6206
6341
|
if (!this.credentialsProvided()) {
|
|
6207
6342
|
return;
|
|
@@ -6220,6 +6355,84 @@ class Openfort {
|
|
|
6220
6355
|
await this.signer.updateAuthentication();
|
|
6221
6356
|
}
|
|
6222
6357
|
}
|
|
6358
|
+
credentialsProvided() {
|
|
6359
|
+
const token = this.instanceManager.getAccessToken();
|
|
6360
|
+
const refreshToken = this.instanceManager.getRefreshToken();
|
|
6361
|
+
return token && ((token.token && token.thirdPartyProvider && token.thirdPartyTokenType)
|
|
6362
|
+
|| (token.token && refreshToken));
|
|
6363
|
+
}
|
|
6364
|
+
async recoverSigner() {
|
|
6365
|
+
if (this.signer) {
|
|
6366
|
+
return;
|
|
6367
|
+
}
|
|
6368
|
+
const signerType = this.instanceManager.getSignerType();
|
|
6369
|
+
if (signerType === SignerType.EMBEDDED) {
|
|
6370
|
+
await this.configureEmbeddedSigner();
|
|
6371
|
+
return;
|
|
6372
|
+
}
|
|
6373
|
+
if (signerType === SignerType.SESSION) {
|
|
6374
|
+
this.configureSessionKey();
|
|
6375
|
+
return;
|
|
6376
|
+
}
|
|
6377
|
+
await this.waitSigner();
|
|
6378
|
+
}
|
|
6379
|
+
async waitSigner() {
|
|
6380
|
+
const retries = 100;
|
|
6381
|
+
const delay = 100;
|
|
6382
|
+
const checkSignerType = async (attempt) => {
|
|
6383
|
+
if (attempt >= retries) {
|
|
6384
|
+
return;
|
|
6385
|
+
}
|
|
6386
|
+
const signerType = this.instanceManager.getSignerType();
|
|
6387
|
+
if (signerType) {
|
|
6388
|
+
return;
|
|
6389
|
+
}
|
|
6390
|
+
await new Promise((resolve) => {
|
|
6391
|
+
setTimeout(resolve, delay);
|
|
6392
|
+
});
|
|
6393
|
+
await checkSignerType(attempt + 1);
|
|
6394
|
+
};
|
|
6395
|
+
await checkSignerType(0);
|
|
6396
|
+
}
|
|
6397
|
+
newEmbeddedSigner(chainId, shieldAuthentication) {
|
|
6398
|
+
if (!this.credentialsProvided()) {
|
|
6399
|
+
throw new OpenfortError('Must be logged in to configure embedded signer', OpenfortErrorType.NOT_LOGGED_IN_ERROR);
|
|
6400
|
+
}
|
|
6401
|
+
const iframeConfiguration = {
|
|
6402
|
+
accessToken: this.instanceManager.getAccessToken()?.token ?? null,
|
|
6403
|
+
thirdPartyProvider: this.instanceManager.getAccessToken()?.thirdPartyProvider ?? null,
|
|
6404
|
+
thirdPartyTokenType: this.instanceManager.getAccessToken()?.thirdPartyTokenType ?? null,
|
|
6405
|
+
chainId: !chainId ? Number(this.instanceManager.getChainID()) ?? null : chainId,
|
|
6406
|
+
recovery: shieldAuthentication ?? null,
|
|
6407
|
+
};
|
|
6408
|
+
return new EmbeddedSigner(this.iframeManager, this.instanceManager, iframeConfiguration);
|
|
6409
|
+
}
|
|
6410
|
+
async flushSigner() {
|
|
6411
|
+
if (this.signer) {
|
|
6412
|
+
await this.signer.logout();
|
|
6413
|
+
this.instanceManager.removeSignerType();
|
|
6414
|
+
return;
|
|
6415
|
+
}
|
|
6416
|
+
const signerType = this.instanceManager.getSignerType();
|
|
6417
|
+
switch (signerType) {
|
|
6418
|
+
case SignerType.EMBEDDED: {
|
|
6419
|
+
const iframeConfiguration = {
|
|
6420
|
+
accessToken: this.instanceManager.getAccessToken()?.token ?? null,
|
|
6421
|
+
thirdPartyProvider: this.instanceManager.getAccessToken()?.thirdPartyProvider ?? null,
|
|
6422
|
+
thirdPartyTokenType: this.instanceManager.getAccessToken()?.thirdPartyTokenType ?? null,
|
|
6423
|
+
chainId: null,
|
|
6424
|
+
recovery: null,
|
|
6425
|
+
};
|
|
6426
|
+
const embeddedSigner = new EmbeddedSigner(this.iframeManager, this.instanceManager, iframeConfiguration);
|
|
6427
|
+
await embeddedSigner.logout();
|
|
6428
|
+
break;
|
|
6429
|
+
}
|
|
6430
|
+
case SignerType.SESSION:
|
|
6431
|
+
this.configureSessionKey();
|
|
6432
|
+
break;
|
|
6433
|
+
}
|
|
6434
|
+
this.instanceManager.removeSignerType();
|
|
6435
|
+
}
|
|
6223
6436
|
}
|
|
6224
6437
|
|
|
6225
|
-
export { AuthType, BasicAuthProvider, EmbeddedState, OAuthProvider, OpenfortConfiguration, SDKConfiguration, ShieldConfiguration, ThirdPartyOAuthProvider, TokenType, Openfort as default };
|
|
6438
|
+
export { AuthType, BasicAuthProvider, EmbeddedState, OAuthProvider, OpenfortConfiguration, OpenfortError, SDKConfiguration, ShieldConfiguration, ThirdPartyOAuthProvider, TokenType, Openfort as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfort/openfort-js",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.8",
|
|
4
4
|
"author": "Openfort (https://www.openfort.xyz)",
|
|
5
5
|
"bugs": "https://github.com/openfort-xyz/openfort-js/issues",
|
|
6
6
|
"repository": "openfort-xyz/openfort-js.git",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"es6-promise": "^4.2.8",
|
|
47
47
|
"jose": "^5.2.2",
|
|
48
48
|
"path": "^0.12.7",
|
|
49
|
+
"stream-browserify": "^3.0.0",
|
|
49
50
|
"uuid": "^8.3.2"
|
|
50
51
|
},
|
|
51
52
|
"exports": {
|