Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ethwalletbypassword #926

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions docs/examples/zencode_cookbook/ethereum/doc_key_pass.py
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 15 additions & 0 deletions docs/pages/zencode-scenarios-ethereum.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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


Expand Down