Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.

Commit d2fe2d1

Browse files
authored
feat: crypto errors (#4)
* chore: ignore docs folder * feat: add invalid crypto exchange error
1 parent bcb52ae commit d2fe2d1

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
build
88
dist
9+
docs
910

1011
# Dependency directory
1112
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git

src/crypto/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Common crypto errors come with the interface, and can be imported directly. All
8484

8585
```js
8686
const {
87+
InvalidCryptoExchangeError,
8788
UnexpectedPeerError
8889
} = require('libp2p-interfaces/src/crypto/errors')
8990

@@ -93,4 +94,5 @@ console.log(error.code === UnexpectedPeerError.code) // true
9394

9495
### Error Types
9596

96-
- `UnexpectedPeerError` - Should be thrown when the expected peer id does not match the peer id determined via the crypto exchange
97+
- `InvalidCryptoExchangeError` - Should be thrown when a peer provides data that is insufficient to finish the crypto exchange.
98+
- `UnexpectedPeerError` - Should be thrown when the expected peer id does not match the peer id determined via the crypto exchange.

src/crypto/errors.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ class UnexpectedPeerError extends Error {
1111
}
1212
}
1313

14+
class InvalidCryptoExchangeError extends Error {
15+
constructor (message = 'Invalid crypto exchange') {
16+
super(message)
17+
this.code = InvalidCryptoExchangeError.code
18+
}
19+
20+
static get code () {
21+
return 'ERR_INVALID_CRYPTO_EXCHANGE'
22+
}
23+
}
24+
1425
module.exports = {
15-
UnexpectedPeerError
26+
UnexpectedPeerError,
27+
InvalidCryptoExchangeError
1628
}

0 commit comments

Comments
 (0)