@bitwarden/sdk-internal 0.2.0-main.23 → 0.2.0-main.230

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