git ssb

0+

Dominic / ssb-peer-invites



Tree: c76f58e8d7c5335c6e7c7f0d9b9c697687c91e59

Files: c76f58e8d7c5335c6e7c7f0d9b9c697687c91e59 / types.js

1607 bytesRaw
1var ref = require('ssb-ref')
2var caps = {invite: require('./cap')}
3var ssbKeys = require('ssb-keys')
4var createIsBase64 = require('is-canonical-base64')
5
6function isObject (o) {
7 return o && 'object' === typeof o
8}
9
10// signatures have a type (eg `.ed25519`) at the end,
11// but not gonna check it right here.
12var signature_rx = createIsBase64('', '\\.sig\\.\\w+')
13var box_rx = createIsBase64()
14
15function isSignature(b) {
16 return signature_rx.test(b)
17}
18
19function isMaybeBase64(b) {
20 return b === undefined || box_rx.test(b)
21}
22
23exports.isInvite = function (msg) {
24 //return true
25 return isObject(msg) && isObject(msg.content) && (
26 'user-invite' === msg.content.type &&
27 ref.isFeed(msg.content.host) &&
28 ref.isFeed(msg.content.invite) &&
29 isMaybeBase64(msg.content.reveal) &&
30 isMaybeBase64(msg.content.public) &&
31 // signature must be valid !!!
32 ssbKeys.verifyObj(msg.content.invite, caps.invite, msg.content)
33 )
34}
35
36exports.isAccept = function (msg) {
37 return isObject(msg) && isObject(msg.content) && (
38 'user-invite/accept' === msg.content.type &&
39 msg.content.id == msg.author &&
40 ref.isMsg(msg.content.receipt) &&
41 isMaybeBase64(msg.content.key) &&
42 // can't verify this without having the invite message.
43 // (that's intentional, forces implementers not to cut corners,
44 // but to check that the receipt is correct)
45 isSignature(msg.content.signature)
46 )
47}
48
49exports.isConfirm = function (msg) {
50 return isObject(msg) && isObject(msg.content) && (
51 'user-invite/confirm' === msg.content.type &&
52 exports.isAccept(msg.content.embed)
53 )
54}
55
56
57
58
59
60
61
62

Built with git-ssb-web