Skip to content

Commit

Permalink
feat: update registry
Browse files Browse the repository at this point in the history
  • Loading branch information
lotharking committed Dec 17, 2024
1 parent 9f342c6 commit 92e3c39
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
24 changes: 15 additions & 9 deletions packages/nestjs-client/src/messages/message.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,23 @@ export class MessageEventService {
if (this.eventHandler) {
if (event.message instanceof CredentialReceptionMessage) {
try {
const credential = (await this.apiClient.credentialTypes.getAll())[0]

const [credential] = await this.apiClient.credentialTypes.getAll()
const connectionId = await this.connectionRepository.findById(event.message.connectionId)
const hash = Buffer.from(await this.eventHandler.credentialHash(event.message.connectionId))
const currentCred = await this.revocationRepository.findOneBy({ hash })
const isCredentialDone = event.message.state === CredentialState.Done

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)
if (connectionId && isCredentialDone) {
if (!currentCred) {
const credentialRev = this.revocationRepository.create({
connectionId,
hash,
revocationDefinitionId: credential.revocationId,
})
await this.revocationRepository.save(credentialRev)
} else {
this.revocationRepository.update(currentCred.id, { connectionId })
}
}
} catch (error) {
this.logger.error(`Cannot create the registry: ${error}`)
Expand Down
4 changes: 2 additions & 2 deletions packages/nestjs-client/src/models/revocation.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ConnectionEntity } from '../connections'
@Entity('revocations')
export class RevocationEntity {
@PrimaryGeneratedColumn('increment')
id?: string
id!: string

@Column({ type: 'varchar', nullable: false })
revocationDefinitionId?: string
Expand All @@ -23,7 +23,7 @@ export class RevocationEntity {

@OneToOne(() => ConnectionEntity, { nullable: false })
@JoinColumn({ name: 'connection_id', referencedColumnName: 'id' })
connection?: ConnectionEntity
connectionId?: ConnectionEntity

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

0 comments on commit 92e3c39

Please sign in to comment.