Be consistent with MTCS TEE request
This commit is contained in:
parent
efb9aae66b
commit
973700e6f4
5 changed files with 84 additions and 26 deletions
|
@ -48,7 +48,8 @@ cosmwasm-std = { version = "1.5.0", features = [
|
||||||
] }
|
] }
|
||||||
cw-storage-plus = "1.1.0"
|
cw-storage-plus = "1.1.0"
|
||||||
cw2 = "1.1.1"
|
cw2 = "1.1.1"
|
||||||
libsecp256k1 = { version = "0.7.1", default-features = false }
|
hex = { version = "0.4.3", default-features = false }
|
||||||
|
k256 = { version = "0.13.2", default-features = false, features = ["ecdsa"] }
|
||||||
schemars = "0.8.15"
|
schemars = "0.8.15"
|
||||||
serde = { version = "1.0.189", default-features = false, features = ["derive"] }
|
serde = { version = "1.0.189", default-features = false, features = ["derive"] }
|
||||||
thiserror = { version = "1.0.49" }
|
thiserror = { version = "1.0.49" }
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
use cosmwasm_std::{entry_point, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};
|
use cosmwasm_std::{
|
||||||
|
entry_point, to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult,
|
||||||
|
};
|
||||||
use cw2::set_contract_version;
|
use cw2::set_contract_version;
|
||||||
|
|
||||||
use crate::error::ContractError;
|
use crate::error::ContractError;
|
||||||
|
@ -37,45 +39,64 @@ pub fn execute(
|
||||||
) -> Result<Response, ContractError> {
|
) -> Result<Response, ContractError> {
|
||||||
match msg {
|
match msg {
|
||||||
ExecuteMsg::JoinComputeNode(JoinComputeNodeMsg {
|
ExecuteMsg::JoinComputeNode(JoinComputeNodeMsg {
|
||||||
compute_node_pub_key,
|
io_exchange_key,
|
||||||
|
address,
|
||||||
nonce,
|
nonce,
|
||||||
}) => execute::enqueue_join_request(deps, compute_node_pub_key, nonce),
|
}) => execute::enqueue_join_request(deps, io_exchange_key, address, nonce),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod execute {
|
pub mod execute {
|
||||||
use cosmwasm_std::{DepsMut, Response};
|
use cosmwasm_std::{DepsMut, Response};
|
||||||
use libsecp256k1::PublicKey;
|
use k256::ecdsa::VerifyingKey;
|
||||||
|
|
||||||
use crate::state::Nonce;
|
use crate::state::{RawAddress, RawNonce, RawPublicKey};
|
||||||
use crate::state::{Request, REQUESTS};
|
use crate::state::{Request, REQUESTS};
|
||||||
use crate::ContractError;
|
use crate::ContractError;
|
||||||
|
|
||||||
pub fn enqueue_join_request(
|
pub fn enqueue_join_request(
|
||||||
deps: DepsMut,
|
deps: DepsMut,
|
||||||
compute_node_pub_key: String,
|
io_exchange_key: RawPublicKey,
|
||||||
nonce: Nonce,
|
address: RawAddress,
|
||||||
|
nonce: RawNonce,
|
||||||
) -> Result<Response, ContractError> {
|
) -> Result<Response, ContractError> {
|
||||||
let _ = PublicKey::parse_slice(compute_node_pub_key.as_bytes(), None)?;
|
let _ = VerifyingKey::from_sec1_bytes(&hex::decode(&io_exchange_key)?)?;
|
||||||
|
let _ = deps.api.addr_validate(&address)?;
|
||||||
|
let _ = hex::decode(&nonce);
|
||||||
|
|
||||||
REQUESTS.save(
|
REQUESTS.save(
|
||||||
deps.storage,
|
deps.storage,
|
||||||
&nonce,
|
&nonce,
|
||||||
&Request::JoinComputeNode(compute_node_pub_key.clone()),
|
&Request::JoinComputeNode((io_exchange_key.clone(), address)),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(Response::new()
|
Ok(Response::new()
|
||||||
.add_attribute("action", "enqueue_request")
|
.add_attribute("action", "enqueue_request")
|
||||||
.add_attribute("compute_node_pub_key", compute_node_pub_key))
|
.add_attribute("io_exchange_key", io_exchange_key))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(not(feature = "library"), entry_point)]
|
#[cfg_attr(not(feature = "library"), entry_point)]
|
||||||
pub fn query(_deps: Deps, _env: Env, _msg: QueryMsg) -> StdResult<Binary> {
|
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
|
||||||
todo!()
|
match msg {
|
||||||
|
QueryMsg::GetRequests {} => to_json_binary(&query::get_requests(deps)?),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod query {}
|
pub mod query {
|
||||||
|
use cosmwasm_std::{Deps, Order, StdResult};
|
||||||
|
|
||||||
|
use crate::msg::query::GetRequestsResponse;
|
||||||
|
use crate::state::{RawNonce, Request, REQUESTS};
|
||||||
|
|
||||||
|
pub fn get_requests(deps: Deps) -> StdResult<GetRequestsResponse> {
|
||||||
|
Ok(GetRequestsResponse {
|
||||||
|
requests: REQUESTS
|
||||||
|
.range(deps.storage, None, None, Order::Ascending)
|
||||||
|
.collect::<StdResult<Vec<(RawNonce, Request)>>>()?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {}
|
mod tests {}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use cosmwasm_std::StdError;
|
use cosmwasm_std::StdError;
|
||||||
use libsecp256k1::Error as SecpError;
|
use hex::FromHexError;
|
||||||
|
use k256::ecdsa::Error as K256Error;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
|
@ -11,11 +12,32 @@ pub enum ContractError {
|
||||||
Unauthorized,
|
Unauthorized,
|
||||||
|
|
||||||
#[error("Invalid pubkey")]
|
#[error("Invalid pubkey")]
|
||||||
InvalidPubKey(SecpError),
|
InvalidPubKey(PublicKeyError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<SecpError> for ContractError {
|
#[derive(Error, Debug)]
|
||||||
fn from(e: SecpError) -> Self {
|
pub enum PublicKeyError {
|
||||||
|
#[error("Not Secp256K1")]
|
||||||
|
K256(K256Error),
|
||||||
|
#[error("Invalid hex")]
|
||||||
|
Hex(FromHexError),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Into<PublicKeyError>> From<T> for ContractError {
|
||||||
|
fn from(e: T) -> Self {
|
||||||
|
let e = e.into();
|
||||||
Self::InvalidPubKey(e)
|
Self::InvalidPubKey(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<K256Error> for PublicKeyError {
|
||||||
|
fn from(e: K256Error) -> Self {
|
||||||
|
PublicKeyError::K256(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<FromHexError> for PublicKeyError {
|
||||||
|
fn from(e: FromHexError) -> Self {
|
||||||
|
PublicKeyError::Hex(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -11,15 +11,28 @@ pub enum ExecuteMsg {
|
||||||
pub mod execute {
|
pub mod execute {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::state::Nonce;
|
|
||||||
|
|
||||||
#[cw_serde]
|
#[cw_serde]
|
||||||
pub struct JoinComputeNodeMsg {
|
pub struct JoinComputeNodeMsg {
|
||||||
pub compute_node_pub_key: String,
|
pub io_exchange_key: String,
|
||||||
pub nonce: Nonce,
|
pub address: String,
|
||||||
|
pub nonce: String,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cw_serde]
|
#[cw_serde]
|
||||||
#[derive(QueryResponses)]
|
#[derive(QueryResponses)]
|
||||||
pub enum QueryMsg {}
|
pub enum QueryMsg {
|
||||||
|
#[returns(query::GetRequestsResponse)]
|
||||||
|
GetRequests {},
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod query {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use crate::state::{RawNonce, Request};
|
||||||
|
|
||||||
|
#[cw_serde]
|
||||||
|
pub struct GetRequestsResponse {
|
||||||
|
pub requests: Vec<(RawNonce, Request)>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use cosmwasm_schema::cw_serde;
|
use cosmwasm_schema::cw_serde;
|
||||||
use cw_storage_plus::{Item, Map};
|
use cw_storage_plus::{Item, Map};
|
||||||
|
|
||||||
pub type Nonce = [u8; 32];
|
pub type RawNonce = String;
|
||||||
pub type RawPublicKey = String;
|
pub type RawPublicKey = String;
|
||||||
|
pub type RawAddress = String;
|
||||||
|
|
||||||
#[cw_serde]
|
#[cw_serde]
|
||||||
pub struct State {
|
pub struct State {
|
||||||
|
@ -11,8 +12,8 @@ pub struct State {
|
||||||
|
|
||||||
#[cw_serde]
|
#[cw_serde]
|
||||||
pub enum Request {
|
pub enum Request {
|
||||||
JoinComputeNode(RawPublicKey),
|
JoinComputeNode((RawPublicKey, RawAddress)),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const STATE: Item<State> = Item::new("state");
|
pub const STATE: Item<State> = Item::new("state");
|
||||||
pub const REQUESTS: Map<&Nonce, Request> = Map::new("requests");
|
pub const REQUESTS: Map<&RawNonce, Request> = Map::new("requests");
|
||||||
|
|
Loading…
Reference in a new issue