@bitwarden/sdk-internal 0.2.0-main.32 → 0.2.0-main.320

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