[![uport][uport-image]][uport-url]
[![uport chat][gitter-image]][gitter-url]
Introduction
Uport is a system for self-sovereign digital identity.
This is the client side library that is used to interact with the mobile application where the end-user's keys are stored.
Signing transactions thus requires that the transactions are sent to the phone where they can be signed.
This is accomplished by showing the user a QR-code for each transaction.
The user can then verify the transaction on the phone and send it to the Ethereum network.
In order to make this flow easy for developers, uport-lib
provides a custom web3 provider which takes care of all of this.
Using uPort in your dapp
Getting Started
First we will instantiate the Uport and Web3 objects.
Then we will get the information of the connected user.
Since the information of the connected user is stored on ipfs we need to provide uport-lib with an ipfs provider upon on creation of Uport instance.
Here we use Infura as an example.
import { Uport } from 'uport-lib'
let uport = new Uport('MyDApp')
let web3 = uport.getWeb3()
uport.getUserPersona()
.then((persona) => {
let profile = persona.profile
console.log(profile)
})
After the above setup, you can now use the web3
object as normal.
Also, the following calls will show a QR code for the user to scan:
web3.eth.getCoinbase()
- returns your uport addressweb3.eth.getAccounts()
- returns your uport address in a listweb3.eth.sendTransaction(txObj)
- returns a transaction hashmyContract.myMethod()
- returns a transaction hash
Check out the examples folder too for how to integrate uport in your DApp
Custom Display of QR codes
uport-lib
features a default QR-code display function, which injects a <div>
containing the QR-code into the DOM.
However, you might want to display the QR-code in a different way.
You can provide a qrDisplay
object with two functions when uport is created.
The openQr
function is called when the user needs to confirm something on the uport app.
The data argument is a uri that needs to be displayed in a QR-code so that the uport app can scan it.
The closeQr
function is called when the action has been confirmed in the uport app and the QR-code can be removed from the screen.
let options = {
qrDisplay: {
openQr(data) {
closeQr() {
}
}
The openQr
function is called each time some information needs to get to the phone.
The closeQr
is called once the phone has taken an action on the data in the QR-code.
Interacting with persona objects of other users
You can also import the Persona
classes from uport lib to interact with any persona in the uport-registry
.
uport.getUserPersona()
.then((persona) => {
let profile = persona.profile
console.log(profile)
})```
More information on how to use personas can be found in the [uport-persona](https://github.com/ConsenSys/uport-persona) repo, or by reading the documentation below.
---------------------------------------------
## Contributing
#### Testing / Building (& watching) / Docs
This basic commands can be found in `package.json -> scripts: { }` for contributing to the library.
npm run test
npm run build
npm run watch
npm run gen-readme
---------------------------------------------
<!-- Badge Variables -->
[uport-image]: https://ipfs.pics/ipfs/QmVHY83dQyym1gDWeMBom7vLJfQ6iGycSWDYZgt2n9Lzah
[uport-url]: https://uport.me
[gitter-image]: https://img.shields.io/badge/gitter-uport--lib-red.svg?style=flat-square
[gitter-url]: https://gitter.im/ConsenSys/uport-lib
<!-- TODO: Add applicable badges
[travis-url]: https://travis-ci.org/webpack/webpack
[travis-image]: https://img.shields.io/travis/webpack/webpack/master.svg
[appveyor-url]: https://ci.appveyor.com/project/sokra/webpack/branch/master
[appveyor-image]: https://ci.appveyor.com/api/projects/status/github/webpack/webpack?svg=true
[coveralls-url]: https://coveralls.io/r/webpack/webpack/
[coveralls-image]: https://img.shields.io/coveralls/webpack/webpack.svg
[npm-url]: https://www.npmjs.com/package/webpack
[npm-image]: https://img.shields.io/npm/v/webpack.svg
[downloads-image]: https://img.shields.io/npm/dm/webpack.svg
[downloads-url]: http://badge.fury.io/js/webpack
[david-url]: https://david-dm.org/webpack/webpack
[david-image]: https://img.shields.io/david/webpack/webpack.svg
[david-dev-url]: https://david-dm.org/webpack/webpack#info=devDependencies
[david-dev-image]: https://david-dm.org/webpack/webpack/dev-status.svg
[david-peer-url]: https://david-dm.org/webpack/webpack#info=peerDependencies
[david-peer-image]: https://david-dm.org/webpack/webpack/peer-status.svg
[nodei-image]: https://nodei.co/npm/webpack.png?downloads=true&downloadRank=true&stars=true
[nodei-url]: https://www.npmjs.com/package/webpack
-->
## Documentation
ERROR, Cannot find class.
<a name="Registry"></a>
## Registry
Class representing a uPort Registry.
**Kind**: global class
* [Registry](#Registry)
* [.constructor(settings)](#Registry+constructor) ⇒ <code>Object</code>
* [.getPublicProfile()](#Registry+getPublicProfile) ⇒ <code>Promise.<JSON, Error></code>
* [.getPersona()](#Registry+getPersona) ⇒ <code>Promise.<PublicPersona, Error></code>
* [.getPersonas()](#Registry+getPersonas) ⇒ <code>Promise.<PublicPersona, Error></code>
<a name="Registry+constructor"></a>
### registry.constructor(settings) ⇒ <code>Object</code>
Class constructor.
Creates a new Registry object. The registryAddress is an optional argument and if not specified will be at the moment set to the default ropsten network uport-registry.
**Kind**: instance method of <code>[Registry](#Registry)</code>
**Returns**: <code>Object</code> - self
| Param | Type | Description |
| --- | --- | --- |
| settings | <code>Object</code> | optional settings containing web3, ipfs and registry settings |
<a name="Registry+getPublicProfile"></a>
### registry.getPublicProfile() ⇒ <code>Promise.<JSON, Error></code>
Gets the public profile JSON object stored in IPFS for the given address.
**Kind**: instance method of <code>[Registry](#Registry)</code>
**Returns**: <code>Promise.<JSON, Error></code> - A promise that returns the JSON object stored in IPFS for the given address
<a name="Registry+getPersona"></a>
### registry.getPersona() ⇒ <code>Promise.<PublicPersona, Error></code>
Gets the the data stored in IPFS for the given object and creates a PublicPersona object.
**Kind**: instance method of <code>[Registry](#Registry)</code>
**Returns**: <code>Promise.<PublicPersona, Error></code> - A promise that returns a new PublicPersona object.
<a name="Registry+getPersonas"></a>
### registry.getPersonas() ⇒ <code>Promise.<PublicPersona, Error></code>
Gets the data stored in IPFS for an array of given addresses and creates an array of PublicPersona objects.
**Kind**: instance method of <code>[Registry](#Registry)</code>
**Returns**: <code>Promise.<PublicPersona, Error></code> - A promise that returns an array of new PublicPersona objects.
<a name="PublicPersona"></a>
## PublicPersona
Class representing PublicPersona, extends PersonaInterface
**Kind**: global class
* [PublicPersona](#PublicPersona)
* [.constructor(publicProfile, address)](#PublicPersona+constructor) ⇒ <code>Object</code>
* [.profile()](#PublicPersona+profile) ⇒ <code>Object</code>
<a name="PublicPersona+constructor"></a>
### publicPersona.constructor(publicProfile, address) ⇒ <code>Object</code>
Class constructor.
Creates a new PublicPersona object.
**Kind**: instance method of <code>[PublicPersona](#PublicPersona)</code>
**Returns**: <code>Object</code> - self
| Param | Type | Description |
| --- | --- | --- |
| publicProfile | <code>JSON</code> | Public Profile on IPFS |
| address | <code>String</code> | The identity address |
<a name="PublicPersona+profile"></a>
### publicPersona.profile() ⇒ <code>Object</code>
A getter which returns a simple Profile Object
**Kind**: instance method of <code>[PublicPersona](#PublicPersona)</code>