From e3e87aa341b8dd8981187486dc9090bd65dfb042 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Mon, 18 Sep 2023 12:57:30 +0500 Subject: [PATCH 01/41] Update package-lock.json. --- package-lock.json | 113 ++++++++++++++++++++++++++-------------------- 1 file changed, 63 insertions(+), 50 deletions(-) diff --git a/package-lock.json b/package-lock.json index 69eb4cb2..10e0de69 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@cheqd/credential-service", - "version": "2.9.2", + "version": "2.9.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@cheqd/credential-service", - "version": "2.9.2", + "version": "2.9.3", "license": "Apache-2.0", "dependencies": { "@cheqd/did-provider-cheqd": "^3.6.8", @@ -87,6 +87,9 @@ "ts-node": "^10.9.1", "typescript": "^5.2.2", "uint8arrays": "^4.0.6" + }, + "engines": { + "node": ">=18.0.0" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -5143,7 +5146,7 @@ "version": "1.1.3", "resolved": "https://registry.npmjs.org/@gar/promisify/-/promisify-1.1.3.tgz", "integrity": "sha512-k2Ty1JcVojjJFwrg/ThKi2ujJ7XNLYaFGNB/bWT9wGR+oSMJHMa5w+CUq6p/pVrKeNNgA7pCqEcjSnHVoqJQFw==", - "devOptional": true + "optional": true }, "node_modules/@graphql-typed-document-node/core": { "version": "3.2.0", @@ -6881,7 +6884,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/@npmcli/fs/-/fs-1.1.1.tgz", "integrity": "sha512-8KG5RD0GVP4ydEzRn/I4BNDuxDtqVbOdm8675T49OIG/NGhaK0pjPX7ZcDlvKYbA+ulvVK3ztfcF4uBdOxuJbQ==", - "devOptional": true, + "optional": true, "dependencies": { "@gar/promisify": "^1.0.1", "semver": "^7.3.5" @@ -6892,7 +6895,7 @@ "resolved": "https://registry.npmjs.org/@npmcli/move-file/-/move-file-1.1.2.tgz", "integrity": "sha512-1SUf/Cg2GzGDyaf15aR9St9TWlb+XvbZXWpDx8YKs7MLzMH/BCeopv+y9vzrzgkfykCGuWOlSu3mZhj2+FQcrg==", "deprecated": "This functionality has been moved to @npmcli/fs", - "devOptional": true, + "optional": true, "dependencies": { "mkdirp": "^1.0.4", "rimraf": "^3.0.2" @@ -8802,7 +8805,7 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-1.1.2.tgz", "integrity": "sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==", - "devOptional": true, + "optional": true, "engines": { "node": ">= 6" } @@ -11953,7 +11956,7 @@ "version": "4.5.0", "resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.5.0.tgz", "integrity": "sha512-5GG/5IbQQpC9FpkRGsSvZI5QYeSCzlJHdpBQntCsuTOxhKD8lqKhrleg2Yi7yvMIf82Ycmmqln9U8V9qwEiJew==", - "devOptional": true, + "optional": true, "dependencies": { "humanize-ms": "^1.2.1" }, @@ -13085,7 +13088,8 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/builtins/-/builtins-1.0.3.tgz", "integrity": "sha512-uYBjakWipfaO/bXI7E8rq6kpwHRZK5cNYrUv2OzZSI/FvmdMyXJ2tG9dKcjEC5YHmHpUAwsargWIZNWdxb/bnQ==", - "devOptional": true + "optional": true, + "peer": true }, "node_modules/busboy": { "version": "1.6.0", @@ -13110,7 +13114,7 @@ "version": "15.3.0", "resolved": "https://registry.npmjs.org/cacache/-/cacache-15.3.0.tgz", "integrity": "sha512-VVdYzXEn+cnbXpFgWs5hTT7OScegHVmLhJIR8Ufqk3iFD6A6j5iSX1KuBTfNEv4tdJWE2PzA6IVFtcLC7fN9wQ==", - "devOptional": true, + "optional": true, "dependencies": { "@npmcli/fs": "^1.0.0", "@npmcli/move-file": "^1.0.1", @@ -15191,7 +15195,7 @@ "version": "2.2.1", "resolved": "https://registry.npmjs.org/env-paths/-/env-paths-2.2.1.tgz", "integrity": "sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A==", - "devOptional": true, + "optional": true, "engines": { "node": ">=6" } @@ -17244,7 +17248,7 @@ "version": "4.1.1", "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz", "integrity": "sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==", - "devOptional": true + "optional": true }, "node_modules/http-errors": { "version": "2.0.0", @@ -17305,7 +17309,7 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz", "integrity": "sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==", - "devOptional": true, + "optional": true, "dependencies": { "ms": "^2.0.0" } @@ -17439,7 +17443,7 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/infer-owner/-/infer-owner-1.0.4.tgz", "integrity": "sha512-IClj+Xz94+d7irH5qRyfJonOdfTzuDaifE6ZPWfx0N0+/ATZCbuTPq2prFl526urkQd90WyUKIh1DfBQ2hMz9A==", - "devOptional": true + "optional": true }, "node_modules/inflight": { "version": "1.0.6", @@ -18049,7 +18053,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/is-lambda/-/is-lambda-1.0.1.tgz", "integrity": "sha512-z7CMFGNrENq5iFB9Bqo64Xk6Y9sg+epq1myIcdHaGnbMTYOxvzsEtdYqQUylB7LxfkvgrrjP32T6Ywciio9UIQ==", - "devOptional": true + "optional": true }, "node_modules/is-number": { "version": "7.0.0", @@ -20837,7 +20841,7 @@ "version": "9.1.0", "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-9.1.0.tgz", "integrity": "sha512-+zopwDy7DNknmwPQplem5lAZX/eCOzSvSNNcSKm5eVwTkOBzoktEfXsa9L23J/GIRhxRsaxzkPEhrJEpE2F4Gg==", - "devOptional": true, + "optional": true, "dependencies": { "agentkeepalive": "^4.1.3", "cacache": "^15.2.0", @@ -20864,7 +20868,7 @@ "version": "6.0.2", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", - "devOptional": true, + "optional": true, "dependencies": { "debug": "4" }, @@ -20876,7 +20880,7 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz", "integrity": "sha512-k0zdNgqWTGA6aeIRVpvfVob4fL52dTfaehylg0Y4UvSySvOq/Y+BOyPrgpUrA7HylqvU8vIZGsRuXmspskV0Tg==", - "devOptional": true, + "optional": true, "dependencies": { "@tootallnate/once": "1", "agent-base": "6", @@ -20890,7 +20894,7 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", - "devOptional": true, + "optional": true, "dependencies": { "agent-base": "6", "debug": "4" @@ -22374,7 +22378,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/minipass-collect/-/minipass-collect-1.0.2.tgz", "integrity": "sha512-6T6lH0H8OG9kITm/Jm6tdooIbogG9e0tLgpY6mphXSm/A9u8Nq1ryBG+Qspiub9LjWlBPsPS3tWQ/Botq4FdxA==", - "devOptional": true, + "optional": true, "dependencies": { "minipass": "^3.0.0" }, @@ -22386,7 +22390,7 @@ "version": "1.4.1", "resolved": "https://registry.npmjs.org/minipass-fetch/-/minipass-fetch-1.4.1.tgz", "integrity": "sha512-CGH1eblLq26Y15+Azk7ey4xh0J/XfJfrCox5LDJiKqI2Q2iwOLOKrlmIaODiSQS8d18jalF6y2K2ePUm0CmShw==", - "devOptional": true, + "optional": true, "dependencies": { "minipass": "^3.1.0", "minipass-sized": "^1.0.3", @@ -22403,7 +22407,7 @@ "version": "1.0.5", "resolved": "https://registry.npmjs.org/minipass-flush/-/minipass-flush-1.0.5.tgz", "integrity": "sha512-JmQSYYpPUqX5Jyn1mXaRwOda1uQ8HP5KAT/oDSLCzt1BYRhQU0/hDtsB1ufZfEEzMZ9aAVmsBw8+FWsIXlClWw==", - "devOptional": true, + "optional": true, "dependencies": { "minipass": "^3.0.0" }, @@ -22415,7 +22419,7 @@ "version": "1.2.4", "resolved": "https://registry.npmjs.org/minipass-pipeline/-/minipass-pipeline-1.2.4.tgz", "integrity": "sha512-xuIq7cIOt09RPRJ19gdi4b+RiNvDFYe5JH+ggNvBqGqpQXcru3PcRmOZuHBKWK1Txf9+cQ+HMVN4d6z46LZP7A==", - "devOptional": true, + "optional": true, "dependencies": { "minipass": "^3.0.0" }, @@ -22427,7 +22431,7 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/minipass-sized/-/minipass-sized-1.0.3.tgz", "integrity": "sha512-MbkQQ2CTiBMlA2Dm/5cY+9SWFEN8pzzOXi6rlM5Xxq0Yqbda5ZQy9sU75a673FE9ZK0Zsbr6Y5iP6u9nktfg2g==", - "devOptional": true, + "optional": true, "dependencies": { "minipass": "^3.0.0" }, @@ -22826,7 +22830,7 @@ "version": "8.4.1", "resolved": "https://registry.npmjs.org/node-gyp/-/node-gyp-8.4.1.tgz", "integrity": "sha512-olTJRgUtAb/hOXG0E93wZDs5YiJlgbXxTwQAFHyNlRsXQnYzUaF2aGgujZbw+hR8aF4ZG/rST57bWMWD16jr9w==", - "devOptional": true, + "optional": true, "dependencies": { "env-paths": "^2.2.0", "glob": "^7.1.4", @@ -22860,7 +22864,7 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-3.0.1.tgz", "integrity": "sha512-QZW4EDmGwlYur0Yyf/b2uGucHQMa8aFUP7eu9ddR73vvhFyt4V0Vl3QHPcTNJ8l6qYOBdxgXdnBXQrHilfRQBg==", - "devOptional": true, + "optional": true, "dependencies": { "delegates": "^1.0.0", "readable-stream": "^3.6.0" @@ -22873,7 +22877,7 @@ "version": "4.0.4", "resolved": "https://registry.npmjs.org/gauge/-/gauge-4.0.4.tgz", "integrity": "sha512-f9m+BEN5jkg6a0fZjleidjN51VE1X+mPFQ2DJ0uv1V39oCLCbsGe6yjbBnp7eK7z/+GAon99a3nHuqbuuthyPg==", - "devOptional": true, + "optional": true, "dependencies": { "aproba": "^1.0.3 || ^2.0.0", "color-support": "^1.1.3", @@ -22892,7 +22896,7 @@ "version": "6.0.2", "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-6.0.2.tgz", "integrity": "sha512-/vBvz5Jfr9dT/aFWd0FIRf+T/Q2WBsLENygUaFUqstqsycmZAP/t5BvFJTK0viFmSUxiUKTUplWy5vt+rvKIxg==", - "devOptional": true, + "optional": true, "dependencies": { "are-we-there-yet": "^3.0.0", "console-control-strings": "^1.1.0", @@ -22907,7 +22911,7 @@ "version": "3.6.2", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", - "devOptional": true, + "optional": true, "dependencies": { "inherits": "^2.0.3", "string_decoder": "^1.1.1", @@ -23179,7 +23183,8 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/npm-package-arg/-/npm-package-arg-7.0.0.tgz", "integrity": "sha512-xXxr8y5U0kl8dVkz2oK7yZjPBvqM2fwaO5l3Yg13p03v8+E3qQcD0JNhHzjL1vyGgxcKkD0cco+NLR72iuPk3g==", - "devOptional": true, + "optional": true, + "peer": true, "dependencies": { "hosted-git-info": "^3.0.2", "osenv": "^0.1.5", @@ -23191,7 +23196,8 @@ "version": "3.0.8", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-3.0.8.tgz", "integrity": "sha512-aXpmwoOhRBrw6X3j0h5RloK4x1OzsxMPyxqIHyNfSe2pypkVTZFpEiRoSipPEPlMrh0HW/XsjkJ5WgnCirpNUw==", - "devOptional": true, + "optional": true, + "peer": true, "dependencies": { "lru-cache": "^6.0.0" }, @@ -23203,7 +23209,8 @@ "version": "5.7.2", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", - "devOptional": true, + "optional": true, + "peer": true, "bin": { "semver": "bin/semver" } @@ -26447,7 +26454,8 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", "integrity": "sha512-B5JU3cabzk8c67mRRd3ECmROafjYMXbuzlwtqdM8IbS8ktlTix8aFGb2bAGKrSRIlnfKwovGUUr72JUPyOb6kQ==", - "devOptional": true, + "optional": true, + "peer": true, "engines": { "node": ">=0.10.0" } @@ -26456,7 +26464,8 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", "integrity": "sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==", - "devOptional": true, + "optional": true, + "peer": true, "engines": { "node": ">=0.10.0" } @@ -26465,7 +26474,8 @@ "version": "0.1.5", "resolved": "https://registry.npmjs.org/osenv/-/osenv-0.1.5.tgz", "integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==", - "devOptional": true, + "optional": true, + "peer": true, "dependencies": { "os-homedir": "^1.0.0", "os-tmpdir": "^1.0.0" @@ -26638,7 +26648,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/p-map/-/p-map-4.0.0.tgz", "integrity": "sha512-/bjOqmgETBYB5BoEeGVea8dmvHb2m9GLy1E9W43yeyfP6QQCZGFNa+XRceJEuDB6zqr+gKpIAmlLebMpykw/MQ==", - "devOptional": true, + "optional": true, "dependencies": { "aggregate-error": "^3.0.0" }, @@ -27715,13 +27725,13 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/promise-inflight/-/promise-inflight-1.0.1.tgz", "integrity": "sha512-6zWPyEOFaQBJYcGMHBKTKJ3u6TBsnMFOIZSa6ce1e/ZrrsOlnHRHbabMjLiBYKp+n44X9eUI6VUPaukCXHuG4g==", - "devOptional": true + "optional": true }, "node_modules/promise-retry": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/promise-retry/-/promise-retry-2.0.1.tgz", "integrity": "sha512-y+WKFlBR8BGXnsNlIHFGPZmyDf3DFMoLhaflAnyZgV6rG6xu+JwesTo2Q9R6XwYmtmwAFCkAk3e35jEdoeh/3g==", - "devOptional": true, + "optional": true, "dependencies": { "err-code": "^2.0.2", "retry": "^0.12.0" @@ -27734,7 +27744,7 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/err-code/-/err-code-2.0.3.tgz", "integrity": "sha512-2bmlRpNKBxT/CRmPOlyISQpNj+qSeYvcym/uT0Jx2bMOlKLtSy1ZmLuVxSEKKyor/N5yhvp/ZiG1oE3DEYMSFA==", - "devOptional": true + "optional": true }, "node_modules/prompts": { "version": "2.4.2", @@ -27901,7 +27911,8 @@ "version": "0.11.0", "resolved": "https://registry.npmjs.org/qrcode-terminal/-/qrcode-terminal-0.11.0.tgz", "integrity": "sha512-Uu7ii+FQy4Qf82G4xu7ShHhjhGahEpCWc3x8UavY3CTcWV+ufmmCtwkr7ZKsX42jdL0kr1B5FKUeqJvAn51jzQ==", - "devOptional": true, + "optional": true, + "peer": true, "bin": { "qrcode-terminal": "bin/qrcode-terminal.js" } @@ -29020,7 +29031,7 @@ "version": "0.12.0", "resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz", "integrity": "sha512-9LkiTwjUh6rT555DtE9rTX+BKByPfrMzEAtnlEtdEwr3Nkffwiihqe2bWADg+OQRjt9gl6ICdmB/ZFDCGAtSow==", - "devOptional": true, + "optional": true, "engines": { "node": ">= 4" } @@ -30054,7 +30065,7 @@ "version": "4.2.0", "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", "integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==", - "devOptional": true, + "optional": true, "engines": { "node": ">= 6.0.0", "npm": ">= 3.0.0" @@ -30064,7 +30075,7 @@ "version": "2.7.1", "resolved": "https://registry.npmjs.org/socks/-/socks-2.7.1.tgz", "integrity": "sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ==", - "devOptional": true, + "optional": true, "dependencies": { "ip": "^2.0.0", "smart-buffer": "^4.2.0" @@ -30078,7 +30089,7 @@ "version": "6.2.1", "resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-6.2.1.tgz", "integrity": "sha512-a6KW9G+6B3nWZ1yB8G7pJwL3ggLy1uTzKAgCb7ttblwqdz9fMGJUuTy3uFzEP48FAs9FLILlmzDlE2JJhVQaXQ==", - "devOptional": true, + "optional": true, "dependencies": { "agent-base": "^6.0.2", "debug": "^4.3.3", @@ -30092,7 +30103,7 @@ "version": "6.0.2", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", - "devOptional": true, + "optional": true, "dependencies": { "debug": "4" }, @@ -30104,7 +30115,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/ip/-/ip-2.0.0.tgz", "integrity": "sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==", - "devOptional": true + "optional": true }, "node_modules/sonic-boom": { "version": "2.8.0", @@ -30254,7 +30265,7 @@ "version": "8.0.1", "resolved": "https://registry.npmjs.org/ssri/-/ssri-8.0.1.tgz", "integrity": "sha512-97qShzy1AiyxvPNIkLWoGua7xoQzzPjQ0HAH4B0rWKo7SZ6USuPcrUiAFrws0UH8RrbWmgq3LMTObhPIHbbBeQ==", - "devOptional": true, + "optional": true, "dependencies": { "minipass": "^3.1.1" }, @@ -31702,7 +31713,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/unique-filename/-/unique-filename-1.1.1.tgz", "integrity": "sha512-Vmp0jIp2ln35UTXuryvjzkjGdRyf9b2lTXuSYUiPmzRcl3FDtYqAwOnTJkAngD9SWhnoJzDbTKwaOrZ+STtxNQ==", - "devOptional": true, + "optional": true, "dependencies": { "unique-slug": "^2.0.0" } @@ -31711,7 +31722,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/unique-slug/-/unique-slug-2.0.2.tgz", "integrity": "sha512-zoWr9ObaxALD3DOPfjPSqxt4fnZiWblxHIgeWqW8x7UqDzEtHEQLzji2cuJYQFCU6KmoJikOYAZlrTHHebjx2w==", - "devOptional": true, + "optional": true, "dependencies": { "imurmurhash": "^0.1.4" } @@ -31929,7 +31940,8 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/validate-npm-package-name/-/validate-npm-package-name-3.0.0.tgz", "integrity": "sha512-M6w37eVCMMouJ9V/sdPGnC5H4uDr73/+xdq0FBLO3TFFX1+7wiUY6Es328NN+y43tmY+doUdN9g9J21vqB7iLw==", - "devOptional": true, + "optional": true, + "peer": true, "dependencies": { "builtins": "^1.0.3" } @@ -32213,7 +32225,8 @@ "version": "2.4.3", "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-2.4.3.tgz", "integrity": "sha512-GaETH5wwsX+GcnzhPgKcKjJ6M2Cq3/iZp1WyY/X1CSqrW+jVNM9Y7D8EC2sM4ZG/V8wZlSniJnCKWPmBYAucRQ==", - "devOptional": true, + "optional": true, + "peer": true, "dependencies": { "graceful-fs": "^4.1.11", "imurmurhash": "^0.1.4", From 647363881756501988d94df2facabba1186e1a25 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Mon, 18 Sep 2023 13:10:59 +0500 Subject: [PATCH 02/41] Remove assertionMethod from form based request body in /did/create API. --- src/controllers/issuer.ts | 2 +- src/static/swagger.json | 35 ++++++++++++++++++++++++++++++++++- src/types/swagger-types.ts | 24 ++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/controllers/issuer.ts b/src/controllers/issuer.ts index 8d1ec915..2194b371 100644 --- a/src/controllers/issuer.ts +++ b/src/controllers/issuer.ts @@ -187,7 +187,7 @@ export class IssuerController { * content: * application/x-www-form-urlencoded: * schema: - * $ref: '#/components/schemas/DidCreateRequest' + * $ref: '#/components/schemas/DidCreateRequestFormBased' * application/json: * schema: * $ref: '#/components/schemas/DidCreateRequest' diff --git a/src/static/swagger.json b/src/static/swagger.json index 0af095b0..986fdff8 100644 --- a/src/static/swagger.json +++ b/src/static/swagger.json @@ -581,7 +581,7 @@ "content": { "application/x-www-form-urlencoded": { "schema": { - "$ref": "#/components/schemas/DidCreateRequest" + "$ref": "#/components/schemas/DidCreateRequestFormBased" } }, "application/json": { @@ -2476,6 +2476,39 @@ ] } }, + "DidCreateRequestFormBased": { + "type": "object", + "properties": { + "network": { + "description": "Network to create the DID on (testnet or mainnet)", + "type": "string", + "enum": [ + "testnet", + "mainnet" + ] + }, + "methodSpecificIdAlgo": { + "description": "Algorithm to use for generating the method-specific ID. The two styles supported are UUIDs and Indy-style Base58. See cheqd DID method documentation for more details.", + "type": "string", + "enum": [ + "uuid", + "base58btc" + ] + }, + "verificationMethodType": { + "description": "Type of verification method to use for the DID. See DID Core specification for more details. Only the types listed below are supported.", + "type": "string", + "enum": [ + "Ed25519VerificationKey2018", + "JsonWebKey2020", + "Ed25519VerificationKey2020" + ] + }, + "didDocument": { + "$ref": "#/components/schemas/DidDocument" + } + } + }, "DidCreateRequest": { "type": "object", "properties": { diff --git a/src/types/swagger-types.ts b/src/types/swagger-types.ts index 9edaf6c8..47424964 100644 --- a/src/types/swagger-types.ts +++ b/src/types/swagger-types.ts @@ -726,6 +726,30 @@ * type: LinkedDomains * serviceEndpoint: * - https://example.com + * DidCreateRequestFormBased: + * type: object + * properties: + * network: + * description: Network to create the DID on (testnet or mainnet) + * type: string + * enum: + * - testnet + * - mainnet + * methodSpecificIdAlgo: + * description: Algorithm to use for generating the method-specific ID. The two styles supported are UUIDs and Indy-style Base58. See cheqd DID method documentation for more details. + * type: string + * enum: + * - uuid + * - base58btc + * verificationMethodType: + * description: Type of verification method to use for the DID. See DID Core specification for more details. Only the types listed below are supported. + * type: string + * enum: + * - Ed25519VerificationKey2018 + * - JsonWebKey2020 + * - Ed25519VerificationKey2020 + * didDocument: + * $ref: '#/components/schemas/DidDocument' * DidCreateRequest: * type: object * properties: From 0f18da32c2013c813abdbb8cad4ffc879eb29789 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Mon, 18 Sep 2023 13:17:13 +0500 Subject: [PATCH 03/41] Remove didDocument from form based request body in /did/create API. --- src/static/swagger.json | 3 --- src/types/swagger-types.ts | 2 -- 2 files changed, 5 deletions(-) diff --git a/src/static/swagger.json b/src/static/swagger.json index 986fdff8..4ad18e1c 100644 --- a/src/static/swagger.json +++ b/src/static/swagger.json @@ -2503,9 +2503,6 @@ "JsonWebKey2020", "Ed25519VerificationKey2020" ] - }, - "didDocument": { - "$ref": "#/components/schemas/DidDocument" } } }, diff --git a/src/types/swagger-types.ts b/src/types/swagger-types.ts index 47424964..4e18cc7b 100644 --- a/src/types/swagger-types.ts +++ b/src/types/swagger-types.ts @@ -748,8 +748,6 @@ * - Ed25519VerificationKey2018 * - JsonWebKey2020 * - Ed25519VerificationKey2020 - * didDocument: - * $ref: '#/components/schemas/DidDocument' * DidCreateRequest: * type: object * properties: From fe9849737a673ccabe93f918bbcadfeedbba49ed Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Mon, 18 Sep 2023 13:32:02 +0500 Subject: [PATCH 04/41] Rename /did/create API request body section name from "methodSpecificIdAlgo" to "identifierFormatType". --- src/controllers/issuer.ts | 8 ++++---- src/static/swagger.json | 4 ++-- src/types/swagger-types.ts | 4 ++-- tests/helpers.ts | 2 +- tests/payloads/did/did-create-without-permissions.json | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/controllers/issuer.ts b/src/controllers/issuer.ts index 2194b371..ff8ac354 100644 --- a/src/controllers/issuer.ts +++ b/src/controllers/issuer.ts @@ -26,11 +26,11 @@ export class IssuerController { .isString() .isIn([VerificationMethods.Ed255192020, VerificationMethods.Ed255192018, VerificationMethods.JWK]) .withMessage('Invalid verificationMethod'), - check('methodSpecificIdAlgo') + check('identifierFormatType') .optional() .isString() .isIn([MethodSpecificIdAlgo.Base58, MethodSpecificIdAlgo.Uuid]) - .withMessage('Invalid methodSpecificIdAlgo'), + .withMessage('Invalid identifierFormatType'), check('network') .optional() .isString() @@ -226,7 +226,7 @@ export class IssuerController { } const { - methodSpecificIdAlgo, + identifierFormatType, network, verificationMethodType, assertionMethod = true, @@ -244,7 +244,7 @@ export class IssuerController { didDocument = generateDidDoc({ verificationMethod: verificationMethodType || VerificationMethods.Ed255192018, verificationMethodId: 'key-1', - methodSpecificIdAlgo: (methodSpecificIdAlgo as MethodSpecificIdAlgo) || MethodSpecificIdAlgo.Uuid, + methodSpecificIdAlgo: (identifierFormatType as MethodSpecificIdAlgo) || MethodSpecificIdAlgo.Uuid, network, publicKey: key.publicKeyHex, }); diff --git a/src/static/swagger.json b/src/static/swagger.json index 4ad18e1c..0e391167 100644 --- a/src/static/swagger.json +++ b/src/static/swagger.json @@ -2487,7 +2487,7 @@ "mainnet" ] }, - "methodSpecificIdAlgo": { + "identifierFormatType": { "description": "Algorithm to use for generating the method-specific ID. The two styles supported are UUIDs and Indy-style Base58. See cheqd DID method documentation for more details.", "type": "string", "enum": [ @@ -2517,7 +2517,7 @@ "mainnet" ] }, - "methodSpecificIdAlgo": { + "identifierFormatType": { "description": "Algorithm to use for generating the method-specific ID. The two styles supported are UUIDs and Indy-style Base58. See cheqd DID method documentation for more details.", "type": "string", "enum": [ diff --git a/src/types/swagger-types.ts b/src/types/swagger-types.ts index 4e18cc7b..4a413e9e 100644 --- a/src/types/swagger-types.ts +++ b/src/types/swagger-types.ts @@ -735,7 +735,7 @@ * enum: * - testnet * - mainnet - * methodSpecificIdAlgo: + * identifierFormatType: * description: Algorithm to use for generating the method-specific ID. The two styles supported are UUIDs and Indy-style Base58. See cheqd DID method documentation for more details. * type: string * enum: @@ -757,7 +757,7 @@ * enum: * - testnet * - mainnet - * methodSpecificIdAlgo: + * identifierFormatType: * description: Algorithm to use for generating the method-specific ID. The two styles supported are UUIDs and Indy-style Base58. See cheqd DID method documentation for more details. * type: string * enum: diff --git a/tests/helpers.ts b/tests/helpers.ts index 3daa5952..2f38e96c 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -8,7 +8,7 @@ import { export const buildSimpleCreateDID = (network = 'testnet') => { return { - methodSpecificIdAlgo: 'uuid', + identifierFormatType: 'uuid', verificationMethodType: 'Ed25519VerificationKey2018', assertionMethod: true, network: network, diff --git a/tests/payloads/did/did-create-without-permissions.json b/tests/payloads/did/did-create-without-permissions.json index f6e1ecd8..6cb224bc 100644 --- a/tests/payloads/did/did-create-without-permissions.json +++ b/tests/payloads/did/did-create-without-permissions.json @@ -1,5 +1,5 @@ { - "methodSpecificIdAlgo": "uuid", + "identifierFormatType": "uuid", "verificationMethodType": "Ed25519VerificationKey2018", "assertionMethod": true, "network": "mainnet" From c89a51dc7c10ca232526366201f7d28df4c728fb Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Mon, 18 Sep 2023 16:12:56 +0500 Subject: [PATCH 05/41] Update DidCreateRequest type. --- src/static/swagger.json | 50 ++++++++++++-------------------------- src/types/swagger-types.ts | 37 ++++++++-------------------- 2 files changed, 26 insertions(+), 61 deletions(-) diff --git a/src/static/swagger.json b/src/static/swagger.json index 0e391167..710fa6b5 100644 --- a/src/static/swagger.json +++ b/src/static/swagger.json @@ -2507,42 +2507,24 @@ } }, "DidCreateRequest": { - "type": "object", - "properties": { - "network": { - "description": "Network to create the DID on (testnet or mainnet)", - "type": "string", - "enum": [ - "testnet", - "mainnet" - ] - }, - "identifierFormatType": { - "description": "Algorithm to use for generating the method-specific ID. The two styles supported are UUIDs and Indy-style Base58. See cheqd DID method documentation for more details.", - "type": "string", - "enum": [ - "uuid", - "base58btc" - ] - }, - "verificationMethodType": { - "description": "Type of verification method to use for the DID. See DID Core specification for more details. Only the types listed below are supported.", - "type": "string", - "enum": [ - "Ed25519VerificationKey2018", - "JsonWebKey2020", - "Ed25519VerificationKey2020" - ] - }, - "assertionMethod": { - "description": "Usually a reference to a Verification Method. An Assertion Method is required to issue JSON-LD credentials. See DID Core specification for more details.", - "type": "boolean", - "default": true + "allOf": [ + { + "type": "object", + "properties": { + "assertionMethod": { + "description": "Usually a reference to a Verification Method. An Assertion Method is required to issue JSON-LD credentials. See DID Core specification for more details.", + "type": "boolean", + "default": true + }, + "didDocument": { + "$ref": "#/components/schemas/DidDocument" + } + } }, - "didDocument": { - "$ref": "#/components/schemas/DidDocument" + { + "$ref": "#/components/schemas/DidCreateRequestFormBased" } - } + ] }, "DidResult": { "type": "object", diff --git a/src/types/swagger-types.ts b/src/types/swagger-types.ts index 4a413e9e..0e30c17b 100644 --- a/src/types/swagger-types.ts +++ b/src/types/swagger-types.ts @@ -749,33 +749,16 @@ * - JsonWebKey2020 * - Ed25519VerificationKey2020 * DidCreateRequest: - * type: object - * properties: - * network: - * description: Network to create the DID on (testnet or mainnet) - * type: string - * enum: - * - testnet - * - mainnet - * identifierFormatType: - * description: Algorithm to use for generating the method-specific ID. The two styles supported are UUIDs and Indy-style Base58. See cheqd DID method documentation for more details. - * type: string - * enum: - * - uuid - * - base58btc - * verificationMethodType: - * description: Type of verification method to use for the DID. See DID Core specification for more details. Only the types listed below are supported. - * type: string - * enum: - * - Ed25519VerificationKey2018 - * - JsonWebKey2020 - * - Ed25519VerificationKey2020 - * assertionMethod: - * description: Usually a reference to a Verification Method. An Assertion Method is required to issue JSON-LD credentials. See DID Core specification for more details. - * type: boolean - * default: true - * didDocument: - * $ref: '#/components/schemas/DidDocument' + * allOf: + * - type: object + * properties: + * assertionMethod: + * description: Usually a reference to a Verification Method. An Assertion Method is required to issue JSON-LD credentials. See DID Core specification for more details. + * type: boolean + * default: true + * didDocument: + * $ref: '#/components/schemas/DidDocument' + * - $ref: '#/components/schemas/DidCreateRequestFormBased' * DidResult: * type: object * properties: From 1b22b73671980db27c71be0c0f5b202bb47ff5ad Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Mon, 18 Sep 2023 16:24:23 +0500 Subject: [PATCH 06/41] Remove an unused assertionMethod variable for a form based case. --- src/controllers/issuer.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/controllers/issuer.ts b/src/controllers/issuer.ts index ff8ac354..9bacfe15 100644 --- a/src/controllers/issuer.ts +++ b/src/controllers/issuer.ts @@ -229,7 +229,6 @@ export class IssuerController { identifierFormatType, network, verificationMethodType, - assertionMethod = true, serviceEndpoint, } = request.body; let didDocument: DIDDocument; @@ -249,10 +248,6 @@ export class IssuerController { publicKey: key.publicKeyHex, }); - if (assertionMethod) { - didDocument.assertionMethod = didDocument.authentication; - } - if (serviceEndpoint) { didDocument.service = [ { From b9200e18ff108bad299a18fc248f8c97bf11661a Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Mon, 18 Sep 2023 16:35:14 +0500 Subject: [PATCH 07/41] Add service section for form based request body in /did/create API. --- src/controllers/issuer.ts | 12 +++--------- src/static/swagger.json | 18 ++++++++++++++++++ src/types/swagger-types.ts | 12 ++++++++++++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/controllers/issuer.ts b/src/controllers/issuer.ts index 9bacfe15..68306ae0 100644 --- a/src/controllers/issuer.ts +++ b/src/controllers/issuer.ts @@ -229,7 +229,7 @@ export class IssuerController { identifierFormatType, network, verificationMethodType, - serviceEndpoint, + service, } = request.body; let didDocument: DIDDocument; try { @@ -248,14 +248,8 @@ export class IssuerController { publicKey: key.publicKeyHex, }); - if (serviceEndpoint) { - didDocument.service = [ - { - id: `${didDocument.id}#service-1`, - type: 'service-1', - serviceEndpoint: [serviceEndpoint], - }, - ]; + if (service) { + didDocument.service = service; } } else { return response.status(StatusCodes.BAD_REQUEST).json({ diff --git a/src/static/swagger.json b/src/static/swagger.json index 710fa6b5..d1fb0581 100644 --- a/src/static/swagger.json +++ b/src/static/swagger.json @@ -2503,6 +2503,24 @@ "JsonWebKey2020", "Ed25519VerificationKey2020" ] + }, + "service": { + "description": "Communicating or interacting with the DID subject or associated entities via one or more service endpoints. See DID Core specification for more details.", + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "type": { + "type": "string" + }, + "serviceEndpoint": { + "type": "string" + } + } + } } } }, diff --git a/src/types/swagger-types.ts b/src/types/swagger-types.ts index 0e30c17b..207f2bf3 100644 --- a/src/types/swagger-types.ts +++ b/src/types/swagger-types.ts @@ -748,6 +748,18 @@ * - Ed25519VerificationKey2018 * - JsonWebKey2020 * - Ed25519VerificationKey2020 + * service: + * description: Communicating or interacting with the DID subject or associated entities via one or more service endpoints. See DID Core specification for more details. + * type: array + * items: + * type: object + * properties: + * id: + * type: string + * type: + * type: string + * serviceEndpoint: + * type: string * DidCreateRequest: * allOf: * - type: object From 73ace3065bdba817bb75fd7a6bc5fa6ea1e8d785 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Mon, 18 Sep 2023 17:07:01 +0500 Subject: [PATCH 08/41] Update DidCreateRequestFormBased request type. --- src/controllers/issuer.ts | 8 ++++- src/static/swagger.json | 65 ++++++++++++++++++++++++++------------ src/types/swagger-types.ts | 48 +++++++++++++++++++++------- 3 files changed, 88 insertions(+), 33 deletions(-) diff --git a/src/controllers/issuer.ts b/src/controllers/issuer.ts index 68306ae0..66e44368 100644 --- a/src/controllers/issuer.ts +++ b/src/controllers/issuer.ts @@ -249,7 +249,13 @@ export class IssuerController { }); if (service) { - didDocument.service = service; + didDocument.service = [ + { + id: `${didDocument.id}#${service.idFragment}`, + type: service.type, + serviceEndpoint: service.serviceEndpoint, + }, + ]; } } else { return response.status(StatusCodes.BAD_REQUEST).json({ diff --git a/src/static/swagger.json b/src/static/swagger.json index d1fb0581..dc202010 100644 --- a/src/static/swagger.json +++ b/src/static/swagger.json @@ -2510,14 +2510,20 @@ "items": { "type": "object", "properties": { - "id": { - "type": "string" + "idFragment": { + "type": "string", + "example": "service-1" }, "type": { - "type": "string" + "type": "string", + "example": "LinkedDomains" }, "serviceEndpoint": { - "type": "string" + "type": "array", + "items": { + "type": "string", + "example": "https://example.com" + } } } } @@ -2525,24 +2531,42 @@ } }, "DidCreateRequest": { - "allOf": [ - { - "type": "object", - "properties": { - "assertionMethod": { - "description": "Usually a reference to a Verification Method. An Assertion Method is required to issue JSON-LD credentials. See DID Core specification for more details.", - "type": "boolean", - "default": true - }, - "didDocument": { - "$ref": "#/components/schemas/DidDocument" - } - } + "type": "object", + "properties": { + "network": { + "description": "Network to create the DID on (testnet or mainnet)", + "type": "string", + "enum": [ + "testnet", + "mainnet" + ] }, - { - "$ref": "#/components/schemas/DidCreateRequestFormBased" + "methodSpecificIdAlgo": { + "description": "Algorithm to use for generating the method-specific ID. The two styles supported are UUIDs and Indy-style Base58. See cheqd DID method documentation for more details.", + "type": "string", + "enum": [ + "uuid", + "base58btc" + ] + }, + "verificationMethodType": { + "description": "Type of verification method to use for the DID. See DID Core specification for more details. Only the types listed below are supported.", + "type": "string", + "enum": [ + "Ed25519VerificationKey2018", + "JsonWebKey2020", + "Ed25519VerificationKey2020" + ] + }, + "assertionMethod": { + "description": "Usually a reference to a Verification Method. An Assertion Method is required to issue JSON-LD credentials. See DID Core specification for more details.", + "type": "boolean", + "default": true + }, + "didDocument": { + "$ref": "#/components/schemas/DidDocument" } - ] + } }, "DidResult": { "type": "object", @@ -2597,6 +2621,7 @@ } }, "Service": { + "description": "Communicating or interacting with the DID subject or associated entities via one or more service endpoints. See DID Core specification for more details.", "type": "object", "properties": { "id": { diff --git a/src/types/swagger-types.ts b/src/types/swagger-types.ts index 207f2bf3..793fc13c 100644 --- a/src/types/swagger-types.ts +++ b/src/types/swagger-types.ts @@ -754,23 +754,46 @@ * items: * type: object * properties: - * id: + * idFragment: * type: string + * example: service-1 * type: * type: string + * example: LinkedDomains * serviceEndpoint: - * type: string + * type: array + * items: + * type: string + * example: https://example.com + * * DidCreateRequest: - * allOf: - * - type: object - * properties: - * assertionMethod: - * description: Usually a reference to a Verification Method. An Assertion Method is required to issue JSON-LD credentials. See DID Core specification for more details. - * type: boolean - * default: true - * didDocument: - * $ref: '#/components/schemas/DidDocument' - * - $ref: '#/components/schemas/DidCreateRequestFormBased' + * type: object + * properties: + * network: + * description: Network to create the DID on (testnet or mainnet) + * type: string + * enum: + * - testnet + * - mainnet + * methodSpecificIdAlgo: + * description: Algorithm to use for generating the method-specific ID. The two styles supported are UUIDs and Indy-style Base58. See cheqd DID method documentation for more details. + * type: string + * enum: + * - uuid + * - base58btc + * verificationMethodType: + * description: Type of verification method to use for the DID. See DID Core specification for more details. Only the types listed below are supported. + * type: string + * enum: + * - Ed25519VerificationKey2018 + * - JsonWebKey2020 + * - Ed25519VerificationKey2020 + * assertionMethod: + * description: Usually a reference to a Verification Method. An Assertion Method is required to issue JSON-LD credentials. See DID Core specification for more details. + * type: boolean + * default: true + * didDocument: + * $ref: '#/components/schemas/DidDocument' * DidResult: * type: object * properties: @@ -807,6 +830,7 @@ * publicKeyBase58: BTJiso1S4iSiReP6wGksSneGfiKHxz9SYcm2KknpqBJt * type: Ed25519VerificationKey2018 * Service: + * description: Communicating or interacting with the DID subject or associated entities via one or more service endpoints. See DID Core specification for more details. * type: object * properties: * id: From eaafd20b0b025a2524d486e3a7e745527080fe9f Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Tue, 19 Sep 2023 13:45:28 +0500 Subject: [PATCH 09/41] Add key section for form based request body in /did/create API. --- src/controllers/issuer.ts | 17 +++++++++-------- src/static/swagger.json | 4 ++++ src/types/swagger-types.ts | 3 +++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/controllers/issuer.ts b/src/controllers/issuer.ts index 66e44368..66f3e3d1 100644 --- a/src/controllers/issuer.ts +++ b/src/controllers/issuer.ts @@ -230,22 +230,23 @@ export class IssuerController { network, verificationMethodType, service, + key, } = request.body; let didDocument: DIDDocument; try { if (request.body.didDocument) { didDocument = request.body.didDocument; } else if (verificationMethodType) { - const key = await new IdentityServiceStrategySetup(response.locals.customerId).agent.createKey( + const publicKeyHex = key ? key : (await new IdentityServiceStrategySetup(response.locals.customerId).agent.createKey( 'Ed25519', response.locals.customerId - ); + )).publicKeyHex; didDocument = generateDidDoc({ verificationMethod: verificationMethodType || VerificationMethods.Ed255192018, verificationMethodId: 'key-1', methodSpecificIdAlgo: (identifierFormatType as MethodSpecificIdAlgo) || MethodSpecificIdAlgo.Uuid, network, - publicKey: key.publicKeyHex, + publicKey: publicKeyHex, }); if (service) { @@ -502,7 +503,7 @@ export class IssuerController { if (result) { const url = new URL( `${process.env.RESOLVER_URL || DefaultResolverUrl}${did}?` + - `resourceId=${resourcePayload.id}&resourceMetadata=true` + `resourceId=${resourcePayload.id}&resourceMetadata=true` ); const didDereferencing = (await (await fetch(url)).json()) as DIDMetadataDereferencingResult; @@ -646,11 +647,11 @@ export class IssuerController { try { const did = request.params.did ? await new IdentityServiceStrategySetup(response.locals.customerId).agent.resolveDid( - request.params.did - ) + request.params.did + ) : await new IdentityServiceStrategySetup(response.locals.customerId).agent.listDids( - response.locals.customerId - ); + response.locals.customerId + ); return response.status(StatusCodes.OK).json(did); } catch (error) { diff --git a/src/static/swagger.json b/src/static/swagger.json index dc202010..1ca671e7 100644 --- a/src/static/swagger.json +++ b/src/static/swagger.json @@ -2527,6 +2527,10 @@ } } } + }, + "key": { + "description": "The unique identifier in hexadecimal public key format used in the verification method to create the DID.", + "type": "string" } } }, diff --git a/src/types/swagger-types.ts b/src/types/swagger-types.ts index 793fc13c..4047309d 100644 --- a/src/types/swagger-types.ts +++ b/src/types/swagger-types.ts @@ -765,6 +765,9 @@ * items: * type: string * example: https://example.com + * key: + * description: The unique identifier in hexadecimal public key format used in the verification method to create the DID. + * type: string * * DidCreateRequest: * type: object From b169d990f8d84767c6ae4c466e094c19ce1772e1 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Tue, 19 Sep 2023 15:24:03 +0500 Subject: [PATCH 10/41] Update swagger (OpenAPI). --- src/static/swagger.json | 2 +- src/types/swagger-types.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/static/swagger.json b/src/static/swagger.json index 1ca671e7..066ae471 100644 --- a/src/static/swagger.json +++ b/src/static/swagger.json @@ -2545,7 +2545,7 @@ "mainnet" ] }, - "methodSpecificIdAlgo": { + "identifierFormatType": { "description": "Algorithm to use for generating the method-specific ID. The two styles supported are UUIDs and Indy-style Base58. See cheqd DID method documentation for more details.", "type": "string", "enum": [ diff --git a/src/types/swagger-types.ts b/src/types/swagger-types.ts index 4047309d..6943d0a4 100644 --- a/src/types/swagger-types.ts +++ b/src/types/swagger-types.ts @@ -778,7 +778,7 @@ * enum: * - testnet * - mainnet - * methodSpecificIdAlgo: + * identifierFormatType: * description: Algorithm to use for generating the method-specific ID. The two styles supported are UUIDs and Indy-style Base58. See cheqd DID method documentation for more details. * type: string * enum: From 0579eefbacc13b6f965ea39d41cfecc0d4080939 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Thu, 21 Sep 2023 12:16:47 +0500 Subject: [PATCH 11/41] Bump '@cheqd/sdk' version. --- package-lock.json | 31 +++++++++++++++++-------------- package.json | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 10e0de69..a2847d35 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "Apache-2.0", "dependencies": { "@cheqd/did-provider-cheqd": "^3.6.8", - "@cheqd/sdk": "^3.6.2", + "@cheqd/sdk": "^3.7.1", "@cheqd/ts-proto": "^3.3.1", "@cosmjs/amino": "^0.31.1", "@cosmjs/encoding": "^0.31.1", @@ -2625,11 +2625,11 @@ } }, "node_modules/@cheqd/sdk": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/@cheqd/sdk/-/sdk-3.6.2.tgz", - "integrity": "sha512-k65l2KUCahXVYZgQVkdLZx7QM5xwAN9U8VzFRANDHT2qPwnU4gYXQE8Y3WWRbNTCETSw5NF1Pj3MTza7Sj83LQ==", + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/@cheqd/sdk/-/sdk-3.7.1.tgz", + "integrity": "sha512-cVek7qerGnhPrujncybThuNi/DzKwkbHY87pGBsHKswNdQVwJWOWf5gRwQMg0FC3NaKeH2moSZpTrTvGGCK+Uw==", "dependencies": { - "@cheqd/ts-proto": "^3.3.1", + "@cheqd/ts-proto": "^3.3.2", "@cosmjs/amino": "^0.31.1", "@cosmjs/crypto": "^0.31.1", "@cosmjs/encoding": "^0.31.1", @@ -2641,24 +2641,27 @@ "@stablelib/ed25519": "^1.0.3", "@types/secp256k1": "^4.0.3", "cosmjs-types": "^0.8.0", - "did-jwt": "^7.2.7", + "did-jwt": "^7.2.8", "did-resolver": "^4.1.0", "file-type": "^18.5.0", "multiformats": "^12.1.1", "secp256k1": "^5.0.0", - "uuid": "^9.0.0" + "uuid": "^9.0.1" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@cheqd/ts-proto": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/@cheqd/ts-proto/-/ts-proto-3.3.1.tgz", - "integrity": "sha512-/Xebb3fPGujw8Fwbu+wneVh5bP7CWEwX9iE01N2wh3cmSyHpbLBlEIcaJQ0Fzq6pSCQIomS4z4+V3cOw2Bkd+g==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/@cheqd/ts-proto/-/ts-proto-3.3.2.tgz", + "integrity": "sha512-CpA7d4MPquWFPuAS7Ex5WtErLKhdblyYex4j87RGxMAdyCm4RrAK2dJC5gZqpHVX4aMtlG1/qfeoaTNuczZYrg==", "dependencies": { "long": "^5.2.3", - "protobufjs": "^7.2.4" + "protobufjs": "^7.2.5" + }, + "engines": { + "node": ">=18.0.0" } }, "node_modules/@colors/colors": { @@ -14727,9 +14730,9 @@ } }, "node_modules/did-jwt": { - "version": "7.2.7", - "resolved": "https://registry.npmjs.org/did-jwt/-/did-jwt-7.2.7.tgz", - "integrity": "sha512-8hCEG13b3YV7Gw+euv4hSFKTk83tAeItP8d/dfz81KL1XfRahsvdbepZS1ckPsS1tLzQadQ+pxscvhkddfuQDA==", + "version": "7.2.8", + "resolved": "https://registry.npmjs.org/did-jwt/-/did-jwt-7.2.8.tgz", + "integrity": "sha512-hT+F7F7crtu9UsDoopGv9tJL/yrLb26IU92FjL2VHrQ8buei1WUCZRJHan2yQSRKtc9Vao0iCxq59bAmYMWnXA==", "dependencies": { "@noble/curves": "^1.0.0", "@noble/hashes": "^1.3.0", diff --git a/package.json b/package.json index 29079cff..af5aff1b 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ ], "dependencies": { "@cheqd/did-provider-cheqd": "^3.6.8", - "@cheqd/sdk": "^3.6.2", + "@cheqd/sdk": "^3.7.1", "@cheqd/ts-proto": "^3.3.1", "@cosmjs/amino": "^0.31.1", "@cosmjs/encoding": "^0.31.1", From d692f1c1e32180c6c530addbe963f74fe0ead12c Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Thu, 21 Sep 2023 12:18:54 +0500 Subject: [PATCH 12/41] Add options section for json based request body in /create/did API. --- src/controllers/issuer.ts | 24 +++++++++++--- src/helpers/helpers.ts | 65 ++++++++++++++++++++++++++++++++++++-- src/static/swagger.json | 26 +++++++++------ src/types/swagger-types.ts | 19 +++++++---- 4 files changed, 110 insertions(+), 24 deletions(-) diff --git a/src/controllers/issuer.ts b/src/controllers/issuer.ts index 66f3e3d1..105ae4c5 100644 --- a/src/controllers/issuer.ts +++ b/src/controllers/issuer.ts @@ -3,12 +3,11 @@ import { check, param, validationResult } from 'express-validator'; import { fromString } from 'uint8arrays'; import type { DIDDocument, Service, VerificationMethod } from 'did-resolver'; import { v4 } from 'uuid'; -import { MethodSpecificIdAlgo, VerificationMethods, CheqdNetwork } from '@cheqd/sdk'; +import { CheqdNetwork, MethodSpecificIdAlgo, VerificationMethods } from '@cheqd/sdk'; import type { MsgCreateResourcePayload } from '@cheqd/ts-proto/cheqd/resource/v2/index.js'; import { StatusCodes } from 'http-status-codes'; - import { IdentityServiceStrategySetup } from '../services/identity/index.js'; -import { generateDidDoc, getQueryParams, validateSpecCompliantPayload } from '../helpers/helpers.js'; +import { generateDidDoc, generateVerificationMethod, getQueryParams, validateDidCreatePayload, validateSpecCompliantPayload } from '../helpers/helpers.js'; import { DIDMetadataDereferencingResult, DefaultResolverUrl } from '@cheqd/did-provider-cheqd'; export class IssuerController { @@ -17,7 +16,7 @@ export class IssuerController { .optional() .isObject() .custom((value) => { - const { valid } = validateSpecCompliantPayload(value); + const { valid } = validateDidCreatePayload(value); return valid; }) .withMessage('Invalid didDocument'), @@ -231,13 +230,28 @@ export class IssuerController { verificationMethodType, service, key, + options, } = request.body; let didDocument: DIDDocument; try { if (request.body.didDocument) { didDocument = request.body.didDocument; + if (options) { + const publicKeyHex = options.key || (await new IdentityServiceStrategySetup(response.locals.customerId).agent.createKey( + 'Ed25519', + response.locals.customerId + )).publicKeyHex; + + didDocument.verificationMethod = [ + generateVerificationMethod(didDocument.id, publicKeyHex, options.verificationMethodType) + ]; + } else { + return response.status(StatusCodes.BAD_REQUEST).json({ + error: 'Provide options section to create a DID', + }); + } } else if (verificationMethodType) { - const publicKeyHex = key ? key : (await new IdentityServiceStrategySetup(response.locals.customerId).agent.createKey( + const publicKeyHex = key || (await new IdentityServiceStrategySetup(response.locals.customerId).agent.createKey( 'Ed25519', response.locals.customerId )).publicKeyHex; diff --git a/src/helpers/helpers.ts b/src/helpers/helpers.ts index 0e5c489e..eaab2b3c 100644 --- a/src/helpers/helpers.ts +++ b/src/helpers/helpers.ts @@ -1,4 +1,4 @@ -import type { DIDDocument } from 'did-resolver'; +import type { DIDDocument, VerificationMethod } from 'did-resolver'; import { MethodSpecificIdAlgo, CheqdNetwork, @@ -8,6 +8,7 @@ import { createVerificationKeys, createDidVerificationMethod, createDidPayload, + toMultibaseRaw, } from '@cheqd/sdk'; import { createHmac } from 'node:crypto'; import type { ParsedQs } from 'qs'; @@ -15,6 +16,9 @@ import type { SpecValidationResult } from '../types/shared.js'; import { DEFAULT_DENOM_EXPONENT, MINIMAL_DENOM } from '../types/constants.js'; import { LitCompatibleCosmosChains, type DkgOptions, LitNetworks } from '@cheqd/did-provider-cheqd'; import type { Coin } from '@cosmjs/amino'; +import { fromString, toString } from 'uint8arrays'; +import { bases } from "multiformats/basics"; +import { base64ToBytes } from "did-jwt"; export interface IDidDocOptions { verificationMethod: VerificationMethods; @@ -66,6 +70,14 @@ export function toDefaultDkg(did: string): DkgOptions { } } +export function validateDidCreatePayload(didDocument: DIDDocument): SpecValidationResult { + // id is required, validated on both compile and runtime + if (!didDocument.id && !didDocument.id.startsWith('did:cheqd:')) return { valid: false, error: 'id is required' }; + + if (!isValidService(didDocument)) return { valid: false, error: 'Service is Invalid' }; + return { valid: true } as SpecValidationResult; +} + export function validateSpecCompliantPayload(didDocument: DIDDocument): SpecValidationResult { // id is required, validated on both compile and runtime if (!didDocument.id && !didDocument.id.startsWith('did:cheqd:')) return { valid: false, error: 'id is required' }; @@ -92,8 +104,8 @@ export function validateSpecCompliantPayload(didDocument: DIDDocument): SpecVali export function isValidService(didDocument: DIDDocument): boolean { return didDocument.service ? didDocument?.service?.every((s) => { - return s?.serviceEndpoint && s?.id && s?.type; - }) + return s?.serviceEndpoint && s?.id && s?.type; + }) : true; } @@ -124,6 +136,53 @@ export function generateDidDoc(options: IDidDocOptions) { return createDidPayload(verificationMethods, [verificationKeys]); } +export function generateVerificationMethod( + did: string, + publicKeyHex: string, + verificationMethodType: VerificationMethods +): VerificationMethod { + const pkBase64 = publicKeyHex.length == 43 ? publicKeyHex : toString(fromString(publicKeyHex, 'hex'), 'base64'); + switch (verificationMethodType) { + case VerificationMethods.Ed255192018: + return generateVerificationMethodEd255192018(did, pkBase64); + case VerificationMethods.Ed255192020: + return generateVerificationMethodEd255192020(did, pkBase64); + case VerificationMethods.JWK: + return generateVerificationMethodJWK(did, pkBase64); + }; +} + +function generateVerificationMethodEd255192018(did: string, pkBase64: string) { + return { + id: `${did}#key-1`, + type: VerificationMethods.Ed255192018, + controller: did, + publicKeyBase58: bases['base58btc'].encode(base64ToBytes(pkBase64)).slice(1) + }; +} + +function generateVerificationMethodEd255192020(did: string, pkBase64: string) { + return { + id: `${did}#key-1`, + type: VerificationMethods.Ed255192020, + controller: did, + publicKeyMultibase: toMultibaseRaw(base64ToBytes(pkBase64)) + }; +} + +function generateVerificationMethodJWK(did: string, pkBase64: string) { + return { + id: `${did}#key-1`, + type: VerificationMethods.JWK, + controller: did, + publicKeyJwk: { + crv: 'Ed25519', + kty: 'OKP', + x: toString(fromString(pkBase64, 'base64pad'), 'base64url') + } + }; +} + export function verifyHookSignature(signingKey: string, rawBody: string, expectedSignature: string): boolean { const hmac = createHmac('sha256', signingKey); hmac.update(rawBody); diff --git a/src/static/swagger.json b/src/static/swagger.json index 066ae471..1e31d437 100644 --- a/src/static/swagger.json +++ b/src/static/swagger.json @@ -2553,20 +2553,28 @@ "base58btc" ] }, - "verificationMethodType": { - "description": "Type of verification method to use for the DID. See DID Core specification for more details. Only the types listed below are supported.", - "type": "string", - "enum": [ - "Ed25519VerificationKey2018", - "JsonWebKey2020", - "Ed25519VerificationKey2020" - ] - }, "assertionMethod": { "description": "Usually a reference to a Verification Method. An Assertion Method is required to issue JSON-LD credentials. See DID Core specification for more details.", "type": "boolean", "default": true }, + "options": { + "type": "object", + "properties": { + "key": { + "type": "string" + }, + "verificationMethodType": { + "description": "Type of verification method to use for the DID. See DID Core specification for more details. Only the types listed below are supported.", + "type": "string", + "enum": [ + "Ed25519VerificationKey2018", + "JsonWebKey2020", + "Ed25519VerificationKey2020" + ] + } + } + }, "didDocument": { "$ref": "#/components/schemas/DidDocument" } diff --git a/src/types/swagger-types.ts b/src/types/swagger-types.ts index 6943d0a4..a0434afe 100644 --- a/src/types/swagger-types.ts +++ b/src/types/swagger-types.ts @@ -784,17 +784,22 @@ * enum: * - uuid * - base58btc - * verificationMethodType: - * description: Type of verification method to use for the DID. See DID Core specification for more details. Only the types listed below are supported. - * type: string - * enum: - * - Ed25519VerificationKey2018 - * - JsonWebKey2020 - * - Ed25519VerificationKey2020 * assertionMethod: * description: Usually a reference to a Verification Method. An Assertion Method is required to issue JSON-LD credentials. See DID Core specification for more details. * type: boolean * default: true + * options: + * type: object + * properties: + * key: + * type: string + * verificationMethodType: + * description: Type of verification method to use for the DID. See DID Core specification for more details. Only the types listed below are supported. + * type: string + * enum: + * - Ed25519VerificationKey2018 + * - JsonWebKey2020 + * - Ed25519VerificationKey2020 * didDocument: * $ref: '#/components/schemas/DidDocument' * DidResult: From 86b53a1e0f5d1ae54b64b69b6dbd504dae7ba752 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Thu, 21 Sep 2023 12:26:49 +0500 Subject: [PATCH 13/41] Remove verificationMethod from json based request body in /did/create API. --- src/static/swagger.json | 80 +++++++++++++++++++++++++++++++++++++- src/types/swagger-types.ts | 53 ++++++++++++++++++++++++- 2 files changed, 131 insertions(+), 2 deletions(-) diff --git a/src/static/swagger.json b/src/static/swagger.json index 1e31d437..036094da 100644 --- a/src/static/swagger.json +++ b/src/static/swagger.json @@ -2476,6 +2476,84 @@ ] } }, + "DidDocumentWithoutVerificationMethod": { + "description": "This input field contains either a complete DID document, or an incremental change (diff) to a DID document. See Universal DID Registrar specification.", + "type": "object", + "properties": { + "@context": { + "type": "array", + "items": { + "type": "string" + } + }, + "id": { + "type": "string" + }, + "controllers": { + "type": "array", + "items": { + "type": "string" + } + }, + "service": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Service" + } + }, + "authentication": { + "type": "array", + "items": { + "type": "string" + } + }, + "assertionMethod": { + "type": "array", + "items": { + "type": "string" + } + }, + "capabilityInvocation": { + "type": "array", + "items": { + "type": "string" + } + }, + "capabilityDelegation": { + "type": "array", + "items": { + "type": "string" + } + }, + "keyAgreement": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "example": { + "@context": [ + "https://www.w3.org/ns/did/v1" + ], + "id": "did:cheqd:testnet:7bf81a20-633c-4cc7-bc4a-5a45801005e0", + "controller": [ + "did:cheqd:testnet:7bf81a20-633c-4cc7-bc4a-5a45801005e0" + ], + "authentication": [ + "did:cheqd:testnet:7bf81a20-633c-4cc7-bc4a-5a45801005e0#key-1" + ], + "service": [ + { + "id": "did:cheqd:testnet:7bf81a20-633c-4cc7-bc4a-5a45801005e0#service-1", + "type": "LinkedDomains", + "serviceEndpoint": [ + "https://example.com" + ] + } + ] + } + }, "DidCreateRequestFormBased": { "type": "object", "properties": { @@ -2576,7 +2654,7 @@ } }, "didDocument": { - "$ref": "#/components/schemas/DidDocument" + "$ref": "#/components/schemas/DidDocumentWithoutVerificationMethod" } } }, diff --git a/src/types/swagger-types.ts b/src/types/swagger-types.ts index a0434afe..5ea84d5e 100644 --- a/src/types/swagger-types.ts +++ b/src/types/swagger-types.ts @@ -725,6 +725,57 @@ * - id: did:cheqd:testnet:7bf81a20-633c-4cc7-bc4a-5a45801005e0#service-1 * type: LinkedDomains * serviceEndpoint: + * - https://example.com + * DidDocumentWithoutVerificationMethod: + * description: This input field contains either a complete DID document, or an incremental change (diff) to a DID document. See Universal DID Registrar specification. + * type: object + * properties: + * '@context': + * type: array + * items: + * type: string + * id: + * type: string + * controllers: + * type: array + * items: + * type: string + * service: + * type: array + * items: + * $ref: '#/components/schemas/Service' + * authentication: + * type: array + * items: + * type: string + * assertionMethod: + * type: array + * items: + * type: string + * capabilityInvocation: + * type: array + * items: + * type: string + * capabilityDelegation: + * type: array + * items: + * type: string + * keyAgreement: + * type: array + * items: + * type: string + * example: + * '@context': + * - https://www.w3.org/ns/did/v1 + * id: did:cheqd:testnet:7bf81a20-633c-4cc7-bc4a-5a45801005e0 + * controller: + * - did:cheqd:testnet:7bf81a20-633c-4cc7-bc4a-5a45801005e0 + * authentication: + * - did:cheqd:testnet:7bf81a20-633c-4cc7-bc4a-5a45801005e0#key-1 + * service: + * - id: did:cheqd:testnet:7bf81a20-633c-4cc7-bc4a-5a45801005e0#service-1 + * type: LinkedDomains + * serviceEndpoint: * - https://example.com * DidCreateRequestFormBased: * type: object @@ -801,7 +852,7 @@ * - JsonWebKey2020 * - Ed25519VerificationKey2020 * didDocument: - * $ref: '#/components/schemas/DidDocument' + * $ref: '#/components/schemas/DidDocumentWithoutVerificationMethod' * DidResult: * type: object * properties: From 1f9302a9f405be769c88264b86f619c84d0bcded Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Thu, 21 Sep 2023 12:31:45 +0500 Subject: [PATCH 14/41] Add example for key field in json based request body in /did/create API. --- src/static/swagger.json | 3 ++- src/types/swagger-types.ts | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/static/swagger.json b/src/static/swagger.json index 036094da..e9698c2e 100644 --- a/src/static/swagger.json +++ b/src/static/swagger.json @@ -2640,7 +2640,8 @@ "type": "object", "properties": { "key": { - "type": "string" + "type": "string", + "example": "8255ddadd75695e01f3d98fcec8ccc7861a030b317d4326b0e48a4d579ddc43a" }, "verificationMethodType": { "description": "Type of verification method to use for the DID. See DID Core specification for more details. Only the types listed below are supported.", diff --git a/src/types/swagger-types.ts b/src/types/swagger-types.ts index 5ea84d5e..88e2b05f 100644 --- a/src/types/swagger-types.ts +++ b/src/types/swagger-types.ts @@ -844,6 +844,7 @@ * properties: * key: * type: string + * example: 8255ddadd75695e01f3d98fcec8ccc7861a030b317d4326b0e48a4d579ddc43a * verificationMethodType: * description: Type of verification method to use for the DID. See DID Core specification for more details. Only the types listed below are supported. * type: string From 6135b4f333894aa43cfde118eafc0896e7d23dd9 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Thu, 21 Sep 2023 13:36:41 +0500 Subject: [PATCH 15/41] Remove an unused expression: - This always evaluates to truthy. --- src/controllers/issuer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/issuer.ts b/src/controllers/issuer.ts index 105ae4c5..e8d225aa 100644 --- a/src/controllers/issuer.ts +++ b/src/controllers/issuer.ts @@ -256,7 +256,7 @@ export class IssuerController { response.locals.customerId )).publicKeyHex; didDocument = generateDidDoc({ - verificationMethod: verificationMethodType || VerificationMethods.Ed255192018, + verificationMethod: verificationMethodType, verificationMethodId: 'key-1', methodSpecificIdAlgo: (identifierFormatType as MethodSpecificIdAlgo) || MethodSpecificIdAlgo.Uuid, network, From b1cef448fcde6e7f44dada6a3f2dd6b4f50c985d Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Thu, 21 Sep 2023 13:52:09 +0500 Subject: [PATCH 16/41] Remove an incorrect description from DidDocumentWithoutVerificationMethod type. --- src/types/swagger-types.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/types/swagger-types.ts b/src/types/swagger-types.ts index 88e2b05f..857a1a9c 100644 --- a/src/types/swagger-types.ts +++ b/src/types/swagger-types.ts @@ -727,7 +727,6 @@ * serviceEndpoint: * - https://example.com * DidDocumentWithoutVerificationMethod: - * description: This input field contains either a complete DID document, or an incremental change (diff) to a DID document. See Universal DID Registrar specification. * type: object * properties: * '@context': From 000f795f42c7c4c1f88caae85e63b88ba10ac91e Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Thu, 21 Sep 2023 16:34:33 +0500 Subject: [PATCH 17/41] Add '@context' section for form based request body in /did/create API. --- src/controllers/issuer.ts | 4 ++++ src/static/swagger.json | 10 +++++++++- src/types/swagger-types.ts | 6 ++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/controllers/issuer.ts b/src/controllers/issuer.ts index e8d225aa..5f3b381d 100644 --- a/src/controllers/issuer.ts +++ b/src/controllers/issuer.ts @@ -263,6 +263,10 @@ export class IssuerController { publicKey: publicKeyHex, }); + if (typeof request.body['@context'] === 'string') { + didDocument['@context'] = [request.body['@context']] ; + } + if (service) { didDocument.service = [ { diff --git a/src/static/swagger.json b/src/static/swagger.json index e9698c2e..f9155f54 100644 --- a/src/static/swagger.json +++ b/src/static/swagger.json @@ -2477,7 +2477,6 @@ } }, "DidDocumentWithoutVerificationMethod": { - "description": "This input field contains either a complete DID document, or an incremental change (diff) to a DID document. See Universal DID Registrar specification.", "type": "object", "properties": { "@context": { @@ -2609,6 +2608,15 @@ "key": { "description": "The unique identifier in hexadecimal public key format used in the verification method to create the DID.", "type": "string" + }, + "@context": { + "type": "array", + "items": { + "type": "string" + }, + "example": [ + "https://www.w3.org/ns/did/v1" + ] } } }, diff --git a/src/types/swagger-types.ts b/src/types/swagger-types.ts index 857a1a9c..90cc3e21 100644 --- a/src/types/swagger-types.ts +++ b/src/types/swagger-types.ts @@ -818,6 +818,12 @@ * key: * description: The unique identifier in hexadecimal public key format used in the verification method to create the DID. * type: string + * '@context': + * type: array + * items: + * type: string + * example: + * - https://www.w3.org/ns/did/v1 * * DidCreateRequest: * type: object From f7c2b48e4ef51d5fcc38252e1ccdf095d5528e56 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Mon, 25 Sep 2023 12:02:01 +0500 Subject: [PATCH 18/41] Use an exist createDidVerificationMethod function instead of helper functions. --- src/controllers/issuer.ts | 20 +++++++++------ src/helpers/helpers.ts | 53 +-------------------------------------- 2 files changed, 14 insertions(+), 59 deletions(-) diff --git a/src/controllers/issuer.ts b/src/controllers/issuer.ts index 5f3b381d..f28fa8e8 100644 --- a/src/controllers/issuer.ts +++ b/src/controllers/issuer.ts @@ -1,14 +1,16 @@ import type { Request, Response } from 'express'; import { check, param, validationResult } from 'express-validator'; -import { fromString } from 'uint8arrays'; +import { fromString, toString } from 'uint8arrays'; import type { DIDDocument, Service, VerificationMethod } from 'did-resolver'; import { v4 } from 'uuid'; -import { CheqdNetwork, MethodSpecificIdAlgo, VerificationMethods } from '@cheqd/sdk'; +import { CheqdNetwork, MethodSpecificIdAlgo, VerificationMethods, createDidVerificationMethod } from '@cheqd/sdk'; import type { MsgCreateResourcePayload } from '@cheqd/ts-proto/cheqd/resource/v2/index.js'; import { StatusCodes } from 'http-status-codes'; import { IdentityServiceStrategySetup } from '../services/identity/index.js'; -import { generateDidDoc, generateVerificationMethod, getQueryParams, validateDidCreatePayload, validateSpecCompliantPayload } from '../helpers/helpers.js'; +import { generateDidDoc, getQueryParams, validateDidCreatePayload, validateSpecCompliantPayload } from '../helpers/helpers.js'; import { DIDMetadataDereferencingResult, DefaultResolverUrl } from '@cheqd/did-provider-cheqd'; +import { bases } from "multiformats/basics"; +import { base64ToBytes } from "did-jwt"; export class IssuerController { public static createValidator = [ @@ -241,10 +243,14 @@ export class IssuerController { 'Ed25519', response.locals.customerId )).publicKeyHex; - - didDocument.verificationMethod = [ - generateVerificationMethod(didDocument.id, publicKeyHex, options.verificationMethodType) - ]; + const pkBase64 = publicKeyHex.length == 43 ? publicKeyHex : toString(fromString(publicKeyHex, 'hex'), 'base64'); + + didDocument.verificationMethod = createDidVerificationMethod([options.verificationMethodType], [{ + methodSpecificId: bases['base58btc'].encode(base64ToBytes(pkBase64)), + didUrl: didDocument.id, + keyId: `${didDocument.id}#key-1`, + publicKey: pkBase64 + }]); } else { return response.status(StatusCodes.BAD_REQUEST).json({ error: 'Provide options section to create a DID', diff --git a/src/helpers/helpers.ts b/src/helpers/helpers.ts index eaab2b3c..be299fbe 100644 --- a/src/helpers/helpers.ts +++ b/src/helpers/helpers.ts @@ -1,4 +1,4 @@ -import type { DIDDocument, VerificationMethod } from 'did-resolver'; +import type { DIDDocument } from 'did-resolver'; import { MethodSpecificIdAlgo, CheqdNetwork, @@ -8,7 +8,6 @@ import { createVerificationKeys, createDidVerificationMethod, createDidPayload, - toMultibaseRaw, } from '@cheqd/sdk'; import { createHmac } from 'node:crypto'; import type { ParsedQs } from 'qs'; @@ -16,9 +15,6 @@ import type { SpecValidationResult } from '../types/shared.js'; import { DEFAULT_DENOM_EXPONENT, MINIMAL_DENOM } from '../types/constants.js'; import { LitCompatibleCosmosChains, type DkgOptions, LitNetworks } from '@cheqd/did-provider-cheqd'; import type { Coin } from '@cosmjs/amino'; -import { fromString, toString } from 'uint8arrays'; -import { bases } from "multiformats/basics"; -import { base64ToBytes } from "did-jwt"; export interface IDidDocOptions { verificationMethod: VerificationMethods; @@ -136,53 +132,6 @@ export function generateDidDoc(options: IDidDocOptions) { return createDidPayload(verificationMethods, [verificationKeys]); } -export function generateVerificationMethod( - did: string, - publicKeyHex: string, - verificationMethodType: VerificationMethods -): VerificationMethod { - const pkBase64 = publicKeyHex.length == 43 ? publicKeyHex : toString(fromString(publicKeyHex, 'hex'), 'base64'); - switch (verificationMethodType) { - case VerificationMethods.Ed255192018: - return generateVerificationMethodEd255192018(did, pkBase64); - case VerificationMethods.Ed255192020: - return generateVerificationMethodEd255192020(did, pkBase64); - case VerificationMethods.JWK: - return generateVerificationMethodJWK(did, pkBase64); - }; -} - -function generateVerificationMethodEd255192018(did: string, pkBase64: string) { - return { - id: `${did}#key-1`, - type: VerificationMethods.Ed255192018, - controller: did, - publicKeyBase58: bases['base58btc'].encode(base64ToBytes(pkBase64)).slice(1) - }; -} - -function generateVerificationMethodEd255192020(did: string, pkBase64: string) { - return { - id: `${did}#key-1`, - type: VerificationMethods.Ed255192020, - controller: did, - publicKeyMultibase: toMultibaseRaw(base64ToBytes(pkBase64)) - }; -} - -function generateVerificationMethodJWK(did: string, pkBase64: string) { - return { - id: `${did}#key-1`, - type: VerificationMethods.JWK, - controller: did, - publicKeyJwk: { - crv: 'Ed25519', - kty: 'OKP', - x: toString(fromString(pkBase64, 'base64pad'), 'base64url') - } - }; -} - export function verifyHookSignature(signingKey: string, rawBody: string, expectedSignature: string): boolean { const hmac = createHmac('sha256', signingKey); hmac.update(rawBody); From 85e8991450fe9f75b29dfeddb00ae8704d0de134 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Mon, 25 Sep 2023 12:43:50 +0500 Subject: [PATCH 19/41] Create CreateDidRequestBody type for asserting request body in /did/create API. --- src/controllers/issuer.ts | 3 ++- src/types/shared.ts | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/controllers/issuer.ts b/src/controllers/issuer.ts index f28fa8e8..4e3ed64e 100644 --- a/src/controllers/issuer.ts +++ b/src/controllers/issuer.ts @@ -11,6 +11,7 @@ import { generateDidDoc, getQueryParams, validateDidCreatePayload, validateSpecC import { DIDMetadataDereferencingResult, DefaultResolverUrl } from '@cheqd/did-provider-cheqd'; import { bases } from "multiformats/basics"; import { base64ToBytes } from "did-jwt"; +import type { CreateDidRequestBody } from '../types/shared.js'; export class IssuerController { public static createValidator = [ @@ -233,7 +234,7 @@ export class IssuerController { service, key, options, - } = request.body; + } = request.body satisfies CreateDidRequestBody; let didDocument: DIDDocument; try { if (request.body.didDocument) { diff --git a/src/types/shared.ts b/src/types/shared.ts index 1cfdeb1d..97ce9791 100644 --- a/src/types/shared.ts +++ b/src/types/shared.ts @@ -29,8 +29,9 @@ import type { ICredentialIssuerLD } from '@veramo/credential-ld'; import type { AbstractIdentifierProvider } from '@veramo/did-manager'; import type { AbstractKeyManagementSystem } from '@veramo/key-manager'; import type { DataSource } from 'typeorm'; -import { CheqdNetwork } from '@cheqd/sdk'; +import { CheqdNetwork, MethodSpecificIdAlgo, Service, VerificationMethods } from '@cheqd/sdk'; import type { AlternativeUri } from '@cheqd/ts-proto/cheqd/resource/v2'; +import type { DIDDocument } from 'did-resolver'; const DefaultUuidPattern = '([a-zA-Z0-9-]{36})'; const DefaultMethodSpecificIdPattern = `(?:[a-zA-Z0-9]{21,22}|${DefaultUuidPattern})`; @@ -61,6 +62,20 @@ export type MinimalPaymentCondition = { feePaymentWindow: number; // in minutes, strictly integer, e.g. 5 minutes, 10 minutes }; +export type CreateDidRequestBody = { + didDocument?: DIDDocument + identifierFormatType: MethodSpecificIdAlgo; + network: CheqdNetwork; + verificationMethodType?: VerificationMethods; + service?: Service | Service[]; + '@context'?: string | string[]; + key?: string; + options?: { + verificationMethodType: VerificationMethods; + key: string; + }; +}; + export type CreateUnencryptedStatusListRequestBody = { did: string; statusListName: string; From 647ba9d3dbd4eb7ed425f93e11f0fb2a12327fb2 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Tue, 26 Sep 2023 20:51:05 +0500 Subject: [PATCH 20/41] Add integration tests for testing form-based request body in /did/create API. --- tests/constants.ts | 18 +++++++++ tests/did/positive.did.spec.ts | 69 ++++++++++++++++++++++++++++++++++ tests/helpers.ts | 13 +++++++ 3 files changed, 100 insertions(+) create mode 100644 tests/did/positive.did.spec.ts diff --git a/tests/constants.ts b/tests/constants.ts index 74863f99..4d328caf 100644 --- a/tests/constants.ts +++ b/tests/constants.ts @@ -13,3 +13,21 @@ export const DEFAULT_SUBJECT_DID = 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLG // Messages export const DEFAULT_DOES_NOT_HAVE_PERMISSIONS = 'Unauthorized error: Your account is not authorized to carry out this action.'; + +export const DEFAULT_CONTEXT="https://www.w3.org/ns/did/v1" + +export enum NETWORK { + MAINNET = "mainnet", + TESTNET = "testnet" +}; + +export enum ID_TYPE { + UUID = "uuid", + BASE58BTC = "base58btc" +}; + +export enum VERIFICATION_METHOD_TYPES { + Ed25519VerificationKey2018 = "Ed25519VerificationKey2018", + Ed25519VerificationKey2020 = "Ed25519VerificationKey2020", + JsonWebKey2020 = "JsonWebKey2020" +}; diff --git a/tests/did/positive.did.spec.ts b/tests/did/positive.did.spec.ts new file mode 100644 index 00000000..818d85e8 --- /dev/null +++ b/tests/did/positive.did.spec.ts @@ -0,0 +1,69 @@ +import { test, expect } from '@playwright/test'; +import { DEFAULT_CONTEXT, ID_TYPE, NETWORK, VERIFICATION_METHOD_TYPES } from '../constants'; +import { StatusCodes } from 'http-status-codes'; +import { buildSimpleService } from 'helpers'; + +test.use({ storageState: 'playwright/.auth/user.json' }); + +test('[Positive] It can create DID with mandatory properties (Indy style)', async ({ request }) => { + // send request to create DID + let response = await request.post(`/did/create`, { + data: `network=${NETWORK.TESTNET}&identifierFormatType=${ID_TYPE.BASE58BTC}&` + + `verificationMethodType=${VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020}`, + headers: { 'Content-Type': 'application/x-www-form-urlencoded' } + }); + expect(response.status()).toBe(StatusCodes.OK); + + // resolve a created DID + response = await request.get(`/did/search/${(await response.json()).did}`, { + headers: { 'Content-Type': 'application/json' } + }); + expect(response.status()).toBe(StatusCodes.OK); + + const didDocument = (await response.json()).didDocument; + + // Check mandatory properties + expect(didDocument.id.split(":")[2]).toBe(NETWORK.TESTNET); + // TODO: Add check for checking ID is Indy Style identifier + expect(didDocument.verificationMethod[0].type).toBe(VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020); +}); + +test('[Positive] It can create DID with mandatory and optional properties (UUID style)', async ({ request }) => { + // send request to create key + let response = await request.post('/key/create', { + headers: { "Content-Type": "application/json" } + }); + expect(response.status()).toBe(StatusCodes.OK); + + const kid = (await response.json()).kid; + + // send request to create DID + response = await request.post(`/did/create`, { + data: `network=${NETWORK.TESTNET}&identifierFormatType=${ID_TYPE.BASE58BTC}&` + + `verificationMethodType=${VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020}&` + + `service=${JSON.stringify(buildSimpleService())}&key=${kid}&@context=${DEFAULT_CONTEXT}`, + headers: { 'Content-Type': 'application/x-www-form-urlencoded' } + }); + expect(response.status()).toBe(StatusCodes.OK); + + const body = await response.json(); + + // Check mandatory properties + expect(body.did.split(":")[2]).toBe(NETWORK.TESTNET); + // TODO: Add check for checking ID is UUID identifier + expect(body.controllerKeyId).toBe(kid); + + // resolve a created DID + const resolvedDid = await request.get(`/did/search/${body.did}`, { + headers: { 'Content-Type': 'application/json' } + }); + expect(resolvedDid.status()).toBe(StatusCodes.OK); + + const didDocument = (await resolvedDid.json()).didDocument; + + // check optional properties + expect(didDocument.verificationMethod[0].type).toBe(VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020); + expect(didDocument.service[0].id).toBe(`${body.did}#service-1`); + expect(didDocument.service[0].type).toBe("LinkedDomains"); + expect(didDocument.service[0].serviceEndpoint[0]).toBe("https://example.com"); +}); diff --git a/tests/helpers.ts b/tests/helpers.ts index 2f38e96c..7e96f6e3 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -137,3 +137,16 @@ export const buildSimpleIssueCredentialRequest = ( }, }; }; + +export const buildSimpleService = ( + idFragment = "service-1", + type = "LinkedDomains", + serviceEndpoint = ["https://example.com"] +) => { + return { + idFragment: idFragment, + type: type, + serviceEndpoint: serviceEndpoint + }; +}; + From 170eb2d4e3cbaa3d215b2794d1a44d3edcf6bd4e Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Wed, 27 Sep 2023 11:37:11 +0500 Subject: [PATCH 21/41] Add integration tests for testing JSON based request body in /did/create API. --- tests/did/positive.did.spec.ts | 106 +++++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 5 deletions(-) diff --git a/tests/did/positive.did.spec.ts b/tests/did/positive.did.spec.ts index 818d85e8..4d6b9813 100644 --- a/tests/did/positive.did.spec.ts +++ b/tests/did/positive.did.spec.ts @@ -2,10 +2,11 @@ import { test, expect } from '@playwright/test'; import { DEFAULT_CONTEXT, ID_TYPE, NETWORK, VERIFICATION_METHOD_TYPES } from '../constants'; import { StatusCodes } from 'http-status-codes'; import { buildSimpleService } from 'helpers'; +import { v4 } from 'uuid'; test.use({ storageState: 'playwright/.auth/user.json' }); -test('[Positive] It can create DID with mandatory properties (Indy style)', async ({ request }) => { +test('[Positive] It can create DID with mandatory properties (Form based + Indy style)', async ({ request }) => { // send request to create DID let response = await request.post(`/did/create`, { data: `network=${NETWORK.TESTNET}&identifierFormatType=${ID_TYPE.BASE58BTC}&` + @@ -28,7 +29,7 @@ test('[Positive] It can create DID with mandatory properties (Indy style)', asyn expect(didDocument.verificationMethod[0].type).toBe(VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020); }); -test('[Positive] It can create DID with mandatory and optional properties (UUID style)', async ({ request }) => { +test('[Positive] It can create DID with mandatory and optional properties (Form based + UUID style)', async ({ request }) => { // send request to create key let response = await request.post('/key/create', { headers: { "Content-Type": "application/json" } @@ -54,12 +55,12 @@ test('[Positive] It can create DID with mandatory and optional properties (UUID expect(body.controllerKeyId).toBe(kid); // resolve a created DID - const resolvedDid = await request.get(`/did/search/${body.did}`, { + response = await request.get(`/did/search/${body.did}`, { headers: { 'Content-Type': 'application/json' } }); - expect(resolvedDid.status()).toBe(StatusCodes.OK); + expect(response.status()).toBe(StatusCodes.OK); - const didDocument = (await resolvedDid.json()).didDocument; + const didDocument = (await response.json()).didDocument; // check optional properties expect(didDocument.verificationMethod[0].type).toBe(VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020); @@ -67,3 +68,98 @@ test('[Positive] It can create DID with mandatory and optional properties (UUID expect(didDocument.service[0].type).toBe("LinkedDomains"); expect(didDocument.service[0].serviceEndpoint[0]).toBe("https://example.com"); }); + +test('[Positive] It can create DID with mandatory properties (JSON based + Indy style)', async ({ request }) => { + // send request to create DID + // let response = await request.post('/did/create', { + // data: { + // network: NETWORK.TESTNET, + // identifierFormatType: ID_TYPE.BASE58BTC, + // options: { + // verificationMethodType: VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020 + // }, + // didDocument: { + // id: "", // how to generate Indy style identifier? + // controller: [{ + // // your did + // }], + // authentication: [{ + // // your did+#key-1 + // }] + // } + // }, + // headers: { "Content-Type": "application/json" } + // }); + // expect(response.status()).toBe(StatusCodes.OK); + + // // resolve a created DID + // response = await request.get(`/did/search/${(await response.json()).did}`, { + // headers: { 'Content-Type': 'application/json' } + // }); + // expect(response.status()).toBe(StatusCodes.OK); + + // const didDocument = (await response.json()).didDocument; + + // // Check mandatory properties + // expect(didDocument.id.split(":")[2]).toBe(NETWORK.TESTNET); + // // TODO: Add check for checking ID is Indy Style identifier + // expect(didDocument.verificationMethod[0].type).toBe(VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020); +}); + +test('[Positive] It can create DID with mandatory and optional properties (JSON based + UUID style)', async ({ request }) => { + // send request to create key + let response = await request.post('/key/create', { + headers: { "Content-Type": "application/json" } + }); + expect(response.status()).toBe(StatusCodes.OK); + + const kid = (await response.json()).kid; + + const did = `did:cheqd:testnet:${v4()}`; + response = await request.post('/did/create', { + data: { + network: NETWORK.TESTNET, + identifierFormatType: ID_TYPE.UUID, + assertionMethod: true, + options: { + verificationMethodType: VERIFICATION_METHOD_TYPES.JsonWebKey2020, + key: kid + }, + didDocument: { + "@context": [ + "https://www.w3.org/ns/did/v1" + ], + id: did, + controller: [ + did + ], + authentication: [ + `${did}#key-1` + ], + service: [{ + id: `${did}#service-1`, + type: "LinkedDomains", + serviceEndpoint: [ + "https://example.com" + ] + }] + } + }, + headers: { "Content-Type": "application/json" } + }); + expect(response.status()).toBe(StatusCodes.OK); + + // resolve a created DID + response = await request.get(`/did/search/${(did)}`, { + headers: { 'Content-Type': 'application/json' } + }); + expect(response.status()).toBe(StatusCodes.OK); + + const didDocument = (await response.json()).didDocument; + + // check optional properties + expect(didDocument.verificationMethod[0].type).toBe(VERIFICATION_METHOD_TYPES.JsonWebKey2020); + expect(didDocument.service[0].id).toBe(`${did}#service-1`); + expect(didDocument.service[0].type).toBe("LinkedDomains"); + expect(didDocument.service[0].serviceEndpoint[0]).toBe("https://example.com"); +}); From 7c061c56d0cb19cf04d6df06509af828d38b1a3e Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Wed, 27 Sep 2023 18:02:14 +0500 Subject: [PATCH 22/41] Fix problem with handling multiple services in did/create API. --- src/controllers/issuer.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/controllers/issuer.ts b/src/controllers/issuer.ts index 4e3ed64e..7f48451e 100644 --- a/src/controllers/issuer.ts +++ b/src/controllers/issuer.ts @@ -271,17 +271,27 @@ export class IssuerController { }); if (typeof request.body['@context'] === 'string') { - didDocument['@context'] = [request.body['@context']] ; + didDocument['@context'] = [request.body['@context']]; } if (service) { - didDocument.service = [ - { + if (Array.isArray(service)) { + const services = JSON.parse(`[${service.toString()}]`); + didDocument.service = []; + for (const service of services) { + didDocument.service.push({ + id: `${didDocument.id}#${service.idFragment}`, + type: service.type, + serviceEndpoint: service.serviceEndpoint, + }) + } + } else { + didDocument.service = [{ id: `${didDocument.id}#${service.idFragment}`, type: service.type, serviceEndpoint: service.serviceEndpoint, - }, - ]; + }]; + } } } else { return response.status(StatusCodes.BAD_REQUEST).json({ From bbd3067aae9fb515a02cce23a453cb0099e8c17b Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Wed, 27 Sep 2023 18:11:51 +0500 Subject: [PATCH 23/41] Fix problem with handling multiple "context" in /did/create API. --- src/controllers/issuer.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/controllers/issuer.ts b/src/controllers/issuer.ts index 7f48451e..c5065163 100644 --- a/src/controllers/issuer.ts +++ b/src/controllers/issuer.ts @@ -270,8 +270,11 @@ export class IssuerController { publicKey: publicKeyHex, }); + if (Array.isArray(request.body['@context'])) { + didDocument['@context'] = request.body['@context']; + } if (typeof request.body['@context'] === 'string') { - didDocument['@context'] = [request.body['@context']]; + didDocument['@context'] = [request.body['@context']] ; } if (service) { From 162c0a1ba4fc3a5ed16631b933e7d5c4b50f1c17 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Wed, 27 Sep 2023 18:17:31 +0500 Subject: [PATCH 24/41] Remove indirect imports in issuer.ts. --- src/controllers/issuer.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/controllers/issuer.ts b/src/controllers/issuer.ts index c5065163..441ddd3f 100644 --- a/src/controllers/issuer.ts +++ b/src/controllers/issuer.ts @@ -1,9 +1,8 @@ import type { Request, Response } from 'express'; import { check, param, validationResult } from 'express-validator'; import { fromString, toString } from 'uint8arrays'; -import type { DIDDocument, Service, VerificationMethod } from 'did-resolver'; import { v4 } from 'uuid'; -import { CheqdNetwork, MethodSpecificIdAlgo, VerificationMethods, createDidVerificationMethod } from '@cheqd/sdk'; +import { CheqdNetwork, DIDDocument, MethodSpecificIdAlgo, Service, VerificationMethod, VerificationMethods, createDidVerificationMethod } from '@cheqd/sdk'; import type { MsgCreateResourcePayload } from '@cheqd/ts-proto/cheqd/resource/v2/index.js'; import { StatusCodes } from 'http-status-codes'; import { IdentityServiceStrategySetup } from '../services/identity/index.js'; From 8324e77d9a03835407df9d2f709294c5214e3c8d Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Wed, 27 Sep 2023 18:21:04 +0500 Subject: [PATCH 25/41] Remove an unused cast. --- src/controllers/issuer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/issuer.ts b/src/controllers/issuer.ts index 441ddd3f..7e98b80b 100644 --- a/src/controllers/issuer.ts +++ b/src/controllers/issuer.ts @@ -264,7 +264,7 @@ export class IssuerController { didDocument = generateDidDoc({ verificationMethod: verificationMethodType, verificationMethodId: 'key-1', - methodSpecificIdAlgo: (identifierFormatType as MethodSpecificIdAlgo) || MethodSpecificIdAlgo.Uuid, + methodSpecificIdAlgo: identifierFormatType || MethodSpecificIdAlgo.Uuid, network, publicKey: publicKeyHex, }); From f98cc77469baa47d9ca9d74c45d777815f869d31 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Thu, 28 Sep 2023 11:34:08 +0500 Subject: [PATCH 26/41] Add negative integration tests for testing /did/create API. --- tests/constants.ts | 6 ++ tests/did/negative.did.spec.ts | 169 +++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 tests/did/negative.did.spec.ts diff --git a/tests/constants.ts b/tests/constants.ts index 4d328caf..b5debb99 100644 --- a/tests/constants.ts +++ b/tests/constants.ts @@ -16,6 +16,12 @@ export const DEFAULT_DOES_NOT_HAVE_PERMISSIONS = export const DEFAULT_CONTEXT="https://www.w3.org/ns/did/v1" +export const NOT_EXISTENT_KEY = "88888888888895e01f3d98fcec8ccc7861a030b317d4326b0e48a88888888888" +export const NOT_SUPPORTED_VERIFICATION_METHOD_TYPE = "not_supported_vm_type" + +export const INVALID_ID = "invalid_id"; +export const INVALID_DID = "invalid_did"; + export enum NETWORK { MAINNET = "mainnet", TESTNET = "testnet" diff --git a/tests/did/negative.did.spec.ts b/tests/did/negative.did.spec.ts new file mode 100644 index 00000000..9f36534b --- /dev/null +++ b/tests/did/negative.did.spec.ts @@ -0,0 +1,169 @@ +import { test, expect } from '@playwright/test'; +import { ID_TYPE, INVALID_DID, INVALID_ID, NETWORK, NOT_EXISTENT_KEY, NOT_SUPPORTED_VERIFICATION_METHOD_TYPE, VERIFICATION_METHOD_TYPES } from '../constants'; +import { StatusCodes } from 'http-status-codes'; +import { v4 } from 'uuid'; + +test.use({ storageState: 'playwright/.auth/user.json' }); + +test('[Negative] It cannot create DID with missed verificationMethodType field in request body (Form based)', async ({ request }) => { + const response = await request.post(`/did/create`, { + data: `network=${NETWORK.TESTNET}&identifierFormatType=${ID_TYPE.BASE58BTC}&]`, + headers: { "Content-Type": "application/x-www-form-urlencoded" } + }); + expect(response.status()).toBe(StatusCodes.BAD_REQUEST); + // TODO: change error message + expect(await response.text()).toEqual(expect.stringContaining("Provide a DID Document or the network type to create a DID")); +}); + +test('[Negative] It cannot create DID with not existent key in request body (Form based)', async ({ request }) => { + const response = await request.post(`/did/create`, { + data: `network=${NETWORK.TESTNET}&identifierFormatType=${ID_TYPE.BASE58BTC}&]` + + `verificationMethodType=${VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020}` + + `key=${NOT_EXISTENT_KEY}`, + headers: { "Content-Type": "application/x-www-form-urlencoded" } + }); + expect(response.status()).toBe(StatusCodes.BAD_REQUEST); + // TODO: change error message + expect(await response.text()).toEqual(expect.stringContaining("Provide a DID Document or the network type to create a DID")); +}); + +test('[Negative] It cannot create DID with not existent key in request body (JSON based)', async ({ request }) => { + const did = `did:cheqd:testnet:${v4()}`; + const response = await request.post('/did/create', { + data: { + network: NETWORK.TESTNET, + identifierFormatType: ID_TYPE.UUID, + options: { + verificationMethodType: VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020, + key: NOT_EXISTENT_KEY + }, + didDocument: { + id: did, + controller: [ + did + ], + authentication: [ + `${did}#key-1` + ] + } + }, + headers: { "Content-Type": "application/json" } + }); + // TODO: change status code to 404 + expect(response.status()).toBe(StatusCodes.INTERNAL_SERVER_ERROR); + expect(await response.text()).toEqual(expect.stringContaining("Key not found")); +}); + +test('[Negative] It cannot create DID with an invalid VerificationMethodType in request body (JSON based)', async ({ request }) => { + const did = `did:cheqd:testnet:${v4()}`; + const response = await request.post('/did/create', { + data: { + network: NETWORK.TESTNET, + identifierFormatType: ID_TYPE.UUID, + options: { + verificationMethodType: NOT_SUPPORTED_VERIFICATION_METHOD_TYPE + }, + didDocument: { + id: did, + controller: [ + did + ], + authentication: [ + `${did}#key-1` + ] + } + }, + headers: { "Content-Type": "application/json" } + }); + // TODO: change status code + expect(response.status()).toBe(StatusCodes.INTERNAL_SERVER_ERROR); + expect(await response.text()).toEqual(expect.stringContaining("Unsupported verificationMethod type")); +}); + +test('[Negative] It cannot create DID with an invalid length of id in DIDDocument in request body (JSON based)', async ({ request }) => { + const invalidDidLength = `did:cheqd:testnet:${INVALID_ID}`; + const response = await request.post('/did/create', { + data: { + network: NETWORK.TESTNET, + identifierFormatType: ID_TYPE.UUID, + options: { + verificationMethodType: VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2018 + }, + didDocument: { + id: invalidDidLength, + controller: [ + invalidDidLength + ], + authentication: [ + `${invalidDidLength}#key-1` + ] + } + }, + headers: { "Content-Type": "application/json" } + }); + // change status code + expect(response.status()).toBe(StatusCodes.INTERNAL_SERVER_ERROR); + expect(await response.text()).toEqual(expect.stringContaining("unique id should be one of: 16 bytes of decoded base58 string or UUID")); +}); + +test('[Negative] It cannot create DID with an invalid id format in DIDDocument in request body (JSON based)', async ({ request }) => { + const response = await request.post('/did/create', { + data: { + network: NETWORK.TESTNET, + identifierFormatType: ID_TYPE.UUID, + options: { + verificationMethodType: VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2018 + }, + didDocument: { + id: INVALID_DID, + controller: [ + INVALID_DID + ], + authentication: [ + `${INVALID_DID}#key-1` + ] + } + }, + headers: { "Content-Type": "application/json" } + }); + // TODO: change status code + expect(response.status()).toBe(StatusCodes.INTERNAL_SERVER_ERROR); + expect(await response.text()).toEqual(expect.stringContaining("unable to split did into method, namespace and id")); +}); + +test('[Negative] It cannot create DID without VerificationMethodType in request body (JSON based)', async ({ request }) => { + const response = await request.post('/did/create', { + data: { + network: NETWORK.TESTNET, + identifierFormatType: ID_TYPE.UUID, + didDocument: { + id: INVALID_DID, + controller: [ + INVALID_DID + ], + authentication: [ + `${INVALID_DID}#key-1` + ] + } + }, + headers: { "Content-Type": "application/json" } + }); + expect(response.status()).toBe(StatusCodes.BAD_REQUEST); + // TODO: Change error message + expect(await response.text()).toEqual(expect.stringContaining("Provide options section to create a DID")); +}); + +test('[Negative] It cannot create DID without DidDocument in request body (JSON based)', async ({ request }) => { + const response = await request.post('/did/create', { + data: { + network: NETWORK.TESTNET, + identifierFormatType: ID_TYPE.UUID, + options: { + verificationMethodType: VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020 + }, + }, + headers: { "Content-Type": "application/json" } + }); + expect(response.status()).toBe(StatusCodes.BAD_REQUEST); + expect(await response.text()).toEqual(expect.stringContaining("Provide a DID Document or the network type to create a DID")); +}); From 9765d7e35f73ad074377b04b9c998c0837ff0832 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Thu, 28 Sep 2023 11:45:19 +0500 Subject: [PATCH 27/41] Re-arch integration tests for did/create API. --- tests/did/did.spec.ts | 41 ------------------------- tests/did/negative.did.spec.ts | 56 +++++++++++++++++++++++++++++++--- tests/did/positive.did.spec.ts | 11 +++++-- 3 files changed, 59 insertions(+), 49 deletions(-) delete mode 100644 tests/did/did.spec.ts diff --git a/tests/did/did.spec.ts b/tests/did/did.spec.ts deleted file mode 100644 index 3d3e1cec..00000000 --- a/tests/did/did.spec.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { test, expect } from '@playwright/test'; -import { StatusCodes } from 'http-status-codes'; -import { DEFAULT_DOES_NOT_HAVE_PERMISSIONS, DEFAULT_MAINNET_DID } from '../constants'; -import * as fs from 'fs'; - -test.use({ storageState: 'playwright/.auth/user.json' }); - -const PAYLOADS_BASE_PATH = './tests/payloads/did'; - -// Negative tests. All of this tests should return 403 Forbidden -// cause here the user tries to make mainnet operations with testnet role -test('Create DID for user with testnet role but network is mainnet', async ({ request }) => { - const response = await request.post(`/did/create`, { - data: JSON.parse(fs.readFileSync(`${PAYLOADS_BASE_PATH}/did-create-without-permissions.json`, 'utf-8')), - headers: { - 'Content-Type': 'application/json', - }, - }); - expect(response).not.toBeOK(); - expect(response.status()).toBe(StatusCodes.FORBIDDEN); - expect(await response.text()).toEqual(expect.stringContaining(DEFAULT_DOES_NOT_HAVE_PERMISSIONS)); -}); - -test('Update DID for user with testnet role but network is mainnet', async ({ request }) => { - const response = await request.post(`/did/update`, { - data: JSON.parse(fs.readFileSync(`${PAYLOADS_BASE_PATH}/did-update-without-permissions.json`, 'utf-8')), - headers: { - 'Content-Type': 'application/json', - }, - }); - expect(response).not.toBeOK(); - expect(response.status()).toBe(StatusCodes.FORBIDDEN); - expect(await response.text()).toEqual(expect.stringContaining(DEFAULT_DOES_NOT_HAVE_PERMISSIONS)); -}); - -test('Deactivate DID for user with testnet role but network is mainnet', async ({ request }) => { - const response = await request.post(`/did/deactivate/${DEFAULT_MAINNET_DID}`, {}); - expect(response).not.toBeOK(); - expect(response.status()).toBe(StatusCodes.FORBIDDEN); - expect(await response.text()).toEqual(expect.stringContaining(DEFAULT_DOES_NOT_HAVE_PERMISSIONS)); -}); diff --git a/tests/did/negative.did.spec.ts b/tests/did/negative.did.spec.ts index 9f36534b..636abe4a 100644 --- a/tests/did/negative.did.spec.ts +++ b/tests/did/negative.did.spec.ts @@ -1,7 +1,20 @@ +import { + NETWORK, + ID_TYPE, + INVALID_ID, + INVALID_DID, + NOT_EXISTENT_KEY, + DEFAULT_MAINNET_DID, + VERIFICATION_METHOD_TYPES, + DEFAULT_DOES_NOT_HAVE_PERMISSIONS, + NOT_SUPPORTED_VERIFICATION_METHOD_TYPE +} from '../constants'; +import * as fs from 'fs'; +import { v4 } from 'uuid'; import { test, expect } from '@playwright/test'; -import { ID_TYPE, INVALID_DID, INVALID_ID, NETWORK, NOT_EXISTENT_KEY, NOT_SUPPORTED_VERIFICATION_METHOD_TYPE, VERIFICATION_METHOD_TYPES } from '../constants'; import { StatusCodes } from 'http-status-codes'; -import { v4 } from 'uuid'; + +const PAYLOADS_BASE_PATH = './tests/payloads/did'; test.use({ storageState: 'playwright/.auth/user.json' }); @@ -17,9 +30,9 @@ test('[Negative] It cannot create DID with missed verificationMethodType field i test('[Negative] It cannot create DID with not existent key in request body (Form based)', async ({ request }) => { const response = await request.post(`/did/create`, { - data: `network=${NETWORK.TESTNET}&identifierFormatType=${ID_TYPE.BASE58BTC}&]` + - `verificationMethodType=${VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020}` + - `key=${NOT_EXISTENT_KEY}`, + data: `network=${NETWORK.TESTNET}&identifierFormatType=${ID_TYPE.BASE58BTC}&]` + + `verificationMethodType=${VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020}` + + `key=${NOT_EXISTENT_KEY}`, headers: { "Content-Type": "application/x-www-form-urlencoded" } }); expect(response.status()).toBe(StatusCodes.BAD_REQUEST); @@ -167,3 +180,36 @@ test('[Negative] It cannot create DID without DidDocument in request body (JSON expect(response.status()).toBe(StatusCodes.BAD_REQUEST); expect(await response.text()).toEqual(expect.stringContaining("Provide a DID Document or the network type to create a DID")); }); + +// Negative tests. All of this tests should return 403 Forbidden +// cause here the user tries to make mainnet operations with testnet role +test('Create DID for user with testnet role but network is mainnet', async ({ request }) => { + const response = await request.post(`/did/create`, { + data: JSON.parse(fs.readFileSync(`${PAYLOADS_BASE_PATH}/did-create-without-permissions.json`, 'utf-8')), + headers: { + 'Content-Type': 'application/json', + }, + }); + expect(response).not.toBeOK(); + expect(response.status()).toBe(StatusCodes.FORBIDDEN); + expect(await response.text()).toEqual(expect.stringContaining(DEFAULT_DOES_NOT_HAVE_PERMISSIONS)); +}); + +test('Update DID for user with testnet role but network is mainnet', async ({ request }) => { + const response = await request.post(`/did/update`, { + data: JSON.parse(fs.readFileSync(`${PAYLOADS_BASE_PATH}/did-update-without-permissions.json`, 'utf-8')), + headers: { + 'Content-Type': 'application/json', + }, + }); + expect(response).not.toBeOK(); + expect(response.status()).toBe(StatusCodes.FORBIDDEN); + expect(await response.text()).toEqual(expect.stringContaining(DEFAULT_DOES_NOT_HAVE_PERMISSIONS)); +}); + +test('Deactivate DID for user with testnet role but network is mainnet', async ({ request }) => { + const response = await request.post(`/did/deactivate/${DEFAULT_MAINNET_DID}`, {}); + expect(response).not.toBeOK(); + expect(response.status()).toBe(StatusCodes.FORBIDDEN); + expect(await response.text()).toEqual(expect.stringContaining(DEFAULT_DOES_NOT_HAVE_PERMISSIONS)); +}); diff --git a/tests/did/positive.did.spec.ts b/tests/did/positive.did.spec.ts index 4d6b9813..7366b5fa 100644 --- a/tests/did/positive.did.spec.ts +++ b/tests/did/positive.did.spec.ts @@ -1,8 +1,13 @@ +import { + ID_TYPE, + NETWORK, + DEFAULT_CONTEXT, + VERIFICATION_METHOD_TYPES +} from '../constants'; +import { v4 } from 'uuid'; +import { buildSimpleService } from 'helpers'; import { test, expect } from '@playwright/test'; -import { DEFAULT_CONTEXT, ID_TYPE, NETWORK, VERIFICATION_METHOD_TYPES } from '../constants'; import { StatusCodes } from 'http-status-codes'; -import { buildSimpleService } from 'helpers'; -import { v4 } from 'uuid'; test.use({ storageState: 'playwright/.auth/user.json' }); From 791171719e91724952cb8022d8ab111265fa70e5 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Thu, 28 Sep 2023 13:55:31 +0500 Subject: [PATCH 28/41] Refactor positive integration tests for /did/create API. --- tests/did/positive.did.spec.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/did/positive.did.spec.ts b/tests/did/positive.did.spec.ts index 7366b5fa..45958856 100644 --- a/tests/did/positive.did.spec.ts +++ b/tests/did/positive.did.spec.ts @@ -78,19 +78,17 @@ test('[Positive] It can create DID with mandatory properties (JSON based + Indy // send request to create DID // let response = await request.post('/did/create', { // data: { - // network: NETWORK.TESTNET, - // identifierFormatType: ID_TYPE.BASE58BTC, // options: { // verificationMethodType: VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020 // }, // didDocument: { // id: "", // how to generate Indy style identifier? - // controller: [{ + // controller: [ // // your did - // }], - // authentication: [{ + // ], + // authentication: [ // // your did+#key-1 - // }] + // ] // } // }, // headers: { "Content-Type": "application/json" } From 38f72befd6075e5bd280742c274eb75262d12c99 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Thu, 28 Sep 2023 16:09:50 +0500 Subject: [PATCH 29/41] Update positive integration tests. --- tests/did/positive.did.spec.ts | 71 +++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/tests/did/positive.did.spec.ts b/tests/did/positive.did.spec.ts index 45958856..47c87d77 100644 --- a/tests/did/positive.did.spec.ts +++ b/tests/did/positive.did.spec.ts @@ -8,6 +8,7 @@ import { v4 } from 'uuid'; import { buildSimpleService } from 'helpers'; import { test, expect } from '@playwright/test'; import { StatusCodes } from 'http-status-codes'; +import { MethodSpecificIdAlgo, createVerificationKeys } from '@cheqd/sdk'; test.use({ storageState: 'playwright/.auth/user.json' }); @@ -75,38 +76,46 @@ test('[Positive] It can create DID with mandatory and optional properties (Form }); test('[Positive] It can create DID with mandatory properties (JSON based + Indy style)', async ({ request }) => { + // send request to create key + let response = await request.post('/key/create', { + headers: { "Content-Type": "application/json" } + }); + expect(response.status()).toBe(StatusCodes.OK); + + const did = createVerificationKeys((await response.json()).kid, MethodSpecificIdAlgo.Base58, "key-1").didUrl; + // send request to create DID - // let response = await request.post('/did/create', { - // data: { - // options: { - // verificationMethodType: VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020 - // }, - // didDocument: { - // id: "", // how to generate Indy style identifier? - // controller: [ - // // your did - // ], - // authentication: [ - // // your did+#key-1 - // ] - // } - // }, - // headers: { "Content-Type": "application/json" } - // }); - // expect(response.status()).toBe(StatusCodes.OK); - - // // resolve a created DID - // response = await request.get(`/did/search/${(await response.json()).did}`, { - // headers: { 'Content-Type': 'application/json' } - // }); - // expect(response.status()).toBe(StatusCodes.OK); - - // const didDocument = (await response.json()).didDocument; - - // // Check mandatory properties - // expect(didDocument.id.split(":")[2]).toBe(NETWORK.TESTNET); - // // TODO: Add check for checking ID is Indy Style identifier - // expect(didDocument.verificationMethod[0].type).toBe(VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020); + response = await request.post('/did/create', { + data: { + options: { + verificationMethodType: VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020 + }, + didDocument: { + id: did, + controller: [ + did + ], + authentication: [ + `${did}#key-1` + ] + } + }, + headers: { "Content-Type": "application/json" } + }); + expect(response.status()).toBe(StatusCodes.OK); + + // resolve a created DID + response = await request.get(`/did/search/${(await response.json()).did}`, { + headers: { 'Content-Type': 'application/json' } + }); + expect(response.status()).toBe(StatusCodes.OK); + + const didDocument = (await response.json()).didDocument; + + // Check mandatory properties + expect(didDocument.id.split(":")[2]).toBe(NETWORK.TESTNET); + // TODO: Add check for checking ID is Indy Style identifier + expect(didDocument.verificationMethod[0].type).toBe(VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020); }); test('[Positive] It can create DID with mandatory and optional properties (JSON based + UUID style)', async ({ request }) => { From 1f6d1ef6cd6030464b0091ede252280209c01daf Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Thu, 28 Sep 2023 16:30:12 +0500 Subject: [PATCH 30/41] Re-arch integration tests for /did/create API. --- ...ve.did.spec.ts => create.negative.spec.ts} | 26 ++----------------- ...ve.did.spec.ts => create.positive.spec.ts} | 0 tests/did/deactivate.negative.spec.ts | 12 +++++++++ tests/did/update.negative.spec.ts | 20 ++++++++++++++ 4 files changed, 34 insertions(+), 24 deletions(-) rename tests/did/{negative.did.spec.ts => create.negative.spec.ts} (86%) rename tests/did/{positive.did.spec.ts => create.positive.spec.ts} (100%) create mode 100644 tests/did/deactivate.negative.spec.ts create mode 100644 tests/did/update.negative.spec.ts diff --git a/tests/did/negative.did.spec.ts b/tests/did/create.negative.spec.ts similarity index 86% rename from tests/did/negative.did.spec.ts rename to tests/did/create.negative.spec.ts index 636abe4a..a89aeef4 100644 --- a/tests/did/negative.did.spec.ts +++ b/tests/did/create.negative.spec.ts @@ -4,7 +4,6 @@ import { INVALID_ID, INVALID_DID, NOT_EXISTENT_KEY, - DEFAULT_MAINNET_DID, VERIFICATION_METHOD_TYPES, DEFAULT_DOES_NOT_HAVE_PERMISSIONS, NOT_SUPPORTED_VERIFICATION_METHOD_TYPE @@ -20,7 +19,7 @@ test.use({ storageState: 'playwright/.auth/user.json' }); test('[Negative] It cannot create DID with missed verificationMethodType field in request body (Form based)', async ({ request }) => { const response = await request.post(`/did/create`, { - data: `network=${NETWORK.TESTNET}&identifierFormatType=${ID_TYPE.BASE58BTC}&]`, + data: `network=${NETWORK.TESTNET}&identifierFormatType=${ID_TYPE.BASE58BTC}`, headers: { "Content-Type": "application/x-www-form-urlencoded" } }); expect(response.status()).toBe(StatusCodes.BAD_REQUEST); @@ -181,9 +180,7 @@ test('[Negative] It cannot create DID without DidDocument in request body (JSON expect(await response.text()).toEqual(expect.stringContaining("Provide a DID Document or the network type to create a DID")); }); -// Negative tests. All of this tests should return 403 Forbidden -// cause here the user tries to make mainnet operations with testnet role -test('Create DID for user with testnet role but network is mainnet', async ({ request }) => { +test('[Negative] It cannot create DID in mainnet network for user with testnet role', async ({ request }) => { const response = await request.post(`/did/create`, { data: JSON.parse(fs.readFileSync(`${PAYLOADS_BASE_PATH}/did-create-without-permissions.json`, 'utf-8')), headers: { @@ -194,22 +191,3 @@ test('Create DID for user with testnet role but network is mainnet', async ({ re expect(response.status()).toBe(StatusCodes.FORBIDDEN); expect(await response.text()).toEqual(expect.stringContaining(DEFAULT_DOES_NOT_HAVE_PERMISSIONS)); }); - -test('Update DID for user with testnet role but network is mainnet', async ({ request }) => { - const response = await request.post(`/did/update`, { - data: JSON.parse(fs.readFileSync(`${PAYLOADS_BASE_PATH}/did-update-without-permissions.json`, 'utf-8')), - headers: { - 'Content-Type': 'application/json', - }, - }); - expect(response).not.toBeOK(); - expect(response.status()).toBe(StatusCodes.FORBIDDEN); - expect(await response.text()).toEqual(expect.stringContaining(DEFAULT_DOES_NOT_HAVE_PERMISSIONS)); -}); - -test('Deactivate DID for user with testnet role but network is mainnet', async ({ request }) => { - const response = await request.post(`/did/deactivate/${DEFAULT_MAINNET_DID}`, {}); - expect(response).not.toBeOK(); - expect(response.status()).toBe(StatusCodes.FORBIDDEN); - expect(await response.text()).toEqual(expect.stringContaining(DEFAULT_DOES_NOT_HAVE_PERMISSIONS)); -}); diff --git a/tests/did/positive.did.spec.ts b/tests/did/create.positive.spec.ts similarity index 100% rename from tests/did/positive.did.spec.ts rename to tests/did/create.positive.spec.ts diff --git a/tests/did/deactivate.negative.spec.ts b/tests/did/deactivate.negative.spec.ts new file mode 100644 index 00000000..11ab2240 --- /dev/null +++ b/tests/did/deactivate.negative.spec.ts @@ -0,0 +1,12 @@ +import { test, expect } from '@playwright/test'; +import { StatusCodes } from 'http-status-codes'; +import { DEFAULT_DOES_NOT_HAVE_PERMISSIONS, DEFAULT_MAINNET_DID } from '../constants'; + +test.use({ storageState: 'playwright/.auth/user.json' }); + +test('[Negative] It cannot deactivated DID in mainnet network for user with testnet role', async ({ request }) => { + const response = await request.post(`/did/deactivate/${DEFAULT_MAINNET_DID}`, {}); + expect(response).not.toBeOK(); + expect(response.status()).toBe(StatusCodes.FORBIDDEN); + expect(await response.text()).toEqual(expect.stringContaining(DEFAULT_DOES_NOT_HAVE_PERMISSIONS)); +}); diff --git a/tests/did/update.negative.spec.ts b/tests/did/update.negative.spec.ts new file mode 100644 index 00000000..9e7f650a --- /dev/null +++ b/tests/did/update.negative.spec.ts @@ -0,0 +1,20 @@ +import * as fs from 'fs'; +import { test, expect } from '@playwright/test'; +import { StatusCodes } from 'http-status-codes'; +import { DEFAULT_DOES_NOT_HAVE_PERMISSIONS } from '../constants'; + +const PAYLOADS_BASE_PATH = './tests/payloads/did'; + +test.use({ storageState: 'playwright/.auth/user.json' }); + +test('[Negative] It cannot update DID in mainnet network for user with testnet role', async ({ request }) => { + const response = await request.post(`/did/update`, { + data: JSON.parse(fs.readFileSync(`${PAYLOADS_BASE_PATH}/did-update-without-permissions.json`, 'utf-8')), + headers: { + 'Content-Type': 'application/json', + }, + }); + expect(response).not.toBeOK(); + expect(response.status()).toBe(StatusCodes.FORBIDDEN); + expect(await response.text()).toEqual(expect.stringContaining(DEFAULT_DOES_NOT_HAVE_PERMISSIONS)); +}); From c0f5fc9dedeae20682cf1f468816b90bddeba254 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Fri, 29 Sep 2023 11:56:02 +0500 Subject: [PATCH 31/41] Update negative integration tests. --- src/controllers/issuer.ts | 35 +++++++++++++++++++++---------- tests/did/create.negative.spec.ts | 15 ++++--------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/controllers/issuer.ts b/src/controllers/issuer.ts index 7e98b80b..a2ebccc0 100644 --- a/src/controllers/issuer.ts +++ b/src/controllers/issuer.ts @@ -239,6 +239,13 @@ export class IssuerController { if (request.body.didDocument) { didDocument = request.body.didDocument; if (options) { + if (options.key) { + if (!(await new IdentityServiceStrategySetup(response.locals.customerId).agent.getKey(key))) { + return response.status(StatusCodes.NOT_FOUND).json({ + error: 'Provide an existing key' + }); + } + } const publicKeyHex = options.key || (await new IdentityServiceStrategySetup(response.locals.customerId).agent.createKey( 'Ed25519', response.locals.customerId @@ -273,20 +280,26 @@ export class IssuerController { didDocument['@context'] = request.body['@context']; } if (typeof request.body['@context'] === 'string') { - didDocument['@context'] = [request.body['@context']] ; + didDocument['@context'] = [request.body['@context']]; } if (service) { if (Array.isArray(service)) { - const services = JSON.parse(`[${service.toString()}]`); - didDocument.service = []; - for (const service of services) { - didDocument.service.push({ - id: `${didDocument.id}#${service.idFragment}`, - type: service.type, - serviceEndpoint: service.serviceEndpoint, - }) - } + try { + const services = JSON.parse(`[${service.toString()}]`); + didDocument.service = []; + for (const service of services) { + didDocument.service.push({ + id: `${didDocument.id}#${service.idFragment}`, + type: service.type, + serviceEndpoint: service.serviceEndpoint, + }) + } + } catch (e) { + return response.status(StatusCodes.BAD_REQUEST).json({ + error: 'Provide the correct service section to create a DID', + }); + }; } else { didDocument.service = [{ id: `${didDocument.id}#${service.idFragment}`, @@ -297,7 +310,7 @@ export class IssuerController { } } else { return response.status(StatusCodes.BAD_REQUEST).json({ - error: 'Provide a DID Document or the network type to create a DID', + error: 'Provide a DID Document or the VerificationMethodType to create a DID', }); } diff --git a/tests/did/create.negative.spec.ts b/tests/did/create.negative.spec.ts index a89aeef4..395f422d 100644 --- a/tests/did/create.negative.spec.ts +++ b/tests/did/create.negative.spec.ts @@ -23,8 +23,7 @@ test('[Negative] It cannot create DID with missed verificationMethodType field i headers: { "Content-Type": "application/x-www-form-urlencoded" } }); expect(response.status()).toBe(StatusCodes.BAD_REQUEST); - // TODO: change error message - expect(await response.text()).toEqual(expect.stringContaining("Provide a DID Document or the network type to create a DID")); + expect(await response.text()).toEqual(expect.stringContaining("Provide a DID Document or the VerificationMethodType to create a DID")); }); test('[Negative] It cannot create DID with not existent key in request body (Form based)', async ({ request }) => { @@ -35,8 +34,7 @@ test('[Negative] It cannot create DID with not existent key in request body (For headers: { "Content-Type": "application/x-www-form-urlencoded" } }); expect(response.status()).toBe(StatusCodes.BAD_REQUEST); - // TODO: change error message - expect(await response.text()).toEqual(expect.stringContaining("Provide a DID Document or the network type to create a DID")); + expect(await response.text()).toEqual(expect.stringContaining("Provide a DID Document or the VerificationMethodType to create a DID")); }); test('[Negative] It cannot create DID with not existent key in request body (JSON based)', async ({ request }) => { @@ -61,9 +59,8 @@ test('[Negative] It cannot create DID with not existent key in request body (JSO }, headers: { "Content-Type": "application/json" } }); - // TODO: change status code to 404 - expect(response.status()).toBe(StatusCodes.INTERNAL_SERVER_ERROR); - expect(await response.text()).toEqual(expect.stringContaining("Key not found")); + expect(response.status()).toBe(StatusCodes.NOT_FOUND); + expect(await response.text()).toEqual(expect.stringContaining("Provide an existing key")); }); test('[Negative] It cannot create DID with an invalid VerificationMethodType in request body (JSON based)', async ({ request }) => { @@ -87,7 +84,6 @@ test('[Negative] It cannot create DID with an invalid VerificationMethodType in }, headers: { "Content-Type": "application/json" } }); - // TODO: change status code expect(response.status()).toBe(StatusCodes.INTERNAL_SERVER_ERROR); expect(await response.text()).toEqual(expect.stringContaining("Unsupported verificationMethod type")); }); @@ -113,7 +109,6 @@ test('[Negative] It cannot create DID with an invalid length of id in DIDDocumen }, headers: { "Content-Type": "application/json" } }); - // change status code expect(response.status()).toBe(StatusCodes.INTERNAL_SERVER_ERROR); expect(await response.text()).toEqual(expect.stringContaining("unique id should be one of: 16 bytes of decoded base58 string or UUID")); }); @@ -138,7 +133,6 @@ test('[Negative] It cannot create DID with an invalid id format in DIDDocument i }, headers: { "Content-Type": "application/json" } }); - // TODO: change status code expect(response.status()).toBe(StatusCodes.INTERNAL_SERVER_ERROR); expect(await response.text()).toEqual(expect.stringContaining("unable to split did into method, namespace and id")); }); @@ -161,7 +155,6 @@ test('[Negative] It cannot create DID without VerificationMethodType in request headers: { "Content-Type": "application/json" } }); expect(response.status()).toBe(StatusCodes.BAD_REQUEST); - // TODO: Change error message expect(await response.text()).toEqual(expect.stringContaining("Provide options section to create a DID")); }); From ebb999c674d2aa2f89dcf63d728ad29917de7526 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Fri, 29 Sep 2023 12:05:09 +0500 Subject: [PATCH 32/41] Update integration tests. --- tests/did/create.negative.spec.ts | 2 +- tests/did/create.positive.spec.ts | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/did/create.negative.spec.ts b/tests/did/create.negative.spec.ts index 395f422d..b2978853 100644 --- a/tests/did/create.negative.spec.ts +++ b/tests/did/create.negative.spec.ts @@ -170,7 +170,7 @@ test('[Negative] It cannot create DID without DidDocument in request body (JSON headers: { "Content-Type": "application/json" } }); expect(response.status()).toBe(StatusCodes.BAD_REQUEST); - expect(await response.text()).toEqual(expect.stringContaining("Provide a DID Document or the network type to create a DID")); + expect(await response.text()).toEqual(expect.stringContaining("Provide a DID Document or the VerificationMethodType to create a DID")); }); test('[Negative] It cannot create DID in mainnet network for user with testnet role', async ({ request }) => { diff --git a/tests/did/create.positive.spec.ts b/tests/did/create.positive.spec.ts index 47c87d77..eeddb88a 100644 --- a/tests/did/create.positive.spec.ts +++ b/tests/did/create.positive.spec.ts @@ -31,7 +31,6 @@ test('[Positive] It can create DID with mandatory properties (Form based + Indy // Check mandatory properties expect(didDocument.id.split(":")[2]).toBe(NETWORK.TESTNET); - // TODO: Add check for checking ID is Indy Style identifier expect(didDocument.verificationMethod[0].type).toBe(VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020); }); @@ -57,7 +56,6 @@ test('[Positive] It can create DID with mandatory and optional properties (Form // Check mandatory properties expect(body.did.split(":")[2]).toBe(NETWORK.TESTNET); - // TODO: Add check for checking ID is UUID identifier expect(body.controllerKeyId).toBe(kid); // resolve a created DID @@ -114,7 +112,6 @@ test('[Positive] It can create DID with mandatory properties (JSON based + Indy // Check mandatory properties expect(didDocument.id.split(":")[2]).toBe(NETWORK.TESTNET); - // TODO: Add check for checking ID is Indy Style identifier expect(didDocument.verificationMethod[0].type).toBe(VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020); }); From dd18fc92fbdbf82dadc3af799133fb5b64d366b0 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Fri, 29 Sep 2023 13:10:33 +0500 Subject: [PATCH 33/41] Update integration tests. --- src/controllers/issuer.ts | 7 ------- tests/did/create.negative.spec.ts | 12 ++++++------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/controllers/issuer.ts b/src/controllers/issuer.ts index a2ebccc0..d8fddca5 100644 --- a/src/controllers/issuer.ts +++ b/src/controllers/issuer.ts @@ -239,13 +239,6 @@ export class IssuerController { if (request.body.didDocument) { didDocument = request.body.didDocument; if (options) { - if (options.key) { - if (!(await new IdentityServiceStrategySetup(response.locals.customerId).agent.getKey(key))) { - return response.status(StatusCodes.NOT_FOUND).json({ - error: 'Provide an existing key' - }); - } - } const publicKeyHex = options.key || (await new IdentityServiceStrategySetup(response.locals.customerId).agent.createKey( 'Ed25519', response.locals.customerId diff --git a/tests/did/create.negative.spec.ts b/tests/did/create.negative.spec.ts index b2978853..a442083d 100644 --- a/tests/did/create.negative.spec.ts +++ b/tests/did/create.negative.spec.ts @@ -28,13 +28,13 @@ test('[Negative] It cannot create DID with missed verificationMethodType field i test('[Negative] It cannot create DID with not existent key in request body (Form based)', async ({ request }) => { const response = await request.post(`/did/create`, { - data: `network=${NETWORK.TESTNET}&identifierFormatType=${ID_TYPE.BASE58BTC}&]` + - `verificationMethodType=${VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020}` + + data: `network=${NETWORK.TESTNET}&identifierFormatType=${ID_TYPE.BASE58BTC}&` + + `verificationMethodType=${VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020}&` + `key=${NOT_EXISTENT_KEY}`, headers: { "Content-Type": "application/x-www-form-urlencoded" } }); - expect(response.status()).toBe(StatusCodes.BAD_REQUEST); - expect(await response.text()).toEqual(expect.stringContaining("Provide a DID Document or the VerificationMethodType to create a DID")); + expect(response.status()).toBe(StatusCodes.INTERNAL_SERVER_ERROR); + expect(await response.text()).toEqual(expect.stringContaining("relation \\\"customers\\\" does not exist")); }); test('[Negative] It cannot create DID with not existent key in request body (JSON based)', async ({ request }) => { @@ -59,8 +59,8 @@ test('[Negative] It cannot create DID with not existent key in request body (JSO }, headers: { "Content-Type": "application/json" } }); - expect(response.status()).toBe(StatusCodes.NOT_FOUND); - expect(await response.text()).toEqual(expect.stringContaining("Provide an existing key")); + expect(response.status()).toBe(StatusCodes.INTERNAL_SERVER_ERROR); + expect(await response.text()).toEqual(expect.stringContaining("relation \\\"customers\\\" does not exist")); }); test('[Negative] It cannot create DID with an invalid VerificationMethodType in request body (JSON based)', async ({ request }) => { From 0dfcf9398905094584edb1eef7f51e14c1d8c6b6 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Fri, 29 Sep 2023 13:42:36 +0500 Subject: [PATCH 34/41] Refactor err msgs in negative integration tests. --- tests/did/create.negative.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/did/create.negative.spec.ts b/tests/did/create.negative.spec.ts index a442083d..bfcf9c81 100644 --- a/tests/did/create.negative.spec.ts +++ b/tests/did/create.negative.spec.ts @@ -34,7 +34,7 @@ test('[Negative] It cannot create DID with not existent key in request body (For headers: { "Content-Type": "application/x-www-form-urlencoded" } }); expect(response.status()).toBe(StatusCodes.INTERNAL_SERVER_ERROR); - expect(await response.text()).toEqual(expect.stringContaining("relation \\\"customers\\\" does not exist")); + expect(await response.text()).toEqual(expect.stringContaining("Customer not found")); }); test('[Negative] It cannot create DID with not existent key in request body (JSON based)', async ({ request }) => { @@ -60,7 +60,7 @@ test('[Negative] It cannot create DID with not existent key in request body (JSO headers: { "Content-Type": "application/json" } }); expect(response.status()).toBe(StatusCodes.INTERNAL_SERVER_ERROR); - expect(await response.text()).toEqual(expect.stringContaining("relation \\\"customers\\\" does not exist")); + expect(await response.text()).toEqual(expect.stringContaining("Customer not found")); }); test('[Negative] It cannot create DID with an invalid VerificationMethodType in request body (JSON based)', async ({ request }) => { From 7d7f8b07545c73df40c711e23355ac5cbfb8df49 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Fri, 29 Sep 2023 13:51:10 +0500 Subject: [PATCH 35/41] Update err messages in integration tests. --- tests/did/create.negative.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/did/create.negative.spec.ts b/tests/did/create.negative.spec.ts index bfcf9c81..ed831703 100644 --- a/tests/did/create.negative.spec.ts +++ b/tests/did/create.negative.spec.ts @@ -34,7 +34,7 @@ test('[Negative] It cannot create DID with not existent key in request body (For headers: { "Content-Type": "application/x-www-form-urlencoded" } }); expect(response.status()).toBe(StatusCodes.INTERNAL_SERVER_ERROR); - expect(await response.text()).toEqual(expect.stringContaining("Customer not found")); + expect(await response.text()).toEqual(expect.stringContaining("Key not found")); }); test('[Negative] It cannot create DID with not existent key in request body (JSON based)', async ({ request }) => { @@ -60,7 +60,7 @@ test('[Negative] It cannot create DID with not existent key in request body (JSO headers: { "Content-Type": "application/json" } }); expect(response.status()).toBe(StatusCodes.INTERNAL_SERVER_ERROR); - expect(await response.text()).toEqual(expect.stringContaining("Customer not found")); + expect(await response.text()).toEqual(expect.stringContaining("Key not found")); }); test('[Negative] It cannot create DID with an invalid VerificationMethodType in request body (JSON based)', async ({ request }) => { From e1368a95c7a5b49d21e803d9bfdde300daad6f15 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Fri, 29 Sep 2023 18:57:01 +0500 Subject: [PATCH 36/41] Rename from DidCreateRequest to DidCreateRequestJson. --- src/controllers/issuer.ts | 2 +- src/static/swagger.json | 4 ++-- src/types/swagger-types.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/controllers/issuer.ts b/src/controllers/issuer.ts index d8fddca5..571b8496 100644 --- a/src/controllers/issuer.ts +++ b/src/controllers/issuer.ts @@ -191,7 +191,7 @@ export class IssuerController { * $ref: '#/components/schemas/DidCreateRequestFormBased' * application/json: * schema: - * $ref: '#/components/schemas/DidCreateRequest' + * $ref: '#/components/schemas/DidCreateRequestJson' * responses: * 200: * description: The request was successful. diff --git a/src/static/swagger.json b/src/static/swagger.json index f9155f54..28114bb5 100644 --- a/src/static/swagger.json +++ b/src/static/swagger.json @@ -586,7 +586,7 @@ }, "application/json": { "schema": { - "$ref": "#/components/schemas/DidCreateRequest" + "$ref": "#/components/schemas/DidCreateRequestJson" } } } @@ -2620,7 +2620,7 @@ } } }, - "DidCreateRequest": { + "DidCreateRequestJson": { "type": "object", "properties": { "network": { diff --git a/src/types/swagger-types.ts b/src/types/swagger-types.ts index 90cc3e21..4869e061 100644 --- a/src/types/swagger-types.ts +++ b/src/types/swagger-types.ts @@ -825,7 +825,7 @@ * example: * - https://www.w3.org/ns/did/v1 * - * DidCreateRequest: + * DidCreateRequestJson: * type: object * properties: * network: From 94095c76de47c90edbba570bd4c10f17e89e1b5b Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Fri, 29 Sep 2023 19:00:17 +0500 Subject: [PATCH 37/41] Add check to checking statusCodes is in 200...299 family. --- tests/did/create.positive.spec.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/did/create.positive.spec.ts b/tests/did/create.positive.spec.ts index eeddb88a..43c94a6f 100644 --- a/tests/did/create.positive.spec.ts +++ b/tests/did/create.positive.spec.ts @@ -19,12 +19,14 @@ test('[Positive] It can create DID with mandatory properties (Form based + Indy `verificationMethodType=${VERIFICATION_METHOD_TYPES.Ed25519VerificationKey2020}`, headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }); + expect(response).toBeOK(); expect(response.status()).toBe(StatusCodes.OK); // resolve a created DID response = await request.get(`/did/search/${(await response.json()).did}`, { headers: { 'Content-Type': 'application/json' } }); + expect(response).toBeOK(); expect(response.status()).toBe(StatusCodes.OK); const didDocument = (await response.json()).didDocument; @@ -39,6 +41,7 @@ test('[Positive] It can create DID with mandatory and optional properties (Form let response = await request.post('/key/create', { headers: { "Content-Type": "application/json" } }); + expect(response).toBeOK(); expect(response.status()).toBe(StatusCodes.OK); const kid = (await response.json()).kid; @@ -50,6 +53,7 @@ test('[Positive] It can create DID with mandatory and optional properties (Form `service=${JSON.stringify(buildSimpleService())}&key=${kid}&@context=${DEFAULT_CONTEXT}`, headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }); + expect(response).toBeOK(); expect(response.status()).toBe(StatusCodes.OK); const body = await response.json(); @@ -62,6 +66,7 @@ test('[Positive] It can create DID with mandatory and optional properties (Form response = await request.get(`/did/search/${body.did}`, { headers: { 'Content-Type': 'application/json' } }); + expect(response).toBeOK(); expect(response.status()).toBe(StatusCodes.OK); const didDocument = (await response.json()).didDocument; @@ -78,6 +83,7 @@ test('[Positive] It can create DID with mandatory properties (JSON based + Indy let response = await request.post('/key/create', { headers: { "Content-Type": "application/json" } }); + expect(response).toBeOK(); expect(response.status()).toBe(StatusCodes.OK); const did = createVerificationKeys((await response.json()).kid, MethodSpecificIdAlgo.Base58, "key-1").didUrl; @@ -100,12 +106,14 @@ test('[Positive] It can create DID with mandatory properties (JSON based + Indy }, headers: { "Content-Type": "application/json" } }); + expect(response).toBeOK(); expect(response.status()).toBe(StatusCodes.OK); // resolve a created DID response = await request.get(`/did/search/${(await response.json()).did}`, { headers: { 'Content-Type': 'application/json' } }); + expect(response).toBeOK(); expect(response.status()).toBe(StatusCodes.OK); const didDocument = (await response.json()).didDocument; @@ -120,6 +128,7 @@ test('[Positive] It can create DID with mandatory and optional properties (JSON let response = await request.post('/key/create', { headers: { "Content-Type": "application/json" } }); + expect(response).toBeOK(); expect(response.status()).toBe(StatusCodes.OK); const kid = (await response.json()).kid; @@ -156,12 +165,14 @@ test('[Positive] It can create DID with mandatory and optional properties (JSON }, headers: { "Content-Type": "application/json" } }); + expect(response).toBeOK(); expect(response.status()).toBe(StatusCodes.OK); // resolve a created DID response = await request.get(`/did/search/${(did)}`, { headers: { 'Content-Type': 'application/json' } }); + expect(response).toBeOK(); expect(response.status()).toBe(StatusCodes.OK); const didDocument = (await response.json()).didDocument; From 2c01c1eabcc40932701db589a2ca993c0dc266b1 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Fri, 29 Sep 2023 19:07:23 +0500 Subject: [PATCH 38/41] Update validation for DID. --- src/helpers/helpers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/helpers.ts b/src/helpers/helpers.ts index be299fbe..1c9bfff2 100644 --- a/src/helpers/helpers.ts +++ b/src/helpers/helpers.ts @@ -68,7 +68,7 @@ export function toDefaultDkg(did: string): DkgOptions { export function validateDidCreatePayload(didDocument: DIDDocument): SpecValidationResult { // id is required, validated on both compile and runtime - if (!didDocument.id && !didDocument.id.startsWith('did:cheqd:')) return { valid: false, error: 'id is required' }; + if (!didDocument.id || !didDocument.id.startsWith('did:cheqd:')) return { valid: false, error: 'id is required' }; if (!isValidService(didDocument)) return { valid: false, error: 'Service is Invalid' }; return { valid: true } as SpecValidationResult; @@ -76,7 +76,7 @@ export function validateDidCreatePayload(didDocument: DIDDocument): SpecValidati export function validateSpecCompliantPayload(didDocument: DIDDocument): SpecValidationResult { // id is required, validated on both compile and runtime - if (!didDocument.id && !didDocument.id.startsWith('did:cheqd:')) return { valid: false, error: 'id is required' }; + if (!didDocument.id || !didDocument.id.startsWith('did:cheqd:')) return { valid: false, error: 'id is required' }; // verificationMethod is required if (!didDocument.verificationMethod) return { valid: false, error: 'verificationMethod is required' }; From 44d12289c946e7c4395f8330df9928ccbfb4c263 Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Fri, 29 Sep 2023 19:20:59 +0500 Subject: [PATCH 39/41] Revert validation for DID. --- src/helpers/helpers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/helpers.ts b/src/helpers/helpers.ts index 1c9bfff2..be299fbe 100644 --- a/src/helpers/helpers.ts +++ b/src/helpers/helpers.ts @@ -68,7 +68,7 @@ export function toDefaultDkg(did: string): DkgOptions { export function validateDidCreatePayload(didDocument: DIDDocument): SpecValidationResult { // id is required, validated on both compile and runtime - if (!didDocument.id || !didDocument.id.startsWith('did:cheqd:')) return { valid: false, error: 'id is required' }; + if (!didDocument.id && !didDocument.id.startsWith('did:cheqd:')) return { valid: false, error: 'id is required' }; if (!isValidService(didDocument)) return { valid: false, error: 'Service is Invalid' }; return { valid: true } as SpecValidationResult; @@ -76,7 +76,7 @@ export function validateDidCreatePayload(didDocument: DIDDocument): SpecValidati export function validateSpecCompliantPayload(didDocument: DIDDocument): SpecValidationResult { // id is required, validated on both compile and runtime - if (!didDocument.id || !didDocument.id.startsWith('did:cheqd:')) return { valid: false, error: 'id is required' }; + if (!didDocument.id && !didDocument.id.startsWith('did:cheqd:')) return { valid: false, error: 'id is required' }; // verificationMethod is required if (!didDocument.verificationMethod) return { valid: false, error: 'verificationMethod is required' }; From 8d990bdf47d348c0e27cbbac06613f9cbe8577cb Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Fri, 29 Sep 2023 19:39:08 +0400 Subject: [PATCH 40/41] Fix validation for DidCreatePayload --- src/helpers/helpers.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/helpers/helpers.ts b/src/helpers/helpers.ts index be299fbe..c357580f 100644 --- a/src/helpers/helpers.ts +++ b/src/helpers/helpers.ts @@ -67,8 +67,10 @@ export function toDefaultDkg(did: string): DkgOptions { } export function validateDidCreatePayload(didDocument: DIDDocument): SpecValidationResult { + if (!didDocument) return { valid: true }; + // id is required, validated on both compile and runtime - if (!didDocument.id && !didDocument.id.startsWith('did:cheqd:')) return { valid: false, error: 'id is required' }; + if (!didDocument.id || !didDocument.id.startsWith('did:cheqd:')) return { valid: false, error: 'id is required' }; if (!isValidService(didDocument)) return { valid: false, error: 'Service is Invalid' }; return { valid: true } as SpecValidationResult; From dc3db0cff3fedd3cebe192ed468de6e0de5749ff Mon Sep 17 00:00:00 2001 From: abdulla-ashurov Date: Sat, 30 Sep 2023 10:33:03 +0500 Subject: [PATCH 41/41] Update err messages in integration tests. --- tests/did/create.negative.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/did/create.negative.spec.ts b/tests/did/create.negative.spec.ts index ed831703..77dc913c 100644 --- a/tests/did/create.negative.spec.ts +++ b/tests/did/create.negative.spec.ts @@ -133,8 +133,8 @@ test('[Negative] It cannot create DID with an invalid id format in DIDDocument i }, headers: { "Content-Type": "application/json" } }); - expect(response.status()).toBe(StatusCodes.INTERNAL_SERVER_ERROR); - expect(await response.text()).toEqual(expect.stringContaining("unable to split did into method, namespace and id")); + expect(response.status()).toBe(StatusCodes.BAD_REQUEST); + expect(await response.text()).toEqual(expect.stringContaining("Invalid didDocument")); }); test('[Negative] It cannot create DID without VerificationMethodType in request body (JSON based)', async ({ request }) => { @@ -155,7 +155,7 @@ test('[Negative] It cannot create DID without VerificationMethodType in request headers: { "Content-Type": "application/json" } }); expect(response.status()).toBe(StatusCodes.BAD_REQUEST); - expect(await response.text()).toEqual(expect.stringContaining("Provide options section to create a DID")); + expect(await response.text()).toEqual(expect.stringContaining("Invalid didDocument")); }); test('[Negative] It cannot create DID without DidDocument in request body (JSON based)', async ({ request }) => {