Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we see an example of plainstream? #24

Open
nichoth opened this issue Feb 18, 2021 · 0 comments
Open

Can we see an example of plainstream? #24

nichoth opened this issue Feb 18, 2021 · 0 comments

Comments

@nichoth
Copy link

nichoth commented Feb 18, 2021

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant