Closed andrea-dintino closed 10 months ago
They are in sync with https://github.com/dyne/Zenroom/blob/master/docs/pages/python.md just checked are 4mnths old... seems maintained no? Anyway you can contribute correction directly there, the edits are automatically published on pipy and dev.zenroom.org
Also please use this as example for Python:
from zenroom import zenroom
keys = '{ "participant": { "keyring": { "ethereum": "6b4f32fc48ff19f0c184f1b7c593fbe26633421798191931c210a3a9bb46ae22" } } }'
data = '{ "myString": "I love the Beatles, all but 3", "participant ethereum address": "0x2B8070975AF995Ef7eb949AE28ee7706B9039504" }'
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'
Given I have a 'string' named 'myString'
Given I have a 'ethereum address' named 'participant ethereum address'
# Here we are creating the signature according to EIP712
When I create the ethereum signature of 'myString'
When I rename the 'ethereum signature' to 'myString.ethereum-signature'
# Here we copy the signature, which we'll print in a different format
When I copy 'myString.ethereum-signature' to 'myString.ethereum-signature.rsv'
# Here we print the signature in the regular 65 bytes long 'signaure hash' format
When I create ethereum address from ethereum signature 'myString.ethereum-signature' of 'myString'
When I copy 'ethereum address' to 'newEthereumAddress'
If I verify 'newEthereumAddress' is equal to 'participant ethereum address'
Then print string 'all good, the recovered ethereum address matches the original one'
Endif
Then print the 'myString.ethereum-signature'
Then print the 'newEthereumAddress'
# Here we print the copy of the signature in the [r,s,v], simply printing it as 'hex'
Then print the 'myString.ethereum-signature.rsv' as 'hex'
"""
result = zenroom.zencode_exec(contract, "", keys, data)
print(result.output)
Example usage of zencode_exec(script, keys=None, data=None, conf=None)
src https://pypi.org/project/zenroom/
Remember that it changed the invocation order
-zencode_exec(script, keys=None, data=None, conf=None)
+zencode_exec(script, conf=None, keys=None, data=None)
Also, that as you said in the chat, the second example would go out
We have been removing support for Lua direct execution, for security reasons
I suggest small modifications on the proposed example from the previous reply.
In fact, it might be better to accept "python objects" as arguments, because looks like a "better integration with python"
from zenroom import zenroom
import json
conf = {}
keys = {
"participant": {
"keyring": {
"ethereum": "6b4f32fc48ff19f0c184f1b7c593fbe26633421798191931c210a3a9bb46ae22"
}
}
}
data = {
"myString": "I love the Beatles, all but 3",
"participant ethereum address": "0x2B8070975AF995Ef7eb949AE28ee7706B9039504"
}
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'
Given I have a 'string' named 'myString'
Given I have a 'ethereum address' named 'participant ethereum address'
# Here we are creating the signature according to EIP712
When I create the ethereum signature of 'myString'
When I rename the 'ethereum signature' to 'myString.ethereum-signature'
# Here we copy the signature, which we'll print in a different format
When I copy 'myString.ethereum-signature' to 'myString.ethereum-signature.rsv'
# Here we print the signature in the regular 65 bytes long 'signaure hash' format
When I create ethereum address from ethereum signature 'myString.ethereum-signature' of 'myString'
When I copy 'ethereum address' to 'newEthereumAddress'
If I verify 'newEthereumAddress' is equal to 'participant ethereum address'
Then print string 'all good, the recovered ethereum address matches the original one'
Endif
Then print the 'myString.ethereum-signature'
Then print the 'newEthereumAddress'
# Here we print the copy of the signature in the [r,s,v], simply printing it as 'hex'
Then print the 'myString.ethereum-signature.rsv' as 'hex'
"""
result = zenroom.zencode_exec(contract, json.dumps(conf), json.dumps(keys), json.dumps(data))
print(result.output)
from zenroom import zenroom import json conf = {}
Please pay attention that the conf
is a string in this https://dev.zenroom.org/#/pages/how-to-embed?id=configuration-directives format "debug=3,logfmt=json"
@puria I blindly supposed that the conf
would be similar to keys
and data
https://dev.zenroom.org/#/pages/zenroom-config
You can pass Zenroom several attributes, wrapped in quotes and separated by a comma
then it doesnot make sense to use conf as python-object-json
using it this way, it works because later it says:
conf = ""
# (...)
result = zenroom.zencode_exec(contract, conf, json.dumps(keys), json.dumps(data))
In https://www.npmjs.com/package/zenroom , they also recommend doing the json thing; another way would be to explain it somehow the same to have more coherence
Yes, both on cli, js, and python the calls are binded to the same primitives that is zencode_exec
and that actually accepts just strings.
So the data
and keys
are escaped json (means JSON.stringify
in js world and json.dumps
in python). But the conf
has that one special syntax:
key=value,key2=value
that's why I pointed out in the provious comment, if you put a dict in there will not gonna work ;p
Ah I understand...! You thought I wrote that code, but it's actually a quote. Unfortunately the M$ github interface does not help so much! There is a small gray line on the left ;p
Fixed by #776
This 2:
https://pypi.org/project/zenroom/
https://dev.zenroom.org/#/pages/python
are badly outdated