Skip to content

Commit

Permalink
refactor(credentials): generic credentials module (#841)
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <[email protected]>
  • Loading branch information
TimoGlastra authored Jun 14, 2022
1 parent ca6c1ce commit 2fe0f18
Show file tree
Hide file tree
Showing 112 changed files with 6,787 additions and 6,892 deletions.
10 changes: 2 additions & 8 deletions demo/src/Faber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ import type { ConnectionRecord } from '@aries-framework/core'
import type { CredDef, Schema } from 'indy-sdk'
import type BottomBar from 'inquirer/lib/ui/bottom-bar'

import {
CredentialProtocolVersion,
V1CredentialPreview,
AttributeFilter,
ProofAttributeInfo,
utils,
} from '@aries-framework/core'
import { V1CredentialPreview, AttributeFilter, ProofAttributeInfo, utils } from '@aries-framework/core'
import { ui } from 'inquirer'

import { BaseAgent } from './BaseAgent'
Expand Down Expand Up @@ -106,7 +100,7 @@ export class Faber extends BaseAgent {

await this.agent.credentials.offerCredential({
connectionId: connectionRecord.id,
protocolVersion: CredentialProtocolVersion.V1,
protocolVersion: 'v1',
credentialFormats: {
indy: {
attributes: credentialPreview.attributes,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/agent/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class Agent {

// We set the modules in the constructor because that allows to set them as read-only
this.connections = this.container.resolve(ConnectionsModule)
this.credentials = this.container.resolve(CredentialsModule)
this.credentials = this.container.resolve(CredentialsModule) as CredentialsModule
this.proofs = this.container.resolve(ProofsModule)
this.mediator = this.container.resolve(MediatorModule)
this.mediationRecipient = this.container.resolve(RecipientModule)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/agent/AgentConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Subject } from 'rxjs'
import { DID_COMM_TRANSPORT_QUEUE } from '../constants'
import { AriesFrameworkError } from '../error'
import { ConsoleLogger, LogLevel } from '../logger'
import { AutoAcceptCredential } from '../modules/credentials/CredentialAutoAcceptType'
import { AutoAcceptCredential } from '../modules/credentials/models/CredentialAutoAcceptType'
import { AutoAcceptProof } from '../modules/proofs/ProofAutoAcceptType'
import { DidCommMimeType } from '../types'

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/credentials/CredentialEvents.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BaseEvent } from '../../agent/Events'
import type { CredentialState } from './CredentialState'
import type { CredentialState } from './models/CredentialState'
import type { CredentialExchangeRecord } from './repository/CredentialExchangeRecord'

export enum CredentialEventTypes {
Expand Down

This file was deleted.

104 changes: 44 additions & 60 deletions packages/core/src/modules/credentials/CredentialServiceOptions.ts
Original file line number Diff line number Diff line change
@@ -1,89 +1,73 @@
import type { AgentMessage } from '../../agent/AgentMessage'
import type { Attachment } from '../../decorators/attachment/Attachment'
import type { LinkedAttachment } from '../../utils/LinkedAttachment'
import type { ConnectionRecord } from '../connections/repository/ConnectionRecord'
import type { AutoAcceptCredential } from './CredentialAutoAcceptType'
import type {
AcceptOfferOptions,
AcceptProposalOptions,
AcceptRequestOptions,
NegotiateOfferOptions,
NegotiateProposalOptions,
RequestCredentialOptions,
} from './CredentialsModuleOptions'
import type { FormatServiceAcceptProposeCredentialFormats } from './formats/models/CredentialFormatServiceOptions'
import type { CredentialPreviewAttribute } from './models/CredentialPreviewAttribute'
import type { V1CredentialPreview } from './protocol/v1/V1CredentialPreview'
import type { ProposeCredentialMessageOptions } from './protocol/v1/messages'
import type { CredentialFormat, CredentialFormatPayload } from './formats'
import type { AutoAcceptCredential } from './models/CredentialAutoAcceptType'
import type { CredentialExchangeRecord } from './repository/CredentialExchangeRecord'

export interface IndyCredentialPreview {
credentialDefinitionId?: string
attributes?: CredentialPreviewAttribute[]
export interface CreateProposalOptions<CFs extends CredentialFormat[]> {
connection: ConnectionRecord
credentialFormats: CredentialFormatPayload<CFs, 'createProposal'>
autoAcceptCredential?: AutoAcceptCredential
comment?: string
}

export interface CredentialProtocolMsgReturnType<MessageType extends AgentMessage> {
message: MessageType
export interface AcceptProposalOptions<CFs extends CredentialFormat[]> {
credentialRecord: CredentialExchangeRecord
}

export interface CredentialOfferTemplate {
credentialDefinitionId: string
comment?: string
preview: V1CredentialPreview
credentialFormats?: CredentialFormatPayload<CFs, 'acceptProposal'>
autoAcceptCredential?: AutoAcceptCredential
attachments?: Attachment[]
linkedAttachments?: LinkedAttachment[]
comment?: string
}

export interface ServiceAcceptOfferOptions extends AcceptOfferOptions {
attachId?: string
credentialFormats: {
indy?: IndyCredentialPreview
jsonld?: {
// todo
}
}
export interface NegotiateProposalOptions<CFs extends CredentialFormat[]> {
credentialRecord: CredentialExchangeRecord
credentialFormats: CredentialFormatPayload<CFs, 'createOffer'>
autoAcceptCredential?: AutoAcceptCredential
comment?: string
}

export interface ServiceOfferCredentialOptions {
export interface CreateOfferOptions<CFs extends CredentialFormat[]> {
// Create offer can also be used for connection-less, so connection is optional
connection?: ConnectionRecord
credentialFormats: CredentialFormatPayload<CFs, 'createOffer'>
autoAcceptCredential?: AutoAcceptCredential
comment?: string
credentialRecordId?: string
connection?: ConnectionRecord
attachId?: string
credentialFormats: FormatServiceAcceptProposeCredentialFormats
}

export interface ServiceAcceptProposalOptions extends AcceptProposalOptions {
offerAttachment?: Attachment
proposalAttachment?: Attachment
export interface AcceptOfferOptions<CFs extends CredentialFormat[]> {
credentialRecord: CredentialExchangeRecord
credentialFormats?: CredentialFormatPayload<CFs, 'acceptOffer'>
autoAcceptCredential?: AutoAcceptCredential
comment?: string
}

export interface ServiceAcceptRequestOptions extends AcceptRequestOptions {
attachId?: string
}
export interface ServiceNegotiateProposalOptions extends NegotiateProposalOptions {
offerAttachment?: Attachment
export interface NegotiateOfferOptions<CFs extends CredentialFormat[]> {
credentialRecord: CredentialExchangeRecord
credentialFormats: CredentialFormatPayload<CFs, 'createProposal'>
autoAcceptCredential?: AutoAcceptCredential
comment?: string
}

export interface ServiceNegotiateOfferOptions extends NegotiateOfferOptions {
offerAttachment?: Attachment
export interface CreateRequestOptions<CFs extends CredentialFormat[]> {
connection: ConnectionRecord
credentialFormats: CredentialFormatPayload<CFs, 'createRequest'>
autoAcceptCredential?: AutoAcceptCredential
comment?: string
}

export interface ServiceRequestCredentialOptions extends RequestCredentialOptions {
attachId?: string
offerAttachment?: Attachment
requestAttachment?: Attachment
export interface AcceptRequestOptions<CFs extends CredentialFormat[]> {
credentialRecord: CredentialExchangeRecord
credentialFormats?: CredentialFormatPayload<CFs, 'acceptRequest'>
autoAcceptCredential?: AutoAcceptCredential
comment?: string
}

export interface ServiceAcceptCredentialOptions {
credentialAttachment?: Attachment
export interface AcceptCredentialOptions {
credentialRecord: CredentialExchangeRecord
}

export type CredentialProposeOptions = Omit<ProposeCredentialMessageOptions, 'id'> & {
linkedAttachments?: LinkedAttachment[]
autoAcceptCredential?: AutoAcceptCredential
export interface CredentialProtocolMsgReturnType<MessageType extends AgentMessage> {
message: MessageType
credentialRecord: CredentialExchangeRecord
}

export interface DeleteCredentialOptions {
Expand Down
Loading

0 comments on commit 2fe0f18

Please sign in to comment.