28 lines
948 B
TypeScript
28 lines
948 B
TypeScript
import type { IServerAccountStore, IServerAccount } from './server.interfaces.js';
|
|
|
|
/**
|
|
* In-memory account storage for the ACME server.
|
|
*/
|
|
export class MemoryAccountStore implements IServerAccountStore {
|
|
private accounts = new Map<string, IServerAccount>();
|
|
private byThumbprint = new Map<string, string>();
|
|
private byUrl = new Map<string, string>();
|
|
|
|
async create(account: IServerAccount): Promise<IServerAccount> {
|
|
this.accounts.set(account.id, account);
|
|
this.byThumbprint.set(account.thumbprint, account.id);
|
|
this.byUrl.set(account.url, account.id);
|
|
return account;
|
|
}
|
|
|
|
async getByThumbprint(thumbprint: string): Promise<IServerAccount | null> {
|
|
const id = this.byThumbprint.get(thumbprint);
|
|
return id ? this.accounts.get(id) || null : null;
|
|
}
|
|
|
|
async getByUrl(url: string): Promise<IServerAccount | null> {
|
|
const id = this.byUrl.get(url);
|
|
return id ? this.accounts.get(id) || null : null;
|
|
}
|
|
}
|