@bitwarden/sdk-internal 0.2.0-main.25 → 0.2.0-main.251

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,110 @@ 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
+ // TODO: Uncomment this when the `uuid` crate is used.
139
+ // export type Uuid = unknown;
140
+
141
+ export type Uuid = string;
142
+
143
+ /**
144
+ * RFC3339 compliant date-time string.
145
+ * @typeParam T - Not used in JavaScript.
146
+ */
147
+ export type DateTime<T = unknown> = string;
148
+
149
+ /**
150
+ * UTC date-time string. Not used in JavaScript.
151
+ */
152
+ export type Utc = unknown;
153
+
154
+ /**
155
+ * An integer that is known not to equal zero.
156
+ */
157
+ export type NonZeroU32 = number;
158
+
159
+ export interface Repository<T> {
160
+ get(id: string): Promise<T | null>;
161
+ list(): Promise<T[]>;
162
+ set(id: string, value: T): Promise<void>;
163
+ remove(id: string): Promise<void>;
164
+ }
165
+
166
+ export interface TokenProvider {
167
+ get_access_token(): Promise<string | undefined>;
168
+ }
169
+
170
+ export interface TestError extends Error {
171
+ name: "TestError";
172
+ }
173
+
174
+ export function isTestError(error: any): error is TestError;
175
+
176
+ export interface Collection {
177
+ id: Uuid | undefined;
178
+ organizationId: Uuid;
179
+ name: EncString;
180
+ externalId: string | undefined;
181
+ hidePasswords: boolean;
182
+ readOnly: boolean;
183
+ manage: boolean;
184
+ defaultUserCollectionEmail: string | undefined;
185
+ type: CollectionType;
186
+ }
187
+
188
+ export interface CollectionView {
189
+ id: Uuid | undefined;
190
+ organizationId: Uuid;
191
+ name: string;
192
+ externalId: string | undefined;
193
+ hidePasswords: boolean;
194
+ readOnly: boolean;
195
+ manage: boolean;
196
+ type: CollectionType;
197
+ }
198
+
199
+ /**
200
+ * Type of collection
201
+ */
202
+ export type CollectionType = "SharedCollection" | "DefaultUserCollection";
203
+
204
+ export interface CollectionDecryptError extends Error {
205
+ name: "CollectionDecryptError";
206
+ variant: "Crypto";
207
+ }
208
+
209
+ export function isCollectionDecryptError(error: any): error is CollectionDecryptError;
210
+
211
+ /**
212
+ * State used for initializing the user cryptographic state.
213
+ */
15
214
  export interface InitUserCryptoRequest {
215
+ /**
216
+ * The user\'s ID.
217
+ */
218
+ userId: Uuid | undefined;
16
219
  /**
17
220
  * The user\'s KDF parameters, as received from the prelogin request
18
221
  */
@@ -24,15 +227,26 @@ export interface InitUserCryptoRequest {
24
227
  /**
25
228
  * The user\'s encrypted private key
26
229
  */
27
- privateKey: string;
230
+ privateKey: EncString;
231
+ /**
232
+ * The user\'s signing key
233
+ */
234
+ signingKey: EncString | undefined;
235
+ /**
236
+ * The user\'s security state
237
+ */
238
+ securityState: SignedSecurityState | undefined;
28
239
  /**
29
240
  * The initialization method to use
30
241
  */
31
242
  method: InitUserCryptoMethod;
32
243
  }
33
244
 
245
+ /**
246
+ * The crypto method used to initialize the user cryptographic state.
247
+ */
34
248
  export type InitUserCryptoMethod =
35
- | { password: { password: string; user_key: string } }
249
+ | { password: { password: string; user_key: EncString } }
36
250
  | { decryptedKey: { decrypted_user_key: string } }
37
251
  | { pin: { pin: string; pin_protected_user_key: EncString } }
38
252
  | { authRequest: { request_private_key: string; method: AuthRequestMethod } }
@@ -40,50 +254,218 @@ export type InitUserCryptoMethod =
40
254
  deviceKey: {
41
255
  device_key: string;
42
256
  protected_device_private_key: EncString;
43
- device_protected_user_key: AsymmetricEncString;
257
+ device_protected_user_key: UnsignedSharedKey;
44
258
  };
45
259
  }
46
- | { keyConnector: { master_key: string; user_key: string } };
260
+ | { keyConnector: { master_key: string; user_key: EncString } };
47
261
 
262
+ /**
263
+ * Auth requests supports multiple initialization methods.
264
+ */
48
265
  export type AuthRequestMethod =
49
- | { userKey: { protected_user_key: AsymmetricEncString } }
50
- | { masterKey: { protected_master_key: AsymmetricEncString; auth_request_key: EncString } };
266
+ | { userKey: { protected_user_key: UnsignedSharedKey } }
267
+ | { masterKey: { protected_master_key: UnsignedSharedKey; auth_request_key: EncString } };
51
268
 
269
+ /**
270
+ * Represents the request to initialize the user\'s organizational cryptographic state.
271
+ */
52
272
  export interface InitOrgCryptoRequest {
53
273
  /**
54
274
  * The encryption keys for all the organizations the user is a part of
55
275
  */
56
- organizationKeys: Map<Uuid, AsymmetricEncString>;
276
+ organizationKeys: Map<Uuid, UnsignedSharedKey>;
57
277
  }
58
278
 
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";
279
+ /**
280
+ * Response from the `update_password` function
281
+ */
282
+ export interface UpdatePasswordResponse {
283
+ /**
284
+ * Hash of the new password
285
+ */
286
+ passwordHash: string;
287
+ /**
288
+ * User key, encrypted with the new password
289
+ */
290
+ newKey: EncString;
291
+ }
292
+
293
+ /**
294
+ * Request for deriving a pin protected user key
295
+ */
296
+ export interface DerivePinKeyResponse {
297
+ /**
298
+ * [UserKey] protected by PIN
299
+ */
300
+ pinProtectedUserKey: EncString;
301
+ /**
302
+ * PIN protected by [UserKey]
303
+ */
304
+ encryptedPin: EncString;
305
+ }
306
+
307
+ /**
308
+ * Request for migrating an account from password to key connector.
309
+ */
310
+ export interface DeriveKeyConnectorRequest {
311
+ /**
312
+ * Encrypted user key, used to validate the master key
313
+ */
314
+ userKeyEncrypted: EncString;
315
+ /**
316
+ * The user\'s master password
317
+ */
318
+ password: string;
319
+ /**
320
+ * The KDF parameters used to derive the master key
321
+ */
322
+ kdf: Kdf;
323
+ /**
324
+ * The user\'s email address
325
+ */
326
+ email: string;
327
+ }
328
+
329
+ /**
330
+ * Response from the `make_key_pair` function
331
+ */
332
+ export interface MakeKeyPairResponse {
333
+ /**
334
+ * The user\'s public key
335
+ */
336
+ userPublicKey: string;
337
+ /**
338
+ * User\'s private key, encrypted with the user key
339
+ */
340
+ userKeyEncryptedPrivateKey: EncString;
341
+ }
342
+
343
+ /**
344
+ * Request for `verify_asymmetric_keys`.
345
+ */
346
+ export interface VerifyAsymmetricKeysRequest {
347
+ /**
348
+ * The user\'s user key
349
+ */
350
+ userKey: string;
351
+ /**
352
+ * The user\'s public key
353
+ */
354
+ userPublicKey: string;
355
+ /**
356
+ * User\'s private key, encrypted with the user key
357
+ */
358
+ userKeyEncryptedPrivateKey: EncString;
359
+ }
360
+
361
+ /**
362
+ * Response for `verify_asymmetric_keys`.
363
+ */
364
+ export interface VerifyAsymmetricKeysResponse {
365
+ /**
366
+ * Whether the user\'s private key was decryptable by the user key.
367
+ */
368
+ privateKeyDecryptable: boolean;
369
+ /**
370
+ * Whether the user\'s private key was a valid RSA key and matched the public key provided.
371
+ */
372
+ validPrivateKey: boolean;
373
+ }
374
+
375
+ /**
376
+ * Response for the `make_keys_for_user_crypto_v2`, containing a set of keys for a user
377
+ */
378
+ export interface UserCryptoV2KeysResponse {
379
+ /**
380
+ * User key
381
+ */
382
+ userKey: string;
383
+ /**
384
+ * Wrapped private key
385
+ */
386
+ privateKey: EncString;
387
+ /**
388
+ * Public key
389
+ */
390
+ publicKey: string;
391
+ /**
392
+ * The user\'s public key, signed by the signing key
393
+ */
394
+ signedPublicKey: SignedPublicKey;
395
+ /**
396
+ * Signing key, encrypted with the user\'s symmetric key
397
+ */
398
+ signingKey: EncString;
399
+ /**
400
+ * Base64 encoded verifying key
401
+ */
402
+ verifyingKey: string;
403
+ /**
404
+ * The user\'s signed security state
405
+ */
406
+ securityState: SignedSecurityState;
407
+ /**
408
+ * The security state\'s version
409
+ */
410
+ securityVersion: number;
411
+ }
412
+
413
+ export type SignedSecurityState = string;
414
+
415
+ /**
416
+ * NewType wrapper for `OrganizationId`
417
+ */
418
+ export type OrganizationId = Tagged<Uuid, "OrganizationId">;
419
+
420
+ export interface DeriveKeyConnectorError extends Error {
421
+ name: "DeriveKeyConnectorError";
422
+ variant: "WrongPassword" | "Crypto";
423
+ }
424
+
425
+ export function isDeriveKeyConnectorError(error: any): error is DeriveKeyConnectorError;
426
+
427
+ export interface EnrollAdminPasswordResetError extends Error {
428
+ name: "EnrollAdminPasswordResetError";
429
+ variant: "VaultLocked" | "Crypto" | "InvalidBase64";
430
+ }
431
+
432
+ export function isEnrollAdminPasswordResetError(error: any): error is EnrollAdminPasswordResetError;
433
+
434
+ export interface CryptoClientError extends Error {
435
+ name: "CryptoClientError";
436
+ variant: "NotAuthenticated" | "VaultLocked" | "Crypto";
437
+ }
438
+
439
+ export function isCryptoClientError(error: any): error is CryptoClientError;
440
+
441
+ export interface StatefulCryptoError extends Error {
442
+ name: "StatefulCryptoError";
443
+ variant: "MissingSecurityState" | "WrongAccountCryptoVersion" | "CryptoError";
80
444
  }
81
445
 
82
- export function isCoreError(error: any): error is CoreError;
446
+ export function isStatefulCryptoError(error: any): error is StatefulCryptoError;
447
+
448
+ /**
449
+ * Feature flags for the Bitwarden SDK client.
450
+ */
451
+ export interface Flags {
452
+ /**
453
+ * Enable cipher key encryption within the `CipherClient`
454
+ */
455
+ enableCipherKeyEncryption?: boolean;
456
+ }
83
457
 
84
458
  export interface EncryptionSettingsError extends Error {
85
459
  name: "EncryptionSettingsError";
86
- variant: "Crypto" | "InvalidBase64" | "VaultLocked" | "InvalidPrivateKey" | "MissingPrivateKey";
460
+ variant:
461
+ | "Crypto"
462
+ | "InvalidBase64"
463
+ | "VaultLocked"
464
+ | "InvalidPrivateKey"
465
+ | "InvalidSigningKey"
466
+ | "InvalidSecurityState"
467
+ | "MissingPrivateKey"
468
+ | "UserIdAlreadySetError";
87
469
  }
88
470
 
89
471
  export function isEncryptionSettingsError(error: any): error is EncryptionSettingsError;
@@ -152,9 +534,16 @@ export interface ClientSettings {
152
534
  deviceType?: DeviceType;
153
535
  }
154
536
 
155
- export type AsymmetricEncString = string;
537
+ export type UnsignedSharedKey = Tagged<string, "UnsignedSharedKey">;
156
538
 
157
- export type EncString = string;
539
+ export type EncString = Tagged<string, "EncString">;
540
+
541
+ export type SignedPublicKey = Tagged<string, "SignedPublicKey">;
542
+
543
+ /**
544
+ * The type of key / signature scheme used for signing and verifying.
545
+ */
546
+ export type SignatureAlgorithm = "ed25519";
158
547
 
159
548
  /**
160
549
  * Key Derivation Function for Bitwarden Account
@@ -166,124 +555,1330 @@ export type Kdf =
166
555
  | { pBKDF2: { iterations: NonZeroU32 } }
167
556
  | { argon2id: { iterations: NonZeroU32; memory: NonZeroU32; parallelism: NonZeroU32 } };
168
557
 
169
- export interface GenerateSshKeyResult {
170
- private_key: string;
171
- public_key: string;
172
- key_fingerprint: string;
173
- }
174
-
175
- export type KeyAlgorithm = "Ed25519" | "Rsa3072" | "Rsa4096";
176
-
177
- export interface KeyGenerationError extends Error {
178
- name: "KeyGenerationError";
179
- variant: "KeyGenerationError" | "KeyConversionError";
558
+ export interface CryptoError extends Error {
559
+ name: "CryptoError";
560
+ variant:
561
+ | "InvalidKey"
562
+ | "InvalidMac"
563
+ | "MacNotProvided"
564
+ | "KeyDecrypt"
565
+ | "InvalidKeyLen"
566
+ | "InvalidUtf8String"
567
+ | "MissingKey"
568
+ | "MissingField"
569
+ | "MissingKeyId"
570
+ | "ReadOnlyKeyStore"
571
+ | "InsufficientKdfParameters"
572
+ | "EncString"
573
+ | "RsaError"
574
+ | "FingerprintError"
575
+ | "ArgonError"
576
+ | "ZeroNumber"
577
+ | "OperationNotSupported"
578
+ | "WrongKeyType"
579
+ | "WrongCoseKeyId"
580
+ | "InvalidNonceLength"
581
+ | "InvalidPadding"
582
+ | "SignatureError"
583
+ | "EncodingError";
180
584
  }
181
585
 
182
- export function isKeyGenerationError(error: any): error is KeyGenerationError;
586
+ export function isCryptoError(error: any): error is CryptoError;
183
587
 
184
- export interface Folder {
185
- id: Uuid | undefined;
186
- name: EncString;
187
- revisionDate: DateTime<Utc>;
588
+ /**
589
+ * Temporary struct to hold metadata related to current account
590
+ *
591
+ * Eventually the SDK itself should have this state and we get rid of this struct.
592
+ */
593
+ export interface Account {
594
+ id: Uuid;
595
+ email: string;
596
+ name: string | undefined;
188
597
  }
189
598
 
190
- export interface FolderView {
191
- id: Uuid | undefined;
192
- name: string;
193
- revisionDate: DateTime<Utc>;
194
- }
599
+ export type ExportFormat = "Csv" | "Json" | { EncryptedJson: { password: string } };
195
600
 
196
- export interface TestError extends Error {
197
- name: "TestError";
601
+ export interface ExportError extends Error {
602
+ name: "ExportError";
603
+ variant:
604
+ | "MissingField"
605
+ | "NotAuthenticated"
606
+ | "VaultLocked"
607
+ | "Csv"
608
+ | "CxfError"
609
+ | "Json"
610
+ | "EncryptedJsonError"
611
+ | "BitwardenCryptoError"
612
+ | "CipherError";
198
613
  }
199
614
 
200
- export function isTestError(error: any): error is TestError;
615
+ export function isExportError(error: any): error is ExportError;
201
616
 
202
- export type Uuid = string;
617
+ export type UsernameGeneratorRequest =
618
+ | { word: { capitalize: boolean; include_number: boolean } }
619
+ | { subaddress: { type: AppendType; email: string } }
620
+ | { catchall: { type: AppendType; domain: string } }
621
+ | { forwarded: { service: ForwarderServiceType; website: string | undefined } };
203
622
 
204
623
  /**
205
- * RFC3339 compliant date-time string.
206
- * @typeParam T - Not used in JavaScript.
624
+ * Configures the email forwarding service to use.
625
+ * For instructions on how to configure each service, see the documentation:
626
+ * <https://bitwarden.com/help/generator/#username-types>
207
627
  */
208
- export type DateTime<T = unknown> = string;
628
+ export type ForwarderServiceType =
629
+ | { addyIo: { api_token: string; domain: string; base_url: string } }
630
+ | { duckDuckGo: { token: string } }
631
+ | { firefox: { api_token: string } }
632
+ | { fastmail: { api_token: string } }
633
+ | { forwardEmail: { api_token: string; domain: string } }
634
+ | { simpleLogin: { api_key: string; base_url: string } };
209
635
 
210
- /**
211
- * UTC date-time string. Not used in JavaScript.
212
- */
213
- export type Utc = unknown;
636
+ export type AppendType = "random" | { websiteName: { website: string } };
637
+
638
+ export interface UsernameError extends Error {
639
+ name: "UsernameError";
640
+ variant: "InvalidApiKey" | "Unknown" | "ResponseContent" | "Reqwest";
641
+ }
642
+
643
+ export function isUsernameError(error: any): error is UsernameError;
214
644
 
215
645
  /**
216
- * An integer that is known not to equal zero.
646
+ * Password generator request options.
217
647
  */
218
- export type NonZeroU32 = number;
219
-
220
- export class BitwardenClient {
221
- free(): void;
648
+ export interface PasswordGeneratorRequest {
222
649
  /**
223
- * @param {ClientSettings | undefined} [settings]
224
- * @param {LogLevel | undefined} [log_level]
650
+ * Include lowercase characters (a-z).
225
651
  */
226
- constructor(settings?: ClientSettings, log_level?: LogLevel);
652
+ lowercase: boolean;
227
653
  /**
228
- * Test method, echoes back the input
229
- * @param {string} msg
230
- * @returns {string}
654
+ * Include uppercase characters (A-Z).
231
655
  */
232
- echo(msg: string): string;
656
+ uppercase: boolean;
233
657
  /**
234
- * @returns {string}
658
+ * Include numbers (0-9).
235
659
  */
236
- version(): string;
660
+ numbers: boolean;
237
661
  /**
238
- * @param {string} msg
239
- * @returns {Promise<void>}
662
+ * Include special characters: ! @ # $ % ^ & *
240
663
  */
241
- throw(msg: string): Promise<void>;
664
+ special: boolean;
242
665
  /**
243
- * Test method, calls http endpoint
244
- * @param {string} url
245
- * @returns {Promise<string>}
666
+ * The length of the generated password.
667
+ * Note that the password length must be greater than the sum of all the minimums.
246
668
  */
247
- http_get(url: string): Promise<string>;
669
+ length: number;
248
670
  /**
249
- * @returns {ClientCrypto}
671
+ * When set to true, the generated password will not contain ambiguous characters.
672
+ * The ambiguous characters are: I, O, l, 0, 1
250
673
  */
251
- crypto(): ClientCrypto;
674
+ avoidAmbiguous: boolean;
252
675
  /**
253
- * @returns {ClientVault}
676
+ * The minimum number of lowercase characters in the generated password.
677
+ * When set, the value must be between 1 and 9. This value is ignored if lowercase is false.
254
678
  */
255
- vault(): ClientVault;
256
- }
257
- export class ClientCrypto {
258
- free(): void;
679
+ minLowercase: number | undefined;
259
680
  /**
260
- * Initialization method for the user crypto. Needs to be called before any other crypto
261
- * operations.
262
- * @param {InitUserCryptoRequest} req
263
- * @returns {Promise<void>}
681
+ * The minimum number of uppercase characters in the generated password.
682
+ * When set, the value must be between 1 and 9. This value is ignored if uppercase is false.
264
683
  */
265
- initialize_user_crypto(req: InitUserCryptoRequest): Promise<void>;
684
+ minUppercase: number | undefined;
266
685
  /**
267
- * Initialization method for the organization crypto. Needs to be called after
268
- * `initialize_user_crypto` but before any other crypto operations.
269
- * @param {InitOrgCryptoRequest} req
270
- * @returns {Promise<void>}
686
+ * The minimum number of numbers in the generated password.
687
+ * When set, the value must be between 1 and 9. This value is ignored if numbers is false.
688
+ */
689
+ minNumber: number | undefined;
690
+ /**
691
+ * The minimum number of special characters in the generated password.
692
+ * When set, the value must be between 1 and 9. This value is ignored if special is false.
693
+ */
694
+ minSpecial: number | undefined;
695
+ }
696
+
697
+ export interface PasswordError extends Error {
698
+ name: "PasswordError";
699
+ variant: "NoCharacterSetEnabled" | "InvalidLength";
700
+ }
701
+
702
+ export function isPasswordError(error: any): error is PasswordError;
703
+
704
+ /**
705
+ * Passphrase generator request options.
706
+ */
707
+ export interface PassphraseGeneratorRequest {
708
+ /**
709
+ * Number of words in the generated passphrase.
710
+ * This value must be between 3 and 20.
711
+ */
712
+ numWords: number;
713
+ /**
714
+ * Character separator between words in the generated passphrase. The value cannot be empty.
715
+ */
716
+ wordSeparator: string;
717
+ /**
718
+ * When set to true, capitalize the first letter of each word in the generated passphrase.
719
+ */
720
+ capitalize: boolean;
721
+ /**
722
+ * When set to true, include a number at the end of one of the words in the generated
723
+ * passphrase.
724
+ */
725
+ includeNumber: boolean;
726
+ }
727
+
728
+ export interface PassphraseError extends Error {
729
+ name: "PassphraseError";
730
+ variant: "InvalidNumWords";
731
+ }
732
+
733
+ export function isPassphraseError(error: any): error is PassphraseError;
734
+
735
+ export interface DiscoverResponse {
736
+ version: string;
737
+ }
738
+
739
+ export type Endpoint =
740
+ | { Web: { id: number } }
741
+ | "BrowserForeground"
742
+ | "BrowserBackground"
743
+ | "DesktopRenderer"
744
+ | "DesktopMain";
745
+
746
+ export interface IpcCommunicationBackendSender {
747
+ send(message: OutgoingMessage): Promise<void>;
748
+ }
749
+
750
+ export interface ChannelError extends Error {
751
+ name: "ChannelError";
752
+ }
753
+
754
+ export function isChannelError(error: any): error is ChannelError;
755
+
756
+ export interface DeserializeError extends Error {
757
+ name: "DeserializeError";
758
+ }
759
+
760
+ export function isDeserializeError(error: any): error is DeserializeError;
761
+
762
+ export interface RequestError extends Error {
763
+ name: "RequestError";
764
+ variant: "Subscribe" | "Receive" | "Timeout" | "Send" | "RpcError";
765
+ }
766
+
767
+ export function isRequestError(error: any): error is RequestError;
768
+
769
+ export interface TypedReceiveError extends Error {
770
+ name: "TypedReceiveError";
771
+ variant: "Channel" | "Timeout" | "Cancelled" | "Typing";
772
+ }
773
+
774
+ export function isTypedReceiveError(error: any): error is TypedReceiveError;
775
+
776
+ export interface ReceiveError extends Error {
777
+ name: "ReceiveError";
778
+ variant: "Channel" | "Timeout" | "Cancelled";
779
+ }
780
+
781
+ export function isReceiveError(error: any): error is ReceiveError;
782
+
783
+ export interface SubscribeError extends Error {
784
+ name: "SubscribeError";
785
+ variant: "NotStarted";
786
+ }
787
+
788
+ export function isSubscribeError(error: any): error is SubscribeError;
789
+
790
+ export type KeyAlgorithm = "Ed25519" | "Rsa3072" | "Rsa4096";
791
+
792
+ export interface SshKeyExportError extends Error {
793
+ name: "SshKeyExportError";
794
+ variant: "KeyConversionError";
795
+ }
796
+
797
+ export function isSshKeyExportError(error: any): error is SshKeyExportError;
798
+
799
+ export interface SshKeyImportError extends Error {
800
+ name: "SshKeyImportError";
801
+ variant: "ParsingError" | "PasswordRequired" | "WrongPassword" | "UnsupportedKeyType";
802
+ }
803
+
804
+ export function isSshKeyImportError(error: any): error is SshKeyImportError;
805
+
806
+ export interface KeyGenerationError extends Error {
807
+ name: "KeyGenerationError";
808
+ variant: "KeyGenerationError" | "KeyConversionError";
809
+ }
810
+
811
+ export function isKeyGenerationError(error: any): error is KeyGenerationError;
812
+
813
+ export interface CallError extends Error {
814
+ name: "CallError";
815
+ }
816
+
817
+ export function isCallError(error: any): error is CallError;
818
+
819
+ export interface EncryptionContext {
820
+ /**
821
+ * The Id of the user that encrypted the cipher. It should always represent a UserId, even for
822
+ * Organization-owned ciphers
823
+ */
824
+ encryptedFor: Uuid;
825
+ cipher: Cipher;
826
+ }
827
+
828
+ export interface Cipher {
829
+ id: Uuid | undefined;
830
+ organizationId: Uuid | undefined;
831
+ folderId: Uuid | undefined;
832
+ collectionIds: Uuid[];
833
+ /**
834
+ * More recent ciphers uses individual encryption keys to encrypt the other fields of the
835
+ * Cipher.
836
+ */
837
+ key: EncString | undefined;
838
+ name: EncString;
839
+ notes: EncString | undefined;
840
+ type: CipherType;
841
+ login: Login | undefined;
842
+ identity: Identity | undefined;
843
+ card: Card | undefined;
844
+ secureNote: SecureNote | undefined;
845
+ sshKey: SshKey | undefined;
846
+ favorite: boolean;
847
+ reprompt: CipherRepromptType;
848
+ organizationUseTotp: boolean;
849
+ edit: boolean;
850
+ permissions: CipherPermissions | undefined;
851
+ viewPassword: boolean;
852
+ localData: LocalData | undefined;
853
+ attachments: Attachment[] | undefined;
854
+ fields: Field[] | undefined;
855
+ passwordHistory: PasswordHistory[] | undefined;
856
+ creationDate: DateTime<Utc>;
857
+ deletedDate: DateTime<Utc> | undefined;
858
+ revisionDate: DateTime<Utc>;
859
+ }
860
+
861
+ export interface CipherView {
862
+ id: Uuid | undefined;
863
+ organizationId: Uuid | undefined;
864
+ folderId: Uuid | undefined;
865
+ collectionIds: Uuid[];
866
+ /**
867
+ * Temporary, required to support re-encrypting existing items.
868
+ */
869
+ key: EncString | undefined;
870
+ name: string;
871
+ notes: string | undefined;
872
+ type: CipherType;
873
+ login: LoginView | undefined;
874
+ identity: IdentityView | undefined;
875
+ card: CardView | undefined;
876
+ secureNote: SecureNoteView | undefined;
877
+ sshKey: SshKeyView | undefined;
878
+ favorite: boolean;
879
+ reprompt: CipherRepromptType;
880
+ organizationUseTotp: boolean;
881
+ edit: boolean;
882
+ permissions: CipherPermissions | undefined;
883
+ viewPassword: boolean;
884
+ localData: LocalDataView | undefined;
885
+ attachments: AttachmentView[] | undefined;
886
+ fields: FieldView[] | undefined;
887
+ passwordHistory: PasswordHistoryView[] | undefined;
888
+ creationDate: DateTime<Utc>;
889
+ deletedDate: DateTime<Utc> | undefined;
890
+ revisionDate: DateTime<Utc>;
891
+ }
892
+
893
+ export type CipherListViewType =
894
+ | { login: LoginListView }
895
+ | "secureNote"
896
+ | { card: CardListView }
897
+ | "identity"
898
+ | "sshKey";
899
+
900
+ /**
901
+ * Available fields on a cipher and can be copied from a the list view in the UI.
902
+ */
903
+ export type CopyableCipherFields =
904
+ | "LoginUsername"
905
+ | "LoginPassword"
906
+ | "LoginTotp"
907
+ | "CardNumber"
908
+ | "CardSecurityCode"
909
+ | "IdentityUsername"
910
+ | "IdentityEmail"
911
+ | "IdentityPhone"
912
+ | "IdentityAddress"
913
+ | "SshKey"
914
+ | "SecureNotes";
915
+
916
+ export interface CipherListView {
917
+ id: Uuid | undefined;
918
+ organizationId: Uuid | undefined;
919
+ folderId: Uuid | undefined;
920
+ collectionIds: Uuid[];
921
+ /**
922
+ * Temporary, required to support calculating TOTP from CipherListView.
923
+ */
924
+ key: EncString | undefined;
925
+ name: string;
926
+ subtitle: string;
927
+ type: CipherListViewType;
928
+ favorite: boolean;
929
+ reprompt: CipherRepromptType;
930
+ organizationUseTotp: boolean;
931
+ edit: boolean;
932
+ permissions: CipherPermissions | undefined;
933
+ viewPassword: boolean;
934
+ /**
935
+ * The number of attachments
936
+ */
937
+ attachments: number;
938
+ /**
939
+ * Indicates if the cipher has old attachments that need to be re-uploaded
940
+ */
941
+ hasOldAttachments: boolean;
942
+ creationDate: DateTime<Utc>;
943
+ deletedDate: DateTime<Utc> | undefined;
944
+ revisionDate: DateTime<Utc>;
945
+ /**
946
+ * Hints for the presentation layer for which fields can be copied.
947
+ */
948
+ copyableFields: CopyableCipherFields[];
949
+ localData: LocalDataView | undefined;
950
+ }
951
+
952
+ /**
953
+ * Represents the result of decrypting a list of ciphers.
954
+ *
955
+ * This struct contains two vectors: `successes` and `failures`.
956
+ * `successes` contains the decrypted `CipherListView` objects,
957
+ * while `failures` contains the original `Cipher` objects that failed to decrypt.
958
+ */
959
+ export interface DecryptCipherListResult {
960
+ /**
961
+ * The decrypted `CipherListView` objects.
962
+ */
963
+ successes: CipherListView[];
964
+ /**
965
+ * The original `Cipher` objects that failed to decrypt.
966
+ */
967
+ failures: Cipher[];
968
+ }
969
+
970
+ export interface Field {
971
+ name: EncString | undefined;
972
+ value: EncString | undefined;
973
+ type: FieldType;
974
+ linkedId: LinkedIdType | undefined;
975
+ }
976
+
977
+ export interface FieldView {
978
+ name: string | undefined;
979
+ value: string | undefined;
980
+ type: FieldType;
981
+ linkedId: LinkedIdType | undefined;
982
+ }
983
+
984
+ export type LinkedIdType = LoginLinkedIdType | CardLinkedIdType | IdentityLinkedIdType;
985
+
986
+ export interface LoginUri {
987
+ uri: EncString | undefined;
988
+ match: UriMatchType | undefined;
989
+ uriChecksum: EncString | undefined;
990
+ }
991
+
992
+ export interface LoginUriView {
993
+ uri: string | undefined;
994
+ match: UriMatchType | undefined;
995
+ uriChecksum: string | undefined;
996
+ }
997
+
998
+ export interface Fido2Credential {
999
+ credentialId: EncString;
1000
+ keyType: EncString;
1001
+ keyAlgorithm: EncString;
1002
+ keyCurve: EncString;
1003
+ keyValue: EncString;
1004
+ rpId: EncString;
1005
+ userHandle: EncString | undefined;
1006
+ userName: EncString | undefined;
1007
+ counter: EncString;
1008
+ rpName: EncString | undefined;
1009
+ userDisplayName: EncString | undefined;
1010
+ discoverable: EncString;
1011
+ creationDate: DateTime<Utc>;
1012
+ }
1013
+
1014
+ export interface Fido2CredentialListView {
1015
+ credentialId: string;
1016
+ rpId: string;
1017
+ userHandle: string | undefined;
1018
+ userName: string | undefined;
1019
+ userDisplayName: string | undefined;
1020
+ }
1021
+
1022
+ export interface Fido2CredentialView {
1023
+ credentialId: string;
1024
+ keyType: string;
1025
+ keyAlgorithm: string;
1026
+ keyCurve: string;
1027
+ keyValue: EncString;
1028
+ rpId: string;
1029
+ userHandle: string | undefined;
1030
+ userName: string | undefined;
1031
+ counter: string;
1032
+ rpName: string | undefined;
1033
+ userDisplayName: string | undefined;
1034
+ discoverable: string;
1035
+ creationDate: DateTime<Utc>;
1036
+ }
1037
+
1038
+ export interface Fido2CredentialFullView {
1039
+ credentialId: string;
1040
+ keyType: string;
1041
+ keyAlgorithm: string;
1042
+ keyCurve: string;
1043
+ keyValue: string;
1044
+ rpId: string;
1045
+ userHandle: string | undefined;
1046
+ userName: string | undefined;
1047
+ counter: string;
1048
+ rpName: string | undefined;
1049
+ userDisplayName: string | undefined;
1050
+ discoverable: string;
1051
+ creationDate: DateTime<Utc>;
1052
+ }
1053
+
1054
+ export interface Fido2CredentialNewView {
1055
+ credentialId: string;
1056
+ keyType: string;
1057
+ keyAlgorithm: string;
1058
+ keyCurve: string;
1059
+ rpId: string;
1060
+ userHandle: string | undefined;
1061
+ userName: string | undefined;
1062
+ counter: string;
1063
+ rpName: string | undefined;
1064
+ userDisplayName: string | undefined;
1065
+ creationDate: DateTime<Utc>;
1066
+ }
1067
+
1068
+ export interface Login {
1069
+ username: EncString | undefined;
1070
+ password: EncString | undefined;
1071
+ passwordRevisionDate: DateTime<Utc> | undefined;
1072
+ uris: LoginUri[] | undefined;
1073
+ totp: EncString | undefined;
1074
+ autofillOnPageLoad: boolean | undefined;
1075
+ fido2Credentials: Fido2Credential[] | undefined;
1076
+ }
1077
+
1078
+ export interface LoginView {
1079
+ username: string | undefined;
1080
+ password: string | undefined;
1081
+ passwordRevisionDate: DateTime<Utc> | undefined;
1082
+ uris: LoginUriView[] | undefined;
1083
+ totp: string | undefined;
1084
+ autofillOnPageLoad: boolean | undefined;
1085
+ fido2Credentials: Fido2Credential[] | undefined;
1086
+ }
1087
+
1088
+ export interface LoginListView {
1089
+ fido2Credentials: Fido2CredentialListView[] | undefined;
1090
+ hasFido2: boolean;
1091
+ username: string | undefined;
1092
+ /**
1093
+ * The TOTP key is not decrypted. Useable as is with [`crate::generate_totp_cipher_view`].
1094
+ */
1095
+ totp: EncString | undefined;
1096
+ uris: LoginUriView[] | undefined;
1097
+ }
1098
+
1099
+ export interface SecureNote {
1100
+ type: SecureNoteType;
1101
+ }
1102
+
1103
+ export interface SecureNoteView {
1104
+ type: SecureNoteType;
1105
+ }
1106
+
1107
+ /**
1108
+ * Request to add or edit a folder.
1109
+ */
1110
+ export interface FolderAddEditRequest {
1111
+ /**
1112
+ * The new name of the folder.
1113
+ */
1114
+ name: string;
1115
+ }
1116
+
1117
+ export interface Folder {
1118
+ id: Uuid | undefined;
1119
+ name: EncString;
1120
+ revisionDate: DateTime<Utc>;
1121
+ }
1122
+
1123
+ export interface FolderView {
1124
+ id: Uuid | undefined;
1125
+ name: string;
1126
+ revisionDate: DateTime<Utc>;
1127
+ }
1128
+
1129
+ export interface DecryptError extends Error {
1130
+ name: "DecryptError";
1131
+ variant: "Crypto" | "VaultLocked";
1132
+ }
1133
+
1134
+ export function isDecryptError(error: any): error is DecryptError;
1135
+
1136
+ export interface EncryptError extends Error {
1137
+ name: "EncryptError";
1138
+ variant: "Crypto" | "VaultLocked" | "MissingUserId";
1139
+ }
1140
+
1141
+ export function isEncryptError(error: any): error is EncryptError;
1142
+
1143
+ export interface TotpResponse {
1144
+ /**
1145
+ * Generated TOTP code
1146
+ */
1147
+ code: string;
1148
+ /**
1149
+ * Time period
1150
+ */
1151
+ period: number;
1152
+ }
1153
+
1154
+ export interface TotpError extends Error {
1155
+ name: "TotpError";
1156
+ variant: "InvalidOtpauth" | "MissingSecret" | "CryptoError" | "VaultLocked";
1157
+ }
1158
+
1159
+ export function isTotpError(error: any): error is TotpError;
1160
+
1161
+ export interface PasswordHistoryView {
1162
+ password: string;
1163
+ lastUsedDate: DateTime<Utc>;
1164
+ }
1165
+
1166
+ export interface PasswordHistory {
1167
+ password: EncString;
1168
+ lastUsedDate: DateTime<Utc>;
1169
+ }
1170
+
1171
+ export interface GetFolderError extends Error {
1172
+ name: "GetFolderError";
1173
+ variant: "ItemNotFound" | "Crypto" | "RepositoryError";
1174
+ }
1175
+
1176
+ export function isGetFolderError(error: any): error is GetFolderError;
1177
+
1178
+ export interface EditFolderError extends Error {
1179
+ name: "EditFolderError";
1180
+ variant:
1181
+ | "ItemNotFound"
1182
+ | "Crypto"
1183
+ | "Api"
1184
+ | "VaultParse"
1185
+ | "MissingField"
1186
+ | "RepositoryError"
1187
+ | "Uuid";
1188
+ }
1189
+
1190
+ export function isEditFolderError(error: any): error is EditFolderError;
1191
+
1192
+ export interface CreateFolderError extends Error {
1193
+ name: "CreateFolderError";
1194
+ variant: "Crypto" | "Api" | "VaultParse" | "MissingField" | "RepositoryError";
1195
+ }
1196
+
1197
+ export function isCreateFolderError(error: any): error is CreateFolderError;
1198
+
1199
+ export interface SshKeyView {
1200
+ /**
1201
+ * SSH private key (ed25519/rsa) in unencrypted openssh private key format [OpenSSH private key](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key)
1202
+ */
1203
+ privateKey: string;
1204
+ /**
1205
+ * SSH public key (ed25519/rsa) according to [RFC4253](https://datatracker.ietf.org/doc/html/rfc4253#section-6.6)
1206
+ */
1207
+ publicKey: string;
1208
+ /**
1209
+ * SSH fingerprint using SHA256 in the format: `SHA256:BASE64_ENCODED_FINGERPRINT`
1210
+ */
1211
+ fingerprint: string;
1212
+ }
1213
+
1214
+ export interface SshKey {
1215
+ /**
1216
+ * SSH private key (ed25519/rsa) in unencrypted openssh private key format [OpenSSH private key](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key)
1217
+ */
1218
+ privateKey: EncString;
1219
+ /**
1220
+ * SSH public key (ed25519/rsa) according to [RFC4253](https://datatracker.ietf.org/doc/html/rfc4253#section-6.6)
1221
+ */
1222
+ publicKey: EncString;
1223
+ /**
1224
+ * SSH fingerprint using SHA256 in the format: `SHA256:BASE64_ENCODED_FINGERPRINT`
1225
+ */
1226
+ fingerprint: EncString;
1227
+ }
1228
+
1229
+ export interface LocalDataView {
1230
+ lastUsedDate: DateTime<Utc> | undefined;
1231
+ lastLaunched: DateTime<Utc> | undefined;
1232
+ }
1233
+
1234
+ export interface LocalData {
1235
+ lastUsedDate: DateTime<Utc> | undefined;
1236
+ lastLaunched: DateTime<Utc> | undefined;
1237
+ }
1238
+
1239
+ export interface IdentityView {
1240
+ title: string | undefined;
1241
+ firstName: string | undefined;
1242
+ middleName: string | undefined;
1243
+ lastName: string | undefined;
1244
+ address1: string | undefined;
1245
+ address2: string | undefined;
1246
+ address3: string | undefined;
1247
+ city: string | undefined;
1248
+ state: string | undefined;
1249
+ postalCode: string | undefined;
1250
+ country: string | undefined;
1251
+ company: string | undefined;
1252
+ email: string | undefined;
1253
+ phone: string | undefined;
1254
+ ssn: string | undefined;
1255
+ username: string | undefined;
1256
+ passportNumber: string | undefined;
1257
+ licenseNumber: string | undefined;
1258
+ }
1259
+
1260
+ export interface Identity {
1261
+ title: EncString | undefined;
1262
+ firstName: EncString | undefined;
1263
+ middleName: EncString | undefined;
1264
+ lastName: EncString | undefined;
1265
+ address1: EncString | undefined;
1266
+ address2: EncString | undefined;
1267
+ address3: EncString | undefined;
1268
+ city: EncString | undefined;
1269
+ state: EncString | undefined;
1270
+ postalCode: EncString | undefined;
1271
+ country: EncString | undefined;
1272
+ company: EncString | undefined;
1273
+ email: EncString | undefined;
1274
+ phone: EncString | undefined;
1275
+ ssn: EncString | undefined;
1276
+ username: EncString | undefined;
1277
+ passportNumber: EncString | undefined;
1278
+ licenseNumber: EncString | undefined;
1279
+ }
1280
+
1281
+ export interface CipherPermissions {
1282
+ delete: boolean;
1283
+ restore: boolean;
1284
+ }
1285
+
1286
+ export interface CipherError extends Error {
1287
+ name: "CipherError";
1288
+ variant:
1289
+ | "MissingFieldError"
1290
+ | "VaultLocked"
1291
+ | "CryptoError"
1292
+ | "EncryptError"
1293
+ | "AttachmentsWithoutKeys";
1294
+ }
1295
+
1296
+ export function isCipherError(error: any): error is CipherError;
1297
+
1298
+ /**
1299
+ * Minimal CardView only including the needed details for list views
1300
+ */
1301
+ export interface CardListView {
1302
+ /**
1303
+ * The brand of the card, e.g. Visa, Mastercard, etc.
1304
+ */
1305
+ brand: string | undefined;
1306
+ }
1307
+
1308
+ export interface CardView {
1309
+ cardholderName: string | undefined;
1310
+ expMonth: string | undefined;
1311
+ expYear: string | undefined;
1312
+ code: string | undefined;
1313
+ brand: string | undefined;
1314
+ number: string | undefined;
1315
+ }
1316
+
1317
+ export interface Card {
1318
+ cardholderName: EncString | undefined;
1319
+ expMonth: EncString | undefined;
1320
+ expYear: EncString | undefined;
1321
+ code: EncString | undefined;
1322
+ brand: EncString | undefined;
1323
+ number: EncString | undefined;
1324
+ }
1325
+
1326
+ export interface DecryptFileError extends Error {
1327
+ name: "DecryptFileError";
1328
+ variant: "Decrypt" | "Io";
1329
+ }
1330
+
1331
+ export function isDecryptFileError(error: any): error is DecryptFileError;
1332
+
1333
+ export interface EncryptFileError extends Error {
1334
+ name: "EncryptFileError";
1335
+ variant: "Encrypt" | "Io";
1336
+ }
1337
+
1338
+ export function isEncryptFileError(error: any): error is EncryptFileError;
1339
+
1340
+ export interface AttachmentView {
1341
+ id: string | undefined;
1342
+ url: string | undefined;
1343
+ size: string | undefined;
1344
+ sizeName: string | undefined;
1345
+ fileName: string | undefined;
1346
+ key: EncString | undefined;
1347
+ /**
1348
+ * The decrypted attachmentkey in base64 format.
1349
+ *
1350
+ * **TEMPORARY FIELD**: This field is a temporary workaround to provide
1351
+ * decrypted attachment keys to the TypeScript client during the migration
1352
+ * process. It will be removed once the encryption/decryption logic is
1353
+ * fully migrated to the SDK.
1354
+ *
1355
+ * **Ticket**: <https://bitwarden.atlassian.net/browse/PM-23005>
1356
+ *
1357
+ * Do not rely on this field for long-term use.
1358
+ */
1359
+ decryptedKey: string | undefined;
1360
+ }
1361
+
1362
+ export interface Attachment {
1363
+ id: string | undefined;
1364
+ url: string | undefined;
1365
+ size: string | undefined;
1366
+ /**
1367
+ * Readable size, ex: \"4.2 KB\" or \"1.43 GB\
1368
+ */
1369
+ sizeName: string | undefined;
1370
+ fileName: EncString | undefined;
1371
+ key: EncString | undefined;
1372
+ }
1373
+
1374
+ export class AttachmentsClient {
1375
+ private constructor();
1376
+ free(): void;
1377
+ decrypt_buffer(
1378
+ cipher: Cipher,
1379
+ attachment: AttachmentView,
1380
+ encrypted_buffer: Uint8Array,
1381
+ ): Uint8Array;
1382
+ }
1383
+ /**
1384
+ * Subclient containing auth functionality.
1385
+ */
1386
+ export class AuthClient {
1387
+ private constructor();
1388
+ free(): void;
1389
+ /**
1390
+ * Client for send access functionality
1391
+ */
1392
+ send_access(): SendAccessClient;
1393
+ }
1394
+ export class BitwardenClient {
1395
+ free(): void;
1396
+ constructor(token_provider: any, settings?: ClientSettings | null);
1397
+ /**
1398
+ * Test method, echoes back the input
1399
+ */
1400
+ echo(msg: string): string;
1401
+ version(): string;
1402
+ throw(msg: string): void;
1403
+ /**
1404
+ * Test method, calls http endpoint
1405
+ */
1406
+ http_get(url: string): Promise<string>;
1407
+ /**
1408
+ * Auth related operations.
1409
+ */
1410
+ auth(): AuthClient;
1411
+ crypto(): CryptoClient;
1412
+ vault(): VaultClient;
1413
+ /**
1414
+ * Constructs a specific client for platform-specific functionality
1415
+ */
1416
+ platform(): PlatformClient;
1417
+ /**
1418
+ * Constructs a specific client for generating passwords and passphrases
1419
+ */
1420
+ generator(): GeneratorClient;
1421
+ exporters(): ExporterClient;
1422
+ }
1423
+ export class CiphersClient {
1424
+ private constructor();
1425
+ free(): void;
1426
+ encrypt(cipher_view: CipherView): EncryptionContext;
1427
+ /**
1428
+ * Encrypt a cipher with the provided key. This should only be used when rotating encryption
1429
+ * keys in the Web client.
1430
+ *
1431
+ * Until key rotation is fully implemented in the SDK, this method must be provided the new
1432
+ * symmetric key in base64 format. See PM-23084
1433
+ *
1434
+ * If the cipher has a CipherKey, it will be re-encrypted with the new key.
1435
+ * If the cipher does not have a CipherKey and CipherKeyEncryption is enabled, one will be
1436
+ * generated using the new key. Otherwise, the cipher's data will be encrypted with the new
1437
+ * key directly.
1438
+ */
1439
+ encrypt_cipher_for_rotation(cipher_view: CipherView, new_key_b64: string): EncryptionContext;
1440
+ decrypt(cipher: Cipher): CipherView;
1441
+ decrypt_list(ciphers: Cipher[]): CipherListView[];
1442
+ /**
1443
+ * Decrypt cipher list with failures
1444
+ * Returns both successfully decrypted ciphers and any that failed to decrypt
1445
+ */
1446
+ decrypt_list_with_failures(ciphers: Cipher[]): DecryptCipherListResult;
1447
+ decrypt_fido2_credentials(cipher_view: CipherView): Fido2CredentialView[];
1448
+ /**
1449
+ * Temporary method used to re-encrypt FIDO2 credentials for a cipher view.
1450
+ * Necessary until the TS clients utilize the SDK entirely for FIDO2 credentials management.
1451
+ * TS clients create decrypted FIDO2 credentials that need to be encrypted manually when
1452
+ * encrypting the rest of the CipherView.
1453
+ * TODO: Remove once TS passkey provider implementation uses SDK - PM-8313
1454
+ */
1455
+ set_fido2_credentials(
1456
+ cipher_view: CipherView,
1457
+ fido2_credentials: Fido2CredentialFullView[],
1458
+ ): CipherView;
1459
+ move_to_organization(cipher_view: CipherView, organization_id: OrganizationId): CipherView;
1460
+ decrypt_fido2_private_key(cipher_view: CipherView): string;
1461
+ }
1462
+ export class CollectionViewNodeItem {
1463
+ private constructor();
1464
+ free(): void;
1465
+ get_item(): CollectionView;
1466
+ get_parent(): CollectionView | undefined;
1467
+ get_children(): CollectionView[];
1468
+ get_ancestors(): Map<any, any>;
1469
+ }
1470
+ export class CollectionViewTree {
1471
+ private constructor();
1472
+ free(): void;
1473
+ get_item_by_id(collection_view: CollectionView): CollectionViewNodeItem | undefined;
1474
+ get_root_items(): CollectionViewNodeItem[];
1475
+ get_flat_items(): CollectionViewNodeItem[];
1476
+ }
1477
+ export class CollectionsClient {
1478
+ private constructor();
1479
+ free(): void;
1480
+ decrypt(collection: Collection): CollectionView;
1481
+ decrypt_list(collections: Collection[]): CollectionView[];
1482
+ /**
1483
+ *
1484
+ * Returns the vector of CollectionView objects in a tree structure based on its implemented
1485
+ * path().
1486
+ */
1487
+ get_collection_tree(collections: CollectionView[]): CollectionViewTree;
1488
+ }
1489
+ /**
1490
+ * A client for the crypto operations.
1491
+ */
1492
+ export class CryptoClient {
1493
+ private constructor();
1494
+ free(): void;
1495
+ /**
1496
+ * Initialization method for the user crypto. Needs to be called before any other crypto
1497
+ * operations.
1498
+ */
1499
+ initialize_user_crypto(req: InitUserCryptoRequest): Promise<void>;
1500
+ /**
1501
+ * Initialization method for the organization crypto. Needs to be called after
1502
+ * `initialize_user_crypto` but before any other crypto operations.
271
1503
  */
272
1504
  initialize_org_crypto(req: InitOrgCryptoRequest): Promise<void>;
1505
+ /**
1506
+ * Generates a new key pair and encrypts the private key with the provided user key.
1507
+ * Crypto initialization not required.
1508
+ */
1509
+ make_key_pair(user_key: string): MakeKeyPairResponse;
1510
+ /**
1511
+ * Verifies a user's asymmetric keys by decrypting the private key with the provided user
1512
+ * key. Returns if the private key is decryptable and if it is a valid matching key.
1513
+ * Crypto initialization not required.
1514
+ */
1515
+ verify_asymmetric_keys(request: VerifyAsymmetricKeysRequest): VerifyAsymmetricKeysResponse;
1516
+ /**
1517
+ * Makes a new signing key pair and signs the public key for the user
1518
+ */
1519
+ make_keys_for_user_crypto_v2(): UserCryptoV2KeysResponse;
1520
+ /**
1521
+ * Creates a rotated set of account keys for the current state
1522
+ */
1523
+ get_v2_rotated_account_keys(): UserCryptoV2KeysResponse;
1524
+ }
1525
+ export class ExporterClient {
1526
+ private constructor();
1527
+ free(): void;
1528
+ export_vault(folders: Folder[], ciphers: Cipher[], format: ExportFormat): string;
1529
+ export_organization_vault(
1530
+ collections: Collection[],
1531
+ ciphers: Cipher[],
1532
+ format: ExportFormat,
1533
+ ): string;
1534
+ /**
1535
+ * Credential Exchange Format (CXF)
1536
+ *
1537
+ * *Warning:* Expect this API to be unstable, and it will change in the future.
1538
+ *
1539
+ * For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
1540
+ * Ideally, the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
1541
+ */
1542
+ export_cxf(account: Account, ciphers: Cipher[]): string;
1543
+ /**
1544
+ * Credential Exchange Format (CXF)
1545
+ *
1546
+ * *Warning:* Expect this API to be unstable, and it will change in the future.
1547
+ *
1548
+ * For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
1549
+ * Ideally, the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
1550
+ */
1551
+ import_cxf(payload: string): Cipher[];
273
1552
  }
274
- export class ClientFolders {
1553
+ /**
1554
+ * Wrapper for folder specific functionality.
1555
+ */
1556
+ export class FoldersClient {
1557
+ private constructor();
275
1558
  free(): void;
276
1559
  /**
277
- * Decrypt folder
278
- * @param {Folder} folder
279
- * @returns {FolderView}
1560
+ * Encrypt a [FolderView] to a [Folder].
1561
+ */
1562
+ encrypt(folder_view: FolderView): Folder;
1563
+ /**
1564
+ * Encrypt a [Folder] to [FolderView].
280
1565
  */
281
1566
  decrypt(folder: Folder): FolderView;
1567
+ /**
1568
+ * Decrypt a list of [Folder]s to a list of [FolderView]s.
1569
+ */
1570
+ decrypt_list(folders: Folder[]): FolderView[];
1571
+ /**
1572
+ * Get all folders from state and decrypt them to a list of [FolderView].
1573
+ */
1574
+ list(): Promise<FolderView[]>;
1575
+ /**
1576
+ * Get a specific [Folder] by its ID from state and decrypt it to a [FolderView].
1577
+ */
1578
+ get(folder_id: string): Promise<FolderView>;
1579
+ /**
1580
+ * Create a new [Folder] and save it to the server.
1581
+ */
1582
+ create(request: FolderAddEditRequest): Promise<FolderView>;
1583
+ /**
1584
+ * Edit the [Folder] and save it to the server.
1585
+ */
1586
+ edit(folder_id: string, request: FolderAddEditRequest): Promise<FolderView>;
1587
+ }
1588
+ export class GeneratorClient {
1589
+ private constructor();
1590
+ free(): void;
1591
+ /**
1592
+ * Generates a random password.
1593
+ *
1594
+ * The character sets and password length can be customized using the `input` parameter.
1595
+ *
1596
+ * # Examples
1597
+ *
1598
+ * ```
1599
+ * use bitwarden_core::Client;
1600
+ * use bitwarden_generators::{GeneratorClientsExt, PassphraseError, PasswordGeneratorRequest};
1601
+ *
1602
+ * async fn test() -> Result<(), PassphraseError> {
1603
+ * let input = PasswordGeneratorRequest {
1604
+ * lowercase: true,
1605
+ * uppercase: true,
1606
+ * numbers: true,
1607
+ * length: 20,
1608
+ * ..Default::default()
1609
+ * };
1610
+ * let password = Client::new(None).generator().password(input).unwrap();
1611
+ * println!("{}", password);
1612
+ * Ok(())
1613
+ * }
1614
+ * ```
1615
+ */
1616
+ password(input: PasswordGeneratorRequest): string;
1617
+ /**
1618
+ * Generates a random passphrase.
1619
+ * A passphrase is a combination of random words separated by a character.
1620
+ * An example of passphrase is `correct horse battery staple`.
1621
+ *
1622
+ * The number of words and their case, the word separator, and the inclusion of
1623
+ * a number in the passphrase can be customized using the `input` parameter.
1624
+ *
1625
+ * # Examples
1626
+ *
1627
+ * ```
1628
+ * use bitwarden_core::Client;
1629
+ * use bitwarden_generators::{GeneratorClientsExt, PassphraseError, PassphraseGeneratorRequest};
1630
+ *
1631
+ * async fn test() -> Result<(), PassphraseError> {
1632
+ * let input = PassphraseGeneratorRequest {
1633
+ * num_words: 4,
1634
+ * ..Default::default()
1635
+ * };
1636
+ * let passphrase = Client::new(None).generator().passphrase(input).unwrap();
1637
+ * println!("{}", passphrase);
1638
+ * Ok(())
1639
+ * }
1640
+ * ```
1641
+ */
1642
+ passphrase(input: PassphraseGeneratorRequest): string;
1643
+ }
1644
+ export class IncomingMessage {
1645
+ free(): void;
1646
+ constructor(payload: Uint8Array, destination: Endpoint, source: Endpoint, topic?: string | null);
1647
+ /**
1648
+ * Try to parse the payload as JSON.
1649
+ * @returns The parsed JSON value, or undefined if the payload is not valid JSON.
1650
+ */
1651
+ parse_payload_as_json(): any;
1652
+ payload: Uint8Array;
1653
+ destination: Endpoint;
1654
+ source: Endpoint;
1655
+ get topic(): string | undefined;
1656
+ set topic(value: string | null | undefined);
1657
+ }
1658
+ /**
1659
+ * JavaScript wrapper around the IPC client. For more information, see the
1660
+ * [IpcClient] documentation.
1661
+ */
1662
+ export class IpcClient {
1663
+ free(): void;
1664
+ constructor(communication_provider: IpcCommunicationBackend);
1665
+ start(): Promise<void>;
1666
+ isRunning(): Promise<boolean>;
1667
+ send(message: OutgoingMessage): Promise<void>;
1668
+ subscribe(): Promise<IpcClientSubscription>;
1669
+ }
1670
+ /**
1671
+ * JavaScript wrapper around the IPC client subscription. For more information, see the
1672
+ * [IpcClientSubscription](crate::IpcClientSubscription) documentation.
1673
+ */
1674
+ export class IpcClientSubscription {
1675
+ private constructor();
1676
+ free(): void;
1677
+ receive(abort_signal?: AbortSignal | null): Promise<IncomingMessage>;
1678
+ }
1679
+ /**
1680
+ * JavaScript implementation of the `CommunicationBackend` trait for IPC communication.
1681
+ */
1682
+ export class IpcCommunicationBackend {
1683
+ free(): void;
1684
+ /**
1685
+ * Creates a new instance of the JavaScript communication backend.
1686
+ */
1687
+ constructor(sender: IpcCommunicationBackendSender);
1688
+ /**
1689
+ * Used by JavaScript to provide an incoming message to the IPC framework.
1690
+ */
1691
+ receive(message: IncomingMessage): void;
282
1692
  }
283
- export class ClientVault {
1693
+ export class OutgoingMessage {
284
1694
  free(): void;
1695
+ constructor(payload: Uint8Array, destination: Endpoint, topic?: string | null);
1696
+ /**
1697
+ * Create a new message and encode the payload as JSON.
1698
+ */
1699
+ static new_json_payload(
1700
+ payload: any,
1701
+ destination: Endpoint,
1702
+ topic?: string | null,
1703
+ ): OutgoingMessage;
1704
+ payload: Uint8Array;
1705
+ destination: Endpoint;
1706
+ get topic(): string | undefined;
1707
+ set topic(value: string | null | undefined);
1708
+ }
1709
+ export class PlatformClient {
1710
+ private constructor();
1711
+ free(): void;
1712
+ state(): StateClient;
1713
+ /**
1714
+ * Load feature flags into the client
1715
+ */
1716
+ load_flags(flags: Flags): void;
1717
+ }
1718
+ /**
1719
+ * This module represents a stopgap solution to provide access to primitive crypto functions for JS
1720
+ * clients. It is not intended to be used outside of the JS clients and this pattern should not be
1721
+ * proliferated. It is necessary because we want to use SDK crypto prior to the SDK being fully
1722
+ * responsible for state and keys.
1723
+ */
1724
+ export class PureCrypto {
1725
+ private constructor();
1726
+ free(): void;
1727
+ /**
1728
+ * DEPRECATED: Use `symmetric_decrypt_string` instead.
1729
+ * Cleanup ticket: <https://bitwarden.atlassian.net/browse/PM-21247>
1730
+ */
1731
+ static symmetric_decrypt(enc_string: string, key: Uint8Array): string;
1732
+ static symmetric_decrypt_string(enc_string: string, key: Uint8Array): string;
1733
+ static symmetric_decrypt_bytes(enc_string: string, key: Uint8Array): Uint8Array;
1734
+ /**
1735
+ * DEPRECATED: Use `symmetric_decrypt_filedata` instead.
1736
+ * Cleanup ticket: <https://bitwarden.atlassian.net/browse/PM-21247>
1737
+ */
1738
+ static symmetric_decrypt_array_buffer(enc_bytes: Uint8Array, key: Uint8Array): Uint8Array;
1739
+ static symmetric_decrypt_filedata(enc_bytes: Uint8Array, key: Uint8Array): Uint8Array;
1740
+ static symmetric_encrypt_string(plain: string, key: Uint8Array): string;
1741
+ /**
1742
+ * DEPRECATED: Only used by send keys
1743
+ */
1744
+ static symmetric_encrypt_bytes(plain: Uint8Array, key: Uint8Array): string;
1745
+ static symmetric_encrypt_filedata(plain: Uint8Array, key: Uint8Array): Uint8Array;
1746
+ static decrypt_user_key_with_master_password(
1747
+ encrypted_user_key: string,
1748
+ master_password: string,
1749
+ email: string,
1750
+ kdf: Kdf,
1751
+ ): Uint8Array;
1752
+ static encrypt_user_key_with_master_password(
1753
+ user_key: Uint8Array,
1754
+ master_password: string,
1755
+ email: string,
1756
+ kdf: Kdf,
1757
+ ): string;
1758
+ static make_user_key_aes256_cbc_hmac(): Uint8Array;
1759
+ static make_user_key_xchacha20_poly1305(): Uint8Array;
1760
+ /**
1761
+ * Wraps (encrypts) a symmetric key using a symmetric wrapping key, returning the wrapped key
1762
+ * as an EncString.
1763
+ */
1764
+ static wrap_symmetric_key(key_to_be_wrapped: Uint8Array, wrapping_key: Uint8Array): string;
1765
+ /**
1766
+ * Unwraps (decrypts) a wrapped symmetric key using a symmetric wrapping key, returning the
1767
+ * unwrapped key as a serialized byte array.
1768
+ */
1769
+ static unwrap_symmetric_key(wrapped_key: string, wrapping_key: Uint8Array): Uint8Array;
1770
+ /**
1771
+ * Wraps (encrypts) an SPKI DER encoded encapsulation (public) key using a symmetric wrapping
1772
+ * key. Note: Usually, a public key is - by definition - public, so this should not be
1773
+ * used. The specific use-case for this function is to enable rotateable key sets, where
1774
+ * the "public key" is not public, with the intent of preventing the server from being able
1775
+ * to overwrite the user key unlocked by the rotateable keyset.
1776
+ */
1777
+ static wrap_encapsulation_key(encapsulation_key: Uint8Array, wrapping_key: Uint8Array): string;
1778
+ /**
1779
+ * Unwraps (decrypts) a wrapped SPKI DER encoded encapsulation (public) key using a symmetric
1780
+ * wrapping key.
1781
+ */
1782
+ static unwrap_encapsulation_key(wrapped_key: string, wrapping_key: Uint8Array): Uint8Array;
1783
+ /**
1784
+ * Wraps (encrypts) a PKCS8 DER encoded decapsulation (private) key using a symmetric wrapping
1785
+ * key,
1786
+ */
1787
+ static wrap_decapsulation_key(decapsulation_key: Uint8Array, wrapping_key: Uint8Array): string;
1788
+ /**
1789
+ * Unwraps (decrypts) a wrapped PKCS8 DER encoded decapsulation (private) key using a symmetric
1790
+ * wrapping key.
1791
+ */
1792
+ static unwrap_decapsulation_key(wrapped_key: string, wrapping_key: Uint8Array): Uint8Array;
1793
+ /**
1794
+ * Encapsulates (encrypts) a symmetric key using an asymmetric encapsulation key (public key)
1795
+ * in SPKI format, returning the encapsulated key as a string. Note: This is unsigned, so
1796
+ * the sender's authenticity cannot be verified by the recipient.
1797
+ */
1798
+ static encapsulate_key_unsigned(shared_key: Uint8Array, encapsulation_key: Uint8Array): string;
1799
+ /**
1800
+ * Decapsulates (decrypts) a symmetric key using an decapsulation key (private key) in PKCS8
1801
+ * DER format. Note: This is unsigned, so the sender's authenticity cannot be verified by the
1802
+ * recipient.
1803
+ */
1804
+ static decapsulate_key_unsigned(
1805
+ encapsulated_key: string,
1806
+ decapsulation_key: Uint8Array,
1807
+ ): Uint8Array;
1808
+ /**
1809
+ * Given a wrapped signing key and the symmetric key it is wrapped with, this returns
1810
+ * the corresponding verifying key.
1811
+ */
1812
+ static verifying_key_for_signing_key(signing_key: string, wrapping_key: Uint8Array): Uint8Array;
1813
+ /**
1814
+ * Returns the algorithm used for the given verifying key.
1815
+ */
1816
+ static key_algorithm_for_verifying_key(verifying_key: Uint8Array): SignatureAlgorithm;
1817
+ /**
1818
+ * For a given signing identity (verifying key), this function verifies that the signing
1819
+ * identity claimed ownership of the public key. This is a one-sided claim and merely shows
1820
+ * that the signing identity has the intent to receive messages encrypted to the public
1821
+ * key.
1822
+ */
1823
+ static verify_and_unwrap_signed_public_key(
1824
+ signed_public_key: Uint8Array,
1825
+ verifying_key: Uint8Array,
1826
+ ): Uint8Array;
1827
+ /**
1828
+ * Derive output of the KDF for a [bitwarden_crypto::Kdf] configuration.
1829
+ */
1830
+ static derive_kdf_material(password: Uint8Array, salt: Uint8Array, kdf: Kdf): Uint8Array;
1831
+ }
1832
+ export class SendAccessClient {
1833
+ private constructor();
1834
+ free(): void;
1835
+ /**
1836
+ * Request an access token for the provided send
1837
+ */
1838
+ request_send_access_token(request: string): Promise<string>;
1839
+ }
1840
+ export class StateClient {
1841
+ private constructor();
1842
+ free(): void;
1843
+ register_cipher_repository(store: Repository<Cipher>): void;
1844
+ register_folder_repository(store: Repository<Folder>): void;
1845
+ }
1846
+ export class TotpClient {
1847
+ private constructor();
1848
+ free(): void;
1849
+ /**
1850
+ * Generates a TOTP code from a provided key
1851
+ *
1852
+ * # Arguments
1853
+ * - `key` - Can be:
1854
+ * - A base32 encoded string
1855
+ * - OTP Auth URI
1856
+ * - Steam URI
1857
+ * - `time_ms` - Optional timestamp in milliseconds
1858
+ */
1859
+ generate_totp(key: string, time_ms?: number | null): TotpResponse;
1860
+ }
1861
+ export class VaultClient {
1862
+ private constructor();
1863
+ free(): void;
1864
+ /**
1865
+ * Attachment related operations.
1866
+ */
1867
+ attachments(): AttachmentsClient;
1868
+ /**
1869
+ * Cipher related operations.
1870
+ */
1871
+ ciphers(): CiphersClient;
1872
+ /**
1873
+ * Folder related operations.
1874
+ */
1875
+ folders(): FoldersClient;
1876
+ /**
1877
+ * TOTP related operations.
1878
+ */
1879
+ totp(): TotpClient;
285
1880
  /**
286
- * @returns {ClientFolders}
1881
+ * Collection related operations.
287
1882
  */
288
- folders(): ClientFolders;
1883
+ collections(): CollectionsClient;
289
1884
  }