@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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { SessionKey, AuthResponse, OAuthProvider as OAuthProvider$1, InitializeOAuthOptions as InitializeOAuthOptions$1, InitAuthResponse, TokenType as TokenType$1, SIWEInitResponse, ThirdPartyOAuthProvider as ThirdPartyOAuthProvider$1, AuthPlayerResponse as AuthPlayerResponse$1, Auth, TransactionIntentResponse as TransactionIntentResponse$1, SessionResponse as SessionResponse$1, EmbeddedState as EmbeddedState$1, SDKOverrides as SDKOverrides$1 } from 'types';
1
+ import { SessionKey, AuthResponse, AuthPlayerResponse as AuthPlayerResponse$1, OAuthProvider as OAuthProvider$1, InitializeOAuthOptions as InitializeOAuthOptions$1, InitAuthResponse, ThirdPartyOAuthProvider as ThirdPartyOAuthProvider$1, TokenType as TokenType$1, SIWEInitResponse, Auth, TransactionIntentResponse as TransactionIntentResponse$1, SessionResponse as SessionResponse$1, EmbeddedState as EmbeddedState$1, SDKOverrides as SDKOverrides$1 } from 'types';
2
2
  import { SDKConfiguration as SDKConfiguration$1 } from 'config';
3
3
  import { Provider as Provider$1 } from 'evm/types';
4
4
 
@@ -76,44 +76,330 @@ declare class Openfort {
76
76
  private readonly iframeManager;
77
77
  private readonly openfortEventEmitter;
78
78
  constructor(sdkConfiguration: SDKConfiguration$1);
79
+ /**
80
+ * Logs the user out by flushing the signer and removing credentials.
81
+ */
79
82
  logout(): Promise<void>;
83
+ /**
84
+ * Returns an Ethereum provider using the configured signer.
85
+ *
86
+ * @param options - Configuration options for the Ethereum provider.
87
+ * @returns A Provider instance.
88
+ * @throws {OpenfortError} If the signer is not an EmbeddedSigner.
89
+ */
80
90
  getEthereumProvider(options?: {
81
91
  announceProvider: boolean;
82
92
  policy?: string;
83
93
  }): Provider$1;
84
- private flushSigner;
94
+ /**
95
+ * Configures a session key and returns the session key details.
96
+ *
97
+ * @returns A SessionKey object containing the address and registration status.
98
+ */
85
99
  configureSessionKey(): SessionKey;
100
+ /**
101
+ * Configures an embedded signer.
102
+ *
103
+ * @param chainId - The chain ID for the embedded signer.
104
+ * @param shieldAuthentication - Shield authentication details.
105
+ * @param recoveryPassword - Recovery password.
106
+ */
86
107
  configureEmbeddedSigner(chainId?: number, shieldAuthentication?: ShieldAuthentication, recoveryPassword?: string): Promise<void>;
87
- private newEmbeddedSigner;
88
- loginWithEmailPassword(email: string, password: string): Promise<AuthResponse>;
89
- signUpWithEmailPassword(email: string, password: string, name?: string): Promise<AuthResponse>;
90
- requestEmailVerification(email: string, redirectUrl: string): Promise<void>;
91
- resetPassword(email: string, password: string, state: string): Promise<void>;
92
- requestResetPassword(email: string, redirectUrl: string): Promise<void>;
93
- verifyEmail(email: string, state: string): Promise<void>;
94
- initOAuth(provider: OAuthProvider$1, usePooling?: boolean, options?: InitializeOAuthOptions$1): Promise<InitAuthResponse>;
95
- initLinkOAuth(provider: OAuthProvider$1, playerToken: string, usePooling?: boolean, options?: InitializeOAuthOptions$1): Promise<InitAuthResponse>;
108
+ /**
109
+ * Logs in a user with email and password.
110
+ *
111
+ * @param email - User's email.
112
+ * @param password - User's password.
113
+ * @returns An AuthResponse object containing authentication details.
114
+ */
115
+ loginWithEmailPassword({ email, password }: {
116
+ email: string;
117
+ password: string;
118
+ }): Promise<AuthResponse>;
119
+ /**
120
+ * Signs up a new user with email and password.
121
+ *
122
+ * @param email - User's email.
123
+ * @param password - User's password.
124
+ * @param options - Additional options for the sign-up process.
125
+ * @returns An AuthResponse object containing authentication details.
126
+ */
127
+ signUpWithEmailPassword({ email, password, options }: {
128
+ email: string;
129
+ password: string;
130
+ options?: {
131
+ data: {
132
+ name: string;
133
+ };
134
+ };
135
+ }): Promise<AuthResponse>;
136
+ /**
137
+ * Links an email and password to an existing account using an authentication token.
138
+ *
139
+ * @param email - User's email.
140
+ * @param password - User's password.
141
+ * @param authToken - Authentication token.
142
+ * @returns An AuthPlayerResponse object.
143
+ */
144
+ linkEmailPassword({ email, password, authToken }: {
145
+ email: string;
146
+ password: string;
147
+ authToken: string;
148
+ }): Promise<AuthPlayerResponse$1>;
149
+ /**
150
+ * Unlinks an email and password from an existing account using an authentication token.
151
+ *
152
+ * @param email - User's email.
153
+ * @param authToken - Authentication token.
154
+ * @returns An AuthPlayerResponse object.
155
+ */
156
+ unlinkEmailPassword({ email, authToken }: {
157
+ email: string;
158
+ authToken: string;
159
+ }): Promise<AuthPlayerResponse$1>;
160
+ /**
161
+ * Requests an email verification link.
162
+ *
163
+ * @param email - User's email.
164
+ * @param redirectUrl - Redirect URL after verification.
165
+ */
166
+ requestEmailVerification({ email, redirectUrl }: {
167
+ email: string;
168
+ redirectUrl: string;
169
+ }): Promise<void>;
170
+ /**
171
+ * Resets the user's password.
172
+ *
173
+ * @param email - User's email.
174
+ * @param password - New password.
175
+ * @param state - Verification state.
176
+ */
177
+ resetPassword({ email, password, state }: {
178
+ email: string;
179
+ password: string;
180
+ state: string;
181
+ }): Promise<void>;
182
+ /**
183
+ * Requests a password reset link.
184
+ *
185
+ * @param email - User's email.
186
+ * @param redirectUrl - Redirect URL after resetting password.
187
+ */
188
+ requestResetPassword({ email, redirectUrl }: {
189
+ email: string;
190
+ redirectUrl: string;
191
+ }): Promise<void>;
192
+ /**
193
+ * Verifies the user's email.
194
+ *
195
+ * @param email - User's email.
196
+ * @param state - Verification state.
197
+ */
198
+ verifyEmail({ email, state }: {
199
+ email: string;
200
+ state: string;
201
+ }): Promise<void>;
202
+ /**
203
+ * Initializes an OAuth authentication process.
204
+ *
205
+ * @param provider - OAuth provider.
206
+ * @param options - Additional options for initialization.
207
+ * @returns An InitAuthResponse object.
208
+ */
209
+ initOAuth({ provider, options }: {
210
+ provider: OAuthProvider$1;
211
+ options?: InitializeOAuthOptions$1;
212
+ }): Promise<InitAuthResponse>;
213
+ /**
214
+ * Initializes an OAuth linking process.
215
+ *
216
+ * @param provider - OAuth provider.
217
+ * @param authToken - Authentication token.
218
+ * @param options - Additional options for initialization.
219
+ * @returns An InitAuthResponse object.
220
+ */
221
+ initLinkOAuth({ provider, authToken, options }: {
222
+ provider: OAuthProvider$1;
223
+ authToken: string;
224
+ options?: InitializeOAuthOptions$1;
225
+ }): Promise<InitAuthResponse>;
226
+ /**
227
+ * Unlinks an OAuth provider from the account.
228
+ *
229
+ * @param provider - OAuth provider.
230
+ * @param authToken - Authentication token.
231
+ * @returns An AuthPlayerResponse object.
232
+ */
233
+ unlinkOAuth({ provider, authToken }: {
234
+ provider: OAuthProvider$1;
235
+ authToken: string;
236
+ }): Promise<AuthPlayerResponse$1>;
237
+ /**
238
+ * Polls for OAuth authentication completion.
239
+ *
240
+ * @param key - OAuth polling key.
241
+ * @returns An AuthResponse object.
242
+ */
96
243
  poolOAuth(key: string): Promise<AuthResponse>;
97
- authenticateWithOAuth(provider: OAuthProvider$1, token: string, tokenType: TokenType$1): Promise<AuthResponse>;
98
- initSIWE(address: string): Promise<SIWEInitResponse>;
99
- authenticateWithThirdPartyProvider(provider: ThirdPartyOAuthProvider$1, token: string, tokenType: TokenType$1): Promise<AuthPlayerResponse$1>;
100
- authenticateWithSIWE(signature: string, message: string, walletClientType: string, connectorType: string): Promise<AuthResponse>;
244
+ /**
245
+ * Authenticates using a third-party OAuth provider.
246
+ *
247
+ * @param provider - Third-party OAuth provider.
248
+ * @param token - OAuth token.
249
+ * @param tokenType - Type of the OAuth token.
250
+ * @returns An AuthPlayerResponse object.
251
+ */
252
+ authenticateWithThirdPartyProvider({ provider, token, tokenType }: {
253
+ provider: ThirdPartyOAuthProvider$1;
254
+ token: string;
255
+ tokenType: TokenType$1;
256
+ }): Promise<AuthPlayerResponse$1>;
257
+ /**
258
+ * Initializes Sign-In with Ethereum (SIWE).
259
+ *
260
+ * @param address - Ethereum address.
261
+ * @returns A SIWEInitResponse object.
262
+ */
263
+ initSIWE({ address }: {
264
+ address: string;
265
+ }): Promise<SIWEInitResponse>;
266
+ /**
267
+ * Authenticates using Sign-In with Ethereum (SIWE).
268
+ *
269
+ * @param signature - SIWE signature.
270
+ * @param message - SIWE message.
271
+ * @param walletClientType - Wallet client type.
272
+ * @param connectorType - Connector type.
273
+ * @returns An AuthResponse object.
274
+ */
275
+ authenticateWithSIWE({ signature, message, walletClientType, connectorType, }: {
276
+ signature: string;
277
+ message: string;
278
+ walletClientType: string;
279
+ connectorType: string;
280
+ }): Promise<AuthResponse>;
281
+ /**
282
+ * Links a wallet using SIWE.
283
+ *
284
+ * @param signature - SIWE signature.
285
+ * @param message - SIWE message.
286
+ * @param walletClientType - Wallet client type.
287
+ * @param connectorType - Connector type.
288
+ * @param authToken - Authentication token.
289
+ * @returns An AuthPlayerResponse object.
290
+ */
291
+ linkWallet({ signature, message, walletClientType, connectorType, authToken, }: {
292
+ signature: string;
293
+ message: string;
294
+ walletClientType: string;
295
+ connectorType: string;
296
+ authToken: string;
297
+ }): Promise<AuthPlayerResponse$1>;
298
+ /**
299
+ * Unlinks a wallet.
300
+ *
301
+ * @param address - Wallet address.
302
+ * @param authToken - Authentication token.
303
+ * @returns An AuthPlayerResponse object.
304
+ */
305
+ unlinkWallet({ address, authToken }: {
306
+ address: string;
307
+ authToken: string;
308
+ }): Promise<AuthPlayerResponse$1>;
309
+ /**
310
+ * Stores authentication credentials.
311
+ *
312
+ * @param auth - Authentication details.
313
+ */
101
314
  storeCredentials(auth: Auth): void;
315
+ /**
316
+ * Sends a signature transaction intent request.
317
+ *
318
+ * @param transactionIntentId - Transaction intent ID.
319
+ * @param userOperationHash - User operation hash.
320
+ * @param signature - Transaction signature.
321
+ * @returns A TransactionIntentResponse object.
322
+ * @throws {OpenfortError} If no userOperationHash or signature is provided.
323
+ */
102
324
  sendSignatureTransactionIntentRequest(transactionIntentId: string, userOperationHash?: string | null, signature?: string | null): Promise<TransactionIntentResponse$1>;
325
+ /**
326
+ * Signs a message.
327
+ *
328
+ * @param message - Message to sign.
329
+ * @param options - Additional options for signing.
330
+ * @returns The signature.
331
+ * @throws {OpenfortError} If no signer is configured.
332
+ */
103
333
  signMessage(message: string | Uint8Array, options?: {
104
334
  hashMessage?: boolean;
105
335
  arrayifyMessage?: boolean;
106
336
  }): Promise<string>;
337
+ /**
338
+ * Signs typed data.
339
+ *
340
+ * @param domain - EIP-712 domain.
341
+ * @param types - Typed data types.
342
+ * @param value - Typed data value.
343
+ * @returns The signature.
344
+ * @throws {OpenfortError} If no signer is configured.
345
+ */
107
346
  signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): Promise<string>;
347
+ /**
348
+ * Sends a session registration request.
349
+ *
350
+ * @param sessionId - Session ID.
351
+ * @param signature - Session signature.
352
+ * @param optimistic - Whether the request is optimistic.
353
+ * @returns A SessionResponse object.
354
+ * @throws {OpenfortError} If no signer is configured.
355
+ * @throws {OpenfortError} If the signer is not a SessionSigner.
356
+ */
108
357
  sendRegisterSessionRequest(sessionId: string, signature: string, optimistic?: boolean): Promise<SessionResponse$1>;
109
- private recoverSigner;
110
- private waitSigner;
358
+ /**
359
+ * Gets the embedded state of the current session.
360
+ *
361
+ * @returns The embedded state.
362
+ */
111
363
  getEmbeddedState(): EmbeddedState$1;
112
- private credentialsProvided;
113
- isAuthenticated(): Promise<boolean>;
364
+ /**
365
+ * Gets the current access token.
366
+ *
367
+ * @returns The access token, or null if not available.
368
+ */
114
369
  getAccessToken(): string | null;
115
- isLoaded(): boolean;
370
+ /**
371
+ * Retrieves the user details.
372
+ *
373
+ * @returns An AuthPlayerResponse object.
374
+ * @throws {OpenfortError} If no access token is found.
375
+ */
376
+ getUser(): Promise<AuthPlayerResponse$1>;
377
+ /**
378
+ * Validates and refreshes the access token if needed.
379
+ */
116
380
  validateAndRefreshToken(): Promise<void>;
381
+ private credentialsProvided;
382
+ private recoverSigner;
383
+ private waitSigner;
384
+ private newEmbeddedSigner;
385
+ private flushSigner;
386
+ }
387
+
388
+ declare enum OpenfortErrorType {
389
+ AUTHENTICATION_ERROR = "AUTHENTICATION_ERROR",
390
+ INVALID_CONFIGURATION = "INVALID_CONFIGURATION",
391
+ NOT_LOGGED_IN_ERROR = "NOT_LOGGED_IN_ERROR",
392
+ REFRESH_TOKEN_ERROR = "REFRESH_TOKEN_ERROR",
393
+ USER_REGISTRATION_ERROR = "USER_REGISTRATION_ERROR",
394
+ LOGOUT_ERROR = "LOGOUT_ERROR",
395
+ OPERATION_NOT_SUPPORTED_ERROR = "OPERATION_NOT_SUPPORTED_ERROR",
396
+ MISSING_SESSION_SIGNER_ERROR = "MISSING_SESSION_SIGNER_ERROR",
397
+ MISSING_EMBEDDED_SIGNER_ERROR = "MISSING_EMBEDDED_SIGNER_ERROR",
398
+ MISSING_SIGNER_ERROR = "MISSING_SIGNER_ERROR"
399
+ }
400
+ declare class OpenfortError extends Error {
401
+ type: OpenfortErrorType;
402
+ constructor(message: string, type: OpenfortErrorType);
117
403
  }
118
404
 
119
405
  declare enum ShieldAuthProvider {
@@ -138,6 +424,7 @@ declare enum EmbeddedState {
138
424
  READY = 4
139
425
  }
140
426
  type InitializeOAuthOptions = {
427
+ usePooling?: boolean;
141
428
  /** A URL to send the user to after they are confirmed. */
142
429
  redirectTo?: string;
143
430
  /** A space-separated list of scopes granted to the OAuth application. */
@@ -552,4 +839,4 @@ declare class SDKConfiguration {
552
839
  });
553
840
  }
554
841
 
555
- export { AuthPlayerResponse, AuthType, BasicAuthProvider, EmbeddedState, InitializeOAuthOptions, OAuthProvider, OpenfortConfiguration, Provider, SDKConfiguration, SDKOverrides, SessionResponse, ShieldAuthOptions, ShieldAuthentication, ShieldConfiguration, ShieldOptions, ThirdPartyOAuthProvider, TokenType, TransactionIntentResponse, TypedDataDomain, TypedDataField, Openfort as default };
842
+ export { AuthPlayerResponse, AuthType, BasicAuthProvider, EmbeddedState, InitializeOAuthOptions, OAuthProvider, OpenfortConfiguration, OpenfortError, Provider, SDKConfiguration, SDKOverrides, SessionResponse, ShieldAuthOptions, ShieldAuthentication, ShieldConfiguration, ShieldOptions, ThirdPartyOAuthProvider, TokenType, TransactionIntentResponse, TypedDataDomain, TypedDataField, Openfort as default };