did-jwt-vc
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -5,3 +5,4 @@ export declare const JWT_ALG = "ES256K-R"; | ||
export declare const DEFAULT_CONTEXT = "https://www.w3.org/2018/credentials/v1"; | ||
export declare const DEFAULT_TYPE = "VerifiableCredential"; | ||
export declare const DEFAULT_VC_TYPE = "VerifiableCredential"; | ||
export declare const DEFAULT_VP_TYPE = "VerifiablePresentation"; | ||
//# sourceMappingURL=constants.d.ts.map |
import { VerifiableCredentialPayload, Issuer, PresentationPayload } from './types'; | ||
import { DIDDocument } from 'did-resolver'; | ||
export { Issuer, VerifiableCredentialPayload, PresentationPayload, }; | ||
interface Resolvable { | ||
@@ -12,3 +13,2 @@ resolve: (did: string) => Promise<DIDDocument | null>; | ||
export declare function verifyPresentation(presentation: string, resolver: Resolvable): Promise<any>; | ||
export {}; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -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";function i(e){if(!e.match(t))throw new TypeError('"'+e+'" is not a valid JWT format')}function o(e){if(!(Number.isInteger(e)&&e<1e11))throw new TypeError('"'+e+'" is not a unix timestamp in seconds')}function a(e){if(e.length<1||!e.includes(r))throw new TypeError('@context is missing default context "'+r+'"')}function c(e){if(e.length<1||!e.includes(n))throw new TypeError('type is missing default "'+n+'"')}function s(e){a(e.vc["@context"]),c(e.vc.type),function(t){if(0===Object.keys(e.vc.credentialSubject).length)throw new TypeError("credentialSubject must not be empty")}(),e.nbf&&o(e.nbf),e.exp&&o(e.exp)}function l(e){if(a(e.vp["@context"]),c(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)i(r[t]);e.exp&&o(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"]),c=Object.assign({},a,{nbf:i||t,vc:{"@context":[r],type:[n],credentialSubject:e.claim}});return o&&(e.issVc=o),c}(e.payload)),s(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 s(t),Promise.resolve(e.createJWT(t,{issuer:r.did,signer:r.signer,alg:"ES256K-R"}))}catch(e){return Promise.reject(e)}},exports.validateVerifiableCredentialAttributes=s,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:"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; | ||
//# 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";function o(e){if(!e.match(r))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 c(e){if(e.length<1||!e.includes(n))throw new TypeError('@context is missing default context "'+n+'"')}function s(e){if(e.length<1||!e.includes(i))throw new TypeError('type is missing default "'+i+'"')}function f(e){c(e.vc["@context"]),s(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 u(e){if(c(e.vp["@context"]),s(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)}e.verifyPresentation=function(e,r){try{return Promise.resolve(t.verifyJWT(e,{resolver:r})).then(function(e){return u(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 u(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=u}); | ||
!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}); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -5,4 +5,5 @@ import { CredentialSubject } from './types'; | ||
export declare function validateContext(value: string[]): void; | ||
export declare function validateType(value: string[]): void; | ||
export declare function validateVcType(value: string[]): void; | ||
export declare function validateVpType(value: string[]): void; | ||
export declare function validateCredentialSubject(value: CredentialSubject): void; | ||
//# sourceMappingURL=validators.d.ts.map |
{ | ||
"name": "did-jwt-vc", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Create and verify W3C Verifiable Credentials and Presentations in JWT format", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -20,3 +20,3 @@ # did-jwt-vc | ||
```typescript | ||
import EthrDID from 'ethr-did' | ||
import * as EthrDID from 'ethr-did' | ||
import { Issuer } from 'did-jwt-vc' | ||
@@ -58,3 +58,3 @@ | ||
console.log(vcJwt) | ||
// eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1Njk5NDg1NDUsInN1YiI6IjB4NDM1ZGYzZWRhNTcxNTRjZjhjZjc5MjYwNzk4ODFmMjkxMmY1NGRiNCIsIm5iZiI6MTU2Mjk1MDI4MiwidmMiOnsiQGNvbnRleHQiOlsiaHR0cHM6Ly93d3cudzMub3JnLzIwMTgvY3JlZGVudGlhbHMvdjEiXSwidHlwZSI6WyJWZXJpZmlhYmxlQ3JlZGVudGlhbCJdLCJjcmVkZW50aWFsU3ViamVjdCI6eyJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2NhbGF1csOpYXQgZW4gbXVzaXF1ZXMgbnVtw6lyaXF1ZXMifX19LCJpc3MiOiJkaWQ6ZXRocjoweGYxMjMyZjg0MGYzYWQ3ZDIzZmNkYWE4NGQ2YzY2ZGFjMjRlZmIxOTgifQ.RynzSF4IqC85-DxRHwUyaagfxjDVV3_WnSl1sA2SYkYEvPLDrK6pgeXVkHCUDOdPiGlMuj2RDbt_yuIPtm1E7gE | ||
// eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1ODI1NDc1OTMsInN1YiI6ImRpZDpldGhyOjB4NDM1ZGYzZWRhNTcxNTRjZjhjZjc5MjYwNzk4ODFmMjkxMmY1NGRiNCIsIm5iZiI6MTU2Mjk1MDI4MiwidmMiOnsiQGNvbnRleHQiOlsiaHR0cHM6Ly93d3cudzMub3JnLzIwMTgvY3JlZGVudGlhbHMvdjEiXSwidHlwZSI6WyJWZXJpZmlhYmxlQ3JlZGVudGlhbCJdLCJjcmVkZW50aWFsU3ViamVjdCI6eyJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2NhbGF1csOpYXQgZW4gbXVzaXF1ZXMgbnVtw6lyaXF1ZXMifX19LCJpc3MiOiJkaWQ6ZXRocjoweGYxMjMyZjg0MGYzYWQ3ZDIzZmNkYWE4NGQ2YzY2ZGFjMjRlZmIxOTgifQ.ljTuUW6bcsoBQksMo5l8eFImVdOA-ew993B4ret_p9A8j2DLQ60CQmqB14NnN5XxD0d_glLRs1Myc_LBJjnuNwE | ||
``` | ||
@@ -72,3 +72,3 @@ | ||
'@context': ['https://www.w3.org/2018/credentials/v1'], | ||
type: ['VerifiableCredential'], | ||
type: ['VerifiablePresentation'], | ||
verifiableCredential: [vcJwt] | ||
@@ -80,3 +80,3 @@ } | ||
console.log(vpJwt) | ||
// eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1Njk5NDg1NDUsInZwIj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mpudU53RSJdfSwiaXNzIjoiZGlkOmV0aHI6MHhmMTIzMmY4NDBmM2FkN2QyM2ZjZGFhODRkNmM2NmRhYzI0ZWZiMTk4In0.cFyO-xPMdj0Hg1DaCkm30hzcVcYdnDdgyxXLZr9NAJNMUzZ6naacuWNGdZGuU0ZDwmgpUMUqIzMqFFRmge0R8QA | ||
``` | ||
@@ -107,24 +107,25 @@ | ||
/* | ||
{ payload: | ||
{ iat: 1569948545, | ||
sub: '0x435df3eda57154cf8cf7926079881f2912f54db4', | ||
nbf: 1562950282, | ||
vc: | ||
{ '@context': [Array], | ||
type: [Array], | ||
credentialSubject: [Object] }, | ||
iss: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198' }, | ||
doc: | ||
{ '@context': 'https://w3id.org/did/v1', | ||
id: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198', | ||
publicKey: [ [Object] ], | ||
authentication: [ [Object] ] }, | ||
issuer: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198', | ||
signer: | ||
{ id: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198#owner', | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198', | ||
ethereumAddress: '0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198' }, | ||
jwt: | ||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1Njk5NDg1NDUsInN1YiI6IjB4NDM1ZGYzZWRhNTcxNTRjZjhjZjc5MjYwNzk4ODFmMjkxMmY1NGRiNCIsIm5iZiI6MTU2Mjk1MDI4MiwidmMiOnsiQGNvbnRleHQiOlsiaHR0cHM6Ly93d3cudzMub3JnLzIwMTgvY3JlZGVudGlhbHMvdjEiXSwidHlwZSI6WyJWZXJpZmlhYmxlQ3JlZGVudGlhbCJdLCJjcmVkZW50aWFsU3ViamVjdCI6eyJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2NhbGF1csOpYXQgZW4gbXVzaXF1ZXMgbnVtw6lyaXF1ZXMifX19LCJpc3MiOiJkaWQ6ZXRocjoweGYxMjMyZjg0MGYzYWQ3ZDIzZmNkYWE4NGQ2YzY2ZGFjMjRlZmIxOTgifQ.RynzSF4IqC85-DxRHwUyaagfxjDVV3_WnSl1sA2SYkYEvPLDrK6pgeXVkHCUDOdPiGlMuj2RDbt_yuIPtm1E7gE' } | ||
{ | ||
payload: { | ||
iat: 1582547593, | ||
sub: 'did:ethr:0x435df3eda57154cf8cf7926079881f2912f54db4', | ||
nbf: 1562950282, | ||
vc: { '@context': [Array], type: [Array], credentialSubject: [Object] }, | ||
iss: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198' | ||
}, | ||
doc: { | ||
'@context': 'https://w3id.org/did/v1', | ||
id: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198', | ||
publicKey: [ [Object] ], | ||
authentication: [ [Object] ] | ||
}, | ||
issuer: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198', | ||
signer: { | ||
id: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198#owner', | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198', | ||
ethereumAddress: '0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198' | ||
}, | ||
jwt: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1ODI1NDc1OTMsInN1YiI6ImRpZDpldGhyOjB4NDM1ZGYzZWRhNTcxNTRjZjhjZjc5MjYwNzk4ODFmMjkxMmY1NGRiNCIsIm5iZiI6MTU2Mjk1MDI4MiwidmMiOnsiQGNvbnRleHQiOlsiaHR0cHM6Ly93d3cudzMub3JnLzIwMTgvY3JlZGVudGlhbHMvdjEiXSwidHlwZSI6WyJWZXJpZmlhYmxlQ3JlZGVudGlhbCJdLCJjcmVkZW50aWFsU3ViamVjdCI6eyJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2NhbGF1csOpYXQgZW4gbXVzaXF1ZXMgbnVtw6lyaXF1ZXMifX19LCJpc3MiOiJkaWQ6ZXRocjoweGYxMjMyZjg0MGYzYWQ3ZDIzZmNkYWE4NGQ2YzY2ZGFjMjRlZmIxOTgifQ.ljTuUW6bcsoBQksMo5l8eFImVdOA-ew993B4ret_p9A8j2DLQ60CQmqB14NnN5XxD0d_glLRs1Myc_LBJjnuNwE' | ||
} | ||
*/ | ||
@@ -143,23 +144,28 @@ ``` | ||
/* | ||
{ payload: | ||
{ iat: 1569948545, | ||
vp: | ||
{ '@context': [Array], | ||
{ | ||
payload: { | ||
iat: 1582547593, | ||
vp: { | ||
'@context': [Array], | ||
type: [Array], | ||
verifiableCredential: [Array] }, | ||
iss: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198' }, | ||
doc: | ||
{ '@context': 'https://w3id.org/did/v1', | ||
id: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198', | ||
publicKey: [ [Object] ], | ||
authentication: [ [Object] ] }, | ||
issuer: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198', | ||
signer: | ||
{ id: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198#owner', | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198', | ||
ethereumAddress: '0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198' }, | ||
jwt: | ||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1Njk5NDg1NDUsInZwIjp7IkBjb250ZXh0IjpbImh0dHBzOi8vd3d3LnczLm9yZy8yMDE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} | ||
verifiableCredential: [Array] | ||
}, | ||
iss: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198' | ||
}, | ||
doc: { | ||
'@context': 'https://w3id.org/did/v1', | ||
id: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198', | ||
publicKey: [ [Object] ], | ||
authentication: [ [Object] ] | ||
}, | ||
issuer: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198', | ||
signer: { | ||
id: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198#owner', | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198', | ||
ethereumAddress: '0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198' | ||
}, | ||
jwt: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1ODI1NDc1OTMsInZwIjp7IkBjb250ZXh0IjpbImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL3YxIl0sInR5cGUiOlsiVmVyaWZpYWJsZVByZXNlbnRhdGlvbiJdLCJ2ZXJpZmlhYmxlQ3JlZGVudGlhbCI6WyJleUowZVhBaU9pSktWMVFpTENKaGJHY2lPaUpGVXpJMU5rc3RVaUo5LmV5SnBZWFFpT2pFMU9ESTFORGMxT1RNc0luTjFZaUk2SW1ScFpEcGxkR2h5T2pCNE5ETTFaR1l6WldSaE5UY3hOVFJqWmpoalpqYzVNall3TnprNE9ERm1Namt4TW1ZMU5HUmlOQ0lzSW01aVppSTZNVFUyTWprMU1ESTRNaXdpZG1NaU9uc2lRR052Ym5SbGVIUWlPbHNpYUhSMGNITTZMeTkzZDNjdWR6TXViM0puTHpJd01UZ3ZZM0psWkdWdWRHbGhiSE12ZGpFaVhTd2lkSGx3WlNJNld5SldaWEpwWm1saFlteGxRM0psWkdWdWRHbGhiQ0pkTENKamNtVmtaVzUwYVdGc1UzVmlhbVZqZENJNmV5SmtaV2R5WldVaU9uc2lkSGx3WlNJNklrSmhZMmhsYkc5eVJHVm5jbVZsSWl3aWJtRnRaU0k2SWtKaFkyTmhiR0YxY3NPcFlYUWdaVzRnYlhWemFYRjFaWE1nYm5WdHc2bHlhWEYxWlhNaWZYMTlMQ0pwYzNNaU9pSmthV1E2WlhSb2Nqb3dlR1l4TWpNeVpqZzBNR1l6WVdRM1pESXpabU5rWVdFNE5HUTJZelkyWkdGak1qUmxabUl4T1RnaWZRLmxqVHVVVzZiY3NvQlFrc01vNWw4ZUZJbVZkT0EtZXc5OTNCNHJldF9wOUE4ajJETFE2MENRbXFCMTRObk41WHhEMGRfZ2xMUnMxTXljX0xCSmpudU53RSJdfSwiaXNzIjoiZGlkOmV0aHI6MHhmMTIzMmY4NDBmM2FkN2QyM2ZjZGFhODRkNmM2NmRhYzI0ZWZiMTk4In0.cFyO-xPMdj0Hg1DaCkm30hzcVcYdnDdgyxXLZr9NAJNMUzZ6naacuWNGdZGuU0ZDwmgpUMUqIzMqFFRmge0R8QA' | ||
} | ||
*/ | ||
``` |
import EthrDID from 'ethr-did' | ||
import { createVerifiableCredential, createPresentation, verifyCredential, verifyPresentation } from '../index' | ||
import { verifyJWT, decodeJWT } from 'did-jwt' | ||
import { DEFAULT_TYPE, DEFAULT_CONTEXT } from '../constants' | ||
import { DEFAULT_VC_TYPE, DEFAULT_VP_TYPE, DEFAULT_CONTEXT } from '../constants' | ||
import { | ||
@@ -9,3 +9,4 @@ validateContext, | ||
validateTimestamp, | ||
validateType, | ||
validateVcType, | ||
validateVpType, | ||
validateCredentialSubject | ||
@@ -26,3 +27,4 @@ } from '../validators' | ||
const mockValidateContext = <jest.Mock<typeof validateContext>>validateContext | ||
const mockValidateType = <jest.Mock<typeof validateType>>validateType | ||
const mockValidateVcType = <jest.Mock<typeof validateVcType>>validateVcType | ||
const mockValidateVpType = <jest.Mock<typeof validateVpType>>validateVpType | ||
const mockValidateCredentialSubject = <jest.Mock<typeof validateCredentialSubject>>validateCredentialSubject | ||
@@ -54,3 +56,3 @@ | ||
'@context': [DEFAULT_CONTEXT, EXTRA_CONTEXT_A], | ||
type: [DEFAULT_TYPE, EXTRA_TYPE_A], | ||
type: [DEFAULT_VC_TYPE, EXTRA_TYPE_A], | ||
credentialSubject: { | ||
@@ -67,3 +69,3 @@ degree: { | ||
'@context': [DEFAULT_CONTEXT, EXTRA_CONTEXT_A], | ||
type: [DEFAULT_TYPE], | ||
type: [DEFAULT_VP_TYPE], | ||
verifiableCredential: [VC_JWT] | ||
@@ -105,3 +107,3 @@ } | ||
) | ||
expect(mockValidateType).toHaveBeenCalledWith( | ||
expect(mockValidateVcType).toHaveBeenCalledWith( | ||
verifiableCredentialPayload.vc.type | ||
@@ -142,3 +144,3 @@ ) | ||
) | ||
expect(mockValidateType).toHaveBeenCalledWith(presentationPayload.vp.type) | ||
expect(mockValidateVpType).toHaveBeenCalledWith(presentationPayload.vp.type) | ||
for (const vc of presentationPayload.vp.verifiableCredential) { | ||
@@ -145,0 +147,0 @@ expect(mockValidateJwtFormat).toHaveBeenCalledWith(vc) |
import * as validators from '../validators' | ||
import { DEFAULT_CONTEXT, DEFAULT_TYPE } from '../constants' | ||
import { DEFAULT_CONTEXT, DEFAULT_VC_TYPE, DEFAULT_VP_TYPE } from '../constants' | ||
@@ -58,17 +58,17 @@ export const DID_A = 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198' | ||
describe('validateType', () => { | ||
describe('validateVcType', () => { | ||
it('does not throw if the value contains only the default type', () => { | ||
expect(() => validators.validateType([DEFAULT_TYPE])).not.toThrow() | ||
expect(() => validators.validateVcType([DEFAULT_VC_TYPE])).not.toThrow() | ||
}) | ||
it('does not throw if the value contains the default type and some user-defined ones', () => { | ||
expect(() => | ||
validators.validateType([DEFAULT_TYPE, EXTRA_TYPE_A, EXTRA_TYPE_B]) | ||
validators.validateVcType([DEFAULT_VC_TYPE, EXTRA_TYPE_A, EXTRA_TYPE_B]) | ||
).not.toThrow() | ||
}) | ||
it('throws a TypeError the value contains no types', () => { | ||
expect(() => validators.validateType([])).toThrow(TypeError) | ||
expect(() => validators.validateVcType([])).toThrow(TypeError) | ||
}) | ||
it('throws a TypeError the value is missing the default type', () => { | ||
expect(() => | ||
validators.validateType([EXTRA_TYPE_A, EXTRA_TYPE_B]) | ||
validators.validateVcType([EXTRA_TYPE_A, EXTRA_TYPE_B]) | ||
).toThrow(TypeError) | ||
@@ -78,2 +78,21 @@ }) | ||
describe('validateVpType', () => { | ||
it('does not throw if the value contains only the default type', () => { | ||
expect(() => validators.validateVpType([DEFAULT_VP_TYPE])).not.toThrow() | ||
}) | ||
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() | ||
}) | ||
it('throws a TypeError the value contains no types', () => { | ||
expect(() => validators.validateVpType([])).toThrow(TypeError) | ||
}) | ||
it('throws a TypeError the value is missing the default type', () => { | ||
expect(() => | ||
validators.validateVpType([EXTRA_TYPE_A, EXTRA_TYPE_B]) | ||
).toThrow(TypeError) | ||
}) | ||
}) | ||
describe('validateJwtFormat', () => { | ||
@@ -80,0 +99,0 @@ it('does not throw if the value is a valid JWT format', () => { |
@@ -5,2 +5,3 @@ export const JWT_ALG = 'ES256K-R' | ||
export const DEFAULT_CONTEXT = 'https://www.w3.org/2018/credentials/v1' | ||
export const DEFAULT_TYPE = 'VerifiableCredential' | ||
export const DEFAULT_VC_TYPE = 'VerifiableCredential' | ||
export const DEFAULT_VP_TYPE = 'VerifiablePresentation' |
import { createJWT, verifyJWT } from 'did-jwt' | ||
import { JWT_ALG, DEFAULT_CONTEXT, DEFAULT_TYPE } from './constants' | ||
import { JWT_ALG, DEFAULT_CONTEXT, DEFAULT_VC_TYPE } from './constants' | ||
import * as validators from './validators' | ||
@@ -11,2 +11,8 @@ import { | ||
export { | ||
Issuer, | ||
VerifiableCredentialPayload, | ||
PresentationPayload, | ||
} | ||
interface Resolvable { | ||
@@ -44,3 +50,3 @@ resolve: (did: string) => Promise<DIDDocument | null> | ||
validators.validateContext(payload.vc['@context']) | ||
validators.validateType(payload.vc.type) | ||
validators.validateVcType(payload.vc.type) | ||
validators.validateCredentialSubject(payload.vc.credentialSubject) | ||
@@ -53,3 +59,3 @@ if (payload.nbf) validators.validateTimestamp(payload.nbf) | ||
validators.validateContext(payload.vp['@context']) | ||
validators.validateType(payload.vp.type) | ||
validators.validateVpType(payload.vp.type) | ||
if (payload.vp.verifiableCredential.length < 1) { | ||
@@ -76,3 +82,3 @@ throw new TypeError('vp.verifiableCredential must not be empty') | ||
'@context': [DEFAULT_CONTEXT], | ||
type: [DEFAULT_TYPE], | ||
type: [DEFAULT_VC_TYPE], | ||
credentialSubject: payload.claim | ||
@@ -79,0 +85,0 @@ } |
import { | ||
DID_FORMAT, | ||
DEFAULT_CONTEXT, | ||
DEFAULT_TYPE, | ||
DEFAULT_VC_TYPE, | ||
DEFAULT_VP_TYPE, | ||
JWT_FORMAT | ||
@@ -36,8 +37,14 @@ } from './constants' | ||
export function validateType(value: string[]): void { | ||
if (value.length < 1 || !value.includes(DEFAULT_TYPE)) { | ||
throw new TypeError(`type is missing default "${DEFAULT_TYPE}"`) | ||
export function validateVcType(value: string[]): void { | ||
if (value.length < 1 || !value.includes(DEFAULT_VC_TYPE)) { | ||
throw new TypeError(`type is missing default "${DEFAULT_VC_TYPE}"`) | ||
} | ||
} | ||
export function validateVpType(value: string[]): void { | ||
if (value.length < 1 || !value.includes(DEFAULT_VP_TYPE)) { | ||
throw new TypeError(`type is missing default "${DEFAULT_VP_TYPE}"`) | ||
} | ||
} | ||
export function validateCredentialSubject(value: CredentialSubject): void { | ||
@@ -44,0 +51,0 @@ if (Object.keys(value).length === 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
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
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
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
80859
577
166
1