Files: fe3ae12adbf9dfc9bd4146fa5708fee8f9297e46 / test / happy.js
3545 bytesRaw
1 | |
2 | var tape = require('tape') |
3 | var ssbKeys = require('ssb-keys') |
4 | var v = require('ssb-validate') |
5 | var i = require('../valid') |
6 | var u = require('../util') |
7 | var crypto = require('crypto') |
8 | |
9 | var invite_key = require('../cap') |
10 | |
11 | var hash = u.hash |
12 | |
13 | var alice = ssbKeys.generate(null, hash('ALICE')) |
14 | var bob = ssbKeys.generate(null, hash('BOB')) |
15 | |
16 | var caps = { |
17 | sign: crypto.randomBytes(32),//.toString('base64'), |
18 | userInvite: crypto.randomBytes(32),//.toString('base64'), |
19 | shs: crypto.randomBytes(32),//.toString('base64'), |
20 | } |
21 | |
22 | tape('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 | |
50 | tape('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 | |
80 | tape('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 | |
109 | tape('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 | |
137 | tape('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