add secmod_denom.ml secmod_signkey.ml
This commit is contained in:
parent
16ab1fff2b
commit
846122b49c
5 changed files with 121 additions and 135 deletions
47
src/secmod_denom.ml
Normal file
47
src/secmod_denom.ml
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
open Syntax
|
||||
|
||||
type t = {
|
||||
sm_key: Signkey.t;
|
||||
(* TODO rename *)
|
||||
keys: Denomination.t list;
|
||||
}
|
||||
|
||||
let dir = Fpath.(v "data" / "secmod_signkey")
|
||||
|
||||
let store_secmod_data t =
|
||||
let* () = Data_file.write_eddsa Fpath.(dir / "sm_key") t.sm_key.priv in
|
||||
t.keys
|
||||
|> List.mapi (fun i key ->
|
||||
let fname = Fpath.(dir / string_of_int i) in
|
||||
(fname, key.Denomination.priv))
|
||||
|> list_iter (fun (fname, key) -> Data_file.write_rsa fname key)
|
||||
|
||||
let load conn =
|
||||
let error_invalid_state =
|
||||
Fmt.error_msg "secmod_denom load error: invalid store state."
|
||||
in
|
||||
let* sm_key = Data_file.load_signkey conn Fpath.(dir / "sm_key") in
|
||||
let* keys =
|
||||
let* l =
|
||||
let open Config.Coin in
|
||||
Syntax.list_map
|
||||
(fun coin ->
|
||||
let section_name = coin.section_name in
|
||||
let fname = Fpath.(dir / section_name) in
|
||||
(* todo: could check that coin config match db values *)
|
||||
Data_file.load_denom conn ~section_name fname)
|
||||
all_coins
|
||||
in
|
||||
match Syntax.opt_list l with
|
||||
| Error () -> error_invalid_state
|
||||
| Ok opt -> Ok opt
|
||||
in
|
||||
match (sm_key, keys) with
|
||||
| None, None -> Ok None
|
||||
| Some sm_key, Some keys -> Ok (Some { sm_key; keys })
|
||||
| _, _ -> error_invalid_state
|
||||
|
||||
let make_new () =
|
||||
let sm_key = Signkey.make () in
|
||||
let keys = List.map Denomination.make Config.Coin.all_coins in
|
||||
{ sm_key; keys }
|
||||
Loading…
Add table
Add a link
Reference in a new issue