How to use the ssb-ref.isFeed function in ssb-ref

To help you get started, we’ve selected a few ssb-ref examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ssb-junkyard / ssb-cli-dashboard / graph.js View on Github external
// return function that'll construct the right view when called
    return function () {
      var el = require('./feeds')(sbot, screen, filter)
      el.setLabel(label+': '+userId)
      return el
    }
  }

  return graphs[graph]()
}

if (!module.parent) {
  var argv = require('minimist')(process.argv.slice(2))
  var graph  = argv._[0]
  var userId = argv._[1]
  if (['follows', 'followers', 'flags', 'flaggers'].indexOf(graph) === -1 || !require('ssb-ref').isFeed(userId)) {
    console.error('Usage: graph.js [follows|followers|flags|flaggers] {feedid}')
    process.exit(1)
  }
  require('./lib/app')(module.exports.bind(null, graph, userId))
}
github ssbc / ssb-friends / index.js View on Github external
pull.drain(function (contacts) {
          if(!contacts) return

          if (isFeed(contacts.from) && isFeed(contacts.to)) { // live data
            handleBlockUnlock(contacts.from, contacts.to, contacts.value)
          } else { // initial data
            for (var from in contacts) {
              var relations = contacts[from]
              for (var to in relations)
                handleBlockUnlock(from, to, relations[to])
            }
          }
        })
      )
github ssbc / ssb-db / lib / validators.js View on Github external
isBlockedOpts: function (v, n) {
    var err = this.get('object')(v, n)
    if (err)
      return err

    // .source
    if (v.source && !ref.isFeed(v.source))
      return AttrType(n, 'source', 'feedId')

    // .dest
    if (v.dest && !ref.isFeed(v.dest))
      return AttrType(n, 'dest', 'feedId')
  },
github ssbc / ssb-db / lib / validators.js View on Github external
//allow content to be string. (i.e. for encrypted messages)
    //or object with type string
    if(!v.content)
      return MissingAttr(n, 'content', 'object|string')
    else if(typeof v.content === 'string')
      ; //check if it's base64?
    else if('object' === typeof v.content) {
      if(!v.content.type || typeof v.content.type != 'string')
      return MissingAttr(n, 'content.type', 'string')
    }
    else
      return MissingAttr(n, 'content', 'object|string')

    // .author
    if (!ref.isFeed(v.author))
      return MissingAttr(n, 'author', 'feedId')

    // .sequence
    if (typeof v.sequence != 'number')
      return MissingAttr(n, 'sequence', 'number')

    // .previous
    if (v.sequence > 1 && !ref.isMsg(v.previous))
      return MissingAttr(n, 'previous', 'msgId')
    else if(v.sequence == 1 && v.previous != null)
      return MissingAttr(n, 'previous', 'null')

    // .timestamp
    if (typeof v.timestamp != 'number')
      return MissingAttr(n, 'timestamp', 'number')
github ssbc / ssb-db / minimal.js View on Github external
db.box = function (opts, state) {
    var content = opts.content
    var recps = opts.content.recps
    if (recps) {
      const isNonEmptyArrayOfFeeds = isArray(recps) && recps.every(isFeed) && recps.length > 0
      if (isFeed(recps) || isNonEmptyArrayOfFeeds) {
        recps = opts.content.recps = [].concat(recps) // force to array
        return box(opts.content, recps)
      } else {
        throw new Error(
          'private message recipients must be valid feeds, '+
          'was:' + JSON.stringify(recps)
        )
      }
    }
    return opts.content
  }
  db.addMap = function (fn) {
github ssbc / ssb-server / plugins / gossip / index.js View on Github external
get: function (addr) {
        if(ref.isFeed(addr)) return getPeer(addr)
        else if(ref.isFeed(addr.key)) return getPeer(addr.key)
        else throw new Error('must provide id:'+JSON.stringify(addr))
//        return u.find(peers, function (a) {
//          return (
//            addr.port === a.port
//            && addr.host === a.host
//            && addr.key === a.key
//          )
//        })
      },
      connect: valid.async(function (addr, cb) {
github soapdog / patchfox / src / patchpatchcore / contact / obs.js View on Github external
function get(id, lookup) {
        if (!ref.isFeed(id)) {
            console.error("Contact state requires an id!", id);
            throw id;
        }
        if (!cacheLoading) {
            cacheLoading = true;
            loadCache();
        }
        if (!lookup[id]) {
            lookup[id] = Value({});
        }
        return lookup[id];
    }
};
github ssbc / ssb-server / plugins / gossip.js View on Github external
function toMultiserverAddress (address) {
  if (isObject(address)) {
    if (ref.isFeed(address.key)) {
      address.key = address.key.match(feedIdRegex)[1]
    }
    var protocol = 'net'
    if (address.host.endsWith('.onion')) { protocol = 'onion' }
    return [protocol, address.host, address.port].join(':') + '~' + ['shs', toBase64(address.key)].join(':')
  }
  return address
}
github mmckegg / patchwork-next / modules / sbot.js View on Github external
content = ssbKeys.box(content, content.recps.map(function (e) {
            return ref.isFeed(e) ? e : e.link
          }))
        else if(content.mentions)