Skip to content

Commit 9cceaf7

Browse files
compat: fix function names
1 parent 8411e81 commit 9cceaf7

File tree

1 file changed

+38
-39
lines changed

1 file changed

+38
-39
lines changed

internal_filesystem/lib/secp256k1_compat.py

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ def new(self, type_str):
1919
elif 'size_t *' in type_str:
2020
return [0]
2121
elif type_str == 'secp256k1_pubkey *':
22-
return bytearray(64) # Placeholder for pubkey
22+
return bytearray(64)
2323
elif type_str == 'secp256k1_ecdsa_signature *':
24-
return bytearray(64) # Placeholder for signature
24+
return bytearray(64)
2525
elif type_str == 'secp256k1_ecdsa_recoverable_signature *':
26-
return bytearray(65) # Placeholder for recoverable signature
26+
return bytearray(65)
2727
elif type_str == 'secp256k1_xonly_pubkey *':
28-
return bytearray(32) # Placeholder for xonly pubkey
28+
return bytearray(32)
2929
elif type_str == 'secp256k1_keypair *':
30-
return bytearray(96) # Placeholder for keypair
30+
return bytearray(96)
3131
raise ValueError(f"Unsupported ffi type: {type_str}")
3232

3333
def buffer(self, obj, size=None):
@@ -57,14 +57,13 @@ def secp256k1_context_create(self, flags):
5757

5858
def secp256k1_ec_seckey_verify(self, ctx, seckey):
5959
try:
60-
return usecp256k1.usecp256k1_ec_seckey_verify(seckey)
61-
except AttributeError:
62-
# Placeholder until usecp256k1 supports this
63-
raise NotImplementedError("secp256k1_ec_seckey_verify not implemented in usecp256k1")
60+
return usecp256k1.ec_seckey_verify(seckey)
61+
except (ValueError, AttributeError):
62+
return 0
6463

6564
def secp256k1_ecdsa_signature_serialize_der(self, ctx, output, outputlen, raw_sig):
6665
try:
67-
result = usecp256k1.usecp256k1_ecdsa_signature_serialize_der(raw_sig)
66+
result = usecp256k1.ecdsa_signature_serialize_der(raw_sig)
6867
if result is None:
6968
return 0
7069
output[:len(result)] = result
@@ -75,7 +74,7 @@ def secp256k1_ecdsa_signature_serialize_der(self, ctx, output, outputlen, raw_si
7574

7675
def secp256k1_ecdsa_signature_parse_der(self, ctx, raw_sig, ser_sig, ser_len):
7776
try:
78-
result = usecp256k1.usecp256k1_ecdsa_signature_parse_der(ser_sig)
77+
result = usecp256k1.ecdsa_signature_parse_der(ser_sig)
7978
if result is None:
8079
return 0
8180
raw_sig[:] = result
@@ -85,7 +84,7 @@ def secp256k1_ecdsa_signature_parse_der(self, ctx, raw_sig, ser_sig, ser_len):
8584

8685
def secp256k1_ecdsa_signature_serialize_compact(self, ctx, output, raw_sig):
8786
try:
88-
result = usecp256k1.usecp256k1_ecdsa_signature_serialize_compact(raw_sig)
87+
result = usecp256k1.ecdsa_signature_serialize_compact(raw_sig)
8988
if result is None:
9089
return 0
9190
output[:64] = result
@@ -95,7 +94,7 @@ def secp256k1_ecdsa_signature_serialize_compact(self, ctx, output, raw_sig):
9594

9695
def secp256k1_ecdsa_signature_parse_compact(self, ctx, raw_sig, ser_sig):
9796
try:
98-
result = usecp256k1.usecp256k1_ecdsa_signature_parse_compact(ser_sig)
97+
result = usecp256k1.ecdsa_signature_parse_compact(ser_sig)
9998
if result is None:
10099
return 0
101100
raw_sig[:] = result
@@ -105,7 +104,7 @@ def secp256k1_ecdsa_signature_parse_compact(self, ctx, raw_sig, ser_sig):
105104

106105
def secp256k1_ecdsa_signature_normalize(self, ctx, sigout, raw_sig):
107106
try:
108-
is_normalized = usecp256k1.usecp256k1_ecdsa_signature_normalize(raw_sig)
107+
is_normalized = usecp256k1.ecdsa_signature_normalize(raw_sig)
109108
if sigout != FFI.NULL:
110109
sigout[:] = is_normalized[1] if is_normalized[1] else raw_sig
111110
return is_normalized[0]
@@ -114,7 +113,7 @@ def secp256k1_ecdsa_signature_normalize(self, ctx, sigout, raw_sig):
114113

115114
def secp256k1_ecdsa_sign(self, ctx, raw_sig, msg32, privkey, nonce_fn, nonce_data):
116115
try:
117-
result = usecp256k1.usecp256k1_ecdsa_sign(msg32, privkey)
116+
result = usecp256k1.ecdsa_sign(msg32, privkey)
118117
if result is None:
119118
return 0
120119
raw_sig[:] = result
@@ -124,13 +123,13 @@ def secp256k1_ecdsa_sign(self, ctx, raw_sig, msg32, privkey, nonce_fn, nonce_dat
124123

125124
def secp256k1_ecdsa_verify(self, ctx, raw_sig, msg32, pubkey):
126125
try:
127-
return usecp256k1.usecp256k1_ecdsa_verify(raw_sig, msg32, pubkey)
126+
return usecp256k1.ecdsa_verify(raw_sig, msg32, pubkey)
128127
except (ValueError, AttributeError):
129128
return 0
130129

131130
def secp256k1_ecdsa_recoverable_signature_serialize_compact(self, ctx, output, recid, recover_sig):
132131
try:
133-
result, rec_id = usecp256k1.usecp256k1_ecdsa_recoverable_signature_serialize_compact(recover_sig)
132+
result, rec_id = usecp256k1.ecdsa_sign_recoverable(recover_sig)
134133
if result is None:
135134
return 0
136135
output[:64] = result
@@ -141,7 +140,7 @@ def secp256k1_ecdsa_recoverable_signature_serialize_compact(self, ctx, output, r
141140

142141
def secp256k1_ecdsa_recoverable_signature_parse_compact(self, ctx, recover_sig, ser_sig, rec_id):
143142
try:
144-
result = usecp256k1.usecp256k1_ecdsa_recoverable_signature_parse_compact(ser_sig, rec_id)
143+
result = usecp256k1.ecdsa_sign_recoverable(ser_sig, rec_id)
145144
if result is None:
146145
return 0
147146
recover_sig[:] = result
@@ -151,7 +150,7 @@ def secp256k1_ecdsa_recoverable_signature_parse_compact(self, ctx, recover_sig,
151150

152151
def secp256k1_ecdsa_recoverable_signature_convert(self, ctx, normal_sig, recover_sig):
153152
try:
154-
result = usecp256k1.usecp256k1_ecdsa_recoverable_signature_convert(recover_sig)
153+
result = usecp256k1.ecdsa_sign_recoverable(recover_sig)
155154
if result is None:
156155
return 0
157156
normal_sig[:] = result
@@ -161,7 +160,7 @@ def secp256k1_ecdsa_recoverable_signature_convert(self, ctx, normal_sig, recover
161160

162161
def secp256k1_ecdsa_sign_recoverable(self, ctx, raw_sig, msg32, privkey, nonce_fn, nonce_data):
163162
try:
164-
result = usecp256k1.usecp256k1_ecdsa_sign_recoverable(msg32, privkey)
163+
result = usecp256k1.ecdsa_sign_recoverable(msg32, privkey)
165164
if result is None:
166165
return 0
167166
raw_sig[:] = result
@@ -171,7 +170,7 @@ def secp256k1_ecdsa_sign_recoverable(self, ctx, raw_sig, msg32, privkey, nonce_f
171170

172171
def secp256k1_ecdsa_recover(self, ctx, pubkey, recover_sig, msg32):
173172
try:
174-
result = usecp256k1.usecp256k1_ecdsa_recover(recover_sig, msg32)
173+
result = usecp256k1.ecdsa_sign_recoverable(recover_sig, msg32)
175174
if result is None:
176175
return 0
177176
pubkey[:] = result
@@ -181,7 +180,7 @@ def secp256k1_ecdsa_recover(self, ctx, pubkey, recover_sig, msg32):
181180

182181
def secp256k1_schnorrsig_sign_custom(self, ctx, sig64, msg, msg_len, keypair, aux_rand32):
183182
try:
184-
result = usecp256k1.usecp256k1_schnorrsig_sign_custom(msg, keypair)
183+
result = usecp256k1.schnorrsig_sign(msg, keypair)
185184
if result is None:
186185
return 0
187186
sig64[:64] = result
@@ -191,13 +190,13 @@ def secp256k1_schnorrsig_sign_custom(self, ctx, sig64, msg, msg_len, keypair, au
191190

192191
def secp256k1_schnorrsig_verify(self, ctx, schnorr_sig, msg, msg_len, xonly_pubkey):
193192
try:
194-
return usecp256k1.usecp256k1_schnorrsig_verify(schnorr_sig, msg, xonly_pubkey)
193+
return usecp256k1.schnorrsig_verify(schnorr_sig, msg, xonly_pubkey)
195194
except (ValueError, AttributeError):
196195
return 0
197196

198197
def secp256k1_tagged_sha256(self, ctx, hash32, tag, tag_len, msg, msg_len):
199198
try:
200-
result = usecp256k1.usecp256k1_tagged_sha256(tag, msg)
199+
result = usecp256k1.tagged_sha256(tag, msg)
201200
if result is None:
202201
return 0
203202
hash32[:32] = result
@@ -207,7 +206,7 @@ def secp256k1_tagged_sha256(self, ctx, hash32, tag, tag_len, msg, msg_len):
207206

208207
def secp256k1_ec_pubkey_serialize(self, ctx, output, outlen, pubkey, flags):
209208
try:
210-
result = usecp256k1.usecp256k1_ec_pubkey_serialize(pubkey, flags)
209+
result = usecp256k1.ec_pubkey_serialize(pubkey, flags)
211210
if result is None:
212211
return 0
213212
output[:outlen[0]] = result
@@ -217,7 +216,7 @@ def secp256k1_ec_pubkey_serialize(self, ctx, output, outlen, pubkey, flags):
217216

218217
def secp256k1_ec_pubkey_parse(self, ctx, pubkey, pubkey_ser, ser_len):
219218
try:
220-
result = usecp256k1.usecp256k1_ec_pubkey_parse(pubkey_ser)
219+
result = usecp256k1.ec_pubkey_parse(pubkey_ser)
221220
if result is None:
222221
return 0
223222
pubkey[:] = result
@@ -227,7 +226,7 @@ def secp256k1_ec_pubkey_parse(self, ctx, pubkey, pubkey_ser, ser_len):
227226

228227
def secp256k1_ec_pubkey_combine(self, ctx, outpub, pubkeys, n_pubkeys):
229228
try:
230-
result = usecp256k1.usecp256k1_ec_pubkey_combine(pubkeys)
229+
result = usecp256k1.ec_pubkey_combine(pubkeys)
231230
if result is None:
232231
return 0
233232
outpub[:] = result
@@ -237,7 +236,7 @@ def secp256k1_ec_pubkey_combine(self, ctx, outpub, pubkeys, n_pubkeys):
237236

238237
def secp256k1_ec_pubkey_tweak_add(self, ctx, pubkey, scalar):
239238
try:
240-
result = usecp256k1.usecp256k1_ec_pubkey_tweak_add(pubkey, scalar)
239+
result = usecp256k1.ec_pubkey_tweak_add(pubkey, scalar)
241240
if result is None:
242241
return 0
243242
pubkey[:] = result
@@ -247,7 +246,7 @@ def secp256k1_ec_pubkey_tweak_add(self, ctx, pubkey, scalar):
247246

248247
def secp256k1_ec_pubkey_tweak_mul(self, ctx, pubkey, scalar):
249248
try:
250-
result = usecp256k1.usecp256k1_ec_pubkey_tweak_mul(pubkey, scalar)
249+
result = usecp256k1.ec_pubkey_tweak_mul(pubkey, scalar)
251250
if result is None:
252251
return 0
253252
pubkey[:] = result
@@ -257,7 +256,7 @@ def secp256k1_ec_pubkey_tweak_mul(self, ctx, pubkey, scalar):
257256

258257
def secp256k1_ec_pubkey_create(self, ctx, pubkey, privkey):
259258
try:
260-
result = usecp256k1.usecp256k1_ec_pubkey_create(privkey)
259+
result = usecp256k1.ec_pubkey_create(privkey)
261260
if result is None:
262261
return 0
263262
pubkey[:] = result
@@ -267,7 +266,7 @@ def secp256k1_ec_pubkey_create(self, ctx, pubkey, privkey):
267266

268267
def secp256k1_xonly_pubkey_from_pubkey(self, ctx, xonly_pubkey, pk_parity, pubkey):
269268
try:
270-
result, parity = usecp256k1.usecp256k1_xonly_pubkey_from_pubkey(pubkey)
269+
result, parity = usecp256k1.xonly_pubkey_from_pubkey(pubkey)
271270
if result is None:
272271
return 0
273272
xonly_pubkey[:] = result
@@ -279,7 +278,7 @@ def secp256k1_xonly_pubkey_from_pubkey(self, ctx, xonly_pubkey, pk_parity, pubke
279278

280279
def secp256k1_ec_privkey_tweak_add(self, ctx, privkey, scalar):
281280
try:
282-
result = usecp256k1.usecp256k1_ec_privkey_tweak_add(privkey, scalar)
281+
result = usecp256k1.ec_privkey_tweak_add(privkey, scalar)
283282
if result is None:
284283
return 0
285284
privkey[:] = result
@@ -289,7 +288,7 @@ def secp256k1_ec_privkey_tweak_add(self, ctx, privkey, scalar):
289288

290289
def secp256k1_ec_privkey_tweak_mul(self, ctx, privkey, scalar):
291290
try:
292-
result = usecp256k1.usecp256k1_ec_privkey_tweak_mul(privkey, scalar)
291+
result = usecp256k1.ec_privkey_tweak_mul(privkey, scalar)
293292
if result is None:
294293
return 0
295294
privkey[:] = result
@@ -299,7 +298,7 @@ def secp256k1_ec_privkey_tweak_mul(self, ctx, privkey, scalar):
299298

300299
def secp256k1_keypair_create(self, ctx, keypair, privkey):
301300
try:
302-
result = usecp256k1.usecp256k1_keypair_create(privkey)
301+
result = usecp256k1.keypair_create(privkey)
303302
if result is None:
304303
return 0
305304
keypair[:] = result
@@ -309,7 +308,7 @@ def secp256k1_keypair_create(self, ctx, keypair, privkey):
309308

310309
def secp256k1_ecdh(self, ctx, output, pubkey, seckey, hashfn=FFI.NULL, hasharg=FFI.NULL):
311310
try:
312-
result = usecp256k1.usecp256k1_ecdh(pubkey, seckey)
311+
result = usecp256k1.ecdh(pubkey, seckey)
313312
if result is None:
314313
return 0
315314
output[:32] = result
@@ -322,10 +321,10 @@ def secp256k1_ecdh(self, ctx, output, pubkey, seckey, hashfn=FFI.NULL, hasharg=F
322321
lib = Lib()
323322

324323
# Feature flags
325-
HAS_RECOVERABLE = hasattr(usecp256k1, 'usecp256k1_ecdsa_sign_recoverable')
326-
HAS_SCHNORR = hasattr(usecp256k1, 'usecp256k1_schnorrsig_sign')
327-
HAS_ECDH = hasattr(usecp256k1, 'usecp256k1_ecdh')
328-
HAS_EXTRAKEYS = hasattr(usecp256k1, 'usecp256k1_keypair_create')
324+
HAS_RECOVERABLE = hasattr(usecp256k1, 'ecdsa_sign_recoverable')
325+
HAS_SCHNORR = hasattr(usecp256k1, 'schnorrsig_sign')
326+
HAS_ECDH = hasattr(usecp256k1, 'ecdh')
327+
HAS_EXTRAKEYS = hasattr(usecp256k1, 'keypair_create')
329328

330329
# Define copy_x for ECDH
331330
def copy_x(output, x32, y32, data):

0 commit comments

Comments
 (0)