Skip to content

Commit 048d8a6

Browse files
authored
Merge pull request #9 from wolfmcnally/develop
Modified "Bech32" format to be "BC32"
2 parents b16d264 + b4573a1 commit 048d8a6

File tree

10 files changed

+78
-74
lines changed

10 files changed

+78
-74
lines changed

MANUAL.md

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,25 @@ $ seedtool --in random --out hex
4444
06799f71d16fad08ec5407d32d670147
4545
```
4646

47-
The `bech32` format can be used in place of `hex`. Bech32 is recognizable by the first 5 characters being `seed1`. Unlike hex, where every possible input is a seed, Bech32 includes error detection.
47+
The `bc32` format can be used in place of `hex`. Unlike hex, where every possible input is a seed, BC32 includes error detection.
4848

4949
```
5050
#
51-
# Generate a 16-byte random seed and display it as Bech32.
51+
# Generate a 16-byte random seed and display it as BC32.
5252
#
5353
54-
$ seedtool --out bech32
55-
seed1ee2mukxh95k4tyjv875aka5xwqc59ge0
54+
$ seedtool --out bc32
55+
dvxe0kpsvzxg4cqtnv7xexnafspdgrn6
5656
5757
#
58-
# Convert the Bech32-encoded seed to hex.
58+
# Convert the BC32-encoded seed to hex.
5959
#
6060
61-
$ seedtool --in bech32 seed1ee2mukxh95k4tyjv875aka5xwqc59ge0
62-
ce55be58d72d2d55924c3fa9db768670
61+
$ seedtool --in bc32 dvxe0kpsvzxg4cqtnv7xexnafspdgrn6
62+
6b0d97d830608c8ae00b9b3c6c9a7d4c
6363
```
6464

65-
An output format `--out` and count `--count` may be specified. Count may be in [1-64] and the default `count` is 16. For the `hex` and `bech32` output formats, the count is the number of bytes generated. For other output formats, `count` is the number of "output units" (e.g., bits, cards, die rolls, etc.)
65+
An output format `--out` and count `--count` may be specified. Count may be in [1-64] and the default `count` is 16. For the `hex` and `bc32` output formats, the count is the number of bytes generated. For other output formats, `count` is the number of "output units" (e.g., bits, cards, die rolls, etc.)
6666

6767
```
6868
#
@@ -218,7 +218,7 @@ crucial enlarge ceramic method custody maximum campus earth ordinary twice adequ
218218

219219
When the `--in` option is used, seedtool takes one or more arguments and uses them to construct the seed. If no arguments are given on the command line, it reads input from stdin and uses what it reads to construct the seed. In the examples below, the end of input to stdin is marked by `^D` on its own line.
220220

221-
When the input format is `hex` or `bech32`, the construction is the identity function (passthrough.)
221+
When the input format is `hex` or `bc32`, the construction is the identity function (passthrough.)
222222

223223
```
224224
#
@@ -231,13 +231,13 @@ $ seedtool --in hex
231231
3d1d142cd016cf8a393a1b477891c5e594fb7c9479b175a0db653067d6de0b17
232232
233233
#
234-
# Input a Bech32 seed via stdin, receive the same seed back in hex.
234+
# Input a BC32 seed via stdin, receive the same seed back in hex.
235235
#
236236
237-
$ seedtool --in bech32
238-
seed1gv0pq3wv5733vyzs6de2tjn7vc677gcm
237+
$ seedtool --in bc32
238+
xl4mgzzlhfxs2j0vc0q28e4xzqxx9sdf
239239
^D
240-
431e1045cca7a3161050d372a5ca7e66
240+
37ebb4085fba4d0549ecc3c0a3e6a610
241241
```
242242

243243
For the other input formats, each "unit" of the input (bit, digit, card, etc.) is converted to a byte and placed in an array. The SHA256 is then taken of the resulting array, yielding a deterministic seed. This seed is then used to generate a cryptographic seed of `count` bytes.
@@ -370,7 +370,7 @@ $ seedtool --in cards --count 20 6c2c3hthacts6d4hkhtd2d7c6c3sqs6h
370370
731e0a4c76189b2b55f4c705ccbb0105d3ee72c0
371371
```
372372

373-
`bip39` and `slip39` output formats can be combined with the `random` (default) input format. If the `--count N` option is used with the `hex` or `bech32` input formats, it results in a seed of `N` bytes being generated and used.
373+
`bip39` and `slip39` output formats can be combined with the `random` (default) input format. If the `--count N` option is used with the `hex` or `bc32` input formats, it results in a seed of `N` bytes being generated and used.
374374

375375
```
376376
#
@@ -389,7 +389,7 @@ $ seedtool --in random --out slip39 --count 32
389389
pumps guest academic academic analysis election admit harvest very webcam acquire answer primary viral venture declare have short bucket pickup pistol squeeze script racism western alarm depend depart lilac zero capacity capture warn
390390
```
391391

392-
`bip39` and `slip39` output formats can be combined with the `hex` or `bech32` input formats. The `--count` option is not allowed and the whole hex seed is used. For `bip39` the seed must be 12-32 bytes and even. For `slip39` the seed must be 16-32 bytes and even.
392+
`bip39` and `slip39` output formats can be combined with the `hex` or `bc32` input formats. The `--count` option is not allowed and the whole hex seed is used. For `bip39` the seed must be 12-32 bytes and even. For `slip39` the seed must be 16-32 bytes and even.
393393

394394
```
395395
#
@@ -407,17 +407,17 @@ $ seedtool --in hex --out bip39 8a3796240f6a9606a577c887f2e5c83a
407407
mechanic royal math burst practice addict noise weekend margin now improve invest
408408
409409
#
410-
# Convert the seed above to Bech32.
410+
# Convert the seed above to BC32.
411411
#
412412
413-
$ seedtool --in hex --out bech32 8a3796240f6a9606a577c887f2e5c83a
414-
seed13gmevfq0d2tqdfthezrl9ewg8g4fq0wc
413+
$ seedtool --in hex --out bc32 8a3796240f6a9606a577c887f2e5c83a
414+
3gmevfq0d2tqdfthezrl9ewg8gk9vsp3
415415
416416
#
417-
# Display the Bech32-encoded seed as BIP39.
417+
# Display the BC32-encoded seed as BIP39.
418418
#
419419
420-
$ seedtool --in bech32 --out bip39 seed13gmevfq0d2tqdfthezrl9ewg8g4fq0wc
420+
$ seedtool --in bc32 --out bip39 3gmevfq0d2tqdfthezrl9ewg8gk9vsp3
421421
mechanic royal math burst practice addict noise weekend margin now improve invest
422422
423423
#
@@ -428,8 +428,8 @@ mechanic royal math burst practice addict noise weekend margin now improve inves
428428
$ seedtool --count 12 --in hex --out bip39 8a3796240f6a9606a577c887f2e5c83a
429429
seedtool: The --count option is not available for hex input.
430430
431-
$ seedtool --count 5 --in bech32 seed1gv0pq3wv5733vyzs6de2tjn7vc677gcm
432-
seedtool: The --count option is not available for bech32 input.
431+
$ seedtool --count 5 --in bc32 6qla75j339vluqwzrhnvr6knngsd37tq
432+
seedtool: The --count option is not available for bc32 input.
433433
434434
#
435435
# The seed you provide must conform to the output format constraints.
@@ -470,13 +470,13 @@ mechanic royal math burst practice addict noise weekend margin now improve inves
470470
471471
#
472472
# Recover from the same BIP39 mnemonic sequence, providing all
473-
# the words via stdin, and displaying the result as Bech32.
473+
# the words via stdin, and displaying the result as BC32.
474474
#
475475
476-
$ seedtool --in bip39 --out bech32
476+
$ seedtool --in bip39 --out bc32
477477
mechanic royal math burst practice addict noise weekend margin now improve invest
478478
^D
479-
seed13gmevfq0d2tqdfthezrl9ewg8g4fq0wc
479+
3gmevfq0d2tqdfthezrl9ewg8gk9vsp3
480480
```
481481

482482
`slip39` can be used as an input format, in which case the original seed is recovered. The SLIP39 shares may be passed on the command line or entered via stdin. If passed on the command line, the shares must each be a single argument (i.e., quoted). If passed via stdin, each share must appear by itself on one line.
@@ -678,6 +678,10 @@ mirror reject rookie talk pudding throw happy era myth already payment owner
678678

679679
## Version History
680680

681+
### 0.3.0, 5/1/2020
682+
683+
* Modified "Bech32" format to be "BC32", including dropping "seed" HRP and '1' divider.
684+
681685
### 0.2.0, 4/22/2020
682686

683687
* Added "bech32" input and output formats.

configure

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /bin/sh
22
# Guess values for system-dependent variables and create Makefiles.
3-
# Generated by GNU Autoconf 2.69 for bc-seedtool-cli 0.2.0.
3+
# Generated by GNU Autoconf 2.69 for bc-seedtool-cli 0.3.0.
44
#
55
#
66
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
@@ -577,8 +577,8 @@ MAKEFLAGS=
577577
# Identity of this package.
578578
PACKAGE_NAME='bc-seedtool-cli'
579579
PACKAGE_TARNAME='bc-seedtool-cli'
580-
PACKAGE_VERSION='0.2.0'
581-
PACKAGE_STRING='bc-seedtool-cli 0.2.0'
580+
PACKAGE_VERSION='0.3.0'
581+
PACKAGE_STRING='bc-seedtool-cli 0.3.0'
582582
PACKAGE_BUGREPORT=''
583583
PACKAGE_URL=''
584584

@@ -1231,7 +1231,7 @@ if test "$ac_init_help" = "long"; then
12311231
# Omit some internal or obsolete options to make the list less imposing.
12321232
# This message is too long to be a string in the A/UX 3.1 sh.
12331233
cat <<_ACEOF
1234-
\`configure' configures bc-seedtool-cli 0.2.0 to adapt to many kinds of systems.
1234+
\`configure' configures bc-seedtool-cli 0.3.0 to adapt to many kinds of systems.
12351235
12361236
Usage: $0 [OPTION]... [VAR=VALUE]...
12371237
@@ -1292,7 +1292,7 @@ fi
12921292

12931293
if test -n "$ac_init_help"; then
12941294
case $ac_init_help in
1295-
short | recursive ) echo "Configuration of bc-seedtool-cli 0.2.0:";;
1295+
short | recursive ) echo "Configuration of bc-seedtool-cli 0.3.0:";;
12961296
esac
12971297
cat <<\_ACEOF
12981298
@@ -1374,7 +1374,7 @@ fi
13741374
test -n "$ac_init_help" && exit $ac_status
13751375
if $ac_init_version; then
13761376
cat <<\_ACEOF
1377-
bc-seedtool-cli configure 0.2.0
1377+
bc-seedtool-cli configure 0.3.0
13781378
generated by GNU Autoconf 2.69
13791379
13801380
Copyright (C) 2012 Free Software Foundation, Inc.
@@ -1885,7 +1885,7 @@ cat >config.log <<_ACEOF
18851885
This file contains any messages produced by compilers while
18861886
running configure, to aid debugging if configure makes a mistake.
18871887
1888-
It was created by bc-seedtool-cli $as_me 0.2.0, which was
1888+
It was created by bc-seedtool-cli $as_me 0.3.0, which was
18891889
generated by GNU Autoconf 2.69. Invocation command line was
18901890
18911891
$ $0 $@
@@ -3609,9 +3609,9 @@ else
36093609

36103610
fi
36113611

3612-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for bech32_seed_encode in -lbc-bech32" >&5
3613-
$as_echo_n "checking for bech32_seed_encode in -lbc-bech32... " >&6; }
3614-
if ${ac_cv_lib_bc_bech32_bech32_seed_encode+:} false; then :
3612+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for bc32_seed_encode in -lbc-bech32" >&5
3613+
$as_echo_n "checking for bc32_seed_encode in -lbc-bech32... " >&6; }
3614+
if ${ac_cv_lib_bc_bech32_bc32_seed_encode+:} false; then :
36153615
$as_echo_n "(cached) " >&6
36163616
else
36173617
ac_check_lib_save_LIBS=$LIBS
@@ -3625,27 +3625,27 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
36253625
#ifdef __cplusplus
36263626
extern "C"
36273627
#endif
3628-
char bech32_seed_encode ();
3628+
char bc32_seed_encode ();
36293629
int
36303630
main ()
36313631
{
3632-
return bech32_seed_encode ();
3632+
return bc32_seed_encode ();
36333633
;
36343634
return 0;
36353635
}
36363636
_ACEOF
36373637
if ac_fn_c_try_link "$LINENO"; then :
3638-
ac_cv_lib_bc_bech32_bech32_seed_encode=yes
3638+
ac_cv_lib_bc_bech32_bc32_seed_encode=yes
36393639
else
3640-
ac_cv_lib_bc_bech32_bech32_seed_encode=no
3640+
ac_cv_lib_bc_bech32_bc32_seed_encode=no
36413641
fi
36423642
rm -f core conftest.err conftest.$ac_objext \
36433643
conftest$ac_exeext conftest.$ac_ext
36443644
LIBS=$ac_check_lib_save_LIBS
36453645
fi
3646-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bc_bech32_bech32_seed_encode" >&5
3647-
$as_echo "$ac_cv_lib_bc_bech32_bech32_seed_encode" >&6; }
3648-
if test "x$ac_cv_lib_bc_bech32_bech32_seed_encode" = xyes; then :
3646+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bc_bech32_bc32_seed_encode" >&5
3647+
$as_echo "$ac_cv_lib_bc_bech32_bc32_seed_encode" >&6; }
3648+
if test "x$ac_cv_lib_bc_bech32_bc32_seed_encode" = xyes; then :
36493649
cat >>confdefs.h <<_ACEOF
36503650
#define HAVE_LIBBC_BECH32 1
36513651
_ACEOF
@@ -4918,7 +4918,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
49184918
# report actual input values of CONFIG_FILES etc. instead of their
49194919
# values after options handling.
49204920
ac_log="
4921-
This file was extended by bc-seedtool-cli $as_me 0.2.0, which was
4921+
This file was extended by bc-seedtool-cli $as_me 0.3.0, which was
49224922
generated by GNU Autoconf 2.69. Invocation command line was
49234923
49244924
CONFIG_FILES = $CONFIG_FILES
@@ -4980,7 +4980,7 @@ _ACEOF
49804980
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
49814981
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
49824982
ac_cs_version="\\
4983-
bc-seedtool-cli config.status 0.2.0
4983+
bc-seedtool-cli config.status 0.3.0
49844984
configured by $0, generated by GNU Autoconf 2.69,
49854985
with options \\"\$ac_cs_config\\"
49864986

configure.ac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Process this file with autoconf to produce a configure script.
33

44
AC_PREREQ([2.69])
5-
AC_INIT([bc-seedtool-cli], [0.2.0])
5+
AC_INIT([bc-seedtool-cli], [0.3.0])
66
AC_CONFIG_SRCDIR([src/seedtool.cpp])
77
AC_CONFIG_HEADERS([src/config.h])
88

@@ -28,7 +28,7 @@ AC_CHECK_LIB([bc-bip39], [bip39_mnemonic_from_word], [], [
2828
echo "### Error! libbc-bip39 must be installed first."
2929
exit -1
3030
])
31-
AC_CHECK_LIB([bc-bech32], [bech32_seed_encode], [], [
31+
AC_CHECK_LIB([bc-bech32], [bc32_seed_encode], [], [
3232
echo "### Error! libbc-bech32 must be installed first."
3333
exit -1
3434
])

src/Makefile.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ OBJS = \
5151
format-ints.o \
5252
format-random.o \
5353
format-slip39.o \
54-
format-bech32.o \
54+
format-bc32.o \
5555
randombytes.o \
5656
hkdf.o
5757

@@ -66,7 +66,7 @@ random.o: random.hpp randombytes.h hkdf.h utils.hpp
6666
randombytes.o: randombytes.h
6767
hkdf.o: hkdf.h
6868
format.o: format.hpp utils.hpp
69-
formats-all.hpp: format-base6.hpp format-base10.hpp format-bip39.hpp format-bits.hpp format-cards.hpp format-dice.hpp format-hex.hpp format-ints.hpp format-random.hpp format-slip39.hpp format-bech32.hpp
69+
formats-all.hpp: format-base6.hpp format-base10.hpp format-bip39.hpp format-bits.hpp format-cards.hpp format-dice.hpp format-hex.hpp format-ints.hpp format-random.hpp format-slip39.hpp format-bc32.hpp
7070
format-base6.o: format-base6.hpp format.hpp params.hpp random.hpp
7171
format-base10.o: format-base10.hpp format.hpp params.hpp random.hpp
7272
format-bip39.o: format-bip39.hpp format.hpp params.hpp random.hpp
@@ -77,7 +77,7 @@ format-hex.o: format-hex.hpp format.hpp params.hpp random.hpp
7777
format-ints.o: format-ints.hpp format.hpp params.hpp random.hpp
7878
format-random.o: format-random.hpp format.hpp params.hpp random.hpp
7979
format-slip39.o: format-slip39.hpp format.hpp params.hpp random.hpp
80-
format-bech32.o: format-bech32.hpp format.hpp params.hpp random.hpp
80+
format-bc32.o: format-bc32.hpp format.hpp params.hpp random.hpp
8181

8282
bindir = $(DESTDIR)/$(prefix)/bin
8383

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//
2-
// format-bech32.cpp
2+
// format-bc32.cpp
33
//
44
// Copyright © 2020 by Blockchain Commons, LLC
55
// Licensed under the "BSD-2-Clause Plus Patent License"
66
//
77

8-
#include "format-bech32.hpp"
8+
#include "format-bc32.hpp"
99

1010
#include <stdexcept>
1111
#include <bc-bech32/bc-bech32.h>
@@ -14,29 +14,29 @@
1414

1515
using namespace std;
1616

17-
bool FormatBech32::is_seed_length_valid(size_t seed_len) {
17+
bool FormatBC32::is_seed_length_valid(size_t seed_len) {
1818
if(!(1 <= seed_len && seed_len <= 64)) { return false; }
1919
return true;
2020
}
2121

22-
void FormatBech32::process_input(Params* p) {
22+
void FormatBC32::process_input(Params* p) {
2323
auto input = p->get_one_argument();
2424
vector<uint8_t> seed;
2525
seed.resize(300);
2626
size_t seed_len = 0;
27-
if(bech32_seed_decode(&seed[0], &seed_len, input.c_str()) == 0) {
28-
throw runtime_error("Invalid bech32 seed.");
27+
if(bc32_seed_decode(&seed[0], &seed_len, input.c_str()) == 0) {
28+
throw runtime_error("Invalid BC32 seed.");
2929
}
3030
seed.resize(seed_len);
3131
p->seed = seed;
3232
}
3333

34-
void FormatBech32::process_output(Params* p) {
34+
void FormatBC32::process_output(Params* p) {
3535
auto data_len = p->seed.size();
3636
char output[200];
3737
auto data = &p->seed[0];
38-
if(bech32_seed_encode(output, data, data_len) == 0) {
39-
throw runtime_error("Bech32 seed encoding failed.");
38+
if(bc32_seed_encode(output, data, data_len) == 0) {
39+
throw runtime_error("BC32 seed encoding failed.");
4040
}
4141
p->output = output;
4242
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// format-bech32.hpp
2+
// format-bch32.hpp
33
//
44
// Copyright © 2020 by Blockchain Commons, LLC
55
// Licensed under the "BSD-2-Clause Plus Patent License"
@@ -9,9 +9,9 @@
99

1010
#include "format.hpp"
1111

12-
class FormatBech32 : public Format {
12+
class FormatBC32 : public Format {
1313
public:
14-
FormatBech32() : Format(Format::Key::bech32, "bech32") {}
14+
FormatBC32() : Format(Format::Key::bc32, "bc32") {}
1515

1616
virtual void process_input(Params* p) override;
1717
virtual void process_output(Params* p) override;

src/format.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static const std::vector<std::string> format_key_names = {
2424
"ints",
2525
"bip39",
2626
"slip39",
27-
"bech32"
27+
"bc32"
2828
};
2929

3030
Format::Key Format::key_for_string(const std::string &arg) {

src/format.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Format {
2525
ints,
2626
bip39,
2727
slip39,
28-
bech32
28+
bc32
2929
};
3030

3131
Format(Key key, const std::string &name) : key(key), name(name) {}

0 commit comments

Comments
 (0)