Exemple #1
0
    def __init__(self, win):
        QWidget.__init__(self)
        self.win = win
        self.setWindowTitle('Electrum-DASH - '+_('Payment Request'))
        self.setMinimumSize(800, 250)
        self.address = ''
        self.label = ''
        self.amount = 0
        self.setFocusPolicy(Qt.NoFocus)

        main_box = QHBoxLayout()

        self.qrw = QRCodeWidget()
        main_box.addWidget(self.qrw, 1)

        vbox = QVBoxLayout()
        main_box.addLayout(vbox)

        self.address_label = QLabel("")
        #self.address_label.setFont(QFont(MONOSPACE_FONT))
        vbox.addWidget(self.address_label)

        self.label_label = QLabel("")
        vbox.addWidget(self.label_label)

        self.amount_label = QLabel("")
        vbox.addWidget(self.amount_label)

        vbox.addStretch(1)
        self.setLayout(main_box)
    def setup_google_auth(self, window, _id, otp_secret):
        vbox = QVBoxLayout()
        window.set_layout(vbox)
        if otp_secret is not None:
            uri = "otpauth://totp/%s?secret=%s" % ('trustedcoin.com',
                                                   otp_secret)
            vbox.addWidget(
                QLabel("Please scan this QR code in Google Authenticator."))
            qrw = QRCodeWidget(uri)
            vbox.addWidget(qrw, 1)
            msg = _('Then, enter your Google Authenticator code:')
        else:
            label = QLabel(
                "This wallet is already registered, but it was never authenticated. To finalize your registration, please enter your Google Authenticator Code. If you do not have this code, delete the wallet file and start a new registration"
            )
            label.setWordWrap(1)
            vbox.addWidget(label)
            msg = _('Google Authenticator code:')

        hbox = QHBoxLayout()
        hbox.addWidget(QLabel(msg))
        pw = AmountEdit(None, is_int=True)
        pw.setFocus(True)
        hbox.addWidget(pw)
        hbox.addStretch(1)
        vbox.addLayout(hbox)

        b = OkButton(window, _('Next'))
        b.setEnabled(False)
        vbox.addLayout(Buttons(CancelButton(window), b))
        pw.textChanged.connect(lambda: b.setEnabled(len(pw.text()) == 6))

        while True:
            if not window.exec_():
                return False
            otp = pw.get_amount()
            try:
                server.auth(_id, otp)
                return True
            except:
                QMessageBox.information(self.window, _('Message'),
                                        _('Incorrect password'), _('OK'))
                pw.setText('')
Exemple #3
0
 def __init__(self, handler, data):
     '''Ask user for 2nd factor authentication. Support text, security card and paired mobile methods.
     Use last method from settings, but support new pairing and downgrade.
     '''
     QDialog.__init__(self, handler.top_level_window())
     self.handler = handler
     self.txdata = data
     self.idxs = self.txdata['keycardData'] if self.txdata['confirmationType'] > 1 else ''
     self.setMinimumWidth(650)
     self.setWindowTitle(_("Ledger Wallet Authentication"))
     self.cfg = copy.deepcopy(self.handler.win.wallet.get_keystore().cfg)
     self.dongle = self.handler.win.wallet.get_keystore().get_client().dongle
     self.ws = None
     self.pin = ''
     
     self.devmode = self.getDevice2FAMode()
     if self.devmode == 0x11 or self.txdata['confirmationType'] == 1:
         self.cfg['mode'] = 0
     
     vbox = QVBoxLayout()
     self.setLayout(vbox)
     
     def on_change_mode(idx):
         if idx < 2 and self.ws:
             self.ws.stop()
             self.ws = None
         self.cfg['mode'] = 0 if self.devmode == 0x11 else idx if idx > 0 else 1
         if self.cfg['mode'] > 1 and self.cfg['pair'] and not self.ws:
             self.req_validation()
         if self.cfg['mode'] > 0:
             self.handler.win.wallet.get_keystore().cfg = self.cfg
             self.handler.win.wallet.save_keystore()
         self.update_dlg()
     def add_pairing():
         self.do_pairing()
     def return_pin():
         self.pin = self.pintxt.text() if self.txdata['confirmationType'] == 1 else self.cardtxt.text() 
         if self.cfg['mode'] == 1:
             self.pin = ''.join(chr(int(str(i),16)) for i in self.pin)
         self.accept()
     
     self.modebox = QWidget()
     modelayout = QHBoxLayout()
     self.modebox.setLayout(modelayout)
     modelayout.addWidget(QLabel(_("Method:")))
     self.modes = QComboBox()
     modelayout.addWidget(self.modes, 2)
     self.addPair = QPushButton(_("Pair"))
     self.addPair.setMaximumWidth(60)
     modelayout.addWidget(self.addPair)
     modelayout.addStretch(1)
     self.modebox.setMaximumHeight(50)
     vbox.addWidget(self.modebox)
     
     self.populate_modes()
     self.modes.currentIndexChanged.connect(on_change_mode)
     self.addPair.clicked.connect(add_pairing)
     
     self.helpmsg = QTextEdit()
     self.helpmsg.setStyleSheet("QTextEdit { background-color: lightgray; }")
     self.helpmsg.setReadOnly(True)
     vbox.addWidget(self.helpmsg)
     
     self.pinbox = QWidget()
     pinlayout = QHBoxLayout()
     self.pinbox.setLayout(pinlayout)
     self.pintxt = QLineEdit()
     self.pintxt.setEchoMode(2)
     self.pintxt.setMaxLength(4)
     self.pintxt.returnPressed.connect(return_pin)
     pinlayout.addWidget(QLabel(_("Enter PIN:")))
     pinlayout.addWidget(self.pintxt)
     pinlayout.addWidget(QLabel(_("NOT DEVICE PIN - see above")))
     pinlayout.addStretch(1)
     self.pinbox.setVisible(self.cfg['mode'] == 0)
     vbox.addWidget(self.pinbox)
                 
     self.cardbox = QWidget()
     card = QVBoxLayout()
     self.cardbox.setLayout(card)
     self.addrtext = QTextEdit()
     self.addrtext.setStyleSheet("QTextEdit { color:blue; background-color:lightgray; padding:15px 10px; border:none; font-size:20pt; font-family:monospace; }")
     self.addrtext.setReadOnly(True)
     self.addrtext.setMaximumHeight(130)
     card.addWidget(self.addrtext)
     
     def pin_changed(s):
         if len(s) < len(self.idxs):
             i = self.idxs[len(s)]
             addr = self.txdata['address']
             if not constants.net.TESTNET:
                 text = addr[:i] + '<u><b>' + addr[i:i+1] + '</u></b>' + addr[i+1:]
             else:
                 # pin needs to be created from mainnet address
                 addr_mainnet = bitcoin.script_to_address(bitcoin.address_to_script(addr), net=constants.BitcoinMainnet)
                 addr_mainnet = addr_mainnet[:i] + '<u><b>' + addr_mainnet[i:i+1] + '</u></b>' + addr_mainnet[i+1:]
                 text = str(addr) + '\n' + str(addr_mainnet)
             self.addrtext.setHtml(str(text))
         else:
             self.addrtext.setHtml(_("Press Enter"))
             
     pin_changed('')    
     cardpin = QHBoxLayout()
     cardpin.addWidget(QLabel(_("Enter PIN:")))
     self.cardtxt = QLineEdit()
     self.cardtxt.setEchoMode(2)
     self.cardtxt.setMaxLength(len(self.idxs))
     self.cardtxt.textChanged.connect(pin_changed)
     self.cardtxt.returnPressed.connect(return_pin)
     cardpin.addWidget(self.cardtxt)
     cardpin.addWidget(QLabel(_("NOT DEVICE PIN - see above")))
     cardpin.addStretch(1)
     card.addLayout(cardpin)
     self.cardbox.setVisible(self.cfg['mode'] == 1)
     vbox.addWidget(self.cardbox)
     
     self.pairbox = QWidget()
     pairlayout = QVBoxLayout()
     self.pairbox.setLayout(pairlayout)
     pairhelp = QTextEdit(helpTxt[5])
     pairhelp.setStyleSheet("QTextEdit { background-color: lightgray; }")
     pairhelp.setReadOnly(True)
     pairlayout.addWidget(pairhelp, 1)
     self.pairqr = QRCodeWidget()
     pairlayout.addWidget(self.pairqr, 4)
     self.pairbox.setVisible(False)
     vbox.addWidget(self.pairbox)
     self.update_dlg()
     
     if self.cfg['mode'] > 1 and not self.ws:
         self.req_validation()