Skip to content

Commit 34dba47

Browse files
authored
Allow appending handshake protocols from node wrapper (#655)
Allow appending handshake protocols from node wrapper (#655) Signed-off-by: Miroslav Kovar <miroslav.kovar@absa.africa>
1 parent 7a7c65d commit 34dba47

File tree

6 files changed

+58
-47
lines changed

6 files changed

+58
-47
lines changed

libvcx/src/api_lib/api_handle/out_of_band.rs

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use std::collections::HashMap;
22

3+
use crate::api_lib::global::pool::get_main_pool_handle;
34
use aries_vcx::error::{VcxError, VcxErrorKind, VcxResult};
45
use aries_vcx::handlers::out_of_band::receiver::OutOfBandReceiver;
56
use aries_vcx::handlers::out_of_band::sender::OutOfBandSender;
6-
use aries_vcx::messages::out_of_band::GoalCode;
7+
use aries_vcx::indy::ledger::transactions::into_did_doc;
78
use aries_vcx::messages::a2a::A2AMessage;
89
use aries_vcx::messages::connection::did::Did;
910
use aries_vcx::messages::connection::invite::Invitation;
1011
use aries_vcx::messages::did_doc::service_resolvable::ServiceResolvable;
11-
use aries_vcx::indy::ledger::transactions::into_did_doc;
12-
use crate::api_lib::global::pool::get_main_pool_handle;
12+
use aries_vcx::messages::out_of_band::{GoalCode, HandshakeProtocol};
1313

1414
use crate::api_lib::api_handle::connection::CONNECTION_MAP;
1515
use crate::api_lib::api_handle::object_cache::ObjectCache;
@@ -22,11 +22,13 @@ lazy_static! {
2222
ObjectCache::<OutOfBandReceiver>::new("out-of-band-receiver-cache");
2323
}
2424

25-
#[derive(Debug, Serialize, Deserialize)]
25+
#[derive(Deserialize)]
2626
pub struct OOBConfig {
2727
pub label: Option<String>,
2828
pub goal_code: Option<GoalCode>,
2929
pub goal: Option<String>,
30+
#[serde(default)]
31+
pub handshake_protocols: Vec<HandshakeProtocol>,
3032
}
3133

3234
fn store_out_of_band_receiver(oob: OutOfBandReceiver) -> VcxResult<u32> {
@@ -59,6 +61,9 @@ pub async fn create_out_of_band(config: &str) -> VcxResult<u32> {
5961
if let Some(goal_code) = &config.goal_code {
6062
oob = oob.set_goal_code(&goal_code);
6163
};
64+
for protocol in config.handshake_protocols {
65+
oob = oob.append_handshake_protocol(&protocol)?;
66+
}
6267
store_out_of_band_sender(oob)
6368
}
6469

@@ -218,18 +223,14 @@ pub fn release_receiver(handle: u32) -> VcxResult<()> {
218223
#[cfg(test)]
219224
pub mod tests {
220225
use aries_vcx::messages::did_doc::service_aries::AriesService;
221-
use aries_vcx::utils::devsetup::SetupMocks;
222226

223227
use super::*;
224228

225-
#[tokio::test]
226-
#[cfg(feature = "general_test")]
227-
async fn test_build_oob_sender_append_services() {
228-
let _setup = SetupMocks::init();
229-
let config = json!(OOBConfig {
230-
label: Some("foo".into()),
231-
goal_code: Some(GoalCode::IssueVC),
232-
goal: Some("foobar".into())
229+
async fn build_and_append_service(did: &str) {
230+
let config = json!({
231+
"label": "foo",
232+
"goal_code": GoalCode::IssueVC,
233+
"goal": "foobar"
233234
})
234235
.to_string();
235236
let oob_handle = create_out_of_band(&config).await.unwrap();
@@ -241,41 +242,40 @@ pub mod tests {
241242
.set_recipient_keys(vec!["abcde".into()]),
242243
);
243244
append_service(oob_handle, &json!(service).to_string()).unwrap();
244-
append_service_did(oob_handle, "V4SGRU86Z58d6TV7PBUe6f").unwrap();
245-
let resolved_service = get_services(oob_handle).unwrap();
246-
assert_eq!(resolved_service.len(), 2);
247-
assert_eq!(service, resolved_service[0]);
245+
append_service_did(oob_handle, did).unwrap();
246+
let resolved_services = get_services(oob_handle).unwrap();
247+
assert_eq!(resolved_services.len(), 2);
248+
assert_eq!(service, resolved_services[0]);
248249
assert_eq!(
249-
ServiceResolvable::Did(Did::new("V4SGRU86Z58d6TV7PBUe6f").unwrap()),
250-
resolved_service[1]
250+
ServiceResolvable::Did(Did::new(did).unwrap()),
251+
resolved_services[1]
251252
);
252253
}
254+
255+
#[tokio::test]
256+
#[cfg(feature = "general_test")]
257+
async fn test_build_oob_sender_append_services() {
258+
build_and_append_service("V4SGRU86Z58d6TV7PBUe6f").await
259+
}
260+
253261
#[tokio::test]
254262
#[cfg(feature = "general_test")]
255263
async fn test_build_oob_sender_append_services_prefix_did_sov() {
256-
let _setup = SetupMocks::init();
257-
let config = json!(OOBConfig {
258-
label: Some("foo".into()),
259-
goal_code: Some(GoalCode::IssueVC),
260-
goal: Some("foobar".into())
261-
})
262-
.to_string();
263-
let oob_handle = create_out_of_band(&config).await.unwrap();
264-
assert!(oob_handle > 0);
265-
let service = ServiceResolvable::AriesService(
266-
AriesService::create()
267-
.set_service_endpoint("http://example.org/agent".into())
268-
.set_routing_keys(vec!["12345".into()])
269-
.set_recipient_keys(vec!["abcde".into()]),
270-
);
271-
append_service(oob_handle, &json!(service).to_string()).unwrap();
272-
append_service_did(oob_handle, "did:sov:V4SGRU86Z58d6TV7PBUe6f").unwrap();
273-
let resolved_service = get_services(oob_handle).unwrap();
274-
assert_eq!(resolved_service.len(), 2);
275-
assert_eq!(service, resolved_service[0]);
264+
build_and_append_service("did:sov:V4SGRU86Z58d6TV7PBUe6f").await
265+
}
266+
267+
#[test]
268+
#[cfg(feature = "general_test")]
269+
fn test_serde_oob_config_handshake_protocols() {
270+
let config_str = json!({ "handshake_protocols": vec!["ConnectionV1", "DidExchangeV1"] }).to_string();
271+
let config_actual: OOBConfig = serde_json::from_str(&config_str).unwrap();
276272
assert_eq!(
277-
ServiceResolvable::Did(Did::new("did:sov:V4SGRU86Z58d6TV7PBUe6f").unwrap()),
278-
resolved_service[1]
273+
config_actual.handshake_protocols,
274+
vec![HandshakeProtocol::ConnectionV1, HandshakeProtocol::DidExchangeV1]
279275
);
276+
277+
let config_str = json!({}).to_string();
278+
let config_actual: OOBConfig = serde_json::from_str(&config_str).unwrap();
279+
assert_eq!(config_actual.handshake_protocols, vec![]);
280280
}
281281
}

messages/src/a2a/message_type.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ impl std::string::ToString for MessageType {
6666
self.version,
6767
self.msg_type
6868
)
69+
// TODO: Remove once handshake protocol is implemented
70+
} else if self.msg_type.is_empty() {
71+
format!(
72+
"{}/{}/{}",
73+
self.prefix,
74+
self.family.to_string(),
75+
self.version,
76+
)
6977
} else {
7078
format!(
7179
"{}/{}/{}/{}",

messages/src/out_of_band/invitation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct OutOfBandInvitation {
2121
#[serde(skip_serializing_if = "Option::is_none")]
2222
pub accept: Option<Vec<MimeType>>,
2323
#[serde(skip_serializing_if = "Option::is_none")]
24-
pub handshake_protocols: Option<Vec<MessageType>>,
24+
pub handshake_protocols: Option<Vec<MessageType>>, // TODO: Make a separate type
2525
pub services: Vec<ServiceResolvable>,
2626
#[serde(rename = "requests~attach")]
2727
pub requests_attach: Attachments,

messages/src/out_of_band/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub enum GoalCode {
1414
P2PMessaging,
1515
}
1616

17+
#[derive(Deserialize, Debug, PartialEq)]
1718
pub enum HandshakeProtocol {
1819
ConnectionV1,
1920
DidExchangeV1,

wrappers/node/src/api/out-of-band-sender.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface IOOBCreateData {
2121
label?: string;
2222
goalCode?: GoalCode;
2323
goal?: string;
24+
handshake_protocols?: HandshakeProtocol[];
2425
}
2526

2627
export enum GoalCode {
@@ -31,8 +32,8 @@ export enum GoalCode {
3132
}
3233

3334
export enum HandshakeProtocol {
34-
ConnectionV1 = 0,
35-
DidExchangeV1 = 1,
35+
ConnectionV1 = "ConnectionV1",
36+
DidExchangeV1 = "DidExchangeV1",
3637
}
3738

3839
export class OutOfBandSender extends VCXBase<IOOBSerializedData> {

wrappers/node/test/suite1/ariesvcx-oob.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import '../module-resolver-helper';
22

33
import { initVcxTestMode } from 'helpers/utils'
4-
import { GoalCode, OutOfBandSender, OutOfBandReceiver } from 'src'
4+
import { GoalCode, OutOfBandSender, OutOfBandReceiver, HandshakeProtocol } from 'src'
55
import { assert } from 'chai';
66

77
const credentialOffer = {
@@ -27,12 +27,12 @@ const credentialOffer = {
2727
]
2828
}
2929

30-
describe('Connection:', () => {
30+
describe('Out of Band:', () => {
3131
before(() => initVcxTestMode())
3232

3333
describe('create:', () => {
3434
it('success', async () => {
35-
const oobSender = await OutOfBandSender.create({source_id: "abcd", label: "foo", goalCode: GoalCode.P2PMessaging, goal: "bar"})
35+
const oobSender = await OutOfBandSender.create({source_id: "abcd", label: "foo", goalCode: GoalCode.P2PMessaging, goal: "bar", handshake_protocols: [HandshakeProtocol.ConnectionV1]})
3636
await oobSender.appendServiceDid("VsKV7grR1BUE29mG2Fm2kX")
3737
const service = {
3838
"id": "did:example:123456789abcdefghi;indy",
@@ -48,6 +48,7 @@ describe('Connection:', () => {
4848
assert.equal(msg["@type"], "https://didcomm.org/out-of-band/1.1/invitation")
4949
assert.equal(msg["goal"], "bar")
5050
assert.equal(msg["label"], "foo")
51+
assert.equal(msg["handshake_protocols"][0], "https://didcomm.org/connections/1.0")
5152
})
5253
})
5354

0 commit comments

Comments
 (0)