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 contracts - Need help with proxy #76

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions network/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"universalDidResolver": {
"specPath": "smart_contracts/artifacts/contracts/migration/UniversalDidResolver.sol/UniversalDidResolver.json",
"address": "0x000000000000000000000000000000000019999"
},
"revocationRegistry": {
"specPath": "smart_contracts/artifacts/contracts/revoke/RevocationRegistry.sol/RevocationRegistry.json",
"address": "0x0000000000000000000000000000000000021111"
}
}
}
17 changes: 16 additions & 1 deletion network/config/besu/genesis.json

Large diffs are not rendered by default.

119 changes: 119 additions & 0 deletions smart_contracts/contracts-ts/RevocationRegistry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { concat, getBytes, keccak256, Signature, toUtf8Bytes, toUtf8String } from 'ethers'
import { RevocationMetadataStruct } from '../typechain-types/contracts/revoke/RevocationRegistry'
import { Contract } from '../utils/contract'

export type RevocationRecord = {
revocationRecord: any
revocation: string
metadata: RevocationMetadataStruct
}

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

public async createRevocationRegistry(
identity: string,
CredDefId: string,
revocationRegistryId: string,
revocationDocumente: string,
) {
const tx = await this.instance.createRevocationRegistry(
identity,
keccak256(toUtf8Bytes(CredDefId)),
keccak256(toUtf8Bytes(revocationRegistryId)),
toUtf8Bytes(revocationDocumente),
)
return tx.wait()
}

public async createCredentialDefinitionSigned(
identity: string,
CredDefId: string,
revocationRegistryId: string,
revocationDocumente: string,
signature: Signature,
) {
const tx = await this.instance.createRevocationRegistrySigned(
identity,
signature.v,
signature.r,
signature.s,
keccak256(toUtf8Bytes(CredDefId)),
keccak256(toUtf8Bytes(revocationRegistryId)),
toUtf8Bytes(revocationDocumente),
)
return tx.wait()
}

public async resolveRevocation(id: string): Promise<RevocationRecord> {
const record = await this.instance.resolveRevocation(keccak256(toUtf8Bytes(id)))
return record.metadata.status
}

public signCreateRevocationWithEndorsementData(
identity: string,
privateKey: Uint8Array,
id: string,
revocation: string,
) {
return this.signEndorsementData(
privateKey,
concat([
identity,
toUtf8Bytes('createRevocationRegistry'),
getBytes(keccak256(toUtf8Bytes(id)), 'hex'),
toUtf8Bytes(revocation),
]),
)
}

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

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

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

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

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

public async unrevokeCredentialSigned(identity: string, signature: Signature, id: string) {
const tx = await this.instance.unrevokeCredentialSigned(
identity,
signature.v,
signature.r,
signature.s,
keccak256(toUtf8Bytes(id)),
)
return tx.wait()
}
}
1 change: 1 addition & 0 deletions smart_contracts/contracts-ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './UniversalDidReolver'
export * from './UpgradeControl'
export * from './ValidatorControl'
export * from './LegacyMappingRegistry'
export * from './RevocationRegistry'
50 changes: 50 additions & 0 deletions smart_contracts/contracts/anoncreds/AnoncredsErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,53 @@ error CredentialDefinitionAlreadyExist(bytes32 id);
* @param id Keccak hash of Credential definition ID.
*/
error CredentialDefinitionNotFound(bytes32 id);

// Revocation errors

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

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

/**
* @notice Error that occurs when trying to revoke a credential without being listed in the Revocation registry.
* @param id Keccak hash of Revocation ID.
*/
error RevocationDoesntExist(bytes32 id);

/**
* @notice Error that occurs when attempting to perform an operation on a revocation that is not active.
* @param id Keccak hash of Revocation ID.
*/
error RevocationIsNotActived(bytes32 id);

/**
* @notice Error that occurs when attempting to perform an operation on a revocation that is not suspended.
* @param id Keccak hash of Revocation ID.
*/
error RevocationIsNotsuspended(bytes32 id);

/**
* @notice Error that occurs when attempting to perform an operation on a revocation that is not revoked.
* @param id Keccak hash of Revocation ID.
*/
error RevocationIsNotRevoked(bytes32 id);

/**
* @notice Error that occurs when attempting to revoke a credential that is already revoked.
* @param id Keccak hash of Credential ID.
*/
error CredentialIsAlreadyRevoked(bytes32 id);

/**
* @notice Error that occurs when the specified issuer is invalid.
* @param id Keccak hash of Issuer ID.
*/
error InvalidIssuer(bytes32 id);
Loading