Skip to content

Commit 59777ef

Browse files
apoelstraroconnor-blockstream
authored andcommitted
codex32: provide user-readable error types
1 parent 139e8c1 commit 59777ef

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/codex32.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,26 @@ uint8_t lagrange_coefficient(std::vector<uint8_t>& indices, uint8_t idx, uint8_t
220220

221221
} // namespace
222222

223+
std::string ErrorString(Error e) {
224+
switch (e) {
225+
case OK: return "ok";
226+
case BAD_CHECKSUM: return "bad checksum";
227+
case BECH32_DECODE: return "bech32 decode failure (invalid character, no HRP, or inconsistent case)";
228+
case INVALID_HRP: return "hrp differed from 'ms'";
229+
case INVALID_ID_LEN: return "seed ID was not 4 characters";
230+
case INVALID_ID_CHAR: return "seed ID used a non-bech32 character";
231+
case INVALID_LENGTH: return "invalid length";
232+
case INVALID_K: return "invalid threshold (k) value";
233+
case INVALID_SHARE_IDX: return "invalid share index";
234+
case TOO_FEW_SHARES: return "tried to derive a share but did not have enough input shares";
235+
case DUPLICATE_SHARE: return "tried to derive a share but two input shares had the same index";
236+
case MISMATCH_K: return "tried to derive a share but input shares had inconsistent threshold (k) values";
237+
case MISMATCH_ID: return "tried to derive a share but input shares had inconsistent seed IDs";
238+
case MISMATCH_LENGTH: return "tried to derive a share but input shares had inconsistent lengths";
239+
}
240+
assert(0);
241+
}
242+
223243
/** Encode a codex32 string. */
224244
std::string Result::Encode() const {
225245
assert(IsValid());

src/codex32.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ enum Error {
4141
MISMATCH_LENGTH,
4242
};
4343

44+
std::string ErrorString(Error e);
45+
4446
class Result
4547
{
4648
public:

0 commit comments

Comments
 (0)