MCPcopy Index your code
hub / github.com/jimmysong/programmingbitcoin / der

Method der

code-ch13/ecc.py:554–569  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

552 return 'Signature({:x},{:x})'.format(self.r, self.s)
553
554 def der(self):
555 rbin = self.r.to_bytes(32, byteorder='big')
556 # remove all null bytes at the beginning
557 rbin = rbin.lstrip(b'\x00')
558 # if rbin has a high bit, add a \x00
559 if rbin[0] & 0x80:
560 rbin = b'\x00' + rbin
561 result = bytes([2, len(rbin)]) + rbin # <1>
562 sbin = self.s.to_bytes(32, byteorder='big')
563 # remove all null bytes at the beginning
564 sbin = sbin.lstrip(b'\x00')
565 # if sbin has a high bit, add a \x00
566 if sbin[0] & 0x80:
567 sbin = b'\x00' + sbin
568 result += bytes([2, len(sbin)]) + sbin
569 return bytes([0x30, len(result)]) + result
570
571 @classmethod
572 def parse(cls, signature_bin):

Callers 2

test_derMethod · 0.95
sign_inputMethod · 0.45

Calls

no outgoing calls

Tested by 1

test_derMethod · 0.76