Skip to content

Commit

Permalink
fix: add revocation entity for save credential
Browse files Browse the repository at this point in the history
  • Loading branch information
lotharking committed Dec 17, 2024
1 parent 63be523 commit 9f342c6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
17 changes: 17 additions & 0 deletions packages/nestjs-client/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,21 @@ export interface EventHandler {
* @param message - An instance of BaseMessage containing the input message details.
*/
inputMessage(message: BaseMessage): Promise<void> | void

/**
* Processes the creation of a unique hash for a credential.
* This method should ensure proper handling of credential generation
* by identifying the session associated with the provided connection ID.
*
* The implementation of this method must:
* 1. Identify the session or context using the given connectionId.
* 2. Generate a unique hash string based on the connection session
* and any other required data for the credential.
*
* @param connectionId - The unique identifier of the connection used
* to determine the session context.
* @returns A Promise that resolves to a unique hash Uint8Array representing
* the generated credential.
*/
credentialHash(connectionId: string): Promise<Uint8Array>
}
29 changes: 15 additions & 14 deletions packages/nestjs-client/src/messages/message.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,26 @@ export class MessageEventService {

await this.apiClient.messages.send(body)

if (event.message instanceof CredentialReceptionMessage) {
try {
const credential = (await this.apiClient.credentialTypes.getAll())[0]
if (this.eventHandler) {
if (event.message instanceof CredentialReceptionMessage) {
try {
const credential = (await this.apiClient.credentialTypes.getAll())[0]

const connectionId = await this.connectionRepository.findById(event.message.connectionId)
const connectionId = await this.connectionRepository.findById(event.message.connectionId)

if (connectionId && event.message.state === CredentialState.Done) {
const credentialRev = this.revocationRepository.create({
connection: connectionId,
revocationDefinitionId: credential.revocationId,
})
await this.revocationRepository.save(credentialRev)
if (connectionId && event.message.state === CredentialState.Done) {
const credentialRev = this.revocationRepository.create({
connection: connectionId,
hash: Buffer.from(await this.eventHandler.credentialHash(event.message.connectionId)),
revocationDefinitionId: credential.revocationId,
})
await this.revocationRepository.save(credentialRev)
}
} catch (error) {
this.logger.error(`Cannot create the registry: ${error}`)
}
} catch (error) {
this.logger.error(`Cannot create the registry: ${error}`)
}
}

if (this.eventHandler) {
await this.eventHandler.inputMessage(event.message)
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/nestjs-client/src/models/revocation.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export class RevocationEntity {
@JoinColumn({ name: 'connection_id', referencedColumnName: 'id' })
connection?: ConnectionEntity

@Column({ type: 'blob', nullable: true })
hash?: Buffer

@CreateDateColumn()
createdTs?: Date

Expand Down

0 comments on commit 9f342c6

Please sign in to comment.