Beispiel #1
0
def password(account_name):
    from beemgraphenebase.account import PasswordKey
    import random
    num = random.sample("stringascii_letters", 10)
    strs = ''
    password = strs.join(num)
    owner_key = PasswordKey(account_name, password, role="owner")
    owner_key=owner_key.get_private()
    key = "P5" + (str(owner_key))[2:51]
    return key
Beispiel #2
0
def generate_password(import_password, wif=1):
    if wif > 0:
        password = import_password
        for _ in range(wif):
            pk = PasswordKey("", password, role="")
            password = str(pk.get_private())
        password = '******' + password
    else:
        password = import_password
    return password
Beispiel #3
0
def passwordkey_to_key(passwordkey, account, role, prefix="STM"):
    """ Get a private key from an input that may be a key or a master
    password.

    :param str passwordkey: Key or master password to check/transform.
    :param str account: Account name the key is for.
    :param str role: Role of the key (posting, active, owner, memo)
    :param str prefix: Network prefix (default: "STM")

    """
    try:
        # check if passwordkey is a valid private key
        PrivateKey(passwordkey, prefix=prefix)
        return passwordkey
    except ValueError:
        # PrivateKey() failed, provided string is not a private key
        # -> treat it as a master password
        pk = PasswordKey(account, passwordkey, role=role, prefix=prefix)
        return str(pk.get_private())
Beispiel #4
0
def recover_account(account):
    """Recover ACCOUNT. This action has to be initiated/signed by the
    account to be recovered.

    """
    acc = Account(account)

    if acc.get_owner_history() == []:
        logger.error("@%s has an empty owner history - recovering "
                     "this account is not possible!" % (acc['name']))
        return

    # ask & verify the old owner key
    old_priv_owner_key = getpass("Enter the old master password or owner "
                                 "key for @%s: " % (acc['name']))
    old_pk = passwordkey_to_key(old_priv_owner_key,
                                acc['name'],
                                role="owner",
                                prefix=acc.steem.prefix)
    old_public_owner_key = format(old_pk.get_public(), acc.steem.prefix)

    # get the new password to prepare all new keys
    new_pwd = getpass("Enter the new master password for @%s: " %
                      (acc['name']))
    key_auths = {}
    for role in ['owner', 'active', 'posting', 'memo']:
        pk = PasswordKey(acc['name'], new_pwd, role=role)
        key_auths[role] = format(pk.get_public_key(), acc.steem.prefix)
        if role == 'owner':
            new_priv_owner_key = str(pk.get_private())

    # Assemble the account recovery operation
    recent_owner_authority = {
        "key_auths": [[old_public_owner_key, 1]],
        "account_auths": [],
        "weight_threshold": 1,
        "prefix": acc.steem.prefix
    }
    new_owner_authority = {
        "key_auths": [[key_auths['owner'], 1]],
        "account_auths": [],
        "weight_threshold": 1,
        "prefix": acc.steem.prefix
    }
    op = operations.Recover_account(
        **{
            'account_to_recover': acc['name'],
            'new_owner_authority': new_owner_authority,
            'recent_owner_authority': recent_owner_authority,
            'extensions': [],
            "prefix": acc.steem.prefix
        })

    # Send the recovery operations to the blockchain
    tb = TransactionBuilder(steem_instance=acc.steem)
    tb.appendOps([op])
    tb.appendWif(new_priv_owner_key)
    tb.appendWif(old_priv_owner_key)
    tb.sign()
    tb.broadcast()
    logger.info("@%s recovered." % (acc['name']))

    # Assemble the account update operation
    op = operations.Account_update(
        **{
            "account": acc["name"],
            'active': {
                'account_auths': [],
                'key_auths': [[key_auths['active'], 1]],
                "address_auths": [],
                'weight_threshold': 1,
                'prefix': acc.steem.prefix
            },
            'posting': {
                'account_auths': acc['posting']['account_auths'],
                'key_auths': [[key_auths['posting'], 1]],
                "address_auths": [],
                'weight_threshold': 1,
                'prefix': acc.steem.prefix
            },
            'memo_key': key_auths['memo'],
            "json_metadata": acc['json_metadata'],
            "prefix": acc.steem.prefix
        })

    # Send the recovery operations to the blockchain
    tb = TransactionBuilder(steem_instance=acc.steem)
    tb.appendOps([op])
    tb.appendWif(new_priv_owner_key)
    tb.sign()
    tb.broadcast()
    logger.info("SUCCESS: @%s's active, posting and memo keys updated." %
                (acc['name']))
Beispiel #5
0
def suggest_keys(account, custom_password):
    """Suggest a set of new keys for ACCOUNT. This should be called by the
    owner of the account to be recovered.

    """
    acc = Account(account)
    if acc.get_owner_history() == []:
        logger.warning("@%s has an empty owner history - recovering "
                       "this account won't be possible!" % (acc['name']))

    # Ask or generate a new master password
    if custom_password:
        new_password = getpass("Enter new master password for %s: " %
                               (acc['name']))
        repMasterPwd = getpass("Repeat new master password for %s: " %
                               (acc['name']))
        if new_password != repMasterPwd:
            raise ValueError("The passwords do not match!")
    else:
        new_password = "******" + str(PrivateKey(prefix=acc.steem.prefix))

    # Derive the new keys
    owner = PasswordKey(acc['name'],
                        new_password,
                        role='owner',
                        prefix=acc.steem.prefix)
    active = PasswordKey(acc['name'],
                         new_password,
                         role='active',
                         prefix=acc.steem.prefix)
    posting = PasswordKey(acc['name'],
                          new_password,
                          role='posting',
                          prefix=acc.steem.prefix)
    memo = PasswordKey(acc['name'],
                       new_password,
                       role='memo',
                       prefix=acc.steem.prefix)

    # Print results
    print("\n1.) Store the new master password and keys safely!")
    if not custom_password:
        t = PrettyTable([
            'New PRIVATE keys', 'DO NOT PUBLISH OR FORWARD, '
            'STORE SAFELY!'
        ])
        t.add_row(['Account', acc['name']])
        t.add_row(['New private master password', new_password])
        t.add_row(['New private active key', active.get_private()])
        t.add_row(['New private posting key', posting.get_private()])
        t.add_row(['New private memo key', memo.get_private()])
        print(t)

    print("\n2.) Make sure you stored the new password and keys safely!")
    print("\n3.) Forward the new PUBLIC owner key to your recovery account:")
    t = PrettyTable(
        ['New PUBLIC owner key', 'Forward this to your '
         'recovery partner'])
    t.add_row(["Account", acc['name']])
    t.add_row(
        ["New public owner key",
         format(owner.get_public(), acc.steem.prefix)])
    t.add_row(["Recovery partner", acc['recovery_account']])
    print(t)
Beispiel #6
0
#!/usr/bin/env python3
from getpass import getpass

from beemgraphenebase.account import PasswordKey
from tabulate import tabulate

hive_id = input("Hive User ID: ")
brain_key = getpass(prompt="Master Password: "******"owner", "active", "posting", "memo"]
data = []
for role in roles:
    keys = PasswordKey(hive_id, brain_key, role=role, prefix="STM")
    priv_key = keys.get_private()
    pub_key = keys.get_public()
    data.append([role, str(pub_key), str(priv_key)])

print(tabulate(data, headers=["Role", "Public Key", "Private Key"]))
if format(pk_validity_check, stm.prefix) != new_owner_key:
    raise ValueError("Invalid public owner key!")


#####################################################################
# Ask and verify the active key of the recovery account
#####################################################################
recovery_ak = getpass("Enter active key, owner key or master "
                      "password for @%s: " % (args.recovery_account))
try:
    pk_check = PrivateKey(recovery_ak, prefix=stm.prefix)
except Exception:
    # PrivateKey() failed - treat it as a master password
    pk = PasswordKey(args.recovery_account, recovery_ak,
                     role="active", prefix=stm.prefix)
    recovery_ak = str(pk.get_private())


#####################################################################
# Assemble the account recovery request operation
#####################################################################
new_owner_authority = {
    'key_auths': [[new_owner_key, 1]],
    'account_auths': [],
    'weight_threshold': 1,
    'prefix': stm.prefix
    }

op = operations.Request_account_recovery(**{
    'account_to_recover': args.account_to_recover,
    'recovery_account': args.recovery_account,
                      prefix=stm.prefix)
memo = PasswordKey(account['name'],
                   new_password,
                   role='memo',
                   prefix=stm.prefix)

#####################################################################
# Print results
#####################################################################
print("\n1.) Store the new master password and keys safely!")
if not args.custom_password:
    t = PrettyTable(
        ['New PRIVATE keys', 'DO NOT PUBLISH OR FORWARD, '
         'STORE SAFELY!'])
    t.add_row(['Account', account['name']])
    t.add_row(['New private master password', new_password])
    t.add_row(['New private active key', active.get_private()])
    t.add_row(['New private posting key', posting.get_private()])
    t.add_row(['New private memo key', memo.get_private()])
    print(t)

print("\n2.) Make sure you stored the new password and keys safely!")

print("\n3.) Forward the new PUBLIC owner key to your recovery account:")
t = PrettyTable(
    ['New PUBLIC owner key', 'Forward this to your '
     'recovery partner'])
t.add_row(["Account", account['name']])
t.add_row(["New public owner key", format(owner.get_public(), stm.prefix)])
print(t)
Beispiel #9
0
                         old_priv_owner_key,
                         role="owner",
                         prefix=stm.prefix)
    old_priv_owner_key = str(old_pk.get_private())
    old_public_owner_key = format(old_pk.get_public(), stm.prefix)

#####################################################################
# get the new password to prepare all new keys
#####################################################################
new_pwd = getpass("Enter the new master password for @%s: " % (acc['name']))
key_auths = {}
for role in ['owner', 'active', 'posting', 'memo']:
    pk = PasswordKey(acc['name'], new_pwd, role=role)
    key_auths[role] = format(pk.get_public_key(), stm.prefix)
    if role == 'owner':
        new_priv_owner_key = str(pk.get_private())

#####################################################################
# Assemble the account recovery operation
#####################################################################
recent_owner_authority = {
    "key_auths": [[old_public_owner_key, 1]],
    "account_auths": [],
    "weight_threshold": 1,
    "prefix": stm.prefix
}
new_owner_authority = {
    "key_auths": [[key_auths['owner'], 1]],
    "account_auths": [],
    "weight_threshold": 1,
    "prefix": stm.prefix
Beispiel #10
0
# script for a tutorial: https://steemit.com/utopian-io/@blockchainstudio/owner-key-vs-master-password-offline-private-key-derivation-from-master-password-public-key-derivation-from-private-key

try:
    from beemgraphenebase.account import PasswordKey
except:
    from steem.steem import Steem
    from steembase.account import PasswordKey
import getpass

roles = ["posting", "active", "memo", "owner"]

print(
    "Warning! This will show your private keys on the screen if you enter your master password correctly."
)
print(
    "To show that key derivations can be done offline, it will not check whether the password is correct."
)

account = input("Enter account name: ")
password = getpass.getpass("Enter master password: "******"%s key" % role)

    pk = PasswordKey(account, password, role=role)

    print("  public:  %s" % pk.get_public())
    print("  private: %s" % pk.get_private())