From e052295734587224c636626371cc9b6b231d2167 Mon Sep 17 00:00:00 2001 From: Guilherme Gps Date: Sun, 17 Mar 2024 14:52:30 -0300 Subject: [PATCH 1/8] Removing non-existent dependency --- nostr-java-crypto/pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/nostr-java-crypto/pom.xml b/nostr-java-crypto/pom.xml index b145860c2..157eac2a5 100644 --- a/nostr-java-crypto/pom.xml +++ b/nostr-java-crypto/pom.xml @@ -36,10 +36,5 @@ nostr-java-util ${project.version} - - ${project.groupId} - nostr-java-secp256k1 - ${project.version} - \ No newline at end of file From bfe2b4046f69f46ac1e6364fe7b2688478955e7a Mon Sep 17 00:00:00 2001 From: erict875 Date: Mon, 18 Mar 2024 18:47:21 +0000 Subject: [PATCH 2/8] https://github.com/tcheeric/nostr-java/issues/98 --- README.md | 40 +++++++++++++++++++++++++++++- nostr-java-api/README.md | 7 ++++++ nostr-java-event/README.md | 24 ------------------ nostr-java-examples/README.md | 46 +++++++++++++++++++++++++++++++++++ nostr-java-id/README.md | 10 ++++++++ nostr-java-test/README.md | 0 6 files changed, 102 insertions(+), 25 deletions(-) create mode 100644 nostr-java-api/README.md delete mode 100644 nostr-java-event/README.md create mode 100644 nostr-java-examples/README.md create mode 100644 nostr-java-id/README.md create mode 100644 nostr-java-test/README.md diff --git a/README.md b/README.md index 677c1b9cb..c66b254a6 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,42 @@ Introducing the nostr-java library, a solution written in java for generating, signing, and publishing nostr events to relays. -For detailed instructions on how to utilise the library, please refer to the [nostr-client](https://github.com/tcheeric/nostr-client/) repository. \ No newline at end of file +## Requirements +- Tested with Java 19. (Java 21 is currently not supported, due to a conflict with lombok. See issue [#101](https://github.com/tcheeric/nostr-java/issues/101) +- A Nostr relay to connect to. This is needed for the [unit tests](https://github.com/tcheeric/nostr-java/tree/main/nostr-java-test). You can either run your own relay, or use a public one. To configure your test relay, update the [relays.properties](https://github.com/tcheeric/nostr-java/blob/main/nostr-java-test/src/test/resources/relays.properties) resource file in the test module. + +## Building +We use Maven to build the project. To build the project, run the following command in the root directory of the project: + +```bash +mvn clean install +``` + +## Supported NIPs +The following NIPs are supported by the API out-of-the-box: +- [NIP-1](https://github.com/nostr-protocol/nips/blob/master/01.md) +- [NIP-2](https://github.com/nostr-protocol/nips/blob/master/02.md) +- [NIP-3](https://github.com/nostr-protocol/nips/blob/master/03.md) +- [NIP-4](https://github.com/nostr-protocol/nips/blob/master/04.md) +- [NIP-5](https://github.com/nostr-protocol/nips/blob/master/05.md) +- [NIP-8](https://github.com/nostr-protocol/nips/blob/master/08.md) +- [NIP-9](https://github.com/nostr-protocol/nips/blob/master/09.md) +- [NIP-12](https://github.com/nostr-protocol/nips/blob/master/12.md) +- [NIP-14](https://github.com/nostr-protocol/nips/blob/master/14.md) +- [NIP-15](https://github.com/nostr-protocol/nips/blob/master/15.md) +- [NIP-20](https://github.com/nostr-protocol/nips/blob/master/20.md) +- [NIP-23](https://github.com/nostr-protocol/nips/blob/master/23.md) +- [NIP-25](https://github.com/nostr-protocol/nips/blob/master/25.md) +- [NIP-28](https://github.com/nostr-protocol/nips/blob/master/28.md) +- [NIP-30](https://github.com/nostr-protocol/nips/blob/master/30.md) +- [NIP-32](https://github.com/nostr-protocol/nips/blob/master/32.md) +- [NIP-40](https://github.com/nostr-protocol/nips/blob/master/40.md) +- [NIP-42](https://github.com/nostr-protocol/nips/blob/master/42.md) +- [NIP-44](https://github.com/nostr-protocol/nips/blob/master/44.md) +- [NIP-46](https://github.com/nostr-protocol/nips/blob/master/46.md) +- [NIP-57](https://github.com/nostr-protocol/nips/blob/master/57.md) + +We also provide the classes [GenericEvent](https://github.com/tcheeric/nostr-java/blob/main/nostr-java-event/src/main/java/nostr/event/impl/GenericEvent.java) and [GenericTag](https://github.com/tcheeric/nostr-java/blob/main/nostr-java-event/src/main/java/nostr/event/impl/GenericTag.java) for creating events and tags that are currently not supported out-of-the-box. +See working example [here](https://github.com/tcheeric/nostr-java/tree/main/nostr-java-examples) + +Read the [nostr-java-api](https://github.com/tcheeric/nostr-java/tree/main/nostr-java-api) documentation \ No newline at end of file diff --git a/nostr-java-api/README.md b/nostr-java-api/README.md new file mode 100644 index 000000000..c1fd552c8 --- /dev/null +++ b/nostr-java-api/README.md @@ -0,0 +1,7 @@ +# nostr-java-api + +This is a Java API for the Nostr protocol. It is a simple wrapper around the Nostr library, which allows you to interact with the Nostr for creating, signing, and publishing events to relays, using Java. + +## Usage + +For detailed instructions on how to utilise the library, please refer to the [nostr-client](https://github.com/tcheeric/nostr-client/) repository. \ No newline at end of file diff --git a/nostr-java-event/README.md b/nostr-java-event/README.md deleted file mode 100644 index 9aa10920e..000000000 --- a/nostr-java-event/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# nostr-event - -We offer support for selected events and tags out of the box: - -The events: -- Event Deletion -- Encrypted Direct Messages -- Ephemeral Events -- Internet Identifier Metadata Events -- Mentions -- Set Metadata events -- Ots Events -- Reaction Events -- Replaceable Events -- Text Note Events - -The Tags: -- Deletion Tag -- Event Tag -- Nonce Tag -- Pubkey Tag -- Subject Tag - -Additionally, you may use the `GenericTag` and `GenericEvent` classes to create your custom tags and events. diff --git a/nostr-java-examples/README.md b/nostr-java-examples/README.md new file mode 100644 index 000000000..a7e5fcd29 --- /dev/null +++ b/nostr-java-examples/README.md @@ -0,0 +1,46 @@ +# nostr-java-examples +This is a collection of examples for the Nostr Java API. It demonstrates how to use the API to create, sign, and publish events to relays. + +## Creating an OOTB Nostr Event +Here is an example illustrating how to create a TextNoteEvent using the Nostr Java API, and submitting it to relays. +1. Create a sender [identity](https://github.com/tcheeric/nostr-java/tree/main/nostr-java-id). In the example below, we generate a random identity, but you may create an identity from a private key, or use the default identity, if setup. +2. You create a list of tags. This is an optional step. In the example below, we create a list of tags with a single PubKeyTag, which is the recipient's public key. +3. You create a NIP01 object, and call the createTextNoteEvent method, passing the list of tags and the message, then sign and send it. + +```java +private static final Identity SENDER = Identity.generateRandomIdentity(); +private final static Map RELAYS = Map.of("lol", "nos.lol", "damus", "relay.damus.io", "ZBD", + "nostr.zebedee.cloud", "taxi", "relay.taxi", "mom", "nostr.mom"); + +private static TextNoteEvent sendTextNoteEvent() { +logHeader("sendTextNoteEvent"); + + List tags = new ArrayList<>(List.of(new PubKeyTag(RECIPIENT.getPublicKey()))); + + var nip01 = new NIP01(SENDER); + nip01.createTextNoteEvent(tags, "Hello world, I'm here on nostr-java API!") + .sign() + .send(RELAYS); + + return nip01.getEvent(); + } + +``` + +## Creating a custom Nostr Event and Tag +We use the ```nostr.api.EventNostr.GenericEventNostr.createGenericEvent(@NonNull Integer kind, @NonNull String content)``` method to create a custom event. The example below creates a custom event with a custom tag, and sends it to relays. +The alt-tag is created using the TagFactory class, which is a helper class for creating custom tags. The TagFactory class has a method for creating each type of tag. In the example below, we create a custom tag with a tag name of "alt", a tag kind of 31, and a tag content of "an alt text". ```["alt", 31, "an alt text"]```. + +```java +private static TextNoteEvent sendTextNoteEvent() { +logHeader("sendTextNoteEvent"); + + var event = new GenericEventNostr(SENDER); + nip01.createTextNoteEvent(1, "Hello world, I'm here on nostr-java API!") + .addTag(new TagFactory("alt", 31, "an alt text").create()) + .sign() + .send(RELAYS); + + return nip01.getEvent(); + } +``` \ No newline at end of file diff --git a/nostr-java-id/README.md b/nostr-java-id/README.md new file mode 100644 index 000000000..8cd65642e --- /dev/null +++ b/nostr-java-id/README.md @@ -0,0 +1,10 @@ +#nostr-java-id +Identities represent nsec, npub pairs. They are used to sign events and to verify the signature of events. The Nostr Java API provides a default identity, which is used if no identity is provided. You may also create an identity from a private key, generate a random identity, or create a custom identity. + +## Creating an Identity from an nsec +```java +Identity.getInstance(PrivateKey nsec); +``` + +## Creating a random identity +You use to create a random identity by calling the ```Identity.generateRandomIdentity()``` method. diff --git a/nostr-java-test/README.md b/nostr-java-test/README.md new file mode 100644 index 000000000..e69de29bb From d42fb30c05f0dc8122ec5a01a0e6d7529e25aadf Mon Sep 17 00:00:00 2001 From: erict875 Date: Mon, 18 Mar 2024 18:53:36 +0000 Subject: [PATCH 3/8] https://github.com/tcheeric/nostr-java/issues/98 --- nostr-java-id/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nostr-java-id/README.md b/nostr-java-id/README.md index 8cd65642e..06dc68955 100644 --- a/nostr-java-id/README.md +++ b/nostr-java-id/README.md @@ -1,4 +1,4 @@ -#nostr-java-id +# nostr-java-id Identities represent nsec, npub pairs. They are used to sign events and to verify the signature of events. The Nostr Java API provides a default identity, which is used if no identity is provided. You may also create an identity from a private key, generate a random identity, or create a custom identity. ## Creating an Identity from an nsec From c01bd8da30acb3db8eefd4af221ec6fc103677d9 Mon Sep 17 00:00:00 2001 From: erict875 Date: Mon, 18 Mar 2024 18:57:23 +0000 Subject: [PATCH 4/8] https://github.com/tcheeric/nostr-java/issues/98 --- nostr-java-id/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nostr-java-id/README.md b/nostr-java-id/README.md index 06dc68955..b1d3ccdb0 100644 --- a/nostr-java-id/README.md +++ b/nostr-java-id/README.md @@ -1,9 +1,9 @@ # nostr-java-id Identities represent nsec, npub pairs. They are used to sign events and to verify the signature of events. The Nostr Java API provides a default identity, which is used if no identity is provided. You may also create an identity from a private key, generate a random identity, or create a custom identity. -## Creating an Identity from an nsec +## Creating an Identity from a private key (in hex format) ```java -Identity.getInstance(PrivateKey nsec); +Identity.getInstance(String privateKey); ``` ## Creating a random identity From 8f0cf6828fef3cd1cbfb1de94100e5e8301f721e Mon Sep 17 00:00:00 2001 From: erict875 Date: Mon, 18 Mar 2024 20:34:11 +0000 Subject: [PATCH 5/8] https://github.com/tcheeric/nostr-java/issues/98 --- nostr-java-examples/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nostr-java-examples/README.md b/nostr-java-examples/README.md index a7e5fcd29..b67b9c042 100644 --- a/nostr-java-examples/README.md +++ b/nostr-java-examples/README.md @@ -28,7 +28,7 @@ logHeader("sendTextNoteEvent"); ``` ## Creating a custom Nostr Event and Tag -We use the ```nostr.api.EventNostr.GenericEventNostr.createGenericEvent(@NonNull Integer kind, @NonNull String content)``` method to create a custom event. The example below creates a custom event with a custom tag, and sends it to relays. +We use the ```nostr.api.EventNostr.GenericEventNostr.createGenericEvent(@NonNull Integer kind, @NonNull String content)``` method to create custom events, i.e. events not supported out-of-the-box by the nostr-java library. The example below re-creates the TextNoteEvent as a custom event, and a custom tag, then sends the event to relays. The alt-tag is created using the TagFactory class, which is a helper class for creating custom tags. The TagFactory class has a method for creating each type of tag. In the example below, we create a custom tag with a tag name of "alt", a tag kind of 31, and a tag content of "an alt text". ```["alt", 31, "an alt text"]```. ```java From adaccd669bc96f20e4bd87ddd05e32e116a4c76f Mon Sep 17 00:00:00 2001 From: erict875 Date: Mon, 18 Mar 2024 20:52:19 +0000 Subject: [PATCH 6/8] https://github.com/tcheeric/nostr-java/issues/98 --- nostr-java-examples/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nostr-java-examples/README.md b/nostr-java-examples/README.md index b67b9c042..20666a64c 100644 --- a/nostr-java-examples/README.md +++ b/nostr-java-examples/README.md @@ -29,7 +29,7 @@ logHeader("sendTextNoteEvent"); ## Creating a custom Nostr Event and Tag We use the ```nostr.api.EventNostr.GenericEventNostr.createGenericEvent(@NonNull Integer kind, @NonNull String content)``` method to create custom events, i.e. events not supported out-of-the-box by the nostr-java library. The example below re-creates the TextNoteEvent as a custom event, and a custom tag, then sends the event to relays. -The alt-tag is created using the TagFactory class, which is a helper class for creating custom tags. The TagFactory class has a method for creating each type of tag. In the example below, we create a custom tag with a tag name of "alt", a tag kind of 31, and a tag content of "an alt text". ```["alt", 31, "an alt text"]```. +The alt-tag is created using the TagFactory class, which is a helper class for creating custom tags. The TagFactory class has a method for creating each type of tag. In the example below, we create a custom tag with a tag name of ```alt```, a tag kind of ```31```, and a tag content of ```an alt text```. ```["alt", 31, "an alt text"]```. ```java private static TextNoteEvent sendTextNoteEvent() { From 71d80a61b66d3f6b136b21d963e7596d108a23a8 Mon Sep 17 00:00:00 2001 From: erict875 Date: Mon, 18 Mar 2024 21:07:40 +0000 Subject: [PATCH 7/8] https://github.com/tcheeric/nostr-java/issues/98 --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c66b254a6..c3a091ffe 100644 --- a/README.md +++ b/README.md @@ -41,4 +41,7 @@ The following NIPs are supported by the API out-of-the-box: We also provide the classes [GenericEvent](https://github.com/tcheeric/nostr-java/blob/main/nostr-java-event/src/main/java/nostr/event/impl/GenericEvent.java) and [GenericTag](https://github.com/tcheeric/nostr-java/blob/main/nostr-java-event/src/main/java/nostr/event/impl/GenericTag.java) for creating events and tags that are currently not supported out-of-the-box. See working example [here](https://github.com/tcheeric/nostr-java/tree/main/nostr-java-examples) -Read the [nostr-java-api](https://github.com/tcheeric/nostr-java/tree/main/nostr-java-api) documentation \ No newline at end of file +Additional reading: +- [nostr-java-api](https://github.com/tcheeric/nostr-java/tree/main/nostr-java-api) +- [nostr-java-id](https://github.com/tcheeric/nostr-java/tree/main/nostr-java-id) +- [nostr-java-examples](https://github.com/tcheeric/nostr-java/tree/main/nostr-java-examples) From 8d50615c9c3ace44430db140845708cf1f762ad6 Mon Sep 17 00:00:00 2001 From: erict875 Date: Mon, 18 Mar 2024 21:30:41 +0000 Subject: [PATCH 8/8] https://github.com/tcheeric/nostr-java/issues/98 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c3a091ffe..6a3eec994 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Introducing the nostr-java library, a solution written in java for generating, signing, and publishing nostr events to relays. ## Requirements -- Tested with Java 19. (Java 21 is currently not supported, due to a conflict with lombok. See issue [#101](https://github.com/tcheeric/nostr-java/issues/101) +- Java 19. (Java 21 is currently not supported, due to a conflict with lombok. See issue [#101](https://github.com/tcheeric/nostr-java/issues/101) - A Nostr relay to connect to. This is needed for the [unit tests](https://github.com/tcheeric/nostr-java/tree/main/nostr-java-test). You can either run your own relay, or use a public one. To configure your test relay, update the [relays.properties](https://github.com/tcheeric/nostr-java/blob/main/nostr-java-test/src/test/resources/relays.properties) resource file in the test module. ## Building