From 1a96423a4702dbf77518c8b1edaca1c114114924 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Fri, 23 Sep 2022 18:55:29 +0300 Subject: [PATCH] alice=client, bob=mint --- core/b_dhke.py | 12 ++++++------ mint/ledger.py | 13 +++++++++---- wallet/wallet.py | 8 ++++---- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/core/b_dhke.py b/core/b_dhke.py index e325c7a..32707c7 100644 --- a/core/b_dhke.py +++ b/core/b_dhke.py @@ -49,7 +49,7 @@ def hash_to_curve(secret_msg): return point -def step1_bob(secret_msg): +def step1_alice(secret_msg): secret_msg = secret_msg.encode("utf-8") Y = hash_to_curve(secret_msg) r = PrivateKey() @@ -57,12 +57,12 @@ def step1_bob(secret_msg): return B_, r -def step2_alice(B_, a): +def step2_bob(B_, a): C_ = B_.mult(a) return C_ -def step3_bob(C_, r, A): +def step3_alice(C_, r, A): C = C_ - A.mult(r) return C @@ -78,9 +78,9 @@ def verify(a, C, secret_msg): # a = PrivateKey() # A = a.pubkey # secret_msg = "test" -# B_, r = step1_bob(secret_msg) -# C_ = step2_alice(B_, a) -# C = step3_bob(C_, r, A) +# B_, r = step1_alice(secret_msg) +# C_ = step2_bob(B_, a) +# C = step3_alice(C_, r, A) # print("C:{}, secret_msg:{}".format(C, secret_msg)) # assert verify(a, C, secret_msg) # assert verify(a, C + C, secret_msg) == False # adding C twice shouldn't pass diff --git a/mint/ledger.py b/mint/ledger.py index 0ec9e51..f5ce49f 100644 --- a/mint/ledger.py +++ b/mint/ledger.py @@ -13,9 +13,14 @@ from core.secp import PrivateKey, PublicKey from core.settings import LIGHTNING, MAX_ORDER from core.split import amount_split from lightning import WALLET -from mint.crud import (get_lightning_invoice, get_proofs_used, - invalidate_proof, store_lightning_invoice, - store_promise, update_lightning_invoice) +from mint.crud import ( + get_lightning_invoice, + get_proofs_used, + invalidate_proof, + store_lightning_invoice, + store_promise, + update_lightning_invoice, +) class Ledger: @@ -58,7 +63,7 @@ class Ledger: async def _generate_promise(self, amount: int, B_: PublicKey): """Generates a promise for given amount and returns a pair (amount, C').""" secret_key = self.keys[amount] # Get the correct key - C_ = b_dhke.step2_alice(B_, secret_key) + C_ = b_dhke.step2_bob(B_, secret_key) await store_promise( amount, B_=B_.serialize().hex(), C_=C_.serialize().hex(), db=self.db ) diff --git a/wallet/wallet.py b/wallet/wallet.py index 0e48f05..f51d66c 100644 --- a/wallet/wallet.py +++ b/wallet/wallet.py @@ -52,7 +52,7 @@ class LedgerAPI: proofs = [] for promise, (r, secret) in zip(promises, secrets): C_ = PublicKey(bytes.fromhex(promise.C_), raw=True) - C = b_dhke.step3_bob(C_, r, self.keys[promise.amount]) + C = b_dhke.step3_alice(C_, r, self.keys[promise.amount]) proof = Proof(amount=promise.amount, C=C.serialize().hex(), secret=secret) proofs.append(proof) return proofs @@ -74,7 +74,7 @@ class LedgerAPI: for amount in amounts: secret = self._generate_secret() secrets.append(secret) - B_, r = b_dhke.step1_bob(secret) + B_, r = b_dhke.step1_alice(secret) rs.append(r) payload: BlindedMessage = BlindedMessage( amount=amount, B_=B_.serialize().hex() @@ -101,7 +101,7 @@ class LedgerAPI: payloads: MintPayloads = MintPayloads() for output_amt in fst_outputs + snd_outputs: secret = self._generate_secret() - B_, r = b_dhke.step1_bob(secret) + B_, r = b_dhke.step1_alice(secret) secrets.append((r, secret)) payload: BlindedMessage = BlindedMessage( amount=output_amt, B_=B_.serialize().hex() @@ -159,7 +159,7 @@ class Wallet(LedgerAPI): async def request_mint(self, amount): return super().request_mint(amount) - async def mint(self, amount, payment_hash=None): + async def mint(self, amount: int, payment_hash: str = None): split = amount_split(amount) proofs = super().mint(split, payment_hash) if proofs == []: