def validate_or_raise(self) -> bool: """ This method will validate a transaction and raise exception if problems are found :return: True if the exception is valid, exceptions otherwise :rtype: bool """ if not isinstance(self, TYPEMAP[self.subtype]): raise TypeError('Invalid subtype: Found: %s Expected: %s', type(self), TYPEMAP[self.subtype]) if not self._validate_custom(): raise ValueError("Custom validation failed") # cryptographic checks if self.txhash != self.calculate_txhash(): raise ValueError("Invalid transaction hash") # FIXME: Why is coinbase skipped? if not isinstance(self, CoinBase) and not isinstance(self, Vote) and \ getAddress('Q', self.PK) != self.txfrom.decode(): raise ValueError('Public key and address dont match') if len(self.signature) == 0 or not XMSS.VERIFY( message=self.txhash, signature=self.signature, pk=self.PK): raise ValueError("Invalid xmss signature") return True
def validate_signed_hash(self): if XMSS.VERIFY(self.txhash, [self.i, self.signature, self.merkle_path, self.i_bms, self.pub, self.PK]) is False: logger.info('xmss_verify failed') return False if XMSS.checkaddress(self.PK, self.txfrom) is False: logger.info('Public key verification failed') return False return True
def _validate_signed_hash(self, height=config.dev.xmss_tree_height): if self.subtype != TX_SUBTYPE_COINBASE and getAddress('Q', self.PK) != self.txfrom: logger.warning('Public key verification failed') return False if not XMSS.VERIFY(message=self.txhash, signature=self.signature, pk=self.PK, height=height): logger.warning('xmss_verify failed') return False return True
def test_sign_verify(self): message = "This is a test" message_bin = str2bin(message) xmss_height = 10 seed = bytearray([i for i in range(48)]) xmss = XMSS(xmss_height, seed) pk = xmss.pk() xmss.set_index(1) for i in range(10): self.assertTrue(xmss.get_index() == i + 1) signature = xmss.SIGN(message_bin) self.assertTrue(XMSS.VERIFY(message_bin, signature, pk))
def measure_xmss_verification_time(s, m): start_time = time.time() answer = XMSS.VERIFY(m, s, None) total_time = time.time() - start_time return answer, total_time