git ssb

1+

Dominic / ssb-private-groups



Commit f8b540f929cf4de61e694622166b3a1e1505f22a

tidy tests

Dominic Tarr committed on 12/27/2018, 8:28:42 PM
Parent: f57b58569dafb4a037a0648c9e7731063a14b691

Files changed

test/index.jschanged
test/index.jsView
@@ -1,16 +1,22 @@
11 var chloride = require('chloride')
22 var tape = require('tape')
33 var group_box = require('group-box')
44 var u = require('../util')
5 +var ssbKeys = require('ssb-keys')
56 var Scuttlebot = require('ssb-server')
67 .use(require('../'))
78
9 +function hash (s) {
10 + return chloride.crypto_hash_sha256(Buffer.from(s, 'utf8'))
11 +}
12 +
813 var alice = Scuttlebot({
9- temp: true
14 + temp: true,
15 + keys: ssbKeys.generate(null, hash('alice_secret1'))
1016 })
1117
12-var bob = alice.createFeed()
18 +var bob = alice.createFeed(ssbKeys.generate(null, hash('bob_secret1')))
1319
1420 function generate (seed) {
1521 var keys = chloride.crypto_box_seed_keypair(seed)
1622 return {
@@ -25,13 +31,10 @@
2531
2632 function scalarmult (pk,sk) {
2733 return chloride.crypto_scalarmult(toBuffer(pk), toBuffer(sk))
2834 }
29-function hash (s) {
30- return chloride.crypto_hash_sha256(Buffer.from(s, 'utf8'))
31-}
32-var alice_keys = generate(hash('alice_secret'))
33-var bob_keys = generate(hash('bob_secret'))
35 +var alice_keys = generate(hash('alice_secret2'))
36 +var bob_keys = generate(hash('bob_secret2'))
3437
3538 tape('create a private-msg-key', function (t) {
3639 alice.privateGroups.addCurvePair(alice_keys, function (err) {
3740 if(err) throw err
@@ -48,59 +51,29 @@
4851 type: 'private-msg-key',
4952 key: bob_keys.public
5053 }, function (err, data) {
5154 if(err) throw err
52- console.log(data)
5355 t.ok(data.key)
5456
5557 var content = { type: 'private', text: 'hello, alice' }
5658 var ptxt = Buffer.from(JSON.stringify(content))
5759 var nonce = u.id2Buffer(data.key)
5860 var keys = [bob_keys, alice_keys].map(function (key) {
5961 return scalarmult(bob_keys.private, key.public)
6062 })
61- var keys2 = [bob_keys].map(function (key) {
62- return scalarmult(alice_keys.private, key.public)
63- })
64- console.log('plaintext.length', ptxt.length)
65-
66- var ctxt = group_box.box(
67- ptxt,
68- nonce,
69- keys
70- )
71-// console.log("CTXT", ctxt.toString('base64'))
72-// console.log("NONCE", nonce)
73-// console.log("KEYS", keys)
74-// console.log("KEYS2", keys2)
7563 var _key = group_box.unboxKey(ctxt, nonce, keys, 8)
76- console.log("INPUT", {
77- ctxt: ctxt.toString('hex'),
78- nonce: nonce,
79- key: _key
80- })
81- console.log(
82- 'INPUT_TEST',
83- chloride.crypto_hash_sha256(Buffer.concat([ctxt, nonce, _key])),
84-group_box.unboxBody(ctxt, nonce, _key).toString()
85- )
86- console.log('d.ptxt', group_box.unboxBody(ctxt, nonce, _key).toString())
87-
88-// console.log('ctxt.length', ctxt.length)
64 + t.ok(_key, 'message can be decrypted')
8965 bob.publish(
9066 ctxt.toString('base64')+'.box2',
9167 function (err, data) {
9268 if(err) throw err
9369 t.ok(data)
94-// console.log(data)
95-// alice.privateGroups.get(function () {
96- alice.get({id: data.key, private: true}, function (err, msg) {
97- if(err) throw err
98- t.deepEqual(msg.content, content)
99- t.end()
70 + alice.get({id: data.key, private: true}, function (err, msg) {
71 + if(err) throw err
72 + t.deepEqual(msg.content, content)
73 + t.end()
10074
101- })
102- // })
75 + })
10376 }
10477 )
10578 })
10679 })
@@ -111,7 +84,4 @@
11184 alice.close()
11285 t.end()
11386 })
11487
115-
116-
117-

Built with git-ssb-web