Skip to content

apsig.proof

apsig.proof provide signer and verifier implementation of FEP-8b32: Object Integrity Proofs.

ProofSigner

A class for signing documents using the Ed25519 signature algorithm, implementing Object Integrity Proofs as specified in FEP-8b32.

This class provides methods to generate keys, sign data, canonicalize documents, and create integrity proofs.

Attributes:

Name Type Description
private_key Ed25519PrivateKey

The Ed25519 private key used for signing.

public_key Ed25519PublicKey

The corresponding Ed25519 public key.

Methods:

Name Description
create_proof

dict, options: dict) -> dict: Creates a proof for the unsecured document using the specified options.

sign

dict, options: dict) -> dict: Signs the unsecured document by creating a proof and returning the signed document.

create_proof(unsecured_document, options)

Creates a proof for the unsecured document using the specified options.

Parameters:

Name Type Description Default
unsecured_document dict

The document for which the proof is created.

required
options dict

Options that define how the proof is structured.

required

Returns:

Name Type Description
dict

The proof object containing the proof value and other relevant information.

sign(unsecured_document, options)

Signs the unsecured document by creating a proof and returning the signed document.

Parameters:

Name Type Description Default
unsecured_document dict

The document to be signed.

required
options dict

Options that define the signing process.

required

Returns:

Name Type Description
dict

The signed document, including the proof.

ProofVerifier

A class for verifying documents signed using the Ed25519 signature algorithm, implementing Object Integrity Proofs as specified in FEP-8b32.

Attributes:

Name Type Description
public_key Ed25519PublicKey

The Ed25519 public key used for verification.

Methods:

Name Description
verify_proof

dict) -> dict: Verifies the proof contained in the secured document.

verify

dict) -> dict: An alias for the verify_proof method.

__init__(public_key)

Initializes the ProofVerifier with a public key.

Parameters:

Name Type Description Default
public_key Ed25519PublicKey | str

The Ed25519 public key as an object or a multibase-encoded string.

required

Raises:

Type Description
TypeError

If the provided public key is not of type Ed25519.

verify(secured_document, raise_on_fail=False)

An alias for the verify_proof method.

This method calls verify_proof to perform the actual verification of the proof contained in the secured document.

Parameters:

Name Type Description Default
secured_document dict

The document containing the proof to be verified.

required

Returns:

Name Type Description
dict Union[str, bool]

The result of the proof verification.

verify_proof(secured_document, raise_on_fail=False)

Verifies the proof contained in the secured document.

This method checks the integrity and authenticity of the secured document by validating the associated proof. It verifies the signature against the hash of the transformed document and the canonical proof configuration.

Parameters:

Name Type Description Default
secured_document dict

The document containing the proof to be verified.

required
raise_on_fail bool

Return error on failure. defaults to False.

False

Returns:

Name Type Description
dict Union[str, bool]

A dictionary containing: - bool: verified: Indicates whether the proof verification was successful. - dict: verifiedDocument: The unsecured document if verification was successful, otherwise None.

Raises:

Type Description
ValueError

If the proof is not found in the document.