credential-status
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -61,4 +61,6 @@ import { DIDDocument } from 'did-resolver'; | ||
* ...new EthrStatusRegistry(config).asStatusMethod, //using convenience method | ||
* "CredentialStatusList2017": new CredentialStatusList2017().checkStatus, //referencing a checkStatus implementation | ||
* "CustomStatusChecker": customStatusCheckerMethod //directly referencing an independent method | ||
* "CredentialStatusList2017": new CredentialStatusList2017().checkStatus, //referencing a checkStatus | ||
* implementation | ||
* "CustomStatusChecker": customStatusCheckerMethod //directly referencing an independent | ||
* method | ||
* }) | ||
@@ -65,0 +67,0 @@ * ``` |
@@ -1,4 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var did_jwt_1 = require("did-jwt"); | ||
import { decodeJWT } from 'did-jwt'; | ||
/** | ||
@@ -8,43 +7,54 @@ * [draft] An implementation of a StatusMethod that can aggregate multiple other methods. | ||
*/ | ||
var Status = /** @class */ (function () { | ||
/** | ||
* All the expected StatusMethods should be registered during construction. | ||
* Example: | ||
* ```typescript | ||
* const status = new Status({ | ||
* ...new EthrStatusRegistry(config).asStatusMethod, //using convenience method | ||
* "CredentialStatusList2017": new CredentialStatusList2017().checkStatus, //referencing a checkStatus implementation | ||
* "CustomStatusChecker": customStatusCheckerMethod //directly referencing an independent method | ||
* }) | ||
* ``` | ||
*/ | ||
function Status(registry) { | ||
if (registry === void 0) { registry = {}; } | ||
this.registry = registry; | ||
class Status { | ||
/** | ||
* All the expected StatusMethods should be registered during construction. | ||
* Example: | ||
* ```typescript | ||
* const status = new Status({ | ||
* ...new EthrStatusRegistry(config).asStatusMethod, //using convenience method | ||
* "CredentialStatusList2017": new CredentialStatusList2017().checkStatus, //referencing a checkStatus | ||
* implementation | ||
* "CustomStatusChecker": customStatusCheckerMethod //directly referencing an independent | ||
* method | ||
* }) | ||
* ``` | ||
*/ | ||
constructor(registry = {}) { | ||
this.registry = void 0; | ||
this.registry = registry; | ||
} | ||
checkStatus(credential, didDoc) { | ||
try { | ||
const _this = this; | ||
// TODO: validate the credential to be VerifiableCredential or VerifiablePresentation | ||
const decoded = decodeJWT(credential); | ||
const statusEntry = decoded.payload.credentialStatus; | ||
if (typeof statusEntry === 'undefined') { | ||
return Promise.resolve({}); | ||
} | ||
const method = _this.registry[statusEntry.type]; | ||
if (typeof method !== 'undefined' && method != null) { | ||
return Promise.resolve(method(credential, didDoc)); | ||
} else { | ||
return Promise.resolve({ | ||
// Once the credential status mechanisms in W3C get more stable, perhaps this can become a `reject` | ||
error: `Credential status method ${statusEntry.type} unknown. Validity can not be determined.` | ||
}); | ||
} | ||
return Promise.resolve(); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
Status.prototype.checkStatus = function (credential, didDoc) { | ||
// TODO: validate the credential to be VerifiableCredential or VerifiablePresentation | ||
var decoded = did_jwt_1.decodeJWT(credential); | ||
var statusEntry = decoded.payload.credentialStatus; | ||
if (typeof statusEntry === 'undefined') { | ||
return new Promise(function (resolve, reject) { | ||
resolve({}); | ||
}); | ||
} | ||
var method = this.registry[statusEntry.type]; | ||
if (typeof method !== 'undefined' && method != null) { | ||
return method(credential, didDoc); | ||
} | ||
else { | ||
return new Promise(function (resolve, reject) { | ||
// Once the credential status mechanisms in W3C get more stable, perhaps this can become a `reject` | ||
resolve({ | ||
error: "Credential status method " + statusEntry.type + " unknown. Validity can not be determined." | ||
}); | ||
}); | ||
} | ||
}; | ||
return Status; | ||
}()); | ||
exports.Status = Status; | ||
//# sourceMappingURL=index.js.map | ||
} | ||
} | ||
export { Status }; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "credential-status", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "credential status aggregator for did-jwt", | ||
@@ -10,9 +10,9 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"build": "tsc", | ||
"build": "microbundle --compress=false", | ||
"test": "jest", | ||
"test-with-coverage": "jest --coverage && codecov", | ||
"test:ci": "jest --coverage && codecov", | ||
"dev": "tsc --watch", | ||
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"", | ||
"lint": "tslint -p tsconfig.json", | ||
"prepare": "npm run build", | ||
"format": "prettier --write \"src/**/*.[jt]s\"", | ||
"lint": "eslint --ignore-pattern \"src/**/*.test.[jt]s\" \"src/**/*.[jt]s\"", | ||
"prepare": "yarn build", | ||
"prepublishOnly": "npm test && npm run lint", | ||
@@ -27,5 +27,6 @@ "release": "semantic-release --debug" | ||
"revocation", | ||
"jwt" | ||
"credentialStatus", | ||
"JWT" | ||
], | ||
"author": "Mircea Nistor <mircea.nistor@consensys.net>", | ||
"author": "Mircea Nistor <mircea.nistor@mesh.xyz>", | ||
"license": "Apache-2.0", | ||
@@ -37,15 +38,20 @@ "bugs": { | ||
"devDependencies": { | ||
"@semantic-release/changelog": "3.0.6", | ||
"@semantic-release/git": "7.0.18", | ||
"@types/jest": "24.9.1", | ||
"@types/node": "12.12.37", | ||
"codecov": "3.6.1", | ||
"jest": "24.9.0", | ||
"@babel/preset-typescript": "^7.16.7", | ||
"@semantic-release/changelog": "6.0.1", | ||
"@semantic-release/git": "10.0.1", | ||
"@types/jest": "27.4.0", | ||
"@types/node": "14.18.8", | ||
"@typescript-eslint/eslint-plugin": "^5.10.0", | ||
"@typescript-eslint/parser": "^5.10.0", | ||
"codecov": "3.8.3", | ||
"eslint": "^8.7.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-jest": "^25.7.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"jest": "27.4.7", | ||
"jest-extended": "0.11.5", | ||
"prettier": "1.19.1", | ||
"semantic-release": "15.14.0", | ||
"ts-jest": "24.3.0", | ||
"tslint": "5.20.1", | ||
"tslint-config-prettier": "1.18.0", | ||
"typescript": "3.8.3" | ||
"microbundle": "^0.14.2", | ||
"prettier": "2.5.1", | ||
"semantic-release": "18.0.1", | ||
"typescript": "4.5.4" | ||
}, | ||
@@ -52,0 +58,0 @@ "files": [ |
# credential-status | ||
[![codecov](https://codecov.io/gh/uport-project/credential-status/branch/develop/graph/badge.svg)](https://codecov.io/gh/uport-project/credential-status) | ||
[![CircleCI](https://circleci.com/gh/uport-project/credential-status.svg?style=svg)](https://circleci.com/gh/uport-project/credential-status) | ||
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/eb3f6debcbf84860a6630acb2630eef2)](https://www.codacy.com/manual/uport-project/credential-status?utm_source=github.com&utm_medium=referral&utm_content=uport-project/credential-status&utm_campaign=Badge_Grade) | ||
@@ -11,5 +9,5 @@ A status method aggregator for verifiable credentials. | ||
Given a JWT credential that embeds a `status` property, it should call the appropriate status checking method and | ||
return its result. | ||
This library is meant to be used with `did-jwt`, as a status method aggregator called during the verification step. | ||
Given a JWT credential that embeds a `status` property, it should call the appropriate status checking method and return | ||
its result. This library is meant to be used with `did-jwt`, as a status method aggregator called during the | ||
verification step. | ||
@@ -19,2 +17,3 @@ Example: | ||
A JWT with a status field in the payload.vc field: | ||
```json | ||
@@ -35,3 +34,3 @@ { | ||
```ts | ||
import { EthrStatusRegistry } from ethr-status-registry | ||
import { EthrStatusRegistry } from 'ethr-status-registry' | ||
import { Status } from 'credential-status' | ||
@@ -41,22 +40,27 @@ //...other JWT verification inits | ||
const status = new Status({ | ||
...new EthrStatusRegistry(config).asStatusMethod, | ||
...new EthrStatusRegistry(config).asStatusMethod, | ||
}) | ||
val verificationResult = await didJWT.verifyJWT(token, resolver) | ||
val didDoc = verificationResult.doc | ||
const verificationResult = await didJWT.verifyJWT(token, resolver) | ||
const didDoc = verificationResult.doc | ||
val result = await status.checkStatus(token, didDoc) | ||
const result = await status.checkStatus(token, didDoc) | ||
// outputs: { "revokedAt": "0x5348684" } | ||
// { "revokedAt": "0x5348684" } | ||
``` | ||
The individual methods used to check for the status need to implement a `checkStatus` method and are expected to use the provided issuer DID document to help generate a result. | ||
The individual methods used to check for the status need to implement a `checkStatus` method and are expected to use the | ||
provided issuer DID document to help generate a result. | ||
### Results | ||
There is no standard format for the result of a status check. It is up to the method implementer to provide their own, and ultimately up to verifiers of credentials to determine which methods they support or accept. | ||
There is no standard format for the result of a status check. It is up to the method implementer to provide their own, | ||
and ultimately up to verifiers of credentials to determine which methods they support or accept. | ||
## Known methods | ||
The only known implementation of a credential-status method is the [ethr-status-registry](https://github.com/uport-project/ethr-status-registry) which uses an ethereum smart contract to register revocations of credentials. | ||
The only known implementation of a credential-status method is | ||
the [ethr-status-registry](https://github.com/uport-project/ethr-status-registry) which uses an ethereum smart contract | ||
to register revocations of credentials. | ||
If you implement your own status check, feel free to submit a link to it here. |
import { decodeJWT } from 'did-jwt' | ||
import { DIDDocument, PublicKey } from 'did-resolver' | ||
import { DIDDocument } from 'did-resolver' | ||
@@ -9,2 +9,4 @@ /** | ||
revoked?: boolean | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
[x: string]: any | ||
@@ -25,2 +27,4 @@ } | ||
id: string | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
[x: string]: any | ||
@@ -56,2 +60,4 @@ } | ||
credentialStatus?: StatusEntry | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
[x: string]: any | ||
@@ -77,4 +83,6 @@ } | ||
* ...new EthrStatusRegistry(config).asStatusMethod, //using convenience method | ||
* "CredentialStatusList2017": new CredentialStatusList2017().checkStatus, //referencing a checkStatus implementation | ||
* "CustomStatusChecker": customStatusCheckerMethod //directly referencing an independent method | ||
* "CredentialStatusList2017": new CredentialStatusList2017().checkStatus, //referencing a checkStatus | ||
* implementation | ||
* "CustomStatusChecker": customStatusCheckerMethod //directly referencing an independent | ||
* method | ||
* }) | ||
@@ -87,3 +95,3 @@ * ``` | ||
checkStatus(credential: string, didDoc: DIDDocument): Promise<null | CredentialStatus> { | ||
async checkStatus(credential: string, didDoc: DIDDocument): Promise<null | CredentialStatus> { | ||
// TODO: validate the credential to be VerifiableCredential or VerifiablePresentation | ||
@@ -94,5 +102,3 @@ const decoded = decodeJWT(credential) | ||
if (typeof statusEntry === 'undefined') { | ||
return new Promise((resolve, reject) => { | ||
resolve({}) | ||
}) | ||
return {} | ||
} | ||
@@ -105,10 +111,8 @@ | ||
} else { | ||
return new Promise((resolve, reject) => { | ||
return { | ||
// Once the credential status mechanisms in W3C get more stable, perhaps this can become a `reject` | ||
resolve({ | ||
error: `Credential status method ${statusEntry.type} unknown. Validity can not be determined.` | ||
}) | ||
}) | ||
error: `Credential status method ${statusEntry.type} unknown. Validity can not be determined.`, | ||
} | ||
} | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
43208
12
385
63
18
1