feat: secret stuff

This commit is contained in:
Vlad Stan
2022-10-10 22:56:03 +03:00
parent 8af4f95cc1
commit 422711649f
5 changed files with 146 additions and 59 deletions
+12 -7
View File
@@ -1,15 +1,19 @@
async function hashToCurve(secretMessage) {
console.log(
'### secretMessage',
nobleSecp256k1.utils.bytesToHex(secretMessage)
)
let point
while (!point) {
const hash = await nobleSecp256k1.utils.sha256(secretMessage)
const hashHex = nobleSecp256k1.utils.bytesToHex(hash)
const pointX = '02' + hashHex
console.log('### pointX', pointX)
try {
point = nobleSecp256k1.Point.fromHex(hash)
point = nobleSecp256k1.Point.fromHex(pointX)
console.log('### point', point.toHex())
} catch (error) {
// console.error(error)
// const x = bytesToNumber(hash) + ''
// const msg = await nobleSecp256k1.utils.sha256(x)
secretMessage = await nobleSecp256k1.utils.sha256(hash)
// secretMessage = nobleSecp256k1.utils.bytesToHex(msg)
secretMessage = await nobleSecp256k1.utils.sha256(secretMessage)
}
}
return point
@@ -26,6 +30,7 @@ async function step1Bob(secretMessage) {
}
function step3Bob(C_, r, A) {
const C = C_.subtract(A.multiply(r))
const rInt = BigInt(r)
const C = C_.subtract(A.multiply(rInt))
return C
}