How to use jsonld-signatures - 10 common examples

To help you get started, we’ve selected a few jsonld-signatures 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
before(async () => {
  // Set up the key that will be signing and verifying
  keyPair = await Ed25519KeyPair.generate({
    id: 'https://example.edu/issuers/keys/1',
    controller: 'https://example.com/i/carol'
  });

  // Register the controller document and the key document with documentLoader
  contexts['https://example.com/i/carol'] = assertionController;
  contexts['https://example.edu/issuers/keys/1'] = keyPair.publicNode();

  // Add the key to the Controller doc (authorizes its use for assertion)
  assertionController.assertionMethod.push(keyPair.id);

  // Set up the signature suite, using the generated key
  suite = new jsigs.suites.Ed25519Signature2018({
    verificationMethod: 'https://example.edu/issuers/keys/1',
    key: keyPair
  });
});
github digitalbazaar / did-cli / lib / driver-veres.js View on Github external
sign: ['ledgerEvent', (results, callback) => {
      const privateKeyPem =
        pki.privateKeyToPem(results.generateKeyPair.privateKey);

      // sign the DID Document
      jsigs.sign(results.ledgerEvent, {
        algorithm: 'LinkedDataSignature2015',
        privateKeyPem: privateKeyPem,
        creator: did + '/keys/1'
      }, (err, result) => {
        if(err) {
          return callback(err);
        }
        callback(null, result);
      });
    }],
    postDidDocument: ['pow', 'sign', (results, callback) => {
github digitalbazaar / vc-js / lib / vc.js View on Github external
const documentLoader = options.documentLoader || defaultDocumentLoader;

  const {controller, domain} = options;
  const purpose = options.purpose || new CredentialIssuancePurpose({
    controller,
    domain
  });

  // run common credential checks
  const {credential} = options;
  if(!credential) {
    throw new TypeError('"credential" property is required for issuing.');
  }
  _checkCredential(credential);

  return jsigs.sign(credential, {purpose, documentLoader, ...options});
}
github digitalbazaar / did-cli / lib / driver-veres.js View on Github external
// setup JSON-LD library to use
const jsonld = require('jsonld')();
// Use the local Veres One context...
const _orig_doc_loader = jsonld.documentLoader;
jsonld.documentLoader = function(url, callback) {
    if (url == 'https://w3id.org/veres-one/v1') {
        return callback(null,
                        {contextUrl: null,
                         documentUrl: url,
                         document: v1_context});
    } else {
        return _orig_doc_loader(url, callback);
    }
};
jsigs.use('jsonld', jsonld);
equihashSigs.use('jsonld', jsonld);

const api = {};
module.exports = api;

api.create = options => {
  let did = 'did:v1:testnet:' + (options.did || uuid());
  let hostname = 'testnet.veres.one';

  if(options.mode === 'dev') {
    hostname = 'veres.one.local:42443';
    request = request.defaults({json: true, strictSSL: false});
  } else if(options.mode === 'live') {
    did = 'did:v1:' + (options.did || uuid());
    hostname = 'veres.one';
  }
github digitalbazaar / vc-js / lib / vc.js View on Github external
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
'use strict';

const jsonld = require('jsonld');
const jsigs = require('jsonld-signatures');
const CredentialIssuancePurpose = require('./CredentialIssuancePurpose');
const defaultDocumentLoader = jsigs.extendContextLoader(
  require('./documentLoader'));

// Z and T can be lowercase
// RFC3339 regex
const dateRegex = new RegExp('^(\\d{4})-(0[1-9]|1[0-2])-' +
    '(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):' +
    '([0-5][0-9]):([0-5][0-9]|60)' +
    '(\\.[0-9]+)?(Z|(\\+|-)([01][0-9]|2[0-3]):' +
    '([0-5][0-9]))$', 'i');

module.exports = {
  issue,
  verify,
  createPresentation,
  CredentialIssuancePurpose,
  defaultDocumentLoader,
github digitalbazaar / vc-js / tests / 10-verify.spec.js View on Github external
async function _generateCredential() {
  const mockCredential = jsonld.clone(mockData.credentials.alpha);
  const {authenticationKey, documentLoader} = await _generateDid();
  const {Ed25519Signature2018} = jsigs.suites;
  const {AuthenticationProofPurpose} = jsigs.purposes;
  testLoader.addLoader(documentLoader);
  const credential = await jsigs.sign(mockCredential, {
    compactProof: false,
    documentLoader: testLoader.documentLoader.bind(testLoader),
    suite: new Ed25519Signature2018({key: authenticationKey}),
    purpose: new AuthenticationProofPurpose({
      challenge: 'challengeString'
    })
  });
  return {credential, documentLoader};
}
github digitalbazaar / vc-js / tests / 10-verify.spec.js View on Github external
async function _generatePresentation({challenge, domain}) {
  const mockPresentation = jsonld.clone(mockData.presentations.alpha);
  const {authenticationKey, documentLoader: dlp} = await _generateDid();
  testLoader.addLoader(dlp);
  const {Ed25519Signature2018} = jsigs.suites;
  const {AuthenticationProofPurpose} = jsigs.purposes;
  const {credential, documentLoader: dlc} = await _generateCredential();
  testLoader.addLoader(dlc);
  mockPresentation.verifiableCredential.push(credential);
  const presentation = await jsigs.sign(mockPresentation, {
    compactProof: false,
    documentLoader: testLoader.documentLoader.bind(testLoader),
    suite: new Ed25519Signature2018({key: authenticationKey}),
    purpose: new AuthenticationProofPurpose({challenge, domain})
  });
  return {presentation};
}
github digitalbazaar / vc-js / tests / 10-verify.spec.js View on Github external
async function _generateCredential() {
  const mockCredential = jsonld.clone(mockData.credentials.alpha);
  const {authenticationKey, documentLoader} = await _generateDid();
  const {Ed25519Signature2018} = jsigs.suites;
  const {AuthenticationProofPurpose} = jsigs.purposes;
  testLoader.addLoader(documentLoader);
  const credential = await jsigs.sign(mockCredential, {
    compactProof: false,
    documentLoader: testLoader.documentLoader.bind(testLoader),
    suite: new Ed25519Signature2018({key: authenticationKey}),
    purpose: new AuthenticationProofPurpose({
      challenge: 'challengeString'
    })
  });
  return {credential, documentLoader};
}
github digitalbazaar / vc-js / tests / 10-verify.spec.js View on Github external
async function _generateCredential() {
  const mockCredential = jsonld.clone(mockData.credentials.alpha);
  const {authenticationKey, documentLoader} = await _generateDid();
  const {Ed25519Signature2018} = jsigs.suites;
  const {AuthenticationProofPurpose} = jsigs.purposes;
  testLoader.addLoader(documentLoader);
  const credential = await jsigs.sign(mockCredential, {
    compactProof: false,
    documentLoader: testLoader.documentLoader.bind(testLoader),
    suite: new Ed25519Signature2018({key: authenticationKey}),
    purpose: new AuthenticationProofPurpose({
      challenge: 'challengeString'
    })
  });
  return {credential, documentLoader};
}
github digitalbazaar / did-io / tests / veres-one / veres-one.spec.js View on Github external
const jsonld = v1.injector.use('jsonld');
    const documentLoader = jsonld.documentLoader;

    jsonld.documentLoader = async url => {
      if(url in VeresOne.contexts) {
        return {
          contextUrl: null,
          documentUrl: url,
          document: VeresOne.contexts[url]
        };
      }
      return documentLoader(url);
    };
    v1.injector.use('jsonld', jsonld);
    const jsigs = require('jsonld-signatures');
    jsigs.use('jsonld', jsonld);
    const eproofs = require('equihash-signature');
    eproofs.install(jsigs);
    v1.injector.use('jsonld-signatures', jsigs);

    v1.keyStore = Store.using('mock');
    v1.didStore = Store.using('mock');
    v1.metaStore = Store.using('mock');
  });

jsonld-signatures

An implementation of the Linked Data Signatures specifications for JSON-LD in JavaScript.

BSD-3-Clause
Latest version published 12 months ago

Package Health Score

67 / 100
Full package analysis