@@ -853,6 +853,83 @@ async fn sidebar_ipc_only_decodes_verified_self_coordinates_and_signs_valid_payl
853853 ) ;
854854}
855855
856+ #[ tokio:: test]
857+ async fn event_writer_admits_sidebar_records_and_recipes_by_their_own_coordinate ( ) {
858+ let host = IdentityHost :: fixture ( ) ;
859+ let community = "https://relay.test" ;
860+ for ( coordinate, payload) in [
861+ (
862+ "channel-sections" ,
863+ serde_json:: json!( { "version" : 1 , "sections" : [ { "id" : "group" , "name" : "Group" , "order" : 0 } ] , "assignments" : { "channel" : "group" } } ) ,
864+ ) ,
865+ (
866+ "channel-stars" ,
867+ serde_json:: json!( { "version" : 1 , "channels" : { "channel" : { "starred" : true , "updatedAt" : 1 } } } ) ,
868+ ) ,
869+ (
870+ "channel-mutes" ,
871+ serde_json:: json!( { "version" : 1 , "channels" : { "channel" : { "muted" : true , "updatedAt" : 1 } } } ) ,
872+ ) ,
873+ (
874+ "channel-sort" ,
875+ serde_json:: json!( { "version" : 1 , "groups" : { "channels" : "recent" } } ) ,
876+ ) ,
877+ ] {
878+ let event = host
879+ . sign_sidebar ( coordinate. into ( ) , payload, 1 )
880+ . await
881+ . unwrap ( ) ;
882+ admit_app_data ( & host, & event, community) . await . unwrap ( ) ;
883+ }
884+ let sidebar = host
885+ . sign_sidebar (
886+ "channel-sort" . into ( ) ,
887+ serde_json:: json!( { "version" : 1 , "groups" : { } } ) ,
888+ 1 ,
889+ )
890+ . await
891+ . unwrap ( ) ;
892+ let mut tampered = sidebar. clone ( ) ;
893+ tampered[ "content" ] = serde_json:: json!( "changed" ) ;
894+ assert ! ( admit_app_data( & host, & tampered, community) . await . is_err( ) ) ;
895+ let mut foreign = sidebar. clone ( ) ;
896+ foreign[ "pubkey" ] = serde_json:: json!( "02" . repeat( 32 ) ) ;
897+ assert ! ( admit_app_data( & host, & foreign, community) . await . is_err( ) ) ;
898+
899+ // Anything outside the four sidebar coordinates is still held to the recipe contract.
900+ let sign = |tags : Vec < Vec < String > > , content : String | {
901+ host. sign ( crate :: identity:: EventTemplate {
902+ kind : 30078 ,
903+ created_at : 1 ,
904+ content,
905+ tags,
906+ } )
907+ } ;
908+ let recipe = serde_json:: json!( { "version" : 1 , "community" : community, "deleted" : false ,
909+ "value" : { "type" : "team" , "id" : "team-one" , "name" : "Team" , "agents" : [ ] } } ) ;
910+ let ciphertext = host. kit_cipher ( recipe. to_string ( ) , true ) . await . unwrap ( ) ;
911+ let coordinate = "buzz-channel-kit-v1:https%3A%2F%2Frelay.test:team:team-one" ;
912+ let kit_tags = |d : & str | {
913+ vec ! [
914+ vec![ "d" . to_owned( ) , d. to_owned( ) ] ,
915+ vec![ "t" . to_owned( ) , "buzz-channel-kit-v1" . to_owned( ) ] ,
916+ ]
917+ } ;
918+ let valid = sign ( kit_tags ( coordinate) , ciphertext. clone ( ) )
919+ . await
920+ . unwrap ( ) ;
921+ admit_app_data ( & host, & valid, community) . await . unwrap ( ) ;
922+ // A recipe cannot borrow a sidebar coordinate, and a sidebar record cannot borrow another.
923+ for d in [ "channel-sections" , "read-state:other" , "unknown" ] {
924+ let event = sign ( kit_tags ( d) , ciphertext. clone ( ) ) . await . unwrap ( ) ;
925+ assert ! ( admit_app_data( & host, & event, community) . await . is_err( ) ) ;
926+ }
927+ let mut duplicate = kit_tags ( coordinate) ;
928+ duplicate. push ( vec ! [ "d" . to_owned( ) , "channel-stars" . to_owned( ) ] ) ;
929+ let event = sign ( duplicate, ciphertext) . await . unwrap ( ) ;
930+ assert ! ( admit_app_data( & host, & event, community) . await . is_err( ) ) ;
931+ }
932+
856933#[ tokio:: test]
857934async fn sidebar_decoder_interoperates_with_nostr_tools_nip44_v2 ( ) {
858935 // Produced with nostr-tools 2.25.2, private key [1; 32].
0 commit comments