-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from ProjectPeter/develop
Release
- Loading branch information
Showing
20 changed files
with
3,853 additions
and
713 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,5 @@ | ||
{ | ||
"presets": ["@babel/env"], | ||
"plugins": [ | ||
["@babel/plugin-proposal-decorators", { "legacy": true }], | ||
"@babel/plugin-proposal-function-sent", | ||
"@babel/plugin-proposal-export-namespace-from", | ||
"@babel/plugin-proposal-numeric-separator", | ||
"@babel/plugin-proposal-throw-expressions", | ||
"@babel/plugin-syntax-dynamic-import", | ||
"@babel/plugin-syntax-import-meta", | ||
["@babel/plugin-proposal-class-properties", { "loose": false }], | ||
"@babel/plugin-proposal-json-strings", | ||
["@babel/plugin-transform-runtime", { | ||
"regenerator": true | ||
}] | ||
], | ||
"sourceMaps": true, | ||
"retainLines": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "airbnb-base", | ||
"rules": { | ||
"no-underscore-dangle": 0, | ||
"class-methods-use-this": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TBD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,135 @@ | ||
# TMNT Client | ||
# Sobol Client | ||
|
||
A JavaScript client library exposing Sobol's RESTful API. | ||
|
||
## Install | ||
|
||
```bash | ||
npm install sobol-client | ||
``` | ||
|
||
Then include in: | ||
|
||
**Node**: | ||
|
||
```javascript | ||
const SobolClient = require('sobol-client'); | ||
``` | ||
|
||
**Browser**: | ||
```html | ||
<script src="./node_modules/sobol-client/dist/sobol-client.js"> | ||
``` | ||
## Connect | ||
API access is granted with the use of [API Keys](docs/keys.md) as follows: | ||
```javascript | ||
SobolClient.connect({ | ||
key: { | ||
private: 'LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUpR...', | ||
kid: '_SkDk2GrZ', | ||
}, | ||
}) | ||
.then((client) => { | ||
console.log(client.getSession()); | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
}); | ||
``` | ||
**Note**: To obtain keys, contact [email protected]. | ||
## Query | ||
To query the API, refer to the following list of endpoints and operations in [client.js](src/client.js). | ||
E.g.: | ||
```javascript | ||
const { Users } = client; | ||
const { user } = client.getSession(); | ||
Users.find() | ||
.then((res) => { | ||
const users = res.data; | ||
// check for automated users | ||
console.log( | ||
'Automated Users?', | ||
(users.includes(user) | ||
? 'Yup! That\'s bad :(' | ||
: 'Nope! Yay that\'s good!' | ||
) | ||
); | ||
// kill the session | ||
client.disconnect(); | ||
}); | ||
``` | ||
## Extend | ||
To extend this library, create a subclass as follows: | ||
```javascript | ||
// client.js | ||
const SobolClient = require('sobol-client/src/client'); | ||
class MyClient extends SobolClient { | ||
constructor() { | ||
super(); | ||
this.Applications = { | ||
find: () => this._request.get(`${this._orgPath}/applications`), | ||
}; | ||
} | ||
} | ||
module.exports = new Client(); // instantiates a singleton | ||
``` | ||
Then use in: | ||
```javascript | ||
// index.js | ||
const MyClient = require('./client.js'); | ||
MyClient.connect({ | ||
key: { | ||
private: 'LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUpR...', | ||
kid: '_SkDk2GrZ', | ||
}, | ||
}) | ||
.then((client) => { | ||
const { Applications } = client; | ||
return Applications.find() | ||
.then((res) => { | ||
console.log('Applications:', res.data); | ||
}); | ||
}); | ||
``` | ||
**Note**: the browser distribution can not be extended directly. | ||
## Development | ||
**Install:** | ||
- Clone repository | ||
- Install dependencies with: `npm install` | ||
**Run**: (include keys in `./tests/*.js`) | ||
- Node: `npm run start-node` | ||
- Browser: `npm run start-browser` | ||
**Build**: | ||
- Build browser distribution: `npm run build` | ||
- Build and watch: `npm run watch` | ||
**Publish**: | ||
- Locally: `npm link` | ||
- NPM: `npm publish` |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# API Keys | ||
|
||
To access Sobol's API layer, you must be issued `API Keys`. | ||
Use these keys **manually** or with the **client**. | ||
|
||
**Note**: To obtain keys, contact [email protected]. | ||
|
||
## RSA Key Pairs | ||
|
||
Sobol uses [RSA](https://en.wikipedia.org/wiki/RSA_(cryptosystem)) key signing to authenticate with the API. These keys are as follows: | ||
|
||
```json | ||
{ | ||
"kid": "_4kDg2GrZ", | ||
"kty": "rsa", | ||
"kft": "base64", | ||
"key": { | ||
"public": "LS0tLS1CRUdJTiBddfdfdcv3DDSQVUJM5gS0VZLS0tL...", | ||
"private": "LS0tLS1CRiBddfUdJTdiFWidBddfS0tLS0tCk1JSUp..." | ||
}, | ||
"alg": { | ||
"public": "spki", | ||
"private": "pkcs8" | ||
} | ||
} | ||
``` | ||
**Note**: The RSA key pairs are encoded in `base64` and will have to be decoded when used with most RSA signing [libraries](#libraries). | ||
|
||
## Authorization | ||
|
||
The client performs the following steps to authenticate: | ||
|
||
1. Decodes the supplied `private` key from `base64` to `ascii` | ||
2. Signs a `base64` encoded `SHA256 signature` using the `kid` and the `private` key | ||
2. `POST`s the following `body` to https://consensys-mesh.com/api/v1/login/ : | ||
|
||
```json | ||
{ | ||
"type": "rsa", | ||
"authorization": { | ||
"signature": "OiJSUzI1NiIDfFdEadfdfsInR5cCI...", | ||
"kid": "_4kDg2GrZ" | ||
} | ||
} | ||
``` | ||
|
||
3. Includes the returned [JWT](https://jwt.io/) in every subsequent request as follows: | ||
|
||
```json | ||
{ | ||
"Authorization": "Bearer eyJhbGciOiJSUzI1NiIDfFdEadfdInR9..." | ||
} | ||
``` | ||
|
||
4. Decodes session information from the JWT resulting in: | ||
|
||
```json | ||
{ | ||
"type": "", | ||
"user": {}, | ||
"orgIds": [] | ||
} | ||
``` | ||
|
||
## Libraries | ||
|
||
* [JWT](https://jwt.io/) | ||
* [OpenSSL](https://www.openssl.org/) | ||
* [cypto](https://nodejs.org/api/crypto.html) | ||
* [Python RSA](https://pypi.org/project/rsa/) | ||
* [Java Example](https://gist.github.com/nielsutrecht/855f3bef0cf559d8d23e94e2aecd4ede) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,51 @@ | ||
{ | ||
"name": "tmnt-client", | ||
"name": "sobol-client", | ||
"version": "0.0.1", | ||
"description": "Provides a JavaScript client to TMNT's API.", | ||
"main": "src/client.js", | ||
"repository": "[email protected]:vleipnik-consensys/tmnt-client.git", | ||
"author": "TMNT", | ||
"description": "A JavaScript client library exposing Sobol's RESTful API.", | ||
"main": "src/index.js", | ||
"repository": "[email protected]:ProjectPeter/sobol-client.git", | ||
"author": "Sobol", | ||
"license": "MIT", | ||
"private": true, | ||
"scripts": { | ||
"start-node": "cross-env NODE_ENV=development nodemon --watch src --watch tests --exec babel-node tests/node.js", | ||
"start-node": "cross-env NODE_ENV=development nodemon --watch src --watch tests --exec node tests/node.js", | ||
"start-browser": "cross-env NODE_ENV=development webpack-dev-server --progress --open --mode development --config webpack.config.js", | ||
"build-node": "", | ||
"build-browser": "" | ||
"build": "cross-env NODE_ENV=production webpack -p --progress --mode production --config webpack.config.js", | ||
"watch": "cross-env NODE_ENV=development nodemon --watch src --watch tests --exec npm run build", | ||
"lint": "eslint ./src/ ./tests/", | ||
"release": "release-it --github.release" | ||
}, | ||
"dependencies": { | ||
"axios": "^0.18.0", | ||
"jsonwebtoken": "^8.3.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.1.2", | ||
"@babel/node": "^7.0.0", | ||
"@babel/plugin-proposal-class-properties": "^7.1.0", | ||
"@babel/plugin-proposal-decorators": "^7.1.2", | ||
"@babel/plugin-proposal-export-namespace-from": "^7.0.0", | ||
"@babel/plugin-proposal-function-sent": "^7.1.0", | ||
"@babel/plugin-proposal-json-strings": "^7.0.0", | ||
"@babel/plugin-proposal-numeric-separator": "^7.0.0", | ||
"@babel/plugin-proposal-throw-expressions": "^7.0.0", | ||
"@babel/plugin-syntax-dynamic-import": "^7.0.0", | ||
"@babel/plugin-syntax-import-meta": "^7.0.0", | ||
"@babel/plugin-transform-runtime": "^7.1.0", | ||
"@babel/preset-env": "^7.1.0", | ||
"@babel/runtime": "7.0.0-beta.55", | ||
"babel-loader": "^8.0.4", | ||
"clean-webpack-plugin": "^0.1.19", | ||
"cross-env": "^5.2.0", | ||
"eslint": "^5.3.0", | ||
"eslint-config-airbnb-base": "13.1.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"html-webpack-plugin": "^3.2.0", | ||
"husky": "^1.1.2", | ||
"lint-staged": "^7.3.0", | ||
"nodemon": "^1.18.4", | ||
"release-it": "^7.6.2", | ||
"uglifyjs-webpack-plugin": "^2.0.1", | ||
"webpack": "^4.20.2", | ||
"webpack-cli": "^3.1.2", | ||
"webpack-dev-server": "^3.1.9" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged && npm run build && git add dist" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.js": [ | ||
"eslint --fix", | ||
"git add" | ||
] | ||
} | ||
} |
Oops, something went wrong.