def test_l3block_signing_hashing(self):
     block = make_l3_block()
     sig = crypto.sign_l3_block(blake2b, secp256k1, key, block)
     self.assertEqual(
         sig,
         "MEQCIBx+i31vFfaXjlyvAYlTyVw+AuGcKnqL55AjuKO5UwwfAiA2+Rf6dde2mpXpK/OrSycQNuiksL8Y1DTc6zz4B+dCqA=="
     )
     sig = crypto.sign_l3_block(sha256, secp256k1, key, block)
     self.assertEqual(
         sig,
         "MEQCIEnH0caGprg13H0q4x803dgVo7xcGyf/i2M+6tCe0aKRAiBvNlcXeJD9yRVT6g8cZ0MM6tJBc/OWx9Kbq1qsCOo/7w=="
     )
     sig = crypto.sign_l3_block(sha3_256, secp256k1, key, block)
     self.assertEqual(
         sig,
         "MEUCIQDPuuxO4PcPKNYMogl58ZF9an/FU7cO3jf2VdjRKLXjKwIgVz64rFKrs1GQ/AVFOSYNP8nM8mcZs5hRoveo4SGeby0="
     )
     block_hash, nonce = crypto.pow_l3_block(blake2b, block)
     self.assertEqual(block_hash,
                      "AKNA21rqNqaWeKglP6QGDe09k+SWZfEmVvHjJxI9w/c=")
     self.assertEqual(nonce, 231)
     block_hash, nonce = crypto.pow_l3_block(sha256, block)
     self.assertEqual(block_hash,
                      "AFFPeRLW3Y/zdfd9QRI6IQD32Hdt2BmzmotwFq0+3WU=")
     self.assertEqual(nonce, 205)
     block_hash, nonce = crypto.pow_l3_block(sha3_256, block)
     self.assertEqual(block_hash,
                      "ABQlIssL2qpK8iPI7lKu5rtEmnv8i7tMLy8sz4LcFH0=")
     self.assertEqual(nonce, 339)
 def test_l3block_signing_hashing_v2(self):
     block = make_l3_block_v2()
     sig = crypto.sign_l3_block(blake2b, secp256k1, key, block)
     self.assertEqual(
         sig,
         "MEQCIGz8Tx1KZs386w9aTr/jtB8fVkprMzv8TW2A4Wc45FSjAiBBzgx9z0n/IcvSYTF/ZHpSlTyL6Xgacf+VsSWUO2JnQQ=="
     )
     sig = crypto.sign_l3_block(sha256, secp256k1, key, block)
     self.assertEqual(
         sig,
         "MEUCIQCqPf3Y0lpNpCDA0m3AvPXbsMDtx3+xiWSOdWOGUHkwsQIgbeDyddkKuUsEC8zCcIFsdgPUy58X5GmCpVrGwkWg+I8="
     )
     sig = crypto.sign_l3_block(sha3_256, secp256k1, key, block)
     self.assertEqual(
         sig,
         "MEQCIFfPjZK5tSVVps4YqdHxD0n/ypkFVaHWyw+lDYPX+HUrAiBB7zoPt8Xd5SpTPcu4YpKl5Z4ff7Ibh2PGhbbWbtcbfw=="
     )
     block_hash, nonce = crypto.pow_l3_block(blake2b, block)
     self.assertEqual(block_hash,
                      "AILgeOkQNYDjaT47dnyYOV8CcCtHJPkxBZLdgOCiUMA=")
     self.assertEqual(nonce, 351)
     block_hash, nonce = crypto.pow_l3_block(sha256, block)
     self.assertEqual(block_hash,
                      "ABWOslEpGB4jRibC0cxHGUrHRTBjOxHhUsANM1f03R0=")
     self.assertEqual(nonce, 7)
     block_hash, nonce = crypto.pow_l3_block(sha3_256, block)
     self.assertEqual(block_hash,
                      "ALOKQPxF0tx99mZP+UZVPotGcT9Oss3mx9sHs2eMA54=")
     self.assertEqual(nonce, 498)
Exemple #3
0
 def sign_block(self, signable_block: "model.BlockModel") -> str:
     """Sign a block with this class' keys
     Args:
         block: BlockModel to sign
     Returns:
         Base64 encoded string of the block signature
     Raises:
         exceptions.InvalidNodeLevel when invalid level on self
         RuntimeError when no private key is set on self
     """
     if self.priv is None:
         raise RuntimeError("No private key has been set for signing")
     if self.level == 1:
         return crypto.sign_l1_block(self.hash, self.encryption, self.priv,
                                     signable_block)
     elif self.level == 2:
         return crypto.sign_l2_block(self.hash, self.encryption, self.priv,
                                     signable_block)
     elif self.level == 3:
         return crypto.sign_l3_block(self.hash, self.encryption, self.priv,
                                     signable_block)
     elif self.level == 4:
         return crypto.sign_l4_block(self.hash, self.encryption, self.priv,
                                     signable_block)
     elif self.level == 5:
         return crypto.sign_l5_block(self.hash, self.encryption, self.priv,
                                     signable_block)
     else:
         raise exceptions.InvalidNodeLevel(
             f"Node level {self.level} not implemented yet")
 def test_l3block_trust_verifying_v2(self):
     block = make_l3_block_v2()
     sig = crypto.sign_l3_block(blake2b, secp256k1, key, block)
     block.proof = sig
     block.scheme = "trust"
     self.assertTrue(crypto.verify_l3_block_trust(blake2b, secp256k1, key.pubkey, block))
     valid_block = copy.deepcopy(block)
     block.dc_id = "forged"
     self.assertFalse(crypto.verify_l3_block_trust(blake2b, secp256k1, key.pubkey, block))
     block = copy.deepcopy(valid_block)
     block.block_id = "forged"
     self.assertFalse(crypto.verify_l3_block_trust(blake2b, secp256k1, key.pubkey, block))
     block = copy.deepcopy(valid_block)
     block.timestamp = "forged"
     self.assertFalse(crypto.verify_l3_block_trust(blake2b, secp256k1, key.pubkey, block))
     block = copy.deepcopy(valid_block)
     block.prev_proof = "forged=="
     self.assertFalse(crypto.verify_l3_block_trust(blake2b, secp256k1, key.pubkey, block))
     block = copy.deepcopy(valid_block)
     block.l1_dc_id = "forged"
     self.assertFalse(crypto.verify_l3_block_trust(blake2b, secp256k1, key.pubkey, block))
     block = copy.deepcopy(valid_block)
     block.l1_block_id = "forged"
     self.assertFalse(crypto.verify_l3_block_trust(blake2b, secp256k1, key.pubkey, block))
     block = copy.deepcopy(valid_block)
     block.l1_proof = "forged"
     self.assertFalse(crypto.verify_l3_block_trust(blake2b, secp256k1, key.pubkey, block))
     block = copy.deepcopy(valid_block)
     block.ddss = "forged"
     self.assertFalse(crypto.verify_l3_block_trust(blake2b, secp256k1, key.pubkey, block))
     block = copy.deepcopy(valid_block)
     block.l2_count = "forged"
     self.assertFalse(crypto.verify_l3_block_trust(blake2b, secp256k1, key.pubkey, block))
     block = copy.deepcopy(valid_block)
     block.regions = ["forged", "stuff"]
     self.assertFalse(crypto.verify_l3_block_trust(blake2b, secp256k1, key.pubkey, block))
     block = copy.deepcopy(valid_block)
     block.clouds = ["forged"]
     self.assertFalse(crypto.verify_l3_block_trust(blake2b, secp256k1, key.pubkey, block))
     block = copy.deepcopy(valid_block)
     block.proof = "MEQCIF+o3DHBiTbpw8X6W4/yOuPF/FfANIiNnG0mFLgjBAjuAiAe/QAHN8ufmHMeRvHFItdrzVHFORGED4/msipzFORGED=="
     self.assertFalse(crypto.verify_l3_block_trust(blake2b, secp256k1, key.pubkey, block))