Skip to content

Instantly share code, notes, and snippets.

@btchip
Created March 2, 2021 17:33
Show Gist options
  • Save btchip/f4ce6a37cc9d08949328678b51907dd4 to your computer and use it in GitHub Desktop.
Save btchip/f4ce6a37cc9d08949328678b51907dd4 to your computer and use it in GitHub Desktop.
Recovering a hex HW1 / first generation Nano hardware wallet seed
import wallycore
import binascii
import argparse
def get_public_address(key):
hashed = wallycore.hash160(wallycore.bip32_key_get_pub_key(key))
return wallycore.base58_from_bytes(bytearray([0x00]) + hashed, wallycore.BASE58_FLAG_CHECKSUM)
def test_path(mainKey, path):
testKey = wallycore.bip32_key_from_parent_path(mainKey, path, wallycore.BIP32_FLAG_SKIP_HASH)
address = get_public_address(testKey)
encodedPrivateKey = wallycore.wif_from_bytes(wallycore.bip32_key_get_priv_key(testKey), 0x80, wallycore.WALLY_WIF_FLAG_COMPRESSED)
print(address + " WIF " + encodedPrivateKey)
parser = argparse.ArgumentParser()
parser.add_argument("hexSeed", help="HW1/Nano printed 64 chars hex seed")
args = parser.parse_args()
seed = binascii.unhexlify(args.hexSeed)
mainKey = wallycore.bip32_key_from_seed(seed, wallycore.BIP32_VER_MAIN_PRIVATE, wallycore.BIP32_FLAG_SKIP_HASH)
test_path(mainKey, [0x8000002c, 0x80000000, 0x80000000, 0x0, 0x0])
test_path(mainKey, [0x8000002c, 0x80000000, 0x80000000, 0x1, 0x0])
test_path(mainKey, [0x80000000, 0x0, 0x0])
test_path(mainKey, [0x80000000, 0x1, 0x0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment