diff options
| -rw-r--r-- | A5.md | 18 |
1 files changed, 9 insertions, 9 deletions
| @@ -1,10 +1,10 @@ | |||
| 1 | # NIP-A5 | 1 | # NIP-A5 |
| 2 | 2 | ||
| 3 | ## WASM Programs | 3 | ## Scrolls |
| 4 | 4 | ||
| 5 | `draft` `optional` | 5 | `draft` `optional` |
| 6 | 6 | ||
| 7 | This NIP defines a standard for publishing self-contained WebAssembly programs as Nostr events. Programs are base64-encoded, executed client-side, and interact with Nostr exclusively through a host-provided handle-based API for building requests, querying relays, and rendering results. | 7 | This NIP defines a standard for publishing self-contained WebAssembly programs as Nostr events ("scrolls"). Scrolls are composed of basic metadata (`name`, `description` and `image`) and initial execution parameters defined as tags and a WASM binary, base64-encoded as the content. The binaries are executed in a sandbox inside a "host" (i.e. a proper Nostr client). Scrolls interact with Nostr only through a set of simple APIs provided by the host. |
| 8 | 8 | ||
| 9 | --- | 9 | --- |
| 10 | 10 | ||
| @@ -16,8 +16,8 @@ This NIP defines a standard for publishing self-contained WebAssembly programs a | |||
| 16 | "content": "<base64-encoded WASM binary>", | 16 | "content": "<base64-encoded WASM binary>", |
| 17 | "tags": | 17 | "tags": |
| 18 | [ | 18 | [ |
| 19 | ["name", "<program-name>"], | 19 | ["name", "<name>"], |
| 20 | ["description", "<optional-description>"], | 20 | ["description", "<description>"], |
| 21 | ["icon", "<image-url>"], | 21 | ["icon", "<image-url>"], |
| 22 | ["param", "<... (see below)>"] | 22 | ["param", "<... (see below)>"] |
| 23 | ] | 23 | ] |
| @@ -70,7 +70,7 @@ The WASM module **must** export its linear memory so the host can read guest str | |||
| 70 | 70 | ||
| 71 | ## Parameters | 71 | ## Parameters |
| 72 | 72 | ||
| 73 | Programs can declare parameters that the host must provide when calling `run()`. Parameters are declared as tags on the program event. | 73 | Scrolls can declare parameters that the host must provide when calling `run()`. |
| 74 | 74 | ||
| 75 | The tag format is `["param", "<name>", "<description>", "<type>", "<required>"]` where: | 75 | The tag format is `["param", "<name>", "<description>", "<type>", "<required>"]` where: |
| 76 | 76 | ||
| @@ -85,9 +85,9 @@ A special parameter called `"me"` of type `public_key` can be specified to be au | |||
| 85 | 85 | ||
| 86 | Parameters of type `event` may take an extra tag item `<supported_kinds>` after `<required>` with a comma-separated list of kinds that are acceptable. | 86 | Parameters of type `event` may take an extra tag item `<supported_kinds>` after `<required>` with a comma-separated list of kinds that are acceptable. |
| 87 | 87 | ||
| 88 | ### Example Event | 88 | ### Example |
| 89 | 89 | ||
| 90 | For example, this program could be displayed as an option to be clicked on any user profile. | 90 | For example, this scroll could be displayed as an option to be clicked on any user profile. |
| 91 | 91 | ||
| 92 | ```yaml | 92 | ```yaml |
| 93 | { | 93 | { |
| @@ -122,7 +122,7 @@ When the host calls `run()`, it passes a single pointer to a buffer containing a | |||
| 122 | | `timestamp` | unix timestamp as u32_be | 4 bytes | | 122 | | `timestamp` | unix timestamp as u32_be | 4 bytes | |
| 123 | | `relay` | relay URL, same as string | 4 + len bytes | | 123 | | `relay` | relay URL, same as string | 4 + len bytes | |
| 124 | 124 | ||
| 125 | For example: in a program with parameters `[me: public_key, target_event: event, target_relay: relay]` the buffer layout would be: | 125 | For example: in a scroll with parameters `[me: public_key, target_event: event, target_relay: relay]` the buffer layout would be: |
| 126 | 126 | ||
| 127 | ``` | 127 | ``` |
| 128 | [ 32-byte current user pubkey ][ 4-byte i32 handle ][ 4-byte len for relay URL ][ UTF-8 relay URL ] | 128 | [ 32-byte current user pubkey ][ 4-byte i32 handle ][ 4-byte len for relay URL ][ UTF-8 relay URL ] |
| @@ -279,7 +279,7 @@ Releases any handle: unconsumed request, active subscription (cancels it), indiv | |||
| 279 | 279 | ||
| 280 | --- | 280 | --- |
| 281 | 281 | ||
| 282 | ## Example Programs and Host | 282 | ## Example programs and host code |
| 283 | 283 | ||
| 284 | - JavaScript host runtime example: https://viewsource.win/fiatjaf.com/nprogram/_/2e7d56d1536fcca8c49e7b2e99db8062f8df9ae1/~/src/nprogram-host.ts | 284 | - JavaScript host runtime example: https://viewsource.win/fiatjaf.com/nprogram/_/2e7d56d1536fcca8c49e7b2e99db8062f8df9ae1/~/src/nprogram-host.ts |
| 285 | - Rust example (basic, just reads from a relay): https://viewsource.win/fiatjaf.com/nprogram/_/2e7d56d1536fcca8c49e7b2e99db8062f8df9ae1/~/examples/basic/src/lib.rs | 285 | - Rust example (basic, just reads from a relay): https://viewsource.win/fiatjaf.com/nprogram/_/2e7d56d1536fcca8c49e7b2e99db8062f8df9ae1/~/examples/basic/src/lib.rs |