mirror of
https://github.com/arnaucube/blindsecp256k1-js.git
synced 2026-02-06 19:06:42 +01:00
Padding the hex strings being hashed to 32 bytes
This commit is contained in:
16
src/index.ts
16
src/index.ts
@@ -93,8 +93,8 @@ export function blind(m: BigInteger, signerR: Point): { mBlinded: BigInteger, us
|
||||
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 @@ function random(bytes: number) {
|
||||
} 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user