Skip to content

Commit

Permalink
uniffi: migrate to indy vdr (#1030)
Browse files Browse the repository at this point in the history
  • Loading branch information
swaptr authored Oct 31, 2023
1 parent c9ffebd commit 63590d1
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 35 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

16 changes: 12 additions & 4 deletions aries_vcx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ doctest = false
[features]
# Feature flag to include the 'modular library' dependencies (vdrtools alternatives; indy-vdr, indy-credx)
credx = ["aries_vcx_core/credx", "test_utils/vdrtools_wallet"]
vdr_proxy_ledger = ["aries_vcx_core/vdr_proxy_ledger", "aries_vcx_core/vdrtools_wallet", "test_utils/vdr_proxy_ledger", "credx"]
vdrtools_wallet = ["aries_vcx_core/vdrtools_wallet", "test_utils/vdrtools_wallet"]
vdr_proxy_ledger = [
"aries_vcx_core/vdr_proxy_ledger",
"aries_vcx_core/vdrtools_wallet",
"test_utils/vdr_proxy_ledger",
"credx",
]
vdrtools_wallet = [
"aries_vcx_core/vdrtools_wallet",
"test_utils/vdrtools_wallet",
]

# Feature for allowing legacy proof verification
legacy_proof = ["aries_vcx_core/legacy_proof"]

[dependencies]
agency_client = { path = "../agency_client" }
messages = { path = "../messages" }
messages = { path = "../messages" }
diddoc_legacy = { path = "../diddoc_legacy" }
aries_vcx_core = { path = "../aries_vcx_core" }
aries_vcx_core = { path = "../aries_vcx_core" }
shared_vcx = { path = "../shared_vcx" }
bs58 = "0.5.0"
async-trait = "0.1.53"
Expand Down
16 changes: 8 additions & 8 deletions tools/libvcx_logger/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{env, io::Write, sync::Once};

#[cfg(target_os = "android")]
use android_logger::Filter;
use android_logger::Config;
use aries_vcx_core::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResult};
use chrono::{
format::{DelayedFormat, StrftimeItems},
Expand Down Expand Up @@ -66,14 +66,14 @@ impl LibvcxDefaultLogger {
#[cfg(target_os = "android")]
let log_filter = match pattern.as_ref() {
Some(val) => match val.to_lowercase().as_ref() {
"error" => Filter::default().with_min_level(log::Level::Error),
"warn" => Filter::default().with_min_level(log::Level::Warn),
"info" => Filter::default().with_min_level(log::Level::Info),
"debug" => Filter::default().with_min_level(log::Level::Debug),
"trace" => Filter::default().with_min_level(log::Level::Trace),
_ => Filter::default().with_min_level(log::Level::Error),
"error" => Config::default().with_max_level(log::LevelFilter::Error),
"warn" => Config::default().with_max_level(log::LevelFilter::Warn),
"info" => Config::default().with_max_level(log::LevelFilter::Info),
"debug" => Config::default().with_max_level(log::LevelFilter::Debug),
"trace" => Config::default().with_max_level(log::LevelFilter::Trace),
_ => Config::default().with_max_level(log::LevelFilter::Error),
},
None => Filter::default().with_min_level(log::Level::Error),
None => Config::default().with_max_level(log::LevelFilter::Error),
};

//Set logging to off when deploying production android app.
Expand Down
8 changes: 5 additions & 3 deletions uniffi_aries_vcx/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ path = "uniffi-bindgen.rs"

[dependencies]
uniffi = { version = "0.23.0", features = ["cli"] }
aries-vcx = { path = "../../aries_vcx" }
test_utils = {path = "../../tools/test_utils" }
tokio = { version = "1.24.1" }
aries-vcx = { path = "../../aries_vcx", features = [
"vdrtools_wallet",
"credx",
] }
tokio = { version = "1.24.1", features = ["rt-multi-thread"] }
once_cell = "1.17.0"
thiserror = "1.0.38"
serde_json = "1.0.91"
Expand Down
35 changes: 22 additions & 13 deletions uniffi_aries_vcx/core/src/core/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@ use std::sync::Arc;
use aries_vcx::{
aries_vcx_core::{
anoncreds::credx_anoncreds::IndyCredxAnonCreds,
ledger::base_ledger::TxnAuthrAgrmtOptions,
ledger::{
base_ledger::TxnAuthrAgrmtOptions,
indy_vdr_ledger::{indyvdr_build_ledger_read, IndyVdrLedgerRead},
request_submitter::vdr_ledger::{IndyVdrLedgerPool, IndyVdrSubmitter},
response_cacher::in_memory::{InMemoryResponseCacher, InMemoryResponseCacherConfig},
},
wallet::indy::{wallet::create_and_open_wallet, IndySdkWallet, WalletConfig},
PoolConfig,
},
errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult},
};
use test_utils::mockdata::mock_ledger::MockLedger;

use crate::{errors::error::VcxUniFFIResult, runtime::block_on};

#[derive(Debug)]
pub struct UniffiProfile {
wallet: IndySdkWallet,
anoncreds: IndyCredxAnonCreds,
ledger_read: MockLedger,
ledger_write: MockLedger,
ledger_read: IndyVdrLedgerRead<IndyVdrSubmitter, InMemoryResponseCacher>,
}

impl UniffiProfile {
pub fn ledger_read(&self) -> &MockLedger {
pub fn ledger_read(&self) -> &IndyVdrLedgerRead<IndyVdrSubmitter, InMemoryResponseCacher> {
&self.ledger_read
}

pub fn ledger_write(&self) -> &MockLedger {
&self.ledger_write
}

pub fn anoncreds(&self) -> &IndyCredxAnonCreds {
&self.anoncreds
}
Expand All @@ -49,16 +49,25 @@ pub struct ProfileHolder {
pub(crate) inner: UniffiProfile,
}

pub fn new_indy_profile(wallet_config: WalletConfig) -> VcxUniFFIResult<Arc<ProfileHolder>> {
pub fn new_indy_profile(
wallet_config: WalletConfig,
genesis_file_path: String,
) -> VcxUniFFIResult<Arc<ProfileHolder>> {
block_on(async {
let wh = create_and_open_wallet(&wallet_config).await?;

let indy_vdr_config = PoolConfig::default();
let cache_config = InMemoryResponseCacherConfig::builder()
.ttl(std::time::Duration::from_secs(60))
.capacity(1000)?
.build();
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,
ledger_read: MockLedger,
ledger_write: MockLedger,
ledger_read,
};

Ok(Arc::new(ProfileHolder { inner: profile }))
Expand Down
2 changes: 1 addition & 1 deletion uniffi_aries_vcx/core/src/vcx.udl
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ enum VcxUniFFIError {

namespace vcx {
[Throws=VcxUniFFIError]
ProfileHolder new_indy_profile(WalletConfig wallet_config);
ProfileHolder new_indy_profile(WalletConfig wallet_config, string genesis_file_path);

[Throws=VcxUniFFIError]
Connection create_inviter(ProfileHolder profile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class AppDemoController : ViewModel() {
rekeyDerivationMethod = null
)

suspend fun setupProfile() {
suspend fun setupProfile(genesisFilePath: String) {
withContext(Dispatchers.IO) {
val newProfile = newIndyProfile(walletConfig)
val newProfile = newIndyProfile(walletConfig, genesisFilePath)
profile = newProfile
connection = createInvitee(newProfile)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.hyperledger.ariesvcx

import android.util.Log
import android.widget.Toast
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand All @@ -18,6 +17,10 @@ import androidx.navigation.NavHostController
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.hyperledger.ariesvcx.utils.prepareGenesisFile
import java.io.BufferedWriter
import java.io.File
import java.io.FileWriter


@Composable
Expand All @@ -30,7 +33,7 @@ fun HomeScreen(

val scope = rememberCoroutineScope()
val context = LocalContext.current

val file = prepareGenesisFile(context)
demoController.subscribeToConnectionComplete { newConn ->
scope.launch(Dispatchers.Main) {
Toast.makeText(
Expand All @@ -50,7 +53,7 @@ fun HomeScreen(
enabled = (!demoState.profileReady),
onClick = {
scope.launch {
demoController.setupProfile()
demoController.setupProfile(file.absolutePath)
withContext(Dispatchers.Main) {
Toast.makeText(
context,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.hyperledger.ariesvcx.utils

import android.content.Context
import android.util.Log
import org.hyperledger.ariesvcx.R
import java.io.BufferedWriter
import java.io.File
import java.io.FileWriter

fun prepareGenesisFile(context: Context): File {
val file = File(context.filesDir, "genesis")
if (!file.exists()) {
val transactions = context.resources.openRawResource(R.raw.transactions).bufferedReader()
.use { it.readText() }
val bufferedWriter = BufferedWriter(FileWriter(file))
bufferedWriter.write(transactions)
bufferedWriter.close()
Log.d("GENESIS", "transactions written")
}
return file
}
4 changes: 4 additions & 0 deletions uniffi_aries_vcx/demo/app/src/main/res/raw/transactions
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node1","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","blskey_pop":"RahHYiCvoNCtPTrVtP7nMC5eTYrsUA8WjXbdhNc8debh1agE9bGiJxWBXYNFbnJXoXhWFMvyqhqhRoq737YQemH5ik9oL7R4NTTCz2LEZhkgLJzB3QRQqJyBNyv7acbdHrAT8nQ9UkLbaVL9NBpnWXBTw4LEMePaSHEw66RzPNdAX1","client_ip":"127.0.0.1","client_port":9702,"node_ip":"127.0.0.1","node_port":9701,"services":["VALIDATOR"]},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"},"metadata":{"from":"Th7MpTaRZVRYnPiabds81Y"},"type":"0"},"txnMetadata":{"seqNo":1,"txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"},"ver":"1"}
{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node2","blskey":"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk","blskey_pop":"Qr658mWZ2YC8JXGXwMDQTzuZCWF7NK9EwxphGmcBvCh6ybUuLxbG65nsX4JvD4SPNtkJ2w9ug1yLTj6fgmuDg41TgECXjLCij3RMsV8CwewBVgVN67wsA45DFWvqvLtu4rjNnE9JbdFTc1Z4WCPA3Xan44K1HoHAq9EVeaRYs8zoF5","client_ip":"127.0.0.1","client_port":9704,"node_ip":"127.0.0.1","node_port":9703,"services":["VALIDATOR"]},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"},"metadata":{"from":"EbP4aYNeTHL6q385GuVpRV"},"type":"0"},"txnMetadata":{"seqNo":2,"txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"},"ver":"1"}
{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node3","blskey":"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5","blskey_pop":"QwDeb2CkNSx6r8QC8vGQK3GRv7Yndn84TGNijX8YXHPiagXajyfTjoR87rXUu4G4QLk2cF8NNyqWiYMus1623dELWwx57rLCFqGh7N4ZRbGDRP4fnVcaKg1BcUxQ866Ven4gw8y4N56S5HzxXNBZtLYmhGHvDtk6PFkFwCvxYrNYjh","client_ip":"127.0.0.1","client_port":9706,"node_ip":"127.0.0.1","node_port":9705,"services":["VALIDATOR"]},"dest":"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya"},"metadata":{"from":"4cU41vWW82ArfxJxHkzXPG"},"type":"0"},"txnMetadata":{"seqNo":3,"txnId":"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4"},"ver":"1"}
{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node4","blskey":"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw","blskey_pop":"RPLagxaR5xdimFzwmzYnz4ZhWtYQEj8iR5ZU53T2gitPCyCHQneUn2Huc4oeLd2B2HzkGnjAff4hWTJT6C7qHYB1Mv2wU5iHHGFWkhnTX9WsEAbunJCV2qcaXScKj4tTfvdDKfLiVuU2av6hbsMztirRze7LvYBkRHV3tGwyCptsrP","client_ip":"127.0.0.1","client_port":9708,"node_ip":"127.0.0.1","node_port":9707,"services":["VALIDATOR"]},"dest":"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA"},"metadata":{"from":"TWwCRQRZ2ZHMJFn9TzLp7W"},"type":"0"},"txnMetadata":{"seqNo":4,"txnId":"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008"},"ver":"1"}

0 comments on commit 63590d1

Please sign in to comment.