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 • 2.39 kB
{"version":3,"file":"W3cV2EnvelopedVerifiablePresentationCodec.mjs","names":[],"sources":["../../../../../src/modules/vc/models/presentation/W3cV2EnvelopedVerifiablePresentationCodec.ts"],"sourcesContent":["import { CredoError } from '../../../../error'\nimport { W3cV2JwtVerifiablePresentation } from '../../jwt-vc/W3cV2JwtVerifiablePresentation'\nimport { W3cV2SdJwtVerifiablePresentation } from '../../sd-jwt-vc/W3cV2SdJwtVerifiablePresentation'\n\nexport function presentationFromDataUri(uri: string) {\n if (!uri.startsWith('data:')) {\n throw new CredoError('Invalid Enveloped Verifiable Presentation: \"id\" is not a valid data URI')\n }\n\n const mimetypeData = uri.slice(5)\n const commaIndex = mimetypeData.indexOf(',')\n if (commaIndex === -1) {\n throw new CredoError('Invalid Enveloped Verifiable Presentation: \"id\" data URI is missing comma separator')\n }\n\n const mimetype = mimetypeData.slice(0, commaIndex)\n const data = mimetypeData.slice(commaIndex + 1)\n\n switch (mimetype) {\n case 'application/vp+sd-jwt':\n return W3cV2SdJwtVerifiablePresentation.fromCompact(data)\n\n case 'application/vp+jwt':\n return W3cV2JwtVerifiablePresentation.fromCompact(data)\n\n default:\n throw new CredoError(`Unsupported Enveloped Verifiable Presentation: ${mimetype} not recognized`)\n }\n}\n\nexport function presentationToDataUri(presentation: W3cV2SdJwtVerifiablePresentation | W3cV2JwtVerifiablePresentation) {\n if (presentation instanceof W3cV2SdJwtVerifiablePresentation) {\n return `data:application/vp+sd-jwt,${presentation.encoded}`\n }\n\n if (presentation instanceof W3cV2JwtVerifiablePresentation) {\n return `data:application/vp+jwt,${presentation.encoded}`\n }\n\n throw new CredoError('Unsupported Verifiable Presentation instance')\n}\n"],"mappings":";;;;;AAIA,SAAgB,wBAAwB,KAAa;CACnD,IAAI,CAAC,IAAI,WAAW,OAAO,GACzB,MAAM,IAAI,WAAW,2EAAyE;CAGhG,MAAM,eAAe,IAAI,MAAM,CAAC;CAChC,MAAM,aAAa,aAAa,QAAQ,GAAG;CAC3C,IAAI,eAAe,IACjB,MAAM,IAAI,WAAW,uFAAqF;CAG5G,MAAM,WAAW,aAAa,MAAM,GAAG,UAAU;CACjD,MAAM,OAAO,aAAa,MAAM,aAAa,CAAC;CAE9C,QAAQ,UAAR;EACE,KAAK,yBACH,OAAO,iCAAiC,YAAY,IAAI;EAE1D,KAAK,sBACH,OAAO,+BAA+B,YAAY,IAAI;EAExD,SACE,MAAM,IAAI,WAAW,kDAAkD,SAAS,gBAAgB;CACpG;AACF;AAEA,SAAgB,sBAAsB,cAAiF;CACrH,IAAI,wBAAwB,kCAC1B,OAAO,8BAA8B,aAAa;CAGpD,IAAI,wBAAwB,gCAC1B,OAAO,2BAA2B,aAAa;CAGjD,MAAM,IAAI,WAAW,8CAA8C;AACrE"}