2022-11-30 16:24:13 +01:00
|
|
|
async function hashToCurve(secretMessage) {
|
|
|
|
let point
|
|
|
|
while (!point) {
|
|
|
|
const hash = await nobleSecp256k1.utils.sha256(secretMessage)
|
|
|
|
const hashHex = nobleSecp256k1.utils.bytesToHex(hash)
|
|
|
|
const pointX = '02' + hashHex
|
|
|
|
try {
|
|
|
|
point = nobleSecp256k1.Point.fromHex(pointX)
|
|
|
|
} catch (error) {
|
|
|
|
secretMessage = await nobleSecp256k1.utils.sha256(secretMessage)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return point
|
|
|
|
}
|
|
|
|
|
|
|
|
async function step1Alice(secretMessage) {
|
|
|
|
secretMessage = uint8ToBase64.encode(secretMessage)
|
|
|
|
secretMessage = new TextEncoder().encode(secretMessage)
|
|
|
|
const Y = await hashToCurve(secretMessage)
|
2023-01-30 09:29:44 +01:00
|
|
|
const r_bytes = nobleSecp256k1.utils.randomPrivateKey()
|
|
|
|
const r = bytesToNumber(r_bytes)
|
2022-11-30 16:24:13 +01:00
|
|
|
const P = nobleSecp256k1.Point.fromPrivateKey(r)
|
|
|
|
const B_ = Y.add(P)
|
2023-01-30 09:29:44 +01:00
|
|
|
return {B_: B_.toHex(true), r: nobleSecp256k1.utils.bytesToHex(r_bytes)}
|
2022-11-30 16:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function step3Alice(C_, r, A) {
|
|
|
|
const rInt = bytesToNumber(r)
|
|
|
|
const C = C_.subtract(A.multiply(rInt))
|
|
|
|
return C
|
|
|
|
}
|