diff --git a/package-lock.json b/package-lock.json index 827f646..d3da64e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1528,19 +1528,37 @@ } }, "@govtechsg/oa-verify": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/@govtechsg/oa-verify/-/oa-verify-3.0.3.tgz", - "integrity": "sha512-S8lT0Vi7fGdCVgnmePiq/78hAloA01Oqn7iw7Lk7abvDjlS53rq7tXv5L+fMq2J4xP0U0BDPgsTxH4uEWMGtuA==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@govtechsg/oa-verify/-/oa-verify-3.1.1.tgz", + "integrity": "sha512-MmbFJZ9qu61JsiPPydWRzBglQO2jzxtvS+QrY1+KSYKQpjihgfvfjTF0L1nvumSyg8Jdp5Toh0ZGfFGfOHzpqg==", "requires": { "@govtechsg/dnsprove": "^2.0.5", "@govtechsg/open-attestation": "3.1.0", - "ethers": "^4.0.40" + "debug": "^4.1.1", + "ethers": "^4.0.44" + }, + "dependencies": { + "@govtechsg/open-attestation": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@govtechsg/open-attestation/-/open-attestation-3.1.0.tgz", + "integrity": "sha512-7QkanH/Q8CUor4gX5Be+jELh5uAdyiVtj5dxU0P8NMjwvtS+hEd/9Iz2do8Xwl8kDS0CYu9tjkLPIxq454dF4Q==", + "requires": { + "ajv": "6.10.2", + "debug": "^4.1.1", + "flatley": "^5.2.0", + "js-sha3": "^0.8.0", + "lodash": "^4.17.15", + "uuid": "^3.3.3", + "validator": "^12.0.0", + "verbal-expressions": "^1.0.2" + } + } } }, "@govtechsg/open-attestation": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@govtechsg/open-attestation/-/open-attestation-3.1.0.tgz", - "integrity": "sha512-7QkanH/Q8CUor4gX5Be+jELh5uAdyiVtj5dxU0P8NMjwvtS+hEd/9Iz2do8Xwl8kDS0CYu9tjkLPIxq454dF4Q==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@govtechsg/open-attestation/-/open-attestation-3.1.1.tgz", + "integrity": "sha512-J8rMbOLS/op1nDcXRyVYac9aHzuQURuY6chLzo1g1nhhoXQa6Rf8sho1qcHVIJ9e5VG+NeEki5ZT0WY/VhI/NQ==", "requires": { "ajv": "6.10.2", "debug": "^4.1.1", @@ -5209,9 +5227,9 @@ "dev": true }, "ethers": { - "version": "4.0.42", - "resolved": "https://registry.npmjs.org/ethers/-/ethers-4.0.42.tgz", - "integrity": "sha512-2gmmt5x683Xz4QwGDBVJhrdXevVAEr5fnXPGDPou2AKB+zklrirGpl0w1SHBn7Wa9hbL2z6MvP3n7k8Yss2MFg==", + "version": "4.0.44", + "resolved": "https://registry.npmjs.org/ethers/-/ethers-4.0.44.tgz", + "integrity": "sha512-kCkMPkpYjBkxzqjcuYUfDY7VHDbf5EXnfRPUOazdqdf59SvXaT+w5lgauxLlk1UjxnAiNfeNS87rkIXnsTaM7Q==", "requires": { "aes-js": "3.0.0", "bn.js": "^4.4.0", @@ -17061,9 +17079,9 @@ } }, "validator": { - "version": "12.1.0", - "resolved": "https://registry.npmjs.org/validator/-/validator-12.1.0.tgz", - "integrity": "sha512-gIC2RBuFRi574Rb9vewGCJ7TCLxHXNx6EKthEgs+Iz0pYa9a9Te1VLG/bGLsAyGWrqR5FfR7tbFUI7FEF2LiGA==" + "version": "12.2.0", + "resolved": "https://registry.npmjs.org/validator/-/validator-12.2.0.tgz", + "integrity": "sha512-jJfE/DW6tIK1Ek8nCfNFqt8Wb3nzMoAbocBF6/Icgg1ZFSBpObdnwVY2jQj6qUqzhx5jc71fpvBWyLGO7Xl+nQ==" }, "value-or-function": { "version": "3.0.0", diff --git a/package.json b/package.json index 4e662c6..114d43d 100644 --- a/package.json +++ b/package.json @@ -45,8 +45,8 @@ ] }, "dependencies": { - "@govtechsg/oa-verify": "3.0.3", - "@govtechsg/open-attestation": "3.1.0", + "@govtechsg/oa-verify": "3.1.1", + "@govtechsg/open-attestation": "3.1.1", "debug": "4.1.1", "node-fetch": "2.6.0" }, diff --git a/src/verify.ts b/src/verify.ts index c54191e..851d29c 100644 --- a/src/verify.ts +++ b/src/verify.ts @@ -32,6 +32,13 @@ type OpencertsRegistryVerificationFragmentData = Partial & { const type = "ISSUER_IDENTITY"; const name = "OpencertsRegistryVerifier"; +// NEVER EVER REPLACE OR CHANGE A VALUE :) +// code for errors and invalid fragment +export enum OpencertsRegistryCode { + INVALID_IDENTITY = 0, + SKIPPED = 1 +} + const storeToFragment = ( registry: Registry, store: string @@ -58,7 +65,11 @@ const storeToFragment = ( value: store, status: "INVALID" as "INVALID" }, - message: `Document store ${store} not found in the registry` + reason: { + code: OpencertsRegistryCode.INVALID_IDENTITY, + codeString: OpencertsRegistryCode[OpencertsRegistryCode.INVALID_IDENTITY], + message: `Document store ${store} not found in the registry` + } }; }; @@ -80,7 +91,11 @@ export const registryVerifier: Verifier< status: "SKIPPED", type, name, - message: `Document issuers doesn't have "documentStore" or "certificateStore" property or ${v3.Method.DocumentStore} method` + reason: { + code: OpencertsRegistryCode.SKIPPED, + codeString: OpencertsRegistryCode[OpencertsRegistryCode.SKIPPED], + message: `Document issuers doesn't have "documentStore" or "certificateStore" property or ${v3.Method.DocumentStore} method` + } }); }, verify: async document => { @@ -104,7 +119,7 @@ export const registryVerifier: Verifier< message: status === "INVALID" ? `Document store ${ - issuerFragments.find(fragment => fragment.status === "VALID")?.data + issuerFragments.find(fragment => fragment.status === "INVALID")?.data } not found in the registry` : undefined }; diff --git a/test/verify.v2.test.ts b/test/verify.v2.test.ts index 5064dd2..90c632f 100644 --- a/test/verify.v2.test.ts +++ b/test/verify.v2.test.ts @@ -43,10 +43,14 @@ describe("verify", () => { type: "DOCUMENT_STATUS" }, { - message: 'Document issuers doesn\'t have "tokenRegistry" property or TOKEN_REGISTRY method', name: "OpenAttestationEthereumTokenRegistryMinted", status: "SKIPPED", - type: "DOCUMENT_STATUS" + type: "DOCUMENT_STATUS", + reason: { + code: 4, + codeString: "SKIPPED", + message: 'Document issuers doesn\'t have "tokenRegistry" property or TOKEN_REGISTRY method' + } }, { data: { @@ -63,10 +67,15 @@ describe("verify", () => { type: "DOCUMENT_STATUS" }, { - message: `Document issuers doesn't have "documentStore" / "tokenRegistry" property or doesn't use DNS-TXT type`, status: "SKIPPED", name: "OpenAttestationDnsTxt", - type: "ISSUER_IDENTITY" + type: "ISSUER_IDENTITY", + reason: { + code: 2, + codeString: "SKIPPED", + message: + 'Document issuers doesn\'t have "documentStore" / "tokenRegistry" property or doesn\'t use DNS-TXT type' + } }, { data: [ diff --git a/test/verify.v3.test.ts b/test/verify.v3.test.ts index 4e3f996..0d65c60 100644 --- a/test/verify.v3.test.ts +++ b/test/verify.v3.test.ts @@ -22,12 +22,10 @@ describe("verify", () => { }, { data: { - details: [ - { - address: "0x8Fc57204c35fb9317D91285eF52D6b892EC08cD3", - issued: true - } - ], + details: { + address: "0x8Fc57204c35fb9317D91285eF52D6b892EC08cD3", + issued: true + }, issuedOnAll: true }, status: "VALID", @@ -35,19 +33,21 @@ describe("verify", () => { type: "DOCUMENT_STATUS" }, { - message: 'Document issuers doesn\'t have "tokenRegistry" property or TOKEN_REGISTRY method', + reason: { + code: 4, + codeString: "SKIPPED", + message: 'Document issuers doesn\'t have "tokenRegistry" property or TOKEN_REGISTRY method' + }, name: "OpenAttestationEthereumTokenRegistryMinted", status: "SKIPPED", type: "DOCUMENT_STATUS" }, { data: { - details: [ - { - address: "0x8Fc57204c35fb9317D91285eF52D6b892EC08cD3", - revoked: false - } - ], + details: { + address: "0x8Fc57204c35fb9317D91285eF52D6b892EC08cD3", + revoked: false + }, revokedOnAny: false }, status: "VALID", @@ -60,7 +60,11 @@ describe("verify", () => { status: "INVALID", value: "0x8Fc57204c35fb9317D91285eF52D6b892EC08cD3" }, - message: "Certificate issuer identity is invalid", + reason: { + code: 1, + codeString: "INVALID_IDENTITY", + message: "Certificate issuer identity is invalid" + }, name: "OpenAttestationDnsTxt", status: "INVALID", type: "ISSUER_IDENTITY" @@ -84,46 +88,64 @@ describe("verify", () => { { data: false, status: "INVALID", - message: "Certificate has been tampered with", + reason: { + code: 0, + codeString: "DOCUMENT_TAMPERED", + message: "Certificate has been tampered with" + }, name: "OpenAttestationHash", type: "DOCUMENT_INTEGRITY" }, { data: { - details: [ - { - issued: false, - address: "0x532C9Ff853CA54370D7492cD84040F9f8099f11B", - error: - 'invalid input argument (arg="document", reason="invalid bytes32 value", value="0xabcd", version=4.0.42)' + details: { + issued: false, + address: "0x532C9Ff853CA54370D7492cD84040F9f8099f11B", + reason: { + code: 3, + codeString: "ETHERS_UNHANDLED_ERROR", + message: "Error with smart contract 0x532C9Ff853CA54370D7492cD84040F9f8099f11B: invalid bytes32 value" } - ], + }, issuedOnAll: false }, - message: "Certificate has not been issued", + reason: { + code: 3, + codeString: "ETHERS_UNHANDLED_ERROR", + message: "Error with smart contract 0x532C9Ff853CA54370D7492cD84040F9f8099f11B: invalid bytes32 value" + }, status: "INVALID", name: "OpenAttestationEthereumDocumentStoreIssued", type: "DOCUMENT_STATUS" }, { - message: 'Document issuers doesn\'t have "tokenRegistry" property or TOKEN_REGISTRY method', + reason: { + code: 4, + codeString: "SKIPPED", + message: 'Document issuers doesn\'t have "tokenRegistry" property or TOKEN_REGISTRY method' + }, name: "OpenAttestationEthereumTokenRegistryMinted", status: "SKIPPED", type: "DOCUMENT_STATUS" }, { data: { - details: [ - { - address: "0x532C9Ff853CA54370D7492cD84040F9f8099f11B", - error: - 'invalid input argument (arg="document", reason="invalid bytes32 value", value="0xabcd", version=4.0.42)', - revoked: true - } - ], + details: { + address: "0x532C9Ff853CA54370D7492cD84040F9f8099f11B", + reason: { + code: 3, + codeString: "ETHERS_UNHANDLED_ERROR", + message: "Error with smart contract 0x532C9Ff853CA54370D7492cD84040F9f8099f11B: invalid bytes32 value" + }, + revoked: true + }, revokedOnAny: true }, - message: "Certificate has been revoked", + reason: { + code: 3, + codeString: "ETHERS_UNHANDLED_ERROR", + message: "Error with smart contract 0x532C9Ff853CA54370D7492cD84040F9f8099f11B: invalid bytes32 value" + }, status: "INVALID", name: "OpenAttestationEthereumDocumentStoreRevoked", type: "DOCUMENT_STATUS"