Esempio n. 1
0
 def __call__(self, value):
     value = str(value)
     if getattr(settings, 'TESTNET', False):
         if is_private_bip32_valid(value) != 'XTN':
             raise ValidationError(
                 u'%s is not a valid BIP32 testnet private key!' % value)
     else:
         if is_private_bip32_valid(value) != 'BTC':
             raise ValidationError(u'%s is not a valid BIP32 private key!' %
                                   value)
Esempio n. 2
0
    def test_is_public_private_bip32_valid(self):
        WALLET_KEYS = ["foo", "1", "2", "3", "4", "5"]

        # not all networks support BIP32 yet
        for netcode in "BTC XTN DOGE".split():
            for wk in WALLET_KEYS:
                wallet = BIP32Node.from_master_secret(wk.encode("utf8"), netcode=netcode)
                text = wallet.wallet_key(as_private=True)
                self.assertEqual(is_private_bip32_valid(text, allowable_netcodes=NETWORK_NAMES), netcode)
                self.assertEqual(is_public_bip32_valid(text, allowable_netcodes=NETWORK_NAMES), None)
                a = text[:-1] + chr(ord(text[-1])+1)
                self.assertEqual(is_private_bip32_valid(a, allowable_netcodes=NETWORK_NAMES), None)
                self.assertEqual(is_public_bip32_valid(a, allowable_netcodes=NETWORK_NAMES), None)
                text = wallet.wallet_key(as_private=False)
                self.assertEqual(is_private_bip32_valid(text, allowable_netcodes=NETWORK_NAMES), None)
                self.assertEqual(is_public_bip32_valid(text, allowable_netcodes=NETWORK_NAMES), netcode)
                a = text[:-1] + chr(ord(text[-1])+1)
                self.assertEqual(is_private_bip32_valid(a, allowable_netcodes=NETWORK_NAMES), None)
                self.assertEqual(is_public_bip32_valid(a, allowable_netcodes=NETWORK_NAMES), None)
Esempio n. 3
0
    def test_is_public_private_bip32_valid(self):
        NETWORK_NAMES = network_codes()
        WALLET_KEYS = ["foo", "1", "2", "3", "4", "5"]

        # not all networks support BIP32 yet
        for netcode in "BTC XTN DOGE".split():
            for wk in WALLET_KEYS:
                wallet = BIP32Node.from_master_secret(wk.encode("utf8"),
                                                      netcode=netcode)
                text = wallet.wallet_key(as_private=True)
                self.assertEqual(
                    is_private_bip32_valid(text,
                                           allowable_netcodes=NETWORK_NAMES),
                    netcode)
                self.assertEqual(
                    is_public_bip32_valid(text,
                                          allowable_netcodes=NETWORK_NAMES),
                    None)
                a = text[:-1] + chr(ord(text[-1]) + 1)
                self.assertEqual(
                    is_private_bip32_valid(a,
                                           allowable_netcodes=NETWORK_NAMES),
                    None)
                self.assertEqual(
                    is_public_bip32_valid(a, allowable_netcodes=NETWORK_NAMES),
                    None)
                text = wallet.wallet_key(as_private=False)
                self.assertEqual(
                    is_private_bip32_valid(text,
                                           allowable_netcodes=NETWORK_NAMES),
                    None)
                self.assertEqual(
                    is_public_bip32_valid(text,
                                          allowable_netcodes=NETWORK_NAMES),
                    netcode)
                a = text[:-1] + chr(ord(text[-1]) + 1)
                self.assertEqual(
                    is_private_bip32_valid(a,
                                           allowable_netcodes=NETWORK_NAMES),
                    None)
                self.assertEqual(
                    is_public_bip32_valid(a, allowable_netcodes=NETWORK_NAMES),
                    None)
Esempio n. 4
0
 def test_standard(self):
     hwif = self.api.create_wallet()
     self.assertTrue(validate.is_private_bip32_valid(
         hwif, allowable_netcodes=['XTN']
     ))
 def __call__(self, value):
     value = str(value)
     if is_private_bip32_valid(value) != 'BTC':
         raise ValidationError(u'%s is not a valid BIP32 private key!' % value)
Esempio n. 6
0
def wallet(testnet, hwif):
    hwif = unicode_str(hwif)
    netcode = 'XTN' if testnet else 'BTC'
    if not validate.is_private_bip32_valid(hwif, allowable_netcodes=[netcode]):
        raise exceptions.InvalidHWIF(hwif)
    return Key.from_text(hwif)
Esempio n. 7
0
def wallet(testnet, hwif):
    hwif = unicode_str(hwif)
    netcode = 'XTN' if testnet else 'BTC'
    if not validate.is_private_bip32_valid(hwif, allowable_netcodes=[netcode]):
        raise exceptions.InvalidHWIF(hwif)
    return Key.from_text(hwif)
Esempio n. 8
0
 def test_standard(self):
     hwif = self.api.create_wallet()
     self.assertTrue(
         validate.is_private_bip32_valid(hwif, allowable_netcodes=['XTN']))