def generate_vault(): bitcointx.SelectParams('mainnet') m = int(input('How many total signatures will be required (aka "m"): ')) n = int(input('How many total keys do you want to generate (aka "n"): ')) privkeys = [] pubkeys = [] for counter in range(1, n): privkey = CBitcoinSecret.from_secret_bytes(os.urandom(32)) pubkey = privkey.pub privkeys.append(privkey) pubkeys.append(pubkey) counter = counter + 1 redeem_list = generate_multisig_redeem_list(pubkeys, m) script_pub_key = CScript([OP_0, sha256(CScript(redeem_list)).digest()]) address = P2WSHBitcoinAddress.from_scriptPubKey(script_pub_key) PATH = '/mnt/keys' if not os.path.isdir(PATH): subprocess.run(['mkdir', PATH]) counter = 1 while counter <= len(privkeys): if counter == 1: input('Insert a USB Drive. Press any key when complete.') else: input('Insert another USB Drive. Press any key when complete or \ press CTL+C to cancel.') subprocess.run(['lsblk']) dev = input( 'Enter the device and partition of the USB drive (ex: sdb1): ') subprocess.run(['umount', f'/dev/{dev}'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) subprocess.run(['mount', f'/dev/{dev}', PATH]) try: if not dev: raise ValueError('Bad Path.') keypath = os.path.join(PATH, f'key{counter}') addresspath = os.path.join(PATH, 'address') scriptpath = os.path.join(PATH, 'script') with open(keypath, 'w') as key_file: key_file.write(str(privkeys[(counter - 1)])) with open(addresspath, 'w') as address_file: address_file.write(str(address)) with open(scriptpath, 'w') as script_file: script_file.write(str(redeem_list)) for file in [keypath, addresspath, scriptpath]: os.chmod(file, S_IREAD | S_IRGRP | S_IROTH) except Exception as e: print(e) print('Bad path given. Try again.') continue subprocess.run(['umount', f'/dev/{dev}']) counter = counter + 1 print('Process complete.')
sys.stderr.write('Sorry, Python 3.x required by this example.\n') sys.exit(1) import hashlib from bitcointx import SelectParams from bitcointx.core import b2x, lx, COIN, COutPoint, CMutableTxOut, CMutableTxIn, CMutableTransaction, Hash160 from bitcointx.core.script import CScript, OP_DUP, OP_HASH160, OP_EQUALVERIFY, OP_CHECKSIG, SignatureHash, SIGHASH_ALL from bitcointx.core.scripteval import VerifyScript, SCRIPT_VERIFY_P2SH from bitcointx.wallet import CBitcoinAddress, CBitcoinSecret SelectParams('mainnet') # Create the (in)famous correct brainwallet secret key. h = hashlib.sha256(b'correct horse battery staple').digest() seckey = CBitcoinSecret.from_secret_bytes(h) # Same as the txid:vout the createrawtransaction RPC call requires # # lx() takes *little-endian* hex and converts it to bytes; in Bitcoin # transaction hashes are shown little-endian rather than the usual big-endian. # There's also a corresponding x() convenience function that takes big-endian # hex and converts it to bytes. txid = lx('7e195aa3de827814f172c362fcf838d92ba10e3f9fdd9c3ecaf79522b311b22d') vout = 0 # Create the txin structure, which includes the outpoint. The scriptSig # defaults to being empty. txin = CMutableTxIn(COutPoint(txid, vout)) # We also need the scriptPubKey of the output we're spending because
def compute_key(key_index: int) -> CBitcoinSecret: """ Deterministically generate a key from an index. """ h = hashlib.sha256(bytes(key_index)).digest() return CBitcoinSecret.from_secret_bytes(h)
import hashlib from config import * from bitcointx.core import b2x from bitcointx.core.script import * from bitcointx.wallet import CCoinAddress, CBitcoinSecret import binascii unhexlify = binascii.unhexlify # # Create AW, RW and secret and public keys AW_privkeys = [ CBitcoinSecret.from_secret_bytes( hashlib.sha256(b'Active Wallet Brain Secret 1').digest()), CBitcoinSecret.from_secret_bytes( hashlib.sha256(b'Active Wallet Brain Secret 2').digest()), CBitcoinSecret.from_secret_bytes( hashlib.sha256(b'Active Wallet Brain Secret 3').digest()) ] RW_privkeys = [ CBitcoinSecret.from_secret_bytes( hashlib.sha256(b'Recovery Wallet Brain Secret 1').digest()), CBitcoinSecret.from_secret_bytes( hashlib.sha256(b'Recovery Wallet Brain Secret 2').digest()), CBitcoinSecret.from_secret_bytes( hashlib.sha256(b'Recovery Wallet Brain Secret 3').digest()) ] AW_pubkeys = [x.pub for x in AW_privkeys] RW_pubkeys = [x.pub for x in RW_privkeys]