From c3f7ad2a7c26fe92a45526083fe3d6ba26664880 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Tue, 2 Apr 2024 22:28:21 +0200 Subject: [PATCH] fix: Add more positive tests and deps bumps [DEV-3798] (#288) * Add more flow tests * Bummp deps * Bump latest --------- Co-authored-by: Tasos Derisiotis <50984242+Eengineer1@users.noreply.github.com> --- package-lock.json | 491 ++++++++++++++++++++----- package.json | 24 +- tests/did/did-deactivate.spec.ts | 145 ++++++++ tests/did/did-update.spec.ts | 157 ++++++++ tests/resource/resource-create.spec.ts | 143 +++++++ 5 files changed, 848 insertions(+), 112 deletions(-) create mode 100644 tests/did/did-deactivate.spec.ts create mode 100644 tests/did/did-update.spec.ts create mode 100644 tests/resource/resource-create.spec.ts diff --git a/package-lock.json b/package-lock.json index 409a8d5..d1dfa3e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,19 +1,19 @@ { "name": "@cheqd/did-registrar", - "version": "2.1.1", + "version": "2.1.2-develop.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@cheqd/did-registrar", - "version": "2.1.1", + "version": "2.1.2-develop.1", "license": "Apache-2.0", "dependencies": { - "@cheqd/sdk": "^4.0.0-develop.1", - "@cheqd/ts-proto": "^3.4.0", - "@cosmjs/proto-signing": "^0.32.2", + "@cheqd/sdk": "^4.0.0", + "@cheqd/ts-proto": "^3.4.1", + "@cosmjs/proto-signing": "^0.32.3", "dotenv": "^16.4.5", - "express": "^4.18.2", + "express": "^4.19.2", "express-validator": "^7.0.1", "helmet": "^7.1.0", "node-cache": "^5.1.2", @@ -21,17 +21,17 @@ "swagger-ui-express": "^5.0.0" }, "devDependencies": { - "@playwright/test": "^1.41.2", + "@playwright/test": "^1.42.1", "@semantic-release/changelog": "^6.0.3", - "@semantic-release/commit-analyzer": "^11.1.0", + "@semantic-release/commit-analyzer": "^12.0.0", "@semantic-release/git": "^10.0.1", "@semantic-release/github": "^9.2.6", - "@semantic-release/npm": "^11.0.2", - "@semantic-release/release-notes-generator": "^12.1.0", + "@semantic-release/npm": "^12.0.0", + "@semantic-release/release-notes-generator": "^13.0.0", "@stablelib/base64": "^1.0.1", "@types/express": "^4.17.21", "@types/helmet": "^4.0.0", - "@types/node": "^20.11.19", + "@types/node": "^20.12.2", "@types/node-fetch": "^2.6.11", "@types/swagger-ui-express": "^4.1.6", "@types/uuid": "^9.0.8", @@ -40,12 +40,12 @@ "base64url": "^3.0.1", "conventional-changelog-conventionalcommits": "^7.0.2", "esbuild": "^0.19.12", - "eslint": "^8.56.0", + "eslint": "^8.57.0", "eslint-config-prettier": "^9.1.0", "eslint-config-typescript": "^3.0.0", "prettier": "^3.2.5", - "semantic-release": "^22.0.12", - "typescript": "^5.3.3" + "semantic-release": "^23.0.6", + "typescript": "^5.4.3" }, "engines": { "node": ">=20.0.0" @@ -169,9 +169,9 @@ } }, "node_modules/@cheqd/sdk": { - "version": "4.0.0-develop.1", - "resolved": "https://registry.npmjs.org/@cheqd/sdk/-/sdk-4.0.0-develop.1.tgz", - "integrity": "sha512-Vw/3VQZ3f3eFORhH8Wqn+QjuyYzKOMokhg1bj+4fr9uWWpn16VcIS7AztsSmKd8EF8T2qMibDyBCgHKY/S2MUQ==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@cheqd/sdk/-/sdk-4.0.0.tgz", + "integrity": "sha512-/ycKpBcitF/bc9QM7Gf/+dJD0mhWbWxQj4eJZv4Ikzur846ZfD3PYEEvSAAW69WYAYSTLjIpXX94UVCXG7Oo1g==", "dependencies": { "@cheqd/ts-proto": "^3.4.1", "@cosmjs/amino": "^0.32.3", @@ -832,9 +832,9 @@ } }, "node_modules/@humanwhocodes/object-schema": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.2.tgz", - "integrity": "sha512-6EwiSjwWYP7pTckG6I5eyFANjPhmPjUX9JRLUSfNPC7FX7zK9gyZAfUEaECL6ALTpGX5AjnBq3C9XmVWPitNpw==", + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.3.tgz", + "integrity": "sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==", "dev": true }, "node_modules/@multiformats/base-x": { @@ -1190,9 +1190,9 @@ } }, "node_modules/@semantic-release/commit-analyzer": { - "version": "11.1.0", - "resolved": "https://registry.npmjs.org/@semantic-release/commit-analyzer/-/commit-analyzer-11.1.0.tgz", - "integrity": "sha512-cXNTbv3nXR2hlzHjAMgbuiQVtvWHTlwwISt60B+4NZv01y/QRY7p2HcJm8Eh2StzcTJoNnflvKjHH/cjFS7d5g==", + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/@semantic-release/commit-analyzer/-/commit-analyzer-12.0.0.tgz", + "integrity": "sha512-qG+md5gdes+xa8zP7lIo1fWE17zRdO8yMCaxh9lyL65TQleoSv8WHHOqRURfghTytUh+NpkSyBprQ5hrkxOKVQ==", "dev": true, "dependencies": { "conventional-changelog-angular": "^7.0.0", @@ -1204,7 +1204,7 @@ "micromatch": "^4.0.2" }, "engines": { - "node": "^18.17 || >=20.6.1" + "node": ">=20.8.1" }, "peerDependencies": { "semantic-release": ">=20.1.0" @@ -1336,9 +1336,9 @@ } }, "node_modules/@semantic-release/npm": { - "version": "11.0.3", - "resolved": "https://registry.npmjs.org/@semantic-release/npm/-/npm-11.0.3.tgz", - "integrity": "sha512-KUsozQGhRBAnoVg4UMZj9ep436VEGwT536/jwSqB7vcEfA6oncCUU7UIYTRdLx7GvTtqn0kBjnkfLVkcnBa2YQ==", + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/@semantic-release/npm/-/npm-12.0.0.tgz", + "integrity": "sha512-72TVYQCH9NvVsO/y13eF8vE4bNnfls518+4KcFwJUKi7AtA/ZXoNgSg9gTTfw5eMZMkiH0izUrpGXgZE/cSQhA==", "dev": true, "dependencies": { "@semantic-release/error": "^4.0.0", @@ -1356,7 +1356,7 @@ "tempy": "^3.0.0" }, "engines": { - "node": "^18.17 || >=20" + "node": ">=20.8.1" }, "peerDependencies": { "semantic-release": ">=20.1.0" @@ -1561,9 +1561,9 @@ } }, "node_modules/@semantic-release/release-notes-generator": { - "version": "12.1.0", - "resolved": "https://registry.npmjs.org/@semantic-release/release-notes-generator/-/release-notes-generator-12.1.0.tgz", - "integrity": "sha512-g6M9AjUKAZUZnxaJZnouNBeDNTCUrJ5Ltj+VJ60gJeDaRRahcHsry9HW8yKrnKkKNkx5lbWiEP1FPMqVNQz8Kg==", + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/@semantic-release/release-notes-generator/-/release-notes-generator-13.0.0.tgz", + "integrity": "sha512-LEeZWb340keMYuREMyxrODPXJJ0JOL8D/mCl74B4LdzbxhtXV2LrPN2QBEcGJrlQhoqLO0RhxQb6masHytKw+A==", "dev": true, "dependencies": { "conventional-changelog-angular": "^7.0.0", @@ -1578,7 +1578,7 @@ "read-pkg-up": "^11.0.0" }, "engines": { - "node": "^18.17 || >=20.6.1" + "node": ">=20.8.1" }, "peerDependencies": { "semantic-release": ">=20.1.0" @@ -2167,10 +2167,10 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, - "node_modules/ansicolors": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/ansicolors/-/ansicolors-0.3.2.tgz", - "integrity": "sha512-QXu7BPrP29VllRxH8GwB7x5iX5qWKAAMLqKQGWTeLWVlNHNOpVMJ91dsxQAIWXpjuW5wqvxu3Jd/nRjrJ+0pqg==", + "node_modules/any-promise": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz", + "integrity": "sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A==", "dev": true }, "node_modules/argparse": { @@ -2379,19 +2379,6 @@ "resolved": "https://registry.npmjs.org/canonicalize/-/canonicalize-2.0.0.tgz", "integrity": "sha512-ulDEYPv7asdKvqahuAY35c1selLdzDwHqugK92hfkzvlDCwXRRelDkR+Er33md/PtnpqHemgkuDPanZ4fiYZ8w==" }, - "node_modules/cardinal": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/cardinal/-/cardinal-2.1.1.tgz", - "integrity": "sha512-JSr5eOgoEymtYHBjNWyjrMqet9Am2miJhlfKNdqLp6zoeAh0KN5dRAcxlecj5mAJrmQomgiOBj35xHLrFjqBpw==", - "dev": true, - "dependencies": { - "ansicolors": "~0.3.2", - "redeyed": "~2.1.0" - }, - "bin": { - "cdl": "bin/cdl.js" - } - }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -2426,6 +2413,65 @@ "node": ">=6" } }, + "node_modules/cli-highlight": { + "version": "2.1.11", + "resolved": "https://registry.npmjs.org/cli-highlight/-/cli-highlight-2.1.11.tgz", + "integrity": "sha512-9KDcoEVwyUXrjcJNvHD0NFc/hiwe/WPVYIleQh2O1N2Zro5gWJZ/K+3DGn8w8P/F6FxOgzyC5bxDyHIgCSPhGg==", + "dev": true, + "dependencies": { + "chalk": "^4.0.0", + "highlight.js": "^10.7.1", + "mz": "^2.4.0", + "parse5": "^5.1.1", + "parse5-htmlparser2-tree-adapter": "^6.0.0", + "yargs": "^16.0.0" + }, + "bin": { + "highlight": "bin/highlight" + }, + "engines": { + "node": ">=8.0.0", + "npm": ">=5.0.0" + } + }, + "node_modules/cli-highlight/node_modules/cliui": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", + "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", + "dev": true, + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^7.0.0" + } + }, + "node_modules/cli-highlight/node_modules/yargs": { + "version": "16.2.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", + "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", + "dev": true, + "dependencies": { + "cliui": "^7.0.2", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.0", + "y18n": "^5.0.5", + "yargs-parser": "^20.2.2" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/cli-highlight/node_modules/yargs-parser": { + "version": "20.2.9", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz", + "integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==", + "dev": true, + "engines": { + "node": ">=10" + } + }, "node_modules/cli-table3": { "version": "0.6.4", "resolved": "https://registry.npmjs.org/cli-table3/-/cli-table3-0.6.4.tgz", @@ -2628,15 +2674,15 @@ "dev": true }, "node_modules/cosmiconfig": { - "version": "8.3.6", - "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-8.3.6.tgz", - "integrity": "sha512-kcZ6+W5QzcJ3P1Mt+83OUv/oHFqZHIx8DuxG6eZ5RGMERoLqp4BuGjhHLYGK+Kf5XVkQvqBSmAy/nGWN3qDgEA==", + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-9.0.0.tgz", + "integrity": "sha512-itvL5h8RETACmOTFc4UfIyB2RfEHi71Ax6E/PivVxq9NseKbOWpeyHEOIbmAw1rs8Ak0VursQNww7lf7YtUwzg==", "dev": true, "dependencies": { + "env-paths": "^2.2.1", "import-fresh": "^3.3.0", "js-yaml": "^4.1.0", - "parse-json": "^5.2.0", - "path-type": "^4.0.0" + "parse-json": "^5.2.0" }, "engines": { "node": ">=14" @@ -2947,9 +2993,9 @@ } }, "node_modules/env-ci": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/env-ci/-/env-ci-10.0.0.tgz", - "integrity": "sha512-U4xcd/utDYFgMh0yWj07R1H6L5fwhVbmxBCpnL0DbVSDZVnsC82HONw0wxtxNkIAcua3KtbomQvIk5xFZGAQJw==", + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/env-ci/-/env-ci-11.0.0.tgz", + "integrity": "sha512-apikxMgkipkgTvMdRT9MNqWx5VLOci79F4VBd7Op/7OPjjoanjdAvn6fglMCCEf/1bAh8eOiuEVCUs4V3qP3nQ==", "dev": true, "dependencies": { "execa": "^8.0.0", @@ -3093,6 +3139,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/env-paths": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/env-paths/-/env-paths-2.2.1.tgz", + "integrity": "sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A==", + "dev": true, + "engines": { + "node": ">=6" + } + }, "node_modules/error-ex": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", @@ -3331,19 +3386,6 @@ "url": "https://opencollective.com/eslint" } }, - "node_modules/esprima": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", - "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", - "dev": true, - "bin": { - "esparse": "bin/esparse.js", - "esvalidate": "bin/esvalidate.js" - }, - "engines": { - "node": ">=4" - } - }, "node_modules/esquery": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.5.0.tgz", @@ -4118,6 +4160,15 @@ "node": ">=16.0.0" } }, + "node_modules/highlight.js": { + "version": "10.7.3", + "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.7.3.tgz", + "integrity": "sha512-tzcUFauisWKNHaRkN4Wjl/ZA07gENAjFl3J/c480dprkGTg5EQstgaNFqBfUqCq54kZRIEcreTsAgF/m2quD7A==", + "dev": true, + "engines": { + "node": "*" + } + }, "node_modules/hmac-drbg": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", @@ -4748,26 +4799,26 @@ } }, "node_modules/marked": { - "version": "9.1.6", - "resolved": "https://registry.npmjs.org/marked/-/marked-9.1.6.tgz", - "integrity": "sha512-jcByLnIFkd5gSXZmjNvS1TlmRhCXZjIzHYlaGkPlLIekG55JDR2Z4va9tZwCiP+/RDERiNhMOFu01xd6O5ct1Q==", + "version": "12.0.1", + "resolved": "https://registry.npmjs.org/marked/-/marked-12.0.1.tgz", + "integrity": "sha512-Y1/V2yafOcOdWQCX0XpAKXzDakPOpn6U0YLxTJs3cww6VxOzZV1BTOOYWLvH3gX38cq+iLwljHHTnMtlDfg01Q==", "dev": true, "bin": { "marked": "bin/marked.js" }, "engines": { - "node": ">= 16" + "node": ">= 18" } }, "node_modules/marked-terminal": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/marked-terminal/-/marked-terminal-6.2.0.tgz", - "integrity": "sha512-ubWhwcBFHnXsjYNsu+Wndpg0zhY4CahSpPlA70PlO0rR9r2sZpkyU+rkCsOWH+KMEkx847UpALON+HWgxowFtw==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/marked-terminal/-/marked-terminal-7.0.0.tgz", + "integrity": "sha512-sNEx8nn9Ktcm6pL0TnRz8tnXq/mSS0Q1FRSwJOAqw4lAB4l49UeDf85Gm1n9RPFm5qurCPjwi1StAQT2XExhZw==", "dev": true, "dependencies": { "ansi-escapes": "^6.2.0", - "cardinal": "^2.1.1", "chalk": "^5.3.0", + "cli-highlight": "^2.1.11", "cli-table3": "^0.6.3", "node-emoji": "^2.1.3", "supports-hyperlinks": "^3.0.0" @@ -4776,7 +4827,7 @@ "node": ">=16.0.0" }, "peerDependencies": { - "marked": ">=1 <12" + "marked": ">=1 <13" } }, "node_modules/marked-terminal/node_modules/chalk": { @@ -4954,6 +5005,17 @@ "npm": ">=7.0.0" } }, + "node_modules/mz": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz", + "integrity": "sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==", + "dev": true, + "dependencies": { + "any-promise": "^1.0.0", + "object-assign": "^4.0.1", + "thenify-all": "^1.0.0" + } + }, "node_modules/natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", @@ -7866,6 +7928,15 @@ "inBundle": true, "license": "ISC" }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/object-inspect": { "version": "1.13.1", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz", @@ -8071,6 +8142,27 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/parse5": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-5.1.1.tgz", + "integrity": "sha512-ugq4DFI0Ptb+WWjAdOK16+u/nHfiIrcE+sh8kZMaM0WllQKLI9rOUq6c2b7cwPkXdzfQESqvoqK6ug7U/Yyzug==", + "dev": true + }, + "node_modules/parse5-htmlparser2-tree-adapter": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/parse5-htmlparser2-tree-adapter/-/parse5-htmlparser2-tree-adapter-6.0.1.tgz", + "integrity": "sha512-qPuWvbLgvDGilKc5BoicRovlT4MtYT6JfJyBOMDsKoiT+GiuP5qyrPCnR9HcPECIJJmZh5jRndyNThnhhb/vlA==", + "dev": true, + "dependencies": { + "parse5": "^6.0.1" + } + }, + "node_modules/parse5-htmlparser2-tree-adapter/node_modules/parse5": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-6.0.1.tgz", + "integrity": "sha512-Ofn/CTFzRGTTxwpNEs9PP93gXShHcTq255nzRYSKe8AkVpZY7e1fpmTfOyoIvjP5HG7Z2ZM7VS9PPhQGW2pOpw==", + "dev": true + }, "node_modules/parseurl": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", @@ -8540,15 +8632,6 @@ "resolved": "https://registry.npmjs.org/readonly-date/-/readonly-date-1.0.0.tgz", "integrity": "sha512-tMKIV7hlk0h4mO3JTmmVuIlJVXjKk3Sep9Bf5OH0O+758ruuVkUy2J9SttDLm91IEX/WHlXPSpxMGjPj4beMIQ==" }, - "node_modules/redeyed": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/redeyed/-/redeyed-2.1.1.tgz", - "integrity": "sha512-FNpGGo1DycYAdnrKFxCMmKYgo/mILAqtRYbkdQD8Ep/Hk2PQ5+aEAEx+IU713RTDmuBaH0c8P5ZozurNu5ObRQ==", - "dev": true, - "dependencies": { - "esprima": "~4.0.0" - } - }, "node_modules/registry-auth-token": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/registry-auth-token/-/registry-auth-token-5.0.2.tgz", @@ -8666,20 +8749,20 @@ } }, "node_modules/semantic-release": { - "version": "22.0.12", - "resolved": "https://registry.npmjs.org/semantic-release/-/semantic-release-22.0.12.tgz", - "integrity": "sha512-0mhiCR/4sZb00RVFJIUlMuiBkW3NMpVIW2Gse7noqEMoFGkvfPPAImEQbkBV8xga4KOPP4FdTRYuLLy32R1fPw==", + "version": "23.0.6", + "resolved": "https://registry.npmjs.org/semantic-release/-/semantic-release-23.0.6.tgz", + "integrity": "sha512-/r62F4PNhJZhyZYMobcpcACGwpFNQyaVcSmqZQXG50GMbHSBVZQLCvwafqxO1lDQKVgmGmyCEtOVYzwvzvyhVw==", "dev": true, "dependencies": { - "@semantic-release/commit-analyzer": "^11.0.0", + "@semantic-release/commit-analyzer": "^12.0.0", "@semantic-release/error": "^4.0.0", - "@semantic-release/github": "^9.0.0", - "@semantic-release/npm": "^11.0.0", - "@semantic-release/release-notes-generator": "^12.0.0", + "@semantic-release/github": "^10.0.0", + "@semantic-release/npm": "^12.0.0", + "@semantic-release/release-notes-generator": "^13.0.0", "aggregate-error": "^5.0.0", - "cosmiconfig": "^8.0.0", + "cosmiconfig": "^9.0.0", "debug": "^4.0.0", - "env-ci": "^10.0.0", + "env-ci": "^11.0.0", "execa": "^8.0.0", "figures": "^6.0.0", "find-versions": "^5.1.0", @@ -8689,8 +8772,8 @@ "hosted-git-info": "^7.0.0", "import-from-esm": "^1.3.1", "lodash-es": "^4.17.21", - "marked": "^9.0.0", - "marked-terminal": "^6.0.0", + "marked": "^12.0.0", + "marked-terminal": "^7.0.0", "micromatch": "^4.0.2", "p-each-series": "^3.0.0", "p-reduce": "^3.0.0", @@ -8705,7 +8788,136 @@ "semantic-release": "bin/semantic-release.js" }, "engines": { - "node": "^18.17 || >=20.6.1" + "node": ">=20.8.1" + } + }, + "node_modules/semantic-release/node_modules/@octokit/auth-token": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-5.0.1.tgz", + "integrity": "sha512-RTmWsLfig8SBoiSdgvCht4BXl1CHU89Co5xiQ5JF19my/sIRDFCQ1RPrmK0exgqUZuNm39C/bV8+/83+MJEjGg==", + "dev": true, + "engines": { + "node": ">= 18" + } + }, + "node_modules/semantic-release/node_modules/@octokit/core": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@octokit/core/-/core-6.0.1.tgz", + "integrity": "sha512-MIpPQXu8Y8GjHwXM81JLveiV+DHJZtLMcB5nKekBGOl3iAtk0HT3i12Xl8Biybu+bCS1+k4qbuKEq5d0RxNRnQ==", + "dev": true, + "dependencies": { + "@octokit/auth-token": "^5.0.0", + "@octokit/graphql": "^8.0.0", + "@octokit/request": "^9.0.0", + "@octokit/request-error": "^6.0.1", + "@octokit/types": "^12.0.0", + "before-after-hook": "^3.0.2", + "universal-user-agent": "^7.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/semantic-release/node_modules/@octokit/endpoint": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-10.0.0.tgz", + "integrity": "sha512-emBcNDxBdC1y3+knJonS5zhUB/CG6TihubxM2U1/pG/Z1y3a4oV0Gzz3lmkCvWWQI6h3tqBAX9MgCBFp+M68Jw==", + "dev": true, + "dependencies": { + "@octokit/types": "^12.0.0", + "universal-user-agent": "^7.0.2" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/semantic-release/node_modules/@octokit/graphql": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-8.0.1.tgz", + "integrity": "sha512-lLDb6LhC1gBj2CxEDa5Xk10+H/boonhs+3Mi6jpRyetskDKNHe6crMeKmUE2efoLofMP8ruannLlCUgpTFmVzQ==", + "dev": true, + "dependencies": { + "@octokit/request": "^9.0.0", + "@octokit/types": "^12.0.0", + "universal-user-agent": "^7.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/semantic-release/node_modules/@octokit/plugin-paginate-rest": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-10.0.0.tgz", + "integrity": "sha512-G1Z67qOiFneKDJyMafHQkWnKm1kU3FfbRZLzxgsFg4dOa3pRNdABbdk+xo/oev6P88lnbt7GKdBNB6dJZuPphA==", + "dev": true, + "dependencies": { + "@octokit/types": "^12.6.0" + }, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "@octokit/core": ">=6" + } + }, + "node_modules/semantic-release/node_modules/@octokit/plugin-retry": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/@octokit/plugin-retry/-/plugin-retry-7.0.3.tgz", + "integrity": "sha512-T9l5Z7XnDZ7dkyNmhJPSUq0YjbqUT/xn4yQbhcSuv4WGC/LqM73/mKwkl68VDPoLw20e8oz4L7qQopWt9v6sow==", + "dev": true, + "dependencies": { + "@octokit/request-error": "^6.0.0", + "@octokit/types": "^12.0.0", + "bottleneck": "^2.15.3" + }, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "@octokit/core": ">=6" + } + }, + "node_modules/semantic-release/node_modules/@octokit/plugin-throttling": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/@octokit/plugin-throttling/-/plugin-throttling-9.0.3.tgz", + "integrity": "sha512-DReKamrLBJOzld73dmmxV2H137QKJfsxszAczEZXeAJQ/Po6bzQacKajPdodA6T1jfmP9+waImus+d/R2j+R7Q==", + "dev": true, + "dependencies": { + "@octokit/types": "^12.6.0", + "bottleneck": "^2.15.3" + }, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "@octokit/core": "^6.0.0" + } + }, + "node_modules/semantic-release/node_modules/@octokit/request": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/@octokit/request/-/request-9.0.1.tgz", + "integrity": "sha512-kL+cAcbSl3dctYLuJmLfx6Iku2MXXy0jszhaEIjQNaCp4zjHXrhVAHeuaRdNvJjW9qjl3u1MJ72+OuBP0YW/pg==", + "dev": true, + "dependencies": { + "@octokit/endpoint": "^10.0.0", + "@octokit/request-error": "^6.0.1", + "@octokit/types": "^12.0.0", + "universal-user-agent": "^7.0.2" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/semantic-release/node_modules/@octokit/request-error": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-6.0.2.tgz", + "integrity": "sha512-WtRVpoHcNXs84+s9s/wqfHaxM68NGMg8Av7h59B50OVO0PwwMx+2GgQ/OliUd0iQBSNWgR6N8afi/KjSHbXHWw==", + "dev": true, + "dependencies": { + "@octokit/types": "^12.0.0" + }, + "engines": { + "node": ">= 18" } }, "node_modules/semantic-release/node_modules/@semantic-release/error": { @@ -8717,6 +8929,36 @@ "node": ">=18" } }, + "node_modules/semantic-release/node_modules/@semantic-release/github": { + "version": "10.0.2", + "resolved": "https://registry.npmjs.org/@semantic-release/github/-/github-10.0.2.tgz", + "integrity": "sha512-SP5ihhv/uQa8vPuWKmbJrrzfv8lRUkDFC6qwgaWoorrflN1DEW0IGCa9w/PxUp8Ad3dbvXZPmpXdGiP3eyTzhg==", + "dev": true, + "dependencies": { + "@octokit/core": "^6.0.0", + "@octokit/plugin-paginate-rest": "^10.0.0", + "@octokit/plugin-retry": "^7.0.0", + "@octokit/plugin-throttling": "^9.0.0", + "@semantic-release/error": "^4.0.0", + "aggregate-error": "^5.0.0", + "debug": "^4.3.4", + "dir-glob": "^3.0.1", + "globby": "^14.0.0", + "http-proxy-agent": "^7.0.0", + "https-proxy-agent": "^7.0.0", + "issue-parser": "^7.0.0", + "lodash-es": "^4.17.21", + "mime": "^4.0.0", + "p-filter": "^4.0.0", + "url-join": "^5.0.0" + }, + "engines": { + "node": ">=20.8.1" + }, + "peerDependencies": { + "semantic-release": ">=20.1.0" + } + }, "node_modules/semantic-release/node_modules/aggregate-error": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-5.0.0.tgz", @@ -8733,6 +8975,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/semantic-release/node_modules/before-after-hook": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-3.0.2.tgz", + "integrity": "sha512-Nik3Sc0ncrMK4UUdXQmAnRtzmNQTAAXmXIopizwZ1W1t8QmfJj+zL4OA2I7XPTPW5z5TDqv4hRo/JzouDJnX3A==", + "dev": true + }, "node_modules/semantic-release/node_modules/clean-stack": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-5.2.0.tgz", @@ -8840,6 +9088,22 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/semantic-release/node_modules/issue-parser": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/issue-parser/-/issue-parser-7.0.0.tgz", + "integrity": "sha512-jgAw78HO3gs9UrKqJNQvfDj9Ouy8Mhu40fbEJ8yXff4MW8+/Fcn9iFjyWUQ6SKbX8ipPk3X5A3AyfYHRu6uVLw==", + "dev": true, + "dependencies": { + "lodash.capitalize": "^4.2.1", + "lodash.escaperegexp": "^4.1.2", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.uniqby": "^4.7.0" + }, + "engines": { + "node": "^18.17 || >=20.6.1" + } + }, "node_modules/semantic-release/node_modules/mimic-fn": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", @@ -8939,6 +9203,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/semantic-release/node_modules/universal-user-agent": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-7.0.2.tgz", + "integrity": "sha512-0JCqzSKnStlRRQfCdowvqy3cy0Dvtlb8xecj/H8JFZuCze4rwjPZQOgvFvn0Ws/usCHQFGpyr+pB9adaGwXn4Q==", + "dev": true + }, "node_modules/semver": { "version": "7.6.0", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", @@ -9525,6 +9795,27 @@ "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", "dev": true }, + "node_modules/thenify": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.1.tgz", + "integrity": "sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==", + "dev": true, + "dependencies": { + "any-promise": "^1.0.0" + } + }, + "node_modules/thenify-all": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/thenify-all/-/thenify-all-1.6.0.tgz", + "integrity": "sha512-RNxQH/qI8/t3thXJDwcstUO4zeqo64+Uy/+sNVRBx4Xn2OX+OZ9oP+iJnNFqplFra2ZUVeKCSa2oVWi3T4uVmA==", + "dev": true, + "dependencies": { + "thenify": ">= 3.1.0 < 4" + }, + "engines": { + "node": ">=0.8" + } + }, "node_modules/through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", diff --git a/package.json b/package.json index 3ce5c65..0f77c25 100644 --- a/package.json +++ b/package.json @@ -47,11 +47,11 @@ "README.md" ], "dependencies": { - "@cheqd/sdk": "^4.0.0-develop.1", - "@cheqd/ts-proto": "^3.4.0", - "@cosmjs/proto-signing": "^0.32.2", + "@cheqd/sdk": "^4.0.0", + "@cheqd/ts-proto": "^3.4.1", + "@cosmjs/proto-signing": "^0.32.3", "dotenv": "^16.4.5", - "express": "^4.18.2", + "express": "^4.19.2", "express-validator": "^7.0.1", "helmet": "^7.1.0", "node-cache": "^5.1.2", @@ -59,17 +59,17 @@ "swagger-ui-express": "^5.0.0" }, "devDependencies": { - "@playwright/test": "^1.41.2", + "@playwright/test": "^1.42.1", "@semantic-release/changelog": "^6.0.3", - "@semantic-release/commit-analyzer": "^11.1.0", + "@semantic-release/commit-analyzer": "^12.0.0", "@semantic-release/git": "^10.0.1", "@semantic-release/github": "^9.2.6", - "@semantic-release/npm": "^11.0.2", - "@semantic-release/release-notes-generator": "^12.1.0", + "@semantic-release/npm": "^12.0.0", + "@semantic-release/release-notes-generator": "^13.0.0", "@stablelib/base64": "^1.0.1", "@types/express": "^4.17.21", "@types/helmet": "^4.0.0", - "@types/node": "^20.11.19", + "@types/node": "^20.12.2", "@types/node-fetch": "^2.6.11", "@types/swagger-ui-express": "^4.1.6", "@types/uuid": "^9.0.8", @@ -78,12 +78,12 @@ "base64url": "^3.0.1", "conventional-changelog-conventionalcommits": "^7.0.2", "esbuild": "^0.19.12", - "eslint": "^8.56.0", + "eslint": "^8.57.0", "eslint-config-prettier": "^9.1.0", "eslint-config-typescript": "^3.0.0", "prettier": "^3.2.5", - "semantic-release": "^22.0.12", - "typescript": "^5.3.3" + "semantic-release": "^23.0.6", + "typescript": "^5.4.3" }, "publishConfig": { "registry": "https://registry.npmjs.org/", diff --git a/tests/did/did-deactivate.spec.ts b/tests/did/did-deactivate.spec.ts new file mode 100644 index 0000000..1285014 --- /dev/null +++ b/tests/did/did-deactivate.spec.ts @@ -0,0 +1,145 @@ +import { test, expect } from '@playwright/test'; +import { sign } from '@stablelib/ed25519'; +import { toString, fromString } from 'uint8arrays'; +import base64url from 'base64url'; + +import * as dotenv from 'dotenv'; +import { assert } from 'console'; + +dotenv.config(); + +const pub_key_base_64 = process.env.TEST_PUBLIC_KEY; +const priv_key_base_64 = process.env.TEST_PRIVATE_KEY; + +assert(pub_key_base_64, 'TEST_PUBLIC_KEY is not defined'); +assert(priv_key_base_64, 'TEST_PRIVATE_KEY is not defined'); + +const pubKeyHex = toString(fromString(pub_key_base_64 as string, 'base64pad'), 'base16'); +const privKeyBytes = base64url.toBuffer(priv_key_base_64 as string); + +let didPayload; +let didState; +let jobId; + +test('did-deactivate. Generate the payload', async ({ request }) => { + const payload = await request.get( + `/1.0/did-document?verificationMethod=JsonWebKey2020&methodSpecificIdAlgo=uuid&network=testnet&publicKeyHex=${pubKeyHex}` + ); + + expect(payload.status()).toBe(200); + + const body = await payload.json(); + expect(body.didDoc).toBeDefined(); + expect(body.key).toBeDefined(); + expect(body.key.kid).toBeDefined(); + expect(body.key.publicKeyHex).toBeDefined(); + + didPayload = body.didDoc; +}); + +test('did-deactivate. Initiate DID Create procedure', async ({ request }) => { + const payload = await request.post('/1.0/create', { + data: { + didDocument: didPayload, + secret: {}, + options: { + network: 'testnet', + }, + }, + }); + + expect(payload.status()).toBe(200); + + const body = await payload.json(); + + expect(body.jobId).toBeDefined(); + expect(body.didState).toBeDefined(); + expect(body.didState.did).toBeDefined(); + expect(body.didState.state).toBeDefined(); + expect(body.didState.secret).toBeDefined(); + + didState = body.didState; + jobId = body.jobId; +}); + +test('did-deactivate. Send the final request for DID creating', async ({ request }) => { + const serializedPayload = didState.signingRequest[0].serializedPayload; + const serializedBytes = Buffer.from(serializedPayload, 'base64'); + const signature = sign(privKeyBytes, serializedBytes); + + const secret = { + signingResponse: [ + { + kid: didState.signingRequest[0].kid, + signature: toString(signature, 'base64'), + }, + ], + }; + + const didCreate = await request.post(`/1.0/create/`, { + data: { + jobId: jobId, + secret: secret, + options: { + network: 'testnet', + }, + didDocument: didPayload, + }, + }); + + expect(didCreate.status()).toBe(201); +}); + +test('did-deactivate. Initiate DID Deactivate procedure', async ({ request }) => { + const payload = await request.post('/1.0/deactivate', { + data: { + did: didPayload.id, + secret: {}, + options: { + network: 'testnet', + }, + }, + }); + + expect(payload.status()).toBe(200); + + const body = await payload.json(); + + expect(body.jobId).toBeDefined(); + expect(body.didState).toBeDefined(); + expect(body.didState.did).toBeDefined(); + expect(body.didState.state).toBeDefined(); + expect(body.didState.secret).toBeDefined(); + + didState = body.didState; + jobId = body.jobId; +}); + +test('did-deactivate. Send the final request for DID deactivating', async ({ request }) => { + const serializedPayload = didState.signingRequest[0].serializedPayload; + const serializedBytes = Buffer.from(serializedPayload, 'base64'); + const signature = sign(privKeyBytes, serializedBytes); + + const secret = { + signingResponse: [ + { + kid: didState.signingRequest[0].kid, + signature: toString(signature, 'base64'), + }, + ], + }; + + const didDeactivate = await request.post(`/1.0/deactivate`, { + data: { + jobId: jobId, + secret: secret, + options: { + network: 'testnet', + }, + did: didPayload.id, + }, + }); + + expect(didDeactivate.status()).toBe(201); +}); + diff --git a/tests/did/did-update.spec.ts b/tests/did/did-update.spec.ts new file mode 100644 index 0000000..3a7852f --- /dev/null +++ b/tests/did/did-update.spec.ts @@ -0,0 +1,157 @@ +import { test, expect } from '@playwright/test'; +import { sign } from '@stablelib/ed25519'; +import { toString, fromString } from 'uint8arrays'; +import base64url from 'base64url'; + +import * as dotenv from 'dotenv'; +import { assert } from 'console'; + +dotenv.config(); + +const pub_key_base_64 = process.env.TEST_PUBLIC_KEY; +const priv_key_base_64 = process.env.TEST_PRIVATE_KEY; + +assert(pub_key_base_64, 'TEST_PUBLIC_KEY is not defined'); +assert(priv_key_base_64, 'TEST_PRIVATE_KEY is not defined'); + +const pubKeyHex = toString(fromString(pub_key_base_64 as string, 'base64pad'), 'base16'); +const privKeyBytes = base64url.toBuffer(priv_key_base_64 as string); + +let didPayload; +let didState; +let jobId; + +test('did-document. Generate the payload', async ({ request }) => { + const payload = await request.get( + `/1.0/did-document?verificationMethod=JsonWebKey2020&methodSpecificIdAlgo=uuid&network=testnet&publicKeyHex=${pubKeyHex}` + ); + + expect(payload.status()).toBe(200); + + const body = await payload.json(); + expect(body.didDoc).toBeDefined(); + expect(body.key).toBeDefined(); + expect(body.key.kid).toBeDefined(); + expect(body.key.publicKeyHex).toBeDefined(); + + didPayload = body.didDoc; +}); + +test('did-update. Initiate DID Create procedure', async ({ request }) => { + const payload = await request.post('/1.0/create', { + data: { + didDocument: didPayload, + secret: {}, + options: { + network: 'testnet', + }, + }, + }); + + expect(payload.status()).toBe(200); + + const body = await payload.json(); + + expect(body.jobId).toBeDefined(); + expect(body.didState).toBeDefined(); + expect(body.didState.did).toBeDefined(); + expect(body.didState.state).toBeDefined(); + expect(body.didState.secret).toBeDefined(); + + didState = body.didState; + jobId = body.jobId; +}); + +test('did-update. Send the final request for DID creating', async ({ request }) => { + const serializedPayload = didState.signingRequest[0].serializedPayload; + const serializedBytes = Buffer.from(serializedPayload, 'base64'); + const signature = sign(privKeyBytes, serializedBytes); + + const secret = { + signingResponse: [ + { + kid: didState.signingRequest[0].kid, + signature: toString(signature, 'base64'), + }, + ], + }; + + const didCreate = await request.post(`/1.0/create/`, { + data: { + jobId: jobId, + secret: secret, + options: { + network: 'testnet', + }, + didDocument: didPayload, + }, + }); + + expect(didCreate.status()).toBe(201); +}); + +test('did-update. Initiate DID Update procedure', async ({ request }) => { + // Change didPayload + didPayload = { + ...didPayload, + service: [ + { + id: `${didPayload.id}#service-1`, + type: 'URL', + serviceEndpoint: ['https://example.com/vc/'], + }, + ], + }; + const payload = await request.post('/1.0/update', { + data: { + didDocument: [didPayload], + did: didPayload.id, + secret: {}, + options: { + network: 'testnet', + }, + }, + }); + + expect(payload.status()).toBe(200); + + const body = await payload.json(); + + expect(body.jobId).toBeDefined(); + expect(body.didState).toBeDefined(); + expect(body.didState.did).toBeDefined(); + expect(body.didState.state).toBeDefined(); + expect(body.didState.secret).toBeDefined(); + + didState = body.didState; + jobId = body.jobId; +}); + +test('did-update. Send the final request for DID updating', async ({ request }) => { + const serializedPayload = didState.signingRequest[0].serializedPayload; + const serializedBytes = Buffer.from(serializedPayload, 'base64'); + const signature = sign(privKeyBytes, serializedBytes); + + const secret = { + signingResponse: [ + { + kid: didState.signingRequest[0].kid, + signature: toString(signature, 'base64'), + }, + ], + }; + + const didUpdate = await request.post(`/1.0/update`, { + data: { + jobId: jobId, + secret: secret, + options: { + network: 'testnet', + }, + didDocument: [didPayload], + did: didPayload.id, + }, + }); + + expect(didUpdate.status()).toBe(201); +}); \ No newline at end of file diff --git a/tests/resource/resource-create.spec.ts b/tests/resource/resource-create.spec.ts new file mode 100644 index 0000000..4b43494 --- /dev/null +++ b/tests/resource/resource-create.spec.ts @@ -0,0 +1,143 @@ +import { test, expect } from '@playwright/test'; +import { sign } from '@stablelib/ed25519'; +import { toString, fromString } from 'uint8arrays'; +import base64url from 'base64url'; + +import * as dotenv from 'dotenv'; +import { assert } from 'console'; + +dotenv.config(); + +const pub_key_base_64 = process.env.TEST_PUBLIC_KEY; +const priv_key_base_64 = process.env.TEST_PRIVATE_KEY; + +assert(pub_key_base_64, 'TEST_PUBLIC_KEY is not defined'); +assert(priv_key_base_64, 'TEST_PRIVATE_KEY is not defined'); + +const pubKeyHex = toString(fromString(pub_key_base_64 as string, 'base64pad'), 'base16'); +const privKeyBytes = base64url.toBuffer(priv_key_base_64 as string); + +let didPayload; +let didState; +let resourceState; +let jobId; + +test('did-document. Generate the payload', async ({ request }) => { + const payload = await request.get( + `/1.0/did-document?verificationMethod=JsonWebKey2020&methodSpecificIdAlgo=uuid&network=testnet&publicKeyHex=${pubKeyHex}` + ); + + expect(payload.status()).toBe(200); + + const body = await payload.json(); + expect(body.didDoc).toBeDefined(); + expect(body.key).toBeDefined(); + expect(body.key.kid).toBeDefined(); + expect(body.key.publicKeyHex).toBeDefined(); + + didPayload = body.didDoc; +}); + +test('resource-create. Initiate DID Create procedure', async ({ request }) => { + const payload = await request.post('/1.0/create', { + data: { + didDocument: didPayload, + secret: {}, + options: { + network: 'testnet', + }, + }, + }); + + expect(payload.status()).toBe(200); + + const body = await payload.json(); + + expect(body.jobId).toBeDefined(); + expect(body.didState).toBeDefined(); + expect(body.didState.did).toBeDefined(); + expect(body.didState.state).toBeDefined(); + expect(body.didState.secret).toBeDefined(); + + didState = body.didState; + jobId = body.jobId; +}); + +test('resource-create. Send the final request for DID creating', async ({ request }) => { + const serializedPayload = didState.signingRequest[0].serializedPayload; + const serializedBytes = Buffer.from(serializedPayload, 'base64'); + const signature = sign(privKeyBytes, serializedBytes); + + const secret = { + signingResponse: [ + { + kid: didState.signingRequest[0].kid, + signature: toString(signature, 'base64'), + }, + ], + }; + + const didCreate = await request.post(`/1.0/create/`, { + data: { + jobId: jobId, + secret: secret, + options: { + network: 'testnet', + }, + didDocument: didPayload, + }, + }); + + expect(didCreate.status()).toBe(201); +}); + +test('resource-create. Initiate Resource creation procedure', async ({ request }) => { + const payload = await request.post(`/1.0/${didPayload.id}/create-resource`, { + data: { + data: "SGVsbG8gV29ybGQ=", + name: "ResourceName", + type: "TextDocument" + }, + }); + + expect(payload.status()).toBe(200); + + const body = await payload.json(); + + expect(body.resourceState).toBeDefined(); + expect(body.resourceState).toBeDefined(); + + resourceState = body.resourceState; + jobId = body.jobId; +}); + +test('resource-create. Send the final request for Resource creating', async ({ request }) => { + const serializedPayload = resourceState.signingRequest[0].serializedPayload; + const serializedBytes = Buffer.from(serializedPayload, 'base64'); + const signature = sign(privKeyBytes, serializedBytes); + + const secret = { + signingResponse: [ + { + kid: resourceState.signingRequest[0].kid, + signature: toString(signature, 'base64'), + }, + ], + }; + + const resourceCreate = await request.post(`/1.0/${didPayload.id}/create-resource`, { + data: { + data: "SGVsbG8gV29ybGQ=", + name: "ResourceName", + type: "TextDocument", + jobId: jobId, + secret: secret, + options: { + network: 'testnet', + }, + did: didPayload.id, + }, + }); + + expect(resourceCreate.status()).toBe(201); +});