Compare commits

..

No commits in common. "4264ca099e420bf6d6d2fa295c17626baecde6d0" and "0df8050df88eb489d3e152d82dd4e9d32db8d1a2" have entirely different histories.

2 changed files with 3 additions and 13 deletions

View File

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

View File

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