Skip to content

Commit 62e6867

Browse files
authored
Merge pull request #197 from alastria/feature/credentialRegistryTransactionFactory
Feature/credential registry transaction factory
2 parents 725782c + fdeaba7 commit 62e6867

4 files changed

+108
-65
lines changed

src/txFactory/credentialRegistryTransactionFactory.ts

+50-7
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { config } from '../config'
22
import { AIdUtils } from '../utils/AIdUtils'
33

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

2224
/**
25+
* function updateSubjectCredential(web3, subjectCredentialHash, status)
26+
* Dev: get delegated invoke updateSubjectCredential transaction object
27+
* @param web3 ethereum connection
28+
* @param subjectCredentialHash should have 32 bytes, credential identification
29+
* @param status uint that indicates the status of the credential
30+
*/
31+
export function updateSubjectCredential(web3, subjectCredentialHash, status) {
32+
const transaction = Object.assign({}, config.basicTransaction)
33+
const delegatedData = web3.eth.abi.encodeFunctionCall(
34+
config.contractsAbi.AlastriaCredentialRegistry.updateSubjectCredential,
35+
[subjectCredentialHash, status]
36+
)
37+
transaction.data = delegated(web3, delegatedData)
38+
transaction.to = config.alastriaIdentityManager // When delegated, target is alastriaIdentityManager
39+
transaction.gasLimit = 600000
40+
return transaction
41+
}
42+
43+
/**
44+
* THIS METHOD WILL BE DEPREATED, USE INSTEAD updateIssuerCredential
2345
* function addIssuerCredential(web3, issuerCredentialHash)
2446
* Dev: get delegated invoke addIssuerCredential transaction object
2547
* @param web3 ethereum connection
@@ -38,6 +60,7 @@ export function addIssuerCredential(web3, issuerCredentialHash) {
3860
}
3961

4062
/**
63+
* THIS METHOD WILL BE DEPREATED, USE INSTEAD updateSubjectCredential
4164
* function deleteSubjectCredential(web3, subjectCredentialHash)
4265
* Dev: get delegated invoke deleteSubjectCredential transaction object
4366
* @param web3 ethereum connection
@@ -79,10 +102,11 @@ export function getSubjectCredentialStatus(
79102
}
80103

81104
/**
105+
* THIS METHOD WILL BE DEPREATED, USE INSTEAD updateIssuerCredential
82106
* function updateCredentialStatus(web3, issuerCredentialHash, status)
83-
* @param web3
84-
* @param issuerCredentialHash
85-
* @param status
107+
* @param web3 ethereum connection
108+
* @param issuerCredentialHash should have 32 bytes
109+
* @param status uint that indicates the status of the credential
86110
*/
87111
export function updateCredentialStatus(web3, issuerCredentialHash, status) {
88112
const transaction = Object.assign({}, config.basicTransaction)
@@ -96,12 +120,30 @@ export function updateCredentialStatus(web3, issuerCredentialHash, status) {
96120
return transaction
97121
}
98122

123+
/**
124+
* function updateIssuerCredential(web3, issuerCredentialHash, status)
125+
* @param web3 ethereum connection
126+
* @param issuerCredentialHash should have 32 bytes
127+
* @param status uint that indicates the status of the credential
128+
*/
129+
export function updateIssuerCredential(web3, issuerCredentialHash, status) {
130+
const transaction = Object.assign({}, config.basicTransaction)
131+
const delegatedData = web3.eth.abi.encodeFunctionCall(
132+
config.contractsAbi.AlastriaCredentialRegistry.updateIssuerCredential,
133+
[issuerCredentialHash, status]
134+
)
135+
transaction.data = delegated(web3, delegatedData)
136+
transaction.to = config.alastriaIdentityManager
137+
transaction.gasLimit = 600000
138+
return transaction
139+
}
140+
99141
/**
100142
* Dev: get the invoke updateCredentialStatus transaction object
101143
* function getIssuerCredentialStatus(address issuer, bytes32 issuerCredentialHash) view public validAddress(issuer) returns (bool exists, Status status)
102144
* @param web3 ethereum connection
103-
* @param didIssuer
104-
* @param issuerCredentialHash
145+
* @param didIssuer alastria Id
146+
* @param issuerCredentialHash should have 32 bytes
105147
*/
106148
export function getIssuerCredentialStatus(
107149
web3,
@@ -120,10 +162,11 @@ export function getIssuerCredentialStatus(
120162
}
121163

122164
/**
165+
* THIS METHOD WILL BE DEPREATED
123166
* Dev: Defining three status functions avoid linking the subject to the issuer or the corresponding hashes
124167
* @param web3 ethereum connection
125-
* @param subjectStatus
126-
* @param issuerStatus
168+
* @param subjectStatus uint that indicates the status of the credential for subject
169+
* @param issuerStatus uint that indicates the status of the credential for issuer
127170
*/
128171
export function getCredentialStatus(web3, subjectStatus, issuerStatus) {
129172
const transaction = Object.assign({}, config.basicTransaction)

src/txFactory/presentationRegistryTransactionFactory.ts

+23-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { config } from '../config'
22
import { AIdUtils } from '../utils/AIdUtils'
33

4+
/**
5+
* THIS METHOD WILL BE DEPREATED, USE INSTEAD updateSubjectPresentation
6+
* Subject functions
7+
* function addSubjectPresentation(web3, subjectPresentationHash, URI)
8+
* @param web3 ethereum connection
9+
* @param subjectPresentationHash should have 32 bytes
10+
* @param URI url for store the presentations for backup
11+
*/
412
export function addSubjectPresentation(web3, subjectPresentationHash, URI) {
513
const transaction = Object.assign({}, config.basicTransaction)
614
const delegatedData = web3.eth.abi.encodeFunctionCall(
@@ -16,8 +24,8 @@ export function addSubjectPresentation(web3, subjectPresentationHash, URI) {
1624
/**
1725
* Subject functions
1826
* function updateSubjectPresentation(bytes32 subjectPresentationHash, Status status) public validStatus(status)
19-
* @param web3
20-
* @param subjectPresentationHash
27+
* @param web3 ethereum connection
28+
* @param subjectPresentationHash should have 32 bytes
2129
*/
2230
export function updateSubjectPresentation(
2331
web3,
@@ -39,9 +47,9 @@ export function updateSubjectPresentation(
3947
* If the Presentation does not exists the return is a void Presentation
4048
* If we want a log, should we add an event?
4149
* function getSubjectPresentationStatus(address subject, bytes32 subjectPresentationHash) view public validAddress(subject) returns(bool exists, Status status)
42-
* @param web3
43-
* @param didSubject
44-
* @param subsubjectPresentationHashject
50+
* @param web3 ethereum connection
51+
* @param didSubject alastria Id
52+
* @param subsubjectPresentationHashject should have 32 bytes
4553
*/
4654
export function getSubjectPresentationStatus(
4755
web3,
@@ -63,9 +71,9 @@ export function getSubjectPresentationStatus(
6371
/**
6472
* Receiver functions
6573
* function updateReceiverPresentation(bytes32 receiverPresentationHash, Status status) public validStatus(status)
66-
* @param web3
67-
* @param receiverPresentationHash
68-
* @param status
74+
* @param web3 ethereum connection
75+
* @param receiverPresentationHash should have 32 bytes
76+
* @param status uint that indicates the status of the presentation
6977
*/
7078
export function updateReceiverPresentation(
7179
web3,
@@ -87,9 +95,9 @@ export function updateReceiverPresentation(
8795
* If the Presentation does not exists the return is a void Presentation
8896
* If we want a log, should we add an event?
8997
* function getReceiverPresentationStatus(address receiver, bytes32 receiverPresentationHash) view public validAddress(receiver) returns(bool exists, Status status) {
90-
* @param web3
91-
* @param didReceiver
92-
* @param receiverPresentationHash
98+
* @param web3 ethereum connection
99+
* @param didReceiver alastria Id
100+
* @param receiverPresentationHash should have 32 bytes
93101
*/
94102
export function getReceiverPresentationStatus(
95103
web3,
@@ -109,12 +117,13 @@ export function getReceiverPresentationStatus(
109117
}
110118

111119
/**
120+
* THIS METHOD WILL BE DEPREATED
112121
* Utility function
113122
* Defining three status functions avoids linking the Subject to the Receiver or the corresponding hashes
114123
* function getPresentationStatus(Status subjectStatus, Status receiverStatus) pure public validStatus(subjectStatus) validStatus(receiverStatus) returns(Status){
115-
* @param web3
116-
* @param subjectStatus
117-
* @param receiverStatus
124+
* @param web3 ethereum connection
125+
* @param subjectStatus uint that indicates the status of the presentation for subject
126+
* @param receiverStatus uint that indicates the status of the presentation for receiver
118127
*/
119128
export function getPresentationStatus(web3, subjectStatus, receiverStatus) {
120129
const transaction = Object.assign({}, config.basicTransaction)

src/txFactory/publicKeyRegistryTransactionFactory.ts

+30-41
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { AIdUtils } from '../utils/AIdUtils'
33
import { AddressUtils } from '../utils/AddressUtils'
44

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

2323
/**
24-
* @param web3
25-
* @param publicKeyHash
24+
* function addPublicKey(bytes32 publicKeyHash) public
25+
* @param web3 ethereum connection
26+
* @param publicKeyHash the hash of the publickey. should have 32 bytes
2627
*/
2728
export function addPublicKey(web3, publicKeyHash) {
2829
const transaction = Object.assign({}, config.basicTransaction)
@@ -37,9 +38,10 @@ export function addPublicKey(web3, publicKeyHash) {
3738
}
3839

3940
/**
40-
* THIS METHOD WILL BE DEPREATED
41-
* @param web3
42-
* @param publicKey
41+
* THIS METHOD WILL BE DEPREATED, USE INSTEAD revokePublicKeyHash
42+
* function revokePublicKey(string memory publicKey) public
43+
* @param web3 ethereum connection
44+
* @param publicKey the public key.
4345
*/
4446
export function revokePublicKey(web3, publicKey) {
4547
const transaction = Object.assign({}, config.basicTransaction)
@@ -54,8 +56,9 @@ export function revokePublicKey(web3, publicKey) {
5456
}
5557

5658
/**
57-
* @param web3
58-
* @param publicKeyHash
59+
* function revokePublicKey(bytes32 publicKeyHash) public
60+
* @param web3 ethereum connection
61+
* @param publicKeyHash the hash of the publickey. should have 32 bytes
5962
*/
6063
export function revokePublicKeyHash(web3, publicKeyHash) {
6164
const transaction = Object.assign({}, config.basicTransaction)
@@ -70,9 +73,10 @@ export function revokePublicKeyHash(web3, publicKeyHash) {
7073
}
7174

7275
/**
73-
* THIS METHOD WILL BE DEPREATED
74-
* @param web3
75-
* @param publicKey
76+
* THIS METHOD WILL BE DEPREATED, USE INSTEAD deletePublicKeyHash
77+
* function deletePublicKey(string memory publicKey) public
78+
* @param web3 ethereum connection
79+
* @param publicKey the public key.
7680
*/
7781
export function deletePublicKey(web3, publicKey) {
7882
const transaction = Object.assign({}, config.basicTransaction)
@@ -87,8 +91,9 @@ export function deletePublicKey(web3, publicKey) {
8791
}
8892

8993
/**
90-
* @param web3
91-
* @param publicKeyHash
94+
* function deletePublicKey(bytes32 publicKeyHash) public
95+
* @param web3 ethereum connection
96+
* @param publicKeyHash the hash of the publickey. should have 32 bytes
9297
*/
9398
export function deletePublicKeyHash(web3, publicKeyHash) {
9499
const transaction = Object.assign({}, config.basicTransaction)
@@ -103,9 +108,10 @@ export function deletePublicKeyHash(web3, publicKeyHash) {
103108
}
104109

105110
/**
106-
* THIS METHOD WILL BE DEPREATED
107-
* @param web3
108-
* @param did
111+
* THIS METHOD WILL BE DEPREATED, USE INSTEAD getPublicKeyStatusHash
112+
* function getCurrentPublicKey(address subject) view public
113+
* @param web3 ethereum connection
114+
* @param did alastri Id
109115
*/
110116
export function getCurrentPublicKey(web3, did) {
111117
const subjectAddr = AIdUtils.getProxyAddress(did)
@@ -120,29 +126,12 @@ export function getCurrentPublicKey(web3, did) {
120126
}
121127

122128
/**
123-
* THIS METHOD WILL BE DEPREATED
124-
* @param web3
125-
* @param did
126-
* @param publicKey
129+
* function getPublicKeyStatus(address subject, bytes32 publicKeyHash) view public
130+
* @param web3 ethereum connection
131+
* @param did alastri Id
132+
* @param publicKeyHash the hash of the publickey. should have 32 bytes
127133
*/
128-
export function getPublicKeyStatus(web3, did, publicKey) {
129-
const subjectAddr = AIdUtils.getProxyAddress(did)
130-
const transaction = Object.assign({}, config.basicTransaction)
131-
transaction.data = web3.eth.abi.encodeFunctionCall(
132-
config.contractsAbi.AlastriaPublicKeyRegistry.getPublicKeyStatus,
133-
[subjectAddr, AddressUtils.getAddressWithoutHexPrefix(publicKey)]
134-
)
135-
transaction.to = config.alastriaPublicKeyRegistry
136-
transaction.gasLimit = 600000
137-
return transaction
138-
}
139-
140-
/**
141-
* @param web3
142-
* @param did
143-
* @param publicKeyHash
144-
*/
145-
export function getPublicKeyStatusHash(web3, did, publicKeyHash) {
134+
export function getPublicKeyStatus(web3, did, publicKeyHash) {
146135
const subjectAddr = AIdUtils.getProxyAddress(did)
147136
const transaction = Object.assign({}, config.basicTransaction)
148137
transaction.data = web3.eth.abi.encodeFunctionCall(

src/txFactory/transactionFactory.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {
22
addSubjectCredential,
3+
updateSubjectCredential,
34
addIssuerCredential,
5+
updateIssuerCredential,
46
deleteSubjectCredential,
57
getSubjectCredentialStatus,
68
updateCredentialStatus,
@@ -52,13 +54,14 @@ import {
5254
deletePublicKeyHash,
5355
getCurrentPublicKey,
5456
getPublicKeyStatus,
55-
getPublicKeyStatusHash,
5657
} from './publicKeyRegistryTransactionFactory'
5758

5859
export const transactionFactory = {
5960
credentialRegistry: {
6061
addSubjectCredential: addSubjectCredential,
62+
updateSubjectCredential: updateSubjectCredential,
6163
addIssuerCredential: addIssuerCredential,
64+
updateIssuerCredential: updateIssuerCredential,
6265
deleteSubjectCredential: deleteSubjectCredential,
6366
getSubjectCredentialStatus: getSubjectCredentialStatus,
6467
updateCredentialStatus: updateCredentialStatus,
@@ -105,7 +108,6 @@ export const transactionFactory = {
105108
deletePublicKey: deletePublicKey,
106109
deletePublicKeyHash: deletePublicKeyHash,
107110
getCurrentPublicKey: getCurrentPublicKey,
108-
getPublicKeyStatus: getPublicKeyStatus,
109-
getPublicKeyStatusHash: getPublicKeyStatusHash,
111+
getPublicKeyStatus: getPublicKeyStatus
110112
}
111113
}

0 commit comments

Comments
 (0)