Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.
Merged
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
28 changes: 13 additions & 15 deletions src/message/sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,25 @@ async function verifySignature (message) {
* @returns {Promise<PublicKey>}
*/
async function messagePublicKey (message) {
// should be available in the from property of the message (peer id)
let from
if (typeof message.from === 'string') {
from = PeerId.createFromB58String(message.from)
} else {
from = PeerId.createFromBytes(message.from)
}

if (message.key) {
const peerId = await PeerId.createFromPubKey(message.key)
const keyPeerId = await PeerId.createFromPubKey(message.key)

// the key belongs to the sender, return the key
if (peerId.isEqual(message.from)) return peerId.pubKey
if (keyPeerId.isEqual(from)) return keyPeerId.pubKey
// We couldn't validate pubkey is from the originator, error
throw new Error('Public Key does not match the originator')
} else if (from.pubKey) {
return from.pubKey
} else {
// should be available in the from property of the message (peer id)
let from
if (typeof message.from === 'string') {
from = PeerId.createFromB58String(message.from)
} else {
from = PeerId.createFromBytes(message.from)
}

if (from.pubKey) {
return from.pubKey
} else {
throw new Error('Could not get the public key from the originator id')
}
throw new Error('Could not get the public key from the originator id')
}
}

Expand Down