@bitwarden/sdk-internal 0.2.0-main.39 → 0.2.0-main.391

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