@@ -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,23 @@ impl<Cfg: Config> Module<Cfg> {
846848 <C :: Runtime as Runtime >:: Modules :: check_invariants ( ctx)
847849 }
848850
851+ fn keymanager_public_key_common < C : Context > ( ctx : & C ) -> Result < types:: KeyManagerPublicKeyQueryResponse , Error > {
852+ let key_manager = ctx
853+ . key_manager ( )
854+ . ok_or_else ( || Error :: InvalidArgument ( anyhow ! ( "key manager not available" ) ) ) ?;
855+ let epoch = ctx. epoch ( ) ;
856+ let key_pair_id = callformat:: get_key_pair_id ( epoch) ;
857+ let public_key = key_manager
858+ . get_public_key ( key_pair_id)
859+ . map_err ( |_| Error :: InvalidArgument ( anyhow ! ( "cannot get public key" ) ) ) ?;
860+ let runtime_id = * ctx. runtime_id ( ) ;
861+ Ok ( types:: KeyManagerPublicKeyQueryResponse {
862+ runtime_id,
863+ key_pair_id,
864+ public_key,
865+ } )
866+ }
867+
849868 fn calldata_public_key_common < C : Context > (
850869 ctx : & C ,
851870 ) -> Result < types:: CallDataPublicKeyQueryResponse , Error > {
@@ -865,6 +884,25 @@ impl<Cfg: Config> Module<Cfg> {
865884 Ok ( types:: CallDataPublicKeyQueryResponse { public_key, epoch } )
866885 }
867886
887+ /// Retrieve the public key for encrypting call data.
888+ #[ handler( query = "core.KeyManagerPublicKey" ) ]
889+ fn query_keymanager_public_key < C : Context > (
890+ ctx : & C ,
891+ _args : ( ) ,
892+ ) -> Result < types:: KeyManagerPublicKeyQueryResponse , Error > {
893+ Self :: keymanager_public_key_common ( ctx)
894+ }
895+
896+ /// Retrieve the public key for encrypting call data (internally exposed call).
897+ #[ handler( call = "core.KeyManagerPublicKey" , internal) ]
898+ fn internal_keymanager_public_key < C : Context > (
899+ ctx : & C ,
900+ _args : ( ) ,
901+ ) -> Result < types:: KeyManagerPublicKeyQueryResponse , Error > {
902+ <C :: Runtime as Runtime >:: Core :: use_tx_gas ( Cfg :: GAS_COST_CALL_CALLDATA_PUBLIC_KEY ) ?;
903+ Self :: keymanager_public_key_common ( ctx)
904+ }
905+
868906 /// Retrieve the public key for encrypting call data.
869907 #[ handler( query = "core.CallDataPublicKey" ) ]
870908 fn query_calldata_public_key < C : Context > (
0 commit comments