Files: 8e7955b783feade5fcafd93d16fc8b1c48886bd2 / test / invite.js
1043 bytesRaw
1 | |
2 | var tape = require('tape') |
3 | var ssbKeys = require('ssb-keys') |
4 | var v = require('ssb-validate') |
5 | var i = require('../') |
6 | |
7 | var crypto = require('crypto') |
8 | |
9 | function hash (s) { |
10 | return crypto.createHash('sha256').update(s).digest() |
11 | } |
12 | |
13 | var alice = ssbKeys.generate(null, hash('ALICE')) |
14 | var bob = ssbKeys.generate(null, hash('BOB')) |
15 | |
16 | tape('happy', function (t) { |
17 | |
18 | var seed = hash('seed') |
19 | |
20 | var invite_content = i.createInvite(seed, bob.id, {name: 'bob'}, {text: 'welcome to ssb!'}) |
21 | |
22 | console.log(invite_content) |
23 | |
24 | var msg = v.create(null, alice, null, invite_content, new Date('2018-03-14T06:14:18.377Z')) |
25 | |
26 | var message = i.verifyInvitePrivate(msg, seed) |
27 | |
28 | t.deepEqual({ |
29 | reveal: {name: 'bob'}, |
30 | private: {text: 'welcome to ssb!'} |
31 | }, message) |
32 | |
33 | var accept_content = i.createAccept(msg, seed, bob.id) |
34 | |
35 | console.log('accept:', accept_content) |
36 | |
37 | var msg2 = v.create(null, bob, null, accept_content, new Date('2018-03-14T06:32:18.377Z')) |
38 | |
39 | var revealed = i.verifyAccept(msg2, msg) |
40 | |
41 | t.deepEqual(revealed, {name: 'bob'}) |
42 | |
43 | t.end() |
44 | }) |
45 | |
46 |
Built with git-ssb-web