@@ -440,3 +440,73 @@ test("MockContext.getObject() returns null when no dispatcher registered", async
440440 } ) ;
441441 assertEquals ( note , null ) ;
442442} ) ;
443+
444+ test ( "MockContext.getActorKeyPairs() calls registered key pairs dispatcher" , async ( ) => {
445+ const mockFederation = createFederation < void > ( ) ;
446+
447+ // Generate a test RSA key pair
448+ const keyPair = await crypto . subtle . generateKey (
449+ {
450+ name : "RSASSA-PKCS1-v1_5" ,
451+ modulusLength : 2048 ,
452+ publicExponent : new Uint8Array ( [ 0x01 , 0x00 , 0x01 ] ) ,
453+ hash : "SHA-256" ,
454+ } ,
455+ true ,
456+ [ "sign" , "verify" ] ,
457+ ) ;
458+
459+ // Register actor dispatcher with key pairs dispatcher
460+ mockFederation
461+ . setActorDispatcher ( "/users/{identifier}" , ( ctx , identifier ) => {
462+ return new Person ( {
463+ id : ctx . getActorUri ( identifier ) ,
464+ preferredUsername : identifier ,
465+ } ) ;
466+ } )
467+ . setKeyPairsDispatcher ( ( ctx , identifier ) => {
468+ return [
469+ {
470+ keyId : new URL ( `${ ctx . getActorUri ( identifier ) . href } #main-key` ) ,
471+ privateKey : keyPair . privateKey ,
472+ publicKey : keyPair . publicKey ,
473+ } ,
474+ ] ;
475+ } ) ;
476+
477+ const context = mockFederation . createContext (
478+ new URL ( "https://example.com" ) ,
479+ undefined ,
480+ ) ;
481+
482+ const keyPairs = await context . getActorKeyPairs ( "alice" ) ;
483+
484+ assertEquals ( keyPairs . length , 1 ) ;
485+ assertEquals (
486+ keyPairs [ 0 ] . keyId . href ,
487+ "https://example.com/users/alice#main-key" ,
488+ ) ;
489+ assertEquals ( keyPairs [ 0 ] . privateKey , keyPair . privateKey ) ;
490+ assertEquals ( keyPairs [ 0 ] . publicKey , keyPair . publicKey ) ;
491+ assertEquals ( keyPairs [ 0 ] . cryptographicKey . id ?. href , keyPairs [ 0 ] . keyId . href ) ;
492+ assertEquals (
493+ keyPairs [ 0 ] . cryptographicKey . ownerId ?. href ,
494+ "https://example.com/users/alice" ,
495+ ) ;
496+ assertEquals ( keyPairs [ 0 ] . multikey . id ?. href , keyPairs [ 0 ] . keyId . href ) ;
497+ assertEquals (
498+ keyPairs [ 0 ] . multikey . controllerId ?. href ,
499+ "https://example.com/users/alice" ,
500+ ) ;
501+ } ) ;
502+
503+ test ( "MockContext.getActorKeyPairs() returns empty array when no dispatcher registered" , async ( ) => {
504+ const mockFederation = createFederation < void > ( ) ;
505+ const context = mockFederation . createContext (
506+ new URL ( "https://example.com" ) ,
507+ undefined ,
508+ ) ;
509+
510+ const keyPairs = await context . getActorKeyPairs ( "alice" ) ;
511+ assertEquals ( keyPairs , [ ] ) ;
512+ } ) ;
0 commit comments