git ssb

0+

Dominic / ssb-peer-invites



Tree: 39b9c70c0e6cbb27bccacdc189c8a2f197e9959d

Files: 39b9c70c0e6cbb27bccacdc189c8a2f197e9959d / test / invite.js

1043 bytesRaw
1
2var tape = require('tape')
3var ssbKeys = require('ssb-keys')
4var v = require('ssb-validate')
5var i = require('../')
6
7var crypto = require('crypto')
8
9function hash (s) {
10 return crypto.createHash('sha256').update(s).digest()
11}
12
13var alice = ssbKeys.generate(null, hash('ALICE'))
14var bob = ssbKeys.generate(null, hash('BOB'))
15
16tape('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