File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ Creates a new SwarmNetworker that will open replication streams on the `corestor
4848{
4949 id: crypto .randomBytes (32 ), // A randomly-generated peer ID,
5050 keyPair: HypercoreProtocol .keyPair (), // A NOISE keypair that's used across all connections.
51+ onauthenticate : (remotePublicKey , cb ) => { cb () }, // A NOISE keypair authentication hook
5152}
5253```
5354
Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ class CorestoreNetworker extends Nanoresource {
1717 this . _replicationOpts = {
1818 encrypt : true ,
1919 live : true ,
20- keyPair : this . keyPair
20+ keyPair : this . keyPair ,
21+ onauthenticate : opts . onauthenticate
2122 }
2223
2324 this . streams = new Set ( )
Original file line number Diff line number Diff line change @@ -489,6 +489,25 @@ test('bidirectional extension send/receive', async t => {
489489 t . end ( )
490490} )
491491
492+ test . only ( 'onauthentication hook' , async t => {
493+ t . plan ( 2 )
494+ const { networker : networker1 } = await create ( {
495+ onauthenticate ( peerPublicKey , cb ) {
496+ t . deepEquals ( peerPublicKey , networker2 . keyPair . publicKey )
497+ cb ( )
498+ }
499+ } )
500+ const { networker : networker2 } = await create ( )
501+
502+ const dkey = hypercoreCrypto . randomBytes ( 32 )
503+ await networker1 . configure ( dkey )
504+ await networker2 . configure ( dkey )
505+
506+ await new Promise ( resolve => setTimeout ( resolve , 100 ) )
507+ await cleanup ( [ networker1 , networker2 ] )
508+ t . end ( )
509+ } )
510+
492511async function create ( opts = { } ) {
493512 if ( ! bootstrap ) {
494513 bootstrap = dht ( {
You can’t perform that action at this time.
0 commit comments