nakov / Practical-Cryptography-for-Developers-Book

Practical Cryptography for Developers: Hashes, MAC, Key Derivation, DHKE, Symmetric and Asymmetric Ciphers, Public Key Cryptosystems, RSA, Elliptic Curves, ECC, secp256k1, ECDH, ECIES, Digital Signatures, ECDSA, EdDSA
https://cryptobook.nakov.com
MIT License
3.42k stars 409 forks source link

ImportError: cannot import name 'sign', 'verify' #58

Open MilanObrenovic opened 1 year ago

MilanObrenovic commented 1 year ago

from pycoin.ecdsa import generator_secp256k1, sign, verify import hashlib, secrets

def sha3_256Hash(msg): hashBytes = hashlib.sha3_256(msg.encode("utf8")).digest() return int.from_bytes(hashBytes, byteorder="big")

def signECDSAsecp256k1(msg, privKey): msgHash = sha3_256Hash(msg) signature = sign(generator_secp256k1, privKey, msgHash) return signature

def verifyECDSAsecp256k1(msg, signature, pubKey): msgHash = sha3_256Hash(msg) valid = verify(generator_secp256k1, pubKey, msgHash, signature) return valid

i think the example code is broken or outdated. i cant import sign or verify at all

etherx-dev commented 1 year ago

download https://github.com/richardkiss/pycoin/releases/tag/0.70 and do

pip3 install pycoin-0.70.tar