1
1
use std:: collections:: HashMap ;
2
2
3
+ use crate :: api_lib:: global:: pool:: get_main_pool_handle;
3
4
use aries_vcx:: error:: { VcxError , VcxErrorKind , VcxResult } ;
4
5
use aries_vcx:: handlers:: out_of_band:: receiver:: OutOfBandReceiver ;
5
6
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 ;
7
8
use aries_vcx:: messages:: a2a:: A2AMessage ;
8
9
use aries_vcx:: messages:: connection:: did:: Did ;
9
10
use aries_vcx:: messages:: connection:: invite:: Invitation ;
10
11
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 } ;
13
13
14
14
use crate :: api_lib:: api_handle:: connection:: CONNECTION_MAP ;
15
15
use crate :: api_lib:: api_handle:: object_cache:: ObjectCache ;
@@ -22,11 +22,13 @@ lazy_static! {
22
22
ObjectCache :: <OutOfBandReceiver >:: new( "out-of-band-receiver-cache" ) ;
23
23
}
24
24
25
- #[ derive( Debug , Serialize , Deserialize ) ]
25
+ #[ derive( Deserialize ) ]
26
26
pub struct OOBConfig {
27
27
pub label : Option < String > ,
28
28
pub goal_code : Option < GoalCode > ,
29
29
pub goal : Option < String > ,
30
+ #[ serde( default ) ]
31
+ pub handshake_protocols : Vec < HandshakeProtocol > ,
30
32
}
31
33
32
34
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> {
59
61
if let Some ( goal_code) = & config. goal_code {
60
62
oob = oob. set_goal_code ( & goal_code) ;
61
63
} ;
64
+ for protocol in config. handshake_protocols {
65
+ oob = oob. append_handshake_protocol ( & protocol) ?;
66
+ }
62
67
store_out_of_band_sender ( oob)
63
68
}
64
69
@@ -218,18 +223,14 @@ pub fn release_receiver(handle: u32) -> VcxResult<()> {
218
223
#[ cfg( test) ]
219
224
pub mod tests {
220
225
use aries_vcx:: messages:: did_doc:: service_aries:: AriesService ;
221
- use aries_vcx:: utils:: devsetup:: SetupMocks ;
222
226
223
227
use super :: * ;
224
228
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"
233
234
} )
234
235
. to_string ( ) ;
235
236
let oob_handle = create_out_of_band ( & config) . await . unwrap ( ) ;
@@ -241,41 +242,40 @@ pub mod tests {
241
242
. set_recipient_keys ( vec ! [ "abcde" . into( ) ] ) ,
242
243
) ;
243
244
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 ] ) ;
248
249
assert_eq ! (
249
- ServiceResolvable :: Did ( Did :: new( "V4SGRU86Z58d6TV7PBUe6f" ) . unwrap( ) ) ,
250
- resolved_service [ 1 ]
250
+ ServiceResolvable :: Did ( Did :: new( did ) . unwrap( ) ) ,
251
+ resolved_services [ 1 ]
251
252
) ;
252
253
}
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
+
253
261
#[ tokio:: test]
254
262
#[ cfg( feature = "general_test" ) ]
255
263
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 ( ) ;
276
272
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 ]
279
275
) ;
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![ ] ) ;
280
280
}
281
281
}
0 commit comments