better error checking

This commit is contained in:
Daniel Lugo 2020-01-29 12:36:16 -04:00
parent 03fe61f2e4
commit 44de364ae4

View file

@ -87,6 +87,12 @@ mySEA.decrypt = (encMsg, secret) => {
} }
mySEA.secret = (recipientOrSenderEpub, recipientOrSenderSEA) => { mySEA.secret = (recipientOrSenderEpub, recipientOrSenderSEA) => {
if (typeof recipientOrSenderEpub !== 'string') {
throw new TypeError('epub has to be an string')
}
if (typeof recipientOrSenderSEA !== 'object') {
throw new TypeError('sea has to be an object')
}
if (recipientOrSenderEpub === recipientOrSenderSEA.pub) { if (recipientOrSenderEpub === recipientOrSenderSEA.pub) {
throw new Error('Do not use pub for mysecret') throw new Error('Do not use pub for mysecret')
} }