Commit 128131cbfd2df26649597c787fbf851b2c81a79d
enable groups
Dominic Tarr committed on 12/29/2018, 5:18:53 AMParent: 56bb6630cc8a69ba81b64ae16b943768e2708080
Files changed
index.js | changed |
index.js | |||
---|---|---|---|
@@ -56,16 +56,14 @@ | |||
56 | 56 … | var state = null | |
57 | 57 … | //cache: {<author>: [scalar_mult(msg_keys[i], <author's latest privacy key>)] | |
58 | 58 … | var cache = {} | |
59 | 59 … | ||
60 | - | ||
60 … | + //maybe in the future, use a level db here. | ||
61 | 61 … | var remoteKeys = sbot._flumeUse('private-groups/remote-keys', Reduce(1, function (acc, data) { | |
62 | 62 … | state = acc = acc || {} | |
63 | 63 … | var msg = data.value | |
64 | 64 … | if(msg.content.type === 'private-msg-key') { | |
65 | - console.log('index msg:', msg) | ||
66 | 65 … | acc[msg.author] = [{sequence: msg.sequence, key: msg.content.key}] | |
67 | - console.log('indexed', acc) | ||
68 | 66 … | cache[msg.author] = null | |
69 | 67 … | } | |
70 | 68 … | return acc | |
71 | 69 … | })) | |
@@ -101,30 +99,35 @@ | |||
101 | 99 … | if(!a_key) return console.log('no author key') | |
102 | 100 … | ||
103 | 101 … | if(!keys_to_try) | |
104 | 102 … | keys_to_try = cache[value.author] = keyState.msgKeys.map(function (curve) { | |
105 | - console.log("A_KEY", a_key, curve) | ||
106 | 103 … | return cl.crypto_scalarmult( | |
107 | 104 … | Buffer.from(curve.private, 'base64'), | |
108 | 105 … | Buffer.from(a_key, 'base64') | |
109 | 106 … | ) | |
110 | 107 … | }) | |
111 | 108 … | ||
112 | - var ctxt = u.ctxt2Buffer(content), nonce = u.id2Buffer(value.previous) | ||
113 | - return group_box.unboxKey(ctxt, nonce, keys_to_try, 8) | ||
109 … | + //the very first message cannot be a group_box. | ||
110 … | + if(value.previous == null) return | ||
111 … | + var ctxt = u.ctxt2Buffer(content) | ||
112 … | + var nonce = u.id2Buffer(value.previous) | ||
114 | 113 … | ||
115 | - /* | ||
114 … | + var key = group_box.unboxKey(ctxt, nonce, keys_to_try, 8) | ||
115 … | + if(key) return key | ||
116 … | + | ||
116 | 117 … | //should group keys be included in this plugin? | |
118 … | + //yes, because box2 supports both direct keys and group keys. | ||
117 | 119 … | var group_keys = [] | |
118 | 120 … | for(var id in keyState.groupKeys) | |
119 | 121 … | group_keys.push(getGroupMsgKey(nonce, keyState.groupKeys[id])) | |
122 … | + | ||
120 | 123 … | //note: if we only allow groups in the first 4 slots | |
121 | 124 … | //that means better sort them before any individuals | |
122 | 125 … | key = group_box.unboxKey( //groups we are in | |
123 | 126 … | ctxt, nonce, group_keys, 4 | |
124 | 127 … | ) | |
125 | 128 … | if(key) return key | |
126 | - */ | ||
129 … | + | ||
127 | 130 … | }, | |
128 | 131 … | value: function (content, key, value) { | |
129 | 132 … | if(!u.isBox2(content)) return | |
130 | 133 … | var ctxt = u.ctxt2Buffer(content) | |
@@ -136,14 +139,14 @@ | |||
136 | 139 … | }) | |
137 | 140 … | ||
138 | 141 … | return { | |
139 | 142 … | get: remoteKeys.get, | |
140 | -// addGroupKey: function (group, cb) { | ||
141 | -// af.get(function () { | ||
142 | -// keyState.groupKeys[hmac(group.id, group.unbox)] = group) | ||
143 | -// af.set(keys, cb) | ||
144 | -// }) | ||
145 | -// }, | ||
143 … | + addGroupKey: function (group, cb) { | ||
144 … | + af.get(function () { | ||
145 … | + keyState.groupKeys[hmac(group.id, group.unbox)] = group) | ||
146 … | + af.set(keys, cb) | ||
147 … | + }) | ||
148 … | + }, | ||
146 | 149 … | addCurvePair: function (curve_keys, cb) { | |
147 | 150 … | onReady(function () { | |
148 | 151 … | if(!u.isCurvePair(curve_keys)) | |
149 | 152 … | return cb(new Error('expected a pair of curve25519 keys')) |
Built with git-ssb-web