refactor(core): describe secret storage as a SecretStore interface (P1.2)

This commit is contained in:
shumeiko.it
2026-10-24 12:07:42 +02:00
parent 815c667374
commit cb51ed0d28
3 changed files with 37 additions and 7 deletions

View File

@@ -156,6 +156,7 @@ export {
type PendingActionRow, type PendingActionStatus, type SavePendingActionInput,
} from './cron-store.js';
export { VaultStore, type VaultEntry } from './vault.js';
export type { SecretStore, SecretEntry, SecretSummary } from './secret-store.js';
export { TelemetryStore, TelemetryCollector, TELEMETRY_EVENTS, type TelemetryEvent, type TelemetrySummary } from './telemetry.js';
export {
SkillHashStore, computeSkillHash, SKILL_HASHES_TABLE_SQL,

View File

@@ -0,0 +1,32 @@
/**
* SecretStore — where Waggle keeps API keys, connector tokens and other
* secrets (P1.2). Code that reads or writes secrets depends on this interface;
* `VaultStore` is the file-backed implementation (AES-256-GCM entries in
* `vault.json`, key in `.vault-key` protected by owner-only permissions).
*/
export interface SecretEntry {
name: string;
value: string;
metadata?: Record<string, unknown>;
updatedAt: string;
}
export interface SecretSummary {
name: string;
metadata?: Record<string, unknown>;
updatedAt: string;
}
export interface SecretStore {
/** The decrypted secret, or null when it is missing or cannot be read. */
get(name: string): SecretEntry | null;
set(name: string, value: string, metadata?: Record<string, unknown>): void;
setAsync(name: string, value: string, metadata?: Record<string, unknown>): Promise<void>;
/** Returns true when the secret existed. */
delete(name: string): boolean;
deleteAsync(name: string): Promise<boolean>;
/** Names and metadata, never values. */
list(): SecretSummary[];
has(name: string): boolean;
}

View File

@@ -12,6 +12,7 @@ import * as fs from 'node:fs';
import * as path from 'node:path';
import { execFileSync } from 'node:child_process';
import { createCoreLogger } from './logger.js';
import type { SecretEntry, SecretStore } from './secret-store.js';
const log = createCoreLogger('vault');
const ALGORITHM = 'aes-256-gcm';
@@ -25,12 +26,7 @@ const IV_LENGTH = 16;
*/
const windowsKeyAclChecked = new Set<string>();
export interface VaultEntry {
name: string;
value: string;
metadata?: Record<string, unknown>;
updatedAt: string;
}
export type VaultEntry = SecretEntry;
interface VaultRecord {
encrypted: string;
@@ -46,7 +42,8 @@ interface ConnectorCredentialInput {
scopes?: string[];
}
export class VaultStore {
/** The file-backed SecretStore. */
export class VaultStore implements SecretStore {
private dataDir: string;
private vaultPath: string;
private keyPath: string;