def verify_multi_sig(self, signature: str, message: str, pks: Sequence[str]) -> bool: epks = [IndyCryptoBlsUtils.bls_from_str(p, VerKey) for p in pks] multi_signature = \ IndyCryptoBlsUtils.bls_from_str(signature, MultiSignature) # type: MultiSignature message_bytes = IndyCryptoBlsUtils.msg_to_bls_bytes(message) return Bls.verify_multi_sig(multi_sig=multi_signature, message=message_bytes, ver_keys=epks, gen=self._generator)
def test_verify_multi_sig_works_for_invalid_signature(generator, message): sign_key1 = SignKey.new(None) ver_key1 = VerKey.new(generator, sign_key1) sign_key2 = SignKey.new(None) ver_key2 = VerKey.new(generator, SignKey.new(None)) signature1 = Bls.sign(message, sign_key1) signature2 = Bls.sign(message, sign_key2) multi_signature_invalid = MultiSignature.new([signature1, signature2]) valid = Bls.verify_multi_sig(multi_signature_invalid, message, [ver_key1, ver_key2], generator) assert not valid
def verify_multi_sig(self, signature: str, message: bytes, pks: Sequence[str]) -> bool: epks = [IndyCryptoBlsUtils.bls_from_str(p, VerKey) for p in pks] if None in epks: return False multi_signature = \ IndyCryptoBlsUtils.bls_from_str(signature, MultiSignature) # type: MultiSignature if multi_signature is None: return False return Bls.verify_multi_sig(multi_sig=multi_signature, message=message, ver_keys=epks, gen=self._generator)
def verify_multi_sig(self, signature: str, message: bytes, pks: Sequence[Optional[VerKey]]) -> bool: # TODO: is it expected that we return False if one of the keys is None? if None in pks: return False multi_signature = \ IndyCryptoBlsUtils.bls_from_str(signature, MultiSignature) # type: MultiSignature if multi_signature is None: return False return Bls.verify_multi_sig(multi_sig=multi_signature, message=message, ver_keys=pks, gen=self._generator)
def demo(): # Create generator generator = Generator.new() # Create first key pair sign_key1 = SignKey.new(None) ver_key1 = VerKey.new(generator, sign_key1) # Create second keys pair based on seed seed = bytes([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8 ]) sign_key2 = SignKey.new(seed) ver_key2 = VerKey.new(generator, sign_key2) # Sample message message = bytes([1, 2, 3, 4, 5]) # Sign message with first sing key signature1 = Bls.sign(message, sign_key1) # Verify first signature with first ver key valid = Bls.verify(signature1, message, ver_key1, generator) assert valid # Sign message with second sing key signature2 = Bls.sign(message, sign_key2) # Verify second signature with second ver key valid = Bls.verify(signature2, message, ver_key2, generator) assert valid # Create multi signature multi_sig = MultiSignature.new([signature1, signature2]) # Verify multi signature valid = Bls.verify_multi_sig(multi_sig, message, [ver_key1, ver_key2], generator) assert valid
def test_verify__multi_sig_works(generator: Generator, message: bytes, multi_sig: MultiSignature, ver_key1: VerKey, ver_key2: VerKey): valid = Bls.verify_multi_sig(multi_sig, message, [ver_key1, ver_key2], generator) assert valid