@bitwarden/sdk-internal 0.2.0-main.24 → 0.2.0-main.241

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