|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright (c) 2018-2021 The Bitcoin Core developers |
| 3 | +# Distributed under the MIT software license, see the accompanying |
| 4 | +# file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 5 | + |
| 6 | +import os |
| 7 | +import sys |
| 8 | +import argparse |
| 9 | +import json |
| 10 | + |
| 11 | +def perform_pre_checks(): |
| 12 | + mock_result_path = os.path.join(os.getcwd(), "mock_result") |
| 13 | + if(os.path.isfile(mock_result_path)): |
| 14 | + with open(mock_result_path, "r", encoding="utf8") as f: |
| 15 | + mock_result = f.read() |
| 16 | + if mock_result[0]: |
| 17 | + sys.stdout.write(mock_result[2:]) |
| 18 | + sys.exit(int(mock_result[0])) |
| 19 | + |
| 20 | +def enumerate(args): |
| 21 | + sys.stdout.write(json.dumps([{"fingerprint": "b3c19bfc", "type": "trezor", "model": "trezor_t"}, {"fingerprint": "00000002"}])) |
| 22 | + |
| 23 | +def getdescriptors(args): |
| 24 | + xpub_pkh = "xpub6CRhJvXV8x2AKWvqi1ZSMFU6cbxzQiYrv3dxSUXCawjMJ1JzpqVsveH4way1yCmJm29KzH1zrVZmVwes4Qo6oXVE1HFn4fdiKrYJngqFFc6" |
| 25 | + xpub_sh = "xpub6CoNoq3Tg4tGSpom2BSwL42gy864KHo3TXkHxLxBbhvCkgmdVXADQmiHbLZhX3Me1cYhRx7s25Lpm4LnT5zu395ANHsXB2QvT9tqJDAibTN" |
| 26 | + xpub_wpkh = "xpub6DUcLgY1DfgDy2RV6q4djwwsLitaoZDumbribqrR8mP78fEtgZa1XEsqT5MWQ7gwLwKsTQPT28XLoVE5A97rDNTwMXjmzPaNijoCApCbWvp" |
| 27 | + |
| 28 | + sys.stdout.write(json.dumps({ |
| 29 | + "receive": [ |
| 30 | + "pkh([b3c19bfc/44'/1'/" + args.account + "']" + xpub_pkh + "/0/*)#h26nxtl9", |
| 31 | + "sh(wpkh([b3c19bfc/49'/1'/" + args.account + "']" + xpub_sh + "/0/*))#32ry02yp", |
| 32 | + "wpkh([b3c19bfc/84'/1'/" + args.account + "']" + xpub_wpkh + "/0/*)#jftn8ppv" |
| 33 | + ], |
| 34 | + "internal": [ |
| 35 | + "pkh([b3c19bfc/44'/1'/" + args.account + "']" + xpub_pkh + "/1/*)#x7ljm70a", |
| 36 | + "sh(wpkh([b3c19bfc/49'/1'/" + args.account + "']" + xpub_sh + "/1/*))#ytdjh437", |
| 37 | + "wpkh([b3c19bfc/84'/1'/" + args.account + "']" + xpub_wpkh + "/1/*)#rawj6535" |
| 38 | + ] |
| 39 | + })) |
| 40 | + |
| 41 | +parser = argparse.ArgumentParser(prog='./invalid_signer.py', description='External invalid signer mock') |
| 42 | +parser.add_argument('--fingerprint') |
| 43 | +parser.add_argument('--chain', default='main') |
| 44 | +parser.add_argument('--stdin', action='store_true') |
| 45 | + |
| 46 | +subparsers = parser.add_subparsers(description='Commands', dest='command') |
| 47 | +subparsers.required = True |
| 48 | + |
| 49 | +parser_enumerate = subparsers.add_parser('enumerate', help='list available signers') |
| 50 | +parser_enumerate.set_defaults(func=enumerate) |
| 51 | + |
| 52 | +parser_getdescriptors = subparsers.add_parser('getdescriptors') |
| 53 | +parser_getdescriptors.set_defaults(func=getdescriptors) |
| 54 | +parser_getdescriptors.add_argument('--account', metavar='account') |
| 55 | + |
| 56 | +if not sys.stdin.isatty(): |
| 57 | + buffer = sys.stdin.read() |
| 58 | + if buffer and buffer.rstrip() != "": |
| 59 | + sys.argv.extend(buffer.rstrip().split(" ")) |
| 60 | + |
| 61 | +args = parser.parse_args() |
| 62 | + |
| 63 | +perform_pre_checks() |
| 64 | + |
| 65 | +args.func(args) |
0 commit comments