From 519b3759535097a24910a125ab763e0aa817fbdd Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sat, 5 Nov 2022 17:24:33 +0100 Subject: [PATCH] comments --- cashu/core/b_dhke.py | 9 +++++++-- cashu/core/base.py | 4 +++- cashu/core/legacy.py | 8 ++++++-- cashu/mint/router.py | 4 +++- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/cashu/core/b_dhke.py b/cashu/core/b_dhke.py index 5c83ddc..8d0d6db 100644 --- a/cashu/core/b_dhke.py +++ b/cashu/core/b_dhke.py @@ -2,23 +2,28 @@ """ Implementation of https://gist.github.com/RubenSomsen/be7a4760dd4596d06963d67baf140406 -Alice: + +Alice (Client): A = a*G return A -Bob: + +Bob (Mint): Y = hash_to_curve(secret_message) r = random blinding factor B'= Y + r*G return B' + Alice: C' = a*B' (= a*Y + a*r*G) return C' + Bob: C = C' - r*A (= C' - a*r*G) (= a*Y) return C, secret_message + Alice: Y = hash_to_curve(secret_message) C == a*Y diff --git a/cashu/core/base.py b/cashu/core/base.py index 6e4989f..d39db5e 100644 --- a/cashu/core/base.py +++ b/cashu/core/base.py @@ -14,7 +14,9 @@ class P2SHScript(BaseModel): class Proof(BaseModel): - id: Union[None, str] = "" + id: Union[ + None, str + ] = "" # NOTE: None for backwards compatibility of old clients < 0.3 amount: int = 0 secret: str = "" C: str = "" diff --git a/cashu/core/legacy.py b/cashu/core/legacy.py index 6abd9c1..7434bdf 100644 --- a/cashu/core/legacy.py +++ b/cashu/core/legacy.py @@ -4,8 +4,12 @@ from secp256k1 import PublicKey def hash_to_point_pre_0_3_3(secret_msg): - """Generates x coordinate from the message hash and checks if the point lies on the curve. - If it does not, it tries computing again a new x coordinate from the hash of the coordinate.""" + """ + NOTE: Clients pre 0.3.3 used a different hash_to_curve + + Generates x coordinate from the message hash and checks if the point lies on the curve. + If it does not, it tries computing again a new x coordinate from the hash of the coordinate. + """ point = None msg = secret_msg while point is None: diff --git a/cashu/mint/router.py b/cashu/mint/router.py index db18cee..09ca2e2 100644 --- a/cashu/mint/router.py +++ b/cashu/mint/router.py @@ -104,8 +104,10 @@ async def split( """ proofs = payload.proofs amount = payload.amount + + # NOTE: backwards compatibility with clients < v0.2.2 outputs = payload.outputs.blinded_messages if payload.outputs else None - # backwards compatibility with clients < v0.2.2 + assert outputs, Exception("no outputs provided.") try: split_return = await ledger.split(proofs, amount, outputs)