summaryrefslogtreecommitdiff
path: root/src/lib/pgp/trust.ts
diff options
context:
space:
mode:
authorJoão Augusto Costa Branco Marado Torres <torres.dev@disroot.org>2025-06-24 12:08:41 -0300
committerJoão Augusto Costa Branco Marado Torres <torres.dev@disroot.org>2025-06-24 12:50:43 -0300
commitf9a77c5c27aede4e5978eb55d9b7af781b680a1d (patch)
treed545e325ba1ae756fc2eac66fac1001b6753c40d /src/lib/pgp/trust.ts
feat!: initial commit
Signed-off-by: João Augusto Costa Branco Marado Torres <torres.dev@disroot.org>
Diffstat (limited to 'src/lib/pgp/trust.ts')
-rw-r--r--src/lib/pgp/trust.ts19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/lib/pgp/trust.ts b/src/lib/pgp/trust.ts
new file mode 100644
index 0000000..cf022b4
--- /dev/null
+++ b/src/lib/pgp/trust.ts
@@ -0,0 +1,19 @@
+import type { Key } from "npm:openpgp@^6.1.1";
+import { TRUSTED_KEYS_DIR } from "../../consts.ts";
+import { createKeysFromDir } from "./create.ts";
+import type { AsyncYieldType } from "../../utils/iterator.ts";
+import { equal, getCall } from "../../utils/anonymous.ts";
+
+let trusted:
+ | Iterable<AsyncYieldType<ReturnType<typeof createKeysFromDir>>>
+ | undefined = undefined;
+
+const fingerprints = () =>
+ Iterator.from(trusted ?? []).map(getCall("getFingerprint"));
+
+export async function keyTrust(key: Key): Promise<number> {
+ if (trusted === undefined) {
+ trusted = await Array.fromAsync(createKeysFromDir(TRUSTED_KEYS_DIR));
+ }
+ return fingerprints().some(equal(key.getFingerprint())) ? 255 : 0;
+}