Skip to content

Commit

Permalink
chore: checkSignAndHashes
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Dec 27, 2024
1 parent 91dca82 commit 041adfa
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions packages/homeserver/src/routes/federation/checkSignAndHashes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import {
import { pruneEventDict } from "../../pruneEventDict";
import { MatrixError } from "../../errors";

export async function checkSignAndHashes(
pdu: SignedJson<HashedEvent<EventBase>>,
export async function checkSignAndHashes<T extends EventBase>(
pdu: T,
origin: string,
getPublicKeyFromServer: (origin: string, key: string) => Promise<string>,
) {
const { hashes, ...rest } = pdu;
): Promise<SignedJson<HashedEvent<T>>> {
const { hashes, ...rest } = pdu as SignedJson<HashedEvent<T>>;

const [signature] = await getSignaturesFromRemote(pdu, origin);

Expand All @@ -37,11 +37,10 @@ export async function checkSignAndHashes(

const [algorithm, hash] = computeHash(pdu);

const expectedHash = pdu.hashes[algorithm];
const expectedHash = (pdu as SignedJson<HashedEvent<T>>).hashes[algorithm];

if (hash !== expectedHash) {
throw new MatrixError("400", "Invalid hash");
}

return true;
return pdu as SignedJson<HashedEvent<T>>;
}

0 comments on commit 041adfa

Please sign in to comment.