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)
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)
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)
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)
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)
def test_standard(self): hwif = self.api.create_wallet() self.assertTrue( validate.is_private_bip32_valid(hwif, allowable_netcodes=['XTN']))