bitauth / libauth

An ultra-lightweight, zero-dependency TypeScript library for Bitcoin Cash, Bitcoin, and Bitauth applications.

Home Page:https://libauth.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How did you compile libsecp256k1?

ARitz-Cracker opened this issue · comments

  • I'm submitting a ...
    [ ] bug report
    [ ] feature request
    [*] question about the decisions made in the repository
    [*] question about how to use this project

I was trying my hand on exposing a function I needed for a project of mine, I thought rather than submitting an issue about it without knowing if or when it would be implemented, I thought I'd learn something new and add it myself, so I spent a lot of time figuring out how the WASM functions were exposed to JS, which lead me to the compiling commands in secp256k1.Dockerfile.

I've tried running the commands specified in the docker-file, but... I kinda ran into a wall when actually trying compile it:

$ emmake make FORMAT=wasm
  CC       src/libsecp256k1_la-secp256k1.lo
In file included from src/secp256k1.c:9:
./src/util.h:118:37: error: __int128 is not supported on this target
SECP256K1_GNUC_EXT typedef unsigned __int128 uint128_t;
                                    ^
In file included from src/secp256k1.c:11:
In file included from ./src/field_impl.h:19:
In file included from ./src/field_5x52_impl.h:19:
./src/field_5x52_asm_impl.h:281:3: error: invalid output constraint '+S' in asm
: "+S"(a), "=m"(tmp1), "=m"(tmp2), "=m"(tmp3)
  ^
./src/field_5x52_asm_impl.h:496:3: error: invalid output constraint '+S' in asm
: "+S"(a), "=m"(tmp1), "=m"(tmp2), "=m"(tmp3)
  ^
In file included from src/secp256k1.c:12:
In file included from ./src/scalar_impl.h:20:
./src/scalar_4x64_impl.h:379:7: error: invalid input constraint 'S' in asm
    : "S"(l), "n"(SECP256K1_N_C_0), "n"(SECP256K1_N_C_1)
      ^
./src/scalar_4x64_impl.h:459:7: error: unknown register name 'rax' in asm
    : "rax", "rdx", "r8", "r9", "r10", "r11", "r12", "r13", "cc");
      ^
./src/scalar_4x64_impl.h:504:52: error: invalid input constraint 'D' in asm
    : "g"(p0), "g"(p1), "g"(p2), "g"(p3), "g"(p4), "D"(r), "n"(SECP256K1_N_C_0), "n"(SECP256K1_N_C_1)
                                                   ^
./src/scalar_4x64_impl.h:709:7: error: invalid output constraint '+d' in asm
    : "+d"(pb)
      ^
./src/scalar_4x64_impl.h:853:7: error: invalid input constraint 'S' in asm
    : "S"(l), "D"(a->d)
      ^
src/secp256k1.c:29:53: warning: unused parameter 'str' [-Wunused-parameter]
static void default_illegal_callback_fn(const char* str, void* data) {
                                                    ^
src/secp256k1.c:39:51: warning: unused parameter 'str' [-Wunused-parameter]
static void default_error_callback_fn(const char* str, void* data) {
                                                  ^
2 warnings and 8 errors generated.
ERROR    root: compiler frontend failed to generate LLVM bitcode, halting
Makefile:1028: recipe for target 'src/libsecp256k1_la-secp256k1.lo' failed
make: *** [src/libsecp256k1_la-secp256k1.lo] Error 1

Hey @ARitz-Cracker, thanks for opening an issue. I'll add an explanation of the compilation process in the readme.

We do all the compilation in Docker to ensure simple and deterministic builds between different development environments.

You'll need to have Docker installed on your machine, then run the npm script for the WASM you want to compile. For Secp256k1, you'll want to run:

npm run compile:secp256k1

The output should be automatically placed in the right locations. If you're adding to the bindings, you'll also need to modify those to include the new functionality. In your case, you'll need to update bindings in secp256k1Wasm.ts and depending on your changes, seckp256k1.ts (the functional wrapper).

Thank you! I managed to get recoverable signatures to work properly! You've been helpful.