Skip to content

Commit 95b3f8b

Browse files
committed
Resove issue #178. Duplicate functions to use publicKeys as a hash.
1 parent 29ec49d commit 95b3f8b

10 files changed

+474
-255
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ build/Release
3636
# Dependency directories
3737
node_modules/
3838
alastriaID-truffle-contracts
39+
alastriaID-hardhat-contracts
3940
jspm_packages/
4041
package-lock.json
42+
src/config.ts
4143

4244
# Typescript v1 declaration files
4345
typings/

package-lock.json

+244-218
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"types": "dist/index.d.ts",
1010
"scripts": {
1111
"postinstall": "run-s build",
12-
"compile": "git clone --branch develop https://github.com/alastria/alastriaID-truffle-contracts.git && npm install --prefix alastriaID-truffle-contracts && npm run compile --prefix alastriaID-truffle-contracts && node src/configFile.js && tsc",
13-
"clean": "rimraf dist alastriaID-truffle-contracts",
12+
"compile": "git clone --branch v2.2 https://github.com/alastria/alastriaID-hardhat-contracts.git && npm install --prefix alastriaID-hardhat-contracts && npm run compile --prefix alastriaID-hardhat-contracts && node src/configFile.js && tsc",
13+
"clean": "rimraf dist alastriaID-hardhat-contracts",
1414
"build": "run-s clean compile",
1515
"test": "mocha -r ts-node/register test/**/*.ts",
1616
"lint": "eslint 'src/**/*.{js,ts,tsx}'",

src/config.ts

+1-1
Large diffs are not rendered by default.

src/configFile.js

+43-15
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,56 @@
22
const fs = require('fs')
33
const path = require('path')
44

5-
const contractsABIPath = '../alastriaID-truffle-contracts/build/contracts'
5+
const contractsABIPath = '../alastriaID-hardhat-contracts/artifacts/contracts'
66
const _contractsAbi = {}
7+
const abi = {}
78

89
// Process the abi dir for getting an object with all the abi functions
9-
fs.readdirSync(path.join(__dirname, `${contractsABIPath}`)).forEach((file) => {
10-
const abi = {}
11-
const abiFile = JSON.parse(
12-
fs.readFileSync(path.join(__dirname, `${contractsABIPath}`, file), 'utf8')
13-
)
14-
abiFile.abi.forEach((element) => {
15-
if (element.type === 'constructor') {
16-
abi.constructor = element
17-
} else {
18-
if (element.name) {
19-
abi[element.name] = element
10+
fs.readdirSync(path.join(__dirname, `${contractsABIPath}`)).forEach((folder) => {
11+
fs.readdirSync(path.join(__dirname, `${contractsABIPath}/${folder}`)).forEach((folderSol) => {
12+
fs.readdirSync(path.join(__dirname, `${contractsABIPath}/${folder}/${folderSol}`)).forEach((file) => {
13+
if(folderSol === 'upgradeability') {
14+
fs.readdirSync(path.join(__dirname, `${contractsABIPath}/${folder}/${folderSol}`)).forEach((folderUpgrade) => {
15+
fs.readdirSync(path.join(__dirname, `${contractsABIPath}/${folder}/${folderSol}/${folderUpgrade}`)).forEach((fileUpgrade) => {
16+
if (!fileUpgrade.endsWith('.dbg.json')) {
17+
const abiFile = JSON.parse(
18+
fs.readFileSync(path.join(__dirname, `${contractsABIPath}/${folder}/${folderSol}/${folderUpgrade}`, fileUpgrade), 'utf8')
19+
)
20+
abiFile.abi.forEach((element) => {
21+
if (element.type === 'constructor') {
22+
abi.constructor = element
23+
} else {
24+
if (element.name) {
25+
abi[element.name] = element
26+
}
27+
}
28+
})
29+
_contractsAbi[abiFile.contractName] = abi
30+
}
31+
})
32+
})
33+
} else {
34+
if (!file.endsWith('.dbg.json')) {
35+
const abiFile = JSON.parse(
36+
fs.readFileSync(path.join(__dirname, `${contractsABIPath}/${folder}/${folderSol}`, file), 'utf8')
37+
)
38+
abiFile.abi.forEach((element) => {
39+
if (element.type === 'constructor') {
40+
abi.constructor = element
41+
} else {
42+
if (element.name) {
43+
abi[element.name] = element
44+
}
45+
}
46+
})
47+
_contractsAbi[abiFile.contractName] = abi
48+
}
2049
}
21-
}
50+
})
2251
})
23-
_contractsAbi[abiFile.contractName] = abi
2452
})
2553

26-
const contractsAddressesPath = '../alastriaID-truffle-contracts'
54+
const contractsAddressesPath = '../alastriaID-hardhat-contracts'
2755
const contractsInfo = JSON.parse(
2856
fs.readFileSync(path.join(__dirname, `${contractsAddressesPath}`, 'addresses.json'), 'utf8')
2957
)

src/txFactory/credentialRegistryTransactionFactory.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,17 @@ export function getSubjectCredentialStatus(
8484
* @param web3 ethereum connection
8585
* @param didSubject subject to recover credential list
8686
*/
87-
//export function getSubjectCredentialList(web3, didSubject) {
88-
//const subjectAddr = AIdUtils.getProxyAddress(didSubject)
89-
//const transaction = Object.assign({}, config.basicTransaction)
90-
//transaction.data = web3.eth.abi.encodeFunctionCall(
91-
//config.contractsAbi.AlastriaCredentialRegistry.getSubjectCredentialList,
92-
//[subjectAddr]
93-
//)
94-
//transaction.to = config.alastriaCredentialRegistry
95-
//transaction.gasLimit = 600000
96-
//return transaction
97-
//}
87+
// export function getSubjectCredentialList(web3, didSubject) {
88+
// const subjectAddr = AIdUtils.getProxyAddress(didSubject)
89+
// const transaction = Object.assign({}, config.basicTransaction)
90+
// transaction.data = web3.eth.abi.encodeFunctionCall(
91+
// config.contractsAbi.AlastriaCredentialRegistry.getSubjectCredentialList,
92+
// [subjectAddr]
93+
// )
94+
// transaction.to = config.alastriaCredentialRegistry
95+
// transaction.gasLimit = 600000
96+
// return transaction
97+
// }
9898

9999
/**
100100
* function updateCredentialStatus(web3, issuerCredentialHash, status)

src/txFactory/identityManagerTransactionFactory.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function prepareAlastriaID(web3, signAddress) {
3838
}
3939

4040
/**
41-
* function createAlastriaIdentity(bytes publicKeyData) public validAddress(msg.sender) isOnTimeToLiveAndIsFromCaller(msg.sender)
41+
* THIS METHOD WILL BE DEPREATED
4242
* @param web3
4343
* @param publicKey publicKey is a String
4444
*/
@@ -57,6 +57,26 @@ export function createAlastriaIdentity(web3, publicKey) {
5757
return transaction
5858
}
5959

60+
/**
61+
62+
* @param web3
63+
* @param publicKeyHash
64+
*/
65+
export function createAlastriaIdentityHash(web3, publicKeyHash) {
66+
const transaction = Object.assign({}, config.basicTransaction)
67+
transaction.gasLimit = 600000
68+
const publicKeyCallData = web3.eth.abi.encodeFunctionCall(
69+
config.contractsAbi.AlastriaPublicKeyRegistry.addKey,
70+
[publicKeyHash]
71+
)
72+
transaction.data = web3.eth.abi.encodeFunctionCall(
73+
config.contractsAbi.AlastriaIdentityManager.createAlastriaIdentity,
74+
[publicKeyCallData]
75+
)
76+
transaction.to = config.alastriaIdentityManager
77+
return transaction
78+
}
79+
6080
/**
6181
* AlastriaIdentityIssuer.sol
6282
* function addIdentityIssuer(address _identityIssuer, Eidas.EidasLevel _level) public alLeastLow(_level) notIdentityIssuer(_identityIssuer)

src/txFactory/presentationRegistryTransactionFactory.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function getSubjectPresentationStatus(
6565
* @param web3
6666
* @param didSubject
6767
*/
68-
/**export function getSubjectPresentationList(web3, didSubject) {
68+
/** export function getSubjectPresentationList(web3, didSubject) {
6969
const subjectAddr = AIdUtils.getProxyAddress(didSubject)
7070
const transaction = Object.assign({}, config.basicTransaction)
7171
transaction.data = web3.eth.abi.encodeFunctionCall(
@@ -75,7 +75,7 @@ export function getSubjectPresentationStatus(
7575
transaction.to = config.alastriaPresentationRegistry
7676
transaction.gasLimit = 600000
7777
return transaction
78-
}*/
78+
} */
7979

8080
/**
8181
* Receiver functions

src/txFactory/publicKeyRegistryTransactionFactory.ts

+131-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { PublicKeyStatus } from '../interfaces'
55
import { AddressUtils } from '../utils/AddressUtils'
66

77
/**
8+
* THIS METHOD WILL BE DEPREATED
89
* function addKey(string memory publicKey, address subject) public
910
* @param web3
1011
* @param publicKey
@@ -22,7 +23,23 @@ export function addKey(web3, publicKey) {
2223
}
2324

2425
/**
25-
* function revokePublicKey(string memory publicKey) public
26+
* @param web3
27+
* @param publicKeyHash
28+
*/
29+
export function addPublicKey(web3, publicKeyHash) {
30+
const transaction = Object.assign({}, config.basicTransaction)
31+
const delegatedData = web3.eth.abi.encodeFunctionCall(
32+
config.contractsAbi.AlastriaPublicKeyRegistry.addPublicKey,
33+
[publicKeyHash]
34+
)
35+
transaction.data = delegated(web3, delegatedData)
36+
transaction.to = config.alastriaIdentityManager
37+
transaction.gasLimit = 600000
38+
return transaction
39+
}
40+
41+
/**
42+
* THIS METHOD WILL BE DEPREATED
2643
* @param web3
2744
* @param publicKey
2845
*/
@@ -39,7 +56,23 @@ export function revokePublicKey(web3, publicKey) {
3956
}
4057

4158
/**
42-
* function deletePublicKey(string memory publicKey) public
59+
* @param web3
60+
* @param publicKeyHash
61+
*/
62+
export function revokePublicKeyHash(web3, publicKeyHash) {
63+
const transaction = Object.assign({}, config.basicTransaction)
64+
const delegatedData = web3.eth.abi.encodeFunctionCall(
65+
config.contractsAbi.AlastriaPublicKeyRegistry.revokePublicKey,
66+
[publicKeyHash]
67+
)
68+
transaction.data = delegated(web3, delegatedData)
69+
transaction.to = config.alastriaIdentityManager
70+
transaction.gasLimit = 600000
71+
return transaction
72+
}
73+
74+
/**
75+
* THIS METHOD WILL BE DEPREATED
4376
* @param web3
4477
* @param publicKey
4578
*/
@@ -55,6 +88,22 @@ export function deletePublicKey(web3, publicKey) {
5588
return transaction
5689
}
5790

91+
/**
92+
* @param web3
93+
* @param publicKeyHash
94+
*/
95+
export function deletePublicKeyHash(web3, publicKeyHash) {
96+
const transaction = Object.assign({}, config.basicTransaction)
97+
const delegatedData = web3.eth.abi.encodeFunctionCall(
98+
config.contractsAbi.AlastriaPublicKeyRegistry.deletePublicKey,
99+
[publicKeyHash]
100+
)
101+
transaction.data = delegated(web3, delegatedData)
102+
transaction.to = config.alastriaIdentityManager
103+
transaction.gasLimit = 600000
104+
return transaction
105+
}
106+
58107
/**
59108
* function getCurrentPublicKey(address subject) view public validAddress(subject) returns (string)
60109
* @param web3
@@ -73,6 +122,7 @@ export function getCurrentPublicKey(web3, did) {
73122
}
74123

75124
/**
125+
* THIS METHOD WILL BE DEPREATED
76126
* @param web3
77127
* @param did
78128
* @param publicKey
@@ -90,6 +140,24 @@ export function getPublicKeyStatus(web3, did, publicKey) {
90140
}
91141

92142
/**
143+
* @param web3
144+
* @param did
145+
* @param publicKeyHash
146+
*/
147+
export function getPublicKeyStatusHash(web3, did, publicKeyHash) {
148+
const subjectAddr = AIdUtils.getProxyAddress(did)
149+
const transaction = Object.assign({}, config.basicTransaction)
150+
transaction.data = web3.eth.abi.encodeFunctionCall(
151+
config.contractsAbi.AlastriaPublicKeyRegistry.getPublicKeyStatus,
152+
[subjectAddr, publicKeyHash]
153+
)
154+
transaction.to = config.alastriaPublicKeyRegistry
155+
transaction.gasLimit = 600000
156+
return transaction
157+
}
158+
159+
/**
160+
* THIS METHOD WILL BE DEPREATED
93161
* @param web3
94162
* @param did
95163
* @param publicKey
@@ -119,6 +187,36 @@ export function getPublicKeyStatusDecodedAsJSON(
119187
}
120188

121189
/**
190+
* @param web3
191+
* @param did
192+
* @param publicKeyHash
193+
*/
194+
export function getPublicKeyStatusDecodedAsJSONHash(
195+
web3,
196+
did,
197+
publicKeyHash
198+
): Promise<PublicKeyStatus> {
199+
const publicKeyStatusTx = getPublicKeyStatus(web3, did, publicKeyHash)
200+
201+
return new Promise((resolve) => {
202+
web3.eth.call(publicKeyStatusTx).then((data) => {
203+
const publicKeyStatusDecoded = web3.eth.abi.decodeParameters(
204+
['bool', 'uint8', 'uint', 'uint'],
205+
data
206+
)
207+
const publicKeyStatusDecodedAsJSON = {
208+
exists: publicKeyStatusDecoded['0'],
209+
status: publicKeyStatusDecoded['1'],
210+
startDate: parseInt(publicKeyStatusDecoded['2']),
211+
endDate: parseInt(publicKeyStatusDecoded['3'])
212+
}
213+
resolve(publicKeyStatusDecodedAsJSON)
214+
})
215+
})
216+
}
217+
218+
/**
219+
* THIS METHOD WILL BE DEPREATED
122220
* @param web3
123221
* @param did
124222
* @param publicKey
@@ -149,6 +247,37 @@ export function isPublicKeyValidForDate(web3, did, publicKey, date) {
149247
})
150248
}
151249

250+
/**
251+
* @param web3
252+
* @param did
253+
* @param publicKeyHash
254+
* @param date in milliseconds
255+
*/
256+
export function isPublicKeyValidForDateHash(web3, did, publicKeyHash, date) {
257+
publicKeyHash = AddressUtils.getAddressWithHexPrefix(publicKeyHash)
258+
return new Promise((resolve, reject) => {
259+
transactionFactory.publicKeyRegistry
260+
.getPublicKeyStatusDecodedAsJSON(web3, did, publicKeyHash)
261+
.then((publicKeyStatusAsJSON) => {
262+
const existsPublicKey = publicKeyStatusAsJSON.exists
263+
264+
if (existsPublicKey) {
265+
const isUserDateBetweenDates = _isUserDateBetweeenDates(
266+
date,
267+
publicKeyStatusAsJSON.startDate,
268+
publicKeyStatusAsJSON.endDate
269+
)
270+
resolve(isUserDateBetweenDates)
271+
} else {
272+
reject(new Error('Public key does not exist'))
273+
}
274+
})
275+
.catch(() => {
276+
reject(new Error('Unresolved error'))
277+
})
278+
})
279+
}
280+
152281
/**
153282
* @param userDate in milliseconds
154283
* @param publicKeyStartDate in milliseconds

0 commit comments

Comments
 (0)