Skip to content

nip/data-functions#2367

Open
samthomson wants to merge 2 commits into
nostr-protocol:masterfrom
samthomson:nip/data-functions
Open

nip/data-functions#2367
samthomson wants to merge 2 commits into
nostr-protocol:masterfrom
samthomson:nip/data-functions

Conversation

@samthomson

Copy link
Copy Markdown

WIP - conversation/feedback welcome, but it's not review ready yet.

This NIP proposes associating data with code, so that complex data can be recomputed on the fly using DVMs.
Similar to attestation types (npi 85?) where someone crunches data and we just query the output, with this NIP we ask for the crunched data, but provide a serverless function to run in order to populate it if it wasn't already defined (ie cached).

A simple example would be comment/reaction counts, or the reactions/comments themselves. Or more complex would be taking a lots of data (eg several weeks of historical weather data nip-whatever) and doing some aggregations on it.

The goal here is to let clients have snappy experiences while working with derived (not root query) data while:

  • reducing complexity in the client
  • keeping relays dumb (data in data out)
  • client builders don't need to invest heavily in infra (or devs to make custom caching stacks)
  • users don't lose centralisation by leaning on non-nostr native caching stacks
  • caching itself is outsourced to network effects; kind 1337s are democratised, and a secondary caching layer can emerge separate from the underlying datas

I've started a rough implementation in relaykit:

image image

A client can then consume as follows:

image

Here's a comparison showing first load, of me fetching weather data from the last month and calculating an average temperature versus me asking for the same one event of the same derived data:

image

And here's a second load, ie how it would be for a second visitor to the same client.

image

Note, if the DVM isn't locked down with a whitelist, then a client can publish a request to the dvm with an ephemeral key to avoid forcing users to login, so this is also a 'guest' friendly solution.

@fiatjaf

fiatjaf commented Jun 3, 2026

Copy link
Copy Markdown
Member

Aren't clients already doing this for many things, like your comment/reaction count example?

@samthomson

samthomson commented Jun 4, 2026 via email

Copy link
Copy Markdown
Author

@fiatjaf

fiatjaf commented Jun 4, 2026

Copy link
Copy Markdown
Member

Is the idea here to publish some custom map/reduce JavaScript code and then some DVM will execute that code and publish the results as events?

@samthomson

Copy link
Copy Markdown
Author

@fiatjaf yes/no. It's not prescriptive. I use a 1337 code sample kind for the serverless function, but then define a replaceable 31337 which references a 1337 but also adds config (ttl, dvm relay, read relays, write relays, optional params for the serverless function). It could be used for anything. Reaction/comment counts (or reactions/comments themselves) could be populated, but also anything. for instance above in my example I get tonnes of - nostr - weather data and crunch it.

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