Skip to content

Commit

Permalink
[ADD] Inverse method, allow to inverse public keys
Browse files Browse the repository at this point in the history
  • Loading branch information
mccwdev committed Nov 19, 2023
1 parent 0749ed4 commit da75253
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions bitcoinlib/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,8 +978,7 @@ def __rmul__(self, other):
return self * other

def __neg__(self):
assert self.secret
return HDKey(secp256k1_n - self.secret)
return self.inverse()

def __len__(self):
return len(self.public_byte)
Expand All @@ -1004,6 +1003,13 @@ def __int__(self):
else:
return None

def inverse(self):
if self.is_private:
return HDKey(secp256k1_n - self.secret)
else:
# Inverse y in init: self._y = secp256k1_p - self._y
return Key(('02' if self._y % 2 else '03') + self.x_hex)

@property
def x(self):
if not self._x and self.x_hex:
Expand Down

0 comments on commit da75253

Please sign in to comment.