git ssb

0+

Dominic / ssb-peer-invites



Tree: 12ee744340c9fc9639316ac7656ef5324003cb16

Files: 12ee744340c9fc9639316ac7656ef5324003cb16 / test / happy.js

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

Built with git-ssb-web