git ssb

1+

Dominic / ssb-keys



Commit 76a13d673e996010f656adc44a1d69cc41b38633

Merge pull request #19 from ssbc/sigil-links

Sigil support
Dominic Tarr committed on 7/30/2015, 3:43:39 PM
Parent: 3a33f961a2a500991a1a90d574257c370c332086
Parent: f75fce2ad5a66cbf4b8ecc30a6545b89082c3fd6

Files changed

index.jschanged
test/index.jschanged
index.jsView
@@ -7,9 +7,9 @@
77 var createHmac = require('hmac')
88
99 var ecc = require('./eccjs')
1010 var sodium = require('sodium').api
11-var isRef = require('ssb-ref')
11+var ssbref = require('ssb-ref')
1212
1313 var pb = require('private-box')
1414
1515 var isBuffer = Buffer.isBuffer
@@ -31,14 +31,12 @@
3131 function hash (data, enc) {
3232 return crypto.createHash('sha256').update(data,enc).digest('base64')+'.sha256'
3333 }
3434
35+var isLink = ssbref.isLink
36+var isFeedId = ssbref.isFeedId
3537
36-var isHash = isRef.isHash
37-var isFeedId = isRef.isFeedId
38-
3938 exports.hash = hash
40-exports.isHash = isHash
4139
4240 function isObject (o) {
4341 return 'object' === typeof o
4442 }
@@ -50,15 +48,20 @@
5048 function isString(s) {
5149 return 'string' === typeof s
5250 }
5351
52+function hasSigil (s) {
53+ return /^(@|%|&)/.test(s)
54+}
55+
5456 function empty(v) { return !!v }
5557
5658 function toBuffer(buf) {
5759 if(buf == null) return buf
5860 if(Buffer.isBuffer(buf)) throw new Error('already a buffer')
5961 var i = buf.indexOf('.')
60- return new Buffer(buf.substring(0, ~i ? i : buf.length), 'base64')
62+ var start = (hasSigil(buf)) ? 1 : 0
63+ return new Buffer(buf.substring(start, ~i ? i : buf.length), 'base64')
6164 }
6265
6366 function toUint8(buf) {
6467 return new Uint8Array(toBuffer(buf))
@@ -83,9 +86,9 @@
8386 return {
8487 curve: curve,
8588 public: pub,
8689 private: keys.private ? tag(keys.private.toString('base64'), curve) : undefined,
87- id: curve === 'ed25519' ? pub : hash(pub)
90+ id: '@'+(curve === 'ed25519' ? pub : hash(pub))
8891 }
8992 }
9093
9194 //(DE)SERIALIZE KEYS
test/index.jsView
@@ -144,12 +144,12 @@
144144 t.end()
145145
146146 })
147147
148-tape('ed25519 id === pubkey', function (t) {
148+tape('ed25519 id === "@" ++ pubkey', function (t) {
149149
150150 var keys = ssbkeys.generate('ed25519')
151- t.equal(keys.id, keys.public)
151+ t.equal(keys.id, '@' + keys.public)
152152
153153 t.end()
154154
155155 })

Built with git-ssb-web