mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 20:25:26 +00:00
55 lines
1.1 KiB
TypeScript
55 lines
1.1 KiB
TypeScript
import fs from "node:fs/promises";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
interface Cache {
|
|
certificates:
|
|
| {
|
|
signerCert: Buffer | string;
|
|
signerKey: Buffer | string;
|
|
wwdr: Buffer | string;
|
|
signerKeyPassphrase: string;
|
|
}
|
|
| undefined;
|
|
}
|
|
|
|
const cache: Cache = {
|
|
certificates: undefined,
|
|
};
|
|
|
|
export async function getCertificates(): Promise<
|
|
Exclude<Cache["certificates"], undefined>
|
|
> {
|
|
if (cache.certificates) {
|
|
return cache.certificates;
|
|
}
|
|
|
|
const [signerCert, signerKey, wwdr, signerKeyPassphrase] =
|
|
await Promise.all([
|
|
fs.readFile(
|
|
path.resolve(__dirname, "../../../certificates/signerCert.pem"),
|
|
"utf-8",
|
|
),
|
|
fs.readFile(
|
|
path.resolve(__dirname, "../../../certificates/signerKey.pem"),
|
|
"utf-8",
|
|
),
|
|
fs.readFile(
|
|
path.resolve(__dirname, "../../../certificates/WWDR.pem"),
|
|
"utf-8",
|
|
),
|
|
Promise.resolve("123456"),
|
|
]);
|
|
|
|
cache.certificates = {
|
|
signerCert,
|
|
signerKey,
|
|
wwdr,
|
|
signerKeyPassphrase,
|
|
};
|
|
|
|
return cache.certificates;
|
|
}
|