Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(anoncreds): pass along options for registry and status list #1734

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 33 additions & 18 deletions packages/anoncreds/src/AnonCredsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,9 @@ export class AnonCredsApi {
}
}

public async registerRevocationRegistryDefinition(options: {
revocationRegistryDefinition: AnonCredsRegisterRevocationRegistryDefinitionOptions
options: Extensible
}): Promise<RegisterRevocationRegistryDefinitionReturn> {
public async registerRevocationRegistryDefinition<T extends Extensible = Extensible>(
options: AnonCredsRegisterRevocationRegistryDefinition<T>
): Promise<RegisterRevocationRegistryDefinitionReturn> {
const { issuerId, tag, credentialDefinitionId, maximumCredentialNumber } = options.revocationRegistryDefinition

const tailsFileService = this.agentContext.dependencyManager.resolve(AnonCredsModuleConfig).tailsFileService
Expand Down Expand Up @@ -409,8 +408,9 @@ export class AnonCredsApi {

const result = await registry.registerRevocationRegistryDefinition(this.agentContext, {
revocationRegistryDefinition,
options: {},
options: options.options,
})

await this.storeRevocationRegistryDefinitionRecord(result, revocationRegistryDefinitionPrivate)

return {
Expand Down Expand Up @@ -465,10 +465,9 @@ export class AnonCredsApi {
}
}

public async registerRevocationStatusList(options: {
revocationStatusList: AnonCredsRegisterRevocationStatusListOptions
options: Extensible
}): Promise<RegisterRevocationStatusListReturn> {
public async registerRevocationStatusList<T extends Extensible = Extensible>(
options: AnonCredsRegisterRevocationStatusList<T>
): Promise<RegisterRevocationStatusListReturn> {
const { issuerId, revocationRegistryDefinitionId } = options.revocationStatusList

const failedReturnBase = {
Expand Down Expand Up @@ -510,7 +509,7 @@ export class AnonCredsApi {

const result = await registry.registerRevocationStatusList(this.agentContext, {
revocationStatusList,
options: {},
options: options.options,
})

return result
Expand All @@ -526,23 +525,24 @@ export class AnonCredsApi {
}
}

public async updateRevocationStatusList(
options: AnonCredsUpdateRevocationStatusListOptions
public async updateRevocationStatusList<T extends Extensible = Extensible>(
options: AnonCredsUpdateRevocationStatusList<T>
): Promise<RegisterRevocationStatusListReturn> {
const { issuedCredentialIndexes, revokedCredentialIndexes, revocationRegistryDefinitionId } = options
const { issuedCredentialIndexes, revokedCredentialIndexes, revocationRegistryDefinitionId } =
options.revocationStatusList

const failedReturnBase = {
revocationStatusListState: {
state: 'failed' as const,
reason: `Error updating revocation status list for revocation registry definition id ${options.revocationRegistryDefinitionId}`,
reason: `Error updating revocation status list for revocation registry definition id ${options.revocationStatusList.revocationRegistryDefinitionId}`,
},
registrationMetadata: {},
revocationStatusListMetadata: {},
}

const registry = this.findRegistryForIdentifier(options.revocationRegistryDefinitionId)
const registry = this.findRegistryForIdentifier(options.revocationStatusList.revocationRegistryDefinitionId)
if (!registry) {
failedReturnBase.revocationStatusListState.reason = `Unable to update revocation status list. No registry found for id ${options.revocationRegistryDefinitionId}`
failedReturnBase.revocationStatusListState.reason = `Unable to update revocation status list. No registry found for id ${options.revocationStatusList.revocationRegistryDefinitionId}`
return failedReturnBase
}

Expand All @@ -562,7 +562,7 @@ export class AnonCredsApi {
)

if (!previousRevocationStatusList) {
failedReturnBase.revocationStatusListState.reason = `Unable to update revocation status list. No previous revocation status list found for ${options.revocationRegistryDefinitionId}`
failedReturnBase.revocationStatusListState.reason = `Unable to update revocation status list. No previous revocation status list found for ${options.revocationStatusList.revocationRegistryDefinitionId}`
return failedReturnBase
}

Expand All @@ -582,7 +582,7 @@ export class AnonCredsApi {

const result = await registry.registerRevocationStatusList(this.agentContext, {
revocationStatusList,
options: {},
options: options.options,
})

return result
Expand Down Expand Up @@ -771,6 +771,21 @@ interface AnonCredsRegisterSchema<T extends Extensible = Extensible> {
options: T
}

interface AnonCredsRegisterRevocationRegistryDefinition<T extends Extensible = Extensible> {
revocationRegistryDefinition: AnonCredsRegisterRevocationRegistryDefinitionOptions
options: T
}

interface AnonCredsRegisterRevocationStatusList<T extends Extensible = Extensible> {
revocationStatusList: AnonCredsRegisterRevocationStatusListOptions
options: T
}

interface AnonCredsUpdateRevocationStatusList<T extends Extensible = Extensible> {
revocationStatusList: AnonCredsUpdateRevocationStatusListOptions
options: T
}

function isFullCredentialDefinitionInput(
credentialDefinition: AnonCredsRegisterCredentialDefinitionOptions
): credentialDefinition is AnonCredsCredentialDefinition {
Expand Down
7 changes: 5 additions & 2 deletions packages/anoncreds/tests/v2-credential-revocation.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,11 @@ describe('IC v2 credential revocation', () => {
expect(credentialRevocationRegistryDefinitionId).toEqual(revocationRegistryDefinitionId)

await faberAgent.modules.anoncreds.updateRevocationStatusList({
revocationRegistryDefinitionId: credentialRevocationRegistryDefinitionId,
revokedCredentialIndexes: [Number(credentialRevocationIndex)],
revocationStatusList: {
revocationRegistryDefinitionId: credentialRevocationRegistryDefinitionId,
revokedCredentialIndexes: [Number(credentialRevocationIndex)],
},
options: {},
})

await faberAgent.credentials.sendRevocationNotification({
Expand Down
14 changes: 10 additions & 4 deletions packages/anoncreds/tests/v2-proofs.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,11 @@ describe('PP V2 AnonCreds Proofs', () => {
// InMemoryAnonCredsRegistry would respect what we ask while actual VDRs will use their own
await sleep(2000)
await faberAgent.modules.anoncreds.updateRevocationStatusList({
revocationRegistryDefinitionId: credentialRevocationRegistryDefinitionId,
revokedCredentialIndexes: [Number(credentialRevocationIndex)],
revocationStatusList: {
revocationRegistryDefinitionId: credentialRevocationRegistryDefinitionId,
revokedCredentialIndexes: [Number(credentialRevocationIndex)],
},
options: {},
})

await aliceAgent.proofs.acceptRequest({
Expand Down Expand Up @@ -906,8 +909,11 @@ describe('PP V2 AnonCreds Proofs', () => {
expect(credentialRevocationIndex).toBeDefined()

const { revocationStatusListState } = await faberAgent.modules.anoncreds.updateRevocationStatusList({
revocationRegistryDefinitionId: credentialRevocationRegistryDefinitionId,
revokedCredentialIndexes: [Number(credentialRevocationIndex)],
revocationStatusList: {
revocationRegistryDefinitionId: credentialRevocationRegistryDefinitionId,
revokedCredentialIndexes: [Number(credentialRevocationIndex)],
},
options: {},
})

expect(revocationStatusListState.revocationStatusList).toBeDefined()
Expand Down
Loading