# selfkey-did-ledger

> Smart contracts that implement SelfKey DID Ledger

Latest version **1.0.1** (published 2019-08-26) · 0 weekly downloads

## Install

```sh
npm install selfkey-did-ledger
pnpm add selfkey-did-ledger
yarn add selfkey-did-ledger
bun add selfkey-did-ledger
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-08-26 |
| First published | 2019-05-26 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 34.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Carlos Bruguera |
| Maintainers | cbruguera |
| Keywords | identity, DID, claims, decentralized |

## Links

- npm: https://www.npmjs.com/package/selfkey-did-ledger
- Repository: https://github.com/SelfKeyFoundation/selfkey-did-ledger
- Homepage: https://github.com/SelfKeyFoundation/selfkey-did-ledger#readme
- Issues: https://github.com/SelfKeyFoundation/selfkey-did-ledger/issues
- npm.io page: https://npm.io/package/selfkey-did-ledger

## Dependencies (2)

- [ethereumjs-util](https://npm.io/package/ethereumjs-util.md) ^6.1.0
- [openzeppelin-solidity](https://npm.io/package/openzeppelin-solidity.md) ^2.2.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2019-08-26
- 1.0.0 — 2019-05-26

## README

# selfkey-identity

Implementation of the `DIDLedger` contract that supports the [SelfKey DID method](./DIDMethodSpecs.md).

<!--
* `develop` — [![CircleCI](https://circleci.com/gh/SelfKeyFoundation/selfkey-identity/tree/develop.svg?style=svg)](https://circleci.com/gh/SelfKeyFoundation/selfkey-identity/tree/develop)
* `master` — [![CircleCI](https://circleci.com/gh/SelfKeyFoundation/selfkey-identity/tree/master.svg?style=svg)](https://circleci.com/gh/SelfKeyFoundation/selfkey-identity/tree/master)-->

## Overview

The `DIDLedger` contract works as a _public_ DID ledger for _decentralized identifiers_ as
specified in the [SelfKey DID method](./DIDMethodSpecs.md) 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](./DIDMethodSpecs.md), 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

```javascript
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

```javascript
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

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

#### Resolving a DID to its controller address

```javascript
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:

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

## Development

The smart contracts are being implemented in Solidity `0.5.4`.

### Pre-requisites

* [NodeJS](htps://nodejs.org), version 9.5+
* [truffle](http://truffleframework.com/)
* [Ganache](https://truffleframework.com/ganache)

### 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:

```javascript
{
  "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](http://truffleframework.com).

## Contributing

Please see the [contributing notes](CONTRIBUTING.md).

---
_Source: https://npm.io/package/selfkey-did-ledger · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
