Example #1
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
Example #2
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()
Example #3
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()
Example #4
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
Example #5
0
def test_private_key_from_passphrase(identity):
    public_key = PublicKey.from_passphrase(identity['passphrase'])
    assert public_key == identity['data']['public_key']
Example #6
0
 def sign(self, passphrase):
     public_key = PublicKey.from_passphrase(passphrase)
     self.transaction.asset['delegate']['publicKey'] = public_key
     super().sign(passphrase)