@@ -139,7 +139,7 @@ pub enum ParseOrSemanticError {
139
139
ParseError ( Bolt11ParseError ) ,
140
140
141
141
/// The invoice could be decoded but violates the BOLT11 standard
142
- SemanticError ( crate :: SemanticError ) ,
142
+ SemanticError ( crate :: Bolt11SemanticError ) ,
143
143
}
144
144
145
145
/// The number of bits used to represent timestamps as defined in BOLT 11.
@@ -1154,16 +1154,16 @@ impl Bolt11Invoice {
1154
1154
}
1155
1155
1156
1156
/// Check that all mandatory fields are present
1157
- fn check_field_counts ( & self ) -> Result < ( ) , SemanticError > {
1157
+ fn check_field_counts ( & self ) -> Result < ( ) , Bolt11SemanticError > {
1158
1158
// "A writer MUST include exactly one p field […]."
1159
1159
let payment_hash_cnt = self . tagged_fields ( ) . filter ( |& tf| match * tf {
1160
1160
TaggedField :: PaymentHash ( _) => true ,
1161
1161
_ => false ,
1162
1162
} ) . count ( ) ;
1163
1163
if payment_hash_cnt < 1 {
1164
- return Err ( SemanticError :: NoPaymentHash ) ;
1164
+ return Err ( Bolt11SemanticError :: NoPaymentHash ) ;
1165
1165
} else if payment_hash_cnt > 1 {
1166
- return Err ( SemanticError :: MultiplePaymentHashes ) ;
1166
+ return Err ( Bolt11SemanticError :: MultiplePaymentHashes ) ;
1167
1167
}
1168
1168
1169
1169
// "A writer MUST include either exactly one d or exactly one h field."
@@ -1172,9 +1172,9 @@ impl Bolt11Invoice {
1172
1172
_ => false ,
1173
1173
} ) . count ( ) ;
1174
1174
if description_cnt < 1 {
1175
- return Err ( SemanticError :: NoDescription ) ;
1175
+ return Err ( Bolt11SemanticError :: NoDescription ) ;
1176
1176
} else if description_cnt > 1 {
1177
- return Err ( SemanticError :: MultipleDescriptions ) ;
1177
+ return Err ( Bolt11SemanticError :: MultipleDescriptions ) ;
1178
1178
}
1179
1179
1180
1180
self . check_payment_secret ( ) ?;
@@ -1183,33 +1183,33 @@ impl Bolt11Invoice {
1183
1183
}
1184
1184
1185
1185
/// Checks that there is exactly one payment secret field
1186
- fn check_payment_secret ( & self ) -> Result < ( ) , SemanticError > {
1186
+ fn check_payment_secret ( & self ) -> Result < ( ) , Bolt11SemanticError > {
1187
1187
// "A writer MUST include exactly one `s` field."
1188
1188
let payment_secret_count = self . tagged_fields ( ) . filter ( |& tf| match * tf {
1189
1189
TaggedField :: PaymentSecret ( _) => true ,
1190
1190
_ => false ,
1191
1191
} ) . count ( ) ;
1192
1192
if payment_secret_count < 1 {
1193
- return Err ( SemanticError :: NoPaymentSecret ) ;
1193
+ return Err ( Bolt11SemanticError :: NoPaymentSecret ) ;
1194
1194
} else if payment_secret_count > 1 {
1195
- return Err ( SemanticError :: MultiplePaymentSecrets ) ;
1195
+ return Err ( Bolt11SemanticError :: MultiplePaymentSecrets ) ;
1196
1196
}
1197
1197
1198
1198
Ok ( ( ) )
1199
1199
}
1200
1200
1201
1201
/// Check that amount is a whole number of millisatoshis
1202
- fn check_amount ( & self ) -> Result < ( ) , SemanticError > {
1202
+ fn check_amount ( & self ) -> Result < ( ) , Bolt11SemanticError > {
1203
1203
if let Some ( amount_pico_btc) = self . amount_pico_btc ( ) {
1204
1204
if amount_pico_btc % 10 != 0 {
1205
- return Err ( SemanticError :: ImpreciseAmount ) ;
1205
+ return Err ( Bolt11SemanticError :: ImpreciseAmount ) ;
1206
1206
}
1207
1207
}
1208
1208
Ok ( ( ) )
1209
1209
}
1210
1210
1211
1211
/// Check that feature bits are set as required
1212
- fn check_feature_bits ( & self ) -> Result < ( ) , SemanticError > {
1212
+ fn check_feature_bits ( & self ) -> Result < ( ) , Bolt11SemanticError > {
1213
1213
self . check_payment_secret ( ) ?;
1214
1214
1215
1215
// "A writer MUST set an s field if and only if the payment_secret feature is set."
@@ -1220,12 +1220,12 @@ impl Bolt11Invoice {
1220
1220
_ => false ,
1221
1221
} ) ;
1222
1222
match features {
1223
- None => Err ( SemanticError :: InvalidFeatures ) ,
1223
+ None => Err ( Bolt11SemanticError :: InvalidFeatures ) ,
1224
1224
Some ( TaggedField :: Features ( features) ) => {
1225
1225
if features. requires_unknown_bits ( ) {
1226
- Err ( SemanticError :: InvalidFeatures )
1226
+ Err ( Bolt11SemanticError :: InvalidFeatures )
1227
1227
} else if !features. supports_payment_secret ( ) {
1228
- Err ( SemanticError :: InvalidFeatures )
1228
+ Err ( Bolt11SemanticError :: InvalidFeatures )
1229
1229
} else {
1230
1230
Ok ( ( ) )
1231
1231
}
@@ -1235,18 +1235,18 @@ impl Bolt11Invoice {
1235
1235
}
1236
1236
1237
1237
/// Check that the invoice is signed correctly and that key recovery works
1238
- pub fn check_signature ( & self ) -> Result < ( ) , SemanticError > {
1238
+ pub fn check_signature ( & self ) -> Result < ( ) , Bolt11SemanticError > {
1239
1239
match self . signed_invoice . recover_payee_pub_key ( ) {
1240
1240
Err ( secp256k1:: Error :: InvalidRecoveryId ) =>
1241
- return Err ( SemanticError :: InvalidRecoveryId ) ,
1241
+ return Err ( Bolt11SemanticError :: InvalidRecoveryId ) ,
1242
1242
Err ( secp256k1:: Error :: InvalidSignature ) =>
1243
- return Err ( SemanticError :: InvalidSignature ) ,
1243
+ return Err ( Bolt11SemanticError :: InvalidSignature ) ,
1244
1244
Err ( e) => panic ! ( "no other error may occur, got {:?}" , e) ,
1245
1245
Ok ( _) => { } ,
1246
1246
}
1247
1247
1248
1248
if !self . signed_invoice . check_signature ( ) {
1249
- return Err ( SemanticError :: InvalidSignature ) ;
1249
+ return Err ( Bolt11SemanticError :: InvalidSignature ) ;
1250
1250
}
1251
1251
1252
1252
Ok ( ( ) )
@@ -1272,7 +1272,7 @@ impl Bolt11Invoice {
1272
1272
///
1273
1273
/// assert!(Bolt11Invoice::from_signed(signed).is_ok());
1274
1274
/// ```
1275
- pub fn from_signed ( signed_invoice : SignedRawBolt11Invoice ) -> Result < Self , SemanticError > {
1275
+ pub fn from_signed ( signed_invoice : SignedRawBolt11Invoice ) -> Result < Self , Bolt11SemanticError > {
1276
1276
let invoice = Bolt11Invoice {
1277
1277
signed_invoice,
1278
1278
} ;
@@ -1654,7 +1654,7 @@ impl std::error::Error for CreationError { }
1654
1654
/// Errors that may occur when converting a [`RawBolt11Invoice`] to a [`Bolt11Invoice`]. They relate to
1655
1655
/// the requirements sections in BOLT #11
1656
1656
#[ derive( Eq , PartialEq , Debug , Clone ) ]
1657
- pub enum SemanticError {
1657
+ pub enum Bolt11SemanticError {
1658
1658
/// The invoice is missing the mandatory payment hash
1659
1659
NoPaymentHash ,
1660
1660
@@ -1687,25 +1687,25 @@ pub enum SemanticError {
1687
1687
ImpreciseAmount ,
1688
1688
}
1689
1689
1690
- impl Display for SemanticError {
1690
+ impl Display for Bolt11SemanticError {
1691
1691
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
1692
1692
match self {
1693
- SemanticError :: NoPaymentHash => f. write_str ( "The invoice is missing the mandatory payment hash" ) ,
1694
- SemanticError :: MultiplePaymentHashes => f. write_str ( "The invoice has multiple payment hashes which isn't allowed" ) ,
1695
- SemanticError :: NoDescription => f. write_str ( "No description or description hash are part of the invoice" ) ,
1696
- SemanticError :: MultipleDescriptions => f. write_str ( "The invoice contains multiple descriptions and/or description hashes which isn't allowed" ) ,
1697
- SemanticError :: NoPaymentSecret => f. write_str ( "The invoice is missing the mandatory payment secret" ) ,
1698
- SemanticError :: MultiplePaymentSecrets => f. write_str ( "The invoice contains multiple payment secrets" ) ,
1699
- SemanticError :: InvalidFeatures => f. write_str ( "The invoice's features are invalid" ) ,
1700
- SemanticError :: InvalidRecoveryId => f. write_str ( "The recovery id doesn't fit the signature/pub key" ) ,
1701
- SemanticError :: InvalidSignature => f. write_str ( "The invoice's signature is invalid" ) ,
1702
- SemanticError :: ImpreciseAmount => f. write_str ( "The invoice's amount was not a whole number of millisatoshis" ) ,
1693
+ Bolt11SemanticError :: NoPaymentHash => f. write_str ( "The invoice is missing the mandatory payment hash" ) ,
1694
+ Bolt11SemanticError :: MultiplePaymentHashes => f. write_str ( "The invoice has multiple payment hashes which isn't allowed" ) ,
1695
+ Bolt11SemanticError :: NoDescription => f. write_str ( "No description or description hash are part of the invoice" ) ,
1696
+ Bolt11SemanticError :: MultipleDescriptions => f. write_str ( "The invoice contains multiple descriptions and/or description hashes which isn't allowed" ) ,
1697
+ Bolt11SemanticError :: NoPaymentSecret => f. write_str ( "The invoice is missing the mandatory payment secret" ) ,
1698
+ Bolt11SemanticError :: MultiplePaymentSecrets => f. write_str ( "The invoice contains multiple payment secrets" ) ,
1699
+ Bolt11SemanticError :: InvalidFeatures => f. write_str ( "The invoice's features are invalid" ) ,
1700
+ Bolt11SemanticError :: InvalidRecoveryId => f. write_str ( "The recovery id doesn't fit the signature/pub key" ) ,
1701
+ Bolt11SemanticError :: InvalidSignature => f. write_str ( "The invoice's signature is invalid" ) ,
1702
+ Bolt11SemanticError :: ImpreciseAmount => f. write_str ( "The invoice's amount was not a whole number of millisatoshis" ) ,
1703
1703
}
1704
1704
}
1705
1705
}
1706
1706
1707
1707
#[ cfg( feature = "std" ) ]
1708
- impl std:: error:: Error for SemanticError { }
1708
+ impl std:: error:: Error for Bolt11SemanticError { }
1709
1709
1710
1710
/// When signing using a fallible method either an user-supplied `SignError` or a [`CreationError`]
1711
1711
/// may occur.
@@ -1867,7 +1867,7 @@ mod test {
1867
1867
use secp256k1:: Secp256k1 ;
1868
1868
use secp256k1:: SecretKey ;
1869
1869
use crate :: { Bolt11Invoice , RawBolt11Invoice , RawHrp , RawDataPart , Currency , Sha256 , PositiveTimestamp ,
1870
- SemanticError } ;
1870
+ Bolt11SemanticError } ;
1871
1871
1872
1872
let private_key = SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ;
1873
1873
let payment_secret = lightning:: ln:: PaymentSecret ( [ 21 ; 32 ] ) ;
@@ -1898,7 +1898,7 @@ mod test {
1898
1898
invoice. data . tagged_fields . push ( PaymentSecret ( payment_secret) . into ( ) ) ;
1899
1899
invoice. sign :: < _ , ( ) > ( |hash| Ok ( Secp256k1 :: new ( ) . sign_ecdsa_recoverable ( hash, & private_key) ) )
1900
1900
} . unwrap ( ) ;
1901
- assert_eq ! ( Bolt11Invoice :: from_signed( invoice) , Err ( SemanticError :: InvalidFeatures ) ) ;
1901
+ assert_eq ! ( Bolt11Invoice :: from_signed( invoice) , Err ( Bolt11SemanticError :: InvalidFeatures ) ) ;
1902
1902
1903
1903
// Missing feature bits
1904
1904
let invoice = {
@@ -1907,7 +1907,7 @@ mod test {
1907
1907
invoice. data . tagged_fields . push ( Features ( InvoiceFeatures :: empty ( ) ) . into ( ) ) ;
1908
1908
invoice. sign :: < _ , ( ) > ( |hash| Ok ( Secp256k1 :: new ( ) . sign_ecdsa_recoverable ( hash, & private_key) ) )
1909
1909
} . unwrap ( ) ;
1910
- assert_eq ! ( Bolt11Invoice :: from_signed( invoice) , Err ( SemanticError :: InvalidFeatures ) ) ;
1910
+ assert_eq ! ( Bolt11Invoice :: from_signed( invoice) , Err ( Bolt11SemanticError :: InvalidFeatures ) ) ;
1911
1911
1912
1912
let mut payment_secret_features = InvoiceFeatures :: empty ( ) ;
1913
1913
payment_secret_features. set_payment_secret_required ( ) ;
@@ -1926,23 +1926,23 @@ mod test {
1926
1926
let invoice = invoice_template. clone ( ) ;
1927
1927
invoice. sign :: < _ , ( ) > ( |hash| Ok ( Secp256k1 :: new ( ) . sign_ecdsa_recoverable ( hash, & private_key) ) )
1928
1928
} . unwrap ( ) ;
1929
- assert_eq ! ( Bolt11Invoice :: from_signed( invoice) , Err ( SemanticError :: NoPaymentSecret ) ) ;
1929
+ assert_eq ! ( Bolt11Invoice :: from_signed( invoice) , Err ( Bolt11SemanticError :: NoPaymentSecret ) ) ;
1930
1930
1931
1931
// No payment secret or feature bits
1932
1932
let invoice = {
1933
1933
let mut invoice = invoice_template. clone ( ) ;
1934
1934
invoice. data . tagged_fields . push ( Features ( InvoiceFeatures :: empty ( ) ) . into ( ) ) ;
1935
1935
invoice. sign :: < _ , ( ) > ( |hash| Ok ( Secp256k1 :: new ( ) . sign_ecdsa_recoverable ( hash, & private_key) ) )
1936
1936
} . unwrap ( ) ;
1937
- assert_eq ! ( Bolt11Invoice :: from_signed( invoice) , Err ( SemanticError :: NoPaymentSecret ) ) ;
1937
+ assert_eq ! ( Bolt11Invoice :: from_signed( invoice) , Err ( Bolt11SemanticError :: NoPaymentSecret ) ) ;
1938
1938
1939
1939
// Missing payment secret
1940
1940
let invoice = {
1941
1941
let mut invoice = invoice_template. clone ( ) ;
1942
1942
invoice. data . tagged_fields . push ( Features ( payment_secret_features) . into ( ) ) ;
1943
1943
invoice. sign :: < _ , ( ) > ( |hash| Ok ( Secp256k1 :: new ( ) . sign_ecdsa_recoverable ( hash, & private_key) ) )
1944
1944
} . unwrap ( ) ;
1945
- assert_eq ! ( Bolt11Invoice :: from_signed( invoice) , Err ( SemanticError :: NoPaymentSecret ) ) ;
1945
+ assert_eq ! ( Bolt11Invoice :: from_signed( invoice) , Err ( Bolt11SemanticError :: NoPaymentSecret ) ) ;
1946
1946
1947
1947
// Multiple payment secrets
1948
1948
let invoice = {
@@ -1951,7 +1951,7 @@ mod test {
1951
1951
invoice. data . tagged_fields . push ( PaymentSecret ( payment_secret) . into ( ) ) ;
1952
1952
invoice. sign :: < _ , ( ) > ( |hash| Ok ( Secp256k1 :: new ( ) . sign_ecdsa_recoverable ( hash, & private_key) ) )
1953
1953
} . unwrap ( ) ;
1954
- assert_eq ! ( Bolt11Invoice :: from_signed( invoice) , Err ( SemanticError :: MultiplePaymentSecrets ) ) ;
1954
+ assert_eq ! ( Bolt11Invoice :: from_signed( invoice) , Err ( Bolt11SemanticError :: MultiplePaymentSecrets ) ) ;
1955
1955
}
1956
1956
1957
1957
#[ test]
0 commit comments