Skip to content

Commit

Permalink
Merge #197: nostr: fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Nov 30, 2023
2 parents 737b59a + b8d2c95 commit 90bdce4
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 34 deletions.
8 changes: 4 additions & 4 deletions crates/nostr/src/nips/nip04.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl From<secp256k1::Error> for Error {
}
}

/// Entrypt
/// Encrypt
#[cfg(feature = "std")]
pub fn encrypt<T>(sk: &SecretKey, pk: &XOnlyPublicKey, text: T) -> Result<String, Error>
where
Expand All @@ -74,7 +74,7 @@ where
encrypt_with_rng(&mut rand::thread_rng(), sk, pk, text)
}

/// Entrypt
/// Encrypt
pub fn encrypt_with_rng<R, T>(
rng: &mut R,
sk: &SecretKey,
Expand Down Expand Up @@ -106,7 +106,7 @@ where
))
}

/// Dectypt
/// Decrypt
pub fn decrypt<S>(
sk: &SecretKey,
pk: &XOnlyPublicKey,
Expand Down Expand Up @@ -188,7 +188,7 @@ mod tests {
Error::Base64Decode
);

//Content encrypted with aes256 using GCM mode
// Content encrypted with aes256 using GCM mode
assert_eq!(
decrypt(
&sender_sk,
Expand Down
8 changes: 4 additions & 4 deletions crates/nostr/src/nips/nip15.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ pub struct CustomerOrder {
pub id: String,
/// Message type (0 in case of customer order)
#[serde(rename = "type")]
pub type_: usize,
pub r#type: usize,
/// Name of the customer
name: Option<String>,
/// Address of the customer if product is physical
Expand All @@ -268,7 +268,7 @@ pub struct MerchantPaymentRequest {
pub id: String,
/// Message type (1 in case of merchant payment request)
#[serde(rename = "type")]
pub type_: usize,
pub r#type: usize,
/// Available payment options
pub payment_options: Vec<PaymentOption>,
}
Expand All @@ -280,7 +280,7 @@ pub struct MerchantVerifyPayment {
pub id: String,
/// Type of the message (2 in case of merchant verify payment)
#[serde(rename = "type")]
pub type_: usize,
pub r#type: usize,
/// Payment successful
pub paid: bool,
/// Item shipped
Expand Down Expand Up @@ -312,7 +312,7 @@ pub struct CustomerOrderItem {
pub struct PaymentOption {
/// Name of the payment option
#[serde(rename = "type")]
pub type_: String,
pub r#type: String,
/// Payment link (url, ln invoice, etc.)
pub link: String,
}
Expand Down
38 changes: 18 additions & 20 deletions crates/nostr/src/nips/nip26.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ impl DelegationTag {
where
C: Verification,
{
// verify signature
// Verify signature
verify_delegation_signature_with_ctx(
secp,
self.delegator_pubkey,
Expand All @@ -310,7 +310,7 @@ impl DelegationTag {
)
.map_err(|_| Error::ConditionsValidation(ValidationError::InvalidSignature))?;

// validate conditions
// Validate conditions
self.conditions.evaluate(event_properties)?;

Ok(())
Expand Down Expand Up @@ -469,15 +469,15 @@ impl Conditions {
Ok(())
}

/// Get [`Vec<Contifion>`]
/// Get [`Vec<Condition>`]
pub fn inner(&self) -> Vec<Condition> {
self.0.clone()
}
}

impl fmt::Display for Conditions {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// convert parts, join
// Convert parts, join
let conditions: String = self
.0
.iter()
Expand Down Expand Up @@ -534,7 +534,6 @@ impl EventProperties {
}

/// Create from an Event
pub fn from_event(event: &Event) -> Self {
Self {
kind: event.kind.as_u64(),
Expand Down Expand Up @@ -601,7 +600,7 @@ mod test {
let tag =
DelegationTag::new(&delegator_keys, delegatee_pubkey, conditions.clone()).unwrap();

// verify signature (it's variable)
// Verify signature (it's variable)
let verify_result = verify_delegation_signature(
delegator_keys.public_key(),
tag.signature(),
Expand All @@ -610,7 +609,7 @@ mod test {
);
assert!(verify_result.is_ok());

// signature changes, cannot compare to expected constant, use signature from result
// Signature changes, cannot compare to expected constant, use signature from result
let expected = format!(
"[\"delegation\",\"1a459a8a6aa6441d480ba665fb8fb21a4cfe8bcacb7d87300f8046a558a3fce4\",\"kind=1&created_at>1676067553&created_at<1678659553\",\"{}\"]",
&tag.signature.to_string());
Expand Down Expand Up @@ -658,14 +657,13 @@ mod test {
)
.is_ok());

// additional test: verify a value from inside the tag
// Additional test: verify a value from inside the tag
assert_eq!(
tag.conditions().to_string(),
"kind=1&created_at>1676067553&created_at<1678659553"
);

// additional test: try validation with invalid values, invalid event kind

// Additional test: try validation with invalid values, invalid event kind
match tag
.validate_with_ctx(
&secp,
Expand Down Expand Up @@ -697,7 +695,7 @@ mod test {
let signature =
sign_delegation(&delegator_keys, delegatee_public_key, conditions.clone()).unwrap();

// signature is changing, validate by verify method
// Signature is changing, validate by verify method
let verify_result = verify_delegation_signature(
delegator_keys.public_key(),
signature,
Expand All @@ -724,7 +722,7 @@ mod test {
let signature =
sign_delegation(&delegator_keys, delegatee_public_key, conditions.clone()).unwrap();

// signature is changing, validate by lowlevel verify
// Signature is changing, validate by lowlevel verify
let unhashed_token: String =
format!("nostr:delegation:{delegatee_public_key}:{conditions}");
let hashed_token = Sha256Hash::hash(unhashed_token.as_bytes());
Expand All @@ -743,7 +741,8 @@ mod test {
SecretKey::from_str("ee35e8bb71131c02c1d7e73231daa48e9953d329a4b701f7133c8f46dd21139c")
.unwrap();
let delegator_keys = Keys::new_with_ctx(&secp, delegator_secret_key);
// use one concrete signature

// Use one concrete signature
let signature = Signature::from_str("f9f00fcf8480686d9da6dfde1187d4ba19c54f6ace4c73361a14db429c4b96eb30b29283d6ea1f06ba9e18e06e408244c689039ddadbacffc56060f3da5b04b8").unwrap();
let delegatee_pk = XOnlyPublicKey::from_str(
"477318cfb5427b9cfc66a9fa376150c1ddbc62115ae27cef72417eb959691396",
Expand Down Expand Up @@ -829,12 +828,12 @@ mod test {

let tag = DelegationTag::new(&delegator_keys, delegatee_pubkey, conditions).unwrap();

// positive
// Positive
assert!(tag
.validate(delegatee_pubkey, &EventProperties::new(1, 1677000000))
.is_ok());

// signature verification fails if wrong delegatee key is given
// Signature verification fails if wrong delegatee key is given
let wrong_pubkey = XOnlyPublicKey::from_str(
"14b91c20c0287495615210ef7772192d43eca6d2a34342e723bd237035e7955b",
)
Expand All @@ -850,7 +849,7 @@ mod test {
_ => panic!("Expected ConditionsValidation"),
}

// wrong event kind
// Wrong event kind
match tag
.validate(delegatee_pubkey, &EventProperties::new(9, 1677000000))
.err()
Expand All @@ -860,7 +859,7 @@ mod test {
_ => panic!("Expected ConditionsValidation"),
};

// wrong creation time
// Wrong creation time
match tag
.validate(delegatee_pubkey, &EventProperties::new(1, 1679000000))
.err()
Expand Down Expand Up @@ -892,11 +891,11 @@ mod test {
"kind=1&created_at>1674834236&created_at<1677426236"
);

// special: empty string
// Special: empty string
let c_empty = Conditions::from_str("").unwrap();
assert_eq!(c_empty.to_string(), "");

// one condition
// One condition
let c_one = Conditions::from_str("created_at<10000").unwrap();
assert_eq!(c_one.to_string(), "created_at<10000");
}
Expand Down Expand Up @@ -962,7 +961,6 @@ mod test {
assert!(c_complex
.evaluate(&EventProperties::new(1, 1677000000))
.is_ok());
//assert_eq!(c_complex.evaluate(&EventProperties{ kind: 1, created_time: 1677000000}).err().unwrap(), ValidationError::InvalidKind);
assert_eq!(
c_complex
.evaluate(&EventProperties::new(5, 1677000000))
Expand Down
4 changes: 2 additions & 2 deletions crates/nostr/src/nips/nip46.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ impl Message {
}
}

/// check if current [`Message`] is a request
/// Check if current [`Message`] is a request
pub fn is_request(&self) -> bool {
match self {
Message::Request { .. } => true,
Expand Down Expand Up @@ -465,7 +465,7 @@ impl Message {
R: Rng + CryptoRng,
{
let req = self.to_request()?;
// TODO: remove if let SOme(res) = ...
// TODO: remove if let Some(res) = ...
if let Some(res) = req.generate_response_with_ctx(secp, rng, keys)? {
Ok(Some(Self::response(self.id(), Some(res), None)))
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/nostr/src/nips/nip98.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl From<bitcoin::hashes::hex::Error> for Error {

/// HTTP Data
pub struct HttpData {
/// absolute request URL
/// Absolute request URL
pub url: UncheckedUrl,
/// HTTP method
pub method: HttpMethod,
Expand Down
2 changes: 1 addition & 1 deletion crates/nostr/src/types/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Metadata {
}
}

/// Set display_name
/// Set display name
pub fn display_name<S>(self, display_name: S) -> Self
where
S: Into<String>,
Expand Down
4 changes: 2 additions & 2 deletions crates/nostr/src/types/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ impl Timestamp {
let timestamp: u64 = self.as_u64();

if timestamp >= 253_402_300_800 {
// year 9999
// Year 9999
return String::from("Unavailable");
}

/* 2000-03-01 (mod 400 year, immediately after feb29 */
// 2000-03-01 (mod 400 year, immediately after feb29
const LEAPOCH: i64 = 11017;
const DAYS_PER_400Y: i64 = 365 * 400 + 97;
const DAYS_PER_100Y: i64 = 365 * 100 + 24;
Expand Down

0 comments on commit 90bdce4

Please sign in to comment.