Class: DidRegistry
modules/did-registry.DidRegistry
Service responsible for handling the DID Document management. See more information about DID in IAM stack here.
const { connectToCacheServer } = await initWithPrivateKeySigner(privateKey, rpcUrl);
const { connectToDidRegistry } = await connectToCacheServer();
const { didRegistry } = await connectToDidRegistry();
didRegistry.getDidDocument();
Table of contents
Constructors
Accessors
Methods
- createDocument
- createPublicClaim
- decodeJWTToken
- getDidDelegates
- getDidDocument
- getDidPublicKeys
- getServices
- init
- isClaim
- issuePublicClaim
- revokeDidDocument
- updateDocument
- updateSignedDidDelegate
- updateSignedDidPublicKey
- verifyPublicClaim
- connect
Constructors
constructor
• new DidRegistry(_signerService
, _cacheClient
, _assetsService
, _ipfsConfig
)
Parameters
Name | Type |
---|---|
_signerService |
SignerService |
_cacheClient |
CacheClient |
_assetsService |
AssetsService |
_ipfsConfig |
IpfsConfig |
Accessors
identityOwner
• get
identityOwner(): EwSigner
Returns
EwSigner
ipfsStore
• get
ipfsStore(): DidStore
Returns
DidStore
jwt
• get
jwt(): JWT
Returns
JWT
registrySettings
• get
registrySettings(): RegistrySettings
Returns
RegistrySettings
Methods
createDocument
▸ createDocument(): Promise
<boolean
>
Create DID document of the current user if not exists.
didRegistry.createDocument();
Returns
Promise
<boolean
>
true if document was created successfully
createPublicClaim
▸ createPublicClaim(options
): Promise
<string
>
Create a public claim with provided data.
didRegistry.createPublicClaim({
data: {
claimType: 'root.roles.energyweb.iam.ewc',
claimTypeVersion: 1,
},
subject: 'did:ethr:volta:0x00...0',
});
Parameters
Name | Type | Description |
---|---|---|
options |
CreatePublicClaimOptions |
object with options |
Returns
Promise
<string
>
JWT token of created claim
decodeJWTToken
▸ decodeJWTToken(options
): Promise
<unknown
>
Decode JWT token of the public claim.
didRegistry.decodeJWTToken({
token: 'eyJh...VCJ9.ey...IyfQ.SflK...sw5c',
});
Parameters
Name | Type | Description |
---|---|---|
options |
DecodeJWTTokenOptions |
object with options |
Returns
Promise
<unknown
>
payload of the JWT token
getDidDelegates
▸ getDidDelegates(options?
): Promise
<undefined
| string
[]>
Gets delegates from DID document of the given DID.
didRegistry.getDidDelegates({
did: 'did:ethr:volta:0x00...0',
});
Parameters
Name | Type | Description |
---|---|---|
options |
GetDidDelegatesOptions |
object with options |
Returns
Promise
<undefined
| string
[]>
list of delegates
getDidDocument
▸ getDidDocument(options?
): Promise
<IDIDDocument
>
Retrieve DID Document of the given DID from SSI-Hub if possible, otherwise from blockchain. Optionally include claims object within services in the document.
didRegistry.getDidDocument({
did: 'did:ethr:volta:0x00...0',
includeClaims: true,
});
Parameters
Name | Type | Description |
---|---|---|
options |
GetDIDDocumentOptions |
object with options |
Returns
Promise
<IDIDDocument
>
DID document
getDidPublicKeys
▸ getDidPublicKeys(options?
): Promise
<IPublicKey
[]>
Gets public keys from DID document of the given DID.
didRegistry.getDidPublicKeys({
did: 'did:ethr:volta:0x00...0',
});
Parameters
Name | Type | Description |
---|---|---|
options |
GetDidPublicKeysOptions |
object with options |
Returns
Promise
<IPublicKey
[]>
list of public keys
getServices
▸ getServices(options?
): Promise
<IServiceEndpoint
[]>
Gets services from DID document of the given DID.
didRegistry.getServices({
did: 'did:ethr:volta:0x00...0',
});
Parameters
Name | Type | Description |
---|---|---|
options |
GetServicesOptions |
object with options |
Returns
Promise
<IServiceEndpoint
[]>
list of claims
init
▸ init(): Promise
<void
>
Returns
Promise
<void
>
isClaim
▸ isClaim(claim
): claim is Object
Validate that claim contains issuer and claimData.
didRegistry.isClaim(token: Record<string, string | number | object>);
Parameters
Name | Type |
---|---|
claim |
any |
Returns
claim is Object
boolean
issuePublicClaim
▸ issuePublicClaim(options
): Promise
<string
>
If token provided issue new token signed by issuer, otherwise create a new claim token based on provided public claim data.
didRegistry.issuePublicClaim({
token: 'eyJh...VCJ9.ey...IyfQ.SflK...sw5c',
publicClaim: {
did: 'did:ethr:volta:0x00...0',
signer: 'did:ethr:volta:0x00...1',
claimData: {
claimType: 'root.roles.energyweb.iam.ewc',
},
},
});
Parameters
Name | Type | Description |
---|---|---|
options |
IssuePublicClaimOptions |
object with options |
Returns
Promise
<string
>
JWT token of created claim
revokeDidDocument
▸ revokeDidDocument(): Promise
<boolean
>
Revoke DID document of the current user.
didRegistry.revokeDidDocument();
Returns
Promise
<boolean
>
true if document was revoked successfully
updateDocument
▸ updateDocument(«destructured»
): Promise
<boolean
>
Update DID document of the given DID with provided data.
didRegistry.updateDocument({
didAttribute: DIDAttribute.PublicKey,
data: publicKey,
validity: 60 * 60 * 1000,
did: 'did:ethr:volta:0x00...0',
});
@param {UpdateDocumentOptions} options object with options
@return true if document was updated successfully
#### Parameters
| Name | Type |
| :------ | :------ |
| `«destructured»` | [`UpdateDocumentOptions`](../interfaces/modules_did_registry.UpdateDocumentOptions.md) |
#### Returns
`Promise`<`boolean`\>
___
### updateSignedDidDelegate
▸ **updateSignedDidDelegate**(`«destructured»`): `Promise`<`boolean`\>
Updates delegate of the DID document of given DID.
```typescript
didRegistry.updateSignedDidDelegate({
did: 'did:ethr:volta:0x00...0',
delegatePublicKey: delegatePublicKey,
validity: 60 * 60 * 1000,
algo: KeyType.Secp256k1,
type: PubKeyType.SignatureAuthentication2018,
});
@param {UpdateSignedDidDelegateOptions} options object with options
@return true if document was updated successfully
#### Parameters
| Name | Type |
| :------ | :------ |
| `«destructured»` | [`UpdateSignedDidDelegateOptions`](../interfaces/modules_did_registry.UpdateSignedDidDelegateOptions.md) |
#### Returns
`Promise`<`boolean`\>
___
### updateSignedDidPublicKey
▸ **updateSignedDidPublicKey**(`«destructured»`): `Promise`<`boolean`\>
Adds public key to the DID document of given DID.
```typescript
didRegistry.updateSignedDidPublicKey({
did: 'did:ethr:volta:0x00...0',
publicKey: publicKey,
validity: 60 * 60 * 1000,
algo: KeyType.Secp256k1,
type: PubKeyType.SignatureAuthentication2018,
tag: '#main-key',
});
@param {UpdateSignedDidPublicKeyOptions} options object with options
@return true if document was updated successfully
#### Parameters
| Name | Type |
| :------ | :------ |
| `«destructured»` | [`UpdateSignedDidPublicKeyOptions`](../interfaces/modules_did_registry.UpdateSignedDidPublicKeyOptions.md) |
#### Returns
`Promise`<`boolean`\>
___
### verifyPublicClaim
▸ **verifyPublicClaim**(`token`, `iss`): `Promise`<``null`` \| `string`\>
Verifies issued token of the public claim.
```typescript
didRegistry.verifyPublicClaim({
token: 'eyJh...VCJ9.ey...IyfQ.SflK...sw5c',
iss: 'did:ethr:volta:0x00...0',
});
Parameters
Name | Type | Description |
---|---|---|
token |
string |
JWT token of the public claim |
iss |
string |
DID of the issuer |
Returns
Promise
<null
| string
>
DID of the authenticated identity on successful verification or null otherwise
connect
▸ Static
connect(signerService
, cacheClient
, assetsService
, ipfsConfig
): Promise
<DidRegistry
>
Parameters
Name | Type |
---|---|
signerService |
SignerService |
cacheClient |
CacheClient |
assetsService |
AssetsService |
ipfsConfig |
IpfsConfig |
Returns
Promise
<DidRegistry
>