Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.wallet.steem = stm
self.wallet.unlock(pwd="TestingOneTwoThree")
with self.assertRaises(
exceptions.MissingKeyError
):
self.wallet.getOwnerKeyForAccount("test")
with self.assertRaises(
exceptions.MissingKeyError
):
self.wallet.getMemoKeyForAccount("test")
with self.assertRaises(
exceptions.MissingKeyError
):
self.wallet.getActiveKeyForAccount("test")
with self.assertRaises(
exceptions.MissingKeyError
):
self.wallet.getPostingKeyForAccount("test")
def test_sign(self):
bts = self.bts
with self.assertRaises(
exceptions.MissingKeyError
):
bts.sign()
def test_broadcast(self):
bts = self.bts
bts.txbuffer.clear()
tx = bts.comment_options({}, "@gtg/witness-gtg-log", account="test")
# tx = bts.sign()
with self.assertRaises(
exceptions.MissingKeyError
):
bts.broadcast(tx=tx)
def test_broadcast(self):
bts = self.bts
bts.txbuffer.clear()
tx = bts.comment_options({}, "@gtg/witness-gtg-log", account="test")
# tx = bts.sign()
with self.assertRaises(
exceptions.MissingKeyError
):
bts.broadcast(tx=tx)
def test_appendWif(self):
nodelist = NodeList()
stm = Steem(node=self.nodes,
nobroadcast=True,
expiration=120,
num_retries=10)
tx = TransactionBuilder(use_condenser_api=True, steem_instance=stm)
tx.appendOps(Transfer(**{"from": "beem",
"to": "beem1",
"amount": Amount("1 STEEM", steem_instance=stm),
"memo": ""}))
with self.assertRaises(
MissingKeyError
):
tx.sign()
with self.assertRaises(
InvalidWifError
):
tx.appendWif("abcdefg")
tx.appendWif(self.active_key)
tx.sign()
self.assertTrue(len(tx["signatures"]) > 0)
if key_type == "memo":
key = self.getPrivateKeyForPublicKey(
account[0]["memo_key"])
if key:
return key
else:
key = None
for authority in account[0][key_type]["key_auths"]:
try:
key = self.getPrivateKeyForPublicKey(authority[0])
if key:
return key
except MissingKeyError:
key = None
if key is None:
raise MissingKeyError("No private key for {} found".format(name))
return
key = self.getPrivateKeyForPublicKey(
account[0]["memo_key"])
if key:
return [key]
else:
keys = []
key = None
for authority in account[0][key_type]["key_auths"]:
try:
key = self.getPrivateKeyForPublicKey(authority[0])
if key:
keys.append(key)
except MissingKeyError:
key = None
if key is None:
raise MissingKeyError("No private key for {} found".format(name))
return keys
return
def encrypt(self, memo, bts_encrypt=False):
""" 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.steem.wallet.getPrivateKeyForPublicKey(
self.from_account["memo_key"]
)
if not memo_wif:
raise MissingKeyError("Memo key for %s missing!" % self.from_account["name"])
if not hasattr(self, 'chain_prefix'):
self.chain_prefix = self.steem.prefix
if bts_encrypt:
enc = BtsMemo.encode_memo_bts(
PrivateKey(memo_wif),
PublicKey(
self.to_account["memo_key"],
prefix=self.chain_prefix
),
nonce,
memo
)
return {
def getPrivateKeyForPublicKey(self, pub):
""" Obtain the private key for a given public key
:param str pub: Public Key
"""
if(Wallet.keys):
if pub in Wallet.keys:
return Wallet.keys[pub]
else:
raise MissingKeyError("No private key for {} found".format(pub))
else:
# Test if wallet exists
if not self.created():
raise NoWalletException
if not self.unlocked():
raise WalletLocked
encwif = self.keyStorage.getPrivateKeyForPublicKey(pub)
if not encwif:
raise MissingKeyError("No private key for {} found".format(pub))
return self.decrypt_wif(encwif)