I want to convert a node JS buffer to a hex string. Obviously, I googled this first, but none of the proposed solutions work.
For example, in this question a comment below the accepted answer says you should do it like this:
let signature4 = Buffer.from(signature3.r, 'hex') + Buffer.from(signature3.s, 'hex') + Buffer.from(signature3.v, 'hex');
But this yields:
TypeError [ERR_INVALID_ARG_TYPE]: The "value" argument must not be of type number. Received type number
If I go for the actual answer which tells me to do it like this:
let signature4 = signature3.r.toString('hex') + signature3.s.toString('hex') + signature3.v.toString('hex');
I get this error:
RangeError: toString() radix argument must be between 2 and 36
If I follow the advice given in the error message and enter 16 as a number like so:
let signature4 = signature3.r.toString(16) + signature3.s.toString(16) + signature3.v.toString(16);
I get this error message:
TypeError [ERR_UNKNOWN_ENCODING]: Unknown encoding: 16
If I instead pass 16 as a string:
let signature4 = signature3.r.toString('16') + signature3.s.toString('16') + signature3.v.toString('16');
I get the same error message:
TypeError [ERR_UNKNOWN_ENCODING]: Unknown encoding: 16
So what's the current way of doing it?
I use Node v10.18.1.