git ssb

1+

Dominic / ssb-keys



Commit 31fc81304b476aa179bd085b401d58d5ba417878

Merge pull request #16 from dominictarr/ssb-ref

get isHash (etc) from ssb-ref
Dominic Tarr committed on 6/29/2015, 5:28:14 PM
Parent: 8c7bb0b48da95a39d1c1edeccd2ccba7792f4725
Parent: de2e69c05bf715f6fad6a795f6467828c73b49ff

Files changed

index.jschanged
package.jsonchanged
test/index.jschanged
index.jsView
@@ -7,8 +7,9 @@
77 var createHmac = require('hmac')
88 var Blake2s = require('blake2s')
99
1010 var ecc = require('./eccjs')
11+var isRef = require('ssb-ref')
1112
1213 //UTILS
1314
1415 function clone (obj) {
@@ -23,23 +24,23 @@
2324 function hash (data, enc) {
2425 return new Blake2s().update(data, enc).digest('base64') + '.blake2s'
2526 }
2627
27-function isHash (data) {
28- return isString(data) && /^[A-Za-z0-9\/+]{43}=\.blake2s$/.test(data)
29-}
3028
29+var isHash = isRef.isHash
30+var isFeedId = isRef.isFeedId
31+
32+exports.hash = hash
33+exports.isHash = isHash
34+
3135 function isObject (o) {
3236 return 'object' === typeof o
3337 }
3438
3539 function isFunction (f) {
3640 return 'function' === typeof f
3741 }
3842
39-exports.isHash = isHash
40-exports.hash = hash
41-
4243 function isString(s) {
4344 return 'string' === typeof s
4445 }
4546
@@ -75,9 +76,9 @@
7576 return {
7677 curve: curve,
7778 public: pub,
7879 private: keys.private ? tag(keys.private.toString('base64'), curve) : undefined,
79- id: hash(pub)
80+ id: curve === 'ed25519' ? pub : hash(pub)
8081 }
8182 }
8283
8384 //(DE)SERIALIZE KEYS
@@ -281,28 +282,29 @@
281282 }
282283
283284 //TODO: remove these (use asymmetric auth for everything)
284285
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+//
291310
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.jsonView
@@ -1,8 +1,8 @@
11 {
22 "name": "ssb-keys",
33 "description": "keyfile operations for ssb",
4- "version": "1.0.1",
4+ "version": "2.0.0",
55 "homepage": "https://github.com/ssbc/ssb-keys",
66 "repository": {
77 "type": "git",
88 "url": "git://github.com/ssbc/ssb-crypto.git"
@@ -13,9 +13,10 @@
1313 "eccjs": "git://github.com/dominictarr/eccjs.git#586f6d47507184a2efe84684ed0a30605cbc43a5",
1414 "hmac": "~1.0.1",
1515 "libsodium-wrappers": "^0.2.8",
1616 "mkdirp": "~0.5.0",
17- "sodium": "^1.0.17"
17+ "sodium": "^1.0.17",
18+ "ssb-ref": "~0.0.0"
1819 },
1920 "devDependencies": {
2021 "tape": "~3.0.0"
2122 },
@@ -26,5 +27,5 @@
2627 "test": "set -e; for t in test/*.js; do node $t; done"
2728 },
2829 "author": "Paul Frazee <pfrazee@gmail.com>",
2930 "license": "MIT"
30-}
31+}
test/index.jsView
@@ -143,4 +143,13 @@
143143
144144 t.end()
145145
146146 })
147+
148+tape('ed25519 id === pubkey', function (t) {
149+
150+ var keys = ssbkeys.generate('ed25519')
151+ t.equal(keys.id, keys.public)
152+
153+ t.end()
154+
155+})

Built with git-ssb-web