@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 • 4.69 kB
Source Map (JSON)
{"version":3,"file":"W3cJwtVerifiableCredential.mjs","names":[],"sources":["../../../../src/modules/vc/jwt-vc/W3cJwtVerifiableCredential.ts"],"sourcesContent":["import { Jwt } from '../../../crypto/jose/jwt/Jwt'\nimport { JsonTransformer } from '../../../utils'\nimport { ClaimFormat } from '../models/ClaimFormat'\nimport type { W3cCredential } from '../models/credential/W3cCredential'\nimport type { W3cJsonCredential } from '../models/credential/W3cJsonCredential'\n\nimport { getCredentialFromJwtPayload } from './credentialTransformer'\n\nexport interface W3cJwtVerifiableCredentialOptions {\n jwt: Jwt\n}\n\nexport class W3cJwtVerifiableCredential {\n public readonly jwt: Jwt\n private _credential: W3cCredential\n\n public constructor(options: W3cJwtVerifiableCredentialOptions) {\n this.jwt = options.jwt\n\n this._credential = getCredentialFromJwtPayload(this.jwt.payload)\n }\n\n public static fromSerializedJwt(serializedJwt: string) {\n const jwt = Jwt.fromSerializedJwt(serializedJwt)\n\n return new W3cJwtVerifiableCredential({\n jwt,\n })\n }\n\n /**\n * Get the W3cCredential 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 `W3cCredential` interface are implemented as getters\n * on the `W3cJwtVerifiableCredential` class itself, so you can also use this directly\n * instead of accessing the inner `credential` property.\n */\n public get credential(): W3cCredential {\n return this._credential\n }\n\n public get serializedJwt(): string {\n return this.jwt.serializedJwt\n }\n\n //\n // Below all properties from the `W3cCredential` interface are implemented as getters\n // this is to make the interface compatible with the W3cJsonLdVerifiableCredential interface\n // which makes using the different classes interchangeably from a user point of view.\n // This is 'easier' than extending the W3cCredential 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.credential.context\n }\n\n public get id() {\n return this.credential.id\n }\n\n public get type() {\n return this.credential.type\n }\n\n public get issuer() {\n return this.credential.issuer\n }\n\n public get issuanceDate() {\n return this.credential.issuanceDate\n }\n\n public get expirationDate() {\n return this.credential.expirationDate\n }\n\n public get credentialSubject() {\n return this.credential.credentialSubject\n }\n\n public get credentialSchema() {\n return this.credential.credentialSchema\n }\n\n public get credentialStatus() {\n return this.credential.credentialStatus\n }\n\n public get issuerId() {\n return this.credential.issuerId\n }\n\n public get credentialSchemaIds() {\n return this.credential.credentialSchemaIds\n }\n\n public get credentialSubjectIds() {\n return this.credential.credentialSubjectIds\n }\n\n public get contexts() {\n return this.credential.contexts\n }\n\n /**\n * The {@link ClaimFormat} of the credential. For JWT credentials this is always `jwt_vc`.\n */\n public get claimFormat(): ClaimFormat.JwtVc {\n return ClaimFormat.JwtVc\n }\n\n /**\n * Get the encoded variant of the W3C Verifiable Credential. For JWT credentials this is\n * a JWT string.\n */\n public get encoded() {\n return this.serializedJwt\n }\n\n public get jsonCredential(): W3cJsonCredential {\n return JsonTransformer.toJSON(this.credential) as W3cJsonCredential\n }\n}\n"],"mappings":";;;;;;AAYA,IAAa,6BAAb,MAAa,2BAA2B;CAItC,YAAmB,SAA4C;EAC7D,KAAK,MAAM,QAAQ;EAEnB,KAAK,cAAc,4BAA4B,KAAK,IAAI,OAAO;CACjE;CAEA,OAAc,kBAAkB,eAAuB;EACrD,MAAM,MAAM,IAAI,kBAAkB,aAAa;EAE/C,OAAO,IAAI,2BAA2B,EACpC,IACF,CAAC;CACH;;;;;;;;;CAUA,IAAW,aAA4B;EACrC,OAAO,KAAK;CACd;CAEA,IAAW,gBAAwB;EACjC,OAAO,KAAK,IAAI;CAClB;CAUA,IAAW,UAAU;EACnB,OAAO,KAAK,WAAW;CACzB;CAEA,IAAW,KAAK;EACd,OAAO,KAAK,WAAW;CACzB;CAEA,IAAW,OAAO;EAChB,OAAO,KAAK,WAAW;CACzB;CAEA,I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