From c0f0421f8ab3de8511c7073c37020e6c298ef78d Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Wed, 2 Nov 2022 23:43:37 +0100 Subject: [PATCH] for r, dont use bigint but hex string --- lnbits/extensions/cashu/static/js/dhke.js | 8 +++++--- lnbits/extensions/cashu/templates/cashu/wallet.html | 10 ++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lnbits/extensions/cashu/static/js/dhke.js b/lnbits/extensions/cashu/static/js/dhke.js index c35a34e9..935bf6d4 100644 --- a/lnbits/extensions/cashu/static/js/dhke.js +++ b/lnbits/extensions/cashu/static/js/dhke.js @@ -21,14 +21,16 @@ async function hashToCurve(secretMessage) { async function step1Alice(secretMessage) { const Y = await hashToCurve(secretMessage) - const r = bytesToNumber(nobleSecp256k1.utils.randomPrivateKey()) + const rpk = nobleSecp256k1.utils.randomPrivateKey() + const r = bytesToNumber(rpk) const P = nobleSecp256k1.Point.fromPrivateKey(r) const B_ = Y.add(P) - return {B_: B_.toHex(true), r} + return {B_: B_.toHex(true), r: nobleSecp256k1.utils.bytesToHex(rpk)} } function step3Alice(C_, r, A) { - const rInt = BigInt(r) + // const rInt = BigInt(r) + const rInt = bytesToNumber(r) const C = C_.subtract(A.multiply(rInt)) return C } diff --git a/lnbits/extensions/cashu/templates/cashu/wallet.html b/lnbits/extensions/cashu/templates/cashu/wallet.html index 4af9c148..105c1e08 100644 --- a/lnbits/extensions/cashu/templates/cashu/wallet.html +++ b/lnbits/extensions/cashu/templates/cashu/wallet.html @@ -1060,7 +1060,11 @@ page_container %} promiseToProof: function (id, amount, C_hex, secret, r) { const C_ = nobleSecp256k1.Point.fromHex(C_hex) const A = this.keys[amount] - const C = step3Alice(C_, r, nobleSecp256k1.Point.fromHex(A)) + const C = step3Alice( + C_, + nobleSecp256k1.utils.hexToBytes(r), + nobleSecp256k1.Point.fromHex(A) + ) return { id, amount, @@ -1226,7 +1230,9 @@ page_container %} const rs = [] for (let i = 0; i < amounts.length; i++) { const secret = nobleSecp256k1.utils.randomBytes(32) - // const secret = nobleSecp256k1.utils.hexToBytes('0000000000000000000000000000000000000000000000000000000000000003') + // const secret = nobleSecp256k1.utils.hexToBytes( + // '0000000000000000000000000000000000000000000000000000000000000000' + // ) // todo: base64Url const encodedSecret = uint8ToBase64.encode(secret) secrets.push(encodedSecret)