mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-24 14:51:05 +01:00
fix: don't even try to refactor
This commit is contained in:
parent
2c8ebaf225
commit
7609f7ea5b
4 changed files with 20 additions and 12 deletions
|
@ -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):
|
async def store_promise(amount: int, B_: str, C_: str, cashu_id: str):
|
||||||
promise_id = urlsafe_short_hash()
|
promise_id = urlsafe_short_hash()
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ from typing import List
|
||||||
from .core.b_dhke import step2_bob
|
from .core.b_dhke import step2_bob
|
||||||
from .core.base import BlindedSignature
|
from .core.base import BlindedSignature
|
||||||
from .core.secp import PublicKey
|
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
|
# todo: extract const
|
||||||
MAX_ORDER = 64
|
MAX_ORDER = 64
|
||||||
|
@ -36,6 +36,6 @@ async def generate_promises(
|
||||||
|
|
||||||
async def generate_promise(master_prvkey: str, amount: int, B_: PublicKey):
|
async def generate_promise(master_prvkey: str, amount: int, B_: PublicKey):
|
||||||
"""Generates a promise for given amount and returns a pair (amount, C')."""
|
"""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)
|
C_ = step2_bob(B_, secret_key)
|
||||||
return BlindedSignature(amount=amount, C_=C_.serialize().hex())
|
return BlindedSignature(amount=amount, C_=C_.serialize().hex())
|
||||||
|
|
|
@ -9,18 +9,18 @@ MAX_ORDER = 64
|
||||||
|
|
||||||
def derive_keys(master_key: str):
|
def derive_keys(master_key: str):
|
||||||
"""Deterministic derivation of keys for 2^n values."""
|
"""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]):
|
def derive_pubkeys(keys: List[PrivateKey]):
|
||||||
return {amt: keys[amt].pubkey for amt in [2**i for i in range(MAX_ORDER)]}
|
return {amt: keys[amt].pubkey for amt in [2**i for i in range(MAX_ORDER)]}
|
||||||
|
|
|
@ -300,6 +300,9 @@ async def mint_coins(
|
||||||
|
|
||||||
try:
|
try:
|
||||||
promises = await generate_promises(cashu.prvkey, amounts, B_s)
|
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)
|
# await store_promise(amount, B_=B_.serialize().hex(), C_=C_.serialize().hex(), cashu_id)
|
||||||
return promises
|
return promises
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
|
Loading…
Add table
Reference in a new issue