Fix passphrase save/recover problem

This commit is contained in:
Craig Everett 2024-11-21 13:24:50 +09:00
parent f05c86894d
commit fd85edd4f3
12 changed files with 37 additions and 31 deletions

View File

@ -3,7 +3,7 @@
{registered,[]},
{included_applications,[]},
{applications,[stdlib,kernel]},
{vsn,"0.1.3"},
{vsn,"0.1.4"},
{modules,[clutch,gmc_con,gmc_grids,gmc_gui,gmc_jt,
gmc_key_master,gmc_sup,gmc_v,gmc_v_netman,
gmc_v_wallman]},

View File

@ -3,7 +3,7 @@
%%% @end
-module(clutch).
-vsn("0.1.3").
-vsn("0.1.4").
-behavior(application).
-author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>").

View File

@ -5,7 +5,7 @@
%%% @end
-module(gmc_con).
-vsn("0.1.3").
-vsn("0.1.4").
-author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later").
@ -63,12 +63,12 @@ show_ui(Name) ->
gen_server:cast(?MODULE, {show_ui, Name}).
-spec open_wallet(Path, Password) -> ok
when Path :: file:filename(),
Password :: string().
-spec open_wallet(Path, Phrase) -> ok
when Path :: file:filename(),
Phrase :: string().
open_wallet(Path, Password) ->
gen_server:cast(?MODULE, {open_wallet, Path, Password}).
open_wallet(Path, Phrase) ->
gen_server:cast(?MODULE, {open_wallet, Path, Phrase}).
-spec close_wallet() -> ok.
@ -787,17 +787,20 @@ do_make_key(Name, Seed, base58, Transform, State) ->
end.
do_make_key2(Name, Bin, Transform, State = #s{wallet = W}) ->
#wallet{poas = POAs, keys = Keys} = W,
do_make_key2(Name, Bin, Transform,
State = #s{wallet = Current, wallets = Wallets, pass = Pass}) ->
#wallet{name = WalletName, poas = POAs, keys = Keys} = Current,
T = transform(Transform),
Seed = T(Bin),
Key = #key{name = KeyName, id = ID} = gmc_key_master:make_key(Name, Seed),
POA = #poa{name = KeyName, id = ID},
NewKeys = [Key | Keys],
NewPOAs = [POA | POAs],
NewWallet = W#wallet{poas = NewPOAs, keys = NewKeys},
Updated = Current#wallet{poas = NewPOAs, keys = NewKeys},
RW = lists:keyfind(WalletName, #wr.name, Wallets),
ok = save_wallet(RW, Pass, Updated),
ok = gmc_gui:show(NewPOAs),
State#s{wallet = NewWallet}.
State#s{wallet = Updated}.
base64_decode(String) ->
@ -836,17 +839,19 @@ do_recover_key(Mnemonic, State) ->
State
end.
do_recover_key2(Seed, State = #s{wallet = W}) ->
#wallet{keys = Keys, poas = POAs} = W,
Recovered = #key{id = ID, name = Name} = gmc_key_master:make_key("", Seed),
do_recover_key2(Seed, State = #s{wallet = Current, wallets = Wallets, pass = Pass}) ->
#wallet{name = WalletName, keys = Keys, poas = POAs} = Current,
Recovered = #key{id = ID, name = AccName} = gmc_key_master:make_key("", Seed),
case lists:keymember(ID, #key.id, Keys) of
false ->
NewKeys = [Recovered | Keys],
POA = #poa{name = Name, id = ID},
POA = #poa{name = AccName, id = ID},
NewPOAs = [POA | POAs],
ok = gmc_gui:show(NewPOAs),
NewWallet = W#wallet{poas = NewPOAs, keys = NewKeys},
State#s{wallet = NewWallet};
Updated = Current#wallet{poas = NewPOAs, keys = NewKeys},
RW = lists:keyfind(WalletName, #wr.name, Wallets),
ok = save_wallet(RW, Pass, Updated),
State#s{wallet = Updated};
true ->
State
end.
@ -893,7 +898,7 @@ do_open_wallet(Path, Phrase, State) ->
{ok, ChainID} -> gmc_gui:chain(ChainID, Node);
Error -> gmc_gui:trouble(Error)
end,
State#s{wallet = Recovered};
State#s{pass = Pass, wallet = Recovered};
Error ->
ok = gmc_gui:trouble(Error),
New = default_wallet(),

View File

@ -37,7 +37,7 @@
%%% @end
-module(gmc_grids).
-vsn("0.1.3").
-vsn("0.1.4").
-author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later").

View File

@ -7,7 +7,7 @@
%%% @end
-module(gmc_gui).
-vsn("0.1.3").
-vsn("0.1.4").
-author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later").

View File

@ -15,7 +15,7 @@
%%% translation library is retained).
-module(gmc_jt).
-vsn("0.1.3").
-vsn("0.1.4").
-export([read_translations/1, j/2, oneshot_j/2]).

View File

@ -8,7 +8,7 @@
%%% @end
-module(gmc_key_master).
-vsn("0.1.3").
-vsn("0.1.4").
-export([make_key/2, encode/1, decode/1]).

View File

@ -12,7 +12,7 @@
%%% @end
-module(gmc_sup).
-vsn("0.1.3").
-vsn("0.1.4").
-behaviour(supervisor).
-author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>").

View File

@ -1,5 +1,5 @@
-module(gmc_v).
-vsn("0.1.3").
-vsn("0.1.4").
-author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later").

View File

@ -1,5 +1,5 @@
-module(gmc_v_netman).
-vsn("0.1.3").
-vsn("0.1.4").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later").

View File

@ -1,5 +1,5 @@
-module(gmc_v_wallman).
-vsn("0.1.3").
-vsn("0.1.4").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later").
@ -221,9 +221,10 @@ do_open3(Path, State = #s{frame = Frame, j = J}) ->
Affirm = wxButton:new(Dialog, ?wxID_OK),
_ = wxBoxSizer:add(ButtSz, Affirm, zxw:flags(wide)),
_ = wxBoxSizer:add(Sizer, PassSz, zxw:flags(base)),
_ = wxBoxSizer:add(Sizer, ButtSz, zxw:flags(base)),
_ = wxBoxSizer:add(Sizer, ButtSz, zxw:flags(wide)),
ok = wxDialog:setSizer(Dialog, Sizer),
ok = wxBoxSizer:layout(Sizer),
ok = wxDialog:setSize(Dialog, {500, 130}),
ok = wxFrame:center(Dialog),
ok = wxStyledTextCtrl:setFocus(PassTx),
case wxDialog:showModal(Dialog) of
@ -232,9 +233,9 @@ do_open3(Path, State = #s{frame = Frame, j = J}) ->
"" ->
ok = wxDialog:destroy(Dialog),
State;
Password ->
Phrase ->
ok = wxDialog:destroy(Dialog),
ok = gmc_con:open_wallet(Path, Password),
ok = gmc_con:open_wallet(Path, Phrase),
ok = do_close(State),
State
end;

View File

@ -4,7 +4,7 @@
{prefix,"gmc"}.
{desc,"A desktop client for the Gajumaru network of blockchain networks"}.
{author,"Craig Everett"}.
{package_id,{"otpr","clutch",{0,1,3}}}.
{package_id,{"otpr","clutch",{0,1,4}}}.
{deps,[{"otpr","hakuzaru",{0,2,0}},
{"otpr","aesophia",{8,0,1}},
{"otpr","aeserialization",{0,1,2}},