How to use the ssb-ref.isMsgId 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 ssbc / ssb-server / plugins / bundles.js View on Github external
createWorking: function (opts, cb) {
      if (!opts || !opts.name || !bundleNameRegex.test(opts.name))
        return cb(error('Invalid name', { invalidName: true }))
      if (!opts.desc || typeof opts.desc != 'string')
        return cb(error('Invalid desc', { invalidDesc: true }))
      if (!opts.dirpath || typeof opts.dirpath != 'string')
        return cb(error('Invalid directory path', { invalidDirpath: true }))
      if (opts.root && !ref.isMsgId(opts.root))
        return cb(error('Invalid root hash', { invalidRoot: true }))
      if (opts.branch && !ref.isMsgId(opts.branch))
        return cb(error('Invalid branch hash', { invalidBranch: true }))

      // add working bundle to db
      var bundle = {
        id: makeWorkingid(),
        name: normalizeName(opts.name),
        desc: opts.desc,
        root: opts.root,
        branch: opts.branch,
        dirpath: opts.dirpath
      }
      var done = multicb()
      workingDB.put(bundle.id, bundle, done())
      bundlesDB.put([normalizeName(bundle.name), bundle.id], 1, done())
      if (bundle.root)
        bundlesDB.put([bundle.root, bundle.id], 1, done())
github ssbc / ssb-server / plugins / bundles.js View on Github external
listRevisions: function (nameOrBundleid) {
      if (!isWorkingid(nameOrBundleid) && !ref.isMsgId(nameOrBundleid))
        nameOrBundleid = normalizeName(nameOrBundleid)
      return pull(
        // read the index
        pl.read(bundlesDB, {
          gte:    [nameOrBundleid, LO],
          lte:    [nameOrBundleid, HI],
          values: false
        }),
        paramap(function (key, cb) {
          var bundleid = key[1]
          if (ref.isMsgId(bundleid)) {
            // fetch published bundle
            bundlesDB.get(bundleid, cb)
          } else if (isWorkingid(bundleid)) {
            // fetch working bundle
            workingDB.get(bundleid, cb)
github ssbc / ssb-server / plugins / bundles.js View on Github external
sbot.bundles.get(bundleid, function (err, bundle) {
          if (err) return cb(err)

          if (ref.isMsgId(bundleid)) {
            // published bundle, lookup the blob
            var blob = bundle.blobs[normalizePath(relpath)]
            if (!blob)
              return cb(error('File not found', { notFound: true }))
            blob.isAutoIndex = isAutoIndex
            cb(null, blob)
          } else {
            // working bundle, read from disk
            var filepath = pathlib.join(bundle.dirpath, normalizePath(relpath))
            fs.stat(filepath, function (err, stat) {
              if (err)
                return cb(explain(err, 'Failed to stat file'))
              stat.path = filepath
              stat.type = mime.lookup(filepath)
              stat.isAutoIndex = isAutoIndex
              cb(null, stat)
github blockades / scuttle-dark-crystal / recover / async / request.js View on Github external
return function Request (rootId, recipients, callback) {
    if (callback === undefined && typeof recipients === 'function') return Request(rootId, null, recipients)
    // if only 2 args, run the function with recipients set to null

    if (!isMsgId(rootId)) return callback(new Error('Invalid root'))
    if (recipients && !Array.isArray(recipients)) return callback(new Error(`Recipients must either be an Array of feed Ids or falsey`))

    if (!recpsValid(recipients)) return callback(new Error(`All recipients must be a feedId`))

    // TODO: verifiy that recipients.indexOf(server.id) < 0

    pull(
      pullShardsByRoot(rootId),
      recipients
        ? pull.filter(isShardForNamedRecipient)
        : pull.through(),
      pull.map(shard => {
        const { recps } = getContent(shard)
        return {
          type: 'invite', // is over-written by invites.async.private.publish
          version: '1', // ditto
github blockades / scuttle-dark-crystal / ritual / pull / by-root.js View on Github external
return function byRoot (rootId, opts = {}) {
    if (!rootId) throw new Error('must have a rootId')
    if (!isMsgId(rootId)) throw new Error('Invalid rootId')

    const query = [{
      $filter: {
        value: {
          timestamp: { $gt: 0 },
          content: {
            type: 'dark-crystal/ritual',
            root: rootId
          }
        }
      }
    }]

    const _opts = Object.assign({}, { query, limit: 100 }, opts)

    return pull(
github blockades / scuttle-dark-crystal / forward / async / publish.js View on Github external
return function publishForward (root, recp, callback) {
    if (!ref.isMsgId(root)) return callback(new Error('Invalid rootId'))
    pull(
      pullShardsByRoot(root),
      pull.collect((err, shards) => {
        if (err) return callback(err)

        if (shards.length < 1) {
          return callback(new Error('There are no shards associated with rootId ', root))
        }

        if (shards.length > 1) {
          return callback(new Error('You have more than one shard for this secret, not yet supported'))
        }

        if (get(shards[0], 'value.author') === recp) {
          return callback(new Error('You may not forward a shard to its author. Use reply instead.'))
        }
github blockades / scuttle-dark-crystal / recover / async / deleteEphemeralKeyPair.js View on Github external
return function deleteEphemeralKeyPair (rootId, recipient, callback) {
    if (!isMsgId(rootId)) return callback(new Error('Invalid root'))
    if (!isFeed(recipient)) return callback(new Error('Invalid recipient'))

    server.ephemeral.deleteKeyPair({ rootId, recp: recipient }, (err) => {
      if (err) return callback(err)
      callback(null, true)
    })
  }
}
github staltz / manyverse / src / frontend / components / Markdown.ts View on Github external
link: (props: {children: any; href: string}) => {
    const isFeedCypherlink = Ref.isFeedId(props.href);
    const isMsgCypherlink = Ref.isMsgId(props.href);
    const isCypherlink = isFeedCypherlink || isMsgCypherlink;
    const isChildCypherlink =
      props.children.length === 1 &&
      (Ref.isFeedId(props.children[0]) || Ref.isMsgId(props.children[0]));
    return $(
      Text,
      {
        ...textProps,
        style: isCypherlink ? styles.cypherlink : styles.link,
        onPress: () => {
          if (isFeedCypherlink) {
            GlobalEventBus.dispatch({
              type: 'triggerFeedCypherlink',
              feedId: props.href,
            });
          } else if (isMsgCypherlink) {