Construct a public key from a serialization in compressed or uncompressed format
(self, data)
| 226 | self.valid = False |
| 227 | |
| 228 | def set(self, data): |
| 229 | """Construct a public key from a serialization in compressed or uncompressed format""" |
| 230 | if (len(data) == 65 and data[0] == 0x04): |
| 231 | p = (int.from_bytes(data[1:33], 'big'), int.from_bytes(data[33:65], 'big'), 1) |
| 232 | self.valid = SECP256K1.on_curve(p) |
| 233 | if self.valid: |
| 234 | self.p = p |
| 235 | self.compressed = False |
| 236 | elif (len(data) == 33 and (data[0] == 0x02 or data[0] == 0x03)): |
| 237 | x = int.from_bytes(data[1:33], 'big') |
| 238 | if SECP256K1.is_x_coord(x): |
| 239 | p = SECP256K1.lift_x(x) |
| 240 | # Make the Y coordinate odd if required (lift_x always produces |
| 241 | # a point with an even Y coordinate). |
| 242 | if data[0] & 1: |
| 243 | p = SECP256K1.negate(p) |
| 244 | self.p = p |
| 245 | self.valid = True |
| 246 | self.compressed = True |
| 247 | else: |
| 248 | self.valid = False |
| 249 | else: |
| 250 | self.valid = False |
| 251 | |
| 252 | @property |
| 253 | def is_compressed(self): |
no test coverage detected