Exemple #1
0
    def get_settings(self):

        self.log.info('Getting settings info for Market %s' %
                      self.transport.market_id)
        settings = self.db.getOrCreate("settings",
                                       {"market_id": self.transport.market_id})

        if settings['arbiter'] == 1:
            settings['arbiter'] = True
        if settings['notary'] == 1:
            settings['notary'] = True

        settings['notaries'] = ast.literal_eval(
            settings['notaries']) if settings['notaries'] != "" else []
        settings['trustedArbiters'] = ast.literal_eval(
            settings['trustedArbiters']
        ) if settings['trustedArbiters'] != "" else []
        settings[
            'privkey'] = settings['privkey'] if 'secret' in settings else ""
        settings['btc_pubkey'] = privkey_to_pubkey(settings.get('privkey'))
        settings['secret'] = settings['secret'] if 'secret' in settings else ""

        self.log.info('SETTINGS: %s' % settings)

        if settings:
            return settings
        else:
            return {}
Exemple #2
0
def mk_stealth_tx_outputs(stealth_addr, value, ephem_privkey, nonce, network='btc'):

    scan_pubkey, spend_pubkey = basic_stealth_address_to_pubkeys(stealth_addr)

    if network == 'btc':
        btc_magic_byte = 42
        if stealth_addr != pubkeys_to_basic_stealth_address(scan_pubkey, spend_pubkey, btc_magic_byte):
            raise Exception('Invalid btc mainnet stealth address: ' + stealth_addr)
        magic_byte_addr = 0

    elif network == 'testnet':
        testnet_magic_byte = 43
        if stealth_addr != pubkeys_to_basic_stealth_address(scan_pubkey, spend_pubkey, testnet_magic_byte):
            raise Exception('Invalid testnet stealth address: ' + stealth_addr)
        magic_byte_addr = 111

    ephem_pubkey = main.privkey_to_pubkey(ephem_privkey)
    output0 = {'script': mk_stealth_metadata_script(ephem_pubkey, nonce),
               'value': 0}

    pay_pubkey = uncover_pay_pubkey_sender(scan_pubkey, spend_pubkey, ephem_privkey)
    pay_addr = main.pubkey_to_address(pay_pubkey, magic_byte_addr)
    output1 = {'address': pay_addr,
               'value': value}

    return [output0, output1]
def mk_stealth_tx_outputs(stealth_addr,
                          value,
                          ephem_privkey,
                          nonce,
                          network='btc'):

    scan_pubkey, spend_pubkey = basic_stealth_address_to_pubkeys(stealth_addr)

    if network == 'btc':
        btc_magic_byte = 42
        if stealth_addr != pubkeys_to_basic_stealth_address(
                scan_pubkey, spend_pubkey, btc_magic_byte):
            raise Exception('Invalid btc mainnet stealth address: ' +
                            stealth_addr)
        magic_byte_addr = 0

    elif network == 'testnet':
        testnet_magic_byte = 43
        if stealth_addr != pubkeys_to_basic_stealth_address(
                scan_pubkey, spend_pubkey, testnet_magic_byte):
            raise Exception('Invalid testnet stealth address: ' + stealth_addr)
        magic_byte_addr = 111

    ephem_pubkey = main.privkey_to_pubkey(ephem_privkey)
    output0 = {
        'script': mk_stealth_metadata_script(ephem_pubkey, nonce),
        'value': 0
    }

    pay_pubkey = uncover_pay_pubkey_sender(scan_pubkey, spend_pubkey,
                                           ephem_privkey)
    pay_addr = main.pubkey_to_address(pay_pubkey, magic_byte_addr)
    output1 = {'address': pay_addr, 'value': value}

    return [output0, output1]
def makePrivCryptor(privkey_hex):
    privkey_bin = '\x02\xca\x00 ' + arithmetic.changebase(privkey_hex,
                                                          16, 256, minlen=32)
    pubkey_hex = arithmetic.privkey_to_pubkey(privkey_hex)
    pubkey_bin_bare = arithmetic.changebase(pubkey_hex, 16, 256, minlen=65)[1:]
    pubkey_bin = '\x02\xca\x00 ' + pubkey_bin_bare[:32] + '\x00 ' + pubkey_bin_bare[32:]
    cryptor = ec.ECC(curve='secp256k1', privkey=privkey_bin, pubkey=pubkey_bin)
    return cryptor
def makePrivCryptor(privkey_hex):
    privkey_bin = '\x02\xca\x00 ' + arithmetic.changebase(
        privkey_hex, 16, 256, minlen=32)
    pubkey_hex = arithmetic.privkey_to_pubkey(privkey_hex)
    pubkey_bin_bare = arithmetic.changebase(pubkey_hex, 16, 256, minlen=65)[1:]
    pubkey_bin = '\x02\xca\x00 ' + pubkey_bin_bare[:
                                                   32] + '\x00 ' + pubkey_bin_bare[
                                                       32:]
    cryptor = ec.ECC(curve='secp256k1', privkey=privkey_bin, pubkey=pubkey_bin)
    return cryptor
Exemple #6
0
    def get_settings(self):

        self.log.info('Getting settings info for Market %s' % self.transport.market_id)
        settings = self.db.getOrCreate("settings", {"market_id": self.transport.market_id})

        if settings['arbiter'] == 1:
            settings['arbiter'] = True
        if settings['notary'] == 1:
            settings['notary'] = True

        settings['notaries'] = ast.literal_eval(settings['notaries']) if settings['notaries'] != "" else []
        settings['trustedArbiters'] = ast.literal_eval(settings['trustedArbiters']) if settings['trustedArbiters'] != "" else []
        settings['privkey'] = settings['privkey'] if 'secret' in settings else ""
        settings['btc_pubkey'] = privkey_to_pubkey(settings.get('privkey'))
        settings['secret'] = settings['secret'] if 'secret' in settings else ""

        self.log.info('SETTINGS: %s' % settings)

        if settings:
            return settings
        else:
            return {}
Exemple #7
0
    def get_settings(self):

        self.log.info("Getting settings info for Market %s" % self.transport.market_id)
        settings = self.db.getOrCreate("settings", {"market_id": self.transport.market_id})

        if settings["arbiter"] == 1:
            settings["arbiter"] = True
        if settings["notary"] == 1:
            settings["notary"] = True

        settings["notaries"] = ast.literal_eval(settings["notaries"]) if settings["notaries"] != "" else []
        settings["trustedArbiters"] = (
            ast.literal_eval(settings["trustedArbiters"]) if settings["trustedArbiters"] != "" else []
        )
        settings["privkey"] = settings["privkey"] if "secret" in settings else ""
        settings["btc_pubkey"] = privkey_to_pubkey(settings.get("privkey"))
        settings["secret"] = settings["secret"] if "secret" in settings else ""

        self.log.info("SETTINGS: %s" % settings)

        if settings:
            return settings
        else:
            return {}
    def _setup_settings(self):

        try:
            self.settings = self.db.selectEntries("settings", {"market_id": self.market_id})
        except (OperationalError, DatabaseError) as e:
            print e
            raise SystemExit("database file %s corrupt or empty - cannot continue" % self.db.db_path)

        if len(self.settings) == 0:
            self.settings = {"market_id": self.market_id, "welcome": "enable"}
            self.db.insertEntry("settings", self.settings)
        else:
            self.settings = self.settings[0]

        # Generate PGP key during initial setup or if previous PGP gen failed
        if not ('PGPPubKey' in self.settings and self.settings["PGPPubKey"]):
            try:
                self.log.info('Generating PGP keypair. This may take several minutes...')
                print 'Generating PGP keypair. This may take several minutes...'
                gpg = gnupg.GPG()
                input_data = gpg.gen_key_input(key_type="RSA",
                                               key_length=2048,
                                               name_email='*****@*****.**',
                                               name_comment="Autogenerated by Open Bazaar",
                                               passphrase="P@ssw0rd")
                assert input_data is not None
                key = gpg.gen_key(input_data)
                assert key is not None

                pubkey_text = gpg.export_keys(key.fingerprint)
                newsettings = {"PGPPubKey": pubkey_text, "PGPPubkeyFingerprint": key.fingerprint}
                self.db.updateEntries("settings", {"market_id": self.market_id}, newsettings)
                self.settings.update(newsettings)

                self.log.info('PGP keypair generated.')
            except Exception as e:
                self.log.error("Encountered a problem with GPG: %s" % e)
                raise SystemExit("Encountered a problem with GPG: %s" % e)

        if not ('pubkey' in self.settings and self.settings['pubkey']):
            # Generate Bitcoin keypair
            self._generate_new_keypair()

        if not ('nickname' in self.settings and self.settings['nickname']):
            newsettings = {'nickname': 'Default'}
            self.db.updateEntries('settings', {"market_id": self.market_id}, newsettings)
            self.settings.update(newsettings)

        self.nickname = self.settings['nickname'] if 'nickname' in self.settings else ""
        self.secret = self.settings['secret'] if 'secret' in self.settings else ""
        self.pubkey = self.settings['pubkey'] if 'pubkey' in self.settings else ""
        self.privkey = self.settings.get('privkey')
        self.btc_pubkey = privkey_to_pubkey(self.privkey)
        self.guid = self.settings['guid'] if 'guid' in self.settings else ""
        self.sin = self.settings['sin'] if 'sin' in self.settings else ""
        self.bitmessage = self.settings['bitmessage'] if 'bitmessage' in self.settings else ""

        if not ('bitmessage' in self.settings and self.settings['bitmessage']):
            # Generate Bitmessage address
            if self.bitmessage_api is not None:
                self._generate_new_bitmessage_address()

        self._myself = ec.ECC(
            pubkey=pubkey_to_pyelliptic(self.pubkey).decode('hex'),
            raw_privkey=self.secret.decode('hex'),
            curve='secp256k1'
        )

        self.log.debug('Retrieved Settings: \n%s', pformat(self.settings))
Exemple #9
0
    def _setup_settings(self):

        try:
            self.settings = self.db.selectEntries(
                "settings", {"market_id": self.market_id})
        except (OperationalError, DatabaseError) as e:
            print e
            raise SystemExit(
                "database file %s corrupt or empty - cannot continue" %
                self.db.db_path)

        if len(self.settings) == 0:
            self.settings = {"market_id": self.market_id, "welcome": "enable"}
            self.db.insertEntry("settings", self.settings)
        else:
            self.settings = self.settings[0]

        # Generate PGP key during initial setup or if previous PGP gen failed
        if not ('PGPPubKey' in self.settings and self.settings["PGPPubKey"]):
            try:
                self.log.info(
                    'Generating PGP keypair. This may take several minutes...')
                print 'Generating PGP keypair. This may take several minutes...'
                gpg = gnupg.GPG()
                input_data = gpg.gen_key_input(
                    key_type="RSA",
                    key_length=2048,
                    name_email='*****@*****.**',
                    name_comment="Autogenerated by Open Bazaar",
                    passphrase="P@ssw0rd")
                assert input_data is not None
                key = gpg.gen_key(input_data)
                assert key is not None

                pubkey_text = gpg.export_keys(key.fingerprint)
                newsettings = {
                    "PGPPubKey": pubkey_text,
                    "PGPPubkeyFingerprint": key.fingerprint
                }
                self.db.updateEntries("settings",
                                      {"market_id": self.market_id},
                                      newsettings)
                self.settings.update(newsettings)

                self.log.info('PGP keypair generated.')
            except Exception as e:
                self.log.error("Encountered a problem with GPG: %s" % e)
                raise SystemExit("Encountered a problem with GPG: %s" % e)

        if not ('pubkey' in self.settings and self.settings['pubkey']):
            # Generate Bitcoin keypair
            self._generate_new_keypair()

        if not ('bitmessage' in self.settings and self.settings['bitmessage']):
            # Generate Bitmessage address
            if self.bitmessage_api is not None:
                self._generate_new_bitmessage_address()

        if not ('nickname' in self.settings and self.settings['nickname']):
            newsettings = {'nickname': 'Default'}
            self.db.updateEntries('settings', {"market_id": self.market_id},
                                  newsettings)
            self.settings.update(newsettings)

        self.nickname = self.settings[
            'nickname'] if 'nickname' in self.settings else ""
        self.secret = self.settings[
            'secret'] if 'secret' in self.settings else ""
        self.pubkey = self.settings[
            'pubkey'] if 'pubkey' in self.settings else ""
        self.privkey = self.settings.get('privkey')
        self.btc_pubkey = privkey_to_pubkey(self.privkey)
        self.guid = self.settings['guid'] if 'guid' in self.settings else ""
        self.sin = self.settings['sin'] if 'sin' in self.settings else ""
        self.bitmessage = self.settings[
            'bitmessage'] if 'bitmessage' in self.settings else ""

        self._myself = ec.ECC(pubkey=pubkey_to_pyelliptic(
            self.pubkey).decode('hex'),
                              raw_privkey=self.secret.decode('hex'),
                              curve='secp256k1')

        self.log.debug('Retrieved Settings: \n%s', pformat(self.settings))
    def test_privtopub(self):
        pubkey_hex1 = arithmetic.privtopub(self.privkey_hex)
        pubkey_hex2 = main.privkey_to_pubkey(self.privkey_hex)

        self.assertEqual(pubkey_hex1, pubkey_hex2)
    def test_privtopub(self):
        pubkey_hex1 = arithmetic.privtopub(self.privkey_hex)
        pubkey_hex2 = main.privkey_to_pubkey(self.privkey_hex)

        self.assertEqual(pubkey_hex1, pubkey_hex2)