3232from ..common import (
3333 AddressType ,
3434 Chain ,
35+ BIP388Policy ,
3536)
3637from .ledger_bitcoin .client import (
3738 createClient ,
@@ -185,7 +186,11 @@ def get_pubkey_at_path(self, path: str) -> ExtendedKey:
185186 return ExtendedKey .deserialize (xpub_str )
186187
187188 @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 :
189194 """
190195 Sign a transaction with a Ledger device. Not all transactions can be signed by a Ledger.
191196
@@ -198,6 +203,8 @@ def sign_tx(self, psbt: PSBT) -> PSBT:
198203 For application versions 2.1.x and above:
199204
200205 - 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
201208 """
202209 master_fp = self .get_master_fingerprint ()
203210
@@ -264,6 +271,25 @@ def legacy_sign_tx() -> PSBT:
264271 else :
265272 continue
266273
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+
267293 # Check if P2WSH
268294 if is_p2wsh (scriptcode ):
269295 if len (psbt_in .witness_script ) == 0 :
0 commit comments