Skip to content

Commit

Permalink
fix offer and credential holding issues
Browse files Browse the repository at this point in the history
Signed-off-by: Swapnil Tripathi <[email protected]>
  • Loading branch information
swaptr committed Nov 13, 2023
1 parent 05ea098 commit 5dc2390
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 37 deletions.
12 changes: 10 additions & 2 deletions uniffi_aries_vcx/core/src/core/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use aries_vcx::{
aries_vcx_core::{
anoncreds::credx_anoncreds::IndyCredxAnonCreds,
anoncreds::{base_anoncreds::BaseAnonCreds, credx_anoncreds::IndyCredxAnonCreds},
ledger::{
base_ledger::TxnAuthrAgrmtOptions,
indy_vdr_ledger::{indyvdr_build_ledger_read, IndyVdrLedgerRead},
Expand Down Expand Up @@ -55,6 +55,15 @@ pub fn new_indy_profile(
) -> VcxUniFFIResult<Arc<ProfileHolder>> {
block_on(async {
let wh = create_and_open_wallet(&wallet_config).await?;
let wallet = IndySdkWallet::new(wh);

let anoncreds = IndyCredxAnonCreds;

anoncreds
.prover_create_link_secret(&wallet, "main")
.await
.ok();

let indy_vdr_config = PoolConfig::default();
let cache_config = InMemoryResponseCacherConfig::builder()
.ttl(std::time::Duration::from_secs(60))
Expand All @@ -63,7 +72,6 @@ pub fn new_indy_profile(
let ledger_pool = IndyVdrLedgerPool::new(genesis_file_path, indy_vdr_config, vec![])?;
let request_submitter = IndyVdrSubmitter::new(ledger_pool);
let ledger_read = indyvdr_build_ledger_read(request_submitter.clone(), cache_config)?;
let wallet = IndySdkWallet::new(wh);
let profile = UniffiProfile {
anoncreds: IndyCredxAnonCreds,
wallet,
Expand Down
8 changes: 4 additions & 4 deletions uniffi_aries_vcx/core/src/handlers/holder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::{Arc, Mutex};

use aries_vcx::{
handlers::issuance::holder::Holder as VcxHolder,
handlers::issuance::holder::Holder as VcxHolder, messages::AriesMessage,
protocols::issuance::holder::state_machine::HolderState as VcxHolderState,
};

Expand Down Expand Up @@ -97,9 +97,9 @@ impl Holder {
pub fn get_msg_credential_request(&self) -> VcxUniFFIResult<String> {
let handler = self.handler.lock()?;

Ok(serde_json::to_string(
&handler.clone().get_msg_credential_request()?,
)?)
Ok(serde_json::to_string(&AriesMessage::from(
handler.clone().get_msg_credential_request()?,
))?)
}

pub fn decline_offer(&self, comment: Option<String>) -> VcxUniFFIResult<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,12 @@ class AppDemoController : ViewModel() {
}

fun processOfferRequest() {
holder?.prepareCredentialRequest(profile!!, "4xE68b6S5VRFrKMMG1U95M")
val message = holder?.getMsgCredentialRequest()
connection?.sendMessage(profile!!, message!!)

_state.update { it.copy(offerReceived = false) }
viewModelScope.launch {
holder?.prepareCredentialRequest(profile!!, "4xE68b6S5VRFrKMMG1U95M")
Log.d("HOLDER", "processOfferRequest: ${holder?.getState()}")
val message = holder?.getMsgCredentialRequest()
connection?.sendMessage(profile!!, message!!)
}
}

suspend fun awaitCredentialPolling() {
Expand All @@ -152,13 +153,12 @@ class AppDemoController : ViewModel() {
if (holder == null) {
Log.d("OFFER", "awaitCredentialPolling: received offer")
holder = createFromOffer("", unpackedMessage.message)
_state.update { it.copy(offerReceived = true) }
onOfferReceived.invoke()
} else {
Log.d("CREDENTIAL", "awaitCredentialPolling: received credential")
holder?.processCredential(profile!!, unpackedMessage.message)
}

_state.update { it.copy(offerReceived = true) }
onOfferReceived.invoke()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.hyperledger.ariesvcx

// Set your public IP address here, this endpoint will be used while communicating with the peer(agent).
const val BASE_RELAY_ENDPOINT = "https://7365-223-236-178-57.ngrok-free.app";
const val BASE_RELAY_ENDPOINT = "https://0ecc-223-236-178-57.ngrok-free.app";
const val RELAY_USER_ID = "demo-user-1";
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,27 @@ fun HolderScreen(
val scope = rememberCoroutineScope()
val context = LocalContext.current

var credentialOffer by remember {
mutableStateOf<String?>(null)
LaunchedEffect(Unit) {
demoController.awaitCredentialPolling()
}

credentialOffer?.let {
LaunchedEffect(Unit) {
demoController.subscribeToShowDialog {
scope.launch(Dispatchers.Main) {
Toast.makeText(
context,
"New Offer Received",
Toast.LENGTH_LONG
).show()
}
}
}

if (demoState.offerReceived) {
AlertDialog(
onDismissRequest = { credentialOffer = null },
onDismissRequest = { },
title = { Text("Accept this invitation?") },
text = { Text(credentialOffer!!) },
text = { Text(demoController.getHolder()?.getAttributes()!!) },
confirmButton = {
TextButton(onClick = {
scope.launch {
Expand All @@ -55,29 +67,13 @@ fun HolderScreen(
}
},
dismissButton = {
TextButton(onClick = { credentialOffer = null }) {
TextButton(onClick = { }) {
Text("Cancel")
}
},
)
}

LaunchedEffect(Unit) {
demoController.awaitCredentialPolling()
}

LaunchedEffect(Unit) {
demoController.subscribeToShowDialog {
scope.launch(Dispatchers.Main) {
Toast.makeText(
context,
"New Offer Received",
Toast.LENGTH_LONG
).show()
}
}
}

Column(
modifier = Modifier
.fillMaxSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ fun ScanScreen(

scannedQRCodeText?.let { text ->
val encoded = Uri.parse(text)?.getQueryParameter("c_i")
if (encoded == null) {
scannedQRCodeText = null
return@let
}
val decoded = String(Base64.decode(encoded, Base64.DEFAULT))

AlertDialog(
Expand Down

0 comments on commit 5dc2390

Please sign in to comment.