Skip to content

Commit 21bac83

Browse files
committed
Working on output formats.
1 parent f486070 commit 21bac83

27 files changed

+664
-137
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"type": "lldb",
88
"request": "launch",
99
"program": "${workspaceFolder}/src/seedtool",
10-
"args": [],
10+
"args": ["--out","slip39","--group","2-of-3"],
1111
"cwd": "${workspaceFolder}/src",
1212
"preLaunchTask": "Build"
1313
}

src/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ format-cards.o: format-cards.h format.h params.h
6767
format-dice.o: format-dice.h format.h params.h
6868
format-hex.o: format-hex.h format.h params.h
6969
format-ints.o: format-ints.h format.h params.h
70-
format-random.o: format-random.h random.h format.h params.h
70+
format-random.o: format-random.h format.h params.h
7171
format-slip39.o: format-slip39.h format.h params.h
7272

7373
bindir = $(DESTDIR)/$(prefix)/bin

src/format-base10.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,21 @@
77

88
#include "format-base10.h"
99
#include "params.h"
10+
#include "utils.h"
11+
12+
void format_base10_process_output(format* this, params* p) {
13+
p->output = data_to_ints(p->seed, p->seed_len, 0, 9, "");
14+
}
15+
16+
static void format_base10_dispose(format* this) {
17+
free(this);
18+
}
19+
20+
format* format_base10_new() {
21+
format* f = calloc(sizeof(format), 1);
22+
f->key = format_key_base10;
23+
f->name = "base10";
24+
f->process_output = format_base10_process_output;
25+
f->dispose = format_base10_dispose;
26+
return f;
27+
}

src/format-base10.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010

1111
#include "format.h"
1212

13+
format* format_base10_new();
14+
1315
#endif /* FORMAT_BASE10_H */

src/format-base6.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,21 @@
77

88
#include "format-base6.h"
99
#include "params.h"
10+
#include "utils.h"
11+
12+
void format_base6_process_output(format* this, params* p) {
13+
p->output = data_to_ints(p->seed, p->seed_len, 0, 5, "");
14+
}
15+
16+
static void format_base6_dispose(format* this) {
17+
free(this);
18+
}
19+
20+
format* format_base6_new() {
21+
format* f = calloc(sizeof(format), 1);
22+
f->key = format_key_base6;
23+
f->name = "base6";
24+
f->process_output = format_base6_process_output;
25+
f->dispose = format_base6_dispose;
26+
return f;
27+
}

src/format-base6.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010

1111
#include "format.h"
1212

13+
format* format_base6_new();
14+
1315
#endif /* FORMAT_BASE6_H */

src/format-bip39.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,39 @@
66
//
77

88
#include "format-bip39.h"
9+
10+
#include <strings.h>
11+
#include <bc-bip39/bc-bip39.h>
12+
913
#include "params.h"
14+
#include "utils.h"
15+
16+
bool format_bip39_is_seed_length_valid(size_t seed_len) {
17+
if(!(12 <= seed_len && seed_len <= 32)) { return false; }
18+
if(seed_len % 2 != 0) { return false; }
19+
return true;
20+
}
21+
22+
void format_bip39_process_output(format* this, params* p) {
23+
if(!format_bip39_is_seed_length_valid(p->seed_len)) { return; }
24+
25+
size_t max_mnemonics_len = 300;
26+
char mnemonics[max_mnemonics_len];
27+
size_t len = bip39_mnemonics_from_secret(p->seed, p->seed_len, mnemonics, max_mnemonics_len);
28+
char* string = malloc(len);
29+
strcpy(string, mnemonics);
30+
p->output = string;
31+
}
32+
33+
static void format_bip39_dispose(format* this) {
34+
free(this);
35+
}
36+
37+
format* format_bip39_new() {
38+
format* f = calloc(sizeof(format), 1);
39+
f->key = format_key_bip39;
40+
f->name = "bip39";
41+
f->process_output = format_bip39_process_output;
42+
f->dispose = format_bip39_dispose;
43+
return f;
44+
}

src/format-bip39.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,10 @@
1010

1111
#include "format.h"
1212

13+
#include <stdbool.h>
14+
#include <stdlib.h>
15+
16+
format* format_bip39_new();
17+
bool format_bip39_is_seed_length_valid(size_t seed_len);
18+
1319
#endif /* FORMAT_BIP39_H */

src/format-bits.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,25 @@
66
//
77

88
#include "format-bits.h"
9+
10+
#include <strings.h>
11+
912
#include "params.h"
13+
#include "utils.h"
14+
15+
void format_bits_process_output(format* this, params* p) {
16+
p->output = data_to_ints(p->seed, p->seed_len, 0, 1, "");
17+
}
18+
19+
static void format_bits_dispose(format* this) {
20+
free(this);
21+
}
22+
23+
format* format_bits_new() {
24+
format* f = calloc(sizeof(format), 1);
25+
f->key = format_key_bits;
26+
f->name = "bits";
27+
f->process_output = format_bits_process_output;
28+
f->dispose = format_bits_dispose;
29+
return f;
30+
}

src/format-bits.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010

1111
#include "format.h"
1212

13+
format* format_bits_new();
14+
1315
#endif /* FORMAT_BITS_H */

0 commit comments

Comments
 (0)