Consolidate Persimmons source
This commit is contained in:
1 parent
6366ca8094
commit
8b1e66e4e9
1 file changed
+17
@@ -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(); }
|
||||
}
|
||||
Reference in new issue
Block a user