@openfort/openfort-js 0.7.8 → 0.7.9
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 +168 -100
- package/dist/index.d.ts +442 -420
- package/dist/index.js +169 -101
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
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
|
-
import { SDKConfiguration as SDKConfiguration$1 } from 'config';
|
|
3
|
-
import { Provider as Provider$1 } from 'evm/types';
|
|
4
|
-
|
|
5
1
|
declare type Bytes = ArrayLike<number>;
|
|
6
2
|
declare type BytesLike = Bytes | string;
|
|
7
3
|
interface Hexable {
|
|
@@ -56,373 +52,35 @@ interface TypedDataField {
|
|
|
56
52
|
type: string;
|
|
57
53
|
}
|
|
58
54
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
declare enum EmbeddedState {
|
|
56
|
+
NONE = 0,
|
|
57
|
+
UNAUTHENTICATED = 1,
|
|
58
|
+
EMBEDDED_SIGNER_NOT_CONFIGURED = 2,
|
|
59
|
+
CREATING_ACCOUNT = 3,
|
|
60
|
+
READY = 4
|
|
64
61
|
}
|
|
62
|
+
type SessionKey = {
|
|
63
|
+
address: string;
|
|
64
|
+
isRegistered: boolean;
|
|
65
|
+
};
|
|
65
66
|
declare enum AuthType {
|
|
66
67
|
OPENFORT = "openfort",
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
declare class Openfort {
|
|
71
|
-
private signer?;
|
|
72
|
-
private readonly authManager;
|
|
73
|
-
private readonly config;
|
|
74
|
-
private readonly backendApiClients;
|
|
75
|
-
private readonly instanceManager;
|
|
76
|
-
private readonly iframeManager;
|
|
77
|
-
private readonly openfortEventEmitter;
|
|
78
|
-
constructor(sdkConfiguration: SDKConfiguration$1);
|
|
79
|
-
/**
|
|
80
|
-
* Logs the user out by flushing the signer and removing credentials.
|
|
81
|
-
*/
|
|
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
|
-
*/
|
|
90
|
-
getEthereumProvider(options?: {
|
|
91
|
-
announceProvider: boolean;
|
|
92
|
-
policy?: string;
|
|
93
|
-
}): Provider$1;
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
107
|
-
configureEmbeddedSigner(chainId?: number, shieldAuthentication?: ShieldAuthentication, recoveryPassword?: string): Promise<void>;
|
|
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
|
-
*/
|
|
243
|
-
poolOAuth(key: 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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
333
|
-
signMessage(message: string | Uint8Array, options?: {
|
|
334
|
-
hashMessage?: boolean;
|
|
335
|
-
arrayifyMessage?: boolean;
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
357
|
-
sendRegisterSessionRequest(sessionId: string, signature: string, optimistic?: boolean): Promise<SessionResponse$1>;
|
|
358
|
-
/**
|
|
359
|
-
* Gets the embedded state of the current session.
|
|
360
|
-
*
|
|
361
|
-
* @returns The embedded state.
|
|
362
|
-
*/
|
|
363
|
-
getEmbeddedState(): EmbeddedState$1;
|
|
364
|
-
/**
|
|
365
|
-
* Gets the current access token.
|
|
366
|
-
*
|
|
367
|
-
* @returns The access token, or null if not available.
|
|
368
|
-
*/
|
|
369
|
-
getAccessToken(): string | null;
|
|
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
|
-
*/
|
|
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);
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
declare enum ShieldAuthProvider {
|
|
406
|
-
OPENFORT = "openfort",
|
|
407
|
-
CUSTOM = "custom"
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
interface ShieldOptions {
|
|
411
|
-
baseURL?: string;
|
|
412
|
-
apiKey: string;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
interface ShieldAuthOptions {
|
|
416
|
-
authProvider: ShieldAuthProvider;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
declare enum EmbeddedState {
|
|
420
|
-
NONE = 0,
|
|
421
|
-
UNAUTHENTICATED = 1,
|
|
422
|
-
EMBEDDED_SIGNER_NOT_CONFIGURED = 2,
|
|
423
|
-
CREATING_ACCOUNT = 3,
|
|
424
|
-
READY = 4
|
|
68
|
+
THIRD_PARTY = "thirdParty"
|
|
425
69
|
}
|
|
70
|
+
type Auth = {
|
|
71
|
+
player?: string;
|
|
72
|
+
accessToken: string;
|
|
73
|
+
refreshToken: string;
|
|
74
|
+
};
|
|
75
|
+
type InitAuthResponse = {
|
|
76
|
+
url: string;
|
|
77
|
+
key: string;
|
|
78
|
+
};
|
|
79
|
+
type SIWEInitResponse = {
|
|
80
|
+
address: string;
|
|
81
|
+
nonce: string;
|
|
82
|
+
expiresAt: number;
|
|
83
|
+
};
|
|
426
84
|
type InitializeOAuthOptions = {
|
|
427
85
|
usePooling?: boolean;
|
|
428
86
|
/** A URL to send the user to after they are confirmed. */
|
|
@@ -664,58 +322,11 @@ interface AuthPlayerResponse {
|
|
|
664
322
|
'createdAt': number;
|
|
665
323
|
'linkedAccounts': Array<LinkedAccountResponse>;
|
|
666
324
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
* https://eips.ethereum.org/EIPS/eip-1474#error-codes
|
|
672
|
-
*/
|
|
673
|
-
declare enum ProviderErrorCode {
|
|
674
|
-
USER_REJECTED_REQUEST = 4001,
|
|
675
|
-
UNAUTHORIZED = 4100,
|
|
676
|
-
UNSUPPORTED_METHOD = 4200,
|
|
677
|
-
DISCONNECTED = 4900
|
|
678
|
-
}
|
|
679
|
-
declare enum RpcErrorCode {
|
|
680
|
-
RPC_SERVER_ERROR = -32000,
|
|
681
|
-
INVALID_REQUEST = -32600,
|
|
682
|
-
METHOD_NOT_FOUND = -32601,
|
|
683
|
-
INVALID_PARAMS = -32602,
|
|
684
|
-
INTERNAL_ERROR = -32603,
|
|
685
|
-
PARSE_ERROR = -32700,
|
|
686
|
-
TRANSACTION_REJECTED = -32003
|
|
687
|
-
}
|
|
688
|
-
declare class JsonRpcError extends Error {
|
|
689
|
-
readonly message: string;
|
|
690
|
-
readonly code: ProviderErrorCode | RpcErrorCode;
|
|
691
|
-
constructor(code: ProviderErrorCode | RpcErrorCode, message: string);
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
interface RequestArguments {
|
|
695
|
-
method: string;
|
|
696
|
-
params?: Array<any>;
|
|
697
|
-
}
|
|
698
|
-
type JsonRpcRequestPayload = RequestArguments & {
|
|
699
|
-
jsonrpc?: string;
|
|
700
|
-
id?: string | number;
|
|
701
|
-
};
|
|
702
|
-
interface JsonRpcRequestCallback {
|
|
703
|
-
(err: JsonRpcError | null, result?: JsonRpcResponsePayload | (JsonRpcResponsePayload | null)[] | null): void;
|
|
704
|
-
}
|
|
705
|
-
interface JsonRpcResponsePayload {
|
|
706
|
-
result?: Array<any> | null;
|
|
707
|
-
error?: JsonRpcError | null;
|
|
708
|
-
jsonrpc?: string;
|
|
709
|
-
id?: string | number;
|
|
325
|
+
interface AuthResponse {
|
|
326
|
+
'player': AuthPlayerResponse;
|
|
327
|
+
'token': string;
|
|
328
|
+
'refreshToken': string;
|
|
710
329
|
}
|
|
711
|
-
type Provider = {
|
|
712
|
-
request: (request: RequestArguments) => Promise<any>;
|
|
713
|
-
sendAsync: (request: JsonRpcRequestPayload | JsonRpcRequestPayload[], callback: JsonRpcRequestCallback) => void;
|
|
714
|
-
send: (request: string | JsonRpcRequestPayload | JsonRpcRequestPayload[], callbackOrParams?: JsonRpcRequestCallback | Array<any>, callback?: JsonRpcRequestCallback) => void;
|
|
715
|
-
on: (event: string, listener: (...args: any[]) => void) => void;
|
|
716
|
-
removeListener: (event: string, listener: (...args: any[]) => void) => void;
|
|
717
|
-
isOpenfort: boolean;
|
|
718
|
-
};
|
|
719
330
|
|
|
720
331
|
/**
|
|
721
332
|
* Openfort API
|
|
@@ -835,8 +446,419 @@ declare class SDKConfiguration {
|
|
|
835
446
|
constructor({ baseConfiguration, shieldConfiguration, overrides, }: {
|
|
836
447
|
baseConfiguration: OpenfortConfiguration;
|
|
837
448
|
shieldConfiguration?: ShieldConfiguration;
|
|
838
|
-
overrides?: SDKOverrides
|
|
449
|
+
overrides?: SDKOverrides;
|
|
839
450
|
});
|
|
840
451
|
}
|
|
841
452
|
|
|
842
|
-
|
|
453
|
+
/**
|
|
454
|
+
* ProviderErrors should take priority over RpcErrorCodes
|
|
455
|
+
* https://eips.ethereum.org/EIPS/eip-1193#provider-errors
|
|
456
|
+
* https://eips.ethereum.org/EIPS/eip-1474#error-codes
|
|
457
|
+
*/
|
|
458
|
+
declare enum ProviderErrorCode {
|
|
459
|
+
USER_REJECTED_REQUEST = 4001,
|
|
460
|
+
UNAUTHORIZED = 4100,
|
|
461
|
+
UNSUPPORTED_METHOD = 4200,
|
|
462
|
+
DISCONNECTED = 4900
|
|
463
|
+
}
|
|
464
|
+
declare enum RpcErrorCode {
|
|
465
|
+
RPC_SERVER_ERROR = -32000,
|
|
466
|
+
INVALID_REQUEST = -32600,
|
|
467
|
+
METHOD_NOT_FOUND = -32601,
|
|
468
|
+
INVALID_PARAMS = -32602,
|
|
469
|
+
INTERNAL_ERROR = -32603,
|
|
470
|
+
PARSE_ERROR = -32700,
|
|
471
|
+
TRANSACTION_REJECTED = -32003
|
|
472
|
+
}
|
|
473
|
+
declare class JsonRpcError extends Error {
|
|
474
|
+
readonly message: string;
|
|
475
|
+
readonly code: ProviderErrorCode | RpcErrorCode;
|
|
476
|
+
constructor(code: ProviderErrorCode | RpcErrorCode, message: string);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
interface RequestArguments {
|
|
480
|
+
method: string;
|
|
481
|
+
params?: Array<any>;
|
|
482
|
+
}
|
|
483
|
+
type JsonRpcRequestPayload = RequestArguments & {
|
|
484
|
+
jsonrpc?: string;
|
|
485
|
+
id?: string | number;
|
|
486
|
+
};
|
|
487
|
+
interface JsonRpcRequestCallback {
|
|
488
|
+
(err: JsonRpcError | null, result?: JsonRpcResponsePayload | (JsonRpcResponsePayload | null)[] | null): void;
|
|
489
|
+
}
|
|
490
|
+
interface JsonRpcResponsePayload {
|
|
491
|
+
result?: Array<any> | null;
|
|
492
|
+
error?: JsonRpcError | null;
|
|
493
|
+
jsonrpc?: string;
|
|
494
|
+
id?: string | number;
|
|
495
|
+
}
|
|
496
|
+
type Provider = {
|
|
497
|
+
request: (request: RequestArguments) => Promise<any>;
|
|
498
|
+
sendAsync: (request: JsonRpcRequestPayload | JsonRpcRequestPayload[], callback: JsonRpcRequestCallback) => void;
|
|
499
|
+
send: (request: string | JsonRpcRequestPayload | JsonRpcRequestPayload[], callbackOrParams?: JsonRpcRequestCallback | Array<any>, callback?: JsonRpcRequestCallback) => void;
|
|
500
|
+
on: (event: string, listener: (...args: any[]) => void) => void;
|
|
501
|
+
removeListener: (event: string, listener: (...args: any[]) => void) => void;
|
|
502
|
+
isOpenfort: boolean;
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
interface ShieldAuthentication {
|
|
506
|
+
auth: ShieldAuthType;
|
|
507
|
+
token: string;
|
|
508
|
+
authProvider?: string;
|
|
509
|
+
tokenType?: string;
|
|
510
|
+
}
|
|
511
|
+
declare enum ShieldAuthType {
|
|
512
|
+
OPENFORT = "openfort",
|
|
513
|
+
CUSTOM = "custom"
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
declare class Openfort {
|
|
517
|
+
private signer?;
|
|
518
|
+
private readonly authManager;
|
|
519
|
+
private readonly config;
|
|
520
|
+
private readonly backendApiClients;
|
|
521
|
+
private readonly instanceManager;
|
|
522
|
+
private readonly iframeManager;
|
|
523
|
+
private readonly openfortEventEmitter;
|
|
524
|
+
constructor(sdkConfiguration: SDKConfiguration);
|
|
525
|
+
/**
|
|
526
|
+
* Logs the user out by flushing the signer and removing credentials.
|
|
527
|
+
*/
|
|
528
|
+
logout(): Promise<void>;
|
|
529
|
+
/**
|
|
530
|
+
* Returns an Ethereum provider using the configured signer.
|
|
531
|
+
*
|
|
532
|
+
* @param options - Configuration options for the Ethereum provider.
|
|
533
|
+
* @returns A Provider instance.
|
|
534
|
+
* @throws {OpenfortError} If the signer is not an EmbeddedSigner.
|
|
535
|
+
*/
|
|
536
|
+
getEthereumProvider(options?: {
|
|
537
|
+
announceProvider: boolean;
|
|
538
|
+
policy?: string;
|
|
539
|
+
}): Provider;
|
|
540
|
+
/**
|
|
541
|
+
* Configures a session key and returns the session key details.
|
|
542
|
+
*
|
|
543
|
+
* @returns A SessionKey object containing the address and registration status.
|
|
544
|
+
*/
|
|
545
|
+
configureSessionKey(): SessionKey;
|
|
546
|
+
/**
|
|
547
|
+
* Configures an embedded signer.
|
|
548
|
+
*
|
|
549
|
+
* @param chainId - The chain ID for the embedded signer.
|
|
550
|
+
* @param shieldAuthentication - Shield authentication details.
|
|
551
|
+
* @param recoveryPassword - Recovery password.
|
|
552
|
+
*/
|
|
553
|
+
configureEmbeddedSigner(chainId?: number, shieldAuthentication?: ShieldAuthentication, recoveryPassword?: string): Promise<void>;
|
|
554
|
+
/**
|
|
555
|
+
* Logs in a user with email and password.
|
|
556
|
+
*
|
|
557
|
+
* @param email - User's email.
|
|
558
|
+
* @param password - User's password.
|
|
559
|
+
* @returns An AuthResponse object containing authentication details.
|
|
560
|
+
*/
|
|
561
|
+
logInWithEmailPassword({ email, password }: {
|
|
562
|
+
email: string;
|
|
563
|
+
password: string;
|
|
564
|
+
}): Promise<AuthResponse>;
|
|
565
|
+
/**
|
|
566
|
+
* Signs up a new user with email and password.
|
|
567
|
+
*
|
|
568
|
+
* @param email - User's email.
|
|
569
|
+
* @param password - User's password.
|
|
570
|
+
* @param options - Additional options for the sign-up process.
|
|
571
|
+
* @returns An AuthResponse object containing authentication details.
|
|
572
|
+
*/
|
|
573
|
+
signUpWithEmailPassword({ email, password, options }: {
|
|
574
|
+
email: string;
|
|
575
|
+
password: string;
|
|
576
|
+
options?: {
|
|
577
|
+
data: {
|
|
578
|
+
name: string;
|
|
579
|
+
};
|
|
580
|
+
};
|
|
581
|
+
}): Promise<AuthResponse>;
|
|
582
|
+
/**
|
|
583
|
+
* Links an email and password to an existing account using an authentication token.
|
|
584
|
+
*
|
|
585
|
+
* @param email - User's email.
|
|
586
|
+
* @param password - User's password.
|
|
587
|
+
* @param authToken - Authentication token.
|
|
588
|
+
* @returns An AuthPlayerResponse object.
|
|
589
|
+
*/
|
|
590
|
+
linkEmailPassword({ email, password, authToken }: {
|
|
591
|
+
email: string;
|
|
592
|
+
password: string;
|
|
593
|
+
authToken: string;
|
|
594
|
+
}): Promise<AuthPlayerResponse>;
|
|
595
|
+
/**
|
|
596
|
+
* Unlinks an email and password from an existing account using an authentication token.
|
|
597
|
+
*
|
|
598
|
+
* @param email - User's email.
|
|
599
|
+
* @param authToken - Authentication token.
|
|
600
|
+
* @returns An AuthPlayerResponse object.
|
|
601
|
+
*/
|
|
602
|
+
unlinkEmailPassword({ email, authToken }: {
|
|
603
|
+
email: string;
|
|
604
|
+
authToken: string;
|
|
605
|
+
}): Promise<AuthPlayerResponse>;
|
|
606
|
+
/**
|
|
607
|
+
* Requests an email verification link.
|
|
608
|
+
*
|
|
609
|
+
* @param email - User's email.
|
|
610
|
+
* @param redirectUrl - Redirect URL after verification.
|
|
611
|
+
*/
|
|
612
|
+
requestEmailVerification({ email, redirectUrl }: {
|
|
613
|
+
email: string;
|
|
614
|
+
redirectUrl: string;
|
|
615
|
+
}): Promise<void>;
|
|
616
|
+
/**
|
|
617
|
+
* Resets the user's password.
|
|
618
|
+
*
|
|
619
|
+
* @param email - User's email.
|
|
620
|
+
* @param password - New password.
|
|
621
|
+
* @param state - Verification state.
|
|
622
|
+
*/
|
|
623
|
+
resetPassword({ email, password, state }: {
|
|
624
|
+
email: string;
|
|
625
|
+
password: string;
|
|
626
|
+
state: string;
|
|
627
|
+
}): Promise<void>;
|
|
628
|
+
/**
|
|
629
|
+
* Requests a password reset link.
|
|
630
|
+
*
|
|
631
|
+
* @param email - User's email.
|
|
632
|
+
* @param redirectUrl - Redirect URL after resetting password.
|
|
633
|
+
*/
|
|
634
|
+
requestResetPassword({ email, redirectUrl }: {
|
|
635
|
+
email: string;
|
|
636
|
+
redirectUrl: string;
|
|
637
|
+
}): Promise<void>;
|
|
638
|
+
/**
|
|
639
|
+
* Verifies the user's email.
|
|
640
|
+
*
|
|
641
|
+
* @param email - User's email.
|
|
642
|
+
* @param state - Verification state.
|
|
643
|
+
*/
|
|
644
|
+
verifyEmail({ email, state }: {
|
|
645
|
+
email: string;
|
|
646
|
+
state: string;
|
|
647
|
+
}): Promise<void>;
|
|
648
|
+
/**
|
|
649
|
+
* Initializes an OAuth authentication process.
|
|
650
|
+
*
|
|
651
|
+
* @param provider - OAuth provider.
|
|
652
|
+
* @param options - Additional options for initialization.
|
|
653
|
+
* @returns An InitAuthResponse object.
|
|
654
|
+
*/
|
|
655
|
+
initOAuth({ provider, options }: {
|
|
656
|
+
provider: OAuthProvider;
|
|
657
|
+
options?: InitializeOAuthOptions;
|
|
658
|
+
}): Promise<InitAuthResponse>;
|
|
659
|
+
/**
|
|
660
|
+
* Initializes an OAuth linking process.
|
|
661
|
+
*
|
|
662
|
+
* @param provider - OAuth provider.
|
|
663
|
+
* @param authToken - Authentication token.
|
|
664
|
+
* @param options - Additional options for initialization.
|
|
665
|
+
* @returns An InitAuthResponse object.
|
|
666
|
+
*/
|
|
667
|
+
initLinkOAuth({ provider, authToken, options }: {
|
|
668
|
+
provider: OAuthProvider;
|
|
669
|
+
authToken: string;
|
|
670
|
+
options?: InitializeOAuthOptions;
|
|
671
|
+
}): Promise<InitAuthResponse>;
|
|
672
|
+
/**
|
|
673
|
+
* Unlinks an OAuth provider from the account.
|
|
674
|
+
*
|
|
675
|
+
* @param provider - OAuth provider.
|
|
676
|
+
* @param authToken - Authentication token.
|
|
677
|
+
* @returns An AuthPlayerResponse object.
|
|
678
|
+
*/
|
|
679
|
+
unlinkOAuth({ provider, authToken }: {
|
|
680
|
+
provider: OAuthProvider;
|
|
681
|
+
authToken: string;
|
|
682
|
+
}): Promise<AuthPlayerResponse>;
|
|
683
|
+
/**
|
|
684
|
+
* Polls for OAuth authentication completion.
|
|
685
|
+
*
|
|
686
|
+
* @param key - OAuth polling key.
|
|
687
|
+
* @returns An AuthResponse object.
|
|
688
|
+
*/
|
|
689
|
+
poolOAuth(key: string): Promise<AuthResponse>;
|
|
690
|
+
/**
|
|
691
|
+
* Authenticates using a third-party OAuth provider.
|
|
692
|
+
*
|
|
693
|
+
* @param provider - Third-party OAuth provider.
|
|
694
|
+
* @param token - OAuth token.
|
|
695
|
+
* @param tokenType - Type of the OAuth token.
|
|
696
|
+
* @returns An AuthPlayerResponse object.
|
|
697
|
+
*/
|
|
698
|
+
authenticateWithThirdPartyProvider({ provider, token, tokenType }: {
|
|
699
|
+
provider: ThirdPartyOAuthProvider;
|
|
700
|
+
token: string;
|
|
701
|
+
tokenType: TokenType;
|
|
702
|
+
}): Promise<AuthPlayerResponse>;
|
|
703
|
+
/**
|
|
704
|
+
* Initializes Sign-In with Ethereum (SIWE).
|
|
705
|
+
*
|
|
706
|
+
* @param address - Ethereum address.
|
|
707
|
+
* @returns A SIWEInitResponse object.
|
|
708
|
+
*/
|
|
709
|
+
initSIWE({ address }: {
|
|
710
|
+
address: string;
|
|
711
|
+
}): Promise<SIWEInitResponse>;
|
|
712
|
+
/**
|
|
713
|
+
* Authenticates using Sign-In with Ethereum (SIWE).
|
|
714
|
+
*
|
|
715
|
+
* @param signature - SIWE signature.
|
|
716
|
+
* @param message - SIWE message.
|
|
717
|
+
* @param walletClientType - Wallet client type.
|
|
718
|
+
* @param connectorType - Connector type.
|
|
719
|
+
* @returns An AuthResponse object.
|
|
720
|
+
*/
|
|
721
|
+
authenticateWithSIWE({ signature, message, walletClientType, connectorType, }: {
|
|
722
|
+
signature: string;
|
|
723
|
+
message: string;
|
|
724
|
+
walletClientType: string;
|
|
725
|
+
connectorType: string;
|
|
726
|
+
}): Promise<AuthResponse>;
|
|
727
|
+
/**
|
|
728
|
+
* Links a wallet using SIWE.
|
|
729
|
+
*
|
|
730
|
+
* @param signature - SIWE signature.
|
|
731
|
+
* @param message - SIWE message.
|
|
732
|
+
* @param walletClientType - Wallet client type.
|
|
733
|
+
* @param connectorType - Connector type.
|
|
734
|
+
* @param authToken - Authentication token.
|
|
735
|
+
* @returns An AuthPlayerResponse object.
|
|
736
|
+
*/
|
|
737
|
+
linkWallet({ signature, message, walletClientType, connectorType, authToken, }: {
|
|
738
|
+
signature: string;
|
|
739
|
+
message: string;
|
|
740
|
+
walletClientType: string;
|
|
741
|
+
connectorType: string;
|
|
742
|
+
authToken: string;
|
|
743
|
+
}): Promise<AuthPlayerResponse>;
|
|
744
|
+
/**
|
|
745
|
+
* Unlinks a wallet.
|
|
746
|
+
*
|
|
747
|
+
* @param address - Wallet address.
|
|
748
|
+
* @param authToken - Authentication token.
|
|
749
|
+
* @returns An AuthPlayerResponse object.
|
|
750
|
+
*/
|
|
751
|
+
unlinkWallet({ address, authToken }: {
|
|
752
|
+
address: string;
|
|
753
|
+
authToken: string;
|
|
754
|
+
}): Promise<AuthPlayerResponse>;
|
|
755
|
+
/**
|
|
756
|
+
* Stores authentication credentials.
|
|
757
|
+
*
|
|
758
|
+
* @param auth - Authentication details.
|
|
759
|
+
*/
|
|
760
|
+
storeCredentials(auth: Auth): void;
|
|
761
|
+
/**
|
|
762
|
+
* Sends a signature transaction intent request.
|
|
763
|
+
*
|
|
764
|
+
* @param transactionIntentId - Transaction intent ID.
|
|
765
|
+
* @param userOperationHash - User operation hash.
|
|
766
|
+
* @param signature - Transaction signature.
|
|
767
|
+
* @param optimistic - Whether the request is optimistic.
|
|
768
|
+
* @returns A TransactionIntentResponse object.
|
|
769
|
+
* @throws {OpenfortError} If no userOperationHash or signature is provided.
|
|
770
|
+
*/
|
|
771
|
+
sendSignatureTransactionIntentRequest(transactionIntentId: string, userOperationHash?: string | null, signature?: string | null, optimistic?: boolean): Promise<TransactionIntentResponse>;
|
|
772
|
+
/**
|
|
773
|
+
* Signs a message.
|
|
774
|
+
*
|
|
775
|
+
* @param message - Message to sign.
|
|
776
|
+
* @param options - Additional options for signing.
|
|
777
|
+
* @returns The signature.
|
|
778
|
+
* @throws {OpenfortError} If no signer is configured.
|
|
779
|
+
*/
|
|
780
|
+
signMessage(message: string | Uint8Array, options?: {
|
|
781
|
+
hashMessage?: boolean;
|
|
782
|
+
arrayifyMessage?: boolean;
|
|
783
|
+
}): Promise<string>;
|
|
784
|
+
/**
|
|
785
|
+
* Signs typed data.
|
|
786
|
+
*
|
|
787
|
+
* @param domain - EIP-712 domain.
|
|
788
|
+
* @param types - Typed data types.
|
|
789
|
+
* @param value - Typed data value.
|
|
790
|
+
* @returns The signature.
|
|
791
|
+
* @throws {OpenfortError} If no signer is configured.
|
|
792
|
+
*/
|
|
793
|
+
signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): Promise<string>;
|
|
794
|
+
/**
|
|
795
|
+
* Sends a session registration request.
|
|
796
|
+
*
|
|
797
|
+
* @param sessionId - Session ID.
|
|
798
|
+
* @param signature - Session signature.
|
|
799
|
+
* @param optimistic - Whether the request is optimistic.
|
|
800
|
+
* @returns A SessionResponse object.
|
|
801
|
+
*/
|
|
802
|
+
sendRegisterSessionRequest(sessionId: string, signature: string, optimistic?: boolean): Promise<SessionResponse>;
|
|
803
|
+
/**
|
|
804
|
+
* Gets the embedded state of the current session.
|
|
805
|
+
*
|
|
806
|
+
* @returns The embedded state.
|
|
807
|
+
*/
|
|
808
|
+
getEmbeddedState(): EmbeddedState;
|
|
809
|
+
/**
|
|
810
|
+
* Gets the current access token.
|
|
811
|
+
*
|
|
812
|
+
* @returns The access token, or null if not available.
|
|
813
|
+
*/
|
|
814
|
+
getAccessToken(): string | null;
|
|
815
|
+
/**
|
|
816
|
+
* Retrieves the user details.
|
|
817
|
+
*
|
|
818
|
+
* @returns An AuthPlayerResponse object.
|
|
819
|
+
* @throws {OpenfortError} If no access token is found.
|
|
820
|
+
*/
|
|
821
|
+
getUser(): Promise<AuthPlayerResponse>;
|
|
822
|
+
/**
|
|
823
|
+
* Validates and refreshes the access token if needed.
|
|
824
|
+
*/
|
|
825
|
+
validateAndRefreshToken(): Promise<void>;
|
|
826
|
+
private credentialsProvided;
|
|
827
|
+
private recoverSigner;
|
|
828
|
+
private waitSigner;
|
|
829
|
+
private newEmbeddedSigner;
|
|
830
|
+
private flushSigner;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
declare enum OpenfortErrorType {
|
|
834
|
+
AUTHENTICATION_ERROR = "AUTHENTICATION_ERROR",
|
|
835
|
+
INVALID_CONFIGURATION = "INVALID_CONFIGURATION",
|
|
836
|
+
NOT_LOGGED_IN_ERROR = "NOT_LOGGED_IN_ERROR",
|
|
837
|
+
REFRESH_TOKEN_ERROR = "REFRESH_TOKEN_ERROR",
|
|
838
|
+
USER_REGISTRATION_ERROR = "USER_REGISTRATION_ERROR",
|
|
839
|
+
LOGOUT_ERROR = "LOGOUT_ERROR",
|
|
840
|
+
OPERATION_NOT_SUPPORTED_ERROR = "OPERATION_NOT_SUPPORTED_ERROR",
|
|
841
|
+
MISSING_SESSION_SIGNER_ERROR = "MISSING_SESSION_SIGNER_ERROR",
|
|
842
|
+
MISSING_EMBEDDED_SIGNER_ERROR = "MISSING_EMBEDDED_SIGNER_ERROR",
|
|
843
|
+
MISSING_SIGNER_ERROR = "MISSING_SIGNER_ERROR"
|
|
844
|
+
}
|
|
845
|
+
declare class OpenfortError extends Error {
|
|
846
|
+
type: OpenfortErrorType;
|
|
847
|
+
constructor(message: string, type: OpenfortErrorType);
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
declare enum ShieldAuthProvider {
|
|
851
|
+
OPENFORT = "openfort",
|
|
852
|
+
CUSTOM = "custom"
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
interface ShieldOptions {
|
|
856
|
+
baseURL?: string;
|
|
857
|
+
apiKey: string;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
interface ShieldAuthOptions {
|
|
861
|
+
authProvider: ShieldAuthProvider;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
export { AuthPlayerResponse, AuthType, BasicAuthProvider, EmbeddedState, InitializeOAuthOptions, OAuthProvider, OpenfortConfiguration, OpenfortError, Provider, SDKConfiguration, SDKOverrides, SessionResponse, ShieldAuthOptions, ShieldAuthType, ShieldAuthentication, ShieldConfiguration, ShieldOptions, ThirdPartyOAuthProvider, TokenType, TransactionIntentResponse, TypedDataDomain, TypedDataField, Openfort as default };
|