From 346d3c6bcb6431a25ec692ec86bbbbc01a7a631d Mon Sep 17 00:00:00 2001 From: Yannick Guern Date: Sat, 10 Sep 2022 11:49:08 +0200 Subject: [PATCH 1/2] feat: Allow to derive public key from private key --- .gitignore | 1 + src/generate_token.rs | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/.gitignore b/.gitignore index ea8c4bf..2a0038a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +.idea \ No newline at end of file diff --git a/src/generate_token.rs b/src/generate_token.rs index 46d1fd2..8446c27 100644 --- a/src/generate_token.rs +++ b/src/generate_token.rs @@ -20,6 +20,7 @@ pub struct GenerateToken { pub enum GenerateTokenError { Parse(ParseErrors), Biscuit(error::Token), + KeyPairError(error::Format), } #[derive(Default, Debug, Clone, Serialize, Deserialize)] @@ -39,6 +40,14 @@ pub fn generate_keypair() -> JsValue { .unwrap() } +#[wasm_bindgen] +pub fn get_public_key(private_key: String) -> Result { + let private = PrivateKey::from_bytes_hex(private_key.as_str()) + .map_err(|err| JsValue::from_serde(&GenerateTokenError::KeyPairError(err)).unwrap())?; + let public = private.public(); + Ok(public.to_bytes_hex()) +} + #[wasm_bindgen] pub fn generate_token(query: &JsValue) -> Result { let query: GenerateToken = query.into_serde().unwrap(); From a0b396229507e4609b4d2a6b19142028655eb124 Mon Sep 17 00:00:00 2001 From: Yannick Guern Date: Fri, 24 Feb 2023 09:00:06 +0100 Subject: [PATCH 2/2] fix token deserialization --- Cargo.lock | 29 ++++++++++++++++++++++------- Cargo.toml | 2 +- src/execute_serialized.rs | 2 +- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dc6813a..24a8055 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,11 +25,11 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "biscuit-auth" -version = "3.0.0-alpha1" -source = "git+https://github.com/biscuit-auth/biscuit-rust?branch=master#f38d100da35605464fa4423f0cbd3c71463d5c39" +version = "3.0.0-alpha4" +source = "git+https://github.com/biscuit-auth/biscuit-rust?branch=main#b723c633f10f587f93b3fa9365e376b60859aa9c" dependencies = [ "base64", - "biscuit-parser", + "biscuit-parser 0.1.0-alpha4", "biscuit-quote", "ed25519-dalek", "getrandom", @@ -61,13 +61,28 @@ dependencies = [ "time", ] +[[package]] +name = "biscuit-parser" +version = "0.1.0-alpha4" +source = "git+https://github.com/biscuit-auth/biscuit-rust?branch=main#b723c633f10f587f93b3fa9365e376b60859aa9c" +dependencies = [ + "hex", + "nom", + "proc-macro2", + "quote", + "serde", + "thiserror", + "time", +] + [[package]] name = "biscuit-quote" -version = "0.2.0-alpha1" -source = "git+https://github.com/biscuit-auth/biscuit-rust?branch=master#f38d100da35605464fa4423f0cbd3c71463d5c39" +version = "0.2.0-alpha5" +source = "git+https://github.com/biscuit-auth/biscuit-rust?branch=main#b723c633f10f587f93b3fa9365e376b60859aa9c" dependencies = [ - "biscuit-parser", + "biscuit-parser 0.1.0-alpha4", "proc-macro-error", + "proc-macro2", "quote", "syn", ] @@ -78,7 +93,7 @@ version = "0.4.0-alpha1" dependencies = [ "base64", "biscuit-auth", - "biscuit-parser", + "biscuit-parser 0.1.0-alpha1", "console_error_panic_hook", "hex", "log", diff --git a/Cargo.toml b/Cargo.toml index e085216..48c6d00 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] wasm-bindgen = { version = "0.2.67", features = ["serde-serialize"] } -biscuit-auth = { git = "https://github.com/biscuit-auth/biscuit-rust", branch = "master", features = ["wasm", "serde-error"] } +biscuit-auth = { git = "https://github.com/biscuit-auth/biscuit-rust", branch = "main", features = ["wasm", "serde-error"] } biscuit-parser= { git = "https://github.com/biscuit-auth/biscuit-rust", branch = "master", features = ["serde-error"] } rand = "0.7" log = "0.4" diff --git a/src/execute_serialized.rs b/src/execute_serialized.rs index 5509600..a6d2220 100644 --- a/src/execute_serialized.rs +++ b/src/execute_serialized.rs @@ -71,7 +71,7 @@ pub fn execute_inner(query: BiscuitQuery) -> Result = public_key .clone() - .and_then(|pk| Biscuit::from_base64(&query.token, |_| pk)); + .and_then(|pk| Biscuit::from_base64(&query.token, pk)); let authorizer = parse_authorizer(&query.authorizer_code);