How to use the jsonld.frame 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 / vc-js / tests / 10-verify.spec.js View on Github external
}
  }
  // target not found
  if(!found) {
    const err = new Error('Not Found');
    err.httpStatusCode = 404;
    err.status = 404;
    throw err;
  }

  const context = [
    constants.DID_CONTEXT_URL,
    constants.VERES_ONE_CONTEXT_URL
  ];
  // frame target
  const framed = await jsonld.frame(
    filtered, {'@context': context, id: target}, {embed: '@always'});

  return Object.assign({'@context': context}, framed['@graph'][0]);
}
github digibib / ls.ext / redef / patron-client / src / backend / routes / resources.js View on Github external
return new Promise((resolve, reject) => {
    jsonld.frame(ntdoc, frame, (error, framedJson) => {
      if (error) {
        reject(error)
      }
      try {
        // error in transformWork will end up in Promise.catch and return 500
        const work = transformWork(framedJson[ '@graph' ][ 0 ])
        resolve(work)
      } catch (error) {
        reject(error)
      }
    })
  })
}
github digitalbazaar / jsonld-signatures / lib / Helper.js View on Github external
};
    if(proofPurpose === 'publicKey') {
      // direct access to public keys
      frame.publicKey = {'@embed': '@never'};
    } else {
      // indirect access to public keys via application suites
      frame[proofPurpose] = {
        '@embed': '@always',
        publicKey: {'@embed': '@never'}
      };
    }
    const opts = {};
    if(options.documentLoader) {
      opts.documentLoader = options.documentLoader;
    }
    const framed = await jsonld.frame(owners, frame, opts);
    return framed['@graph'];
  }
github TangleID / TangleID / packages / jsonld / src / jsonld.ts View on Github external
export const frame = async (input: object, frame: object, options: object = {}): Promise => {
  // @ts-ignore
  return jsonld.frame(input, frame, options);
};
github digitalbazaar / jsonld-signatures / lib / suites / LinkedDataSignature.js View on Github external
// backwards compatibility support for `creator`
      const {creator} = proof;
      verificationMethod = creator;
    }

    if(typeof verificationMethod === 'object') {
      verificationMethod = verificationMethod.id;
    }

    if(!verificationMethod) {
      throw new Error('No "verificationMethod" or "creator" found in proof.');
    }

    // Note: `expansionMap` is intentionally not passed; we can safely drop
    // properties here and must allow for it
    const {'@graph': [framed]} = await jsonld.frame(verificationMethod, {
      '@context': constants.SECURITY_CONTEXT_URL,
      '@embed': '@always',
      id: verificationMethod
    }, {documentLoader, compactToRelative: false});
    if(!framed) {
      throw new Error(`Verification method ${verificationMethod} not found.`);
    }

    // ensure verification method has not been revoked
    if(framed.revoked !== undefined) {
      throw new Error('The verification method has been revoked.');
    }

    return framed;
  }
github digitalbazaar / jsonld-signatures / lib / Helper.js View on Github external
// `CryptographicKey` used here for backwards compatibility
    let requiredKeyType = 'CryptographicKey';
    if(options.keyType) {
      requiredKeyType = options.keyType;
    }

    const frame = {
      '@context': constants.SECURITY_CONTEXT_URL,
      type: requiredKeyType,
      owner: {'@embed': '@never'}
    };
    const opts = {};
    if(options.documentLoader) {
      opts.documentLoader = options.documentLoader;
    }
    const framed = await jsonld.frame(key, frame, opts);

    // FIXME: improve validation
    if(!framed['@graph'][0]) {
      throw new Error(`The public key is not a "${requiredKeyType}".`);
    }
    if(!framed['@graph'][0].owner) {
      throw new Error('The public key has no specified owner.');
    }
    framed['@graph'][0]['@context'] = framed['@context'];
    return framed['@graph'][0];
  }
github DefinitelyTyped / DefinitelyTyped / types / jsonld / jsonld-tests.ts View on Github external
* frame() test
 */
jsonld.frame(doc, frame, (err, res) => {
    log(res);
});

jsonld.frame(doc, frame, {embed: "@last", explicit: false}, (err, res) => {
    log(res);
});

jsonld.frame(doc, frame)
.then((res) => {
    log(res);
});

jsonld.frame(doc, frame, {requireAll: true})
.then((res) => {
    log(res);
});

/**
 * normalize() test
 */
jsonld.normalize(doc, (err, res) => {
    log(res);
});

jsonld.normalize(doc, {algorithm: 'URDNA2015', expansion: false}, (err, res) => {
    log(res);
});

jsonld.normalize(doc)
github DefinitelyTyped / DefinitelyTyped / types / jsonld / jsonld-tests.ts View on Github external
log(res);
});

jsonld.flatten(doc, context, {base: baseUrl})
.then((res) => {
    log(res);
});

/**
 * frame() test
 */
jsonld.frame(doc, frame, (err, res) => {
    log(res);
});

jsonld.frame(doc, frame, {embed: "@last", explicit: false}, (err, res) => {
    log(res);
});

jsonld.frame(doc, frame)
.then((res) => {
    log(res);
});

jsonld.frame(doc, frame, {requireAll: true})
.then((res) => {
    log(res);
});

/**
 * normalize() test
 */
github BlueBrain / nexus-js / apps / search-poc / src / views / MainView.tsx View on Github external
        .then(json => jsonld.frame(json, studioFrame, { embed: '@always' }))
        .then(frame => frame['@graph'][0])
github levelgraph / levelgraph-jsonld / index.js View on Github external
fetchExpandedTriples(iri, function(err, expanded) {
      if (err || expanded === null) {
        return callback(err, expanded);
      }
      jsonld.frame(expanded[iri], frame, function(err, framed) {
        if (err || expanded === null) {
          return callback(err, framed);
        }
        jsonld.compact(framed, context, options, callback);
      });
    });
  };