Coverage for tropicsquare / ecc / signature.py: 100%
12 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-27 21:24 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-27 21:24 +0000
1"""Signature classes for TROPIC01 ECC signing operations."""
4class Signature:
5 """Base class for cryptographic signatures.
7 Represents a digital signature with R and S components as returned
8 by TROPIC01 signing operations (ECDSA and EdDSA).
10 :param r: R component of signature (32 bytes)
11 :param s: S component of signature (32 bytes)
12 """
14 def __init__(self, r: bytes, s: bytes):
15 """Initialize signature.
17 :param r: R component (32 bytes)
18 :param s: S component (32 bytes)
19 """
20 self.r = r
21 self.s = s
23 def to_dict(self) -> dict:
24 """Convert signature to dictionary.
26 :returns: Dictionary with R and S components
27 :rtype: dict
29 Example::
31 {
32 'r': 'a1b2c3...',
33 's': 'd4e5f6...'
34 }
35 """
36 return {
37 'r': self.r.hex(),
38 's': self.s.hex()
39 }
41 def __str__(self) -> str:
42 """Get human-readable string representation.
44 :returns: Formatted signature with R and S components
45 """
46 return f"{self.__class__.__name__}:\n R: {self.r.hex()}\n S: {self.s.hex()}"
48 def __repr__(self) -> str:
49 """Get detailed string representation for debugging.
51 :returns: Detailed representation with class name
52 """
53 return f"{self.__class__.__name__}(r={self.r.hex()[:16]}..., s={self.s.hex()[:16]}...)"
56class EcdsaSignature(Signature):
57 """ECDSA signature from P256 curve signing operation.
59 Represents an ECDSA (Elliptic Curve Digital Signature Algorithm)
60 signature created using the P256 curve. This signature can be verified
61 using standard ECDSA verification with the corresponding public key.
63 The signature consists of two 32-byte components (R, S) that can be
64 converted to DER encoding for use with standard cryptographic libraries.
66 Example::
68 signature = ts.ecdsa_sign(1, message_hash)
69 print(signature.r.hex())
70 print(signature.s.hex())
71 """
74class EddsaSignature(Signature):
75 """EdDSA signature from Ed25519 curve signing operation.
77 Represents an EdDSA (Edwards-curve Digital Signature Algorithm)
78 signature created using the Ed25519 curve. This signature can be verified
79 using standard Ed25519 verification with the corresponding public key.
81 The signature consists of two 32-byte components (R, S) that form
82 the standard 64-byte Ed25519 signature format when concatenated.
84 Example::
86 signature = ts.eddsa_sign(0, message)
87 print(signature.r.hex())
88 print(signature.s.hex())
89 """