Skip to content

Commit 518a137

Browse files
committed
feat: upgrade to zig 0.15.2
1 parent b96922b commit 518a137

8 files changed

Lines changed: 69 additions & 68 deletions

File tree

.github/workflows/check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches: [main]
88

99
env:
10-
ZIG_VERSION: 0.14.0-dev.3427+dea72d15d
10+
ZIG_VERSION: 0.15.2
1111

1212
jobs:
1313
build:

build.zig

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
const std = @import("std");
22

33
fn buildSecp256k1(libsecp_c: *std.Build.Dependency, b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) !*std.Build.Step.Compile {
4-
const lib = b.addStaticLibrary(.{
4+
const lib = b.addLibrary(.{
5+
.linkage = .static,
56
.name = "libsecp",
6-
.target = target,
7-
.optimize = optimize,
8-
.root_source_file = b.path("src/secp256k1.zig"),
7+
.root_module = b.createModule(.{
8+
.target = target,
9+
.optimize = optimize,
10+
.root_source_file = b.path("src/secp256k1.zig"),
11+
}),
912
});
1013

1114
lib.addIncludePath(libsecp_c.path(""));
1215
lib.addIncludePath(libsecp_c.path("src"));
1316
lib.addIncludePath(libsecp_c.path("include"));
1417

15-
var flags = std.ArrayList([]const u8).init(b.allocator);
16-
defer flags.deinit();
17-
18-
try flags.appendSlice(&.{"-DENABLE_MODULE_RECOVERY=1"});
19-
try flags.appendSlice(&.{"-DENABLE_MODULE_SCHNORRSIG=1"});
20-
try flags.appendSlice(&.{"-DENABLE_MODULE_ECDH=1"});
21-
try flags.appendSlice(&.{"-DENABLE_MODULE_EXTRAKEYS=1"});
22-
2318
lib.addCSourceFiles(.{
2419
.root = libsecp_c.path(""),
25-
.flags = flags.items,
20+
.flags = &.{
21+
"-DENABLE_MODULE_RECOVERY=1",
22+
"-DENABLE_MODULE_SCHNORRSIG=1",
23+
"-DENABLE_MODULE_ECDH=1",
24+
"-DENABLE_MODULE_EXTRAKEYS=1",
25+
},
2626
.files = &.{
2727
"./src/secp256k1.c",
2828
"./src/precomputed_ecmult.c",
@@ -58,10 +58,7 @@ pub fn build(b: *std.Build) !void {
5858
// set a preferred release mode, allowing the user to decide how to optimize.
5959
const optimize = b.standardOptimizeOption(.{});
6060

61-
const libsecp_c = b.dependency("libsecp256k1", .{
62-
.target = target,
63-
.optimize = optimize,
64-
});
61+
const libsecp_c = b.dependency("libsecp256k1", .{});
6562

6663
// libsecp256k1 static C library.
6764
const libsecp256k1 = try buildSecp256k1(libsecp_c, b, target, optimize);
@@ -80,21 +77,25 @@ pub fn build(b: *std.Build) !void {
8077
// Creates a step for unit testing. This only builds the test executable
8178
// but does not run it.
8279
const lib_unit_tests = b.addTest(.{
83-
.root_source_file = b.path("src/secp256k1.zig"),
84-
.target = target,
80+
.root_module = b.createModule(.{
81+
.root_source_file = b.path("src/secp256k1.zig"),
82+
.target = target,
83+
}),
8584
});
8685
lib_unit_tests.linkLibrary(libsecp256k1);
8786
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
8887

8988
const example_tests = b.addTest(.{
90-
.root_source_file = b.path("src/examples.zig"),
91-
.target = target,
89+
.root_module = b.createModule(.{
90+
.root_source_file = b.path("src/examples.zig"),
91+
.target = target,
92+
}),
9293
});
9394
example_tests.linkLibrary(libsecp256k1);
9495
const run_example_test = b.addRunArtifact(example_tests);
9596

9697
// Similar to creating the run step earlier, this exposes a `test` step to
97-
// the `zig build --help` menu, providing a way for the user to request
98+
// the `` menu, providing a way for the user to request
9899
// running the unit tests.
99100
const test_step = b.step("test", "Run tests");
100101
test_step.dependOn(&run_lib_unit_tests.step);

build.zig.zon

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,10 @@
66
//
77
// It is redundant to include "zig" in this name because it is already
88
// within the Zig package namespace.
9-
.name = "secp256k1",
10-
11-
// This is a [Semantic Version](https://semver.org/).
12-
// In a future version of Zig it will be used for package deduplication.
13-
.version = "0.0.0",
14-
15-
// This field is optional.
16-
// This is currently advisory only; Zig does not yet do anything
17-
// with this value.
18-
//.minimum_zig_version = "0.11.0",
19-
20-
// This field is optional.
21-
// Each dependency must either provide a `url` and `hash`, or a `path`.
22-
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
23-
// Once all dependencies are fetched, `zig build` no longer requires
24-
// internet connectivity.
9+
.name = .secp256k1,
10+
.fingerprint = 0xed75d6d9e762dcbe,
11+
.version = "0.0.3",
12+
.minimum_zig_version = "0.15.2",
2513
.dependencies = .{
2614
.libsecp256k1 = .{
2715
.url = "https://github.com/bitcoin-core/secp256k1/archive/refs/tags/v0.5.1.tar.gz",

src/ecdsa/ecdsa.zig

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
const std = @import("std");
2-
const secp256k1 = @cImport({
3-
@cInclude("secp256k1.h");
4-
@cInclude("secp256k1_recovery.h");
5-
@cInclude("secp256k1_preallocated.h");
6-
@cInclude("secp256k1_schnorrsig.h");
7-
});
82
const secp = @import("../secp256k1.zig");
3+
const secp256k1 = secp.secp256k1;
94

105
const serialized_signature = @import("serialized_signature.zig");
116
pub const SerializedSignature = @import("serialized_signature.zig").SerializedSignature;

src/ecdsa/recovery.zig

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
//! Provides a signing function that allows recovering the public key from the
22
//! signature.
33
//!
4-
const secp256k1 = @cImport({
5-
@cInclude("secp256k1.h");
6-
@cInclude("secp256k1_recovery.h");
7-
@cInclude("secp256k1_preallocated.h");
8-
@cInclude("secp256k1_schnorrsig.h");
9-
});
104
const std = @import("std");
115
const secp = @import("../secp256k1.zig");
6+
const secp256k1 = secp.secp256k1;
127
const constants = @import("../constants.zig");
138

149
const Error = secp.Error;

src/root.zig

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1-
pub usingnamespace @import("secp256k1.zig");
1+
const secp256k1 = @import("secp256k1.zig");
2+
3+
pub const constants = secp256k1.constants;
4+
pub const Error = secp256k1.Error;
5+
pub const ecdsa = secp256k1.ecdsa;
6+
pub const schnorr = secp256k1.schnorr;
7+
pub const Message = secp256k1.Message;
8+
pub const KeyPair = secp256k1.KeyPair;
9+
pub const XOnlyPublicKey = secp256k1.XOnlyPublicKey;
10+
pub const Secp256k1 = secp256k1.Secp256k1;
11+
pub const Scalar = secp256k1.Scalar;
12+
pub const ErrorParseHex = secp256k1.ErrorParseHex;
13+
pub const PublicKey = secp256k1.PublicKey;
14+
pub const SecretKey = secp256k1.SecretKey;

src/schnorr.zig

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@ const std = @import("std");
22
const constants = @import("constants.zig");
33
const crypto = std.crypto;
44

5-
const secp256k1 = @cImport({
6-
@cInclude("secp256k1.h");
7-
@cInclude("secp256k1_recovery.h");
8-
@cInclude("secp256k1_preallocated.h");
9-
@cInclude("secp256k1_schnorrsig.h");
10-
});
5+
const secp_mod = @import("secp256k1.zig");
6+
const secp256k1 = secp_mod.secp256k1;
117

12-
const Error = @import("secp256k1.zig").Error;
13-
const ErrorParseHex = @import("secp256k1.zig").ErrorParseHex;
14-
const Secp256k1 = @import("secp256k1.zig").Secp256k1;
15-
const KeyPair = @import("secp256k1.zig").KeyPair;
16-
const SecretKey = @import("secp256k1.zig").SecretKey;
17-
const XOnlyPublicKey = @import("secp256k1.zig").XOnlyPublicKey;
8+
const Error = secp_mod.Error;
9+
const ErrorParseHex = secp_mod.ErrorParseHex;
10+
const Secp256k1 = secp_mod.Secp256k1;
11+
const KeyPair = secp_mod.KeyPair;
12+
const SecretKey = secp_mod.SecretKey;
13+
const XOnlyPublicKey = secp_mod.XOnlyPublicKey;
1814

1915
pub const Signature = struct {
2016
inner: [constants.schnorr_signature_size]u8,

src/secp256k1.zig

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub const schnorr = struct {
4848
pub const Signature = schnorr_lib.Signature;
4949
};
5050

51-
const secp256k1 = @cImport({
51+
pub const secp256k1 = @cImport({
5252
@cInclude("secp256k1.h");
5353
@cInclude("secp256k1_recovery.h");
5454
@cInclude("secp256k1_preallocated.h");
@@ -181,9 +181,22 @@ pub const Secp256k1 = struct {
181181
secp256k1.secp256k1_context_destroy(self.ctx);
182182
}
183183

184-
pub usingnamespace ecdsa_lib.Secp;
185-
pub usingnamespace schnorr_lib.Secp;
186-
pub usingnamespace recovery_lib.Secp;
184+
// Re-exported from ecdsa_lib.Secp
185+
pub const signEcdsa = ecdsa_lib.Secp.signEcdsa;
186+
pub const signEcdsaWithNoncedata = ecdsa_lib.Secp.signEcdsaWithNoncedata;
187+
pub const signEcdsaGrindR = ecdsa_lib.Secp.signEcdsaGrindR;
188+
pub const signEcdsaLowR = ecdsa_lib.Secp.signEcdsaLowR;
189+
pub const verifyEcdsa = ecdsa_lib.Secp.verifyEcdsa;
190+
191+
// Re-exported from schnorr_lib.Secp
192+
pub const signSchnorrWithAuxRand = schnorr_lib.Secp.signSchnorrWithAuxRand;
193+
pub const verifySchnorr = schnorr_lib.Secp.verifySchnorr;
194+
pub const signSchnorrHelper = schnorr_lib.Secp.signSchnorrHelper;
195+
196+
// Re-exported from recovery_lib.Secp
197+
pub const signEcdsaRecoverable = recovery_lib.Secp.signEcdsaRecoverable;
198+
pub const signEcdsaRecoverableWithNoncedata = recovery_lib.Secp.signEcdsaRecoverableWithNoncedata;
199+
pub const recoverEcdsa = recovery_lib.Secp.recoverEcdsa;
187200

188201
/// Creating new [`Secp256k1`] object, after all u need to call DEINIT
189202
pub fn genNew() @This() {

0 commit comments

Comments
 (0)