From a01e7ccc51a678ad96eb5c38f00d167c8b811aae Mon Sep 17 00:00:00 2001 From: Doug Anderson444 Date: Sat, 29 Jun 2024 20:35:12 -0300 Subject: [PATCH] emit the offer --- crates/delano-wit-ui/src/api.rs | 15 +++++++++------ crates/delano-wit-ui/src/bindings.rs | 2 +- crates/delano-wit-ui/wit/world.wit | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/crates/delano-wit-ui/src/api.rs b/crates/delano-wit-ui/src/api.rs index 95b2b18..4067984 100644 --- a/crates/delano-wit-ui/src/api.rs +++ b/crates/delano-wit-ui/src/api.rs @@ -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::{ @@ -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 @@ -336,13 +341,11 @@ impl Object for State { } impl From 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(), diff --git a/crates/delano-wit-ui/src/bindings.rs b/crates/delano-wit-ui/src/bindings.rs index 91952d9..cad23d5 100644 --- a/crates/delano-wit-ui/src/bindings.rs +++ b/crates/delano-wit-ui/src/bindings.rs @@ -3585,7 +3585,7 @@ pub mod delano { pub struct Everything { pub page: Option, /// issue: option, - /// 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 { diff --git a/crates/delano-wit-ui/wit/world.wit b/crates/delano-wit-ui/wit/world.wit index c6f2d27..4e12d5f 100644 --- a/crates/delano-wit-ui/wit/world.wit +++ b/crates/delano-wit-ui/wit/world.wit @@ -12,7 +12,7 @@ interface context-types { record everything { page: option, // issue: option, - /// 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, }