Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit ad3458b

Browse files
author
KoalaSat
authored
Include Java nostr (#480)
2 parents 5599523 + 8b28b9d commit ad3458b

15 files changed

Lines changed: 60 additions & 33 deletions

File tree

.github/workflows/android-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- uses: actions/setup-java@v3
2222
with:
2323
distribution: temurin
24-
java-version: 11
24+
java-version: 19
2525

2626
- name: Setup Gradle
2727
uses: gradle/gradle-build-action@v2

android/app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ dependencies {
165165

166166
implementation 'com.facebook.fresco:animated-webp:2.6.0'
167167
implementation 'com.facebook.fresco:webpsupport:2.6.0'
168+
implementation 'com.github.KoalaSat.nostr-java:nostr-base:70e62e24ad'
169+
implementation 'com.github.KoalaSat.nostr-java:nostr-event:70e62e24ad'
168170

169171
implementation 'com.facebook.fresco:animated-gif:2.6.0'
170172

android/app/src/main/java/com/nostros/classes/Event.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
import java.util.regex.Matcher;
2222
import 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+
2429
public 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

android/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

3+
allprojects {
4+
repositories {
5+
maven { url 'https://jitpack.io' }
6+
}
7+
}
8+
39
buildscript {
410
ext {
511
buildToolsVersion = "33.0.0"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

frontend/Components/MenuItems/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const MenuItems: React.FC = () => {
4545

4646
React.useEffect(() => {
4747
setActiveRelays(relays.filter((relay) => relay.active).length)
48-
}, [relays])
48+
}, [relays, balance])
4949

5050
const onPressLogout: () => void = () => {
5151
logout()
@@ -154,7 +154,7 @@ export const MenuItems: React.FC = () => {
154154
onPress={() => onPressItem('wallet', 1)}
155155
onTouchEnd={() => setDrawerItemIndex(-1)}
156156
right={() => {
157-
if (!type || !balance) return <></>
157+
if (!type || balance === undefined) return <></>
158158
return (
159159
<Text>
160160
{`${balance} `}

frontend/Components/TextContent/LinksPreview/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export const LinksPreview: React.FC<TextContentProps> = ({ urls, lnUrl }) => {
7878
rowPosition: 'top' | 'bottom',
7979
) => JSX.Element = (link, index, rowPosition) => (
8080
<TouchableWithoutFeedback
81+
key={link}
8182
onPress={() =>
8283
navigate('ImageGallery', {
8384
urls: imageLinks,
@@ -86,7 +87,6 @@ export const LinksPreview: React.FC<TextContentProps> = ({ urls, lnUrl }) => {
8687
}
8788
>
8889
<FastImage
89-
key={link}
9090
style={[
9191
styles.cardCover,
9292
{

frontend/Contexts/WalletContext.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export const WalletContextProvider = ({ children }: WalletContextProviderProps):
131131

132132
const logoutWallet: () => void = () => {
133133
SInfo.deleteItem('lndHub', {})
134+
SInfo.deleteItem('lnBits', {})
134135
setType(undefined)
135136
setConfig(undefined)
136137
setBalance(undefined)

frontend/Pages/ConversationPage/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const ConversationPage: React.FC<ConversationPageProps> = ({ route }) =>
7575

7676
return () =>
7777
relayPool?.unsubscribe([
78-
`conversation${route.params.pubKey}`,
78+
`conversation${route.params.pubKey.substring(0, 8)}`,
7979
`conversation-replies${route.params.pubKey.substring(0, 8)}`,
8080
])
8181
}, []),
@@ -272,7 +272,7 @@ export const ConversationPage: React.FC<ConversationPageProps> = ({ route }) =>
272272
if (!publicKey || !privateKey || !otherUser) return <></>
273273

274274
const eTags = getETags(item)
275-
const showAvatar = directMessages[index - 1]?.pubkey !== item.pubkey
275+
const showAvatar = index < 1 || directMessages[index - 1]?.pubkey !== item.pubkey
276276
const isReply = eTags.length > 0
277277
const repliedMessageId = eTags.length > 0 ? eTags[eTags.length - 1][1] : undefined
278278
const repliedMessage = directMessages.find((message) => message.id === repliedMessageId)

frontend/Pages/HomePage/HomeFeed/MyFeed/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export const MyFeed: React.FC<MyFeedProps> = ({
9292

9393
const message: RelayFilters = {
9494
kinds: [Kind.Text, Kind.RecommendRelay],
95-
authors: contacts
95+
authors: contacts,
9696
}
9797
if (results.length >= pageSize) {
9898
message.since = results[pageSize - 1].created_at

0 commit comments

Comments
 (0)