1 | [![CircleCI](https://img.shields.io/circleci/project/github/uport-project/uport-connect.svg)](https://circleci.com/gh/uport-project/uport-connect)
|
2 | [![Join the chat at](https://img.shields.io/badge/Riot-Join%20chat-green.svg)](https://chat.uport.me/#/login)
|
3 | [![npm](https://img.shields.io/npm/dt/uport-connect.svg)](https://www.npmjs.com/package/uport-connect)
|
4 | [![npm](https://img.shields.io/npm/v/uport-connect.svg)](https://www.npmjs.com/package/uport-connect)
|
5 | [![Codecov](https://img.shields.io/codecov/c/github/uport-project/uport-connect.svg)](https://codecov.io/gh/uport-project/uport-connect)
|
6 | [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com)
|
7 | [![Twitter Follow](https://img.shields.io/twitter/follow/uport_me.svg?style=social&label=Follow)](https://twitter.com/uport_me)
|
8 |
|
9 | [Quick Start](#quick-start) | [Tutorial and Examples](#tutorials) | [Usage Guide](#usage-guide) | [Development Guide](#development-guide) | [Contributing](#contribute)
|
10 |
|
11 | **Required Upgrade v1.0.0 or ^0.7.5**
|
12 |
|
13 | **^0.7.5 to support new both new uPort Mobile Clients and legacy uPort Mobile Clients - [View Details](https://github.com/uport-project/uport-connect/releases/tag/v0.7.5)**
|
14 |
|
15 | **v1.0.0 to support only new uPort Mobile Clients and to use new features and fixes**
|
16 |
|
17 | :bangbang: :warning: **v1.0.0** is released at the npm next tag at **uport-connect@next**. Only the newest uPort Mobile Client release will work with **v1.0.0**. It will become the default release once the newest uPort Mobile Client release is widely adopted (~ 2 weeks). Reference master branch for docs and info on current default release **v0.7.5**. Documentation for **v1.0.0** can only be found here and in the docs folder. The [developer site](https://developer.uport.me) will not contain **v1.0.0** documentation until it is the default release :warning: :bangbang:
|
18 |
|
19 | # <a name="introduction"></a> Introduction
|
20 |
|
21 | **uPort** is a collection of tools and protocols for building decentralized user-centric applications. It is built on open standards and open source libraries. uPort identities can be created and interacted with through uPort clients, including the uPort mobile app. Identities are fully owned and controlled by the creator, and don't rely on centralized third-parties for creation, control or validation.
|
22 |
|
23 | `uport-connect` is the client side library that allows you interact with a user's uPort identity through a uPort client, primarily the mobile app. It handles the communication channel between your app and a uPort client, which can vary depending on the environment which your application runs. Over this communication channel you can send requests for a user's data, share credentials, generate transactions to be signed by a user and relay requests you originally created on your server with [uport-credentials](https://github.com/uport-project/uport-credentials). This library offers the default quick start implementation to integrate with uPort, but if it doesn't offer exactly what you need, you may be interested in using [uport-tranports](https://github.com/uport-project/uport-transports) and [uport-credentials](https://github.com/uport-project/uport-credentials) instead.
|
24 |
|
25 | For more information about our system and other products visit [uport.me](https://www.uport.me). View our [protocol specs](https://github.com/uport-project/specs/) if interested in understanding the lower level details.
|
26 |
|
27 | For any questions or library support reach out to the [uPort team on riot](https://chat.uport.me/#/login) or create a [Github issue](https://github.com/uport-project/uport-connect/issues).
|
28 |
|
29 | ---------------------------------------------
|
30 |
|
31 | ## <a name="getting-started"></a>Getting started with uPort
|
32 |
|
33 | For additional documentation on all functionality [visit our docs](https://github.com/uport-project/uport-connect/blob/develop/docs/reference/index.md). For a more interactive intro visit [developer.uport.me](https://developer.uport.me/gettingstarted). For a quick start continue below.
|
34 |
|
35 | ### <a name="quick-start"></a> Quick Start
|
36 |
|
37 | ```shell
|
38 | npm install uport-connect
|
39 | ```
|
40 |
|
41 | First we will instantiate the uPort object, by default it is configured on the Rinkeby test network, reference the docs for additional config arguments which can be passed.
|
42 |
|
43 | ```javascript
|
44 | import { Connect } from 'uport-connect'
|
45 | const uport = new Connect('MyDAppName')
|
46 | // or on mainnet
|
47 | // const uport = new Connect('MyDAppName', {network: 'mainnet'})
|
48 | ```
|
49 |
|
50 | To request the DID and address of user use `requestDisclosure()`:
|
51 |
|
52 | ```javascript
|
53 | uport.requestDisclosure()
|
54 |
|
55 | uport.onResponse('disclosureReq').then(res => {
|
56 | const did = res.payload.did
|
57 | ...
|
58 | })
|
59 | ```
|
60 |
|
61 | Or to request addtional credentials, along with the DID.
|
62 |
|
63 | ```javascript
|
64 | const reqObj = { requested: ['name', 'country'],
|
65 | notifications: true }
|
66 |
|
67 | uport.requestDisclosure(reqObj)
|
68 |
|
69 | uport.onResponse('disclosureReq').then(res => {
|
70 | const did = res.payload.did
|
71 | const verified = res.payload.verified // An array of shared verified credentials, matching requested
|
72 | ...
|
73 | })
|
74 | ```
|
75 |
|
76 | uPort Connect will save session data and data from prior requests to localStorage and will load it on instantiation. You can check if it is available before creating a selective disclosure request again.
|
77 |
|
78 | ```javascript
|
79 | if (uport.did) {
|
80 | // Already connected, reference docs to see data which will be available
|
81 | } else {
|
82 | // Create a request if necessary
|
83 | }
|
84 | ```
|
85 |
|
86 | To send a request message (JWT) you created on your server or elsewhere use `send()`:
|
87 |
|
88 | ```javascript
|
89 | const reqID = 'myRequestID'
|
90 | const request = `eyJ0eXAiOiJKV1QiLCJhbG...`
|
91 | uport.send(request, reqID)
|
92 | uport.onResponse(reqID).then(payload => {
|
93 | // Response is available now, handle as necessary to your implementation
|
94 | // If the response was returned your server, you may poll for it now
|
95 | })
|
96 | ```
|
97 |
|
98 | To request a user to sign a claim
|
99 |
|
100 | ```javascript
|
101 | const unsignedClaim = {
|
102 | "Citizen of city X": {
|
103 | "Allowed to vote": true,
|
104 | "Document": "QmZZBBKPS2NWc6PMZbUk9zUHCo1SHKzQPPX4ndfwaYzmPW"
|
105 | }
|
106 | }
|
107 |
|
108 | const sub ="did:ethr:0x413daa771a2fc9c5ae5a66abd144881ef2498c54"
|
109 |
|
110 | uport.requestVerificationSignature(unsignedClaim, sub)
|
111 |
|
112 | uport.onResponse('verSigReq').then(res => {
|
113 | const signedClaim = res.payload
|
114 | })
|
115 | ```
|
116 |
|
117 | To create a transaction request use `contract()` or `sendTransaction()`:
|
118 |
|
119 | ```javascript
|
120 | const abi = [{"constant": false,"inputs": [{"name": "status","type": "string"}],"name": "updateStatus","outputs": [],"type": "function"}]
|
121 | const contractAddress = '0x71845bbfe5ddfdb919e780febfff5eda62a30fdc'
|
122 | const statusContract = uport.contract(abi).at(contractAddress)
|
123 |
|
124 | statusContract.updateStatus('hello', 'updateStatusReq')
|
125 | uport.onResponse('updateStatusReq').then(payload => {
|
126 | const txId = payload.res
|
127 | })
|
128 | ```
|
129 |
|
130 | ```javascript
|
131 | const txObj = {
|
132 | address: '0x71845bbfe5ddfdb919e780febfff5eda62a30fdc',
|
133 | value: 1 * 1.0e18
|
134 | }
|
135 | uport.sendTransaction(txObj, 'ethSendReq')
|
136 | uport.onResponse('ethSendReq').then(res => {
|
137 | const txId = res.payload
|
138 | })
|
139 | ```
|
140 | ### <a name="quick-start"></a> Quick Start with Provider (web3)
|
141 |
|
142 | Get provider and instantiate web3 or other provider supported library.
|
143 |
|
144 | ```javascript
|
145 | const provider = uport.getProvider()
|
146 | const web3 = new Web3(provider)
|
147 | ```
|
148 |
|
149 | To request the address of user:
|
150 |
|
151 | ```javascript
|
152 | web3.eth.getCoinbase((error, address) => { ... })
|
153 | ```
|
154 |
|
155 | To call contract:
|
156 | ```javascript
|
157 | const statusContract = web3.eth.contract(abi).at(contractAddress)
|
158 | statusContract.updateStatus('hello', (error, txHash) => { ... })
|
159 | ```
|
160 |
|
161 | To send transaction:
|
162 | ```javascript
|
163 | web3.eth.sendTransaction(txObj, (error, txHash) => {...})
|
164 | ```
|
165 |
|
166 | ### Private Chain support
|
167 |
|
168 | While the primary uPort Credentials functionality does not tie you to any specific blockchain. You are able to request ethereum accounts for use with private ethereum compatible chains. You will need a network ID and a JSON-RPC endpoint accessible to both your browser app and the mobile client.
|
169 |
|
170 | To configure it, pass in a network object for configuration.
|
171 |
|
172 | ```javascript
|
173 | const uport = new Connect('MyDAppName', {
|
174 | network: {
|
175 | id: '0xdeadbeef',
|
176 | rpcUrl: 'https://mybankrpc.example.com/'
|
177 | }
|
178 | })
|
179 | const provider = uport.getProvider()
|
180 | const web3 = new Web3(provider)
|
181 | web3.eth.getCoinbase((error, address) => { ... }) // request address for use on private chain
|
182 | ```
|
183 |
|
184 | ### <a name="browser-quick-start"></a> Browser Window Quick Start
|
185 |
|
186 | For use directly in the browser you can reference the uport-connect distribution files from a number of places. They can be found in our npm package in the 'dist' folder or you can build them locally from this repo.
|
187 |
|
188 | For a quick setup you may also request a remote copy from [unpkg CDN](https://unpkg.com/) as follows:
|
189 |
|
190 | ```html
|
191 | <!-- The most recent version -->
|
192 | <script src="https://unpkg.com/uport-connect/dist/uport-connect.js"></script>
|
193 | <!-- The most recent minified version -->
|
194 | <script src="https://unpkg.com/uport-connect/dist/uport-connect.min.js"></script>
|
195 | <!-- You can also fetch specific versions by specifying the version, files names may differ for past versions -->
|
196 | <script src="https://unpkg.com/uport-connect@<version>/dist/uport-connect.js"></script>
|
197 | ```
|
198 | To see all available dist files on unpkg, vist [unpkg.com/uport-connect/dist/](https://unpkg.com/uport-connect/dist/)
|
199 |
|
200 | Then to instantiate the uPort object from the browser window object:
|
201 |
|
202 | ```js
|
203 | const Connect = window.uportconnect
|
204 | const uport = new Connect('MyDApp')
|
205 | ```
|
206 |
|
207 | ### <a name="tutorials"></a> Tutorials and Developer Site
|
208 |
|
209 | For a more in depth guide, check out our [developer site](https://developer.uport.me/uport-connect/guides/usage) or clone this repository and check out the sample apps in the `/examples` folder.
|
210 |
|
211 | ---------------------------------------------
|
212 |
|
213 | ## <a name="development-guide"></a> Development Guide
|
214 |
|
215 | #### Run Locally
|
216 |
|
217 | Download this repo or your fork, then run `npm install`.
|
218 |
|
219 | #### <a name="build"></a> Builds
|
220 |
|
221 | All builds are created from files in `/src`
|
222 |
|
223 | To transpile to ES5. All files are output to `/lib`. The entry of our npm package is `/lib/Connect.js`
|
224 |
|
225 | ```shell
|
226 | $ npm run build:es5
|
227 | ```
|
228 |
|
229 | To generate a bundle/distributable. We use webpack for our builds. The output dist is `/dist/uport-connect.js` and source map `/dist/uport-connect.map.js`
|
230 |
|
231 | ```shell
|
232 | $ npm run build:dist
|
233 | ```
|
234 |
|
235 | To generate a production bundle/distributable. Includes build optimizations related to size and code is minified. The output dist is `/dist/uport-connect.min.js` and source map `/dist/uport-connect.min.map.js`
|
236 |
|
237 | ```shell
|
238 | $ npm run build:dist:prod
|
239 | ```
|
240 |
|
241 | #### <a name="test"></a> Tests
|
242 |
|
243 | We write our tests using [mocha](http://mochajs.org) and run them with [karma](https://karma-runner.github.io/1.0/index.html).
|
244 |
|
245 | To run our tests:
|
246 |
|
247 | ```shell
|
248 | $ npm test
|
249 | ```
|
250 |
|
251 | #### <a name="coverage"></a> Code Coverage
|
252 |
|
253 | Code coverage reports are generated when tests are run and can be viewed in browser. Reports are also published on [CodeCov](https://codecov.io/gh/uport-project/uport-connect) when pushed to github.
|
254 |
|
255 | ```shell
|
256 | $ npm test
|
257 | $ open test/coverage/html/index.html
|
258 | ```
|
259 |
|
260 | #### <a name="lint"></a> Linting
|
261 |
|
262 | Run our linter, we follow [JavaScript Standard Style](http://standardjs.com/).
|
263 |
|
264 | ```shell
|
265 | $ npm run lint
|
266 | ```
|
267 | #### <a name="docs"></a> Documentation
|
268 |
|
269 | We write inline documentation using [JSDoc](http://usejsdoc.org). To generate docs:
|
270 |
|
271 | ```shell
|
272 | $ npm run build:docs:html
|
273 | $ open docs/index.html
|
274 | ```
|
275 | ```shell
|
276 | $ npm run build:docs:md // to generate a markdown file in /docs folder
|
277 | ```
|
278 |
|
279 | #### <a name="scripts"></a> Scripts
|
280 |
|
281 | Additional scripts can be found in `package.json -> scripts: { }`.
|
282 |
|
283 |
|
284 | #### <a name="versioning"></a> Versioning
|
285 |
|
286 | We follow MAJOR.MINOR.PATCH [Semantic Versioning](http://semver.org)
|
287 |
|
288 |
|
289 | #### <a name="npm-install"></a> NPM Install Develop branch
|
290 |
|
291 | You can npm install the develop branch of uport-connect using the follow commands.
|
292 |
|
293 | ```shell
|
294 | $ npm install "git://github.com/uport-project/uport-connect.git#develop" --save
|
295 | $ (cd node_modules/uport-connect && npm install babel-cli && npm run prepublish)
|
296 | ```
|
297 |
|
298 | ### <a name="frontend"></a> Frontend Library Specific Fixes
|
299 | Each Frontend Library React, Angular, Vue, etc... can sometimes require specific configuration settings. To prevent developers from solving the same problems twice we're going document Library specific issues on a case-by-case basis.
|
300 |
|
301 | #### <a name="angular"></a> Angular
|
302 | When adding the `uport-connect.js` library to an Angular project please install the `crypto-browserify` module as a project dependency and create a path alias pointing `crypto` to the `crypto-browserify` module.
|
303 |
|
304 | This will fix a `crypto.createHash()` undefined error.
|
305 |
|
306 | ```
|
307 | "paths": {
|
308 | "crypto": ["../node_modules/crypto-browserify/index.js"]
|
309 | }
|
310 | ```
|
311 |
|
312 | #### <a name="frontend-other"></a> Other Frontend Libraries
|
313 | Are you experiencing other Frontend Library specific issues?
|
314 |
|
315 | Let us know in <a href="https://github.com/uport-project/uport-connect/issues"> the issues</a>.
|
316 |
|
317 |
|
318 | ## <a name="contribute"></a> Contributing
|
319 |
|
320 | Code, test and documentation contributions are welcomed and encouraged. Please read the guidelines below and reach out on our [riot](https://chat.uport.me/#/login) or create an [issue](https://github.com/uport-project/uport-connect/issues) if any contribution is more than trivial. We can help you see where/if it fits into our roadmap and if we are likely to accept. We are also looking to add references to projects using `uport-connect` with example implementations and use cases.
|
321 |
|
322 | #### <a name="bugs"></a> Reporting Bugs
|
323 |
|
324 | Well formed bug reports are hugely valuable to the project and allow us quickly evaluate and fix a bug. Poorly formed bug reports leave use searching for more details and even worse may leave us trying to resolve bugs not related to the code here. Primarily be thoughtful when submitting bugs and leave enough details to minimize the paths we have to take when finding a resolution. Report bugs by creating an [issue](https://github.com/uport-project/uport-connect/issues).
|
325 |
|
326 | Some guidelines for reporting bugs:
|
327 |
|
328 | - Make sure that your issue is caused by uport-connect and not your application code.
|
329 | - Create a simple and minimal test case that demonstrates the bug.
|
330 | - Search the issues to see if the bug has already been reported. If it has, add any additional details in the comments.
|
331 | - Write a descriptive and specific title.
|
332 | - Include browser, OS, uport-connect version and any other details specific to the environment.
|
333 | - Check whether the bug can be reproduced in other environments (ie. other browsers).
|
334 |
|
335 | #### <a name="code"></a> Contributing code
|
336 |
|
337 | Our `master` branch reflects our most recent release, while we accept pull requests from topic branches into our `develop` branch. To submit code for a feature, bug or documentation, [fork this repo](https://help.github.com/articles/fork-a-repo/) and add all related commits to a topic branch (feature/your-title, fix/your-title, doc/your-title, etc). Once ready for review, open a pull request to merge into `develop`.
|
338 |
|
339 | All commits are required to be well formed. We follow the [AngularJS Commit Message Conventions](https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#commit). We use these commit messages to create a useful history, generate CHANGELOGS and to determine release versions.
|
340 |
|
341 | Before submitting your changes run `npm run lint` to find any formatting issues that don't adhere to the original codebase. Run `npm run karma` to be sure all tests pass. When submitting a bug fix try to add additional tests to cover that bug or similar bugs in the future. If a bug was specific to an environment consider adding a environment specific note in the docs. When submitting code for a new feature or functionality add the relevant documentation and test coverage as well.
|