@bitwarden/sdk-internal 0.2.0-main.40 → 0.2.0-main.400

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.
@@ -1,6 +1,109 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
- export function generate_ssh_key(key_algorithm: KeyAlgorithm): GenerateSshKeyResult;
3
+ export function init_sdk(log_level?: LogLevel | null): void;
4
+ /**
5
+ * Generate a new SSH key pair
6
+ *
7
+ * # Arguments
8
+ * - `key_algorithm` - The algorithm to use for the key pair
9
+ *
10
+ * # Returns
11
+ * - `Ok(SshKey)` if the key was successfully generated
12
+ * - `Err(KeyGenerationError)` if the key could not be generated
13
+ */
14
+ export function generate_ssh_key(key_algorithm: KeyAlgorithm): SshKeyView;
15
+ /**
16
+ * Convert a PCKS8 or OpenSSH encrypted or unencrypted private key
17
+ * to an OpenSSH private key with public key and fingerprint
18
+ *
19
+ * # Arguments
20
+ * - `imported_key` - The private key to convert
21
+ * - `password` - The password to use for decrypting the key
22
+ *
23
+ * # Returns
24
+ * - `Ok(SshKey)` if the key was successfully coneverted
25
+ * - `Err(PasswordRequired)` if the key is encrypted and no password was provided
26
+ * - `Err(WrongPassword)` if the password provided is incorrect
27
+ * - `Err(ParsingError)` if the key could not be parsed
28
+ * - `Err(UnsupportedKeyType)` if the key type is not supported
29
+ */
30
+ export function import_ssh_key(imported_key: string, password?: string | null): SshKeyView;
31
+ /**
32
+ * Registers a DiscoverHandler so that the client can respond to DiscoverRequests.
33
+ */
34
+ export function ipcRegisterDiscoverHandler(
35
+ ipc_client: IpcClient,
36
+ response: DiscoverResponse,
37
+ ): Promise<void>;
38
+ /**
39
+ * Sends a DiscoverRequest to the specified destination and returns the response.
40
+ */
41
+ export function ipcRequestDiscover(
42
+ ipc_client: IpcClient,
43
+ destination: Endpoint,
44
+ abort_signal?: AbortSignal | null,
45
+ ): Promise<DiscoverResponse>;
46
+ export enum CardLinkedIdType {
47
+ CardholderName = 300,
48
+ ExpMonth = 301,
49
+ ExpYear = 302,
50
+ Code = 303,
51
+ Brand = 304,
52
+ Number = 305,
53
+ }
54
+ export enum CipherRepromptType {
55
+ None = 0,
56
+ Password = 1,
57
+ }
58
+ export enum CipherType {
59
+ Login = 1,
60
+ SecureNote = 2,
61
+ Card = 3,
62
+ Identity = 4,
63
+ SshKey = 5,
64
+ }
65
+ /**
66
+ * Represents the type of a [FieldView].
67
+ */
68
+ export enum FieldType {
69
+ /**
70
+ * Text field
71
+ */
72
+ Text = 0,
73
+ /**
74
+ * Hidden text field
75
+ */
76
+ Hidden = 1,
77
+ /**
78
+ * Boolean field
79
+ */
80
+ Boolean = 2,
81
+ /**
82
+ * Linked field
83
+ */
84
+ Linked = 3,
85
+ }
86
+ export enum IdentityLinkedIdType {
87
+ Title = 400,
88
+ MiddleName = 401,
89
+ Address1 = 402,
90
+ Address2 = 403,
91
+ Address3 = 404,
92
+ City = 405,
93
+ State = 406,
94
+ PostalCode = 407,
95
+ Country = 408,
96
+ Company = 409,
97
+ Email = 410,
98
+ Phone = 411,
99
+ Ssn = 412,
100
+ Username = 413,
101
+ PassportNumber = 414,
102
+ LicenseNumber = 415,
103
+ FirstName = 416,
104
+ LastName = 417,
105
+ FullName = 418,
106
+ }
4
107
  export enum LogLevel {
5
108
  Trace = 0,
6
109
  Debug = 1,
@@ -8,7 +111,263 @@ export enum LogLevel {
8
111
  Warn = 3,
9
112
  Error = 4,
10
113
  }
114
+ export enum LoginLinkedIdType {
115
+ Username = 100,
116
+ Password = 101,
117
+ }
118
+ export enum SecureNoteType {
119
+ Generic = 0,
120
+ }
121
+ export enum UriMatchType {
122
+ Domain = 0,
123
+ Host = 1,
124
+ StartsWith = 2,
125
+ Exact = 3,
126
+ RegularExpression = 4,
127
+ Never = 5,
128
+ }
129
+
130
+ /**
131
+ * @deprecated Use PasswordManagerClient instead
132
+ */
133
+ export type BitwardenClient = PasswordManagerClient;
134
+
135
+ import { Tagged } from "type-fest";
136
+
137
+ /**
138
+ * A string that **MUST** be a valid UUID.
139
+ *
140
+ * Never create or cast to this type directly, use the `uuid<T>()` function instead.
141
+ */
142
+ export type Uuid = unknown;
143
+
144
+ /**
145
+ * RFC3339 compliant date-time string.
146
+ * @typeParam T - Not used in JavaScript.
147
+ */
148
+ export type DateTime<T = unknown> = string;
149
+
150
+ /**
151
+ * UTC date-time string. Not used in JavaScript.
152
+ */
153
+ export type Utc = unknown;
154
+
155
+ /**
156
+ * An integer that is known not to equal zero.
157
+ */
158
+ export type NonZeroU32 = number;
159
+
160
+ export interface Repository<T> {
161
+ get(id: string): Promise<T | null>;
162
+ list(): Promise<T[]>;
163
+ set(id: string, value: T): Promise<void>;
164
+ remove(id: string): Promise<void>;
165
+ }
166
+
167
+ export interface TokenProvider {
168
+ get_access_token(): Promise<string | undefined>;
169
+ }
170
+
171
+ /**
172
+ * Active feature flags for the SDK.
173
+ */
174
+ export interface FeatureFlags extends Map<string, boolean> {}
175
+
176
+ export interface Repositories {
177
+ cipher: Repository<Cipher> | null;
178
+ folder: Repository<Folder> | null;
179
+ }
180
+
181
+ export interface IndexedDbConfiguration {
182
+ db_name: string;
183
+ }
184
+
185
+ export interface TestError extends Error {
186
+ name: "TestError";
187
+ }
188
+
189
+ export function isTestError(error: any): error is TestError;
190
+
191
+ /**
192
+ * Represents the possible, expected errors that can occur when requesting a send access token.
193
+ */
194
+ export type SendAccessTokenApiErrorResponse =
195
+ | {
196
+ error: "invalid_request";
197
+ error_description?: string;
198
+ send_access_error_type?: SendAccessTokenInvalidRequestError;
199
+ }
200
+ | {
201
+ error: "invalid_grant";
202
+ error_description?: string;
203
+ send_access_error_type?: SendAccessTokenInvalidGrantError;
204
+ }
205
+ | { error: "invalid_client"; error_description?: string }
206
+ | { error: "unauthorized_client"; error_description?: string }
207
+ | { error: "unsupported_grant_type"; error_description?: string }
208
+ | { error: "invalid_scope"; error_description?: string }
209
+ | { error: "invalid_target"; error_description?: string };
210
+
211
+ /**
212
+ * Invalid grant errors - typically due to invalid credentials.
213
+ */
214
+ export type SendAccessTokenInvalidGrantError =
215
+ | "send_id_invalid"
216
+ | "password_hash_b64_invalid"
217
+ | "email_invalid"
218
+ | "otp_invalid"
219
+ | "otp_generation_failed"
220
+ | "unknown";
221
+
222
+ /**
223
+ * Invalid request errors - typically due to missing parameters.
224
+ */
225
+ export type SendAccessTokenInvalidRequestError =
226
+ | "send_id_required"
227
+ | "password_hash_b64_required"
228
+ | "email_required"
229
+ | "email_and_otp_required_otp_sent"
230
+ | "unknown";
231
+
232
+ /**
233
+ * Any unexpected error that occurs when making requests to identity. This could be
234
+ * local/transport/decoding failure from the HTTP client (DNS/TLS/connect/read timeout,
235
+ * connection reset, or JSON decode failure on a success response) or non-2xx response with an
236
+ * unexpected body or status. Used when decoding the server\'s error payload into
237
+ * `SendAccessTokenApiErrorResponse` fails, or for 5xx responses where no structured error is
238
+ * available.
239
+ */
240
+ export type UnexpectedIdentityError = string;
241
+
242
+ /**
243
+ * Represents errors that can occur when requesting a send access token.
244
+ * It includes expected and unexpected API errors.
245
+ */
246
+ export type SendAccessTokenError =
247
+ | { kind: "unexpected"; data: UnexpectedIdentityError }
248
+ | { kind: "expected"; data: SendAccessTokenApiErrorResponse };
249
+
250
+ /**
251
+ * A send access token which can be used to access a send.
252
+ */
253
+ export interface SendAccessTokenResponse {
254
+ /**
255
+ * The actual token string.
256
+ */
257
+ token: string;
258
+ /**
259
+ * The timestamp in milliseconds when the token expires.
260
+ */
261
+ expiresAt: number;
262
+ }
263
+
264
+ /**
265
+ * A request structure for requesting a send access token from the API.
266
+ */
267
+ export interface SendAccessTokenRequest {
268
+ /**
269
+ * The id of the send for which the access token is requested.
270
+ */
271
+ sendId: string;
272
+ /**
273
+ * The optional send access credentials.
274
+ */
275
+ sendAccessCredentials?: SendAccessCredentials;
276
+ }
277
+
278
+ /**
279
+ * The credentials used for send access requests.
280
+ */
281
+ export type SendAccessCredentials =
282
+ | SendPasswordCredentials
283
+ | SendEmailCredentials
284
+ | SendEmailOtpCredentials;
285
+
286
+ /**
287
+ * Credentials for getting a send access token using an email and OTP.
288
+ */
289
+ export interface SendEmailOtpCredentials {
290
+ /**
291
+ * The email address to which the OTP will be sent.
292
+ */
293
+ email: string;
294
+ /**
295
+ * The one-time password (OTP) that the user has received via email.
296
+ */
297
+ otp: string;
298
+ }
299
+
300
+ /**
301
+ * Credentials for sending an OTP to the user\'s email address.
302
+ * This is used when the send requires email verification with an OTP.
303
+ */
304
+ export interface SendEmailCredentials {
305
+ /**
306
+ * The email address to which the OTP will be sent.
307
+ */
308
+ email: string;
309
+ }
310
+
311
+ /**
312
+ * Credentials for sending password secured access requests.
313
+ * Clone auto implements the standard lib\'s Clone trait, allowing us to create copies of this
314
+ * struct.
315
+ */
316
+ export interface SendPasswordCredentials {
317
+ /**
318
+ * A Base64-encoded hash of the password protecting the send.
319
+ */
320
+ passwordHashB64: string;
321
+ }
322
+
323
+ /**
324
+ * NewType wrapper for `CollectionId`
325
+ */
326
+ export type CollectionId = Tagged<Uuid, "CollectionId">;
327
+
328
+ export interface Collection {
329
+ id: CollectionId | undefined;
330
+ organizationId: OrganizationId;
331
+ name: EncString;
332
+ externalId: string | undefined;
333
+ hidePasswords: boolean;
334
+ readOnly: boolean;
335
+ manage: boolean;
336
+ defaultUserCollectionEmail: string | undefined;
337
+ type: CollectionType;
338
+ }
339
+
340
+ export interface CollectionView {
341
+ id: CollectionId | undefined;
342
+ organizationId: OrganizationId;
343
+ name: string;
344
+ externalId: string | undefined;
345
+ hidePasswords: boolean;
346
+ readOnly: boolean;
347
+ manage: boolean;
348
+ type: CollectionType;
349
+ }
350
+
351
+ /**
352
+ * Type of collection
353
+ */
354
+ export type CollectionType = "SharedCollection" | "DefaultUserCollection";
355
+
356
+ export interface CollectionDecryptError extends Error {
357
+ name: "CollectionDecryptError";
358
+ variant: "Crypto";
359
+ }
360
+
361
+ export function isCollectionDecryptError(error: any): error is CollectionDecryptError;
362
+
363
+ /**
364
+ * State used for initializing the user cryptographic state.
365
+ */
11
366
  export interface InitUserCryptoRequest {
367
+ /**
368
+ * The user\'s ID.
369
+ */
370
+ userId: UserId | undefined;
12
371
  /**
13
372
  * The user\'s KDF parameters, as received from the prelogin request
14
373
  */
@@ -20,64 +379,174 @@ export interface InitUserCryptoRequest {
20
379
  /**
21
380
  * The user\'s encrypted private key
22
381
  */
23
- privateKey: string;
382
+ privateKey: EncString;
383
+ /**
384
+ * The user\'s signing key
385
+ */
386
+ signingKey: EncString | undefined;
387
+ /**
388
+ * The user\'s security state
389
+ */
390
+ securityState: SignedSecurityState | undefined;
24
391
  /**
25
392
  * The initialization method to use
26
393
  */
27
394
  method: InitUserCryptoMethod;
28
395
  }
29
396
 
397
+ /**
398
+ * The crypto method used to initialize the user cryptographic state.
399
+ */
30
400
  export type InitUserCryptoMethod =
31
- | { password: { password: string; user_key: string } }
401
+ | { password: { password: string; user_key: EncString } }
402
+ | { masterPasswordUnlock: { password: string; master_password_unlock: MasterPasswordUnlockData } }
32
403
  | { decryptedKey: { decrypted_user_key: string } }
33
404
  | { pin: { pin: string; pin_protected_user_key: EncString } }
34
- | { authRequest: { request_private_key: string; method: AuthRequestMethod } }
405
+ | { pinEnvelope: { pin: string; pin_protected_user_key_envelope: PasswordProtectedKeyEnvelope } }
406
+ | { authRequest: { request_private_key: B64; method: AuthRequestMethod } }
35
407
  | {
36
408
  deviceKey: {
37
409
  device_key: string;
38
410
  protected_device_private_key: EncString;
39
- device_protected_user_key: AsymmetricEncString;
411
+ device_protected_user_key: UnsignedSharedKey;
40
412
  };
41
413
  }
42
- | { keyConnector: { master_key: string; user_key: string } };
414
+ | { keyConnector: { master_key: B64; user_key: EncString } };
43
415
 
416
+ /**
417
+ * Auth requests supports multiple initialization methods.
418
+ */
44
419
  export type AuthRequestMethod =
45
- | { userKey: { protected_user_key: AsymmetricEncString } }
46
- | { masterKey: { protected_master_key: AsymmetricEncString; auth_request_key: EncString } };
420
+ | { userKey: { protected_user_key: UnsignedSharedKey } }
421
+ | { masterKey: { protected_master_key: UnsignedSharedKey; auth_request_key: EncString } };
47
422
 
423
+ /**
424
+ * Represents the request to initialize the user\'s organizational cryptographic state.
425
+ */
48
426
  export interface InitOrgCryptoRequest {
49
427
  /**
50
428
  * The encryption keys for all the organizations the user is a part of
51
429
  */
52
- organizationKeys: Map<Uuid, AsymmetricEncString>;
430
+ organizationKeys: Map<OrganizationId, UnsignedSharedKey>;
431
+ }
432
+
433
+ /**
434
+ * Response from the `update_kdf` function
435
+ */
436
+ export interface UpdateKdfResponse {
437
+ /**
438
+ * The authentication data for the new KDF setting
439
+ */
440
+ masterPasswordAuthenticationData: MasterPasswordAuthenticationData;
441
+ /**
442
+ * The unlock data for the new KDF setting
443
+ */
444
+ masterPasswordUnlockData: MasterPasswordUnlockData;
445
+ /**
446
+ * The authentication data for the KDF setting prior to the change
447
+ */
448
+ oldMasterPasswordAuthenticationData: MasterPasswordAuthenticationData;
449
+ }
450
+
451
+ /**
452
+ * Response from the `make_update_password` function
453
+ */
454
+ export interface UpdatePasswordResponse {
455
+ /**
456
+ * Hash of the new password
457
+ */
458
+ passwordHash: B64;
459
+ /**
460
+ * User key, encrypted with the new password
461
+ */
462
+ newKey: EncString;
463
+ }
464
+
465
+ /**
466
+ * Request for deriving a pin protected user key
467
+ */
468
+ export interface EnrollPinResponse {
469
+ /**
470
+ * [UserKey] protected by PIN
471
+ */
472
+ pinProtectedUserKeyEnvelope: PasswordProtectedKeyEnvelope;
473
+ /**
474
+ * PIN protected by [UserKey]
475
+ */
476
+ userKeyEncryptedPin: EncString;
477
+ }
478
+
479
+ /**
480
+ * Request for deriving a pin protected user key
481
+ */
482
+ export interface DerivePinKeyResponse {
483
+ /**
484
+ * [UserKey] protected by PIN
485
+ */
486
+ pinProtectedUserKey: EncString;
487
+ /**
488
+ * PIN protected by [UserKey]
489
+ */
490
+ encryptedPin: EncString;
491
+ }
492
+
493
+ /**
494
+ * Request for migrating an account from password to key connector.
495
+ */
496
+ export interface DeriveKeyConnectorRequest {
497
+ /**
498
+ * Encrypted user key, used to validate the master key
499
+ */
500
+ userKeyEncrypted: EncString;
501
+ /**
502
+ * The user\'s master password
503
+ */
504
+ password: string;
505
+ /**
506
+ * The KDF parameters used to derive the master key
507
+ */
508
+ kdf: Kdf;
509
+ /**
510
+ * The user\'s email address
511
+ */
512
+ email: string;
53
513
  }
54
514
 
515
+ /**
516
+ * Response from the `make_key_pair` function
517
+ */
55
518
  export interface MakeKeyPairResponse {
56
519
  /**
57
520
  * The user\'s public key
58
521
  */
59
- userPublicKey: string;
522
+ userPublicKey: B64;
60
523
  /**
61
524
  * User\'s private key, encrypted with the user key
62
525
  */
63
526
  userKeyEncryptedPrivateKey: EncString;
64
527
  }
65
528
 
529
+ /**
530
+ * Request for `verify_asymmetric_keys`.
531
+ */
66
532
  export interface VerifyAsymmetricKeysRequest {
67
533
  /**
68
534
  * The user\'s user key
69
535
  */
70
- userKey: string;
536
+ userKey: B64;
71
537
  /**
72
538
  * The user\'s public key
73
539
  */
74
- userPublicKey: string;
540
+ userPublicKey: B64;
75
541
  /**
76
542
  * User\'s private key, encrypted with the user key
77
543
  */
78
544
  userKeyEncryptedPrivateKey: EncString;
79
545
  }
80
546
 
547
+ /**
548
+ * Response for `verify_asymmetric_keys`.
549
+ */
81
550
  export interface VerifyAsymmetricKeysResponse {
82
551
  /**
83
552
  * Whether the user\'s private key was decryptable by the user key.
@@ -89,42 +558,141 @@ export interface VerifyAsymmetricKeysResponse {
89
558
  validPrivateKey: boolean;
90
559
  }
91
560
 
92
- export interface CoreError extends Error {
93
- name: "CoreError";
94
- variant:
95
- | "MissingFieldError"
96
- | "VaultLocked"
97
- | "NotAuthenticated"
98
- | "AccessTokenInvalid"
99
- | "InvalidResponse"
100
- | "Crypto"
101
- | "IdentityFail"
102
- | "Reqwest"
103
- | "Serde"
104
- | "Io"
105
- | "InvalidBase64"
106
- | "Chrono"
107
- | "ResponseContent"
108
- | "ValidationError"
109
- | "InvalidStateFileVersion"
110
- | "InvalidStateFile"
111
- | "Internal"
112
- | "EncryptionSettings";
561
+ /**
562
+ * Response for the `make_keys_for_user_crypto_v2`, containing a set of keys for a user
563
+ */
564
+ export interface UserCryptoV2KeysResponse {
565
+ /**
566
+ * User key
567
+ */
568
+ userKey: B64;
569
+ /**
570
+ * Wrapped private key
571
+ */
572
+ privateKey: EncString;
573
+ /**
574
+ * Public key
575
+ */
576
+ publicKey: B64;
577
+ /**
578
+ * The user\'s public key, signed by the signing key
579
+ */
580
+ signedPublicKey: SignedPublicKey;
581
+ /**
582
+ * Signing key, encrypted with the user\'s symmetric key
583
+ */
584
+ signingKey: EncString;
585
+ /**
586
+ * Base64 encoded verifying key
587
+ */
588
+ verifyingKey: B64;
589
+ /**
590
+ * The user\'s signed security state
591
+ */
592
+ securityState: SignedSecurityState;
593
+ /**
594
+ * The security state\'s version
595
+ */
596
+ securityVersion: number;
113
597
  }
114
598
 
115
- export function isCoreError(error: any): error is CoreError;
599
+ /**
600
+ * Represents the data required to unlock with the master password.
601
+ */
602
+ export interface MasterPasswordUnlockData {
603
+ /**
604
+ * The key derivation function used to derive the master key
605
+ */
606
+ kdf: Kdf;
607
+ /**
608
+ * The master key wrapped user key
609
+ */
610
+ masterKeyWrappedUserKey: EncString;
611
+ /**
612
+ * The salt used in the KDF, typically the user\'s email
613
+ */
614
+ salt: string;
615
+ }
116
616
 
117
- export interface EncryptionSettingsError extends Error {
118
- name: "EncryptionSettingsError";
119
- variant: "Crypto" | "InvalidBase64" | "VaultLocked" | "InvalidPrivateKey" | "MissingPrivateKey";
617
+ /**
618
+ * Represents the data required to authenticate with the master password.
619
+ */
620
+ export interface MasterPasswordAuthenticationData {
621
+ kdf: Kdf;
622
+ salt: string;
623
+ masterPasswordAuthenticationHash: B64;
120
624
  }
121
625
 
122
- export function isEncryptionSettingsError(error: any): error is EncryptionSettingsError;
626
+ export type SignedSecurityState = string;
123
627
 
124
- export type DeviceType =
125
- | "Android"
126
- | "iOS"
127
- | "ChromeExtension"
628
+ /**
629
+ * NewType wrapper for `UserId`
630
+ */
631
+ export type UserId = Tagged<Uuid, "UserId">;
632
+
633
+ /**
634
+ * NewType wrapper for `OrganizationId`
635
+ */
636
+ export type OrganizationId = Tagged<Uuid, "OrganizationId">;
637
+
638
+ export interface MasterPasswordError extends Error {
639
+ name: "MasterPasswordError";
640
+ variant:
641
+ | "EncryptionKeyMalformed"
642
+ | "KdfMalformed"
643
+ | "InvalidKdfConfiguration"
644
+ | "MissingField"
645
+ | "Crypto";
646
+ }
647
+
648
+ export function isMasterPasswordError(error: any): error is MasterPasswordError;
649
+
650
+ export interface DeriveKeyConnectorError extends Error {
651
+ name: "DeriveKeyConnectorError";
652
+ variant: "WrongPassword" | "Crypto";
653
+ }
654
+
655
+ export function isDeriveKeyConnectorError(error: any): error is DeriveKeyConnectorError;
656
+
657
+ export interface EnrollAdminPasswordResetError extends Error {
658
+ name: "EnrollAdminPasswordResetError";
659
+ variant: "Crypto";
660
+ }
661
+
662
+ export function isEnrollAdminPasswordResetError(error: any): error is EnrollAdminPasswordResetError;
663
+
664
+ export interface CryptoClientError extends Error {
665
+ name: "CryptoClientError";
666
+ variant: "NotAuthenticated" | "Crypto" | "InvalidKdfSettings" | "PasswordProtectedKeyEnvelope";
667
+ }
668
+
669
+ export function isCryptoClientError(error: any): error is CryptoClientError;
670
+
671
+ export interface StatefulCryptoError extends Error {
672
+ name: "StatefulCryptoError";
673
+ variant: "MissingSecurityState" | "WrongAccountCryptoVersion" | "Crypto";
674
+ }
675
+
676
+ export function isStatefulCryptoError(error: any): error is StatefulCryptoError;
677
+
678
+ export interface EncryptionSettingsError extends Error {
679
+ name: "EncryptionSettingsError";
680
+ variant:
681
+ | "Crypto"
682
+ | "InvalidPrivateKey"
683
+ | "InvalidSigningKey"
684
+ | "InvalidSecurityState"
685
+ | "MissingPrivateKey"
686
+ | "UserIdAlreadySet"
687
+ | "WrongPin";
688
+ }
689
+
690
+ export function isEncryptionSettingsError(error: any): error is EncryptionSettingsError;
691
+
692
+ export type DeviceType =
693
+ | "Android"
694
+ | "iOS"
695
+ | "ChromeExtension"
128
696
  | "FirefoxExtension"
129
697
  | "OperaExtension"
130
698
  | "EdgeExtension"
@@ -147,7 +715,8 @@ export type DeviceType =
147
715
  | "Server"
148
716
  | "WindowsCLI"
149
717
  | "MacOsCLI"
150
- | "LinuxCLI";
718
+ | "LinuxCLI"
719
+ | "DuckDuckGoBrowser";
151
720
 
152
721
  /**
153
722
  * Basic client behavior settings. These settings specify the various targets and behavior of the
@@ -162,6 +731,7 @@ export type DeviceType =
162
731
  * api_url: \"https://api.bitwarden.com\".to_string(),
163
732
  * user_agent: \"Bitwarden Rust-SDK\".to_string(),
164
733
  * device_type: DeviceType::SDK,
734
+ * bitwarden_client_version: None,
165
735
  * };
166
736
  * let default = ClientSettings::default();
167
737
  * ```
@@ -183,11 +753,26 @@ export interface ClientSettings {
183
753
  * Device type to send to Bitwarden. Defaults to SDK
184
754
  */
185
755
  deviceType?: DeviceType;
756
+ /**
757
+ * Bitwarden Client Version to send to Bitwarden.
758
+ */
759
+ bitwardenClientVersion?: string | undefined;
186
760
  }
187
761
 
188
- export type AsymmetricEncString = string;
762
+ export type UnsignedSharedKey = Tagged<string, "UnsignedSharedKey">;
763
+
764
+ export type EncString = Tagged<string, "EncString">;
765
+
766
+ export type SignedPublicKey = Tagged<string, "SignedPublicKey">;
767
+
768
+ export type PasswordProtectedKeyEnvelope = Tagged<string, "PasswordProtectedKeyEnvelope">;
769
+
770
+ export type DataEnvelope = Tagged<string, "DataEnvelope">;
189
771
 
190
- export type EncString = string;
772
+ /**
773
+ * The type of key / signature scheme used for signing and verifying.
774
+ */
775
+ export type SignatureAlgorithm = "ed25519";
191
776
 
192
777
  /**
193
778
  * Key Derivation Function for Bitwarden Account
@@ -199,108 +784,1720 @@ export type Kdf =
199
784
  | { pBKDF2: { iterations: NonZeroU32 } }
200
785
  | { argon2id: { iterations: NonZeroU32; memory: NonZeroU32; parallelism: NonZeroU32 } };
201
786
 
202
- export interface GenerateSshKeyResult {
203
- private_key: string;
204
- public_key: string;
205
- key_fingerprint: string;
787
+ export interface CryptoError extends Error {
788
+ name: "CryptoError";
789
+ variant:
790
+ | "InvalidKey"
791
+ | "InvalidMac"
792
+ | "MacNotProvided"
793
+ | "KeyDecrypt"
794
+ | "InvalidKeyLen"
795
+ | "InvalidUtf8String"
796
+ | "MissingKey"
797
+ | "MissingField"
798
+ | "MissingKeyId"
799
+ | "KeyOperationNotSupported"
800
+ | "ReadOnlyKeyStore"
801
+ | "InsufficientKdfParameters"
802
+ | "EncString"
803
+ | "Rsa"
804
+ | "Fingerprint"
805
+ | "Argon"
806
+ | "ZeroNumber"
807
+ | "OperationNotSupported"
808
+ | "WrongKeyType"
809
+ | "WrongCoseKeyId"
810
+ | "InvalidNonceLength"
811
+ | "InvalidPadding"
812
+ | "Signature"
813
+ | "Encoding";
814
+ }
815
+
816
+ export function isCryptoError(error: any): error is CryptoError;
817
+
818
+ /**
819
+ * Base64 encoded data
820
+ *
821
+ * Is indifferent about padding when decoding, but always produces padding when encoding.
822
+ */
823
+ export type B64 = string;
824
+
825
+ /**
826
+ * Temporary struct to hold metadata related to current account
827
+ *
828
+ * Eventually the SDK itself should have this state and we get rid of this struct.
829
+ */
830
+ export interface Account {
831
+ id: Uuid;
832
+ email: string;
833
+ name: string | undefined;
834
+ }
835
+
836
+ export type ExportFormat = "Csv" | "Json" | { EncryptedJson: { password: string } };
837
+
838
+ export interface ExportError extends Error {
839
+ name: "ExportError";
840
+ variant:
841
+ | "MissingField"
842
+ | "NotAuthenticated"
843
+ | "Csv"
844
+ | "Cxf"
845
+ | "Json"
846
+ | "EncryptedJson"
847
+ | "BitwardenCrypto"
848
+ | "Cipher";
849
+ }
850
+
851
+ export function isExportError(error: any): error is ExportError;
852
+
853
+ export type UsernameGeneratorRequest =
854
+ | { word: { capitalize: boolean; include_number: boolean } }
855
+ | { subaddress: { type: AppendType; email: string } }
856
+ | { catchall: { type: AppendType; domain: string } }
857
+ | { forwarded: { service: ForwarderServiceType; website: string | undefined } };
858
+
859
+ /**
860
+ * Configures the email forwarding service to use.
861
+ * For instructions on how to configure each service, see the documentation:
862
+ * <https://bitwarden.com/help/generator/#username-types>
863
+ */
864
+ export type ForwarderServiceType =
865
+ | { addyIo: { api_token: string; domain: string; base_url: string } }
866
+ | { duckDuckGo: { token: string } }
867
+ | { firefox: { api_token: string } }
868
+ | { fastmail: { api_token: string } }
869
+ | { forwardEmail: { api_token: string; domain: string } }
870
+ | { simpleLogin: { api_key: string; base_url: string } };
871
+
872
+ export type AppendType = "random" | { websiteName: { website: string } };
873
+
874
+ export interface UsernameError extends Error {
875
+ name: "UsernameError";
876
+ variant: "InvalidApiKey" | "Unknown" | "ResponseContent" | "Reqwest";
877
+ }
878
+
879
+ export function isUsernameError(error: any): error is UsernameError;
880
+
881
+ /**
882
+ * Password generator request options.
883
+ */
884
+ export interface PasswordGeneratorRequest {
885
+ /**
886
+ * Include lowercase characters (a-z).
887
+ */
888
+ lowercase: boolean;
889
+ /**
890
+ * Include uppercase characters (A-Z).
891
+ */
892
+ uppercase: boolean;
893
+ /**
894
+ * Include numbers (0-9).
895
+ */
896
+ numbers: boolean;
897
+ /**
898
+ * Include special characters: ! @ # $ % ^ & *
899
+ */
900
+ special: boolean;
901
+ /**
902
+ * The length of the generated password.
903
+ * Note that the password length must be greater than the sum of all the minimums.
904
+ */
905
+ length: number;
906
+ /**
907
+ * When set to true, the generated password will not contain ambiguous characters.
908
+ * The ambiguous characters are: I, O, l, 0, 1
909
+ */
910
+ avoidAmbiguous: boolean;
911
+ /**
912
+ * The minimum number of lowercase characters in the generated password.
913
+ * When set, the value must be between 1 and 9. This value is ignored if lowercase is false.
914
+ */
915
+ minLowercase: number | undefined;
916
+ /**
917
+ * The minimum number of uppercase characters in the generated password.
918
+ * When set, the value must be between 1 and 9. This value is ignored if uppercase is false.
919
+ */
920
+ minUppercase: number | undefined;
921
+ /**
922
+ * The minimum number of numbers in the generated password.
923
+ * When set, the value must be between 1 and 9. This value is ignored if numbers is false.
924
+ */
925
+ minNumber: number | undefined;
926
+ /**
927
+ * The minimum number of special characters in the generated password.
928
+ * When set, the value must be between 1 and 9. This value is ignored if special is false.
929
+ */
930
+ minSpecial: number | undefined;
931
+ }
932
+
933
+ export interface PasswordError extends Error {
934
+ name: "PasswordError";
935
+ variant: "NoCharacterSetEnabled" | "InvalidLength";
936
+ }
937
+
938
+ export function isPasswordError(error: any): error is PasswordError;
939
+
940
+ /**
941
+ * Passphrase generator request options.
942
+ */
943
+ export interface PassphraseGeneratorRequest {
944
+ /**
945
+ * Number of words in the generated passphrase.
946
+ * This value must be between 3 and 20.
947
+ */
948
+ numWords: number;
949
+ /**
950
+ * Character separator between words in the generated passphrase. The value cannot be empty.
951
+ */
952
+ wordSeparator: string;
953
+ /**
954
+ * When set to true, capitalize the first letter of each word in the generated passphrase.
955
+ */
956
+ capitalize: boolean;
957
+ /**
958
+ * When set to true, include a number at the end of one of the words in the generated
959
+ * passphrase.
960
+ */
961
+ includeNumber: boolean;
962
+ }
963
+
964
+ export type PassphraseError = { InvalidNumWords: { minimum: number; maximum: number } };
965
+
966
+ export interface DiscoverResponse {
967
+ version: string;
968
+ }
969
+
970
+ export type Endpoint =
971
+ | { Web: { id: number } }
972
+ | "BrowserForeground"
973
+ | "BrowserBackground"
974
+ | "DesktopRenderer"
975
+ | "DesktopMain";
976
+
977
+ export interface IpcCommunicationBackendSender {
978
+ send(message: OutgoingMessage): Promise<void>;
979
+ }
980
+
981
+ export interface IpcSessionRepository {
982
+ get(endpoint: Endpoint): Promise<any | undefined>;
983
+ save(endpoint: Endpoint, session: any): Promise<void>;
984
+ remove(endpoint: Endpoint): Promise<void>;
985
+ }
986
+
987
+ export interface ChannelError extends Error {
988
+ name: "ChannelError";
989
+ }
990
+
991
+ export function isChannelError(error: any): error is ChannelError;
992
+
993
+ export interface DeserializeError extends Error {
994
+ name: "DeserializeError";
995
+ }
996
+
997
+ export function isDeserializeError(error: any): error is DeserializeError;
998
+
999
+ export interface RequestError extends Error {
1000
+ name: "RequestError";
1001
+ variant: "Subscribe" | "Receive" | "Timeout" | "Send" | "Rpc";
1002
+ }
1003
+
1004
+ export function isRequestError(error: any): error is RequestError;
1005
+
1006
+ export interface TypedReceiveError extends Error {
1007
+ name: "TypedReceiveError";
1008
+ variant: "Channel" | "Timeout" | "Cancelled" | "Typing";
1009
+ }
1010
+
1011
+ export function isTypedReceiveError(error: any): error is TypedReceiveError;
1012
+
1013
+ export interface ReceiveError extends Error {
1014
+ name: "ReceiveError";
1015
+ variant: "Channel" | "Timeout" | "Cancelled";
1016
+ }
1017
+
1018
+ export function isReceiveError(error: any): error is ReceiveError;
1019
+
1020
+ export interface SubscribeError extends Error {
1021
+ name: "SubscribeError";
1022
+ variant: "NotStarted";
206
1023
  }
207
1024
 
1025
+ export function isSubscribeError(error: any): error is SubscribeError;
1026
+
208
1027
  export type KeyAlgorithm = "Ed25519" | "Rsa3072" | "Rsa4096";
209
1028
 
1029
+ export interface SshKeyExportError extends Error {
1030
+ name: "SshKeyExportError";
1031
+ variant: "KeyConversion";
1032
+ }
1033
+
1034
+ export function isSshKeyExportError(error: any): error is SshKeyExportError;
1035
+
1036
+ export interface SshKeyImportError extends Error {
1037
+ name: "SshKeyImportError";
1038
+ variant: "Parsing" | "PasswordRequired" | "WrongPassword" | "UnsupportedKeyType";
1039
+ }
1040
+
1041
+ export function isSshKeyImportError(error: any): error is SshKeyImportError;
1042
+
210
1043
  export interface KeyGenerationError extends Error {
211
1044
  name: "KeyGenerationError";
212
- variant: "KeyGenerationError" | "KeyConversionError";
1045
+ variant: "KeyGeneration" | "KeyConversion";
213
1046
  }
214
1047
 
215
1048
  export function isKeyGenerationError(error: any): error is KeyGenerationError;
216
1049
 
217
- export interface Folder {
218
- id: Uuid | undefined;
1050
+ export interface DatabaseError extends Error {
1051
+ name: "DatabaseError";
1052
+ variant: "UnsupportedConfiguration" | "ThreadBoundRunner" | "Serialization" | "JS" | "Internal";
1053
+ }
1054
+
1055
+ export function isDatabaseError(error: any): error is DatabaseError;
1056
+
1057
+ export interface StateRegistryError extends Error {
1058
+ name: "StateRegistryError";
1059
+ variant: "DatabaseAlreadyInitialized" | "DatabaseNotInitialized" | "Database";
1060
+ }
1061
+
1062
+ export function isStateRegistryError(error: any): error is StateRegistryError;
1063
+
1064
+ export interface CallError extends Error {
1065
+ name: "CallError";
1066
+ }
1067
+
1068
+ export function isCallError(error: any): error is CallError;
1069
+
1070
+ /**
1071
+ * NewType wrapper for `CipherId`
1072
+ */
1073
+ export type CipherId = Tagged<Uuid, "CipherId">;
1074
+
1075
+ export interface EncryptionContext {
1076
+ /**
1077
+ * The Id of the user that encrypted the cipher. It should always represent a UserId, even for
1078
+ * Organization-owned ciphers
1079
+ */
1080
+ encryptedFor: UserId;
1081
+ cipher: Cipher;
1082
+ }
1083
+
1084
+ export interface Cipher {
1085
+ id: CipherId | undefined;
1086
+ organizationId: OrganizationId | undefined;
1087
+ folderId: FolderId | undefined;
1088
+ collectionIds: CollectionId[];
1089
+ /**
1090
+ * More recent ciphers uses individual encryption keys to encrypt the other fields of the
1091
+ * Cipher.
1092
+ */
1093
+ key: EncString | undefined;
219
1094
  name: EncString;
1095
+ notes: EncString | undefined;
1096
+ type: CipherType;
1097
+ login: Login | undefined;
1098
+ identity: Identity | undefined;
1099
+ card: Card | undefined;
1100
+ secureNote: SecureNote | undefined;
1101
+ sshKey: SshKey | undefined;
1102
+ favorite: boolean;
1103
+ reprompt: CipherRepromptType;
1104
+ organizationUseTotp: boolean;
1105
+ edit: boolean;
1106
+ permissions: CipherPermissions | undefined;
1107
+ viewPassword: boolean;
1108
+ localData: LocalData | undefined;
1109
+ attachments: Attachment[] | undefined;
1110
+ fields: Field[] | undefined;
1111
+ passwordHistory: PasswordHistory[] | undefined;
1112
+ creationDate: DateTime<Utc>;
1113
+ deletedDate: DateTime<Utc> | undefined;
220
1114
  revisionDate: DateTime<Utc>;
1115
+ archivedDate: DateTime<Utc> | undefined;
1116
+ data: string | undefined;
221
1117
  }
222
1118
 
223
- export interface FolderView {
224
- id: Uuid | undefined;
1119
+ export interface CipherView {
1120
+ id: CipherId | undefined;
1121
+ organizationId: OrganizationId | undefined;
1122
+ folderId: FolderId | undefined;
1123
+ collectionIds: CollectionId[];
1124
+ /**
1125
+ * Temporary, required to support re-encrypting existing items.
1126
+ */
1127
+ key: EncString | undefined;
225
1128
  name: string;
1129
+ notes: string | undefined;
1130
+ type: CipherType;
1131
+ login: LoginView | undefined;
1132
+ identity: IdentityView | undefined;
1133
+ card: CardView | undefined;
1134
+ secureNote: SecureNoteView | undefined;
1135
+ sshKey: SshKeyView | undefined;
1136
+ favorite: boolean;
1137
+ reprompt: CipherRepromptType;
1138
+ organizationUseTotp: boolean;
1139
+ edit: boolean;
1140
+ permissions: CipherPermissions | undefined;
1141
+ viewPassword: boolean;
1142
+ localData: LocalDataView | undefined;
1143
+ attachments: AttachmentView[] | undefined;
1144
+ fields: FieldView[] | undefined;
1145
+ passwordHistory: PasswordHistoryView[] | undefined;
1146
+ creationDate: DateTime<Utc>;
1147
+ deletedDate: DateTime<Utc> | undefined;
226
1148
  revisionDate: DateTime<Utc>;
1149
+ archivedDate: DateTime<Utc> | undefined;
227
1150
  }
228
1151
 
229
- export interface TestError extends Error {
230
- name: "TestError";
231
- }
1152
+ export type CipherListViewType =
1153
+ | { login: LoginListView }
1154
+ | "secureNote"
1155
+ | { card: CardListView }
1156
+ | "identity"
1157
+ | "sshKey";
232
1158
 
233
- export function isTestError(error: any): error is TestError;
1159
+ /**
1160
+ * Available fields on a cipher and can be copied from a the list view in the UI.
1161
+ */
1162
+ export type CopyableCipherFields =
1163
+ | "LoginUsername"
1164
+ | "LoginPassword"
1165
+ | "LoginTotp"
1166
+ | "CardNumber"
1167
+ | "CardSecurityCode"
1168
+ | "IdentityUsername"
1169
+ | "IdentityEmail"
1170
+ | "IdentityPhone"
1171
+ | "IdentityAddress"
1172
+ | "SshKey"
1173
+ | "SecureNotes";
234
1174
 
235
- export type Uuid = string;
1175
+ export interface CipherListView {
1176
+ id: CipherId | undefined;
1177
+ organizationId: OrganizationId | undefined;
1178
+ folderId: FolderId | undefined;
1179
+ collectionIds: CollectionId[];
1180
+ /**
1181
+ * Temporary, required to support calculating TOTP from CipherListView.
1182
+ */
1183
+ key: EncString | undefined;
1184
+ name: string;
1185
+ subtitle: string;
1186
+ type: CipherListViewType;
1187
+ favorite: boolean;
1188
+ reprompt: CipherRepromptType;
1189
+ organizationUseTotp: boolean;
1190
+ edit: boolean;
1191
+ permissions: CipherPermissions | undefined;
1192
+ viewPassword: boolean;
1193
+ /**
1194
+ * The number of attachments
1195
+ */
1196
+ attachments: number;
1197
+ /**
1198
+ * Indicates if the cipher has old attachments that need to be re-uploaded
1199
+ */
1200
+ hasOldAttachments: boolean;
1201
+ creationDate: DateTime<Utc>;
1202
+ deletedDate: DateTime<Utc> | undefined;
1203
+ revisionDate: DateTime<Utc>;
1204
+ archivedDate: DateTime<Utc> | undefined;
1205
+ /**
1206
+ * Hints for the presentation layer for which fields can be copied.
1207
+ */
1208
+ copyableFields: CopyableCipherFields[];
1209
+ localData: LocalDataView | undefined;
1210
+ }
236
1211
 
237
1212
  /**
238
- * RFC3339 compliant date-time string.
239
- * @typeParam T - Not used in JavaScript.
1213
+ * Represents the result of decrypting a list of ciphers.
1214
+ *
1215
+ * This struct contains two vectors: `successes` and `failures`.
1216
+ * `successes` contains the decrypted `CipherListView` objects,
1217
+ * while `failures` contains the original `Cipher` objects that failed to decrypt.
240
1218
  */
241
- export type DateTime<T = unknown> = string;
1219
+ export interface DecryptCipherListResult {
1220
+ /**
1221
+ * The decrypted `CipherListView` objects.
1222
+ */
1223
+ successes: CipherListView[];
1224
+ /**
1225
+ * The original `Cipher` objects that failed to decrypt.
1226
+ */
1227
+ failures: Cipher[];
1228
+ }
242
1229
 
243
1230
  /**
244
- * UTC date-time string. Not used in JavaScript.
1231
+ * Request to add a cipher.
245
1232
  */
246
- export type Utc = unknown;
1233
+ export interface CipherCreateRequest {
1234
+ organizationId: OrganizationId | undefined;
1235
+ folderId: FolderId | undefined;
1236
+ name: string;
1237
+ notes: string | undefined;
1238
+ favorite: boolean;
1239
+ reprompt: CipherRepromptType;
1240
+ type: CipherViewType;
1241
+ fields: FieldView[];
1242
+ }
247
1243
 
248
1244
  /**
249
- * An integer that is known not to equal zero.
1245
+ * Request to edit a cipher.
250
1246
  */
251
- export type NonZeroU32 = number;
1247
+ export interface CipherEditRequest {
1248
+ id: CipherId;
1249
+ organizationId: OrganizationId | undefined;
1250
+ folderId: FolderId | undefined;
1251
+ favorite: boolean;
1252
+ reprompt: CipherRepromptType;
1253
+ name: string;
1254
+ notes: string | undefined;
1255
+ fields: FieldView[];
1256
+ type: CipherViewType;
1257
+ revisionDate: DateTime<Utc>;
1258
+ archivedDate: DateTime<Utc> | undefined;
1259
+ attachments: AttachmentView[];
1260
+ key: EncString | undefined;
1261
+ }
252
1262
 
253
- export class BitwardenClient {
254
- free(): void;
255
- constructor(settings?: ClientSettings, log_level?: LogLevel);
1263
+ export interface Field {
1264
+ name: EncString | undefined;
1265
+ value: EncString | undefined;
1266
+ type: FieldType;
1267
+ linkedId: LinkedIdType | undefined;
1268
+ }
1269
+
1270
+ export interface FieldView {
1271
+ name: string | undefined;
1272
+ value: string | undefined;
1273
+ type: FieldType;
1274
+ linkedId: LinkedIdType | undefined;
1275
+ }
1276
+
1277
+ export type LinkedIdType = LoginLinkedIdType | CardLinkedIdType | IdentityLinkedIdType;
1278
+
1279
+ export interface LoginUri {
1280
+ uri: EncString | undefined;
1281
+ match: UriMatchType | undefined;
1282
+ uriChecksum: EncString | undefined;
1283
+ }
1284
+
1285
+ export interface LoginUriView {
1286
+ uri: string | undefined;
1287
+ match: UriMatchType | undefined;
1288
+ uriChecksum: string | undefined;
1289
+ }
1290
+
1291
+ export interface Fido2Credential {
1292
+ credentialId: EncString;
1293
+ keyType: EncString;
1294
+ keyAlgorithm: EncString;
1295
+ keyCurve: EncString;
1296
+ keyValue: EncString;
1297
+ rpId: EncString;
1298
+ userHandle: EncString | undefined;
1299
+ userName: EncString | undefined;
1300
+ counter: EncString;
1301
+ rpName: EncString | undefined;
1302
+ userDisplayName: EncString | undefined;
1303
+ discoverable: EncString;
1304
+ creationDate: DateTime<Utc>;
1305
+ }
1306
+
1307
+ export interface Fido2CredentialListView {
1308
+ credentialId: string;
1309
+ rpId: string;
1310
+ userHandle: string | undefined;
1311
+ userName: string | undefined;
1312
+ userDisplayName: string | undefined;
1313
+ counter: string;
1314
+ }
1315
+
1316
+ export interface Fido2CredentialView {
1317
+ credentialId: string;
1318
+ keyType: string;
1319
+ keyAlgorithm: string;
1320
+ keyCurve: string;
1321
+ keyValue: EncString;
1322
+ rpId: string;
1323
+ userHandle: string | undefined;
1324
+ userName: string | undefined;
1325
+ counter: string;
1326
+ rpName: string | undefined;
1327
+ userDisplayName: string | undefined;
1328
+ discoverable: string;
1329
+ creationDate: DateTime<Utc>;
1330
+ }
1331
+
1332
+ export interface Fido2CredentialFullView {
1333
+ credentialId: string;
1334
+ keyType: string;
1335
+ keyAlgorithm: string;
1336
+ keyCurve: string;
1337
+ keyValue: string;
1338
+ rpId: string;
1339
+ userHandle: string | undefined;
1340
+ userName: string | undefined;
1341
+ counter: string;
1342
+ rpName: string | undefined;
1343
+ userDisplayName: string | undefined;
1344
+ discoverable: string;
1345
+ creationDate: DateTime<Utc>;
1346
+ }
1347
+
1348
+ export interface Fido2CredentialNewView {
1349
+ credentialId: string;
1350
+ keyType: string;
1351
+ keyAlgorithm: string;
1352
+ keyCurve: string;
1353
+ rpId: string;
1354
+ userHandle: string | undefined;
1355
+ userName: string | undefined;
1356
+ counter: string;
1357
+ rpName: string | undefined;
1358
+ userDisplayName: string | undefined;
1359
+ creationDate: DateTime<Utc>;
1360
+ }
1361
+
1362
+ export interface Login {
1363
+ username: EncString | undefined;
1364
+ password: EncString | undefined;
1365
+ passwordRevisionDate: DateTime<Utc> | undefined;
1366
+ uris: LoginUri[] | undefined;
1367
+ totp: EncString | undefined;
1368
+ autofillOnPageLoad: boolean | undefined;
1369
+ fido2Credentials: Fido2Credential[] | undefined;
1370
+ }
1371
+
1372
+ export interface LoginView {
1373
+ username: string | undefined;
1374
+ password: string | undefined;
1375
+ passwordRevisionDate: DateTime<Utc> | undefined;
1376
+ uris: LoginUriView[] | undefined;
1377
+ totp: string | undefined;
1378
+ autofillOnPageLoad: boolean | undefined;
1379
+ fido2Credentials: Fido2Credential[] | undefined;
1380
+ }
1381
+
1382
+ export interface LoginListView {
1383
+ fido2Credentials: Fido2CredentialListView[] | undefined;
1384
+ hasFido2: boolean;
1385
+ username: string | undefined;
256
1386
  /**
257
- * Test method, echoes back the input
1387
+ * The TOTP key is not decrypted. Useable as is with [`crate::generate_totp_cipher_view`].
258
1388
  */
259
- echo(msg: string): string;
260
- version(): string;
261
- throw(msg: string): Promise<void>;
1389
+ totp: EncString | undefined;
1390
+ uris: LoginUriView[] | undefined;
1391
+ }
1392
+
1393
+ export interface SecureNote {
1394
+ type: SecureNoteType;
1395
+ }
1396
+
1397
+ export interface SecureNoteView {
1398
+ type: SecureNoteType;
1399
+ }
1400
+
1401
+ /**
1402
+ * Result of checking password exposure via HIBP API.
1403
+ */
1404
+ export type ExposedPasswordResult =
1405
+ | { type: "NotChecked" }
1406
+ | { type: "Found"; value: number }
1407
+ | { type: "Error"; value: string };
1408
+
1409
+ /**
1410
+ * Login cipher data needed for risk evaluation.
1411
+ */
1412
+ export interface CipherLoginDetails {
262
1413
  /**
263
- * Test method, calls http endpoint
1414
+ * Cipher ID to identify which cipher in results.
264
1415
  */
265
- http_get(url: string): Promise<string>;
266
- crypto(): ClientCrypto;
267
- vault(): ClientVault;
268
- }
269
- export class ClientCrypto {
270
- private constructor();
271
- free(): void;
1416
+ id: CipherId;
272
1417
  /**
273
- * Initialization method for the user crypto. Needs to be called before any other crypto
274
- * operations.
1418
+ * The decrypted password to evaluate.
275
1419
  */
276
- initialize_user_crypto(req: InitUserCryptoRequest): Promise<void>;
1420
+ password: string;
277
1421
  /**
278
- * Initialization method for the organization crypto. Needs to be called after
279
- * `initialize_user_crypto` but before any other crypto operations.
1422
+ * Username or email (login ciphers only have one field).
280
1423
  */
281
- initialize_org_crypto(req: InitOrgCryptoRequest): Promise<void>;
1424
+ username: string | undefined;
1425
+ }
1426
+
1427
+ /**
1428
+ * Password reuse map wrapper for WASM compatibility.
1429
+ */
1430
+ export type PasswordReuseMap = Record<string, number>;
1431
+
1432
+ /**
1433
+ * Options for configuring risk computation.
1434
+ */
1435
+ export interface CipherRiskOptions {
282
1436
  /**
283
- * Generates a new key pair and encrypts the private key with the provided user key.
284
- * Crypto initialization not required.
1437
+ * Pre-computed password reuse map (password count).
1438
+ * If provided, enables reuse detection across ciphers.
285
1439
  */
286
- make_key_pair(user_key: string): MakeKeyPairResponse;
1440
+ passwordMap?: PasswordReuseMap | undefined;
287
1441
  /**
288
- * Verifies a user's asymmetric keys by decrypting the private key with the provided user
289
- * key. Returns if the private key is decryptable and if it is a valid matching key.
1442
+ * Whether to check passwords against Have I Been Pwned API.
1443
+ * When true, makes network requests to check for exposed passwords.
1444
+ */
1445
+ checkExposed?: boolean;
1446
+ /**
1447
+ * Optional HIBP API base URL override. When None, uses the production HIBP URL.
1448
+ * Can be used for testing or alternative password breach checking services.
1449
+ */
1450
+ hibpBaseUrl?: string | undefined;
1451
+ }
1452
+
1453
+ /**
1454
+ * Risk evaluation result for a single cipher.
1455
+ */
1456
+ export interface CipherRiskResult {
1457
+ /**
1458
+ * Cipher ID matching the input CipherLoginDetails.
1459
+ */
1460
+ id: CipherId;
1461
+ /**
1462
+ * Password strength score from 0 (weakest) to 4 (strongest).
1463
+ * Calculated using zxcvbn with cipher-specific context.
1464
+ */
1465
+ password_strength: number;
1466
+ /**
1467
+ * Result of checking password exposure via HIBP API.
1468
+ * - `NotChecked`: check_exposed was false, or password was empty
1469
+ * - `Found(n)`: Successfully checked, found in n breaches
1470
+ * - `Error(msg)`: HIBP API request failed for this cipher with the given error message
1471
+ */
1472
+ exposed_result: ExposedPasswordResult;
1473
+ /**
1474
+ * Number of times this password appears in the provided password_map.
1475
+ * None if not found or if no password_map was provided.
1476
+ */
1477
+ reuse_count: number | undefined;
1478
+ }
1479
+
1480
+ /**
1481
+ * Request to add or edit a folder.
1482
+ */
1483
+ export interface FolderAddEditRequest {
1484
+ /**
1485
+ * The new name of the folder.
1486
+ */
1487
+ name: string;
1488
+ }
1489
+
1490
+ /**
1491
+ * NewType wrapper for `FolderId`
1492
+ */
1493
+ export type FolderId = Tagged<Uuid, "FolderId">;
1494
+
1495
+ export interface Folder {
1496
+ id: FolderId | undefined;
1497
+ name: EncString;
1498
+ revisionDate: DateTime<Utc>;
1499
+ }
1500
+
1501
+ export interface FolderView {
1502
+ id: FolderId | undefined;
1503
+ name: string;
1504
+ revisionDate: DateTime<Utc>;
1505
+ }
1506
+
1507
+ export interface AncestorMap {
1508
+ ancestors: Map<CollectionId, string>;
1509
+ }
1510
+
1511
+ export interface DecryptError extends Error {
1512
+ name: "DecryptError";
1513
+ variant: "Crypto";
1514
+ }
1515
+
1516
+ export function isDecryptError(error: any): error is DecryptError;
1517
+
1518
+ export interface EncryptError extends Error {
1519
+ name: "EncryptError";
1520
+ variant: "Crypto" | "MissingUserId";
1521
+ }
1522
+
1523
+ export function isEncryptError(error: any): error is EncryptError;
1524
+
1525
+ export interface TotpResponse {
1526
+ /**
1527
+ * Generated TOTP code
1528
+ */
1529
+ code: string;
1530
+ /**
1531
+ * Time period
1532
+ */
1533
+ period: number;
1534
+ }
1535
+
1536
+ export interface TotpError extends Error {
1537
+ name: "TotpError";
1538
+ variant: "InvalidOtpauth" | "MissingSecret" | "Crypto";
1539
+ }
1540
+
1541
+ export function isTotpError(error: any): error is TotpError;
1542
+
1543
+ export interface PasswordHistoryView {
1544
+ password: string;
1545
+ lastUsedDate: DateTime<Utc>;
1546
+ }
1547
+
1548
+ export interface PasswordHistory {
1549
+ password: EncString;
1550
+ lastUsedDate: DateTime<Utc>;
1551
+ }
1552
+
1553
+ export interface GetFolderError extends Error {
1554
+ name: "GetFolderError";
1555
+ variant: "ItemNotFound" | "Crypto" | "Repository";
1556
+ }
1557
+
1558
+ export function isGetFolderError(error: any): error is GetFolderError;
1559
+
1560
+ export interface EditFolderError extends Error {
1561
+ name: "EditFolderError";
1562
+ variant:
1563
+ | "ItemNotFound"
1564
+ | "Crypto"
1565
+ | "Api"
1566
+ | "VaultParse"
1567
+ | "MissingField"
1568
+ | "Repository"
1569
+ | "Uuid";
1570
+ }
1571
+
1572
+ export function isEditFolderError(error: any): error is EditFolderError;
1573
+
1574
+ export interface CreateFolderError extends Error {
1575
+ name: "CreateFolderError";
1576
+ variant: "Crypto" | "Api" | "VaultParse" | "MissingField" | "Repository";
1577
+ }
1578
+
1579
+ export function isCreateFolderError(error: any): error is CreateFolderError;
1580
+
1581
+ export interface CipherRiskError extends Error {
1582
+ name: "CipherRiskError";
1583
+ variant: "Reqwest";
1584
+ }
1585
+
1586
+ export function isCipherRiskError(error: any): error is CipherRiskError;
1587
+
1588
+ export interface SshKeyView {
1589
+ /**
1590
+ * SSH private key (ed25519/rsa) in unencrypted openssh private key format [OpenSSH private key](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key)
1591
+ */
1592
+ privateKey: string;
1593
+ /**
1594
+ * SSH public key (ed25519/rsa) according to [RFC4253](https://datatracker.ietf.org/doc/html/rfc4253#section-6.6)
1595
+ */
1596
+ publicKey: string;
1597
+ /**
1598
+ * SSH fingerprint using SHA256 in the format: `SHA256:BASE64_ENCODED_FINGERPRINT`
1599
+ */
1600
+ fingerprint: string;
1601
+ }
1602
+
1603
+ export interface SshKey {
1604
+ /**
1605
+ * SSH private key (ed25519/rsa) in unencrypted openssh private key format [OpenSSH private key](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key)
1606
+ */
1607
+ privateKey: EncString;
1608
+ /**
1609
+ * SSH public key (ed25519/rsa) according to [RFC4253](https://datatracker.ietf.org/doc/html/rfc4253#section-6.6)
1610
+ */
1611
+ publicKey: EncString;
1612
+ /**
1613
+ * SSH fingerprint using SHA256 in the format: `SHA256:BASE64_ENCODED_FINGERPRINT`
1614
+ */
1615
+ fingerprint: EncString;
1616
+ }
1617
+
1618
+ export interface LocalDataView {
1619
+ lastUsedDate: DateTime<Utc> | undefined;
1620
+ lastLaunched: DateTime<Utc> | undefined;
1621
+ }
1622
+
1623
+ export interface LocalData {
1624
+ lastUsedDate: DateTime<Utc> | undefined;
1625
+ lastLaunched: DateTime<Utc> | undefined;
1626
+ }
1627
+
1628
+ export interface IdentityView {
1629
+ title: string | undefined;
1630
+ firstName: string | undefined;
1631
+ middleName: string | undefined;
1632
+ lastName: string | undefined;
1633
+ address1: string | undefined;
1634
+ address2: string | undefined;
1635
+ address3: string | undefined;
1636
+ city: string | undefined;
1637
+ state: string | undefined;
1638
+ postalCode: string | undefined;
1639
+ country: string | undefined;
1640
+ company: string | undefined;
1641
+ email: string | undefined;
1642
+ phone: string | undefined;
1643
+ ssn: string | undefined;
1644
+ username: string | undefined;
1645
+ passportNumber: string | undefined;
1646
+ licenseNumber: string | undefined;
1647
+ }
1648
+
1649
+ export interface Identity {
1650
+ title: EncString | undefined;
1651
+ firstName: EncString | undefined;
1652
+ middleName: EncString | undefined;
1653
+ lastName: EncString | undefined;
1654
+ address1: EncString | undefined;
1655
+ address2: EncString | undefined;
1656
+ address3: EncString | undefined;
1657
+ city: EncString | undefined;
1658
+ state: EncString | undefined;
1659
+ postalCode: EncString | undefined;
1660
+ country: EncString | undefined;
1661
+ company: EncString | undefined;
1662
+ email: EncString | undefined;
1663
+ phone: EncString | undefined;
1664
+ ssn: EncString | undefined;
1665
+ username: EncString | undefined;
1666
+ passportNumber: EncString | undefined;
1667
+ licenseNumber: EncString | undefined;
1668
+ }
1669
+
1670
+ /**
1671
+ * Represents the inner data of a cipher view.
1672
+ */
1673
+ export type CipherViewType =
1674
+ | { login: LoginView }
1675
+ | { card: CardView }
1676
+ | { identity: IdentityView }
1677
+ | { secureNote: SecureNoteView }
1678
+ | { sshKey: SshKeyView };
1679
+
1680
+ export interface CipherPermissions {
1681
+ delete: boolean;
1682
+ restore: boolean;
1683
+ }
1684
+
1685
+ export interface GetCipherError extends Error {
1686
+ name: "GetCipherError";
1687
+ variant: "ItemNotFound" | "Crypto" | "RepositoryError";
1688
+ }
1689
+
1690
+ export function isGetCipherError(error: any): error is GetCipherError;
1691
+
1692
+ export interface EditCipherError extends Error {
1693
+ name: "EditCipherError";
1694
+ variant:
1695
+ | "ItemNotFound"
1696
+ | "Crypto"
1697
+ | "Api"
1698
+ | "VaultParse"
1699
+ | "MissingField"
1700
+ | "NotAuthenticated"
1701
+ | "Repository"
1702
+ | "Uuid";
1703
+ }
1704
+
1705
+ export function isEditCipherError(error: any): error is EditCipherError;
1706
+
1707
+ export interface CreateCipherError extends Error {
1708
+ name: "CreateCipherError";
1709
+ variant: "Crypto" | "Api" | "VaultParse" | "MissingField" | "NotAuthenticated" | "Repository";
1710
+ }
1711
+
1712
+ export function isCreateCipherError(error: any): error is CreateCipherError;
1713
+
1714
+ export interface CipherError extends Error {
1715
+ name: "CipherError";
1716
+ variant:
1717
+ | "MissingField"
1718
+ | "Crypto"
1719
+ | "Decrypt"
1720
+ | "Encrypt"
1721
+ | "AttachmentsWithoutKeys"
1722
+ | "OrganizationAlreadySet"
1723
+ | "PutShare"
1724
+ | "PutShareMany"
1725
+ | "Repository"
1726
+ | "Chrono"
1727
+ | "SerdeJson";
1728
+ }
1729
+
1730
+ export function isCipherError(error: any): error is CipherError;
1731
+
1732
+ /**
1733
+ * Minimal CardView only including the needed details for list views
1734
+ */
1735
+ export interface CardListView {
1736
+ /**
1737
+ * The brand of the card, e.g. Visa, Mastercard, etc.
1738
+ */
1739
+ brand: string | undefined;
1740
+ }
1741
+
1742
+ export interface CardView {
1743
+ cardholderName: string | undefined;
1744
+ expMonth: string | undefined;
1745
+ expYear: string | undefined;
1746
+ code: string | undefined;
1747
+ brand: string | undefined;
1748
+ number: string | undefined;
1749
+ }
1750
+
1751
+ export interface Card {
1752
+ cardholderName: EncString | undefined;
1753
+ expMonth: EncString | undefined;
1754
+ expYear: EncString | undefined;
1755
+ code: EncString | undefined;
1756
+ brand: EncString | undefined;
1757
+ number: EncString | undefined;
1758
+ }
1759
+
1760
+ export interface DecryptFileError extends Error {
1761
+ name: "DecryptFileError";
1762
+ variant: "Decrypt" | "Io";
1763
+ }
1764
+
1765
+ export function isDecryptFileError(error: any): error is DecryptFileError;
1766
+
1767
+ export interface EncryptFileError extends Error {
1768
+ name: "EncryptFileError";
1769
+ variant: "Encrypt" | "Io";
1770
+ }
1771
+
1772
+ export function isEncryptFileError(error: any): error is EncryptFileError;
1773
+
1774
+ export interface AttachmentView {
1775
+ id: string | undefined;
1776
+ url: string | undefined;
1777
+ size: string | undefined;
1778
+ sizeName: string | undefined;
1779
+ fileName: string | undefined;
1780
+ key: EncString | undefined;
1781
+ /**
1782
+ * The decrypted attachmentkey in base64 format.
1783
+ *
1784
+ * **TEMPORARY FIELD**: This field is a temporary workaround to provide
1785
+ * decrypted attachment keys to the TypeScript client during the migration
1786
+ * process. It will be removed once the encryption/decryption logic is
1787
+ * fully migrated to the SDK.
1788
+ *
1789
+ * **Ticket**: <https://bitwarden.atlassian.net/browse/PM-23005>
1790
+ *
1791
+ * Do not rely on this field for long-term use.
1792
+ */
1793
+ decryptedKey: string | undefined;
1794
+ }
1795
+
1796
+ export interface Attachment {
1797
+ id: string | undefined;
1798
+ url: string | undefined;
1799
+ size: string | undefined;
1800
+ /**
1801
+ * Readable size, ex: \"4.2 KB\" or \"1.43 GB\
1802
+ */
1803
+ sizeName: string | undefined;
1804
+ fileName: EncString | undefined;
1805
+ key: EncString | undefined;
1806
+ }
1807
+
1808
+ export class AttachmentsClient {
1809
+ private constructor();
1810
+ free(): void;
1811
+ [Symbol.dispose](): void;
1812
+ decrypt_buffer(
1813
+ cipher: Cipher,
1814
+ attachment: AttachmentView,
1815
+ encrypted_buffer: Uint8Array,
1816
+ ): Uint8Array;
1817
+ }
1818
+ /**
1819
+ * Subclient containing auth functionality.
1820
+ */
1821
+ export class AuthClient {
1822
+ private constructor();
1823
+ free(): void;
1824
+ [Symbol.dispose](): void;
1825
+ /**
1826
+ * Client for identity functionality
1827
+ */
1828
+ identity(): IdentityClient;
1829
+ /**
1830
+ * Client for send access functionality
1831
+ */
1832
+ send_access(): SendAccessClient;
1833
+ }
1834
+ /**
1835
+ * Client for evaluating credential risk for login ciphers.
1836
+ */
1837
+ export class CipherRiskClient {
1838
+ private constructor();
1839
+ free(): void;
1840
+ [Symbol.dispose](): void;
1841
+ /**
1842
+ * Build password reuse map for a list of login ciphers.
1843
+ *
1844
+ * Returns a map where keys are passwords and values are the number of times
1845
+ * each password appears in the provided list. This map can be passed to `compute_risk()`
1846
+ * to enable password reuse detection.
1847
+ */
1848
+ password_reuse_map(login_details: CipherLoginDetails[]): PasswordReuseMap;
1849
+ /**
1850
+ * Evaluate security risks for multiple login ciphers concurrently.
1851
+ *
1852
+ * For each cipher:
1853
+ * 1. Calculates password strength (0-4) using zxcvbn with cipher-specific context
1854
+ * 2. Optionally checks if the password has been exposed via Have I Been Pwned API
1855
+ * 3. Counts how many times the password is reused in the provided `password_map`
1856
+ *
1857
+ * Returns a vector of `CipherRisk` results, one for each input cipher.
1858
+ *
1859
+ * ## HIBP Check Results (`exposed_result` field)
1860
+ *
1861
+ * The `exposed_result` field uses the `ExposedPasswordResult` enum with three possible states:
1862
+ * - `NotChecked`: Password exposure check was not performed because:
1863
+ * - `check_exposed` option was `false`, or
1864
+ * - Password was empty
1865
+ * - `Found(n)`: Successfully checked via HIBP API, password appears in `n` data breaches
1866
+ * - `Error(msg)`: HIBP API request failed with error message `msg`
1867
+ *
1868
+ * # Errors
1869
+ *
1870
+ * This method only returns `Err` for internal logic failures. HIBP API errors are
1871
+ * captured per-cipher in the `exposed_result` field as `ExposedPasswordResult::Error(msg)`.
1872
+ */
1873
+ compute_risk(
1874
+ login_details: CipherLoginDetails[],
1875
+ options: CipherRiskOptions,
1876
+ ): Promise<CipherRiskResult[]>;
1877
+ }
1878
+ export class CiphersClient {
1879
+ private constructor();
1880
+ free(): void;
1881
+ [Symbol.dispose](): void;
1882
+ /**
1883
+ * Create a new [Cipher] and save it to the server.
1884
+ */
1885
+ create(request: CipherCreateRequest): Promise<CipherView>;
1886
+ /**
1887
+ * Edit an existing [Cipher] and save it to the server.
1888
+ */
1889
+ edit(request: CipherEditRequest): Promise<CipherView>;
1890
+ /**
1891
+ * Moves a cipher into an organization, adds it to collections, and calls the share_cipher API.
1892
+ */
1893
+ share_cipher(
1894
+ cipher_view: CipherView,
1895
+ organization_id: OrganizationId,
1896
+ collection_ids: CollectionId[],
1897
+ original_cipher?: Cipher | null,
1898
+ ): Promise<Cipher>;
1899
+ /**
1900
+ * Moves a group of ciphers into an organization, adds them to collections, and calls the
1901
+ * share_ciphers API.
1902
+ */
1903
+ share_ciphers_bulk(
1904
+ cipher_views: CipherView[],
1905
+ organization_id: OrganizationId,
1906
+ collection_ids: CollectionId[],
1907
+ ): Promise<Cipher[]>;
1908
+ encrypt(cipher_view: CipherView): EncryptionContext;
1909
+ /**
1910
+ * Encrypt a cipher with the provided key. This should only be used when rotating encryption
1911
+ * keys in the Web client.
1912
+ *
1913
+ * Until key rotation is fully implemented in the SDK, this method must be provided the new
1914
+ * symmetric key in base64 format. See PM-23084
1915
+ *
1916
+ * If the cipher has a CipherKey, it will be re-encrypted with the new key.
1917
+ * If the cipher does not have a CipherKey and CipherKeyEncryption is enabled, one will be
1918
+ * generated using the new key. Otherwise, the cipher's data will be encrypted with the new
1919
+ * key directly.
1920
+ */
1921
+ encrypt_cipher_for_rotation(cipher_view: CipherView, new_key: B64): EncryptionContext;
1922
+ decrypt(cipher: Cipher): CipherView;
1923
+ decrypt_list(ciphers: Cipher[]): CipherListView[];
1924
+ /**
1925
+ * Decrypt cipher list with failures
1926
+ * Returns both successfully decrypted ciphers and any that failed to decrypt
1927
+ */
1928
+ decrypt_list_with_failures(ciphers: Cipher[]): DecryptCipherListResult;
1929
+ decrypt_fido2_credentials(cipher_view: CipherView): Fido2CredentialView[];
1930
+ /**
1931
+ * Temporary method used to re-encrypt FIDO2 credentials for a cipher view.
1932
+ * Necessary until the TS clients utilize the SDK entirely for FIDO2 credentials management.
1933
+ * TS clients create decrypted FIDO2 credentials that need to be encrypted manually when
1934
+ * encrypting the rest of the CipherView.
1935
+ * TODO: Remove once TS passkey provider implementation uses SDK - PM-8313
1936
+ */
1937
+ set_fido2_credentials(
1938
+ cipher_view: CipherView,
1939
+ fido2_credentials: Fido2CredentialFullView[],
1940
+ ): CipherView;
1941
+ move_to_organization(cipher_view: CipherView, organization_id: OrganizationId): CipherView;
1942
+ decrypt_fido2_private_key(cipher_view: CipherView): string;
1943
+ }
1944
+ export class CollectionViewNodeItem {
1945
+ private constructor();
1946
+ free(): void;
1947
+ [Symbol.dispose](): void;
1948
+ get_item(): CollectionView;
1949
+ get_parent(): CollectionView | undefined;
1950
+ get_children(): CollectionView[];
1951
+ get_ancestors(): AncestorMap;
1952
+ }
1953
+ export class CollectionViewTree {
1954
+ private constructor();
1955
+ free(): void;
1956
+ [Symbol.dispose](): void;
1957
+ get_item_for_view(collection_view: CollectionView): CollectionViewNodeItem | undefined;
1958
+ get_root_items(): CollectionViewNodeItem[];
1959
+ get_flat_items(): CollectionViewNodeItem[];
1960
+ }
1961
+ export class CollectionsClient {
1962
+ private constructor();
1963
+ free(): void;
1964
+ [Symbol.dispose](): void;
1965
+ decrypt(collection: Collection): CollectionView;
1966
+ decrypt_list(collections: Collection[]): CollectionView[];
1967
+ /**
1968
+ *
1969
+ * Returns the vector of CollectionView objects in a tree structure based on its implemented
1970
+ * path().
1971
+ */
1972
+ get_collection_tree(collections: CollectionView[]): CollectionViewTree;
1973
+ }
1974
+ /**
1975
+ * A client for the crypto operations.
1976
+ */
1977
+ export class CryptoClient {
1978
+ private constructor();
1979
+ free(): void;
1980
+ [Symbol.dispose](): void;
1981
+ /**
1982
+ * Initialization method for the user crypto. Needs to be called before any other crypto
1983
+ * operations.
1984
+ */
1985
+ initialize_user_crypto(req: InitUserCryptoRequest): Promise<void>;
1986
+ /**
1987
+ * Initialization method for the organization crypto. Needs to be called after
1988
+ * `initialize_user_crypto` but before any other crypto operations.
1989
+ */
1990
+ initialize_org_crypto(req: InitOrgCryptoRequest): Promise<void>;
1991
+ /**
1992
+ * Generates a new key pair and encrypts the private key with the provided user key.
1993
+ * Crypto initialization not required.
1994
+ */
1995
+ make_key_pair(user_key: B64): MakeKeyPairResponse;
1996
+ /**
1997
+ * Verifies a user's asymmetric keys by decrypting the private key with the provided user
1998
+ * key. Returns if the private key is decryptable and if it is a valid matching key.
290
1999
  * Crypto initialization not required.
291
2000
  */
292
2001
  verify_asymmetric_keys(request: VerifyAsymmetricKeysRequest): VerifyAsymmetricKeysResponse;
2002
+ /**
2003
+ * Makes a new signing key pair and signs the public key for the user
2004
+ */
2005
+ make_keys_for_user_crypto_v2(): UserCryptoV2KeysResponse;
2006
+ /**
2007
+ * Creates a rotated set of account keys for the current state
2008
+ */
2009
+ get_v2_rotated_account_keys(): UserCryptoV2KeysResponse;
2010
+ /**
2011
+ * Create the data necessary to update the user's kdf settings. The user's encryption key is
2012
+ * re-encrypted for the password under the new kdf settings. This returns the re-encrypted
2013
+ * user key and the new password hash but does not update sdk state.
2014
+ */
2015
+ make_update_kdf(password: string, kdf: Kdf): UpdateKdfResponse;
2016
+ /**
2017
+ * Protects the current user key with the provided PIN. The result can be stored and later
2018
+ * used to initialize another client instance by using the PIN and the PIN key with
2019
+ * `initialize_user_crypto`.
2020
+ */
2021
+ enroll_pin(pin: string): EnrollPinResponse;
2022
+ /**
2023
+ * Protects the current user key with the provided PIN. The result can be stored and later
2024
+ * used to initialize another client instance by using the PIN and the PIN key with
2025
+ * `initialize_user_crypto`. The provided pin is encrypted with the user key.
2026
+ */
2027
+ enroll_pin_with_encrypted_pin(encrypted_pin: string): EnrollPinResponse;
2028
+ /**
2029
+ * Decrypts a `PasswordProtectedKeyEnvelope`, returning the user key, if successful.
2030
+ * This is a stop-gap solution, until initialization of the SDK is used.
2031
+ */
2032
+ unseal_password_protected_key_envelope(pin: string, envelope: string): Uint8Array;
2033
+ }
2034
+ export class ExporterClient {
2035
+ private constructor();
2036
+ free(): void;
2037
+ [Symbol.dispose](): void;
2038
+ export_vault(folders: Folder[], ciphers: Cipher[], format: ExportFormat): string;
2039
+ export_organization_vault(
2040
+ collections: Collection[],
2041
+ ciphers: Cipher[],
2042
+ format: ExportFormat,
2043
+ ): string;
2044
+ /**
2045
+ * Credential Exchange Format (CXF)
2046
+ *
2047
+ * *Warning:* Expect this API to be unstable, and it will change in the future.
2048
+ *
2049
+ * For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
2050
+ * Ideally, the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
2051
+ */
2052
+ export_cxf(account: Account, ciphers: Cipher[]): string;
2053
+ /**
2054
+ * Credential Exchange Format (CXF)
2055
+ *
2056
+ * *Warning:* Expect this API to be unstable, and it will change in the future.
2057
+ *
2058
+ * For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
2059
+ * Ideally, the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
2060
+ */
2061
+ import_cxf(payload: string): Cipher[];
293
2062
  }
294
- export class ClientFolders {
2063
+ /**
2064
+ * Wrapper for folder specific functionality.
2065
+ */
2066
+ export class FoldersClient {
295
2067
  private constructor();
296
2068
  free(): void;
2069
+ [Symbol.dispose](): void;
2070
+ /**
2071
+ * Encrypt a [FolderView] to a [Folder].
2072
+ */
2073
+ encrypt(folder_view: FolderView): Folder;
297
2074
  /**
298
- * Decrypt folder
2075
+ * Encrypt a [Folder] to [FolderView].
299
2076
  */
300
2077
  decrypt(folder: Folder): FolderView;
2078
+ /**
2079
+ * Decrypt a list of [Folder]s to a list of [FolderView]s.
2080
+ */
2081
+ decrypt_list(folders: Folder[]): FolderView[];
2082
+ /**
2083
+ * Get all folders from state and decrypt them to a list of [FolderView].
2084
+ */
2085
+ list(): Promise<FolderView[]>;
2086
+ /**
2087
+ * Get a specific [Folder] by its ID from state and decrypt it to a [FolderView].
2088
+ */
2089
+ get(folder_id: FolderId): Promise<FolderView>;
2090
+ /**
2091
+ * Create a new [Folder] and save it to the server.
2092
+ */
2093
+ create(request: FolderAddEditRequest): Promise<FolderView>;
2094
+ /**
2095
+ * Edit the [Folder] and save it to the server.
2096
+ */
2097
+ edit(folder_id: FolderId, request: FolderAddEditRequest): Promise<FolderView>;
301
2098
  }
302
- export class ClientVault {
2099
+ export class GeneratorClient {
303
2100
  private constructor();
304
2101
  free(): void;
305
- folders(): ClientFolders;
2102
+ [Symbol.dispose](): void;
2103
+ /**
2104
+ * Generates a random password.
2105
+ *
2106
+ * The character sets and password length can be customized using the `input` parameter.
2107
+ *
2108
+ * # Examples
2109
+ *
2110
+ * ```
2111
+ * use bitwarden_core::Client;
2112
+ * use bitwarden_generators::{GeneratorClientsExt, PassphraseError, PasswordGeneratorRequest};
2113
+ *
2114
+ * async fn test() -> Result<(), PassphraseError> {
2115
+ * let input = PasswordGeneratorRequest {
2116
+ * lowercase: true,
2117
+ * uppercase: true,
2118
+ * numbers: true,
2119
+ * length: 20,
2120
+ * ..Default::default()
2121
+ * };
2122
+ * let password = Client::new(None).generator().password(input).unwrap();
2123
+ * println!("{}", password);
2124
+ * Ok(())
2125
+ * }
2126
+ * ```
2127
+ */
2128
+ password(input: PasswordGeneratorRequest): string;
2129
+ /**
2130
+ * Generates a random passphrase.
2131
+ * A passphrase is a combination of random words separated by a character.
2132
+ * An example of passphrase is `correct horse battery staple`.
2133
+ *
2134
+ * The number of words and their case, the word separator, and the inclusion of
2135
+ * a number in the passphrase can be customized using the `input` parameter.
2136
+ *
2137
+ * # Examples
2138
+ *
2139
+ * ```
2140
+ * use bitwarden_core::Client;
2141
+ * use bitwarden_generators::{GeneratorClientsExt, PassphraseError, PassphraseGeneratorRequest};
2142
+ *
2143
+ * async fn test() -> Result<(), PassphraseError> {
2144
+ * let input = PassphraseGeneratorRequest {
2145
+ * num_words: 4,
2146
+ * ..Default::default()
2147
+ * };
2148
+ * let passphrase = Client::new(None).generator().passphrase(input).unwrap();
2149
+ * println!("{}", passphrase);
2150
+ * Ok(())
2151
+ * }
2152
+ * ```
2153
+ */
2154
+ passphrase(input: PassphraseGeneratorRequest): string;
2155
+ }
2156
+ /**
2157
+ * The IdentityClient is used to obtain identity / access tokens from the Bitwarden Identity API.
2158
+ */
2159
+ export class IdentityClient {
2160
+ private constructor();
2161
+ free(): void;
2162
+ [Symbol.dispose](): void;
2163
+ }
2164
+ export class IncomingMessage {
2165
+ free(): void;
2166
+ [Symbol.dispose](): void;
2167
+ constructor(payload: Uint8Array, destination: Endpoint, source: Endpoint, topic?: string | null);
2168
+ /**
2169
+ * Try to parse the payload as JSON.
2170
+ * @returns The parsed JSON value, or undefined if the payload is not valid JSON.
2171
+ */
2172
+ parse_payload_as_json(): any;
2173
+ payload: Uint8Array;
2174
+ destination: Endpoint;
2175
+ source: Endpoint;
2176
+ get topic(): string | undefined;
2177
+ set topic(value: string | null | undefined);
2178
+ }
2179
+ /**
2180
+ * JavaScript wrapper around the IPC client. For more information, see the
2181
+ * [IpcClient] documentation.
2182
+ */
2183
+ export class IpcClient {
2184
+ private constructor();
2185
+ free(): void;
2186
+ [Symbol.dispose](): void;
2187
+ /**
2188
+ * Create a new `IpcClient` instance with an in-memory session repository for saving
2189
+ * sessions within the SDK.
2190
+ */
2191
+ static newWithSdkInMemorySessions(communication_provider: IpcCommunicationBackend): IpcClient;
2192
+ /**
2193
+ * Create a new `IpcClient` instance with a client-managed session repository for saving
2194
+ * sessions using State Provider.
2195
+ */
2196
+ static newWithClientManagedSessions(
2197
+ communication_provider: IpcCommunicationBackend,
2198
+ session_repository: IpcSessionRepository,
2199
+ ): IpcClient;
2200
+ start(): Promise<void>;
2201
+ isRunning(): Promise<boolean>;
2202
+ send(message: OutgoingMessage): Promise<void>;
2203
+ subscribe(): Promise<IpcClientSubscription>;
2204
+ }
2205
+ /**
2206
+ * JavaScript wrapper around the IPC client subscription. For more information, see the
2207
+ * [IpcClientSubscription](crate::IpcClientSubscription) documentation.
2208
+ */
2209
+ export class IpcClientSubscription {
2210
+ private constructor();
2211
+ free(): void;
2212
+ [Symbol.dispose](): void;
2213
+ receive(abort_signal?: AbortSignal | null): Promise<IncomingMessage>;
2214
+ }
2215
+ /**
2216
+ * JavaScript implementation of the `CommunicationBackend` trait for IPC communication.
2217
+ */
2218
+ export class IpcCommunicationBackend {
2219
+ free(): void;
2220
+ [Symbol.dispose](): void;
2221
+ /**
2222
+ * Creates a new instance of the JavaScript communication backend.
2223
+ */
2224
+ constructor(sender: IpcCommunicationBackendSender);
2225
+ /**
2226
+ * Used by JavaScript to provide an incoming message to the IPC framework.
2227
+ */
2228
+ receive(message: IncomingMessage): void;
2229
+ }
2230
+ export class OutgoingMessage {
2231
+ free(): void;
2232
+ [Symbol.dispose](): void;
2233
+ constructor(payload: Uint8Array, destination: Endpoint, topic?: string | null);
2234
+ /**
2235
+ * Create a new message and encode the payload as JSON.
2236
+ */
2237
+ static new_json_payload(
2238
+ payload: any,
2239
+ destination: Endpoint,
2240
+ topic?: string | null,
2241
+ ): OutgoingMessage;
2242
+ payload: Uint8Array;
2243
+ destination: Endpoint;
2244
+ get topic(): string | undefined;
2245
+ set topic(value: string | null | undefined);
2246
+ }
2247
+ /**
2248
+ * The main entry point for the Bitwarden SDK in WebAssembly environments
2249
+ */
2250
+ export class PasswordManagerClient {
2251
+ free(): void;
2252
+ [Symbol.dispose](): void;
2253
+ /**
2254
+ * Initialize a new instance of the SDK client
2255
+ */
2256
+ constructor(token_provider: any, settings?: ClientSettings | null);
2257
+ /**
2258
+ * Test method, echoes back the input
2259
+ */
2260
+ echo(msg: string): string;
2261
+ /**
2262
+ * Returns the current SDK version
2263
+ */
2264
+ version(): string;
2265
+ /**
2266
+ * Test method, always throws an error
2267
+ */
2268
+ throw(msg: string): void;
2269
+ /**
2270
+ * Test method, calls http endpoint
2271
+ */
2272
+ http_get(url: string): Promise<string>;
2273
+ /**
2274
+ * Auth related operations.
2275
+ */
2276
+ auth(): AuthClient;
2277
+ /**
2278
+ * Crypto related operations.
2279
+ */
2280
+ crypto(): CryptoClient;
2281
+ /**
2282
+ * Vault item related operations.
2283
+ */
2284
+ vault(): VaultClient;
2285
+ /**
2286
+ * Constructs a specific client for platform-specific functionality
2287
+ */
2288
+ platform(): PlatformClient;
2289
+ /**
2290
+ * Constructs a specific client for generating passwords and passphrases
2291
+ */
2292
+ generator(): GeneratorClient;
2293
+ /**
2294
+ * Exporter related operations.
2295
+ */
2296
+ exporters(): ExporterClient;
2297
+ }
2298
+ export class PlatformClient {
2299
+ private constructor();
2300
+ free(): void;
2301
+ [Symbol.dispose](): void;
2302
+ state(): StateClient;
2303
+ /**
2304
+ * Load feature flags into the client
2305
+ */
2306
+ load_flags(flags: FeatureFlags): void;
2307
+ }
2308
+ /**
2309
+ * This module represents a stopgap solution to provide access to primitive crypto functions for JS
2310
+ * clients. It is not intended to be used outside of the JS clients and this pattern should not be
2311
+ * proliferated. It is necessary because we want to use SDK crypto prior to the SDK being fully
2312
+ * responsible for state and keys.
2313
+ */
2314
+ export class PureCrypto {
2315
+ private constructor();
2316
+ free(): void;
2317
+ [Symbol.dispose](): void;
2318
+ /**
2319
+ * DEPRECATED: Use `symmetric_decrypt_string` instead.
2320
+ * Cleanup ticket: <https://bitwarden.atlassian.net/browse/PM-21247>
2321
+ */
2322
+ static symmetric_decrypt(enc_string: string, key: Uint8Array): string;
2323
+ static symmetric_decrypt_string(enc_string: string, key: Uint8Array): string;
2324
+ static symmetric_decrypt_bytes(enc_string: string, key: Uint8Array): Uint8Array;
2325
+ /**
2326
+ * DEPRECATED: Use `symmetric_decrypt_filedata` instead.
2327
+ * Cleanup ticket: <https://bitwarden.atlassian.net/browse/PM-21247>
2328
+ */
2329
+ static symmetric_decrypt_array_buffer(enc_bytes: Uint8Array, key: Uint8Array): Uint8Array;
2330
+ static symmetric_decrypt_filedata(enc_bytes: Uint8Array, key: Uint8Array): Uint8Array;
2331
+ static symmetric_encrypt_string(plain: string, key: Uint8Array): string;
2332
+ /**
2333
+ * DEPRECATED: Only used by send keys
2334
+ */
2335
+ static symmetric_encrypt_bytes(plain: Uint8Array, key: Uint8Array): string;
2336
+ static symmetric_encrypt_filedata(plain: Uint8Array, key: Uint8Array): Uint8Array;
2337
+ static decrypt_user_key_with_master_password(
2338
+ encrypted_user_key: string,
2339
+ master_password: string,
2340
+ email: string,
2341
+ kdf: Kdf,
2342
+ ): Uint8Array;
2343
+ static encrypt_user_key_with_master_password(
2344
+ user_key: Uint8Array,
2345
+ master_password: string,
2346
+ email: string,
2347
+ kdf: Kdf,
2348
+ ): string;
2349
+ static make_user_key_aes256_cbc_hmac(): Uint8Array;
2350
+ static make_user_key_xchacha20_poly1305(): Uint8Array;
2351
+ /**
2352
+ * Wraps (encrypts) a symmetric key using a symmetric wrapping key, returning the wrapped key
2353
+ * as an EncString.
2354
+ */
2355
+ static wrap_symmetric_key(key_to_be_wrapped: Uint8Array, wrapping_key: Uint8Array): string;
2356
+ /**
2357
+ * Unwraps (decrypts) a wrapped symmetric key using a symmetric wrapping key, returning the
2358
+ * unwrapped key as a serialized byte array.
2359
+ */
2360
+ static unwrap_symmetric_key(wrapped_key: string, wrapping_key: Uint8Array): Uint8Array;
2361
+ /**
2362
+ * Wraps (encrypts) an SPKI DER encoded encapsulation (public) key using a symmetric wrapping
2363
+ * key. Note: Usually, a public key is - by definition - public, so this should not be
2364
+ * used. The specific use-case for this function is to enable rotateable key sets, where
2365
+ * the "public key" is not public, with the intent of preventing the server from being able
2366
+ * to overwrite the user key unlocked by the rotateable keyset.
2367
+ */
2368
+ static wrap_encapsulation_key(encapsulation_key: Uint8Array, wrapping_key: Uint8Array): string;
2369
+ /**
2370
+ * Unwraps (decrypts) a wrapped SPKI DER encoded encapsulation (public) key using a symmetric
2371
+ * wrapping key.
2372
+ */
2373
+ static unwrap_encapsulation_key(wrapped_key: string, wrapping_key: Uint8Array): Uint8Array;
2374
+ /**
2375
+ * Wraps (encrypts) a PKCS8 DER encoded decapsulation (private) key using a symmetric wrapping
2376
+ * key,
2377
+ */
2378
+ static wrap_decapsulation_key(decapsulation_key: Uint8Array, wrapping_key: Uint8Array): string;
2379
+ /**
2380
+ * Unwraps (decrypts) a wrapped PKCS8 DER encoded decapsulation (private) key using a symmetric
2381
+ * wrapping key.
2382
+ */
2383
+ static unwrap_decapsulation_key(wrapped_key: string, wrapping_key: Uint8Array): Uint8Array;
2384
+ /**
2385
+ * Encapsulates (encrypts) a symmetric key using an asymmetric encapsulation key (public key)
2386
+ * in SPKI format, returning the encapsulated key as a string. Note: This is unsigned, so
2387
+ * the sender's authenticity cannot be verified by the recipient.
2388
+ */
2389
+ static encapsulate_key_unsigned(shared_key: Uint8Array, encapsulation_key: Uint8Array): string;
2390
+ /**
2391
+ * Decapsulates (decrypts) a symmetric key using an decapsulation key (private key) in PKCS8
2392
+ * DER format. Note: This is unsigned, so the sender's authenticity cannot be verified by the
2393
+ * recipient.
2394
+ */
2395
+ static decapsulate_key_unsigned(
2396
+ encapsulated_key: string,
2397
+ decapsulation_key: Uint8Array,
2398
+ ): Uint8Array;
2399
+ /**
2400
+ * Given a wrapped signing key and the symmetric key it is wrapped with, this returns
2401
+ * the corresponding verifying key.
2402
+ */
2403
+ static verifying_key_for_signing_key(signing_key: string, wrapping_key: Uint8Array): Uint8Array;
2404
+ /**
2405
+ * Returns the algorithm used for the given verifying key.
2406
+ */
2407
+ static key_algorithm_for_verifying_key(verifying_key: Uint8Array): SignatureAlgorithm;
2408
+ /**
2409
+ * For a given signing identity (verifying key), this function verifies that the signing
2410
+ * identity claimed ownership of the public key. This is a one-sided claim and merely shows
2411
+ * that the signing identity has the intent to receive messages encrypted to the public
2412
+ * key.
2413
+ */
2414
+ static verify_and_unwrap_signed_public_key(
2415
+ signed_public_key: Uint8Array,
2416
+ verifying_key: Uint8Array,
2417
+ ): Uint8Array;
2418
+ /**
2419
+ * Derive output of the KDF for a [bitwarden_crypto::Kdf] configuration.
2420
+ */
2421
+ static derive_kdf_material(password: Uint8Array, salt: Uint8Array, kdf: Kdf): Uint8Array;
2422
+ static decrypt_user_key_with_master_key(
2423
+ encrypted_user_key: string,
2424
+ master_key: Uint8Array,
2425
+ ): Uint8Array;
2426
+ /**
2427
+ * Given an encrypted private RSA key and the symmetric key it is wrapped with, this returns
2428
+ * the corresponding public RSA key in DER format.
2429
+ */
2430
+ static rsa_extract_public_key(
2431
+ encrypted_private_key: string,
2432
+ wrapping_key: Uint8Array,
2433
+ ): Uint8Array;
2434
+ }
2435
+ /**
2436
+ * The `SendAccessClient` is used to interact with the Bitwarden API to get send access tokens.
2437
+ */
2438
+ export class SendAccessClient {
2439
+ private constructor();
2440
+ free(): void;
2441
+ [Symbol.dispose](): void;
2442
+ /**
2443
+ * Requests a new send access token.
2444
+ */
2445
+ request_send_access_token(request: SendAccessTokenRequest): Promise<SendAccessTokenResponse>;
2446
+ }
2447
+ export class StateClient {
2448
+ private constructor();
2449
+ free(): void;
2450
+ [Symbol.dispose](): void;
2451
+ register_cipher_repository(cipher_repository: any): void;
2452
+ register_folder_repository(store: any): void;
2453
+ register_client_managed_repositories(repositories: Repositories): void;
2454
+ /**
2455
+ * Initialize the database for SDK managed repositories.
2456
+ */
2457
+ initialize_state(configuration: IndexedDbConfiguration): Promise<void>;
2458
+ }
2459
+ export class TotpClient {
2460
+ private constructor();
2461
+ free(): void;
2462
+ [Symbol.dispose](): void;
2463
+ /**
2464
+ * Generates a TOTP code from a provided key
2465
+ *
2466
+ * # Arguments
2467
+ * - `key` - Can be:
2468
+ * - A base32 encoded string
2469
+ * - OTP Auth URI
2470
+ * - Steam URI
2471
+ * - `time_ms` - Optional timestamp in milliseconds
2472
+ */
2473
+ generate_totp(key: string, time_ms?: number | null): TotpResponse;
2474
+ }
2475
+ export class VaultClient {
2476
+ private constructor();
2477
+ free(): void;
2478
+ [Symbol.dispose](): void;
2479
+ /**
2480
+ * Attachment related operations.
2481
+ */
2482
+ attachments(): AttachmentsClient;
2483
+ /**
2484
+ * Cipher related operations.
2485
+ */
2486
+ ciphers(): CiphersClient;
2487
+ /**
2488
+ * Folder related operations.
2489
+ */
2490
+ folders(): FoldersClient;
2491
+ /**
2492
+ * TOTP related operations.
2493
+ */
2494
+ totp(): TotpClient;
2495
+ /**
2496
+ * Collection related operations.
2497
+ */
2498
+ collections(): CollectionsClient;
2499
+ /**
2500
+ * Cipher risk evaluation operations.
2501
+ */
2502
+ cipher_risk(): CipherRiskClient;
306
2503
  }