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

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