pub struct PaymentClaim { /* private fields */ }Expand description
A peer’s self-signed designation of where to pay it (SPEC §3.4).
The fields are private on purpose: the only way to read the address is
verify (or PeerEntry::verified_payment_address), so it is not
possible to obtain a payee from this type without having checked it. An unverified payee has no
legitimate use, and a type that cannot hand one out cannot be misused into paying a thief.
Implementations§
Source§impl PaymentClaim
impl PaymentClaim
Sourcepub fn new(
address: impl Into<String>,
spki_der: &[u8],
signature: &[u8],
) -> Self
pub fn new( address: impl Into<String>, spki_der: &[u8], signature: &[u8], ) -> Self
A claim naming address, attested by the key in spki_der with signature over
payment_signing_bytes. Producing signature is the caller’s job — this crate holds no
private keys and performs no signing.
Sourcepub fn spki_der(&self) -> Vec<u8> ⓘ
pub fn spki_der(&self) -> Vec<u8> ⓘ
The attesting key’s SPKI DER, decoded. Empty when the field is not valid base64.
Exposed for diagnostics and for re-assembling a claim in tests; reading the key is harmless, which is precisely why the address is not exposed the same way.
Sourcepub fn signature(&self) -> Vec<u8> ⓘ
pub fn signature(&self) -> Vec<u8> ⓘ
The raw signature bytes, decoded. Empty when the field is not valid base64.
Sourcepub fn within_caps(&self) -> bool
pub fn within_caps(&self) -> bool
Whether every field is within its cap (SPEC §3.4.2). Checked before any decoding so a hostile sender cannot make a receiver allocate on an oversized field.
Sourcepub fn verify(
&self,
peer_id: &str,
network_id: &str,
verifier: &impl SignatureVerifier,
) -> Result<&str, PaymentClaimError>
pub fn verify( &self, peer_id: &str, network_id: &str, verifier: &impl SignatureVerifier, ) -> Result<&str, PaymentClaimError>
The payee address, only if this claim is genuinely the one peer_id made for
network_id (SPEC §3.4.3).
Three checks, in order, each of which a real attack fails: fields within caps and decodable;
SHA-256(spki) == peer_id, so the key is this peer’s and not a relay’s; and the signature
covering payment_signing_bytes, so neither the address nor the network can be rewritten
underneath it.
Trait Implementations§
Source§impl Clone for PaymentClaim
impl Clone for PaymentClaim
Source§fn clone(&self) -> PaymentClaim
fn clone(&self) -> PaymentClaim
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more