mirror of https://github.com/waku-org/js-waku.git
Use Uint8Array instead of hex string for hash
This commit is contained in:
parent
595fb877eb
commit
b3f4686da1
|
@ -1,8 +1,7 @@
|
||||||
import * as secp from "@noble/secp256k1";
|
import * as secp from "@noble/secp256k1";
|
||||||
import { keccak256 } from "js-sha3";
|
|
||||||
import { concat } from "uint8arrays/concat";
|
import { concat } from "uint8arrays/concat";
|
||||||
|
|
||||||
import { randomBytes } from "../crypto";
|
import { keccak256, randomBytes } from "../crypto";
|
||||||
import { hexToBytes } from "../utils";
|
import { hexToBytes } from "../utils";
|
||||||
|
|
||||||
import * as ecies from "./ecies";
|
import * as ecies from "./ecies";
|
||||||
|
@ -239,7 +238,7 @@ function getSignature(message: Uint8Array): Uint8Array {
|
||||||
return message.slice(message.length - SignatureLength, message.length);
|
return message.slice(message.length - SignatureLength, message.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getHash(message: Uint8Array, isSigned: boolean): string {
|
function getHash(message: Uint8Array, isSigned: boolean): Uint8Array {
|
||||||
if (isSigned) {
|
if (isSigned) {
|
||||||
return keccak256(message.slice(0, message.length - SignatureLength));
|
return keccak256(message.slice(0, message.length - SignatureLength));
|
||||||
}
|
}
|
||||||
|
@ -247,7 +246,7 @@ function getHash(message: Uint8Array, isSigned: boolean): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
function ecRecoverPubKey(
|
function ecRecoverPubKey(
|
||||||
messageHash: string,
|
messageHash: Uint8Array,
|
||||||
signature: Uint8Array
|
signature: Uint8Array
|
||||||
): Uint8Array | undefined {
|
): Uint8Array | undefined {
|
||||||
const recoveryDataView = new DataView(signature.slice(64).buffer);
|
const recoveryDataView = new DataView(signature.slice(64).buffer);
|
||||||
|
@ -255,7 +254,7 @@ function ecRecoverPubKey(
|
||||||
const _signature = secp.Signature.fromCompact(signature.slice(0, 64));
|
const _signature = secp.Signature.fromCompact(signature.slice(0, 64));
|
||||||
|
|
||||||
return secp.recoverPublicKey(
|
return secp.recoverPublicKey(
|
||||||
hexToBytes(messageHash),
|
messageHash,
|
||||||
_signature,
|
_signature,
|
||||||
recovery,
|
recovery,
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
|
Loading…
Reference in New Issue