Skip to main content

Request an Attestation

This section covers creating a Claim and a Credential.

KILT is a premissionless system. Anyone or anything can claim something and attest to it. But an attested credential only has value if the Verifier of the credential trusts the Attester of the credential.

Create Credentialโ€‹

Use the previously created light DID, ctype, and Claimer provided content to generate the Claim object.

A claim consists of attributes that we claim to be true about us.

claimer/createClaim.ts
import * as Kilt from '@kiltprotocol/sdk-js'

// Create a Claim object from light DID, CType and given content.
export function createClaim(
lightDid: Kilt.DidUri,
ctype: Kilt.ICType,
content: Kilt.IClaim['contents']
): Kilt.IClaim {
const claim = Kilt.Claim.fromCTypeAndClaimContents(ctype, content, lightDid)

return claim
}

The fromCTypeAndClaimContents function takes the lightDid, ctype, and content values and generates a Claim object.

Receive attestation for claimโ€‹

Since you want to receive an attestation for those claims, build a Credential in the generateCredential function below.

The credential contains all necessary information so the Attester can attest it.

claimer/generateCredential.ts
import { config as envConfig } from 'dotenv'

import * as Kilt from '@kiltprotocol/sdk-js'

import { createClaim } from './createClaim'
import { generateLightDid } from './generateLightDid'
import { getCtypeSchema } from '../attester/ctypeSchema'

export function generateCredential(
claimerDid: Kilt.DidUri,
claimAttributes: Kilt.IClaim['contents']
): Kilt.ICredential {
// Create claim.
const ctype = getCtypeSchema()
const claim = createClaim(claimerDid, ctype, claimAttributes)

// Create credential and request attestation.
console.log('Claimer -> create request')
return Kilt.Credential.fromClaim(claim)
}

// Don't execute if this is imported by another file.
if (require.main === module) {
;(async () => {
envConfig()

try {
await Kilt.init()

const claimerDidMnemonic = process.env.CLAIMER_DID_MNEMONIC as string
const claimerDid = generateLightDid(claimerDidMnemonic)

const request = generateCredential(claimerDid.uri, {
age: 28,
name: 'Max Mustermann'
})
console.log(
'โš ๏ธ save this to ./claimer/_credential.json for testing โš ๏ธ\n\n'
)
console.log(JSON.stringify(request, null, 2))
} catch (e) {
console.log('Error while building credential')
throw e
}
})()
}

The main function takes the Claimer mnemonic and generates the light DID following the steps outlined in the DID section. It then calls the generateCredential function using the supplied claim attributes. It then uses the createClaim method from the previous step to create the Claim object and the Kilt.Credential.fromClaim method takes the claim and returns the Credential object.

When Attesters issue Attestations, they are written to the chain, which requires a deposit. Each new Credential is unique. During testing, you can store and reuse credentials into ./claimer/_credential.json to avoid multiple attestations.

You can share this credential with others following the workshop to see how they get denied from fraudulent senders.

Runโ€‹

yarn ts-node claimer/generateCredential.ts

OK, you've made a claim as a Claimer and created a credential from it. The next step is to finish the Attester and get the credential attested!