def test_from_bytes(multi_sig: MultiSignature):
    xbytes = multi_sig.as_bytes()

    multi_sig2 = MultiSignature.from_bytes(xbytes)
    assert type(multi_sig2) is MultiSignature

    xbytes2 = multi_sig2.as_bytes()
    assert xbytes == xbytes2
Пример #2
0
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
Пример #3
0
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
Пример #4
0
def multi_sig(signature1: Signature, signature2: Signature) -> MultiSignature:
    multi_sig = MultiSignature.new([signature1, signature2])

    assert type(multi_sig) is MultiSignature
    assert multi_sig.c_instance is not None
    return multi_sig
 def create_multi_sig(self, signatures: Sequence[str]) -> str:
     sigs = [
         IndyCryptoBlsUtils.bls_from_str(s, Signature) for s in signatures
     ]
     bts = MultiSignature.new(sigs)
     return IndyCryptoBlsUtils.bls_to_str(bts)
 def create_multi_sig(self, signatures: Sequence[str]) -> str:
     sigs = [IndyCryptoBlsUtils.bls_from_str(s, Signature) for s in signatures]
     bts = MultiSignature.new(sigs)
     return IndyCryptoBlsUtils.bls_to_str(bts)
def test_as_bytes(multi_sig: MultiSignature):
    xbytes = multi_sig.as_bytes()
    assert len(xbytes) > 0