UNPKG

@sphereon/pex

Version:

A Typescript implementation of the v1 and v2 DIF Presentation Exchange specification

178 lines (177 loc) 7.31 kB
import { PresentationDefinitionV1, PresentationDefinitionV2, PresentationSubmission } from '@sphereon/pex-models'; import { CompactSdJwtVc, IPresentation, IProof, IProofPurpose, IProofType, OriginalVerifiableCredential, SdJwtDecodedVerifiableCredential, SdJwtVcKbJwtHeader, SdJwtVcKbJwtPayload, W3CVerifiablePresentation } from '@sphereon/ssi-types'; import { PresentationEvaluationResults } from '../evaluation'; export interface ProofOptions { /** * The signature type. For instance RsaSignature2018 */ type?: IProofType | string; /** * Type supports selective disclosure? */ typeSupportsSelectiveDisclosure?: boolean; /** * A challenge protecting against replay attacks */ challenge?: string; /** * A domain protecting against replay attacks */ domain?: string; /** * The purpose of this proof, for instance assertionMethod or authentication, see https://www.w3.org/TR/vc-data-model/#proofs-signatures-0 */ proofPurpose?: IProofPurpose | string; /** * The ISO8601 date-time string for creation. You can update the Proof value later in the callback. If not supplied the current date/time will be used */ created?: string; /** * Similar to challenge. A nonce to protect against replay attacks, used in some ZKP proofs */ nonce?: string; } export interface SignatureOptions { /** * The private key */ privateKey?: string; /** * Key encoding */ keyEncoding?: KeyEncoding; /** * The verification method value */ verificationMethod?: string; /** * Can be used if you want to provide the Json-ld proof value directly without relying on the callback function generating it */ proofValue?: string; /** * Can be used if you want to provide the JWS proof value directly without relying on the callback function generating it */ jws?: string; } /** * The location of the presentation submission. Can be external or part of the VP */ export declare enum PresentationSubmissionLocation { EXTERNAL = 0,// External to the VP, for instance to use it in OID4VP PRESENTATION = 1 } export type PartialSdJwtKbJwt = { header: Partial<SdJwtVcKbJwtHeader>; payload: Partial<SdJwtVcKbJwtPayload>; }; export type PartialSdJwtDecodedVerifiableCredential = Omit<SdJwtDecodedVerifiableCredential, 'kbJwt'> & { kbJwt: PartialSdJwtKbJwt; }; /** * The result object containing the presentation and presentation submission */ export interface PresentationResult { /** * The resulting presentation, can have an embedded submission data depending on the location parameter */ presentations: Array<IPresentation | SdJwtDecodedVerifiableCredential | PartialSdJwtDecodedVerifiableCredential>; /** * The resulting location of the presentation submission. * Please note that this result object will always also put the submission in the presentationSubmission property, even if it is also embedded in the Verifiable Presentation */ presentationSubmissionLocation: PresentationSubmissionLocation; /** * The presentation submission. * Please note that this property will always be populated, even if it is also embedded in the Verifiable Presentation. If you need to determine the location, use the presentationSubmissionLocation property */ presentationSubmission: PresentationSubmission; } /** * The result object containing the VP and presentation submission */ export interface VerifiablePresentationResult { /** * The resulting VP, can have an embedded submission data depending on the location parameter */ verifiablePresentations: Array<W3CVerifiablePresentation | CompactSdJwtVc>; /** * The resulting location of the presentation submission. * Please note that this result object will always also put the submission in the presentationSubmission property, even if it is also embedded in the Verifiable Presentation */ presentationSubmissionLocation: PresentationSubmissionLocation; /** * The presentation submission. * Please note that this property will always be populated, even if it is also embedded in the Verifiable Presentation. If you need to determine the location, use the presentationSubmissionLocation property */ presentationSubmission: PresentationSubmission; } export interface PresentationFromOpts { /** * The optional holderDID of the presentation */ holderDID?: string; /** * The presentation submission data location. * * Can be External, which means it is only returned and not embedded into the VP, * or Presentation, which means it will become part of the VP */ presentationSubmissionLocation?: PresentationSubmissionLocation; /** * A base presentation payload. Can be used to provide default values. Be aware that any verifiable credential will always be overwritten */ basePresentationPayload?: IPresentation; } export interface VerifiablePresentationFromOpts extends PresentationFromOpts { /** * Proof options */ proofOptions?: ProofOptions; /** * The signature options */ signatureOptions?: SignatureOptions; } export interface PresentationSignCallBackParams { /** * The originally supplied presentation sign options */ options: VerifiablePresentationFromOpts; /** * The selected credentials to include in the eventual VP as determined by PEX and/or user * * NOTE: when the presentation is a decoded SD-JWT, this property will only contain a single SD-JWT credential */ selectedCredentials: OriginalVerifiableCredential[]; /** * The presentation object created from the definition and verifiable credentials. * Can be used directly or in more complex situations can be discarded by using the definition, credentials, proof options, submission and evaluation results * * When the presentation is a decoded SD-JWT VP, the the compact SD-JWT contains the SD-JWT with the (optionally selectively disclosed) disclosures * and only the optional KB-JWT should be appended to the `compactSdJwt` property. If no KB-JWT is needed on the presentation, the `compactSdJwt` property * from the decoded SD-JWT can be returned as-is. */ presentation: IPresentation | SdJwtDecodedVerifiableCredential | PartialSdJwtDecodedVerifiableCredential; /** * A partial proof value the callback can use to complete. If proofValue or JWS was supplied the proof could be complete already */ proof: Partial<IProof>; /** * The presentation definition */ presentationDefinition: PresentationDefinitionV1 | PresentationDefinitionV2; /** * The presentation submission data, which can also be found in the presentation itself depending on the location param */ presentationSubmission: PresentationSubmission; /** * The evaluation results, which the callback function could use to create a VP using the proof(s) using the supplied credentials */ evaluationResults: PresentationEvaluationResults; } export declare enum KeyEncoding { Jwk = "Jwk", Base58 = "Base58", Hex = "Hex", Multibase = "Multibase" }