modules/claims.ClaimsService
Service responsible for handling the request and issuance of claims. See more information about claims in IAM stack here.
const { connectToCacheServer } = await initWithPrivateKeySigner(privateKey, rpcUrl);
const { connectToDidRegistry } = await connectToCacheServer();
const { claimsService } = await connectToDidRegistry();
claimsService.getClaimById(claim.id);
- claimRevocationDetails
- createClaimRequest
- createDelegateProof
- createIdentityProof
- createSelfSignedClaim
- deleteClaim
- getClaimById
- getClaimId
- getClaimsByIssuer
- getClaimsByRequester
- getClaimsBySubject
- getClaimsBySubjects
- getNamespaceFromClaimType
- getUserClaims
- hasOnChainRole
- init
- isClaimRevoked
- issueClaim
- issueClaimRequest
- publishPublicClaim
- registerOnchain
- rejectClaimRequest
- revokeClaim
- revokeMultipleClaim
- verifyVc
- create
• new ClaimsService(_signerService
, _domainsService
, _cacheClient
, _didRegistry
, _verifiableCredentialService
)
Name | Type |
---|---|
_signerService |
SignerService |
_domainsService |
DomainsService |
_cacheClient |
CacheClient |
_didRegistry |
DidRegistry |
_verifiableCredentialService |
VerifiableCredentialsServiceBase |
▸ claimRevocationDetails(options
): Promise
<undefined
| ClaimRevocationDetailsResult
>
Get the revocation details for a subject's On-Chain claim. Returns the revoker and revocationTimeStamp for the revocation.
claimsService.claimRevocationDetails({
claim: {
namespace: 'root.roles.energyweb.iam.ewc',
subject: 'did:ethr:volta:0x00...0',
},
});
or
claimsService.claimRevocationDetails({
claimId: claim.id,
});
Name | Type | Description |
---|---|---|
options |
ClaimRevocationDetailsOptions |
object containing options |
Promise
<undefined
| ClaimRevocationDetailsResult
>
revocation details
▸ createClaimRequest(options
): Promise
<void
>
Allows subject to request for credential by creating and sending a claim request to claim issuer.
claimsService.createClaimRequest({
claim: {
claimType: 'email.roles.energyweb.iam.ewc',
claimTypeVersion: 1,
requestorFields: [{key: 'foo', value: 'bar'}],
};
subject: 'did:ethr:0x00...0',
registrationTypes: [RegistrationTypes.OnChain, RegistrationTypes.OffChain]
});
Name | Type | Description |
---|---|---|
options |
CreateClaimRequestOptions |
object containing options |
Promise
<void
>
▸ createDelegateProof(delegateKey
, identity
, algorithm?
): Promise
<string
>
Create a public claim to prove identity.
claimsService.createDelegateProof(
'245a40a9...776071ca57cec',
'did:ethr:0x00...0',
Algorithms.EIP191,
);
Name | Type | Default value | Description |
---|---|---|---|
delegateKey |
string |
undefined |
Private key of the delegate in hexadecimal format |
identity |
string |
undefined |
DID of the delegate |
algorithm |
Algorithms |
Algorithms.EIP191 |
Algorithm used to sign the delegate (EIP191 and ES256 available) |
Promise
<string
>
JWT token of delegate
▸ createIdentityProof(): Promise
<string
>
Create a public claim to prove identity.
claimsService.createIdentityProof();
Promise
<string
>
JWT token of created identity
▸ createSelfSignedClaim(options
): Promise
<string
>
Creates self signed off-chain claim with data
and adds it to subject
document. Signer must own or control subject.
claimsService.createSelfSignedClaim({
data: {
claimType: 'email.roles.energyweb.iam.ewc',
claimTypeVersion: 1,
issuerFields: [{key: 'foo', value: 'bar'}],
profile: {
name: 'John Doe',
birthdate: '1990-01-01',
address: '123 Main St',
},
},
subject: 'did:ethr:volta:0x00...0',
});
Name | Type | Description |
---|---|---|
options |
CreateSelfSignedClaimOptions |
object containing options |
Promise
<string
>
URl to IPFS
▸ deleteClaim(options
): Promise
<void
>
Delete claim request. Works only for pending claims (not issued or rejected).
claimsService.deleteClaim({
id: '7281a130-e2b1-430d-8c14-201010eae901',
});
Name | Type | Description |
---|---|---|
options |
DeleteClaimOptions |
object containing options |
Promise
<void
>
▸ getClaimById(claimId
): Promise
<undefined
| Claim
>
Retrieve claim with given id.
const claimId = '7281a130-e2b1-430d-8c14-201010eae901';
claimsService.getClaimById(claimId);
Name | Type | Description |
---|---|---|
claimId |
string |
claim id |
Promise
<undefined
| Claim
>
claim with given id
▸ getClaimId(__namedParameters
): Promise
<string
>
Name | Type |
---|---|
__namedParameters |
Object |
__namedParameters.claimData |
ClaimData |
Promise
<string
>
▸ getClaimsByIssuer(options
): Promise
<Claim
[]>
Retrieve claims issued by a given issuer with allowing filter by status and parent namespace.
claimsService.getClaimsByIssuer({
did: 'did:ethr:0x00...0',
isAccepted: false,
namespace: 'energyweb.iam.ewc',
});
Name | Type | Description |
---|---|---|
options |
GetClaimsByIssuerOptions |
object containing options |
Promise
<Claim
[]>
list of claims
▸ getClaimsByRequester(options
): Promise
<Claim
[]>
Retrieve claims requested by a given requester with allowing filter by status and parent namespace.
claimsService.getClaimsByRequester({
did: 'did:ethr:0x00...0',
isAccepted: false,
namespace: 'energyweb.iam.ewc',
});
Name | Type | Description |
---|---|---|
options |
GetClaimsByRequesterOptions |
object containing options |
Promise
<Claim
[]>
list of claims
▸ getClaimsBySubject(options
): Promise
<Claim
[]>
Retrieve claims for given subject with allowing filter by status and parent namespace.
claimsService.getClaimsBySubject({
did: 'did:ethr:0x00...0',
isAccepted: false,
namespace: 'energyweb.iam.ewc',
});
Name | Type | Description |
---|---|---|
options |
GetClaimsBySubjectOptions |
object containing options |
Promise
<Claim
[]>
list of claims
▸ getClaimsBySubjects(subjects
): Promise
<Claim
[]>
Retrieve claims related to a given subjects.
claimsService.getClaimsBySubjects(['did:ethr:0x00...0', 'did:ethr:0x00...1', ...]);
Name | Type | Description |
---|---|---|
subjects |
string [] |
list of subjects |
Promise
<Claim
[]>
list of claims
▸ getNamespaceFromClaimType(claimType
): string
Get namespace
from claim type.
claimsService.getNamespaceFromClaimType(
'email.roles.energyweb.iam.ewc'
);
Name | Type | Description |
---|---|---|
claimType |
string |
Private key of the delegate in hexadecimal format |
string
Namespace of given claim type
▸ getUserClaims(options
): Promise
<IServiceEndpoint
& ClaimData
[]>
Get published off-chain claims of the given subject.
claimsService.getUserClaims({
did: 'did:ethr:0x00...0',
});
Name | Type | Description |
---|---|---|
options |
GetUserClaimsOptions |
object containing options |
Promise
<IServiceEndpoint
& ClaimData
[]>
Claims containing DID document service endpoints
▸ hasOnChainRole(did
, role
, version
): Promise
<boolean
>
A utility function to check the blockchain directly if a DID has a role.
claimsService.hasOnChainRole('did:ethr:ewc:0x00...0', 'email.roles.iam.ewc', 1);
Name | Type | Description |
---|---|---|
did |
string |
The ethr DID to check |
role |
string |
The role to check (the full namespace) |
version |
number |
The version to check |
Promise
<boolean
>
true
if DID has role at the version. false
if not.
▸ init(): Promise
<void
>
Promise
<void
>
▸ isClaimRevoked(options
): Promise
<boolean
>
Check if On-Chain claim is revoked.
claimsService.isClaimRevoked({
claim: {
namespace: 'root.roles.energyweb.iam.ewc',
subject: 'did:ethr:volta:0x00...0',
},
});
or
claimsService.isClaimRevoked({
claimId: claim.id,
});
Name | Type | Description |
---|---|---|
options |
IsClaimRevokedOptions |
object containing options |
Promise
<boolean
>
true if claim is revoked
▸ issueClaim(options
): Promise
<undefined
| string
>
Issue claim without previous request. Option available for issuers only.
claimsService.issueClaim({
claim: {
claimType: 'email.roles.energyweb.iam.ewc',
claimTypeVersion: 1,
issuerFields: [{key: 'foo', value: 'bar'}],
};
subject: 'did:ethr:0x00...0',
registrationTypes: [RegistrationTypes.OnChain, RegistrationTypes.OffChain]
});
Name | Type | Description |
---|---|---|
options |
IssueClaimOptions |
object containing options |
Promise
<undefined
| string
>
Issued token if registrationTypes includes RegistrationTypes.OffChain
▸ issueClaimRequest(options
): Promise
<void
>
Issue a claim request by signing both off-chain and on-chain request and persisting result to the cache-server. Optionally, issue on-chain role can be submitted to the ClaimManager contract as well.
const claim: Claim = await claimsService.getClaimById('7281a130-e2b1-430d-8c14-201010eae901');
claimsService.issueClaimRequest({
requester: claim.requester,
token: claim.token,
id: claim.id,
subjectAgreement: claim.subjectAgreement,
registrationTypes: claim.registrationTypes;
issuerFields: [{key: 'foo', value: 'bar'}],
publishOnChain: false,
});
Name | Type | Description |
---|---|---|
options |
IssueClaimRequestOptions |
object containing options |
Promise
<void
>
▸ publishPublicClaim(options
): Promise
<undefined
| string
>
Register role to claim manager contract if registrationTypes includes RegistrationTypes.OnChain Publish role to IPFS and add DID document service if registrationTypes includes RegistrationTypes.OffChain
const claim: Claim = await claimsService.getClaimById('7281a130-e2b1-430d-8c14-201010eae901');
claimsService.publishPublicClaim({
claim: {
token: claim.token,
claimType: claim.claimType,
};
registrationTypes: claim.registrationTypes,
});
Name | Type | Description |
---|---|---|
options |
PublishPublicClaimOptions |
object containing options |
Promise
<undefined
| string
>
URl to IPFS if registrationTypes includes RegistrationTypes.OffChain
▸ registerOnchain(claim
): Promise
<void
>
Register issued on-chain claim on Claim Manager contract.
const claim: Claim = await claimsService.getClaimById('7281a130-e2b1-430d-8c14-201010eae901');
claimsService.registerOnchain({
claimType: claim.claimType,
claimTypeVersion: claim.claimTypeVersion,
subjectAgreement: claim.subjectAgreement,
onChainProof: claim.onChainProof,
acceptedBy: claim.acceptedBy;
subject: claim.subject,
});
Name | Type | Description |
---|---|---|
claim |
RegisterOnchainOptions |
object containing options |
Promise
<void
>
▸ rejectClaimRequest(options
): Promise
<void
>
Reject claim request.
const claim: Claim = await claimsService.getClaimById('7281a130-e2b1-430d-8c14-201010eae901');
claimsService.rejectClaimRequest({
id: claim.id,
requesterDID: claim.requester,
rejectionReason: 'some reason',
});
Name | Type | Description |
---|---|---|
options |
RejectClaimRequestOptions |
object containing options |
Promise
<void
>
▸ revokeClaim(options
): Promise
<boolean
>
Revoke On-Chain issued claim by claimId
or given namespace
and subject
. Required claimId
or claim
parameters.
claimsService.revokeClaim({
claim: {
namespace: 'root.roles.energyweb.iam.ewc',
subject: 'did:ethr:volta:0x00...0',
},
registrationTypes = [RegistrationTypes.OnChain, RegistrationTypes.OffChain],
});
or
claimsService.revokeClaim({
claimId: claim.id,
registrationTypes = [RegistrationTypes.OnChain, RegistrationTypes.OffChain],
});
Name | Type | Description |
---|---|---|
options |
RevokeClaimOptions |
object containing options |
Promise
<boolean
>
true if claim was revoked
▸ revokeMultipleClaim(options
): Promise
<void
>
Revoke On-Chain issued claims of the given namespace for multiple subjects. Namespace must be the same for all subjects.
Specify claims
or claimIds
parameters.
claimsService.revokeMultipleClaim({
claims: [{
namespace: 'root.roles.energyweb.iam.ewc',
subject: 'did:ethr:volta:0x00...0',
registrationTypes = [RegistrationTypes.OnChain, RegistrationTypes.OffChain],
},
{
namespace: 'root.roles.energyweb.iam.ewc',
subject: 'did:ethr:volta:0x00...1',
registrationTypes = [RegistrationTypes.OnChain],
}],
});
or
claimsService.revokeMultipleClaim({
claimIds: ['245a40a9...776071ca57cec', '245a40a9...776071ca57cec'],
});
Name | Type | Description |
---|---|---|
options |
RevokeMultipleClaimOptions |
object containing options |
Promise
<void
>
▸ verifyVc(vc
): Promise
<void
>
Name | Type |
---|---|
vc |
VerifiableCredential <RoleCredentialSubject > |
Promise
<void
>
▸ Static
create(signerService
, domainsService
, cacheClient
, didRegistry
, verifiableCredentialService
): Promise
<ClaimsService
>
Name | Type |
---|---|
signerService |
SignerService |
domainsService |
DomainsService |
cacheClient |
CacheClient |
didRegistry |
DidRegistry |
verifiableCredentialService |
VerifiableCredentialsServiceBase |
Promise
<ClaimsService
>