code: function (token, references) {
      if (!references || !references.length) {
        return Promise.resolve(false);
      }
  
      const endpoints = {};
  
      references.forEach(reference => {
        endpoints[reference.endpoint] = endpoints[reference.endpoint] || [];
        endpoints[reference.endpoint].push(reference.me);
      });
  
      return Promise.all(
        Object.keys(endpoints)
          .map(endpoint => validateToken(token, endpoints[endpoint], endpoint))
      )
        .then(result =>
          result.some(valid => valid && !(valid instanceof Error)) ||
          result.find(valid => valid instanceof TokenScopeError) ||
          result[0]
        );
    }
docs: Helper functions