Python
asyncio
is required, meaning you will need Python 3.7 or above.
You can install it globally with:
pip install -U didkit
To use DIDKit in Python, import the
didkit
library and manipulate the didkit
module as you would any other. It contains all the same functions as the other bindings, so you can refer to the Rust docs for an overview of the core structure of DIDKit as a library.The method
issueCredential
, for example, takes all the properties you would expect, as JSON strings and returns a credential as a JSON string that the user then .loads
to access individual fields. See the following example:import asyncio
import didkit
import json
jwk = didkit.generate_ed25519_key()
did = didkit.key_to_did("key", jwk)
credential = {
"@context": "https://www.w3.org/2018/credentials/v1",
"id": "http://example.org/credentials/3731",
"type": ["VerifiableCredential"],
"issuer": did,
"issuanceDate": "2020-08-19T21:41:50Z",
"credentialSubject": {
"id": "did:example:d23dd687a7dc6787646f2eb98d0",
},
}
async def main():
signed_credential = await didkit.issue_credential(
json.dumps(credential),
json.dumps({}),
jwk)
print(json.loads(signed_credential))
asyncio.run(main())
Framework | Example |
---|---|
pytest | |
Functions have kept the same signatures, but some have become asynchronous. You will need to start using
asyncio
if it is not already the case.
Last modified 11mo ago