Skip to content

Instantly share code, notes, and snippets.

View AljoschaMeyer's full-sized avatar

Aljoscha Meyer AljoschaMeyer

View GitHub Profile
@AljoschaMeyer
AljoschaMeyer / cargo.toml
Created March 11, 2018 21:22
Demo of ssb-client-rs
[package]
name = "demo-ssb-client"
version = "0.1.0"
authors = ["AljoschaMeyer <mail@aljoscha-meyer.de>"]
[dependencies]
tokio = "0.1.3"
futures = "0.1.18"
sodiumoxide = "0.0.16"
@AljoschaMeyer
AljoschaMeyer / lib.rs
Created March 10, 2018 16:40
What ps could look like if LocalExecutor::spawn_local didn't require a 'static bound.
//! Implements the [packet-stream protocol](https://github.com/ssbc/packet-stream) in rust.
#![deny(missing_docs)]
extern crate atm_async_utils;
#[macro_use]
extern crate futures_core;
extern crate futures_executor;
extern crate futures_sink;
extern crate futures_io;
extern crate futures_util;
@AljoschaMeyer
AljoschaMeyer / main.rs
Created March 5, 2018 21:46
Example of using muxrpc over secret_stream with an event loop.
#![feature(try_from)]
#![feature(ip_constructors)]
extern crate futures;
extern crate tokio;
extern crate tokio_io;
extern crate sodiumoxide;
extern crate secret_stream;
extern crate ssb_common;
extern crate ssb_keyfile;
@AljoschaMeyer
AljoschaMeyer / main.rs
Created March 4, 2018 12:47
Example of using muxrpc-rs
#![feature(try_from)]
#![feature(ip_constructors)]
extern crate futures;
extern crate tokio;
extern crate tokio_io;
extern crate sodiumoxide;
extern crate secret_stream;
extern crate ssb_common;
extern crate ssb_keyfile;
@AljoschaMeyer
AljoschaMeyer / main.rs
Created February 20, 2018 14:08
Example of using packet-stream-rs
#![feature(try_from)]
#![feature(ip_constructors)]
extern crate futures;
extern crate tokio;
extern crate tokio_io;
extern crate sodiumoxide;
extern crate secret_stream;
extern crate ssb_common;
extern crate ssb_keyfile;
digraph OverallApproach {
/* rankdir=LR; */
node [shape=box];
ssbclient[label="ssb-client"];
ms[label="multiserver"];
muxrpc[label="muxrpc"];
ssbconf[label="ssb-config"];
@AljoschaMeyer
AljoschaMeyer / crypto-client.js
Last active October 31, 2017 19:08
js implementation of secret-handshake, with a focus on readability
const {
crypto_auth_verify,
crypto_auth,
crypto_scalarmult,
crypto_hash_sha256,
crypto_sign_ed25519_sk_to_curve25519,
crypto_sign_ed25519_pk_to_curve25519,
crypto_secretbox_open_easy,
crypto_sign_verify_detached,
crypto_sign_detached,
@AljoschaMeyer
AljoschaMeyer / dialogue.md
Last active September 17, 2017 12:51
Draft of a multiplexing abstraction.

Dialogue

A simple abstraction layer for multiplexed, streaming communication between two peers. Inpired by/based on packet-stream, but with a few breaking changes.

Over a reliable, ordered, one-to-one, duplex communication channel, the following types of communication are supported:

  • message: Send a packet to the peer.
  • request: Send a packet to the peer, receive a response packet. Can be cancelled by either participant.
  • duplex: Send many packets to the peer, receive many response packets. Both participants can cancel the duplex.

Additionally, implementations may provide restricted versions of duplexes, e.g. unidirectional streams, or unidirectional streams which expect a single response after signalling their end. On the wire, these would simply use duplex packets, only the interface for the programmer is restricted.

@AljoschaMeyer
AljoschaMeyer / index.js
Created June 9, 2017 14:26
Generate minimal test data for box-stream
const sodium = require('chloride');
const boxes = require('pull-box-stream');
const pull = require('pull-stream');
const encryptionKey = Buffer.from([162,29,153,150,123,225,10,173,175,201,160,34,190,179,158,14,176,105,232,238,97,66,133,194,250,148,199,7,34,157,174,24, 44,140,79,227,23,153,202,203,81,40,114,59,56,167,63,166,201,9,50,152,0,255,226,147]);
const plain1 = Buffer.from([0, 1, 2, 3, 4, 5, 6, 7]);
const plain2 = Buffer.from([7, 6, 5, 4, 3, 2, 1, 0]);
@AljoschaMeyer
AljoschaMeyer / data.json
Last active June 5, 2017 18:21
Generate minimal test data for secret-handshake
{"app":{"type":"Buffer","data":[52,185,47,13,238,73,54,193,180,19,66,202,191,136,67,66,207,130,141,57,155,24,157,10,109,135,81,181,218,83,45,48]},"client_pub":{"type":"Buffer","data":[205,114,202,57,38,184,63,222,144,155,64,179,144,197,229,104,203,61,147,95,133,75,69,81,114,149,95,100,152,202,196,229]},"client_sec":{"type":"Buffer","data":[113,68,145,235,255,76,78,208,78,118,201,180,137,97,236,25,175,200,166,106,242,242,232,76,25,143,73,127,1,32,29,173,205,114,202,57,38,184,63,222,144,155,64,179,144,197,229,104,203,61,147,95,133,75,69,81,114,149,95,100,152,202,196,229]},"client_eph_pub":{"type":"Buffer","data":[5,183,99,118,32,105,120,85,99,217,136,206,182,220,187,54,53,38,182,52,146,127,126,36,34,252,151,147,154,206,118,63]},"client_eph_sec":{"type":"Buffer","data":[64,228,231,100,36,145,174,8,56,182,83,77,150,44,120,250,125,72,251,41,5,24,16,209,57,53,192,149,157,160,83,64]},"server_pub":{"type":"Buffer","data":[102,24,108,176,85,212,227,58,158,129,206,237,133,175,164,37,166,135,224,46,113,177,173,46,53,39,