Skip to content

Commit

Permalink
emit the offer
Browse files Browse the repository at this point in the history
  • Loading branch information
DougAnderson444 committed Jun 29, 2024
1 parent e476d25 commit a01e7cc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions crates/delano-wit-ui/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use self::{

use super::*;

use base64ct::{Base64UrlUnpadded, Encoding};
use chrono::prelude::*;
use delano_events::{Context, Events, Provables, Publishables, SubscribeTopic};
use delano_keys::{
Expand Down Expand Up @@ -149,6 +148,12 @@ impl State {
hints,
};

// serde_json serialize and emit offer
let serialized = serde_json::to_string(&offer)
.map_err(|e| format!("Serialize offer failed: {}", e))?;

wurbo_in::emit(&serialized);

// We also want to track this offer in the history
// So we can 1) Look up the key for values, and
// 2) Remind the person with hints/attrs if needed
Expand Down Expand Up @@ -336,13 +341,11 @@ impl Object for State {
}

impl From<String> for State {
fn from(base64: String) -> Self {
// Default of Loaded is None
let decoded = Base64UrlUnpadded::decode_vec(&base64).unwrap_or_default();
let loaded = serde_json::from_slice(&decoded).unwrap_or_default();
fn from(data: String) -> Self {
let loaded: Loaded = serde_json::from_str(&data).unwrap_or_default();
Self {
history: Default::default(),
loaded: serde_json::from_slice(&decoded).unwrap_or_default(),
loaded: loaded.clone(),
builder: CredentialStruct::from(&loaded),
offer: Default::default(),
proof: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion crates/delano-wit-ui/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3585,7 +3585,7 @@ pub mod delano {
pub struct Everything {
pub page: Option<Page>,
/// issue: option<issuer>,
/// The base64URLsafe unpadded encoded JSON string of the loadable data (offer or proof)
/// The JSON string of the loadable data (offer or proof)
pub load: Option<_rt::String>,
}
impl ::core::fmt::Debug for Everything {
Expand Down
2 changes: 1 addition & 1 deletion crates/delano-wit-ui/wit/world.wit
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface context-types {
record everything {
page: option<page>,
// issue: option<issuer>,
/// The base64URLsafe unpadded encoded JSON string of the loadable data (offer or proof)
/// The JSON string of the loadable data (offer or proof)
load: option<string>,
}

Expand Down

0 comments on commit a01e7cc

Please sign in to comment.