git ssb

1+

Dominic / ssb-private-groups



Tree: 0176e2211786e153e0d216f0557517b926095894

Files: 0176e2211786e153e0d216f0557517b926095894 / util.js

1349 bytesRaw
1var cl = require('chloride')
2
3//var rx = require('is-canonical-base64')(null, null, 32)
4exports.isUnboxKey = function (s) {
5 return s === Buffer.from(s, 'base64').toString('base64')
6// return rx.test(s)
7}
8exports.id2Buffer = function (id) {
9 return Buffer.from(id.substring(1, id.indexOf('.')), 'base64')
10}
11
12exports.isBox2 = function (ctxt) {
13 //we can just do a fairly lax check here, don't check the content
14 //is canonical base64, because that check has already been done.
15 return 'string' == typeof ctxt && /\.box2$/.test(ctxt)
16}
17
18exports.isCurvePair = function (keys) {
19 return keys.public && keys.private
20}
21
22exports.ctxt2Buffer = function (ctxt) {
23 return exports.isBox2(ctxt) && Buffer.from(ctxt.substring(0, ctxt.indexOf('.')), 'base64')
24}
25
26function toBuffer(b) {
27 return Buffer.isBuffer(b) ? b : Buffer.from(b, 'base64')
28}
29
30exports.hmac = function (a, b) {
31 return cl.crypto_auth(toBuffer(a), toBuffer(b))
32}
33
34exports.getGroupMsgKey = function (previous, group) {
35 //or would it be better to use generic hash (with key?)
36 return exports.hmac(Buffer.concat([previous, exports.id2Buffer(group.id)]), Buffer.from(group.unbox, 'base64'))
37}
38
39exports.scalarmultKeys = function (a_key, recps) {
40 return recps.map(function (curve) {
41 return cl.crypto_scalarmult(
42 toBuffer(curve.private),
43 toBuffer(a_key)
44 )
45 })
46}
47
48
49
50
51

Built with git-ssb-web