A Verifiable Presentation is a presentation of a VC. It allows the holder to present and share their entire or partial information from the VC in a secure manner.
VerifiablePresentation
contains the following 7 fields:
@context
: indicates the context of the VP, the default value is: 'https://www.w3.org/2018/credentials/v1'version
: indicates the version of the Credential, the current version is 1;type
: indicates the presentation type of the VP -- vpTypes
, including three VP presentations -- VP, VP_Digest, VP_SelectiveDisclosure. To find more details, please check the section -- 'VP Type Selection';verifiableCredential
: indicates the VC presented by the VP;id
: the id of the VP, which is the identifier of the VP;proof
: the signature of the VP presented by the holder. To find more details, please check the following section -- 'Holder Signature'hasher
:the hashType of Digest calculation in VC, the default hash method is Keccak256
To generate a VerifiablePresentation
, you need to go through 2 steps:
VerifiablePresentationBuilder
via a DID;VerifiablePresentation
by addVC()
and build()
methods;export class VerifiablePresentationBuilder {
#did: Did;
....}
export interface VerifiablePresentation {
'@context': string[];
version: VerifiablePresentationVersion;
type: VerifiablePresentationType[];
verifiableCredential: VerifiableCredential[];
id: HexString;
proof: Proof; // holder's signature
hasher: [HashType];
}
Note: the id
field of VP is calculated via hashing the VC's Digest, the default hash method is Keccak256
.
// generate the proof
const {
id,
signature,
type: signType
} = await this.#did.signWithKey(u8aConcat(hash, stringToU8a(challenge)), 'authentication');
A VP contains the following methods to construct a VP from a VC:
addVC
build