Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs/orbitdb #4

Merged
merged 5 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ dist/

# JSDoc output folder
docs/api/*
!docs/api/README.md
!docs/api/README.md

orbitdb
37 changes: 33 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<img src="https://github.com/orbitdb/orbitdb/blob/main/images/orbit_db_logo_color.png" width="256" />
</p>

[![Matrix](https://img.shields.io/matrix/orbit-db:matrix.org?label=chat%20on%20matrix)](https://app.element.io/#/room/#orbit-db:matrix.org) [![npm version](https://badge.fury.io/js/orbit-db.svg)](https://www.npmjs.com/package/orbit-db-identity-provider-did) [![node](https://img.shields.io/node/v/orbit-db.svg)](https://www.npmjs.com/package/@orbitdb/identity-provider-did)
[![Matrix](https://img.shields.io/matrix/orbit-db:matrix.org?label=chat%20on%20matrix)](https://app.element.io/#/room/#orbit-db:matrix.org) [![npm (scoped)](https://img.shields.io/npm/v/%40orbitdb/identity-provider-did)](https://www.npmjs.com/package/%40orbitdb/identity-provider-did) [![node-current (scoped)](https://img.shields.io/node/v/%40orbitdb/identity-provider-did)](https://www.npmjs.com/package/%40orbitdb/identity-provider-did)

Create and sign OrbitDB identities using a Decentralized IDentifier (DID). See https://www.w3.org/TR/did-core/.

Expand All @@ -18,21 +18,50 @@ npm i @orbitdb/identity-provider-did

## Usage

Use [addIdentityProvider](https://api.orbitdb.org/module-Identities.html#.addIdentityProvider) to make the DID identity provider available to OrbitDB, then pass the `provider` param to [createIdentity](https://api.orbitdb.org/module-Identities-Identities.html#createIdentity) with the DID identity provider function:
Start by registering the OrbitDBIdentityProviderDID identity provider with [useIdentityProvider](https://api.orbitdb.org/module-Identities.html#.useIdentityProvider).

Once registered, you can simply pass in the identity provider when creating an OrbitDB instance:

```js
import { createOrbitDB, useIdentityProvider } from '@orbitdb/core'
import * as OrbitDBIdentityProviderDID from '@orbitdb/identity-provider-did'
import KeyDidResolver from 'key-did-resolver'
import { Ed25519Provider } from 'key-did-provider-ed25519'
import { create } from 'ipfs-core'

const ipfs = await create()

const seed = new Uint8Array(/* some private seed */)

OrbitDBIdentityProviderDID.setDIDResolver(KeyDidResolver.getResolver())
useIdentityProvider(OrbitDBIdentityProviderDID)
const didProvider = new Ed25519Provider(seed)
const provider = OrbitDBIdentityProviderDID({ didProvider })
await createOrbitDB({ ipfs, identity: { provider } })
```

If you require a more custom approach to managing identities, you can create an identity by passing the identity provider to [createIdentity](https://api.orbitdb.org/module-Identities-Identities.html#createIdentity) then use the resulting identity with OrbitDB:

```js
import { createOrbitDB, Identities, useIdentityProvider } from '@orbitdb/core'
import OrbitDBIdentityProviderDID from '@orbitdb/identity-provider-did'
import KeyDidResolver from 'key-did-resolver'
import { Ed25519Provider } from 'key-did-provider-ed25519'
import { create } from 'ipfs-core'
import { Identities, useIdentityProvider } from '@orbitdb/core'

const ipfs = await create()

const seed = new Uint8Array(/* some private seed */)

OrbitDBIdentityProviderDID.setDIDResolver(KeyDidResolver.getResolver())
useIdentityProvider(OrbitDBIdentityProviderDID)

const didProvider = new Ed25519Provider(seed)

const identities = await Identities({ ipfs })
const identity = await identities.createIdentity({ provider: OrbitDBIdentityProviderDID({ didProvider }) }) // you can now use this with your OrbitDB databases.
const identity = await identities.createIdentity({ provider: OrbitDBIdentityProviderDID({ didProvider }) })

await createOrbitDB({ ipfs, identities, identity })
```

## Contributing
Expand Down
Loading