@bitwarden/sdk-internal 0.2.0-main.16 → 0.2.0-main.160

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,6 +82,24 @@ 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 {
16
104
  /**
17
105
  * The user\'s KDF parameters, as received from the prelogin request
@@ -31,6 +119,9 @@ export interface InitUserCryptoRequest {
31
119
  method: InitUserCryptoMethod;
32
120
  }
33
121
 
122
+ /**
123
+ * The crypto method used to initialize the user cryptographic state.
124
+ */
34
125
  export type InitUserCryptoMethod =
35
126
  | { password: { password: string; user_key: string } }
36
127
  | { decryptedKey: { decrypted_user_key: string } }
@@ -40,46 +131,73 @@ export type InitUserCryptoMethod =
40
131
  deviceKey: {
41
132
  device_key: string;
42
133
  protected_device_private_key: EncString;
43
- device_protected_user_key: AsymmetricEncString;
134
+ device_protected_user_key: UnsignedSharedKey;
44
135
  };
45
136
  }
46
137
  | { keyConnector: { master_key: string; user_key: string } };
47
138
 
139
+ /**
140
+ * Auth requests supports multiple initialization methods.
141
+ */
48
142
  export type AuthRequestMethod =
49
- | { userKey: { protected_user_key: AsymmetricEncString } }
50
- | { masterKey: { protected_master_key: AsymmetricEncString; auth_request_key: EncString } };
143
+ | { userKey: { protected_user_key: UnsignedSharedKey } }
144
+ | { masterKey: { protected_master_key: UnsignedSharedKey; auth_request_key: EncString } };
51
145
 
146
+ /**
147
+ * Represents the request to initialize the user\'s organizational cryptographic state.
148
+ */
52
149
  export interface InitOrgCryptoRequest {
53
150
  /**
54
151
  * The encryption keys for all the organizations the user is a part of
55
152
  */
56
- organizationKeys: Map<Uuid, AsymmetricEncString>;
153
+ organizationKeys: Map<Uuid, UnsignedSharedKey>;
57
154
  }
58
155
 
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";
80
- }
81
-
82
- export function isCoreError(error: any): error is CoreError;
156
+ /**
157
+ * Response from the `make_key_pair` function
158
+ */
159
+ export interface MakeKeyPairResponse {
160
+ /**
161
+ * The user\'s public key
162
+ */
163
+ userPublicKey: string;
164
+ /**
165
+ * User\'s private key, encrypted with the user key
166
+ */
167
+ userKeyEncryptedPrivateKey: EncString;
168
+ }
169
+
170
+ /**
171
+ * Request for `verify_asymmetric_keys`.
172
+ */
173
+ export interface VerifyAsymmetricKeysRequest {
174
+ /**
175
+ * The user\'s user key
176
+ */
177
+ userKey: string;
178
+ /**
179
+ * The user\'s public key
180
+ */
181
+ userPublicKey: string;
182
+ /**
183
+ * User\'s private key, encrypted with the user key
184
+ */
185
+ userKeyEncryptedPrivateKey: EncString;
186
+ }
187
+
188
+ /**
189
+ * Response for `verify_asymmetric_keys`.
190
+ */
191
+ export interface VerifyAsymmetricKeysResponse {
192
+ /**
193
+ * Whether the user\'s private key was decryptable by the user key.
194
+ */
195
+ privateKeyDecryptable: boolean;
196
+ /**
197
+ * Whether the user\'s private key was a valid RSA key and matched the public key provided.
198
+ */
199
+ validPrivateKey: boolean;
200
+ }
83
201
 
84
202
  export interface EncryptionSettingsError extends Error {
85
203
  name: "EncryptionSettingsError";
@@ -152,7 +270,7 @@ export interface ClientSettings {
152
270
  deviceType?: DeviceType;
153
271
  }
154
272
 
155
- export type AsymmetricEncString = string;
273
+ export type UnsignedSharedKey = string;
156
274
 
157
275
  export type EncString = string;
158
276
 
@@ -166,14 +284,202 @@ export type Kdf =
166
284
  | { pBKDF2: { iterations: NonZeroU32 } }
167
285
  | { argon2id: { iterations: NonZeroU32; memory: NonZeroU32; parallelism: NonZeroU32 } };
168
286
 
169
- export interface GenerateSshKeyResult {
170
- private_key: string;
171
- public_key: string;
172
- key_fingerprint: string;
287
+ export interface CryptoError extends Error {
288
+ name: "CryptoError";
289
+ variant:
290
+ | "InvalidKey"
291
+ | "InvalidMac"
292
+ | "MacNotProvided"
293
+ | "KeyDecrypt"
294
+ | "InvalidKeyLen"
295
+ | "InvalidUtf8String"
296
+ | "MissingKey"
297
+ | "MissingField"
298
+ | "MissingKeyId"
299
+ | "ReadOnlyKeyStore"
300
+ | "InsufficientKdfParameters"
301
+ | "EncString"
302
+ | "RsaError"
303
+ | "FingerprintError"
304
+ | "ArgonError"
305
+ | "ZeroNumber"
306
+ | "OperationNotSupported"
307
+ | "WrongKeyType";
308
+ }
309
+
310
+ export function isCryptoError(error: any): error is CryptoError;
311
+
312
+ /**
313
+ * Temporary struct to hold metadata related to current account
314
+ *
315
+ * Eventually the SDK itself should have this state and we get rid of this struct.
316
+ */
317
+ export interface Account {
318
+ id: Uuid;
319
+ email: string;
320
+ name: string | undefined;
321
+ }
322
+
323
+ export type ExportFormat = "Csv" | "Json" | { EncryptedJson: { password: string } };
324
+
325
+ export interface ExportError extends Error {
326
+ name: "ExportError";
327
+ variant:
328
+ | "MissingField"
329
+ | "NotAuthenticated"
330
+ | "VaultLocked"
331
+ | "Csv"
332
+ | "CxfError"
333
+ | "Json"
334
+ | "EncryptedJsonError"
335
+ | "BitwardenCryptoError"
336
+ | "CipherError";
337
+ }
338
+
339
+ export function isExportError(error: any): error is ExportError;
340
+
341
+ export type UsernameGeneratorRequest =
342
+ | { word: { capitalize: boolean; include_number: boolean } }
343
+ | { subaddress: { type: AppendType; email: string } }
344
+ | { catchall: { type: AppendType; domain: string } }
345
+ | { forwarded: { service: ForwarderServiceType; website: string | undefined } };
346
+
347
+ export interface UsernameError extends Error {
348
+ name: "UsernameError";
349
+ variant: "InvalidApiKey" | "Unknown" | "ResponseContent" | "Reqwest";
350
+ }
351
+
352
+ export function isUsernameError(error: any): error is UsernameError;
353
+
354
+ /**
355
+ * Password generator request options.
356
+ */
357
+ export interface PasswordGeneratorRequest {
358
+ /**
359
+ * Include lowercase characters (a-z).
360
+ */
361
+ lowercase: boolean;
362
+ /**
363
+ * Include uppercase characters (A-Z).
364
+ */
365
+ uppercase: boolean;
366
+ /**
367
+ * Include numbers (0-9).
368
+ */
369
+ numbers: boolean;
370
+ /**
371
+ * Include special characters: ! @ # $ % ^ & *
372
+ */
373
+ special: boolean;
374
+ /**
375
+ * The length of the generated password.
376
+ * Note that the password length must be greater than the sum of all the minimums.
377
+ */
378
+ length: number;
379
+ /**
380
+ * When set to true, the generated password will not contain ambiguous characters.
381
+ * The ambiguous characters are: I, O, l, 0, 1
382
+ */
383
+ avoidAmbiguous: boolean;
384
+ /**
385
+ * The minimum number of lowercase characters in the generated password.
386
+ * When set, the value must be between 1 and 9. This value is ignored if lowercase is false.
387
+ */
388
+ minLowercase: number | undefined;
389
+ /**
390
+ * The minimum number of uppercase characters in the generated password.
391
+ * When set, the value must be between 1 and 9. This value is ignored if uppercase is false.
392
+ */
393
+ minUppercase: number | undefined;
394
+ /**
395
+ * The minimum number of numbers in the generated password.
396
+ * When set, the value must be between 1 and 9. This value is ignored if numbers is false.
397
+ */
398
+ minNumber: number | undefined;
399
+ /**
400
+ * The minimum number of special characters in the generated password.
401
+ * When set, the value must be between 1 and 9. This value is ignored if special is false.
402
+ */
403
+ minSpecial: number | undefined;
404
+ }
405
+
406
+ export interface PasswordError extends Error {
407
+ name: "PasswordError";
408
+ variant: "NoCharacterSetEnabled" | "InvalidLength";
409
+ }
410
+
411
+ export function isPasswordError(error: any): error is PasswordError;
412
+
413
+ /**
414
+ * Passphrase generator request options.
415
+ */
416
+ export interface PassphraseGeneratorRequest {
417
+ /**
418
+ * Number of words in the generated passphrase.
419
+ * This value must be between 3 and 20.
420
+ */
421
+ numWords: number;
422
+ /**
423
+ * Character separator between words in the generated passphrase. The value cannot be empty.
424
+ */
425
+ wordSeparator: string;
426
+ /**
427
+ * When set to true, capitalize the first letter of each word in the generated passphrase.
428
+ */
429
+ capitalize: boolean;
430
+ /**
431
+ * When set to true, include a number at the end of one of the words in the generated
432
+ * passphrase.
433
+ */
434
+ includeNumber: boolean;
435
+ }
436
+
437
+ export interface PassphraseError extends Error {
438
+ name: "PassphraseError";
439
+ variant: "InvalidNumWords";
440
+ }
441
+
442
+ export function isPassphraseError(error: any): error is PassphraseError;
443
+
444
+ export type Endpoint =
445
+ | { Web: { id: number } }
446
+ | "BrowserForeground"
447
+ | "BrowserBackground"
448
+ | "DesktopRenderer"
449
+ | "DesktopMain";
450
+
451
+ export interface IpcCommunicationBackendSender {
452
+ send(message: OutgoingMessage): Promise<void>;
453
+ }
454
+
455
+ export interface ChannelError extends Error {
456
+ name: "ChannelError";
457
+ }
458
+
459
+ export function isChannelError(error: any): error is ChannelError;
460
+
461
+ export interface DeserializeError extends Error {
462
+ name: "DeserializeError";
173
463
  }
174
464
 
465
+ export function isDeserializeError(error: any): error is DeserializeError;
466
+
175
467
  export type KeyAlgorithm = "Ed25519" | "Rsa3072" | "Rsa4096";
176
468
 
469
+ export interface SshKeyExportError extends Error {
470
+ name: "SshKeyExportError";
471
+ variant: "KeyConversionError";
472
+ }
473
+
474
+ export function isSshKeyExportError(error: any): error is SshKeyExportError;
475
+
476
+ export interface SshKeyImportError extends Error {
477
+ name: "SshKeyImportError";
478
+ variant: "ParsingError" | "PasswordRequired" | "WrongPassword" | "UnsupportedKeyType";
479
+ }
480
+
481
+ export function isSshKeyImportError(error: any): error is SshKeyImportError;
482
+
177
483
  export interface KeyGenerationError extends Error {
178
484
  name: "KeyGenerationError";
179
485
  variant: "KeyGenerationError" | "KeyConversionError";
@@ -181,6 +487,226 @@ export interface KeyGenerationError extends Error {
181
487
 
182
488
  export function isKeyGenerationError(error: any): error is KeyGenerationError;
183
489
 
490
+ export interface Cipher {
491
+ id: Uuid | undefined;
492
+ organizationId: Uuid | undefined;
493
+ folderId: Uuid | undefined;
494
+ collectionIds: Uuid[];
495
+ /**
496
+ * More recent ciphers uses individual encryption keys to encrypt the other fields of the
497
+ * Cipher.
498
+ */
499
+ key: EncString | undefined;
500
+ name: EncString;
501
+ notes: EncString | undefined;
502
+ type: CipherType;
503
+ login: Login | undefined;
504
+ identity: Identity | undefined;
505
+ card: Card | undefined;
506
+ secureNote: SecureNote | undefined;
507
+ sshKey: SshKey | undefined;
508
+ favorite: boolean;
509
+ reprompt: CipherRepromptType;
510
+ organizationUseTotp: boolean;
511
+ edit: boolean;
512
+ permissions: CipherPermissions | undefined;
513
+ viewPassword: boolean;
514
+ localData: LocalData | undefined;
515
+ attachments: Attachment[] | undefined;
516
+ fields: Field[] | undefined;
517
+ passwordHistory: PasswordHistory[] | undefined;
518
+ creationDate: DateTime<Utc>;
519
+ deletedDate: DateTime<Utc> | undefined;
520
+ revisionDate: DateTime<Utc>;
521
+ }
522
+
523
+ export interface CipherView {
524
+ id: Uuid | undefined;
525
+ organizationId: Uuid | undefined;
526
+ folderId: Uuid | undefined;
527
+ collectionIds: Uuid[];
528
+ /**
529
+ * Temporary, required to support re-encrypting existing items.
530
+ */
531
+ key: EncString | undefined;
532
+ name: string;
533
+ notes: string | undefined;
534
+ type: CipherType;
535
+ login: LoginView | undefined;
536
+ identity: IdentityView | undefined;
537
+ card: CardView | undefined;
538
+ secureNote: SecureNoteView | undefined;
539
+ sshKey: SshKeyView | undefined;
540
+ favorite: boolean;
541
+ reprompt: CipherRepromptType;
542
+ organizationUseTotp: boolean;
543
+ edit: boolean;
544
+ permissions: CipherPermissions | undefined;
545
+ viewPassword: boolean;
546
+ localData: LocalDataView | undefined;
547
+ attachments: AttachmentView[] | undefined;
548
+ fields: FieldView[] | undefined;
549
+ passwordHistory: PasswordHistoryView[] | undefined;
550
+ creationDate: DateTime<Utc>;
551
+ deletedDate: DateTime<Utc> | undefined;
552
+ revisionDate: DateTime<Utc>;
553
+ }
554
+
555
+ export type CipherListViewType =
556
+ | { login: LoginListView }
557
+ | "secureNote"
558
+ | "card"
559
+ | "identity"
560
+ | "sshKey";
561
+
562
+ export interface CipherListView {
563
+ id: Uuid | undefined;
564
+ organizationId: Uuid | undefined;
565
+ folderId: Uuid | undefined;
566
+ collectionIds: Uuid[];
567
+ /**
568
+ * Temporary, required to support calculating TOTP from CipherListView.
569
+ */
570
+ key: EncString | undefined;
571
+ name: string;
572
+ subtitle: string;
573
+ type: CipherListViewType;
574
+ favorite: boolean;
575
+ reprompt: CipherRepromptType;
576
+ organizationUseTotp: boolean;
577
+ edit: boolean;
578
+ permissions: CipherPermissions | undefined;
579
+ viewPassword: boolean;
580
+ /**
581
+ * The number of attachments
582
+ */
583
+ attachments: number;
584
+ creationDate: DateTime<Utc>;
585
+ deletedDate: DateTime<Utc> | undefined;
586
+ revisionDate: DateTime<Utc>;
587
+ }
588
+
589
+ export interface Field {
590
+ name: EncString | undefined;
591
+ value: EncString | undefined;
592
+ type: FieldType;
593
+ linkedId: LinkedIdType | undefined;
594
+ }
595
+
596
+ export interface FieldView {
597
+ name: string | undefined;
598
+ value: string | undefined;
599
+ type: FieldType;
600
+ linkedId: LinkedIdType | undefined;
601
+ }
602
+
603
+ export type LinkedIdType = LoginLinkedIdType | CardLinkedIdType | IdentityLinkedIdType;
604
+
605
+ export interface LoginUri {
606
+ uri: EncString | undefined;
607
+ match: UriMatchType | undefined;
608
+ uriChecksum: EncString | undefined;
609
+ }
610
+
611
+ export interface LoginUriView {
612
+ uri: string | undefined;
613
+ match: UriMatchType | undefined;
614
+ uriChecksum: string | undefined;
615
+ }
616
+
617
+ export interface Fido2Credential {
618
+ credentialId: EncString;
619
+ keyType: EncString;
620
+ keyAlgorithm: EncString;
621
+ keyCurve: EncString;
622
+ keyValue: EncString;
623
+ rpId: EncString;
624
+ userHandle: EncString | undefined;
625
+ userName: EncString | undefined;
626
+ counter: EncString;
627
+ rpName: EncString | undefined;
628
+ userDisplayName: EncString | undefined;
629
+ discoverable: EncString;
630
+ creationDate: DateTime<Utc>;
631
+ }
632
+
633
+ export interface Fido2CredentialListView {
634
+ credentialId: string;
635
+ rpId: string;
636
+ userHandle: string | undefined;
637
+ userName: string | undefined;
638
+ userDisplayName: string | undefined;
639
+ }
640
+
641
+ export interface Fido2CredentialView {
642
+ credentialId: string;
643
+ keyType: string;
644
+ keyAlgorithm: string;
645
+ keyCurve: string;
646
+ keyValue: EncString;
647
+ rpId: string;
648
+ userHandle: string | undefined;
649
+ userName: string | undefined;
650
+ counter: string;
651
+ rpName: string | undefined;
652
+ userDisplayName: string | undefined;
653
+ discoverable: string;
654
+ creationDate: DateTime<Utc>;
655
+ }
656
+
657
+ export interface Fido2CredentialNewView {
658
+ credentialId: string;
659
+ keyType: string;
660
+ keyAlgorithm: string;
661
+ keyCurve: string;
662
+ rpId: string;
663
+ userHandle: string | undefined;
664
+ userName: string | undefined;
665
+ counter: string;
666
+ rpName: string | undefined;
667
+ userDisplayName: string | undefined;
668
+ creationDate: DateTime<Utc>;
669
+ }
670
+
671
+ export interface Login {
672
+ username: EncString | undefined;
673
+ password: EncString | undefined;
674
+ passwordRevisionDate: DateTime<Utc> | undefined;
675
+ uris: LoginUri[] | undefined;
676
+ totp: EncString | undefined;
677
+ autofillOnPageLoad: boolean | undefined;
678
+ fido2Credentials: Fido2Credential[] | undefined;
679
+ }
680
+
681
+ export interface LoginView {
682
+ username: string | undefined;
683
+ password: string | undefined;
684
+ passwordRevisionDate: DateTime<Utc> | undefined;
685
+ uris: LoginUriView[] | undefined;
686
+ totp: string | undefined;
687
+ autofillOnPageLoad: boolean | undefined;
688
+ fido2Credentials: Fido2Credential[] | undefined;
689
+ }
690
+
691
+ export interface LoginListView {
692
+ fido2Credentials: Fido2CredentialListView[] | undefined;
693
+ hasFido2: boolean;
694
+ username: string | undefined;
695
+ /**
696
+ * The TOTP key is not decrypted. Useable as is with [`crate::generate_totp_cipher_view`].
697
+ */
698
+ totp: EncString | undefined;
699
+ uris: LoginUriView[] | undefined;
700
+ }
701
+
702
+ export interface SecureNote {
703
+ type: SecureNoteType;
704
+ }
705
+
706
+ export interface SecureNoteView {
707
+ type: SecureNoteType;
708
+ }
709
+
184
710
  export interface Folder {
185
711
  id: Uuid | undefined;
186
712
  name: EncString;
@@ -193,11 +719,204 @@ export interface FolderView {
193
719
  revisionDate: DateTime<Utc>;
194
720
  }
195
721
 
196
- export interface TestError extends Error {
197
- name: "TestError";
722
+ export interface DecryptError extends Error {
723
+ name: "DecryptError";
724
+ variant: "Crypto" | "VaultLocked";
198
725
  }
199
726
 
200
- export function isTestError(error: any): error is TestError;
727
+ export function isDecryptError(error: any): error is DecryptError;
728
+
729
+ export interface EncryptError extends Error {
730
+ name: "EncryptError";
731
+ variant: "Crypto" | "VaultLocked";
732
+ }
733
+
734
+ export function isEncryptError(error: any): error is EncryptError;
735
+
736
+ export interface TotpResponse {
737
+ /**
738
+ * Generated TOTP code
739
+ */
740
+ code: string;
741
+ /**
742
+ * Time period
743
+ */
744
+ period: number;
745
+ }
746
+
747
+ export interface TotpError extends Error {
748
+ name: "TotpError";
749
+ variant: "InvalidOtpauth" | "MissingSecret" | "CryptoError" | "VaultLocked";
750
+ }
751
+
752
+ export function isTotpError(error: any): error is TotpError;
753
+
754
+ export interface PasswordHistoryView {
755
+ password: string;
756
+ lastUsedDate: DateTime<Utc>;
757
+ }
758
+
759
+ export interface PasswordHistory {
760
+ password: EncString;
761
+ lastUsedDate: DateTime<Utc>;
762
+ }
763
+
764
+ export interface Collection {
765
+ id: Uuid | undefined;
766
+ organizationId: Uuid;
767
+ name: EncString;
768
+ externalId: string | undefined;
769
+ hidePasswords: boolean;
770
+ readOnly: boolean;
771
+ manage: boolean;
772
+ }
773
+
774
+ export interface SshKeyView {
775
+ /**
776
+ * SSH private key (ed25519/rsa) in unencrypted openssh private key format [OpenSSH private key](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key)
777
+ */
778
+ privateKey: string;
779
+ /**
780
+ * SSH public key (ed25519/rsa) according to [RFC4253](https://datatracker.ietf.org/doc/html/rfc4253#section-6.6)
781
+ */
782
+ publicKey: string;
783
+ /**
784
+ * SSH fingerprint using SHA256 in the format: `SHA256:BASE64_ENCODED_FINGERPRINT`
785
+ */
786
+ fingerprint: string;
787
+ }
788
+
789
+ export interface SshKey {
790
+ /**
791
+ * SSH private key (ed25519/rsa) in unencrypted openssh private key format [OpenSSH private key](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key)
792
+ */
793
+ privateKey: EncString;
794
+ /**
795
+ * SSH public key (ed25519/rsa) according to [RFC4253](https://datatracker.ietf.org/doc/html/rfc4253#section-6.6)
796
+ */
797
+ publicKey: EncString;
798
+ /**
799
+ * SSH fingerprint using SHA256 in the format: `SHA256:BASE64_ENCODED_FINGERPRINT`
800
+ */
801
+ fingerprint: EncString;
802
+ }
803
+
804
+ export interface LocalDataView {
805
+ lastUsedDate: DateTime<Utc> | undefined;
806
+ lastLaunched: DateTime<Utc> | undefined;
807
+ }
808
+
809
+ export interface LocalData {
810
+ lastUsedDate: DateTime<Utc> | undefined;
811
+ lastLaunched: DateTime<Utc> | undefined;
812
+ }
813
+
814
+ export interface IdentityView {
815
+ title: string | undefined;
816
+ firstName: string | undefined;
817
+ middleName: string | undefined;
818
+ lastName: string | undefined;
819
+ address1: string | undefined;
820
+ address2: string | undefined;
821
+ address3: string | undefined;
822
+ city: string | undefined;
823
+ state: string | undefined;
824
+ postalCode: string | undefined;
825
+ country: string | undefined;
826
+ company: string | undefined;
827
+ email: string | undefined;
828
+ phone: string | undefined;
829
+ ssn: string | undefined;
830
+ username: string | undefined;
831
+ passportNumber: string | undefined;
832
+ licenseNumber: string | undefined;
833
+ }
834
+
835
+ export interface Identity {
836
+ title: EncString | undefined;
837
+ firstName: EncString | undefined;
838
+ middleName: EncString | undefined;
839
+ lastName: EncString | undefined;
840
+ address1: EncString | undefined;
841
+ address2: EncString | undefined;
842
+ address3: EncString | undefined;
843
+ city: EncString | undefined;
844
+ state: EncString | undefined;
845
+ postalCode: EncString | undefined;
846
+ country: EncString | undefined;
847
+ company: EncString | undefined;
848
+ email: EncString | undefined;
849
+ phone: EncString | undefined;
850
+ ssn: EncString | undefined;
851
+ username: EncString | undefined;
852
+ passportNumber: EncString | undefined;
853
+ licenseNumber: EncString | undefined;
854
+ }
855
+
856
+ export interface CipherPermissions {
857
+ delete: boolean;
858
+ restore: boolean;
859
+ }
860
+
861
+ export interface CipherError extends Error {
862
+ name: "CipherError";
863
+ variant: "MissingFieldError" | "VaultLocked" | "CryptoError" | "AttachmentsWithoutKeys";
864
+ }
865
+
866
+ export function isCipherError(error: any): error is CipherError;
867
+
868
+ export interface CardView {
869
+ cardholderName: string | undefined;
870
+ expMonth: string | undefined;
871
+ expYear: string | undefined;
872
+ code: string | undefined;
873
+ brand: string | undefined;
874
+ number: string | undefined;
875
+ }
876
+
877
+ export interface Card {
878
+ cardholderName: EncString | undefined;
879
+ expMonth: EncString | undefined;
880
+ expYear: EncString | undefined;
881
+ code: EncString | undefined;
882
+ brand: EncString | undefined;
883
+ number: EncString | undefined;
884
+ }
885
+
886
+ export interface DecryptFileError extends Error {
887
+ name: "DecryptFileError";
888
+ variant: "Decrypt" | "Io";
889
+ }
890
+
891
+ export function isDecryptFileError(error: any): error is DecryptFileError;
892
+
893
+ export interface EncryptFileError extends Error {
894
+ name: "EncryptFileError";
895
+ variant: "Encrypt" | "Io";
896
+ }
897
+
898
+ export function isEncryptFileError(error: any): error is EncryptFileError;
899
+
900
+ export interface AttachmentView {
901
+ id: string | undefined;
902
+ url: string | undefined;
903
+ size: string | undefined;
904
+ sizeName: string | undefined;
905
+ fileName: string | undefined;
906
+ key: EncString | undefined;
907
+ }
908
+
909
+ export interface Attachment {
910
+ id: string | undefined;
911
+ url: string | undefined;
912
+ size: string | undefined;
913
+ /**
914
+ * Readable size, ex: \"4.2 KB\" or \"1.43 GB\
915
+ */
916
+ sizeName: string | undefined;
917
+ fileName: EncString | undefined;
918
+ key: EncString | undefined;
919
+ }
201
920
 
202
921
  export type Uuid = string;
203
922
 
@@ -217,73 +936,325 @@ export type Utc = unknown;
217
936
  */
218
937
  export type NonZeroU32 = number;
219
938
 
220
- export class BitwardenClient {
939
+ export interface TestError extends Error {
940
+ name: "TestError";
941
+ }
942
+
943
+ export function isTestError(error: any): error is TestError;
944
+
945
+ export class AttachmentsClient {
946
+ private constructor();
221
947
  free(): void;
222
948
  /**
223
- * @param {ClientSettings | undefined} [settings]
224
- * @param {LogLevel | undefined} [log_level]
949
+ * Decrypts an attachment's encrypted content
225
950
  */
226
- constructor(settings?: ClientSettings, log_level?: LogLevel);
951
+ decrypt_buffer(
952
+ cipher: Cipher,
953
+ attachment: AttachmentView,
954
+ encrypted_buffer: Uint8Array,
955
+ ): Uint8Array;
956
+ }
957
+ export class BitwardenClient {
958
+ free(): void;
959
+ constructor(settings?: ClientSettings | null);
227
960
  /**
228
961
  * Test method, echoes back the input
229
- * @param {string} msg
230
- * @returns {string}
231
962
  */
232
963
  echo(msg: string): string;
964
+ version(): string;
965
+ throw(msg: string): void;
233
966
  /**
234
- * @returns {string}
967
+ * Test method, calls http endpoint
235
968
  */
236
- version(): string;
969
+ http_get(url: string): Promise<string>;
970
+ crypto(): CryptoClient;
971
+ vault(): VaultClient;
237
972
  /**
238
- * @param {string} msg
239
- * @returns {Promise<void>}
973
+ * Constructs a specific client for generating passwords and passphrases
240
974
  */
241
- throw(msg: string): Promise<void>;
975
+ generator(): GeneratorClient;
976
+ exporters(): ExporterClient;
977
+ }
978
+ export class CiphersClient {
979
+ private constructor();
980
+ free(): void;
242
981
  /**
243
- * Test method, calls http endpoint
244
- * @param {string} url
245
- * @returns {Promise<string>}
982
+ * Encrypt cipher
983
+ *
984
+ * # Arguments
985
+ * - `cipher_view` - The decrypted cipher to encrypt
986
+ *
987
+ * # Returns
988
+ * - `Ok(Cipher)` containing the encrypted cipher
989
+ * - `Err(EncryptError)` if encryption fails
246
990
  */
247
- http_get(url: string): Promise<string>;
991
+ encrypt(cipher_view: CipherView): Cipher;
248
992
  /**
249
- * @returns {ClientCrypto}
993
+ * Decrypt cipher
994
+ *
995
+ * # Arguments
996
+ * - `cipher` - The encrypted cipher to decrypt
997
+ *
998
+ * # Returns
999
+ * - `Ok(CipherView)` containing the decrypted cipher
1000
+ * - `Err(DecryptError)` if decryption fails
250
1001
  */
251
- crypto(): ClientCrypto;
1002
+ decrypt(cipher: Cipher): CipherView;
252
1003
  /**
253
- * @returns {ClientVault}
1004
+ * Decrypt list of ciphers
1005
+ *
1006
+ * # Arguments
1007
+ * - `ciphers` - The list of encrypted ciphers to decrypt
1008
+ *
1009
+ * # Returns
1010
+ * - `Ok(Vec<CipherListView>)` containing the decrypted ciphers
1011
+ * - `Err(DecryptError)` if decryption fails
254
1012
  */
255
- vault(): ClientVault;
1013
+ decrypt_list(ciphers: Cipher[]): CipherListView[];
1014
+ /**
1015
+ * Decrypt FIDO2 credentials
1016
+ *
1017
+ * # Arguments
1018
+ * - `cipher_view` - Cipher to encrypt containing the FIDO2 credential
1019
+ *
1020
+ * # Returns
1021
+ * - `Ok(Vec<Fido2CredentialView>)` containing the decrypted FIDO2 credentials
1022
+ * - `Err(DecryptError)` if decryption fails
1023
+ */
1024
+ decrypt_fido2_credentials(cipher_view: CipherView): Fido2CredentialView[];
1025
+ /**
1026
+ * Decrypt key
1027
+ *
1028
+ * This method is a temporary solution to allow typescript client access to decrypted key
1029
+ * values, particularly for FIDO2 credentials.
1030
+ *
1031
+ * # Arguments
1032
+ * - `cipher_view` - Decrypted cipher containing the key
1033
+ *
1034
+ * # Returns
1035
+ * - `Ok(String)` containing the decrypted key
1036
+ * - `Err(CipherError)`
1037
+ */
1038
+ decrypt_fido2_private_key(cipher_view: CipherView): string;
256
1039
  }
257
- export class ClientCrypto {
1040
+ export class CryptoClient {
1041
+ private constructor();
258
1042
  free(): void;
259
1043
  /**
260
1044
  * Initialization method for the user crypto. Needs to be called before any other crypto
261
1045
  * operations.
262
- * @param {InitUserCryptoRequest} req
263
- * @returns {Promise<void>}
264
1046
  */
265
1047
  initialize_user_crypto(req: InitUserCryptoRequest): Promise<void>;
266
1048
  /**
267
1049
  * Initialization method for the organization crypto. Needs to be called after
268
1050
  * `initialize_user_crypto` but before any other crypto operations.
269
- * @param {InitOrgCryptoRequest} req
270
- * @returns {Promise<void>}
271
1051
  */
272
1052
  initialize_org_crypto(req: InitOrgCryptoRequest): Promise<void>;
1053
+ /**
1054
+ * Generates a new key pair and encrypts the private key with the provided user key.
1055
+ * Crypto initialization not required.
1056
+ */
1057
+ make_key_pair(user_key: string): MakeKeyPairResponse;
1058
+ /**
1059
+ * Verifies a user's asymmetric keys by decrypting the private key with the provided user
1060
+ * key. Returns if the private key is decryptable and if it is a valid matching key.
1061
+ * Crypto initialization not required.
1062
+ */
1063
+ verify_asymmetric_keys(request: VerifyAsymmetricKeysRequest): VerifyAsymmetricKeysResponse;
1064
+ }
1065
+ export class ExporterClient {
1066
+ private constructor();
1067
+ free(): void;
1068
+ export_vault(folders: Folder[], ciphers: Cipher[], format: ExportFormat): string;
1069
+ export_organization_vault(
1070
+ collections: Collection[],
1071
+ ciphers: Cipher[],
1072
+ format: ExportFormat,
1073
+ ): string;
1074
+ /**
1075
+ * Credential Exchange Format (CXF)
1076
+ *
1077
+ * *Warning:* Expect this API to be unstable, and it will change in the future.
1078
+ *
1079
+ * For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
1080
+ * Ideally the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
1081
+ */
1082
+ export_cxf(account: Account, ciphers: Cipher[]): string;
1083
+ /**
1084
+ * Credential Exchange Format (CXF)
1085
+ *
1086
+ * *Warning:* Expect this API to be unstable, and it will change in the future.
1087
+ *
1088
+ * For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
1089
+ * Ideally the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
1090
+ */
1091
+ import_cxf(payload: string): Cipher[];
273
1092
  }
274
- export class ClientFolders {
1093
+ export class FoldersClient {
1094
+ private constructor();
275
1095
  free(): void;
276
1096
  /**
277
1097
  * Decrypt folder
278
- * @param {Folder} folder
279
- * @returns {FolderView}
280
1098
  */
281
1099
  decrypt(folder: Folder): FolderView;
282
1100
  }
283
- export class ClientVault {
1101
+ export class GeneratorClient {
1102
+ private constructor();
1103
+ free(): void;
1104
+ /**
1105
+ * Generates a random password.
1106
+ *
1107
+ * The character sets and password length can be customized using the `input` parameter.
1108
+ *
1109
+ * # Examples
1110
+ *
1111
+ * ```
1112
+ * use bitwarden_core::Client;
1113
+ * use bitwarden_generators::{GeneratorClientsExt, PassphraseError, PasswordGeneratorRequest};
1114
+ *
1115
+ * async fn test() -> Result<(), PassphraseError> {
1116
+ * let input = PasswordGeneratorRequest {
1117
+ * lowercase: true,
1118
+ * uppercase: true,
1119
+ * numbers: true,
1120
+ * length: 20,
1121
+ * ..Default::default()
1122
+ * };
1123
+ * let password = Client::new(None).generator().password(input).unwrap();
1124
+ * println!("{}", password);
1125
+ * Ok(())
1126
+ * }
1127
+ * ```
1128
+ */
1129
+ password(input: PasswordGeneratorRequest): string;
1130
+ /**
1131
+ * Generates a random passphrase.
1132
+ * A passphrase is a combination of random words separated by a character.
1133
+ * An example of passphrase is `correct horse battery staple`.
1134
+ *
1135
+ * The number of words and their case, the word separator, and the inclusion of
1136
+ * a number in the passphrase can be customized using the `input` parameter.
1137
+ *
1138
+ * # Examples
1139
+ *
1140
+ * ```
1141
+ * use bitwarden_core::Client;
1142
+ * use bitwarden_generators::{GeneratorClientsExt, PassphraseError, PassphraseGeneratorRequest};
1143
+ *
1144
+ * async fn test() -> Result<(), PassphraseError> {
1145
+ * let input = PassphraseGeneratorRequest {
1146
+ * num_words: 4,
1147
+ * ..Default::default()
1148
+ * };
1149
+ * let passphrase = Client::new(None).generator().passphrase(input).unwrap();
1150
+ * println!("{}", passphrase);
1151
+ * Ok(())
1152
+ * }
1153
+ * ```
1154
+ */
1155
+ passphrase(input: PassphraseGeneratorRequest): string;
1156
+ }
1157
+ export class IncomingMessage {
284
1158
  free(): void;
1159
+ constructor(payload: Uint8Array, destination: Endpoint, source: Endpoint, topic?: string | null);
285
1160
  /**
286
- * @returns {ClientFolders}
1161
+ * Try to parse the payload as JSON.
1162
+ * @returns The parsed JSON value, or undefined if the payload is not valid JSON.
287
1163
  */
288
- folders(): ClientFolders;
1164
+ parse_payload_as_json(): any;
1165
+ payload: Uint8Array;
1166
+ destination: Endpoint;
1167
+ source: Endpoint;
1168
+ get topic(): string | undefined;
1169
+ set topic(value: string | null | undefined);
1170
+ }
1171
+ export class IpcClient {
1172
+ free(): void;
1173
+ constructor(communication_provider: IpcCommunicationBackend);
1174
+ send(message: OutgoingMessage): Promise<void>;
1175
+ subscribe(): Promise<IpcClientSubscription>;
1176
+ }
1177
+ export class IpcClientSubscription {
1178
+ private constructor();
1179
+ free(): void;
1180
+ receive(): Promise<IncomingMessage>;
1181
+ }
1182
+ export class IpcCommunicationBackend {
1183
+ free(): void;
1184
+ constructor(sender: IpcCommunicationBackendSender);
1185
+ /**
1186
+ * JavaScript function to provide a received message to the backend/IPC framework.
1187
+ */
1188
+ deliver_message(message: IncomingMessage): void;
1189
+ }
1190
+ export class OutgoingMessage {
1191
+ free(): void;
1192
+ constructor(payload: Uint8Array, destination: Endpoint, topic?: string | null);
1193
+ /**
1194
+ * Create a new message and encode the payload as JSON.
1195
+ */
1196
+ static new_json_payload(
1197
+ payload: any,
1198
+ destination: Endpoint,
1199
+ topic?: string | null,
1200
+ ): OutgoingMessage;
1201
+ payload: Uint8Array;
1202
+ destination: Endpoint;
1203
+ get topic(): string | undefined;
1204
+ set topic(value: string | null | undefined);
1205
+ }
1206
+ /**
1207
+ * This module represents a stopgap solution to provide access to primitive crypto functions for JS
1208
+ * clients. It is not intended to be used outside of the JS clients and this pattern should not be
1209
+ * proliferated. It is necessary because we want to use SDK crypto prior to the SDK being fully
1210
+ * responsible for state and keys.
1211
+ */
1212
+ export class PureCrypto {
1213
+ private constructor();
1214
+ free(): void;
1215
+ static symmetric_decrypt(enc_string: string, key: Uint8Array): string;
1216
+ static symmetric_decrypt_to_bytes(enc_string: string, key: Uint8Array): Uint8Array;
1217
+ static symmetric_decrypt_array_buffer(enc_bytes: Uint8Array, key: Uint8Array): Uint8Array;
1218
+ static symmetric_encrypt(plain: string, key: Uint8Array): string;
1219
+ static symmetric_encrypt_to_array_buffer(plain: Uint8Array, key: Uint8Array): Uint8Array;
1220
+ }
1221
+ export class ReceiveError {
1222
+ private constructor();
1223
+ free(): void;
1224
+ timeout: boolean;
1225
+ crypto: any;
1226
+ communication: any;
1227
+ }
1228
+ export class SendError {
1229
+ private constructor();
1230
+ free(): void;
1231
+ crypto: any;
1232
+ communication: any;
1233
+ }
1234
+ export class TotpClient {
1235
+ private constructor();
1236
+ free(): void;
1237
+ /**
1238
+ * Generates a TOTP code from a provided key
1239
+ *
1240
+ * # Arguments
1241
+ * - `key` - Can be:
1242
+ * - A base32 encoded string
1243
+ * - OTP Auth URI
1244
+ * - Steam URI
1245
+ * - `time_ms` - Optional timestamp in milliseconds
1246
+ *
1247
+ * # Returns
1248
+ * - `Ok(TotpResponse)` containing the generated code and period
1249
+ * - `Err(TotpError)` if code generation fails
1250
+ */
1251
+ generate_totp(key: string, time_ms?: number | null): TotpResponse;
1252
+ }
1253
+ export class VaultClient {
1254
+ private constructor();
1255
+ free(): void;
1256
+ attachments(): AttachmentsClient;
1257
+ ciphers(): CiphersClient;
1258
+ folders(): FoldersClient;
1259
+ totp(): TotpClient;
289
1260
  }