def main() :
    parser = argparse.ArgumentParser(description='Generate CSV table with brain key, pub key and private key')
    parser.add_argument('--number', type=int, help='Number of brain keys to generate')
    parser.add_argument('--filename', type=str, help='filename to store CSV file in')
    parser.add_argument('-encrypt', help='Encrypt private key with BIP38!', action='store_true')
    parser.set_defaults(number=10)
    args = parser.parse_args()

    '''
    Optionally encrypt with BIP38
    '''
    pw = ""
    if args.encrypt :
        import getpass
        while True :
            pw = getpass.getpass('Passphrase: ')
            pwck = getpass.getpass('Retype passphrase: ')
            if(pw == pwck) :
                break
            else :
                print("Given Passphrases do not match!")

    t = PrettyTable(["wif", "pub", "sequence"])
    b = BrainKey()
    for i in range(0, args.number) :
        wif = b.get_private()
        pub = format(b.get_private().pubkey, prefix)
        if args.encrypt :  # (optionally) encrypt paper wallet
            try :
                wif = format(bip38.encrypt(wif, pw), "encwif")
            except :
                raise Exception("Error encoding the privkey for pubkey %s.  Already encrypted?" % pub)
            assert format(b.get_private(), 'wif') == format(bip38.decrypt(wif, pw), 'wif')

        t.add_row([wif, pub, b.sequence])
        b.next_sequence()

    print("This is your (unencrypted) Brainkey. Make sure to store it savely:")
    print("\n\n\t%s\n\n" % b.get_brainkey())
    print(t.get_string())

    if args.filename :
        with open(args.filename, 'w') as file:
            file.write("# This is your (unencrypted) Brainkey. Make sure to store it savely:\n")
            file.write("#\n#\t%s\n#\n" % b.get_brainkey())
        with open(args.filename, 'a') as csvfile:
            spamwriter = csv.writer(csvfile, delimiter=';')
            spamwriter.writerow(t.field_names)
            for r in t._rows :
                spamwriter.writerow(r)
 def test_BrainKey(self):
     b = BrainKey("COLORER BICORN KASBEKE FAERIE LOCHIA GOMUTI SOVKHOZ Y GERMAL AUNTIE PERFUMY TIME FEATURE GANGAN CELEMIN MATZO")
     keys = ["5Hsbn6kXio4bb7eW5bX7kTp2sdkmbzP8kGWoau46Cf7en7T1RRE",
             "5K9MHEyiSye5iFL2srZu3ZVjzAZjcQxUgUvuttcVrymovFbU4cc",
             "5JBXhzDWQdYPAzRxxuGtzqM7ULLKPK7GZmktHTyF9foGGfbtDLT",
             "5Kbbfbs6DmJFNddWiP1XZfDKwhm5dkn9KX5AENQfQke2RYBBDcz",
             "5JUqLwgxn8f7myNz4gDwo5e77HZgopHMDHv4icNVww9Rxu1GDG5",
             "5JNBVj5QVh86N8MUUwY3EVUmsZwChZftxnuJx22DzEtHWC4rmvK",
             "5JdvczYtxPPjQdXMki1tpNvuSbvPMxJG5y4ndEAuQsC5RYMQXuC",
             "5HsUSesU2YB4EA3dmpGtHh8aPAwEdkdhidG8hcU2Nd2tETKk85t",
             "5JpveiQd1mt91APyQwvsCdAXWJ7uag3JmhtSxpGienic8vv1k2W",
             "5KDGhQUqQmwcGQ9tegimSyyT4vmH8h2fMzoNe1MT9bEGvRvR6kD"]
     for i in keys:
         p = b.next_sequence().get_private()
         self.assertEqual(str(p), i)
Ejemplo n.º 3
0
 def test_BrainKey_sequences(self):
     b = BrainKey("COLORER BICORN KASBEKE FAERIE LOCHIA GOMUTI SOVKHOZ Y GERMAL AUNTIE PERFUMY TIME FEATURE GANGAN CELEMIN MATZO")
     keys = ["5Hsbn6kXio4bb7eW5bX7kTp2sdkmbzP8kGWoau46Cf7en7T1RRE",
             "5K9MHEyiSye5iFL2srZu3ZVjzAZjcQxUgUvuttcVrymovFbU4cc",
             "5JBXhzDWQdYPAzRxxuGtzqM7ULLKPK7GZmktHTyF9foGGfbtDLT",
             "5Kbbfbs6DmJFNddWiP1XZfDKwhm5dkn9KX5AENQfQke2RYBBDcz",
             "5JUqLwgxn8f7myNz4gDwo5e77HZgopHMDHv4icNVww9Rxu1GDG5",
             "5JNBVj5QVh86N8MUUwY3EVUmsZwChZftxnuJx22DzEtHWC4rmvK",
             "5JdvczYtxPPjQdXMki1tpNvuSbvPMxJG5y4ndEAuQsC5RYMQXuC",
             "5HsUSesU2YB4EA3dmpGtHh8aPAwEdkdhidG8hcU2Nd2tETKk85t",
             "5JpveiQd1mt91APyQwvsCdAXWJ7uag3JmhtSxpGienic8vv1k2W",
             "5KDGhQUqQmwcGQ9tegimSyyT4vmH8h2fMzoNe1MT9bEGvRvR6kD"]
     for i in keys:
         p = b.next_sequence().get_private()
         self.assertEqual(str(p), i)
Ejemplo n.º 4
0
def main() :
    parser = argparse.ArgumentParser(description='Generate CSV table with brain key, pub key and private key')
    parser.add_argument('--number', type=int, help='Number of brain keys to generate')
    parser.add_argument('--filename', type=str, help='filename to store CSV file in')
    parser.add_argument('-encrypt', help='Encrypt private key with BIP38!', action='store_true')
    parser.set_defaults(number=10)
    args = parser.parse_args()

    '''
    Optionally encrypt with BIP38
    '''
    pw = ""
    if args.encrypt :
        import getpass
        while True :
            pw = getpass.getpass('Passphrase: ')
            pwck = getpass.getpass('Retype passphrase: ')
            if(pw == pwck) :
                break
            else :
                print("Given Passphrases do not match!")

    t = PrettyTable(["wif", "pub", "sequence"])
    b = BrainKey()
    for i in range(0, args.number) :
        wif = b.get_private()
        pub = format(b.get_private().pubkey, prefix)
        if args.encrypt :  # (optionally) encrypt paper wallet
            try :
                wif = format(bip38.encrypt(wif, pw), "encwif")
            except :
                raise Exception("Error encoding the privkey for pubkey %s.  Already encrypted?" % pub)
            assert format(b.get_private(), 'wif') == format(bip38.decrypt(wif, pw), 'wif')

        qrwif = StringIO()
        qr = qrcode.QRCode(error_correction=qrcode.ERROR_CORRECT_H)
        qr.add_data(wif)
        qr.print_ascii(out=qrwif, tty=False, invert=False)

        qrpub = StringIO()
        qr = qrcode.QRCode(error_correction=qrcode.ERROR_CORRECT_H)
        qr.add_data(pub)
        qr.print_ascii(out=qrpub, tty=False, invert=False)

        t.add_row(["%s%s" % (qrwif.getvalue(), wif),
                   "%s%s" % (qrpub.getvalue(), pub),
                   b.sequence])
        b.next_sequence()

    print("This is your (unencrypted) Brainkey. Make sure to store it savely:")
    print("\n\n\t%s\n\n" % b.get_brainkey())

    t.hrules = 1
    t.vrules = 1
    t.padding_width = 1
    t.header = False
    data = t.get_string()
    print(data)

    if args.filename :
        with open(args.filename, 'w') as file:
            file.write("# This is your (unencrypted) Brainkey. Make sure to store it savely:\n")
            file.write("#\n#\t%s\n#\n" % b.get_brainkey())
        with open(args.filename, 'a') as csvfile:
            spamwriter = csv.writer(csvfile, delimiter=';')
            spamwriter.writerow(t.field_names)
            for r in t._rows :
                spamwriter.writerow(r)
Ejemplo n.º 5
0
    def create_account(self,
                       account_name,
                       json_meta="",
                       creator=None,
                       additional_owner_keys=[],
                       additional_active_keys=[],
                       additional_posting_keys=[],
                       additional_owner_accounts=[],
                       additional_active_accounts=[],
                       additional_posting_accounts=[],
                       storekeys=True,
                       ):
        """ Create new account in Steem and store new keys in the wallet
            automatically and return the brain key.

            The brainkey can be used to recover all generated keys (see
            `graphenebase.account` for more details.

            By default, this call will use ``default_author`` to
            register a new name ``account_name`` with all keys being
            derived from a new brain key that will be returned. The
            corresponding keys will automatically be installed in the
            wallet.

            :param str account_name: (**required**) new account name
            :param str json_meta: Optional meta data for the account
            :param str creator: which account should pay the registration fee
                                (defaults to ``default_author``)
            :param array additional_owner_keys:  Additional owner public keys
            :param array additional_active_keys: Additional active public keys
            :param array additional_posting_keys: Additional posting public keys
            :param array additional_owner_accounts: Additional owner account names
            :param array additional_active_accounts: Additional acctive account names
            :param array additional_posting_accounts: Additional posting account names
            :param bool storekeys: Store new keys in the wallet (default: ``True``)

        """
        if not creator and config["default_author"]:
            creator = config["default_author"]
        if not creator:
            raise ValueError(
                "Not creator account given. Define it with " +
                "creator=x, or set the default_author in piston")

        if storekeys:
            wallet = Wallet(self.rpc)

        " Generate new keys "
        from graphenebase.account import BrainKey
        # owner
        key = BrainKey()
        brain_key = key.get_brainkey()
        if storekeys:
            wallet.addPrivateKey(key.get_private_key())
        owner = format(key.get_public_key(), prefix)

        # active
        key = key.next_sequence()
        if storekeys:
            wallet.addPrivateKey(key.get_private_key())
        active = format(key.get_public_key(), prefix)

        # posting
        key = key.next_sequence()
        if storekeys:
            wallet.addPrivateKey(key.get_private_key())
        posting = format(key.get_public_key(), prefix)

        # memo
        key = key.next_sequence()
        if storekeys:
            wallet.addPrivateKey(key.get_private_key())
        memo = format(key.get_public_key(), prefix)

        owner_key_authority = [[owner, 1]]
        active_key_authority = [[active, 1]]
        posting_key_authority = [[posting, 1]]
        owner_accounts_authority = []
        active_accounts_authority = []
        posting_accounts_authority = []

        # additional authorities
        for k in additional_owner_keys:
            owner_key_authority.append([k, 1])
        for k in additional_active_keys:
            active_key_authority.append([k, 1])
        for k in additional_posting_keys:
            posting_key_authority.append([k, 1])

        for k in additional_owner_accounts:
            owner_accounts_authority.append([k, 1])
        for k in additional_active_accounts:
            active_accounts_authority.append([k, 1])
        for k in additional_posting_accounts:
            posting_accounts_authority.append([k, 1])

        props = self.rpc.get_chain_properties()
        fee = props["account_creation_fee"]
        s = {'creator': creator,
             'fee': fee,
             'json_metadata': json_meta,
             'memo_key': memo,
             'new_account_name': account_name,
             'owner': {'account_auths': owner_accounts_authority,
                       'key_auths': owner_key_authority,
                       'weight_threshold': 1},
             'active': {'account_auths': active_accounts_authority,
                        'key_auths': active_key_authority,
                        'weight_threshold': 1},
             'posting': {'account_auths': posting_accounts_authority,
                         'key_auths': posting_key_authority,
                         'weight_threshold': 1}}

        op = transactions.Account_create(**s)
        if not self.wif:
            wif = Wallet(self.rpc).getPostingKeyForAccount(creator)
            self.executeOp(op, wif)
        else:
            self.executeOp(op)

        return brain_key