vaultkeeper 0.4.0 → 0.5.0

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/dist/index.d.cts CHANGED
@@ -134,6 +134,21 @@ declare class IdentityMismatchError extends VaultError {
134
134
  readonly currentHash: string;
135
135
  constructor(message: string, previousHash: string, currentHash: string);
136
136
  }
137
+ /**
138
+ * Thrown when a caller requests a signing/verification algorithm that is not
139
+ * in the allowed set (e.g. `'md5'`).
140
+ */
141
+ declare class InvalidAlgorithmError extends VaultError {
142
+ /**
143
+ * The algorithm that was requested.
144
+ */
145
+ readonly algorithm: string;
146
+ /**
147
+ * The set of algorithms that are allowed.
148
+ */
149
+ readonly allowed: string[];
150
+ constructor(message: string, algorithm: string, allowed: string[]);
151
+ }
137
152
  /**
138
153
  * Thrown during initialization when a required system dependency (e.g. OpenSSL
139
154
  * or a native credential helper) is missing or incompatible.
@@ -377,6 +392,8 @@ interface BackendConfig {
377
392
  plugin?: boolean | undefined;
378
393
  /** Filesystem path used by file-based backends. */
379
394
  path?: string | undefined;
395
+ /** Backend-specific options collected during interactive setup. */
396
+ options?: Record<string, string> | undefined;
380
397
  }
381
398
 
382
399
  /**
@@ -384,9 +401,15 @@ interface BackendConfig {
384
401
  */
385
402
  /**
386
403
  * Factory function for creating a SecretBackend instance.
404
+ *
405
+ * @remarks
406
+ * Factories may optionally accept a {@link BackendConfig} to configure the
407
+ * backend from the user's vaultkeeper config file. Factories that do not need
408
+ * configuration can ignore the parameter.
409
+ *
387
410
  * @public
388
411
  */
389
- type BackendFactory = () => SecretBackend;
412
+ type BackendFactory = (config?: BackendConfig) => SecretBackend;
390
413
  /**
391
414
  * Abstraction interface for all secret storage backends.
392
415
  *
@@ -450,12 +473,45 @@ interface ListableBackend extends SecretBackend {
450
473
  declare function isListableBackend(backend: SecretBackend): backend is ListableBackend;
451
474
 
452
475
  /**
453
- * Registry for secret backend implementations.
476
+ * Types for the backend setup protocol.
454
477
  *
455
- * @remarks
456
- * The registry maintains a mapping of backend types to factory functions,
457
- * allowing dynamic creation of backends based on configuration.
478
+ * @packageDocumentation
479
+ */
480
+ /**
481
+ * A question yielded by a backend setup generator.
482
+ * @public
483
+ */
484
+ interface SetupQuestion {
485
+ /** Machine key for BackendConfig.options */
486
+ readonly key: string;
487
+ /** Human-readable prompt */
488
+ readonly prompt: string;
489
+ /** Present for selection questions; when absent, the answer is a free-form string. */
490
+ readonly choices?: readonly SetupChoice[];
491
+ }
492
+ /**
493
+ * A choice within a setup question.
494
+ * @public
458
495
  */
496
+ interface SetupChoice {
497
+ /** Persisted value */
498
+ readonly value: string;
499
+ /** Display label */
500
+ readonly label: string;
501
+ }
502
+ /**
503
+ * Result returned when a backend setup generator completes.
504
+ * @public
505
+ */
506
+ interface SetupResult {
507
+ /** Merge into BackendConfig.options */
508
+ readonly options: Record<string, string>;
509
+ }
510
+ /**
511
+ * Factory that creates a backend setup generator.
512
+ * @public
513
+ */
514
+ type BackendSetupFactory = () => AsyncGenerator<SetupQuestion, SetupResult, string>;
459
515
 
460
516
  /**
461
517
  * Registry for secret backend implementations.
@@ -469,6 +525,7 @@ declare function isListableBackend(backend: SecretBackend): backend is ListableB
469
525
  */
470
526
  declare class BackendRegistry {
471
527
  private static backends;
528
+ private static setups;
472
529
  /**
473
530
  * Register a backend factory.
474
531
  * @param type - Backend type identifier
@@ -478,10 +535,11 @@ declare class BackendRegistry {
478
535
  /**
479
536
  * Create a backend instance by type.
480
537
  * @param type - Backend type identifier
538
+ * @param config - Optional backend configuration forwarded to the factory
481
539
  * @returns A SecretBackend instance
482
- * @throws Error if the backend type is not registered
540
+ * @throws {@link BackendUnavailableError} if the backend type is not registered
483
541
  */
484
- static create(type: string): SecretBackend;
542
+ static create(type: string, config?: BackendConfig): SecretBackend;
485
543
  /**
486
544
  * Get all registered backend type identifiers.
487
545
  * @returns Array of backend type identifiers
@@ -500,6 +558,36 @@ declare class BackendRegistry {
500
558
  * @public
501
559
  */
502
560
  static getAvailableTypes(): Promise<string[]>;
561
+ /**
562
+ * Register a setup factory for a backend type.
563
+ * @param type - Backend type identifier
564
+ * @param factory - Factory function that creates a setup generator
565
+ */
566
+ static registerSetup(type: string, factory: BackendSetupFactory): void;
567
+ /**
568
+ * Get the setup factory for a backend type, if one is registered.
569
+ * @param type - Backend type identifier
570
+ * @returns The setup factory, or `undefined` if none is registered
571
+ */
572
+ static getSetup(type: string): BackendSetupFactory | undefined;
573
+ /**
574
+ * Check whether a setup factory is registered for the given backend type.
575
+ * @param type - Backend type identifier
576
+ * @returns `true` if a setup factory is registered
577
+ */
578
+ static hasSetup(type: string): boolean;
579
+ /**
580
+ * Clear all registered backend factories.
581
+ * Intended for use in tests only.
582
+ * @internal
583
+ */
584
+ static clearBackends(): void;
585
+ /**
586
+ * Clear all registered setup factories.
587
+ * Intended for use in tests only.
588
+ * @internal
589
+ */
590
+ static clearSetups(): void;
503
591
  }
504
592
 
505
593
  /**
@@ -645,6 +733,8 @@ declare class VaultKeeper {
645
733
  * with the vault metadata (`vaultResponse`).
646
734
  * @throws {VaultError} If `token` is invalid or was not created by this
647
735
  * vault instance.
736
+ * @throws {InvalidAlgorithmError} If `request.algorithm` is not in the
737
+ * allowed set (e.g. `'md5'`).
648
738
  */
649
739
  sign(token: CapabilityToken, request: SignRequest): Promise<{
650
740
  result: SignResult;
@@ -657,8 +747,11 @@ declare class VaultKeeper {
657
747
  * capability tokens are required. It is safe to call from CI or any
658
748
  * context that has access to public key material.
659
749
  *
660
- * Never throws. Returns `false` for invalid key material, malformed
661
- * signatures, or any verification failure.
750
+ * Returns `false` for invalid key material, malformed signatures, or
751
+ * any verification failure (except disallowed algorithms, which throw).
752
+ *
753
+ * @throws {InvalidAlgorithmError} If `request.algorithm` is not in the
754
+ * allowed set (e.g. `'md5'`).
662
755
  *
663
756
  * @param request - The data, signature, public key, and optional
664
757
  * algorithm override.
@@ -700,4 +793,4 @@ declare class VaultKeeper {
700
793
  setDevelopmentMode(executablePath: string, enabled: boolean): Promise<void>;
701
794
  }
702
795
 
703
- export { AuthorizationDeniedError, type BackendConfig, type BackendFactory, BackendLockedError, BackendRegistry, BackendUnavailableError, CapabilityToken, DeviceNotPresentError, type ExecRequest, type ExecResult, type FetchRequest, FilesystemError, IdentityMismatchError, KeyRevokedError, KeyRotatedError, type KeyStatus, type ListableBackend, PluginNotFoundError, type PreflightCheck, type PreflightCheckStatus, type PreflightResult, RotationInProgressError, type SecretAccessor, type SecretBackend, SecretNotFoundError, SetupError, type SetupOptions, type SignRequest, type SignResult, TokenExpiredError, TokenRevokedError, type TrustTier, UsageLimitExceededError, type VaultConfig, VaultError, VaultKeeper, type VaultKeeperOptions, type VaultResponse, type VerifyRequest, isListableBackend };
796
+ export { AuthorizationDeniedError, type BackendConfig, type BackendFactory, BackendLockedError, BackendRegistry, type BackendSetupFactory, BackendUnavailableError, CapabilityToken, DeviceNotPresentError, type ExecRequest, type ExecResult, type FetchRequest, FilesystemError, IdentityMismatchError, InvalidAlgorithmError, KeyRevokedError, KeyRotatedError, type KeyStatus, type ListableBackend, PluginNotFoundError, type PreflightCheck, type PreflightCheckStatus, type PreflightResult, RotationInProgressError, type SecretAccessor, type SecretBackend, SecretNotFoundError, type SetupChoice, SetupError, type SetupOptions, type SetupQuestion, type SetupResult, type SignRequest, type SignResult, TokenExpiredError, TokenRevokedError, type TrustTier, UsageLimitExceededError, type VaultConfig, VaultError, VaultKeeper, type VaultKeeperOptions, type VaultResponse, type VerifyRequest, isListableBackend };
package/dist/index.d.ts CHANGED
@@ -134,6 +134,21 @@ declare class IdentityMismatchError extends VaultError {
134
134
  readonly currentHash: string;
135
135
  constructor(message: string, previousHash: string, currentHash: string);
136
136
  }
137
+ /**
138
+ * Thrown when a caller requests a signing/verification algorithm that is not
139
+ * in the allowed set (e.g. `'md5'`).
140
+ */
141
+ declare class InvalidAlgorithmError extends VaultError {
142
+ /**
143
+ * The algorithm that was requested.
144
+ */
145
+ readonly algorithm: string;
146
+ /**
147
+ * The set of algorithms that are allowed.
148
+ */
149
+ readonly allowed: string[];
150
+ constructor(message: string, algorithm: string, allowed: string[]);
151
+ }
137
152
  /**
138
153
  * Thrown during initialization when a required system dependency (e.g. OpenSSL
139
154
  * or a native credential helper) is missing or incompatible.
@@ -377,6 +392,8 @@ interface BackendConfig {
377
392
  plugin?: boolean | undefined;
378
393
  /** Filesystem path used by file-based backends. */
379
394
  path?: string | undefined;
395
+ /** Backend-specific options collected during interactive setup. */
396
+ options?: Record<string, string> | undefined;
380
397
  }
381
398
 
382
399
  /**
@@ -384,9 +401,15 @@ interface BackendConfig {
384
401
  */
385
402
  /**
386
403
  * Factory function for creating a SecretBackend instance.
404
+ *
405
+ * @remarks
406
+ * Factories may optionally accept a {@link BackendConfig} to configure the
407
+ * backend from the user's vaultkeeper config file. Factories that do not need
408
+ * configuration can ignore the parameter.
409
+ *
387
410
  * @public
388
411
  */
389
- type BackendFactory = () => SecretBackend;
412
+ type BackendFactory = (config?: BackendConfig) => SecretBackend;
390
413
  /**
391
414
  * Abstraction interface for all secret storage backends.
392
415
  *
@@ -450,12 +473,45 @@ interface ListableBackend extends SecretBackend {
450
473
  declare function isListableBackend(backend: SecretBackend): backend is ListableBackend;
451
474
 
452
475
  /**
453
- * Registry for secret backend implementations.
476
+ * Types for the backend setup protocol.
454
477
  *
455
- * @remarks
456
- * The registry maintains a mapping of backend types to factory functions,
457
- * allowing dynamic creation of backends based on configuration.
478
+ * @packageDocumentation
479
+ */
480
+ /**
481
+ * A question yielded by a backend setup generator.
482
+ * @public
483
+ */
484
+ interface SetupQuestion {
485
+ /** Machine key for BackendConfig.options */
486
+ readonly key: string;
487
+ /** Human-readable prompt */
488
+ readonly prompt: string;
489
+ /** Present for selection questions; when absent, the answer is a free-form string. */
490
+ readonly choices?: readonly SetupChoice[];
491
+ }
492
+ /**
493
+ * A choice within a setup question.
494
+ * @public
458
495
  */
496
+ interface SetupChoice {
497
+ /** Persisted value */
498
+ readonly value: string;
499
+ /** Display label */
500
+ readonly label: string;
501
+ }
502
+ /**
503
+ * Result returned when a backend setup generator completes.
504
+ * @public
505
+ */
506
+ interface SetupResult {
507
+ /** Merge into BackendConfig.options */
508
+ readonly options: Record<string, string>;
509
+ }
510
+ /**
511
+ * Factory that creates a backend setup generator.
512
+ * @public
513
+ */
514
+ type BackendSetupFactory = () => AsyncGenerator<SetupQuestion, SetupResult, string>;
459
515
 
460
516
  /**
461
517
  * Registry for secret backend implementations.
@@ -469,6 +525,7 @@ declare function isListableBackend(backend: SecretBackend): backend is ListableB
469
525
  */
470
526
  declare class BackendRegistry {
471
527
  private static backends;
528
+ private static setups;
472
529
  /**
473
530
  * Register a backend factory.
474
531
  * @param type - Backend type identifier
@@ -478,10 +535,11 @@ declare class BackendRegistry {
478
535
  /**
479
536
  * Create a backend instance by type.
480
537
  * @param type - Backend type identifier
538
+ * @param config - Optional backend configuration forwarded to the factory
481
539
  * @returns A SecretBackend instance
482
- * @throws Error if the backend type is not registered
540
+ * @throws {@link BackendUnavailableError} if the backend type is not registered
483
541
  */
484
- static create(type: string): SecretBackend;
542
+ static create(type: string, config?: BackendConfig): SecretBackend;
485
543
  /**
486
544
  * Get all registered backend type identifiers.
487
545
  * @returns Array of backend type identifiers
@@ -500,6 +558,36 @@ declare class BackendRegistry {
500
558
  * @public
501
559
  */
502
560
  static getAvailableTypes(): Promise<string[]>;
561
+ /**
562
+ * Register a setup factory for a backend type.
563
+ * @param type - Backend type identifier
564
+ * @param factory - Factory function that creates a setup generator
565
+ */
566
+ static registerSetup(type: string, factory: BackendSetupFactory): void;
567
+ /**
568
+ * Get the setup factory for a backend type, if one is registered.
569
+ * @param type - Backend type identifier
570
+ * @returns The setup factory, or `undefined` if none is registered
571
+ */
572
+ static getSetup(type: string): BackendSetupFactory | undefined;
573
+ /**
574
+ * Check whether a setup factory is registered for the given backend type.
575
+ * @param type - Backend type identifier
576
+ * @returns `true` if a setup factory is registered
577
+ */
578
+ static hasSetup(type: string): boolean;
579
+ /**
580
+ * Clear all registered backend factories.
581
+ * Intended for use in tests only.
582
+ * @internal
583
+ */
584
+ static clearBackends(): void;
585
+ /**
586
+ * Clear all registered setup factories.
587
+ * Intended for use in tests only.
588
+ * @internal
589
+ */
590
+ static clearSetups(): void;
503
591
  }
504
592
 
505
593
  /**
@@ -645,6 +733,8 @@ declare class VaultKeeper {
645
733
  * with the vault metadata (`vaultResponse`).
646
734
  * @throws {VaultError} If `token` is invalid or was not created by this
647
735
  * vault instance.
736
+ * @throws {InvalidAlgorithmError} If `request.algorithm` is not in the
737
+ * allowed set (e.g. `'md5'`).
648
738
  */
649
739
  sign(token: CapabilityToken, request: SignRequest): Promise<{
650
740
  result: SignResult;
@@ -657,8 +747,11 @@ declare class VaultKeeper {
657
747
  * capability tokens are required. It is safe to call from CI or any
658
748
  * context that has access to public key material.
659
749
  *
660
- * Never throws. Returns `false` for invalid key material, malformed
661
- * signatures, or any verification failure.
750
+ * Returns `false` for invalid key material, malformed signatures, or
751
+ * any verification failure (except disallowed algorithms, which throw).
752
+ *
753
+ * @throws {InvalidAlgorithmError} If `request.algorithm` is not in the
754
+ * allowed set (e.g. `'md5'`).
662
755
  *
663
756
  * @param request - The data, signature, public key, and optional
664
757
  * algorithm override.
@@ -700,4 +793,4 @@ declare class VaultKeeper {
700
793
  setDevelopmentMode(executablePath: string, enabled: boolean): Promise<void>;
701
794
  }
702
795
 
703
- export { AuthorizationDeniedError, type BackendConfig, type BackendFactory, BackendLockedError, BackendRegistry, BackendUnavailableError, CapabilityToken, DeviceNotPresentError, type ExecRequest, type ExecResult, type FetchRequest, FilesystemError, IdentityMismatchError, KeyRevokedError, KeyRotatedError, type KeyStatus, type ListableBackend, PluginNotFoundError, type PreflightCheck, type PreflightCheckStatus, type PreflightResult, RotationInProgressError, type SecretAccessor, type SecretBackend, SecretNotFoundError, SetupError, type SetupOptions, type SignRequest, type SignResult, TokenExpiredError, TokenRevokedError, type TrustTier, UsageLimitExceededError, type VaultConfig, VaultError, VaultKeeper, type VaultKeeperOptions, type VaultResponse, type VerifyRequest, isListableBackend };
796
+ export { AuthorizationDeniedError, type BackendConfig, type BackendFactory, BackendLockedError, BackendRegistry, type BackendSetupFactory, BackendUnavailableError, CapabilityToken, DeviceNotPresentError, type ExecRequest, type ExecResult, type FetchRequest, FilesystemError, IdentityMismatchError, InvalidAlgorithmError, KeyRevokedError, KeyRotatedError, type KeyStatus, type ListableBackend, PluginNotFoundError, type PreflightCheck, type PreflightCheckStatus, type PreflightResult, RotationInProgressError, type SecretAccessor, type SecretBackend, SecretNotFoundError, type SetupChoice, SetupError, type SetupOptions, type SetupQuestion, type SetupResult, type SignRequest, type SignResult, TokenExpiredError, TokenRevokedError, type TrustTier, UsageLimitExceededError, type VaultConfig, VaultError, VaultKeeper, type VaultKeeperOptions, type VaultResponse, type VerifyRequest, isListableBackend };