2121import java .util .regex .Matcher ;
2222import java .util .regex .Pattern ;
2323
24+ import nostr .crypto .schnorr .Schnorr ;
25+ import nostr .crypto .bech32 .Bech32 ;
26+ import nostr .util .NostrException ;
27+ import nostr .util .NostrUtil ;
28+
2429public class Event {
2530 private final int created_at ;
2631 private final String content ;
@@ -87,7 +92,13 @@ public void save(SQLiteDatabase database, String userPubKey, String relayUrl) {
8792 }
8893
8994 protected boolean isValid () {
90- return !id .isEmpty () && !sig .isEmpty () && created_at <= System .currentTimeMillis () / 1000L ;
95+ boolean verified = false ;
96+ try {
97+ verified = Schnorr .verify (NostrUtil .hexToBytes (id ), NostrUtil .hexToBytes (pubkey ), NostrUtil .hexToBytes (sig ));
98+ } catch (Exception e ) {
99+ e .printStackTrace ();
100+ }
101+ return verified && created_at <= System .currentTimeMillis () / 1000L ;
91102 }
92103
93104 protected String getMainEventId () {
@@ -143,9 +154,9 @@ protected int getUserMentioned(String userPubKey) {
143154
144155 protected String getRepostId () {
145156 String match = null ;
146- Matcher m = Pattern .compile ("#\\ [(\\ d+)\\ ]" ).matcher (content );
147- while ( m .find ()) {
148- int position = Integer .parseInt (m .group (1 ));
157+ Matcher matcherTag = Pattern .compile ("#\\ [(\\ d+)\\ ]" ).matcher (content );
158+ if ( matcherTag .find ()) {
159+ int position = Integer .parseInt (matcherTag .group (1 ));
149160 try {
150161 JSONArray tag = tags .getJSONArray (position );
151162 String tagKind = tag .getString (0 );
@@ -156,6 +167,15 @@ protected String getRepostId() {
156167 e .printStackTrace ();
157168 }
158169 }
170+ Matcher matcherBech = Pattern .compile ("nostr:((nevent1|note1)\\ S+)" ).matcher (content );
171+ if (matcherBech .find ()) {
172+ String bech32 = matcherBech .group (1 );
173+ try {
174+ match = Bech32 .fromBech32 (bech32 );
175+ } catch (NostrException e ) {
176+ e .printStackTrace ();
177+ }
178+ }
159179 return match ;
160180 }
161181
0 commit comments