Skip to content

Commit

Permalink
FEAT: Remove support for deprecated SECP256K1 flags (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
MementoRC authored Jan 27, 2024
1 parent dc3cdbd commit d492d2f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 49 deletions.
14 changes: 4 additions & 10 deletions _cffi_build/secp256k1.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,16 @@ typedef int (*secp256k1_nonce_function)(
void *data,
unsigned int attempt
);
#define SECP256K1_FLAGS_TYPE_MASK ...
#define SECP256K1_FLAGS_TYPE_CONTEXT ...
#define SECP256K1_FLAGS_TYPE_COMPRESSION ...
#define SECP256K1_FLAGS_BIT_CONTEXT_VERIFY ...
#define SECP256K1_FLAGS_BIT_CONTEXT_SIGN ...
#define SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY ...
#define SECP256K1_FLAGS_BIT_COMPRESSION ...

#define SECP256K1_CONTEXT_NONE ...
#define SECP256K1_CONTEXT_VERIFY ...
#define SECP256K1_CONTEXT_SIGN ...
#define SECP256K1_CONTEXT_DECLASSIFY ...
#define SECP256K1_EC_COMPRESSED ...
#define SECP256K1_EC_UNCOMPRESSED ...
#define SECP256K1_TAG_PUBKEY_EVEN ...
#define SECP256K1_TAG_PUBKEY_ODD ...
#define SECP256K1_TAG_PUBKEY_UNCOMPRESSED ...
#define SECP256K1_TAG_PUBKEY_HYBRID_EVEN ...
#define SECP256K1_TAG_PUBKEY_HYBRID_ODD ...

extern const secp256k1_context *secp256k1_context_static;
extern void secp256k1_selftest(void);
extern secp256k1_context *secp256k1_context_create(
Expand Down
17 changes: 5 additions & 12 deletions coincurve/_windows_libsecp256k1.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,14 @@
unsigned int attempt
);
#define SECP256K1_FLAGS_TYPE_MASK 255
#define SECP256K1_FLAGS_TYPE_CONTEXT 1
#define SECP256K1_FLAGS_TYPE_COMPRESSION 2
#define SECP256K1_FLAGS_BIT_CONTEXT_VERIFY 256
#define SECP256K1_FLAGS_BIT_CONTEXT_SIGN 512
#define SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY 1024
#define SECP256K1_FLAGS_BIT_COMPRESSION 256
#define SECP256K1_TAG_PUBKEY_EVEN 2
#define SECP256K1_TAG_PUBKEY_ODD 3
#define SECP256K1_TAG_PUBKEY_UNCOMPRESSED 4
#define SECP256K1_CONTEXT_NONE 1
#define SECP256K1_CONTEXT_DECLASSIFY 1025
#define SECP256K1_EC_COMPRESSED 258
#define SECP256K1_EC_UNCOMPRESSED 2
#define SECP256K1_TAG_PUBKEY_EVEN 2
#define SECP256K1_TAG_PUBKEY_ODD 3
#define SECP256K1_TAG_PUBKEY_UNCOMPRESSED 4
#define SECP256K1_TAG_PUBKEY_HYBRID_EVEN 6
#define SECP256K1_TAG_PUBKEY_HYBRID_ODD 7
extern const secp256k1_context *secp256k1_context_static;
extern void secp256k1_selftest(void);
Expand Down
4 changes: 2 additions & 2 deletions coincurve/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from threading import Lock
from typing import Optional

from coincurve.flags import CONTEXT_ALL, CONTEXT_FLAGS
from coincurve.flags import CONTEXT_FLAGS, CONTEXT_NONE

from ._libsecp256k1 import ffi, lib


class Context:
def __init__(self, seed: Optional[bytes] = None, flag=CONTEXT_ALL, name: str = ''):
def __init__(self, seed: Optional[bytes] = None, flag=CONTEXT_NONE, name: str = ''):
if flag not in CONTEXT_FLAGS:
raise ValueError(f'{flag} is an invalid context flag.')
self._lock = Lock()
Expand Down
14 changes: 10 additions & 4 deletions coincurve/flags.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
from ._libsecp256k1 import lib

CONTEXT_SIGN = lib.SECP256K1_CONTEXT_SIGN
CONTEXT_VERIFY = lib.SECP256K1_CONTEXT_VERIFY
CONTEXT_ALL = CONTEXT_SIGN | CONTEXT_VERIFY
CONTEXT_NONE = lib.SECP256K1_CONTEXT_NONE
CONTEXT_FLAGS = {CONTEXT_SIGN, CONTEXT_VERIFY, CONTEXT_ALL, CONTEXT_NONE}
CONTEXT_FLAGS = {
CONTEXT_NONE,
}

EC_COMPRESSED = lib.SECP256K1_EC_COMPRESSED
EC_UNCOMPRESSED = lib.SECP256K1_EC_UNCOMPRESSED

# Additional flags available from libsecp256k1
# lib.SECP256K1_TAG_PUBKEY_EVEN
# lib.SECP256K1_TAG_PUBKEY_ODD
# lib.SECP256K1_TAG_PUBKEY_UNCOMPRESSED
# lib.SECP256K1_TAG_PUBKEY_HYBRID_EVEN
# lib.SECP256K1_TAG_PUBKEY_HYBRID_ODD
21 changes: 0 additions & 21 deletions tests/test_flags.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
from coincurve.flags import (
CONTEXT_ALL,
CONTEXT_FLAGS,
CONTEXT_NONE,
CONTEXT_SIGN,
CONTEXT_VERIFY,
EC_COMPRESSED,
EC_UNCOMPRESSED,
)


def test_context_flags():
expected_flags = {
CONTEXT_SIGN,
CONTEXT_VERIFY,
CONTEXT_ALL,
CONTEXT_NONE,
}
assert CONTEXT_FLAGS == expected_flags
Expand All @@ -24,21 +18,6 @@ def test_context_none():
assert CONTEXT_NONE == (1 << 0)


def test_context_sign():
# From libsecp256k1's include/secp256k1.h
assert CONTEXT_SIGN == ((1 << 0) | (1 << 9))


def test_context_verify():
# From libsecp256k1's include/secp256k1.h
assert CONTEXT_VERIFY == ((1 << 0) | (1 << 8))


def test_context_all():
# From libsecp256k1's include/secp256k1.h
assert CONTEXT_ALL == (CONTEXT_SIGN | CONTEXT_VERIFY)


def test_ec_compressed():
# From libsecp256k1's include/secp256k1.h
assert EC_COMPRESSED == (1 << 1) | (1 << 8)
Expand Down

0 comments on commit d492d2f

Please sign in to comment.