Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

did-jwt-vc

Package Overview
Dependencies
Maintainers
6
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

did-jwt-vc - npm Package Compare versions

Comparing version 2.1.7 to 2.1.8

2

lib/index.js

@@ -1,2 +0,2 @@

var e=require("did-jwt");const t=/^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/,r="https://www.w3.org/2018/credentials/v1";function n(e){return Array.isArray(e)?e:[e]}function i(e){return Array.isArray(e)?e.map(e=>i(e)):e instanceof Date?new Date(e.getTime()):e&&"object"==typeof e?Object.getOwnPropertyNames(e).reduce((t,r)=>(Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r)),t[r]=i(e[r]),t),Object.create(Object.getPrototypeOf(e))):e}function o(e){return null!=e}function a(e,t=!0){var a,l,c,s,d,f,u;let p=i(e);var v,y,b;"object"==typeof(v=e)&&v.sub&&v.iss&&v.claim&&v.iat&&(p=function(e){const{iat:t,nbf:n,claim:i,vc:o,...a}=e,l={...a,nbf:n||t,vc:{"@context":[r],type:["VerifiableCredential"],credentialSubject:i}};return o&&(e.issVc=o),l}(e)),p.credentialSubject={...e.credentialSubject,...null==(a=e.vc)?void 0:a.credentialSubject},!e.sub||null!=(l=e.credentialSubject)&&l.id||!p.credentialSubject||(p.credentialSubject.id=e.sub,t&&delete p.sub),t&&(null==(y=p.vc)||delete y.credentialSubject),void 0!==e.issuer&&"object"!=typeof e.issuer||(p.issuer=function(e){if("object"!=typeof e)return e;const t={...e};return Object.keys(t).forEach(e=>void 0===t[e]&&delete t[e]),t}({id:e.iss,...e.issuer}),!t||null!=(b=e.issuer)&&b.id||delete p.iss),!e.id&&e.jti&&(p.id=p.id||p.jti,t&&delete p.jti);const x=[...n(p.type),...n(null==(c=p.vc)?void 0:c.type)].filter(o);var w,j,O,m;p.type=[...new Set(x)],t&&(null==(w=p.vc)||delete w.type),p.evidence=null==(s=e.vc)?void 0:s.evidence,t&&(null==(j=p.vc)||delete j.evidence),p.credentialStatus=null==(d=e.vc)?void 0:d.credentialStatus,t&&(null==(O=p.vc)||delete O.credentialStatus),p.termsOfUse=null==(f=e.vc)?void 0:f.termsOfUse,t&&(null==(m=p.vc)||delete m.termsOfUse);const g=[...n(e.context),...n(e["@context"]),...n(null==(u=e.vc)?void 0:u["@context"])].filter(o);var h;return p["@context"]=[...new Set(g)],t&&(delete p.context,null==(h=p.vc)||delete h["@context"]),e.issuanceDate||!e.iat&&!e.nbf||(p.issuanceDate=new Date(1e3*(e.nbf||e.iat)).toISOString(),t&&(e.nbf?delete p.nbf:delete p.iat)),!e.expirationDate&&e.exp&&(p.expirationDate=new Date(1e3*e.exp).toISOString(),t&&delete p.exp),t&&p.vc&&0===Object.keys(p.vc).length&&delete p.vc,p}function l(t,r=!0){let n;try{n=e.decodeJWT(t)}catch(e){throw new TypeError("unknown credential format")}return{...a(n.payload,r),proof:{type:"JwtProof2020",jwt:t}}}function c(e,r=!0){var n;if("string"==typeof e){if(t.test(e))return l(e,r);{let t;try{t=JSON.parse(e)}catch(e){throw new TypeError("unknown credential format")}return c(t,r)}}return null!=(n=e.proof)&&n.jwt?i({...l(e.proof.jwt,r),proof:e.proof}):{proof:{},...a(e,r)}}function s(e,t=!0){var r,a,l;if(Array.isArray(e.credentialSubject))throw Error("credentialSubject of type array not supported");const c=i({vc:{...e.vc},...e});c.vc=c.vc;const s={...e.credentialSubject,...null==(r=e.vc)?void 0:r.credentialSubject};var d;e.sub||(c.sub=null==(d=e.credentialSubject)?void 0:d.id,t&&delete s.id);const f=[...n(e.context),...n(e["@context"]),...n(null==(a=e.vc)?void 0:a["@context"])].filter(o);c.vc["@context"]=[...new Set(f)],t&&(delete c.context,delete c["@context"]);const u=[...n(e.type),...n(null==(l=e.vc)?void 0:l.type)].filter(o);if(c.vc.type=[...new Set(u)],t&&delete c.type,e.id&&-1===Object.getOwnPropertyNames(e).indexOf("jti")&&(c.jti=e.id,t&&delete c.id),e.issuanceDate&&-1===Object.getOwnPropertyNames(e).indexOf("nbf")){const r=Date.parse(e.issuanceDate);isNaN(r)||(c.nbf=Math.floor(r/1e3),t&&delete c.issuanceDate)}if(e.expirationDate&&-1===Object.getOwnPropertyNames(e).indexOf("exp")){const r=Date.parse(e.expirationDate);isNaN(r)||(c.exp=Math.floor(r/1e3),t&&delete c.expirationDate)}var p;e.issuer&&-1===Object.getOwnPropertyNames(e).indexOf("iss")&&("object"==typeof e.issuer?(c.iss=null==(p=e.issuer)?void 0:p.id,t&&(delete c.issuer.id,0===Object.keys(c.issuer).length&&delete c.issuer)):"string"==typeof e.issuer&&(c.iss=e.iss||""+e.issuer,t&&delete c.issuer)),c.vc.credentialSubject=s,t&&delete c.credentialSubject;const v=["evidence","termsOfUse","refreshService","credentialSchema","credentialStatus"];for(const r of v)e[r]&&(c.vc[r]||(c.vc[r]=e[r]),t&&delete c[r]);return c}function d(e,t=!0){var r,a,l;const s=i(e);var d;s.verifiableCredential=[...n(e.verifiableCredential),...n(null==(r=e.vp)?void 0:r.verifiableCredential)].filter(o),s.verifiableCredential=s.verifiableCredential.map(e=>c(e,t)),t&&(null==(d=s.vp)||delete d.verifiableCredential),e.iss&&!e.holder&&(s.holder=e.iss,t&&delete s.iss),e.aud&&(s.verifier=[...n(e.verifier),...n(e.aud)].filter(o),s.verifier=[...new Set(s.verifier)],t&&delete s.aud),e.jti&&-1===Object.getOwnPropertyNames(e).indexOf("id")&&(s.id=e.id||e.jti,t&&delete s.jti);const f=[...n(e.type),...n(null==(a=e.vp)?void 0:a.type)].filter(o);var u;s.type=[...new Set(f)],t&&(null==(u=s.vp)||delete u.type);const p=[...n(e.context),...n(e["@context"]),...n(null==(l=e.vp)?void 0:l["@context"])].filter(o);var v;return s["@context"]=[...new Set(p)],t&&(delete s.context,null==(v=s.vp)||delete v["@context"]),e.issuanceDate||!e.iat&&!e.nbf||(s.issuanceDate=new Date(1e3*(e.nbf||e.iat)).toISOString(),t&&(e.nbf?delete s.nbf:delete s.iat)),!e.expirationDate&&e.exp&&(s.expirationDate=new Date(1e3*e.exp).toISOString(),t&&delete s.exp),s.vp&&0===Object.keys(s.vp).length&&t&&delete s.vp,s}function f(t,r=!0){let n;try{n=e.decodeJWT(t)}catch(e){throw new TypeError("unknown presentation format")}return{...d(n.payload,r),proof:{type:"JwtProof2020",jwt:t}}}function u(e,r=!0){var n;if("string"==typeof e){if(t.test(e))return f(e,r);{let t;try{t=JSON.parse(e)}catch(e){throw new TypeError("unknown presentation format")}return u(t,r)}}return null!=(n=e.proof)&&n.jwt?{...f(e.proof.jwt,r),proof:e.proof}:{proof:{},...d(e,r)}}function p(e,t=!0){var r,a,l;const c=i({vp:{...e.vp},...e});c.vp=c.vp;const s=[...n(e.context),...n(e["@context"]),...n(null==(r=e.vp)?void 0:r["@context"])].filter(o);c.vp["@context"]=[...new Set(s)],t&&(delete c.context,delete c["@context"]);const d=[...n(e.type),...n(null==(a=e.vp)?void 0:a.type)].filter(o);if(c.vp.type=[...new Set(d)],t&&delete c.type,e.id&&-1===Object.getOwnPropertyNames(e).indexOf("jti")&&(c.jti=e.id,t&&delete c.id),e.issuanceDate&&-1===Object.getOwnPropertyNames(e).indexOf("nbf")){const r=Date.parse(e.issuanceDate);isNaN(r)||(c.nbf=Math.floor(r/1e3),t&&delete c.issuanceDate)}if(e.expirationDate&&-1===Object.getOwnPropertyNames(e).indexOf("exp")){const r=Date.parse(e.expirationDate);isNaN(r)||(c.exp=Math.floor(r/1e3),t&&delete c.expirationDate)}var f;if((c.verifiableCredential||null!=(l=c.vp)&&l.verifiableCredential)&&(c.vp.verifiableCredential=[...n(c.verifiableCredential),...n(null==(f=c.vp)?void 0:f.verifiableCredential)].filter(o).map(e=>{var t;return"object"==typeof e&&null!=(t=e.proof)&&t.jwt?e.proof.jwt:e})),t&&delete c.verifiableCredential,e.holder&&-1===Object.getOwnPropertyNames(e).indexOf("iss")&&"string"==typeof e.holder&&(c.iss=e.holder,t&&delete c.holder),e.verifier){const r=[...n(e.verifier),...n(e.aud)].filter(o);c.aud=[...new Set(r)],t&&delete c.verifier}return c}function v(e){if("string"==typeof e&&!e.match(t))throw new TypeError(`"${e}" is not a valid JWT format`)}function y(e){if("number"==typeof e){if(!(Number.isInteger(e)&&e<1e11))throw new TypeError(`"${e}" is not a unix timestamp in seconds`)}else if("string"==typeof e)y(Math.floor(new Date(e).valueOf()/1e3));else if(!(t=e)||isNaN(t)||"[object Date]"!==Object.prototype.toString.call(t))throw new TypeError(`"${e}" is not a valid time`);var t}function b(e){const t=n(e);if(t.length<1||-1===t.indexOf(r))throw new TypeError(`@context is missing default context "${r}"`)}function x(e){const t=n(e);if(t.length<1||-1===t.indexOf("VerifiableCredential"))throw new TypeError('type is missing default "VerifiableCredential"')}function w(e){const t=n(e);if(t.length<1||-1===t.indexOf("VerifiablePresentation"))throw new TypeError('type is missing default "VerifiablePresentation"')}function j(e){if(0===Object.keys(e).length)throw new TypeError("credentialSubject must not be empty")}function O(e){b(e.vc["@context"]),x(e.vc.type),j(e.vc.credentialSubject),e.nbf&&y(e.nbf),e.exp&&y(e.exp)}function m(e){b(e["@context"]),x(e.type),j(e.credentialSubject),e.issuanceDate&&y(e.issuanceDate),e.expirationDate&&y(e.expirationDate)}function g(e){if(b(e.vp["@context"]),w(e.vp.type),e.vp.verifiableCredential&&e.vp.verifiableCredential.length>=1)for(const t of n(e.vp.verifiableCredential))"string"==typeof t?v(t):m(t);e.exp&&y(e.exp)}function h(e){if(b(e["@context"]),w(e.type),e.verifiableCredential&&e.verifiableCredential.length>=1)for(const t of e.verifiableCredential)"string"==typeof t?v(t):m(t);e.expirationDate&&y(e.expirationDate)}function S(e,t){if(t.challenge&&t.challenge!==e.nonce)throw new Error(`Presentation does not contain the mandatory challenge (JWT: nonce) for : ${t.challenge}`);if(t.domain){let r;if(e.aud&&(r=(Array.isArray(e.aud)?e.aud:[e.aud]).find(e=>t.domain===e)),void 0===r)throw new Error(`Presentation does not contain the mandatory domain (JWT: aud) for : ${t.domain}`)}}exports.createVerifiableCredentialJwt=function(t,r,n={}){try{var i;const o={iat:void 0,...s(t,n.removeOriginalFields)};return O(o),Promise.resolve(e.createJWT(o,{...n,issuer:r.did||o.iss||"",signer:r.signer},{...n.header,alg:r.alg||(null==(i=n.header)?void 0:i.alg)||"ES256K"}))}catch(e){return Promise.reject(e)}},exports.createVerifiablePresentationJwt=function(t,r,i={}){try{var a;const l={iat:void 0,...p(t,null==i?void 0:i.removeOriginalFields)};if(i.challenge&&-1===Object.getOwnPropertyNames(l).indexOf("nonce")&&(l.nonce=i.challenge),i.domain){const e=[...n(i.domain),...n(l.aud)].filter(o);l.aud=[...new Set(e)]}return g(l),Promise.resolve(e.createJWT(l,{...i,issuer:r.did||l.iss||"",signer:r.signer},{...i.header,alg:r.alg||(null==(a=i.header)?void 0:a.alg)||"ES256K"}))}catch(e){return Promise.reject(e)}},exports.normalizeCredential=c,exports.normalizePresentation=u,exports.transformCredentialInput=s,exports.transformPresentationInput=p,exports.validateCredentialPayload=m,exports.validateJwtCredentialPayload=O,exports.validateJwtPresentationPayload=g,exports.validatePresentationPayload=h,exports.verifyCredential=function(t,r,n={}){try{return Promise.resolve(e.verifyJWT(t,{resolver:r,...n})).then(function(e){return e.verifiableCredential=c(e.jwt,null==n?void 0:n.removeOriginalFields),m(e.verifiableCredential),e})}catch(e){return Promise.reject(e)}},exports.verifyPresentation=function(t,r,n={}){try{return Promise.resolve(e.verifyJWT(t,{resolver:r,...n})).then(function(e){return S(e.payload,n),e.verifiablePresentation=u(e.jwt,null==n?void 0:n.removeOriginalFields),h(e.verifiablePresentation),e})}catch(e){return Promise.reject(e)}},exports.verifyPresentationPayloadOptions=S;
var e=require("did-jwt");const t=/^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/,r="https://www.w3.org/2018/credentials/v1",n=["evidence","termsOfUse","refreshService","credentialSchema","credentialStatus"];function i(e){return Array.isArray(e)?e:[e]}function o(e){return Array.isArray(e)?e.map(e=>o(e)):e instanceof Date?new Date(e.getTime()):e&&"object"==typeof e?Object.getOwnPropertyNames(e).reduce((t,r)=>(Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r)),t[r]=o(e[r]),t),Object.create(Object.getPrototypeOf(e))):e}function a(e){return null!=e}function l(e,t=!0){var l,c,s,d;let f=o(e);var u,p,v;"object"==typeof(u=e)&&u.sub&&u.iss&&u.claim&&u.iat&&(f=function(e){const{iat:t,nbf:n,claim:i,vc:o,...a}=e,l={...a,nbf:n||t,vc:{"@context":[r],type:["VerifiableCredential"],credentialSubject:i}};return o&&(e.issVc=o),l}(e)),f.credentialSubject={...e.credentialSubject,...null==(l=e.vc)?void 0:l.credentialSubject},!e.sub||null!=(c=e.credentialSubject)&&c.id||!f.credentialSubject||(f.credentialSubject.id=e.sub,t&&delete f.sub),t&&(null==(p=f.vc)||delete p.credentialSubject),void 0!==e.issuer&&"object"!=typeof e.issuer||(f.issuer=function(e){if("object"!=typeof e)return e;const t={...e};return Object.keys(t).forEach(e=>void 0===t[e]&&delete t[e]),t}({id:e.iss,...e.issuer}),!t||null!=(v=e.issuer)&&v.id||delete f.iss),!e.id&&e.jti&&(f.id=f.id||f.jti,t&&delete f.jti);const y=[...i(f.type),...i(null==(s=f.vc)?void 0:s.type)].filter(a);var b;f.type=[...new Set(y)],t&&(null==(b=f.vc)||delete b.type);for(const r of n)e.vc&&e.vc[r]&&(f[r]||(f[r]=e.vc[r]),t&&delete f.vc[r]);const x=[...i(e.context),...i(e["@context"]),...i(null==(d=e.vc)?void 0:d["@context"])].filter(a);var w;return f["@context"]=[...new Set(x)],t&&(delete f.context,null==(w=f.vc)||delete w["@context"]),e.issuanceDate||!e.iat&&!e.nbf||(f.issuanceDate=new Date(1e3*(e.nbf||e.iat)).toISOString(),t&&(e.nbf?delete f.nbf:delete f.iat)),!e.expirationDate&&e.exp&&(f.expirationDate=new Date(1e3*e.exp).toISOString(),t&&delete f.exp),t&&f.vc&&0===Object.keys(f.vc).length&&delete f.vc,f}function c(t,r=!0){let n;try{n=e.decodeJWT(t)}catch(e){throw new TypeError("unknown credential format")}return{...l(n.payload,r),proof:{type:"JwtProof2020",jwt:t}}}function s(e,r=!0){var n;if("string"==typeof e){if(t.test(e))return c(e,r);{let t;try{t=JSON.parse(e)}catch(e){throw new TypeError("unknown credential format")}return s(t,r)}}return null!=(n=e.proof)&&n.jwt?o({...c(e.proof.jwt,r),proof:e.proof}):{proof:{},...l(e,r)}}function d(e,t=!0){var r,l,c;if(Array.isArray(e.credentialSubject))throw Error("credentialSubject of type array not supported");const s=o({vc:{...e.vc},...e});s.vc=s.vc;const d={...e.credentialSubject,...null==(r=e.vc)?void 0:r.credentialSubject};var f;e.sub||(s.sub=null==(f=e.credentialSubject)?void 0:f.id,t&&delete d.id);const u=[...i(e.context),...i(e["@context"]),...i(null==(l=e.vc)?void 0:l["@context"])].filter(a);s.vc["@context"]=[...new Set(u)],t&&(delete s.context,delete s["@context"]);const p=[...i(e.type),...i(null==(c=e.vc)?void 0:c.type)].filter(a);if(s.vc.type=[...new Set(p)],t&&delete s.type,e.id&&-1===Object.getOwnPropertyNames(e).indexOf("jti")&&(s.jti=e.id,t&&delete s.id),e.issuanceDate&&-1===Object.getOwnPropertyNames(e).indexOf("nbf")){const r=Date.parse(e.issuanceDate);isNaN(r)||(s.nbf=Math.floor(r/1e3),t&&delete s.issuanceDate)}if(e.expirationDate&&-1===Object.getOwnPropertyNames(e).indexOf("exp")){const r=Date.parse(e.expirationDate);isNaN(r)||(s.exp=Math.floor(r/1e3),t&&delete s.expirationDate)}var v;e.issuer&&-1===Object.getOwnPropertyNames(e).indexOf("iss")&&("object"==typeof e.issuer?(s.iss=null==(v=e.issuer)?void 0:v.id,t&&(delete s.issuer.id,0===Object.keys(s.issuer).length&&delete s.issuer)):"string"==typeof e.issuer&&(s.iss=e.iss||""+e.issuer,t&&delete s.issuer)),s.vc.credentialSubject=d,t&&delete s.credentialSubject;for(const r of n)e[r]&&(s.vc[r]||(s.vc[r]=e[r]),t&&delete s[r]);return s}function f(e,t=!0){var r,n,l;const c=o(e);var d;c.verifiableCredential=[...i(e.verifiableCredential),...i(null==(r=e.vp)?void 0:r.verifiableCredential)].filter(a),c.verifiableCredential=c.verifiableCredential.map(e=>s(e,t)),t&&(null==(d=c.vp)||delete d.verifiableCredential),e.iss&&!e.holder&&(c.holder=e.iss,t&&delete c.iss),e.aud&&(c.verifier=[...i(e.verifier),...i(e.aud)].filter(a),c.verifier=[...new Set(c.verifier)],t&&delete c.aud),e.jti&&-1===Object.getOwnPropertyNames(e).indexOf("id")&&(c.id=e.id||e.jti,t&&delete c.jti);const f=[...i(e.type),...i(null==(n=e.vp)?void 0:n.type)].filter(a);var u;c.type=[...new Set(f)],t&&(null==(u=c.vp)||delete u.type);const p=[...i(e.context),...i(e["@context"]),...i(null==(l=e.vp)?void 0:l["@context"])].filter(a);var v;return c["@context"]=[...new Set(p)],t&&(delete c.context,null==(v=c.vp)||delete v["@context"]),e.issuanceDate||!e.iat&&!e.nbf||(c.issuanceDate=new Date(1e3*(e.nbf||e.iat)).toISOString(),t&&(e.nbf?delete c.nbf:delete c.iat)),!e.expirationDate&&e.exp&&(c.expirationDate=new Date(1e3*e.exp).toISOString(),t&&delete c.exp),c.vp&&0===Object.keys(c.vp).length&&t&&delete c.vp,c}function u(t,r=!0){let n;try{n=e.decodeJWT(t)}catch(e){throw new TypeError("unknown presentation format")}return{...f(n.payload,r),proof:{type:"JwtProof2020",jwt:t}}}function p(e,r=!0){var n;if("string"==typeof e){if(t.test(e))return u(e,r);{let t;try{t=JSON.parse(e)}catch(e){throw new TypeError("unknown presentation format")}return p(t,r)}}return null!=(n=e.proof)&&n.jwt?{...u(e.proof.jwt,r),proof:e.proof}:{proof:{},...f(e,r)}}function v(e,t=!0){var r,n,l;const c=o({vp:{...e.vp},...e});c.vp=c.vp;const s=[...i(e.context),...i(e["@context"]),...i(null==(r=e.vp)?void 0:r["@context"])].filter(a);c.vp["@context"]=[...new Set(s)],t&&(delete c.context,delete c["@context"]);const d=[...i(e.type),...i(null==(n=e.vp)?void 0:n.type)].filter(a);if(c.vp.type=[...new Set(d)],t&&delete c.type,e.id&&-1===Object.getOwnPropertyNames(e).indexOf("jti")&&(c.jti=e.id,t&&delete c.id),e.issuanceDate&&-1===Object.getOwnPropertyNames(e).indexOf("nbf")){const r=Date.parse(e.issuanceDate);isNaN(r)||(c.nbf=Math.floor(r/1e3),t&&delete c.issuanceDate)}if(e.expirationDate&&-1===Object.getOwnPropertyNames(e).indexOf("exp")){const r=Date.parse(e.expirationDate);isNaN(r)||(c.exp=Math.floor(r/1e3),t&&delete c.expirationDate)}var f;if((c.verifiableCredential||null!=(l=c.vp)&&l.verifiableCredential)&&(c.vp.verifiableCredential=[...i(c.verifiableCredential),...i(null==(f=c.vp)?void 0:f.verifiableCredential)].filter(a).map(e=>{var t;return"object"==typeof e&&null!=(t=e.proof)&&t.jwt?e.proof.jwt:e})),t&&delete c.verifiableCredential,e.holder&&-1===Object.getOwnPropertyNames(e).indexOf("iss")&&"string"==typeof e.holder&&(c.iss=e.holder,t&&delete c.holder),e.verifier){const r=[...i(e.verifier),...i(e.aud)].filter(a);c.aud=[...new Set(r)],t&&delete c.verifier}return c}function y(e){if("string"==typeof e&&!e.match(t))throw new TypeError(`"${e}" is not a valid JWT format`)}function b(e){if("number"==typeof e){if(!(Number.isInteger(e)&&e<1e11))throw new TypeError(`"${e}" is not a unix timestamp in seconds`)}else if("string"==typeof e)b(Math.floor(new Date(e).valueOf()/1e3));else if(!(t=e)||isNaN(t)||"[object Date]"!==Object.prototype.toString.call(t))throw new TypeError(`"${e}" is not a valid time`);var t}function x(e){const t=i(e);if(t.length<1||-1===t.indexOf(r))throw new TypeError(`@context is missing default context "${r}"`)}function w(e){const t=i(e);if(t.length<1||-1===t.indexOf("VerifiableCredential"))throw new TypeError('type is missing default "VerifiableCredential"')}function j(e){const t=i(e);if(t.length<1||-1===t.indexOf("VerifiablePresentation"))throw new TypeError('type is missing default "VerifiablePresentation"')}function g(e){if(0===Object.keys(e).length)throw new TypeError("credentialSubject must not be empty")}function h(e){x(e.vc["@context"]),w(e.vc.type),g(e.vc.credentialSubject),e.nbf&&b(e.nbf),e.exp&&b(e.exp)}function O(e){x(e["@context"]),w(e.type),g(e.credentialSubject),e.issuanceDate&&b(e.issuanceDate),e.expirationDate&&b(e.expirationDate)}function m(e){if(x(e.vp["@context"]),j(e.vp.type),e.vp.verifiableCredential&&e.vp.verifiableCredential.length>=1)for(const t of i(e.vp.verifiableCredential))"string"==typeof t?y(t):O(t);e.exp&&b(e.exp)}function S(e){if(x(e["@context"]),j(e.type),e.verifiableCredential&&e.verifiableCredential.length>=1)for(const t of e.verifiableCredential)"string"==typeof t?y(t):O(t);e.expirationDate&&b(e.expirationDate)}function P(e,t){if(t.challenge&&t.challenge!==e.nonce)throw new Error(`Presentation does not contain the mandatory challenge (JWT: nonce) for : ${t.challenge}`);if(t.domain){let r;if(e.aud&&(r=(Array.isArray(e.aud)?e.aud:[e.aud]).find(e=>t.domain===e)),void 0===r)throw new Error(`Presentation does not contain the mandatory domain (JWT: aud) for : ${t.domain}`)}}exports.createVerifiableCredentialJwt=function(t,r,n={}){try{var i;const o={iat:void 0,...d(t,n.removeOriginalFields)};return h(o),Promise.resolve(e.createJWT(o,{...n,issuer:r.did||o.iss||"",signer:r.signer},{...n.header,alg:r.alg||(null==(i=n.header)?void 0:i.alg)||"ES256K"}))}catch(e){return Promise.reject(e)}},exports.createVerifiablePresentationJwt=function(t,r,n={}){try{var o;const l={iat:void 0,...v(t,null==n?void 0:n.removeOriginalFields)};if(n.challenge&&-1===Object.getOwnPropertyNames(l).indexOf("nonce")&&(l.nonce=n.challenge),n.domain){const e=[...i(n.domain),...i(l.aud)].filter(a);l.aud=[...new Set(e)]}return m(l),Promise.resolve(e.createJWT(l,{...n,issuer:r.did||l.iss||"",signer:r.signer},{...n.header,alg:r.alg||(null==(o=n.header)?void 0:o.alg)||"ES256K"}))}catch(e){return Promise.reject(e)}},exports.normalizeCredential=s,exports.normalizePresentation=p,exports.transformCredentialInput=d,exports.transformPresentationInput=v,exports.validateCredentialPayload=O,exports.validateJwtCredentialPayload=h,exports.validateJwtPresentationPayload=m,exports.validatePresentationPayload=S,exports.verifyCredential=function(t,r,n={}){try{return Promise.resolve(e.verifyJWT(t,{resolver:r,...n})).then(function(e){return e.verifiableCredential=s(e.jwt,null==n?void 0:n.removeOriginalFields),O(e.verifiableCredential),e})}catch(e){return Promise.reject(e)}},exports.verifyPresentation=function(t,r,n={}){try{return Promise.resolve(e.verifyJWT(t,{resolver:r,...n})).then(function(e){return P(e.payload,n),e.verifiablePresentation=p(e.jwt,null==n?void 0:n.removeOriginalFields),S(e.verifiablePresentation),e})}catch(e){return Promise.reject(e)}},exports.verifyPresentationPayloadOptions=P;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import{decodeJWT as e,createJWT as t,verifyJWT as n}from"did-jwt";function i(){return(i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e}).apply(this,arguments)}const r=/^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/,o="https://www.w3.org/2018/credentials/v1",a=["iat","nbf","claim","vc"];function l(e){return Array.isArray(e)?e:[e]}function c(e){return Array.isArray(e)?e.map(e=>c(e)):e instanceof Date?new Date(e.getTime()):e&&"object"==typeof e?Object.getOwnPropertyNames(e).reduce((t,n)=>(Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n)),t[n]=c(e[n]),t),Object.create(Object.getPrototypeOf(e))):e}function s(e){return null!=e}function d(e,t=!0){var n,r,d,f,u,p,v;let b=c(e);var y,w,x;"object"==typeof(y=e)&&y.sub&&y.iss&&y.claim&&y.iat&&(b=function(e){const{iat:t,nbf:n,claim:r,vc:l}=e,c=i({},function(e,t){if(null==e)return{};var n,i,r={},o=Object.keys(e);for(i=0;i<o.length;i++)t.indexOf(n=o[i])>=0||(r[n]=e[n]);return r}(e,a),{nbf:n||t,vc:{"@context":[o],type:["VerifiableCredential"],credentialSubject:r}});return l&&(e.issVc=l),c}(e)),b.credentialSubject=i({},e.credentialSubject,null==(n=e.vc)?void 0:n.credentialSubject),!e.sub||null!=(r=e.credentialSubject)&&r.id||!b.credentialSubject||(b.credentialSubject.id=e.sub,t&&delete b.sub),t&&(null==(w=b.vc)||delete w.credentialSubject),void 0!==e.issuer&&"object"!=typeof e.issuer||(b.issuer=function(e){if("object"!=typeof e)return e;const t=i({},e);return Object.keys(t).forEach(e=>void 0===t[e]&&delete t[e]),t}(i({id:e.iss},e.issuer)),!t||null!=(x=e.issuer)&&x.id||delete b.iss),!e.id&&e.jti&&(b.id=b.id||b.jti,t&&delete b.jti);const j=[...l(b.type),...l(null==(d=b.vc)?void 0:d.type)].filter(s);var O,g,h,m;b.type=[...new Set(j)],t&&(null==(O=b.vc)||delete O.type),b.evidence=null==(f=e.vc)?void 0:f.evidence,t&&(null==(g=b.vc)||delete g.evidence),b.credentialStatus=null==(u=e.vc)?void 0:u.credentialStatus,t&&(null==(h=b.vc)||delete h.credentialStatus),b.termsOfUse=null==(p=e.vc)?void 0:p.termsOfUse,t&&(null==(m=b.vc)||delete m.termsOfUse);const S=[...l(e.context),...l(e["@context"]),...l(null==(v=e.vc)?void 0:v["@context"])].filter(s);var D;return b["@context"]=[...new Set(S)],t&&(delete b.context,null==(D=b.vc)||delete D["@context"]),e.issuanceDate||!e.iat&&!e.nbf||(b.issuanceDate=new Date(1e3*(e.nbf||e.iat)).toISOString(),t&&(e.nbf?delete b.nbf:delete b.iat)),!e.expirationDate&&e.exp&&(b.expirationDate=new Date(1e3*e.exp).toISOString(),t&&delete b.exp),t&&b.vc&&0===Object.keys(b.vc).length&&delete b.vc,b}function f(t,n=!0){let r;try{r=e(t)}catch(e){throw new TypeError("unknown credential format")}return i({},d(r.payload,n),{proof:{type:"JwtProof2020",jwt:t}})}function u(e,t=!0){var n;if("string"==typeof e){if(r.test(e))return f(e,t);{let n;try{n=JSON.parse(e)}catch(e){throw new TypeError("unknown credential format")}return u(n,t)}}return null!=(n=e.proof)&&n.jwt?c(i({},f(e.proof.jwt,t),{proof:e.proof})):i({proof:{}},d(e,t))}function p(e,t=!0){var n,r,o;if(Array.isArray(e.credentialSubject))throw Error("credentialSubject of type array not supported");const a=c(i({vc:i({},e.vc)},e));a.vc=a.vc;const d=i({},e.credentialSubject,null==(n=e.vc)?void 0:n.credentialSubject);var f;e.sub||(a.sub=null==(f=e.credentialSubject)?void 0:f.id,t&&delete d.id);const u=[...l(e.context),...l(e["@context"]),...l(null==(r=e.vc)?void 0:r["@context"])].filter(s);a.vc["@context"]=[...new Set(u)],t&&(delete a.context,delete a["@context"]);const p=[...l(e.type),...l(null==(o=e.vc)?void 0:o.type)].filter(s);if(a.vc.type=[...new Set(p)],t&&delete a.type,e.id&&-1===Object.getOwnPropertyNames(e).indexOf("jti")&&(a.jti=e.id,t&&delete a.id),e.issuanceDate&&-1===Object.getOwnPropertyNames(e).indexOf("nbf")){const n=Date.parse(e.issuanceDate);isNaN(n)||(a.nbf=Math.floor(n/1e3),t&&delete a.issuanceDate)}if(e.expirationDate&&-1===Object.getOwnPropertyNames(e).indexOf("exp")){const n=Date.parse(e.expirationDate);isNaN(n)||(a.exp=Math.floor(n/1e3),t&&delete a.expirationDate)}var v;e.issuer&&-1===Object.getOwnPropertyNames(e).indexOf("iss")&&("object"==typeof e.issuer?(a.iss=null==(v=e.issuer)?void 0:v.id,t&&(delete a.issuer.id,0===Object.keys(a.issuer).length&&delete a.issuer)):"string"==typeof e.issuer&&(a.iss=e.iss||""+e.issuer,t&&delete a.issuer)),a.vc.credentialSubject=d,t&&delete a.credentialSubject;const b=["evidence","termsOfUse","refreshService","credentialSchema","credentialStatus"];for(const n of b)e[n]&&(a.vc[n]||(a.vc[n]=e[n]),t&&delete a[n]);return a}function v(e,t=!0){var n,i,r;const o=c(e);var a;o.verifiableCredential=[...l(e.verifiableCredential),...l(null==(n=e.vp)?void 0:n.verifiableCredential)].filter(s),o.verifiableCredential=o.verifiableCredential.map(e=>u(e,t)),t&&(null==(a=o.vp)||delete a.verifiableCredential),e.iss&&!e.holder&&(o.holder=e.iss,t&&delete o.iss),e.aud&&(o.verifier=[...l(e.verifier),...l(e.aud)].filter(s),o.verifier=[...new Set(o.verifier)],t&&delete o.aud),e.jti&&-1===Object.getOwnPropertyNames(e).indexOf("id")&&(o.id=e.id||e.jti,t&&delete o.jti);const d=[...l(e.type),...l(null==(i=e.vp)?void 0:i.type)].filter(s);var f;o.type=[...new Set(d)],t&&(null==(f=o.vp)||delete f.type);const p=[...l(e.context),...l(e["@context"]),...l(null==(r=e.vp)?void 0:r["@context"])].filter(s);var v;return o["@context"]=[...new Set(p)],t&&(delete o.context,null==(v=o.vp)||delete v["@context"]),e.issuanceDate||!e.iat&&!e.nbf||(o.issuanceDate=new Date(1e3*(e.nbf||e.iat)).toISOString(),t&&(e.nbf?delete o.nbf:delete o.iat)),!e.expirationDate&&e.exp&&(o.expirationDate=new Date(1e3*e.exp).toISOString(),t&&delete o.exp),o.vp&&0===Object.keys(o.vp).length&&t&&delete o.vp,o}function b(t,n=!0){let r;try{r=e(t)}catch(e){throw new TypeError("unknown presentation format")}return i({},v(r.payload,n),{proof:{type:"JwtProof2020",jwt:t}})}function y(e,t=!0){var n;if("string"==typeof e){if(r.test(e))return b(e,t);{let n;try{n=JSON.parse(e)}catch(e){throw new TypeError("unknown presentation format")}return y(n,t)}}return null!=(n=e.proof)&&n.jwt?i({},b(e.proof.jwt,t),{proof:e.proof}):i({proof:{}},v(e,t))}function w(e,t=!0){var n,r,o;const a=c(i({vp:i({},e.vp)},e));a.vp=a.vp;const d=[...l(e.context),...l(e["@context"]),...l(null==(n=e.vp)?void 0:n["@context"])].filter(s);a.vp["@context"]=[...new Set(d)],t&&(delete a.context,delete a["@context"]);const f=[...l(e.type),...l(null==(r=e.vp)?void 0:r.type)].filter(s);if(a.vp.type=[...new Set(f)],t&&delete a.type,e.id&&-1===Object.getOwnPropertyNames(e).indexOf("jti")&&(a.jti=e.id,t&&delete a.id),e.issuanceDate&&-1===Object.getOwnPropertyNames(e).indexOf("nbf")){const n=Date.parse(e.issuanceDate);isNaN(n)||(a.nbf=Math.floor(n/1e3),t&&delete a.issuanceDate)}if(e.expirationDate&&-1===Object.getOwnPropertyNames(e).indexOf("exp")){const n=Date.parse(e.expirationDate);isNaN(n)||(a.exp=Math.floor(n/1e3),t&&delete a.expirationDate)}var u;if((a.verifiableCredential||null!=(o=a.vp)&&o.verifiableCredential)&&(a.vp.verifiableCredential=[...l(a.verifiableCredential),...l(null==(u=a.vp)?void 0:u.verifiableCredential)].filter(s).map(e=>{var t;return"object"==typeof e&&null!=(t=e.proof)&&t.jwt?e.proof.jwt:e})),t&&delete a.verifiableCredential,e.holder&&-1===Object.getOwnPropertyNames(e).indexOf("iss")&&"string"==typeof e.holder&&(a.iss=e.holder,t&&delete a.holder),e.verifier){const n=[...l(e.verifier),...l(e.aud)].filter(s);a.aud=[...new Set(n)],t&&delete a.verifier}return a}function x(e){if("string"==typeof e&&!e.match(r))throw new TypeError(`"${e}" is not a valid JWT format`)}function j(e){if("number"==typeof e){if(!(Number.isInteger(e)&&e<1e11))throw new TypeError(`"${e}" is not a unix timestamp in seconds`)}else if("string"==typeof e)j(Math.floor(new Date(e).valueOf()/1e3));else if(!(t=e)||isNaN(t)||"[object Date]"!==Object.prototype.toString.call(t))throw new TypeError(`"${e}" is not a valid time`);var t}function O(e){const t=l(e);if(t.length<1||-1===t.indexOf(o))throw new TypeError(`@context is missing default context "${o}"`)}function g(e){const t=l(e);if(t.length<1||-1===t.indexOf("VerifiableCredential"))throw new TypeError('type is missing default "VerifiableCredential"')}function h(e){const t=l(e);if(t.length<1||-1===t.indexOf("VerifiablePresentation"))throw new TypeError('type is missing default "VerifiablePresentation"')}function m(e){if(0===Object.keys(e).length)throw new TypeError("credentialSubject must not be empty")}async function S(e,n,r={}){var o;const a=i({iat:void 0},p(e,r.removeOriginalFields));return N(a),t(a,i({},r,{issuer:n.did||a.iss||"",signer:n.signer}),i({},r.header,{alg:n.alg||(null==(o=r.header)?void 0:o.alg)||"ES256K"}))}async function D(e,n,r={}){var o;const a=i({iat:void 0},w(e,null==r?void 0:r.removeOriginalFields));if(r.challenge&&-1===Object.getOwnPropertyNames(a).indexOf("nonce")&&(a.nonce=r.challenge),r.domain){const e=[...l(r.domain),...l(a.aud)].filter(s);a.aud=[...new Set(e)]}return P(a),t(a,i({},r,{issuer:n.did||a.iss||"",signer:n.signer}),i({},r.header,{alg:n.alg||(null==(o=r.header)?void 0:o.alg)||"ES256K"}))}function N(e){O(e.vc["@context"]),g(e.vc.type),m(e.vc.credentialSubject),e.nbf&&j(e.nbf),e.exp&&j(e.exp)}function C(e){O(e["@context"]),g(e.type),m(e.credentialSubject),e.issuanceDate&&j(e.issuanceDate),e.expirationDate&&j(e.expirationDate)}function P(e){if(O(e.vp["@context"]),h(e.vp.type),e.vp.verifiableCredential&&e.vp.verifiableCredential.length>=1)for(const t of l(e.vp.verifiableCredential))"string"==typeof t?x(t):C(t);e.exp&&j(e.exp)}function E(e){if(O(e["@context"]),h(e.type),e.verifiableCredential&&e.verifiableCredential.length>=1)for(const t of e.verifiableCredential)"string"==typeof t?x(t):C(t);e.expirationDate&&j(e.expirationDate)}async function T(e,t,r={}){const o=await n(e,i({resolver:t},r));return o.verifiableCredential=u(o.jwt,null==r?void 0:r.removeOriginalFields),C(o.verifiableCredential),o}function A(e,t){if(t.challenge&&t.challenge!==e.nonce)throw new Error(`Presentation does not contain the mandatory challenge (JWT: nonce) for : ${t.challenge}`);if(t.domain){let n;if(e.aud&&(n=(Array.isArray(e.aud)?e.aud:[e.aud]).find(e=>t.domain===e)),void 0===n)throw new Error(`Presentation does not contain the mandatory domain (JWT: aud) for : ${t.domain}`)}}async function k(e,t,r={}){const o=await n(e,i({resolver:t},r));return A(o.payload,r),o.verifiablePresentation=y(o.jwt,null==r?void 0:r.removeOriginalFields),E(o.verifiablePresentation),o}export{S as createVerifiableCredentialJwt,D as createVerifiablePresentationJwt,u as normalizeCredential,y as normalizePresentation,p as transformCredentialInput,w as transformPresentationInput,C as validateCredentialPayload,N as validateJwtCredentialPayload,P as validateJwtPresentationPayload,E as validatePresentationPayload,T as verifyCredential,k as verifyPresentation,A as verifyPresentationPayloadOptions};
import{decodeJWT as e,createJWT as t,verifyJWT as n}from"did-jwt";function i(){return(i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e}).apply(this,arguments)}const r=/^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/,o="https://www.w3.org/2018/credentials/v1",a=["iat","nbf","claim","vc"],l=["evidence","termsOfUse","refreshService","credentialSchema","credentialStatus"];function c(e){return Array.isArray(e)?e:[e]}function s(e){return Array.isArray(e)?e.map(e=>s(e)):e instanceof Date?new Date(e.getTime()):e&&"object"==typeof e?Object.getOwnPropertyNames(e).reduce((t,n)=>(Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n)),t[n]=s(e[n]),t),Object.create(Object.getPrototypeOf(e))):e}function d(e){return null!=e}function f(e,t=!0){var n,r,f,u;let p=s(e);var v,b,y;"object"==typeof(v=e)&&v.sub&&v.iss&&v.claim&&v.iat&&(p=function(e){const{iat:t,nbf:n,claim:r,vc:l}=e,c=i({},function(e,t){if(null==e)return{};var n,i,r={},o=Object.keys(e);for(i=0;i<o.length;i++)t.indexOf(n=o[i])>=0||(r[n]=e[n]);return r}(e,a),{nbf:n||t,vc:{"@context":[o],type:["VerifiableCredential"],credentialSubject:r}});return l&&(e.issVc=l),c}(e)),p.credentialSubject=i({},e.credentialSubject,null==(n=e.vc)?void 0:n.credentialSubject),!e.sub||null!=(r=e.credentialSubject)&&r.id||!p.credentialSubject||(p.credentialSubject.id=e.sub,t&&delete p.sub),t&&(null==(b=p.vc)||delete b.credentialSubject),void 0!==e.issuer&&"object"!=typeof e.issuer||(p.issuer=function(e){if("object"!=typeof e)return e;const t=i({},e);return Object.keys(t).forEach(e=>void 0===t[e]&&delete t[e]),t}(i({id:e.iss},e.issuer)),!t||null!=(y=e.issuer)&&y.id||delete p.iss),!e.id&&e.jti&&(p.id=p.id||p.jti,t&&delete p.jti);const w=[...c(p.type),...c(null==(f=p.vc)?void 0:f.type)].filter(d);var x;p.type=[...new Set(w)],t&&(null==(x=p.vc)||delete x.type);for(const n of l)e.vc&&e.vc[n]&&(p[n]||(p[n]=e.vc[n]),t&&delete p.vc[n]);const j=[...c(e.context),...c(e["@context"]),...c(null==(u=e.vc)?void 0:u["@context"])].filter(d);var g;return p["@context"]=[...new Set(j)],t&&(delete p.context,null==(g=p.vc)||delete g["@context"]),e.issuanceDate||!e.iat&&!e.nbf||(p.issuanceDate=new Date(1e3*(e.nbf||e.iat)).toISOString(),t&&(e.nbf?delete p.nbf:delete p.iat)),!e.expirationDate&&e.exp&&(p.expirationDate=new Date(1e3*e.exp).toISOString(),t&&delete p.exp),t&&p.vc&&0===Object.keys(p.vc).length&&delete p.vc,p}function u(t,n=!0){let r;try{r=e(t)}catch(e){throw new TypeError("unknown credential format")}return i({},f(r.payload,n),{proof:{type:"JwtProof2020",jwt:t}})}function p(e,t=!0){var n;if("string"==typeof e){if(r.test(e))return u(e,t);{let n;try{n=JSON.parse(e)}catch(e){throw new TypeError("unknown credential format")}return p(n,t)}}return null!=(n=e.proof)&&n.jwt?s(i({},u(e.proof.jwt,t),{proof:e.proof})):i({proof:{}},f(e,t))}function v(e,t=!0){var n,r,o;if(Array.isArray(e.credentialSubject))throw Error("credentialSubject of type array not supported");const a=s(i({vc:i({},e.vc)},e));a.vc=a.vc;const f=i({},e.credentialSubject,null==(n=e.vc)?void 0:n.credentialSubject);var u;e.sub||(a.sub=null==(u=e.credentialSubject)?void 0:u.id,t&&delete f.id);const p=[...c(e.context),...c(e["@context"]),...c(null==(r=e.vc)?void 0:r["@context"])].filter(d);a.vc["@context"]=[...new Set(p)],t&&(delete a.context,delete a["@context"]);const v=[...c(e.type),...c(null==(o=e.vc)?void 0:o.type)].filter(d);if(a.vc.type=[...new Set(v)],t&&delete a.type,e.id&&-1===Object.getOwnPropertyNames(e).indexOf("jti")&&(a.jti=e.id,t&&delete a.id),e.issuanceDate&&-1===Object.getOwnPropertyNames(e).indexOf("nbf")){const n=Date.parse(e.issuanceDate);isNaN(n)||(a.nbf=Math.floor(n/1e3),t&&delete a.issuanceDate)}if(e.expirationDate&&-1===Object.getOwnPropertyNames(e).indexOf("exp")){const n=Date.parse(e.expirationDate);isNaN(n)||(a.exp=Math.floor(n/1e3),t&&delete a.expirationDate)}var b;e.issuer&&-1===Object.getOwnPropertyNames(e).indexOf("iss")&&("object"==typeof e.issuer?(a.iss=null==(b=e.issuer)?void 0:b.id,t&&(delete a.issuer.id,0===Object.keys(a.issuer).length&&delete a.issuer)):"string"==typeof e.issuer&&(a.iss=e.iss||""+e.issuer,t&&delete a.issuer)),a.vc.credentialSubject=f,t&&delete a.credentialSubject;for(const n of l)e[n]&&(a.vc[n]||(a.vc[n]=e[n]),t&&delete a[n]);return a}function b(e,t=!0){var n,i,r;const o=s(e);var a;o.verifiableCredential=[...c(e.verifiableCredential),...c(null==(n=e.vp)?void 0:n.verifiableCredential)].filter(d),o.verifiableCredential=o.verifiableCredential.map(e=>p(e,t)),t&&(null==(a=o.vp)||delete a.verifiableCredential),e.iss&&!e.holder&&(o.holder=e.iss,t&&delete o.iss),e.aud&&(o.verifier=[...c(e.verifier),...c(e.aud)].filter(d),o.verifier=[...new Set(o.verifier)],t&&delete o.aud),e.jti&&-1===Object.getOwnPropertyNames(e).indexOf("id")&&(o.id=e.id||e.jti,t&&delete o.jti);const l=[...c(e.type),...c(null==(i=e.vp)?void 0:i.type)].filter(d);var f;o.type=[...new Set(l)],t&&(null==(f=o.vp)||delete f.type);const u=[...c(e.context),...c(e["@context"]),...c(null==(r=e.vp)?void 0:r["@context"])].filter(d);var v;return o["@context"]=[...new Set(u)],t&&(delete o.context,null==(v=o.vp)||delete v["@context"]),e.issuanceDate||!e.iat&&!e.nbf||(o.issuanceDate=new Date(1e3*(e.nbf||e.iat)).toISOString(),t&&(e.nbf?delete o.nbf:delete o.iat)),!e.expirationDate&&e.exp&&(o.expirationDate=new Date(1e3*e.exp).toISOString(),t&&delete o.exp),o.vp&&0===Object.keys(o.vp).length&&t&&delete o.vp,o}function y(t,n=!0){let r;try{r=e(t)}catch(e){throw new TypeError("unknown presentation format")}return i({},b(r.payload,n),{proof:{type:"JwtProof2020",jwt:t}})}function w(e,t=!0){var n;if("string"==typeof e){if(r.test(e))return y(e,t);{let n;try{n=JSON.parse(e)}catch(e){throw new TypeError("unknown presentation format")}return w(n,t)}}return null!=(n=e.proof)&&n.jwt?i({},y(e.proof.jwt,t),{proof:e.proof}):i({proof:{}},b(e,t))}function x(e,t=!0){var n,r,o;const a=s(i({vp:i({},e.vp)},e));a.vp=a.vp;const l=[...c(e.context),...c(e["@context"]),...c(null==(n=e.vp)?void 0:n["@context"])].filter(d);a.vp["@context"]=[...new Set(l)],t&&(delete a.context,delete a["@context"]);const f=[...c(e.type),...c(null==(r=e.vp)?void 0:r.type)].filter(d);if(a.vp.type=[...new Set(f)],t&&delete a.type,e.id&&-1===Object.getOwnPropertyNames(e).indexOf("jti")&&(a.jti=e.id,t&&delete a.id),e.issuanceDate&&-1===Object.getOwnPropertyNames(e).indexOf("nbf")){const n=Date.parse(e.issuanceDate);isNaN(n)||(a.nbf=Math.floor(n/1e3),t&&delete a.issuanceDate)}if(e.expirationDate&&-1===Object.getOwnPropertyNames(e).indexOf("exp")){const n=Date.parse(e.expirationDate);isNaN(n)||(a.exp=Math.floor(n/1e3),t&&delete a.expirationDate)}var u;if((a.verifiableCredential||null!=(o=a.vp)&&o.verifiableCredential)&&(a.vp.verifiableCredential=[...c(a.verifiableCredential),...c(null==(u=a.vp)?void 0:u.verifiableCredential)].filter(d).map(e=>{var t;return"object"==typeof e&&null!=(t=e.proof)&&t.jwt?e.proof.jwt:e})),t&&delete a.verifiableCredential,e.holder&&-1===Object.getOwnPropertyNames(e).indexOf("iss")&&"string"==typeof e.holder&&(a.iss=e.holder,t&&delete a.holder),e.verifier){const n=[...c(e.verifier),...c(e.aud)].filter(d);a.aud=[...new Set(n)],t&&delete a.verifier}return a}function j(e){if("string"==typeof e&&!e.match(r))throw new TypeError(`"${e}" is not a valid JWT format`)}function g(e){if("number"==typeof e){if(!(Number.isInteger(e)&&e<1e11))throw new TypeError(`"${e}" is not a unix timestamp in seconds`)}else if("string"==typeof e)g(Math.floor(new Date(e).valueOf()/1e3));else if(!(t=e)||isNaN(t)||"[object Date]"!==Object.prototype.toString.call(t))throw new TypeError(`"${e}" is not a valid time`);var t}function O(e){const t=c(e);if(t.length<1||-1===t.indexOf(o))throw new TypeError(`@context is missing default context "${o}"`)}function h(e){const t=c(e);if(t.length<1||-1===t.indexOf("VerifiableCredential"))throw new TypeError('type is missing default "VerifiableCredential"')}function m(e){const t=c(e);if(t.length<1||-1===t.indexOf("VerifiablePresentation"))throw new TypeError('type is missing default "VerifiablePresentation"')}function S(e){if(0===Object.keys(e).length)throw new TypeError("credentialSubject must not be empty")}async function D(e,n,r={}){var o;const a=i({iat:void 0},v(e,r.removeOriginalFields));return C(a),t(a,i({},r,{issuer:n.did||a.iss||"",signer:n.signer}),i({},r.header,{alg:n.alg||(null==(o=r.header)?void 0:o.alg)||"ES256K"}))}async function N(e,n,r={}){var o;const a=i({iat:void 0},x(e,null==r?void 0:r.removeOriginalFields));if(r.challenge&&-1===Object.getOwnPropertyNames(a).indexOf("nonce")&&(a.nonce=r.challenge),r.domain){const e=[...c(r.domain),...c(a.aud)].filter(d);a.aud=[...new Set(e)]}return E(a),t(a,i({},r,{issuer:n.did||a.iss||"",signer:n.signer}),i({},r.header,{alg:n.alg||(null==(o=r.header)?void 0:o.alg)||"ES256K"}))}function C(e){O(e.vc["@context"]),h(e.vc.type),S(e.vc.credentialSubject),e.nbf&&g(e.nbf),e.exp&&g(e.exp)}function P(e){O(e["@context"]),h(e.type),S(e.credentialSubject),e.issuanceDate&&g(e.issuanceDate),e.expirationDate&&g(e.expirationDate)}function E(e){if(O(e.vp["@context"]),m(e.vp.type),e.vp.verifiableCredential&&e.vp.verifiableCredential.length>=1)for(const t of c(e.vp.verifiableCredential))"string"==typeof t?j(t):P(t);e.exp&&g(e.exp)}function T(e){if(O(e["@context"]),m(e.type),e.verifiableCredential&&e.verifiableCredential.length>=1)for(const t of e.verifiableCredential)"string"==typeof t?j(t):P(t);e.expirationDate&&g(e.expirationDate)}async function A(e,t,r={}){const o=await n(e,i({resolver:t},r));return o.verifiableCredential=p(o.jwt,null==r?void 0:r.removeOriginalFields),P(o.verifiableCredential),o}function k(e,t){if(t.challenge&&t.challenge!==e.nonce)throw new Error(`Presentation does not contain the mandatory challenge (JWT: nonce) for : ${t.challenge}`);if(t.domain){let n;if(e.aud&&(n=(Array.isArray(e.aud)?e.aud:[e.aud]).find(e=>t.domain===e)),void 0===n)throw new Error(`Presentation does not contain the mandatory domain (JWT: aud) for : ${t.domain}`)}}async function J(e,t,r={}){const o=await n(e,i({resolver:t},r));return k(o.payload,r),o.verifiablePresentation=w(o.jwt,null==r?void 0:r.removeOriginalFields),T(o.verifiablePresentation),o}export{D as createVerifiableCredentialJwt,N as createVerifiablePresentationJwt,p as normalizeCredential,w as normalizePresentation,v as transformCredentialInput,x as transformPresentationInput,P as validateCredentialPayload,C as validateJwtCredentialPayload,E as validateJwtPresentationPayload,T as validatePresentationPayload,A as verifyCredential,J as verifyPresentation,k as verifyPresentationPayloadOptions};
//# sourceMappingURL=index.modern.js.map

@@ -1,2 +0,2 @@

import{decodeJWT as e,verifyJWT as t,createJWT as n}from"did-jwt";const r=/^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/,i="https://www.w3.org/2018/credentials/v1";function o(e){return Array.isArray(e)?e:[e]}function a(e){return Array.isArray(e)?e.map(e=>a(e)):e instanceof Date?new Date(e.getTime()):e&&"object"==typeof e?Object.getOwnPropertyNames(e).reduce((t,n)=>(Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n)),t[n]=a(e[n]),t),Object.create(Object.getPrototypeOf(e))):e}function l(e){return null!=e}function c(e,t=!0){var n,r,c,s,d,f,u;let p=a(e);var v,b,y;"object"==typeof(v=e)&&v.sub&&v.iss&&v.claim&&v.iat&&(p=function(e){const{iat:t,nbf:n,claim:r,vc:o,...a}=e,l={...a,nbf:n||t,vc:{"@context":[i],type:["VerifiableCredential"],credentialSubject:r}};return o&&(e.issVc=o),l}(e)),p.credentialSubject={...e.credentialSubject,...null==(n=e.vc)?void 0:n.credentialSubject},!e.sub||null!=(r=e.credentialSubject)&&r.id||!p.credentialSubject||(p.credentialSubject.id=e.sub,t&&delete p.sub),t&&(null==(b=p.vc)||delete b.credentialSubject),void 0!==e.issuer&&"object"!=typeof e.issuer||(p.issuer=function(e){if("object"!=typeof e)return e;const t={...e};return Object.keys(t).forEach(e=>void 0===t[e]&&delete t[e]),t}({id:e.iss,...e.issuer}),!t||null!=(y=e.issuer)&&y.id||delete p.iss),!e.id&&e.jti&&(p.id=p.id||p.jti,t&&delete p.jti);const w=[...o(p.type),...o(null==(c=p.vc)?void 0:c.type)].filter(l);var x,j,O,g;p.type=[...new Set(w)],t&&(null==(x=p.vc)||delete x.type),p.evidence=null==(s=e.vc)?void 0:s.evidence,t&&(null==(j=p.vc)||delete j.evidence),p.credentialStatus=null==(d=e.vc)?void 0:d.credentialStatus,t&&(null==(O=p.vc)||delete O.credentialStatus),p.termsOfUse=null==(f=e.vc)?void 0:f.termsOfUse,t&&(null==(g=p.vc)||delete g.termsOfUse);const h=[...o(e.context),...o(e["@context"]),...o(null==(u=e.vc)?void 0:u["@context"])].filter(l);var m;return p["@context"]=[...new Set(h)],t&&(delete p.context,null==(m=p.vc)||delete m["@context"]),e.issuanceDate||!e.iat&&!e.nbf||(p.issuanceDate=new Date(1e3*(e.nbf||e.iat)).toISOString(),t&&(e.nbf?delete p.nbf:delete p.iat)),!e.expirationDate&&e.exp&&(p.expirationDate=new Date(1e3*e.exp).toISOString(),t&&delete p.exp),t&&p.vc&&0===Object.keys(p.vc).length&&delete p.vc,p}function s(t,n=!0){let r;try{r=e(t)}catch(e){throw new TypeError("unknown credential format")}return{...c(r.payload,n),proof:{type:"JwtProof2020",jwt:t}}}function d(e,t=!0){var n;if("string"==typeof e){if(r.test(e))return s(e,t);{let n;try{n=JSON.parse(e)}catch(e){throw new TypeError("unknown credential format")}return d(n,t)}}return null!=(n=e.proof)&&n.jwt?a({...s(e.proof.jwt,t),proof:e.proof}):{proof:{},...c(e,t)}}function f(e,t=!0){var n,r,i;if(Array.isArray(e.credentialSubject))throw Error("credentialSubject of type array not supported");const c=a({vc:{...e.vc},...e});c.vc=c.vc;const s={...e.credentialSubject,...null==(n=e.vc)?void 0:n.credentialSubject};var d;e.sub||(c.sub=null==(d=e.credentialSubject)?void 0:d.id,t&&delete s.id);const f=[...o(e.context),...o(e["@context"]),...o(null==(r=e.vc)?void 0:r["@context"])].filter(l);c.vc["@context"]=[...new Set(f)],t&&(delete c.context,delete c["@context"]);const u=[...o(e.type),...o(null==(i=e.vc)?void 0:i.type)].filter(l);if(c.vc.type=[...new Set(u)],t&&delete c.type,e.id&&-1===Object.getOwnPropertyNames(e).indexOf("jti")&&(c.jti=e.id,t&&delete c.id),e.issuanceDate&&-1===Object.getOwnPropertyNames(e).indexOf("nbf")){const n=Date.parse(e.issuanceDate);isNaN(n)||(c.nbf=Math.floor(n/1e3),t&&delete c.issuanceDate)}if(e.expirationDate&&-1===Object.getOwnPropertyNames(e).indexOf("exp")){const n=Date.parse(e.expirationDate);isNaN(n)||(c.exp=Math.floor(n/1e3),t&&delete c.expirationDate)}var p;e.issuer&&-1===Object.getOwnPropertyNames(e).indexOf("iss")&&("object"==typeof e.issuer?(c.iss=null==(p=e.issuer)?void 0:p.id,t&&(delete c.issuer.id,0===Object.keys(c.issuer).length&&delete c.issuer)):"string"==typeof e.issuer&&(c.iss=e.iss||""+e.issuer,t&&delete c.issuer)),c.vc.credentialSubject=s,t&&delete c.credentialSubject;const v=["evidence","termsOfUse","refreshService","credentialSchema","credentialStatus"];for(const n of v)e[n]&&(c.vc[n]||(c.vc[n]=e[n]),t&&delete c[n]);return c}function u(e,t=!0){var n,r,i;const c=a(e);var s;c.verifiableCredential=[...o(e.verifiableCredential),...o(null==(n=e.vp)?void 0:n.verifiableCredential)].filter(l),c.verifiableCredential=c.verifiableCredential.map(e=>d(e,t)),t&&(null==(s=c.vp)||delete s.verifiableCredential),e.iss&&!e.holder&&(c.holder=e.iss,t&&delete c.iss),e.aud&&(c.verifier=[...o(e.verifier),...o(e.aud)].filter(l),c.verifier=[...new Set(c.verifier)],t&&delete c.aud),e.jti&&-1===Object.getOwnPropertyNames(e).indexOf("id")&&(c.id=e.id||e.jti,t&&delete c.jti);const f=[...o(e.type),...o(null==(r=e.vp)?void 0:r.type)].filter(l);var u;c.type=[...new Set(f)],t&&(null==(u=c.vp)||delete u.type);const p=[...o(e.context),...o(e["@context"]),...o(null==(i=e.vp)?void 0:i["@context"])].filter(l);var v;return c["@context"]=[...new Set(p)],t&&(delete c.context,null==(v=c.vp)||delete v["@context"]),e.issuanceDate||!e.iat&&!e.nbf||(c.issuanceDate=new Date(1e3*(e.nbf||e.iat)).toISOString(),t&&(e.nbf?delete c.nbf:delete c.iat)),!e.expirationDate&&e.exp&&(c.expirationDate=new Date(1e3*e.exp).toISOString(),t&&delete c.exp),c.vp&&0===Object.keys(c.vp).length&&t&&delete c.vp,c}function p(t,n=!0){let r;try{r=e(t)}catch(e){throw new TypeError("unknown presentation format")}return{...u(r.payload,n),proof:{type:"JwtProof2020",jwt:t}}}function v(e,t=!0){var n;if("string"==typeof e){if(r.test(e))return p(e,t);{let n;try{n=JSON.parse(e)}catch(e){throw new TypeError("unknown presentation format")}return v(n,t)}}return null!=(n=e.proof)&&n.jwt?{...p(e.proof.jwt,t),proof:e.proof}:{proof:{},...u(e,t)}}function b(e,t=!0){var n,r,i;const c=a({vp:{...e.vp},...e});c.vp=c.vp;const s=[...o(e.context),...o(e["@context"]),...o(null==(n=e.vp)?void 0:n["@context"])].filter(l);c.vp["@context"]=[...new Set(s)],t&&(delete c.context,delete c["@context"]);const d=[...o(e.type),...o(null==(r=e.vp)?void 0:r.type)].filter(l);if(c.vp.type=[...new Set(d)],t&&delete c.type,e.id&&-1===Object.getOwnPropertyNames(e).indexOf("jti")&&(c.jti=e.id,t&&delete c.id),e.issuanceDate&&-1===Object.getOwnPropertyNames(e).indexOf("nbf")){const n=Date.parse(e.issuanceDate);isNaN(n)||(c.nbf=Math.floor(n/1e3),t&&delete c.issuanceDate)}if(e.expirationDate&&-1===Object.getOwnPropertyNames(e).indexOf("exp")){const n=Date.parse(e.expirationDate);isNaN(n)||(c.exp=Math.floor(n/1e3),t&&delete c.expirationDate)}var f;if((c.verifiableCredential||null!=(i=c.vp)&&i.verifiableCredential)&&(c.vp.verifiableCredential=[...o(c.verifiableCredential),...o(null==(f=c.vp)?void 0:f.verifiableCredential)].filter(l).map(e=>{var t;return"object"==typeof e&&null!=(t=e.proof)&&t.jwt?e.proof.jwt:e})),t&&delete c.verifiableCredential,e.holder&&-1===Object.getOwnPropertyNames(e).indexOf("iss")&&"string"==typeof e.holder&&(c.iss=e.holder,t&&delete c.holder),e.verifier){const n=[...o(e.verifier),...o(e.aud)].filter(l);c.aud=[...new Set(n)],t&&delete c.verifier}return c}function y(e){if("string"==typeof e&&!e.match(r))throw new TypeError(`"${e}" is not a valid JWT format`)}function w(e){if("number"==typeof e){if(!(Number.isInteger(e)&&e<1e11))throw new TypeError(`"${e}" is not a unix timestamp in seconds`)}else if("string"==typeof e)w(Math.floor(new Date(e).valueOf()/1e3));else if(!(t=e)||isNaN(t)||"[object Date]"!==Object.prototype.toString.call(t))throw new TypeError(`"${e}" is not a valid time`);var t}function x(e){const t=o(e);if(t.length<1||-1===t.indexOf(i))throw new TypeError(`@context is missing default context "${i}"`)}function j(e){const t=o(e);if(t.length<1||-1===t.indexOf("VerifiableCredential"))throw new TypeError('type is missing default "VerifiableCredential"')}function O(e){const t=o(e);if(t.length<1||-1===t.indexOf("VerifiablePresentation"))throw new TypeError('type is missing default "VerifiablePresentation"')}function g(e){if(0===Object.keys(e).length)throw new TypeError("credentialSubject must not be empty")}const h=function(e,n,r={}){try{return Promise.resolve(t(e,{resolver:n,...r})).then(function(e){return T(e.payload,r),e.verifiablePresentation=v(e.jwt,null==r?void 0:r.removeOriginalFields),E(e.verifiablePresentation),e})}catch(e){return Promise.reject(e)}},m=function(e,n,r={}){try{return Promise.resolve(t(e,{resolver:n,...r})).then(function(e){return e.verifiableCredential=d(e.jwt,null==r?void 0:r.removeOriginalFields),N(e.verifiableCredential),e})}catch(e){return Promise.reject(e)}},S=function(e,t,r={}){try{var i;const a={iat:void 0,...b(e,null==r?void 0:r.removeOriginalFields)};if(r.challenge&&-1===Object.getOwnPropertyNames(a).indexOf("nonce")&&(a.nonce=r.challenge),r.domain){const e=[...o(r.domain),...o(a.aud)].filter(l);a.aud=[...new Set(e)]}return C(a),Promise.resolve(n(a,{...r,issuer:t.did||a.iss||"",signer:t.signer},{...r.header,alg:t.alg||(null==(i=r.header)?void 0:i.alg)||"ES256K"}))}catch(e){return Promise.reject(e)}},D=function(e,t,r={}){try{var i;const o={iat:void 0,...f(e,r.removeOriginalFields)};return P(o),Promise.resolve(n(o,{...r,issuer:t.did||o.iss||"",signer:t.signer},{...r.header,alg:t.alg||(null==(i=r.header)?void 0:i.alg)||"ES256K"}))}catch(e){return Promise.reject(e)}};function P(e){x(e.vc["@context"]),j(e.vc.type),g(e.vc.credentialSubject),e.nbf&&w(e.nbf),e.exp&&w(e.exp)}function N(e){x(e["@context"]),j(e.type),g(e.credentialSubject),e.issuanceDate&&w(e.issuanceDate),e.expirationDate&&w(e.expirationDate)}function C(e){if(x(e.vp["@context"]),O(e.vp.type),e.vp.verifiableCredential&&e.vp.verifiableCredential.length>=1)for(const t of o(e.vp.verifiableCredential))"string"==typeof t?y(t):N(t);e.exp&&w(e.exp)}function E(e){if(x(e["@context"]),O(e.type),e.verifiableCredential&&e.verifiableCredential.length>=1)for(const t of e.verifiableCredential)"string"==typeof t?y(t):N(t);e.expirationDate&&w(e.expirationDate)}function T(e,t){if(t.challenge&&t.challenge!==e.nonce)throw new Error(`Presentation does not contain the mandatory challenge (JWT: nonce) for : ${t.challenge}`);if(t.domain){let n;if(e.aud&&(n=(Array.isArray(e.aud)?e.aud:[e.aud]).find(e=>t.domain===e)),void 0===n)throw new Error(`Presentation does not contain the mandatory domain (JWT: aud) for : ${t.domain}`)}}export{D as createVerifiableCredentialJwt,S as createVerifiablePresentationJwt,d as normalizeCredential,v as normalizePresentation,f as transformCredentialInput,b as transformPresentationInput,N as validateCredentialPayload,P as validateJwtCredentialPayload,C as validateJwtPresentationPayload,E as validatePresentationPayload,m as verifyCredential,h as verifyPresentation,T as verifyPresentationPayloadOptions};
import{decodeJWT as e,verifyJWT as t,createJWT as r}from"did-jwt";const n=/^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/,i="https://www.w3.org/2018/credentials/v1",o=["evidence","termsOfUse","refreshService","credentialSchema","credentialStatus"];function a(e){return Array.isArray(e)?e:[e]}function l(e){return Array.isArray(e)?e.map(e=>l(e)):e instanceof Date?new Date(e.getTime()):e&&"object"==typeof e?Object.getOwnPropertyNames(e).reduce((t,r)=>(Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r)),t[r]=l(e[r]),t),Object.create(Object.getPrototypeOf(e))):e}function c(e){return null!=e}function s(e,t=!0){var r,n,s,d;let f=l(e);var u,p,v;"object"==typeof(u=e)&&u.sub&&u.iss&&u.claim&&u.iat&&(f=function(e){const{iat:t,nbf:r,claim:n,vc:o,...a}=e,l={...a,nbf:r||t,vc:{"@context":[i],type:["VerifiableCredential"],credentialSubject:n}};return o&&(e.issVc=o),l}(e)),f.credentialSubject={...e.credentialSubject,...null==(r=e.vc)?void 0:r.credentialSubject},!e.sub||null!=(n=e.credentialSubject)&&n.id||!f.credentialSubject||(f.credentialSubject.id=e.sub,t&&delete f.sub),t&&(null==(p=f.vc)||delete p.credentialSubject),void 0!==e.issuer&&"object"!=typeof e.issuer||(f.issuer=function(e){if("object"!=typeof e)return e;const t={...e};return Object.keys(t).forEach(e=>void 0===t[e]&&delete t[e]),t}({id:e.iss,...e.issuer}),!t||null!=(v=e.issuer)&&v.id||delete f.iss),!e.id&&e.jti&&(f.id=f.id||f.jti,t&&delete f.jti);const b=[...a(f.type),...a(null==(s=f.vc)?void 0:s.type)].filter(c);var y;f.type=[...new Set(b)],t&&(null==(y=f.vc)||delete y.type);for(const r of o)e.vc&&e.vc[r]&&(f[r]||(f[r]=e.vc[r]),t&&delete f.vc[r]);const w=[...a(e.context),...a(e["@context"]),...a(null==(d=e.vc)?void 0:d["@context"])].filter(c);var x;return f["@context"]=[...new Set(w)],t&&(delete f.context,null==(x=f.vc)||delete x["@context"]),e.issuanceDate||!e.iat&&!e.nbf||(f.issuanceDate=new Date(1e3*(e.nbf||e.iat)).toISOString(),t&&(e.nbf?delete f.nbf:delete f.iat)),!e.expirationDate&&e.exp&&(f.expirationDate=new Date(1e3*e.exp).toISOString(),t&&delete f.exp),t&&f.vc&&0===Object.keys(f.vc).length&&delete f.vc,f}function d(t,r=!0){let n;try{n=e(t)}catch(e){throw new TypeError("unknown credential format")}return{...s(n.payload,r),proof:{type:"JwtProof2020",jwt:t}}}function f(e,t=!0){var r;if("string"==typeof e){if(n.test(e))return d(e,t);{let r;try{r=JSON.parse(e)}catch(e){throw new TypeError("unknown credential format")}return f(r,t)}}return null!=(r=e.proof)&&r.jwt?l({...d(e.proof.jwt,t),proof:e.proof}):{proof:{},...s(e,t)}}function u(e,t=!0){var r,n,i;if(Array.isArray(e.credentialSubject))throw Error("credentialSubject of type array not supported");const s=l({vc:{...e.vc},...e});s.vc=s.vc;const d={...e.credentialSubject,...null==(r=e.vc)?void 0:r.credentialSubject};var f;e.sub||(s.sub=null==(f=e.credentialSubject)?void 0:f.id,t&&delete d.id);const u=[...a(e.context),...a(e["@context"]),...a(null==(n=e.vc)?void 0:n["@context"])].filter(c);s.vc["@context"]=[...new Set(u)],t&&(delete s.context,delete s["@context"]);const p=[...a(e.type),...a(null==(i=e.vc)?void 0:i.type)].filter(c);if(s.vc.type=[...new Set(p)],t&&delete s.type,e.id&&-1===Object.getOwnPropertyNames(e).indexOf("jti")&&(s.jti=e.id,t&&delete s.id),e.issuanceDate&&-1===Object.getOwnPropertyNames(e).indexOf("nbf")){const r=Date.parse(e.issuanceDate);isNaN(r)||(s.nbf=Math.floor(r/1e3),t&&delete s.issuanceDate)}if(e.expirationDate&&-1===Object.getOwnPropertyNames(e).indexOf("exp")){const r=Date.parse(e.expirationDate);isNaN(r)||(s.exp=Math.floor(r/1e3),t&&delete s.expirationDate)}var v;e.issuer&&-1===Object.getOwnPropertyNames(e).indexOf("iss")&&("object"==typeof e.issuer?(s.iss=null==(v=e.issuer)?void 0:v.id,t&&(delete s.issuer.id,0===Object.keys(s.issuer).length&&delete s.issuer)):"string"==typeof e.issuer&&(s.iss=e.iss||""+e.issuer,t&&delete s.issuer)),s.vc.credentialSubject=d,t&&delete s.credentialSubject;for(const r of o)e[r]&&(s.vc[r]||(s.vc[r]=e[r]),t&&delete s[r]);return s}function p(e,t=!0){var r,n,i;const o=l(e);var s;o.verifiableCredential=[...a(e.verifiableCredential),...a(null==(r=e.vp)?void 0:r.verifiableCredential)].filter(c),o.verifiableCredential=o.verifiableCredential.map(e=>f(e,t)),t&&(null==(s=o.vp)||delete s.verifiableCredential),e.iss&&!e.holder&&(o.holder=e.iss,t&&delete o.iss),e.aud&&(o.verifier=[...a(e.verifier),...a(e.aud)].filter(c),o.verifier=[...new Set(o.verifier)],t&&delete o.aud),e.jti&&-1===Object.getOwnPropertyNames(e).indexOf("id")&&(o.id=e.id||e.jti,t&&delete o.jti);const d=[...a(e.type),...a(null==(n=e.vp)?void 0:n.type)].filter(c);var u;o.type=[...new Set(d)],t&&(null==(u=o.vp)||delete u.type);const p=[...a(e.context),...a(e["@context"]),...a(null==(i=e.vp)?void 0:i["@context"])].filter(c);var v;return o["@context"]=[...new Set(p)],t&&(delete o.context,null==(v=o.vp)||delete v["@context"]),e.issuanceDate||!e.iat&&!e.nbf||(o.issuanceDate=new Date(1e3*(e.nbf||e.iat)).toISOString(),t&&(e.nbf?delete o.nbf:delete o.iat)),!e.expirationDate&&e.exp&&(o.expirationDate=new Date(1e3*e.exp).toISOString(),t&&delete o.exp),o.vp&&0===Object.keys(o.vp).length&&t&&delete o.vp,o}function v(t,r=!0){let n;try{n=e(t)}catch(e){throw new TypeError("unknown presentation format")}return{...p(n.payload,r),proof:{type:"JwtProof2020",jwt:t}}}function b(e,t=!0){var r;if("string"==typeof e){if(n.test(e))return v(e,t);{let r;try{r=JSON.parse(e)}catch(e){throw new TypeError("unknown presentation format")}return b(r,t)}}return null!=(r=e.proof)&&r.jwt?{...v(e.proof.jwt,t),proof:e.proof}:{proof:{},...p(e,t)}}function y(e,t=!0){var r,n,i;const o=l({vp:{...e.vp},...e});o.vp=o.vp;const s=[...a(e.context),...a(e["@context"]),...a(null==(r=e.vp)?void 0:r["@context"])].filter(c);o.vp["@context"]=[...new Set(s)],t&&(delete o.context,delete o["@context"]);const d=[...a(e.type),...a(null==(n=e.vp)?void 0:n.type)].filter(c);if(o.vp.type=[...new Set(d)],t&&delete o.type,e.id&&-1===Object.getOwnPropertyNames(e).indexOf("jti")&&(o.jti=e.id,t&&delete o.id),e.issuanceDate&&-1===Object.getOwnPropertyNames(e).indexOf("nbf")){const r=Date.parse(e.issuanceDate);isNaN(r)||(o.nbf=Math.floor(r/1e3),t&&delete o.issuanceDate)}if(e.expirationDate&&-1===Object.getOwnPropertyNames(e).indexOf("exp")){const r=Date.parse(e.expirationDate);isNaN(r)||(o.exp=Math.floor(r/1e3),t&&delete o.expirationDate)}var f;if((o.verifiableCredential||null!=(i=o.vp)&&i.verifiableCredential)&&(o.vp.verifiableCredential=[...a(o.verifiableCredential),...a(null==(f=o.vp)?void 0:f.verifiableCredential)].filter(c).map(e=>{var t;return"object"==typeof e&&null!=(t=e.proof)&&t.jwt?e.proof.jwt:e})),t&&delete o.verifiableCredential,e.holder&&-1===Object.getOwnPropertyNames(e).indexOf("iss")&&"string"==typeof e.holder&&(o.iss=e.holder,t&&delete o.holder),e.verifier){const r=[...a(e.verifier),...a(e.aud)].filter(c);o.aud=[...new Set(r)],t&&delete o.verifier}return o}function w(e){if("string"==typeof e&&!e.match(n))throw new TypeError(`"${e}" is not a valid JWT format`)}function x(e){if("number"==typeof e){if(!(Number.isInteger(e)&&e<1e11))throw new TypeError(`"${e}" is not a unix timestamp in seconds`)}else if("string"==typeof e)x(Math.floor(new Date(e).valueOf()/1e3));else if(!(t=e)||isNaN(t)||"[object Date]"!==Object.prototype.toString.call(t))throw new TypeError(`"${e}" is not a valid time`);var t}function j(e){const t=a(e);if(t.length<1||-1===t.indexOf(i))throw new TypeError(`@context is missing default context "${i}"`)}function g(e){const t=a(e);if(t.length<1||-1===t.indexOf("VerifiableCredential"))throw new TypeError('type is missing default "VerifiableCredential"')}function h(e){const t=a(e);if(t.length<1||-1===t.indexOf("VerifiablePresentation"))throw new TypeError('type is missing default "VerifiablePresentation"')}function O(e){if(0===Object.keys(e).length)throw new TypeError("credentialSubject must not be empty")}const m=function(e,r,n={}){try{return Promise.resolve(t(e,{resolver:r,...n})).then(function(e){return A(e.payload,n),e.verifiablePresentation=b(e.jwt,null==n?void 0:n.removeOriginalFields),T(e.verifiablePresentation),e})}catch(e){return Promise.reject(e)}},S=function(e,r,n={}){try{return Promise.resolve(t(e,{resolver:r,...n})).then(function(e){return e.verifiableCredential=f(e.jwt,null==n?void 0:n.removeOriginalFields),C(e.verifiableCredential),e})}catch(e){return Promise.reject(e)}},D=function(e,t,n={}){try{var i;const o={iat:void 0,...y(e,null==n?void 0:n.removeOriginalFields)};if(n.challenge&&-1===Object.getOwnPropertyNames(o).indexOf("nonce")&&(o.nonce=n.challenge),n.domain){const e=[...a(n.domain),...a(o.aud)].filter(c);o.aud=[...new Set(e)]}return E(o),Promise.resolve(r(o,{...n,issuer:t.did||o.iss||"",signer:t.signer},{...n.header,alg:t.alg||(null==(i=n.header)?void 0:i.alg)||"ES256K"}))}catch(e){return Promise.reject(e)}},P=function(e,t,n={}){try{var i;const o={iat:void 0,...u(e,n.removeOriginalFields)};return N(o),Promise.resolve(r(o,{...n,issuer:t.did||o.iss||"",signer:t.signer},{...n.header,alg:t.alg||(null==(i=n.header)?void 0:i.alg)||"ES256K"}))}catch(e){return Promise.reject(e)}};function N(e){j(e.vc["@context"]),g(e.vc.type),O(e.vc.credentialSubject),e.nbf&&x(e.nbf),e.exp&&x(e.exp)}function C(e){j(e["@context"]),g(e.type),O(e.credentialSubject),e.issuanceDate&&x(e.issuanceDate),e.expirationDate&&x(e.expirationDate)}function E(e){if(j(e.vp["@context"]),h(e.vp.type),e.vp.verifiableCredential&&e.vp.verifiableCredential.length>=1)for(const t of a(e.vp.verifiableCredential))"string"==typeof t?w(t):C(t);e.exp&&x(e.exp)}function T(e){if(j(e["@context"]),h(e.type),e.verifiableCredential&&e.verifiableCredential.length>=1)for(const t of e.verifiableCredential)"string"==typeof t?w(t):C(t);e.expirationDate&&x(e.expirationDate)}function A(e,t){if(t.challenge&&t.challenge!==e.nonce)throw new Error(`Presentation does not contain the mandatory challenge (JWT: nonce) for : ${t.challenge}`);if(t.domain){let r;if(e.aud&&(r=(Array.isArray(e.aud)?e.aud:[e.aud]).find(e=>t.domain===e)),void 0===r)throw new Error(`Presentation does not contain the mandatory domain (JWT: aud) for : ${t.domain}`)}}export{P as createVerifiableCredentialJwt,D as createVerifiablePresentationJwt,f as normalizeCredential,b as normalizePresentation,u as transformCredentialInput,y as transformPresentationInput,C as validateCredentialPayload,N as validateJwtCredentialPayload,E as validateJwtPresentationPayload,T as validatePresentationPayload,S as verifyCredential,m as verifyPresentation,A as verifyPresentationPayloadOptions};
//# sourceMappingURL=index.module.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("did-jwt")):"function"==typeof define&&define.amd?define(["exports","did-jwt"],t):t((e||self).didJwtVc={},e.didJwt)}(this,function(e,t){const n="ES256K",i=/^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/,r="https://www.w3.org/2018/credentials/v1",o="VerifiableCredential",a="VerifiablePresentation",l="JwtProof2020";function c(e){return Array.isArray(e)?e:[e]}function s(e){return Array.isArray(e)?e.map(e=>s(e)):e instanceof Date?new Date(e.getTime()):e&&"object"==typeof e?Object.getOwnPropertyNames(e).reduce((t,n)=>(Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n)),t[n]=s(e[n]),t),Object.create(Object.getPrototypeOf(e))):e}function d(e){return null!=e}function f(e,t=!0){var n,i,a,l,f,u,p;let v=s(e);var y,b,w;"object"==typeof(y=e)&&y.sub&&y.iss&&y.claim&&y.iat&&(v=function(e){const{iat:t,nbf:n,claim:i,vc:a,...l}=e,c={...l,nbf:n||t,vc:{"@context":[r],type:[o],credentialSubject:i}};return a&&(e.issVc=a),c}(e)),v.credentialSubject={...e.credentialSubject,...null==(n=e.vc)?void 0:n.credentialSubject},!e.sub||null!=(i=e.credentialSubject)&&i.id||!v.credentialSubject||(v.credentialSubject.id=e.sub,t&&delete v.sub),t&&(null==(b=v.vc)||delete b.credentialSubject),void 0!==e.issuer&&"object"!=typeof e.issuer||(v.issuer=function(e){if("object"!=typeof e)return e;const t={...e};return Object.keys(t).forEach(e=>void 0===t[e]&&delete t[e]),t}({id:e.iss,...e.issuer}),!t||null!=(w=e.issuer)&&w.id||delete v.iss),!e.id&&e.jti&&(v.id=v.id||v.jti,t&&delete v.jti);const x=[...c(v.type),...c(null==(a=v.vc)?void 0:a.type)].filter(d);var j,h,m,g;v.type=[...new Set(x)],t&&(null==(j=v.vc)||delete j.type),v.evidence=null==(l=e.vc)?void 0:l.evidence,t&&(null==(h=v.vc)||delete h.evidence),v.credentialStatus=null==(f=e.vc)?void 0:f.credentialStatus,t&&(null==(m=v.vc)||delete m.credentialStatus),v.termsOfUse=null==(u=e.vc)?void 0:u.termsOfUse,t&&(null==(g=v.vc)||delete g.termsOfUse);const O=[...c(e.context),...c(e["@context"]),...c(null==(p=e.vc)?void 0:p["@context"])].filter(d);var S;return v["@context"]=[...new Set(O)],t&&(delete v.context,null==(S=v.vc)||delete S["@context"]),e.issuanceDate||!e.iat&&!e.nbf||(v.issuanceDate=new Date(1e3*(e.nbf||e.iat)).toISOString(),t&&(e.nbf?delete v.nbf:delete v.iat)),!e.expirationDate&&e.exp&&(v.expirationDate=new Date(1e3*e.exp).toISOString(),t&&delete v.exp),t&&v.vc&&0===Object.keys(v.vc).length&&delete v.vc,v}function u(e,n=!0){let i;try{i=t.decodeJWT(e)}catch(e){throw new TypeError("unknown credential format")}return{...f(i.payload,n),proof:{type:l,jwt:e}}}function p(e,t=!0){var n;if("string"==typeof e){if(i.test(e))return u(e,t);{let n;try{n=JSON.parse(e)}catch(e){throw new TypeError("unknown credential format")}return p(n,t)}}return null!=(n=e.proof)&&n.jwt?s({...u(e.proof.jwt,t),proof:e.proof}):{proof:{},...f(e,t)}}function v(e,t=!0){var n,i,r;if(Array.isArray(e.credentialSubject))throw Error("credentialSubject of type array not supported");const o=s({vc:{...e.vc},...e});o.vc=o.vc;const a={...e.credentialSubject,...null==(n=e.vc)?void 0:n.credentialSubject};var l;e.sub||(o.sub=null==(l=e.credentialSubject)?void 0:l.id,t&&delete a.id);const f=[...c(e.context),...c(e["@context"]),...c(null==(i=e.vc)?void 0:i["@context"])].filter(d);o.vc["@context"]=[...new Set(f)],t&&(delete o.context,delete o["@context"]);const u=[...c(e.type),...c(null==(r=e.vc)?void 0:r.type)].filter(d);if(o.vc.type=[...new Set(u)],t&&delete o.type,e.id&&-1===Object.getOwnPropertyNames(e).indexOf("jti")&&(o.jti=e.id,t&&delete o.id),e.issuanceDate&&-1===Object.getOwnPropertyNames(e).indexOf("nbf")){const n=Date.parse(e.issuanceDate);isNaN(n)||(o.nbf=Math.floor(n/1e3),t&&delete o.issuanceDate)}if(e.expirationDate&&-1===Object.getOwnPropertyNames(e).indexOf("exp")){const n=Date.parse(e.expirationDate);isNaN(n)||(o.exp=Math.floor(n/1e3),t&&delete o.expirationDate)}var p;e.issuer&&-1===Object.getOwnPropertyNames(e).indexOf("iss")&&("object"==typeof e.issuer?(o.iss=null==(p=e.issuer)?void 0:p.id,t&&(delete o.issuer.id,0===Object.keys(o.issuer).length&&delete o.issuer)):"string"==typeof e.issuer&&(o.iss=e.iss||""+e.issuer,t&&delete o.issuer)),o.vc.credentialSubject=a,t&&delete o.credentialSubject;const v=["evidence","termsOfUse","refreshService","credentialSchema","credentialStatus"];for(const n of v)e[n]&&(o.vc[n]||(o.vc[n]=e[n]),t&&delete o[n]);return o}function y(e,t=!0){var n,i,r;const o=s(e);var a;o.verifiableCredential=[...c(e.verifiableCredential),...c(null==(n=e.vp)?void 0:n.verifiableCredential)].filter(d),o.verifiableCredential=o.verifiableCredential.map(e=>p(e,t)),t&&(null==(a=o.vp)||delete a.verifiableCredential),e.iss&&!e.holder&&(o.holder=e.iss,t&&delete o.iss),e.aud&&(o.verifier=[...c(e.verifier),...c(e.aud)].filter(d),o.verifier=[...new Set(o.verifier)],t&&delete o.aud),e.jti&&-1===Object.getOwnPropertyNames(e).indexOf("id")&&(o.id=e.id||e.jti,t&&delete o.jti);const l=[...c(e.type),...c(null==(i=e.vp)?void 0:i.type)].filter(d);var f;o.type=[...new Set(l)],t&&(null==(f=o.vp)||delete f.type);const u=[...c(e.context),...c(e["@context"]),...c(null==(r=e.vp)?void 0:r["@context"])].filter(d);var v;return o["@context"]=[...new Set(u)],t&&(delete o.context,null==(v=o.vp)||delete v["@context"]),e.issuanceDate||!e.iat&&!e.nbf||(o.issuanceDate=new Date(1e3*(e.nbf||e.iat)).toISOString(),t&&(e.nbf?delete o.nbf:delete o.iat)),!e.expirationDate&&e.exp&&(o.expirationDate=new Date(1e3*e.exp).toISOString(),t&&delete o.exp),o.vp&&0===Object.keys(o.vp).length&&t&&delete o.vp,o}function b(e,n=!0){let i;try{i=t.decodeJWT(e)}catch(e){throw new TypeError("unknown presentation format")}return{...y(i.payload,n),proof:{type:l,jwt:e}}}function w(e,t=!0){var n;if("string"==typeof e){if(i.test(e))return b(e,t);{let n;try{n=JSON.parse(e)}catch(e){throw new TypeError("unknown presentation format")}return w(n,t)}}return null!=(n=e.proof)&&n.jwt?{...b(e.proof.jwt,t),proof:e.proof}:{proof:{},...y(e,t)}}function x(e,t=!0){var n,i,r;const o=s({vp:{...e.vp},...e});o.vp=o.vp;const a=[...c(e.context),...c(e["@context"]),...c(null==(n=e.vp)?void 0:n["@context"])].filter(d);o.vp["@context"]=[...new Set(a)],t&&(delete o.context,delete o["@context"]);const l=[...c(e.type),...c(null==(i=e.vp)?void 0:i.type)].filter(d);if(o.vp.type=[...new Set(l)],t&&delete o.type,e.id&&-1===Object.getOwnPropertyNames(e).indexOf("jti")&&(o.jti=e.id,t&&delete o.id),e.issuanceDate&&-1===Object.getOwnPropertyNames(e).indexOf("nbf")){const n=Date.parse(e.issuanceDate);isNaN(n)||(o.nbf=Math.floor(n/1e3),t&&delete o.issuanceDate)}if(e.expirationDate&&-1===Object.getOwnPropertyNames(e).indexOf("exp")){const n=Date.parse(e.expirationDate);isNaN(n)||(o.exp=Math.floor(n/1e3),t&&delete o.expirationDate)}var f;if((o.verifiableCredential||null!=(r=o.vp)&&r.verifiableCredential)&&(o.vp.verifiableCredential=[...c(o.verifiableCredential),...c(null==(f=o.vp)?void 0:f.verifiableCredential)].filter(d).map(e=>{var t;return"object"==typeof e&&null!=(t=e.proof)&&t.jwt?e.proof.jwt:e})),t&&delete o.verifiableCredential,e.holder&&-1===Object.getOwnPropertyNames(e).indexOf("iss")&&"string"==typeof e.holder&&(o.iss=e.holder,t&&delete o.holder),e.verifier){const n=[...c(e.verifier),...c(e.aud)].filter(d);o.aud=[...new Set(n)],t&&delete o.verifier}return o}function j(e){if("string"==typeof e&&!e.match(i))throw new TypeError(`"${e}" is not a valid JWT format`)}function h(e){if("number"==typeof e){if(!(Number.isInteger(e)&&e<1e11))throw new TypeError(`"${e}" is not a unix timestamp in seconds`)}else if("string"==typeof e)h(Math.floor(new Date(e).valueOf()/1e3));else if(!(t=e)||isNaN(t)||"[object Date]"!==Object.prototype.toString.call(t))throw new TypeError(`"${e}" is not a valid time`);var t}function m(e){const t=c(e);if(t.length<1||-1===t.indexOf(r))throw new TypeError(`@context is missing default context "${r}"`)}function g(e){const t=c(e);if(t.length<1||-1===t.indexOf(o))throw new TypeError(`type is missing default "${o}"`)}function O(e){const t=c(e);if(t.length<1||-1===t.indexOf(a))throw new TypeError(`type is missing default "${a}"`)}function S(e){if(0===Object.keys(e).length)throw new TypeError("credentialSubject must not be empty")}function P(e){m(e.vc["@context"]),g(e.vc.type),S(e.vc.credentialSubject),e.nbf&&h(e.nbf),e.exp&&h(e.exp)}function D(e){m(e["@context"]),g(e.type),S(e.credentialSubject),e.issuanceDate&&h(e.issuanceDate),e.expirationDate&&h(e.expirationDate)}function C(e){if(m(e.vp["@context"]),O(e.vp.type),e.vp.verifiableCredential&&e.vp.verifiableCredential.length>=1)for(const t of c(e.vp.verifiableCredential))"string"==typeof t?j(t):D(t);e.exp&&h(e.exp)}function N(e){if(m(e["@context"]),O(e.type),e.verifiableCredential&&e.verifiableCredential.length>=1)for(const t of e.verifiableCredential)"string"==typeof t?j(t):D(t);e.expirationDate&&h(e.expirationDate)}function T(e,t){if(t.challenge&&t.challenge!==e.nonce)throw new Error(`Presentation does not contain the mandatory challenge (JWT: nonce) for : ${t.challenge}`);if(t.domain){let n;if(e.aud&&(n=(Array.isArray(e.aud)?e.aud:[e.aud]).find(e=>t.domain===e)),void 0===n)throw new Error(`Presentation does not contain the mandatory domain (JWT: aud) for : ${t.domain}`)}}e.createVerifiableCredentialJwt=function(e,i,r={}){try{var o;const a={iat:void 0,...v(e,r.removeOriginalFields)};return P(a),Promise.resolve(t.createJWT(a,{...r,issuer:i.did||a.iss||"",signer:i.signer},{...r.header,alg:i.alg||(null==(o=r.header)?void 0:o.alg)||n}))}catch(e){return Promise.reject(e)}},e.createVerifiablePresentationJwt=function(e,i,r={}){try{var o;const a={iat:void 0,...x(e,null==r?void 0:r.removeOriginalFields)};if(r.challenge&&-1===Object.getOwnPropertyNames(a).indexOf("nonce")&&(a.nonce=r.challenge),r.domain){const e=[...c(r.domain),...c(a.aud)].filter(d);a.aud=[...new Set(e)]}return C(a),Promise.resolve(t.createJWT(a,{...r,issuer:i.did||a.iss||"",signer:i.signer},{...r.header,alg:i.alg||(null==(o=r.header)?void 0:o.alg)||n}))}catch(e){return Promise.reject(e)}},e.normalizeCredential=p,e.normalizePresentation=w,e.transformCredentialInput=v,e.transformPresentationInput=x,e.validateCredentialPayload=D,e.validateJwtCredentialPayload=P,e.validateJwtPresentationPayload=C,e.validatePresentationPayload=N,e.verifyCredential=function(e,n,i={}){try{return Promise.resolve(t.verifyJWT(e,{resolver:n,...i})).then(function(e){return e.verifiableCredential=p(e.jwt,null==i?void 0:i.removeOriginalFields),D(e.verifiableCredential),e})}catch(e){return Promise.reject(e)}},e.verifyPresentation=function(e,n,i={}){try{return Promise.resolve(t.verifyJWT(e,{resolver:n,...i})).then(function(e){return T(e.payload,i),e.verifiablePresentation=w(e.jwt,null==i?void 0:i.removeOriginalFields),N(e.verifiablePresentation),e})}catch(e){return Promise.reject(e)}},e.verifyPresentationPayloadOptions=T});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("did-jwt")):"function"==typeof define&&define.amd?define(["exports","did-jwt"],t):t((e||self).didJwtVc={},e.didJwt)}(this,function(e,t){const n="ES256K",r=/^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/,i="https://www.w3.org/2018/credentials/v1",o="VerifiableCredential",a="VerifiablePresentation",l="JwtProof2020",c=["evidence","termsOfUse","refreshService","credentialSchema","credentialStatus"];function s(e){return Array.isArray(e)?e:[e]}function d(e){return Array.isArray(e)?e.map(e=>d(e)):e instanceof Date?new Date(e.getTime()):e&&"object"==typeof e?Object.getOwnPropertyNames(e).reduce((t,n)=>(Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n)),t[n]=d(e[n]),t),Object.create(Object.getPrototypeOf(e))):e}function f(e){return null!=e}function u(e,t=!0){var n,r,a,l;let u=d(e);var p,v,y;"object"==typeof(p=e)&&p.sub&&p.iss&&p.claim&&p.iat&&(u=function(e){const{iat:t,nbf:n,claim:r,vc:a,...l}=e,c={...l,nbf:n||t,vc:{"@context":[i],type:[o],credentialSubject:r}};return a&&(e.issVc=a),c}(e)),u.credentialSubject={...e.credentialSubject,...null==(n=e.vc)?void 0:n.credentialSubject},!e.sub||null!=(r=e.credentialSubject)&&r.id||!u.credentialSubject||(u.credentialSubject.id=e.sub,t&&delete u.sub),t&&(null==(v=u.vc)||delete v.credentialSubject),void 0!==e.issuer&&"object"!=typeof e.issuer||(u.issuer=function(e){if("object"!=typeof e)return e;const t={...e};return Object.keys(t).forEach(e=>void 0===t[e]&&delete t[e]),t}({id:e.iss,...e.issuer}),!t||null!=(y=e.issuer)&&y.id||delete u.iss),!e.id&&e.jti&&(u.id=u.id||u.jti,t&&delete u.jti);const b=[...s(u.type),...s(null==(a=u.vc)?void 0:a.type)].filter(f);var w;u.type=[...new Set(b)],t&&(null==(w=u.vc)||delete w.type);for(const n of c)e.vc&&e.vc[n]&&(u[n]||(u[n]=e.vc[n]),t&&delete u.vc[n]);const x=[...s(e.context),...s(e["@context"]),...s(null==(l=e.vc)?void 0:l["@context"])].filter(f);var j;return u["@context"]=[...new Set(x)],t&&(delete u.context,null==(j=u.vc)||delete j["@context"]),e.issuanceDate||!e.iat&&!e.nbf||(u.issuanceDate=new Date(1e3*(e.nbf||e.iat)).toISOString(),t&&(e.nbf?delete u.nbf:delete u.iat)),!e.expirationDate&&e.exp&&(u.expirationDate=new Date(1e3*e.exp).toISOString(),t&&delete u.exp),t&&u.vc&&0===Object.keys(u.vc).length&&delete u.vc,u}function p(e,n=!0){let r;try{r=t.decodeJWT(e)}catch(e){throw new TypeError("unknown credential format")}return{...u(r.payload,n),proof:{type:l,jwt:e}}}function v(e,t=!0){var n;if("string"==typeof e){if(r.test(e))return p(e,t);{let n;try{n=JSON.parse(e)}catch(e){throw new TypeError("unknown credential format")}return v(n,t)}}return null!=(n=e.proof)&&n.jwt?d({...p(e.proof.jwt,t),proof:e.proof}):{proof:{},...u(e,t)}}function y(e,t=!0){var n,r,i;if(Array.isArray(e.credentialSubject))throw Error("credentialSubject of type array not supported");const o=d({vc:{...e.vc},...e});o.vc=o.vc;const a={...e.credentialSubject,...null==(n=e.vc)?void 0:n.credentialSubject};var l;e.sub||(o.sub=null==(l=e.credentialSubject)?void 0:l.id,t&&delete a.id);const u=[...s(e.context),...s(e["@context"]),...s(null==(r=e.vc)?void 0:r["@context"])].filter(f);o.vc["@context"]=[...new Set(u)],t&&(delete o.context,delete o["@context"]);const p=[...s(e.type),...s(null==(i=e.vc)?void 0:i.type)].filter(f);if(o.vc.type=[...new Set(p)],t&&delete o.type,e.id&&-1===Object.getOwnPropertyNames(e).indexOf("jti")&&(o.jti=e.id,t&&delete o.id),e.issuanceDate&&-1===Object.getOwnPropertyNames(e).indexOf("nbf")){const n=Date.parse(e.issuanceDate);isNaN(n)||(o.nbf=Math.floor(n/1e3),t&&delete o.issuanceDate)}if(e.expirationDate&&-1===Object.getOwnPropertyNames(e).indexOf("exp")){const n=Date.parse(e.expirationDate);isNaN(n)||(o.exp=Math.floor(n/1e3),t&&delete o.expirationDate)}var v;e.issuer&&-1===Object.getOwnPropertyNames(e).indexOf("iss")&&("object"==typeof e.issuer?(o.iss=null==(v=e.issuer)?void 0:v.id,t&&(delete o.issuer.id,0===Object.keys(o.issuer).length&&delete o.issuer)):"string"==typeof e.issuer&&(o.iss=e.iss||""+e.issuer,t&&delete o.issuer)),o.vc.credentialSubject=a,t&&delete o.credentialSubject;for(const n of c)e[n]&&(o.vc[n]||(o.vc[n]=e[n]),t&&delete o[n]);return o}function b(e,t=!0){var n,r,i;const o=d(e);var a;o.verifiableCredential=[...s(e.verifiableCredential),...s(null==(n=e.vp)?void 0:n.verifiableCredential)].filter(f),o.verifiableCredential=o.verifiableCredential.map(e=>v(e,t)),t&&(null==(a=o.vp)||delete a.verifiableCredential),e.iss&&!e.holder&&(o.holder=e.iss,t&&delete o.iss),e.aud&&(o.verifier=[...s(e.verifier),...s(e.aud)].filter(f),o.verifier=[...new Set(o.verifier)],t&&delete o.aud),e.jti&&-1===Object.getOwnPropertyNames(e).indexOf("id")&&(o.id=e.id||e.jti,t&&delete o.jti);const l=[...s(e.type),...s(null==(r=e.vp)?void 0:r.type)].filter(f);var c;o.type=[...new Set(l)],t&&(null==(c=o.vp)||delete c.type);const u=[...s(e.context),...s(e["@context"]),...s(null==(i=e.vp)?void 0:i["@context"])].filter(f);var p;return o["@context"]=[...new Set(u)],t&&(delete o.context,null==(p=o.vp)||delete p["@context"]),e.issuanceDate||!e.iat&&!e.nbf||(o.issuanceDate=new Date(1e3*(e.nbf||e.iat)).toISOString(),t&&(e.nbf?delete o.nbf:delete o.iat)),!e.expirationDate&&e.exp&&(o.expirationDate=new Date(1e3*e.exp).toISOString(),t&&delete o.exp),o.vp&&0===Object.keys(o.vp).length&&t&&delete o.vp,o}function w(e,n=!0){let r;try{r=t.decodeJWT(e)}catch(e){throw new TypeError("unknown presentation format")}return{...b(r.payload,n),proof:{type:l,jwt:e}}}function x(e,t=!0){var n;if("string"==typeof e){if(r.test(e))return w(e,t);{let n;try{n=JSON.parse(e)}catch(e){throw new TypeError("unknown presentation format")}return x(n,t)}}return null!=(n=e.proof)&&n.jwt?{...w(e.proof.jwt,t),proof:e.proof}:{proof:{},...b(e,t)}}function j(e,t=!0){var n,r,i;const o=d({vp:{...e.vp},...e});o.vp=o.vp;const a=[...s(e.context),...s(e["@context"]),...s(null==(n=e.vp)?void 0:n["@context"])].filter(f);o.vp["@context"]=[...new Set(a)],t&&(delete o.context,delete o["@context"]);const l=[...s(e.type),...s(null==(r=e.vp)?void 0:r.type)].filter(f);if(o.vp.type=[...new Set(l)],t&&delete o.type,e.id&&-1===Object.getOwnPropertyNames(e).indexOf("jti")&&(o.jti=e.id,t&&delete o.id),e.issuanceDate&&-1===Object.getOwnPropertyNames(e).indexOf("nbf")){const n=Date.parse(e.issuanceDate);isNaN(n)||(o.nbf=Math.floor(n/1e3),t&&delete o.issuanceDate)}if(e.expirationDate&&-1===Object.getOwnPropertyNames(e).indexOf("exp")){const n=Date.parse(e.expirationDate);isNaN(n)||(o.exp=Math.floor(n/1e3),t&&delete o.expirationDate)}var c;if((o.verifiableCredential||null!=(i=o.vp)&&i.verifiableCredential)&&(o.vp.verifiableCredential=[...s(o.verifiableCredential),...s(null==(c=o.vp)?void 0:c.verifiableCredential)].filter(f).map(e=>{var t;return"object"==typeof e&&null!=(t=e.proof)&&t.jwt?e.proof.jwt:e})),t&&delete o.verifiableCredential,e.holder&&-1===Object.getOwnPropertyNames(e).indexOf("iss")&&"string"==typeof e.holder&&(o.iss=e.holder,t&&delete o.holder),e.verifier){const n=[...s(e.verifier),...s(e.aud)].filter(f);o.aud=[...new Set(n)],t&&delete o.verifier}return o}function h(e){if("string"==typeof e&&!e.match(r))throw new TypeError(`"${e}" is not a valid JWT format`)}function g(e){if("number"==typeof e){if(!(Number.isInteger(e)&&e<1e11))throw new TypeError(`"${e}" is not a unix timestamp in seconds`)}else if("string"==typeof e)g(Math.floor(new Date(e).valueOf()/1e3));else if(!(t=e)||isNaN(t)||"[object Date]"!==Object.prototype.toString.call(t))throw new TypeError(`"${e}" is not a valid time`);var t}function m(e){const t=s(e);if(t.length<1||-1===t.indexOf(i))throw new TypeError(`@context is missing default context "${i}"`)}function O(e){const t=s(e);if(t.length<1||-1===t.indexOf(o))throw new TypeError(`type is missing default "${o}"`)}function S(e){const t=s(e);if(t.length<1||-1===t.indexOf(a))throw new TypeError(`type is missing default "${a}"`)}function P(e){if(0===Object.keys(e).length)throw new TypeError("credentialSubject must not be empty")}function D(e){m(e.vc["@context"]),O(e.vc.type),P(e.vc.credentialSubject),e.nbf&&g(e.nbf),e.exp&&g(e.exp)}function C(e){m(e["@context"]),O(e.type),P(e.credentialSubject),e.issuanceDate&&g(e.issuanceDate),e.expirationDate&&g(e.expirationDate)}function N(e){if(m(e.vp["@context"]),S(e.vp.type),e.vp.verifiableCredential&&e.vp.verifiableCredential.length>=1)for(const t of s(e.vp.verifiableCredential))"string"==typeof t?h(t):C(t);e.exp&&g(e.exp)}function T(e){if(m(e["@context"]),S(e.type),e.verifiableCredential&&e.verifiableCredential.length>=1)for(const t of e.verifiableCredential)"string"==typeof t?h(t):C(t);e.expirationDate&&g(e.expirationDate)}function J(e,t){if(t.challenge&&t.challenge!==e.nonce)throw new Error(`Presentation does not contain the mandatory challenge (JWT: nonce) for : ${t.challenge}`);if(t.domain){let n;if(e.aud&&(n=(Array.isArray(e.aud)?e.aud:[e.aud]).find(e=>t.domain===e)),void 0===n)throw new Error(`Presentation does not contain the mandatory domain (JWT: aud) for : ${t.domain}`)}}e.createVerifiableCredentialJwt=function(e,r,i={}){try{var o;const a={iat:void 0,...y(e,i.removeOriginalFields)};return D(a),Promise.resolve(t.createJWT(a,{...i,issuer:r.did||a.iss||"",signer:r.signer},{...i.header,alg:r.alg||(null==(o=i.header)?void 0:o.alg)||n}))}catch(e){return Promise.reject(e)}},e.createVerifiablePresentationJwt=function(e,r,i={}){try{var o;const a={iat:void 0,...j(e,null==i?void 0:i.removeOriginalFields)};if(i.challenge&&-1===Object.getOwnPropertyNames(a).indexOf("nonce")&&(a.nonce=i.challenge),i.domain){const e=[...s(i.domain),...s(a.aud)].filter(f);a.aud=[...new Set(e)]}return N(a),Promise.resolve(t.createJWT(a,{...i,issuer:r.did||a.iss||"",signer:r.signer},{...i.header,alg:r.alg||(null==(o=i.header)?void 0:o.alg)||n}))}catch(e){return Promise.reject(e)}},e.normalizeCredential=v,e.normalizePresentation=x,e.transformCredentialInput=y,e.transformPresentationInput=j,e.validateCredentialPayload=C,e.validateJwtCredentialPayload=D,e.validateJwtPresentationPayload=N,e.validatePresentationPayload=T,e.verifyCredential=function(e,n,r={}){try{return Promise.resolve(t.verifyJWT(e,{resolver:n,...r})).then(function(e){return e.verifiableCredential=v(e.jwt,null==r?void 0:r.removeOriginalFields),C(e.verifiableCredential),e})}catch(e){return Promise.reject(e)}},e.verifyPresentation=function(e,n,r={}){try{return Promise.resolve(t.verifyJWT(e,{resolver:n,...r})).then(function(e){return J(e.payload,r),e.verifiablePresentation=x(e.jwt,null==r?void 0:r.removeOriginalFields),T(e.verifiablePresentation),e})}catch(e){return Promise.reject(e)}},e.verifyPresentationPayloadOptions=J});
//# sourceMappingURL=index.umd.js.map
{
"name": "did-jwt-vc",
"version": "2.1.7",
"version": "2.1.8",
"description": "Create and verify W3C Verifiable Credentials and Presentations in JWT format",

@@ -51,24 +51,24 @@ "source": "src/index.ts",

"devDependencies": {
"@babel/core": "7.14.6",
"@babel/preset-env": "7.14.7",
"@babel/preset-typescript": "7.14.5",
"@semantic-release/changelog": "5.0.1",
"@semantic-release/git": "9.0.0",
"@types/faker": "5.5.7",
"@types/jest": "27.0.1",
"@babel/core": "7.16.0",
"@babel/preset-env": "7.16.0",
"@babel/preset-typescript": "7.16.0",
"@semantic-release/changelog": "6.0.1",
"@semantic-release/git": "10.0.1",
"@types/faker": "5.5.9",
"@types/jest": "27.0.2",
"@types/node": "15.12.4",
"@typescript-eslint/eslint-plugin": "4.28.3",
"@typescript-eslint/parser": "4.28.3",
"@typescript-eslint/eslint-plugin": "4.33.0",
"@typescript-eslint/parser": "4.33.0",
"codecov": "3.8.2",
"eslint": "7.31.0",
"eslint": "7.32.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-jest": "24.3.6",
"eslint-plugin-prettier": "3.4.0",
"eslint-plugin-jest": "24.7.0",
"eslint-plugin-prettier": "4.0.0",
"ethr-did": "2.1.4",
"faker": "5.5.3",
"jest": "27.0.6",
"microbundle": "^0.13.3",
"prettier": "2.3.2",
"semantic-release": "17.4.4",
"typescript": "4.3.5"
"jest": "27.3.1",
"microbundle": "0.13.3",
"prettier": "2.4.1",
"semantic-release": "18.0.0",
"typescript": "4.4.4"
},

@@ -75,0 +75,0 @@ "engines": {

@@ -18,2 +18,10 @@ import {

/*
* Additional W3C VC fields:
* These are defined as optional top-level properties in the W3C spec but are not mapped to top-level JWT names,
* so they should be moved inside the "vc" object when transforming to a JWT.
* Conversely, they should be moved out of the "vc" object when transforming from a JWT to W3C JSON.
*/
const additionalPropNames = ['evidence', 'termsOfUse', 'refreshService', 'credentialSchema', 'credentialStatus']
// eslint-disable-next-line @typescript-eslint/no-explicit-any

@@ -115,17 +123,13 @@ export function asArray(arg: any | any[]): any[] {

result.evidence = input.vc?.evidence
if (removeOriginalFields) {
delete result.vc?.evidence
for (const prop of additionalPropNames) {
if (input.vc && input.vc[prop]) {
if (!result[prop]) {
result[prop] = input.vc[prop]
}
if (removeOriginalFields) {
delete result.vc[prop]
}
}
}
result.credentialStatus = input.vc?.credentialStatus
if (removeOriginalFields) {
delete result.vc?.credentialStatus
}
result.termsOfUse = input.vc?.termsOfUse
if (removeOriginalFields) {
delete result.vc?.termsOfUse
}
const contextArray: string[] = [

@@ -318,6 +322,2 @@ ...asArray(input.context),

// additional W3C VC fields to map:
// these may exist at the top-level of a W3C credential, but should be moved inside vc when transforming to JWT
const additionalPropNames = ['evidence', 'termsOfUse', 'refreshService', 'credentialSchema', 'credentialStatus']
for (const prop of additionalPropNames) {

@@ -324,0 +324,0 @@ if (input[prop]) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc