|
1 | | -use bitcoin::secp256k1::PublicKey; |
2 | 1 | use core::{fmt::Write, ops::Deref}; |
3 | | -use lightning::io; |
4 | 2 | use lightning::sign::EntropySource; |
5 | 3 |
|
6 | 4 | use crate::lsps0::msgs::RequestId; |
7 | | -use crate::prelude::{String, Vec}; |
| 5 | +use crate::prelude::String; |
8 | 6 |
|
9 | 7 | /// Maximum transaction index that can be used in a `short_channel_id`. |
10 | 8 | /// This value is based on the 3-bytes available for tx index. |
@@ -56,53 +54,6 @@ pub fn hex_str(value: &[u8]) -> String { |
56 | 54 | res |
57 | 55 | } |
58 | 56 |
|
59 | | -pub fn to_vec(hex: &str) -> Option<Vec<u8>> { |
60 | | - let mut out = Vec::with_capacity(hex.len() / 2); |
61 | | - |
62 | | - let mut b = 0; |
63 | | - for (idx, c) in hex.as_bytes().iter().enumerate() { |
64 | | - b <<= 4; |
65 | | - match *c { |
66 | | - b'A'..=b'F' => b |= c - b'A' + 10, |
67 | | - b'a'..=b'f' => b |= c - b'a' + 10, |
68 | | - b'0'..=b'9' => b |= c - b'0', |
69 | | - _ => return None, |
70 | | - } |
71 | | - if (idx & 1) == 1 { |
72 | | - out.push(b); |
73 | | - b = 0; |
74 | | - } |
75 | | - } |
76 | | - |
77 | | - Some(out) |
78 | | -} |
79 | | - |
80 | | -pub fn to_compressed_pubkey(hex: &str) -> Option<PublicKey> { |
81 | | - if hex.len() != 33 * 2 { |
82 | | - return None; |
83 | | - } |
84 | | - let data = match to_vec(&hex[0..33 * 2]) { |
85 | | - Some(bytes) => bytes, |
86 | | - None => return None, |
87 | | - }; |
88 | | - match PublicKey::from_slice(&data) { |
89 | | - Ok(pk) => Some(pk), |
90 | | - Err(_) => None, |
91 | | - } |
92 | | -} |
93 | | - |
94 | | -pub fn parse_pubkey(pubkey_str: &str) -> Result<PublicKey, io::Error> { |
95 | | - let pubkey = to_compressed_pubkey(pubkey_str); |
96 | | - if pubkey.is_none() { |
97 | | - return Err(io::Error::new( |
98 | | - io::ErrorKind::Other, |
99 | | - "ERROR: unable to parse given pubkey for node", |
100 | | - )); |
101 | | - } |
102 | | - |
103 | | - Ok(pubkey.unwrap()) |
104 | | -} |
105 | | - |
106 | 57 | #[cfg(test)] |
107 | 58 | mod tests { |
108 | 59 | use super::*; |
|
0 commit comments