Compare commits
5 Commits
0df8050df8
...
4264ca099e
Author | SHA1 | Date |
---|---|---|
Derrick Hammer | 4264ca099e | |
Derrick Hammer | 58330a2576 | |
Derrick Hammer | 787baef9a0 | |
Derrick Hammer | d7fe74cbce | |
Derrick Hammer | ce246ead59 |
|
@ -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;
|
||||
}
|
||||
|
|
11
src/utils.ts
11
src/utils.ts
|
@ -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,
|
||||
]);
|
||||
}
|
||||
|
|
Reference in New Issue