Commit 31fc81304b476aa179bd085b401d58d5ba417878
Merge pull request #16 from dominictarr/ssb-ref
get isHash (etc) from ssb-refDominic Tarr committed on 6/29/2015, 5:28:14 PM
Parent: 8c7bb0b48da95a39d1c1edeccd2ccba7792f4725
Parent: de2e69c05bf715f6fad6a795f6467828c73b49ff
Files changed
index.js | changed |
package.json | changed |
test/index.js | changed |
index.js | ||
---|---|---|
@@ -7,8 +7,9 @@ | ||
7 | 7 | var createHmac = require('hmac') |
8 | 8 | var Blake2s = require('blake2s') |
9 | 9 | |
10 | 10 | var ecc = require('./eccjs') |
11 | +var isRef = require('ssb-ref') | |
11 | 12 | |
12 | 13 | //UTILS |
13 | 14 | |
14 | 15 | function clone (obj) { |
@@ -23,23 +24,23 @@ | ||
23 | 24 | function hash (data, enc) { |
24 | 25 | return new Blake2s().update(data, enc).digest('base64') + '.blake2s' |
25 | 26 | } |
26 | 27 | |
27 | -function isHash (data) { | |
28 | - return isString(data) && /^[A-Za-z0-9\/+]{43}=\.blake2s$/.test(data) | |
29 | -} | |
30 | 28 | |
29 | +var isHash = isRef.isHash | |
30 | +var isFeedId = isRef.isFeedId | |
31 | + | |
32 | +exports.hash = hash | |
33 | +exports.isHash = isHash | |
34 | + | |
31 | 35 | function isObject (o) { |
32 | 36 | return 'object' === typeof o |
33 | 37 | } |
34 | 38 | |
35 | 39 | function isFunction (f) { |
36 | 40 | return 'function' === typeof f |
37 | 41 | } |
38 | 42 | |
39 | -exports.isHash = isHash | |
40 | -exports.hash = hash | |
41 | - | |
42 | 43 | function isString(s) { |
43 | 44 | return 'string' === typeof s |
44 | 45 | } |
45 | 46 | |
@@ -75,9 +76,9 @@ | ||
75 | 76 | return { |
76 | 77 | curve: curve, |
77 | 78 | public: pub, |
78 | 79 | private: keys.private ? tag(keys.private.toString('base64'), curve) : undefined, |
79 | - id: hash(pub) | |
80 | + id: curve === 'ed25519' ? pub : hash(pub) | |
80 | 81 | } |
81 | 82 | } |
82 | 83 | |
83 | 84 | //(DE)SERIALIZE KEYS |
@@ -281,28 +282,29 @@ | ||
281 | 282 | } |
282 | 283 | |
283 | 284 | //TODO: remove these (use asymmetric auth for everything) |
284 | 285 | |
285 | -exports.signObjHmac = function (secret, obj) { | |
286 | - obj = clone(obj) | |
287 | - var str = JSON.stringify(obj, null, 2) | |
288 | - obj.hmac = exports.hmac(str, secret) | |
289 | - return obj | |
290 | -} | |
286 | +//exports.signObjHmac = function (secret, obj) { | |
287 | +// obj = clone(obj) | |
288 | +// var str = JSON.stringify(obj, null, 2) | |
289 | +// obj.hmac = exports.hmac(str, secret) | |
290 | +// return obj | |
291 | +//} | |
292 | +// | |
293 | +//exports.verifyObjHmac = function (secret, obj) { | |
294 | +// obj = clone(obj) | |
295 | +// var hmac = obj.hmac | |
296 | +// delete obj.hmac | |
297 | +// var str = JSON.stringify(obj, null, 2) | |
298 | +// var _hmac = exports.hmac(str, secret) | |
299 | +// return deepEqual(hmac, _hmac) | |
300 | +//} | |
301 | +// | |
302 | +//exports.createAuth = function (keys, role) { | |
303 | +// return exports.signObj(keys, { | |
304 | +// role: role || 'client', | |
305 | +// ts: Date.now(), | |
306 | +// public: keys.public | |
307 | +// }) | |
308 | +//} | |
309 | +// | |
291 | 310 | |
292 | -exports.verifyObjHmac = function (secret, obj) { | |
293 | - obj = clone(obj) | |
294 | - var hmac = obj.hmac | |
295 | - delete obj.hmac | |
296 | - var str = JSON.stringify(obj, null, 2) | |
297 | - var _hmac = exports.hmac(str, secret) | |
298 | - return deepEqual(hmac, _hmac) | |
299 | -} | |
300 | - | |
301 | -exports.createAuth = function (keys, role) { | |
302 | - return exports.signObj(keys, { | |
303 | - role: role || 'client', | |
304 | - ts: Date.now(), | |
305 | - public: keys.public | |
306 | - }) | |
307 | -} | |
308 | - |
package.json | ||
---|---|---|
@@ -1,8 +1,8 @@ | ||
1 | 1 | { |
2 | 2 | "name": "ssb-keys", |
3 | 3 | "description": "keyfile operations for ssb", |
4 | - "version": "1.0.1", | |
4 | + "version": "2.0.0", | |
5 | 5 | "homepage": "https://github.com/ssbc/ssb-keys", |
6 | 6 | "repository": { |
7 | 7 | "type": "git", |
8 | 8 | "url": "git://github.com/ssbc/ssb-crypto.git" |
@@ -13,9 +13,10 @@ | ||
13 | 13 | "eccjs": "git://github.com/dominictarr/eccjs.git#586f6d47507184a2efe84684ed0a30605cbc43a5", |
14 | 14 | "hmac": "~1.0.1", |
15 | 15 | "libsodium-wrappers": "^0.2.8", |
16 | 16 | "mkdirp": "~0.5.0", |
17 | - "sodium": "^1.0.17" | |
17 | + "sodium": "^1.0.17", | |
18 | + "ssb-ref": "~0.0.0" | |
18 | 19 | }, |
19 | 20 | "devDependencies": { |
20 | 21 | "tape": "~3.0.0" |
21 | 22 | }, |
@@ -26,5 +27,5 @@ | ||
26 | 27 | "test": "set -e; for t in test/*.js; do node $t; done" |
27 | 28 | }, |
28 | 29 | "author": "Paul Frazee <pfrazee@gmail.com>", |
29 | 30 | "license": "MIT" |
30 | -} | |
31 | +} |
Built with git-ssb-web