Skip to main content

Javascript

At a Glance#

  • Three slightly different versions of the DIDKit binary can be installed via npm, all under the organization "@spruceid":
  • For a quick function & type reference, you can check out the Issuing a Credential and Options sections of the /lib/node/README.md file in the DIDKit repo. Better yet, install it and run the commands yourself!
  • To test your installation or just to see examples of calls and returns with valid DID-key test vectors, see the provided test script

Installation#

Installation over node package managers is quite simple. Run this command to confirm version number and proper operation of basic functions:

// Import the module
const DIDKit = require('@spruceid/didkit');
console.log(DIDKit.getVersion());
// To issue credentials and presentations, you need a key.
// The library provides a function to generate one.
const key = DIDKit.generateEd25519Key();
// There are two helpful functions to obtain a DID and the `did:key`
// `verificationMethod` from the key.
const did = DIDKit.keyToDID('key', key);
const verificationMethod = DIDKit.keyToVerificationMethod('key', key);

Examples#

ComponentsExample
Wasm, Blockchain IndexerJS Code
Web Application, dAppJS Code

Code#