@fourt/sdk 1.4.1 → 1.5.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 +174 -333
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +59 -148
- package/dist/index.d.ts +59 -148
- package/dist/index.js +174 -333
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.cts +13 -1
- package/dist/types/index.d.ts +13 -1
- package/package.json +6 -6
- package/dist/index-Cy_WMhHm.d.cts +0 -19
- package/dist/index-Cy_WMhHm.d.ts +0 -19
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { User } from './types/index.cjs';
|
|
2
2
|
import { getWebAuthnAttestation, TSignedRequest, TurnkeyClient } from '@turnkey/http';
|
|
3
3
|
import * as viem_account_abstraction from 'viem/account-abstraction';
|
|
4
4
|
import { Hex } from '../types/misc.js';
|
|
@@ -30,6 +30,7 @@ declare class SessionStore {
|
|
|
30
30
|
clearBundle(): void;
|
|
31
31
|
clearType(): void;
|
|
32
32
|
clearToken(): void;
|
|
33
|
+
clearCsrfToken(): void;
|
|
33
34
|
clearOtpId(): void;
|
|
34
35
|
clearAll(): void;
|
|
35
36
|
private _getInitialState;
|
|
@@ -44,57 +45,40 @@ type AuthenticationServiceResponse<Route extends AuthenticationServiceRoutes> =
|
|
|
44
45
|
}>['Response'];
|
|
45
46
|
type AuthenticationServiceEndpoints = [
|
|
46
47
|
{
|
|
47
|
-
Route: '/v1/email
|
|
48
|
+
Route: '/v1/email/init';
|
|
48
49
|
Body: {
|
|
49
50
|
email: string;
|
|
50
|
-
|
|
51
|
-
redirectUrl: string;
|
|
52
|
-
expirationSeconds?: number;
|
|
51
|
+
redirectUrl?: string;
|
|
53
52
|
};
|
|
54
53
|
Response: {
|
|
55
|
-
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
Route: '/v1/email-auth';
|
|
60
|
-
Body: {};
|
|
61
|
-
Response: {
|
|
62
|
-
method: string;
|
|
54
|
+
otpId: string;
|
|
63
55
|
};
|
|
64
56
|
},
|
|
65
57
|
{
|
|
66
|
-
Route: '/v1/
|
|
58
|
+
Route: '/v1/email/complete';
|
|
67
59
|
Body: {
|
|
68
|
-
email: string;
|
|
69
|
-
} | {
|
|
70
|
-
email: string;
|
|
71
|
-
otpCode: string;
|
|
72
60
|
otpId: string;
|
|
73
|
-
|
|
61
|
+
otpCode: string;
|
|
62
|
+
publicKey: string;
|
|
74
63
|
};
|
|
75
|
-
Response:
|
|
76
|
-
otpId: string;
|
|
77
|
-
} & {
|
|
64
|
+
Response: {
|
|
78
65
|
userId: string;
|
|
79
|
-
apiKeyId: string;
|
|
80
|
-
credentialBundle: string;
|
|
81
66
|
subOrgId: string;
|
|
82
|
-
}
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
Route: '/v1/email/method';
|
|
71
|
+
Body: {};
|
|
72
|
+
Response: {
|
|
73
|
+
method: 'otp' | 'magiclink';
|
|
74
|
+
};
|
|
83
75
|
},
|
|
84
76
|
{
|
|
85
77
|
Route: '/v1/signup';
|
|
86
|
-
Body:
|
|
87
|
-
passkey: {
|
|
88
|
-
challenge: string;
|
|
89
|
-
attestation: Awaited<ReturnType<typeof getWebAuthnAttestation>>;
|
|
90
|
-
};
|
|
91
|
-
iframe: {
|
|
92
|
-
targetPublicKey: string;
|
|
93
|
-
redirectUrl: string;
|
|
94
|
-
expirationSeconds?: number;
|
|
95
|
-
};
|
|
96
|
-
}> & {
|
|
78
|
+
Body: {
|
|
97
79
|
email: string;
|
|
80
|
+
challenge: string;
|
|
81
|
+
attestation: Awaited<ReturnType<typeof getWebAuthnAttestation>>;
|
|
98
82
|
};
|
|
99
83
|
Response: {
|
|
100
84
|
user: User;
|
|
@@ -166,7 +150,7 @@ type AuthenticationServiceEndpoints = [
|
|
|
166
150
|
Response: User;
|
|
167
151
|
}
|
|
168
152
|
];
|
|
169
|
-
declare const ROUTE_METHOD_LIST: readonly [readonly ["/v1/signup", "POST"], readonly ["/v1/email
|
|
153
|
+
declare const ROUTE_METHOD_LIST: readonly [readonly ["/v1/signup", "POST"], readonly ["/v1/email/init", "POST"], readonly ["/v1/email/method", "GET"], readonly ["/v1/email/complete", "POST"], readonly ["/v1/lookup", "POST"], readonly ["/v1/signin", "POST"], readonly ["/v1/sign", "POST"], readonly ["/v1/oauth/init", "POST"], readonly ["/v1/refresh", "POST"], readonly ["/v1/csrf-token", "GET"], readonly ["/v1/logout", "POST"], readonly ["/v1/me", "GET"]];
|
|
170
154
|
type RouteMethod = (typeof ROUTE_METHOD_LIST)[number];
|
|
171
155
|
type Route = RouteMethod[0];
|
|
172
156
|
type Method = RouteMethod[1];
|
|
@@ -198,7 +182,7 @@ declare abstract class SignerClient {
|
|
|
198
182
|
protected set stamper(stamper: TurnkeyClient['stamper']);
|
|
199
183
|
protected get stamper(): TurnkeyClient['stamper'];
|
|
200
184
|
protected lookUpUser(email: string): Promise<string | null>;
|
|
201
|
-
protected
|
|
185
|
+
protected signIn(subOrgId?: string): Promise<void>;
|
|
202
186
|
protected request<R extends Route, M extends Method>(route: R, method: M, body?: AuthenticationServiceBody<R>): Promise<AuthenticationServiceResponse<R>>;
|
|
203
187
|
/**
|
|
204
188
|
* Compute milliseconds until refresh time.
|
|
@@ -211,24 +195,14 @@ declare abstract class SignerClient {
|
|
|
211
195
|
private _refreshToken;
|
|
212
196
|
}
|
|
213
197
|
|
|
214
|
-
type
|
|
198
|
+
type WebAuthnSignInParams = {
|
|
215
199
|
email: string;
|
|
216
200
|
};
|
|
217
|
-
type
|
|
218
|
-
method: string;
|
|
219
|
-
};
|
|
220
|
-
type EmailInitializeAuthParams = {
|
|
201
|
+
type InitEmailAuthParams = {
|
|
221
202
|
email: string;
|
|
222
203
|
redirectUrl?: string;
|
|
223
|
-
expirationSeconds?: number;
|
|
224
204
|
};
|
|
225
|
-
type
|
|
226
|
-
bundle: string;
|
|
227
|
-
subOrgId: string;
|
|
228
|
-
sessionType: SessionType;
|
|
229
|
-
isNewUser?: boolean;
|
|
230
|
-
};
|
|
231
|
-
type CompleteAuthWithOtpParams = {
|
|
205
|
+
type CompleteEmailAuthParams = {
|
|
232
206
|
email: string;
|
|
233
207
|
otpCode: string;
|
|
234
208
|
};
|
|
@@ -241,29 +215,21 @@ type WebSignerClientConstructorParams = SignerClientInheritedConstructorParams<{
|
|
|
241
215
|
webauthn: {
|
|
242
216
|
rpId: string;
|
|
243
217
|
};
|
|
244
|
-
iframe?: {
|
|
245
|
-
iframeElementId?: string;
|
|
246
|
-
iframeContainerId?: string;
|
|
247
|
-
};
|
|
248
218
|
oauth?: OAuthConfiguration;
|
|
249
219
|
}>;
|
|
250
220
|
/**
|
|
251
221
|
* A signer client for web applications.
|
|
252
222
|
*/
|
|
253
223
|
declare class WebSignerClient extends SignerClient {
|
|
254
|
-
private
|
|
224
|
+
private indexedDbStamper;
|
|
255
225
|
private webauthnStamper;
|
|
256
|
-
iframeConfig: {
|
|
257
|
-
iframeElementId: string;
|
|
258
|
-
iframeContainerId: string;
|
|
259
|
-
};
|
|
260
226
|
readonly oauthConfiguration: WebSignerClientConstructorParams['oauth'];
|
|
261
227
|
/**
|
|
262
228
|
* Initializes a new instance of the `WebSignerClient` class.
|
|
263
229
|
*
|
|
264
230
|
* @param {WebSignerClientConstructorParams} params params for the constructor
|
|
265
231
|
*/
|
|
266
|
-
constructor({ configuration, webauthn,
|
|
232
|
+
constructor({ configuration, webauthn, oauth, }: WebSignerClientConstructorParams);
|
|
267
233
|
logout(): Promise<void>;
|
|
268
234
|
signRawMessage<Into extends string>(msg: string): Promise<Into>;
|
|
269
235
|
/**
|
|
@@ -275,95 +241,45 @@ declare class WebSignerClient extends SignerClient {
|
|
|
275
241
|
/**
|
|
276
242
|
* Signs in a user with webauthn.
|
|
277
243
|
*
|
|
278
|
-
* @param {
|
|
244
|
+
* @param {WebAuthnSignInParams} params params for the sign in
|
|
279
245
|
*/
|
|
280
|
-
|
|
246
|
+
webAuthnSignIn({ email }: WebAuthnSignInParams): Promise<void>;
|
|
281
247
|
/**
|
|
282
248
|
* Handles auth user process with email according to the method of the used app.
|
|
283
249
|
*
|
|
284
|
-
* @param {
|
|
250
|
+
* @param {InitEmailAuthParams} params params needed for the initialization of the auth process
|
|
285
251
|
*/
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
getIframePublicKey(): Promise<string>;
|
|
252
|
+
initEmailAuth(params: InitEmailAuthParams): Promise<void>;
|
|
253
|
+
getPublicKey(): Promise<string>;
|
|
254
|
+
resetKeyPair(): Promise<void>;
|
|
290
255
|
/**
|
|
291
256
|
* Verifies the provided otp code.
|
|
292
257
|
*
|
|
293
|
-
* @param {
|
|
258
|
+
* @param {CompleteEmailAuthParams} params params needed for otp code verification
|
|
294
259
|
*/
|
|
295
|
-
|
|
296
|
-
bundle: string;
|
|
297
|
-
subOrgId: string;
|
|
298
|
-
}>;
|
|
260
|
+
completeEmailAuth(params: CompleteEmailAuthParams): Promise<void>;
|
|
299
261
|
/**
|
|
300
262
|
* Gets the email authentication method of the app.
|
|
301
263
|
*/
|
|
302
|
-
getEmailAuthMethod(): Promise<
|
|
303
|
-
/**
|
|
304
|
-
* Starts email authentication process via otp.
|
|
305
|
-
*/
|
|
306
|
-
private _initOtpAuth;
|
|
307
|
-
/**
|
|
308
|
-
* Completes the authentication process with a credential bundle.
|
|
309
|
-
*
|
|
310
|
-
* @param {CompleteAuthWithBundleParams} params params for the completion of the auth process
|
|
311
|
-
*/
|
|
312
|
-
completeAuthWithBundle({ bundle, subOrgId, sessionType, }: CompleteAuthWithBundleParams): Promise<void>;
|
|
264
|
+
getEmailAuthMethod(): Promise<"otp" | "magiclink">;
|
|
313
265
|
/**
|
|
314
266
|
* Checks for an existing session and if exists, updates the stamper accordingly.
|
|
315
267
|
*/
|
|
316
268
|
private _updateStamper;
|
|
317
|
-
/**
|
|
318
|
-
* Init authentication with magic link email.
|
|
319
|
-
*
|
|
320
|
-
* @param {EmailInitializeAuthParams} params params for the sign in
|
|
321
|
-
*/
|
|
322
|
-
private _initMagicLinkAuth;
|
|
323
269
|
/**
|
|
324
270
|
* Creates a passkey account using the webauthn stamper.
|
|
325
271
|
*
|
|
326
|
-
* @param {
|
|
327
|
-
*/
|
|
328
|
-
private _createWebauthnAccount;
|
|
329
|
-
/**
|
|
330
|
-
* Creates an email account using the iframe stamper.
|
|
331
|
-
*
|
|
332
|
-
* @param {Extract<CreateAccountParams, { method: 'email' }>} params params for the creation of the account
|
|
272
|
+
* @param {WebAuthnSignInParams} params params for the creation of the account
|
|
333
273
|
*/
|
|
334
|
-
private
|
|
274
|
+
private _createWebAuthnAccount;
|
|
335
275
|
/**
|
|
336
|
-
*
|
|
276
|
+
* Init account creation with email.
|
|
337
277
|
*
|
|
338
|
-
* @param {
|
|
278
|
+
* @param {InitEmailAuthParams} params params for the creation of the account
|
|
339
279
|
*/
|
|
340
|
-
private
|
|
280
|
+
private _initEmailAuth;
|
|
341
281
|
private _webauthnGenerateAttestation;
|
|
342
|
-
private
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
declare class MagicLinkModule {
|
|
346
|
-
private readonly _webSignerClient;
|
|
347
|
-
constructor(_webSignerClient: WebSignerClient);
|
|
348
|
-
/**
|
|
349
|
-
* Completes authentication with magic link that contains a bundle.
|
|
350
|
-
*
|
|
351
|
-
* @param params {CompleteAuthWithBundleParams} params received as URL params necessary to complete authentication process.
|
|
352
|
-
* @returns {Promise<void>} promise that completes the authentication process.
|
|
353
|
-
*/
|
|
354
|
-
complete(params: Pick<CompleteAuthWithBundleParams, 'subOrgId' | 'bundle'>): Promise<void>;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
declare class OtpModule {
|
|
358
|
-
private readonly _webSignerClient;
|
|
359
|
-
constructor(_webSignerClient: WebSignerClient);
|
|
360
|
-
/**
|
|
361
|
-
* Completes authentication with OTP code after user receives the bundle and subOrgId.
|
|
362
|
-
*
|
|
363
|
-
* @param params {CompleteAuthWithOtpParams} params to complete the authentication process.
|
|
364
|
-
* @returns {Promise<void>} promise that completes the authentication process.
|
|
365
|
-
*/
|
|
366
|
-
complete(params: CompleteAuthWithOtpParams): Promise<void>;
|
|
282
|
+
private _initIndexedDbStamper;
|
|
367
283
|
}
|
|
368
284
|
|
|
369
285
|
/**
|
|
@@ -372,25 +288,28 @@ declare class OtpModule {
|
|
|
372
288
|
*/
|
|
373
289
|
declare class EmailModule {
|
|
374
290
|
private readonly _webSignerClient;
|
|
375
|
-
private readonly _magicLinkModule;
|
|
376
|
-
private readonly _otpModule;
|
|
377
291
|
constructor(_webSignerClient: WebSignerClient);
|
|
378
292
|
/**
|
|
379
293
|
* Initialize user authentication process using email.
|
|
380
294
|
*
|
|
381
|
-
* @param params {
|
|
382
|
-
* @returns {Promise<void>} promise that resolves
|
|
295
|
+
* @param params {InitEmailAuthParams} params to initialize the user authentication process.
|
|
296
|
+
* @returns {Promise<void>} promise that resolves when the initialization is complete.
|
|
297
|
+
*/
|
|
298
|
+
initialize(params: InitEmailAuthParams): Promise<void>;
|
|
299
|
+
/**
|
|
300
|
+
* Completes email authentication with OTP code.
|
|
301
|
+
*
|
|
302
|
+
* @param params {CompleteEmailAuthParams} params to complete the authentication process.
|
|
303
|
+
* @returns {Promise<void>} promise that completes the authentication process.
|
|
383
304
|
*/
|
|
384
|
-
|
|
305
|
+
complete(params: CompleteEmailAuthParams): Promise<void>;
|
|
385
306
|
/**
|
|
386
307
|
* Get the email authentication method of the app, that was chosen in fourt.io dashboard.
|
|
387
308
|
* It can be either `magiclink` or `otp`.
|
|
388
309
|
*
|
|
389
|
-
* @returns {Promise<
|
|
310
|
+
* @returns {Promise<'otp' | 'magiclink'>} promise that resolves to the email authentication method.
|
|
390
311
|
*/
|
|
391
|
-
getAuthMethod(): Promise<
|
|
392
|
-
get magicLink(): MagicLinkModule;
|
|
393
|
-
get otp(): OtpModule;
|
|
312
|
+
getAuthMethod(): Promise<'otp' | 'magiclink'>;
|
|
394
313
|
}
|
|
395
314
|
|
|
396
315
|
/**
|
|
@@ -403,18 +322,14 @@ declare class PasskeysModule {
|
|
|
403
322
|
/**
|
|
404
323
|
* Signs in a user using Passkeys.
|
|
405
324
|
*
|
|
406
|
-
* @param params {
|
|
325
|
+
* @param params {WebAuthnSignInParams} params for the sign-in process.
|
|
407
326
|
*/
|
|
408
|
-
signIn(params:
|
|
327
|
+
signIn(params: WebAuthnSignInParams): Promise<void>;
|
|
409
328
|
}
|
|
410
329
|
|
|
411
330
|
declare class GoogleModule {
|
|
412
331
|
private readonly _webSignerClient;
|
|
413
332
|
constructor(_webSignerClient: WebSignerClient);
|
|
414
|
-
/**
|
|
415
|
-
*
|
|
416
|
-
* @returns
|
|
417
|
-
*/
|
|
418
333
|
init(): Promise<string>;
|
|
419
334
|
}
|
|
420
335
|
|
|
@@ -427,10 +342,6 @@ declare class FacebookModule {
|
|
|
427
342
|
declare class AppleModule {
|
|
428
343
|
private readonly _webSignerClient;
|
|
429
344
|
constructor(_webSignerClient: WebSignerClient);
|
|
430
|
-
/**
|
|
431
|
-
*
|
|
432
|
-
* @returns
|
|
433
|
-
*/
|
|
434
345
|
init(): Promise<string>;
|
|
435
346
|
}
|
|
436
347
|
|
|
@@ -451,7 +362,7 @@ declare class OAuthModule {
|
|
|
451
362
|
get google(): GoogleModule;
|
|
452
363
|
get facebook(): FacebookModule;
|
|
453
364
|
get apple(): AppleModule;
|
|
454
|
-
complete({
|
|
365
|
+
complete({ subOrgId }: CompleteParams): Promise<void>;
|
|
455
366
|
}
|
|
456
367
|
|
|
457
368
|
/**
|
|
@@ -572,7 +483,7 @@ declare class ViemModule {
|
|
|
572
483
|
|
|
573
484
|
type FourtWebSignerConstructorParams = {
|
|
574
485
|
configuration: SignerClientConstructorParams['configuration'];
|
|
575
|
-
auth: Pick<WebSignerClientConstructorParams, 'webauthn' | '
|
|
486
|
+
auth: Pick<WebSignerClientConstructorParams, 'webauthn' | 'oauth'>;
|
|
576
487
|
};
|
|
577
488
|
/**
|
|
578
489
|
* A client for interacting with the Fourt Web Signer.
|
|
@@ -601,7 +512,7 @@ declare class FourtWebSigner {
|
|
|
601
512
|
*
|
|
602
513
|
* @param {FourtWebSignerConstructorParams} params the required parameters to initialize the client
|
|
603
514
|
*/
|
|
604
|
-
constructor({ configuration, auth: { webauthn,
|
|
515
|
+
constructor({ configuration, auth: { webauthn, oauth }, }: FourtWebSignerConstructorParams);
|
|
605
516
|
/**
|
|
606
517
|
* A module for interacting with the Viem library.
|
|
607
518
|
*/
|