npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

selfkey-did-ledger

v1.0.1

Published

Smart contracts that implement SelfKey DID Ledger

Downloads

8

Readme

selfkey-identity

Implementation of the DIDLedger contract that supports the SelfKey DID method.

Overview

The DIDLedger contract works as a public DID ledger for decentralized identifiers as specified in the SelfKey DID method specs document. Any Ethereum account can generate a DID and manage it through the provided public method interface.

Method interface

  • createDID(bytes32 _metadata): generates a new DID associated with the caller address as the controller. An "optional" _metadata parameter is allowed to be used as information for any resolvers dealing with this method. By default, it's assumed that a 32-byte array with value of zero means that the controller address is a regular Ethereum account.

  • setMetadata(bytes32 id, bytes32 _metadata): a DID controller can change the metadata according to the specific needs of a particular protocol or for personal reasons. The purpose of this field is not strictly defined by the ledger. However, under the SelfKey DID method, a DID resolver must interpret the metadata value as the type of identity in order to resolve it accordingly. For example: if the controller address is an instance of a smart contract (e.g. ERC725), the value to be used as metadata would be keccak256('ERC725'). Other protocols or applications might choose to use this attribute in a different manner.

  • deleteDID(bytes32 id): callable by the controller address. Deletes the DID from the ledger.

  • setController(bytes32 id, address newController): DID controller address can transfer control of the DID specified as id to a different address newController.

  • getController(bytes32 id) returns (address): resolves a DID to its controller address.

Example web3 code

Using web3 v1.0, the following illustrates how to interact with the DIDLedger contract, either from the truffle console or any client-facing app:

Loading the contract

const fs = require('fs')
const ledgerAddress = '0x24512422CF6AD1c0C465cBF0Bbd5155EaA3DA634'
const ledgerABI = JSON.parse(fs.readFileSync('./build/contracts/DIDLedger.json')).abi
const ledger = new web3.eth.Contract(ledgerABI, ledgerAddress)

Creating a DID

const zero = web3.utils.hexToBytes('0x0000000000000000000000000000000000000000000000000000000000000000')
let tx = ledger.methods.createDID(zero).send({ 'from': '0xaf04420C45fc6a063c531C13D9850e4Aa5d951b4' })

If making these tests using the truffle console, the from address should be set to that being loaded from the wallet.json mnemonic key.

Retrieving the DID from the transaction data

let did
tx.then((result) => { did = result.events.CreatedDID.returnValues.id })

Resolving a DID to its controller address

ledger.methods.getController(did).call()

If desired to get more info about a DID (e.g. metadata, creation and update datetimes), the dids mapping should be accessed directly as follows:

ledger.methods.dids(did).call()

Development

The smart contracts are being implemented in Solidity 0.5.4.

Pre-requisites

Initialization

npm install

Setting up a wallet

Truffle configuration file (truffle-config.js) assumes there should be a file local/wallet.json with a list of BIP32 mnemonic words encoding a wallet's private key.

(local directory already added to .gitignore to prevent accidental pushing of private keys to github).

An example wallet.json file should look like this:

{
  "mnemonic":
    "swear tourist road ready scout venture elephant quick pull dress stock trick"
}

Testing

For local testing, open a new terminal window and run ganache-cli, then on the project directory:

npm test

or run tests with code coverage:

npm run test:cov

Note: any running instance of ganache-cli will need to be closed for running the tests with coverage since solidity-coverage runs its own local environment.

To interact with contracts deployed on Ethereum (e.g. Ropsten testnet), open truffle console:

truffle console --network ropsten

Linting

We provide the following linting command for inspecting solidity contracts:

npm run lint:sol

Deploying

Run the following truffle command in order to deploy (e.g. Ropsten testnet)

truffle migrate --network ropsten -f 2

This will run the second migration file, which deploys the DID ledger to the specified network.

Parameters for connecting to each network are specified in the truffle-config.js file.

For info on other Truffle commands, see truffleframework.com.

Contributing

Please see the contributing notes.