Files: 68df1eba527e24ae3645414bbadd9f374f16d524 / test / index.js
3541 bytesRaw
1 | var tape = require('tape') |
2 | var ssbkeys = require('../') |
3 | var crypto = require('crypto') |
4 | var path = '/tmp/ssb-keys_'+Date.now() |
5 | |
6 | tape('create and load async', function (t) { |
7 | console.log(ssbkeys) |
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 | console.log(k1, k2) |
13 | t.equal(k1.id.toString('hex'), k2.id.toString('hex')) |
14 | t.equal(k1.private.toString('hex'), k2.private.toString('hex')) |
15 | t.equal(k1.public.toString('hex'), k2.public.toString('hex')) |
16 | t.end() |
17 | }) |
18 | }) |
19 | }) |
20 | |
21 | tape('create and load sync', function (t) { |
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 | tape('sign and verify', function (t) { |
31 | var keys = ssbkeys.generate() |
32 | var msg = ssbkeys.hash("HELLO THERE?") |
33 | var sig = ssbkeys.sign(keys, msg) |
34 | console.log('public', keys.public) |
35 | console.log('sig', sig) |
36 | t.ok(sig) |
37 | t.equal(ssbkeys.getTag(sig), 'sig.ed25519') |
38 | t.ok(ssbkeys.verify(keys, sig, msg)) |
39 | |
40 | t.end() |
41 | |
42 | }) |
43 | |
44 | tape('sign and verify, call with keys directly', function (t) { |
45 | |
46 | var keys = ssbkeys.generate() |
47 | var msg = ssbkeys.hash("HELLO THERE?") |
48 | var sig = ssbkeys.sign(keys.private, msg) |
49 | console.log('public', keys.public) |
50 | console.log('sig', sig) |
51 | t.ok(sig) |
52 | t.equal(ssbkeys.getTag(sig), 'sig.ed25519') |
53 | t.ok(ssbkeys.verify(keys.public, sig, msg)) |
54 | |
55 | t.end() |
56 | |
57 | }) |
58 | |
59 | tape('sign and verify a javascript object', function (t) { |
60 | |
61 | var obj = require('../package.json') |
62 | |
63 | console.log(obj) |
64 | |
65 | var keys = ssbkeys.generate() |
66 | var sig = ssbkeys.signObj(keys.private, obj) |
67 | console.log(sig) |
68 | t.ok(sig) |
69 | t.ok(ssbkeys.verifyObj(keys, sig, obj)) |
70 | t.end() |
71 | |
72 | }) |
73 | |
74 | //tape('test legacy curve: k256', function (t) { |
75 | // var keys = ssbkeys.generate('k256') |
76 | // |
77 | // var msg = ssbkeys.hash("LEGACY SYSTEMS") |
78 | // var sig = ssbkeys.sign(keys, msg) |
79 | // |
80 | // console.log('public', keys.public) |
81 | // console.log('sig', sig) |
82 | // |
83 | // t.ok(sig) |
84 | // t.equal(ssbkeys.getTag(sig), 'sig.k256') |
85 | // t.ok(ssbkeys.verify(keys, sig, msg)) |
86 | // |
87 | // t.end() |
88 | //}) |
89 | // |
90 | //tape('create and load async, legacy', function (t) { |
91 | // |
92 | // ssbkeys.create(path, 'k256', function(err, k1) { |
93 | // if (err) throw err |
94 | // ssbkeys.load(path, function(err, k2) { |
95 | // if (err) throw err |
96 | // |
97 | // t.equal(k2.curve, 'k256') |
98 | // t.equal(k1.id, k2.id) |
99 | // t.equal(k1.private, k2.private) |
100 | // t.equal(k1.public, k2.public) |
101 | // |
102 | // t.end() |
103 | // }) |
104 | // }) |
105 | //}) |
106 | |
107 | //tape('create and load sync, legacy', function (t) { |
108 | // |
109 | // var k1 = ssbkeys.createSync(path, 'k256', true) |
110 | // var k2 = ssbkeys.loadSync(path) |
111 | // |
112 | // console.log(k2) |
113 | // |
114 | // t.equal(k2.curve, 'k256') |
115 | // t.equal(k1.id, k2.id) |
116 | // t.equal(k1.private, k2.private) |
117 | // t.equal(k1.public, k2.public) |
118 | // |
119 | // t.end() |
120 | //}) |
121 | // |
122 | tape('seeded keys, ed25519', function (t) { |
123 | |
124 | var seed = crypto.randomBytes(32) |
125 | var k1 = ssbkeys.generate('ed25519', seed) |
126 | var k2 = ssbkeys.generate('ed25519', seed) |
127 | |
128 | t.deepEqual(k1, k2) |
129 | |
130 | t.end() |
131 | |
132 | }) |
133 | |
134 | //tape('seeded keys, k256', function (t) { |
135 | // |
136 | // var seed = crypto.randomBytes(32) |
137 | // var k1 = ssbkeys.generate('k256', seed) |
138 | // var k2 = ssbkeys.generate('k256', seed) |
139 | // |
140 | // t.deepEqual(k1, k2) |
141 | // |
142 | // t.end() |
143 | // |
144 | //}) |
145 | // |
146 | tape('ed25519 id === "@" ++ pubkey', function (t) { |
147 | |
148 | var keys = ssbkeys.generate('ed25519') |
149 | t.equal(keys.id, '@' + keys.public) |
150 | |
151 | t.end() |
152 | |
153 | }) |
154 | |
155 |
Built with git-ssb-web