diff --git a/src/crypto/README.md b/src/crypto/README.md index ac00951f5..f344e486a 100644 --- a/src/crypto/README.md +++ b/src/crypto/README.md @@ -85,6 +85,7 @@ Common crypto errors come with the interface, and can be imported directly. All ```js const { InvalidCryptoExchangeError, + InvalidCryptoTransmissionError, UnexpectedPeerError } = require('libp2p-interfaces/src/crypto/errors') @@ -95,4 +96,5 @@ console.log(error.code === UnexpectedPeerError.code) // true ### Error Types - `InvalidCryptoExchangeError` - Should be thrown when a peer provides data that is insufficient to finish the crypto exchange. +- `InvalidCryptoTransmissionError` - Should be thrown when an error occurs during encryption/decryption. - `UnexpectedPeerError` - Should be thrown when the expected peer id does not match the peer id determined via the crypto exchange. diff --git a/src/crypto/errors.js b/src/crypto/errors.js index dc6af4612..2c8f661cb 100644 --- a/src/crypto/errors.js +++ b/src/crypto/errors.js @@ -22,7 +22,19 @@ class InvalidCryptoExchangeError extends Error { } } +class InvalidCryptoTransmissionError extends Error { + constructor (message = 'Invalid crypto transmission') { + super(message) + this.code = InvalidCryptoTransmissionError.code + } + + static get code () { + return 'ERR_INVALID_CRYPTO_TRANSMISSION' + } +} + module.exports = { UnexpectedPeerError, - InvalidCryptoExchangeError + InvalidCryptoExchangeError, + InvalidCryptoTransmissionError }