Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
907e832
chore(deps): bump org.sonatype.central:central-publishing-maven-plugin
dependabot[bot] Aug 18, 2025
b073d36
chore(deps): bump org.apache.maven.plugins:maven-compiler-plugin
dependabot[bot] Aug 18, 2025
d71f027
chore(deps-dev): bump com.google.guava:guava
dependabot[bot] Aug 18, 2025
c7a79d2
chore(deps): bump org.projectlombok:lombok from 1.18.36 to 1.18.38
dependabot[bot] Aug 18, 2025
2e3a24e
chore(deps): bump org.bouncycastle:bcprov-jdk18on from 1.78 to 1.81
dependabot[bot] Aug 18, 2025
b3b9a5a
chore(deps): bump org.apache.maven.plugins:maven-javadoc-plugin
dependabot[bot] Aug 18, 2025
8dee1a6
chore(deps): bump org.apache.maven.plugins:maven-gpg-plugin
dependabot[bot] Aug 18, 2025
957b407
chore(deps): bump org.apache.commons:commons-lang3 from 3.17.0 to 3.18.0
dependabot[bot] Aug 18, 2025
18f065e
chore(deps): bump org.junit.jupiter:junit-jupiter from 5.10.2 to 5.13.4
dependabot[bot] Aug 18, 2025
c0baaf7
docs: streamline README and move setup instructions
tcheeric Aug 19, 2025
a7ad2b9
Add Nostr Java API reference documentation
tcheeric Aug 19, 2025
e90f565
docs: document extending events
tcheeric Aug 19, 2025
043c8f8
docs: add custom events howto
tcheeric Aug 19, 2025
20770e4
docs: add quick API guide
tcheeric Aug 19, 2025
a93ae7b
docs: restore badges
tcheeric Aug 19, 2025
fb65751
Merge pull request #383 from tcheeric/codex/remove-badges-and-marketi…
tcheeric Aug 19, 2025
359cfc3
Merge pull request #387 from tcheeric/codex/create-nostr-java-api-usa…
tcheeric Aug 19, 2025
692a1ed
Merge pull request #386 from tcheeric/codex/add-custom-events-documen…
tcheeric Aug 19, 2025
c80737b
Merge pull request #385 from tcheeric/codex/create-documentation-for-…
tcheeric Aug 19, 2025
ffe7565
Merge pull request #384 from tcheeric/codex/create-nostr-java-api-doc…
tcheeric Aug 19, 2025
4381b09
Assign Copilot reviewer for develop PRs
tcheeric Aug 19, 2025
edce372
fix: allow PR quality gate to label issues
tcheeric Aug 19, 2025
510c233
Handle permission errors in quality gate workflow
tcheeric Aug 19, 2025
ab49f9f
fix: set PR gate label permissions
tcheeric Aug 19, 2025
dde9618
Merge pull request #388 from tcheeric/codex/create-pr-for-chat-request
tcheeric Aug 19, 2025
0b8b852
Merge pull request #382 from tcheeric/dependabot/maven/org.junit.jupi…
tcheeric Aug 19, 2025
c7697e6
Merge pull request #381 from tcheeric/dependabot/maven/org.apache.com…
tcheeric Aug 19, 2025
976d9ad
Merge pull request #380 from tcheeric/dependabot/maven/org.apache.mav…
tcheeric Aug 19, 2025
2275ba8
Merge branch 'develop' into dependabot/maven/org.apache.maven.plugins…
tcheeric Aug 19, 2025
3a96e29
Merge pull request #379 from tcheeric/dependabot/maven/org.apache.mav…
tcheeric Aug 19, 2025
4b0c563
Merge branch 'develop' into dependabot/maven/org.bouncycastle-bcprov-…
tcheeric Aug 19, 2025
dd8aa1c
Merge pull request #378 from tcheeric/dependabot/maven/org.bouncycast…
tcheeric Aug 19, 2025
b2e45e8
Merge pull request #377 from tcheeric/dependabot/maven/org.projectlom…
tcheeric Aug 19, 2025
d5ba0cb
Merge branch 'develop' into dependabot/maven/com.google.guava-guava-3…
tcheeric Aug 19, 2025
127daac
Merge pull request #376 from tcheeric/dependabot/maven/com.google.gua…
tcheeric Aug 19, 2025
e402293
Merge pull request #375 from tcheeric/dependabot/maven/org.apache.mav…
tcheeric Aug 19, 2025
4b8274f
Merge pull request #374 from tcheeric/dependabot/maven/org.sonatype.c…
tcheeric Aug 19, 2025
9e6a610
chore: shorten PR quality gate and skip dependabot
tcheeric Aug 19, 2025
296545b
Merge pull request #389 from tcheeric/codex/update-pr-quality-gate.ym…
tcheeric Aug 19, 2025
f45e2fd
docs: document PR quality gate rules
tcheeric Aug 19, 2025
36b9c16
chore: run dependabot against develop
tcheeric Aug 19, 2025
f5e009f
Merge pull request #391 from tcheeric/codex/update-dependabot.yml-for…
tcheeric Aug 19, 2025
eeebe39
docs: document naming format requirements
tcheeric Aug 19, 2025
2490c32
docs: emphasize human expertise for AI
tcheeric Aug 19, 2025
7d35891
Merge pull request #390 from tcheeric/codex/update-agents.md-with-pr-…
tcheeric Aug 19, 2025
9fabfe6
Run Copilot reviewer workflow for develop
tcheeric Aug 19, 2025
c439219
Merge pull request #392 from tcheeric/codex/fix-assign-copilot-review…
tcheeric Aug 19, 2025
2083bd9
docs: mention PR template in guidelines
tcheeric Aug 19, 2025
90d6f98
Merge branch 'develop' into codex/update-agents.md-with-pr-quality-ga…
tcheeric Aug 19, 2025
ac6336c
Merge pull request #393 from tcheeric/codex/update-agents.md-with-pr-…
tcheeric Aug 19, 2025
cc254c9
docs: list NIP URLs for Copilot
tcheeric Aug 19, 2025
01645d0
Update CONTRIBUTING.md
tcheeric Aug 19, 2025
38dbf30
Merge branch 'develop' into codex/update-agents.md-with-pr-quality-ga…
tcheeric Aug 19, 2025
1f2f3f0
Merge pull request #394 from tcheeric/codex/update-agents.md-with-pr-…
tcheeric Aug 19, 2025
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
Prev Previous commit
Next Next commit
Add Nostr Java API reference documentation
  • Loading branch information
tcheeric committed Aug 19, 2025
commit a7ad2b9d694c38f3c6ed54edea769a4b2029fcdf
184 changes: 184 additions & 0 deletions docs/reference/nostr-java-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# Nostr Java API Reference

This document provides an overview of the public API exposed by the `nostr-java` modules. It lists the major classes, configuration objects and their key method signatures, and shows brief examples of how to use them. Where applicable, links to related [Nostr Improvement Proposals (NIPs)](https://github.com/nostr-protocol/nips) are provided.

## Identity (`nostr-java-id`)

### `Identity`
Represents a Nostr identity backed by a private key. It can derive a public key and sign `ISignable` objects.

```java
public static Identity create(PrivateKey privateKey)
public static Identity create(String privateKey)
public static Identity generateRandomIdentity()
public PublicKey getPublicKey()
public Signature sign(ISignable signable)
```

**Usage:**
```java
Identity id = Identity.generateRandomIdentity();
PublicKey pub = id.getPublicKey();
Signature sig = id.sign(event);
```

## Event Model (`nostr-java-event`)

### Core Types
- `BaseMessage` – base class for all relay messages.
- `BaseEvent` – root class for Nostr events.
- `BaseTag` – helper for tag encoding and decoding.

### Predefined Events
The `nostr.event` package provides event implementations for many NIPs:

| Class | NIP |
|-------|-----|
| `NIP01Event` | [NIP-01](https://github.com/nostr-protocol/nips/blob/master/01.md) – standard text notes. |
| `NIP04Event` | [NIP-04](https://github.com/nostr-protocol/nips/blob/master/04.md) – encrypted direct messages. |
| `NIP05Event` | [NIP-05](https://github.com/nostr-protocol/nips/blob/master/05.md) – DNS identifiers. |
| `NIP09Event` | [NIP-09](https://github.com/nostr-protocol/nips/blob/master/09.md) – event deletion. |
| `NIP25Event` | [NIP-25](https://github.com/nostr-protocol/nips/blob/master/25.md) – reactions. |
| `NIP52Event` | [NIP-52](https://github.com/nostr-protocol/nips/blob/master/52.md) – calendar events. |
| `NIP99Event` | [NIP-99](https://github.com/nostr-protocol/nips/blob/master/99.md) – classified listings. |

### Filters
`Filters` and related `Filterable` implementations help build subscription requests.

```java
new Filters(Filterable... filterables)
List<Filterable> getFilterByType(String type)
void setLimit(Integer limit)
```

**Usage:**
```java
Filters filters = new Filters(new AuthorFilter(pubKey));
filters.setLimit(100);
```

## WebSocket Clients (`nostr-java-client`, `nostr-java-api`)

### `WebSocketClientIF`
Abstraction over a WebSocket connection to a relay.

```java
<T extends BaseMessage> List<String> send(T eventMessage) throws IOException
List<String> send(String json) throws IOException
void close() throws IOException
```

### `StandardWebSocketClient`
Spring `TextWebSocketHandler` based implementation of `WebSocketClientIF`.

```java
public StandardWebSocketClient(String relayUri)
public <T extends BaseMessage> List<String> send(T eventMessage) throws IOException
public List<String> send(String json) throws IOException
public void close() throws IOException
```

### `SpringWebSocketClient`
Wrapper that adds retry logic around a `WebSocketClientIF`.

```java
public List<String> send(BaseMessage eventMessage) throws IOException
public List<String> send(String json) throws IOException
public List<String> recover(IOException ex, String json) throws IOException
public void close() throws IOException
```

### `NostrSpringWebSocketClient`
High level client coordinating multiple relay connections and signing.

```java
public NostrIF setRelays(Map<String,String> relays)
public List<String> sendEvent(IEvent event)
public List<String> sendRequest(List<Filters> filters, String subscriptionId)
public NostrIF sign(Identity identity, ISignable signable)
public boolean verify(GenericEvent event)
public Map<String,String> getRelays()
public void close()
```

### Configuration
- `RetryConfig` – enables Spring Retry support.
- `RelaysProperties` – maps relay names to URLs via configuration properties.
- `RelayConfig` – loads `relays.properties` and exposes a `Map<String,String>` bean.

## Encryption and Cryptography

### `MessageCipher`
Strategy interface for message encryption.

```java
String encrypt(String message)
String decrypt(String message)
```

Implementations:
- `MessageCipher04` – NIP-04 direct message encryption.
- `MessageCipher44` – NIP-44 payload encryption.

### `Schnorr`
Utility for Schnorr signatures (BIP-340).

```java
static byte[] sign(byte[] msg, byte[] secKey, byte[] auxRand)
static boolean verify(byte[] msg, byte[] pubKey, byte[] sig)
static byte[] generatePrivateKey()
static byte[] genPubKey(byte[] secKey)
```

### `Bech32`
Utility for Bech32/Bech32m encoding used by [NIP-19](https://github.com/nostr-protocol/nips/blob/master/19.md).

```java
static String toBech32(Bech32Prefix hrp, byte[] hexKey)
static String fromBech32(String str)
```

## Utilities (`nostr-java-util`)

### `NostrUtil`
General helper functions.

```java
static String bytesToHex(byte[] bytes)
static byte[] hexToBytes(String hex)
static byte[] sha256(byte[] data)
static byte[] createRandomByteArray(int len)
```

### `NostrException`
Base checked exception for utility methods.

## Examples

### Send a Text Note (NIP-01)
```java
Identity id = Identity.generateRandomIdentity();
NIP01 nip01 = new NIP01(id).createTextNoteEvent("Hello Nostr");
NostrIF client = NostrSpringWebSocketClient.getInstance(id)
.setRelays(Map.of("relay","wss://relay.example"));
client.sendEvent(nip01.getEvent());
```

### Encrypted Direct Message (NIP-04)
```java
Identity alice = Identity.generateRandomIdentity();
Identity bob = Identity.generateRandomIdentity();
NIP04 dm = new NIP04(alice, bob.getPublicKey())
.createDirectMessageEvent("secret");
String plaintext = NIP04.decrypt(bob, dm.getEvent());
```

### Subscription with Filters
```java
Filters filters = new Filters(new AuthorFilter(pubKey));
NostrIF client = NostrSpringWebSocketClient.getInstance(id);
List<String> events = client.sendRequest(filters, "sub-id");
```

---
This reference is a starting point; consult the source for complete details and additional NIP helpers.