@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
27 lines (26 loc) • 1.7 kB
JavaScript
import { CredoError } from "../../../../error/CredoError.mjs";
import "../../../../error/index.mjs";
import { W3cV2JwtVerifiablePresentation } from "../../jwt-vc/W3cV2JwtVerifiablePresentation.mjs";
import { W3cV2SdJwtVerifiablePresentation } from "../../sd-jwt-vc/W3cV2SdJwtVerifiablePresentation.mjs";
//#region src/modules/vc/models/presentation/W3cV2EnvelopedVerifiablePresentationCodec.ts
function presentationFromDataUri(uri) {
if (!uri.startsWith("data:")) throw new CredoError("Invalid Enveloped Verifiable Presentation: \"id\" is not a valid data URI");
const mimetypeData = uri.slice(5);
const commaIndex = mimetypeData.indexOf(",");
if (commaIndex === -1) throw new CredoError("Invalid Enveloped Verifiable Presentation: \"id\" data URI is missing comma separator");
const mimetype = mimetypeData.slice(0, commaIndex);
const data = mimetypeData.slice(commaIndex + 1);
switch (mimetype) {
case "application/vp+sd-jwt": return W3cV2SdJwtVerifiablePresentation.fromCompact(data);
case "application/vp+jwt": return W3cV2JwtVerifiablePresentation.fromCompact(data);
default: throw new CredoError(`Unsupported Enveloped Verifiable Presentation: ${mimetype} not recognized`);
}
}
function presentationToDataUri(presentation) {
if (presentation instanceof W3cV2SdJwtVerifiablePresentation) return `data:application/vp+sd-jwt,${presentation.encoded}`;
if (presentation instanceof W3cV2JwtVerifiablePresentation) return `data:application/vp+jwt,${presentation.encoded}`;
throw new CredoError("Unsupported Verifiable Presentation instance");
}
//#endregion
export { presentationFromDataUri, presentationToDataUri };
//# sourceMappingURL=W3cV2EnvelopedVerifiablePresentationCodec.mjs.map