pub struct NodePubkey(pub PublicKey);secp256k1 only.Expand description
Newtype over secp256k1::PublicKey representing a deserialized key identifying an LN node.
This can be considered similar to NodeId with these differences:
NodeIdis more performant for non-cryptographic operations.NodeIdcan not perform any cryptographic operations itself.NodePubkey, despite its field being public, maintains more invariants. In this library, a validNodeIdis not guaranteed to be a validNodePubkey
§Example
let marvin_str = "029ef8ee0ba895e2807ac1df1987a7888116c468e70f42e7b089e06811b0e45482";
let marvin = marvin_str.parse::<ln_types::NodePubkey>().unwrap();
assert_eq!(marvin.to_string(), marvin_str);Tuple Fields§
§0: PublicKeyThe underlying public key used for cryptographic operations.
Implementations§
Source§impl NodePubkey
impl NodePubkey
Sourcepub fn verify<M: Into<Message>, C: Verification>(
&self,
secp: &Secp256k1<C>,
message: M,
signature: &[u8],
) -> Result<(), Error>
Available on crate feature node_pubkey_verify only.
pub fn verify<M: Into<Message>, C: Verification>( &self, secp: &Secp256k1<C>, message: M, signature: &[u8], ) -> Result<(), Error>
node_pubkey_verify only.Verify a message signed by this key.
This is a convenience method that simply uses slices.
While this could be seen as regression from strongly-typed secp256k1 library, it should
be a good tradeoff here. The reason is we know that LN signatures are not DER-encoded
and there shouldn’t be a reason to need to keep message hash around.
If you need anything advanced, you can still use the raw secp256k1::PublicKey.
§Example
use ln_types::secp256k1::hashes::{sha256d, Hash};
let marvin_str = "029ef8ee0ba895e2807ac1df1987a7888116c468e70f42e7b089e06811b0e45482";
let marvin = marvin_str.parse::<ln_types::NodePubkey>().unwrap();
let message = "Lightning Signed Message:I am the author of `ln-types` Rust crate.";
let signature = &[0x29, 0x79, 0x4d, 0x9a, 0x6a, 0x48, 0x68, 0x0f, 0x9b, 0x8d, 0x60, 0x97, 0xa6, 0xd8, 0xef, 0x1d, 0x5c, 0xf9, 0xdc, 0x27, 0xcd, 0x76, 0x9a, 0x86, 0x58, 0xd6, 0x94, 0x00, 0x1c, 0x12, 0xb8, 0xdd, 0x49, 0xaf, 0x2b, 0xca, 0x0a, 0x24, 0xd8, 0xf4, 0x5a, 0x3b, 0x3c, 0xc7, 0x87, 0xf0, 0x48, 0x60, 0x63, 0x23, 0xf4, 0x24, 0xba, 0xa8, 0x0f, 0x5e, 0xe6, 0x05, 0x79, 0x81, 0xe2, 0x29, 0x6f, 0x0d];
let secp = ln_types::secp256k1::Secp256k1::verification_only();
let message = sha256d::Hash::hash(message.as_bytes());
let message = secp256k1::Message::from_digest(message.to_byte_array());
marvin.verify(&secp, message, signature).unwrap();Sourcepub fn verify_lightning_message<C: Verification>(
&self,
secp: &Secp256k1<C>,
message: &[u8],
signature: &[u8],
) -> Result<(), Error>
Available on crate feature node_pubkey_recovery only.
pub fn verify_lightning_message<C: Verification>( &self, secp: &Secp256k1<C>, message: &[u8], signature: &[u8], ) -> Result<(), Error>
node_pubkey_recovery only.Verifies a message signed by signmessage Eclair/LND RPC.
The signatures of messages returned by node RPCs are not so simple.
They prefix messages with Lightning Signed Message:, use double sha256 and recovery.
It is the reason why this function requires the recovery feature of secp256k1.
This function takes care of all that complexity for you so that you can verify the messages conveniently.
§Example
let marvin_str = "029ef8ee0ba895e2807ac1df1987a7888116c468e70f42e7b089e06811b0e45482";
let marvin = marvin_str.parse::<ln_types::NodePubkey>().unwrap();
let message = "I am the author of `ln-types` Rust crate.";
let signature = &[0x1f, 0x29, 0x79, 0x4d, 0x9a, 0x6a, 0x48, 0x68, 0x0f, 0x9b, 0x8d, 0x60, 0x97, 0xa6, 0xd8, 0xef, 0x1d, 0x5c, 0xf9, 0xdc, 0x27, 0xcd, 0x76, 0x9a, 0x86, 0x58, 0xd6, 0x94, 0x00, 0x1c, 0x12, 0xb8, 0xdd, 0x49, 0xaf, 0x2b, 0xca, 0x0a, 0x24, 0xd8, 0xf4, 0x5a, 0x3b, 0x3c, 0xc7, 0x87, 0xf0, 0x48, 0x60, 0x63, 0x23, 0xf4, 0x24, 0xba, 0xa8, 0x0f, 0x5e, 0xe6, 0x05, 0x79, 0x81, 0xe2, 0x29, 0x6f, 0x0d];
let secp = ln_types::secp256k1::Secp256k1::verification_only();
marvin.verify_lightning_message(&secp, message.as_bytes(), signature).unwrap();Sourcepub fn to_node_id(&self) -> NodeId
pub fn to_node_id(&self) -> NodeId
Convenience conversion method.
This is more readable and less prone to inference problems than Into::into.
Sourcepub fn from_secret_key<C: Signing>(secp: &Secp256k1<C>, sk: &SecretKey) -> Self
pub fn from_secret_key<C: Signing>(secp: &Secp256k1<C>, sk: &SecretKey) -> Self
Computes public key from a secret key and stores it as NodePubkey.
Trait Implementations§
Source§impl AsMut<PublicKey> for NodePubkey
impl AsMut<PublicKey> for NodePubkey
Source§impl AsRef<PublicKey> for NodePubkey
impl AsRef<PublicKey> for NodePubkey
Source§impl Borrow<PublicKey> for NodePubkey
impl Borrow<PublicKey> for NodePubkey
Source§impl BorrowMut<PublicKey> for NodePubkey
impl BorrowMut<PublicKey> for NodePubkey
Source§fn borrow_mut(&mut self) -> &mut PublicKey
fn borrow_mut(&mut self) -> &mut PublicKey
Source§impl Clone for NodePubkey
impl Clone for NodePubkey
Source§fn clone(&self) -> NodePubkey
fn clone(&self) -> NodePubkey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NodePubkey
impl Debug for NodePubkey
Source§impl Display for NodePubkey
Shows NodePubkey as hex
impl Display for NodePubkey
Shows NodePubkey as hex
Source§impl<'a> From<&'a NodePubkey> for NodeId
impl<'a> From<&'a NodePubkey> for NodeId
Source§fn from(value: &'a NodePubkey) -> Self
fn from(value: &'a NodePubkey) -> Self
Source§impl From<NodePubkey> for [u8; 33]
impl From<NodePubkey> for [u8; 33]
Source§fn from(value: NodePubkey) -> Self
fn from(value: NodePubkey) -> Self
Source§impl From<NodePubkey> for NodeId
impl From<NodePubkey> for NodeId
Source§fn from(value: NodePubkey) -> Self
fn from(value: NodePubkey) -> Self
Source§impl<'a> FromSql<'a> for NodePubkey
Available on crate feature postgres-types only.Supports BYTEA, TEXT, and VARCHAR.
impl<'a> FromSql<'a> for NodePubkey
postgres-types only.Supports BYTEA, TEXT, and VARCHAR.
Decoded as bytes if BYTEA is used, as hex string otherwise.
Source§fn from_sql(
ty: &Type,
raw: &'a [u8],
) -> Result<Self, Box<dyn Error + Send + Sync + 'static>>
fn from_sql( ty: &Type, raw: &'a [u8], ) -> Result<Self, Box<dyn Error + Send + Sync + 'static>>
Type in its binary format. Read moreSource§fn accepts(ty: &Type) -> bool
fn accepts(ty: &Type) -> bool
Type.Source§impl FromStr for NodePubkey
Expects hex representation
impl FromStr for NodePubkey
Expects hex representation
Source§impl Hash for NodePubkey
impl Hash for NodePubkey
Source§impl LowerHex for NodePubkey
impl LowerHex for NodePubkey
Source§impl Ord for NodePubkey
impl Ord for NodePubkey
Source§fn cmp(&self, other: &NodePubkey) -> Ordering
fn cmp(&self, other: &NodePubkey) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl ParseArgFromStr for NodePubkey
Available on crate feature parse_arg only.
impl ParseArgFromStr for NodePubkey
parse_arg only.Source§impl PartialEq for NodePubkey
impl PartialEq for NodePubkey
Source§impl PartialOrd for NodePubkey
impl PartialOrd for NodePubkey
Source§impl ToSql for NodePubkey
Available on crate feature postgres-types only.Supports BYTEA, TEXT, and VARCHAR.
impl ToSql for NodePubkey
postgres-types only.Supports BYTEA, TEXT, and VARCHAR.
Stored as bytes if BYTEA is used, as hex string otherwise.
Source§fn to_sql(
&self,
ty: &Type,
out: &mut BytesMut,
) -> Result<IsNull, Box<dyn Error + Send + Sync + 'static>>
fn to_sql( &self, ty: &Type, out: &mut BytesMut, ) -> Result<IsNull, Box<dyn Error + Send + Sync + 'static>>
self into the binary format of the specified
Postgres Type, appending it to out. Read moreSource§fn accepts(ty: &Type) -> bool
fn accepts(ty: &Type) -> bool
Type.Source§fn to_sql_checked(
&self,
ty: &Type,
out: &mut BytesMut,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn to_sql_checked( &self, ty: &Type, out: &mut BytesMut, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§fn encode_format(&self, _ty: &Type) -> Format
fn encode_format(&self, _ty: &Type) -> Format
Source§impl<'a> TryFrom<&'a [u8]> for NodePubkey
impl<'a> TryFrom<&'a [u8]> for NodePubkey
Source§impl<'a> TryFrom<&'a str> for NodePubkey
Expects hex representation
impl<'a> TryFrom<&'a str> for NodePubkey
Expects hex representation
Source§impl TryFrom<Box<str>> for NodePubkey
Available on crate feature alloc only.Expects hex representation
impl TryFrom<Box<str>> for NodePubkey
alloc only.Expects hex representation
Source§impl TryFrom<NodeId> for NodePubkey
impl TryFrom<NodeId> for NodePubkey
Source§impl TryFrom<String> for NodePubkey
Available on crate feature alloc only.Expects hex representation
impl TryFrom<String> for NodePubkey
alloc only.Expects hex representation
Source§impl UpperHex for NodePubkey
impl UpperHex for NodePubkey
Source§impl Value for NodePubkey
Available on crate feature slog only.Currently uses Display but may use emit_bytes if/when it’s implemented.
impl Value for NodePubkey
slog only.Currently uses Display but may use emit_bytes if/when it’s implemented.
impl Eq for NodePubkey
impl StructuralPartialEq for NodePubkey
Auto Trait Implementations§
impl Freeze for NodePubkey
impl RefUnwindSafe for NodePubkey
impl Send for NodePubkey
impl Sync for NodePubkey
impl Unpin for NodePubkey
impl UnwindSafe for NodePubkey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> BorrowToSql for Twhere
T: ToSql,
impl<T> BorrowToSql for Twhere
T: ToSql,
Source§fn borrow_to_sql(&self) -> &dyn ToSql
fn borrow_to_sql(&self) -> &dyn ToSql
self as a ToSql trait object.