@bitwarden/sdk-internal 0.2.0-main.37 → 0.2.0-main.370

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