From 8b1e66e4e9b0e438dbf880f426deb33587b8852a Mon Sep 17 00:00:00 2001 From: matcha Date: Sun, 4 Oct 2026 02:46:48 +0000 Subject: [PATCH] Consolidate Persimmons source --- extension/vault-session.mjs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 extension/vault-session.mjs diff --git a/extension/vault-session.mjs b/extension/vault-session.mjs new file mode 100644 index 0000000..0634b22 --- /dev/null +++ b/extension/vault-session.mjs @@ -0,0 +1,17 @@ +// Memory only. Nothing here is serialized to storage or exposed externally. +export const AUTO_LOCK = 'human-auto-lock'; +export const policies = ['close', '5', '15', '60']; +export class VaultSession { + constructor(now = Date.now) { this.now = now; this.clear(); } + clear() { this.key = null; this.owner = null; this.deadline = 0; this.policy = 'close'; this.epoch = (this.epoch || 0) + 1; } + set(key, owner, policy) { + if (!policies.includes(policy) || key.extractable !== false) throw new Error('Invalid session'); + this.clear(); this.key = key; this.owner = owner; this.policy = policy; + this.deadline = policy === 'close' ? Infinity : this.now() + Number(policy) * 60000; + } + get(owner) { + if (this.now() >= this.deadline || owner !== this.owner) this.clear(); + return this.key; + } + closed() { if (this.policy === 'close') this.clear(); } +}