fix: don't even try to refactor

This commit is contained in:
Vlad Stan 2022-10-07 14:51:06 +03:00 committed by dni ⚡
parent 2c8ebaf225
commit 7609f7ea5b
4 changed files with 20 additions and 12 deletions

View File

@ -93,6 +93,11 @@ async def delete_cashu(cashu_id) -> None:
##########################################
async def store_promises(amounts: List[int], B_s: List[str], C_s: List[str], cashu_id: str):
for amount, B_, C_ in zip(amounts, B_s, C_s):
await store_promise(amount, B_, C_, cashu_id)
async def store_promise(amount: int, B_: str, C_: str, cashu_id: str):
promise_id = urlsafe_short_hash()

View File

@ -3,7 +3,7 @@ from typing import List
from .core.b_dhke import step2_bob
from .core.base import BlindedSignature
from .core.secp import PublicKey
from .mint_helper import derive_key, derive_keys, derive_pubkeys
from .mint_helper import derive_keys, derive_pubkeys
# todo: extract const
MAX_ORDER = 64
@ -36,6 +36,6 @@ async def generate_promises(
async def generate_promise(master_prvkey: str, amount: int, B_: PublicKey):
"""Generates a promise for given amount and returns a pair (amount, C')."""
secret_key = derive_key(master_prvkey, amount) # Get the correct key
secret_key = derive_keys(master_prvkey)[amount] # Get the correct key
C_ = step2_bob(B_, secret_key)
return BlindedSignature(amount=amount, C_=C_.serialize().hex())

View File

@ -9,18 +9,18 @@ MAX_ORDER = 64
def derive_keys(master_key: str):
"""Deterministic derivation of keys for 2^n values."""
return {2**i: derive_key(master_key, i) for i in range(MAX_ORDER)}
return {
2
** i: PrivateKey(
hashlib.sha256((str(master_key) + str(i)).encode("utf-8"))
.hexdigest()
.encode("utf-8")[:32],
raw=True,
)
for i in range(MAX_ORDER)
}
def derive_key(master_key: str, i: int):
"""Deterministic derivation of keys for a particular value."""
return PrivateKey(
hashlib.sha256((str(master_key) + str(i)).encode("utf-8"))
.hexdigest()
.encode("utf-8")[:32],
raw=True,
)
def derive_pubkeys(keys: List[PrivateKey]):
return {amt: keys[amt].pubkey for amt in [2**i for i in range(MAX_ORDER)]}

View File

@ -300,6 +300,9 @@ async def mint_coins(
try:
promises = await generate_promises(cashu.prvkey, amounts, B_s)
for amount, B_, p in zip(amounts, B_s, promises):
await store_promise(amount, B_.serialize().hex(), p.C_, cashu_id)
# store_promises(amounts, B_s, C_s, cashu_id)
# await store_promise(amount, B_=B_.serialize().hex(), C_=C_.serialize().hex(), cashu_id)
return promises
except Exception as exc: