Esempio n. 1
0
    def verify(self):
        """Verify the Message object

        Returns:
            bool: returns a boolean - true if verified, false if not
        """
        message = self.message if isinstance(self.message,
                                             bytes) else self.message.encode()
        key = PublicKey.from_hex(self.publickey) if hasattr(
            self, 'publickey') else PublicKey.from_hex(self.publicKey)
        signature = unhexlify(self.signature)
        is_verified = key.public_key.verify(signature, message)
        return is_verified
Esempio n. 2
0
def test_transfer_secondsig_transaction():
    """Test if a transfer transaction with second signature gets built
    """
    transaction = Transfer(
        recipientId='AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC',
        amount=200000000,
    )
    transaction.set_type_group(TRANSACTION_TYPE_GROUP.CORE)
    transaction.set_nonce(1)
    transaction.schnorr_sign('this is a top secret passphrase')
    transaction.second_sign('second top secret passphrase')
    transaction_dict = transaction.to_dict()

    assert transaction_dict['nonce'] == 1
    assert transaction_dict['signature']
    assert transaction_dict['signSignature']
    assert transaction_dict['type'] is TRANSACTION_TRANSFER
    assert transaction_dict['typeGroup'] == 1
    assert transaction_dict['typeGroup'] == TRANSACTION_TYPE_GROUP.CORE.value

    transaction.schnorr_verify(
    )  # if no exception is raised, it means the transaction is valid
    transaction.schnorr_verify_second(
        PublicKey.from_passphrase('second top secret passphrase')
    )  # if no exception is raised, it means the transaction is valid
Esempio n. 3
0
    def sign(self, passphrase):
        """Sign the transaction using the given passphrase

        Args:
            passphrase (str): passphrase associated with the account sending this transaction
        """
        self.transaction.senderPublicKey = PublicKey.from_passphrase(passphrase)
        message = Message.sign(self.transaction.to_bytes(), passphrase)
        self.transaction.signature = message.signature
        self.transaction.id = self.transaction.get_id()
Esempio n. 4
0
    def schnorr_sign(self, passphrase):
        """Sign the transaction using the given passphrase

        Args:
            passphrase (str): passphrase associated with the account sending this transaction
        """
        self.transaction.senderPublicKey = PublicKey.from_passphrase(passphrase)
        msg = hashlib.sha256(self.transaction.to_bytes(False, True, False)).digest()
        secret = unhexlify(PrivateKey.from_passphrase(passphrase).to_hex())
        self.transaction.signature = hexlify(schnorr.bcrypto410_sign(msg, secret))
        self.transaction.id = self.transaction.get_id()
Esempio n. 5
0
    def __init__(self, second_passphrase, fee=None):
        """Create a second signature registration transaction

        Args:
            second_passphrase (str): used for signing a transaction the 2nd time
            fee (int, optional): fee used for the transaction (default is already set)
        """
        super().__init__()
        public_key = PublicKey.from_passphrase(second_passphrase)
        self.transaction.asset['signature'] = {'publicKey': public_key}
        if fee:
            self.transaction.fee = fee
Esempio n. 6
0
def test_private_key_from_hex(identity):
    public_key = PublicKey.from_hex(identity['data']['public_key'])
    assert isinstance(public_key, PublicKey)
    assert public_key.to_hex() == identity['data']['public_key']
Esempio n. 7
0
def test_private_key_from_passphrase(identity):
    public_key = PublicKey.from_passphrase(identity['passphrase'])
    assert public_key == identity['data']['public_key']
Esempio n. 8
0
 def sign(self, passphrase):
     public_key = PublicKey.from_passphrase(passphrase)
     self.transaction.asset['delegate']['publicKey'] = public_key
     super().sign(passphrase)