Pass Uint8Array when possible

This commit is contained in:
Franck Royer 2022-05-20 10:20:06 +10:00
parent 5648f72d3d
commit ce0c5cef07
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 3 additions and 5 deletions

View File

@ -100,9 +100,9 @@ export function clearDecode(
const isSigned = isMessageSigned(buf); const isSigned = isMessageSigned(buf);
if (isSigned) { if (isSigned) {
const signature = getSignature(buf); const signature = getSignature(message);
const hash = getHash(buf, isSigned); const hash = getHash(message, isSigned);
const publicKey = ecRecoverPubKey(hash, Buffer.from(signature)); const publicKey = ecRecoverPubKey(hash, signature);
sig = { signature, publicKey }; sig = { signature, publicKey };
} }
@ -277,8 +277,6 @@ function ecRecoverPubKey(
messageHash: string, messageHash: string,
signature: Uint8Array signature: Uint8Array
): Uint8Array | undefined { ): Uint8Array | undefined {
// TODO: This is only needed because we are getting a `Buffer` instance.
signature = new Uint8Array(signature);
const recoveryDataView = new DataView(signature.slice(64).buffer); const recoveryDataView = new DataView(signature.slice(64).buffer);
const recovery = recoveryDataView.getUint8(0); const recovery = recoveryDataView.getUint8(0);
const _signature = secp.Signature.fromCompact(signature.slice(0, 64)); const _signature = secp.Signature.fromCompact(signature.slice(0, 64));