Skip to content

Commit

Permalink
Obsolete bx seed command
Browse files Browse the repository at this point in the history
  • Loading branch information
kulpreet committed Aug 11, 2023
1 parent 20eba4d commit 5281cfb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 84 deletions.
1 change: 0 additions & 1 deletion data/bx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ _bx()
script-decode
script-encode
script-to-address
seed
send-tx
send-tx-node
send-tx-p2p
Expand Down
37 changes: 11 additions & 26 deletions include/bitcoin/explorer/commands/seed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ namespace commands {
/**
* Various localizable strings.
*/
#define BX_SEED_BIT_LENGTH_UNSUPPORTED \
"The seed size is not supported."
#define BX_SEED_OBSOLETE \
"This command is obsolete. Use an alternative source of entropy for your key generation needs."

/**
* Class to implement the seed command.
Expand Down Expand Up @@ -111,6 +111,15 @@ class BCX_API seed
return "Generate a pseudorandom seed.";
}

/**
* Declare whether the command has been obsoleted.
* @return True if the command is obsolete
*/
virtual bool obsolete()
{
return true;
}

/**
* Load program argument definitions.
* A value of -1 indicates that the number of instances is unlimited.
Expand Down Expand Up @@ -150,11 +159,6 @@ class BCX_API seed
BX_CONFIG_VARIABLE ",c",
value<boost::filesystem::path>(),
"The path to the configuration settings file."
)
(
"bit_length,b",
value<uint16_t>(&option_.bit_length)->default_value(192),
"The length of the seed in bits. Must be divisible by 8 and must not be less than 128, defaults to 192."
);

return options;
Expand All @@ -179,23 +183,6 @@ class BCX_API seed

/* Properties */

/**
* Get the value of the bit_length option.
*/
virtual uint16_t& get_bit_length_option()
{
return option_.bit_length;
}

/**
* Set the value of the bit_length option.
*/
virtual void set_bit_length_option(
const uint16_t& value)
{
option_.bit_length = value;
}

private:

/**
Expand All @@ -219,11 +206,9 @@ class BCX_API seed
struct option
{
option()
: bit_length()
{
}

uint16_t bit_length;
} option_;
};

Expand Down
5 changes: 2 additions & 3 deletions model/generate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,8 @@
<argument name="SCRIPT" stdin="true" type="script" description="The script to use in the address. Multiple tokens must be quoted. If not specified the script is read from STDIN."/>
</command>

<command symbol="seed" output="base16" category="WALLET" description="Generate a pseudorandom seed.">
<option name="bit_length" type="uint16_t" default="192" description="The length of the seed in bits. Must be divisible by 8 and must not be less than 128, defaults to 192." />
<define name="BX_SEED_BIT_LENGTH_UNSUPPORTED" value="The seed size is not supported." />
<command symbol="seed" output="base16" category="WALLET" obsolete="true" description="Generate a pseudorandom seed.">
<define name="BX_SEED_OBSOLETE" value="This command is obsolete. Use an alternative source of entropy for your key generation needs." />
</command>

<command symbol="send-tx" formerly="sendtx-obelisk" output="string" category="ONLINE" network="true" description="Broadcast a transaction to the Bitcoin network via a Libbitcoin server.">
Expand Down
17 changes: 2 additions & 15 deletions src/commands/seed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,8 @@ using namespace bc::config;

console_result seed::invoke(std::ostream& output, std::ostream& error)
{
const auto bit_length = get_bit_length_option();

// These are soft requirements for security and rationality.
// We use bit vs. byte length input as the more familiar convention.
if (bit_length < minimum_seed_size * byte_bits ||
bit_length % byte_bits != 0)
{
error << BX_SEED_BIT_LENGTH_UNSUPPORTED << std::endl;
return console_result::failure;
}

const auto seed = new_seed(bit_length);

output << base16(seed) << std::endl;
return console_result::okay;
error << BX_SEED_OBSOLETE << std::endl;
return console_result::failure;
}

} //namespace commands
Expand Down
41 changes: 2 additions & 39 deletions test/commands/seed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,13 @@ BX_USING_NAMESPACES()
BOOST_AUTO_TEST_SUITE(offline)
BOOST_AUTO_TEST_SUITE(seed__invoke)

#define BX_SEED_BITS_TO_TERMINATED_BASE16(bits) (2 * (bits / 8) + 1)

BOOST_AUTO_TEST_CASE(seed__invoke__minimum_size__okay_output)
{
BX_DECLARE_COMMAND(seed);

// Here we must explicitly set the default value, since we are bypassing
// the boost parser and variable bindings which implement defaults.
command.set_bit_length_option(128);
BX_REQUIRE_OKAY(command.invoke(output, error));
BOOST_REQUIRE(output.str().size() == BX_SEED_BITS_TO_TERMINATED_BASE16(128));
}

BOOST_AUTO_TEST_CASE(seed__invoke__good_size__okay_output)
{
BX_DECLARE_COMMAND(seed);
command.set_bit_length_option(256);
BX_REQUIRE_OKAY(command.invoke(output, error));
BOOST_REQUIRE(output.str().size() == BX_SEED_BITS_TO_TERMINATED_BASE16(256));
}

BOOST_AUTO_TEST_CASE(seed__invoke_big_size_okay_output)
{
BX_DECLARE_COMMAND(seed);
command.set_bit_length_option(512);
BX_REQUIRE_OKAY(command.invoke(output, error));
BOOST_REQUIRE(output.str().size() == BX_SEED_BITS_TO_TERMINATED_BASE16(512));
}

BOOST_AUTO_TEST_CASE(seed__invoke__too_short__failure_error)
BOOST_AUTO_TEST_CASE(seed__invoke__always__failure_error)
{
BX_DECLARE_COMMAND(seed);
command.set_bit_length_option(64);
BX_REQUIRE_FAILURE(command.invoke(output, error));
BX_REQUIRE_ERROR(BX_SEED_BIT_LENGTH_UNSUPPORTED "\n");
BX_REQUIRE_ERROR(BX_SEED_OBSOLETE "\n");
}

BOOST_AUTO_TEST_CASE(seed__invoke__not_byte_aligned__failure_error)
{
BX_DECLARE_COMMAND(seed);
command.set_bit_length_option(129);
BX_REQUIRE_FAILURE(command.invoke(output, error));
BX_REQUIRE_ERROR(BX_SEED_BIT_LENGTH_UNSUPPORTED "\n");
}

BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 5281cfb

Please sign in to comment.