@fourt/sdk 1.1.7 → 1.2.1
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 +259 -120
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +81 -40
- package/dist/index.d.ts +81 -40
- package/dist/index.js +261 -122
- package/dist/index.js.map +1 -1
- package/package.json +18 -19
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { getWebAuthnAttestation, TSignedRequest, TurnkeyClient } from '@turnkey/
|
|
|
3
3
|
import * as viem_account_abstraction from 'viem/account-abstraction';
|
|
4
4
|
import { Hex } from '../types/misc.js';
|
|
5
5
|
import * as viem from 'viem';
|
|
6
|
-
import { LocalAccount, Client, SignableMessage, Hex as Hex$1, TypedData, TypedDataDefinition, SerializeTransactionFn, TransactionSerializable, IsNarrowable, TransactionSerialized, GetTransactionType } from 'viem';
|
|
6
|
+
import { LocalAccount, Client, Transport, Chain, JsonRpcAccount, SignableMessage, Hex as Hex$1, TypedData, TypedDataDefinition, SerializeTransactionFn, TransactionSerializable, IsNarrowable, TransactionSerialized, GetTransactionType } from 'viem';
|
|
7
7
|
import { toLightSmartAccount } from 'permissionless/accounts';
|
|
8
8
|
|
|
9
9
|
declare enum SessionType {
|
|
@@ -16,9 +16,6 @@ declare enum SessionType {
|
|
|
16
16
|
*/
|
|
17
17
|
declare class SessionStore {
|
|
18
18
|
private readonly _store;
|
|
19
|
-
/**
|
|
20
|
-
* Initializes a new instance of the `SessionStore` class by creating a new `zustand`store with the initial state.
|
|
21
|
-
*/
|
|
22
19
|
constructor();
|
|
23
20
|
/**
|
|
24
21
|
* Gets the type from the session state.
|
|
@@ -44,6 +41,18 @@ declare class SessionStore {
|
|
|
44
41
|
* @param {string} token the token to set.
|
|
45
42
|
*/
|
|
46
43
|
set token(token: string);
|
|
44
|
+
/**
|
|
45
|
+
* Gets the CSRF token from the session state.
|
|
46
|
+
*
|
|
47
|
+
* @returns {string | undefined} the CSRF token.
|
|
48
|
+
*/
|
|
49
|
+
get csrfToken(): string | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Sets the CSRF token in the session state.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} csrfToken the CSRF token to set.
|
|
54
|
+
*/
|
|
55
|
+
set csrfToken(csrfToken: string);
|
|
47
56
|
/**
|
|
48
57
|
* Gets the bundle from the session state.
|
|
49
58
|
*
|
|
@@ -128,7 +137,8 @@ type AuthenticationServiceEndpoints = [
|
|
|
128
137
|
};
|
|
129
138
|
Response: {
|
|
130
139
|
user: User;
|
|
131
|
-
token
|
|
140
|
+
token?: string;
|
|
141
|
+
csrfToken?: string;
|
|
132
142
|
};
|
|
133
143
|
},
|
|
134
144
|
{
|
|
@@ -148,6 +158,7 @@ type AuthenticationServiceEndpoints = [
|
|
|
148
158
|
Response: {
|
|
149
159
|
user: User;
|
|
150
160
|
token: string;
|
|
161
|
+
csrfToken: string;
|
|
151
162
|
};
|
|
152
163
|
},
|
|
153
164
|
{
|
|
@@ -160,13 +171,38 @@ type AuthenticationServiceEndpoints = [
|
|
|
160
171
|
};
|
|
161
172
|
},
|
|
162
173
|
{
|
|
163
|
-
Route: 'v1/oauth/init';
|
|
174
|
+
Route: '/v1/oauth/init';
|
|
164
175
|
Body: {
|
|
165
176
|
provider: string;
|
|
166
177
|
};
|
|
167
178
|
Response: {
|
|
168
179
|
url: string;
|
|
169
180
|
};
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
Route: '/v1/refresh';
|
|
184
|
+
Body: {};
|
|
185
|
+
Response: {
|
|
186
|
+
token: string;
|
|
187
|
+
csrfToken: string;
|
|
188
|
+
};
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
Route: '/v1/csrf-token';
|
|
192
|
+
Body: {};
|
|
193
|
+
Response: {
|
|
194
|
+
csrfToken: string;
|
|
195
|
+
};
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
Route: '/v1/logout';
|
|
199
|
+
Body: {};
|
|
200
|
+
Response: {};
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
Route: '/v1/me';
|
|
204
|
+
Body: {};
|
|
205
|
+
Response: User;
|
|
170
206
|
}
|
|
171
207
|
];
|
|
172
208
|
|
|
@@ -184,20 +220,23 @@ declare abstract class SignerClient {
|
|
|
184
220
|
protected readonly _turnkeyClient: TurnkeyClient;
|
|
185
221
|
protected readonly _configuration: Required<SignerClientConstructorParams['configuration']>;
|
|
186
222
|
protected readonly _sessionStore: SessionStore;
|
|
187
|
-
private
|
|
223
|
+
private _refreshPromise?;
|
|
224
|
+
private _refreshTimer?;
|
|
188
225
|
constructor({ stamper, configuration: { apiUrl, paymasterRpcUrl, ...requiredConfiguration }, }: SignerClientConstructorParams);
|
|
189
|
-
logout(): void;
|
|
190
226
|
get configuration(): Required<SignerClientConfiguration>;
|
|
191
|
-
|
|
192
|
-
|
|
227
|
+
getUser(): Promise<User>;
|
|
228
|
+
isLoggedIn(): Promise<boolean>;
|
|
229
|
+
getToken(): Promise<string>;
|
|
230
|
+
private _isTokenExpired;
|
|
231
|
+
logout(): Promise<void>;
|
|
232
|
+
signRawMessage<Into extends string>(msg: string): Promise<Into>;
|
|
193
233
|
protected set stamper(stamper: TurnkeyClient['stamper']);
|
|
194
234
|
protected get stamper(): TurnkeyClient['stamper'];
|
|
195
|
-
protected get sessionStore(): SessionStore;
|
|
196
|
-
signRawMessage<Into extends string>(msg: string): Promise<Into>;
|
|
197
|
-
getToken(): string | undefined;
|
|
198
235
|
protected lookUpUser(email: string): Promise<string | null>;
|
|
199
236
|
protected whoAmI(subOrgId?: string): Promise<void>;
|
|
200
237
|
protected request<Route extends AuthenticationServiceRoutes>(route: Route, body?: AuthenticationServiceBody<Route>): Promise<AuthenticationServiceResponse<Route>>;
|
|
238
|
+
protected _scheduleRefresh(token: string): void;
|
|
239
|
+
private _refreshToken;
|
|
201
240
|
}
|
|
202
241
|
|
|
203
242
|
type WebauthnSignInParams = {
|
|
@@ -246,13 +285,14 @@ declare class WebSignerClient extends SignerClient {
|
|
|
246
285
|
* @param {WebSignerClientConstructorParams} params params for the constructor
|
|
247
286
|
*/
|
|
248
287
|
constructor({ configuration, webauthn, iframe, oauth, }: WebSignerClientConstructorParams);
|
|
249
|
-
signRawMessage<Into extends string>(msg: string): Promise<Into>;
|
|
250
288
|
logout(): Promise<void>;
|
|
289
|
+
signRawMessage<Into extends string>(msg: string): Promise<Into>;
|
|
251
290
|
/**
|
|
252
|
-
*
|
|
291
|
+
* Get the pre-filled URL for initiating oauth with a specific provider.
|
|
253
292
|
*
|
|
293
|
+
* @param {string} provider provider for which we are getting the URL, currently google or apple
|
|
254
294
|
*/
|
|
255
|
-
|
|
295
|
+
getOAuthInitUrl(provider: string): Promise<string>;
|
|
256
296
|
/**
|
|
257
297
|
* Signs in a user with webauthn.
|
|
258
298
|
*
|
|
@@ -266,18 +306,22 @@ declare class WebSignerClient extends SignerClient {
|
|
|
266
306
|
*/
|
|
267
307
|
emailAuth(params: EmailInitializeAuthParams): Promise<void>;
|
|
268
308
|
getIframePublicKey(): Promise<string>;
|
|
269
|
-
/**
|
|
270
|
-
* Signs in a user with email.
|
|
271
|
-
*
|
|
272
|
-
* @param {EmailInitializeAuthParams} params params for the sign in
|
|
273
|
-
*/
|
|
274
|
-
private _signInWithEmail;
|
|
275
309
|
/**
|
|
276
310
|
* Completes the authentication process with a credential bundle.
|
|
277
311
|
*
|
|
278
312
|
* @param {CompleteAuthWithBundleParams} params params for the completion of the auth process
|
|
279
313
|
*/
|
|
280
314
|
completeAuthWithBundle({ bundle, subOrgId, sessionType, }: CompleteAuthWithBundleParams): Promise<void>;
|
|
315
|
+
/**
|
|
316
|
+
* Checks for an existing session and if exists, updates the stamper accordingly.
|
|
317
|
+
*/
|
|
318
|
+
private _updateStamper;
|
|
319
|
+
/**
|
|
320
|
+
* Signs in a user with email.
|
|
321
|
+
*
|
|
322
|
+
* @param {EmailInitializeAuthParams} params params for the sign in
|
|
323
|
+
*/
|
|
324
|
+
private _signInWithEmail;
|
|
281
325
|
/**
|
|
282
326
|
* Creates a passkey account using the webauthn stamper.
|
|
283
327
|
*
|
|
@@ -298,12 +342,6 @@ declare class WebSignerClient extends SignerClient {
|
|
|
298
342
|
private _createAccount;
|
|
299
343
|
private _webauthnGenerateAttestation;
|
|
300
344
|
private _initIframeStamper;
|
|
301
|
-
/**
|
|
302
|
-
* Get the pre-filled URL for initiating oauth with a specific provider.
|
|
303
|
-
*
|
|
304
|
-
* @param {string} provider provider for which we are getting the URL, currently google or apple
|
|
305
|
-
*/
|
|
306
|
-
getOAuthInitUrl(provider: string): Promise<string>;
|
|
307
345
|
}
|
|
308
346
|
|
|
309
347
|
/**
|
|
@@ -426,20 +464,21 @@ declare class UserModule {
|
|
|
426
464
|
*/
|
|
427
465
|
constructor(_webSignerClient: WebSignerClient);
|
|
428
466
|
/**
|
|
429
|
-
*
|
|
430
|
-
*
|
|
431
|
-
* @returns {User | undefined} user information.
|
|
467
|
+
* Retrieves information for the authenticated user.
|
|
468
|
+
* Assumes a user is already logged in, otherwise it will throw an error.
|
|
432
469
|
*/
|
|
433
|
-
|
|
434
|
-
/**
|
|
435
|
-
*
|
|
436
|
-
* @returns {string | undefined} user token.
|
|
470
|
+
getInfo(): Promise<User>;
|
|
471
|
+
/**
|
|
472
|
+
* Checks if a user is currently logged in to the fourt.io SDK.
|
|
437
473
|
*/
|
|
438
|
-
|
|
474
|
+
isLoggedIn(): Promise<boolean>;
|
|
475
|
+
/**
|
|
476
|
+
* Generates an access token with a lifespan of 15 minutes.
|
|
477
|
+
* Assumes a user is already logged in, otherwise it will throw an error.
|
|
478
|
+
*/
|
|
479
|
+
getToken(): Promise<string>;
|
|
439
480
|
/**
|
|
440
481
|
* Logs out the user.
|
|
441
|
-
*
|
|
442
|
-
* @returns {void}
|
|
443
482
|
*/
|
|
444
483
|
logout(): Promise<void>;
|
|
445
484
|
}
|
|
@@ -448,7 +487,7 @@ type CcipRequestReturnType = Hex;
|
|
|
448
487
|
|
|
449
488
|
type CurrentUserToLightSmartAccountParams = {
|
|
450
489
|
owner: LocalAccount;
|
|
451
|
-
client: Client
|
|
490
|
+
client: Client<Transport, Chain | undefined, JsonRpcAccount | LocalAccount | undefined>;
|
|
452
491
|
};
|
|
453
492
|
declare class ViemModule {
|
|
454
493
|
private readonly _signerClient;
|
|
@@ -465,6 +504,7 @@ declare class ViemModule {
|
|
|
465
504
|
request?: (parameters: viem.CcipRequestParameters) => Promise<CcipRequestReturnType>;
|
|
466
505
|
} | undefined;
|
|
467
506
|
chain: undefined;
|
|
507
|
+
experimental_blockTag?: viem.BlockTag | undefined;
|
|
468
508
|
key: string;
|
|
469
509
|
name: string;
|
|
470
510
|
pollingInterval: number;
|
|
@@ -484,6 +524,7 @@ declare class ViemModule {
|
|
|
484
524
|
cacheTime?: undefined;
|
|
485
525
|
ccipRead?: undefined;
|
|
486
526
|
chain?: undefined;
|
|
527
|
+
experimental_blockTag?: undefined;
|
|
487
528
|
key?: undefined;
|
|
488
529
|
name?: undefined;
|
|
489
530
|
pollingInterval?: undefined;
|
|
@@ -491,7 +532,7 @@ declare class ViemModule {
|
|
|
491
532
|
transport?: undefined;
|
|
492
533
|
type?: undefined;
|
|
493
534
|
uid?: undefined;
|
|
494
|
-
} & viem.ExactPartial<Pick<viem.PublicActions<viem.HttpTransport, undefined, undefined>, "call" | "createContractEventFilter" | "createEventFilter" | "estimateContractGas" | "estimateGas" | "getBlock" | "getBlockNumber" | "
|
|
535
|
+
} & viem.ExactPartial<Pick<viem.PublicActions<viem.HttpTransport<undefined, false>, undefined, undefined>, "getChainId" | "prepareTransactionRequest" | "sendRawTransaction" | "call" | "createContractEventFilter" | "createEventFilter" | "estimateContractGas" | "estimateGas" | "getBlock" | "getBlockNumber" | "getContractEvents" | "getEnsText" | "getFilterChanges" | "getGasPrice" | "getLogs" | "getTransaction" | "getTransactionCount" | "getTransactionReceipt" | "readContract" | "simulateContract" | "uninstallFilter" | "watchBlockNumber" | "watchContractEvent"> & Pick<viem.WalletActions<undefined, undefined>, "sendTransaction" | "writeContract">>>(fn: (client: Client<viem.HttpTransport<undefined, false>, undefined, undefined, viem.PaymasterRpcSchema, viem_account_abstraction.PaymasterActions>) => client) => Client<viem.HttpTransport<undefined, false>, undefined, undefined, viem.PaymasterRpcSchema, { [K in keyof client]: client[K]; } & viem_account_abstraction.PaymasterActions>;
|
|
495
536
|
}>;
|
|
496
537
|
signMessage(msg: SignableMessage): Promise<Hex$1>;
|
|
497
538
|
signTypedData<TTypedData extends TypedData | Record<string, unknown>, TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData>(params: TypedDataDefinition<TTypedData, TPrimaryType>): Promise<Hex$1>;
|