Skip to content

Commit

Permalink
Out of Band NAPI
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Kovar <[email protected]>
  • Loading branch information
mirgee committed Nov 25, 2022
1 parent 1947406 commit 24d6a0c
Show file tree
Hide file tree
Showing 14 changed files with 375 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
**/target
**/.DS_Store
**/node_modules
**/*.node
wrappers/ios/vcx/vcx.framework/**
wrappers/ios/vcx/vcx.framework.dSYM/**
wrappers/ios/vcx/vcx.framework.dSYM/**
96 changes: 94 additions & 2 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ members = [
"libvcx",
"agency_client",
"messages",
"agents/rust/aries-vcx-agent"
"agents/rust/aries-vcx-agent",
"wrappers/node-napi-rs/api-node",
]

[workspace.package]
Expand Down
2 changes: 1 addition & 1 deletion libvcx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition.workspace = true
[lib]
name = "vcx"
path = "src/lib.rs"
crate-type = ["staticlib", "cdylib"]
crate-type = ["staticlib", "cdylib", "lib"]
doctest = false

[features]
Expand Down
21 changes: 21 additions & 0 deletions wrappers/node-napi-rs/api-node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "api-node"
version.workspace = true
authors.workspace = true
license.workspace = true
edition.workspace = true

[lib]
name = "api_node"
path = "src/lib.rs"
crate-type = ["cdylib"]
doctest = false

[dependencies]
libvcx = { path = "../../../libvcx" }
log = "0.4.16"
napi = { version = "=2.9.1", default-features = false, features = [ "async" ] }
napi-derive = { version = "=2.9.1" }

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

fn main() {
napi_build::setup();
}
1 change: 1 addition & 0 deletions wrappers/node-napi-rs/api-node/src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod out_of_band;
111 changes: 111 additions & 0 deletions wrappers/node-napi-rs/api-node/src/api/out_of_band.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
use napi_derive::napi;
use ::vcx::api_lib::api_handle::out_of_band;

use crate::error::to_napi_err;

#[napi]
// TODO: Does not need to be async
pub async fn out_of_band_sender_create(config: String) -> napi::Result<u32> {
out_of_band::create_out_of_band(&config)
.await
.map_err(to_napi_err)
}

#[napi]
pub fn out_of_band_receiver_create(msg: String) -> napi::Result<u32> {
out_of_band::create_out_of_band_msg_from_msg(&msg)
.map_err(to_napi_err)
}

#[napi]
pub fn out_of_band_sender_append_message(handle: u32, msg: String) -> napi::Result<()> {
out_of_band::append_message(handle, &msg)
.map_err(to_napi_err)
}

#[napi]
pub fn out_of_band_sender_append_service(handle: u32, service: String) -> napi::Result<()> {
out_of_band::append_service(handle, &service)
.map_err(to_napi_err)
}

#[napi]
pub fn out_of_band_sender_append_service_did(handle: u32, did: String) -> napi::Result<()> {
out_of_band::append_service_did(handle, &did)
.map_err(to_napi_err)
}

#[napi]
pub fn out_of_band_receiver_extract_message(handle: u32) -> napi::Result<String> {
out_of_band::extract_a2a_message(handle)
.map_err(to_napi_err)
}

#[napi]
pub fn out_of_band_sender_to_message(handle: u32) -> napi::Result<String> {
out_of_band::to_a2a_message(handle)
.map_err(to_napi_err)
}

#[napi]
pub async fn out_of_band_receiver_connection_exists(handle: u32, conn_handles: Vec<u32>) -> napi::Result<u32> {
out_of_band::connection_exists(handle, &conn_handles)
.await
.map(|res| res.0)
.map_err(to_napi_err)
}

#[napi]
pub async fn out_of_band_receiver_build_connection(handle: u32) -> napi::Result<String> {
out_of_band::build_connection(handle)
.await
.map_err(to_napi_err)
}

#[napi]
pub fn out_of_band_sender_get_thread_id(handle: u32) -> napi::Result<String> {
out_of_band::get_thread_id_sender(handle)
.map_err(to_napi_err)
}

#[napi]
pub fn out_of_band_receiver_get_thread_id(handle: u32) -> napi::Result<String> {
out_of_band::get_thread_id_receiver(handle)
.map_err(to_napi_err)
}

#[napi]
pub fn out_of_band_sender_serialize(handle: u32) -> napi::Result<String> {
out_of_band::to_string_sender(handle)
.map_err(to_napi_err)
}

#[napi]
pub fn out_of_band_receiver_serialize(handle: u32) -> napi::Result<String> {
out_of_band::to_string_receiver(handle)
.map_err(to_napi_err)
}

#[napi]
pub fn out_of_band_sender_deserialize(oob_data: String) -> napi::Result<u32> {
out_of_band::from_string_sender(&oob_data)
.map_err(to_napi_err)
}

#[napi]
pub fn out_of_band_receiver_deserialize(oob_data: String) -> napi::Result<u32> {
out_of_band::from_string_receiver(&oob_data)
.map_err(to_napi_err)
}

#[napi]
pub fn out_of_band_sender_release(handle: u32) -> napi::Result<()> {
out_of_band::release_sender(handle)
.map_err(to_napi_err)
}

#[napi]
pub fn out_of_band_receiver_release(handle: u32) -> napi::Result<()> {
out_of_band::release_receiver(handle)
.map_err(to_napi_err)
}
6 changes: 6 additions & 0 deletions wrappers/node-napi-rs/api-node/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use vcx::api_lib::utils::logger::VcxError;

pub fn to_napi_err(err: VcxError) -> napi::Error {
error!("{}", err.to_string());
napi::Error::new(napi::Status::Unknown, format!("{:?}", Into::<u32>::into(err.kind())))
}
5 changes: 5 additions & 0 deletions wrappers/node-napi-rs/api-node/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[macro_use]
extern crate log;

pub mod api;
pub mod error;
22 changes: 22 additions & 0 deletions wrappers/node-napi-rs/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* tslint:disable */
/* eslint-disable */

/* auto-generated by NAPI-RS */

export function outOfBandSenderCreate(config: string): Promise<number>
export function outOfBandReceiverCreate(msg: string): number
export function outOfBandSenderAppendMessage(handle: number, msg: string): void
export function outOfBandSenderAppendService(handle: number, service: string): void
export function outOfBandSenderAppendServiceDid(handle: number, did: string): void
export function outOfBandReceiverExtractMessage(handle: number): string
export function outOfBandSenderToMessage(handle: number): string
export function outOfBandReceiverConnectionExists(handle: number, connHandles: Array<number>): Promise<number>
export function outOfBandReceiverBuildConnection(handle: number): Promise<string>
export function outOfBandSenderGetThreadId(handle: number): string
export function outOfBandReceiverGetThreadId(handle: number): string
export function outOfBandSenderSerialize(handle: number): string
export function outOfBandReceiverSerialize(handle: number): string
export function outOfBandSenderDeserialize(oobData: string): number
export function outOfBandReceiverDeserialize(oobData: string): number
export function outOfBandSenderRelease(handle: number): void
export function outOfBandReceiverRelease(handle: number): void
Loading

0 comments on commit 24d6a0c

Please sign in to comment.