test/index.jsView |
---|
1 | 1 | var tape = require('tape') |
2 | 2 | var ssbkeys = require('../') |
3 | 3 | var crypto = require('crypto') |
4 | | -var path = require('path').join(__dirname, 'keyfile') |
5 | | -var fs = require('fs') |
| 4 | +var path = '/tmp/ssb-keys_'+Date.now() |
6 | 5 | |
7 | 6 | tape('create and load async', function (t) { |
8 | | - try { fs.unlinkSync(path) } catch(e) {} |
9 | 7 | console.log(ssbkeys) |
10 | 8 | ssbkeys.create(path, function(err, k1) { |
11 | 9 | if (err) throw err |
12 | 10 | ssbkeys.load(path, function(err, k2) { |
19 | 17 | }) |
20 | 18 | }) |
21 | 19 | }) |
22 | 20 | |
23 | | -return |
24 | 21 | tape('create and load sync', function (t) { |
25 | | - try { fs.unlinkSync(path) } catch(e) {} |
26 | 22 | var k1 = ssbkeys.createSync(path) |
27 | 23 | var k2 = ssbkeys.loadSync(path) |
28 | 24 | t.equal(k1.id.toString('hex'), k2.id.toString('hex')) |
29 | 25 | t.equal(k1.private.toString('hex'), k2.private.toString('hex')) |
30 | 26 | t.equal(k1.public.toString('hex'), k2.public.toString('hex')) |
31 | 27 | t.end() |
32 | 28 | }) |
33 | 29 | |
34 | | - |
35 | 30 | tape('sign and verify', function (t) { |
36 | | - |
37 | 31 | var keys = ssbkeys.generate() |
38 | 32 | var msg = ssbkeys.hash("HELLO THERE?") |
39 | 33 | var sig = ssbkeys.sign(keys, msg) |
40 | 34 | console.log('public', keys.public) |
76 | 70 | t.end() |
77 | 71 | |
78 | 72 | }) |
79 | 73 | |
80 | | -tape('test legacy curve: k256', function (t) { |
81 | | - var keys = ssbkeys.generate('k256') |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | + |
82 | 106 | |
83 | | - var msg = ssbkeys.hash("LEGACY SYSTEMS") |
84 | | - var sig = ssbkeys.sign(keys, msg) |
85 | | - |
86 | | - console.log('public', keys.public) |
87 | | - console.log('sig', sig) |
88 | | - |
89 | | - t.ok(sig) |
90 | | - t.equal(ssbkeys.getTag(sig), 'sig.k256') |
91 | | - t.ok(ssbkeys.verify(keys, sig, msg)) |
92 | | - |
93 | | - t.end() |
94 | | -}) |
95 | | - |
96 | | -tape('create and load async, legacy', function (t) { |
97 | | - try { fs.unlinkSync(path) } catch(e) {} |
98 | | - ssbkeys.create(path, 'k256', function(err, k1) { |
99 | | - if (err) throw err |
100 | | - ssbkeys.load(path, function(err, k2) { |
101 | | - if (err) throw err |
102 | | - |
103 | | - t.equal(k2.curve, 'k256') |
104 | | - t.equal(k1.id, k2.id) |
105 | | - t.equal(k1.private, k2.private) |
106 | | - t.equal(k1.public, k2.public) |
107 | | - |
108 | | - t.end() |
109 | | - }) |
110 | | - }) |
111 | | -}) |
112 | | - |
113 | | -tape('create and load sync, legacy', function (t) { |
114 | | - try { fs.unlinkSync(path) } catch(e) {} |
115 | | - var k1 = ssbkeys.createSync(path, 'k256', true) |
116 | | - var k2 = ssbkeys.loadSync(path) |
117 | | - |
118 | | - console.log(k2) |
119 | | - |
120 | | - t.equal(k2.curve, 'k256') |
121 | | - t.equal(k1.id, k2.id) |
122 | | - t.equal(k1.private, k2.private) |
123 | | - t.equal(k1.public, k2.public) |
124 | | - |
125 | | - t.end() |
126 | | -}) |
127 | | - |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
128 | 122 | tape('seeded keys, ed25519', function (t) { |
129 | 123 | |
130 | 124 | var seed = crypto.randomBytes(32) |
131 | 125 | var k1 = ssbkeys.generate('ed25519', seed) |
136 | 130 | t.end() |
137 | 131 | |
138 | 132 | }) |
139 | 133 | |
140 | | -tape('seeded keys, k256', function (t) { |
141 | | - |
142 | | - var seed = crypto.randomBytes(32) |
143 | | - var k1 = ssbkeys.generate('k256', seed) |
144 | | - var k2 = ssbkeys.generate('k256', seed) |
145 | | - |
146 | | - t.deepEqual(k1, k2) |
147 | | - |
148 | | - t.end() |
149 | | - |
150 | | -}) |
151 | | - |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | + |
| 142 | + |
| 143 | + |
| 144 | + |
| 145 | + |
152 | 146 | tape('ed25519 id === "@" ++ pubkey', function (t) { |
153 | 147 | |
154 | 148 | var keys = ssbkeys.generate('ed25519') |
155 | 149 | t.equal(keys.id, '@' + keys.public) |
157 | 151 | t.end() |
158 | 152 | |
159 | 153 | }) |
160 | 154 | |
161 | | -tape('create and load presigil-legacy async', function (t) { |
162 | | - try { fs.unlinkSync(path) } catch(e) {} |
163 | | - var keys = ssbkeys.generate('ed25519') |
164 | | - keys.id = keys.id.substring(1) |
165 | | - fs.writeFileSync(path, JSON.stringify(keys)) |
166 | | - |
167 | | - var k2 = ssbkeys.loadSync(path) |
168 | | - t.equal(k2.id, '@' + keys.id) |
169 | | - t.end() |
170 | | - |
171 | | -}) |
172 | | - |
173 | | -tape('create and load presigil-legacy', function (t) { |
174 | | - |
175 | | - try { fs.unlinkSync(path) } catch(e) {} |
176 | | - var keys = ssbkeys.generate('ed25519') |
177 | | - keys.id = keys.id.substring(1) |
178 | | - fs.writeFileSync(path, JSON.stringify(keys)) |
179 | | - |
180 | | - ssbkeys.load(path, function (err, k2) { |
181 | | - if(err) throw err |
182 | | - t.equal(k2.id, '@' + keys.id) |
183 | | - t.end() |
184 | | - }) |
185 | | - |
186 | | -}) |
187 | | - |
188 | | - |