Skip to content

Commit

Permalink
feat: Implement a function to verify NIP01Event
Browse files Browse the repository at this point in the history
  • Loading branch information
EjembiEmmanuel committed May 15, 2024
1 parent dfe1e77 commit bb5c307
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion onchain/src/bip340.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use core::to_byte_array::AppendFormattedToByteArray;
use core::traits::Into;
use starknet::{secp256k1::{Secp256k1Point}, secp256_trait::{Secp256Trait, Secp256PointTrait}};


const TWO_POW_32: u128 = 0x100000000;
const TWO_POW_64: u128 = 0x10000000000000000;
const TWO_POW_96: u128 = 0x1000000000000000000000000;
Expand Down Expand Up @@ -90,7 +91,7 @@ fn hash_challenge(rx: u256, px: u256, m: ByteArray) -> u256 {
/// # Returns
/// Returns `true` if the signature is valid for the given message and public key; otherwise,
/// returns `false`.
fn verify(px: u256, rx: u256, s: u256, m: ByteArray) -> bool {
pub fn verify(px: u256, rx: u256, s: u256, m: ByteArray) -> bool {
let n = Secp256Trait::<Secp256k1Point>::get_curve_size();

if px >= p || rx >= p || s >= n {
Expand Down Expand Up @@ -124,6 +125,7 @@ fn verify(px: u256, rx: u256, s: u256, m: ByteArray) -> bool {
!(Rx == 0 && Ry == 0) && Ry % 2 == 0 && Rx == rx
}


#[cfg(test)]
mod tests {
use core::clone::Clone;
Expand Down
1 change: 1 addition & 0 deletions onchain/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pub mod bech32;
pub mod bip340;
pub mod nostr_profile;
pub mod social_pay_request;
pub mod nip01;
2 changes: 1 addition & 1 deletion onchain/src/nip01.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[derive(Copy, Drop)]
struct NIP01Event {
pub struct NIP01Event {
id: u256,
pubkey: u256,
created_at: u64,
Expand Down
2 changes: 2 additions & 0 deletions onchain/src/social_pay_request.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use core::to_byte_array::{FormatAsByteArray, AppendFormattedToByteArray};
use core::fmt::{Display, Formatter, Error};

use joyboy::nostr_profile::{NostrProfile, encode};
use joyboy::bip340::{verify};
use joyboy::nip01::{NIP01Event};

type NostrKey = u256;

Expand Down

0 comments on commit bb5c307

Please sign in to comment.