Skip to content

Commit

Permalink
Sync up
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Stas <[email protected]>
  • Loading branch information
Patrik-Stas committed Dec 21, 2022
1 parent 37ded58 commit b2213f7
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 66 deletions.
12 changes: 3 additions & 9 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion wrappers/node-napi-rs/api-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ doctest = false
libvcx = { path = "../../../libvcx" }
log = "0.4.16"
napi = { version = "=2.9.1", default-features = false, features = [ "async" ] }
napi-derive = { version = "=2.9.1" }
napi-derive = { version = "=2.9.3" }

[build-dependencies]
napi-build = "2.0.1"
43 changes: 22 additions & 21 deletions wrappers/node-napi-rs/api-node/src/api/mediated_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use napi::bindgen_prelude::Buffer;
use napi_derive::napi;

use vcx::api_lib::global::wallet::get_main_wallet_handle;
use vcx::aries_vcx::error::{VcxError, VcxErrorKind};
use vcx::aries_vcx::indy;
use vcx::api_lib::api_handle::mediated_connection::{self, parse_status_codes};
use vcx::api_lib::errors::error::{LibvcxError, LibvcxErrorKind};
use vcx::aries_vcx::protocols::connection::pairwise_info::PairwiseInfo;
use vcx::serde_json;

Expand Down Expand Up @@ -77,8 +77,8 @@ pub async fn mediated_connection_send_message(handle: u32, msg: String) -> napi:
#[napi]
pub async fn mediated_connection_create_with_connection_request_v2(request: String, pw_info: String) -> napi::Result<u32> {
let pw_info: PairwiseInfo = serde_json::from_str(&pw_info).map_err(|err| {
VcxError::from_msg(
VcxErrorKind::InvalidJson,
LibvcxError::from_msg(
LibvcxErrorKind::InvalidJson,
format!("Cannot deserialize pw info: {:?}", err),
)
})
Expand Down Expand Up @@ -206,21 +206,22 @@ pub async fn mediated_connection_messages_download(
.map_err(to_napi_err)
}

#[napi]
pub async fn mediated_connection_sign_data(handle: u32, data: Buffer) -> napi::Result<Buffer> {
let vk = mediated_connection::get_pw_verkey(handle)
.map_err(to_napi_err)?;
Ok(Buffer::from(indy::signing::sign(get_main_wallet_handle(), &vk, &data.to_vec())
.await
.map_err(to_napi_err)?
))
}

#[napi]
pub async fn mediated_connection_verify_signature(handle: u32, data: Buffer, signature: Buffer) -> napi::Result<bool> {
let vk = mediated_connection::get_their_pw_verkey(handle)
.map_err(to_napi_err)?;
indy::signing::verify(&vk, &data.to_vec(), &signature.to_vec())
.await
.map_err(to_napi_err)
}
//
// #[napi]
// pub async fn mediated_connection_sign_data(handle: u32, data: Buffer) -> napi::Result<Buffer> {
// let vk = mediated_connection::get_pw_verkey(handle)
// .map_err(to_napi_err)?;
// Ok(Buffer::from(indy::signing::sign(get_main_wallet_handle(), &vk, &data.to_vec())
// .await
// .map_err(to_napi_err)?
// ))
// }
//
// #[napi]
// pub async fn mediated_connection_verify_signature(handle: u32, data: Buffer, signature: Buffer) -> napi::Result<bool> {
// let vk = mediated_connection::get_their_pw_verkey(handle)
// .map_err(to_napi_err)?;
// indy::signing::verify(&vk, &data.to_vec(), &signature.to_vec())
// .await
// .map_err(to_napi_err)
// }
52 changes: 27 additions & 25 deletions wrappers/node-napi-rs/api-node/src/api/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use vcx::{
},
aries_vcx::{
agency_client::{configuration::AgencyClientConfig, testing::mocking::enable_agency_mocks},
error::{VcxError, VcxErrorKind},
global::settings::enable_indy_mocks,
},
serde_json,
};
use vcx::api_lib::errors::error::{LibvcxError, LibvcxErrorKind};

use crate::error::to_napi_err;

Expand All @@ -22,28 +22,30 @@ pub fn init_default_logger(pattern: Option<String>) -> napi::Result<()> {
LibvcxDefaultLogger::init(pattern).map_err(to_napi_err)
}

#[napi]
pub fn create_agency_client_for_main_wallet(config: String) -> napi::Result<()> {
let config = serde_json::from_str::<AgencyClientConfig>(&config)
.map_err(|err| VcxError::from_msg(VcxErrorKind::InvalidJson, format!("Serialization error: {:?}", err)))
.map_err(to_napi_err)?;
let client = get_main_agency_client()
.map_err(to_napi_err)?
.configure(get_main_wallet_handle(), &config)
.map_err(|err| {
VcxError::from_msg(
VcxErrorKind::InvalidJson,
format!("failed to configure agency client: {:?}", err),
)
})
.map_err(to_napi_err)?;
set_main_agency_client(client);
Ok(())
}
// todo: restore
// #[napi]
// pub fn create_agency_client_for_main_wallet(config: String) -> napi::Result<()> {
// let config = serde_json::from_str::<AgencyClientConfig>(&config)
// .map_err(|err| LibvcxError::from_msg(LibvcxErrorKind::InvalidJson, format!("Serialization error: {:?}", err)))
// .map_err(to_napi_err)?;
// let client = get_main_agency_client()
// .map_err(to_napi_err)?
// .configure(get_main_wallet_handle(), &config)
// .map_err(|err| {
// LibvcxError::from_msg(
// LibvcxErrorKind::InvalidJson,
// format!("failed to configure agency client: {:?}", err),
// )
// })
// .map_err(to_napi_err)?;
// set_main_agency_client(client);
// Ok(())
// }

#[napi]
pub fn enable_mocks() -> ::napi::Result<()> {
enable_indy_mocks().map_err(to_napi_err)?;
enable_agency_mocks();
Ok(())
}
// todo: restore
// #[napi]
// pub fn enable_mocks() -> ::napi::Result<()> {
// enable_indy_mocks().map_err(to_napi_err)?;
// enable_agency_mocks();
// Ok(())
// }
15 changes: 7 additions & 8 deletions wrappers/node-napi-rs/api-node/src/api/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,28 @@ use vcx::{
create_main_wallet, get_main_wallet_handle, reset_main_wallet_handle,
set_main_wallet_handle,
},
aries_vcx::{
error::{VcxError, VcxErrorKind},
indy::{self, wallet::WalletConfig},
},
aries_vcx::indy::{self, wallet::WalletConfig},
serde_json,
};
use vcx::api_lib::errors::error::{LibvcxError, LibvcxErrorKind};
use vcx::api_lib::global::wallet::{close_main_wallet, open_as_main_wallet};

use crate::error::to_napi_err;

#[napi]
pub async fn wallet_open_as_main(wallet_config: String) -> napi::Result<i32> {
let wallet_config = serde_json::from_str::<WalletConfig>(&wallet_config)
.map_err(|err| VcxError::from_msg(VcxErrorKind::InvalidJson, format!("Serialization error: {:?}", err)))
.map_err(|err| LibvcxError::from_msg(LibvcxErrorKind::InvalidJson, format!("Serialization error: {:?}", err)))
.map_err(to_napi_err)?;
let handle = indy::wallet::open_wallet(&wallet_config).await.map_err(to_napi_err)?;
let handle = open_as_main_wallet(&wallet_config).await.map_err(to_napi_err)?;
set_main_wallet_handle(handle);
Ok(handle.0)
}

#[napi]
pub async fn wallet_create_main(wallet_config: String) -> napi::Result<()> {
let wallet_config = serde_json::from_str::<WalletConfig>(&wallet_config)
.map_err(|err| VcxError::from_msg(VcxErrorKind::InvalidJson, format!("Serialization error: {:?}", err)))
.map_err(|err| LibvcxError::from_msg(LibvcxErrorKind::InvalidJson, format!("Serialization error: {:?}", err)))
.map_err(to_napi_err)?;
create_main_wallet(&wallet_config)
.await
Expand All @@ -35,7 +34,7 @@ pub async fn wallet_create_main(wallet_config: String) -> napi::Result<()> {

#[napi]
pub async fn wallet_close_main() -> ::napi::Result<()> {
indy::wallet::close_wallet(get_main_wallet_handle())
close_main_wallet()
.await
.map_err(to_napi_err)?;
reset_main_wallet_handle();
Expand Down
4 changes: 2 additions & 2 deletions wrappers/node-napi-rs/api-node/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use vcx::api_lib::utils::logger::VcxError;
use vcx::api_lib::errors::error::LibvcxError;

pub fn to_napi_err(err: VcxError) -> napi::Error {
pub fn to_napi_err(err: LibvcxError) -> napi::Error {
error!("{}", err.to_string());
napi::Error::new(napi::Status::Unknown, format!("{:?}", Into::<u32>::into(err.kind())))
}

0 comments on commit b2213f7

Please sign in to comment.