token-guardian
Version:
A comprehensive solution for protecting and managing API tokens and secrets
112 lines (111 loc) • 3.21 kB
TypeScript
import { TokenConfig } from '../interfaces/TokenConfig';
/**
* Stored token data structure
*/
interface StoredToken {
value: string;
config: TokenConfig;
expiry: Date | null;
created: Date;
lastUsed: Date | null;
}
/**
/**
* Audit log entry structure
*/
export interface AuditLogEntry {
tokenName: string;
action: string;
timestamp: Date;
details?: {
configType?: string;
hasNewExpiry?: boolean;
[key: string]: unknown;
};
}
/**
* Secure storage for protected tokens
*/
export declare class TokenStore {
private tokens;
private encryptionKey;
private auditLog;
/**
* Creates a new TokenStore
* @param encryptionKey Key used for encrypting tokens
*/
constructor(encryptionKey: string);
/**
* Stores a token securely
* @param tokenName The name/identifier of the token
* @param tokenValue The token value
* @param config Configuration for the token
* @returns True if the token was stored successfully
*/
storeToken(tokenName: string, tokenValue: string, config: TokenConfig): boolean;
/**
* Updates an existing token
* @param tokenName The name/identifier of the token
* @param newValue The new token value
* @param newExpiry Optional new expiry date
* @returns True if the token was updated successfully
*/
updateToken(tokenName: string, newValue: string, newExpiry?: Date | null): boolean;
/**
* Retrieves a token
* @param tokenName The name/identifier of the token
* @returns The decrypted token value, or null if not found
*/
getToken(tokenName: string): {
value: string;
config: TokenConfig;
} | null;
/**
* Gets token data including metadata
* @param tokenName The name/identifier of the token
* @returns The token data, or null if not found
*/
getTokenData(tokenName: string): StoredToken | null;
/**
* Records usage of a token for auditing
* @param tokenName The name/identifier of the token
*/
recordTokenUsage(tokenName: string): void;
/**
* Removes a token
* @param tokenName The name/identifier of the token
* @returns True if the token was removed successfully
*/
removeToken(tokenName: string): boolean;
/**
* Gets a list of all stored token names
* @returns Array of token names
*/
listTokens(): string[];
/**
* Gets the audit log
* @param tokenName Optional token name to filter logs
* @returns Array of audit log entries
*/
getAuditLog(tokenName?: string): AuditLogEntry[];
/**
* Logs an action for auditing
* @param tokenName The name/identifier of the token
* @param action The action performed
* @param details Optional details about the action
*/
private logAction;
/**
* Encrypts a value with the encryption key
* @param value The value to encrypt
* @returns Encrypted value
*/
private encrypt;
/**
* Decrypts a value with the encryption key
* @param encrypted The encrypted value
* @returns Decrypted value
*/
private decrypt;
}
export {};