docs: Move custom identity provider docs to READMEs.

This commit is contained in:
Hayden Young 2023-06-24 15:35:48 +01:00
parent 3af0fc2306
commit 8b17f172fa
2 changed files with 42 additions and 47 deletions

View File

@ -129,3 +129,42 @@ The resulting output is a JSON object containing the identity information:
} }
} }
``` ```
## Custom identity providers
A custom identity provider can be used provided the module takes the following form:
```javascript
// A unique name for the identity provider
const type = 'custom'
// check whether the identity was signed by the identity's id.
const verifyIdentity = identity => {
}
// The identity provider.
const MyCustomIdentityProvider = ({ keystore }) => {
const getId = async ({ id } = {}) => {
}
const signIdentity = async (data, { id } = {}) => {
}
return {
getId,
signIdentity
}
}
export { MyCustomIdentityProvider as default, verifyIdentity, type }
```
To use it, add it to the list of known identity providers:
```javascript
import as MyCustomIdentityProvider from 'my-custom-identity-provider'
addIdentityProvider(MyCustomIdentityProvider)
```
where my-custom-identity-provider is the custom module.

View File

@ -1,57 +1,13 @@
/** /**
* @module IdentityProviders * @module IdentityProviders
* @description * @description
* Identity providers. * Identity providers for signing and verifying an identity using various
* * cryptographic mechanism.
* ## Custom Providers
*
* An identity provider provides a method for signing and verifying an
* identity using a particular cryptographic mechanism.
*
* A custom identity provider can be used provided the module takes the
* following form:
* ```javascript
* // A unique name for the identity provider
* const type = 'custom'
*
* // check whether the identity was signed by the identity's id.
* const verifyIdentity = identity => {
*
* }
*
* // The identity provider.
* const MyCustomIdentityProvider = ({ keystore }) => {
* const getId = async ({ id } = {}) => {
*
* }
*
* const signIdentity = async (data, { id } = {}) => {
*
* }
*
* return {
* getId,
* signIdentity
* }
* }
*
* export { MyCustomIdentityProvider as default, verifyIdentity, type }
* ```
*
* To use it, add it to the list of known identity providers:
* ```javascript
* import * as MyCustomIdentityProvider from 'my-custom-identity-provider'
* addIdentityProvider(MyCustomIdentityProvider)
* ```
*
* where my-custom-identity-provider is the custom module.
*/ */
import * as PublicKeyIdentityProvider from './publickey.js' import * as PublicKeyIdentityProvider from './publickey.js'
const identityProviders = { const identityProviders = {
publickey: PublicKeyIdentityProvider publickey: PublicKeyIdentityProvider
// [DIDIdentityProvider.type]: DIDIdentityProvider,
// [EthIdentityProvider.type]: EthIdentityProvider
} }
/** /**