Skip to content

Commit

Permalink
Merge pull request #197 from alastria/feature/credentialRegistryTrans…
Browse files Browse the repository at this point in the history
…actionFactory

Feature/credential registry transaction factory
  • Loading branch information
DaniRumpi authored Nov 11, 2024
2 parents 725782c + fdeaba7 commit 62e6867
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 65 deletions.
57 changes: 50 additions & 7 deletions src/txFactory/credentialRegistryTransactionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { config } from '../config'
import { AIdUtils } from '../utils/AIdUtils'

/**
* THIS METHOD WILL BE DEPREATED, USE INSTEAD updateSubjectCredential
* function addSubjectCredential(web3, subjectCredentialHash, URI)
* Dev: get delegated invoke addSubjectCredential transaction object
* @param web3 ethereum connection
* @param subjectCredentialHash should have 32 bytes, credential identification
* @param URI url for store the credentials for backup
*/
export function addSubjectCredential(web3, subjectCredentialHash, URI) {
const transaction = Object.assign({}, config.basicTransaction)
Expand All @@ -20,6 +22,26 @@ export function addSubjectCredential(web3, subjectCredentialHash, URI) {
}

/**
* function updateSubjectCredential(web3, subjectCredentialHash, status)
* Dev: get delegated invoke updateSubjectCredential transaction object
* @param web3 ethereum connection
* @param subjectCredentialHash should have 32 bytes, credential identification
* @param status uint that indicates the status of the credential
*/
export function updateSubjectCredential(web3, subjectCredentialHash, status) {
const transaction = Object.assign({}, config.basicTransaction)
const delegatedData = web3.eth.abi.encodeFunctionCall(
config.contractsAbi.AlastriaCredentialRegistry.updateSubjectCredential,
[subjectCredentialHash, status]
)
transaction.data = delegated(web3, delegatedData)
transaction.to = config.alastriaIdentityManager // When delegated, target is alastriaIdentityManager
transaction.gasLimit = 600000
return transaction
}

/**
* THIS METHOD WILL BE DEPREATED, USE INSTEAD updateIssuerCredential
* function addIssuerCredential(web3, issuerCredentialHash)
* Dev: get delegated invoke addIssuerCredential transaction object
* @param web3 ethereum connection
Expand All @@ -38,6 +60,7 @@ export function addIssuerCredential(web3, issuerCredentialHash) {
}

/**
* THIS METHOD WILL BE DEPREATED, USE INSTEAD updateSubjectCredential
* function deleteSubjectCredential(web3, subjectCredentialHash)
* Dev: get delegated invoke deleteSubjectCredential transaction object
* @param web3 ethereum connection
Expand Down Expand Up @@ -79,10 +102,11 @@ export function getSubjectCredentialStatus(
}

/**
* THIS METHOD WILL BE DEPREATED, USE INSTEAD updateIssuerCredential
* function updateCredentialStatus(web3, issuerCredentialHash, status)
* @param web3
* @param issuerCredentialHash
* @param status
* @param web3 ethereum connection
* @param issuerCredentialHash should have 32 bytes
* @param status uint that indicates the status of the credential
*/
export function updateCredentialStatus(web3, issuerCredentialHash, status) {
const transaction = Object.assign({}, config.basicTransaction)
Expand All @@ -96,12 +120,30 @@ export function updateCredentialStatus(web3, issuerCredentialHash, status) {
return transaction
}

/**
* function updateIssuerCredential(web3, issuerCredentialHash, status)
* @param web3 ethereum connection
* @param issuerCredentialHash should have 32 bytes
* @param status uint that indicates the status of the credential
*/
export function updateIssuerCredential(web3, issuerCredentialHash, status) {
const transaction = Object.assign({}, config.basicTransaction)
const delegatedData = web3.eth.abi.encodeFunctionCall(
config.contractsAbi.AlastriaCredentialRegistry.updateIssuerCredential,
[issuerCredentialHash, status]
)
transaction.data = delegated(web3, delegatedData)
transaction.to = config.alastriaIdentityManager
transaction.gasLimit = 600000
return transaction
}

/**
* Dev: get the invoke updateCredentialStatus transaction object
* function getIssuerCredentialStatus(address issuer, bytes32 issuerCredentialHash) view public validAddress(issuer) returns (bool exists, Status status)
* @param web3 ethereum connection
* @param didIssuer
* @param issuerCredentialHash
* @param didIssuer alastria Id
* @param issuerCredentialHash should have 32 bytes
*/
export function getIssuerCredentialStatus(
web3,
Expand All @@ -120,10 +162,11 @@ export function getIssuerCredentialStatus(
}

/**
* THIS METHOD WILL BE DEPREATED
* Dev: Defining three status functions avoid linking the subject to the issuer or the corresponding hashes
* @param web3 ethereum connection
* @param subjectStatus
* @param issuerStatus
* @param subjectStatus uint that indicates the status of the credential for subject
* @param issuerStatus uint that indicates the status of the credential for issuer
*/
export function getCredentialStatus(web3, subjectStatus, issuerStatus) {
const transaction = Object.assign({}, config.basicTransaction)
Expand Down
37 changes: 23 additions & 14 deletions src/txFactory/presentationRegistryTransactionFactory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { config } from '../config'
import { AIdUtils } from '../utils/AIdUtils'

/**
* THIS METHOD WILL BE DEPREATED, USE INSTEAD updateSubjectPresentation
* Subject functions
* function addSubjectPresentation(web3, subjectPresentationHash, URI)
* @param web3 ethereum connection
* @param subjectPresentationHash should have 32 bytes
* @param URI url for store the presentations for backup
*/
export function addSubjectPresentation(web3, subjectPresentationHash, URI) {
const transaction = Object.assign({}, config.basicTransaction)
const delegatedData = web3.eth.abi.encodeFunctionCall(
Expand All @@ -16,8 +24,8 @@ export function addSubjectPresentation(web3, subjectPresentationHash, URI) {
/**
* Subject functions
* function updateSubjectPresentation(bytes32 subjectPresentationHash, Status status) public validStatus(status)
* @param web3
* @param subjectPresentationHash
* @param web3 ethereum connection
* @param subjectPresentationHash should have 32 bytes
*/
export function updateSubjectPresentation(
web3,
Expand All @@ -39,9 +47,9 @@ export function updateSubjectPresentation(
* If the Presentation does not exists the return is a void Presentation
* If we want a log, should we add an event?
* function getSubjectPresentationStatus(address subject, bytes32 subjectPresentationHash) view public validAddress(subject) returns(bool exists, Status status)
* @param web3
* @param didSubject
* @param subsubjectPresentationHashject
* @param web3 ethereum connection
* @param didSubject alastria Id
* @param subsubjectPresentationHashject should have 32 bytes
*/
export function getSubjectPresentationStatus(
web3,
Expand All @@ -63,9 +71,9 @@ export function getSubjectPresentationStatus(
/**
* Receiver functions
* function updateReceiverPresentation(bytes32 receiverPresentationHash, Status status) public validStatus(status)
* @param web3
* @param receiverPresentationHash
* @param status
* @param web3 ethereum connection
* @param receiverPresentationHash should have 32 bytes
* @param status uint that indicates the status of the presentation
*/
export function updateReceiverPresentation(
web3,
Expand All @@ -87,9 +95,9 @@ export function updateReceiverPresentation(
* If the Presentation does not exists the return is a void Presentation
* If we want a log, should we add an event?
* function getReceiverPresentationStatus(address receiver, bytes32 receiverPresentationHash) view public validAddress(receiver) returns(bool exists, Status status) {
* @param web3
* @param didReceiver
* @param receiverPresentationHash
* @param web3 ethereum connection
* @param didReceiver alastria Id
* @param receiverPresentationHash should have 32 bytes
*/
export function getReceiverPresentationStatus(
web3,
Expand All @@ -109,12 +117,13 @@ export function getReceiverPresentationStatus(
}

/**
* THIS METHOD WILL BE DEPREATED
* Utility function
* Defining three status functions avoids linking the Subject to the Receiver or the corresponding hashes
* function getPresentationStatus(Status subjectStatus, Status receiverStatus) pure public validStatus(subjectStatus) validStatus(receiverStatus) returns(Status){
* @param web3
* @param subjectStatus
* @param receiverStatus
* @param web3 ethereum connection
* @param subjectStatus uint that indicates the status of the presentation for subject
* @param receiverStatus uint that indicates the status of the presentation for receiver
*/
export function getPresentationStatus(web3, subjectStatus, receiverStatus) {
const transaction = Object.assign({}, config.basicTransaction)
Expand Down
71 changes: 30 additions & 41 deletions src/txFactory/publicKeyRegistryTransactionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { AIdUtils } from '../utils/AIdUtils'
import { AddressUtils } from '../utils/AddressUtils'

/**
* THIS METHOD WILL BE DEPREATED
* function addKey(string memory publicKey, address subject) public
* @param web3
* @param publicKey
* THIS METHOD WILL BE DEPREATED, USE INSTEAD addPublicKey
* function addKey(string memory publicKey) public
* @param web3 ethereum connection
* @param publicKey the public key.
*/
export function addKey(web3, publicKey) {
const transaction = Object.assign({}, config.basicTransaction)
Expand All @@ -21,8 +21,9 @@ export function addKey(web3, publicKey) {
}

/**
* @param web3
* @param publicKeyHash
* function addPublicKey(bytes32 publicKeyHash) public
* @param web3 ethereum connection
* @param publicKeyHash the hash of the publickey. should have 32 bytes
*/
export function addPublicKey(web3, publicKeyHash) {
const transaction = Object.assign({}, config.basicTransaction)
Expand All @@ -37,9 +38,10 @@ export function addPublicKey(web3, publicKeyHash) {
}

/**
* THIS METHOD WILL BE DEPREATED
* @param web3
* @param publicKey
* THIS METHOD WILL BE DEPREATED, USE INSTEAD revokePublicKeyHash
* function revokePublicKey(string memory publicKey) public
* @param web3 ethereum connection
* @param publicKey the public key.
*/
export function revokePublicKey(web3, publicKey) {
const transaction = Object.assign({}, config.basicTransaction)
Expand All @@ -54,8 +56,9 @@ export function revokePublicKey(web3, publicKey) {
}

/**
* @param web3
* @param publicKeyHash
* function revokePublicKey(bytes32 publicKeyHash) public
* @param web3 ethereum connection
* @param publicKeyHash the hash of the publickey. should have 32 bytes
*/
export function revokePublicKeyHash(web3, publicKeyHash) {
const transaction = Object.assign({}, config.basicTransaction)
Expand All @@ -70,9 +73,10 @@ export function revokePublicKeyHash(web3, publicKeyHash) {
}

/**
* THIS METHOD WILL BE DEPREATED
* @param web3
* @param publicKey
* THIS METHOD WILL BE DEPREATED, USE INSTEAD deletePublicKeyHash
* function deletePublicKey(string memory publicKey) public
* @param web3 ethereum connection
* @param publicKey the public key.
*/
export function deletePublicKey(web3, publicKey) {
const transaction = Object.assign({}, config.basicTransaction)
Expand All @@ -87,8 +91,9 @@ export function deletePublicKey(web3, publicKey) {
}

/**
* @param web3
* @param publicKeyHash
* function deletePublicKey(bytes32 publicKeyHash) public
* @param web3 ethereum connection
* @param publicKeyHash the hash of the publickey. should have 32 bytes
*/
export function deletePublicKeyHash(web3, publicKeyHash) {
const transaction = Object.assign({}, config.basicTransaction)
Expand All @@ -103,9 +108,10 @@ export function deletePublicKeyHash(web3, publicKeyHash) {
}

/**
* THIS METHOD WILL BE DEPREATED
* @param web3
* @param did
* THIS METHOD WILL BE DEPREATED, USE INSTEAD getPublicKeyStatusHash
* function getCurrentPublicKey(address subject) view public
* @param web3 ethereum connection
* @param did alastri Id
*/
export function getCurrentPublicKey(web3, did) {
const subjectAddr = AIdUtils.getProxyAddress(did)
Expand All @@ -120,29 +126,12 @@ export function getCurrentPublicKey(web3, did) {
}

/**
* THIS METHOD WILL BE DEPREATED
* @param web3
* @param did
* @param publicKey
* function getPublicKeyStatus(address subject, bytes32 publicKeyHash) view public
* @param web3 ethereum connection
* @param did alastri Id
* @param publicKeyHash the hash of the publickey. should have 32 bytes
*/
export function getPublicKeyStatus(web3, did, publicKey) {
const subjectAddr = AIdUtils.getProxyAddress(did)
const transaction = Object.assign({}, config.basicTransaction)
transaction.data = web3.eth.abi.encodeFunctionCall(
config.contractsAbi.AlastriaPublicKeyRegistry.getPublicKeyStatus,
[subjectAddr, AddressUtils.getAddressWithoutHexPrefix(publicKey)]
)
transaction.to = config.alastriaPublicKeyRegistry
transaction.gasLimit = 600000
return transaction
}

/**
* @param web3
* @param did
* @param publicKeyHash
*/
export function getPublicKeyStatusHash(web3, did, publicKeyHash) {
export function getPublicKeyStatus(web3, did, publicKeyHash) {
const subjectAddr = AIdUtils.getProxyAddress(did)
const transaction = Object.assign({}, config.basicTransaction)
transaction.data = web3.eth.abi.encodeFunctionCall(
Expand Down
8 changes: 5 additions & 3 deletions src/txFactory/transactionFactory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
addSubjectCredential,
updateSubjectCredential,
addIssuerCredential,
updateIssuerCredential,
deleteSubjectCredential,
getSubjectCredentialStatus,
updateCredentialStatus,
Expand Down Expand Up @@ -52,13 +54,14 @@ import {
deletePublicKeyHash,
getCurrentPublicKey,
getPublicKeyStatus,
getPublicKeyStatusHash,
} from './publicKeyRegistryTransactionFactory'

export const transactionFactory = {
credentialRegistry: {
addSubjectCredential: addSubjectCredential,
updateSubjectCredential: updateSubjectCredential,
addIssuerCredential: addIssuerCredential,
updateIssuerCredential: updateIssuerCredential,
deleteSubjectCredential: deleteSubjectCredential,
getSubjectCredentialStatus: getSubjectCredentialStatus,
updateCredentialStatus: updateCredentialStatus,
Expand Down Expand Up @@ -105,7 +108,6 @@ export const transactionFactory = {
deletePublicKey: deletePublicKey,
deletePublicKeyHash: deletePublicKeyHash,
getCurrentPublicKey: getCurrentPublicKey,
getPublicKeyStatus: getPublicKeyStatus,
getPublicKeyStatusHash: getPublicKeyStatusHash,
getPublicKeyStatus: getPublicKeyStatus
}
}

0 comments on commit 62e6867

Please sign in to comment.