bovine.crypto.helper
content_digest_sha256
Computes the SHA256 digest of given content
>>> content_digest_sha256(b"moo")
'sha-256=R9+ukoir89XSJSq/sL1qyWYmN9ZG5t+dXSdLwzbierw='
>>> content_digest_sha256(b"moo", prefix="SHA-256")
'SHA-256=R9+ukoir89XSJSq/sL1qyWYmN9ZG5t+dXSdLwzbierw='
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content
|
str | bytes
|
Content to be encoded |
required |
prefix
|
str
|
Prefix to use should be either “SHA-256” or “sha-256” depending on taste |
'sha-256'
|
Source code in bovine/bovine/crypto/helper.py
content_digest_sha256_rfc_9530
Computes the content digest according to RFC 9530
>>> content_digest_sha256_rfc_9530(b'{"hello": "world"}\n')
('content-digest', 'sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg=:')
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content
|
bytes
|
Usually the request body to compute the digest from |
required |
Returns:
Type | Description |
---|---|
Tuple[str, str]
|
Tuple of header name, header value |
Source code in bovine/bovine/crypto/helper.py
did_key_to_public_key
did_key_to_public_key(did: str) -> Ed25519PublicKey
Transform a did key to a public key
>>> did = "did:key:z6MkekwC6R9bj9ErToB7AiZJfyCSDhaZe1UxhDbCqJrhqpS5"
>>> did_key_to_public_key(did)
<cryptography.hazmat.bindings._rust.openssl.ed25519.Ed25519PublicKey object at ...>
Source code in bovine/bovine/crypto/helper.py
ensure_data_integrity_context
Performs context injection according to
Verifiable Credentials: Data Integrity. The data integrity
context being added is https://w3id.org/security/data-integrity/v2
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc
|
dict
|
Document |
required |
Returns:
Type | Description |
---|---|
dict
|
The same document with the data integrity context added. |
Source code in bovine/bovine/crypto/helper.py
jcs_sha256
Returns the sha256 digest of the representation
of dict according to JCS. This assumes that doc
is JSON serializable.
JCS is defined in RFC8785.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc
|
dict
|
The document |
required |
context
|
dict | None
|
ignored used in rdfc_sha256 |
None
|
Source code in bovine/bovine/crypto/helper.py
jcs_sha384
Returns the sha384 digest of the representation
of dict according to JCS. This assumes that doc
is JSON serializable.
JCS is defined in RFC8785.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc
|
dict
|
The document |
required |
context
|
dict | None
|
ignored used in rdfc_sha256 |
None
|
Source code in bovine/bovine/crypto/helper.py
public_key_to_did_key
public_key_to_did_key(
public_key: Union[
Ed25519PublicKey,
RSAPublicKey,
EllipticCurvePublicKey,
],
) -> str
Converts a public key to a did:key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
public_key
|
Union[Ed25519PublicKey, RSAPublicKey, EllipticCurvePublicKey]
|
The public key |
required |
Source code in bovine/bovine/crypto/helper.py
rdfc_sha256
Returns the sha256 digest of the representation of dict according to RDF-Canon
The algorithm used is URDNA2015 and the result are n-quads.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc
|
dict
|
The document |
required |
context
|
dict
|
If doc has no |
{}
|
Source code in bovine/bovine/crypto/helper.py
rdfc_sha384
Returns the sha384 digest of the representation of dict according to RDF-Canon
The algorithm used is URDNA2015 and the result are n-quads.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc
|
dict
|
The document |
required |
context
|
dict
|
If doc has no |
{}
|