fix render templates
This commit is contained in:
parent
10a2d680af
commit
fda78d7358
File diff suppressed because one or more lines are too long
|
@ -71,7 +71,7 @@ def generate_keys():
|
|||
def gen_did_document(did, keys):
|
||||
if did[:8] != "did:web:":
|
||||
return "", ""
|
||||
document = did_document_tmpl.copy()
|
||||
document = json.loads(did_document_tmpl)
|
||||
webdid_owner = did+"#owner"
|
||||
webdid_revocation = did+"#revocation"
|
||||
document["id"] = did
|
||||
|
|
|
@ -11,7 +11,7 @@ from pyvckit.sign import sign_proof
|
|||
def sign(credential, key, issuer_did):
|
||||
document = json.loads(credential)
|
||||
_did = issuer_did + "#" + issuer_did.split("did:key:")[1]
|
||||
proof = proof_tmpl.copy()
|
||||
proof = json.loads(proof_tmpl)
|
||||
proof['verificationMethod'] = _did
|
||||
proof['created'] = now()
|
||||
|
||||
|
@ -31,7 +31,7 @@ def main():
|
|||
did = generate_did(key)
|
||||
signing_key = get_signing_key(key)
|
||||
|
||||
credential = credential_tmpl.copy()
|
||||
credential = json.loads(credential_tmpl)
|
||||
credential["issuer"] = did
|
||||
credential["issuanceDate"] = now()
|
||||
cred = json.dumps(credential)
|
||||
|
|
|
@ -8,12 +8,12 @@ from pyvckit.sign import sign_proof
|
|||
|
||||
|
||||
def sign_vp(signing_key, holder_did, vc):
|
||||
presentation = presentation_tmpl.copy()
|
||||
presentation = json.loads(presentation_tmpl)
|
||||
presentation["verifiableCredential"].append(json.loads(vc))
|
||||
presentation["holder"] = holder_did
|
||||
|
||||
_did = holder_did + "#" + holder_did.split("did:key:")[1]
|
||||
proof = proof_tmpl.copy()
|
||||
proof = json.loads(proof_tmpl)
|
||||
proof['verificationMethod'] = _did
|
||||
proof['created'] = now()
|
||||
|
||||
|
|
|
@ -1,35 +1,37 @@
|
|||
# templates
|
||||
|
||||
|
||||
credential_tmpl = {
|
||||
credential_tmpl = """{
|
||||
"@context": "https://www.w3.org/2018/credentials/v1",
|
||||
"id": "http://example.org/credentials/3731",
|
||||
"type": ["VerifiableCredential"],
|
||||
"type": [
|
||||
"VerifiableCredential"
|
||||
],
|
||||
"credentialSubject": {
|
||||
"id": "did:key:z6MkgGXSJoacuuNdwU1rGfPpFH72GACnzykKTxzCCTZs6Z2M",
|
||||
"id": "did:key:z6MkgGXSJoacuuNdwU1rGfPpFH72GACnzykKTxzCCTZs6Z2M"
|
||||
},
|
||||
"issuer": None,
|
||||
"issuanceDate": None
|
||||
}
|
||||
"issuer": "",
|
||||
"issuanceDate": ""
|
||||
}"""
|
||||
|
||||
proof_tmpl = {
|
||||
'@context':'https://w3id.org/security/v2',
|
||||
'type': 'Ed25519Signature2018',
|
||||
'proofPurpose': 'assertionMethod',
|
||||
'verificationMethod': None,
|
||||
'created': None
|
||||
}
|
||||
proof_tmpl = """{
|
||||
"@context":"https://w3id.org/security/v2",
|
||||
"type": "Ed25519Signature2018",
|
||||
"proofPurpose": "assertionMethod",
|
||||
"verificationMethod": "",
|
||||
"created": ""
|
||||
}"""
|
||||
|
||||
presentation_tmpl = {
|
||||
presentation_tmpl = """{
|
||||
"@context": ["https://www.w3.org/2018/credentials/v1"],
|
||||
"id": "http://example.org/presentations/3731",
|
||||
"type": ["VerifiablePresentation"],
|
||||
"holder": "",
|
||||
"verifiableCredential": []
|
||||
}
|
||||
}"""
|
||||
|
||||
|
||||
did_document_tmpl = {
|
||||
did_document_tmpl = """{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/did/v1",
|
||||
{
|
||||
|
@ -64,4 +66,4 @@ did_document_tmpl = {
|
|||
"serviceEndpoint": "data:application/octet-stream;base64,eJyzMmAAAwADKABr"
|
||||
}
|
||||
]
|
||||
}
|
||||
}"""
|
||||
|
|
2
setup.py
2
setup.py
|
@ -9,7 +9,7 @@ test_requires = [
|
|||
|
||||
setup(
|
||||
name="pyvckit",
|
||||
version="0.0.6",
|
||||
version="0.0.7",
|
||||
packages=['pyvckit'],
|
||||
install_requires=[
|
||||
"jsonref",
|
||||
|
|
|
@ -147,6 +147,36 @@ def test_verifiable_credential():
|
|||
assert verified
|
||||
|
||||
|
||||
def test_verifiable_presentation():
|
||||
key = generate_keys()
|
||||
did = generate_did(key)
|
||||
signing_key = get_signing_key(key)
|
||||
|
||||
credential = {
|
||||
"@context": "https://www.w3.org/2018/credentials/v1",
|
||||
"id": "http://example.org/credentials/3732",
|
||||
"type": ["VerifiableCredential"],
|
||||
"credentialSubject": {
|
||||
"id": "did:key:z6MkgGXSJoacuuNdwU1rGfPpFH72GACnzykKTxzCCTZs6Z2M",
|
||||
},
|
||||
"issuer": did,
|
||||
"issuanceDate": now()
|
||||
}
|
||||
|
||||
cred = json.dumps(credential)
|
||||
|
||||
vc = sign(cred, signing_key, did)
|
||||
vc_json = json.dumps(vc)
|
||||
assert verify_vc(json.dumps(vc))
|
||||
|
||||
holder_key = generate_keys()
|
||||
holder_did = generate_did(holder_key)
|
||||
holder_signing_key = get_signing_key(holder_key)
|
||||
vp = sign_vp(holder_signing_key, holder_did, vc_json)
|
||||
verified = verify_vp(json.dumps(vp))
|
||||
assert verified
|
||||
|
||||
|
||||
def test_verifiable_credential_fail():
|
||||
key = generate_keys()
|
||||
did = generate_did(key)
|
||||
|
@ -171,35 +201,6 @@ def test_verifiable_credential_fail():
|
|||
assert not verified
|
||||
|
||||
|
||||
def test_verifiable_presentation():
|
||||
key = generate_keys()
|
||||
did = generate_did(key)
|
||||
signing_key = get_signing_key(key)
|
||||
|
||||
credential = {
|
||||
"@context": "https://www.w3.org/2018/credentials/v1",
|
||||
"id": "http://example.org/credentials/3731",
|
||||
"type": ["VerifiableCredential"],
|
||||
"credentialSubject": {
|
||||
"id": "did:key:z6MkgGXSJoacuuNdwU1rGfPpFH72GACnzykKTxzCCTZs6Z2M",
|
||||
},
|
||||
"issuer": did,
|
||||
"issuanceDate": now()
|
||||
}
|
||||
|
||||
cred = json.dumps(credential)
|
||||
|
||||
vc = sign(cred, signing_key, did)
|
||||
vc_json = json.dumps(vc)
|
||||
|
||||
holder_key = generate_keys()
|
||||
holder_did = generate_did(holder_key)
|
||||
holder_signing_key = get_signing_key(holder_key)
|
||||
vp = sign_vp(holder_signing_key, holder_did, vc_json)
|
||||
verified = verify_vp(json.dumps(vp))
|
||||
assert verified
|
||||
|
||||
|
||||
def test_verifiable_presentation_fail1():
|
||||
key = generate_keys()
|
||||
did = generate_did(key)
|
||||
|
|
Loading…
Reference in a new issue