Recover a public key from a compact signature.
(cls, hash, sig)
| 584 | |
| 585 | @classmethod |
| 586 | def recover_compact(cls, hash, sig): # pylint: disable=redefined-builtin |
| 587 | """Recover a public key from a compact signature.""" |
| 588 | if len(sig) != 65: |
| 589 | raise ValueError("Signature should be 65 characters, not [%d]" % (len(sig), )) |
| 590 | |
| 591 | recid = (sig[0] - 27) & 3 |
| 592 | compressed = (sig[0] - 27) & 4 != 0 |
| 593 | |
| 594 | cec_key = CECKey() |
| 595 | cec_key.set_compressed(compressed) |
| 596 | |
| 597 | sigR = sig[1:33] |
| 598 | sigS = sig[33:65] |
| 599 | |
| 600 | result = cec_key.recover(sigR, sigS, hash, len(hash), recid, 0) |
| 601 | |
| 602 | if result < 1: |
| 603 | return False |
| 604 | |
| 605 | pubkey = cec_key.get_pubkey() |
| 606 | |
| 607 | return CPubKey(pubkey, _cec_key=cec_key) |
| 608 | |
| 609 | @property |
| 610 | def is_valid(self): |
no test coverage detected