Struct ln_types::node_pubkey::NodePubkey [−][src]
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
pub fn verify<H: ThirtyTwoByteHash + Hash, C: Verification>(
&self,
secp: &Secp256k1<C>,
message: &[u8],
signature: &[u8]
) -> Result<(), Error>
This is supported on crate feature node_pubkey_verify only.
pub fn verify<H: ThirtyTwoByteHash + Hash, C: Verification>(
&self,
secp: &Secp256k1<C>,
message: &[u8],
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::bitcoin_hashes::sha256d;
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();
marvin.verify::<sha256d::Hash, _>(&secp, message.as_bytes(), signature).unwrap();pub fn verify_lightning_message<C: Verification>(
&self,
secp: &Secp256k1<C>,
message: &[u8],
signature: &[u8]
) -> Result<(), Error>
This is supported 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();Convenience conversion method.
This is more readable and less prone to inference problems than Into::into.
Computes public key from a secret key and stores it as NodePubkey.
Trait Implementations
Mutably borrows from an owned value. Read more
Shows NodePubkey as hex
Performs the conversion.
Performs the conversion.
Performs the conversion.
Supports BYTEA, TEXT, and VARCHAR.
Decoded as bytes if BYTEA is used, as hex string otherwise.
Expects hex representation
Writes human-readable description of the type to the writer. Read more
This method tests for self and other values to be equal, and is used
by ==. Read more
This method tests for !=.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
Supports BYTEA, TEXT, and VARCHAR.
Stored as bytes if BYTEA is used, as hex string otherwise.
Expects hex representation
Expects hex representation
Expects hex representation
Currently uses Display but may use emit_bytes if/when it’s implemented.
Auto Trait Implementations
impl RefUnwindSafe for NodePubkey
impl Send for NodePubkey
impl Sync for NodePubkey
impl Unpin for NodePubkey
impl UnwindSafe for NodePubkey
Blanket Implementations
Mutably borrows from an owned value. Read more
Returns a reference to self as a ToSql trait object.
