diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 84d2132..56c69f0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/configuration.json b/configuration.json index 55652d2..ff62636 100644 --- a/configuration.json +++ b/configuration.json @@ -1,5 +1,5 @@ { - "nodeURL": "http://63.33.206.111/rpc", + "nodeURL": "http://", "addressPassword": "Passw0rd", "firstIdentityPubk": "0xaca7aa42e831f41b6f246d089fbcabe73e1c6ce01a1bb5d944fda4e148e1d6930f6ebb5138b1d103e3e384c893962a238e4088a549bfe84867da96942931f69a", "entity1Pubk": "0x356e3fce435d8729062e52d263c0c705b3c5e201a9a9608cdb070764e6b8df30ae8423b439a7af2bcc3529778341ab06c1e44411352f217b68ce44a673a1df63", @@ -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, diff --git a/exampleFirstEntity/1.createEntityAlastriaID.js b/exampleFirstEntity/1.createEntityAlastriaID.js index 97dd2c1..10f60e9 100644 --- a/exampleFirstEntity/1.createEntityAlastriaID.js +++ b/exampleFirstEntity/1.createEntityAlastriaID.js @@ -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 diff --git a/examplePublicKey/1.getSubject1CurrentPublicKey.js b/examplePublicKey/1.getSubject1CurrentPublicKey.js index 83324f4..60a20c9 100644 --- a/examplePublicKey/1.getSubject1CurrentPublicKey.js +++ b/examplePublicKey/1.getSubject1CurrentPublicKey.js @@ -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) diff --git a/examplePublicKey/2.getEntity3CurrentPublicKey.js b/examplePublicKey/2.getEntity3CurrentPublicKey.js index 3500304..9beff54 100644 --- a/examplePublicKey/2.getEntity3CurrentPublicKey.js +++ b/examplePublicKey/2.getEntity3CurrentPublicKey.js @@ -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) diff --git a/examplePublicKey/3.isPublicKeyValidForCertainDate.js b/examplePublicKey/3.isPublicKeyValidForCertainDate.js index b81eacc..c0250f2 100644 --- a/examplePublicKey/3.isPublicKeyValidForCertainDate.js +++ b/examplePublicKey/3.isPublicKeyValidForCertainDate.js @@ -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) diff --git a/package.json b/package.json index 560efce..f17c5f8 100644 --- a/package.json +++ b/package.json @@ -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": {