Compare commits

..

5 Commits

2 changed files with 13 additions and 3 deletions

View File

@ -40,7 +40,7 @@ function setup() {
try {
let query = Query.fromBinary(data);
events.emit("response", query, origin);
events.emit("query", query, origin);
} catch {}
});
}
@ -100,6 +100,9 @@ const plugin: Plugin = {
events.on("create", async (message: Message, origin: Buffer) => {
let newEntry = entryFromMessage(message);
if (!newEntry.signature?.length) {
return;
}
if (!verifyEntry(newEntry)) {
return;
}

View File

@ -1,9 +1,16 @@
import { SignedRegistryEntry } from "./types.js";
import * as ed from "@noble/ed25519";
import b4a from "b4a";
import { sha512 } from "@noble/hashes/sha512";
ed.utils.sha512Sync = (...m) => sha512(ed.utils.concatBytes(...m));
export function verifyEntry(entry: SignedRegistryEntry) {
return ed.sync.verify(entry.signature, createSignatureData(entry), entry.pk);
return ed.sync.verify(
entry.signature,
createSignatureData(entry),
entry.pk.slice(1)
);
}
export function signEntry(
@ -16,7 +23,7 @@ export function signEntry(
export function createSignatureData(entry: SignedRegistryEntry): Uint8Array {
return b4a.concat([
encodeEndian(entry.revision, 8),
entry.data.length,
b4a.from([entry.data.length]),
entry.data,
]);
}