Skip to content

Commit

Permalink
ethwalletbypassword Get wallets fpom miner by password in private blo…
Browse files Browse the repository at this point in the history
…ckchain
  • Loading branch information
Ignat99 committed Sep 19, 2024
1 parent ba1447a commit b2096b4
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
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

0 comments on commit b2096b4

Please sign in to comment.