From 123f73f0db3716147f344808f4a178e723fb4236 Mon Sep 17 00:00:00 2001 From: Javier Esses Date: Mon, 21 Sep 2020 18:46:14 -0300 Subject: [PATCH] Moved rif-id-auth package to this repo --- jest.config.js | 8 +- packages/rif-id-auth/README.md | 73 ++ packages/rif-id-auth/package-lock.json | 889 +++++++++++++++++++++++++ packages/rif-id-auth/package.json | 35 + packages/rif-id-auth/src/index.js | 155 +++++ packages/rif-id-auth/src/test-utils.js | 15 + packages/rif-id-auth/test/auth.spec.js | 290 ++++++++ 7 files changed, 1461 insertions(+), 4 deletions(-) create mode 100644 packages/rif-id-auth/README.md create mode 100644 packages/rif-id-auth/package-lock.json create mode 100644 packages/rif-id-auth/package.json create mode 100644 packages/rif-id-auth/src/index.js create mode 100644 packages/rif-id-auth/src/test-utils.js create mode 100644 packages/rif-id-auth/test/auth.spec.js diff --git a/jest.config.js b/jest.config.js index 4d81862..c899281 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,10 +3,10 @@ module.exports = { testEnvironment: 'node', reporters: ['default', 'jest-junit'], testResultsProcessor: 'jest-junit', - "globals": { - "ts-jest": { - "tsConfig": "./packages/tsconfig.settings.json" + globals: { + 'ts-jest': { + tsConfig: './packages/tsconfig.settings.json' } }, testTimeout: 30000 -}; +} diff --git a/packages/rif-id-auth/README.md b/packages/rif-id-auth/README.md new file mode 100644 index 0000000..96d9a8f --- /dev/null +++ b/packages/rif-id-auth/README.md @@ -0,0 +1,73 @@ +# RIF Identity Authentication + +This package exposes a set of functions to authenticate users using [DIDs](https://w3c.github.io/did-core/) and [Verifiable Credentials](https://w3c.github.io/vc-data-model/) + +## How it works + +1. User sends him/her DID and asks for a challenge. +2. The package generates it and associate the just generated challenge with the received DID. The challenge will be valid for a fixed time. Default: 5 minutes +3. The user signs a VC that includes the challenge in it and sends its JWT representation to the package. +4. The package validates that the VC is signed by the private key associated with the previous sent DID and that it contains the previous sent challenge. If it is ok, it generates another VC and returns its JWT representation. Default expiration time: 10 hours. +5. The user sends that received JWT in the `Authorization` header of each authenticated request. +6. The package provides a middleware that can be used in [Express](https://expressjs.com/) applications, it validates the sent JWT, if it is okay, it authenticates the request, if not, 401 is returned. + +## Operations + +### initializeAuth + +The library must be initialized with this method. If not, an exception will be thrown when invoking the rest of the methods. It configures the library with the sent options and initializes the identity that will sign the authentication JWTs. + + +#### Parameter +- `env` +Is an `object` that contains the following: +-- `did` - did that will be used to sign auth tokens. REQUIRED +-- `signer` - [`Signer`](https://github.com/decentralized-identity/did-jwt/blob/master/src/SimpleSigner.ts) object associated with the did, will be used to sign auth tokens. REQUIRED +-- `rpcUrl`: rsk rpc url used to validate credentials - Default: `https://did.testnet.rsk.co:4444` +-- `authExpirationInHours` - Default: 10 +-- `challengeExpirationInSeconds` - Default: 300 +-- `maxRequestsPerToken` - Default: 20 + +### getChallenge + +Generates a random 64 bytes challenge that will be validated when the user logs in. The challenge will be deleted after the `challengeExpirationInSeconds` value provided in the `initializeAuth` method. + +#### Parameter +- `did` - `string` DID that will be associated with the generated challenge. REQUIRED + +### getAuthToken + +Generates the JWT representation of a VC that will be used to authenticate requests from now onward. Throws errors if the challenge is not valid or the VC received is not well formatted. The generated JWT will be deleted after the `authExpirationInHours` value provided in the `initializeAuth` method. + +#### Parameter +- `jwt` - `jwt` representation of a VC signed by the client with the received challenge. That VC should be signed by the DID sent before and follow this format: +``` +vc: { + '@context': ['https://www.w3.org/2018/credentials/v1'], + type: ['VerifiableCredential'], + credentialSubject: { + claims: [ + { claimType: 'challenge', claimValue: RECEIVED_CHALLENGE } + ] + } + } +``` + +### authExpressMiddleware + +It is a middleware created to be used in Express applications. The `token` should be included raw in the `Authorization` header of the request. This method validates that that token has been signed by the `privateKey` provided in the `initializeAuth` method, that it is not expired and also that the `token` did not exceed the max amount of requests allowed per user (`maxRequestsPerToken`) + + +## Run for development and test + +``` +npm i +npm test +``` + +### Link to other project +``` +npm link +cd path/to/your/project +npm link @rsksmart/rif-id-jwt-auth +``` \ No newline at end of file diff --git a/packages/rif-id-auth/package-lock.json b/packages/rif-id-auth/package-lock.json new file mode 100644 index 0000000..8324bdf --- /dev/null +++ b/packages/rif-id-auth/package-lock.json @@ -0,0 +1,889 @@ +{ + "name": "@rsksmart/rif-id-auth", + "version": "0.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@babel/runtime": { + "version": "7.11.2", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.11.2.tgz", + "integrity": "sha512-TeWkU52so0mPtDcaCTxNBI/IHiz0pZgr8VEFqXFtZWpYD08ZB6FaSwVAS8MKRQAP3bYKiVjwysOJgMFY28o6Tw==", + "requires": { + "regenerator-runtime": "^0.13.4" + } + }, + "@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==", + "dev": true, + "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" + } + }, + "@stablelib/binary": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@stablelib/binary/-/binary-1.0.0.tgz", + "integrity": "sha512-W01QhOw1tWL51Du1c5JZphJs7toRbfra1C2DBlhT0mRHZWGWB1hpFbqiZUFY7QNIMUpmmHLrlZs3YsSCB/giUg==", + "requires": { + "@stablelib/int": "^1.0.0" + } + }, + "@stablelib/ed25519": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@stablelib/ed25519/-/ed25519-1.0.1.tgz", + "integrity": "sha512-kvC98vkJeertRj37yqTcjOwUVYWQ0jcywxxWpeuTal5ZNgH7EcbljtQYECA2Pi2N0zNG0a0AjSD2Q2DFcUxRjQ==", + "requires": { + "@stablelib/random": "^1.0.0", + "@stablelib/sha512": "^1.0.0", + "@stablelib/wipe": "^1.0.0" + } + }, + "@stablelib/hash": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@stablelib/hash/-/hash-1.0.0.tgz", + "integrity": "sha512-wBvSIIx4Y8799BRD4TBhezS1P9+irGAKdsNgbZMeU5ndMbw7BtZALdCm0FcJIRFxJ2giPLPS9YCgrwWAhzSRLQ==" + }, + "@stablelib/int": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@stablelib/int/-/int-1.0.0.tgz", + "integrity": "sha512-MRigEQCO7xM93nZqW4CbIBjhANGw3jJxGVSUZH3PQ6HWL1IGrFWVDBzIclWxl4l5aRRpqoM+76ellQNdUJPnsA==" + }, + "@stablelib/random": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@stablelib/random/-/random-1.0.0.tgz", + "integrity": "sha512-G9vwwKrNCGMI/uHL6XeWe2Nk4BuxkYyWZagGaDU9wrsuV+9hUwNI1lok2WVo8uJDa2zx7ahNwN7Ij983hOUFEw==", + "requires": { + "@stablelib/binary": "^1.0.0", + "@stablelib/wipe": "^1.0.0" + } + }, + "@stablelib/sha512": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@stablelib/sha512/-/sha512-1.0.0.tgz", + "integrity": "sha512-qvUu5SraAdGa8HAkAasfMyD9C+MwlRnFVRJ6cRxAEIekmDsU3tfGLnUm3wb9ao4t0FkihGrj8GKlV82TTR4Phw==", + "requires": { + "@stablelib/binary": "^1.0.0", + "@stablelib/hash": "^1.0.0", + "@stablelib/wipe": "^1.0.0" + } + }, + "@stablelib/utf8": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@stablelib/utf8/-/utf8-1.0.0.tgz", + "integrity": "sha512-Y8QWrK4T0yW0HMFfSI3ZaMHKV37q27hX5ilsmKV358x01mzYfj5fwIf2LjzTlF+UIemHEXSlSN9XJnv1ML4znQ==" + }, + "@stablelib/wipe": { + "version": "1.0.0", + "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==", + "dev": true, + "requires": { + "@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==", + "dev": true, + "requires": { + "@types/bn.js": "*" + } + }, + "@types/keccak": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@types/keccak/-/keccak-3.0.1.tgz", + "integrity": "sha512-/MxAVmtyyeOvZ6dGf3ciLwFRuV5M8DRIyYNFGHYI6UyBW4/XqyO0LZw+JFMvaeY3cHItQAkELclBU1x5ank6mg==", + "dev": true, + "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==", + "dev": true + }, + "@types/node": { + "version": "14.11.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.11.1.tgz", + "integrity": "sha512-oTQgnd0hblfLsJ6BvJzzSL+Inogp3lq9fGgqRkMB/ziKMgEUaFl801OncOzUmalfzt14N0oPHMK47ipl+wbTIw==", + "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==", + "dev": true, + "requires": { + "find-babel-config": "^1.1.0", + "glob": "^7.1.2", + "pkg-up": "^2.0.0", + "reselect": "^3.0.1", + "resolve": "^1.4.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=", + "requires": { + "core-js": "^2.4.0", + "regenerator-runtime": "^0.11.0" + }, + "dependencies": { + "regenerator-runtime": { + "version": "0.11.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", + "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==" + } + } + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true + }, + "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==", + "dev": true + }, + "bindings": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", + "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "dev": true, + "requires": { + "file-uri-to-path": "1.0.0" + } + }, + "bn.js": { + "version": "4.11.9", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.9.tgz", + "integrity": "sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw==" + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "brorand": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz", + "integrity": "sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8=" + }, + "buffer": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.6.0.tgz", + "integrity": "sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw==", + "requires": { + "base64-js": "^1.0.2", + "ieee754": "^1.1.4" + } + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, + "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==" + }, + "did-jwt": { + "version": "4.5.1", + "resolved": "https://registry.npmjs.org/did-jwt/-/did-jwt-4.5.1.tgz", + "integrity": "sha512-wgp9zKlCtNC8l8ZNfWiTq01myXlMe+n1LUWGJuYpmqPPv38ZB3pf16HGQr96OZOXaNLq+izRGytzX/VDMwZWlg==", + "requires": { + "@babel/runtime": "^7.11.2", + "@stablelib/ed25519": "^1.0.1", + "@stablelib/utf8": "^1.0.0", + "buffer": "^5.6.0", + "did-resolver": "^2.1.0", + "elliptic": "^6.5.3", + "js-sha256": "^0.9.0", + "js-sha3": "^0.8.0", + "uport-base64url": "3.0.2-alpha.0" + } + }, + "did-jwt-vc": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/did-jwt-vc/-/did-jwt-vc-1.0.6.tgz", + "integrity": "sha512-k0pYUfT9ivn8yBBayuSeHm0tRG7pRGRnYwrCSVWciFcxnfQK94QUoax9g7HQtvgyxqAWP0DQUTDK75zp1/wZ0g==", + "requires": { + "did-jwt": "^4.4.2" + } + }, + "did-resolver": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/did-resolver/-/did-resolver-2.1.1.tgz", + "integrity": "sha512-FYLTkNWofjYNDGV1HTQlyVu1OqZiFxR4I8KM+oxGVOkbXva15NfWzbzciqdXUDqOhe6so5aroAdrVip6gSAYSA==" + }, + "elliptic": { + "version": "6.5.3", + "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.3.tgz", + "integrity": "sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==", + "requires": { + "bn.js": "^4.4.0", + "brorand": "^1.0.1", + "hash.js": "^1.0.0", + "hmac-drbg": "^1.0.0", + "inherits": "^2.0.1", + "minimalistic-assert": "^1.0.0", + "minimalistic-crypto-utils": "^1.0.0" + } + }, + "ethjs-abi": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/ethjs-abi/-/ethjs-abi-0.2.1.tgz", + "integrity": "sha1-4KepOn6BFjqUR3utVu3lJKtt5TM=", + "requires": { + "bn.js": "4.11.6", + "js-sha3": "0.5.5", + "number-to-bn": "1.7.0" + }, + "dependencies": { + "bn.js": { + "version": "4.11.6", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz", + "integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=" + }, + "js-sha3": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.5.5.tgz", + "integrity": "sha1-uvDA6MVK1ZA0R9+Wreekobynmko=" + } + } + }, + "ethjs-contract": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/ethjs-contract/-/ethjs-contract-0.2.3.tgz", + "integrity": "sha512-fKsHm57wxwHrZhVlD8AHU2lC2G3c1fmvoEz15BpqIkuGWiTbjuvrQo2Avc+3EQpSsTFWNdyxC0h1WKRcn5kkyQ==", + "requires": { + "babel-runtime": "^6.26.0", + "ethjs-abi": "0.2.0", + "ethjs-filter": "0.1.8", + "ethjs-util": "0.1.3", + "js-sha3": "0.5.5" + }, + "dependencies": { + "bn.js": { + "version": "4.11.6", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz", + "integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=" + }, + "ethjs-abi": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/ethjs-abi/-/ethjs-abi-0.2.0.tgz", + "integrity": "sha1-0+LCIQEVIPxJm3FoIDbBT8wvWyU=", + "requires": { + "bn.js": "4.11.6", + "js-sha3": "0.5.5", + "number-to-bn": "1.7.0" + } + }, + "js-sha3": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.5.5.tgz", + "integrity": "sha1-uvDA6MVK1ZA0R9+Wreekobynmko=" + } + } + }, + "ethjs-filter": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/ethjs-filter/-/ethjs-filter-0.1.8.tgz", + "integrity": "sha512-qTDPskDL2UadHwjvM8A+WG9HwM4/FoSY3p3rMJORkHltYcAuiQZd2otzOYKcL5w2Q3sbAkW/E3yt/FPFL/AVXA==" + }, + "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==", + "requires": { + "bn.js": "4.11.6", + "ethjs-schema": "0.2.1", + "ethjs-util": "0.1.3", + "is-hex-prefixed": "1.0.0", + "number-to-bn": "1.7.0", + "strip-hex-prefix": "1.0.0" + }, + "dependencies": { + "bn.js": { + "version": "4.11.6", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz", + "integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=" + } + } + }, + "ethjs-provider-http": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/ethjs-provider-http/-/ethjs-provider-http-0.1.6.tgz", + "integrity": "sha1-HsXZtL4lfvHValALIqdBmF6IlCA=", + "requires": { + "xhr2": "0.1.3" + } + }, + "ethjs-query": { + "version": "0.3.8", + "resolved": "https://registry.npmjs.org/ethjs-query/-/ethjs-query-0.3.8.tgz", + "integrity": "sha512-/J5JydqrOzU8O7VBOwZKUWXxHDGr46VqNjBCJgBVNNda+tv7Xc8Y2uJc6aMHHVbeN3YOQ7YRElgIc0q1CI02lQ==", + "requires": { + "babel-runtime": "^6.26.0", + "ethjs-format": "0.2.7", + "ethjs-rpc": "0.2.0", + "promise-to-callback": "^1.0.0" + } + }, + "ethjs-rpc": { + "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==", + "requires": { + "promise-to-callback": "^1.0.0" + } + }, + "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==" + }, + "ethjs-util": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/ethjs-util/-/ethjs-util-0.1.3.tgz", + "integrity": "sha1-39XqSkANxeQhqInK9H4IGtp4u1U=", + "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==", + "dev": true, + "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": { + "bn.js": { + "version": "4.11.6", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz", + "integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=", + "dev": true + }, + "did-jwt": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/did-jwt/-/did-jwt-0.1.3.tgz", + "integrity": "sha512-hZvjC4bstxo6bqFIOAlX90LdSaA5uxMdg0zSFCPm2WwIhgHFp4SfVM6f5yq1ebA5/cJzcUr+MclnTrlEiixuiQ==", + "dev": true, + "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==", + "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", + "number-to-bn": "1.7.0" + }, + "dependencies": { + "js-sha3": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.5.5.tgz", + "integrity": "sha1-uvDA6MVK1ZA0R9+Wreekobynmko=", + "dev": true + } + } + }, + "ethjs-contract": { + "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", + "ethjs-util": "0.1.3", + "js-sha3": "0.5.5" + }, + "dependencies": { + "js-sha3": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.5.5.tgz", + "integrity": "sha1-uvDA6MVK1ZA0R9+Wreekobynmko=", + "dev": true + } + } + }, + "ethjs-filter": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/ethjs-filter/-/ethjs-filter-0.1.5.tgz", + "integrity": "sha1-ARKvYBfCRnfjK4/esg5hlgGbdZg=", + "dev": true + }, + "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==", + "dev": true, + "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" + }, + "dependencies": { + "ethjs-abi": { + "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", + "number-to-bn": "1.7.0" + } + }, + "js-sha3": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.5.5.tgz", + "integrity": "sha1-uvDA6MVK1ZA0R9+Wreekobynmko=", + "dev": true + } + } + } + } + }, + "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==" + }, + "ethr-did-resolver": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ethr-did-resolver/-/ethr-did-resolver-3.0.0.tgz", + "integrity": "sha512-o400l9p8ee6W09fZLMX2BERcyFRrebE7DCjb46Rzgypb7QzX1rBOzHJ0PorWRINXFqoPMoxR7OeIrD17obIbng==", + "requires": { + "buffer": "^5.1.0", + "did-resolver": "2.1.1", + "elliptic": "^6.5.3", + "ethjs-abi": "^0.2.1", + "ethjs-contract": "^0.2.0", + "ethjs-provider-http": "^0.1.6", + "ethjs-query": "^0.3.5", + "ethr-did-registry": "^0.0.3", + "js-sha3": "^0.8.0" + } + }, + "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==", + "dev": true + }, + "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==", + "dev": true, + "requires": { + "json5": "^0.5.1", + "path-exists": "^3.0.0" + } + }, + "find-up": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", + "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", + "dev": true, + "requires": { + "locate-path": "^2.0.0" + } + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true + }, + "glob": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "hash.js": { + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.7.tgz", + "integrity": "sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA==", + "requires": { + "inherits": "^2.0.3", + "minimalistic-assert": "^1.0.1" + } + }, + "hmac-drbg": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", + "integrity": "sha1-0nRXAQJabHdabFRXk+1QL8DGSaE=", + "requires": { + "hash.js": "^1.0.3", + "minimalistic-assert": "^1.0.0", + "minimalistic-crypto-utils": "^1.0.1" + } + }, + "ieee754": { + "version": "1.1.13", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz", + "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==" + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "is-fn": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-fn/-/is-fn-1.0.0.tgz", + "integrity": "sha1-lUPV3nvPWwiiLsiiC65uKG1RDYw=" + }, + "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=" + }, + "js-sha256": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.9.0.tgz", + "integrity": "sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==" + }, + "js-sha3": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz", + "integrity": "sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q==" + }, + "json5": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/json5/-/json5-0.5.1.tgz", + "integrity": "sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE=", + "dev": true + }, + "keccak": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/keccak/-/keccak-3.0.1.tgz", + "integrity": "sha512-epq90L9jlFWCW7+pQa6JOnKn2Xgl2mtI664seYR6MHskvI9agt7AnDqmAlp9TqU4/caMYbA08Hi5DMZAl5zdkA==", + "dev": true, + "requires": { + "node-addon-api": "^2.0.0", + "node-gyp-build": "^4.2.0" + } + }, + "locate-path": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", + "integrity": "sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=", + "dev": true, + "requires": { + "p-locate": "^2.0.0", + "path-exists": "^3.0.0" + } + }, + "lodash": { + "version": "4.17.20", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", + "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", + "dev": true + }, + "minimalistic-assert": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz", + "integrity": "sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==" + }, + "minimalistic-crypto-utils": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz", + "integrity": "sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo=" + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "nan": { + "version": "2.14.1", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.1.tgz", + "integrity": "sha512-isWHgVjnFjh2x2yuJ/tj3JbwoHu3UC2dX5G/88Cm24yB6YopVgxvBObDY7n5xW6ExmFhJpSEQqFPvq9zaXc8Jw==", + "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==", + "dev": true + }, + "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==", + "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=", + "requires": { + "bn.js": "4.11.6", + "strip-hex-prefix": "1.0.0" + }, + "dependencies": { + "bn.js": { + "version": "4.11.6", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz", + "integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=" + } + } + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "requires": { + "wrappy": "1" + } + }, + "p-limit": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", + "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", + "dev": true, + "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=", + "dev": true, + "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=", + "dev": true + }, + "path-exists": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", + "dev": true + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true + }, + "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==", + "dev": true + }, + "pkg-up": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/pkg-up/-/pkg-up-2.0.0.tgz", + "integrity": "sha1-yBmscoBZpGHKscOImivjxJoATX8=", + "dev": true, + "requires": { + "find-up": "^2.1.0" + } + }, + "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=", + "requires": { + "is-fn": "^1.0.0", + "set-immediate-shim": "^1.0.1" + } + }, + "regenerator-runtime": { + "version": "0.13.7", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.7.tgz", + "integrity": "sha512-a54FxoJDIr27pgf7IgeQGxmqUNYrcV338lf/6gH456HZ/PhX+5BcwHXG9ajESmwe6WRO0tAzRUrRmNONWgkrew==" + }, + "reselect": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/reselect/-/reselect-3.0.1.tgz", + "integrity": "sha1-79qpjqdFEyTQkrKyFjpqHXqaIUc=", + "dev": true + }, + "resolve": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz", + "integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==", + "dev": true, + "requires": { + "path-parse": "^1.0.6" + } + }, + "rskjs-util": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/rskjs-util/-/rskjs-util-1.0.3.tgz", + "integrity": "sha512-Q6zfYFQndaBln1iY2gnBfYgDLymbZHAxKXOcZVLAKJkHilcieoUN3ZXVxLA3K30KlgAfmRVG72iTzi+yPNZB1w==", + "dev": true, + "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==", + "dev": true, + "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", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true + }, + "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=" + }, + "strip-hex-prefix": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/strip-hex-prefix/-/strip-hex-prefix-1.0.0.tgz", + "integrity": "sha1-DF8VX+8RUTczd96du1iNoFUA428=", + "requires": { + "is-hex-prefixed": "1.0.0" + } + }, + "tweetnacl": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", + "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==", + "dev": true + }, + "uport-base64url": { + "version": "3.0.2-alpha.0", + "resolved": "https://registry.npmjs.org/uport-base64url/-/uport-base64url-3.0.2-alpha.0.tgz", + "integrity": "sha512-pRu0xm1K39IUzuMQEmFWdqP+H8jOzblwTXf0r9wFBCa6ZLLQsNuDeUwB2Ld+9zlBSvQQv+XEzG7cQukSCueZqw==", + "requires": { + "buffer": "^5.2.1" + } + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true + }, + "xhr2": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/xhr2/-/xhr2-0.1.3.tgz", + "integrity": "sha1-y/xHWaabSoiOeM9PILBRA4dXvRE=" + } + } +} diff --git a/packages/rif-id-auth/package.json b/packages/rif-id-auth/package.json new file mode 100644 index 0000000..5b73be0 --- /dev/null +++ b/packages/rif-id-auth/package.json @@ -0,0 +1,35 @@ +{ + "name": "@rsksmart/rif-id-auth", + "version": "0.0.0", + "description": "RIF Identity - Authentication with Verifiable Credentials", + "main": "lib/index.js", + "scripts": { + "build": "babel src --out-dir lib" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/rsksamrt/rif-identity.js.git" + }, + "keywords": [ + "rsk", + "rif", + "identity" + ], + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/rsksamrt/rif-identity.js/issues" + }, + "homepage": "https://github.com/rsksamrt/rif-identity.js#readme", + "dependencies": { + "did-jwt": "^4.5.1", + "did-jwt-vc": "^1.0.6", + "did-resolver": "^2.1.1", + "ethr-did-resolver": "^3.0.0", + "js-sha3": "^0.8.0" + }, + "devDependencies": { + "@rsksmart/rif-id-ethr-did": "0.0.2", + "@rsksmart/rif-id-mnemonic": "0.0.1" + } +} diff --git a/packages/rif-id-auth/src/index.js b/packages/rif-id-auth/src/index.js new file mode 100644 index 0000000..a8864d9 --- /dev/null +++ b/packages/rif-id-auth/src/index.js @@ -0,0 +1,155 @@ +const { randomBytes } = require('crypto') +const { createVerifiableCredentialJwt, verifyCredential } = require('did-jwt-vc') +const { verifyJWT } = require('did-jwt') +const { getResolver } = require('ethr-did-resolver') +const { Resolver } = require('did-resolver') +const { keccak256 } = require('js-sha3') + +const challenges = {} +const tokenRequestCounter = {} + +let + providerConfig, ethrDidResolver, didResolver, identity, + challengeExpirationInSeconds, maxRequestsPerToken, rpcUrl, authExpirationInHours + +const initializeAuth = (env) => { + if (!env) { + throw new Error('Missing env object') + } + + rpcUrl = env.rpcUrl || 'https://did.testnet.rsk.co:4444' + challengeExpirationInSeconds = env.challengeExpirationInSeconds || 300 + authExpirationInHours = env.authExpirationInHours || 10 + maxRequestsPerToken = env.maxRequestsPerToken || 20 + + const { did, signer } = env + + if (!did) { + throw new Error('Missing env variable: did') + } + + if (!signer) { + throw new Error('Missing env variable: signer') + } + + providerConfig = { + networks: [{ name: 'rsk:testnet', registry: '0xdca7ef03e98e0dc2b855be647c39abe984fcf21b', rpcUrl }] + } + ethrDidResolver = getResolver(providerConfig) + didResolver = new Resolver(ethrDidResolver) + + identity = { signer, did } +} + +const getChallenge = (did) => { + if (!identity) { + throw new Error('Library not initialized') + } + + if (!did) { + throw new Error('Invalid did') + } + + const challenge = randomBytes(64).toString('hex') + + challenges[did] = challenge + setTimeout(() => delete challenges[did], challengeExpirationInSeconds * 1000) + + return challenge +} + +const getAuthToken = async (jwt) => { + if (!identity) { + throw new Error('Library not initialized') + } + + if (!jwt) { + throw new Error('JWT VC is required') + } + + const { payload, issuer } = await verifyJWT(jwt, { resolver: didResolver }) + + if (!challenges[issuer]) { + throw new Error('Request for a challenge before auth') + } + + const challengeClaim = payload.vc.credentialSubject.claims.find( + (claim) => claim.claimType === 'challenge' + ) + + if (!challengeClaim || !challengeClaim.claimValue) { + throw new Error('Invalid payload, missing challenge claim') + } + if (challenges[issuer] !== challengeClaim.claimValue) { + throw new Error('Invalid challenge') + } + + const expirationInSeconds = Math.floor(authExpirationInHours * 60 * 60) + + const token = await createVerifiableCredentialJwt({ + sub: issuer, + iss: identity.did, + nbf: Math.round((+Date.now()) / 1000), + exp: Math.round((+Date.now() / 1000) + expirationInSeconds), + vc: { + '@context': ['https://www.w3.org/2018/credentials/v1'], + type: ['VerifiableCredential'], + credentialSubject: { + claims: [ + { claimType: 'authToken' } + ] + } + } + }, identity) + + const hash = keccak256(token).toString('hex') + tokenRequestCounter[hash] = 0 + setTimeout(() => delete tokenRequestCounter[hash], expirationInSeconds * 1000) + + return token +} + +const authExpressMiddleware = async (req, res, next) => { + if (!identity) { + throw new Error('Library not initialized') + } + + // eslint-disable-next-line dot-notation + const token = req.headers['authorization'] + + if (token) { + try { + const { issuer } = await verifyCredential(token, didResolver) + + if (issuer !== identity.did) { + res.status(401).send('Invalid VC issuer') + } else { + const hash = keccak256(token).toString('hex') + + if (tokenRequestCounter[hash] >= 0) { + tokenRequestCounter[hash]++ + + if (tokenRequestCounter[hash] <= maxRequestsPerToken) { + next() + } else { + res.status(401).send('Max amount of requests reached') + } + } else { + res.status(401).send('Expired token') + } + } + } catch (err) { + if (err.message.toLowerCase().includes('jwt has expired')) { + res.status(401).send('Expired token') + } else if (err.message.toLowerCase().includes('incorrect format jwt')) { + res.status(401).send('Invalid token') + } else { + res.status(401).send(err.message) + } + } + } else { + res.status(401).send('No authorization header present') + } +} + +module.exports = { getAuthToken, authExpressMiddleware, initializeAuth, getChallenge } diff --git a/packages/rif-id-auth/src/test-utils.js b/packages/rif-id-auth/src/test-utils.js new file mode 100644 index 0000000..2c78679 --- /dev/null +++ b/packages/rif-id-auth/src/test-utils.js @@ -0,0 +1,15 @@ +const { createVerifiableCredentialJwt } = require('did-jwt-vc') + +const getLoginJwt = async (claimType, claimValue, identity) => createVerifiableCredentialJwt({ + vc: { + '@context': ['https://www.w3.org/2018/credentials/v1'], + type: ['VerifiableCredential'], + credentialSubject: { + claims: [ + { claimType, claimValue } + ] + } + } +}, identity) + +module.exports = { getLoginJwt } diff --git a/packages/rif-id-auth/test/auth.spec.js b/packages/rif-id-auth/test/auth.spec.js new file mode 100644 index 0000000..153c510 --- /dev/null +++ b/packages/rif-id-auth/test/auth.spec.js @@ -0,0 +1,290 @@ +const { rskTestnetDIDFromPrivateKey } = require('@rsksmart/rif-id-ethr-did') +const { mnemonicToSeed, seedToRSKHDKey, generateMnemonic } = require('@rsksmart/rif-id-mnemonic') +const { authExpressMiddleware, getChallenge, getAuthToken, initializeAuth } = require('../src') +const { getLoginJwt } = require('../src/test-utils') +const { verifyCredential } = require('did-jwt-vc') +const { getResolver } = require('ethr-did-resolver') +const { Resolver } = require('did-resolver') + +const expectToThrowErrorMessage = async (fn, message) => { + try { + await fn() + throw new Error('Did not throw any error') + } catch (err) { + expect(err.message).toEqual(message) + } +} + +const getMockedRes = (expectedError) => ({ + send: function (message) { + expect(message).toBe(expectedError) + }, + status: function (responseStatus) { + expect(responseStatus).toBe(401) + return this + } +}) + +const getMockedReq = (token) => ({ + headers: { + authorization: token + } +}) + +describe('auth tests', () => { + let identity, did, did2, signer, signer2, env, didResolver + + beforeAll(async () => { + const mnemonic = generateMnemonic(12) + const seed = await mnemonicToSeed(mnemonic) + const hdKey = seedToRSKHDKey(seed) + + const privateKey = hdKey.derive(0).privateKey.toString('hex') + identity = rskTestnetDIDFromPrivateKey()(privateKey) + + const privateKey2 = hdKey.derive(1).privateKey.toString('hex') + const identity2 = rskTestnetDIDFromPrivateKey()(privateKey2) + did2 = identity2.did + signer2 = identity2.signer; + + ({ did, signer } = identity) + env = { + did, + signer, + rpcUrl: 'https://did.testnet.rsk.co:4444', + authExpirationInHours: 4 + } + + const providerConfig = { networks: [{ name: 'rsk:testnet', registry: '0xdca7ef03e98e0dc2b855be647c39abe984fcf21b', rpcUrl: env.rpcUrl }] } + const ethrDidResolver = getResolver(providerConfig) + didResolver = new Resolver(ethrDidResolver) + }) + + describe('non initialized validations', () => { + it('getChallenge', () => { + expectToThrowErrorMessage(() => getChallenge(), 'Library not initialized') + }) + + it('getAuthToken', () => { + expectToThrowErrorMessage(() => getAuthToken(), 'Library not initialized') + }) + + it('authExpressMiddleware', () => { + expectToThrowErrorMessage(() => authExpressMiddleware(), 'Library not initialized') + }) + + it('should throw an error if the challenge has not been asked before', async () => { + initializeAuth(env) + + const jwt = await getLoginJwt('challenge', 'invalid', identity) + + await expectToThrowErrorMessage(() => getAuthToken(jwt), 'Request for a challenge before auth') + }) + }) + + describe('initialize', () => { + it('should throw an error if not env provided', () => { + expectToThrowErrorMessage(() => initializeAuth(), 'Missing env object') + }) + + it('should throw an error if not did provided', () => { + expectToThrowErrorMessage(() => initializeAuth({}), 'Missing env variable: did') + }) + + it('should throw an error if not signer provided', () => { + expectToThrowErrorMessage(() => initializeAuth({ did }), 'Missing env variable: signer') + }) + + it('should initialize the library and do not throw errors', () => { + initializeAuth({ did, signer }) + }) + }) + + describe('getChallenge', () => { + it('should get a challenge given a did', () => { + initializeAuth(env) + + const challenge = getChallenge(identity.did) + + expect(challenge).toBeTruthy() + expect(challenge).toHaveLength(128) + }) + + it('should throw an error if no did', () => { + initializeAuth(env) + expectToThrowErrorMessage(() => getChallenge(), 'Invalid did') + }) + }) + + describe('getAuthToken', () => { + beforeEach(() => { + initializeAuth(env) + }) + + it('should throw an error if no jwt', async () => { + await expectToThrowErrorMessage(() => getAuthToken(), 'JWT VC is required') + }) + + it('should throw an error if invalid jwt', async () => { + await expectToThrowErrorMessage(() => getAuthToken('invalid'), 'Incorrect format JWT') + }) + + it('should throw an error when sending an invalid challenge', async () => { + getChallenge(identity.did) + + const jwt = await getLoginJwt('challenge', 'invalid', identity) + + await expectToThrowErrorMessage(() => getAuthToken(jwt), 'Invalid challenge') + }) + + it('should throw an error when sending an invalid payload', async () => { + getChallenge(identity.did) + + const jwt = await getLoginJwt('notWhatIsNeeded', 'invalid', identity) + + await expectToThrowErrorMessage(() => getAuthToken(jwt), 'Invalid payload, missing challenge claim') + }) + + it('should get a valid token when sending the proper challenge', async () => { + const challenge = getChallenge(identity.did) + + const jwt = await getLoginJwt('challenge', challenge, identity) + + const token = await getAuthToken(jwt) + + expect(token).toBeTruthy() + + const { issuer, payload } = await verifyCredential(token, didResolver) + + expect(payload.sub).toEqual(identity.did) + expect(payload.exp).toBeLessThan((Date.now() / 1000) + env.authExpirationInHours * 60 * 60 + 10) // added 10 seconds of grace + expect(issuer).toEqual(env.did) + }, 8000) + }) + + describe('authExpressMiddleware', () => { + let next + + beforeEach(() => { + initializeAuth(env) + + next = jest.fn() + }) + + it('should call next() if valid token', async () => { + const challenge = getChallenge(identity.did) + + const jwt = await getLoginJwt('challenge', challenge, identity) + + const token = await getAuthToken(jwt) + + const mockedReq = getMockedReq(token) + const mockedRes = getMockedRes() + + await authExpressMiddleware(mockedReq, mockedRes, next) + + expect(next.mock.calls).toHaveLength(1) + }, 8000) + + it('should return a no token message', async () => { + const mockedReq = { headers: { } } + + await authExpressMiddleware(mockedReq, getMockedRes('No authorization header present')) + }) + + it('should return a no token message if empty token', async () => { + const mockedReq = getMockedReq('') + + await authExpressMiddleware(mockedReq, getMockedRes('No authorization header present')) + }) + + it('should return an invalid format token message', async () => { + const mockedReq = getMockedReq('invalid') + + await authExpressMiddleware(mockedReq, getMockedRes('Invalid token')) + }) + + it('should return invalid issuer message', async () => { + /* + * tries to send any other VC issued by an unknown issuer + * this test uses the VC JWT generated by the client, doesn't matter the claims contained in it + */ + + const identity2 = { did: did2, signer: signer2 } + + const jwt = await getLoginJwt('does-not', 'matter', identity2) + + const mockedReq = getMockedReq(jwt) + + await authExpressMiddleware(mockedReq, getMockedRes('Invalid VC issuer')) + }, 8000) + + it('should return max amount of requests reached', async () => { + const newEnv = { + ...env, + maxRequestsPerToken: 3 + } + + initializeAuth(newEnv) + + const challenge = getChallenge(identity.did) + + const jwt = await getLoginJwt('challenge', challenge, identity) + + const token = await getAuthToken(jwt) + + const mockedReq = getMockedReq(token) + const mockedRes = getMockedRes() + + // submit three requests + await authExpressMiddleware(mockedReq, mockedRes, next) + await authExpressMiddleware(mockedReq, mockedRes, next) + await authExpressMiddleware(mockedReq, mockedRes, next) + + // the fourth one should return a 401 + await authExpressMiddleware(mockedReq, getMockedRes('Max amount of requests reached')) + }, 12000) + }) + + describe('time related methods', () => { + let next + + beforeEach(() => { + initializeAuth(env) + + next = jest.fn() + }) + + it('should throw an error when sending a challenge that is expired', async () => { + jest.useFakeTimers() + + const challenge = getChallenge(identity.did) + + const jwt = await getLoginJwt('challenge', challenge, identity) + + jest.runAllTimers() + await expectToThrowErrorMessage(() => getAuthToken(jwt), 'Request for a challenge before auth') + }) + + it('should return expired vc message', async () => { + jest.useFakeTimers() + + initializeAuth(env) + + const challenge = getChallenge(identity.did) + + const jwt = await getLoginJwt('challenge', challenge, identity) + + const token = await getAuthToken(jwt) + + const mockedReq = getMockedReq(token) + const mockedRes = getMockedRes() + + // submit first request and should work + await authExpressMiddleware(mockedReq, mockedRes, next) + + jest.runAllTimers() + await authExpressMiddleware(mockedReq, getMockedRes('Expired token')) + }, 14000) + }) +})