Skip to content

Commit

Permalink
Merge pull request #6 from Akanoa/add-generate-public-key-from-private
Browse files Browse the repository at this point in the history
Expose Public Key derivation
  • Loading branch information
Geal authored Feb 24, 2023
2 parents e094be4 + a0b3962 commit f56ef6a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
.idea
29 changes: 22 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/execute_serialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn execute_inner(query: BiscuitQuery) -> Result<BiscuitResult, ExecuteErrors

let deser: Result<Biscuit, error::Token> = 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);

Expand Down
9 changes: 9 additions & 0 deletions src/generate_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct GenerateToken {
pub enum GenerateTokenError {
Parse(ParseErrors),
Biscuit(error::Token),
KeyPairError(error::Format),
}

#[derive(Default, Debug, Clone, Serialize, Deserialize)]
Expand All @@ -39,6 +40,14 @@ pub fn generate_keypair() -> JsValue {
.unwrap()
}

#[wasm_bindgen]
pub fn get_public_key(private_key: String) -> Result<String, JsValue> {
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<String, JsValue> {
let query: GenerateToken = query.into_serde().unwrap();
Expand Down

0 comments on commit f56ef6a

Please sign in to comment.