From 5067675f87aaf594239b425b511e942a9b0f6af5 Mon Sep 17 00:00:00 2001 From: rober12 Date: Sun, 10 Nov 2024 10:59:42 +0100 Subject: [PATCH 1/4] added updateSubjectCredential and updateIssuerCredential functions. Also marks some deprecated functions --- .../credentialRegistryTransactionFactory.ts | 42 +++++++++++++++++++ .../presentationRegistryTransactionFactory.ts | 9 ++++ 2 files changed, 51 insertions(+) diff --git a/src/txFactory/credentialRegistryTransactionFactory.ts b/src/txFactory/credentialRegistryTransactionFactory.ts index 6fde667..67a952b 100644 --- a/src/txFactory/credentialRegistryTransactionFactory.ts +++ b/src/txFactory/credentialRegistryTransactionFactory.ts @@ -2,6 +2,7 @@ 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 @@ -20,6 +21,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 @@ -38,6 +59,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 @@ -79,6 +101,7 @@ export function getSubjectCredentialStatus( } /** + * THIS METHOD WILL BE DEPREATED, USE INSTEAD updateIssuerCredential * function updateCredentialStatus(web3, issuerCredentialHash, status) * @param web3 * @param issuerCredentialHash @@ -96,6 +119,24 @@ export function updateCredentialStatus(web3, issuerCredentialHash, status) { return transaction } +/** + * function updateIssuerCredentialStatus(web3, issuerCredentialHash, status) + * @param web3 + * @param issuerCredentialHash + * @param status + */ +export function updateIssuerCredentialStatus(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) @@ -120,6 +161,7 @@ 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 diff --git a/src/txFactory/presentationRegistryTransactionFactory.ts b/src/txFactory/presentationRegistryTransactionFactory.ts index d482207..3f9b5e3 100644 --- a/src/txFactory/presentationRegistryTransactionFactory.ts +++ b/src/txFactory/presentationRegistryTransactionFactory.ts @@ -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 + * @param subjectPresentationHash + * @param URI + */ export function addSubjectPresentation(web3, subjectPresentationHash, URI) { const transaction = Object.assign({}, config.basicTransaction) const delegatedData = web3.eth.abi.encodeFunctionCall( @@ -109,6 +117,7 @@ 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){ From a8e692874f3de623726bf045617ed80f58f80527 Mon Sep 17 00:00:00 2001 From: rober12 Date: Sun, 10 Nov 2024 11:03:46 +0100 Subject: [PATCH 2/4] export functions updateSubjectCredential and updateIssuerCredential --- src/txFactory/credentialRegistryTransactionFactory.ts | 2 +- src/txFactory/transactionFactory.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/txFactory/credentialRegistryTransactionFactory.ts b/src/txFactory/credentialRegistryTransactionFactory.ts index 67a952b..ef88f58 100644 --- a/src/txFactory/credentialRegistryTransactionFactory.ts +++ b/src/txFactory/credentialRegistryTransactionFactory.ts @@ -125,7 +125,7 @@ export function updateCredentialStatus(web3, issuerCredentialHash, status) { * @param issuerCredentialHash * @param status */ -export function updateIssuerCredentialStatus(web3, issuerCredentialHash, status) { +export function updateIssuerCredential(web3, issuerCredentialHash, status) { const transaction = Object.assign({}, config.basicTransaction) const delegatedData = web3.eth.abi.encodeFunctionCall( config.contractsAbi.AlastriaCredentialRegistry.updateIssuerCredential, diff --git a/src/txFactory/transactionFactory.ts b/src/txFactory/transactionFactory.ts index dec04b4..a86c248 100644 --- a/src/txFactory/transactionFactory.ts +++ b/src/txFactory/transactionFactory.ts @@ -1,6 +1,8 @@ import { addSubjectCredential, + updateSubjectCredential, addIssuerCredential, + updateIssuerCredential, deleteSubjectCredential, getSubjectCredentialStatus, updateCredentialStatus, @@ -58,7 +60,9 @@ import { export const transactionFactory = { credentialRegistry: { addSubjectCredential: addSubjectCredential, + updateSubjectCredential: updateSubjectCredential, addIssuerCredential: addIssuerCredential, + updateIssuerCredential: updateIssuerCredential, deleteSubjectCredential: deleteSubjectCredential, getSubjectCredentialStatus: getSubjectCredentialStatus, updateCredentialStatus: updateCredentialStatus, From e43c9b4dd59ea612e78386f4578195b7df891e83 Mon Sep 17 00:00:00 2001 From: rober12 Date: Mon, 11 Nov 2024 09:35:54 +0100 Subject: [PATCH 3/4] Complete documentation of the functions --- .../credentialRegistryTransactionFactory.ts | 21 +++---- .../presentationRegistryTransactionFactory.ts | 34 +++++------ .../publicKeyRegistryTransactionFactory.ts | 60 +++++++++++-------- 3 files changed, 62 insertions(+), 53 deletions(-) diff --git a/src/txFactory/credentialRegistryTransactionFactory.ts b/src/txFactory/credentialRegistryTransactionFactory.ts index ef88f58..93df498 100644 --- a/src/txFactory/credentialRegistryTransactionFactory.ts +++ b/src/txFactory/credentialRegistryTransactionFactory.ts @@ -7,6 +7,7 @@ import { AIdUtils } from '../utils/AIdUtils' * 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) @@ -103,9 +104,9 @@ 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) @@ -121,9 +122,9 @@ export function updateCredentialStatus(web3, issuerCredentialHash, status) { /** * function updateIssuerCredentialStatus(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 updateIssuerCredential(web3, issuerCredentialHash, status) { const transaction = Object.assign({}, config.basicTransaction) @@ -141,8 +142,8 @@ export function updateIssuerCredential(web3, issuerCredentialHash, status) { * 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, @@ -164,8 +165,8 @@ 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) diff --git a/src/txFactory/presentationRegistryTransactionFactory.ts b/src/txFactory/presentationRegistryTransactionFactory.ts index 3f9b5e3..8f48bb0 100644 --- a/src/txFactory/presentationRegistryTransactionFactory.ts +++ b/src/txFactory/presentationRegistryTransactionFactory.ts @@ -5,9 +5,9 @@ import { AIdUtils } from '../utils/AIdUtils' * THIS METHOD WILL BE DEPREATED, USE INSTEAD updateSubjectPresentation * Subject functions * function addSubjectPresentation(web3, subjectPresentationHash, URI) - * @param web3 - * @param subjectPresentationHash - * @param 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) @@ -24,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, @@ -47,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, @@ -71,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, @@ -95,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, @@ -121,9 +121,9 @@ export function getReceiverPresentationStatus( * 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) diff --git a/src/txFactory/publicKeyRegistryTransactionFactory.ts b/src/txFactory/publicKeyRegistryTransactionFactory.ts index 3f4f552..4c93f0f 100644 --- a/src/txFactory/publicKeyRegistryTransactionFactory.ts +++ b/src/txFactory/publicKeyRegistryTransactionFactory.ts @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -120,10 +126,11 @@ export function getCurrentPublicKey(web3, did) { } /** - * THIS METHOD WILL BE DEPREATED - * @param web3 - * @param did - * @param publicKey + * TODO: ELIMINAR??? + * THIS METHOD WILL BE DEPREATED, USE INSTEAD getPublicKeyStatusHash + * function getPublicKeyStatus(address subject, bytes32 publicKeyHash) view public + * @param did ethereum connection + * @param publicKey the public key. */ export function getPublicKeyStatus(web3, did, publicKey) { const subjectAddr = AIdUtils.getProxyAddress(did) @@ -138,9 +145,10 @@ export function getPublicKeyStatus(web3, did, publicKey) { } /** - * @param web3 - * @param did - * @param publicKeyHash + * 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 getPublicKeyStatusHash(web3, did, publicKeyHash) { const subjectAddr = AIdUtils.getProxyAddress(did) From fdeaba7d377cd136307b61d64a4988a86639aace Mon Sep 17 00:00:00 2001 From: rober12 Date: Mon, 11 Nov 2024 15:14:50 +0100 Subject: [PATCH 4/4] remove unused function and rename credentialRegistryTransactionFactory function --- .../credentialRegistryTransactionFactory.ts | 2 +- .../publicKeyRegistryTransactionFactory.ts | 21 +------------------ src/txFactory/transactionFactory.ts | 4 +--- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/src/txFactory/credentialRegistryTransactionFactory.ts b/src/txFactory/credentialRegistryTransactionFactory.ts index 93df498..8184617 100644 --- a/src/txFactory/credentialRegistryTransactionFactory.ts +++ b/src/txFactory/credentialRegistryTransactionFactory.ts @@ -121,7 +121,7 @@ export function updateCredentialStatus(web3, issuerCredentialHash, status) { } /** - * function updateIssuerCredentialStatus(web3, issuerCredentialHash, status) + * 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 diff --git a/src/txFactory/publicKeyRegistryTransactionFactory.ts b/src/txFactory/publicKeyRegistryTransactionFactory.ts index 4c93f0f..91bd28e 100644 --- a/src/txFactory/publicKeyRegistryTransactionFactory.ts +++ b/src/txFactory/publicKeyRegistryTransactionFactory.ts @@ -125,32 +125,13 @@ export function getCurrentPublicKey(web3, did) { return transaction } -/** - * TODO: ELIMINAR??? - * THIS METHOD WILL BE DEPREATED, USE INSTEAD getPublicKeyStatusHash - * function getPublicKeyStatus(address subject, bytes32 publicKeyHash) view public - * @param did ethereum connection - * @param publicKey the public key. - */ -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 -} - /** * 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 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( diff --git a/src/txFactory/transactionFactory.ts b/src/txFactory/transactionFactory.ts index a86c248..a87c517 100644 --- a/src/txFactory/transactionFactory.ts +++ b/src/txFactory/transactionFactory.ts @@ -54,7 +54,6 @@ import { deletePublicKeyHash, getCurrentPublicKey, getPublicKeyStatus, - getPublicKeyStatusHash, } from './publicKeyRegistryTransactionFactory' export const transactionFactory = { @@ -109,7 +108,6 @@ export const transactionFactory = { deletePublicKey: deletePublicKey, deletePublicKeyHash: deletePublicKeyHash, getCurrentPublicKey: getCurrentPublicKey, - getPublicKeyStatus: getPublicKeyStatus, - getPublicKeyStatusHash: getPublicKeyStatusHash, + getPublicKeyStatus: getPublicKeyStatus } }