bovine.crypto
This module includes wrappers for creating cryptographic identities and the functionality to verify signatures of http requests. BovineClient and BovineActor take care of making properly signed requests.
build_validate_http_signature(key_retriever)
Creates a validate_signature function. validate_signature takes the request as parameter and returns the owner if the http signature is valid. If you do not wish to use quart (or a compatible framework), you should use build_validate_http_signature_raw.
Example for the key_retriever
argument.
from bovine.crypto.types import CryptographicIdentifier
async def retrieve(key_id):
async with aiohttp.ClientSession() as session:
response = await session.get(key_id)
data = await response.json()
return CryptographicIdentifier.from_publickey(
data.get("publicKey", data)
)
validator = build_validate_http_signature(retrieve)
validator
then accepts as argument a werzeug.wrappers.Request
object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key_retriever |
Callable[[str], Awaitable[Tuple[str | None, str | None] | CryptographicIdentifier | None]]
|
A coroutine that given a key id returns the corresponding CryptographicIdentifier or a tuple |
required |
Returns:
Type | Description |
---|---|
The coroutine SignatureChecker.validate_signature_request |
Source code in bovine/bovine/crypto/__init__.py
build_validate_http_signature_raw(key_retriever)
Creates a validate_signature function. validate_signature takes
(method, url, headers, body)
as parameters and returns
the owner if the http signature is valid.
The rest of behavior is as build_validate_http_signature
.
Returns:
Type | Description |
---|---|
The coroutine SignatureChecker.validate_signature |
Source code in bovine/bovine/crypto/__init__.py
generate_ed25519_private_key()
Returns a multicodec/multibase encoded ed25519 private key
generate_rsa_public_private_key()
Generates a new pair of RSA public and private keys.
Returns:
Type | Description |
---|---|
Tuple[str, str]
|
pem encoded public and private key |
Source code in bovine/bovine/crypto/__init__.py
private_key_to_did_key(private_key_str)
Computes public key in did key form of Ed25519 private key
Parameters:
Name | Type | Description | Default |
---|---|---|---|
private_key_str |
str
|
multibase/multicodec encoded Ed25519 private key |
required |
Returns:
Type | Description |
---|---|
str
|
did:key |
Source code in bovine/bovine/crypto/__init__.py
validate_moo_auth_signature(request, domain)
async
Validates the Moo-Auth-1 <https://blog.mymath.rocks/2023-03-15/BIN1_Moo_Authentication_and_Authoriation>
_ signature of the request.
Returns the did-key if the signature is valid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request |
The request to validate the signature for. |
required | |
domain |
The domain the request is made to. |
required |
Returns:
Type | Description |
---|---|
Tuple[Optional[str], Optional[str]]
|
On success the did key and domain, on failure None, None When no domain is passed the did key and None is returned |