Skip to main content

Revoke a Credential

If the conditions that make a credential valid cease to exist, an Attester can revoke and optionally remove their attestation from the KILT blockchain. This does not automatically delete the credential from the Claimer's wallet, of course, but it makes it impossible for the Claimer to use the credential in the future.

Since the attestation creation reserved some KILT tokens from the submitter's balance, removing an attestation would return those funds into the payer's pockets.

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

export async function revokeCredential(
attester: Kilt.DidUri,
submitterAccount: Kilt.KiltKeyringPair,
signCallback: Kilt.SignExtrinsicCallback,
credential: Kilt.ICredential,
shouldRemove = false
): Promise<void> {
const api = Kilt.ConfigService.get('api')

const tx = shouldRemove
? // If the attestation is to be removed, create a `remove` tx,
// which revokes and removes the attestation in one go.
api.tx.attestation.remove(credential.rootHash, null)
: // Otherwise, simply revoke the attestation but leave it on chain.
// Hence, the storage is not cleared and the deposit not returned.
api.tx.attestation.revoke(credential.rootHash, null)

const authorizedTx = await Kilt.Did.authorizeTx(
attester,
tx,
signCallback,
submitterAccount.address
)

// Submit the right tx to the KILT blockchain.
await Kilt.Blockchain.signAndSubmitTx(authorizedTx, submitterAccount)
}

Claim Back an Attestation Deposit

Claiming back the deposit of an attestation is semantically equivalent to revoking and removing the attestation, with the difference that the extrinsic to claim the deposit can only be called by the deposit owner and does not require the Attester's signature:

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

export async function reclaimAttestationDeposit(
submitterAddress: Kilt.KiltKeyringPair,
credential: Kilt.ICredential
): Promise<void> {
const api = Kilt.ConfigService.get('api')

// Generate the tx to claim the deposit back.
const depositReclaimTx = api.tx.attestation.reclaimDeposit(
credential.rootHash
)

// Submit the revocation tx to the KILT blockchain.
await Kilt.Blockchain.signAndSubmitTx(depositReclaimTx, submitterAddress)
}