const tokenStore = new Map();
let registered = false;
export function storeToken(key, token) {
    const existing = tokenStore.get(key);
    if (existing) {
        existing.fill(0);
    }
    tokenStore.set(key, Buffer.from(token, "utf-8"));
}
export function readToken(key) {
    const buf = tokenStore.get(key);
    if (!buf)
        return undefined;
    return buf.toString("utf-8");
}
export function clearAllTokens() {
    for (const buf of tokenStore.values()) {
        buf.fill(0);
    }
    tokenStore.clear();
}
export function registerCleanupHandlers() {
    if (registered)
        return;
    registered = true;
    process.on("exit", clearAllTokens);
    process.on("SIGINT", () => {
        clearAllTokens();
        process.exit(130);
    });
    process.on("SIGTERM", () => {
        clearAllTokens();
        process.exit(0);
    });
}
//# sourceMappingURL=tokenBuffer.js.map