Commit 76a13d673e996010f656adc44a1d69cc41b38633
Merge pull request #19 from ssbc/sigil-links
Sigil supportDominic Tarr committed on 7/30/2015, 3:43:39 PM
Parent: 3a33f961a2a500991a1a90d574257c370c332086
Parent: f75fce2ad5a66cbf4b8ecc30a6545b89082c3fd6
Files changed
index.js | changed |
test/index.js | changed |
index.js | ||
---|---|---|
@@ -7,9 +7,9 @@ | ||
7 | 7 | var createHmac = require('hmac') |
8 | 8 | |
9 | 9 | var ecc = require('./eccjs') |
10 | 10 | var sodium = require('sodium').api |
11 | -var isRef = require('ssb-ref') | |
11 | +var ssbref = require('ssb-ref') | |
12 | 12 | |
13 | 13 | var pb = require('private-box') |
14 | 14 | |
15 | 15 | var isBuffer = Buffer.isBuffer |
@@ -31,14 +31,12 @@ | ||
31 | 31 | function hash (data, enc) { |
32 | 32 | return crypto.createHash('sha256').update(data,enc).digest('base64')+'.sha256' |
33 | 33 | } |
34 | 34 | |
35 | +var isLink = ssbref.isLink | |
36 | +var isFeedId = ssbref.isFeedId | |
35 | 37 | |
36 | -var isHash = isRef.isHash | |
37 | -var isFeedId = isRef.isFeedId | |
38 | - | |
39 | 38 | exports.hash = hash |
40 | -exports.isHash = isHash | |
41 | 39 | |
42 | 40 | function isObject (o) { |
43 | 41 | return 'object' === typeof o |
44 | 42 | } |
@@ -50,15 +48,20 @@ | ||
50 | 48 | function isString(s) { |
51 | 49 | return 'string' === typeof s |
52 | 50 | } |
53 | 51 | |
52 | +function hasSigil (s) { | |
53 | + return /^(@|%|&)/.test(s) | |
54 | +} | |
55 | + | |
54 | 56 | function empty(v) { return !!v } |
55 | 57 | |
56 | 58 | function toBuffer(buf) { |
57 | 59 | if(buf == null) return buf |
58 | 60 | if(Buffer.isBuffer(buf)) throw new Error('already a buffer') |
59 | 61 | 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') | |
61 | 64 | } |
62 | 65 | |
63 | 66 | function toUint8(buf) { |
64 | 67 | return new Uint8Array(toBuffer(buf)) |
@@ -83,9 +86,9 @@ | ||
83 | 86 | return { |
84 | 87 | curve: curve, |
85 | 88 | public: pub, |
86 | 89 | private: keys.private ? tag(keys.private.toString('base64'), curve) : undefined, |
87 | - id: curve === 'ed25519' ? pub : hash(pub) | |
90 | + id: '@'+(curve === 'ed25519' ? pub : hash(pub)) | |
88 | 91 | } |
89 | 92 | } |
90 | 93 | |
91 | 94 | //(DE)SERIALIZE KEYS |
test/index.js | ||
---|---|---|
@@ -144,12 +144,12 @@ | ||
144 | 144 | t.end() |
145 | 145 | |
146 | 146 | }) |
147 | 147 | |
148 | -tape('ed25519 id === pubkey', function (t) { | |
148 | +tape('ed25519 id === "@" ++ pubkey', function (t) { | |
149 | 149 | |
150 | 150 | var keys = ssbkeys.generate('ed25519') |
151 | - t.equal(keys.id, keys.public) | |
151 | + t.equal(keys.id, '@' + keys.public) | |
152 | 152 | |
153 | 153 | t.end() |
154 | 154 | |
155 | 155 | }) |
Built with git-ssb-web