@@ -9,6 +9,7 @@ use crate::{
99 update:: { op, script, OpParams } ,
1010 Error ,
1111} ;
12+ use bs_traits:: { GetKey , Signer } ;
1213use multicid:: { cid, vlad, Cid } ;
1314use multicodec:: Codec ;
1415use multihash:: mh;
@@ -19,10 +20,10 @@ use std::{fs::read, path::Path};
1920use tracing:: debug;
2021
2122/// open a new provenance log based on the config
22- pub fn open_plog < F1 , F2 > ( config : Config , get_key : F1 , sign_entry : F2 ) -> Result < Log , Error >
23+ pub fn open_plog < G , S > ( config : Config , get_key : & G , sign_entry : & S ) -> Result < Log , Error >
2324where
24- F1 : Fn ( & Key , Codec , usize , usize ) -> Result < Multikey , Error > ,
25- F2 : Fn ( & Multikey , & [ u8 ] ) -> Result < Multisig , Error > ,
25+ G : GetKey < Key = Multikey , KeyPath = Key , Codec = Codec > ,
26+ S : Signer < Key = Multikey , Signature = Multisig > ,
2627{
2728 // 0. Set up the list of ops we're going to add
2829 let mut op_params = Vec :: default ( ) ;
3536 . try_for_each ( |params| -> Result < ( ) , Error > {
3637 match params {
3738 p @ OpParams :: KeyGen { .. } => {
38- let _ = load_key ( & mut op_params, p, & get_key) ?;
39+ let _ = load_key ( & mut op_params, p, get_key) ?;
3940 }
4041 p @ OpParams :: CidGen { .. } => {
4142 let _ = load_cid ( & mut op_params, p, |path| -> Result < Vec < u8 > , Error > {
5455 . vlad_params
5556 . ok_or :: < Error > ( OpenError :: InvalidVladParams . into ( ) ) ?;
5657 // get the vlad signing key
57- let vlad_mk = load_key ( & mut op_params, & vlad_key_params, & get_key) ?;
58+ let vlad_mk = load_key ( & mut op_params, & vlad_key_params, get_key) ?;
5859 // get the cid for the first lock script
5960 let mut first_lock_script: Option < Script > = None ;
6061 let cid = load_cid (
@@ -82,15 +83,15 @@ where
8283 . ok_or :: < Error > ( OpenError :: InvalidKeyParams . into ( ) ) ?;
8384
8485 // get the entry signing key
85- let entry_mk = load_key ( & mut op_params, & entrykey_params, & get_key) ?;
86+ let entry_mk = load_key ( & mut op_params, & entrykey_params, get_key) ?;
8687
8788 // get the params for the pubkey
8889 let pubkey_params = config
8990 . pubkey_params
9091 . ok_or :: < Error > ( OpenError :: InvalidKeyParams . into ( ) ) ?;
9192
9293 // get the pubkey
93- let _ = load_key ( & mut op_params, & pubkey_params, & get_key) ?;
94+ let _ = load_key ( & mut op_params, & pubkey_params, get_key) ?;
9495
9596 // load the entry lock script
9697 let lock_script = {
@@ -162,7 +163,8 @@ where
162163 // get the serialzied version of the entry with an empty "proof" field
163164 let ev: Vec < u8 > = e. clone ( ) . into ( ) ;
164165 // call the call back to have the caller sign the data
165- let ms = sign_entry ( & entry_mk, & ev)
166+ let ms = sign_entry
167+ . try_sign ( & entry_mk, & ev)
166168 . map_err ( |e| PlogError :: from ( EntryError :: SignFailed ( e. to_string ( ) ) ) ) ?;
167169 // store the signature as proof
168170 Ok ( ms. into ( ) )
@@ -179,13 +181,9 @@ where
179181 Ok ( log)
180182}
181183
182- fn load_key < F > (
183- ops : & mut Vec < OpParams > ,
184- params : & OpParams ,
185- mut get_key : F ,
186- ) -> Result < Multikey , Error >
184+ fn load_key < G > ( ops : & mut Vec < OpParams > , params : & OpParams , get_key : & G ) -> Result < Multikey , Error >
187185where
188- F : FnMut ( & Key , Codec , usize , usize ) -> Result < Multikey , Error > ,
186+ G : GetKey < Key = Multikey , KeyPath = Key , Codec = Codec > ,
189187{
190188 debug ! ( "load_key: {:?}" , params) ;
191189 match params {
@@ -197,7 +195,7 @@ where
197195 revoke,
198196 } => {
199197 // call back to generate the key
200- let mk = get_key ( key, * codec, * threshold, * limit) ?;
198+ let mk = get_key. get_key ( key, codec, * threshold, * limit) ?;
201199
202200 // get the public key
203201 let pk = mk. conv_view ( ) ?. to_public_key ( ) ?;
0 commit comments