def execute(args: Namespace, wallet_passwd: str) -> None: from hathor.crypto.util import get_private_key_bytes, get_public_key_bytes_compressed from hathor.wallet import Wallet from hathor.wallet.util import generate_multisig_address, generate_multisig_redeem_script if (args.pubkey_count and args.pubkey_count > 16) or args.signatures_required > 16: print( 'Error: maximum number of public keys or signatures required is 16' ) return if not args.pubkey_count and not args.public_keys: print('Error: you must give at least pubkey_count or public_keys') return if args.dir: wallet = Wallet(directory=args.dir) else: wallet = Wallet() wallet.unlock(wallet_passwd.encode()) if args.public_keys: public_keys_hex = args.public_keys.split(',') public_bytes = [bytes.fromhex(pkh) for pkh in public_keys_hex] else: # If not public keys as parameter, we need to create them public_bytes = [] for i in range(args.pubkey_count): addr = wallet.get_unused_address() key = wallet.keys[addr] pk = key.get_private_key(wallet_passwd.encode()) public_key_bytes = get_public_key_bytes_compressed(pk.public_key()) public_bytes.append(public_key_bytes) print('------------------\n') print('Key {}\n'.format(i + 1)) print('Private key: {}\n'.format( get_private_key_bytes( pk, encryption_algorithm=serialization.BestAvailableEncryption( wallet_passwd.encode())).hex())) print('Public key: {}\n'.format(public_key_bytes.hex())) print('Address: {}\n'.format(addr)) # Then we create the redeem script redeem_script = generate_multisig_redeem_script(args.signatures_required, public_bytes) print('------------------\n') print('Redeem script:', redeem_script.hex()) print('\n') # Then we created the multisig address address = generate_multisig_address(redeem_script) print('------------------\n') print('MultiSig address:', address) print('------------------\n\n')
def setUp(self): super().setUp() self.network = 'testnet' self.manager = self.create_peer(self.network, unlock_wallet=True) self.public_keys = [ bytes.fromhex( '0250bf5890c9c6e9b4ab7f70375d31b827d45d0b7b4e3ba1918bcbe71b412c11d7' ), bytes.fromhex( '02d83dd1e9e0ac7976704eedab43fe0b79309166a47d70ec3ce8bbb08b8414db46' ), bytes.fromhex( '02358c539fa7474bf12f774749d0e1b5a9bc6e50920464818ebdb0043b143ae2ba' ) ] self.private_keys = [ '3081de304906092a864886f70d01050d303c301b06092a864886f70d01050c300e04089abeae5e8a8f75d302020800301d060960' '864801650304012a0410abbde27221fd302280c13fca7887c85e048190c41403f39b1e9bbc5b6b7c3be4729c054fae9506dc0f83' '61adcff0ea393f0bb3ca9f992fc2eea83d532691bc9a570ed7fb9e939e6d1787881af40b19fb467f06595229e29b5a6268d831f0' '287530c7935d154deac61dd4ced988166f9c98054912935b607e2fb332e11c95b30ea4686eb0bda7dd57ed1eeb25b07cea9669dd' 'e5210528a00653159626a5baa61cdee7f4', '3081de304906092a864886f70d01050d303c301b06092a864886f70d01050c300e040817ca6c6c47ade0de02020800301d060960' '864801650304012a041003746599b1d7dde5b875e4d8e2c4c157048190a25ccabb17e603260f8a1407bdca24904b6ae0aa9ae225' 'd87552e5a9aa62d98b35b2c6c78f33cb051f3a3932387b4cea6f49e94f14ee856d0b630d77c1299ad7207b0be727d338cf92a3ff' 'fe232aff59764240aff84e079a5f6fb3355048ac15703290a005a9a033fdcb7fcf582a5ddf6fd7b7c1193bd7912cd275a88a8a68' '23b6c3ed291b4a3f4724875a3ae058054c', '3081de304906092a864886f70d01050d303c301b06092a864886f70d01050c300e0408089f48fbf59fa92902020800301d060960' '864801650304012a041072f553e860b77654fd5fb80e5891e7c90481900fde272b88f9a70e7220b2d5adeda1ed29667527caedc2' '385be7f9e0d63defdde20557e90726e102f879eaf2233cceca8d4af239d5b2a159467255446f001c99b69e570bb176b95248fc21' 'cb752d463b494c2195411639989086336a530d1f4eae91493faf89368f439991baa947ebeca00be7f5099ed69606dc78a4cc384d' '41542350a9054c5fa1295305dfc37e5989' ] self.redeem_script = generate_multisig_redeem_script( 2, self.public_keys) self.multisig_address_b58 = generate_multisig_address( self.redeem_script) self.multisig_address = decode_address(self.multisig_address_b58) self.address = decode_address(self.manager.wallet.get_unused_address()) self.outside_address = decode_address(self.get_address(0))