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
48
48
{
49
49
id: crypto .randomBytes (32 ), // A randomly-generated peer ID,
50
50
keyPair: HypercoreProtocol .keyPair (), // A NOISE keypair that's used across all connections.
51
+ onauthenticate : (remotePublicKey , cb ) => { cb () }, // A NOISE keypair authentication hook
51
52
}
52
53
```
53
54
Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ class CorestoreNetworker extends Nanoresource {
17
17
this . _replicationOpts = {
18
18
encrypt : true ,
19
19
live : true ,
20
- keyPair : this . keyPair
20
+ keyPair : this . keyPair ,
21
+ onauthenticate : opts . onauthenticate
21
22
}
22
23
23
24
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 => {
489
489
t . end ( )
490
490
} )
491
491
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
+
492
511
async function create ( opts = { } ) {
493
512
if ( ! bootstrap ) {
494
513
bootstrap = dht ( {
You can’t perform that action at this time.
0 commit comments