Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
51e0bda
readme update
avlo Jun 14, 2024
a5ab118
java 22
avlo Jun 17, 2024
03c9e41
unit tests
avlo Jun 19, 2024
9fa2e61
Merge branch 'deserializer_refactor' into java22
avlo Jun 19, 2024
5bdd422
merge
avlo Jun 19, 2024
b5e2655
merge
avlo Jun 19, 2024
867a0bb
added kind validators to classified listing event and zap request/rec…
avlo Jun 24, 2024
022fcff
Merge branch 'kind_validators' into java22
avlo Jun 26, 2024
cc9d5fd
added required constructor parameter "subscriptionId" to EventMessage…
avlo Aug 21, 2024
5a8f13b
added NIP-52 CalendarTimeBasedEvent, its associated factories and tests
avlo Sep 4, 2024
8f0bf01
added CalendarContent to BaseTag mappings for NIP52
avlo Sep 5, 2024
6b9ebc0
Merge branch 'develop' into add_NIP52_event
avlo Sep 5, 2024
1db5188
Merge branch 'develop' into java22
avlo Sep 5, 2024
ece11dd
Merge branch 'add_NIP52_event' into java22
avlo Sep 5, 2024
c7b793f
simplified web-socket client using Spring WebSocketClient & Netty
avlo Sep 6, 2024
2302457
deprecated URL changed to URI
avlo Sep 6, 2024
4399ecc
converting to builder construction
avlo Sep 7, 2024
ff50e33
initial unit tests atop spring websocketclient
avlo Sep 7, 2024
c983a4b
auto-serialization & deserialization via @Jacksonized & @SuperBuilder
avlo Sep 7, 2024
11d42b7
customized CalendarTimeBasedEvent builder/superbuilder with deseriali…
avlo Sep 7, 2024
dd89ee8
test fixes
avlo Sep 10, 2024
b68502b
re: nostr.api.Nostr (client) implementation- given it's complexity/nu…
avlo Sep 10, 2024
5daff43
commit cleanup
avlo Sep 10, 2024
24d030e
Merge branch 'java22' into spring_websocketclient
avlo Sep 10, 2024
ec6bd3a
added nip52 api test
avlo Sep 10, 2024
18dc18d
add asserts for expected values
avlo Sep 12, 2024
744ecf8
updated classified listings for use with websocket and builder
avlo Sep 12, 2024
36be2dd
working snap
avlo Sep 12, 2024
a0af7e2
deserialization
avlo Sep 13, 2024
202b3e4
round trip both event followed by request confirming event receipt an…
avlo Sep 13, 2024
a0095dc
merge branch spring_websocketclient-classified_listing
avlo Sep 13, 2024
85c0c08
merge
avlo Sep 13, 2024
ab40328
cleanup
avlo Sep 13, 2024
e49c059
cleanup
avlo Sep 13, 2024
0bb9ebe
cleanup
avlo Sep 13, 2024
98689bd
- EventNostr send() methods should (and now do) return OkMessage (pre…
avlo Sep 25, 2024
65585a8
dependency cleanup
avlo Sep 26, 2024
7954709
Merge branch 'spring_websocketclient' into java22
avlo Sep 26, 2024
72b49b8
dependency cleanup, unit tests
avlo Sep 26, 2024
edadae1
session close implementations
avlo Sep 26, 2024
346376d
openbeans replaced with java beans
avlo Sep 26, 2024
668b446
cleanup
avlo Sep 26, 2024
5ddc219
calendar content deserializer + unit tests
avlo Sep 26, 2024
47b3e06
Merge branch 'java22_spring_websocketclient' into java22
avlo Sep 26, 2024
140a602
CalendarTimeBasedEvent API unit tests
avlo Sep 26, 2024
020a470
Subscriber impl refactored out, removed
avlo Sep 26, 2024
e8b34aa
added order-independent JSON comparator for tests
avlo Sep 26, 2024
3e767a5
test assertions updated to use JsonComparator equivalence (aka, order…
avlo Sep 27, 2024
a82fe5d
test assertions updated to use JsonComparator equivalence (aka, order…
avlo Sep 27, 2024
658a7b4
tag mappings
avlo Sep 28, 2024
fd00957
java 21
avlo Dec 10, 2024
904bc32
Merge branch 'upstream-develop' into java21-merge-upstream_develop
avlo Dec 10, 2024
e8048fd
in the interest of minimizing the number of nostr-java core/foundatio…
avlo Dec 11, 2024
a722eff
AddressTag to AddressableTag
avlo Dec 13, 2024
ba7b43e
added Signature fromString(String) method
avlo Dec 14, 2024
0431cdc
updated relay URI(s) to Map<String, String> obtained from/using ApiE…
avlo Dec 16, 2024
711ec0c
EventMessage.encode() replaced explicit null check with Optional.ofNu…
avlo Dec 17, 2024
ff01b21
merge from java21 branch
avlo Dec 17, 2024
a72c6fb
added single parameter ctor(Event) to EventMessageFactory & related u…
avlo Dec 18, 2024
8c07f53
Client's event messages to relays do not have subscription ids.
Dec 20, 2024
c2ce7b6
send should return all BaseMessage subclasses, not only OkMessages
Dec 20, 2024
f1a684e
I am limiting tests to only required tags in the response, as other r…
Dec 20, 2024
14347a4
Client's event messages to relays do not have subscription ids.
Dec 20, 2024
e426879
Removed unused imports
Dec 20, 2024
5ffee20
Commented out failing test cases
Dec 20, 2024
1e9fdcf
Merge branch 'java21-merge_sig_et' into java_21-et_merge
avlo Dec 21, 2024
85eb15c
merge erics java21-merge_sig_et PR branch into nicks java21 branch
avlo Dec 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nostr-java-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@
<properties>
<exec.mainClass>nostr.java.api.NostrJavaApi</exec.mainClass>
</properties>
</project>
</project>
26 changes: 18 additions & 8 deletions nostr-java-api/src/main/java/nostr/api/EventNostr.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@
import nostr.base.PublicKey;
import nostr.event.BaseTag;
import nostr.event.impl.GenericEvent;
import nostr.event.json.codec.BaseMessageDecoder;
import nostr.id.Identity;

import java.util.List;
import java.util.Map;

import nostr.event.BaseMessage;

/**
* @author guilhermegps
*/
@Getter
@NoArgsConstructor
public abstract class EventNostr<T extends GenericEvent> extends Nostr {
public abstract class EventNostr<T extends GenericEvent> extends NostrSpringWebSocketClient {

@Setter
private T event;
Expand All @@ -38,22 +42,28 @@ public EventNostr sign() {
return this;
}

public T send() {
public <U extends BaseMessage> U send() {
return this.send(getRelays());
}

public T send(Map<String, String> relays) {
super.send(this.event, relays);
@SuppressWarnings("unchecked")
public <U extends BaseMessage> U send(Map<String, String> relays) {
List<String> messages = super.send(this.event, relays);
BaseMessageDecoder<U> decoder = new BaseMessageDecoder<U>();

return this.event;
return messages.stream()
.map(msg -> (U) decoder.decode(msg))
.filter(msg -> msg != null)
.findFirst()
.orElseThrow(() -> new RuntimeException("No message received"));
}

public T signAndSend() {
public <U extends BaseMessage> U signAndSend() {
return this.signAndSend(getRelays());
}

public T signAndSend(Map<String, String> relays) {
return (T) sign().send(relays);
public <U extends BaseMessage> U signAndSend(Map<String, String> relays) {
return (U) sign().send(relays);
}

public EventNostr setSender(@NonNull Identity sender) {
Expand Down
10 changes: 5 additions & 5 deletions nostr-java-api/src/main/java/nostr/api/NIP12.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import nostr.event.tag.HashtagTag;
import nostr.event.tag.ReferenceTag;

import java.net.URL;
import java.net.URI;

/**
*
Expand All @@ -27,20 +27,20 @@ public class NIP12 {
public static HashtagTag createHashtagTag(@NonNull String hashtag) {
return new HashtagTagFactory(hashtag).create();
}

/**
* Create an URL tag
* @param url the reference
*/
public static ReferenceTag createReferenceTag(@NonNull URL url) {
public static ReferenceTag createReferenceTag(@NonNull URI url) {
return new ReferenceTagFactory(url).create();
}

/**
* Create a Geo tag
* @param location the geohash
*/
public static GeohashTag createGeohashTag(@NonNull String location) {
return new GeohashTagFactory(location).create();
}
}
}
21 changes: 21 additions & 0 deletions nostr-java-api/src/main/java/nostr/api/NIP52.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package nostr.api;

import lombok.NonNull;
import nostr.api.factory.impl.NIP52Impl.CalendarTimeBasedEventFactory;
import nostr.event.BaseTag;
import nostr.event.NIP52Event;
import nostr.event.impl.CalendarContent;
import nostr.id.Identity;

import java.util.List;

public class NIP52<T extends NIP52Event> extends EventNostr<T> {
public NIP52(@NonNull Identity sender) {
setSender(sender);
}

public NIP52<T> createCalendarTimeBasedEvent(@NonNull List<BaseTag> baseTags, @NonNull String content, @NonNull CalendarContent calendarContent) {
setEvent((T) new CalendarTimeBasedEventFactory(getSender(), baseTags, content, calendarContent).create());
return this;
}
}
51 changes: 32 additions & 19 deletions nostr-java-api/src/main/java/nostr/api/Nostr.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* @author eric
*/
@NoArgsConstructor
public class Nostr {
public class Nostr implements NostrIF {

private static Nostr INSTANCE;

Expand All @@ -56,30 +56,33 @@ public class Nostr {
@Getter
private Map<String, String> relays;

public static Nostr getInstance() {
public static NostrIF getInstance() {
return (INSTANCE == null) ? new Nostr() : INSTANCE;
}

public static Nostr getInstance(@NonNull Identity sender) {
public static NostrIF getInstance(@NonNull Identity sender) {
return (INSTANCE == null) ? new Nostr(sender) : INSTANCE;
}

public Nostr(@NonNull Identity sender) {
this.sender = sender;
}

public Nostr setSender(@NonNull Identity sender) {
@Override
public NostrIF setSender(@NonNull Identity sender) {
this.sender = sender;

return this;
}

public Nostr setRelays(@NonNull Map<String, String> relays) {
@Override
public NostrIF setRelays(@NonNull Map<String, String> relays) {
this.relays = relays;

return this;
}

@Override
public void close() {
if (client == null) {
throw new IllegalStateException("Client is not initialized");
Expand All @@ -91,63 +94,73 @@ public void close() {
}
}

public void send(@NonNull IEvent event) {
send(event, getRelays());
@Override
public List<String> send(@NonNull IEvent event) {
return send(event, getRelays());
}

public void send(@NonNull IEvent event, Map<String, String> relays) {
@Override
public List<String> send(@NonNull IEvent event, Map<String, String> relays) {
var context = new DefaultRequestContext();
context.setPrivateKey(getSender().getPrivateKey().getRawData());
context.setRelays(relays);

send(new EventMessage(event), context);
return send(new EventMessage(event), context);
}


public void send(@NonNull Filters filters, @NonNull String subscriptionId) {
send(filters, subscriptionId, getRelays());
@Override
public List<String> send(@NonNull Filters filters, @NonNull String subscriptionId) {
return send(filters, subscriptionId, getRelays());
}

public void send(@NonNull Filters filters, @NonNull String subscriptionId, Map<String, String> relays) {
@Override
public List<String> send(@NonNull Filters filters, @NonNull String subscriptionId, Map<String, String> relays) {
List<Filters> filtersList = new ArrayList<>();
filtersList.add(filters);

send(filtersList, subscriptionId, relays);
return send(filtersList, subscriptionId, relays);
}

public void send(@NonNull List<Filters> filtersList, @NonNull String subscriptionId) {
send(filtersList, subscriptionId, getRelays());
@Override
public List<String> send(@NonNull List<Filters> filtersList, @NonNull String subscriptionId) {
return send(filtersList, subscriptionId, getRelays());
}

public void send(@NonNull List<Filters> filtersList, @NonNull String subscriptionId, Map<String, String> relays) {
@Override
public List<String> send(@NonNull List<Filters> filtersList, @NonNull String subscriptionId, Map<String, String> relays) {

var context = new DefaultRequestContext();
context.setRelays(relays);
context.setPrivateKey(getSender().getPrivateKey().getRawData());
var message = new ReqMessage(subscriptionId, filtersList);

send(message, context);
return send(message, context);
}

public void send(@NonNull BaseMessage message, @NonNull RequestContext context) {
@Override
public List<String> send(@NonNull BaseMessage message, @NonNull RequestContext context) {
if (context instanceof DefaultRequestContext) {
try {
Client.getInstance().connect(context).send(message);
} catch (TimeoutException e) {
throw new RuntimeException(e);
}
}
return List.of();
}

/**
* @param signable
*/
public Nostr sign(@NonNull Identity identity, @NonNull ISignable signable) {
@Override
public NostrIF sign(@NonNull Identity identity, @NonNull ISignable signable) {
identity.sign(signable);

return this;
}

@Override
public boolean verify(@NonNull GenericEvent event) {
if (!event.isSigned()) {
throw new IllegalStateException("The event is not signed");
Expand Down
31 changes: 31 additions & 0 deletions nostr-java-api/src/main/java/nostr/api/NostrIF.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package nostr.api;

import lombok.NonNull;
import nostr.base.IEvent;
import nostr.base.ISignable;
import nostr.context.RequestContext;
import nostr.event.BaseMessage;
import nostr.event.impl.Filters;
import nostr.event.impl.GenericEvent;
import nostr.id.Identity;

import java.io.IOException;
import java.util.List;
import java.util.Map;

public interface NostrIF {
NostrIF setSender(@NonNull Identity sender);
NostrIF setRelays(@NonNull Map<String, String> relays);
List<String> send(@NonNull IEvent event);
List<String> send(@NonNull IEvent event, Map<String, String> relays);
List<String> send(@NonNull Filters filters, @NonNull String subscriptionId);
List<String> send(@NonNull Filters filters, @NonNull String subscriptionId, Map<String, String> relays);
List<String> send(@NonNull List<Filters> filtersList, @NonNull String subscriptionId);
List<String> send(@NonNull List<Filters> filtersList, @NonNull String subscriptionId, Map<String, String> relays);
List<String> send(@NonNull BaseMessage message, @NonNull RequestContext context);
NostrIF sign(@NonNull Identity identity, @NonNull ISignable signable);
boolean verify(@NonNull GenericEvent event);
Identity getSender();
Map<String, String> getRelays();
void close() throws IOException;
}
Loading