Getting started¶
Requirements¶
- Node.js 20 or newer
Install¶
Your first credential¶
import { generateDidKey, issueCredential, verifyCredentialJwt } from 'simple-vc';
const issuer = generateDidKey();
const holder = generateDidKey();
const jwt = await issueCredential({
issuer,
subject: holder.did,
type: ['UniversityDegreeCredential'],
claims: { degree: { type: 'BachelorDegree', name: 'BSc Computer Science' } },
expiresIn: 60 * 60 * 24 * 365, // optional: 1 year
});
const verified = await verifyCredentialJwt(jwt);
console.log(verified.verified); // true
Running the demo from source¶
git clone https://github.com/marcelogdomingues/simple-vc
cd simple-vc
npm install
npm run demo
npm test
What you get back¶
verifyCredentialJwt returns a VerifiedCredential:
verified—trueif the signature is valid.issuer— the issuer DID that signed it.verifiableCredential— the decoded W3C credential (credentialSubject,type,issuanceDate,expirationDate, …).
If the signature is invalid or the JWT was tampered with, the call throws —
wrap it in try/catch.
Next steps¶
- Understand the moving parts in Concepts.
- See every option in the API reference.
- When you outgrow
did:key, read Going to production.