Merge pull request #6 from informalsystems/hu55a1n1/5-register-epoch-key
Register epoch key
This commit is contained in:
commit
3ffa3fac5e
3 changed files with 51 additions and 7 deletions
|
@ -4,7 +4,7 @@ use cosmwasm_std::{
|
||||||
use cw2::set_contract_version;
|
use cw2::set_contract_version;
|
||||||
|
|
||||||
use crate::error::ContractError;
|
use crate::error::ContractError;
|
||||||
use crate::msg::execute::{BootstrapKeyManagerMsg, JoinComputeNodeMsg};
|
use crate::msg::execute::{BootstrapKeyManagerMsg, JoinComputeNodeMsg, RegisterEpochKeyMsg};
|
||||||
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
|
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
|
||||||
use crate::state::{State, STATE};
|
use crate::state::{State, STATE};
|
||||||
|
|
||||||
|
@ -45,6 +45,9 @@ pub fn execute(
|
||||||
}) => {
|
}) => {
|
||||||
execute::bootstrap_key_manger(deps, compute_mrenclave, key_manager_mrenclave, tcb_info)
|
execute::bootstrap_key_manger(deps, compute_mrenclave, key_manager_mrenclave, tcb_info)
|
||||||
}
|
}
|
||||||
|
ExecuteMsg::RegisterEpochKey(RegisterEpochKeyMsg { epoch_key }) => {
|
||||||
|
execute::register_epoch_key(deps, epoch_key)
|
||||||
|
}
|
||||||
ExecuteMsg::JoinComputeNode(JoinComputeNodeMsg {
|
ExecuteMsg::JoinComputeNode(JoinComputeNodeMsg {
|
||||||
io_exchange_key,
|
io_exchange_key,
|
||||||
address,
|
address,
|
||||||
|
@ -58,8 +61,8 @@ pub mod execute {
|
||||||
use k256::ecdsa::VerifyingKey;
|
use k256::ecdsa::VerifyingKey;
|
||||||
|
|
||||||
use crate::state::{
|
use crate::state::{
|
||||||
Mrenclave, RawAddress, RawMrenclave, RawNonce, RawPublicKey, RawTcbInfo, SgxState,
|
EpochState, Mrenclave, RawAddress, RawMrenclave, RawNonce, RawPublicKey, RawTcbInfo,
|
||||||
SGX_STATE,
|
SgxState, EPOCH_STATE, SGX_STATE,
|
||||||
};
|
};
|
||||||
use crate::state::{Request, REQUESTS};
|
use crate::state::{Request, REQUESTS};
|
||||||
use crate::ContractError;
|
use crate::ContractError;
|
||||||
|
@ -98,6 +101,22 @@ pub mod execute {
|
||||||
.add_attribute("tcb_info", tcb_info))
|
.add_attribute("tcb_info", tcb_info))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn register_epoch_key(
|
||||||
|
deps: DepsMut,
|
||||||
|
epoch_key: RawPublicKey,
|
||||||
|
) -> Result<Response, ContractError> {
|
||||||
|
let _ = VerifyingKey::from_sec1_bytes(&hex::decode(&epoch_key)?)?;
|
||||||
|
|
||||||
|
let epoch_state = EpochState {
|
||||||
|
epoch_key: epoch_key.clone(),
|
||||||
|
};
|
||||||
|
EPOCH_STATE.save(deps.storage, &epoch_state)?;
|
||||||
|
|
||||||
|
Ok(Response::new()
|
||||||
|
.add_attribute("action", "register_epoch_key")
|
||||||
|
.add_attribute("epoch_key", epoch_key))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn enqueue_join_request(
|
pub fn enqueue_join_request(
|
||||||
deps: DepsMut,
|
deps: DepsMut,
|
||||||
io_exchange_key: RawPublicKey,
|
io_exchange_key: RawPublicKey,
|
||||||
|
@ -125,6 +144,7 @@ pub mod execute {
|
||||||
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
|
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
|
||||||
match msg {
|
match msg {
|
||||||
QueryMsg::GetSgxState {} => to_json_binary(&query::get_sgx_state(deps)?),
|
QueryMsg::GetSgxState {} => to_json_binary(&query::get_sgx_state(deps)?),
|
||||||
|
QueryMsg::GetEpochState {} => to_json_binary(&query::get_epoch_state(deps)?),
|
||||||
QueryMsg::GetRequests {} => to_json_binary(&query::get_requests(deps)?),
|
QueryMsg::GetRequests {} => to_json_binary(&query::get_requests(deps)?),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,8 +152,8 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
|
||||||
pub mod query {
|
pub mod query {
|
||||||
use cosmwasm_std::{Deps, StdResult};
|
use cosmwasm_std::{Deps, StdResult};
|
||||||
|
|
||||||
use crate::msg::query::{GetRequestsResponse, GetSgxStateResponse};
|
use crate::msg::query::{GetEpochStateResponse, GetRequestsResponse, GetSgxStateResponse};
|
||||||
use crate::state::{SgxState, REQUESTS, SGX_STATE};
|
use crate::state::{EpochState, SgxState, EPOCH_STATE, REQUESTS, SGX_STATE};
|
||||||
|
|
||||||
pub fn get_sgx_state(deps: Deps) -> StdResult<GetSgxStateResponse> {
|
pub fn get_sgx_state(deps: Deps) -> StdResult<GetSgxStateResponse> {
|
||||||
let SgxState {
|
let SgxState {
|
||||||
|
@ -147,6 +167,11 @@ pub mod query {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_epoch_state(deps: Deps) -> StdResult<GetEpochStateResponse> {
|
||||||
|
let EpochState { epoch_key } = EPOCH_STATE.load(deps.storage)?;
|
||||||
|
Ok(GetEpochStateResponse { epoch_key })
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_requests(deps: Deps) -> StdResult<GetRequestsResponse> {
|
pub fn get_requests(deps: Deps) -> StdResult<GetRequestsResponse> {
|
||||||
Ok(GetRequestsResponse {
|
Ok(GetRequestsResponse {
|
||||||
requests: REQUESTS.load(deps.storage)?,
|
requests: REQUESTS.load(deps.storage)?,
|
||||||
|
|
|
@ -6,6 +6,7 @@ pub struct InstantiateMsg;
|
||||||
#[cw_serde]
|
#[cw_serde]
|
||||||
pub enum ExecuteMsg {
|
pub enum ExecuteMsg {
|
||||||
BootstrapKeyManager(execute::BootstrapKeyManagerMsg),
|
BootstrapKeyManager(execute::BootstrapKeyManagerMsg),
|
||||||
|
RegisterEpochKey(execute::RegisterEpochKeyMsg),
|
||||||
JoinComputeNode(execute::JoinComputeNodeMsg),
|
JoinComputeNode(execute::JoinComputeNodeMsg),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +20,11 @@ pub mod execute {
|
||||||
pub tcb_info: String,
|
pub tcb_info: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cw_serde]
|
||||||
|
pub struct RegisterEpochKeyMsg {
|
||||||
|
pub epoch_key: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[cw_serde]
|
#[cw_serde]
|
||||||
pub struct JoinComputeNodeMsg {
|
pub struct JoinComputeNodeMsg {
|
||||||
pub io_exchange_key: String,
|
pub io_exchange_key: String,
|
||||||
|
@ -32,6 +38,8 @@ pub mod execute {
|
||||||
pub enum QueryMsg {
|
pub enum QueryMsg {
|
||||||
#[returns(query::GetSgxStateResponse)]
|
#[returns(query::GetSgxStateResponse)]
|
||||||
GetSgxState {},
|
GetSgxState {},
|
||||||
|
#[returns(query::GetEpochStateResponse)]
|
||||||
|
GetEpochState {},
|
||||||
#[returns(query::GetRequestsResponse)]
|
#[returns(query::GetRequestsResponse)]
|
||||||
GetRequests {},
|
GetRequests {},
|
||||||
}
|
}
|
||||||
|
@ -39,7 +47,7 @@ pub enum QueryMsg {
|
||||||
pub mod query {
|
pub mod query {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::state::{RawMrenclave, RawNonce, Request};
|
use crate::state::{RawMrenclave, RawNonce, RawPublicKey, Request};
|
||||||
|
|
||||||
#[cw_serde]
|
#[cw_serde]
|
||||||
pub struct GetSgxStateResponse {
|
pub struct GetSgxStateResponse {
|
||||||
|
@ -47,6 +55,11 @@ pub mod query {
|
||||||
pub key_manager_mrenclave: RawMrenclave,
|
pub key_manager_mrenclave: RawMrenclave,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cw_serde]
|
||||||
|
pub struct GetEpochStateResponse {
|
||||||
|
pub epoch_key: RawPublicKey,
|
||||||
|
}
|
||||||
|
|
||||||
#[cw_serde]
|
#[cw_serde]
|
||||||
pub struct GetRequestsResponse {
|
pub struct GetRequestsResponse {
|
||||||
pub requests: Vec<(RawNonce, Request)>,
|
pub requests: Vec<(RawNonce, Request)>,
|
||||||
|
|
|
@ -26,6 +26,12 @@ pub struct SgxState {
|
||||||
pub tcb_info: RawTcbInfo,
|
pub tcb_info: RawTcbInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cw_serde]
|
||||||
|
pub struct EpochState {
|
||||||
|
pub epoch_key: RawPublicKey,
|
||||||
|
}
|
||||||
|
|
||||||
pub const STATE: Item<State> = Item::new("state");
|
pub const STATE: Item<State> = Item::new("state");
|
||||||
pub const REQUESTS: Item<Vec<(RawNonce, Request)>> = Item::new("requests");
|
pub const REQUESTS: Item<Vec<(RawNonce, Request)>> = Item::new("requests");
|
||||||
pub const SGX_STATE: Item<SgxState> = Item::new("sgxstate");
|
pub const SGX_STATE: Item<SgxState> = Item::new("sgx_state");
|
||||||
|
pub const EPOCH_STATE: Item<EpochState> = Item::new("epoch_state");
|
||||||
|
|
Loading…
Reference in a new issue