Skip to content
This repository was archived by the owner on Jun 12, 2023. It is now read-only.

Make swarm key the onboarding key for an undefined key setup #166

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/miner.erl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
blockchain_block:block(), boolean()}},
election_epoch = 1 :: pos_integer(),
blockchain_ref = make_ref() :: reference(),
onboarding_key=undefined :: undefined | public_key:public_key()
onboarding_key = undefined :: undefined | libp2p_crypto:pubkey()
}).

-define(H3_MINIMUM_RESOLUTION, 9).
Expand Down Expand Up @@ -329,7 +329,7 @@ handle_call(onboarding_key_bin, _From, State=#state{onboarding_key=undefined}) -
%% Return an empty binary if no onboarding key is present
{reply, <<>>, State};
handle_call(onboarding_key_bin, _From, State=#state{onboarding_key=PubKey}) ->
{reply, libp2p_crypto:pubkey_to_bin({ecc_compact, PubKey}), State};
{reply, libp2p_crypto:pubkey_to_bin(PubKey), State};
handle_call({add_gateway_txn, Owner, Payer, Fee, StakingFee}, _From, State=#state{}) ->
{ok, PubKey, SigFun, _ECDHFun} = libp2p_swarm:keys(blockchain_swarm:swarm()),
PubKeyBin = libp2p_crypto:pubkey_to_bin(PubKey),
Expand Down
8 changes: 5 additions & 3 deletions src/miner_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ init(_Args) ->
{PubKey,
libp2p_crypto:mk_ecdh_fun(PrivKey0),
libp2p_crypto:mk_sig_fun(PrivKey0),
undefined};
PubKey};
{error, enoent} ->
KeyMap = #{secret := PrivKey0, public := PubKey} = libp2p_crypto:generate_keys(ecc_compact),
ok = libp2p_crypto:save_keys(KeyMap, SwarmKey),
{PubKey,
libp2p_crypto:mk_ecdh_fun(PrivKey0),
libp2p_crypto:mk_sig_fun(PrivKey0),
undefined}
PubKey}
end,
ECCWorker = [];
{ecc, Props} when is_list(Props) ->
Expand Down Expand Up @@ -117,7 +117,9 @@ init(_Args) ->
ecc508:wake(ECCPid),
%% Get (or generate) the public and onboarding keys
{ok, PublicKey, KeySlot} = GetPublicKey(KeySlot0),
{ok, OnboardingKey} = ecc508:genkey(ECCPid, public, OnboardingKeySlot),
{ok, OnboardingRawKey} = ecc508:genkey(ECCPid, public, OnboardingKeySlot),
%% gateway_mfr ensures that the onboarding keys is a compact key
OnboardingKey = {ecc_compact, OnboardingRawKey},
%% The signing and ecdh functions will use an actual
%% worker against a named process.
SigFun = fun(Bin) ->
Expand Down