How to use the jsonld.hasValue function in jsonld

To help you get started, we’ve selected a few jsonld 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 digitalbazaar / did-cli / lib / drivers / veres / index.js View on Github external
}
  }
  if(options.set) {
    if(options.set[0] === 'id' || options.set[0] === '@id') {
      throw new Error('Can not set "id"');
    }
    target[options.set[0]] = options.set[1];
    store = true;
  }
  if(options.delete) {
    delete target[options.delete];
    store = true;
  }
  if(options.find) {
    if(options.find[0] in target &&
      jsonld.hasValue(target, options.find[0], options.find[1])) {
      console.log(did);
    }
  }

  // if no options, show all notes
  if(!options.clear &&
    !options.add && !options.remove &&
    !options.set && !options.get && !options.delete &&
    !options.find) {
    _showNote(did, target, null, options);
  }

  // remove if all properties gone
  if(Object.keys(target).length === 0) {
    delete config.dids[did];
    store = true;
github digitalbazaar / vc-js / lib / vc.js View on Github external
async function _verifyCredential(options = {}) {
  const {credential} = options;

  // check if developer mistakenly passed in a VP as 'credential'
  if(jsonld.hasValue(credential, 'type', 'VerifiablePresentation')) {
    throw new TypeError('Use "presentation" property when verifying VPs.');
  }

  // run common credential checks
  try {
    _checkCredential(credential);
  } catch(error) {
    return {
      verified: false,
      results: [{credential, verified: false, error}],
      error
    };
  }

  const documentLoader = options.documentLoader || defaultDocumentLoader;
github digitalbazaar / did-cli / lib / drivers / veres / index.js View on Github external
const release = await _config._lockConfig(options);
  const config = await _config._loadConfig(options);

  // set explicit notes
  const notes = {};
  if(options.name) {
    logger._debug(options, 'adding "name" note');
    jsonld.addValue(notes, 'name', options.name);
  }
  if(options.description) {
    logger._debug(options, 'adding "description" note');
    jsonld.addValue(notes, 'description', options.description);
  }
  // check if ok to set auto notes
  if(options.notes) {
    if(jsonld.hasValue(config, 'urn:did-client:notes:auto', 'created')) {
      jsonld.addValue(notes, 'created', new Date().toISOString());
    }
  }
  await release();
  await helpers._notesAddMany(didDocument.id, notes, options);

  logger._log(options, 'Local DID generation successful.');

  if(options.register) {
    await _send({options, didDocument, v1/* , privateDidDocument*/});
  } else {
    logger._log(
      options, 'To register the DID globally, use the `register` command.');
  }
};
github digitalbazaar / jsonld-signatures / lib / suites / JwsLinkedDataSignature.js View on Github external
async assertVerificationMethod({verificationMethod}) {
    if(!jsonld.hasValue(verificationMethod, 'type', this.requiredKeyType)) {
      throw new Error(
        `Invalid key type. Key type must be "${this.requiredKeyType}".`);
    }
  }