Exemple #1
0
    def decrypt(self, memo):
        """ Decrypt a memo

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

        memo_wif = self.graphene.wallet.getPrivateKeyForPublicKey(
            self.to_account["options"]["memo_key"]
        )
        if not memo_wif:
            raise MissingKeyError("Memo key for %s missing!" % self.to_account["name"])

        # TODO: Use pubkeys of the message, not pubkeys of account!
        return BtsMemo.decode_memo(
            PrivateKey(memo_wif),
            PublicKey(
                self.from_account["options"]["memo_key"],
                prefix=self.graphene.rpc.chain_params["prefix"]
            ),
            memo.get("nonce"),
            memo.get("message")
        )
Exemple #2
0
    def encrypt(self, memo):
        """ Encrypt a memo

            :param str memo: clear text memo message
            :returns: encrypted memo
            :rtype: str
        """
        if not memo:
            return None

        nonce = str(random.getrandbits(64))
        memo_wif = self.graphene.wallet.getPrivateKeyForPublicKey(
            self.from_account["options"]["memo_key"]
        )
        if not memo_wif:
            raise MissingKeyError("Memo key for %s missing!" % self.from_account["name"])

        enc = BtsMemo.encode_memo(
            PrivateKey(memo_wif),
            PublicKey(
                self.to_account["options"]["memo_key"],
                prefix=self.graphene.rpc.chain_params["prefix"]
            ),
            nonce,
            memo
        )

        return {
            "message": enc,
            "nonce": nonce,
            "from": self.from_account["options"]["memo_key"],
            "to": self.to_account["options"]["memo_key"]
        }
Exemple #3
0
 def appendWif(self, wif):
     """ Add a wif that should be used for signing of the transaction.
     """
     if wif:
         try:
             PrivateKey(wif)
             self.wifs.append(wif)
         except:
             raise InvalidWifError
Exemple #4
0
 def decrypt_wif(self, encwif):
     """ decrypt a wif key
     """
     try:
         # Try to decode as wif
         PrivateKey(encwif)
         return encwif
     except:
         pass
     assert not self.locked()
     return format(bip38.decrypt(encwif, self.masterpassword), "wif")
Exemple #5
0
    def addPrivateKey(self, wif):
        """ Add a private key to the wallet database
        """
        # it could be either graphenebase or graphenebase so we can't check the type directly
        if isinstance(wif, PrivateKey) or isinstance(wif, GPHPrivateKey):
            wif = str(wif)
        try:
            pub = format(PrivateKey(wif).pubkey, self.prefix)
        except:
            raise InvalidWifError(
                "Invalid Private Key Format. Please use WIF!")

        if self.keyStorage:
            # Test if wallet exists
            if not self.created():
                raise NoWalletException
            self.keyStorage.add(self.encrypt_wif(wif), pub)
Exemple #6
0
    def setKeys(self, loadkeys):
        """ This method is strictly only for in memory keys that are
            passed to Wallet/graphene with the ``keys`` argument
        """
        log.debug(
            "Force setting of private keys. Not using the wallet database!")
        if isinstance(loadkeys, dict):
            Wallet.keyMap = loadkeys
            loadkeys = list(loadkeys.values())
        elif not isinstance(loadkeys, list):
            loadkeys = [loadkeys]

        for wif in loadkeys:
            try:
                key = PrivateKey(wif)
            except:
                raise InvalidWifError
            Wallet.keys[format(key.pubkey, self.prefix)] = str(key)
Exemple #7
0
 def getAccountFromPrivateKey(self, wif):
     """ Obtain account name from private key
     """
     pub = format(PrivateKey(wif).pubkey, self.prefix)
     return self.getAccountFromPublicKey(pub)
Exemple #8
0
 def encrypt_wif(self, wif):
     """ Encrypt a wif key
     """
     assert not self.locked()
     return format(bip38.encrypt(PrivateKey(wif), self.masterpassword),
                   "encwif")