Currently if you try to pass an invalid hex value as an ID, e.g. if you pass fieldIds: [ 'shhh' ] then encode and decode will work without error, but you will get back an empty string: fieldIds: [ '' ]. This is because Buffer.from('shhh', 'hex') returns an empty Buffer.
I think it makes sense to throw if any of these id fields is invalid. We should do:
function idBufferFromHex(idString) {
const buf = Buffer.from(idString, hex)
if (buf.length !== 32) throw new Error('invalid id, must be 32-bytes encoded as hex string')
return buf
Currently if you try to pass an invalid hex value as an ID, e.g. if you pass
fieldIds: [ 'shhh' ]then encode and decode will work without error, but you will get back an empty string:fieldIds: [ '' ]. This is becauseBuffer.from('shhh', 'hex')returns an empty Buffer.I think it makes sense to throw if any of these id fields is invalid. We should do: