@fourt/sdk 1.1.6 → 1.2.0
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 +268 -139
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -41
- package/dist/index.d.ts +66 -41
- package/dist/index.js +270 -141
- package/dist/index.js.map +1 -1
- package/package.json +14 -15
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.
|
|
@@ -128,7 +125,7 @@ type AuthenticationServiceEndpoints = [
|
|
|
128
125
|
};
|
|
129
126
|
Response: {
|
|
130
127
|
user: User;
|
|
131
|
-
token
|
|
128
|
+
token?: string;
|
|
132
129
|
};
|
|
133
130
|
},
|
|
134
131
|
{
|
|
@@ -160,13 +157,30 @@ type AuthenticationServiceEndpoints = [
|
|
|
160
157
|
};
|
|
161
158
|
},
|
|
162
159
|
{
|
|
163
|
-
Route: 'v1/oauth/init';
|
|
160
|
+
Route: '/v1/oauth/init';
|
|
164
161
|
Body: {
|
|
165
162
|
provider: string;
|
|
166
163
|
};
|
|
167
164
|
Response: {
|
|
168
165
|
url: string;
|
|
169
166
|
};
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
Route: '/v1/refresh';
|
|
170
|
+
Body: {};
|
|
171
|
+
Response: {
|
|
172
|
+
token: string;
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
Route: '/v1/logout';
|
|
177
|
+
Body: {};
|
|
178
|
+
Response: {};
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
Route: '/v1/me';
|
|
182
|
+
Body: {};
|
|
183
|
+
Response: User;
|
|
170
184
|
}
|
|
171
185
|
];
|
|
172
186
|
|
|
@@ -184,20 +198,24 @@ declare abstract class SignerClient {
|
|
|
184
198
|
protected readonly _turnkeyClient: TurnkeyClient;
|
|
185
199
|
protected readonly _configuration: Required<SignerClientConstructorParams['configuration']>;
|
|
186
200
|
protected readonly _sessionStore: SessionStore;
|
|
187
|
-
private
|
|
201
|
+
private _refreshPromise?;
|
|
202
|
+
private _refreshTimer?;
|
|
188
203
|
constructor({ stamper, configuration: { apiUrl, paymasterRpcUrl, ...requiredConfiguration }, }: SignerClientConstructorParams);
|
|
189
|
-
logout(): void;
|
|
190
204
|
get configuration(): Required<SignerClientConfiguration>;
|
|
191
|
-
|
|
192
|
-
|
|
205
|
+
getUser(): Promise<User>;
|
|
206
|
+
isLoggedIn(): Promise<boolean>;
|
|
207
|
+
getToken(): Promise<string>;
|
|
208
|
+
private _isTokenExpired;
|
|
209
|
+
logout(): Promise<void>;
|
|
210
|
+
signRawMessage<Into extends string>(msg: string): Promise<Into>;
|
|
193
211
|
protected set stamper(stamper: TurnkeyClient['stamper']);
|
|
194
212
|
protected get stamper(): TurnkeyClient['stamper'];
|
|
195
|
-
protected get sessionStore(): SessionStore;
|
|
196
|
-
signRawMessage<Into extends string>(msg: string): Promise<Into>;
|
|
197
|
-
getToken(): string | undefined;
|
|
198
213
|
protected lookUpUser(email: string): Promise<string | null>;
|
|
199
214
|
protected whoAmI(subOrgId?: string): Promise<void>;
|
|
200
215
|
protected request<Route extends AuthenticationServiceRoutes>(route: Route, body?: AuthenticationServiceBody<Route>): Promise<AuthenticationServiceResponse<Route>>;
|
|
216
|
+
protected _scheduleRefresh(token: string): void;
|
|
217
|
+
private _refreshToken;
|
|
218
|
+
private _getCookie;
|
|
201
219
|
}
|
|
202
220
|
|
|
203
221
|
type WebauthnSignInParams = {
|
|
@@ -233,7 +251,12 @@ type WebSignerClientConstructorParams = SignerClientInheritedConstructorParams<{
|
|
|
233
251
|
* A signer client for web applications.
|
|
234
252
|
*/
|
|
235
253
|
declare class WebSignerClient extends SignerClient {
|
|
236
|
-
private
|
|
254
|
+
private iframeStamper;
|
|
255
|
+
private webauthnStamper;
|
|
256
|
+
iframeConfig: {
|
|
257
|
+
iframeElementId: string;
|
|
258
|
+
iframeContainerId: string;
|
|
259
|
+
};
|
|
237
260
|
readonly oauthConfiguration: WebSignerClientConstructorParams['oauth'];
|
|
238
261
|
/**
|
|
239
262
|
* Initializes a new instance of the `WebSignerClient` class.
|
|
@@ -241,13 +264,14 @@ declare class WebSignerClient extends SignerClient {
|
|
|
241
264
|
* @param {WebSignerClientConstructorParams} params params for the constructor
|
|
242
265
|
*/
|
|
243
266
|
constructor({ configuration, webauthn, iframe, oauth, }: WebSignerClientConstructorParams);
|
|
244
|
-
signRawMessage<Into extends string>(msg: string): Promise<Into>;
|
|
245
267
|
logout(): Promise<void>;
|
|
268
|
+
signRawMessage<Into extends string>(msg: string): Promise<Into>;
|
|
246
269
|
/**
|
|
247
|
-
*
|
|
270
|
+
* Get the pre-filled URL for initiating oauth with a specific provider.
|
|
248
271
|
*
|
|
272
|
+
* @param {string} provider provider for which we are getting the URL, currently google or apple
|
|
249
273
|
*/
|
|
250
|
-
|
|
274
|
+
getOAuthInitUrl(provider: string): Promise<string>;
|
|
251
275
|
/**
|
|
252
276
|
* Signs in a user with webauthn.
|
|
253
277
|
*
|
|
@@ -261,18 +285,22 @@ declare class WebSignerClient extends SignerClient {
|
|
|
261
285
|
*/
|
|
262
286
|
emailAuth(params: EmailInitializeAuthParams): Promise<void>;
|
|
263
287
|
getIframePublicKey(): Promise<string>;
|
|
264
|
-
/**
|
|
265
|
-
* Signs in a user with email.
|
|
266
|
-
*
|
|
267
|
-
* @param {EmailInitializeAuthParams} params params for the sign in
|
|
268
|
-
*/
|
|
269
|
-
private _signInWithEmail;
|
|
270
288
|
/**
|
|
271
289
|
* Completes the authentication process with a credential bundle.
|
|
272
290
|
*
|
|
273
291
|
* @param {CompleteAuthWithBundleParams} params params for the completion of the auth process
|
|
274
292
|
*/
|
|
275
293
|
completeAuthWithBundle({ bundle, subOrgId, sessionType, }: CompleteAuthWithBundleParams): Promise<void>;
|
|
294
|
+
/**
|
|
295
|
+
* Checks for an existing session and if exists, updates the stamper accordingly.
|
|
296
|
+
*/
|
|
297
|
+
private _updateStamper;
|
|
298
|
+
/**
|
|
299
|
+
* Signs in a user with email.
|
|
300
|
+
*
|
|
301
|
+
* @param {EmailInitializeAuthParams} params params for the sign in
|
|
302
|
+
*/
|
|
303
|
+
private _signInWithEmail;
|
|
276
304
|
/**
|
|
277
305
|
* Creates a passkey account using the webauthn stamper.
|
|
278
306
|
*
|
|
@@ -293,12 +321,6 @@ declare class WebSignerClient extends SignerClient {
|
|
|
293
321
|
private _createAccount;
|
|
294
322
|
private _webauthnGenerateAttestation;
|
|
295
323
|
private _initIframeStamper;
|
|
296
|
-
/**
|
|
297
|
-
* Get the pre-filled URL for initiating oauth with a specific provider.
|
|
298
|
-
*
|
|
299
|
-
* @param {string} provider provider for which we are getting the URL, currently google or apple
|
|
300
|
-
*/
|
|
301
|
-
getOAuthInitUrl(provider: string): Promise<string>;
|
|
302
324
|
}
|
|
303
325
|
|
|
304
326
|
/**
|
|
@@ -421,20 +443,21 @@ declare class UserModule {
|
|
|
421
443
|
*/
|
|
422
444
|
constructor(_webSignerClient: WebSignerClient);
|
|
423
445
|
/**
|
|
424
|
-
*
|
|
425
|
-
*
|
|
426
|
-
* @returns {User | undefined} user information.
|
|
446
|
+
* Retrieves information for the authenticated user.
|
|
447
|
+
* Assumes a user is already logged in, otherwise it will throw an error.
|
|
427
448
|
*/
|
|
428
|
-
|
|
429
|
-
/**
|
|
430
|
-
*
|
|
431
|
-
* @returns {string | undefined} user token.
|
|
449
|
+
getInfo(): Promise<User>;
|
|
450
|
+
/**
|
|
451
|
+
* Checks if a user is currently logged in to the fourt.io SDK.
|
|
432
452
|
*/
|
|
433
|
-
|
|
453
|
+
isLoggedIn(): Promise<boolean>;
|
|
454
|
+
/**
|
|
455
|
+
* Generates an access token with a lifespan of 15 minutes.
|
|
456
|
+
* Assumes a user is already logged in, otherwise it will throw an error.
|
|
457
|
+
*/
|
|
458
|
+
getToken(): Promise<string>;
|
|
434
459
|
/**
|
|
435
460
|
* Logs out the user.
|
|
436
|
-
*
|
|
437
|
-
* @returns {void}
|
|
438
461
|
*/
|
|
439
462
|
logout(): Promise<void>;
|
|
440
463
|
}
|
|
@@ -443,7 +466,7 @@ type CcipRequestReturnType = Hex;
|
|
|
443
466
|
|
|
444
467
|
type CurrentUserToLightSmartAccountParams = {
|
|
445
468
|
owner: LocalAccount;
|
|
446
|
-
client: Client
|
|
469
|
+
client: Client<Transport, Chain | undefined, JsonRpcAccount | LocalAccount | undefined>;
|
|
447
470
|
};
|
|
448
471
|
declare class ViemModule {
|
|
449
472
|
private readonly _signerClient;
|
|
@@ -460,6 +483,7 @@ declare class ViemModule {
|
|
|
460
483
|
request?: (parameters: viem.CcipRequestParameters) => Promise<CcipRequestReturnType>;
|
|
461
484
|
} | undefined;
|
|
462
485
|
chain: undefined;
|
|
486
|
+
experimental_blockTag?: viem.BlockTag | undefined;
|
|
463
487
|
key: string;
|
|
464
488
|
name: string;
|
|
465
489
|
pollingInterval: number;
|
|
@@ -479,6 +503,7 @@ declare class ViemModule {
|
|
|
479
503
|
cacheTime?: undefined;
|
|
480
504
|
ccipRead?: undefined;
|
|
481
505
|
chain?: undefined;
|
|
506
|
+
experimental_blockTag?: undefined;
|
|
482
507
|
key?: undefined;
|
|
483
508
|
name?: undefined;
|
|
484
509
|
pollingInterval?: undefined;
|
|
@@ -486,7 +511,7 @@ declare class ViemModule {
|
|
|
486
511
|
transport?: undefined;
|
|
487
512
|
type?: undefined;
|
|
488
513
|
uid?: undefined;
|
|
489
|
-
} & viem.ExactPartial<Pick<viem.PublicActions<viem.HttpTransport, undefined, undefined>, "call" | "createContractEventFilter" | "createEventFilter" | "estimateContractGas" | "estimateGas" | "getBlock" | "getBlockNumber" | "
|
|
514
|
+
} & 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>;
|
|
490
515
|
}>;
|
|
491
516
|
signMessage(msg: SignableMessage): Promise<Hex$1>;
|
|
492
517
|
signTypedData<TTypedData extends TypedData | Record<string, unknown>, TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData>(params: TypedDataDefinition<TTypedData, TPrimaryType>): Promise<Hex$1>;
|