import { injectable } from "@codemation/core"; import type { HmacNonceStore } from "./HmacNonceStore"; @injectable() export class InMemoryHmacNonceStore implements HmacNonceStore { private readonly store = new Map(); async recordIfNew(nonce: string, expiresAt: Date): Promise { const nowSec = Math.floor(Date.now() / 1000); for (const [key, expirySec] of this.store.entries()) { if (expirySec <= nowSec) this.store.delete(key); } if (this.store.has(nonce)) return false; this.store.set(nonce, Math.floor(expiresAt.getTime() / 1000)); return true; } }