@windingtree/org.id-auth
Advanced tools
Comparing version 0.4.1 to 0.4.2
@@ -58,3 +58,1 @@ import type { KeyLike, JWK } from './keys'; | ||
export declare const verifyVC: (vc: SignedVC, publicKey: KeyLike | JWK | string) => Promise<CredentialReference>; | ||
export declare const isExpired: (vc: CredentialReference) => boolean; | ||
export declare const isValidFromUntil: (vc: CredentialReference) => boolean; |
@@ -6,6 +6,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isValidFromUntil = exports.isExpired = exports.verifyVC = exports.createVC = exports.buildProofUtil = exports.checkDateUtil = exports.buildHolderUtil = exports.verifyJwsSignedWithBlockchainAccount = exports.decodeJws = exports.parseBlockchainAccountId = exports.signWithWeb3Provider = exports.buildUnsignedDataForWeb3Signature = void 0; | ||
exports.verifyVC = exports.createVC = exports.buildProofUtil = exports.checkDateUtil = exports.buildHolderUtil = exports.verifyJwsSignedWithBlockchainAccount = exports.decodeJws = exports.parseBlockchainAccountId = exports.signWithWeb3Provider = exports.buildUnsignedDataForWeb3Signature = void 0; | ||
const web3_1 = __importDefault(require("web3")); | ||
const keys_1 = require("./keys"); | ||
const org_id_utils_1 = require("@windingtree/org.id-utils"); | ||
const org_json_schema_1 = __importDefault(require("@windingtree/org.json-schema")); | ||
const luxon_1 = require("luxon"); | ||
@@ -332,2 +333,7 @@ const parse_1 = require("jose/jwk/parse"); | ||
const verifyVC = async (vc, publicKey) => { | ||
// Validate ORG.JSON VC against the VC schema | ||
const vcSchemaValid = org_id_utils_1.object.validateWithSchemaOrRef(org_json_schema_1.default, '#/definitions/CredentialReference', vc); | ||
if (vcSchemaValid !== null) { | ||
throw new Error(`VC schema validation: ${vcSchemaValid}`); | ||
} | ||
const jws = org_id_utils_1.object.getDeepValue(vc, 'proof.jws'); | ||
@@ -380,29 +386,36 @@ if (typeof jws !== 'string') { | ||
} | ||
// @todo Add validation of the payload against the VC schema | ||
return decodedPayload; | ||
}; | ||
exports.verifyVC = verifyVC; | ||
// Check if VC expired | ||
const isExpired = (vc) => { | ||
const unsignedPayload = JSON.parse(JSON.stringify(vc)); | ||
delete unsignedPayload.proof; | ||
// Compare unsigned and signed payloads | ||
if (JSON.stringify(unsignedPayload) !== JSON.stringify(decodedPayload)) { | ||
throw new Error('Unsigned and signed payloads are not equal'); | ||
} | ||
const currentDate = luxon_1.DateTime.now(); | ||
return typeof vc.expirationDate === 'undefined' || | ||
currentDate > luxon_1.DateTime.fromISO(vc.expirationDate); | ||
}; | ||
exports.isExpired = isExpired; | ||
// Check if VC fullfil from-until range | ||
const isValidFromUntil = (vc) => { | ||
const currentDate = luxon_1.DateTime.now(); | ||
if (typeof vc.validFrom !== 'undefined' && typeof vc.validUntil !== 'undefined') { | ||
return currentDate >= luxon_1.DateTime.fromISO(vc.validFrom) && | ||
currentDate <= luxon_1.DateTime.fromISO(vc.validUntil); | ||
// Check if VC expired | ||
if (!(typeof decodedPayload.expirationDate === 'undefined' || | ||
currentDate <= luxon_1.DateTime.fromISO(decodedPayload.expirationDate))) { | ||
throw new Error(`VC expired at: ${decodedPayload.expirationDate}`); | ||
} | ||
if (typeof vc.validFrom !== 'undefined' && typeof vc.validUntil === 'undefined') { | ||
return currentDate >= luxon_1.DateTime.fromISO(vc.validFrom); | ||
// Check if VC active by both dates | ||
if (typeof decodedPayload.validFrom !== 'undefined' && | ||
typeof decodedPayload.validUntil !== 'undefined' && | ||
!(currentDate >= luxon_1.DateTime.fromISO(decodedPayload.validFrom) && | ||
currentDate <= luxon_1.DateTime.fromISO(decodedPayload.validUntil))) { | ||
throw new Error(`VC inactive. Valid from date: ${decodedPayload.validFrom}. Valid until date: ${decodedPayload.validUntil}`); | ||
} | ||
if (typeof vc.validFrom === 'undefined' && typeof vc.validUntil !== 'undefined') { | ||
return currentDate <= luxon_1.DateTime.fromISO(vc.validUntil); | ||
// Check if VC active by `from` date only | ||
if (typeof vc.validFrom !== 'undefined' && | ||
typeof vc.validUntil === 'undefined' && | ||
currentDate < luxon_1.DateTime.fromISO(vc.validFrom)) { | ||
throw new Error(`VC inactive. Valid from date: ${decodedPayload.validFrom}`); | ||
} | ||
return true; | ||
// Check if VC active by `until` date only | ||
if (typeof vc.validFrom === 'undefined' && | ||
typeof vc.validUntil !== 'undefined' && | ||
currentDate > luxon_1.DateTime.fromISO(vc.validUntil)) { | ||
throw new Error(`VC inactive. Valid until date: ${decodedPayload.validUntil}`); | ||
} | ||
return decodedPayload; | ||
}; | ||
exports.isValidFromUntil = isValidFromUntil; | ||
exports.verifyVC = verifyVC; | ||
//# sourceMappingURL=vc.js.map |
{ | ||
"name": "@windingtree/org.id-auth", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "ORGiD authentication library", | ||
@@ -43,3 +43,3 @@ "main": "dist/index.js", | ||
"jose": "3.13.0", | ||
"@windingtree/org.id-utils": "0.2.17", | ||
"@windingtree/org.id-utils": "0.2.18", | ||
"@windingtree/org.json-schema": "0.5.7-beta", | ||
@@ -46,0 +46,0 @@ "luxon": "1.27.0", |
Sorry, the diff of this file is not supported yet
60682
830
+ Added@windingtree/org.id-utils@0.2.18(transitive)
+ Addedajv@8.6.0(transitive)
+ Addedajv-formats@2.1.0(transitive)
+ Addedjson-schema-traverse@1.0.0(transitive)
+ Addedrequire-from-string@2.0.2(transitive)
- Removed@windingtree/org.id-utils@0.2.17(transitive)