Skip to content

Commit 208ecce

Browse files
authored
Removed DIDs and updated to new signing scheme (#1)
1 parent 68eb6d7 commit 208ecce

16 files changed

+351
-710
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,5 @@ cython_debug/
143143
save/
144144
myenv/
145145
sample_vcs/
146-
did.json
146+
jwks_private.json
147+
jwks.json

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,31 @@ Before you can run scripts, you must first activate your virtual environment. Yo
1717
source myenv/bin/activate
1818
```
1919

20-
## Generate a DID
21-
To generate a random DID, use the following command:
20+
## Generate a JWK Set
21+
To generate a random JWK Set, use the following command:
2222

2323
```
24-
python generate_random_did.py did.json
24+
python generate_random_jwks.py jwks.json jwks_private.json
2525
```
2626

27-
This script will generate the necessary JWK formatted keys and create a new DID based on them, saving them `did.json`.
27+
This script will generate the necessary JWK formatted keys, saving the public keyset in `jwks.json` and the private keyset in `jwks_private.json`.
2828

2929
## Generate a VC
3030
To generate a sample VC, use the following command:
3131

3232
```
33-
python encode_resource.py did.json ./fixtures/vc-c19-pcr-jwt-payload.json sample_vcs/sample.fhir-backed-vc
33+
python encode_resource.py jwks_private.json https://commonhealth.org fixtures/vc-c19-pcr-jwt-payload.json sample_vcs/lab_result.smart-health-card
3434
```
3535

36-
This script uses the DID config defined in `did.json`, generates a new VC based on `./fixtures/vc-c19-pcr-jwt-payload.json`, and saves that in `sample_vcs/sample.fhir-backed-vc`.
36+
This script uses the private JWK set defined in `jwks_private.json`, generates a new VC based on `./fixtures/vc-c19-pcr-jwt-payload.json`, and saves that in `sample_vcs/lab_result.smart-health-card`.
3737

3838
## Verify a VC
3939
To verifiy a VC, use the following command:
4040

4141
```
42-
python decode_resource.py sample_vcs/sample.fhir-backed-vc
42+
python decode_resource.py sample_vcs/covid19.smart-health-card
4343
```
4444

45-
This script loads the VC from `sample_vcs/sample.fhir-backed-vc`, and verifies it based on the DID encoded in the JWS header.
45+
This script loads the VC from `sample_vcs/covid19.smart-health-card`, and verifies it based on the issuer and kid information encoded in the JWS.
4646

4747

decode_inline.py

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,10 @@
1-
from did.did_service import DIDService
2-
from did.did import DIDPublicKeyDocument
3-
from jwcrypto import jwk, jws
4-
from jwcrypto.common import json_encode
51
import json
62
import argparse
73
import base64
8-
9-
did_service = DIDService()
10-
11-
def get_did_from_header(jws_raw):
12-
##instantiate a JWS object
13-
jwstoken = jws.JWS()
14-
15-
##import the data into the JWS object
16-
jwstoken.deserialize(jws_raw)
17-
18-
##based on the JWS header, resolve the public signing key to be used for verification
19-
kid = jwstoken.jose_header.get('kid')
20-
split = kid.split("#")
21-
did = split[0]
22-
return did
23-
24-
def decode_vc(jws_raw):
25-
##instantiate a JWS object
26-
jwstoken = jws.JWS()
27-
28-
##import the data into the JWS object
29-
jwstoken.deserialize(jws_raw)
30-
31-
##based on the JWS header, resolve the public signing key to be used for verification
32-
kid = jwstoken.jose_header.get('kid')
33-
key = did_service.resolve_key(kid)
34-
35-
##load the JWK into a useable key
36-
verifier_key = jwk.JWK.from_json(json.dumps(key))
37-
38-
##verify the payload
39-
jwstoken.verify(verifier_key)
40-
return jwstoken
4+
import utils
415

426
def main():
43-
parser = argparse.ArgumentParser(description='Decodes a vc using the supplied DID config')
7+
parser = argparse.ArgumentParser(description='Decodes a vc')
448
parser.add_argument('input', help='Input resource')
459
args = parser.parse_args()
4610

@@ -51,12 +15,7 @@ def main():
5115
print("Base 64 decoding failed, assuming input is JWS")
5216
jws_raw = args.input
5317

54-
# print(jws_raw)
55-
decoded_vc = decode_vc(jws_raw)
56-
payload_dict = json.loads(decoded_vc.payload)
57-
58-
##check that iss matches did in header
59-
assert payload_dict['iss'] == get_did_from_header(jws_raw)
18+
payload_dict = utils.decode_vc(jws_raw)
6019

6120
print(json.dumps(payload_dict, indent=4))
6221

decode_resource.py

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,15 @@
1-
from did.did_service import DIDService
2-
from did.did import DIDPublicKeyDocument
3-
from jwcrypto import jwk, jws
4-
from jwcrypto.common import json_encode
51
import json
62
import argparse
7-
8-
did_service = DIDService()
9-
10-
def get_did_from_header(jws_raw):
11-
##instantiate a JWS object
12-
jwstoken = jws.JWS()
13-
14-
##import the data into the JWS object
15-
jwstoken.deserialize(jws_raw)
16-
17-
##based on the JWS header, resolve the public signing key to be used for verification
18-
kid = jwstoken.jose_header.get('kid')
19-
split = kid.split("#")
20-
did = split[0]
21-
return did
22-
23-
def decode_vc(jws_raw):
24-
##instantiate a JWS object
25-
jwstoken = jws.JWS()
26-
27-
##import the data into the JWS object
28-
jwstoken.deserialize(jws_raw)
29-
30-
##based on the JWS header, resolve the public signing key to be used for verification
31-
kid = jwstoken.jose_header.get('kid')
32-
key = did_service.resolve_key(kid)
33-
34-
##load the JWK into a useable key
35-
verifier_key = jwk.JWK.from_json(json.dumps(key))
36-
37-
##verify the payload
38-
jwstoken.verify(verifier_key)
39-
return jwstoken
3+
import utils
404

415
def main():
42-
parser = argparse.ArgumentParser(description='Decodes a vc using the supplied DID config')
6+
parser = argparse.ArgumentParser(description='Decodes a vc')
437
parser.add_argument('input_file', help='Input file')
448

459
args = parser.parse_args()
4610
with open(args.input_file, 'r') as input_file:
4711
fhir_backed_vc = json.load(input_file).get('verifiableCredential')[0]
48-
decoded_vc = decode_vc(fhir_backed_vc)
49-
payload_dict = json.loads(decoded_vc.payload)
50-
51-
##check that iss matches did in header
52-
assert payload_dict['iss'] == get_did_from_header(fhir_backed_vc)
12+
payload_dict = utils.decode_vc(fhir_backed_vc)
5313

5414
print(json.dumps(payload_dict, indent=4))
5515

decode_resource_local.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import json
2+
import argparse
3+
import utils
4+
5+
def main():
6+
parser = argparse.ArgumentParser(description='Decodes a vc')
7+
parser.add_argument('input_file', help='Input file')
8+
parser.add_argument('jwks_file', help='JWKS file')
9+
10+
args = parser.parse_args()
11+
with open(args.input_file, 'r') as input_file:
12+
fhir_backed_vc = json.load(input_file).get('verifiableCredential')[0]
13+
payload_dict = utils.decode_vc_from_local_issuer(fhir_backed_vc, args.jwks_file)
14+
15+
print(json.dumps(payload_dict, indent=4))
16+
17+
if __name__ == "__main__":
18+
main()

did/did.py

Lines changed: 0 additions & 144 deletions
This file was deleted.

0 commit comments

Comments
 (0)