Skip to content

Commit

Permalink
refactor(proofs)!: generalize proofs api and improve consistency with…
Browse files Browse the repository at this point in the history
… credentials module

Signed-off-by: Timo Glastra <[email protected]>
  • Loading branch information
TimoGlastra committed Feb 9, 2023
1 parent f18d189 commit c8472b4
Show file tree
Hide file tree
Showing 157 changed files with 6,989 additions and 6,256 deletions.
5 changes: 1 addition & 4 deletions demo/src/Alice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,8 @@ export class Alice extends BaseAgent {
}

public async acceptProofRequest(proofRecord: ProofExchangeRecord) {
const requestedCredentials = await this.agent.proofs.autoSelectCredentialsForProofRequest({
const requestedCredentials = await this.agent.proofs.selectCredentialsForRequest({
proofRecordId: proofRecord.id,
config: {
filterByPresentationPreview: true,
},
})

await this.agent.proofs.acceptRequest({
Expand Down
18 changes: 6 additions & 12 deletions demo/src/Faber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ import type { ConnectionRecord, ConnectionStateChangedEvent } from '@aries-frame
import type { CredDef, Schema } from 'indy-sdk'
import type BottomBar from 'inquirer/lib/ui/bottom-bar'

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

import { BaseAgent } from './BaseAgent'
Expand Down Expand Up @@ -171,15 +165,16 @@ export class Faber extends BaseAgent {
private async newProofAttribute() {
await this.printProofFlow(greenText(`Creating new proof attribute for 'name' ...\n`))
const proofAttribute = {
name: new ProofAttributeInfo({
name: {
name: 'name',
restrictions: [
new AttributeFilter({
{
credentialDefinitionId: this.credentialDefinition?.id,
}),
},
],
}),
},
}

return proofAttribute
}

Expand All @@ -195,7 +190,6 @@ export class Faber extends BaseAgent {
indy: {
name: 'proof-request',
version: '1.0',
nonce: '1298236324864',
requestedAttributes: proofAttribute,
},
},
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"test": "jest",
"lint": "eslint --ignore-path .gitignore .",
"validate": "yarn lint && yarn check-types && yarn check-format",
"prepare": "husky install",
"run-mediator": "ts-node ./samples/mediator.ts",
"next-version-bump": "ts-node ./scripts/get-next-bump.ts"
},
Expand All @@ -48,7 +47,6 @@
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-prettier": "^3.4.0",
"express": "^4.17.1",
"husky": "^7.0.1",
"indy-sdk": "^1.16.0-dev-1636",
"jest": "^27.0.4",
"lerna": "^4.0.0",
Expand Down
3 changes: 0 additions & 3 deletions packages/bbs-signatures/tests/bbs-signatures.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,7 @@ describeSkipNode17And18('BBS W3cCredentialService', () => {

const result = await w3cCredentialService.verifyPresentation(agentContext, {
presentation: vp,
proofType: 'Ed25519Signature2018',
challenge: 'e950bfe5-d7ec-4303-ad61-6983fb976ac9',
verificationMethod:
'did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL#z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL',
})

expect(result.verified).toBe(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describeSkipNode17And18('credentials, BBS+ signature', () => {

testLogger.test('Alice sends (v2, Indy) credential proposal to Faber')

const credentialExchangeRecord: CredentialExchangeRecord = await aliceAgent.credentials.proposeCredential({
const credentialExchangeRecord = await aliceAgent.credentials.proposeCredential({
connectionId: aliceConnection.id,
protocolVersion: 'v2',
credentialFormats: {
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/agent/AgentModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ export type AgentModulesInput = Partial<DefaultAgentModulesInput> & ModulesMap
* Defines the input type for the default agent modules. This is overwritten as we
* want the input type to allow for generics to be passed in for the credentials module.
*/
export type DefaultAgentModulesInput = Omit<DefaultAgentModules, 'credentials'> & {
export type DefaultAgentModulesInput = Omit<DefaultAgentModules, 'credentials' | 'proofs'> & {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
credentials: CredentialsModule<any>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
proofs: ProofsModule<any>
}

/**
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/agent/BaseAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { AgentApi, EmptyModuleMap, ModulesMap, WithoutDefaultModules, Custo
import type { TransportSession } from './TransportService'
import type { Logger } from '../logger'
import type { CredentialsModule } from '../modules/credentials'
import type { ProofsModule } from '../modules/proofs'
import type { DependencyManager } from '../plugins'

import { AriesFrameworkError } from '../error'
Expand All @@ -14,7 +15,7 @@ import { DiscoverFeaturesApi } from '../modules/discover-features'
import { GenericRecordsApi } from '../modules/generic-records'
import { LedgerApi } from '../modules/ledger'
import { OutOfBandApi } from '../modules/oob'
import { ProofsApi } from '../modules/proofs/ProofsApi'
import { ProofsApi } from '../modules/proofs'
import { MediatorApi, RecipientApi } from '../modules/routing'
import { StorageUpdateService } from '../storage'
import { UpdateAssistant } from '../storage/migration/UpdateAssistant'
Expand Down Expand Up @@ -44,7 +45,7 @@ export abstract class BaseAgent<AgentModules extends ModulesMap = EmptyModuleMap

public readonly connections: ConnectionsApi
public readonly credentials: CustomOrDefaultApi<AgentModules['credentials'], CredentialsModule>
public readonly proofs: ProofsApi
public readonly proofs: CustomOrDefaultApi<AgentModules['proofs'], ProofsModule>
public readonly mediator: MediatorApi
public readonly mediationRecipient: RecipientApi
public readonly basicMessages: BasicMessagesApi
Expand Down Expand Up @@ -88,7 +89,7 @@ export abstract class BaseAgent<AgentModules extends ModulesMap = EmptyModuleMap
AgentModules['credentials'],
CredentialsModule
>
this.proofs = this.dependencyManager.resolve(ProofsApi)
this.proofs = this.dependencyManager.resolve(ProofsApi) as CustomOrDefaultApi<AgentModules['proofs'], ProofsModule>
this.mediator = this.dependencyManager.resolve(MediatorApi)
this.mediationRecipient = this.dependencyManager.resolve(RecipientApi)
this.basicMessages = this.dependencyManager.resolve(BasicMessagesApi)
Expand Down
11 changes: 4 additions & 7 deletions packages/core/src/agent/__tests__/Agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { IndyLedgerService } from '../../modules/ledger'
import { LedgerApi } from '../../modules/ledger/LedgerApi'
import { ProofRepository } from '../../modules/proofs'
import { ProofsApi } from '../../modules/proofs/ProofsApi'
import { V1ProofService } from '../../modules/proofs/protocol/v1'
import { V2ProofService } from '../../modules/proofs/protocol/v2'
import { V1ProofProtocol } from '../../modules/proofs/protocol/v1'
import { V2ProofProtocol } from '../../modules/proofs/protocol/v2'
import {
MediationRecipientService,
MediationRepository,
Expand Down Expand Up @@ -161,8 +161,6 @@ describe('Agent', () => {
expect(container.resolve(ConnectionRepository)).toBeInstanceOf(ConnectionRepository)
expect(container.resolve(TrustPingService)).toBeInstanceOf(TrustPingService)

expect(container.resolve(V1ProofService)).toBeInstanceOf(V1ProofService)
expect(container.resolve(V2ProofService)).toBeInstanceOf(V2ProofService)
expect(container.resolve(ProofsApi)).toBeInstanceOf(ProofsApi)
expect(container.resolve(ProofRepository)).toBeInstanceOf(ProofRepository)

Expand Down Expand Up @@ -204,8 +202,6 @@ describe('Agent', () => {
expect(container.resolve(ConnectionRepository)).toBe(container.resolve(ConnectionRepository))
expect(container.resolve(TrustPingService)).toBe(container.resolve(TrustPingService))

expect(container.resolve(V1ProofService)).toBe(container.resolve(V1ProofService))
expect(container.resolve(V2ProofService)).toBe(container.resolve(V2ProofService))
expect(container.resolve(ProofsApi)).toBe(container.resolve(ProofsApi))
expect(container.resolve(ProofRepository)).toBe(container.resolve(ProofRepository))

Expand Down Expand Up @@ -263,10 +259,11 @@ describe('Agent', () => {
'https://didcomm.org/messagepickup/2.0',
'https://didcomm.org/out-of-band/1.1',
'https://didcomm.org/present-proof/1.0',
'https://didcomm.org/present-proof/2.0',
'https://didcomm.org/revocation_notification/1.0',
'https://didcomm.org/revocation_notification/2.0',
])
)
expect(protocols.length).toEqual(14)
expect(protocols.length).toEqual(15)
})
})
4 changes: 2 additions & 2 deletions packages/core/src/decorators/attachment/Attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface AttachmentOptions {
mimeType?: string
lastmodTime?: Date
byteCount?: number
data: AttachmentData
data: AttachmentDataOptions
}

export interface AttachmentDataOptions {
Expand Down Expand Up @@ -97,7 +97,7 @@ export class Attachment {
this.mimeType = options.mimeType
this.lastmodTime = options.lastmodTime
this.byteCount = options.byteCount
this.data = options.data
this.data = new AttachmentData(options.data)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ export class ConnectionService {
previousSentMessage,
previousReceivedMessage,
}: {
previousSentMessage?: AgentMessage
previousReceivedMessage?: AgentMessage
previousSentMessage?: AgentMessage | null
previousReceivedMessage?: AgentMessage | null
} = {}
) {
const { connection, message } = messageContext
Expand Down
Loading

0 comments on commit c8472b4

Please sign in to comment.