fix: type incompatibilities (#75)

This commit is contained in:
Irakli Gozalishvili
2020-12-02 01:33:13 -08:00
committed by GitHub
parent bac57b05dc
commit 67a5f51805
23 changed files with 180 additions and 94 deletions

View File

@ -40,6 +40,7 @@ async function verifySignature (message) {
const baseMessage = { ...message }
delete baseMessage.signature
delete baseMessage.key
// @ts-ignore - from is optional
baseMessage.from = PeerId.createFromCID(baseMessage.from).toBytes()
const bytes = uint8ArrayConcat([
SignPrefix,
@ -50,6 +51,7 @@ async function verifySignature (message) {
const pubKey = await messagePublicKey(message)
// verify the base message
// @ts-ignore - may not have signature
return pubKey.verify(bytes, message.signature)
}
@ -62,6 +64,7 @@ async function verifySignature (message) {
*/
async function messagePublicKey (message) {
// should be available in the from property of the message (peer id)
// @ts-ignore - from is optional
const from = PeerId.createFromCID(message.from)
if (message.key) {
@ -78,6 +81,11 @@ async function messagePublicKey (message) {
}
}
/**
* @typedef {import('..').InMessage} InMessage
* @typedef {import('libp2p-crypto').PublicKey} PublicKey
*/
module.exports = {
messagePublicKey,
signMessage,