Skip to content

Instantly share code, notes, and snippets.

@ericgay
Created January 15, 2018 22:03
Show Gist options
  • Save ericgay/75c205cbabf6acd7768f8710e05b6904 to your computer and use it in GitHub Desktop.
Save ericgay/75c205cbabf6acd7768f8710e05b6904 to your computer and use it in GitHub Desktop.
Blockstack import wallet from a JSON file
#!/usr/bin/env python2
# usage: import_json_wallet wallet.json passphrase
import os, json, tempfile, sys, time, re
from blockstack_client.wallet import decrypt_wallet, inspect_wallet_data
wallet_filename = sys.argv[1]
password = sys.argv[2]
with open(wallet_filename) as wallet_file:
wallet_data = json.load(wallet_file)
decoded_wallet = decrypt_wallet(wallet_data, password)
if 'wallet' in decoded_wallet:
import_wallet_command = "blockstack import_wallet {0} {1} {2}".format(
decoded_wallet['wallet']['payment_privkey'] if isinstance(decoded_wallet['wallet']['payment_privkey'], unicode) else "2,3," + ",".join(decoded_wallet['wallet']['payment_privkey']['private_keys']),
decoded_wallet['wallet']['owner_privkey'] if isinstance(decoded_wallet['wallet']['owner_privkey'], unicode) else "2,3," + ",".join(decoded_wallet['wallet']['payment_privkey']['private_keys']),
decoded_wallet['wallet']['data_privkey'])
os.system(import_wallet_command)
else:
print "error decrypting wallet"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment