MCPcopy
hub / github.com/petertodd/python-bitcoinlib / recover_compact

Method recover_compact

bitcoin/core/key.py:586–607  ·  view source on GitHub ↗

Recover a public key from a compact signature.

(cls, hash, sig)

Source from the content-addressed store, hash-verified

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):

Callers 1

VerifyMessageFunction · 0.80

Calls 5

set_compressedMethod · 0.95
recoverMethod · 0.95
get_pubkeyMethod · 0.95
CECKeyClass · 0.85
CPubKeyClass · 0.85

Tested by

no test coverage detected