git ssb

0+

Dominic / ssb-peer-invites



Commit 31ba9f2ced690940575b567c8e7a790e97e21ec3

rename ssb-user-invites > ssb-peer-invites

mixmix committed on 2/4/2019, 12:49:46 AM
Parent: db9daf227bf427c246cd50b93653cdb076843279

Files changed

README.mdchanged
cap.jschanged
index.jschanged
test/accept.jschanged
test/accept2.jschanged
test/accept3.jschanged
test/accept4.jschanged
test/accept5.jschanged
test/error-without-pubs.jschanged
test/happy.jschanged
test/invalid.jschanged
test/invite-with-pubs.jschanged
test/will-replicate.jschanged
types.jschanged
valid.jschanged
README.mdView
@@ -1,5 +1,5 @@
1-# user-invites
1 +# peer-invites
22
33 when ssb was younger, we created the current invite system,
44 henceforth in this document referred to as the "followbot" system.
55 special peers called "pubs" can create tokens called "invite codes".
@@ -22,28 +22,28 @@
2222
2323 ```
2424 sbot plugins.install ssb-device-address
2525 sbot plugins.install ssb-identities
26-sbot plugins.install ssb-user-invites
26 +sbot plugins.install ssb-peer-invites
2727 ```
2828
2929 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
3232 and restart, and also announce a public address using
3333 [ssb-device-address](https://github.com/ssbc/ssb-device-address)
3434
3535 then restart your sbot local server, there will be a bit of
3636 index building, then you can create invites!
3737
3838 ```
39->sbot userInvites.create
39 +>sbot peerInvites.create
4040 invite_code...
4141 ```
4242 send `invite_code` to your friend and they can use
4343
4444 ```
45->sbot userInvites.openInvite {invite_code}
45 +>sbot peerInvites.openInvite {invite_code}
4646 { private:..., reveal:...}
4747 ```
4848 This shows what you have been invited to. This can contain a welcome
4949 message, or access to private groups (TODO).
@@ -52,16 +52,16 @@
5252
5353 then, to actually accept the invite, they do:
5454
5555 ```
56->sbot userInvites.acceptInvite {invite_code}
56 +>sbot peerInvites.acceptInvite {invite_code}
5757 accept_message...
5858 ```
5959
6060 ## user invites - how it works
6161
6262 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)
6464 The message may contain both a private and a reveal section.
6565 (private section is only readably be the guest, but reveal is published
6666 if they guest accepts the invite).
6767
@@ -72,15 +72,15 @@
7272 The guest accepting the invite is a two step process. First they use the
7373 seed and the pub addresses to connect to a pub and request the invite message.
7474 Here they may read a private message from their host, as well as see what will
7575 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'`).
7878 Now peers who replicate the pub's feed can see the guest has arrived.
7979
8080 ## api
8181
82-### userInvites.create({id?, public?, reveal?, hops?}, cb(err, invite))
82 +### peerInvites.create({id?, public?, reveal?, hops?}, cb(err, invite))
8383
8484 does everything needed to create an invite. generates a seed, finds pubs to act
8585 as introducers, and publishes an invite message.
8686
@@ -89,9 +89,9 @@
8989 that `private` is read only by the guest, but the key to `reveal` is published
9090 as the guest accepts the invite. (so it's eventually read by everyone, but only
9191 if the guest accepts the invite)
9292
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.
9494 You can see who invited who. (so if someone invites an asshole, the community can see
9595 who did that, but the host will already know that, so they'll think twice, or caution
9696 their friend to not be a jerk) `reveal` can be used to enhance this. It could for
9797 example - be used to assign someone a name before they are invited.
@@ -101,22 +101,22 @@
101101
102102 on success, cb is called with `{invite: msgId, seed: seed, pubs: [addr,...]}`
103103 this information can be sent to the guest as the invite!
104104
105-### userInvites.openInvite(invite, cb(err, invite_msg, content)
105 +### peerInvites.openInvite(invite, cb(err, invite_msg, content)
106106
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`)
108108 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.
110110 firstly opening the invite, then accepting (on user confirmation)
111111
112112 calling openInvite will not publish a message, but may make a network connection
113113 (if you do not already possess the `invite_msg` which you won't the first time)
114114
115-### userInvites.acceptInvite(invite, cb)
115 +### peerInvites.acceptInvite(invite, cb)
116116
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.
119119
120120 ## example
121121
122122 Alice wishes to invite Bob to her corner of the ssb
@@ -129,9 +129,9 @@
129129 var invite_key = ssbKeys.generate(null, seed)
130130 var invite_cap = require('ssb-config').caps.invite
131131
132132 alice_sbot.publish(ssbKeys.signObj({
133- type: 'user-invite',
133 + type: 'peer-invite',
134134 invite: invite_key.id,
135135 host: alice.id,
136136
137137 //optional fields
@@ -165,9 +165,9 @@
165165 alice's feed. if the invite has reveal and public
166166 fields, bob decrypts them by hashing the seed.
167167
168168 If bob accepts the invite,
169-bob then creates an "user-invite/accept" message,
169 +bob then creates an "peer-invite/accept" message,
170170 which is a proof that he has the seed, and knows
171171 who's invite he is accepting, and indicates the long term
172172 key he will be using. At this point, he can forget the seed.
173173
@@ -175,9 +175,9 @@
175175 var invite_key = ssbKeys.generate(null, seed)
176176 var invite_cap = require('ssb-config').caps.invite
177177
178178 sbot_bob.publish(ssbKeys.signObj({
179- type: 'user-invite/accept',
179 + type: 'peer-invite/accept',
180180 receipt: getId(invite_msg), //the id of the invite message
181181 id: bob.id, //the id we are accepting this invite as.
182182 //if the invite has a reveal, key must be included.
183183 key: hash(hash(seed))
@@ -191,9 +191,9 @@
191191 and if is correct, posts a confirm message.
192192
193193 ``` js
194194 sbot_pub.publish({
195- type: 'user-invite/confirm',
195 + type: 'peer-invite/confirm',
196196 embed: invite_accept_msg //embed the whole message.
197197 }, function (err, invite_confirm_msg) {
198198 ...
199199 })
@@ -233,30 +233,30 @@
233233 with what alice says about him)
234234
235235 ## messages
236236
237-### user-invite
237 +### peer-invite
238238
239239 published by the host when creating the invite.
240240
241241 ``` js
242242 {
243- type: 'user-invite',
243 + type: 'peer-invite',
244244 host: author_id, // author of this message.
245245 invite: guest_temp_id, // public key guest will use to authenticate
246246 reveal: boxed, // encrypted message to be revealed (optional)
247247 private: boxed, // encrypted message for guest only (optional)
248248 signature: sig, //signed by `guest_temp_id`, to prove that `author` held that.
249249 }
250250 ```
251251
252-### user-invite/accept
252 +### peer-invite/accept
253253
254254 published by guest when accepting the above invite.
255255
256256 ``` js
257257 {
258- type: 'user-invite/accept',
258 + type: 'peer-invite/accept',
259259 receipt: invite_id, // the id of the invite message (which is being accepted).
260260 id: guest_long_term_id, // the real identity which the guest will use now.
261261 key: hash(seed), // key used to encrypt the `reveal` field. required if reveal was present.
262262 // if the guest does not wish to reveal that info, they should ask
@@ -264,16 +264,16 @@
264264 signature: sig // signed by guest_temp_id, to prove that guest_long_term_id held that.
265265 }
266266 ```
267267
268-### user-invite/confirm
268 +### peer-invite/confirm
269269
270270 published by a pub, when observing an invite accept message.
271271 it just embeds the accept_message.
272272
273273 ``` js
274274 {
275- type: 'user-invite/confirm',
275 + type: 'peer-invite/confirm',
276276 embed: accept_message
277277 }
278278 ```
279279
cap.jsView
@@ -5,6 +5,6 @@
55 'string' == typeof s ? new Buffer(s, 'utf8') : s
66 )
77 }
88
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!
1010
index.jsView
@@ -9,9 +9,9 @@
99 var ssbKeys = require('ssb-keys')
1010 var u = require('./util')
1111
1212 function code(err, c) {
13- err.code = 'user-invites:'+c
13 + err.code = 'peer-invites:'+c
1414 return err
1515 }
1616
1717 function all (stream, cb) {
@@ -33,9 +33,9 @@
3333 function toBuffer(b) {
3434 return Buffer.isBuffer(b) ? b : Buffer.from(b, 'base64')
3535 }
3636
37-exports.name = 'user-invites'
37 +exports.name = 'peer-invites'
3838
3939 exports.version = '1.0.0'
4040 exports.manifest = {
4141 getInvite: 'async',
@@ -60,12 +60,12 @@
6060 // that would be easier to do if this was a levelreduce? (keys: reduce, instead of a single reduce?)
6161
6262 exports.init = function (sbot, config) {
6363 var init = false
64- var layer = sbot.friends.createLayer('user-invites')
64 + var layer = sbot.friends.createLayer('peer-invites')
6565
6666 var caps = config.caps || {}
67- caps.userInvite = caps.userInvite || require('./cap')
67 + caps.peerInvite = caps.peerInvite || require('./cap')
6868 var initial = {invites: {}, accepts: {}, hosts: {}, guests: {}}
6969
7070 function reduce (acc, data, _seq) {
7171 if(!acc) acc = initial
@@ -123,9 +123,9 @@
123123 }
124124
125125 var state
126126 //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) {
128128 var _invites = Reduce(3, reduce, null, null, initial)(log, name)
129129 state = _invites.value
130130 return _invites
131131 })
@@ -151,9 +151,9 @@
151151 invites.get(function (err, v) {
152152 if(err) return cb(err)
153153 if(v.guests[id])
154154 return cb(null, {
155- allow: ['userInvites.getInvite', 'userInvites.confirm'],
155 + allow: ['peerInvites.getInvite', 'peerInvites.confirm'],
156156 deny: null
157157 })
158158 fn.apply(null, args)
159159 })
@@ -207,9 +207,9 @@
207207
208208 function getConfirm (invite_id, accept, cb) {
209209 getResponse(invite_id, function (msg) {
210210 return (
211- msg.content.type === 'user-invite/confirm' &&
211 + msg.content.type === 'peer-invite/confirm' &&
212212 msg.content.embed.content.receipt === invite_id &&
213213 deepEquals(msg.content.embed, accept)
214214 )
215215 }, cb)
@@ -260,9 +260,9 @@
260260
261261 function getAccept (invite_id, cb) {
262262 getResponse(invite_id, function (msg) {
263263 return (
264- msg.content.type === 'user-invite/accept' &&
264 + msg.content.type === 'peer-invite/accept' &&
265265 msg.content.receipt === invite_id
266266 )
267267 }, cb)
268268 }
@@ -326,9 +326,9 @@
326326 if(err) {
327327 pushFound(pub, err)
328328 return cb()
329329 }
330- rpc.userInvites.willReplicate({}, function (err, v) {
330 + rpc.peerInvites.willReplicate({}, function (err, v) {
331331 //pass through input if true, else (err or false)
332332 //then drop.
333333 pushFound(pub, err, !!v)
334334 cb(null, v && pub)
@@ -348,9 +348,9 @@
348348 }
349349
350350 invites.create = function (opts, cb) {
351351 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.'))
353353
354354 var host_id = opts.id || sbot.id
355355 invites.getNearbyPubs(opts, function (err, near) {
356356 if(near.length == 0 && !opts.allowWithoutPubs)
@@ -384,9 +384,9 @@
384384 ssbClient(keys, {
385385 remote: addr,
386386 caps: {shs: invite.cap || caps.shs},
387387 manifest: {
388- userInvites: {
388 + peerInvites: {
389389 getInvite: 'async',
390390 confirm: 'async'
391391 }
392392 }
@@ -411,9 +411,9 @@
411411 next(msg)
412412 else
413413 connectFirst(invite, function (err, rpc) {
414414 if(err) return cb(err)
415- rpc.userInvites.getInvite(invite.invite, function (err, msg) {
415 + rpc.peerInvites.getInvite(invite.invite, function (err, msg) {
416416 if(err) return cb(err)
417417 next(msg)
418418 })
419419 })
@@ -468,9 +468,9 @@
468468 getConfirm(invite_id, accept, function (err, confirm) {
469469 if(!confirm)
470470 connectFirst(invite, function (err, rpc) {
471471 if(err) return cb(err)
472- rpc.userInvites.confirm(accept, function (err, confirm) {
472 + rpc.peerInvites.confirm(accept, function (err, confirm) {
473473 //TODO: store confirms for us in the state.
474474 cb(err, confirm)
475475 })
476476 })
test/accept.jsView
@@ -27,9 +27,9 @@
2727 }
2828
2929 var caps = {
3030 sign: crypto.randomBytes(32),//.toString('base64'),
31- userInvite: crypto.randomBytes(32),//.toString('base64'),
31 + peerInvite: crypto.randomBytes(32),//.toString('base64'),
3232 shs: crypto.randomBytes(32),//.toString('base64'),
3333 }
3434
3535 var alice = createSbot({
@@ -60,17 +60,17 @@
6060 {
6161 remote: alice.getAddress('device') || alice.getAddress('device'),
6262 caps: caps,
6363 manifest: {
64- userInvites: {
64 + peerInvites: {
6565 getInvite: 'async',
6666 confirm: 'async'
6767 }
6868 }
6969 },
7070 function (err, _bob) {
7171 if(err) throw err
72- _bob.userInvites.getInvite(msg.key, function (err, invite) {
72 + _bob.peerInvites.getInvite(msg.key, function (err, invite) {
7373 if(err) throw err
7474 t.ok(invite)
7575 t.deepEqual(invite, msg.value)
7676 //check this invite is valid. would throw if it wasn't.
@@ -80,9 +80,9 @@
8080 var accept_content = I.createAccept(invite, seed, bob.id, caps)
8181
8282 bob.publish(accept_content, function (err, accept) {
8383 if(err) throw err
84- _bob.userInvites.confirm(accept.value, function (err, msg) {
84 + _bob.peerInvites.confirm(accept.value, function (err, msg) {
8585 if(err) throw err
8686 t.ok(msg)
8787 var confirm_id = '%'+ssbKeys.hash(JSON.stringify(msg, null, 2))
8888 alice.get(confirm_id, function (err, _msg) {
@@ -90,9 +90,9 @@
9090 t.deepEqual(msg, _msg)
9191
9292
9393 //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) {
9595 if(err) throw err
9696 t.deepEqual(msg2, msg)
9797 alice.close()
9898 bob.close()
test/accept2.jsView
@@ -30,9 +30,9 @@
3030 }
3131
3232 var caps = {
3333 sign: crypto.randomBytes(32),//.toString('base64'),
34- userInvite: crypto.randomBytes(32),//.toString('base64'),
34 + peerInvite: crypto.randomBytes(32),//.toString('base64'),
3535 shs: crypto.randomBytes(32),//.toString('base64'),
3636 }
3737
3838 var alice = createSbot({
@@ -61,24 +61,24 @@
6161 // var content = I.createInvite(seed, alice.id, {name: 'bob'}, {text: 'welcome to ssb!'})
6262 // alice.publish(content, function (err, msg) {
6363 // I.verifyInvitePublic(msg.value)
6464
65- alice.userInvites.create({allowWithoutPubs: true}, function (err, _invite) {
65 + alice.peerInvites.create({allowWithoutPubs: true}, function (err, _invite) {
6666 if(err) throw err
6767 var invite = u.parse(_invite)
6868 var seed = invite.seed
6969 var invite_id = invite.invite
7070
7171 //use device address, just for tests
7272 invite.pubs.push(alice.getAddress('device'))
7373
74- bob.userInvites.openInvite(invite, function (err, invite_msg, data) {
74 + bob.peerInvites.openInvite(invite, function (err, invite_msg, data) {
7575 if(err) throw err
7676 t.ok(invite)
7777 t.equal(toId(invite_msg), invite_id)
7878 t.deepEqual(data, {reveal: undefined, private: undefined})
7979 //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) {
8181 if(err) throw err
8282
8383 //check that alice and bob both understand the other to be following them.
8484 bob.friends.hops({reverse: true}, function (err, hops) {
test/accept3.jsView
@@ -34,9 +34,9 @@
3434 }
3535
3636 var caps = {
3737 sign: crypto.randomBytes(32),//.toString('base64'),
38- userInvite: crypto.randomBytes(32),//.toString('base64'),
38 + peerInvite: crypto.randomBytes(32),//.toString('base64'),
3939 shs: crypto.randomBytes(32),//.toString('base64'),
4040 }
4141
4242 var alice = createSbot({
@@ -62,25 +62,25 @@
6262 //in this test, we use a separate identity to create the invite,
6363 //to test multiple identity support, and also simulate confirmation by pub.
6464 alice.identities.create(function (err, carol_id) {
6565 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) {
6767 if(err) throw err
6868 var invite = u.parse(_invite)
6969 var seed = invite.seed
7070 var invite_id = invite.invite
7171
7272 //use device address, just for tests
7373 invite.pubs.push(alice.getAddress('device'))
7474
75- bob.userInvites.openInvite(invite, function (err, invite_msg, data) {
75 + bob.peerInvites.openInvite(invite, function (err, invite_msg, data) {
7676 if(err) throw err
7777 t.ok(invite)
7878 t.equal(invite_msg.author, carol_id)
7979 t.equal(toId(invite_msg), invite_id)
8080 t.deepEqual(data, {reveal: undefined, private: undefined})
8181 //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) {
8383 if(err) throw err
8484 t.equal(confirm.author, alice.id)
8585 //check that alice and bob both understand the other to be following them.
8686 bob.friends.hops({reverse: true}, function (err, hops) {
test/accept4.jsView
@@ -34,9 +34,9 @@
3434 }
3535
3636 var caps = {
3737 sign: crypto.randomBytes(32),//.toString('base64'),
38- userInvite: crypto.randomBytes(32),//.toString('base64'),
38 + peerInvite: crypto.randomBytes(32),//.toString('base64'),
3939 shs: crypto.randomBytes(32),//.toString('base64'),
4040 }
4141
4242 var alice = createSbot({
@@ -55,18 +55,18 @@
5555 })
5656
5757 tape('create an invite', function (t) {
5858
59- alice.userInvites.create({allowWithoutPubs: true}, function (err, _invite) {
59 + alice.peerInvites.create({allowWithoutPubs: true}, function (err, _invite) {
6060 if(err) throw err
6161 var invite = u.parse(_invite)
6262 var seed = invite.seed
6363 var invite_id = invite.invite
6464
6565 //use device address, just for tests
6666 invite.pubs.push(alice.getAddress('device'))
6767
68- bob.userInvites.openInvite(invite, function (err, invite_msg, data) {
68 + bob.peerInvites.openInvite(invite, function (err, invite_msg, data) {
6969 if(err) throw err
7070 t.ok(invite)
7171 t.equal(toId(invite_msg), invite_id)
7272 t.deepEqual(data, {reveal: undefined, private: undefined})
@@ -76,9 +76,9 @@
7676 var accept_content = I.createAccept(invite_msg, seed, bob.id, caps)
7777 bob.publish(accept_content, function (err, accept) {
7878 if(err) throw err
7979
80- bob.userInvites.acceptInvite(invite, function (err, confirm) {
80 + bob.peerInvites.acceptInvite(invite, function (err, confirm) {
8181 if(err) throw err
8282
8383 //check that alice and bob both understand the other to be following them.
8484 bob.friends.hops({reverse: true}, function (err, hops) {
test/accept5.jsView
@@ -34,9 +34,9 @@
3434 }
3535
3636 var caps = {
3737 sign: crypto.randomBytes(32),//.toString('base64'),
38- userInvite: crypto.randomBytes(32),//.toString('base64'),
38 + peerInvite: crypto.randomBytes(32),//.toString('base64'),
3939 shs: crypto.randomBytes(32),//.toString('base64'),
4040 }
4141
4242 var alice = createSbot({
@@ -55,18 +55,18 @@
5555 })
5656
5757 tape('create an invite', function (t) {
5858
59- alice.userInvites.create({allowWithoutPubs: true}, function (err, _invite) {
59 + alice.peerInvites.create({allowWithoutPubs: true}, function (err, _invite) {
6060 if(err) throw err
6161 var invite = u.parse(_invite)
6262 var seed = invite.seed
6363 var invite_id = invite.invite
6464
6565 //use device address, just for tests
6666 invite.pubs.push(alice.getAddress('device'))
6767
68- bob.userInvites.openInvite(invite, function (err, invite_msg, data) {
68 + bob.peerInvites.openInvite(invite, function (err, invite_msg, data) {
6969 if(err) throw err
7070 t.ok(invite)
7171 t.equal(toId(invite_msg), invite_id)
7272 t.deepEqual(data, {reveal: undefined, private: undefined})
@@ -81,9 +81,9 @@
8181 //before bob receives it back, and so he calls again.
8282
8383 alice.publish(I.createConfirm(accept.value), function (err, _confirm) {
8484 if(err) throw err
85- bob.userInvites.acceptInvite(invite, function (err, confirm) {
85 + bob.peerInvites.acceptInvite(invite, function (err, confirm) {
8686 if(err) throw err
8787 //alice returns the same confirm message, does not create a new one
8888 t.equal(toId(confirm), toId(_confirm.value), 'id is equal')
8989 t.deepEqual(confirm, _confirm.value)
test/error-without-pubs.jsView
@@ -30,9 +30,9 @@
3030 }
3131
3232 var caps = {
3333 sign: crypto.randomBytes(32),//.toString('base64'),
34- userInvite: crypto.randomBytes(32),//.toString('base64'),
34 + peerInvite: crypto.randomBytes(32),//.toString('base64'),
3535 shs: crypto.randomBytes(32),//.toString('base64'),
3636 }
3737
3838 var alice = createSbot({
@@ -52,9 +52,9 @@
5252 var seed = crypto.randomBytes(32)
5353
5454 //without the pubs option, do not allow creating
5555 //an invite.
56- alice.userInvites.create({}, function (err, invite) {
56 + alice.peerInvites.create({}, function (err, invite) {
5757 t.ok(err)
5858 alice.close()
5959 t.end()
6060 })
test/happy.jsView
@@ -14,9 +14,9 @@
1414 var bob = ssbKeys.generate(null, hash('BOB'))
1515
1616 var caps = {
1717 sign: crypto.randomBytes(32),//.toString('base64'),
18- userInvite: crypto.randomBytes(32),//.toString('base64'),
18 + peerInvite: crypto.randomBytes(32),//.toString('base64'),
1919 shs: crypto.randomBytes(32),//.toString('base64'),
2020 }
2121
2222 tape('happy', function (t) {
test/invalid.jsView
@@ -5,9 +5,9 @@
55 var u = require('../util')
66 var crypto = require('crypto')
77 var caps = {
88 sign: crypto.randomBytes(32),//.toString('base64'),
9- userInvite: crypto.randomBytes(32),//.toString('base64'),
9 + peerInvite: crypto.randomBytes(32),//.toString('base64'),
1010 shs: crypto.randomBytes(32),//.toString('base64'),
1111 }
1212
1313 var invite_key = require('../cap')
@@ -35,23 +35,23 @@
3535
3636 //construct a message where host does not match
3737 var seed = hash('seed2')
3838 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',
4141 invite: ssbKeys.generate(null, hash('seed3')),
4242 host: alice.id
4343 })
4444
4545 var msg = v.create(null, alice, caps.sign, invalid, new Date('2018-03-26T06:14:18.377Z'))
4646
4747 throws(t, function () {
4848 i.verifyInvitePublic(msg, caps)
49- }, 'user-invites:invite-signature-failed')
49 + }, 'peer-invites:invite-signature-failed')
5050
5151 throws(t, function () {
5252 i.verifyInvitePrivate(msg, seed, caps)
53- }, 'user-invites:invite-signature-failed')
53 + }, 'peer-invites:invite-signature-failed')
5454
5555 t.end()
5656 })
5757
@@ -61,10 +61,10 @@
6161 //construct a message where host does not match
6262 var seed = hash('seed2')
6363 var keys = ssbKeys.generate(null, seed)
6464 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',
6767 invite: keys.id, //correct key
6868 reveal: u.box({hidden: true}, u.hash(u.hash(wrong_seed))),
6969 host: alice.id
7070 })
@@ -73,23 +73,23 @@
7373 t.ok(i.verifyInvitePublic(invite_msg, caps))
7474
7575 throws(t, function () {
7676 i.verifyInvitePrivate(invite_msg, seed, caps)
77- }, 'user-invites:decrypt-reveal-failed')
77 + }, 'peer-invites:decrypt-reveal-failed')
7878
7979 //say if the invitee creates a accept message anyway.
8080
8181 throws(t, function () {
8282 i.createAccept(invite_msg, wrong_seed, bob.id, caps)
83- }, 'user-invites:seed-must-match-invite')
83 + }, 'peer-invites:seed-must-match-invite')
8484
8585
8686 throws(t, function () {
8787 i.createAccept(invite_msg, seed, bob.id, caps)
88- }, 'user-invites:decrypt-reveal-failed')
88 + }, 'peer-invites:decrypt-reveal-failed')
8989
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',
9292 receipt: '%'+ssbKeys.hash(JSON.stringify(invite_msg, null, 2)),
9393 id: bob.id,
9494 key: u.hash(u.hash(seed)) //what the reveal key should be.
9595 })
@@ -98,20 +98,20 @@
9898 v.create(null, bob, caps.sign, accept, new Date('2018-03-26T06:14:18.377Z'))
9999
100100 throws(t, function () {
101101 i.verifyAccept(accept_msg, invite_msg, caps)
102- }, 'user-invites:decrypt-accept-reveal-failed')
102 + }, 'peer-invites:decrypt-accept-reveal-failed')
103103
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',
106106 receipt: '%'+ssbKeys.hash(JSON.stringify(invite_msg, null, 2)),
107107 id: bob.id,
108108 key: u.hash('not the key') //what the reveal key should be.
109109 })
110110
111111 throws(t, function () {
112112 i.verifyAccept(accept_msg, invite_msg, caps)
113- }, 'user-invites:decrypt-accept-reveal-failed')
113 + }, 'peer-invites:decrypt-accept-reveal-failed')
114114
115115 t.end()
116116 })
117117
@@ -134,9 +134,9 @@
134134
135135 //just test we do not verify the incorrect invite
136136 throws(t, function () {
137137 i.verifyAccept(accept, invite2, caps)
138- }, 'user-invites:accept-wrong-invite')
138 + }, 'peer-invites:accept-wrong-invite')
139139
140140 t.end()
141141
142142 })
@@ -145,10 +145,10 @@
145145 var seed = hash('seed1')
146146
147147 var invite = v.create(null, alice, caps.sign, i.createInvite(seed, alice.id, null, null, caps), new Date('2018-03-14T06:14:18.377Z'))
148148 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',
151151 receipt: '%'+ssbKeys.hash(JSON.stringify(invite, null, 2)),
152152 id: bob.id,
153153 })
154154 var accept2 = v.create(null, bob, caps.sign, accept_content, new Date('2018-03-14T06:32:18.377Z'))
@@ -156,9 +156,9 @@
156156
157157 //just test we do not verify the incorrect invite
158158 throws(t, function () {
159159 i.verifyAccept(accept2, invite, caps)
160- }, 'user-invites:accept-invite-signature-failed')
160 + }, 'peer-invites:accept-invite-signature-failed')
161161
162162 t.end()
163163 })
164164
@@ -166,10 +166,10 @@
166166 tape('wrong invite', function (t) {
167167 var seed = hash('seed1')
168168
169169 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',
172172 receipt: '%'+ssbKeys.hash(JSON.stringify(invite, null, 2)),
173173 id: bob.id,
174174 //key is missing!
175175 })
@@ -178,9 +178,9 @@
178178
179179 //just test we do not verify the incorrect invite
180180 throws(t, function () {
181181 i.verifyAccept(accept2, invite, caps)
182- }, 'user-invites:accept-must-reveal-key')
182 + }, 'peer-invites:accept-must-reveal-key')
183183
184184 t.end()
185185 })
186186
test/invite-with-pubs.jsView
@@ -23,9 +23,9 @@
2323 }
2424
2525 var caps = {
2626 sign: crypto.randomBytes(32),
27- userInvite: crypto.randomBytes(32),
27 + peerInvite: crypto.randomBytes(32),
2828 shs: crypto.randomBytes(32),
2929 }
3030
3131 var alice = createSbot({
@@ -88,9 +88,9 @@
8888 })
8989 })
9090
9191 tape('getNearbyPubs', function (t) {
92- alice.userInvites.getNearbyPubs({}, function (err, pubs) {
92 + alice.peerInvites.getNearbyPubs({}, function (err, pubs) {
9393 if(err) throw err
9494 t.ok(pubs.length)
9595 t.end()
9696 })
@@ -100,17 +100,17 @@
100100 tape('create-invite, with automatic pubs', function (t) {
101101 var n = 1
102102 //wait until carol has received alice's invite
103103 carol.post(function (data) {
104- if(data.value.content.type === 'user-invite') {
104 + if(data.value.content.type === 'peer-invite') {
105105 console.log('invit?', data)
106106 if(--n) return
107107 t.end()
108108 }
109109 })
110110
111111 setTimeout(function () {
112- alice.userInvites.create({}, function (err, _invite) {
112 + alice.peerInvites.create({}, function (err, _invite) {
113113 if(err) throw err
114114 console.log('create invite')
115115 invite = u.parse(_invite)
116116 console.log(_invite)
@@ -124,12 +124,12 @@
124124 alice.get(invite.invite, function (err, invite_msg) {
125125 if(err) throw err
126126 t.deepEqual(invite.pubs, [carol.getAddress('device')])
127127
128- bob.userInvites.openInvite(invite, function (err, _invite_msg) {
128 + bob.peerInvites.openInvite(invite, function (err, _invite_msg) {
129129 if(err) throw explain(err, 'error while opening invite')
130130 t.deepEqual(_invite_msg, invite_msg)
131- bob.userInvites.acceptInvite(invite, function (err) {
131 + bob.peerInvites.acceptInvite(invite, function (err) {
132132 if(err) throw err
133133 t.end()
134134 })
135135 })
@@ -138,9 +138,9 @@
138138
139139 //there is another race here. seems flumedb
140140 //doesn't like it if you close and immediately
141141 //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.
143143 tape('cleanup', function (t) {
144144 setTimeout(function () {
145145 alice.close()
146146 carol.close()
test/will-replicate.jsView
@@ -28,9 +28,9 @@
2828 .use(require('../'))
2929
3030 var caps = {
3131 sign: crypto.randomBytes(32),//.toString('base64'),
32- userInvite: crypto.randomBytes(32),//.toString('base64'),
32 + peerInvite: crypto.randomBytes(32),//.toString('base64'),
3333 shs: crypto.randomBytes(32),//.toString('base64'),
3434 }
3535
3636 var alice = createSbot({
@@ -57,9 +57,9 @@
5757 t.ok(data)
5858 console.log(data)
5959 bob.connect(alice.getAddress(), function (err, _alice) {
6060 if(err) throw err
61- _alice.userInvites.willReplicate(function (err, wr) {
61 + _alice.peerInvites.willReplicate(function (err, wr) {
6262 if(err) throw err
6363 t.ok(wr) //alice should replicate for bob's guests
6464 _alice.close()
6565 t.end()
@@ -70,9 +70,9 @@
7070
7171 tape("bob won't replicate alice's guests", function (t) {
7272 alice.connect(bob.getAddress(), function (err, _bob) {
7373 if(err) throw err
74- _bob.userInvites.willReplicate(function (err, wr) {
74 + _bob.peerInvites.willReplicate(function (err, wr) {
7575 if(err) throw err
7676 t.notOk(wr) //alice should replicate for bob's guests
7777 _bob.close()
7878 t.end()
types.jsView
@@ -23,21 +23,21 @@
2323 exports.isInvite = function (msg, caps) {
2424 if(!isObject(caps)) throw new Error('caps must be provided')
2525 //return true
2626 return isObject(msg) && isObject(msg.content) && (
27- 'user-invite' === msg.content.type &&
27 + 'peer-invite' === msg.content.type &&
2828 ref.isFeed(msg.content.host) &&
2929 ref.isFeed(msg.content.invite) &&
3030 isMaybeBase64(msg.content.reveal) &&
3131 isMaybeBase64(msg.content.public) &&
3232 // signature must be valid !!!
33- ssbKeys.verifyObj(msg.content.invite, caps.userInvite, msg.content)
33 + ssbKeys.verifyObj(msg.content.invite, caps.peerInvite, msg.content)
3434 )
3535 }
3636
3737 exports.isAccept = function (msg) {
3838 return isObject(msg) && isObject(msg.content) && (
39- 'user-invite/accept' === msg.content.type &&
39 + 'peer-invite/accept' === msg.content.type &&
4040 msg.content.id == msg.author &&
4141 ref.isMsg(msg.content.receipt) &&
4242 isMaybeBase64(msg.content.key) &&
4343 // can't verify this without having the invite message.
@@ -48,9 +48,9 @@
4848 }
4949
5050 exports.isConfirm = function (msg) {
5151 return isObject(msg) && isObject(msg.content) && (
52- 'user-invite/confirm' === msg.content.type &&
52 + 'peer-invite/confirm' === msg.content.type &&
5353 exports.isAccept(msg.content.embed) &&
5454 //second pointer back to receipt, so that links can find it
5555 //(since it unfortunately does not handle links nested deeper
5656 //inside objects. when we look up the message,
valid.jsView
@@ -4,9 +4,9 @@
44
55 var invite_key = require('./cap')
66
77 function code(err, c) {
8- err.code = 'user-invites:'+c
8 + err.code = 'peer-invites:'+c
99 return err
1010 }
1111
1212 function isObject (o) {
@@ -40,11 +40,11 @@
4040
4141 seed = toBuffer(seed)
4242 var keys = ssbKeys.generate(null, seed) //K
4343 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',
4747 invite: keys.id,
4848 host: host, //sign our own key, to prove we created K
4949 reveal: reveal ? u.box(reveal, hash2(seed)) : undefined,
5050 private: private ? u.box(private, hash(seed)) : undefined
@@ -56,9 +56,9 @@
5656
5757 if(msg.content.host != msg.author)
5858 throw code(new Error('host did not match author'), 'host-must-match-author')
5959
60- if(!ssbKeys.verifyObj(msg.content.invite, caps.userInvite, msg.content))
60 + if(!ssbKeys.verifyObj(msg.content.invite, caps.peerInvite, msg.content))
6161 throw code(new Error('invalid invite signature'), 'invite-signature-failed')
6262
6363 //an ordinary message so doesn't use special hmac_key, unless configed to.
6464 if(!ssbKeys.verifyObj(msg.author, caps.sign, msg))
@@ -92,21 +92,21 @@
9292 if(keys.id != msg.content.invite)
9393 throw code(new Error('seed does not match invite'), 'seed-must-match-invite')
9494 var inviteId = toMsgId(msg)
9595 var content = {
96- type: 'user-invite/accept',
96 + type: 'peer-invite/accept',
9797 receipt: inviteId,
9898 id: id
9999 }
100100 if(msg.content.reveal)
101101 content.key = hash2(seed).toString('base64')
102- return ssbKeys.signObj(keys, caps.userInvite, content)
102 + return ssbKeys.signObj(keys, caps.peerInvite, content)
103103 }
104104
105105 exports.verifyAcceptOnly = function (accept, caps) {
106106 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')
109109 if(!isMsg(accept.content.receipt))
110110 throw code(new Error('accept must reference invite message id'), 'accept-reference-invite')
111111 //verify signed as ordinary message.
112112 if(!ssbKeys.verifyObj(accept.content.id, caps.sign, accept))
@@ -118,10 +118,10 @@
118118 if(!invite_msg) throw new Error('invite must be provided')
119119
120120 exports.verifyAcceptOnly(accept, caps)
121121
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')
124124
125125 var invite_id = toMsgId(invite_msg)
126126 var reveal
127127
@@ -136,17 +136,17 @@
136136 reveal = u.unbox(invite_msg.content.reveal, toBuffer(accept.content.key))
137137 if(!reveal) throw code(new Error('accept did not correctly reveal invite'), 'decrypt-accept-reveal-failed')
138138 }
139139
140- if(!ssbKeys.verifyObj(invite_msg.content.invite, caps.userInvite, accept.content))
140 + if(!ssbKeys.verifyObj(invite_msg.content.invite, caps.peerInvite, accept.content))
141141 throw code(new Error('did not verify invite-acceptance contents'), 'accept-invite-signature-failed')
142142 //an ordinary message, so does not use hmac_key
143143 return reveal || true
144144 }
145145
146146 exports.createConfirm = function (accept) {
147147 return {
148- type: 'user-invite/confirm',
148 + type: 'peer-invite/confirm',
149149 embed: accept,
150150 //second pointer back to receipt, so that links can find it
151151 //(since it unfortunately does not handle links nested deeper
152152 //inside objects. when we look up the message,

Built with git-ssb-web