Пример #1
0
    def generate(cls,
                 recipient_id,
                 amount,
                 secret,
                 second_secret=None,
                 vendor_field=None,
                 fee=None):
        """
        Creates a transfer transaction

        :param recipient_id: id of user to send to (string)
        :param amount: amount to transfer (integer)
        :param secret: secret passphrase (string or bytes)
        :param second_secret: second secret passphrase (string or bytes)
        :param vendor_field: #TODO
        :param fee: fee for transaction
        :return: (Transfer)
        """

        self = cls(fee, _error_use_class_method=False)
        self._sender_public_key = Keys(secret).get_public_key()

        self._recipient_id = recipient_id
        self._amount = amount

        if vendor_field and len(vendor_field) <= 64:
            self._vendor_field = vendor_field

        self.sign(secret, second_secret)
        return self
Пример #2
0
    def test_from_public_key_1(self):
        Network.use("mainnet")
        public_key = Keys("secret").get_public_key()
        address = Address.from_public_key(public_key)

        self.assertTrue(isinstance(address, bytes))
        self.assertEqual(address, b"AJWRd23HNEhPLkK1ymMnwnDBX2a7QBZqff")
Пример #3
0
    def test_private_key_2(self):
        private_key = Keys("secret".encode()).get_private_key()

        self.assertIsNotNone(private_key)
        self.assertIsInstance(private_key, str)
        self.assertEqual(
            private_key,
            "2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a25fe97bf527a25b")
Пример #4
0
    def test_private_key_1(self):
        private_key = Keys("shhItsASecret").get_private_key()

        self.assertIsNotNone(private_key)
        self.assertIsInstance(private_key, str)
        self.assertEqual(
            private_key,
            "a1ac5e739d797c2d73ae768dfdb60274832c27ab99400baf8ed8e9514e46ad5d")
Пример #5
0
    def test_from_public_key_2(self):
        Network.use("mainnet")
        public_key = Keys("secret second test to be sure it works correctly"
                          ).get_public_key()
        address = Address.from_public_key(public_key)

        self.assertTrue(isinstance(address, bytes))
        self.assertEqual(address, b"AQSqYnjmwj1GBL5twD4K9EBXDaTHZognox")
Пример #6
0
    def test_public_key_1(self):
        public_key = Keys("shhItsASecret").get_public_key()

        self.assertIsNotNone(public_key)
        self.assertIsInstance(public_key, str)
        self.assertEqual(
            public_key,
            "02966d9d8ecc2fa80ceb1d59ec76e3a318d4b30699a4dd3001d68891f7a3c54ac8"
        )
Пример #7
0
    def test_public_key_2(self):
        public_key = Keys("secret".encode()).get_public_key()

        self.assertIsNotNone(public_key)
        self.assertIsInstance(public_key, str)
        self.assertEqual(
            public_key,
            "03a02b9d5fdd1307c2ee4652ba54d492d1fd11a7d1bb3f3a44c4a05e79f19de933"
        )
Пример #8
0
    def from_secret(secret):
        """
        Create address from secret passphrase

        :param secret: secret passphrase (bytes)
        :return: BPL address (string)
        """

        return Address.from_public_key(Keys(secret).get_public_key())
Пример #9
0
    def generate(cls, secret, second_secret, fee=None):
        """
        Create a Second Signature transaction

        :param secret: secret passphrase (string or bytes)
        :param second_secret: second secret passphrase (string or bytes)
        :param fee: fee for transaction
        :return: (SecondSignature)
        """

        self = cls.__init__(fee, _error_use_class_method=False)
        self._sender_public_key = Keys(secret).get_public_key()

        self._asset["signature"] = {
            "publicKey": Keys(second_secret).get_public_key()
        }

        self.sign(secret, second_secret)
        return self
Пример #10
0
    def verify(public_key, message, signature):
        """
        Verifies a message - https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm

        :param public_key: public key (string)
        :param message: message used to verify signature (bytes)
        :param signature: signature (string)
        :return: boolean
        """

        G = SECP256k1.generator
        n = G.order()

        uncompressed_public_key = Keys.uncompress_public_key(public_key)
        try:
            Q_a = Keys.point_from_public_key(
                unhexlify(uncompressed_public_key))
            return verify_point(G, Q_a) and Signature.verify_signature(
                G, n, Q_a, message, unhexlify(signature))
        except AssertionError:
            return False
Пример #11
0
    def generate(cls, ipfs_hash, secret, second_secret=None, fee=None):
        """
        Create a IPFS transaction

        :param ipfs_hash: ipfs_hash (string)
        :param secret: secret passphrase (string or bytes)
        :param second_secret: second secret passphrase (string or bytes)
        :param fee: fee for transaction
        :return: (IPFS)
        """

        self = cls(fee, _error_use_class_method=False)
        self._sender_public_key = Keys(secret).get_public_key()

        self._vendor_field = ipfs_hash

        self.sign(secret, second_secret)
        return self
Пример #12
0
    def generate(cls, votes, secret, second_secret=None, fee=None):
        """
        Creates a vote transaction

        :param votes: votes (list)
        :param secret: secret passphrase (string or bytes)
        :param second_secret: second secret passphrase (string or bytes)
        :param fee: fee for transaction
        :return: (Vote)
        """

        self = cls(fee, _error_use_class_method=False)
        self._sender_public_key = Keys(secret).get_public_key()
        self._recipient_id = Address.from_secret(secret)

        self._asset["votes"] = votes

        self.sign(secret, second_secret)
        return self
Пример #13
0
    def generate(cls, username, secret, second_secret=None, fee=None):
        """
        Create a delegate transaction

        :param username: username of delegate (string)
        :param secret: secret passphrase (string or bytes)
        :param second_secret: second secret passphrase (string or bytes)
        :param fee: fee for transaction (integer)
        :return: (Delegate)
        """

        self = cls(fee, _error_use_class_method=False)
        self._sender_public_key = Keys(secret).get_public_key()

        self._asset["delegate"] = {
            "username": username,
            "publicKey": self._sender_public_key
        }

        self.sign(secret, second_secret)
        return self
Пример #14
0
    def generate(cls, min, lifetime, keysgroup, secret, second_secret=None, fee=None):
        """
        Create a Multi-Signature transaction

        :param min: #TODO
        :param lifetime: #TODO
        :param keysgroup: #TODO
        :param secret: secret passphrase (string or bytes)
        :param second_secret: second secret passphrase (string or bytes)
        :param fee: fee for transaction (integer)
        :return: (MultiSignature)
        """
        self = cls(fee, _error_use_class_method=False)
        self._sender_public_key = Keys(secret).get_public_key()

        self._asset["multisignature"] = {
            "min": min,
            "lifetime": lifetime,
            "keysgroup": keysgroup
        }

        self.sign(secret, second_secret)
        return self
Пример #15
0
    def test_verify_2(self):
        public_key = Keys("secret just to make sure it works").get_public_key()
        message = sha256("message data".encode())
        signature = "304402203aef6f3c4aaa0cb597b8e9b80248983641ae909a8700feea8609bdddb0db6bd40220364735b3fed0a4e0b19e78d7c36658bbd36db8658afce4e227f4aad78318407b"

        self.assertTrue(Signature.verify(public_key, message, signature))
Пример #16
0
    def test_verify_1(self):
        public_key = Keys("secret").get_public_key()
        message = sha256("message".encode())
        signature = "304402202f43daad19f64dd114d55c1488e4ecaee1ce79183008e21e663e24dc882c9b9d022023d0f4e9f63ac43404625b43dbd8df77a774b9e9f33e0d8ff569f6b6b5014e38"

        self.assertTrue(Signature.verify(public_key, message, signature))