@credo-ts/core
Version:
<p align="center"> <br /> <img alt="Credo Logo" src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png" height="250px" /> </p> <h1 align="center"><b>Credo - Core</b></h1
1 lines • 3.72 kB
Source Map (JSON)
{"version":3,"file":"W3cJwtVerifiablePresentation.mjs","names":[],"sources":["../../../../src/modules/vc/jwt-vc/W3cJwtVerifiablePresentation.ts"],"sourcesContent":["import { Jwt } from '../../../crypto/jose/jwt/Jwt'\nimport { CredoError } from '../../../error'\nimport type { W3cPresentation } from '../models'\nimport { ClaimFormat } from '../models'\n\nimport { getPresentationFromJwtPayload } from './presentationTransformer'\n\nexport interface W3cJwtVerifiablePresentationOptions {\n jwt: Jwt\n}\n\nexport class W3cJwtVerifiablePresentation {\n public readonly jwt: Jwt\n private _presentation: W3cPresentation\n\n public constructor(options: W3cJwtVerifiablePresentationOptions) {\n this.jwt = options.jwt\n\n this._presentation = getPresentationFromJwtPayload(this.jwt.payload)\n }\n\n public static fromSerializedJwt(serializedJwt: string) {\n const jwt = Jwt.fromSerializedJwt(serializedJwt)\n\n if (!jwt.payload.additionalClaims.nonce) {\n throw new CredoError(`JWT payload does not contain required claim 'nonce'`)\n }\n\n return new W3cJwtVerifiablePresentation({\n jwt,\n })\n }\n\n /**\n * Get the W3cPresentation from the JWT payload. This does not include the JWT wrapper,\n * and thus is not suitable for sharing. If you need a JWT, use the `serializedJwt` property.\n *\n * All properties and getters from the `W3cPresentation` interface are implemented as getters\n * on the `W3cJwtVerifiablePresentation` class itself, so you can also use this directly\n * instead of accessing the inner `presentation` property.\n */\n public get presentation(): W3cPresentation {\n return this._presentation\n }\n\n public get serializedJwt(): string {\n return this.jwt.serializedJwt\n }\n\n //\n // Below all properties from the `W3cPresentation` interface are implemented as getters\n // this is to make the interface compatible with the W3cJsonLdVerifiablePresentation interface\n // which makes using the different classes interchangeably from a user point of view.\n // This is 'easier' than extending the W3cPresentation class as it means we have to create the\n // instance based on JSON, but also add custom properties.\n //\n\n public get context() {\n return this.presentation.context\n }\n\n public get id() {\n return this.presentation.id\n }\n\n public get type() {\n return this.presentation.type\n }\n\n public get holder() {\n return this.presentation.holder\n }\n\n public get verifiableCredential() {\n return this.presentation.verifiableCredential\n }\n\n public get holderId() {\n return this.presentation.holderId\n }\n\n /**\n * The {@link ClaimFormat} of the presentation. For JWT presentations this is always `jwt_vp`.\n */\n public get claimFormat(): ClaimFormat.JwtVp {\n return ClaimFormat.JwtVp\n }\n\n /**\n * Get the encoded variant of the W3C Verifiable Presentation. For JWT presentations this is\n * a JWT string.\n */\n public get encoded() {\n return this.serializedJwt\n }\n}\n"],"mappings":";;;;;;;;;;AAWA,IAAa,+BAAb,MAAa,6BAA6B;CAIxC,AAAO,YAAY,SAA8C;AAC/D,OAAK,MAAM,QAAQ;AAEnB,OAAK,gBAAgB,8BAA8B,KAAK,IAAI,QAAQ;;CAGtE,OAAc,kBAAkB,eAAuB;EACrD,MAAM,MAAM,IAAI,kBAAkB,cAAc;AAEhD,MAAI,CAAC,IAAI,QAAQ,iBAAiB,MAChC,OAAM,IAAI,WAAW,sDAAsD;AAG7E,SAAO,IAAI,6BAA6B,EACtC,KACD,CAAC;;;;;;;;;;CAWJ,IAAW,eAAgC;AACzC,SAAO,KAAK;;CAGd,IAAW,gBAAwB;AACjC,SAAO,KAAK,IAAI;;CAWlB,IAAW,UAAU;AACnB,SAAO,KAAK,aAAa;;CAG3B,IAAW,KAAK;AACd,SAAO,KAAK,aAAa;;CAG3B,IAAW,OAAO;AAChB,SAAO,KAAK,aAAa;;CAG3B,IAAW,SAAS;AAClB,SAAO,KAAK,aAAa;;CAG3B,IAAW,uBAAuB;AAChC,SAAO,KAAK,aAAa;;CAG3B,IAAW,WAAW;AACpB,SAAO,KAAK,aAAa;;;;;CAM3B,IAAW,cAAiC;AAC1C,SAAO,YAAY;;;;;;CAOrB,IAAW,UAAU;AACnB,SAAO,KAAK"}