@bitwarden/sdk-internal 0.2.0-main.15 → 0.2.0-main.151

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