common.keypair
Cryptographic keypair utilities for SecretVaults.
This module provides secp256k1-based keypair functionality including key generation, signing, and DID (Decentralized Identifier) creation.
- class Keypair(privkey_bytes: bytes)[source]
Bases:
objectA cryptographic keypair for SecretVaults operations.
Provides secp256k1-based keypair functionality with methods for signing, DID generation, and key management.
- classmethod from_hex(hex_key: str) Keypair[source]
Create a keypair from a hexadecimal private key string.
- Parameters:
hex_key – Private key as hex string
- Returns:
Keypair instance
- classmethod from_bytes(key_bytes: bytes) Keypair[source]
Create a keypair from private key bytes.
- Parameters:
key_bytes – Private key as bytes
- Returns:
Keypair instance
- classmethod generate() Keypair[source]
Generate a new random keypair.
- Returns:
Keypair instance with cryptographically secure random private key
- private_key() PrivateKey[source]
Get the secp256k1 private key object.
- Returns:
secp256k1.PrivateKey instance
- public_key() PublicKey[source]
Get the secp256k1 public key object.
- Returns:
secp256k1.PublicKey instance
- private_key_hex() str[source]
Get the private key as a hexadecimal string.
- Returns:
Private key as hex string
- public_key_hex(compressed=False) str[source]
Get the public key as a hexadecimal string.
- Parameters:
compressed – Whether to return compressed format
- Returns:
Public key as hex string
- matches_public_key(pk: bytes | str) bool[source]
Check if this keypair’s public key matches the given key.
- Parameters:
pk – Public key as bytes or hex string
- Returns:
True if public keys match, False otherwise
- to_did() Did[source]
Create a DID (Decentralized Identifier) from the public key.
- Returns:
Did object representing this keypair’s identity