Struct ln_types::node_pubkey::NodePubkey[][src]

pub struct NodePubkey(pub PublicKey);
This is supported on crate feature 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:

  • NodeId is more performant for non-cryptographic operations.
  • NodeId can not perform any cryptographic operations itself.
  • NodePubkey, despite its field being public, maintains more invariants. In this library, a valid NodeId is not guaranteed to be a valid NodePubkey

Example

let marvin_str = "029ef8ee0ba895e2807ac1df1987a7888116c468e70f42e7b089e06811b0e45482";
let marvin = marvin_str.parse::<ln_types::NodePubkey>().unwrap();
assert_eq!(marvin.to_string(), marvin_str);

Tuple Fields

0: PublicKey

The underlying public key used for cryptographic operations.

Implementations

This is supported on crate feature 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();
This is supported on crate feature 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

Performs the conversion.

Performs the conversion.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Shows NodePubkey as hex

Formats the value using the given formatter. Read more

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.

Creates a new value of this type from a buffer of data of the specified Postgres Type in its binary format. Read more

Determines if a value of this type can be created from the specified Postgres Type. Read more

Creates a new value of this type from a NULL SQL value. Read more

A convenience function that delegates to from_sql and from_sql_null depending on the value of raw. Read more

Expects hex representation

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

Formats the value using the given formatter.

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

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

This method tests greater than or equal to (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.

Converts the value of self into the binary format of the specified Postgres Type, appending it to out. Read more

Determines if a value of this type can be converted to the specified Postgres Type. Read more

An adaptor method used internally by Rust-Postgres. Read more

The type returned in the event of a conversion error.

Performs the conversion.

Expects hex representation

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Expects hex representation

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Expects hex representation

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Formats the value using the given formatter.

Currently uses Display but may use emit_bytes if/when it’s implemented.

Serialize self into Serializer Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns a reference to self as a ToSql trait object.

Performs the conversion.

Performs the conversion.

Should always be Self

Outputs the hash in hexadecimal form

Outputs the hash in hexadecimal form

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.