Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_crypt_js(self):
print("test_crypt_js")
js_pubkey = b"IuoWmTU/dG7Q7O2mSEIQKnXbMTEJcko45gFqcu0tEWs="
js_signature = b"+F6d6gKexVhzk0LUK6hkKuu76nc0Nt9RakrT4hu2Hkve8qzsz8jNvCuCuKvQN37OUNKqUh9lTMfBYPDFu2KGDQ=="
js_message = b"dfc27cdbd6ec86613185e00afb27b11af2b8e2e8fc1573f80722a6e537cb06ab"
self.assertTrue(ed25519.verify(
js_message,
js_signature,
js_pubkey
))
self.assertTrue(crypto.verify(
js_pubkey,
js_signature,
js_message
))
def test_signatories(self):
signatories = Signatories()
keypairs = []
keypairs.append(crypto.create_key_pair())
keypairs.append(crypto.create_key_pair())
keypairs.append(crypto.create_key_pair())
for key in keypairs:
signatories.append(key)
self.assertTrue(signatories.size() == 3)
tx = Transaction(
payload = Transaction.Payload(
creator_account_id = "test@test"
),
signatures = []
)
)
payload = Transaction.Payload(
commands = [
Command(create_account = create_ac)
],
creator_account_id = self.creator,
tx_counter = self.tx_counter,
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))
def verify_pubkey(pubkey):
try:
key = crypto.b64decode(pubkey)
except:
logger.info("Stateless Public Key not Base64 Encode")
return False
if len(key) == 32:
return True
logger.info("Stateless Public Key Length Failed: " + key.decode())
return False
def verify(transaction):
logger.info("Transaction Stateless Verify")
payload = transaction.payload
for cmd in transaction.payload.commands:
if not command(cmd):
logger.info("Stateless Command Failed")
return False
for signature in transaction.signatures:
if not crypto.verify(signature.pubkey,
signature.signature,
crypto.sign_hash(payload)):
logger.info("Stateless Signature Verify Failed")
return False
if verify_created_time(payload.created_time):
return True
return False
def verify(self):
logger.debug("Response.verify")
return crypto.verify(
self.response.signature.pubkey,
self.response.signature.signature,
crypto.sign_hash(self.response.payload)
)