Skip to content

Commit 612aafc

Browse files
committed
bip44 descriptor test and build.zig
1 parent a299fa0 commit 612aafc

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

build.zig

+22
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ pub fn build(b: *std.Build) void {
3636
.optimize = optimize,
3737
});
3838

39+
// main wallet
40+
const walle = b.addExecutable(.{
41+
.name = "walle",
42+
// In this case the main source file is merely a path, however, in more
43+
// complicated build scripts, this could be a generated file.
44+
.root_source_file = b.path("src/walle.zig"),
45+
.target = target,
46+
.optimize = optimize,
47+
});
48+
3949
const crypto = b.addModule("crypto", .{
4050
.root_source_file = b.path("src/crypto/crypto.zig"),
4151
});
@@ -53,24 +63,33 @@ pub fn build(b: *std.Build) void {
5363
wbx.root_module.addImport("base58", base58_module);
5464
wbx.root_module.addImport("crypto", crypto);
5565

66+
walle.root_module.addImport("base58", base58_module);
67+
walle.root_module.addImport("clap", clap_module);
68+
walle.root_module.addImport("crypto", crypto);
69+
walle.linkLibrary(sqlite.artifact("sqlite"));
70+
walle.root_module.addImport("sqlite", sqlite_module);
71+
5672
// This declares intent for the executable to be installed into the
5773
// standard location when the user invokes the "install" step (the default
5874
// step when running `zig build`).
5975
b.installArtifact(indexer);
6076
b.installArtifact(wbx);
77+
b.installArtifact(walle);
6178

6279
// This *creates* a Run step in the build graph, to be executed when another
6380
// step is evaluated that depends on it. The next line below will establish
6481
// such a dependency.
6582
const run_cmd_indexer = b.addRunArtifact(indexer);
6683
const run_cmd_wbx = b.addRunArtifact(wbx);
84+
const run_cmd_walle = b.addRunArtifact(walle);
6785

6886
// By making the run step depend on the install step, it will be run from the
6987
// installation directory rather than directly from within the cache directory.
7088
// This is not necessary, however, if the application depends on other installed
7189
// files, this ensures they will be present and in the expected location.
7290
run_cmd_indexer.step.dependOn(b.getInstallStep());
7391
run_cmd_wbx.step.dependOn(b.getInstallStep());
92+
run_cmd_walle.step.dependOn(b.getInstallStep());
7493

7594
// This allows the user to pass arguments to the application in the build
7695
// command itself, like this: `zig build run -- arg1 arg2 etc`
@@ -88,6 +107,9 @@ pub fn build(b: *std.Build) void {
88107
const run_step_wbx = b.step("run_wbx", "Run the walle bitcoin explorer");
89108
run_step_wbx.dependOn(&run_cmd_wbx.step);
90109

110+
const run_step_walle = b.step("run_walle", "Run the walle main bitcoin");
111+
run_step_walle.dependOn(&run_cmd_walle.step);
112+
91113
// Similar to creating the run step earlier, this exposes a `test` step to
92114
// the `zig build --help` menu, providing a way for the user to request
93115
// running the unit tests.

src/bip44.zig

+11
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,17 @@ test "generatePrivateAccount" {
201201
try std.testing.expectEqualStrings(expected, &compressed);
202202
}
203203

204+
test "generateDescriptorPrivate" {
205+
const addr_serialized = "xprv9s21ZrQH143K46XPEERBYSrepx6CqH2BDKpP9CzBougQShKQRk1NFXrLH8FzeC5HmLDVm1wmJa8k5Xy8LvcirPkNAF5q5Fav1zmkd8omLnR".*;
206+
const master_extended_privkey = try bip32.ExtendedPrivateKey.fromAddress(addr_serialized);
207+
const extended_privkey = try generateDescriptorPrivate(master_extended_privkey, bip_84_purpose, 1, 0);
208+
const extended_privkey_index = try bip32.deriveChildFromExtendedPrivateKey(extended_privkey, 0);
209+
const public = bip32.generatePublicKey(extended_privkey_index.privatekey);
210+
const compressed = try public.toStrCompressed();
211+
const expected = "02351fc272fab79ebd0386c0308ff7c9b7c171f77c63e979d5f20b38c2a4e93eac";
212+
try std.testing.expectEqualStrings(expected, &compressed);
213+
}
214+
204215
test "keypath" {
205216
const allocator = std.testing.allocator;
206217
const k1 = try KeyPath(5).fromStr("84'/0'/0'/0/1");

0 commit comments

Comments
 (0)