Giter VIP home page Giter VIP logo

uport-lib's Introduction

WARNING: uport-lib renamed uport-connect

As of February 2017 our library uport-lib has been renamed uport-connect on npm and our new repo can be found here https://github.com/uport-project/uport-connect. From February 2017 onwards, all functionality, future features, support, and additional details can be found in uport-connect.


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 address
  • web3.eth.getAccounts()- returns your uport address in a list
  • web3.eth.sendTransaction(txObj) - returns a transaction hash
  • myContract.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) { // your code here },
    closeQr() { // your code here }
  }
}

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 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 install from Github

To install this package from Github and the develop branch:

$ npm install "git://github.com/ConsenSys/uport-lib.git#develop" --save
$ (cd node_modules/uport-lib && npm install babel-cli && npm run prepublish)

uport-lib's People

Contributors

zachferland avatar pelle avatar oed avatar coder5876 avatar jeffscottward avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.