Skip to content

Commit

Permalink
Merge branch 'main' into sm
Browse files Browse the repository at this point in the history
  • Loading branch information
auer-martin committed Jul 26, 2023
2 parents 71c430b + 6795426 commit 3b8e9bb
Show file tree
Hide file tree
Showing 74 changed files with 1,422 additions and 1,148 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/continuous-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
with:
node-version: 16
cache: 'yarn'
registry-url: 'https://registry.npmjs.org/'

- name: Install dependencies
run: yarn install --frozen-lockfile
Expand Down Expand Up @@ -78,6 +79,7 @@ jobs:
with:
node-version: 16
cache: 'yarn'
registry-url: 'https://registry.npmjs.org/'

- name: Install dependencies
run: yarn install --frozen-lockfile
Expand All @@ -91,7 +93,7 @@ jobs:
echo version="${NEW_VERSION}" >> "$GITHUB_OUTPUT"
- name: Create Tag
uses: mathieudutour/github-tag-action@v6.0
uses: mathieudutour/github-tag-action@v6.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: ${{ steps.new-version.outputs.version }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
- name: Run tests
run: TEST_AGENT_PUBLIC_DID_SEED=${TEST_AGENT_PUBLIC_DID_SEED} ENDORSER_AGENT_PUBLIC_DID_SEED=${ENDORSER_AGENT_PUBLIC_DID_SEED} GENESIS_TXN_PATH=${GENESIS_TXN_PATH} yarn test --coverage --forceExit --bail

- uses: codecov/codecov-action@v1
- uses: codecov/codecov-action@v3
if: always()

version-stable:
Expand Down Expand Up @@ -182,7 +182,7 @@ jobs:
echo version="${NEW_VERSION}" >> "$GITHUB_OUTPUT"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v5
with:
commit-message: |
chore(release): v${{ steps.new-version.outputs.version }}
Expand Down
5 changes: 0 additions & 5 deletions demo/src/Alice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ export class Alice extends BaseAgent {
}

public async acceptCredentialOffer(credentialRecord: CredentialExchangeRecord) {
const linkSecretIds = await this.agent.modules.anoncreds.getLinkSecretIds()
if (linkSecretIds.length === 0) {
await this.agent.modules.anoncreds.createLinkSecret()
}

await this.agent.credentials.acceptOffer({
credentialRecordId: credentialRecord.id,
})
Expand Down
20 changes: 10 additions & 10 deletions packages/action-menu/src/ActionMenuApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
AriesFrameworkError,
ConnectionService,
MessageSender,
OutboundMessageContext,
injectable,
getOutboundMessageContext,
} from '@aries-framework/core'

import { ActionMenuRole } from './ActionMenuRole'
Expand Down Expand Up @@ -66,10 +66,10 @@ export class ActionMenuApi {
connection,
})

const outboundMessageContext = new OutboundMessageContext(message, {
agentContext: this.agentContext,
connection,
const outboundMessageContext = await getOutboundMessageContext(this.agentContext, {
message,
associatedRecord: record,
connectionRecord: connection,
})

await this.messageSender.sendMessage(outboundMessageContext)
Expand All @@ -92,10 +92,10 @@ export class ActionMenuApi {
menu: options.menu,
})

const outboundMessageContext = new OutboundMessageContext(message, {
agentContext: this.agentContext,
connection,
const outboundMessageContext = await getOutboundMessageContext(this.agentContext, {
message,
associatedRecord: record,
connectionRecord: connection,
})

await this.messageSender.sendMessage(outboundMessageContext)
Expand Down Expand Up @@ -126,10 +126,10 @@ export class ActionMenuApi {
performedAction: options.performedAction,
})

const outboundMessageContext = new OutboundMessageContext(message, {
agentContext: this.agentContext,
connection,
const outboundMessageContext = await getOutboundMessageContext(this.agentContext, {
message,
associatedRecord: record,
connectionRecord: connection,
})

await this.messageSender.sendMessage(outboundMessageContext)
Expand Down
11 changes: 11 additions & 0 deletions packages/anoncreds-rs/src/AnonCredsRsModuleConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export interface AnonCredsRsModuleConfigOptions {
* ```
*/
anoncreds: Anoncreds

/**
* Create a default link secret if there are no created link secrets.
* @defaultValue true
*/
autoCreateLinkSecret?: boolean
}

/**
Expand All @@ -55,4 +61,9 @@ export class AnonCredsRsModuleConfig {
public get anoncreds() {
return this.options.anoncreds
}

/** See {@link AnonCredsModuleConfigOptions.autoCreateLinkSecret} */
public get autoCreateLinkSecret() {
return this.options.autoCreateLinkSecret ?? true
}
}
17 changes: 12 additions & 5 deletions packages/anoncreds-rs/src/services/AnonCredsRsHolderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
AnonCredsRestrictionWrapper,
unqualifiedCredentialDefinitionIdRegex,
AnonCredsRegistryService,
storeLinkSecret,
} from '@aries-framework/anoncreds'
import { AriesFrameworkError, JsonTransformer, TypedArrayEncoder, injectable, utils } from '@aries-framework/core'
import {
Expand All @@ -47,6 +48,7 @@ import {
anoncreds,
} from '@hyperledger/anoncreds-shared'

import { AnonCredsRsModuleConfig } from '../AnonCredsRsModuleConfig'
import { AnonCredsRsError } from '../errors/AnonCredsRsError'

@injectable()
Expand Down Expand Up @@ -198,15 +200,20 @@ export class AnonCredsRsHolderService implements AnonCredsHolderService {
const linkSecretRepository = agentContext.dependencyManager.resolve(AnonCredsLinkSecretRepository)

// If a link secret is specified, use it. Otherwise, attempt to use default link secret
const linkSecretRecord = options.linkSecretId
let linkSecretRecord = options.linkSecretId
? await linkSecretRepository.getByLinkSecretId(agentContext, options.linkSecretId)
: await linkSecretRepository.findDefault(agentContext)

// No default link secret. Automatically create one if set on module config
if (!linkSecretRecord) {
// No default link secret
throw new AnonCredsRsError(
'No link secret provided to createCredentialRequest and no default link secret has been found'
)
const moduleConfig = agentContext.dependencyManager.resolve(AnonCredsRsModuleConfig)
if (!moduleConfig.autoCreateLinkSecret) {
throw new AnonCredsRsError(
'No link secret provided to createCredentialRequest and no default link secret has been found'
)
}
const { linkSecretId, linkSecretValue } = await this.createLinkSecret(agentContext, {})
linkSecretRecord = await storeLinkSecret(agentContext, { linkSecretId, linkSecretValue, setAsDefault: true })
}

if (!linkSecretRecord.value) {
Expand Down
27 changes: 9 additions & 18 deletions packages/anoncreds/src/AnonCredsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
AnonCredsCredentialDefinitionPrivateRepository,
AnonCredsKeyCorrectnessProofRecord,
AnonCredsKeyCorrectnessProofRepository,
AnonCredsLinkSecretRecord,
AnonCredsLinkSecretRepository,
} from './repository'
import { AnonCredsCredentialDefinitionRecord } from './repository/AnonCredsCredentialDefinitionRecord'
Expand All @@ -40,6 +39,7 @@ import {
AnonCredsIssuerServiceSymbol,
} from './services'
import { AnonCredsRegistryService } from './services/registry/AnonCredsRegistryService'
import { storeLinkSecret } from './utils'

@injectable()
export class AnonCredsApi {
Expand Down Expand Up @@ -81,30 +81,21 @@ export class AnonCredsApi {

/**
* Create a Link Secret, optionally indicating its ID and if it will be the default one
* If there is no default Link Secret, this will be set as default (even if setAsDefault is true).
* If there is no default Link Secret, this will be set as default (even if setAsDefault is false).
*
*/
public async createLinkSecret(options?: AnonCredsCreateLinkSecretOptions) {
public async createLinkSecret(options?: AnonCredsCreateLinkSecretOptions): Promise<string> {
const { linkSecretId, linkSecretValue } = await this.anonCredsHolderService.createLinkSecret(this.agentContext, {
linkSecretId: options?.linkSecretId,
})

// In some cases we don't have the linkSecretValue. However we still want a record so we know which link secret ids are valid
const linkSecretRecord = new AnonCredsLinkSecretRecord({ linkSecretId, value: linkSecretValue })

// If it is the first link secret registered, set as default
const defaultLinkSecretRecord = await this.anonCredsLinkSecretRepository.findDefault(this.agentContext)
if (!defaultLinkSecretRecord || options?.setAsDefault) {
linkSecretRecord.setTag('isDefault', true)
}

// Set the current default link secret as not default
if (defaultLinkSecretRecord && options?.setAsDefault) {
defaultLinkSecretRecord.setTag('isDefault', false)
await this.anonCredsLinkSecretRepository.update(this.agentContext, defaultLinkSecretRecord)
}
await storeLinkSecret(this.agentContext, {
linkSecretId,
linkSecretValue,
setAsDefault: options?.setAsDefault,
})

await this.anonCredsLinkSecretRepository.save(this.agentContext, linkSecretRecord)
return linkSecretId
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { agentDependencies, getAgentConfig, getAgentContext } from '../../../../
import {
IndySdkHolderService,
IndySdkIssuerService,
IndySdkModuleConfig,
IndySdkStorageService,
IndySdkVerifierService,
IndySdkWallet,
Expand Down Expand Up @@ -63,6 +64,7 @@ const agentContext = getAgentContext({
[AnonCredsRegistryService, new AnonCredsRegistryService()],
[AnonCredsModuleConfig, anonCredsModuleConfig],
[AnonCredsLinkSecretRepository, anonCredsLinkSecretRepository],
[IndySdkModuleConfig, new IndySdkModuleConfig({ indySdk, autoCreateLinkSecret: false })],
],
agentConfig,
wallet,
Expand Down
1 change: 1 addition & 0 deletions packages/anoncreds/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export * from './AnonCredsApiOptions'
export { generateLegacyProverDidLikeString } from './utils/proverDid'
export * from './utils/indyIdentifiers'
export { assertBestPracticeRevocationInterval } from './utils/revocationInterval'
export { storeLinkSecret } from './utils/linkSecret'
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,18 @@ export class V1CredentialProtocol
credentialRecord.assertProtocolVersion('v1')
credentialRecord.assertState(CredentialState.OfferSent)

const previousReceivedMessage = await didCommMessageRepository.findAgentMessage(messageContext.agentContext, {
const lastReceivedMessage = await didCommMessageRepository.findAgentMessage(messageContext.agentContext, {
associatedRecordId: credentialRecord.id,
messageClass: V1ProposeCredentialMessage,
})
const previousSentMessage = await didCommMessageRepository.getAgentMessage(messageContext.agentContext, {
const lastSentMessage = await didCommMessageRepository.getAgentMessage(messageContext.agentContext, {
associatedRecordId: credentialRecord.id,
messageClass: V1OfferCredentialMessage,
})

connectionService.assertConnectionOrServiceDecorator(messageContext, {
previousReceivedMessage,
previousSentMessage,
await connectionService.assertConnectionOrOutOfBandExchange(messageContext, {
lastReceivedMessage,
lastSentMessage,
})

await this.indyCredentialFormat.processProposal(messageContext.agentContext, {
Expand Down Expand Up @@ -257,7 +257,7 @@ export class V1CredentialProtocol
})

// Assert
connectionService.assertConnectionOrServiceDecorator(messageContext)
await connectionService.assertConnectionOrOutOfBandExchange(messageContext)

// Save record
await credentialRepository.save(messageContext.agentContext, credentialRecord)
Expand Down Expand Up @@ -506,21 +506,21 @@ export class V1CredentialProtocol
}

if (credentialRecord) {
const previousSentMessage = await didCommMessageRepository.getAgentMessage(messageContext.agentContext, {
const lastSentMessage = await didCommMessageRepository.getAgentMessage(messageContext.agentContext, {
associatedRecordId: credentialRecord.id,
messageClass: V1ProposeCredentialMessage,
})
const previousReceivedMessage = await didCommMessageRepository.findAgentMessage(messageContext.agentContext, {
const lastReceivedMessage = await didCommMessageRepository.findAgentMessage(messageContext.agentContext, {
associatedRecordId: credentialRecord.id,
messageClass: V1OfferCredentialMessage,
})

// Assert
credentialRecord.assertProtocolVersion('v1')
credentialRecord.assertState(CredentialState.ProposalSent)
connectionService.assertConnectionOrServiceDecorator(messageContext, {
previousReceivedMessage,
previousSentMessage,
await connectionService.assertConnectionOrOutOfBandExchange(messageContext, {
lastReceivedMessage,
lastSentMessage,
})

await this.indyCredentialFormat.processOffer(messageContext.agentContext, {
Expand All @@ -546,7 +546,7 @@ export class V1CredentialProtocol
})

// Assert
connectionService.assertConnectionOrServiceDecorator(messageContext)
await connectionService.assertConnectionOrOutOfBandExchange(messageContext)

await this.indyCredentialFormat.processOffer(messageContext.agentContext, {
credentialRecord,
Expand Down Expand Up @@ -750,9 +750,9 @@ export class V1CredentialProtocol
// Assert
credentialRecord.assertProtocolVersion('v1')
credentialRecord.assertState(CredentialState.OfferSent)
connectionService.assertConnectionOrServiceDecorator(messageContext, {
previousReceivedMessage: proposalMessage ?? undefined,
previousSentMessage: offerMessage ?? undefined,
await connectionService.assertConnectionOrOutOfBandExchange(messageContext, {
lastReceivedMessage: proposalMessage ?? undefined,
lastSentMessage: offerMessage ?? undefined,
})

const requestAttachment = requestMessage.getRequestAttachmentById(INDY_CREDENTIAL_REQUEST_ATTACHMENT_ID)
Expand Down Expand Up @@ -886,9 +886,9 @@ export class V1CredentialProtocol
// Assert
credentialRecord.assertProtocolVersion('v1')
credentialRecord.assertState(CredentialState.RequestSent)
connectionService.assertConnectionOrServiceDecorator(messageContext, {
previousReceivedMessage: offerCredentialMessage,
previousSentMessage: requestCredentialMessage,
await connectionService.assertConnectionOrOutOfBandExchange(messageContext, {
lastReceivedMessage: offerCredentialMessage,
lastSentMessage: requestCredentialMessage,
})

const issueAttachment = issueMessage.getCredentialAttachmentById(INDY_CREDENTIAL_ATTACHMENT_ID)
Expand Down Expand Up @@ -981,9 +981,9 @@ export class V1CredentialProtocol
// Assert
credentialRecord.assertProtocolVersion('v1')
credentialRecord.assertState(CredentialState.CredentialIssued)
connectionService.assertConnectionOrServiceDecorator(messageContext, {
previousReceivedMessage: requestCredentialMessage,
previousSentMessage: issueCredentialMessage,
await connectionService.assertConnectionOrOutOfBandExchange(messageContext, {
lastReceivedMessage: requestCredentialMessage,
lastSentMessage: issueCredentialMessage,
})

// Update record
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const credentialIssueMessage = new V1IssueCredentialMessage({

const didCommMessageRecord = new DidCommMessageRecord({
associatedRecordId: '04a2c382-999e-4de9-a1d2-9dec0b2fa5e4',
message: {},
message: { '@id': '123', '@type': 'https://didcomm.org/issue-credential/1.0/offer-credential' },
role: DidCommMessageRole.Receiver,
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ describe('V1 Connectionless Credentials', () => {
protocolVersion: 'v1',
})

const { message: offerMessage } = await faberAgent.oob.createLegacyConnectionlessInvitation({
const { invitationUrl } = await faberAgent.oob.createLegacyConnectionlessInvitation({
recordId: faberCredentialRecord.id,
message,
domain: 'https://a-domain.com',
})

await aliceAgent.receiveMessage(offerMessage.toJSON())
await aliceAgent.oob.receiveInvitationFromUrl(invitationUrl)

let aliceCredentialRecord = await waitForCredentialRecordSubject(aliceReplay, {
threadId: faberCredentialRecord.threadId,
Expand Down Expand Up @@ -162,7 +162,6 @@ describe('V1 Connectionless Credentials', () => {
})

const { message: offerMessage } = await faberAgent.oob.createLegacyConnectionlessInvitation({
recordId: faberCredentialRecord.id,
message,
domain: 'https://a-domain.com',
})
Expand Down
Loading

0 comments on commit 3b8e9bb

Please sign in to comment.