adapted to changes in signer lib
This commit is contained in:
parent
cd4bf0c99e
commit
50d5f9f387
@ -29,6 +29,15 @@ wit_bindgen::generate!({
|
||||
additional_derives: [PartialEq, serde::Deserialize, serde::Serialize, process_macros::SerdeJsonInto],
|
||||
});
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
enum SignerRequest {
|
||||
Sign,
|
||||
Verify { node: String, signature: Vec<u8> },
|
||||
}
|
||||
#[derive(Debug, Serialize, Deserialize, SerdeJsonInto)]
|
||||
struct SignResponse {
|
||||
signature: Vec<u8>,
|
||||
}
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
enum FrontendRequest {
|
||||
Sign,
|
||||
@ -37,22 +46,11 @@ enum FrontendRequest {
|
||||
Debug(String),
|
||||
}
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
enum SignerRequest {
|
||||
Sign(SignRequest),
|
||||
Verify { from: Address, data: SignResponse },
|
||||
}
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct SignRequest {
|
||||
struct LoginMessage {
|
||||
pub site: String,
|
||||
pub time: u64,
|
||||
pub nonce: Option<String>,
|
||||
}
|
||||
#[derive(Debug, Serialize, Deserialize, SerdeJsonInto)]
|
||||
struct SignResponse {
|
||||
pub body: SignRequest,
|
||||
pub message: Vec<u8>,
|
||||
pub signature: Vec<u8>,
|
||||
}
|
||||
const ICON: &str = include_str!("icon");
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
@ -94,6 +92,35 @@ impl VersionedState {
|
||||
}
|
||||
}
|
||||
|
||||
fn _signer_test(our: &Address) -> anyhow::Result<()> {
|
||||
let target = Address::new(our.node(), ("sign", "sign", "sys"));
|
||||
let login_message = LoginMessage {
|
||||
site: WEB2_URL.to_string(),
|
||||
nonce: Some(WEB2_LOGIN_NONCE.to_string()),
|
||||
time: get_now(),
|
||||
};
|
||||
let blob = serde_json::to_vec(&login_message)?;
|
||||
// Get the signature from login:sys:sys
|
||||
let res: SignResponse = Request::to(target.clone())
|
||||
.blob_bytes(blob.clone())
|
||||
.body(serde_json::to_vec(&SignerRequest::Sign)?)
|
||||
.send_and_await_response(10)??
|
||||
.body()
|
||||
.try_into()?;
|
||||
// Send signature to designated endpoint on Web2 app
|
||||
let body2 = SignerRequest::Verify {
|
||||
node: our.node().to_string(),
|
||||
signature: res.signature,
|
||||
};
|
||||
let verify_res = Request::to(target)
|
||||
.blob_bytes(blob)
|
||||
.body(serde_json::to_vec(&body2)?)
|
||||
.send_and_await_response(10)??;
|
||||
let is_good: bool = serde_json::from_slice(verify_res.body())?;
|
||||
kiprintln!("verify_res \n{:#?}", is_good);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
call_init!(initialize);
|
||||
fn initialize(our: Address) {
|
||||
init_logging(Level::DEBUG, Level::INFO, None, None, None).unwrap();
|
||||
@ -115,12 +142,6 @@ fn initialize(our: Address) {
|
||||
http_server
|
||||
.bind_ws_path("/", WsBindingConfig::default())
|
||||
.unwrap();
|
||||
// let http_config = HttpBindingConfig::default().secure_subdomain(true);
|
||||
|
||||
// http_server
|
||||
// .serve_ui("ui", vec!["/hypr-login"], http_config.clone())
|
||||
// .expect("Failed to serve UI");
|
||||
// http_server.secure_bind_http_path("/").unwrap();
|
||||
|
||||
main_loop(&our, &mut state, &mut http_server);
|
||||
}
|
||||
@ -207,15 +228,17 @@ fn handle_login_request(
|
||||
let request = serde_json::from_slice::<FrontendRequest>(request_bytes)?;
|
||||
match request {
|
||||
FrontendRequest::Sign => {
|
||||
let target = Address::new(our.node(), ("login", "login", "sys"));
|
||||
let lr = SignerRequest::Sign(SignRequest {
|
||||
let target = Address::new(our.node(), ("sign", "sign", "sys"));
|
||||
let body = LoginMessage {
|
||||
site: WEB2_URL.to_string(),
|
||||
nonce: Some(WEB2_LOGIN_NONCE.to_string()),
|
||||
time: get_now(),
|
||||
});
|
||||
};
|
||||
let body_bytes = serde_json::to_vec(&body)?;
|
||||
// Get the signature from login:sys:sys
|
||||
let res: SignResponse = Request::to(target)
|
||||
.body(serde_json::to_vec(&lr)?)
|
||||
.blob_bytes(body_bytes)
|
||||
.body(serde_json::to_vec(&SignerRequest::Sign)?)
|
||||
.send_and_await_response(10)??
|
||||
.body()
|
||||
.try_into()?;
|
||||
@ -255,7 +278,8 @@ fn attempt_login(
|
||||
let mut json_headers = HashMap::new();
|
||||
json_headers.insert("Content-type".to_string(), "application/json".to_string());
|
||||
let node = our.node();
|
||||
let message = signature_response.message;
|
||||
let blob = get_blob().ok_or(anyhow::anyhow!("no blob"))?;
|
||||
let message = blob.bytes();
|
||||
let signature = signature_response.signature;
|
||||
let json =
|
||||
serde_json::to_vec(&json!({"node":node, "message": message, "signature": signature}))?;
|
||||
|
@ -227,6 +227,7 @@ fn mother_script(prefix: &str) -> String {
|
||||
<script>
|
||||
const HYPERWARE_APP_PATH = '{0}';
|
||||
</script>
|
||||
<script src="./proxy.js" />
|
||||
"#,
|
||||
prefix
|
||||
);
|
||||
|
Binary file not shown.
Binary file not shown.
@ -8,14 +8,14 @@
|
||||
"homepage:homepage:sys",
|
||||
"http-server:distro:sys",
|
||||
"http-client:distro:sys",
|
||||
"login:login:sys",
|
||||
"sign:sign:sys",
|
||||
"vfs:distro:sys"
|
||||
],
|
||||
"grant_capabilities": [
|
||||
"homepage:homepage:sys",
|
||||
"http-server:distro:sys",
|
||||
"http-client:distro:sys",
|
||||
"login:login:sys",
|
||||
"sign:sign:sys",
|
||||
"vfs:distro:sys"
|
||||
],
|
||||
"public": false
|
||||
|
Loading…
x
Reference in New Issue
Block a user