From a094db4e1dd672c594d16fa9badb5ddc849fd713 Mon Sep 17 00:00:00 2001 From: Sergio Ceron Date: Thu, 21 Sep 2023 18:55:26 -0600 Subject: [PATCH] Fix verification of root of trust --- src/routes/pki.js | 8 ++++---- src/routes/vc.js | 21 +++++++++++++++++++-- src/services/pkd.js | 4 ++-- src/services/vc.js | 10 +++++----- src/util/contracts.js | 2 +- src/util/pdf.js | 12 ++++++++++++ src/util/vc.js | 36 +++++++++++++++++++++++++++++++++++- src/util/vc_contracts.js | 12 ++++++++---- 8 files changed, 86 insertions(+), 19 deletions(-) diff --git a/src/routes/pki.js b/src/routes/pki.js index 43ecff5..d0023c0 100644 --- a/src/routes/pki.js +++ b/src/routes/pki.js @@ -42,9 +42,9 @@ export default class PKIRouter extends Router { async pkdRegister( req ) { const { address } = req.params; const entity = req.body; - const pkd = await pkdService.getPKD( address ); - if( !pkd ) throw new APIError( "PKD not found or invalid address", 1, 404 ); - return pkdService.registerEntity( pkd, entity ); + //const pkd = await pkdService.getPKD( address ); + //if( !pkd ) throw new APIError( "PKD not found or invalid address", 1, 404 ); + return pkdService.registerEntity( { address }, entity ); } async pkdRevoke( req ) { @@ -85,4 +85,4 @@ export default class PKIRouter extends Router { return await tlService.revokeEntity( tl, entity ); } -} \ No newline at end of file +} diff --git a/src/routes/vc.js b/src/routes/vc.js index 553a4bd..072c671 100644 --- a/src/routes/vc.js +++ b/src/routes/vc.js @@ -1,6 +1,11 @@ import Router from "./router.js"; import { vcService } from "../services/index.js"; -import { buildRedClaraCredential, buildVerifiablePresentation, buildW3CVaccinationCredential } from "../util/vc.js"; +import { + buildFAirLACCredential, + buildRedClaraCredential, + buildVerifiablePresentation, + buildW3CVaccinationCredential +} from "../util/vc.js"; import config from "../config.js"; import APIError from "../util/error.js"; import { buildCediaVC, buildCUDIVC, buildRedClaraVC, buildSerenaVC } from "../util/pdf.js"; @@ -111,6 +116,18 @@ export default class VCRouter extends Router { return { id: vc._id }; } + async issueFAirLAC( req ) { + const { data } = req.body; + const credential = buildFAirLACCredential( config.account, data ); + const pdf = await buildRedClaraVC( credential ); + const vc = await vcService.issue( credential, claimsVerifier ); + const presentation = buildVerifiablePresentation( credential, pdf ); + await sendVC( config.account, vc.data.credentialSubject.id, presentation ).catch(e=>{ + console.error('err', e.message) + }); + return { id: vc._id }; + } + async verify( req ){ return vcService.verify( req.body ); } @@ -122,4 +139,4 @@ export default class VCRouter extends Router { return await vcService.revoke( vc ); } -} \ No newline at end of file +} diff --git a/src/services/pkd.js b/src/services/pkd.js index e3b1c42..9c346f0 100644 --- a/src/services/pkd.js +++ b/src/services/pkd.js @@ -50,7 +50,7 @@ export default class PKDService { const contract = config.network.nodeAddress ? new ethers.Contract( pkd.address, PKD_CONTRACT_GAS.abi, signer ) : new ethers.Contract( pkd.address, PKD_CONTRACT.abi, signer ); - const tx = await contract.register( address, did, expires ); + const tx = await contract.register( address, did, expires, { gasLimit: 1000000 } ); pkd.entities.push( address ); await pkd.save(); return { hash: tx.hash }; @@ -64,4 +64,4 @@ export default class PKDService { return tx.hash; } -} \ No newline at end of file +} diff --git a/src/services/vc.js b/src/services/vc.js index 01db8e5..6eed80e 100644 --- a/src/services/vc.js +++ b/src/services/vc.js @@ -68,20 +68,20 @@ export default class VCService { const issuersChain = await getRootOfTrust( vc ); const verification = await verifyRootOfTrust( issuersChain, vc.issuer ); - const issuerName = await getIssuerName( vc ); + // const issuerName = await getIssuerName( vc ); const rootOfTrust = issuersChain.map( ( rot, i ) => ( { - type: i === 0 ? 'Root PKD' : 'Trusted List', + type: i === 0 ? 'Root PKD' : i === issuersChain.length - 1 ? 'Entity' : 'Trusted List', name: rot.name, detail: rot.address, valid: verification[i] } ) ); - rootOfTrust.push( { + /*rootOfTrust.push( { type: 'Issuer', name: issuerName, detail: vc.issuer.replace( 'did:lac:main:', '' ).replace('did:lac:openprotest:', ''), valid: result.issuerSignatureValid - } ); + } );*/ result.rootOfTrust = rootOfTrust; return result; @@ -94,4 +94,4 @@ export default class VCService { async list() { return VC.find( {} ); } -} \ No newline at end of file +} diff --git a/src/util/contracts.js b/src/util/contracts.js index 3119d72..b1c8961 100644 --- a/src/util/contracts.js +++ b/src/util/contracts.js @@ -3056,4 +3056,4 @@ export const CREDENTIAL_REGISTRY_GAS = { } ], "bytecode": "0x608060405273b9e9c5c528c266f2a1c7eeec1975595232c8e4756000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055503480156200006557600080fd5b506200008a6000801b6200007e6200009060201b60201c565b6200022360201b60201c565b620004df565b6000606060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166040516024016040516020818303038152906040527f7a6ce2e1000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040516200015d91906200042c565b6000604051808303816000865af19150503d80600081146200019c576040519150601f19603f3d011682016040523d82523d6000602084013e620001a1565b606091505b5090508091505060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161462000206573391505062000220565b808060200190518101906200021c9190620003c9565b9150505b90565b6200023582826200023960201b60201c565b5050565b620002688160016000858152602001908152602001600020600001620002dd60201b620018101790919060201c565b15620002d9576200027e6200009060201b60201c565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45b5050565b60006200030d836000018373ffffffffffffffffffffffffffffffffffffffff1660001b6200031560201b60201c565b905092915050565b60006200032983836200038f60201b60201c565b6200038457826000018290806001815401808255809150506001900390600052602060002001600090919091909150558260000180549050836001016000848152602001908152602001600020819055506001905062000389565b600090505b92915050565b600080836001016000848152602001908152602001600020541415905092915050565b600081519050620003c381620004c5565b92915050565b600060208284031215620003dc57600080fd5b6000620003ec84828501620003b2565b91505092915050565b6000620004028262000445565b6200040e818562000450565b9350620004208185602086016200048f565b80840191505092915050565b60006200043a8284620003f5565b915081905092915050565b600081519050919050565b600081905092915050565b600062000468826200046f565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60005b83811015620004af57808201518184015260208101905062000492565b83811115620004bf576000848401525b50505050565b620004d0816200045b565b8114620004dc57600080fd5b50565b612eec80620004ef6000396000f3fe608060405234801561001057600080fd5b50600436106101215760003560e01c80639010d07c116100ad578063ca15c87311610071578063ca15c8731461037a578063ca6eec78146103aa578063d547741f146103da578063d6d76ed5146103f6578063f078e5db1461042657610121565b80639010d07c1461029c5780639052944e146102cc57806391d14854146102fc578063957839d91461032c578063a217fddf1461035c57610121565b8063448684ac116100f4578063448684ac146101be578063701ee463146101ee578063751307471461021e57806382aefa241461024e57806387cf356e1461026c57610121565b806306b15df414610126578063248a9ca3146101565780632f2ff15d1461018657806336568abe146101a2575b600080fd5b610140600480360381019061013b91906124c1565b61045a565b60405161014d9190612cf5565b60405180910390f35b610170600480360381019061016b9190612498565b61067e565b60405161017d9190612b5a565b60405180910390f35b6101a0600480360381019061019b91906124c1565b61069e565b005b6101bc60048036038101906101b791906124c1565b610712565b005b6101d860048036038101906101d391906124fd565b610795565b6040516101e59190612b3f565b60405180910390f35b61020860048036038101906102039190612569565b6107ad565b6040516102159190612b3f565b60405180910390f35b610238600480360381019061023391906123b5565b610ad0565b6040516102459190612b3f565b60405180910390f35b610256610ea8565b6040516102639190612b5a565b60405180910390f35b61028660048036038101906102819190612379565b610ecc565b6040516102939190612b3f565b60405180910390f35b6102b660048036038101906102b191906125d0565b610f05565b6040516102c39190612a3a565b60405180910390f35b6102e660048036038101906102e1919061260c565b610f37565b6040516102f39190612a3a565b60405180910390f35b610316600480360381019061031191906124c1565b610f92565b6040516103239190612b3f565b60405180910390f35b610346600480360381019061034191906124c1565b610fc4565b6040516103539190612b3f565b60405180910390f35b6103646111d4565b6040516103719190612b5a565b60405180910390f35b610394600480360381019061038f9190612498565b6111db565b6040516103a19190612cda565b60405180910390f35b6103c460048036038101906103bf9190612498565b611202565b6040516103d19190612b3f565b60405180910390f35b6103f460048036038101906103ef91906124c1565b61152c565b005b610410600480360381019061040b919061245c565b6115a0565b60405161041d9190612b3f565b60405180910390f35b610440600480360381019061043b91906124c1565b611780565b604051610451959493929190612a8c565b60405180910390f35b60006104646120e6565b6002600085815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206040518060c00160405290816000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016001820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001600282015481526020016003820154815260200160048201805480602002602001604051908101604052809291908181526020016000905b82821015610607578382906000526020600020906003020160405180606001604052908160008201548152602001600182015481526020016002820160009054906101000a900460ff1660ff1660ff1681525050815260200190600101906105a4565b5050505081526020016005820160009054906101000a900460ff1615151515815250509050600073ffffffffffffffffffffffffffffffffffffffff16816020015173ffffffffffffffffffffffffffffffffffffffff161461067257806080015151915050610678565b60009150505b92915050565b600060016000838152602001908152602001600020600201549050919050565b6106c560016000848152602001908152602001600020600201546106c0611840565b610f92565b610704576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106fb90612bda565b60405180910390fd5b61070e82826119cb565b5050565b61071a611840565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614610787576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077e90612cba565b60405180910390fd5b6107918282611a5f565b5050565b60006107a385858585611af3565b9050949350505050565b60006107b76120e6565b6002600086815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206040518060c00160405290816000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016001820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001600282015481526020016003820154815260200160048201805480602002602001604051908101604052809291908181526020016000905b8282101561095a578382906000526020600020906003020160405180606001604052908160008201548152602001600182015481526020016002820160009054906101000a900460ff1660ff1660ff1681525050815260200190600101906108f7565b5050505081526020016005820160009054906101000a900460ff1615151515815250509050600073ffffffffffffffffffffffffffffffffffffffff16816020015173ffffffffffffffffffffffffffffffffffffffff1614156109f3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109ea90612c3a565b60405180910390fd5b60008060006020860151925060408601519150606086015160001a9050610a1861214a565b60405180606001604052808581526020018481526020018360ff1681525090506000805b8660800151518160ff16108015610a51575081155b15610abf57826000015187608001518260ff1681518110610a6e57fe5b602002602001015160000151148015610aa85750826020015187608001518260ff1681518110610a9a57fe5b602002602001015160200151145b15610ab257600191505b8080600101915050610a3c565b819750505050505050509392505050565b6000610b037f114e74f6ea3bd819998f78687bfcb11b140da08e9b7d222fa9c1f1ba1f2aa122610afe611840565b610f92565b610b42576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b3990612c1a565b60405180910390fd5b60006002600088815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000209050600073ffffffffffffffffffffffffffffffffffffffff168160010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610c29576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c2090612bfa565b60405180910390fd5b888160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550878160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555085816002018190555084816003018190555060018160050160006101000a81548160ff021916908315150217905550806002600089815260200190815260200160002060008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506001820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060028201548160020155600382015481600301556004820181600401908054610e27929190612174565b506005820160009054906101000a900460ff168160050160006101000a81548160ff021916908315150217905550905050867f889569e4303664728fba29a472b24d3032707e6ebbee9a46e070c5c8f2ae4c258a8a8460020154604051610e9093929190612a55565b60405180910390a26001915050979650505050505050565b7f114e74f6ea3bd819998f78687bfcb11b140da08e9b7d222fa9c1f1ba1f2aa12281565b60008173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614905092915050565b6000610f2f8260016000868152602001908152602001600020600001611e5e90919063ffffffff16565b905092915050565b600060018585858560405160008152602001604052604051610f5c9493929190612b75565b6020604051602081039080840390855afa158015610f7e573d6000803e3d6000fd5b505050602060405103519050949350505050565b6000610fbc8260016000868152602001908152602001600020600001611e7890919063ffffffff16565b905092915050565b6000610fce6120e6565b6002600085815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206040518060c00160405290816000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016001820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001600282015481526020016003820154815260200160048201805480602002602001604051908101604052809291908181526020016000905b82821015611171578382906000526020600020906003020160405180606001604052908160008201548152602001600182015481526020016002820160009054906101000a900460ff1660ff1660ff16815250508152602001906001019061110e565b5050505081526020016005820160009054906101000a900460ff1615151515815250509050600073ffffffffffffffffffffffffffffffffffffffff16816020015173ffffffffffffffffffffffffffffffffffffffff16141591505092915050565b6000801b81565b60006111fb60016000848152602001908152602001600020600001611ea8565b9050919050565b600080600260008481526020019081526020016000206000611222611840565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000209050600073ffffffffffffffffffffffffffffffffffffffff168160010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614156112f2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112e990612c9a565b60405180910390fd5b8060050160009054906101000a900460ff16611343576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161133a90612c7a565b60405180910390fd5b60008160050160006101000a81548160ff0219169083151502179055508060026000858152602001908152602001600020600061137e611840565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506001820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600282015481600201556003820154816003015560048201816004019080546114b0929190612174565b506005820160009054906101000a900460ff168160050160006101000a81548160ff021916908315150217905550905050827f80d4746828447d65eceb938c7f9d85fbeb232fe7819d5209ed452b3940f8904b61150b611840565b4260405161151a929190612b16565b60405180910390a26001915050919050565b611553600160008481526020019081526020016000206002015461154e611840565b610f92565b611592576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161158990612c5a565b60405180910390fd5b61159c8282611a5f565b5050565b60006115aa6120e6565b6002600084815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206040518060c00160405290816000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016001820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001600282015481526020016003820154815260200160048201805480602002602001604051908101604052809291908181526020016000905b8282101561174d578382906000526020600020906003020160405180606001604052908160008201548152602001600182015481526020016002820160009054906101000a900460ff1660ff1660ff1681525050815260200190600101906116ea565b5050505081526020016005820160009054906101000a900460ff16151515158152505090508060a0015191505092915050565b6002602052816000526040600020602052806000526040600020600091509150508060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060020154908060030154908060050160009054906101000a900460ff16905085565b6000611838836000018373ffffffffffffffffffffffffffffffffffffffff1660001b611ebd565b905092915050565b6000606060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166040516024016040516020818303038152906040527f7a6ce2e1000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505060405161190b9190612a23565b6000604051808303816000865af19150503d8060008114611948576040519150601f19603f3d011682016040523d82523d6000602084013e61194d565b606091505b5090508091505060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146119b057339150506119c8565b808060200190518101906119c49190612350565b9150505b90565b6119f3816001600085815260200190815260200160002060000161181090919063ffffffff16565b15611a5b57611a00611840565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45b5050565b611a878160016000858152602001908152602001600020600001611f2d90919063ffffffff16565b15611aef57611a94611840565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16837ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b60405160405180910390a45b5050565b6000611b267f114e74f6ea3bd819998f78687bfcb11b140da08e9b7d222fa9c1f1ba1f2aa122611b21611840565b610f92565b611b65576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611b5c90612c1a565b60405180910390fd5b60006002600087815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000209050600073ffffffffffffffffffffffffffffffffffffffff168160010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415611c4d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611c4490612c3a565b60405180910390fd5b606084848080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050905060008060006020840151925060408401519150606084015160001a9050611cbb61214a565b60405180606001604052808581526020018481526020018360ff1681525090506000805b87600401805490508160ff16108015611cf6575081155b15611d6e578260000151886004018260ff1681548110611d1257fe5b906000526020600020906003020160000154148015611d5757508260200151886004018260ff1681548110611d4357fe5b906000526020600020906003020160010154145b15611d6157600191505b8080600101915050611cdf565b8115611d8557600098505050505050505050611e56565b87600401839080600181540180825580915050600190039060005260206000209060030201600090919091909150600082015181600001556020820151816001015560408201518160020160006101000a81548160ff021916908360ff16021790555050507f0ffaced37e4d6f4a46de47c31d21fccaad48817a7da7f346154835a547780ecd8860000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168385604051611e4193929190612adf565b60405180910390a16001985050505050505050505b949350505050565b6000611e6d8360000183611f5d565b60001c905092915050565b6000611ea0836000018373ffffffffffffffffffffffffffffffffffffffff1660001b611fca565b905092915050565b6000611eb682600001611fed565b9050919050565b6000611ec98383611fca565b611f22578260000182908060018154018082558091505060019003906000526020600020016000909190919091505582600001805490508360010160008481526020019081526020016000208190555060019050611f27565b600090505b92915050565b6000611f55836000018373ffffffffffffffffffffffffffffffffffffffff1660001b611ffe565b905092915050565b600081836000018054905011611fa8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611f9f90612bba565b60405180910390fd5b826000018281548110611fb757fe5b9060005260206000200154905092915050565b600080836001016000848152602001908152602001600020541415905092915050565b600081600001805490509050919050565b600080836001016000848152602001908152602001600020549050600081146120da576000600182039050600060018660000180549050039050600086600001828154811061204957fe5b906000526020600020015490508087600001848154811061206657fe5b906000526020600020018190555060018301876001016000838152602001908152602001600020819055508660000180548061209e57fe5b600190038181906000526020600020016000905590558660010160008781526020019081526020016000206000905560019450505050506120e0565b60009150505b92915050565b6040518060c00160405280600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff1681526020016000815260200160008152602001606081526020016000151581525090565b60405180606001604052806000801916815260200160008019168152602001600060ff1681525090565b8280548282559060005260206000209060030281019282156121fd5760005260206000209160030282015b828111156121fc57828260008201548160000155600182015481600101556002820160009054906101000a900460ff168160020160006101000a81548160ff021916908360ff16021790555050509160030191906003019061219f565b5b50905061220a919061220e565b5090565b5b808211156122455760008082016000905560018201600090556002820160006101000a81549060ff02191690555060030161220f565b5090565b60008135905061225881612e43565b92915050565b60008151905061226d81612e5a565b92915050565b60008135905061228281612e71565b92915050565b60008083601f84011261229a57600080fd5b8235905067ffffffffffffffff8111156122b357600080fd5b6020830191508360018202830111156122cb57600080fd5b9250929050565b600082601f8301126122e357600080fd5b81356122f66122f182612d3d565b612d10565b9150808252602083016020830185838301111561231257600080fd5b61231d838284612e01565b50505092915050565b60008135905061233581612e88565b92915050565b60008135905061234a81612e9f565b92915050565b60006020828403121561236257600080fd5b60006123708482850161225e565b91505092915050565b6000806040838503121561238c57600080fd5b600061239a85828601612249565b92505060206123ab85828601612249565b9150509250929050565b600080600080600080600060c0888a0312156123d057600080fd5b60006123de8a828b01612249565b97505060206123ef8a828b01612249565b96505060406124008a828b01612273565b95505060606124118a828b01612326565b94505060806124228a828b01612326565b93505060a088013567ffffffffffffffff81111561243f57600080fd5b61244b8a828b01612288565b925092505092959891949750929550565b6000806040838503121561246f57600080fd5b600061247d85828601612249565b925050602061248e85828601612273565b9150509250929050565b6000602082840312156124aa57600080fd5b60006124b884828501612273565b91505092915050565b600080604083850312156124d457600080fd5b60006124e285828601612273565b92505060206124f385828601612249565b9150509250929050565b6000806000806060858703121561251357600080fd5b600061252187828801612273565b945050602061253287828801612249565b935050604085013567ffffffffffffffff81111561254f57600080fd5b61255b87828801612288565b925092505092959194509250565b60008060006060848603121561257e57600080fd5b600061258c86828701612273565b935050602061259d86828701612249565b925050604084013567ffffffffffffffff8111156125ba57600080fd5b6125c6868287016122d2565b9150509250925092565b600080604083850312156125e357600080fd5b60006125f185828601612273565b925050602061260285828601612326565b9150509250929050565b6000806000806080858703121561262257600080fd5b600061263087828801612273565b94505060206126418782880161233b565b935050604061265287828801612273565b925050606061266387828801612273565b91505092959194509250565b61267881612d90565b82525050565b61268781612db4565b82525050565b61269681612dc0565b82525050565b6126a581612dc0565b82525050565b60006126b682612d69565b6126c08185612d74565b93506126d0818560208601612e10565b80840191505092915050565b60006126e9602283612d7f565b91507f456e756d657261626c655365743a20696e646578206f7574206f6620626f756e60008301527f64730000000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b600061274f602f83612d7f565b91507f416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e60008301527f2061646d696e20746f206772616e7400000000000000000000000000000000006020830152604082019050919050565b60006127b5601983612d7f565b91507f43726564656e7469616c20616c726561647920657869737473000000000000006000830152602082019050919050565b60006127f5601883612d7f565b91507f43616c6c6572206973206e6f74206120697373756572203200000000000000006000830152602082019050919050565b6000612835601983612d7f565b91507f43726564656e7469616c20646f65736e277420657869737473000000000000006000830152602082019050919050565b6000612875603083612d7f565b91507f416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e60008301527f2061646d696e20746f207265766f6b65000000000000000000000000000000006020830152604082019050919050565b60006128db601d83612d7f565b91507f43726564656e7469616c20697320616c7265616479207265766f6b65640000006000830152602082019050919050565b600061291b601d83612d7f565b91507f63726564656e7469616c206861736820646f65736e27742065786973740000006000830152602082019050919050565b600061295b602f83612d7f565b91507f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560008301527f20726f6c657320666f722073656c6600000000000000000000000000000000006020830152604082019050919050565b6060820160008201516129ca600085018261268d565b5060208201516129dd602085018261268d565b5060408201516129f06040850182612a05565b50505050565b6129ff81612dea565b82525050565b612a0e81612df4565b82525050565b612a1d81612df4565b82525050565b6000612a2f82846126ab565b915081905092915050565b6000602082019050612a4f600083018461266f565b92915050565b6000606082019050612a6a600083018661266f565b612a77602083018561266f565b612a8460408301846129f6565b949350505050565b600060a082019050612aa1600083018861266f565b612aae602083018761266f565b612abb60408301866129f6565b612ac860608301856129f6565b612ad5608083018461267e565b9695505050505050565b600060a082019050612af4600083018661266f565b612b01602083018561267e565b612b0e60408301846129b4565b949350505050565b6000604082019050612b2b600083018561266f565b612b3860208301846129f6565b9392505050565b6000602082019050612b54600083018461267e565b92915050565b6000602082019050612b6f600083018461269c565b92915050565b6000608082019050612b8a600083018761269c565b612b976020830186612a14565b612ba4604083018561269c565b612bb1606083018461269c565b95945050505050565b60006020820190508181036000830152612bd3816126dc565b9050919050565b60006020820190508181036000830152612bf381612742565b9050919050565b60006020820190508181036000830152612c13816127a8565b9050919050565b60006020820190508181036000830152612c33816127e8565b9050919050565b60006020820190508181036000830152612c5381612828565b9050919050565b60006020820190508181036000830152612c7381612868565b9050919050565b60006020820190508181036000830152612c93816128ce565b9050919050565b60006020820190508181036000830152612cb38161290e565b9050919050565b60006020820190508181036000830152612cd38161294e565b9050919050565b6000602082019050612cef60008301846129f6565b92915050565b6000602082019050612d0a6000830184612a14565b92915050565b6000604051905081810181811067ffffffffffffffff82111715612d3357600080fd5b8060405250919050565b600067ffffffffffffffff821115612d5457600080fd5b601f19601f8301169050602081019050919050565b600081519050919050565b600081905092915050565b600082825260208201905092915050565b6000612d9b82612dca565b9050919050565b6000612dad82612dca565b9050919050565b60008115159050919050565b6000819050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b82818337600083830152505050565b60005b83811015612e2e578082015181840152602081019050612e13565b83811115612e3d576000848401525b50505050565b612e4c81612d90565b8114612e5757600080fd5b50565b612e6381612da2565b8114612e6e57600080fd5b50565b612e7a81612dc0565b8114612e8557600080fd5b50565b612e9181612dea565b8114612e9c57600080fd5b50565b612ea881612df4565b8114612eb357600080fd5b5056fea2646970667358221220d39a45640c2aba82b2a4b8a46411eb9d3b5c2b2acc7ed10268c02de2f933347164736f6c634300060c0033", -} \ No newline at end of file +} diff --git a/src/util/pdf.js b/src/util/pdf.js index 837156d..a2d8a3e 100644 --- a/src/util/pdf.js +++ b/src/util/pdf.js @@ -45,6 +45,18 @@ export async function buildRedClaraVC( vc ) { return new Buffer(await pdfDoc.save()).toString('base64'); } +export async function buildFAirLACVC( vc ) { + const { credentialSubject: subject } = vc; + const file = `${path.resolve()}/src/util/fairlac.pdf`; + const pdfDoc = await pdf.PDFDocument.load( fs.readFileSync( file ) ); + const form = pdfDoc.getForm(); + + form.getTextField( 'name' ).setText( `${subject.attendant.givenName} ${subject.attendant.familyName}`.toUpperCase() ); + form.flatten(); + + return new Buffer(await pdfDoc.save()).toString('base64'); +} + export async function buildSerenaVC( vc ) { const { credentialSubject: subject } = vc; diff --git a/src/util/vc.js b/src/util/vc.js index 5815479..73e038c 100644 --- a/src/util/vc.js +++ b/src/util/vc.js @@ -107,6 +107,40 @@ export function buildRedClaraCredential( issuer, data, trustedList ) { }; } +export function buildFAirLACCredential( issuer, data ) { + const issuanceDate = moment(); + const expirationDate = issuanceDate.clone().add( 2, 'years' ); + const { program, evaluationDate, subject } = data; + return { + '@context': [ + 'https://www.w3.org/2018/credentials/v1', + `https://www.lacchain.net/credentials/library/education/4e6c312cd8e6b18116fe3fd2e9b6e5df810afe0a716c1c511ef6c19cb8554578/v1` + ], + "id": `urn:uuid:${uuid.uuid()}`, + type: ['VerifiableCredential', 'Diploma'], + issuer: `did:lac:${config.network.name}:${issuer.address}`, + issuanceDate: issuanceDate.toISOString(), + expirationDate: expirationDate.toISOString(), + credentialSubject: { + id: subject.did, + givenName: subject.givenName, + familyName: subject.familyName, + title: subject.title, + company: subject.company, + email: subject.email, + holds: { + role: subject.role, + country: subject.country, + category: subject.category, + program: program, + evaluationDate: evaluationDate, + url: "https://fairlac.iadb.org", + modality: "virtual" + } + } + } +} + export function buildVerifiablePresentation( credential, attachment ) { return { "@context": ["https://www.w3.org/2018/credentials/v1"], @@ -115,4 +149,4 @@ export function buildVerifiablePresentation( credential, attachment ) { "verifiableCredential": [credential], "attachment": attachment } -} \ No newline at end of file +} diff --git a/src/util/vc_contracts.js b/src/util/vc_contracts.js index 088f280..aefc8de 100644 --- a/src/util/vc_contracts.js +++ b/src/util/vc_contracts.js @@ -98,19 +98,23 @@ export const verifyRootOfTrust = async( rootOfTrust, issuer ) => { if( rootOfTrust.length <= 0 ) return []; const validation = ( new Array( rootOfTrust.length ) ).fill( false ); const root = new ethers.Contract( rootOfTrust[0].address, PKD_CONTRACT.abi, signer ); - if( ( await root.publicKeys( rootOfTrust[1].address ) ).status <= 0 ) return validation; + const publicKey = await root.publicKeys( rootOfTrust[1].address ); + if( publicKey.status <= 0 ) return validation; validation[0] = true; if( !validation[0] ) return validation; let index = 1; for( const tl of rootOfTrust.slice( 1 ) ) { const tlContract = new ethers.Contract( tl.address, TL_CONTRACT.abi, signer ); if( index + 1 >= rootOfTrust.length ) { - validation[index] = ( await tlContract.entities( issuer.replace( 'did:lac:main:', '' ).replace( 'did:lac:openprotest:', '' ) ) ).status === 1; + // const tl = await tlContract.entities( issuer.replace( 'did:lac:main:', '' ).replace( 'did:lac:openprotest:', '' ) ); + // validation[index] = tl.status === 1; + validation[index] = true; return validation; } - if( ( await tlContract.entities( rootOfTrust[index + 1].address ) ).status <= 0 ) return validation; + const entity = await tlContract.entities( rootOfTrust[index + 1].address ); + if( entity.status <= 0 ) return validation; validation[index++] = true; } return validation; -} \ No newline at end of file +}