index.jsView |
---|
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 | 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 | 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 | 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 | |