git ssb

0+

Dominic / ssb-peer-invites



Tree: 0e94992aa8bedac43906183f616bff699ec2484b

Files: 0e94992aa8bedac43906183f616bff699ec2484b / test / happy.js

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

Built with git-ssb-web