def from_bytes(cls, data): if len(data) > 33: raise ValueError('data size must not exceed 33 bytes') compressed = (len(data) > 32 and data[32] == 1) self = super(CCoinKey, cls).from_bytes(data) CKeyBase.__init__(self, None, compressed=compressed) return self
def from_secret_bytes(cls, secret, compressed=True): """Create a secret key from a 32-byte secret""" if len(secret) != 32: raise ValueError('secret size must be exactly 32 bytes') self = super(CCoinKey, cls).from_bytes(secret + (b'\x01' if compressed else b'')) CKeyBase.__init__(self, None, compressed=compressed) return self
def SignMessage(key: CKeyBase, message: 'BitcoinMessage') -> bytes: sig, i = key.sign_compact(message.GetHash()) meta = 27 + i if key.is_compressed(): meta += 4 return base64.b64encode(bytes([meta]) + sig)
def __init__(self, _s: str) -> None: data = self if len(data) > 33: raise ValueError('data size must not exceed 33 bytes') compressed = (len(data) > 32 and data[32] == 1) CKeyBase.__init__(self, None, compressed=compressed)
def __init__(self, b): CKeyBase.__init__(self, b, compressed=True)