diff --git a/example-scripts/bip39-to-sskr.sh b/example-scripts/bip39-to-sskr.sh deleted file mode 100755 index be10fa6..0000000 --- a/example-scripts/bip39-to-sskr.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -# -# This is an example script that uses Seedtool that converts a BIP39 seed into a set of SSKR shares in one step. -# -# -# Example invocation on single line: -# -# ./bip39-to-sskr.sh "slender horse coil sketch public wink nest point royal believe inform lyrics critic harbor scheme enrich burden glance song chicken grief first panic actor" --group-threshold 1 --group 2-of-3 --group 3-of-5 -# -# tuna acid epic hard data tied visa acid acid able hope glow iced meow flew ruby omit fizz need task gear claw door hope meow waxy dark keep barn math beta tent half wasp idea fern peck void limp peck fact half cook game down fish -# tuna acid epic hard data tied visa acid acid acid keno kept oboe data rock skew plus vast free kick horn horn fund foxy tomb gray diet soap roof runs time pose yell able inch fern crux lung into twin pool back user purr fish guru -# tuna acid epic hard data tied visa acid acid also belt fish yurt wave play gear ruby claw fern redo cola wave waxy iron blue luau film bulb kept taco pose drop bias dull jowl fern open echo heat game axis waxy jury list king judo -# tuna acid epic hard data tied visa acid brag able drop mild paid what rich fair jolt urge user exit race saga lion user play cyan crux heat fizz wolf figs chef oval void half numb king gems puma exam away oval scar play vibe cook -# tuna acid epic hard data tied visa acid brag acid cyan axis mild trip fizz unit dice calm memo ramp flew sets toil trip view waxy mild days lung news gush diet yank yank back pool aunt scar roof draw even zest many rust axis memo -# tuna acid epic hard data tied visa acid brag also menu noon flux lamb quiz gift lazy slot twin very axis high hope ruby aqua surf acid very rich each knob fund purr guru oboe mint flux pool fizz gear sets apex deli kiwi tent bald -# tuna acid epic hard data tied visa acid brag apex next also knob hang gift play slot bias miss jowl zone heat barn road game acid quiz next jury holy cash keys very flap zone monk fish curl gift good zaps hawk jade calm fern list -# tuna acid epic hard data tied visa acid brag aqua work cyan cash onyx cook inch fern memo note sets wall need soap puff cusp free eyes crux grim code solo lamb judo veto main idle days cusp solo zest kiwi quad foxy claw play unit -# -# -# Example invocation using STDIN to supply the BIP39 words -# -# ./bip39-to-sskr.sh "" --group-threshold 1 --group 2-of-3 --group 3-of-5 -# slender horse coil sketch public wink nest point royal believe inform lyrics critic harbor scheme enrich burden glance song chicken grief first panic actor -# ^D -# -# tuna acid epic hard data skew wand acid acid able jugs noon kiln aunt roof leaf race figs horn exit knob wave next fuel pose taco miss work ruby webs huts film mild wolf zoom free puff wave whiz sets beta wave tent time kiwi vibe -# tuna acid epic hard data skew wand acid acid acid hill oboe lazy stub hard fair diet days task jowl glow jade hope into hope undo game toys view flux vibe navy time judo duty main eyes hope junk what news lazy redo half yank gyro -# tuna acid epic hard data skew wand acid acid also diet visa miss liar jowl warm mint bald data mint code zaps also aunt gush wand even purr belt plus judo join chef waxy kiln soap rich memo warm plus each epic task numb unit kept -# tuna acid epic hard data skew wand acid brag able leaf wall toys trip undo exit ruby navy girl work legs bulb purr luau girl wasp poem quiz able void skew puff yawn gyro kite rich cook each peck belt lazy time void luck zaps maze -# tuna acid epic hard data skew wand acid brag acid yoga jolt gems song mild hard inky when zest keep surf work hard news calm gear poem plus zone cook numb lava leaf work judo ruin zinc oval task next acid gyro oboe road lion runs -# tuna acid epic hard data skew wand acid brag also high runs memo onyx note skew good jury oval peck pose menu toil lung news note iris hard slot kite arch navy heat note tent high item very barn limp zone quad taxi judo fuel eyes -# tuna acid epic hard data skew wand acid brag apex days exit axis ramp tomb oval luau cost bulb down vast junk fish navy sets exit iris fizz eyes limp idea peck drum film unit help loud keno iron buzz knob epic mild frog fair cash -# tuna acid epic hard data skew wand acid brag aqua lung grim visa help echo deli into ruby webs glow data item wand deli iced memo arch door buzz chef into toys ruin numb user wall idle echo half zest work tiny tied pose apex vibe -# - -BIP39=$1 -SSKR_OPTIONS=${@:2} -seedtool --in bip39 ${BIP39} | seedtool --in hex --out sskr ${SSKR_OPTIONS} diff --git a/example-scripts/sskr-to-bip39.sh b/example-scripts/sskr-to-bip39.sh deleted file mode 100755 index d9602bf..0000000 --- a/example-scripts/sskr-to-bip39.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -# -# This is an example script that converts a set of SSKR shares to BIP-39 seed in one step. It takes the shares from STDIN and -# write the BIP-39 seed to STDOUT. -# -# Example invocation: -# -# ./sskr-to-bip39.sh -# tuna acid epic hard data tied visa acid acid able hope glow iced meow flew ruby omit fizz need task gear claw door hope meow waxy dark keep barn math beta tent half wasp idea fern peck void limp peck fact half cook game down fish -# tuna acid epic hard data tied visa acid acid acid keno kept oboe data rock skew plus vast free kick horn horn fund foxy tomb gray diet soap roof runs time pose yell able inch fern crux lung into twin pool back user purr fish guru -# ^D -# -# slender horse coil sketch public wink nest point royal believe inform lyrics critic harbor scheme enrich burden glance song chicken grief first panic actor - -seedtool --in sskr | seedtool --in hex --out bip39 diff --git a/src/format-sskr.cpp b/src/format-sskr.cpp index 5f70126..821c116 100644 --- a/src/format-sskr.cpp +++ b/src/format-sskr.cpp @@ -116,7 +116,6 @@ void FormatSSKR::process_output(Params* p) { assert(gen_share_count == share_count); assert(bytes_in_each_share == share_len); - if(p->is_ur_out) { StringVector strings; for (int i = 0; i < share_count; i++) { uint8_t* bytes = shares_buffer + (i * bytes_in_each_share); @@ -124,26 +123,15 @@ void FormatSSKR::process_output(Params* p) { ByteVector cbor; ur::CborLite::encodeTagAndValue(cbor, ur::CborLite::Major::semantic, size_t(309)); ur::CborLite::encodeBytes(cbor, v); + if (p->is_ur_out) { ur::UR ur("crypto-sskr", cbor); - auto s = ur::UREncoder::encode(ur); - strings.push_back(s); - } - auto all_strings = join(strings, "\n"); - p->output = all_strings; + strings.push_back(ur::UREncoder::encode(ur)); } else { - StringVector strings; - for (int i = 0; i < share_count; i++) { - uint8_t* bytes = shares_buffer + (i * bytes_in_each_share); - auto v = ByteVector(bytes, bytes + bytes_in_each_share); - ByteVector cbor; - ur::CborLite::encodeTagAndValue(cbor, ur::CborLite::Major::semantic, size_t(309)); - ur::CborLite::encodeBytes(cbor, v); - auto s = ur::Bytewords::encode(ur::Bytewords::standard, cbor); - strings.push_back(s); + strings.push_back(ur::Bytewords::encode(ur::Bytewords::standard, cbor)); + } } auto all_strings = join(strings, "\n"); p->output = all_strings; - } } FormatSSKR::FormatSSKR() diff --git a/src/params.cpp b/src/params.cpp index d974284..324bca7 100644 --- a/src/params.cpp +++ b/src/params.cpp @@ -100,46 +100,6 @@ void Params::validate_output_format() { } } -void Params::validate_output_for_input() { - // Any input format works with hex output format. - if(is_hex(output_format)) { - return; - } - - // Any input format works with any Bytewords output format. - if(is_bytewords_any(output_format)) { - return; - } - - // Random input works with any output format. - if(is_random(input_format)) { - return; - } - - // Hex input works with any output format. - if(is_hex(input_format)) { - return; - } - - // Any Bytewords input works with any output format. - if(is_bytewords_any(input_format)) { - return; - } - - // BIP39 UR input works with BIP39 output format. - if(is_ur_in && is_bip39(input_format) && is_bip39(output_format)) { - return; - } - - // SSKR UR input works with SSKR output format. - if(is_ur_in && is_sskr(input_format) && is_sskr(output_format)) { - return; - } - - argp_error(state, "Input format %s cannot be used with output format %s", - input_format->name.c_str(), output_format->name.c_str()); -} - void Params::validate_ints_specific() { auto f = dynamic_cast(output_format); if(f != NULL) { @@ -378,7 +338,6 @@ void Params::validate() { validate_input(); validate_count_for_input_format(); validate_output_format(); - validate_output_for_input(); validate_ints_specific(); validate_bip39_specific(); validate_sskr_specific(); diff --git a/src/params.hpp b/src/params.hpp index 46ade17..22ee17b 100644 --- a/src/params.hpp +++ b/src/params.hpp @@ -96,7 +96,6 @@ class Params { void validate_input_format(); void validate_count_for_input_format(); void validate_output_format(); - void validate_output_for_input(); void validate_ints_specific(); void validate_bip39_specific(); void validate_sskr_specific(); diff --git a/src/test.sh b/src/test.sh index 8083f71..95a1b69 100755 --- a/src/test.sh +++ b/src/test.sh @@ -294,6 +294,46 @@ testInSSKRUR() "$(${SEEDTOOL} --in ur ur:crypto-sskr/taadecgomymwaeadaemdfnpldrprcmtpcnfwztcstaotfsbsadatkspyfg ur:crypto-sskr/taadecgomymwaeadaoglvdolfhemvogaiyksjpvabncphhmsmkjznbdefy)" } +testBip39ToSskr() +{ + assertEquals $'tuna acid epic hard data edge next acid acid able rust claw zaps curl zero exit wolf solo beta whiz jowl keys beta help nail flap data peck beta task flap blue grim holy warm curl ruin main cook twin exit dark when brag zero blue +tuna acid epic hard data edge next acid acid acid aqua solo legs away back poem inky cash view ruin nail stub puma duty hang inch edge rock lion taco iron puma legs knob many keno note work huts next meow kept pose view buzz item +tuna acid epic hard data edge next acid acid also guru onyx away junk also axis saga jolt scar item monk arch jade lung cook axis aunt logo arch swan body gala warm cook cyan many zest kiln vast gush king leaf horn bulb vibe meow +tuna acid epic hard data edge next acid brag able toil edge wall gala obey task body zinc cyan solo meow view roof free wall what tomb paid brew note judo owls chef kept stub deli down wall owls wave fair kept kept duty vows city +tuna acid epic hard data edge next acid brag acid runs lion note blue glow flux legs slot purr claw task quad roof list grim cash ruin what iris fizz cash mild slot cost bias wolf runs quiz ruin wave iced navy gear monk huts blue +tuna acid epic hard data edge next acid brag also bald down vibe foxy iced part wasp heat kiwi mint cyan kite kick redo wall fair judo zest chef edge fuel game legs poem apex keys lava oboe cats hard time ramp gift drum zoom hang +tuna acid epic hard data edge next acid brag apex huts nail memo cola luck data knob horn wasp foxy keys door kick kiln grim undo cats onyx iced warm crux keys hill silk slot plus bulb zoom acid hard love help jugs lion keno hill +tuna acid epic hard data edge next acid brag aqua heat maze heat nail draw luck toil solo cats twin view cats bulb exam frog arch flew ruby twin wand toys jury saga what exam aqua duty mint rust knob legs waxy beta quiz knob taco' \ + "$(${SEEDTOOL} --in bip39 --out sskr --group-threshold 1 --group 2-of-3 --group 3-of-5 'slender horse coil sketch public wink nest point royal believe inform lyrics critic harbor scheme enrich burden glance song chicken grief first panic actor')" +} + +testSskrToBip39() +{ + assertEquals $'clump flavor moment wood resource mom usual solid fortune material document under' \ + "$(${SEEDTOOL} --in sskr --out bip39 \ + 'tuna acid epic gyro edge next able acid able flux down eyes pool task cyan gyro kept exit paid wave high news bias zone zaps calm note poem aqua' \ + 'tuna acid epic gyro edge next able acid also wolf vows bald sets claw bald dull cost slot inky liar work note tied zest safe crux kiln work exit')" +} + +testAllInputOutputCombinations() +{ + # Tests all combinations of input and output formats. We don't want to + # hard-code these all, so we just test whether `hex -> A` is the same as `hex + # -> A -> B -> A`. + # + # The formats below are all the formats that can represent a full seed. There + # are others like "ints", but these don't represent a full seed with the + # default --count setting. + formats="hex bip39 sskr btw btwu btwm" + for dst_format in $formats; do + for src_format in $formats; do + output_orig="$(${SEEDTOOL} | ${SEEDTOOL} --in hex --out $dst_format)" + output_roundtrip="$(${SEEDTOOL} | ${SEEDTOOL} --in hex --out $dst_format | ${SEEDTOOL} --in $dst_format --out $src_format | ${SEEDTOOL} --in $src_format --out $dst_format)" + assertEquals "dst=$dst_format and src=$src_format must be compatible." "$output_orig" "$output_roundtrip" + done + done +} + # Eat all command-line arguments before calling shunit2. shift $# # TODO no shunit2 on windows/msys2/mingw64 platform