From 2a023b15a3a6cba1da05f8439dacb26e898104f1 Mon Sep 17 00:00:00 2001 From: Mircea Nistor Date: Mon, 15 Mar 2021 18:50:26 +0100 Subject: [PATCH] feat: upgrade to latest did core spec (#99) (#109) (#111) * feat: refactor configuration options, add `chainID` * fix: improve `kid` stability during attribute changes * chore: cleanup in tests and local dependencies * test(coverage): improve test coverage * refactor(style): enable linting using `eslint` * refactor: isolate some of the type definitions * fix: test that checksum address resolves to identical DID document (#105) * fix: setAttribute with sigAuth adds key to authentication section (#95) * feat: enable base58 encoding for keys (#106)(#99) * refactor: group types, defaults, and helper methods * fix: add support for deactivated DIDs (#83)(#85) * fix(deps): bump did-resolver version * fix: update the default `@context` to be LD compatible (#99) * docs: update readme and spec to reflect reality and current DID spec compliance (#99) * fix: rename `publicKey` to `verificationMethod` (#99) * fix: rename `ethereumAddress` to `blockchainAccountId` (#99) * feat: no more errors thrown during resolution. fixes #83 closes #85 fixes #95 fixes #105 closes #106 fixes #99 BREAKING CHANGE: The return type is `DIDResolutionResult` which wraps a `DIDDocument`. BREAKING CHANGE: No errors are thrown during DID resolution. Please check `result.didResolutionMetadata.error` instead. BREAKING CHANGE: This DID core spec requirement will break for users expecting `publicKey`, `ethereumAddress`, `Secp256k1VerificationKey2018` entries in the DID document. They are replaced with `verificationMethod`, `blockchainAccountId` and `EcdsaSecp256k1VerificationKey2019` and `EcdsaSecp256k1RecoveryMethod2020` depending on the content. --- commitlint.config.js | 3 - package-lock.json | 441 --------------------- package.json | 35 +- src/__tests__/errors.test.ts | 36 ++ src/__tests__/networks.integration.test.ts | 9 - src/__tests__/resolver.test.ts | 9 - src/configuration.ts | 7 +- src/helpers.ts | 27 +- src/index.ts | 2 + src/resolver.ts | 24 +- 10 files changed, 104 insertions(+), 489 deletions(-) delete mode 100644 commitlint.config.js create mode 100644 src/__tests__/errors.test.ts diff --git a/commitlint.config.js b/commitlint.config.js deleted file mode 100644 index a4f43697..00000000 --- a/commitlint.config.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - extends: ['@commitlint/config-conventional'] -} diff --git a/package-lock.json b/package-lock.json index 8329d784..991fdf02 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1913,359 +1913,6 @@ "minimist": "^1.2.0" } }, - "@commitlint/cli": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/@commitlint/cli/-/cli-12.0.1.tgz", - "integrity": "sha512-V+cMYNHJOr40XT9Kvz3Vrz1Eh7QE1rjQrUbifawDAqcOrBJFuoXwU2SAcRtYFCSqFy9EhbreQGhZFs8dYb90KA==", - "dev": true, - "requires": { - "@commitlint/format": "^12.0.1", - "@commitlint/lint": "^12.0.1", - "@commitlint/load": "^12.0.1", - "@commitlint/read": "^12.0.1", - "@commitlint/types": "^12.0.1", - "get-stdin": "8.0.0", - "lodash": "^4.17.19", - "resolve-from": "5.0.0", - "resolve-global": "1.0.0", - "yargs": "^16.2.0" - }, - "dependencies": { - "ansi-regex": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", - "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", - "dev": true - }, - "ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, - "requires": { - "color-convert": "^2.0.1" - } - }, - "cliui": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", - "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", - "dev": true, - "requires": { - "string-width": "^4.2.0", - "strip-ansi": "^6.0.0", - "wrap-ansi": "^7.0.0" - } - }, - "color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, - "requires": { - "color-name": "~1.1.4" - } - }, - "emoji-regex": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", - "dev": true - }, - "is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true - }, - "string-width": { - "version": "4.2.2", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.2.tgz", - "integrity": "sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==", - "dev": true, - "requires": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.0" - } - }, - "strip-ansi": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", - "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", - "dev": true, - "requires": { - "ansi-regex": "^5.0.0" - } - }, - "wrap-ansi": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", - "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", - "dev": true, - "requires": { - "ansi-styles": "^4.0.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0" - } - }, - "y18n": { - "version": "5.0.5", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.5.tgz", - "integrity": "sha512-hsRUr4FFrvhhRH12wOdfs38Gy7k2FFzB9qgN9v3aLykRq0dRcdcpz5C9FxdS2NuhOrI/628b/KSTJ3rwHysYSg==", - "dev": true - }, - "yargs": { - "version": "16.2.0", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", - "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", - "dev": true, - "requires": { - "cliui": "^7.0.2", - "escalade": "^3.1.1", - "get-caller-file": "^2.0.5", - "require-directory": "^2.1.1", - "string-width": "^4.2.0", - "y18n": "^5.0.5", - "yargs-parser": "^20.2.2" - }, - "dependencies": { - "get-caller-file": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", - "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", - "dev": true - }, - "require-directory": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", - "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", - "dev": true - } - } - } - } - }, - "@commitlint/config-conventional": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/@commitlint/config-conventional/-/config-conventional-12.0.1.tgz", - "integrity": "sha512-1ZhB135lh47zVmf1orwcjxuKuam11fJIH/bdVxW9XiQv8XPwC6iIp19knfl8FcOT78AVBnes1z6EVxgUeP2/4Q==", - "dev": true, - "requires": { - "conventional-changelog-conventionalcommits": "^4.3.1" - } - }, - "@commitlint/ensure": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/@commitlint/ensure/-/ensure-12.0.1.tgz", - "integrity": "sha512-XdBq+q1YBBDxWIAEjE3Y1YMbzhUnUuSLAEWD8SU1xsvEpQXWRYwDlMBRkjO7funNWTdL0ZQSkZDzme70imYjbw==", - "dev": true, - "requires": { - "@commitlint/types": "^12.0.1", - "lodash": "^4.17.19" - } - }, - "@commitlint/execute-rule": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/@commitlint/execute-rule/-/execute-rule-12.0.1.tgz", - "integrity": "sha512-JzyweYfZlFLtXpgP+btzSY3YAkGPg61TqUSYQqBr4+5IaVf1FruMm5v4D5eLu9dAJuNKUfHbM3AEfuEPiZ79pg==", - "dev": true - }, - "@commitlint/format": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/@commitlint/format/-/format-12.0.1.tgz", - "integrity": "sha512-rF79ipAxR8yFzPzG5tRoEZ//MRkyxCXj4JhpEjtdaCMBAXMssI8uazn3e5D8z4UFgSDe9qOnL0OmQvql7HTMoA==", - "dev": true, - "requires": { - "@commitlint/types": "^12.0.1", - "chalk": "^4.0.0" - } - }, - "@commitlint/is-ignored": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/@commitlint/is-ignored/-/is-ignored-12.0.1.tgz", - "integrity": "sha512-AplfLn5mX/kWTIiSolcOhTYcgphuGLX8FUr+HmyHBEqUkO36jt0z9caysH47fqU71ePtH63v1DWm+RYQ5RPDjg==", - "dev": true, - "requires": { - "@commitlint/types": "^12.0.1", - "semver": "7.3.4" - }, - "dependencies": { - "lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "requires": { - "yallist": "^4.0.0" - } - }, - "semver": { - "version": "7.3.4", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.4.tgz", - "integrity": "sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw==", - "dev": true, - "requires": { - "lru-cache": "^6.0.0" - } - }, - "yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true - } - } - }, - "@commitlint/lint": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/@commitlint/lint/-/lint-12.0.1.tgz", - "integrity": "sha512-1lKyRCq4ahJrY+Xxo8LsqCbALeJkodtEfpmYHeA5HpPMnK7lRSplLqOLcTCjoPfd4vO+gl6aDEZN+ow3YGQBOg==", - "dev": true, - "requires": { - "@commitlint/is-ignored": "^12.0.1", - "@commitlint/parse": "^12.0.1", - "@commitlint/rules": "^12.0.1", - "@commitlint/types": "^12.0.1" - } - }, - "@commitlint/load": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/@commitlint/load/-/load-12.0.1.tgz", - "integrity": "sha512-dX8KdCWn7w0bTkkk3zKQpe9X8vsTRa5EM+1ffF313wCX9b6tGa9vujhEHCkSzKAbbE2tFV64CHZygE7rtlHdIA==", - "dev": true, - "requires": { - "@commitlint/execute-rule": "^12.0.1", - "@commitlint/resolve-extends": "^12.0.1", - "@commitlint/types": "^12.0.1", - "chalk": "^4.0.0", - "cosmiconfig": "^7.0.0", - "lodash": "^4.17.19", - "resolve-from": "^5.0.0" - } - }, - "@commitlint/message": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/@commitlint/message/-/message-12.0.1.tgz", - "integrity": "sha512-fXuoxRC+NT1wEQi6p8oHfT7wvWIRgTk+udlRJnWTjmMpiYzVnMmmZfasdShirWr4TtxQtMyL+5DVgh7Y98kURw==", - "dev": true - }, - "@commitlint/parse": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/@commitlint/parse/-/parse-12.0.1.tgz", - "integrity": "sha512-7oEGASmzBnHir5jSIR7KephXrKh7rIi9a6RpH1tOT+CIENYvhe8EDtIy29qMt+RLa2LlaPF7YrAgaJRfzG0YDQ==", - "dev": true, - "requires": { - "@commitlint/types": "^12.0.1", - "conventional-changelog-angular": "^5.0.11", - "conventional-commits-parser": "^3.0.0" - } - }, - "@commitlint/read": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/@commitlint/read/-/read-12.0.1.tgz", - "integrity": "sha512-baa0YeD4QOctEuthLpExQSi9xPiw0kDPfUVHqp8I88iuIXJECeS8S1+1GBiz89e8dLN9zmEE+sN9vtJHdAp9YA==", - "dev": true, - "requires": { - "@commitlint/top-level": "^12.0.1", - "@commitlint/types": "^12.0.1", - "fs-extra": "^9.0.0", - "git-raw-commits": "^2.0.0" - } - }, - "@commitlint/resolve-extends": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/@commitlint/resolve-extends/-/resolve-extends-12.0.1.tgz", - "integrity": "sha512-Mvg0GDi/68Cqw893ha8uhxE8myHfPmiSSSi7d1x4VJNR4hoS37lBdX89kyx4i9NPmLfviY2cUJKTyK8ZrFznZw==", - "dev": true, - "requires": { - "import-fresh": "^3.0.0", - "lodash": "^4.17.19", - "resolve-from": "^5.0.0", - "resolve-global": "^1.0.0" - } - }, - "@commitlint/rules": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/@commitlint/rules/-/rules-12.0.1.tgz", - "integrity": "sha512-A5O0ubNGugZR9WWxk5IVOLo07lpdUwhG5WkAW2lYpgZ7Z/2U4PLob9b4Ih1eHbQu+gnVeFr91k7F0DrpM7B8EQ==", - "dev": true, - "requires": { - "@commitlint/ensure": "^12.0.1", - "@commitlint/message": "^12.0.1", - "@commitlint/to-lines": "^12.0.1", - "@commitlint/types": "^12.0.1" - } - }, - "@commitlint/to-lines": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/@commitlint/to-lines/-/to-lines-12.0.1.tgz", - "integrity": "sha512-XwcJ1jY7x2fhudzbGMpNQkTSMVrxWrI8bRMbVe3Abuu7RfYpFf7VXAlhtnLfxBoagaK7RxjC2+eRidp/3txQBg==", - "dev": true - }, - "@commitlint/top-level": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/@commitlint/top-level/-/top-level-12.0.1.tgz", - "integrity": "sha512-rHdgt7U24GEau2/9i2vEAbksxkBRiVjHj5ECFL5dd0AJOIvaK++vMg4EF/ME0X/1yd9qVTHTNOl2Q4tTFK7VBQ==", - "dev": true, - "requires": { - "find-up": "^5.0.0" - }, - "dependencies": { - "find-up": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", - "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", - "dev": true, - "requires": { - "locate-path": "^6.0.0", - "path-exists": "^4.0.0" - } - }, - "locate-path": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", - "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", - "dev": true, - "requires": { - "p-locate": "^5.0.0" - } - }, - "p-limit": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", - "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", - "dev": true, - "requires": { - "yocto-queue": "^0.1.0" - } - }, - "p-locate": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", - "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", - "dev": true, - "requires": { - "p-limit": "^3.0.2" - } - }, - "path-exists": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", - "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", - "dev": true - } - } - }, - "@commitlint/types": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/@commitlint/types/-/types-12.0.1.tgz", - "integrity": "sha512-FsNDMV0W7D19/ZbR412klpqAilXASx75Neqh7jPtK278IEwdukOg3vth1r5kTm+BjDScM7wMUEOwIW3NNfAtwg==", - "dev": true, - "requires": { - "chalk": "^4.0.0" - } - }, "@eslint/eslintrc": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.4.0.tgz", @@ -4660,17 +4307,6 @@ "q": "^1.5.1" } }, - "conventional-changelog-conventionalcommits": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/conventional-changelog-conventionalcommits/-/conventional-changelog-conventionalcommits-4.5.0.tgz", - "integrity": "sha512-buge9xDvjjOxJlyxUnar/+6i/aVEVGA7EEh4OafBCXPlLUQPGbRUBhBUveWRxzvR8TEjhKEP4BdepnpG2FSZXw==", - "dev": true, - "requires": { - "compare-func": "^2.0.0", - "lodash": "^4.17.15", - "q": "^1.5.1" - } - }, "conventional-changelog-writer": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/conventional-changelog-writer/-/conventional-changelog-writer-4.1.0.tgz", @@ -5256,12 +4892,6 @@ } } }, - "dargs": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/dargs/-/dargs-7.0.0.tgz", - "integrity": "sha512-2iy1EkLdlBzQGvbweYRFxmFath8+K7+AKB0TlhHWkNuH+TmovaMH/Wp7V7R4u7f4SnX3OgLsU9t1NI9ioDnUpg==", - "dev": true - }, "dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -7362,12 +6992,6 @@ "integrity": "sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==", "dev": true }, - "get-stdin": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-8.0.0.tgz", - "integrity": "sha512-sY22aA6xchAzprjyqmSEQv4UbAAzRN0L2dQB0NlN5acTTK9Don6nhoc3eAbUnpZiCANAMfd/+40kVdKfFygohg==", - "dev": true - }, "get-stream": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", @@ -7442,41 +7066,6 @@ } } }, - "git-raw-commits": { - "version": "2.0.10", - "resolved": "https://registry.npmjs.org/git-raw-commits/-/git-raw-commits-2.0.10.tgz", - "integrity": "sha512-sHhX5lsbG9SOO6yXdlwgEMQ/ljIn7qMpAbJZCGfXX2fq5T8M5SrDnpYk9/4HswTildcIqatsWa91vty6VhWSaQ==", - "dev": true, - "requires": { - "dargs": "^7.0.0", - "lodash": "^4.17.15", - "meow": "^8.0.0", - "split2": "^3.0.0", - "through2": "^4.0.0" - }, - "dependencies": { - "readable-stream": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", - "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", - "dev": true, - "requires": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - } - }, - "through2": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/through2/-/through2-4.0.2.tgz", - "integrity": "sha512-iOqSav00cVxEEICeD7TjLB1sueEL+81Wpzp2bY17uZjZN0pWZPuo4suZ/61VujxmqSGFfgOcNuTZ85QJwNZQpw==", - "dev": true, - "requires": { - "readable-stream": "3" - } - } - } - }, "glob": { "version": "7.1.6", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", @@ -7500,15 +7089,6 @@ "is-glob": "^4.0.1" } }, - "global-dirs": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/global-dirs/-/global-dirs-0.1.1.tgz", - "integrity": "sha1-sxnA3UYH81PzvpzKTHL8FIxJ9EU=", - "dev": true, - "requires": { - "ini": "^1.3.4" - } - }, "globals": { "version": "11.12.0", "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", @@ -7801,12 +7381,6 @@ "integrity": "sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw==", "dev": true }, - "husky": { - "version": "5.1.3", - "resolved": "https://registry.npmjs.org/husky/-/husky-5.1.3.tgz", - "integrity": "sha512-fbNJ+Gz5wx2LIBtMweJNY1D7Uc8p1XERi5KNRMccwfQA+rXlxWNSdUxswo0gT8XqxywTIw7Ywm/F4v/O35RdMg==", - "dev": true - }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -15986,15 +15560,6 @@ "integrity": "sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==", "dev": true }, - "resolve-global": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/resolve-global/-/resolve-global-1.0.0.tgz", - "integrity": "sha512-zFa12V4OLtT5XUX/Q4VLvTfBf+Ok0SPc1FNGM/z9ctUdiU618qwKpWnd0CHs3+RqROfyEg/DhuHbMWYqcgljEw==", - "dev": true, - "requires": { - "global-dirs": "^0.1.1" - } - }, "resolve-url": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/resolve-url/-/resolve-url-0.2.1.tgz", @@ -18285,12 +17850,6 @@ "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.6.tgz", "integrity": "sha512-AP1+fQIWSM/sMiET8fyayjx/J+JmTPt2Mr0FkrgqB4todtfa53sOsrSAcIrJRD5XS20bKUwaDIuMkWKCEiQLKA==", "dev": true - }, - "yocto-queue": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", - "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", - "dev": true } } } diff --git a/package.json b/package.json index 27ec2386..d9702078 100644 --- a/package.json +++ b/package.json @@ -53,29 +53,26 @@ "test-with-coverage": "jest --coverage && codecov" }, "devDependencies": { - "@babel/core": "^7.13.10", - "@babel/preset-env": "^7.13.10", - "@babel/preset-typescript": "^7.13.0", - "@commitlint/cli": "^12.0.1", - "@commitlint/config-conventional": "^12.0.1", + "@babel/core": "7.13.10", + "@babel/preset-env": "7.13.10", + "@babel/preset-typescript": "7.13.0", "@semantic-release/changelog": "5.0.1", "@semantic-release/git": "9.0.0", - "@types/jest": "^26.0.20", - "@typescript-eslint/eslint-plugin": "^4.17.0", - "@typescript-eslint/parser": "^4.17.0", - "babel-jest": "^26.6.3", + "@types/jest": "26.0.20", + "@typescript-eslint/eslint-plugin": "4.17.0", + "@typescript-eslint/parser": "4.17.0", + "babel-jest": "26.6.3", "codecov": "3.8.1", - "eslint": "^7.21.0", - "eslint-config-prettier": "^8.1.0", - "ganache-cli": "^6.12.2", - "husky": "^5.1.3", + "eslint": "7.21.0", + "eslint-config-prettier": "8.1.0", + "ganache-cli": "6.12.2", "jest": "26.6.3", - "microbundle": "^0.13.0", - "prettier": "^2.2.1", - "pretty-quick": "^3.1.0", - "semantic-release": "^17.4.1", - "typescript": "^4.2.3", - "uint8arrays": "^2.1.3" + "microbundle": "0.13.0", + "prettier": "2.2.1", + "pretty-quick": "3.1.0", + "semantic-release": "17.4.1", + "typescript": "4.2.3", + "uint8arrays": "2.1.3" }, "dependencies": { "@ethersproject/abi": "^5.0.13", diff --git a/src/__tests__/errors.test.ts b/src/__tests__/errors.test.ts new file mode 100644 index 00000000..66ef129d --- /dev/null +++ b/src/__tests__/errors.test.ts @@ -0,0 +1,36 @@ +import { Resolver } from 'did-resolver' +import { getResolver } from '../resolver' + +describe('error handling', () => { + const didResolver = new Resolver( + getResolver({ + networks: [{ name: 'example', rpcUrl: 'example.com' }], + }) + ) + + it('rejects invalid DID', async () => { + expect.assertions(1) + await expect(didResolver.resolve('did:ethr:2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqX')).resolves.toEqual({ + didDocument: null, + didDocumentMetadata: {}, + didResolutionMetadata: { + error: 'invalidDid', + message: 'Not a valid did:ethr: 2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqX', + }, + }) + }) + + it('rejects resolution on unconfigured network', async () => { + expect.assertions(1) + await expect( + didResolver.resolve('did:ethr:zrx:0x03fdd57adec3d438ea237fe46b33ee1e016eda6b585c3e27ea66686c2ea5358479') + ).resolves.toEqual({ + didDocument: null, + didDocumentMetadata: {}, + didResolutionMetadata: { + error: 'unknownNetwork', + message: 'The DID resolver does not have a configuration for network: zrx', + }, + }) + }) +}) diff --git a/src/__tests__/networks.integration.test.ts b/src/__tests__/networks.integration.test.ts index e433ba28..043852b0 100644 --- a/src/__tests__/networks.integration.test.ts +++ b/src/__tests__/networks.integration.test.ts @@ -176,14 +176,5 @@ describe('ethrResolver (alt-chains)', () => { }, }) }) - - it('throws on resolving unconfigured network', async () => { - expect.assertions(1) - const ethr = getResolver({ networks: [{ name: 'rsk', rpcUrl: 'https://did.rsk.co:4444' }] }) - const resolver = new Resolver(ethr) - await expect( - resolver.resolve('did:ethr:zrx:0x03fdd57adec3d438ea237fe46b33ee1e016eda6b585c3e27ea66686c2ea5358479') - ).rejects.toThrowError('unknown_network: The DID resolver does not have a configuration for network: zrx') - }) }) }) diff --git a/src/__tests__/resolver.test.ts b/src/__tests__/resolver.test.ts index d0bde0b0..d0ac00f1 100644 --- a/src/__tests__/resolver.test.ts +++ b/src/__tests__/resolver.test.ts @@ -979,13 +979,4 @@ describe('ethrResolver', () => { }) }) }) - - describe('error handling', () => { - it('rejects promise', async () => { - expect.assertions(1) - await expect(didResolver.resolve('did:ethr:2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqX')).rejects.toEqual( - new Error('Not a valid ethr DID: did:ethr:2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqX') - ) - }) - }) }) diff --git a/src/configuration.ts b/src/configuration.ts index af20815d..ba8484ad 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -2,7 +2,7 @@ import { BigNumber } from '@ethersproject/bignumber' import { Contract, ContractFactory } from '@ethersproject/contracts' import { InfuraProvider, JsonRpcProvider, Provider } from '@ethersproject/providers' import DidRegistryContract from 'ethr-did-registry' -import { DEFAULT_REGISTRY_ADDRESS, knownNetworks } from './helpers' +import { DEFAULT_REGISTRY_ADDRESS, knownInfuraNetworks, knownNetworks } from './helpers' /** * A configuration entry for an ethereum network @@ -57,8 +57,9 @@ function getContractForNetwork(conf: ProviderConfiguration): Contract { let provider: Provider = conf.provider || conf.web3?.currentProvider if (!provider) { if (conf.rpcUrl) { - const chainId = conf.chainId ? BigNumber.from(conf.chainId).toNumber() : conf.chainId - const networkName = knownNetworks[conf.name || ''] ? conf.name?.replace('mainnet', 'homestead') : 'any' + const chainIdRaw = conf.chainId ? conf.chainId : knownNetworks[conf.name || ''] + const chainId = chainIdRaw ? BigNumber.from(chainIdRaw).toNumber() : chainIdRaw + const networkName = knownInfuraNetworks[conf.name || ''] ? conf.name?.replace('mainnet', 'homestead') : 'any' provider = new JsonRpcProvider(conf.rpcUrl, chainId || networkName) } else { throw new Error(`invalid_config: No web3 provider could be determined for network ${conf.name || conf.chainId}`) diff --git a/src/helpers.ts b/src/helpers.ts index a31a174e..42b8f9a0 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -98,7 +98,7 @@ export function interpretIdentifier(identifier: string): { address: string; publ } } -const knownInfuraNetworks: Record = { +export const knownInfuraNetworks: Record = { mainnet: '0x1', ropsten: '0x3', rinkeby: '0x4', @@ -108,4 +108,29 @@ const knownInfuraNetworks: Record = { export const knownNetworks: Record = { ...knownInfuraNetworks, + rsk: '0x1e', + 'rsk:testnet': '0x1f', + artis_t1: '0x03c401', + artis_s1: '0x03c301', + matic: '0x89', + maticmum: '0x13881', +} + +export enum Errors { + /** + * The resolver has failed to construct the DID document. + * This can be caused by a network issue, a wrong registry address or malformed logs while parsing the registry history. + * Please inspect the `DIDResolutionMetadata.message` to debug further. + */ + notFound = 'notFound', + + /** + * The resolver does not know how to resolve the given DID. Most likely it is not a `did:ethr`. + */ + invalidDid = 'invalidDid', + + /** + * The resolver is misconfigured or is being asked to resolve a DID anchored on an unknown network + */ + unknownNetwork = 'unknownNetwork', } diff --git a/src/index.ts b/src/index.ts index e0b3bc82..10fa9d52 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,7 @@ import { legacyAttrTypes, stringToBytes32, verificationMethodTypes, + Errors, } from './helpers' export { @@ -20,4 +21,5 @@ export { legacyAttrTypes as attrTypes, verificationMethodTypes, identifierMatcher, + Errors, } diff --git a/src/resolver.ts b/src/resolver.ts index bc4044fe..debcce1a 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -27,6 +27,7 @@ import { nullAddress, DIDOwnerChanged, knownNetworks, + Errors, } from './helpers' import { logDecoder } from './logParser' @@ -280,13 +281,28 @@ export class EthrDidResolver { ): Promise { const fullId = parsed.id.match(identifierMatcher) if (!fullId) { - throw new Error(`Not a valid ethr DID: ${did}`) + return { + didResolutionMetadata: { + error: Errors.invalidDid, + message: `Not a valid did:ethr: ${parsed.id}`, + }, + didDocumentMetadata: {}, + didDocument: null, + } } const id = fullId[2] const networkId = !fullId[1] ? 'mainnet' : fullId[1].slice(0, -1) - if (!this.contracts[networkId]) - throw new Error(`unknown_network: The DID resolver does not have a configuration for network: ${networkId}`) + if (!this.contracts[networkId]) { + return { + didResolutionMetadata: { + error: Errors.unknownNetwork, + message: `The DID resolver does not have a configuration for network: ${networkId}`, + }, + didDocumentMetadata: {}, + didDocument: null, + } + } const { controller, history, controllerKey, chainId } = await this.changeLog(id, networkId, options.blockTag) try { @@ -300,7 +316,7 @@ export class EthrDidResolver { } catch (e) { return { didResolutionMetadata: { - error: 'notFound', + error: Errors.notFound, message: e.toString(), // This is not in spec, nut may be helpful }, didDocumentMetadata: {},