-
-
Save nutrina/9306e82080d34abc33aa696753c6c4f2 to your computer and use it in GitHub Desktop.
Create VC with type EthereumEip712Signature2021
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from copy import copy, deepcopy | |
from pprint import pprint | |
import didkit | |
import asyncio | |
import json | |
# JWK = '{"kty":"OKP","crv":"Ed25519","x":"PBcY2yJ4h_cLUnQNcYhplu9KQQBNpGxP4sYcMPdlu6I","d":"n5WUFIghmRYZi0rEYo2lz-Zg2B9B1KW4MYfJXwOXfyI"}' | |
JWK = '{"kty":"EC","crv":"secp256k1","x":"PdB2nS-knyAxc6KPuxBr65vRpW-duAXwpeXlwGJ03eU","y":"MwoGZ08hF5uv-_UEC9BKsYdJVSbJNHcFhR1BZWer5RQ","d":"z9VrSNNZXf9ywUx3v_8cLDhSw8-pvAT9qu_WZmqqfWM"}' | |
async def main(): | |
print("#" * 80) | |
# did = didkit.key_to_did("key", JWK) | |
did = didkit.key_to_did("ethr", JWK) | |
print("issuer: ", did) | |
credential = { | |
"type": ["VerifiableCredential"], | |
"issuer": did, | |
"@context": [ | |
"https://www.w3.org/2018/credentials/v1", | |
"https://w3id.org/vc/status-list/2021/v1", # for credentialStatus | |
], | |
"issuanceDate": "2022-07-19T10:42:24.883Z", | |
"expirationDate": "2022-10-17T10:42:24.883Z", | |
"credentialSubject": { | |
"@context": { | |
"hash": "https://schema.org/Text", | |
"provider": "https://schema.org/Text", | |
"metaPointer": "https://schema.org/URL", | |
"customInfo": "https://schema.org/Thing", | |
}, | |
"id": "did:pkh:eip155:1:0x12FeD9f987bc340c6bE43fD80aD641E8cD740682", | |
"hash": "v0.0.0:AjcRjxx7Hp3PKPSNwPeBJjR21pLyA14CVeQ1XijzxUc=", | |
"provider": "Twitter", | |
"metaPointer": "https://gitcoin.co/docs.html", | |
"customInfo": { | |
"field1": "value", | |
}, | |
}, | |
"credentialStatus": { | |
"id": "https://example.edu/credentials/status/3#94567", | |
"type": "StatusList2021Entry", | |
"statusPurpose": "revocation", | |
"statusListIndex": "94567", | |
"statusListCredential": "https://example.edu/credentials/status/3", | |
}, | |
} | |
################################################### | |
# Issue credential | |
# options = {"type": "Eip712Signature2021"} | |
verification_method = await didkit.key_to_verification_method("ethr", JWK) | |
print("verification_method:", verification_method) | |
options = { | |
# "proofPurpose": "assertionMethod", | |
"type": "EthereumEip712Signature2021", | |
"verificationMethod": verification_method, | |
} | |
# options = {} | |
credential = await didkit.issue_credential( | |
json.dumps(credential), json.dumps(options), JWK | |
) | |
print("CREDENTIAL") | |
print(json.dumps(json.loads(credential), indent=2)) | |
print("-" * 80) | |
################################################### | |
# Verify | |
print("Verify - success case") | |
verification = await didkit.verify_credential( | |
credential, '{"proofPurpose":"assertionMethod"}' | |
) | |
print(verification) | |
print("-" * 80) | |
################################################### | |
# Verify with error | |
print("Verify - error case") | |
credential_with_error = json.loads(credential) | |
credential_with_error["credentialSubject"]["customInfo"]["field"] = "bad_value" | |
verification = await didkit.verify_credential( | |
json.dumps(credential_with_error), '{"proofPurpose":"assertionMethod"}' | |
) | |
print(verification) | |
print("-" * 80) | |
asyncio.run(main()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment