pub struct PublicKey { /* private fields */ }Expand description
A secp256k1 public key (a point on the curve).
Uses composition with Point, following Rust conventions. The TS SDK uses class inheritance (PublicKey extends Point); we mirror the public API names.
Implementations§
Source§impl PublicKey
impl PublicKey
Sourcepub fn from_point(point: Point) -> Self
pub fn from_point(point: Point) -> Self
Create a PublicKey from a Point.
Sourcepub fn from_private_key(key: &PrivateKey) -> Self
pub fn from_private_key(key: &PrivateKey) -> Self
Derive a public key from a private key.
Sourcepub fn from_string(s: &str) -> Result<Self, PrimitivesError>
pub fn from_string(s: &str) -> Result<Self, PrimitivesError>
Parse a public key from a hex string (compressed or uncompressed DER).
Compressed: 33 bytes (66 hex chars), starts with 02 or 03 Uncompressed: 65 bytes (130 hex chars), starts with 04
Sourcepub fn from_der_bytes(bytes: &[u8]) -> Result<Self, PrimitivesError>
pub fn from_der_bytes(bytes: &[u8]) -> Result<Self, PrimitivesError>
Parse a public key from DER-encoded bytes.
Sourcepub fn to_der(&self) -> Vec<u8> ⓘ
pub fn to_der(&self) -> Vec<u8> ⓘ
Encode the public key in compressed DER format (33 bytes).
Format: prefix(1) || x(32) prefix = 0x02 if y is even, 0x03 if y is odd
Sourcepub fn to_der_hex(&self) -> String
pub fn to_der_hex(&self) -> String
Encode the public key in compressed DER format as a hex string.
Sourcepub fn to_der_uncompressed(&self) -> Vec<u8> ⓘ
pub fn to_der_uncompressed(&self) -> Vec<u8> ⓘ
Encode the public key in uncompressed DER format (65 bytes).
Format: 0x04 || x(32) || y(32)
Sourcepub fn to_hash(&self) -> Vec<u8> ⓘ
pub fn to_hash(&self) -> Vec<u8> ⓘ
Hash the compressed public key with hash160 (RIPEMD-160(SHA-256)).
Returns 20 bytes – the public key hash used in P2PKH addresses.
Sourcepub fn to_address(&self, prefix: &[u8]) -> String
pub fn to_address(&self, prefix: &[u8]) -> String
Derive a P2PKH Bitcoin address from this public key.
Format: Base58Check(prefix || hash160(compressed_der))
Default prefix [0x00] for mainnet.
Sourcepub fn verify(&self, message: &[u8], signature: &Signature) -> bool
pub fn verify(&self, message: &[u8], signature: &Signature) -> bool
Verify a message signature using this public key.
The message is hashed with SHA-256 before verification.
Compute ECDH shared secret: private_key.bn * self.point.
Returns the resulting point on the curve.
Sourcepub fn derive_child(
&self,
private_key: &PrivateKey,
invoice_number: &str,
) -> Result<PublicKey, PrimitivesError>
pub fn derive_child( &self, private_key: &PrivateKey, invoice_number: &str, ) -> Result<PublicKey, PrimitivesError>
Derive a child public key using Type-42 key derivation (BRC-42).
Computes: child_point = self.point + G * HMAC-SHA256(shared_secret_compressed, invoice_number) where shared_secret = private_key * self.