git ssb

0+

Dominic / ssb-peer-invites



Tree: 8299fab7cda81af8f07aacbeb7374249c6e8d848

Files: 8299fab7cda81af8f07aacbeb7374249c6e8d848 / test / happy.js

3176 bytesRaw
1
2var tape = require('tape')
3var ssbKeys = require('ssb-keys')
4var v = require('ssb-validate')
5var i = require('../valid')
6var u = require('../util')
7
8var invite_key = require('../cap')
9
10var hash = u.hash
11
12var alice = ssbKeys.generate(null, hash('ALICE'))
13var bob = ssbKeys.generate(null, hash('BOB'))
14
15tape('happy', function (t) {
16
17 var seed = hash('seed1')
18
19 var tmp = ssbKeys.generate(null, seed)
20
21 var invite_content = i.createInvite(seed, alice.id, {name: 'bob'}, {text: 'welcome to ssb!'})
22
23 var msg = v.create(null, alice, null, invite_content, new Date('2018-03-14T06:14:18.377Z'))
24
25 var message = i.verifyInvitePrivate(msg, seed)
26
27 t.deepEqual({
28 reveal: {name: 'bob'},
29 private: {text: 'welcome to ssb!'}
30 }, message)
31
32 var accept_content = i.createAccept(msg, seed, bob.id)
33
34 var msg2 = v.create(null, bob, null, accept_content, new Date('2018-03-14T06:32:18.377Z'))
35
36 var revealed = i.verifyAccept(msg2, msg)
37
38 t.deepEqual(revealed, {name: 'bob'})
39
40 t.end()
41})
42
43tape('happy 2, without private', function (t) {
44
45 var seed = hash('seed2')
46
47 var tmp = ssbKeys.generate(null, seed)
48
49 var invite_content = i.createInvite(seed, alice.id, {name: 'bob'}, null)
50
51 var msg = v.create(null, alice, null, invite_content, new Date('2018-03-14T06:14:18.377Z'))
52
53 var message = i.verifyInvitePrivate(msg, seed)
54
55 t.deepEqual({
56 reveal: {name: 'bob'},
57 private: undefined
58 }, message)
59
60 var accept_content = i.createAccept(msg, seed, bob.id)
61
62 var msg2 = v.create(null, bob, null, accept_content, new Date('2018-03-14T06:32:18.377Z'))
63
64 var revealed = i.verifyAccept(msg2, msg)
65
66 t.deepEqual(revealed, {name: 'bob'})
67
68 t.end()
69})
70
71
72
73tape('happy 3, without reveal', function (t) {
74
75 var seed = hash('seed3')
76
77 var tmp = ssbKeys.generate(null, seed)
78
79 var invite_content = i.createInvite(seed, alice.id, null, {name: 'bob'})
80
81 var msg = v.create(null, alice, null, invite_content, new Date('2018-03-14T06:14:18.377Z'))
82
83 var message = i.verifyInvitePrivate(msg, seed)
84
85 t.deepEqual({
86 reveal: undefined,
87 private: {name: 'bob'}
88 }, message)
89
90 var accept_content = i.createAccept(msg, seed, bob.id)
91
92 var msg2 = v.create(null, bob, null, accept_content, new Date('2018-03-14T06:32:18.377Z'))
93
94 var revealed = i.verifyAccept(msg2, msg)
95
96 t.equal(revealed, true)
97
98 t.end()
99})
100
101
102tape('happy 4, neither private or reveal', function (t) {
103
104 var seed = hash('seed4')
105
106 var tmp = ssbKeys.generate(null, seed)
107
108 var invite_content = i.createInvite(seed, alice.id)
109
110 var msg = v.create(null, alice, null, invite_content, new Date('2018-03-14T06:14:18.377Z'))
111
112 var message = i.verifyInvitePrivate(msg, seed)
113
114 t.deepEqual({
115 reveal: undefined,
116 private: undefined
117 }, message)
118
119 var accept_content = i.createAccept(msg, seed, bob.id)
120
121 var msg2 = v.create(null, bob, null, accept_content, new Date('2018-03-14T06:32:18.377Z'))
122
123 var revealed = i.verifyAccept(msg2, msg)
124
125 t.equal(revealed, true)
126
127 t.end()
128})
129
130tape('safety', function (t) {
131 t.throws(function () {
132 //do now give away your own private key!
133 i.createInvite(hash("ALICE"), alice.id, {name: 'bob'}, {text: 'welcome to ssb!'})
134 })
135 t.end()
136})
137
138
139
140
141
142
143
144

Built with git-ssb-web