MCPcopy Create free account
hub / github.com/ElementsProject/elements / set

Method set

test/functional/test_framework/key.py:228–250  ·  view source on GitHub ↗

Construct a public key from a serialization in compressed or uncompressed format

(self, data)

Source from the content-addressed store, hash-verified

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):

Callers 1

run_testMethod · 0.95

Calls 4

on_curveMethod · 0.80
is_x_coordMethod · 0.80
lift_xMethod · 0.80
negateMethod · 0.80

Tested by

no test coverage detected