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

Fix/additional fields #62

Merged
merged 6 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ EMAIL_TRANSPORTER = AWS
# KEY_MANAGER_DID_JWT = /did-jwt/generate
# KEY_MANAGER_DID_COMM_ENCRYPT = /didcomm/x25519/encrypt
# KEY_MANAGER_SECP256K1_PLAIN_MESSAGE_SIGN = /secp256k1/sign/plain-message
# KEY_MANAGER_SECP256K1_SIGN_LACCHAIN_TRANSACTION=/secp256k1/sign/lacchain-tx


## Chain Of trust
Expand Down Expand Up @@ -111,4 +112,5 @@ NODE_ADDRESS = 0xad730de8c4bfc3d845f7ce851bcf2ea17c049585
# CHAIN_OF_TRUST_CONTRACT_ADDRESS = '0x25a64325d73cB7226EBcC390600ccB6a7557e4f1' # Mandatory. Update this value accordinly

## verification registry
# VERIFICATION_REGISTRY_CONTRACT_ADDRESS = '0xcd438C44caf4346EaA44ff47825c6C34Ce73a616' # optional, just in case you are willing to use another verification registry
# PROOF_OF_EXISTENCE_MODE = "ENABLED_NOT_THROWABLE" # options: "STRICT", "DISABLED", by default "ENABLED_NOT_THROWABLE"
# VERIFICATION_REGISTRY_CONTRACT_ADDRESS = '0xF17Da8641771c0196318515b662b0C00132C4163' # optional, just in case you are willing to use another verification registry
4 changes: 3 additions & 1 deletion .example.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ EMAIL_TRANSPORTER = AWS
# KEY_MANAGER_DID_JWT = /did-jwt/generate
# KEY_MANAGER_DID_COMM_ENCRYPT = /didcomm/x25519/encrypt
# KEY_MANAGER_SECP256K1_PLAIN_MESSAGE_SIGN = /secp256k1/sign/plain-message
# KEY_MANAGER_SECP256K1_SIGN_LACCHAIN_TRANSACTION=/secp256k1/sign/lacchain-tx


## Chain Of trust
Expand Down Expand Up @@ -110,4 +111,5 @@ NODE_ADDRESS = 0xad730de8c4bfc3d845f7ce851bcf2ea17c049585
# CHAIN_OF_TRUST_CONTRACT_ADDRESS = '0x25a64325d73cB7226EBcC390600ccB6a7557e4f1' # Mandatory. Update this value accordinly

## verification registry
# VERIFICATION_REGISTRY_CONTRACT_ADDRESS = '0xcd438C44caf4346EaA44ff47825c6C34Ce73a616' # optional, just in case you are willing to use another verification registry
# PROOF_OF_EXISTENCE_MODE = "ENABLED_NOT_THROWABLE" # options: "STRICT", "DISABLED", by default "ENABLED_NOT_THROWABLE"
# VERIFICATION_REGISTRY_CONTRACT_ADDRESS = '0xF17Da8641771c0196318515b662b0C00132C4163' # optional, just in case you are willing to use another verification registry
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

### 0.0.7

* Add PoE for emitted credentials.
* Add configuration variable `PROOF_OF_EXISTENCE_MODE` to set PoE mode:
* DISABLED: Proof of existence is disabled, in the respose the field TxHash is set to null
* STRICT: Proof of existence must strictly succeed otherwise the request throws and in the respose the field TxHash is set to null, otherwise that field will have a valid transaction hash
* ENABLED_NOT_THROWABLE: If Proof of existence fails the request does not throw but in the respose the field TxHash is set to null, otherwise that field will have a valid transaction hash
* Updates verification registry to '0xF17Da8641771c0196318515b662b0C00132C4163' which by default uses
didRegistry: 0x43dE0954a2c83A415d82b9F31705B969b5856003
* Considers certificate period fields (if defined) as the verifiable credential issuance/expiration dates
* Add additional fields
* validates mandatory and optional DDCCCoreDataSet fields
* Downgrades ethers to version 5.6.5 since it was needed to use GasModel Library.

### 0.0.6

* add additional codes for "brand" field used to transform DDCCCoreDataSeet to Verifiable Credential.
Expand Down
141 changes: 107 additions & 34 deletions docs/Credential-Sending.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,114 @@
api_url=http://localhost:3010 # Set LACPass API url
```

2. Send DDCC data through to patient wallet
2. Send DDCC data to patient wallet

```sh
## input variables
path_to_qr=../qr-code-examples/qr-example-1 # you should point to the public pem certificate that represents the signing certificate used to sign
issuer_did="did:lac1:1iT4kYaSKhpM7BFB75ZxYF7V3uTRAeWfPvwhFZXJQj8WrJakCczSatqNVvKZTnsD3uMz"
receiver_did="did:lac1:1iT5hMy9wbHfnd7C7QJCsQEiF7PusFngyCu2YqgLmCNJPQX77Z8WaXG6cwQtC4czY74w" #TODO: use
country_code="CL"
vaccine_code="J07BB04"
date="1998-06-04"
dose=1
center='Vaccination Site'
brand_code='XM4YL8'
lot='PO1234'

#patient
birthDate='1996-08-12'
name='John Doe'
identifier='UY/CU353467'
sex='male'

country='{"code": '\"$country_code\"'}'
vaccine='{"code": '\"$vaccine_code\"'}'
brand='{"code": '\"$brand_code\"'}'
vaccination='{"date": '\"$date\"', "dose": '$dose',"country": '$country', "center": '\"$center\"' ,"vaccine": '$vaccine', "brand": '$brand', "lot": '\"$lot\"'}'
ddccData='{"vaccination":'$vaccination', "birthDate": '\"$birthDate\"', "name": '\"$name\"', "identifier": '\"$identifier\"', "sex": '\"$sex\"'}'

echo 'sending data: ...'
echo $ddccData | jq

## TODO: add additional fields

# process
send_ddcc_vc_url="$api_url"/api/v1/verifiable-credential/ddcc/send
data='{"issuerDid":'\"$issuer_did\"', "receiverDid":'\"$receiver_did\"', "ddccData": '$ddccData'}'
curl -X 'POST' ${send_ddcc_vc_url} -H 'accept: application/json' -F qrCode=@$path_to_qr -F data="$data"
curl -X 'POST' \
'http://localhost:3010/api/v1/verifiable-credential/ddcc/send' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"bundle": {
"resourceType": "Bundle",
"id": "4ca19732-837a-48a3-8059-f98acee1ed73",
"meta": {
"versionId": "2",
"lastUpdated": "2023-08-21T19:28:47.673+00:00",
"source": "#0QGP9sLFOsQcEoOG"
},
"identifier": {
"system": "http://worldhealthorgnaization.github.io/ddcc/Document",
"value": "5ca19732-837a-48a3-8059-f98bcee1ed73"
},
"type": "document",
"timestamp": "2023-08-21T19:28:45.964Z",
"link": [
{
"relation": "publication",
"url": "urn:HCID:6624"
}
],
"entry": [
{
"fullUrl": "urn:uuid:351be87f-e802-4b94-8cfd-46e81aa2cd5b",
"resource": {
"resourceType": "DocumentReference",
"meta": {
"profile": [
"http://worldhealthorganization.github.io/ddcc/StructureDefinition/DDCCDocumentReferenceQR"
]
},
"status": "current",
"type": {
"coding": [
{
"system": "http://worldhealthorganization.github.io/ddcc/CodeSystem/DDCC-QR-Type-CodeSystem",
"code": "who",
"display": "WHO DDCC"
}
]
},
"subject": {
"reference": "urn:uuid:28a20344-6f4c-4cc3-adfa-2fdfb59cdeff"
},
"authenticator": {
"reference": "urn:uuid:56e370bb-9f09-345c-b0a5-3c76422a1491"
},
"description": "WHO QR code for COVID 19 Vaccine Certificate",
"content": [
{
"attachment": {
"contentType": "application/json",
"data": "ewogICAgICAicmVzb3VyY2VUe...yIsCiAgICAgICJzZXgiIDogIm1hbGUiCiAgICB9Cg=="
},
"format": {
"system": "http://worldhealthorganization.github.io/ddcc/CodeSystem/DDCC-QR-Format-CodeSystem",
"code": "serialized"
}
},
{
"attachment": {
"contentType": "image/png",
"data": "iVBORw0KUV...ORK5CYII="
},
"format": {
"system": "http://worldhealthorganization.github.io/ddcc/CodeSystem/DDCC-QR-Format-CodeSystem",
"code": "image"
}
},
{
"attachment": {
"contentType": "application/pdf",
"data": "JVBERi0xLjcW5kc3RyZWFtCmVuZG9iagoKOCAwIG9i...HN0cmVhbQplbmRvYmoKCnN0YXJ0eHJlZgoyNDMxOAolJUVPRg=="
},
"format": {
"system": "http://worldhealthorganization.github.io/ddcc/CodeSystem/DDCC-QR-Format-CodeSystem",
"code": "pdf"
}
}
]
}
}
],
"signature": {
"type": [
{
"system": "urn:iso-astm:E1762-95:2013",
"code": "1.2.840.10065.1.12.1.5"
}
],
"when": "2023-08-22T19:38:45.964Z",
"who": {
"identifier": {
"value": "Some Identifier"
}
},
"data": "prOxII3XzrdsOihKp...AN+wAV6m5RxmTdGfUJQkmdXXrVKEw7xl/Q+E+nLcO6NcAKuD+QhGPc0w=="
}
},
"issuerDid": "did:lac1:1iT5NSDvBrkYQ9oDtGAdeyYjwDDJLGKbEY4RGzG253RpyEMjiEURhgRTw96qnTfcqNpa",
"receiverDid": "did:lac1:1iT5QTdhkxWeZALaQMMhwsDzYZmbmE2dD3UZZ1LtdY7BzH6vZEta3AzsJD7RoRjaRkrB"
}'
```

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lacpass-client",
"version": "0.0.6",
"version": "0.0.7",
"description": "Rest api for lacpass Client",
"license": "MIT",
"scripts": {
Expand Down Expand Up @@ -74,7 +74,7 @@
"class-validator-jsonschema": "^2.2.0",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"ethers": "^6.3.0",
"ethers": "^5.6.5",
"express": "^4.17.3",
"express-formidable": "^1.2.0",
"express-rate-limit": "^6.3.0",
Expand Down
27 changes: 26 additions & 1 deletion src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import { VERIFICATION_REGISTRY_CONTRACT_ADDRESSES } from '@constants/verification.registry';
import { randomUUID } from 'crypto';
import { config } from 'dotenv';
import { isAddress } from 'ethers';
import { LogLevel } from 'typescript-logging';
import { Log4TSProvider } from 'typescript-logging-log4ts-style';
import { version } from 'package.json';
import { isAddress } from 'ethers/lib/utils';
import { ProofOfExistenceMode } from '@constants/poe';

config({ path: `.env.${process.env.ENV || 'dev'}` });

Expand Down Expand Up @@ -35,6 +36,29 @@ export const getChainId = (): string => {

export const CHAIN_ID = getChainId();

export const resolveProofOfExistenceMode = () => {
const pOEValue = process.env.PROOF_OF_EXISTENCE_MODE;
let mode: ProofOfExistenceMode;
if (!pOEValue || pOEValue === 'ENABLED_NOT_THROWABLE') {
mode = ProofOfExistenceMode.ENABLED_NOT_THROWABLE;
} else if (pOEValue === 'STRICT') {
mode = ProofOfExistenceMode.STRICT;
} else if (pOEValue === 'DISABLED') {
mode = ProofOfExistenceMode.DISABLED;
} else {
log.error(
'Invalid option for PROOF_OF_EXISTENCE_MODE environment variable, found',
pOEValue,
'. Exiting ...'
);
process.exit(1);
}
log.info(`Setting Proof Existence Mode to', ${mode} for`, pOEValue);
return mode;
};

export const PROOF_OF_EXISTENCE_MODE = resolveProofOfExistenceMode();

export const resolveVerificationRegistryContractAddress = (
verificationRegistryContractAddress = process.env
.VERIFICATION_REGISTRY_CONTRACT_ADDRESS
Expand Down Expand Up @@ -150,6 +174,7 @@ export const {
KEY_MANAGER_DID_JWT,
KEY_MANAGER_DID_COMM_ENCRYPT,
KEY_MANAGER_SECP256K1_PLAIN_MESSAGE_SIGN,
KEY_MANAGER_SECP256K1_SIGN_LACCHAIN_TRANSACTION,
SECURE_RELAY_MESSAGE_DELIVERER_BASE_URL,
SECURE_RELAY_MESSAGE_DELIVERER_SEND
} = process.env;
17 changes: 17 additions & 0 deletions src/constants/disease.code.mapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// reference: http://lacpass.create.cl:8089/ValueSet-ddcc-vaccines.html
export const DISEASE_LIST: Map<string, string> = new Map<string, string>();

DISEASE_LIST.set('RA01', 'COVID-19');
DISEASE_LIST.set('1D47', 'Yellow fever');
DISEASE_LIST.set('1F03', 'Measles');
DISEASE_LIST.set('1F03.0', 'Measles without complication');
DISEASE_LIST.set('1F03.1', 'Measles complicated by encephalitis');
DISEASE_LIST.set('1F03.2', 'Measles complicated by meningitis');
DISEASE_LIST.set('1F03.Y', 'Measles with other complications');
DISEASE_LIST.set('1C81', 'Acute poliomyelitis');
DISEASE_LIST.set('XN9S3', 'Yellow fever virus');
DISEASE_LIST.set('XN186', 'Measles virus');
DISEASE_LIST.set('XN3M0', 'Poliovirus');
DISEASE_LIST.set('XN6KZ', 'Wild poliovirus type 1');
DISEASE_LIST.set('XN9CF', 'Wild poliovirus type 2');
DISEASE_LIST.set('XN97R', 'Wild poliovirus type 3');
11 changes: 10 additions & 1 deletion src/constants/errorMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export enum ErrorsMessages {
PASSWORD_ERROR = 'Property password must be longer than or equal to 6 characters',
// HTTP STANDARD MESSAGES
INTERNAL_SERVER_ERROR = 'Internal Server Error',
// eslint-disable-next-line max-len
INDEPENDENT_MISCONFIGURATION_ERROR = 'Service is expected to be configured as independent service but critical variables are missing',
// eslint-disable-next-line max-len
PROOF_OF_EXISTENCE_FAILED = 'There was an error while attempting to register a Proof of existence',
BAD_REQUEST_ERROR = 'Bad request error',
USER_ALREADY_EXISTS = 'A user with this email is already registered',
CREATE_DID_ERROR = 'An internal server error occurred while trying to create a new did',
Expand All @@ -37,6 +41,7 @@ export enum ErrorsMessages {
VACCINATION_MISSING_ATTRIBUTE = 'No vaccination attribute was found',
COUNTRY_MISSING_ATTRIBUTE = 'No country attribute was found',
VACCINE_MISSING_ATTRIBUTE = 'No vaccine attribute was found',
BRAND_MISSING_ATTRIBUTE = 'No brand attribute was found',
PLAIN_MESSAGE_SIGNING_ERROR = 'There was an error while trying to sign plain message',
CANONICALIZE_ERROR = 'An error occurred while trying to canonicalize message',
VM_NOT_FOUND = 'Verification method was not found',
Expand All @@ -51,7 +56,11 @@ export enum ErrorsMessages {
DDCCCOREDATASET_NOT_FOUND = 'No ddcCoredataSet was found',
DDCCCOREDATASET_PARSE_ERROR = 'The specified ddcCoredataSet could not be parsed',
// eslint-disable-next-line max-len
DDCCCOREDATASET_ATTRIBUTE_NOT_FOUND = 'ddccCoreDataSet attribute inside parsed data'
LACCHAIN_CONTRACT_TRANSACTION_ERROR = 'There was an error, there may be an issue with the params you are sending',
// eslint-disable-next-line max-len
CHAIN_ID_FROM_DID_NOT_SUPPORTED = 'The chain id extracted from the passed DID is not supported',
// eslint-disable-next-line max-len
SIGN_TRANSACTION_ERROR = 'An error occurred while trying to sign transaction against external service'
}

export const Errors = {
Expand Down
Loading
Loading