decentralized-identity / Element

Licence: apache-2.0
DID Method implementation using the Sidetree protocol on top of Ethereum and IPFS

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Element

The Journal Of Blockchain
区块链自媒体、专注区块链技术学习和实践、IPFS/Filecoin、Bitcoin、Ethereum、EOS、Cosmos、区块链、白皮书、Coinmarketcap、Coindesk、Safe Network、Telegram、Docker、社会治理、经济激励
Stars: ✭ 63 (-21.25%)
Mutual labels:  ethereum, dapp, ipfs, crypto
Gun
An open source cybersecurity protocol for syncing decentralized graph data.
Stars: ✭ 15,172 (+18865%)
Mutual labels:  dapp, protocol, crypto
Unstoppable Wallet Ios
A secure and decentralized Bitcoin and other cryptocurrency wallet for iPhone. Supports Bitcoin, Ethereum, EOS, Binance Chain, Bitcoin Cash, DASH, ...
Stars: ✭ 180 (+125%)
Mutual labels:  ethereum, dapp, ipfs
Unstoppable Wallet Android
A secure and decentralized Bitcoin and other cryptocurrency wallet for Android phones. Supports Bitcoin, Ethereum, EOS, Binance Chain, Bitcoin Cash, DASH, ...
Stars: ✭ 165 (+106.25%)
Mutual labels:  ethereum, dapp, ipfs
Graph Node
Graph Node indexes data from blockchains such as Ethereum and serves it over GraphQL
Stars: ✭ 884 (+1005%)
Mutual labels:  ethereum, protocol, ipfs
Eth Dev Reading List
A list of links to articles, tutorials and papers that are helpful for people developing on the ethereum stack
Stars: ✭ 280 (+250%)
Mutual labels:  ethereum, dapp, ipfs
Awesome Web3
🚀 A curated list of tools, libs and resources to help you build awesome dapps
Stars: ✭ 104 (+30%)
Mutual labels:  ethereum, dapp, ipfs
Web3swift
Elegant Web3js functionality in Swift. Native ABI parsing and smart contract interactions.
Stars: ✭ 237 (+196.25%)
Mutual labels:  ethereum, dapp, crypto
Celo Monorepo
Official repository for core projects comprising the Celo platform
Stars: ✭ 269 (+236.25%)
Mutual labels:  ethereum, dapp, crypto
Embark
Framework for serverless Decentralized Applications using Ethereum, IPFS and other platforms
Stars: ✭ 3,478 (+4247.5%)
Mutual labels:  ethereum, dapp, ipfs
Dapp
TypeScript React Redux Ethereum IPFS Starter Kit
Stars: ✭ 33 (-58.75%)
Mutual labels:  ethereum, dapp, ipfs
Cryptex
Gemini, GDAX, Bitfinex, Poloniex, Binance, Kraken, Cryptopia, Koinex, BitGrail and CoinMarketCap cryptocurrency exchange API clients in Swift / iOS SDK. Check prices and account balances using Sample iOS app.
Stars: ✭ 51 (-36.25%)
Mutual labels:  ethereum, crypto
Trace
Supply chain transparency platform proof-of-concept based on the Ethereum blockchain ✍️
Stars: ✭ 52 (-35%)
Mutual labels:  ethereum, dapp
Nfte
A universal way of embedding NFTs in your website or app, works with any ERC-721 contract. Bringing The Metaverse to Web2.
Stars: ✭ 75 (-6.25%)
Mutual labels:  ethereum, crypto
Protocol
⛓ Dev Protocol is an open source middleware for creator's sustainability.
Stars: ✭ 56 (-30%)
Mutual labels:  ethereum, protocol
Ethereumbook
Mastering Ethereum, by Andreas M. Antonopoulos, Gavin Wood
Stars: ✭ 11,663 (+14478.75%)
Mutual labels:  ethereum, dapp
Cryptocurrency Dashboard
Crypto Currency Dashboard Using Twitter 🐦 And Coinmarketcap 🚀 API
Stars: ✭ 54 (-32.5%)
Mutual labels:  ethereum, crypto
Subspace
Library for Reactive Dapp Development with auto syncing and caching capabilities
Stars: ✭ 57 (-28.75%)
Mutual labels:  ethereum, dapp
Connect
(Aragon 1) Seamlessly integrate DAO functionality into web and node.js apps.
Stars: ✭ 81 (+1.25%)
Mutual labels:  ethereum, dapp
Web3e
Web3E Ethereum for Embedded devices running Arduino framework
Stars: ✭ 50 (-37.5%)
Mutual labels:  ethereum, dapp

See sidetree.js

This repo is no longer maintained.

Element

Build Status codecov

🔥 Experimental Sidetree Protocol based DID Method elem with Ethereum and IPFS

See the DID method specification

See our blog post

[OUTDATED] Click below image for demo video.

Element Testnet Demo

See also ion, sidetree, sidetree-ethereum.

Useful resources

Getting Started

git clone [email protected]:decentralized-identity/element.git
cd element
npm install

Element follows the Mono Repo structure. Running npm install will install dependencies in the top level npm project as well as in the following packages:

  • Element LIB: Javascript SDK for using Element. Works with node 10, node 12 and in the browser
  • Element APP: Progressive Web App to create a wallet, create a DID, add and remove keys, search through the Element Block explorer, etc... The PWA allows you to use two different types of Sidetree nodes:
    • The light node (or browser node) which uses element-lib in the browser for Sidetree operations and interacts with Ethereum through Metamask Make sure you have the Metamask browser extension installed if you want to use it the light node.
    • The full node which uses element-api for Sidetree operations
  • Element API: API powered by element-lib that exposes Sidetree operations with an HTTP interface. See Swagger documentation for more details.

How to use element-lib

cd packages/element-lib

Running the tests

In order to run the tests, you need to start Element services

npm run services:start

This will start 3 services:

  • Ganache: A local Ethereum chain initialized with the Element smart contract running with on port 8545
  • IPFS: A local IPFS node running on port 5001
  • CouchDB: A local CouchDB instance running on port 5984. CouchDB will be ran in the Docker container, so you will need Docker installed. If you don't have it and / or don't want to install it, it is fine. Just be aware that the CouchDB tests will fail

Check that services are properly initalized with

npm run services:healthcheck

Then you can run the tests (note that running this command will initialize the services if they have not been initialized)

npm test

When you are done, you can stop the Element services by running

npm run services:stop

Initializing the Sidetree class

In order to use element-lib in node or in the browser, you will need to initalize the Sidetree class by providing three interfaces:

  • A db interface: this is where all the caching artifacts will be stored. While caching is not technically required for Element to work, CRUD operations will be prohibitively slow without it. To initialize, chose one db adapter (several options are available here):

    • RXDB
    • CouchDB
    • Firestore: A good option if you're going to use Element in a Firebase Cloud Function, pretty slow otherwise. Also note that this technology is proprietary as opposed to the two above which are open source..
  • A storage interface: the Content Addressed Storage layer where Sidetree operation data will be stored. To initialize, chose one storage adapter (several options are available here):

    • IPFS
    • IPFS Storage Manager: A layer on top of IPFS that uses a cache and some retry logic when the call to IPFS fails: This one is recommended for production use as the IPFS link provided by Infura tend to fail intermittently
  • A blockchain interface: An interface for the decentralized ledger to be used for anchoring Sidetree operations. Element may only be used with the Ethereum interface, however feel free to reuse this codebase to implement a did method that uses a different ledger.

  • A parameter object. Currently the supported parameters are:

    • maxOperationsPerBatch: recommended value is 10000,
    • batchingIntervalInSeconds: recommended value is 10,
    • didMethodName: recommended value is did:elem:ropsten for Element testnet
    • logLevel: one of [ error, warn, info, http, verbose, debug, silly ]. error would log all the logs, while silly would only capture the most unimportant ones

See several examples for how to initialize the Sidetree class:

Using element-lib to Create Read Update Delete DIDs

Once you have an instance of the Sidetree class with the suitable adapters, you can access all the helper functions (sidetree.func) and perform CRUD operations (sidetree.op). Here are a few code snippet to get you started:

Create a DID

const { Sidetree, MnemonicKeySystem } = require("@transmute/element-lib");

// Instantiate the Sidetree class
const element = new Sidetree(/* See previous section for how to initialize the Sidetree class*/);

// Generate a simple did document model
const mks = new MnemonicKeySystem(MnemonicKeySystem.generateMnemonic());
const primaryKey = await mks.getKeyForPurpose("primary", 0);
const recoveryKey = await mks.getKeyForPurpose("recovery", 0);
const didDocumentModel = element.op.getDidDocumentModel(
  primaryKey.publicKey,
  recoveryKey.publicKey
);

// Generate Sidetree Create payload
const createPayload = element.op.getCreatePayload(didDocumentModel, primaryKey);

// Create the Sidetree transaction.
// This can potentially take a few minutes if you're not on a local network
const createTransaction = await element.batchScheduler.writeNow(createPayload);
const didUniqueSuffix = element.func.getDidUniqueSuffix(createPayload);
const did = `did:elem:ropsten:${didUniqueSuffix}`;
console.log(`${did} was successfully created`);

Read a DID (aka resolve a DID)

const didDocument = await element.resolve(didUniqueSuffix, true);
console.log(
  `${did} was successfully resolved into ${JSON.stringify(
    didDocument,
    null,
    2
  )}`
);

Update a DID document

Add a new key to the did document

// Get last operation data
const operations = await element.db.readCollection(didUniqueSuffix);
const lastOperation = operations.pop();

// Generate update payload for adding a new key
const newKey = await mks.getKeyForPurpose("primary", 1);
const newPublicKey = {
  id: "#newKey",
  usage: "signing",
  type: "Secp256k1VerificationKey2018",
  publicKeyHex: newKey.publicKey,
};
const updatePayload = await element.op.getUpdatePayloadForAddingAKey(
  lastOperation,
  newPublicKey,
  primaryKey.privateKey
);

// Create the Sidetree transaction.
const updateTransaction = await element.batchScheduler.writeNow(updatePayload);
const newDidDocument = await element.resolve(didUniqueSuffix, true);
console.log(`${JSON.stringify(newDidDocument, null, 2)} has a new publicKey`);

Recover a did document

How to recover a did document using the recovery key if the private key is lost:

// Generate a recovery payload with the inital did document model
const recoveryPayload = await element.op.getRecoverPayload(
  didUniqueSuffix,
  didDocumentModel,
  recoveryKey.privateKey
);

// Send Sidetree transaction
const recoveryTransaction = await element.batchScheduler.writeNow(
  recoveryPayload
);
const recoveredDidDocument = await element.resolve(didUniqueSuffix, true);
console.log(`${JSON.stringify(recoveredDidDocument, null, 2)} was recovered`);

Delete a did document

// Generate a delete payload this will brick the did forever
const deletePayload = await element.op.getDeletePayload(
  didUniqueSuffix,
  recoveryKey.privateKey
);

// Send Sidetree transaction
const deleteTransaction = await element.batchScheduler.writeNow(deletePayload);
const deletedDidDocument = await element.resolve(didUniqueSuffix, true);
console.log(`${JSON.stringify(deletedDidDocument, null, 2)} was deleted`);

How to use element-api

Define the environment file

In the root level directory copy the example config

cp example.env .env

then fill the following values:

  • ELEMENT_MNEMONIC: a mnemonic funded with ethereum. See step 1 and 2 of this tutorial
  • ELEMENT_PROVIDER: either http://localhost:8545 for connecting with local ganache network or use an Infura URL that should look like this https://ropsten.infura.io/v3/<API_TOKEN>
  • ELEMENT_IPFS_MULTIADDR: either /ip4/127.0.0.1/tcp/5001 for connecting with local IPFS node or /dns4/ipfs.infura.io/tcp/5001/https for connecting through Infura
  • ELEMENT_CONTRACT_ADDRESS: "0xD49Da2b7C0A15f6ac5A856f026D68A9B9848D96f"
  • ELEMENT_COUCHDB_REMOTE: Only use this if you want to you the replication feature of CouchDB

Then run the following create the api config file

cd packages/element-api
npm run env:create:prod

You may now start the API by running

npm run start # if you have setup a firebase project
npm run start:standalone # to run the standalone express version of the API

How to use element-app

All config is checked into source so you can run the app by:

npm run start

Useful commands

Install:

npm i

Run smart contract tests:

npm run test:contracts

Run lib, api and app tests:

npm run test

Lint

npm run lint

Coverage

npm run coverage

Publishing

If you have 2fa enabled for npm (and you should!).

lerna version patch
NPM_CONFIG_OTP=123456 lerna publish

Testing Documentation

npm i -g http-server
serve ./docs

See .travis.yml for setup and test commands for linux.

Docker

To run the APP in docker, run

docker run --rm -p 80:80 gjgd/element-app:latest

To run the API in docker, run

docker run --rm -p 80:5002 gjgd/element-api:latest

How to build Element APP with a different domain for the API:

  1. Clone Element
  2. cd packages/element-app
  3. edit the content of .env.production to the API_URL you want to use
  4. docker build -t my-tag .
  5. docker run --rm -p 80:5002 my-tag
  6. Now the app runs on port 80 and will use the API_URL specified in 3)

Release process

lerna publish
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].