-
Notifications
You must be signed in to change notification settings - Fork 38k
Check descriptors returned by external signers #23628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fanquake
merged 1 commit into
bitcoin:master
from
sstone:external-signer-catch-invalid-scriptors
Dec 10, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2018-2021 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
import os | ||
import sys | ||
import argparse | ||
import json | ||
|
||
def perform_pre_checks(): | ||
mock_result_path = os.path.join(os.getcwd(), "mock_result") | ||
if(os.path.isfile(mock_result_path)): | ||
with open(mock_result_path, "r", encoding="utf8") as f: | ||
mock_result = f.read() | ||
if mock_result[0]: | ||
sys.stdout.write(mock_result[2:]) | ||
sys.exit(int(mock_result[0])) | ||
|
||
def enumerate(args): | ||
sys.stdout.write(json.dumps([{"fingerprint": "b3c19bfc", "type": "trezor", "model": "trezor_t"}, {"fingerprint": "00000002"}])) | ||
|
||
def getdescriptors(args): | ||
xpub_pkh = "xpub6CRhJvXV8x2AKWvqi1ZSMFU6cbxzQiYrv3dxSUXCawjMJ1JzpqVsveH4way1yCmJm29KzH1zrVZmVwes4Qo6oXVE1HFn4fdiKrYJngqFFc6" | ||
xpub_sh = "xpub6CoNoq3Tg4tGSpom2BSwL42gy864KHo3TXkHxLxBbhvCkgmdVXADQmiHbLZhX3Me1cYhRx7s25Lpm4LnT5zu395ANHsXB2QvT9tqJDAibTN" | ||
xpub_wpkh = "xpub6DUcLgY1DfgDy2RV6q4djwwsLitaoZDumbribqrR8mP78fEtgZa1XEsqT5MWQ7gwLwKsTQPT28XLoVE5A97rDNTwMXjmzPaNijoCApCbWvp" | ||
|
||
sys.stdout.write(json.dumps({ | ||
"receive": [ | ||
"pkh([b3c19bfc/44'/1'/" + args.account + "']" + xpub_pkh + "/0/*)#h26nxtl9", | ||
"sh(wpkh([b3c19bfc/49'/1'/" + args.account + "']" + xpub_sh + "/0/*))#32ry02yp", | ||
"wpkh([b3c19bfc/84'/1'/" + args.account + "']" + xpub_wpkh + "/0/*)#jftn8ppv" | ||
], | ||
"internal": [ | ||
"pkh([b3c19bfc/44'/1'/" + args.account + "']" + xpub_pkh + "/1/*)#x7ljm70a", | ||
"sh(wpkh([b3c19bfc/49'/1'/" + args.account + "']" + xpub_sh + "/1/*))#ytdjh437", | ||
"wpkh([b3c19bfc/84'/1'/" + args.account + "']" + xpub_wpkh + "/1/*)#rawj6535" | ||
] | ||
})) | ||
|
||
parser = argparse.ArgumentParser(prog='./invalid_signer.py', description='External invalid signer mock') | ||
parser.add_argument('--fingerprint') | ||
parser.add_argument('--chain', default='main') | ||
parser.add_argument('--stdin', action='store_true') | ||
|
||
subparsers = parser.add_subparsers(description='Commands', dest='command') | ||
subparsers.required = True | ||
|
||
parser_enumerate = subparsers.add_parser('enumerate', help='list available signers') | ||
parser_enumerate.set_defaults(func=enumerate) | ||
|
||
parser_getdescriptors = subparsers.add_parser('getdescriptors') | ||
parser_getdescriptors.set_defaults(func=getdescriptors) | ||
parser_getdescriptors.add_argument('--account', metavar='account') | ||
|
||
if not sys.stdin.isatty(): | ||
buffer = sys.stdin.read() | ||
if buffer and buffer.rstrip() != "": | ||
sys.argv.extend(buffer.rstrip().split(" ")) | ||
|
||
args = parser.parse_args() | ||
|
||
perform_pre_checks() | ||
|
||
args.func(args) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python3 -c "import sys; print(type(sys.stdin))"
reports that this is a TextIOWrapper (even when I pipe something in such that stdin isn't a tty), so that BufferedIOBase.read will be used, which cannot return None. Why notbuffer = sys.stdin.read().rstrip()
, then? Then it wouldn't be necessary to strip it twice. Andif buffer and buffer.rstrip() != ""
could be simplyif buffer
or maybeif buffer != ""
if you prefer to be verbose.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was copied from the original https://github.com/bitcoin/bitcoin/blob/master/test/functional/mocks/signer.py code.