diff --git a/docs/examples/zencode_cookbook/ethereum/doc_key_pass.py b/docs/examples/zencode_cookbook/ethereum/doc_key_pass.py new file mode 100644 index 000000000..f0cf7fcbb --- /dev/null +++ b/docs/examples/zencode_cookbook/ethereum/doc_key_pass.py @@ -0,0 +1,48 @@ +from web3 import Web3 +import eth_keys +from eth_account import account +from zenroom import zenroom +import json + +password = 'My_pass' +keyfile = open('./UTC--2024-07-16T10-09-46.525942921Z--e...1') +keyfile_contents = keyfile.read() +keyfile.close() + + +private_key = eth_keys.keys.PrivateKey(account.Account.decrypt(keyfile_contents, password)) +print(private_key) +public_key = private_key.public_key +print(public_key) + +private_key_str = str(private_key) + +conf = "" + +keys = { + "participant": { + "keyring": { + "ethereum": private_key_str + } + } +} + +data = { +} + + + + + +contract = """Scenario ethereum: sign ethereum message + +# Here we are loading the private key and the message to be signed +Given I am 'participant' +Given I have my 'keyring' +When I create the ethereum address +Then print my 'ethereum address' +Then print the keyring +""" + +result = zenroom.zencode_exec(contract, conf, json.dumps(keys), json.dumps(data)) +print(result.output) diff --git a/docs/pages/zencode-scenarios-ethereum.md b/docs/pages/zencode-scenarios-ethereum.md index 2b26fe120..0f0026f94 100644 --- a/docs/pages/zencode-scenarios-ethereum.md +++ b/docs/pages/zencode-scenarios-ethereum.md @@ -30,6 +30,19 @@ Then you can upload it with a script that looks like the following script: [](../_media/examples/zencode_cookbook/ethereum/doc_key_upload.zen ':include :type=code gherkin') +## Get a private key by password +If we use [private ethereum blockchain](https://medium.com/scb-digital/running-a-private-ethereum-blockchain-using-docker-589c8e6a4fe8), then our keyring located in docker conteiner: geth-miner. + +Path like that: /root/.ethereum/keystore/UTC--2024-07-16T10-09-46.525942921Z--e...1 + +Usually, access from the network is not possible to this file. But there is more or less [standard access](https://github.com/ethereum/go-ethereum/blob/master/cmd/clef/tutorial.md) + +The following script allows you to log in using only a password and automatically receives keyrings already generated by the miner. + + +[](../_media/examples/zencode_cookbook/ethereum/doc_key_pass.py ':include :type=code gherkin') + + ## Public key @@ -39,6 +52,8 @@ If, for any reason, you need the ethereum public key, then you can simply comput [](../_media/examples/zencode_cookbook/ethereum/doc_pubgen.zen ':include :type=code gherkin') + + # Create Ethereum address