Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

chore: fix verifySignature #66

Merged
merged 2 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class PubsubBaseProtocol extends EventEmitter {
}

// Check the message signature if present
if (message.signature && !verifySignature(message)) {
if (message.signature && !(await verifySignature(message))) {
throw errcode(new Error('Invalid message signature'), codes.ERR_INVALID_SIGNATURE)
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/message/sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ async function signMessage (peerId, message) {

/**
* Verifies the signature of the given message
* @param {rpc.RPC.Message} message
* @param {InMessage} message
* @returns {Promise<Boolean>}
*/
async function verifySignature (message) {
// Get message sans the signature
const baseMessage = { ...message }
delete baseMessage.signature
delete baseMessage.key
if (typeof baseMessage.from === 'string') {
baseMessage.from = PeerId.createFromB58String(baseMessage.from).toBytes()
}
const bytes = Buffer.concat([
SignPrefix,
Message.encode(baseMessage)
Expand Down