Skip to content

Conversation

Ardakilic
Copy link

Hello,

This PR aims to add support for nostr protocol to crosspost.

I've tried to update the documents and write tests accordingly, and tried to keep everything tidy. I've used the popular nostr-tools package to connect with the nostr relays.

I've successfully implemented and dispatched a message to my relays using my fork's branch that I've created on my personal account:

https://primal.net/e/nevent1qqs9qmmd7wmlvh68dy0zm5e288s7uf2hgsmhfjv5tq6u5gpnh57x95cux09ee

This is the snippet that I've used to dispatch this message:

#!/usr/bin/env node
/**
 * @fileoverview Example usage of the Nostr strategy
 */

import { NostrStrategy } from "./dist/index.js";

const nostr = new NostrStrategy({
	// You can use either nsec format or hex format
	privateKey: process.env.NOSTR_PRIVATE_KEY || "nsec...", // example nsec key
	relays: process.env.NOSTR_RELAYS?.split(",") || [
		"wss://relay.damus.io",
		"wss://nos.lol",
		"wss://relay.nostr.band"
	],
});

async function postToNostr() {
	try {
		console.log("Posting to Nostr...");
		
		const response = await nostr.post("Hello Nostr! This is a test message from the crosspost library. 🚀 #nostr #decentralized");
		
		console.log("Successfully posted to Nostr!");
		console.log("Event ID:", response.event.id);
		console.log("Published to relays:", response.publishedTo);
		console.log("Nostr URI:", nostr.getUrlFromResponse(response));
		
		// Clean up connections
		nostr.close();
	} catch (error) {
		console.error("Failed to post to Nostr:", error.message);
		nostr.close();
		process.exit(1);
	}
}

// Only run if this file is executed directly
if (import.meta.url === `file://${process.argv[1]}`) {
	postToNostr();
}

I'd appreciate if you'd consider this contribution for the repository, since I use X, Bluesky, Mastodon and Nostr all.

PS: Nostr does not allow image uploads by the nature, but you can embed any image from any source as long as you provide a valid image URL, such as an s3 bucket, or imgur etc. so I've added a note there.

If you need me to do anything, please let me know.

Thanks, and kind regards!

@nzakas
Copy link
Contributor

nzakas commented Aug 13, 2025

Thanks for taking a look at this. I need to dig in further, but on first glance, I don't want to include nostr-tools as a dependency. It's almost 10MB and that's a lot for use with just one strategy. In general, I prefer to handroll clients for different protocols instead of relying on existing SDKs, which tend to be quite bloated.

@Ardakilic
Copy link
Author

Thanks for the feedback @nzakas , noted. I'll try to either find a lighter library or write from scratch. If I succeed, I'll update this PR.

@Ardakilic
Copy link
Author

Hello again @nzakas ,

I've removed the nostr-tools dependency and implemented the posting side manually.

However, I believe it's hard to bypass elyptic curve algorithms and encryption dependencies:

Nostr authentication is like ssh key authentication, you dispatch messages to relays using your private key, and public key is your address, you're not bound to any domain at all.

So I had to introduce some encryption libraries for this to work. They were possibly sub dependencies of nostr-tools (havent't checked).

I'd appreciate your feedback on this. Theoretically, I can guide the users to use some online sites to convert nsec... formatted private keys to hex format, and provide them in addition to a newly converted public key, and it should remove at least one dependency. However, almost every nostr client uses nsec.. string directly or through a browser extension.

PS: If this makes the project out of your focus and you'd think it would not be feasible to merge because of the new dependencies, since nostr is rather a new protocol, I understand, no problems. I was going to make exactly same thing as crosspost, without realizing this exists, then instead simply wanted to contribute 😊

@nzakas
Copy link
Contributor

nzakas commented Aug 14, 2025

Thanks. I'm going to need to find a chunk of time to dig deeply into this to better understand how Nostr is supposed to work and what a coherent strategy would look like.

@nzakas
Copy link
Contributor

nzakas commented Sep 1, 2025

Just had some time to look at this now. I'm not comfortable with the current implementation for a bunch of reasons, but rather than go back and forth, I'll just take some time to implement it. I appreciate your work on this and I'll use it as a guide as I move forward.

@nzakas nzakas marked this pull request as draft September 1, 2025 21:08
@Ardakilic
Copy link
Author

Heya,

First of all, thank you for the review.

Of course, no problems!

Also, I'd appreciate if you could share some feedback why it would not be feasible to merge as current state, totally to try to improve myself.

Thanks again for the interest, have a great day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants