Skip to content

Commit

Permalink
chore: Add peer id str to mismatch error (#273)
Browse files Browse the repository at this point in the history
* Add peer id str to mismatch error

* Update error messages
  • Loading branch information
dapplion authored Feb 20, 2023
1 parent 63c7cac commit 1990c6f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export async function verifySignedPayload (
// Unmarshaling from PublicKey protobuf
const payloadPeerId = await peerIdFromKeys(payload.identityKey)
if (!payloadPeerId.equals(remotePeer)) {
throw new Error("Peer ID doesn't match libp2p public key.")
throw new Error(`Payload identity key ${payloadPeerId.toString()} does not match expected remote peer ${remotePeer.toString()}`)
}
const generatedPayload = getHandshakePayload(noiseStaticKey)

Expand Down
4 changes: 2 additions & 2 deletions test/xx-handshake.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('XX Handshake', () => {
assert(false, 'Should throw exception')
} catch (e) {
const err = e as Error
expect(err.message).equals("Error occurred while verifying signed payload: Peer ID doesn't match libp2p public key.")
expect(err.message).equals(`Error occurred while verifying signed payload: Payload identity key ${peerB.toString()} does not match expected remote peer ${fakePeer.toString()}`)
}
})

Expand Down Expand Up @@ -120,7 +120,7 @@ describe('XX Handshake', () => {
assert(false, 'Should throw exception')
} catch (e) {
const err = e as Error
expect(err.message).equals("Error occurred while verifying signed payload: Peer ID doesn't match libp2p public key.")
expect(err.message).equals(`Error occurred while verifying signed payload: Payload identity key ${peerA.toString()} does not match expected remote peer ${fakePeer.toString()}`)
}
})
})

0 comments on commit 1990c6f

Please sign in to comment.