From 9cceaf795de8447877b4265e0b36a6ee5bafa039 Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Mon, 19 May 2025 11:28:59 +0200 Subject: [PATCH] compat: fix function names --- internal_filesystem/lib/secp256k1_compat.py | 77 ++++++++++----------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/internal_filesystem/lib/secp256k1_compat.py b/internal_filesystem/lib/secp256k1_compat.py index 2dea30f8..b8da8739 100644 --- a/internal_filesystem/lib/secp256k1_compat.py +++ b/internal_filesystem/lib/secp256k1_compat.py @@ -19,15 +19,15 @@ class FFI: elif 'size_t *' in type_str: return [0] elif type_str == 'secp256k1_pubkey *': - return bytearray(64) # Placeholder for pubkey + return bytearray(64) elif type_str == 'secp256k1_ecdsa_signature *': - return bytearray(64) # Placeholder for signature + return bytearray(64) elif type_str == 'secp256k1_ecdsa_recoverable_signature *': - return bytearray(65) # Placeholder for recoverable signature + return bytearray(65) elif type_str == 'secp256k1_xonly_pubkey *': - return bytearray(32) # Placeholder for xonly pubkey + return bytearray(32) elif type_str == 'secp256k1_keypair *': - return bytearray(96) # Placeholder for keypair + return bytearray(96) raise ValueError(f"Unsupported ffi type: {type_str}") def buffer(self, obj, size=None): @@ -57,14 +57,13 @@ class Lib: def secp256k1_ec_seckey_verify(self, ctx, seckey): try: - return usecp256k1.usecp256k1_ec_seckey_verify(seckey) - except AttributeError: - # Placeholder until usecp256k1 supports this - raise NotImplementedError("secp256k1_ec_seckey_verify not implemented in usecp256k1") + return usecp256k1.ec_seckey_verify(seckey) + except (ValueError, AttributeError): + return 0 def secp256k1_ecdsa_signature_serialize_der(self, ctx, output, outputlen, raw_sig): try: - result = usecp256k1.usecp256k1_ecdsa_signature_serialize_der(raw_sig) + result = usecp256k1.ecdsa_signature_serialize_der(raw_sig) if result is None: return 0 output[:len(result)] = result @@ -75,7 +74,7 @@ class Lib: def secp256k1_ecdsa_signature_parse_der(self, ctx, raw_sig, ser_sig, ser_len): try: - result = usecp256k1.usecp256k1_ecdsa_signature_parse_der(ser_sig) + result = usecp256k1.ecdsa_signature_parse_der(ser_sig) if result is None: return 0 raw_sig[:] = result @@ -85,7 +84,7 @@ class Lib: def secp256k1_ecdsa_signature_serialize_compact(self, ctx, output, raw_sig): try: - result = usecp256k1.usecp256k1_ecdsa_signature_serialize_compact(raw_sig) + result = usecp256k1.ecdsa_signature_serialize_compact(raw_sig) if result is None: return 0 output[:64] = result @@ -95,7 +94,7 @@ class Lib: def secp256k1_ecdsa_signature_parse_compact(self, ctx, raw_sig, ser_sig): try: - result = usecp256k1.usecp256k1_ecdsa_signature_parse_compact(ser_sig) + result = usecp256k1.ecdsa_signature_parse_compact(ser_sig) if result is None: return 0 raw_sig[:] = result @@ -105,7 +104,7 @@ class Lib: def secp256k1_ecdsa_signature_normalize(self, ctx, sigout, raw_sig): try: - is_normalized = usecp256k1.usecp256k1_ecdsa_signature_normalize(raw_sig) + is_normalized = usecp256k1.ecdsa_signature_normalize(raw_sig) if sigout != FFI.NULL: sigout[:] = is_normalized[1] if is_normalized[1] else raw_sig return is_normalized[0] @@ -114,7 +113,7 @@ class Lib: def secp256k1_ecdsa_sign(self, ctx, raw_sig, msg32, privkey, nonce_fn, nonce_data): try: - result = usecp256k1.usecp256k1_ecdsa_sign(msg32, privkey) + result = usecp256k1.ecdsa_sign(msg32, privkey) if result is None: return 0 raw_sig[:] = result @@ -124,13 +123,13 @@ class Lib: def secp256k1_ecdsa_verify(self, ctx, raw_sig, msg32, pubkey): try: - return usecp256k1.usecp256k1_ecdsa_verify(raw_sig, msg32, pubkey) + return usecp256k1.ecdsa_verify(raw_sig, msg32, pubkey) except (ValueError, AttributeError): return 0 def secp256k1_ecdsa_recoverable_signature_serialize_compact(self, ctx, output, recid, recover_sig): try: - result, rec_id = usecp256k1.usecp256k1_ecdsa_recoverable_signature_serialize_compact(recover_sig) + result, rec_id = usecp256k1.ecdsa_sign_recoverable(recover_sig) if result is None: return 0 output[:64] = result @@ -141,7 +140,7 @@ class Lib: def secp256k1_ecdsa_recoverable_signature_parse_compact(self, ctx, recover_sig, ser_sig, rec_id): try: - result = usecp256k1.usecp256k1_ecdsa_recoverable_signature_parse_compact(ser_sig, rec_id) + result = usecp256k1.ecdsa_sign_recoverable(ser_sig, rec_id) if result is None: return 0 recover_sig[:] = result @@ -151,7 +150,7 @@ class Lib: def secp256k1_ecdsa_recoverable_signature_convert(self, ctx, normal_sig, recover_sig): try: - result = usecp256k1.usecp256k1_ecdsa_recoverable_signature_convert(recover_sig) + result = usecp256k1.ecdsa_sign_recoverable(recover_sig) if result is None: return 0 normal_sig[:] = result @@ -161,7 +160,7 @@ class Lib: def secp256k1_ecdsa_sign_recoverable(self, ctx, raw_sig, msg32, privkey, nonce_fn, nonce_data): try: - result = usecp256k1.usecp256k1_ecdsa_sign_recoverable(msg32, privkey) + result = usecp256k1.ecdsa_sign_recoverable(msg32, privkey) if result is None: return 0 raw_sig[:] = result @@ -171,7 +170,7 @@ class Lib: def secp256k1_ecdsa_recover(self, ctx, pubkey, recover_sig, msg32): try: - result = usecp256k1.usecp256k1_ecdsa_recover(recover_sig, msg32) + result = usecp256k1.ecdsa_sign_recoverable(recover_sig, msg32) if result is None: return 0 pubkey[:] = result @@ -181,7 +180,7 @@ class Lib: def secp256k1_schnorrsig_sign_custom(self, ctx, sig64, msg, msg_len, keypair, aux_rand32): try: - result = usecp256k1.usecp256k1_schnorrsig_sign_custom(msg, keypair) + result = usecp256k1.schnorrsig_sign(msg, keypair) if result is None: return 0 sig64[:64] = result @@ -191,13 +190,13 @@ class Lib: def secp256k1_schnorrsig_verify(self, ctx, schnorr_sig, msg, msg_len, xonly_pubkey): try: - return usecp256k1.usecp256k1_schnorrsig_verify(schnorr_sig, msg, xonly_pubkey) + return usecp256k1.schnorrsig_verify(schnorr_sig, msg, xonly_pubkey) except (ValueError, AttributeError): return 0 def secp256k1_tagged_sha256(self, ctx, hash32, tag, tag_len, msg, msg_len): try: - result = usecp256k1.usecp256k1_tagged_sha256(tag, msg) + result = usecp256k1.tagged_sha256(tag, msg) if result is None: return 0 hash32[:32] = result @@ -207,7 +206,7 @@ class Lib: def secp256k1_ec_pubkey_serialize(self, ctx, output, outlen, pubkey, flags): try: - result = usecp256k1.usecp256k1_ec_pubkey_serialize(pubkey, flags) + result = usecp256k1.ec_pubkey_serialize(pubkey, flags) if result is None: return 0 output[:outlen[0]] = result @@ -217,7 +216,7 @@ class Lib: def secp256k1_ec_pubkey_parse(self, ctx, pubkey, pubkey_ser, ser_len): try: - result = usecp256k1.usecp256k1_ec_pubkey_parse(pubkey_ser) + result = usecp256k1.ec_pubkey_parse(pubkey_ser) if result is None: return 0 pubkey[:] = result @@ -227,7 +226,7 @@ class Lib: def secp256k1_ec_pubkey_combine(self, ctx, outpub, pubkeys, n_pubkeys): try: - result = usecp256k1.usecp256k1_ec_pubkey_combine(pubkeys) + result = usecp256k1.ec_pubkey_combine(pubkeys) if result is None: return 0 outpub[:] = result @@ -237,7 +236,7 @@ class Lib: def secp256k1_ec_pubkey_tweak_add(self, ctx, pubkey, scalar): try: - result = usecp256k1.usecp256k1_ec_pubkey_tweak_add(pubkey, scalar) + result = usecp256k1.ec_pubkey_tweak_add(pubkey, scalar) if result is None: return 0 pubkey[:] = result @@ -247,7 +246,7 @@ class Lib: def secp256k1_ec_pubkey_tweak_mul(self, ctx, pubkey, scalar): try: - result = usecp256k1.usecp256k1_ec_pubkey_tweak_mul(pubkey, scalar) + result = usecp256k1.ec_pubkey_tweak_mul(pubkey, scalar) if result is None: return 0 pubkey[:] = result @@ -257,7 +256,7 @@ class Lib: def secp256k1_ec_pubkey_create(self, ctx, pubkey, privkey): try: - result = usecp256k1.usecp256k1_ec_pubkey_create(privkey) + result = usecp256k1.ec_pubkey_create(privkey) if result is None: return 0 pubkey[:] = result @@ -267,7 +266,7 @@ class Lib: def secp256k1_xonly_pubkey_from_pubkey(self, ctx, xonly_pubkey, pk_parity, pubkey): try: - result, parity = usecp256k1.usecp256k1_xonly_pubkey_from_pubkey(pubkey) + result, parity = usecp256k1.xonly_pubkey_from_pubkey(pubkey) if result is None: return 0 xonly_pubkey[:] = result @@ -279,7 +278,7 @@ class Lib: def secp256k1_ec_privkey_tweak_add(self, ctx, privkey, scalar): try: - result = usecp256k1.usecp256k1_ec_privkey_tweak_add(privkey, scalar) + result = usecp256k1.ec_privkey_tweak_add(privkey, scalar) if result is None: return 0 privkey[:] = result @@ -289,7 +288,7 @@ class Lib: def secp256k1_ec_privkey_tweak_mul(self, ctx, privkey, scalar): try: - result = usecp256k1.usecp256k1_ec_privkey_tweak_mul(privkey, scalar) + result = usecp256k1.ec_privkey_tweak_mul(privkey, scalar) if result is None: return 0 privkey[:] = result @@ -299,7 +298,7 @@ class Lib: def secp256k1_keypair_create(self, ctx, keypair, privkey): try: - result = usecp256k1.usecp256k1_keypair_create(privkey) + result = usecp256k1.keypair_create(privkey) if result is None: return 0 keypair[:] = result @@ -309,7 +308,7 @@ class Lib: def secp256k1_ecdh(self, ctx, output, pubkey, seckey, hashfn=FFI.NULL, hasharg=FFI.NULL): try: - result = usecp256k1.usecp256k1_ecdh(pubkey, seckey) + result = usecp256k1.ecdh(pubkey, seckey) if result is None: return 0 output[:32] = result @@ -322,10 +321,10 @@ ffi = FFI() lib = Lib() # Feature flags -HAS_RECOVERABLE = hasattr(usecp256k1, 'usecp256k1_ecdsa_sign_recoverable') -HAS_SCHNORR = hasattr(usecp256k1, 'usecp256k1_schnorrsig_sign') -HAS_ECDH = hasattr(usecp256k1, 'usecp256k1_ecdh') -HAS_EXTRAKEYS = hasattr(usecp256k1, 'usecp256k1_keypair_create') +HAS_RECOVERABLE = hasattr(usecp256k1, 'ecdsa_sign_recoverable') +HAS_SCHNORR = hasattr(usecp256k1, 'schnorrsig_sign') +HAS_ECDH = hasattr(usecp256k1, 'ecdh') +HAS_EXTRAKEYS = hasattr(usecp256k1, 'keypair_create') # Define copy_x for ECDH def copy_x(output, x32, y32, data):