def verify(self, **kwargs):
        """ Verify a message with an account's memo key

            :param str account: (optional) the account that owns the bet
                (defaults to ``default_account``)

            :returns: True if the message is verified successfully
            :raises InvalidMessageSignature if the signature is not ok
        """
        # Split message into its parts
        parts = re.split("|".join(self.MESSAGE_SPLIT), self.message)
        parts = [x for x in parts if x.strip()]

        assert len(parts) > 2, "Incorrect number of message parts"

        # Strip away all whitespaces before and after the message
        message = parts[0].strip()
        signature = parts[2].strip()
        # Parse the meta data
        meta = dict(re.findall(r"(\S+)=(.*)", parts[1]))

        log.info("Message is: {}".format(message))
        log.info("Meta is: {}".format(json.dumps(meta)))
        log.info("Signature is: {}".format(signature))

        # Ensure we have all the data in meta
        assert "account" in meta, "No 'account' could be found in meta data"
        assert "memokey" in meta, "No 'memokey' could be found in meta data"
        assert "block" in meta, "No 'block' could be found in meta data"
        assert "timestamp" in meta, "No 'timestamp' could be found in meta data"

        account_name = meta.get("account").strip()
        memo_key = meta["memokey"].strip()

        try:
            self.publickey_class(memo_key, prefix=self.blockchain.prefix)
        except Exception:
            raise InvalidMemoKeyException("The memo key in the message is invalid")

        # Load account from blockchain
        try:
            account = self.account_class(
                account_name, blockchain_instance=self.blockchain
            )
        except AccountDoesNotExistsException:
            raise AccountDoesNotExistsException(
                "Could not find account {}. Are you connected to the right chain?".format(
                    account_name
                )
            )

        # Test if memo key is the same as on the blockchain
        if not account["options"]["memo_key"] == memo_key:
            raise WrongMemoKey(
                "Memo Key of account {} on the Blockchain ".format(account["name"])
                + "differs from memo key in the message: {} != {}".format(
                    account["options"]["memo_key"], memo_key
                )
            )

        # Reformat message
        enc_message = self.SIGNED_MESSAGE_META.format(**locals())

        # Verify Signature
        pubkey = verify_message(enc_message, unhexlify(signature))

        # Verify pubky
        pk = self.publickey_class(
            hexlify(pubkey).decode("ascii"), prefix=self.blockchain.prefix
        )
        if format(pk, self.blockchain.prefix) != memo_key:
            raise InvalidMessageSignature("The signature doesn't match the memo key")

        self.signed_by_account = account
        self.signed_by_name = account["name"]
        self.meta = meta
        self.plain_message = message

        return True
def verify(self, **kwargs):
        """ Verify a message with an account's memo key

            :param str account: (optional) the account that owns the bet
                (defaults to ``default_account``)

            :returns: True if the message is verified successfully
            :raises InvalidMessageSignature if the signature is not ok
        """
        # Split message into its parts
        parts = re.split("|".join(self.MESSAGE_SPLIT), self.message)
        parts = [x for x in parts if x.strip()]

        assert len(parts) > 2, "Incorrect number of message parts"

        # Strip away all whitespaces before and after the message
        message = parts[0].strip()
        signature = parts[2].strip()
        # Parse the meta data
        meta = dict(re.findall(r"(\S+)=(.*)", parts[1]))

        log.info("Message is: {}".format(message))
        log.info("Meta is: {}".format(json.dumps(meta)))
        log.info("Signature is: {}".format(signature))

        # Ensure we have all the data in meta
        assert "account" in meta, "No 'account' could be found in meta data"
        assert "memokey" in meta, "No 'memokey' could be found in meta data"
        assert "block" in meta, "No 'block' could be found in meta data"
        assert "timestamp" in meta, "No 'timestamp' could be found in meta data"

        account_name = meta.get("account").strip()
        memo_key = meta["memokey"].strip()

        try:
            self.publickey_class(memo_key, prefix=self.blockchain.prefix)
        except Exception:
            raise InvalidMemoKeyException("The memo key in the message is invalid")

        # Load account from blockchain
        try:
            account = self.account_class(
                account_name, blockchain_instance=self.blockchain
            )
        except AccountDoesNotExistsException:
            raise AccountDoesNotExistsException(
                "Could not find account {}. Are you connected to the right chain?".format(
                    account_name
                )
            )

        # Test if memo key is the same as on the blockchain
        if not account["options"]["memo_key"] == memo_key:
            raise WrongMemoKey(
                "Memo Key of account {} on the Blockchain ".format(account["name"])
                + "differs from memo key in the message: {} != {}".format(
                    account["options"]["memo_key"], memo_key
                )
            )

        # Reformat message
        enc_message = self.SIGNED_MESSAGE_META.format(**locals())

        # Verify Signature
        pubkey = verify_message(enc_message, unhexlify(signature))

        # Verify pubky
        pk = self.publickey_class(
            hexlify(pubkey).decode("ascii"), prefix=self.blockchain.prefix
        )
        if format(pk, self.blockchain.prefix) != memo_key:
            raise InvalidMessageSignature("The signature doesn't match the memo key")

        self.signed_by_account = account
        self.signed_by_name = account["name"]
        self.meta = meta
        self.plain_message = message

        return True
def verify ( self , * * kwargs ) : # Split message into its parts parts = re . split ( "|" . join ( self . MESSAGE_SPLIT ) , self . message ) parts = [ x for x in parts if x . strip ( ) ] assert len ( parts ) > 2 , "Incorrect number of message parts" # Strip away all whitespaces before and after the message message = parts [ 0 ] . strip ( ) signature = parts [ 2 ] . strip ( ) # Parse the meta data meta = dict ( re . findall ( r"(\S+)=(.*)" , parts [ 1 ] ) ) log . info ( "Message is: {}" . format ( message ) ) log . info ( "Meta is: {}" . format ( json . dumps ( meta ) ) ) log . info ( "Signature is: {}" . format ( signature ) ) # Ensure we have all the data in meta assert "account" in meta , "No 'account' could be found in meta data" assert "memokey" in meta , "No 'memokey' could be found in meta data" assert "block" in meta , "No 'block' could be found in meta data" assert "timestamp" in meta , "No 'timestamp' could be found in meta data" account_name = meta . get ( "account" ) . strip ( ) memo_key = meta [ "memokey" ] . strip ( ) try : self . publickey_class ( memo_key , prefix = self . blockchain . prefix ) except Exception : raise InvalidMemoKeyException ( "The memo key in the message is invalid" ) # Load account from blockchain try : account = self . account_class ( account_name , blockchain_instance = self . blockchain ) except AccountDoesNotExistsException : raise AccountDoesNotExistsException ( "Could not find account {}. Are you connected to the right chain?" . format ( account_name ) ) # Test if memo key is the same as on the blockchain if not account [ "options" ] [ "memo_key" ] == memo_key : raise WrongMemoKey ( "Memo Key of account {} on the Blockchain " . format ( account [ "name" ] ) + "differs from memo key in the message: {} != {}" . format ( account [ "options" ] [ "memo_key" ] , memo_key ) ) # Reformat message enc_message = self . SIGNED_MESSAGE_META . format ( * * locals ( ) ) # Verify Signature pubkey = verify_message ( enc_message , unhexlify ( signature ) ) # Verify pubky pk = self . publickey_class ( hexlify ( pubkey ) . decode ( "ascii" ) , prefix = self . blockchain . prefix ) if format ( pk , self . blockchain . prefix ) != memo_key : raise InvalidMessageSignature ( "The signature doesn't match the memo key" ) self . signed_by_account = account self . signed_by_name = account [ "name" ] self . meta = meta self . plain_message = message return True
Verify a message with an account's memo key

            :param str account: (optional) the account that owns the bet
                (defaults to ``default_account``)

            :returns: True if the message is verified successfully
            :raises InvalidMessageSignature if the signature is not ok
Verify a message with an account s memo key