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

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