diff --git a/docs/api/classes/modules_did_registry.DidRegistry.md b/docs/api/classes/modules_did_registry.DidRegistry.md index 4b21eba8..39e98177 100644 --- a/docs/api/classes/modules_did_registry.DidRegistry.md +++ b/docs/api/classes/modules_did_registry.DidRegistry.md @@ -2,6 +2,16 @@ [modules/did-registry](../modules/modules_did_registry.md).DidRegistry +Service responsible for handling the DID Document management. +See more information about DID in IAM stack [here](https://energy-web-foundation.gitbook.io/energy-web/foundational-concepts/self-sovereign-identity#decentralized-identifiers-dids). + +```typescript +const { connectToCacheServer } = await initWithPrivateKeySigner(privateKey, rpcUrl); +const { connectToDidRegistry } = await connectToCacheServer(); +const { didRegistry } = await connectToDidRegistry(); +didRegistry.getDidDocument(); +``` + ## Table of contents ### Constructors @@ -72,29 +82,41 @@ ___ ▸ **createDocument**(): `Promise`<`boolean`\> -**`description`** create did document if not exists +Create DID document of the current user if not exists. + +```typescript +didRegistry.createDocument(); +``` #### Returns `Promise`<`boolean`\> -true if document is created successfully +true if document was created successfully ___ ### createPublicClaim -▸ **createPublicClaim**(`__namedParameters`): `Promise`<`string`\> +▸ **createPublicClaim**(`options`): `Promise`<`string`\> + +Create a public claim with provided data. -**`description`** create a public claim based on data provided +```typescript +didRegistry.createPublicClaim({ + data: { + claimType: 'root.roles.energyweb.iam.ewc', + claimTypeVersion: 1, + }, + subject: 'did:ethr:volta:0x00...0', +}); +``` #### Parameters -| Name | Type | -| :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.data` | [`ClaimData`](../interfaces/modules_did_registry.ClaimData.md) | -| `__namedParameters.subject?` | `string` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `options` | [`CreatePublicClaimOptions`](../interfaces/modules_did_registry.CreatePublicClaimOptions.md) | object with options | #### Returns @@ -106,68 +128,101 @@ ___ ### decodeJWTToken -▸ **decodeJWTToken**(`__namedParameters`): `Promise`<`unknown`\> +▸ **decodeJWTToken**(`options`): `Promise`<`unknown`\> + +Decode JWT token of the public claim. + +```typescript +didRegistry.decodeJWTToken({ + token: 'eyJh...VCJ9.ey...IyfQ.SflK...sw5c', +}); +``` #### Parameters -| Name | Type | -| :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.token` | `string` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `options` | [`DecodeJWTTokenOptions`](../interfaces/modules_did_registry.DecodeJWTTokenOptions.md) | object with options | #### Returns `Promise`<`unknown`\> +payload of the JWT token + ___ ### getDidDelegates -▸ **getDidDelegates**(`__namedParameters`): `Promise`<`undefined` \| `string`[]\> +▸ **getDidDelegates**(`options?`): `Promise`<`undefined` \| `string`[]\> + +Gets delegates from DID document of the given DID. -**`description`** get public keys from DID's document +```typescript +didRegistry.getDidDelegates({ + did: 'did:ethr:volta:0x00...0', +}); +``` #### Parameters -| Name | Type | -| :------ | :------ | -| `__namedParameters` | `Object` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `options` | [`GetDidDelegatesOptions`](../interfaces/modules_did_registry.GetDidDelegatesOptions.md) | object with options | #### Returns `Promise`<`undefined` \| `string`[]\> -list of DID's delegates +list of delegates ___ ### getDidDocument -▸ **getDidDocument**(`__namedParameters?`): `Promise`<{ `service`: `IServiceEndpoint` & [`ClaimData`](../interfaces/modules_did_registry.ClaimData.md)[] }\> +▸ **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. + +```typescript +didRegistry.getDidDocument({ + did: 'did:ethr:volta:0x00...0', + includeClaims: true, +}); +``` #### Parameters -| Name | Type | -| :------ | :------ | -| `__namedParameters` | `undefined` \| { `did?`: `string` ; `includeClaims?`: `boolean` } | +| Name | Type | Description | +| :------ | :------ | :------ | +| `options` | [`GetDIDDocumentOptions`](../interfaces/modules_did_registry.GetDIDDocumentOptions.md) | object with options | #### Returns -`Promise`<{ `service`: `IServiceEndpoint` & [`ClaimData`](../interfaces/modules_did_registry.ClaimData.md)[] }\> +`Promise`<`IDIDDocument`\> + +DID document ___ ### getDidPublicKeys -▸ **getDidPublicKeys**(`__namedParameters`): `Promise`<`IPublicKey`[]\> +▸ **getDidPublicKeys**(`options?`): `Promise`<`IPublicKey`[]\> + +Gets public keys from DID document of the given DID. -**`description`** get public keys from User's DID document +```typescript +didRegistry.getDidPublicKeys({ + did: 'did:ethr:volta:0x00...0', +}); +``` #### Parameters -| Name | Type | -| :------ | :------ | -| `__namedParameters` | `Object` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `options` | [`GetDidPublicKeysOptions`](../interfaces/modules_did_registry.GetDidPublicKeysOptions.md) | object with options | #### Returns @@ -179,19 +234,25 @@ ___ ### getServices -▸ **getServices**(`__namedParameters?`): `Promise`<`IServiceEndpoint` & [`ClaimData`](../interfaces/modules_did_registry.ClaimData.md)[]\> +▸ **getServices**(`options?`): `Promise`<`IServiceEndpoint`[]\> + +Gets services from DID document of the given DID. -**`description`** gets list of services endpoints from User's DID document +```typescript +didRegistry.getServices({ + did: 'did:ethr:volta:0x00...0', +}); +``` #### Parameters -| Name | Type | -| :------ | :------ | -| `__namedParameters` | `undefined` \| { `did?`: `string` } | +| Name | Type | Description | +| :------ | :------ | :------ | +| `options` | [`GetServicesOptions`](../interfaces/modules_did_registry.GetServicesOptions.md) | object with options | #### Returns -`Promise`<`IServiceEndpoint` & [`ClaimData`](../interfaces/modules_did_registry.ClaimData.md)[]\> +`Promise`<`IServiceEndpoint`[]\> list of claims @@ -209,23 +270,35 @@ ___ ### issuePublicClaim -▸ **issuePublicClaim**(`__namedParameters`): `Promise`<`string`\> +▸ **issuePublicClaim**(`options`): `Promise`<`string`\> -**`description`** issue a public claim +If token provided issue new token signed by issuer, +otherwise create a new claim token based on provided public claim data. + +```typescript +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 | -| :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.publicClaim?` | `IPublicClaim` | -| `__namedParameters.token?` | `string` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `options` | [`IssuePublicClaimOptions`](../interfaces/modules_did_registry.IssuePublicClaimOptions.md) | object with options | #### Returns `Promise`<`string`\> -return issued token +JWT token of created claim ___ @@ -233,109 +306,135 @@ ___ ▸ **revokeDidDocument**(): `Promise`<`boolean`\> -**`description`** revokes did document +Revoke DID document of the current user. + +```typescript +didRegistry.revokeDidDocument(); +``` #### Returns `Promise`<`boolean`\> -information (true/false) if the DID document was revoked +true if document was revoked successfully ___ ### updateDocument -▸ **updateDocument**(`options`): `Promise`<`boolean`\> +▸ **updateDocument**(`__namedParameters`): `Promise`<`boolean`\> + +Update DID document of the given DID with provided data. -**`description`** updates did document based on data provided +```typescript +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 | Description | -| :------ | :------ | :------ | -| `options` | `Object` | Options to connect with blockchain | -| `options.data` | `IUpdateData` | New attribute value | -| `options.did?` | `string` | Asset did to be updated | -| `options.didAttribute` | `DIDAttribute` | Type of document to be updated | -| `options.validity?` | `number` | Time (s) for the attribute to expire | +| Name | Type | +| :------ | :------ | +| `__namedParameters` | [`UpdateDocumentOptions`](../interfaces/modules_did_registry.UpdateDocumentOptions.md) | #### Returns `Promise`<`boolean`\> -true if document is updated successfuly - ___ ### updateSignedDidDelegate ▸ **updateSignedDidDelegate**(`__namedParameters`): `Promise`<`boolean`\> -**`description`** updates delegate of the document of controlled `did` +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 | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.algo` | `KeyType` | -| `__namedParameters.delegatePublicKey` | `string` | -| `__namedParameters.did` | `string` | -| `__namedParameters.type` | `PubKeyType` | -| `__namedParameters.validity?` | `number` | +| `__namedParameters` | [`UpdateSignedDidDelegateOptions`](../interfaces/modules_did_registry.UpdateSignedDidDelegateOptions.md) | #### Returns `Promise`<`boolean`\> -true if document is updated successfuly - ___ ### updateSignedDidPublicKey ▸ **updateSignedDidPublicKey**(`__namedParameters`): `Promise`<`boolean`\> -**`description`** Adds public key to the document of controlled `did` +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 | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.algo` | `KeyType` | -| `__namedParameters.did` | `string` | -| `__namedParameters.publicKey` | `string` | -| `__namedParameters.tag` | `string` | -| `__namedParameters.type` | `PubKeyType` | -| `__namedParameters.validity?` | `number` | +| `__namedParameters` | [`UpdateSignedDidPublicKeyOptions`](../interfaces/modules_did_registry.UpdateSignedDidPublicKeyOptions.md) | #### Returns `Promise`<`boolean`\> -true if document is updated successfuly - ___ ### verifyPublicClaim ▸ **verifyPublicClaim**(`token`, `iss`): `Promise`<``null`` \| `string`\> -**`description`** verifies issued token of claim +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 | -| :------ | :------ | -| `token` | `string` | -| `iss` | `string` | +| Name | Type | Description | +| :------ | :------ | :------ | +| `token` | `string` | JWT token of the public claim | +| `iss` | `string` | DID of the issuer | #### Returns `Promise`<``null`` \| `string`\> -public claim data +DID of the authenticated identity on successful verification or null otherwise ___ diff --git a/docs/api/interfaces/modules_did_registry.CreatePublicClaimOptions.md b/docs/api/interfaces/modules_did_registry.CreatePublicClaimOptions.md new file mode 100644 index 00000000..6d042e90 --- /dev/null +++ b/docs/api/interfaces/modules_did_registry.CreatePublicClaimOptions.md @@ -0,0 +1,22 @@ +# Interface: CreatePublicClaimOptions + +[modules/did-registry](../modules/modules_did_registry.md).CreatePublicClaimOptions + +## Table of contents + +### Properties + +- [data](modules_did_registry.CreatePublicClaimOptions.md#data) +- [subject](modules_did_registry.CreatePublicClaimOptions.md#subject) + +## Properties + +### data + +• **data**: [`ClaimData`](modules_did_registry.ClaimData.md) + +___ + +### subject + +• `Optional` **subject**: `string` diff --git a/docs/api/interfaces/modules_did_registry.DecodeJWTTokenOptions.md b/docs/api/interfaces/modules_did_registry.DecodeJWTTokenOptions.md new file mode 100644 index 00000000..74a0a290 --- /dev/null +++ b/docs/api/interfaces/modules_did_registry.DecodeJWTTokenOptions.md @@ -0,0 +1,15 @@ +# Interface: DecodeJWTTokenOptions + +[modules/did-registry](../modules/modules_did_registry.md).DecodeJWTTokenOptions + +## Table of contents + +### Properties + +- [token](modules_did_registry.DecodeJWTTokenOptions.md#token) + +## Properties + +### token + +• **token**: `string` diff --git a/docs/api/interfaces/modules_did_registry.DownloadClaimsOptions.md b/docs/api/interfaces/modules_did_registry.DownloadClaimsOptions.md new file mode 100644 index 00000000..6bc5dd29 --- /dev/null +++ b/docs/api/interfaces/modules_did_registry.DownloadClaimsOptions.md @@ -0,0 +1,15 @@ +# Interface: DownloadClaimsOptions + +[modules/did-registry](../modules/modules_did_registry.md).DownloadClaimsOptions + +## Table of contents + +### Properties + +- [services](modules_did_registry.DownloadClaimsOptions.md#services) + +## Properties + +### services + +• **services**: `IServiceEndpoint`[] diff --git a/docs/api/interfaces/modules_did_registry.GetDIDDocumentOptions.md b/docs/api/interfaces/modules_did_registry.GetDIDDocumentOptions.md new file mode 100644 index 00000000..7f083a18 --- /dev/null +++ b/docs/api/interfaces/modules_did_registry.GetDIDDocumentOptions.md @@ -0,0 +1,22 @@ +# Interface: GetDIDDocumentOptions + +[modules/did-registry](../modules/modules_did_registry.md).GetDIDDocumentOptions + +## Table of contents + +### Properties + +- [did](modules_did_registry.GetDIDDocumentOptions.md#did) +- [includeClaims](modules_did_registry.GetDIDDocumentOptions.md#includeclaims) + +## Properties + +### did + +• **did**: `string` + +___ + +### includeClaims + +• `Optional` **includeClaims**: `boolean` diff --git a/docs/api/interfaces/modules_did_registry.GetDidDelegatesOptions.md b/docs/api/interfaces/modules_did_registry.GetDidDelegatesOptions.md new file mode 100644 index 00000000..d8ff8c84 --- /dev/null +++ b/docs/api/interfaces/modules_did_registry.GetDidDelegatesOptions.md @@ -0,0 +1,15 @@ +# Interface: GetDidDelegatesOptions + +[modules/did-registry](../modules/modules_did_registry.md).GetDidDelegatesOptions + +## Table of contents + +### Properties + +- [did](modules_did_registry.GetDidDelegatesOptions.md#did) + +## Properties + +### did + +• **did**: `string` diff --git a/docs/api/interfaces/modules_did_registry.GetDidPublicKeysOptions.md b/docs/api/interfaces/modules_did_registry.GetDidPublicKeysOptions.md new file mode 100644 index 00000000..be98c0a1 --- /dev/null +++ b/docs/api/interfaces/modules_did_registry.GetDidPublicKeysOptions.md @@ -0,0 +1,15 @@ +# Interface: GetDidPublicKeysOptions + +[modules/did-registry](../modules/modules_did_registry.md).GetDidPublicKeysOptions + +## Table of contents + +### Properties + +- [did](modules_did_registry.GetDidPublicKeysOptions.md#did) + +## Properties + +### did + +• **did**: `string` diff --git a/docs/api/interfaces/modules_did_registry.GetServicesOptions.md b/docs/api/interfaces/modules_did_registry.GetServicesOptions.md new file mode 100644 index 00000000..097d6ecb --- /dev/null +++ b/docs/api/interfaces/modules_did_registry.GetServicesOptions.md @@ -0,0 +1,15 @@ +# Interface: GetServicesOptions + +[modules/did-registry](../modules/modules_did_registry.md).GetServicesOptions + +## Table of contents + +### Properties + +- [did](modules_did_registry.GetServicesOptions.md#did) + +## Properties + +### did + +• **did**: `string` diff --git a/docs/api/interfaces/modules_did_registry.IssuePublicClaimOptions.md b/docs/api/interfaces/modules_did_registry.IssuePublicClaimOptions.md new file mode 100644 index 00000000..f26f5353 --- /dev/null +++ b/docs/api/interfaces/modules_did_registry.IssuePublicClaimOptions.md @@ -0,0 +1,22 @@ +# Interface: IssuePublicClaimOptions + +[modules/did-registry](../modules/modules_did_registry.md).IssuePublicClaimOptions + +## Table of contents + +### Properties + +- [publicClaim](modules_did_registry.IssuePublicClaimOptions.md#publicclaim) +- [token](modules_did_registry.IssuePublicClaimOptions.md#token) + +## Properties + +### publicClaim + +• `Optional` **publicClaim**: `IPublicClaim` + +___ + +### token + +• `Optional` **token**: `string` diff --git a/docs/api/interfaces/modules_did_registry.UpdateDocumentOptions.md b/docs/api/interfaces/modules_did_registry.UpdateDocumentOptions.md new file mode 100644 index 00000000..3b3fab07 --- /dev/null +++ b/docs/api/interfaces/modules_did_registry.UpdateDocumentOptions.md @@ -0,0 +1,36 @@ +# Interface: UpdateDocumentOptions + +[modules/did-registry](../modules/modules_did_registry.md).UpdateDocumentOptions + +## Table of contents + +### Properties + +- [data](modules_did_registry.UpdateDocumentOptions.md#data) +- [did](modules_did_registry.UpdateDocumentOptions.md#did) +- [didAttribute](modules_did_registry.UpdateDocumentOptions.md#didattribute) +- [validity](modules_did_registry.UpdateDocumentOptions.md#validity) + +## Properties + +### data + +• **data**: `IUpdateData` + +___ + +### did + +• `Optional` **did**: `string` + +___ + +### didAttribute + +• **didAttribute**: `DIDAttribute` + +___ + +### validity + +• `Optional` **validity**: `number` diff --git a/docs/api/interfaces/modules_did_registry.UpdateSignedDidDelegateOptions.md b/docs/api/interfaces/modules_did_registry.UpdateSignedDidDelegateOptions.md new file mode 100644 index 00000000..8dc8c409 --- /dev/null +++ b/docs/api/interfaces/modules_did_registry.UpdateSignedDidDelegateOptions.md @@ -0,0 +1,43 @@ +# Interface: UpdateSignedDidDelegateOptions + +[modules/did-registry](../modules/modules_did_registry.md).UpdateSignedDidDelegateOptions + +## Table of contents + +### Properties + +- [algo](modules_did_registry.UpdateSignedDidDelegateOptions.md#algo) +- [delegatePublicKey](modules_did_registry.UpdateSignedDidDelegateOptions.md#delegatepublickey) +- [did](modules_did_registry.UpdateSignedDidDelegateOptions.md#did) +- [type](modules_did_registry.UpdateSignedDidDelegateOptions.md#type) +- [validity](modules_did_registry.UpdateSignedDidDelegateOptions.md#validity) + +## Properties + +### algo + +• **algo**: `KeyType` + +___ + +### delegatePublicKey + +• **delegatePublicKey**: `string` + +___ + +### did + +• **did**: `string` + +___ + +### type + +• **type**: `PubKeyType` + +___ + +### validity + +• `Optional` **validity**: `number` diff --git a/docs/api/interfaces/modules_did_registry.UpdateSignedDidPublicKeyOptions.md b/docs/api/interfaces/modules_did_registry.UpdateSignedDidPublicKeyOptions.md new file mode 100644 index 00000000..2c5e7409 --- /dev/null +++ b/docs/api/interfaces/modules_did_registry.UpdateSignedDidPublicKeyOptions.md @@ -0,0 +1,50 @@ +# Interface: UpdateSignedDidPublicKeyOptions + +[modules/did-registry](../modules/modules_did_registry.md).UpdateSignedDidPublicKeyOptions + +## Table of contents + +### Properties + +- [algo](modules_did_registry.UpdateSignedDidPublicKeyOptions.md#algo) +- [did](modules_did_registry.UpdateSignedDidPublicKeyOptions.md#did) +- [publicKey](modules_did_registry.UpdateSignedDidPublicKeyOptions.md#publickey) +- [tag](modules_did_registry.UpdateSignedDidPublicKeyOptions.md#tag) +- [type](modules_did_registry.UpdateSignedDidPublicKeyOptions.md#type) +- [validity](modules_did_registry.UpdateSignedDidPublicKeyOptions.md#validity) + +## Properties + +### algo + +• **algo**: `KeyType` + +___ + +### did + +• **did**: `string` + +___ + +### publicKey + +• **publicKey**: `string` + +___ + +### tag + +• **tag**: `string` + +___ + +### type + +• **type**: `PubKeyType` + +___ + +### validity + +• `Optional` **validity**: `number` diff --git a/docs/api/interfaces/modules_did_registry.ValidDateUpdateDocumentRequestOptions.md b/docs/api/interfaces/modules_did_registry.ValidDateUpdateDocumentRequestOptions.md new file mode 100644 index 00000000..c1d81d65 --- /dev/null +++ b/docs/api/interfaces/modules_did_registry.ValidDateUpdateDocumentRequestOptions.md @@ -0,0 +1,29 @@ +# Interface: ValidDateUpdateDocumentRequestOptions + +[modules/did-registry](../modules/modules_did_registry.md).ValidDateUpdateDocumentRequestOptions + +## Table of contents + +### Properties + +- [data](modules_did_registry.ValidDateUpdateDocumentRequestOptions.md#data) +- [did](modules_did_registry.ValidDateUpdateDocumentRequestOptions.md#did) +- [didAttribute](modules_did_registry.ValidDateUpdateDocumentRequestOptions.md#didattribute) + +## Properties + +### data + +• **data**: `IUpdateData` + +___ + +### did + +• **did**: `string` + +___ + +### didAttribute + +• **didAttribute**: `DIDAttribute` diff --git a/docs/api/modules/modules_claims.md b/docs/api/modules/modules_claims.md index cab36b29..94cdb738 100644 --- a/docs/api/modules/modules_claims.md +++ b/docs/api/modules/modules_claims.md @@ -124,7 +124,7 @@ ___ ### readyToBeRegisteredOnchain -▸ **readyToBeRegisteredOnchain**(`claim`): claim is Required\> +▸ **readyToBeRegisteredOnchain**(`claim`): claim is Required\> #### Parameters @@ -134,4 +134,4 @@ ___ #### Returns -claim is Required\> +claim is Required\> diff --git a/docs/api/modules/modules_did_registry.md b/docs/api/modules/modules_did_registry.md index 3ba2bd6e..3ddf336c 100644 --- a/docs/api/modules/modules_did_registry.md +++ b/docs/api/modules/modules_did_registry.md @@ -11,4 +11,16 @@ - [AssetProfile](../interfaces/modules_did_registry.AssetProfile.md) - [AssetProfiles](../interfaces/modules_did_registry.AssetProfiles.md) - [ClaimData](../interfaces/modules_did_registry.ClaimData.md) +- [CreatePublicClaimOptions](../interfaces/modules_did_registry.CreatePublicClaimOptions.md) +- [DecodeJWTTokenOptions](../interfaces/modules_did_registry.DecodeJWTTokenOptions.md) +- [DownloadClaimsOptions](../interfaces/modules_did_registry.DownloadClaimsOptions.md) +- [GetDIDDocumentOptions](../interfaces/modules_did_registry.GetDIDDocumentOptions.md) +- [GetDidDelegatesOptions](../interfaces/modules_did_registry.GetDidDelegatesOptions.md) +- [GetDidPublicKeysOptions](../interfaces/modules_did_registry.GetDidPublicKeysOptions.md) +- [GetServicesOptions](../interfaces/modules_did_registry.GetServicesOptions.md) +- [IssuePublicClaimOptions](../interfaces/modules_did_registry.IssuePublicClaimOptions.md) - [Profile](../interfaces/modules_did_registry.Profile.md) +- [UpdateDocumentOptions](../interfaces/modules_did_registry.UpdateDocumentOptions.md) +- [UpdateSignedDidDelegateOptions](../interfaces/modules_did_registry.UpdateSignedDidDelegateOptions.md) +- [UpdateSignedDidPublicKeyOptions](../interfaces/modules_did_registry.UpdateSignedDidPublicKeyOptions.md) +- [ValidDateUpdateDocumentRequestOptions](../interfaces/modules_did_registry.ValidDateUpdateDocumentRequestOptions.md) diff --git a/src/modules/claims/claims.service.ts b/src/modules/claims/claims.service.ts index d062761a..0606235e 100644 --- a/src/modules/claims/claims.service.ts +++ b/src/modules/claims/claims.service.ts @@ -580,25 +580,26 @@ export class ClaimsService { // TODO: create docs annotations async getClaimId({ claimData }: { claimData: ClaimData }) { - const { service = [] } = await this._didRegistry.getDidDocument(); - const { id, claimTypeVersion } = - service.find( - ({ profile, claimType, claimTypeVersion }) => - Boolean(profile) || - (claimType === claimData.claimType && - claimTypeVersion === claimData.claimTypeVersion) - ) || {}; + const services = await this._didRegistry.getServices(); + const service = services.find( + ({ profile, claimType, claimTypeVersion }) => + Boolean(profile) || + (claimType === claimData.claimType && + claimTypeVersion === claimData.claimTypeVersion) + ); + + if (!service) return v4(); if (claimData.profile && id) { - return id; + return service.id; } if ( claimData.claimType && - id && - claimData.claimTypeVersion === claimTypeVersion + service.id && + claimData.claimTypeVersion === service.claimTypeVersion ) { - return id; + return service.id; } return v4(); } @@ -736,22 +737,25 @@ export class ClaimsService { async getUserClaims({ did = this._signerService.did, }: GetUserClaimsOptions): Promise<(IServiceEndpoint & ClaimData)[]> { - const [{ service }, issuedClaims] = await Promise.all([ - this._didRegistry.getDidDocument({ did }), + const [services, issuedClaims] = await Promise.all([ + this._didRegistry.getServices({ did }), this.getClaimsBySubject({ did, isAccepted: true, }), ]); - if (service.length === 0 || issuedClaims.length === 0) return []; + if (services.length === 0 || issuedClaims.length === 0) return []; const issuedClaimsTypes = issuedClaims .filter((c) => c.registrationTypes.includes(RegistrationTypes.OffChain)) .map(({ claimType }) => claimType); - return service.filter( - ({ claimType }) => claimType && issuedClaimsTypes.includes(claimType) + return services.filter( + ({ claimType }) => + claimType && + typeof claimType === 'string' && + issuedClaimsTypes.includes(claimType) ); } diff --git a/src/modules/did-registry/did-registry.service.ts b/src/modules/did-registry/did-registry.service.ts index 321c7807..1fbe0541 100644 --- a/src/modules/did-registry/did-registry.service.ts +++ b/src/modules/did-registry/did-registry.service.ts @@ -2,7 +2,6 @@ import { Wallet, providers } from 'ethers'; import { KeyType } from '@ew-did-registry/keys'; import { JWT } from '@ew-did-registry/jwt'; import { ProxyOperator } from '@ew-did-registry/proxyidentity'; - import { addressOf, EwSigner, @@ -11,6 +10,7 @@ import { import { DIDAttribute, Encoding, + IDIDDocument, IPublicKey, IServiceEndpoint, IUpdateData, @@ -27,16 +27,28 @@ import { Methods } from '@ew-did-registry/did'; import { ClaimsIssuer, ClaimsUser, - IPublicClaim, ProofVerifier, } from '@ew-did-registry/claims'; import { SignerService } from '../signer/signer.service'; import { ERROR_MESSAGES } from '../../errors'; import { CacheClient } from '../cache-client/cache-client.service'; -import { ClaimData } from './did.types'; +import { + ClaimData, + CreatePublicClaimOptions, + DecodeJWTTokenOptions, + DownloadClaimsOptions, + GetDidDelegatesOptions, + GetDIDDocumentOptions, + GetDidPublicKeysOptions, + GetServicesOptions, + IssuePublicClaimOptions, + UpdateDocumentOptions, + UpdateSignedDidDelegateOptions, + UpdateSignedDidPublicKeyOptions, + ValidDateUpdateDocumentRequestOptions, +} from './did.types'; import { chainConfigs } from '../../config/chain.config'; import { AssetsService } from '../assets/assets.service'; - import { UpdateServicePoint, UpdateDelegate, @@ -45,6 +57,18 @@ import { import { getLogger } from '../../config/logger.config'; const { JsonRpcProvider } = providers; + +/** + * Service responsible for handling the DID Document management. + * See more information about DID in IAM stack [here](https://energy-web-foundation.gitbook.io/energy-web/foundational-concepts/self-sovereign-identity#decentralized-identifiers-dids). + * + * ```typescript + * const { connectToCacheServer } = await initWithPrivateKeySigner(privateKey, rpcUrl); + * const { connectToDidRegistry } = await connectToCacheServer(); + * const { didRegistry } = await connectToDidRegistry(); + * didRegistry.getDidDocument(); + * ``` + */ export class DidRegistry { private _identityOwner: EwSigner; private _operator: Operator; @@ -97,20 +121,33 @@ export class DidRegistry { this._setClaims(); } - async getDidDocument({ - did = this._did, - includeClaims = true, - }: { did?: string; includeClaims?: boolean } | undefined = {}) { + /** + * Retrieve DID Document of the given DID from SSI-Hub if possible, otherwise from blockchain. + * Optionally include claims object within services in the document. + * + * ```typescript + * didRegistry.getDidDocument({ + * did: 'did:ethr:volta:0x00...0', + * includeClaims: true, + * }); + * ``` + * @param {GetDIDDocumentOptions} options object with options + * @return DID document + */ + async getDidDocument( + { did, includeClaims }: GetDIDDocumentOptions = { + did: this._did, + includeClaims: true, + } + ): Promise { if (this._cacheClient) { try { const didDoc = await this._cacheClient.getDidDocument( did, includeClaims ); - return { - ...didDoc, - service: didDoc.service as (IServiceEndpoint & ClaimData)[], - }; + // TODO: implement includeClaims + return didDoc; } catch (err) { getLogger().info(err); throw err; @@ -132,47 +169,84 @@ export class DidRegistry { } /** - * @description gets list of services endpoints from User's DID document + * Gets services from DID document of the given DID. + * + * ```typescript + * didRegistry.getServices({ + * did: 'did:ethr:volta:0x00...0', + * }); + * ``` + * @param {GetServicesOptions} options object with options * @returns list of claims */ - async getServices({ - did = this._signerService.did, - }: { did?: string } | undefined = {}) { - const { service } = (await this.getDidDocument({ did })) || {}; - return service; + async getServices( + { did }: GetServicesOptions = { + did: this._signerService.did, + } + ): Promise { + const didDocument = await this.getDidDocument({ did }); + return didDocument?.service; } /** - * @description get public keys from User's DID document + * Gets public keys from DID document of the given DID. + * + * ```typescript + * didRegistry.getDidPublicKeys({ + * did: 'did:ethr:volta:0x00...0', + * }); + * ``` + * @param {GetDidPublicKeysOptions} options object with options * @returns list of public keys */ - async getDidPublicKeys({ - did = this._signerService.did, - }): Promise { - return (await this.getDidDocument({ did: did, includeClaims: false })) - .publicKey; + async getDidPublicKeys( + { did }: GetDidPublicKeysOptions = { + did: this._signerService.did, + } + ): Promise { + const didDocument = await this.getDidDocument({ did }); + return didDocument?.publicKey; } /** - * @description get public keys from DID's document - * @returns list of DID's delegates + * Gets delegates from DID document of the given DID. + * + * ```typescript + * didRegistry.getDidDelegates({ + * did: 'did:ethr:volta:0x00...0', + * }); + * ``` + * @param {GetDidDelegatesOptions} options object with options + * @returns list of delegates */ - async getDidDelegates({ did = this._did }): Promise { - return (await this.getDidDocument({ did: did, includeClaims: true })) - .delegates; + async getDidDelegates( + { did }: GetDidDelegatesOptions = { + did: this._did, + } + ): Promise { + const didDocument = await this.getDidDocument({ did }); + return didDocument?.delegates; } /** - * @description create a public claim based on data provided - * @returns JWT token of created claim + * Create a public claim with provided data. + * + * ```typescript + * didRegistry.createPublicClaim({ + * data: { + * claimType: 'root.roles.energyweb.iam.ewc', + * claimTypeVersion: 1, + * }, + * subject: 'did:ethr:volta:0x00...0', + * }); + * ``` + * @param {CreatePublicClaimOptions} options object with options + * @return JWT token of created claim */ async createPublicClaim({ data, subject, - }: { - data: ClaimData; - subject?: string; - }) { + }: CreatePublicClaimOptions): Promise { if (subject) { return this._userClaims.createPublicClaim(data, { subject, issuer: '' }); } @@ -180,30 +254,52 @@ export class DidRegistry { } /** - * @description issue a public claim - * @returns return issued token + * If token provided issue new token signed by issuer, + * otherwise create a new claim token based on provided public claim data. + * + * ```typescript + * 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', + * }, + * }, + * }); + * ``` + * @param {IssuePublicClaimOptions} options object with options + * @return JWT token of created claim */ async issuePublicClaim({ token, publicClaim, - }: { - token?: string; - publicClaim?: IPublicClaim; - }) { - if (publicClaim) { - return this._issuerClaims.issuePublicClaim(publicClaim); - } - if (token) { - return this._issuerClaims.issuePublicClaim(token); + }: IssuePublicClaimOptions): Promise { + const params = publicClaim || token; + if (params) { + return this._issuerClaims.issuePublicClaim(params); } - throw new Error('unable to issue Public Claim'); + + throw new Error( + 'Unable to issue public claim: `token` or `publicClaim` must be provided' + ); } /** - * @description verifies issued token of claim - * @returns public claim data + * Verifies issued token of the public claim. + * + * ```typescript + * didRegistry.verifyPublicClaim({ + * token: 'eyJh...VCJ9.ey...IyfQ.SflK...sw5c', + * iss: 'did:ethr:volta:0x00...0', + * }); + * ``` + * @param {String} token JWT token of the public claim + * @param {String} iss DID of the issuer + * @return DID of the authenticated identity on successful verification or null otherwise */ - async verifyPublicClaim(token: string, iss: string) { + async verifyPublicClaim(token: string, iss: string): Promise { const issuerDoc = await this.getDidDocument({ did: iss, includeClaims: true, @@ -213,29 +309,25 @@ export class DidRegistry { } /** - * @param options Options to connect with blockchain - * - * @param options.didAttribute Type of document to be updated + * Update DID document of the given DID with provided data. * - * @param options.data New attribute value - * @param options.did Asset did to be updated - * @param options.validity Time (s) for the attribute to expire - * - * @description updates did document based on data provided - * @returns true if document is updated successfuly + * ```typescript + * 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 */ async updateDocument({ didAttribute, data, validity, did = this._signerService.did, - }: { - didAttribute: DIDAttribute; - data: IUpdateData; - did?: string; - validity?: number; - }): Promise { + }: UpdateDocumentOptions): Promise { this.validDateUpdateDocumentRequest({ didAttribute, data, @@ -255,8 +347,20 @@ export class DidRegistry { } /** - * @description Adds public key to the document of controlled `did` - * @returns true if document is updated successfuly + * 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 */ async updateSignedDidPublicKey({ did = this._signerService.did, @@ -265,14 +369,7 @@ export class DidRegistry { algo = KeyType.Secp256k1, type = PubKeyType.SignatureAuthentication2018, tag = '', - }: { - did: string; - publicKey: string; - algo: KeyType; - type: PubKeyType; - tag: string; - validity?: number; - }): Promise { + }: UpdateSignedDidPublicKeyOptions): Promise { if (!publicKey) throw new Error( ERROR_MESSAGES.CAN_NOT_UPDATE_DOCUMENT_PROPERTIES_INVALID_OR_MISSING + @@ -291,8 +388,19 @@ export class DidRegistry { } /** - * @description updates delegate of the document of controlled `did` - * @returns true if document is updated successfuly + * 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 */ async updateSignedDidDelegate({ did = this._signerService.did, @@ -300,13 +408,7 @@ export class DidRegistry { validity, algo = KeyType.Secp256k1, type = PubKeyType.SignatureAuthentication2018, - }: { - did: string; - delegatePublicKey: string; - algo: KeyType; - type: PubKeyType; - validity?: number; - }): Promise { + }: UpdateSignedDidDelegateOptions): Promise { if (!delegatePublicKey) throw new Error( ERROR_MESSAGES.CAN_NOT_UPDATE_DOCUMENT_PROPERTIES_INVALID_OR_MISSING + @@ -323,8 +425,13 @@ export class DidRegistry { } /** - * @description create did document if not exists - * @returns true if document is created successfully + * Create DID document of the current user if not exists. + * + * ```typescript + * didRegistry.createDocument(); + * ``` + * + * @return true if document was created successfully */ async createDocument(): Promise { if (this._cacheClient) { @@ -341,19 +448,44 @@ export class DidRegistry { } /** - * @description revokes did document - * @returns information (true/false) if the DID document was revoked + * Revoke DID document of the current user. + * + * ```typescript + * didRegistry.revokeDidDocument(); + * ``` + * + * @return true if document was revoked successfully */ async revokeDidDocument(): Promise { await this._document.deactivate(); return true; } - async decodeJWTToken({ token }: { token: string }) { + /** + * Decode JWT token of the public claim. + * + * ```typescript + * didRegistry.decodeJWTToken({ + * token: 'eyJh...VCJ9.ey...IyfQ.SflK...sw5c', + * }); + * ``` + * @param {DecodeJWTTokenOptions} options object with options + * @return payload of the JWT token + */ + async decodeJWTToken({ token }: DecodeJWTTokenOptions) { return this._jwt.decode(token); } - private async getDIDDocFull(did: string) { + /** + * Get `DIDDocumentFull` class of the given DID + * + * ```typescript + * didRegistry.getDIDDocFull('did:ethr:volta:0x00...0'); + * ``` + * @param {String} did DID of the document + * @return `DIDDocumentFull` object + */ + private async getDIDDocFull(did: string): Promise { if (did === this._signerService.did) { return this._document; } else { @@ -375,7 +507,14 @@ export class DidRegistry { } } - private async _setOperator() { + /** + * Set operator based on current configs + * + * ```typescript + * didRegistry._setOperator(); + * ``` + */ + private async _setOperator(): Promise { const signer = this._signerService.signer; const provider = signer.provider; const publicKey = await this._signerService.publicKey(); @@ -399,15 +538,36 @@ export class DidRegistry { this._operator = new Operator(this._identityOwner, { address }); } - private setJWT() { + /** + * Set JWT + * + * ```typescript + * didRegistry.setJWT(); + * ``` + */ + private setJWT(): void { this._jwt = new JWT(this._identityOwner); } - private async _setDocument() { + /** + * Set document of the current user + * + * ```typescript + * didRegistry._setDocument(); + * ``` + */ + private _setDocument(): void { this._document = new DIDDocumentFull(this._did, this._operator); } - private _setClaims() { + /** + * Set claims user and claims issuer class + * + * ```typescript + * didRegistry._setClaims(); + * ``` + */ + private _setClaims(): void { this._userClaims = new ClaimsUser( this._identityOwner, this._document, @@ -420,7 +580,20 @@ export class DidRegistry { ); } - private async downloadClaims({ services }: { services: IServiceEndpoint[] }) { + /** + * Download document claims from IPFS + * + * ```typescript + * const document = await didRegistry.getDidDocument(); + * didRegistry.downloadClaims(document.services); + * ``` + * + * @param {DownloadClaimsOptions} options object with options + * @returns resolved claims + */ + private async downloadClaims({ + services, + }: DownloadClaimsOptions): Promise<(IServiceEndpoint & ClaimData)[]> { return Promise.all( services.map(async ({ serviceEndpoint, ...rest }) => { const data = await this._ipfsStore.get(serviceEndpoint); @@ -438,17 +611,24 @@ export class DidRegistry { } /** - * validates update document request + * Validates update document request. Throws error if validation fails. + * + * ```typescript + * didRegistry.validDateUpdateDocumentRequest({ + * didAttribute: DIDAttribute.PublicKey, + * data: publicKey, + * did: 'did:ethr:volta:0x00...0', + * }); + * ``` + * + * @param {ValidDateUpdateDocumentRequestOptions} options object with options + * */ private validDateUpdateDocumentRequest({ didAttribute, data, did, - }: { - didAttribute: DIDAttribute; - data: IUpdateData; - did: string; - }) { + }: ValidDateUpdateDocumentRequestOptions): void { const rq = { didAttribute, data, did }; try { switch (didAttribute) { diff --git a/src/modules/did-registry/did.types.ts b/src/modules/did-registry/did.types.ts index 85354aed..06573871 100644 --- a/src/modules/did-registry/did.types.ts +++ b/src/modules/did-registry/did.types.ts @@ -1,3 +1,12 @@ +import { IPublicClaim } from '@ew-did-registry/claims'; +import { + DIDAttribute, + IServiceEndpoint, + IUpdateData, + PubKeyType, +} from '@ew-did-registry/did-resolver-interface'; +import { KeyType } from '@ew-did-registry/keys'; + export interface AssetProfile { name?: string; icon?: string; @@ -20,3 +29,114 @@ export interface ClaimData extends Record { claimTypeVersion?: number; issuerFields?: { key: string; value: string | number }[]; } + +export interface GetDIDDocumentOptions { + /* DID of the user */ + did: string; + + /* Indicates resolving claims object */ + includeClaims?: boolean; +} + +export interface GetServicesOptions { + /* DID of the user */ + did: string; +} + +export interface GetDidPublicKeysOptions { + /* DID of the user */ + did: string; +} + +export interface GetDidDelegatesOptions { + /* DID of the user */ + did: string; +} + +export interface CreatePublicClaimOptions { + /* Claim data */ + data: ClaimData; + + /* Subject of the claim */ + subject?: string; +} + +export interface IssuePublicClaimOptions { + /* Signed JWT claim token */ + token?: string; + + /* Public claim data object */ + publicClaim?: IPublicClaim; +} + +export interface UpdateDocumentOptions { + /* Type of document to be updated */ + didAttribute: DIDAttribute; + + /* New attribute value */ + data: IUpdateData; + + /* DID of the document to be updated */ + did?: string; + + /* Time (s) for the attribute to expire */ + validity?: number; +} + +export interface UpdateSignedDidPublicKeyOptions { + /* DID of the document to be updated */ + did: string; + + /* New public key */ + publicKey: string; + + /* Algorithm of the new public key */ + algo: KeyType; + + /* Type of the new public key */ + type: PubKeyType; + + /* Tag for the new public key */ + tag: string; + + /* Time (s) for the attribute to expire */ + validity?: number; +} + +export interface UpdateSignedDidDelegateOptions { + /* DID of the document to be updated */ + did: string; + + /* New delegate public key */ + delegatePublicKey: string; + + /* Algorithm of the new public key */ + algo: KeyType; + + /* Type of the new public key */ + type: PubKeyType; + + /* Time (s) for the attribute to expire */ + validity?: number; +} + +export interface DecodeJWTTokenOptions { + /* Signed JWT token */ + token: string; +} + +export interface DownloadClaimsOptions { + /* services endpoint of the DID documents */ + services: IServiceEndpoint[]; +} + +export interface ValidDateUpdateDocumentRequestOptions { + /* Type of document to be updated */ + didAttribute: DIDAttribute; + + /* New attribute value */ + data: IUpdateData; + + /* DID of the document to be updated */ + did: string; +}