git ssb

0+

Dominic / ssb-peer-invites



Tree: 3c6e9ba6132fbd1415505276a00c24a5126918a1

Files: 3c6e9ba6132fbd1415505276a00c24a5126918a1 / test / accept2.js

2531 bytesRaw
1//WARNING: this test currently only passes
2//if the computer has a network.
3var crypto = require('crypto')
4var I = require('../valid')
5var createClient = require('ssb-client')
6
7
8var ssbKeys = require('ssb-keys')
9var tape = require('tape')
10var pull = require('pull-stream')
11var ref = require('ssb-ref')
12
13var createSbot = require('scuttlebot')
14 .use(require('ssb-links'))
15 .use({
16 name: 'replicate', version: '1.0.0',
17 manifest: { request: 'sync' },
18 init: function () {
19 return { request: function () {} }
20 }
21 })
22 .use(require('ssb-query'))
23 .use(require('ssb-device-address'))
24 .use(require('ssb-identities'))
25 .use(require('ssb-friends'))
26 .use(require('../'))
27
28function all(stream, cb) {
29 return pull(stream, pull.collect(cb))
30}
31
32var caps = {
33 sign: crypto.randomBytes(32),//.toString('base64'),
34 userInvite: crypto.randomBytes(32),//.toString('base64'),
35 shs: crypto.randomBytes(32),//.toString('base64'),
36}
37
38var alice = createSbot({
39 temp: true,
40 timeout: 1000,
41 port: 12342,
42 keys:ssbKeys.generate(),
43 caps: caps
44})
45var bob = createSbot({
46 temp: true,
47 timeout: 1000,
48 port: 12343,
49 keys:ssbKeys.generate(),
50 caps: caps
51})
52
53function toId(msg) {
54 return '%'+ssbKeys.hash(JSON.stringify(msg, null, 2))
55}
56
57tape('create an invite', function (t) {
58
59 var seed = crypto.randomBytes(32)
60
61// var content = I.createInvite(seed, alice.id, {name: 'bob'}, {text: 'welcome to ssb!'})
62// alice.publish(content, function (err, msg) {
63 // I.verifyInvitePublic(msg.value)
64
65 alice.userInvites.create({}, function (err, invite) {
66 if(err) throw err
67 var seed = invite.seed
68 var invite_id = invite.invite
69
70 //use device address, just for tests
71 invite.pubs.push(alice.getAddress('device'))
72
73 bob.userInvites.openInvite(invite, function (err, invite_msg, data) {
74 if(err) throw err
75 t.ok(invite)
76 t.equal(toId(invite_msg), invite_id)
77 t.deepEqual(data, {reveal: undefined, private: undefined})
78 //check this invite is valid. would throw if it wasn't.
79 bob.userInvites.acceptInvite(invite, function (err, confirm) {
80 if(err) throw err
81
82 //check that alice and bob both understand the other to be following them.
83 bob.friends.hops({reverse: true}, function (err, hops) {
84 t.equal(hops[alice.id], 1)
85 alice.friends.hops({reverse: true}, function (err, hops) {
86 t.equal(hops[bob.id], 1)
87 alice.close()
88 bob.close()
89 t.end()
90 })
91 })
92 })
93 })
94 })
95})
96
97
98
99

Built with git-ssb-web