did-jwt-vc
Advanced tools
Comparing version 0.1.3 to 0.1.4
import { VerifiableCredentialPayload, Issuer, PresentationPayload } from './types'; | ||
import { DIDDocument } from 'did-resolver'; | ||
export { Issuer, VerifiableCredentialPayload, PresentationPayload, }; | ||
export { Issuer, VerifiableCredentialPayload, PresentationPayload }; | ||
interface Resolvable { | ||
@@ -5,0 +5,0 @@ resolve: (did: string) => Promise<DIDDocument | null>; |
@@ -1,2 +0,2 @@ | ||
var e=require("did-jwt"),t=/^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/,r="https://www.w3.org/2018/credentials/v1",n="VerifiableCredential",i="VerifiablePresentation";function o(e){if(!e.match(t))throw new TypeError('"'+e+'" is not a valid JWT format')}function a(e){if(!(Number.isInteger(e)&&e<1e11))throw new TypeError('"'+e+'" is not a unix timestamp in seconds')}function s(e){if(e.length<1||!e.includes(r))throw new TypeError('@context is missing default context "'+r+'"')}function c(e){s(e.vc["@context"]),function(e){if(e.length<1||!e.includes(n))throw new TypeError('type is missing default "'+n+'"')}(e.vc.type),function(t){if(0===Object.keys(e.vc.credentialSubject).length)throw new TypeError("credentialSubject must not be empty")}(),e.nbf&&a(e.nbf),e.exp&&a(e.exp)}function l(e){if(s(e.vp["@context"]),function(e){if(e.length<1||!e.includes(i))throw new TypeError('type is missing default "'+i+'"')}(e.vp.type),e.vp.verifiableCredential.length<1)throw new TypeError("vp.verifiableCredential must not be empty");for(var t=0,r=e.vp.verifiableCredential;t<r.length;t+=1)o(r[t]);e.exp&&a(e.exp)}exports.verifyPresentation=function(t,r){try{return Promise.resolve(e.verifyJWT(t,{resolver:r})).then(function(e){return l(e.payload),e})}catch(e){return Promise.reject(e)}},exports.verifyCredential=function(t,i){try{return Promise.resolve(e.verifyJWT(t,{resolver:i})).then(function(e){var t;return(t=e.payload)instanceof Object&&t.sub&&t.iss&&t.claim&&t.iat&&(e.payload=function(e){var t=e.iat,i=e.nbf,o=e.vc,a=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&-1===t.indexOf(n)&&(r[n]=e[n]);return r}(e,["iat","nbf","claim","vc"]),s=Object.assign({},a,{nbf:i||t,vc:{"@context":[r],type:[n],credentialSubject:e.claim}});return o&&(e.issVc=o),s}(e.payload)),c(e.payload),e})}catch(e){return Promise.reject(e)}},exports.createPresentation=function(t,r){try{return l(t),Promise.resolve(e.createJWT(t,{issuer:r.did,signer:r.signer,alg:"ES256K-R"}))}catch(e){return Promise.reject(e)}},exports.createVerifiableCredential=function(t,r){try{return c(t),Promise.resolve(e.createJWT(t,{issuer:r.did,signer:r.signer,alg:"ES256K-R"}))}catch(e){return Promise.reject(e)}},exports.validateVerifiableCredentialAttributes=c,exports.validatePresentationAttributes=l; | ||
var e=require("did-jwt"),t=/^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+\/=]*$/,r="https://www.w3.org/2018/credentials/v1",n="VerifiableCredential",i="VerifiablePresentation";function o(e){if(!e.match(t))throw new TypeError('"'+e+'" is not a valid JWT format')}function a(e){if(!(Number.isInteger(e)&&e<1e11))throw new TypeError('"'+e+'" is not a unix timestamp in seconds')}function s(e){if(e.length<1||!e.includes(r))throw new TypeError('@context is missing default context "'+r+'"')}function c(e){s(e.vc["@context"]),function(e){if(e.length<1||!e.includes(n))throw new TypeError('type is missing default "'+n+'"')}(e.vc.type),function(t){if(0===Object.keys(e.vc.credentialSubject).length)throw new TypeError("credentialSubject must not be empty")}(),e.nbf&&a(e.nbf),e.exp&&a(e.exp)}function l(e){if(s(e.vp["@context"]),function(e){if(e.length<1||!e.includes(i))throw new TypeError('type is missing default "'+i+'"')}(e.vp.type),e.vp.verifiableCredential.length<1)throw new TypeError("vp.verifiableCredential must not be empty");for(var t=0,r=e.vp.verifiableCredential;t<r.length;t+=1)o(r[t]);e.exp&&a(e.exp)}exports.verifyPresentation=function(t,r){try{return Promise.resolve(e.verifyJWT(t,{resolver:r})).then(function(e){return l(e.payload),e})}catch(e){return Promise.reject(e)}},exports.verifyCredential=function(t,i){try{return Promise.resolve(e.verifyJWT(t,{resolver:i})).then(function(e){var t;return(t=e.payload)instanceof Object&&t.sub&&t.iss&&t.claim&&t.iat&&(e.payload=function(e){var t=e.iat,i=e.nbf,o=e.vc,a=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&-1===t.indexOf(n)&&(r[n]=e[n]);return r}(e,["iat","nbf","claim","vc"]),s=Object.assign({},a,{nbf:i||t,vc:{"@context":[r],type:[n],credentialSubject:e.claim}});return o&&(e.issVc=o),s}(e.payload)),c(e.payload),e})}catch(e){return Promise.reject(e)}},exports.createPresentation=function(t,r){try{return l(t),Promise.resolve(e.createJWT(t,{issuer:r.did,signer:r.signer,alg:r.alg||"ES256K-R"}))}catch(e){return Promise.reject(e)}},exports.createVerifiableCredential=function(t,r){try{return c(t),Promise.resolve(e.createJWT(t,{issuer:r.did,signer:r.signer,alg:r.alg||"ES256K-R"}))}catch(e){return Promise.reject(e)}},exports.validateVerifiableCredentialAttributes=c,exports.validatePresentationAttributes=l; | ||
//# sourceMappingURL=index.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.didJwtVc={},e.didJwt)}(this,function(e,t){var r=/^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/,n="https://www.w3.org/2018/credentials/v1",i="VerifiableCredential",o="VerifiablePresentation";function a(e){if(!e.match(r))throw new TypeError('"'+e+'" is not a valid JWT format')}function c(e){if(!(Number.isInteger(e)&&e<1e11))throw new TypeError('"'+e+'" is not a unix timestamp in seconds')}function s(e){if(e.length<1||!e.includes(n))throw new TypeError('@context is missing default context "'+n+'"')}function f(e){s(e.vc["@context"]),function(e){if(e.length<1||!e.includes(i))throw new TypeError('type is missing default "'+i+'"')}(e.vc.type),function(t){if(0===Object.keys(e.vc.credentialSubject).length)throw new TypeError("credentialSubject must not be empty")}(),e.nbf&&c(e.nbf),e.exp&&c(e.exp)}function l(e){if(s(e.vp["@context"]),function(e){if(e.length<1||!e.includes(o))throw new TypeError('type is missing default "'+o+'"')}(e.vp.type),e.vp.verifiableCredential.length<1)throw new TypeError("vp.verifiableCredential must not be empty");for(var t=0,r=e.vp.verifiableCredential;t<r.length;t+=1)a(r[t]);e.exp&&c(e.exp)}e.verifyPresentation=function(e,r){try{return Promise.resolve(t.verifyJWT(e,{resolver:r})).then(function(e){return l(e.payload),e})}catch(e){return Promise.reject(e)}},e.verifyCredential=function(e,r){try{return Promise.resolve(t.verifyJWT(e,{resolver:r})).then(function(e){var t;return(t=e.payload)instanceof Object&&t.sub&&t.iss&&t.claim&&t.iat&&(e.payload=function(e){var t=e.iat,r=e.nbf,o=e.vc,a=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&-1===t.indexOf(n)&&(r[n]=e[n]);return r}(e,["iat","nbf","claim","vc"]),c=Object.assign({},a,{nbf:r||t,vc:{"@context":[n],type:[i],credentialSubject:e.claim}});return o&&(e.issVc=o),c}(e.payload)),f(e.payload),e})}catch(e){return Promise.reject(e)}},e.createPresentation=function(e,r){try{return l(e),Promise.resolve(t.createJWT(e,{issuer:r.did,signer:r.signer,alg:"ES256K-R"}))}catch(e){return Promise.reject(e)}},e.createVerifiableCredential=function(e,r){try{return f(e),Promise.resolve(t.createJWT(e,{issuer:r.did,signer:r.signer,alg:"ES256K-R"}))}catch(e){return Promise.reject(e)}},e.validateVerifiableCredentialAttributes=f,e.validatePresentationAttributes=l}); | ||
!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.didJwtVc={},e.didJwt)}(this,function(e,t){var r=/^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+\/=]*$/,n="https://www.w3.org/2018/credentials/v1",i="VerifiableCredential",o="VerifiablePresentation";function a(e){if(!e.match(r))throw new TypeError('"'+e+'" is not a valid JWT format')}function c(e){if(!(Number.isInteger(e)&&e<1e11))throw new TypeError('"'+e+'" is not a unix timestamp in seconds')}function s(e){if(e.length<1||!e.includes(n))throw new TypeError('@context is missing default context "'+n+'"')}function f(e){s(e.vc["@context"]),function(e){if(e.length<1||!e.includes(i))throw new TypeError('type is missing default "'+i+'"')}(e.vc.type),function(t){if(0===Object.keys(e.vc.credentialSubject).length)throw new TypeError("credentialSubject must not be empty")}(),e.nbf&&c(e.nbf),e.exp&&c(e.exp)}function l(e){if(s(e.vp["@context"]),function(e){if(e.length<1||!e.includes(o))throw new TypeError('type is missing default "'+o+'"')}(e.vp.type),e.vp.verifiableCredential.length<1)throw new TypeError("vp.verifiableCredential must not be empty");for(var t=0,r=e.vp.verifiableCredential;t<r.length;t+=1)a(r[t]);e.exp&&c(e.exp)}e.verifyPresentation=function(e,r){try{return Promise.resolve(t.verifyJWT(e,{resolver:r})).then(function(e){return l(e.payload),e})}catch(e){return Promise.reject(e)}},e.verifyCredential=function(e,r){try{return Promise.resolve(t.verifyJWT(e,{resolver:r})).then(function(e){var t;return(t=e.payload)instanceof Object&&t.sub&&t.iss&&t.claim&&t.iat&&(e.payload=function(e){var t=e.iat,r=e.nbf,o=e.vc,a=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&-1===t.indexOf(n)&&(r[n]=e[n]);return r}(e,["iat","nbf","claim","vc"]),c=Object.assign({},a,{nbf:r||t,vc:{"@context":[n],type:[i],credentialSubject:e.claim}});return o&&(e.issVc=o),c}(e.payload)),f(e.payload),e})}catch(e){return Promise.reject(e)}},e.createPresentation=function(e,r){try{return l(e),Promise.resolve(t.createJWT(e,{issuer:r.did,signer:r.signer,alg:r.alg||"ES256K-R"}))}catch(e){return Promise.reject(e)}},e.createVerifiableCredential=function(e,r){try{return f(e),Promise.resolve(t.createJWT(e,{issuer:r.did,signer:r.signer,alg:r.alg||"ES256K-R"}))}catch(e){return Promise.reject(e)}},e.validateVerifiableCredentialAttributes=f,e.validatePresentationAttributes=l}); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -35,3 +35,4 @@ import { Signer } from 'did-jwt'; | ||
signer: Signer; | ||
alg: string; | ||
} | ||
//# sourceMappingURL=types.d.ts.map |
{ | ||
"name": "did-jwt-vc", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Create and verify W3C Verifiable Credentials and Presentations in JWT format", | ||
@@ -18,5 +18,10 @@ "main": "lib/index.js", | ||
"test": "jest", | ||
"build": "microbundle" | ||
"build": "npm run format && npm test && npm run build:js", | ||
"build:js": "microbundle", | ||
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"", | ||
"lint": "tslint -p tsconfig.json", | ||
"prepare": "npm run build", | ||
"prepublishOnly": "npm test && npm run lint" | ||
}, | ||
"author": "", | ||
"author": "mi-xu", | ||
"license": "ISC", | ||
@@ -23,0 +28,0 @@ "dependencies": { |
@@ -90,3 +90,8 @@ # did-jwt-vc | ||
const resolver = new Resolver(getResolver()) | ||
// see also https://github.com/decentralized-identity/ethr-did-resolver#multi-network-configuration | ||
const providerConfig = { | ||
rpcUrl: 'https://mainnet.infura.io/v3/<YOUR Infura.io PROJECT ID>', | ||
registry: '0xdca7ef03e98e0dc2b855be647c39abe984fcf21b' | ||
} | ||
const resolver = new Resolver(getResolver(providerConfig)) | ||
``` | ||
@@ -93,0 +98,0 @@ |
@@ -18,8 +18,4 @@ import EthrDID from 'ethr-did' | ||
const mockValidateJwtFormat = <jest.Mock<typeof validateJwtFormat>>( | ||
validateJwtFormat | ||
) | ||
const mockValidateTimestamp = <jest.Mock<typeof validateTimestamp>>( | ||
validateTimestamp | ||
) | ||
const mockValidateJwtFormat = <jest.Mock<typeof validateJwtFormat>>validateJwtFormat | ||
const mockValidateTimestamp = <jest.Mock<typeof validateTimestamp>>validateTimestamp | ||
@@ -79,6 +75,3 @@ const mockValidateContext = <jest.Mock<typeof validateContext>>validateContext | ||
it('creates a valid Verifiable Credential JWT with required fields', async () => { | ||
const vcJwt = await createVerifiableCredential( | ||
verifiableCredentialPayload, | ||
did | ||
) | ||
const vcJwt = await createVerifiableCredential(verifiableCredentialPayload, did) | ||
const decodedVc = await decodeJWT(vcJwt) | ||
@@ -89,6 +82,3 @@ const { iat, ...payload } = decodedVc.payload | ||
it('creates a valid Verifiable Credential JWT with extra optional fields', async () => { | ||
const vcJwt = await createVerifiableCredential( | ||
{ ...verifiableCredentialPayload, extra: 42 }, | ||
did | ||
) | ||
const vcJwt = await createVerifiableCredential({ ...verifiableCredentialPayload, extra: 42 }, did) | ||
const decodedVc = await decodeJWT(vcJwt) | ||
@@ -100,11 +90,5 @@ const { iat, ...payload } = decodedVc.payload | ||
await createVerifiableCredential(verifiableCredentialPayload, did) | ||
expect(mockValidateTimestamp).toHaveBeenCalledWith( | ||
verifiableCredentialPayload.nbf | ||
) | ||
expect(mockValidateContext).toHaveBeenCalledWith( | ||
verifiableCredentialPayload.vc['@context'] | ||
) | ||
expect(mockValidateVcType).toHaveBeenCalledWith( | ||
verifiableCredentialPayload.vc.type | ||
) | ||
expect(mockValidateTimestamp).toHaveBeenCalledWith(verifiableCredentialPayload.nbf) | ||
expect(mockValidateContext).toHaveBeenCalledWith(verifiableCredentialPayload.vc['@context']) | ||
expect(mockValidateVcType).toHaveBeenCalledWith(verifiableCredentialPayload.vc.type) | ||
expect(mockValidateCredentialSubject).toHaveBeenCalledWith(verifiableCredentialPayload.vc.credentialSubject) | ||
@@ -114,6 +98,3 @@ }) | ||
const timestamp = Math.floor(new Date().getTime()) | ||
await createVerifiableCredential( | ||
{ ...verifiableCredentialPayload, exp: timestamp }, | ||
did | ||
) | ||
await createVerifiableCredential({ ...verifiableCredentialPayload, exp: timestamp }, did) | ||
expect(mockValidateTimestamp).toHaveBeenCalledWith(timestamp) | ||
@@ -131,6 +112,3 @@ }) | ||
it('creates a valid Presentation JWT with extra optional fields', async () => { | ||
const presentationJwt = await createPresentation( | ||
{ ...presentationPayload, extra: 42 }, | ||
did | ||
) | ||
const presentationJwt = await createPresentation({ ...presentationPayload, extra: 42 }, did) | ||
const decodedPresentation = await decodeJWT(presentationJwt) | ||
@@ -142,5 +120,3 @@ const { iat, ...payload } = decodedPresentation.payload | ||
await createPresentation(presentationPayload, did) | ||
expect(mockValidateContext).toHaveBeenCalledWith( | ||
presentationPayload.vp['@context'] | ||
) | ||
expect(mockValidateContext).toHaveBeenCalledWith(presentationPayload.vp['@context']) | ||
expect(mockValidateVpType).toHaveBeenCalledWith(presentationPayload.vp.type) | ||
@@ -187,3 +163,4 @@ for (const vc of presentationPayload.vp.verifiableCredential) { | ||
// tslint:disable-next-line: max-line-length | ||
const LEGACY_FORMAT_ATTESTATION = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1NjM4MjQ4MDksImV4cCI6OTk2Mjk1MDI4Miwic3ViIjoiZGlkOmV0aHI6MHhmMTIzMmY4NDBmM2FkN2QyM2ZjZGFhODRkNmM2NmRhYzI0ZWZiMTk4IiwiY2xhaW0iOnsiZGVncmVlIjp7InR5cGUiOiJCYWNoZWxvckRlZ3JlZSIsIm5hbWUiOiJCYWNjYWxhdXLDqWF0IGVuIG11c2lxdWVzIG51bcOpcmlxdWVzIn19LCJpc3MiOiJkaWQ6ZXRocjoweGYzYmVhYzMwYzQ5OGQ5ZTI2ODY1ZjM0ZmNhYTU3ZGJiOTM1YjBkNzQifQ.OsKmaxoA2pt3_ixWK61BaMDc072g2PymBX_CCUSo-irvtIRUP5qBCcerhpASe5hOcTg5nNpNg0XYXnqyF9I4XwE' | ||
const LEGACY_FORMAT_ATTESTATION = | ||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1NjM4MjQ4MDksImV4cCI6OTk2Mjk1MDI4Miwic3ViIjoiZGlkOmV0aHI6MHhmMTIzMmY4NDBmM2FkN2QyM2ZjZGFhODRkNmM2NmRhYzI0ZWZiMTk4IiwiY2xhaW0iOnsiZGVncmVlIjp7InR5cGUiOiJCYWNoZWxvckRlZ3JlZSIsIm5hbWUiOiJCYWNjYWxhdXLDqWF0IGVuIG11c2lxdWVzIG51bcOpcmlxdWVzIn19LCJpc3MiOiJkaWQ6ZXRocjoweGYzYmVhYzMwYzQ5OGQ5ZTI2ODY1ZjM0ZmNhYTU3ZGJiOTM1YjBkNzQifQ.OsKmaxoA2pt3_ixWK61BaMDc072g2PymBX_CCUSo-irvtIRUP5qBCcerhpASe5hOcTg5nNpNg0XYXnqyF9I4XwE' | ||
const verified = await verifyCredential(LEGACY_FORMAT_ATTESTATION, resolver) | ||
@@ -215,2 +192,2 @@ expect(verified.payload.vc).toBeDefined() | ||
}) | ||
}) | ||
}) |
@@ -19,15 +19,9 @@ import * as validators from '../validators' | ||
it('does not throw if the value is a valid unix timestamp in seconds', () => { | ||
expect(() => | ||
validators.validateTimestamp(Math.floor(new Date().getTime() / 1000)) | ||
).not.toThrow() | ||
expect(() => validators.validateTimestamp(Math.floor(new Date().getTime() / 1000))).not.toThrow() | ||
}) | ||
it('throws a TypeError if the value is a millisecond timestamp', () => { | ||
expect(() => validators.validateTimestamp(new Date().getTime())).toThrow( | ||
TypeError | ||
) | ||
expect(() => validators.validateTimestamp(new Date().getTime())).toThrow(TypeError) | ||
}) | ||
it('throws a TypeError if the value is not an integer', () => { | ||
expect(() => | ||
validators.validateTimestamp(new Date().getTime() / 1000) | ||
).toThrow(TypeError) | ||
expect(() => validators.validateTimestamp(new Date().getTime() / 1000)).toThrow(TypeError) | ||
}) | ||
@@ -41,9 +35,3 @@ }) | ||
it('does not throw if the value contains the default context and some user-defined ones', () => { | ||
expect(() => | ||
validators.validateContext([ | ||
DEFAULT_CONTEXT, | ||
EXTRA_CONTEXT_A, | ||
EXTRA_CONTEXT_B | ||
]) | ||
).not.toThrow() | ||
expect(() => validators.validateContext([DEFAULT_CONTEXT, EXTRA_CONTEXT_A, EXTRA_CONTEXT_B])).not.toThrow() | ||
}) | ||
@@ -54,5 +42,3 @@ it('throws a TypeError the value contains no contexts', () => { | ||
it('throws a TypeError the value is missing the default context', () => { | ||
expect(() => | ||
validators.validateContext([EXTRA_CONTEXT_A, EXTRA_CONTEXT_B]) | ||
).toThrow(TypeError) | ||
expect(() => validators.validateContext([EXTRA_CONTEXT_A, EXTRA_CONTEXT_B])).toThrow(TypeError) | ||
}) | ||
@@ -66,5 +52,3 @@ }) | ||
it('does not throw if the value contains the default type and some user-defined ones', () => { | ||
expect(() => | ||
validators.validateVcType([DEFAULT_VC_TYPE, EXTRA_TYPE_A, EXTRA_TYPE_B]) | ||
).not.toThrow() | ||
expect(() => validators.validateVcType([DEFAULT_VC_TYPE, EXTRA_TYPE_A, EXTRA_TYPE_B])).not.toThrow() | ||
}) | ||
@@ -75,5 +59,3 @@ it('throws a TypeError the value contains no types', () => { | ||
it('throws a TypeError the value is missing the default type', () => { | ||
expect(() => | ||
validators.validateVcType([EXTRA_TYPE_A, EXTRA_TYPE_B]) | ||
).toThrow(TypeError) | ||
expect(() => validators.validateVcType([EXTRA_TYPE_A, EXTRA_TYPE_B])).toThrow(TypeError) | ||
}) | ||
@@ -87,5 +69,3 @@ }) | ||
it('does not throw if the value contains the default type and some user-defined ones', () => { | ||
expect(() => | ||
validators.validateVpType([DEFAULT_VP_TYPE, EXTRA_TYPE_A, EXTRA_TYPE_B]) | ||
).not.toThrow() | ||
expect(() => validators.validateVpType([DEFAULT_VP_TYPE, EXTRA_TYPE_A, EXTRA_TYPE_B])).not.toThrow() | ||
}) | ||
@@ -96,5 +76,3 @@ it('throws a TypeError the value contains no types', () => { | ||
it('throws a TypeError the value is missing the default type', () => { | ||
expect(() => | ||
validators.validateVpType([EXTRA_TYPE_A, EXTRA_TYPE_B]) | ||
).toThrow(TypeError) | ||
expect(() => validators.validateVpType([EXTRA_TYPE_A, EXTRA_TYPE_B])).toThrow(TypeError) | ||
}) | ||
@@ -114,5 +92,3 @@ }) | ||
it('does not throw if the value is an object with at least one attribute', () => { | ||
expect(() => | ||
validators.validateCredentialSubject({ name: 'test' }) | ||
).not.toThrow() | ||
expect(() => validators.validateCredentialSubject({ name: 'test' })).not.toThrow() | ||
}) | ||
@@ -119,0 +95,0 @@ it('throws a TypeError if the value is an object with no attributes', () => { |
import { createJWT, verifyJWT } from 'did-jwt' | ||
import { JWT_ALG, DEFAULT_CONTEXT, DEFAULT_VC_TYPE } from './constants' | ||
import * as validators from './validators' | ||
import { | ||
VerifiableCredentialPayload, | ||
Issuer, | ||
PresentationPayload | ||
} from './types' | ||
import { VerifiableCredentialPayload, Issuer, PresentationPayload } from './types' | ||
import { DIDDocument } from 'did-resolver' | ||
export { | ||
Issuer, | ||
VerifiableCredentialPayload, | ||
PresentationPayload, | ||
} | ||
export { Issuer, VerifiableCredentialPayload, PresentationPayload } | ||
@@ -29,10 +21,7 @@ interface Resolvable { | ||
signer: issuer.signer, | ||
alg: JWT_ALG | ||
alg: issuer.alg || JWT_ALG | ||
}) | ||
} | ||
export async function createPresentation( | ||
payload: PresentationPayload, | ||
issuer: Issuer | ||
): Promise<string> { | ||
export async function createPresentation(payload: PresentationPayload, issuer: Issuer): Promise<string> { | ||
validatePresentationAttributes(payload) | ||
@@ -42,9 +31,7 @@ return createJWT(payload, { | ||
signer: issuer.signer, | ||
alg: JWT_ALG | ||
alg: issuer.alg || JWT_ALG | ||
}) | ||
} | ||
export function validateVerifiableCredentialAttributes( | ||
payload: VerifiableCredentialPayload | ||
): void { | ||
export function validateVerifiableCredentialAttributes(payload: VerifiableCredentialPayload): void { | ||
validators.validateContext(payload.vc['@context']) | ||
@@ -76,3 +63,3 @@ validators.validateVcType(payload.vc.type) | ||
const { iat, nbf, claim, vc, ...rest } = payload | ||
const result:VerifiableCredentialPayload = { | ||
const result: VerifiableCredentialPayload = { | ||
...rest, | ||
@@ -92,3 +79,3 @@ nbf: nbf ? nbf : iat, | ||
const verified = await verifyJWT(vc, { resolver }) | ||
if(isLegacyAttestationFormat(verified.payload)) { | ||
if (isLegacyAttestationFormat(verified.payload)) { | ||
verified.payload = attestationToVcFormat(verified.payload) | ||
@@ -104,2 +91,2 @@ } | ||
return verified | ||
} | ||
} |
@@ -41,2 +41,3 @@ import { Signer } from 'did-jwt' | ||
signer: Signer | ||
alg: string | ||
} |
@@ -1,8 +0,2 @@ | ||
import { | ||
DID_FORMAT, | ||
DEFAULT_CONTEXT, | ||
DEFAULT_VC_TYPE, | ||
DEFAULT_VP_TYPE, | ||
JWT_FORMAT | ||
} from './constants' | ||
import { DID_FORMAT, DEFAULT_CONTEXT, DEFAULT_VC_TYPE, DEFAULT_VP_TYPE, JWT_FORMAT } from './constants' | ||
import { CredentialSubject } from './types' | ||
@@ -31,5 +25,3 @@ | ||
if (value.length < 1 || !value.includes(DEFAULT_CONTEXT)) { | ||
throw new TypeError( | ||
`@context is missing default context "${DEFAULT_CONTEXT}"` | ||
) | ||
throw new TypeError(`@context is missing default context "${DEFAULT_CONTEXT}"`) | ||
} | ||
@@ -36,0 +28,0 @@ } |
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 not supported yet
Sorry, the diff of this file is not supported yet
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
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
81125
1
171
0
513