Allowing to decode points from the curve

This commit is contained in:
Jør∂¡
2021-02-04 18:32:19 +01:00
parent 1c8f9e6ffe
commit 3d3d3c0c8d
2 changed files with 28 additions and 12 deletions

View File

@@ -15,6 +15,11 @@ export const ecParams = { G, n }
export type UserSecretData = { a: BigNumber, b: BigNumber, f: Point }
export type UnblindedSignature = { s: BigNumber, f: Point }
export function messageToBigNumber(message: string) {
const msg = Buffer.from(message, 'utf8')
return new BigNumber(msg)
}
export function hashBigNumber(m: BigNumber) {
const mHex = m.toString(16)
@@ -24,10 +29,14 @@ export function hashBigNumber(m: BigNumber) {
return keccak256('0x0' + mHex).slice(2) // Trim 0x
}
export function bigNumberFromString(s: string) {
export function stringToBigNumber(s: string) {
return new BigNumber(s)
}
export function decodePoint(hexPoint: string): Point {
return secp256k1.keyFromPublic(Buffer.from(hexPoint, "hex")).getPublic()
}
function random(bytes: number) {
let k: BigNumber
do {
@@ -96,7 +105,7 @@ export function verify(m: BigNumber, s: UnblindedSignature, q: Point) {
const sG = G.mul(s.s)
const hHex = hashBigNumber(m)
const h = new BigNumber(Buffer.from(hHex, "hex"))
const rx = s.f.getX().mod(n)