@fourt/sdk 0.4.0 → 0.5.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.d.cts CHANGED
@@ -1,10 +1,14 @@
1
1
  import { getWebAuthnAttestation, TSignedRequest, TurnkeyClient } from '@turnkey/http';
2
- import { User } from './types/index.cjs';
2
+ import { U as User, A as AtLeastOne } from './index-Cy_WMhHm.cjs';
3
3
  import * as viem_account_abstraction from 'viem/account-abstraction';
4
4
  import * as viem from 'viem';
5
5
  import { LocalAccount, Client, SignableMessage, Hex, TypedData, TypedDataDefinition, SerializeTransactionFn, TransactionSerializable, IsNarrowable, TransactionSerialized, GetTransactionType } from 'viem';
6
6
  import { toLightSmartAccount } from 'permissionless/accounts';
7
7
 
8
+ declare enum SessionType {
9
+ Email = "email",
10
+ Passkeys = "passkeys"
11
+ }
8
12
  /**
9
13
  * A store for the session state.
10
14
  */
@@ -14,6 +18,18 @@ declare class SessionStore {
14
18
  * Initializes a new instance of the `SessionStore` class by creating a new `zustand`store with the initial state.
15
19
  */
16
20
  constructor();
21
+ /**
22
+ * Gets the type from the session state.
23
+ *
24
+ * @returns {SessionType | undefined} the type.
25
+ */
26
+ get type(): SessionType | undefined;
27
+ /**
28
+ * Sets the type in the session state.
29
+ *
30
+ * @param {SessionType} type the type to set.
31
+ */
32
+ set type(type: SessionType);
17
33
  /**
18
34
  * Gets the token from the session state.
19
35
  *
@@ -26,6 +42,18 @@ declare class SessionStore {
26
42
  * @param {string} token the token to set.
27
43
  */
28
44
  set token(token: string);
45
+ /**
46
+ * Gets the bundle from the session state.
47
+ *
48
+ * @returns {string | undefined} the bundle.
49
+ */
50
+ get bundle(): string | undefined;
51
+ /**
52
+ * Sets the bundle in the session state.
53
+ *
54
+ * @param {string} bundle the bundle to set.
55
+ */
56
+ set bundle(bundle: string);
29
57
  /**
30
58
  * Gets the user from the session state.
31
59
  *
@@ -42,6 +70,14 @@ declare class SessionStore {
42
70
  * Clears the user from the session state.
43
71
  */
44
72
  clearUser(): void;
73
+ /**
74
+ * Clears the bundle from the session state.
75
+ */
76
+ clearBundle(): void;
77
+ /**
78
+ * Clears the type from the session state.
79
+ */
80
+ clearType(): void;
45
81
  /**
46
82
  * Clears the token from the session state.
47
83
  */
@@ -62,12 +98,30 @@ type AuthenticationServiceResponse<Route extends AuthenticationServiceRoutes> =
62
98
  }>['Response'];
63
99
  type AuthenticationServiceEndpoints = [
64
100
  {
65
- Route: '/v1/signup';
101
+ Route: '/v1/email-auth';
66
102
  Body: {
103
+ email: string;
104
+ targetPublicKey: string;
105
+ redirectUrl: string;
106
+ expirationSeconds?: number;
107
+ };
108
+ Response: {
109
+ subOrgId: string;
110
+ };
111
+ },
112
+ {
113
+ Route: '/v1/signup';
114
+ Body: AtLeastOne<{
67
115
  passkey: {
68
116
  challenge: string;
69
117
  attestation: Awaited<ReturnType<typeof getWebAuthnAttestation>>;
70
118
  };
119
+ iframe: {
120
+ targetPublicKey: string;
121
+ redirectUrl: string;
122
+ expirationSeconds?: number;
123
+ };
124
+ }> & {
71
125
  email: string;
72
126
  };
73
127
  Response: {
@@ -137,10 +191,24 @@ declare abstract class SignerClient {
137
191
  type WebauthnSignInParams = {
138
192
  email: string;
139
193
  };
194
+ type EmailInitializeAuthParams = {
195
+ email: string;
196
+ redirectUrl: string;
197
+ expirationSeconds?: number;
198
+ };
199
+ type EmailCompleteAuthWithBundleParams = {
200
+ bundle: string;
201
+ subOrgId: string;
202
+ isNewUser?: boolean;
203
+ };
140
204
  type WebSignerClientConstructorParams = SignerClientInheritedConstructorParams<{
141
205
  webauthn: {
142
206
  rpId: string;
143
207
  };
208
+ iframe?: {
209
+ iframeElementId?: string;
210
+ iframeContainerId?: string;
211
+ };
144
212
  }>;
145
213
  /**
146
214
  * A signer client for web applications.
@@ -152,15 +220,58 @@ declare class WebSignerClient extends SignerClient {
152
220
  *
153
221
  * @param {WebSignerClientConstructorParams} params params for the constructor
154
222
  */
155
- constructor({ configuration, webauthn }: WebSignerClientConstructorParams);
223
+ constructor({ configuration, webauthn, iframe, }: WebSignerClientConstructorParams);
224
+ signRawMessage<Into extends string>(msg: string): Promise<Into>;
225
+ logout(): Promise<void>;
226
+ /**
227
+ * Checks for an existing session and if exists, updates the stamper accordingly.
228
+ *
229
+ */
230
+ private updateStamper;
156
231
  /**
157
232
  * Signs in a user with webauthn.
158
233
  *
159
234
  * @param {WebauthnSignInParams} params params for the sign in
160
235
  */
161
236
  webauthnSignIn({ email }: WebauthnSignInParams): Promise<void>;
237
+ /**
238
+ * Handle auth user process with email.
239
+ *
240
+ * @param {EmailInitializeAuthParams} params Params needed for the initialization of the auth process
241
+ */
242
+ emailAuth(params: EmailInitializeAuthParams): Promise<void>;
243
+ /**
244
+ * Signs in a user with email.
245
+ *
246
+ * @param {EmailInitializeAuthParams} params params for the sign in
247
+ */
248
+ private _signInWithEmail;
249
+ /**
250
+ * Completes the authentication process with a credential bundle.
251
+ *
252
+ * @param {EmailCompleteAuthWithBundleParams} params params for the completion of the auth process
253
+ */
254
+ completeAuthWithBundle({ bundle, subOrgId, }: EmailCompleteAuthWithBundleParams): Promise<void>;
255
+ /**
256
+ * Creates a passkey account using the webauthn stamper.
257
+ *
258
+ * @param {Extract<CreateAccountParams, { method: 'webauthn' }>} params params for the creation of the account
259
+ */
260
+ private _createWebauthnAccount;
261
+ /**
262
+ * Creates an email account using the iframe stamper.
263
+ *
264
+ * @param {Extract<CreateAccountParams, { method: 'email' }>} params params for the creation of the account
265
+ */
266
+ private _createEmailAccount;
267
+ /**
268
+ * Handle the account creation process.
269
+ *
270
+ * @param {CreateAccountParams} params params to create an account
271
+ */
162
272
  private _createAccount;
163
273
  private _webauthnGenerateAttestation;
274
+ private _initIframeStamper;
164
275
  }
165
276
 
166
277
  type CurrentUserToLightSmartAccountParams = {
@@ -213,6 +324,29 @@ declare class ViemModule {
213
324
  } | undefined): Promise<IsNarrowable<TransactionSerialized<GetTransactionType<transaction>>, Hex> extends true ? TransactionSerialized<GetTransactionType<transaction>> : Hex>;
214
325
  }
215
326
 
327
+ /**
328
+ * A module for interacting with the Email authentication methods.
329
+ * Available through the `auth.email` property on a `FourtWebSigner` instance.
330
+ */
331
+ declare class EmailModule {
332
+ private readonly _webSignerClient;
333
+ constructor(_webSignerClient: WebSignerClient);
334
+ /**
335
+ * Initialize user authentication process using email.
336
+ *
337
+ * @param params {EmailInitializeAuthParams} params to initialize the user authentication process.
338
+ * @returns {Promise<void>} promise that resolves to the result of the authentication process.
339
+ */
340
+ initialize(params: EmailInitializeAuthParams): Promise<void>;
341
+ /**
342
+ * Completes authentication with bundle after user receives the bundle and subOrgId as URL params.
343
+ *
344
+ * @param params {EmailCompleteAuthWithBundleParams} params received as URL params necessary to complete authentication process.
345
+ * @returns {Promise<void>} promise that completes the authentication process.
346
+ */
347
+ complete(params: EmailCompleteAuthWithBundleParams): Promise<void>;
348
+ }
349
+
216
350
  /**
217
351
  * A module for interacting with the Passkeys authentication methods.
218
352
  * Available through the `auth.passkeys` property on a `FourtWebSigner` instance.
@@ -236,6 +370,7 @@ declare class PasskeysModule {
236
370
  declare class AuthModule {
237
371
  private readonly _webSignerClient;
238
372
  private readonly _passkeys;
373
+ private readonly _email;
239
374
  /**
240
375
  * Initializes a new instance of the `AuthModule` class.
241
376
  *
@@ -246,6 +381,10 @@ declare class AuthModule {
246
381
  * A module for interacting with the Passkeys authentication methods.
247
382
  */
248
383
  get passkeys(): PasskeysModule;
384
+ /**
385
+ * A module for interacting with the Passkeys authentication methods.
386
+ */
387
+ get email(): EmailModule;
249
388
  }
250
389
 
251
390
  /**
@@ -271,12 +410,12 @@ declare class UserModule {
271
410
  *
272
411
  * @returns {void}
273
412
  */
274
- logout(): void;
413
+ logout(): Promise<void>;
275
414
  }
276
415
 
277
416
  type FourtWebSignerConstructorParams = {
278
417
  configuration: SignerClientConstructorParams['configuration'];
279
- auth: Pick<WebSignerClientConstructorParams, 'webauthn'>;
418
+ auth: Pick<WebSignerClientConstructorParams, 'webauthn' | 'iframe'>;
280
419
  };
281
420
  /**
282
421
  * A client for interacting with the Fourt Web Signer.
@@ -305,7 +444,7 @@ declare class FourtWebSigner {
305
444
  *
306
445
  * @param {FourtWebSignerConstructorParams} params the required parameters to initialize the client
307
446
  */
308
- constructor({ configuration, auth: { webauthn }, }: FourtWebSignerConstructorParams);
447
+ constructor({ configuration, auth: { webauthn, iframe }, }: FourtWebSignerConstructorParams);
309
448
  /**
310
449
  * A module for interacting with the Viem library.
311
450
  */
package/dist/index.d.ts CHANGED
@@ -1,10 +1,14 @@
1
1
  import { getWebAuthnAttestation, TSignedRequest, TurnkeyClient } from '@turnkey/http';
2
- import { User } from './types/index.js';
2
+ import { U as User, A as AtLeastOne } from './index-Cy_WMhHm.js';
3
3
  import * as viem_account_abstraction from 'viem/account-abstraction';
4
4
  import * as viem from 'viem';
5
5
  import { LocalAccount, Client, SignableMessage, Hex, TypedData, TypedDataDefinition, SerializeTransactionFn, TransactionSerializable, IsNarrowable, TransactionSerialized, GetTransactionType } from 'viem';
6
6
  import { toLightSmartAccount } from 'permissionless/accounts';
7
7
 
8
+ declare enum SessionType {
9
+ Email = "email",
10
+ Passkeys = "passkeys"
11
+ }
8
12
  /**
9
13
  * A store for the session state.
10
14
  */
@@ -14,6 +18,18 @@ declare class SessionStore {
14
18
  * Initializes a new instance of the `SessionStore` class by creating a new `zustand`store with the initial state.
15
19
  */
16
20
  constructor();
21
+ /**
22
+ * Gets the type from the session state.
23
+ *
24
+ * @returns {SessionType | undefined} the type.
25
+ */
26
+ get type(): SessionType | undefined;
27
+ /**
28
+ * Sets the type in the session state.
29
+ *
30
+ * @param {SessionType} type the type to set.
31
+ */
32
+ set type(type: SessionType);
17
33
  /**
18
34
  * Gets the token from the session state.
19
35
  *
@@ -26,6 +42,18 @@ declare class SessionStore {
26
42
  * @param {string} token the token to set.
27
43
  */
28
44
  set token(token: string);
45
+ /**
46
+ * Gets the bundle from the session state.
47
+ *
48
+ * @returns {string | undefined} the bundle.
49
+ */
50
+ get bundle(): string | undefined;
51
+ /**
52
+ * Sets the bundle in the session state.
53
+ *
54
+ * @param {string} bundle the bundle to set.
55
+ */
56
+ set bundle(bundle: string);
29
57
  /**
30
58
  * Gets the user from the session state.
31
59
  *
@@ -42,6 +70,14 @@ declare class SessionStore {
42
70
  * Clears the user from the session state.
43
71
  */
44
72
  clearUser(): void;
73
+ /**
74
+ * Clears the bundle from the session state.
75
+ */
76
+ clearBundle(): void;
77
+ /**
78
+ * Clears the type from the session state.
79
+ */
80
+ clearType(): void;
45
81
  /**
46
82
  * Clears the token from the session state.
47
83
  */
@@ -62,12 +98,30 @@ type AuthenticationServiceResponse<Route extends AuthenticationServiceRoutes> =
62
98
  }>['Response'];
63
99
  type AuthenticationServiceEndpoints = [
64
100
  {
65
- Route: '/v1/signup';
101
+ Route: '/v1/email-auth';
66
102
  Body: {
103
+ email: string;
104
+ targetPublicKey: string;
105
+ redirectUrl: string;
106
+ expirationSeconds?: number;
107
+ };
108
+ Response: {
109
+ subOrgId: string;
110
+ };
111
+ },
112
+ {
113
+ Route: '/v1/signup';
114
+ Body: AtLeastOne<{
67
115
  passkey: {
68
116
  challenge: string;
69
117
  attestation: Awaited<ReturnType<typeof getWebAuthnAttestation>>;
70
118
  };
119
+ iframe: {
120
+ targetPublicKey: string;
121
+ redirectUrl: string;
122
+ expirationSeconds?: number;
123
+ };
124
+ }> & {
71
125
  email: string;
72
126
  };
73
127
  Response: {
@@ -137,10 +191,24 @@ declare abstract class SignerClient {
137
191
  type WebauthnSignInParams = {
138
192
  email: string;
139
193
  };
194
+ type EmailInitializeAuthParams = {
195
+ email: string;
196
+ redirectUrl: string;
197
+ expirationSeconds?: number;
198
+ };
199
+ type EmailCompleteAuthWithBundleParams = {
200
+ bundle: string;
201
+ subOrgId: string;
202
+ isNewUser?: boolean;
203
+ };
140
204
  type WebSignerClientConstructorParams = SignerClientInheritedConstructorParams<{
141
205
  webauthn: {
142
206
  rpId: string;
143
207
  };
208
+ iframe?: {
209
+ iframeElementId?: string;
210
+ iframeContainerId?: string;
211
+ };
144
212
  }>;
145
213
  /**
146
214
  * A signer client for web applications.
@@ -152,15 +220,58 @@ declare class WebSignerClient extends SignerClient {
152
220
  *
153
221
  * @param {WebSignerClientConstructorParams} params params for the constructor
154
222
  */
155
- constructor({ configuration, webauthn }: WebSignerClientConstructorParams);
223
+ constructor({ configuration, webauthn, iframe, }: WebSignerClientConstructorParams);
224
+ signRawMessage<Into extends string>(msg: string): Promise<Into>;
225
+ logout(): Promise<void>;
226
+ /**
227
+ * Checks for an existing session and if exists, updates the stamper accordingly.
228
+ *
229
+ */
230
+ private updateStamper;
156
231
  /**
157
232
  * Signs in a user with webauthn.
158
233
  *
159
234
  * @param {WebauthnSignInParams} params params for the sign in
160
235
  */
161
236
  webauthnSignIn({ email }: WebauthnSignInParams): Promise<void>;
237
+ /**
238
+ * Handle auth user process with email.
239
+ *
240
+ * @param {EmailInitializeAuthParams} params Params needed for the initialization of the auth process
241
+ */
242
+ emailAuth(params: EmailInitializeAuthParams): Promise<void>;
243
+ /**
244
+ * Signs in a user with email.
245
+ *
246
+ * @param {EmailInitializeAuthParams} params params for the sign in
247
+ */
248
+ private _signInWithEmail;
249
+ /**
250
+ * Completes the authentication process with a credential bundle.
251
+ *
252
+ * @param {EmailCompleteAuthWithBundleParams} params params for the completion of the auth process
253
+ */
254
+ completeAuthWithBundle({ bundle, subOrgId, }: EmailCompleteAuthWithBundleParams): Promise<void>;
255
+ /**
256
+ * Creates a passkey account using the webauthn stamper.
257
+ *
258
+ * @param {Extract<CreateAccountParams, { method: 'webauthn' }>} params params for the creation of the account
259
+ */
260
+ private _createWebauthnAccount;
261
+ /**
262
+ * Creates an email account using the iframe stamper.
263
+ *
264
+ * @param {Extract<CreateAccountParams, { method: 'email' }>} params params for the creation of the account
265
+ */
266
+ private _createEmailAccount;
267
+ /**
268
+ * Handle the account creation process.
269
+ *
270
+ * @param {CreateAccountParams} params params to create an account
271
+ */
162
272
  private _createAccount;
163
273
  private _webauthnGenerateAttestation;
274
+ private _initIframeStamper;
164
275
  }
165
276
 
166
277
  type CurrentUserToLightSmartAccountParams = {
@@ -213,6 +324,29 @@ declare class ViemModule {
213
324
  } | undefined): Promise<IsNarrowable<TransactionSerialized<GetTransactionType<transaction>>, Hex> extends true ? TransactionSerialized<GetTransactionType<transaction>> : Hex>;
214
325
  }
215
326
 
327
+ /**
328
+ * A module for interacting with the Email authentication methods.
329
+ * Available through the `auth.email` property on a `FourtWebSigner` instance.
330
+ */
331
+ declare class EmailModule {
332
+ private readonly _webSignerClient;
333
+ constructor(_webSignerClient: WebSignerClient);
334
+ /**
335
+ * Initialize user authentication process using email.
336
+ *
337
+ * @param params {EmailInitializeAuthParams} params to initialize the user authentication process.
338
+ * @returns {Promise<void>} promise that resolves to the result of the authentication process.
339
+ */
340
+ initialize(params: EmailInitializeAuthParams): Promise<void>;
341
+ /**
342
+ * Completes authentication with bundle after user receives the bundle and subOrgId as URL params.
343
+ *
344
+ * @param params {EmailCompleteAuthWithBundleParams} params received as URL params necessary to complete authentication process.
345
+ * @returns {Promise<void>} promise that completes the authentication process.
346
+ */
347
+ complete(params: EmailCompleteAuthWithBundleParams): Promise<void>;
348
+ }
349
+
216
350
  /**
217
351
  * A module for interacting with the Passkeys authentication methods.
218
352
  * Available through the `auth.passkeys` property on a `FourtWebSigner` instance.
@@ -236,6 +370,7 @@ declare class PasskeysModule {
236
370
  declare class AuthModule {
237
371
  private readonly _webSignerClient;
238
372
  private readonly _passkeys;
373
+ private readonly _email;
239
374
  /**
240
375
  * Initializes a new instance of the `AuthModule` class.
241
376
  *
@@ -246,6 +381,10 @@ declare class AuthModule {
246
381
  * A module for interacting with the Passkeys authentication methods.
247
382
  */
248
383
  get passkeys(): PasskeysModule;
384
+ /**
385
+ * A module for interacting with the Passkeys authentication methods.
386
+ */
387
+ get email(): EmailModule;
249
388
  }
250
389
 
251
390
  /**
@@ -271,12 +410,12 @@ declare class UserModule {
271
410
  *
272
411
  * @returns {void}
273
412
  */
274
- logout(): void;
413
+ logout(): Promise<void>;
275
414
  }
276
415
 
277
416
  type FourtWebSignerConstructorParams = {
278
417
  configuration: SignerClientConstructorParams['configuration'];
279
- auth: Pick<WebSignerClientConstructorParams, 'webauthn'>;
418
+ auth: Pick<WebSignerClientConstructorParams, 'webauthn' | 'iframe'>;
280
419
  };
281
420
  /**
282
421
  * A client for interacting with the Fourt Web Signer.
@@ -305,7 +444,7 @@ declare class FourtWebSigner {
305
444
  *
306
445
  * @param {FourtWebSignerConstructorParams} params the required parameters to initialize the client
307
446
  */
308
- constructor({ configuration, auth: { webauthn }, }: FourtWebSignerConstructorParams);
447
+ constructor({ configuration, auth: { webauthn, iframe }, }: FourtWebSignerConstructorParams);
309
448
  /**
310
449
  * A module for interacting with the Viem library.
311
450
  */