Commit 31ba9f2ced690940575b567c8e7a790e97e21ec3
rename ssb-user-invites > ssb-peer-invites
mixmix committed on 2/4/2019, 12:49:46 AMParent: db9daf227bf427c246cd50b93653cdb076843279
Files changed
README.md | changed |
cap.js | changed |
index.js | changed |
test/accept.js | changed |
test/accept2.js | changed |
test/accept3.js | changed |
test/accept4.js | changed |
test/accept5.js | changed |
test/error-without-pubs.js | changed |
test/happy.js | changed |
test/invalid.js | changed |
test/invite-with-pubs.js | changed |
test/will-replicate.js | changed |
types.js | changed |
valid.js | changed |
README.md | ||
---|---|---|
@@ -1,5 +1,5 @@ | ||
1 | -# user-invites | |
1 … | +# peer-invites | |
2 | 2 … | |
3 | 3 … | when ssb was younger, we created the current invite system, |
4 | 4 … | henceforth in this document referred to as the "followbot" system. |
5 | 5 … | special peers called "pubs" can create tokens called "invite codes". |
@@ -22,28 +22,28 @@ | ||
22 | 22 … | |
23 | 23 … | ``` |
24 | 24 … | sbot plugins.install ssb-device-address |
25 | 25 … | sbot plugins.install ssb-identities |
26 | -sbot plugins.install ssb-user-invites | |
26 … | +sbot plugins.install ssb-peer-invites | |
27 | 27 … | ``` |
28 | 28 … | |
29 | 29 … | with user invites, you do not need to have your own pub server, |
30 | -as long as you have a friend has one (that supports user-invites). | |
31 | -To enable user-invites on your pub, install the same modules | |
30 … | +as long as you have a friend has one (that supports peer-invites). | |
31 … | +To enable peer-invites on your pub, install the same modules | |
32 | 32 … | and restart, and also announce a public address using |
33 | 33 … | [ssb-device-address](https://github.com/ssbc/ssb-device-address) |
34 | 34 … | |
35 | 35 … | then restart your sbot local server, there will be a bit of |
36 | 36 … | index building, then you can create invites! |
37 | 37 … | |
38 | 38 … | ``` |
39 | ->sbot userInvites.create | |
39 … | +>sbot peerInvites.create | |
40 | 40 … | invite_code... |
41 | 41 … | ``` |
42 | 42 … | send `invite_code` to your friend and they can use |
43 | 43 … | |
44 | 44 … | ``` |
45 | ->sbot userInvites.openInvite {invite_code} | |
45 … | +>sbot peerInvites.openInvite {invite_code} | |
46 | 46 … | { private:..., reveal:...} |
47 | 47 … | ``` |
48 | 48 … | This shows what you have been invited to. This can contain a welcome |
49 | 49 … | message, or access to private groups (TODO). |
@@ -52,16 +52,16 @@ | ||
52 | 52 … | |
53 | 53 … | then, to actually accept the invite, they do: |
54 | 54 … | |
55 | 55 … | ``` |
56 | ->sbot userInvites.acceptInvite {invite_code} | |
56 … | +>sbot peerInvites.acceptInvite {invite_code} | |
57 | 57 … | accept_message... |
58 | 58 … | ``` |
59 | 59 … | |
60 | 60 … | ## user invites - how it works |
61 | 61 … | |
62 | 62 … | host (user creating the invite) generates a _seed_, and publishes an invitation |
63 | -message (`type:'user-invite'`) for their guest (new user, receiving the invite) | |
63 … | +message (`type:'peer-invite'`) for their guest (new user, receiving the invite) | |
64 | 64 … | The message may contain both a private and a reveal section. |
65 | 65 … | (private section is only readably be the guest, but reveal is published |
66 | 66 … | if they guest accepts the invite). |
67 | 67 … | |
@@ -72,15 +72,15 @@ | ||
72 | 72 … | The guest accepting the invite is a two step process. First they use the |
73 | 73 … | seed and the pub addresses to connect to a pub and request the invite message. |
74 | 74 … | Here they may read a private message from their host, as well as see what will |
75 | 75 … | be revealed once they accept. If they accept, they publish a accept message |
76 | -on their own feed (`type: 'user-invite/accept'`), and then pass that to the pub, | |
77 | -who then publishes a confirm message (`type: user-invite/confirm'`). | |
76 … | +on their own feed (`type: 'peer-invite/accept'`), and then pass that to the pub, | |
77 … | +who then publishes a confirm message (`type: peer-invite/confirm'`). | |
78 | 78 … | Now peers who replicate the pub's feed can see the guest has arrived. |
79 | 79 … | |
80 | 80 … | ## api |
81 | 81 … | |
82 | -### userInvites.create({id?, public?, reveal?, hops?}, cb(err, invite)) | |
82 … | +### peerInvites.create({id?, public?, reveal?, hops?}, cb(err, invite)) | |
83 | 83 … | |
84 | 84 … | does everything needed to create an invite. generates a seed, finds pubs to act |
85 | 85 … | as introducers, and publishes an invite message. |
86 | 86 … | |
@@ -89,9 +89,9 @@ | ||
89 | 89 … | that `private` is read only by the guest, but the key to `reveal` is published |
90 | 90 … | as the guest accepts the invite. (so it's eventually read by everyone, but only |
91 | 91 … | if the guest accepts the invite) |
92 | 92 … | |
93 | -user-invites have a lot more accountability than the previous _followbot_ system. | |
93 … | +peer-invites have a lot more accountability than the previous _followbot_ system. | |
94 | 94 … | You can see who invited who. (so if someone invites an asshole, the community can see |
95 | 95 … | who did that, but the host will already know that, so they'll think twice, or caution |
96 | 96 … | their friend to not be a jerk) `reveal` can be used to enhance this. It could for |
97 | 97 … | example - be used to assign someone a name before they are invited. |
@@ -101,22 +101,22 @@ | ||
101 | 101 … | |
102 | 102 … | on success, cb is called with `{invite: msgId, seed: seed, pubs: [addr,...]}` |
103 | 103 … | this information can be sent to the guest as the invite! |
104 | 104 … | |
105 | -### userInvites.openInvite(invite, cb(err, invite_msg, content) | |
105 … | +### peerInvites.openInvite(invite, cb(err, invite_msg, content) | |
106 | 106 … | |
107 | -"open" an invite. retrives the invite message created by the host (using `userInvites.create`) | |
107 … | +"open" an invite. retrives the invite message created by the host (using `peerInvites.create`) | |
108 | 108 … | and decrypt any encrypted values. since the invite may contain a welcome message, etc, |
109 | -user interfaces implementing user interfaces should process user-invites in two steps. | |
109 … | +user interfaces implementing user interfaces should process peer-invites in two steps. | |
110 | 110 … | firstly opening the invite, then accepting (on user confirmation) |
111 | 111 … | |
112 | 112 … | calling openInvite will not publish a message, but may make a network connection |
113 | 113 … | (if you do not already possess the `invite_msg` which you won't the first time) |
114 | 114 … | |
115 | -### userInvites.acceptInvite(invite, cb) | |
115 … | +### peerInvites.acceptInvite(invite, cb) | |
116 | 116 … | |
117 | -accept the invite. this publishes a `user-invite/accept` message locally, | |
118 | -and then contacts a pub and asks them publish a `user-invite/confirm` message. | |
117 … | +accept the invite. this publishes a `peer-invite/accept` message locally, | |
118 … | +and then contacts a pub and asks them publish a `peer-invite/confirm` message. | |
119 | 119 … | |
120 | 120 … | ## example |
121 | 121 … | |
122 | 122 … | Alice wishes to invite Bob to her corner of the ssb |
@@ -129,9 +129,9 @@ | ||
129 | 129 … | var invite_key = ssbKeys.generate(null, seed) |
130 | 130 … | var invite_cap = require('ssb-config').caps.invite |
131 | 131 … | |
132 | 132 … | alice_sbot.publish(ssbKeys.signObj({ |
133 | - type: 'user-invite', | |
133 … | + type: 'peer-invite', | |
134 | 134 … | invite: invite_key.id, |
135 | 135 … | host: alice.id, |
136 | 136 … | |
137 | 137 … | //optional fields |
@@ -165,9 +165,9 @@ | ||
165 | 165 … | alice's feed. if the invite has reveal and public |
166 | 166 … | fields, bob decrypts them by hashing the seed. |
167 | 167 … | |
168 | 168 … | If bob accepts the invite, |
169 | -bob then creates an "user-invite/accept" message, | |
169 … | +bob then creates an "peer-invite/accept" message, | |
170 | 170 … | which is a proof that he has the seed, and knows |
171 | 171 … | who's invite he is accepting, and indicates the long term |
172 | 172 … | key he will be using. At this point, he can forget the seed. |
173 | 173 … | |
@@ -175,9 +175,9 @@ | ||
175 | 175 … | var invite_key = ssbKeys.generate(null, seed) |
176 | 176 … | var invite_cap = require('ssb-config').caps.invite |
177 | 177 … | |
178 | 178 … | sbot_bob.publish(ssbKeys.signObj({ |
179 | - type: 'user-invite/accept', | |
179 … | + type: 'peer-invite/accept', | |
180 | 180 … | receipt: getId(invite_msg), //the id of the invite message |
181 | 181 … | id: bob.id, //the id we are accepting this invite as. |
182 | 182 … | //if the invite has a reveal, key must be included. |
183 | 183 … | key: hash(hash(seed)) |
@@ -191,9 +191,9 @@ | ||
191 | 191 … | and if is correct, posts a confirm message. |
192 | 192 … | |
193 | 193 … | ``` js |
194 | 194 … | sbot_pub.publish({ |
195 | - type: 'user-invite/confirm', | |
195 … | + type: 'peer-invite/confirm', | |
196 | 196 … | embed: invite_accept_msg //embed the whole message. |
197 | 197 … | }, function (err, invite_confirm_msg) { |
198 | 198 … | ... |
199 | 199 … | }) |
@@ -233,30 +233,30 @@ | ||
233 | 233 … | with what alice says about him) |
234 | 234 … | |
235 | 235 … | ## messages |
236 | 236 … | |
237 | -### user-invite | |
237 … | +### peer-invite | |
238 | 238 … | |
239 | 239 … | published by the host when creating the invite. |
240 | 240 … | |
241 | 241 … | ``` js |
242 | 242 … | { |
243 | - type: 'user-invite', | |
243 … | + type: 'peer-invite', | |
244 | 244 … | host: author_id, // author of this message. |
245 | 245 … | invite: guest_temp_id, // public key guest will use to authenticate |
246 | 246 … | reveal: boxed, // encrypted message to be revealed (optional) |
247 | 247 … | private: boxed, // encrypted message for guest only (optional) |
248 | 248 … | signature: sig, //signed by `guest_temp_id`, to prove that `author` held that. |
249 | 249 … | } |
250 | 250 … | ``` |
251 | 251 … | |
252 | -### user-invite/accept | |
252 … | +### peer-invite/accept | |
253 | 253 … | |
254 | 254 … | published by guest when accepting the above invite. |
255 | 255 … | |
256 | 256 … | ``` js |
257 | 257 … | { |
258 | - type: 'user-invite/accept', | |
258 … | + type: 'peer-invite/accept', | |
259 | 259 … | receipt: invite_id, // the id of the invite message (which is being accepted). |
260 | 260 … | id: guest_long_term_id, // the real identity which the guest will use now. |
261 | 261 … | key: hash(seed), // key used to encrypt the `reveal` field. required if reveal was present. |
262 | 262 … | // if the guest does not wish to reveal that info, they should ask |
@@ -264,16 +264,16 @@ | ||
264 | 264 … | signature: sig // signed by guest_temp_id, to prove that guest_long_term_id held that. |
265 | 265 … | } |
266 | 266 … | ``` |
267 | 267 … | |
268 | -### user-invite/confirm | |
268 … | +### peer-invite/confirm | |
269 | 269 … | |
270 | 270 … | published by a pub, when observing an invite accept message. |
271 | 271 … | it just embeds the accept_message. |
272 | 272 … | |
273 | 273 … | ``` js |
274 | 274 … | { |
275 | - type: 'user-invite/confirm', | |
275 … | + type: 'peer-invite/confirm', | |
276 | 276 … | embed: accept_message |
277 | 277 … | } |
278 | 278 … | ``` |
279 | 279 … |
cap.js | ||
---|---|---|
@@ -5,6 +5,6 @@ | ||
5 | 5 … | 'string' == typeof s ? new Buffer(s, 'utf8') : s |
6 | 6 … | ) |
7 | 7 … | } |
8 | 8 … | |
9 | -module.exports = hash("user-invites:DEVELOPMENT") //XXX DON'T publish without fixing this! | |
9 … | +module.exports = hash("peer-invites:DEVELOPMENT") //XXX DON'T publish without fixing this! | |
10 | 10 … |
index.js | ||
---|---|---|
@@ -9,9 +9,9 @@ | ||
9 | 9 … | var ssbKeys = require('ssb-keys') |
10 | 10 … | var u = require('./util') |
11 | 11 … | |
12 | 12 … | function code(err, c) { |
13 | - err.code = 'user-invites:'+c | |
13 … | + err.code = 'peer-invites:'+c | |
14 | 14 … | return err |
15 | 15 … | } |
16 | 16 … | |
17 | 17 … | function all (stream, cb) { |
@@ -33,9 +33,9 @@ | ||
33 | 33 … | function toBuffer(b) { |
34 | 34 … | return Buffer.isBuffer(b) ? b : Buffer.from(b, 'base64') |
35 | 35 … | } |
36 | 36 … | |
37 | -exports.name = 'user-invites' | |
37 … | +exports.name = 'peer-invites' | |
38 | 38 … | |
39 | 39 … | exports.version = '1.0.0' |
40 | 40 … | exports.manifest = { |
41 | 41 … | getInvite: 'async', |
@@ -60,12 +60,12 @@ | ||
60 | 60 … | // that would be easier to do if this was a levelreduce? (keys: reduce, instead of a single reduce?) |
61 | 61 … | |
62 | 62 … | exports.init = function (sbot, config) { |
63 | 63 … | var init = false |
64 | - var layer = sbot.friends.createLayer('user-invites') | |
64 … | + var layer = sbot.friends.createLayer('peer-invites') | |
65 | 65 … | |
66 | 66 … | var caps = config.caps || {} |
67 | - caps.userInvite = caps.userInvite || require('./cap') | |
67 … | + caps.peerInvite = caps.peerInvite || require('./cap') | |
68 | 68 … | var initial = {invites: {}, accepts: {}, hosts: {}, guests: {}} |
69 | 69 … | |
70 | 70 … | function reduce (acc, data, _seq) { |
71 | 71 … | if(!acc) acc = initial |
@@ -123,9 +123,9 @@ | ||
123 | 123 … | } |
124 | 124 … | |
125 | 125 … | var state |
126 | 126 … | //a hack here, so that we can grab a handle on invites.value.set |
127 | - var invites = sbot._flumeUse('user-invites', function (log, name) { | |
127 … | + var invites = sbot._flumeUse('peer-invites', function (log, name) { | |
128 | 128 … | var _invites = Reduce(3, reduce, null, null, initial)(log, name) |
129 | 129 … | state = _invites.value |
130 | 130 … | return _invites |
131 | 131 … | }) |
@@ -151,9 +151,9 @@ | ||
151 | 151 … | invites.get(function (err, v) { |
152 | 152 … | if(err) return cb(err) |
153 | 153 … | if(v.guests[id]) |
154 | 154 … | return cb(null, { |
155 | - allow: ['userInvites.getInvite', 'userInvites.confirm'], | |
155 … | + allow: ['peerInvites.getInvite', 'peerInvites.confirm'], | |
156 | 156 … | deny: null |
157 | 157 … | }) |
158 | 158 … | fn.apply(null, args) |
159 | 159 … | }) |
@@ -207,9 +207,9 @@ | ||
207 | 207 … | |
208 | 208 … | function getConfirm (invite_id, accept, cb) { |
209 | 209 … | getResponse(invite_id, function (msg) { |
210 | 210 … | return ( |
211 | - msg.content.type === 'user-invite/confirm' && | |
211 … | + msg.content.type === 'peer-invite/confirm' && | |
212 | 212 … | msg.content.embed.content.receipt === invite_id && |
213 | 213 … | deepEquals(msg.content.embed, accept) |
214 | 214 … | ) |
215 | 215 … | }, cb) |
@@ -260,9 +260,9 @@ | ||
260 | 260 … | |
261 | 261 … | function getAccept (invite_id, cb) { |
262 | 262 … | getResponse(invite_id, function (msg) { |
263 | 263 … | return ( |
264 | - msg.content.type === 'user-invite/accept' && | |
264 … | + msg.content.type === 'peer-invite/accept' && | |
265 | 265 … | msg.content.receipt === invite_id |
266 | 266 … | ) |
267 | 267 … | }, cb) |
268 | 268 … | } |
@@ -326,9 +326,9 @@ | ||
326 | 326 … | if(err) { |
327 | 327 … | pushFound(pub, err) |
328 | 328 … | return cb() |
329 | 329 … | } |
330 | - rpc.userInvites.willReplicate({}, function (err, v) { | |
330 … | + rpc.peerInvites.willReplicate({}, function (err, v) { | |
331 | 331 … | //pass through input if true, else (err or false) |
332 | 332 … | //then drop. |
333 | 333 … | pushFound(pub, err, !!v) |
334 | 334 … | cb(null, v && pub) |
@@ -348,9 +348,9 @@ | ||
348 | 348 … | } |
349 | 349 … | |
350 | 350 … | invites.create = function (opts, cb) { |
351 | 351 … | if(isFunction(opts)) |
352 | - return opts(new Error ('user-invites: expected: options *must* be provided.')) | |
352 … | + return opts(new Error ('peer-invites: expected: options *must* be provided.')) | |
353 | 353 … | |
354 | 354 … | var host_id = opts.id || sbot.id |
355 | 355 … | invites.getNearbyPubs(opts, function (err, near) { |
356 | 356 … | if(near.length == 0 && !opts.allowWithoutPubs) |
@@ -384,9 +384,9 @@ | ||
384 | 384 … | ssbClient(keys, { |
385 | 385 … | remote: addr, |
386 | 386 … | caps: {shs: invite.cap || caps.shs}, |
387 | 387 … | manifest: { |
388 | - userInvites: { | |
388 … | + peerInvites: { | |
389 | 389 … | getInvite: 'async', |
390 | 390 … | confirm: 'async' |
391 | 391 … | } |
392 | 392 … | } |
@@ -411,9 +411,9 @@ | ||
411 | 411 … | next(msg) |
412 | 412 … | else |
413 | 413 … | connectFirst(invite, function (err, rpc) { |
414 | 414 … | if(err) return cb(err) |
415 | - rpc.userInvites.getInvite(invite.invite, function (err, msg) { | |
415 … | + rpc.peerInvites.getInvite(invite.invite, function (err, msg) { | |
416 | 416 … | if(err) return cb(err) |
417 | 417 … | next(msg) |
418 | 418 … | }) |
419 | 419 … | }) |
@@ -468,9 +468,9 @@ | ||
468 | 468 … | getConfirm(invite_id, accept, function (err, confirm) { |
469 | 469 … | if(!confirm) |
470 | 470 … | connectFirst(invite, function (err, rpc) { |
471 | 471 … | if(err) return cb(err) |
472 | - rpc.userInvites.confirm(accept, function (err, confirm) { | |
472 … | + rpc.peerInvites.confirm(accept, function (err, confirm) { | |
473 | 473 … | //TODO: store confirms for us in the state. |
474 | 474 … | cb(err, confirm) |
475 | 475 … | }) |
476 | 476 … | }) |
test/accept.js | ||
---|---|---|
@@ -27,9 +27,9 @@ | ||
27 | 27 … | } |
28 | 28 … | |
29 | 29 … | var caps = { |
30 | 30 … | sign: crypto.randomBytes(32),//.toString('base64'), |
31 | - userInvite: crypto.randomBytes(32),//.toString('base64'), | |
31 … | + peerInvite: crypto.randomBytes(32),//.toString('base64'), | |
32 | 32 … | shs: crypto.randomBytes(32),//.toString('base64'), |
33 | 33 … | } |
34 | 34 … | |
35 | 35 … | var alice = createSbot({ |
@@ -60,17 +60,17 @@ | ||
60 | 60 … | { |
61 | 61 … | remote: alice.getAddress('device') || alice.getAddress('device'), |
62 | 62 … | caps: caps, |
63 | 63 … | manifest: { |
64 | - userInvites: { | |
64 … | + peerInvites: { | |
65 | 65 … | getInvite: 'async', |
66 | 66 … | confirm: 'async' |
67 | 67 … | } |
68 | 68 … | } |
69 | 69 … | }, |
70 | 70 … | function (err, _bob) { |
71 | 71 … | if(err) throw err |
72 | - _bob.userInvites.getInvite(msg.key, function (err, invite) { | |
72 … | + _bob.peerInvites.getInvite(msg.key, function (err, invite) { | |
73 | 73 … | if(err) throw err |
74 | 74 … | t.ok(invite) |
75 | 75 … | t.deepEqual(invite, msg.value) |
76 | 76 … | //check this invite is valid. would throw if it wasn't. |
@@ -80,9 +80,9 @@ | ||
80 | 80 … | var accept_content = I.createAccept(invite, seed, bob.id, caps) |
81 | 81 … | |
82 | 82 … | bob.publish(accept_content, function (err, accept) { |
83 | 83 … | if(err) throw err |
84 | - _bob.userInvites.confirm(accept.value, function (err, msg) { | |
84 … | + _bob.peerInvites.confirm(accept.value, function (err, msg) { | |
85 | 85 … | if(err) throw err |
86 | 86 … | t.ok(msg) |
87 | 87 … | var confirm_id = '%'+ssbKeys.hash(JSON.stringify(msg, null, 2)) |
88 | 88 … | alice.get(confirm_id, function (err, _msg) { |
@@ -90,9 +90,9 @@ | ||
90 | 90 … | t.deepEqual(msg, _msg) |
91 | 91 … | |
92 | 92 … | |
93 | 93 … | //calling accept again should return the previous accept message. |
94 | - _bob.userInvites.confirm(accept.value, function (err, msg2) { | |
94 … | + _bob.peerInvites.confirm(accept.value, function (err, msg2) { | |
95 | 95 … | if(err) throw err |
96 | 96 … | t.deepEqual(msg2, msg) |
97 | 97 … | alice.close() |
98 | 98 … | bob.close() |
test/accept2.js | ||
---|---|---|
@@ -30,9 +30,9 @@ | ||
30 | 30 … | } |
31 | 31 … | |
32 | 32 … | var caps = { |
33 | 33 … | sign: crypto.randomBytes(32),//.toString('base64'), |
34 | - userInvite: crypto.randomBytes(32),//.toString('base64'), | |
34 … | + peerInvite: crypto.randomBytes(32),//.toString('base64'), | |
35 | 35 … | shs: crypto.randomBytes(32),//.toString('base64'), |
36 | 36 … | } |
37 | 37 … | |
38 | 38 … | var alice = createSbot({ |
@@ -61,24 +61,24 @@ | ||
61 | 61 … | // var content = I.createInvite(seed, alice.id, {name: 'bob'}, {text: 'welcome to ssb!'}) |
62 | 62 … | // alice.publish(content, function (err, msg) { |
63 | 63 … | // I.verifyInvitePublic(msg.value) |
64 | 64 … | |
65 | - alice.userInvites.create({allowWithoutPubs: true}, function (err, _invite) { | |
65 … | + alice.peerInvites.create({allowWithoutPubs: true}, function (err, _invite) { | |
66 | 66 … | if(err) throw err |
67 | 67 … | var invite = u.parse(_invite) |
68 | 68 … | var seed = invite.seed |
69 | 69 … | var invite_id = invite.invite |
70 | 70 … | |
71 | 71 … | //use device address, just for tests |
72 | 72 … | invite.pubs.push(alice.getAddress('device')) |
73 | 73 … | |
74 | - bob.userInvites.openInvite(invite, function (err, invite_msg, data) { | |
74 … | + bob.peerInvites.openInvite(invite, function (err, invite_msg, data) { | |
75 | 75 … | if(err) throw err |
76 | 76 … | t.ok(invite) |
77 | 77 … | t.equal(toId(invite_msg), invite_id) |
78 | 78 … | t.deepEqual(data, {reveal: undefined, private: undefined}) |
79 | 79 … | //check this invite is valid. would throw if it wasn't. |
80 | - bob.userInvites.acceptInvite(invite, function (err, confirm) { | |
80 … | + bob.peerInvites.acceptInvite(invite, function (err, confirm) { | |
81 | 81 … | if(err) throw err |
82 | 82 … | |
83 | 83 … | //check that alice and bob both understand the other to be following them. |
84 | 84 … | bob.friends.hops({reverse: true}, function (err, hops) { |
test/accept3.js | ||
---|---|---|
@@ -34,9 +34,9 @@ | ||
34 | 34 … | } |
35 | 35 … | |
36 | 36 … | var caps = { |
37 | 37 … | sign: crypto.randomBytes(32),//.toString('base64'), |
38 | - userInvite: crypto.randomBytes(32),//.toString('base64'), | |
38 … | + peerInvite: crypto.randomBytes(32),//.toString('base64'), | |
39 | 39 … | shs: crypto.randomBytes(32),//.toString('base64'), |
40 | 40 … | } |
41 | 41 … | |
42 | 42 … | var alice = createSbot({ |
@@ -62,25 +62,25 @@ | ||
62 | 62 … | //in this test, we use a separate identity to create the invite, |
63 | 63 … | //to test multiple identity support, and also simulate confirmation by pub. |
64 | 64 … | alice.identities.create(function (err, carol_id) { |
65 | 65 … | if(err) throw err |
66 | - alice.userInvites.create({id: carol_id, allowWithoutPubs: true}, function (err, _invite) { | |
66 … | + alice.peerInvites.create({id: carol_id, allowWithoutPubs: true}, function (err, _invite) { | |
67 | 67 … | if(err) throw err |
68 | 68 … | var invite = u.parse(_invite) |
69 | 69 … | var seed = invite.seed |
70 | 70 … | var invite_id = invite.invite |
71 | 71 … | |
72 | 72 … | //use device address, just for tests |
73 | 73 … | invite.pubs.push(alice.getAddress('device')) |
74 | 74 … | |
75 | - bob.userInvites.openInvite(invite, function (err, invite_msg, data) { | |
75 … | + bob.peerInvites.openInvite(invite, function (err, invite_msg, data) { | |
76 | 76 … | if(err) throw err |
77 | 77 … | t.ok(invite) |
78 | 78 … | t.equal(invite_msg.author, carol_id) |
79 | 79 … | t.equal(toId(invite_msg), invite_id) |
80 | 80 … | t.deepEqual(data, {reveal: undefined, private: undefined}) |
81 | 81 … | //check this invite is valid. would throw if it wasn't. |
82 | - bob.userInvites.acceptInvite(invite, function (err, confirm) { | |
82 … | + bob.peerInvites.acceptInvite(invite, function (err, confirm) { | |
83 | 83 … | if(err) throw err |
84 | 84 … | t.equal(confirm.author, alice.id) |
85 | 85 … | //check that alice and bob both understand the other to be following them. |
86 | 86 … | bob.friends.hops({reverse: true}, function (err, hops) { |
test/accept4.js | ||
---|---|---|
@@ -34,9 +34,9 @@ | ||
34 | 34 … | } |
35 | 35 … | |
36 | 36 … | var caps = { |
37 | 37 … | sign: crypto.randomBytes(32),//.toString('base64'), |
38 | - userInvite: crypto.randomBytes(32),//.toString('base64'), | |
38 … | + peerInvite: crypto.randomBytes(32),//.toString('base64'), | |
39 | 39 … | shs: crypto.randomBytes(32),//.toString('base64'), |
40 | 40 … | } |
41 | 41 … | |
42 | 42 … | var alice = createSbot({ |
@@ -55,18 +55,18 @@ | ||
55 | 55 … | }) |
56 | 56 … | |
57 | 57 … | tape('create an invite', function (t) { |
58 | 58 … | |
59 | - alice.userInvites.create({allowWithoutPubs: true}, function (err, _invite) { | |
59 … | + alice.peerInvites.create({allowWithoutPubs: true}, function (err, _invite) { | |
60 | 60 … | if(err) throw err |
61 | 61 … | var invite = u.parse(_invite) |
62 | 62 … | var seed = invite.seed |
63 | 63 … | var invite_id = invite.invite |
64 | 64 … | |
65 | 65 … | //use device address, just for tests |
66 | 66 … | invite.pubs.push(alice.getAddress('device')) |
67 | 67 … | |
68 | - bob.userInvites.openInvite(invite, function (err, invite_msg, data) { | |
68 … | + bob.peerInvites.openInvite(invite, function (err, invite_msg, data) { | |
69 | 69 … | if(err) throw err |
70 | 70 … | t.ok(invite) |
71 | 71 … | t.equal(toId(invite_msg), invite_id) |
72 | 72 … | t.deepEqual(data, {reveal: undefined, private: undefined}) |
@@ -76,9 +76,9 @@ | ||
76 | 76 … | var accept_content = I.createAccept(invite_msg, seed, bob.id, caps) |
77 | 77 … | bob.publish(accept_content, function (err, accept) { |
78 | 78 … | if(err) throw err |
79 | 79 … | |
80 | - bob.userInvites.acceptInvite(invite, function (err, confirm) { | |
80 … | + bob.peerInvites.acceptInvite(invite, function (err, confirm) { | |
81 | 81 … | if(err) throw err |
82 | 82 … | |
83 | 83 … | //check that alice and bob both understand the other to be following them. |
84 | 84 … | bob.friends.hops({reverse: true}, function (err, hops) { |
test/accept5.js | ||
---|---|---|
@@ -34,9 +34,9 @@ | ||
34 | 34 … | } |
35 | 35 … | |
36 | 36 … | var caps = { |
37 | 37 … | sign: crypto.randomBytes(32),//.toString('base64'), |
38 | - userInvite: crypto.randomBytes(32),//.toString('base64'), | |
38 … | + peerInvite: crypto.randomBytes(32),//.toString('base64'), | |
39 | 39 … | shs: crypto.randomBytes(32),//.toString('base64'), |
40 | 40 … | } |
41 | 41 … | |
42 | 42 … | var alice = createSbot({ |
@@ -55,18 +55,18 @@ | ||
55 | 55 … | }) |
56 | 56 … | |
57 | 57 … | tape('create an invite', function (t) { |
58 | 58 … | |
59 | - alice.userInvites.create({allowWithoutPubs: true}, function (err, _invite) { | |
59 … | + alice.peerInvites.create({allowWithoutPubs: true}, function (err, _invite) { | |
60 | 60 … | if(err) throw err |
61 | 61 … | var invite = u.parse(_invite) |
62 | 62 … | var seed = invite.seed |
63 | 63 … | var invite_id = invite.invite |
64 | 64 … | |
65 | 65 … | //use device address, just for tests |
66 | 66 … | invite.pubs.push(alice.getAddress('device')) |
67 | 67 … | |
68 | - bob.userInvites.openInvite(invite, function (err, invite_msg, data) { | |
68 … | + bob.peerInvites.openInvite(invite, function (err, invite_msg, data) { | |
69 | 69 … | if(err) throw err |
70 | 70 … | t.ok(invite) |
71 | 71 … | t.equal(toId(invite_msg), invite_id) |
72 | 72 … | t.deepEqual(data, {reveal: undefined, private: undefined}) |
@@ -81,9 +81,9 @@ | ||
81 | 81 … | //before bob receives it back, and so he calls again. |
82 | 82 … | |
83 | 83 … | alice.publish(I.createConfirm(accept.value), function (err, _confirm) { |
84 | 84 … | if(err) throw err |
85 | - bob.userInvites.acceptInvite(invite, function (err, confirm) { | |
85 … | + bob.peerInvites.acceptInvite(invite, function (err, confirm) { | |
86 | 86 … | if(err) throw err |
87 | 87 … | //alice returns the same confirm message, does not create a new one |
88 | 88 … | t.equal(toId(confirm), toId(_confirm.value), 'id is equal') |
89 | 89 … | t.deepEqual(confirm, _confirm.value) |
test/error-without-pubs.js | ||
---|---|---|
@@ -30,9 +30,9 @@ | ||
30 | 30 … | } |
31 | 31 … | |
32 | 32 … | var caps = { |
33 | 33 … | sign: crypto.randomBytes(32),//.toString('base64'), |
34 | - userInvite: crypto.randomBytes(32),//.toString('base64'), | |
34 … | + peerInvite: crypto.randomBytes(32),//.toString('base64'), | |
35 | 35 … | shs: crypto.randomBytes(32),//.toString('base64'), |
36 | 36 … | } |
37 | 37 … | |
38 | 38 … | var alice = createSbot({ |
@@ -52,9 +52,9 @@ | ||
52 | 52 … | var seed = crypto.randomBytes(32) |
53 | 53 … | |
54 | 54 … | //without the pubs option, do not allow creating |
55 | 55 … | //an invite. |
56 | - alice.userInvites.create({}, function (err, invite) { | |
56 … | + alice.peerInvites.create({}, function (err, invite) { | |
57 | 57 … | t.ok(err) |
58 | 58 … | alice.close() |
59 | 59 … | t.end() |
60 | 60 … | }) |
test/happy.js | ||
---|---|---|
@@ -14,9 +14,9 @@ | ||
14 | 14 … | var bob = ssbKeys.generate(null, hash('BOB')) |
15 | 15 … | |
16 | 16 … | var caps = { |
17 | 17 … | sign: crypto.randomBytes(32),//.toString('base64'), |
18 | - userInvite: crypto.randomBytes(32),//.toString('base64'), | |
18 … | + peerInvite: crypto.randomBytes(32),//.toString('base64'), | |
19 | 19 … | shs: crypto.randomBytes(32),//.toString('base64'), |
20 | 20 … | } |
21 | 21 … | |
22 | 22 … | tape('happy', function (t) { |
test/invalid.js | ||
---|---|---|
@@ -5,9 +5,9 @@ | ||
5 | 5 … | var u = require('../util') |
6 | 6 … | var crypto = require('crypto') |
7 | 7 … | var caps = { |
8 | 8 … | sign: crypto.randomBytes(32),//.toString('base64'), |
9 | - userInvite: crypto.randomBytes(32),//.toString('base64'), | |
9 … | + peerInvite: crypto.randomBytes(32),//.toString('base64'), | |
10 | 10 … | shs: crypto.randomBytes(32),//.toString('base64'), |
11 | 11 … | } |
12 | 12 … | |
13 | 13 … | var invite_key = require('../cap') |
@@ -35,23 +35,23 @@ | ||
35 | 35 … | |
36 | 36 … | //construct a message where host does not match |
37 | 37 … | var seed = hash('seed2') |
38 | 38 … | var keys = ssbKeys.generate(null, seed) |
39 | - var invalid = ssbKeys.signObj(keys, caps.userInvite, { | |
40 | - type: 'user-invite', | |
39 … | + var invalid = ssbKeys.signObj(keys, caps.peerInvite, { | |
40 … | + type: 'peer-invite', | |
41 | 41 … | invite: ssbKeys.generate(null, hash('seed3')), |
42 | 42 … | host: alice.id |
43 | 43 … | }) |
44 | 44 … | |
45 | 45 … | var msg = v.create(null, alice, caps.sign, invalid, new Date('2018-03-26T06:14:18.377Z')) |
46 | 46 … | |
47 | 47 … | throws(t, function () { |
48 | 48 … | i.verifyInvitePublic(msg, caps) |
49 | - }, 'user-invites:invite-signature-failed') | |
49 … | + }, 'peer-invites:invite-signature-failed') | |
50 | 50 … | |
51 | 51 … | throws(t, function () { |
52 | 52 … | i.verifyInvitePrivate(msg, seed, caps) |
53 | - }, 'user-invites:invite-signature-failed') | |
53 … | + }, 'peer-invites:invite-signature-failed') | |
54 | 54 … | |
55 | 55 … | t.end() |
56 | 56 … | }) |
57 | 57 … | |
@@ -61,10 +61,10 @@ | ||
61 | 61 … | //construct a message where host does not match |
62 | 62 … | var seed = hash('seed2') |
63 | 63 … | var keys = ssbKeys.generate(null, seed) |
64 | 64 … | var wrong_seed = hash('wrong_seed') |
65 | - var invalid = ssbKeys.signObj(keys, caps.userInvite, { | |
66 | - type: 'user-invite', | |
65 … | + var invalid = ssbKeys.signObj(keys, caps.peerInvite, { | |
66 … | + type: 'peer-invite', | |
67 | 67 … | invite: keys.id, //correct key |
68 | 68 … | reveal: u.box({hidden: true}, u.hash(u.hash(wrong_seed))), |
69 | 69 … | host: alice.id |
70 | 70 … | }) |
@@ -73,23 +73,23 @@ | ||
73 | 73 … | t.ok(i.verifyInvitePublic(invite_msg, caps)) |
74 | 74 … | |
75 | 75 … | throws(t, function () { |
76 | 76 … | i.verifyInvitePrivate(invite_msg, seed, caps) |
77 | - }, 'user-invites:decrypt-reveal-failed') | |
77 … | + }, 'peer-invites:decrypt-reveal-failed') | |
78 | 78 … | |
79 | 79 … | //say if the invitee creates a accept message anyway. |
80 | 80 … | |
81 | 81 … | throws(t, function () { |
82 | 82 … | i.createAccept(invite_msg, wrong_seed, bob.id, caps) |
83 | - }, 'user-invites:seed-must-match-invite') | |
83 … | + }, 'peer-invites:seed-must-match-invite') | |
84 | 84 … | |
85 | 85 … | |
86 | 86 … | throws(t, function () { |
87 | 87 … | i.createAccept(invite_msg, seed, bob.id, caps) |
88 | - }, 'user-invites:decrypt-reveal-failed') | |
88 … | + }, 'peer-invites:decrypt-reveal-failed') | |
89 | 89 … | |
90 | - var accept = ssbKeys.signObj(ssbKeys.generate(null, seed), caps.userInvite, { | |
91 | - type: 'user-invite/accept', | |
90 … | + var accept = ssbKeys.signObj(ssbKeys.generate(null, seed), caps.peerInvite, { | |
91 … | + type: 'peer-invite/accept', | |
92 | 92 … | receipt: '%'+ssbKeys.hash(JSON.stringify(invite_msg, null, 2)), |
93 | 93 … | id: bob.id, |
94 | 94 … | key: u.hash(u.hash(seed)) //what the reveal key should be. |
95 | 95 … | }) |
@@ -98,20 +98,20 @@ | ||
98 | 98 … | v.create(null, bob, caps.sign, accept, new Date('2018-03-26T06:14:18.377Z')) |
99 | 99 … | |
100 | 100 … | throws(t, function () { |
101 | 101 … | i.verifyAccept(accept_msg, invite_msg, caps) |
102 | - }, 'user-invites:decrypt-accept-reveal-failed') | |
102 … | + }, 'peer-invites:decrypt-accept-reveal-failed') | |
103 | 103 … | |
104 | - var accept2 = ssbKeys.signObj(ssbKeys.generate(null, seed), caps.userInvite, { | |
105 | - type: 'user-invite/accept', | |
104 … | + var accept2 = ssbKeys.signObj(ssbKeys.generate(null, seed), caps.peerInvite, { | |
105 … | + type: 'peer-invite/accept', | |
106 | 106 … | receipt: '%'+ssbKeys.hash(JSON.stringify(invite_msg, null, 2)), |
107 | 107 … | id: bob.id, |
108 | 108 … | key: u.hash('not the key') //what the reveal key should be. |
109 | 109 … | }) |
110 | 110 … | |
111 | 111 … | throws(t, function () { |
112 | 112 … | i.verifyAccept(accept_msg, invite_msg, caps) |
113 | - }, 'user-invites:decrypt-accept-reveal-failed') | |
113 … | + }, 'peer-invites:decrypt-accept-reveal-failed') | |
114 | 114 … | |
115 | 115 … | t.end() |
116 | 116 … | }) |
117 | 117 … | |
@@ -134,9 +134,9 @@ | ||
134 | 134 … | |
135 | 135 … | //just test we do not verify the incorrect invite |
136 | 136 … | throws(t, function () { |
137 | 137 … | i.verifyAccept(accept, invite2, caps) |
138 | - }, 'user-invites:accept-wrong-invite') | |
138 … | + }, 'peer-invites:accept-wrong-invite') | |
139 | 139 … | |
140 | 140 … | t.end() |
141 | 141 … | |
142 | 142 … | }) |
@@ -145,10 +145,10 @@ | ||
145 | 145 … | var seed = hash('seed1') |
146 | 146 … | |
147 | 147 … | var invite = v.create(null, alice, caps.sign, i.createInvite(seed, alice.id, null, null, caps), new Date('2018-03-14T06:14:18.377Z')) |
148 | 148 … | var seed2 = hash('seed2') |
149 | - var accept_content = ssbKeys.signObj(ssbKeys.generate(null, seed2), caps.userInvite, { | |
150 | - type: 'user-invite/accept', | |
149 … | + var accept_content = ssbKeys.signObj(ssbKeys.generate(null, seed2), caps.peerInvite, { | |
150 … | + type: 'peer-invite/accept', | |
151 | 151 … | receipt: '%'+ssbKeys.hash(JSON.stringify(invite, null, 2)), |
152 | 152 … | id: bob.id, |
153 | 153 … | }) |
154 | 154 … | var accept2 = v.create(null, bob, caps.sign, accept_content, new Date('2018-03-14T06:32:18.377Z')) |
@@ -156,9 +156,9 @@ | ||
156 | 156 … | |
157 | 157 … | //just test we do not verify the incorrect invite |
158 | 158 … | throws(t, function () { |
159 | 159 … | i.verifyAccept(accept2, invite, caps) |
160 | - }, 'user-invites:accept-invite-signature-failed') | |
160 … | + }, 'peer-invites:accept-invite-signature-failed') | |
161 | 161 … | |
162 | 162 … | t.end() |
163 | 163 … | }) |
164 | 164 … | |
@@ -166,10 +166,10 @@ | ||
166 | 166 … | tape('wrong invite', function (t) { |
167 | 167 … | var seed = hash('seed1') |
168 | 168 … | |
169 | 169 … | var invite = v.create(null, alice, caps.sign, i.createInvite(seed, alice.id, 'REVEAL', null, caps), new Date('2018-03-14T06:14:18.377Z')) |
170 | - var accept_content = ssbKeys.signObj(ssbKeys.generate(null, seed), caps.userInvite, { | |
171 | - type: 'user-invite/accept', | |
170 … | + var accept_content = ssbKeys.signObj(ssbKeys.generate(null, seed), caps.peerInvite, { | |
171 … | + type: 'peer-invite/accept', | |
172 | 172 … | receipt: '%'+ssbKeys.hash(JSON.stringify(invite, null, 2)), |
173 | 173 … | id: bob.id, |
174 | 174 … | //key is missing! |
175 | 175 … | }) |
@@ -178,9 +178,9 @@ | ||
178 | 178 … | |
179 | 179 … | //just test we do not verify the incorrect invite |
180 | 180 … | throws(t, function () { |
181 | 181 … | i.verifyAccept(accept2, invite, caps) |
182 | - }, 'user-invites:accept-must-reveal-key') | |
182 … | + }, 'peer-invites:accept-must-reveal-key') | |
183 | 183 … | |
184 | 184 … | t.end() |
185 | 185 … | }) |
186 | 186 … |
test/invite-with-pubs.js | ||
---|---|---|
@@ -23,9 +23,9 @@ | ||
23 | 23 … | } |
24 | 24 … | |
25 | 25 … | var caps = { |
26 | 26 … | sign: crypto.randomBytes(32), |
27 | - userInvite: crypto.randomBytes(32), | |
27 … | + peerInvite: crypto.randomBytes(32), | |
28 | 28 … | shs: crypto.randomBytes(32), |
29 | 29 … | } |
30 | 30 … | |
31 | 31 … | var alice = createSbot({ |
@@ -88,9 +88,9 @@ | ||
88 | 88 … | }) |
89 | 89 … | }) |
90 | 90 … | |
91 | 91 … | tape('getNearbyPubs', function (t) { |
92 | - alice.userInvites.getNearbyPubs({}, function (err, pubs) { | |
92 … | + alice.peerInvites.getNearbyPubs({}, function (err, pubs) { | |
93 | 93 … | if(err) throw err |
94 | 94 … | t.ok(pubs.length) |
95 | 95 … | t.end() |
96 | 96 … | }) |
@@ -100,17 +100,17 @@ | ||
100 | 100 … | tape('create-invite, with automatic pubs', function (t) { |
101 | 101 … | var n = 1 |
102 | 102 … | //wait until carol has received alice's invite |
103 | 103 … | carol.post(function (data) { |
104 | - if(data.value.content.type === 'user-invite') { | |
104 … | + if(data.value.content.type === 'peer-invite') { | |
105 | 105 … | console.log('invit?', data) |
106 | 106 … | if(--n) return |
107 | 107 … | t.end() |
108 | 108 … | } |
109 | 109 … | }) |
110 | 110 … | |
111 | 111 … | setTimeout(function () { |
112 | - alice.userInvites.create({}, function (err, _invite) { | |
112 … | + alice.peerInvites.create({}, function (err, _invite) { | |
113 | 113 … | if(err) throw err |
114 | 114 … | console.log('create invite') |
115 | 115 … | invite = u.parse(_invite) |
116 | 116 … | console.log(_invite) |
@@ -124,12 +124,12 @@ | ||
124 | 124 … | alice.get(invite.invite, function (err, invite_msg) { |
125 | 125 … | if(err) throw err |
126 | 126 … | t.deepEqual(invite.pubs, [carol.getAddress('device')]) |
127 | 127 … | |
128 | - bob.userInvites.openInvite(invite, function (err, _invite_msg) { | |
128 … | + bob.peerInvites.openInvite(invite, function (err, _invite_msg) { | |
129 | 129 … | if(err) throw explain(err, 'error while opening invite') |
130 | 130 … | t.deepEqual(_invite_msg, invite_msg) |
131 | - bob.userInvites.acceptInvite(invite, function (err) { | |
131 … | + bob.peerInvites.acceptInvite(invite, function (err) { | |
132 | 132 … | if(err) throw err |
133 | 133 … | t.end() |
134 | 134 … | }) |
135 | 135 … | }) |
@@ -138,9 +138,9 @@ | ||
138 | 138 … | |
139 | 139 … | //there is another race here. seems flumedb |
140 | 140 … | //doesn't like it if you close and immediately |
141 | 141 … | //it receives a message. (should just drop that though) |
142 | -//we don't need to fix that just to get user-invites working, though. | |
142 … | +//we don't need to fix that just to get peer-invites working, though. | |
143 | 143 … | tape('cleanup', function (t) { |
144 | 144 … | setTimeout(function () { |
145 | 145 … | alice.close() |
146 | 146 … | carol.close() |
test/will-replicate.js | ||
---|---|---|
@@ -28,9 +28,9 @@ | ||
28 | 28 … | .use(require('../')) |
29 | 29 … | |
30 | 30 … | var caps = { |
31 | 31 … | sign: crypto.randomBytes(32),//.toString('base64'), |
32 | - userInvite: crypto.randomBytes(32),//.toString('base64'), | |
32 … | + peerInvite: crypto.randomBytes(32),//.toString('base64'), | |
33 | 33 … | shs: crypto.randomBytes(32),//.toString('base64'), |
34 | 34 … | } |
35 | 35 … | |
36 | 36 … | var alice = createSbot({ |
@@ -57,9 +57,9 @@ | ||
57 | 57 … | t.ok(data) |
58 | 58 … | console.log(data) |
59 | 59 … | bob.connect(alice.getAddress(), function (err, _alice) { |
60 | 60 … | if(err) throw err |
61 | - _alice.userInvites.willReplicate(function (err, wr) { | |
61 … | + _alice.peerInvites.willReplicate(function (err, wr) { | |
62 | 62 … | if(err) throw err |
63 | 63 … | t.ok(wr) //alice should replicate for bob's guests |
64 | 64 … | _alice.close() |
65 | 65 … | t.end() |
@@ -70,9 +70,9 @@ | ||
70 | 70 … | |
71 | 71 … | tape("bob won't replicate alice's guests", function (t) { |
72 | 72 … | alice.connect(bob.getAddress(), function (err, _bob) { |
73 | 73 … | if(err) throw err |
74 | - _bob.userInvites.willReplicate(function (err, wr) { | |
74 … | + _bob.peerInvites.willReplicate(function (err, wr) { | |
75 | 75 … | if(err) throw err |
76 | 76 … | t.notOk(wr) //alice should replicate for bob's guests |
77 | 77 … | _bob.close() |
78 | 78 … | t.end() |
types.js | |||
---|---|---|---|
@@ -23,21 +23,21 @@ | |||
23 | 23 … | exports.isInvite = function (msg, caps) { | |
24 | 24 … | if(!isObject(caps)) throw new Error('caps must be provided') | |
25 | 25 … | //return true | |
26 | 26 … | return isObject(msg) && isObject(msg.content) && ( | |
27 | - 'user-invite' === msg.content.type && | ||
27 … | + 'peer-invite' === msg.content.type && | ||
28 | 28 … | ref.isFeed(msg.content.host) && | |
29 | 29 … | ref.isFeed(msg.content.invite) && | |
30 | 30 … | isMaybeBase64(msg.content.reveal) && | |
31 | 31 … | isMaybeBase64(msg.content.public) && | |
32 | 32 … | // signature must be valid !!! | |
33 | - ssbKeys.verifyObj(msg.content.invite, caps.userInvite, msg.content) | ||
33 … | + ssbKeys.verifyObj(msg.content.invite, caps.peerInvite, msg.content) | ||
34 | 34 … | ) | |
35 | 35 … | } | |
36 | 36 … | ||
37 | 37 … | exports.isAccept = function (msg) { | |
38 | 38 … | return isObject(msg) && isObject(msg.content) && ( | |
39 | - 'user-invite/accept' === msg.content.type && | ||
39 … | + 'peer-invite/accept' === msg.content.type && | ||
40 | 40 … | msg.content.id == msg.author && | |
41 | 41 … | ref.isMsg(msg.content.receipt) && | |
42 | 42 … | isMaybeBase64(msg.content.key) && | |
43 | 43 … | // can't verify this without having the invite message. | |
@@ -48,9 +48,9 @@ | |||
48 | 48 … | } | |
49 | 49 … | ||
50 | 50 … | exports.isConfirm = function (msg) { | |
51 | 51 … | return isObject(msg) && isObject(msg.content) && ( | |
52 | - 'user-invite/confirm' === msg.content.type && | ||
52 … | + 'peer-invite/confirm' === msg.content.type && | ||
53 | 53 … | exports.isAccept(msg.content.embed) && | |
54 | 54 … | //second pointer back to receipt, so that links can find it | |
55 | 55 … | //(since it unfortunately does not handle links nested deeper | |
56 | 56 … | //inside objects. when we look up the message, |
valid.js | ||
---|---|---|
@@ -4,9 +4,9 @@ | ||
4 | 4 … | |
5 | 5 … | var invite_key = require('./cap') |
6 | 6 … | |
7 | 7 … | function code(err, c) { |
8 | - err.code = 'user-invites:'+c | |
8 … | + err.code = 'peer-invites:'+c | |
9 | 9 … | return err |
10 | 10 … | } |
11 | 11 … | |
12 | 12 … | function isObject (o) { |
@@ -40,11 +40,11 @@ | ||
40 | 40 … | |
41 | 41 … | seed = toBuffer(seed) |
42 | 42 … | var keys = ssbKeys.generate(null, seed) //K |
43 | 43 … | if(keys.id === host) |
44 | - throw code(new Error('do not create invite with own public key'), 'user-invites:no-own-goal') | |
45 | - return ssbKeys.signObj(keys, caps.userInvite, { | |
46 | - type: 'user-invite', | |
44 … | + throw code(new Error('do not create invite with own public key'), 'peer-invites:no-own-goal') | |
45 … | + return ssbKeys.signObj(keys, caps.peerInvite, { | |
46 … | + type: 'peer-invite', | |
47 | 47 … | invite: keys.id, |
48 | 48 … | host: host, //sign our own key, to prove we created K |
49 | 49 … | reveal: reveal ? u.box(reveal, hash2(seed)) : undefined, |
50 | 50 … | private: private ? u.box(private, hash(seed)) : undefined |
@@ -56,9 +56,9 @@ | ||
56 | 56 … | |
57 | 57 … | if(msg.content.host != msg.author) |
58 | 58 … | throw code(new Error('host did not match author'), 'host-must-match-author') |
59 | 59 … | |
60 | - if(!ssbKeys.verifyObj(msg.content.invite, caps.userInvite, msg.content)) | |
60 … | + if(!ssbKeys.verifyObj(msg.content.invite, caps.peerInvite, msg.content)) | |
61 | 61 … | throw code(new Error('invalid invite signature'), 'invite-signature-failed') |
62 | 62 … | |
63 | 63 … | //an ordinary message so doesn't use special hmac_key, unless configed to. |
64 | 64 … | if(!ssbKeys.verifyObj(msg.author, caps.sign, msg)) |
@@ -92,21 +92,21 @@ | ||
92 | 92 … | if(keys.id != msg.content.invite) |
93 | 93 … | throw code(new Error('seed does not match invite'), 'seed-must-match-invite') |
94 | 94 … | var inviteId = toMsgId(msg) |
95 | 95 … | var content = { |
96 | - type: 'user-invite/accept', | |
96 … | + type: 'peer-invite/accept', | |
97 | 97 … | receipt: inviteId, |
98 | 98 … | id: id |
99 | 99 … | } |
100 | 100 … | if(msg.content.reveal) |
101 | 101 … | content.key = hash2(seed).toString('base64') |
102 | - return ssbKeys.signObj(keys, caps.userInvite, content) | |
102 … | + return ssbKeys.signObj(keys, caps.peerInvite, content) | |
103 | 103 … | } |
104 | 104 … | |
105 | 105 … | exports.verifyAcceptOnly = function (accept, caps) { |
106 | 106 … | if(!isObject(caps)) throw new Error('caps *must* be provided') |
107 | - if(accept.content.type !== 'user-invite/accept') | |
108 | - throw code(new Error('accept must be type: "user-invite/accept", was:'+JSON.stringify(accept.content.type)), 'accept-message-type') | |
107 … | + if(accept.content.type !== 'peer-invite/accept') | |
108 … | + throw code(new Error('accept must be type: "peer-invite/accept", was:'+JSON.stringify(accept.content.type)), 'accept-message-type') | |
109 | 109 … | if(!isMsg(accept.content.receipt)) |
110 | 110 … | throw code(new Error('accept must reference invite message id'), 'accept-reference-invite') |
111 | 111 … | //verify signed as ordinary message. |
112 | 112 … | if(!ssbKeys.verifyObj(accept.content.id, caps.sign, accept)) |
@@ -118,10 +118,10 @@ | ||
118 | 118 … | if(!invite_msg) throw new Error('invite must be provided') |
119 | 119 … | |
120 | 120 … | exports.verifyAcceptOnly(accept, caps) |
121 | 121 … | |
122 | - if(invite_msg.content.type !== 'user-invite') | |
123 | - throw code(new Error('accept must be type: invite, was:'+accept.content.type), 'user-invites:invite-message-type') | |
122 … | + if(invite_msg.content.type !== 'peer-invite') | |
123 … | + throw code(new Error('accept must be type: invite, was:'+accept.content.type), 'peer-invites:invite-message-type') | |
124 | 124 … | |
125 | 125 … | var invite_id = toMsgId(invite_msg) |
126 | 126 … | var reveal |
127 | 127 … | |
@@ -136,17 +136,17 @@ | ||
136 | 136 … | reveal = u.unbox(invite_msg.content.reveal, toBuffer(accept.content.key)) |
137 | 137 … | if(!reveal) throw code(new Error('accept did not correctly reveal invite'), 'decrypt-accept-reveal-failed') |
138 | 138 … | } |
139 | 139 … | |
140 | - if(!ssbKeys.verifyObj(invite_msg.content.invite, caps.userInvite, accept.content)) | |
140 … | + if(!ssbKeys.verifyObj(invite_msg.content.invite, caps.peerInvite, accept.content)) | |
141 | 141 … | throw code(new Error('did not verify invite-acceptance contents'), 'accept-invite-signature-failed') |
142 | 142 … | //an ordinary message, so does not use hmac_key |
143 | 143 … | return reveal || true |
144 | 144 … | } |
145 | 145 … | |
146 | 146 … | exports.createConfirm = function (accept) { |
147 | 147 … | return { |
148 | - type: 'user-invite/confirm', | |
148 … | + type: 'peer-invite/confirm', | |
149 | 149 … | embed: accept, |
150 | 150 … | //second pointer back to receipt, so that links can find it |
151 | 151 … | //(since it unfortunately does not handle links nested deeper |
152 | 152 … | //inside objects. when we look up the message, |
Built with git-ssb-web