Esempio n. 1
0
def gen_keys(mnemonic):

    w = Wallet(mnemonic)
    sk, opk = w.derive_account("eth", account=0)
    sk = PrivateKey(sk)
    pk = PublicKey(opk)

    return sk, pk, opk
def generate_account():
    """Create a digital wallet and Ethereum account from a mnemonic seed phrase."""
    # Fetch mnemonic from environment variable.
    mnemonic = os.getenv("MNEMONIC")

    # Create Wallet Object
    wallet = Wallet(mnemonic)

    # Derive Ethereum Private Key
    private, public = wallet.derive_account("eth")

    # Convert private key into an Ethereum account
    account = Account.privateKeyToAccount(private)

    return account
Esempio n. 3
0
def prueba():
    if not os.path.exists("words.txt"):
        mnemo = Mnemonic("english")
        words = mnemo.generate(strength=256)

        with open("words.txt", 'w') as f:
            f.write(words)

        print(words)
    else:
        with open("words.txt", 'r') as f:
            words = f.read()
    print(words)
    w = Wallet(words)
    sk, pk = w.derive_account("TESTNET", account=0, address_index=0)
    sk = PrivateKey(sk)
    pk_bytes = bytes.fromhex(pk) if isinstance(pk, str) else pk
    if len(pk_bytes) != 64:
        pk_bytes = PublicKey(pk_bytes).format(False)[1:]
    print(sk.to_der())
Esempio n. 4
0

words = mnemo.generate(strength=128)

seed = mnemo.to_seed(words, passphrase="")


#print(seed)



from coincurve import PrivateKey,PublicKey
from bip44 import Wallet
from bip44.utils import get_eth_addr
mnemonic = "purity tunnel grid error scout long fruit false embody caught skin gate"
w = Wallet(mnemonic)
sk, pk = w.derive_account("eth", account=0)
sk = PrivateKey(sk)
print(sk.public_key.format() == pk)

pk=PublicKey(pk)



print(pk)





Esempio n. 5
0
import qrcode
import qrcode.image.svg
import six
from mnemonic import Mnemonic
from bip44 import Wallet
from bip44.utils import get_eth_addr

def generate_qrcode(string, size=128):
    stream = six.BytesIO()
    qrcode.make(string, image_factory=qrcode.image.svg.SvgImage, box_size=10).save(stream)
    b64_image_string = base64.b64encode(stream.getvalue()).decode('utf-8')
    return f"<img  width='128' src='data:image/svg+xml;base64,{ b64_image_string }'>"

mnemo = Mnemonic("english")
words = mnemo.generate()
w = Wallet(words)
sk, pk = w.derive_account("eth", account=0)

print("CS address: %s" % get_eth_addr(pk))
print("Private key in hex format: %s" % sk.hex())
addr = get_eth_addr(pk)
addr_qr = generate_qrcode(addr)

words_qr = generate_qrcode(words)

url = BLOCK_EXPLORER_URL + addr
url_qr = generate_qrcode(url)
sk_qr = generate_qrcode(sk.hex())
file_loader = FileSystemLoader('.')
env = Environment(loader=file_loader)
template = env.get_template('template.html')