@bitwarden/sdk-internal 0.2.0-main.11 → 0.2.0-main.110

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.
package/VERSION ADDED
@@ -0,0 +1 @@
1
+ 131cbfae6dbd68f3ee53e94181fcbb4646e372ae
@@ -1,10 +1,34 @@
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;
8
32
  export enum LogLevel {
9
33
  Trace = 0,
10
34
  Debug = 1,
@@ -56,30 +80,42 @@ export interface InitOrgCryptoRequest {
56
80
  organizationKeys: Map<Uuid, AsymmetricEncString>;
57
81
  }
58
82
 
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";
83
+ export interface MakeKeyPairResponse {
84
+ /**
85
+ * The user\'s public key
86
+ */
87
+ userPublicKey: string;
88
+ /**
89
+ * User\'s private key, encrypted with the user key
90
+ */
91
+ userKeyEncryptedPrivateKey: EncString;
92
+ }
93
+
94
+ export interface VerifyAsymmetricKeysRequest {
95
+ /**
96
+ * The user\'s user key
97
+ */
98
+ userKey: string;
99
+ /**
100
+ * The user\'s public key
101
+ */
102
+ userPublicKey: string;
103
+ /**
104
+ * User\'s private key, encrypted with the user key
105
+ */
106
+ userKeyEncryptedPrivateKey: EncString;
80
107
  }
81
108
 
82
- export function isCoreError(error: any): error is CoreError;
109
+ export interface VerifyAsymmetricKeysResponse {
110
+ /**
111
+ * Whether the user\'s private key was decryptable by the user key.
112
+ */
113
+ privateKeyDecryptable: boolean;
114
+ /**
115
+ * Whether the user\'s private key was a valid RSA key and matched the public key provided.
116
+ */
117
+ validPrivateKey: boolean;
118
+ }
83
119
 
84
120
  export interface EncryptionSettingsError extends Error {
85
121
  name: "EncryptionSettingsError";
@@ -166,14 +202,47 @@ export type Kdf =
166
202
  | { pBKDF2: { iterations: NonZeroU32 } }
167
203
  | { argon2id: { iterations: NonZeroU32; memory: NonZeroU32; parallelism: NonZeroU32 } };
168
204
 
169
- export interface GenerateSshKeyResult {
170
- private_key: string;
171
- public_key: string;
172
- key_fingerprint: string;
205
+ export interface CryptoError extends Error {
206
+ name: "CryptoError";
207
+ variant:
208
+ | "InvalidKey"
209
+ | "InvalidMac"
210
+ | "MacNotProvided"
211
+ | "KeyDecrypt"
212
+ | "InvalidKeyLen"
213
+ | "InvalidUtf8String"
214
+ | "MissingKey"
215
+ | "MissingField"
216
+ | "MissingKeyId"
217
+ | "ReadOnlyKeyStore"
218
+ | "InsufficientKdfParameters"
219
+ | "EncString"
220
+ | "RsaError"
221
+ | "FingerprintError"
222
+ | "ArgonError"
223
+ | "ZeroNumber"
224
+ | "OperationNotSupported"
225
+ | "WrongKeyType";
173
226
  }
174
227
 
228
+ export function isCryptoError(error: any): error is CryptoError;
229
+
175
230
  export type KeyAlgorithm = "Ed25519" | "Rsa3072" | "Rsa4096";
176
231
 
232
+ export interface SshKeyExportError extends Error {
233
+ name: "SshKeyExportError";
234
+ variant: "KeyConversionError";
235
+ }
236
+
237
+ export function isSshKeyExportError(error: any): error is SshKeyExportError;
238
+
239
+ export interface SshKeyImportError extends Error {
240
+ name: "SshKeyImportError";
241
+ variant: "ParsingError" | "PasswordRequired" | "WrongPassword" | "UnsupportedKeyType";
242
+ }
243
+
244
+ export function isSshKeyImportError(error: any): error is SshKeyImportError;
245
+
177
246
  export interface KeyGenerationError extends Error {
178
247
  name: "KeyGenerationError";
179
248
  variant: "KeyGenerationError" | "KeyConversionError";
@@ -193,11 +262,66 @@ export interface FolderView {
193
262
  revisionDate: DateTime<Utc>;
194
263
  }
195
264
 
196
- export interface TestError extends Error {
197
- name: "TestError";
265
+ export interface DecryptFileError extends Error {
266
+ name: "DecryptFileError";
267
+ variant: "Decrypt" | "Io";
198
268
  }
199
269
 
200
- export function isTestError(error: any): error is TestError;
270
+ export function isDecryptFileError(error: any): error is DecryptFileError;
271
+
272
+ export interface EncryptFileError extends Error {
273
+ name: "EncryptFileError";
274
+ variant: "Encrypt" | "Io";
275
+ }
276
+
277
+ export function isEncryptFileError(error: any): error is EncryptFileError;
278
+
279
+ export interface DecryptError extends Error {
280
+ name: "DecryptError";
281
+ variant: "Crypto" | "VaultLocked";
282
+ }
283
+
284
+ export function isDecryptError(error: any): error is DecryptError;
285
+
286
+ export interface EncryptError extends Error {
287
+ name: "EncryptError";
288
+ variant: "Crypto" | "VaultLocked";
289
+ }
290
+
291
+ export function isEncryptError(error: any): error is EncryptError;
292
+
293
+ export interface TotpResponse {
294
+ /**
295
+ * Generated TOTP code
296
+ */
297
+ code: string;
298
+ /**
299
+ * Time period
300
+ */
301
+ period: number;
302
+ }
303
+
304
+ export interface TotpError extends Error {
305
+ name: "TotpError";
306
+ variant: "InvalidOtpauth" | "MissingSecret" | "CryptoError" | "VaultLocked";
307
+ }
308
+
309
+ export function isTotpError(error: any): error is TotpError;
310
+
311
+ export interface SshKeyView {
312
+ /**
313
+ * SSH private key (ed25519/rsa) in unencrypted openssh private key format [OpenSSH private key](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key)
314
+ */
315
+ privateKey: string;
316
+ /**
317
+ * SSH public key (ed25519/rsa) according to [RFC4253](https://datatracker.ietf.org/doc/html/rfc4253#section-6.6)
318
+ */
319
+ publicKey: string;
320
+ /**
321
+ * SSH fingerprint using SHA256 in the format: `SHA256:BASE64_ENCODED_FINGERPRINT`
322
+ */
323
+ fingerprint: string;
324
+ }
201
325
 
202
326
  export type Uuid = string;
203
327
 
@@ -217,73 +341,98 @@ export type Utc = unknown;
217
341
  */
218
342
  export type NonZeroU32 = number;
219
343
 
344
+ export interface TestError extends Error {
345
+ name: "TestError";
346
+ }
347
+
348
+ export function isTestError(error: any): error is TestError;
349
+
220
350
  export class BitwardenClient {
221
351
  free(): void;
222
- /**
223
- * @param {ClientSettings | undefined} [settings]
224
- * @param {LogLevel | undefined} [log_level]
225
- */
226
- constructor(settings?: ClientSettings, log_level?: LogLevel);
352
+ constructor(settings?: ClientSettings | null);
227
353
  /**
228
354
  * Test method, echoes back the input
229
- * @param {string} msg
230
- * @returns {string}
231
355
  */
232
356
  echo(msg: string): string;
233
- /**
234
- * @returns {string}
235
- */
236
357
  version(): string;
237
- /**
238
- * @param {string} msg
239
- * @returns {Promise<void>}
240
- */
241
- throw(msg: string): Promise<void>;
358
+ throw(msg: string): void;
242
359
  /**
243
360
  * Test method, calls http endpoint
244
- * @param {string} url
245
- * @returns {Promise<string>}
246
361
  */
247
362
  http_get(url: string): Promise<string>;
363
+ crypto(): CryptoClient;
364
+ vault(): VaultClient;
365
+ }
366
+ export class ClientFolders {
367
+ private constructor();
368
+ free(): void;
248
369
  /**
249
- * @returns {ClientCrypto}
370
+ * Decrypt folder
250
371
  */
251
- crypto(): ClientCrypto;
372
+ decrypt(folder: Folder): FolderView;
373
+ }
374
+ export class ClientTotp {
375
+ private constructor();
376
+ free(): void;
252
377
  /**
253
- * @returns {ClientVault}
378
+ * Generates a TOTP code from a provided key
379
+ *
380
+ * # Arguments
381
+ * - `key` - Can be:
382
+ * - A base32 encoded string
383
+ * - OTP Auth URI
384
+ * - Steam URI
385
+ * - `time_ms` - Optional timestamp in milliseconds
386
+ *
387
+ * # Returns
388
+ * - `Ok(TotpResponse)` containing the generated code and period
389
+ * - `Err(TotpError)` if code generation fails
254
390
  */
255
- vault(): ClientVault;
391
+ generate_totp(key: string, time_ms?: number | null): TotpResponse;
256
392
  }
257
- export class ClientCrypto {
393
+ export class CryptoClient {
394
+ private constructor();
258
395
  free(): void;
259
396
  /**
260
397
  * Initialization method for the user crypto. Needs to be called before any other crypto
261
398
  * operations.
262
- * @param {InitUserCryptoRequest} req
263
- * @returns {Promise<void>}
264
399
  */
265
400
  initialize_user_crypto(req: InitUserCryptoRequest): Promise<void>;
266
401
  /**
267
402
  * Initialization method for the organization crypto. Needs to be called after
268
403
  * `initialize_user_crypto` but before any other crypto operations.
269
- * @param {InitOrgCryptoRequest} req
270
- * @returns {Promise<void>}
271
404
  */
272
405
  initialize_org_crypto(req: InitOrgCryptoRequest): Promise<void>;
273
- }
274
- export class ClientFolders {
275
- free(): void;
276
406
  /**
277
- * Decrypt folder
278
- * @param {Folder} folder
279
- * @returns {FolderView}
407
+ * Generates a new key pair and encrypts the private key with the provided user key.
408
+ * Crypto initialization not required.
280
409
  */
281
- decrypt(folder: Folder): FolderView;
282
- }
283
- export class ClientVault {
284
- free(): void;
410
+ make_key_pair(user_key: string): MakeKeyPairResponse;
285
411
  /**
286
- * @returns {ClientFolders}
412
+ * Verifies a user's asymmetric keys by decrypting the private key with the provided user
413
+ * key. Returns if the private key is decryptable and if it is a valid matching key.
414
+ * Crypto initialization not required.
287
415
  */
416
+ verify_asymmetric_keys(request: VerifyAsymmetricKeysRequest): VerifyAsymmetricKeysResponse;
417
+ }
418
+ /**
419
+ * This module represents a stopgap solution to provide access to primitive crypto functions for JS
420
+ * clients. It is not intended to be used outside of the JS clients and this pattern should not be
421
+ * proliferated. It is necessary because we want to use SDK crypto prior to the SDK being fully
422
+ * responsible for state and keys.
423
+ */
424
+ export class PureCrypto {
425
+ private constructor();
426
+ free(): void;
427
+ static symmetric_decrypt(enc_string: string, key_b64: string): string;
428
+ static symmetric_decrypt_to_bytes(enc_string: string, key_b64: string): Uint8Array;
429
+ static symmetric_decrypt_array_buffer(enc_bytes: Uint8Array, key_b64: string): Uint8Array;
430
+ static symmetric_encrypt(plain: string, key_b64: string): string;
431
+ static symmetric_encrypt_to_array_buffer(plain: Uint8Array, key_b64: string): Uint8Array;
432
+ }
433
+ export class VaultClient {
434
+ private constructor();
435
+ free(): void;
288
436
  folders(): ClientFolders;
437
+ totp(): ClientTotp;
289
438
  }
@@ -2,3 +2,4 @@ import * as wasm from "./bitwarden_wasm_internal_bg.wasm";
2
2
  export * from "./bitwarden_wasm_internal_bg.js";
3
3
  import { __wbg_set_wasm } from "./bitwarden_wasm_internal_bg.js";
4
4
  __wbg_set_wasm(wasm);
5
+ wasm.__wbindgen_start();