def getNUMS(index=0): """Taking secp256k1's G as a seed, either in compressed or uncompressed form, append "index" as a byte, and append a second byte "counter" try to create a new NUMS base point from the sha256 of that bytestring. Loop counter and alternate compressed/uncompressed until finding a valid curve point. The first such point is considered as "the" NUMS base point alternative for this index value. The search process is of course deterministic/repeatable, so it's fine to just store a list of all the correct values for each index, but for transparency left in code for initialization by any user. The NUMS generator generated is returned as a secp256k1.PublicKey. """ assert index in range(256) nums_point = None for G in [getG(True), getG(False)]: seed = G + struct.pack(b'B', index) for counter in range(256): seed_c = seed + struct.pack(b'B', counter) hashed_seed = hashlib.sha256(seed_c).digest() #Every x-coord on the curve has two y-values, encoded #in compressed form with 02/03 parity byte. We just #choose the former. claimed_point = b"\x02" + hashed_seed try: nums_point = podle_PublicKey(claimed_point) return nums_point except: continue assert False, "It seems inconceivable, doesn't it?" # pragma: no cover
def __init__(self, u=None, priv=None, P=None, P2=None, s=None, e=None, used=False): #This class allows storing of utxo in format "txid:n" only for #convenience of storage/access; it doesn't check or use the data. #Arguments must be provided in hex. self.u = u if not priv: if P: #Construct a pubkey from raw hex self.P = podle_PublicKey(binascii.unhexlify(P)) else: self.P = None else: if P: raise PoDLEError("Pubkey should not be provided with privkey") #any other formatting abnormality will just throw in PrivateKey if len(priv) == 66 and priv[-2:] == '01': priv = priv[:-2] self.priv = podle_PrivateKey(binascii.unhexlify(priv)) self.P = self.priv.public_key if P2: self.P2 = podle_PublicKey(binascii.unhexlify(P2)) else: self.P2 = None #These sig values should be passed in hex. self.s = None self.e = None if s: self.s = binascii.unhexlify(s) if e: self.e = binascii.unhexlify(e) #Optionally maintain usage state (boolean) self.used = used #the H(P2) value self.commitment = None
def __init__(self, u=None, priv=None, P=None, P2=None, s=None, e=None, used=False): #This class allows storing of utxo in format "txid:n" only for #convenience of storage/access; it doesn't check or use the data. #Arguments must be provided in binary not hex. self.u = u if not priv: if P: self.P = podle_PublicKey(P) else: self.P = None else: if P: raise PoDLEError("Pubkey should not be provided with privkey") #any other formatting abnormality will just throw in PrivateKey if len(priv) == 33 and priv[-1:] == b"\x01": priv = priv[:-1] self.priv = podle_PrivateKey(priv) self.P = self.priv.pub if P2: self.P2 = podle_PublicKey(P2) else: self.P2 = None self.s = None self.e = None if s: self.s = s if e: self.e = e #Optionally maintain usage state (boolean) self.used = used #the H(P2) value self.commitment = None