Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #158

Merged
merged 49 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f21c23d
point back to develop branch
VictorNS69 Mar 28, 2022
07efe78
Cambios necesarios para probar la versión 2.1
ManuelGCh Oct 13, 2022
0490148
Remove deprecated examples
Oct 17, 2022
011936f
Changed esLint versions to avoid problems with node v16
Oct 18, 2022
50298c7
rename and rearrange examples
Oct 18, 2022
858fdbc
added new example of getCredentialStatus
Oct 18, 2022
9908469
added all possible examples about credentials and presentations excep…
Oct 18, 2022
808b110
added new example of revoke a credential directly without prior ancho…
Oct 19, 2022
9227eb0
cleaned 8.revokeEntity1CredentialDirectly.js and added explanatory co…
Oct 19, 2022
5357599
rename examples to have the same structure in the presentation folder…
Oct 21, 2022
c80134e
Add 8.revokeSubject1PresentationDirectly.js
ManuelGCh Oct 21, 2022
57471f7
Remove duplicate examples
Oct 21, 2022
060a8dc
Merge branch 'develop' into feature/upgradeables
DaniRumpi Oct 28, 2022
725ab90
Merge pull request #137 from alastria/feature/upgradeables
rober12 Oct 28, 2022
b7809ba
Fix version
rober12 Nov 4, 2022
4a6210b
Merge pull request #138 from alastria/fix/version_compile
DaniRumpi Nov 4, 2022
c12dcc8
point back to develop branch
rober12 Nov 4, 2022
61cce1a
Merge pull request #139 from alastria/PointBackDevelop
DaniRumpi Nov 7, 2022
9aa73fb
added new example of how to build a multivalued credential
Nov 8, 2022
c66f094
fix the numbering of the credential examples
Nov 8, 2022
ab22b79
added neccesary information to configuration.json to build multivalue…
Nov 8, 2022
2b27af3
Merge pull request #142 from alastria/feature/multivaluedCredentials
DaniRumpi Nov 11, 2022
9e858cb
added a complete example of creating, signing and validating an Alast…
rober12 Feb 17, 2023
b35b713
Correct some values of configuration.json
rober12 Feb 17, 2023
35edcfd
added a complete example of creating, signing and validating an Alast…
rober12 Feb 17, 2023
e30f4c7
added a complete example of creating, signing and validating an Alast…
rober12 Feb 17, 2023
be64ce3
added a complete example of creating, signing and validating a verifi…
rober12 Feb 17, 2023
a583090
added complete examples of create DID and decode/validate JWTs
rober12 Feb 17, 2023
799e749
fixed publicKey of FirstIdentity
rober12 Feb 17, 2023
e7f2226
added complete examples of creating, signing and validating a present…
rober12 Feb 17, 2023
1b7935a
all examples finished
rober12 Feb 17, 2023
2acf263
publicKeys corrected in configuration.json, old script 1.tokenFactory…
rober12 Feb 20, 2023
d60b086
unifying names
rober12 Feb 20, 2023
1ccd47d
removed scripts
rober12 Feb 20, 2023
03020c1
removed unused variables
rober12 Feb 20, 2023
3bb561a
fixed script to correct some values
rober12 Feb 20, 2023
01832ca
Merge pull request #153 from alastria/feature/objects-artifacts
DaniRumpi Mar 7, 2023
5967b96
update all alastria artifacts and objects with the new specification
rober12 Mar 7, 2023
85295b4
fix example 3.updateEntity2Presentation.js
rober12 Mar 9, 2023
ac7f6f4
Merge pull request #154 from alastria/feature/objects-artifacts
DaniRumpi Mar 9, 2023
3089a49
update package.json description
rober12 May 20, 2024
5c223e5
update createAlastriaID functions and package.json
rober12 May 20, 2024
7e22244
update .gitignore to remove package-lock.json from the repository
rober12 May 20, 2024
ca88c88
Remove unnecessary file
rober12 May 20, 2024
7772ced
update publicKey examples
rober12 May 21, 2024
ee14a88
removed unnecessary console.log
rober12 May 22, 2024
ea80ef1
Merge pull request #157 from alastria/feature/public-key-hash
DaniRumpi May 22, 2024
4e54649
update README.md
rober12 May 22, 2024
c26d928
Merge branch 'master' into develop
DaniRumpi May 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ build/Release
# Dependency directories
node_modules/
jspm_packages/
package-lock.json

# TypeScript v1 declaration files
typings/
Expand Down
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,42 @@ tsc
|exampleAuthentication| It contains an example of how authentication is done |[Wiki](https://github.com/alastria/alastria-identity-example/wiki/Authentication-example)
|keystores| Contains the mocked keystores that we used to create the identities with different roles. These roles are explained [here](/keystores/README.md) |

## Environment requirements

**This section specifies the environment requirements for the successful execution of the examples.**

First of all, to avoid possible errors with node and npm, it is recommended that the installation is done through **Nvm**.

Once you have **Nvm installed**, all you need to do is install the required version of node with .
```sh
nvm install <version>
```

On the other hand, if any problem persists, it is recommended to **clean the npm cache** with the following command
```sh
npm cache clean -f
```

The list of Npm and Node versions that have worked for the different members of the core identity team are listed below.
|**Versions**|**Does it work?**|
|:--|:--|
|Node 14.19.0 && Npm 6.14.16|**OK**|
|Node 14.20 && Npm 6.14.17|**OK**|
|Node 14.20.1 && Npm 6.14.17|**OK**|
|Node 16.13.0 && Npm 8.15.0|**OK**|
|Node 16.13.2 && Npm 8.1.2|**OK**|
|Node 16.14 && Npm 8.3.1|**OK**|
|Node 18.19.0 && Npm 10.2.3|**OK**|

### Problems with the version of the library and the json-objects installed when running npm install
If you encounter problems with the version of the library and the json-objects that are installed after npm install, you need to perform the following steps to solve these problems:
- Delete node_modules folder -> `rm -rf node_modules`
- Delete the package-lock.json -> `rm package-lock.json`
- Clean the cache -> `npm cache clean -f`
- Install all dependencies -> `npm install` (from the root directory)

Following these steps then check that the version of the library and the json objects that have been installed are correct. To do this go to the `node_modules -> alastria-identity-lib` folder and look at the code inside, to check if it is the one you want.
Perform the same checking operation for the json-object code `node_modules -> alastria-identity-json-objects`

## How to use it

Expand Down
89 changes: 45 additions & 44 deletions configuration.json
Original file line number Diff line number Diff line change
@@ -1,84 +1,85 @@
{
"nodeURL": "http://63.33.206.111/rpc",
"nodeURL": "http://<redT-nodeIP>",
"addressPassword": "Passw0rd",
"rawPublicKeySubject": "03fdd57adec3d438ea237fe46b33ee1e016eda6b585c3e27ea66686c2ea5358479",
"rawPublicKeyReceiver": "8b82bb2b1b5b4c1d56beeb88c98fcf894c23e8dee598d94c1c77099d3a80367f46",
"firstIdentityPubk": "0x0ce5edc204ae977d6d69fcc6b339a57b544ef4d094929f3eb918a77dfba26998e77ec5b29a379dd59bbe962e2b22745143aa2b52c4a875b7492c137eeebf4055",
"firstIdentityPubk": "0xaca7aa42e831f41b6f246d089fbcabe73e1c6ce01a1bb5d944fda4e148e1d6930f6ebb5138b1d103e3e384c893962a238e4088a549bfe84867da96942931f69a",
"entity1Pubk": "0x356e3fce435d8729062e52d263c0c705b3c5e201a9a9608cdb070764e6b8df30ae8423b439a7af2bcc3529778341ab06c1e44411352f217b68ce44a673a1df63",
"entity2Pubk": "0xa33e56a80b9dc83a4456265d877c0765cea76146e625572fc679804f8867222ca3c816433a9b6e6690b0b8e919ffa874982706e812314aae09d85fc62fc4fa3c",
"entity3Pubk": "0xf6aa52924a7280241bd84d098d7c03b4e3a7e08f206b68868f439b65a6c3b26b1bd30b960325be8670339a66258b851ae170691429248149b601da5798f42d28",
"subject1Pubk": "0x2e507af01167c98a6accc0cd46ab2a256dd6b6c69ec1c0c28f80fb62e1f7d70233768b0c58dbbdac1fc358b8141c075a520483cf9779e4ea98d13df2833f3767",
"subject2Pubk": "0xaca7aa42e831f41b6f246d089fbcabe73e1c6ce01a1bb5d944fda4e148e1d6930f6ebb5138b1d103e3e384c893962a238e4088a549bfe84867da96942931f69a",
"rawPrivateKey": "278a5de700e29faae8e40e366ec5012b5ec63d36ec77e8a2417154cc1d25383f",
"subject2Pubk": "0x028c2b8f606bc8b9803f0ccb753bf4ef4372e2ddfa69d875e2bb6cad68fd7b3bb2f42231714c21f1963b3c6282d85619cd52c470cc743277de3f438dec53732e",
"context": [
"https://w3id.org/did/v1",
"JWT"
"https://www.w3.org/2018/credentials/v1",
"https://w3id.org/did/v1"
],
"type": [
"CustomType"
],
"signedTxCreateAlastriaID": "0xf901888203f180830927c094bd4a2c84edb97be5beff7cd341bd63567e73f8c980b901246d69d99a000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000c450382c1a000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000803265353037616630313136376339386136616363633063643436616232613235366464366236633639656331633063323866383066623632653166376437303233333736386230633538646262646163316663333538623831343163303735613532303438336366393737396534656139386431336466323833336633373637000000000000000000000000000000000000000000000000000000001ca0e3e05abb1592bd15dc72e57d8930c24efdd0e286437a34ca2f118372ad428b25a0480ac816c93a5c1e8eff1dfd96f850dc664c5daa1ff94a88bdf789b0652ebfd3",
"userPublicKey": "AE2309349218937HASKHIUE9287432",
"providerURL": "https://regular.telsius.blockchainbyeveris.io:2000",
"callbackURL": "https://serviceprovider.alastria.blockchainbyeveris.io/api/login/",
"providerURL": "http://63.33.206.111/rpc",
"callbackURL": "https://entity.alastria/api/v1/login",
"mfau": "http://url/mfa_server",
"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",
"jti": "https://www.entity.com/alastria/credentials/3734",
"kidCredential": "did:ala:quor:redt:12eeaCCA9eEbB78eB97d7cac6b#keys-1",
"subjectAlastriaID": "did:ala:quor:redt:0x12eeaCCA9eEbB78eB97d7cac6b",
"credentialKey": "StudentID",
"credentialValue": "11235813",
"credentialKeyFather": "Driving license",
"credentialValueFather": {},
"credentialSubKey1": "Driver`s Name",
"credentialSubKey2": "Driver`s Surname",
"credentialSubKey3": "Type of license",
"credentialSubKey4": "Years with the license",
"credentialSubValue1": "PersonName",
"credentialSubValue2": "PersonSurname",
"credentialSubValue3": "B",
"credentialSubValue4": "20 years",
"uri": "www.google.com",
"procUrl": "https://www.empresa.com/alastria/businessprocess/4583",
"procHash": "H398sjHd...kldjUYn475n",
"procUrl": "https://www.entity.com/alastria/businessprocess/4583",
"procHash": "dccf25f46542dfb668b931e7b7cef29731a1754f659c393eb801ca851bd15ffc",
"procDesc": "Short description to business process 4583",
"data": [
{
"@context": "JWT",
"@context": [
"JWT",
"https://alastria.github.io/identity/credentials/v1",
"https://www.w3.org/2018/identity/driving-license/v1"
],
"levelOfAssurance": 3,
"required": true,
"field_name": "name"
"field_name": "driving_license"
},
{
"@context": "JWT",
"levelOfAssurance": 3,
"@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": "0x706b3e4611a855b8b1267c4e9f0c77124af003fe",
"didEntity1": "did:ala:quor:redT:706b3e4611a855b8b1267c4e9f0c77124af003fe",
"entity2": "0x3729a1872356dd5c5ac377c85d539fe63cb561d8",
"didEntity2": "did:ala:quor:redT:3729a1872356dd5c5ac377c85d539fe63cb561d8",
"entity3": "0x0994bc29da542208e694f0de3138bb24006ac65c",
"didEntity3": "did:ala:quor:redT:0994bc29da542208e694f0de3138bb24006ac65c",
"subject1": "0xec27f358fd0d11d8934ceb51305622ae79b6ad15",
"didSubject1": "did:ala:quor:redT:ec27f358fd0d11d8934ceb51305622ae79b6ad15",
"subject2": "0x08462c184eb8ec89493db5e7390b91080174b603",
"didSubject2": "did:ala:quor:redT:08462c184eb8ec89493db5e7390b91080174b603",
"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,
"revokeEntity2Presentation": 3,
"updateIssuerCredentialTo": 2,
"subject1PresentationStatus": {
"exist": true,
Expand Down
119 changes: 88 additions & 31 deletions exampleAuthentication/1.authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@ const { tokensFactory } = require('alastria-identity-lib')
const fs = require('fs')
const keythereum = require('keythereum')

//Preparing to read configuration.json
const rawdata = fs.readFileSync('../configuration.json')
const configData = JSON.parse(rawdata)

//Preparing entity1 and subject1 keystore (privateKey)
const keyDataEntity1 = fs.readFileSync(
'../keystores/entity1-a9728125c573924b2b1ad6a8a8cd9bf6858ced49.json'
)
const keystoreDataEntity1 = JSON.parse(keyDataEntity1)
const keyDataSubject1 = fs.readFileSync(
'../keystores/subject1-806bc0d7a47b890383a831634bcb92dd4030b092.json'
)
const keystoreDataSubject1 = JSON.parse(keyDataSubject1)

// Init your blockchain provider

const entity1KeyStore = keystoreDataEntity1

let entity1PrivateKey
try {
entity1PrivateKey = keythereum.recover(
Expand All @@ -29,8 +23,11 @@ try {
process.exit(1)
}

const keyDataSubject1 = fs.readFileSync(
'../keystores/subject1-806bc0d7a47b890383a831634bcb92dd4030b092.json'
)
const keystoreDataSubject1 = JSON.parse(keyDataSubject1)
const subject1Keystore = keystoreDataSubject1

let subject1PrivateKey
try {
subject1PrivateKey = keythereum.recover(
Expand All @@ -42,51 +39,111 @@ try {
process.exit(1)
}

console.log('\n ------ Example of Authentication ------ \n')
// ***********************************************************************************************************************
// Starting reading/calculating DATA declared in configuration.json used to create the Alastria Token and Alastria Session
const randomCharacters =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
//Alastria Token info
const issAT = configData.didEntity1
const gwu = configData.providerURL
const cbu = configData.callbackURL
const exp = Math.round(Date.now() / 1000) + 600 // 10 min = 600 seconds
const nbf = Math.round(Date.now() / 1000) - 600 // 10 min before
const kidAT = issAT + '#keys-1' //header.KID
const jwkAT = configData.entity1Pubk //header.JWK
let jtiAT = ''
const jtiVariableLength = 20 //length of the variable part of the jti

//Generating a random JTI to AT
for (let i = 0; i < jtiVariableLength; i++) {
jtiAT += randomCharacters.charAt(
Math.floor(Math.random() * randomCharacters.length)
)
}
jtiAT = 'nameEntity/alastria/alastria-token/' + jtiAT

//Alastria Session info
const context = configData.context
const issAS = configData.didSubject1
const kidAS = issAS + '#keys-1'
const type = ['US211'] //other info setted in the library
const jwkAS = configData.subject1Pubk
let jtiAS = ''
const mfau = configData.mfau

//Generating a random JTI to AS
for (let i = 0; i < jtiVariableLength; i++) {
jtiAS += randomCharacters.charAt(
Math.floor(Math.random() * randomCharacters.length)
)
}
jtiAS = 'nameEntity/alastria/alastria-session/' + jtiAS
// Ending DATA reading/calculating
// ***********************************************************************************************************************

console.log('\t ------ Example of Authentication ------ \n')

//1 - First the entity creates Alastria Token artifact
console.log('\t 1 - Creating Alastria Token (AT)\n')

const alastriaToken = tokensFactory.tokens.createAlastriaToken(
configData.didEntity1,
configData.providerURL,
configData.callbackURL,
configData.networkId,
configData.tokenExpTime,
configData.kidCredential,
configData.entity1Pubk,
configData.tokenActivationDate,
configData.jsonTokenId
context,
issAT,
gwu,
cbu,
exp,
kidAT,
type,
mfau,
jwkAT,
nbf,
jtiAT
)
console.log('\tThe Alastria token is: \n', alastriaToken)
console.log('\nThe Alastria token is: \n', alastriaToken)

// Signing the AlastriaToken
//2 - The entity sign the Alastria Token
console.log('\t 2 - Signing Alastria Token (AT)\n')
const signedAT = tokensFactory.tokens.signJWT(alastriaToken, entity1PrivateKey)
console.log('\nThe Alastria token signed is: \n', signedAT)

//3 - To other communication channel (QR, Deeplink...) the entity sends to the subject AT artifact
// and the subject with the publicKey of the entity verifies it.
// '04' means uncompressed key (more info at https://github.com/indutny/elliptic/issues/138)
console.log('\t 3 - Subject verifies the Alastria Token (AT)\n')
const verifyAT = tokensFactory.tokens.verifyJWT(
signedAT,
'04' + configData.entity1Pubk.substr(2)
)
console.log('\tIs the signedJWT verified?', verifyAT)
console.log('\nIs the Alastria Token verified?', verifyAT)

//4 - Subject creates the Alastria Session to respond to the challenge set by the entity.
console.log('\t 4 - Creating Alastria Session (AS)\n')
const alastriaSession = tokensFactory.tokens.createAlastriaSession(
configData.context,
configData.didSubject1,
configData.subject1Pubk,
context,
issAS,
kidAS,
signedAT,
configData.tokenExpTime,
configData.tokenActivationDate,
configData.jsonTokenId
exp,
type,
jwkAS,
nbf,
jtiAS
)
console.log('\tThe Alastria session is:\n', alastriaSession)
console.log('\nThe Alastria session is:\n', alastriaSession)

//5 - The subject sign the Alastria Session
console.log('\t 5 - Signing Alastria Session (AS)\n')
const signedAS = tokensFactory.tokens.signJWT(
alastriaSession,
subject1PrivateKey
)
console.log('\tThe signedAS is:\n', signedAS)
console.log('\nThe Alastria Session signed is:\n', signedAS)

//6 - Answer to the cbu of the AT, the subject sends the AS to the entity
// '04' means uncompressed key (more info at https://github.com/indutny/elliptic/issues/138)
console.log('\t 6 - Entity verifies the Alastria Session (AS)\n')
const verifyAS = tokensFactory.tokens.verifyJWT(
signedAS,
'04' + configData.subject1Pubk.substr(2)
)
console.log('\tIs the signedJWT verified?', verifyAS)
console.log('\nIs the signedJWT verified?', verifyAS)
9 changes: 5 additions & 4 deletions exampleCreateAlastriaID/1.createEntity2AlastriaID.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ function preparedAlastriaId() {
}

function createAlastriaId() {
const txCreateAlastriaID = transactionFactory.identityManager.createAlastriaIdentity(
const entity2PubKeyHash = `${web3.utils.sha3(configData.entity2Pubk.substr(2))}`
const txCreateAlastriaID = transactionFactory.identityManager.createAlastriaIdentityHash(
web3,
configData.entity2Pubk.substr(2)
entity2PubKeyHash
)
return txCreateAlastriaID
}
Expand All @@ -96,7 +97,7 @@ async function main() {
const signedAT = tokensFactory.tokens.signJWT(at, entity1PrivateKey)
console.log('\tsignedAT: \n', signedAT)

const createResult = await createAlastriaId()
const createResult = createAlastriaId()
const signedCreateTransaction = await entity2Identity.getKnownTransaction(
createResult
)
Expand All @@ -117,7 +118,7 @@ async function main() {
// wallet address (from public key ir signst tx), entity2 public key, the tx which is signed by the entity2 and the signed AT

// Below, it should build the tx prepareAlastriaId and sign it
const prepareResult = await preparedAlastriaId()
const prepareResult = preparedAlastriaId()
const signedPreparedTransaction = await entity1Identity.getKnownTransaction(
prepareResult
)
Expand Down
Loading
Loading