Files: bc976c6da636fee26b5ecccf6f7b24831ad881f4 / test / index.js
3025 bytesRaw
1 | var tape = require('tape') |
2 | var ssbkeys = require('../') |
3 | |
4 | var path = require('path').join(__dirname, 'keyfile') |
5 | |
6 | tape('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 | |
20 | tape('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 | |
31 | tape('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.equal(ssbkeys.getTag(sig), 'blake2s.ed25519') |
40 | t.ok(ssbkeys.verify(keys, sig, msg)) |
41 | |
42 | t.end() |
43 | |
44 | }) |
45 | |
46 | tape('sign and verify, call with keys directly', function (t) { |
47 | |
48 | var keys = ssbkeys.generate() |
49 | var msg = ssbkeys.hash("HELLO THERE?") |
50 | var sig = ssbkeys.sign(keys.private, msg) |
51 | console.log('public', keys.public) |
52 | console.log('sig', sig) |
53 | t.ok(sig) |
54 | t.equal(ssbkeys.getTag(sig), 'blake2s.ed25519') |
55 | t.ok(ssbkeys.verify(keys.public, sig, msg)) |
56 | |
57 | t.end() |
58 | |
59 | }) |
60 | |
61 | tape('sign and verify a javascript object', function (t) { |
62 | |
63 | var obj = require('../package.json') |
64 | |
65 | console.log(obj) |
66 | |
67 | var keys = ssbkeys.generate() |
68 | var sig = ssbkeys.signObj(keys.private, obj) |
69 | console.log(sig) |
70 | t.ok(sig) |
71 | t.ok(ssbkeys.verifyObj(keys, sig, obj)) |
72 | t.end() |
73 | |
74 | }) |
75 | |
76 | tape('test legacy curve: k256', function (t) { |
77 | var keys = ssbkeys.generate('k256') |
78 | |
79 | var msg = ssbkeys.hash("LEGACY SYSTEMS") |
80 | var sig = ssbkeys.sign(keys, msg) |
81 | |
82 | console.log('public', keys.public) |
83 | console.log('sig', sig) |
84 | |
85 | t.ok(sig) |
86 | t.equal(ssbkeys.getTag(sig), 'blake2s.k256') |
87 | t.ok(ssbkeys.verify(keys, sig, msg)) |
88 | |
89 | t.end() |
90 | }) |
91 | |
92 | tape('create and load async, legacy', function (t) { |
93 | try { require('fs').unlinkSync(path) } catch(e) {} |
94 | ssbkeys.create(path, 'k256', function(err, k1) { |
95 | if (err) throw err |
96 | ssbkeys.load(path, function(err, k2) { |
97 | if (err) throw err |
98 | |
99 | t.equal(k2.curve, 'k256') |
100 | t.equal(k1.id, k2.id) |
101 | t.equal(k1.private, k2.private) |
102 | t.equal(k1.public, k2.public) |
103 | |
104 | t.end() |
105 | }) |
106 | }) |
107 | }) |
108 | |
109 | tape('create and load sync, legacy', function (t) { |
110 | try { require('fs').unlinkSync(path) } catch(e) {} |
111 | var k1 = ssbkeys.createSync(path, 'k256', true) |
112 | var k2 = ssbkeys.loadSync(path) |
113 | |
114 | console.log(k2) |
115 | |
116 | t.equal(k2.curve, 'k256') |
117 | t.equal(k1.id, k2.id) |
118 | t.equal(k1.private, k2.private) |
119 | t.equal(k1.public, k2.public) |
120 | |
121 | t.end() |
122 | }) |
123 | |
124 | |
125 |
Built with git-ssb-web