ThreeIdProvider is a JavaScript SDK that allows developers to create and manage 3ID identities on the Ceramic network. It exposes a DID Provider interface which exposes JOSE signing and decryption though a JSON-RPC interface. ThreeIdProvider can be used in combination with js-did.
Install 3id-did-provider in your npm project:
$ npm install 3id-did-provider
Import the 3id-did-provider module
const ThreeIdProvider = require('3id-did-provider')
Import using the dist build in your html code
<script type="text/javascript" src="../dist/threeid-provider.js"></script>
the getPermission
configuration parameter is always required when creating an instance of ThreeIdProvider. It is used to give an application permission to decrypt and sign data. What this function should do is to present a dialog to the user in the wallet UI, asking for permission to access the given paths.
The function is called with one parameter which is the request
object. It looks like this:
{
type: 'authenticate',
origin: 'https://my.app.origin',
payload: {
paths: ['/path/1', '/path/2']
}
}
In the above example the app with origin https://my.app.origin
is requesting access to /path/1
and /path/2
. If the user consents to this the function should just return the paths
array, otherwise an empty array. Note that an array containing only some of the requested paths may also be returned.
To create an instance with an auth method you can pass two params to the create function as shown below. If the auth method doesn't have a 3ID associated with it yet a new 3ID will be created. This means that a seed will be randomly generated in the background. and the given authSecret will be added as an authentication method to the newly created 3ID.
const authSecret = new Uint8Array([ ... ]) // 32 bytes of entropy used to authenticate
const authId = 'myAuthenticationMethod' // a name of the auth method
const ceramic = ... // An instance of Ceramic (either @ceramicnetwork/core, or @ceramicnetwork/http-client)
const threeId = await ThreeIdProvider.create({ getPermission, authSecret, authId, ceramic })
To create a wallet with a seed you can simply pass it as an option to the constructor. This will create an instance of the ThreeIdProvider that derives all it's keys from this seed. Be careful, if this seed is lost the DID and all of it's data will be lost as well. Note that you will get different 3IDs every time the create
method is invoked with the same seed. An authentication method must be used in order to interact with the same 3ID consistently.
const seed = new Uint8Array([ ... ]) // 32 bytes of entropy used as the seed
const ceramic = ... // An instance of Ceramic (either @ceramicnetwork/core, or @ceramicnetwork/http-client)
const threeId = await ThreeIdProvider.create({ getPermission, seed, ceramic })
An instance of the DID provider from ThreeIdProvider can be passed directly to js-did.
import ThreeIdResolver from '@ceramicnetwork/3id-did-resolve'
import Ceramic from '@ceramicnetwork/http-client'
const provider = threeId.getDidProvider()
const resolver = ThreeIdResolver.getResolver(new Ceramic())
const did = new DID({ provider, resolver })