Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate node bindings using napi-rs #661

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c0d24c6
Generate node bindings using napi-rs
mirgee Nov 22, 2022
bfd2189
Use new API in OutOfBandSender node class
mirgee Nov 22, 2022
ce7d33d
Use new API in OutOfBandReceiver node class
mirgee Nov 22, 2022
2b00cb5
Custom serialize method
mirgee Nov 22, 2022
5575993
Adjust base class, apply for sender
mirgee Nov 23, 2022
637177a
Fix oob node wrapper unit tests
mirgee Nov 23, 2022
1d14347
Add some mediated connection functions to index.d.ts
mirgee Nov 23, 2022
bbf541f
Partially adjust mediated-connection.ts to use ffi-napi-rs
mirgee Nov 23, 2022
682b9ff
Expose create_with_request_v2
mirgee Nov 23, 2022
d47525f
Expose send_generic_message
mirgee Nov 23, 2022
9cf56f3
Expose get_connection_info
mirgee Nov 23, 2022
5bbd1bf
Expose send_discovery_features
mirgee Nov 23, 2022
a681b0e
Expose download_connection_messages
mirgee Nov 23, 2022
863fa5a
Expose signature signing and verification
mirgee Nov 23, 2022
74e9657
Change mediated connection base class
mirgee Nov 23, 2022
de62a26
create_main_wallet
mirgee Nov 23, 2022
a9da4d9
open_main_wallet
mirgee Nov 23, 2022
e57864e
Close main wallet
mirgee Nov 23, 2022
4288c6a
Partially enable connection wrapper tests
mirgee Nov 24, 2022
4b3a722
Propagate error type information from rust to node
mirgee Nov 24, 2022
4cd474c
New error class
mirgee Nov 24, 2022
96e65a4
Fix signing
mirgee Nov 24, 2022
e0249b2
Fix unit tests
mirgee Nov 24, 2022
62cdc94
Try disabling napi_derive macro in tests
mirgee Nov 24, 2022
6da1406
Put back error handling
mirgee Nov 24, 2022
aed19ba
Try specifying noop for the dep specifically
mirgee Nov 24, 2022
a100b75
Try downgrading napi-rs
mirgee Nov 24, 2022
4a7f895
Try dynamic_lookup, undefined, -Wl linker flags
mirgee Nov 24, 2022
41cf793
Revert "Try dynamic_lookup, undefined, -Wl linker flags"
mirgee Nov 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
424 changes: 255 additions & 169 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions aries_vcx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ derive_builder = "0.10.2"
tokio = { version = "1.15.0" }
messages = { path = "../messages" }
zmq = { version = "0.9.2" }
napi = "=2.9.1"

[target.'cfg(target_os = "android")'.dependencies]
android_logger = "0.5"
Expand Down
22 changes: 22 additions & 0 deletions aries_vcx/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,28 @@ impl From<SenderConfigBuilderError> for VcxError {
}
}

impl From<VcxError> for napi::Error {
fn from(err: VcxError) -> Self {
let reason = err.to_string();
error!("{}", reason);
// Use message field to propagate information about error type
napi::Error::new(napi::Status::Unknown, format!("{:?}", Into::<u32>::into(err.kind())))
}
}

impl From<napi::Error> for VcxError {
fn from(err: napi::Error) -> Self {
let reason = err.to_string();
error!("{}", reason);
// TODO: This is hacky, there are other options
match err.reason.parse::<u32>() {
Ok(r) => VcxError::from(VcxErrorKind::from(r)),
Err(_) => VcxError::from_msg(VcxErrorKind::UnknownError, reason)

}
}
}

impl From<AgencyClientErrorKind> for VcxErrorKind {
fn from(agency_err: AgencyClientErrorKind) -> VcxErrorKind {
match agency_err {
Expand Down
4 changes: 2 additions & 2 deletions aries_vcx/src/handlers/connection/mediated_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,11 +776,11 @@ impl MediatedConnection {
}
}

pub async fn send_generic_message(&self, wallet_handle: WalletHandle, message: &str) -> VcxResult<String> {
pub async fn send_generic_message(&self, wallet_handle: WalletHandle, message: &str) -> VcxResult<()> {
trace!("MediatedConnection::send_generic_message >>> message: {:?}", message);
let message = Self::build_basic_message(message);
let send_message = self.send_message_closure(wallet_handle).await?;
send_message(message).await.map(|_| String::new())
send_message(message).await
}

pub async fn send_a2a_message(&self, wallet_handle: WalletHandle, message: &A2AMessage) -> VcxResult<String> {
Expand Down
2 changes: 2 additions & 0 deletions aries_vcx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ extern crate derive_builder;
#[cfg(test)]
extern crate async_channel;

extern crate napi;

pub extern crate messages;

#[macro_use]
Expand Down
5 changes: 5 additions & 0 deletions libvcx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ chrono = "0.4.19"
time = "0.1.44"
lazy_static = "1.3"
libc = "=0.2.114"
napi = { version = "=2.9.1", default-features = false, features = [ "async" ] }
napi-derive = { version = "=2.9.1" }
rand = "0.7.3"
serde = "1.0.97"
serde_json = "1.0.40"
Expand All @@ -44,3 +46,6 @@ android_logger = "0.5"

[dev-dependencies]
tokio = { version = "1.15", features = [ "rt", "macros" ] }

[build-dependencies]
napi-build = "2.0.1"
3 changes: 3 additions & 0 deletions libvcx/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
extern crate napi_build;

use std::env;
use std::fs;
use std::path::Path;
Expand Down Expand Up @@ -33,4 +35,5 @@ fn main() {
}
}
}
napi_build::setup();
}
145 changes: 61 additions & 84 deletions libvcx/src/api_lib/api_c/mediated_connection.rs

Large diffs are not rendered by default.

40 changes: 29 additions & 11 deletions libvcx/src/api_lib/api_c/out_of_band.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub extern "C" fn vcx_out_of_band_sender_create(
config
);

execute_async::<BoxFuture<'static, Result<(), ()>>>(Box::pin(async move {
match out_of_band::create_out_of_band(&config).await {
execute(move || {
match out_of_band::create_out_of_band(config) {
Ok(handle) => {
trace!(
"vcx_out_of_band_sender_create_cb(command_handle: {}, rc: {}, handle: {})",
Expand All @@ -41,6 +41,7 @@ pub extern "C" fn vcx_out_of_band_sender_create(
cb(command_handle, error::SUCCESS.code_num, handle);
}
Err(err) => {
let err: VcxError = err.into();
set_current_error_vcx(&err);
error!(
"vcx_out_of_band_sender_create_cb(command_handle: {}, rc: {}, handle: {})",
Expand All @@ -50,7 +51,7 @@ pub extern "C" fn vcx_out_of_band_sender_create(
}
}
Ok(())
}));
});

error::SUCCESS.code_num
}
Expand All @@ -73,7 +74,7 @@ pub extern "C" fn vcx_out_of_band_receiver_create(
);

execute(move || {
match out_of_band::create_out_of_band_msg_from_msg(&message) {
match out_of_band::create_out_of_band_msg_from_msg(message) {
Ok(handle) => {
trace!(
"vcx_out_of_band_receiver_create_cb(command_handle: {}, rc: {}, handle: {})",
Expand All @@ -84,6 +85,7 @@ pub extern "C" fn vcx_out_of_band_receiver_create(
cb(command_handle, error::SUCCESS.code_num, handle);
}
Err(err) => {
let err: VcxError = err.into();
set_current_error_vcx(&err);
error!(
"vcx_out_of_band_receiver_create_cb(command_handle: {}, rc: {}, handle: {}):",
Expand Down Expand Up @@ -127,6 +129,7 @@ pub extern "C" fn vcx_out_of_band_sender_get_thread_id(
cb(command_handle, error::SUCCESS.code_num, thid.as_ptr());
}
Err(err) => {
let err: VcxError = err.into();
set_current_error_vcx(&err);
error!(
"vcx_out_of_band_sender_get_thread_id_cb(command_handle: {}, rc: {}, thid: {})",
Expand Down Expand Up @@ -170,6 +173,7 @@ pub extern "C" fn vcx_out_of_band_receiver_get_thread_id(
cb(command_handle, error::SUCCESS.code_num, thid.as_ptr());
}
Err(err) => {
let err: VcxError = err.into();
set_current_error_vcx(&err);
error!(
"vcx_out_of_band_receiver_get_thread_id_cb(command_handle: {}, rc: {}, thid: {})",
Expand Down Expand Up @@ -204,7 +208,7 @@ pub extern "C" fn vcx_out_of_band_sender_append_message(
);

execute(move || {
match out_of_band::append_message(handle, &message) {
match out_of_band::append_message(handle, message) {
Ok(()) => {
trace!(
"vcx_out_of_band_sender_append_message_cb(command_handle: {}, rc: {})",
Expand All @@ -214,6 +218,7 @@ pub extern "C" fn vcx_out_of_band_sender_append_message(
cb(command_handle, error::SUCCESS.code_num);
}
Err(err) => {
let err: VcxError = err.into();
set_current_error_vcx(&err);
error!(
"vcx_out_of_band_sender_append_message_cb(command_handle: {}, rc: {})",
Expand Down Expand Up @@ -248,7 +253,7 @@ pub extern "C" fn vcx_out_of_band_sender_append_service(
);

execute(move || {
match out_of_band::append_service(handle, &service) {
match out_of_band::append_service(handle, service) {
Ok(()) => {
trace!(
"vcx_out_of_band_sender_append_service_cb(command_handle: {}, rc: {})",
Expand All @@ -258,6 +263,7 @@ pub extern "C" fn vcx_out_of_band_sender_append_service(
cb(command_handle, error::SUCCESS.code_num);
}
Err(err) => {
let err: VcxError = err.into();
set_current_error_vcx(&err);
error!(
"vcx_out_of_band_sender_append_service_cb(command_handle: {}, rc: {})",
Expand Down Expand Up @@ -292,7 +298,7 @@ pub extern "C" fn vcx_out_of_band_sender_append_service_did(
);

execute(move || {
match out_of_band::append_service_did(handle, &did) {
match out_of_band::append_service_did(handle, did) {
Ok(()) => {
trace!(
"vcx_out_of_band_sender_append_service_did_cb(command_handle: {}, rc: {})",
Expand All @@ -302,6 +308,7 @@ pub extern "C" fn vcx_out_of_band_sender_append_service_did(
cb(command_handle, error::SUCCESS.code_num);
}
Err(err) => {
let err: VcxError = err.into();
set_current_error_vcx(&err);
error!(
"vcx_out_of_band_sender_append_service_did_cb(command_handle: {}, rc: {})",
Expand Down Expand Up @@ -345,6 +352,7 @@ pub extern "C" fn vcx_out_of_band_receiver_extract_message(
cb(command_handle, error::SUCCESS.code_num, msg.as_ptr());
}
Err(err) => {
let err: VcxError = err.into();
set_current_error_vcx(&err);
error!(
"vcx_out_of_band_receiver_extract_message_cb(command_handle: {}, rc: {}, msg: {})",
Expand Down Expand Up @@ -388,6 +396,7 @@ pub extern "C" fn vcx_out_of_band_to_message(
cb(command_handle, error::SUCCESS.code_num, msg.as_ptr());
}
Err(err) => {
let err: VcxError = err.into();
set_current_error_vcx(&err);
error!(
"vcx_out_of_band_to_message_cb(command_handle: {}, rc: {}, msg: {})",
Expand Down Expand Up @@ -434,12 +443,14 @@ pub extern "C" fn vcx_out_of_band_receiver_connection_exists(
};

execute_async::<BoxFuture<'static, Result<(), ()>>>(Box::pin(async move {
match out_of_band::connection_exists(handle, &conn_handles).await {
Ok((conn_handle, found_one)) => {
match out_of_band::connection_exists(handle, conn_handles).await {
Ok(conn_handle) => {
let found_one = conn_handle == 0;
trace!("vcx_out_of_band_receiver_connection_exists_cb(command_handle: {}, rc: {}, conn_handle: {}, found_one: {})", command_handle, error::SUCCESS.message, conn_handle, found_one);
cb(command_handle, error::SUCCESS.code_num, conn_handle, found_one);
}
Err(err) => {
let err: VcxError = err.into();
set_current_error_vcx(&err);
error!("vcx_out_of_band_receiver_connection_exists_cb(command_handle: {}, rc: {}, conn_handle: {}, found_one: {})", command_handle, err, 0, false);
cb(command_handle, err.into(), 0, false);
Expand Down Expand Up @@ -480,6 +491,7 @@ pub extern "C" fn vcx_out_of_band_receiver_build_connection(
cb(command_handle, error::SUCCESS.code_num, connection.as_ptr());
}
Err(err) => {
let err: VcxError = err.into();
set_current_error_vcx(&err);
error!(
"vcx_out_of_band_receiver_build_connection_cb(command_handle: {}, rc: {}, connection: {})",
Expand Down Expand Up @@ -523,6 +535,7 @@ pub extern "C" fn vcx_out_of_band_sender_serialize(
cb(command_handle, error::SUCCESS.code_num, oob_json.as_ptr());
}
Err(err) => {
let err: VcxError = err.into();
set_current_error_vcx(&err);
error!(
"vcx_out_of_band_sender_serialize_cb(command_handle: {}, rc: {}, oob_json: {})",
Expand Down Expand Up @@ -566,6 +579,7 @@ pub extern "C" fn vcx_out_of_band_receiver_serialize(
cb(command_handle, error::SUCCESS.code_num, oob_json.as_ptr());
}
Err(err) => {
let err: VcxError = err.into();
set_current_error_vcx(&err);
error!(
"vcx_out_of_band_receiver_serialize_cb(command_handle: {}, rc: {}, oob_json: {})",
Expand Down Expand Up @@ -598,7 +612,7 @@ pub extern "C" fn vcx_out_of_band_sender_deserialize(
);

execute(move || {
match out_of_band::from_string_sender(&oob_json) {
match out_of_band::from_string_sender(oob_json) {
Ok(handle) => {
trace!(
"vcx_out_of_band_sender_deserialize_cb(command_handle: {}, rc: {}, handle: {})",
Expand All @@ -609,6 +623,7 @@ pub extern "C" fn vcx_out_of_band_sender_deserialize(
cb(command_handle, error::SUCCESS.code_num, handle);
}
Err(err) => {
let err: VcxError = err.into();
set_current_error_vcx(&err);
error!(
"vcx_out_of_band_sender_deserialize_cb(command_handle: {}, rc: {}, handle: {})",
Expand Down Expand Up @@ -641,7 +656,7 @@ pub extern "C" fn vcx_out_of_band_receiver_deserialize(
);

execute(move || {
match out_of_band::from_string_receiver(&oob_json) {
match out_of_band::from_string_receiver(oob_json) {
Ok(handle) => {
trace!(
"vcx_out_of_band_receiver_deserialize_cb(command_handle: {}, rc: {}, handle: {})",
Expand All @@ -652,6 +667,7 @@ pub extern "C" fn vcx_out_of_band_receiver_deserialize(
cb(command_handle, error::SUCCESS.code_num, handle);
}
Err(err) => {
let err: VcxError = err.into();
set_current_error_vcx(&err);
error!(
"vcx_out_of_band_receiver_deserialize_cb(command_handle: {}, rc: {}, handle: {})",
Expand Down Expand Up @@ -680,6 +696,7 @@ pub extern "C" fn vcx_out_of_band_sender_release(handle: u32) -> u32 {
error::SUCCESS.code_num
}
Err(err) => {
let err: VcxError = err.into();
error!("vcx_out_of_band_sender_release(handle: {}), rc: {})", handle, err);
err.into()
}
Expand All @@ -700,6 +717,7 @@ pub extern "C" fn vcx_out_of_band_receiver_release(handle: u32) -> u32 {
error::SUCCESS.code_num
}
Err(err) => {
let err: VcxError = err.into();
error!("vcx_out_of_band_receiver_release(handle: {}), rc: {})", handle, err);
err.into()
}
Expand Down
Loading