@bitwarden/sdk-internal 0.2.0-main.22 → 0.2.0-main.220

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