Skip to content

Commit

Permalink
implement mock signing
Browse files Browse the repository at this point in the history
  • Loading branch information
borngraced committed Aug 29, 2024
1 parent 2fddf83 commit d632223
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion relay_rpc/src/rpc/params/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ pub enum ResponseParamsSuccess {
SessionRequest(bool),
SessionEvent(bool),
SessionDelete(bool),
SessionPing(bool),
SessionPing(bool)
}
impl_relay_protocol_metadata!(ResponseParamsSuccess, response);
impl_relay_protocol_helpers!(ResponseParamsSuccess);
Expand Down
1 change: 1 addition & 0 deletions sign_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ thiserror = "1.0"
url = "2.3"
x25519-dalek = { version = "2.0", features = ["static_secrets"] }
rand = { version = "0.8" }
ethers = "2.0.14"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1.22", features = [
Expand Down
39 changes: 34 additions & 5 deletions sign_api/examples/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const SUPPORTED_METHODS: &[&str] = &[
"eth_sign",
"personal_sign",
"eth_signTypedData",
"eth_signTypedData_v4"
];
const SUPPORTED_CHAINS: &[&str] = &["eip155:1", "eip155:5"];
const SUPPORTED_EVENTS: &[&str] = &["chainChanged", "accountsChanged"];
Expand Down Expand Up @@ -242,11 +243,29 @@ async fn process_inbound_request(
Params::SessionPropose(proposal) => {
process_proposal_request(context.clone(), proposal).await?
}
Params::SessionRequest(request) => {
println!("params: {}", request.request.params);
println!("method: {}", request.request.method);

todo!()
Params::SessionRequest(param) => {
// process sign tx request here
let message = param.request.params[0].as_str().unwrap();
let address = param.request.params[1].as_str().unwrap();

// For testing purposes, we'll create a mock signature
let mock_signature = mock_sign(address, message);
let context = context.lock().await;
let response = Response::Success(SuccessfulResponse {
id: request.id,
jsonrpc: JSON_RPC_VERSION_STR.into(),
result: serde_json::to_value(mock_signature).unwrap(),
});
let payload = serde_json::to_string(&Payload::from(response))?;
println!("\nSending response topic={topic} payload={payload}");
const IRN_RESPONSE_METADATA: IrnMetadata = IrnMetadata {
tag: 1109,
ttl: 300,
prompt: false,
};
let _ = context.publish_payload(topic.clone(), IRN_RESPONSE_METADATA, &payload).await;

return Ok(());
}
Params::SessionDelete(params) => {
session_delete_cleanup_required = Some(topic.clone());
Expand All @@ -269,6 +288,16 @@ async fn process_inbound_request(
Ok(())
}

fn mock_sign(address: &str, message: &str) -> String {
// Remove '0x' prefix if present
let message = message.strip_prefix("0x").unwrap_or(message);

// In a real implementation, we would sign the message here.
// For mocking purposes, we'll create a deterministic "signature" based on the inputs.
let mock_signature = ethers::utils::keccak256(format!("{:?}{}", address, message).as_bytes());
format!("0x{}", hex::encode(mock_signature))
}

fn process_inbound_response(response: Response) -> Result<()> {
match response {
Response::Success(value) => {
Expand Down

0 comments on commit d632223

Please sign in to comment.