nostril

A C cli tool for creating nostr events
git clone git://jb55.com/nostril
Log | Files | Refs | Submodules | README

commit e8fd862590410e9392279721d243148279c02efa
parent 098f639f4688ddf1337d18a4e9d626d2f43f62fc
Author: William Casarin <jb55@jb55.com>
Date:   Mon,  8 Aug 2022 15:31:38 -0700

embed libsecp256k1 build

don't rely on external deps

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
A.gitmodules | 3+++
MMakefile | 36++++++++++++++++++++++++++++++------
Adeps/secp256k1 | 1+
Mnostril.c | 9++++-----
4 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/.gitmodules b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "deps/secp256k1"] + path = deps/secp256k1 + url = https://github.com/bitcoin-core/secp256k1 diff --git a/Makefile b/Makefile @@ -1,17 +1,40 @@ -CFLAGS = -Wall -Og +CFLAGS = -Wall -Og -Ideps/secp256k1/include OBJS = sha256.o nostril.o aes.o base64.o -HEADERS = hex.h random.h config.h sha256.h +HEADERS = hex.h random.h config.h sha256.h deps/secp256k1/include/secp256k1.h PREFIX ?= /usr/local +ARS = libsecp256k1.a + +SUBMODULES = deps/secp256k1 all: nostril -%.o: %.c config.h +deps/secp256k1/.git: + @devtools/refresh-submodules.sh $(SUBMODULES) + +deps/secp256k1/include/secp256k1.h: deps/secp256k1/.git + +deps/secp256k1/configure: deps/secp256k1/.git + cd deps/secp256k1; \ + ./autogen.sh + +deps/secp256k1/config.log: deps/secp256k1/configure + cd deps/secp256k1; \ + ./configure --disable-shared --enable-module-ecdh --enable-module-schnorrsig --enable-module-extrakeys + +deps/secp256k1/.libs/libsecp256k1.a: deps/secp256k1/config.log + cd deps/secp256k1; \ + make -j libsecp256k1.la + +libsecp256k1.a: deps/secp256k1/.libs/libsecp256k1.a + cp $< $@ + +%.o: %.c $(HEADERS) @echo "cc $<" @$(CC) $(CFLAGS) -c $< -o $@ -nostril: $(HEADERS) $(OBJS) - $(CC) $(CFLAGS) $(OBJS) -lsecp256k1 -o $@ +nostril: $(HEADERS) $(OBJS) $(ARS) + $(CC) $(CFLAGS) $(OBJS) $(ARS) -o $@ install: nostril mkdir -p $(PREFIX)/bin @@ -24,7 +47,8 @@ configurator: configurator.c $(CC) $< -o $@ clean: - rm -f nostril *.o + rm -f nostril *.o *.a + rm -rf deps/secp256k1 tags: fake ctags *.c *.h diff --git a/deps/secp256k1 b/deps/secp256k1 @@ -0,0 +1 @@ +Subproject commit 694ce8fb2d1fd8a3d641d7c33705691d41a2a860 diff --git a/nostril.c b/nostril.c @@ -6,9 +6,9 @@ #include <errno.h> #include <inttypes.h> -#include <secp256k1.h> -#include <secp256k1_ecdh.h> -#include <secp256k1_schnorrsig.h> +#include "secp256k1.h" +#include "secp256k1_ecdh.h" +#include "secp256k1_schnorrsig.h" #include "cursor.h" #include "hex.h" @@ -209,7 +209,7 @@ static int make_sig(secp256k1_context *ctx, struct key *key, return 0; } - return secp256k1_schnorrsig_sign(ctx, sig, id, &key->pair, aux); + return secp256k1_schnorrsig_sign32(ctx, sig, id, &key->pair, aux); } static int create_key(secp256k1_context *ctx, struct key *key) @@ -603,7 +603,6 @@ static int make_encrypted_dm(secp256k1_context *ctx, struct key *key, if (enclen == 0) { fprintf(stderr, "make_encrypted_dm: aes_encrypt failed\n"); free(buf); - free(encbuf); return 0; }