示例#1
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))
示例#2
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
示例#3
0
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)
        stm.wallet.addPrivateKey(posting_privkey)
    else:
        stm = Steem(node=testnet_node,
                    wif={'active': str(active_privkey),
示例#4
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":
    account['name'],
示例#5
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']))
示例#6
0
    # 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())

#####################################################################
# 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": [],