From ffb658ac2c4ecf05e8616726eee55196c825def0 Mon Sep 17 00:00:00 2001 From: Cayman Date: Mon, 20 Jul 2020 01:00:15 -0500 Subject: [PATCH 1/2] chore: fix verifySignature --- src/index.js | 2 +- src/message/sign.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 89d4e8f..da307cd 100644 --- a/src/index.js +++ b/src/index.js @@ -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) } } diff --git a/src/message/sign.js b/src/message/sign.js index 89e124f..eec4ba6 100644 --- a/src/message/sign.js +++ b/src/message/sign.js @@ -29,7 +29,7 @@ async function signMessage (peerId, message) { /** * Verifies the signature of the given message - * @param {rpc.RPC.Message} message + * @param {InMessage} message * @returns {Promise} */ async function verifySignature (message) { @@ -37,6 +37,9 @@ async function verifySignature (message) { 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) @@ -46,7 +49,7 @@ async function verifySignature (message) { const pubKey = await messagePublicKey(message) // verify the base message - return pubKey.verify(bytes, message.signature) + return await pubKey.verify(bytes, message.signature) } /** From 51f0a5fc77cc6591e6226440072c123a9ed45fb7 Mon Sep 17 00:00:00 2001 From: Cayman Date: Mon, 20 Jul 2020 09:36:48 -0500 Subject: [PATCH 2/2] chore: update src/message/sign.js Co-authored-by: Vasco Santos --- src/message/sign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/message/sign.js b/src/message/sign.js index eec4ba6..a12f37d 100644 --- a/src/message/sign.js +++ b/src/message/sign.js @@ -49,7 +49,7 @@ async function verifySignature (message) { const pubKey = await messagePublicKey(message) // verify the base message - return await pubKey.verify(bytes, message.signature) + return pubKey.verify(bytes, message.signature) } /**