Skip to content

Commit

Permalink
fix: sign vertex hash instead of vertex operation (#300)
Browse files Browse the repository at this point in the history
Co-authored-by: Oak <[email protected]>
  • Loading branch information
trungnotchung and d-roak authored Dec 29, 2024
1 parent 87bb515 commit 4220e72
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
8 changes: 3 additions & 5 deletions packages/node/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export async function signGeneratedVertices(node: DRPNode, vertices: Vertex[]) {
return;
}

await node.signVertexOperation(vertex);
await node.signVertex(vertex);
});

await Promise.all(signPromises);
Expand Down Expand Up @@ -260,9 +260,7 @@ export async function verifyIncomingVertices(
}

const publicKeyBytes = uint8ArrayFromString(publicKey, "base64");
const operationData = uint8ArrayFromString(
JSON.stringify(vertex.operation),
);
const data = uint8ArrayFromString(vertex.hash);

try {
const cryptoKey = await crypto.subtle.importKey(
Expand All @@ -277,7 +275,7 @@ export async function verifyIncomingVertices(
{ name: "Ed25519" },
cryptoKey,
signature,
operationData,
data,
);

return isValid ? vertex : null;
Expand Down
6 changes: 2 additions & 4 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,11 @@ export class DRPNode {
operations.syncObject(this, id, peerId);
}

async signVertexOperation(vertex: Vertex) {
async signVertex(vertex: Vertex) {
if (vertex.peerId !== this.networkNode.peerId) {
log.error("::signVertexOperation: Invalid peer id");
return "";
}
vertex.signature = await this.networkNode.sign(
JSON.stringify(vertex.operation),
);
vertex.signature = await this.networkNode.sign(vertex.hash);
}
}

0 comments on commit 4220e72

Please sign in to comment.