2024-05-28 11:41:12 +00:00
|
|
|
# PyVckit
|
|
|
|
PyVckit es una librería para:
|
|
|
|
- firmar credenciales verificables
|
|
|
|
- verificar credenciales verificables
|
|
|
|
- generar presentaciones verificables
|
|
|
|
- verificar presentaciones verificables
|
|
|
|
|
2024-05-28 12:09:57 +00:00
|
|
|
Esta libreria esta fuertemente inspirada en [didkit de SpruceId](https://github.com/spruceid/didkit) y pretende mantener compatibilidad con ella.
|
2024-05-28 11:41:12 +00:00
|
|
|
|
|
|
|
Por ahora la criptografía soportada es solo EdDSA con una firma Ed25519Signature2018.
|
|
|
|
|
|
|
|
# Instalación
|
|
|
|
Por ahora la instalación es desde el repositorio:
|
2024-05-28 15:40:01 +00:00
|
|
|
```sh
|
|
|
|
python -m venv env
|
|
|
|
source env/bin/activate
|
|
|
|
git clone https://gitea.pangea.org/ereuse/pyvckit.git
|
|
|
|
cd pyvckit
|
|
|
|
pip install -r requirements.txt
|
|
|
|
pip install -e .
|
2024-05-28 11:41:12 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
# Cli
|
|
|
|
El modo de uso bajo la linea de comandos seria el siguiente:
|
|
|
|
|
|
|
|
## generar un par de claves:
|
|
|
|
```sh
|
|
|
|
python did.py -n keys > keypair.json
|
|
|
|
```
|
|
|
|
|
|
|
|
## generar un identificador did:
|
2024-05-30 09:12:04 +00:00
|
|
|
|
|
|
|
### did key
|
2024-05-28 11:41:12 +00:00
|
|
|
```sh
|
|
|
|
python did.py -n did -k keypair.json
|
|
|
|
```
|
|
|
|
|
2024-05-30 09:12:04 +00:00
|
|
|
### did web
|
|
|
|
```sh
|
|
|
|
python did.py -n did -k keypair.json -u https://localhost/user1/dids/
|
|
|
|
```
|
|
|
|
|
2024-05-28 12:09:57 +00:00
|
|
|
## generar una credencial firmada de ejemplo:
|
2024-05-28 12:19:12 +00:00
|
|
|
Se genera un ejemplo de credencial que es el que aparece en la plantilla credential_tmpl del fichero [templates.py](templates.py)
|
2024-05-28 11:41:12 +00:00
|
|
|
```sh
|
|
|
|
python sign_vc.py -k keypair.json > credential_signed.json
|
|
|
|
```
|
|
|
|
|
|
|
|
## verificar una credencial firmada:
|
|
|
|
```sh
|
|
|
|
python verify_vc.py credential_signed.json
|
|
|
|
```
|
|
|
|
|
|
|
|
## generar una presentación verificable:
|
|
|
|
```sh
|
|
|
|
python sign_vp.py -k keypair.json -c credential_signed.json > presentation_signed.json
|
|
|
|
```
|
|
|
|
|
2024-05-30 09:18:22 +00:00
|
|
|
## verificar una presentación verificable:
|
2024-05-28 11:41:12 +00:00
|
|
|
```sh
|
|
|
|
python verify_vp.py presentation_signed.json
|
|
|
|
```
|
2024-05-28 12:09:57 +00:00
|
|
|
|
2024-05-30 09:12:04 +00:00
|
|
|
## creación del documento did:
|
|
|
|
Este comando creara un documento json y una ruta url donde colocar este documento. El did tiene que ser un did web.
|
2024-05-30 09:18:22 +00:00
|
|
|
Este documento es un ejemplo y en producción hay que adaptarlo para contener las credenciales verificables revocadas.
|
2024-05-30 09:12:04 +00:00
|
|
|
```sh
|
|
|
|
python did.py -k keypair.json -g did:web:localhost:did-registry:z6MkiNc8xqJLcG7QR1wzD9HPs5oPQEaWNcVf92QsbppNiB7C
|
|
|
|
```
|
|
|
|
|
2024-05-28 12:09:57 +00:00
|
|
|
# Uso como librería
|
|
|
|
En los test podras encontrar ejemplos de uso. Ahora explicare los casos habituales
|
|
|
|
|
|
|
|
## generar un par de claves:
|
|
|
|
```python
|
|
|
|
from pyvckit.did import generate_keys
|
|
|
|
key = generate_keys()
|
|
|
|
```
|
|
|
|
|
|
|
|
## generar un identificador did:
|
2024-05-30 09:12:04 +00:00
|
|
|
|
|
|
|
### did key
|
2024-05-28 12:09:57 +00:00
|
|
|
```python
|
|
|
|
from pyvckit.did import generate_keys, generate_did
|
|
|
|
key = generate_keys()
|
|
|
|
did = generate_did(key)
|
|
|
|
```
|
|
|
|
|
2024-05-30 09:12:04 +00:00
|
|
|
### did web
|
|
|
|
```python
|
|
|
|
from pyvckit.did import generate_keys, generate_did
|
|
|
|
key = generate_keys()
|
|
|
|
url = "https://localhost/user1/dids/"
|
|
|
|
did = generate_did(key, url)
|
|
|
|
```
|
|
|
|
|
2024-05-28 12:09:57 +00:00
|
|
|
## generar una credencial firmada:
|
|
|
|
Suponiendo que **credential** es una credencial válida.
|
|
|
|
**credential** es una variable de tipo string
|
|
|
|
```python
|
|
|
|
from pyvckit.did import generate_keys, generate_did, get_signing_key
|
|
|
|
from pyvckit.sign_vc import sign
|
|
|
|
|
|
|
|
key = generate_keys()
|
|
|
|
did = generate_did(key)
|
|
|
|
signing_key = get_signing_key(key)
|
|
|
|
vc = sign(credential, signing_key, did)
|
|
|
|
```
|
|
|
|
|
|
|
|
## verificar una credencial firmada:
|
|
|
|
Suponiendo que **vc** es una credencial verificable correctamente firmada
|
|
|
|
```python
|
|
|
|
import json
|
|
|
|
from pyvckit.verify import verify_vc
|
|
|
|
|
|
|
|
verified = verify_vc(json.dumps(vc))
|
|
|
|
```
|
|
|
|
|
|
|
|
## generar una presentación verificable:
|
|
|
|
```python
|
|
|
|
from pyvckit.did import generate_keys, generate_did, get_signing_key
|
|
|
|
from pyvckit.sign_vp import sign_vp
|
|
|
|
|
|
|
|
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_string)
|
|
|
|
```
|
|
|
|
|
|
|
|
## verificat una presentación verificable:
|
|
|
|
```python
|
|
|
|
from pyvckit.verify_vp import verify_vp
|
|
|
|
verified = verify_vp(json.dumps(vp))
|
|
|
|
```
|
2024-05-30 09:12:04 +00:00
|
|
|
|
|
|
|
## creación del documento did:
|
|
|
|
Este comando creara un documento json y una ruta url donde colocar este documento. El did tiene que ser un did web.
|
|
|
|
Este documento es un ejemplo y en producción hay que adaptarlo para contener las credenciales verificables revocadas.
|
|
|
|
```python
|
|
|
|
from pyvckit.did import generate_keys, generate_did, gen_did_document
|
|
|
|
|
|
|
|
key = generate_keys()
|
|
|
|
url = "https://localhost/did-registry"
|
|
|
|
did = generate_did(key, url)
|
|
|
|
definitive_url, document = gen_did_document(did, key)
|
|
|
|
```
|