Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

uport-connect

Package Overview
Dependencies
Maintainers
4
Versions
149
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uport-connect

Library for integrating uPort into your app frontend

  • 0.8.14-alpha-31
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
64
decreased by-40.74%
Maintainers
4
Weekly downloads
 
Created
Source

CircleCI Join the chat at npm npm Codecov js-standard-style Twitter Follow

Quick Start | Tutorial and Examples | Usage Guide | Development Guide | Contributing

Introduction

Required Upgrade to v0.7.5 to support new uPort Clients - View Details

uPort is a system for self-sovereign digital identity anchored in Ethereum. The uPort technology primarily consists of smart contracts, developer libraries, microservices and uPort clients including our mobile app. uPort identities are fully owned and controlled by the creator, and don't rely on centralized third-parties for creation, control or validation. In the current implementation of the system this is achievable by having the mobile app act as the primary secure container for data related to your identity and for a set of keys which allow you sign transactions, grant authorization and sign credentials. The identity is anchored in the blockchain with an identifier and public data is stored in IPFS.

uport-connect is the client side library that allows you interact with user's uPort identities 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-js. 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-core-js and uport-js instead.

For more information about our system and other products visit uport.me. View our protocol specs if interested in understanding some of the lower level details.

For any questions or library support reach out to the uPort team on riot or create a Github issue.


Getting started with uPort

For additional documentation on all functionality visit our docs. For a more interactive intro visit developer.uport.me. For a quick start continue below.

Quick Start

npm install uport-connect

First we will instantiate the uPort object, by default it is configured on the Rinkeby test network.

import Connect from 'uport-connect'
const uport = new Connect('MyDAppName')

To request the ID and address of user use requestAddress():

uport.requestAddress()
uport.onResponse('addressReq').then(payload => {
  const address = payload.res.address
  // or
  // const address = uport.address
  // const doc = uport.doc
  // TODO Show whats in the doc
})

To send a request token you created on your server or elsewhere use request():

const requestToken = `eyJ0eXAiOiJKV1QiLCJhbG...`
uport.request(token, 'myRequestID')
uport.onResponse('myRequestId').then(payload => {
  // Response is available now, handle as necessary to your implementation
  // If the response was returned your server, you may poll for it now
})

To create a transaction request use contract() or sendTransaction():

const abi = [{"constant": false,"inputs": [{"name": "status","type": "string"}],"name": "updateStatus","outputs": [],"type": "function"}]
const contractAddress = '0x71845bbfe5ddfdb919e780febfff5eda62a30fdc'
const statusContract = uport.contract(abi).at(contractAddress)

statusContract.updateStatus('hello', 'updateStatusReq')
uport.onResponse('updateStatusReq').then(payload => {
  const txId = payload.res
})
const txObj = {
  address: '0x71845bbfe5ddfdb919e780febfff5eda62a30fdc',
  value: 1 * 1.0e18
}
uport.sendTransaction(txObj, 'ethSendReq')
uport.onResponse('ethSendReq').then(payload => {
  const txId = payload.res
})

Quick Start with Provider (web3)

Get provider and instantiate web3 or other provider supported library.

const provider = uport.getProvider()
const web3 = new Web3(provider)

To request the address of user:

web3.eth.getCoinbase((error, address) => { ... })

To call contract:

const statusContract = web3.eth.contract(abi).at(contractAddress)
statusContract.updateStatus('hello', (error, txHash) => { ... })

To send transaction:

web3.eth.sendTransaction(txObj, (error, txHash) => {...})

Browser Window Quick Start

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.

For a quick setup you may also request a remote copy from unpkg CDN as follows:

<!-- The most recent version  -->
<script src="https://unpkg.com/uport-connect/dist/uport-connect.js"></script>
<!-- The most recent minified version  -->
<script src="https://unpkg.com/uport-connect/dist/uport-connect.min.js"></script>
<!-- You can also fetch specific versions by specifying the version, files names may differ for past versions -->
<script src="https://unpkg.com/uport-connect@<version>/dist/uport-connect.js"></script>

To see all available dist files on unpkg, vist unpkg.com/uport-connect/dist/

Then to instantiate the uPort object from the browser window object:

var Connect = window.uportconnect
var uport = new Connect('MyDApp')

Tutorial and Examples

For a more in depth quick start example follow our tutorial for building a simple dapp or locally open the /examples folder. This simple example will show you how to use our default QR flow to connect and create transactions to send ether or interact with smart contracts.


Development Guide

Run Locally

Download this repo or your fork, then run npm install.

Builds

All builds are created from files in /src

To transpile to ES5. All files are output to /lib. The entry of our npm package is /lib/Connect.js

$ npm run build:es5

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

$ npm run build:dist

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

$ npm run build:dist:prod
Tests

We write our tests using mocha and run them with karma. TestRPC runs in the background during tests.

To run our tests:

$ npm test
Code Coverage

Code coverage reports are generated when tests are run and can be viewed in browser. Reports are also published on CodeCov when pushed to github.

$ npm test
$ open test/coverage/html/index.html
Linting

Run our linter, we follow JavaScript Standard Style.

$ npm run lint
Documentation

We write inline documentation using JSDoc. To generate docs:

$ npm run build:docs:html
$ open docs/index.html
$ npm run build:docs:md // to generate a markdown file in /docs folder
Scripts

Additional scripts can be found in package.json -> scripts: { }.

Versioning

We follow MAJOR.MINOR.PATCH Semantic Versioning

NPM Install Develop branch

You can npm install the develop branch of uport-connect using the follow commands.

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

Frontend Library Specific Fixes

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.

Angular

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.

This will fix a crypto.createHash() undefined error.

"paths": {
  "crypto": ["../node_modules/crypto-browserify/index.js"]
}
Other Frontend Libraries

Are you experiencing other Frontend Library specific issues?

Let us know in the issues.

Contributing

Code, test and documentation contributions are welcomed and encouraged. Please read the guidelines below and reach out on our riot or create an issue 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.

Reporting Bugs

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.

Some guidelines for reporting bugs:

  • Make sure that your issue is caused by uport-connect and not your application code.
  • Create a simple and minimal test case that demonstrates the bug.
  • Search the issues to see if the bug has already been reported. If it has, add any additional details in the comments.
  • Write a descriptive and specific title.
  • Include browser, OS, uport-connect version and any other details specific to the environment.
  • Check whether the bug can be reproduced in other environments (ie. other browsers).
Contributing code

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 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.

All commits are required to be well formed. We follow the AngularJS Commit Message Conventions. We use these commit messages to create a useful history, generate CHANGELOGS and to determine release versions.

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.

Keywords

FAQs

Package last updated on 06 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc