-
Notifications
You must be signed in to change notification settings - Fork 24
Working with the Library, Smart Contracts and Examples WIP
Working with Alastria Identity requires initially understanding a series of terms that we will explain below: The concepts that are being used in these examples are:
- Entity → Company or organization (legal person). An entity can be one or both:
- Service Provider → Entity which requests information from a subject, so it creates Presentation Requests and receives Presentations.
- Issuer → It can help anyone to create a new identity. Also this kind of entity can emits certified information about a subject, so it creates Credentials.
- Subject → Person (natural or legal) who has information certified by an issuer and sends it to a service provider, so it receives credentials and creates presentations. It is the information owner. This information is saved and controlled from a wallet.
- Admin → Root identity which deploys the Smart Contracts and owns them. It is just used when creating the first entity. The following entities must be created by an issuer entity (in this example, entity1).
Name | Role |
---|---|
admin | Service Provider + Issuer |
entity1 | Service Provider + Issuer |
entity2 | Service Provider |
entity3 | Issuer |
subject1 | Subject |
subject2 | Subject |
In order to work with Alastria Identity, firstly it is advisable to download the repositories of Smart Contracts, Library and Examples in the same location, for example, you can create a folder on the Desktop named as alastria-identity and within it download these repositories via git. Before downloading the Alastria Identity repositories, we must be sure that we have installed nodejs. We are going to install version 10.X, to do this, we carry out the following steps:
cd ~
curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt install nodejs
It is also necessary to install make, for this we execute the following command
sudo apt install build-essential
Another essential component to be able to work with these repositories, is the installation of truffle, for this, through npm we will proceed to it. From the command line, we execute the following action:
npm install -g truffle
In the place where we want to download it, through the command line we write the following commands:
git clone https://github.com/alastria/alastria-identity.git
git clone https://github.com/alastria/alastria-identity-lib.git
git clone https://github.com/alastria/alastria-identity-example.git
Once this is done, we will start with the Smart Contracts, for this we place ourselves in the alastria-identity repository, and we make sure that we are in the master branch by writing git branch, it has to give us master as a result. In order to work with this repository, we will use truffle and its configuration, for this, first of all we edit the truffle.js file and make the following changes:
module.exports = {
networks: {
'development': {
host: "localhost",
port: 8545,
network_id: "*",
gas: 0xffffff,
gasPrice: 0x0,
},
'testnet': {
host: "192.168.1.33",
port: 22000,
network_id: "*",
gas: 0xffffff,
gasPrice: 0x0,
from: "0x64101c4f6b3394c249933983592ac0bbaf6b2f14"
}
},
compilers: {
solc: {
version: "0.4.23", // A version or constraint - Ex. "^0.5.0"
parser: "solcjs", // Leverages solc-js purely for speedy parsing
settings: {
optimizer: {
enabled: true,
runs: 200 // Optimize for how many times you intend to run the code
},
evmVersion: "byzantium" // Default: "petersburg"
}
}
}
};
At the same time we have changed truffle-config, you have to go to the migrations directory and modify the network identifier in the first file 1_initial_migrations.js, and also, you have to change the call to unlock, placing the call as follows:
web3.eth.personal.unlockAccount(…….)
Once these changes are made, the command truffle deploy –network is executed. And after waiting a while, the screen should show something similar to the following:
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
Starting migrations...
======================
> Network name: 'testnet'
> Network id: 9535753591
> Block gas limit: 0x65e50956
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
> transaction hash: 0xbbc019185adcac34265e179939e297f988fe68681590a23e59d725844a7d66e7
> Blocks: 0 Seconds: 0
> contract address: 0x00fA5905ad8a56d05007cebC32931D2e17296644
> block number: 3109
> block timestamp: 1611483718
> account: 0x64101C4f6B3394C249933983592ac0bBaF6B2F14
> balance: 0
> gas used: 227174
> gas price: 0 gwei
> value sent: 0 ETH
> total cost: 0 ETH
> Saving artifacts
-------------------------------------
> Total cost: 0 ETH
2_deploy_contracts_registry.js
==============================
Replacing 'AlastriaPublicKeyRegistry'
-------------------------------------
> transaction hash: 0x9abb83889c1bd7516d36835c51a199e23c5931a53ec880362e529b6a6c3f1f65
> Blocks: 0 Seconds: 0
> contract address: 0x24e9f15Bf9D82529C9B84EE492Be2B00bF403E15
> block number: 3112
> block timestamp: 1611483721
> account: 0x64101C4f6B3394C249933983592ac0bBaF6B2F14
> balance: 0
> gas used: 739769
> gas price: 0 gwei
> value sent: 0 ETH
> total cost: 0 ETH
Replacing 'AlastriaCredentialRegistry'
--------------------------------------
> transaction hash: 0x7106910e51a9371c762db3780cff55d22ac9648714a8d72260ca4b52f131e037
> Blocks: 0 Seconds: 0
> contract address: 0xaA63426bdBCE10AaBBefC7bF54A8ba76099542FC
> block number: 3114
> block timestamp: 1611483723
> account: 0x64101C4f6B3394C249933983592ac0bBaF6B2F14
> balance: 0
> gas used: 852383
> gas price: 0 gwei
> value sent: 0 ETH
> total cost: 0 ETH
Replacing 'AlastriaPresentationRegistry'
----------------------------------------
> transaction hash: 0x5ffe36828e77a08334611f335d48d2b1988a35d387f18e4dc67c4c7329b65a10
> Blocks: 0 Seconds: 0
> contract address: 0x0796A4d3dc96661Ea12Be9005AcE3D76902B207b
> block number: 3116
> block timestamp: 1611483725
> account: 0x64101C4f6B3394C249933983592ac0bBaF6B2F14
> balance: 0
> gas used: 1204237
> gas price: 0 gwei
> value sent: 0 ETH
> total cost: 0 ETH
> Saving artifacts
-------------------------------------
> Total cost: 0 ETH
3_deploy_contracts_identityManager.js
=====================================
Replacing 'Eidas'
-----------------
> transaction hash: 0x5f86d26b5f30d2389f44f65d7348bd6b8ea08852e98f0af7df30caaf9c878d2f
> Blocks: 0 Seconds: 0
> contract address: 0x8cDF2269c6b44580BaC141AeF533119A1BE8E2a6
> block number: 3119
> block timestamp: 1611483728
> account: 0x64101C4f6B3394C249933983592ac0bBaF6B2F14
> balance: 0
> gas used: 117830
> gas price: 0 gwei
> value sent: 0 ETH
> total cost: 0 ETH
Linking
-------
* Contract: AlastriaIdentityIssuer <--> Library: Eidas (at address: 0x8cDF2269c6b44580BaC141AeF533119A1BE8E2a6)
Linking
-------
* Contract: AlastriaIdentityManager <--> Library: Eidas (at address: 0x8cDF2269c6b44580BaC141AeF533119A1BE8E2a6)
Replacing 'AlastriaIdentityServiceProvider'
-------------------------------------------
> transaction hash: 0x4686c78f70295f21fc6512f41a71d896a9bde08a64971a7b65d2e69e967305ec
> Blocks: 0 Seconds: 0
> contract address: 0xe88D1b5A9C7b01618EEB166D14b62b2F014E4B70
> block number: 3122
> block timestamp: 1611483731
> account: 0x64101C4f6B3394C249933983592ac0bBaF6B2F14
> balance: 0
> gas used: 213535
> gas price: 0 gwei
> value sent: 0 ETH
> total cost: 0 ETH
Replacing 'AlastriaIdentityIssuer'
----------------------------------
> transaction hash: 0xa06aa39b939a7e7c7f05d19ce0973ddfd6b00b0de1268fa8192090efb006fb56
> Blocks: 0 Seconds: 0
> contract address: 0xc254305772a1CA38B59d8EB02BeB8f00683B1326
> block number: 3124
> block timestamp: 1611483733
> account: 0x64101C4f6B3394C249933983592ac0bBaF6B2F14
> balance: 0
> gas used: 424459
> gas price: 0 gwei
> value sent: 0 ETH
> total cost: 0 ETH
Replacing 'AlastriaIdentityManager'
-----------------------------------
> transaction hash: 0x0444fa826a1c3486eee578475ca8cb984b7b8efac3c704a91a838de1f3ed3a97
> Blocks: 0 Seconds: 0
> contract address: 0x88727F6072B32471Ab7C9E2934A2ea4e9B15B0d9
> block number: 3126
> block timestamp: 1611483735
> account: 0x64101C4f6B3394C249933983592ac0bBaF6B2F14
> balance: 0
> gas used: 5176759
> gas price: 0 gwei
> value sent: 0 ETH
> total cost: 0 ETH
> Saving artifacts
-------------------------------------
> Total cost: 0 ETH
Summary
=======
> Total deployments: 8
> Final cost: 0 ETH
In this way we would have already deployed the contracts in the node that we want to use to be able to make use of the Alastria Identity Contracts.
Another way to deploy contracts is through the script that the repository itself has for this purpose. To do this, we go to the dev-tools folder, and in it, we open the deployContracts folder. Once this is done, we edit the config.json file, and modify the file with the data corresponding to our node, and the location of the abi, which we are going to use, and the ContractInfo.md file in case we have to change it, but normally both abi information and ContractInfo.md it is not neccesary.
Once modified, we will have to launch a npm install from the console, inside this directory. After that, we execute the first of the scripts using the node 1.flattenContracts.js command and if there are no errors, we execute the following command: node 2.deployUpdateContracts.js command. For the second one you have to edit the 2.deployUpdateContract file and put the correct node. Once this is done, if there are no errors, you must show us the following information.
Starting compiling contracs
Compiling Contract ...
Contract Eidas compiled successfuly
Deploying Eidas Contract ...
Contract Eidas deployed successfuly. Address: 0x393327e46e237bc9b2a698efdb56d11f59b7faab
Eidas ABI saved!
Compiling Contract ...
AlastriaCredentialRegistry ABI saved!
AlastriaIdentityEntity ABI saved!
AlastriaIdentityIssuer ABI saved!
AlastriaIdentityManager ABI saved!
AlastriaIdentityServiceProvider ABI saved!
AlastriaPresentationRegistry ABI saved!
AlastriaProxy ABI saved!
AlastriaPublicKeyRegistry ABI saved!
Eidas ABI saved!
Owned ABI saved!
Contract Manager compiled successfuly
Deploying Manager Contract ...
Eidas address info saved!
Contract AlastriaIdentityManager deployed successfuly. Address: 0xc59934952968b99de371baceb8226ec72778e164
Contract AlastriaCredentialRegistry deployed successfuly. Address: 0xe8b01f85ab4170f2ecdb2d7a30d19ba9e8ca687e
Contract AlastriaPresentationRegistry deployed successfuly. Address: 0xba84f4f9875c0caef081e7dd5db44f671494672c
Contract AlastriaPublicKeyManager deployed successfuly. Address: 0x29b6d76db3c4ccb04da59faf0a1b60d10db3637e
AlastriaIdentityManager address info saved!
AlastriaCredentialRegistry address info saved!
AlastriaPresentationRegistry address info saved!
AlastriaPublicKeyRegistry address info saved!
This is the best way to deploy the Smart Contracts as all changes are made automatically.
If you want to work with Remix, you need to install some components. In the first place, it is necessary that in our environment we have remixd and then from the Remix IDE we can connect, for this, first we go to our console and execute the following command:
npm install -g remixd
Done this, and that it has not given us any error, we continue executing the following command that would be the following:
remixd -s --remix-ide
An example of use would be the following:
remixd -s /home/Ubuntu/Desktop/alastria/alastria-identity/contracts http://remix.ethereum.org
In the IDE it will be necessary to install a new plugin called Remixd, which will allow us to connect with our team. Once this is done, we will be able to work with remix in the normal way as we work with any Smart Contract that we have developed in the IDE itself. In order to display the contracts, it is necessary to have ganache installed to be able to make use of the accounts that are generated after lifting the node created by it. Also indicate that Remix currently has a plugin in beta mode, called Quorum that allows you to connect to a Quorum node, but it is necessary to have CORS active when the call to geth is made to start our node adding in out geth call the following flag : --rpccorsdomain=”http://remix.ethereum.org” .
After doing that, you can put on the Get RPC field the url with the port of your node, and it will connect as it is showed in the following image
--------Image----------
After you have configured and you have set up the Web Provider to your node, you have to unlock manually the account you want to use and use the methods from the smart contracts normally.
Once the deployment method has been chosen, which for our case it is Byzantium, we deploy the AlastriaIdentityManager contract as shown in the following image. From here, we can use all methods of Smart Contracts.
--------Image----------
For Ganache, you have to configure the truffle-config.js with the ganache parameters. Following this, the configuration would be like this:
module.exports = {
networks: {
'development': {
host: "localhost",
port: 8545,
network_id: "*",
gas: 0xffffff,
gasPrice: 0x0,
from: "0x64101c4f6b3394c249933983592ac0bbaf6b2f14"
},
},
compilers: {
solc: {
version: "0.4.23", // A version or constraint - Ex. "^0.5.0"
parser: "solcjs", // Leverages solc-js purely for speedy parsing
settings: {
optimizer: {
enabled: true,
runs: 200 // Optimize for how many times you intend to run the code
},
evmVersion: "byzantium" // Default: "petersburg"
}
}
}
};
Once you have completed this process, you can deploy your Smart Contracts as it is written in the previous sections. After that, you have to run the setProxyAdmin and work with the rest of the ecosystem as you were in a normal network.
The execution of this script will allow us to obtain the proxy address of the account that has deployed the contracts. This function is important to later be able to execute the Examples that will be explained in the Examples section and in turn if you want to work correctly with the entire Alastria Identidad ecosystem. The script to run to generate the proxy address is the following:
const IdentityManager = artifacts.require("AlastriaIdentityManager");
const fs = require("fs");
const path = require("path");
const ethers = require("ethers");
const adminPath = path.resolve('./dev-tools/createFakeIdentities/mocked-identity-keys/issuer-806bc0d7a47b890383a831634bcb92dd4030b092');
const imAddress = "0x16947aD7c14419269e957Be374E6E345AD4EDf97";
module.exports = async function () {
try {
let provider = new ethers.providers.JsonRpcProvider("http://localhost:8545");
let adminKeystore = fs.readFileSync(adminPath,'utf-8');
let adminAccount = await ethers.Wallet.fromEncryptedJson(adminKeystore,"Passw0rd",(progress)=>{
//console.log(progress);
});
const wallet = adminAccount.connect(provider);
let imInstance = new ethers.Contract(imAddress,IdentityManager.abi,wallet);
const tx1 = await imInstance.prepareAlastriaID(adminAccount.address);
console.log(tx1);
const tx2 = await imInstance.createAlastriaIdentity("0x50382c1a0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008430783034306365356564633230346165393737643664363966636336623333396135376235343465663464303934393239663365623931386137376466626132363939386537376563356232396133373964643539626265393632653262323237343531343361613262353263346138373562373439326331333765656562663430353500000000000000000000000000000000000000000000000000000000");
console.log(tx2);
} catch (error) {
console.log(error);
}
}
Sometimes you can have this error:
error:
{ Error: processing response error (body="{\"jsonrpc\":\"2.0\",\"id\":65,\"error\":{\"code\":-32000,\"message\":\"replacement transaction underpriced\"}}\n", error={"code":-32000}, requestBody="{\"method\":\"eth_sendRawTransaction\",\"params\":[\"0xf901ab0e808307c2e694c59934952968b99de371baceb8226ec72778e16480b901446d69d99a000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e450382c1a000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000823078323138666461653461313162313963666133636238353830333935656662663934376539326531353031353231613830626462663638343130663462656566643661616331333836396465386139356464646438666537653339343534336562386139373036653336316562353863666266326534363436386638323130643400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000850470c01b11a083110d85e19ab512e9460c6a98311b7b6ae0e9608305374b533778b018395f8da071eab20a0512bbec3de3e0ba719a7872be4264769107e55f4140f197ab7b6e70\"],\"id\":65,\"jsonrpc\":\"2.0\"}", requestMethod="POST", url="http://192.168.1.33:22000", code=SERVER_ERROR, version=web/5.0.11)
at Logger.makeError (/usr/lib/node_modules/ethers/node_modules/@ethersproject/logger/src.ts/index.ts:205:28)
at Logger.throwError (/usr/lib/node_modules/ethers/node_modules/@ethersproject/logger/src.ts/index.ts:217:20)
at /usr/lib/node_modules/ethers/node_modules/@ethersproject/web/src.ts/index.ts:284:28
at step (/usr/lib/node_modules/ethers/node_modules/@ethersproject/web/lib/index.js:33:23)
at Object.next (/usr/lib/node_modules/ethers/node_modules/@ethersproject/web/lib/index.js:14:53)
at fulfilled (/usr/lib/node_modules/ethers/node_modules/@ethersproject/web/lib/index.js:5:58)
at process._tickCallback (internal/process/next_tick.js:68:7)
reason: 'processing response error',
code: 'SERVER_ERROR',
In that case in the setAdminProxy script you have to put between the transactions the following lines:
tx1.wait();
const sleep =(waitTimeInMs)=> new Promise(resolve=>setTimeout(resolve,waitTimeInMs));
await sleep(10000);
For the tx2 you need to get the abi encode of the addKey method from the PublicKeyRegistry Smart Contract with the Public Key of the admin account and put it on the parameter of the createAlastriaIdentity method.
To be able to carry out, the tx3 is necessary to obtain the proxy address of the admin for it, with a small JavaScript script we can obtain that address. Said script is the following:
web3.eth.call({
to: config.alastriaIdentityManager,
data: web3.eth.abi.encodeFunctionCall(
config.contractsAbi.AlastriaIdentityManager.identityKeys,
[adminKeystore.address]
)
})
.then((AlastriaIdentity) => {
console.log(
`alastriaProxyAddress: 0x${AlastriaIdentity.slice(26)}`
)
In adminKeystore.address, we will put the admin's address. Once the address of the Proxy Address is obtained: alastriaProxyAddress: 0x092024441041ad3f4bfcfaef01fd970e0ec329d6, we will execute the tx3 which is the following:
const tx3 = await imInstance.addIdentityIssuer("0x092024441041ad3f4bfcfaef01fd970e0ec329d6", 3);
console.log("tx3", tx3);
Finally, we will execute a fourth and fith transactions, which are the following:
const tx4 = await imInstance.addServiceProvider ("0x092024441041ad3f4bfcfaef01fd970e0ec329d6")
const tx5 = await imInstance. addEntity("0x092024441041ad3f4bfcfaef01fd970e0ec329d6","Entidad1" , "A-28964782","www.entidad1.com/logo","www.entidad1.com/AID", "www.entidad1.com/AOA", true)
where we pass as a parameter the Proxy Address that we have obtained previously. With both tx we will have outputs like this one:
ubuntu@ubuntu-VirtualBox:~/Escritorio/alastria/alastria-identity$ truffle exec setAdminProxy.js --network testnet
Using network 'testnet'.
tx3 { nonce: 18,
gasPrice: BigNumber { _hex: '0x00', _isBigNumber: true },
gasLimit: BigNumber { _hex: '0xd519', _isBigNumber: true },
to: '0xc59934952968B99De371baceb8226eC72778E164',
value: BigNumber { _hex: '0x00', _isBigNumber: true },
data:
'0x889776a8000000000000000000000000092024441041ad3f4bfcfaef01fd970e0ec329d60000000000000000000000000000000000000000000000000000000000000003',
chainId: 9535753591,
v: 19071507217,
r:
'0x854fe4ec228a6ba4369c53cbbc10269c8de7edd817d5f3f01bb8880fc3f623ce',
s:
'0x73148c2f2833cb76d121b6218491d4d5a400090b95f0a71e58be03f985fbde2d',
from: '0x64101C4f6B3394C249933983592ac0bBaF6B2F14',
hash:
'0xc11f9fed7689398466f726a76f571474fdcf212803cddbd471e3888f9ab6c743',
wait: [Function] }
Before starting to work with the library, we proceed to install typescript, to do this, we execute the following command npm install -g typescript. Later, to work with the library, the first thing to do within it is to execute the npm install command, in this way all the dependencies that may exist. With this command also within the library the repository of Smart Contracts with which we have worked previously will be cloned. Due to this, we copy the repository with which we have worked previously in the main directory of the library, replacing the one that has just been cloned with the one that we have already worked with. Once this is done, we go to the src folder that is in the root directory of the library repository. Inside src we edit the configFile.js file, checking that the contractsPath is correct.
#!/usr/bin/node
const fs = require('fs')
const path = require('path')
const contractsPath = '../alastria-identity/contracts'
var _contractsAbi = {}
// Process the abi dir for getting an object with all the abi functions
fs.readdirSync(path.join(__dirname, `${contractsPath}/abi`)).forEach((file) => {
const abi = {}
const abiFile = JSON.parse(
fs.readFileSync(path.join(__dirname, `${contractsPath}/abi`, file), 'utf8')
)
abiFile.forEach((element) => {
if (element.type === 'constructor') {
abi.constructor = element
} else {
abi[element.name] = element
}
})
_contractsAbi[file.match(/sol_(.*)\.abi/)[1]] = abi
})
// Read file ContractInfo.md and take rows to aobtain the addres of each contract
const contractsInfo = fs.readFileSync(
path.join(__dirname, `${contractsPath}/`, 'ContractInfo.md'),
'utf8'
)
const contractInfoRow = contractsInfo.split('\n')
const config = {
alastriaIdentityManager: contractInfoRow[3].split(' | ')[1],
alastriaCredentialRegistry: contractInfoRow[4].split(' | ')[1],
alastriaPresentationRegistry: contractInfoRow[5].split(' | ')[1],
alastriaPublicKeyRegistry: contractInfoRow[6].split(' | ')[1],
basicTransaction: {
to: '0x0000000000000000000000000000000000000000',
data: '0x0',
gasLimit: 0,
gasPrice: 0
},
contractsAbi: _contractsAbi,
zeroValue:
'00000000000000000000000000000000000000000000000000000000000000000000'
}
function getConfig() {
fs.writeFileSync(
'./src/config.ts',
`export const config = ${JSON.stringify(config)}`
)
}
getConfig()
After this we proceed to execute first of all a tsc command and after that a node configFile.js. Carrying out this action, the addresses of the deployed contracts will be copied to the config.ts file.
Inside the Examples repository, we execute the following command: npm install -save github:alastria/alastria-identity-lib.git. The previous command will generate a folder with the necessary dependencies to be able to work with the examples. Apart from this, having modified the library in the previous point, we copy the folder of the library that we have modified previously in the node_modules folder and we get inside it to transpile its content using the tsc command. With this we can now make use of the contracts that we have displayed in our node referring to the addresses of the contracts. As well, you can use npm link instead of copy the folder, just you have to go to your library folder and run a npm link inside the folder. After that the libray it will be put as global , and it will have a symlink in the global folder, so all changes you have done in your liberary folder will be replicated to the global folder. In order to work properly with the Examples, we must make sure that we have the Proxy Address of the address that will be the admin, that is, the address that has displayed the proxied contracts. Therefore, it is necessary to have previously executed the point 2.3 setProxyAdmin. These examples contain the following folder structure:
- dev-tools: In this directory we are going to find a script that will allow us to execute the rest of the scripts found in the following directories in order to generate the digital identities necessary to make use of the examples. Inside the script it will make calls to the scripts that are in the directories exampleFirstEntity, exampleCreateAlastriaID, exampleIssuer and exampleServiceProvider.
- exampleAuthentication: In this directory we will find a script to authenticate the generated Alastria Token and verify the Alastria Session through the generated JWT.
- exampleCreateAlastriaID: In this directory we will find the scripts that will be executed to generate the identities related to the second and third entity. Apart from that, we will find two scripts to generate the identities of two subjects. Therefore, it is important that both the identity of entity1 and the identity of entity2 have been previously created.
- exampleEntities: In this directory we will find the necessary scripts to be able to provision a new entity that we are going to use in our examples. In these scripts we will find one to list all the entities that we have, in another to obtain one that interests us, in another to be able to put the name, to be able to put the Cif, Addresses, Identity and Logo *** exampleFirstEntity**: As its name indicates, in this directory we will find the necessary scripts to be able to generate the first identity related to the entities. Inside this directory, are the first scripts that are executed if we execute the dev-tools script
- exampleIssuer: In this directory, we can find the necessary scripts so that an entity can act as issuer *** examplePresentations**: In this directory, we can find the necessary scripts to be able to create Presentations and list them. If you want to make use of the presentations, if in the scripts 2.getSubjectPresentationStatus.js, 5.getEntity2PresentationStatus.js and 7.getPresentationStatus.js the result is {exist: false, status: '0'}, this means that it is not working correctly because probably the DID of the subject or entity has been overwritten and it will be necessary to run the examples located in the exampleCreateAlastriaID folder again.
- examplePublicKey: In this directory we will find 3 scripts that will allow us to first obtain the Current Public Key that subject 1 has, in the second script we can find the current Public Key of entity 3, and in the last script we can validate if the provided Public Key is valid for a certain date.
- exampleServiceProvider: In this directory, we can find the necessary scripts so that an entity can act as a ServiceProvider
- exampleTokens: This directory contains a script to generate an AlastriaToken, AlastriaSession, Credentials, AlastriaIdentity
- ** keystores**: This directory contains the keystores of the accounts that will intervene in the examples.
In turn, there is a file in the root called configuration.json, which we will have to manipulate in order to work with these. The file contains the following parameters:
{
"nodeURL": "http://63.33.206.111/rpc",
"addressPassword": "Passw0rd",
"rawPublicKeySubject": "03fdd57adec3d438ea237fe46b33ee1e016eda6b585c3e27ea66686c2ea5358479",
"rawPublicKeyReceiver": "8b82bb2b1b5b4c1d56beeb88c98fcf894c23e8dee598d94c1c77099d3a80367f46",
"adminPubk": "0x0ce5edc204ae977d6d69fcc6b339a57b544ef4d094929f3eb918a77dfba26998e77ec5b29a379dd59bbe962e2b22745143aa2b52c4a875b7492c137eeebf4055",
"entity1Pubk": "0x356e3fce435d8729062e52d263c0c705b3c5e201a9a9608cdb070764e6b8df30ae8423b439a7af2bcc3529778341ab06c1e44411352f217b68ce44a673a1df63",
"entity2Pubk": "0xa33e56a80b9dc83a4456265d877c0765cea76146e625572fc679804f8867222ca3c816433a9b6e6690b0b8e919ffa874982706e812314aae09d85fc62fc4fa3c",
"entity3Pubk": "0xf6aa52924a7280241bd84d098d7c03b4e3a7e08f206b68868f439b65a6c3b26b1bd30b960325be8670339a66258b851ae170691429248149b601da5798f42d28",
"subject1Pubk": "0x2e507af01167c98a6accc0cd46ab2a256dd6b6c69ec1c0c28f80fb62e1f7d70233768b0c58dbbdac1fc358b8141c075a520483cf9779e4ea98d13df2833f3767",
"subject2Pubk": "0xaca7aa42e831f41b6f246d089fbcabe73e1c6ce01a1bb5d944fda4e148e1d6930f6ebb5138b1d103e3e384c893962a238e4088a549bfe84867da96942931f69a",
"rawPrivateKey": "278a5de700e29faae8e40e366ec5012b5ec63d36ec77e8a2417154cc1d25383f",
"context": [
"https://w3id.org/did/v1",
"JWT"
],
"type": [
"CustomType"
],
"signedTxCreateAlastriaID" : "0xf901888203f180830927c094bd4a2c84edb97be5beff7cd341bd63567e73f8c980b901246d69d99a000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000c450382c1a000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000803265353037616630313136376339386136616363633063643436616232613235366464366236633639656331633063323866383066623632653166376437303233333736386230633538646262646163316663333538623831343163303735613532303438336366393737396534656139386431336466323833336633373637000000000000000000000000000000000000000000000000000000001ca0e3e05abb1592bd15dc72e57d8930c24efdd0e286437a34ca2f118372ad428b25a0480ac816c93a5c1e8eff1dfd96f850dc664c5daa1ff94a88bdf789b0652ebfd3",
"userPublicKey": "AE2309349218937HASKHIUE9287432",
"providerURL": "https://regular.telsius.blockchainbyeveris.io:2000",
"callbackURL": "https://serviceprovider.alastria.blockchainbyeveris.io/api/login/",
"alastriaNetId": "Alastria network",
"tokenExpTime": 1563783392,
"tokenActivationDate": 1563782792,
"tokenNotBefore": 123456789,
"jsonTokenId": "ze298y42sba",
"network": "quor",
"networkId": "redT",
"tokenPayload": {
"header": {
"alg": "ES256K",
"typ": "JWT",
"kid": "did:ala:quor:redt:0x12eeaCCA9eEbB78eB97d7cac6b#keys-1",
"jwk": "0x12345"
},
"payload": {
"iss": "did:ala:quor:redT:e53d78c1c6fc694a0f29b3f24bee439338acbe3e",
"gwu": "http://1.2.3.4:8097/alastria/presentation",
"cbu": "http://1.2.3.4:8097/alastria/presentation",
"iat": 1590569132,
"ani": "redT",
"exp": 1563783392
}
},
"jti": "https://www.empresa.com/alastria/credentials/3734",
"kidCredential": "did:ala:quor:redt:12eeaCCA9eEbB78eB97d7cac6b#keys-1",
"subjectAlastriaID": "did:ala:quor:redt:0x12eeaCCA9eEbB78eB97d7cac6b",
"credentialKey": "StudentID",
"credentialValue": "11235813",
"uri": "www.google.com",
"procUrl": "https://www.empresa.com/alastria/businessprocess/4583",
"procHash": "H398sjHd...kldjUYn475n",
"data": [
{
"@context": "JWT",
"levelOfAssurance": 3,
"required": true,
"field_name": "name"
},
{
"@context": "JWT",
"levelOfAssurance": 3,
"required": true,
"field_name": "email"
}
],
"entity1": "0xd2f868f056ef3a48bbc8d446dfed411e9bf93ab0",
"didEntity1": "did:ala:quor:redT:d2f868f056ef3a48bbc8d446dfed411e9bf93ab0",
"entity2": "0xf86484b4ae0148de488f4b66d0bf578bb3779fcd",
"didEntity2": "did:ala:quor:redT:0xf86484b4ae0148de488f4b66d0bf578bb3779fcd",
"entity3": "0xb0462601a17581ed1b5dda86272aee5e49e2f5f7",
"didEntity3": "did:ala:quor:redT:0xb0462601a17581ed1b5dda86272aee5e49e2f5f7",
"subject1": "0x87ff106536c5c129e8a5e1434888eb1c5fb5a927",
"didSubject1": "did:ala:quor:redT:0x87ff106536c5c129e8a5e1434888eb1c5fb5a927",
"subject2": "0x5a6d79a6240ce5724f551922a2d1addee9fcfa4c",
"didSubject2": "did:ala:quor:redT:0x5a6d79a6240ce5724f551922a2d1addee9fcfa4c",
"issuerLevel": 2,
"updateSubject1PresentationTo": 2,
"updateEntity2PresentationTo": 1,
"updateIssuerCredentialTo": 2,
"subject1PresentationStatus": {
"exist": true,
"status": "2"
},
"entity2PresentationStatus": {
"exist": true,
"status": "1"
},
"entityData1": {
"name": "Entidad1",
"cif": "A-28964782",
"urlLogo": "www.entidad1.com/logo",
"urlCreateAID": "www.entidad1.com/AID",
"urlAOA": "www.entidad1.com/AOA",
"status": true
},
"entityData2": {
"name": "Entidad2",
"cif": "A-95974786",
"urlLogo": "www.entidad2.com/logo",
"urlCreateAID": "www.entidad2.com/AID",
"urlAOA": "www.entidad2.com/AOA",
"status": true
},
"entityData3": {
"name": "Entidad3",
"cif": "A-49934581",
"urlLogo": "www.entidad3.com/logo",
"urlCreateAID": "www.entidad3.com/AID",
"urlAOA": "www.entidad3.com/AOA",
"status": true
}
}
In this file, the following parameters will have to be modified initially so that the examples work correctly: "nodeURL": "http://63.33.206.111/rpc", "addressPassword": "Passw0rd", "adminPubk": "0x0ce5edc204ae977d6d69fcc6b339a57b544ef4d094929f3eb918a77dfba26998e77ec5b29a379dd59bbe962e2b22745143aa2b52c4a875b7492c137eeebf4055", "entity1Pubk": "0x356e3fce435d8729062e52d263c0c705b3c5e201a9a9608cdb070764e6b8df30ae8423b439a7af2bcc3529778341ab06c1e44411352f217b68ce44a673a1df63", "entity2Pubk": "0xa33e56a80b9dc83a4456265d877c0765cea76146e625572fc679804f8867222ca3c816433a9b6e6690b0b8e919ffa874982706e812314aae09d85fc62fc4fa3c", "entity3Pubk": "0xf6aa52924a7280241bd84d098d7c03b4e3a7e08f206b68868f439b65a6c3b26b1bd30b960325be8670339a66258b851ae170691429248149b601da5798f42d28",
In nodeURL we will put the url of the node where we will have everything related to Identity displayed In AddressPassword, we will put the Password of the address that has displayed the contracts that will act as admin, and it will be our first issuer and who will generate the next issuer. In case you use different passwords for all accounts, you must change the password in every example. In the Alastria repository, all accounts have the same password which is Passw0rd. In adminPubK we will put the Public Key of the address that we are going to use as admin. In order to obtain said key, a script can be made that takes it from the keystore, or if we have the private key, there are online options such as: ABDK Toolkit, with which we can obtain the rest of the Necessary data (address, short Public Key, long Public Key….). Or, we can use the following script to obtain the public key of each of the keystores that we want to use for the examples.
/* Example of how to obtain the public key through
* a private key using a keystore
*/
/* Requires needed. You have to install the following
* packages
* npm install ethereumjs-wallet keythereum
*/
const hdkey = require('ethereumjs-wallet/hdkey')
const privateKey = hdkey.fromMasterSeed('random')._hdkey._privateKey
const Wallet = require('ethereumjs-wallet')
const keythereum = require('keythereum')
const fs = require('fs')
// Account's password.
const password = "Passw0rd" // Add the account password if needed
// Load keystores
let keyData = fs.readFileSync('./keystore.json')
let keystoreData = JSON.parse(keyData)
// Obtain the private key account1 from the keystore
let account1PrivK
try{
account1PrivK = keythereum.recover(password, keystoreData)
}catch(error){
console.log("ERROR: ", error)
}
// Get the public key
const account1Puk = Wallet.fromPrivateKey(account1PrivK)
console.log("account1 pubk:", account1Puk.getPublicKeyString(),"\n")
In the entity [1-3] PubK we will put the public keys of the accounts that we are going to use in the examples as entities, which as it has been done with the public key of admin, we do it with them.