@bitwarden/sdk-internal 0.2.0-main.14 → 0.2.0-main.141

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 } }
@@ -45,10 +136,16 @@ export type InitUserCryptoMethod =
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
143
  | { userKey: { protected_user_key: AsymmetricEncString } }
50
144
  | { masterKey: { protected_master_key: AsymmetricEncString; 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
@@ -56,30 +153,51 @@ export interface InitOrgCryptoRequest {
56
153
  organizationKeys: Map<Uuid, AsymmetricEncString>;
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";
@@ -166,14 +284,65 @@ 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
+ export type Endpoint =
313
+ | { Web: { id: number } }
314
+ | "BrowserForeground"
315
+ | "BrowserBackground"
316
+ | "DesktopRenderer"
317
+ | "DesktopMain";
318
+
319
+ export interface CommunicationBackend {
320
+ send(message: OutgoingMessage): Promise<void>;
321
+ receive(): Promise<IncomingMessage>;
173
322
  }
174
323
 
324
+ export interface DeserializeError extends Error {
325
+ name: "DeserializeError";
326
+ }
327
+
328
+ export function isDeserializeError(error: any): error is DeserializeError;
329
+
175
330
  export type KeyAlgorithm = "Ed25519" | "Rsa3072" | "Rsa4096";
176
331
 
332
+ export interface SshKeyExportError extends Error {
333
+ name: "SshKeyExportError";
334
+ variant: "KeyConversionError";
335
+ }
336
+
337
+ export function isSshKeyExportError(error: any): error is SshKeyExportError;
338
+
339
+ export interface SshKeyImportError extends Error {
340
+ name: "SshKeyImportError";
341
+ variant: "ParsingError" | "PasswordRequired" | "WrongPassword" | "UnsupportedKeyType";
342
+ }
343
+
344
+ export function isSshKeyImportError(error: any): error is SshKeyImportError;
345
+
177
346
  export interface KeyGenerationError extends Error {
178
347
  name: "KeyGenerationError";
179
348
  variant: "KeyGenerationError" | "KeyConversionError";
@@ -181,6 +350,226 @@ export interface KeyGenerationError extends Error {
181
350
 
182
351
  export function isKeyGenerationError(error: any): error is KeyGenerationError;
183
352
 
353
+ export interface Cipher {
354
+ id: Uuid | undefined;
355
+ organizationId: Uuid | undefined;
356
+ folderId: Uuid | undefined;
357
+ collectionIds: Uuid[];
358
+ /**
359
+ * More recent ciphers uses individual encryption keys to encrypt the other fields of the
360
+ * Cipher.
361
+ */
362
+ key: EncString | undefined;
363
+ name: EncString;
364
+ notes: EncString | undefined;
365
+ type: CipherType;
366
+ login: Login | undefined;
367
+ identity: Identity | undefined;
368
+ card: Card | undefined;
369
+ secureNote: SecureNote | undefined;
370
+ sshKey: SshKey | undefined;
371
+ favorite: boolean;
372
+ reprompt: CipherRepromptType;
373
+ organizationUseTotp: boolean;
374
+ edit: boolean;
375
+ permissions: CipherPermissions | undefined;
376
+ viewPassword: boolean;
377
+ localData: LocalData | undefined;
378
+ attachments: Attachment[] | undefined;
379
+ fields: Field[] | undefined;
380
+ passwordHistory: PasswordHistory[] | undefined;
381
+ creationDate: DateTime<Utc>;
382
+ deletedDate: DateTime<Utc> | undefined;
383
+ revisionDate: DateTime<Utc>;
384
+ }
385
+
386
+ export interface CipherView {
387
+ id: Uuid | undefined;
388
+ organizationId: Uuid | undefined;
389
+ folderId: Uuid | undefined;
390
+ collectionIds: Uuid[];
391
+ /**
392
+ * Temporary, required to support re-encrypting existing items.
393
+ */
394
+ key: EncString | undefined;
395
+ name: string;
396
+ notes: string | undefined;
397
+ type: CipherType;
398
+ login: LoginView | undefined;
399
+ identity: IdentityView | undefined;
400
+ card: CardView | undefined;
401
+ secureNote: SecureNoteView | undefined;
402
+ sshKey: SshKeyView | undefined;
403
+ favorite: boolean;
404
+ reprompt: CipherRepromptType;
405
+ organizationUseTotp: boolean;
406
+ edit: boolean;
407
+ permissions: CipherPermissions | undefined;
408
+ viewPassword: boolean;
409
+ localData: LocalDataView | undefined;
410
+ attachments: AttachmentView[] | undefined;
411
+ fields: FieldView[] | undefined;
412
+ passwordHistory: PasswordHistoryView[] | undefined;
413
+ creationDate: DateTime<Utc>;
414
+ deletedDate: DateTime<Utc> | undefined;
415
+ revisionDate: DateTime<Utc>;
416
+ }
417
+
418
+ export type CipherListViewType =
419
+ | { login: LoginListView }
420
+ | "secureNote"
421
+ | "card"
422
+ | "identity"
423
+ | "sshKey";
424
+
425
+ export interface CipherListView {
426
+ id: Uuid | undefined;
427
+ organizationId: Uuid | undefined;
428
+ folderId: Uuid | undefined;
429
+ collectionIds: Uuid[];
430
+ /**
431
+ * Temporary, required to support calculating TOTP from CipherListView.
432
+ */
433
+ key: EncString | undefined;
434
+ name: string;
435
+ subtitle: string;
436
+ type: CipherListViewType;
437
+ favorite: boolean;
438
+ reprompt: CipherRepromptType;
439
+ organizationUseTotp: boolean;
440
+ edit: boolean;
441
+ permissions: CipherPermissions | undefined;
442
+ viewPassword: boolean;
443
+ /**
444
+ * The number of attachments
445
+ */
446
+ attachments: number;
447
+ creationDate: DateTime<Utc>;
448
+ deletedDate: DateTime<Utc> | undefined;
449
+ revisionDate: DateTime<Utc>;
450
+ }
451
+
452
+ export interface Field {
453
+ name: EncString | undefined;
454
+ value: EncString | undefined;
455
+ type: FieldType;
456
+ linkedId: LinkedIdType | undefined;
457
+ }
458
+
459
+ export interface FieldView {
460
+ name: string | undefined;
461
+ value: string | undefined;
462
+ type: FieldType;
463
+ linkedId: LinkedIdType | undefined;
464
+ }
465
+
466
+ export type LinkedIdType = LoginLinkedIdType | CardLinkedIdType | IdentityLinkedIdType;
467
+
468
+ export interface LoginUri {
469
+ uri: EncString | undefined;
470
+ match: UriMatchType | undefined;
471
+ uriChecksum: EncString | undefined;
472
+ }
473
+
474
+ export interface LoginUriView {
475
+ uri: string | undefined;
476
+ match: UriMatchType | undefined;
477
+ uriChecksum: string | undefined;
478
+ }
479
+
480
+ export interface Fido2Credential {
481
+ credentialId: EncString;
482
+ keyType: EncString;
483
+ keyAlgorithm: EncString;
484
+ keyCurve: EncString;
485
+ keyValue: EncString;
486
+ rpId: EncString;
487
+ userHandle: EncString | undefined;
488
+ userName: EncString | undefined;
489
+ counter: EncString;
490
+ rpName: EncString | undefined;
491
+ userDisplayName: EncString | undefined;
492
+ discoverable: EncString;
493
+ creationDate: DateTime<Utc>;
494
+ }
495
+
496
+ export interface Fido2CredentialListView {
497
+ credentialId: string;
498
+ rpId: string;
499
+ userHandle: string | undefined;
500
+ userName: string | undefined;
501
+ userDisplayName: string | undefined;
502
+ }
503
+
504
+ export interface Fido2CredentialView {
505
+ credentialId: string;
506
+ keyType: string;
507
+ keyAlgorithm: string;
508
+ keyCurve: string;
509
+ keyValue: EncString;
510
+ rpId: string;
511
+ userHandle: string | undefined;
512
+ userName: string | undefined;
513
+ counter: string;
514
+ rpName: string | undefined;
515
+ userDisplayName: string | undefined;
516
+ discoverable: string;
517
+ creationDate: DateTime<Utc>;
518
+ }
519
+
520
+ export interface Fido2CredentialNewView {
521
+ credentialId: string;
522
+ keyType: string;
523
+ keyAlgorithm: string;
524
+ keyCurve: string;
525
+ rpId: string;
526
+ userHandle: string | undefined;
527
+ userName: string | undefined;
528
+ counter: string;
529
+ rpName: string | undefined;
530
+ userDisplayName: string | undefined;
531
+ creationDate: DateTime<Utc>;
532
+ }
533
+
534
+ export interface Login {
535
+ username: EncString | undefined;
536
+ password: EncString | undefined;
537
+ passwordRevisionDate: DateTime<Utc> | undefined;
538
+ uris: LoginUri[] | undefined;
539
+ totp: EncString | undefined;
540
+ autofillOnPageLoad: boolean | undefined;
541
+ fido2Credentials: Fido2Credential[] | undefined;
542
+ }
543
+
544
+ export interface LoginView {
545
+ username: string | undefined;
546
+ password: string | undefined;
547
+ passwordRevisionDate: DateTime<Utc> | undefined;
548
+ uris: LoginUriView[] | undefined;
549
+ totp: string | undefined;
550
+ autofillOnPageLoad: boolean | undefined;
551
+ fido2Credentials: Fido2Credential[] | undefined;
552
+ }
553
+
554
+ export interface LoginListView {
555
+ fido2Credentials: Fido2CredentialListView[] | undefined;
556
+ hasFido2: boolean;
557
+ username: string | undefined;
558
+ /**
559
+ * The TOTP key is not decrypted. Useable as is with [`crate::generate_totp_cipher_view`].
560
+ */
561
+ totp: EncString | undefined;
562
+ uris: LoginUriView[] | undefined;
563
+ }
564
+
565
+ export interface SecureNote {
566
+ type: SecureNoteType;
567
+ }
568
+
569
+ export interface SecureNoteView {
570
+ type: SecureNoteType;
571
+ }
572
+
184
573
  export interface Folder {
185
574
  id: Uuid | undefined;
186
575
  name: EncString;
@@ -193,11 +582,194 @@ export interface FolderView {
193
582
  revisionDate: DateTime<Utc>;
194
583
  }
195
584
 
196
- export interface TestError extends Error {
197
- name: "TestError";
585
+ export interface DecryptFileError extends Error {
586
+ name: "DecryptFileError";
587
+ variant: "Decrypt" | "Io";
198
588
  }
199
589
 
200
- export function isTestError(error: any): error is TestError;
590
+ export function isDecryptFileError(error: any): error is DecryptFileError;
591
+
592
+ export interface EncryptFileError extends Error {
593
+ name: "EncryptFileError";
594
+ variant: "Encrypt" | "Io";
595
+ }
596
+
597
+ export function isEncryptFileError(error: any): error is EncryptFileError;
598
+
599
+ export interface DecryptError extends Error {
600
+ name: "DecryptError";
601
+ variant: "Crypto" | "VaultLocked";
602
+ }
603
+
604
+ export function isDecryptError(error: any): error is DecryptError;
605
+
606
+ export interface EncryptError extends Error {
607
+ name: "EncryptError";
608
+ variant: "Crypto" | "VaultLocked";
609
+ }
610
+
611
+ export function isEncryptError(error: any): error is EncryptError;
612
+
613
+ export interface TotpResponse {
614
+ /**
615
+ * Generated TOTP code
616
+ */
617
+ code: string;
618
+ /**
619
+ * Time period
620
+ */
621
+ period: number;
622
+ }
623
+
624
+ export interface TotpError extends Error {
625
+ name: "TotpError";
626
+ variant: "InvalidOtpauth" | "MissingSecret" | "CryptoError" | "VaultLocked";
627
+ }
628
+
629
+ export function isTotpError(error: any): error is TotpError;
630
+
631
+ export interface PasswordHistoryView {
632
+ password: string;
633
+ lastUsedDate: DateTime<Utc>;
634
+ }
635
+
636
+ export interface PasswordHistory {
637
+ password: EncString;
638
+ lastUsedDate: DateTime<Utc>;
639
+ }
640
+
641
+ export interface SshKeyView {
642
+ /**
643
+ * SSH private key (ed25519/rsa) in unencrypted openssh private key format [OpenSSH private key](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key)
644
+ */
645
+ privateKey: string;
646
+ /**
647
+ * SSH public key (ed25519/rsa) according to [RFC4253](https://datatracker.ietf.org/doc/html/rfc4253#section-6.6)
648
+ */
649
+ publicKey: string;
650
+ /**
651
+ * SSH fingerprint using SHA256 in the format: `SHA256:BASE64_ENCODED_FINGERPRINT`
652
+ */
653
+ fingerprint: string;
654
+ }
655
+
656
+ export interface SshKey {
657
+ /**
658
+ * SSH private key (ed25519/rsa) in unencrypted openssh private key format [OpenSSH private key](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key)
659
+ */
660
+ privateKey: EncString;
661
+ /**
662
+ * SSH public key (ed25519/rsa) according to [RFC4253](https://datatracker.ietf.org/doc/html/rfc4253#section-6.6)
663
+ */
664
+ publicKey: EncString;
665
+ /**
666
+ * SSH fingerprint using SHA256 in the format: `SHA256:BASE64_ENCODED_FINGERPRINT`
667
+ */
668
+ fingerprint: EncString;
669
+ }
670
+
671
+ export interface LocalDataView {
672
+ lastUsedDate: number | undefined;
673
+ lastLaunched: number | undefined;
674
+ }
675
+
676
+ export interface LocalData {
677
+ lastUsedDate: number | undefined;
678
+ lastLaunched: number | undefined;
679
+ }
680
+
681
+ export interface IdentityView {
682
+ title: string | undefined;
683
+ firstName: string | undefined;
684
+ middleName: string | undefined;
685
+ lastName: string | undefined;
686
+ address1: string | undefined;
687
+ address2: string | undefined;
688
+ address3: string | undefined;
689
+ city: string | undefined;
690
+ state: string | undefined;
691
+ postalCode: string | undefined;
692
+ country: string | undefined;
693
+ company: string | undefined;
694
+ email: string | undefined;
695
+ phone: string | undefined;
696
+ ssn: string | undefined;
697
+ username: string | undefined;
698
+ passportNumber: string | undefined;
699
+ licenseNumber: string | undefined;
700
+ }
701
+
702
+ export interface Identity {
703
+ title: EncString | undefined;
704
+ firstName: EncString | undefined;
705
+ middleName: EncString | undefined;
706
+ lastName: EncString | undefined;
707
+ address1: EncString | undefined;
708
+ address2: EncString | undefined;
709
+ address3: EncString | undefined;
710
+ city: EncString | undefined;
711
+ state: EncString | undefined;
712
+ postalCode: EncString | undefined;
713
+ country: EncString | undefined;
714
+ company: EncString | undefined;
715
+ email: EncString | undefined;
716
+ phone: EncString | undefined;
717
+ ssn: EncString | undefined;
718
+ username: EncString | undefined;
719
+ passportNumber: EncString | undefined;
720
+ licenseNumber: EncString | undefined;
721
+ }
722
+
723
+ export interface CipherPermissions {
724
+ delete: boolean;
725
+ restore: boolean;
726
+ }
727
+
728
+ export interface CipherError extends Error {
729
+ name: "CipherError";
730
+ variant: "MissingFieldError" | "VaultLocked" | "CryptoError" | "AttachmentsWithoutKeys";
731
+ }
732
+
733
+ export function isCipherError(error: any): error is CipherError;
734
+
735
+ export interface CardView {
736
+ cardholderName: string | undefined;
737
+ expMonth: string | undefined;
738
+ expYear: string | undefined;
739
+ code: string | undefined;
740
+ brand: string | undefined;
741
+ number: string | undefined;
742
+ }
743
+
744
+ export interface Card {
745
+ cardholderName: EncString | undefined;
746
+ expMonth: EncString | undefined;
747
+ expYear: EncString | undefined;
748
+ code: EncString | undefined;
749
+ brand: EncString | undefined;
750
+ number: EncString | undefined;
751
+ }
752
+
753
+ export interface AttachmentView {
754
+ id: string | undefined;
755
+ url: string | undefined;
756
+ size: string | undefined;
757
+ sizeName: string | undefined;
758
+ fileName: string | undefined;
759
+ key: EncString | undefined;
760
+ }
761
+
762
+ export interface Attachment {
763
+ id: string | undefined;
764
+ url: string | undefined;
765
+ size: string | undefined;
766
+ /**
767
+ * Readable size, ex: \"4.2 KB\" or \"1.43 GB\
768
+ */
769
+ sizeName: string | undefined;
770
+ fileName: EncString | undefined;
771
+ key: EncString | undefined;
772
+ }
201
773
 
202
774
  export type Uuid = string;
203
775
 
@@ -217,73 +789,210 @@ export type Utc = unknown;
217
789
  */
218
790
  export type NonZeroU32 = number;
219
791
 
792
+ export interface TestError extends Error {
793
+ name: "TestError";
794
+ }
795
+
796
+ export function isTestError(error: any): error is TestError;
797
+
220
798
  export class BitwardenClient {
221
799
  free(): void;
222
- /**
223
- * @param {ClientSettings | undefined} [settings]
224
- * @param {LogLevel | undefined} [log_level]
225
- */
226
- constructor(settings?: ClientSettings, log_level?: LogLevel);
800
+ constructor(settings?: ClientSettings | null);
227
801
  /**
228
802
  * Test method, echoes back the input
229
- * @param {string} msg
230
- * @returns {string}
231
803
  */
232
804
  echo(msg: string): string;
805
+ version(): string;
806
+ throw(msg: string): void;
233
807
  /**
234
- * @returns {string}
808
+ * Test method, calls http endpoint
235
809
  */
236
- version(): string;
810
+ http_get(url: string): Promise<string>;
811
+ crypto(): CryptoClient;
812
+ vault(): VaultClient;
813
+ }
814
+ export class ClientCiphers {
815
+ private constructor();
816
+ free(): void;
237
817
  /**
238
- * @param {string} msg
239
- * @returns {Promise<void>}
818
+ * Encrypt cipher
819
+ *
820
+ * # Arguments
821
+ * - `cipher_view` - The decrypted cipher to encrypt
822
+ *
823
+ * # Returns
824
+ * - `Ok(Cipher)` containing the encrypted cipher
825
+ * - `Err(EncryptError)` if encryption fails
240
826
  */
241
- throw(msg: string): Promise<void>;
827
+ encrypt(cipher_view: CipherView): Cipher;
242
828
  /**
243
- * Test method, calls http endpoint
244
- * @param {string} url
245
- * @returns {Promise<string>}
829
+ * Decrypt cipher
830
+ *
831
+ * # Arguments
832
+ * - `cipher` - The encrypted cipher to decrypt
833
+ *
834
+ * # Returns
835
+ * - `Ok(CipherView)` containing the decrypted cipher
836
+ * - `Err(DecryptError)` if decryption fails
246
837
  */
247
- http_get(url: string): Promise<string>;
838
+ decrypt(cipher: Cipher): CipherView;
248
839
  /**
249
- * @returns {ClientCrypto}
840
+ * Decrypt list of ciphers
841
+ *
842
+ * # Arguments
843
+ * - `ciphers` - The list of encrypted ciphers to decrypt
844
+ *
845
+ * # Returns
846
+ * - `Ok(Vec<CipherListView>)` containing the decrypted ciphers
847
+ * - `Err(DecryptError)` if decryption fails
250
848
  */
251
- crypto(): ClientCrypto;
849
+ decrypt_list(ciphers: Cipher[]): CipherListView[];
252
850
  /**
253
- * @returns {ClientVault}
851
+ * Decrypt FIDO2 credentials
852
+ *
853
+ * # Arguments
854
+ * - `cipher_view` - Cipher to encrypt containing the FIDO2 credential
855
+ *
856
+ * # Returns
857
+ * - `Ok(Vec<Fido2CredentialView>)` containing the decrypted FIDO2 credentials
858
+ * - `Err(DecryptError)` if decryption fails
254
859
  */
255
- vault(): ClientVault;
860
+ decrypt_fido2_credentials(cipher_view: CipherView): Fido2CredentialView[];
861
+ /**
862
+ * Decrypt key
863
+ *
864
+ * This method is a temporary solution to allow typescript client access to decrypted key
865
+ * values, particularly for FIDO2 credentials.
866
+ *
867
+ * # Arguments
868
+ * - `cipher_view` - Decrypted cipher containing the key
869
+ *
870
+ * # Returns
871
+ * - `Ok(String)` containing the decrypted key
872
+ * - `Err(CipherError)`
873
+ */
874
+ decrypt_fido2_private_key(cipher_view: CipherView): string;
256
875
  }
257
- export class ClientCrypto {
876
+ export class ClientFolders {
877
+ private constructor();
878
+ free(): void;
879
+ /**
880
+ * Decrypt folder
881
+ */
882
+ decrypt(folder: Folder): FolderView;
883
+ }
884
+ export class ClientTotp {
885
+ private constructor();
886
+ free(): void;
887
+ /**
888
+ * Generates a TOTP code from a provided key
889
+ *
890
+ * # Arguments
891
+ * - `key` - Can be:
892
+ * - A base32 encoded string
893
+ * - OTP Auth URI
894
+ * - Steam URI
895
+ * - `time_ms` - Optional timestamp in milliseconds
896
+ *
897
+ * # Returns
898
+ * - `Ok(TotpResponse)` containing the generated code and period
899
+ * - `Err(TotpError)` if code generation fails
900
+ */
901
+ generate_totp(key: string, time_ms?: number | null): TotpResponse;
902
+ }
903
+ export class CryptoClient {
904
+ private constructor();
258
905
  free(): void;
259
906
  /**
260
907
  * Initialization method for the user crypto. Needs to be called before any other crypto
261
908
  * operations.
262
- * @param {InitUserCryptoRequest} req
263
- * @returns {Promise<void>}
264
909
  */
265
910
  initialize_user_crypto(req: InitUserCryptoRequest): Promise<void>;
266
911
  /**
267
912
  * Initialization method for the organization crypto. Needs to be called after
268
913
  * `initialize_user_crypto` but before any other crypto operations.
269
- * @param {InitOrgCryptoRequest} req
270
- * @returns {Promise<void>}
271
914
  */
272
915
  initialize_org_crypto(req: InitOrgCryptoRequest): Promise<void>;
916
+ /**
917
+ * Generates a new key pair and encrypts the private key with the provided user key.
918
+ * Crypto initialization not required.
919
+ */
920
+ make_key_pair(user_key: string): MakeKeyPairResponse;
921
+ /**
922
+ * Verifies a user's asymmetric keys by decrypting the private key with the provided user
923
+ * key. Returns if the private key is decryptable and if it is a valid matching key.
924
+ * Crypto initialization not required.
925
+ */
926
+ verify_asymmetric_keys(request: VerifyAsymmetricKeysRequest): VerifyAsymmetricKeysResponse;
273
927
  }
274
- export class ClientFolders {
928
+ export class IncomingMessage {
275
929
  free(): void;
930
+ constructor(payload: Uint8Array, destination: Endpoint, source: Endpoint, topic?: string | null);
276
931
  /**
277
- * Decrypt folder
278
- * @param {Folder} folder
279
- * @returns {FolderView}
932
+ * Try to parse the payload as JSON.
933
+ * @returns The parsed JSON value, or undefined if the payload is not valid JSON.
280
934
  */
281
- decrypt(folder: Folder): FolderView;
935
+ parse_payload_as_json(): any;
936
+ payload: Uint8Array;
937
+ destination: Endpoint;
938
+ source: Endpoint;
939
+ get topic(): string | undefined;
940
+ set topic(value: string | null | undefined);
941
+ }
942
+ export class IpcClient {
943
+ free(): void;
944
+ constructor(communication_provider: CommunicationBackend);
945
+ send(message: OutgoingMessage): Promise<void>;
946
+ receive(): Promise<IncomingMessage>;
282
947
  }
283
- export class ClientVault {
948
+ export class OutgoingMessage {
284
949
  free(): void;
950
+ constructor(payload: Uint8Array, destination: Endpoint, topic?: string | null);
285
951
  /**
286
- * @returns {ClientFolders}
952
+ * Create a new message and encode the payload as JSON.
287
953
  */
954
+ static new_json_payload(
955
+ payload: any,
956
+ destination: Endpoint,
957
+ topic?: string | null,
958
+ ): OutgoingMessage;
959
+ payload: Uint8Array;
960
+ destination: Endpoint;
961
+ get topic(): string | undefined;
962
+ set topic(value: string | null | undefined);
963
+ }
964
+ /**
965
+ * This module represents a stopgap solution to provide access to primitive crypto functions for JS
966
+ * clients. It is not intended to be used outside of the JS clients and this pattern should not be
967
+ * proliferated. It is necessary because we want to use SDK crypto prior to the SDK being fully
968
+ * responsible for state and keys.
969
+ */
970
+ export class PureCrypto {
971
+ private constructor();
972
+ free(): void;
973
+ static symmetric_decrypt(enc_string: string, key: Uint8Array): string;
974
+ static symmetric_decrypt_to_bytes(enc_string: string, key: Uint8Array): Uint8Array;
975
+ static symmetric_decrypt_array_buffer(enc_bytes: Uint8Array, key: Uint8Array): Uint8Array;
976
+ static symmetric_encrypt(plain: string, key: Uint8Array): string;
977
+ static symmetric_encrypt_to_array_buffer(plain: Uint8Array, key: Uint8Array): Uint8Array;
978
+ }
979
+ export class ReceiveError {
980
+ private constructor();
981
+ free(): void;
982
+ timeout: boolean;
983
+ crypto: any;
984
+ communication: any;
985
+ }
986
+ export class SendError {
987
+ private constructor();
988
+ free(): void;
989
+ crypto: any;
990
+ communication: any;
991
+ }
992
+ export class VaultClient {
993
+ private constructor();
994
+ free(): void;
995
+ ciphers(): ClientCiphers;
288
996
  folders(): ClientFolders;
997
+ totp(): ClientTotp;
289
998
  }