@@ -427,6 +427,8 @@ pub trait Config: 'static {
427427 const GAS_COST_CALL_CALLDATA_PUBLIC_KEY : u64 = 20 ;
428428 /// The gas cost of the internal call to retrieve the current epoch.
429429 const GAS_COST_CALL_CURRENT_EPOCH : u64 = 10 ;
430+ /// The gas cost of the internal call to retrieve the current long-term public key
431+ const GAS_COST_CALL_PUBLIC_KEY : u64 = 20 ;
430432}
431433
432434pub struct Module < Cfg : Config > {
@@ -846,6 +848,25 @@ impl<Cfg: Config> Module<Cfg> {
846848 <C :: Runtime as Runtime >:: Modules :: check_invariants ( ctx)
847849 }
848850
851+ fn keymanager_public_key_common < C : Context > (
852+ ctx : & C ,
853+ ) -> Result < types:: KeyManagerPublicKeyQueryResponse , Error > {
854+ let key_manager = ctx
855+ . key_manager ( )
856+ . ok_or_else ( || Error :: InvalidArgument ( anyhow ! ( "key manager not available" ) ) ) ?;
857+ let epoch = ctx. epoch ( ) ;
858+ let key_pair_id = callformat:: get_key_pair_id ( epoch) ;
859+ let public_key = key_manager
860+ . get_public_key ( key_pair_id)
861+ . map_err ( |_| Error :: InvalidArgument ( anyhow ! ( "cannot get public key" ) ) ) ?;
862+ let runtime_id = * ctx. runtime_id ( ) ;
863+ Ok ( types:: KeyManagerPublicKeyQueryResponse {
864+ runtime_id,
865+ key_pair_id,
866+ public_key,
867+ } )
868+ }
869+
849870 fn calldata_public_key_common < C : Context > (
850871 ctx : & C ,
851872 ) -> Result < types:: CallDataPublicKeyQueryResponse , Error > {
@@ -865,6 +886,25 @@ impl<Cfg: Config> Module<Cfg> {
865886 Ok ( types:: CallDataPublicKeyQueryResponse { public_key, epoch } )
866887 }
867888
889+ /// Retrieve the public key for encrypting call data.
890+ #[ handler( query = "core.KeyManagerPublicKey" ) ]
891+ fn query_keymanager_public_key < C : Context > (
892+ ctx : & C ,
893+ _args : ( ) ,
894+ ) -> Result < types:: KeyManagerPublicKeyQueryResponse , Error > {
895+ Self :: keymanager_public_key_common ( ctx)
896+ }
897+
898+ /// Retrieve the public key for encrypting call data (internally exposed call).
899+ #[ handler( call = "core.KeyManagerPublicKey" , internal) ]
900+ fn internal_keymanager_public_key < C : Context > (
901+ ctx : & C ,
902+ _args : ( ) ,
903+ ) -> Result < types:: KeyManagerPublicKeyQueryResponse , Error > {
904+ <C :: Runtime as Runtime >:: Core :: use_tx_gas ( Cfg :: GAS_COST_CALL_CALLDATA_PUBLIC_KEY ) ?;
905+ Self :: keymanager_public_key_common ( ctx)
906+ }
907+
868908 /// Retrieve the public key for encrypting call data.
869909 #[ handler( query = "core.CallDataPublicKey" ) ]
870910 fn query_calldata_public_key < C : Context > (
0 commit comments