@bitwarden/sdk-internal 0.2.0-main.544 → 0.2.0-main.545

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/VERSION CHANGED
@@ -1 +1 @@
1
- 4ffddfe5fb69d3e93d110b4dda9db4ccd017b203
1
+ 598bd479f7f15321b103bd8bae193b6f7cc03cd2
@@ -180,11 +180,6 @@ export interface TokenProvider {
180
180
  get_access_token(): Promise<string | undefined>;
181
181
  }
182
182
 
183
- /**
184
- * Active feature flags for the SDK.
185
- */
186
- export interface FeatureFlags extends Map<string, boolean> {}
187
-
188
183
  export interface IndexedDbConfiguration {
189
184
  db_name: string;
190
185
  }
@@ -195,12 +190,9 @@ export interface Repositories {
195
190
  }
196
191
 
197
192
  /**
198
- * The credentials used for send access requests.
193
+ * Active feature flags for the SDK.
199
194
  */
200
- export type SendAccessCredentials =
201
- | SendPasswordCredentials
202
- | SendEmailOtpCredentials
203
- | SendEmailCredentials;
195
+ export interface FeatureFlags extends Map<string, boolean> {}
204
196
 
205
197
  /**
206
198
  * Credentials for getting a send access token using an email and OTP.
@@ -217,26 +209,26 @@ export interface SendEmailOtpCredentials {
217
209
  }
218
210
 
219
211
  /**
220
- * Credentials for sending password secured access requests.
221
- * Clone auto implements the standard lib\'s Clone trait, allowing us to create copies of this
222
- * struct.
212
+ * Credentials for sending an OTP to the user\'s email address.
213
+ * This is used when the send requires email verification with an OTP.
223
214
  */
224
- export interface SendPasswordCredentials {
215
+ export interface SendEmailCredentials {
225
216
  /**
226
- * A Base64-encoded hash of the password protecting the send.
217
+ * The email address to which the OTP will be sent.
227
218
  */
228
- passwordHashB64: string;
219
+ email: string;
229
220
  }
230
221
 
231
222
  /**
232
- * Credentials for sending an OTP to the user\'s email address.
233
- * This is used when the send requires email verification with an OTP.
223
+ * Credentials for sending password secured access requests.
224
+ * Clone auto implements the standard lib\'s Clone trait, allowing us to create copies of this
225
+ * struct.
234
226
  */
235
- export interface SendEmailCredentials {
227
+ export interface SendPasswordCredentials {
236
228
  /**
237
- * The email address to which the OTP will be sent.
229
+ * A Base64-encoded hash of the password protecting the send.
238
230
  */
239
- email: string;
231
+ passwordHashB64: string;
240
232
  }
241
233
 
242
234
  /**
@@ -254,12 +246,12 @@ export interface SendAccessTokenRequest {
254
246
  }
255
247
 
256
248
  /**
257
- * Represents errors that can occur when requesting a send access token.
258
- * It includes expected and unexpected API errors.
249
+ * The credentials used for send access requests.
259
250
  */
260
- export type SendAccessTokenError =
261
- | { kind: "unexpected"; data: UnexpectedIdentityError }
262
- | { kind: "expected"; data: SendAccessTokenApiErrorResponse };
251
+ export type SendAccessCredentials =
252
+ | SendPasswordCredentials
253
+ | SendEmailOtpCredentials
254
+ | SendEmailCredentials;
263
255
 
264
256
  /**
265
257
  * Any unexpected error that occurs when making requests to identity. This could be
@@ -285,6 +277,14 @@ export interface SendAccessTokenResponse {
285
277
  expiresAt: number;
286
278
  }
287
279
 
280
+ /**
281
+ * Represents errors that can occur when requesting a send access token.
282
+ * It includes expected and unexpected API errors.
283
+ */
284
+ export type SendAccessTokenError =
285
+ | { kind: "unexpected"; data: UnexpectedIdentityError }
286
+ | { kind: "expected"; data: SendAccessTokenApiErrorResponse };
287
+
288
288
  /**
289
289
  * Invalid request errors - typically due to missing parameters.
290
290
  */
@@ -325,31 +325,6 @@ export type SendAccessTokenInvalidGrantError =
325
325
  | "otp_generation_failed"
326
326
  | "unknown";
327
327
 
328
- /**
329
- * Result of TDE registration process.
330
- */
331
- export interface TdeRegistrationResponse {
332
- /**
333
- * The account cryptographic state of the user
334
- */
335
- account_cryptographic_state: WrappedAccountCryptographicState;
336
- /**
337
- * The device key
338
- */
339
- device_key: B64;
340
- /**
341
- * The decrypted user key. This can be used to get the consuming client to an unlocked state.
342
- */
343
- user_key: B64;
344
- }
345
-
346
- export interface RegistrationError extends Error {
347
- name: "RegistrationError";
348
- variant: "KeyConnectorApi" | "Api" | "Crypto";
349
- }
350
-
351
- export function isRegistrationError(error: any): error is RegistrationError;
352
-
353
328
  /**
354
329
  * Request parameters for SSO JIT master password registration.
355
330
  */
@@ -389,6 +364,33 @@ export interface JitMasterPasswordRegistrationRequest {
389
364
  reset_password_enroll: boolean;
390
365
  }
391
366
 
367
+ /**
368
+ * Request parameters for TDE (Trusted Device Encryption) registration.
369
+ */
370
+ export interface TdeRegistrationRequest {
371
+ /**
372
+ * Organization ID to enroll in
373
+ */
374
+ org_id: OrganizationId;
375
+ /**
376
+ * Organization\'s public key for encrypting the reset password key. This should be verified by
377
+ * the client and not verifying may compromise the security of the user\'s account.
378
+ */
379
+ org_public_key: B64;
380
+ /**
381
+ * User ID for the account being initialized
382
+ */
383
+ user_id: UserId;
384
+ /**
385
+ * Device identifier for TDE enrollment
386
+ */
387
+ device_identifier: string;
388
+ /**
389
+ * Whether to trust this device for TDE
390
+ */
391
+ trust_device: boolean;
392
+ }
393
+
392
394
  /**
393
395
  * Result of Key Connector registration process.
394
396
  */
@@ -412,30 +414,21 @@ export interface KeyConnectorRegistrationResult {
412
414
  }
413
415
 
414
416
  /**
415
- * Request parameters for TDE (Trusted Device Encryption) registration.
417
+ * Result of TDE registration process.
416
418
  */
417
- export interface TdeRegistrationRequest {
418
- /**
419
- * Organization ID to enroll in
420
- */
421
- org_id: OrganizationId;
422
- /**
423
- * Organization\'s public key for encrypting the reset password key. This should be verified by
424
- * the client and not verifying may compromise the security of the user\'s account.
425
- */
426
- org_public_key: B64;
419
+ export interface TdeRegistrationResponse {
427
420
  /**
428
- * User ID for the account being initialized
421
+ * The account cryptographic state of the user
429
422
  */
430
- user_id: UserId;
423
+ account_cryptographic_state: WrappedAccountCryptographicState;
431
424
  /**
432
- * Device identifier for TDE enrollment
425
+ * The device key
433
426
  */
434
- device_identifier: string;
427
+ device_key: B64;
435
428
  /**
436
- * Whether to trust this device for TDE
429
+ * The decrypted user key. This can be used to get the consuming client to an unlocked state.
437
430
  */
438
- trust_device: boolean;
431
+ user_key: B64;
439
432
  }
440
433
 
441
434
  /**
@@ -456,6 +449,269 @@ export interface JitMasterPasswordRegistrationResponse {
456
449
  user_key: B64;
457
450
  }
458
451
 
452
+ export interface RegistrationError extends Error {
453
+ name: "RegistrationError";
454
+ variant: "KeyConnectorApi" | "Api" | "Crypto";
455
+ }
456
+
457
+ export function isRegistrationError(error: any): error is RegistrationError;
458
+
459
+ export interface PasswordPreloginError extends Error {
460
+ name: "PasswordPreloginError";
461
+ variant: "Api" | "Unknown";
462
+ }
463
+
464
+ export function isPasswordPreloginError(error: any): error is PasswordPreloginError;
465
+
466
+ export interface PasswordLoginError extends Error {
467
+ name: "PasswordLoginError";
468
+ variant: "InvalidUsernameOrPassword" | "PasswordAuthenticationDataDerivation" | "Unknown";
469
+ }
470
+
471
+ export function isPasswordLoginError(error: any): error is PasswordLoginError;
472
+
473
+ /**
474
+ * Public SDK request model for logging in via password
475
+ */
476
+ export interface PasswordLoginRequest {
477
+ /**
478
+ * Common login request fields
479
+ */
480
+ loginRequest: LoginRequest;
481
+ /**
482
+ * User\'s email address
483
+ */
484
+ email: string;
485
+ /**
486
+ * User\'s master password
487
+ */
488
+ password: string;
489
+ /**
490
+ * Prelogin data required for password authentication
491
+ * (e.g., KDF configuration for deriving the master key)
492
+ */
493
+ preloginResponse: PasswordPreloginResponse;
494
+ }
495
+
496
+ /**
497
+ * Response containing the data required before password-based authentication
498
+ */
499
+ export interface PasswordPreloginResponse {
500
+ /**
501
+ * The Key Derivation Function (KDF) configuration for the user
502
+ */
503
+ kdf: Kdf;
504
+ /**
505
+ * The salt used in the KDF process
506
+ */
507
+ salt: string;
508
+ }
509
+
510
+ /**
511
+ * The common bucket of login fields to be re-used across all login mechanisms
512
+ * (e.g., password, SSO, etc.). This will include handling client_id and 2FA.
513
+ */
514
+ export interface LoginRequest {
515
+ /**
516
+ * OAuth client identifier
517
+ */
518
+ clientId: string;
519
+ /**
520
+ * Device information for this login request
521
+ */
522
+ device: LoginDeviceRequest;
523
+ }
524
+
525
+ /**
526
+ * Common login response model used across different login methods.
527
+ */
528
+ export type LoginResponse = { Authenticated: LoginSuccessResponse };
529
+
530
+ /**
531
+ * Device information for login requests.
532
+ * This is common across all login mechanisms and describes the device
533
+ * making the authentication request.
534
+ */
535
+ export interface LoginDeviceRequest {
536
+ /**
537
+ * The type of device making the login request
538
+ * Note: today, we already have the DeviceType on the ApiConfigurations
539
+ * but we do not have the other device fields so we will accept the device data at login time
540
+ * for now. In the future, we might refactor the unauthN client to instantiate with full
541
+ * device info which would deprecate this struct. However, using the device_type here
542
+ * allows us to avoid any timing issues in scenarios where the device type could change
543
+ * between client instantiation and login (unlikely but possible).
544
+ */
545
+ deviceType: DeviceType;
546
+ /**
547
+ * Unique identifier for the device
548
+ */
549
+ deviceIdentifier: string;
550
+ /**
551
+ * Human-readable name of the device
552
+ */
553
+ deviceName: string;
554
+ /**
555
+ * Push notification token for the device (only for mobile devices)
556
+ */
557
+ devicePushToken: string | undefined;
558
+ }
559
+
560
+ /**
561
+ * SDK response model for a successful login.
562
+ * This is the model that will be exposed to consuming applications.
563
+ */
564
+ export interface LoginSuccessResponse {
565
+ /**
566
+ * The access token string.
567
+ */
568
+ accessToken: string;
569
+ /**
570
+ * The duration in seconds until the token expires.
571
+ */
572
+ expiresIn: number;
573
+ /**
574
+ * The timestamp in milliseconds when the token expires.
575
+ * We calculate this for more convenient token expiration handling.
576
+ */
577
+ expiresAt: number;
578
+ /**
579
+ * The scope of the access token.
580
+ * OAuth 2.0 RFC reference: <https://datatracker.ietf.org/doc/html/rfc6749#section-3.3>
581
+ */
582
+ scope: string;
583
+ /**
584
+ * The type of the token.
585
+ * This will be \"Bearer\" for send access tokens.
586
+ * OAuth 2.0 RFC reference: <https://datatracker.ietf.org/doc/html/rfc6749#section-7.1>
587
+ */
588
+ tokenType: string;
589
+ /**
590
+ * The optional refresh token string.
591
+ * This token can be used to obtain new access tokens when the current one expires.
592
+ */
593
+ refreshToken: string | undefined;
594
+ /**
595
+ * The user key wrapped user private key.
596
+ * Note: previously known as \"private_key\".
597
+ */
598
+ userKeyWrappedUserPrivateKey: string | undefined;
599
+ /**
600
+ * Two-factor authentication token for future requests.
601
+ */
602
+ twoFactorToken: string | undefined;
603
+ /**
604
+ * Indicates whether an admin has reset the user\'s master password,
605
+ * requiring them to set a new password upon next login.
606
+ */
607
+ forcePasswordReset: boolean | undefined;
608
+ /**
609
+ * Indicates whether the user uses Key Connector and if the client should have a locally
610
+ * configured Key Connector URL in their environment.
611
+ * Note: This is currently only applicable for client_credential grant type logins and
612
+ * is only expected to be relevant for the CLI
613
+ */
614
+ apiUseKeyConnector: boolean | undefined;
615
+ /**
616
+ * The user\'s decryption options for unlocking their vault.
617
+ */
618
+ userDecryptionOptions: UserDecryptionOptionsResponse;
619
+ /**
620
+ * If the user is subject to an organization master password policy,
621
+ * this field contains the requirements of that policy.
622
+ */
623
+ masterPasswordPolicy: MasterPasswordPolicyResponse | undefined;
624
+ }
625
+
626
+ /**
627
+ * SDK domain model for user decryption options.
628
+ * Provides the various methods available to unlock a user\'s vault.
629
+ */
630
+ export interface UserDecryptionOptionsResponse {
631
+ /**
632
+ * Master password unlock option. None if user doesn\'t have a master password.
633
+ */
634
+ masterPasswordUnlock?: MasterPasswordUnlockData;
635
+ /**
636
+ * Trusted Device decryption option.
637
+ */
638
+ trustedDeviceOption?: TrustedDeviceUserDecryptionOption;
639
+ /**
640
+ * Key Connector decryption option.
641
+ * Mutually exclusive with Trusted Device option.
642
+ */
643
+ keyConnectorOption?: KeyConnectorUserDecryptionOption;
644
+ /**
645
+ * WebAuthn PRF decryption option.
646
+ */
647
+ webauthnPrfOption?: WebAuthnPrfUserDecryptionOption;
648
+ }
649
+
650
+ /**
651
+ * SDK domain model for WebAuthn PRF user decryption option.
652
+ */
653
+ export interface WebAuthnPrfUserDecryptionOption {
654
+ /**
655
+ * PRF key encrypted private key
656
+ */
657
+ encryptedPrivateKey: EncString;
658
+ /**
659
+ * Public Key encrypted user key
660
+ */
661
+ encryptedUserKey: UnsignedSharedKey;
662
+ /**
663
+ * Credential ID for this WebAuthn PRF credential.
664
+ * TODO: PM-32163 - can remove `Option<T>` after 3 releases from server v2026.1.1
665
+ */
666
+ credentialId: string | undefined;
667
+ /**
668
+ * Transport methods available for this credential (e.g., \"usb\", \"nfc\", \"ble\", \"internal\",
669
+ * \"hybrid\").
670
+ * TODO: PM-32163 - can remove `Option<T>` after 3 releases from server v2026.1.1
671
+ */
672
+ transports: string[] | undefined;
673
+ }
674
+
675
+ /**
676
+ * SDK domain model for Key Connector user decryption option.
677
+ */
678
+ export interface KeyConnectorUserDecryptionOption {
679
+ /**
680
+ * URL of the Key Connector server to use for decryption.
681
+ */
682
+ keyConnectorUrl: string;
683
+ }
684
+
685
+ /**
686
+ * SDK domain model for Trusted Device user decryption option.
687
+ */
688
+ export interface TrustedDeviceUserDecryptionOption {
689
+ /**
690
+ * Whether the user has admin approval for device login.
691
+ */
692
+ hasAdminApproval: boolean;
693
+ /**
694
+ * Whether the user has a device that can approve logins.
695
+ */
696
+ hasLoginApprovingDevice: boolean;
697
+ /**
698
+ * Whether the user has permission to manage password reset for other users.
699
+ */
700
+ hasManageResetPasswordPermission: boolean;
701
+ /**
702
+ * Whether the user is in TDE offboarding.
703
+ */
704
+ isTdeOffboarding: boolean;
705
+ /**
706
+ * The device key encrypted device private key. Only present if the device is trusted.
707
+ */
708
+ encryptedPrivateKey?: EncString;
709
+ /**
710
+ * The device private key encrypted user key. Only present if the device is trusted.
711
+ */
712
+ encryptedUserKey?: UnsignedSharedKey;
713
+ }
714
+
459
715
  export interface Collection {
460
716
  id: CollectionId | undefined;
461
717
  organizationId: OrganizationId;
@@ -1263,6 +1519,45 @@ export type Endpoint =
1263
1519
  | "DesktopRenderer"
1264
1520
  | "DesktopMain";
1265
1521
 
1522
+ /**
1523
+ * SDK domain model for master password policy requirements.
1524
+ * Defines the complexity requirements for a user\'s master password
1525
+ * when enforced by an organization policy.
1526
+ */
1527
+ export interface MasterPasswordPolicyResponse {
1528
+ /**
1529
+ * The minimum complexity score required for the master password.
1530
+ * Complexity is calculated based on password strength metrics.
1531
+ */
1532
+ minComplexity?: number;
1533
+ /**
1534
+ * The minimum length required for the master password.
1535
+ */
1536
+ minLength?: number;
1537
+ /**
1538
+ * Whether the master password must contain at least one lowercase letter.
1539
+ */
1540
+ requireLower?: boolean;
1541
+ /**
1542
+ * Whether the master password must contain at least one uppercase letter.
1543
+ */
1544
+ requireUpper?: boolean;
1545
+ /**
1546
+ * Whether the master password must contain at least one numeric digit.
1547
+ */
1548
+ requireNumbers?: boolean;
1549
+ /**
1550
+ * Whether the master password must contain at least one special character.
1551
+ */
1552
+ requireSpecial?: boolean;
1553
+ /**
1554
+ * Whether this policy should be enforced when the user logs in.
1555
+ * If true, the user will be required to update their master password
1556
+ * if it doesn\'t meet the policy requirements.
1557
+ */
1558
+ enforceOnLogin?: boolean;
1559
+ }
1560
+
1266
1561
  export interface ServerCommunicationConfigRepositoryError extends Error {
1267
1562
  name: "ServerCommunicationConfigRepositoryError";
1268
1563
  variant: "GetError" | "SaveError";
@@ -2350,9 +2645,9 @@ export class AuthClient {
2350
2645
  */
2351
2646
  registration(): RegistrationClient;
2352
2647
  /**
2353
- * Client for identity functionality
2648
+ * Client for login functionality
2354
2649
  */
2355
- identity(): IdentityClient;
2650
+ login(client_settings: ClientSettings): LoginClient;
2356
2651
  }
2357
2652
  /**
2358
2653
  * Client for performing admin operations on ciphers. Unlike the regular CiphersClient,
@@ -2789,14 +3084,6 @@ export class GeneratorClient {
2789
3084
  */
2790
3085
  password(input: PasswordGeneratorRequest): string;
2791
3086
  }
2792
- /**
2793
- * The IdentityClient is used to obtain identity / access tokens from the Bitwarden Identity API.
2794
- */
2795
- export class IdentityClient {
2796
- private constructor();
2797
- free(): void;
2798
- [Symbol.dispose](): void;
2799
- }
2800
3087
  export class IncomingMessage {
2801
3088
  free(): void;
2802
3089
  [Symbol.dispose](): void;
@@ -2863,6 +3150,88 @@ export class IpcCommunicationBackend {
2863
3150
  */
2864
3151
  receive(message: IncomingMessage): void;
2865
3152
  }
3153
+ /**
3154
+ * Client for authenticating Bitwarden users.
3155
+ *
3156
+ * Handles unauthenticated operations to obtain access tokens from the Identity API.
3157
+ * After successful authentication, use the returned tokens to create an authenticated core client.
3158
+ *
3159
+ * # Lifecycle
3160
+ *
3161
+ * 1. Create `LoginClient` via `AuthClient`
3162
+ * 2. Call login method
3163
+ * 3. Use returned tokens with authenticated core client
3164
+ *
3165
+ * # Password Login Example
3166
+ *
3167
+ * ```rust,no_run
3168
+ * # use bitwarden_auth::{AuthClient, login::login_via_password::PasswordLoginRequest};
3169
+ * # use bitwarden_auth::login::models::{LoginRequest, LoginDeviceRequest, LoginResponse};
3170
+ * # use bitwarden_core::{Client, ClientSettings, DeviceType};
3171
+ * # async fn example(email: String, password: String) -> Result<(), Box<dyn std::error::Error>> {
3172
+ * // Create auth client
3173
+ * let client = Client::new(None);
3174
+ * let auth_client = AuthClient::new(client);
3175
+ *
3176
+ * // Configure client settings and create login client
3177
+ * let settings = ClientSettings {
3178
+ * identity_url: "https://identity.bitwarden.com".to_string(),
3179
+ * api_url: "https://api.bitwarden.com".to_string(),
3180
+ * user_agent: "MyApp/1.0".to_string(),
3181
+ * device_type: DeviceType::SDK,
3182
+ * device_identifier: None,
3183
+ * bitwarden_client_version: None,
3184
+ * bitwarden_package_type: None,
3185
+ * };
3186
+ * let login_client = auth_client.login(settings);
3187
+ *
3188
+ * // Get user's KDF config
3189
+ * let prelogin = login_client.get_password_prelogin(email.clone()).await?;
3190
+ *
3191
+ * // Login with credentials
3192
+ * let response = login_client.login_via_password(PasswordLoginRequest {
3193
+ * login_request: LoginRequest {
3194
+ * client_id: "connector".to_string(),
3195
+ * device: LoginDeviceRequest {
3196
+ * device_type: DeviceType::SDK,
3197
+ * device_identifier: "device-id".to_string(),
3198
+ * device_name: "My Device".to_string(),
3199
+ * device_push_token: None,
3200
+ * },
3201
+ * },
3202
+ * email,
3203
+ * password,
3204
+ * prelogin_response: prelogin,
3205
+ * }).await?;
3206
+ *
3207
+ * // Use tokens from response for authenticated requests
3208
+ * match response {
3209
+ * LoginResponse::Authenticated(success) => {
3210
+ * let access_token = success.access_token;
3211
+ * // Use access_token for authenticated requests
3212
+ * }
3213
+ * }
3214
+ * # Ok(())
3215
+ * # }
3216
+ * ```
3217
+ */
3218
+ export class LoginClient {
3219
+ private constructor();
3220
+ free(): void;
3221
+ [Symbol.dispose](): void;
3222
+ /**
3223
+ * Retrieves the data required before authenticating with a password.
3224
+ * This includes the user's KDF configuration needed to properly derive the master key.
3225
+ */
3226
+ get_password_prelogin(email: string): Promise<PasswordPreloginResponse>;
3227
+ /**
3228
+ * Authenticates a user via email and master password.
3229
+ *
3230
+ * Derives the master password hash using KDF settings from prelogin, then sends
3231
+ * the authentication request to obtain access tokens and vault keys.
3232
+ */
3233
+ login_via_password(request: PasswordLoginRequest): Promise<LoginResponse>;
3234
+ }
2866
3235
  export class OutgoingMessage {
2867
3236
  free(): void;
2868
3237
  [Symbol.dispose](): void;