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

Method sec

code-ch08/ecc.py:405–418  ·  view source on GitHub ↗

returns the binary version of the SEC format

(self, compressed=True)

Source from the content-addressed store, hash-verified

403 return total.x.num == sig.r
404
405 def sec(self, compressed=True):
406 '''returns the binary version of the SEC format'''
407 # if compressed, starts with b'\x02' if self.y.num is even, b'\x03' if self.y is odd
408 # then self.x.num
409 # remember, you have to convert self.x.num/self.y.num to binary (some_integer.to_bytes(32, 'big'))
410 if compressed:
411 if self.y.num % 2 == 0:
412 return b'\x02' + self.x.num.to_bytes(32, 'big')
413 else:
414 return b'\x03' + self.x.num.to_bytes(32, 'big')
415 else:
416 # if non-compressed, starts with b'\x04' followod by self.x and then self.y
417 return b'\x04' + self.x.num.to_bytes(32, 'big') + \
418 self.y.num.to_bytes(32, 'big')
419
420 def hash160(self, compressed=True):
421 return hash160(self.sec(compressed))

Callers 3

hash160Method · 0.95
sign_inputMethod · 0.45
test_secMethod · 0.45

Calls

no outgoing calls

Tested by 1

test_secMethod · 0.36