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

Revocation registry #108

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
90 changes: 47 additions & 43 deletions network/config.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,50 @@
{
"chainId": 1337,
"nodeAddress": "http://127.0.0.1:8545",
"contracts": {
"validatorControl": {
"specPath": "smart_contracts/artifacts/contracts/network/ValidatorControl.sol/ValidatorControl.json",
"address": "0x0000000000000000000000000000000000007777"
},
"accountControl": {
"specPath": "smart_contracts/artifacts/contracts/auth/AccountControl.sol/AccountControl.json",
"address": "0x0000000000000000000000000000000000008888"
},
"roleControl": {
"specPath": "smart_contracts/artifacts/contracts/auth/RoleControl.sol/RoleControl.json",
"address": "0x0000000000000000000000000000000000006666"
},
"upgradeControl": {
"specPath": "smart_contracts/artifacts/contracts/upgrade/UpgradeControl.sol/UpgradeControl.json",
"address": "0x0000000000000000000000000000000000009999"
},
"ethereumDidRegistry": {
"specPath": "smart_contracts/artifacts/contracts/did/EthereumExtDidRegistry.sol/EthereumExtDidRegistry.json",
"address": "0x0000000000000000000000000000000000018888"
},
"indyDidRegistry": {
"specPath": "smart_contracts/artifacts/contracts/did/IndyDidRegistry.sol/IndyDidRegistry.json",
"address": "0x0000000000000000000000000000000000003333"
},
"schemaRegistry": {
"specPath": "smart_contracts/artifacts/contracts/anoncreds/SchemaRegistry.sol/SchemaRegistry.json",
"address": "0x0000000000000000000000000000000000005555"
},
"credDefRegistry": {
"specPath": "smart_contracts/artifacts/contracts/anoncreds/CredentialDefinitionRegistry.sol/CredentialDefinitionRegistry.json",
"address": "0x0000000000000000000000000000000000004444"
},
"legacyMappingRegistry": {
"specPath": "smart_contracts/artifacts/contracts/migration/LegacyMappingRegistry.sol/LegacyMappingRegistry.json",
"address": "0x0000000000000000000000000000000000017777"
},
"universalDidResolver": {
"specPath": "smart_contracts/artifacts/contracts/migration/UniversalDidResolver.sol/UniversalDidResolver.json",
"address": "0x000000000000000000000000000000000019999"
}
"chainId": 1337,
"nodeAddress": "http://127.0.0.1:8545",
"contracts": {
"validatorControl": {
"specPath": "smart_contracts/artifacts/contracts/network/ValidatorControl.sol/ValidatorControl.json",
"address": "0x0000000000000000000000000000000000007777"
},
"accountControl": {
"specPath": "smart_contracts/artifacts/contracts/auth/AccountControl.sol/AccountControl.json",
"address": "0x0000000000000000000000000000000000008888"
},
"roleControl": {
"specPath": "smart_contracts/artifacts/contracts/auth/RoleControl.sol/RoleControl.json",
"address": "0x0000000000000000000000000000000000006666"
},
"upgradeControl": {
"specPath": "smart_contracts/artifacts/contracts/upgrade/UpgradeControl.sol/UpgradeControl.json",
"address": "0x0000000000000000000000000000000000009999"
},
"ethereumDidRegistry": {
"specPath": "smart_contracts/artifacts/contracts/did/EthereumExtDidRegistry.sol/EthereumExtDidRegistry.json",
"address": "0x0000000000000000000000000000000000018888"
},
"indyDidRegistry": {
"specPath": "smart_contracts/artifacts/contracts/did/IndyDidRegistry.sol/IndyDidRegistry.json",
"address": "0x0000000000000000000000000000000000003333"
},
"schemaRegistry": {
"specPath": "smart_contracts/artifacts/contracts/anoncreds/SchemaRegistry.sol/SchemaRegistry.json",
"address": "0x0000000000000000000000000000000000005555"
},
"credDefRegistry": {
"specPath": "smart_contracts/artifacts/contracts/anoncreds/CredentialDefinitionRegistry.sol/CredentialDefinitionRegistry.json",
"address": "0x0000000000000000000000000000000000004444"
},
"legacyMappingRegistry": {
"specPath": "smart_contracts/artifacts/contracts/migration/LegacyMappingRegistry.sol/LegacyMappingRegistry.json",
"address": "0x0000000000000000000000000000000000017777"
},
"universalDidResolver": {
"specPath": "smart_contracts/artifacts/contracts/migration/UniversalDidResolver.sol/UniversalDidResolver.json",
"address": "0x000000000000000000000000000000000019999"
},
"revocationRegistry": {
"specPath": "smart_contracts/artifacts/contracts/anoncreds/RevocationRegistry.sol/RevocationRegistry.json",
"address": "0x0000000000000000000000000000000000002222"
}
}
}
2 changes: 1 addition & 1 deletion network/config/nodes/validator5/key
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0x40b6b9dc85d45b8bd1d8edc548ace4e5fd6c705bbf28a509f12791777b6b8843
0xe638e254e3d07ddc7a1332078f9ab1e41144b6c990149d5c882a50389b6e272a
117 changes: 117 additions & 0 deletions smart_contracts/contracts-ts/RevocationRegistry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* Copyright (c) 2024 DSR Corporation, Denver, Colorado.
* https://www.dsr-corporation.com
* SPDX-License-Identifier: Apache-2.0
*/

import { AbiCoder, concat, getBytes, keccak256, Signature, solidityPacked, toUtf8Bytes, toUtf8String } from 'ethers'
import {
RevocationRegistryDefinitionMetadataStruct,
RevocationRegistryEntryStruct,
} from '../typechain-types/contracts/anoncreds/RevocationRegistry'
import { Contract } from '../utils/contract'

export type RevocationRegistryDefinitionRecord = {
revRegDef: string
metadata: RevocationRegistryDefinitionMetadataStruct
}

export class RevocationRegistry extends Contract {
constructor(sender?: any) {
super(RevocationRegistry.name, sender)
}

public async createRevocationRegistryDefinition(
identity: string,
id: string,
credDefId: string,
issuerId: string,
revRegDef: string,
) {
const tx = await this.instance.createRevocationRegistryDefinition(
identity,
keccak256(toUtf8Bytes(id)),
keccak256(toUtf8Bytes(credDefId)),
issuerId,
toUtf8Bytes(revRegDef),
)
return tx.wait()
}

public async createRevocationRegistryDefinitionSigned(
identity: string,
id: string,
credDefId: string,
issuerId: string,
revRegDef: string,
signature: Signature,
) {
const tx = await this.instance.createRevocationRegistryDefinitionSigned(
identity,
signature.v,
signature.r,
signature.s,
keccak256(toUtf8Bytes(id)),
keccak256(toUtf8Bytes(credDefId)),
issuerId,
toUtf8Bytes(revRegDef),
)
return tx.wait()
}

public async createRevocationRegistryEntry(
identity: string,
revRegId: string,
issuerId: string,
revRegEntry: RevocationRegistryEntryStruct,
) {
const tx = await this.instance.createRevocationRegistryEntry(
identity,
keccak256(toUtf8Bytes(revRegId)),
issuerId,
revRegEntry,
)
return tx.wait()
}

public async resolveRevocationRegistryDefinition(id: string): Promise<RevocationRegistryDefinitionRecord> {
const record = await this.instance.resolveRevocationRegistryDefinition(keccak256(toUtf8Bytes(id)))
return {
revRegDef: toUtf8String(getBytes(record.revRegDef)),
metadata: {
created: record.metadata.created,
issuerId: record.metadata.issuerId,
currentAccumulator: record.metadata.currentAccumulator,
},
}
}

public async fetchAllRevocationEntries(id: string): Promise<RevocationRegistryEntryStruct[]> {
const eventLogs = await this.instance.queryFilter(
this.instance.filters.RevocationRegistryEntryCreated(keccak256(toUtf8Bytes(id))),
)
const revRegEntries = eventLogs.map((log) => log.args.revRegEntry.toObject(true))
return revRegEntries
}

public signCreateRevRegDefEndorsementData(
identity: string,
privateKey: Uint8Array,
id: string,
credDefId: string,
issuerId: string,
revRegDef: string,
) {
return this.signEndorsementData(
privateKey,
concat([
identity,
toUtf8Bytes('createRevocationRegistryDefinition'),
getBytes(keccak256(toUtf8Bytes(id)), 'hex'),
getBytes(keccak256(toUtf8Bytes(credDefId)), 'hex'),
toUtf8Bytes(issuerId),
getBytes(toUtf8Bytes(revRegDef), 'hex'),
]),
)
}
}
1 change: 1 addition & 0 deletions smart_contracts/contracts-ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export * from './UniversalDidReolver'
export * from './UpgradeControl'
export * from './ValidatorControl'
export * from './LegacyMappingRegistry'
export * from './RevocationRegistry'
26 changes: 26 additions & 0 deletions smart_contracts/contracts/anoncreds/AnoncredsErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,29 @@ error CredentialDefinitionAlreadyExist(bytes32 id);
* @param id Keccak hash of Credential definition ID.
*/
error CredentialDefinitionNotFound(bytes32 id);

// RevReg errors

/**
* @notice Error that occurs when the new previous Accumulator in Revocation Registry Entry does not match current Ledger Accumulator
* @param accumulator Current Ledger Accumulator.
*/
error AccumulatorMismatch(bytes accumulator);

/**
* @notice Error that occurs when attempting to perform an operation on Revocation Registries while not being the Revocation Registry Definition Iusser.
* @param did Issuer DID.
*/
error NotRevocationRegistryDefinitionIssuer(string did);

/**
* @notice Error that occurs when trying to create a revocation registry definition with already existing identifier.
* @param id Keccak hash of Credential definition ID.
*/
error RevocationRegistryDefinitionAlreadyExist(bytes32 id);

/**
* @notice Error that occurs when the specified revocation registry definition is not found.
* @param id Keccak hash of Revocation Registry definition ID.
*/
error RevocationRegistryDefinitionNotFound(bytes32 id);
Loading