Merge pull request #5 from brickpop/feature/import-point-hex Padding the hex strings being hashed to 32 bytes
arnau 17317030+arnaucube@users.noreply.github.com
Fri, 05 Feb 2021 23:34:35 +0100
1 files changed,
12 insertions(+),
4 deletions(-)
jump to
M
src/index.ts
→
src/index.ts
@@ -93,8 +93,8 @@ const ainv = u.a.modInverse(n as unknown as number)
const ainvrx = ainv.multiply(rx) const mHex = m.toString(16) - const hHex = keccak256('0x' + mHex) - const h = BigInteger.fromHex(hHex.slice(2)) + const hHex = keccak256('0x' + zeroPad(mHex, 32)).substr(2) + const h = BigInteger.fromHex(hHex) const mBlinded = ainvrx.multiply(h) return { mBlinded: mBlinded.mod(n), userSecretData: u }@@ -121,8 +121,8 @@ export function verify(m: BigInteger, s: UnblindedSignature, q: Point) {
const sG = G.multiply(s.s) const mHex = m.toString(16) - const hHex = keccak256('0x' + mHex) - const h = BigInteger.fromHex(hHex.slice(2)) + const hHex = keccak256('0x' + zeroPad(mHex, 32)).substr(2) + const h = BigInteger.fromHex(hHex) const rx = s.f.affineX.mod(n) const right = s.f.add(@@ -147,3 +147,11 @@ k = BigInteger.fromByteArrayUnsigned(randomBytes(bytes)) as unknown as BigInteger
} while (k.toString() == '0' && k.gcd(n).toString() != '1') return k } + +function zeroPad(hexString: string, byteLength: number) { + if (hexString.length > (byteLength * 2)) throw new Error("Out of bounds") + while (hexString.length < (byteLength * 2)) { + hexString = "0" + hexString + } + return hexString +}