How to use crypto-ld - 10 common examples

To help you get started, we’ve selected a few crypto-ld 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-io / tests / veres-one / veres-did-doc.spec.js View on Github external
it('should add/remove a public key node from the DID Doc', async () => {
      await didDoc.importKeys(exampleKeys);

      const authSuite = didDoc.doc[constants.SUITES.authentication][0];
      const authKey = authSuite.publicKey[0];

      didDoc.removeKey(authKey);

      // Check to make sure key is removed
      expect(authSuite.publicKey).to.eql([]);
      expect(didDoc.keys[keyId]).to.not.exist();

      // Now re-add the key
      const suiteId = `${did}#auth-suite-1`;

      const key = await LDKeyPair.from(exampleKeys[keyId]);
      await didDoc.addKey({suiteId, key});

      expect(authSuite.publicKey).to.eql([key.publicNode({owner: did})]);
      expect(didDoc.keys[keyId]).to.eql(key);
    });
  });
github digitalbazaar / vc-js / tests / 10-verify.spec.js View on Github external
async function _generateDid() {
  const mockDoc = jsonld.util.clone(mockData.privateDidDocuments.alpha);
  const capabilityInvocationKey = await Ed25519KeyPair.generate();
  const keyFingerprint = `z${capabilityInvocationKey.fingerprint()}`;

  const did = `did:v1:test:nym:${keyFingerprint}`;
  // cryptonym dids are based on fingerprint of capabilityInvokation key
  mockDoc.id = did;
  capabilityInvocationKey.id = _generateKeyId(
    {did, key: capabilityInvocationKey});
  const controller = did;
  capabilityInvocationKey.controller = controller;
  mockDoc.capabilityInvocation[0] = {
    id: capabilityInvocationKey.id,
    type: capabilityInvocationKey.type,
    controller: capabilityInvocationKey.controller,
    publicKeyBase58: capabilityInvocationKey.publicKeyBase58
  };
  const authenticationKey = await Ed25519KeyPair.generate();
github digitalbazaar / vc-js / tests / 10-verify.spec.js View on Github external
const keyFingerprint = `z${capabilityInvocationKey.fingerprint()}`;

  const did = `did:v1:test:nym:${keyFingerprint}`;
  // cryptonym dids are based on fingerprint of capabilityInvokation key
  mockDoc.id = did;
  capabilityInvocationKey.id = _generateKeyId(
    {did, key: capabilityInvocationKey});
  const controller = did;
  capabilityInvocationKey.controller = controller;
  mockDoc.capabilityInvocation[0] = {
    id: capabilityInvocationKey.id,
    type: capabilityInvocationKey.type,
    controller: capabilityInvocationKey.controller,
    publicKeyBase58: capabilityInvocationKey.publicKeyBase58
  };
  const authenticationKey = await Ed25519KeyPair.generate();
  authenticationKey.id = _generateKeyId(
    {did, key: authenticationKey});
  authenticationKey.controller = controller;
  mockDoc.authentication[0] = {
    id: authenticationKey.id,
    type: authenticationKey.type,
    controller: authenticationKey.controller,
    publicKeyBase58: authenticationKey.publicKeyBase58
  };
  const documentLoader = await _createDidDocumentLoader({record: mockDoc});
  return {
    authenticationKey, did, documentLoader, mockDoc, capabilityInvocationKey
  };
}
github digitalbazaar / did-cli / lib / drivers / veres / ed25519-key-add.js View on Github external
module.exports = async options => {
  const {
    did, private: privateKeyBase58, public: publicKeyBase58,
    purpose: proofPurpose
  } = options;
  logger._debug(options, 'ed25519-key-add', {did});
  const privateDidDocument = await helpers.getSynchronizedDid(options);
  // create the key
  // TODO: implement passphrase
  const keyPair = await LDKeyPair.from({
    controller: did, privateKeyBase58, publicKeyBase58,
    type: 'Ed25519VerificationKey2018'
  });

  keyPair.id = privateDidDocument.generateKeyId({did, keyPair});
  if(keyPair.id in privateDidDocument.keys) {
    throw new Error('The key already exists.');
  }

  // activate a JSON patch observer which will be resolved in _send.
  privateDidDocument.observe();
  privateDidDocument.addKey({key: keyPair, proofPurpose});

  logger._log(options, 'DID local update successful.');

  await _send(
github digitalbazaar / did-io / lib / methods / veres-one / veres-did-doc.js View on Github external
// Generate a capabilityInvocation key, to base the DID URI on
    const invokeKey = await LDKeyPair.generate(keyOptions);
    const did = this.generateId({keyPair: invokeKey, didType, env});
    this.doc.id = did;

    // Generate an authentication key pair and suite
    const authKey = await LDKeyPair.generate(keyOptions);
    authKey.id = `${did}#authn-key-1`;
    this.doc[constants.SUITES.authentication] = [
      this.generateSuite({key: authKey, suiteId: `${did}#auth-suite-1`})
    ];
    this.keys[authKey.id] = authKey;

    // Generate a capabilityDelegation key pair and suite
    const delegateKey = await LDKeyPair.generate(keyOptions);
    delegateKey.id = `${did}#ocap-delegate-key-1`;
    this.doc[constants.SUITES.capabilityDelegation] = [
      this.generateSuite({key: delegateKey, suiteId: `${did}#delegate-suite-1`})
    ];
    this.keys[delegateKey.id] = delegateKey;

    // Generate a capabilityInvocation suite (from an earlier generated key)
    invokeKey.id = `${did}#ocap-invoke-key-1`;
    this.doc[constants.SUITES.capabilityInvocation] = [
      this.generateSuite({key: invokeKey, suiteId: `${did}#invoke-suite-1`})
    ];
    this.keys[invokeKey.id] = invokeKey;
  }
github digitalbazaar / did-io / tests / veres-one / veres-did-doc.spec.js View on Github external
it('should generate a nym type did', async () => {
      const didDoc = new VeresOneDidDoc({keyType, didType: 'nym', injector});
      const keyOptions = {
        type: keyType, injector: didDoc.injector, passphrase: null
      };

      const keyPair = await LDKeyPair.generate(keyOptions);
      const did = didDoc.generateId({keyPair, env: 'dev'});

      expect(did).to.match(/^did:v1:test:nym:.*/);
    });
  });
github digitalbazaar / jsonld-signatures / tests / mock / Ed25519Signature2018.js View on Github external
'creator': publicKeys.carol.id,
    'jws':
      'eyJhbGciOiJFZERTQSIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19' +
      '..' +
      'ANcNI6x6KDA_hHux2RLM8_i9aoZY34GwcZevOjkSh22WoNB4FcP6dNgf2nKzX' +
      'XJIr-IqUnEwMYeD36fc8jv1AA',
    'proofPurpose': NOOP_PROOF_PURPOSE_URI
  }
};

mock.parameters = {};

mock.parameters.sign = {
  creator: publicKeys.carol.id,
  date: '2018-02-13T21:26:08Z',
  key: new Ed25519KeyPair({
    privateKeyBase58: privateKeys.carol.privateKeyBase58,
    ...publicKeys.carol
  })
};

mock.parameters.verify = {
  creator: publicKeys.carol.id,
  date: '2018-02-13T21:26:08Z'
};

mock.parameters.verifyWithPassedKey = mock.parameters.sign;

mock.parameters.authenticationController = {
  '@context': constants.SECURITY_CONTEXT_URL,
  id: controllers.carol.id,
  authentication: publicKeys.carol.id
github digitalbazaar / jsonld-signatures / tests / mock / RsaSignature2018.js View on Github external
'DJBMvvFAIC00nSGB6Tn0XKbbF9XrsaJZREWvR2aONYTQQxnyXirtXnlewJMB' +
      'Bn2h9hfcGZrvnC1b6PgWmukzFJ1IiH1dWgnDIS81BH-IxXnPkbuYDeySorc4' +
      'QU9MJxdVkY5EL4HYbcIfwKj6X4LBQ2_ZHZIu1jdqLcRZqHcsDF5KKylKc1TH' +
      'n5VRWy5WhYg_gBnyWny8E6Qkrze53MR7OuAmmNJ1m1nN8SxDrG6a08L78J0-' +
      'Fbas5OjAQz3c17GY8mVuDPOBIOVjMEghBlgl3nOi1ysxbRGhHLEK4s0KKbeR' +
      'ogZdgt1DkQxDFxxn41QWDw_mmMCjs9qxg0zcZzqEJw',
    'proofPurpose': NOOP_PROOF_PURPOSE_URI
  }
};

mock.parameters = {};

mock.parameters.sign = {
  creator: publicKeys.alice.id,
  date: '2018-02-22T15:16:04Z',
  key: new RSAKeyPair({
    privateKeyPem: privateKeys.alice.privateKeyPem,
    ...publicKeys.alice
  })
};

mock.parameters.verify = {
  creator: publicKeys.alice.id,
  date: '2018-02-22T15:16:04Z'
};

mock.parameters.verifyWithPassedKey = mock.parameters.sign;

mock.parameters.authenticationController = {
  '@context': constants.SECURITY_CONTEXT_URL,
  id: controllers.alice.id,
  authentication: publicKeys.alice.id
github decentralized-identity / element / packages / element-lib / src / crypto / index.js View on Github external
const createEd25519Keys = async () => {
  const key = await Ed25519KeyPair.generate();
  return key;
};
github digitalbazaar / did-io / lib / methods / veres-one / veres-did-doc.js View on Github external
async importKeys(data = {}, options = {}) {
    for(const keyData of Object.values(data)) {
      const key = await LDKeyPair.from(keyData,
        {injector: this.injector, ...options});
      this.keys[key.id] = key;
    }
  }

crypto-ld

A Javascript library for generating and performing common operations on Linked Data cryptographic key pairs.

BSD-3-Clause
Latest version published 2 years ago

Package Health Score

51 / 100
Full package analysis