@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
36 lines • 1.45 kB
JavaScript
/**
* Why an account principal is no longer current (D11 S3-4), or `undefined` while it is: the host must still be signed
* into the attested account, and the attestation must not have reached `attestedUntil`.
*/
export function accountLapse(principal, authority) {
const hostAccount = authority?.hostAccount();
if (hostAccount === undefined)
return "presenter_account_unavailable";
if (hostAccount !== principal.acc)
return "presenter_account_mismatch";
return Date.now() / 1000 < principal.attestedUntil ? undefined : "attestation_expired";
}
/** One timer per account principal that revokes it at `attestedUntil`; each re-attestation re-arms it. */
export class AttestationExpiry {
constructor() {
this.timers = new Map();
}
arm(principal, expire) {
this.clear(principal);
const delay = Math.max(0, principal.attestedUntil * 1000 - Date.now());
const timer = setTimeout(expire, delay);
// The host's own lifetime decides when it exits; a pending expiry never holds the process.
timer.unref();
this.timers.set(principal, timer);
}
clear(principal) {
clearTimeout(this.timers.get(principal));
this.timers.delete(principal);
}
dispose() {
for (const timer of this.timers.values())
clearTimeout(timer);
this.timers.clear();
}
}
//# sourceMappingURL=mcp-presenter-account-lifetime.js.map