Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lnaddr.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ def __str__(self):
)

def lndecode(a, verbose=False):
# When calling secp256k1:
# Uses ALL_FLAGS if available.
# Falls back to FLAG_VERIFY if ALL_FLAGS is missing.
# Falls back to no flags (safe default) if neither constant exists.
flags = None
if hasattr(secp256k1, "ALL_FLAGS"):
flags = secp256k1.ALL_FLAGS
elif hasattr(secp256k1, "FLAG_VERIFY"):
flags = secp256k1.FLAG_VERIFY

hrp, data = bech32_decode(a)
if not hrp:
raise ValueError("Bad bech32 checksum")
Expand Down Expand Up @@ -345,7 +355,7 @@ def lndecode(a, verbose=False):
if data_length != 53:
addr.unknown_tags.append((tag, tagdata))
continue
addr.pubkey = secp256k1.PublicKey(flags=secp256k1.ALL_FLAGS)
addr.pubkey = secp256k1.PublicKey(flags)
addr.pubkey.deserialize(trim_to_bytes(tagdata))
else:
addr.unknown_tags.append((tag, tagdata))
Expand All @@ -372,7 +382,7 @@ def lndecode(a, verbose=False):
if not addr.pubkey.ecdsa_verify(bytearray([ord(c) for c in hrp]) + data.tobytes(), addr.signature):
raise ValueError('Invalid signature')
else: # Recover pubkey from signature.
addr.pubkey = secp256k1.PublicKey(flags=secp256k1.ALL_FLAGS)
addr.pubkey = secp256k1.PublicKey(flags)
addr.signature = addr.pubkey.ecdsa_recoverable_deserialize(
sigdecoded[0:64], sigdecoded[64])
addr.pubkey.public_key = addr.pubkey.ecdsa_recover(
Expand Down