Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def helper_make_response(self,payload):
return Response(
QueryResponse(
payload=payload,
signature=Signature(
pubkey=self.keypair.public_key,
signature=crypto.sign(self.keypair, crypto.sign_hash(payload))
)
Transaction(
payload = Transaction.Payload(
creator_account_id = "test@test",
created_time = tx.debug_proto_transaction().payload.created_time
),
signatures = [
Signature(
pubkey = keypairs[0].public_key,
signature = crypto.sign(
keypairs[0],
crypto.sign_hash(tx.debug_proto_transaction().payload)
)
),
Signature(
pubkey = keypairs[1].public_key,
signature = crypto.sign(
keypairs[1],
crypto.sign_hash(tx.debug_proto_transaction().payload)
)
created_time = crypto.now()
)
payload2 = Transaction.Payload(
commands = [
Command(create_account = create_ac)
],
creator_account_id = self.creator,
tx_counter = self.tx_counter,
created_time = crypto.now()+1
)
tx = Transaction(
payload = payload,
signatures = [
Signature(
pubkey = self.keypair.public_key,
signature = crypto.sign(self.keypair,crypto.sign_hash(payload2))
)
]
)
self.assertFalse(stateless_validator.verify(tx))
)
payload = Transaction.Payload(
commands = [
Command(create_account = create_ac)
],
creator_account_id = self.creator,
tx_counter = self.tx_counter,
created_time = crypto.now()
)
tx = Transaction(
payload = payload,
signatures = [
Signature(
pubkey = self.keypair.public_key,
signature = crypto.sign(self.keypair,crypto.sign_hash(payload))
)
]
)
self.assertTrue(stateless_validator.verify(tx))
)
payload = Transaction.Payload(
commands = [
Command(create_account = create_ac)
],
creator_account_id = self.creator,
tx_counter = self.tx_counter,
created_time = crypto.now()-3600*24*1000*10
)
tx = Transaction(
payload = payload,
signatures = [
Signature(
pubkey = self.keypair.public_key,
signature = crypto.sign(self.keypair,crypto.sign_hash(payload))
)
]
)
self.assertFalse(stateless_validator.verify(tx))
payload = Transaction.Payload(
commands = [
Command(create_account = create_ac)
],
creator_account_id = self.creator,
tx_counter = self.tx_counter,
created_time = crypto.now()+3600*24*1000*10
)
tx = Transaction(
payload = payload,
def test_sha3_sign(self):
key_pair = crypto.create_key_pair()
message = crypto.sha3_256(bytes(b'a031b'))
dummy_message = crypto.sha3_256(bytes(b'a032b'))
sign = crypto.sign(key_pair,message)
self.assertTrue(crypto.verify(key_pair.public_key,sign,message))
self.assertFalse(crypto.verify(key_pair.public_key,sign,dummy_message))
signatories.sign(tx)
self.assertEqual(len(tx.signatures),3)
for i in range(0,3):
sig = tx.signatures[i]
self.assertTrue(
crypto.verify(
sig.pubkey,
sig.signature,
crypto.sign_hash(tx.payload)
)
)
self.assertEqual(
sig.signature,
crypto.sign(
keypairs[i],
crypto.sign_hash(tx.payload)
)
)
signatories.clean()
self.assertEqual(signatories.size(),0)
def sign(self,tx):
logger.debug("Signatories.sign")
payload = tx.payload
for signatory in self.signatories:
if not [ signature for signature in tx.signatures if signature.pubkey == signatory.public_key ]:
tx.signatures.extend([
Signature(
pubkey = signatory.public_key,
signature = crypto.sign(signatory, crypto.sign_hash(payload))
)