Fix odd case where 0 is encoded as an empty byte array

This commit is contained in:
Franck Royer 2022-05-05 10:30:25 +10:00
parent ba8139441c
commit d30a918a44
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 3 additions and 1 deletions

View File

@ -88,7 +88,9 @@ export class ENR extends Map<ENRKey, ENRValue> {
dbg("Failed to decode ENR key to UTF-8, skipping it", kvs[i], e);
}
}
const enr = new ENR(obj, BigInt("0x" + bytesToHex(seq)), signature);
// If seq is an empty array, translate as value 0
const hexSeq = "0x" + (seq.length ? bytesToHex(seq) : "00");
const enr = new ENR(obj, BigInt(hexSeq), signature);
const rlpEncodedBytes = hexToBytes(RLP.encode([seq, ...kvs]));
if (!enr.verify(rlpEncodedBytes, signature)) {