|
40 | 40 | from embit.util import secp256k1
|
41 | 41 | from embit.liquid.finalizer import finalize_psbt
|
42 | 42 | from embit.liquid.transaction import write_commitment
|
| 43 | +from embit.descriptor import Descriptor |
43 | 44 |
|
44 | 45 | # The test emulator port
|
45 | 46 | SIMULATOR_PATH = "tcp:127.0.0.1:30121"
|
@@ -572,6 +573,57 @@ def display_multisig_address(
|
572 | 573 |
|
573 | 574 | return str(address)
|
574 | 575 |
|
| 576 | + # Custom Specter method - register multisig on the Jade |
| 577 | + @jade_exception |
| 578 | + def register_multisig(self, descriptor: str) -> None: |
| 579 | + |
| 580 | + descriptor = Descriptor.from_string(descriptor) |
| 581 | + signer_origins = [] |
| 582 | + signers = [] |
| 583 | + paths = [] |
| 584 | + for key in descriptor.keys: |
| 585 | + # Tuple to derive deterministic name for the registration |
| 586 | + signer_origins.append((key.origin.fingerprint, key.origin.derivation)) |
| 587 | + |
| 588 | + # We won't include the additional path in the multisig registration |
| 589 | + signers.append( |
| 590 | + { |
| 591 | + "fingerprint": key.fingerprint, |
| 592 | + "derivation": key.derivation, |
| 593 | + "xpub": key.key.to_string(), |
| 594 | + "path": [], |
| 595 | + } |
| 596 | + ) |
| 597 | + |
| 598 | + # Get a deterministic name for this multisig wallet (ignoring bip67 key sorting) |
| 599 | + if descriptor.wsh and not descriptor.sh: |
| 600 | + addr_type = AddressType.WIT |
| 601 | + elif descriptor.wsh and descriptor.sh: |
| 602 | + addr_type = AddressType.SH_WIT |
| 603 | + elif descriptor.wsh.is_legacy: |
| 604 | + addr_type = AddressType.LEGACY |
| 605 | + else: |
| 606 | + raise BadArgumentError( |
| 607 | + "The script type of the descriptor does not match any standard type." |
| 608 | + ) |
| 609 | + |
| 610 | + script_variant = self._convertAddrType(addr_type, multisig=True) |
| 611 | + threshold = descriptor.miniscript.args[0].num # hackish ... |
| 612 | + |
| 613 | + multisig_name = self._get_multisig_name( |
| 614 | + script_variant, threshold, signer_origins |
| 615 | + ) |
| 616 | + |
| 617 | + # 're-registering' is a no-op |
| 618 | + self.jade.register_multisig( |
| 619 | + self._network(), |
| 620 | + multisig_name, |
| 621 | + script_variant, |
| 622 | + descriptor.is_sorted, |
| 623 | + threshold, |
| 624 | + signers, |
| 625 | + ) |
| 626 | + |
575 | 627 | # Setup a new device
|
576 | 628 | def setup_device(self, label: str = "", passphrase: str = "") -> bool:
|
577 | 629 | """
|
|
0 commit comments