Skip to content

Commit

Permalink
Add RPC inteface for getting wallet info (#2562)
Browse files Browse the repository at this point in the history
* Add RPC inteface for getting wallet info
  • Loading branch information
Traf333 committed Mar 13, 2024
1 parent 851f2fc commit fe86c71
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
3 changes: 3 additions & 0 deletions bitacross-worker/enclave-runtime/src/initialization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ pub(crate) fn init_enclave(
getter_executor,
shielding_key_repository,
ocall_api.clone(),
signing_key_repository.clone(),
bitcoin_key_repository,
ethereum_key_repository,
);
let rpc_handler = Arc::new(RpcWsHandler::new(io_handler, watch_extractor, connection_registry));
GLOBAL_RPC_WS_HANDLER_COMPONENT.initialize(rpc_handler);
Expand Down
33 changes: 32 additions & 1 deletion bitacross-worker/enclave-runtime/src/rpc/worker_api_direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ use crate::{
generate_dcap_ra_extrinsic_from_quote_internal,
generate_ias_ra_extrinsic_from_der_cert_internal,
},
initialization::global_components::{
EnclaveBitcoinKeyRepository, EnclaveEthereumKeyRepository, EnclaveSigningKeyRepository,
},
std::string::ToString,
utils::{
get_stf_enclave_signer_from_solo_or_parachain,
Expand Down Expand Up @@ -51,7 +54,7 @@ use litentry_macros::if_not_production;
use litentry_primitives::{AesRequest, DecryptableRequest};
use log::debug;
use sgx_crypto_helper::rsa3072::Rsa3072PubKey;
use sp_core::Pair;
use sp_core::crypto::Pair;
use sp_runtime::OpaqueExtrinsic;
use std::{borrow::ToOwned, format, str, string::String, sync::Arc, vec::Vec};

Expand All @@ -74,6 +77,9 @@ pub fn public_api_rpc_handler<Author, GetterExecutor, AccessShieldingKey, OcallA
getter_executor: Arc<GetterExecutor>,
shielding_key: Arc<AccessShieldingKey>,
ocall_api: Arc<OcallApi>,
signing_key_repository: Arc<EnclaveSigningKeyRepository>,
bitcoin_key_repository: Arc<EnclaveBitcoinKeyRepository>,
ethereum_key_repository: Arc<EnclaveEthereumKeyRepository>,
) -> IoHandler
where
Author: AuthorApi<H256, H256, TrustedCallSigned, Getter> + Send + Sync + 'static,
Expand Down Expand Up @@ -145,6 +151,31 @@ where
}
});

io.add_sync_method("bitacross_getPublicKeys", move |_: Params| {
debug!("worker_api_direct rpc was called: bitacross_getPublicKeys");

let signer = match signing_key_repository.retrieve_key() {
Ok(pair) => pair.public().0.to_hex(),
Err(_e) => compute_hex_encoded_return_error("Can not obtain signer key"),
};

let bitcoin_key = match bitcoin_key_repository.retrieve_key() {
Ok(pair) => pair.public_bytes().to_hex(),
Err(_e) => compute_hex_encoded_return_error("Can not obtain bitcoin key"),
};

let ethereum_key = match ethereum_key_repository.retrieve_key() {
Ok(pair) => pair.public_bytes().to_hex(),
Err(_e) => compute_hex_encoded_return_error("Can not obtain ethereum key"),
};

Ok(json!({
"signer": signer,
"bitcoin_key": bitcoin_key,
"ethereum_key": ethereum_key
}))
});

let local_top_pool_author = top_pool_author.clone();
io.add_sync_method("author_getShardVault", move |_: Params| {
debug!("worker_api_direct rpc was called: author_getShardVault");
Expand Down
11 changes: 11 additions & 0 deletions bitacross-worker/enclave-runtime/src/test/direct_rpc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
*/

use crate::{
initialization::global_components::{
GLOBAL_BITCOIN_KEY_REPOSITORY_COMPONENT, GLOBAL_ETHEREUM_KEY_REPOSITORY_COMPONENT,
GLOBAL_SIGNING_KEY_REPOSITORY_COMPONENT,
},
rpc::worker_api_direct::public_api_rpc_handler,
test::{
fixtures::components::create_ocall_api,
Expand All @@ -32,6 +36,7 @@ use itc_direct_rpc_server::{
};
use itc_parentchain_test::ParentchainHeaderBuilder;
use itc_tls_websocket_server::{ConnectionToken, WebSocketMessageHandler};
use itp_component_container::ComponentGetter;
use itp_rpc::{Id, RpcRequest, RpcReturnValue};
use itp_sgx_crypto::get_rsa3072_repository;
use itp_sgx_temp_dir::TempDir;
Expand Down Expand Up @@ -68,6 +73,9 @@ pub fn state_get_mrenclave_works() {
getter_executor,
Arc::new(rsa_repository),
ocall_api.into(),
GLOBAL_SIGNING_KEY_REPOSITORY_COMPONENT.get().unwrap(),
GLOBAL_BITCOIN_KEY_REPOSITORY_COMPONENT.get().unwrap(),
GLOBAL_ETHEREUM_KEY_REPOSITORY_COMPONENT.get().unwrap(),
);
let rpc_handler = Arc::new(RpcWsHandler::new(io_handler, watch_extractor, connection_registry));

Expand Down Expand Up @@ -117,6 +125,9 @@ pub fn get_state_request_works() {
getter_executor,
Arc::new(rsa_repository),
ocall_api,
GLOBAL_SIGNING_KEY_REPOSITORY_COMPONENT.get().unwrap(),
GLOBAL_BITCOIN_KEY_REPOSITORY_COMPONENT.get().unwrap(),
GLOBAL_ETHEREUM_KEY_REPOSITORY_COMPONENT.get().unwrap(),
);
let rpc_handler = Arc::new(RpcWsHandler::new(io_handler, watch_extractor, connection_registry));

Expand Down

0 comments on commit fe86c71

Please sign in to comment.