|
4 | 4 |
|
5 | 5 | from .command_builder import BitcoinCommandBuilder, BitcoinInsType |
6 | 6 | from ...common import Chain |
7 | | -from .client_command import ClientCommandInterpreter |
8 | | -from .client_base import Client, PartialSignature, SignPsbtYieldedObject, TransportClient |
| 7 | +from .client_command import ClientCommandInterpreter, CCMD_YIELD_MUSIG_PARTIALSIGNATURE_TAG, CCMD_YIELD_MUSIG_PUBNONCE_TAG |
| 8 | +from .client_base import Client, MusigPubNonce, MusigPartialSignature, PartialSignature, SignPsbtYieldedObject, TransportClient |
9 | 9 | from .client_legacy import LegacyClient |
10 | 10 | from .errors import UnknownDeviceError |
11 | 11 | from .exception import DeviceException, NotSupportedError |
@@ -52,17 +52,54 @@ def _decode_signpsbt_yielded_value(res: bytes) -> Tuple[int, SignPsbtYieldedObje |
52 | 52 | res_buffer = BytesIO(res) |
53 | 53 | input_index_or_tag = read_varint(res_buffer) |
54 | 54 |
|
55 | | - # values follow an encoding without an explicit tag, where the |
56 | | - # first element is the input index. All the signature types are implemented |
57 | | - # by the PartialSignature type (not to be confused with the musig Partial Signature). |
58 | | - input_index = input_index_or_tag |
| 55 | + if input_index_or_tag == CCMD_YIELD_MUSIG_PUBNONCE_TAG: |
| 56 | + input_index = read_varint(res_buffer) |
| 57 | + pubnonce = res_buffer.read(66) |
| 58 | + participant_pk = res_buffer.read(33) |
| 59 | + aggregate_pubkey = res_buffer.read(33) |
| 60 | + tapleaf_hash = res_buffer.read() |
| 61 | + if len(tapleaf_hash) == 0: |
| 62 | + tapleaf_hash = None |
| 63 | + |
| 64 | + return ( |
| 65 | + input_index, |
| 66 | + MusigPubNonce( |
| 67 | + participant_pubkey=participant_pk, |
| 68 | + aggregate_pubkey=aggregate_pubkey, |
| 69 | + tapleaf_hash=tapleaf_hash, |
| 70 | + pubnonce=pubnonce |
| 71 | + ) |
| 72 | + ) |
| 73 | + elif input_index_or_tag == CCMD_YIELD_MUSIG_PARTIALSIGNATURE_TAG: |
| 74 | + input_index = read_varint(res_buffer) |
| 75 | + partial_signature = res_buffer.read(32) |
| 76 | + participant_pk = res_buffer.read(33) |
| 77 | + aggregate_pubkey = res_buffer.read(33) |
| 78 | + tapleaf_hash = res_buffer.read() |
| 79 | + if len(tapleaf_hash) == 0: |
| 80 | + tapleaf_hash = None |
| 81 | + |
| 82 | + return ( |
| 83 | + input_index, |
| 84 | + MusigPartialSignature( |
| 85 | + participant_pubkey=participant_pk, |
| 86 | + aggregate_pubkey=aggregate_pubkey, |
| 87 | + tapleaf_hash=tapleaf_hash, |
| 88 | + partial_signature=partial_signature |
| 89 | + ) |
| 90 | + ) |
| 91 | + else: |
| 92 | + # other values follow an encoding without an explicit tag, where the |
| 93 | + # first element is the input index. All the signature types are implemented |
| 94 | + # by the PartialSignature type (not to be confused with the musig Partial Signature). |
| 95 | + input_index = input_index_or_tag |
59 | 96 |
|
60 | | - pubkey_augm_len = read_uint(res_buffer, 8) |
61 | | - pubkey_augm = res_buffer.read(pubkey_augm_len) |
| 97 | + pubkey_augm_len = read_uint(res_buffer, 8) |
| 98 | + pubkey_augm = res_buffer.read(pubkey_augm_len) |
62 | 99 |
|
63 | | - signature = res_buffer.read() |
| 100 | + signature = res_buffer.read() |
64 | 101 |
|
65 | | - return((input_index, _make_partial_signature(pubkey_augm, signature))) |
| 102 | + return((input_index, _make_partial_signature(pubkey_augm, signature))) |
66 | 103 |
|
67 | 104 | def read_uint(buf: BytesIO, |
68 | 105 | bit_len: int, |
|
0 commit comments