@bitwarden/sdk-internal 0.2.0-main.21 → 0.2.0-main.210

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