44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
import unittest
|
|
from onionrblocks.generators import signedby
|
|
import kasten
|
|
import hashlib
|
|
from nacl.signing import SigningKey, VerifyKey
|
|
|
|
from time import time
|
|
from math import floor
|
|
|
|
def sha3_hash_bytes(data):
|
|
return hashlib.sha3_256(data).digest()
|
|
|
|
class TestSignedByProof(unittest.TestCase):
|
|
def test_signed_by_create(self):
|
|
key = SigningKey.generate()
|
|
test_data = kasten.generator.pack.pack(
|
|
b"test", "tst")
|
|
gen = signedby.Signed.generate(test_data, key)
|
|
self.assertEqual(
|
|
gen.get_packed(),
|
|
test_data
|
|
)
|
|
hashed = hashlib.sha3_256(test_data).digest()
|
|
signed = key.sign(hashed)
|
|
self.assertEqual(signed, gen.id)
|
|
key.verify_key.verify(signed)
|
|
self.assertEqual(hashlib.sha3_256(test_data).digest(), signed[64:])
|
|
|
|
def test_signed_by_create_raw_keys(self):
|
|
key = SigningKey.generate()
|
|
test_data = kasten.generator.pack.pack(
|
|
b"test", "tst")
|
|
gen = signedby.Signed.generate(test_data, key.encode())
|
|
self.assertEqual(
|
|
gen.get_packed(),
|
|
test_data
|
|
)
|
|
hashed = hashlib.sha3_256(test_data).digest()
|
|
signed = key.sign(hashed)
|
|
self.assertEqual(signed, gen.id)
|
|
key.verify_key.verify(signed)
|
|
self.assertEqual(hashlib.sha3_256(test_data).digest(), signed[64:])
|
|
|
|
unittest.main() |