mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-20 18:44:20 +01:00
* init flake8 * exclude nostr client, and add ds_store to gitignore * fix flake8 F811 issue, redefinition of unused variables * add flake8 to workflow * F401 unused imports * F541 f-string is missing placeholders * E501 line too long > 150 characters * E722 no bare except * E402 module level import not at top of file * F405 no star imports * E712 comparison to False should be 'if cond is False:' * F841 local variable is assigned to but never used * E266 too many leading '#' for block comment * E265, E261 * E713 test for membership should be 'not in' * E711, E741 E741 ambiguous variable name 'l' E711 comparison to None should be 'if cond is None:' * flake config * isort * refactor makefile flake8 usage * reflaking the rebase * black * fix tests? * black * fix line lenght it test_cli * sort out makefile * fix strings * reintroduce black-check * reflake and mypy * isort * Update cashu/wallet/wallet.py Co-authored-by: Angus Pearson <angus@toaster.cc> * Update cashu/mint/ledger.py Co-authored-by: Angus Pearson <angus@toaster.cc> --------- Co-authored-by: Angus Pearson <angus@toaster.cc>
52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
import hashlib
|
|
|
|
from secp256k1 import PrivateKey, PublicKey
|
|
|
|
from ..core.settings import settings
|
|
|
|
|
|
def hash_to_point_pre_0_3_3(secret_msg):
|
|
"""
|
|
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:
|
|
_hash = hashlib.sha256(msg).hexdigest().encode("utf-8") # type: ignore
|
|
try:
|
|
# We construct compressed pub which has x coordinate encoded with even y
|
|
_hash = list(_hash[:33]) # take the 33 bytes and get a list of bytes
|
|
_hash[0] = 0x02 # set first byte to represent even y coord
|
|
_hash = bytes(_hash)
|
|
point = PublicKey(_hash, raw=True)
|
|
except Exception:
|
|
msg = _hash
|
|
|
|
return point
|
|
|
|
|
|
def verify_pre_0_3_3(a, C, secret_msg):
|
|
Y = hash_to_point_pre_0_3_3(secret_msg.encode("utf-8"))
|
|
return C == Y.mult(a) # type: ignore
|
|
|
|
|
|
def derive_keys_backwards_compatible_insecure_pre_0_12(
|
|
master_key: str, derivation_path: str = ""
|
|
):
|
|
"""
|
|
WARNING: Broken key derivation for backwards compatibility with 0.11.
|
|
"""
|
|
return {
|
|
2
|
|
** i: PrivateKey(
|
|
hashlib.sha256((master_key + derivation_path + str(i)).encode("utf-8"))
|
|
.hexdigest()
|
|
.encode("utf-8")[:32],
|
|
raw=True,
|
|
)
|
|
for i in range(settings.max_order)
|
|
}
|