auditdrivencrypto / secret-handshake

Mutually authenticating key agreement handshake
MIT License
202 stars 29 forks source link

Can we see an example of `plainstream`? #24

Open nichoth opened 3 years ago

nichoth commented 3 years ago

It's unclear from the readme as to what sort of stream plainstream is -- source, transform, sink? It would be cool to see an example that sends some data between client and server, like a chatting example, if I'm not misunderstanding this too badly.

var SHS = require('secret-handshake')

var cl = require('chloride')
var appKey = ... //32 random bytes
var alice = cl.crypto_sign_keypair() //client
var bob = cl.crypto_sign_keypair()   //server

function authorize(id, cb) {
  cb(null, check(id)) //check wether id is authorized.
}

//initialize, with default timeouts.
var ServerStream = SHS.createServer(alice, authorize, appKey)
var ClientStream = SHS.createClient(bob, appkey)

var alice_stream = ServerStream(function (err, stream) {
  ...
  // **in here, what do you do with stream?**
})

var bob_stream = ClientStream(alice.publicKey, function (err, stream) {
  ...
})

//simulate a streaming network connection by connecting streams together
pull(alice_stream, bob_stream, alice_stream)