-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ledger): smart schema and credential definition registration (#900)
Signed-off-by: Moriarty <moritz@animo.id>
- Loading branch information
1 parent
adfa65b
commit 1e708e9
Showing
8 changed files
with
648 additions
and
9 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
packages/core/src/modules/indy/repository/AnonCredsCredentialDefinitionRecord.ts
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,39 @@ | ||
import type { CredDef } from 'indy-sdk' | ||
|
||
import { BaseRecord } from '../../../storage/BaseRecord' | ||
import { didFromCredentialDefinitionId } from '../../../utils/did' | ||
|
||
export interface AnonCredsCredentialDefinitionRecordProps { | ||
credentialDefinition: CredDef | ||
} | ||
|
||
export type DefaultAnonCredsCredentialDefinitionTags = { | ||
credentialDefinitionId: string | ||
issuerDid: string | ||
schemaId: string | ||
tag: string | ||
} | ||
|
||
export class AnonCredsCredentialDefinitionRecord extends BaseRecord<DefaultAnonCredsCredentialDefinitionTags> { | ||
public static readonly type = 'AnonCredsCredentialDefinitionRecord' | ||
public readonly type = AnonCredsCredentialDefinitionRecord.type | ||
public readonly credentialDefinition!: CredDef | ||
|
||
public constructor(props: AnonCredsCredentialDefinitionRecordProps) { | ||
super() | ||
|
||
if (props) { | ||
this.credentialDefinition = props.credentialDefinition | ||
} | ||
} | ||
|
||
public getTags() { | ||
return { | ||
...this._tags, | ||
credentialDefinitionId: this.credentialDefinition.id, | ||
issuerDid: didFromCredentialDefinitionId(this.credentialDefinition.id), | ||
schemaId: this.credentialDefinition.schemaId, | ||
tag: this.credentialDefinition.tag, | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/core/src/modules/indy/repository/AnonCredsCredentialDefinitionRepository.ts
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,27 @@ | ||
import type { AgentContext } from '../../../agent/context/AgentContext' | ||
|
||
import { EventEmitter } from '../../../agent/EventEmitter' | ||
import { InjectionSymbols } from '../../../constants' | ||
import { injectable, inject } from '../../../plugins' | ||
import { Repository } from '../../../storage/Repository' | ||
import { StorageService } from '../../../storage/StorageService' | ||
|
||
import { AnonCredsCredentialDefinitionRecord } from './AnonCredsCredentialDefinitionRecord' | ||
|
||
@injectable() | ||
export class AnonCredsCredentialDefinitionRepository extends Repository<AnonCredsCredentialDefinitionRecord> { | ||
public constructor( | ||
@inject(InjectionSymbols.StorageService) storageService: StorageService<AnonCredsCredentialDefinitionRecord>, | ||
eventEmitter: EventEmitter | ||
) { | ||
super(AnonCredsCredentialDefinitionRecord, storageService, eventEmitter) | ||
} | ||
|
||
public async getByCredentialDefinitionId(agentContext: AgentContext, credentialDefinitionId: string) { | ||
return this.getSingleByQuery(agentContext, { credentialDefinitionId }) | ||
} | ||
|
||
public async findByCredentialDefinitionId(agentContext: AgentContext, credentialDefinitionId: string) { | ||
return this.findSingleByQuery(agentContext, { credentialDefinitionId }) | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
packages/core/src/modules/indy/repository/AnonCredsSchemaRecord.ts
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,39 @@ | ||
import type { Schema } from 'indy-sdk' | ||
|
||
import { BaseRecord } from '../../../storage/BaseRecord' | ||
import { didFromSchemaId } from '../../../utils/did' | ||
|
||
export interface AnonCredsSchemaRecordProps { | ||
schema: Schema | ||
} | ||
|
||
export type DefaultAnonCredsSchemaTags = { | ||
schemaId: string | ||
schemaIssuerDid: string | ||
schemaName: string | ||
schemaVersion: string | ||
} | ||
|
||
export class AnonCredsSchemaRecord extends BaseRecord<DefaultAnonCredsSchemaTags> { | ||
public static readonly type = 'AnonCredsSchemaRecord' | ||
public readonly type = AnonCredsSchemaRecord.type | ||
public readonly schema!: Schema | ||
|
||
public constructor(props: AnonCredsSchemaRecordProps) { | ||
super() | ||
|
||
if (props) { | ||
this.schema = props.schema | ||
} | ||
} | ||
|
||
public getTags() { | ||
return { | ||
...this._tags, | ||
schemaId: this.schema.id, | ||
schemaIssuerDid: didFromSchemaId(this.schema.id), | ||
schemaName: this.schema.name, | ||
schemaVersion: this.schema.version, | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/core/src/modules/indy/repository/AnonCredsSchemaRepository.ts
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,27 @@ | ||
import type { AgentContext } from '../../../agent/context/AgentContext' | ||
|
||
import { EventEmitter } from '../../../agent/EventEmitter' | ||
import { InjectionSymbols } from '../../../constants' | ||
import { injectable, inject } from '../../../plugins' | ||
import { Repository } from '../../../storage/Repository' | ||
import { StorageService } from '../../../storage/StorageService' | ||
|
||
import { AnonCredsSchemaRecord } from './AnonCredsSchemaRecord' | ||
|
||
@injectable() | ||
export class AnonCredsSchemaRepository extends Repository<AnonCredsSchemaRecord> { | ||
public constructor( | ||
@inject(InjectionSymbols.StorageService) storageService: StorageService<AnonCredsSchemaRecord>, | ||
eventEmitter: EventEmitter | ||
) { | ||
super(AnonCredsSchemaRecord, storageService, eventEmitter) | ||
} | ||
|
||
public async getBySchemaId(agentContext: AgentContext, schemaId: string) { | ||
return this.getSingleByQuery(agentContext, { schemaId: schemaId }) | ||
} | ||
|
||
public async findBySchemaId(agentContext: AgentContext, schemaId: string) { | ||
return await this.findSingleByQuery(agentContext, { schemaId: schemaId }) | ||
} | ||
} |
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
Oops, something went wrong.