git ssb

1+

Dominic / ssb-keys



Tree: bb67911fcc0812000fcd96fbcabf11ef9d29a48b

Files: bb67911fcc0812000fcd96fbcabf11ef9d29a48b / test / index.js

1218 bytesRaw
1var tape = require('tape')
2var ssbkeys = require('../')
3
4var path = require('path').join(__dirname, 'keyfile')
5
6tape('create and load async', function (t) {
7 try { require('fs').unlinkSync(path) } catch(e) {}
8 ssbkeys.create(path, function(err, k1) {
9 if (err) throw err
10 ssbkeys.load(path, function(err, k2) {
11 if (err) throw err
12 t.equal(k1.id.toString('hex'), k2.id.toString('hex'))
13 t.equal(k1.private.toString('hex'), k2.private.toString('hex'))
14 t.equal(k1.public.toString('hex'), k2.public.toString('hex'))
15 t.end()
16 })
17 })
18})
19
20tape('create and load sync', function (t) {
21 try { require('fs').unlinkSync(path) } catch(e) {}
22 var k1 = ssbkeys.createSync(path)
23 var k2 = ssbkeys.loadSync(path)
24 t.equal(k1.id.toString('hex'), k2.id.toString('hex'))
25 t.equal(k1.private.toString('hex'), k2.private.toString('hex'))
26 t.equal(k1.public.toString('hex'), k2.public.toString('hex'))
27 t.end()
28})
29
30
31tape('sign and verify', function (t) {
32
33 var keys = ssbkeys.generate()
34 var msg = ssbkeys.hash("HELLO THERE?")
35 var sig = ssbkeys.sign(keys, msg)
36 console.log('public', keys.public)
37 console.log('sig', sig)
38 t.ok(sig)
39 t.ok(ssbkeys.verify(keys, sig, msg))
40
41 t.end()
42
43})
44

Built with git-ssb-web