did-jwt-vc
Advanced tools
Comparing version 2.1.5 to 2.1.6
@@ -0,1 +1,8 @@ | ||
## [2.1.6](https://github.com/decentralized-identity/did-jwt-vc/compare/2.1.5...2.1.6) (2021-07-22) | ||
### Bug Fixes | ||
* **build:** revert back to microbundle and module output ([d28729a](https://github.com/decentralized-identity/did-jwt-vc/commit/d28729abb906e817e6822dd38abdbdd3f89f1c66)), closes [#84](https://github.com/decentralized-identity/did-jwt-vc/issues/84) | ||
## [2.1.5](https://github.com/decentralized-identity/did-jwt-vc/compare/2.1.4...2.1.5) (2021-07-21) | ||
@@ -2,0 +9,0 @@ |
@@ -0,0 +0,0 @@ import { VerifiableCredential, JWT, JwtPresentationPayload, JwtCredentialPayload, CredentialPayload, W3CCredential, Verifiable, PresentationPayload, W3CPresentation } from './types'; |
@@ -0,0 +0,0 @@ import { Resolvable } from 'did-resolver'; |
181
lib/index.js
@@ -1,179 +0,2 @@ | ||
import { createJWT, verifyJWT } from 'did-jwt'; | ||
import { JWT_ALG } from './constants'; | ||
import * as validators from './validators'; | ||
import { transformCredentialInput, transformPresentationInput, normalizeCredential, normalizePresentation, asArray, notEmpty, } from './converters'; | ||
export { transformCredentialInput, transformPresentationInput, normalizeCredential, normalizePresentation, }; | ||
/** | ||
* Creates a VerifiableCredential given a `CredentialPayload` or `JwtCredentialPayload` and an `Issuer`. | ||
* | ||
* This method transforms the payload into the [JWT encoding](https://www.w3.org/TR/vc-data-model/#jwt-encoding) | ||
* described in the [W3C VC spec](https://www.w3.org/TR/vc-data-model) and then validated to conform to the minimum spec | ||
* required spec. | ||
* | ||
* The `issuer` is then used to assign an algorithm, override the `iss` field of the payload and then sign the JWT. | ||
* | ||
* @param payload `CredentialPayload` or `JwtCredentialPayload` | ||
* @param issuer `Issuer` the DID, signer and algorithm that will sign the token | ||
* @return a `Promise` that resolves to the JWT encoded verifiable credential or rejects with `TypeError` if the | ||
* `payload` is not W3C compliant | ||
*/ | ||
export async function createVerifiableCredentialJwt(payload, issuer, options = {}) { | ||
var _a; | ||
const parsedPayload = { | ||
iat: undefined, | ||
...transformCredentialInput(payload, options.removeOriginalFields), | ||
}; | ||
validateJwtCredentialPayload(parsedPayload); | ||
return createJWT(parsedPayload, { | ||
issuer: issuer.did || parsedPayload.iss || '', | ||
signer: issuer.signer, | ||
}, { | ||
...options.header, | ||
alg: issuer.alg || ((_a = options.header) === null || _a === void 0 ? void 0 : _a.alg) || JWT_ALG, | ||
}); | ||
} | ||
/** | ||
* Creates a VerifiablePresentation JWT given a `PresentationPayload` or `JwtPresentationPayload` and an `Issuer`. | ||
* | ||
* This method transforms the payload into the [JWT encoding](https://www.w3.org/TR/vc-data-model/#jwt-encoding) | ||
* described in the [W3C VC spec](https://www.w3.org/TR/vc-data-model) and then validated to conform to the minimum spec | ||
* required spec. | ||
* | ||
* The `holder` is then used to assign an algorithm, override the `iss` field of the payload and then sign the JWT. | ||
* | ||
* @param payload `PresentationPayload` or `JwtPresentationPayload` | ||
* @param holder `Issuer` of the Presentation JWT (holder of the VC), signer and algorithm that will sign the token | ||
* @param options `CreatePresentationOptions` allows to pass additional values to the resulting JWT payload | ||
* @return a `Promise` that resolves to the JWT encoded verifiable presentation or rejects with `TypeError` if the | ||
* `payload` is not W3C compliant | ||
*/ | ||
export async function createVerifiablePresentationJwt(payload, holder, options = {}) { | ||
var _a; | ||
const parsedPayload = { | ||
iat: undefined, | ||
...transformPresentationInput(payload, options === null || options === void 0 ? void 0 : options.removeOriginalFields), | ||
}; | ||
// add challenge to nonce | ||
if (options.challenge && Object.getOwnPropertyNames(parsedPayload).indexOf('nonce') === -1) { | ||
parsedPayload.nonce = options.challenge; | ||
} | ||
// add domain to audience. | ||
if (options.domain) { | ||
const audience = [...asArray(options.domain), ...asArray(parsedPayload.aud)].filter(notEmpty); | ||
parsedPayload.aud = [...new Set(audience)]; | ||
} | ||
validateJwtPresentationPayload(parsedPayload); | ||
return createJWT(parsedPayload, { | ||
issuer: holder.did || parsedPayload.iss || '', | ||
signer: holder.signer, | ||
}, { | ||
...options.header, | ||
alg: holder.alg || ((_a = options.header) === null || _a === void 0 ? void 0 : _a.alg) || JWT_ALG, | ||
}); | ||
} | ||
export function validateJwtCredentialPayload(payload) { | ||
validators.validateContext(payload.vc['@context']); | ||
validators.validateVcType(payload.vc.type); | ||
validators.validateCredentialSubject(payload.vc.credentialSubject); | ||
if (payload.nbf) | ||
validators.validateTimestamp(payload.nbf); | ||
if (payload.exp) | ||
validators.validateTimestamp(payload.exp); | ||
} | ||
export function validateCredentialPayload(payload) { | ||
validators.validateContext(payload['@context']); | ||
validators.validateVcType(payload.type); | ||
validators.validateCredentialSubject(payload.credentialSubject); | ||
if (payload.issuanceDate) | ||
validators.validateTimestamp(payload.issuanceDate); | ||
if (payload.expirationDate) | ||
validators.validateTimestamp(payload.expirationDate); | ||
} | ||
export function validateJwtPresentationPayload(payload) { | ||
validators.validateContext(payload.vp['@context']); | ||
validators.validateVpType(payload.vp.type); | ||
// empty credential array is allowed | ||
if (payload.vp.verifiableCredential && payload.vp.verifiableCredential.length >= 1) { | ||
for (const vc of asArray(payload.vp.verifiableCredential)) { | ||
if (typeof vc === 'string') { | ||
validators.validateJwtFormat(vc); | ||
} | ||
else { | ||
validateCredentialPayload(vc); | ||
} | ||
} | ||
} | ||
if (payload.exp) | ||
validators.validateTimestamp(payload.exp); | ||
} | ||
export function validatePresentationPayload(payload) { | ||
validators.validateContext(payload['@context']); | ||
validators.validateVpType(payload.type); | ||
// empty credential array is allowed | ||
if (payload.verifiableCredential && payload.verifiableCredential.length >= 1) { | ||
for (const vc of payload.verifiableCredential) { | ||
if (typeof vc === 'string') { | ||
validators.validateJwtFormat(vc); | ||
} | ||
else { | ||
validateCredentialPayload(vc); | ||
} | ||
} | ||
} | ||
if (payload.expirationDate) | ||
validators.validateTimestamp(payload.expirationDate); | ||
} | ||
/** | ||
* Verifies and validates a VerifiableCredential that is encoded as a JWT according to the W3C spec. | ||
* | ||
* @return a `Promise` that resolves to a `VerifiedCredential` or rejects with `TypeError` if the input is not | ||
* W3C compliant | ||
* @param vc the credential to be verified. Currently only the JWT encoding is supported by this library | ||
* @param resolver a configured `Resolver` (or an implementation of `Resolvable`) that can provide the DID document of the JWT issuer | ||
*/ | ||
export async function verifyCredential(vc, resolver, options = {}) { | ||
const verified = await verifyJWT(vc, { resolver, ...options }); | ||
verified.verifiableCredential = normalizeCredential(verified.jwt, options === null || options === void 0 ? void 0 : options.removeOriginalFields); | ||
validateCredentialPayload(verified.verifiableCredential); | ||
return verified; | ||
} | ||
/** | ||
* Verifies that the given JwtPresentationPayload contains the appropriate options from VerifyPresentationOptions | ||
* | ||
* @param payload the JwtPresentationPayload to verify against | ||
* @param options the VerifyPresentationOptions that contain the optional values to verify. | ||
* @throws {Error} If VerifyPresentationOptions are not satisfied | ||
*/ | ||
export function verifyPresentationPayloadOptions(payload, options) { | ||
if (options.challenge && options.challenge !== payload.nonce) { | ||
throw new Error(`Presentation does not contain the mandatory challenge (JWT: nonce) for : ${options.challenge}`); | ||
} | ||
if (options.domain) { | ||
// aud might be array | ||
let matchedAudience; | ||
if (payload.aud) { | ||
const audArray = Array.isArray(payload.aud) ? payload.aud : [payload.aud]; | ||
matchedAudience = audArray.find((item) => options.domain === item); | ||
} | ||
if (typeof matchedAudience === 'undefined') { | ||
throw new Error(`Presentation does not contain the mandatory domain (JWT: aud) for : ${options.domain}`); | ||
} | ||
} | ||
} | ||
/** | ||
* Verifies and validates a VerifiablePresentation that is encoded as a JWT according to the W3C spec. | ||
* | ||
* @return a `Promise` that resolves to a `VerifiedPresentation` or rejects with `TypeError` if the input is | ||
* not W3C compliant or the VerifyPresentationOptions are not satisfied. | ||
* @param presentation the presentation to be verified. Currently only the JWT encoding is supported by this library | ||
* @param resolver a configured `Resolver` or an implementation of `Resolvable` that can provide the DID document of the JWT issuer (presentation holder) | ||
* @param options optional verification options that need to be satisfied | ||
*/ | ||
export async function verifyPresentation(presentation, resolver, options = {}) { | ||
const verified = await verifyJWT(presentation, { resolver, ...options }); | ||
verifyPresentationPayloadOptions(verified.payload, options); | ||
verified.verifiablePresentation = normalizePresentation(verified.jwt, options === null || options === void 0 ? void 0 : options.removeOriginalFields); | ||
validatePresentationPayload(verified.verifiablePresentation); | ||
return verified; | ||
} | ||
//# sourceMappingURL=index.js.map | ||
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,{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,{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; | ||
//# sourceMappingURL=index.js.map |
import { Signer, JWTVerified, JWTHeader } from 'did-jwt'; | ||
export declare const JWT_ALG = "ES256K"; | ||
export declare const DID_FORMAT: RegExp; | ||
export declare const JWT_FORMAT: RegExp; | ||
export declare const DEFAULT_CONTEXT = "https://www.w3.org/2018/credentials/v1"; | ||
export declare const DEFAULT_VC_TYPE = "VerifiableCredential"; | ||
export declare const DEFAULT_VP_TYPE = "VerifiablePresentation"; | ||
export declare const DEFAULT_JWT_PROOF_TYPE = "JwtProof2020"; | ||
export declare type JwtCredentialSubject = Record<string, any>; | ||
@@ -3,0 +10,0 @@ export interface CredentialStatus { |
@@ -0,0 +0,0 @@ import { JwtCredentialSubject, DateType } from './types'; |
{ | ||
"name": "did-jwt-vc", | ||
"version": "2.1.5", | ||
"version": "2.1.6", | ||
"description": "Create and verify W3C Verifiable Credentials and Presentations in JWT format", | ||
"source": "src/index.ts", | ||
"main": "./lib/index.js", | ||
"module": "./lib/index.module.js", | ||
"types": "./lib/index.d.ts", | ||
@@ -15,3 +16,3 @@ "files": [ | ||
"test:ci": "jest --coverage && codecov", | ||
"build:js": "tsc", | ||
"build:js": "microbundle", | ||
"build": "yarn lint && yarn build:js && yarn test", | ||
@@ -69,2 +70,3 @@ "format": "prettier --write \"src/**/*.ts\"", | ||
"jest": "27.0.6", | ||
"microbundle": "^0.13.3", | ||
"prettier": "2.3.2", | ||
@@ -71,0 +73,0 @@ "semantic-release": "17.4.4", |
@@ -12,3 +12,3 @@ import { EthrDID } from 'ethr-did' | ||
import { Resolvable } from 'did-resolver' | ||
import { DEFAULT_VC_TYPE, DEFAULT_VP_TYPE, DEFAULT_CONTEXT } from '../constants' | ||
import { DEFAULT_VC_TYPE, DEFAULT_VP_TYPE, DEFAULT_CONTEXT } from '../types' | ||
import { | ||
@@ -15,0 +15,0 @@ validateContext, |
import * as validators from '../validators' | ||
import { DEFAULT_CONTEXT, DEFAULT_VC_TYPE, DEFAULT_VP_TYPE } from '../constants' | ||
import { DEFAULT_CONTEXT, DEFAULT_VC_TYPE, DEFAULT_VP_TYPE } from '../types' | ||
@@ -4,0 +4,0 @@ export const DID_A = 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198' |
@@ -6,2 +6,6 @@ import { | ||
JwtCredentialPayload, | ||
JWT_FORMAT, | ||
DEFAULT_JWT_PROOF_TYPE, | ||
DEFAULT_CONTEXT, | ||
DEFAULT_VC_TYPE, | ||
CredentialPayload, | ||
@@ -14,3 +18,2 @@ W3CCredential, | ||
import { decodeJWT } from 'did-jwt' | ||
import { JWT_FORMAT, DEFAULT_JWT_PROOF_TYPE, DEFAULT_CONTEXT, DEFAULT_VC_TYPE } from './constants' | ||
@@ -17,0 +20,0 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any |
import { createJWT, verifyJWT } from 'did-jwt' | ||
import { Resolvable } from 'did-resolver' | ||
import { JWT_ALG } from './constants' | ||
import * as validators from './validators' | ||
@@ -23,2 +22,3 @@ import { | ||
VerifyCredentialOptions, | ||
JWT_ALG, | ||
} from './types' | ||
@@ -25,0 +25,0 @@ import { |
import { Signer, JWTVerified, JWTHeader } from 'did-jwt' | ||
export const JWT_ALG = 'ES256K' | ||
export const DID_FORMAT = /^did:([a-zA-Z0-9_]+):([:[a-zA-Z0-9_.-]+)(\/[^#]*)?(#.*)?$/ | ||
export const JWT_FORMAT = /^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/ | ||
export const DEFAULT_CONTEXT = 'https://www.w3.org/2018/credentials/v1' | ||
export const DEFAULT_VC_TYPE = 'VerifiableCredential' | ||
export const DEFAULT_VP_TYPE = 'VerifiablePresentation' | ||
export const DEFAULT_JWT_PROOF_TYPE = 'JwtProof2020' | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
@@ -4,0 +12,0 @@ export type JwtCredentialSubject = Record<string, any> |
@@ -1,2 +0,2 @@ | ||
import { DEFAULT_CONTEXT, DEFAULT_VC_TYPE, DEFAULT_VP_TYPE, JWT_FORMAT } from './constants' | ||
import { DEFAULT_CONTEXT, DEFAULT_VC_TYPE, DEFAULT_VP_TYPE, JWT_FORMAT } from './types' | ||
import { JwtCredentialSubject, DateType } from './types' | ||
@@ -3,0 +3,0 @@ import { VerifiableCredential } from '.' |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
449995
22
28
3564
3