Skip to content

Commit

Permalink
Merge pull request #154 from alastria/feature/objects-artifacts
Browse files Browse the repository at this point in the history
update all alastria artifacts and objects with the new specification
  • Loading branch information
DaniRumpi authored Mar 9, 2023
2 parents 01832ca + 85295b4 commit ac7f6f4
Show file tree
Hide file tree
Showing 18 changed files with 9,571 additions and 1,520 deletions.
5 changes: 3 additions & 2 deletions configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,16 @@
"uri": "www.google.com",
"procUrl": "https://www.entity.com/alastria/businessprocess/4583",
"procHash": "dccf25f46542dfb668b931e7b7cef29731a1754f659c393eb801ca851bd15ffc",
"procDesc": "Short description to business process 4583",
"data": [
{
"@context": "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": "https://www.w3.org/2018/identity/email/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"
Expand Down
38 changes: 24 additions & 14 deletions exampleAuthentication/1.authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,38 +41,43 @@ try {

// ***********************************************************************************************************************
// Starting reading/calculating DATA declared in configuration.json used to create the Alastria Token and Alastria Session
const randomCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
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 kidAT = issAT + '#keys-1' //header.KID
const jwkAT = configData.entity1Pubk //header.JWK
let jtiAT = ""
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 += randomCharacters.charAt(
Math.floor(Math.random() * randomCharacters.length)
)
}
jtiAT = "nameEntity/alastria/alastria-token/" + jtiAT
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 kidAS = issAS + '#keys-1'
const type = ['US211'] //other info setted in the library
const jwkAS = configData.subject1Pubk
let jtiAS = ""
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 += randomCharacters.charAt(
Math.floor(Math.random() * randomCharacters.length)
)
}
jtiAS = "nameEntity/alastria/alastria-session/" + jtiAS
jtiAS = 'nameEntity/alastria/alastria-session/' + jtiAS
// Ending DATA reading/calculating
// ***********************************************************************************************************************

Expand All @@ -82,12 +87,14 @@ console.log('\t ------ Example of Authentication ------ \n')
console.log('\t 1 - Creating Alastria Token (AT)\n')

const alastriaToken = tokensFactory.tokens.createAlastriaToken(
context,
issAT,
gwu,
cbu,
ani,
exp,
kidAT,
type,
mfau,
jwkAT,
nbf,
jtiAT
Expand Down Expand Up @@ -115,9 +122,9 @@ const alastriaSession = tokensFactory.tokens.createAlastriaSession(
context,
issAS,
kidAS,
type,
signedAT,
exp,
type,
jwkAS,
nbf,
jtiAS
Expand All @@ -126,7 +133,10 @@ 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)
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
Expand Down
22 changes: 13 additions & 9 deletions exampleCredentials/1.addEntity1Credential.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,30 @@ const subjectAlastriaID = configData.subjectAlastriaID
const didEntity1 = configData.didEntity1
const context = configData.context
const tokenExpTime = configData.tokenExpTime
const tokenActivationDate = configData.tokenActivationDate
const nbf = Math.round(Date.now() / 1000) - 86400
const jwk = configData.entity1Pubk

// Credential Map (key-->value)
const credentialSubject = {}
const credentialKey = configData.credentialKey
const credentialValue = configData.credentialValue
credentialSubject[credentialKey] = credentialValue
credentialSubject.levelOfAssurance = 'basic'
const type = ['DrivingLicense']

// End fake data to test

const credential = tokensFactory.tokens.createCredential(
didEntity1,
context,
credentialSubject,
kidCredential,
subjectAlastriaID,
tokenExpTime,
tokenActivationDate,
jti
didEntity1,
context,
credentialSubject,
type,
kidCredential,
subjectAlastriaID,
tokenExpTime,
nbf,
jti,
jwk
)
console.log('The credential1 is: ', credential)

Expand Down
Loading

0 comments on commit ac7f6f4

Please sign in to comment.