Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 14 additions & 2 deletions nostr-java-api/src/main/java/nostr/api/EventNostr.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package nostr.api;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import nostr.api.factory.impl.GenericEventFactory;
Expand All @@ -18,6 +19,7 @@
/**
* @author guilhermegps
*/
@NoArgsConstructor
public abstract class EventNostr<T extends GenericEvent> extends Nostr {

@Getter
Expand All @@ -27,6 +29,10 @@ public abstract class EventNostr<T extends GenericEvent> extends Nostr {
@Getter
private PublicKey recipient;

public EventNostr(@NonNull Identity sender) {
super(sender);
}

public EventNostr sign() {
super.sign(getSender(), event);

Expand Down Expand Up @@ -72,12 +78,18 @@ public EventNostr addTag(@NonNull BaseTag tag) {
return this;
}

public static class Event<T extends GenericEvent> extends EventNostr<T> {
@NoArgsConstructor
public static class GenericEventNostr<T extends GenericEvent> extends EventNostr<T> {

public GenericEventNostr(@NonNull Identity sender) {
super.setSender(sender);
}

/**
* @param content
* @return
*/
public Event createGenericEvent(@NonNull Integer kind, @NonNull String content) {
public GenericEventNostr createGenericEvent(@NonNull Integer kind, @NonNull String content) {
var factory = new GenericEventFactory(getSender(), kind, content);
var event = factory.create();
setEvent((T) event);
Expand Down
4 changes: 2 additions & 2 deletions nostr-java-api/src/main/java/nostr/api/NIP01.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
*/
package nostr.api;

import java.util.List;

import lombok.NonNull;
import nostr.api.factory.impl.NIP01Impl.AddressTagFactory;
import nostr.api.factory.impl.NIP01Impl.CloseMessageFactory;
Expand Down Expand Up @@ -44,6 +42,8 @@
import nostr.event.tag.PubKeyTag;
import nostr.id.IIdentity;

import java.util.List;

/**
*
* @author eric
Expand Down
5 changes: 0 additions & 5 deletions nostr-java-api/src/main/java/nostr/api/NIP03.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@
*/
package nostr.api;

import java.util.List;
import lombok.NonNull;
import nostr.api.factory.impl.NIP02Impl;
import nostr.api.factory.impl.NIP03Impl;
import nostr.api.factory.impl.NIP03Impl.OtsEventFactory;
import nostr.base.IEvent;
import nostr.event.BaseTag;
import nostr.event.impl.GenericEvent;
import nostr.event.impl.OtsEvent;
import nostr.id.IIdentity;

/**
Expand Down
10 changes: 6 additions & 4 deletions nostr-java-api/src/main/java/nostr/api/NIP04.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public NIP04(@NonNull IIdentity sender, @NonNull PublicKey recipient) {
* @param content the DM content in clear-text
*/
public NIP04<T> createDirectMessageEvent(@NonNull String content) {
var event = new DirectMessageEventFactory(getSender(), getRecipient(), content).create();
var encryptedContent = encrypt(getSender(), content, getRecipient());
var event = new DirectMessageEventFactory(getSender(), getRecipient(), encryptedContent).create();
this.setEvent((T) event);

return this;
Expand All @@ -56,7 +57,8 @@ public NIP04<T> createDirectMessageEvent(@NonNull String content) {
* @return the DM event
*/
public NIP04<T> createDirectMessageEvent(@NonNull List<BaseTag> tags, @NonNull PublicKey recipient, @NonNull String content) {
var event = new DirectMessageEventFactory(tags, recipient, content).create();
var encryptedContent = encrypt(getSender(), content, recipient);
var event = new DirectMessageEventFactory(tags, recipient, encryptedContent).create();
this.setEvent((T) event);

return this;
Expand All @@ -66,7 +68,7 @@ public NIP04<T> createDirectMessageEvent(@NonNull List<BaseTag> tags, @NonNull P
* Encrypt the direct message
* @return the current instance with an encrypted message
*/
public NIP04<T> encrypt() {
private NIP04<T> encrypt() {
encryptDirectMessage(getSender(), (DirectMessageEvent) getEvent());
return this;
}
Expand Down Expand Up @@ -135,7 +137,7 @@ public static String decrypt(@NonNull IIdentity rcptId, @NonNull GenericEvent ev

// I am the message recipient
var sender = event.getPubKey();
log.log(Level.INFO, "The message is being decrypted for {0}", sender);
log.log(Level.FINE, "The message is being decrypted for {0}", sender);
MessageCipher cipher = new MessageCipher04(rcptId.getPrivateKey().getRawData(), sender.getRawData());
return cipher.decrypt(event.getContent());
}
Expand Down
4 changes: 2 additions & 2 deletions nostr-java-api/src/main/java/nostr/api/NIP08.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
*/
package nostr.api;

import java.util.List;

import lombok.NonNull;
import nostr.api.factory.impl.NIP08Impl.MentionsEventFactory;
import nostr.event.BaseTag;
import nostr.event.NIP08Event;
import nostr.event.impl.MentionsEvent;
import nostr.id.IIdentity;

import java.util.List;

/**
*
* @author eric
Expand Down
4 changes: 2 additions & 2 deletions nostr-java-api/src/main/java/nostr/api/NIP09.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
*/
package nostr.api;

import java.util.List;

import lombok.NonNull;
import nostr.api.factory.impl.NIP09Impl.DeletionEventFactory;
import nostr.event.BaseTag;
import nostr.event.NIP09Event;
import nostr.event.tag.EventTag;
import nostr.id.IIdentity;

import java.util.List;

/**
*
* @author eric
Expand Down
3 changes: 2 additions & 1 deletion nostr-java-api/src/main/java/nostr/api/NIP12.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
package nostr.api;

import java.net.URL;
import lombok.NonNull;
import nostr.api.factory.impl.NIP12Impl.GeohashTagFactory;
import nostr.api.factory.impl.NIP12Impl.HashtagTagFactory;
Expand All @@ -13,6 +12,8 @@
import nostr.event.tag.HashtagTag;
import nostr.event.tag.ReferenceTag;

import java.net.URL;

/**
*
* @author eric
Expand Down
2 changes: 1 addition & 1 deletion nostr-java-api/src/main/java/nostr/api/NIP15.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import lombok.NonNull;
import nostr.api.factory.impl.NIP15Impl;
import nostr.event.impl.*;
import nostr.event.impl.CreateOrUpdateStallEvent.Stall;
import nostr.event.impl.CustomerOrderEvent.Customer;
import nostr.event.impl.GenericEvent;
import nostr.event.impl.MerchantRequestPaymentEvent.Payment;
import nostr.event.impl.NostrMarketplaceEvent.Product;
import nostr.event.impl.VerifyPaymentOrShippedEvent.PaymentShipmentStatus;
Expand Down
7 changes: 4 additions & 3 deletions nostr-java-api/src/main/java/nostr/api/NIP23.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@

import lombok.NonNull;
import nostr.api.factory.impl.NIP23Impl;
import nostr.api.factory.impl.NIP23Impl.*;
import nostr.event.BaseTag;
import nostr.api.factory.impl.NIP23Impl.ImageTagFactory;
import nostr.api.factory.impl.NIP23Impl.PublishedAtTagFactory;
import nostr.api.factory.impl.NIP23Impl.SummaryTagFactory;
import nostr.api.factory.impl.NIP23Impl.TitleTagFactory;
import nostr.event.impl.GenericEvent;
import nostr.event.impl.GenericTag;
import nostr.event.tag.AddressTag;
import nostr.event.tag.EventTag;
import nostr.id.IIdentity;

import java.net.URL;
import java.util.List;

/**
* @author eric
Expand Down
6 changes: 3 additions & 3 deletions nostr-java-api/src/main/java/nostr/api/NIP25.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
*/
package nostr.api;

import java.util.ArrayList;
import java.util.List;

import lombok.NonNull;
import nostr.api.factory.impl.NIP25Impl.ReactionEventFactory;
import nostr.event.BaseTag;
Expand All @@ -16,6 +13,9 @@
import nostr.event.tag.EmojiTag;
import nostr.id.IIdentity;

import java.util.ArrayList;
import java.util.List;

public class NIP25<T extends NIP25Event> extends EventNostr<T> {

public NIP25(@NonNull IIdentity sender) {
Expand Down
3 changes: 2 additions & 1 deletion nostr-java-api/src/main/java/nostr/api/NIP32.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
*/
package nostr.api;

import java.util.Map;
import lombok.NonNull;
import nostr.api.factory.impl.NIP32Impl.Label;
import nostr.api.factory.impl.NIP32Impl.LabelTagFactory;
import nostr.api.factory.impl.NIP32Impl.NameSpace;
import nostr.api.factory.impl.NIP32Impl.NamespaceTagFactory;
import nostr.event.impl.GenericTag;

import java.util.Map;

/**
*
* @author eric
Expand Down
2 changes: 1 addition & 1 deletion nostr-java-api/src/main/java/nostr/api/NIP44.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static String decrypt(@NonNull IIdentity rcptId, @NonNull GenericEvent ev

// I am the message recipient
var sender = event.getPubKey();
log.log(Level.INFO, "The message is being decrypted for {0}", sender);
log.log(Level.FINE, "The message is being decrypted for {0}", sender);
MessageCipher cipher = new MessageCipher44(rcptId.getPrivateKey().toString(), sender.toString());
return cipher.decrypt(event.getContent());
}
Expand Down
Loading