-
Notifications
You must be signed in to change notification settings - Fork 3
Verifiable Credentials Step By Step
Suhail Manzoor edited this page Dec 10, 2020
·
5 revisions
How to generate Verifiable Credentials
Firstly generate a ed25519 key-pair which can be found at Transmute DID Key:
import * as ed25519 from '@transmute/did-key-ed25519';
import crypto from 'crypto';
const seed = crypto.randomBytes(32).toString('hex');
let key = await Ed25519KeyPair.generate({
secureRandom: () => {
return Buffer.from(seed, 'hex');
},
});Then you generate a DID document using the key-pair generated above. In order to generate the document, you first have to install npm i @transmute/did-key-common@latest --save and then pass the key generated above to the keyToDidDoc function.
import crypto from 'crypto';
import * as ed25519 from '@transmute/did-key-ed25519';
import { keyToDidDoc } from '@transmute/did-key-common';
const seed = crypto.randomBytes(32).toString('hex');
let ed25519Key = await Ed25519KeyPair.generate({
secureRandom: () => {
return Buffer.from(seed, 'hex');
},
});
const diddoc = await keyToDidDoc(ed25519Key);If you consoled the diddoc object, you will see something similar to the following:
{
'@context': [
'https://www.w3.org/ns/did/v1',
{
'@base': 'did:key:z6MkqMqrHZnfctNuXJ39fX8vDnUxVrPYL8LiqypWyb2a8S5y'
}
],
id: 'did:key:z6MkqMqrHZnfctNuXJ39fX8vDnUxVrPYL8LiqypWyb2a8S5y',
verificationMethod: [
{
id: '#z6MkqMqrHZnfctNuXJ39fX8vDnUxVrPYL8LiqypWyb2a8S5y',
type: 'Ed25519VerificationKey2018',
controller: 'did:key:z6MkqMqrHZnfctNuXJ39fX8vDnUxVrPYL8LiqypWyb2a8S5y',
publicKeyBase58: 'BuaohKYEHLtSQoCSyxB5NgvxgH7gvF6N9xub9K4ZDDJb'
},
{
id: '#z6LSku5fknwx7iJCvPG4n5KgCv9Gu5xVLP84AEM49nMX2pJy',
type: 'X25519KeyAgreementKey2019',
controller: 'did:key:z6MkqMqrHZnfctNuXJ39fX8vDnUxVrPYL8LiqypWyb2a8S5y',
publicKeyBase58: 'ADuWEV962FaTpztJFRoitKvo3wRNdmwuHFdNfKhzKSYD'
}
],
authentication: [ '#z6MkqMqrHZnfctNuXJ39fX8vDnUxVrPYL8LiqypWyb2a8S5y' ],
assertionMethod: [ '#z6MkqMqrHZnfctNuXJ39fX8vDnUxVrPYL8LiqypWyb2a8S5y' ],
capabilityInvocation: [ '#z6MkqMqrHZnfctNuXJ39fX8vDnUxVrPYL8LiqypWyb2a8S5y' ],
capabilityDelegation: [ '#z6MkqMqrHZnfctNuXJ39fX8vDnUxVrPYL8LiqypWyb2a8S5y' ],
keyAgreement: [ '#z6LSku5fknwx7iJCvPG4n5KgCv9Gu5xVLP84AEM49nMX2pJy' ]
}