mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-23 22:15:44 +00:00
zenroom unit tests are passing
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
b394831e39
commit
4fd071adeb
@ -8,7 +8,7 @@ from cryptoconditions.types.zenroom import ZenroomSha256
|
|||||||
from cryptoconditions.crypto import Ed25519SigningKey as SigningKey
|
from cryptoconditions.crypto import Ed25519SigningKey as SigningKey
|
||||||
from nacl.signing import VerifyKey
|
from nacl.signing import VerifyKey
|
||||||
from planetmint_driver.crypto import generate_keypair
|
from planetmint_driver.crypto import generate_keypair
|
||||||
|
from ast import literal_eval
|
||||||
import zenroom
|
import zenroom
|
||||||
|
|
||||||
CONDITION_SCRIPT = """Rule input encoding base58
|
CONDITION_SCRIPT = """Rule input encoding base58
|
||||||
@ -17,8 +17,8 @@ CONDITION_SCRIPT = """Rule input encoding base58
|
|||||||
Given I have the 'keys'
|
Given I have the 'keys'
|
||||||
Given that I have a 'string dictionary' named 'houses' inside 'asset'
|
Given that I have a 'string dictionary' named 'houses' inside 'asset'
|
||||||
When I create the signature of 'houses'
|
When I create the signature of 'houses'
|
||||||
When I rename the 'signature' to 'data.signature'
|
When I rename the 'signature' to 'signature'
|
||||||
Then print the 'data.signature'"""
|
Then print the 'signature'"""
|
||||||
|
|
||||||
FULFILL_SCRIPT = \
|
FULFILL_SCRIPT = \
|
||||||
"""Rule input encoding base58
|
"""Rule input encoding base58
|
||||||
@ -26,8 +26,8 @@ FULFILL_SCRIPT = \
|
|||||||
Scenario 'ecdh': Bob verifies the signature from Alice
|
Scenario 'ecdh': Bob verifies the signature from Alice
|
||||||
Given I have a 'ecdh public key' from 'Alice'
|
Given I have a 'ecdh public key' from 'Alice'
|
||||||
Given that I have a 'string dictionary' named 'houses' inside 'asset'
|
Given that I have a 'string dictionary' named 'houses' inside 'asset'
|
||||||
Given I have a 'signature' named 'data.signature' inside 'result'
|
Given I have a 'signature' named 'signature' inside 'result'
|
||||||
When I verify the 'houses' has a signature in 'data.signature' by 'Alice'
|
When I verify the 'houses' has a signature in 'signature' by 'Alice'
|
||||||
Then print the string 'ok'"""
|
Then print the string 'ok'"""
|
||||||
|
|
||||||
SK_TO_PK = \
|
SK_TO_PK = \
|
||||||
@ -380,55 +380,47 @@ def test_zenroom_signing():
|
|||||||
}
|
}
|
||||||
version = '2.0'
|
version = '2.0'
|
||||||
|
|
||||||
CONDITION_SCRIPT = """Rule input encoding base58
|
CONDITION_SCRIPT = """
|
||||||
Rule output encoding base58
|
|
||||||
Scenario 'ecdh': create the signature of an object
|
Scenario 'ecdh': create the signature of an object
|
||||||
Given I have the 'keys'
|
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' inside 'asset'
|
||||||
When I create the signature of 'houses'
|
When I create the signature of 'houses'
|
||||||
When I rename the 'signature' to 'data.signature'
|
Then print the 'signature'"""
|
||||||
Then print the 'data.signature'"""
|
|
||||||
|
|
||||||
FULFILL_SCRIPT = \
|
FULFILL_SCRIPT = \
|
||||||
"""Rule input encoding base58
|
"""Scenario 'ecdh': Bob verifies the signature from Alice
|
||||||
Rule output encoding base58
|
|
||||||
Scenario 'ecdh': Bob verifies the signature from Alice
|
|
||||||
Given I have a 'ecdh public key' from 'Alice'
|
Given I have a 'ecdh public key' from 'Alice'
|
||||||
Given that I have a 'string dictionary' named 'houses' inside 'asset'
|
Given that I have a 'string dictionary' named 'houses' inside 'asset'
|
||||||
Given I have a 'signature' named 'data.signature' inside 'result'
|
Given I have a 'signature' named 'signature' inside 'result'
|
||||||
When I verify the 'houses' has a signature in 'data.signature' by 'Alice'
|
When I verify the 'houses' has a signature in 'signature' by 'Alice'
|
||||||
Then print the string 'ok'"""
|
Then print the string 'ok'"""
|
||||||
|
|
||||||
SK_TO_PK = \
|
SK_TO_PK = \
|
||||||
"""Rule input encoding base58
|
"""Scenario 'ecdh': Create the keypair
|
||||||
Rule output encoding base58
|
|
||||||
Scenario 'ecdh': Create the keypair
|
|
||||||
Given that I am known as '{}'
|
Given that I am known as '{}'
|
||||||
Given I have the 'keys'
|
Given I have the 'keyring'
|
||||||
When I create the ecdh public key
|
When I create the ecdh public key
|
||||||
When I create the testnet address
|
When I create the bitcoin address
|
||||||
Then print my 'ecdh public key'
|
Then print my 'ecdh public key'
|
||||||
Then print my 'testnet address'"""
|
Then print my 'bitcoin address'"""
|
||||||
|
|
||||||
GENERATE_KEYPAIR = \
|
GENERATE_KEYPAIR = \
|
||||||
"""Rule input encoding base58
|
"""Scenario 'ecdh': Create the keypair
|
||||||
Rule output encoding base58
|
|
||||||
Scenario 'ecdh': Create the keypair
|
|
||||||
Given that I am known as 'Pippo'
|
Given that I am known as 'Pippo'
|
||||||
When I create the ecdh key
|
When I create the ecdh key
|
||||||
When I create the testnet key
|
When I create the bitcoin key
|
||||||
Then print data"""
|
Then print data"""
|
||||||
|
|
||||||
ZENROOM_DATA = {
|
ZENROOM_DATA = {
|
||||||
'also': 'more data'
|
'also': 'more data'
|
||||||
}
|
}
|
||||||
alice = json.loads(ZenroomSha256.run_zenroom(GENERATE_KEYPAIR).output)['keys']
|
alice = json.loads(ZenroomSha256.run_zenroom(GENERATE_KEYPAIR).output)['keyring']
|
||||||
bob = json.loads(ZenroomSha256.run_zenroom(GENERATE_KEYPAIR).output)['keys']
|
bob = json.loads(ZenroomSha256.run_zenroom(GENERATE_KEYPAIR).output)['keyring']
|
||||||
|
|
||||||
zen_public_keys = json.loads(ZenroomSha256.run_zenroom(SK_TO_PK.format('Alice'),
|
zen_public_keys = json.loads(ZenroomSha256.run_zenroom(SK_TO_PK.format('Alice'),
|
||||||
keys={'keys': alice}).output)
|
keys={'keyring': alice}).output)
|
||||||
zen_public_keys.update(json.loads(ZenroomSha256.run_zenroom(SK_TO_PK.format('Bob'),
|
zen_public_keys.update(json.loads(ZenroomSha256.run_zenroom(SK_TO_PK.format('Bob'),
|
||||||
keys={'keys': bob}).output))
|
keys={'keyring': bob}).output))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -438,11 +430,7 @@ def test_zenroom_signing():
|
|||||||
# CRYPTO-CONDITIONS: generate the condition uri
|
# CRYPTO-CONDITIONS: generate the condition uri
|
||||||
condition_uri_zen = zenroomscpt.condition.serialize_uri()
|
condition_uri_zen = zenroomscpt.condition.serialize_uri()
|
||||||
print(F'\nzenroom condition URI: {condition_uri_zen}')
|
print(F'\nzenroom condition URI: {condition_uri_zen}')
|
||||||
#print(F'condition_uri is: {condition_uri}')
|
|
||||||
# # print(F'condition_uri_zen is: {condition_uri_zen}')
|
|
||||||
# ZEN-CRYPTO-CONDITION: generate the condition did
|
|
||||||
#zen_condition_did = 'did:bdb:MIIBMxaCARoKICAgIC0tIGdlbmVyYXRlIGEgc2ltcGxlIGtleXJpbmcKICAgIGtleXJpbmcgPSBFQ0RILm5ldygpCiAgICBrZXlyaW5nOmtleWdlbigpCiAgICAKICAgIC0tIGV4cG9ydCB0aGUga2V5cGFpciB0byBqc29uCiAgICBleHBvcnQgPSBKU09OLmVuY29kZSgKICAgICAgIHsKICAgICAgICAgIHB1YmxpYyAgPSBrZXlyaW5nOiBwdWJsaWMoKTpiYXNlNjQoKSwKICAgICAgICAgIHByaXZhdGUgPSBrZXlyaW5nOnByaXZhdGUoKTpiYXNlNjQoKQogICAgICAgfQogICAgKQogICAgcHJpbnQoZXhwb3J0KQoWBE5vbmUWBE5vbmUWBE5vbmUCAQA='
|
|
||||||
|
|
||||||
# CRYPTO-CONDITIONS: construct an unsigned fulfillment dictionary
|
# CRYPTO-CONDITIONS: construct an unsigned fulfillment dictionary
|
||||||
unsigned_fulfillment_dict_zen = {
|
unsigned_fulfillment_dict_zen = {
|
||||||
'type': zenroomscpt.TYPE_NAME,
|
'type': zenroomscpt.TYPE_NAME,
|
||||||
@ -464,7 +452,7 @@ def test_zenroom_signing():
|
|||||||
}
|
}
|
||||||
token_creation_tx = {
|
token_creation_tx = {
|
||||||
'operation': 'CREATE',
|
'operation': 'CREATE',
|
||||||
'asset': HOUSE_ASSETS,#rfid_token,
|
'asset': HOUSE_ASSETS,
|
||||||
'metadata': None,
|
'metadata': None,
|
||||||
'outputs': [output,],
|
'outputs': [output,],
|
||||||
'inputs': [input_,],
|
'inputs': [input_,],
|
||||||
@ -493,15 +481,11 @@ def test_zenroom_signing():
|
|||||||
message = zenroomscpt.sign(message, CONDITION_SCRIPT, alice)
|
message = zenroomscpt.sign(message, CONDITION_SCRIPT, alice)
|
||||||
assert(zenroomscpt.validate(message=message))
|
assert(zenroomscpt.validate(message=message))
|
||||||
|
|
||||||
### WORkS until here
|
message = json.loads(message)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fulfillment_uri_zen = zenroomscpt.serialize_uri()
|
fulfillment_uri_zen = zenroomscpt.serialize_uri()
|
||||||
print(f'\nfulfillment_uri_zen is: {fulfillment_uri_zen}')
|
|
||||||
fulfillment_fromuri_zen = zenroomscpt.from_uri(fulfillment_uri_zen)
|
message['inputs'][0]['fulfillment'] = fulfillment_uri_zen
|
||||||
token_creation_tx['inputs'][0]['fulfillment'] = fulfillment_uri_zen
|
tx = message
|
||||||
tx = token_creation_tx
|
|
||||||
tx['id'] = None
|
tx['id'] = None
|
||||||
json_str_tx = json.dumps(
|
json_str_tx = json.dumps(
|
||||||
tx,
|
tx,
|
||||||
@ -511,18 +495,8 @@ def test_zenroom_signing():
|
|||||||
)
|
)
|
||||||
# SHA3: hash the serialized id-less transaction to generate the id
|
# SHA3: hash the serialized id-less transaction to generate the id
|
||||||
shared_creation_txid = sha3_256(json_str_tx.encode()).hexdigest()
|
shared_creation_txid = sha3_256(json_str_tx.encode()).hexdigest()
|
||||||
# add the id
|
message['id'] = shared_creation_txid
|
||||||
token_creation_tx['id'] = shared_creation_txid
|
|
||||||
#print(F'The TX to be consensed: {token_creation_tx}')
|
|
||||||
# send CREATE tx into the bdb network
|
|
||||||
##tx = signed_create_tx.to_dict()
|
|
||||||
##tx['id'] = None
|
|
||||||
##payload = json.dumps(tx, skipkeys=False, sort_keys=True,
|
|
||||||
## separators=(',', ':'))
|
|
||||||
##assert sha3_256(payload.encode()).hexdigest() == signed_create_tx.id
|
|
||||||
|
|
||||||
#returned_creation_tx = bdb.transactions.send_commit(token_creation_tx)
|
|
||||||
#tx = request.get_json(force=True)
|
|
||||||
|
|
||||||
from planetmint.transactions.types.assets.create import Create
|
from planetmint.transactions.types.assets.create import Create
|
||||||
from planetmint.transactions.types.assets.transfer import Transfer
|
from planetmint.transactions.types.assets.transfer import Transfer
|
||||||
@ -532,24 +506,20 @@ def test_zenroom_signing():
|
|||||||
from planetmint.transactions.common.transaction_mode_types import BROADCAST_TX_ASYNC
|
from planetmint.transactions.common.transaction_mode_types import BROADCAST_TX_ASYNC
|
||||||
validated = None
|
validated = None
|
||||||
try:
|
try:
|
||||||
tx_obj = Transaction.from_dict(token_creation_tx)
|
tx_obj = Transaction.from_dict(message)
|
||||||
except SchemaValidationError as e:
|
except SchemaValidationError as e:
|
||||||
assert()
|
assert()
|
||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
print(e)
|
print(e)
|
||||||
assert()
|
assert()
|
||||||
#pool = current_app.config['bigchain_pool']
|
|
||||||
#with pool() as planet:
|
|
||||||
#try:
|
|
||||||
from planetmint.lib import Planetmint
|
from planetmint.lib import Planetmint
|
||||||
planet = Planetmint()
|
planet = Planetmint()
|
||||||
validated = planet.validate_transaction(tx_obj)
|
validated = planet.validate_transaction(tx_obj)
|
||||||
print( f"\n\nVALIDATED =====: {validated}")
|
|
||||||
#except ValidationError as e:
|
|
||||||
# assert()
|
|
||||||
mode = BROADCAST_TX_ASYNC
|
mode = BROADCAST_TX_ASYNC
|
||||||
status_code, message = planet.write_transaction(tx_obj, mode)
|
status_code, message = planet.write_transaction(tx_obj, mode)
|
||||||
print( f"\n\nstatus and result : {status_code} + {message}")
|
print( f"\n\nstatus and result : {status_code} + {message}")
|
||||||
print( f"VALIDATED : {validated}")
|
print( f"VALIDATED : {validated}")
|
||||||
assert()
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user