git ssb

1+

Dominic / ssb-keys



Commit e48278b3df2cbdcd9b4bbc7bc037eed5facb93be

split tests into fs and browser

Dominic Tarr committed on 6/18/2016, 3:21:33 PM
Parent: 9380a0ea407a45d5dc3c9720cb27c322b538739f

Files changed

test/index.jschanged
test/fs.jsadded
test/index.jsView
@@ -1,12 +1,10 @@
11 var tape = require('tape')
22 var ssbkeys = require('../')
33 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()
65
76 tape('create and load async', function (t) {
8- try { fs.unlinkSync(path) } catch(e) {}
97 console.log(ssbkeys)
108 ssbkeys.create(path, function(err, k1) {
119 if (err) throw err
1210 ssbkeys.load(path, function(err, k2) {
@@ -19,22 +17,18 @@
1917 })
2018 })
2119 })
2220
23-return
2421 tape('create and load sync', function (t) {
25- try { fs.unlinkSync(path) } catch(e) {}
2622 var k1 = ssbkeys.createSync(path)
2723 var k2 = ssbkeys.loadSync(path)
2824 t.equal(k1.id.toString('hex'), k2.id.toString('hex'))
2925 t.equal(k1.private.toString('hex'), k2.private.toString('hex'))
3026 t.equal(k1.public.toString('hex'), k2.public.toString('hex'))
3127 t.end()
3228 })
3329
34-
3530 tape('sign and verify', function (t) {
36-
3731 var keys = ssbkeys.generate()
3832 var msg = ssbkeys.hash("HELLO THERE?")
3933 var sig = ssbkeys.sign(keys, msg)
4034 console.log('public', keys.public)
@@ -76,56 +70,56 @@
7670 t.end()
7771
7872 })
7973
80-tape('test legacy curve: k256', function (t) {
81- var keys = ssbkeys.generate('k256')
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+//})
82106
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+//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+//
128122 tape('seeded keys, ed25519', function (t) {
129123
130124 var seed = crypto.randomBytes(32)
131125 var k1 = ssbkeys.generate('ed25519', seed)
@@ -136,20 +130,20 @@
136130 t.end()
137131
138132 })
139133
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+//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+//
152146 tape('ed25519 id === "@" ++ pubkey', function (t) {
153147
154148 var keys = ssbkeys.generate('ed25519')
155149 t.equal(keys.id, '@' + keys.public)
@@ -157,32 +151,4 @@
157151 t.end()
158152
159153 })
160154
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-
test/fs.jsView
@@ -1,0 +1,32 @@
1+var tape = require('tape')
2+var ssbkeys = require('../')
3+var crypto = require('crypto')
4+var path = '/tmp/ssb-keys_'+Date.now()
5+var fs = require('fs')
6+
7+tape('create and load presigil-legacy async', function (t) {
8+
9+ var keys = ssbkeys.generate('ed25519')
10+ keys.id = keys.id.substring(1)
11+ fs.writeFileSync(path, JSON.stringify(keys))
12+
13+ var k2 = ssbkeys.loadSync(path)
14+ t.equal(k2.id, '@' + keys.id)
15+ t.end()
16+
17+})
18+
19+tape('create and load presigil-legacy', function (t) {
20+
21+ var keys = ssbkeys.generate('ed25519')
22+ keys.id = keys.id.substring(1)
23+ fs.writeFileSync(path, JSON.stringify(keys))
24+
25+ ssbkeys.load(path, function (err, k2) {
26+ if(err) throw err
27+ t.equal(k2.id, '@' + keys.id)
28+ t.end()
29+ })
30+
31+})
32+

Built with git-ssb-web