add prebuilt libsecp binaries

This commit is contained in:
Stepan Snigirev 2021-01-18 18:02:40 +01:00
parent e1e61ded60
commit 0b396c3ad6
7 changed files with 24 additions and 5 deletions

3
.gitignore vendored
View File

@ -3,9 +3,6 @@ __pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/

View File

@ -11,6 +11,7 @@ setup(
author_email = 'snigirev.stepan@gmail.com',
packages=find_namespace_packages("src", include=["*"]),
package_dir={"": "src"},
package_data={"embit": ["util/prebuilt/*"]},
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",

View File

@ -16,12 +16,33 @@ CONTEXT_NONE = 0b0000000001
EC_COMPRESSED = 0b0100000010
EC_UNCOMPRESSED = 0b0000000010
def _init(flags = (CONTEXT_SIGN | CONTEXT_VERIFY)):
library_path = ctypes.util.find_library('libsecp256k1')
def _find_library():
library_path = None
extension = ""
if platform.system() == "Darwin":
extension = ".dylib"
elif platform.system() == "Linux":
extension = ".so"
elif platform.system() == "Windows":
extension = ".dll"
path = os.path.join(os.path.dirname(__file__),
"prebuilt/libsecp256k1_%s_%s%s" % (platform.system().lower(), platform.machine().lower(), extension))
if os.path.isfile(path):
return path
# try searching
if not library_path:
library_path = ctypes.util.find_library('libsecp256k1')
# library search failed
if not library_path:
if platform.system() == "Linux" and os.path.isfile("/usr/local/lib/libsecp256k1.so.0"):
library_path = "/usr/local/lib/libsecp256k1.so.0"
return library_path
def _init(flags = (CONTEXT_SIGN | CONTEXT_VERIFY)):
library_path = _find_library()
print(library_path)
# meh, can't find library
if not library_path:
raise RuntimeError("Can't find libsecp256k1 library. Make sure to compile and install it.")

Binary file not shown.

Binary file not shown.

Binary file not shown.