Esempio n. 1
0
 def mock_fork(self, bad_header):
     forkpoint = bad_header['block_height']
     b = blockchain.Blockchain(config=self.config,
                               forkpoint=forkpoint,
                               parent=None,
                               forkpoint_hash=bh2u(sha256(str(forkpoint))),
                               prev_hash=bh2u(sha256(str(forkpoint - 1))))
     return b
Esempio n. 2
0
    def check_from_x(self, x, prv):
        node = BIP32Node.from_xkey(x)

        self.assertEqual(self.xtype, node.xtype)
        self.assertEqual(1, node.depth)
        self.assertEqual(self.master_fpr, bh2u(node.fingerprint))
        self.assertEqual(self.child_num, bh2u(node.child_number))
        self.assertEqual(self.chain_code, bh2u(node.chaincode))
        self.assertEqual(self.pub_key, node.eckey.get_public_key_hex())
        if prv:
            self.assertEqual(self.sec_key, bh2u(node.eckey.get_secret_bytes()))
 def test_mnemonic_to_seed(self):
     for test_name, test in SEED_TEST_CASES.items():
         if test.words_hex is not None:
             self.assertEqual(test.words_hex, bh2u(test.words.encode('utf8')), msg=test_name)
         self.assertTrue(is_new_seed(test.words, prefix=test.seed_version), msg=test_name)
         m = mnemonic.Mnemonic(lang=test.lang)
         if test.entropy is not None:
             self.assertEqual(test.entropy, m.mnemonic_decode(test.words), msg=test_name)
         if test.passphrase_hex is not None:
             self.assertEqual(test.passphrase_hex, bh2u(test.passphrase.encode('utf8')), msg=test_name)
         seed = mnemonic.Mnemonic.mnemonic_to_seed(mnemonic=test.words, passphrase=test.passphrase)
         self.assertEqual(test.bip32_seed, bh2u(seed), msg=test_name)
Esempio n. 4
0
 def update(self, window: 'ElectrumWindow'):
     wallet = window.wallet
     if type(wallet) != Multisig_Wallet:
         return
     assert isinstance(wallet,
                       Multisig_Wallet)  # only here for type-hints in IDE
     if self.listener is None:
         self.logger.info("starting listener")
         self.listener = Listener(self)
         self.listener.start()
     elif self.listener:
         self.logger.info("shutting down listener")
         self.listener.stop()
         self.listener = None
     self.keys = []
     self.cosigner_list = []
     for key, keystore in wallet.keystores.items():
         xpub = keystore.get_master_public_key()  # type: str
         pubkey = BIP32Node.from_xkey(xpub).eckey.get_public_key_bytes(
             compressed=True)
         _hash = bh2u(crypto.sha256d(pubkey))
         if not keystore.is_watching_only():
             self.keys.append((key, _hash, window))
         else:
             self.cosigner_list.append((window, xpub, pubkey, _hash))
     if self.listener:
         self.listener.set_keyhashes([t[1] for t in self.keys])
Esempio n. 5
0
        def update(features):
            self.features = features
            set_label_enabled()
            if features.bootloader_hash:
                bl_hash = bh2u(features.bootloader_hash)
                bl_hash = "\n".join([bl_hash[:32], bl_hash[32:]])
            else:
                bl_hash = "N/A"
            noyes = [_("No"), _("Yes")]
            endis = [_("Enable Passphrases"), _("Disable Passphrases")]
            disen = [_("Disabled"), _("Enabled")]
            setchange = [_("Set a PIN"), _("Change PIN")]

            version = "%d.%d.%d" % (features.major_version,
                                    features.minor_version,
                                    features.patch_version)

            device_label.setText(features.label)
            pin_set_label.setText(noyes[features.pin_protection])
            passphrases_label.setText(disen[features.passphrase_protection])
            bl_hash_label.setText(bl_hash)
            label_edit.setText(features.label)
            device_id_label.setText(features.device_id)
            initialized_label.setText(noyes[features.initialized])
            version_label.setText(version)
            clear_pin_button.setVisible(features.pin_protection)
            clear_pin_warning.setVisible(features.pin_protection)
            pin_button.setText(setchange[features.pin_protection])
            pin_msg.setVisible(not features.pin_protection)
            passphrase_button.setText(endis[features.passphrase_protection])
            language_label.setText(features.language)
Esempio n. 6
0
 def gen_random_versioned_seed(cls):
     version = cls.LATEST_VERSION
     hex_seed = bh2u(os.urandom(16))
     checksum = cls.code_hashid(version + hex_seed)
     return VersionedSeed(version=version.upper(),
                          seed=hex_seed.upper(),
                          checksum=checksum.upper())
 def test_dsa_msg(self):
     msg = DashDsaMsg.from_hex(DSA_MSG)
     assert msg.nDenom == 2
     assert type(msg.txCollateral) == str
     tx = Transaction(msg.txCollateral)
     assert type(tx) == Transaction
     assert bh2u(msg.serialize()) == DSA_MSG
Esempio n. 8
0
 def test_push_script(self):
     # https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki#push-operators
     self.assertEqual(push_script(''), bh2u(bytes([opcodes.OP_0])))
     self.assertEqual(push_script('07'), bh2u(bytes([opcodes.OP_7])))
     self.assertEqual(push_script('10'), bh2u(bytes([opcodes.OP_16])))
     self.assertEqual(push_script('81'), bh2u(bytes([opcodes.OP_1NEGATE])))
     self.assertEqual(push_script('11'), '0111')
     self.assertEqual(push_script(75 * '42'), '4b' + 75 * '42')
     self.assertEqual(push_script(76 * '42'), bh2u(bytes([opcodes.OP_PUSHDATA1]) + bfh('4c' + 76 * '42')))
     self.assertEqual(push_script(100 * '42'), bh2u(bytes([opcodes.OP_PUSHDATA1]) + bfh('64' + 100 * '42')))
     self.assertEqual(push_script(255 * '42'), bh2u(bytes([opcodes.OP_PUSHDATA1]) + bfh('ff' + 255 * '42')))
     self.assertEqual(push_script(256 * '42'), bh2u(bytes([opcodes.OP_PUSHDATA2]) + bfh('0001' + 256 * '42')))
     self.assertEqual(push_script(520 * '42'), bh2u(bytes([opcodes.OP_PUSHDATA2]) + bfh('0802' + 520 * '42')))
 def test_dsq_msg(self):
     msg = DashDsqMsg.from_hex(DSQ_MSG)
     assert msg.nDenom == 2
     assert type(msg.masternodeOutPoint) == TxOutPoint
     assert msg.nTime == 1567673683
     assert msg.fReady
     assert len(msg.vchSig) == 96
     assert bh2u(msg.serialize()) == DSQ_MSG
Esempio n. 10
0
 def test_dssu_msg(self):
     msg = DashDssuMsg.from_hex(DSSU_MSG)
     assert msg.sessionID == 67305985
     assert msg.state == 5
     assert msg.entriesCount == 3
     assert msg.statusUpdate == 1
     assert msg.messageID == 21
     assert bh2u(msg.serialize()) == DSSU_MSG
Esempio n. 11
0
 def sign_transaction(self, keystore, tx: PartialTransaction, prev_tx):
     self.prev_tx = prev_tx
     client = self.get_client(keystore)
     inputs = self.tx_inputs(tx, for_sig=True, keystore=keystore)
     outputs = self.tx_outputs(tx, keystore=keystore)
     signatures = client.sign_tx(self.get_coin_name(), inputs, outputs,
                                 lock_time=tx.locktime, version=tx.version)[0]
     signatures = [(bh2u(x) + '01') for x in signatures]
     tx.update_signatures(signatures)
Esempio n. 12
0
 def test_dsi_msg(self):
     msg = DashDsiMsg.from_hex(DSI_MSG)
     assert len(msg.vecTxDSIn) == 2
     for txin in msg.vecTxDSIn:
         assert type(txin) == CTxIn
     assert type(msg.txCollateral) == str
     tx = Transaction(msg.txCollateral)
     assert type(tx) == Transaction
     assert len(msg.vecTxDSOut) == 2
     for txout in msg.vecTxDSOut:
         assert type(txout) == CTxOut
     assert bh2u(msg.serialize()) == DSI_MSG
Esempio n. 13
0
    def test_tx_outpoint(self):
        # test normal outpoint
        o = TxOutPoint(bfh(TEST_HASH)[::-1], 1)
        assert o.is_null == False
        assert o.hash_is_null == False
        assert str(o) == TEST_HASH + ':1'
        ser = o.serialize()
        assert bh2u(ser) == bh2u(bfh(TEST_HASH)[::-1]) + '01000000'
        s = BCDataStream()
        s.write(ser)
        o2 = TxOutPoint.read_vds(s)
        assert str(o2) == str(o)

        # test null outpoint
        o = TxOutPoint(b'\x00' * 32, -1)
        assert o.is_null == True
        assert o.hash_is_null == True
        assert str(o) == '0' * 64 + ':-1'
        ser = o.serialize()
        assert bh2u(ser) == '0' * 64 + 'f' * 8
        s = BCDataStream()
        s.write(ser)
        o2 = TxOutPoint.read_vds(s)
        assert str(o2) == str(o)

        # test null hash
        o = TxOutPoint(b'\x00' * 32, 0)
        assert o.is_null == False
        assert o.hash_is_null == True
        assert str(o) == '0' * 64 + ':0'
        ser = o.serialize()
        assert bh2u(ser) == '0' * 64 + '00000000'
        s = BCDataStream()
        s.write(ser)
        o2 = TxOutPoint.read_vds(s)
        assert str(o2) == str(o)
Esempio n. 14
0
 def sign_transaction(self, keystore, tx: PartialTransaction, prev_tx):
     prev_tx = {
         bfh(txhash): self.electrum_tx_to_txtype(tx)
         for txhash, tx in prev_tx.items()
     }
     client = self.get_client(keystore)
     inputs = self.tx_inputs(tx, for_sig=True, keystore=keystore)
     outputs = self.tx_outputs(tx, keystore=keystore)
     details = SignTx(lock_time=tx.locktime, version=tx.version)
     signatures, _ = client.sign_tx(self.get_coin_name(),
                                    inputs,
                                    outputs,
                                    details=details,
                                    prev_txes=prev_tx)
     signatures = [(bh2u(x) + '01') for x in signatures]
     tx.update_signatures(signatures)
Esempio n. 15
0
 def test_version_msg(self):
     msg = DashVersionMsg.from_hex(VERSION_MSG)
     assert msg.version == 70215
     assert msg.services == 5
     assert msg.timestamp == 1567673683
     assert msg.recv_services == 0
     assert msg.recv_ip == IPv6Address('::')
     assert msg.recv_port == 0
     assert msg.trans_services == 5
     assert msg.trans_ip == IPv6Address('::')
     assert msg.trans_port == 0
     assert msg.nonce == 12615609395080869973
     assert msg.user_agent == b'/Dash Core:0.14.0.3/'
     assert msg.start_height == 169118
     assert msg.relay == 1
     assert msg.mnauth_challenge == bfh('9404092b784754ae2757c614d3e76ae1'
                                        '80dc66305055ee6e6c62b409c1d57b30')
     assert msg.fMasternode == 0
     assert bh2u(msg.serialize()) == VERSION_MSG
Esempio n. 16
0
 def test_dsc_msg(self):
     msg = DashDscMsg.from_hex(DSC_MSG)
     assert msg.sessionID == 67305985
     assert msg.messageID == 21
     assert bh2u(msg.serialize()) == DSC_MSG
Esempio n. 17
0
 def test_dss_msg(self):
     msg = DashDssMsg.from_hex(DSS_MSG)
     assert len(msg.inputs) == 2
     for txin in msg.inputs:
         assert type(txin) == CTxIn
     assert bh2u(msg.serialize()) == DSS_MSG
Esempio n. 18
0
 def test_dsf_msg(self):
     msg = DashDsfMsg.from_hex(DSF_MSG)
     assert msg.sessionID == 7
     assert type(msg.txFinal) == Transaction
     assert bh2u(msg.serialize()) == DSF_MSG
Esempio n. 19
0
 def test_mnemonic_to_seed_basic(self):
     # note: not a valid electrum seed
     seed = mnemonic.Mnemonic.mnemonic_to_seed(mnemonic='foobar', passphrase='none')
     self.assertEqual('741b72fd15effece6bfe5a26a52184f66811bd2be363190e07a42cca442b1a5bb22b3ad0eb338197287e6d314866c7fba863ac65d3f156087a5052ebc7157fce',
                      bh2u(seed))