Skip to content

Commit

Permalink
Merge pull request #153 from alastria/feature/objects-artifacts
Browse files Browse the repository at this point in the history
Feature/objects artifacts
  • Loading branch information
DaniRumpi authored Mar 7, 2023
2 parents 2b27af3 + 3bb561a commit 01832ca
Show file tree
Hide file tree
Showing 12 changed files with 698 additions and 289 deletions.
57 changes: 19 additions & 38 deletions configuration.json
Original file line number Diff line number Diff line change
@@ -1,83 +1,64 @@
{
"nodeURL": "http://63.33.206.111/rpc",
"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 licence",
"credentialKeyFather": "Driving license",
"credentialValueFather": {},
"credentialSubKey1": "Driver`s Name",
"credentialSubKey2": "Driver`s Surname",
"credentialSubKey3": "Type of licence",
"credentialSubKey4": "Years with the licence",
"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",
"data": [
{
"@context": "JWT",
"@context": "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": "https://www.w3.org/2018/identity/email/v1",
"levelOfAssurance": 0,
"required": true,
"field_name": "email"
}
],
"entity1": "0xd1f4cfd94a0b3d92f737f9a16685fa69ed2c9a8f",
"didEntity1": "did:ala:quor:redT:d1f4cfd94a0b3d92f737f9a16685fa69ed2c9a8f",
"entity1": "0xdb040fd6acca0e742898484bd2738b38a8c57aa8",
"didEntity1": "did:ala:quor:redT:db040fd6acca0e742898484bd2738b38a8c57aa8",
"entity2": "0x82f83d802f235955e9543d3f8e485ccd06436a89",
"didEntity2": "did:ala:quor:redT:82f83d802f235955e9543d3f8e485ccd06436a89",
"entity3": "0x220ea50a0315eb025ebfb8c309d515ea5a4ac3c4",
Expand Down
117 changes: 82 additions & 35 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,101 @@ 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 ani = configData.networkId
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 = ""

//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
issAT,
gwu,
cbu,
ani,
exp,
kidAT,
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,
type,
signedAT,
configData.tokenExpTime,
configData.tokenActivationDate,
configData.jsonTokenId
exp,
jwkAS,
nbf,
jtiAS
)
console.log('\tThe Alastria session is:\n', alastriaSession)
console.log('\nThe Alastria session is:\n', alastriaSession)

const signedAS = tokensFactory.tokens.signJWT(
alastriaSession,
subject1PrivateKey
)
console.log('\tThe signedAS is:\n', signedAS)
//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('\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)
83 changes: 83 additions & 0 deletions exampleTokens/1.alastriaToken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
const { tokensFactory } = require('alastria-identity-lib')
const { tests } = require('alastria-identity-JSON-objects/tests')
const fs = require('fs')
const keythereum = require('keythereum')

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

const rawDataSignedObjects = fs.readFileSync('./SignedObjects.json')
const configDataSignedObjects = JSON.parse(rawDataSignedObjects)

//FirstIdentity = Entity1
const keyDataFirstIdentity = fs.readFileSync(
'../keystores/firstIdentity-643266eb3105f4bf8b4f4fec50886e453f0da9ad.json'
)
const keystoreDataFirstIdentity = JSON.parse(keyDataFirstIdentity)

let firstIdentityPrivateKey
try {
firstIdentityPrivateKey = keythereum.recover(configData.addressPassword, keystoreDataFirstIdentity)
} catch (error) {
console.error('ERROR: ', error)
process.exit(1)
}

// **************************************************************************************************
// Starting reading/calculating DATA declared in configuration.json used to create the Alastria Token
const randomCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
const iss = configData.didEntity1
const gwu = configData.providerURL
const cbu = configData.callbackURL
const ani = configData.networkId
const exp = Math.round(Date.now() / 1000) + 600 // 10 min = 600 seconds
const nbf = Math.round(Date.now() / 1000) - 600 // 10 min before
const kid = iss + "#keys-1" //header.KID
const jwk = configData.firstIdentityPubk //header.JWK
let jti = ""
const jtiVariableLength = 20 //length of the variable part of the jti
// IAT does not need to be passed, the library calculates it.

//Neeed to added in the librery first to Alastria Token artifact
const type = ["US12"] // the type "AlastriaToken" is setted in the library
const context = configData.context
const mfau = configData.mfau

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

//Creating Alastria Token
console.log('\t 1 - Creating Alastria Token (AT)\n')
const alastriaToken = tokensFactory.tokens.createAlastriaToken(
iss,
gwu,
cbu,
ani,
exp,
kid,
jwk,
nbf,
jti
)
console.log('\nThe Alastria Token (AT) is: \n', alastriaToken)

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

// Validating the AlastriaToken
console.log('\t 3 - Validating the Alastria Token (AT)\n')
tests.tokens.validateToken(signedAT)

configDataSignedObjects.signedAT = signedAT
fs.writeFileSync(
'./SignedObjects.json',
JSON.stringify(configDataSignedObjects, null, 4)
)
Loading

0 comments on commit 01832ca

Please sign in to comment.