Skip to content

Commit

Permalink
update publicKey examples
Browse files Browse the repository at this point in the history
  • Loading branch information
rober12 committed May 21, 2024
1 parent ca88c88 commit 7772ced
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 49 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: '12.x'
node-version: '18.x'
- name: Install dependencies
run: npm install
env:
NODE_ENV: development
- name: Run all examples
run: dev-tools/executeAllExamples.sh
shell: bash
34 changes: 21 additions & 13 deletions configuration.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"nodeURL": "http://63.33.206.111/rpc",
"nodeURL": "http://<redT-nodeIP>",
"addressPassword": "Passw0rd",
"firstIdentityPubk": "0xaca7aa42e831f41b6f246d089fbcabe73e1c6ce01a1bb5d944fda4e148e1d6930f6ebb5138b1d103e3e384c893962a238e4088a549bfe84867da96942931f69a",
"entity1Pubk": "0x356e3fce435d8729062e52d263c0c705b3c5e201a9a9608cdb070764e6b8df30ae8423b439a7af2bcc3529778341ab06c1e44411352f217b68ce44a673a1df63",
Expand Down Expand Up @@ -46,28 +46,36 @@
"procDesc": "Short description to business process 4583",
"data": [
{
"@context": ["JWT", "https://alastria.github.io/identity/credentials/v1", "https://www.w3.org/2018/identity/driving-license/v1"],
"@context": [
"JWT",
"https://alastria.github.io/identity/credentials/v1",
"https://www.w3.org/2018/identity/driving-license/v1"
],
"levelOfAssurance": 3,
"required": true,
"field_name": "driving_license"
},
{
"@context": ["JWT", "https://alastria.github.io/identity/credentials/v1", "https://www.w3.org/2018/identity/driving-license/v1"],
"@context": [
"JWT",
"https://alastria.github.io/identity/credentials/v1",
"https://www.w3.org/2018/identity/driving-license/v1"
],
"levelOfAssurance": 0,
"required": true,
"field_name": "email"
}
],
"entity1": "0xdb040fd6acca0e742898484bd2738b38a8c57aa8",
"didEntity1": "did:ala:quor:redT:db040fd6acca0e742898484bd2738b38a8c57aa8",
"entity2": "0x82f83d802f235955e9543d3f8e485ccd06436a89",
"didEntity2": "did:ala:quor:redT:82f83d802f235955e9543d3f8e485ccd06436a89",
"entity3": "0x220ea50a0315eb025ebfb8c309d515ea5a4ac3c4",
"didEntity3": "did:ala:quor:redT:220ea50a0315eb025ebfb8c309d515ea5a4ac3c4",
"subject1": "0x4b7fa6f648f677efecb5b178a6560db23857438b",
"didSubject1": "did:ala:quor:redT:4b7fa6f648f677efecb5b178a6560db23857438b",
"subject2": "0x302b6117248c12c066b8008e0ee5180a18e5698e",
"didSubject2": "did:ala:quor:redT:302b6117248c12c066b8008e0ee5180a18e5698e",
"entity1": "0x59e23b61f42877d14231f05996b9089a2f6081b5",
"didEntity1": "did:ala:quor:redT:59e23b61f42877d14231f05996b9089a2f6081b5",
"entity2": "0x6d26cdd054ad1f7dd51cfe28e449c4cd33bc3165",
"didEntity2": "did:ala:quor:redT:6d26cdd054ad1f7dd51cfe28e449c4cd33bc3165",
"entity3": "0x4e9363e45f3b8b6f0ef8d7cdbf4df1d1a36e0089",
"didEntity3": "did:ala:quor:redT:4e9363e45f3b8b6f0ef8d7cdbf4df1d1a36e0089",
"subject1": "0x576a5823d80dc7974438c4eb6fc861921d525c3e",
"didSubject1": "did:ala:quor:redT:576a5823d80dc7974438c4eb6fc861921d525c3e",
"subject2": "0x02976e59938f023e5a868e520401648df6ce8d9d",
"didSubject2": "did:ala:quor:redT:02976e59938f023e5a868e520401648df6ce8d9d",
"issuerLevel": 2,
"updateSubject1PresentationTo": 2,
"updateEntity2PresentationTo": 1,
Expand Down
1 change: 1 addition & 0 deletions exampleFirstEntity/1.createEntityAlastriaID.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function preparedAlastriaId() {

function createAlastriaId() {
const entity1PubKeyHash = `${web3.utils.sha3(configData.entity1Pubk.substr(2))}`
console.log("PUBLIC KEY HASH", entity1PubKeyHash);
const txCreateAlastriaID = transactionFactory.identityManager.createAlastriaIdentityHash(
web3,
entity1PubKeyHash
Expand Down
18 changes: 13 additions & 5 deletions examplePublicKey/1.getSubject1CurrentPublicKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,25 @@ if (configData.didSubject1 === undefined) {
console.error('You must create an Alastria ID')
process.exit(1)
}

const currentPubKey = transactionFactory.publicKeyRegistry.getCurrentPublicKey(
const subject1PubKeyHash = `${web3.utils.sha3(configData.subject1Pubk.substr(2))}`
const currentPubKey = transactionFactory.publicKeyRegistry.getPublicKeyStatusHash(
web3,
configData.didSubject1
configData.didSubject1,
subject1PubKeyHash
)
console.log("TRANSACCION", currentPubKey);
web3.eth
.call(currentPubKey)
.then((result) => {
// We add this replace to find only the alphanumeric substring (the rest of null/void characters are not important)
const publicKey = web3.utils.hexToAscii(result).replace(/[^0-9A-Z]+/gi, '')
console.log('RESULT ----->', publicKey)
const resultStatus = web3.eth.abi.decodeParameters(['bool', 'uint8', 'uint256', 'uint256'], result)
const publicKeyStatus = {
exist: resultStatus[0],
status: resultStatus[1],
startDate: resultStatus[2],
endDate: resultStatus[3]
}
console.log('publicKeyStatus for Subject1 ------>', publicKeyStatus)
})
.catch((error) => {
console.error('Error -------->', error)
Expand Down
16 changes: 12 additions & 4 deletions examplePublicKey/2.getEntity3CurrentPublicKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ if (configData.didEntity3 === undefined) {
process.exit(1)
}

const currentPubKey = transactionFactory.publicKeyRegistry.getCurrentPublicKey(
const entity3PubKeyHash = `${web3.utils.sha3(configData.entity3Pubk.substr(2))}`
const currentPubKey = transactionFactory.publicKeyRegistry.getPublicKeyStatusHash(
web3,
configData.didEntity3
configData.didEntity3,
entity3PubKeyHash
)

web3.eth
.call(currentPubKey)
.then((result) => {
// We add this replace to find only the alphanumeric substring (the rest of null/void characters are not important)
const publicKey = web3.utils.hexToAscii(result).replace(/[^0-9A-Z]+/gi, '')
console.log('RESULT ----->', publicKey)
const resultStatus = web3.eth.abi.decodeParameters(['bool', 'uint8', 'uint256', 'uint256'], result)
const publicKeyStatus = {
exist: resultStatus[0],
status: resultStatus[1],
startDate: resultStatus[2],
endDate: resultStatus[3]
}
console.log('publicKeyStatus for Entity3 ------>', publicKeyStatus)
})
.catch((error) => {
console.error('Error -------->', error)
Expand Down
43 changes: 21 additions & 22 deletions examplePublicKey/3.isPublicKeyValidForCertainDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,33 @@ if (configData.entity3 === undefined) {
}

console.log('We retrive the current public key for entity3')
const getPubKTx = transactionFactory.publicKeyRegistry.getCurrentPublicKey(
const entity3PubKeyHash = `${web3.utils.sha3(configData.entity3Pubk.substr(2))}`
const getPubKTx = transactionFactory.publicKeyRegistry.getPublicKeyStatusHash(
web3,
configData.didEntity3
configData.didEntity3,
entity3PubKeyHash
)
web3.eth
.call(getPubKTx)
.then((data) => {
const publicKeyAsString = web3.eth.abi.decodeParameters(['string'], data)[0]
console.log('This is the public key for entity3', publicKeyAsString)
.then((result) => {
const resultStatus = web3.eth.abi.decodeParameters(['bool', 'uint8', 'uint256', 'uint256'], result)
const publicKeyStatus = {
exist: resultStatus[0],
status: resultStatus[1],
startDate: resultStatus[2],
endDate: resultStatus[3]
}
console.log('publicKeyStatus for Entity3 ------>', publicKeyStatus)

console.log(
'Convert the publicKey to byte32 as the input parameter requires this type'
)
const publicKeyAsByte32 = `0x${web3.utils.sha3(publicKeyAsString)}`
const date = 1588612481
const date = new Date();

console.log('Check if it is valid for a date')
transactionFactory.publicKeyRegistry
.isPublicKeyValidForDate(
web3,
configData.didEntity3,
publicKeyAsByte32,
date
)
.then((isValid) => {
if (isValid) console.log('The public key is valid for the date ' + date)
else console.log('The public key is NOT valid for the date ' + date)
})
if (publicKeyStatus.endDate == 0) {
console.log('The public key is valid for the date ' + date)
} else if (publicKeyStatus.endDate >= date.getTime()) {
console.log('The public key is valid for the date ' + date)
} else {
console.log('The public key is NOT valid for the date ' + date)
}
})
.catch(function (error) {
console.error('Something fails', error)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alastria-identity-example",
"version": "2.1.1",
"version": "2.2.0",
"description": "This is an example of how to interact with the libraries from [alastria-identity-lib](https://github.com/alastria/alastria-identity-lib). The library alastria-identity-lib re-covers the Smart Contracts from [alastria-identity](https://github.com/alastria/alastriaID-hardhat-contracts).",
"main": "",
"scripts": {
Expand Down

0 comments on commit 7772ced

Please sign in to comment.