UNPKG

@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.77 kB
{"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/ClaimFormat'\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,YAAmB,SAA8C;EAC/D,KAAK,MAAM,QAAQ;EAEnB,KAAK,gBAAgB,8BAA8B,KAAK,IAAI,OAAO;CACrE;CAEA,OAAc,kBAAkB,eAAuB;EACrD,MAAM,MAAM,IAAI,kBAAkB,aAAa;EAE/C,IAAI,CAAC,IAAI,QAAQ,iBAAiB,OAChC,MAAM,IAAI,WAAW,qDAAqD;EAG5E,OAAO,IAAI,6BAA6B,EACtC,IACF,CAAC;CACH;;;;;;;;;CAUA,IAAW,eAAgC;EACzC,OAAO,KAAK;CACd;CAEA,IAAW,gBAAwB;EACjC,OAAO,KAAK,IAAI;CAClB;CAUA,IAAW,UAAU;EACnB,OAAO,KAAK,aAAa;CAC3B;CAEA,IAAW,KAAK;EACd,OAAO,KAAK,aAAa;CAC3B;CAEA,IAAW,OAAO;EAChB,OAAO,KAAK,aAAa;CAC3B;CAEA,IAAW,SAAS;EAClB,OAAO,KAAK,aAAa;CAC3B;CAEA,IAAW,uBAAuB;EAChC,OAAO,KAAK,aAAa;CAC3B;CAEA,IAAW,WAAW;EACpB,OAAO,KAAK,aAAa;CAC3B;;;;CAKA,IAAW,cAAiC;EAC1C,OAAA;CACF;;;;;CAMA,IAAW,UAAU;EACnB,OAAO,KAAK;CACd;AACF"}