From 50f49c77a8ef7a99318ee7ce55d5a8d1d08ec09d Mon Sep 17 00:00:00 2001 From: Seth Date: Wed, 22 Dec 2021 19:16:20 +0800 Subject: [PATCH 1/4] chore: add trial version of dnsprove lib --- package-lock.json | 5 ++--- package.json | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 24784829..b1491f09 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1367,9 +1367,8 @@ } }, "@govtechsg/dnsprove": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/@govtechsg/dnsprove/-/dnsprove-2.1.3.tgz", - "integrity": "sha512-eW/4MimGjhdS8mS5wM6RCezV+F9RBDuo5WD8DoLLXCipkMWYeWraCAhpKLd+Zl9NC2ROLXNDJSqg8/TUXt5/sg==", + "version": "git+https://github.com/Open-Attestation/dnsprove.git#975559ee1b83d3d79e4ce88291a4c13c6a34d423", + "from": "git+https://github.com/Open-Attestation/dnsprove.git#feat/add-networks", "requires": { "axios": "^0.21.1", "debug": "^4.3.1", diff --git a/package.json b/package.json index 25d9e760..e8c54211 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "author": "", "license": "Apache-2.0", "dependencies": { - "@govtechsg/dnsprove": "^2.1.3", + "@govtechsg/dnsprove": "git+https://github.com/Open-Attestation/dnsprove.git#feat/add-networks", "@govtechsg/document-store": "^2.2.3", "@govtechsg/open-attestation": "^6.2.0", "@govtechsg/token-registry": "^2.5.3", From 2bc6b9c801ddd173ac7505e7842f5a71b76ccd42 Mon Sep 17 00:00:00 2001 From: Seth Date: Wed, 22 Dec 2021 19:17:54 +0800 Subject: [PATCH 2/4] chore(testing): to be reverted; for trial run and testing purposes only --- dist/cjs/common/error.js | 29 ++ dist/cjs/common/errorHandler.js | 88 +++++ dist/cjs/common/logger.js | 16 + dist/cjs/common/messages.js | 4 + dist/cjs/common/utils.js | 180 ++++++++++ dist/cjs/config.js | 4 + dist/cjs/did/resolver.js | 122 +++++++ dist/cjs/did/verifier.js | 119 +++++++ dist/cjs/getIdentifier.js | 93 ++++++ dist/cjs/index.js | 79 +++++ dist/cjs/types/core.js | 7 + dist/cjs/types/error.js | 107 ++++++ dist/cjs/validator.js | 20 ++ .../hash/openAttestationHash.js | 98 ++++++ .../hash/openAttestationHash.type.js | 2 + .../didSigned/didSignedDocumentStatus.js | 309 ++++++++++++++++++ .../didSigned/didSignedDocumentStatus.type.js | 70 ++++ .../documentStatus/didSigned/index.js | 13 + .../ethereumDocumentStoreStatus.js | 274 ++++++++++++++++ .../ethereumDocumentStoreStatus.type.js | 59 ++++ .../documentStatus/documentStore/index.js | 13 + .../documentStatus/revocation.types.js | 31 ++ .../ethereumTokenRegistryStatus.js | 236 +++++++++++++ .../ethereumTokenRegistryStatus.type.js | 39 +++ .../documentStatus/tokenRegistry/index.js | 13 + dist/cjs/verifiers/documentStatus/utils.js | 193 +++++++++++ .../issuerIdentity/did/didIdentityProof.js | 185 +++++++++++ .../did/didIdentityProof.type.js | 2 + .../cjs/verifiers/issuerIdentity/did/index.js | 13 + .../issuerIdentity/dnsDid/dnsDidProof.js | 186 +++++++++++ .../issuerIdentity/dnsDid/dnsDidProof.type.js | 20 ++ .../verifiers/issuerIdentity/dnsDid/index.js | 13 + .../verifiers/issuerIdentity/dnsTxt/index.js | 13 + .../dnsTxt/openAttestationDnsTxt.js | 220 +++++++++++++ .../dnsTxt/openAttestationDnsTxt.type.js | 33 ++ dist/cjs/verifiers/verificationBuilder.js | 37 +++ dist/esm/common/error.js | 26 ++ dist/esm/common/errorHandler.js | 84 +++++ dist/esm/common/logger.js | 9 + dist/esm/common/messages.js | 1 + dist/esm/common/utils.js | 162 +++++++++ dist/esm/config.js | 1 + dist/esm/did/resolver.js | 112 +++++++ dist/esm/did/verifier.js | 114 +++++++ dist/esm/getIdentifier.js | 89 +++++ dist/esm/index.js | 38 +++ dist/esm/types/core.js | 3 + dist/esm/types/error.js | 104 ++++++ dist/esm/validator.js | 16 + .../hash/openAttestationHash.js | 95 ++++++ .../hash/openAttestationHash.type.js | 1 + .../didSigned/didSignedDocumentStatus.js | 306 +++++++++++++++++ .../didSigned/didSignedDocumentStatus.type.js | 67 ++++ .../documentStatus/didSigned/index.js | 1 + .../ethereumDocumentStoreStatus.js | 269 +++++++++++++++ .../ethereumDocumentStoreStatus.type.js | 56 ++++ .../documentStatus/documentStore/index.js | 1 + .../documentStatus/revocation.types.js | 28 ++ .../ethereumTokenRegistryStatus.js | 231 +++++++++++++ .../ethereumTokenRegistryStatus.type.js | 36 ++ .../documentStatus/tokenRegistry/index.js | 1 + dist/esm/verifiers/documentStatus/utils.js | 182 +++++++++++ .../issuerIdentity/did/didIdentityProof.js | 182 +++++++++++ .../did/didIdentityProof.type.js | 1 + .../esm/verifiers/issuerIdentity/did/index.js | 1 + .../issuerIdentity/dnsDid/dnsDidProof.js | 183 +++++++++++ .../issuerIdentity/dnsDid/dnsDidProof.type.js | 17 + .../verifiers/issuerIdentity/dnsDid/index.js | 1 + .../verifiers/issuerIdentity/dnsTxt/index.js | 1 + .../dnsTxt/openAttestationDnsTxt.js | 217 ++++++++++++ .../dnsTxt/openAttestationDnsTxt.type.js | 30 ++ dist/esm/verifiers/verificationBuilder.js | 33 ++ dist/types/src/common/error.d.ts | 5 + dist/types/src/common/errorHandler.d.ts | 8 + dist/types/src/common/logger.d.ts | 10 + dist/types/src/common/messages.d.ts | 1 + dist/types/src/common/utils.d.ts | 69 ++++ dist/types/src/common/utils.test.d.ts | 1 + dist/types/src/config.d.ts | 1 + dist/types/src/did/resolver.d.ts | 19 ++ dist/types/src/did/resolver.test.d.ts | 1 + dist/types/src/did/verifier.d.ts | 66 ++++ dist/types/src/getIdentifier.d.ts | 8 + dist/types/src/getIdentifier.test.d.ts | 1 + dist/types/src/index.d.ts | 26 ++ dist/types/src/types/core.d.ts | 111 +++++++ dist/types/src/types/error.d.ts | 99 ++++++ dist/types/src/validator.d.ts | 2 + dist/types/src/validator.test.d.ts | 1 + .../hash/openAttestationHash.d.ts | 5 + .../hash/openAttestationHash.test.d.ts | 1 + .../hash/openAttestationHash.type.d.ts | 5 + .../didSigned/didSignedDocumentStatus.d.ts | 5 + .../didSignedDocumentStatus.test.d.ts | 1 + .../didSignedDocumentStatus.type.d.ts | 190 +++++++++++ .../documentStatus/didSigned/index.d.ts | 1 + .../ethereumDocumentStoreStatus.d.ts | 13 + .../ethereumDocumentStoreStatus.test.d.ts | 1 + .../ethereumDocumentStoreStatus.type.d.ts | 159 +++++++++ .../documentStatus/documentStore/index.d.ts | 1 + .../documentStatus/revocation.types.d.ts | 61 ++++ .../ethereumTokenRegistryStatus.d.ts | 11 + .../ethereumTokenRegistryStatus.test.d.ts | 1 + .../ethereumTokenRegistryStatus.type.d.ts | 80 +++++ .../documentStatus/tokenRegistry/index.d.ts | 1 + .../src/verifiers/documentStatus/utils.d.ts | 26 ++ .../issuerIdentity/did/didIdentityProof.d.ts | 5 + .../did/didIdentityProof.test.d.ts | 1 + .../did/didIdentityProof.type.d.ts | 11 + .../verifiers/issuerIdentity/did/index.d.ts | 1 + .../issuerIdentity/dnsDid/dnsDidProof.d.ts | 5 + .../dnsDid/dnsDidProof.test.d.ts | 1 + .../dnsDid/dnsDidProof.type.d.ts | 56 ++++ .../issuerIdentity/dnsDid/index.d.ts | 1 + .../issuerIdentity/dnsTxt/index.d.ts | 1 + .../dnsTxt/openAttestationDnsTxt.d.ts | 3 + .../dnsTxt/openAttestationDnsTxt.test.d.ts | 1 + .../dnsTxt/openAttestationDnsTxt.type.d.ts | 97 ++++++ .../src/verifiers/verificationBuilder.d.ts | 2 + .../verify.v2.integration.errors.test.d.ts | 4 + .../types/src/verify.v2.integration.test.d.ts | 4 + .../types/src/verify.v3.integration.test.d.ts | 1 + dist/types/test/fixtures/v2/document.d.ts | 18 + .../v2/documentDidCustomRevocation.d.ts | 1 + .../fixtures/v2/documentDidMissingProof.d.ts | 1 + .../v2/documentDidMixedTokenRegistry.d.ts | 1 + .../v2/documentDidObfuscatedRevocation.d.ts | 1 + .../test/fixtures/v2/documentDidSigned.d.ts | 1 + .../v2/documentDidWrongSignature.d.ts | 1 + .../v2/documentDnsDidMixedTokenRegistry.d.ts | 2 + .../fixtures/v2/documentDnsDidNoDnsTxt.d.ts | 1 + .../fixtures/v2/documentDnsDidSigned.d.ts | 1 + ...MainnetInvalidWithIncorrectMerkleRoot.d.ts | 15 + ...MainnetInvalidWithOddLengthMerkleRoot.d.ts | 15 + ...umentMainnetValidWithCertificateStore.d.ts | 11 + .../v2/documentRinkebyWithDocumentStore.d.ts | 7 + .../v2/documentRopstenMixedIssuance.d.ts | 1 + ...tRopstenNotIssuedWithCertificateStore.d.ts | 24 ++ ...mentRopstenNotIssuedWithDocumentStore.d.ts | 14 + ...mentRopstenNotIssuedWithTokenRegistry.d.ts | 14 + .../v2/documentRopstenObfuscated.d.ts | 20 ++ ...entRopstenRevokedWithCertificateStore.d.ts | 30 ++ ...cumentRopstenRevokedWithDocumentStore.d.ts | 14 + .../v2/documentRopstenRevokedWithToken.d.ts | 30 ++ ...umentRopstenValidWithCertificateStore.d.ts | 24 ++ ...documentRopstenValidWithDocumentStore.d.ts | 14 + .../v2/documentRopstenValidWithToken.d.ts | 14 + .../test/fixtures/v2/tamperedDocument.d.ts | 19 ++ dist/types/test/utils/index.d.ts | 3 + 149 files changed, 7121 insertions(+) create mode 100644 dist/cjs/common/error.js create mode 100644 dist/cjs/common/errorHandler.js create mode 100644 dist/cjs/common/logger.js create mode 100644 dist/cjs/common/messages.js create mode 100644 dist/cjs/common/utils.js create mode 100644 dist/cjs/config.js create mode 100644 dist/cjs/did/resolver.js create mode 100644 dist/cjs/did/verifier.js create mode 100644 dist/cjs/getIdentifier.js create mode 100644 dist/cjs/index.js create mode 100644 dist/cjs/types/core.js create mode 100644 dist/cjs/types/error.js create mode 100644 dist/cjs/validator.js create mode 100644 dist/cjs/verifiers/documentIntegrity/hash/openAttestationHash.js create mode 100644 dist/cjs/verifiers/documentIntegrity/hash/openAttestationHash.type.js create mode 100644 dist/cjs/verifiers/documentStatus/didSigned/didSignedDocumentStatus.js create mode 100644 dist/cjs/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.js create mode 100644 dist/cjs/verifiers/documentStatus/didSigned/index.js create mode 100644 dist/cjs/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.js create mode 100644 dist/cjs/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.js create mode 100644 dist/cjs/verifiers/documentStatus/documentStore/index.js create mode 100644 dist/cjs/verifiers/documentStatus/revocation.types.js create mode 100644 dist/cjs/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.js create mode 100644 dist/cjs/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.js create mode 100644 dist/cjs/verifiers/documentStatus/tokenRegistry/index.js create mode 100644 dist/cjs/verifiers/documentStatus/utils.js create mode 100644 dist/cjs/verifiers/issuerIdentity/did/didIdentityProof.js create mode 100644 dist/cjs/verifiers/issuerIdentity/did/didIdentityProof.type.js create mode 100644 dist/cjs/verifiers/issuerIdentity/did/index.js create mode 100644 dist/cjs/verifiers/issuerIdentity/dnsDid/dnsDidProof.js create mode 100644 dist/cjs/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.js create mode 100644 dist/cjs/verifiers/issuerIdentity/dnsDid/index.js create mode 100644 dist/cjs/verifiers/issuerIdentity/dnsTxt/index.js create mode 100644 dist/cjs/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.js create mode 100644 dist/cjs/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.js create mode 100644 dist/cjs/verifiers/verificationBuilder.js create mode 100644 dist/esm/common/error.js create mode 100644 dist/esm/common/errorHandler.js create mode 100644 dist/esm/common/logger.js create mode 100644 dist/esm/common/messages.js create mode 100644 dist/esm/common/utils.js create mode 100644 dist/esm/config.js create mode 100644 dist/esm/did/resolver.js create mode 100644 dist/esm/did/verifier.js create mode 100644 dist/esm/getIdentifier.js create mode 100644 dist/esm/index.js create mode 100644 dist/esm/types/core.js create mode 100644 dist/esm/types/error.js create mode 100644 dist/esm/validator.js create mode 100644 dist/esm/verifiers/documentIntegrity/hash/openAttestationHash.js create mode 100644 dist/esm/verifiers/documentIntegrity/hash/openAttestationHash.type.js create mode 100644 dist/esm/verifiers/documentStatus/didSigned/didSignedDocumentStatus.js create mode 100644 dist/esm/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.js create mode 100644 dist/esm/verifiers/documentStatus/didSigned/index.js create mode 100644 dist/esm/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.js create mode 100644 dist/esm/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.js create mode 100644 dist/esm/verifiers/documentStatus/documentStore/index.js create mode 100644 dist/esm/verifiers/documentStatus/revocation.types.js create mode 100644 dist/esm/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.js create mode 100644 dist/esm/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.js create mode 100644 dist/esm/verifiers/documentStatus/tokenRegistry/index.js create mode 100644 dist/esm/verifiers/documentStatus/utils.js create mode 100644 dist/esm/verifiers/issuerIdentity/did/didIdentityProof.js create mode 100644 dist/esm/verifiers/issuerIdentity/did/didIdentityProof.type.js create mode 100644 dist/esm/verifiers/issuerIdentity/did/index.js create mode 100644 dist/esm/verifiers/issuerIdentity/dnsDid/dnsDidProof.js create mode 100644 dist/esm/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.js create mode 100644 dist/esm/verifiers/issuerIdentity/dnsDid/index.js create mode 100644 dist/esm/verifiers/issuerIdentity/dnsTxt/index.js create mode 100644 dist/esm/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.js create mode 100644 dist/esm/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.js create mode 100644 dist/esm/verifiers/verificationBuilder.js create mode 100644 dist/types/src/common/error.d.ts create mode 100644 dist/types/src/common/errorHandler.d.ts create mode 100644 dist/types/src/common/logger.d.ts create mode 100644 dist/types/src/common/messages.d.ts create mode 100644 dist/types/src/common/utils.d.ts create mode 100644 dist/types/src/common/utils.test.d.ts create mode 100644 dist/types/src/config.d.ts create mode 100644 dist/types/src/did/resolver.d.ts create mode 100644 dist/types/src/did/resolver.test.d.ts create mode 100644 dist/types/src/did/verifier.d.ts create mode 100644 dist/types/src/getIdentifier.d.ts create mode 100644 dist/types/src/getIdentifier.test.d.ts create mode 100644 dist/types/src/index.d.ts create mode 100644 dist/types/src/types/core.d.ts create mode 100644 dist/types/src/types/error.d.ts create mode 100644 dist/types/src/validator.d.ts create mode 100644 dist/types/src/validator.test.d.ts create mode 100644 dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.d.ts create mode 100644 dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.test.d.ts create mode 100644 dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.type.d.ts create mode 100644 dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.d.ts create mode 100644 dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.test.d.ts create mode 100644 dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.d.ts create mode 100644 dist/types/src/verifiers/documentStatus/didSigned/index.d.ts create mode 100644 dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.d.ts create mode 100644 dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.test.d.ts create mode 100644 dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.d.ts create mode 100644 dist/types/src/verifiers/documentStatus/documentStore/index.d.ts create mode 100644 dist/types/src/verifiers/documentStatus/revocation.types.d.ts create mode 100644 dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.d.ts create mode 100644 dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.test.d.ts create mode 100644 dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.d.ts create mode 100644 dist/types/src/verifiers/documentStatus/tokenRegistry/index.d.ts create mode 100644 dist/types/src/verifiers/documentStatus/utils.d.ts create mode 100644 dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.d.ts create mode 100644 dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.test.d.ts create mode 100644 dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.type.d.ts create mode 100644 dist/types/src/verifiers/issuerIdentity/did/index.d.ts create mode 100644 dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.d.ts create mode 100644 dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.test.d.ts create mode 100644 dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.d.ts create mode 100644 dist/types/src/verifiers/issuerIdentity/dnsDid/index.d.ts create mode 100644 dist/types/src/verifiers/issuerIdentity/dnsTxt/index.d.ts create mode 100644 dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.d.ts create mode 100644 dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.test.d.ts create mode 100644 dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.d.ts create mode 100644 dist/types/src/verifiers/verificationBuilder.d.ts create mode 100644 dist/types/src/verify.v2.integration.errors.test.d.ts create mode 100644 dist/types/src/verify.v2.integration.test.d.ts create mode 100644 dist/types/src/verify.v3.integration.test.d.ts create mode 100644 dist/types/test/fixtures/v2/document.d.ts create mode 100644 dist/types/test/fixtures/v2/documentDidCustomRevocation.d.ts create mode 100644 dist/types/test/fixtures/v2/documentDidMissingProof.d.ts create mode 100644 dist/types/test/fixtures/v2/documentDidMixedTokenRegistry.d.ts create mode 100644 dist/types/test/fixtures/v2/documentDidObfuscatedRevocation.d.ts create mode 100644 dist/types/test/fixtures/v2/documentDidSigned.d.ts create mode 100644 dist/types/test/fixtures/v2/documentDidWrongSignature.d.ts create mode 100644 dist/types/test/fixtures/v2/documentDnsDidMixedTokenRegistry.d.ts create mode 100644 dist/types/test/fixtures/v2/documentDnsDidNoDnsTxt.d.ts create mode 100644 dist/types/test/fixtures/v2/documentDnsDidSigned.d.ts create mode 100644 dist/types/test/fixtures/v2/documentMainnetInvalidWithIncorrectMerkleRoot.d.ts create mode 100644 dist/types/test/fixtures/v2/documentMainnetInvalidWithOddLengthMerkleRoot.d.ts create mode 100644 dist/types/test/fixtures/v2/documentMainnetValidWithCertificateStore.d.ts create mode 100644 dist/types/test/fixtures/v2/documentRinkebyWithDocumentStore.d.ts create mode 100644 dist/types/test/fixtures/v2/documentRopstenMixedIssuance.d.ts create mode 100644 dist/types/test/fixtures/v2/documentRopstenNotIssuedWithCertificateStore.d.ts create mode 100644 dist/types/test/fixtures/v2/documentRopstenNotIssuedWithDocumentStore.d.ts create mode 100644 dist/types/test/fixtures/v2/documentRopstenNotIssuedWithTokenRegistry.d.ts create mode 100644 dist/types/test/fixtures/v2/documentRopstenObfuscated.d.ts create mode 100644 dist/types/test/fixtures/v2/documentRopstenRevokedWithCertificateStore.d.ts create mode 100644 dist/types/test/fixtures/v2/documentRopstenRevokedWithDocumentStore.d.ts create mode 100644 dist/types/test/fixtures/v2/documentRopstenRevokedWithToken.d.ts create mode 100644 dist/types/test/fixtures/v2/documentRopstenValidWithCertificateStore.d.ts create mode 100644 dist/types/test/fixtures/v2/documentRopstenValidWithDocumentStore.d.ts create mode 100644 dist/types/test/fixtures/v2/documentRopstenValidWithToken.d.ts create mode 100644 dist/types/test/fixtures/v2/tamperedDocument.d.ts create mode 100644 dist/types/test/utils/index.d.ts diff --git a/dist/cjs/common/error.js b/dist/cjs/common/error.js new file mode 100644 index 00000000..9f9d60a4 --- /dev/null +++ b/dist/cjs/common/error.js @@ -0,0 +1,29 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.CodedError = void 0; +var CodedError = /** @class */ (function (_super) { + __extends(CodedError, _super); + function CodedError(message, code, codeString) { + var _this = _super.call(this, message) || this; + _this.code = code; + _this.codeString = codeString; + return _this; + } + return CodedError; +}(Error)); +exports.CodedError = CodedError; diff --git a/dist/cjs/common/errorHandler.js b/dist/cjs/common/errorHandler.js new file mode 100644 index 00000000..68038c4c --- /dev/null +++ b/dist/cjs/common/errorHandler.js @@ -0,0 +1,88 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.withCodedErrorHandler = void 0; +var withCodedErrorHandler = function (verify, errorOptions) { return function (document, options +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore https://github.com/microsoft/TypeScript/issues/26781 +) { return __awaiter(void 0, void 0, void 0, function () { + var e_1, message, code, codeString, name, type, unexpectedErrorCode, unexpectedErrorString; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + _a.trys.push([0, 2, , 3]); + return [4 /*yield*/, verify(document, options)]; + case 1: + // Using return await to ensure async function execute in try block + return [2 /*return*/, _a.sent()]; + case 2: + e_1 = _a.sent(); + message = e_1.message, code = e_1.code, codeString = e_1.codeString; + name = errorOptions.name, type = errorOptions.type, unexpectedErrorCode = errorOptions.unexpectedErrorCode, unexpectedErrorString = errorOptions.unexpectedErrorString; + if (message && code && codeString) { + return [2 /*return*/, { + name: name, + type: type, + data: e_1, + reason: { + message: message, + code: code, + codeString: codeString, + }, + status: "ERROR", + }]; + } + else { + return [2 /*return*/, { + name: name, + type: type, + data: e_1, + reason: { + message: e_1.message, + code: unexpectedErrorCode, + codeString: unexpectedErrorString, + }, + status: "ERROR", + }]; + } + return [3 /*break*/, 3]; + case 3: return [2 /*return*/]; + } + }); +}); }; }; +exports.withCodedErrorHandler = withCodedErrorHandler; diff --git a/dist/cjs/common/logger.js b/dist/cjs/common/logger.js new file mode 100644 index 00000000..fb045a22 --- /dev/null +++ b/dist/cjs/common/logger.js @@ -0,0 +1,16 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getLogger = void 0; +var debug_1 = __importDefault(require("debug")); +var logger = debug_1.default("oa-verify"); +var getLogger = function (namespace) { return ({ + trace: logger.extend("trace:" + namespace), + debug: logger.extend("debug:" + namespace), + info: logger.extend("info:" + namespace), + warn: logger.extend("warn:" + namespace), + error: logger.extend("error:" + namespace), +}); }; +exports.getLogger = getLogger; diff --git a/dist/cjs/common/messages.js b/dist/cjs/common/messages.js new file mode 100644 index 00000000..14089916 --- /dev/null +++ b/dist/cjs/common/messages.js @@ -0,0 +1,4 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.warnProvider = void 0; +exports.warnProvider = "You are falling back to oa-verify default configuration, which is not suitable for production environment. It is highly recommended that you configure and provide your own API key. Refer to https://github.com/Open-Attestation/oa-verify#provider"; diff --git a/dist/cjs/common/utils.js b/dist/cjs/common/utils.js new file mode 100644 index 00000000..1b2519df --- /dev/null +++ b/dist/cjs/common/utils.js @@ -0,0 +1,180 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.unhandledError = exports.serverError = exports.invalidArgument = exports.certificateRevoked = exports.certificateNotIssued = exports.contractNotFound = exports.isDocumentStoreAddressOrTokenRegistryAddressInvalid = exports.isErrorFragment = exports.isSkippedFragment = exports.isInvalidFragment = exports.isValidFragment = exports.getIssuerIdentityFragments = exports.getDocumentStatusFragments = exports.getDocumentIntegrityFragments = exports.getOpenAttestationDnsTxtIdentityProofFragment = exports.getOpenAttestationDnsDidIdentityProofFragment = exports.getOpenAttestationDidIdentityProofFragment = exports.getOpenAttestationEthereumTokenRegistryStatusFragment = exports.getOpenAttestationEthereumDocumentStoreStatusFragment = exports.getOpenAttestationDidSignedDocumentStatusFragment = exports.getOpenAttestationHashFragment = exports.getFragmentByName = exports.generateProvider = exports.getProvider = exports.getDefaultProvider = void 0; +var ethers_1 = require("ethers"); +var config_1 = require("../config"); +var error_1 = require("../types/error"); +var messages_1 = require("../common/messages"); +var getDefaultProvider = function (options) { + var network = options.network || process.env.PROVIDER_NETWORK || "homestead"; + var providerType = process.env.PROVIDER_ENDPOINT_TYPE || "infura"; + var apiKey = process.env.PROVIDER_API_KEY || (providerType === "infura" && config_1.INFURA_API_KEY) || ""; + // create infura provider to get connection information + // we then use StaticJsonRpcProvider so that we can set our own custom limit + var uselessProvider = exports.generateProvider({ + providerType: providerType, + network: network, + apiKey: apiKey, + }); + var connection = __assign(__assign({}, uselessProvider.connection), { throttleLimit: 3 }); + return new ethers_1.providers.StaticJsonRpcProvider(connection, network); +}; +exports.getDefaultProvider = getDefaultProvider; +// getProvider is a function to get an existing provider or to get a Default provider, when given the options +var getProvider = function (options) { + var _a; + return (_a = options.provider) !== null && _a !== void 0 ? _a : exports.getDefaultProvider(options); +}; +exports.getProvider = getProvider; +/** + * Generate Provider generates a provider based on the defined options or your env var, if no options or env var was detected, it will generate a provider based on the default values. + * Generate Provider using the following options: (if no option is specified it will use the default values) + * @param {Object} ProviderDetails - Details to use for the function to successfully generate a provider. + * @param {string} ProviderDetails.network - The network in which the provider is connected to, i.e. "homestead", "mainnet", "ropsten", "rinkeby" + * @param {string} ProviderDetails.providerType - Specify which provider to use: "infura", "alchemy" or "jsonrpc" + * @param {string} ProviderDetails.url - Specify which url for JsonRPC to connect to, if not specified will connect to localhost:8545 + * @param {string} ProviderDetails.apiKey - If no apiKey is provided, a default shared API key will be used, which may result in reduced performance and throttled requests. + */ +var generateProvider = function (options) { + if (!!options && Object.keys(options).length === 1 && options.apiKey) { + throw new Error("We could not link the apiKey provided to a provider, please state the provider to use in the parameter."); + } + var network = (options === null || options === void 0 ? void 0 : options.network) || process.env.PROVIDER_NETWORK || "homestead"; + var provider = (options === null || options === void 0 ? void 0 : options.providerType) || process.env.PROVIDER_ENDPOINT_TYPE || "infura"; + var url = (options === null || options === void 0 ? void 0 : options.url) || process.env.PROVIDER_ENDPOINT_URL || ""; + var apiKey = (options === null || options === void 0 ? void 0 : options.apiKey) || (provider === "infura" && process.env.INFURA_API_KEY) || process.env.PROVIDER_API_KEY || ""; + !apiKey && console.warn(messages_1.warnProvider); + if (!!options && Object.keys(options).length === 1 && url) { + return new ethers_1.providers.JsonRpcProvider(url); + } + switch (provider) { + case "infura": + return apiKey ? new ethers_1.providers.InfuraProvider(network, apiKey) : new ethers_1.providers.InfuraProvider(network); + case "alchemy": + return apiKey ? new ethers_1.providers.AlchemyProvider(network, apiKey) : new ethers_1.providers.AlchemyProvider(network); + case "jsonrpc": + return new ethers_1.providers.JsonRpcProvider(url); + default: + throw new Error("The provider provided is not on the list of providers. Please use one of the following: infura, alchemy or jsonrpc."); + } +}; +exports.generateProvider = generateProvider; +/** + * Simple typed utility to return a fragment depending on the name + * @param name + */ +var getFragmentByName = function (name) { return function (fragments) { return fragments.find(function (fragment) { return fragment.name === name; }); }; }; +exports.getFragmentByName = getFragmentByName; +exports.getOpenAttestationHashFragment = exports.getFragmentByName("OpenAttestationHash"); +exports.getOpenAttestationDidSignedDocumentStatusFragment = exports.getFragmentByName("OpenAttestationDidSignedDocumentStatus"); +exports.getOpenAttestationEthereumDocumentStoreStatusFragment = exports.getFragmentByName("OpenAttestationEthereumDocumentStoreStatus"); +exports.getOpenAttestationEthereumTokenRegistryStatusFragment = exports.getFragmentByName("OpenAttestationEthereumTokenRegistryStatus"); +exports.getOpenAttestationDidIdentityProofFragment = exports.getFragmentByName("OpenAttestationDidIdentityProof"); +exports.getOpenAttestationDnsDidIdentityProofFragment = exports.getFragmentByName("OpenAttestationDnsDidIdentityProof"); +exports.getOpenAttestationDnsTxtIdentityProofFragment = exports.getFragmentByName("OpenAttestationDnsTxtIdentityProof"); +/** + * Simple typed utility to return fragments depending on the type + */ +var getFragmentByType = function (type) { return function (fragments) { return fragments.filter(function (fragment) { return fragment.type === type; }); }; }; +exports.getDocumentIntegrityFragments = getFragmentByType("DOCUMENT_INTEGRITY"); +exports.getDocumentStatusFragments = getFragmentByType("DOCUMENT_STATUS"); +exports.getIssuerIdentityFragments = getFragmentByType("ISSUER_IDENTITY"); +var isValidFragment = function (fragment) { + return (fragment === null || fragment === void 0 ? void 0 : fragment.status) === "VALID"; +}; +exports.isValidFragment = isValidFragment; +var isInvalidFragment = function (fragment) { + return (fragment === null || fragment === void 0 ? void 0 : fragment.status) === "INVALID"; +}; +exports.isInvalidFragment = isInvalidFragment; +var isSkippedFragment = function (fragment) { + return (fragment === null || fragment === void 0 ? void 0 : fragment.status) === "SKIPPED"; +}; +exports.isSkippedFragment = isSkippedFragment; +var isErrorFragment = function (fragment) { + return (fragment === null || fragment === void 0 ? void 0 : fragment.status) === "ERROR"; +}; +exports.isErrorFragment = isErrorFragment; +// this function check if the reason of the error is that the document store or token registry is invalid +var isDocumentStoreAddressOrTokenRegistryAddressInvalid = function (fragments) { + var _a, _b, _c, _d; + var documentStoreIssuedFragment = exports.getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); + var tokenRegistryMintedFragment = exports.getOpenAttestationEthereumTokenRegistryStatusFragment(fragments); + // 2 is the error code used by oa-verify in case of invalid address + return ((((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED && + ((_b = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _b === void 0 ? void 0 : _b.message.toLowerCase()) === "Invalid document store address".toLowerCase()) || + (((_c = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _c === void 0 ? void 0 : _c.code) === error_1.OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED && + ((_d = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _d === void 0 ? void 0 : _d.message.toLowerCase()) === "Invalid token registry address".toLowerCase())); +}; +exports.isDocumentStoreAddressOrTokenRegistryAddressInvalid = isDocumentStoreAddressOrTokenRegistryAddressInvalid; +// this function check if the reason of the error is contract not found in document store +var contractNotFound = function (fragments) { + var _a, _b; + var documentStoreIssuedFragment = exports.getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); + // 404 is the error code used by oa-verify in case of contract not found + return (((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED && + ((_b = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _b === void 0 ? void 0 : _b.message.toLowerCase()) === "Contract is not found".toLowerCase()); +}; +exports.contractNotFound = contractNotFound; +// this function check if the reason of the error is that the document is not issued in document store or token registry +var certificateNotIssued = function (fragments) { + var _a, _b; + var documentStoreIssuedFragment = exports.getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); + var tokenRegistryMintedFragment = exports.getOpenAttestationEthereumTokenRegistryStatusFragment(fragments); + // 1 is the error code used by oa-verify in case of document / token not issued / minted + return (((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED || + ((_b = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _b === void 0 ? void 0 : _b.code) === error_1.OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED); +}; +exports.certificateNotIssued = certificateNotIssued; +// this function check if the reason of the error is that the document is revoked in document store +var certificateRevoked = function (fragments) { + var _a; + var documentStoreIssuedFragment = exports.getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); + // 1 is the error code used by oa-verify in case of document / token not issued / minted + return ((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED; +}; +exports.certificateRevoked = certificateRevoked; +// this function check if the error is caused by an invalid merkle root (incorrect length/odd length/invalid characters) +var invalidArgument = function (fragments) { + var _a, _b, _c, _d; + var documentStoreIssuedFragment = exports.getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); + var tokenRegistryMintedFragment = exports.getOpenAttestationEthereumTokenRegistryStatusFragment(fragments); + // why INVALID_ARGUMENT is because we follow the error codes returned by Ethers (https://docs.ethers.io/v5/api/utils/logger/#errors) + return ((((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED && + ((_b = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _b === void 0 ? void 0 : _b.message.toLowerCase()) === "Invalid call arguments".toLowerCase()) || + (((_c = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _c === void 0 ? void 0 : _c.code) === error_1.OpenAttestationEthereumTokenRegistryStatusCode.INVALID_ARGUMENT && + ((_d = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _d === void 0 ? void 0 : _d.message.toLowerCase()) === "Invalid contract arguments".toLowerCase())); +}; +exports.invalidArgument = invalidArgument; +// this function check if the reason of the error is that we can't connect to Ethereum (due to any HTTP 4xx or 5xx errors) +var serverError = function (fragments) { + var _a, _b; + var documentStoreIssuedFragment = exports.getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); + var tokenRegistryMintedFragment = exports.getOpenAttestationEthereumTokenRegistryStatusFragment(fragments); + // 429 is the error code used by oa-verify in case of Ethers returning a missing response error + return (((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === error_1.OpenAttestationEthereumDocumentStoreStatusCode.SERVER_ERROR || + ((_b = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _b === void 0 ? void 0 : _b.code) === error_1.OpenAttestationEthereumTokenRegistryStatusCode.SERVER_ERROR); +}; +exports.serverError = serverError; +// this function catches all other unhandled errors +var unhandledError = function (fragments) { + var _a, _b; + var documentStoreIssuedFragment = exports.getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); + var tokenRegistryMintedFragment = exports.getOpenAttestationEthereumTokenRegistryStatusFragment(fragments); + // 3 is the error code used by oa-verify in case of weird errors that we didn't foresee to handle + return (((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === + error_1.OpenAttestationEthereumDocumentStoreStatusCode.ETHERS_UNHANDLED_ERROR || + ((_b = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _b === void 0 ? void 0 : _b.code) === error_1.OpenAttestationEthereumDocumentStoreStatusCode.ETHERS_UNHANDLED_ERROR); +}; +exports.unhandledError = unhandledError; diff --git a/dist/cjs/config.js b/dist/cjs/config.js new file mode 100644 index 00000000..eb631a35 --- /dev/null +++ b/dist/cjs/config.js @@ -0,0 +1,4 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.INFURA_API_KEY = void 0; +exports.INFURA_API_KEY = process.env.INFURA_API_KEY || "bb46da3f80e040e8ab73c0a9ff365d18"; diff --git a/dist/cjs/did/resolver.js b/dist/cjs/did/resolver.js new file mode 100644 index 00000000..652b1a52 --- /dev/null +++ b/dist/cjs/did/resolver.js @@ -0,0 +1,122 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getVerificationMethod = exports.resolve = exports.createResolver = exports.getProviderConfig = void 0; +var did_resolver_1 = require("did-resolver"); +var ethr_did_resolver_1 = require("ethr-did-resolver"); +var web_did_resolver_1 = require("web-did-resolver"); +var node_cache_1 = __importDefault(require("node-cache")); +var config_1 = require("../config"); +var utils_1 = require("../common/utils"); +var getProviderConfig = function () { + var _a, _b, _c; + var provider = utils_1.generateProvider(); + var rpcUrl = ((_a = provider === null || provider === void 0 ? void 0 : provider.connection) === null || _a === void 0 ? void 0 : _a.url) || ""; + var networkName = ((_b = provider === null || provider === void 0 ? void 0 : provider._network) === null || _b === void 0 ? void 0 : _b.name) === "homestead" ? "mainnet" : ((_c = provider === null || provider === void 0 ? void 0 : provider._network) === null || _c === void 0 ? void 0 : _c.name) || ""; + if (!rpcUrl || !networkName) { + return { networks: [{ name: "mainnet", rpcUrl: "https://mainnet.infura.io/v3/" + config_1.INFURA_API_KEY }] }; + } + return { + networks: [{ name: networkName, rpcUrl: rpcUrl }], + }; +}; +exports.getProviderConfig = getProviderConfig; +var didResolutionCache = new node_cache_1.default({ stdTTL: 5 * 60 }); // 5 min +var defaultResolver = new did_resolver_1.Resolver(__assign(__assign({}, ethr_did_resolver_1.getResolver(exports.getProviderConfig())), web_did_resolver_1.getResolver())); +var createResolver = function (_a) { + var ethrResolverConfig = _a.ethrResolverConfig; + return ethrResolverConfig + ? new did_resolver_1.Resolver(__assign(__assign({}, ethr_did_resolver_1.getResolver(ethrResolverConfig)), web_did_resolver_1.getResolver())) + : defaultResolver; +}; +exports.createResolver = createResolver; +var resolve = function (didUrl, resolver) { return __awaiter(void 0, void 0, void 0, function () { + var cachedResult, didResolutionResult, _a, did; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + cachedResult = didResolutionCache.get(didUrl); + if (cachedResult) + return [2 /*return*/, cachedResult]; + if (!resolver) return [3 /*break*/, 2]; + return [4 /*yield*/, resolver.resolve(didUrl)]; + case 1: + _a = _b.sent(); + return [3 /*break*/, 4]; + case 2: return [4 /*yield*/, defaultResolver.resolve(didUrl)]; + case 3: + _a = _b.sent(); + _b.label = 4; + case 4: + didResolutionResult = _a; + did = didResolutionResult.didDocument || undefined; + didResolutionCache.set(didUrl, did); + return [2 /*return*/, did]; + } + }); +}); }; +exports.resolve = resolve; +var getVerificationMethod = function (did, key, resolver) { return __awaiter(void 0, void 0, void 0, function () { + var didDocument; + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: return [4 /*yield*/, exports.resolve(did, resolver)]; + case 1: + didDocument = _b.sent(); + if (!didDocument) + return [2 /*return*/]; + return [2 /*return*/, (_a = didDocument.verificationMethod) === null || _a === void 0 ? void 0 : _a.find(function (k) { return k.id.toLowerCase() === key.toLowerCase(); })]; + } + }); +}); }; +exports.getVerificationMethod = getVerificationMethod; diff --git a/dist/cjs/did/verifier.js b/dist/cjs/did/verifier.js new file mode 100644 index 00000000..f8402727 --- /dev/null +++ b/dist/cjs/did/verifier.js @@ -0,0 +1,119 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.verifySignature = exports.verifySecp256k1VerificationKey2018 = exports.DidVerificationStatusArray = exports.DidVerificationStatus = exports.InvalidDidVerificationStatus = exports.ValidDidVerificationStatusArray = exports.ValidDidVerificationStatus = void 0; +var ethers_1 = require("ethers"); +var runtypes_1 = require("runtypes"); +var resolver_1 = require("./resolver"); +var error_1 = require("../types/error"); +var error_2 = require("../common/error"); +exports.ValidDidVerificationStatus = runtypes_1.Record({ + verified: runtypes_1.Literal(true), + did: runtypes_1.String, +}); +exports.ValidDidVerificationStatusArray = runtypes_1.Array(exports.ValidDidVerificationStatus).withConstraint(function (elements) { return elements.length > 0 || "Expect at least one valid element"; }); +exports.InvalidDidVerificationStatus = runtypes_1.Record({ + verified: runtypes_1.Literal(false), + did: runtypes_1.String, + reason: error_1.Reason, +}); +exports.DidVerificationStatus = runtypes_1.Union(exports.ValidDidVerificationStatus, exports.InvalidDidVerificationStatus); +exports.DidVerificationStatusArray = runtypes_1.Array(exports.DidVerificationStatus); +var verifySecp256k1VerificationKey2018 = function (_a) { + var did = _a.did, verificationMethod = _a.verificationMethod, merkleRoot = _a.merkleRoot, signature = _a.signature; + var messageBytes = ethers_1.utils.arrayify(merkleRoot); + var blockchainAccountId = verificationMethod.blockchainAccountId; + if (!blockchainAccountId) { + return { + did: did, + verified: false, + reason: { + code: error_1.OpenAttestationSignatureCode.KEY_MISSING, + codeString: error_1.OpenAttestationSignatureCode[error_1.OpenAttestationSignatureCode.KEY_MISSING], + message: "ethereumAddress not found on public key " + JSON.stringify(verificationMethod), + }, + }; + } + // blockchainAccountId looks like 0x0cE1854a3836daF9130028Cf90D6d35B1Ae46457@eip155:3, let's get rid of the part after @, @ included + var ethereumAddress = blockchainAccountId.split("@")[0]; + var merkleRootSigned = ethers_1.utils.verifyMessage(messageBytes, signature).toLowerCase() === ethereumAddress.toLowerCase(); + if (!merkleRootSigned) { + return { + did: did, + verified: false, + reason: { + code: error_1.OpenAttestationSignatureCode.WRONG_SIGNATURE, + codeString: error_1.OpenAttestationSignatureCode[error_1.OpenAttestationSignatureCode.WRONG_SIGNATURE], + message: "merkle root is not signed correctly by " + ethereumAddress, + }, + }; + } + return { + did: did, + verified: true, + }; +}; +exports.verifySecp256k1VerificationKey2018 = verifySecp256k1VerificationKey2018; +var verifySignature = function (_a) { + var key = _a.key, merkleRoot = _a.merkleRoot, signature = _a.signature, did = _a.did, resolver = _a.resolver; + return __awaiter(void 0, void 0, void 0, function () { + var verificationMethod; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: return [4 /*yield*/, resolver_1.getVerificationMethod(did, key, resolver)]; + case 1: + verificationMethod = _b.sent(); + if (!verificationMethod) + throw new error_2.CodedError("No public key found on DID document for the DID " + did + " and key " + key, error_1.OpenAttestationSignatureCode.KEY_NOT_IN_DID, "KEY_NOT_IN_DID"); + switch (verificationMethod.type) { + case "EcdsaSecp256k1RecoveryMethod2020": + return [2 /*return*/, exports.verifySecp256k1VerificationKey2018({ + did: did, + verificationMethod: verificationMethod, + merkleRoot: merkleRoot, + signature: signature, + })]; + default: + throw new error_2.CodedError("Signature type " + verificationMethod.type + " is currently not support", error_1.OpenAttestationSignatureCode.UNSUPPORTED_KEY_TYPE, "UNSUPPORTED_KEY_TYPE"); + } + return [2 /*return*/]; + } + }); + }); +}; +exports.verifySignature = verifySignature; diff --git a/dist/cjs/getIdentifier.js b/dist/cjs/getIdentifier.js new file mode 100644 index 00000000..f06dd43f --- /dev/null +++ b/dist/cjs/getIdentifier.js @@ -0,0 +1,93 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getIdentifier = void 0; +var core_1 = require("./types/core"); +var verifier_1 = require("./did/verifier"); +var dnsDidProof_type_1 = require("./verifiers/issuerIdentity/dnsDid/dnsDidProof.type"); +var openAttestationDnsTxt_type_1 = require("./verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type"); +var IdentityProof; +(function (IdentityProof) { + IdentityProof["DNS"] = "OpenAttestationDnsTxtIdentityProof"; + IdentityProof["DNSDID"] = "OpenAttestationDnsDidIdentityProof"; + IdentityProof["DID"] = "OpenAttestationDidIdentityProof"; +})(IdentityProof || (IdentityProof = {})); +var getDnsIdentifierProof = function (_a) { + var data = _a.data; + var type = "DNS"; + if (openAttestationDnsTxt_type_1.DnsTxtVerificationStatusDataV3.guard(data)) { + return { + identifier: data.identifier, + type: type, + }; + } + else if (openAttestationDnsTxt_type_1.DnsTxtVerificationStatusArray.guard(data)) { + return data.map(function (issuer) { return ({ + identifier: issuer.location, + type: type, + }); }); + } + throw new Error("Fragment for DNS not supported"); +}; +var getDnsDidIdentifierProof = function (_a) { + var data = _a.data; + var type = "DNS-DID"; + if (dnsDidProof_type_1.DnsDidVerificationStatusArray.guard(data)) { + return data.map(function (issuer) { return ({ + identifier: issuer.location, + type: type, + }); }); + } + else if (dnsDidProof_type_1.DnsDidVerificationStatus.guard(data)) { + return { + identifier: data.location, + type: type, + }; + } + throw new Error("Fragment for DNS-DID not supported"); +}; +var getDidIdentifierProof = function (_a) { + var data = _a.data; + var type = "DID"; + if (verifier_1.DidVerificationStatusArray.guard(data)) { + return data.map(function (issuer) { return ({ + identifier: issuer.did, + type: type, + }); }); + } + else if (verifier_1.DidVerificationStatus.guard(data)) { + return { + identifier: data.did, + type: type, + }; + } + throw new Error("Fragment for DID not supported"); +}; +var getIdentityProofFragment = function (fragments) { + if (fragments.length < 1) { + throw new Error("Please provide at least one verification fragment"); + } + return fragments.find(function (status) { return status.type === "ISSUER_IDENTITY" && status.status === "VALID"; }); +}; +var getIdentifier = function (fragments) { + var fragment = getIdentityProofFragment(fragments); + if (!fragment) { + throw new Error("Did not find any Issuer Identity fragment that is valid"); + } + if (!core_1.isVerificationFragmentWithData(fragment)) { + throw new Error("No data property found in fragment, malformed fragment"); + } + switch (fragment.name) { + case IdentityProof.DNS: + return getDnsIdentifierProof(fragment); + case IdentityProof.DNSDID: + return getDnsDidIdentifierProof(fragment); + case IdentityProof.DID: + return getDidIdentifierProof(fragment); + default: + return { + identifier: "Unknown", + type: "Unknown", + }; + } +}; +exports.getIdentifier = getIdentifier; diff --git a/dist/cjs/index.js b/dist/cjs/index.js new file mode 100644 index 00000000..36c255ec --- /dev/null +++ b/dist/cjs/index.js @@ -0,0 +1,79 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.utils = exports.getIdentifier = exports.createResolver = exports.openAttestationDidIdentityProof = exports.openAttestationDnsDidIdentityProof = exports.openAttestationDnsTxtIdentityProof = exports.openAttestationDidSignedDocumentStatus = exports.openAttestationEthereumTokenRegistryStatus = exports.openAttestationEthereumDocumentStoreStatus = exports.openAttestationHash = exports.verify = exports.isValid = exports.openAttestationVerifiers = exports.verificationBuilder = void 0; +var verificationBuilder_1 = require("./verifiers/verificationBuilder"); +Object.defineProperty(exports, "verificationBuilder", { enumerable: true, get: function () { return verificationBuilder_1.verificationBuilder; } }); +var openAttestationHash_1 = require("./verifiers/documentIntegrity/hash/openAttestationHash"); +Object.defineProperty(exports, "openAttestationHash", { enumerable: true, get: function () { return openAttestationHash_1.openAttestationHash; } }); +var validator_1 = require("./validator"); +Object.defineProperty(exports, "isValid", { enumerable: true, get: function () { return validator_1.isValid; } }); +var tokenRegistry_1 = require("./verifiers/documentStatus/tokenRegistry"); +Object.defineProperty(exports, "openAttestationEthereumTokenRegistryStatus", { enumerable: true, get: function () { return tokenRegistry_1.openAttestationEthereumTokenRegistryStatus; } }); +var documentStore_1 = require("./verifiers/documentStatus/documentStore"); +Object.defineProperty(exports, "openAttestationEthereumDocumentStoreStatus", { enumerable: true, get: function () { return documentStore_1.openAttestationEthereumDocumentStoreStatus; } }); +var didSigned_1 = require("./verifiers/documentStatus/didSigned"); +Object.defineProperty(exports, "openAttestationDidSignedDocumentStatus", { enumerable: true, get: function () { return didSigned_1.openAttestationDidSignedDocumentStatus; } }); +var dnsTxt_1 = require("./verifiers/issuerIdentity/dnsTxt"); +Object.defineProperty(exports, "openAttestationDnsTxtIdentityProof", { enumerable: true, get: function () { return dnsTxt_1.openAttestationDnsTxtIdentityProof; } }); +var did_1 = require("./verifiers/issuerIdentity/did"); +Object.defineProperty(exports, "openAttestationDidIdentityProof", { enumerable: true, get: function () { return did_1.openAttestationDidIdentityProof; } }); +var dnsDid_1 = require("./verifiers/issuerIdentity/dnsDid"); +Object.defineProperty(exports, "openAttestationDnsDidIdentityProof", { enumerable: true, get: function () { return dnsDid_1.openAttestationDnsDidIdentityProof; } }); +var resolver_1 = require("./did/resolver"); +Object.defineProperty(exports, "createResolver", { enumerable: true, get: function () { return resolver_1.createResolver; } }); +var getIdentifier_1 = require("./getIdentifier"); +Object.defineProperty(exports, "getIdentifier", { enumerable: true, get: function () { return getIdentifier_1.getIdentifier; } }); +var utils = __importStar(require("./common/utils")); +exports.utils = utils; +var util_1 = __importDefault(require("util")); +// eslint-disable-next-line @typescript-eslint/no-empty-function +util_1.default.deprecate(function infuraApiKey() { }, "'INFURA_API_KEY' has been deprecated, please use 'PROVIDER_API_KEY'."); +var openAttestationVerifiers = [ + openAttestationHash_1.openAttestationHash, + tokenRegistry_1.openAttestationEthereumTokenRegistryStatus, + documentStore_1.openAttestationEthereumDocumentStoreStatus, + didSigned_1.openAttestationDidSignedDocumentStatus, + dnsTxt_1.openAttestationDnsTxtIdentityProof, + dnsDid_1.openAttestationDnsDidIdentityProof, +]; +exports.openAttestationVerifiers = openAttestationVerifiers; +var defaultBuilderOption = { + network: process.env.PROVIDER_NETWORK || "homestead", +}; +var verify = verificationBuilder_1.verificationBuilder(openAttestationVerifiers, defaultBuilderOption); +exports.verify = verify; +__exportStar(require("./types/core"), exports); +__exportStar(require("./verifiers/documentIntegrity/hash/openAttestationHash.type"), exports); +__exportStar(require("./verifiers/documentStatus/didSigned/didSignedDocumentStatus.type"), exports); +__exportStar(require("./verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type"), exports); +__exportStar(require("./verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type"), exports); +__exportStar(require("./verifiers/issuerIdentity/did/didIdentityProof.type"), exports); +__exportStar(require("./verifiers/issuerIdentity/dnsDid/dnsDidProof.type"), exports); +__exportStar(require("./verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type"), exports); +__exportStar(require("./types/error"), exports); +__exportStar(require("./common/error"), exports); diff --git a/dist/cjs/types/core.js b/dist/cjs/types/core.js new file mode 100644 index 00000000..828c1c34 --- /dev/null +++ b/dist/cjs/types/core.js @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.isVerificationFragmentWithData = void 0; +var isVerificationFragmentWithData = function (fragment) { + return fragment.data; +}; +exports.isVerificationFragmentWithData = isVerificationFragmentWithData; diff --git a/dist/cjs/types/error.js b/dist/cjs/types/error.js new file mode 100644 index 00000000..a703d661 --- /dev/null +++ b/dist/cjs/types/error.js @@ -0,0 +1,107 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Reason = exports.OpenAttestationSignatureCode = exports.OpenAttestationDnsDidCode = exports.OpenAttestationDidCode = exports.OpenAttestationDidSignedDocumentStatusCode = exports.OpenAttestationHashCode = exports.OpenAttestationDnsTxtCode = exports.OpenAttestationEthereumTokenRegistryStatusCode = exports.OpenAttestationDocumentSignedCode = exports.OpenAttestationEthereumDocumentStoreStatusCode = void 0; +// NEVER EVER REPLACE OR CHANGE A VALUE :) +// code for errors and invalid fragment +var runtypes_1 = require("runtypes"); +var OpenAttestationEthereumDocumentStoreStatusCode; +(function (OpenAttestationEthereumDocumentStoreStatusCode) { + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["UNEXPECTED_ERROR"] = 0] = "UNEXPECTED_ERROR"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["DOCUMENT_NOT_ISSUED"] = 1] = "DOCUMENT_NOT_ISSUED"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["CONTRACT_ADDRESS_INVALID"] = 2] = "CONTRACT_ADDRESS_INVALID"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["ETHERS_UNHANDLED_ERROR"] = 3] = "ETHERS_UNHANDLED_ERROR"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["SKIPPED"] = 4] = "SKIPPED"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["DOCUMENT_REVOKED"] = 5] = "DOCUMENT_REVOKED"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["INVALID_ARGUMENT"] = 6] = "INVALID_ARGUMENT"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["CONTRACT_NOT_FOUND"] = 404] = "CONTRACT_NOT_FOUND"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["INVALID_ISSUERS"] = 7] = "INVALID_ISSUERS"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["INVALID_VALIDATION_METHOD"] = 8] = "INVALID_VALIDATION_METHOD"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["UNRECOGNIZED_DOCUMENT"] = 9] = "UNRECOGNIZED_DOCUMENT"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["SERVER_ERROR"] = 500] = "SERVER_ERROR"; +})(OpenAttestationEthereumDocumentStoreStatusCode = exports.OpenAttestationEthereumDocumentStoreStatusCode || (exports.OpenAttestationEthereumDocumentStoreStatusCode = {})); +var OpenAttestationDocumentSignedCode; +(function (OpenAttestationDocumentSignedCode) { + OpenAttestationDocumentSignedCode[OpenAttestationDocumentSignedCode["UNEXPECTED_ERROR"] = 0] = "UNEXPECTED_ERROR"; + OpenAttestationDocumentSignedCode[OpenAttestationDocumentSignedCode["DOCUMENT_PROOF_INVALID"] = 1] = "DOCUMENT_PROOF_INVALID"; + OpenAttestationDocumentSignedCode[OpenAttestationDocumentSignedCode["DOCUMENT_PROOF_ERROR"] = 2] = "DOCUMENT_PROOF_ERROR"; + OpenAttestationDocumentSignedCode[OpenAttestationDocumentSignedCode["SKIPPED"] = 4] = "SKIPPED"; +})(OpenAttestationDocumentSignedCode = exports.OpenAttestationDocumentSignedCode || (exports.OpenAttestationDocumentSignedCode = {})); +var OpenAttestationEthereumTokenRegistryStatusCode; +(function (OpenAttestationEthereumTokenRegistryStatusCode) { + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["UNEXPECTED_ERROR"] = 0] = "UNEXPECTED_ERROR"; + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["DOCUMENT_NOT_MINTED"] = 1] = "DOCUMENT_NOT_MINTED"; + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["CONTRACT_ADDRESS_INVALID"] = 2] = "CONTRACT_ADDRESS_INVALID"; + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["ETHERS_UNHANDLED_ERROR"] = 3] = "ETHERS_UNHANDLED_ERROR"; + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["SKIPPED"] = 4] = "SKIPPED"; + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["INVALID_ISSUERS"] = 5] = "INVALID_ISSUERS"; + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["INVALID_ARGUMENT"] = 6] = "INVALID_ARGUMENT"; + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["UNDEFINED_TOKEN_REGISTRY"] = 7] = "UNDEFINED_TOKEN_REGISTRY"; + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["INVALID_VALIDATION_METHOD"] = 8] = "INVALID_VALIDATION_METHOD"; + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["UNRECOGNIZED_DOCUMENT"] = 9] = "UNRECOGNIZED_DOCUMENT"; + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["SERVER_ERROR"] = 500] = "SERVER_ERROR"; +})(OpenAttestationEthereumTokenRegistryStatusCode = exports.OpenAttestationEthereumTokenRegistryStatusCode || (exports.OpenAttestationEthereumTokenRegistryStatusCode = {})); +var OpenAttestationDnsTxtCode; +(function (OpenAttestationDnsTxtCode) { + OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["UNEXPECTED_ERROR"] = 0] = "UNEXPECTED_ERROR"; + OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["INVALID_IDENTITY"] = 1] = "INVALID_IDENTITY"; + OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["SKIPPED"] = 2] = "SKIPPED"; + OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["INVALID_ISSUERS"] = 3] = "INVALID_ISSUERS"; + OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["MATCHING_RECORD_NOT_FOUND"] = 4] = "MATCHING_RECORD_NOT_FOUND"; + OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["UNRECOGNIZED_DOCUMENT"] = 5] = "UNRECOGNIZED_DOCUMENT"; + OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["UNSUPPORTED"] = 6] = "UNSUPPORTED"; +})(OpenAttestationDnsTxtCode = exports.OpenAttestationDnsTxtCode || (exports.OpenAttestationDnsTxtCode = {})); +var OpenAttestationHashCode; +(function (OpenAttestationHashCode) { + OpenAttestationHashCode[OpenAttestationHashCode["DOCUMENT_TAMPERED"] = 0] = "DOCUMENT_TAMPERED"; + OpenAttestationHashCode[OpenAttestationHashCode["UNEXPECTED_ERROR"] = 1] = "UNEXPECTED_ERROR"; + OpenAttestationHashCode[OpenAttestationHashCode["SKIPPED"] = 2] = "SKIPPED"; +})(OpenAttestationHashCode = exports.OpenAttestationHashCode || (exports.OpenAttestationHashCode = {})); +var OpenAttestationDidSignedDocumentStatusCode; +(function (OpenAttestationDidSignedDocumentStatusCode) { + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["SKIPPED"] = 0] = "SKIPPED"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["UNEXPECTED_ERROR"] = 1] = "UNEXPECTED_ERROR"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["MISSING_REVOCATION"] = 2] = "MISSING_REVOCATION"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["UNSIGNED"] = 3] = "UNSIGNED"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["INVALID_ISSUERS"] = 4] = "INVALID_ISSUERS"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["MALFORMED_IDENTITY_PROOF"] = 5] = "MALFORMED_IDENTITY_PROOF"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["CORRESPONDING_PROOF_MISSING"] = 6] = "CORRESPONDING_PROOF_MISSING"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["DID_MISSING"] = 7] = "DID_MISSING"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["UNRECOGNIZED_DOCUMENT"] = 8] = "UNRECOGNIZED_DOCUMENT"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["UNRECOGNIZED_REVOCATION_TYPE"] = 9] = "UNRECOGNIZED_REVOCATION_TYPE"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["REVOCATION_LOCATION_MISSING"] = 10] = "REVOCATION_LOCATION_MISSING"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["OCSP_RESPONSE_INVALID"] = 11] = "OCSP_RESPONSE_INVALID"; +})(OpenAttestationDidSignedDocumentStatusCode = exports.OpenAttestationDidSignedDocumentStatusCode || (exports.OpenAttestationDidSignedDocumentStatusCode = {})); +var OpenAttestationDidCode; +(function (OpenAttestationDidCode) { + OpenAttestationDidCode[OpenAttestationDidCode["SKIPPED"] = 0] = "SKIPPED"; + OpenAttestationDidCode[OpenAttestationDidCode["UNEXPECTED_ERROR"] = 1] = "UNEXPECTED_ERROR"; + OpenAttestationDidCode[OpenAttestationDidCode["INVALID_ISSUERS"] = 2] = "INVALID_ISSUERS"; + OpenAttestationDidCode[OpenAttestationDidCode["MALFORMED_IDENTITY_PROOF"] = 3] = "MALFORMED_IDENTITY_PROOF"; + OpenAttestationDidCode[OpenAttestationDidCode["DID_MISSING"] = 4] = "DID_MISSING"; + OpenAttestationDidCode[OpenAttestationDidCode["UNSIGNED"] = 5] = "UNSIGNED"; + OpenAttestationDidCode[OpenAttestationDidCode["UNRECOGNIZED_DOCUMENT"] = 6] = "UNRECOGNIZED_DOCUMENT"; +})(OpenAttestationDidCode = exports.OpenAttestationDidCode || (exports.OpenAttestationDidCode = {})); +var OpenAttestationDnsDidCode; +(function (OpenAttestationDnsDidCode) { + OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["SKIPPED"] = 0] = "SKIPPED"; + OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["UNEXPECTED_ERROR"] = 1] = "UNEXPECTED_ERROR"; + OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["MALFORMED_IDENTITY_PROOF"] = 2] = "MALFORMED_IDENTITY_PROOF"; + OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["INVALID_ISSUERS"] = 3] = "INVALID_ISSUERS"; + OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["UNSIGNED"] = 4] = "UNSIGNED"; + OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["UNRECOGNIZED_DOCUMENT"] = 5] = "UNRECOGNIZED_DOCUMENT"; + OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["INVALID_IDENTITY"] = 6] = "INVALID_IDENTITY"; +})(OpenAttestationDnsDidCode = exports.OpenAttestationDnsDidCode || (exports.OpenAttestationDnsDidCode = {})); +var OpenAttestationSignatureCode; +(function (OpenAttestationSignatureCode) { + OpenAttestationSignatureCode[OpenAttestationSignatureCode["UNEXPECTED_ERROR"] = 0] = "UNEXPECTED_ERROR"; + OpenAttestationSignatureCode[OpenAttestationSignatureCode["KEY_MISSING"] = 1] = "KEY_MISSING"; + OpenAttestationSignatureCode[OpenAttestationSignatureCode["DID_MISSING"] = 3] = "DID_MISSING"; + OpenAttestationSignatureCode[OpenAttestationSignatureCode["KEY_NOT_IN_DID"] = 4] = "KEY_NOT_IN_DID"; + OpenAttestationSignatureCode[OpenAttestationSignatureCode["UNSUPPORTED_KEY_TYPE"] = 6] = "UNSUPPORTED_KEY_TYPE"; + OpenAttestationSignatureCode[OpenAttestationSignatureCode["WRONG_SIGNATURE"] = 7] = "WRONG_SIGNATURE"; +})(OpenAttestationSignatureCode = exports.OpenAttestationSignatureCode || (exports.OpenAttestationSignatureCode = {})); +exports.Reason = runtypes_1.Record({ + code: runtypes_1.Number, + codeString: runtypes_1.String, + message: runtypes_1.String, +}); diff --git a/dist/cjs/validator.js b/dist/cjs/validator.js new file mode 100644 index 00000000..dc37a560 --- /dev/null +++ b/dist/cjs/validator.js @@ -0,0 +1,20 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.isValid = void 0; +var isValid = function (verificationFragments, types) { + if (types === void 0) { types = ["DOCUMENT_STATUS", "DOCUMENT_INTEGRITY", "ISSUER_IDENTITY"]; } + if (verificationFragments.length < 1) { + throw new Error("Please provide at least one verification fragment to check"); + } + if (types.length < 1) { + throw new Error("Please provide at least one type to check"); + } + return types.every(function (type) { + var verificationFragmentsForType = verificationFragments.filter(function (fragment) { return fragment.type === type; }); + // return true if at least one fragment is valid + // and all fragments are valid or skipped + return (verificationFragmentsForType.some(function (fragment) { return fragment.status === "VALID"; }) && + verificationFragmentsForType.every(function (fragment) { return fragment.status === "VALID" || fragment.status === "SKIPPED"; })); + }); +}; +exports.isValid = isValid; diff --git a/dist/cjs/verifiers/documentIntegrity/hash/openAttestationHash.js b/dist/cjs/verifiers/documentIntegrity/hash/openAttestationHash.js new file mode 100644 index 00000000..38fc08f2 --- /dev/null +++ b/dist/cjs/verifiers/documentIntegrity/hash/openAttestationHash.js @@ -0,0 +1,98 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.openAttestationHash = void 0; +var open_attestation_1 = require("@govtechsg/open-attestation"); +var error_1 = require("../../../types/error"); +var errorHandler_1 = require("../../../common/errorHandler"); +var name = "OpenAttestationHash"; +var type = "DOCUMENT_INTEGRITY"; +var skip = function () { + return Promise.resolve({ + status: "SKIPPED", + type: type, + name: name, + reason: { + code: error_1.OpenAttestationHashCode.SKIPPED, + codeString: error_1.OpenAttestationHashCode[error_1.OpenAttestationHashCode.SKIPPED], + message: "Document does not have merkle root, target hash or data.", + }, + }); +}; +var test = function (document) { + return open_attestation_1.utils.isWrappedV3Document(document) || open_attestation_1.utils.isWrappedV2Document(document); +}; +var verify = function (document) { return __awaiter(void 0, void 0, void 0, function () { + var hash; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, open_attestation_1.verifySignature(document)]; + case 1: + hash = _a.sent(); + if (!hash) { + return [2 /*return*/, { + type: type, + name: name, + data: hash, + reason: { + code: error_1.OpenAttestationHashCode.DOCUMENT_TAMPERED, + codeString: error_1.OpenAttestationHashCode[error_1.OpenAttestationHashCode.DOCUMENT_TAMPERED], + message: "Document has been tampered with", + }, + status: "INVALID", + }]; + } + return [2 /*return*/, { + type: type, + name: name, + data: hash, + status: "VALID", + }]; + } + }); +}); }; +exports.openAttestationHash = { + skip: skip, + test: test, + verify: errorHandler_1.withCodedErrorHandler(verify, { + name: name, + type: type, + unexpectedErrorCode: error_1.OpenAttestationHashCode.UNEXPECTED_ERROR, + unexpectedErrorString: error_1.OpenAttestationHashCode[error_1.OpenAttestationHashCode.UNEXPECTED_ERROR], + }), +}; diff --git a/dist/cjs/verifiers/documentIntegrity/hash/openAttestationHash.type.js b/dist/cjs/verifiers/documentIntegrity/hash/openAttestationHash.type.js new file mode 100644 index 00000000..c8ad2e54 --- /dev/null +++ b/dist/cjs/verifiers/documentIntegrity/hash/openAttestationHash.type.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/cjs/verifiers/documentStatus/didSigned/didSignedDocumentStatus.js b/dist/cjs/verifiers/documentStatus/didSigned/didSignedDocumentStatus.js new file mode 100644 index 00000000..eb018cf9 --- /dev/null +++ b/dist/cjs/verifiers/documentStatus/didSigned/didSignedDocumentStatus.js @@ -0,0 +1,309 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.openAttestationDidSignedDocumentStatus = void 0; +var open_attestation_1 = require("@govtechsg/open-attestation"); +var error_1 = require("../../../types/error"); +var verifier_1 = require("../../../did/verifier"); +var error_2 = require("../../../common/error"); +var errorHandler_1 = require("../../../common/errorHandler"); +var utils_1 = require("../utils"); +var revocation_types_1 = require("../revocation.types"); +var didSignedDocumentStatus_type_1 = require("./didSignedDocumentStatus.type"); +var name = "OpenAttestationDidSignedDocumentStatus"; +var type = "DOCUMENT_STATUS"; +var skip = function () { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, { + status: "SKIPPED", + type: type, + name: name, + reason: { + code: error_1.OpenAttestationDidSignedDocumentStatusCode.SKIPPED, + codeString: error_1.OpenAttestationDidSignedDocumentStatusCode[error_1.OpenAttestationDidSignedDocumentStatusCode.SKIPPED], + message: "Document was not signed by DID directly", + }, + }]; + }); +}); }; +var test = function (document) { + if (open_attestation_1.utils.isSignedWrappedV2Document(document)) { + return document.proof.some(function (proof) { return proof.type === "OpenAttestationSignature2018"; }); + } + else if (open_attestation_1.utils.isSignedWrappedV3Document(document)) { + return document.proof.type === "OpenAttestationMerkleProofSignature2018"; + } + return false; +}; +var transformToDidSignedIssuanceStatus = function (status) { + return verifier_1.ValidDidVerificationStatus.guard(status) + ? { + issued: true, + did: status.did, + } + : { + issued: false, + did: status.did, + reason: status.reason, + }; +}; +var verifyV2 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + var documentData, merkleRoot, _a, targetHash, proofs, issuers, revocation, revocationStatusCallback, revocationStatuses, signatureVerificationDeferred, issuance, notIssued, revoked, data, reason; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + documentData = open_attestation_1.getData(document); + merkleRoot = "0x" + document.signature.merkleRoot; + _a = document.signature, targetHash = _a.targetHash, proofs = _a.proof; + documentData.issuers.forEach(function (issuer) { + var _a, _b; + if (!(((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === "DID" || ((_b = issuer.identityProof) === null || _b === void 0 ? void 0 : _b.type) === "DNS-DID")) + throw new error_2.CodedError("All issuers must use DID or DNS-DID identityProof type.", error_1.OpenAttestationDidSignedDocumentStatusCode.INVALID_ISSUERS, error_1.OpenAttestationDidSignedDocumentStatusCode[error_1.OpenAttestationDidSignedDocumentStatusCode.INVALID_ISSUERS]); + }); + issuers = documentData.issuers; + revocation = issuers.map(function (issuer) { return issuer.revocation; }); + if (revocation.some(function (r) { return typeof (r === null || r === void 0 ? void 0 : r.type) === "undefined"; })) + throw new error_2.CodedError("revocation block not found for an issuer", error_1.OpenAttestationDidSignedDocumentStatusCode.MISSING_REVOCATION, "MISSING_REVOCATION"); + revocationStatusCallback = function (revocationItem) { + switch (revocationItem.type) { + case open_attestation_1.v2.RevocationType.RevocationStore: + if (typeof revocationItem.location === "string") { + return utils_1.isRevokedOnDocumentStore({ + documentStore: revocationItem.location, + merkleRoot: merkleRoot, + provider: options.provider, + targetHash: targetHash, + proofs: proofs, + }); + } + throw new error_2.CodedError("missing revocation location for an issuer", error_1.OpenAttestationDidSignedDocumentStatusCode.REVOCATION_LOCATION_MISSING, "REVOCATION_LOCATION_MISSING"); + case open_attestation_1.v2.RevocationType.OcspResponder: + if (typeof revocationItem.location === "string") { + return utils_1.isRevokedByOcspResponder({ + certificateId: documentData.id, + location: revocationItem.location, + }); + } + throw new error_2.CodedError("missing revocation location for an issuer", error_1.OpenAttestationDidSignedDocumentStatusCode.REVOCATION_LOCATION_MISSING, "REVOCATION_LOCATION_MISSING"); + case open_attestation_1.v2.RevocationType.None: + return Promise.resolve({ revoked: false }); + default: + throw new error_2.CodedError("unrecognized revocation type for an issuer", error_1.OpenAttestationDidSignedDocumentStatusCode.UNRECOGNIZED_REVOCATION_TYPE, "UNRECOGNIZED_REVOCATION_TYPE"); + } + }; + return [4 /*yield*/, Promise.all(revocation.map(revocationStatusCallback))]; + case 1: + revocationStatuses = _b.sent(); + // Check that all the issuers have signed on the document + if (!document.proof) + throw new error_2.CodedError("Document is not signed. Proofs are missing.", error_1.OpenAttestationDidSignedDocumentStatusCode.UNSIGNED, "UNSIGNED"); + signatureVerificationDeferred = issuers.map(function (issuer) { return __awaiter(void 0, void 0, void 0, function () { + var key, did, correspondingProof; + var _a; + return __generator(this, function (_b) { + key = (_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.key; + did = issuer.id; + if (!did) + throw new error_2.CodedError("id is missing in issuer", error_1.OpenAttestationDidSignedDocumentStatusCode.DID_MISSING, "DID_MISSING"); + if (!key) + throw new error_2.CodedError("Key is not present", error_1.OpenAttestationDidSignedDocumentStatusCode.MALFORMED_IDENTITY_PROOF, "MALFORMED_IDENTITY_PROOF"); + correspondingProof = document.proof.find(function (p) { return p.verificationMethod.toLowerCase() === key.toLowerCase(); }); + if (!correspondingProof) + throw new error_2.CodedError("Proof not found for " + key, error_1.OpenAttestationDidSignedDocumentStatusCode.CORRESPONDING_PROOF_MISSING, "CORRESPONDING_PROOF_MISSING"); + return [2 /*return*/, verifier_1.verifySignature({ + merkleRoot: merkleRoot, + key: key, + signature: correspondingProof.signature, + did: did, + resolver: options.resolver, + })]; + }); + }); }); + return [4 /*yield*/, Promise.all(signatureVerificationDeferred)]; + case 2: return [4 /*yield*/, (_b.sent()).map(transformToDidSignedIssuanceStatus)]; + case 3: + issuance = _b.sent(); + notIssued = issuance.find(didSignedDocumentStatus_type_1.InvalidDidSignedIssuanceStatus.guard); + revoked = revocationStatuses.find(revocation_types_1.InvalidRevocationStatus.guard); + data = { + issuedOnAll: !notIssued, + revokedOnAny: !!revoked, + details: { + issuance: issuance, + revocation: revocationStatuses, + }, + }; + if (didSignedDocumentStatus_type_1.ValidDidSignedDataV2.guard(data)) { + return [2 /*return*/, { + name: name, + type: type, + data: data, + status: "VALID", + }]; + } + if (didSignedDocumentStatus_type_1.InvalidDidSignedIssuanceStatus.guard(notIssued)) { + reason = notIssued.reason; + } + else if (revocation_types_1.InvalidRevocationStatus.guard(revoked)) { + reason = revoked.reason; + } + if (!reason) { + throw new error_2.CodedError("Unable to retrieve the reason of the failure", error_1.OpenAttestationDidSignedDocumentStatusCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); + } + return [2 /*return*/, { + name: name, + type: type, + data: data, + status: "INVALID", + reason: reason, + }]; + } + }); +}); }; +var verifyV3 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + var _a, merkleRootRaw, targetHash, proofs, merkleRoot, metaData, verificationResult, _b, issuedOnAll, getRevocationStatus, revocationStatus, revokedOnAny, reason; + var _c; + return __generator(this, function (_d) { + switch (_d.label) { + case 0: + _a = document.proof, merkleRootRaw = _a.merkleRoot, targetHash = _a.targetHash, proofs = _a.proofs; + merkleRoot = "0x" + merkleRootRaw; + metaData = document.openAttestationMetadata; + _b = transformToDidSignedIssuanceStatus; + return [4 /*yield*/, verifier_1.verifySignature({ + key: document.proof.key, + did: metaData.proof.value, + merkleRoot: merkleRoot, + signature: document.proof.signature, + resolver: options.resolver, + })]; + case 1: + verificationResult = _b.apply(void 0, [_d.sent()]); + if (!((_c = metaData.proof.revocation) === null || _c === void 0 ? void 0 : _c.type)) { + throw new error_2.CodedError("revocation block not found for an issuer", error_1.OpenAttestationDidSignedDocumentStatusCode.MISSING_REVOCATION, "MISSING_REVOCATION"); + } + issuedOnAll = verificationResult.issued; + getRevocationStatus = function (docType, location) { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (docType) { + case open_attestation_1.v3.RevocationType.RevocationStore: + if (typeof location === "string") { + return [2 /*return*/, utils_1.isRevokedOnDocumentStore({ + documentStore: location, + merkleRoot: merkleRoot, + targetHash: targetHash, + proofs: proofs, + provider: options.provider, + })]; + } + throw new error_2.CodedError("missing revocation location for an issuer", error_1.OpenAttestationDidSignedDocumentStatusCode.REVOCATION_LOCATION_MISSING, "REVOCATION_LOCATION_MISSING"); + case open_attestation_1.v3.RevocationType.OcspResponder: + throw new Error("Ocsp revocation type not yet supported for v3"); + case open_attestation_1.v3.RevocationType.None: + return [2 /*return*/, { revoked: false }]; + default: + throw new error_2.CodedError("revocation type not found for an issuer", error_1.OpenAttestationDidSignedDocumentStatusCode.UNRECOGNIZED_REVOCATION_TYPE, "UNRECOGNIZED_REVOCATION_TYPE"); + } + return [2 /*return*/]; + }); + }); }; + return [4 /*yield*/, getRevocationStatus(metaData.proof.revocation.type, metaData.proof.revocation.location)]; + case 2: + revocationStatus = _d.sent(); + revokedOnAny = revocationStatus.revoked; + if (didSignedDocumentStatus_type_1.ValidDidSignedIssuanceStatus.guard(verificationResult) && revocation_types_1.ValidRevocationStatus.guard(revocationStatus)) { + return [2 /*return*/, { + name: name, + type: type, + data: { + issuedOnAll: true, + revokedOnAny: false, + details: { + issuance: verificationResult, + revocation: revocationStatus, + }, + }, + status: "VALID", + }]; + } + reason = didSignedDocumentStatus_type_1.InvalidDidSignedIssuanceStatus.guard(verificationResult) + ? verificationResult.reason + : revocation_types_1.InvalidRevocationStatus.guard(revocationStatus) + ? revocationStatus.reason + : undefined; + if (!reason) { + throw new error_2.CodedError("Unable to retrieve the reason of the failure", error_1.OpenAttestationDidSignedDocumentStatusCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); + } + return [2 /*return*/, { + name: name, + type: type, + data: { + issuedOnAll: issuedOnAll, + revokedOnAny: revokedOnAny, + details: { + issuance: verificationResult, + revocation: revocationStatus, + }, + }, + status: "INVALID", + reason: reason, + }]; + } + }); +}); }; +var verify = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + if (open_attestation_1.utils.isSignedWrappedV2Document(document)) { + return [2 /*return*/, verifyV2(document, options)]; + } + else if (open_attestation_1.utils.isSignedWrappedV3Document(document)) { + return [2 /*return*/, verifyV3(document, options)]; + } + throw new error_2.CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", error_1.OpenAttestationDidSignedDocumentStatusCode.UNRECOGNIZED_DOCUMENT, error_1.OpenAttestationDidSignedDocumentStatusCode[error_1.OpenAttestationDidSignedDocumentStatusCode.UNRECOGNIZED_DOCUMENT]); + }); +}); }; +exports.openAttestationDidSignedDocumentStatus = { + skip: skip, + test: test, + verify: errorHandler_1.withCodedErrorHandler(verify, { + name: name, + type: type, + unexpectedErrorCode: error_1.OpenAttestationDidSignedDocumentStatusCode.UNEXPECTED_ERROR, + unexpectedErrorString: error_1.OpenAttestationDidSignedDocumentStatusCode[error_1.OpenAttestationDidSignedDocumentStatusCode.UNEXPECTED_ERROR], + }), +}; diff --git a/dist/cjs/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.js b/dist/cjs/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.js new file mode 100644 index 00000000..841492a6 --- /dev/null +++ b/dist/cjs/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.js @@ -0,0 +1,70 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.InvalidDidSignedDataV3 = exports.ValidDidSignedDataV3 = exports.InvalidDidSignedDataV2 = exports.ValidDidSignedDataV2 = exports.ValidOcspResponseRevoked = exports.ValidOcspResponse = exports.ValidOcspReasonCode = exports.DidSignedIssuanceStatusArray = exports.DidSignedIssuanceStatus = exports.InvalidDidSignedIssuanceStatus = exports.ValidDidSignedIssuanceStatusArray = exports.ValidDidSignedIssuanceStatus = void 0; +var runtypes_1 = require("runtypes"); +var error_1 = require("../../../types/error"); +var revocation_types_1 = require("../revocation.types"); +/** + * DID signed issuance status + */ +exports.ValidDidSignedIssuanceStatus = runtypes_1.Record({ + did: runtypes_1.String, + issued: runtypes_1.Literal(true), +}); +exports.ValidDidSignedIssuanceStatusArray = runtypes_1.Array(exports.ValidDidSignedIssuanceStatus); +exports.InvalidDidSignedIssuanceStatus = runtypes_1.Record({ + did: runtypes_1.String, + issued: runtypes_1.Literal(false), + reason: error_1.Reason, +}); +exports.DidSignedIssuanceStatus = runtypes_1.Union(exports.ValidDidSignedIssuanceStatus, exports.InvalidDidSignedIssuanceStatus); +exports.DidSignedIssuanceStatusArray = runtypes_1.Array(exports.DidSignedIssuanceStatus); +/** + * OCSP response + */ +exports.ValidOcspReasonCode = runtypes_1.Number.withConstraint(function (n) { return n >= 0 && n <= 10 && n != 7; }); +exports.ValidOcspResponse = runtypes_1.Record({ + certificateStatus: revocation_types_1.OcspResponderRevocationStatus, +}); +exports.ValidOcspResponseRevoked = runtypes_1.Record({ + reasonCode: exports.ValidOcspReasonCode, + certificateStatus: revocation_types_1.OcspResponderRevocationStatus, +}); +/** + * Data for v2 Fragments + */ +exports.ValidDidSignedDataV2 = runtypes_1.Record({ + issuedOnAll: runtypes_1.Literal(true), + revokedOnAny: runtypes_1.Literal(false), + details: runtypes_1.Record({ + issuance: exports.ValidDidSignedIssuanceStatusArray, + revocation: revocation_types_1.ValidRevocationStatusArray, + }), +}); +exports.InvalidDidSignedDataV2 = runtypes_1.Record({ + issuedOnAll: runtypes_1.Boolean, + revokedOnAny: runtypes_1.Boolean, + details: runtypes_1.Record({ + issuance: exports.DidSignedIssuanceStatusArray, + revocation: revocation_types_1.RevocationStatusArray, + }), +}); +/** + * Data for v3 Fragments + */ +exports.ValidDidSignedDataV3 = runtypes_1.Record({ + issuedOnAll: runtypes_1.Literal(true), + revokedOnAny: runtypes_1.Literal(false), + details: runtypes_1.Record({ + issuance: exports.ValidDidSignedIssuanceStatus, + revocation: revocation_types_1.ValidRevocationStatus, + }), +}); +exports.InvalidDidSignedDataV3 = runtypes_1.Record({ + issuedOnAll: runtypes_1.Boolean, + revokedOnAny: runtypes_1.Boolean, + details: runtypes_1.Record({ + issuance: exports.DidSignedIssuanceStatus, + revocation: revocation_types_1.RevocationStatus, + }), +}); diff --git a/dist/cjs/verifiers/documentStatus/didSigned/index.js b/dist/cjs/verifiers/documentStatus/didSigned/index.js new file mode 100644 index 00000000..23b5b0d5 --- /dev/null +++ b/dist/cjs/verifiers/documentStatus/didSigned/index.js @@ -0,0 +1,13 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./didSignedDocumentStatus"), exports); diff --git a/dist/cjs/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.js b/dist/cjs/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.js new file mode 100644 index 00000000..b034f1a1 --- /dev/null +++ b/dist/cjs/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.js @@ -0,0 +1,274 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.openAttestationEthereumDocumentStoreStatus = exports.isIssuedOnDocumentStore = exports.getIssuersDocumentStores = void 0; +var open_attestation_1 = require("@govtechsg/open-attestation"); +var document_store_1 = require("@govtechsg/document-store"); +var error_1 = require("../../../types/error"); +var error_2 = require("../../../common/error"); +var errorHandler_1 = require("../../../common/errorHandler"); +var utils_1 = require("../utils"); +var revocation_types_1 = require("../revocation.types"); +var ethereumDocumentStoreStatus_type_1 = require("./ethereumDocumentStoreStatus.type"); +var name = "OpenAttestationEthereumDocumentStoreStatus"; +var type = "DOCUMENT_STATUS"; +// Returns list of all document stores, throws when not all issuers are using document store +var getIssuersDocumentStores = function (document) { + var data = open_attestation_1.getData(document); + return data.issuers.map(function (issuer) { + var documentStoreAddress = issuer.documentStore || issuer.certificateStore; + if (!documentStoreAddress) + throw new error_2.CodedError("Document store address not found in issuer " + issuer.name, error_1.OpenAttestationEthereumDocumentStoreStatusCode.INVALID_ISSUERS, error_1.OpenAttestationEthereumDocumentStoreStatusCode[error_1.OpenAttestationEthereumDocumentStoreStatusCode.INVALID_ISSUERS]); + return documentStoreAddress; + }); +}; +exports.getIssuersDocumentStores = getIssuersDocumentStores; +var isIssuedOnDocumentStore = function (_a) { + var documentStore = _a.documentStore, merkleRoot = _a.merkleRoot, provider = _a.provider; + return __awaiter(void 0, void 0, void 0, function () { + var documentStoreContract, issued, error_3; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _b.trys.push([0, 3, , 4]); + return [4 /*yield*/, document_store_1.DocumentStoreFactory.connect(documentStore, provider)]; + case 1: + documentStoreContract = _b.sent(); + return [4 /*yield*/, documentStoreContract.isIssued(merkleRoot)]; + case 2: + issued = _b.sent(); + return [2 /*return*/, issued + ? { + issued: true, + address: documentStore, + } + : { + issued: false, + address: documentStore, + reason: { + message: "Document " + merkleRoot + " has not been issued under contract " + documentStore, + code: error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED, + codeString: error_1.OpenAttestationEthereumDocumentStoreStatusCode[error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED], + }, + }]; + case 3: + error_3 = _b.sent(); + // If error can be decoded and it's because of document is not issued, we return false + // Else allow error to continue to bubble up + return [2 /*return*/, { + issued: false, + address: documentStore, + reason: { + message: utils_1.decodeError(error_3), + code: error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED, + codeString: error_1.OpenAttestationEthereumDocumentStoreStatusCode[error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED], + }, + }]; + case 4: return [2 /*return*/]; + } + }); + }); +}; +exports.isIssuedOnDocumentStore = isIssuedOnDocumentStore; +var skip = function () { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, { + status: "SKIPPED", + type: type, + name: name, + reason: { + code: error_1.OpenAttestationEthereumDocumentStoreStatusCode.SKIPPED, + codeString: error_1.OpenAttestationEthereumDocumentStoreStatusCode[error_1.OpenAttestationEthereumDocumentStoreStatusCode.SKIPPED], + message: "Document issuers doesn't have \"documentStore\" or \"certificateStore\" property or " + open_attestation_1.v3.Method.DocumentStore + " method", + }, + }]; + }); +}); }; +var test = function (document) { + if (open_attestation_1.utils.isWrappedV2Document(document)) { + var documentData = open_attestation_1.getData(document); + return documentData.issuers.some(function (issuer) { return "documentStore" in issuer || "certificateStore" in issuer; }); + } + else if (open_attestation_1.utils.isWrappedV3Document(document)) { + return document.openAttestationMetadata.proof.method === open_attestation_1.v3.Method.DocumentStore; + } + return false; +}; +var verifyV2 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + var documentStores, merkleRoot, targetHash, proofs, issuanceStatuses, notIssued, revocationStatuses, revoked; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + documentStores = exports.getIssuersDocumentStores(document); + merkleRoot = "0x" + document.signature.merkleRoot; + targetHash = document.signature.targetHash; + proofs = document.signature.proof || []; + return [4 /*yield*/, Promise.all(documentStores.map(function (documentStore) { + return exports.isIssuedOnDocumentStore({ documentStore: documentStore, merkleRoot: merkleRoot, provider: options.provider }); + }))]; + case 1: + issuanceStatuses = _a.sent(); + notIssued = issuanceStatuses.find(ethereumDocumentStoreStatus_type_1.InvalidDocumentStoreIssuanceStatus.guard); + if (ethereumDocumentStoreStatus_type_1.InvalidDocumentStoreIssuanceStatus.guard(notIssued)) { + return [2 /*return*/, { + name: name, + type: type, + data: { + issuedOnAll: false, + details: { issuance: issuanceStatuses }, + }, + reason: notIssued.reason, + status: "INVALID", + }]; + } + return [4 /*yield*/, Promise.all(documentStores.map(function (documentStore) { + return utils_1.isRevokedOnDocumentStore({ + documentStore: documentStore, + merkleRoot: merkleRoot, + targetHash: targetHash, + proofs: proofs, + provider: options.provider, + }); + }))]; + case 2: + revocationStatuses = _a.sent(); + revoked = revocationStatuses.find(revocation_types_1.InvalidRevocationStatus.guard); + if (revocation_types_1.InvalidRevocationStatus.guard(revoked)) { + return [2 /*return*/, { + name: name, + type: type, + data: { + issuedOnAll: true, + revokedOnAny: true, + details: { issuance: issuanceStatuses, revocation: revocationStatuses }, + }, + reason: revoked.reason, + status: "INVALID", + }]; + } + if (ethereumDocumentStoreStatus_type_1.ValidDocumentStoreIssuanceStatusArray.guard(issuanceStatuses) && + revocation_types_1.ValidRevocationStatusArray.guard(revocationStatuses)) { + return [2 /*return*/, { + name: name, + type: type, + data: { + issuedOnAll: true, + revokedOnAny: false, + details: { issuance: issuanceStatuses, revocation: revocationStatuses }, + }, + status: "VALID", + }]; + } + throw new error_2.CodedError("Reached an unexpected state when verifying v2 document", error_1.OpenAttestationEthereumDocumentStoreStatusCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); + } + }); +}); }; +var verifyV3 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + var _a, merkleRootRaw, targetHash, proofs, merkleRoot, documentStore, issuance, revocation, data, reason; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _a = document.proof, merkleRootRaw = _a.merkleRoot, targetHash = _a.targetHash, proofs = _a.proofs; + merkleRoot = "0x" + merkleRootRaw; + documentStore = document.openAttestationMetadata.proof.value; + return [4 /*yield*/, exports.isIssuedOnDocumentStore({ documentStore: documentStore, merkleRoot: merkleRoot, provider: options.provider })]; + case 1: + issuance = _b.sent(); + return [4 /*yield*/, utils_1.isRevokedOnDocumentStore({ + documentStore: documentStore, + merkleRoot: merkleRoot, + targetHash: targetHash, + proofs: proofs, + provider: options.provider, + })]; + case 2: + revocation = _b.sent(); + data = { + issuedOnAll: issuance.issued, + revokedOnAny: revocation.revoked, + details: { + issuance: issuance, + revocation: revocation, + }, + }; + if (ethereumDocumentStoreStatus_type_1.ValidDocumentStoreDataV3.guard(data)) { + return [2 /*return*/, { + name: name, + type: type, + data: data, + status: "VALID", + }]; + } + if (revocation_types_1.InvalidRevocationStatus.guard(revocation)) { + reason = revocation.reason; + } + else if (ethereumDocumentStoreStatus_type_1.InvalidDocumentStoreIssuanceStatus.guard(issuance)) { + reason = issuance.reason; + } + if (!reason) { + throw new error_2.CodedError("Unable to retrieve the reason of the failure", error_1.OpenAttestationEthereumDocumentStoreStatusCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); + } + return [2 /*return*/, { + name: name, + type: type, + data: data, + status: "INVALID", + reason: reason, + }]; + } + }); +}); }; +var verify = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + if (open_attestation_1.utils.isWrappedV2Document(document)) + return [2 /*return*/, verifyV2(document, options)]; + else if (open_attestation_1.utils.isWrappedV3Document(document)) + return [2 /*return*/, verifyV3(document, options)]; + throw new error_2.CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", error_1.OpenAttestationEthereumDocumentStoreStatusCode.UNRECOGNIZED_DOCUMENT, error_1.OpenAttestationEthereumDocumentStoreStatusCode[error_1.OpenAttestationEthereumDocumentStoreStatusCode.UNRECOGNIZED_DOCUMENT]); + }); +}); }; +exports.openAttestationEthereumDocumentStoreStatus = { + skip: skip, + test: test, + verify: errorHandler_1.withCodedErrorHandler(verify, { + name: name, + type: type, + unexpectedErrorCode: error_1.OpenAttestationEthereumDocumentStoreStatusCode.UNEXPECTED_ERROR, + unexpectedErrorString: error_1.OpenAttestationEthereumDocumentStoreStatusCode[error_1.OpenAttestationEthereumDocumentStoreStatusCode.UNEXPECTED_ERROR], + }), +}; diff --git a/dist/cjs/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.js b/dist/cjs/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.js new file mode 100644 index 00000000..ca5f7c3b --- /dev/null +++ b/dist/cjs/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.js @@ -0,0 +1,59 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.InvalidDocumentStoreDataV3 = exports.ValidDocumentStoreDataV3 = exports.InvalidDocumentStoreDataV2 = exports.DocumentStoreIssuanceStatusArray = exports.DocumentStoreIssuanceStatus = exports.InvalidDocumentStoreIssuanceStatus = exports.ValidDocumentStoreIssuanceStatusArray = exports.ValidDocumentStoreIssuanceStatus = void 0; +var runtypes_1 = require("runtypes"); +var error_1 = require("../../../types/error"); +var revocation_types_1 = require("../revocation.types"); +/** + * Document store issuance status + */ +exports.ValidDocumentStoreIssuanceStatus = runtypes_1.Record({ + issued: runtypes_1.Literal(true), + address: runtypes_1.String, +}); +exports.ValidDocumentStoreIssuanceStatusArray = runtypes_1.Array(exports.ValidDocumentStoreIssuanceStatus); +exports.InvalidDocumentStoreIssuanceStatus = runtypes_1.Record({ + issued: runtypes_1.Literal(false), + address: runtypes_1.String, + reason: error_1.Reason, +}); +exports.DocumentStoreIssuanceStatus = runtypes_1.Union(exports.ValidDocumentStoreIssuanceStatus, exports.InvalidDocumentStoreIssuanceStatus); +exports.DocumentStoreIssuanceStatusArray = runtypes_1.Array(exports.DocumentStoreIssuanceStatus); +/** + * Data for v2 Fragments + */ +var ValidDocumentStoreDataV2 = runtypes_1.Record({ + issuedOnAll: runtypes_1.Literal(true), + revokedOnAny: runtypes_1.Literal(false), + details: runtypes_1.Record({ + issuance: exports.ValidDocumentStoreIssuanceStatusArray, + revocation: revocation_types_1.ValidRevocationStatusArray, + }), +}); +exports.InvalidDocumentStoreDataV2 = runtypes_1.Record({ + issuedOnAll: runtypes_1.Boolean, + revokedOnAny: runtypes_1.Optional(runtypes_1.Boolean), + details: runtypes_1.Record({ + issuance: exports.DocumentStoreIssuanceStatusArray, + revocation: runtypes_1.Optional(revocation_types_1.RevocationStatusArray), + }), +}); +/** + * Data for v3 Fragments + */ +exports.ValidDocumentStoreDataV3 = runtypes_1.Record({ + issuedOnAll: runtypes_1.Literal(true), + revokedOnAny: runtypes_1.Literal(false), + details: runtypes_1.Record({ + issuance: exports.ValidDocumentStoreIssuanceStatus, + revocation: revocation_types_1.ValidRevocationStatus, + }), +}); +exports.InvalidDocumentStoreDataV3 = runtypes_1.Record({ + issuedOnAll: runtypes_1.Boolean, + revokedOnAny: runtypes_1.Boolean, + details: runtypes_1.Record({ + issuance: exports.DocumentStoreIssuanceStatus, + revocation: revocation_types_1.RevocationStatus, + }), +}); diff --git a/dist/cjs/verifiers/documentStatus/documentStore/index.js b/dist/cjs/verifiers/documentStatus/documentStore/index.js new file mode 100644 index 00000000..6e7be98a --- /dev/null +++ b/dist/cjs/verifiers/documentStatus/documentStore/index.js @@ -0,0 +1,13 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./ethereumDocumentStoreStatus"), exports); diff --git a/dist/cjs/verifiers/documentStatus/revocation.types.js b/dist/cjs/verifiers/documentStatus/revocation.types.js new file mode 100644 index 00000000..0b80e5f9 --- /dev/null +++ b/dist/cjs/verifiers/documentStatus/revocation.types.js @@ -0,0 +1,31 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.OcspResponderRevocationReason = exports.OcspResponderRevocationStatus = exports.RevocationStatusArray = exports.RevocationStatus = exports.InvalidRevocationStatus = exports.ValidRevocationStatusArray = exports.ValidRevocationStatus = void 0; +var runtypes_1 = require("runtypes"); +var error_1 = require("../../types/error"); +exports.ValidRevocationStatus = runtypes_1.Record({ + revoked: runtypes_1.Literal(false), + address: runtypes_1.Optional(runtypes_1.String), +}); +exports.ValidRevocationStatusArray = runtypes_1.Array(exports.ValidRevocationStatus); +exports.InvalidRevocationStatus = runtypes_1.Record({ + revoked: runtypes_1.Literal(true), + address: runtypes_1.String, + reason: error_1.Reason, +}); +exports.RevocationStatus = runtypes_1.Union(exports.ValidRevocationStatus, exports.InvalidRevocationStatus); +exports.RevocationStatusArray = runtypes_1.Array(exports.RevocationStatus); +exports.OcspResponderRevocationStatus = runtypes_1.Union(runtypes_1.Literal("good"), runtypes_1.Literal("revoked"), runtypes_1.Literal("unknown")); +var OcspResponderRevocationReason; +(function (OcspResponderRevocationReason) { + OcspResponderRevocationReason[OcspResponderRevocationReason["UNSPECIFIED"] = 0] = "UNSPECIFIED"; + OcspResponderRevocationReason[OcspResponderRevocationReason["KEY_COMPROMISE"] = 1] = "KEY_COMPROMISE"; + OcspResponderRevocationReason[OcspResponderRevocationReason["CA_COMPROMISE"] = 2] = "CA_COMPROMISE"; + OcspResponderRevocationReason[OcspResponderRevocationReason["AFFILIATION_CHANGED"] = 3] = "AFFILIATION_CHANGED"; + OcspResponderRevocationReason[OcspResponderRevocationReason["SUPERSEDED"] = 4] = "SUPERSEDED"; + OcspResponderRevocationReason[OcspResponderRevocationReason["CESSATION_OF_OPERATION"] = 5] = "CESSATION_OF_OPERATION"; + OcspResponderRevocationReason[OcspResponderRevocationReason["CERTIFICATE_HOLD"] = 6] = "CERTIFICATE_HOLD"; + OcspResponderRevocationReason[OcspResponderRevocationReason["REMOVE_FROM_CRL"] = 8] = "REMOVE_FROM_CRL"; + OcspResponderRevocationReason[OcspResponderRevocationReason["PRIVILEGE_WITHDRAWN"] = 9] = "PRIVILEGE_WITHDRAWN"; + OcspResponderRevocationReason[OcspResponderRevocationReason["A_A_COMPROMISE"] = 10] = "A_A_COMPROMISE"; +})(OcspResponderRevocationReason = exports.OcspResponderRevocationReason || (exports.OcspResponderRevocationReason = {})); diff --git a/dist/cjs/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.js b/dist/cjs/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.js new file mode 100644 index 00000000..a5d1c144 --- /dev/null +++ b/dist/cjs/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.js @@ -0,0 +1,236 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.openAttestationEthereumTokenRegistryStatus = exports.isTokenMintedOnRegistry = exports.getTokenRegistry = void 0; +var open_attestation_1 = require("@govtechsg/open-attestation"); +var token_registry_1 = require("@govtechsg/token-registry"); +var ethers_1 = require("ethers"); +var error_1 = require("../../../types/error"); +var error_2 = require("../../../common/error"); +var errorHandler_1 = require("../../../common/errorHandler"); +var ethereumTokenRegistryStatus_type_1 = require("./ethereumTokenRegistryStatus.type"); +var name = "OpenAttestationEthereumTokenRegistryStatus"; +var type = "DOCUMENT_STATUS"; +var getTokenRegistry = function (document) { + if (open_attestation_1.utils.isWrappedV2Document(document)) { + var issuers = open_attestation_1.getData(document).issuers; + if (issuers.length !== 1) + throw new error_2.CodedError("Only one issuer is allowed for tokens", error_1.OpenAttestationEthereumTokenRegistryStatusCode.INVALID_ISSUERS, error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.INVALID_ISSUERS]); + if (!issuers[0].tokenRegistry) + throw new error_2.CodedError("Token registry is undefined", error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNDEFINED_TOKEN_REGISTRY, error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNDEFINED_TOKEN_REGISTRY]); + return issuers[0].tokenRegistry; + } + if (open_attestation_1.utils.isWrappedV3Document(document)) { + if (!document.openAttestationMetadata.proof.value) + throw new error_2.CodedError("Token registry is undefined", error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNDEFINED_TOKEN_REGISTRY, error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNDEFINED_TOKEN_REGISTRY]); + return document.openAttestationMetadata.proof.value; + } + throw new error_2.CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT, error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT]); +}; +exports.getTokenRegistry = getTokenRegistry; +var getMerkleRoot = function (document) { + if (open_attestation_1.utils.isWrappedV2Document(document)) + return "0x" + document.signature.merkleRoot; + else if (open_attestation_1.utils.isWrappedV3Document(document)) + return "0x" + document.proof.merkleRoot; + throw new error_2.CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT, error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT]); +}; +var isNonExistentToken = function (error) { + var message = error.message; + if (!message) + return false; + return message.includes("owner query for nonexistent token"); +}; +var isMissingTokenRegistry = function (error) { + var _a; + return (!error.reason && + ((_a = error.method) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === "ownerOf(uint256)".toLowerCase() && + error.code === ethers_1.errors.CALL_EXCEPTION); +}; +var decodeError = function (error) { + var _a; + var reason = error.reason && Array.isArray(error.reason) ? error.reason[0] : (_a = error.reason) !== null && _a !== void 0 ? _a : ""; + switch (true) { + case isNonExistentToken(error): + return "Document has not been issued under token registry"; + case isMissingTokenRegistry(error): + return "Token registry is not found"; + case reason.toLowerCase() === "ENS name not configured".toLowerCase() && + error.code === ethers_1.errors.UNSUPPORTED_OPERATION: + return "ENS name is not configured"; + case reason.toLowerCase() === "invalid address".toLowerCase() && error.code === ethers_1.errors.INVALID_ARGUMENT: + return "Invalid token registry address"; + case error.code === ethers_1.errors.INVALID_ARGUMENT: + return "Invalid contract arguments"; + case error.code === ethers_1.errors.SERVER_ERROR: + throw new error_2.CodedError("Unable to connect to the Ethereum network, please try again later", error_1.OpenAttestationEthereumTokenRegistryStatusCode.SERVER_ERROR, error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.SERVER_ERROR]); + default: + throw error; + } +}; +var isTokenMintedOnRegistry = function (_a) { + var tokenRegistry = _a.tokenRegistry, merkleRoot = _a.merkleRoot, provider = _a.provider; + return __awaiter(void 0, void 0, void 0, function () { + var tokenRegistryContract, minted, error_3; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _b.trys.push([0, 3, , 4]); + return [4 /*yield*/, token_registry_1.TradeTrustErc721Factory.connect(tokenRegistry, provider)]; + case 1: + tokenRegistryContract = _b.sent(); + return [4 /*yield*/, tokenRegistryContract.ownerOf(merkleRoot).then(function (owner) { return !(owner === ethers_1.constants.AddressZero); })]; + case 2: + minted = _b.sent(); + return [2 /*return*/, minted + ? { minted: minted, address: tokenRegistry } + : { + minted: minted, + address: tokenRegistry, + reason: { + code: error_1.OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED, + codeString: error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED], + message: "Document " + merkleRoot + " has not been issued under contract " + tokenRegistry, + }, + }]; + case 3: + error_3 = _b.sent(); + return [2 /*return*/, { + minted: false, + address: tokenRegistry, + reason: { + message: decodeError(error_3), + code: error_1.OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED, + codeString: error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED], + }, + }]; + case 4: return [2 /*return*/]; + } + }); + }); +}; +exports.isTokenMintedOnRegistry = isTokenMintedOnRegistry; +var skip = function () { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, { + status: "SKIPPED", + type: type, + name: name, + reason: { + code: error_1.OpenAttestationEthereumTokenRegistryStatusCode.SKIPPED, + codeString: error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.SKIPPED], + message: "Document issuers doesn't have \"tokenRegistry\" property or " + open_attestation_1.v3.Method.TokenRegistry + " method", + }, + }]; + }); +}); }; +var test = function (document) { + if (open_attestation_1.utils.isWrappedV2Document(document)) { + var documentData = open_attestation_1.getData(document); + return documentData.issuers.some(function (issuer) { return "tokenRegistry" in issuer; }); + } + else if (open_attestation_1.utils.isWrappedV3Document(document)) { + return document.openAttestationMetadata.proof.method === open_attestation_1.v3.Method.TokenRegistry; + } + return false; +}; +// TODO split +var verify = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + var tokenRegistry, merkleRoot, mintStatus, fragment, fragment; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!open_attestation_1.utils.isWrappedV3Document(document) && !open_attestation_1.utils.isWrappedV2Document(document)) + throw new error_2.CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT, error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT]); + tokenRegistry = exports.getTokenRegistry(document); + merkleRoot = getMerkleRoot(document); + return [4 /*yield*/, exports.isTokenMintedOnRegistry({ tokenRegistry: tokenRegistry, merkleRoot: merkleRoot, provider: options.provider })]; + case 1: + mintStatus = _a.sent(); + if (ethereumTokenRegistryStatus_type_1.ValidTokenRegistryStatus.guard(mintStatus)) { + fragment = { + name: name, + type: type, + status: "VALID", + }; + if (open_attestation_1.utils.isWrappedV3Document(document)) { + return [2 /*return*/, __assign(__assign({}, fragment), { data: { mintedOnAll: true, details: mintStatus } })]; + } + else { + return [2 /*return*/, __assign(__assign({}, fragment), { data: { mintedOnAll: true, details: [mintStatus] } })]; + } + } + else { + fragment = { + name: name, + type: type, + reason: mintStatus.reason, + status: "INVALID", + }; + if (open_attestation_1.utils.isWrappedV3Document(document)) { + return [2 /*return*/, __assign(__assign({}, fragment), { data: { mintedOnAll: false, details: mintStatus } })]; + } + else { + return [2 /*return*/, __assign(__assign({}, fragment), { data: { mintedOnAll: false, details: [mintStatus] } })]; + } + } + return [2 /*return*/]; + } + }); +}); }; +exports.openAttestationEthereumTokenRegistryStatus = { + skip: skip, + test: test, + verify: errorHandler_1.withCodedErrorHandler(verify, { + name: name, + type: type, + unexpectedErrorCode: error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNEXPECTED_ERROR, + unexpectedErrorString: error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNEXPECTED_ERROR], + }), +}; diff --git a/dist/cjs/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.js b/dist/cjs/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.js new file mode 100644 index 00000000..9bef2751 --- /dev/null +++ b/dist/cjs/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.js @@ -0,0 +1,39 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.InvalidTokenRegistryDataV3 = exports.ValidTokenRegistryDataV3 = exports.InvalidTokenRegistryDataV2 = exports.ValidTokenRegistryDataV2 = exports.InvalidTokenRegistryStatus = exports.ValidTokenRegistryStatus = void 0; +var runtypes_1 = require("runtypes"); +var error_1 = require("../../../types/error"); +/** + * Token registry mint status + */ +exports.ValidTokenRegistryStatus = runtypes_1.Record({ + minted: runtypes_1.Literal(true), + address: runtypes_1.String, +}); +exports.InvalidTokenRegistryStatus = runtypes_1.Record({ + minted: runtypes_1.Literal(false), + address: runtypes_1.String, + reason: error_1.Reason, +}); +/** + * Data for v2 Fragments + */ +exports.ValidTokenRegistryDataV2 = runtypes_1.Record({ + mintedOnAll: runtypes_1.Literal(true), + details: runtypes_1.Array(exports.ValidTokenRegistryStatus), +}); +exports.InvalidTokenRegistryDataV2 = runtypes_1.Record({ + mintedOnAll: runtypes_1.Literal(false), + details: runtypes_1.Array(runtypes_1.Union(exports.ValidTokenRegistryStatus, exports.InvalidTokenRegistryStatus)), +}); +/** + * Data for v3 Fragments + */ +exports.ValidTokenRegistryDataV3 = runtypes_1.Record({ + mintedOnAll: runtypes_1.Literal(true), + details: exports.ValidTokenRegistryStatus, +}); +exports.InvalidTokenRegistryDataV3 = runtypes_1.Record({ + mintedOnAll: runtypes_1.Literal(false), + details: exports.InvalidTokenRegistryStatus, +}); diff --git a/dist/cjs/verifiers/documentStatus/tokenRegistry/index.js b/dist/cjs/verifiers/documentStatus/tokenRegistry/index.js new file mode 100644 index 00000000..f926c61a --- /dev/null +++ b/dist/cjs/verifiers/documentStatus/tokenRegistry/index.js @@ -0,0 +1,13 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./ethereumTokenRegistryStatus"), exports); diff --git a/dist/cjs/verifiers/documentStatus/utils.js b/dist/cjs/verifiers/documentStatus/utils.js new file mode 100644 index 00000000..2ac42057 --- /dev/null +++ b/dist/cjs/verifiers/documentStatus/utils.js @@ -0,0 +1,193 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.isRevokedOnDocumentStore = exports.isRevokedByOcspResponder = exports.isAnyHashRevoked = exports.decodeError = exports.getIntermediateHashes = void 0; +var open_attestation_1 = require("@govtechsg/open-attestation"); +var ethers_1 = require("ethers"); +var document_store_1 = require("@govtechsg/document-store"); +var error_1 = require("../../types/error"); +var error_2 = require("../../common/error"); +var revocation_types_1 = require("./revocation.types"); +var axios_1 = __importDefault(require("axios")); +var didSignedDocumentStatus_type_1 = require("./didSigned/didSignedDocumentStatus.type"); +var getIntermediateHashes = function (targetHash, proofs) { + if (proofs === void 0) { proofs = []; } + var hashes = ["0x" + targetHash]; + proofs.reduce(function (prev, curr) { + var next = open_attestation_1.utils.combineHashString(prev, curr); + hashes.push("0x" + next); + return next; + }, targetHash); + return hashes; +}; +exports.getIntermediateHashes = getIntermediateHashes; +/** + * Try to decode the error to see if we can deterministically tell if the document has NOT been issued or revoked. + * + * In case where we cannot tell, we throw an error + * */ +var decodeError = function (error) { + var _a, _b, _c, _d; + var reason = error.reason && Array.isArray(error.reason) ? error.reason[0] : (_a = error.reason) !== null && _a !== void 0 ? _a : ""; + switch (true) { + case !error.reason && + (((_b = error.method) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === "isRevoked(bytes32)".toLowerCase() || + ((_c = error.method) === null || _c === void 0 ? void 0 : _c.toLowerCase()) === "isIssued(bytes32)".toLowerCase()) && + error.code === ethers_1.errors.CALL_EXCEPTION: + return "Contract is not found"; + case reason.toLowerCase() === "ENS name not configured".toLowerCase() && + error.code === ethers_1.errors.UNSUPPORTED_OPERATION: + return "ENS name is not configured"; + case reason.toLowerCase() === "bad address checksum".toLowerCase() && error.code === ethers_1.errors.INVALID_ARGUMENT: + return "Bad document store address checksum"; + case ((_d = error.message) === null || _d === void 0 ? void 0 : _d.toLowerCase()) === "name not found".toLowerCase(): + return "ENS name is not found"; + case reason.toLowerCase() === "invalid address".toLowerCase() && error.code === ethers_1.errors.INVALID_ARGUMENT: + return "Invalid document store address"; + case error.code === ethers_1.errors.INVALID_ARGUMENT: + return "Invalid call arguments"; + case error.code === ethers_1.errors.SERVER_ERROR: + throw new error_2.CodedError("Unable to connect to the Ethereum network, please try again later", error_1.OpenAttestationEthereumDocumentStoreStatusCode.SERVER_ERROR, error_1.OpenAttestationEthereumDocumentStoreStatusCode[error_1.OpenAttestationEthereumDocumentStoreStatusCode.SERVER_ERROR]); + default: + throw error; + } +}; +exports.decodeError = decodeError; +/** + * Given a list of hashes, check against one smart contract if any of the hash has been revoked + * */ +var isAnyHashRevoked = function (smartContract, intermediateHashes) { return __awaiter(void 0, void 0, void 0, function () { + var revokedStatusDeferred, revokedStatuses; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + revokedStatusDeferred = intermediateHashes.map(function (hash) { + return smartContract.isRevoked(hash).then(function (status) { return (status ? hash : undefined); }); + }); + return [4 /*yield*/, Promise.all(revokedStatusDeferred)]; + case 1: + revokedStatuses = _a.sent(); + return [2 /*return*/, revokedStatuses.find(function (hash) { return hash; })]; + } + }); +}); }; +exports.isAnyHashRevoked = isAnyHashRevoked; +var isRevokedByOcspResponder = function (_a) { + var certificateId = _a.certificateId, location = _a.location; + return __awaiter(void 0, void 0, void 0, function () { + var data, reasonCode; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: return [4 /*yield*/, axios_1.default.get(location + "/" + certificateId)]; + case 1: + data = (_b.sent()).data; + if (didSignedDocumentStatus_type_1.ValidOcspResponseRevoked.guard(data) && data.certificateStatus === "revoked") { + reasonCode = data.reasonCode; + return [2 /*return*/, { + revoked: true, + address: location, + reason: { + message: revocation_types_1.OcspResponderRevocationReason[reasonCode], + code: reasonCode, + codeString: revocation_types_1.OcspResponderRevocationReason[reasonCode], + }, + }]; + } + else if (didSignedDocumentStatus_type_1.ValidOcspResponse.guard(data) && data.certificateStatus !== "revoked") { + return [2 /*return*/, { + revoked: false, + address: location, + }]; + } + throw new error_2.CodedError("oscp response invalid", error_1.OpenAttestationDidSignedDocumentStatusCode.OCSP_RESPONSE_INVALID, "OCSP_RESPONSE_INVALID"); + } + }); + }); +}; +exports.isRevokedByOcspResponder = isRevokedByOcspResponder; +var isRevokedOnDocumentStore = function (_a) { + var documentStore = _a.documentStore, merkleRoot = _a.merkleRoot, provider = _a.provider, targetHash = _a.targetHash, proofs = _a.proofs; + return __awaiter(void 0, void 0, void 0, function () { + var documentStoreContract, intermediateHashes, revokedHash, error_3; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _b.trys.push([0, 3, , 4]); + return [4 /*yield*/, document_store_1.DocumentStoreFactory.connect(documentStore, provider)]; + case 1: + documentStoreContract = _b.sent(); + intermediateHashes = exports.getIntermediateHashes(targetHash, proofs); + return [4 /*yield*/, exports.isAnyHashRevoked(documentStoreContract, intermediateHashes)]; + case 2: + revokedHash = _b.sent(); + return [2 /*return*/, revokedHash + ? { + revoked: true, + address: documentStore, + reason: { + message: "Document " + merkleRoot + " has been revoked under contract " + documentStore, + code: error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED, + codeString: error_1.OpenAttestationEthereumDocumentStoreStatusCode[error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED], + }, + } + : { + revoked: false, + address: documentStore, + }]; + case 3: + error_3 = _b.sent(); + // If error can be decoded and it's because of document is not revoked, we return false + // Else allow error to continue to bubble up + return [2 /*return*/, { + revoked: true, + address: documentStore, + reason: { + message: exports.decodeError(error_3), + code: error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED, + codeString: error_1.OpenAttestationEthereumDocumentStoreStatusCode[error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED], + }, + }]; + case 4: return [2 /*return*/]; + } + }); + }); +}; +exports.isRevokedOnDocumentStore = isRevokedOnDocumentStore; diff --git a/dist/cjs/verifiers/issuerIdentity/did/didIdentityProof.js b/dist/cjs/verifiers/issuerIdentity/did/didIdentityProof.js new file mode 100644 index 00000000..10044c58 --- /dev/null +++ b/dist/cjs/verifiers/issuerIdentity/did/didIdentityProof.js @@ -0,0 +1,185 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.openAttestationDidIdentityProof = void 0; +var open_attestation_1 = require("@govtechsg/open-attestation"); +var error_1 = require("../../../types/error"); +var verifier_1 = require("../../../did/verifier"); +var errorHandler_1 = require("../../../common/errorHandler"); +var error_2 = require("../../../common/error"); +var name = "OpenAttestationDidIdentityProof"; +var type = "ISSUER_IDENTITY"; +var skip = function () { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, { + status: "SKIPPED", + type: type, + name: name, + reason: { + code: error_1.OpenAttestationDidCode.SKIPPED, + codeString: error_1.OpenAttestationDidCode[error_1.OpenAttestationDidCode.SKIPPED], + message: "Document is not using DID as top level identifier or has not been wrapped", + }, + }]; + }); +}); }; +var test = function (document) { + if (open_attestation_1.utils.isWrappedV2Document(document)) { + var issuers = open_attestation_1.getData(document).issuers; + return issuers.some(function (issuer) { var _a; return ((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === open_attestation_1.v2.IdentityProofType.Did; }); + } + else if (open_attestation_1.utils.isWrappedV3Document(document)) { + return document.openAttestationMetadata.identityProof.type === open_attestation_1.v3.IdentityProofType.Did; + } + return false; +}; +var verifyV2 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + var data, merkleRoot, signatureVerificationDeferred, signatureVerifications, invalidSignature; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!open_attestation_1.utils.isSignedWrappedV2Document(document)) + throw new error_2.CodedError("Document is not signed", error_1.OpenAttestationDidCode.UNSIGNED, "UNSIGNED"); + data = open_attestation_1.getData(document); + merkleRoot = "0x" + document.signature.merkleRoot; + signatureVerificationDeferred = data.issuers.map(function (issuer) { return __awaiter(void 0, void 0, void 0, function () { + var did, key_1, correspondingProof; + var _a, _b; + return __generator(this, function (_c) { + if (((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === "DID") { + did = issuer.id; + if (!did) + throw new error_2.CodedError("id is missing in issuer", error_1.OpenAttestationDidCode.DID_MISSING, "DID_MISSING"); + key_1 = (_b = issuer.identityProof) === null || _b === void 0 ? void 0 : _b.key; + if (!key_1) + throw new error_2.CodedError("Key is not present", error_1.OpenAttestationDidCode.MALFORMED_IDENTITY_PROOF, "MALFORMED_IDENTITY_PROOF"); + correspondingProof = document.proof.find(function (p) { return p.verificationMethod.toLowerCase() === key_1.toLowerCase(); }); + if (!correspondingProof) + throw new error_2.CodedError("No proof for " + key_1, error_1.OpenAttestationDidCode.MALFORMED_IDENTITY_PROOF, "MALFORMED_IDENTITY_PROOF"); + return [2 /*return*/, verifier_1.verifySignature({ + merkleRoot: merkleRoot, + key: key_1, + signature: correspondingProof.signature, + did: did, + resolver: options.resolver, + })]; + } + throw new error_2.CodedError("Issuer is not using DID identityProof type", error_1.OpenAttestationDidCode.INVALID_ISSUERS, error_1.OpenAttestationDidCode[error_1.OpenAttestationDidCode.INVALID_ISSUERS]); + }); + }); }); + return [4 /*yield*/, Promise.all(signatureVerificationDeferred)]; + case 1: + signatureVerifications = _a.sent(); + if (verifier_1.ValidDidVerificationStatusArray.guard(signatureVerifications)) { + return [2 /*return*/, { + name: name, + type: type, + data: signatureVerifications, + status: "VALID", + }]; + } + invalidSignature = signatureVerifications.find(verifier_1.InvalidDidVerificationStatus.guard); + if (verifier_1.InvalidDidVerificationStatus.guard(invalidSignature)) { + return [2 /*return*/, { + name: name, + type: type, + data: signatureVerifications, + reason: invalidSignature.reason, + status: "INVALID", + }]; + } + throw new error_2.CodedError("Unable to retrieve the reason of the failure", error_1.OpenAttestationDidCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); + } + }); +}); }; +var verifyV3 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + var merkleRoot, _a, key, signature, did, verificationStatus; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + if (!open_attestation_1.utils.isSignedWrappedV3Document(document)) + throw new error_2.CodedError("Document is not signed", error_1.OpenAttestationDidCode.UNSIGNED, "UNSIGNED"); + merkleRoot = "0x" + document.proof.merkleRoot; + _a = document.proof, key = _a.key, signature = _a.signature; + did = document.openAttestationMetadata.identityProof.identifier; + return [4 /*yield*/, verifier_1.verifySignature({ + did: did, + merkleRoot: merkleRoot, + key: key, + signature: signature, + resolver: options.resolver, + })]; + case 1: + verificationStatus = _b.sent(); + if (verifier_1.ValidDidVerificationStatus.guard(verificationStatus)) { + return [2 /*return*/, { + name: name, + type: type, + data: verificationStatus, + status: "VALID", + }]; + } + return [2 /*return*/, { + name: name, + type: type, + data: verificationStatus, + reason: verificationStatus.reason, + status: "INVALID", + }]; + } + }); +}); }; +var verify = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + if (open_attestation_1.utils.isWrappedV2Document(document)) + return [2 /*return*/, verifyV2(document, options)]; + else if (open_attestation_1.utils.isWrappedV3Document(document)) + return [2 /*return*/, verifyV3(document, options)]; + throw new error_2.CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", error_1.OpenAttestationDidCode.UNRECOGNIZED_DOCUMENT, error_1.OpenAttestationDidCode[error_1.OpenAttestationDidCode.UNRECOGNIZED_DOCUMENT]); + }); +}); }; +exports.openAttestationDidIdentityProof = { + skip: skip, + test: test, + verify: errorHandler_1.withCodedErrorHandler(verify, { + name: name, + type: type, + unexpectedErrorCode: error_1.OpenAttestationDidCode.UNEXPECTED_ERROR, + unexpectedErrorString: error_1.OpenAttestationDidCode[error_1.OpenAttestationDidCode.UNEXPECTED_ERROR], + }), +}; diff --git a/dist/cjs/verifiers/issuerIdentity/did/didIdentityProof.type.js b/dist/cjs/verifiers/issuerIdentity/did/didIdentityProof.type.js new file mode 100644 index 00000000..c8ad2e54 --- /dev/null +++ b/dist/cjs/verifiers/issuerIdentity/did/didIdentityProof.type.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/cjs/verifiers/issuerIdentity/did/index.js b/dist/cjs/verifiers/issuerIdentity/did/index.js new file mode 100644 index 00000000..958a1609 --- /dev/null +++ b/dist/cjs/verifiers/issuerIdentity/did/index.js @@ -0,0 +1,13 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./didIdentityProof"), exports); diff --git a/dist/cjs/verifiers/issuerIdentity/dnsDid/dnsDidProof.js b/dist/cjs/verifiers/issuerIdentity/dnsDid/dnsDidProof.js new file mode 100644 index 00000000..b267d3ca --- /dev/null +++ b/dist/cjs/verifiers/issuerIdentity/dnsDid/dnsDidProof.js @@ -0,0 +1,186 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.openAttestationDnsDidIdentityProof = void 0; +var open_attestation_1 = require("@govtechsg/open-attestation"); +var dnsprove_1 = require("@govtechsg/dnsprove"); +var error_1 = require("../../../types/error"); +var errorHandler_1 = require("../../../common/errorHandler"); +var error_2 = require("../../../common/error"); +var dnsDidProof_type_1 = require("./dnsDidProof.type"); +var name = "OpenAttestationDnsDidIdentityProof"; +var type = "ISSUER_IDENTITY"; +var skip = function () { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, { + status: "SKIPPED", + type: type, + name: name, + reason: { + code: error_1.OpenAttestationDnsDidCode.SKIPPED, + codeString: error_1.OpenAttestationDnsDidCode[error_1.OpenAttestationDnsDidCode.SKIPPED], + message: "Document was not issued using DNS-DID", + }, + }]; + }); +}); }; +var test = function (document) { + if (open_attestation_1.utils.isSignedWrappedV2Document(document)) { + var data = open_attestation_1.getData(document); + return data.issuers.some(function (issuer) { var _a; return ((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === "DNS-DID"; }); + } + else if (open_attestation_1.utils.isSignedWrappedV3Document(document)) { + return document.openAttestationMetadata.identityProof.type === open_attestation_1.v3.IdentityProofType.DNSDid; + } + return false; +}; +var verifyIssuerDnsDid = function (_a) { + var key = _a.key, location = _a.location; + return __awaiter(void 0, void 0, void 0, function () { + var records; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: return [4 /*yield*/, dnsprove_1.getDnsDidRecords(location)]; + case 1: + records = _b.sent(); + return [2 /*return*/, { + location: location, + key: key, + status: records.some(function (record) { return record.publicKey.toLowerCase() === key.toLowerCase(); }) ? "VALID" : "INVALID", + }]; + } + }); + }); +}; +var verifyV2 = function (document) { return __awaiter(void 0, void 0, void 0, function () { + var documentData, deferredVerificationStatus, verificationStatus; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + documentData = open_attestation_1.getData(document); + deferredVerificationStatus = documentData.issuers.map(function (issuer) { + var identityProof = issuer.identityProof; + if (!identityProof) + throw new error_2.CodedError("Identity proof missing", error_1.OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF, error_1.OpenAttestationDnsDidCode[error_1.OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF]); + var key = identityProof.key, location = identityProof.location, identityProofType = identityProof.type; + if (identityProofType !== open_attestation_1.v2.IdentityProofType.DNSDid) + throw new error_2.CodedError("Issuer is not using DID-DNS identityProof type", error_1.OpenAttestationDnsDidCode.INVALID_ISSUERS, error_1.OpenAttestationDnsDidCode[error_1.OpenAttestationDnsDidCode.INVALID_ISSUERS]); + if (!location) + throw new error_2.CodedError("location is not present in identity proof", error_1.OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF, error_1.OpenAttestationDnsDidCode[error_1.OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF]); + if (!key) + throw new error_2.CodedError("key is not present in identity proof", error_1.OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF, error_1.OpenAttestationDnsDidCode[error_1.OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF]); + return verifyIssuerDnsDid({ key: key, location: location }); + }); + return [4 /*yield*/, Promise.all(deferredVerificationStatus)]; + case 1: + verificationStatus = _a.sent(); + if (dnsDidProof_type_1.ValidDnsDidVerificationStatusArray.guard(verificationStatus)) { + return [2 /*return*/, { + name: name, + type: type, + data: verificationStatus, + status: "VALID", + }]; + } + return [2 /*return*/, { + name: name, + type: type, + data: verificationStatus, + reason: { + message: "Could not find identity at location", + code: error_1.OpenAttestationDnsDidCode.INVALID_IDENTITY, + codeString: "INVALID_IDENTITY", + }, + status: "INVALID", + }]; + } + }); +}); }; +var verifyV3 = function (document) { return __awaiter(void 0, void 0, void 0, function () { + var location, key, verificationStatus; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!open_attestation_1.utils.isSignedWrappedV3Document(document)) + throw new error_2.CodedError("document is not signed", error_1.OpenAttestationDnsDidCode.UNSIGNED, error_1.OpenAttestationDnsDidCode[error_1.OpenAttestationDnsDidCode.UNSIGNED]); + location = document.openAttestationMetadata.identityProof.identifier; + key = document.proof.key; + return [4 /*yield*/, verifyIssuerDnsDid({ key: key, location: location })]; + case 1: + verificationStatus = _a.sent(); + if (dnsDidProof_type_1.ValidDnsDidVerificationStatus.guard(verificationStatus)) { + return [2 /*return*/, { + name: name, + type: type, + data: verificationStatus, + status: "VALID", + }]; + } + return [2 /*return*/, { + name: name, + type: type, + data: verificationStatus, + status: "INVALID", + reason: { + message: "Could not find identity at location", + code: error_1.OpenAttestationDnsDidCode.INVALID_IDENTITY, + codeString: "INVALID_IDENTITY", + }, + }]; + } + }); +}); }; +var verify = function (document) { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + if (open_attestation_1.utils.isSignedWrappedV2Document(document)) + return [2 /*return*/, verifyV2(document)]; + else if (open_attestation_1.utils.isSignedWrappedV3Document(document)) + return [2 /*return*/, verifyV3(document)]; + throw new error_2.CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", error_1.OpenAttestationDnsDidCode.UNRECOGNIZED_DOCUMENT, error_1.OpenAttestationDnsDidCode[error_1.OpenAttestationDnsDidCode.UNRECOGNIZED_DOCUMENT]); + }); +}); }; +exports.openAttestationDnsDidIdentityProof = { + skip: skip, + test: test, + verify: errorHandler_1.withCodedErrorHandler(verify, { + name: name, + type: type, + unexpectedErrorCode: error_1.OpenAttestationDnsDidCode.UNEXPECTED_ERROR, + unexpectedErrorString: error_1.OpenAttestationDnsDidCode[error_1.OpenAttestationDnsDidCode.UNEXPECTED_ERROR], + }), +}; diff --git a/dist/cjs/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.js b/dist/cjs/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.js new file mode 100644 index 00000000..f3022636 --- /dev/null +++ b/dist/cjs/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.js @@ -0,0 +1,20 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.DnsDidVerificationStatusArray = exports.DnsDidVerificationStatus = exports.InvalidDnsDidVerificationStatus = exports.ValidDnsDidVerificationStatusArray = exports.ValidDnsDidVerificationStatus = void 0; +var runtypes_1 = require("runtypes"); +/** + * DNS-DID verification status + */ +exports.ValidDnsDidVerificationStatus = runtypes_1.Record({ + status: runtypes_1.Literal("VALID"), + location: runtypes_1.String, + key: runtypes_1.String, +}); +exports.ValidDnsDidVerificationStatusArray = runtypes_1.Array(exports.ValidDnsDidVerificationStatus).withConstraint(function (elements) { return elements.length > 0 || "Expect at least one valid element"; }); +exports.InvalidDnsDidVerificationStatus = runtypes_1.Record({ + status: runtypes_1.Literal("INVALID"), + location: runtypes_1.String, + key: runtypes_1.String, +}); +exports.DnsDidVerificationStatus = runtypes_1.Union(exports.ValidDnsDidVerificationStatus, exports.InvalidDnsDidVerificationStatus); +exports.DnsDidVerificationStatusArray = runtypes_1.Array(exports.DnsDidVerificationStatus); diff --git a/dist/cjs/verifiers/issuerIdentity/dnsDid/index.js b/dist/cjs/verifiers/issuerIdentity/dnsDid/index.js new file mode 100644 index 00000000..ff72a0fb --- /dev/null +++ b/dist/cjs/verifiers/issuerIdentity/dnsDid/index.js @@ -0,0 +1,13 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./dnsDidProof"), exports); diff --git a/dist/cjs/verifiers/issuerIdentity/dnsTxt/index.js b/dist/cjs/verifiers/issuerIdentity/dnsTxt/index.js new file mode 100644 index 00000000..33f18d67 --- /dev/null +++ b/dist/cjs/verifiers/issuerIdentity/dnsTxt/index.js @@ -0,0 +1,13 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./openAttestationDnsTxt"), exports); diff --git a/dist/cjs/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.js b/dist/cjs/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.js new file mode 100644 index 00000000..1fb5e045 --- /dev/null +++ b/dist/cjs/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.js @@ -0,0 +1,220 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.openAttestationDnsTxtIdentityProof = void 0; +var open_attestation_1 = require("@govtechsg/open-attestation"); +var dnsprove_1 = require("@govtechsg/dnsprove"); +var error_1 = require("../../../types/error"); +var errorHandler_1 = require("../../../common/errorHandler"); +var error_2 = require("../../../common/error"); +var openAttestationDnsTxt_type_1 = require("./openAttestationDnsTxt.type"); +var name = "OpenAttestationDnsTxtIdentityProof"; +var type = "ISSUER_IDENTITY"; +// Resolve identity of an issuer, currently supporting only DNS-TXT +// DNS-TXT is explained => https://github.com/Open-Attestation/adr/blob/master/decentralized_identity_proof_DNS-TXT.md +var resolveIssuerIdentity = function (location, smartContractAddress, options) { return __awaiter(void 0, void 0, void 0, function () { + var network, records, matchingRecord; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, options.provider.getNetwork()]; + case 1: + network = _a.sent(); + return [4 /*yield*/, dnsprove_1.getDocumentStoreRecords(location)]; + case 2: + records = _a.sent(); + matchingRecord = records.find(function (record) { + return record.addr.toLowerCase() === smartContractAddress.toLowerCase() && + record.netId === network.chainId.toString(10) && + record.type === "openatts" && + record.net === "ethereum"; + }); + return [2 /*return*/, matchingRecord + ? { + status: "VALID", + location: location, + value: smartContractAddress, + } + : { + status: "INVALID", + location: location, + value: smartContractAddress, + reason: { + message: "Matching DNS record not found for " + smartContractAddress, + code: error_1.OpenAttestationDnsTxtCode.MATCHING_RECORD_NOT_FOUND, + codeString: error_1.OpenAttestationDnsTxtCode[error_1.OpenAttestationDnsTxtCode.MATCHING_RECORD_NOT_FOUND], + }, + }]; + } + }); +}); }; +var skip = function () { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, { + status: "SKIPPED", + type: type, + name: name, + reason: { + code: error_1.OpenAttestationDnsTxtCode.SKIPPED, + codeString: error_1.OpenAttestationDnsTxtCode[error_1.OpenAttestationDnsTxtCode.SKIPPED], + message: "Document issuers doesn't have \"documentStore\" / \"tokenRegistry\" property or doesn't use " + open_attestation_1.v3.IdentityProofType.DNSTxt + " type", + }, + }]; + }); +}); }; +var test = function (document) { + if (open_attestation_1.utils.isWrappedV2Document(document)) { + var documentData = open_attestation_1.getData(document); + // at least one issuer uses DNS-TXT + return documentData.issuers.some(function (issuer) { + var _a; + return ((issuer.documentStore || issuer.tokenRegistry || issuer.certificateStore) && + ((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === open_attestation_1.v2.IdentityProofType.DNSTxt); + }); + } + else if (open_attestation_1.utils.isWrappedV3Document(document)) { + return document.openAttestationMetadata.identityProof.type === open_attestation_1.v3.IdentityProofType.DNSTxt; + } + return false; +}; +var verifyV2 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + var documentData, identities, invalidIdentity; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + documentData = open_attestation_1.getData(document); + return [4 /*yield*/, Promise.all(documentData.issuers.map(function (issuer) { + var _a; + if (((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === open_attestation_1.v2.IdentityProofType.DNSTxt) { + var location = issuer.identityProof.location; + var smartContractAddress = issuer.documentStore || issuer.tokenRegistry || issuer.certificateStore; + if (!location) + throw new error_2.CodedError("Location not found in identity proof", error_1.OpenAttestationDnsTxtCode.INVALID_ISSUERS, error_1.OpenAttestationDnsTxtCode[error_1.OpenAttestationDnsTxtCode.INVALID_ISSUERS]); + if (!smartContractAddress) + throw new error_2.CodedError("Smart contract address not found in identity proof", error_1.OpenAttestationDnsTxtCode.INVALID_ISSUERS, error_1.OpenAttestationDnsTxtCode[error_1.OpenAttestationDnsTxtCode.INVALID_ISSUERS]); + return resolveIssuerIdentity(location, smartContractAddress, options); + } + var invalidResponse = { + status: "INVALID", + reason: { + message: "Issuer is not using DNS-TXT identityProof type", + code: error_1.OpenAttestationDnsTxtCode.INVALID_ISSUERS, + codeString: error_1.OpenAttestationDnsTxtCode[error_1.OpenAttestationDnsTxtCode.INVALID_ISSUERS], + }, + }; + return invalidResponse; // eslint is happy, so am I (https://github.com/bradzacher/eslint-plugin-typescript/blob/master/docs/rules/no-object-literal-type-assertion.md) + }))]; + case 1: + identities = _a.sent(); + if (openAttestationDnsTxt_type_1.ValidDnsTxtVerificationStatusArray.guard(identities)) { + return [2 /*return*/, { + name: name, + type: type, + data: identities, + status: "VALID", + }]; + } + invalidIdentity = identities.find(openAttestationDnsTxt_type_1.InvalidDnsTxtVerificationStatus.guard); + if (openAttestationDnsTxt_type_1.InvalidDnsTxtVerificationStatus.guard(invalidIdentity)) { + return [2 /*return*/, { + name: name, + type: type, + data: identities, + reason: invalidIdentity.reason, + status: "INVALID", + }]; + } + throw new error_2.CodedError("Unable to retrieve the reason of the failure", error_1.OpenAttestationDnsTxtCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); + } + }); +}); }; +var verifyV3 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + var smartContractAddress, identifier, issuerIdentity; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (document.openAttestationMetadata.proof.method !== open_attestation_1.v3.Method.DocumentStore && + document.openAttestationMetadata.proof.method !== open_attestation_1.v3.Method.TokenRegistry) + throw new error_2.CodedError("DNS-TXT is only supported with documents issued using document store or token registry", error_1.OpenAttestationDnsTxtCode.UNSUPPORTED, error_1.OpenAttestationDnsTxtCode[error_1.OpenAttestationDnsTxtCode.UNSUPPORTED]); + smartContractAddress = document.openAttestationMetadata.proof.value; + identifier = document.openAttestationMetadata.identityProof.identifier; + return [4 /*yield*/, resolveIssuerIdentity(identifier, smartContractAddress, options)]; + case 1: + issuerIdentity = _a.sent(); + if (openAttestationDnsTxt_type_1.ValidDnsTxtVerificationStatus.guard(issuerIdentity)) { + return [2 /*return*/, { + name: name, + type: type, + data: { + identifier: issuerIdentity.location, + value: issuerIdentity.value, + }, + status: "VALID", + }]; + } + return [2 /*return*/, { + name: name, + type: type, + data: { + identifier: issuerIdentity.location, + value: issuerIdentity.value, + }, + reason: issuerIdentity.reason, + status: "INVALID", + }]; + } + }); +}); }; +exports.openAttestationDnsTxtIdentityProof = { + skip: skip, + test: test, + verify: errorHandler_1.withCodedErrorHandler(function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + if (open_attestation_1.utils.isWrappedV2Document(document)) + return [2 /*return*/, verifyV2(document, options)]; + else if (open_attestation_1.utils.isWrappedV3Document(document)) + return [2 /*return*/, verifyV3(document, options)]; + // this code is actually unreachable because of the test function + throw new error_2.CodedError("Document does not match either v2 or v3 formats", error_1.OpenAttestationDnsTxtCode.UNRECOGNIZED_DOCUMENT, error_1.OpenAttestationDnsTxtCode[error_1.OpenAttestationDnsTxtCode.UNRECOGNIZED_DOCUMENT]); + }); + }); }, { + name: name, + type: type, + unexpectedErrorCode: error_1.OpenAttestationDnsTxtCode.UNEXPECTED_ERROR, + unexpectedErrorString: error_1.OpenAttestationDnsTxtCode[error_1.OpenAttestationDnsTxtCode.UNEXPECTED_ERROR], + }), +}; diff --git a/dist/cjs/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.js b/dist/cjs/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.js new file mode 100644 index 00000000..a32e90b6 --- /dev/null +++ b/dist/cjs/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.js @@ -0,0 +1,33 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.DnsTxtVerificationStatusDataV3 = exports.InvalidDnsTxtVerificationStatusDataV3 = exports.ValidDnsTxtVerificationStatusDataV3 = exports.DnsTxtVerificationStatusArray = exports.DnsTxtVerificationStatus = exports.InvalidDnsTxtVerificationStatus = exports.ValidDnsTxtVerificationStatusArray = exports.ValidDnsTxtVerificationStatus = void 0; +var runtypes_1 = require("runtypes"); +var error_1 = require("../../../types/error"); +/** + * DNS-TXT verification status + */ +exports.ValidDnsTxtVerificationStatus = runtypes_1.Record({ + status: runtypes_1.Literal("VALID"), + location: runtypes_1.String, + value: runtypes_1.String, +}); +exports.ValidDnsTxtVerificationStatusArray = runtypes_1.Array(exports.ValidDnsTxtVerificationStatus).withConstraint(function (elements) { return elements.length > 0 || "Expect at least one valid element"; }); +exports.InvalidDnsTxtVerificationStatus = runtypes_1.Record({ + status: runtypes_1.Literal("INVALID"), + location: runtypes_1.Optional(runtypes_1.String), + value: runtypes_1.Optional(runtypes_1.String), + reason: error_1.Reason, +}); +exports.DnsTxtVerificationStatus = runtypes_1.Union(exports.ValidDnsTxtVerificationStatus, exports.InvalidDnsTxtVerificationStatus); +exports.DnsTxtVerificationStatusArray = runtypes_1.Array(exports.DnsTxtVerificationStatus); +/** + * Data for v3 Fragments + */ +exports.ValidDnsTxtVerificationStatusDataV3 = runtypes_1.Record({ + identifier: runtypes_1.String, + value: runtypes_1.String, +}); +// by design runtypes will validate arrays when an object has only partial properties +// https://github.com/pelotom/runtypes/issues/32 +exports.InvalidDnsTxtVerificationStatusDataV3 = exports.ValidDnsTxtVerificationStatusDataV3.asPartial().withConstraint(function (value) { return !Array.isArray(value) || "can't be an array"; }); +exports.DnsTxtVerificationStatusDataV3 = runtypes_1.Union(exports.ValidDnsTxtVerificationStatusDataV3, exports.InvalidDnsTxtVerificationStatusDataV3); diff --git a/dist/cjs/verifiers/verificationBuilder.js b/dist/cjs/verifiers/verificationBuilder.js new file mode 100644 index 00000000..c58340fe --- /dev/null +++ b/dist/cjs/verifiers/verificationBuilder.js @@ -0,0 +1,37 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.verificationBuilder = void 0; +var utils_1 = require("../common/utils"); +var messages_1 = require("../common/messages"); +// keeping the following code for posterity. If we want the function below to return better types, we can use the following +// type PromiseValue = T extends Promise ? U : never; +// Promise>[]> +/** + * A verification manager will run a list of {@link Verifier} over a signed document. + * Before running each verifier, the manager will make sure the verifier can handle the specific document by calling its exposed test function. + * The manager will return the consolidated list of {@link VerificationFragment} + */ +var displayWarning = true; +var verificationBuilder = function (verifiers, builderOptions) { return function (document, promisesCallback) { + // if the user didn't configure an API key and didn't configure a provider or a resolver, then he will likely use a development key. We then warn him once, that he may need to configure things properly, especially for production + if (displayWarning && + (!builderOptions.resolver || !builderOptions.provider) && + !process.env.INFURA_API_KEY && + !process.env.PROVIDER_API_KEY) { + displayWarning = false; + console.warn(messages_1.warnProvider); + } + var verifierOptions = { + provider: utils_1.getProvider(builderOptions), + resolver: builderOptions.resolver, + }; + var promises = verifiers.map(function (verifier) { + if (verifier.test(document, verifierOptions)) { + return verifier.verify(document, verifierOptions); + } + return verifier.skip(document, verifierOptions); + }); + promisesCallback === null || promisesCallback === void 0 ? void 0 : promisesCallback(promises); + return Promise.all(promises); +}; }; +exports.verificationBuilder = verificationBuilder; diff --git a/dist/esm/common/error.js b/dist/esm/common/error.js new file mode 100644 index 00000000..10f86e14 --- /dev/null +++ b/dist/esm/common/error.js @@ -0,0 +1,26 @@ +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var CodedError = /** @class */ (function (_super) { + __extends(CodedError, _super); + function CodedError(message, code, codeString) { + var _this = _super.call(this, message) || this; + _this.code = code; + _this.codeString = codeString; + return _this; + } + return CodedError; +}(Error)); +export { CodedError }; diff --git a/dist/esm/common/errorHandler.js b/dist/esm/common/errorHandler.js new file mode 100644 index 00000000..affb5315 --- /dev/null +++ b/dist/esm/common/errorHandler.js @@ -0,0 +1,84 @@ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +export var withCodedErrorHandler = function (verify, errorOptions) { return function (document, options +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore https://github.com/microsoft/TypeScript/issues/26781 +) { return __awaiter(void 0, void 0, void 0, function () { + var e_1, message, code, codeString, name, type, unexpectedErrorCode, unexpectedErrorString; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + _a.trys.push([0, 2, , 3]); + return [4 /*yield*/, verify(document, options)]; + case 1: + // Using return await to ensure async function execute in try block + return [2 /*return*/, _a.sent()]; + case 2: + e_1 = _a.sent(); + message = e_1.message, code = e_1.code, codeString = e_1.codeString; + name = errorOptions.name, type = errorOptions.type, unexpectedErrorCode = errorOptions.unexpectedErrorCode, unexpectedErrorString = errorOptions.unexpectedErrorString; + if (message && code && codeString) { + return [2 /*return*/, { + name: name, + type: type, + data: e_1, + reason: { + message: message, + code: code, + codeString: codeString, + }, + status: "ERROR", + }]; + } + else { + return [2 /*return*/, { + name: name, + type: type, + data: e_1, + reason: { + message: e_1.message, + code: unexpectedErrorCode, + codeString: unexpectedErrorString, + }, + status: "ERROR", + }]; + } + return [3 /*break*/, 3]; + case 3: return [2 /*return*/]; + } + }); +}); }; }; diff --git a/dist/esm/common/logger.js b/dist/esm/common/logger.js new file mode 100644 index 00000000..7a5fbba6 --- /dev/null +++ b/dist/esm/common/logger.js @@ -0,0 +1,9 @@ +import debug from "debug"; +var logger = debug("oa-verify"); +export var getLogger = function (namespace) { return ({ + trace: logger.extend("trace:" + namespace), + debug: logger.extend("debug:" + namespace), + info: logger.extend("info:" + namespace), + warn: logger.extend("warn:" + namespace), + error: logger.extend("error:" + namespace), +}); }; diff --git a/dist/esm/common/messages.js b/dist/esm/common/messages.js new file mode 100644 index 00000000..603628c3 --- /dev/null +++ b/dist/esm/common/messages.js @@ -0,0 +1 @@ +export var warnProvider = "You are falling back to oa-verify default configuration, which is not suitable for production environment. It is highly recommended that you configure and provide your own API key. Refer to https://github.com/Open-Attestation/oa-verify#provider"; diff --git a/dist/esm/common/utils.js b/dist/esm/common/utils.js new file mode 100644 index 00000000..c410eb8b --- /dev/null +++ b/dist/esm/common/utils.js @@ -0,0 +1,162 @@ +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +import { providers } from "ethers"; +import { INFURA_API_KEY } from "../config"; +import { OpenAttestationEthereumDocumentStoreStatusCode, OpenAttestationEthereumTokenRegistryStatusCode, } from "../types/error"; +import { warnProvider } from "../common/messages"; +export var getDefaultProvider = function (options) { + var network = options.network || process.env.PROVIDER_NETWORK || "homestead"; + var providerType = process.env.PROVIDER_ENDPOINT_TYPE || "infura"; + var apiKey = process.env.PROVIDER_API_KEY || (providerType === "infura" && INFURA_API_KEY) || ""; + // create infura provider to get connection information + // we then use StaticJsonRpcProvider so that we can set our own custom limit + var uselessProvider = generateProvider({ + providerType: providerType, + network: network, + apiKey: apiKey, + }); + var connection = __assign(__assign({}, uselessProvider.connection), { throttleLimit: 3 }); + return new providers.StaticJsonRpcProvider(connection, network); +}; +// getProvider is a function to get an existing provider or to get a Default provider, when given the options +export var getProvider = function (options) { + var _a; + return (_a = options.provider) !== null && _a !== void 0 ? _a : getDefaultProvider(options); +}; +/** + * Generate Provider generates a provider based on the defined options or your env var, if no options or env var was detected, it will generate a provider based on the default values. + * Generate Provider using the following options: (if no option is specified it will use the default values) + * @param {Object} ProviderDetails - Details to use for the function to successfully generate a provider. + * @param {string} ProviderDetails.network - The network in which the provider is connected to, i.e. "homestead", "mainnet", "ropsten", "rinkeby" + * @param {string} ProviderDetails.providerType - Specify which provider to use: "infura", "alchemy" or "jsonrpc" + * @param {string} ProviderDetails.url - Specify which url for JsonRPC to connect to, if not specified will connect to localhost:8545 + * @param {string} ProviderDetails.apiKey - If no apiKey is provided, a default shared API key will be used, which may result in reduced performance and throttled requests. + */ +export var generateProvider = function (options) { + if (!!options && Object.keys(options).length === 1 && options.apiKey) { + throw new Error("We could not link the apiKey provided to a provider, please state the provider to use in the parameter."); + } + var network = (options === null || options === void 0 ? void 0 : options.network) || process.env.PROVIDER_NETWORK || "homestead"; + var provider = (options === null || options === void 0 ? void 0 : options.providerType) || process.env.PROVIDER_ENDPOINT_TYPE || "infura"; + var url = (options === null || options === void 0 ? void 0 : options.url) || process.env.PROVIDER_ENDPOINT_URL || ""; + var apiKey = (options === null || options === void 0 ? void 0 : options.apiKey) || (provider === "infura" && process.env.INFURA_API_KEY) || process.env.PROVIDER_API_KEY || ""; + !apiKey && console.warn(warnProvider); + if (!!options && Object.keys(options).length === 1 && url) { + return new providers.JsonRpcProvider(url); + } + switch (provider) { + case "infura": + return apiKey ? new providers.InfuraProvider(network, apiKey) : new providers.InfuraProvider(network); + case "alchemy": + return apiKey ? new providers.AlchemyProvider(network, apiKey) : new providers.AlchemyProvider(network); + case "jsonrpc": + return new providers.JsonRpcProvider(url); + default: + throw new Error("The provider provided is not on the list of providers. Please use one of the following: infura, alchemy or jsonrpc."); + } +}; +/** + * Simple typed utility to return a fragment depending on the name + * @param name + */ +export var getFragmentByName = function (name) { return function (fragments) { return fragments.find(function (fragment) { return fragment.name === name; }); }; }; +export var getOpenAttestationHashFragment = getFragmentByName("OpenAttestationHash"); +export var getOpenAttestationDidSignedDocumentStatusFragment = getFragmentByName("OpenAttestationDidSignedDocumentStatus"); +export var getOpenAttestationEthereumDocumentStoreStatusFragment = getFragmentByName("OpenAttestationEthereumDocumentStoreStatus"); +export var getOpenAttestationEthereumTokenRegistryStatusFragment = getFragmentByName("OpenAttestationEthereumTokenRegistryStatus"); +export var getOpenAttestationDidIdentityProofFragment = getFragmentByName("OpenAttestationDidIdentityProof"); +export var getOpenAttestationDnsDidIdentityProofFragment = getFragmentByName("OpenAttestationDnsDidIdentityProof"); +export var getOpenAttestationDnsTxtIdentityProofFragment = getFragmentByName("OpenAttestationDnsTxtIdentityProof"); +/** + * Simple typed utility to return fragments depending on the type + */ +var getFragmentByType = function (type) { return function (fragments) { return fragments.filter(function (fragment) { return fragment.type === type; }); }; }; +export var getDocumentIntegrityFragments = getFragmentByType("DOCUMENT_INTEGRITY"); +export var getDocumentStatusFragments = getFragmentByType("DOCUMENT_STATUS"); +export var getIssuerIdentityFragments = getFragmentByType("ISSUER_IDENTITY"); +export var isValidFragment = function (fragment) { + return (fragment === null || fragment === void 0 ? void 0 : fragment.status) === "VALID"; +}; +export var isInvalidFragment = function (fragment) { + return (fragment === null || fragment === void 0 ? void 0 : fragment.status) === "INVALID"; +}; +export var isSkippedFragment = function (fragment) { + return (fragment === null || fragment === void 0 ? void 0 : fragment.status) === "SKIPPED"; +}; +export var isErrorFragment = function (fragment) { + return (fragment === null || fragment === void 0 ? void 0 : fragment.status) === "ERROR"; +}; +// this function check if the reason of the error is that the document store or token registry is invalid +export var isDocumentStoreAddressOrTokenRegistryAddressInvalid = function (fragments) { + var _a, _b, _c, _d; + var documentStoreIssuedFragment = getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); + var tokenRegistryMintedFragment = getOpenAttestationEthereumTokenRegistryStatusFragment(fragments); + // 2 is the error code used by oa-verify in case of invalid address + return ((((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED && + ((_b = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _b === void 0 ? void 0 : _b.message.toLowerCase()) === "Invalid document store address".toLowerCase()) || + (((_c = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _c === void 0 ? void 0 : _c.code) === OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED && + ((_d = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _d === void 0 ? void 0 : _d.message.toLowerCase()) === "Invalid token registry address".toLowerCase())); +}; +// this function check if the reason of the error is contract not found in document store +export var contractNotFound = function (fragments) { + var _a, _b; + var documentStoreIssuedFragment = getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); + // 404 is the error code used by oa-verify in case of contract not found + return (((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED && + ((_b = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _b === void 0 ? void 0 : _b.message.toLowerCase()) === "Contract is not found".toLowerCase()); +}; +// this function check if the reason of the error is that the document is not issued in document store or token registry +export var certificateNotIssued = function (fragments) { + var _a, _b; + var documentStoreIssuedFragment = getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); + var tokenRegistryMintedFragment = getOpenAttestationEthereumTokenRegistryStatusFragment(fragments); + // 1 is the error code used by oa-verify in case of document / token not issued / minted + return (((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED || + ((_b = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _b === void 0 ? void 0 : _b.code) === OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED); +}; +// this function check if the reason of the error is that the document is revoked in document store +export var certificateRevoked = function (fragments) { + var _a; + var documentStoreIssuedFragment = getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); + // 1 is the error code used by oa-verify in case of document / token not issued / minted + return ((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED; +}; +// this function check if the error is caused by an invalid merkle root (incorrect length/odd length/invalid characters) +export var invalidArgument = function (fragments) { + var _a, _b, _c, _d; + var documentStoreIssuedFragment = getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); + var tokenRegistryMintedFragment = getOpenAttestationEthereumTokenRegistryStatusFragment(fragments); + // why INVALID_ARGUMENT is because we follow the error codes returned by Ethers (https://docs.ethers.io/v5/api/utils/logger/#errors) + return ((((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED && + ((_b = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _b === void 0 ? void 0 : _b.message.toLowerCase()) === "Invalid call arguments".toLowerCase()) || + (((_c = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _c === void 0 ? void 0 : _c.code) === OpenAttestationEthereumTokenRegistryStatusCode.INVALID_ARGUMENT && + ((_d = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _d === void 0 ? void 0 : _d.message.toLowerCase()) === "Invalid contract arguments".toLowerCase())); +}; +// this function check if the reason of the error is that we can't connect to Ethereum (due to any HTTP 4xx or 5xx errors) +export var serverError = function (fragments) { + var _a, _b; + var documentStoreIssuedFragment = getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); + var tokenRegistryMintedFragment = getOpenAttestationEthereumTokenRegistryStatusFragment(fragments); + // 429 is the error code used by oa-verify in case of Ethers returning a missing response error + return (((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === OpenAttestationEthereumDocumentStoreStatusCode.SERVER_ERROR || + ((_b = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _b === void 0 ? void 0 : _b.code) === OpenAttestationEthereumTokenRegistryStatusCode.SERVER_ERROR); +}; +// this function catches all other unhandled errors +export var unhandledError = function (fragments) { + var _a, _b; + var documentStoreIssuedFragment = getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); + var tokenRegistryMintedFragment = getOpenAttestationEthereumTokenRegistryStatusFragment(fragments); + // 3 is the error code used by oa-verify in case of weird errors that we didn't foresee to handle + return (((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === + OpenAttestationEthereumDocumentStoreStatusCode.ETHERS_UNHANDLED_ERROR || + ((_b = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _b === void 0 ? void 0 : _b.code) === OpenAttestationEthereumDocumentStoreStatusCode.ETHERS_UNHANDLED_ERROR); +}; diff --git a/dist/esm/config.js b/dist/esm/config.js new file mode 100644 index 00000000..9d6225a2 --- /dev/null +++ b/dist/esm/config.js @@ -0,0 +1 @@ +export var INFURA_API_KEY = process.env.INFURA_API_KEY || "bb46da3f80e040e8ab73c0a9ff365d18"; diff --git a/dist/esm/did/resolver.js b/dist/esm/did/resolver.js new file mode 100644 index 00000000..a3827756 --- /dev/null +++ b/dist/esm/did/resolver.js @@ -0,0 +1,112 @@ +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +import { Resolver } from "did-resolver"; +import { getResolver as ethrGetResolver } from "ethr-did-resolver"; +import { getResolver as webGetResolver } from "web-did-resolver"; +import NodeCache from "node-cache"; +import { INFURA_API_KEY } from "../config"; +import { generateProvider } from "../common/utils"; +export var getProviderConfig = function () { + var _a, _b, _c; + var provider = generateProvider(); + var rpcUrl = ((_a = provider === null || provider === void 0 ? void 0 : provider.connection) === null || _a === void 0 ? void 0 : _a.url) || ""; + var networkName = ((_b = provider === null || provider === void 0 ? void 0 : provider._network) === null || _b === void 0 ? void 0 : _b.name) === "homestead" ? "mainnet" : ((_c = provider === null || provider === void 0 ? void 0 : provider._network) === null || _c === void 0 ? void 0 : _c.name) || ""; + if (!rpcUrl || !networkName) { + return { networks: [{ name: "mainnet", rpcUrl: "https://mainnet.infura.io/v3/" + INFURA_API_KEY }] }; + } + return { + networks: [{ name: networkName, rpcUrl: rpcUrl }], + }; +}; +var didResolutionCache = new NodeCache({ stdTTL: 5 * 60 }); // 5 min +var defaultResolver = new Resolver(__assign(__assign({}, ethrGetResolver(getProviderConfig())), webGetResolver())); +export var createResolver = function (_a) { + var ethrResolverConfig = _a.ethrResolverConfig; + return ethrResolverConfig + ? new Resolver(__assign(__assign({}, ethrGetResolver(ethrResolverConfig)), webGetResolver())) + : defaultResolver; +}; +export var resolve = function (didUrl, resolver) { return __awaiter(void 0, void 0, void 0, function () { + var cachedResult, didResolutionResult, _a, did; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + cachedResult = didResolutionCache.get(didUrl); + if (cachedResult) + return [2 /*return*/, cachedResult]; + if (!resolver) return [3 /*break*/, 2]; + return [4 /*yield*/, resolver.resolve(didUrl)]; + case 1: + _a = _b.sent(); + return [3 /*break*/, 4]; + case 2: return [4 /*yield*/, defaultResolver.resolve(didUrl)]; + case 3: + _a = _b.sent(); + _b.label = 4; + case 4: + didResolutionResult = _a; + did = didResolutionResult.didDocument || undefined; + didResolutionCache.set(didUrl, did); + return [2 /*return*/, did]; + } + }); +}); }; +export var getVerificationMethod = function (did, key, resolver) { return __awaiter(void 0, void 0, void 0, function () { + var didDocument; + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: return [4 /*yield*/, resolve(did, resolver)]; + case 1: + didDocument = _b.sent(); + if (!didDocument) + return [2 /*return*/]; + return [2 /*return*/, (_a = didDocument.verificationMethod) === null || _a === void 0 ? void 0 : _a.find(function (k) { return k.id.toLowerCase() === key.toLowerCase(); })]; + } + }); +}); }; diff --git a/dist/esm/did/verifier.js b/dist/esm/did/verifier.js new file mode 100644 index 00000000..92f9f7a0 --- /dev/null +++ b/dist/esm/did/verifier.js @@ -0,0 +1,114 @@ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +import { utils } from "ethers"; +import { Literal, Record, String, Union, Array as RunTypesArray } from "runtypes"; +import { getVerificationMethod } from "./resolver"; +import { Reason, OpenAttestationSignatureCode } from "../types/error"; +import { CodedError } from "../common/error"; +export var ValidDidVerificationStatus = Record({ + verified: Literal(true), + did: String, +}); +export var ValidDidVerificationStatusArray = RunTypesArray(ValidDidVerificationStatus).withConstraint(function (elements) { return elements.length > 0 || "Expect at least one valid element"; }); +export var InvalidDidVerificationStatus = Record({ + verified: Literal(false), + did: String, + reason: Reason, +}); +export var DidVerificationStatus = Union(ValidDidVerificationStatus, InvalidDidVerificationStatus); +export var DidVerificationStatusArray = RunTypesArray(DidVerificationStatus); +export var verifySecp256k1VerificationKey2018 = function (_a) { + var did = _a.did, verificationMethod = _a.verificationMethod, merkleRoot = _a.merkleRoot, signature = _a.signature; + var messageBytes = utils.arrayify(merkleRoot); + var blockchainAccountId = verificationMethod.blockchainAccountId; + if (!blockchainAccountId) { + return { + did: did, + verified: false, + reason: { + code: OpenAttestationSignatureCode.KEY_MISSING, + codeString: OpenAttestationSignatureCode[OpenAttestationSignatureCode.KEY_MISSING], + message: "ethereumAddress not found on public key " + JSON.stringify(verificationMethod), + }, + }; + } + // blockchainAccountId looks like 0x0cE1854a3836daF9130028Cf90D6d35B1Ae46457@eip155:3, let's get rid of the part after @, @ included + var ethereumAddress = blockchainAccountId.split("@")[0]; + var merkleRootSigned = utils.verifyMessage(messageBytes, signature).toLowerCase() === ethereumAddress.toLowerCase(); + if (!merkleRootSigned) { + return { + did: did, + verified: false, + reason: { + code: OpenAttestationSignatureCode.WRONG_SIGNATURE, + codeString: OpenAttestationSignatureCode[OpenAttestationSignatureCode.WRONG_SIGNATURE], + message: "merkle root is not signed correctly by " + ethereumAddress, + }, + }; + } + return { + did: did, + verified: true, + }; +}; +export var verifySignature = function (_a) { + var key = _a.key, merkleRoot = _a.merkleRoot, signature = _a.signature, did = _a.did, resolver = _a.resolver; + return __awaiter(void 0, void 0, void 0, function () { + var verificationMethod; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: return [4 /*yield*/, getVerificationMethod(did, key, resolver)]; + case 1: + verificationMethod = _b.sent(); + if (!verificationMethod) + throw new CodedError("No public key found on DID document for the DID " + did + " and key " + key, OpenAttestationSignatureCode.KEY_NOT_IN_DID, "KEY_NOT_IN_DID"); + switch (verificationMethod.type) { + case "EcdsaSecp256k1RecoveryMethod2020": + return [2 /*return*/, verifySecp256k1VerificationKey2018({ + did: did, + verificationMethod: verificationMethod, + merkleRoot: merkleRoot, + signature: signature, + })]; + default: + throw new CodedError("Signature type " + verificationMethod.type + " is currently not support", OpenAttestationSignatureCode.UNSUPPORTED_KEY_TYPE, "UNSUPPORTED_KEY_TYPE"); + } + return [2 /*return*/]; + } + }); + }); +}; diff --git a/dist/esm/getIdentifier.js b/dist/esm/getIdentifier.js new file mode 100644 index 00000000..e9855f53 --- /dev/null +++ b/dist/esm/getIdentifier.js @@ -0,0 +1,89 @@ +import { isVerificationFragmentWithData } from "./types/core"; +import { DidVerificationStatus, DidVerificationStatusArray } from "./did/verifier"; +import { DnsDidVerificationStatus, DnsDidVerificationStatusArray, } from "./verifiers/issuerIdentity/dnsDid/dnsDidProof.type"; +import { DnsTxtVerificationStatusArray, DnsTxtVerificationStatusDataV3, } from "./verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type"; +var IdentityProof; +(function (IdentityProof) { + IdentityProof["DNS"] = "OpenAttestationDnsTxtIdentityProof"; + IdentityProof["DNSDID"] = "OpenAttestationDnsDidIdentityProof"; + IdentityProof["DID"] = "OpenAttestationDidIdentityProof"; +})(IdentityProof || (IdentityProof = {})); +var getDnsIdentifierProof = function (_a) { + var data = _a.data; + var type = "DNS"; + if (DnsTxtVerificationStatusDataV3.guard(data)) { + return { + identifier: data.identifier, + type: type, + }; + } + else if (DnsTxtVerificationStatusArray.guard(data)) { + return data.map(function (issuer) { return ({ + identifier: issuer.location, + type: type, + }); }); + } + throw new Error("Fragment for DNS not supported"); +}; +var getDnsDidIdentifierProof = function (_a) { + var data = _a.data; + var type = "DNS-DID"; + if (DnsDidVerificationStatusArray.guard(data)) { + return data.map(function (issuer) { return ({ + identifier: issuer.location, + type: type, + }); }); + } + else if (DnsDidVerificationStatus.guard(data)) { + return { + identifier: data.location, + type: type, + }; + } + throw new Error("Fragment for DNS-DID not supported"); +}; +var getDidIdentifierProof = function (_a) { + var data = _a.data; + var type = "DID"; + if (DidVerificationStatusArray.guard(data)) { + return data.map(function (issuer) { return ({ + identifier: issuer.did, + type: type, + }); }); + } + else if (DidVerificationStatus.guard(data)) { + return { + identifier: data.did, + type: type, + }; + } + throw new Error("Fragment for DID not supported"); +}; +var getIdentityProofFragment = function (fragments) { + if (fragments.length < 1) { + throw new Error("Please provide at least one verification fragment"); + } + return fragments.find(function (status) { return status.type === "ISSUER_IDENTITY" && status.status === "VALID"; }); +}; +export var getIdentifier = function (fragments) { + var fragment = getIdentityProofFragment(fragments); + if (!fragment) { + throw new Error("Did not find any Issuer Identity fragment that is valid"); + } + if (!isVerificationFragmentWithData(fragment)) { + throw new Error("No data property found in fragment, malformed fragment"); + } + switch (fragment.name) { + case IdentityProof.DNS: + return getDnsIdentifierProof(fragment); + case IdentityProof.DNSDID: + return getDnsDidIdentifierProof(fragment); + case IdentityProof.DID: + return getDidIdentifierProof(fragment); + default: + return { + identifier: "Unknown", + type: "Unknown", + }; + } +}; diff --git a/dist/esm/index.js b/dist/esm/index.js new file mode 100644 index 00000000..0c0da17c --- /dev/null +++ b/dist/esm/index.js @@ -0,0 +1,38 @@ +import { verificationBuilder } from "./verifiers/verificationBuilder"; +import { openAttestationHash } from "./verifiers/documentIntegrity/hash/openAttestationHash"; +import { isValid } from "./validator"; +import { openAttestationEthereumTokenRegistryStatus } from "./verifiers/documentStatus/tokenRegistry"; +import { openAttestationEthereumDocumentStoreStatus } from "./verifiers/documentStatus/documentStore"; +import { openAttestationDidSignedDocumentStatus } from "./verifiers/documentStatus/didSigned"; +import { openAttestationDnsTxtIdentityProof } from "./verifiers/issuerIdentity/dnsTxt"; +import { openAttestationDidIdentityProof } from "./verifiers/issuerIdentity/did"; +import { openAttestationDnsDidIdentityProof } from "./verifiers/issuerIdentity/dnsDid"; +import { createResolver } from "./did/resolver"; +import { getIdentifier } from "./getIdentifier"; +import * as utils from "./common/utils"; +import util from "util"; +// eslint-disable-next-line @typescript-eslint/no-empty-function +util.deprecate(function infuraApiKey() { }, "'INFURA_API_KEY' has been deprecated, please use 'PROVIDER_API_KEY'."); +var openAttestationVerifiers = [ + openAttestationHash, + openAttestationEthereumTokenRegistryStatus, + openAttestationEthereumDocumentStoreStatus, + openAttestationDidSignedDocumentStatus, + openAttestationDnsTxtIdentityProof, + openAttestationDnsDidIdentityProof, +]; +var defaultBuilderOption = { + network: process.env.PROVIDER_NETWORK || "homestead", +}; +var verify = verificationBuilder(openAttestationVerifiers, defaultBuilderOption); +export * from "./types/core"; +export * from "./verifiers/documentIntegrity/hash/openAttestationHash.type"; +export * from "./verifiers/documentStatus/didSigned/didSignedDocumentStatus.type"; +export * from "./verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type"; +export * from "./verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type"; +export * from "./verifiers/issuerIdentity/did/didIdentityProof.type"; +export * from "./verifiers/issuerIdentity/dnsDid/dnsDidProof.type"; +export * from "./verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type"; +export * from "./types/error"; +export * from "./common/error"; +export { verificationBuilder, openAttestationVerifiers, isValid, verify, openAttestationHash, openAttestationEthereumDocumentStoreStatus, openAttestationEthereumTokenRegistryStatus, openAttestationDidSignedDocumentStatus, openAttestationDnsTxtIdentityProof, openAttestationDnsDidIdentityProof, openAttestationDidIdentityProof, createResolver, getIdentifier, utils, }; diff --git a/dist/esm/types/core.js b/dist/esm/types/core.js new file mode 100644 index 00000000..a6c0fc58 --- /dev/null +++ b/dist/esm/types/core.js @@ -0,0 +1,3 @@ +export var isVerificationFragmentWithData = function (fragment) { + return fragment.data; +}; diff --git a/dist/esm/types/error.js b/dist/esm/types/error.js new file mode 100644 index 00000000..2af0947e --- /dev/null +++ b/dist/esm/types/error.js @@ -0,0 +1,104 @@ +// NEVER EVER REPLACE OR CHANGE A VALUE :) +// code for errors and invalid fragment +import { Number, Record, String } from "runtypes"; +export var OpenAttestationEthereumDocumentStoreStatusCode; +(function (OpenAttestationEthereumDocumentStoreStatusCode) { + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["UNEXPECTED_ERROR"] = 0] = "UNEXPECTED_ERROR"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["DOCUMENT_NOT_ISSUED"] = 1] = "DOCUMENT_NOT_ISSUED"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["CONTRACT_ADDRESS_INVALID"] = 2] = "CONTRACT_ADDRESS_INVALID"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["ETHERS_UNHANDLED_ERROR"] = 3] = "ETHERS_UNHANDLED_ERROR"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["SKIPPED"] = 4] = "SKIPPED"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["DOCUMENT_REVOKED"] = 5] = "DOCUMENT_REVOKED"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["INVALID_ARGUMENT"] = 6] = "INVALID_ARGUMENT"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["CONTRACT_NOT_FOUND"] = 404] = "CONTRACT_NOT_FOUND"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["INVALID_ISSUERS"] = 7] = "INVALID_ISSUERS"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["INVALID_VALIDATION_METHOD"] = 8] = "INVALID_VALIDATION_METHOD"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["UNRECOGNIZED_DOCUMENT"] = 9] = "UNRECOGNIZED_DOCUMENT"; + OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["SERVER_ERROR"] = 500] = "SERVER_ERROR"; +})(OpenAttestationEthereumDocumentStoreStatusCode || (OpenAttestationEthereumDocumentStoreStatusCode = {})); +export var OpenAttestationDocumentSignedCode; +(function (OpenAttestationDocumentSignedCode) { + OpenAttestationDocumentSignedCode[OpenAttestationDocumentSignedCode["UNEXPECTED_ERROR"] = 0] = "UNEXPECTED_ERROR"; + OpenAttestationDocumentSignedCode[OpenAttestationDocumentSignedCode["DOCUMENT_PROOF_INVALID"] = 1] = "DOCUMENT_PROOF_INVALID"; + OpenAttestationDocumentSignedCode[OpenAttestationDocumentSignedCode["DOCUMENT_PROOF_ERROR"] = 2] = "DOCUMENT_PROOF_ERROR"; + OpenAttestationDocumentSignedCode[OpenAttestationDocumentSignedCode["SKIPPED"] = 4] = "SKIPPED"; +})(OpenAttestationDocumentSignedCode || (OpenAttestationDocumentSignedCode = {})); +export var OpenAttestationEthereumTokenRegistryStatusCode; +(function (OpenAttestationEthereumTokenRegistryStatusCode) { + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["UNEXPECTED_ERROR"] = 0] = "UNEXPECTED_ERROR"; + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["DOCUMENT_NOT_MINTED"] = 1] = "DOCUMENT_NOT_MINTED"; + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["CONTRACT_ADDRESS_INVALID"] = 2] = "CONTRACT_ADDRESS_INVALID"; + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["ETHERS_UNHANDLED_ERROR"] = 3] = "ETHERS_UNHANDLED_ERROR"; + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["SKIPPED"] = 4] = "SKIPPED"; + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["INVALID_ISSUERS"] = 5] = "INVALID_ISSUERS"; + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["INVALID_ARGUMENT"] = 6] = "INVALID_ARGUMENT"; + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["UNDEFINED_TOKEN_REGISTRY"] = 7] = "UNDEFINED_TOKEN_REGISTRY"; + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["INVALID_VALIDATION_METHOD"] = 8] = "INVALID_VALIDATION_METHOD"; + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["UNRECOGNIZED_DOCUMENT"] = 9] = "UNRECOGNIZED_DOCUMENT"; + OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["SERVER_ERROR"] = 500] = "SERVER_ERROR"; +})(OpenAttestationEthereumTokenRegistryStatusCode || (OpenAttestationEthereumTokenRegistryStatusCode = {})); +export var OpenAttestationDnsTxtCode; +(function (OpenAttestationDnsTxtCode) { + OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["UNEXPECTED_ERROR"] = 0] = "UNEXPECTED_ERROR"; + OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["INVALID_IDENTITY"] = 1] = "INVALID_IDENTITY"; + OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["SKIPPED"] = 2] = "SKIPPED"; + OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["INVALID_ISSUERS"] = 3] = "INVALID_ISSUERS"; + OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["MATCHING_RECORD_NOT_FOUND"] = 4] = "MATCHING_RECORD_NOT_FOUND"; + OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["UNRECOGNIZED_DOCUMENT"] = 5] = "UNRECOGNIZED_DOCUMENT"; + OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["UNSUPPORTED"] = 6] = "UNSUPPORTED"; +})(OpenAttestationDnsTxtCode || (OpenAttestationDnsTxtCode = {})); +export var OpenAttestationHashCode; +(function (OpenAttestationHashCode) { + OpenAttestationHashCode[OpenAttestationHashCode["DOCUMENT_TAMPERED"] = 0] = "DOCUMENT_TAMPERED"; + OpenAttestationHashCode[OpenAttestationHashCode["UNEXPECTED_ERROR"] = 1] = "UNEXPECTED_ERROR"; + OpenAttestationHashCode[OpenAttestationHashCode["SKIPPED"] = 2] = "SKIPPED"; +})(OpenAttestationHashCode || (OpenAttestationHashCode = {})); +export var OpenAttestationDidSignedDocumentStatusCode; +(function (OpenAttestationDidSignedDocumentStatusCode) { + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["SKIPPED"] = 0] = "SKIPPED"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["UNEXPECTED_ERROR"] = 1] = "UNEXPECTED_ERROR"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["MISSING_REVOCATION"] = 2] = "MISSING_REVOCATION"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["UNSIGNED"] = 3] = "UNSIGNED"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["INVALID_ISSUERS"] = 4] = "INVALID_ISSUERS"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["MALFORMED_IDENTITY_PROOF"] = 5] = "MALFORMED_IDENTITY_PROOF"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["CORRESPONDING_PROOF_MISSING"] = 6] = "CORRESPONDING_PROOF_MISSING"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["DID_MISSING"] = 7] = "DID_MISSING"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["UNRECOGNIZED_DOCUMENT"] = 8] = "UNRECOGNIZED_DOCUMENT"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["UNRECOGNIZED_REVOCATION_TYPE"] = 9] = "UNRECOGNIZED_REVOCATION_TYPE"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["REVOCATION_LOCATION_MISSING"] = 10] = "REVOCATION_LOCATION_MISSING"; + OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["OCSP_RESPONSE_INVALID"] = 11] = "OCSP_RESPONSE_INVALID"; +})(OpenAttestationDidSignedDocumentStatusCode || (OpenAttestationDidSignedDocumentStatusCode = {})); +export var OpenAttestationDidCode; +(function (OpenAttestationDidCode) { + OpenAttestationDidCode[OpenAttestationDidCode["SKIPPED"] = 0] = "SKIPPED"; + OpenAttestationDidCode[OpenAttestationDidCode["UNEXPECTED_ERROR"] = 1] = "UNEXPECTED_ERROR"; + OpenAttestationDidCode[OpenAttestationDidCode["INVALID_ISSUERS"] = 2] = "INVALID_ISSUERS"; + OpenAttestationDidCode[OpenAttestationDidCode["MALFORMED_IDENTITY_PROOF"] = 3] = "MALFORMED_IDENTITY_PROOF"; + OpenAttestationDidCode[OpenAttestationDidCode["DID_MISSING"] = 4] = "DID_MISSING"; + OpenAttestationDidCode[OpenAttestationDidCode["UNSIGNED"] = 5] = "UNSIGNED"; + OpenAttestationDidCode[OpenAttestationDidCode["UNRECOGNIZED_DOCUMENT"] = 6] = "UNRECOGNIZED_DOCUMENT"; +})(OpenAttestationDidCode || (OpenAttestationDidCode = {})); +export var OpenAttestationDnsDidCode; +(function (OpenAttestationDnsDidCode) { + OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["SKIPPED"] = 0] = "SKIPPED"; + OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["UNEXPECTED_ERROR"] = 1] = "UNEXPECTED_ERROR"; + OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["MALFORMED_IDENTITY_PROOF"] = 2] = "MALFORMED_IDENTITY_PROOF"; + OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["INVALID_ISSUERS"] = 3] = "INVALID_ISSUERS"; + OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["UNSIGNED"] = 4] = "UNSIGNED"; + OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["UNRECOGNIZED_DOCUMENT"] = 5] = "UNRECOGNIZED_DOCUMENT"; + OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["INVALID_IDENTITY"] = 6] = "INVALID_IDENTITY"; +})(OpenAttestationDnsDidCode || (OpenAttestationDnsDidCode = {})); +export var OpenAttestationSignatureCode; +(function (OpenAttestationSignatureCode) { + OpenAttestationSignatureCode[OpenAttestationSignatureCode["UNEXPECTED_ERROR"] = 0] = "UNEXPECTED_ERROR"; + OpenAttestationSignatureCode[OpenAttestationSignatureCode["KEY_MISSING"] = 1] = "KEY_MISSING"; + OpenAttestationSignatureCode[OpenAttestationSignatureCode["DID_MISSING"] = 3] = "DID_MISSING"; + OpenAttestationSignatureCode[OpenAttestationSignatureCode["KEY_NOT_IN_DID"] = 4] = "KEY_NOT_IN_DID"; + OpenAttestationSignatureCode[OpenAttestationSignatureCode["UNSUPPORTED_KEY_TYPE"] = 6] = "UNSUPPORTED_KEY_TYPE"; + OpenAttestationSignatureCode[OpenAttestationSignatureCode["WRONG_SIGNATURE"] = 7] = "WRONG_SIGNATURE"; +})(OpenAttestationSignatureCode || (OpenAttestationSignatureCode = {})); +export var Reason = Record({ + code: Number, + codeString: String, + message: String, +}); diff --git a/dist/esm/validator.js b/dist/esm/validator.js new file mode 100644 index 00000000..e17e8a30 --- /dev/null +++ b/dist/esm/validator.js @@ -0,0 +1,16 @@ +export var isValid = function (verificationFragments, types) { + if (types === void 0) { types = ["DOCUMENT_STATUS", "DOCUMENT_INTEGRITY", "ISSUER_IDENTITY"]; } + if (verificationFragments.length < 1) { + throw new Error("Please provide at least one verification fragment to check"); + } + if (types.length < 1) { + throw new Error("Please provide at least one type to check"); + } + return types.every(function (type) { + var verificationFragmentsForType = verificationFragments.filter(function (fragment) { return fragment.type === type; }); + // return true if at least one fragment is valid + // and all fragments are valid or skipped + return (verificationFragmentsForType.some(function (fragment) { return fragment.status === "VALID"; }) && + verificationFragmentsForType.every(function (fragment) { return fragment.status === "VALID" || fragment.status === "SKIPPED"; })); + }); +}; diff --git a/dist/esm/verifiers/documentIntegrity/hash/openAttestationHash.js b/dist/esm/verifiers/documentIntegrity/hash/openAttestationHash.js new file mode 100644 index 00000000..4c37a93d --- /dev/null +++ b/dist/esm/verifiers/documentIntegrity/hash/openAttestationHash.js @@ -0,0 +1,95 @@ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +import { utils, verifySignature } from "@govtechsg/open-attestation"; +import { OpenAttestationHashCode } from "../../../types/error"; +import { withCodedErrorHandler } from "../../../common/errorHandler"; +var name = "OpenAttestationHash"; +var type = "DOCUMENT_INTEGRITY"; +var skip = function () { + return Promise.resolve({ + status: "SKIPPED", + type: type, + name: name, + reason: { + code: OpenAttestationHashCode.SKIPPED, + codeString: OpenAttestationHashCode[OpenAttestationHashCode.SKIPPED], + message: "Document does not have merkle root, target hash or data.", + }, + }); +}; +var test = function (document) { + return utils.isWrappedV3Document(document) || utils.isWrappedV2Document(document); +}; +var verify = function (document) { return __awaiter(void 0, void 0, void 0, function () { + var hash; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, verifySignature(document)]; + case 1: + hash = _a.sent(); + if (!hash) { + return [2 /*return*/, { + type: type, + name: name, + data: hash, + reason: { + code: OpenAttestationHashCode.DOCUMENT_TAMPERED, + codeString: OpenAttestationHashCode[OpenAttestationHashCode.DOCUMENT_TAMPERED], + message: "Document has been tampered with", + }, + status: "INVALID", + }]; + } + return [2 /*return*/, { + type: type, + name: name, + data: hash, + status: "VALID", + }]; + } + }); +}); }; +export var openAttestationHash = { + skip: skip, + test: test, + verify: withCodedErrorHandler(verify, { + name: name, + type: type, + unexpectedErrorCode: OpenAttestationHashCode.UNEXPECTED_ERROR, + unexpectedErrorString: OpenAttestationHashCode[OpenAttestationHashCode.UNEXPECTED_ERROR], + }), +}; diff --git a/dist/esm/verifiers/documentIntegrity/hash/openAttestationHash.type.js b/dist/esm/verifiers/documentIntegrity/hash/openAttestationHash.type.js new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/esm/verifiers/documentIntegrity/hash/openAttestationHash.type.js @@ -0,0 +1 @@ +export {}; diff --git a/dist/esm/verifiers/documentStatus/didSigned/didSignedDocumentStatus.js b/dist/esm/verifiers/documentStatus/didSigned/didSignedDocumentStatus.js new file mode 100644 index 00000000..0449b3b2 --- /dev/null +++ b/dist/esm/verifiers/documentStatus/didSigned/didSignedDocumentStatus.js @@ -0,0 +1,306 @@ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +import { getData, utils, v2, v3 } from "@govtechsg/open-attestation"; +import { OpenAttestationDidSignedDocumentStatusCode } from "../../../types/error"; +import { ValidDidVerificationStatus, verifySignature } from "../../../did/verifier"; +import { CodedError } from "../../../common/error"; +import { withCodedErrorHandler } from "../../../common/errorHandler"; +import { isRevokedByOcspResponder, isRevokedOnDocumentStore } from "../utils"; +import { InvalidRevocationStatus, ValidRevocationStatus } from "../revocation.types"; +import { InvalidDidSignedIssuanceStatus, ValidDidSignedDataV2, ValidDidSignedIssuanceStatus, } from "./didSignedDocumentStatus.type"; +var name = "OpenAttestationDidSignedDocumentStatus"; +var type = "DOCUMENT_STATUS"; +var skip = function () { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, { + status: "SKIPPED", + type: type, + name: name, + reason: { + code: OpenAttestationDidSignedDocumentStatusCode.SKIPPED, + codeString: OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode.SKIPPED], + message: "Document was not signed by DID directly", + }, + }]; + }); +}); }; +var test = function (document) { + if (utils.isSignedWrappedV2Document(document)) { + return document.proof.some(function (proof) { return proof.type === "OpenAttestationSignature2018"; }); + } + else if (utils.isSignedWrappedV3Document(document)) { + return document.proof.type === "OpenAttestationMerkleProofSignature2018"; + } + return false; +}; +var transformToDidSignedIssuanceStatus = function (status) { + return ValidDidVerificationStatus.guard(status) + ? { + issued: true, + did: status.did, + } + : { + issued: false, + did: status.did, + reason: status.reason, + }; +}; +var verifyV2 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + var documentData, merkleRoot, _a, targetHash, proofs, issuers, revocation, revocationStatusCallback, revocationStatuses, signatureVerificationDeferred, issuance, notIssued, revoked, data, reason; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + documentData = getData(document); + merkleRoot = "0x" + document.signature.merkleRoot; + _a = document.signature, targetHash = _a.targetHash, proofs = _a.proof; + documentData.issuers.forEach(function (issuer) { + var _a, _b; + if (!(((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === "DID" || ((_b = issuer.identityProof) === null || _b === void 0 ? void 0 : _b.type) === "DNS-DID")) + throw new CodedError("All issuers must use DID or DNS-DID identityProof type.", OpenAttestationDidSignedDocumentStatusCode.INVALID_ISSUERS, OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode.INVALID_ISSUERS]); + }); + issuers = documentData.issuers; + revocation = issuers.map(function (issuer) { return issuer.revocation; }); + if (revocation.some(function (r) { return typeof (r === null || r === void 0 ? void 0 : r.type) === "undefined"; })) + throw new CodedError("revocation block not found for an issuer", OpenAttestationDidSignedDocumentStatusCode.MISSING_REVOCATION, "MISSING_REVOCATION"); + revocationStatusCallback = function (revocationItem) { + switch (revocationItem.type) { + case v2.RevocationType.RevocationStore: + if (typeof revocationItem.location === "string") { + return isRevokedOnDocumentStore({ + documentStore: revocationItem.location, + merkleRoot: merkleRoot, + provider: options.provider, + targetHash: targetHash, + proofs: proofs, + }); + } + throw new CodedError("missing revocation location for an issuer", OpenAttestationDidSignedDocumentStatusCode.REVOCATION_LOCATION_MISSING, "REVOCATION_LOCATION_MISSING"); + case v2.RevocationType.OcspResponder: + if (typeof revocationItem.location === "string") { + return isRevokedByOcspResponder({ + certificateId: documentData.id, + location: revocationItem.location, + }); + } + throw new CodedError("missing revocation location for an issuer", OpenAttestationDidSignedDocumentStatusCode.REVOCATION_LOCATION_MISSING, "REVOCATION_LOCATION_MISSING"); + case v2.RevocationType.None: + return Promise.resolve({ revoked: false }); + default: + throw new CodedError("unrecognized revocation type for an issuer", OpenAttestationDidSignedDocumentStatusCode.UNRECOGNIZED_REVOCATION_TYPE, "UNRECOGNIZED_REVOCATION_TYPE"); + } + }; + return [4 /*yield*/, Promise.all(revocation.map(revocationStatusCallback))]; + case 1: + revocationStatuses = _b.sent(); + // Check that all the issuers have signed on the document + if (!document.proof) + throw new CodedError("Document is not signed. Proofs are missing.", OpenAttestationDidSignedDocumentStatusCode.UNSIGNED, "UNSIGNED"); + signatureVerificationDeferred = issuers.map(function (issuer) { return __awaiter(void 0, void 0, void 0, function () { + var key, did, correspondingProof; + var _a; + return __generator(this, function (_b) { + key = (_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.key; + did = issuer.id; + if (!did) + throw new CodedError("id is missing in issuer", OpenAttestationDidSignedDocumentStatusCode.DID_MISSING, "DID_MISSING"); + if (!key) + throw new CodedError("Key is not present", OpenAttestationDidSignedDocumentStatusCode.MALFORMED_IDENTITY_PROOF, "MALFORMED_IDENTITY_PROOF"); + correspondingProof = document.proof.find(function (p) { return p.verificationMethod.toLowerCase() === key.toLowerCase(); }); + if (!correspondingProof) + throw new CodedError("Proof not found for " + key, OpenAttestationDidSignedDocumentStatusCode.CORRESPONDING_PROOF_MISSING, "CORRESPONDING_PROOF_MISSING"); + return [2 /*return*/, verifySignature({ + merkleRoot: merkleRoot, + key: key, + signature: correspondingProof.signature, + did: did, + resolver: options.resolver, + })]; + }); + }); }); + return [4 /*yield*/, Promise.all(signatureVerificationDeferred)]; + case 2: return [4 /*yield*/, (_b.sent()).map(transformToDidSignedIssuanceStatus)]; + case 3: + issuance = _b.sent(); + notIssued = issuance.find(InvalidDidSignedIssuanceStatus.guard); + revoked = revocationStatuses.find(InvalidRevocationStatus.guard); + data = { + issuedOnAll: !notIssued, + revokedOnAny: !!revoked, + details: { + issuance: issuance, + revocation: revocationStatuses, + }, + }; + if (ValidDidSignedDataV2.guard(data)) { + return [2 /*return*/, { + name: name, + type: type, + data: data, + status: "VALID", + }]; + } + if (InvalidDidSignedIssuanceStatus.guard(notIssued)) { + reason = notIssued.reason; + } + else if (InvalidRevocationStatus.guard(revoked)) { + reason = revoked.reason; + } + if (!reason) { + throw new CodedError("Unable to retrieve the reason of the failure", OpenAttestationDidSignedDocumentStatusCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); + } + return [2 /*return*/, { + name: name, + type: type, + data: data, + status: "INVALID", + reason: reason, + }]; + } + }); +}); }; +var verifyV3 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + var _a, merkleRootRaw, targetHash, proofs, merkleRoot, metaData, verificationResult, _b, issuedOnAll, getRevocationStatus, revocationStatus, revokedOnAny, reason; + var _c; + return __generator(this, function (_d) { + switch (_d.label) { + case 0: + _a = document.proof, merkleRootRaw = _a.merkleRoot, targetHash = _a.targetHash, proofs = _a.proofs; + merkleRoot = "0x" + merkleRootRaw; + metaData = document.openAttestationMetadata; + _b = transformToDidSignedIssuanceStatus; + return [4 /*yield*/, verifySignature({ + key: document.proof.key, + did: metaData.proof.value, + merkleRoot: merkleRoot, + signature: document.proof.signature, + resolver: options.resolver, + })]; + case 1: + verificationResult = _b.apply(void 0, [_d.sent()]); + if (!((_c = metaData.proof.revocation) === null || _c === void 0 ? void 0 : _c.type)) { + throw new CodedError("revocation block not found for an issuer", OpenAttestationDidSignedDocumentStatusCode.MISSING_REVOCATION, "MISSING_REVOCATION"); + } + issuedOnAll = verificationResult.issued; + getRevocationStatus = function (docType, location) { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (docType) { + case v3.RevocationType.RevocationStore: + if (typeof location === "string") { + return [2 /*return*/, isRevokedOnDocumentStore({ + documentStore: location, + merkleRoot: merkleRoot, + targetHash: targetHash, + proofs: proofs, + provider: options.provider, + })]; + } + throw new CodedError("missing revocation location for an issuer", OpenAttestationDidSignedDocumentStatusCode.REVOCATION_LOCATION_MISSING, "REVOCATION_LOCATION_MISSING"); + case v3.RevocationType.OcspResponder: + throw new Error("Ocsp revocation type not yet supported for v3"); + case v3.RevocationType.None: + return [2 /*return*/, { revoked: false }]; + default: + throw new CodedError("revocation type not found for an issuer", OpenAttestationDidSignedDocumentStatusCode.UNRECOGNIZED_REVOCATION_TYPE, "UNRECOGNIZED_REVOCATION_TYPE"); + } + return [2 /*return*/]; + }); + }); }; + return [4 /*yield*/, getRevocationStatus(metaData.proof.revocation.type, metaData.proof.revocation.location)]; + case 2: + revocationStatus = _d.sent(); + revokedOnAny = revocationStatus.revoked; + if (ValidDidSignedIssuanceStatus.guard(verificationResult) && ValidRevocationStatus.guard(revocationStatus)) { + return [2 /*return*/, { + name: name, + type: type, + data: { + issuedOnAll: true, + revokedOnAny: false, + details: { + issuance: verificationResult, + revocation: revocationStatus, + }, + }, + status: "VALID", + }]; + } + reason = InvalidDidSignedIssuanceStatus.guard(verificationResult) + ? verificationResult.reason + : InvalidRevocationStatus.guard(revocationStatus) + ? revocationStatus.reason + : undefined; + if (!reason) { + throw new CodedError("Unable to retrieve the reason of the failure", OpenAttestationDidSignedDocumentStatusCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); + } + return [2 /*return*/, { + name: name, + type: type, + data: { + issuedOnAll: issuedOnAll, + revokedOnAny: revokedOnAny, + details: { + issuance: verificationResult, + revocation: revocationStatus, + }, + }, + status: "INVALID", + reason: reason, + }]; + } + }); +}); }; +var verify = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + if (utils.isSignedWrappedV2Document(document)) { + return [2 /*return*/, verifyV2(document, options)]; + } + else if (utils.isSignedWrappedV3Document(document)) { + return [2 /*return*/, verifyV3(document, options)]; + } + throw new CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", OpenAttestationDidSignedDocumentStatusCode.UNRECOGNIZED_DOCUMENT, OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode.UNRECOGNIZED_DOCUMENT]); + }); +}); }; +export var openAttestationDidSignedDocumentStatus = { + skip: skip, + test: test, + verify: withCodedErrorHandler(verify, { + name: name, + type: type, + unexpectedErrorCode: OpenAttestationDidSignedDocumentStatusCode.UNEXPECTED_ERROR, + unexpectedErrorString: OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode.UNEXPECTED_ERROR], + }), +}; diff --git a/dist/esm/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.js b/dist/esm/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.js new file mode 100644 index 00000000..ac9e08b3 --- /dev/null +++ b/dist/esm/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.js @@ -0,0 +1,67 @@ +import { Array as RunTypesArray, Boolean, Literal, Record, String, Union, Number } from "runtypes"; +import { Reason } from "../../../types/error"; +import { RevocationStatus, RevocationStatusArray, ValidRevocationStatus, ValidRevocationStatusArray, OcspResponderRevocationStatus, } from "../revocation.types"; +/** + * DID signed issuance status + */ +export var ValidDidSignedIssuanceStatus = Record({ + did: String, + issued: Literal(true), +}); +export var ValidDidSignedIssuanceStatusArray = RunTypesArray(ValidDidSignedIssuanceStatus); +export var InvalidDidSignedIssuanceStatus = Record({ + did: String, + issued: Literal(false), + reason: Reason, +}); +export var DidSignedIssuanceStatus = Union(ValidDidSignedIssuanceStatus, InvalidDidSignedIssuanceStatus); +export var DidSignedIssuanceStatusArray = RunTypesArray(DidSignedIssuanceStatus); +/** + * OCSP response + */ +export var ValidOcspReasonCode = Number.withConstraint(function (n) { return n >= 0 && n <= 10 && n != 7; }); +export var ValidOcspResponse = Record({ + certificateStatus: OcspResponderRevocationStatus, +}); +export var ValidOcspResponseRevoked = Record({ + reasonCode: ValidOcspReasonCode, + certificateStatus: OcspResponderRevocationStatus, +}); +/** + * Data for v2 Fragments + */ +export var ValidDidSignedDataV2 = Record({ + issuedOnAll: Literal(true), + revokedOnAny: Literal(false), + details: Record({ + issuance: ValidDidSignedIssuanceStatusArray, + revocation: ValidRevocationStatusArray, + }), +}); +export var InvalidDidSignedDataV2 = Record({ + issuedOnAll: Boolean, + revokedOnAny: Boolean, + details: Record({ + issuance: DidSignedIssuanceStatusArray, + revocation: RevocationStatusArray, + }), +}); +/** + * Data for v3 Fragments + */ +export var ValidDidSignedDataV3 = Record({ + issuedOnAll: Literal(true), + revokedOnAny: Literal(false), + details: Record({ + issuance: ValidDidSignedIssuanceStatus, + revocation: ValidRevocationStatus, + }), +}); +export var InvalidDidSignedDataV3 = Record({ + issuedOnAll: Boolean, + revokedOnAny: Boolean, + details: Record({ + issuance: DidSignedIssuanceStatus, + revocation: RevocationStatus, + }), +}); diff --git a/dist/esm/verifiers/documentStatus/didSigned/index.js b/dist/esm/verifiers/documentStatus/didSigned/index.js new file mode 100644 index 00000000..1c14b400 --- /dev/null +++ b/dist/esm/verifiers/documentStatus/didSigned/index.js @@ -0,0 +1 @@ +export * from "./didSignedDocumentStatus"; diff --git a/dist/esm/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.js b/dist/esm/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.js new file mode 100644 index 00000000..c1e8d812 --- /dev/null +++ b/dist/esm/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.js @@ -0,0 +1,269 @@ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +import { getData, utils, v3 } from "@govtechsg/open-attestation"; +import { DocumentStoreFactory } from "@govtechsg/document-store"; +import { OpenAttestationEthereumDocumentStoreStatusCode } from "../../../types/error"; +import { CodedError } from "../../../common/error"; +import { withCodedErrorHandler } from "../../../common/errorHandler"; +import { decodeError, isRevokedOnDocumentStore } from "../utils"; +import { InvalidRevocationStatus, ValidRevocationStatusArray } from "../revocation.types"; +import { InvalidDocumentStoreIssuanceStatus, ValidDocumentStoreDataV3, ValidDocumentStoreIssuanceStatusArray, } from "./ethereumDocumentStoreStatus.type"; +var name = "OpenAttestationEthereumDocumentStoreStatus"; +var type = "DOCUMENT_STATUS"; +// Returns list of all document stores, throws when not all issuers are using document store +export var getIssuersDocumentStores = function (document) { + var data = getData(document); + return data.issuers.map(function (issuer) { + var documentStoreAddress = issuer.documentStore || issuer.certificateStore; + if (!documentStoreAddress) + throw new CodedError("Document store address not found in issuer " + issuer.name, OpenAttestationEthereumDocumentStoreStatusCode.INVALID_ISSUERS, OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode.INVALID_ISSUERS]); + return documentStoreAddress; + }); +}; +export var isIssuedOnDocumentStore = function (_a) { + var documentStore = _a.documentStore, merkleRoot = _a.merkleRoot, provider = _a.provider; + return __awaiter(void 0, void 0, void 0, function () { + var documentStoreContract, issued, error_1; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _b.trys.push([0, 3, , 4]); + return [4 /*yield*/, DocumentStoreFactory.connect(documentStore, provider)]; + case 1: + documentStoreContract = _b.sent(); + return [4 /*yield*/, documentStoreContract.isIssued(merkleRoot)]; + case 2: + issued = _b.sent(); + return [2 /*return*/, issued + ? { + issued: true, + address: documentStore, + } + : { + issued: false, + address: documentStore, + reason: { + message: "Document " + merkleRoot + " has not been issued under contract " + documentStore, + code: OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED, + codeString: OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED], + }, + }]; + case 3: + error_1 = _b.sent(); + // If error can be decoded and it's because of document is not issued, we return false + // Else allow error to continue to bubble up + return [2 /*return*/, { + issued: false, + address: documentStore, + reason: { + message: decodeError(error_1), + code: OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED, + codeString: OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED], + }, + }]; + case 4: return [2 /*return*/]; + } + }); + }); +}; +var skip = function () { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, { + status: "SKIPPED", + type: type, + name: name, + reason: { + code: OpenAttestationEthereumDocumentStoreStatusCode.SKIPPED, + codeString: OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode.SKIPPED], + message: "Document issuers doesn't have \"documentStore\" or \"certificateStore\" property or " + v3.Method.DocumentStore + " method", + }, + }]; + }); +}); }; +var test = function (document) { + if (utils.isWrappedV2Document(document)) { + var documentData = getData(document); + return documentData.issuers.some(function (issuer) { return "documentStore" in issuer || "certificateStore" in issuer; }); + } + else if (utils.isWrappedV3Document(document)) { + return document.openAttestationMetadata.proof.method === v3.Method.DocumentStore; + } + return false; +}; +var verifyV2 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + var documentStores, merkleRoot, targetHash, proofs, issuanceStatuses, notIssued, revocationStatuses, revoked; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + documentStores = getIssuersDocumentStores(document); + merkleRoot = "0x" + document.signature.merkleRoot; + targetHash = document.signature.targetHash; + proofs = document.signature.proof || []; + return [4 /*yield*/, Promise.all(documentStores.map(function (documentStore) { + return isIssuedOnDocumentStore({ documentStore: documentStore, merkleRoot: merkleRoot, provider: options.provider }); + }))]; + case 1: + issuanceStatuses = _a.sent(); + notIssued = issuanceStatuses.find(InvalidDocumentStoreIssuanceStatus.guard); + if (InvalidDocumentStoreIssuanceStatus.guard(notIssued)) { + return [2 /*return*/, { + name: name, + type: type, + data: { + issuedOnAll: false, + details: { issuance: issuanceStatuses }, + }, + reason: notIssued.reason, + status: "INVALID", + }]; + } + return [4 /*yield*/, Promise.all(documentStores.map(function (documentStore) { + return isRevokedOnDocumentStore({ + documentStore: documentStore, + merkleRoot: merkleRoot, + targetHash: targetHash, + proofs: proofs, + provider: options.provider, + }); + }))]; + case 2: + revocationStatuses = _a.sent(); + revoked = revocationStatuses.find(InvalidRevocationStatus.guard); + if (InvalidRevocationStatus.guard(revoked)) { + return [2 /*return*/, { + name: name, + type: type, + data: { + issuedOnAll: true, + revokedOnAny: true, + details: { issuance: issuanceStatuses, revocation: revocationStatuses }, + }, + reason: revoked.reason, + status: "INVALID", + }]; + } + if (ValidDocumentStoreIssuanceStatusArray.guard(issuanceStatuses) && + ValidRevocationStatusArray.guard(revocationStatuses)) { + return [2 /*return*/, { + name: name, + type: type, + data: { + issuedOnAll: true, + revokedOnAny: false, + details: { issuance: issuanceStatuses, revocation: revocationStatuses }, + }, + status: "VALID", + }]; + } + throw new CodedError("Reached an unexpected state when verifying v2 document", OpenAttestationEthereumDocumentStoreStatusCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); + } + }); +}); }; +var verifyV3 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + var _a, merkleRootRaw, targetHash, proofs, merkleRoot, documentStore, issuance, revocation, data, reason; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _a = document.proof, merkleRootRaw = _a.merkleRoot, targetHash = _a.targetHash, proofs = _a.proofs; + merkleRoot = "0x" + merkleRootRaw; + documentStore = document.openAttestationMetadata.proof.value; + return [4 /*yield*/, isIssuedOnDocumentStore({ documentStore: documentStore, merkleRoot: merkleRoot, provider: options.provider })]; + case 1: + issuance = _b.sent(); + return [4 /*yield*/, isRevokedOnDocumentStore({ + documentStore: documentStore, + merkleRoot: merkleRoot, + targetHash: targetHash, + proofs: proofs, + provider: options.provider, + })]; + case 2: + revocation = _b.sent(); + data = { + issuedOnAll: issuance.issued, + revokedOnAny: revocation.revoked, + details: { + issuance: issuance, + revocation: revocation, + }, + }; + if (ValidDocumentStoreDataV3.guard(data)) { + return [2 /*return*/, { + name: name, + type: type, + data: data, + status: "VALID", + }]; + } + if (InvalidRevocationStatus.guard(revocation)) { + reason = revocation.reason; + } + else if (InvalidDocumentStoreIssuanceStatus.guard(issuance)) { + reason = issuance.reason; + } + if (!reason) { + throw new CodedError("Unable to retrieve the reason of the failure", OpenAttestationEthereumDocumentStoreStatusCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); + } + return [2 /*return*/, { + name: name, + type: type, + data: data, + status: "INVALID", + reason: reason, + }]; + } + }); +}); }; +var verify = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + if (utils.isWrappedV2Document(document)) + return [2 /*return*/, verifyV2(document, options)]; + else if (utils.isWrappedV3Document(document)) + return [2 /*return*/, verifyV3(document, options)]; + throw new CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", OpenAttestationEthereumDocumentStoreStatusCode.UNRECOGNIZED_DOCUMENT, OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode.UNRECOGNIZED_DOCUMENT]); + }); +}); }; +export var openAttestationEthereumDocumentStoreStatus = { + skip: skip, + test: test, + verify: withCodedErrorHandler(verify, { + name: name, + type: type, + unexpectedErrorCode: OpenAttestationEthereumDocumentStoreStatusCode.UNEXPECTED_ERROR, + unexpectedErrorString: OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode.UNEXPECTED_ERROR], + }), +}; diff --git a/dist/esm/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.js b/dist/esm/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.js new file mode 100644 index 00000000..edcc5437 --- /dev/null +++ b/dist/esm/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.js @@ -0,0 +1,56 @@ +import { Array as RunTypesArray, Boolean, Literal, Optional, Record, String, Union } from "runtypes"; +import { Reason } from "../../../types/error"; +import { RevocationStatus, RevocationStatusArray, ValidRevocationStatus, ValidRevocationStatusArray, } from "../revocation.types"; +/** + * Document store issuance status + */ +export var ValidDocumentStoreIssuanceStatus = Record({ + issued: Literal(true), + address: String, +}); +export var ValidDocumentStoreIssuanceStatusArray = RunTypesArray(ValidDocumentStoreIssuanceStatus); +export var InvalidDocumentStoreIssuanceStatus = Record({ + issued: Literal(false), + address: String, + reason: Reason, +}); +export var DocumentStoreIssuanceStatus = Union(ValidDocumentStoreIssuanceStatus, InvalidDocumentStoreIssuanceStatus); +export var DocumentStoreIssuanceStatusArray = RunTypesArray(DocumentStoreIssuanceStatus); +/** + * Data for v2 Fragments + */ +var ValidDocumentStoreDataV2 = Record({ + issuedOnAll: Literal(true), + revokedOnAny: Literal(false), + details: Record({ + issuance: ValidDocumentStoreIssuanceStatusArray, + revocation: ValidRevocationStatusArray, + }), +}); +export var InvalidDocumentStoreDataV2 = Record({ + issuedOnAll: Boolean, + revokedOnAny: Optional(Boolean), + details: Record({ + issuance: DocumentStoreIssuanceStatusArray, + revocation: Optional(RevocationStatusArray), + }), +}); +/** + * Data for v3 Fragments + */ +export var ValidDocumentStoreDataV3 = Record({ + issuedOnAll: Literal(true), + revokedOnAny: Literal(false), + details: Record({ + issuance: ValidDocumentStoreIssuanceStatus, + revocation: ValidRevocationStatus, + }), +}); +export var InvalidDocumentStoreDataV3 = Record({ + issuedOnAll: Boolean, + revokedOnAny: Boolean, + details: Record({ + issuance: DocumentStoreIssuanceStatus, + revocation: RevocationStatus, + }), +}); diff --git a/dist/esm/verifiers/documentStatus/documentStore/index.js b/dist/esm/verifiers/documentStatus/documentStore/index.js new file mode 100644 index 00000000..51a171e5 --- /dev/null +++ b/dist/esm/verifiers/documentStatus/documentStore/index.js @@ -0,0 +1 @@ +export * from "./ethereumDocumentStoreStatus"; diff --git a/dist/esm/verifiers/documentStatus/revocation.types.js b/dist/esm/verifiers/documentStatus/revocation.types.js new file mode 100644 index 00000000..1e94ebb6 --- /dev/null +++ b/dist/esm/verifiers/documentStatus/revocation.types.js @@ -0,0 +1,28 @@ +import { Literal, Record, String, Union, Array as RunTypesArray, Optional } from "runtypes"; +import { Reason } from "../../types/error"; +export var ValidRevocationStatus = Record({ + revoked: Literal(false), + address: Optional(String), +}); +export var ValidRevocationStatusArray = RunTypesArray(ValidRevocationStatus); +export var InvalidRevocationStatus = Record({ + revoked: Literal(true), + address: String, + reason: Reason, +}); +export var RevocationStatus = Union(ValidRevocationStatus, InvalidRevocationStatus); +export var RevocationStatusArray = RunTypesArray(RevocationStatus); +export var OcspResponderRevocationStatus = Union(Literal("good"), Literal("revoked"), Literal("unknown")); +export var OcspResponderRevocationReason; +(function (OcspResponderRevocationReason) { + OcspResponderRevocationReason[OcspResponderRevocationReason["UNSPECIFIED"] = 0] = "UNSPECIFIED"; + OcspResponderRevocationReason[OcspResponderRevocationReason["KEY_COMPROMISE"] = 1] = "KEY_COMPROMISE"; + OcspResponderRevocationReason[OcspResponderRevocationReason["CA_COMPROMISE"] = 2] = "CA_COMPROMISE"; + OcspResponderRevocationReason[OcspResponderRevocationReason["AFFILIATION_CHANGED"] = 3] = "AFFILIATION_CHANGED"; + OcspResponderRevocationReason[OcspResponderRevocationReason["SUPERSEDED"] = 4] = "SUPERSEDED"; + OcspResponderRevocationReason[OcspResponderRevocationReason["CESSATION_OF_OPERATION"] = 5] = "CESSATION_OF_OPERATION"; + OcspResponderRevocationReason[OcspResponderRevocationReason["CERTIFICATE_HOLD"] = 6] = "CERTIFICATE_HOLD"; + OcspResponderRevocationReason[OcspResponderRevocationReason["REMOVE_FROM_CRL"] = 8] = "REMOVE_FROM_CRL"; + OcspResponderRevocationReason[OcspResponderRevocationReason["PRIVILEGE_WITHDRAWN"] = 9] = "PRIVILEGE_WITHDRAWN"; + OcspResponderRevocationReason[OcspResponderRevocationReason["A_A_COMPROMISE"] = 10] = "A_A_COMPROMISE"; +})(OcspResponderRevocationReason || (OcspResponderRevocationReason = {})); diff --git a/dist/esm/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.js b/dist/esm/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.js new file mode 100644 index 00000000..ff4b9cf1 --- /dev/null +++ b/dist/esm/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.js @@ -0,0 +1,231 @@ +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +import { getData, utils, v3 } from "@govtechsg/open-attestation"; +import { TradeTrustErc721Factory } from "@govtechsg/token-registry"; +import { constants, errors } from "ethers"; +import { OpenAttestationEthereumTokenRegistryStatusCode } from "../../../types/error"; +import { CodedError } from "../../../common/error"; +import { withCodedErrorHandler } from "../../../common/errorHandler"; +import { ValidTokenRegistryStatus, } from "./ethereumTokenRegistryStatus.type"; +var name = "OpenAttestationEthereumTokenRegistryStatus"; +var type = "DOCUMENT_STATUS"; +export var getTokenRegistry = function (document) { + if (utils.isWrappedV2Document(document)) { + var issuers = getData(document).issuers; + if (issuers.length !== 1) + throw new CodedError("Only one issuer is allowed for tokens", OpenAttestationEthereumTokenRegistryStatusCode.INVALID_ISSUERS, OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.INVALID_ISSUERS]); + if (!issuers[0].tokenRegistry) + throw new CodedError("Token registry is undefined", OpenAttestationEthereumTokenRegistryStatusCode.UNDEFINED_TOKEN_REGISTRY, OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.UNDEFINED_TOKEN_REGISTRY]); + return issuers[0].tokenRegistry; + } + if (utils.isWrappedV3Document(document)) { + if (!document.openAttestationMetadata.proof.value) + throw new CodedError("Token registry is undefined", OpenAttestationEthereumTokenRegistryStatusCode.UNDEFINED_TOKEN_REGISTRY, OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.UNDEFINED_TOKEN_REGISTRY]); + return document.openAttestationMetadata.proof.value; + } + throw new CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT, OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT]); +}; +var getMerkleRoot = function (document) { + if (utils.isWrappedV2Document(document)) + return "0x" + document.signature.merkleRoot; + else if (utils.isWrappedV3Document(document)) + return "0x" + document.proof.merkleRoot; + throw new CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT, OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT]); +}; +var isNonExistentToken = function (error) { + var message = error.message; + if (!message) + return false; + return message.includes("owner query for nonexistent token"); +}; +var isMissingTokenRegistry = function (error) { + var _a; + return (!error.reason && + ((_a = error.method) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === "ownerOf(uint256)".toLowerCase() && + error.code === errors.CALL_EXCEPTION); +}; +var decodeError = function (error) { + var _a; + var reason = error.reason && Array.isArray(error.reason) ? error.reason[0] : (_a = error.reason) !== null && _a !== void 0 ? _a : ""; + switch (true) { + case isNonExistentToken(error): + return "Document has not been issued under token registry"; + case isMissingTokenRegistry(error): + return "Token registry is not found"; + case reason.toLowerCase() === "ENS name not configured".toLowerCase() && + error.code === errors.UNSUPPORTED_OPERATION: + return "ENS name is not configured"; + case reason.toLowerCase() === "invalid address".toLowerCase() && error.code === errors.INVALID_ARGUMENT: + return "Invalid token registry address"; + case error.code === errors.INVALID_ARGUMENT: + return "Invalid contract arguments"; + case error.code === errors.SERVER_ERROR: + throw new CodedError("Unable to connect to the Ethereum network, please try again later", OpenAttestationEthereumTokenRegistryStatusCode.SERVER_ERROR, OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.SERVER_ERROR]); + default: + throw error; + } +}; +export var isTokenMintedOnRegistry = function (_a) { + var tokenRegistry = _a.tokenRegistry, merkleRoot = _a.merkleRoot, provider = _a.provider; + return __awaiter(void 0, void 0, void 0, function () { + var tokenRegistryContract, minted, error_1; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _b.trys.push([0, 3, , 4]); + return [4 /*yield*/, TradeTrustErc721Factory.connect(tokenRegistry, provider)]; + case 1: + tokenRegistryContract = _b.sent(); + return [4 /*yield*/, tokenRegistryContract.ownerOf(merkleRoot).then(function (owner) { return !(owner === constants.AddressZero); })]; + case 2: + minted = _b.sent(); + return [2 /*return*/, minted + ? { minted: minted, address: tokenRegistry } + : { + minted: minted, + address: tokenRegistry, + reason: { + code: OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED, + codeString: OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED], + message: "Document " + merkleRoot + " has not been issued under contract " + tokenRegistry, + }, + }]; + case 3: + error_1 = _b.sent(); + return [2 /*return*/, { + minted: false, + address: tokenRegistry, + reason: { + message: decodeError(error_1), + code: OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED, + codeString: OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED], + }, + }]; + case 4: return [2 /*return*/]; + } + }); + }); +}; +var skip = function () { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, { + status: "SKIPPED", + type: type, + name: name, + reason: { + code: OpenAttestationEthereumTokenRegistryStatusCode.SKIPPED, + codeString: OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.SKIPPED], + message: "Document issuers doesn't have \"tokenRegistry\" property or " + v3.Method.TokenRegistry + " method", + }, + }]; + }); +}); }; +var test = function (document) { + if (utils.isWrappedV2Document(document)) { + var documentData = getData(document); + return documentData.issuers.some(function (issuer) { return "tokenRegistry" in issuer; }); + } + else if (utils.isWrappedV3Document(document)) { + return document.openAttestationMetadata.proof.method === v3.Method.TokenRegistry; + } + return false; +}; +// TODO split +var verify = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + var tokenRegistry, merkleRoot, mintStatus, fragment, fragment; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!utils.isWrappedV3Document(document) && !utils.isWrappedV2Document(document)) + throw new CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT, OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT]); + tokenRegistry = getTokenRegistry(document); + merkleRoot = getMerkleRoot(document); + return [4 /*yield*/, isTokenMintedOnRegistry({ tokenRegistry: tokenRegistry, merkleRoot: merkleRoot, provider: options.provider })]; + case 1: + mintStatus = _a.sent(); + if (ValidTokenRegistryStatus.guard(mintStatus)) { + fragment = { + name: name, + type: type, + status: "VALID", + }; + if (utils.isWrappedV3Document(document)) { + return [2 /*return*/, __assign(__assign({}, fragment), { data: { mintedOnAll: true, details: mintStatus } })]; + } + else { + return [2 /*return*/, __assign(__assign({}, fragment), { data: { mintedOnAll: true, details: [mintStatus] } })]; + } + } + else { + fragment = { + name: name, + type: type, + reason: mintStatus.reason, + status: "INVALID", + }; + if (utils.isWrappedV3Document(document)) { + return [2 /*return*/, __assign(__assign({}, fragment), { data: { mintedOnAll: false, details: mintStatus } })]; + } + else { + return [2 /*return*/, __assign(__assign({}, fragment), { data: { mintedOnAll: false, details: [mintStatus] } })]; + } + } + return [2 /*return*/]; + } + }); +}); }; +export var openAttestationEthereumTokenRegistryStatus = { + skip: skip, + test: test, + verify: withCodedErrorHandler(verify, { + name: name, + type: type, + unexpectedErrorCode: OpenAttestationEthereumTokenRegistryStatusCode.UNEXPECTED_ERROR, + unexpectedErrorString: OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.UNEXPECTED_ERROR], + }), +}; diff --git a/dist/esm/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.js b/dist/esm/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.js new file mode 100644 index 00000000..4f842694 --- /dev/null +++ b/dist/esm/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.js @@ -0,0 +1,36 @@ +import { Array as RunTypesArray, Literal, Record, String, Union } from "runtypes"; +import { Reason } from "../../../types/error"; +/** + * Token registry mint status + */ +export var ValidTokenRegistryStatus = Record({ + minted: Literal(true), + address: String, +}); +export var InvalidTokenRegistryStatus = Record({ + minted: Literal(false), + address: String, + reason: Reason, +}); +/** + * Data for v2 Fragments + */ +export var ValidTokenRegistryDataV2 = Record({ + mintedOnAll: Literal(true), + details: RunTypesArray(ValidTokenRegistryStatus), +}); +export var InvalidTokenRegistryDataV2 = Record({ + mintedOnAll: Literal(false), + details: RunTypesArray(Union(ValidTokenRegistryStatus, InvalidTokenRegistryStatus)), +}); +/** + * Data for v3 Fragments + */ +export var ValidTokenRegistryDataV3 = Record({ + mintedOnAll: Literal(true), + details: ValidTokenRegistryStatus, +}); +export var InvalidTokenRegistryDataV3 = Record({ + mintedOnAll: Literal(false), + details: InvalidTokenRegistryStatus, +}); diff --git a/dist/esm/verifiers/documentStatus/tokenRegistry/index.js b/dist/esm/verifiers/documentStatus/tokenRegistry/index.js new file mode 100644 index 00000000..45f2ecca --- /dev/null +++ b/dist/esm/verifiers/documentStatus/tokenRegistry/index.js @@ -0,0 +1 @@ +export * from "./ethereumTokenRegistryStatus"; diff --git a/dist/esm/verifiers/documentStatus/utils.js b/dist/esm/verifiers/documentStatus/utils.js new file mode 100644 index 00000000..367338c4 --- /dev/null +++ b/dist/esm/verifiers/documentStatus/utils.js @@ -0,0 +1,182 @@ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +import { utils } from "@govtechsg/open-attestation"; +import { errors } from "ethers"; +import { DocumentStoreFactory } from "@govtechsg/document-store"; +import { OpenAttestationEthereumDocumentStoreStatusCode, OpenAttestationDidSignedDocumentStatusCode, } from "../../types/error"; +import { CodedError } from "../../common/error"; +import { OcspResponderRevocationReason } from "./revocation.types"; +import axios from "axios"; +import { ValidOcspResponse, ValidOcspResponseRevoked } from "./didSigned/didSignedDocumentStatus.type"; +export var getIntermediateHashes = function (targetHash, proofs) { + if (proofs === void 0) { proofs = []; } + var hashes = ["0x" + targetHash]; + proofs.reduce(function (prev, curr) { + var next = utils.combineHashString(prev, curr); + hashes.push("0x" + next); + return next; + }, targetHash); + return hashes; +}; +/** + * Try to decode the error to see if we can deterministically tell if the document has NOT been issued or revoked. + * + * In case where we cannot tell, we throw an error + * */ +export var decodeError = function (error) { + var _a, _b, _c, _d; + var reason = error.reason && Array.isArray(error.reason) ? error.reason[0] : (_a = error.reason) !== null && _a !== void 0 ? _a : ""; + switch (true) { + case !error.reason && + (((_b = error.method) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === "isRevoked(bytes32)".toLowerCase() || + ((_c = error.method) === null || _c === void 0 ? void 0 : _c.toLowerCase()) === "isIssued(bytes32)".toLowerCase()) && + error.code === errors.CALL_EXCEPTION: + return "Contract is not found"; + case reason.toLowerCase() === "ENS name not configured".toLowerCase() && + error.code === errors.UNSUPPORTED_OPERATION: + return "ENS name is not configured"; + case reason.toLowerCase() === "bad address checksum".toLowerCase() && error.code === errors.INVALID_ARGUMENT: + return "Bad document store address checksum"; + case ((_d = error.message) === null || _d === void 0 ? void 0 : _d.toLowerCase()) === "name not found".toLowerCase(): + return "ENS name is not found"; + case reason.toLowerCase() === "invalid address".toLowerCase() && error.code === errors.INVALID_ARGUMENT: + return "Invalid document store address"; + case error.code === errors.INVALID_ARGUMENT: + return "Invalid call arguments"; + case error.code === errors.SERVER_ERROR: + throw new CodedError("Unable to connect to the Ethereum network, please try again later", OpenAttestationEthereumDocumentStoreStatusCode.SERVER_ERROR, OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode.SERVER_ERROR]); + default: + throw error; + } +}; +/** + * Given a list of hashes, check against one smart contract if any of the hash has been revoked + * */ +export var isAnyHashRevoked = function (smartContract, intermediateHashes) { return __awaiter(void 0, void 0, void 0, function () { + var revokedStatusDeferred, revokedStatuses; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + revokedStatusDeferred = intermediateHashes.map(function (hash) { + return smartContract.isRevoked(hash).then(function (status) { return (status ? hash : undefined); }); + }); + return [4 /*yield*/, Promise.all(revokedStatusDeferred)]; + case 1: + revokedStatuses = _a.sent(); + return [2 /*return*/, revokedStatuses.find(function (hash) { return hash; })]; + } + }); +}); }; +export var isRevokedByOcspResponder = function (_a) { + var certificateId = _a.certificateId, location = _a.location; + return __awaiter(void 0, void 0, void 0, function () { + var data, reasonCode; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: return [4 /*yield*/, axios.get(location + "/" + certificateId)]; + case 1: + data = (_b.sent()).data; + if (ValidOcspResponseRevoked.guard(data) && data.certificateStatus === "revoked") { + reasonCode = data.reasonCode; + return [2 /*return*/, { + revoked: true, + address: location, + reason: { + message: OcspResponderRevocationReason[reasonCode], + code: reasonCode, + codeString: OcspResponderRevocationReason[reasonCode], + }, + }]; + } + else if (ValidOcspResponse.guard(data) && data.certificateStatus !== "revoked") { + return [2 /*return*/, { + revoked: false, + address: location, + }]; + } + throw new CodedError("oscp response invalid", OpenAttestationDidSignedDocumentStatusCode.OCSP_RESPONSE_INVALID, "OCSP_RESPONSE_INVALID"); + } + }); + }); +}; +export var isRevokedOnDocumentStore = function (_a) { + var documentStore = _a.documentStore, merkleRoot = _a.merkleRoot, provider = _a.provider, targetHash = _a.targetHash, proofs = _a.proofs; + return __awaiter(void 0, void 0, void 0, function () { + var documentStoreContract, intermediateHashes, revokedHash, error_1; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _b.trys.push([0, 3, , 4]); + return [4 /*yield*/, DocumentStoreFactory.connect(documentStore, provider)]; + case 1: + documentStoreContract = _b.sent(); + intermediateHashes = getIntermediateHashes(targetHash, proofs); + return [4 /*yield*/, isAnyHashRevoked(documentStoreContract, intermediateHashes)]; + case 2: + revokedHash = _b.sent(); + return [2 /*return*/, revokedHash + ? { + revoked: true, + address: documentStore, + reason: { + message: "Document " + merkleRoot + " has been revoked under contract " + documentStore, + code: OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED, + codeString: OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED], + }, + } + : { + revoked: false, + address: documentStore, + }]; + case 3: + error_1 = _b.sent(); + // If error can be decoded and it's because of document is not revoked, we return false + // Else allow error to continue to bubble up + return [2 /*return*/, { + revoked: true, + address: documentStore, + reason: { + message: decodeError(error_1), + code: OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED, + codeString: OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED], + }, + }]; + case 4: return [2 /*return*/]; + } + }); + }); +}; diff --git a/dist/esm/verifiers/issuerIdentity/did/didIdentityProof.js b/dist/esm/verifiers/issuerIdentity/did/didIdentityProof.js new file mode 100644 index 00000000..4ead938e --- /dev/null +++ b/dist/esm/verifiers/issuerIdentity/did/didIdentityProof.js @@ -0,0 +1,182 @@ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +import { getData, utils, v2, v3 } from "@govtechsg/open-attestation"; +import { OpenAttestationDidCode } from "../../../types/error"; +import { InvalidDidVerificationStatus, ValidDidVerificationStatus, ValidDidVerificationStatusArray, verifySignature, } from "../../../did/verifier"; +import { withCodedErrorHandler } from "../../../common/errorHandler"; +import { CodedError } from "../../../common/error"; +var name = "OpenAttestationDidIdentityProof"; +var type = "ISSUER_IDENTITY"; +var skip = function () { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, { + status: "SKIPPED", + type: type, + name: name, + reason: { + code: OpenAttestationDidCode.SKIPPED, + codeString: OpenAttestationDidCode[OpenAttestationDidCode.SKIPPED], + message: "Document is not using DID as top level identifier or has not been wrapped", + }, + }]; + }); +}); }; +var test = function (document) { + if (utils.isWrappedV2Document(document)) { + var issuers = getData(document).issuers; + return issuers.some(function (issuer) { var _a; return ((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === v2.IdentityProofType.Did; }); + } + else if (utils.isWrappedV3Document(document)) { + return document.openAttestationMetadata.identityProof.type === v3.IdentityProofType.Did; + } + return false; +}; +var verifyV2 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + var data, merkleRoot, signatureVerificationDeferred, signatureVerifications, invalidSignature; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!utils.isSignedWrappedV2Document(document)) + throw new CodedError("Document is not signed", OpenAttestationDidCode.UNSIGNED, "UNSIGNED"); + data = getData(document); + merkleRoot = "0x" + document.signature.merkleRoot; + signatureVerificationDeferred = data.issuers.map(function (issuer) { return __awaiter(void 0, void 0, void 0, function () { + var did, key_1, correspondingProof; + var _a, _b; + return __generator(this, function (_c) { + if (((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === "DID") { + did = issuer.id; + if (!did) + throw new CodedError("id is missing in issuer", OpenAttestationDidCode.DID_MISSING, "DID_MISSING"); + key_1 = (_b = issuer.identityProof) === null || _b === void 0 ? void 0 : _b.key; + if (!key_1) + throw new CodedError("Key is not present", OpenAttestationDidCode.MALFORMED_IDENTITY_PROOF, "MALFORMED_IDENTITY_PROOF"); + correspondingProof = document.proof.find(function (p) { return p.verificationMethod.toLowerCase() === key_1.toLowerCase(); }); + if (!correspondingProof) + throw new CodedError("No proof for " + key_1, OpenAttestationDidCode.MALFORMED_IDENTITY_PROOF, "MALFORMED_IDENTITY_PROOF"); + return [2 /*return*/, verifySignature({ + merkleRoot: merkleRoot, + key: key_1, + signature: correspondingProof.signature, + did: did, + resolver: options.resolver, + })]; + } + throw new CodedError("Issuer is not using DID identityProof type", OpenAttestationDidCode.INVALID_ISSUERS, OpenAttestationDidCode[OpenAttestationDidCode.INVALID_ISSUERS]); + }); + }); }); + return [4 /*yield*/, Promise.all(signatureVerificationDeferred)]; + case 1: + signatureVerifications = _a.sent(); + if (ValidDidVerificationStatusArray.guard(signatureVerifications)) { + return [2 /*return*/, { + name: name, + type: type, + data: signatureVerifications, + status: "VALID", + }]; + } + invalidSignature = signatureVerifications.find(InvalidDidVerificationStatus.guard); + if (InvalidDidVerificationStatus.guard(invalidSignature)) { + return [2 /*return*/, { + name: name, + type: type, + data: signatureVerifications, + reason: invalidSignature.reason, + status: "INVALID", + }]; + } + throw new CodedError("Unable to retrieve the reason of the failure", OpenAttestationDidCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); + } + }); +}); }; +var verifyV3 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + var merkleRoot, _a, key, signature, did, verificationStatus; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + if (!utils.isSignedWrappedV3Document(document)) + throw new CodedError("Document is not signed", OpenAttestationDidCode.UNSIGNED, "UNSIGNED"); + merkleRoot = "0x" + document.proof.merkleRoot; + _a = document.proof, key = _a.key, signature = _a.signature; + did = document.openAttestationMetadata.identityProof.identifier; + return [4 /*yield*/, verifySignature({ + did: did, + merkleRoot: merkleRoot, + key: key, + signature: signature, + resolver: options.resolver, + })]; + case 1: + verificationStatus = _b.sent(); + if (ValidDidVerificationStatus.guard(verificationStatus)) { + return [2 /*return*/, { + name: name, + type: type, + data: verificationStatus, + status: "VALID", + }]; + } + return [2 /*return*/, { + name: name, + type: type, + data: verificationStatus, + reason: verificationStatus.reason, + status: "INVALID", + }]; + } + }); +}); }; +var verify = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + if (utils.isWrappedV2Document(document)) + return [2 /*return*/, verifyV2(document, options)]; + else if (utils.isWrappedV3Document(document)) + return [2 /*return*/, verifyV3(document, options)]; + throw new CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", OpenAttestationDidCode.UNRECOGNIZED_DOCUMENT, OpenAttestationDidCode[OpenAttestationDidCode.UNRECOGNIZED_DOCUMENT]); + }); +}); }; +export var openAttestationDidIdentityProof = { + skip: skip, + test: test, + verify: withCodedErrorHandler(verify, { + name: name, + type: type, + unexpectedErrorCode: OpenAttestationDidCode.UNEXPECTED_ERROR, + unexpectedErrorString: OpenAttestationDidCode[OpenAttestationDidCode.UNEXPECTED_ERROR], + }), +}; diff --git a/dist/esm/verifiers/issuerIdentity/did/didIdentityProof.type.js b/dist/esm/verifiers/issuerIdentity/did/didIdentityProof.type.js new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/esm/verifiers/issuerIdentity/did/didIdentityProof.type.js @@ -0,0 +1 @@ +export {}; diff --git a/dist/esm/verifiers/issuerIdentity/did/index.js b/dist/esm/verifiers/issuerIdentity/did/index.js new file mode 100644 index 00000000..cd1e1bb4 --- /dev/null +++ b/dist/esm/verifiers/issuerIdentity/did/index.js @@ -0,0 +1 @@ +export * from "./didIdentityProof"; diff --git a/dist/esm/verifiers/issuerIdentity/dnsDid/dnsDidProof.js b/dist/esm/verifiers/issuerIdentity/dnsDid/dnsDidProof.js new file mode 100644 index 00000000..a625d705 --- /dev/null +++ b/dist/esm/verifiers/issuerIdentity/dnsDid/dnsDidProof.js @@ -0,0 +1,183 @@ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +import { getData, utils, v2, v3 } from "@govtechsg/open-attestation"; +import { getDnsDidRecords } from "@govtechsg/dnsprove"; +import { OpenAttestationDnsDidCode } from "../../../types/error"; +import { withCodedErrorHandler } from "../../../common/errorHandler"; +import { CodedError } from "../../../common/error"; +import { ValidDnsDidVerificationStatus, ValidDnsDidVerificationStatusArray, } from "./dnsDidProof.type"; +var name = "OpenAttestationDnsDidIdentityProof"; +var type = "ISSUER_IDENTITY"; +var skip = function () { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, { + status: "SKIPPED", + type: type, + name: name, + reason: { + code: OpenAttestationDnsDidCode.SKIPPED, + codeString: OpenAttestationDnsDidCode[OpenAttestationDnsDidCode.SKIPPED], + message: "Document was not issued using DNS-DID", + }, + }]; + }); +}); }; +var test = function (document) { + if (utils.isSignedWrappedV2Document(document)) { + var data = getData(document); + return data.issuers.some(function (issuer) { var _a; return ((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === "DNS-DID"; }); + } + else if (utils.isSignedWrappedV3Document(document)) { + return document.openAttestationMetadata.identityProof.type === v3.IdentityProofType.DNSDid; + } + return false; +}; +var verifyIssuerDnsDid = function (_a) { + var key = _a.key, location = _a.location; + return __awaiter(void 0, void 0, void 0, function () { + var records; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: return [4 /*yield*/, getDnsDidRecords(location)]; + case 1: + records = _b.sent(); + return [2 /*return*/, { + location: location, + key: key, + status: records.some(function (record) { return record.publicKey.toLowerCase() === key.toLowerCase(); }) ? "VALID" : "INVALID", + }]; + } + }); + }); +}; +var verifyV2 = function (document) { return __awaiter(void 0, void 0, void 0, function () { + var documentData, deferredVerificationStatus, verificationStatus; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + documentData = getData(document); + deferredVerificationStatus = documentData.issuers.map(function (issuer) { + var identityProof = issuer.identityProof; + if (!identityProof) + throw new CodedError("Identity proof missing", OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF, OpenAttestationDnsDidCode[OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF]); + var key = identityProof.key, location = identityProof.location, identityProofType = identityProof.type; + if (identityProofType !== v2.IdentityProofType.DNSDid) + throw new CodedError("Issuer is not using DID-DNS identityProof type", OpenAttestationDnsDidCode.INVALID_ISSUERS, OpenAttestationDnsDidCode[OpenAttestationDnsDidCode.INVALID_ISSUERS]); + if (!location) + throw new CodedError("location is not present in identity proof", OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF, OpenAttestationDnsDidCode[OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF]); + if (!key) + throw new CodedError("key is not present in identity proof", OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF, OpenAttestationDnsDidCode[OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF]); + return verifyIssuerDnsDid({ key: key, location: location }); + }); + return [4 /*yield*/, Promise.all(deferredVerificationStatus)]; + case 1: + verificationStatus = _a.sent(); + if (ValidDnsDidVerificationStatusArray.guard(verificationStatus)) { + return [2 /*return*/, { + name: name, + type: type, + data: verificationStatus, + status: "VALID", + }]; + } + return [2 /*return*/, { + name: name, + type: type, + data: verificationStatus, + reason: { + message: "Could not find identity at location", + code: OpenAttestationDnsDidCode.INVALID_IDENTITY, + codeString: "INVALID_IDENTITY", + }, + status: "INVALID", + }]; + } + }); +}); }; +var verifyV3 = function (document) { return __awaiter(void 0, void 0, void 0, function () { + var location, key, verificationStatus; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!utils.isSignedWrappedV3Document(document)) + throw new CodedError("document is not signed", OpenAttestationDnsDidCode.UNSIGNED, OpenAttestationDnsDidCode[OpenAttestationDnsDidCode.UNSIGNED]); + location = document.openAttestationMetadata.identityProof.identifier; + key = document.proof.key; + return [4 /*yield*/, verifyIssuerDnsDid({ key: key, location: location })]; + case 1: + verificationStatus = _a.sent(); + if (ValidDnsDidVerificationStatus.guard(verificationStatus)) { + return [2 /*return*/, { + name: name, + type: type, + data: verificationStatus, + status: "VALID", + }]; + } + return [2 /*return*/, { + name: name, + type: type, + data: verificationStatus, + status: "INVALID", + reason: { + message: "Could not find identity at location", + code: OpenAttestationDnsDidCode.INVALID_IDENTITY, + codeString: "INVALID_IDENTITY", + }, + }]; + } + }); +}); }; +var verify = function (document) { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + if (utils.isSignedWrappedV2Document(document)) + return [2 /*return*/, verifyV2(document)]; + else if (utils.isSignedWrappedV3Document(document)) + return [2 /*return*/, verifyV3(document)]; + throw new CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", OpenAttestationDnsDidCode.UNRECOGNIZED_DOCUMENT, OpenAttestationDnsDidCode[OpenAttestationDnsDidCode.UNRECOGNIZED_DOCUMENT]); + }); +}); }; +export var openAttestationDnsDidIdentityProof = { + skip: skip, + test: test, + verify: withCodedErrorHandler(verify, { + name: name, + type: type, + unexpectedErrorCode: OpenAttestationDnsDidCode.UNEXPECTED_ERROR, + unexpectedErrorString: OpenAttestationDnsDidCode[OpenAttestationDnsDidCode.UNEXPECTED_ERROR], + }), +}; diff --git a/dist/esm/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.js b/dist/esm/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.js new file mode 100644 index 00000000..177308f3 --- /dev/null +++ b/dist/esm/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.js @@ -0,0 +1,17 @@ +import { Array as RunTypesArray, Literal, Record, String, Union } from "runtypes"; +/** + * DNS-DID verification status + */ +export var ValidDnsDidVerificationStatus = Record({ + status: Literal("VALID"), + location: String, + key: String, +}); +export var ValidDnsDidVerificationStatusArray = RunTypesArray(ValidDnsDidVerificationStatus).withConstraint(function (elements) { return elements.length > 0 || "Expect at least one valid element"; }); +export var InvalidDnsDidVerificationStatus = Record({ + status: Literal("INVALID"), + location: String, + key: String, +}); +export var DnsDidVerificationStatus = Union(ValidDnsDidVerificationStatus, InvalidDnsDidVerificationStatus); +export var DnsDidVerificationStatusArray = RunTypesArray(DnsDidVerificationStatus); diff --git a/dist/esm/verifiers/issuerIdentity/dnsDid/index.js b/dist/esm/verifiers/issuerIdentity/dnsDid/index.js new file mode 100644 index 00000000..5433c63d --- /dev/null +++ b/dist/esm/verifiers/issuerIdentity/dnsDid/index.js @@ -0,0 +1 @@ +export * from "./dnsDidProof"; diff --git a/dist/esm/verifiers/issuerIdentity/dnsTxt/index.js b/dist/esm/verifiers/issuerIdentity/dnsTxt/index.js new file mode 100644 index 00000000..3d32f907 --- /dev/null +++ b/dist/esm/verifiers/issuerIdentity/dnsTxt/index.js @@ -0,0 +1 @@ +export * from "./openAttestationDnsTxt"; diff --git a/dist/esm/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.js b/dist/esm/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.js new file mode 100644 index 00000000..57d115a9 --- /dev/null +++ b/dist/esm/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.js @@ -0,0 +1,217 @@ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +import { getData, utils, v2, v3 } from "@govtechsg/open-attestation"; +import { getDocumentStoreRecords } from "@govtechsg/dnsprove"; +import { OpenAttestationDnsTxtCode } from "../../../types/error"; +import { withCodedErrorHandler } from "../../../common/errorHandler"; +import { CodedError } from "../../../common/error"; +import { InvalidDnsTxtVerificationStatus, ValidDnsTxtVerificationStatus, ValidDnsTxtVerificationStatusArray, } from "./openAttestationDnsTxt.type"; +var name = "OpenAttestationDnsTxtIdentityProof"; +var type = "ISSUER_IDENTITY"; +// Resolve identity of an issuer, currently supporting only DNS-TXT +// DNS-TXT is explained => https://github.com/Open-Attestation/adr/blob/master/decentralized_identity_proof_DNS-TXT.md +var resolveIssuerIdentity = function (location, smartContractAddress, options) { return __awaiter(void 0, void 0, void 0, function () { + var network, records, matchingRecord; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, options.provider.getNetwork()]; + case 1: + network = _a.sent(); + return [4 /*yield*/, getDocumentStoreRecords(location)]; + case 2: + records = _a.sent(); + matchingRecord = records.find(function (record) { + return record.addr.toLowerCase() === smartContractAddress.toLowerCase() && + record.netId === network.chainId.toString(10) && + record.type === "openatts" && + record.net === "ethereum"; + }); + return [2 /*return*/, matchingRecord + ? { + status: "VALID", + location: location, + value: smartContractAddress, + } + : { + status: "INVALID", + location: location, + value: smartContractAddress, + reason: { + message: "Matching DNS record not found for " + smartContractAddress, + code: OpenAttestationDnsTxtCode.MATCHING_RECORD_NOT_FOUND, + codeString: OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode.MATCHING_RECORD_NOT_FOUND], + }, + }]; + } + }); +}); }; +var skip = function () { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, { + status: "SKIPPED", + type: type, + name: name, + reason: { + code: OpenAttestationDnsTxtCode.SKIPPED, + codeString: OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode.SKIPPED], + message: "Document issuers doesn't have \"documentStore\" / \"tokenRegistry\" property or doesn't use " + v3.IdentityProofType.DNSTxt + " type", + }, + }]; + }); +}); }; +var test = function (document) { + if (utils.isWrappedV2Document(document)) { + var documentData = getData(document); + // at least one issuer uses DNS-TXT + return documentData.issuers.some(function (issuer) { + var _a; + return ((issuer.documentStore || issuer.tokenRegistry || issuer.certificateStore) && + ((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === v2.IdentityProofType.DNSTxt); + }); + } + else if (utils.isWrappedV3Document(document)) { + return document.openAttestationMetadata.identityProof.type === v3.IdentityProofType.DNSTxt; + } + return false; +}; +var verifyV2 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + var documentData, identities, invalidIdentity; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + documentData = getData(document); + return [4 /*yield*/, Promise.all(documentData.issuers.map(function (issuer) { + var _a; + if (((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === v2.IdentityProofType.DNSTxt) { + var location = issuer.identityProof.location; + var smartContractAddress = issuer.documentStore || issuer.tokenRegistry || issuer.certificateStore; + if (!location) + throw new CodedError("Location not found in identity proof", OpenAttestationDnsTxtCode.INVALID_ISSUERS, OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode.INVALID_ISSUERS]); + if (!smartContractAddress) + throw new CodedError("Smart contract address not found in identity proof", OpenAttestationDnsTxtCode.INVALID_ISSUERS, OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode.INVALID_ISSUERS]); + return resolveIssuerIdentity(location, smartContractAddress, options); + } + var invalidResponse = { + status: "INVALID", + reason: { + message: "Issuer is not using DNS-TXT identityProof type", + code: OpenAttestationDnsTxtCode.INVALID_ISSUERS, + codeString: OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode.INVALID_ISSUERS], + }, + }; + return invalidResponse; // eslint is happy, so am I (https://github.com/bradzacher/eslint-plugin-typescript/blob/master/docs/rules/no-object-literal-type-assertion.md) + }))]; + case 1: + identities = _a.sent(); + if (ValidDnsTxtVerificationStatusArray.guard(identities)) { + return [2 /*return*/, { + name: name, + type: type, + data: identities, + status: "VALID", + }]; + } + invalidIdentity = identities.find(InvalidDnsTxtVerificationStatus.guard); + if (InvalidDnsTxtVerificationStatus.guard(invalidIdentity)) { + return [2 /*return*/, { + name: name, + type: type, + data: identities, + reason: invalidIdentity.reason, + status: "INVALID", + }]; + } + throw new CodedError("Unable to retrieve the reason of the failure", OpenAttestationDnsTxtCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); + } + }); +}); }; +var verifyV3 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + var smartContractAddress, identifier, issuerIdentity; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (document.openAttestationMetadata.proof.method !== v3.Method.DocumentStore && + document.openAttestationMetadata.proof.method !== v3.Method.TokenRegistry) + throw new CodedError("DNS-TXT is only supported with documents issued using document store or token registry", OpenAttestationDnsTxtCode.UNSUPPORTED, OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode.UNSUPPORTED]); + smartContractAddress = document.openAttestationMetadata.proof.value; + identifier = document.openAttestationMetadata.identityProof.identifier; + return [4 /*yield*/, resolveIssuerIdentity(identifier, smartContractAddress, options)]; + case 1: + issuerIdentity = _a.sent(); + if (ValidDnsTxtVerificationStatus.guard(issuerIdentity)) { + return [2 /*return*/, { + name: name, + type: type, + data: { + identifier: issuerIdentity.location, + value: issuerIdentity.value, + }, + status: "VALID", + }]; + } + return [2 /*return*/, { + name: name, + type: type, + data: { + identifier: issuerIdentity.location, + value: issuerIdentity.value, + }, + reason: issuerIdentity.reason, + status: "INVALID", + }]; + } + }); +}); }; +export var openAttestationDnsTxtIdentityProof = { + skip: skip, + test: test, + verify: withCodedErrorHandler(function (document, options) { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + if (utils.isWrappedV2Document(document)) + return [2 /*return*/, verifyV2(document, options)]; + else if (utils.isWrappedV3Document(document)) + return [2 /*return*/, verifyV3(document, options)]; + // this code is actually unreachable because of the test function + throw new CodedError("Document does not match either v2 or v3 formats", OpenAttestationDnsTxtCode.UNRECOGNIZED_DOCUMENT, OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode.UNRECOGNIZED_DOCUMENT]); + }); + }); }, { + name: name, + type: type, + unexpectedErrorCode: OpenAttestationDnsTxtCode.UNEXPECTED_ERROR, + unexpectedErrorString: OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode.UNEXPECTED_ERROR], + }), +}; diff --git a/dist/esm/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.js b/dist/esm/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.js new file mode 100644 index 00000000..63bd0854 --- /dev/null +++ b/dist/esm/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.js @@ -0,0 +1,30 @@ +import { Array as RunTypesArray, Literal, Optional, Record, String, Union } from "runtypes"; +import { Reason } from "../../../types/error"; +/** + * DNS-TXT verification status + */ +export var ValidDnsTxtVerificationStatus = Record({ + status: Literal("VALID"), + location: String, + value: String, +}); +export var ValidDnsTxtVerificationStatusArray = RunTypesArray(ValidDnsTxtVerificationStatus).withConstraint(function (elements) { return elements.length > 0 || "Expect at least one valid element"; }); +export var InvalidDnsTxtVerificationStatus = Record({ + status: Literal("INVALID"), + location: Optional(String), + value: Optional(String), + reason: Reason, +}); +export var DnsTxtVerificationStatus = Union(ValidDnsTxtVerificationStatus, InvalidDnsTxtVerificationStatus); +export var DnsTxtVerificationStatusArray = RunTypesArray(DnsTxtVerificationStatus); +/** + * Data for v3 Fragments + */ +export var ValidDnsTxtVerificationStatusDataV3 = Record({ + identifier: String, + value: String, +}); +// by design runtypes will validate arrays when an object has only partial properties +// https://github.com/pelotom/runtypes/issues/32 +export var InvalidDnsTxtVerificationStatusDataV3 = ValidDnsTxtVerificationStatusDataV3.asPartial().withConstraint(function (value) { return !Array.isArray(value) || "can't be an array"; }); +export var DnsTxtVerificationStatusDataV3 = Union(ValidDnsTxtVerificationStatusDataV3, InvalidDnsTxtVerificationStatusDataV3); diff --git a/dist/esm/verifiers/verificationBuilder.js b/dist/esm/verifiers/verificationBuilder.js new file mode 100644 index 00000000..ec2fffb0 --- /dev/null +++ b/dist/esm/verifiers/verificationBuilder.js @@ -0,0 +1,33 @@ +import { getProvider } from "../common/utils"; +import { warnProvider } from "../common/messages"; +// keeping the following code for posterity. If we want the function below to return better types, we can use the following +// type PromiseValue = T extends Promise ? U : never; +// Promise>[]> +/** + * A verification manager will run a list of {@link Verifier} over a signed document. + * Before running each verifier, the manager will make sure the verifier can handle the specific document by calling its exposed test function. + * The manager will return the consolidated list of {@link VerificationFragment} + */ +var displayWarning = true; +export var verificationBuilder = function (verifiers, builderOptions) { return function (document, promisesCallback) { + // if the user didn't configure an API key and didn't configure a provider or a resolver, then he will likely use a development key. We then warn him once, that he may need to configure things properly, especially for production + if (displayWarning && + (!builderOptions.resolver || !builderOptions.provider) && + !process.env.INFURA_API_KEY && + !process.env.PROVIDER_API_KEY) { + displayWarning = false; + console.warn(warnProvider); + } + var verifierOptions = { + provider: getProvider(builderOptions), + resolver: builderOptions.resolver, + }; + var promises = verifiers.map(function (verifier) { + if (verifier.test(document, verifierOptions)) { + return verifier.verify(document, verifierOptions); + } + return verifier.skip(document, verifierOptions); + }); + promisesCallback === null || promisesCallback === void 0 ? void 0 : promisesCallback(promises); + return Promise.all(promises); +}; }; diff --git a/dist/types/src/common/error.d.ts b/dist/types/src/common/error.d.ts new file mode 100644 index 00000000..f2e9e08e --- /dev/null +++ b/dist/types/src/common/error.d.ts @@ -0,0 +1,5 @@ +export declare class CodedError extends Error { + code: number; + codeString: string; + constructor(message: string, code: number, codeString: string); +} diff --git a/dist/types/src/common/errorHandler.d.ts b/dist/types/src/common/errorHandler.d.ts new file mode 100644 index 00000000..22d8542a --- /dev/null +++ b/dist/types/src/common/errorHandler.d.ts @@ -0,0 +1,8 @@ +import { DocumentsToVerify, ErrorVerificationFragment, VerificationFragment, VerificationFragmentType, VerifierOptions } from "../types/core"; +export interface ErrorOptions { + name: string; + type: VerificationFragmentType; + unexpectedErrorCode: number; + unexpectedErrorString: string; +} +export declare const withCodedErrorHandler: Promise>(verify: T, errorOptions: ErrorOptions) => (document: DocumentsToVerify, options: VerifierOptions) => ReturnType | Promise>; diff --git a/dist/types/src/common/logger.d.ts b/dist/types/src/common/logger.d.ts new file mode 100644 index 00000000..987dfdb2 --- /dev/null +++ b/dist/types/src/common/logger.d.ts @@ -0,0 +1,10 @@ +import debug from "debug"; +interface Logger { + trace: debug.Debugger; + debug: debug.Debugger; + info: debug.Debugger; + warn: debug.Debugger; + error: debug.Debugger; +} +export declare const getLogger: (namespace: string) => Logger; +export {}; diff --git a/dist/types/src/common/messages.d.ts b/dist/types/src/common/messages.d.ts new file mode 100644 index 00000000..35eb3e12 --- /dev/null +++ b/dist/types/src/common/messages.d.ts @@ -0,0 +1 @@ +export declare const warnProvider = "You are falling back to oa-verify default configuration, which is not suitable for production environment. It is highly recommended that you configure and provide your own API key. Refer to https://github.com/Open-Attestation/oa-verify#provider"; diff --git a/dist/types/src/common/utils.d.ts b/dist/types/src/common/utils.d.ts new file mode 100644 index 00000000..be33215a --- /dev/null +++ b/dist/types/src/common/utils.d.ts @@ -0,0 +1,69 @@ +import { providers } from "ethers"; +import { VerificationBuilderOptions, VerificationBuilderOptionsWithNetwork, VerificationFragment, ProviderDetails } from "../types/core"; +import { OpenAttestationHashVerificationFragment } from "../verifiers/documentIntegrity/hash/openAttestationHash.type"; +import { OpenAttestationDidSignedDocumentStatusVerificationFragment } from "../verifiers/documentStatus/didSigned/didSignedDocumentStatus.type"; +import { OpenAttestationEthereumDocumentStoreStatusFragment } from "../verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type"; +import { OpenAttestationEthereumTokenRegistryStatusFragment } from "../verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type"; +import { OpenAttestationDidIdentityProofVerificationFragment } from "../verifiers/issuerIdentity/did/didIdentityProof.type"; +import { OpenAttestationDnsDidIdentityProofVerificationFragment } from "../verifiers/issuerIdentity/dnsDid/dnsDidProof.type"; +import { OpenAttestationDnsTxtIdentityProofVerificationFragment } from "../verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type"; +export declare const getDefaultProvider: (options: VerificationBuilderOptionsWithNetwork) => providers.Provider; +export declare const getProvider: (options: VerificationBuilderOptions) => providers.Provider; +/** + * Generate Provider generates a provider based on the defined options or your env var, if no options or env var was detected, it will generate a provider based on the default values. + * Generate Provider using the following options: (if no option is specified it will use the default values) + * @param {Object} ProviderDetails - Details to use for the function to successfully generate a provider. + * @param {string} ProviderDetails.network - The network in which the provider is connected to, i.e. "homestead", "mainnet", "ropsten", "rinkeby" + * @param {string} ProviderDetails.providerType - Specify which provider to use: "infura", "alchemy" or "jsonrpc" + * @param {string} ProviderDetails.url - Specify which url for JsonRPC to connect to, if not specified will connect to localhost:8545 + * @param {string} ProviderDetails.apiKey - If no apiKey is provided, a default shared API key will be used, which may result in reduced performance and throttled requests. + */ +export declare const generateProvider: (options?: ProviderDetails | undefined) => providers.Provider; +/** + * Simple typed utility to return a fragment depending on the name + * @param name + */ +export declare const getFragmentByName: (name: string) => (fragments: Fragment[]) => ReturnedFragment | undefined; +export declare const getOpenAttestationHashFragment: (fragments: Fragment[]) => OpenAttestationHashVerificationFragment | undefined; +export declare const getOpenAttestationDidSignedDocumentStatusFragment: (fragments: Fragment[]) => OpenAttestationDidSignedDocumentStatusVerificationFragment | undefined; +export declare const getOpenAttestationEthereumDocumentStoreStatusFragment: (fragments: Fragment[]) => OpenAttestationEthereumDocumentStoreStatusFragment | undefined; +export declare const getOpenAttestationEthereumTokenRegistryStatusFragment: (fragments: Fragment[]) => OpenAttestationEthereumTokenRegistryStatusFragment | undefined; +export declare const getOpenAttestationDidIdentityProofFragment: (fragments: Fragment[]) => OpenAttestationDidIdentityProofVerificationFragment | undefined; +export declare const getOpenAttestationDnsDidIdentityProofFragment: (fragments: Fragment[]) => OpenAttestationDnsDidIdentityProofVerificationFragment | undefined; +export declare const getOpenAttestationDnsTxtIdentityProofFragment: (fragments: Fragment[]) => OpenAttestationDnsTxtIdentityProofVerificationFragment | undefined; +export declare const getDocumentIntegrityFragments: (fragments: Fragment[]) => (Fragment & { + type: "DOCUMENT_INTEGRITY"; +})[]; +export declare const getDocumentStatusFragments: (fragments: Fragment[]) => (Fragment & { + type: "DOCUMENT_STATUS"; +})[]; +export declare const getIssuerIdentityFragments: (fragments: Fragment[]) => (Fragment & { + type: "ISSUER_IDENTITY"; +})[]; +/** + * type utilities and guard to get fragment depending on the status + */ +declare type ValidFragment = Type extends { + status: "VALID"; +} ? Type : never; +declare type InvalidFragment = Type extends { + status: "INVALID"; +} ? Type : never; +declare type SkippedFragment = Type extends { + status: "SKIPPED"; +} ? Type : never; +declare type ErrorFragment = Type extends { + status: "ERROR"; +} ? Type : never; +export declare const isValidFragment: (fragment: Fragment | undefined) => fragment is ValidFragment; +export declare const isInvalidFragment: (fragment: Fragment | undefined) => fragment is InvalidFragment; +export declare const isSkippedFragment: (fragment: Fragment | undefined) => fragment is SkippedFragment; +export declare const isErrorFragment: (fragment: Fragment | undefined) => fragment is ErrorFragment; +export declare const isDocumentStoreAddressOrTokenRegistryAddressInvalid: (fragments: VerificationFragment[]) => boolean; +export declare const contractNotFound: (fragments: VerificationFragment[]) => boolean; +export declare const certificateNotIssued: (fragments: VerificationFragment[]) => boolean; +export declare const certificateRevoked: (fragments: VerificationFragment[]) => boolean; +export declare const invalidArgument: (fragments: VerificationFragment[]) => boolean; +export declare const serverError: (fragments: VerificationFragment[]) => boolean; +export declare const unhandledError: (fragments: VerificationFragment[]) => boolean; +export {}; diff --git a/dist/types/src/common/utils.test.d.ts b/dist/types/src/common/utils.test.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/types/src/common/utils.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/types/src/config.d.ts b/dist/types/src/config.d.ts new file mode 100644 index 00000000..7f56705f --- /dev/null +++ b/dist/types/src/config.d.ts @@ -0,0 +1 @@ +export declare const INFURA_API_KEY: string; diff --git a/dist/types/src/did/resolver.d.ts b/dist/types/src/did/resolver.d.ts new file mode 100644 index 00000000..f6ae702a --- /dev/null +++ b/dist/types/src/did/resolver.d.ts @@ -0,0 +1,19 @@ +import { DIDDocument, Resolver, VerificationMethod } from "did-resolver"; +export interface EthrResolverConfig { + networks: Array<{ + name: string; + registry?: string; + rpcUrl: string; + }>; +} +export declare const getProviderConfig: () => { + networks: { + name: any; + rpcUrl: any; + }[]; +}; +export declare const createResolver: ({ ethrResolverConfig }: { + ethrResolverConfig?: EthrResolverConfig | undefined; +}) => Resolver; +export declare const resolve: (didUrl: string, resolver?: Resolver | undefined) => Promise; +export declare const getVerificationMethod: (did: string, key: string, resolver?: Resolver | undefined) => Promise; diff --git a/dist/types/src/did/resolver.test.d.ts b/dist/types/src/did/resolver.test.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/types/src/did/resolver.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/types/src/did/verifier.d.ts b/dist/types/src/did/verifier.d.ts new file mode 100644 index 00000000..08d0d16c --- /dev/null +++ b/dist/types/src/did/verifier.d.ts @@ -0,0 +1,66 @@ +import { VerificationMethod, Resolver } from "did-resolver"; +import { Literal, Record, Static, String, Union, Array as RunTypesArray } from "runtypes"; +export declare const ValidDidVerificationStatus: Record<{ + verified: Literal; + did: String; +}, false>; +export declare type ValidDidVerificationStatus = Static; +export declare const ValidDidVerificationStatusArray: import("runtypes").Constraint; + did: String; +}, false>, false>, { + did: string; + verified: true; +}[], unknown>; +export declare type ValidDidVerificationStatusArray = Static; +export declare const InvalidDidVerificationStatus: Record<{ + verified: Literal; + did: String; + reason: Record<{ + code: import("runtypes").Number; + codeString: String; + message: String; + }, false>; +}, false>; +export declare type InvalidDidVerificationStatus = Static; +export declare const DidVerificationStatus: Union<[Record<{ + verified: Literal; + did: String; +}, false>, Record<{ + verified: Literal; + did: String; + reason: Record<{ + code: import("runtypes").Number; + codeString: String; + message: String; + }, false>; +}, false>]>; +export declare type DidVerificationStatus = Static; +export declare const DidVerificationStatusArray: RunTypesArray; + did: String; +}, false>, Record<{ + verified: Literal; + did: String; + reason: Record<{ + code: import("runtypes").Number; + codeString: String; + message: String; + }, false>; +}, false>]>, false>; +export declare type DidVerificationStatusArray = Static; +interface VerifySignature { + did: string; + signature: string; + merkleRoot: string; + verificationMethod: VerificationMethod; +} +export declare const verifySecp256k1VerificationKey2018: ({ did, verificationMethod, merkleRoot, signature, }: VerifySignature) => DidVerificationStatus; +export declare const verifySignature: ({ key, merkleRoot, signature, did, resolver, }: { + key: string; + merkleRoot: string; + did: string; + signature: string; + resolver?: Resolver | undefined; +}) => Promise; +export {}; diff --git a/dist/types/src/getIdentifier.d.ts b/dist/types/src/getIdentifier.d.ts new file mode 100644 index 00000000..d5b9bfbe --- /dev/null +++ b/dist/types/src/getIdentifier.d.ts @@ -0,0 +1,8 @@ +import { AllVerificationFragment } from "./types/core"; +export declare const getIdentifier: >(fragments: T[]) => { + identifier: string | undefined; + type: string; +}[] | { + identifier: string | undefined; + type: string; +}; diff --git a/dist/types/src/getIdentifier.test.d.ts b/dist/types/src/getIdentifier.test.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/types/src/getIdentifier.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/types/src/index.d.ts b/dist/types/src/index.d.ts new file mode 100644 index 00000000..62c99519 --- /dev/null +++ b/dist/types/src/index.d.ts @@ -0,0 +1,26 @@ +import { verificationBuilder } from "./verifiers/verificationBuilder"; +import { Verifier } from "./types/core"; +import { openAttestationHash } from "./verifiers/documentIntegrity/hash/openAttestationHash"; +import { isValid } from "./validator"; +import { openAttestationEthereumTokenRegistryStatus } from "./verifiers/documentStatus/tokenRegistry"; +import { openAttestationEthereumDocumentStoreStatus } from "./verifiers/documentStatus/documentStore"; +import { openAttestationDidSignedDocumentStatus } from "./verifiers/documentStatus/didSigned"; +import { openAttestationDnsTxtIdentityProof } from "./verifiers/issuerIdentity/dnsTxt"; +import { openAttestationDidIdentityProof } from "./verifiers/issuerIdentity/did"; +import { openAttestationDnsDidIdentityProof } from "./verifiers/issuerIdentity/dnsDid"; +import { createResolver } from "./did/resolver"; +import { getIdentifier } from "./getIdentifier"; +import * as utils from "./common/utils"; +declare const openAttestationVerifiers: (Verifier | Verifier | Verifier | Verifier | Verifier | Verifier)[]; +declare const verify: (document: import("./types/core").DocumentsToVerify, promisesCallback?: import("./types/core").PromiseCallback | undefined) => Promise; +export * from "./types/core"; +export * from "./verifiers/documentIntegrity/hash/openAttestationHash.type"; +export * from "./verifiers/documentStatus/didSigned/didSignedDocumentStatus.type"; +export * from "./verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type"; +export * from "./verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type"; +export * from "./verifiers/issuerIdentity/did/didIdentityProof.type"; +export * from "./verifiers/issuerIdentity/dnsDid/dnsDidProof.type"; +export * from "./verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type"; +export * from "./types/error"; +export * from "./common/error"; +export { verificationBuilder, openAttestationVerifiers, isValid, verify, Verifier, openAttestationHash, openAttestationEthereumDocumentStoreStatus, openAttestationEthereumTokenRegistryStatus, openAttestationDidSignedDocumentStatus, openAttestationDnsTxtIdentityProof, openAttestationDnsDidIdentityProof, openAttestationDidIdentityProof, createResolver, getIdentifier, utils, }; diff --git a/dist/types/src/types/core.d.ts b/dist/types/src/types/core.d.ts new file mode 100644 index 00000000..22bc4477 --- /dev/null +++ b/dist/types/src/types/core.d.ts @@ -0,0 +1,111 @@ +import { SignedWrappedDocument, v2, v3, WrappedDocument } from "@govtechsg/open-attestation"; +import { Resolver } from "did-resolver"; +import { providers } from "ethers"; +import { OcspResponderRevocationReason, OcspResponderRevocationStatus } from "src/verifiers/documentStatus/revocation.types"; +import { Reason } from "./error"; +/** + * Callback function that will provide back the promises resolving to the verification fragment. It will be called before the promises are all resolved and thus give the possibility to consumers to perform their own extra checks. + */ +export declare type PromiseCallback = (promises: Promise[]) => void; +export interface VerificationBuilderOptionsWithProvider { + provider: providers.Provider; + resolver?: Resolver; +} +export interface VerificationBuilderOptionsWithNetwork { + network: string; + resolver?: Resolver; + provider?: never; +} +export declare type VerificationBuilderOptions = VerificationBuilderOptionsWithProvider | VerificationBuilderOptionsWithNetwork; +export interface VerifierOptions { + provider: providers.Provider; + resolver?: Resolver; +} +/** + * A verification fragment is the result of a verification + * It will *always* + * - return the status + * - VALID: when the verification is successful + * - INVALID: when the verification is unsuccessful + * - ERROR: when an unexpected error is met + * - SKIPPED: when the verification was skipped by the manager + * - return the type who indicate the kind of checks performed + * - DOCUMENT_INTEGRITY + * - DOCUMENT_STATUS + * - ISSUER_IDENTITY + * - return the name who can help to determine the verifier that created the result + * + * Additional fields might be populated + * - A reason to provide further information about the error/invalid/skipped state + * - Data to provide further information + */ +export interface VerificationFragment { + name: string; + type: VerificationFragmentType; + status: VerificationFragmentStatus; +} +export interface ValidVerificationFragment extends VerificationFragment { + status: "VALID"; + data: Data; + reason?: never; +} +export interface InvalidVerificationFragment extends VerificationFragment { + status: "INVALID"; + reason: Reason; + data: Data; +} +export interface ErrorVerificationFragment extends VerificationFragment { + status: "ERROR"; + reason: Reason; + data: Data; +} +export interface SkippedVerificationFragment extends VerificationFragment { + status: "SKIPPED"; + reason: Reason; + data?: never; +} +export declare type VerificationFragmentType = "DOCUMENT_INTEGRITY" | "DOCUMENT_STATUS" | "ISSUER_IDENTITY"; +export declare type VerificationFragmentStatus = "ERROR" | "VALID" | "INVALID" | "SKIPPED"; +/** + * type for combined verification fragments that will hold data + */ +export declare type VerificationFragmentWithData = ValidVerificationFragment | InvalidVerificationFragment | ErrorVerificationFragment; +export declare const isVerificationFragmentWithData: (fragment: any) => fragment is VerificationFragmentWithData; +/** + * type for all verification fragments + */ +export declare type AllVerificationFragment = VerificationFragmentWithData | SkippedVerificationFragment; +/** + * A verifier is an object whose goal is to perform specific validation on a signed document. It exposes + * - a *test* function, who must return true or false. The function must indicate whether condition are fulfilled for the verifier to run on a specific signed document + * - a *verify* function, who must return the result of the verification as a {@link VerificationFragment} + * - a *skip* function, who must return the result of a verification when it's skipped by providing additional data on why the validation didn't run. + */ +export interface Verifier { + skip: (document: DocumentsToVerify, options: VerifierOptions) => Promise; + test: (document: DocumentsToVerify, options: VerifierOptions) => boolean; + verify: (document: DocumentsToVerify, options: VerifierOptions) => Promise; +} +export declare type Hash = string; +export declare type DocumentsToVerify = WrappedDocument | WrappedDocument | SignedWrappedDocument; +export declare type providerType = "alchemy" | "infura" | "jsonrpc"; +export interface ProviderDetails { + network?: string; + providerType?: providerType; + url?: string; + apiKey?: string; +} +/** + * Specifies the parameters of the OCSP response + * @param {string} certificateStatus - status of the certificate {@link OcspResponderRevocationStatus} + */ +export interface OcspResponse { + certificateStatus: OcspResponderRevocationStatus; +} +/** + * Specifies the parameters of the OCSP response when document is revoked + * @param {number} reasonCode - code indicating reason for revocation {@link OcspResponderRevocationReason} + */ +export interface OcspResponseRevoked extends OcspResponse { + reasonCode: OcspResponderRevocationReason; +} diff --git a/dist/types/src/types/error.d.ts b/dist/types/src/types/error.d.ts new file mode 100644 index 00000000..45792f2d --- /dev/null +++ b/dist/types/src/types/error.d.ts @@ -0,0 +1,99 @@ +import { Number, Record, Static, String } from "runtypes"; +export declare enum OpenAttestationEthereumDocumentStoreStatusCode { + UNEXPECTED_ERROR = 0, + DOCUMENT_NOT_ISSUED = 1, + CONTRACT_ADDRESS_INVALID = 2, + ETHERS_UNHANDLED_ERROR = 3, + SKIPPED = 4, + DOCUMENT_REVOKED = 5, + INVALID_ARGUMENT = 6, + CONTRACT_NOT_FOUND = 404, + INVALID_ISSUERS = 7, + INVALID_VALIDATION_METHOD = 8, + UNRECOGNIZED_DOCUMENT = 9, + SERVER_ERROR = 500 +} +export declare enum OpenAttestationDocumentSignedCode { + UNEXPECTED_ERROR = 0, + DOCUMENT_PROOF_INVALID = 1, + DOCUMENT_PROOF_ERROR = 2, + SKIPPED = 4 +} +export declare enum OpenAttestationEthereumTokenRegistryStatusCode { + UNEXPECTED_ERROR = 0, + DOCUMENT_NOT_MINTED = 1, + CONTRACT_ADDRESS_INVALID = 2, + ETHERS_UNHANDLED_ERROR = 3, + SKIPPED = 4, + INVALID_ISSUERS = 5, + INVALID_ARGUMENT = 6, + UNDEFINED_TOKEN_REGISTRY = 7, + INVALID_VALIDATION_METHOD = 8, + UNRECOGNIZED_DOCUMENT = 9, + SERVER_ERROR = 500 +} +export declare enum OpenAttestationDnsTxtCode { + UNEXPECTED_ERROR = 0, + INVALID_IDENTITY = 1, + SKIPPED = 2, + INVALID_ISSUERS = 3, + MATCHING_RECORD_NOT_FOUND = 4, + UNRECOGNIZED_DOCUMENT = 5, + UNSUPPORTED = 6 +} +export declare enum OpenAttestationHashCode { + DOCUMENT_TAMPERED = 0, + UNEXPECTED_ERROR = 1, + SKIPPED = 2 +} +export declare enum OpenAttestationDidSignedDocumentStatusCode { + SKIPPED = 0, + UNEXPECTED_ERROR = 1, + MISSING_REVOCATION = 2, + UNSIGNED = 3, + INVALID_ISSUERS = 4, + MALFORMED_IDENTITY_PROOF = 5, + CORRESPONDING_PROOF_MISSING = 6, + DID_MISSING = 7, + UNRECOGNIZED_DOCUMENT = 8, + UNRECOGNIZED_REVOCATION_TYPE = 9, + REVOCATION_LOCATION_MISSING = 10, + OCSP_RESPONSE_INVALID = 11 +} +export declare enum OpenAttestationDidCode { + SKIPPED = 0, + UNEXPECTED_ERROR = 1, + INVALID_ISSUERS = 2, + MALFORMED_IDENTITY_PROOF = 3, + DID_MISSING = 4, + UNSIGNED = 5, + UNRECOGNIZED_DOCUMENT = 6 +} +export declare enum OpenAttestationDnsDidCode { + SKIPPED = 0, + UNEXPECTED_ERROR = 1, + MALFORMED_IDENTITY_PROOF = 2, + INVALID_ISSUERS = 3, + UNSIGNED = 4, + UNRECOGNIZED_DOCUMENT = 5, + INVALID_IDENTITY = 6 +} +export declare enum OpenAttestationSignatureCode { + UNEXPECTED_ERROR = 0, + KEY_MISSING = 1, + DID_MISSING = 3, + KEY_NOT_IN_DID = 4, + UNSUPPORTED_KEY_TYPE = 6, + WRONG_SIGNATURE = 7 +} +export interface EthersError extends Error { + reason?: string | string[]; + code?: string; + method?: string; +} +export declare const Reason: Record<{ + code: Number; + codeString: String; + message: String; +}, false>; +export declare type Reason = Static; diff --git a/dist/types/src/validator.d.ts b/dist/types/src/validator.d.ts new file mode 100644 index 00000000..2329134a --- /dev/null +++ b/dist/types/src/validator.d.ts @@ -0,0 +1,2 @@ +import { VerificationFragment, VerificationFragmentType } from "./types/core"; +export declare const isValid: (verificationFragments: VerificationFragment[], types?: VerificationFragmentType[]) => boolean; diff --git a/dist/types/src/validator.test.d.ts b/dist/types/src/validator.test.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/types/src/validator.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.d.ts b/dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.d.ts new file mode 100644 index 00000000..25b494ef --- /dev/null +++ b/dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.d.ts @@ -0,0 +1,5 @@ +import { Verifier } from "../../../types/core"; +import { OpenAttestationHashVerificationFragment } from "./openAttestationHash.type"; +declare type VerifierType = Verifier; +export declare const openAttestationHash: VerifierType; +export {}; diff --git a/dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.test.d.ts b/dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.test.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.type.d.ts b/dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.type.d.ts new file mode 100644 index 00000000..64412667 --- /dev/null +++ b/dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.type.d.ts @@ -0,0 +1,5 @@ +import { ErrorVerificationFragment, InvalidVerificationFragment, SkippedVerificationFragment, ValidVerificationFragment } from "../../../types/core"; +export declare type OpenAttestationHashValidFragment = ValidVerificationFragment; +export declare type OpenAttestationHashInvalidFragment = InvalidVerificationFragment; +export declare type OpenAttestationHashErrorFragment = ErrorVerificationFragment; +export declare type OpenAttestationHashVerificationFragment = OpenAttestationHashValidFragment | OpenAttestationHashInvalidFragment | OpenAttestationHashErrorFragment | SkippedVerificationFragment; diff --git a/dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.d.ts b/dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.d.ts new file mode 100644 index 00000000..ffb2d35d --- /dev/null +++ b/dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.d.ts @@ -0,0 +1,5 @@ +import { Verifier } from "../../../types/core"; +import { OpenAttestationDidSignedDocumentStatusVerificationFragment } from "./didSignedDocumentStatus.type"; +declare type VerifierType = Verifier; +export declare const openAttestationDidSignedDocumentStatus: VerifierType; +export {}; diff --git a/dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.test.d.ts b/dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.test.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.d.ts b/dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.d.ts new file mode 100644 index 00000000..65ee42d7 --- /dev/null +++ b/dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.d.ts @@ -0,0 +1,190 @@ +import { Array as RunTypesArray, Boolean, Literal, Record, Static, String, Union, Number } from "runtypes"; +import { ErrorVerificationFragment, InvalidVerificationFragment, SkippedVerificationFragment, ValidVerificationFragment } from "../../../types/core"; +/** + * DID signed issuance status + */ +export declare const ValidDidSignedIssuanceStatus: Record<{ + did: String; + issued: Literal; +}, false>; +export declare type ValidDidSignedIssuanceStatus = Static; +export declare const ValidDidSignedIssuanceStatusArray: RunTypesArray; +}, false>, false>; +export declare type ValidDidSignedIssuanceStatusArray = Static; +export declare const InvalidDidSignedIssuanceStatus: Record<{ + did: String; + issued: Literal; + reason: Record<{ + code: Number; + /** + * Data for v3 Fragments + */ + codeString: String; + message: String; + }, false>; +}, false>; +export declare type InvalidDidSignedIssuanceStatus = Static; +export declare const DidSignedIssuanceStatus: Union<[Record<{ + did: String; + issued: Literal; +}, false>, Record<{ + did: String; + issued: Literal; + reason: Record<{ + code: Number; + /** + * Data for v3 Fragments + */ + codeString: String; + message: String; + }, false>; +}, false>]>; +export declare type DidSignedIssuanceStatus = Static; +export declare const DidSignedIssuanceStatusArray: RunTypesArray; +}, false>, Record<{ + did: String; + issued: Literal; + reason: Record<{ + code: Number; + /** + * Data for v3 Fragments + */ + codeString: String; + message: String; + }, false>; +}, false>]>, false>; +export declare type DidSignedIssuanceStatusArray = Static; +/** + * OCSP response + */ +export declare const ValidOcspReasonCode: import("runtypes").Constraint; +export declare const ValidOcspResponse: Record<{ + certificateStatus: Union<[Literal<"good">, Literal<"revoked">, Literal<"unknown">]>; +}, false>; +export declare const ValidOcspResponseRevoked: Record<{ + reasonCode: import("runtypes").Constraint; + certificateStatus: Union<[Literal<"good">, Literal<"revoked">, Literal<"unknown">]>; +}, false>; +/** + * Data for v2 Fragments + */ +export declare const ValidDidSignedDataV2: Record<{ + issuedOnAll: Literal; + revokedOnAny: Literal; + details: Record<{ + issuance: RunTypesArray; + }, false>, false>; + revocation: RunTypesArray; + address: import("runtypes").Optional; + }, false>, false>; + }, false>; +}, false>; +export declare type ValidDidSignedDataV2 = Static; +export declare const InvalidDidSignedDataV2: Record<{ + issuedOnAll: Boolean; + revokedOnAny: Boolean; + details: Record<{ + issuance: RunTypesArray; + }, false>, Record<{ + did: String; + issued: Literal; + reason: Record<{ + code: Number; + /** + * Data for v3 Fragments + */ + codeString: String; + message: String; + }, false>; + }, false>]>, false>; + revocation: RunTypesArray; + address: import("runtypes").Optional; + }, false>, Record<{ + revoked: Literal; + address: String; + reason: Record<{ + code: Number; + /** + * Data for v3 Fragments + */ + codeString: String; + message: String; + }, false>; + }, false>]>, false>; + }, false>; +}, false>; +export declare type InvalidDidSignedDataV2 = Static; +/** + * Data for v3 Fragments + */ +export declare const ValidDidSignedDataV3: Record<{ + issuedOnAll: Literal; + revokedOnAny: Literal; + details: Record<{ + issuance: Record<{ + did: String; + issued: Literal; + }, false>; + revocation: Record<{ + revoked: Literal; + address: import("runtypes").Optional; + }, false>; + }, false>; +}, false>; +export declare type ValidDidSignedDataV3 = Static; +export declare const InvalidDidSignedDataV3: Record<{ + issuedOnAll: Boolean; + revokedOnAny: Boolean; + details: Record<{ + issuance: Union<[Record<{ + did: String; + issued: Literal; + }, false>, Record<{ + did: String; + issued: Literal; + reason: Record<{ + code: Number; + /** + * Data for v3 Fragments + */ + codeString: String; + message: String; + }, false>; + }, false>]>; + revocation: Union<[Record<{ + revoked: Literal; + address: import("runtypes").Optional; + }, false>, Record<{ + revoked: Literal; + address: String; + reason: Record<{ + code: Number; + /** + * Data for v3 Fragments + */ + codeString: String; + message: String; + }, false>; + }, false>]>; + }, false>; +}, false>; +export declare type InvalidDidSignedDataV3 = Static; +/** + * Fragments + */ +export declare type OpenAttestationDidSignedDocumentStatusValidFragmentV2 = ValidVerificationFragment; +export declare type OpenAttestationDidSignedDocumentStatusInvalidFragmentV2 = InvalidVerificationFragment; +export declare type OpenAttestationDidSignedDocumentStatusValidFragmentV3 = ValidVerificationFragment; +export declare type OpenAttestationDidSignedDocumentStatusInvalidFragmentV3 = InvalidVerificationFragment; +export declare type OpenAttestationDidSignedDocumentStatusErrorFragment = ErrorVerificationFragment; +export declare type OpenAttestationDidSignedDocumentStatusVerificationFragment = OpenAttestationDidSignedDocumentStatusValidFragmentV2 | OpenAttestationDidSignedDocumentStatusInvalidFragmentV2 | OpenAttestationDidSignedDocumentStatusValidFragmentV3 | OpenAttestationDidSignedDocumentStatusInvalidFragmentV3 | OpenAttestationDidSignedDocumentStatusErrorFragment | SkippedVerificationFragment; diff --git a/dist/types/src/verifiers/documentStatus/didSigned/index.d.ts b/dist/types/src/verifiers/documentStatus/didSigned/index.d.ts new file mode 100644 index 00000000..1c14b400 --- /dev/null +++ b/dist/types/src/verifiers/documentStatus/didSigned/index.d.ts @@ -0,0 +1 @@ +export * from "./didSignedDocumentStatus"; diff --git a/dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.d.ts b/dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.d.ts new file mode 100644 index 00000000..0dea3168 --- /dev/null +++ b/dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.d.ts @@ -0,0 +1,13 @@ +import { v2, WrappedDocument } from "@govtechsg/open-attestation"; +import { providers } from "ethers"; +import { Verifier } from "../../../types/core"; +import { DocumentStoreIssuanceStatus, OpenAttestationEthereumDocumentStoreStatusFragment } from "./ethereumDocumentStoreStatus.type"; +declare type VerifierType = Verifier; +export declare const getIssuersDocumentStores: (document: WrappedDocument) => string[]; +export declare const isIssuedOnDocumentStore: ({ documentStore, merkleRoot, provider, }: { + documentStore: string; + merkleRoot: string; + provider: providers.Provider; +}) => Promise; +export declare const openAttestationEthereumDocumentStoreStatus: VerifierType; +export {}; diff --git a/dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.test.d.ts b/dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.test.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.d.ts b/dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.d.ts new file mode 100644 index 00000000..b5150fe3 --- /dev/null +++ b/dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.d.ts @@ -0,0 +1,159 @@ +import { Array as RunTypesArray, Boolean, Literal, Optional, Record, Static, String, Union } from "runtypes"; +import { ErrorVerificationFragment, InvalidVerificationFragment, SkippedVerificationFragment, ValidVerificationFragment } from "../../../types/core"; +/** + * Document store issuance status + */ +export declare const ValidDocumentStoreIssuanceStatus: Record<{ + issued: Literal; + address: String; +}, false>; +export declare type ValidDocumentStoreIssuanceStatus = Static; +export declare const ValidDocumentStoreIssuanceStatusArray: RunTypesArray; + address: String; +}, false>, false>; +export declare type ValidDocumentStoreIssuanceStatusArray = Static; +export declare const InvalidDocumentStoreIssuanceStatus: Record<{ + issued: Literal; + address: String; + reason: Record<{ + code: import("runtypes").Number; + codeString: String; + message: String; + }, false>; +}, false>; +export declare type InvalidDocumentStoreIssuanceStatus = Static; +export declare const DocumentStoreIssuanceStatus: Union<[Record<{ + issued: Literal; + address: String; +}, false>, Record<{ + issued: Literal; + address: String; + reason: Record<{ + code: import("runtypes").Number; + codeString: String; + message: String; + }, false>; +}, false>]>; +export declare type DocumentStoreIssuanceStatus = Static; +export declare const DocumentStoreIssuanceStatusArray: RunTypesArray; + address: String; +}, false>, Record<{ + issued: Literal; + address: String; + reason: Record<{ + code: import("runtypes").Number; + codeString: String; + message: String; + }, false>; +}, false>]>, false>; +export declare type DocumentStoreIssuanceStatusArray = Static; +/** + * Data for v2 Fragments + */ +declare const ValidDocumentStoreDataV2: Record<{ + issuedOnAll: Literal; + revokedOnAny: Literal; + details: Record<{ + issuance: RunTypesArray; + address: String; + }, false>, false>; + revocation: RunTypesArray; + address: Optional; + }, false>, false>; + }, false>; +}, false>; +export declare type ValidDocumentStoreDataV2 = Static; +export declare const InvalidDocumentStoreDataV2: Record<{ + issuedOnAll: Boolean; + revokedOnAny: Optional; + details: Record<{ + issuance: RunTypesArray; + address: String; + }, false>, Record<{ + issued: Literal; + address: String; + reason: Record<{ + code: import("runtypes").Number; + codeString: String; + message: String; + }, false>; + }, false>]>, false>; + revocation: Optional; + address: Optional; + }, false>, Record<{ + revoked: Literal; + address: String; + reason: Record<{ + code: import("runtypes").Number; + codeString: String; + message: String; + }, false>; + }, false>]>, false>>; + }, false>; +}, false>; +export declare type InvalidDocumentStoreDataV2 = Static; +/** + * Data for v3 Fragments + */ +export declare const ValidDocumentStoreDataV3: Record<{ + issuedOnAll: Literal; + revokedOnAny: Literal; + details: Record<{ + issuance: Record<{ + issued: Literal; + address: String; + }, false>; + revocation: Record<{ + revoked: Literal; + address: Optional; + }, false>; + }, false>; +}, false>; +export declare type ValidDocumentStoreDataV3 = Static; +export declare const InvalidDocumentStoreDataV3: Record<{ + issuedOnAll: Boolean; + revokedOnAny: Boolean; + details: Record<{ + issuance: Union<[Record<{ + issued: Literal; + address: String; + }, false>, Record<{ + issued: Literal; + address: String; + reason: Record<{ + code: import("runtypes").Number; + codeString: String; + message: String; + }, false>; + }, false>]>; + revocation: Union<[Record<{ + revoked: Literal; + address: Optional; + }, false>, Record<{ + revoked: Literal; + address: String; + reason: Record<{ + code: import("runtypes").Number; + codeString: String; + message: String; + }, false>; + }, false>]>; + }, false>; +}, false>; +export declare type InvalidDocumentStoreDataV3 = Static; +/** + * Fragments + */ +export declare type OpenAttestationEthereumDocumentStoreStatusFragmentValidFragmentV2 = ValidVerificationFragment; +export declare type OpenAttestationEthereumDocumentStoreStatusFragmentInvalidFragmentV2 = InvalidVerificationFragment; +export declare type OpenAttestationEthereumDocumentStoreStatusFragmentValidFragmentV3 = ValidVerificationFragment; +export declare type OpenAttestationEthereumDocumentStoreStatusFragmentInvalidFragmentV3 = InvalidVerificationFragment; +export declare type OpenAttestationEthereumDocumentStoreStatusErrorFragment = ErrorVerificationFragment; +export declare type OpenAttestationEthereumDocumentStoreStatusFragment = OpenAttestationEthereumDocumentStoreStatusFragmentValidFragmentV2 | OpenAttestationEthereumDocumentStoreStatusFragmentInvalidFragmentV2 | OpenAttestationEthereumDocumentStoreStatusFragmentValidFragmentV3 | OpenAttestationEthereumDocumentStoreStatusFragmentInvalidFragmentV3 | OpenAttestationEthereumDocumentStoreStatusErrorFragment | SkippedVerificationFragment; +export {}; diff --git a/dist/types/src/verifiers/documentStatus/documentStore/index.d.ts b/dist/types/src/verifiers/documentStatus/documentStore/index.d.ts new file mode 100644 index 00000000..51a171e5 --- /dev/null +++ b/dist/types/src/verifiers/documentStatus/documentStore/index.d.ts @@ -0,0 +1 @@ +export * from "./ethereumDocumentStoreStatus"; diff --git a/dist/types/src/verifiers/documentStatus/revocation.types.d.ts b/dist/types/src/verifiers/documentStatus/revocation.types.d.ts new file mode 100644 index 00000000..4c07c1c2 --- /dev/null +++ b/dist/types/src/verifiers/documentStatus/revocation.types.d.ts @@ -0,0 +1,61 @@ +import { Literal, Record, Static, String, Union, Array as RunTypesArray, Optional } from "runtypes"; +export declare const ValidRevocationStatus: Record<{ + revoked: Literal; + address: Optional; +}, false>; +export declare type ValidRevocationStatus = Static; +export declare const ValidRevocationStatusArray: RunTypesArray; + address: Optional; +}, false>, false>; +export declare type ValidRevocationStatusArray = Static; +export declare const InvalidRevocationStatus: Record<{ + revoked: Literal; + address: String; + reason: Record<{ + code: import("runtypes").Number; + codeString: String; + message: String; + }, false>; +}, false>; +export declare type InvalidRevocationStatus = Static; +export declare const RevocationStatus: Union<[Record<{ + revoked: Literal; + address: Optional; +}, false>, Record<{ + revoked: Literal; + address: String; + reason: Record<{ + code: import("runtypes").Number; + codeString: String; + message: String; + }, false>; +}, false>]>; +export declare type RevocationStatus = Static; +export declare const RevocationStatusArray: RunTypesArray; + address: Optional; +}, false>, Record<{ + revoked: Literal; + address: String; + reason: Record<{ + code: import("runtypes").Number; + codeString: String; + message: String; + }, false>; +}, false>]>, false>; +export declare type RevocationStatusArray = Static; +export declare const OcspResponderRevocationStatus: Union<[Literal<"good">, Literal<"revoked">, Literal<"unknown">]>; +export declare type OcspResponderRevocationStatus = Static; +export declare enum OcspResponderRevocationReason { + UNSPECIFIED = 0, + KEY_COMPROMISE = 1, + CA_COMPROMISE = 2, + AFFILIATION_CHANGED = 3, + SUPERSEDED = 4, + CESSATION_OF_OPERATION = 5, + CERTIFICATE_HOLD = 6, + REMOVE_FROM_CRL = 8, + PRIVILEGE_WITHDRAWN = 9, + A_A_COMPROMISE = 10 +} diff --git a/dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.d.ts b/dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.d.ts new file mode 100644 index 00000000..ab9471ed --- /dev/null +++ b/dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.d.ts @@ -0,0 +1,11 @@ +import { v2, v3, WrappedDocument } from "@govtechsg/open-attestation"; +import { providers } from "ethers"; +import { Verifier } from "../../../types/core"; +import { InvalidTokenRegistryStatus, OpenAttestationEthereumTokenRegistryStatusFragment, ValidTokenRegistryStatus } from "./ethereumTokenRegistryStatus.type"; +export declare const getTokenRegistry: (document: WrappedDocument | WrappedDocument) => string; +export declare const isTokenMintedOnRegistry: ({ tokenRegistry, merkleRoot, provider, }: { + tokenRegistry: string; + merkleRoot: string; + provider: providers.Provider; +}) => Promise; +export declare const openAttestationEthereumTokenRegistryStatus: Verifier; diff --git a/dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.test.d.ts b/dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.test.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.d.ts b/dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.d.ts new file mode 100644 index 00000000..03eb8927 --- /dev/null +++ b/dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.d.ts @@ -0,0 +1,80 @@ +import { Array as RunTypesArray, Literal, Record, Static, String, Union } from "runtypes"; +import { ErrorVerificationFragment, InvalidVerificationFragment, SkippedVerificationFragment, ValidVerificationFragment } from "../../../types/core"; +/** + * Token registry mint status + */ +export declare const ValidTokenRegistryStatus: Record<{ + minted: Literal; + address: String; +}, false>; +export declare type ValidTokenRegistryStatus = Static; +export declare const InvalidTokenRegistryStatus: Record<{ + minted: Literal; + address: String; + reason: Record<{ + code: import("runtypes").Number; + codeString: String; + message: String; + }, false>; +}, false>; +export declare type InvalidTokenRegistryStatus = Static; +/** + * Data for v2 Fragments + */ +export declare const ValidTokenRegistryDataV2: Record<{ + mintedOnAll: Literal; + details: RunTypesArray; + address: String; + }, false>, false>; +}, false>; +export declare type ValidTokenRegistryDataV2 = Static; +export declare const InvalidTokenRegistryDataV2: Record<{ + mintedOnAll: Literal; + details: RunTypesArray; + address: String; + }, false>, Record<{ + minted: Literal; + address: String; + reason: Record<{ + code: import("runtypes").Number; + codeString: String; + message: String; + }, false>; + }, false>]>, false>; +}, false>; +export declare type InvalidTokenRegistryDataV2 = Static; +/** + * Data for v3 Fragments + */ +export declare const ValidTokenRegistryDataV3: Record<{ + mintedOnAll: Literal; + details: Record<{ + minted: Literal; + address: String; + }, false>; +}, false>; +export declare type ValidTokenRegistryDataV3 = Static; +export declare const InvalidTokenRegistryDataV3: Record<{ + mintedOnAll: Literal; + details: Record<{ + minted: Literal; + address: String; + reason: Record<{ + code: import("runtypes").Number; + codeString: String; + message: String; + }, false>; + }, false>; +}, false>; +export declare type InvalidTokenRegistryDataV3 = Static; +/** + * Fragments + */ +export declare type OpenAttestationEthereumTokenRegistryStatusValidFragmentV2 = ValidVerificationFragment; +export declare type OpenAttestationEthereumTokenRegistryStatusValidFragmentV3 = ValidVerificationFragment; +export declare type OpenAttestationEthereumTokenRegistryStatusInvalidFragmentV2 = InvalidVerificationFragment; +export declare type OpenAttestationEthereumTokenRegistryStatusInvalidFragmentV3 = InvalidVerificationFragment; +export declare type OpenAttestationEthereumTokenRegistryStatusErrorFragment = ErrorVerificationFragment; +export declare type OpenAttestationEthereumTokenRegistryStatusFragment = OpenAttestationEthereumTokenRegistryStatusValidFragmentV2 | OpenAttestationEthereumTokenRegistryStatusValidFragmentV3 | OpenAttestationEthereumTokenRegistryStatusInvalidFragmentV2 | OpenAttestationEthereumTokenRegistryStatusInvalidFragmentV3 | OpenAttestationEthereumTokenRegistryStatusErrorFragment | SkippedVerificationFragment; diff --git a/dist/types/src/verifiers/documentStatus/tokenRegistry/index.d.ts b/dist/types/src/verifiers/documentStatus/tokenRegistry/index.d.ts new file mode 100644 index 00000000..45f2ecca --- /dev/null +++ b/dist/types/src/verifiers/documentStatus/tokenRegistry/index.d.ts @@ -0,0 +1 @@ +export * from "./ethereumTokenRegistryStatus"; diff --git a/dist/types/src/verifiers/documentStatus/utils.d.ts b/dist/types/src/verifiers/documentStatus/utils.d.ts new file mode 100644 index 00000000..e5a9fa7c --- /dev/null +++ b/dist/types/src/verifiers/documentStatus/utils.d.ts @@ -0,0 +1,26 @@ +import { DocumentStore } from "@govtechsg/document-store"; +import { providers } from "ethers"; +import { Hash } from "../../types/core"; +import { RevocationStatus } from "./revocation.types"; +export declare const getIntermediateHashes: (targetHash: Hash, proofs?: Hash[]) => string[]; +/** + * Try to decode the error to see if we can deterministically tell if the document has NOT been issued or revoked. + * + * In case where we cannot tell, we throw an error + * */ +export declare const decodeError: (error: any) => "Invalid document store address" | "Contract is not found" | "Invalid call arguments" | "ENS name is not configured" | "Bad document store address checksum" | "ENS name is not found"; +/** + * Given a list of hashes, check against one smart contract if any of the hash has been revoked + * */ +export declare const isAnyHashRevoked: (smartContract: DocumentStore, intermediateHashes: Hash[]) => Promise; +export declare const isRevokedByOcspResponder: ({ certificateId, location, }: { + certificateId: string; + location: string; +}) => Promise; +export declare const isRevokedOnDocumentStore: ({ documentStore, merkleRoot, provider, targetHash, proofs, }: { + documentStore: string; + merkleRoot: string; + provider: providers.Provider; + targetHash: Hash; + proofs?: string[] | undefined; +}) => Promise; diff --git a/dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.d.ts b/dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.d.ts new file mode 100644 index 00000000..a2c6c2df --- /dev/null +++ b/dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.d.ts @@ -0,0 +1,5 @@ +import { Verifier } from "../../../types/core"; +import { OpenAttestationDidIdentityProofVerificationFragment } from "./didIdentityProof.type"; +declare type VerifierType = Verifier; +export declare const openAttestationDidIdentityProof: VerifierType; +export {}; diff --git a/dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.test.d.ts b/dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.test.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.type.d.ts b/dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.type.d.ts new file mode 100644 index 00000000..3dd82476 --- /dev/null +++ b/dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.type.d.ts @@ -0,0 +1,11 @@ +import { ErrorVerificationFragment, InvalidVerificationFragment, SkippedVerificationFragment, ValidVerificationFragment } from "../../../types/core"; +import { DidVerificationStatusArray, InvalidDidVerificationStatus, ValidDidVerificationStatus, ValidDidVerificationStatusArray } from "../../../did/verifier"; +/** + * Fragments + */ +export declare type OpenAttestationDidIdentityProofValidFragmentV3 = ValidVerificationFragment; +export declare type OpenAttestationDidIdentityProofInvalidFragmentV3 = InvalidVerificationFragment; +export declare type OpenAttestationDidIdentityProofValidFragmentV2 = ValidVerificationFragment; +export declare type OpenAttestationDidIdentityProofInvalidFragmentV2 = InvalidVerificationFragment; +export declare type OpenAttestationDidIdentityProofErrorFragment = ErrorVerificationFragment; +export declare type OpenAttestationDidIdentityProofVerificationFragment = OpenAttestationDidIdentityProofValidFragmentV2 | OpenAttestationDidIdentityProofInvalidFragmentV2 | OpenAttestationDidIdentityProofValidFragmentV3 | OpenAttestationDidIdentityProofInvalidFragmentV3 | OpenAttestationDidIdentityProofErrorFragment | SkippedVerificationFragment; diff --git a/dist/types/src/verifiers/issuerIdentity/did/index.d.ts b/dist/types/src/verifiers/issuerIdentity/did/index.d.ts new file mode 100644 index 00000000..cd1e1bb4 --- /dev/null +++ b/dist/types/src/verifiers/issuerIdentity/did/index.d.ts @@ -0,0 +1 @@ +export * from "./didIdentityProof"; diff --git a/dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.d.ts b/dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.d.ts new file mode 100644 index 00000000..d29be50f --- /dev/null +++ b/dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.d.ts @@ -0,0 +1,5 @@ +import { Verifier } from "../../../types/core"; +import { OpenAttestationDnsDidIdentityProofVerificationFragment } from "./dnsDidProof.type"; +declare type VerifierType = Verifier; +export declare const openAttestationDnsDidIdentityProof: VerifierType; +export {}; diff --git a/dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.test.d.ts b/dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.test.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.d.ts b/dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.d.ts new file mode 100644 index 00000000..e24b3c80 --- /dev/null +++ b/dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.d.ts @@ -0,0 +1,56 @@ +import { Array as RunTypesArray, Literal, Record, Static, String, Union } from "runtypes"; +import { ErrorVerificationFragment, InvalidVerificationFragment, SkippedVerificationFragment, ValidVerificationFragment } from "../../../types/core"; +/** + * DNS-DID verification status + */ +export declare const ValidDnsDidVerificationStatus: Record<{ + status: Literal<"VALID">; + location: String; + key: String; +}, false>; +export declare type ValidDnsDidVerificationStatus = Static; +export declare const ValidDnsDidVerificationStatusArray: import("runtypes").Constraint; + location: String; + key: String; +}, false>, false>, { + status: "VALID"; + location: string; + key: string; +}[], unknown>; +export declare type ValidDnsDidVerificationStatusArray = Static; +export declare const InvalidDnsDidVerificationStatus: Record<{ + status: Literal<"INVALID">; + location: String; + key: String; +}, false>; +export declare type InvalidDnsDidVerificationStatus = Static; +export declare const DnsDidVerificationStatus: Union<[Record<{ + status: Literal<"VALID">; + location: String; + key: String; +}, false>, Record<{ + status: Literal<"INVALID">; + location: String; + key: String; +}, false>]>; +export declare type DnsDidVerificationStatus = Static; +export declare const DnsDidVerificationStatusArray: RunTypesArray; + location: String; + key: String; +}, false>, Record<{ + status: Literal<"INVALID">; + location: String; + key: String; +}, false>]>, false>; +export declare type DnsDidVerificationStatusArray = Static; +/** + * Fragments + */ +export declare type OpenAttestationDnsDidIdentityProofValidFragmentV3 = ValidVerificationFragment; +export declare type OpenAttestationDnsDidIdentityProofInvalidFragmentV3 = InvalidVerificationFragment; +export declare type OpenAttestationDnsDidIdentityProofValidFragmentV2 = ValidVerificationFragment; +export declare type OpenAttestationDnsDidIdentityProofInvalidFragmentV2 = InvalidVerificationFragment; +export declare type OpenAttestationDnsDidIdentityProofErrorFragment = ErrorVerificationFragment; +export declare type OpenAttestationDnsDidIdentityProofVerificationFragment = OpenAttestationDnsDidIdentityProofValidFragmentV2 | OpenAttestationDnsDidIdentityProofInvalidFragmentV2 | OpenAttestationDnsDidIdentityProofValidFragmentV3 | OpenAttestationDnsDidIdentityProofInvalidFragmentV3 | OpenAttestationDnsDidIdentityProofErrorFragment | SkippedVerificationFragment; diff --git a/dist/types/src/verifiers/issuerIdentity/dnsDid/index.d.ts b/dist/types/src/verifiers/issuerIdentity/dnsDid/index.d.ts new file mode 100644 index 00000000..5433c63d --- /dev/null +++ b/dist/types/src/verifiers/issuerIdentity/dnsDid/index.d.ts @@ -0,0 +1 @@ +export * from "./dnsDidProof"; diff --git a/dist/types/src/verifiers/issuerIdentity/dnsTxt/index.d.ts b/dist/types/src/verifiers/issuerIdentity/dnsTxt/index.d.ts new file mode 100644 index 00000000..3d32f907 --- /dev/null +++ b/dist/types/src/verifiers/issuerIdentity/dnsTxt/index.d.ts @@ -0,0 +1 @@ +export * from "./openAttestationDnsTxt"; diff --git a/dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.d.ts b/dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.d.ts new file mode 100644 index 00000000..f37826f2 --- /dev/null +++ b/dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.d.ts @@ -0,0 +1,3 @@ +import { Verifier } from "../../../types/core"; +import { OpenAttestationDnsTxtIdentityProofVerificationFragment } from "./openAttestationDnsTxt.type"; +export declare const openAttestationDnsTxtIdentityProof: Verifier; diff --git a/dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.test.d.ts b/dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.test.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.d.ts b/dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.d.ts new file mode 100644 index 00000000..cc460dec --- /dev/null +++ b/dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.d.ts @@ -0,0 +1,97 @@ +import { Array as RunTypesArray, Literal, Optional, Record, Static, String, Union } from "runtypes"; +import { ErrorVerificationFragment, InvalidVerificationFragment, SkippedVerificationFragment, ValidVerificationFragment } from "../../../types/core"; +/** + * DNS-TXT verification status + */ +export declare const ValidDnsTxtVerificationStatus: Record<{ + status: Literal<"VALID">; + location: String; + value: String; +}, false>; +export declare type ValidDnsTxtVerificationStatus = Static; +export declare const ValidDnsTxtVerificationStatusArray: import("runtypes").Constraint; + location: String; + value: String; +}, false>, false>, { + status: "VALID"; + location: string; + value: string; +}[], unknown>; +export declare type ValidDnsTxtVerificationStatusArray = Static; +export declare const InvalidDnsTxtVerificationStatus: Record<{ + status: Literal<"INVALID">; + location: Optional; + value: Optional; + reason: Record<{ + code: import("runtypes").Number; + codeString: String; + message: String; + }, false>; +}, false>; +export declare type InvalidDnsTxtVerificationStatus = Static; +export declare const DnsTxtVerificationStatus: Union<[Record<{ + status: Literal<"VALID">; + location: String; + value: String; +}, false>, Record<{ + status: Literal<"INVALID">; + location: Optional; + value: Optional; + reason: Record<{ + code: import("runtypes").Number; + codeString: String; + message: String; + }, false>; +}, false>]>; +export declare type DnsTxtVerificationStatus = Static; +export declare const DnsTxtVerificationStatusArray: RunTypesArray; + location: String; + value: String; +}, false>, Record<{ + status: Literal<"INVALID">; + location: Optional; + value: Optional; + reason: Record<{ + code: import("runtypes").Number; + codeString: String; + message: String; + }, false>; +}, false>]>, false>; +export declare type DnsTxtVerificationStatusArray = Static; +/** + * Data for v3 Fragments + */ +export declare const ValidDnsTxtVerificationStatusDataV3: Record<{ + identifier: String; + value: String; +}, false>; +export declare type ValidDnsTxtVerificationStatusDataV3 = Static; +export declare const InvalidDnsTxtVerificationStatusDataV3: import("runtypes").Constraint, { + identifier?: string | undefined; + value?: string | undefined; +}, unknown>; +export declare type InvalidDnsTxtVerificationStatusDataV3 = Static; +export declare const DnsTxtVerificationStatusDataV3: Union<[Record<{ + identifier: String; + value: String; +}, false>, import("runtypes").Constraint, { + identifier?: string | undefined; + value?: string | undefined; +}, unknown>]>; +export declare type DnsTxtVerificationStatusDataV3 = Static; +/** + * Fragments + */ +export declare type OpenAttestationDnsTxtIdentityProofValidFragmentV2 = ValidVerificationFragment; +export declare type OpenAttestationDnsTxtIdentityProofInvalidFragmentV2 = InvalidVerificationFragment; +export declare type OpenAttestationDnsTxtIdentityProofValidFragmentV3 = ValidVerificationFragment; +export declare type OpenAttestationDnsTxtIdentityProofInvalidFragmentV3 = InvalidVerificationFragment; +export declare type OpenAttestationDnsTxtIdentityProofVerificationFragment = OpenAttestationDnsTxtIdentityProofValidFragmentV2 | OpenAttestationDnsTxtIdentityProofInvalidFragmentV2 | OpenAttestationDnsTxtIdentityProofValidFragmentV3 | OpenAttestationDnsTxtIdentityProofInvalidFragmentV3 | ErrorVerificationFragment | SkippedVerificationFragment; diff --git a/dist/types/src/verifiers/verificationBuilder.d.ts b/dist/types/src/verifiers/verificationBuilder.d.ts new file mode 100644 index 00000000..64517102 --- /dev/null +++ b/dist/types/src/verifiers/verificationBuilder.d.ts @@ -0,0 +1,2 @@ +import { VerificationBuilderOptions, VerificationFragment, PromiseCallback, Verifier, DocumentsToVerify } from "../types/core"; +export declare const verificationBuilder: >(verifiers: T[], builderOptions: VerificationBuilderOptions) => (document: DocumentsToVerify, promisesCallback?: PromiseCallback | undefined) => Promise; diff --git a/dist/types/src/verify.v2.integration.errors.test.d.ts b/dist/types/src/verify.v2.integration.errors.test.d.ts new file mode 100644 index 00000000..3275561c --- /dev/null +++ b/dist/types/src/verify.v2.integration.errors.test.d.ts @@ -0,0 +1,4 @@ +/** + * @jest-environment node + */ +export {}; diff --git a/dist/types/src/verify.v2.integration.test.d.ts b/dist/types/src/verify.v2.integration.test.d.ts new file mode 100644 index 00000000..3275561c --- /dev/null +++ b/dist/types/src/verify.v2.integration.test.d.ts @@ -0,0 +1,4 @@ +/** + * @jest-environment node + */ +export {}; diff --git a/dist/types/src/verify.v3.integration.test.d.ts b/dist/types/src/verify.v3.integration.test.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/dist/types/src/verify.v3.integration.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/types/test/fixtures/v2/document.d.ts b/dist/types/test/fixtures/v2/document.d.ts new file mode 100644 index 00000000..c8e98b89 --- /dev/null +++ b/dist/types/test/fixtures/v2/document.d.ts @@ -0,0 +1,18 @@ +import { v2, WrappedDocument } from "@govtechsg/open-attestation"; +interface CustomDocument extends v2.OpenAttestationDocument { + name: string; + issuedOn: string; + transcript: any; + issuers: { + url: string; + name: string; + certificateStore: string; + }[]; + recipient: { + name: string; + email: string; + phone: string; + }; +} +export declare const document: WrappedDocument; +export {}; diff --git a/dist/types/test/fixtures/v2/documentDidCustomRevocation.d.ts b/dist/types/test/fixtures/v2/documentDidCustomRevocation.d.ts new file mode 100644 index 00000000..046b27b3 --- /dev/null +++ b/dist/types/test/fixtures/v2/documentDidCustomRevocation.d.ts @@ -0,0 +1 @@ +export declare const documentDidCustomRevocation: any; diff --git a/dist/types/test/fixtures/v2/documentDidMissingProof.d.ts b/dist/types/test/fixtures/v2/documentDidMissingProof.d.ts new file mode 100644 index 00000000..1cf8d01b --- /dev/null +++ b/dist/types/test/fixtures/v2/documentDidMissingProof.d.ts @@ -0,0 +1 @@ +export declare const documentDidMissingProof: any; diff --git a/dist/types/test/fixtures/v2/documentDidMixedTokenRegistry.d.ts b/dist/types/test/fixtures/v2/documentDidMixedTokenRegistry.d.ts new file mode 100644 index 00000000..4488ccc0 --- /dev/null +++ b/dist/types/test/fixtures/v2/documentDidMixedTokenRegistry.d.ts @@ -0,0 +1 @@ +export declare const documentDidMixedTokenRegistry: any; diff --git a/dist/types/test/fixtures/v2/documentDidObfuscatedRevocation.d.ts b/dist/types/test/fixtures/v2/documentDidObfuscatedRevocation.d.ts new file mode 100644 index 00000000..ade92e65 --- /dev/null +++ b/dist/types/test/fixtures/v2/documentDidObfuscatedRevocation.d.ts @@ -0,0 +1 @@ +export declare const documentDidObfuscatedRevocation: any; diff --git a/dist/types/test/fixtures/v2/documentDidSigned.d.ts b/dist/types/test/fixtures/v2/documentDidSigned.d.ts new file mode 100644 index 00000000..d940c024 --- /dev/null +++ b/dist/types/test/fixtures/v2/documentDidSigned.d.ts @@ -0,0 +1 @@ +export declare const documentDidSigned: any; diff --git a/dist/types/test/fixtures/v2/documentDidWrongSignature.d.ts b/dist/types/test/fixtures/v2/documentDidWrongSignature.d.ts new file mode 100644 index 00000000..9a8dbe42 --- /dev/null +++ b/dist/types/test/fixtures/v2/documentDidWrongSignature.d.ts @@ -0,0 +1 @@ +export declare const documentDidWrongSignature: any; diff --git a/dist/types/test/fixtures/v2/documentDnsDidMixedTokenRegistry.d.ts b/dist/types/test/fixtures/v2/documentDnsDidMixedTokenRegistry.d.ts new file mode 100644 index 00000000..fac7eceb --- /dev/null +++ b/dist/types/test/fixtures/v2/documentDnsDidMixedTokenRegistry.d.ts @@ -0,0 +1,2 @@ +export declare const documentDnsDidMixedTokenRegistryInvalid: any; +export declare const documentDnsDidMixedTokenRegistryValid: any; diff --git a/dist/types/test/fixtures/v2/documentDnsDidNoDnsTxt.d.ts b/dist/types/test/fixtures/v2/documentDnsDidNoDnsTxt.d.ts new file mode 100644 index 00000000..42d6a726 --- /dev/null +++ b/dist/types/test/fixtures/v2/documentDnsDidNoDnsTxt.d.ts @@ -0,0 +1 @@ +export declare const documentDnsDidNoDnsTxt: any; diff --git a/dist/types/test/fixtures/v2/documentDnsDidSigned.d.ts b/dist/types/test/fixtures/v2/documentDnsDidSigned.d.ts new file mode 100644 index 00000000..ba868fd5 --- /dev/null +++ b/dist/types/test/fixtures/v2/documentDnsDidSigned.d.ts @@ -0,0 +1 @@ +export declare const documentDnsDidSigned: any; diff --git a/dist/types/test/fixtures/v2/documentMainnetInvalidWithIncorrectMerkleRoot.d.ts b/dist/types/test/fixtures/v2/documentMainnetInvalidWithIncorrectMerkleRoot.d.ts new file mode 100644 index 00000000..9e11a422 --- /dev/null +++ b/dist/types/test/fixtures/v2/documentMainnetInvalidWithIncorrectMerkleRoot.d.ts @@ -0,0 +1,15 @@ +import { v2, WrappedDocument } from "@govtechsg/open-attestation"; +interface CustomDocument extends v2.OpenAttestationDocument { + recipient: { + name: string; + address: { + street: string; + country: string; + }; + }; + certification: any; + consignment: any; + declaration: any; +} +export declare const documentMainnetInvalidWithIncorrectMerkleRoot: WrappedDocument; +export {}; diff --git a/dist/types/test/fixtures/v2/documentMainnetInvalidWithOddLengthMerkleRoot.d.ts b/dist/types/test/fixtures/v2/documentMainnetInvalidWithOddLengthMerkleRoot.d.ts new file mode 100644 index 00000000..afa175f4 --- /dev/null +++ b/dist/types/test/fixtures/v2/documentMainnetInvalidWithOddLengthMerkleRoot.d.ts @@ -0,0 +1,15 @@ +import { v2, WrappedDocument } from "@govtechsg/open-attestation"; +interface CustomDocument extends v2.OpenAttestationDocument { + recipient: { + name: string; + address: { + street: string; + country: string; + }; + }; + certification: any; + consignment: any; + declaration: any; +} +export declare const documentMainnetInvalidWithOddLengthMerkleRoot: WrappedDocument; +export {}; diff --git a/dist/types/test/fixtures/v2/documentMainnetValidWithCertificateStore.d.ts b/dist/types/test/fixtures/v2/documentMainnetValidWithCertificateStore.d.ts new file mode 100644 index 00000000..4fc2b4cd --- /dev/null +++ b/dist/types/test/fixtures/v2/documentMainnetValidWithCertificateStore.d.ts @@ -0,0 +1,11 @@ +import { v2, WrappedDocument } from "@govtechsg/open-attestation"; +interface CustomDocument extends v2.OpenAttestationDocument { + name: string; + issuedOn: string; + $template: string; + recipient: { + name: string; + }; +} +export declare const documentMainnetValidWithCertificateStore: WrappedDocument; +export {}; diff --git a/dist/types/test/fixtures/v2/documentRinkebyWithDocumentStore.d.ts b/dist/types/test/fixtures/v2/documentRinkebyWithDocumentStore.d.ts new file mode 100644 index 00000000..37275b44 --- /dev/null +++ b/dist/types/test/fixtures/v2/documentRinkebyWithDocumentStore.d.ts @@ -0,0 +1,7 @@ +import { v2, WrappedDocument } from "@govtechsg/open-attestation"; +interface CustomDocument extends v2.OpenAttestationDocument { + name: string; +} +export declare const documentRinkebyValidWithDocumentStore: WrappedDocument; +export declare const documentRinkebyRevokedWithDocumentStore: WrappedDocument; +export {}; diff --git a/dist/types/test/fixtures/v2/documentRopstenMixedIssuance.d.ts b/dist/types/test/fixtures/v2/documentRopstenMixedIssuance.d.ts new file mode 100644 index 00000000..3da1e594 --- /dev/null +++ b/dist/types/test/fixtures/v2/documentRopstenMixedIssuance.d.ts @@ -0,0 +1 @@ +export declare const documentRopstenMixedIssuance: any; diff --git a/dist/types/test/fixtures/v2/documentRopstenNotIssuedWithCertificateStore.d.ts b/dist/types/test/fixtures/v2/documentRopstenNotIssuedWithCertificateStore.d.ts new file mode 100644 index 00000000..0ec5b8eb --- /dev/null +++ b/dist/types/test/fixtures/v2/documentRopstenNotIssuedWithCertificateStore.d.ts @@ -0,0 +1,24 @@ +import { v2, WrappedDocument } from "@govtechsg/open-attestation"; +interface CustomDocument extends v2.OpenAttestationDocument { + name: string; + issuedOn: string; + description: string; + admissionDate: string; + graduationDate: string; + transcript: any; + cumulativeScore: string; + additionalData: any; + issuers: { + url: string; + name: string; + certificateStore: string; + uen: string; + email: string; + }[]; + recipient: { + name: string; + nric: string; + }; +} +export declare const documentRopstenNotIssuedWithCertificateStore: WrappedDocument; +export {}; diff --git a/dist/types/test/fixtures/v2/documentRopstenNotIssuedWithDocumentStore.d.ts b/dist/types/test/fixtures/v2/documentRopstenNotIssuedWithDocumentStore.d.ts new file mode 100644 index 00000000..a75b495c --- /dev/null +++ b/dist/types/test/fixtures/v2/documentRopstenNotIssuedWithDocumentStore.d.ts @@ -0,0 +1,14 @@ +import { v2, WrappedDocument } from "@govtechsg/open-attestation"; +interface CustomDocument extends v2.OpenAttestationDocument { + recipient: { + name: string; + address: { + street: string; + country: string; + }; + }; + consignment: any; + declaration: any; +} +export declare const documentRopstenNotIssuedWithDocumentStore: WrappedDocument; +export {}; diff --git a/dist/types/test/fixtures/v2/documentRopstenNotIssuedWithTokenRegistry.d.ts b/dist/types/test/fixtures/v2/documentRopstenNotIssuedWithTokenRegistry.d.ts new file mode 100644 index 00000000..ae39d95b --- /dev/null +++ b/dist/types/test/fixtures/v2/documentRopstenNotIssuedWithTokenRegistry.d.ts @@ -0,0 +1,14 @@ +import { v2, WrappedDocument } from "@govtechsg/open-attestation"; +interface CustomDocument extends v2.OpenAttestationDocument { + recipient: { + name: string; + address: { + street: string; + country: string; + }; + }; + consignment: any; + declaration: any; +} +export declare const documentRopstenNotIssuedWithTokenRegistry: WrappedDocument; +export {}; diff --git a/dist/types/test/fixtures/v2/documentRopstenObfuscated.d.ts b/dist/types/test/fixtures/v2/documentRopstenObfuscated.d.ts new file mode 100644 index 00000000..ad8f1c99 --- /dev/null +++ b/dist/types/test/fixtures/v2/documentRopstenObfuscated.d.ts @@ -0,0 +1,20 @@ +import { v2, WrappedDocument } from "@govtechsg/open-attestation"; +interface CustomDocument extends v2.OpenAttestationDocument { + name: string; + description: string; + issuedOn: string; + admissionDate: string; + graduationDate: string; + transcript: any; + additionalData: any; + issuers: [ + { + name: string; + url: string; + documentStore: string; + identityProof: any; + } + ]; +} +export declare const documentRopstenObfuscated: WrappedDocument; +export {}; diff --git a/dist/types/test/fixtures/v2/documentRopstenRevokedWithCertificateStore.d.ts b/dist/types/test/fixtures/v2/documentRopstenRevokedWithCertificateStore.d.ts new file mode 100644 index 00000000..046588c1 --- /dev/null +++ b/dist/types/test/fixtures/v2/documentRopstenRevokedWithCertificateStore.d.ts @@ -0,0 +1,30 @@ +import { v2, WrappedDocument } from "@govtechsg/open-attestation"; +interface CustomDocument extends v2.OpenAttestationDocument { + recipient: { + name: string; + address: { + street: string; + country: string; + }; + }; + consignment: { + description: string; + quantity: { + value: string; + unit: string; + }; + countryOfOrigin: string; + outwardBillNo: string; + dateOfDischarge: string; + dateOfDeparture: string; + countryOfFinalDestination: string; + outgoingVehicleNo: "string"; + }; + declaration: { + name: string; + designation: string; + date: string; + }; +} +export declare const documentRopstenRevokedWithCertificateStore: WrappedDocument; +export {}; diff --git a/dist/types/test/fixtures/v2/documentRopstenRevokedWithDocumentStore.d.ts b/dist/types/test/fixtures/v2/documentRopstenRevokedWithDocumentStore.d.ts new file mode 100644 index 00000000..56291436 --- /dev/null +++ b/dist/types/test/fixtures/v2/documentRopstenRevokedWithDocumentStore.d.ts @@ -0,0 +1,14 @@ +import { v2, WrappedDocument } from "@govtechsg/open-attestation"; +interface CustomDocument extends v2.OpenAttestationDocument { + recipient: { + name: string; + address: { + street: string; + country: string; + }; + }; + consignment: any; + declaration: any; +} +export declare const documentRopstenRevokedWithDocumentStore: WrappedDocument; +export {}; diff --git a/dist/types/test/fixtures/v2/documentRopstenRevokedWithToken.d.ts b/dist/types/test/fixtures/v2/documentRopstenRevokedWithToken.d.ts new file mode 100644 index 00000000..ce242d6a --- /dev/null +++ b/dist/types/test/fixtures/v2/documentRopstenRevokedWithToken.d.ts @@ -0,0 +1,30 @@ +import { v2, WrappedDocument } from "@govtechsg/open-attestation"; +interface CustomDocument extends v2.OpenAttestationDocument { + recipient: { + name: string; + address: { + street: string; + country: string; + }; + }; + consignment: { + description: string; + quantity: { + value: string; + unit: string; + }; + countryOfOrigin: string; + outwardBillNo: string; + dateOfDischarge: string; + dateOfDeparture: string; + countryOfFinalDestination: string; + outgoingVehicleNo: "string"; + }; + declaration: { + name: string; + designation: string; + date: string; + }; +} +export declare const documentRopstenRevokedWithToken: WrappedDocument; +export {}; diff --git a/dist/types/test/fixtures/v2/documentRopstenValidWithCertificateStore.d.ts b/dist/types/test/fixtures/v2/documentRopstenValidWithCertificateStore.d.ts new file mode 100644 index 00000000..baef0616 --- /dev/null +++ b/dist/types/test/fixtures/v2/documentRopstenValidWithCertificateStore.d.ts @@ -0,0 +1,24 @@ +import { v2, WrappedDocument } from "@govtechsg/open-attestation"; +interface CustomDocument extends v2.OpenAttestationDocument { + name: string; + issuedOn: string; + description: string; + admissionDate: string; + graduationDate: string; + transcript: any; + cumulativeScore: string; + additionalData: any; + issuers: { + url: string; + name: string; + certificateStore: string; + uen: string; + email: string; + }[]; + recipient: { + name: string; + nric: string; + }; +} +export declare const documentRopstenValidWithCertificateStore: WrappedDocument; +export {}; diff --git a/dist/types/test/fixtures/v2/documentRopstenValidWithDocumentStore.d.ts b/dist/types/test/fixtures/v2/documentRopstenValidWithDocumentStore.d.ts new file mode 100644 index 00000000..7e6640da --- /dev/null +++ b/dist/types/test/fixtures/v2/documentRopstenValidWithDocumentStore.d.ts @@ -0,0 +1,14 @@ +import { v2, WrappedDocument } from "@govtechsg/open-attestation"; +interface CustomDocument extends v2.OpenAttestationDocument { + recipient: { + name: string; + address: { + street: string; + country: string; + }; + }; + consignment: any; + declaration: any; +} +export declare const documentRopstenValidWithDocumentStore: WrappedDocument; +export {}; diff --git a/dist/types/test/fixtures/v2/documentRopstenValidWithToken.d.ts b/dist/types/test/fixtures/v2/documentRopstenValidWithToken.d.ts new file mode 100644 index 00000000..f2bef50a --- /dev/null +++ b/dist/types/test/fixtures/v2/documentRopstenValidWithToken.d.ts @@ -0,0 +1,14 @@ +import { v2, WrappedDocument } from "@govtechsg/open-attestation"; +interface CustomDocument extends v2.OpenAttestationDocument { + recipient: { + name: string; + address: { + street: string; + country: string; + }; + }; + consignment: any; + declaration: any; +} +export declare const documentRopstenValidWithToken: WrappedDocument; +export {}; diff --git a/dist/types/test/fixtures/v2/tamperedDocument.d.ts b/dist/types/test/fixtures/v2/tamperedDocument.d.ts new file mode 100644 index 00000000..1ce7ff73 --- /dev/null +++ b/dist/types/test/fixtures/v2/tamperedDocument.d.ts @@ -0,0 +1,19 @@ +import { v2, WrappedDocument } from "@govtechsg/open-attestation"; +interface CustomDocument extends v2.OpenAttestationDocument { + name: string; + issuedOn: string; + transcript: any; + issuers: { + url: string; + name: string; + certificateStore: string; + }[]; + recipient: { + name: string; + email: string; + phone: string; + }; +} +export declare const tamperedDocumentWithCertificateStore: WrappedDocument; +export declare const tamperedDocumentWithInvalidCertificateStore: WrappedDocument; +export {}; diff --git a/dist/types/test/utils/index.d.ts b/dist/types/test/utils/index.d.ts new file mode 100644 index 00000000..412629c7 --- /dev/null +++ b/dist/types/test/utils/index.d.ts @@ -0,0 +1,3 @@ +import { VerificationFragment } from "../../src/types/core"; +export declare const getFailingFragments: (fragments: VerificationFragment[]) => VerificationFragment[]; +export declare const getFragmentsByName: (fragments: VerificationFragment[], name: string) => VerificationFragment[]; From b86f08696a294d92843184178bda3623e3cd62af Mon Sep 17 00:00:00 2001 From: Seth Date: Tue, 4 Jan 2022 15:22:23 +0800 Subject: [PATCH 3/4] Revert "chore(testing): to be reverted; for trial run and testing purposes only" This reverts commit 2bc6b9c801ddd173ac7505e7842f5a71b76ccd42. --- dist/cjs/common/error.js | 29 -- dist/cjs/common/errorHandler.js | 88 ----- dist/cjs/common/logger.js | 16 - dist/cjs/common/messages.js | 4 - dist/cjs/common/utils.js | 180 ---------- dist/cjs/config.js | 4 - dist/cjs/did/resolver.js | 122 ------- dist/cjs/did/verifier.js | 119 ------- dist/cjs/getIdentifier.js | 93 ------ dist/cjs/index.js | 79 ----- dist/cjs/types/core.js | 7 - dist/cjs/types/error.js | 107 ------ dist/cjs/validator.js | 20 -- .../hash/openAttestationHash.js | 98 ------ .../hash/openAttestationHash.type.js | 2 - .../didSigned/didSignedDocumentStatus.js | 309 ------------------ .../didSigned/didSignedDocumentStatus.type.js | 70 ---- .../documentStatus/didSigned/index.js | 13 - .../ethereumDocumentStoreStatus.js | 274 ---------------- .../ethereumDocumentStoreStatus.type.js | 59 ---- .../documentStatus/documentStore/index.js | 13 - .../documentStatus/revocation.types.js | 31 -- .../ethereumTokenRegistryStatus.js | 236 ------------- .../ethereumTokenRegistryStatus.type.js | 39 --- .../documentStatus/tokenRegistry/index.js | 13 - dist/cjs/verifiers/documentStatus/utils.js | 193 ----------- .../issuerIdentity/did/didIdentityProof.js | 185 ----------- .../did/didIdentityProof.type.js | 2 - .../cjs/verifiers/issuerIdentity/did/index.js | 13 - .../issuerIdentity/dnsDid/dnsDidProof.js | 186 ----------- .../issuerIdentity/dnsDid/dnsDidProof.type.js | 20 -- .../verifiers/issuerIdentity/dnsDid/index.js | 13 - .../verifiers/issuerIdentity/dnsTxt/index.js | 13 - .../dnsTxt/openAttestationDnsTxt.js | 220 ------------- .../dnsTxt/openAttestationDnsTxt.type.js | 33 -- dist/cjs/verifiers/verificationBuilder.js | 37 --- dist/esm/common/error.js | 26 -- dist/esm/common/errorHandler.js | 84 ----- dist/esm/common/logger.js | 9 - dist/esm/common/messages.js | 1 - dist/esm/common/utils.js | 162 --------- dist/esm/config.js | 1 - dist/esm/did/resolver.js | 112 ------- dist/esm/did/verifier.js | 114 ------- dist/esm/getIdentifier.js | 89 ----- dist/esm/index.js | 38 --- dist/esm/types/core.js | 3 - dist/esm/types/error.js | 104 ------ dist/esm/validator.js | 16 - .../hash/openAttestationHash.js | 95 ------ .../hash/openAttestationHash.type.js | 1 - .../didSigned/didSignedDocumentStatus.js | 306 ----------------- .../didSigned/didSignedDocumentStatus.type.js | 67 ---- .../documentStatus/didSigned/index.js | 1 - .../ethereumDocumentStoreStatus.js | 269 --------------- .../ethereumDocumentStoreStatus.type.js | 56 ---- .../documentStatus/documentStore/index.js | 1 - .../documentStatus/revocation.types.js | 28 -- .../ethereumTokenRegistryStatus.js | 231 ------------- .../ethereumTokenRegistryStatus.type.js | 36 -- .../documentStatus/tokenRegistry/index.js | 1 - dist/esm/verifiers/documentStatus/utils.js | 182 ----------- .../issuerIdentity/did/didIdentityProof.js | 182 ----------- .../did/didIdentityProof.type.js | 1 - .../esm/verifiers/issuerIdentity/did/index.js | 1 - .../issuerIdentity/dnsDid/dnsDidProof.js | 183 ----------- .../issuerIdentity/dnsDid/dnsDidProof.type.js | 17 - .../verifiers/issuerIdentity/dnsDid/index.js | 1 - .../verifiers/issuerIdentity/dnsTxt/index.js | 1 - .../dnsTxt/openAttestationDnsTxt.js | 217 ------------ .../dnsTxt/openAttestationDnsTxt.type.js | 30 -- dist/esm/verifiers/verificationBuilder.js | 33 -- dist/types/src/common/error.d.ts | 5 - dist/types/src/common/errorHandler.d.ts | 8 - dist/types/src/common/logger.d.ts | 10 - dist/types/src/common/messages.d.ts | 1 - dist/types/src/common/utils.d.ts | 69 ---- dist/types/src/common/utils.test.d.ts | 1 - dist/types/src/config.d.ts | 1 - dist/types/src/did/resolver.d.ts | 19 -- dist/types/src/did/resolver.test.d.ts | 1 - dist/types/src/did/verifier.d.ts | 66 ---- dist/types/src/getIdentifier.d.ts | 8 - dist/types/src/getIdentifier.test.d.ts | 1 - dist/types/src/index.d.ts | 26 -- dist/types/src/types/core.d.ts | 111 ------- dist/types/src/types/error.d.ts | 99 ------ dist/types/src/validator.d.ts | 2 - dist/types/src/validator.test.d.ts | 1 - .../hash/openAttestationHash.d.ts | 5 - .../hash/openAttestationHash.test.d.ts | 1 - .../hash/openAttestationHash.type.d.ts | 5 - .../didSigned/didSignedDocumentStatus.d.ts | 5 - .../didSignedDocumentStatus.test.d.ts | 1 - .../didSignedDocumentStatus.type.d.ts | 190 ----------- .../documentStatus/didSigned/index.d.ts | 1 - .../ethereumDocumentStoreStatus.d.ts | 13 - .../ethereumDocumentStoreStatus.test.d.ts | 1 - .../ethereumDocumentStoreStatus.type.d.ts | 159 --------- .../documentStatus/documentStore/index.d.ts | 1 - .../documentStatus/revocation.types.d.ts | 61 ---- .../ethereumTokenRegistryStatus.d.ts | 11 - .../ethereumTokenRegistryStatus.test.d.ts | 1 - .../ethereumTokenRegistryStatus.type.d.ts | 80 ----- .../documentStatus/tokenRegistry/index.d.ts | 1 - .../src/verifiers/documentStatus/utils.d.ts | 26 -- .../issuerIdentity/did/didIdentityProof.d.ts | 5 - .../did/didIdentityProof.test.d.ts | 1 - .../did/didIdentityProof.type.d.ts | 11 - .../verifiers/issuerIdentity/did/index.d.ts | 1 - .../issuerIdentity/dnsDid/dnsDidProof.d.ts | 5 - .../dnsDid/dnsDidProof.test.d.ts | 1 - .../dnsDid/dnsDidProof.type.d.ts | 56 ---- .../issuerIdentity/dnsDid/index.d.ts | 1 - .../issuerIdentity/dnsTxt/index.d.ts | 1 - .../dnsTxt/openAttestationDnsTxt.d.ts | 3 - .../dnsTxt/openAttestationDnsTxt.test.d.ts | 1 - .../dnsTxt/openAttestationDnsTxt.type.d.ts | 97 ------ .../src/verifiers/verificationBuilder.d.ts | 2 - .../verify.v2.integration.errors.test.d.ts | 4 - .../types/src/verify.v2.integration.test.d.ts | 4 - .../types/src/verify.v3.integration.test.d.ts | 1 - dist/types/test/fixtures/v2/document.d.ts | 18 - .../v2/documentDidCustomRevocation.d.ts | 1 - .../fixtures/v2/documentDidMissingProof.d.ts | 1 - .../v2/documentDidMixedTokenRegistry.d.ts | 1 - .../v2/documentDidObfuscatedRevocation.d.ts | 1 - .../test/fixtures/v2/documentDidSigned.d.ts | 1 - .../v2/documentDidWrongSignature.d.ts | 1 - .../v2/documentDnsDidMixedTokenRegistry.d.ts | 2 - .../fixtures/v2/documentDnsDidNoDnsTxt.d.ts | 1 - .../fixtures/v2/documentDnsDidSigned.d.ts | 1 - ...MainnetInvalidWithIncorrectMerkleRoot.d.ts | 15 - ...MainnetInvalidWithOddLengthMerkleRoot.d.ts | 15 - ...umentMainnetValidWithCertificateStore.d.ts | 11 - .../v2/documentRinkebyWithDocumentStore.d.ts | 7 - .../v2/documentRopstenMixedIssuance.d.ts | 1 - ...tRopstenNotIssuedWithCertificateStore.d.ts | 24 -- ...mentRopstenNotIssuedWithDocumentStore.d.ts | 14 - ...mentRopstenNotIssuedWithTokenRegistry.d.ts | 14 - .../v2/documentRopstenObfuscated.d.ts | 20 -- ...entRopstenRevokedWithCertificateStore.d.ts | 30 -- ...cumentRopstenRevokedWithDocumentStore.d.ts | 14 - .../v2/documentRopstenRevokedWithToken.d.ts | 30 -- ...umentRopstenValidWithCertificateStore.d.ts | 24 -- ...documentRopstenValidWithDocumentStore.d.ts | 14 - .../v2/documentRopstenValidWithToken.d.ts | 14 - .../test/fixtures/v2/tamperedDocument.d.ts | 19 -- dist/types/test/utils/index.d.ts | 3 - 149 files changed, 7121 deletions(-) delete mode 100644 dist/cjs/common/error.js delete mode 100644 dist/cjs/common/errorHandler.js delete mode 100644 dist/cjs/common/logger.js delete mode 100644 dist/cjs/common/messages.js delete mode 100644 dist/cjs/common/utils.js delete mode 100644 dist/cjs/config.js delete mode 100644 dist/cjs/did/resolver.js delete mode 100644 dist/cjs/did/verifier.js delete mode 100644 dist/cjs/getIdentifier.js delete mode 100644 dist/cjs/index.js delete mode 100644 dist/cjs/types/core.js delete mode 100644 dist/cjs/types/error.js delete mode 100644 dist/cjs/validator.js delete mode 100644 dist/cjs/verifiers/documentIntegrity/hash/openAttestationHash.js delete mode 100644 dist/cjs/verifiers/documentIntegrity/hash/openAttestationHash.type.js delete mode 100644 dist/cjs/verifiers/documentStatus/didSigned/didSignedDocumentStatus.js delete mode 100644 dist/cjs/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.js delete mode 100644 dist/cjs/verifiers/documentStatus/didSigned/index.js delete mode 100644 dist/cjs/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.js delete mode 100644 dist/cjs/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.js delete mode 100644 dist/cjs/verifiers/documentStatus/documentStore/index.js delete mode 100644 dist/cjs/verifiers/documentStatus/revocation.types.js delete mode 100644 dist/cjs/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.js delete mode 100644 dist/cjs/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.js delete mode 100644 dist/cjs/verifiers/documentStatus/tokenRegistry/index.js delete mode 100644 dist/cjs/verifiers/documentStatus/utils.js delete mode 100644 dist/cjs/verifiers/issuerIdentity/did/didIdentityProof.js delete mode 100644 dist/cjs/verifiers/issuerIdentity/did/didIdentityProof.type.js delete mode 100644 dist/cjs/verifiers/issuerIdentity/did/index.js delete mode 100644 dist/cjs/verifiers/issuerIdentity/dnsDid/dnsDidProof.js delete mode 100644 dist/cjs/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.js delete mode 100644 dist/cjs/verifiers/issuerIdentity/dnsDid/index.js delete mode 100644 dist/cjs/verifiers/issuerIdentity/dnsTxt/index.js delete mode 100644 dist/cjs/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.js delete mode 100644 dist/cjs/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.js delete mode 100644 dist/cjs/verifiers/verificationBuilder.js delete mode 100644 dist/esm/common/error.js delete mode 100644 dist/esm/common/errorHandler.js delete mode 100644 dist/esm/common/logger.js delete mode 100644 dist/esm/common/messages.js delete mode 100644 dist/esm/common/utils.js delete mode 100644 dist/esm/config.js delete mode 100644 dist/esm/did/resolver.js delete mode 100644 dist/esm/did/verifier.js delete mode 100644 dist/esm/getIdentifier.js delete mode 100644 dist/esm/index.js delete mode 100644 dist/esm/types/core.js delete mode 100644 dist/esm/types/error.js delete mode 100644 dist/esm/validator.js delete mode 100644 dist/esm/verifiers/documentIntegrity/hash/openAttestationHash.js delete mode 100644 dist/esm/verifiers/documentIntegrity/hash/openAttestationHash.type.js delete mode 100644 dist/esm/verifiers/documentStatus/didSigned/didSignedDocumentStatus.js delete mode 100644 dist/esm/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.js delete mode 100644 dist/esm/verifiers/documentStatus/didSigned/index.js delete mode 100644 dist/esm/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.js delete mode 100644 dist/esm/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.js delete mode 100644 dist/esm/verifiers/documentStatus/documentStore/index.js delete mode 100644 dist/esm/verifiers/documentStatus/revocation.types.js delete mode 100644 dist/esm/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.js delete mode 100644 dist/esm/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.js delete mode 100644 dist/esm/verifiers/documentStatus/tokenRegistry/index.js delete mode 100644 dist/esm/verifiers/documentStatus/utils.js delete mode 100644 dist/esm/verifiers/issuerIdentity/did/didIdentityProof.js delete mode 100644 dist/esm/verifiers/issuerIdentity/did/didIdentityProof.type.js delete mode 100644 dist/esm/verifiers/issuerIdentity/did/index.js delete mode 100644 dist/esm/verifiers/issuerIdentity/dnsDid/dnsDidProof.js delete mode 100644 dist/esm/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.js delete mode 100644 dist/esm/verifiers/issuerIdentity/dnsDid/index.js delete mode 100644 dist/esm/verifiers/issuerIdentity/dnsTxt/index.js delete mode 100644 dist/esm/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.js delete mode 100644 dist/esm/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.js delete mode 100644 dist/esm/verifiers/verificationBuilder.js delete mode 100644 dist/types/src/common/error.d.ts delete mode 100644 dist/types/src/common/errorHandler.d.ts delete mode 100644 dist/types/src/common/logger.d.ts delete mode 100644 dist/types/src/common/messages.d.ts delete mode 100644 dist/types/src/common/utils.d.ts delete mode 100644 dist/types/src/common/utils.test.d.ts delete mode 100644 dist/types/src/config.d.ts delete mode 100644 dist/types/src/did/resolver.d.ts delete mode 100644 dist/types/src/did/resolver.test.d.ts delete mode 100644 dist/types/src/did/verifier.d.ts delete mode 100644 dist/types/src/getIdentifier.d.ts delete mode 100644 dist/types/src/getIdentifier.test.d.ts delete mode 100644 dist/types/src/index.d.ts delete mode 100644 dist/types/src/types/core.d.ts delete mode 100644 dist/types/src/types/error.d.ts delete mode 100644 dist/types/src/validator.d.ts delete mode 100644 dist/types/src/validator.test.d.ts delete mode 100644 dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.d.ts delete mode 100644 dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.test.d.ts delete mode 100644 dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.type.d.ts delete mode 100644 dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.d.ts delete mode 100644 dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.test.d.ts delete mode 100644 dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.d.ts delete mode 100644 dist/types/src/verifiers/documentStatus/didSigned/index.d.ts delete mode 100644 dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.d.ts delete mode 100644 dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.test.d.ts delete mode 100644 dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.d.ts delete mode 100644 dist/types/src/verifiers/documentStatus/documentStore/index.d.ts delete mode 100644 dist/types/src/verifiers/documentStatus/revocation.types.d.ts delete mode 100644 dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.d.ts delete mode 100644 dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.test.d.ts delete mode 100644 dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.d.ts delete mode 100644 dist/types/src/verifiers/documentStatus/tokenRegistry/index.d.ts delete mode 100644 dist/types/src/verifiers/documentStatus/utils.d.ts delete mode 100644 dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.d.ts delete mode 100644 dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.test.d.ts delete mode 100644 dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.type.d.ts delete mode 100644 dist/types/src/verifiers/issuerIdentity/did/index.d.ts delete mode 100644 dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.d.ts delete mode 100644 dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.test.d.ts delete mode 100644 dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.d.ts delete mode 100644 dist/types/src/verifiers/issuerIdentity/dnsDid/index.d.ts delete mode 100644 dist/types/src/verifiers/issuerIdentity/dnsTxt/index.d.ts delete mode 100644 dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.d.ts delete mode 100644 dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.test.d.ts delete mode 100644 dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.d.ts delete mode 100644 dist/types/src/verifiers/verificationBuilder.d.ts delete mode 100644 dist/types/src/verify.v2.integration.errors.test.d.ts delete mode 100644 dist/types/src/verify.v2.integration.test.d.ts delete mode 100644 dist/types/src/verify.v3.integration.test.d.ts delete mode 100644 dist/types/test/fixtures/v2/document.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentDidCustomRevocation.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentDidMissingProof.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentDidMixedTokenRegistry.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentDidObfuscatedRevocation.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentDidSigned.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentDidWrongSignature.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentDnsDidMixedTokenRegistry.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentDnsDidNoDnsTxt.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentDnsDidSigned.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentMainnetInvalidWithIncorrectMerkleRoot.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentMainnetInvalidWithOddLengthMerkleRoot.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentMainnetValidWithCertificateStore.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentRinkebyWithDocumentStore.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentRopstenMixedIssuance.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentRopstenNotIssuedWithCertificateStore.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentRopstenNotIssuedWithDocumentStore.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentRopstenNotIssuedWithTokenRegistry.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentRopstenObfuscated.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentRopstenRevokedWithCertificateStore.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentRopstenRevokedWithDocumentStore.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentRopstenRevokedWithToken.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentRopstenValidWithCertificateStore.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentRopstenValidWithDocumentStore.d.ts delete mode 100644 dist/types/test/fixtures/v2/documentRopstenValidWithToken.d.ts delete mode 100644 dist/types/test/fixtures/v2/tamperedDocument.d.ts delete mode 100644 dist/types/test/utils/index.d.ts diff --git a/dist/cjs/common/error.js b/dist/cjs/common/error.js deleted file mode 100644 index 9f9d60a4..00000000 --- a/dist/cjs/common/error.js +++ /dev/null @@ -1,29 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -exports.CodedError = void 0; -var CodedError = /** @class */ (function (_super) { - __extends(CodedError, _super); - function CodedError(message, code, codeString) { - var _this = _super.call(this, message) || this; - _this.code = code; - _this.codeString = codeString; - return _this; - } - return CodedError; -}(Error)); -exports.CodedError = CodedError; diff --git a/dist/cjs/common/errorHandler.js b/dist/cjs/common/errorHandler.js deleted file mode 100644 index 68038c4c..00000000 --- a/dist/cjs/common/errorHandler.js +++ /dev/null @@ -1,88 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.withCodedErrorHandler = void 0; -var withCodedErrorHandler = function (verify, errorOptions) { return function (document, options -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore https://github.com/microsoft/TypeScript/issues/26781 -) { return __awaiter(void 0, void 0, void 0, function () { - var e_1, message, code, codeString, name, type, unexpectedErrorCode, unexpectedErrorString; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - _a.trys.push([0, 2, , 3]); - return [4 /*yield*/, verify(document, options)]; - case 1: - // Using return await to ensure async function execute in try block - return [2 /*return*/, _a.sent()]; - case 2: - e_1 = _a.sent(); - message = e_1.message, code = e_1.code, codeString = e_1.codeString; - name = errorOptions.name, type = errorOptions.type, unexpectedErrorCode = errorOptions.unexpectedErrorCode, unexpectedErrorString = errorOptions.unexpectedErrorString; - if (message && code && codeString) { - return [2 /*return*/, { - name: name, - type: type, - data: e_1, - reason: { - message: message, - code: code, - codeString: codeString, - }, - status: "ERROR", - }]; - } - else { - return [2 /*return*/, { - name: name, - type: type, - data: e_1, - reason: { - message: e_1.message, - code: unexpectedErrorCode, - codeString: unexpectedErrorString, - }, - status: "ERROR", - }]; - } - return [3 /*break*/, 3]; - case 3: return [2 /*return*/]; - } - }); -}); }; }; -exports.withCodedErrorHandler = withCodedErrorHandler; diff --git a/dist/cjs/common/logger.js b/dist/cjs/common/logger.js deleted file mode 100644 index fb045a22..00000000 --- a/dist/cjs/common/logger.js +++ /dev/null @@ -1,16 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getLogger = void 0; -var debug_1 = __importDefault(require("debug")); -var logger = debug_1.default("oa-verify"); -var getLogger = function (namespace) { return ({ - trace: logger.extend("trace:" + namespace), - debug: logger.extend("debug:" + namespace), - info: logger.extend("info:" + namespace), - warn: logger.extend("warn:" + namespace), - error: logger.extend("error:" + namespace), -}); }; -exports.getLogger = getLogger; diff --git a/dist/cjs/common/messages.js b/dist/cjs/common/messages.js deleted file mode 100644 index 14089916..00000000 --- a/dist/cjs/common/messages.js +++ /dev/null @@ -1,4 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.warnProvider = void 0; -exports.warnProvider = "You are falling back to oa-verify default configuration, which is not suitable for production environment. It is highly recommended that you configure and provide your own API key. Refer to https://github.com/Open-Attestation/oa-verify#provider"; diff --git a/dist/cjs/common/utils.js b/dist/cjs/common/utils.js deleted file mode 100644 index 1b2519df..00000000 --- a/dist/cjs/common/utils.js +++ /dev/null @@ -1,180 +0,0 @@ -"use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.unhandledError = exports.serverError = exports.invalidArgument = exports.certificateRevoked = exports.certificateNotIssued = exports.contractNotFound = exports.isDocumentStoreAddressOrTokenRegistryAddressInvalid = exports.isErrorFragment = exports.isSkippedFragment = exports.isInvalidFragment = exports.isValidFragment = exports.getIssuerIdentityFragments = exports.getDocumentStatusFragments = exports.getDocumentIntegrityFragments = exports.getOpenAttestationDnsTxtIdentityProofFragment = exports.getOpenAttestationDnsDidIdentityProofFragment = exports.getOpenAttestationDidIdentityProofFragment = exports.getOpenAttestationEthereumTokenRegistryStatusFragment = exports.getOpenAttestationEthereumDocumentStoreStatusFragment = exports.getOpenAttestationDidSignedDocumentStatusFragment = exports.getOpenAttestationHashFragment = exports.getFragmentByName = exports.generateProvider = exports.getProvider = exports.getDefaultProvider = void 0; -var ethers_1 = require("ethers"); -var config_1 = require("../config"); -var error_1 = require("../types/error"); -var messages_1 = require("../common/messages"); -var getDefaultProvider = function (options) { - var network = options.network || process.env.PROVIDER_NETWORK || "homestead"; - var providerType = process.env.PROVIDER_ENDPOINT_TYPE || "infura"; - var apiKey = process.env.PROVIDER_API_KEY || (providerType === "infura" && config_1.INFURA_API_KEY) || ""; - // create infura provider to get connection information - // we then use StaticJsonRpcProvider so that we can set our own custom limit - var uselessProvider = exports.generateProvider({ - providerType: providerType, - network: network, - apiKey: apiKey, - }); - var connection = __assign(__assign({}, uselessProvider.connection), { throttleLimit: 3 }); - return new ethers_1.providers.StaticJsonRpcProvider(connection, network); -}; -exports.getDefaultProvider = getDefaultProvider; -// getProvider is a function to get an existing provider or to get a Default provider, when given the options -var getProvider = function (options) { - var _a; - return (_a = options.provider) !== null && _a !== void 0 ? _a : exports.getDefaultProvider(options); -}; -exports.getProvider = getProvider; -/** - * Generate Provider generates a provider based on the defined options or your env var, if no options or env var was detected, it will generate a provider based on the default values. - * Generate Provider using the following options: (if no option is specified it will use the default values) - * @param {Object} ProviderDetails - Details to use for the function to successfully generate a provider. - * @param {string} ProviderDetails.network - The network in which the provider is connected to, i.e. "homestead", "mainnet", "ropsten", "rinkeby" - * @param {string} ProviderDetails.providerType - Specify which provider to use: "infura", "alchemy" or "jsonrpc" - * @param {string} ProviderDetails.url - Specify which url for JsonRPC to connect to, if not specified will connect to localhost:8545 - * @param {string} ProviderDetails.apiKey - If no apiKey is provided, a default shared API key will be used, which may result in reduced performance and throttled requests. - */ -var generateProvider = function (options) { - if (!!options && Object.keys(options).length === 1 && options.apiKey) { - throw new Error("We could not link the apiKey provided to a provider, please state the provider to use in the parameter."); - } - var network = (options === null || options === void 0 ? void 0 : options.network) || process.env.PROVIDER_NETWORK || "homestead"; - var provider = (options === null || options === void 0 ? void 0 : options.providerType) || process.env.PROVIDER_ENDPOINT_TYPE || "infura"; - var url = (options === null || options === void 0 ? void 0 : options.url) || process.env.PROVIDER_ENDPOINT_URL || ""; - var apiKey = (options === null || options === void 0 ? void 0 : options.apiKey) || (provider === "infura" && process.env.INFURA_API_KEY) || process.env.PROVIDER_API_KEY || ""; - !apiKey && console.warn(messages_1.warnProvider); - if (!!options && Object.keys(options).length === 1 && url) { - return new ethers_1.providers.JsonRpcProvider(url); - } - switch (provider) { - case "infura": - return apiKey ? new ethers_1.providers.InfuraProvider(network, apiKey) : new ethers_1.providers.InfuraProvider(network); - case "alchemy": - return apiKey ? new ethers_1.providers.AlchemyProvider(network, apiKey) : new ethers_1.providers.AlchemyProvider(network); - case "jsonrpc": - return new ethers_1.providers.JsonRpcProvider(url); - default: - throw new Error("The provider provided is not on the list of providers. Please use one of the following: infura, alchemy or jsonrpc."); - } -}; -exports.generateProvider = generateProvider; -/** - * Simple typed utility to return a fragment depending on the name - * @param name - */ -var getFragmentByName = function (name) { return function (fragments) { return fragments.find(function (fragment) { return fragment.name === name; }); }; }; -exports.getFragmentByName = getFragmentByName; -exports.getOpenAttestationHashFragment = exports.getFragmentByName("OpenAttestationHash"); -exports.getOpenAttestationDidSignedDocumentStatusFragment = exports.getFragmentByName("OpenAttestationDidSignedDocumentStatus"); -exports.getOpenAttestationEthereumDocumentStoreStatusFragment = exports.getFragmentByName("OpenAttestationEthereumDocumentStoreStatus"); -exports.getOpenAttestationEthereumTokenRegistryStatusFragment = exports.getFragmentByName("OpenAttestationEthereumTokenRegistryStatus"); -exports.getOpenAttestationDidIdentityProofFragment = exports.getFragmentByName("OpenAttestationDidIdentityProof"); -exports.getOpenAttestationDnsDidIdentityProofFragment = exports.getFragmentByName("OpenAttestationDnsDidIdentityProof"); -exports.getOpenAttestationDnsTxtIdentityProofFragment = exports.getFragmentByName("OpenAttestationDnsTxtIdentityProof"); -/** - * Simple typed utility to return fragments depending on the type - */ -var getFragmentByType = function (type) { return function (fragments) { return fragments.filter(function (fragment) { return fragment.type === type; }); }; }; -exports.getDocumentIntegrityFragments = getFragmentByType("DOCUMENT_INTEGRITY"); -exports.getDocumentStatusFragments = getFragmentByType("DOCUMENT_STATUS"); -exports.getIssuerIdentityFragments = getFragmentByType("ISSUER_IDENTITY"); -var isValidFragment = function (fragment) { - return (fragment === null || fragment === void 0 ? void 0 : fragment.status) === "VALID"; -}; -exports.isValidFragment = isValidFragment; -var isInvalidFragment = function (fragment) { - return (fragment === null || fragment === void 0 ? void 0 : fragment.status) === "INVALID"; -}; -exports.isInvalidFragment = isInvalidFragment; -var isSkippedFragment = function (fragment) { - return (fragment === null || fragment === void 0 ? void 0 : fragment.status) === "SKIPPED"; -}; -exports.isSkippedFragment = isSkippedFragment; -var isErrorFragment = function (fragment) { - return (fragment === null || fragment === void 0 ? void 0 : fragment.status) === "ERROR"; -}; -exports.isErrorFragment = isErrorFragment; -// this function check if the reason of the error is that the document store or token registry is invalid -var isDocumentStoreAddressOrTokenRegistryAddressInvalid = function (fragments) { - var _a, _b, _c, _d; - var documentStoreIssuedFragment = exports.getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); - var tokenRegistryMintedFragment = exports.getOpenAttestationEthereumTokenRegistryStatusFragment(fragments); - // 2 is the error code used by oa-verify in case of invalid address - return ((((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED && - ((_b = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _b === void 0 ? void 0 : _b.message.toLowerCase()) === "Invalid document store address".toLowerCase()) || - (((_c = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _c === void 0 ? void 0 : _c.code) === error_1.OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED && - ((_d = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _d === void 0 ? void 0 : _d.message.toLowerCase()) === "Invalid token registry address".toLowerCase())); -}; -exports.isDocumentStoreAddressOrTokenRegistryAddressInvalid = isDocumentStoreAddressOrTokenRegistryAddressInvalid; -// this function check if the reason of the error is contract not found in document store -var contractNotFound = function (fragments) { - var _a, _b; - var documentStoreIssuedFragment = exports.getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); - // 404 is the error code used by oa-verify in case of contract not found - return (((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED && - ((_b = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _b === void 0 ? void 0 : _b.message.toLowerCase()) === "Contract is not found".toLowerCase()); -}; -exports.contractNotFound = contractNotFound; -// this function check if the reason of the error is that the document is not issued in document store or token registry -var certificateNotIssued = function (fragments) { - var _a, _b; - var documentStoreIssuedFragment = exports.getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); - var tokenRegistryMintedFragment = exports.getOpenAttestationEthereumTokenRegistryStatusFragment(fragments); - // 1 is the error code used by oa-verify in case of document / token not issued / minted - return (((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED || - ((_b = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _b === void 0 ? void 0 : _b.code) === error_1.OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED); -}; -exports.certificateNotIssued = certificateNotIssued; -// this function check if the reason of the error is that the document is revoked in document store -var certificateRevoked = function (fragments) { - var _a; - var documentStoreIssuedFragment = exports.getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); - // 1 is the error code used by oa-verify in case of document / token not issued / minted - return ((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED; -}; -exports.certificateRevoked = certificateRevoked; -// this function check if the error is caused by an invalid merkle root (incorrect length/odd length/invalid characters) -var invalidArgument = function (fragments) { - var _a, _b, _c, _d; - var documentStoreIssuedFragment = exports.getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); - var tokenRegistryMintedFragment = exports.getOpenAttestationEthereumTokenRegistryStatusFragment(fragments); - // why INVALID_ARGUMENT is because we follow the error codes returned by Ethers (https://docs.ethers.io/v5/api/utils/logger/#errors) - return ((((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED && - ((_b = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _b === void 0 ? void 0 : _b.message.toLowerCase()) === "Invalid call arguments".toLowerCase()) || - (((_c = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _c === void 0 ? void 0 : _c.code) === error_1.OpenAttestationEthereumTokenRegistryStatusCode.INVALID_ARGUMENT && - ((_d = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _d === void 0 ? void 0 : _d.message.toLowerCase()) === "Invalid contract arguments".toLowerCase())); -}; -exports.invalidArgument = invalidArgument; -// this function check if the reason of the error is that we can't connect to Ethereum (due to any HTTP 4xx or 5xx errors) -var serverError = function (fragments) { - var _a, _b; - var documentStoreIssuedFragment = exports.getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); - var tokenRegistryMintedFragment = exports.getOpenAttestationEthereumTokenRegistryStatusFragment(fragments); - // 429 is the error code used by oa-verify in case of Ethers returning a missing response error - return (((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === error_1.OpenAttestationEthereumDocumentStoreStatusCode.SERVER_ERROR || - ((_b = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _b === void 0 ? void 0 : _b.code) === error_1.OpenAttestationEthereumTokenRegistryStatusCode.SERVER_ERROR); -}; -exports.serverError = serverError; -// this function catches all other unhandled errors -var unhandledError = function (fragments) { - var _a, _b; - var documentStoreIssuedFragment = exports.getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); - var tokenRegistryMintedFragment = exports.getOpenAttestationEthereumTokenRegistryStatusFragment(fragments); - // 3 is the error code used by oa-verify in case of weird errors that we didn't foresee to handle - return (((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === - error_1.OpenAttestationEthereumDocumentStoreStatusCode.ETHERS_UNHANDLED_ERROR || - ((_b = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _b === void 0 ? void 0 : _b.code) === error_1.OpenAttestationEthereumDocumentStoreStatusCode.ETHERS_UNHANDLED_ERROR); -}; -exports.unhandledError = unhandledError; diff --git a/dist/cjs/config.js b/dist/cjs/config.js deleted file mode 100644 index eb631a35..00000000 --- a/dist/cjs/config.js +++ /dev/null @@ -1,4 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.INFURA_API_KEY = void 0; -exports.INFURA_API_KEY = process.env.INFURA_API_KEY || "bb46da3f80e040e8ab73c0a9ff365d18"; diff --git a/dist/cjs/did/resolver.js b/dist/cjs/did/resolver.js deleted file mode 100644 index 652b1a52..00000000 --- a/dist/cjs/did/resolver.js +++ /dev/null @@ -1,122 +0,0 @@ -"use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getVerificationMethod = exports.resolve = exports.createResolver = exports.getProviderConfig = void 0; -var did_resolver_1 = require("did-resolver"); -var ethr_did_resolver_1 = require("ethr-did-resolver"); -var web_did_resolver_1 = require("web-did-resolver"); -var node_cache_1 = __importDefault(require("node-cache")); -var config_1 = require("../config"); -var utils_1 = require("../common/utils"); -var getProviderConfig = function () { - var _a, _b, _c; - var provider = utils_1.generateProvider(); - var rpcUrl = ((_a = provider === null || provider === void 0 ? void 0 : provider.connection) === null || _a === void 0 ? void 0 : _a.url) || ""; - var networkName = ((_b = provider === null || provider === void 0 ? void 0 : provider._network) === null || _b === void 0 ? void 0 : _b.name) === "homestead" ? "mainnet" : ((_c = provider === null || provider === void 0 ? void 0 : provider._network) === null || _c === void 0 ? void 0 : _c.name) || ""; - if (!rpcUrl || !networkName) { - return { networks: [{ name: "mainnet", rpcUrl: "https://mainnet.infura.io/v3/" + config_1.INFURA_API_KEY }] }; - } - return { - networks: [{ name: networkName, rpcUrl: rpcUrl }], - }; -}; -exports.getProviderConfig = getProviderConfig; -var didResolutionCache = new node_cache_1.default({ stdTTL: 5 * 60 }); // 5 min -var defaultResolver = new did_resolver_1.Resolver(__assign(__assign({}, ethr_did_resolver_1.getResolver(exports.getProviderConfig())), web_did_resolver_1.getResolver())); -var createResolver = function (_a) { - var ethrResolverConfig = _a.ethrResolverConfig; - return ethrResolverConfig - ? new did_resolver_1.Resolver(__assign(__assign({}, ethr_did_resolver_1.getResolver(ethrResolverConfig)), web_did_resolver_1.getResolver())) - : defaultResolver; -}; -exports.createResolver = createResolver; -var resolve = function (didUrl, resolver) { return __awaiter(void 0, void 0, void 0, function () { - var cachedResult, didResolutionResult, _a, did; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - cachedResult = didResolutionCache.get(didUrl); - if (cachedResult) - return [2 /*return*/, cachedResult]; - if (!resolver) return [3 /*break*/, 2]; - return [4 /*yield*/, resolver.resolve(didUrl)]; - case 1: - _a = _b.sent(); - return [3 /*break*/, 4]; - case 2: return [4 /*yield*/, defaultResolver.resolve(didUrl)]; - case 3: - _a = _b.sent(); - _b.label = 4; - case 4: - didResolutionResult = _a; - did = didResolutionResult.didDocument || undefined; - didResolutionCache.set(didUrl, did); - return [2 /*return*/, did]; - } - }); -}); }; -exports.resolve = resolve; -var getVerificationMethod = function (did, key, resolver) { return __awaiter(void 0, void 0, void 0, function () { - var didDocument; - var _a; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: return [4 /*yield*/, exports.resolve(did, resolver)]; - case 1: - didDocument = _b.sent(); - if (!didDocument) - return [2 /*return*/]; - return [2 /*return*/, (_a = didDocument.verificationMethod) === null || _a === void 0 ? void 0 : _a.find(function (k) { return k.id.toLowerCase() === key.toLowerCase(); })]; - } - }); -}); }; -exports.getVerificationMethod = getVerificationMethod; diff --git a/dist/cjs/did/verifier.js b/dist/cjs/did/verifier.js deleted file mode 100644 index f8402727..00000000 --- a/dist/cjs/did/verifier.js +++ /dev/null @@ -1,119 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.verifySignature = exports.verifySecp256k1VerificationKey2018 = exports.DidVerificationStatusArray = exports.DidVerificationStatus = exports.InvalidDidVerificationStatus = exports.ValidDidVerificationStatusArray = exports.ValidDidVerificationStatus = void 0; -var ethers_1 = require("ethers"); -var runtypes_1 = require("runtypes"); -var resolver_1 = require("./resolver"); -var error_1 = require("../types/error"); -var error_2 = require("../common/error"); -exports.ValidDidVerificationStatus = runtypes_1.Record({ - verified: runtypes_1.Literal(true), - did: runtypes_1.String, -}); -exports.ValidDidVerificationStatusArray = runtypes_1.Array(exports.ValidDidVerificationStatus).withConstraint(function (elements) { return elements.length > 0 || "Expect at least one valid element"; }); -exports.InvalidDidVerificationStatus = runtypes_1.Record({ - verified: runtypes_1.Literal(false), - did: runtypes_1.String, - reason: error_1.Reason, -}); -exports.DidVerificationStatus = runtypes_1.Union(exports.ValidDidVerificationStatus, exports.InvalidDidVerificationStatus); -exports.DidVerificationStatusArray = runtypes_1.Array(exports.DidVerificationStatus); -var verifySecp256k1VerificationKey2018 = function (_a) { - var did = _a.did, verificationMethod = _a.verificationMethod, merkleRoot = _a.merkleRoot, signature = _a.signature; - var messageBytes = ethers_1.utils.arrayify(merkleRoot); - var blockchainAccountId = verificationMethod.blockchainAccountId; - if (!blockchainAccountId) { - return { - did: did, - verified: false, - reason: { - code: error_1.OpenAttestationSignatureCode.KEY_MISSING, - codeString: error_1.OpenAttestationSignatureCode[error_1.OpenAttestationSignatureCode.KEY_MISSING], - message: "ethereumAddress not found on public key " + JSON.stringify(verificationMethod), - }, - }; - } - // blockchainAccountId looks like 0x0cE1854a3836daF9130028Cf90D6d35B1Ae46457@eip155:3, let's get rid of the part after @, @ included - var ethereumAddress = blockchainAccountId.split("@")[0]; - var merkleRootSigned = ethers_1.utils.verifyMessage(messageBytes, signature).toLowerCase() === ethereumAddress.toLowerCase(); - if (!merkleRootSigned) { - return { - did: did, - verified: false, - reason: { - code: error_1.OpenAttestationSignatureCode.WRONG_SIGNATURE, - codeString: error_1.OpenAttestationSignatureCode[error_1.OpenAttestationSignatureCode.WRONG_SIGNATURE], - message: "merkle root is not signed correctly by " + ethereumAddress, - }, - }; - } - return { - did: did, - verified: true, - }; -}; -exports.verifySecp256k1VerificationKey2018 = verifySecp256k1VerificationKey2018; -var verifySignature = function (_a) { - var key = _a.key, merkleRoot = _a.merkleRoot, signature = _a.signature, did = _a.did, resolver = _a.resolver; - return __awaiter(void 0, void 0, void 0, function () { - var verificationMethod; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: return [4 /*yield*/, resolver_1.getVerificationMethod(did, key, resolver)]; - case 1: - verificationMethod = _b.sent(); - if (!verificationMethod) - throw new error_2.CodedError("No public key found on DID document for the DID " + did + " and key " + key, error_1.OpenAttestationSignatureCode.KEY_NOT_IN_DID, "KEY_NOT_IN_DID"); - switch (verificationMethod.type) { - case "EcdsaSecp256k1RecoveryMethod2020": - return [2 /*return*/, exports.verifySecp256k1VerificationKey2018({ - did: did, - verificationMethod: verificationMethod, - merkleRoot: merkleRoot, - signature: signature, - })]; - default: - throw new error_2.CodedError("Signature type " + verificationMethod.type + " is currently not support", error_1.OpenAttestationSignatureCode.UNSUPPORTED_KEY_TYPE, "UNSUPPORTED_KEY_TYPE"); - } - return [2 /*return*/]; - } - }); - }); -}; -exports.verifySignature = verifySignature; diff --git a/dist/cjs/getIdentifier.js b/dist/cjs/getIdentifier.js deleted file mode 100644 index f06dd43f..00000000 --- a/dist/cjs/getIdentifier.js +++ /dev/null @@ -1,93 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getIdentifier = void 0; -var core_1 = require("./types/core"); -var verifier_1 = require("./did/verifier"); -var dnsDidProof_type_1 = require("./verifiers/issuerIdentity/dnsDid/dnsDidProof.type"); -var openAttestationDnsTxt_type_1 = require("./verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type"); -var IdentityProof; -(function (IdentityProof) { - IdentityProof["DNS"] = "OpenAttestationDnsTxtIdentityProof"; - IdentityProof["DNSDID"] = "OpenAttestationDnsDidIdentityProof"; - IdentityProof["DID"] = "OpenAttestationDidIdentityProof"; -})(IdentityProof || (IdentityProof = {})); -var getDnsIdentifierProof = function (_a) { - var data = _a.data; - var type = "DNS"; - if (openAttestationDnsTxt_type_1.DnsTxtVerificationStatusDataV3.guard(data)) { - return { - identifier: data.identifier, - type: type, - }; - } - else if (openAttestationDnsTxt_type_1.DnsTxtVerificationStatusArray.guard(data)) { - return data.map(function (issuer) { return ({ - identifier: issuer.location, - type: type, - }); }); - } - throw new Error("Fragment for DNS not supported"); -}; -var getDnsDidIdentifierProof = function (_a) { - var data = _a.data; - var type = "DNS-DID"; - if (dnsDidProof_type_1.DnsDidVerificationStatusArray.guard(data)) { - return data.map(function (issuer) { return ({ - identifier: issuer.location, - type: type, - }); }); - } - else if (dnsDidProof_type_1.DnsDidVerificationStatus.guard(data)) { - return { - identifier: data.location, - type: type, - }; - } - throw new Error("Fragment for DNS-DID not supported"); -}; -var getDidIdentifierProof = function (_a) { - var data = _a.data; - var type = "DID"; - if (verifier_1.DidVerificationStatusArray.guard(data)) { - return data.map(function (issuer) { return ({ - identifier: issuer.did, - type: type, - }); }); - } - else if (verifier_1.DidVerificationStatus.guard(data)) { - return { - identifier: data.did, - type: type, - }; - } - throw new Error("Fragment for DID not supported"); -}; -var getIdentityProofFragment = function (fragments) { - if (fragments.length < 1) { - throw new Error("Please provide at least one verification fragment"); - } - return fragments.find(function (status) { return status.type === "ISSUER_IDENTITY" && status.status === "VALID"; }); -}; -var getIdentifier = function (fragments) { - var fragment = getIdentityProofFragment(fragments); - if (!fragment) { - throw new Error("Did not find any Issuer Identity fragment that is valid"); - } - if (!core_1.isVerificationFragmentWithData(fragment)) { - throw new Error("No data property found in fragment, malformed fragment"); - } - switch (fragment.name) { - case IdentityProof.DNS: - return getDnsIdentifierProof(fragment); - case IdentityProof.DNSDID: - return getDnsDidIdentifierProof(fragment); - case IdentityProof.DID: - return getDidIdentifierProof(fragment); - default: - return { - identifier: "Unknown", - type: "Unknown", - }; - } -}; -exports.getIdentifier = getIdentifier; diff --git a/dist/cjs/index.js b/dist/cjs/index.js deleted file mode 100644 index 36c255ec..00000000 --- a/dist/cjs/index.js +++ /dev/null @@ -1,79 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.utils = exports.getIdentifier = exports.createResolver = exports.openAttestationDidIdentityProof = exports.openAttestationDnsDidIdentityProof = exports.openAttestationDnsTxtIdentityProof = exports.openAttestationDidSignedDocumentStatus = exports.openAttestationEthereumTokenRegistryStatus = exports.openAttestationEthereumDocumentStoreStatus = exports.openAttestationHash = exports.verify = exports.isValid = exports.openAttestationVerifiers = exports.verificationBuilder = void 0; -var verificationBuilder_1 = require("./verifiers/verificationBuilder"); -Object.defineProperty(exports, "verificationBuilder", { enumerable: true, get: function () { return verificationBuilder_1.verificationBuilder; } }); -var openAttestationHash_1 = require("./verifiers/documentIntegrity/hash/openAttestationHash"); -Object.defineProperty(exports, "openAttestationHash", { enumerable: true, get: function () { return openAttestationHash_1.openAttestationHash; } }); -var validator_1 = require("./validator"); -Object.defineProperty(exports, "isValid", { enumerable: true, get: function () { return validator_1.isValid; } }); -var tokenRegistry_1 = require("./verifiers/documentStatus/tokenRegistry"); -Object.defineProperty(exports, "openAttestationEthereumTokenRegistryStatus", { enumerable: true, get: function () { return tokenRegistry_1.openAttestationEthereumTokenRegistryStatus; } }); -var documentStore_1 = require("./verifiers/documentStatus/documentStore"); -Object.defineProperty(exports, "openAttestationEthereumDocumentStoreStatus", { enumerable: true, get: function () { return documentStore_1.openAttestationEthereumDocumentStoreStatus; } }); -var didSigned_1 = require("./verifiers/documentStatus/didSigned"); -Object.defineProperty(exports, "openAttestationDidSignedDocumentStatus", { enumerable: true, get: function () { return didSigned_1.openAttestationDidSignedDocumentStatus; } }); -var dnsTxt_1 = require("./verifiers/issuerIdentity/dnsTxt"); -Object.defineProperty(exports, "openAttestationDnsTxtIdentityProof", { enumerable: true, get: function () { return dnsTxt_1.openAttestationDnsTxtIdentityProof; } }); -var did_1 = require("./verifiers/issuerIdentity/did"); -Object.defineProperty(exports, "openAttestationDidIdentityProof", { enumerable: true, get: function () { return did_1.openAttestationDidIdentityProof; } }); -var dnsDid_1 = require("./verifiers/issuerIdentity/dnsDid"); -Object.defineProperty(exports, "openAttestationDnsDidIdentityProof", { enumerable: true, get: function () { return dnsDid_1.openAttestationDnsDidIdentityProof; } }); -var resolver_1 = require("./did/resolver"); -Object.defineProperty(exports, "createResolver", { enumerable: true, get: function () { return resolver_1.createResolver; } }); -var getIdentifier_1 = require("./getIdentifier"); -Object.defineProperty(exports, "getIdentifier", { enumerable: true, get: function () { return getIdentifier_1.getIdentifier; } }); -var utils = __importStar(require("./common/utils")); -exports.utils = utils; -var util_1 = __importDefault(require("util")); -// eslint-disable-next-line @typescript-eslint/no-empty-function -util_1.default.deprecate(function infuraApiKey() { }, "'INFURA_API_KEY' has been deprecated, please use 'PROVIDER_API_KEY'."); -var openAttestationVerifiers = [ - openAttestationHash_1.openAttestationHash, - tokenRegistry_1.openAttestationEthereumTokenRegistryStatus, - documentStore_1.openAttestationEthereumDocumentStoreStatus, - didSigned_1.openAttestationDidSignedDocumentStatus, - dnsTxt_1.openAttestationDnsTxtIdentityProof, - dnsDid_1.openAttestationDnsDidIdentityProof, -]; -exports.openAttestationVerifiers = openAttestationVerifiers; -var defaultBuilderOption = { - network: process.env.PROVIDER_NETWORK || "homestead", -}; -var verify = verificationBuilder_1.verificationBuilder(openAttestationVerifiers, defaultBuilderOption); -exports.verify = verify; -__exportStar(require("./types/core"), exports); -__exportStar(require("./verifiers/documentIntegrity/hash/openAttestationHash.type"), exports); -__exportStar(require("./verifiers/documentStatus/didSigned/didSignedDocumentStatus.type"), exports); -__exportStar(require("./verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type"), exports); -__exportStar(require("./verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type"), exports); -__exportStar(require("./verifiers/issuerIdentity/did/didIdentityProof.type"), exports); -__exportStar(require("./verifiers/issuerIdentity/dnsDid/dnsDidProof.type"), exports); -__exportStar(require("./verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type"), exports); -__exportStar(require("./types/error"), exports); -__exportStar(require("./common/error"), exports); diff --git a/dist/cjs/types/core.js b/dist/cjs/types/core.js deleted file mode 100644 index 828c1c34..00000000 --- a/dist/cjs/types/core.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.isVerificationFragmentWithData = void 0; -var isVerificationFragmentWithData = function (fragment) { - return fragment.data; -}; -exports.isVerificationFragmentWithData = isVerificationFragmentWithData; diff --git a/dist/cjs/types/error.js b/dist/cjs/types/error.js deleted file mode 100644 index a703d661..00000000 --- a/dist/cjs/types/error.js +++ /dev/null @@ -1,107 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.Reason = exports.OpenAttestationSignatureCode = exports.OpenAttestationDnsDidCode = exports.OpenAttestationDidCode = exports.OpenAttestationDidSignedDocumentStatusCode = exports.OpenAttestationHashCode = exports.OpenAttestationDnsTxtCode = exports.OpenAttestationEthereumTokenRegistryStatusCode = exports.OpenAttestationDocumentSignedCode = exports.OpenAttestationEthereumDocumentStoreStatusCode = void 0; -// NEVER EVER REPLACE OR CHANGE A VALUE :) -// code for errors and invalid fragment -var runtypes_1 = require("runtypes"); -var OpenAttestationEthereumDocumentStoreStatusCode; -(function (OpenAttestationEthereumDocumentStoreStatusCode) { - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["UNEXPECTED_ERROR"] = 0] = "UNEXPECTED_ERROR"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["DOCUMENT_NOT_ISSUED"] = 1] = "DOCUMENT_NOT_ISSUED"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["CONTRACT_ADDRESS_INVALID"] = 2] = "CONTRACT_ADDRESS_INVALID"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["ETHERS_UNHANDLED_ERROR"] = 3] = "ETHERS_UNHANDLED_ERROR"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["SKIPPED"] = 4] = "SKIPPED"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["DOCUMENT_REVOKED"] = 5] = "DOCUMENT_REVOKED"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["INVALID_ARGUMENT"] = 6] = "INVALID_ARGUMENT"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["CONTRACT_NOT_FOUND"] = 404] = "CONTRACT_NOT_FOUND"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["INVALID_ISSUERS"] = 7] = "INVALID_ISSUERS"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["INVALID_VALIDATION_METHOD"] = 8] = "INVALID_VALIDATION_METHOD"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["UNRECOGNIZED_DOCUMENT"] = 9] = "UNRECOGNIZED_DOCUMENT"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["SERVER_ERROR"] = 500] = "SERVER_ERROR"; -})(OpenAttestationEthereumDocumentStoreStatusCode = exports.OpenAttestationEthereumDocumentStoreStatusCode || (exports.OpenAttestationEthereumDocumentStoreStatusCode = {})); -var OpenAttestationDocumentSignedCode; -(function (OpenAttestationDocumentSignedCode) { - OpenAttestationDocumentSignedCode[OpenAttestationDocumentSignedCode["UNEXPECTED_ERROR"] = 0] = "UNEXPECTED_ERROR"; - OpenAttestationDocumentSignedCode[OpenAttestationDocumentSignedCode["DOCUMENT_PROOF_INVALID"] = 1] = "DOCUMENT_PROOF_INVALID"; - OpenAttestationDocumentSignedCode[OpenAttestationDocumentSignedCode["DOCUMENT_PROOF_ERROR"] = 2] = "DOCUMENT_PROOF_ERROR"; - OpenAttestationDocumentSignedCode[OpenAttestationDocumentSignedCode["SKIPPED"] = 4] = "SKIPPED"; -})(OpenAttestationDocumentSignedCode = exports.OpenAttestationDocumentSignedCode || (exports.OpenAttestationDocumentSignedCode = {})); -var OpenAttestationEthereumTokenRegistryStatusCode; -(function (OpenAttestationEthereumTokenRegistryStatusCode) { - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["UNEXPECTED_ERROR"] = 0] = "UNEXPECTED_ERROR"; - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["DOCUMENT_NOT_MINTED"] = 1] = "DOCUMENT_NOT_MINTED"; - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["CONTRACT_ADDRESS_INVALID"] = 2] = "CONTRACT_ADDRESS_INVALID"; - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["ETHERS_UNHANDLED_ERROR"] = 3] = "ETHERS_UNHANDLED_ERROR"; - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["SKIPPED"] = 4] = "SKIPPED"; - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["INVALID_ISSUERS"] = 5] = "INVALID_ISSUERS"; - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["INVALID_ARGUMENT"] = 6] = "INVALID_ARGUMENT"; - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["UNDEFINED_TOKEN_REGISTRY"] = 7] = "UNDEFINED_TOKEN_REGISTRY"; - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["INVALID_VALIDATION_METHOD"] = 8] = "INVALID_VALIDATION_METHOD"; - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["UNRECOGNIZED_DOCUMENT"] = 9] = "UNRECOGNIZED_DOCUMENT"; - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["SERVER_ERROR"] = 500] = "SERVER_ERROR"; -})(OpenAttestationEthereumTokenRegistryStatusCode = exports.OpenAttestationEthereumTokenRegistryStatusCode || (exports.OpenAttestationEthereumTokenRegistryStatusCode = {})); -var OpenAttestationDnsTxtCode; -(function (OpenAttestationDnsTxtCode) { - OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["UNEXPECTED_ERROR"] = 0] = "UNEXPECTED_ERROR"; - OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["INVALID_IDENTITY"] = 1] = "INVALID_IDENTITY"; - OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["SKIPPED"] = 2] = "SKIPPED"; - OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["INVALID_ISSUERS"] = 3] = "INVALID_ISSUERS"; - OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["MATCHING_RECORD_NOT_FOUND"] = 4] = "MATCHING_RECORD_NOT_FOUND"; - OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["UNRECOGNIZED_DOCUMENT"] = 5] = "UNRECOGNIZED_DOCUMENT"; - OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["UNSUPPORTED"] = 6] = "UNSUPPORTED"; -})(OpenAttestationDnsTxtCode = exports.OpenAttestationDnsTxtCode || (exports.OpenAttestationDnsTxtCode = {})); -var OpenAttestationHashCode; -(function (OpenAttestationHashCode) { - OpenAttestationHashCode[OpenAttestationHashCode["DOCUMENT_TAMPERED"] = 0] = "DOCUMENT_TAMPERED"; - OpenAttestationHashCode[OpenAttestationHashCode["UNEXPECTED_ERROR"] = 1] = "UNEXPECTED_ERROR"; - OpenAttestationHashCode[OpenAttestationHashCode["SKIPPED"] = 2] = "SKIPPED"; -})(OpenAttestationHashCode = exports.OpenAttestationHashCode || (exports.OpenAttestationHashCode = {})); -var OpenAttestationDidSignedDocumentStatusCode; -(function (OpenAttestationDidSignedDocumentStatusCode) { - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["SKIPPED"] = 0] = "SKIPPED"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["UNEXPECTED_ERROR"] = 1] = "UNEXPECTED_ERROR"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["MISSING_REVOCATION"] = 2] = "MISSING_REVOCATION"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["UNSIGNED"] = 3] = "UNSIGNED"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["INVALID_ISSUERS"] = 4] = "INVALID_ISSUERS"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["MALFORMED_IDENTITY_PROOF"] = 5] = "MALFORMED_IDENTITY_PROOF"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["CORRESPONDING_PROOF_MISSING"] = 6] = "CORRESPONDING_PROOF_MISSING"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["DID_MISSING"] = 7] = "DID_MISSING"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["UNRECOGNIZED_DOCUMENT"] = 8] = "UNRECOGNIZED_DOCUMENT"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["UNRECOGNIZED_REVOCATION_TYPE"] = 9] = "UNRECOGNIZED_REVOCATION_TYPE"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["REVOCATION_LOCATION_MISSING"] = 10] = "REVOCATION_LOCATION_MISSING"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["OCSP_RESPONSE_INVALID"] = 11] = "OCSP_RESPONSE_INVALID"; -})(OpenAttestationDidSignedDocumentStatusCode = exports.OpenAttestationDidSignedDocumentStatusCode || (exports.OpenAttestationDidSignedDocumentStatusCode = {})); -var OpenAttestationDidCode; -(function (OpenAttestationDidCode) { - OpenAttestationDidCode[OpenAttestationDidCode["SKIPPED"] = 0] = "SKIPPED"; - OpenAttestationDidCode[OpenAttestationDidCode["UNEXPECTED_ERROR"] = 1] = "UNEXPECTED_ERROR"; - OpenAttestationDidCode[OpenAttestationDidCode["INVALID_ISSUERS"] = 2] = "INVALID_ISSUERS"; - OpenAttestationDidCode[OpenAttestationDidCode["MALFORMED_IDENTITY_PROOF"] = 3] = "MALFORMED_IDENTITY_PROOF"; - OpenAttestationDidCode[OpenAttestationDidCode["DID_MISSING"] = 4] = "DID_MISSING"; - OpenAttestationDidCode[OpenAttestationDidCode["UNSIGNED"] = 5] = "UNSIGNED"; - OpenAttestationDidCode[OpenAttestationDidCode["UNRECOGNIZED_DOCUMENT"] = 6] = "UNRECOGNIZED_DOCUMENT"; -})(OpenAttestationDidCode = exports.OpenAttestationDidCode || (exports.OpenAttestationDidCode = {})); -var OpenAttestationDnsDidCode; -(function (OpenAttestationDnsDidCode) { - OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["SKIPPED"] = 0] = "SKIPPED"; - OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["UNEXPECTED_ERROR"] = 1] = "UNEXPECTED_ERROR"; - OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["MALFORMED_IDENTITY_PROOF"] = 2] = "MALFORMED_IDENTITY_PROOF"; - OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["INVALID_ISSUERS"] = 3] = "INVALID_ISSUERS"; - OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["UNSIGNED"] = 4] = "UNSIGNED"; - OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["UNRECOGNIZED_DOCUMENT"] = 5] = "UNRECOGNIZED_DOCUMENT"; - OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["INVALID_IDENTITY"] = 6] = "INVALID_IDENTITY"; -})(OpenAttestationDnsDidCode = exports.OpenAttestationDnsDidCode || (exports.OpenAttestationDnsDidCode = {})); -var OpenAttestationSignatureCode; -(function (OpenAttestationSignatureCode) { - OpenAttestationSignatureCode[OpenAttestationSignatureCode["UNEXPECTED_ERROR"] = 0] = "UNEXPECTED_ERROR"; - OpenAttestationSignatureCode[OpenAttestationSignatureCode["KEY_MISSING"] = 1] = "KEY_MISSING"; - OpenAttestationSignatureCode[OpenAttestationSignatureCode["DID_MISSING"] = 3] = "DID_MISSING"; - OpenAttestationSignatureCode[OpenAttestationSignatureCode["KEY_NOT_IN_DID"] = 4] = "KEY_NOT_IN_DID"; - OpenAttestationSignatureCode[OpenAttestationSignatureCode["UNSUPPORTED_KEY_TYPE"] = 6] = "UNSUPPORTED_KEY_TYPE"; - OpenAttestationSignatureCode[OpenAttestationSignatureCode["WRONG_SIGNATURE"] = 7] = "WRONG_SIGNATURE"; -})(OpenAttestationSignatureCode = exports.OpenAttestationSignatureCode || (exports.OpenAttestationSignatureCode = {})); -exports.Reason = runtypes_1.Record({ - code: runtypes_1.Number, - codeString: runtypes_1.String, - message: runtypes_1.String, -}); diff --git a/dist/cjs/validator.js b/dist/cjs/validator.js deleted file mode 100644 index dc37a560..00000000 --- a/dist/cjs/validator.js +++ /dev/null @@ -1,20 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.isValid = void 0; -var isValid = function (verificationFragments, types) { - if (types === void 0) { types = ["DOCUMENT_STATUS", "DOCUMENT_INTEGRITY", "ISSUER_IDENTITY"]; } - if (verificationFragments.length < 1) { - throw new Error("Please provide at least one verification fragment to check"); - } - if (types.length < 1) { - throw new Error("Please provide at least one type to check"); - } - return types.every(function (type) { - var verificationFragmentsForType = verificationFragments.filter(function (fragment) { return fragment.type === type; }); - // return true if at least one fragment is valid - // and all fragments are valid or skipped - return (verificationFragmentsForType.some(function (fragment) { return fragment.status === "VALID"; }) && - verificationFragmentsForType.every(function (fragment) { return fragment.status === "VALID" || fragment.status === "SKIPPED"; })); - }); -}; -exports.isValid = isValid; diff --git a/dist/cjs/verifiers/documentIntegrity/hash/openAttestationHash.js b/dist/cjs/verifiers/documentIntegrity/hash/openAttestationHash.js deleted file mode 100644 index 38fc08f2..00000000 --- a/dist/cjs/verifiers/documentIntegrity/hash/openAttestationHash.js +++ /dev/null @@ -1,98 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.openAttestationHash = void 0; -var open_attestation_1 = require("@govtechsg/open-attestation"); -var error_1 = require("../../../types/error"); -var errorHandler_1 = require("../../../common/errorHandler"); -var name = "OpenAttestationHash"; -var type = "DOCUMENT_INTEGRITY"; -var skip = function () { - return Promise.resolve({ - status: "SKIPPED", - type: type, - name: name, - reason: { - code: error_1.OpenAttestationHashCode.SKIPPED, - codeString: error_1.OpenAttestationHashCode[error_1.OpenAttestationHashCode.SKIPPED], - message: "Document does not have merkle root, target hash or data.", - }, - }); -}; -var test = function (document) { - return open_attestation_1.utils.isWrappedV3Document(document) || open_attestation_1.utils.isWrappedV2Document(document); -}; -var verify = function (document) { return __awaiter(void 0, void 0, void 0, function () { - var hash; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, open_attestation_1.verifySignature(document)]; - case 1: - hash = _a.sent(); - if (!hash) { - return [2 /*return*/, { - type: type, - name: name, - data: hash, - reason: { - code: error_1.OpenAttestationHashCode.DOCUMENT_TAMPERED, - codeString: error_1.OpenAttestationHashCode[error_1.OpenAttestationHashCode.DOCUMENT_TAMPERED], - message: "Document has been tampered with", - }, - status: "INVALID", - }]; - } - return [2 /*return*/, { - type: type, - name: name, - data: hash, - status: "VALID", - }]; - } - }); -}); }; -exports.openAttestationHash = { - skip: skip, - test: test, - verify: errorHandler_1.withCodedErrorHandler(verify, { - name: name, - type: type, - unexpectedErrorCode: error_1.OpenAttestationHashCode.UNEXPECTED_ERROR, - unexpectedErrorString: error_1.OpenAttestationHashCode[error_1.OpenAttestationHashCode.UNEXPECTED_ERROR], - }), -}; diff --git a/dist/cjs/verifiers/documentIntegrity/hash/openAttestationHash.type.js b/dist/cjs/verifiers/documentIntegrity/hash/openAttestationHash.type.js deleted file mode 100644 index c8ad2e54..00000000 --- a/dist/cjs/verifiers/documentIntegrity/hash/openAttestationHash.type.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/cjs/verifiers/documentStatus/didSigned/didSignedDocumentStatus.js b/dist/cjs/verifiers/documentStatus/didSigned/didSignedDocumentStatus.js deleted file mode 100644 index eb018cf9..00000000 --- a/dist/cjs/verifiers/documentStatus/didSigned/didSignedDocumentStatus.js +++ /dev/null @@ -1,309 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.openAttestationDidSignedDocumentStatus = void 0; -var open_attestation_1 = require("@govtechsg/open-attestation"); -var error_1 = require("../../../types/error"); -var verifier_1 = require("../../../did/verifier"); -var error_2 = require("../../../common/error"); -var errorHandler_1 = require("../../../common/errorHandler"); -var utils_1 = require("../utils"); -var revocation_types_1 = require("../revocation.types"); -var didSignedDocumentStatus_type_1 = require("./didSignedDocumentStatus.type"); -var name = "OpenAttestationDidSignedDocumentStatus"; -var type = "DOCUMENT_STATUS"; -var skip = function () { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, { - status: "SKIPPED", - type: type, - name: name, - reason: { - code: error_1.OpenAttestationDidSignedDocumentStatusCode.SKIPPED, - codeString: error_1.OpenAttestationDidSignedDocumentStatusCode[error_1.OpenAttestationDidSignedDocumentStatusCode.SKIPPED], - message: "Document was not signed by DID directly", - }, - }]; - }); -}); }; -var test = function (document) { - if (open_attestation_1.utils.isSignedWrappedV2Document(document)) { - return document.proof.some(function (proof) { return proof.type === "OpenAttestationSignature2018"; }); - } - else if (open_attestation_1.utils.isSignedWrappedV3Document(document)) { - return document.proof.type === "OpenAttestationMerkleProofSignature2018"; - } - return false; -}; -var transformToDidSignedIssuanceStatus = function (status) { - return verifier_1.ValidDidVerificationStatus.guard(status) - ? { - issued: true, - did: status.did, - } - : { - issued: false, - did: status.did, - reason: status.reason, - }; -}; -var verifyV2 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - var documentData, merkleRoot, _a, targetHash, proofs, issuers, revocation, revocationStatusCallback, revocationStatuses, signatureVerificationDeferred, issuance, notIssued, revoked, data, reason; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - documentData = open_attestation_1.getData(document); - merkleRoot = "0x" + document.signature.merkleRoot; - _a = document.signature, targetHash = _a.targetHash, proofs = _a.proof; - documentData.issuers.forEach(function (issuer) { - var _a, _b; - if (!(((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === "DID" || ((_b = issuer.identityProof) === null || _b === void 0 ? void 0 : _b.type) === "DNS-DID")) - throw new error_2.CodedError("All issuers must use DID or DNS-DID identityProof type.", error_1.OpenAttestationDidSignedDocumentStatusCode.INVALID_ISSUERS, error_1.OpenAttestationDidSignedDocumentStatusCode[error_1.OpenAttestationDidSignedDocumentStatusCode.INVALID_ISSUERS]); - }); - issuers = documentData.issuers; - revocation = issuers.map(function (issuer) { return issuer.revocation; }); - if (revocation.some(function (r) { return typeof (r === null || r === void 0 ? void 0 : r.type) === "undefined"; })) - throw new error_2.CodedError("revocation block not found for an issuer", error_1.OpenAttestationDidSignedDocumentStatusCode.MISSING_REVOCATION, "MISSING_REVOCATION"); - revocationStatusCallback = function (revocationItem) { - switch (revocationItem.type) { - case open_attestation_1.v2.RevocationType.RevocationStore: - if (typeof revocationItem.location === "string") { - return utils_1.isRevokedOnDocumentStore({ - documentStore: revocationItem.location, - merkleRoot: merkleRoot, - provider: options.provider, - targetHash: targetHash, - proofs: proofs, - }); - } - throw new error_2.CodedError("missing revocation location for an issuer", error_1.OpenAttestationDidSignedDocumentStatusCode.REVOCATION_LOCATION_MISSING, "REVOCATION_LOCATION_MISSING"); - case open_attestation_1.v2.RevocationType.OcspResponder: - if (typeof revocationItem.location === "string") { - return utils_1.isRevokedByOcspResponder({ - certificateId: documentData.id, - location: revocationItem.location, - }); - } - throw new error_2.CodedError("missing revocation location for an issuer", error_1.OpenAttestationDidSignedDocumentStatusCode.REVOCATION_LOCATION_MISSING, "REVOCATION_LOCATION_MISSING"); - case open_attestation_1.v2.RevocationType.None: - return Promise.resolve({ revoked: false }); - default: - throw new error_2.CodedError("unrecognized revocation type for an issuer", error_1.OpenAttestationDidSignedDocumentStatusCode.UNRECOGNIZED_REVOCATION_TYPE, "UNRECOGNIZED_REVOCATION_TYPE"); - } - }; - return [4 /*yield*/, Promise.all(revocation.map(revocationStatusCallback))]; - case 1: - revocationStatuses = _b.sent(); - // Check that all the issuers have signed on the document - if (!document.proof) - throw new error_2.CodedError("Document is not signed. Proofs are missing.", error_1.OpenAttestationDidSignedDocumentStatusCode.UNSIGNED, "UNSIGNED"); - signatureVerificationDeferred = issuers.map(function (issuer) { return __awaiter(void 0, void 0, void 0, function () { - var key, did, correspondingProof; - var _a; - return __generator(this, function (_b) { - key = (_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.key; - did = issuer.id; - if (!did) - throw new error_2.CodedError("id is missing in issuer", error_1.OpenAttestationDidSignedDocumentStatusCode.DID_MISSING, "DID_MISSING"); - if (!key) - throw new error_2.CodedError("Key is not present", error_1.OpenAttestationDidSignedDocumentStatusCode.MALFORMED_IDENTITY_PROOF, "MALFORMED_IDENTITY_PROOF"); - correspondingProof = document.proof.find(function (p) { return p.verificationMethod.toLowerCase() === key.toLowerCase(); }); - if (!correspondingProof) - throw new error_2.CodedError("Proof not found for " + key, error_1.OpenAttestationDidSignedDocumentStatusCode.CORRESPONDING_PROOF_MISSING, "CORRESPONDING_PROOF_MISSING"); - return [2 /*return*/, verifier_1.verifySignature({ - merkleRoot: merkleRoot, - key: key, - signature: correspondingProof.signature, - did: did, - resolver: options.resolver, - })]; - }); - }); }); - return [4 /*yield*/, Promise.all(signatureVerificationDeferred)]; - case 2: return [4 /*yield*/, (_b.sent()).map(transformToDidSignedIssuanceStatus)]; - case 3: - issuance = _b.sent(); - notIssued = issuance.find(didSignedDocumentStatus_type_1.InvalidDidSignedIssuanceStatus.guard); - revoked = revocationStatuses.find(revocation_types_1.InvalidRevocationStatus.guard); - data = { - issuedOnAll: !notIssued, - revokedOnAny: !!revoked, - details: { - issuance: issuance, - revocation: revocationStatuses, - }, - }; - if (didSignedDocumentStatus_type_1.ValidDidSignedDataV2.guard(data)) { - return [2 /*return*/, { - name: name, - type: type, - data: data, - status: "VALID", - }]; - } - if (didSignedDocumentStatus_type_1.InvalidDidSignedIssuanceStatus.guard(notIssued)) { - reason = notIssued.reason; - } - else if (revocation_types_1.InvalidRevocationStatus.guard(revoked)) { - reason = revoked.reason; - } - if (!reason) { - throw new error_2.CodedError("Unable to retrieve the reason of the failure", error_1.OpenAttestationDidSignedDocumentStatusCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); - } - return [2 /*return*/, { - name: name, - type: type, - data: data, - status: "INVALID", - reason: reason, - }]; - } - }); -}); }; -var verifyV3 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - var _a, merkleRootRaw, targetHash, proofs, merkleRoot, metaData, verificationResult, _b, issuedOnAll, getRevocationStatus, revocationStatus, revokedOnAny, reason; - var _c; - return __generator(this, function (_d) { - switch (_d.label) { - case 0: - _a = document.proof, merkleRootRaw = _a.merkleRoot, targetHash = _a.targetHash, proofs = _a.proofs; - merkleRoot = "0x" + merkleRootRaw; - metaData = document.openAttestationMetadata; - _b = transformToDidSignedIssuanceStatus; - return [4 /*yield*/, verifier_1.verifySignature({ - key: document.proof.key, - did: metaData.proof.value, - merkleRoot: merkleRoot, - signature: document.proof.signature, - resolver: options.resolver, - })]; - case 1: - verificationResult = _b.apply(void 0, [_d.sent()]); - if (!((_c = metaData.proof.revocation) === null || _c === void 0 ? void 0 : _c.type)) { - throw new error_2.CodedError("revocation block not found for an issuer", error_1.OpenAttestationDidSignedDocumentStatusCode.MISSING_REVOCATION, "MISSING_REVOCATION"); - } - issuedOnAll = verificationResult.issued; - getRevocationStatus = function (docType, location) { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (docType) { - case open_attestation_1.v3.RevocationType.RevocationStore: - if (typeof location === "string") { - return [2 /*return*/, utils_1.isRevokedOnDocumentStore({ - documentStore: location, - merkleRoot: merkleRoot, - targetHash: targetHash, - proofs: proofs, - provider: options.provider, - })]; - } - throw new error_2.CodedError("missing revocation location for an issuer", error_1.OpenAttestationDidSignedDocumentStatusCode.REVOCATION_LOCATION_MISSING, "REVOCATION_LOCATION_MISSING"); - case open_attestation_1.v3.RevocationType.OcspResponder: - throw new Error("Ocsp revocation type not yet supported for v3"); - case open_attestation_1.v3.RevocationType.None: - return [2 /*return*/, { revoked: false }]; - default: - throw new error_2.CodedError("revocation type not found for an issuer", error_1.OpenAttestationDidSignedDocumentStatusCode.UNRECOGNIZED_REVOCATION_TYPE, "UNRECOGNIZED_REVOCATION_TYPE"); - } - return [2 /*return*/]; - }); - }); }; - return [4 /*yield*/, getRevocationStatus(metaData.proof.revocation.type, metaData.proof.revocation.location)]; - case 2: - revocationStatus = _d.sent(); - revokedOnAny = revocationStatus.revoked; - if (didSignedDocumentStatus_type_1.ValidDidSignedIssuanceStatus.guard(verificationResult) && revocation_types_1.ValidRevocationStatus.guard(revocationStatus)) { - return [2 /*return*/, { - name: name, - type: type, - data: { - issuedOnAll: true, - revokedOnAny: false, - details: { - issuance: verificationResult, - revocation: revocationStatus, - }, - }, - status: "VALID", - }]; - } - reason = didSignedDocumentStatus_type_1.InvalidDidSignedIssuanceStatus.guard(verificationResult) - ? verificationResult.reason - : revocation_types_1.InvalidRevocationStatus.guard(revocationStatus) - ? revocationStatus.reason - : undefined; - if (!reason) { - throw new error_2.CodedError("Unable to retrieve the reason of the failure", error_1.OpenAttestationDidSignedDocumentStatusCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); - } - return [2 /*return*/, { - name: name, - type: type, - data: { - issuedOnAll: issuedOnAll, - revokedOnAny: revokedOnAny, - details: { - issuance: verificationResult, - revocation: revocationStatus, - }, - }, - status: "INVALID", - reason: reason, - }]; - } - }); -}); }; -var verify = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - if (open_attestation_1.utils.isSignedWrappedV2Document(document)) { - return [2 /*return*/, verifyV2(document, options)]; - } - else if (open_attestation_1.utils.isSignedWrappedV3Document(document)) { - return [2 /*return*/, verifyV3(document, options)]; - } - throw new error_2.CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", error_1.OpenAttestationDidSignedDocumentStatusCode.UNRECOGNIZED_DOCUMENT, error_1.OpenAttestationDidSignedDocumentStatusCode[error_1.OpenAttestationDidSignedDocumentStatusCode.UNRECOGNIZED_DOCUMENT]); - }); -}); }; -exports.openAttestationDidSignedDocumentStatus = { - skip: skip, - test: test, - verify: errorHandler_1.withCodedErrorHandler(verify, { - name: name, - type: type, - unexpectedErrorCode: error_1.OpenAttestationDidSignedDocumentStatusCode.UNEXPECTED_ERROR, - unexpectedErrorString: error_1.OpenAttestationDidSignedDocumentStatusCode[error_1.OpenAttestationDidSignedDocumentStatusCode.UNEXPECTED_ERROR], - }), -}; diff --git a/dist/cjs/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.js b/dist/cjs/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.js deleted file mode 100644 index 841492a6..00000000 --- a/dist/cjs/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.js +++ /dev/null @@ -1,70 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.InvalidDidSignedDataV3 = exports.ValidDidSignedDataV3 = exports.InvalidDidSignedDataV2 = exports.ValidDidSignedDataV2 = exports.ValidOcspResponseRevoked = exports.ValidOcspResponse = exports.ValidOcspReasonCode = exports.DidSignedIssuanceStatusArray = exports.DidSignedIssuanceStatus = exports.InvalidDidSignedIssuanceStatus = exports.ValidDidSignedIssuanceStatusArray = exports.ValidDidSignedIssuanceStatus = void 0; -var runtypes_1 = require("runtypes"); -var error_1 = require("../../../types/error"); -var revocation_types_1 = require("../revocation.types"); -/** - * DID signed issuance status - */ -exports.ValidDidSignedIssuanceStatus = runtypes_1.Record({ - did: runtypes_1.String, - issued: runtypes_1.Literal(true), -}); -exports.ValidDidSignedIssuanceStatusArray = runtypes_1.Array(exports.ValidDidSignedIssuanceStatus); -exports.InvalidDidSignedIssuanceStatus = runtypes_1.Record({ - did: runtypes_1.String, - issued: runtypes_1.Literal(false), - reason: error_1.Reason, -}); -exports.DidSignedIssuanceStatus = runtypes_1.Union(exports.ValidDidSignedIssuanceStatus, exports.InvalidDidSignedIssuanceStatus); -exports.DidSignedIssuanceStatusArray = runtypes_1.Array(exports.DidSignedIssuanceStatus); -/** - * OCSP response - */ -exports.ValidOcspReasonCode = runtypes_1.Number.withConstraint(function (n) { return n >= 0 && n <= 10 && n != 7; }); -exports.ValidOcspResponse = runtypes_1.Record({ - certificateStatus: revocation_types_1.OcspResponderRevocationStatus, -}); -exports.ValidOcspResponseRevoked = runtypes_1.Record({ - reasonCode: exports.ValidOcspReasonCode, - certificateStatus: revocation_types_1.OcspResponderRevocationStatus, -}); -/** - * Data for v2 Fragments - */ -exports.ValidDidSignedDataV2 = runtypes_1.Record({ - issuedOnAll: runtypes_1.Literal(true), - revokedOnAny: runtypes_1.Literal(false), - details: runtypes_1.Record({ - issuance: exports.ValidDidSignedIssuanceStatusArray, - revocation: revocation_types_1.ValidRevocationStatusArray, - }), -}); -exports.InvalidDidSignedDataV2 = runtypes_1.Record({ - issuedOnAll: runtypes_1.Boolean, - revokedOnAny: runtypes_1.Boolean, - details: runtypes_1.Record({ - issuance: exports.DidSignedIssuanceStatusArray, - revocation: revocation_types_1.RevocationStatusArray, - }), -}); -/** - * Data for v3 Fragments - */ -exports.ValidDidSignedDataV3 = runtypes_1.Record({ - issuedOnAll: runtypes_1.Literal(true), - revokedOnAny: runtypes_1.Literal(false), - details: runtypes_1.Record({ - issuance: exports.ValidDidSignedIssuanceStatus, - revocation: revocation_types_1.ValidRevocationStatus, - }), -}); -exports.InvalidDidSignedDataV3 = runtypes_1.Record({ - issuedOnAll: runtypes_1.Boolean, - revokedOnAny: runtypes_1.Boolean, - details: runtypes_1.Record({ - issuance: exports.DidSignedIssuanceStatus, - revocation: revocation_types_1.RevocationStatus, - }), -}); diff --git a/dist/cjs/verifiers/documentStatus/didSigned/index.js b/dist/cjs/verifiers/documentStatus/didSigned/index.js deleted file mode 100644 index 23b5b0d5..00000000 --- a/dist/cjs/verifiers/documentStatus/didSigned/index.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./didSignedDocumentStatus"), exports); diff --git a/dist/cjs/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.js b/dist/cjs/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.js deleted file mode 100644 index b034f1a1..00000000 --- a/dist/cjs/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.js +++ /dev/null @@ -1,274 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.openAttestationEthereumDocumentStoreStatus = exports.isIssuedOnDocumentStore = exports.getIssuersDocumentStores = void 0; -var open_attestation_1 = require("@govtechsg/open-attestation"); -var document_store_1 = require("@govtechsg/document-store"); -var error_1 = require("../../../types/error"); -var error_2 = require("../../../common/error"); -var errorHandler_1 = require("../../../common/errorHandler"); -var utils_1 = require("../utils"); -var revocation_types_1 = require("../revocation.types"); -var ethereumDocumentStoreStatus_type_1 = require("./ethereumDocumentStoreStatus.type"); -var name = "OpenAttestationEthereumDocumentStoreStatus"; -var type = "DOCUMENT_STATUS"; -// Returns list of all document stores, throws when not all issuers are using document store -var getIssuersDocumentStores = function (document) { - var data = open_attestation_1.getData(document); - return data.issuers.map(function (issuer) { - var documentStoreAddress = issuer.documentStore || issuer.certificateStore; - if (!documentStoreAddress) - throw new error_2.CodedError("Document store address not found in issuer " + issuer.name, error_1.OpenAttestationEthereumDocumentStoreStatusCode.INVALID_ISSUERS, error_1.OpenAttestationEthereumDocumentStoreStatusCode[error_1.OpenAttestationEthereumDocumentStoreStatusCode.INVALID_ISSUERS]); - return documentStoreAddress; - }); -}; -exports.getIssuersDocumentStores = getIssuersDocumentStores; -var isIssuedOnDocumentStore = function (_a) { - var documentStore = _a.documentStore, merkleRoot = _a.merkleRoot, provider = _a.provider; - return __awaiter(void 0, void 0, void 0, function () { - var documentStoreContract, issued, error_3; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - _b.trys.push([0, 3, , 4]); - return [4 /*yield*/, document_store_1.DocumentStoreFactory.connect(documentStore, provider)]; - case 1: - documentStoreContract = _b.sent(); - return [4 /*yield*/, documentStoreContract.isIssued(merkleRoot)]; - case 2: - issued = _b.sent(); - return [2 /*return*/, issued - ? { - issued: true, - address: documentStore, - } - : { - issued: false, - address: documentStore, - reason: { - message: "Document " + merkleRoot + " has not been issued under contract " + documentStore, - code: error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED, - codeString: error_1.OpenAttestationEthereumDocumentStoreStatusCode[error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED], - }, - }]; - case 3: - error_3 = _b.sent(); - // If error can be decoded and it's because of document is not issued, we return false - // Else allow error to continue to bubble up - return [2 /*return*/, { - issued: false, - address: documentStore, - reason: { - message: utils_1.decodeError(error_3), - code: error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED, - codeString: error_1.OpenAttestationEthereumDocumentStoreStatusCode[error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED], - }, - }]; - case 4: return [2 /*return*/]; - } - }); - }); -}; -exports.isIssuedOnDocumentStore = isIssuedOnDocumentStore; -var skip = function () { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, { - status: "SKIPPED", - type: type, - name: name, - reason: { - code: error_1.OpenAttestationEthereumDocumentStoreStatusCode.SKIPPED, - codeString: error_1.OpenAttestationEthereumDocumentStoreStatusCode[error_1.OpenAttestationEthereumDocumentStoreStatusCode.SKIPPED], - message: "Document issuers doesn't have \"documentStore\" or \"certificateStore\" property or " + open_attestation_1.v3.Method.DocumentStore + " method", - }, - }]; - }); -}); }; -var test = function (document) { - if (open_attestation_1.utils.isWrappedV2Document(document)) { - var documentData = open_attestation_1.getData(document); - return documentData.issuers.some(function (issuer) { return "documentStore" in issuer || "certificateStore" in issuer; }); - } - else if (open_attestation_1.utils.isWrappedV3Document(document)) { - return document.openAttestationMetadata.proof.method === open_attestation_1.v3.Method.DocumentStore; - } - return false; -}; -var verifyV2 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - var documentStores, merkleRoot, targetHash, proofs, issuanceStatuses, notIssued, revocationStatuses, revoked; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - documentStores = exports.getIssuersDocumentStores(document); - merkleRoot = "0x" + document.signature.merkleRoot; - targetHash = document.signature.targetHash; - proofs = document.signature.proof || []; - return [4 /*yield*/, Promise.all(documentStores.map(function (documentStore) { - return exports.isIssuedOnDocumentStore({ documentStore: documentStore, merkleRoot: merkleRoot, provider: options.provider }); - }))]; - case 1: - issuanceStatuses = _a.sent(); - notIssued = issuanceStatuses.find(ethereumDocumentStoreStatus_type_1.InvalidDocumentStoreIssuanceStatus.guard); - if (ethereumDocumentStoreStatus_type_1.InvalidDocumentStoreIssuanceStatus.guard(notIssued)) { - return [2 /*return*/, { - name: name, - type: type, - data: { - issuedOnAll: false, - details: { issuance: issuanceStatuses }, - }, - reason: notIssued.reason, - status: "INVALID", - }]; - } - return [4 /*yield*/, Promise.all(documentStores.map(function (documentStore) { - return utils_1.isRevokedOnDocumentStore({ - documentStore: documentStore, - merkleRoot: merkleRoot, - targetHash: targetHash, - proofs: proofs, - provider: options.provider, - }); - }))]; - case 2: - revocationStatuses = _a.sent(); - revoked = revocationStatuses.find(revocation_types_1.InvalidRevocationStatus.guard); - if (revocation_types_1.InvalidRevocationStatus.guard(revoked)) { - return [2 /*return*/, { - name: name, - type: type, - data: { - issuedOnAll: true, - revokedOnAny: true, - details: { issuance: issuanceStatuses, revocation: revocationStatuses }, - }, - reason: revoked.reason, - status: "INVALID", - }]; - } - if (ethereumDocumentStoreStatus_type_1.ValidDocumentStoreIssuanceStatusArray.guard(issuanceStatuses) && - revocation_types_1.ValidRevocationStatusArray.guard(revocationStatuses)) { - return [2 /*return*/, { - name: name, - type: type, - data: { - issuedOnAll: true, - revokedOnAny: false, - details: { issuance: issuanceStatuses, revocation: revocationStatuses }, - }, - status: "VALID", - }]; - } - throw new error_2.CodedError("Reached an unexpected state when verifying v2 document", error_1.OpenAttestationEthereumDocumentStoreStatusCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); - } - }); -}); }; -var verifyV3 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - var _a, merkleRootRaw, targetHash, proofs, merkleRoot, documentStore, issuance, revocation, data, reason; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - _a = document.proof, merkleRootRaw = _a.merkleRoot, targetHash = _a.targetHash, proofs = _a.proofs; - merkleRoot = "0x" + merkleRootRaw; - documentStore = document.openAttestationMetadata.proof.value; - return [4 /*yield*/, exports.isIssuedOnDocumentStore({ documentStore: documentStore, merkleRoot: merkleRoot, provider: options.provider })]; - case 1: - issuance = _b.sent(); - return [4 /*yield*/, utils_1.isRevokedOnDocumentStore({ - documentStore: documentStore, - merkleRoot: merkleRoot, - targetHash: targetHash, - proofs: proofs, - provider: options.provider, - })]; - case 2: - revocation = _b.sent(); - data = { - issuedOnAll: issuance.issued, - revokedOnAny: revocation.revoked, - details: { - issuance: issuance, - revocation: revocation, - }, - }; - if (ethereumDocumentStoreStatus_type_1.ValidDocumentStoreDataV3.guard(data)) { - return [2 /*return*/, { - name: name, - type: type, - data: data, - status: "VALID", - }]; - } - if (revocation_types_1.InvalidRevocationStatus.guard(revocation)) { - reason = revocation.reason; - } - else if (ethereumDocumentStoreStatus_type_1.InvalidDocumentStoreIssuanceStatus.guard(issuance)) { - reason = issuance.reason; - } - if (!reason) { - throw new error_2.CodedError("Unable to retrieve the reason of the failure", error_1.OpenAttestationEthereumDocumentStoreStatusCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); - } - return [2 /*return*/, { - name: name, - type: type, - data: data, - status: "INVALID", - reason: reason, - }]; - } - }); -}); }; -var verify = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - if (open_attestation_1.utils.isWrappedV2Document(document)) - return [2 /*return*/, verifyV2(document, options)]; - else if (open_attestation_1.utils.isWrappedV3Document(document)) - return [2 /*return*/, verifyV3(document, options)]; - throw new error_2.CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", error_1.OpenAttestationEthereumDocumentStoreStatusCode.UNRECOGNIZED_DOCUMENT, error_1.OpenAttestationEthereumDocumentStoreStatusCode[error_1.OpenAttestationEthereumDocumentStoreStatusCode.UNRECOGNIZED_DOCUMENT]); - }); -}); }; -exports.openAttestationEthereumDocumentStoreStatus = { - skip: skip, - test: test, - verify: errorHandler_1.withCodedErrorHandler(verify, { - name: name, - type: type, - unexpectedErrorCode: error_1.OpenAttestationEthereumDocumentStoreStatusCode.UNEXPECTED_ERROR, - unexpectedErrorString: error_1.OpenAttestationEthereumDocumentStoreStatusCode[error_1.OpenAttestationEthereumDocumentStoreStatusCode.UNEXPECTED_ERROR], - }), -}; diff --git a/dist/cjs/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.js b/dist/cjs/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.js deleted file mode 100644 index ca5f7c3b..00000000 --- a/dist/cjs/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.js +++ /dev/null @@ -1,59 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.InvalidDocumentStoreDataV3 = exports.ValidDocumentStoreDataV3 = exports.InvalidDocumentStoreDataV2 = exports.DocumentStoreIssuanceStatusArray = exports.DocumentStoreIssuanceStatus = exports.InvalidDocumentStoreIssuanceStatus = exports.ValidDocumentStoreIssuanceStatusArray = exports.ValidDocumentStoreIssuanceStatus = void 0; -var runtypes_1 = require("runtypes"); -var error_1 = require("../../../types/error"); -var revocation_types_1 = require("../revocation.types"); -/** - * Document store issuance status - */ -exports.ValidDocumentStoreIssuanceStatus = runtypes_1.Record({ - issued: runtypes_1.Literal(true), - address: runtypes_1.String, -}); -exports.ValidDocumentStoreIssuanceStatusArray = runtypes_1.Array(exports.ValidDocumentStoreIssuanceStatus); -exports.InvalidDocumentStoreIssuanceStatus = runtypes_1.Record({ - issued: runtypes_1.Literal(false), - address: runtypes_1.String, - reason: error_1.Reason, -}); -exports.DocumentStoreIssuanceStatus = runtypes_1.Union(exports.ValidDocumentStoreIssuanceStatus, exports.InvalidDocumentStoreIssuanceStatus); -exports.DocumentStoreIssuanceStatusArray = runtypes_1.Array(exports.DocumentStoreIssuanceStatus); -/** - * Data for v2 Fragments - */ -var ValidDocumentStoreDataV2 = runtypes_1.Record({ - issuedOnAll: runtypes_1.Literal(true), - revokedOnAny: runtypes_1.Literal(false), - details: runtypes_1.Record({ - issuance: exports.ValidDocumentStoreIssuanceStatusArray, - revocation: revocation_types_1.ValidRevocationStatusArray, - }), -}); -exports.InvalidDocumentStoreDataV2 = runtypes_1.Record({ - issuedOnAll: runtypes_1.Boolean, - revokedOnAny: runtypes_1.Optional(runtypes_1.Boolean), - details: runtypes_1.Record({ - issuance: exports.DocumentStoreIssuanceStatusArray, - revocation: runtypes_1.Optional(revocation_types_1.RevocationStatusArray), - }), -}); -/** - * Data for v3 Fragments - */ -exports.ValidDocumentStoreDataV3 = runtypes_1.Record({ - issuedOnAll: runtypes_1.Literal(true), - revokedOnAny: runtypes_1.Literal(false), - details: runtypes_1.Record({ - issuance: exports.ValidDocumentStoreIssuanceStatus, - revocation: revocation_types_1.ValidRevocationStatus, - }), -}); -exports.InvalidDocumentStoreDataV3 = runtypes_1.Record({ - issuedOnAll: runtypes_1.Boolean, - revokedOnAny: runtypes_1.Boolean, - details: runtypes_1.Record({ - issuance: exports.DocumentStoreIssuanceStatus, - revocation: revocation_types_1.RevocationStatus, - }), -}); diff --git a/dist/cjs/verifiers/documentStatus/documentStore/index.js b/dist/cjs/verifiers/documentStatus/documentStore/index.js deleted file mode 100644 index 6e7be98a..00000000 --- a/dist/cjs/verifiers/documentStatus/documentStore/index.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./ethereumDocumentStoreStatus"), exports); diff --git a/dist/cjs/verifiers/documentStatus/revocation.types.js b/dist/cjs/verifiers/documentStatus/revocation.types.js deleted file mode 100644 index 0b80e5f9..00000000 --- a/dist/cjs/verifiers/documentStatus/revocation.types.js +++ /dev/null @@ -1,31 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.OcspResponderRevocationReason = exports.OcspResponderRevocationStatus = exports.RevocationStatusArray = exports.RevocationStatus = exports.InvalidRevocationStatus = exports.ValidRevocationStatusArray = exports.ValidRevocationStatus = void 0; -var runtypes_1 = require("runtypes"); -var error_1 = require("../../types/error"); -exports.ValidRevocationStatus = runtypes_1.Record({ - revoked: runtypes_1.Literal(false), - address: runtypes_1.Optional(runtypes_1.String), -}); -exports.ValidRevocationStatusArray = runtypes_1.Array(exports.ValidRevocationStatus); -exports.InvalidRevocationStatus = runtypes_1.Record({ - revoked: runtypes_1.Literal(true), - address: runtypes_1.String, - reason: error_1.Reason, -}); -exports.RevocationStatus = runtypes_1.Union(exports.ValidRevocationStatus, exports.InvalidRevocationStatus); -exports.RevocationStatusArray = runtypes_1.Array(exports.RevocationStatus); -exports.OcspResponderRevocationStatus = runtypes_1.Union(runtypes_1.Literal("good"), runtypes_1.Literal("revoked"), runtypes_1.Literal("unknown")); -var OcspResponderRevocationReason; -(function (OcspResponderRevocationReason) { - OcspResponderRevocationReason[OcspResponderRevocationReason["UNSPECIFIED"] = 0] = "UNSPECIFIED"; - OcspResponderRevocationReason[OcspResponderRevocationReason["KEY_COMPROMISE"] = 1] = "KEY_COMPROMISE"; - OcspResponderRevocationReason[OcspResponderRevocationReason["CA_COMPROMISE"] = 2] = "CA_COMPROMISE"; - OcspResponderRevocationReason[OcspResponderRevocationReason["AFFILIATION_CHANGED"] = 3] = "AFFILIATION_CHANGED"; - OcspResponderRevocationReason[OcspResponderRevocationReason["SUPERSEDED"] = 4] = "SUPERSEDED"; - OcspResponderRevocationReason[OcspResponderRevocationReason["CESSATION_OF_OPERATION"] = 5] = "CESSATION_OF_OPERATION"; - OcspResponderRevocationReason[OcspResponderRevocationReason["CERTIFICATE_HOLD"] = 6] = "CERTIFICATE_HOLD"; - OcspResponderRevocationReason[OcspResponderRevocationReason["REMOVE_FROM_CRL"] = 8] = "REMOVE_FROM_CRL"; - OcspResponderRevocationReason[OcspResponderRevocationReason["PRIVILEGE_WITHDRAWN"] = 9] = "PRIVILEGE_WITHDRAWN"; - OcspResponderRevocationReason[OcspResponderRevocationReason["A_A_COMPROMISE"] = 10] = "A_A_COMPROMISE"; -})(OcspResponderRevocationReason = exports.OcspResponderRevocationReason || (exports.OcspResponderRevocationReason = {})); diff --git a/dist/cjs/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.js b/dist/cjs/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.js deleted file mode 100644 index a5d1c144..00000000 --- a/dist/cjs/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.js +++ /dev/null @@ -1,236 +0,0 @@ -"use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.openAttestationEthereumTokenRegistryStatus = exports.isTokenMintedOnRegistry = exports.getTokenRegistry = void 0; -var open_attestation_1 = require("@govtechsg/open-attestation"); -var token_registry_1 = require("@govtechsg/token-registry"); -var ethers_1 = require("ethers"); -var error_1 = require("../../../types/error"); -var error_2 = require("../../../common/error"); -var errorHandler_1 = require("../../../common/errorHandler"); -var ethereumTokenRegistryStatus_type_1 = require("./ethereumTokenRegistryStatus.type"); -var name = "OpenAttestationEthereumTokenRegistryStatus"; -var type = "DOCUMENT_STATUS"; -var getTokenRegistry = function (document) { - if (open_attestation_1.utils.isWrappedV2Document(document)) { - var issuers = open_attestation_1.getData(document).issuers; - if (issuers.length !== 1) - throw new error_2.CodedError("Only one issuer is allowed for tokens", error_1.OpenAttestationEthereumTokenRegistryStatusCode.INVALID_ISSUERS, error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.INVALID_ISSUERS]); - if (!issuers[0].tokenRegistry) - throw new error_2.CodedError("Token registry is undefined", error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNDEFINED_TOKEN_REGISTRY, error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNDEFINED_TOKEN_REGISTRY]); - return issuers[0].tokenRegistry; - } - if (open_attestation_1.utils.isWrappedV3Document(document)) { - if (!document.openAttestationMetadata.proof.value) - throw new error_2.CodedError("Token registry is undefined", error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNDEFINED_TOKEN_REGISTRY, error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNDEFINED_TOKEN_REGISTRY]); - return document.openAttestationMetadata.proof.value; - } - throw new error_2.CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT, error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT]); -}; -exports.getTokenRegistry = getTokenRegistry; -var getMerkleRoot = function (document) { - if (open_attestation_1.utils.isWrappedV2Document(document)) - return "0x" + document.signature.merkleRoot; - else if (open_attestation_1.utils.isWrappedV3Document(document)) - return "0x" + document.proof.merkleRoot; - throw new error_2.CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT, error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT]); -}; -var isNonExistentToken = function (error) { - var message = error.message; - if (!message) - return false; - return message.includes("owner query for nonexistent token"); -}; -var isMissingTokenRegistry = function (error) { - var _a; - return (!error.reason && - ((_a = error.method) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === "ownerOf(uint256)".toLowerCase() && - error.code === ethers_1.errors.CALL_EXCEPTION); -}; -var decodeError = function (error) { - var _a; - var reason = error.reason && Array.isArray(error.reason) ? error.reason[0] : (_a = error.reason) !== null && _a !== void 0 ? _a : ""; - switch (true) { - case isNonExistentToken(error): - return "Document has not been issued under token registry"; - case isMissingTokenRegistry(error): - return "Token registry is not found"; - case reason.toLowerCase() === "ENS name not configured".toLowerCase() && - error.code === ethers_1.errors.UNSUPPORTED_OPERATION: - return "ENS name is not configured"; - case reason.toLowerCase() === "invalid address".toLowerCase() && error.code === ethers_1.errors.INVALID_ARGUMENT: - return "Invalid token registry address"; - case error.code === ethers_1.errors.INVALID_ARGUMENT: - return "Invalid contract arguments"; - case error.code === ethers_1.errors.SERVER_ERROR: - throw new error_2.CodedError("Unable to connect to the Ethereum network, please try again later", error_1.OpenAttestationEthereumTokenRegistryStatusCode.SERVER_ERROR, error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.SERVER_ERROR]); - default: - throw error; - } -}; -var isTokenMintedOnRegistry = function (_a) { - var tokenRegistry = _a.tokenRegistry, merkleRoot = _a.merkleRoot, provider = _a.provider; - return __awaiter(void 0, void 0, void 0, function () { - var tokenRegistryContract, minted, error_3; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - _b.trys.push([0, 3, , 4]); - return [4 /*yield*/, token_registry_1.TradeTrustErc721Factory.connect(tokenRegistry, provider)]; - case 1: - tokenRegistryContract = _b.sent(); - return [4 /*yield*/, tokenRegistryContract.ownerOf(merkleRoot).then(function (owner) { return !(owner === ethers_1.constants.AddressZero); })]; - case 2: - minted = _b.sent(); - return [2 /*return*/, minted - ? { minted: minted, address: tokenRegistry } - : { - minted: minted, - address: tokenRegistry, - reason: { - code: error_1.OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED, - codeString: error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED], - message: "Document " + merkleRoot + " has not been issued under contract " + tokenRegistry, - }, - }]; - case 3: - error_3 = _b.sent(); - return [2 /*return*/, { - minted: false, - address: tokenRegistry, - reason: { - message: decodeError(error_3), - code: error_1.OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED, - codeString: error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED], - }, - }]; - case 4: return [2 /*return*/]; - } - }); - }); -}; -exports.isTokenMintedOnRegistry = isTokenMintedOnRegistry; -var skip = function () { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, { - status: "SKIPPED", - type: type, - name: name, - reason: { - code: error_1.OpenAttestationEthereumTokenRegistryStatusCode.SKIPPED, - codeString: error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.SKIPPED], - message: "Document issuers doesn't have \"tokenRegistry\" property or " + open_attestation_1.v3.Method.TokenRegistry + " method", - }, - }]; - }); -}); }; -var test = function (document) { - if (open_attestation_1.utils.isWrappedV2Document(document)) { - var documentData = open_attestation_1.getData(document); - return documentData.issuers.some(function (issuer) { return "tokenRegistry" in issuer; }); - } - else if (open_attestation_1.utils.isWrappedV3Document(document)) { - return document.openAttestationMetadata.proof.method === open_attestation_1.v3.Method.TokenRegistry; - } - return false; -}; -// TODO split -var verify = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - var tokenRegistry, merkleRoot, mintStatus, fragment, fragment; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!open_attestation_1.utils.isWrappedV3Document(document) && !open_attestation_1.utils.isWrappedV2Document(document)) - throw new error_2.CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT, error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT]); - tokenRegistry = exports.getTokenRegistry(document); - merkleRoot = getMerkleRoot(document); - return [4 /*yield*/, exports.isTokenMintedOnRegistry({ tokenRegistry: tokenRegistry, merkleRoot: merkleRoot, provider: options.provider })]; - case 1: - mintStatus = _a.sent(); - if (ethereumTokenRegistryStatus_type_1.ValidTokenRegistryStatus.guard(mintStatus)) { - fragment = { - name: name, - type: type, - status: "VALID", - }; - if (open_attestation_1.utils.isWrappedV3Document(document)) { - return [2 /*return*/, __assign(__assign({}, fragment), { data: { mintedOnAll: true, details: mintStatus } })]; - } - else { - return [2 /*return*/, __assign(__assign({}, fragment), { data: { mintedOnAll: true, details: [mintStatus] } })]; - } - } - else { - fragment = { - name: name, - type: type, - reason: mintStatus.reason, - status: "INVALID", - }; - if (open_attestation_1.utils.isWrappedV3Document(document)) { - return [2 /*return*/, __assign(__assign({}, fragment), { data: { mintedOnAll: false, details: mintStatus } })]; - } - else { - return [2 /*return*/, __assign(__assign({}, fragment), { data: { mintedOnAll: false, details: [mintStatus] } })]; - } - } - return [2 /*return*/]; - } - }); -}); }; -exports.openAttestationEthereumTokenRegistryStatus = { - skip: skip, - test: test, - verify: errorHandler_1.withCodedErrorHandler(verify, { - name: name, - type: type, - unexpectedErrorCode: error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNEXPECTED_ERROR, - unexpectedErrorString: error_1.OpenAttestationEthereumTokenRegistryStatusCode[error_1.OpenAttestationEthereumTokenRegistryStatusCode.UNEXPECTED_ERROR], - }), -}; diff --git a/dist/cjs/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.js b/dist/cjs/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.js deleted file mode 100644 index 9bef2751..00000000 --- a/dist/cjs/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.js +++ /dev/null @@ -1,39 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.InvalidTokenRegistryDataV3 = exports.ValidTokenRegistryDataV3 = exports.InvalidTokenRegistryDataV2 = exports.ValidTokenRegistryDataV2 = exports.InvalidTokenRegistryStatus = exports.ValidTokenRegistryStatus = void 0; -var runtypes_1 = require("runtypes"); -var error_1 = require("../../../types/error"); -/** - * Token registry mint status - */ -exports.ValidTokenRegistryStatus = runtypes_1.Record({ - minted: runtypes_1.Literal(true), - address: runtypes_1.String, -}); -exports.InvalidTokenRegistryStatus = runtypes_1.Record({ - minted: runtypes_1.Literal(false), - address: runtypes_1.String, - reason: error_1.Reason, -}); -/** - * Data for v2 Fragments - */ -exports.ValidTokenRegistryDataV2 = runtypes_1.Record({ - mintedOnAll: runtypes_1.Literal(true), - details: runtypes_1.Array(exports.ValidTokenRegistryStatus), -}); -exports.InvalidTokenRegistryDataV2 = runtypes_1.Record({ - mintedOnAll: runtypes_1.Literal(false), - details: runtypes_1.Array(runtypes_1.Union(exports.ValidTokenRegistryStatus, exports.InvalidTokenRegistryStatus)), -}); -/** - * Data for v3 Fragments - */ -exports.ValidTokenRegistryDataV3 = runtypes_1.Record({ - mintedOnAll: runtypes_1.Literal(true), - details: exports.ValidTokenRegistryStatus, -}); -exports.InvalidTokenRegistryDataV3 = runtypes_1.Record({ - mintedOnAll: runtypes_1.Literal(false), - details: exports.InvalidTokenRegistryStatus, -}); diff --git a/dist/cjs/verifiers/documentStatus/tokenRegistry/index.js b/dist/cjs/verifiers/documentStatus/tokenRegistry/index.js deleted file mode 100644 index f926c61a..00000000 --- a/dist/cjs/verifiers/documentStatus/tokenRegistry/index.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./ethereumTokenRegistryStatus"), exports); diff --git a/dist/cjs/verifiers/documentStatus/utils.js b/dist/cjs/verifiers/documentStatus/utils.js deleted file mode 100644 index 2ac42057..00000000 --- a/dist/cjs/verifiers/documentStatus/utils.js +++ /dev/null @@ -1,193 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.isRevokedOnDocumentStore = exports.isRevokedByOcspResponder = exports.isAnyHashRevoked = exports.decodeError = exports.getIntermediateHashes = void 0; -var open_attestation_1 = require("@govtechsg/open-attestation"); -var ethers_1 = require("ethers"); -var document_store_1 = require("@govtechsg/document-store"); -var error_1 = require("../../types/error"); -var error_2 = require("../../common/error"); -var revocation_types_1 = require("./revocation.types"); -var axios_1 = __importDefault(require("axios")); -var didSignedDocumentStatus_type_1 = require("./didSigned/didSignedDocumentStatus.type"); -var getIntermediateHashes = function (targetHash, proofs) { - if (proofs === void 0) { proofs = []; } - var hashes = ["0x" + targetHash]; - proofs.reduce(function (prev, curr) { - var next = open_attestation_1.utils.combineHashString(prev, curr); - hashes.push("0x" + next); - return next; - }, targetHash); - return hashes; -}; -exports.getIntermediateHashes = getIntermediateHashes; -/** - * Try to decode the error to see if we can deterministically tell if the document has NOT been issued or revoked. - * - * In case where we cannot tell, we throw an error - * */ -var decodeError = function (error) { - var _a, _b, _c, _d; - var reason = error.reason && Array.isArray(error.reason) ? error.reason[0] : (_a = error.reason) !== null && _a !== void 0 ? _a : ""; - switch (true) { - case !error.reason && - (((_b = error.method) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === "isRevoked(bytes32)".toLowerCase() || - ((_c = error.method) === null || _c === void 0 ? void 0 : _c.toLowerCase()) === "isIssued(bytes32)".toLowerCase()) && - error.code === ethers_1.errors.CALL_EXCEPTION: - return "Contract is not found"; - case reason.toLowerCase() === "ENS name not configured".toLowerCase() && - error.code === ethers_1.errors.UNSUPPORTED_OPERATION: - return "ENS name is not configured"; - case reason.toLowerCase() === "bad address checksum".toLowerCase() && error.code === ethers_1.errors.INVALID_ARGUMENT: - return "Bad document store address checksum"; - case ((_d = error.message) === null || _d === void 0 ? void 0 : _d.toLowerCase()) === "name not found".toLowerCase(): - return "ENS name is not found"; - case reason.toLowerCase() === "invalid address".toLowerCase() && error.code === ethers_1.errors.INVALID_ARGUMENT: - return "Invalid document store address"; - case error.code === ethers_1.errors.INVALID_ARGUMENT: - return "Invalid call arguments"; - case error.code === ethers_1.errors.SERVER_ERROR: - throw new error_2.CodedError("Unable to connect to the Ethereum network, please try again later", error_1.OpenAttestationEthereumDocumentStoreStatusCode.SERVER_ERROR, error_1.OpenAttestationEthereumDocumentStoreStatusCode[error_1.OpenAttestationEthereumDocumentStoreStatusCode.SERVER_ERROR]); - default: - throw error; - } -}; -exports.decodeError = decodeError; -/** - * Given a list of hashes, check against one smart contract if any of the hash has been revoked - * */ -var isAnyHashRevoked = function (smartContract, intermediateHashes) { return __awaiter(void 0, void 0, void 0, function () { - var revokedStatusDeferred, revokedStatuses; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - revokedStatusDeferred = intermediateHashes.map(function (hash) { - return smartContract.isRevoked(hash).then(function (status) { return (status ? hash : undefined); }); - }); - return [4 /*yield*/, Promise.all(revokedStatusDeferred)]; - case 1: - revokedStatuses = _a.sent(); - return [2 /*return*/, revokedStatuses.find(function (hash) { return hash; })]; - } - }); -}); }; -exports.isAnyHashRevoked = isAnyHashRevoked; -var isRevokedByOcspResponder = function (_a) { - var certificateId = _a.certificateId, location = _a.location; - return __awaiter(void 0, void 0, void 0, function () { - var data, reasonCode; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: return [4 /*yield*/, axios_1.default.get(location + "/" + certificateId)]; - case 1: - data = (_b.sent()).data; - if (didSignedDocumentStatus_type_1.ValidOcspResponseRevoked.guard(data) && data.certificateStatus === "revoked") { - reasonCode = data.reasonCode; - return [2 /*return*/, { - revoked: true, - address: location, - reason: { - message: revocation_types_1.OcspResponderRevocationReason[reasonCode], - code: reasonCode, - codeString: revocation_types_1.OcspResponderRevocationReason[reasonCode], - }, - }]; - } - else if (didSignedDocumentStatus_type_1.ValidOcspResponse.guard(data) && data.certificateStatus !== "revoked") { - return [2 /*return*/, { - revoked: false, - address: location, - }]; - } - throw new error_2.CodedError("oscp response invalid", error_1.OpenAttestationDidSignedDocumentStatusCode.OCSP_RESPONSE_INVALID, "OCSP_RESPONSE_INVALID"); - } - }); - }); -}; -exports.isRevokedByOcspResponder = isRevokedByOcspResponder; -var isRevokedOnDocumentStore = function (_a) { - var documentStore = _a.documentStore, merkleRoot = _a.merkleRoot, provider = _a.provider, targetHash = _a.targetHash, proofs = _a.proofs; - return __awaiter(void 0, void 0, void 0, function () { - var documentStoreContract, intermediateHashes, revokedHash, error_3; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - _b.trys.push([0, 3, , 4]); - return [4 /*yield*/, document_store_1.DocumentStoreFactory.connect(documentStore, provider)]; - case 1: - documentStoreContract = _b.sent(); - intermediateHashes = exports.getIntermediateHashes(targetHash, proofs); - return [4 /*yield*/, exports.isAnyHashRevoked(documentStoreContract, intermediateHashes)]; - case 2: - revokedHash = _b.sent(); - return [2 /*return*/, revokedHash - ? { - revoked: true, - address: documentStore, - reason: { - message: "Document " + merkleRoot + " has been revoked under contract " + documentStore, - code: error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED, - codeString: error_1.OpenAttestationEthereumDocumentStoreStatusCode[error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED], - }, - } - : { - revoked: false, - address: documentStore, - }]; - case 3: - error_3 = _b.sent(); - // If error can be decoded and it's because of document is not revoked, we return false - // Else allow error to continue to bubble up - return [2 /*return*/, { - revoked: true, - address: documentStore, - reason: { - message: exports.decodeError(error_3), - code: error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED, - codeString: error_1.OpenAttestationEthereumDocumentStoreStatusCode[error_1.OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED], - }, - }]; - case 4: return [2 /*return*/]; - } - }); - }); -}; -exports.isRevokedOnDocumentStore = isRevokedOnDocumentStore; diff --git a/dist/cjs/verifiers/issuerIdentity/did/didIdentityProof.js b/dist/cjs/verifiers/issuerIdentity/did/didIdentityProof.js deleted file mode 100644 index 10044c58..00000000 --- a/dist/cjs/verifiers/issuerIdentity/did/didIdentityProof.js +++ /dev/null @@ -1,185 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.openAttestationDidIdentityProof = void 0; -var open_attestation_1 = require("@govtechsg/open-attestation"); -var error_1 = require("../../../types/error"); -var verifier_1 = require("../../../did/verifier"); -var errorHandler_1 = require("../../../common/errorHandler"); -var error_2 = require("../../../common/error"); -var name = "OpenAttestationDidIdentityProof"; -var type = "ISSUER_IDENTITY"; -var skip = function () { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, { - status: "SKIPPED", - type: type, - name: name, - reason: { - code: error_1.OpenAttestationDidCode.SKIPPED, - codeString: error_1.OpenAttestationDidCode[error_1.OpenAttestationDidCode.SKIPPED], - message: "Document is not using DID as top level identifier or has not been wrapped", - }, - }]; - }); -}); }; -var test = function (document) { - if (open_attestation_1.utils.isWrappedV2Document(document)) { - var issuers = open_attestation_1.getData(document).issuers; - return issuers.some(function (issuer) { var _a; return ((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === open_attestation_1.v2.IdentityProofType.Did; }); - } - else if (open_attestation_1.utils.isWrappedV3Document(document)) { - return document.openAttestationMetadata.identityProof.type === open_attestation_1.v3.IdentityProofType.Did; - } - return false; -}; -var verifyV2 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - var data, merkleRoot, signatureVerificationDeferred, signatureVerifications, invalidSignature; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!open_attestation_1.utils.isSignedWrappedV2Document(document)) - throw new error_2.CodedError("Document is not signed", error_1.OpenAttestationDidCode.UNSIGNED, "UNSIGNED"); - data = open_attestation_1.getData(document); - merkleRoot = "0x" + document.signature.merkleRoot; - signatureVerificationDeferred = data.issuers.map(function (issuer) { return __awaiter(void 0, void 0, void 0, function () { - var did, key_1, correspondingProof; - var _a, _b; - return __generator(this, function (_c) { - if (((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === "DID") { - did = issuer.id; - if (!did) - throw new error_2.CodedError("id is missing in issuer", error_1.OpenAttestationDidCode.DID_MISSING, "DID_MISSING"); - key_1 = (_b = issuer.identityProof) === null || _b === void 0 ? void 0 : _b.key; - if (!key_1) - throw new error_2.CodedError("Key is not present", error_1.OpenAttestationDidCode.MALFORMED_IDENTITY_PROOF, "MALFORMED_IDENTITY_PROOF"); - correspondingProof = document.proof.find(function (p) { return p.verificationMethod.toLowerCase() === key_1.toLowerCase(); }); - if (!correspondingProof) - throw new error_2.CodedError("No proof for " + key_1, error_1.OpenAttestationDidCode.MALFORMED_IDENTITY_PROOF, "MALFORMED_IDENTITY_PROOF"); - return [2 /*return*/, verifier_1.verifySignature({ - merkleRoot: merkleRoot, - key: key_1, - signature: correspondingProof.signature, - did: did, - resolver: options.resolver, - })]; - } - throw new error_2.CodedError("Issuer is not using DID identityProof type", error_1.OpenAttestationDidCode.INVALID_ISSUERS, error_1.OpenAttestationDidCode[error_1.OpenAttestationDidCode.INVALID_ISSUERS]); - }); - }); }); - return [4 /*yield*/, Promise.all(signatureVerificationDeferred)]; - case 1: - signatureVerifications = _a.sent(); - if (verifier_1.ValidDidVerificationStatusArray.guard(signatureVerifications)) { - return [2 /*return*/, { - name: name, - type: type, - data: signatureVerifications, - status: "VALID", - }]; - } - invalidSignature = signatureVerifications.find(verifier_1.InvalidDidVerificationStatus.guard); - if (verifier_1.InvalidDidVerificationStatus.guard(invalidSignature)) { - return [2 /*return*/, { - name: name, - type: type, - data: signatureVerifications, - reason: invalidSignature.reason, - status: "INVALID", - }]; - } - throw new error_2.CodedError("Unable to retrieve the reason of the failure", error_1.OpenAttestationDidCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); - } - }); -}); }; -var verifyV3 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - var merkleRoot, _a, key, signature, did, verificationStatus; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - if (!open_attestation_1.utils.isSignedWrappedV3Document(document)) - throw new error_2.CodedError("Document is not signed", error_1.OpenAttestationDidCode.UNSIGNED, "UNSIGNED"); - merkleRoot = "0x" + document.proof.merkleRoot; - _a = document.proof, key = _a.key, signature = _a.signature; - did = document.openAttestationMetadata.identityProof.identifier; - return [4 /*yield*/, verifier_1.verifySignature({ - did: did, - merkleRoot: merkleRoot, - key: key, - signature: signature, - resolver: options.resolver, - })]; - case 1: - verificationStatus = _b.sent(); - if (verifier_1.ValidDidVerificationStatus.guard(verificationStatus)) { - return [2 /*return*/, { - name: name, - type: type, - data: verificationStatus, - status: "VALID", - }]; - } - return [2 /*return*/, { - name: name, - type: type, - data: verificationStatus, - reason: verificationStatus.reason, - status: "INVALID", - }]; - } - }); -}); }; -var verify = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - if (open_attestation_1.utils.isWrappedV2Document(document)) - return [2 /*return*/, verifyV2(document, options)]; - else if (open_attestation_1.utils.isWrappedV3Document(document)) - return [2 /*return*/, verifyV3(document, options)]; - throw new error_2.CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", error_1.OpenAttestationDidCode.UNRECOGNIZED_DOCUMENT, error_1.OpenAttestationDidCode[error_1.OpenAttestationDidCode.UNRECOGNIZED_DOCUMENT]); - }); -}); }; -exports.openAttestationDidIdentityProof = { - skip: skip, - test: test, - verify: errorHandler_1.withCodedErrorHandler(verify, { - name: name, - type: type, - unexpectedErrorCode: error_1.OpenAttestationDidCode.UNEXPECTED_ERROR, - unexpectedErrorString: error_1.OpenAttestationDidCode[error_1.OpenAttestationDidCode.UNEXPECTED_ERROR], - }), -}; diff --git a/dist/cjs/verifiers/issuerIdentity/did/didIdentityProof.type.js b/dist/cjs/verifiers/issuerIdentity/did/didIdentityProof.type.js deleted file mode 100644 index c8ad2e54..00000000 --- a/dist/cjs/verifiers/issuerIdentity/did/didIdentityProof.type.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/cjs/verifiers/issuerIdentity/did/index.js b/dist/cjs/verifiers/issuerIdentity/did/index.js deleted file mode 100644 index 958a1609..00000000 --- a/dist/cjs/verifiers/issuerIdentity/did/index.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./didIdentityProof"), exports); diff --git a/dist/cjs/verifiers/issuerIdentity/dnsDid/dnsDidProof.js b/dist/cjs/verifiers/issuerIdentity/dnsDid/dnsDidProof.js deleted file mode 100644 index b267d3ca..00000000 --- a/dist/cjs/verifiers/issuerIdentity/dnsDid/dnsDidProof.js +++ /dev/null @@ -1,186 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.openAttestationDnsDidIdentityProof = void 0; -var open_attestation_1 = require("@govtechsg/open-attestation"); -var dnsprove_1 = require("@govtechsg/dnsprove"); -var error_1 = require("../../../types/error"); -var errorHandler_1 = require("../../../common/errorHandler"); -var error_2 = require("../../../common/error"); -var dnsDidProof_type_1 = require("./dnsDidProof.type"); -var name = "OpenAttestationDnsDidIdentityProof"; -var type = "ISSUER_IDENTITY"; -var skip = function () { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, { - status: "SKIPPED", - type: type, - name: name, - reason: { - code: error_1.OpenAttestationDnsDidCode.SKIPPED, - codeString: error_1.OpenAttestationDnsDidCode[error_1.OpenAttestationDnsDidCode.SKIPPED], - message: "Document was not issued using DNS-DID", - }, - }]; - }); -}); }; -var test = function (document) { - if (open_attestation_1.utils.isSignedWrappedV2Document(document)) { - var data = open_attestation_1.getData(document); - return data.issuers.some(function (issuer) { var _a; return ((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === "DNS-DID"; }); - } - else if (open_attestation_1.utils.isSignedWrappedV3Document(document)) { - return document.openAttestationMetadata.identityProof.type === open_attestation_1.v3.IdentityProofType.DNSDid; - } - return false; -}; -var verifyIssuerDnsDid = function (_a) { - var key = _a.key, location = _a.location; - return __awaiter(void 0, void 0, void 0, function () { - var records; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: return [4 /*yield*/, dnsprove_1.getDnsDidRecords(location)]; - case 1: - records = _b.sent(); - return [2 /*return*/, { - location: location, - key: key, - status: records.some(function (record) { return record.publicKey.toLowerCase() === key.toLowerCase(); }) ? "VALID" : "INVALID", - }]; - } - }); - }); -}; -var verifyV2 = function (document) { return __awaiter(void 0, void 0, void 0, function () { - var documentData, deferredVerificationStatus, verificationStatus; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - documentData = open_attestation_1.getData(document); - deferredVerificationStatus = documentData.issuers.map(function (issuer) { - var identityProof = issuer.identityProof; - if (!identityProof) - throw new error_2.CodedError("Identity proof missing", error_1.OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF, error_1.OpenAttestationDnsDidCode[error_1.OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF]); - var key = identityProof.key, location = identityProof.location, identityProofType = identityProof.type; - if (identityProofType !== open_attestation_1.v2.IdentityProofType.DNSDid) - throw new error_2.CodedError("Issuer is not using DID-DNS identityProof type", error_1.OpenAttestationDnsDidCode.INVALID_ISSUERS, error_1.OpenAttestationDnsDidCode[error_1.OpenAttestationDnsDidCode.INVALID_ISSUERS]); - if (!location) - throw new error_2.CodedError("location is not present in identity proof", error_1.OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF, error_1.OpenAttestationDnsDidCode[error_1.OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF]); - if (!key) - throw new error_2.CodedError("key is not present in identity proof", error_1.OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF, error_1.OpenAttestationDnsDidCode[error_1.OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF]); - return verifyIssuerDnsDid({ key: key, location: location }); - }); - return [4 /*yield*/, Promise.all(deferredVerificationStatus)]; - case 1: - verificationStatus = _a.sent(); - if (dnsDidProof_type_1.ValidDnsDidVerificationStatusArray.guard(verificationStatus)) { - return [2 /*return*/, { - name: name, - type: type, - data: verificationStatus, - status: "VALID", - }]; - } - return [2 /*return*/, { - name: name, - type: type, - data: verificationStatus, - reason: { - message: "Could not find identity at location", - code: error_1.OpenAttestationDnsDidCode.INVALID_IDENTITY, - codeString: "INVALID_IDENTITY", - }, - status: "INVALID", - }]; - } - }); -}); }; -var verifyV3 = function (document) { return __awaiter(void 0, void 0, void 0, function () { - var location, key, verificationStatus; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!open_attestation_1.utils.isSignedWrappedV3Document(document)) - throw new error_2.CodedError("document is not signed", error_1.OpenAttestationDnsDidCode.UNSIGNED, error_1.OpenAttestationDnsDidCode[error_1.OpenAttestationDnsDidCode.UNSIGNED]); - location = document.openAttestationMetadata.identityProof.identifier; - key = document.proof.key; - return [4 /*yield*/, verifyIssuerDnsDid({ key: key, location: location })]; - case 1: - verificationStatus = _a.sent(); - if (dnsDidProof_type_1.ValidDnsDidVerificationStatus.guard(verificationStatus)) { - return [2 /*return*/, { - name: name, - type: type, - data: verificationStatus, - status: "VALID", - }]; - } - return [2 /*return*/, { - name: name, - type: type, - data: verificationStatus, - status: "INVALID", - reason: { - message: "Could not find identity at location", - code: error_1.OpenAttestationDnsDidCode.INVALID_IDENTITY, - codeString: "INVALID_IDENTITY", - }, - }]; - } - }); -}); }; -var verify = function (document) { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - if (open_attestation_1.utils.isSignedWrappedV2Document(document)) - return [2 /*return*/, verifyV2(document)]; - else if (open_attestation_1.utils.isSignedWrappedV3Document(document)) - return [2 /*return*/, verifyV3(document)]; - throw new error_2.CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", error_1.OpenAttestationDnsDidCode.UNRECOGNIZED_DOCUMENT, error_1.OpenAttestationDnsDidCode[error_1.OpenAttestationDnsDidCode.UNRECOGNIZED_DOCUMENT]); - }); -}); }; -exports.openAttestationDnsDidIdentityProof = { - skip: skip, - test: test, - verify: errorHandler_1.withCodedErrorHandler(verify, { - name: name, - type: type, - unexpectedErrorCode: error_1.OpenAttestationDnsDidCode.UNEXPECTED_ERROR, - unexpectedErrorString: error_1.OpenAttestationDnsDidCode[error_1.OpenAttestationDnsDidCode.UNEXPECTED_ERROR], - }), -}; diff --git a/dist/cjs/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.js b/dist/cjs/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.js deleted file mode 100644 index f3022636..00000000 --- a/dist/cjs/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.js +++ /dev/null @@ -1,20 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.DnsDidVerificationStatusArray = exports.DnsDidVerificationStatus = exports.InvalidDnsDidVerificationStatus = exports.ValidDnsDidVerificationStatusArray = exports.ValidDnsDidVerificationStatus = void 0; -var runtypes_1 = require("runtypes"); -/** - * DNS-DID verification status - */ -exports.ValidDnsDidVerificationStatus = runtypes_1.Record({ - status: runtypes_1.Literal("VALID"), - location: runtypes_1.String, - key: runtypes_1.String, -}); -exports.ValidDnsDidVerificationStatusArray = runtypes_1.Array(exports.ValidDnsDidVerificationStatus).withConstraint(function (elements) { return elements.length > 0 || "Expect at least one valid element"; }); -exports.InvalidDnsDidVerificationStatus = runtypes_1.Record({ - status: runtypes_1.Literal("INVALID"), - location: runtypes_1.String, - key: runtypes_1.String, -}); -exports.DnsDidVerificationStatus = runtypes_1.Union(exports.ValidDnsDidVerificationStatus, exports.InvalidDnsDidVerificationStatus); -exports.DnsDidVerificationStatusArray = runtypes_1.Array(exports.DnsDidVerificationStatus); diff --git a/dist/cjs/verifiers/issuerIdentity/dnsDid/index.js b/dist/cjs/verifiers/issuerIdentity/dnsDid/index.js deleted file mode 100644 index ff72a0fb..00000000 --- a/dist/cjs/verifiers/issuerIdentity/dnsDid/index.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./dnsDidProof"), exports); diff --git a/dist/cjs/verifiers/issuerIdentity/dnsTxt/index.js b/dist/cjs/verifiers/issuerIdentity/dnsTxt/index.js deleted file mode 100644 index 33f18d67..00000000 --- a/dist/cjs/verifiers/issuerIdentity/dnsTxt/index.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./openAttestationDnsTxt"), exports); diff --git a/dist/cjs/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.js b/dist/cjs/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.js deleted file mode 100644 index 1fb5e045..00000000 --- a/dist/cjs/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.js +++ /dev/null @@ -1,220 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.openAttestationDnsTxtIdentityProof = void 0; -var open_attestation_1 = require("@govtechsg/open-attestation"); -var dnsprove_1 = require("@govtechsg/dnsprove"); -var error_1 = require("../../../types/error"); -var errorHandler_1 = require("../../../common/errorHandler"); -var error_2 = require("../../../common/error"); -var openAttestationDnsTxt_type_1 = require("./openAttestationDnsTxt.type"); -var name = "OpenAttestationDnsTxtIdentityProof"; -var type = "ISSUER_IDENTITY"; -// Resolve identity of an issuer, currently supporting only DNS-TXT -// DNS-TXT is explained => https://github.com/Open-Attestation/adr/blob/master/decentralized_identity_proof_DNS-TXT.md -var resolveIssuerIdentity = function (location, smartContractAddress, options) { return __awaiter(void 0, void 0, void 0, function () { - var network, records, matchingRecord; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, options.provider.getNetwork()]; - case 1: - network = _a.sent(); - return [4 /*yield*/, dnsprove_1.getDocumentStoreRecords(location)]; - case 2: - records = _a.sent(); - matchingRecord = records.find(function (record) { - return record.addr.toLowerCase() === smartContractAddress.toLowerCase() && - record.netId === network.chainId.toString(10) && - record.type === "openatts" && - record.net === "ethereum"; - }); - return [2 /*return*/, matchingRecord - ? { - status: "VALID", - location: location, - value: smartContractAddress, - } - : { - status: "INVALID", - location: location, - value: smartContractAddress, - reason: { - message: "Matching DNS record not found for " + smartContractAddress, - code: error_1.OpenAttestationDnsTxtCode.MATCHING_RECORD_NOT_FOUND, - codeString: error_1.OpenAttestationDnsTxtCode[error_1.OpenAttestationDnsTxtCode.MATCHING_RECORD_NOT_FOUND], - }, - }]; - } - }); -}); }; -var skip = function () { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, { - status: "SKIPPED", - type: type, - name: name, - reason: { - code: error_1.OpenAttestationDnsTxtCode.SKIPPED, - codeString: error_1.OpenAttestationDnsTxtCode[error_1.OpenAttestationDnsTxtCode.SKIPPED], - message: "Document issuers doesn't have \"documentStore\" / \"tokenRegistry\" property or doesn't use " + open_attestation_1.v3.IdentityProofType.DNSTxt + " type", - }, - }]; - }); -}); }; -var test = function (document) { - if (open_attestation_1.utils.isWrappedV2Document(document)) { - var documentData = open_attestation_1.getData(document); - // at least one issuer uses DNS-TXT - return documentData.issuers.some(function (issuer) { - var _a; - return ((issuer.documentStore || issuer.tokenRegistry || issuer.certificateStore) && - ((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === open_attestation_1.v2.IdentityProofType.DNSTxt); - }); - } - else if (open_attestation_1.utils.isWrappedV3Document(document)) { - return document.openAttestationMetadata.identityProof.type === open_attestation_1.v3.IdentityProofType.DNSTxt; - } - return false; -}; -var verifyV2 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - var documentData, identities, invalidIdentity; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - documentData = open_attestation_1.getData(document); - return [4 /*yield*/, Promise.all(documentData.issuers.map(function (issuer) { - var _a; - if (((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === open_attestation_1.v2.IdentityProofType.DNSTxt) { - var location = issuer.identityProof.location; - var smartContractAddress = issuer.documentStore || issuer.tokenRegistry || issuer.certificateStore; - if (!location) - throw new error_2.CodedError("Location not found in identity proof", error_1.OpenAttestationDnsTxtCode.INVALID_ISSUERS, error_1.OpenAttestationDnsTxtCode[error_1.OpenAttestationDnsTxtCode.INVALID_ISSUERS]); - if (!smartContractAddress) - throw new error_2.CodedError("Smart contract address not found in identity proof", error_1.OpenAttestationDnsTxtCode.INVALID_ISSUERS, error_1.OpenAttestationDnsTxtCode[error_1.OpenAttestationDnsTxtCode.INVALID_ISSUERS]); - return resolveIssuerIdentity(location, smartContractAddress, options); - } - var invalidResponse = { - status: "INVALID", - reason: { - message: "Issuer is not using DNS-TXT identityProof type", - code: error_1.OpenAttestationDnsTxtCode.INVALID_ISSUERS, - codeString: error_1.OpenAttestationDnsTxtCode[error_1.OpenAttestationDnsTxtCode.INVALID_ISSUERS], - }, - }; - return invalidResponse; // eslint is happy, so am I (https://github.com/bradzacher/eslint-plugin-typescript/blob/master/docs/rules/no-object-literal-type-assertion.md) - }))]; - case 1: - identities = _a.sent(); - if (openAttestationDnsTxt_type_1.ValidDnsTxtVerificationStatusArray.guard(identities)) { - return [2 /*return*/, { - name: name, - type: type, - data: identities, - status: "VALID", - }]; - } - invalidIdentity = identities.find(openAttestationDnsTxt_type_1.InvalidDnsTxtVerificationStatus.guard); - if (openAttestationDnsTxt_type_1.InvalidDnsTxtVerificationStatus.guard(invalidIdentity)) { - return [2 /*return*/, { - name: name, - type: type, - data: identities, - reason: invalidIdentity.reason, - status: "INVALID", - }]; - } - throw new error_2.CodedError("Unable to retrieve the reason of the failure", error_1.OpenAttestationDnsTxtCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); - } - }); -}); }; -var verifyV3 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - var smartContractAddress, identifier, issuerIdentity; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (document.openAttestationMetadata.proof.method !== open_attestation_1.v3.Method.DocumentStore && - document.openAttestationMetadata.proof.method !== open_attestation_1.v3.Method.TokenRegistry) - throw new error_2.CodedError("DNS-TXT is only supported with documents issued using document store or token registry", error_1.OpenAttestationDnsTxtCode.UNSUPPORTED, error_1.OpenAttestationDnsTxtCode[error_1.OpenAttestationDnsTxtCode.UNSUPPORTED]); - smartContractAddress = document.openAttestationMetadata.proof.value; - identifier = document.openAttestationMetadata.identityProof.identifier; - return [4 /*yield*/, resolveIssuerIdentity(identifier, smartContractAddress, options)]; - case 1: - issuerIdentity = _a.sent(); - if (openAttestationDnsTxt_type_1.ValidDnsTxtVerificationStatus.guard(issuerIdentity)) { - return [2 /*return*/, { - name: name, - type: type, - data: { - identifier: issuerIdentity.location, - value: issuerIdentity.value, - }, - status: "VALID", - }]; - } - return [2 /*return*/, { - name: name, - type: type, - data: { - identifier: issuerIdentity.location, - value: issuerIdentity.value, - }, - reason: issuerIdentity.reason, - status: "INVALID", - }]; - } - }); -}); }; -exports.openAttestationDnsTxtIdentityProof = { - skip: skip, - test: test, - verify: errorHandler_1.withCodedErrorHandler(function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - if (open_attestation_1.utils.isWrappedV2Document(document)) - return [2 /*return*/, verifyV2(document, options)]; - else if (open_attestation_1.utils.isWrappedV3Document(document)) - return [2 /*return*/, verifyV3(document, options)]; - // this code is actually unreachable because of the test function - throw new error_2.CodedError("Document does not match either v2 or v3 formats", error_1.OpenAttestationDnsTxtCode.UNRECOGNIZED_DOCUMENT, error_1.OpenAttestationDnsTxtCode[error_1.OpenAttestationDnsTxtCode.UNRECOGNIZED_DOCUMENT]); - }); - }); }, { - name: name, - type: type, - unexpectedErrorCode: error_1.OpenAttestationDnsTxtCode.UNEXPECTED_ERROR, - unexpectedErrorString: error_1.OpenAttestationDnsTxtCode[error_1.OpenAttestationDnsTxtCode.UNEXPECTED_ERROR], - }), -}; diff --git a/dist/cjs/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.js b/dist/cjs/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.js deleted file mode 100644 index a32e90b6..00000000 --- a/dist/cjs/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.js +++ /dev/null @@ -1,33 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.DnsTxtVerificationStatusDataV3 = exports.InvalidDnsTxtVerificationStatusDataV3 = exports.ValidDnsTxtVerificationStatusDataV3 = exports.DnsTxtVerificationStatusArray = exports.DnsTxtVerificationStatus = exports.InvalidDnsTxtVerificationStatus = exports.ValidDnsTxtVerificationStatusArray = exports.ValidDnsTxtVerificationStatus = void 0; -var runtypes_1 = require("runtypes"); -var error_1 = require("../../../types/error"); -/** - * DNS-TXT verification status - */ -exports.ValidDnsTxtVerificationStatus = runtypes_1.Record({ - status: runtypes_1.Literal("VALID"), - location: runtypes_1.String, - value: runtypes_1.String, -}); -exports.ValidDnsTxtVerificationStatusArray = runtypes_1.Array(exports.ValidDnsTxtVerificationStatus).withConstraint(function (elements) { return elements.length > 0 || "Expect at least one valid element"; }); -exports.InvalidDnsTxtVerificationStatus = runtypes_1.Record({ - status: runtypes_1.Literal("INVALID"), - location: runtypes_1.Optional(runtypes_1.String), - value: runtypes_1.Optional(runtypes_1.String), - reason: error_1.Reason, -}); -exports.DnsTxtVerificationStatus = runtypes_1.Union(exports.ValidDnsTxtVerificationStatus, exports.InvalidDnsTxtVerificationStatus); -exports.DnsTxtVerificationStatusArray = runtypes_1.Array(exports.DnsTxtVerificationStatus); -/** - * Data for v3 Fragments - */ -exports.ValidDnsTxtVerificationStatusDataV3 = runtypes_1.Record({ - identifier: runtypes_1.String, - value: runtypes_1.String, -}); -// by design runtypes will validate arrays when an object has only partial properties -// https://github.com/pelotom/runtypes/issues/32 -exports.InvalidDnsTxtVerificationStatusDataV3 = exports.ValidDnsTxtVerificationStatusDataV3.asPartial().withConstraint(function (value) { return !Array.isArray(value) || "can't be an array"; }); -exports.DnsTxtVerificationStatusDataV3 = runtypes_1.Union(exports.ValidDnsTxtVerificationStatusDataV3, exports.InvalidDnsTxtVerificationStatusDataV3); diff --git a/dist/cjs/verifiers/verificationBuilder.js b/dist/cjs/verifiers/verificationBuilder.js deleted file mode 100644 index c58340fe..00000000 --- a/dist/cjs/verifiers/verificationBuilder.js +++ /dev/null @@ -1,37 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.verificationBuilder = void 0; -var utils_1 = require("../common/utils"); -var messages_1 = require("../common/messages"); -// keeping the following code for posterity. If we want the function below to return better types, we can use the following -// type PromiseValue = T extends Promise ? U : never; -// Promise>[]> -/** - * A verification manager will run a list of {@link Verifier} over a signed document. - * Before running each verifier, the manager will make sure the verifier can handle the specific document by calling its exposed test function. - * The manager will return the consolidated list of {@link VerificationFragment} - */ -var displayWarning = true; -var verificationBuilder = function (verifiers, builderOptions) { return function (document, promisesCallback) { - // if the user didn't configure an API key and didn't configure a provider or a resolver, then he will likely use a development key. We then warn him once, that he may need to configure things properly, especially for production - if (displayWarning && - (!builderOptions.resolver || !builderOptions.provider) && - !process.env.INFURA_API_KEY && - !process.env.PROVIDER_API_KEY) { - displayWarning = false; - console.warn(messages_1.warnProvider); - } - var verifierOptions = { - provider: utils_1.getProvider(builderOptions), - resolver: builderOptions.resolver, - }; - var promises = verifiers.map(function (verifier) { - if (verifier.test(document, verifierOptions)) { - return verifier.verify(document, verifierOptions); - } - return verifier.skip(document, verifierOptions); - }); - promisesCallback === null || promisesCallback === void 0 ? void 0 : promisesCallback(promises); - return Promise.all(promises); -}; }; -exports.verificationBuilder = verificationBuilder; diff --git a/dist/esm/common/error.js b/dist/esm/common/error.js deleted file mode 100644 index 10f86e14..00000000 --- a/dist/esm/common/error.js +++ /dev/null @@ -1,26 +0,0 @@ -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var CodedError = /** @class */ (function (_super) { - __extends(CodedError, _super); - function CodedError(message, code, codeString) { - var _this = _super.call(this, message) || this; - _this.code = code; - _this.codeString = codeString; - return _this; - } - return CodedError; -}(Error)); -export { CodedError }; diff --git a/dist/esm/common/errorHandler.js b/dist/esm/common/errorHandler.js deleted file mode 100644 index affb5315..00000000 --- a/dist/esm/common/errorHandler.js +++ /dev/null @@ -1,84 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -export var withCodedErrorHandler = function (verify, errorOptions) { return function (document, options -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore https://github.com/microsoft/TypeScript/issues/26781 -) { return __awaiter(void 0, void 0, void 0, function () { - var e_1, message, code, codeString, name, type, unexpectedErrorCode, unexpectedErrorString; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - _a.trys.push([0, 2, , 3]); - return [4 /*yield*/, verify(document, options)]; - case 1: - // Using return await to ensure async function execute in try block - return [2 /*return*/, _a.sent()]; - case 2: - e_1 = _a.sent(); - message = e_1.message, code = e_1.code, codeString = e_1.codeString; - name = errorOptions.name, type = errorOptions.type, unexpectedErrorCode = errorOptions.unexpectedErrorCode, unexpectedErrorString = errorOptions.unexpectedErrorString; - if (message && code && codeString) { - return [2 /*return*/, { - name: name, - type: type, - data: e_1, - reason: { - message: message, - code: code, - codeString: codeString, - }, - status: "ERROR", - }]; - } - else { - return [2 /*return*/, { - name: name, - type: type, - data: e_1, - reason: { - message: e_1.message, - code: unexpectedErrorCode, - codeString: unexpectedErrorString, - }, - status: "ERROR", - }]; - } - return [3 /*break*/, 3]; - case 3: return [2 /*return*/]; - } - }); -}); }; }; diff --git a/dist/esm/common/logger.js b/dist/esm/common/logger.js deleted file mode 100644 index 7a5fbba6..00000000 --- a/dist/esm/common/logger.js +++ /dev/null @@ -1,9 +0,0 @@ -import debug from "debug"; -var logger = debug("oa-verify"); -export var getLogger = function (namespace) { return ({ - trace: logger.extend("trace:" + namespace), - debug: logger.extend("debug:" + namespace), - info: logger.extend("info:" + namespace), - warn: logger.extend("warn:" + namespace), - error: logger.extend("error:" + namespace), -}); }; diff --git a/dist/esm/common/messages.js b/dist/esm/common/messages.js deleted file mode 100644 index 603628c3..00000000 --- a/dist/esm/common/messages.js +++ /dev/null @@ -1 +0,0 @@ -export var warnProvider = "You are falling back to oa-verify default configuration, which is not suitable for production environment. It is highly recommended that you configure and provide your own API key. Refer to https://github.com/Open-Attestation/oa-verify#provider"; diff --git a/dist/esm/common/utils.js b/dist/esm/common/utils.js deleted file mode 100644 index c410eb8b..00000000 --- a/dist/esm/common/utils.js +++ /dev/null @@ -1,162 +0,0 @@ -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -import { providers } from "ethers"; -import { INFURA_API_KEY } from "../config"; -import { OpenAttestationEthereumDocumentStoreStatusCode, OpenAttestationEthereumTokenRegistryStatusCode, } from "../types/error"; -import { warnProvider } from "../common/messages"; -export var getDefaultProvider = function (options) { - var network = options.network || process.env.PROVIDER_NETWORK || "homestead"; - var providerType = process.env.PROVIDER_ENDPOINT_TYPE || "infura"; - var apiKey = process.env.PROVIDER_API_KEY || (providerType === "infura" && INFURA_API_KEY) || ""; - // create infura provider to get connection information - // we then use StaticJsonRpcProvider so that we can set our own custom limit - var uselessProvider = generateProvider({ - providerType: providerType, - network: network, - apiKey: apiKey, - }); - var connection = __assign(__assign({}, uselessProvider.connection), { throttleLimit: 3 }); - return new providers.StaticJsonRpcProvider(connection, network); -}; -// getProvider is a function to get an existing provider or to get a Default provider, when given the options -export var getProvider = function (options) { - var _a; - return (_a = options.provider) !== null && _a !== void 0 ? _a : getDefaultProvider(options); -}; -/** - * Generate Provider generates a provider based on the defined options or your env var, if no options or env var was detected, it will generate a provider based on the default values. - * Generate Provider using the following options: (if no option is specified it will use the default values) - * @param {Object} ProviderDetails - Details to use for the function to successfully generate a provider. - * @param {string} ProviderDetails.network - The network in which the provider is connected to, i.e. "homestead", "mainnet", "ropsten", "rinkeby" - * @param {string} ProviderDetails.providerType - Specify which provider to use: "infura", "alchemy" or "jsonrpc" - * @param {string} ProviderDetails.url - Specify which url for JsonRPC to connect to, if not specified will connect to localhost:8545 - * @param {string} ProviderDetails.apiKey - If no apiKey is provided, a default shared API key will be used, which may result in reduced performance and throttled requests. - */ -export var generateProvider = function (options) { - if (!!options && Object.keys(options).length === 1 && options.apiKey) { - throw new Error("We could not link the apiKey provided to a provider, please state the provider to use in the parameter."); - } - var network = (options === null || options === void 0 ? void 0 : options.network) || process.env.PROVIDER_NETWORK || "homestead"; - var provider = (options === null || options === void 0 ? void 0 : options.providerType) || process.env.PROVIDER_ENDPOINT_TYPE || "infura"; - var url = (options === null || options === void 0 ? void 0 : options.url) || process.env.PROVIDER_ENDPOINT_URL || ""; - var apiKey = (options === null || options === void 0 ? void 0 : options.apiKey) || (provider === "infura" && process.env.INFURA_API_KEY) || process.env.PROVIDER_API_KEY || ""; - !apiKey && console.warn(warnProvider); - if (!!options && Object.keys(options).length === 1 && url) { - return new providers.JsonRpcProvider(url); - } - switch (provider) { - case "infura": - return apiKey ? new providers.InfuraProvider(network, apiKey) : new providers.InfuraProvider(network); - case "alchemy": - return apiKey ? new providers.AlchemyProvider(network, apiKey) : new providers.AlchemyProvider(network); - case "jsonrpc": - return new providers.JsonRpcProvider(url); - default: - throw new Error("The provider provided is not on the list of providers. Please use one of the following: infura, alchemy or jsonrpc."); - } -}; -/** - * Simple typed utility to return a fragment depending on the name - * @param name - */ -export var getFragmentByName = function (name) { return function (fragments) { return fragments.find(function (fragment) { return fragment.name === name; }); }; }; -export var getOpenAttestationHashFragment = getFragmentByName("OpenAttestationHash"); -export var getOpenAttestationDidSignedDocumentStatusFragment = getFragmentByName("OpenAttestationDidSignedDocumentStatus"); -export var getOpenAttestationEthereumDocumentStoreStatusFragment = getFragmentByName("OpenAttestationEthereumDocumentStoreStatus"); -export var getOpenAttestationEthereumTokenRegistryStatusFragment = getFragmentByName("OpenAttestationEthereumTokenRegistryStatus"); -export var getOpenAttestationDidIdentityProofFragment = getFragmentByName("OpenAttestationDidIdentityProof"); -export var getOpenAttestationDnsDidIdentityProofFragment = getFragmentByName("OpenAttestationDnsDidIdentityProof"); -export var getOpenAttestationDnsTxtIdentityProofFragment = getFragmentByName("OpenAttestationDnsTxtIdentityProof"); -/** - * Simple typed utility to return fragments depending on the type - */ -var getFragmentByType = function (type) { return function (fragments) { return fragments.filter(function (fragment) { return fragment.type === type; }); }; }; -export var getDocumentIntegrityFragments = getFragmentByType("DOCUMENT_INTEGRITY"); -export var getDocumentStatusFragments = getFragmentByType("DOCUMENT_STATUS"); -export var getIssuerIdentityFragments = getFragmentByType("ISSUER_IDENTITY"); -export var isValidFragment = function (fragment) { - return (fragment === null || fragment === void 0 ? void 0 : fragment.status) === "VALID"; -}; -export var isInvalidFragment = function (fragment) { - return (fragment === null || fragment === void 0 ? void 0 : fragment.status) === "INVALID"; -}; -export var isSkippedFragment = function (fragment) { - return (fragment === null || fragment === void 0 ? void 0 : fragment.status) === "SKIPPED"; -}; -export var isErrorFragment = function (fragment) { - return (fragment === null || fragment === void 0 ? void 0 : fragment.status) === "ERROR"; -}; -// this function check if the reason of the error is that the document store or token registry is invalid -export var isDocumentStoreAddressOrTokenRegistryAddressInvalid = function (fragments) { - var _a, _b, _c, _d; - var documentStoreIssuedFragment = getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); - var tokenRegistryMintedFragment = getOpenAttestationEthereumTokenRegistryStatusFragment(fragments); - // 2 is the error code used by oa-verify in case of invalid address - return ((((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED && - ((_b = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _b === void 0 ? void 0 : _b.message.toLowerCase()) === "Invalid document store address".toLowerCase()) || - (((_c = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _c === void 0 ? void 0 : _c.code) === OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED && - ((_d = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _d === void 0 ? void 0 : _d.message.toLowerCase()) === "Invalid token registry address".toLowerCase())); -}; -// this function check if the reason of the error is contract not found in document store -export var contractNotFound = function (fragments) { - var _a, _b; - var documentStoreIssuedFragment = getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); - // 404 is the error code used by oa-verify in case of contract not found - return (((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED && - ((_b = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _b === void 0 ? void 0 : _b.message.toLowerCase()) === "Contract is not found".toLowerCase()); -}; -// this function check if the reason of the error is that the document is not issued in document store or token registry -export var certificateNotIssued = function (fragments) { - var _a, _b; - var documentStoreIssuedFragment = getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); - var tokenRegistryMintedFragment = getOpenAttestationEthereumTokenRegistryStatusFragment(fragments); - // 1 is the error code used by oa-verify in case of document / token not issued / minted - return (((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED || - ((_b = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _b === void 0 ? void 0 : _b.code) === OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED); -}; -// this function check if the reason of the error is that the document is revoked in document store -export var certificateRevoked = function (fragments) { - var _a; - var documentStoreIssuedFragment = getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); - // 1 is the error code used by oa-verify in case of document / token not issued / minted - return ((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED; -}; -// this function check if the error is caused by an invalid merkle root (incorrect length/odd length/invalid characters) -export var invalidArgument = function (fragments) { - var _a, _b, _c, _d; - var documentStoreIssuedFragment = getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); - var tokenRegistryMintedFragment = getOpenAttestationEthereumTokenRegistryStatusFragment(fragments); - // why INVALID_ARGUMENT is because we follow the error codes returned by Ethers (https://docs.ethers.io/v5/api/utils/logger/#errors) - return ((((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED && - ((_b = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _b === void 0 ? void 0 : _b.message.toLowerCase()) === "Invalid call arguments".toLowerCase()) || - (((_c = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _c === void 0 ? void 0 : _c.code) === OpenAttestationEthereumTokenRegistryStatusCode.INVALID_ARGUMENT && - ((_d = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _d === void 0 ? void 0 : _d.message.toLowerCase()) === "Invalid contract arguments".toLowerCase())); -}; -// this function check if the reason of the error is that we can't connect to Ethereum (due to any HTTP 4xx or 5xx errors) -export var serverError = function (fragments) { - var _a, _b; - var documentStoreIssuedFragment = getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); - var tokenRegistryMintedFragment = getOpenAttestationEthereumTokenRegistryStatusFragment(fragments); - // 429 is the error code used by oa-verify in case of Ethers returning a missing response error - return (((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === OpenAttestationEthereumDocumentStoreStatusCode.SERVER_ERROR || - ((_b = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _b === void 0 ? void 0 : _b.code) === OpenAttestationEthereumTokenRegistryStatusCode.SERVER_ERROR); -}; -// this function catches all other unhandled errors -export var unhandledError = function (fragments) { - var _a, _b; - var documentStoreIssuedFragment = getOpenAttestationEthereumDocumentStoreStatusFragment(fragments); - var tokenRegistryMintedFragment = getOpenAttestationEthereumTokenRegistryStatusFragment(fragments); - // 3 is the error code used by oa-verify in case of weird errors that we didn't foresee to handle - return (((_a = documentStoreIssuedFragment === null || documentStoreIssuedFragment === void 0 ? void 0 : documentStoreIssuedFragment.reason) === null || _a === void 0 ? void 0 : _a.code) === - OpenAttestationEthereumDocumentStoreStatusCode.ETHERS_UNHANDLED_ERROR || - ((_b = tokenRegistryMintedFragment === null || tokenRegistryMintedFragment === void 0 ? void 0 : tokenRegistryMintedFragment.reason) === null || _b === void 0 ? void 0 : _b.code) === OpenAttestationEthereumDocumentStoreStatusCode.ETHERS_UNHANDLED_ERROR); -}; diff --git a/dist/esm/config.js b/dist/esm/config.js deleted file mode 100644 index 9d6225a2..00000000 --- a/dist/esm/config.js +++ /dev/null @@ -1 +0,0 @@ -export var INFURA_API_KEY = process.env.INFURA_API_KEY || "bb46da3f80e040e8ab73c0a9ff365d18"; diff --git a/dist/esm/did/resolver.js b/dist/esm/did/resolver.js deleted file mode 100644 index a3827756..00000000 --- a/dist/esm/did/resolver.js +++ /dev/null @@ -1,112 +0,0 @@ -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -import { Resolver } from "did-resolver"; -import { getResolver as ethrGetResolver } from "ethr-did-resolver"; -import { getResolver as webGetResolver } from "web-did-resolver"; -import NodeCache from "node-cache"; -import { INFURA_API_KEY } from "../config"; -import { generateProvider } from "../common/utils"; -export var getProviderConfig = function () { - var _a, _b, _c; - var provider = generateProvider(); - var rpcUrl = ((_a = provider === null || provider === void 0 ? void 0 : provider.connection) === null || _a === void 0 ? void 0 : _a.url) || ""; - var networkName = ((_b = provider === null || provider === void 0 ? void 0 : provider._network) === null || _b === void 0 ? void 0 : _b.name) === "homestead" ? "mainnet" : ((_c = provider === null || provider === void 0 ? void 0 : provider._network) === null || _c === void 0 ? void 0 : _c.name) || ""; - if (!rpcUrl || !networkName) { - return { networks: [{ name: "mainnet", rpcUrl: "https://mainnet.infura.io/v3/" + INFURA_API_KEY }] }; - } - return { - networks: [{ name: networkName, rpcUrl: rpcUrl }], - }; -}; -var didResolutionCache = new NodeCache({ stdTTL: 5 * 60 }); // 5 min -var defaultResolver = new Resolver(__assign(__assign({}, ethrGetResolver(getProviderConfig())), webGetResolver())); -export var createResolver = function (_a) { - var ethrResolverConfig = _a.ethrResolverConfig; - return ethrResolverConfig - ? new Resolver(__assign(__assign({}, ethrGetResolver(ethrResolverConfig)), webGetResolver())) - : defaultResolver; -}; -export var resolve = function (didUrl, resolver) { return __awaiter(void 0, void 0, void 0, function () { - var cachedResult, didResolutionResult, _a, did; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - cachedResult = didResolutionCache.get(didUrl); - if (cachedResult) - return [2 /*return*/, cachedResult]; - if (!resolver) return [3 /*break*/, 2]; - return [4 /*yield*/, resolver.resolve(didUrl)]; - case 1: - _a = _b.sent(); - return [3 /*break*/, 4]; - case 2: return [4 /*yield*/, defaultResolver.resolve(didUrl)]; - case 3: - _a = _b.sent(); - _b.label = 4; - case 4: - didResolutionResult = _a; - did = didResolutionResult.didDocument || undefined; - didResolutionCache.set(didUrl, did); - return [2 /*return*/, did]; - } - }); -}); }; -export var getVerificationMethod = function (did, key, resolver) { return __awaiter(void 0, void 0, void 0, function () { - var didDocument; - var _a; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: return [4 /*yield*/, resolve(did, resolver)]; - case 1: - didDocument = _b.sent(); - if (!didDocument) - return [2 /*return*/]; - return [2 /*return*/, (_a = didDocument.verificationMethod) === null || _a === void 0 ? void 0 : _a.find(function (k) { return k.id.toLowerCase() === key.toLowerCase(); })]; - } - }); -}); }; diff --git a/dist/esm/did/verifier.js b/dist/esm/did/verifier.js deleted file mode 100644 index 92f9f7a0..00000000 --- a/dist/esm/did/verifier.js +++ /dev/null @@ -1,114 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -import { utils } from "ethers"; -import { Literal, Record, String, Union, Array as RunTypesArray } from "runtypes"; -import { getVerificationMethod } from "./resolver"; -import { Reason, OpenAttestationSignatureCode } from "../types/error"; -import { CodedError } from "../common/error"; -export var ValidDidVerificationStatus = Record({ - verified: Literal(true), - did: String, -}); -export var ValidDidVerificationStatusArray = RunTypesArray(ValidDidVerificationStatus).withConstraint(function (elements) { return elements.length > 0 || "Expect at least one valid element"; }); -export var InvalidDidVerificationStatus = Record({ - verified: Literal(false), - did: String, - reason: Reason, -}); -export var DidVerificationStatus = Union(ValidDidVerificationStatus, InvalidDidVerificationStatus); -export var DidVerificationStatusArray = RunTypesArray(DidVerificationStatus); -export var verifySecp256k1VerificationKey2018 = function (_a) { - var did = _a.did, verificationMethod = _a.verificationMethod, merkleRoot = _a.merkleRoot, signature = _a.signature; - var messageBytes = utils.arrayify(merkleRoot); - var blockchainAccountId = verificationMethod.blockchainAccountId; - if (!blockchainAccountId) { - return { - did: did, - verified: false, - reason: { - code: OpenAttestationSignatureCode.KEY_MISSING, - codeString: OpenAttestationSignatureCode[OpenAttestationSignatureCode.KEY_MISSING], - message: "ethereumAddress not found on public key " + JSON.stringify(verificationMethod), - }, - }; - } - // blockchainAccountId looks like 0x0cE1854a3836daF9130028Cf90D6d35B1Ae46457@eip155:3, let's get rid of the part after @, @ included - var ethereumAddress = blockchainAccountId.split("@")[0]; - var merkleRootSigned = utils.verifyMessage(messageBytes, signature).toLowerCase() === ethereumAddress.toLowerCase(); - if (!merkleRootSigned) { - return { - did: did, - verified: false, - reason: { - code: OpenAttestationSignatureCode.WRONG_SIGNATURE, - codeString: OpenAttestationSignatureCode[OpenAttestationSignatureCode.WRONG_SIGNATURE], - message: "merkle root is not signed correctly by " + ethereumAddress, - }, - }; - } - return { - did: did, - verified: true, - }; -}; -export var verifySignature = function (_a) { - var key = _a.key, merkleRoot = _a.merkleRoot, signature = _a.signature, did = _a.did, resolver = _a.resolver; - return __awaiter(void 0, void 0, void 0, function () { - var verificationMethod; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: return [4 /*yield*/, getVerificationMethod(did, key, resolver)]; - case 1: - verificationMethod = _b.sent(); - if (!verificationMethod) - throw new CodedError("No public key found on DID document for the DID " + did + " and key " + key, OpenAttestationSignatureCode.KEY_NOT_IN_DID, "KEY_NOT_IN_DID"); - switch (verificationMethod.type) { - case "EcdsaSecp256k1RecoveryMethod2020": - return [2 /*return*/, verifySecp256k1VerificationKey2018({ - did: did, - verificationMethod: verificationMethod, - merkleRoot: merkleRoot, - signature: signature, - })]; - default: - throw new CodedError("Signature type " + verificationMethod.type + " is currently not support", OpenAttestationSignatureCode.UNSUPPORTED_KEY_TYPE, "UNSUPPORTED_KEY_TYPE"); - } - return [2 /*return*/]; - } - }); - }); -}; diff --git a/dist/esm/getIdentifier.js b/dist/esm/getIdentifier.js deleted file mode 100644 index e9855f53..00000000 --- a/dist/esm/getIdentifier.js +++ /dev/null @@ -1,89 +0,0 @@ -import { isVerificationFragmentWithData } from "./types/core"; -import { DidVerificationStatus, DidVerificationStatusArray } from "./did/verifier"; -import { DnsDidVerificationStatus, DnsDidVerificationStatusArray, } from "./verifiers/issuerIdentity/dnsDid/dnsDidProof.type"; -import { DnsTxtVerificationStatusArray, DnsTxtVerificationStatusDataV3, } from "./verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type"; -var IdentityProof; -(function (IdentityProof) { - IdentityProof["DNS"] = "OpenAttestationDnsTxtIdentityProof"; - IdentityProof["DNSDID"] = "OpenAttestationDnsDidIdentityProof"; - IdentityProof["DID"] = "OpenAttestationDidIdentityProof"; -})(IdentityProof || (IdentityProof = {})); -var getDnsIdentifierProof = function (_a) { - var data = _a.data; - var type = "DNS"; - if (DnsTxtVerificationStatusDataV3.guard(data)) { - return { - identifier: data.identifier, - type: type, - }; - } - else if (DnsTxtVerificationStatusArray.guard(data)) { - return data.map(function (issuer) { return ({ - identifier: issuer.location, - type: type, - }); }); - } - throw new Error("Fragment for DNS not supported"); -}; -var getDnsDidIdentifierProof = function (_a) { - var data = _a.data; - var type = "DNS-DID"; - if (DnsDidVerificationStatusArray.guard(data)) { - return data.map(function (issuer) { return ({ - identifier: issuer.location, - type: type, - }); }); - } - else if (DnsDidVerificationStatus.guard(data)) { - return { - identifier: data.location, - type: type, - }; - } - throw new Error("Fragment for DNS-DID not supported"); -}; -var getDidIdentifierProof = function (_a) { - var data = _a.data; - var type = "DID"; - if (DidVerificationStatusArray.guard(data)) { - return data.map(function (issuer) { return ({ - identifier: issuer.did, - type: type, - }); }); - } - else if (DidVerificationStatus.guard(data)) { - return { - identifier: data.did, - type: type, - }; - } - throw new Error("Fragment for DID not supported"); -}; -var getIdentityProofFragment = function (fragments) { - if (fragments.length < 1) { - throw new Error("Please provide at least one verification fragment"); - } - return fragments.find(function (status) { return status.type === "ISSUER_IDENTITY" && status.status === "VALID"; }); -}; -export var getIdentifier = function (fragments) { - var fragment = getIdentityProofFragment(fragments); - if (!fragment) { - throw new Error("Did not find any Issuer Identity fragment that is valid"); - } - if (!isVerificationFragmentWithData(fragment)) { - throw new Error("No data property found in fragment, malformed fragment"); - } - switch (fragment.name) { - case IdentityProof.DNS: - return getDnsIdentifierProof(fragment); - case IdentityProof.DNSDID: - return getDnsDidIdentifierProof(fragment); - case IdentityProof.DID: - return getDidIdentifierProof(fragment); - default: - return { - identifier: "Unknown", - type: "Unknown", - }; - } -}; diff --git a/dist/esm/index.js b/dist/esm/index.js deleted file mode 100644 index 0c0da17c..00000000 --- a/dist/esm/index.js +++ /dev/null @@ -1,38 +0,0 @@ -import { verificationBuilder } from "./verifiers/verificationBuilder"; -import { openAttestationHash } from "./verifiers/documentIntegrity/hash/openAttestationHash"; -import { isValid } from "./validator"; -import { openAttestationEthereumTokenRegistryStatus } from "./verifiers/documentStatus/tokenRegistry"; -import { openAttestationEthereumDocumentStoreStatus } from "./verifiers/documentStatus/documentStore"; -import { openAttestationDidSignedDocumentStatus } from "./verifiers/documentStatus/didSigned"; -import { openAttestationDnsTxtIdentityProof } from "./verifiers/issuerIdentity/dnsTxt"; -import { openAttestationDidIdentityProof } from "./verifiers/issuerIdentity/did"; -import { openAttestationDnsDidIdentityProof } from "./verifiers/issuerIdentity/dnsDid"; -import { createResolver } from "./did/resolver"; -import { getIdentifier } from "./getIdentifier"; -import * as utils from "./common/utils"; -import util from "util"; -// eslint-disable-next-line @typescript-eslint/no-empty-function -util.deprecate(function infuraApiKey() { }, "'INFURA_API_KEY' has been deprecated, please use 'PROVIDER_API_KEY'."); -var openAttestationVerifiers = [ - openAttestationHash, - openAttestationEthereumTokenRegistryStatus, - openAttestationEthereumDocumentStoreStatus, - openAttestationDidSignedDocumentStatus, - openAttestationDnsTxtIdentityProof, - openAttestationDnsDidIdentityProof, -]; -var defaultBuilderOption = { - network: process.env.PROVIDER_NETWORK || "homestead", -}; -var verify = verificationBuilder(openAttestationVerifiers, defaultBuilderOption); -export * from "./types/core"; -export * from "./verifiers/documentIntegrity/hash/openAttestationHash.type"; -export * from "./verifiers/documentStatus/didSigned/didSignedDocumentStatus.type"; -export * from "./verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type"; -export * from "./verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type"; -export * from "./verifiers/issuerIdentity/did/didIdentityProof.type"; -export * from "./verifiers/issuerIdentity/dnsDid/dnsDidProof.type"; -export * from "./verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type"; -export * from "./types/error"; -export * from "./common/error"; -export { verificationBuilder, openAttestationVerifiers, isValid, verify, openAttestationHash, openAttestationEthereumDocumentStoreStatus, openAttestationEthereumTokenRegistryStatus, openAttestationDidSignedDocumentStatus, openAttestationDnsTxtIdentityProof, openAttestationDnsDidIdentityProof, openAttestationDidIdentityProof, createResolver, getIdentifier, utils, }; diff --git a/dist/esm/types/core.js b/dist/esm/types/core.js deleted file mode 100644 index a6c0fc58..00000000 --- a/dist/esm/types/core.js +++ /dev/null @@ -1,3 +0,0 @@ -export var isVerificationFragmentWithData = function (fragment) { - return fragment.data; -}; diff --git a/dist/esm/types/error.js b/dist/esm/types/error.js deleted file mode 100644 index 2af0947e..00000000 --- a/dist/esm/types/error.js +++ /dev/null @@ -1,104 +0,0 @@ -// NEVER EVER REPLACE OR CHANGE A VALUE :) -// code for errors and invalid fragment -import { Number, Record, String } from "runtypes"; -export var OpenAttestationEthereumDocumentStoreStatusCode; -(function (OpenAttestationEthereumDocumentStoreStatusCode) { - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["UNEXPECTED_ERROR"] = 0] = "UNEXPECTED_ERROR"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["DOCUMENT_NOT_ISSUED"] = 1] = "DOCUMENT_NOT_ISSUED"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["CONTRACT_ADDRESS_INVALID"] = 2] = "CONTRACT_ADDRESS_INVALID"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["ETHERS_UNHANDLED_ERROR"] = 3] = "ETHERS_UNHANDLED_ERROR"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["SKIPPED"] = 4] = "SKIPPED"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["DOCUMENT_REVOKED"] = 5] = "DOCUMENT_REVOKED"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["INVALID_ARGUMENT"] = 6] = "INVALID_ARGUMENT"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["CONTRACT_NOT_FOUND"] = 404] = "CONTRACT_NOT_FOUND"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["INVALID_ISSUERS"] = 7] = "INVALID_ISSUERS"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["INVALID_VALIDATION_METHOD"] = 8] = "INVALID_VALIDATION_METHOD"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["UNRECOGNIZED_DOCUMENT"] = 9] = "UNRECOGNIZED_DOCUMENT"; - OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode["SERVER_ERROR"] = 500] = "SERVER_ERROR"; -})(OpenAttestationEthereumDocumentStoreStatusCode || (OpenAttestationEthereumDocumentStoreStatusCode = {})); -export var OpenAttestationDocumentSignedCode; -(function (OpenAttestationDocumentSignedCode) { - OpenAttestationDocumentSignedCode[OpenAttestationDocumentSignedCode["UNEXPECTED_ERROR"] = 0] = "UNEXPECTED_ERROR"; - OpenAttestationDocumentSignedCode[OpenAttestationDocumentSignedCode["DOCUMENT_PROOF_INVALID"] = 1] = "DOCUMENT_PROOF_INVALID"; - OpenAttestationDocumentSignedCode[OpenAttestationDocumentSignedCode["DOCUMENT_PROOF_ERROR"] = 2] = "DOCUMENT_PROOF_ERROR"; - OpenAttestationDocumentSignedCode[OpenAttestationDocumentSignedCode["SKIPPED"] = 4] = "SKIPPED"; -})(OpenAttestationDocumentSignedCode || (OpenAttestationDocumentSignedCode = {})); -export var OpenAttestationEthereumTokenRegistryStatusCode; -(function (OpenAttestationEthereumTokenRegistryStatusCode) { - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["UNEXPECTED_ERROR"] = 0] = "UNEXPECTED_ERROR"; - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["DOCUMENT_NOT_MINTED"] = 1] = "DOCUMENT_NOT_MINTED"; - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["CONTRACT_ADDRESS_INVALID"] = 2] = "CONTRACT_ADDRESS_INVALID"; - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["ETHERS_UNHANDLED_ERROR"] = 3] = "ETHERS_UNHANDLED_ERROR"; - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["SKIPPED"] = 4] = "SKIPPED"; - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["INVALID_ISSUERS"] = 5] = "INVALID_ISSUERS"; - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["INVALID_ARGUMENT"] = 6] = "INVALID_ARGUMENT"; - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["UNDEFINED_TOKEN_REGISTRY"] = 7] = "UNDEFINED_TOKEN_REGISTRY"; - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["INVALID_VALIDATION_METHOD"] = 8] = "INVALID_VALIDATION_METHOD"; - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["UNRECOGNIZED_DOCUMENT"] = 9] = "UNRECOGNIZED_DOCUMENT"; - OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode["SERVER_ERROR"] = 500] = "SERVER_ERROR"; -})(OpenAttestationEthereumTokenRegistryStatusCode || (OpenAttestationEthereumTokenRegistryStatusCode = {})); -export var OpenAttestationDnsTxtCode; -(function (OpenAttestationDnsTxtCode) { - OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["UNEXPECTED_ERROR"] = 0] = "UNEXPECTED_ERROR"; - OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["INVALID_IDENTITY"] = 1] = "INVALID_IDENTITY"; - OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["SKIPPED"] = 2] = "SKIPPED"; - OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["INVALID_ISSUERS"] = 3] = "INVALID_ISSUERS"; - OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["MATCHING_RECORD_NOT_FOUND"] = 4] = "MATCHING_RECORD_NOT_FOUND"; - OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["UNRECOGNIZED_DOCUMENT"] = 5] = "UNRECOGNIZED_DOCUMENT"; - OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode["UNSUPPORTED"] = 6] = "UNSUPPORTED"; -})(OpenAttestationDnsTxtCode || (OpenAttestationDnsTxtCode = {})); -export var OpenAttestationHashCode; -(function (OpenAttestationHashCode) { - OpenAttestationHashCode[OpenAttestationHashCode["DOCUMENT_TAMPERED"] = 0] = "DOCUMENT_TAMPERED"; - OpenAttestationHashCode[OpenAttestationHashCode["UNEXPECTED_ERROR"] = 1] = "UNEXPECTED_ERROR"; - OpenAttestationHashCode[OpenAttestationHashCode["SKIPPED"] = 2] = "SKIPPED"; -})(OpenAttestationHashCode || (OpenAttestationHashCode = {})); -export var OpenAttestationDidSignedDocumentStatusCode; -(function (OpenAttestationDidSignedDocumentStatusCode) { - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["SKIPPED"] = 0] = "SKIPPED"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["UNEXPECTED_ERROR"] = 1] = "UNEXPECTED_ERROR"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["MISSING_REVOCATION"] = 2] = "MISSING_REVOCATION"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["UNSIGNED"] = 3] = "UNSIGNED"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["INVALID_ISSUERS"] = 4] = "INVALID_ISSUERS"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["MALFORMED_IDENTITY_PROOF"] = 5] = "MALFORMED_IDENTITY_PROOF"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["CORRESPONDING_PROOF_MISSING"] = 6] = "CORRESPONDING_PROOF_MISSING"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["DID_MISSING"] = 7] = "DID_MISSING"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["UNRECOGNIZED_DOCUMENT"] = 8] = "UNRECOGNIZED_DOCUMENT"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["UNRECOGNIZED_REVOCATION_TYPE"] = 9] = "UNRECOGNIZED_REVOCATION_TYPE"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["REVOCATION_LOCATION_MISSING"] = 10] = "REVOCATION_LOCATION_MISSING"; - OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode["OCSP_RESPONSE_INVALID"] = 11] = "OCSP_RESPONSE_INVALID"; -})(OpenAttestationDidSignedDocumentStatusCode || (OpenAttestationDidSignedDocumentStatusCode = {})); -export var OpenAttestationDidCode; -(function (OpenAttestationDidCode) { - OpenAttestationDidCode[OpenAttestationDidCode["SKIPPED"] = 0] = "SKIPPED"; - OpenAttestationDidCode[OpenAttestationDidCode["UNEXPECTED_ERROR"] = 1] = "UNEXPECTED_ERROR"; - OpenAttestationDidCode[OpenAttestationDidCode["INVALID_ISSUERS"] = 2] = "INVALID_ISSUERS"; - OpenAttestationDidCode[OpenAttestationDidCode["MALFORMED_IDENTITY_PROOF"] = 3] = "MALFORMED_IDENTITY_PROOF"; - OpenAttestationDidCode[OpenAttestationDidCode["DID_MISSING"] = 4] = "DID_MISSING"; - OpenAttestationDidCode[OpenAttestationDidCode["UNSIGNED"] = 5] = "UNSIGNED"; - OpenAttestationDidCode[OpenAttestationDidCode["UNRECOGNIZED_DOCUMENT"] = 6] = "UNRECOGNIZED_DOCUMENT"; -})(OpenAttestationDidCode || (OpenAttestationDidCode = {})); -export var OpenAttestationDnsDidCode; -(function (OpenAttestationDnsDidCode) { - OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["SKIPPED"] = 0] = "SKIPPED"; - OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["UNEXPECTED_ERROR"] = 1] = "UNEXPECTED_ERROR"; - OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["MALFORMED_IDENTITY_PROOF"] = 2] = "MALFORMED_IDENTITY_PROOF"; - OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["INVALID_ISSUERS"] = 3] = "INVALID_ISSUERS"; - OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["UNSIGNED"] = 4] = "UNSIGNED"; - OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["UNRECOGNIZED_DOCUMENT"] = 5] = "UNRECOGNIZED_DOCUMENT"; - OpenAttestationDnsDidCode[OpenAttestationDnsDidCode["INVALID_IDENTITY"] = 6] = "INVALID_IDENTITY"; -})(OpenAttestationDnsDidCode || (OpenAttestationDnsDidCode = {})); -export var OpenAttestationSignatureCode; -(function (OpenAttestationSignatureCode) { - OpenAttestationSignatureCode[OpenAttestationSignatureCode["UNEXPECTED_ERROR"] = 0] = "UNEXPECTED_ERROR"; - OpenAttestationSignatureCode[OpenAttestationSignatureCode["KEY_MISSING"] = 1] = "KEY_MISSING"; - OpenAttestationSignatureCode[OpenAttestationSignatureCode["DID_MISSING"] = 3] = "DID_MISSING"; - OpenAttestationSignatureCode[OpenAttestationSignatureCode["KEY_NOT_IN_DID"] = 4] = "KEY_NOT_IN_DID"; - OpenAttestationSignatureCode[OpenAttestationSignatureCode["UNSUPPORTED_KEY_TYPE"] = 6] = "UNSUPPORTED_KEY_TYPE"; - OpenAttestationSignatureCode[OpenAttestationSignatureCode["WRONG_SIGNATURE"] = 7] = "WRONG_SIGNATURE"; -})(OpenAttestationSignatureCode || (OpenAttestationSignatureCode = {})); -export var Reason = Record({ - code: Number, - codeString: String, - message: String, -}); diff --git a/dist/esm/validator.js b/dist/esm/validator.js deleted file mode 100644 index e17e8a30..00000000 --- a/dist/esm/validator.js +++ /dev/null @@ -1,16 +0,0 @@ -export var isValid = function (verificationFragments, types) { - if (types === void 0) { types = ["DOCUMENT_STATUS", "DOCUMENT_INTEGRITY", "ISSUER_IDENTITY"]; } - if (verificationFragments.length < 1) { - throw new Error("Please provide at least one verification fragment to check"); - } - if (types.length < 1) { - throw new Error("Please provide at least one type to check"); - } - return types.every(function (type) { - var verificationFragmentsForType = verificationFragments.filter(function (fragment) { return fragment.type === type; }); - // return true if at least one fragment is valid - // and all fragments are valid or skipped - return (verificationFragmentsForType.some(function (fragment) { return fragment.status === "VALID"; }) && - verificationFragmentsForType.every(function (fragment) { return fragment.status === "VALID" || fragment.status === "SKIPPED"; })); - }); -}; diff --git a/dist/esm/verifiers/documentIntegrity/hash/openAttestationHash.js b/dist/esm/verifiers/documentIntegrity/hash/openAttestationHash.js deleted file mode 100644 index 4c37a93d..00000000 --- a/dist/esm/verifiers/documentIntegrity/hash/openAttestationHash.js +++ /dev/null @@ -1,95 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -import { utils, verifySignature } from "@govtechsg/open-attestation"; -import { OpenAttestationHashCode } from "../../../types/error"; -import { withCodedErrorHandler } from "../../../common/errorHandler"; -var name = "OpenAttestationHash"; -var type = "DOCUMENT_INTEGRITY"; -var skip = function () { - return Promise.resolve({ - status: "SKIPPED", - type: type, - name: name, - reason: { - code: OpenAttestationHashCode.SKIPPED, - codeString: OpenAttestationHashCode[OpenAttestationHashCode.SKIPPED], - message: "Document does not have merkle root, target hash or data.", - }, - }); -}; -var test = function (document) { - return utils.isWrappedV3Document(document) || utils.isWrappedV2Document(document); -}; -var verify = function (document) { return __awaiter(void 0, void 0, void 0, function () { - var hash; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, verifySignature(document)]; - case 1: - hash = _a.sent(); - if (!hash) { - return [2 /*return*/, { - type: type, - name: name, - data: hash, - reason: { - code: OpenAttestationHashCode.DOCUMENT_TAMPERED, - codeString: OpenAttestationHashCode[OpenAttestationHashCode.DOCUMENT_TAMPERED], - message: "Document has been tampered with", - }, - status: "INVALID", - }]; - } - return [2 /*return*/, { - type: type, - name: name, - data: hash, - status: "VALID", - }]; - } - }); -}); }; -export var openAttestationHash = { - skip: skip, - test: test, - verify: withCodedErrorHandler(verify, { - name: name, - type: type, - unexpectedErrorCode: OpenAttestationHashCode.UNEXPECTED_ERROR, - unexpectedErrorString: OpenAttestationHashCode[OpenAttestationHashCode.UNEXPECTED_ERROR], - }), -}; diff --git a/dist/esm/verifiers/documentIntegrity/hash/openAttestationHash.type.js b/dist/esm/verifiers/documentIntegrity/hash/openAttestationHash.type.js deleted file mode 100644 index cb0ff5c3..00000000 --- a/dist/esm/verifiers/documentIntegrity/hash/openAttestationHash.type.js +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/esm/verifiers/documentStatus/didSigned/didSignedDocumentStatus.js b/dist/esm/verifiers/documentStatus/didSigned/didSignedDocumentStatus.js deleted file mode 100644 index 0449b3b2..00000000 --- a/dist/esm/verifiers/documentStatus/didSigned/didSignedDocumentStatus.js +++ /dev/null @@ -1,306 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -import { getData, utils, v2, v3 } from "@govtechsg/open-attestation"; -import { OpenAttestationDidSignedDocumentStatusCode } from "../../../types/error"; -import { ValidDidVerificationStatus, verifySignature } from "../../../did/verifier"; -import { CodedError } from "../../../common/error"; -import { withCodedErrorHandler } from "../../../common/errorHandler"; -import { isRevokedByOcspResponder, isRevokedOnDocumentStore } from "../utils"; -import { InvalidRevocationStatus, ValidRevocationStatus } from "../revocation.types"; -import { InvalidDidSignedIssuanceStatus, ValidDidSignedDataV2, ValidDidSignedIssuanceStatus, } from "./didSignedDocumentStatus.type"; -var name = "OpenAttestationDidSignedDocumentStatus"; -var type = "DOCUMENT_STATUS"; -var skip = function () { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, { - status: "SKIPPED", - type: type, - name: name, - reason: { - code: OpenAttestationDidSignedDocumentStatusCode.SKIPPED, - codeString: OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode.SKIPPED], - message: "Document was not signed by DID directly", - }, - }]; - }); -}); }; -var test = function (document) { - if (utils.isSignedWrappedV2Document(document)) { - return document.proof.some(function (proof) { return proof.type === "OpenAttestationSignature2018"; }); - } - else if (utils.isSignedWrappedV3Document(document)) { - return document.proof.type === "OpenAttestationMerkleProofSignature2018"; - } - return false; -}; -var transformToDidSignedIssuanceStatus = function (status) { - return ValidDidVerificationStatus.guard(status) - ? { - issued: true, - did: status.did, - } - : { - issued: false, - did: status.did, - reason: status.reason, - }; -}; -var verifyV2 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - var documentData, merkleRoot, _a, targetHash, proofs, issuers, revocation, revocationStatusCallback, revocationStatuses, signatureVerificationDeferred, issuance, notIssued, revoked, data, reason; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - documentData = getData(document); - merkleRoot = "0x" + document.signature.merkleRoot; - _a = document.signature, targetHash = _a.targetHash, proofs = _a.proof; - documentData.issuers.forEach(function (issuer) { - var _a, _b; - if (!(((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === "DID" || ((_b = issuer.identityProof) === null || _b === void 0 ? void 0 : _b.type) === "DNS-DID")) - throw new CodedError("All issuers must use DID or DNS-DID identityProof type.", OpenAttestationDidSignedDocumentStatusCode.INVALID_ISSUERS, OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode.INVALID_ISSUERS]); - }); - issuers = documentData.issuers; - revocation = issuers.map(function (issuer) { return issuer.revocation; }); - if (revocation.some(function (r) { return typeof (r === null || r === void 0 ? void 0 : r.type) === "undefined"; })) - throw new CodedError("revocation block not found for an issuer", OpenAttestationDidSignedDocumentStatusCode.MISSING_REVOCATION, "MISSING_REVOCATION"); - revocationStatusCallback = function (revocationItem) { - switch (revocationItem.type) { - case v2.RevocationType.RevocationStore: - if (typeof revocationItem.location === "string") { - return isRevokedOnDocumentStore({ - documentStore: revocationItem.location, - merkleRoot: merkleRoot, - provider: options.provider, - targetHash: targetHash, - proofs: proofs, - }); - } - throw new CodedError("missing revocation location for an issuer", OpenAttestationDidSignedDocumentStatusCode.REVOCATION_LOCATION_MISSING, "REVOCATION_LOCATION_MISSING"); - case v2.RevocationType.OcspResponder: - if (typeof revocationItem.location === "string") { - return isRevokedByOcspResponder({ - certificateId: documentData.id, - location: revocationItem.location, - }); - } - throw new CodedError("missing revocation location for an issuer", OpenAttestationDidSignedDocumentStatusCode.REVOCATION_LOCATION_MISSING, "REVOCATION_LOCATION_MISSING"); - case v2.RevocationType.None: - return Promise.resolve({ revoked: false }); - default: - throw new CodedError("unrecognized revocation type for an issuer", OpenAttestationDidSignedDocumentStatusCode.UNRECOGNIZED_REVOCATION_TYPE, "UNRECOGNIZED_REVOCATION_TYPE"); - } - }; - return [4 /*yield*/, Promise.all(revocation.map(revocationStatusCallback))]; - case 1: - revocationStatuses = _b.sent(); - // Check that all the issuers have signed on the document - if (!document.proof) - throw new CodedError("Document is not signed. Proofs are missing.", OpenAttestationDidSignedDocumentStatusCode.UNSIGNED, "UNSIGNED"); - signatureVerificationDeferred = issuers.map(function (issuer) { return __awaiter(void 0, void 0, void 0, function () { - var key, did, correspondingProof; - var _a; - return __generator(this, function (_b) { - key = (_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.key; - did = issuer.id; - if (!did) - throw new CodedError("id is missing in issuer", OpenAttestationDidSignedDocumentStatusCode.DID_MISSING, "DID_MISSING"); - if (!key) - throw new CodedError("Key is not present", OpenAttestationDidSignedDocumentStatusCode.MALFORMED_IDENTITY_PROOF, "MALFORMED_IDENTITY_PROOF"); - correspondingProof = document.proof.find(function (p) { return p.verificationMethod.toLowerCase() === key.toLowerCase(); }); - if (!correspondingProof) - throw new CodedError("Proof not found for " + key, OpenAttestationDidSignedDocumentStatusCode.CORRESPONDING_PROOF_MISSING, "CORRESPONDING_PROOF_MISSING"); - return [2 /*return*/, verifySignature({ - merkleRoot: merkleRoot, - key: key, - signature: correspondingProof.signature, - did: did, - resolver: options.resolver, - })]; - }); - }); }); - return [4 /*yield*/, Promise.all(signatureVerificationDeferred)]; - case 2: return [4 /*yield*/, (_b.sent()).map(transformToDidSignedIssuanceStatus)]; - case 3: - issuance = _b.sent(); - notIssued = issuance.find(InvalidDidSignedIssuanceStatus.guard); - revoked = revocationStatuses.find(InvalidRevocationStatus.guard); - data = { - issuedOnAll: !notIssued, - revokedOnAny: !!revoked, - details: { - issuance: issuance, - revocation: revocationStatuses, - }, - }; - if (ValidDidSignedDataV2.guard(data)) { - return [2 /*return*/, { - name: name, - type: type, - data: data, - status: "VALID", - }]; - } - if (InvalidDidSignedIssuanceStatus.guard(notIssued)) { - reason = notIssued.reason; - } - else if (InvalidRevocationStatus.guard(revoked)) { - reason = revoked.reason; - } - if (!reason) { - throw new CodedError("Unable to retrieve the reason of the failure", OpenAttestationDidSignedDocumentStatusCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); - } - return [2 /*return*/, { - name: name, - type: type, - data: data, - status: "INVALID", - reason: reason, - }]; - } - }); -}); }; -var verifyV3 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - var _a, merkleRootRaw, targetHash, proofs, merkleRoot, metaData, verificationResult, _b, issuedOnAll, getRevocationStatus, revocationStatus, revokedOnAny, reason; - var _c; - return __generator(this, function (_d) { - switch (_d.label) { - case 0: - _a = document.proof, merkleRootRaw = _a.merkleRoot, targetHash = _a.targetHash, proofs = _a.proofs; - merkleRoot = "0x" + merkleRootRaw; - metaData = document.openAttestationMetadata; - _b = transformToDidSignedIssuanceStatus; - return [4 /*yield*/, verifySignature({ - key: document.proof.key, - did: metaData.proof.value, - merkleRoot: merkleRoot, - signature: document.proof.signature, - resolver: options.resolver, - })]; - case 1: - verificationResult = _b.apply(void 0, [_d.sent()]); - if (!((_c = metaData.proof.revocation) === null || _c === void 0 ? void 0 : _c.type)) { - throw new CodedError("revocation block not found for an issuer", OpenAttestationDidSignedDocumentStatusCode.MISSING_REVOCATION, "MISSING_REVOCATION"); - } - issuedOnAll = verificationResult.issued; - getRevocationStatus = function (docType, location) { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (docType) { - case v3.RevocationType.RevocationStore: - if (typeof location === "string") { - return [2 /*return*/, isRevokedOnDocumentStore({ - documentStore: location, - merkleRoot: merkleRoot, - targetHash: targetHash, - proofs: proofs, - provider: options.provider, - })]; - } - throw new CodedError("missing revocation location for an issuer", OpenAttestationDidSignedDocumentStatusCode.REVOCATION_LOCATION_MISSING, "REVOCATION_LOCATION_MISSING"); - case v3.RevocationType.OcspResponder: - throw new Error("Ocsp revocation type not yet supported for v3"); - case v3.RevocationType.None: - return [2 /*return*/, { revoked: false }]; - default: - throw new CodedError("revocation type not found for an issuer", OpenAttestationDidSignedDocumentStatusCode.UNRECOGNIZED_REVOCATION_TYPE, "UNRECOGNIZED_REVOCATION_TYPE"); - } - return [2 /*return*/]; - }); - }); }; - return [4 /*yield*/, getRevocationStatus(metaData.proof.revocation.type, metaData.proof.revocation.location)]; - case 2: - revocationStatus = _d.sent(); - revokedOnAny = revocationStatus.revoked; - if (ValidDidSignedIssuanceStatus.guard(verificationResult) && ValidRevocationStatus.guard(revocationStatus)) { - return [2 /*return*/, { - name: name, - type: type, - data: { - issuedOnAll: true, - revokedOnAny: false, - details: { - issuance: verificationResult, - revocation: revocationStatus, - }, - }, - status: "VALID", - }]; - } - reason = InvalidDidSignedIssuanceStatus.guard(verificationResult) - ? verificationResult.reason - : InvalidRevocationStatus.guard(revocationStatus) - ? revocationStatus.reason - : undefined; - if (!reason) { - throw new CodedError("Unable to retrieve the reason of the failure", OpenAttestationDidSignedDocumentStatusCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); - } - return [2 /*return*/, { - name: name, - type: type, - data: { - issuedOnAll: issuedOnAll, - revokedOnAny: revokedOnAny, - details: { - issuance: verificationResult, - revocation: revocationStatus, - }, - }, - status: "INVALID", - reason: reason, - }]; - } - }); -}); }; -var verify = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - if (utils.isSignedWrappedV2Document(document)) { - return [2 /*return*/, verifyV2(document, options)]; - } - else if (utils.isSignedWrappedV3Document(document)) { - return [2 /*return*/, verifyV3(document, options)]; - } - throw new CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", OpenAttestationDidSignedDocumentStatusCode.UNRECOGNIZED_DOCUMENT, OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode.UNRECOGNIZED_DOCUMENT]); - }); -}); }; -export var openAttestationDidSignedDocumentStatus = { - skip: skip, - test: test, - verify: withCodedErrorHandler(verify, { - name: name, - type: type, - unexpectedErrorCode: OpenAttestationDidSignedDocumentStatusCode.UNEXPECTED_ERROR, - unexpectedErrorString: OpenAttestationDidSignedDocumentStatusCode[OpenAttestationDidSignedDocumentStatusCode.UNEXPECTED_ERROR], - }), -}; diff --git a/dist/esm/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.js b/dist/esm/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.js deleted file mode 100644 index ac9e08b3..00000000 --- a/dist/esm/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.js +++ /dev/null @@ -1,67 +0,0 @@ -import { Array as RunTypesArray, Boolean, Literal, Record, String, Union, Number } from "runtypes"; -import { Reason } from "../../../types/error"; -import { RevocationStatus, RevocationStatusArray, ValidRevocationStatus, ValidRevocationStatusArray, OcspResponderRevocationStatus, } from "../revocation.types"; -/** - * DID signed issuance status - */ -export var ValidDidSignedIssuanceStatus = Record({ - did: String, - issued: Literal(true), -}); -export var ValidDidSignedIssuanceStatusArray = RunTypesArray(ValidDidSignedIssuanceStatus); -export var InvalidDidSignedIssuanceStatus = Record({ - did: String, - issued: Literal(false), - reason: Reason, -}); -export var DidSignedIssuanceStatus = Union(ValidDidSignedIssuanceStatus, InvalidDidSignedIssuanceStatus); -export var DidSignedIssuanceStatusArray = RunTypesArray(DidSignedIssuanceStatus); -/** - * OCSP response - */ -export var ValidOcspReasonCode = Number.withConstraint(function (n) { return n >= 0 && n <= 10 && n != 7; }); -export var ValidOcspResponse = Record({ - certificateStatus: OcspResponderRevocationStatus, -}); -export var ValidOcspResponseRevoked = Record({ - reasonCode: ValidOcspReasonCode, - certificateStatus: OcspResponderRevocationStatus, -}); -/** - * Data for v2 Fragments - */ -export var ValidDidSignedDataV2 = Record({ - issuedOnAll: Literal(true), - revokedOnAny: Literal(false), - details: Record({ - issuance: ValidDidSignedIssuanceStatusArray, - revocation: ValidRevocationStatusArray, - }), -}); -export var InvalidDidSignedDataV2 = Record({ - issuedOnAll: Boolean, - revokedOnAny: Boolean, - details: Record({ - issuance: DidSignedIssuanceStatusArray, - revocation: RevocationStatusArray, - }), -}); -/** - * Data for v3 Fragments - */ -export var ValidDidSignedDataV3 = Record({ - issuedOnAll: Literal(true), - revokedOnAny: Literal(false), - details: Record({ - issuance: ValidDidSignedIssuanceStatus, - revocation: ValidRevocationStatus, - }), -}); -export var InvalidDidSignedDataV3 = Record({ - issuedOnAll: Boolean, - revokedOnAny: Boolean, - details: Record({ - issuance: DidSignedIssuanceStatus, - revocation: RevocationStatus, - }), -}); diff --git a/dist/esm/verifiers/documentStatus/didSigned/index.js b/dist/esm/verifiers/documentStatus/didSigned/index.js deleted file mode 100644 index 1c14b400..00000000 --- a/dist/esm/verifiers/documentStatus/didSigned/index.js +++ /dev/null @@ -1 +0,0 @@ -export * from "./didSignedDocumentStatus"; diff --git a/dist/esm/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.js b/dist/esm/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.js deleted file mode 100644 index c1e8d812..00000000 --- a/dist/esm/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.js +++ /dev/null @@ -1,269 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -import { getData, utils, v3 } from "@govtechsg/open-attestation"; -import { DocumentStoreFactory } from "@govtechsg/document-store"; -import { OpenAttestationEthereumDocumentStoreStatusCode } from "../../../types/error"; -import { CodedError } from "../../../common/error"; -import { withCodedErrorHandler } from "../../../common/errorHandler"; -import { decodeError, isRevokedOnDocumentStore } from "../utils"; -import { InvalidRevocationStatus, ValidRevocationStatusArray } from "../revocation.types"; -import { InvalidDocumentStoreIssuanceStatus, ValidDocumentStoreDataV3, ValidDocumentStoreIssuanceStatusArray, } from "./ethereumDocumentStoreStatus.type"; -var name = "OpenAttestationEthereumDocumentStoreStatus"; -var type = "DOCUMENT_STATUS"; -// Returns list of all document stores, throws when not all issuers are using document store -export var getIssuersDocumentStores = function (document) { - var data = getData(document); - return data.issuers.map(function (issuer) { - var documentStoreAddress = issuer.documentStore || issuer.certificateStore; - if (!documentStoreAddress) - throw new CodedError("Document store address not found in issuer " + issuer.name, OpenAttestationEthereumDocumentStoreStatusCode.INVALID_ISSUERS, OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode.INVALID_ISSUERS]); - return documentStoreAddress; - }); -}; -export var isIssuedOnDocumentStore = function (_a) { - var documentStore = _a.documentStore, merkleRoot = _a.merkleRoot, provider = _a.provider; - return __awaiter(void 0, void 0, void 0, function () { - var documentStoreContract, issued, error_1; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - _b.trys.push([0, 3, , 4]); - return [4 /*yield*/, DocumentStoreFactory.connect(documentStore, provider)]; - case 1: - documentStoreContract = _b.sent(); - return [4 /*yield*/, documentStoreContract.isIssued(merkleRoot)]; - case 2: - issued = _b.sent(); - return [2 /*return*/, issued - ? { - issued: true, - address: documentStore, - } - : { - issued: false, - address: documentStore, - reason: { - message: "Document " + merkleRoot + " has not been issued under contract " + documentStore, - code: OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED, - codeString: OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED], - }, - }]; - case 3: - error_1 = _b.sent(); - // If error can be decoded and it's because of document is not issued, we return false - // Else allow error to continue to bubble up - return [2 /*return*/, { - issued: false, - address: documentStore, - reason: { - message: decodeError(error_1), - code: OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED, - codeString: OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED], - }, - }]; - case 4: return [2 /*return*/]; - } - }); - }); -}; -var skip = function () { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, { - status: "SKIPPED", - type: type, - name: name, - reason: { - code: OpenAttestationEthereumDocumentStoreStatusCode.SKIPPED, - codeString: OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode.SKIPPED], - message: "Document issuers doesn't have \"documentStore\" or \"certificateStore\" property or " + v3.Method.DocumentStore + " method", - }, - }]; - }); -}); }; -var test = function (document) { - if (utils.isWrappedV2Document(document)) { - var documentData = getData(document); - return documentData.issuers.some(function (issuer) { return "documentStore" in issuer || "certificateStore" in issuer; }); - } - else if (utils.isWrappedV3Document(document)) { - return document.openAttestationMetadata.proof.method === v3.Method.DocumentStore; - } - return false; -}; -var verifyV2 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - var documentStores, merkleRoot, targetHash, proofs, issuanceStatuses, notIssued, revocationStatuses, revoked; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - documentStores = getIssuersDocumentStores(document); - merkleRoot = "0x" + document.signature.merkleRoot; - targetHash = document.signature.targetHash; - proofs = document.signature.proof || []; - return [4 /*yield*/, Promise.all(documentStores.map(function (documentStore) { - return isIssuedOnDocumentStore({ documentStore: documentStore, merkleRoot: merkleRoot, provider: options.provider }); - }))]; - case 1: - issuanceStatuses = _a.sent(); - notIssued = issuanceStatuses.find(InvalidDocumentStoreIssuanceStatus.guard); - if (InvalidDocumentStoreIssuanceStatus.guard(notIssued)) { - return [2 /*return*/, { - name: name, - type: type, - data: { - issuedOnAll: false, - details: { issuance: issuanceStatuses }, - }, - reason: notIssued.reason, - status: "INVALID", - }]; - } - return [4 /*yield*/, Promise.all(documentStores.map(function (documentStore) { - return isRevokedOnDocumentStore({ - documentStore: documentStore, - merkleRoot: merkleRoot, - targetHash: targetHash, - proofs: proofs, - provider: options.provider, - }); - }))]; - case 2: - revocationStatuses = _a.sent(); - revoked = revocationStatuses.find(InvalidRevocationStatus.guard); - if (InvalidRevocationStatus.guard(revoked)) { - return [2 /*return*/, { - name: name, - type: type, - data: { - issuedOnAll: true, - revokedOnAny: true, - details: { issuance: issuanceStatuses, revocation: revocationStatuses }, - }, - reason: revoked.reason, - status: "INVALID", - }]; - } - if (ValidDocumentStoreIssuanceStatusArray.guard(issuanceStatuses) && - ValidRevocationStatusArray.guard(revocationStatuses)) { - return [2 /*return*/, { - name: name, - type: type, - data: { - issuedOnAll: true, - revokedOnAny: false, - details: { issuance: issuanceStatuses, revocation: revocationStatuses }, - }, - status: "VALID", - }]; - } - throw new CodedError("Reached an unexpected state when verifying v2 document", OpenAttestationEthereumDocumentStoreStatusCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); - } - }); -}); }; -var verifyV3 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - var _a, merkleRootRaw, targetHash, proofs, merkleRoot, documentStore, issuance, revocation, data, reason; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - _a = document.proof, merkleRootRaw = _a.merkleRoot, targetHash = _a.targetHash, proofs = _a.proofs; - merkleRoot = "0x" + merkleRootRaw; - documentStore = document.openAttestationMetadata.proof.value; - return [4 /*yield*/, isIssuedOnDocumentStore({ documentStore: documentStore, merkleRoot: merkleRoot, provider: options.provider })]; - case 1: - issuance = _b.sent(); - return [4 /*yield*/, isRevokedOnDocumentStore({ - documentStore: documentStore, - merkleRoot: merkleRoot, - targetHash: targetHash, - proofs: proofs, - provider: options.provider, - })]; - case 2: - revocation = _b.sent(); - data = { - issuedOnAll: issuance.issued, - revokedOnAny: revocation.revoked, - details: { - issuance: issuance, - revocation: revocation, - }, - }; - if (ValidDocumentStoreDataV3.guard(data)) { - return [2 /*return*/, { - name: name, - type: type, - data: data, - status: "VALID", - }]; - } - if (InvalidRevocationStatus.guard(revocation)) { - reason = revocation.reason; - } - else if (InvalidDocumentStoreIssuanceStatus.guard(issuance)) { - reason = issuance.reason; - } - if (!reason) { - throw new CodedError("Unable to retrieve the reason of the failure", OpenAttestationEthereumDocumentStoreStatusCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); - } - return [2 /*return*/, { - name: name, - type: type, - data: data, - status: "INVALID", - reason: reason, - }]; - } - }); -}); }; -var verify = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - if (utils.isWrappedV2Document(document)) - return [2 /*return*/, verifyV2(document, options)]; - else if (utils.isWrappedV3Document(document)) - return [2 /*return*/, verifyV3(document, options)]; - throw new CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", OpenAttestationEthereumDocumentStoreStatusCode.UNRECOGNIZED_DOCUMENT, OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode.UNRECOGNIZED_DOCUMENT]); - }); -}); }; -export var openAttestationEthereumDocumentStoreStatus = { - skip: skip, - test: test, - verify: withCodedErrorHandler(verify, { - name: name, - type: type, - unexpectedErrorCode: OpenAttestationEthereumDocumentStoreStatusCode.UNEXPECTED_ERROR, - unexpectedErrorString: OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode.UNEXPECTED_ERROR], - }), -}; diff --git a/dist/esm/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.js b/dist/esm/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.js deleted file mode 100644 index edcc5437..00000000 --- a/dist/esm/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.js +++ /dev/null @@ -1,56 +0,0 @@ -import { Array as RunTypesArray, Boolean, Literal, Optional, Record, String, Union } from "runtypes"; -import { Reason } from "../../../types/error"; -import { RevocationStatus, RevocationStatusArray, ValidRevocationStatus, ValidRevocationStatusArray, } from "../revocation.types"; -/** - * Document store issuance status - */ -export var ValidDocumentStoreIssuanceStatus = Record({ - issued: Literal(true), - address: String, -}); -export var ValidDocumentStoreIssuanceStatusArray = RunTypesArray(ValidDocumentStoreIssuanceStatus); -export var InvalidDocumentStoreIssuanceStatus = Record({ - issued: Literal(false), - address: String, - reason: Reason, -}); -export var DocumentStoreIssuanceStatus = Union(ValidDocumentStoreIssuanceStatus, InvalidDocumentStoreIssuanceStatus); -export var DocumentStoreIssuanceStatusArray = RunTypesArray(DocumentStoreIssuanceStatus); -/** - * Data for v2 Fragments - */ -var ValidDocumentStoreDataV2 = Record({ - issuedOnAll: Literal(true), - revokedOnAny: Literal(false), - details: Record({ - issuance: ValidDocumentStoreIssuanceStatusArray, - revocation: ValidRevocationStatusArray, - }), -}); -export var InvalidDocumentStoreDataV2 = Record({ - issuedOnAll: Boolean, - revokedOnAny: Optional(Boolean), - details: Record({ - issuance: DocumentStoreIssuanceStatusArray, - revocation: Optional(RevocationStatusArray), - }), -}); -/** - * Data for v3 Fragments - */ -export var ValidDocumentStoreDataV3 = Record({ - issuedOnAll: Literal(true), - revokedOnAny: Literal(false), - details: Record({ - issuance: ValidDocumentStoreIssuanceStatus, - revocation: ValidRevocationStatus, - }), -}); -export var InvalidDocumentStoreDataV3 = Record({ - issuedOnAll: Boolean, - revokedOnAny: Boolean, - details: Record({ - issuance: DocumentStoreIssuanceStatus, - revocation: RevocationStatus, - }), -}); diff --git a/dist/esm/verifiers/documentStatus/documentStore/index.js b/dist/esm/verifiers/documentStatus/documentStore/index.js deleted file mode 100644 index 51a171e5..00000000 --- a/dist/esm/verifiers/documentStatus/documentStore/index.js +++ /dev/null @@ -1 +0,0 @@ -export * from "./ethereumDocumentStoreStatus"; diff --git a/dist/esm/verifiers/documentStatus/revocation.types.js b/dist/esm/verifiers/documentStatus/revocation.types.js deleted file mode 100644 index 1e94ebb6..00000000 --- a/dist/esm/verifiers/documentStatus/revocation.types.js +++ /dev/null @@ -1,28 +0,0 @@ -import { Literal, Record, String, Union, Array as RunTypesArray, Optional } from "runtypes"; -import { Reason } from "../../types/error"; -export var ValidRevocationStatus = Record({ - revoked: Literal(false), - address: Optional(String), -}); -export var ValidRevocationStatusArray = RunTypesArray(ValidRevocationStatus); -export var InvalidRevocationStatus = Record({ - revoked: Literal(true), - address: String, - reason: Reason, -}); -export var RevocationStatus = Union(ValidRevocationStatus, InvalidRevocationStatus); -export var RevocationStatusArray = RunTypesArray(RevocationStatus); -export var OcspResponderRevocationStatus = Union(Literal("good"), Literal("revoked"), Literal("unknown")); -export var OcspResponderRevocationReason; -(function (OcspResponderRevocationReason) { - OcspResponderRevocationReason[OcspResponderRevocationReason["UNSPECIFIED"] = 0] = "UNSPECIFIED"; - OcspResponderRevocationReason[OcspResponderRevocationReason["KEY_COMPROMISE"] = 1] = "KEY_COMPROMISE"; - OcspResponderRevocationReason[OcspResponderRevocationReason["CA_COMPROMISE"] = 2] = "CA_COMPROMISE"; - OcspResponderRevocationReason[OcspResponderRevocationReason["AFFILIATION_CHANGED"] = 3] = "AFFILIATION_CHANGED"; - OcspResponderRevocationReason[OcspResponderRevocationReason["SUPERSEDED"] = 4] = "SUPERSEDED"; - OcspResponderRevocationReason[OcspResponderRevocationReason["CESSATION_OF_OPERATION"] = 5] = "CESSATION_OF_OPERATION"; - OcspResponderRevocationReason[OcspResponderRevocationReason["CERTIFICATE_HOLD"] = 6] = "CERTIFICATE_HOLD"; - OcspResponderRevocationReason[OcspResponderRevocationReason["REMOVE_FROM_CRL"] = 8] = "REMOVE_FROM_CRL"; - OcspResponderRevocationReason[OcspResponderRevocationReason["PRIVILEGE_WITHDRAWN"] = 9] = "PRIVILEGE_WITHDRAWN"; - OcspResponderRevocationReason[OcspResponderRevocationReason["A_A_COMPROMISE"] = 10] = "A_A_COMPROMISE"; -})(OcspResponderRevocationReason || (OcspResponderRevocationReason = {})); diff --git a/dist/esm/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.js b/dist/esm/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.js deleted file mode 100644 index ff4b9cf1..00000000 --- a/dist/esm/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.js +++ /dev/null @@ -1,231 +0,0 @@ -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -import { getData, utils, v3 } from "@govtechsg/open-attestation"; -import { TradeTrustErc721Factory } from "@govtechsg/token-registry"; -import { constants, errors } from "ethers"; -import { OpenAttestationEthereumTokenRegistryStatusCode } from "../../../types/error"; -import { CodedError } from "../../../common/error"; -import { withCodedErrorHandler } from "../../../common/errorHandler"; -import { ValidTokenRegistryStatus, } from "./ethereumTokenRegistryStatus.type"; -var name = "OpenAttestationEthereumTokenRegistryStatus"; -var type = "DOCUMENT_STATUS"; -export var getTokenRegistry = function (document) { - if (utils.isWrappedV2Document(document)) { - var issuers = getData(document).issuers; - if (issuers.length !== 1) - throw new CodedError("Only one issuer is allowed for tokens", OpenAttestationEthereumTokenRegistryStatusCode.INVALID_ISSUERS, OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.INVALID_ISSUERS]); - if (!issuers[0].tokenRegistry) - throw new CodedError("Token registry is undefined", OpenAttestationEthereumTokenRegistryStatusCode.UNDEFINED_TOKEN_REGISTRY, OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.UNDEFINED_TOKEN_REGISTRY]); - return issuers[0].tokenRegistry; - } - if (utils.isWrappedV3Document(document)) { - if (!document.openAttestationMetadata.proof.value) - throw new CodedError("Token registry is undefined", OpenAttestationEthereumTokenRegistryStatusCode.UNDEFINED_TOKEN_REGISTRY, OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.UNDEFINED_TOKEN_REGISTRY]); - return document.openAttestationMetadata.proof.value; - } - throw new CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT, OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT]); -}; -var getMerkleRoot = function (document) { - if (utils.isWrappedV2Document(document)) - return "0x" + document.signature.merkleRoot; - else if (utils.isWrappedV3Document(document)) - return "0x" + document.proof.merkleRoot; - throw new CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT, OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT]); -}; -var isNonExistentToken = function (error) { - var message = error.message; - if (!message) - return false; - return message.includes("owner query for nonexistent token"); -}; -var isMissingTokenRegistry = function (error) { - var _a; - return (!error.reason && - ((_a = error.method) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === "ownerOf(uint256)".toLowerCase() && - error.code === errors.CALL_EXCEPTION); -}; -var decodeError = function (error) { - var _a; - var reason = error.reason && Array.isArray(error.reason) ? error.reason[0] : (_a = error.reason) !== null && _a !== void 0 ? _a : ""; - switch (true) { - case isNonExistentToken(error): - return "Document has not been issued under token registry"; - case isMissingTokenRegistry(error): - return "Token registry is not found"; - case reason.toLowerCase() === "ENS name not configured".toLowerCase() && - error.code === errors.UNSUPPORTED_OPERATION: - return "ENS name is not configured"; - case reason.toLowerCase() === "invalid address".toLowerCase() && error.code === errors.INVALID_ARGUMENT: - return "Invalid token registry address"; - case error.code === errors.INVALID_ARGUMENT: - return "Invalid contract arguments"; - case error.code === errors.SERVER_ERROR: - throw new CodedError("Unable to connect to the Ethereum network, please try again later", OpenAttestationEthereumTokenRegistryStatusCode.SERVER_ERROR, OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.SERVER_ERROR]); - default: - throw error; - } -}; -export var isTokenMintedOnRegistry = function (_a) { - var tokenRegistry = _a.tokenRegistry, merkleRoot = _a.merkleRoot, provider = _a.provider; - return __awaiter(void 0, void 0, void 0, function () { - var tokenRegistryContract, minted, error_1; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - _b.trys.push([0, 3, , 4]); - return [4 /*yield*/, TradeTrustErc721Factory.connect(tokenRegistry, provider)]; - case 1: - tokenRegistryContract = _b.sent(); - return [4 /*yield*/, tokenRegistryContract.ownerOf(merkleRoot).then(function (owner) { return !(owner === constants.AddressZero); })]; - case 2: - minted = _b.sent(); - return [2 /*return*/, minted - ? { minted: minted, address: tokenRegistry } - : { - minted: minted, - address: tokenRegistry, - reason: { - code: OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED, - codeString: OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED], - message: "Document " + merkleRoot + " has not been issued under contract " + tokenRegistry, - }, - }]; - case 3: - error_1 = _b.sent(); - return [2 /*return*/, { - minted: false, - address: tokenRegistry, - reason: { - message: decodeError(error_1), - code: OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED, - codeString: OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED], - }, - }]; - case 4: return [2 /*return*/]; - } - }); - }); -}; -var skip = function () { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, { - status: "SKIPPED", - type: type, - name: name, - reason: { - code: OpenAttestationEthereumTokenRegistryStatusCode.SKIPPED, - codeString: OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.SKIPPED], - message: "Document issuers doesn't have \"tokenRegistry\" property or " + v3.Method.TokenRegistry + " method", - }, - }]; - }); -}); }; -var test = function (document) { - if (utils.isWrappedV2Document(document)) { - var documentData = getData(document); - return documentData.issuers.some(function (issuer) { return "tokenRegistry" in issuer; }); - } - else if (utils.isWrappedV3Document(document)) { - return document.openAttestationMetadata.proof.method === v3.Method.TokenRegistry; - } - return false; -}; -// TODO split -var verify = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - var tokenRegistry, merkleRoot, mintStatus, fragment, fragment; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!utils.isWrappedV3Document(document) && !utils.isWrappedV2Document(document)) - throw new CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT, OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT]); - tokenRegistry = getTokenRegistry(document); - merkleRoot = getMerkleRoot(document); - return [4 /*yield*/, isTokenMintedOnRegistry({ tokenRegistry: tokenRegistry, merkleRoot: merkleRoot, provider: options.provider })]; - case 1: - mintStatus = _a.sent(); - if (ValidTokenRegistryStatus.guard(mintStatus)) { - fragment = { - name: name, - type: type, - status: "VALID", - }; - if (utils.isWrappedV3Document(document)) { - return [2 /*return*/, __assign(__assign({}, fragment), { data: { mintedOnAll: true, details: mintStatus } })]; - } - else { - return [2 /*return*/, __assign(__assign({}, fragment), { data: { mintedOnAll: true, details: [mintStatus] } })]; - } - } - else { - fragment = { - name: name, - type: type, - reason: mintStatus.reason, - status: "INVALID", - }; - if (utils.isWrappedV3Document(document)) { - return [2 /*return*/, __assign(__assign({}, fragment), { data: { mintedOnAll: false, details: mintStatus } })]; - } - else { - return [2 /*return*/, __assign(__assign({}, fragment), { data: { mintedOnAll: false, details: [mintStatus] } })]; - } - } - return [2 /*return*/]; - } - }); -}); }; -export var openAttestationEthereumTokenRegistryStatus = { - skip: skip, - test: test, - verify: withCodedErrorHandler(verify, { - name: name, - type: type, - unexpectedErrorCode: OpenAttestationEthereumTokenRegistryStatusCode.UNEXPECTED_ERROR, - unexpectedErrorString: OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.UNEXPECTED_ERROR], - }), -}; diff --git a/dist/esm/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.js b/dist/esm/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.js deleted file mode 100644 index 4f842694..00000000 --- a/dist/esm/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.js +++ /dev/null @@ -1,36 +0,0 @@ -import { Array as RunTypesArray, Literal, Record, String, Union } from "runtypes"; -import { Reason } from "../../../types/error"; -/** - * Token registry mint status - */ -export var ValidTokenRegistryStatus = Record({ - minted: Literal(true), - address: String, -}); -export var InvalidTokenRegistryStatus = Record({ - minted: Literal(false), - address: String, - reason: Reason, -}); -/** - * Data for v2 Fragments - */ -export var ValidTokenRegistryDataV2 = Record({ - mintedOnAll: Literal(true), - details: RunTypesArray(ValidTokenRegistryStatus), -}); -export var InvalidTokenRegistryDataV2 = Record({ - mintedOnAll: Literal(false), - details: RunTypesArray(Union(ValidTokenRegistryStatus, InvalidTokenRegistryStatus)), -}); -/** - * Data for v3 Fragments - */ -export var ValidTokenRegistryDataV3 = Record({ - mintedOnAll: Literal(true), - details: ValidTokenRegistryStatus, -}); -export var InvalidTokenRegistryDataV3 = Record({ - mintedOnAll: Literal(false), - details: InvalidTokenRegistryStatus, -}); diff --git a/dist/esm/verifiers/documentStatus/tokenRegistry/index.js b/dist/esm/verifiers/documentStatus/tokenRegistry/index.js deleted file mode 100644 index 45f2ecca..00000000 --- a/dist/esm/verifiers/documentStatus/tokenRegistry/index.js +++ /dev/null @@ -1 +0,0 @@ -export * from "./ethereumTokenRegistryStatus"; diff --git a/dist/esm/verifiers/documentStatus/utils.js b/dist/esm/verifiers/documentStatus/utils.js deleted file mode 100644 index 367338c4..00000000 --- a/dist/esm/verifiers/documentStatus/utils.js +++ /dev/null @@ -1,182 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -import { utils } from "@govtechsg/open-attestation"; -import { errors } from "ethers"; -import { DocumentStoreFactory } from "@govtechsg/document-store"; -import { OpenAttestationEthereumDocumentStoreStatusCode, OpenAttestationDidSignedDocumentStatusCode, } from "../../types/error"; -import { CodedError } from "../../common/error"; -import { OcspResponderRevocationReason } from "./revocation.types"; -import axios from "axios"; -import { ValidOcspResponse, ValidOcspResponseRevoked } from "./didSigned/didSignedDocumentStatus.type"; -export var getIntermediateHashes = function (targetHash, proofs) { - if (proofs === void 0) { proofs = []; } - var hashes = ["0x" + targetHash]; - proofs.reduce(function (prev, curr) { - var next = utils.combineHashString(prev, curr); - hashes.push("0x" + next); - return next; - }, targetHash); - return hashes; -}; -/** - * Try to decode the error to see if we can deterministically tell if the document has NOT been issued or revoked. - * - * In case where we cannot tell, we throw an error - * */ -export var decodeError = function (error) { - var _a, _b, _c, _d; - var reason = error.reason && Array.isArray(error.reason) ? error.reason[0] : (_a = error.reason) !== null && _a !== void 0 ? _a : ""; - switch (true) { - case !error.reason && - (((_b = error.method) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === "isRevoked(bytes32)".toLowerCase() || - ((_c = error.method) === null || _c === void 0 ? void 0 : _c.toLowerCase()) === "isIssued(bytes32)".toLowerCase()) && - error.code === errors.CALL_EXCEPTION: - return "Contract is not found"; - case reason.toLowerCase() === "ENS name not configured".toLowerCase() && - error.code === errors.UNSUPPORTED_OPERATION: - return "ENS name is not configured"; - case reason.toLowerCase() === "bad address checksum".toLowerCase() && error.code === errors.INVALID_ARGUMENT: - return "Bad document store address checksum"; - case ((_d = error.message) === null || _d === void 0 ? void 0 : _d.toLowerCase()) === "name not found".toLowerCase(): - return "ENS name is not found"; - case reason.toLowerCase() === "invalid address".toLowerCase() && error.code === errors.INVALID_ARGUMENT: - return "Invalid document store address"; - case error.code === errors.INVALID_ARGUMENT: - return "Invalid call arguments"; - case error.code === errors.SERVER_ERROR: - throw new CodedError("Unable to connect to the Ethereum network, please try again later", OpenAttestationEthereumDocumentStoreStatusCode.SERVER_ERROR, OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode.SERVER_ERROR]); - default: - throw error; - } -}; -/** - * Given a list of hashes, check against one smart contract if any of the hash has been revoked - * */ -export var isAnyHashRevoked = function (smartContract, intermediateHashes) { return __awaiter(void 0, void 0, void 0, function () { - var revokedStatusDeferred, revokedStatuses; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - revokedStatusDeferred = intermediateHashes.map(function (hash) { - return smartContract.isRevoked(hash).then(function (status) { return (status ? hash : undefined); }); - }); - return [4 /*yield*/, Promise.all(revokedStatusDeferred)]; - case 1: - revokedStatuses = _a.sent(); - return [2 /*return*/, revokedStatuses.find(function (hash) { return hash; })]; - } - }); -}); }; -export var isRevokedByOcspResponder = function (_a) { - var certificateId = _a.certificateId, location = _a.location; - return __awaiter(void 0, void 0, void 0, function () { - var data, reasonCode; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: return [4 /*yield*/, axios.get(location + "/" + certificateId)]; - case 1: - data = (_b.sent()).data; - if (ValidOcspResponseRevoked.guard(data) && data.certificateStatus === "revoked") { - reasonCode = data.reasonCode; - return [2 /*return*/, { - revoked: true, - address: location, - reason: { - message: OcspResponderRevocationReason[reasonCode], - code: reasonCode, - codeString: OcspResponderRevocationReason[reasonCode], - }, - }]; - } - else if (ValidOcspResponse.guard(data) && data.certificateStatus !== "revoked") { - return [2 /*return*/, { - revoked: false, - address: location, - }]; - } - throw new CodedError("oscp response invalid", OpenAttestationDidSignedDocumentStatusCode.OCSP_RESPONSE_INVALID, "OCSP_RESPONSE_INVALID"); - } - }); - }); -}; -export var isRevokedOnDocumentStore = function (_a) { - var documentStore = _a.documentStore, merkleRoot = _a.merkleRoot, provider = _a.provider, targetHash = _a.targetHash, proofs = _a.proofs; - return __awaiter(void 0, void 0, void 0, function () { - var documentStoreContract, intermediateHashes, revokedHash, error_1; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - _b.trys.push([0, 3, , 4]); - return [4 /*yield*/, DocumentStoreFactory.connect(documentStore, provider)]; - case 1: - documentStoreContract = _b.sent(); - intermediateHashes = getIntermediateHashes(targetHash, proofs); - return [4 /*yield*/, isAnyHashRevoked(documentStoreContract, intermediateHashes)]; - case 2: - revokedHash = _b.sent(); - return [2 /*return*/, revokedHash - ? { - revoked: true, - address: documentStore, - reason: { - message: "Document " + merkleRoot + " has been revoked under contract " + documentStore, - code: OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED, - codeString: OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED], - }, - } - : { - revoked: false, - address: documentStore, - }]; - case 3: - error_1 = _b.sent(); - // If error can be decoded and it's because of document is not revoked, we return false - // Else allow error to continue to bubble up - return [2 /*return*/, { - revoked: true, - address: documentStore, - reason: { - message: decodeError(error_1), - code: OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED, - codeString: OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED], - }, - }]; - case 4: return [2 /*return*/]; - } - }); - }); -}; diff --git a/dist/esm/verifiers/issuerIdentity/did/didIdentityProof.js b/dist/esm/verifiers/issuerIdentity/did/didIdentityProof.js deleted file mode 100644 index 4ead938e..00000000 --- a/dist/esm/verifiers/issuerIdentity/did/didIdentityProof.js +++ /dev/null @@ -1,182 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -import { getData, utils, v2, v3 } from "@govtechsg/open-attestation"; -import { OpenAttestationDidCode } from "../../../types/error"; -import { InvalidDidVerificationStatus, ValidDidVerificationStatus, ValidDidVerificationStatusArray, verifySignature, } from "../../../did/verifier"; -import { withCodedErrorHandler } from "../../../common/errorHandler"; -import { CodedError } from "../../../common/error"; -var name = "OpenAttestationDidIdentityProof"; -var type = "ISSUER_IDENTITY"; -var skip = function () { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, { - status: "SKIPPED", - type: type, - name: name, - reason: { - code: OpenAttestationDidCode.SKIPPED, - codeString: OpenAttestationDidCode[OpenAttestationDidCode.SKIPPED], - message: "Document is not using DID as top level identifier or has not been wrapped", - }, - }]; - }); -}); }; -var test = function (document) { - if (utils.isWrappedV2Document(document)) { - var issuers = getData(document).issuers; - return issuers.some(function (issuer) { var _a; return ((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === v2.IdentityProofType.Did; }); - } - else if (utils.isWrappedV3Document(document)) { - return document.openAttestationMetadata.identityProof.type === v3.IdentityProofType.Did; - } - return false; -}; -var verifyV2 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - var data, merkleRoot, signatureVerificationDeferred, signatureVerifications, invalidSignature; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!utils.isSignedWrappedV2Document(document)) - throw new CodedError("Document is not signed", OpenAttestationDidCode.UNSIGNED, "UNSIGNED"); - data = getData(document); - merkleRoot = "0x" + document.signature.merkleRoot; - signatureVerificationDeferred = data.issuers.map(function (issuer) { return __awaiter(void 0, void 0, void 0, function () { - var did, key_1, correspondingProof; - var _a, _b; - return __generator(this, function (_c) { - if (((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === "DID") { - did = issuer.id; - if (!did) - throw new CodedError("id is missing in issuer", OpenAttestationDidCode.DID_MISSING, "DID_MISSING"); - key_1 = (_b = issuer.identityProof) === null || _b === void 0 ? void 0 : _b.key; - if (!key_1) - throw new CodedError("Key is not present", OpenAttestationDidCode.MALFORMED_IDENTITY_PROOF, "MALFORMED_IDENTITY_PROOF"); - correspondingProof = document.proof.find(function (p) { return p.verificationMethod.toLowerCase() === key_1.toLowerCase(); }); - if (!correspondingProof) - throw new CodedError("No proof for " + key_1, OpenAttestationDidCode.MALFORMED_IDENTITY_PROOF, "MALFORMED_IDENTITY_PROOF"); - return [2 /*return*/, verifySignature({ - merkleRoot: merkleRoot, - key: key_1, - signature: correspondingProof.signature, - did: did, - resolver: options.resolver, - })]; - } - throw new CodedError("Issuer is not using DID identityProof type", OpenAttestationDidCode.INVALID_ISSUERS, OpenAttestationDidCode[OpenAttestationDidCode.INVALID_ISSUERS]); - }); - }); }); - return [4 /*yield*/, Promise.all(signatureVerificationDeferred)]; - case 1: - signatureVerifications = _a.sent(); - if (ValidDidVerificationStatusArray.guard(signatureVerifications)) { - return [2 /*return*/, { - name: name, - type: type, - data: signatureVerifications, - status: "VALID", - }]; - } - invalidSignature = signatureVerifications.find(InvalidDidVerificationStatus.guard); - if (InvalidDidVerificationStatus.guard(invalidSignature)) { - return [2 /*return*/, { - name: name, - type: type, - data: signatureVerifications, - reason: invalidSignature.reason, - status: "INVALID", - }]; - } - throw new CodedError("Unable to retrieve the reason of the failure", OpenAttestationDidCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); - } - }); -}); }; -var verifyV3 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - var merkleRoot, _a, key, signature, did, verificationStatus; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - if (!utils.isSignedWrappedV3Document(document)) - throw new CodedError("Document is not signed", OpenAttestationDidCode.UNSIGNED, "UNSIGNED"); - merkleRoot = "0x" + document.proof.merkleRoot; - _a = document.proof, key = _a.key, signature = _a.signature; - did = document.openAttestationMetadata.identityProof.identifier; - return [4 /*yield*/, verifySignature({ - did: did, - merkleRoot: merkleRoot, - key: key, - signature: signature, - resolver: options.resolver, - })]; - case 1: - verificationStatus = _b.sent(); - if (ValidDidVerificationStatus.guard(verificationStatus)) { - return [2 /*return*/, { - name: name, - type: type, - data: verificationStatus, - status: "VALID", - }]; - } - return [2 /*return*/, { - name: name, - type: type, - data: verificationStatus, - reason: verificationStatus.reason, - status: "INVALID", - }]; - } - }); -}); }; -var verify = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - if (utils.isWrappedV2Document(document)) - return [2 /*return*/, verifyV2(document, options)]; - else if (utils.isWrappedV3Document(document)) - return [2 /*return*/, verifyV3(document, options)]; - throw new CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", OpenAttestationDidCode.UNRECOGNIZED_DOCUMENT, OpenAttestationDidCode[OpenAttestationDidCode.UNRECOGNIZED_DOCUMENT]); - }); -}); }; -export var openAttestationDidIdentityProof = { - skip: skip, - test: test, - verify: withCodedErrorHandler(verify, { - name: name, - type: type, - unexpectedErrorCode: OpenAttestationDidCode.UNEXPECTED_ERROR, - unexpectedErrorString: OpenAttestationDidCode[OpenAttestationDidCode.UNEXPECTED_ERROR], - }), -}; diff --git a/dist/esm/verifiers/issuerIdentity/did/didIdentityProof.type.js b/dist/esm/verifiers/issuerIdentity/did/didIdentityProof.type.js deleted file mode 100644 index cb0ff5c3..00000000 --- a/dist/esm/verifiers/issuerIdentity/did/didIdentityProof.type.js +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/esm/verifiers/issuerIdentity/did/index.js b/dist/esm/verifiers/issuerIdentity/did/index.js deleted file mode 100644 index cd1e1bb4..00000000 --- a/dist/esm/verifiers/issuerIdentity/did/index.js +++ /dev/null @@ -1 +0,0 @@ -export * from "./didIdentityProof"; diff --git a/dist/esm/verifiers/issuerIdentity/dnsDid/dnsDidProof.js b/dist/esm/verifiers/issuerIdentity/dnsDid/dnsDidProof.js deleted file mode 100644 index a625d705..00000000 --- a/dist/esm/verifiers/issuerIdentity/dnsDid/dnsDidProof.js +++ /dev/null @@ -1,183 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -import { getData, utils, v2, v3 } from "@govtechsg/open-attestation"; -import { getDnsDidRecords } from "@govtechsg/dnsprove"; -import { OpenAttestationDnsDidCode } from "../../../types/error"; -import { withCodedErrorHandler } from "../../../common/errorHandler"; -import { CodedError } from "../../../common/error"; -import { ValidDnsDidVerificationStatus, ValidDnsDidVerificationStatusArray, } from "./dnsDidProof.type"; -var name = "OpenAttestationDnsDidIdentityProof"; -var type = "ISSUER_IDENTITY"; -var skip = function () { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, { - status: "SKIPPED", - type: type, - name: name, - reason: { - code: OpenAttestationDnsDidCode.SKIPPED, - codeString: OpenAttestationDnsDidCode[OpenAttestationDnsDidCode.SKIPPED], - message: "Document was not issued using DNS-DID", - }, - }]; - }); -}); }; -var test = function (document) { - if (utils.isSignedWrappedV2Document(document)) { - var data = getData(document); - return data.issuers.some(function (issuer) { var _a; return ((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === "DNS-DID"; }); - } - else if (utils.isSignedWrappedV3Document(document)) { - return document.openAttestationMetadata.identityProof.type === v3.IdentityProofType.DNSDid; - } - return false; -}; -var verifyIssuerDnsDid = function (_a) { - var key = _a.key, location = _a.location; - return __awaiter(void 0, void 0, void 0, function () { - var records; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: return [4 /*yield*/, getDnsDidRecords(location)]; - case 1: - records = _b.sent(); - return [2 /*return*/, { - location: location, - key: key, - status: records.some(function (record) { return record.publicKey.toLowerCase() === key.toLowerCase(); }) ? "VALID" : "INVALID", - }]; - } - }); - }); -}; -var verifyV2 = function (document) { return __awaiter(void 0, void 0, void 0, function () { - var documentData, deferredVerificationStatus, verificationStatus; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - documentData = getData(document); - deferredVerificationStatus = documentData.issuers.map(function (issuer) { - var identityProof = issuer.identityProof; - if (!identityProof) - throw new CodedError("Identity proof missing", OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF, OpenAttestationDnsDidCode[OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF]); - var key = identityProof.key, location = identityProof.location, identityProofType = identityProof.type; - if (identityProofType !== v2.IdentityProofType.DNSDid) - throw new CodedError("Issuer is not using DID-DNS identityProof type", OpenAttestationDnsDidCode.INVALID_ISSUERS, OpenAttestationDnsDidCode[OpenAttestationDnsDidCode.INVALID_ISSUERS]); - if (!location) - throw new CodedError("location is not present in identity proof", OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF, OpenAttestationDnsDidCode[OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF]); - if (!key) - throw new CodedError("key is not present in identity proof", OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF, OpenAttestationDnsDidCode[OpenAttestationDnsDidCode.MALFORMED_IDENTITY_PROOF]); - return verifyIssuerDnsDid({ key: key, location: location }); - }); - return [4 /*yield*/, Promise.all(deferredVerificationStatus)]; - case 1: - verificationStatus = _a.sent(); - if (ValidDnsDidVerificationStatusArray.guard(verificationStatus)) { - return [2 /*return*/, { - name: name, - type: type, - data: verificationStatus, - status: "VALID", - }]; - } - return [2 /*return*/, { - name: name, - type: type, - data: verificationStatus, - reason: { - message: "Could not find identity at location", - code: OpenAttestationDnsDidCode.INVALID_IDENTITY, - codeString: "INVALID_IDENTITY", - }, - status: "INVALID", - }]; - } - }); -}); }; -var verifyV3 = function (document) { return __awaiter(void 0, void 0, void 0, function () { - var location, key, verificationStatus; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!utils.isSignedWrappedV3Document(document)) - throw new CodedError("document is not signed", OpenAttestationDnsDidCode.UNSIGNED, OpenAttestationDnsDidCode[OpenAttestationDnsDidCode.UNSIGNED]); - location = document.openAttestationMetadata.identityProof.identifier; - key = document.proof.key; - return [4 /*yield*/, verifyIssuerDnsDid({ key: key, location: location })]; - case 1: - verificationStatus = _a.sent(); - if (ValidDnsDidVerificationStatus.guard(verificationStatus)) { - return [2 /*return*/, { - name: name, - type: type, - data: verificationStatus, - status: "VALID", - }]; - } - return [2 /*return*/, { - name: name, - type: type, - data: verificationStatus, - status: "INVALID", - reason: { - message: "Could not find identity at location", - code: OpenAttestationDnsDidCode.INVALID_IDENTITY, - codeString: "INVALID_IDENTITY", - }, - }]; - } - }); -}); }; -var verify = function (document) { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - if (utils.isSignedWrappedV2Document(document)) - return [2 /*return*/, verifyV2(document)]; - else if (utils.isSignedWrappedV3Document(document)) - return [2 /*return*/, verifyV3(document)]; - throw new CodedError("Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.", OpenAttestationDnsDidCode.UNRECOGNIZED_DOCUMENT, OpenAttestationDnsDidCode[OpenAttestationDnsDidCode.UNRECOGNIZED_DOCUMENT]); - }); -}); }; -export var openAttestationDnsDidIdentityProof = { - skip: skip, - test: test, - verify: withCodedErrorHandler(verify, { - name: name, - type: type, - unexpectedErrorCode: OpenAttestationDnsDidCode.UNEXPECTED_ERROR, - unexpectedErrorString: OpenAttestationDnsDidCode[OpenAttestationDnsDidCode.UNEXPECTED_ERROR], - }), -}; diff --git a/dist/esm/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.js b/dist/esm/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.js deleted file mode 100644 index 177308f3..00000000 --- a/dist/esm/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.js +++ /dev/null @@ -1,17 +0,0 @@ -import { Array as RunTypesArray, Literal, Record, String, Union } from "runtypes"; -/** - * DNS-DID verification status - */ -export var ValidDnsDidVerificationStatus = Record({ - status: Literal("VALID"), - location: String, - key: String, -}); -export var ValidDnsDidVerificationStatusArray = RunTypesArray(ValidDnsDidVerificationStatus).withConstraint(function (elements) { return elements.length > 0 || "Expect at least one valid element"; }); -export var InvalidDnsDidVerificationStatus = Record({ - status: Literal("INVALID"), - location: String, - key: String, -}); -export var DnsDidVerificationStatus = Union(ValidDnsDidVerificationStatus, InvalidDnsDidVerificationStatus); -export var DnsDidVerificationStatusArray = RunTypesArray(DnsDidVerificationStatus); diff --git a/dist/esm/verifiers/issuerIdentity/dnsDid/index.js b/dist/esm/verifiers/issuerIdentity/dnsDid/index.js deleted file mode 100644 index 5433c63d..00000000 --- a/dist/esm/verifiers/issuerIdentity/dnsDid/index.js +++ /dev/null @@ -1 +0,0 @@ -export * from "./dnsDidProof"; diff --git a/dist/esm/verifiers/issuerIdentity/dnsTxt/index.js b/dist/esm/verifiers/issuerIdentity/dnsTxt/index.js deleted file mode 100644 index 3d32f907..00000000 --- a/dist/esm/verifiers/issuerIdentity/dnsTxt/index.js +++ /dev/null @@ -1 +0,0 @@ -export * from "./openAttestationDnsTxt"; diff --git a/dist/esm/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.js b/dist/esm/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.js deleted file mode 100644 index 57d115a9..00000000 --- a/dist/esm/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.js +++ /dev/null @@ -1,217 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -import { getData, utils, v2, v3 } from "@govtechsg/open-attestation"; -import { getDocumentStoreRecords } from "@govtechsg/dnsprove"; -import { OpenAttestationDnsTxtCode } from "../../../types/error"; -import { withCodedErrorHandler } from "../../../common/errorHandler"; -import { CodedError } from "../../../common/error"; -import { InvalidDnsTxtVerificationStatus, ValidDnsTxtVerificationStatus, ValidDnsTxtVerificationStatusArray, } from "./openAttestationDnsTxt.type"; -var name = "OpenAttestationDnsTxtIdentityProof"; -var type = "ISSUER_IDENTITY"; -// Resolve identity of an issuer, currently supporting only DNS-TXT -// DNS-TXT is explained => https://github.com/Open-Attestation/adr/blob/master/decentralized_identity_proof_DNS-TXT.md -var resolveIssuerIdentity = function (location, smartContractAddress, options) { return __awaiter(void 0, void 0, void 0, function () { - var network, records, matchingRecord; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, options.provider.getNetwork()]; - case 1: - network = _a.sent(); - return [4 /*yield*/, getDocumentStoreRecords(location)]; - case 2: - records = _a.sent(); - matchingRecord = records.find(function (record) { - return record.addr.toLowerCase() === smartContractAddress.toLowerCase() && - record.netId === network.chainId.toString(10) && - record.type === "openatts" && - record.net === "ethereum"; - }); - return [2 /*return*/, matchingRecord - ? { - status: "VALID", - location: location, - value: smartContractAddress, - } - : { - status: "INVALID", - location: location, - value: smartContractAddress, - reason: { - message: "Matching DNS record not found for " + smartContractAddress, - code: OpenAttestationDnsTxtCode.MATCHING_RECORD_NOT_FOUND, - codeString: OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode.MATCHING_RECORD_NOT_FOUND], - }, - }]; - } - }); -}); }; -var skip = function () { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, { - status: "SKIPPED", - type: type, - name: name, - reason: { - code: OpenAttestationDnsTxtCode.SKIPPED, - codeString: OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode.SKIPPED], - message: "Document issuers doesn't have \"documentStore\" / \"tokenRegistry\" property or doesn't use " + v3.IdentityProofType.DNSTxt + " type", - }, - }]; - }); -}); }; -var test = function (document) { - if (utils.isWrappedV2Document(document)) { - var documentData = getData(document); - // at least one issuer uses DNS-TXT - return documentData.issuers.some(function (issuer) { - var _a; - return ((issuer.documentStore || issuer.tokenRegistry || issuer.certificateStore) && - ((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === v2.IdentityProofType.DNSTxt); - }); - } - else if (utils.isWrappedV3Document(document)) { - return document.openAttestationMetadata.identityProof.type === v3.IdentityProofType.DNSTxt; - } - return false; -}; -var verifyV2 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - var documentData, identities, invalidIdentity; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - documentData = getData(document); - return [4 /*yield*/, Promise.all(documentData.issuers.map(function (issuer) { - var _a; - if (((_a = issuer.identityProof) === null || _a === void 0 ? void 0 : _a.type) === v2.IdentityProofType.DNSTxt) { - var location = issuer.identityProof.location; - var smartContractAddress = issuer.documentStore || issuer.tokenRegistry || issuer.certificateStore; - if (!location) - throw new CodedError("Location not found in identity proof", OpenAttestationDnsTxtCode.INVALID_ISSUERS, OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode.INVALID_ISSUERS]); - if (!smartContractAddress) - throw new CodedError("Smart contract address not found in identity proof", OpenAttestationDnsTxtCode.INVALID_ISSUERS, OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode.INVALID_ISSUERS]); - return resolveIssuerIdentity(location, smartContractAddress, options); - } - var invalidResponse = { - status: "INVALID", - reason: { - message: "Issuer is not using DNS-TXT identityProof type", - code: OpenAttestationDnsTxtCode.INVALID_ISSUERS, - codeString: OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode.INVALID_ISSUERS], - }, - }; - return invalidResponse; // eslint is happy, so am I (https://github.com/bradzacher/eslint-plugin-typescript/blob/master/docs/rules/no-object-literal-type-assertion.md) - }))]; - case 1: - identities = _a.sent(); - if (ValidDnsTxtVerificationStatusArray.guard(identities)) { - return [2 /*return*/, { - name: name, - type: type, - data: identities, - status: "VALID", - }]; - } - invalidIdentity = identities.find(InvalidDnsTxtVerificationStatus.guard); - if (InvalidDnsTxtVerificationStatus.guard(invalidIdentity)) { - return [2 /*return*/, { - name: name, - type: type, - data: identities, - reason: invalidIdentity.reason, - status: "INVALID", - }]; - } - throw new CodedError("Unable to retrieve the reason of the failure", OpenAttestationDnsTxtCode.UNEXPECTED_ERROR, "UNEXPECTED_ERROR"); - } - }); -}); }; -var verifyV3 = function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - var smartContractAddress, identifier, issuerIdentity; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (document.openAttestationMetadata.proof.method !== v3.Method.DocumentStore && - document.openAttestationMetadata.proof.method !== v3.Method.TokenRegistry) - throw new CodedError("DNS-TXT is only supported with documents issued using document store or token registry", OpenAttestationDnsTxtCode.UNSUPPORTED, OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode.UNSUPPORTED]); - smartContractAddress = document.openAttestationMetadata.proof.value; - identifier = document.openAttestationMetadata.identityProof.identifier; - return [4 /*yield*/, resolveIssuerIdentity(identifier, smartContractAddress, options)]; - case 1: - issuerIdentity = _a.sent(); - if (ValidDnsTxtVerificationStatus.guard(issuerIdentity)) { - return [2 /*return*/, { - name: name, - type: type, - data: { - identifier: issuerIdentity.location, - value: issuerIdentity.value, - }, - status: "VALID", - }]; - } - return [2 /*return*/, { - name: name, - type: type, - data: { - identifier: issuerIdentity.location, - value: issuerIdentity.value, - }, - reason: issuerIdentity.reason, - status: "INVALID", - }]; - } - }); -}); }; -export var openAttestationDnsTxtIdentityProof = { - skip: skip, - test: test, - verify: withCodedErrorHandler(function (document, options) { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - if (utils.isWrappedV2Document(document)) - return [2 /*return*/, verifyV2(document, options)]; - else if (utils.isWrappedV3Document(document)) - return [2 /*return*/, verifyV3(document, options)]; - // this code is actually unreachable because of the test function - throw new CodedError("Document does not match either v2 or v3 formats", OpenAttestationDnsTxtCode.UNRECOGNIZED_DOCUMENT, OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode.UNRECOGNIZED_DOCUMENT]); - }); - }); }, { - name: name, - type: type, - unexpectedErrorCode: OpenAttestationDnsTxtCode.UNEXPECTED_ERROR, - unexpectedErrorString: OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode.UNEXPECTED_ERROR], - }), -}; diff --git a/dist/esm/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.js b/dist/esm/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.js deleted file mode 100644 index 63bd0854..00000000 --- a/dist/esm/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.js +++ /dev/null @@ -1,30 +0,0 @@ -import { Array as RunTypesArray, Literal, Optional, Record, String, Union } from "runtypes"; -import { Reason } from "../../../types/error"; -/** - * DNS-TXT verification status - */ -export var ValidDnsTxtVerificationStatus = Record({ - status: Literal("VALID"), - location: String, - value: String, -}); -export var ValidDnsTxtVerificationStatusArray = RunTypesArray(ValidDnsTxtVerificationStatus).withConstraint(function (elements) { return elements.length > 0 || "Expect at least one valid element"; }); -export var InvalidDnsTxtVerificationStatus = Record({ - status: Literal("INVALID"), - location: Optional(String), - value: Optional(String), - reason: Reason, -}); -export var DnsTxtVerificationStatus = Union(ValidDnsTxtVerificationStatus, InvalidDnsTxtVerificationStatus); -export var DnsTxtVerificationStatusArray = RunTypesArray(DnsTxtVerificationStatus); -/** - * Data for v3 Fragments - */ -export var ValidDnsTxtVerificationStatusDataV3 = Record({ - identifier: String, - value: String, -}); -// by design runtypes will validate arrays when an object has only partial properties -// https://github.com/pelotom/runtypes/issues/32 -export var InvalidDnsTxtVerificationStatusDataV3 = ValidDnsTxtVerificationStatusDataV3.asPartial().withConstraint(function (value) { return !Array.isArray(value) || "can't be an array"; }); -export var DnsTxtVerificationStatusDataV3 = Union(ValidDnsTxtVerificationStatusDataV3, InvalidDnsTxtVerificationStatusDataV3); diff --git a/dist/esm/verifiers/verificationBuilder.js b/dist/esm/verifiers/verificationBuilder.js deleted file mode 100644 index ec2fffb0..00000000 --- a/dist/esm/verifiers/verificationBuilder.js +++ /dev/null @@ -1,33 +0,0 @@ -import { getProvider } from "../common/utils"; -import { warnProvider } from "../common/messages"; -// keeping the following code for posterity. If we want the function below to return better types, we can use the following -// type PromiseValue = T extends Promise ? U : never; -// Promise>[]> -/** - * A verification manager will run a list of {@link Verifier} over a signed document. - * Before running each verifier, the manager will make sure the verifier can handle the specific document by calling its exposed test function. - * The manager will return the consolidated list of {@link VerificationFragment} - */ -var displayWarning = true; -export var verificationBuilder = function (verifiers, builderOptions) { return function (document, promisesCallback) { - // if the user didn't configure an API key and didn't configure a provider or a resolver, then he will likely use a development key. We then warn him once, that he may need to configure things properly, especially for production - if (displayWarning && - (!builderOptions.resolver || !builderOptions.provider) && - !process.env.INFURA_API_KEY && - !process.env.PROVIDER_API_KEY) { - displayWarning = false; - console.warn(warnProvider); - } - var verifierOptions = { - provider: getProvider(builderOptions), - resolver: builderOptions.resolver, - }; - var promises = verifiers.map(function (verifier) { - if (verifier.test(document, verifierOptions)) { - return verifier.verify(document, verifierOptions); - } - return verifier.skip(document, verifierOptions); - }); - promisesCallback === null || promisesCallback === void 0 ? void 0 : promisesCallback(promises); - return Promise.all(promises); -}; }; diff --git a/dist/types/src/common/error.d.ts b/dist/types/src/common/error.d.ts deleted file mode 100644 index f2e9e08e..00000000 --- a/dist/types/src/common/error.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -export declare class CodedError extends Error { - code: number; - codeString: string; - constructor(message: string, code: number, codeString: string); -} diff --git a/dist/types/src/common/errorHandler.d.ts b/dist/types/src/common/errorHandler.d.ts deleted file mode 100644 index 22d8542a..00000000 --- a/dist/types/src/common/errorHandler.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { DocumentsToVerify, ErrorVerificationFragment, VerificationFragment, VerificationFragmentType, VerifierOptions } from "../types/core"; -export interface ErrorOptions { - name: string; - type: VerificationFragmentType; - unexpectedErrorCode: number; - unexpectedErrorString: string; -} -export declare const withCodedErrorHandler: Promise>(verify: T, errorOptions: ErrorOptions) => (document: DocumentsToVerify, options: VerifierOptions) => ReturnType | Promise>; diff --git a/dist/types/src/common/logger.d.ts b/dist/types/src/common/logger.d.ts deleted file mode 100644 index 987dfdb2..00000000 --- a/dist/types/src/common/logger.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import debug from "debug"; -interface Logger { - trace: debug.Debugger; - debug: debug.Debugger; - info: debug.Debugger; - warn: debug.Debugger; - error: debug.Debugger; -} -export declare const getLogger: (namespace: string) => Logger; -export {}; diff --git a/dist/types/src/common/messages.d.ts b/dist/types/src/common/messages.d.ts deleted file mode 100644 index 35eb3e12..00000000 --- a/dist/types/src/common/messages.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const warnProvider = "You are falling back to oa-verify default configuration, which is not suitable for production environment. It is highly recommended that you configure and provide your own API key. Refer to https://github.com/Open-Attestation/oa-verify#provider"; diff --git a/dist/types/src/common/utils.d.ts b/dist/types/src/common/utils.d.ts deleted file mode 100644 index be33215a..00000000 --- a/dist/types/src/common/utils.d.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { providers } from "ethers"; -import { VerificationBuilderOptions, VerificationBuilderOptionsWithNetwork, VerificationFragment, ProviderDetails } from "../types/core"; -import { OpenAttestationHashVerificationFragment } from "../verifiers/documentIntegrity/hash/openAttestationHash.type"; -import { OpenAttestationDidSignedDocumentStatusVerificationFragment } from "../verifiers/documentStatus/didSigned/didSignedDocumentStatus.type"; -import { OpenAttestationEthereumDocumentStoreStatusFragment } from "../verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type"; -import { OpenAttestationEthereumTokenRegistryStatusFragment } from "../verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type"; -import { OpenAttestationDidIdentityProofVerificationFragment } from "../verifiers/issuerIdentity/did/didIdentityProof.type"; -import { OpenAttestationDnsDidIdentityProofVerificationFragment } from "../verifiers/issuerIdentity/dnsDid/dnsDidProof.type"; -import { OpenAttestationDnsTxtIdentityProofVerificationFragment } from "../verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type"; -export declare const getDefaultProvider: (options: VerificationBuilderOptionsWithNetwork) => providers.Provider; -export declare const getProvider: (options: VerificationBuilderOptions) => providers.Provider; -/** - * Generate Provider generates a provider based on the defined options or your env var, if no options or env var was detected, it will generate a provider based on the default values. - * Generate Provider using the following options: (if no option is specified it will use the default values) - * @param {Object} ProviderDetails - Details to use for the function to successfully generate a provider. - * @param {string} ProviderDetails.network - The network in which the provider is connected to, i.e. "homestead", "mainnet", "ropsten", "rinkeby" - * @param {string} ProviderDetails.providerType - Specify which provider to use: "infura", "alchemy" or "jsonrpc" - * @param {string} ProviderDetails.url - Specify which url for JsonRPC to connect to, if not specified will connect to localhost:8545 - * @param {string} ProviderDetails.apiKey - If no apiKey is provided, a default shared API key will be used, which may result in reduced performance and throttled requests. - */ -export declare const generateProvider: (options?: ProviderDetails | undefined) => providers.Provider; -/** - * Simple typed utility to return a fragment depending on the name - * @param name - */ -export declare const getFragmentByName: (name: string) => (fragments: Fragment[]) => ReturnedFragment | undefined; -export declare const getOpenAttestationHashFragment: (fragments: Fragment[]) => OpenAttestationHashVerificationFragment | undefined; -export declare const getOpenAttestationDidSignedDocumentStatusFragment: (fragments: Fragment[]) => OpenAttestationDidSignedDocumentStatusVerificationFragment | undefined; -export declare const getOpenAttestationEthereumDocumentStoreStatusFragment: (fragments: Fragment[]) => OpenAttestationEthereumDocumentStoreStatusFragment | undefined; -export declare const getOpenAttestationEthereumTokenRegistryStatusFragment: (fragments: Fragment[]) => OpenAttestationEthereumTokenRegistryStatusFragment | undefined; -export declare const getOpenAttestationDidIdentityProofFragment: (fragments: Fragment[]) => OpenAttestationDidIdentityProofVerificationFragment | undefined; -export declare const getOpenAttestationDnsDidIdentityProofFragment: (fragments: Fragment[]) => OpenAttestationDnsDidIdentityProofVerificationFragment | undefined; -export declare const getOpenAttestationDnsTxtIdentityProofFragment: (fragments: Fragment[]) => OpenAttestationDnsTxtIdentityProofVerificationFragment | undefined; -export declare const getDocumentIntegrityFragments: (fragments: Fragment[]) => (Fragment & { - type: "DOCUMENT_INTEGRITY"; -})[]; -export declare const getDocumentStatusFragments: (fragments: Fragment[]) => (Fragment & { - type: "DOCUMENT_STATUS"; -})[]; -export declare const getIssuerIdentityFragments: (fragments: Fragment[]) => (Fragment & { - type: "ISSUER_IDENTITY"; -})[]; -/** - * type utilities and guard to get fragment depending on the status - */ -declare type ValidFragment = Type extends { - status: "VALID"; -} ? Type : never; -declare type InvalidFragment = Type extends { - status: "INVALID"; -} ? Type : never; -declare type SkippedFragment = Type extends { - status: "SKIPPED"; -} ? Type : never; -declare type ErrorFragment = Type extends { - status: "ERROR"; -} ? Type : never; -export declare const isValidFragment: (fragment: Fragment | undefined) => fragment is ValidFragment; -export declare const isInvalidFragment: (fragment: Fragment | undefined) => fragment is InvalidFragment; -export declare const isSkippedFragment: (fragment: Fragment | undefined) => fragment is SkippedFragment; -export declare const isErrorFragment: (fragment: Fragment | undefined) => fragment is ErrorFragment; -export declare const isDocumentStoreAddressOrTokenRegistryAddressInvalid: (fragments: VerificationFragment[]) => boolean; -export declare const contractNotFound: (fragments: VerificationFragment[]) => boolean; -export declare const certificateNotIssued: (fragments: VerificationFragment[]) => boolean; -export declare const certificateRevoked: (fragments: VerificationFragment[]) => boolean; -export declare const invalidArgument: (fragments: VerificationFragment[]) => boolean; -export declare const serverError: (fragments: VerificationFragment[]) => boolean; -export declare const unhandledError: (fragments: VerificationFragment[]) => boolean; -export {}; diff --git a/dist/types/src/common/utils.test.d.ts b/dist/types/src/common/utils.test.d.ts deleted file mode 100644 index cb0ff5c3..00000000 --- a/dist/types/src/common/utils.test.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/types/src/config.d.ts b/dist/types/src/config.d.ts deleted file mode 100644 index 7f56705f..00000000 --- a/dist/types/src/config.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const INFURA_API_KEY: string; diff --git a/dist/types/src/did/resolver.d.ts b/dist/types/src/did/resolver.d.ts deleted file mode 100644 index f6ae702a..00000000 --- a/dist/types/src/did/resolver.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { DIDDocument, Resolver, VerificationMethod } from "did-resolver"; -export interface EthrResolverConfig { - networks: Array<{ - name: string; - registry?: string; - rpcUrl: string; - }>; -} -export declare const getProviderConfig: () => { - networks: { - name: any; - rpcUrl: any; - }[]; -}; -export declare const createResolver: ({ ethrResolverConfig }: { - ethrResolverConfig?: EthrResolverConfig | undefined; -}) => Resolver; -export declare const resolve: (didUrl: string, resolver?: Resolver | undefined) => Promise; -export declare const getVerificationMethod: (did: string, key: string, resolver?: Resolver | undefined) => Promise; diff --git a/dist/types/src/did/resolver.test.d.ts b/dist/types/src/did/resolver.test.d.ts deleted file mode 100644 index cb0ff5c3..00000000 --- a/dist/types/src/did/resolver.test.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/types/src/did/verifier.d.ts b/dist/types/src/did/verifier.d.ts deleted file mode 100644 index 08d0d16c..00000000 --- a/dist/types/src/did/verifier.d.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { VerificationMethod, Resolver } from "did-resolver"; -import { Literal, Record, Static, String, Union, Array as RunTypesArray } from "runtypes"; -export declare const ValidDidVerificationStatus: Record<{ - verified: Literal; - did: String; -}, false>; -export declare type ValidDidVerificationStatus = Static; -export declare const ValidDidVerificationStatusArray: import("runtypes").Constraint; - did: String; -}, false>, false>, { - did: string; - verified: true; -}[], unknown>; -export declare type ValidDidVerificationStatusArray = Static; -export declare const InvalidDidVerificationStatus: Record<{ - verified: Literal; - did: String; - reason: Record<{ - code: import("runtypes").Number; - codeString: String; - message: String; - }, false>; -}, false>; -export declare type InvalidDidVerificationStatus = Static; -export declare const DidVerificationStatus: Union<[Record<{ - verified: Literal; - did: String; -}, false>, Record<{ - verified: Literal; - did: String; - reason: Record<{ - code: import("runtypes").Number; - codeString: String; - message: String; - }, false>; -}, false>]>; -export declare type DidVerificationStatus = Static; -export declare const DidVerificationStatusArray: RunTypesArray; - did: String; -}, false>, Record<{ - verified: Literal; - did: String; - reason: Record<{ - code: import("runtypes").Number; - codeString: String; - message: String; - }, false>; -}, false>]>, false>; -export declare type DidVerificationStatusArray = Static; -interface VerifySignature { - did: string; - signature: string; - merkleRoot: string; - verificationMethod: VerificationMethod; -} -export declare const verifySecp256k1VerificationKey2018: ({ did, verificationMethod, merkleRoot, signature, }: VerifySignature) => DidVerificationStatus; -export declare const verifySignature: ({ key, merkleRoot, signature, did, resolver, }: { - key: string; - merkleRoot: string; - did: string; - signature: string; - resolver?: Resolver | undefined; -}) => Promise; -export {}; diff --git a/dist/types/src/getIdentifier.d.ts b/dist/types/src/getIdentifier.d.ts deleted file mode 100644 index d5b9bfbe..00000000 --- a/dist/types/src/getIdentifier.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { AllVerificationFragment } from "./types/core"; -export declare const getIdentifier: >(fragments: T[]) => { - identifier: string | undefined; - type: string; -}[] | { - identifier: string | undefined; - type: string; -}; diff --git a/dist/types/src/getIdentifier.test.d.ts b/dist/types/src/getIdentifier.test.d.ts deleted file mode 100644 index cb0ff5c3..00000000 --- a/dist/types/src/getIdentifier.test.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/types/src/index.d.ts b/dist/types/src/index.d.ts deleted file mode 100644 index 62c99519..00000000 --- a/dist/types/src/index.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { verificationBuilder } from "./verifiers/verificationBuilder"; -import { Verifier } from "./types/core"; -import { openAttestationHash } from "./verifiers/documentIntegrity/hash/openAttestationHash"; -import { isValid } from "./validator"; -import { openAttestationEthereumTokenRegistryStatus } from "./verifiers/documentStatus/tokenRegistry"; -import { openAttestationEthereumDocumentStoreStatus } from "./verifiers/documentStatus/documentStore"; -import { openAttestationDidSignedDocumentStatus } from "./verifiers/documentStatus/didSigned"; -import { openAttestationDnsTxtIdentityProof } from "./verifiers/issuerIdentity/dnsTxt"; -import { openAttestationDidIdentityProof } from "./verifiers/issuerIdentity/did"; -import { openAttestationDnsDidIdentityProof } from "./verifiers/issuerIdentity/dnsDid"; -import { createResolver } from "./did/resolver"; -import { getIdentifier } from "./getIdentifier"; -import * as utils from "./common/utils"; -declare const openAttestationVerifiers: (Verifier | Verifier | Verifier | Verifier | Verifier | Verifier)[]; -declare const verify: (document: import("./types/core").DocumentsToVerify, promisesCallback?: import("./types/core").PromiseCallback | undefined) => Promise; -export * from "./types/core"; -export * from "./verifiers/documentIntegrity/hash/openAttestationHash.type"; -export * from "./verifiers/documentStatus/didSigned/didSignedDocumentStatus.type"; -export * from "./verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type"; -export * from "./verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type"; -export * from "./verifiers/issuerIdentity/did/didIdentityProof.type"; -export * from "./verifiers/issuerIdentity/dnsDid/dnsDidProof.type"; -export * from "./verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type"; -export * from "./types/error"; -export * from "./common/error"; -export { verificationBuilder, openAttestationVerifiers, isValid, verify, Verifier, openAttestationHash, openAttestationEthereumDocumentStoreStatus, openAttestationEthereumTokenRegistryStatus, openAttestationDidSignedDocumentStatus, openAttestationDnsTxtIdentityProof, openAttestationDnsDidIdentityProof, openAttestationDidIdentityProof, createResolver, getIdentifier, utils, }; diff --git a/dist/types/src/types/core.d.ts b/dist/types/src/types/core.d.ts deleted file mode 100644 index 22bc4477..00000000 --- a/dist/types/src/types/core.d.ts +++ /dev/null @@ -1,111 +0,0 @@ -import { SignedWrappedDocument, v2, v3, WrappedDocument } from "@govtechsg/open-attestation"; -import { Resolver } from "did-resolver"; -import { providers } from "ethers"; -import { OcspResponderRevocationReason, OcspResponderRevocationStatus } from "src/verifiers/documentStatus/revocation.types"; -import { Reason } from "./error"; -/** - * Callback function that will provide back the promises resolving to the verification fragment. It will be called before the promises are all resolved and thus give the possibility to consumers to perform their own extra checks. - */ -export declare type PromiseCallback = (promises: Promise[]) => void; -export interface VerificationBuilderOptionsWithProvider { - provider: providers.Provider; - resolver?: Resolver; -} -export interface VerificationBuilderOptionsWithNetwork { - network: string; - resolver?: Resolver; - provider?: never; -} -export declare type VerificationBuilderOptions = VerificationBuilderOptionsWithProvider | VerificationBuilderOptionsWithNetwork; -export interface VerifierOptions { - provider: providers.Provider; - resolver?: Resolver; -} -/** - * A verification fragment is the result of a verification - * It will *always* - * - return the status - * - VALID: when the verification is successful - * - INVALID: when the verification is unsuccessful - * - ERROR: when an unexpected error is met - * - SKIPPED: when the verification was skipped by the manager - * - return the type who indicate the kind of checks performed - * - DOCUMENT_INTEGRITY - * - DOCUMENT_STATUS - * - ISSUER_IDENTITY - * - return the name who can help to determine the verifier that created the result - * - * Additional fields might be populated - * - A reason to provide further information about the error/invalid/skipped state - * - Data to provide further information - */ -export interface VerificationFragment { - name: string; - type: VerificationFragmentType; - status: VerificationFragmentStatus; -} -export interface ValidVerificationFragment extends VerificationFragment { - status: "VALID"; - data: Data; - reason?: never; -} -export interface InvalidVerificationFragment extends VerificationFragment { - status: "INVALID"; - reason: Reason; - data: Data; -} -export interface ErrorVerificationFragment extends VerificationFragment { - status: "ERROR"; - reason: Reason; - data: Data; -} -export interface SkippedVerificationFragment extends VerificationFragment { - status: "SKIPPED"; - reason: Reason; - data?: never; -} -export declare type VerificationFragmentType = "DOCUMENT_INTEGRITY" | "DOCUMENT_STATUS" | "ISSUER_IDENTITY"; -export declare type VerificationFragmentStatus = "ERROR" | "VALID" | "INVALID" | "SKIPPED"; -/** - * type for combined verification fragments that will hold data - */ -export declare type VerificationFragmentWithData = ValidVerificationFragment | InvalidVerificationFragment | ErrorVerificationFragment; -export declare const isVerificationFragmentWithData: (fragment: any) => fragment is VerificationFragmentWithData; -/** - * type for all verification fragments - */ -export declare type AllVerificationFragment = VerificationFragmentWithData | SkippedVerificationFragment; -/** - * A verifier is an object whose goal is to perform specific validation on a signed document. It exposes - * - a *test* function, who must return true or false. The function must indicate whether condition are fulfilled for the verifier to run on a specific signed document - * - a *verify* function, who must return the result of the verification as a {@link VerificationFragment} - * - a *skip* function, who must return the result of a verification when it's skipped by providing additional data on why the validation didn't run. - */ -export interface Verifier { - skip: (document: DocumentsToVerify, options: VerifierOptions) => Promise; - test: (document: DocumentsToVerify, options: VerifierOptions) => boolean; - verify: (document: DocumentsToVerify, options: VerifierOptions) => Promise; -} -export declare type Hash = string; -export declare type DocumentsToVerify = WrappedDocument | WrappedDocument | SignedWrappedDocument; -export declare type providerType = "alchemy" | "infura" | "jsonrpc"; -export interface ProviderDetails { - network?: string; - providerType?: providerType; - url?: string; - apiKey?: string; -} -/** - * Specifies the parameters of the OCSP response - * @param {string} certificateStatus - status of the certificate {@link OcspResponderRevocationStatus} - */ -export interface OcspResponse { - certificateStatus: OcspResponderRevocationStatus; -} -/** - * Specifies the parameters of the OCSP response when document is revoked - * @param {number} reasonCode - code indicating reason for revocation {@link OcspResponderRevocationReason} - */ -export interface OcspResponseRevoked extends OcspResponse { - reasonCode: OcspResponderRevocationReason; -} diff --git a/dist/types/src/types/error.d.ts b/dist/types/src/types/error.d.ts deleted file mode 100644 index 45792f2d..00000000 --- a/dist/types/src/types/error.d.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { Number, Record, Static, String } from "runtypes"; -export declare enum OpenAttestationEthereumDocumentStoreStatusCode { - UNEXPECTED_ERROR = 0, - DOCUMENT_NOT_ISSUED = 1, - CONTRACT_ADDRESS_INVALID = 2, - ETHERS_UNHANDLED_ERROR = 3, - SKIPPED = 4, - DOCUMENT_REVOKED = 5, - INVALID_ARGUMENT = 6, - CONTRACT_NOT_FOUND = 404, - INVALID_ISSUERS = 7, - INVALID_VALIDATION_METHOD = 8, - UNRECOGNIZED_DOCUMENT = 9, - SERVER_ERROR = 500 -} -export declare enum OpenAttestationDocumentSignedCode { - UNEXPECTED_ERROR = 0, - DOCUMENT_PROOF_INVALID = 1, - DOCUMENT_PROOF_ERROR = 2, - SKIPPED = 4 -} -export declare enum OpenAttestationEthereumTokenRegistryStatusCode { - UNEXPECTED_ERROR = 0, - DOCUMENT_NOT_MINTED = 1, - CONTRACT_ADDRESS_INVALID = 2, - ETHERS_UNHANDLED_ERROR = 3, - SKIPPED = 4, - INVALID_ISSUERS = 5, - INVALID_ARGUMENT = 6, - UNDEFINED_TOKEN_REGISTRY = 7, - INVALID_VALIDATION_METHOD = 8, - UNRECOGNIZED_DOCUMENT = 9, - SERVER_ERROR = 500 -} -export declare enum OpenAttestationDnsTxtCode { - UNEXPECTED_ERROR = 0, - INVALID_IDENTITY = 1, - SKIPPED = 2, - INVALID_ISSUERS = 3, - MATCHING_RECORD_NOT_FOUND = 4, - UNRECOGNIZED_DOCUMENT = 5, - UNSUPPORTED = 6 -} -export declare enum OpenAttestationHashCode { - DOCUMENT_TAMPERED = 0, - UNEXPECTED_ERROR = 1, - SKIPPED = 2 -} -export declare enum OpenAttestationDidSignedDocumentStatusCode { - SKIPPED = 0, - UNEXPECTED_ERROR = 1, - MISSING_REVOCATION = 2, - UNSIGNED = 3, - INVALID_ISSUERS = 4, - MALFORMED_IDENTITY_PROOF = 5, - CORRESPONDING_PROOF_MISSING = 6, - DID_MISSING = 7, - UNRECOGNIZED_DOCUMENT = 8, - UNRECOGNIZED_REVOCATION_TYPE = 9, - REVOCATION_LOCATION_MISSING = 10, - OCSP_RESPONSE_INVALID = 11 -} -export declare enum OpenAttestationDidCode { - SKIPPED = 0, - UNEXPECTED_ERROR = 1, - INVALID_ISSUERS = 2, - MALFORMED_IDENTITY_PROOF = 3, - DID_MISSING = 4, - UNSIGNED = 5, - UNRECOGNIZED_DOCUMENT = 6 -} -export declare enum OpenAttestationDnsDidCode { - SKIPPED = 0, - UNEXPECTED_ERROR = 1, - MALFORMED_IDENTITY_PROOF = 2, - INVALID_ISSUERS = 3, - UNSIGNED = 4, - UNRECOGNIZED_DOCUMENT = 5, - INVALID_IDENTITY = 6 -} -export declare enum OpenAttestationSignatureCode { - UNEXPECTED_ERROR = 0, - KEY_MISSING = 1, - DID_MISSING = 3, - KEY_NOT_IN_DID = 4, - UNSUPPORTED_KEY_TYPE = 6, - WRONG_SIGNATURE = 7 -} -export interface EthersError extends Error { - reason?: string | string[]; - code?: string; - method?: string; -} -export declare const Reason: Record<{ - code: Number; - codeString: String; - message: String; -}, false>; -export declare type Reason = Static; diff --git a/dist/types/src/validator.d.ts b/dist/types/src/validator.d.ts deleted file mode 100644 index 2329134a..00000000 --- a/dist/types/src/validator.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { VerificationFragment, VerificationFragmentType } from "./types/core"; -export declare const isValid: (verificationFragments: VerificationFragment[], types?: VerificationFragmentType[]) => boolean; diff --git a/dist/types/src/validator.test.d.ts b/dist/types/src/validator.test.d.ts deleted file mode 100644 index cb0ff5c3..00000000 --- a/dist/types/src/validator.test.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.d.ts b/dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.d.ts deleted file mode 100644 index 25b494ef..00000000 --- a/dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { Verifier } from "../../../types/core"; -import { OpenAttestationHashVerificationFragment } from "./openAttestationHash.type"; -declare type VerifierType = Verifier; -export declare const openAttestationHash: VerifierType; -export {}; diff --git a/dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.test.d.ts b/dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.test.d.ts deleted file mode 100644 index cb0ff5c3..00000000 --- a/dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.test.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.type.d.ts b/dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.type.d.ts deleted file mode 100644 index 64412667..00000000 --- a/dist/types/src/verifiers/documentIntegrity/hash/openAttestationHash.type.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { ErrorVerificationFragment, InvalidVerificationFragment, SkippedVerificationFragment, ValidVerificationFragment } from "../../../types/core"; -export declare type OpenAttestationHashValidFragment = ValidVerificationFragment; -export declare type OpenAttestationHashInvalidFragment = InvalidVerificationFragment; -export declare type OpenAttestationHashErrorFragment = ErrorVerificationFragment; -export declare type OpenAttestationHashVerificationFragment = OpenAttestationHashValidFragment | OpenAttestationHashInvalidFragment | OpenAttestationHashErrorFragment | SkippedVerificationFragment; diff --git a/dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.d.ts b/dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.d.ts deleted file mode 100644 index ffb2d35d..00000000 --- a/dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { Verifier } from "../../../types/core"; -import { OpenAttestationDidSignedDocumentStatusVerificationFragment } from "./didSignedDocumentStatus.type"; -declare type VerifierType = Verifier; -export declare const openAttestationDidSignedDocumentStatus: VerifierType; -export {}; diff --git a/dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.test.d.ts b/dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.test.d.ts deleted file mode 100644 index cb0ff5c3..00000000 --- a/dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.test.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.d.ts b/dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.d.ts deleted file mode 100644 index 65ee42d7..00000000 --- a/dist/types/src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.type.d.ts +++ /dev/null @@ -1,190 +0,0 @@ -import { Array as RunTypesArray, Boolean, Literal, Record, Static, String, Union, Number } from "runtypes"; -import { ErrorVerificationFragment, InvalidVerificationFragment, SkippedVerificationFragment, ValidVerificationFragment } from "../../../types/core"; -/** - * DID signed issuance status - */ -export declare const ValidDidSignedIssuanceStatus: Record<{ - did: String; - issued: Literal; -}, false>; -export declare type ValidDidSignedIssuanceStatus = Static; -export declare const ValidDidSignedIssuanceStatusArray: RunTypesArray; -}, false>, false>; -export declare type ValidDidSignedIssuanceStatusArray = Static; -export declare const InvalidDidSignedIssuanceStatus: Record<{ - did: String; - issued: Literal; - reason: Record<{ - code: Number; - /** - * Data for v3 Fragments - */ - codeString: String; - message: String; - }, false>; -}, false>; -export declare type InvalidDidSignedIssuanceStatus = Static; -export declare const DidSignedIssuanceStatus: Union<[Record<{ - did: String; - issued: Literal; -}, false>, Record<{ - did: String; - issued: Literal; - reason: Record<{ - code: Number; - /** - * Data for v3 Fragments - */ - codeString: String; - message: String; - }, false>; -}, false>]>; -export declare type DidSignedIssuanceStatus = Static; -export declare const DidSignedIssuanceStatusArray: RunTypesArray; -}, false>, Record<{ - did: String; - issued: Literal; - reason: Record<{ - code: Number; - /** - * Data for v3 Fragments - */ - codeString: String; - message: String; - }, false>; -}, false>]>, false>; -export declare type DidSignedIssuanceStatusArray = Static; -/** - * OCSP response - */ -export declare const ValidOcspReasonCode: import("runtypes").Constraint; -export declare const ValidOcspResponse: Record<{ - certificateStatus: Union<[Literal<"good">, Literal<"revoked">, Literal<"unknown">]>; -}, false>; -export declare const ValidOcspResponseRevoked: Record<{ - reasonCode: import("runtypes").Constraint; - certificateStatus: Union<[Literal<"good">, Literal<"revoked">, Literal<"unknown">]>; -}, false>; -/** - * Data for v2 Fragments - */ -export declare const ValidDidSignedDataV2: Record<{ - issuedOnAll: Literal; - revokedOnAny: Literal; - details: Record<{ - issuance: RunTypesArray; - }, false>, false>; - revocation: RunTypesArray; - address: import("runtypes").Optional; - }, false>, false>; - }, false>; -}, false>; -export declare type ValidDidSignedDataV2 = Static; -export declare const InvalidDidSignedDataV2: Record<{ - issuedOnAll: Boolean; - revokedOnAny: Boolean; - details: Record<{ - issuance: RunTypesArray; - }, false>, Record<{ - did: String; - issued: Literal; - reason: Record<{ - code: Number; - /** - * Data for v3 Fragments - */ - codeString: String; - message: String; - }, false>; - }, false>]>, false>; - revocation: RunTypesArray; - address: import("runtypes").Optional; - }, false>, Record<{ - revoked: Literal; - address: String; - reason: Record<{ - code: Number; - /** - * Data for v3 Fragments - */ - codeString: String; - message: String; - }, false>; - }, false>]>, false>; - }, false>; -}, false>; -export declare type InvalidDidSignedDataV2 = Static; -/** - * Data for v3 Fragments - */ -export declare const ValidDidSignedDataV3: Record<{ - issuedOnAll: Literal; - revokedOnAny: Literal; - details: Record<{ - issuance: Record<{ - did: String; - issued: Literal; - }, false>; - revocation: Record<{ - revoked: Literal; - address: import("runtypes").Optional; - }, false>; - }, false>; -}, false>; -export declare type ValidDidSignedDataV3 = Static; -export declare const InvalidDidSignedDataV3: Record<{ - issuedOnAll: Boolean; - revokedOnAny: Boolean; - details: Record<{ - issuance: Union<[Record<{ - did: String; - issued: Literal; - }, false>, Record<{ - did: String; - issued: Literal; - reason: Record<{ - code: Number; - /** - * Data for v3 Fragments - */ - codeString: String; - message: String; - }, false>; - }, false>]>; - revocation: Union<[Record<{ - revoked: Literal; - address: import("runtypes").Optional; - }, false>, Record<{ - revoked: Literal; - address: String; - reason: Record<{ - code: Number; - /** - * Data for v3 Fragments - */ - codeString: String; - message: String; - }, false>; - }, false>]>; - }, false>; -}, false>; -export declare type InvalidDidSignedDataV3 = Static; -/** - * Fragments - */ -export declare type OpenAttestationDidSignedDocumentStatusValidFragmentV2 = ValidVerificationFragment; -export declare type OpenAttestationDidSignedDocumentStatusInvalidFragmentV2 = InvalidVerificationFragment; -export declare type OpenAttestationDidSignedDocumentStatusValidFragmentV3 = ValidVerificationFragment; -export declare type OpenAttestationDidSignedDocumentStatusInvalidFragmentV3 = InvalidVerificationFragment; -export declare type OpenAttestationDidSignedDocumentStatusErrorFragment = ErrorVerificationFragment; -export declare type OpenAttestationDidSignedDocumentStatusVerificationFragment = OpenAttestationDidSignedDocumentStatusValidFragmentV2 | OpenAttestationDidSignedDocumentStatusInvalidFragmentV2 | OpenAttestationDidSignedDocumentStatusValidFragmentV3 | OpenAttestationDidSignedDocumentStatusInvalidFragmentV3 | OpenAttestationDidSignedDocumentStatusErrorFragment | SkippedVerificationFragment; diff --git a/dist/types/src/verifiers/documentStatus/didSigned/index.d.ts b/dist/types/src/verifiers/documentStatus/didSigned/index.d.ts deleted file mode 100644 index 1c14b400..00000000 --- a/dist/types/src/verifiers/documentStatus/didSigned/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./didSignedDocumentStatus"; diff --git a/dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.d.ts b/dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.d.ts deleted file mode 100644 index 0dea3168..00000000 --- a/dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { v2, WrappedDocument } from "@govtechsg/open-attestation"; -import { providers } from "ethers"; -import { Verifier } from "../../../types/core"; -import { DocumentStoreIssuanceStatus, OpenAttestationEthereumDocumentStoreStatusFragment } from "./ethereumDocumentStoreStatus.type"; -declare type VerifierType = Verifier; -export declare const getIssuersDocumentStores: (document: WrappedDocument) => string[]; -export declare const isIssuedOnDocumentStore: ({ documentStore, merkleRoot, provider, }: { - documentStore: string; - merkleRoot: string; - provider: providers.Provider; -}) => Promise; -export declare const openAttestationEthereumDocumentStoreStatus: VerifierType; -export {}; diff --git a/dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.test.d.ts b/dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.test.d.ts deleted file mode 100644 index cb0ff5c3..00000000 --- a/dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.test.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.d.ts b/dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.d.ts deleted file mode 100644 index b5150fe3..00000000 --- a/dist/types/src/verifiers/documentStatus/documentStore/ethereumDocumentStoreStatus.type.d.ts +++ /dev/null @@ -1,159 +0,0 @@ -import { Array as RunTypesArray, Boolean, Literal, Optional, Record, Static, String, Union } from "runtypes"; -import { ErrorVerificationFragment, InvalidVerificationFragment, SkippedVerificationFragment, ValidVerificationFragment } from "../../../types/core"; -/** - * Document store issuance status - */ -export declare const ValidDocumentStoreIssuanceStatus: Record<{ - issued: Literal; - address: String; -}, false>; -export declare type ValidDocumentStoreIssuanceStatus = Static; -export declare const ValidDocumentStoreIssuanceStatusArray: RunTypesArray; - address: String; -}, false>, false>; -export declare type ValidDocumentStoreIssuanceStatusArray = Static; -export declare const InvalidDocumentStoreIssuanceStatus: Record<{ - issued: Literal; - address: String; - reason: Record<{ - code: import("runtypes").Number; - codeString: String; - message: String; - }, false>; -}, false>; -export declare type InvalidDocumentStoreIssuanceStatus = Static; -export declare const DocumentStoreIssuanceStatus: Union<[Record<{ - issued: Literal; - address: String; -}, false>, Record<{ - issued: Literal; - address: String; - reason: Record<{ - code: import("runtypes").Number; - codeString: String; - message: String; - }, false>; -}, false>]>; -export declare type DocumentStoreIssuanceStatus = Static; -export declare const DocumentStoreIssuanceStatusArray: RunTypesArray; - address: String; -}, false>, Record<{ - issued: Literal; - address: String; - reason: Record<{ - code: import("runtypes").Number; - codeString: String; - message: String; - }, false>; -}, false>]>, false>; -export declare type DocumentStoreIssuanceStatusArray = Static; -/** - * Data for v2 Fragments - */ -declare const ValidDocumentStoreDataV2: Record<{ - issuedOnAll: Literal; - revokedOnAny: Literal; - details: Record<{ - issuance: RunTypesArray; - address: String; - }, false>, false>; - revocation: RunTypesArray; - address: Optional; - }, false>, false>; - }, false>; -}, false>; -export declare type ValidDocumentStoreDataV2 = Static; -export declare const InvalidDocumentStoreDataV2: Record<{ - issuedOnAll: Boolean; - revokedOnAny: Optional; - details: Record<{ - issuance: RunTypesArray; - address: String; - }, false>, Record<{ - issued: Literal; - address: String; - reason: Record<{ - code: import("runtypes").Number; - codeString: String; - message: String; - }, false>; - }, false>]>, false>; - revocation: Optional; - address: Optional; - }, false>, Record<{ - revoked: Literal; - address: String; - reason: Record<{ - code: import("runtypes").Number; - codeString: String; - message: String; - }, false>; - }, false>]>, false>>; - }, false>; -}, false>; -export declare type InvalidDocumentStoreDataV2 = Static; -/** - * Data for v3 Fragments - */ -export declare const ValidDocumentStoreDataV3: Record<{ - issuedOnAll: Literal; - revokedOnAny: Literal; - details: Record<{ - issuance: Record<{ - issued: Literal; - address: String; - }, false>; - revocation: Record<{ - revoked: Literal; - address: Optional; - }, false>; - }, false>; -}, false>; -export declare type ValidDocumentStoreDataV3 = Static; -export declare const InvalidDocumentStoreDataV3: Record<{ - issuedOnAll: Boolean; - revokedOnAny: Boolean; - details: Record<{ - issuance: Union<[Record<{ - issued: Literal; - address: String; - }, false>, Record<{ - issued: Literal; - address: String; - reason: Record<{ - code: import("runtypes").Number; - codeString: String; - message: String; - }, false>; - }, false>]>; - revocation: Union<[Record<{ - revoked: Literal; - address: Optional; - }, false>, Record<{ - revoked: Literal; - address: String; - reason: Record<{ - code: import("runtypes").Number; - codeString: String; - message: String; - }, false>; - }, false>]>; - }, false>; -}, false>; -export declare type InvalidDocumentStoreDataV3 = Static; -/** - * Fragments - */ -export declare type OpenAttestationEthereumDocumentStoreStatusFragmentValidFragmentV2 = ValidVerificationFragment; -export declare type OpenAttestationEthereumDocumentStoreStatusFragmentInvalidFragmentV2 = InvalidVerificationFragment; -export declare type OpenAttestationEthereumDocumentStoreStatusFragmentValidFragmentV3 = ValidVerificationFragment; -export declare type OpenAttestationEthereumDocumentStoreStatusFragmentInvalidFragmentV3 = InvalidVerificationFragment; -export declare type OpenAttestationEthereumDocumentStoreStatusErrorFragment = ErrorVerificationFragment; -export declare type OpenAttestationEthereumDocumentStoreStatusFragment = OpenAttestationEthereumDocumentStoreStatusFragmentValidFragmentV2 | OpenAttestationEthereumDocumentStoreStatusFragmentInvalidFragmentV2 | OpenAttestationEthereumDocumentStoreStatusFragmentValidFragmentV3 | OpenAttestationEthereumDocumentStoreStatusFragmentInvalidFragmentV3 | OpenAttestationEthereumDocumentStoreStatusErrorFragment | SkippedVerificationFragment; -export {}; diff --git a/dist/types/src/verifiers/documentStatus/documentStore/index.d.ts b/dist/types/src/verifiers/documentStatus/documentStore/index.d.ts deleted file mode 100644 index 51a171e5..00000000 --- a/dist/types/src/verifiers/documentStatus/documentStore/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./ethereumDocumentStoreStatus"; diff --git a/dist/types/src/verifiers/documentStatus/revocation.types.d.ts b/dist/types/src/verifiers/documentStatus/revocation.types.d.ts deleted file mode 100644 index 4c07c1c2..00000000 --- a/dist/types/src/verifiers/documentStatus/revocation.types.d.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { Literal, Record, Static, String, Union, Array as RunTypesArray, Optional } from "runtypes"; -export declare const ValidRevocationStatus: Record<{ - revoked: Literal; - address: Optional; -}, false>; -export declare type ValidRevocationStatus = Static; -export declare const ValidRevocationStatusArray: RunTypesArray; - address: Optional; -}, false>, false>; -export declare type ValidRevocationStatusArray = Static; -export declare const InvalidRevocationStatus: Record<{ - revoked: Literal; - address: String; - reason: Record<{ - code: import("runtypes").Number; - codeString: String; - message: String; - }, false>; -}, false>; -export declare type InvalidRevocationStatus = Static; -export declare const RevocationStatus: Union<[Record<{ - revoked: Literal; - address: Optional; -}, false>, Record<{ - revoked: Literal; - address: String; - reason: Record<{ - code: import("runtypes").Number; - codeString: String; - message: String; - }, false>; -}, false>]>; -export declare type RevocationStatus = Static; -export declare const RevocationStatusArray: RunTypesArray; - address: Optional; -}, false>, Record<{ - revoked: Literal; - address: String; - reason: Record<{ - code: import("runtypes").Number; - codeString: String; - message: String; - }, false>; -}, false>]>, false>; -export declare type RevocationStatusArray = Static; -export declare const OcspResponderRevocationStatus: Union<[Literal<"good">, Literal<"revoked">, Literal<"unknown">]>; -export declare type OcspResponderRevocationStatus = Static; -export declare enum OcspResponderRevocationReason { - UNSPECIFIED = 0, - KEY_COMPROMISE = 1, - CA_COMPROMISE = 2, - AFFILIATION_CHANGED = 3, - SUPERSEDED = 4, - CESSATION_OF_OPERATION = 5, - CERTIFICATE_HOLD = 6, - REMOVE_FROM_CRL = 8, - PRIVILEGE_WITHDRAWN = 9, - A_A_COMPROMISE = 10 -} diff --git a/dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.d.ts b/dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.d.ts deleted file mode 100644 index ab9471ed..00000000 --- a/dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { v2, v3, WrappedDocument } from "@govtechsg/open-attestation"; -import { providers } from "ethers"; -import { Verifier } from "../../../types/core"; -import { InvalidTokenRegistryStatus, OpenAttestationEthereumTokenRegistryStatusFragment, ValidTokenRegistryStatus } from "./ethereumTokenRegistryStatus.type"; -export declare const getTokenRegistry: (document: WrappedDocument | WrappedDocument) => string; -export declare const isTokenMintedOnRegistry: ({ tokenRegistry, merkleRoot, provider, }: { - tokenRegistry: string; - merkleRoot: string; - provider: providers.Provider; -}) => Promise; -export declare const openAttestationEthereumTokenRegistryStatus: Verifier; diff --git a/dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.test.d.ts b/dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.test.d.ts deleted file mode 100644 index cb0ff5c3..00000000 --- a/dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.test.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.d.ts b/dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.d.ts deleted file mode 100644 index 03eb8927..00000000 --- a/dist/types/src/verifiers/documentStatus/tokenRegistry/ethereumTokenRegistryStatus.type.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { Array as RunTypesArray, Literal, Record, Static, String, Union } from "runtypes"; -import { ErrorVerificationFragment, InvalidVerificationFragment, SkippedVerificationFragment, ValidVerificationFragment } from "../../../types/core"; -/** - * Token registry mint status - */ -export declare const ValidTokenRegistryStatus: Record<{ - minted: Literal; - address: String; -}, false>; -export declare type ValidTokenRegistryStatus = Static; -export declare const InvalidTokenRegistryStatus: Record<{ - minted: Literal; - address: String; - reason: Record<{ - code: import("runtypes").Number; - codeString: String; - message: String; - }, false>; -}, false>; -export declare type InvalidTokenRegistryStatus = Static; -/** - * Data for v2 Fragments - */ -export declare const ValidTokenRegistryDataV2: Record<{ - mintedOnAll: Literal; - details: RunTypesArray; - address: String; - }, false>, false>; -}, false>; -export declare type ValidTokenRegistryDataV2 = Static; -export declare const InvalidTokenRegistryDataV2: Record<{ - mintedOnAll: Literal; - details: RunTypesArray; - address: String; - }, false>, Record<{ - minted: Literal; - address: String; - reason: Record<{ - code: import("runtypes").Number; - codeString: String; - message: String; - }, false>; - }, false>]>, false>; -}, false>; -export declare type InvalidTokenRegistryDataV2 = Static; -/** - * Data for v3 Fragments - */ -export declare const ValidTokenRegistryDataV3: Record<{ - mintedOnAll: Literal; - details: Record<{ - minted: Literal; - address: String; - }, false>; -}, false>; -export declare type ValidTokenRegistryDataV3 = Static; -export declare const InvalidTokenRegistryDataV3: Record<{ - mintedOnAll: Literal; - details: Record<{ - minted: Literal; - address: String; - reason: Record<{ - code: import("runtypes").Number; - codeString: String; - message: String; - }, false>; - }, false>; -}, false>; -export declare type InvalidTokenRegistryDataV3 = Static; -/** - * Fragments - */ -export declare type OpenAttestationEthereumTokenRegistryStatusValidFragmentV2 = ValidVerificationFragment; -export declare type OpenAttestationEthereumTokenRegistryStatusValidFragmentV3 = ValidVerificationFragment; -export declare type OpenAttestationEthereumTokenRegistryStatusInvalidFragmentV2 = InvalidVerificationFragment; -export declare type OpenAttestationEthereumTokenRegistryStatusInvalidFragmentV3 = InvalidVerificationFragment; -export declare type OpenAttestationEthereumTokenRegistryStatusErrorFragment = ErrorVerificationFragment; -export declare type OpenAttestationEthereumTokenRegistryStatusFragment = OpenAttestationEthereumTokenRegistryStatusValidFragmentV2 | OpenAttestationEthereumTokenRegistryStatusValidFragmentV3 | OpenAttestationEthereumTokenRegistryStatusInvalidFragmentV2 | OpenAttestationEthereumTokenRegistryStatusInvalidFragmentV3 | OpenAttestationEthereumTokenRegistryStatusErrorFragment | SkippedVerificationFragment; diff --git a/dist/types/src/verifiers/documentStatus/tokenRegistry/index.d.ts b/dist/types/src/verifiers/documentStatus/tokenRegistry/index.d.ts deleted file mode 100644 index 45f2ecca..00000000 --- a/dist/types/src/verifiers/documentStatus/tokenRegistry/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./ethereumTokenRegistryStatus"; diff --git a/dist/types/src/verifiers/documentStatus/utils.d.ts b/dist/types/src/verifiers/documentStatus/utils.d.ts deleted file mode 100644 index e5a9fa7c..00000000 --- a/dist/types/src/verifiers/documentStatus/utils.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { DocumentStore } from "@govtechsg/document-store"; -import { providers } from "ethers"; -import { Hash } from "../../types/core"; -import { RevocationStatus } from "./revocation.types"; -export declare const getIntermediateHashes: (targetHash: Hash, proofs?: Hash[]) => string[]; -/** - * Try to decode the error to see if we can deterministically tell if the document has NOT been issued or revoked. - * - * In case where we cannot tell, we throw an error - * */ -export declare const decodeError: (error: any) => "Invalid document store address" | "Contract is not found" | "Invalid call arguments" | "ENS name is not configured" | "Bad document store address checksum" | "ENS name is not found"; -/** - * Given a list of hashes, check against one smart contract if any of the hash has been revoked - * */ -export declare const isAnyHashRevoked: (smartContract: DocumentStore, intermediateHashes: Hash[]) => Promise; -export declare const isRevokedByOcspResponder: ({ certificateId, location, }: { - certificateId: string; - location: string; -}) => Promise; -export declare const isRevokedOnDocumentStore: ({ documentStore, merkleRoot, provider, targetHash, proofs, }: { - documentStore: string; - merkleRoot: string; - provider: providers.Provider; - targetHash: Hash; - proofs?: string[] | undefined; -}) => Promise; diff --git a/dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.d.ts b/dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.d.ts deleted file mode 100644 index a2c6c2df..00000000 --- a/dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { Verifier } from "../../../types/core"; -import { OpenAttestationDidIdentityProofVerificationFragment } from "./didIdentityProof.type"; -declare type VerifierType = Verifier; -export declare const openAttestationDidIdentityProof: VerifierType; -export {}; diff --git a/dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.test.d.ts b/dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.test.d.ts deleted file mode 100644 index cb0ff5c3..00000000 --- a/dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.test.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.type.d.ts b/dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.type.d.ts deleted file mode 100644 index 3dd82476..00000000 --- a/dist/types/src/verifiers/issuerIdentity/did/didIdentityProof.type.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { ErrorVerificationFragment, InvalidVerificationFragment, SkippedVerificationFragment, ValidVerificationFragment } from "../../../types/core"; -import { DidVerificationStatusArray, InvalidDidVerificationStatus, ValidDidVerificationStatus, ValidDidVerificationStatusArray } from "../../../did/verifier"; -/** - * Fragments - */ -export declare type OpenAttestationDidIdentityProofValidFragmentV3 = ValidVerificationFragment; -export declare type OpenAttestationDidIdentityProofInvalidFragmentV3 = InvalidVerificationFragment; -export declare type OpenAttestationDidIdentityProofValidFragmentV2 = ValidVerificationFragment; -export declare type OpenAttestationDidIdentityProofInvalidFragmentV2 = InvalidVerificationFragment; -export declare type OpenAttestationDidIdentityProofErrorFragment = ErrorVerificationFragment; -export declare type OpenAttestationDidIdentityProofVerificationFragment = OpenAttestationDidIdentityProofValidFragmentV2 | OpenAttestationDidIdentityProofInvalidFragmentV2 | OpenAttestationDidIdentityProofValidFragmentV3 | OpenAttestationDidIdentityProofInvalidFragmentV3 | OpenAttestationDidIdentityProofErrorFragment | SkippedVerificationFragment; diff --git a/dist/types/src/verifiers/issuerIdentity/did/index.d.ts b/dist/types/src/verifiers/issuerIdentity/did/index.d.ts deleted file mode 100644 index cd1e1bb4..00000000 --- a/dist/types/src/verifiers/issuerIdentity/did/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./didIdentityProof"; diff --git a/dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.d.ts b/dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.d.ts deleted file mode 100644 index d29be50f..00000000 --- a/dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { Verifier } from "../../../types/core"; -import { OpenAttestationDnsDidIdentityProofVerificationFragment } from "./dnsDidProof.type"; -declare type VerifierType = Verifier; -export declare const openAttestationDnsDidIdentityProof: VerifierType; -export {}; diff --git a/dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.test.d.ts b/dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.test.d.ts deleted file mode 100644 index cb0ff5c3..00000000 --- a/dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.test.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.d.ts b/dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.d.ts deleted file mode 100644 index e24b3c80..00000000 --- a/dist/types/src/verifiers/issuerIdentity/dnsDid/dnsDidProof.type.d.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { Array as RunTypesArray, Literal, Record, Static, String, Union } from "runtypes"; -import { ErrorVerificationFragment, InvalidVerificationFragment, SkippedVerificationFragment, ValidVerificationFragment } from "../../../types/core"; -/** - * DNS-DID verification status - */ -export declare const ValidDnsDidVerificationStatus: Record<{ - status: Literal<"VALID">; - location: String; - key: String; -}, false>; -export declare type ValidDnsDidVerificationStatus = Static; -export declare const ValidDnsDidVerificationStatusArray: import("runtypes").Constraint; - location: String; - key: String; -}, false>, false>, { - status: "VALID"; - location: string; - key: string; -}[], unknown>; -export declare type ValidDnsDidVerificationStatusArray = Static; -export declare const InvalidDnsDidVerificationStatus: Record<{ - status: Literal<"INVALID">; - location: String; - key: String; -}, false>; -export declare type InvalidDnsDidVerificationStatus = Static; -export declare const DnsDidVerificationStatus: Union<[Record<{ - status: Literal<"VALID">; - location: String; - key: String; -}, false>, Record<{ - status: Literal<"INVALID">; - location: String; - key: String; -}, false>]>; -export declare type DnsDidVerificationStatus = Static; -export declare const DnsDidVerificationStatusArray: RunTypesArray; - location: String; - key: String; -}, false>, Record<{ - status: Literal<"INVALID">; - location: String; - key: String; -}, false>]>, false>; -export declare type DnsDidVerificationStatusArray = Static; -/** - * Fragments - */ -export declare type OpenAttestationDnsDidIdentityProofValidFragmentV3 = ValidVerificationFragment; -export declare type OpenAttestationDnsDidIdentityProofInvalidFragmentV3 = InvalidVerificationFragment; -export declare type OpenAttestationDnsDidIdentityProofValidFragmentV2 = ValidVerificationFragment; -export declare type OpenAttestationDnsDidIdentityProofInvalidFragmentV2 = InvalidVerificationFragment; -export declare type OpenAttestationDnsDidIdentityProofErrorFragment = ErrorVerificationFragment; -export declare type OpenAttestationDnsDidIdentityProofVerificationFragment = OpenAttestationDnsDidIdentityProofValidFragmentV2 | OpenAttestationDnsDidIdentityProofInvalidFragmentV2 | OpenAttestationDnsDidIdentityProofValidFragmentV3 | OpenAttestationDnsDidIdentityProofInvalidFragmentV3 | OpenAttestationDnsDidIdentityProofErrorFragment | SkippedVerificationFragment; diff --git a/dist/types/src/verifiers/issuerIdentity/dnsDid/index.d.ts b/dist/types/src/verifiers/issuerIdentity/dnsDid/index.d.ts deleted file mode 100644 index 5433c63d..00000000 --- a/dist/types/src/verifiers/issuerIdentity/dnsDid/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./dnsDidProof"; diff --git a/dist/types/src/verifiers/issuerIdentity/dnsTxt/index.d.ts b/dist/types/src/verifiers/issuerIdentity/dnsTxt/index.d.ts deleted file mode 100644 index 3d32f907..00000000 --- a/dist/types/src/verifiers/issuerIdentity/dnsTxt/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./openAttestationDnsTxt"; diff --git a/dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.d.ts b/dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.d.ts deleted file mode 100644 index f37826f2..00000000 --- a/dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Verifier } from "../../../types/core"; -import { OpenAttestationDnsTxtIdentityProofVerificationFragment } from "./openAttestationDnsTxt.type"; -export declare const openAttestationDnsTxtIdentityProof: Verifier; diff --git a/dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.test.d.ts b/dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.test.d.ts deleted file mode 100644 index cb0ff5c3..00000000 --- a/dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.test.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.d.ts b/dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.d.ts deleted file mode 100644 index cc460dec..00000000 --- a/dist/types/src/verifiers/issuerIdentity/dnsTxt/openAttestationDnsTxt.type.d.ts +++ /dev/null @@ -1,97 +0,0 @@ -import { Array as RunTypesArray, Literal, Optional, Record, Static, String, Union } from "runtypes"; -import { ErrorVerificationFragment, InvalidVerificationFragment, SkippedVerificationFragment, ValidVerificationFragment } from "../../../types/core"; -/** - * DNS-TXT verification status - */ -export declare const ValidDnsTxtVerificationStatus: Record<{ - status: Literal<"VALID">; - location: String; - value: String; -}, false>; -export declare type ValidDnsTxtVerificationStatus = Static; -export declare const ValidDnsTxtVerificationStatusArray: import("runtypes").Constraint; - location: String; - value: String; -}, false>, false>, { - status: "VALID"; - location: string; - value: string; -}[], unknown>; -export declare type ValidDnsTxtVerificationStatusArray = Static; -export declare const InvalidDnsTxtVerificationStatus: Record<{ - status: Literal<"INVALID">; - location: Optional; - value: Optional; - reason: Record<{ - code: import("runtypes").Number; - codeString: String; - message: String; - }, false>; -}, false>; -export declare type InvalidDnsTxtVerificationStatus = Static; -export declare const DnsTxtVerificationStatus: Union<[Record<{ - status: Literal<"VALID">; - location: String; - value: String; -}, false>, Record<{ - status: Literal<"INVALID">; - location: Optional; - value: Optional; - reason: Record<{ - code: import("runtypes").Number; - codeString: String; - message: String; - }, false>; -}, false>]>; -export declare type DnsTxtVerificationStatus = Static; -export declare const DnsTxtVerificationStatusArray: RunTypesArray; - location: String; - value: String; -}, false>, Record<{ - status: Literal<"INVALID">; - location: Optional; - value: Optional; - reason: Record<{ - code: import("runtypes").Number; - codeString: String; - message: String; - }, false>; -}, false>]>, false>; -export declare type DnsTxtVerificationStatusArray = Static; -/** - * Data for v3 Fragments - */ -export declare const ValidDnsTxtVerificationStatusDataV3: Record<{ - identifier: String; - value: String; -}, false>; -export declare type ValidDnsTxtVerificationStatusDataV3 = Static; -export declare const InvalidDnsTxtVerificationStatusDataV3: import("runtypes").Constraint, { - identifier?: string | undefined; - value?: string | undefined; -}, unknown>; -export declare type InvalidDnsTxtVerificationStatusDataV3 = Static; -export declare const DnsTxtVerificationStatusDataV3: Union<[Record<{ - identifier: String; - value: String; -}, false>, import("runtypes").Constraint, { - identifier?: string | undefined; - value?: string | undefined; -}, unknown>]>; -export declare type DnsTxtVerificationStatusDataV3 = Static; -/** - * Fragments - */ -export declare type OpenAttestationDnsTxtIdentityProofValidFragmentV2 = ValidVerificationFragment; -export declare type OpenAttestationDnsTxtIdentityProofInvalidFragmentV2 = InvalidVerificationFragment; -export declare type OpenAttestationDnsTxtIdentityProofValidFragmentV3 = ValidVerificationFragment; -export declare type OpenAttestationDnsTxtIdentityProofInvalidFragmentV3 = InvalidVerificationFragment; -export declare type OpenAttestationDnsTxtIdentityProofVerificationFragment = OpenAttestationDnsTxtIdentityProofValidFragmentV2 | OpenAttestationDnsTxtIdentityProofInvalidFragmentV2 | OpenAttestationDnsTxtIdentityProofValidFragmentV3 | OpenAttestationDnsTxtIdentityProofInvalidFragmentV3 | ErrorVerificationFragment | SkippedVerificationFragment; diff --git a/dist/types/src/verifiers/verificationBuilder.d.ts b/dist/types/src/verifiers/verificationBuilder.d.ts deleted file mode 100644 index 64517102..00000000 --- a/dist/types/src/verifiers/verificationBuilder.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { VerificationBuilderOptions, VerificationFragment, PromiseCallback, Verifier, DocumentsToVerify } from "../types/core"; -export declare const verificationBuilder: >(verifiers: T[], builderOptions: VerificationBuilderOptions) => (document: DocumentsToVerify, promisesCallback?: PromiseCallback | undefined) => Promise; diff --git a/dist/types/src/verify.v2.integration.errors.test.d.ts b/dist/types/src/verify.v2.integration.errors.test.d.ts deleted file mode 100644 index 3275561c..00000000 --- a/dist/types/src/verify.v2.integration.errors.test.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * @jest-environment node - */ -export {}; diff --git a/dist/types/src/verify.v2.integration.test.d.ts b/dist/types/src/verify.v2.integration.test.d.ts deleted file mode 100644 index 3275561c..00000000 --- a/dist/types/src/verify.v2.integration.test.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * @jest-environment node - */ -export {}; diff --git a/dist/types/src/verify.v3.integration.test.d.ts b/dist/types/src/verify.v3.integration.test.d.ts deleted file mode 100644 index cb0ff5c3..00000000 --- a/dist/types/src/verify.v3.integration.test.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/types/test/fixtures/v2/document.d.ts b/dist/types/test/fixtures/v2/document.d.ts deleted file mode 100644 index c8e98b89..00000000 --- a/dist/types/test/fixtures/v2/document.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { v2, WrappedDocument } from "@govtechsg/open-attestation"; -interface CustomDocument extends v2.OpenAttestationDocument { - name: string; - issuedOn: string; - transcript: any; - issuers: { - url: string; - name: string; - certificateStore: string; - }[]; - recipient: { - name: string; - email: string; - phone: string; - }; -} -export declare const document: WrappedDocument; -export {}; diff --git a/dist/types/test/fixtures/v2/documentDidCustomRevocation.d.ts b/dist/types/test/fixtures/v2/documentDidCustomRevocation.d.ts deleted file mode 100644 index 046b27b3..00000000 --- a/dist/types/test/fixtures/v2/documentDidCustomRevocation.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const documentDidCustomRevocation: any; diff --git a/dist/types/test/fixtures/v2/documentDidMissingProof.d.ts b/dist/types/test/fixtures/v2/documentDidMissingProof.d.ts deleted file mode 100644 index 1cf8d01b..00000000 --- a/dist/types/test/fixtures/v2/documentDidMissingProof.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const documentDidMissingProof: any; diff --git a/dist/types/test/fixtures/v2/documentDidMixedTokenRegistry.d.ts b/dist/types/test/fixtures/v2/documentDidMixedTokenRegistry.d.ts deleted file mode 100644 index 4488ccc0..00000000 --- a/dist/types/test/fixtures/v2/documentDidMixedTokenRegistry.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const documentDidMixedTokenRegistry: any; diff --git a/dist/types/test/fixtures/v2/documentDidObfuscatedRevocation.d.ts b/dist/types/test/fixtures/v2/documentDidObfuscatedRevocation.d.ts deleted file mode 100644 index ade92e65..00000000 --- a/dist/types/test/fixtures/v2/documentDidObfuscatedRevocation.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const documentDidObfuscatedRevocation: any; diff --git a/dist/types/test/fixtures/v2/documentDidSigned.d.ts b/dist/types/test/fixtures/v2/documentDidSigned.d.ts deleted file mode 100644 index d940c024..00000000 --- a/dist/types/test/fixtures/v2/documentDidSigned.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const documentDidSigned: any; diff --git a/dist/types/test/fixtures/v2/documentDidWrongSignature.d.ts b/dist/types/test/fixtures/v2/documentDidWrongSignature.d.ts deleted file mode 100644 index 9a8dbe42..00000000 --- a/dist/types/test/fixtures/v2/documentDidWrongSignature.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const documentDidWrongSignature: any; diff --git a/dist/types/test/fixtures/v2/documentDnsDidMixedTokenRegistry.d.ts b/dist/types/test/fixtures/v2/documentDnsDidMixedTokenRegistry.d.ts deleted file mode 100644 index fac7eceb..00000000 --- a/dist/types/test/fixtures/v2/documentDnsDidMixedTokenRegistry.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export declare const documentDnsDidMixedTokenRegistryInvalid: any; -export declare const documentDnsDidMixedTokenRegistryValid: any; diff --git a/dist/types/test/fixtures/v2/documentDnsDidNoDnsTxt.d.ts b/dist/types/test/fixtures/v2/documentDnsDidNoDnsTxt.d.ts deleted file mode 100644 index 42d6a726..00000000 --- a/dist/types/test/fixtures/v2/documentDnsDidNoDnsTxt.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const documentDnsDidNoDnsTxt: any; diff --git a/dist/types/test/fixtures/v2/documentDnsDidSigned.d.ts b/dist/types/test/fixtures/v2/documentDnsDidSigned.d.ts deleted file mode 100644 index ba868fd5..00000000 --- a/dist/types/test/fixtures/v2/documentDnsDidSigned.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const documentDnsDidSigned: any; diff --git a/dist/types/test/fixtures/v2/documentMainnetInvalidWithIncorrectMerkleRoot.d.ts b/dist/types/test/fixtures/v2/documentMainnetInvalidWithIncorrectMerkleRoot.d.ts deleted file mode 100644 index 9e11a422..00000000 --- a/dist/types/test/fixtures/v2/documentMainnetInvalidWithIncorrectMerkleRoot.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { v2, WrappedDocument } from "@govtechsg/open-attestation"; -interface CustomDocument extends v2.OpenAttestationDocument { - recipient: { - name: string; - address: { - street: string; - country: string; - }; - }; - certification: any; - consignment: any; - declaration: any; -} -export declare const documentMainnetInvalidWithIncorrectMerkleRoot: WrappedDocument; -export {}; diff --git a/dist/types/test/fixtures/v2/documentMainnetInvalidWithOddLengthMerkleRoot.d.ts b/dist/types/test/fixtures/v2/documentMainnetInvalidWithOddLengthMerkleRoot.d.ts deleted file mode 100644 index afa175f4..00000000 --- a/dist/types/test/fixtures/v2/documentMainnetInvalidWithOddLengthMerkleRoot.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { v2, WrappedDocument } from "@govtechsg/open-attestation"; -interface CustomDocument extends v2.OpenAttestationDocument { - recipient: { - name: string; - address: { - street: string; - country: string; - }; - }; - certification: any; - consignment: any; - declaration: any; -} -export declare const documentMainnetInvalidWithOddLengthMerkleRoot: WrappedDocument; -export {}; diff --git a/dist/types/test/fixtures/v2/documentMainnetValidWithCertificateStore.d.ts b/dist/types/test/fixtures/v2/documentMainnetValidWithCertificateStore.d.ts deleted file mode 100644 index 4fc2b4cd..00000000 --- a/dist/types/test/fixtures/v2/documentMainnetValidWithCertificateStore.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { v2, WrappedDocument } from "@govtechsg/open-attestation"; -interface CustomDocument extends v2.OpenAttestationDocument { - name: string; - issuedOn: string; - $template: string; - recipient: { - name: string; - }; -} -export declare const documentMainnetValidWithCertificateStore: WrappedDocument; -export {}; diff --git a/dist/types/test/fixtures/v2/documentRinkebyWithDocumentStore.d.ts b/dist/types/test/fixtures/v2/documentRinkebyWithDocumentStore.d.ts deleted file mode 100644 index 37275b44..00000000 --- a/dist/types/test/fixtures/v2/documentRinkebyWithDocumentStore.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { v2, WrappedDocument } from "@govtechsg/open-attestation"; -interface CustomDocument extends v2.OpenAttestationDocument { - name: string; -} -export declare const documentRinkebyValidWithDocumentStore: WrappedDocument; -export declare const documentRinkebyRevokedWithDocumentStore: WrappedDocument; -export {}; diff --git a/dist/types/test/fixtures/v2/documentRopstenMixedIssuance.d.ts b/dist/types/test/fixtures/v2/documentRopstenMixedIssuance.d.ts deleted file mode 100644 index 3da1e594..00000000 --- a/dist/types/test/fixtures/v2/documentRopstenMixedIssuance.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const documentRopstenMixedIssuance: any; diff --git a/dist/types/test/fixtures/v2/documentRopstenNotIssuedWithCertificateStore.d.ts b/dist/types/test/fixtures/v2/documentRopstenNotIssuedWithCertificateStore.d.ts deleted file mode 100644 index 0ec5b8eb..00000000 --- a/dist/types/test/fixtures/v2/documentRopstenNotIssuedWithCertificateStore.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { v2, WrappedDocument } from "@govtechsg/open-attestation"; -interface CustomDocument extends v2.OpenAttestationDocument { - name: string; - issuedOn: string; - description: string; - admissionDate: string; - graduationDate: string; - transcript: any; - cumulativeScore: string; - additionalData: any; - issuers: { - url: string; - name: string; - certificateStore: string; - uen: string; - email: string; - }[]; - recipient: { - name: string; - nric: string; - }; -} -export declare const documentRopstenNotIssuedWithCertificateStore: WrappedDocument; -export {}; diff --git a/dist/types/test/fixtures/v2/documentRopstenNotIssuedWithDocumentStore.d.ts b/dist/types/test/fixtures/v2/documentRopstenNotIssuedWithDocumentStore.d.ts deleted file mode 100644 index a75b495c..00000000 --- a/dist/types/test/fixtures/v2/documentRopstenNotIssuedWithDocumentStore.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { v2, WrappedDocument } from "@govtechsg/open-attestation"; -interface CustomDocument extends v2.OpenAttestationDocument { - recipient: { - name: string; - address: { - street: string; - country: string; - }; - }; - consignment: any; - declaration: any; -} -export declare const documentRopstenNotIssuedWithDocumentStore: WrappedDocument; -export {}; diff --git a/dist/types/test/fixtures/v2/documentRopstenNotIssuedWithTokenRegistry.d.ts b/dist/types/test/fixtures/v2/documentRopstenNotIssuedWithTokenRegistry.d.ts deleted file mode 100644 index ae39d95b..00000000 --- a/dist/types/test/fixtures/v2/documentRopstenNotIssuedWithTokenRegistry.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { v2, WrappedDocument } from "@govtechsg/open-attestation"; -interface CustomDocument extends v2.OpenAttestationDocument { - recipient: { - name: string; - address: { - street: string; - country: string; - }; - }; - consignment: any; - declaration: any; -} -export declare const documentRopstenNotIssuedWithTokenRegistry: WrappedDocument; -export {}; diff --git a/dist/types/test/fixtures/v2/documentRopstenObfuscated.d.ts b/dist/types/test/fixtures/v2/documentRopstenObfuscated.d.ts deleted file mode 100644 index ad8f1c99..00000000 --- a/dist/types/test/fixtures/v2/documentRopstenObfuscated.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { v2, WrappedDocument } from "@govtechsg/open-attestation"; -interface CustomDocument extends v2.OpenAttestationDocument { - name: string; - description: string; - issuedOn: string; - admissionDate: string; - graduationDate: string; - transcript: any; - additionalData: any; - issuers: [ - { - name: string; - url: string; - documentStore: string; - identityProof: any; - } - ]; -} -export declare const documentRopstenObfuscated: WrappedDocument; -export {}; diff --git a/dist/types/test/fixtures/v2/documentRopstenRevokedWithCertificateStore.d.ts b/dist/types/test/fixtures/v2/documentRopstenRevokedWithCertificateStore.d.ts deleted file mode 100644 index 046588c1..00000000 --- a/dist/types/test/fixtures/v2/documentRopstenRevokedWithCertificateStore.d.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { v2, WrappedDocument } from "@govtechsg/open-attestation"; -interface CustomDocument extends v2.OpenAttestationDocument { - recipient: { - name: string; - address: { - street: string; - country: string; - }; - }; - consignment: { - description: string; - quantity: { - value: string; - unit: string; - }; - countryOfOrigin: string; - outwardBillNo: string; - dateOfDischarge: string; - dateOfDeparture: string; - countryOfFinalDestination: string; - outgoingVehicleNo: "string"; - }; - declaration: { - name: string; - designation: string; - date: string; - }; -} -export declare const documentRopstenRevokedWithCertificateStore: WrappedDocument; -export {}; diff --git a/dist/types/test/fixtures/v2/documentRopstenRevokedWithDocumentStore.d.ts b/dist/types/test/fixtures/v2/documentRopstenRevokedWithDocumentStore.d.ts deleted file mode 100644 index 56291436..00000000 --- a/dist/types/test/fixtures/v2/documentRopstenRevokedWithDocumentStore.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { v2, WrappedDocument } from "@govtechsg/open-attestation"; -interface CustomDocument extends v2.OpenAttestationDocument { - recipient: { - name: string; - address: { - street: string; - country: string; - }; - }; - consignment: any; - declaration: any; -} -export declare const documentRopstenRevokedWithDocumentStore: WrappedDocument; -export {}; diff --git a/dist/types/test/fixtures/v2/documentRopstenRevokedWithToken.d.ts b/dist/types/test/fixtures/v2/documentRopstenRevokedWithToken.d.ts deleted file mode 100644 index ce242d6a..00000000 --- a/dist/types/test/fixtures/v2/documentRopstenRevokedWithToken.d.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { v2, WrappedDocument } from "@govtechsg/open-attestation"; -interface CustomDocument extends v2.OpenAttestationDocument { - recipient: { - name: string; - address: { - street: string; - country: string; - }; - }; - consignment: { - description: string; - quantity: { - value: string; - unit: string; - }; - countryOfOrigin: string; - outwardBillNo: string; - dateOfDischarge: string; - dateOfDeparture: string; - countryOfFinalDestination: string; - outgoingVehicleNo: "string"; - }; - declaration: { - name: string; - designation: string; - date: string; - }; -} -export declare const documentRopstenRevokedWithToken: WrappedDocument; -export {}; diff --git a/dist/types/test/fixtures/v2/documentRopstenValidWithCertificateStore.d.ts b/dist/types/test/fixtures/v2/documentRopstenValidWithCertificateStore.d.ts deleted file mode 100644 index baef0616..00000000 --- a/dist/types/test/fixtures/v2/documentRopstenValidWithCertificateStore.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { v2, WrappedDocument } from "@govtechsg/open-attestation"; -interface CustomDocument extends v2.OpenAttestationDocument { - name: string; - issuedOn: string; - description: string; - admissionDate: string; - graduationDate: string; - transcript: any; - cumulativeScore: string; - additionalData: any; - issuers: { - url: string; - name: string; - certificateStore: string; - uen: string; - email: string; - }[]; - recipient: { - name: string; - nric: string; - }; -} -export declare const documentRopstenValidWithCertificateStore: WrappedDocument; -export {}; diff --git a/dist/types/test/fixtures/v2/documentRopstenValidWithDocumentStore.d.ts b/dist/types/test/fixtures/v2/documentRopstenValidWithDocumentStore.d.ts deleted file mode 100644 index 7e6640da..00000000 --- a/dist/types/test/fixtures/v2/documentRopstenValidWithDocumentStore.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { v2, WrappedDocument } from "@govtechsg/open-attestation"; -interface CustomDocument extends v2.OpenAttestationDocument { - recipient: { - name: string; - address: { - street: string; - country: string; - }; - }; - consignment: any; - declaration: any; -} -export declare const documentRopstenValidWithDocumentStore: WrappedDocument; -export {}; diff --git a/dist/types/test/fixtures/v2/documentRopstenValidWithToken.d.ts b/dist/types/test/fixtures/v2/documentRopstenValidWithToken.d.ts deleted file mode 100644 index f2bef50a..00000000 --- a/dist/types/test/fixtures/v2/documentRopstenValidWithToken.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { v2, WrappedDocument } from "@govtechsg/open-attestation"; -interface CustomDocument extends v2.OpenAttestationDocument { - recipient: { - name: string; - address: { - street: string; - country: string; - }; - }; - consignment: any; - declaration: any; -} -export declare const documentRopstenValidWithToken: WrappedDocument; -export {}; diff --git a/dist/types/test/fixtures/v2/tamperedDocument.d.ts b/dist/types/test/fixtures/v2/tamperedDocument.d.ts deleted file mode 100644 index 1ce7ff73..00000000 --- a/dist/types/test/fixtures/v2/tamperedDocument.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { v2, WrappedDocument } from "@govtechsg/open-attestation"; -interface CustomDocument extends v2.OpenAttestationDocument { - name: string; - issuedOn: string; - transcript: any; - issuers: { - url: string; - name: string; - certificateStore: string; - }[]; - recipient: { - name: string; - email: string; - phone: string; - }; -} -export declare const tamperedDocumentWithCertificateStore: WrappedDocument; -export declare const tamperedDocumentWithInvalidCertificateStore: WrappedDocument; -export {}; diff --git a/dist/types/test/utils/index.d.ts b/dist/types/test/utils/index.d.ts deleted file mode 100644 index 412629c7..00000000 --- a/dist/types/test/utils/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { VerificationFragment } from "../../src/types/core"; -export declare const getFailingFragments: (fragments: VerificationFragment[]) => VerificationFragment[]; -export declare const getFragmentsByName: (fragments: VerificationFragment[], name: string) => VerificationFragment[]; From 920ccc1b049a3452cb36d8a220214a2b39d8ea30 Mon Sep 17 00:00:00 2001 From: Seth Date: Tue, 4 Jan 2022 15:23:15 +0800 Subject: [PATCH 4/4] chore: update dnsprove version --- package-lock.json | 5 +++-- package.json | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index b1491f09..9e2aed62 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1367,8 +1367,9 @@ } }, "@govtechsg/dnsprove": { - "version": "git+https://github.com/Open-Attestation/dnsprove.git#975559ee1b83d3d79e4ce88291a4c13c6a34d423", - "from": "git+https://github.com/Open-Attestation/dnsprove.git#feat/add-networks", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@govtechsg/dnsprove/-/dnsprove-2.3.0.tgz", + "integrity": "sha512-d8nmtlk8xbM7tR/7sKJcz1cL5yRLDxLysbzO5JTohj2grRij4jKyHwcEyfVTX5up6zXv2ELFcsu0zyvRuVVXFA==", "requires": { "axios": "^0.21.1", "debug": "^4.3.1", diff --git a/package.json b/package.json index e8c54211..abcd0c1e 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "author": "", "license": "Apache-2.0", "dependencies": { - "@govtechsg/dnsprove": "git+https://github.com/Open-Attestation/dnsprove.git#feat/add-networks", + "@govtechsg/dnsprove": "^2.3.0", "@govtechsg/document-store": "^2.2.3", "@govtechsg/open-attestation": "^6.2.0", "@govtechsg/token-registry": "^2.5.3",