Пример #1
0
    def add_signature(self, kp: KeyPair) -> Transaction:
        """Signs the base hash of the `Transaction` and adds the `Signature` to the list of `signatures`.

        Args:
            kp: The `KeyPair` used to sign the base hash of this `Transaction`.

        Returns:
            Itself.
        """
        signature = kp.sign(self._base_hash())
        self.signatures.append(signature)
        return self
Пример #2
0
    def add_publisher_signature(self, name: str, kp: KeyPair) -> Transaction:
        """Signs the publish hash of the `Transaction` and adds the `Signature` to the list of `publisher_signatures`.
        The publish hash includes the list of `signers` and their `signatures`.

        Args:
            name: The name of the publisher, will set the `publisher` field with its value.
            kp: The `KeyPair` used to sign the publish hash of this `Transaction`.

        Returns:
            Itself.
        """
        signature = kp.sign(self._publish_hash())
        self.publisher_signatures.append(signature)
        self.publisher = name
        self.hash = None
        return self
Пример #3
0
from hashlib import sha3_256 as sha3
from base64 import b64encode

from pyost.algorithm import Ed25519, Secp256k1
from pyost.signature import KeyPair

if __name__ == '__main__':
    text = b'hello'
    info = sha3(text).digest()
    print(info.hex())

    for algo in [Ed25519, Secp256k1]:
        kp = KeyPair(algo)
        print(kp.algo_cls.__int__())
        print(kp.seckey.hex())
        print(kp.pubkey.hex())

        sig = kp.sign(info)
        print(sig.pubkey.hex())
        print(sig.sig.hex())
        print(b64encode(sig.pubkey))
        print(b64encode(sig.sig))