Beispiel #1
0
 def test_decrypt(self):
     for memo in test_cases:
         dec = decode_memo(PrivateKey(memo["wif"]),
                           PublicKey(memo["to"], prefix="GPH"),
                           memo["nonce"],
                           memo["message"])
         self.assertEqual(memo["plain"], dec)
Beispiel #2
0
 def test_decrypt_bugged_padding(self):
     for memo in not_enough_padding:
         dec = decode_memo(
             PrivateKey(memo["wif"]),
             PublicKey(memo["to"], prefix="GPH"),
             memo["nonce"],
             memo["message"],
         )
         self.assertEqual(memo["plain"], dec)
Beispiel #3
0
 def test_decrypt(self):
     for memo in test_cases:
         dec = decode_memo(
             PrivateKey(memo["wif"]),
             PublicKey(memo["to"], prefix="GPH"),
             memo["nonce"],
             memo["message"],
         )
         self.assertEqual(memo["plain"], dec)
Beispiel #4
0
def ovaltine(memo, private_key):
    """
    Decode BitShares Transfer Memo
    """
    return (
        decode_memo(
            PrivateKey(private_key),  # associated with memo["to"] public key
            PublicKey(memo["from"], prefix=PREFIX),
            memo["nonce"],
            memo["message"],
        )
        .replace("\n", "")
        .replace(" ", "")
    )
    def decrypt(self, message):
        """ Decrypt a message

            :param dict message: encrypted memo message
            :returns: decrypted message
            :rtype: str
        """
        if not message:
            return None

        # We first try to decode assuming we received the memo
        try:
            memo_wif = self.blockchain.wallet.getPrivateKeyForPublicKey(
                message["to"])
            pubkey = message["from"]
        except KeyNotFound:
            try:
                # if that failed, we assume that we have sent the memo
                memo_wif = self.blockchain.wallet.getPrivateKeyForPublicKey(
                    message["from"])
                pubkey = message["to"]
            except KeyNotFound:
                # if all fails, raise exception
                raise MissingKeyError(
                    "None of the required memo keys are installed!"
                    "Need any of {}".format([message["to"], message["from"]]))

        if not hasattr(self, "chain_prefix"):
            self.chain_prefix = self.blockchain.prefix

        return memo.decode_memo(
            self.privatekey_class(memo_wif),
            self.publickey_class(pubkey, prefix=self.chain_prefix),
            message.get("nonce"),
            message.get("message"),
        )