def m_new_certificate(passenger_first_name: str, passenger_last_name: str, passenger_id_number: str, passenger_date_of_birth: str, analysis_id: str, analysis_ver: str, analysis_date: str, analysis_type: str, analysis_result: str, lab_name: str, lab_address: str, lab_phone: str, issuer_did: str, issuer_password: str): """Creates a new certificate. --- Definitions --- {"name": "passenger_first_name", "prompt": "Passenger first name", "default": "Alberto"} {"name": "passenger_last_name", "prompt": "Passenger last name", "default": "Costa"} {"name": "passenger_id_number", "prompt": "Document ID number", "default": "46106508H"} {"name": "passenger_date_of_birth", "prompt": "Passenger Date of Birth", "default": "27-04-1982"} {"name": "analysis_id", "prompt": "Diagnostic number", "default": "LE4RDS"} {"name": "analysis_ver", "prompt": "Diagnostic version", "default": "1"} {"name": "analysis_date", "prompt": "Diagnostic date", "default": "Now"} {"name": "analysis_type", "prompt": "Diagnostic type", "default": "Virolens"} {"name": "analysis_result", "prompt": "Result of diagnosis", "default": "FREE"} {"name": "lab_name", "prompt": "Laboratory name", "default": "Perfect Health plc"} {"name": "lab_address", "prompt": "Laboratory address", "default": "Wonderful Street 123, Perfect City, Valhalla"} {"name": "lab_phone", "prompt": "Laboratory phone", "default": "+3463540040"} {"name": "issuer_did", "prompt": "DID of Issuer", "default": "did:elsi:VATES-X12345678X"} {"name": "password", "prompt": "Password of Issuer", "default": "ThePassword"} """ # Data to be included for the UK (as 16-Jan-2021) # Name, which should match the name on the travel documents # Date of birth or age # The result of the test # The date the test sample was collected or received by the test provider # The name of the test provider and their contact details # The name of the test device if analysis_date == "Now": analysis_date = int(time.time()) # Create a credential with the diagnostic data claims = new_unsigned_credential(passenger_first_name, passenger_last_name, passenger_id_number, passenger_date_of_birth, analysis_id, analysis_ver, analysis_date, analysis_type, analysis_result, lab_name, lab_address, lab_phone, issuer_did) # Get the JWK key from the wallet key = wallet.key_JWK(issuer_did, issuer_password) if key is None: print("Error: key from wallet is None!") return None print(type(key)) # Create a signed Verifiable Credential in serialized JWT/JWS format # Assume the issuer is the Lanzarote Airport, subject is the citizen and should use her ID # Assume also that the password is the default one st = new_signed_credential(claims=claims, jwk_key=key) # Save the Credential in the database, indexed by its unique id hash = new_certificate(claims["uuid"], st) print(f"New certificate created: {st}")
def get_privatekey(account: str, password: str): """Get an existing private key in the wallet. Must specify an existing account name and its password """ key_jwk = wallet.key_JWK(account, password) response_jwk = key_jwk.export(private_key=True, as_dict=True) return response_jwk
def new_signed_credential(iss=None, sub=None, certificate=None, password=None): # Try to resolve the Issuer and get its DID Document DID, name, DIDDocument, active = tf.resolver.resolveDID(iss) # Check if the Issuer exists and return if not if DIDDocument is None: return None # Get the public Key from the DID Document did_key = DIDDocument["publicKey"][0] # Generate a template Verifiable Credential now = int(time.time()) validity = 5*24*60*60 # The token will expire in 6 days credential = { "iss": iss, "sub": sub, "iat": now, "exp": now + validity, "nbf": now, "vc": { "@context": [ "https://www.w3.org/2018/credentials/v1", "https://alastria.github.io/identity/credentials/v1", "https://safeisland.org/.well-known/christmasbasket/v1" ], "type": [ "VerifiableCredential", "AlastriaVerifiableCredential", "ChristmasBasket" ], "credentialSubject": { "issuedAt": "alastria.redt", "levelOfAssurance": 2, "christmasBasket": { } } } } # Fill the "christmasBasket" field of the Verifiable Credential credential["vc"]["credentialSubject"]["christmasBasket"] = certificate credential = json.dumps(credential, ensure_ascii=False, sort_keys=False) # The header of the JWT header = { "typ": "JWT", "alg": "ES256K", "kid": did_key["id"] } # Generate a JWT token, not yet signed token = jwt.JWT( algs=["ES256K"], header=header, claims=credential ) # Get the JWK key from the wallet key = wallet.key_JWK(DID, password) if key is None: return None print(type(key)) # Sign the JWT with the key token.make_signed_token(key) # Serialize the token for transmission or storage st = token.serialize() return st
def m_new_vaccination_certificate( passenger_first_name: str, passenger_last_name: str, passenger_id_number: str, passenger_date_of_birth: str, vaccination_disease: str, vaccination_vaccine: str, vaccination_product: str, vaccination_auth_holder: str, vaccination_dose_number: str, vaccination_total_doses: str, vaccination_batch: str, vaccination_date: str, vaccination_center: str, vaccination_professional: str, vaccination_country: str, issuer_did: str, issuer_password: str): """Creates a new certificate. --- Definitions --- {"name": "passenger_first_name", "prompt": "Passenger first name", "default": "Alberto"} {"name": "passenger_last_name", "prompt": "Passenger last name", "default": "Costa"} {"name": "passenger_id_number", "prompt": "Document ID number", "default": "46106508H"} {"name": "passenger_date_of_birth", "prompt": "Passenger Date of Birth", "default": "27-04-1982"} {"name": "vaccination_disease", "prompt": "Disease or agent targeted", "default": "COVID19"} {"name": "vaccination_vaccine", "prompt": "Vaccine / prophylaxis", "default": "1119349007 | COVID-19 mRNA vaccine"} {"name": "vaccination_product", "prompt": "Vaccine medicinal product", "default": "COMIRNATY concentrate for dispersion for injection"} {"name": "vaccination_auth_holder", "prompt": "Marketing Authorization Holder", "default": "Pfizer BioNTech"} {"name": "vaccination_dose_number", "prompt": "Order in the vaccination course", "default": "1"} {"name": "vaccination_total_doses", "prompt": "Total doses in series", "default": "2"} {"name": "vaccination_batch", "prompt": "Batch/lot number", "default": "AH65374U"} {"name": "vaccination_date", "prompt": "Date of vaccination", "default": "Now"} {"name": "vaccination_center", "prompt": "Administering centre", "default": "Perfect Health plc"} {"name": "vaccination_professional", "prompt": "Health Professional identification", "default": "ES46106508H"} {"name": "vaccination_country", "prompt": "Country of vaccination", "default": "ES"} {"name": "issuer_did", "prompt": "DID of Issuer", "default": "did:elsi:VATES-X12345678X"} {"name": "password", "prompt": "Password of Issuer", "default": "ThePassword"} """ # Data to be included for the UK (as 16-Jan-2021) # Name, which should match the name on the travel documents # Date of birth or age # The result of the test # The date the test sample was collected or received by the test provider # The name of the test provider and their contact details # The name of the test device if vaccination_date == "Now": vaccination_date = int(time.time()) vaccination_next_date = vaccination_date + 30 * 24 * 60 * 60 # Create a credential with the diagnostic data claims = new_unsigned_vaccination_credential( passenger_first_name, passenger_last_name, passenger_id_number, passenger_date_of_birth, vaccination_disease, vaccination_vaccine, vaccination_product, vaccination_auth_holder, vaccination_dose_number, vaccination_total_doses, vaccination_batch, vaccination_date, vaccination_next_date, vaccination_center, vaccination_professional, vaccination_country, issuer_did) # Get the JWK key from the wallet key = wallet.key_JWK(issuer_did, issuer_password) if key is None: print("Error: key from wallet is None!") return None print(type(key)) # Create a signed Verifiable Credential in serialized JWT/JWS format # Assume the issuer is the Lanzarote Airport, subject is the citizen and should use her ID # Assume also that the password is the default one st = new_signed_credential(claims=claims, jwk_key=key) # Save the Credential in the database, indexed by its unique id hash = new_certificate(claims["uuid"], st) print(f"New certificate created: {st}")
def create_test_credentials(): """Creates a new certificate. --- Definitions --- """ # The Issuer is the Perfect Health laboratory issuer_did = "did:elsi:VATES-X12345678X" issuer_password = "******" # Get the JWK key from the wallet key = wallet.key_JWK(issuer_did, issuer_password) if key is None: print("Error: key from wallet is None!") return None ################################################### # Start of credential creation ################################################### #################################################### # Create a credential with the diagnostic data claims = new_unsigned_credential( passenger_first_name="Alberto", passenger_last_name="Costa", passenger_id_number="46106508H", passenger_date_of_birth="27-04-1982", analysis_id="LE4RDS", analysis_ver="1", analysis_date=int(time.time()), analysis_type="Virolens", analysis_result="FREE", lab_name="Perfect Health plc", lab_address="Wonderful Street 123, Perfect City, Valhalla", lab_phone="+34635400401", issuer_did=issuer_did) print(f"Claims: {claims}") st = new_signed_credential(claims=claims, jwk_key=key) if st is None: print(f"Error creating signed credential") return # Save the Credential in the database, indexed by its unique id uuid = new_certificate(claims["uuid"], st) print( f"New certificate created: {uuid}, Credential Schema: {claims['vc']['credentialSchema']['id']}" ) #################################################### #################################################### #################################################### # Create a credential with the diagnostic data claims = new_unsigned_credential( passenger_first_name="Juan", passenger_last_name="Lopez", passenger_id_number="76443987U", passenger_date_of_birth="30-09-1954", analysis_id="JK8754FD", analysis_ver="1", analysis_date=int(time.time()), analysis_type="Virolens", analysis_result="FREE", lab_name="Perfect Health plc", lab_address="Wonderful Street 123, Perfect City, Valhalla", lab_phone="+34635400401", issuer_did=issuer_did) st = new_signed_credential(claims=claims, jwk_key=key) # Save the Credential in the database, indexed by its unique id uuid = new_certificate(claims["uuid"], st) print( f"New certificate created: {uuid}, Credential Schema: {claims['vc']['credentialSchema']['id']}" ) #################################################### #################################################### #################################################### # Create a credential with the diagnostic data claims = new_unsigned_credential( passenger_first_name="Perico", passenger_last_name="Perez", passenger_id_number="87335620L", passenger_date_of_birth="11-05-1977", analysis_id="IU4509VC", analysis_ver="1", analysis_date=int(time.time()), analysis_type="PCR", analysis_result="FREE", lab_name="Perfect Health plc", lab_address="Wonderful Street 123, Perfect City, Valhalla", lab_phone="+34635400401", issuer_did=issuer_did) st = new_signed_credential(claims=claims, jwk_key=key) # Save the Credential in the database, indexed by its unique id uuid = new_certificate(claims["uuid"], st) print( f"New certificate created: {uuid}, Credential Schema: {claims['vc']['credentialSchema']['id']}" ) #################################################### #################################################### #################################################### # Create a Vaccination credential claims = new_unsigned_vaccination_credential( passenger_first_name="Perico", passenger_last_name="Perez", passenger_id_number="87335620L", passenger_date_of_birth="11-05-1977", vaccination_disease="COVID19", vaccination_vaccine="1119349007 | COVID-19 mRNA vaccine", vaccination_product= "COMIRNATY concentrate for dispersion for injection", vaccination_auth_holder="Pfizer BioNTech", vaccination_dose_number="1", vaccination_total_doses="2", vaccination_batch="AH65374U", vaccination_date=int(time.time()), vaccination_next_date=int(time.time()) + 30 * 24 * 60 * 60, vaccination_center="Perfect Health plc", vaccination_professional="ES46106508H", vaccination_country="ES", issuer_did=issuer_did) st = new_signed_credential(claims=claims, jwk_key=key) # Save the Credential in the database, indexed by its unique id uuid = new_certificate(claims["uuid"], st) print( f"New certificate created: {uuid}, Credential Schema: {claims['vc']['credentialSchema']['id']}" )