示例#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
示例#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
示例#3
0
 def test_PasswordKey(self):
     a = [
         "Aang7foN3oz1Ungai2qua5toh3map8ladei1eem2ohsh2shuo8aeji9Thoseo7ah",
         "iep1Mees9eghiifahwei5iidi0Sazae9aigaeT7itho3quoo2dah5zuvobaelau5",
         "ohBeuyoothae5aer9odaegh5Eeloh1fi7obei9ahSh0haeYuas1sheehaiv5LaiX",
         "geiQuoo9NeeLoaZee0ain3Ku1biedohsesien4uHo1eib1ahzaesh5shae3iena7",
         "jahzeice6Ix8ohBo3eik9pohjahgeegoh9sahthai1aeMahs8ki7Iub1oojeeSuo",
         "eiVahHoh2hi4fazah9Tha8loxeeNgequaquuYee6Shoopo3EiWoosheeX6yohg2o",
         "PheeCh3ar8xoofoiphoo4aisahjiiPah4vah0eeceiJ2iyeem9wahyupeithah9T",
         "IuyiibahNgieshei2eeFu8aic1IeMae9ooXi9jaiwaht4Wiengieghahnguang0U",
         "Ipee1quee7sheughemae4eir8pheix3quac3ei0Aquo9ohieLaeseeh8AhGeM2ew",
         "Tech5iir0aP6waiMeiHoph3iwoch4iijoogh0zoh9aSh6Ueb2Dee5dang1aa8IiP"
     ]
     b = [
         "STM5NyCrrXHmdikC6QPRAPoDjSHVQJe3WC5bMZuF6YhqhSsfYfjhN",
         "STM8gyvJtYyv5ZbT2ZxbAtgufQ5ovV2bq6EQp4YDTzQuSwyg7Ckry",
         "STM7yE71iVPSpaq8Ae2AmsKfyFxA8pwYv5zgQtCnX7xMwRUQMVoGf",
         "STM5jRgWA2kswPaXsQNtD2MMjs92XfJ1TYob6tjHtsECg2AusF5Wo",
         "STM6XHwVxcP6zP5NV1jUbG6Kso9m8ZG9g2CjDiPcZpAxHngx6ATPB",
         "STM59X1S4ofTAeHd1iNHDGxim5GkLo2AdcznksUsSYGU687ywB5WV",
         "STM6BPPL4iSRbFVVN8v3BEEEyDsC1STRK7Ba9ewQ4Lqvszn5J8VAe",
         "STM7cdK927wj95ptUrCk6HKWVeF74LG5cTjDTV22Z3yJ4Xw8xc9qp",
         "STM7VNFRjrE1hs1CKpEAP9NAabdFpwvzYXRKvkrVBBv2kTQCbNHz7",
         "STM7ZZFhEBjujcKjkmY31i1spPMx6xDSRhkursZLigi2HKLuALe5t",
     ]
     for i, pwd in enumerate(a):
         p = format(
             PasswordKey("xeroc", pwd, "posting").get_public(), "STM")
         self.assertEqual(p, b[i])
示例#4
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())
示例#5
0
def getcred(username, wif):
    key_auths_public = {}
    key_auths_private = {}
    for role in ['owner', 'active', 'posting', 'memo']:
        pk = PasswordKey(username, wif, role=role, prefix="EUR")
        key_auths_public[role] = str(pk.get_public_key())
        key_auths_private[role] = str(pk.get_private_key())

    data = {
        "name":
        username,
        "wif":
        wif,
        "owner": [{
            "type": "public",
            "value": key_auths_public["owner"]
        }, {
            "type": "private",
            "value": key_auths_private["owner"]
        }],
        "active": [{
            "type": "public",
            "value": key_auths_public["active"]
        }, {
            "type": "private",
            "value": key_auths_private["active"]
        }],
        "posting": [{
            "type": "public",
            "value": key_auths_public["posting"]
        }, {
            "type": "private",
            "value": key_auths_private["posting"]
        }],
        "memo": [{
            "type": "public",
            "value": key_auths_public["memo"]
        }, {
            "type": "private",
            "value": key_auths_private["memo"]
        }]
    }
    print(json.dumps(data, indent=4))
示例#6
0
def checkwif(username, wif):
    key_auths_public = {}
    blk_auths_public = {}

    try:
        account = Account(username)
    except:
        return False

    for role in ['owner', 'active', 'posting', 'memo']:
        pk = PasswordKey(username, wif, role=role, prefix="EUR")
        key_auths_public[role] = str(pk.get_public_key())
        if role == "memo":
            blk_auths_public[role] = str(account.json()["memo_key"])
        else:
            blk_auths_public[role] = str(
                account.json()[role]["key_auths"][0][0])

        if key_auths_public[role] != blk_auths_public[role]:
            return False
    return True
示例#7
0
 def test_encrypt_decrypt(self):
     base58 = u'#HU6pdQ4Hh8cFrDVooekRPVZu4BdrhAe9RxrWrei2CwfAApAPdM4PT5mSV9cV3tTuWKotYQF6suyM4JHFBZz4pcwyezPzuZ2na7uwhRcLqFotsqxWRBpaXkNks2QCnYLS8'
     text = u'#爱'
     nonce = u'1462976530069648'
     wif = str(PasswordKey("", "", role="", prefix="STM").get_private_key())
     private_key = PrivateKey(wif=wif, prefix="STM")
     public_key = private_key.pubkey
     cypertext = encode_memo(private_key,
                             public_key,
                             nonce,
                             text,
                             prefix="STM")
     self.assertEqual(cypertext, base58)
     plaintext = decode_memo(private_key, cypertext)
     self.assertEqual(plaintext, text)
示例#8
0
            sys.exit("There's no such directory " + reldir)

cur_password = unix_getpass(prompt='Current password for @%s: ' %
                            (acc['name']))

if not checkwif(acc['name'], cur_password):
    sys.exit("Password provided is not correct.")

new_password = unix_getpass(prompt='New password for @%s: ' % (acc['name']))
repeat_pwd = unix_getpass(prompt='Repeat new password for @%s: ' %
                          (acc['name']))

assert (new_password == repeat_pwd)

signing_key = PasswordKey(acc['name'],
                          cur_password,
                          role="owner",
                          prefix=prefix)
wif = str(signing_key.get_private_key())

#Since we're going to build a transaction is simpler to do everything here instead of using a function
key_auths_public = {}
key_auths_private = {}
for role in ['owner', 'active', 'posting', 'memo']:
    pk = PasswordKey(acc['name'], new_password, role=role, prefix="EUR")
    key_auths_public[role] = str(pk.get_public_key())
    key_auths_private[role] = str(pk.get_private_key())

op = operations.Account_update(
    **{
        "account": acc["name"],
        'owner': {
示例#9
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']))
示例#10
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)
示例#11
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"]))
示例#12
0
        account = Account(args.account[0])
        break
    except Exception as exception:
        assert type(exception).__name__ == 'AccountDoesNotExistsException'
        assert exception.__class__.__name__ == 'AccountDoesNotExistsException'
        sys.exit(
            "The account provided doesn't exist in the EFTG Blockchain. Wrong account "
            + args.account[0])

password = args.password[0]

key_auths_public = {}
key_auths_private = {}
blk_auths_public = {}
for role in ['owner', 'active', 'posting', 'memo']:
    pk = PasswordKey(account['name'], password, role=role, prefix=prefix)
    key_auths_public[role] = str(pk.get_public_key())
    key_auths_private[role] = str(pk.get_private_key())
    if role == "memo":
        blk_auths_public[role] = str(account.json()["memo_key"])
    else:
        blk_auths_public[role] = str(account.json()[role]["key_auths"][0][0])

    if key_auths_public[role] != blk_auths_public[role]:
        sys.exit("Password provided is not correct. Public " + role + " key " +
                 key_auths_public[role] +
                 " doesn't match the one in the EFTG blockchain " +
                 blk_auths_public[role])

data = {
    "name":
#####################################################################
if args.custom_password:
    new_password = getpass("Enter new master password for %s: " %
                           (account['name']))
    repMasterPwd = getpass("Repeat new master password for %s: " %
                           (account['name']))
    if new_password != repMasterPwd:
        raise ValueError("The passwords do not match!")
else:
    new_password = "******" + str(PrivateKey(prefix=stm.prefix))

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

#####################################################################
示例#14
0
stm = Steem(node=args.node, nobroadcast=args.dry_mode)
acc = Account(args.account[0], steem_instance=stm)

#####################################################################
# ask & verify the old owner key
#####################################################################
old_priv_owner_key = getpass("Enter the old master password or owner "
                             "key for @%s: " % (acc['name']))
try:
    old_pk = PrivateKey(old_priv_owner_key, prefix=stm.prefix)
    old_public_owner_key = format(old_pk.get_public(), stm.prefix)
except Exception:
    # not a PrivateKey -> treat as master password
    old_pk = PasswordKey(acc['name'],
                         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())
 def time_PasswordKey(self):
     pwd = "Aang7foN3oz1Ungai2qua5toh3map8ladei1eem2ohsh2shuo8aeji9Thoseo7ah"
     format(PasswordKey("xeroc", pwd, "posting").get_public(), "STM")
示例#16
0
from beembase.objects import Permission

#capture user information
username = input('account to be recovered: ')
old_password = input('recent password for account: ')
new_password = input('new password for account: ')

recovery_account = input('account owner (recovery account): ')
recovery_account_private_key = input('account owner private ACTIVE key: ')

s = Steem(node=['https://api.steemit.com'],
          keys=[recovery_account_private_key])

#create new account owner keys
new_account_owner_private_key = PasswordKey(username,
                                            new_password,
                                            role='owner').get_private_key()
new_account_owner_private_key_string = str(new_account_owner_private_key)
new_account_owner_public_key = str(new_account_owner_private_key.pubkey)

#create old account owner keys
old_account_owner_private_key = PasswordKey(username,
                                            old_password,
                                            role='owner').get_private_key()
old_account_owner_private_key_string = str(old_account_owner_private_key)
old_account_owner_public_key = str(old_account_owner_private_key.pubkey)

#owner key format
new_owner_authority = {
    "key_auths": [[new_account_owner_public_key, 1]],
    "account_auths": [],
# PublicKey call to make sure it is a valid public key
pk_validity_check = PublicKey(new_owner_key, prefix=stm.prefix)
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,
示例#18
0
password = "******"
username = "******"
useWallet = False
walletpassword = "******"

if __name__ == "__main__":
    testnet_node = "https://testnet.steem.vc"
    stm = Steem(node=testnet_node)
    prefix = stm.prefix
    # curl --data "username=username&password=secretPassword" https://testnet.steem.vc/create
    if useWallet:
        stm.wallet.wipe(True)
        stm.wallet.create(walletpassword)
        stm.wallet.unlock(walletpassword)
    active_key = PasswordKey(username, password, role="active", prefix=prefix)
    owner_key = PasswordKey(username, password, role="owner", prefix=prefix)
    posting_key = PasswordKey(username, password, role="posting", prefix=prefix)
    memo_key = PasswordKey(username, password, role="memo", prefix=prefix)
    active_pubkey = active_key.get_public_key()
    owner_pubkey = owner_key.get_public_key()
    posting_pubkey = posting_key.get_public_key()
    memo_pubkey = memo_key.get_public_key()
    active_privkey = active_key.get_private_key()
    posting_privkey = posting_key.get_private_key()
    owner_privkey = owner_key.get_private_key()
    memo_privkey = memo_key.get_private_key()
    if useWallet:
        stm.wallet.addPrivateKey(owner_privkey)
        stm.wallet.addPrivateKey(active_privkey)
        stm.wallet.addPrivateKey(memo_privkey)
示例#19
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())