From 216f1ccf3667a018d95e09b00be8096e1c52b4a8 Mon Sep 17 00:00:00 2001 From: Javier Esses Date: Thu, 24 Sep 2020 13:29:25 -0300 Subject: [PATCH] Authentication module (#49) * initialize, add and delete credentials * Authentication reducer * serviceLogin operation * npm audit fix * Changed auth operations to prevent it to fail * Added tests and validation to auth operations * Improved tests, readability and return the token to be used by the callback after succesful login * Rebase * Moved internal closures out of the function with needed params curried * Update rif-id-daf version --- .gitignore | 3 + README.md | 1 + package-lock.json | 89 ++- packages/rif-id-core/package-lock.json | 657 ++---------------- packages/rif-id-core/package.json | 6 +- .../src/operations/authentication.ts | 52 ++ .../src/reducers/authentication.ts | 42 ++ .../test/operations/authentication.test.ts | 134 ++++ .../test/reducers/authentication.test.ts | 179 +++++ packages/rif-id-core/test/util.ts | 1 + 10 files changed, 536 insertions(+), 628 deletions(-) create mode 100644 packages/rif-id-core/src/operations/authentication.ts create mode 100644 packages/rif-id-core/src/reducers/authentication.ts create mode 100644 packages/rif-id-core/test/operations/authentication.test.ts create mode 100644 packages/rif-id-core/test/reducers/authentication.test.ts diff --git a/.gitignore b/.gitignore index d7b6d1d..a04d660 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,6 @@ lib coverage junit.xml *.sqlite + +# logs +*.log \ No newline at end of file diff --git a/README.md b/README.md index 4714942..fc4b27e 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Setup: ``` npm install npm run setup +npm run build ``` First installs global dependencies, then links inner packages, finally installs inner packages dependencies. diff --git a/package-lock.json b/package-lock.json index 99279ac..48b8d6b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4768,23 +4768,29 @@ "dev": true }, "compare-func": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/compare-func/-/compare-func-1.3.4.tgz", - "integrity": "sha512-sq2sWtrqKPkEXAC8tEJA1+BqAH9GbFkGBtUOqrUX57VSfwp8xyktctk+uLoRy5eccTdxzDcVIztlYDpKs3Jv1Q==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/compare-func/-/compare-func-2.0.0.tgz", + "integrity": "sha512-zHig5N+tPWARooBnb0Zx1MFcdfpyJrfTJ3Y5L+IFvUm8rM74hHz66z0gw0x4tijh5CorKkKUCnW82R2vmpeCRA==", "dev": true, "requires": { "array-ify": "^1.0.0", - "dot-prop": "^3.0.0" + "dot-prop": "^5.1.0" }, "dependencies": { "dot-prop": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-3.0.0.tgz", - "integrity": "sha1-G3CK8JSknJoOfbyteQq6U52sEXc=", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-5.3.0.tgz", + "integrity": "sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q==", "dev": true, "requires": { - "is-obj": "^1.0.0" + "is-obj": "^2.0.0" } + }, + "is-obj": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz", + "integrity": "sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w==", + "dev": true } } }, @@ -4835,13 +4841,40 @@ "dev": true }, "conventional-changelog-angular": { - "version": "5.0.10", - "resolved": "https://registry.npmjs.org/conventional-changelog-angular/-/conventional-changelog-angular-5.0.10.tgz", - "integrity": "sha512-k7RPPRs0vp8+BtPsM9uDxRl6KcgqtCJmzRD1wRtgqmhQ96g8ifBGo9O/TZBG23jqlXS/rg8BKRDELxfnQQGiaA==", + "version": "5.0.11", + "resolved": "https://registry.npmjs.org/conventional-changelog-angular/-/conventional-changelog-angular-5.0.11.tgz", + "integrity": "sha512-nSLypht/1yEflhuTogC03i7DX7sOrXGsRn14g131Potqi6cbGbGEE9PSDEHKldabB6N76HiSyw9Ph+kLmC04Qw==", "dev": true, "requires": { - "compare-func": "^1.3.1", + "compare-func": "^2.0.0", "q": "^1.5.1" + }, + "dependencies": { + "compare-func": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/compare-func/-/compare-func-2.0.0.tgz", + "integrity": "sha512-zHig5N+tPWARooBnb0Zx1MFcdfpyJrfTJ3Y5L+IFvUm8rM74hHz66z0gw0x4tijh5CorKkKUCnW82R2vmpeCRA==", + "dev": true, + "requires": { + "array-ify": "^1.0.0", + "dot-prop": "^5.1.0" + } + }, + "dot-prop": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-5.3.0.tgz", + "integrity": "sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q==", + "dev": true, + "requires": { + "is-obj": "^2.0.0" + } + }, + "is-obj": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz", + "integrity": "sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w==", + "dev": true + } } }, "conventional-changelog-core": { @@ -4942,12 +4975,12 @@ "dev": true }, "conventional-changelog-writer": { - "version": "4.0.16", - "resolved": "https://registry.npmjs.org/conventional-changelog-writer/-/conventional-changelog-writer-4.0.16.tgz", - "integrity": "sha512-jmU1sDJDZpm/dkuFxBeRXvyNcJQeKhGtVcFFkwTphUAzyYWcwz2j36Wcv+Mv2hU3tpvLMkysOPXJTLO55AUrYQ==", + "version": "4.0.17", + "resolved": "https://registry.npmjs.org/conventional-changelog-writer/-/conventional-changelog-writer-4.0.17.tgz", + "integrity": "sha512-IKQuK3bib/n032KWaSb8YlBFds+aLmzENtnKtxJy3+HqDq5kohu3g/UdNbIHeJWygfnEbZjnCKFxAW0y7ArZAw==", "dev": true, "requires": { - "compare-func": "^1.3.1", + "compare-func": "^2.0.0", "conventional-commits-filter": "^2.0.6", "dateformat": "^3.0.0", "handlebars": "^4.7.6", @@ -5666,9 +5699,9 @@ } }, "dot-prop": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.0.tgz", - "integrity": "sha512-tUMXrxlExSW6U2EXiiKGSBVdYgtV8qlHL+C10TsW4PURY/ic+eaysnSkwB4kA/mBlCyy/IKDJ+Lc3wbWeaXtuQ==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.1.tgz", + "integrity": "sha512-l0p4+mIuJIua0mhxGoh4a+iNL9bmeK5DvnSVQa6T0OhrVmaEa1XScX5Etc673FePCJOArq/4Pa2cLGODUWTPOQ==", "dev": true, "requires": { "is-obj": "^1.0.0" @@ -11964,9 +11997,9 @@ } }, "neo-async": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.1.tgz", - "integrity": "sha512-iyam8fBuCUpWeKPGpaNMetEocMt364qkCsfL9JuhjXX6dRnguRVOfk2GZaDpPjcOKiiXCPINZC1GczQ7iTq3Zw==", + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", + "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "dev": true }, "nice-try": { @@ -11982,9 +12015,9 @@ "dev": true }, "node-fetch": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", - "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==", + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==", "dev": true }, "node-fetch-npm": { @@ -14481,9 +14514,9 @@ "dev": true }, "uglify-js": { - "version": "3.10.0", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.10.0.tgz", - "integrity": "sha512-Esj5HG5WAyrLIdYU74Z3JdG2PxdIusvj6IWHMtlyESxc7kcDz7zYlYjpnSokn1UbpV0d/QX9fan7gkCNd/9BQA==", + "version": "3.10.4", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.10.4.tgz", + "integrity": "sha512-kBFT3U4Dcj4/pJ52vfjCSfyLyvG9VYYuGYPmrPvAxRw/i7xHiT4VvCev+uiEMcEEiu6UNB6KgWmGtSUYIWScbw==", "dev": true, "optional": true }, diff --git a/packages/rif-id-core/package-lock.json b/packages/rif-id-core/package-lock.json index 086c674..3f3017f 100644 --- a/packages/rif-id-core/package-lock.json +++ b/packages/rif-id-core/package-lock.json @@ -33,47 +33,6 @@ "ethr-did-registry": "0.0.3" } }, - "@rsksmart/rif-id-daf": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/@rsksmart/rif-id-daf/-/rif-id-daf-0.0.3.tgz", - "integrity": "sha512-e4zst/Qy3mzff6zapye/fqOUQ+39C/OVUDYOtFIowPu0qt9LGmaRtqbLXgn5TYcrkFBBOnvWCkWf+/tap0RfIw==", - "requires": { - "@rsksmart/rif-id-ethr-did": "0.0.1", - "@rsksmart/rif-id-mnemonic": "0.0.1", - "daf-core": "^6.1.2", - "daf-ethr-did": "^6.1.2", - "typeorm": "0.2.24" - } - }, - "@rsksmart/rif-id-ethr-did": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/@rsksmart/rif-id-ethr-did/-/rif-id-ethr-did-0.0.1.tgz", - "integrity": "sha512-TPIzZJac6P8xvrkTaD52HkSi59+g1UTla9ig11IE+8bLGRGwE1mtzhJoKcAUNG6MvWA/yelln7lqS1lf7vyrUQ==", - "requires": { - "@types/elliptic": "^6.4.12", - "@types/keccak": "^3.0.1", - "@types/lodash": "^4.14.157", - "@types/node": "^14.0.23", - "elliptic": "^6.5.3", - "ethr-did": "^1.1.0", - "keccak": "^3.0.0", - "lodash": "^4.17.19", - "rskjs-util": "^1.0.3" - } - }, - "@rsksmart/rif-id-mnemonic": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/@rsksmart/rif-id-mnemonic/-/rif-id-mnemonic-0.0.1.tgz", - "integrity": "sha512-8r9Qb+YTsXMNcoKA3Ki4dDy7emdUa5Ekx89Zv/zPjdEb0gVlajJFHvac75GLVWGtSrzz57bbiNpIRSFZqlF38Q==", - "requires": { - "@types/lodash": "^4.14.155", - "@types/randombytes": "^2.0.0", - "bip32": "^2.0.5", - "bip39": "^3.0.2", - "lodash": "^4.17.15", - "randombytes": "^2.1.0" - } - }, "@stablelib/binary": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@stablelib/binary/-/binary-1.0.0.tgz", @@ -131,14 +90,6 @@ "resolved": "https://registry.npmjs.org/@stablelib/wipe/-/wipe-1.0.0.tgz", "integrity": "sha512-0Fd4MQCbEh8OFSO+gG7wBXok7yRC3w+xe/wWM8KNye7EGoHr4BTFZNWV/1xAn2r8/gyFKxPXT8uxXRzDzGq6rg==" }, - "@types/bn.js": { - "version": "4.11.6", - "resolved": "https://registry.npmjs.org/@types/bn.js/-/bn.js-4.11.6.tgz", - "integrity": "sha512-pqr857jrp2kPuO9uRjZ3PwnJTjoQy+fcdxvBTvHm6dkmEL9q+hDD/2j/0ELOBPtPnS8LjCX0gI9nbl8lVkadpg==", - "requires": { - "@types/node": "*" - } - }, "@types/body-parser": { "version": "1.19.0", "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.0.tgz", @@ -163,14 +114,6 @@ "@types/node": "*" } }, - "@types/elliptic": { - "version": "6.4.12", - "resolved": "https://registry.npmjs.org/@types/elliptic/-/elliptic-6.4.12.tgz", - "integrity": "sha512-gP1KsqoouLJGH6IJa28x7PXb3cRqh83X8HCLezd2dF+XcAIMKYv53KV+9Zn6QA561E120uOqZBQ+Jy/cl+fviw==", - "requires": { - "@types/bn.js": "*" - } - }, "@types/express": { "version": "4.17.8", "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.8.tgz", @@ -194,19 +137,6 @@ "@types/range-parser": "*" } }, - "@types/keccak": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@types/keccak/-/keccak-3.0.1.tgz", - "integrity": "sha512-/MxAVmtyyeOvZ6dGf3ciLwFRuV5M8DRIyYNFGHYI6UyBW4/XqyO0LZw+JFMvaeY3cHItQAkELclBU1x5ank6mg==", - "requires": { - "@types/node": "*" - } - }, - "@types/lodash": { - "version": "4.14.161", - "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.161.tgz", - "integrity": "sha512-EP6O3Jkr7bXvZZSZYlsgt5DIjiGr0dXP1/jVEwVLTFgg0d+3lWVQkRavYVQszV7dYUwvg0B8R0MBDpcmXg7XIA==" - }, "@types/mime": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@types/mime/-/mime-2.0.3.tgz", @@ -216,7 +146,8 @@ "@types/node": { "version": "14.10.2", "resolved": "https://registry.npmjs.org/@types/node/-/node-14.10.2.tgz", - "integrity": "sha512-IzMhbDYCpv26pC2wboJ4MMOa9GKtjplXfcAqrMeNJpUUwpM/2ATt2w1JPUXwS6spu856TvKZL2AOmeU2rAxskw==" + "integrity": "sha512-IzMhbDYCpv26pC2wboJ4MMOa9GKtjplXfcAqrMeNJpUUwpM/2ATt2w1JPUXwS6spu856TvKZL2AOmeU2rAxskw==", + "dev": true }, "@types/qs": { "version": "6.9.5", @@ -224,14 +155,6 @@ "integrity": "sha512-/JHkVHtx/REVG0VVToGRGH2+23hsYLHdyG+GrvoUGlGAd0ErauXDyvHtRI/7H7mzLm+tBCKA7pfcpkQ1lf58iQ==", "dev": true }, - "@types/randombytes": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@types/randombytes/-/randombytes-2.0.0.tgz", - "integrity": "sha512-bz8PhAVlwN72vqefzxa14DKNT8jK/mV66CSjwdVQM/k3Th3EPKfUtdMniwZgMedQTFuywAsfjnZsg+pEnltaMA==", - "requires": { - "@types/node": "*" - } - }, "@types/range-parser": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.3.tgz", @@ -295,29 +218,19 @@ "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=", "dev": true }, - "babel-plugin-module-resolver": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/babel-plugin-module-resolver/-/babel-plugin-module-resolver-3.2.0.tgz", - "integrity": "sha512-tjR0GvSndzPew/Iayf4uICWZqjBwnlMWjSx6brryfQ81F9rxBVqwDJtFCV8oOs0+vJeefK9TmdZtkIFdFe1UnA==", + "axios": { + "version": "0.20.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.20.0.tgz", + "integrity": "sha512-ANA4rr2BDcmmAQLOKft2fufrtuvlqR+cXNNinUmvfeSNCOF98PZL+7M/v1zIdGo7OLjEA9J2gXJL+j4zGsl0bA==", "requires": { - "find-babel-config": "^1.1.0", - "glob": "^7.1.2", - "pkg-up": "^2.0.0", - "reselect": "^3.0.1", - "resolve": "^1.4.0" - }, - "dependencies": { - "reselect": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/reselect/-/reselect-3.0.1.tgz", - "integrity": "sha1-79qpjqdFEyTQkrKyFjpqHXqaIUc=" - } + "follow-redirects": "^1.10.0" } }, "babel-runtime": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=", + "dev": true, "requires": { "core-js": "^2.4.0", "regenerator-runtime": "^0.11.0" @@ -326,7 +239,8 @@ "regenerator-runtime": { "version": "0.11.1", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", - "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==" + "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==", + "dev": true } } }, @@ -341,71 +255,11 @@ "integrity": "sha1-hdPnAlEHVmGTM4j4MdHri49jFOM=", "dev": true }, - "base-x": { - "version": "3.0.8", - "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.8.tgz", - "integrity": "sha512-Rl/1AWP4J/zRrk54hhlxH4drNxPJXYUaKffODVI53/dAsV4t9fBxyxYKAVPU1XBHxYwOWP9h9H0hM2MVw4YfJA==", - "requires": { - "safe-buffer": "^5.0.1" - } - }, "base64-js": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.1.tgz", "integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==" }, - "base64url": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/base64url/-/base64url-3.0.1.tgz", - "integrity": "sha512-ir1UPr3dkwexU7FdV8qBBbNDRUhMmIekYMFZfi+C/sLNnRESKPl23nB9b2pltqfOQNnGzsDdId90AEtG5tCx4A==" - }, - "bindings": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", - "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", - "requires": { - "file-uri-to-path": "1.0.0" - } - }, - "bip32": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/bip32/-/bip32-2.0.5.tgz", - "integrity": "sha512-zVY4VvJV+b2fS0/dcap/5XLlpqtgwyN8oRkuGgAS1uLOeEp0Yo6Tw2yUTozTtlrMJO3G8n4g/KX/XGFHW6Pq3g==", - "requires": { - "@types/node": "10.12.18", - "bs58check": "^2.1.1", - "create-hash": "^1.2.0", - "create-hmac": "^1.1.7", - "tiny-secp256k1": "^1.1.3", - "typeforce": "^1.11.5", - "wif": "^2.0.6" - }, - "dependencies": { - "@types/node": { - "version": "10.12.18", - "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.18.tgz", - "integrity": "sha512-fh+pAqt4xRzPfqA6eh3Z2y6fyZavRIumvjhaCL753+TVkGKGhpPeyrJG2JftD0T9q4GF00KjefsQ+PQNDdWQaQ==" - } - } - }, - "bip39": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/bip39/-/bip39-3.0.2.tgz", - "integrity": "sha512-J4E1r2N0tUylTKt07ibXvhpT2c5pyAFgvuA5q1H9uDy6dEGpjV8jmymh3MTYJDLCNbIVClSB9FbND49I6N24MQ==", - "requires": { - "@types/node": "11.11.6", - "create-hash": "^1.1.0", - "pbkdf2": "^3.0.9", - "randombytes": "^2.0.1" - }, - "dependencies": { - "@types/node": { - "version": "11.11.6", - "resolved": "https://registry.npmjs.org/@types/node/-/node-11.11.6.tgz", - "integrity": "sha512-Exw4yUWMBXM3X+8oqzJNRqZSwUAaS4+7NdvHqQuFi/d+synz++xmX3QIf+BFqneW8N31R8Ky+sikfZUXq07ggQ==" - } - } - }, "blakejs": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/blakejs/-/blakejs-1.1.0.tgz", @@ -465,24 +319,6 @@ "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz", "integrity": "sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8=" }, - "bs58": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz", - "integrity": "sha1-vhYedsNU9veIrkBx9j806MTwpCo=", - "requires": { - "base-x": "^3.0.2" - } - }, - "bs58check": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/bs58check/-/bs58check-2.1.2.tgz", - "integrity": "sha512-0TS1jicxdU09dwJMNZtVAfzPi6Q6QeN0pM1Fkzrjn+XYHvzMKPU3pHVpva+769iNVSfIYWf7LJ6WR+BuuMf8cA==", - "requires": { - "bs58": "^4.0.0", - "create-hash": "^1.1.0", - "safe-buffer": "^5.1.2" - } - }, "buffer": { "version": "5.6.0", "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.6.0.tgz", @@ -513,15 +349,6 @@ "supports-color": "^5.3.0" } }, - "cipher-base": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.4.tgz", - "integrity": "sha512-Kkht5ye6ZGmwv40uUDZztayT2ThLQGfnj/T71N/XzeZeo3nf8foyW7zGTsPYkEya3m5f3cAypH+qe7YOrM1U2Q==", - "requires": { - "inherits": "^2.0.1", - "safe-buffer": "^5.0.1" - } - }, "cli-highlight": { "version": "2.1.4", "resolved": "https://registry.npmjs.org/cli-highlight/-/cli-highlight-2.1.4.tgz", @@ -665,32 +492,8 @@ "core-js": { "version": "2.6.11", "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.11.tgz", - "integrity": "sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg==" - }, - "create-hash": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz", - "integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==", - "requires": { - "cipher-base": "^1.0.1", - "inherits": "^2.0.1", - "md5.js": "^1.3.4", - "ripemd160": "^2.0.1", - "sha.js": "^2.4.0" - } - }, - "create-hmac": { - "version": "1.1.7", - "resolved": "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz", - "integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==", - "requires": { - "cipher-base": "^1.0.3", - "create-hash": "^1.1.0", - "inherits": "^2.0.1", - "ripemd160": "^2.0.0", - "safe-buffer": "^5.0.1", - "sha.js": "^2.4.8" - } + "integrity": "sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg==", + "dev": true }, "cross-fetch": { "version": "3.0.5", @@ -786,32 +589,6 @@ } } }, - "daf-ethr-did": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/daf-ethr-did/-/daf-ethr-did-6.3.0.tgz", - "integrity": "sha512-2vMjmvYa0ZxbgRQzAmaBV4fSgr30QH+ftnnODbdxcqWFC0asxysZJcSvHwJMfrYsjrsqVv99gtrTkB7cXx4e+A==", - "requires": { - "daf-core": "^6.3.0", - "debug": "^4.1.1", - "ethjs-provider-signer": "^0.1.4", - "ethr-did": "^1.1.0", - "js-sha3": "^0.8.0" - }, - "dependencies": { - "daf-core": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/daf-core/-/daf-core-6.3.0.tgz", - "integrity": "sha512-CZfpGs27OErWMCGTNA3SCBMDvExnAtrHD591iZenusztXKBdLjO/L7Y5y/akoQGH+drTt0WPN7bzpI6/jcx/1A==", - "requires": { - "blakejs": "^1.1.0", - "debug": "^4.1.1", - "events": "^3.0.0", - "typeorm": "^0.2.24", - "uuid": "^7.0.2" - } - } - } - }, "daf-libsodium": { "version": "6.1.2", "resolved": "https://registry.npmjs.org/daf-libsodium/-/daf-libsodium-6.1.2.tgz", @@ -879,7 +656,6 @@ "version": "6.3.0", "resolved": "https://registry.npmjs.org/daf-w3c/-/daf-w3c-6.3.0.tgz", "integrity": "sha512-XmwYNjLpnC3snv2S+VzBcILt+N9wK10jOIE0nzNxyN49xWXw2+CeL9qjrJ2QcyrXLBR4enSdtZ95Dcn/QkT5mg==", - "dev": true, "requires": { "blakejs": "^1.1.0", "daf-core": "^6.3.0", @@ -893,7 +669,6 @@ "version": "6.3.0", "resolved": "https://registry.npmjs.org/daf-core/-/daf-core-6.3.0.tgz", "integrity": "sha512-CZfpGs27OErWMCGTNA3SCBMDvExnAtrHD591iZenusztXKBdLjO/L7Y5y/akoQGH+drTt0WPN7bzpI6/jcx/1A==", - "dev": true, "requires": { "blakejs": "^1.1.0", "debug": "^4.1.1", @@ -905,8 +680,7 @@ "did-resolver": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/did-resolver/-/did-resolver-1.1.0.tgz", - "integrity": "sha512-Q02Sc5VuQnJzzR8fQ/DzyCHiYb31WpQdocOsxppI66wwT4XalYRDeCr3a48mL6sYPQo76AkBh0mxte9ZBuQzxA==", - "dev": true + "integrity": "sha512-Q02Sc5VuQnJzzR8fQ/DzyCHiYb31WpQdocOsxppI66wwT4XalYRDeCr3a48mL6sYPQo76AkBh0mxte9ZBuQzxA==" } } }, @@ -955,7 +729,6 @@ "version": "0.2.0", "resolved": "https://registry.npmjs.org/did-jwt-vc/-/did-jwt-vc-0.2.0.tgz", "integrity": "sha512-YlIXA3GLryD9nlHOUAzYaU6UMVvZ3103HVBILuGLvRTnE9YVmlfc6nMuYOcIzbgLW2P8pZgIgZsyEFzRdkDRFg==", - "dev": true, "requires": { "did-jwt": "^4.3.2" } @@ -1110,6 +883,7 @@ "version": "0.2.1", "resolved": "https://registry.npmjs.org/ethjs-abi/-/ethjs-abi-0.2.1.tgz", "integrity": "sha1-4KepOn6BFjqUR3utVu3lJKtt5TM=", + "dev": true, "requires": { "bn.js": "4.11.6", "js-sha3": "0.5.5", @@ -1119,17 +893,20 @@ "bn.js": { "version": "4.11.6", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz", - "integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=" + "integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=", + "dev": true }, "js-sha3": { "version": "0.5.5", "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.5.5.tgz", - "integrity": "sha1-uvDA6MVK1ZA0R9+Wreekobynmko=" + "integrity": "sha1-uvDA6MVK1ZA0R9+Wreekobynmko=", + "dev": true }, "number-to-bn": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/number-to-bn/-/number-to-bn-1.7.0.tgz", "integrity": "sha1-uzYjWS9+X54AMLGXe9QaDFP+HqA=", + "dev": true, "requires": { "bn.js": "4.11.6", "strip-hex-prefix": "1.0.0" @@ -1141,6 +918,7 @@ "version": "0.1.9", "resolved": "https://registry.npmjs.org/ethjs-contract/-/ethjs-contract-0.1.9.tgz", "integrity": "sha1-HCdmiWpW1H7B1tZhgpxJzDilUgo=", + "dev": true, "requires": { "ethjs-abi": "0.2.0", "ethjs-filter": "0.1.5", @@ -1151,12 +929,14 @@ "bn.js": { "version": "4.11.6", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz", - "integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=" + "integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=", + "dev": true }, "ethjs-abi": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/ethjs-abi/-/ethjs-abi-0.2.0.tgz", "integrity": "sha1-0+LCIQEVIPxJm3FoIDbBT8wvWyU=", + "dev": true, "requires": { "bn.js": "4.11.6", "js-sha3": "0.5.5", @@ -1166,12 +946,14 @@ "js-sha3": { "version": "0.5.5", "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.5.5.tgz", - "integrity": "sha1-uvDA6MVK1ZA0R9+Wreekobynmko=" + "integrity": "sha1-uvDA6MVK1ZA0R9+Wreekobynmko=", + "dev": true }, "number-to-bn": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/number-to-bn/-/number-to-bn-1.7.0.tgz", "integrity": "sha1-uzYjWS9+X54AMLGXe9QaDFP+HqA=", + "dev": true, "requires": { "bn.js": "4.11.6", "strip-hex-prefix": "1.0.0" @@ -1182,12 +964,14 @@ "ethjs-filter": { "version": "0.1.5", "resolved": "https://registry.npmjs.org/ethjs-filter/-/ethjs-filter-0.1.5.tgz", - "integrity": "sha1-ARKvYBfCRnfjK4/esg5hlgGbdZg=" + "integrity": "sha1-ARKvYBfCRnfjK4/esg5hlgGbdZg=", + "dev": true }, "ethjs-format": { "version": "0.2.7", "resolved": "https://registry.npmjs.org/ethjs-format/-/ethjs-format-0.2.7.tgz", "integrity": "sha512-uNYAi+r3/mvR3xYu2AfSXx5teP4ovy9z2FrRsblU+h2logsaIKZPi9V3bn3V7wuRcnG0HZ3QydgZuVaRo06C4Q==", + "dev": true, "requires": { "bn.js": "4.11.6", "ethjs-schema": "0.2.1", @@ -1200,12 +984,14 @@ "bn.js": { "version": "4.11.6", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz", - "integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=" + "integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=", + "dev": true }, "number-to-bn": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/number-to-bn/-/number-to-bn-1.7.0.tgz", "integrity": "sha1-uzYjWS9+X54AMLGXe9QaDFP+HqA=", + "dev": true, "requires": { "bn.js": "4.11.6", "strip-hex-prefix": "1.0.0" @@ -1217,65 +1003,16 @@ "version": "0.1.6", "resolved": "https://registry.npmjs.org/ethjs-provider-http/-/ethjs-provider-http-0.1.6.tgz", "integrity": "sha1-HsXZtL4lfvHValALIqdBmF6IlCA=", + "dev": true, "requires": { "xhr2": "0.1.3" } }, - "ethjs-provider-signer": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/ethjs-provider-signer/-/ethjs-provider-signer-0.1.4.tgz", - "integrity": "sha1-a9XLOKjVsN30asHiOmDuoXFhca4=", - "requires": { - "ethjs-provider-http": "0.1.6", - "ethjs-rpc": "0.1.2" - }, - "dependencies": { - "bn.js": { - "version": "4.11.6", - "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz", - "integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=" - }, - "ethjs-format": { - "version": "0.1.8", - "resolved": "https://registry.npmjs.org/ethjs-format/-/ethjs-format-0.1.8.tgz", - "integrity": "sha1-kl7N2WXqcqKi2vKhIuW/gLWtUio=", - "requires": { - "bn.js": "4.11.6", - "ethjs-schema": "0.1.4", - "ethjs-util": "0.1.3", - "is-hex-prefixed": "1.0.0", - "number-to-bn": "1.7.0", - "strip-hex-prefix": "1.0.0" - } - }, - "ethjs-rpc": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/ethjs-rpc/-/ethjs-rpc-0.1.2.tgz", - "integrity": "sha1-OaNFa1HFmu6vtbpVZYmlny2ojSY=", - "requires": { - "ethjs-format": "0.1.8" - } - }, - "ethjs-schema": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/ethjs-schema/-/ethjs-schema-0.1.4.tgz", - "integrity": "sha1-AyOhYzOxrOmo8daWpu5jRI/dRV8=" - }, - "number-to-bn": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/number-to-bn/-/number-to-bn-1.7.0.tgz", - "integrity": "sha1-uzYjWS9+X54AMLGXe9QaDFP+HqA=", - "requires": { - "bn.js": "4.11.6", - "strip-hex-prefix": "1.0.0" - } - } - } - }, "ethjs-query": { "version": "0.3.8", "resolved": "https://registry.npmjs.org/ethjs-query/-/ethjs-query-0.3.8.tgz", "integrity": "sha512-/J5JydqrOzU8O7VBOwZKUWXxHDGr46VqNjBCJgBVNNda+tv7Xc8Y2uJc6aMHHVbeN3YOQ7YRElgIc0q1CI02lQ==", + "dev": true, "requires": { "babel-runtime": "^6.26.0", "ethjs-format": "0.2.7", @@ -1287,6 +1024,7 @@ "version": "0.2.0", "resolved": "https://registry.npmjs.org/ethjs-rpc/-/ethjs-rpc-0.2.0.tgz", "integrity": "sha512-RINulkNZTKnj4R/cjYYtYMnFFaBcVALzbtEJEONrrka8IeoarNB9Jbzn+2rT00Cv8y/CxAI+GgY1d0/i2iQeOg==", + "dev": true, "requires": { "promise-to-callback": "^1.0.0" } @@ -1294,7 +1032,8 @@ "ethjs-schema": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/ethjs-schema/-/ethjs-schema-0.2.1.tgz", - "integrity": "sha512-DXd8lwNrhT9sjsh/Vd2Z+4pfyGxhc0POVnLBUfwk5udtdoBzADyq+sK39dcb48+ZU+2VgtwHxtGWnLnCfmfW5g==" + "integrity": "sha512-DXd8lwNrhT9sjsh/Vd2Z+4pfyGxhc0POVnLBUfwk5udtdoBzADyq+sK39dcb48+ZU+2VgtwHxtGWnLnCfmfW5g==", + "dev": true }, "ethjs-signer": { "version": "0.1.1", @@ -1361,69 +1100,17 @@ "version": "0.1.3", "resolved": "https://registry.npmjs.org/ethjs-util/-/ethjs-util-0.1.3.tgz", "integrity": "sha1-39XqSkANxeQhqInK9H4IGtp4u1U=", + "dev": true, "requires": { "is-hex-prefixed": "1.0.0", "strip-hex-prefix": "1.0.0" } }, - "ethr-did": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/ethr-did/-/ethr-did-1.1.0.tgz", - "integrity": "sha512-sk5Q7mM+zC8IpffQaWXyCLZLSVMoasgpZJXZ++7ONslGEJQfs1fcvqvXZ5zLoHqYjVud9I8LpXTgbpGJsONY+A==", - "requires": { - "@babel/runtime": "^7.3.1", - "buffer": "^5.1.0", - "did-jwt": "^0.1.1", - "did-resolver": "^0.0.6", - "ethjs-contract": "^0.1.9", - "ethjs-provider-http": "^0.1.6", - "ethjs-query": "^0.3.8", - "ethr-did-resolver": "^0.2.0" - }, - "dependencies": { - "did-jwt": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/did-jwt/-/did-jwt-0.1.3.tgz", - "integrity": "sha512-hZvjC4bstxo6bqFIOAlX90LdSaA5uxMdg0zSFCPm2WwIhgHFp4SfVM6f5yq1ebA5/cJzcUr+MclnTrlEiixuiQ==", - "requires": { - "@babel/runtime": "^7.3.1", - "base64url": "^3.0.1", - "buffer": "^5.2.1", - "did-resolver": "0.0.6", - "elliptic": "^6.4.0", - "js-sha256": "^0.9.0", - "js-sha3": "^0.8.0", - "tweetnacl": "^1.0.1", - "tweetnacl-util": "^0.15.0" - } - }, - "did-resolver": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/did-resolver/-/did-resolver-0.0.6.tgz", - "integrity": "sha512-PqxzaoomTbJG3IzEouUGgppu3xrsbGKHS75zS3vS/Hfm56XxLpwIe7yFLokgXUbMWmLa0dczFHOibmebO4wRLA==" - }, - "ethr-did-resolver": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/ethr-did-resolver/-/ethr-did-resolver-0.2.0.tgz", - "integrity": "sha512-6ysQhoDa8vGFesECQfxFkEV+DVFMhcWJ35qgMVk0F8a9i7Iy9Fl29cM/5U7JCgBjZoaPrSKCMmNK4rfFNrYc4A==", - "requires": { - "babel-plugin-module-resolver": "^3.1.1", - "babel-runtime": "^6.26.0", - "buffer": "^5.1.0", - "did-resolver": "0.0.6", - "ethjs-abi": "^0.2.1", - "ethjs-contract": "^0.1.9", - "ethjs-provider-http": "^0.1.6", - "ethjs-query": "^0.3.5", - "ethr-did-registry": "^0.0.3" - } - } - } - }, "ethr-did-registry": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/ethr-did-registry/-/ethr-did-registry-0.0.3.tgz", - "integrity": "sha512-4BPvMGkxAK9vTduCq6D5b8ZqjteD2cvDIPPriXP6nnmPhWKFSxypo+AFvyQ0omJGa0cGTR+dkdI/8jiF7U/qaw==" + "integrity": "sha512-4BPvMGkxAK9vTduCq6D5b8ZqjteD2cvDIPPriXP6nnmPhWKFSxypo+AFvyQ0omJGa0cGTR+dkdI/8jiF7U/qaw==", + "dev": true }, "ethr-did-resolver": { "version": "2.2.0", @@ -1519,11 +1206,6 @@ "resolved": "https://registry.npmjs.org/figlet/-/figlet-1.5.0.tgz", "integrity": "sha512-ZQJM4aifMpz6H19AW1VqvZ7l4pOE9p7i/3LyxgO2kp+PO/VcDYNqIHEMtkccqIhTXMKci4kjueJr/iCQEaT/Ww==" }, - "file-uri-to-path": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", - "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" - }, "finalhandler": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", @@ -1556,22 +1238,6 @@ } } }, - "find-babel-config": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/find-babel-config/-/find-babel-config-1.2.0.tgz", - "integrity": "sha512-jB2CHJeqy6a820ssiqwrKMeyC6nNdmrcgkKWJWmpoxpE8RKciYJXCcXRq1h2AzCo5I5BJeN2tkGEO3hLTuePRA==", - "requires": { - "json5": "^0.5.1", - "path-exists": "^3.0.0" - }, - "dependencies": { - "path-exists": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", - "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=" - } - } - }, "find-up": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", @@ -1581,6 +1247,11 @@ "path-exists": "^4.0.0" } }, + "follow-redirects": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.0.tgz", + "integrity": "sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==" + }, "forwarded": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", @@ -1636,16 +1307,6 @@ "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" }, - "hash-base": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.1.0.tgz", - "integrity": "sha512-1nmYp/rhMDiE7AYkDw+lLwlAzz0AntGIe51F3RfFfEqyQ3feY2eI/NcwC6umIQVOASPMsWJLJScWKSSvzL9IVA==", - "requires": { - "inherits": "^2.0.4", - "readable-stream": "^3.6.0", - "safe-buffer": "^5.2.0" - } - }, "hash.js": { "version": "1.1.7", "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.7.tgz", @@ -1733,7 +1394,8 @@ "is-fn": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-fn/-/is-fn-1.0.0.tgz", - "integrity": "sha1-lUPV3nvPWwiiLsiiC65uKG1RDYw=" + "integrity": "sha1-lUPV3nvPWwiiLsiiC65uKG1RDYw=", + "dev": true }, "is-fullwidth-code-point": { "version": "3.0.0", @@ -1743,7 +1405,8 @@ "is-hex-prefixed": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-hex-prefixed/-/is-hex-prefixed-1.0.0.tgz", - "integrity": "sha1-fY035q135dEnFIkTxXPggtd39VQ=" + "integrity": "sha1-fY035q135dEnFIkTxXPggtd39VQ=", + "dev": true }, "js-sha256": { "version": "0.9.0", @@ -1769,20 +1432,6 @@ "esprima": "^4.0.0" } }, - "json5": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/json5/-/json5-0.5.1.tgz", - "integrity": "sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE=" - }, - "keccak": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/keccak/-/keccak-3.0.1.tgz", - "integrity": "sha512-epq90L9jlFWCW7+pQa6JOnKn2Xgl2mtI664seYR6MHskvI9agt7AnDqmAlp9TqU4/caMYbA08Hi5DMZAl5zdkA==", - "requires": { - "node-addon-api": "^2.0.0", - "node-gyp-build": "^4.2.0" - } - }, "libsodium": { "version": "0.7.8", "resolved": "https://registry.npmjs.org/libsodium/-/libsodium-0.7.8.tgz", @@ -1806,11 +1455,6 @@ "p-locate": "^4.1.0" } }, - "lodash": { - "version": "4.17.20", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", - "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==" - }, "loose-envify": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", @@ -1819,16 +1463,6 @@ "js-tokens": "^3.0.0 || ^4.0.0" } }, - "md5.js": { - "version": "1.3.5", - "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz", - "integrity": "sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg==", - "requires": { - "hash-base": "^3.0.0", - "inherits": "^2.0.1", - "safe-buffer": "^5.1.2" - } - }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -1934,27 +1568,12 @@ } } }, - "nan": { - "version": "2.14.1", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.1.tgz", - "integrity": "sha512-isWHgVjnFjh2x2yuJ/tj3JbwoHu3UC2dX5G/88Cm24yB6YopVgxvBObDY7n5xW6ExmFhJpSEQqFPvq9zaXc8Jw==" - }, "negotiator": { "version": "0.6.2", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==", "dev": true }, - "node-addon-api": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz", - "integrity": "sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA==" - }, - "node-gyp-build": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.2.3.tgz", - "integrity": "sha512-MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg==" - }, "number-to-bn": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/number-to-bn/-/number-to-bn-1.1.0.tgz", @@ -2051,86 +1670,17 @@ "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, - "path-parse": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", - "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==" - }, "path-to-regexp": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=", "dev": true }, - "pbkdf2": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.1.1.tgz", - "integrity": "sha512-4Ejy1OPxi9f2tt1rRV7Go7zmfDQ+ZectEQz3VGUQhgq62HtIRPDyG/JtnwIxs6x3uNMwo2V7q1fMvKjb+Tnpqg==", - "requires": { - "create-hash": "^1.1.2", - "create-hmac": "^1.1.4", - "ripemd160": "^2.0.1", - "safe-buffer": "^5.0.1", - "sha.js": "^2.4.8" - } - }, - "pkg-up": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/pkg-up/-/pkg-up-2.0.0.tgz", - "integrity": "sha1-yBmscoBZpGHKscOImivjxJoATX8=", - "requires": { - "find-up": "^2.1.0" - }, - "dependencies": { - "find-up": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", - "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", - "requires": { - "locate-path": "^2.0.0" - } - }, - "locate-path": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", - "integrity": "sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=", - "requires": { - "p-locate": "^2.0.0", - "path-exists": "^3.0.0" - } - }, - "p-limit": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", - "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", - "requires": { - "p-try": "^1.0.0" - } - }, - "p-locate": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", - "integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=", - "requires": { - "p-limit": "^1.1.0" - } - }, - "p-try": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", - "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=" - }, - "path-exists": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", - "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=" - } - } - }, "promise-to-callback": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/promise-to-callback/-/promise-to-callback-1.0.0.tgz", "integrity": "sha1-XSp0kBC/tn2WNZj805YHRqaP7vc=", + "dev": true, "requires": { "is-fn": "^1.0.0", "set-immediate-shim": "^1.0.1" @@ -2152,14 +1702,6 @@ "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==", "dev": true }, - "randombytes": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", - "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", - "requires": { - "safe-buffer": "^5.1.0" - } - }, "range-parser": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", @@ -2178,16 +1720,6 @@ "unpipe": "1.0.0" } }, - "readable-stream": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", - "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", - "requires": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - } - }, "redux": { "version": "4.0.5", "resolved": "https://registry.npmjs.org/redux/-/redux-4.0.5.tgz", @@ -2227,50 +1759,12 @@ "resolved": "https://registry.npmjs.org/reselect/-/reselect-4.0.0.tgz", "integrity": "sha512-qUgANli03jjAyGlnbYVAV5vvnOmJnODyABz51RdBN7M4WaVu8mecZWgyQNkG8Yqe3KRGRt0l4K4B3XVEULC4CA==" }, - "resolve": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz", - "integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==", - "requires": { - "path-parse": "^1.0.6" - } - }, - "ripemd160": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.2.tgz", - "integrity": "sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA==", - "requires": { - "hash-base": "^3.0.0", - "inherits": "^2.0.1" - } - }, "rlp": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/rlp/-/rlp-2.0.0.tgz", "integrity": "sha1-nbOE/0uJqPYVY9kjldhiWxjzr7A=", "dev": true }, - "rskjs-util": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/rskjs-util/-/rskjs-util-1.0.3.tgz", - "integrity": "sha512-Q6zfYFQndaBln1iY2gnBfYgDLymbZHAxKXOcZVLAKJkHilcieoUN3ZXVxLA3K30KlgAfmRVG72iTzi+yPNZB1w==", - "requires": { - "keccak": "^1.0.2" - }, - "dependencies": { - "keccak": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/keccak/-/keccak-1.4.0.tgz", - "integrity": "sha512-eZVaCpblK5formjPjeTBik7TAg+pqnDrMHIffSvi9Lh7PQgM1+hSzakUeZFCk9DVVG0dacZJuaz2ntwlzZUIBw==", - "requires": { - "bindings": "^1.2.1", - "inherits": "^2.0.3", - "nan": "^2.2.1", - "safe-buffer": "^5.1.0" - } - } - } - }, "safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -2353,7 +1847,8 @@ "set-immediate-shim": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/set-immediate-shim/-/set-immediate-shim-1.0.1.tgz", - "integrity": "sha1-SysbJ+uAip+NzEgaWOXlb1mfP2E=" + "integrity": "sha1-SysbJ+uAip+NzEgaWOXlb1mfP2E=", + "dev": true }, "setprototypeof": { "version": "1.1.1", @@ -2391,14 +1886,6 @@ "strip-ansi": "^6.0.0" } }, - "string_decoder": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", - "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", - "requires": { - "safe-buffer": "~5.2.0" - } - }, "strip-ansi": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", @@ -2411,6 +1898,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/strip-hex-prefix/-/strip-hex-prefix-1.0.0.tgz", "integrity": "sha1-DF8VX+8RUTczd96du1iNoFUA428=", + "dev": true, "requires": { "is-hex-prefixed": "1.0.0" } @@ -2444,18 +1932,6 @@ "thenify": ">= 3.1.0 < 4" } }, - "tiny-secp256k1": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/tiny-secp256k1/-/tiny-secp256k1-1.1.5.tgz", - "integrity": "sha512-duE2hSLSQIpHGzmK48OgRrGTi+4OTkXLC6aa86uOYQ6LLCYZSarVKIAvEtY7MoXjoL6bOXMSerEGMzrvW4SkDw==", - "requires": { - "bindings": "^1.3.0", - "bn.js": "^4.11.8", - "create-hmac": "^1.1.7", - "elliptic": "^6.4.0", - "nan": "^2.13.2" - } - }, "toidentifier": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", @@ -2470,12 +1946,14 @@ "tweetnacl": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", - "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==", + "dev": true }, "tweetnacl-util": { "version": "0.15.1", "resolved": "https://registry.npmjs.org/tweetnacl-util/-/tweetnacl-util-0.15.1.tgz", - "integrity": "sha512-RKJBIj8lySrShN4w6i/BonWp2Z/uxwC3h4y7xsRrpP59ZboCd0GpEVsOnMDYLMmKBpYhb5TgHzZXy7wTfYFBRw==" + "integrity": "sha512-RKJBIj8lySrShN4w6i/BonWp2Z/uxwC3h4y7xsRrpP59ZboCd0GpEVsOnMDYLMmKBpYhb5TgHzZXy7wTfYFBRw==", + "dev": true }, "type-is": { "version": "1.6.18", @@ -2487,11 +1965,6 @@ "mime-types": "~2.1.24" } }, - "typeforce": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/typeforce/-/typeforce-1.18.0.tgz", - "integrity": "sha512-7uc1O8h1M1g0rArakJdf0uLRSSgFcYexrVoKo+bzJd32gd4gDy2L/Z+8/FjPnU9ydY3pEnVPtr9FyscYY60K1g==" - }, "typeorm": { "version": "0.2.24", "resolved": "https://registry.npmjs.org/typeorm/-/typeorm-0.2.24.tgz", @@ -2528,11 +2001,6 @@ "buffer": "^5.2.1" } }, - "util-deprecate": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" - }, "utils-merge": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", @@ -2565,14 +2033,6 @@ "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=" }, - "wif": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/wif/-/wif-2.0.6.tgz", - "integrity": "sha1-CNP1IFbGZnkplyb63g1DKudLRwQ=", - "requires": { - "bs58check": "<3.0.0" - } - }, "wrap-ansi": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", @@ -2615,7 +2075,8 @@ "xhr2": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/xhr2/-/xhr2-0.1.3.tgz", - "integrity": "sha1-y/xHWaabSoiOeM9PILBRA4dXvRE=" + "integrity": "sha1-y/xHWaabSoiOeM9PILBRA4dXvRE=", + "dev": true }, "xml2js": { "version": "0.4.23", diff --git a/packages/rif-id-core/package.json b/packages/rif-id-core/package.json index f636013..da86a07 100644 --- a/packages/rif-id-core/package.json +++ b/packages/rif-id-core/package.json @@ -24,10 +24,12 @@ "homepage": "https://github.com/rsksamrt/rif-identity.js#readme", "dependencies": { "@reduxjs/toolkit": "^1.4.0", - "@rsksmart/rif-id-daf": "0.0.3", + "@rsksmart/rif-id-daf": "0.0.5", "daf-core": "^6.1.2", "daf-did-comm": "^6.3.0", - "daf-selective-disclosure": "^6.3.0" + "daf-selective-disclosure": "^6.3.0", + "daf-w3c": "^6.3.0", + "axios": "^0.20.0" }, "devDependencies": { "@rsksmart/ethr-did-utils": "^1.0.1", diff --git a/packages/rif-id-core/src/operations/authentication.ts b/packages/rif-id-core/src/operations/authentication.ts new file mode 100644 index 0000000..deb5f39 --- /dev/null +++ b/packages/rif-id-core/src/operations/authentication.ts @@ -0,0 +1,52 @@ +import { Dispatch } from '@reduxjs/toolkit' +import { Agent, Credential, Message } from 'daf-core' +import { Callback, callbackify } from './util' +import axios from 'axios' +import { ActionSignW3cVc } from 'daf-w3c' +import { addServiceToken } from '../reducers/authentication' + +const makeLoginCredentialPayload = (issuer: string, subject: string) => (challenge: string) => { + if (!challenge) { + throw new Error('Server did not return any challenge to login') + } + + return { + '@context': ['https://www.w3.org/2018/credentials/v1'], + type: ['VerifiableCredential'], + issuer, + credentialSubject: { + id: subject, + claims: [{ claimType: 'challenge', claimValue: challenge }] + } + } +} + +const verifyServiceDid = (expectedDid: string) => (message: Message): Credential => { + const credential = message.credentials[0] + + if (credential.issuer.did !== expectedDid) { + throw new Error('The issuer of the auth credential is not the expected did') + } + + return credential +} + +export const serviceAuthenticationFactory = (agent: Agent) => (serviceUrl: string, serviceDid: string, did: string, cb?: Callback) => (dispatch: Dispatch) => callbackify( + async () => axios.post(`${serviceUrl}/request-auth`, { did }) + .then(res => res.status === 200 && !!res.data && res.data.challenge) + .then(challenge => makeLoginCredentialPayload(did, serviceDid)(challenge)) + .then(payload => agent.handleAction({ + type: 'sign.w3c.vc.jwt', + save: false, + data: payload + } as ActionSignW3cVc)) + .then(({ raw }) => axios.post(`${serviceUrl}/auth`, { jwt: raw })) + .then(res => res.status === 200 && !!res.data && res.data.token) + .then(token => agent.handleMessage({ raw: token, metaData: [], save: false })) + .then(message => verifyServiceDid(serviceDid)(message)) + .then(vc => { + dispatch(addServiceToken({ identity: did, serviceDid: vc.issuer.did, token: vc.raw })) + return vc.raw + }), + cb +) diff --git a/packages/rif-id-core/src/reducers/authentication.ts b/packages/rif-id-core/src/reducers/authentication.ts new file mode 100644 index 0000000..bd00d96 --- /dev/null +++ b/packages/rif-id-core/src/reducers/authentication.ts @@ -0,0 +1,42 @@ +import { createSlice, PayloadAction } from '@reduxjs/toolkit' + +export interface ServiceTokens { + [serviceDid: string]: string +} + +export interface AuthenticationState { + [identity: string]: ServiceTokens +} + +const initialState: AuthenticationState = {} + +interface AddServiceTokenPayload { + identity: string + serviceDid: string + token: string +} + +interface RemoveServiceTokenPayload { + identity: string + serviceDid: string +} + +const authenticationSlice = createSlice({ + name: 'authentication', + initialState, + reducers: { + addServiceToken (state: AuthenticationState, { payload: { identity, serviceDid, token } }: PayloadAction) { + if (!state[identity]) state[identity] = {} + state[identity][serviceDid] = token + }, + removeServiceToken (state: AuthenticationState, { payload: { identity, serviceDid } }: PayloadAction) { + if (state[identity]) delete state[identity][serviceDid] + } + } +}) + +export const { addServiceToken, removeServiceToken } = authenticationSlice.actions + +export const selectServiceTokenByIdentity = (state: AuthenticationState, identity: string, serviceDid: string) => state[identity] && state[identity][serviceDid] + +export default authenticationSlice.reducer diff --git a/packages/rif-id-core/test/operations/authentication.test.ts b/packages/rif-id-core/test/operations/authentication.test.ts new file mode 100644 index 0000000..a5bd977 --- /dev/null +++ b/packages/rif-id-core/test/operations/authentication.test.ts @@ -0,0 +1,134 @@ +import { Store, AnyAction, configureStore } from '@reduxjs/toolkit' +import { generateMnemonic } from '@rsksmart/rif-id-mnemonic' +import { AbstractIdentity, Agent } from 'daf-core' +import { createAgent, deleteDatabase, did, issueTestCredential } from '../util' +import authenticationReducer, { AuthenticationState } from '../../src/reducers/authentication' +import { serviceAuthenticationFactory } from '../../src/operations/authentication' +import axios from 'axios' + +jest.mock('axios') +const mockedAxios = axios as jest.Mocked + +const mockAxios = ( + expectedServiceUrl: string, challenge: string, token?: string +) => { + const mockedImplementation = (url: string) => { + expect(url.startsWith(expectedServiceUrl)).toBeTruthy() + + let data + if (url.indexOf('/request-auth') > -1) { + data = { challenge } + } else if (url.indexOf('/auth') > -1) { + data = { token } + } else { + return Promise.resolve({ status: 404 }) + } + return Promise.resolve({ + data, + status: 200, + statusText: 'OK' + }) + } + + if (token) { + return mockedAxios.post + .mockImplementationOnce(mockedImplementation) + .mockImplementationOnce(mockedImplementation) + } + + return mockedAxios.post.mockImplementationOnce(mockedImplementation) +} + +describe('authentication operations', () => { + let agent: Agent + let database: string + let store: Store + let serviceAuthentication: ReturnType + let identity: AbstractIdentity + const serviceUrl = 'https://the.service' + + beforeEach(async () => { + const mnemonic = generateMnemonic(12) + database = `test.rif-id-core.operations.login.${new Date().getTime()}.sqlite` + agent = await createAgent(database, { mnemonic }) + store = configureStore({ reducer: authenticationReducer }) + serviceAuthentication = serviceAuthenticationFactory(agent) + + identity = await agent.identityManager.createIdentity() + }) + + afterEach(() => deleteDatabase(agent, database)) + + test('should save a login token', async () => { + const testCredential = await issueTestCredential(identity.did) + const challengeToReturn = '123456789qwerty' + const tokenToReturn = testCredential.raw + mockAxios(serviceUrl, challengeToReturn, tokenToReturn) + + await serviceAuthentication(serviceUrl, testCredential.issuer.did, identity.did)(store.dispatch) + + const state = store.getState() + expect(state[identity.did]).toBeTruthy() + expect(state[identity.did][testCredential.issuer.did]).toEqual(tokenToReturn) + }) + + describe('expect to throw errors', () => { + let expectedState: AuthenticationState, actualState: AuthenticationState + + beforeEach(() => { + expectedState = store.getState() + }) + + afterEach(() => { + actualState = store.getState() + expect(actualState).toEqual(expectedState) + }) + + test('should throw an error if not expected service did', async () => { + const testCredential = await issueTestCredential(identity.did) + const challengeToReturn = '123456789qwerty' + const tokenToReturn = testCredential.raw + + mockAxios(serviceUrl, challengeToReturn, tokenToReturn) + + const notServiceDid = did + + await serviceAuthentication(serviceUrl, notServiceDid, identity.did)(store.dispatch).catch(e => { + expect(e.message).toEqual('The issuer of the auth credential is not the expected did') + }) + }) + + test('should throw an error if the server does not send a proper challenge', async () => { + const challengeToReturn = undefined + + mockAxios(serviceUrl, challengeToReturn) + + await serviceAuthentication(serviceUrl, 'does not matter', identity.did)(store.dispatch).catch(e => { + expect(e.message).toEqual('Server did not return any challenge to login') + }) + }) + + test('should throw the agent error if received invalid token', async () => { + const challengeToReturn = '123456789qwerty' + const tokenToReturn = 'invalid' + mockAxios(serviceUrl, challengeToReturn, tokenToReturn) + + await serviceAuthentication(serviceUrl, 'does not matter', identity.did)(store.dispatch).catch(e => { + expect(e.message).toContain('Unsupported message type') + }) + }) + + test + .each(['400', '401', '404', '500'])('should throw the axios error %s', async (errorCode: string) => { + // emulates the error thrown in https://github.com/axios/axios/blob/master/lib/core/settle.js#L18 + const axiosError = `Request failed with status code ${errorCode}` + mockedAxios.post.mockImplementationOnce(() => { + return Promise.reject(new Error(axiosError)) + }) + + await serviceAuthentication(serviceUrl, 'does not matter', identity.did)(store.dispatch).catch(e => { + expect(e.message).toEqual(axiosError) + }) + }) + }) +}) diff --git a/packages/rif-id-core/test/reducers/authentication.test.ts b/packages/rif-id-core/test/reducers/authentication.test.ts new file mode 100644 index 0000000..f0f00a1 --- /dev/null +++ b/packages/rif-id-core/test/reducers/authentication.test.ts @@ -0,0 +1,179 @@ +import { AnyAction, configureStore, Store } from '@reduxjs/toolkit' +import { did, did2, did3, did4 } from '../util' +import authenticationReducer, { addServiceToken, AuthenticationState, removeServiceToken, selectServiceTokenByIdentity } from '../../src/reducers/authentication' + +describe('authentication reducer', () => { + const token = 'theToken' + const anotherToken = 'another' + + describe('reducer', () => { + let store: Store + let expectedState: AuthenticationState + + beforeEach(() => { + store = configureStore({ reducer: authenticationReducer }) + }) + + afterEach(() => { + expect(store.getState()).toEqual(expectedState) + }) + + test('no tokens', () => { + expectedState = {} + }) + + test('adds token for one identity with one service', () => { + store.dispatch(addServiceToken({ identity: did, serviceDid: did2, token })) + + expectedState = {} + expectedState[did] = {} + expectedState[did][did2] = token + }) + + test('adds token for one identity with two services', () => { + store.dispatch(addServiceToken({ identity: did, serviceDid: did2, token })) + store.dispatch(addServiceToken({ identity: did, serviceDid: did3, token: anotherToken })) + + expectedState = {} + expectedState[did] = {} + expectedState[did][did2] = token + expectedState[did][did3] = anotherToken + }) + + test('adds token for two identities with one service each', async () => { + store.dispatch(addServiceToken({ identity: did, serviceDid: did2, token })) + store.dispatch(addServiceToken({ identity: did3, serviceDid: did4, token: anotherToken })) + + expectedState = {} + expectedState[did] = {} + expectedState[did][did2] = token + expectedState[did3] = {} + expectedState[did3][did4] = anotherToken + }) + + test('adds tokens for two identities with two services each', async () => { + store.dispatch(addServiceToken({ identity: did, serviceDid: did2, token })) + store.dispatch(addServiceToken({ identity: did, serviceDid: did4, token: anotherToken })) + store.dispatch(addServiceToken({ identity: did3, serviceDid: did2, token })) + store.dispatch(addServiceToken({ identity: did3, serviceDid: did4, token: anotherToken })) + + expectedState = {} + expectedState[did] = {} + expectedState[did][did2] = token + expectedState[did][did4] = anotherToken + expectedState[did3] = {} + expectedState[did3][did2] = token + expectedState[did3][did4] = anotherToken + }) + + test('removes the unique token from one identity with one service', () => { + store.dispatch(addServiceToken({ identity: did, serviceDid: did2, token })) + store.dispatch(removeServiceToken({ identity: did, serviceDid: did2 })) + + expectedState = {} + expectedState[did] = {} + }) + + test('removes just one token from one identity with two services', () => { + store.dispatch(addServiceToken({ identity: did, serviceDid: did2, token })) + store.dispatch(addServiceToken({ identity: did, serviceDid: did3, token: anotherToken })) + store.dispatch(removeServiceToken({ identity: did, serviceDid: did2 })) + + expectedState = {} + expectedState[did] = {} + expectedState[did][did3] = anotherToken + }) + + test('removes one token from two identities with one token each', () => { + store.dispatch(addServiceToken({ identity: did, serviceDid: did2, token })) + store.dispatch(addServiceToken({ identity: did3, serviceDid: did4, token: anotherToken })) + store.dispatch(removeServiceToken({ identity: did3, serviceDid: did4 })) + + expectedState = {} + expectedState[did] = {} + expectedState[did3] = {} + expectedState[did][did2] = token + }) + + test('removes one token for each identities when two identities with two tokens each', () => { + store.dispatch(addServiceToken({ identity: did, serviceDid: did2, token })) + store.dispatch(addServiceToken({ identity: did, serviceDid: did4, token: anotherToken })) + store.dispatch(addServiceToken({ identity: did3, serviceDid: did2, token })) + store.dispatch(addServiceToken({ identity: did3, serviceDid: did4, token: anotherToken })) + store.dispatch(removeServiceToken({ identity: did, serviceDid: did2 })) + store.dispatch(removeServiceToken({ identity: did3, serviceDid: did4 })) + + expectedState = {} + expectedState[did] = {} + expectedState[did][did4] = anotherToken + expectedState[did3] = {} + expectedState[did3][did2] = token + }) + }) + + describe('action creators', () => { + test('add service token', () => { + const payload = { identity: did, serviceDid: did2, token } + expect(addServiceToken(payload)).toEqual({ payload, type: addServiceToken.type }) + }) + + test('remove service token', () => { + const payload = { identity: did, serviceDid: did2 } + expect(removeServiceToken(payload)).toEqual({ payload, type: removeServiceToken.type }) + }) + }) + + describe('selectors', () => { + test('initial state', () => { + const initialState: AuthenticationState = {} + + expect(selectServiceTokenByIdentity(initialState, did, did2)).toBeUndefined() + }) + + test('select existing value one service one token state', () => { + const state: AuthenticationState = {} + state[did] = {} + state[did][did2] = token + + expect(selectServiceTokenByIdentity(state, did, did2)).toEqual(token) + }) + + test('select non existing value one service one token state', () => { + const state: AuthenticationState = {} + state[did] = {} + state[did][did2] = token + + expect(selectServiceTokenByIdentity(state, did3, did4)).toBeUndefined() + }) + + test('select existing values two services two tokens each state', () => { + const state: AuthenticationState = {} + state[did] = {} + state[did4] = {} + state[did][did2] = token + state[did][did3] = anotherToken + state[did4][did2] = anotherToken + state[did4][did3] = token + + expect(selectServiceTokenByIdentity(state, did, did2)).toEqual(token) + expect(selectServiceTokenByIdentity(state, did4, did3)).toEqual(token) + expect(selectServiceTokenByIdentity(state, did4, did2)).toEqual(anotherToken) + expect(selectServiceTokenByIdentity(state, did, did3)).toEqual(anotherToken) + }) + + test('select non existing values two services two tokens each state', () => { + const state: AuthenticationState = {} + state[did] = {} + state[did4] = {} + state[did][did2] = token + state[did][did3] = anotherToken + state[did4][did2] = anotherToken + state[did4][did3] = token + + expect(selectServiceTokenByIdentity(state, did3, did4)).toBeUndefined() + expect(selectServiceTokenByIdentity(state, did2, did4)).toBeUndefined() + expect(selectServiceTokenByIdentity(state, did, did4)).toBeUndefined() + expect(selectServiceTokenByIdentity(state, did4, did)).toBeUndefined() + }) + }) +}) diff --git a/packages/rif-id-core/test/util.ts b/packages/rif-id-core/test/util.ts index f782e05..f410457 100644 --- a/packages/rif-id-core/test/util.ts +++ b/packages/rif-id-core/test/util.ts @@ -123,6 +123,7 @@ export const deleteDatabase = (agent: Daf.Agent, database: string) => agent.dbCo export const did = 'did:ethr:rsk:testnet:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74' export const did2 = 'did:ethr:rsk:testnet:0xdcbe93e98e0dcebe677c39a84f5f212b85ba7ef0' export const did3 = 'did:ethr:rsk:testnet:0xbe935f08e079e7a7c898bcbde5dceba214fe6f2' +export const did4 = 'did:ethr:rsk:testnet:0xc78b1d101938ea2f1e6dc5c16766627cf88b7a28' export const issueTestCredential = async (subject: string): Promise => { const mnemonic = generateMnemonic(12)