@bitwarden/sdk-internal 0.2.0-main.34 → 0.2.0-main.340

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,216 +375,1389 @@ 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 } }
32
398
  | { decryptedKey: { decrypted_user_key: string } }
33
399
  | { pin: { pin: string; pin_protected_user_key: EncString } }
34
- | { authRequest: { request_private_key: string; method: AuthRequestMethod } }
400
+ | { pinEnvelope: { pin: string; pin_protected_user_key_envelope: PasswordProtectedKeyEnvelope } }
401
+ | { authRequest: { request_private_key: B64; method: AuthRequestMethod } }
35
402
  | {
36
403
  deviceKey: {
37
404
  device_key: string;
38
405
  protected_device_private_key: EncString;
39
- device_protected_user_key: AsymmetricEncString;
406
+ device_protected_user_key: UnsignedSharedKey;
40
407
  };
41
408
  }
42
- | { keyConnector: { master_key: string; user_key: string } };
409
+ | { keyConnector: { master_key: B64; user_key: EncString } };
43
410
 
411
+ /**
412
+ * Auth requests supports multiple initialization methods.
413
+ */
44
414
  export type AuthRequestMethod =
45
- | { userKey: { protected_user_key: AsymmetricEncString } }
46
- | { masterKey: { protected_master_key: AsymmetricEncString; auth_request_key: EncString } };
415
+ | { userKey: { protected_user_key: UnsignedSharedKey } }
416
+ | { masterKey: { protected_master_key: UnsignedSharedKey; auth_request_key: EncString } };
47
417
 
418
+ /**
419
+ * Represents the request to initialize the user\'s organizational cryptographic state.
420
+ */
48
421
  export interface InitOrgCryptoRequest {
49
422
  /**
50
423
  * The encryption keys for all the organizations the user is a part of
51
424
  */
52
- organizationKeys: Map<Uuid, AsymmetricEncString>;
425
+ organizationKeys: Map<OrganizationId, UnsignedSharedKey>;
53
426
  }
54
427
 
55
- export interface CoreError extends Error {
56
- name: "CoreError";
57
- variant:
58
- | "MissingFieldError"
59
- | "VaultLocked"
60
- | "NotAuthenticated"
61
- | "AccessTokenInvalid"
62
- | "InvalidResponse"
63
- | "Crypto"
64
- | "IdentityFail"
65
- | "Reqwest"
66
- | "Serde"
67
- | "Io"
68
- | "InvalidBase64"
69
- | "Chrono"
70
- | "ResponseContent"
71
- | "ValidationError"
72
- | "InvalidStateFileVersion"
73
- | "InvalidStateFile"
74
- | "Internal"
75
- | "EncryptionSettings";
76
- }
77
-
78
- export function isCoreError(error: any): error is CoreError;
428
+ /**
429
+ * Response from the `update_kdf` function
430
+ */
431
+ export interface UpdateKdfResponse {
432
+ /**
433
+ * The authentication data for the new KDF setting
434
+ */
435
+ masterPasswordAuthenticationData: MasterPasswordAuthenticationData;
436
+ /**
437
+ * The unlock data for the new KDF setting
438
+ */
439
+ masterPasswordUnlockData: MasterPasswordUnlockData;
440
+ /**
441
+ * The authentication data for the KDF setting prior to the change
442
+ */
443
+ oldMasterPasswordAuthenticationData: MasterPasswordAuthenticationData;
444
+ }
79
445
 
80
- export interface EncryptionSettingsError extends Error {
81
- name: "EncryptionSettingsError";
82
- variant: "Crypto" | "InvalidBase64" | "VaultLocked" | "InvalidPrivateKey" | "MissingPrivateKey";
446
+ /**
447
+ * Response from the `update_password` function
448
+ */
449
+ export interface UpdatePasswordResponse {
450
+ /**
451
+ * Hash of the new password
452
+ */
453
+ passwordHash: B64;
454
+ /**
455
+ * User key, encrypted with the new password
456
+ */
457
+ newKey: EncString;
83
458
  }
84
459
 
85
- export function isEncryptionSettingsError(error: any): error is EncryptionSettingsError;
460
+ /**
461
+ * Request for deriving a pin protected user key
462
+ */
463
+ export interface EnrollPinResponse {
464
+ /**
465
+ * [UserKey] protected by PIN
466
+ */
467
+ pinProtectedUserKeyEnvelope: PasswordProtectedKeyEnvelope;
468
+ /**
469
+ * PIN protected by [UserKey]
470
+ */
471
+ userKeyEncryptedPin: EncString;
472
+ }
86
473
 
87
- export type DeviceType =
88
- | "Android"
89
- | "iOS"
90
- | "ChromeExtension"
91
- | "FirefoxExtension"
92
- | "OperaExtension"
93
- | "EdgeExtension"
94
- | "WindowsDesktop"
95
- | "MacOsDesktop"
96
- | "LinuxDesktop"
97
- | "ChromeBrowser"
98
- | "FirefoxBrowser"
99
- | "OperaBrowser"
100
- | "EdgeBrowser"
101
- | "IEBrowser"
102
- | "UnknownBrowser"
103
- | "AndroidAmazon"
104
- | "UWP"
105
- | "SafariBrowser"
106
- | "VivaldiBrowser"
107
- | "VivaldiExtension"
108
- | "SafariExtension"
109
- | "SDK"
110
- | "Server"
111
- | "WindowsCLI"
112
- | "MacOsCLI"
113
- | "LinuxCLI";
474
+ /**
475
+ * Request for deriving a pin protected user key
476
+ */
477
+ export interface DerivePinKeyResponse {
478
+ /**
479
+ * [UserKey] protected by PIN
480
+ */
481
+ pinProtectedUserKey: EncString;
482
+ /**
483
+ * PIN protected by [UserKey]
484
+ */
485
+ encryptedPin: EncString;
486
+ }
114
487
 
115
488
  /**
116
- * Basic client behavior settings. These settings specify the various targets and behavior of the
117
- * Bitwarden Client. They are optional and uneditable once the client is initialized.
118
- *
119
- * Defaults to
120
- *
121
- * ```
122
- * # use bitwarden_core::{ClientSettings, DeviceType};
123
- * let settings = ClientSettings {
124
- * identity_url: \"https://identity.bitwarden.com\".to_string(),
125
- * api_url: \"https://api.bitwarden.com\".to_string(),
126
- * user_agent: \"Bitwarden Rust-SDK\".to_string(),
127
- * device_type: DeviceType::SDK,
128
- * };
129
- * let default = ClientSettings::default();
130
- * ```
489
+ * Request for migrating an account from password to key connector.
131
490
  */
132
- export interface ClientSettings {
491
+ export interface DeriveKeyConnectorRequest {
492
+ /**
493
+ * Encrypted user key, used to validate the master key
494
+ */
495
+ userKeyEncrypted: EncString;
496
+ /**
497
+ * The user\'s master password
498
+ */
499
+ password: string;
500
+ /**
501
+ * The KDF parameters used to derive the master key
502
+ */
503
+ kdf: Kdf;
504
+ /**
505
+ * The user\'s email address
506
+ */
507
+ email: string;
508
+ }
509
+
510
+ /**
511
+ * Response from the `make_key_pair` function
512
+ */
513
+ export interface MakeKeyPairResponse {
514
+ /**
515
+ * The user\'s public key
516
+ */
517
+ userPublicKey: B64;
518
+ /**
519
+ * User\'s private key, encrypted with the user key
520
+ */
521
+ userKeyEncryptedPrivateKey: EncString;
522
+ }
523
+
524
+ /**
525
+ * Request for `verify_asymmetric_keys`.
526
+ */
527
+ export interface VerifyAsymmetricKeysRequest {
528
+ /**
529
+ * The user\'s user key
530
+ */
531
+ userKey: B64;
532
+ /**
533
+ * The user\'s public key
534
+ */
535
+ userPublicKey: B64;
536
+ /**
537
+ * User\'s private key, encrypted with the user key
538
+ */
539
+ userKeyEncryptedPrivateKey: EncString;
540
+ }
541
+
542
+ /**
543
+ * Response for `verify_asymmetric_keys`.
544
+ */
545
+ export interface VerifyAsymmetricKeysResponse {
546
+ /**
547
+ * Whether the user\'s private key was decryptable by the user key.
548
+ */
549
+ privateKeyDecryptable: boolean;
550
+ /**
551
+ * Whether the user\'s private key was a valid RSA key and matched the public key provided.
552
+ */
553
+ validPrivateKey: boolean;
554
+ }
555
+
556
+ /**
557
+ * Response for the `make_keys_for_user_crypto_v2`, containing a set of keys for a user
558
+ */
559
+ export interface UserCryptoV2KeysResponse {
560
+ /**
561
+ * User key
562
+ */
563
+ userKey: B64;
564
+ /**
565
+ * Wrapped private key
566
+ */
567
+ privateKey: EncString;
568
+ /**
569
+ * Public key
570
+ */
571
+ publicKey: B64;
572
+ /**
573
+ * The user\'s public key, signed by the signing key
574
+ */
575
+ signedPublicKey: SignedPublicKey;
576
+ /**
577
+ * Signing key, encrypted with the user\'s symmetric key
578
+ */
579
+ signingKey: EncString;
580
+ /**
581
+ * Base64 encoded verifying key
582
+ */
583
+ verifyingKey: B64;
584
+ /**
585
+ * The user\'s signed security state
586
+ */
587
+ securityState: SignedSecurityState;
588
+ /**
589
+ * The security state\'s version
590
+ */
591
+ securityVersion: number;
592
+ }
593
+
594
+ /**
595
+ * Represents the data required to unlock with the master password.
596
+ */
597
+ export interface MasterPasswordUnlockData {
598
+ /**
599
+ * The key derivation function used to derive the master key
600
+ */
601
+ kdf: Kdf;
602
+ /**
603
+ * The master key wrapped user key
604
+ */
605
+ masterKeyWrappedUserKey: EncString;
606
+ /**
607
+ * The salt used in the KDF, typically the user\'s email
608
+ */
609
+ salt: string;
610
+ }
611
+
612
+ /**
613
+ * Represents the data required to authenticate with the master password.
614
+ */
615
+ export interface MasterPasswordAuthenticationData {
616
+ kdf: Kdf;
617
+ salt: string;
618
+ masterPasswordAuthenticationHash: B64;
619
+ }
620
+
621
+ export type SignedSecurityState = string;
622
+
623
+ /**
624
+ * NewType wrapper for `UserId`
625
+ */
626
+ export type UserId = Tagged<Uuid, "UserId">;
627
+
628
+ /**
629
+ * NewType wrapper for `OrganizationId`
630
+ */
631
+ export type OrganizationId = Tagged<Uuid, "OrganizationId">;
632
+
633
+ /**
634
+ * A non-generic wrapper around `bitwarden-crypto`\'s `PasswordProtectedKeyEnvelope`.
635
+ */
636
+ export type PasswordProtectedKeyEnvelope = Tagged<string, "PasswordProtectedKeyEnvelope">;
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"
696
+ | "FirefoxExtension"
697
+ | "OperaExtension"
698
+ | "EdgeExtension"
699
+ | "WindowsDesktop"
700
+ | "MacOsDesktop"
701
+ | "LinuxDesktop"
702
+ | "ChromeBrowser"
703
+ | "FirefoxBrowser"
704
+ | "OperaBrowser"
705
+ | "EdgeBrowser"
706
+ | "IEBrowser"
707
+ | "UnknownBrowser"
708
+ | "AndroidAmazon"
709
+ | "UWP"
710
+ | "SafariBrowser"
711
+ | "VivaldiBrowser"
712
+ | "VivaldiExtension"
713
+ | "SafariExtension"
714
+ | "SDK"
715
+ | "Server"
716
+ | "WindowsCLI"
717
+ | "MacOsCLI"
718
+ | "LinuxCLI";
719
+
720
+ /**
721
+ * Basic client behavior settings. These settings specify the various targets and behavior of the
722
+ * Bitwarden Client. They are optional and uneditable once the client is initialized.
723
+ *
724
+ * Defaults to
725
+ *
726
+ * ```
727
+ * # use bitwarden_core::{ClientSettings, DeviceType};
728
+ * let settings = ClientSettings {
729
+ * identity_url: \"https://identity.bitwarden.com\".to_string(),
730
+ * api_url: \"https://api.bitwarden.com\".to_string(),
731
+ * user_agent: \"Bitwarden Rust-SDK\".to_string(),
732
+ * device_type: DeviceType::SDK,
733
+ * };
734
+ * let default = ClientSettings::default();
735
+ * ```
736
+ */
737
+ export interface ClientSettings {
738
+ /**
739
+ * The identity url of the targeted Bitwarden instance. Defaults to `https://identity.bitwarden.com`
740
+ */
741
+ identityUrl?: string;
742
+ /**
743
+ * The api url of the targeted Bitwarden instance. Defaults to `https://api.bitwarden.com`
744
+ */
745
+ apiUrl?: string;
746
+ /**
747
+ * The user_agent to sent to Bitwarden. Defaults to `Bitwarden Rust-SDK`
748
+ */
749
+ userAgent?: string;
750
+ /**
751
+ * Device type to send to Bitwarden. Defaults to SDK
752
+ */
753
+ deviceType?: DeviceType;
754
+ }
755
+
756
+ export type UnsignedSharedKey = Tagged<string, "UnsignedSharedKey">;
757
+
758
+ export type EncString = Tagged<string, "EncString">;
759
+
760
+ export type SignedPublicKey = Tagged<string, "SignedPublicKey">;
761
+
762
+ /**
763
+ * The type of key / signature scheme used for signing and verifying.
764
+ */
765
+ export type SignatureAlgorithm = "ed25519";
766
+
767
+ /**
768
+ * Key Derivation Function for Bitwarden Account
769
+ *
770
+ * In Bitwarden accounts can use multiple KDFs to derive their master key from their password. This
771
+ * Enum represents all the possible KDFs.
772
+ */
773
+ export type Kdf =
774
+ | { pBKDF2: { iterations: NonZeroU32 } }
775
+ | { argon2id: { iterations: NonZeroU32; memory: NonZeroU32; parallelism: NonZeroU32 } };
776
+
777
+ export interface CryptoError extends Error {
778
+ name: "CryptoError";
779
+ variant:
780
+ | "InvalidKey"
781
+ | "InvalidMac"
782
+ | "MacNotProvided"
783
+ | "KeyDecrypt"
784
+ | "InvalidKeyLen"
785
+ | "InvalidUtf8String"
786
+ | "MissingKey"
787
+ | "MissingField"
788
+ | "MissingKeyId"
789
+ | "ReadOnlyKeyStore"
790
+ | "InsufficientKdfParameters"
791
+ | "EncString"
792
+ | "Rsa"
793
+ | "Fingerprint"
794
+ | "Argon"
795
+ | "ZeroNumber"
796
+ | "OperationNotSupported"
797
+ | "WrongKeyType"
798
+ | "WrongCoseKeyId"
799
+ | "InvalidNonceLength"
800
+ | "InvalidPadding"
801
+ | "Signature"
802
+ | "Encoding";
803
+ }
804
+
805
+ export function isCryptoError(error: any): error is CryptoError;
806
+
807
+ /**
808
+ * Base64 encoded data
809
+ *
810
+ * Is indifferent about padding when decoding, but always produces padding when encoding.
811
+ */
812
+ export type B64 = string;
813
+
814
+ /**
815
+ * Temporary struct to hold metadata related to current account
816
+ *
817
+ * Eventually the SDK itself should have this state and we get rid of this struct.
818
+ */
819
+ export interface Account {
820
+ id: Uuid;
821
+ email: string;
822
+ name: string | undefined;
823
+ }
824
+
825
+ export type ExportFormat = "Csv" | "Json" | { EncryptedJson: { password: string } };
826
+
827
+ export interface ExportError extends Error {
828
+ name: "ExportError";
829
+ variant:
830
+ | "MissingField"
831
+ | "NotAuthenticated"
832
+ | "Csv"
833
+ | "Cxf"
834
+ | "Json"
835
+ | "EncryptedJson"
836
+ | "BitwardenCrypto"
837
+ | "Cipher";
838
+ }
839
+
840
+ export function isExportError(error: any): error is ExportError;
841
+
842
+ export type UsernameGeneratorRequest =
843
+ | { word: { capitalize: boolean; include_number: boolean } }
844
+ | { subaddress: { type: AppendType; email: string } }
845
+ | { catchall: { type: AppendType; domain: string } }
846
+ | { forwarded: { service: ForwarderServiceType; website: string | undefined } };
847
+
848
+ /**
849
+ * Configures the email forwarding service to use.
850
+ * For instructions on how to configure each service, see the documentation:
851
+ * <https://bitwarden.com/help/generator/#username-types>
852
+ */
853
+ export type ForwarderServiceType =
854
+ | { addyIo: { api_token: string; domain: string; base_url: string } }
855
+ | { duckDuckGo: { token: string } }
856
+ | { firefox: { api_token: string } }
857
+ | { fastmail: { api_token: string } }
858
+ | { forwardEmail: { api_token: string; domain: string } }
859
+ | { simpleLogin: { api_key: string; base_url: string } };
860
+
861
+ export type AppendType = "random" | { websiteName: { website: string } };
862
+
863
+ export interface UsernameError extends Error {
864
+ name: "UsernameError";
865
+ variant: "InvalidApiKey" | "Unknown" | "ResponseContent" | "Reqwest";
866
+ }
867
+
868
+ export function isUsernameError(error: any): error is UsernameError;
869
+
870
+ /**
871
+ * Password generator request options.
872
+ */
873
+ export interface PasswordGeneratorRequest {
874
+ /**
875
+ * Include lowercase characters (a-z).
876
+ */
877
+ lowercase: boolean;
878
+ /**
879
+ * Include uppercase characters (A-Z).
880
+ */
881
+ uppercase: boolean;
882
+ /**
883
+ * Include numbers (0-9).
884
+ */
885
+ numbers: boolean;
886
+ /**
887
+ * Include special characters: ! @ # $ % ^ & *
888
+ */
889
+ special: boolean;
890
+ /**
891
+ * The length of the generated password.
892
+ * Note that the password length must be greater than the sum of all the minimums.
893
+ */
894
+ length: number;
895
+ /**
896
+ * When set to true, the generated password will not contain ambiguous characters.
897
+ * The ambiguous characters are: I, O, l, 0, 1
898
+ */
899
+ avoidAmbiguous: boolean;
900
+ /**
901
+ * The minimum number of lowercase characters in the generated password.
902
+ * When set, the value must be between 1 and 9. This value is ignored if lowercase is false.
903
+ */
904
+ minLowercase: number | undefined;
905
+ /**
906
+ * The minimum number of uppercase characters in the generated password.
907
+ * When set, the value must be between 1 and 9. This value is ignored if uppercase is false.
908
+ */
909
+ minUppercase: number | undefined;
910
+ /**
911
+ * The minimum number of numbers in the generated password.
912
+ * When set, the value must be between 1 and 9. This value is ignored if numbers is false.
913
+ */
914
+ minNumber: number | undefined;
915
+ /**
916
+ * The minimum number of special characters in the generated password.
917
+ * When set, the value must be between 1 and 9. This value is ignored if special is false.
918
+ */
919
+ minSpecial: number | undefined;
920
+ }
921
+
922
+ export interface PasswordError extends Error {
923
+ name: "PasswordError";
924
+ variant: "NoCharacterSetEnabled" | "InvalidLength";
925
+ }
926
+
927
+ export function isPasswordError(error: any): error is PasswordError;
928
+
929
+ /**
930
+ * Passphrase generator request options.
931
+ */
932
+ export interface PassphraseGeneratorRequest {
933
+ /**
934
+ * Number of words in the generated passphrase.
935
+ * This value must be between 3 and 20.
936
+ */
937
+ numWords: number;
938
+ /**
939
+ * Character separator between words in the generated passphrase. The value cannot be empty.
940
+ */
941
+ wordSeparator: string;
942
+ /**
943
+ * When set to true, capitalize the first letter of each word in the generated passphrase.
944
+ */
945
+ capitalize: boolean;
946
+ /**
947
+ * When set to true, include a number at the end of one of the words in the generated
948
+ * passphrase.
949
+ */
950
+ includeNumber: boolean;
951
+ }
952
+
953
+ export type PassphraseError = { InvalidNumWords: { minimum: number; maximum: number } };
954
+
955
+ export interface DiscoverResponse {
956
+ version: string;
957
+ }
958
+
959
+ export type Endpoint =
960
+ | { Web: { id: number } }
961
+ | "BrowserForeground"
962
+ | "BrowserBackground"
963
+ | "DesktopRenderer"
964
+ | "DesktopMain";
965
+
966
+ export interface IpcCommunicationBackendSender {
967
+ send(message: OutgoingMessage): Promise<void>;
968
+ }
969
+
970
+ export interface ChannelError extends Error {
971
+ name: "ChannelError";
972
+ }
973
+
974
+ export function isChannelError(error: any): error is ChannelError;
975
+
976
+ export interface DeserializeError extends Error {
977
+ name: "DeserializeError";
978
+ }
979
+
980
+ export function isDeserializeError(error: any): error is DeserializeError;
981
+
982
+ export interface RequestError extends Error {
983
+ name: "RequestError";
984
+ variant: "Subscribe" | "Receive" | "Timeout" | "Send" | "Rpc";
985
+ }
986
+
987
+ export function isRequestError(error: any): error is RequestError;
988
+
989
+ export interface TypedReceiveError extends Error {
990
+ name: "TypedReceiveError";
991
+ variant: "Channel" | "Timeout" | "Cancelled" | "Typing";
992
+ }
993
+
994
+ export function isTypedReceiveError(error: any): error is TypedReceiveError;
995
+
996
+ export interface ReceiveError extends Error {
997
+ name: "ReceiveError";
998
+ variant: "Channel" | "Timeout" | "Cancelled";
999
+ }
1000
+
1001
+ export function isReceiveError(error: any): error is ReceiveError;
1002
+
1003
+ export interface SubscribeError extends Error {
1004
+ name: "SubscribeError";
1005
+ variant: "NotStarted";
1006
+ }
1007
+
1008
+ export function isSubscribeError(error: any): error is SubscribeError;
1009
+
1010
+ export type KeyAlgorithm = "Ed25519" | "Rsa3072" | "Rsa4096";
1011
+
1012
+ export interface SshKeyExportError extends Error {
1013
+ name: "SshKeyExportError";
1014
+ variant: "KeyConversion";
1015
+ }
1016
+
1017
+ export function isSshKeyExportError(error: any): error is SshKeyExportError;
1018
+
1019
+ export interface SshKeyImportError extends Error {
1020
+ name: "SshKeyImportError";
1021
+ variant: "Parsing" | "PasswordRequired" | "WrongPassword" | "UnsupportedKeyType";
1022
+ }
1023
+
1024
+ export function isSshKeyImportError(error: any): error is SshKeyImportError;
1025
+
1026
+ export interface KeyGenerationError extends Error {
1027
+ name: "KeyGenerationError";
1028
+ variant: "KeyGeneration" | "KeyConversion";
1029
+ }
1030
+
1031
+ export function isKeyGenerationError(error: any): error is KeyGenerationError;
1032
+
1033
+ export interface DatabaseError extends Error {
1034
+ name: "DatabaseError";
1035
+ variant: "UnsupportedConfiguration" | "ThreadBoundRunner" | "Serialization" | "JS" | "Internal";
1036
+ }
1037
+
1038
+ export function isDatabaseError(error: any): error is DatabaseError;
1039
+
1040
+ export interface StateRegistryError extends Error {
1041
+ name: "StateRegistryError";
1042
+ variant: "DatabaseAlreadyInitialized" | "DatabaseNotInitialized" | "Database";
1043
+ }
1044
+
1045
+ export function isStateRegistryError(error: any): error is StateRegistryError;
1046
+
1047
+ export interface CallError extends Error {
1048
+ name: "CallError";
1049
+ }
1050
+
1051
+ export function isCallError(error: any): error is CallError;
1052
+
1053
+ /**
1054
+ * NewType wrapper for `CipherId`
1055
+ */
1056
+ export type CipherId = Tagged<Uuid, "CipherId">;
1057
+
1058
+ export interface EncryptionContext {
1059
+ /**
1060
+ * The Id of the user that encrypted the cipher. It should always represent a UserId, even for
1061
+ * Organization-owned ciphers
1062
+ */
1063
+ encryptedFor: UserId;
1064
+ cipher: Cipher;
1065
+ }
1066
+
1067
+ export interface Cipher {
1068
+ id: CipherId | undefined;
1069
+ organizationId: OrganizationId | undefined;
1070
+ folderId: FolderId | undefined;
1071
+ collectionIds: CollectionId[];
1072
+ /**
1073
+ * More recent ciphers uses individual encryption keys to encrypt the other fields of the
1074
+ * Cipher.
1075
+ */
1076
+ key: EncString | undefined;
1077
+ name: EncString;
1078
+ notes: EncString | undefined;
1079
+ type: CipherType;
1080
+ login: Login | undefined;
1081
+ identity: Identity | undefined;
1082
+ card: Card | undefined;
1083
+ secureNote: SecureNote | undefined;
1084
+ sshKey: SshKey | undefined;
1085
+ favorite: boolean;
1086
+ reprompt: CipherRepromptType;
1087
+ organizationUseTotp: boolean;
1088
+ edit: boolean;
1089
+ permissions: CipherPermissions | undefined;
1090
+ viewPassword: boolean;
1091
+ localData: LocalData | undefined;
1092
+ attachments: Attachment[] | undefined;
1093
+ fields: Field[] | undefined;
1094
+ passwordHistory: PasswordHistory[] | undefined;
1095
+ creationDate: DateTime<Utc>;
1096
+ deletedDate: DateTime<Utc> | undefined;
1097
+ revisionDate: DateTime<Utc>;
1098
+ archivedDate: DateTime<Utc> | undefined;
1099
+ }
1100
+
1101
+ export interface CipherView {
1102
+ id: CipherId | undefined;
1103
+ organizationId: OrganizationId | undefined;
1104
+ folderId: FolderId | undefined;
1105
+ collectionIds: CollectionId[];
1106
+ /**
1107
+ * Temporary, required to support re-encrypting existing items.
1108
+ */
1109
+ key: EncString | undefined;
1110
+ name: string;
1111
+ notes: string | undefined;
1112
+ type: CipherType;
1113
+ login: LoginView | undefined;
1114
+ identity: IdentityView | undefined;
1115
+ card: CardView | undefined;
1116
+ secureNote: SecureNoteView | undefined;
1117
+ sshKey: SshKeyView | undefined;
1118
+ favorite: boolean;
1119
+ reprompt: CipherRepromptType;
1120
+ organizationUseTotp: boolean;
1121
+ edit: boolean;
1122
+ permissions: CipherPermissions | undefined;
1123
+ viewPassword: boolean;
1124
+ localData: LocalDataView | undefined;
1125
+ attachments: AttachmentView[] | undefined;
1126
+ fields: FieldView[] | undefined;
1127
+ passwordHistory: PasswordHistoryView[] | undefined;
1128
+ creationDate: DateTime<Utc>;
1129
+ deletedDate: DateTime<Utc> | undefined;
1130
+ revisionDate: DateTime<Utc>;
1131
+ archivedDate: DateTime<Utc> | undefined;
1132
+ }
1133
+
1134
+ export type CipherListViewType =
1135
+ | { login: LoginListView }
1136
+ | "secureNote"
1137
+ | { card: CardListView }
1138
+ | "identity"
1139
+ | "sshKey";
1140
+
1141
+ /**
1142
+ * Available fields on a cipher and can be copied from a the list view in the UI.
1143
+ */
1144
+ export type CopyableCipherFields =
1145
+ | "LoginUsername"
1146
+ | "LoginPassword"
1147
+ | "LoginTotp"
1148
+ | "CardNumber"
1149
+ | "CardSecurityCode"
1150
+ | "IdentityUsername"
1151
+ | "IdentityEmail"
1152
+ | "IdentityPhone"
1153
+ | "IdentityAddress"
1154
+ | "SshKey"
1155
+ | "SecureNotes";
1156
+
1157
+ export interface CipherListView {
1158
+ id: CipherId | undefined;
1159
+ organizationId: OrganizationId | undefined;
1160
+ folderId: FolderId | undefined;
1161
+ collectionIds: CollectionId[];
1162
+ /**
1163
+ * Temporary, required to support calculating TOTP from CipherListView.
1164
+ */
1165
+ key: EncString | undefined;
1166
+ name: string;
1167
+ subtitle: string;
1168
+ type: CipherListViewType;
1169
+ favorite: boolean;
1170
+ reprompt: CipherRepromptType;
1171
+ organizationUseTotp: boolean;
1172
+ edit: boolean;
1173
+ permissions: CipherPermissions | undefined;
1174
+ viewPassword: boolean;
1175
+ /**
1176
+ * The number of attachments
1177
+ */
1178
+ attachments: number;
1179
+ /**
1180
+ * Indicates if the cipher has old attachments that need to be re-uploaded
1181
+ */
1182
+ hasOldAttachments: boolean;
1183
+ creationDate: DateTime<Utc>;
1184
+ deletedDate: DateTime<Utc> | undefined;
1185
+ revisionDate: DateTime<Utc>;
1186
+ archivedDate: DateTime<Utc> | undefined;
1187
+ /**
1188
+ * Hints for the presentation layer for which fields can be copied.
1189
+ */
1190
+ copyableFields: CopyableCipherFields[];
1191
+ localData: LocalDataView | undefined;
1192
+ }
1193
+
1194
+ /**
1195
+ * Represents the result of decrypting a list of ciphers.
1196
+ *
1197
+ * This struct contains two vectors: `successes` and `failures`.
1198
+ * `successes` contains the decrypted `CipherListView` objects,
1199
+ * while `failures` contains the original `Cipher` objects that failed to decrypt.
1200
+ */
1201
+ export interface DecryptCipherListResult {
1202
+ /**
1203
+ * The decrypted `CipherListView` objects.
1204
+ */
1205
+ successes: CipherListView[];
1206
+ /**
1207
+ * The original `Cipher` objects that failed to decrypt.
1208
+ */
1209
+ failures: Cipher[];
1210
+ }
1211
+
1212
+ export interface Field {
1213
+ name: EncString | undefined;
1214
+ value: EncString | undefined;
1215
+ type: FieldType;
1216
+ linkedId: LinkedIdType | undefined;
1217
+ }
1218
+
1219
+ export interface FieldView {
1220
+ name: string | undefined;
1221
+ value: string | undefined;
1222
+ type: FieldType;
1223
+ linkedId: LinkedIdType | undefined;
1224
+ }
1225
+
1226
+ export type LinkedIdType = LoginLinkedIdType | CardLinkedIdType | IdentityLinkedIdType;
1227
+
1228
+ export interface LoginUri {
1229
+ uri: EncString | undefined;
1230
+ match: UriMatchType | undefined;
1231
+ uriChecksum: EncString | undefined;
1232
+ }
1233
+
1234
+ export interface LoginUriView {
1235
+ uri: string | undefined;
1236
+ match: UriMatchType | undefined;
1237
+ uriChecksum: string | undefined;
1238
+ }
1239
+
1240
+ export interface Fido2Credential {
1241
+ credentialId: EncString;
1242
+ keyType: EncString;
1243
+ keyAlgorithm: EncString;
1244
+ keyCurve: EncString;
1245
+ keyValue: EncString;
1246
+ rpId: EncString;
1247
+ userHandle: EncString | undefined;
1248
+ userName: EncString | undefined;
1249
+ counter: EncString;
1250
+ rpName: EncString | undefined;
1251
+ userDisplayName: EncString | undefined;
1252
+ discoverable: EncString;
1253
+ creationDate: DateTime<Utc>;
1254
+ }
1255
+
1256
+ export interface Fido2CredentialListView {
1257
+ credentialId: string;
1258
+ rpId: string;
1259
+ userHandle: string | undefined;
1260
+ userName: string | undefined;
1261
+ userDisplayName: string | undefined;
1262
+ counter: string;
1263
+ }
1264
+
1265
+ export interface Fido2CredentialView {
1266
+ credentialId: string;
1267
+ keyType: string;
1268
+ keyAlgorithm: string;
1269
+ keyCurve: string;
1270
+ keyValue: EncString;
1271
+ rpId: string;
1272
+ userHandle: string | undefined;
1273
+ userName: string | undefined;
1274
+ counter: string;
1275
+ rpName: string | undefined;
1276
+ userDisplayName: string | undefined;
1277
+ discoverable: string;
1278
+ creationDate: DateTime<Utc>;
1279
+ }
1280
+
1281
+ export interface Fido2CredentialFullView {
1282
+ credentialId: string;
1283
+ keyType: string;
1284
+ keyAlgorithm: string;
1285
+ keyCurve: string;
1286
+ keyValue: string;
1287
+ rpId: string;
1288
+ userHandle: string | undefined;
1289
+ userName: string | undefined;
1290
+ counter: string;
1291
+ rpName: string | undefined;
1292
+ userDisplayName: string | undefined;
1293
+ discoverable: string;
1294
+ creationDate: DateTime<Utc>;
1295
+ }
1296
+
1297
+ export interface Fido2CredentialNewView {
1298
+ credentialId: string;
1299
+ keyType: string;
1300
+ keyAlgorithm: string;
1301
+ keyCurve: string;
1302
+ rpId: string;
1303
+ userHandle: string | undefined;
1304
+ userName: string | undefined;
1305
+ counter: string;
1306
+ rpName: string | undefined;
1307
+ userDisplayName: string | undefined;
1308
+ creationDate: DateTime<Utc>;
1309
+ }
1310
+
1311
+ export interface Login {
1312
+ username: EncString | undefined;
1313
+ password: EncString | undefined;
1314
+ passwordRevisionDate: DateTime<Utc> | undefined;
1315
+ uris: LoginUri[] | undefined;
1316
+ totp: EncString | undefined;
1317
+ autofillOnPageLoad: boolean | undefined;
1318
+ fido2Credentials: Fido2Credential[] | undefined;
1319
+ }
1320
+
1321
+ export interface LoginView {
1322
+ username: string | undefined;
1323
+ password: string | undefined;
1324
+ passwordRevisionDate: DateTime<Utc> | undefined;
1325
+ uris: LoginUriView[] | undefined;
1326
+ totp: string | undefined;
1327
+ autofillOnPageLoad: boolean | undefined;
1328
+ fido2Credentials: Fido2Credential[] | undefined;
1329
+ }
1330
+
1331
+ export interface LoginListView {
1332
+ fido2Credentials: Fido2CredentialListView[] | undefined;
1333
+ hasFido2: boolean;
1334
+ username: string | undefined;
1335
+ /**
1336
+ * The TOTP key is not decrypted. Useable as is with [`crate::generate_totp_cipher_view`].
1337
+ */
1338
+ totp: EncString | undefined;
1339
+ uris: LoginUriView[] | undefined;
1340
+ }
1341
+
1342
+ export interface SecureNote {
1343
+ type: SecureNoteType;
1344
+ }
1345
+
1346
+ export interface SecureNoteView {
1347
+ type: SecureNoteType;
1348
+ }
1349
+
1350
+ /**
1351
+ * Request to add or edit a folder.
1352
+ */
1353
+ export interface FolderAddEditRequest {
1354
+ /**
1355
+ * The new name of the folder.
1356
+ */
1357
+ name: string;
1358
+ }
1359
+
1360
+ /**
1361
+ * NewType wrapper for `FolderId`
1362
+ */
1363
+ export type FolderId = Tagged<Uuid, "FolderId">;
1364
+
1365
+ export interface Folder {
1366
+ id: FolderId | undefined;
1367
+ name: EncString;
1368
+ revisionDate: DateTime<Utc>;
1369
+ }
1370
+
1371
+ export interface FolderView {
1372
+ id: FolderId | undefined;
1373
+ name: string;
1374
+ revisionDate: DateTime<Utc>;
1375
+ }
1376
+
1377
+ export interface AncestorMap {
1378
+ ancestors: Map<CollectionId, string>;
1379
+ }
1380
+
1381
+ export interface DecryptError extends Error {
1382
+ name: "DecryptError";
1383
+ variant: "Crypto";
1384
+ }
1385
+
1386
+ export function isDecryptError(error: any): error is DecryptError;
1387
+
1388
+ export interface EncryptError extends Error {
1389
+ name: "EncryptError";
1390
+ variant: "Crypto" | "MissingUserId";
1391
+ }
1392
+
1393
+ export function isEncryptError(error: any): error is EncryptError;
1394
+
1395
+ export interface TotpResponse {
1396
+ /**
1397
+ * Generated TOTP code
1398
+ */
1399
+ code: string;
1400
+ /**
1401
+ * Time period
1402
+ */
1403
+ period: number;
1404
+ }
1405
+
1406
+ export interface TotpError extends Error {
1407
+ name: "TotpError";
1408
+ variant: "InvalidOtpauth" | "MissingSecret" | "Crypto";
1409
+ }
1410
+
1411
+ export function isTotpError(error: any): error is TotpError;
1412
+
1413
+ export interface PasswordHistoryView {
1414
+ password: string;
1415
+ lastUsedDate: DateTime<Utc>;
1416
+ }
1417
+
1418
+ export interface PasswordHistory {
1419
+ password: EncString;
1420
+ lastUsedDate: DateTime<Utc>;
1421
+ }
1422
+
1423
+ export interface GetFolderError extends Error {
1424
+ name: "GetFolderError";
1425
+ variant: "ItemNotFound" | "Crypto" | "Repository";
1426
+ }
1427
+
1428
+ export function isGetFolderError(error: any): error is GetFolderError;
1429
+
1430
+ export interface EditFolderError extends Error {
1431
+ name: "EditFolderError";
1432
+ variant:
1433
+ | "ItemNotFound"
1434
+ | "Crypto"
1435
+ | "Api"
1436
+ | "VaultParse"
1437
+ | "MissingField"
1438
+ | "Repository"
1439
+ | "Uuid";
1440
+ }
1441
+
1442
+ export function isEditFolderError(error: any): error is EditFolderError;
1443
+
1444
+ export interface CreateFolderError extends Error {
1445
+ name: "CreateFolderError";
1446
+ variant: "Crypto" | "Api" | "VaultParse" | "MissingField" | "Repository";
1447
+ }
1448
+
1449
+ export function isCreateFolderError(error: any): error is CreateFolderError;
1450
+
1451
+ export interface SshKeyView {
133
1452
  /**
134
- * The identity url of the targeted Bitwarden instance. Defaults to `https://identity.bitwarden.com`
1453
+ * SSH private key (ed25519/rsa) in unencrypted openssh private key format [OpenSSH private key](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key)
135
1454
  */
136
- identityUrl?: string;
1455
+ privateKey: string;
137
1456
  /**
138
- * The api url of the targeted Bitwarden instance. Defaults to `https://api.bitwarden.com`
1457
+ * SSH public key (ed25519/rsa) according to [RFC4253](https://datatracker.ietf.org/doc/html/rfc4253#section-6.6)
139
1458
  */
140
- apiUrl?: string;
1459
+ publicKey: string;
141
1460
  /**
142
- * The user_agent to sent to Bitwarden. Defaults to `Bitwarden Rust-SDK`
1461
+ * SSH fingerprint using SHA256 in the format: `SHA256:BASE64_ENCODED_FINGERPRINT`
143
1462
  */
144
- userAgent?: string;
1463
+ fingerprint: string;
1464
+ }
1465
+
1466
+ export interface SshKey {
145
1467
  /**
146
- * Device type to send to Bitwarden. Defaults to SDK
1468
+ * SSH private key (ed25519/rsa) in unencrypted openssh private key format [OpenSSH private key](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key)
147
1469
  */
148
- deviceType?: DeviceType;
1470
+ privateKey: EncString;
1471
+ /**
1472
+ * SSH public key (ed25519/rsa) according to [RFC4253](https://datatracker.ietf.org/doc/html/rfc4253#section-6.6)
1473
+ */
1474
+ publicKey: EncString;
1475
+ /**
1476
+ * SSH fingerprint using SHA256 in the format: `SHA256:BASE64_ENCODED_FINGERPRINT`
1477
+ */
1478
+ fingerprint: EncString;
149
1479
  }
150
1480
 
151
- export type AsymmetricEncString = string;
1481
+ export interface LocalDataView {
1482
+ lastUsedDate: DateTime<Utc> | undefined;
1483
+ lastLaunched: DateTime<Utc> | undefined;
1484
+ }
152
1485
 
153
- export type EncString = string;
1486
+ export interface LocalData {
1487
+ lastUsedDate: DateTime<Utc> | undefined;
1488
+ lastLaunched: DateTime<Utc> | undefined;
1489
+ }
154
1490
 
155
- /**
156
- * Key Derivation Function for Bitwarden Account
157
- *
158
- * In Bitwarden accounts can use multiple KDFs to derive their master key from their password. This
159
- * Enum represents all the possible KDFs.
160
- */
161
- export type Kdf =
162
- | { pBKDF2: { iterations: NonZeroU32 } }
163
- | { argon2id: { iterations: NonZeroU32; memory: NonZeroU32; parallelism: NonZeroU32 } };
1491
+ export interface IdentityView {
1492
+ title: string | undefined;
1493
+ firstName: string | undefined;
1494
+ middleName: string | undefined;
1495
+ lastName: string | undefined;
1496
+ address1: string | undefined;
1497
+ address2: string | undefined;
1498
+ address3: string | undefined;
1499
+ city: string | undefined;
1500
+ state: string | undefined;
1501
+ postalCode: string | undefined;
1502
+ country: string | undefined;
1503
+ company: string | undefined;
1504
+ email: string | undefined;
1505
+ phone: string | undefined;
1506
+ ssn: string | undefined;
1507
+ username: string | undefined;
1508
+ passportNumber: string | undefined;
1509
+ licenseNumber: string | undefined;
1510
+ }
164
1511
 
165
- export interface GenerateSshKeyResult {
166
- private_key: string;
167
- public_key: string;
168
- key_fingerprint: string;
1512
+ export interface Identity {
1513
+ title: EncString | undefined;
1514
+ firstName: EncString | undefined;
1515
+ middleName: EncString | undefined;
1516
+ lastName: EncString | undefined;
1517
+ address1: EncString | undefined;
1518
+ address2: EncString | undefined;
1519
+ address3: EncString | undefined;
1520
+ city: EncString | undefined;
1521
+ state: EncString | undefined;
1522
+ postalCode: EncString | undefined;
1523
+ country: EncString | undefined;
1524
+ company: EncString | undefined;
1525
+ email: EncString | undefined;
1526
+ phone: EncString | undefined;
1527
+ ssn: EncString | undefined;
1528
+ username: EncString | undefined;
1529
+ passportNumber: EncString | undefined;
1530
+ licenseNumber: EncString | undefined;
169
1531
  }
170
1532
 
171
- export type KeyAlgorithm = "Ed25519" | "Rsa3072" | "Rsa4096";
1533
+ export interface CipherPermissions {
1534
+ delete: boolean;
1535
+ restore: boolean;
1536
+ }
172
1537
 
173
- export interface KeyGenerationError extends Error {
174
- name: "KeyGenerationError";
175
- variant: "KeyGenerationError" | "KeyConversionError";
1538
+ export interface CipherError extends Error {
1539
+ name: "CipherError";
1540
+ variant: "MissingField" | "Crypto" | "Encrypt" | "AttachmentsWithoutKeys";
176
1541
  }
177
1542
 
178
- export function isKeyGenerationError(error: any): error is KeyGenerationError;
1543
+ export function isCipherError(error: any): error is CipherError;
179
1544
 
180
- export interface Folder {
181
- id: Uuid | undefined;
182
- name: EncString;
183
- revisionDate: DateTime<Utc>;
1545
+ /**
1546
+ * Minimal CardView only including the needed details for list views
1547
+ */
1548
+ export interface CardListView {
1549
+ /**
1550
+ * The brand of the card, e.g. Visa, Mastercard, etc.
1551
+ */
1552
+ brand: string | undefined;
184
1553
  }
185
1554
 
186
- export interface FolderView {
187
- id: Uuid | undefined;
188
- name: string;
189
- revisionDate: DateTime<Utc>;
1555
+ export interface CardView {
1556
+ cardholderName: string | undefined;
1557
+ expMonth: string | undefined;
1558
+ expYear: string | undefined;
1559
+ code: string | undefined;
1560
+ brand: string | undefined;
1561
+ number: string | undefined;
190
1562
  }
191
1563
 
192
- export interface TestError extends Error {
193
- name: "TestError";
1564
+ export interface Card {
1565
+ cardholderName: EncString | undefined;
1566
+ expMonth: EncString | undefined;
1567
+ expYear: EncString | undefined;
1568
+ code: EncString | undefined;
1569
+ brand: EncString | undefined;
1570
+ number: EncString | undefined;
194
1571
  }
195
1572
 
196
- export function isTestError(error: any): error is TestError;
1573
+ export interface DecryptFileError extends Error {
1574
+ name: "DecryptFileError";
1575
+ variant: "Decrypt" | "Io";
1576
+ }
197
1577
 
198
- export type Uuid = string;
1578
+ export function isDecryptFileError(error: any): error is DecryptFileError;
199
1579
 
200
- /**
201
- * RFC3339 compliant date-time string.
202
- * @typeParam T - Not used in JavaScript.
203
- */
204
- export type DateTime<T = unknown> = string;
1580
+ export interface EncryptFileError extends Error {
1581
+ name: "EncryptFileError";
1582
+ variant: "Encrypt" | "Io";
1583
+ }
1584
+
1585
+ export function isEncryptFileError(error: any): error is EncryptFileError;
1586
+
1587
+ export interface AttachmentView {
1588
+ id: string | undefined;
1589
+ url: string | undefined;
1590
+ size: string | undefined;
1591
+ sizeName: string | undefined;
1592
+ fileName: string | undefined;
1593
+ key: EncString | undefined;
1594
+ /**
1595
+ * The decrypted attachmentkey in base64 format.
1596
+ *
1597
+ * **TEMPORARY FIELD**: This field is a temporary workaround to provide
1598
+ * decrypted attachment keys to the TypeScript client during the migration
1599
+ * process. It will be removed once the encryption/decryption logic is
1600
+ * fully migrated to the SDK.
1601
+ *
1602
+ * **Ticket**: <https://bitwarden.atlassian.net/browse/PM-23005>
1603
+ *
1604
+ * Do not rely on this field for long-term use.
1605
+ */
1606
+ decryptedKey: string | undefined;
1607
+ }
1608
+
1609
+ export interface Attachment {
1610
+ id: string | undefined;
1611
+ url: string | undefined;
1612
+ size: string | undefined;
1613
+ /**
1614
+ * Readable size, ex: \"4.2 KB\" or \"1.43 GB\
1615
+ */
1616
+ sizeName: string | undefined;
1617
+ fileName: EncString | undefined;
1618
+ key: EncString | undefined;
1619
+ }
205
1620
 
1621
+ export class AttachmentsClient {
1622
+ private constructor();
1623
+ free(): void;
1624
+ decrypt_buffer(
1625
+ cipher: Cipher,
1626
+ attachment: AttachmentView,
1627
+ encrypted_buffer: Uint8Array,
1628
+ ): Uint8Array;
1629
+ }
206
1630
  /**
207
- * UTC date-time string. Not used in JavaScript.
1631
+ * Subclient containing auth functionality.
208
1632
  */
209
- export type Utc = unknown;
210
-
1633
+ export class AuthClient {
1634
+ private constructor();
1635
+ free(): void;
1636
+ /**
1637
+ * Client for send access functionality
1638
+ */
1639
+ send_access(): SendAccessClient;
1640
+ }
211
1641
  /**
212
- * An integer that is known not to equal zero.
1642
+ * The main entry point for the Bitwarden SDK in WebAssembly environments
213
1643
  */
214
- export type NonZeroU32 = number;
215
-
216
1644
  export class BitwardenClient {
217
1645
  free(): void;
218
- constructor(settings?: ClientSettings, log_level?: LogLevel);
1646
+ /**
1647
+ * Initialize a new instance of the SDK client
1648
+ */
1649
+ constructor(token_provider: any, settings?: ClientSettings | null);
219
1650
  /**
220
1651
  * Test method, echoes back the input
221
1652
  */
222
1653
  echo(msg: string): string;
1654
+ /**
1655
+ * Returns the current SDK version
1656
+ */
223
1657
  version(): string;
224
- throw(msg: string): Promise<void>;
1658
+ /**
1659
+ * Test method, always throws an error
1660
+ */
1661
+ throw(msg: string): void;
225
1662
  /**
226
1663
  * Test method, calls http endpoint
227
1664
  */
228
1665
  http_get(url: string): Promise<string>;
229
- crypto(): ClientCrypto;
230
- vault(): ClientVault;
1666
+ /**
1667
+ * Auth related operations.
1668
+ */
1669
+ auth(): AuthClient;
1670
+ /**
1671
+ * Crypto related operations.
1672
+ */
1673
+ crypto(): CryptoClient;
1674
+ /**
1675
+ * Vault item related operations.
1676
+ */
1677
+ vault(): VaultClient;
1678
+ /**
1679
+ * Constructs a specific client for platform-specific functionality
1680
+ */
1681
+ platform(): PlatformClient;
1682
+ /**
1683
+ * Constructs a specific client for generating passwords and passphrases
1684
+ */
1685
+ generator(): GeneratorClient;
1686
+ /**
1687
+ * Exporter related operations.
1688
+ */
1689
+ exporters(): ExporterClient;
1690
+ }
1691
+ export class CiphersClient {
1692
+ private constructor();
1693
+ free(): void;
1694
+ encrypt(cipher_view: CipherView): EncryptionContext;
1695
+ /**
1696
+ * Encrypt a cipher with the provided key. This should only be used when rotating encryption
1697
+ * keys in the Web client.
1698
+ *
1699
+ * Until key rotation is fully implemented in the SDK, this method must be provided the new
1700
+ * symmetric key in base64 format. See PM-23084
1701
+ *
1702
+ * If the cipher has a CipherKey, it will be re-encrypted with the new key.
1703
+ * If the cipher does not have a CipherKey and CipherKeyEncryption is enabled, one will be
1704
+ * generated using the new key. Otherwise, the cipher's data will be encrypted with the new
1705
+ * key directly.
1706
+ */
1707
+ encrypt_cipher_for_rotation(cipher_view: CipherView, new_key: B64): EncryptionContext;
1708
+ decrypt(cipher: Cipher): CipherView;
1709
+ decrypt_list(ciphers: Cipher[]): CipherListView[];
1710
+ /**
1711
+ * Decrypt cipher list with failures
1712
+ * Returns both successfully decrypted ciphers and any that failed to decrypt
1713
+ */
1714
+ decrypt_list_with_failures(ciphers: Cipher[]): DecryptCipherListResult;
1715
+ decrypt_fido2_credentials(cipher_view: CipherView): Fido2CredentialView[];
1716
+ /**
1717
+ * Temporary method used to re-encrypt FIDO2 credentials for a cipher view.
1718
+ * Necessary until the TS clients utilize the SDK entirely for FIDO2 credentials management.
1719
+ * TS clients create decrypted FIDO2 credentials that need to be encrypted manually when
1720
+ * encrypting the rest of the CipherView.
1721
+ * TODO: Remove once TS passkey provider implementation uses SDK - PM-8313
1722
+ */
1723
+ set_fido2_credentials(
1724
+ cipher_view: CipherView,
1725
+ fido2_credentials: Fido2CredentialFullView[],
1726
+ ): CipherView;
1727
+ move_to_organization(cipher_view: CipherView, organization_id: OrganizationId): CipherView;
1728
+ decrypt_fido2_private_key(cipher_view: CipherView): string;
1729
+ }
1730
+ export class CollectionViewNodeItem {
1731
+ private constructor();
1732
+ free(): void;
1733
+ get_item(): CollectionView;
1734
+ get_parent(): CollectionView | undefined;
1735
+ get_children(): CollectionView[];
1736
+ get_ancestors(): AncestorMap;
1737
+ }
1738
+ export class CollectionViewTree {
1739
+ private constructor();
1740
+ free(): void;
1741
+ get_item_for_view(collection_view: CollectionView): CollectionViewNodeItem | undefined;
1742
+ get_root_items(): CollectionViewNodeItem[];
1743
+ get_flat_items(): CollectionViewNodeItem[];
1744
+ }
1745
+ export class CollectionsClient {
1746
+ private constructor();
1747
+ free(): void;
1748
+ decrypt(collection: Collection): CollectionView;
1749
+ decrypt_list(collections: Collection[]): CollectionView[];
1750
+ /**
1751
+ *
1752
+ * Returns the vector of CollectionView objects in a tree structure based on its implemented
1753
+ * path().
1754
+ */
1755
+ get_collection_tree(collections: CollectionView[]): CollectionViewTree;
231
1756
  }
232
- export class ClientCrypto {
1757
+ /**
1758
+ * A client for the crypto operations.
1759
+ */
1760
+ export class CryptoClient {
233
1761
  private constructor();
234
1762
  free(): void;
235
1763
  /**
@@ -242,17 +1770,421 @@ export class ClientCrypto {
242
1770
  * `initialize_user_crypto` but before any other crypto operations.
243
1771
  */
244
1772
  initialize_org_crypto(req: InitOrgCryptoRequest): Promise<void>;
1773
+ /**
1774
+ * Generates a new key pair and encrypts the private key with the provided user key.
1775
+ * Crypto initialization not required.
1776
+ */
1777
+ make_key_pair(user_key: B64): MakeKeyPairResponse;
1778
+ /**
1779
+ * Verifies a user's asymmetric keys by decrypting the private key with the provided user
1780
+ * key. Returns if the private key is decryptable and if it is a valid matching key.
1781
+ * Crypto initialization not required.
1782
+ */
1783
+ verify_asymmetric_keys(request: VerifyAsymmetricKeysRequest): VerifyAsymmetricKeysResponse;
1784
+ /**
1785
+ * Makes a new signing key pair and signs the public key for the user
1786
+ */
1787
+ make_keys_for_user_crypto_v2(): UserCryptoV2KeysResponse;
1788
+ /**
1789
+ * Creates a rotated set of account keys for the current state
1790
+ */
1791
+ get_v2_rotated_account_keys(): UserCryptoV2KeysResponse;
1792
+ /**
1793
+ * Create the data necessary to update the user's kdf settings. The user's encryption key is
1794
+ * re-encrypted for the password under the new kdf settings. This returns the re-encrypted
1795
+ * user key and the new password hash but does not update sdk state.
1796
+ */
1797
+ make_update_kdf(password: string, kdf: Kdf): UpdateKdfResponse;
1798
+ /**
1799
+ * Protects the current user key with the provided PIN. The result can be stored and later
1800
+ * used to initialize another client instance by using the PIN and the PIN key with
1801
+ * `initialize_user_crypto`.
1802
+ */
1803
+ enroll_pin(pin: string): EnrollPinResponse;
1804
+ /**
1805
+ * Protects the current user key with the provided PIN. The result can be stored and later
1806
+ * used to initialize another client instance by using the PIN and the PIN key with
1807
+ * `initialize_user_crypto`. The provided pin is encrypted with the user key.
1808
+ */
1809
+ enroll_pin_with_encrypted_pin(encrypted_pin: string): EnrollPinResponse;
1810
+ /**
1811
+ * Decrypts a `PasswordProtectedKeyEnvelope`, returning the user key, if successful.
1812
+ * This is a stop-gap solution, until initialization of the SDK is used.
1813
+ */
1814
+ unseal_password_protected_key_envelope(
1815
+ pin: string,
1816
+ envelope: PasswordProtectedKeyEnvelope,
1817
+ ): Uint8Array;
245
1818
  }
246
- export class ClientFolders {
1819
+ export class ExporterClient {
1820
+ private constructor();
1821
+ free(): void;
1822
+ export_vault(folders: Folder[], ciphers: Cipher[], format: ExportFormat): string;
1823
+ export_organization_vault(
1824
+ collections: Collection[],
1825
+ ciphers: Cipher[],
1826
+ format: ExportFormat,
1827
+ ): string;
1828
+ /**
1829
+ * Credential Exchange Format (CXF)
1830
+ *
1831
+ * *Warning:* Expect this API to be unstable, and it will change in the future.
1832
+ *
1833
+ * For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
1834
+ * Ideally, the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
1835
+ */
1836
+ export_cxf(account: Account, ciphers: Cipher[]): string;
1837
+ /**
1838
+ * Credential Exchange Format (CXF)
1839
+ *
1840
+ * *Warning:* Expect this API to be unstable, and it will change in the future.
1841
+ *
1842
+ * For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
1843
+ * Ideally, the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
1844
+ */
1845
+ import_cxf(payload: string): Cipher[];
1846
+ }
1847
+ /**
1848
+ * Wrapper for folder specific functionality.
1849
+ */
1850
+ export class FoldersClient {
247
1851
  private constructor();
248
1852
  free(): void;
249
1853
  /**
250
- * Decrypt folder
1854
+ * Encrypt a [FolderView] to a [Folder].
1855
+ */
1856
+ encrypt(folder_view: FolderView): Folder;
1857
+ /**
1858
+ * Encrypt a [Folder] to [FolderView].
251
1859
  */
252
1860
  decrypt(folder: Folder): FolderView;
1861
+ /**
1862
+ * Decrypt a list of [Folder]s to a list of [FolderView]s.
1863
+ */
1864
+ decrypt_list(folders: Folder[]): FolderView[];
1865
+ /**
1866
+ * Get all folders from state and decrypt them to a list of [FolderView].
1867
+ */
1868
+ list(): Promise<FolderView[]>;
1869
+ /**
1870
+ * Get a specific [Folder] by its ID from state and decrypt it to a [FolderView].
1871
+ */
1872
+ get(folder_id: FolderId): Promise<FolderView>;
1873
+ /**
1874
+ * Create a new [Folder] and save it to the server.
1875
+ */
1876
+ create(request: FolderAddEditRequest): Promise<FolderView>;
1877
+ /**
1878
+ * Edit the [Folder] and save it to the server.
1879
+ */
1880
+ edit(folder_id: FolderId, request: FolderAddEditRequest): Promise<FolderView>;
1881
+ }
1882
+ export class GeneratorClient {
1883
+ private constructor();
1884
+ free(): void;
1885
+ /**
1886
+ * Generates a random password.
1887
+ *
1888
+ * The character sets and password length can be customized using the `input` parameter.
1889
+ *
1890
+ * # Examples
1891
+ *
1892
+ * ```
1893
+ * use bitwarden_core::Client;
1894
+ * use bitwarden_generators::{GeneratorClientsExt, PassphraseError, PasswordGeneratorRequest};
1895
+ *
1896
+ * async fn test() -> Result<(), PassphraseError> {
1897
+ * let input = PasswordGeneratorRequest {
1898
+ * lowercase: true,
1899
+ * uppercase: true,
1900
+ * numbers: true,
1901
+ * length: 20,
1902
+ * ..Default::default()
1903
+ * };
1904
+ * let password = Client::new(None).generator().password(input).unwrap();
1905
+ * println!("{}", password);
1906
+ * Ok(())
1907
+ * }
1908
+ * ```
1909
+ */
1910
+ password(input: PasswordGeneratorRequest): string;
1911
+ /**
1912
+ * Generates a random passphrase.
1913
+ * A passphrase is a combination of random words separated by a character.
1914
+ * An example of passphrase is `correct horse battery staple`.
1915
+ *
1916
+ * The number of words and their case, the word separator, and the inclusion of
1917
+ * a number in the passphrase can be customized using the `input` parameter.
1918
+ *
1919
+ * # Examples
1920
+ *
1921
+ * ```
1922
+ * use bitwarden_core::Client;
1923
+ * use bitwarden_generators::{GeneratorClientsExt, PassphraseError, PassphraseGeneratorRequest};
1924
+ *
1925
+ * async fn test() -> Result<(), PassphraseError> {
1926
+ * let input = PassphraseGeneratorRequest {
1927
+ * num_words: 4,
1928
+ * ..Default::default()
1929
+ * };
1930
+ * let passphrase = Client::new(None).generator().passphrase(input).unwrap();
1931
+ * println!("{}", passphrase);
1932
+ * Ok(())
1933
+ * }
1934
+ * ```
1935
+ */
1936
+ passphrase(input: PassphraseGeneratorRequest): string;
1937
+ }
1938
+ export class IncomingMessage {
1939
+ free(): void;
1940
+ constructor(payload: Uint8Array, destination: Endpoint, source: Endpoint, topic?: string | null);
1941
+ /**
1942
+ * Try to parse the payload as JSON.
1943
+ * @returns The parsed JSON value, or undefined if the payload is not valid JSON.
1944
+ */
1945
+ parse_payload_as_json(): any;
1946
+ payload: Uint8Array;
1947
+ destination: Endpoint;
1948
+ source: Endpoint;
1949
+ get topic(): string | undefined;
1950
+ set topic(value: string | null | undefined);
1951
+ }
1952
+ /**
1953
+ * JavaScript wrapper around the IPC client. For more information, see the
1954
+ * [IpcClient] documentation.
1955
+ */
1956
+ export class IpcClient {
1957
+ free(): void;
1958
+ constructor(communication_provider: IpcCommunicationBackend);
1959
+ start(): Promise<void>;
1960
+ isRunning(): Promise<boolean>;
1961
+ send(message: OutgoingMessage): Promise<void>;
1962
+ subscribe(): Promise<IpcClientSubscription>;
1963
+ }
1964
+ /**
1965
+ * JavaScript wrapper around the IPC client subscription. For more information, see the
1966
+ * [IpcClientSubscription](crate::IpcClientSubscription) documentation.
1967
+ */
1968
+ export class IpcClientSubscription {
1969
+ private constructor();
1970
+ free(): void;
1971
+ receive(abort_signal?: AbortSignal | null): Promise<IncomingMessage>;
1972
+ }
1973
+ /**
1974
+ * JavaScript implementation of the `CommunicationBackend` trait for IPC communication.
1975
+ */
1976
+ export class IpcCommunicationBackend {
1977
+ free(): void;
1978
+ /**
1979
+ * Creates a new instance of the JavaScript communication backend.
1980
+ */
1981
+ constructor(sender: IpcCommunicationBackendSender);
1982
+ /**
1983
+ * Used by JavaScript to provide an incoming message to the IPC framework.
1984
+ */
1985
+ receive(message: IncomingMessage): void;
1986
+ }
1987
+ export class OutgoingMessage {
1988
+ free(): void;
1989
+ constructor(payload: Uint8Array, destination: Endpoint, topic?: string | null);
1990
+ /**
1991
+ * Create a new message and encode the payload as JSON.
1992
+ */
1993
+ static new_json_payload(
1994
+ payload: any,
1995
+ destination: Endpoint,
1996
+ topic?: string | null,
1997
+ ): OutgoingMessage;
1998
+ payload: Uint8Array;
1999
+ destination: Endpoint;
2000
+ get topic(): string | undefined;
2001
+ set topic(value: string | null | undefined);
2002
+ }
2003
+ export class PlatformClient {
2004
+ private constructor();
2005
+ free(): void;
2006
+ state(): StateClient;
2007
+ /**
2008
+ * Load feature flags into the client
2009
+ */
2010
+ load_flags(flags: FeatureFlags): void;
2011
+ }
2012
+ /**
2013
+ * This module represents a stopgap solution to provide access to primitive crypto functions for JS
2014
+ * clients. It is not intended to be used outside of the JS clients and this pattern should not be
2015
+ * proliferated. It is necessary because we want to use SDK crypto prior to the SDK being fully
2016
+ * responsible for state and keys.
2017
+ */
2018
+ export class PureCrypto {
2019
+ private constructor();
2020
+ free(): void;
2021
+ /**
2022
+ * DEPRECATED: Use `symmetric_decrypt_string` instead.
2023
+ * Cleanup ticket: <https://bitwarden.atlassian.net/browse/PM-21247>
2024
+ */
2025
+ static symmetric_decrypt(enc_string: string, key: Uint8Array): string;
2026
+ static symmetric_decrypt_string(enc_string: string, key: Uint8Array): string;
2027
+ static symmetric_decrypt_bytes(enc_string: string, key: Uint8Array): Uint8Array;
2028
+ /**
2029
+ * DEPRECATED: Use `symmetric_decrypt_filedata` instead.
2030
+ * Cleanup ticket: <https://bitwarden.atlassian.net/browse/PM-21247>
2031
+ */
2032
+ static symmetric_decrypt_array_buffer(enc_bytes: Uint8Array, key: Uint8Array): Uint8Array;
2033
+ static symmetric_decrypt_filedata(enc_bytes: Uint8Array, key: Uint8Array): Uint8Array;
2034
+ static symmetric_encrypt_string(plain: string, key: Uint8Array): string;
2035
+ /**
2036
+ * DEPRECATED: Only used by send keys
2037
+ */
2038
+ static symmetric_encrypt_bytes(plain: Uint8Array, key: Uint8Array): string;
2039
+ static symmetric_encrypt_filedata(plain: Uint8Array, key: Uint8Array): Uint8Array;
2040
+ static decrypt_user_key_with_master_password(
2041
+ encrypted_user_key: string,
2042
+ master_password: string,
2043
+ email: string,
2044
+ kdf: Kdf,
2045
+ ): Uint8Array;
2046
+ static encrypt_user_key_with_master_password(
2047
+ user_key: Uint8Array,
2048
+ master_password: string,
2049
+ email: string,
2050
+ kdf: Kdf,
2051
+ ): string;
2052
+ static make_user_key_aes256_cbc_hmac(): Uint8Array;
2053
+ static make_user_key_xchacha20_poly1305(): Uint8Array;
2054
+ /**
2055
+ * Wraps (encrypts) a symmetric key using a symmetric wrapping key, returning the wrapped key
2056
+ * as an EncString.
2057
+ */
2058
+ static wrap_symmetric_key(key_to_be_wrapped: Uint8Array, wrapping_key: Uint8Array): string;
2059
+ /**
2060
+ * Unwraps (decrypts) a wrapped symmetric key using a symmetric wrapping key, returning the
2061
+ * unwrapped key as a serialized byte array.
2062
+ */
2063
+ static unwrap_symmetric_key(wrapped_key: string, wrapping_key: Uint8Array): Uint8Array;
2064
+ /**
2065
+ * Wraps (encrypts) an SPKI DER encoded encapsulation (public) key using a symmetric wrapping
2066
+ * key. Note: Usually, a public key is - by definition - public, so this should not be
2067
+ * used. The specific use-case for this function is to enable rotateable key sets, where
2068
+ * the "public key" is not public, with the intent of preventing the server from being able
2069
+ * to overwrite the user key unlocked by the rotateable keyset.
2070
+ */
2071
+ static wrap_encapsulation_key(encapsulation_key: Uint8Array, wrapping_key: Uint8Array): string;
2072
+ /**
2073
+ * Unwraps (decrypts) a wrapped SPKI DER encoded encapsulation (public) key using a symmetric
2074
+ * wrapping key.
2075
+ */
2076
+ static unwrap_encapsulation_key(wrapped_key: string, wrapping_key: Uint8Array): Uint8Array;
2077
+ /**
2078
+ * Wraps (encrypts) a PKCS8 DER encoded decapsulation (private) key using a symmetric wrapping
2079
+ * key,
2080
+ */
2081
+ static wrap_decapsulation_key(decapsulation_key: Uint8Array, wrapping_key: Uint8Array): string;
2082
+ /**
2083
+ * Unwraps (decrypts) a wrapped PKCS8 DER encoded decapsulation (private) key using a symmetric
2084
+ * wrapping key.
2085
+ */
2086
+ static unwrap_decapsulation_key(wrapped_key: string, wrapping_key: Uint8Array): Uint8Array;
2087
+ /**
2088
+ * Encapsulates (encrypts) a symmetric key using an asymmetric encapsulation key (public key)
2089
+ * in SPKI format, returning the encapsulated key as a string. Note: This is unsigned, so
2090
+ * the sender's authenticity cannot be verified by the recipient.
2091
+ */
2092
+ static encapsulate_key_unsigned(shared_key: Uint8Array, encapsulation_key: Uint8Array): string;
2093
+ /**
2094
+ * Decapsulates (decrypts) a symmetric key using an decapsulation key (private key) in PKCS8
2095
+ * DER format. Note: This is unsigned, so the sender's authenticity cannot be verified by the
2096
+ * recipient.
2097
+ */
2098
+ static decapsulate_key_unsigned(
2099
+ encapsulated_key: string,
2100
+ decapsulation_key: Uint8Array,
2101
+ ): Uint8Array;
2102
+ /**
2103
+ * Given a wrapped signing key and the symmetric key it is wrapped with, this returns
2104
+ * the corresponding verifying key.
2105
+ */
2106
+ static verifying_key_for_signing_key(signing_key: string, wrapping_key: Uint8Array): Uint8Array;
2107
+ /**
2108
+ * Returns the algorithm used for the given verifying key.
2109
+ */
2110
+ static key_algorithm_for_verifying_key(verifying_key: Uint8Array): SignatureAlgorithm;
2111
+ /**
2112
+ * For a given signing identity (verifying key), this function verifies that the signing
2113
+ * identity claimed ownership of the public key. This is a one-sided claim and merely shows
2114
+ * that the signing identity has the intent to receive messages encrypted to the public
2115
+ * key.
2116
+ */
2117
+ static verify_and_unwrap_signed_public_key(
2118
+ signed_public_key: Uint8Array,
2119
+ verifying_key: Uint8Array,
2120
+ ): Uint8Array;
2121
+ /**
2122
+ * Derive output of the KDF for a [bitwarden_crypto::Kdf] configuration.
2123
+ */
2124
+ static derive_kdf_material(password: Uint8Array, salt: Uint8Array, kdf: Kdf): Uint8Array;
2125
+ static decrypt_user_key_with_master_key(
2126
+ encrypted_user_key: string,
2127
+ master_key: Uint8Array,
2128
+ ): Uint8Array;
2129
+ }
2130
+ /**
2131
+ * The `SendAccessClient` is used to interact with the Bitwarden API to get send access tokens.
2132
+ */
2133
+ export class SendAccessClient {
2134
+ private constructor();
2135
+ free(): void;
2136
+ /**
2137
+ * Requests a new send access token.
2138
+ */
2139
+ request_send_access_token(request: SendAccessTokenRequest): Promise<SendAccessTokenResponse>;
2140
+ }
2141
+ export class StateClient {
2142
+ private constructor();
2143
+ free(): void;
2144
+ register_cipher_repository(cipher_repository: any): void;
2145
+ register_folder_repository(store: any): void;
2146
+ register_client_managed_repositories(repositories: Repositories): void;
2147
+ /**
2148
+ * Initialize the database for SDK managed repositories.
2149
+ */
2150
+ initialize_state(configuration: IndexedDbConfiguration): Promise<void>;
2151
+ }
2152
+ export class TotpClient {
2153
+ private constructor();
2154
+ free(): void;
2155
+ /**
2156
+ * Generates a TOTP code from a provided key
2157
+ *
2158
+ * # Arguments
2159
+ * - `key` - Can be:
2160
+ * - A base32 encoded string
2161
+ * - OTP Auth URI
2162
+ * - Steam URI
2163
+ * - `time_ms` - Optional timestamp in milliseconds
2164
+ */
2165
+ generate_totp(key: string, time_ms?: number | null): TotpResponse;
253
2166
  }
254
- export class ClientVault {
2167
+ export class VaultClient {
255
2168
  private constructor();
256
2169
  free(): void;
257
- folders(): ClientFolders;
2170
+ /**
2171
+ * Attachment related operations.
2172
+ */
2173
+ attachments(): AttachmentsClient;
2174
+ /**
2175
+ * Cipher related operations.
2176
+ */
2177
+ ciphers(): CiphersClient;
2178
+ /**
2179
+ * Folder related operations.
2180
+ */
2181
+ folders(): FoldersClient;
2182
+ /**
2183
+ * TOTP related operations.
2184
+ */
2185
+ totp(): TotpClient;
2186
+ /**
2187
+ * Collection related operations.
2188
+ */
2189
+ collections(): CollectionsClient;
258
2190
  }