Beispiel #1
0
    def create_blind_account(self):
        label = self.ui.blindLabel.text()
        generated = self.ui.blindBrainkeyPlain.toPlainText().strip()
        if len(generated) == 0:
            self.ui.blindBrainkeyPlain.setFocus()
            return
        bk = BrainKey(generated)

        bk.sequence = 0
        owner_key = bk.get_blind_private()

        private_key = owner_key

        private_wif = str(private_key)
        public_key = str(private_key.pubkey)

        self.iso.store.blindAccountStorage.add(public_key, label)
        self.iso.store.keyStorage.add(private_wif, public_key)
        table = self.ui.blindAccounts
        n = table.rowCount()

        self._insert_blind_account_row(n, label, public_key)

        self.ui.blindLabel.setText("")
        self.ui.blindBrainkeyPlain.setPlainText("")
        self.ba_page_balances()
Beispiel #2
0
    def setupRoom(self, from_key_or_label, room_brain_key):
        #		if self.setted_up:
        #			return
        #		self.setted_up = True
        self.isRoom = True

        from bitsharesbase.account import BrainKey
        room_bk = BrainKey(room_brain_key)
        to_priv = room_bk.get_blind_private()

        from_key, from_icon, from_label = self.keyExpandLabel(
            from_key_or_label)
        to_key, to_icon, to_label = str(to_priv.pubkey), "room", room_brain_key

        self._title_ = to_label
        self.ptab.setTabTitle(self, to_label)
        self._icon_ = self.ptab.setTabIcon(self, to_icon)

        self.from_pub = from_key
        self.to_pub = to_key

        self.roompriv = to_priv
        self.roompub = str(to_priv.pubkey)

        icons = self.ptab.tabIcons
        self.ui.toIcon.setPixmap(picon(icons[to_icon]))
        self.ui.toName.setText(to_label)
        self.ui.toPub.setText(to_key)
Beispiel #3
0
def getbrainkeys(ctx, limit):
    """ Return keys for cloudlogin
    """
    from bitsharesbase.account import BrainKey

    password = click.prompt("Passphrase", hide_input=True).strip()
    t = [["index", "wif", "pubkey", "accounts"]]
    wif = BrainKey(password)
    for i in range(limit):
        pubkey = format(wif.get_public_key(),
                        ctx.bitshares.rpc.chain_params["prefix"])

        t.append([
            i,
            str(wif.get_private_key()),
            pubkey,
            ctx.bitshares.wallet.getAccountFromPublicKey(pubkey) or "",
        ])
        next(wif)

    print_table(t)
Beispiel #4
0
	def openRoom(self, from_key_or_label, name, save=True, to_front=True):
		from bitsharesbase.account import BrainKey
		to_bk = BrainKey(name)
		to_priv = to_bk.get_blind_private()
		to_key = str(to_priv.pubkey)
		to_icon = "room"
		to_label = name
		
		self.add_room_key(to_priv)
		
		
		self.known_expansions[to_key] = (to_key, to_icon, to_label)
		tab = self.getmakeTab(from_key_or_label, to_key, to_front=to_front)
		tab.setupRoom(from_key_or_label, name)
		
		if save:
			store = self.iso.store.chatroomStorage
			try:
				store.add(name, str(to_priv.pubkey), self.server_url)
			except KeyError:
				pass
		
		return tab
Beispiel #5
0
    def create_blind_account(self):
        label = self.ui.blindLabel.text()
        generated = self.ui.blindBrainkeyPlain.toPlainText().strip()
        if len(generated) == 0:
            self.ui.blindBrainkeyPlain.setFocus()
            return
        if len(label) == 0:
            self.ui.blindLabel.setFocus()
            return
        bk = BrainKey(generated)

        bk.sequence = 0
        owner_key = bk.get_blind_private()

        private_key = owner_key

        private_wif = str(private_key)
        public_key = str(private_key.pubkey)

        try:
            with self.iso.unlockedWallet(reason='Add new blind account') as w:
                self.iso.store.blindAccountStorage.add(public_key, label)
                self.iso.store.keyStorage.add(private_wif, public_key)
        except WalletLocked:
            return
        except Exception as exc:
            showexc(exc)
            return

        table = self.ui.blindAccounts
        n = table.rowCount()

        self._insert_blind_account_row(n, label, public_key, 1)

        self.ui.blindLabel.setText("")
        self.ui.blindBrainkeyPlain.setPlainText("")
        self.ba_page_balances()
Beispiel #6
0
def create_account(acc_name):

    #get account if it exist
    try:
        acc = Account(acc_name, bitshares_instance=testnet)
        print("account exists " + acc_name)
    except:
        acc = None
        print("account doesn't exist " + acc_name)

    #check if we already have the active private key
    if acc is not None:
        active_public = acc["active"]["key_auths"][0][0]
        active_private = wallet.getPrivateKeyForPublicKey(active_public)
        if active_private is not None:
            print("active_private is already added")
            return

    #keys are generated from brain key which is equal to account name
    owner_key = BrainKey(acc_name, 0)
    active_key = BrainKey(str(owner_key.get_private_key()), 0)
    memo_key = BrainKey(str(active_key.get_private_key()), 0)

    owner_private = str(owner_key.get_private_key())
    owner_public = "ZGV" + str(owner_key.get_public_key())[3:]
    active_private = str(active_key.get_private_key())
    active_public = "ZGV" + str(active_key.get_public_key())[3:]
    memo_private = str(memo_key.get_private_key())
    memo_public = "ZGV" + str(memo_key.get_public_key())[3:]

    #private active key is added to the local key storage
    if not wallet.getPrivateKeyForPublicKey(active_public):
        wallet.addPrivateKey(active_private)
        print("active_private added " + active_private)

    #return if account already exists
    if acc is not None:
        return

    #create account
    testnet.create_account(acc_name,
                           registrar=source_name,
                           referrer=source_name,
                           owner_key=owner_public,
                           active_key=active_public,
                           memo_key=memo_public)
    print("account created " + acc_name)

    #transfer initial supply to the account
    testnet.transfer(acc_name, init_supply, "ZGV", account=source_account)
Beispiel #7
0
    def validateCurrentPage(self):
        c = self.currentId()

        if (c == AccountWizard.PAGE_INTRO):
            self.ui.passwordConfirm.setText("")

            if self.ui.rNewBrain.isChecked():
                generated = self.ui.brainkeyView.toPlainText()
                if not generated:
                    bk = BrainKey()  # this will generate a new one
                    self.ui.brainkeyView.setPlainText(bk.get_brainkey())

            if self.ui.rOldBrain.isChecked():
                self.ui.brainkeyView.setPlainText("")

            #self.button(QtGui.QWizard.NextButton).clicked.emit(True)

        if (c == AccountWizard.PAGE_OLD_BRAIN):
            entered = self.ui.brainkeyEdit.toPlainText()
            if not (entered):
                return False

            bk = BrainKey(entered)

            generated = self.ui.brainkeyView.toPlainText()
            if generated:
                # compare normalized brainkeys
                old_bk = BrainKey(generated)
                if old_bk.get_brainkey() != bk.get_brainkey():
                    showerror(
                        "Brainkey does not match the generated one",
                        additional=
                        "If you lose your brainkey, you will lose your account and funds."
                    )
                    return False

            # TODO: proper way to verify brain key?
            if len(bk.get_brainkey()) < 25 * 2:
                showerror("This does not look like a brain key")
                return False

            bk.sequence = 0
            owner_key = bk.get_private()
            active_key_index = 0  #find_first_unused_derived_key_index( owner_key )
            active_key = owner_key.derive_private_key(active_key_index)
            memo_key_index = 0  #find_first_unused_derived_key_index( active_key )
            memo_key = active_key.derive_private_key(memo_key_index)

            #bk.sequence = 0; active_key = bk.get_private()
            #bk.sequence = 1; owner_key = bk.get_private()
            #bk.sequence = 2; memo_key = bk.get_private()

            privs = ""
            privs += str(active_key) + "\n"
            privs += str(owner_key) + "\n"
            privs += str(memo_key) + "\n"

            print("Private keys (a,o,m)" + privs)

            #pubs = ""
            #pubs += str(active_key.pubkey) + "\n"
            #pubs += str(owner_key.pubkey) + "\n"
            #pubs += str(memo_key.pubkey) + "\n"

            self.ui.pubkeyOwner.setText(str(owner_key.pubkey))
            self.ui.pubkeyActive.setText(str(active_key.pubkey))
            self.ui.pubkeyMemo.setText(str(memo_key.pubkey))

            #self.ui.publicKeys.setPlainText(pubs)
            self.ui.privateKeys.setPlainText(privs)

        if (c == AccountWizard.PAGE_NEW_PASS):
            account_name = self.ui.inventAccount.text()
            password = self.ui.inventPassword.text()
            if not (account_name) or not (password):
                return False

            if len(password) < 12:
                showerror("Password should contain at least 12 characters")
                return False

            self.ui.oldAccount.setText(account_name)
            self.ui.inventPassword.setReadOnly(True)
            self.ui.passwordConfirm.setText("Confirm your password")

        if (c == AccountWizard.PAGE_OLD_PASS):
            account_name = self.ui.oldAccount.text()
            password = self.ui.oldPassword.text()
            if not (account_name) or not (password):
                return False

            old_password = self.ui.inventPassword.text()
            if old_password and (password != old_password):
                showerror(
                    "Password you entered during previous step does not match this one",
                    additional=
                    "If you lose your password, you will lose your account and funds."
                )
                return False

            active_key = PasswordKey(account_name, password, role="active")
            owner_key = PasswordKey(account_name, password, role="owner")
            memo_key = PasswordKey(account_name, password, role="memo")

            #print("Active key:", active_key.get_private(), active_key.get_public())
            #print("Owner key:", owner_key.get_private(), owner_key.get_public())
            #print("Memo key:", memo_key.get_private(), memo_key.get_public())

            privs = ""
            privs += str(active_key.get_private()) + "\n"
            privs += str(owner_key.get_private()) + "\n"
            privs += str(memo_key.get_private()) + "\n"

            print("Private keys (a,o,m)\n" + privs)

            #pubs = ""
            #pubs += str(active_key.get_public()) + "\n"
            #pubs += str(owner_key.get_public()) + "\n"
            #pubs += str(memo_key.get_public()) + "\n"

            self.ui.pubkeyOwner.setText(str(owner_key.get_public()))
            self.ui.pubkeyActive.setText(str(active_key.get_public()))
            self.ui.pubkeyMemo.setText(str(memo_key.get_public()))

            self.ui.accountName.setText(account_name)
            #self.ui.publicKeys.setPlainText(pubs)

            self.ui.accountEdit.setText(account_name)
            self.ui.privateKeys.setPlainText(privs)

        if (c == AccountWizard.PAGE_REGISTER):
            account_name = self.ui.accountName.text()

            self.ui.accountEdit.setText(account_name)

            #pubkeys = self.ui.publicKeys.toPlainText()
            #privkeys = self.ui.privateKeys.toPlainText()

            owner_key = self.ui.pubkeyOwner.text()
            active_key = self.ui.pubkeyActive.text()
            memo_key = self.ui.pubkeyMemo.text()

            if not account_name:
                showerror("Please enter account name", account_name)
                return False

            if not owner_key or not active_key or not memo_key:
                showerror("Please enter all three (owner, active, memo) keys")
                return False

            if self.ui.faucetBox.isVisible() == True:
                #config = self.iso.store.configStorage
                proxy = self.iso.get_proxy_config()
                print("Faucet using proxy", proxy)
                selected = self.ui.faucetBox.currentText()
                faucet = None
                for name, url, refurl, factory in KnownFaucets:
                    if name == selected:
                        faucet = BTSFaucet(url, refurl, proxyUrl=proxy)
                        break

                if not faucet:
                    showerror("No faucet selected")
                    return False

                try:
                    reg = faucet.register(account_name,
                                          owner_key,
                                          active_key,
                                          memo_key,
                                          refcode=None,
                                          referrer=None)
                except Exception as e:
                    import traceback
                    traceback.print_exc()
                    showexc(e)
                    return False
                except:
                    import traceback
                    traceback.print_exc()
                    return False

                from pprint import pprint
                print("REG:")
                pprint(reg)

            if self.ui.registrarBox.isVisible() == True:

                selected = self.ui.registrarBox.currentText()

                data = {
                    'name': account_name,
                    'owner_key': owner_key,
                    'active_key': active_key,
                    'memo_key': memo_key,
                }
                try:
                    trx = QTransactionBuilder.QRegisterAccount(
                        selected, selected, data, isolator=self.iso)
                    if not trx:
                        return False
                except BaseException as error:
                    showexc(error)
                    return False

            self.ui.accountStatus.setText("")
            self.ui.privkeysStatus.setText("Your account has been registered.")
            #self.button(QtGui.QWizard.NextButton).clicked.emit(True)

        return True
Beispiel #8
0
def create_acc(acc_num):
    acc = get_acc(acc_num)
    owner_key = BrainKey(acc["name"] + secret_passphrase, 0)
    active_key = BrainKey(str(owner_key.get_private_key()), 0)
    memo_key = BrainKey(str(active_key.get_private_key()), 0)

    owner_private = str(owner_key.get_private_key())
    owner_public = "ZGV" + str(owner_key.get_public_key())[3:]
    active_private = str(active_key.get_private_key())
    active_public = "ZGV" + str(active_key.get_public_key())[3:]
    memo_private = str(memo_key.get_private_key())
    memo_public = "ZGV" + str(memo_key.get_public_key())[3:]

    if not wallet.getPrivateKeyForPublicKey(active_public):
        wallet.addPrivateKey(active_private)
        print("active_private added " + active_private)

    testnet.create_account(acc["name"],
                           registrar=source_name,
                           referrer=source_name,
                           owner_key=owner_public,
                           active_key=active_public,
                           memo_key=memo_public)
    print(acc["name"] + " account created")
    acc["balance"] = 0
    return acc
Beispiel #9
0
 def generate_blind_brainkey(self):
     bk = BrainKey()  # this will generate a new one
     self.ui.blindBrainkeyPlain.setPlainText(bk.get_brainkey())
def create_account(acc_name):
    print("new account " + acc_name)
        
    #keys are generated from brain key which is equal to account name
    owner_key = BrainKey(acc_name, 0)
    active_key = BrainKey(str(owner_key.get_private_key()), 0)
    memo_key = BrainKey(str(active_key.get_private_key()), 0)

    owner_private = str(owner_key.get_private_key())
    owner_public = "ZGV" + str(owner_key.get_public_key())[3:]
    active_private = str(active_key.get_private_key())
    active_public = "ZGV" + str(active_key.get_public_key())[3:]
    memo_private = str(memo_key.get_private_key())
    memo_public = "ZGV" + str(memo_key.get_public_key())[3:]

    #private active key is added to the local key storage
    if not wallet.getPrivateKeyForPublicKey(active_public):
        wallet.addPrivateKey(active_private)
        print("active_private added " + active_private)

    testnet.create_account(
        acc_name,
        registrar=source_name,
        referrer=source_name,
        owner_key=owner_public,
        active_key=active_public,
        memo_key=memo_public)
    print("account created ")