mirror of
https://github.com/planetmint/planetmint.git
synced 2026-02-21 02:52:59 +00:00
250 migrate zenroom script usage within planetmint so that tx schema 21 is used (#253)
* * **Changed** adjusted to zenroom calling convention of PRP #13 (breaking change) * **Changed** zenroom test cases to comply to the new calling convention * **Fixed** zenroom signing bug (call of wrong function) * **Changed** using cryptoconditions 0.10.0 * **Deprecated** usage of ripde160md as a address generation algorithm, isn't available from python 3.9.14 on, skipping these tests from now on. * **Changed** script/ouptut tag to be of type array or object for schema v3.0 and v2.0 * **Changed** added 'script' handling to the common/transactions.py class * **Fixed** data input handling to the transaction fullfillment methods Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> * connected the version string in the banner of 'planetmint start' to the planetmint/version.py variables. Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> * added input validation to the transaction script parsing and passing Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> * added backend support for the scripts Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> * adjusted tests to the new zenroom calling convention Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> * blackified the code Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> * increased version to 1.1.0 Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> * fixed docs building issues of dependency inheritance Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
@@ -6,7 +6,7 @@ RUN apt-get update \
|
||||
&& apt-get clean
|
||||
RUN apt-get install -y vim
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y build-essential cmake openssh-client openssh-server
|
||||
RUN apt-get install -y build-essential cmake openssh-client openssh-server git
|
||||
RUN apt-get install -y zsh
|
||||
|
||||
RUN mkdir -p /src
|
||||
@@ -15,6 +15,7 @@ RUN pip install --upgrade \
|
||||
pytest~=6.2.5 \
|
||||
pycco \
|
||||
websocket-client~=0.47.0 \
|
||||
planetmint-cryptoconditions>=0.9.9 \
|
||||
planetmint-cryptoconditions>=0.10.0 \
|
||||
planetmint-driver>=9.2.0 \
|
||||
blns
|
||||
RUN pip install base58 pynacl==1.4.0 zenroom==2.1.0.dev1655293214 pyasn1==0.4.8 cryptography==3.4.7
|
||||
|
||||
@@ -5,17 +5,16 @@
|
||||
|
||||
import pytest
|
||||
|
||||
CONDITION_SCRIPT = """
|
||||
Scenario 'ecdh': create the signature of an object
|
||||
CONDITION_SCRIPT = """Scenario 'ecdh': create the signature of an object
|
||||
Given I have the 'keyring'
|
||||
Given that I have a 'string dictionary' named 'houses' inside 'asset'
|
||||
Given that I have a 'string dictionary' named 'houses'
|
||||
When I create the signature of 'houses'
|
||||
Then print the 'signature'"""
|
||||
|
||||
FULFILL_SCRIPT = """Scenario 'ecdh': Bob verifies the signature from Alice
|
||||
Given I have a 'ecdh public key' from 'Alice'
|
||||
Given that I have a 'string dictionary' named 'houses' inside 'asset'
|
||||
Given I have a 'signature' named 'signature' inside 'metadata'
|
||||
Given that I have a 'string dictionary' named 'houses'
|
||||
Given I have a 'signature' named 'signature'
|
||||
When I verify the 'houses' has a signature in 'signature' by 'Alice'
|
||||
Then print the string 'ok'"""
|
||||
|
||||
@@ -33,25 +32,24 @@ GENERATE_KEYPAIR = """Scenario 'ecdh': Create the keypair
|
||||
When I create the bitcoin key
|
||||
Then print data"""
|
||||
|
||||
ZENROOM_DATA = {"also": "more data"}
|
||||
|
||||
HOUSE_ASSETS = {
|
||||
"data": {
|
||||
"houses": [
|
||||
{
|
||||
"name": "Harry",
|
||||
"team": "Gryffindor",
|
||||
},
|
||||
{
|
||||
"name": "Draco",
|
||||
"team": "Slytherin",
|
||||
},
|
||||
],
|
||||
}
|
||||
INITIAL_STATE = {"also": "more data"}
|
||||
SCRIPT_INPUT = {
|
||||
"houses": [
|
||||
{
|
||||
"name": "Harry",
|
||||
"team": "Gryffindor",
|
||||
},
|
||||
{
|
||||
"name": "Draco",
|
||||
"team": "Slytherin",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
metadata = {"units": 300, "type": "KG"}
|
||||
|
||||
ZENROOM_DATA = {"that": "is my data"}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def gen_key_zencode():
|
||||
@@ -75,7 +73,12 @@ def condition_script_zencode():
|
||||
|
||||
@pytest.fixture
|
||||
def zenroom_house_assets():
|
||||
return HOUSE_ASSETS
|
||||
return SCRIPT_INPUT
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def zenroom_script_input():
|
||||
return SCRIPT_INPUT
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@@ -3,6 +3,7 @@ import base58
|
||||
from hashlib import sha3_256
|
||||
from cryptoconditions.types.zenroom import ZenroomSha256
|
||||
from planetmint_driver.crypto import generate_keypair
|
||||
|
||||
from .helper.hosts import Hosts
|
||||
from zenroom import zencode_exec
|
||||
import time
|
||||
@@ -14,6 +15,7 @@ def test_zenroom_signing(
|
||||
fulfill_script_zencode,
|
||||
zenroom_data,
|
||||
zenroom_house_assets,
|
||||
zenroom_script_input,
|
||||
condition_script_zencode,
|
||||
):
|
||||
|
||||
@@ -24,17 +26,11 @@ def test_zenroom_signing(
|
||||
bob = json.loads(zencode_exec(gen_key_zencode).output)["keyring"]
|
||||
|
||||
zen_public_keys = json.loads(
|
||||
zencode_exec(
|
||||
secret_key_to_private_key_zencode.format("Alice"),
|
||||
keys=json.dumps({"keyring": alice}),
|
||||
).output
|
||||
zencode_exec(secret_key_to_private_key_zencode.format("Alice"), keys=json.dumps({"keyring": alice})).output
|
||||
)
|
||||
zen_public_keys.update(
|
||||
json.loads(
|
||||
zencode_exec(
|
||||
secret_key_to_private_key_zencode.format("Bob"),
|
||||
keys=json.dumps({"keyring": bob}),
|
||||
).output
|
||||
zencode_exec(secret_key_to_private_key_zencode.format("Bob"), keys=json.dumps({"keyring": bob})).output
|
||||
)
|
||||
)
|
||||
|
||||
@@ -68,9 +64,19 @@ def test_zenroom_signing(
|
||||
],
|
||||
}
|
||||
metadata = {"result": {"output": ["ok"]}}
|
||||
|
||||
script_ = {
|
||||
"code": {"type": "zenroom", "raw": "test_string", "parameters": [{"obj": "1"}, {"obj": "2"}]},
|
||||
"state": "dd8bbd234f9869cab4cc0b84aa660e9b5ef0664559b8375804ee8dce75b10576",
|
||||
"input": zenroom_script_input,
|
||||
"output": ["ok"],
|
||||
"policies": {},
|
||||
}
|
||||
|
||||
token_creation_tx = {
|
||||
"operation": "CREATE",
|
||||
"asset": zenroom_house_assets,
|
||||
"asset": {"data": {"test": "my asset"}},
|
||||
"script": script_,
|
||||
"metadata": metadata,
|
||||
"outputs": [
|
||||
output,
|
||||
@@ -83,39 +89,44 @@ def test_zenroom_signing(
|
||||
}
|
||||
|
||||
# JSON: serialize the transaction-without-id to a json formatted string
|
||||
message = json.dumps(
|
||||
tx = json.dumps(
|
||||
token_creation_tx,
|
||||
sort_keys=True,
|
||||
separators=(",", ":"),
|
||||
ensure_ascii=False,
|
||||
)
|
||||
|
||||
script_ = json.dumps(script_)
|
||||
# major workflow:
|
||||
# we store the fulfill script in the transaction/message (zenroom-sha)
|
||||
# the condition script is used to fulfill the transaction and create the signature
|
||||
#
|
||||
# the server should ick the fulfill script and recreate the zenroom-sha and verify the signature
|
||||
|
||||
message = zenroomscpt.sign(message, condition_script_zencode, alice)
|
||||
assert zenroomscpt.validate(message=message)
|
||||
signed_input = zenroomscpt.sign(script_, condition_script_zencode, alice)
|
||||
|
||||
message = json.loads(message)
|
||||
input_signed = json.loads(signed_input)
|
||||
input_signed["input"]["signature"] = input_signed["output"]["signature"]
|
||||
del input_signed["output"]["signature"]
|
||||
del input_signed["output"]["logs"]
|
||||
input_signed["output"] = ["ok"] # define expected output that is to be compared
|
||||
input_msg = json.dumps(input_signed)
|
||||
|
||||
assert zenroomscpt.validate(message=input_msg)
|
||||
|
||||
tx = json.loads(tx)
|
||||
fulfillment_uri_zen = zenroomscpt.serialize_uri()
|
||||
|
||||
message["inputs"][0]["fulfillment"] = fulfillment_uri_zen
|
||||
tx = message
|
||||
tx["inputs"][0]["fulfillment"] = fulfillment_uri_zen
|
||||
tx["script"] = input_signed
|
||||
tx["id"] = None
|
||||
json_str_tx = json.dumps(tx, sort_keys=True, skipkeys=False, separators=(",", ":"))
|
||||
# SHA3: hash the serialized id-less transaction to generate the id
|
||||
shared_creation_txid = sha3_256(json_str_tx.encode()).hexdigest()
|
||||
message["id"] = shared_creation_txid
|
||||
|
||||
tx["id"] = shared_creation_txid
|
||||
hosts = Hosts("/shared/hostnames")
|
||||
pm_alpha = hosts.get_connection()
|
||||
|
||||
sent_transfer_tx = pm_alpha.transactions.send_commit(message)
|
||||
sent_transfer_tx = pm_alpha.transactions.send_commit(tx)
|
||||
time.sleep(1)
|
||||
|
||||
# Assert that transaction is stored on both planetmint nodes
|
||||
hosts.assert_transaction(shared_creation_txid)
|
||||
print(f"\n\nstatus and result : + {sent_transfer_tx}")
|
||||
|
||||
Reference in New Issue
Block a user