32
32
from ..common import (
33
33
AddressType ,
34
34
Chain ,
35
+ BIP388Policy ,
35
36
)
36
37
from .ledger_bitcoin .client import (
37
38
createClient ,
@@ -185,7 +186,11 @@ def get_pubkey_at_path(self, path: str) -> ExtendedKey:
185
186
return ExtendedKey .deserialize (xpub_str )
186
187
187
188
@ledger_exception
188
- def sign_tx (self , psbt : PSBT ) -> PSBT :
189
+ def sign_tx (
190
+ self ,
191
+ psbt : PSBT ,
192
+ bip388_policy : Optional [BIP388Policy ]
193
+ ) -> PSBT :
189
194
"""
190
195
Sign a transaction with a Ledger device. Not all transactions can be signed by a Ledger.
191
196
@@ -198,6 +203,8 @@ def sign_tx(self, psbt: PSBT) -> PSBT:
198
203
For application versions 2.1.x and above:
199
204
200
205
- Only keys derived with standard BIP 44, 49, 84, and 86 derivation paths are supported for single signature addresses.
206
+
207
+ BIP388: for basic descriptors this is optional, but if provided name must be empty
201
208
"""
202
209
master_fp = self .get_master_fingerprint ()
203
210
@@ -264,6 +271,25 @@ def legacy_sign_tx() -> PSBT:
264
271
else :
265
272
continue
266
273
274
+ if bip388_policy is not None :
275
+ policy = WalletPolicy (
276
+ name = bip388_policy .name ,
277
+ descriptor_template = bip388_policy .descriptor_template ,
278
+ keys_info = bip388_policy .keys_info
279
+ )
280
+ if policy .id not in wallets :
281
+ if bip388_policy .hmac is None :
282
+ raise BadArgumentError ("Missing --hmac" )
283
+ wallets [policy .id ] = (
284
+ signing_priority [script_addrtype ],
285
+ script_addrtype ,
286
+ policy ,
287
+ bytes .fromhex (bip388_policy .hmac ),
288
+ )
289
+ continue
290
+
291
+ # No BIP388 policy provided, construct on the fly
292
+
267
293
# Check if P2WSH
268
294
if is_p2wsh (scriptcode ):
269
295
if len (psbt_in .witness_script ) == 0 :
0 commit comments