From 922d7a247b7867b0a0fc9e2758ab99bc7344f330 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 17 Sep 2019 17:44:22 +0200 Subject: [PATCH 1/3] use latest Team Crypto methods --- scripts/tests/test-rpc.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/scripts/tests/test-rpc.js b/scripts/tests/test-rpc.js index 61d642a6e..113165b05 100644 --- a/scripts/tests/test-rpc.js +++ b/scripts/tests/test-rpc.js @@ -266,22 +266,16 @@ nThen(function (w) { ed: sharedConfig.teamEdKeys, }; + var rosterSeed = Crypto.Team.createSeed(); + var rosterKeys = Crypto.Team.deriveMemberKeys(rosterSeed, oscar.curveKeys); + Roster.create({ network: oscar.network, - channel: sharedConfig.rosterChannel, + channel: rosterKeys.channel, //sharedConfig.rosterChannel, owners: [ oscar.edKeys.edPublic ], - keys: { - myCurvePublic: oscar.curveKeys.curvePublic, - myCurvePrivate: oscar.curveKeys.curvePrivate, - - teamCurvePublic: team.curve.curvePublic, - teamCurvePrivate: team.curve.curvePrivate, - - teamEdPrivate: team.ed.edPrivate, - teamEdPublic: team.ed.edPublic, - }, + keys: rosterKeys, anon_rpc: oscar.anonRpc, lastKnownHash: void 0, }, w(function (err, roster) { From cc4ea50ef6ef809d678eb245ed6eae255e0b421b Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 17 Sep 2019 18:46:24 +0200 Subject: [PATCH 2/3] comment out dead code --- scripts/tests/test-rpc.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/tests/test-rpc.js b/scripts/tests/test-rpc.js index 113165b05..92e911569 100644 --- a/scripts/tests/test-rpc.js +++ b/scripts/tests/test-rpc.js @@ -261,10 +261,12 @@ nThen(function (w) { // network // owners: +/* var team = { curve: sharedConfig.teamCurveKeys, ed: sharedConfig.teamEdKeys, }; +*/ var rosterSeed = Crypto.Team.createSeed(); var rosterKeys = Crypto.Team.deriveMemberKeys(rosterSeed, oscar.curveKeys); From 5c984854c7ec0c064061b48cdf4705d4632c970b Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 17 Sep 2019 18:49:49 +0200 Subject: [PATCH 3/3] WIP --- www/common/outer/roster.js | 56 +++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/www/common/outer/roster.js b/www/common/outer/roster.js index 2db000f80..5000f10ce 100644 --- a/www/common/outer/roster.js +++ b/www/common/outer/roster.js @@ -123,6 +123,11 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) { throw new Error("CANNOT_ADD_TO_UNITIALIZED_ROSTER"); } + // XXX reject if not all of these are present + // displayName + // notifications (channel) + // XXX if no role is passed, assume MEMBER + var changed = false; Object.keys(args).forEach(function (curve) { // FIXME only allow valid curve keys, anything else is pollution @@ -250,6 +255,16 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) { return true; }; + // describe the team {name, description}, (only admin/owner) + commands.TOPIC = function (/* args, author, roster */) { + + }; + + // add a link to an avatar (only owner/admin can do this) + commands.AVATAR = function (/* args, author, roster */) { + + }; + var handleCommand = function (content, author, roster) { if (!(Array.isArray(content) && typeof(author) === 'string')) { throw new Error("INVALID ARGUMENTS"); @@ -269,16 +284,23 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) { return handleCommand(content, author, clone(roster)); }; + var getMessageId = function (msgString) { + return msgString.slice(0, 64); + }; + Roster.create = function (config, _cb) { if (typeof(_cb) !== 'function') { throw new Error("EXPECTED_CALLBACK"); } var cb = Util.once(Util.mkAsync(_cb)); if (!config.network) { return void cb("EXPECTED_NETWORK"); } if (!config.channel || typeof(config.channel) !== 'string' || config.channel.length !== 32) { return void cb("EXPECTED_CHANNEL"); } - if (!config.owners || !Array.isArray(config.owners)) { return void cb("EXPECTED_OWNERS"); } if (!config.keys || typeof(config.keys) !== 'object') { return void cb("EXPECTED_CRYPTO_KEYS"); } if (!config.anon_rpc) { return void cb("EXPECTED_ANON_RPC"); } + + + + var anon_rpc = config.anon_rpc; var keys = config.keys; @@ -291,6 +313,7 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) { var events = { change: Util.mkEvent(), + checkpoint: Util.mkEvent(), }; roster.on = function (key, handler) { @@ -307,6 +330,12 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) { return ref.state; }; + // XXX you must be able to 'leave' a roster session + roster.stop = function () { + // shut down the chainpad-netflux session and... + // cpNf.leave(); + }; + var ready = false; var onReady = function (/* info */) { ready = true; @@ -330,6 +359,10 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) { console.log("ROSTER CONNECTED"); }; + // XXX reuse code from RPC ? + var pending = {}; + //var timeouts = {}; + var onMessage = function (msg, user, vKey, isCp , hash, author) { //console.log("onMessage"); //console.log(typeof(msg), msg); @@ -344,18 +377,31 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) { console.error(err); } + var id = getMessageId(hash); + if (typeof(pending[id]) === 'function') { + // it was your message, execute a callback + if (!changed) { + pending[id]("NO_CHANGE"); + } else { + pending[id](void 0, clone(roster.state)); + } + } else { + // it was not your message, or it timed out... + // execute change ? + console.log("HASH", hash); + } if (changed) { events.change.fire(); } return void console.log(msg); }; - var isReady = function () { return Boolean(ready && me); }; var metadata, crypto; - var send = function (msg, cb) { + var send = function (msg, _cb) { + var cb = Util.once(Util.mkAsync(_cb)); if (!isReady()) { return void cb("NOT_READY"); } var changed = false; @@ -369,12 +415,14 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) { var ciphertext = crypto.encrypt(Sortify(msg)); + var id = getMessageId(ciphertext); + anon_rpc.send('WRITE_PRIVATE_MESSAGE', [ channel, ciphertext ], function (err) { if (err) { return void cb(err); } - cb(); + pending[id] = cb; }); };