Exemple #1
0
    def sign_vtt(self, transaction) -> VTTransaction:
        vtt_body = transaction.body
        vtt_hash = sha256(vtt_body.to_pb_bytes())

        der_bytes = self.sign_hash(vtt_hash).encode(compact=False)

        signature = Signature(secp256k1=Secp256k1Signature(der=der_bytes))
        pubkey = self.to_public().pub_key()
        _sig = KeyedSignature(signature=signature, public_key=pubkey)

        transaction.signatures.append(_sig)
        return transaction
Exemple #2
0
def verify_openssl(signature: Signature, signature_form: bytes,
                   pub: 'WitPublicKey'):
    """Validate a signature using OpenSSL"""
    import os
    import tempfile

    with tempfile.TemporaryDirectory() as directory_name:
        with open(directory_name + '/sig.raw', 'wb') as file:
            file.write(signature.encode())

        with open(directory_name + '/hash1.sha256', 'wb') as file:
            file.write(sha256(signature_form))

        with open(directory_name + '/key.hex', 'w') as file:
            file.write('3056301006072a8648ce3d020106052b8104000a034200\n' +
                       pub.hex())

        os.system(
            f'xxd -r -p < {directory_name}/key.hex | openssl pkey -pubin -inform der > {directory_name}/key.pem'
        )
        os.system(
            f'openssl sha256 < {directory_name}/hash1.sha256 -verify {directory_name}/key.pem -signature {directory_name}/sig.raw'
        )
Exemple #3
0
 def hash(self):
     return sha256(self.pb_bytes())
Exemple #4
0
 def hash(self):
     print(type(self.msg), bytes(self.msg))
     return sha256(bytes(self.msg))
 def encode(self):
     data = self.serialize()
     assert len(data) == 78
     checksum = sha256(sha256(data))[:4]
     return base58.encode(data + checksum)
 def decode(cls, string: str) -> 'ExtendedKey':
     bts = base58.decode(string)
     assert len(bts) == 82, f'Invalid length {len(bts)})'
     data, checksum = bts[:78], bts[78:]
     assert sha256(sha256(data)).startswith(checksum), 'Invalid checksum'
     return cls.deserialize(data)