def test_Vote(self): op = operations.Vote( **{"voter": "foobara", "author": "foobarc", "permlink": "foobard", "weight": 1000} ) ops = [operations.Operation(op)] tx = Signed_Transaction( ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops ) tx = tx.sign([wif]) tx.verify([PrivateKey(wif).pubkey]) txWire = hexlify(bytes(tx)).decode("ascii") compare = ("f68585abf4dce7c80457010007666f6f6261726107666f6f62617263" "07666f6f62617264e8030001202e09123f732a438ef6d6138484d7ad" "edfdcf4a4f3d171f7fcafe836efa2a3c8877290bd34c67eded824ac0" "cc39e33d154d0617f64af936a83c442f62aef08fec") self.assertEqual(compare[:-130], txWire[:-130])
def appendWif(self, wif): if wif: try: PrivateKey(wif) self.wifs.append(wif) except: raise InvalidKeyFormat
def decrypt_wif(self, encwif): """ decrypt a wif key """ try: # Try to decode as wif PrivateKey(encwif) return encwif except: pass self.unlock() return format(bip38.decrypt(encwif, self.masterpassword), "wif")
def addPrivateKey(self, wif): """ Add a private key to the wallet database """ # it could be either graphenebase or dpaypybase so we can't check the type directly if isinstance(wif, PrivateKey) or isinstance(wif, GraphenePrivateKey): 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(): self.newWallet() self.keyStorage.add(self.encrypt_wif(wif), pub)
def setKeys(self, loadkeys): """ This method is strictly only for in memory keys that are passed to Wallet/dPay 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)
def getAccountFromPrivateKey(self, wif): """ Obtain account name from private key """ pub = format(PrivateKey(wif).pubkey, self.prefix) return self.getAccountFromPublicKey(pub)
def encrypt_wif(self, wif): """ Encrypt a wif key """ self.unlock() return format(bip38.encrypt(PrivateKey(wif), self.masterpassword), "encwif")