Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: jwt_authorization_secret added to secret generation example #35

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion affinidi-messaging-mediator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ To build and run this project, you need to set up the following:
cargo run --example generate_secrets
```

This will generate `affinidi-messaging-mediator/conf/secrets.json-generated` file containing a did:peer together with the pair of keys for verification and encryption. Use the generated did:peer as a value for `<MEDIATOR_DID>` placeholder in following commands as well as in [affinidi-messaging-sdk - Examples](../affinidi-messaging-sdk#examples).
This will generate `affinidi-messaging-mediator/conf/secrets.json-generated` file containing a did:peer together with the pair of keys for verification and encryption and `jwt_authorization_secret` you shall use for `jwt_authorization_secret` value in `mediator.toml`.
Use the generated did:peer as a value for `<MEDIATOR_DID>` placeholder in following commands as well as in [affinidi-messaging-sdk - Examples](../affinidi-messaging-sdk#examples).

4. Save the generated `secrets.json-generated` file as `affinidi-messaging-mediator/conf/secrets.json`.

Expand Down
12 changes: 11 additions & 1 deletion affinidi-messaging-mediator/examples/generate_secrets.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use std::fs::File;
use std::io::Write;

use base64::prelude::{Engine as _, BASE64_URL_SAFE_NO_PAD};

use did_peer::{
DIDPeer, DIDPeerCreateKeys, DIDPeerKeys, DIDPeerService, PeerServiceEndPoint,
PeerServiceEndPointLong,
};
use ring::signature::Ed25519KeyPair;
use serde_json::json;
use ssi::{
dids::DIDKey,
Expand Down Expand Up @@ -110,7 +113,7 @@ async fn main() -> std::io::Result<()> {
let (did_peer, _) =
DIDPeer::create_peer_did(&keys, Some(&services)).expect("Failed to create did:peer");

println!("{}", did_peer);
println!("did = {}", did_peer);

let secrets_json = json!([
{
Expand Down Expand Up @@ -141,5 +144,12 @@ async fn main() -> std::io::Result<()> {
let mut file = File::create("./conf/secrets.json-generated")?;
file.write_all(json_string.as_bytes())?;

// Create jwt_authorization_secret
let doc = Ed25519KeyPair::generate_pkcs8(&ring::rand::SystemRandom::new()).unwrap();
println!(
"jwt_authorization_secret = {}",
&BASE64_URL_SAFE_NO_PAD.encode(doc.as_ref())
);

Ok(())
}
Loading