mirror of
https://github.com/KoalaSat/nostros.git
synced 2024-09-29 22:50:43 +00:00
Include Java nostr
This commit is contained in:
parent
55995232ae
commit
8b28b9dae0
2
.github/workflows/android-build.yml
vendored
2
.github/workflows/android-build.yml
vendored
@ -21,7 +21,7 @@ jobs:
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: 11
|
||||
java-version: 19
|
||||
|
||||
- name: Setup Gradle
|
||||
uses: gradle/gradle-build-action@v2
|
||||
|
@ -165,6 +165,8 @@ dependencies {
|
||||
|
||||
implementation 'com.facebook.fresco:animated-webp:2.6.0'
|
||||
implementation 'com.facebook.fresco:webpsupport:2.6.0'
|
||||
implementation 'com.github.KoalaSat.nostr-java:nostr-base:70e62e24ad'
|
||||
implementation 'com.github.KoalaSat.nostr-java:nostr-event:70e62e24ad'
|
||||
|
||||
implementation 'com.facebook.fresco:animated-gif:2.6.0'
|
||||
|
||||
|
@ -21,6 +21,11 @@ import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import nostr.crypto.schnorr.Schnorr;
|
||||
import nostr.crypto.bech32.Bech32;
|
||||
import nostr.util.NostrException;
|
||||
import nostr.util.NostrUtil;
|
||||
|
||||
public class Event {
|
||||
private final int created_at;
|
||||
private final String content;
|
||||
@ -87,7 +92,13 @@ public class Event {
|
||||
}
|
||||
|
||||
protected boolean isValid() {
|
||||
return !id.isEmpty() && !sig.isEmpty() && created_at <= System.currentTimeMillis() / 1000L;
|
||||
boolean verified = false;
|
||||
try {
|
||||
verified = Schnorr.verify(NostrUtil.hexToBytes(id), NostrUtil.hexToBytes(pubkey), NostrUtil.hexToBytes(sig));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return verified && created_at <= System.currentTimeMillis() / 1000L;
|
||||
}
|
||||
|
||||
protected String getMainEventId() {
|
||||
@ -143,9 +154,9 @@ public class Event {
|
||||
|
||||
protected String getRepostId() {
|
||||
String match = null;
|
||||
Matcher m = Pattern.compile("#\\[(\\d+)\\]").matcher(content);
|
||||
while (m.find()) {
|
||||
int position = Integer.parseInt(m.group(1));
|
||||
Matcher matcherTag = Pattern.compile("#\\[(\\d+)\\]").matcher(content);
|
||||
if (matcherTag.find()) {
|
||||
int position = Integer.parseInt(matcherTag.group(1));
|
||||
try {
|
||||
JSONArray tag = tags.getJSONArray(position);
|
||||
String tagKind = tag.getString(0);
|
||||
@ -156,6 +167,15 @@ public class Event {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Matcher matcherBech = Pattern.compile("nostr:((nevent1|note1)\\S+)").matcher(content);
|
||||
if (matcherBech.find()) {
|
||||
String bech32 = matcherBech.group(1);
|
||||
try {
|
||||
match = Bech32.fromBech32(bech32);
|
||||
} catch (NostrException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return match;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,11 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
maven { url 'https://jitpack.io' }
|
||||
}
|
||||
}
|
||||
|
||||
buildscript {
|
||||
ext {
|
||||
buildToolsVersion = "33.0.0"
|
||||
|
@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
@ -45,7 +45,7 @@ export const MenuItems: React.FC = () => {
|
||||
|
||||
React.useEffect(() => {
|
||||
setActiveRelays(relays.filter((relay) => relay.active).length)
|
||||
}, [relays])
|
||||
}, [relays, balance])
|
||||
|
||||
const onPressLogout: () => void = () => {
|
||||
logout()
|
||||
@ -154,7 +154,7 @@ export const MenuItems: React.FC = () => {
|
||||
onPress={() => onPressItem('wallet', 1)}
|
||||
onTouchEnd={() => setDrawerItemIndex(-1)}
|
||||
right={() => {
|
||||
if (!type || !balance) return <></>
|
||||
if (!type || balance === undefined) return <></>
|
||||
return (
|
||||
<Text>
|
||||
{`${balance} `}
|
||||
|
@ -78,6 +78,7 @@ export const LinksPreview: React.FC<TextContentProps> = ({ urls, lnUrl }) => {
|
||||
rowPosition: 'top' | 'bottom',
|
||||
) => JSX.Element = (link, index, rowPosition) => (
|
||||
<TouchableWithoutFeedback
|
||||
key={link}
|
||||
onPress={() =>
|
||||
navigate('ImageGallery', {
|
||||
urls: imageLinks,
|
||||
@ -86,7 +87,6 @@ export const LinksPreview: React.FC<TextContentProps> = ({ urls, lnUrl }) => {
|
||||
}
|
||||
>
|
||||
<FastImage
|
||||
key={link}
|
||||
style={[
|
||||
styles.cardCover,
|
||||
{
|
||||
|
@ -131,6 +131,7 @@ export const WalletContextProvider = ({ children }: WalletContextProviderProps):
|
||||
|
||||
const logoutWallet: () => void = () => {
|
||||
SInfo.deleteItem('lndHub', {})
|
||||
SInfo.deleteItem('lnBits', {})
|
||||
setType(undefined)
|
||||
setConfig(undefined)
|
||||
setBalance(undefined)
|
||||
|
@ -75,7 +75,7 @@ export const ConversationPage: React.FC<ConversationPageProps> = ({ route }) =>
|
||||
|
||||
return () =>
|
||||
relayPool?.unsubscribe([
|
||||
`conversation${route.params.pubKey}`,
|
||||
`conversation${route.params.pubKey.substring(0, 8)}`,
|
||||
`conversation-replies${route.params.pubKey.substring(0, 8)}`,
|
||||
])
|
||||
}, []),
|
||||
@ -272,7 +272,7 @@ export const ConversationPage: React.FC<ConversationPageProps> = ({ route }) =>
|
||||
if (!publicKey || !privateKey || !otherUser) return <></>
|
||||
|
||||
const eTags = getETags(item)
|
||||
const showAvatar = directMessages[index - 1]?.pubkey !== item.pubkey
|
||||
const showAvatar = index < 1 || directMessages[index - 1]?.pubkey !== item.pubkey
|
||||
const isReply = eTags.length > 0
|
||||
const repliedMessageId = eTags.length > 0 ? eTags[eTags.length - 1][1] : undefined
|
||||
const repliedMessage = directMessages.find((message) => message.id === repliedMessageId)
|
||||
|
@ -92,7 +92,7 @@ export const MyFeed: React.FC<MyFeedProps> = ({
|
||||
|
||||
const message: RelayFilters = {
|
||||
kinds: [Kind.Text, Kind.RecommendRelay],
|
||||
authors: contacts
|
||||
authors: contacts,
|
||||
}
|
||||
if (results.length >= pageSize) {
|
||||
message.since = results[pageSize - 1].created_at
|
||||
|
@ -119,16 +119,16 @@ export const NotificationsFeed: React.FC = () => {
|
||||
{
|
||||
kinds: [Kind.Text],
|
||||
'#p': [publicKey],
|
||||
since: limitDate
|
||||
since: limitDate,
|
||||
},
|
||||
{
|
||||
kinds: [Kind.Text],
|
||||
'#e': [publicKey],
|
||||
since: limitDate
|
||||
since: limitDate,
|
||||
},
|
||||
{
|
||||
kinds: [30001],
|
||||
authors: [publicKey]
|
||||
authors: [publicKey],
|
||||
},
|
||||
])
|
||||
}
|
||||
|
@ -37,9 +37,9 @@ export const NotePage: React.FC<NotePageProps> = ({ route }) => {
|
||||
|
||||
return () =>
|
||||
relayPool?.unsubscribe([
|
||||
`meta-notepage${route.params.noteId}`,
|
||||
`notepage${route.params.noteId}`,
|
||||
`notepage-replies-${route.params.noteId}`,
|
||||
`meta-notepage${route.params.noteId.substring(0, 8)}`,
|
||||
`notepage${route.params.noteId.substring(0, 8)}`,
|
||||
`notepage-replies-${route.params.noteId.substring(0, 8)}`,
|
||||
])
|
||||
}, []),
|
||||
)
|
||||
|
@ -44,7 +44,7 @@ export const NotesFeed: React.FC<NotesFeedProps> = ({
|
||||
}, [pageSize, lastEventId, activeTab])
|
||||
|
||||
const subscribe: () => Promise<void> = async () => {
|
||||
relayPool?.subscribe(`profile-user${publicKey}`, [
|
||||
relayPool?.subscribe(`profile-user${publicKey.substring(0, 8)}`, [
|
||||
{
|
||||
kinds: [Kind.Text, Kind.RecommendRelay],
|
||||
authors: [publicKey],
|
||||
|
@ -56,18 +56,16 @@ export const WalletPage: React.FC = () => {
|
||||
if (database && publicKey) {
|
||||
const preimages: string[] = actions.filter((item) => item.id !== '').map((item) => item.id)
|
||||
|
||||
getZaps(database, { preimages }).then(
|
||||
(results) => {
|
||||
if (results) {
|
||||
const map: Record<string, Zap> = {}
|
||||
results.forEach((zap) => {
|
||||
if (!zap.preimage || zap.preimage === '') return
|
||||
map[zap.preimage] = zap
|
||||
})
|
||||
setZaps(map)
|
||||
}
|
||||
},
|
||||
)
|
||||
getZaps(database, { preimages }).then((results) => {
|
||||
if (results) {
|
||||
const map: Record<string, Zap> = {}
|
||||
results.forEach((zap) => {
|
||||
if (!zap.preimage || zap.preimage === '') return
|
||||
map[zap.preimage] = zap
|
||||
})
|
||||
setZaps(map)
|
||||
}
|
||||
})
|
||||
relayPool?.subscribe(`profile-zaps${publicKey.substring(0, 8)}`, [
|
||||
{
|
||||
kinds: [9735],
|
||||
|
@ -53,7 +53,7 @@ class LndHub {
|
||||
private readonly getTransactions: () => Promise<WalletAction[] | undefined> = async () => {
|
||||
if (!this.config) return
|
||||
const response = await axios.get(`${this.config.url}/gettxs`, { headers: this.getHeaders() })
|
||||
if (response) {
|
||||
if (response?.data) {
|
||||
return response.data.map((item: any) => {
|
||||
return {
|
||||
id: item.payment_preimage,
|
||||
@ -71,7 +71,7 @@ class LndHub {
|
||||
const response = await axios.get(`${this.config.url}/getuserinvoices`, {
|
||||
headers: this.getHeaders(),
|
||||
})
|
||||
if (response) {
|
||||
if (response?.data) {
|
||||
return response.data
|
||||
.filter((item: any) => item.ispaid)
|
||||
.map((item: any) => {
|
||||
|
Loading…
Reference in New Issue
Block a user