# jesse-rif-id-daf

> RIF Identity - DAF

Latest version **0.0.24** (published 2020-09-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install jesse-rif-id-daf
pnpm add jesse-rif-id-daf
yarn add jesse-rif-id-daf
bun add jesse-rif-id-daf
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.24 |
| Published | 2020-09-30 |
| First published | 2020-09-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 705.2 KB |
| Known vulnerabilities | 0 (+31 in 3 direct dependencies) |
| Install scripts | no |
| Maintainers | jessgusclark |
| Keywords | rsk, rif, identity |

## Links

- npm: https://www.npmjs.com/package/jesse-rif-id-daf
- Repository: https://github.com/rsksamrt/rif-identity.js
- Homepage: https://github.com/rsksamrt/rif-identity.js#readme
- Issues: https://github.com/rsksamrt/rif-identity.js/issues
- npm.io page: https://npm.io/package/jesse-rif-id-daf

## Dependencies (9)

- [uuid](https://npm.io/package/uuid.md) ^3.3.3
- [axios](https://npm.io/package/axios.md) ^0.20.0
- [debug](https://npm.io/package/debug.md) ^4.2.0
- [typeorm](https://npm.io/package/typeorm.md) 0.2.24
- [daf-core](https://npm.io/package/daf-core.md) ^6.3.0
- [cross-fetch](https://npm.io/package/cross-fetch.md) ^3.0.6
- [daf-ethr-did](https://npm.io/package/daf-ethr-did.md) ^6.1.2
- [@rsksmart/rif-id-ethr-did](https://npm.io/package/@rsksmart/rif-id-ethr-did.md) 0.0.2
- [@rsksmart/rif-id-mnemonic](https://npm.io/package/@rsksmart/rif-id-mnemonic.md) 0.0.1

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

- 0.0.24 (latest) — 2020-09-30
- 0.0.23 — 2020-09-30
- 0.0.22 — 2020-09-29
- 0.0.21 — 2020-09-29
- 0.0.3 — 2020-09-25
- 0.0.2 — 2020-09-09

## README

<p align="middle">
    <img src="https://www.rifos.org/assets/img/logo.svg" alt="logo" height="100" >
</p>
<h3 align="middle"><code>rif-id-daf</code></h3>
<p align="middle">
    RIF Identity - DAF
</p>
<p align="middle">
    <a href="https://badge.fury.io/js/%40rsksmart%2Frif-id-daf">
        <img src="https://badge.fury.io/js/%40rsksmart%2Frif-id-daf.svg" alt="npm" />
    </a>
</p>

```
npm i @rsksmart/rif-id-daf
```

Extensions for uPort DAF agent.

## Features

### Support for RIF Identity key model

uPort DAF provides an _Identity provider_ module that is responsible for the creation of keys and derivation of the respective identity. Each time an identity is created, a new private key is generated. RIF model proposes to use deterministic derivation for private keys, making all the identities associated with a single mnemonic phrase.

The model uses a wallet account like derivation for identity keys:
1. Create a mnemonic phrase to derive identities from
2. Use BIP32 to derive private keys using `TBD` derivation path

For a better developer experience the extension also provides BIP-44 support. Use mnemonic phrase instead of hex keys.

To use this interface we provide:
1. New ORM Entity: `IdentityMnemonic`. Now used to store one single mnemonic.
2. `SeedStore` class - interface to store a seed
3. `RIFIdKeyManagementSystem` class - wrapper for a `daf` `AbstractKeyManagementSystem` - responsible for creating private keys derived from the mnemonic's seed.
4. `RIFIdentityProvider` class - Extension for `daf` `IdentityProvider` enabling to import a mnemonic

All this modules can be plugged to uPort agent as explained in [usage](#usage) to provide uPort agent of this capabilities.

> The identity recovery model is **to be defined**

## Usage

To setup a DAF agent using RIF identity provider implementation:

```typescript
import { Connection } from 'typeorm'
import { KeyStore, IdentityStore, Agent } from 'daf-core'
import { SecretBox, KeyManagementSystem } from 'daf-libsodium' // change for daf-react-native-libsodioum for React Native support
import { Entities, MnemonicStore, RIFIdKeyManagementSystem, RIFIdentityProvider } from '@rsksamrt/rid-id-daf'

const dbConnection = createConnection({
  type: 'sqlite',
  database: 'rif-identity.sqlite',
  entities: [...Entities, ...DAFEntities],
  logging: false,
  synchronize: true
})

// key store
const secretKey = '0f3c04d7416607ba306997f9fd1920474aff39beb23b847da5c21215076cc9b3' // set your own secret key
const secretBox = new SecretBox(secretKey)
const keyStore = new KeyStore(dbConnection, secretBox)
const mnemonicStore = new MnemonicStore(dbConnection, secretBox)

// key management system
const keyManagementSystem = new KeyManagementSystem(keyStore)
const rifIdKeyManagementSystem = new RIFIdKeyManagementSystem(keyManagementSystem, keyStore, mnemonicStore)

// rif identity provider
const identityStore = new IdentityStore('rsk-testnet-ethr', dbConnection)

const rifIdentityProvider = new RIFIdentityProvider({
    kms: rifIdKeyManagementSystem,
    identityStore,
    network: 'rsk',
    rpcUrl: 'http://localhost:8545'
})

const agent = new Agent({
    dbConnection,
    identityProviders: [rifIdentityProvider],
    didResolver: null
})

const mnemonic = generateMnemonic(12)

await rifIdentityProvider.importMnemonic(mnemonic)

const identity = await agent.identityManager.createIdentity()
```

## Extend

- Enable multiple mnemonics

## Test

From base repo directory run `npm test` or any of the described [test script variants](../../README#test).

## References

- uPort DAF: https://github.com/uport-project/daf

---
_Source: https://npm.io/package/jesse-rif-id-daf · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
