@bitwarden/sdk-internal 0.2.0-main.22 → 0.2.0-main.221

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;
259
+ }
260
+
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";
80
341
  }
81
342
 
82
- export function isCoreError(error: any): error is CoreError;
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";
527
+ }
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";
173
586
  }
174
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,266 @@ 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
+ export interface Field {
839
+ name: EncString | undefined;
840
+ value: EncString | undefined;
841
+ type: FieldType;
842
+ linkedId: LinkedIdType | undefined;
843
+ }
844
+
845
+ export interface FieldView {
846
+ name: string | undefined;
847
+ value: string | undefined;
848
+ type: FieldType;
849
+ linkedId: LinkedIdType | undefined;
850
+ }
851
+
852
+ export type LinkedIdType = LoginLinkedIdType | CardLinkedIdType | IdentityLinkedIdType;
853
+
854
+ export interface LoginUri {
855
+ uri: EncString | undefined;
856
+ match: UriMatchType | undefined;
857
+ uriChecksum: EncString | undefined;
858
+ }
859
+
860
+ export interface LoginUriView {
861
+ uri: string | undefined;
862
+ match: UriMatchType | undefined;
863
+ uriChecksum: string | undefined;
864
+ }
865
+
866
+ export interface Fido2Credential {
867
+ credentialId: EncString;
868
+ keyType: EncString;
869
+ keyAlgorithm: EncString;
870
+ keyCurve: EncString;
871
+ keyValue: EncString;
872
+ rpId: EncString;
873
+ userHandle: EncString | undefined;
874
+ userName: EncString | undefined;
875
+ counter: EncString;
876
+ rpName: EncString | undefined;
877
+ userDisplayName: EncString | undefined;
878
+ discoverable: EncString;
879
+ creationDate: DateTime<Utc>;
880
+ }
881
+
882
+ export interface Fido2CredentialListView {
883
+ credentialId: string;
884
+ rpId: string;
885
+ userHandle: string | undefined;
886
+ userName: string | undefined;
887
+ userDisplayName: string | undefined;
888
+ }
889
+
890
+ export interface Fido2CredentialView {
891
+ credentialId: string;
892
+ keyType: string;
893
+ keyAlgorithm: string;
894
+ keyCurve: string;
895
+ keyValue: EncString;
896
+ rpId: string;
897
+ userHandle: string | undefined;
898
+ userName: string | undefined;
899
+ counter: string;
900
+ rpName: string | undefined;
901
+ userDisplayName: string | undefined;
902
+ discoverable: string;
903
+ creationDate: DateTime<Utc>;
904
+ }
905
+
906
+ export interface Fido2CredentialNewView {
907
+ credentialId: string;
908
+ keyType: string;
909
+ keyAlgorithm: string;
910
+ keyCurve: string;
911
+ rpId: string;
912
+ userHandle: string | undefined;
913
+ userName: string | undefined;
914
+ counter: string;
915
+ rpName: string | undefined;
916
+ userDisplayName: string | undefined;
917
+ creationDate: DateTime<Utc>;
918
+ }
919
+
920
+ export interface Login {
921
+ username: EncString | undefined;
922
+ password: EncString | undefined;
923
+ passwordRevisionDate: DateTime<Utc> | undefined;
924
+ uris: LoginUri[] | undefined;
925
+ totp: EncString | undefined;
926
+ autofillOnPageLoad: boolean | undefined;
927
+ fido2Credentials: Fido2Credential[] | undefined;
928
+ }
929
+
930
+ export interface LoginView {
931
+ username: string | undefined;
932
+ password: string | undefined;
933
+ passwordRevisionDate: DateTime<Utc> | undefined;
934
+ uris: LoginUriView[] | undefined;
935
+ totp: string | undefined;
936
+ autofillOnPageLoad: boolean | undefined;
937
+ fido2Credentials: Fido2Credential[] | undefined;
938
+ }
939
+
940
+ export interface LoginListView {
941
+ fido2Credentials: Fido2CredentialListView[] | undefined;
942
+ hasFido2: boolean;
943
+ username: string | undefined;
944
+ /**
945
+ * The TOTP key is not decrypted. Useable as is with [`crate::generate_totp_cipher_view`].
946
+ */
947
+ totp: EncString | undefined;
948
+ uris: LoginUriView[] | undefined;
949
+ }
950
+
951
+ export interface SecureNote {
952
+ type: SecureNoteType;
953
+ }
954
+
955
+ export interface SecureNoteView {
956
+ type: SecureNoteType;
957
+ }
958
+
184
959
  export interface Folder {
185
960
  id: Uuid | undefined;
186
961
  name: EncString;
@@ -193,11 +968,224 @@ export interface FolderView {
193
968
  revisionDate: DateTime<Utc>;
194
969
  }
195
970
 
196
- export interface TestError extends Error {
197
- name: "TestError";
971
+ export interface DecryptError extends Error {
972
+ name: "DecryptError";
973
+ variant: "Crypto" | "VaultLocked";
198
974
  }
199
975
 
200
- export function isTestError(error: any): error is TestError;
976
+ export function isDecryptError(error: any): error is DecryptError;
977
+
978
+ export interface EncryptError extends Error {
979
+ name: "EncryptError";
980
+ variant: "Crypto" | "VaultLocked" | "MissingUserId";
981
+ }
982
+
983
+ export function isEncryptError(error: any): error is EncryptError;
984
+
985
+ export interface TotpResponse {
986
+ /**
987
+ * Generated TOTP code
988
+ */
989
+ code: string;
990
+ /**
991
+ * Time period
992
+ */
993
+ period: number;
994
+ }
995
+
996
+ export interface TotpError extends Error {
997
+ name: "TotpError";
998
+ variant: "InvalidOtpauth" | "MissingSecret" | "CryptoError" | "VaultLocked";
999
+ }
1000
+
1001
+ export function isTotpError(error: any): error is TotpError;
1002
+
1003
+ export interface PasswordHistoryView {
1004
+ password: string;
1005
+ lastUsedDate: DateTime<Utc>;
1006
+ }
1007
+
1008
+ export interface PasswordHistory {
1009
+ password: EncString;
1010
+ lastUsedDate: DateTime<Utc>;
1011
+ }
1012
+
1013
+ export interface Collection {
1014
+ id: Uuid | undefined;
1015
+ organizationId: Uuid;
1016
+ name: EncString;
1017
+ externalId: string | undefined;
1018
+ hidePasswords: boolean;
1019
+ readOnly: boolean;
1020
+ manage: boolean;
1021
+ }
1022
+
1023
+ export interface SshKeyView {
1024
+ /**
1025
+ * SSH private key (ed25519/rsa) in unencrypted openssh private key format [OpenSSH private key](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key)
1026
+ */
1027
+ privateKey: string;
1028
+ /**
1029
+ * SSH public key (ed25519/rsa) according to [RFC4253](https://datatracker.ietf.org/doc/html/rfc4253#section-6.6)
1030
+ */
1031
+ publicKey: string;
1032
+ /**
1033
+ * SSH fingerprint using SHA256 in the format: `SHA256:BASE64_ENCODED_FINGERPRINT`
1034
+ */
1035
+ fingerprint: string;
1036
+ }
1037
+
1038
+ export interface SshKey {
1039
+ /**
1040
+ * SSH private key (ed25519/rsa) in unencrypted openssh private key format [OpenSSH private key](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key)
1041
+ */
1042
+ privateKey: EncString;
1043
+ /**
1044
+ * SSH public key (ed25519/rsa) according to [RFC4253](https://datatracker.ietf.org/doc/html/rfc4253#section-6.6)
1045
+ */
1046
+ publicKey: EncString;
1047
+ /**
1048
+ * SSH fingerprint using SHA256 in the format: `SHA256:BASE64_ENCODED_FINGERPRINT`
1049
+ */
1050
+ fingerprint: EncString;
1051
+ }
1052
+
1053
+ export interface LocalDataView {
1054
+ lastUsedDate: DateTime<Utc> | undefined;
1055
+ lastLaunched: DateTime<Utc> | undefined;
1056
+ }
1057
+
1058
+ export interface LocalData {
1059
+ lastUsedDate: DateTime<Utc> | undefined;
1060
+ lastLaunched: DateTime<Utc> | undefined;
1061
+ }
1062
+
1063
+ export interface IdentityView {
1064
+ title: string | undefined;
1065
+ firstName: string | undefined;
1066
+ middleName: string | undefined;
1067
+ lastName: string | undefined;
1068
+ address1: string | undefined;
1069
+ address2: string | undefined;
1070
+ address3: string | undefined;
1071
+ city: string | undefined;
1072
+ state: string | undefined;
1073
+ postalCode: string | undefined;
1074
+ country: string | undefined;
1075
+ company: string | undefined;
1076
+ email: string | undefined;
1077
+ phone: string | undefined;
1078
+ ssn: string | undefined;
1079
+ username: string | undefined;
1080
+ passportNumber: string | undefined;
1081
+ licenseNumber: string | undefined;
1082
+ }
1083
+
1084
+ export interface Identity {
1085
+ title: EncString | undefined;
1086
+ firstName: EncString | undefined;
1087
+ middleName: EncString | undefined;
1088
+ lastName: EncString | undefined;
1089
+ address1: EncString | undefined;
1090
+ address2: EncString | undefined;
1091
+ address3: EncString | undefined;
1092
+ city: EncString | undefined;
1093
+ state: EncString | undefined;
1094
+ postalCode: EncString | undefined;
1095
+ country: EncString | undefined;
1096
+ company: EncString | undefined;
1097
+ email: EncString | undefined;
1098
+ phone: EncString | undefined;
1099
+ ssn: EncString | undefined;
1100
+ username: EncString | undefined;
1101
+ passportNumber: EncString | undefined;
1102
+ licenseNumber: EncString | undefined;
1103
+ }
1104
+
1105
+ export interface CipherPermissions {
1106
+ delete: boolean;
1107
+ restore: boolean;
1108
+ }
1109
+
1110
+ export interface CipherError extends Error {
1111
+ name: "CipherError";
1112
+ variant: "MissingFieldError" | "VaultLocked" | "CryptoError" | "AttachmentsWithoutKeys";
1113
+ }
1114
+
1115
+ export function isCipherError(error: any): error is CipherError;
1116
+
1117
+ /**
1118
+ * Minimal CardView only including the needed details for list views
1119
+ */
1120
+ export interface CardListView {
1121
+ /**
1122
+ * The brand of the card, e.g. Visa, Mastercard, etc.
1123
+ */
1124
+ brand: string | undefined;
1125
+ }
1126
+
1127
+ export interface CardView {
1128
+ cardholderName: string | undefined;
1129
+ expMonth: string | undefined;
1130
+ expYear: string | undefined;
1131
+ code: string | undefined;
1132
+ brand: string | undefined;
1133
+ number: string | undefined;
1134
+ }
1135
+
1136
+ export interface Card {
1137
+ cardholderName: EncString | undefined;
1138
+ expMonth: EncString | undefined;
1139
+ expYear: EncString | undefined;
1140
+ code: EncString | undefined;
1141
+ brand: EncString | undefined;
1142
+ number: EncString | undefined;
1143
+ }
1144
+
1145
+ export interface DecryptFileError extends Error {
1146
+ name: "DecryptFileError";
1147
+ variant: "Decrypt" | "Io";
1148
+ }
1149
+
1150
+ export function isDecryptFileError(error: any): error is DecryptFileError;
1151
+
1152
+ export interface EncryptFileError extends Error {
1153
+ name: "EncryptFileError";
1154
+ variant: "Encrypt" | "Io";
1155
+ }
1156
+
1157
+ export function isEncryptFileError(error: any): error is EncryptFileError;
1158
+
1159
+ export interface AttachmentView {
1160
+ id: string | undefined;
1161
+ url: string | undefined;
1162
+ size: string | undefined;
1163
+ sizeName: string | undefined;
1164
+ fileName: string | undefined;
1165
+ key: EncString | undefined;
1166
+ }
1167
+
1168
+ export interface Attachment {
1169
+ id: string | undefined;
1170
+ url: string | undefined;
1171
+ size: string | undefined;
1172
+ /**
1173
+ * Readable size, ex: \"4.2 KB\" or \"1.43 GB\
1174
+ */
1175
+ sizeName: string | undefined;
1176
+ fileName: EncString | undefined;
1177
+ key: EncString | undefined;
1178
+ }
1179
+
1180
+ import { Tagged } from "type-fest";
1181
+
1182
+ /**
1183
+ * A string that **MUST** be a valid UUID.
1184
+ *
1185
+ * Never create or cast to this type directly, use the `uuid<T>()` function instead.
1186
+ */
1187
+ // TODO: Uncomment this when the `uuid` crate is used.
1188
+ // export type Uuid = unknown;
201
1189
 
202
1190
  export type Uuid = string;
203
1191
 
@@ -217,73 +1205,411 @@ export type Utc = unknown;
217
1205
  */
218
1206
  export type NonZeroU32 = number;
219
1207
 
1208
+ export interface Repository<T> {
1209
+ get(id: string): Promise<T | null>;
1210
+ list(): Promise<T[]>;
1211
+ set(id: string, value: T): Promise<void>;
1212
+ remove(id: string): Promise<void>;
1213
+ }
1214
+
1215
+ export interface TokenProvider {
1216
+ get_access_token(): Promise<string>;
1217
+ }
1218
+
1219
+ export interface TestError extends Error {
1220
+ name: "TestError";
1221
+ }
1222
+
1223
+ export function isTestError(error: any): error is TestError;
1224
+
1225
+ export class AttachmentsClient {
1226
+ private constructor();
1227
+ free(): void;
1228
+ decrypt_buffer(
1229
+ cipher: Cipher,
1230
+ attachment: AttachmentView,
1231
+ encrypted_buffer: Uint8Array,
1232
+ ): Uint8Array;
1233
+ }
220
1234
  export class BitwardenClient {
221
1235
  free(): void;
222
- /**
223
- * @param {ClientSettings | undefined} [settings]
224
- * @param {LogLevel | undefined} [log_level]
225
- */
226
- constructor(settings?: ClientSettings, log_level?: LogLevel);
1236
+ constructor(settings: ClientSettings | null | undefined, token_provider: any);
227
1237
  /**
228
1238
  * Test method, echoes back the input
229
- * @param {string} msg
230
- * @returns {string}
231
1239
  */
232
1240
  echo(msg: string): string;
233
- /**
234
- * @returns {string}
235
- */
236
1241
  version(): string;
237
- /**
238
- * @param {string} msg
239
- * @returns {Promise<void>}
240
- */
241
- throw(msg: string): Promise<void>;
1242
+ throw(msg: string): void;
242
1243
  /**
243
1244
  * Test method, calls http endpoint
244
- * @param {string} url
245
- * @returns {Promise<string>}
246
1245
  */
247
1246
  http_get(url: string): Promise<string>;
1247
+ crypto(): CryptoClient;
1248
+ vault(): VaultClient;
248
1249
  /**
249
- * @returns {ClientCrypto}
1250
+ * Constructs a specific client for platform-specific functionality
250
1251
  */
251
- crypto(): ClientCrypto;
1252
+ platform(): PlatformClient;
252
1253
  /**
253
- * @returns {ClientVault}
1254
+ * Constructs a specific client for generating passwords and passphrases
254
1255
  */
255
- vault(): ClientVault;
1256
+ generator(): GeneratorClient;
1257
+ exporters(): ExporterClient;
256
1258
  }
257
- export class ClientCrypto {
1259
+ export class CiphersClient {
1260
+ private constructor();
1261
+ free(): void;
1262
+ encrypt(cipher_view: CipherView): EncryptionContext;
1263
+ decrypt(cipher: Cipher): CipherView;
1264
+ decrypt_list(ciphers: Cipher[]): CipherListView[];
1265
+ decrypt_fido2_credentials(cipher_view: CipherView): Fido2CredentialView[];
1266
+ move_to_organization(cipher_view: CipherView, organization_id: OrganizationId): CipherView;
1267
+ decrypt_fido2_private_key(cipher_view: CipherView): string;
1268
+ }
1269
+ /**
1270
+ * A client for the crypto operations.
1271
+ */
1272
+ export class CryptoClient {
1273
+ private constructor();
258
1274
  free(): void;
259
1275
  /**
260
1276
  * Initialization method for the user crypto. Needs to be called before any other crypto
261
1277
  * operations.
262
- * @param {InitUserCryptoRequest} req
263
- * @returns {Promise<void>}
264
1278
  */
265
1279
  initialize_user_crypto(req: InitUserCryptoRequest): Promise<void>;
266
1280
  /**
267
1281
  * Initialization method for the organization crypto. Needs to be called after
268
1282
  * `initialize_user_crypto` but before any other crypto operations.
269
- * @param {InitOrgCryptoRequest} req
270
- * @returns {Promise<void>}
271
1283
  */
272
1284
  initialize_org_crypto(req: InitOrgCryptoRequest): Promise<void>;
1285
+ /**
1286
+ * Generates a new key pair and encrypts the private key with the provided user key.
1287
+ * Crypto initialization not required.
1288
+ */
1289
+ make_key_pair(user_key: string): MakeKeyPairResponse;
1290
+ /**
1291
+ * Verifies a user's asymmetric keys by decrypting the private key with the provided user
1292
+ * key. Returns if the private key is decryptable and if it is a valid matching key.
1293
+ * Crypto initialization not required.
1294
+ */
1295
+ verify_asymmetric_keys(request: VerifyAsymmetricKeysRequest): VerifyAsymmetricKeysResponse;
1296
+ /**
1297
+ * Makes a new signing key pair and signs the public key for the user
1298
+ */
1299
+ make_user_signing_keys_for_enrollment(): MakeUserSigningKeysResponse;
1300
+ /**
1301
+ * Creates a rotated set of account keys for the current state
1302
+ */
1303
+ get_v2_rotated_account_keys(user_key: string): RotateUserKeysResponse;
273
1304
  }
274
- export class ClientFolders {
1305
+ export class ExporterClient {
1306
+ private constructor();
275
1307
  free(): void;
1308
+ export_vault(folders: Folder[], ciphers: Cipher[], format: ExportFormat): string;
1309
+ export_organization_vault(
1310
+ collections: Collection[],
1311
+ ciphers: Cipher[],
1312
+ format: ExportFormat,
1313
+ ): string;
1314
+ /**
1315
+ * Credential Exchange Format (CXF)
1316
+ *
1317
+ * *Warning:* Expect this API to be unstable, and it will change in the future.
1318
+ *
1319
+ * For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
1320
+ * Ideally the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
1321
+ */
1322
+ export_cxf(account: Account, ciphers: Cipher[]): string;
276
1323
  /**
277
- * Decrypt folder
278
- * @param {Folder} folder
279
- * @returns {FolderView}
1324
+ * Credential Exchange Format (CXF)
1325
+ *
1326
+ * *Warning:* Expect this API to be unstable, and it will change in the future.
1327
+ *
1328
+ * For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
1329
+ * Ideally the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
280
1330
  */
1331
+ import_cxf(payload: string): Cipher[];
1332
+ }
1333
+ export class FoldersClient {
1334
+ private constructor();
1335
+ free(): void;
1336
+ encrypt(folder_view: FolderView): Folder;
281
1337
  decrypt(folder: Folder): FolderView;
1338
+ decrypt_list(folders: Folder[]): FolderView[];
1339
+ }
1340
+ export class GeneratorClient {
1341
+ private constructor();
1342
+ free(): void;
1343
+ /**
1344
+ * Generates a random password.
1345
+ *
1346
+ * The character sets and password length can be customized using the `input` parameter.
1347
+ *
1348
+ * # Examples
1349
+ *
1350
+ * ```
1351
+ * use bitwarden_core::Client;
1352
+ * use bitwarden_generators::{GeneratorClientsExt, PassphraseError, PasswordGeneratorRequest};
1353
+ *
1354
+ * async fn test() -> Result<(), PassphraseError> {
1355
+ * let input = PasswordGeneratorRequest {
1356
+ * lowercase: true,
1357
+ * uppercase: true,
1358
+ * numbers: true,
1359
+ * length: 20,
1360
+ * ..Default::default()
1361
+ * };
1362
+ * let password = Client::new(None).generator().password(input).unwrap();
1363
+ * println!("{}", password);
1364
+ * Ok(())
1365
+ * }
1366
+ * ```
1367
+ */
1368
+ password(input: PasswordGeneratorRequest): string;
1369
+ /**
1370
+ * Generates a random passphrase.
1371
+ * A passphrase is a combination of random words separated by a character.
1372
+ * An example of passphrase is `correct horse battery staple`.
1373
+ *
1374
+ * The number of words and their case, the word separator, and the inclusion of
1375
+ * a number in the passphrase can be customized using the `input` parameter.
1376
+ *
1377
+ * # Examples
1378
+ *
1379
+ * ```
1380
+ * use bitwarden_core::Client;
1381
+ * use bitwarden_generators::{GeneratorClientsExt, PassphraseError, PassphraseGeneratorRequest};
1382
+ *
1383
+ * async fn test() -> Result<(), PassphraseError> {
1384
+ * let input = PassphraseGeneratorRequest {
1385
+ * num_words: 4,
1386
+ * ..Default::default()
1387
+ * };
1388
+ * let passphrase = Client::new(None).generator().passphrase(input).unwrap();
1389
+ * println!("{}", passphrase);
1390
+ * Ok(())
1391
+ * }
1392
+ * ```
1393
+ */
1394
+ passphrase(input: PassphraseGeneratorRequest): string;
282
1395
  }
283
- export class ClientVault {
1396
+ export class IncomingMessage {
1397
+ free(): void;
1398
+ constructor(payload: Uint8Array, destination: Endpoint, source: Endpoint, topic?: string | null);
1399
+ /**
1400
+ * Try to parse the payload as JSON.
1401
+ * @returns The parsed JSON value, or undefined if the payload is not valid JSON.
1402
+ */
1403
+ parse_payload_as_json(): any;
1404
+ payload: Uint8Array;
1405
+ destination: Endpoint;
1406
+ source: Endpoint;
1407
+ get topic(): string | undefined;
1408
+ set topic(value: string | null | undefined);
1409
+ }
1410
+ /**
1411
+ * JavaScript wrapper around the IPC client. For more information, see the
1412
+ * [IpcClient] documentation.
1413
+ */
1414
+ export class IpcClient {
1415
+ free(): void;
1416
+ constructor(communication_provider: IpcCommunicationBackend);
1417
+ start(): Promise<void>;
1418
+ isRunning(): Promise<boolean>;
1419
+ send(message: OutgoingMessage): Promise<void>;
1420
+ subscribe(): Promise<IpcClientSubscription>;
1421
+ }
1422
+ /**
1423
+ * JavaScript wrapper around the IPC client subscription. For more information, see the
1424
+ * [IpcClientSubscription](crate::IpcClientSubscription) documentation.
1425
+ */
1426
+ export class IpcClientSubscription {
1427
+ private constructor();
284
1428
  free(): void;
1429
+ receive(abort_signal?: AbortSignal | null): Promise<IncomingMessage>;
1430
+ }
1431
+ /**
1432
+ * JavaScript implementation of the `CommunicationBackend` trait for IPC communication.
1433
+ */
1434
+ export class IpcCommunicationBackend {
1435
+ free(): void;
1436
+ /**
1437
+ * Creates a new instance of the JavaScript communication backend.
1438
+ */
1439
+ constructor(sender: IpcCommunicationBackendSender);
1440
+ /**
1441
+ * Used by JavaScript to provide an incoming message to the IPC framework.
1442
+ */
1443
+ receive(message: IncomingMessage): void;
1444
+ }
1445
+ export class OutgoingMessage {
1446
+ free(): void;
1447
+ constructor(payload: Uint8Array, destination: Endpoint, topic?: string | null);
1448
+ /**
1449
+ * Create a new message and encode the payload as JSON.
1450
+ */
1451
+ static new_json_payload(
1452
+ payload: any,
1453
+ destination: Endpoint,
1454
+ topic?: string | null,
1455
+ ): OutgoingMessage;
1456
+ payload: Uint8Array;
1457
+ destination: Endpoint;
1458
+ get topic(): string | undefined;
1459
+ set topic(value: string | null | undefined);
1460
+ }
1461
+ export class PlatformClient {
1462
+ private constructor();
1463
+ free(): void;
1464
+ state(): StateClient;
1465
+ }
1466
+ /**
1467
+ * This module represents a stopgap solution to provide access to primitive crypto functions for JS
1468
+ * clients. It is not intended to be used outside of the JS clients and this pattern should not be
1469
+ * proliferated. It is necessary because we want to use SDK crypto prior to the SDK being fully
1470
+ * responsible for state and keys.
1471
+ */
1472
+ export class PureCrypto {
1473
+ private constructor();
1474
+ free(): void;
1475
+ /**
1476
+ * DEPRECATED: Use `symmetric_decrypt_string` instead.
1477
+ * Cleanup ticket: <https://bitwarden.atlassian.net/browse/PM-21247>
1478
+ */
1479
+ static symmetric_decrypt(enc_string: string, key: Uint8Array): string;
1480
+ static symmetric_decrypt_string(enc_string: string, key: Uint8Array): string;
1481
+ static symmetric_decrypt_bytes(enc_string: string, key: Uint8Array): Uint8Array;
1482
+ /**
1483
+ * DEPRECATED: Use `symmetric_decrypt_filedata` instead.
1484
+ * Cleanup ticket: <https://bitwarden.atlassian.net/browse/PM-21247>
1485
+ */
1486
+ static symmetric_decrypt_array_buffer(enc_bytes: Uint8Array, key: Uint8Array): Uint8Array;
1487
+ static symmetric_decrypt_filedata(enc_bytes: Uint8Array, key: Uint8Array): Uint8Array;
1488
+ static symmetric_encrypt_string(plain: string, key: Uint8Array): string;
1489
+ /**
1490
+ * DEPRECATED: Only used by send keys
1491
+ */
1492
+ static symmetric_encrypt_bytes(plain: Uint8Array, key: Uint8Array): string;
1493
+ static symmetric_encrypt_filedata(plain: Uint8Array, key: Uint8Array): Uint8Array;
1494
+ static decrypt_user_key_with_master_password(
1495
+ encrypted_user_key: string,
1496
+ master_password: string,
1497
+ email: string,
1498
+ kdf: Kdf,
1499
+ ): Uint8Array;
1500
+ static encrypt_user_key_with_master_password(
1501
+ user_key: Uint8Array,
1502
+ master_password: string,
1503
+ email: string,
1504
+ kdf: Kdf,
1505
+ ): string;
1506
+ static make_user_key_aes256_cbc_hmac(): Uint8Array;
1507
+ static make_user_key_xchacha20_poly1305(): Uint8Array;
1508
+ /**
1509
+ * Wraps (encrypts) a symmetric key using a symmetric wrapping key, returning the wrapped key
1510
+ * as an EncString.
1511
+ */
1512
+ static wrap_symmetric_key(key_to_be_wrapped: Uint8Array, wrapping_key: Uint8Array): string;
1513
+ /**
1514
+ * Unwraps (decrypts) a wrapped symmetric key using a symmetric wrapping key, returning the
1515
+ * unwrapped key as a serialized byte array.
1516
+ */
1517
+ static unwrap_symmetric_key(wrapped_key: string, wrapping_key: Uint8Array): Uint8Array;
1518
+ /**
1519
+ * Wraps (encrypts) an SPKI DER encoded encapsulation (public) key using a symmetric wrapping
1520
+ * key. Note: Usually, a public key is - by definition - public, so this should not be
1521
+ * used. The specific use-case for this function is to enable rotateable key sets, where
1522
+ * the "public key" is not public, with the intent of preventing the server from being able
1523
+ * to overwrite the user key unlocked by the rotateable keyset.
1524
+ */
1525
+ static wrap_encapsulation_key(encapsulation_key: Uint8Array, wrapping_key: Uint8Array): string;
1526
+ /**
1527
+ * Unwraps (decrypts) a wrapped SPKI DER encoded encapsulation (public) key using a symmetric
1528
+ * wrapping key.
1529
+ */
1530
+ static unwrap_encapsulation_key(wrapped_key: string, wrapping_key: Uint8Array): Uint8Array;
1531
+ /**
1532
+ * Wraps (encrypts) a PKCS8 DER encoded decapsulation (private) key using a symmetric wrapping
1533
+ * key,
1534
+ */
1535
+ static wrap_decapsulation_key(decapsulation_key: Uint8Array, wrapping_key: Uint8Array): string;
1536
+ /**
1537
+ * Unwraps (decrypts) a wrapped PKCS8 DER encoded decapsulation (private) key using a symmetric
1538
+ * wrapping key.
1539
+ */
1540
+ static unwrap_decapsulation_key(wrapped_key: string, wrapping_key: Uint8Array): Uint8Array;
1541
+ /**
1542
+ * Encapsulates (encrypts) a symmetric key using an asymmetric encapsulation key (public key)
1543
+ * in SPKI format, returning the encapsulated key as a string. Note: This is unsigned, so
1544
+ * the sender's authenticity cannot be verified by the recipient.
1545
+ */
1546
+ static encapsulate_key_unsigned(shared_key: Uint8Array, encapsulation_key: Uint8Array): string;
1547
+ /**
1548
+ * Decapsulates (decrypts) a symmetric key using an decapsulation key (private key) in PKCS8
1549
+ * DER format. Note: This is unsigned, so the sender's authenticity cannot be verified by the
1550
+ * recipient.
1551
+ */
1552
+ static decapsulate_key_unsigned(
1553
+ encapsulated_key: string,
1554
+ decapsulation_key: Uint8Array,
1555
+ ): Uint8Array;
1556
+ /**
1557
+ * Given a wrapped signing key and the symmetric key it is wrapped with, this returns
1558
+ * the corresponding verifying key.
1559
+ */
1560
+ static verifying_key_for_signing_key(signing_key: string, wrapping_key: Uint8Array): Uint8Array;
1561
+ /**
1562
+ * Returns the algorithm used for the given verifying key.
1563
+ */
1564
+ static key_algorithm_for_verifying_key(verifying_key: Uint8Array): SignatureAlgorithm;
1565
+ /**
1566
+ * For a given signing identity (verifying key), this function verifies that the signing
1567
+ * identity claimed ownership of the public key. This is a one-sided claim and merely shows
1568
+ * that the signing identity has the intent to receive messages encrypted to the public
1569
+ * key.
1570
+ */
1571
+ static verify_and_unwrap_signed_public_key(
1572
+ signed_public_key: Uint8Array,
1573
+ verifying_key: Uint8Array,
1574
+ ): Uint8Array;
1575
+ }
1576
+ export class StateClient {
1577
+ private constructor();
1578
+ free(): void;
1579
+ register_cipher_repository(store: Repository<Cipher>): void;
1580
+ }
1581
+ export class TotpClient {
1582
+ private constructor();
1583
+ free(): void;
1584
+ /**
1585
+ * Generates a TOTP code from a provided key
1586
+ *
1587
+ * # Arguments
1588
+ * - `key` - Can be:
1589
+ * - A base32 encoded string
1590
+ * - OTP Auth URI
1591
+ * - Steam URI
1592
+ * - `time_ms` - Optional timestamp in milliseconds
1593
+ */
1594
+ generate_totp(key: string, time_ms?: number | null): TotpResponse;
1595
+ }
1596
+ export class VaultClient {
1597
+ private constructor();
1598
+ free(): void;
1599
+ /**
1600
+ * Attachment related operations.
1601
+ */
1602
+ attachments(): AttachmentsClient;
1603
+ /**
1604
+ * Cipher related operations.
1605
+ */
1606
+ ciphers(): CiphersClient;
1607
+ /**
1608
+ * Folder related operations.
1609
+ */
1610
+ folders(): FoldersClient;
285
1611
  /**
286
- * @returns {ClientFolders}
1612
+ * TOTP related operations.
287
1613
  */
288
- folders(): ClientFolders;
1614
+ totp(): TotpClient;
289
1615
  }