Skip to content

Commit c8a9e9f

Browse files
authored
Merge branch 'develop' into dependabot/maven/org.apache.maven.plugins-maven-source-plugin-3.3.1
2 parents 89f02f9 + 5ac6705 commit c8a9e9f

19 files changed

Lines changed: 273 additions & 78 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Publish to GitHub Packages
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- '**/pom.xml'
8+
- '.github/workflows/publish-github-packages.yml'
9+
workflow_dispatch:
10+
11+
jobs:
12+
publish:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
- name: Set up JDK 21
21+
uses: actions/setup-java@v4
22+
with:
23+
distribution: 'temurin'
24+
java-version: '21'
25+
cache: 'maven'
26+
server-id: github
27+
server-username: ${{ github.actor }}
28+
server-password: ${{ secrets.GITHUB_TOKEN }}
29+
- name: Publish modules
30+
run: ./mvnw -B -q deploy -DskipTests -Dgpg.skip=true \
31+
-DaltDeploymentRepository=github::default::https://maven.pkg.github.com/${{ github.repository }}

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ The URL format for the NIPs is https://github.com/nostr-protocol/nips/blob/maste
1919
- Maintain the versions in the configuration section of the pom.xml files.
2020
- Always make sure that the events are compliant with the Nostr protocol specifications, and that the events are valid according to the NIP specifications.
2121
- Always remove unused imports
22+
- When creating a branch, bump up the version in the pom files to the next minor version.
2223

2324
## Pull Requests
2425

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Artifacts are published to GitHub Packages and can be consumed from Maven by add
2828
<repositories>
2929
<repository>
3030
<id>github</id>
31-
<url>https://maven.pkg.github.com/OWNER/REPO</url>
31+
<url>https://maven.pkg.github.com/tcheeric/nostr-java</url>
3232
</repository>
3333
</repositories>
3434

@@ -43,12 +43,13 @@ Artifacts are published to GitHub Packages and can be consumed from Maven by add
4343

4444
Authenticating to GitHub Packages is required; provide a personal access token with the appropriate scopes or `GITHUB_TOKEN` credentials. See the [GitHub Packages documentation](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry) for more details.
4545

46+
## Publishing Modules
47+
48+
This repository includes a [GitHub Actions workflow](.github/workflows/publish-github-packages.yml) that publishes all Maven modules to GitHub Packages. The workflow runs on pushes to `main` that modify `pom.xml` files and can also be triggered manually from the Actions tab.
49+
4650
## Examples
4751
Example usages are located in the [`nostr-java-examples`](./nostr-java-examples) module. Additional demonstrations can be found in [nostr-client](https://github.com/tcheeric/nostr-client) and [SuperConductor](https://github.com/avlo/superconductor).
4852

49-
## Retry Support
50-
`SpringWebSocketClient` leverages Spring Retry so that failed WebSocket send operations are attempted up to three times with exponential backoff.
51-
5253
## Supported NIPs
5354
The API currently implements the following [NIPs](https://github.com/nostr-protocol/nips):
5455
- [NIP-1](https://github.com/nostr-protocol/nips/blob/master/01.md)

docs/CODEBASE_OVERVIEW.md

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,72 @@ If a relay response is not received before the timeout elapses, the client logs
3939
## Retry behavior
4040
`SpringWebSocketClient` leverages Spring Retry so that failed send operations are retried up to three times with an exponential backoff starting at 500 ms.
4141

42-
## Creating and sending events
43-
The examples module shows how to create built-in and custom events. Below is an excerpt from the examples illustrating the creation of a `TextNoteEvent`:
42+
## Creating custom events
43+
The `ExpirationEventExample` demonstrates how to build a NIP-40 expiration event with `GenericEvent` and send it using both the `StandardWebSocketClient` and the `SpringWebSocketClient`:
44+
4445
```java
45-
private static final Identity RECIPIENT = Identity.generateRandomIdentity();
46-
private static final Identity SENDER = Identity.generateRandomIdentity();
46+
BaseTag expirationTag = new GenericTag("expiration",
47+
new ElementAttribute("param0", String.valueOf(expiration)));
48+
GenericEvent event = new GenericEvent(identity.getPublicKey(), Kind.TEXT_NOTE,
49+
List.of(expirationTag),
50+
"This message will expire at the specified timestamp and be deleted by relays.\n");
51+
identity.sign(event);
52+
```
4753

48-
private static GenericEvent sendTextNoteEvent() {
49-
50-
List<BaseTag> tags = new ArrayList<>(List.of(new PubKeyTag(RECIPIENT.getPublicKey())));
54+
## Creating text note events with TextNoteEvent
55+
The `TextNoteEventExample` illustrates constructing a text note directly with the
56+
out-of-the-box `TextNoteEvent` class and sending it to a relay using the
57+
`StandardWebSocketClient`:
5158

52-
var nip01 = new NIP01(SENDER);
53-
nip01.createTextNoteEvent(tags, "Hello world, I'm here on nostr-java API!")
54-
.sign()
55-
.send(RELAYS);
59+
```java
60+
Identity identity = Identity.generateRandomIdentity();
61+
TextNoteEvent event = new TextNoteEvent(identity.getPublicKey(),
62+
List.<BaseTag>of(),
63+
"Hello from TextNoteEvent!\n");
64+
identity.sign(event);
65+
try (StandardWebSocketClient client = new StandardWebSocketClient("ws://localhost:5555")) {
66+
client.send(new EventMessage(event));
67+
}
68+
```
5669

57-
return nip01.getEvent();
70+
## Sending text events with NostrSpringWebSocketClient
71+
The `SpringClientTextEventExample` demonstrates using the `NIP01` helper class to
72+
publish a simple text note via `NostrSpringWebSocketClient`:
73+
74+
```java
75+
Identity sender = Identity.generateRandomIdentity();
76+
NIP01 client = new NIP01(sender);
77+
client.setRelays(Map.of("local", "ws://localhost:5555"));
78+
client.createTextNoteEvent("Hello from NostrSpringWebSocketClient!\n")
79+
.signAndSend();
80+
```
81+
82+
## Requesting events with filters
83+
The `FilterExample` shows how to query a relay for events matching a set of filters.
84+
It builds filters for author and kind, sends them with `NIP01`, and prints each
85+
returned event:
86+
87+
```java
88+
Identity sender = Identity.generateRandomIdentity();
89+
NIP01 client = new NIP01(sender);
90+
client.setRelays(Map.of("damus", "wss://relay.damus.io"));
91+
92+
Filters filters = new Filters(
93+
new AuthorFilter<>(new PublicKey("21ef0d8541375ae4bca85285097fba370f7e540b5a30e5e75670c16679f9d144")),
94+
new KindFilter<>(Kind.TEXT_NOTE)
95+
);
96+
97+
List<String> responses = client.sendRequest(filters, "filter-example-" + System.currentTimeMillis());
98+
var decoder = new BaseMessageDecoder<BaseMessage>();
99+
for (String json : responses) {
100+
BaseMessage message = decoder.decode(json);
101+
if (message instanceof EventMessage eventMessage) {
102+
System.out.println(eventMessage.getEvent());
58103
}
104+
}
105+
client.close();
59106
```
107+
60108
## Creating custom events and tags
61109
Custom tag types can be introduced without modifying existing core code by
62110
registering them with the `TagRegistry`. The registry maps tag codes to factory

nostr-java-api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>xyz.tcheeric</groupId>
66
<artifactId>nostr-java</artifactId>
7-
<version>0.7.3</version>
7+
<version>0.8-SNAPHOT</version>
88
<relativePath>../pom.xml</relativePath>
99
</parent>
1010

nostr-java-base/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>xyz.tcheeric</groupId>
66
<artifactId>nostr-java</artifactId>
7-
<version>0.7.3</version>
7+
<version>0.8-SNAPHOT</version>
88
<relativePath>../pom.xml</relativePath>
99
</parent>
1010

nostr-java-client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>xyz.tcheeric</groupId>
66
<artifactId>nostr-java</artifactId>
7-
<version>0.7.3</version>
7+
<version>0.8-SNAPHOT</version>
88
<relativePath>../pom.xml</relativePath>
99
</parent>
1010

nostr-java-crypto/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>xyz.tcheeric</groupId>
66
<artifactId>nostr-java</artifactId>
7-
<version>0.7.3</version>
7+
<version>0.8-SNAPHOT</version>
88
<relativePath>../pom.xml</relativePath>
99
</parent>
1010

nostr-java-encryption/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>xyz.tcheeric</groupId>
66
<artifactId>nostr-java</artifactId>
7-
<version>0.7.3</version>
7+
<version>0.8-SNAPHOT</version>
88
<relativePath>../pom.xml</relativePath>
99
</parent>
1010

nostr-java-event/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>xyz.tcheeric</groupId>
66
<artifactId>nostr-java</artifactId>
7-
<version>0.7.3</version>
7+
<version>0.8-SNAPHOT</version>
88
<relativePath>../pom.xml</relativePath>
99
</parent>
1010

0 commit comments

Comments
 (0)