def test_createmultisig(self): c = Commands(None, None, None) pubkeys = [ "03b25918969e43702abeb6a60942e72e3a3c603dfd272de59e7679a52f35527ccf", "0383cf538b41dbba7b7ee57a53bc673fef8a6896734ae587032f755ac0cba86cc2" ] result = c.createmultisig(2, pubkeys) result_rev = c.createmultisig(2, list(reversed(pubkeys))) assert result == result_rev assert result == { "address": "3AiUfSRMbvXzyAHhFoFAtVFibWPdkNV9DW", "redeemScript": ("52210383cf538b41dbba7b7ee57a53bc673fef8a6896734ae587032f755ac0cba86c" "c22103b25918969e43702abeb6a60942e72e3a3c603dfd272de59e7679a52f35527ccf52ae" ) }
def run_offline_command(config, config_options): cmdname = config.get('cmd') cmd = known_commands[cmdname] password = config_options.get('password') if cmd.requires_wallet: wallet_path = config.get_wallet_path() if not WalletStorage.files_are_matched_by_path(wallet_path): print("Error: wallet does not exist at given path") sys.exit(1) storage = WalletStorage(wallet_path) if storage.is_encrypted(): storage.decrypt(password) parent_wallet = ParentWallet(storage) else: parent_wallet = None # check password if cmd.requires_password and parent_wallet.has_password(): try: parent_wallet.check_password(password) except InvalidPassword: print("Error: This password does not decode this wallet.") sys.exit(1) if cmd.requires_network: print("Warning: running command offline") # arguments passed to function args = [config.get(x) for x in cmd.params] # decode json arguments if cmdname not in ('setconfig', ): args = [json_decode(arg) for arg in args] # options kwargs = {} for x in cmd.options: kwargs[x] = (config_options.get(x) if x in ['password', 'new_password'] else config.get(x)) cmd_runner = Commands(config, parent_wallet, None) func = getattr(cmd_runner, cmd.name) result = func(*args, **kwargs) # save wallet if parent_wallet: parent_wallet.save_storage() return result
def run_offline_command(config, config_options): cmdname = config.get('cmd') cmd = known_commands[cmdname] password = config_options.get('password') if cmd.requires_wallet: wallet_path = config.get_cmdline_wallet_filepath() if not WalletStorage.files_are_matched_by_path(wallet_path): print("Error: wallet does not exist at given path") sys.exit(1) storage = WalletStorage(wallet_path) wallet = Wallet(storage) else: wallet = None if cmd.requires_password: try: wallet.check_password(password) except (InvalidPassword, IncompatibleWalletError): print( "Error: This password cannot access the wallet's private data." ) sys.exit(1) if cmd.requires_network: print("Warning: running command offline") # arguments passed to function args = [config.get(x) for x in cmd.params] # decode json arguments if cmdname not in ('setconfig', ): args = [json_decode(arg) for arg in args] # options kwargs = {} for x in cmd.options: kwargs[x] = (config_options.get(x) if x in ['password', 'new_password'] else config.get(x)) cmd_runner = Commands(config, wallet, None) func = getattr(cmd_runner, cmd.name) result = func(*args, **kwargs) # save wallet if wallet: wallet.save_storage() return result
def test_verifymessage(self): c = Commands(None, None, None) message = 'Hello' signature = privkey.sign_message_to_base64(message) address = privkey.public_key.to_address() assert c.verifymessage(address, signature, message)
def test_encrypt(self): c = Commands(None, None, None) msg = 'BitcoinSV' enc_msg = c.encrypt(pubkey_hex, msg) assert privkey.decrypt_message(enc_msg).decode() == msg