MCPcopy Index your code
hub / github.com/petertodd/python-bitcoinlib / sign

Method sign

bitcoin/core/key.py:333–350  ·  view source on GitHub ↗
(self, hash)

Source from the content-addressed store, hash-verified

331
332
333 def sign(self, hash): # pylint: disable=redefined-builtin
334 if not isinstance(hash, bytes):
335 raise TypeError('Hash must be bytes instance; got %r' % hash.__class__)
336 if len(hash) != 32:
337 raise ValueError('Hash must be exactly 32 bytes long')
338
339 if _libsecp256k1_enable_signing:
340 return self._sign_with_libsecp256k1(hash)
341
342 sig_size0 = ctypes.c_uint32()
343 sig_size0.value = _ssl.ECDSA_size(self.k)
344 mb_sig = ctypes.create_string_buffer(sig_size0.value)
345 result = _ssl.ECDSA_sign(0, hash, len(hash), mb_sig, ctypes.byref(sig_size0), self.k)
346 assert 1 == result
347 if bitcoin.core.script.IsLowDERSignature(mb_sig.raw[:sig_size0.value]):
348 return mb_sig.raw[:sig_size0.value]
349 else:
350 return self.signature_to_low_s(mb_sig.raw[:sig_size0.value])
351
352 def sign_compact(self, hash): # pylint: disable=redefined-builtin
353 if not isinstance(hash, bytes):

Callers 3

test_signMethod · 0.45
testMethod · 0.45

Calls 2

signature_to_low_sMethod · 0.95

Tested by 3

test_signMethod · 0.36
testMethod · 0.36