-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add resource connector in credential issuance
- Loading branch information
1 parent
e18d4ac
commit 332471b
Showing
4 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as dotenv from 'dotenv'; | ||
import type { VerifiableCredential } from '@veramo/core'; | ||
import { IdentityServiceStrategySetup } from '../identity'; | ||
import type { AlternativeUri, MsgCreateResourcePayload } from '@cheqd/ts-proto/cheqd/resource/v2'; | ||
import { v4 } from 'uuid'; | ||
import { fromString } from 'uint8arrays'; | ||
import type { CustomerEntity } from '../../database/entities/customer.entity'; | ||
dotenv.config(); | ||
|
||
/** | ||
* Helper class for the Verida protocol. | ||
* | ||
* Run the init method before running any other method. | ||
*/ | ||
export class ResourceConnector { | ||
static instance = new ResourceConnector(); | ||
|
||
/** | ||
* Send a Verifiable Credential to a DID via the Verida protocol. | ||
* | ||
* @param recipientDid The DID of the recipient. | ||
* @param messageSubject The subject of the message in which the Credential will be sent to the recipient (similar to an email subject). | ||
* @param credential The credential itself. | ||
* @param credentialName The name of the credential. For instance, will be displayed in the Verida Wallet UI. | ||
* @param credentialSummary A summary of the credential. For instance, will be displayed in the Verida Wallet UI. | ||
*/ | ||
async sendCredential( | ||
customer: CustomerEntity, | ||
recipientDid: string, | ||
credential: VerifiableCredential, | ||
credentialName: string, | ||
resourceType: string, | ||
resourceVersion: string, | ||
alsoKnownAs?: AlternativeUri[] | ||
) { | ||
// Get strategy e.g. postgres or local | ||
const identityServiceStrategySetup = new IdentityServiceStrategySetup(customer.customerId); | ||
|
||
let resourcePayload: Partial<MsgCreateResourcePayload> = {}; | ||
resourcePayload = { | ||
collectionId: recipientDid.split(':').pop(), | ||
id: v4(), | ||
name: credentialName, | ||
resourceType, | ||
data: fromString(credential, 'utf-8'), | ||
version: resourceVersion, | ||
alsoKnownAs, | ||
}; | ||
await identityServiceStrategySetup.agent.createResource(recipientDid.split(':')[2], resourcePayload, customer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters