Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RawBolt11Invoice to/from ascii utilities #3549

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

devrandom
Copy link
Member

for remote signing of invoices

let parsed = UncheckedHrpstring::new(s)
.map_err(|_| Bolt11ParseError::MalformedHRP)?;
let hrp = parsed.hrp();
let raw_hrp: RawHrp = hrp.to_string().to_lowercase().parse()?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gah we need to make the HRP decoder support mixed-case strings...allocating a new string just to lower-case it before parsing it is absurd...Doesn't have to happen here, but the over-allocations in this crate irritate me.


/// Convert from ascii bytes with HRP prefix and base32 encoded data part.
/// Can be used to receive unsigned invoices for remote signing.
pub fn from_ascii(s: &str) -> Result<Self, Bolt11ParseError> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda prefer we call this from_bytes or something. The fact that its a string is a bit weird to expose in the API - there's no string serialization for an unsigned invoice, we're just supporting serializing them to bytes for programatic use.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so there are no low-level utilities to ser/de the data part to bytes, so this would add significant amount of code. I changed this to be [Fe32] for the data part, and str for the hrp. see what you think.

@devrandom devrandom force-pushed the 2025-01-invoice-base32 branch from 9011867 to 67d736a Compare January 17, 2025 22:39
for remote signing of invoices
@devrandom devrandom force-pushed the 2025-01-invoice-base32 branch from 67d736a to c16f1c6 Compare January 17, 2025 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants