upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfiatjaf <fiatjaf@gmail.com>2026-04-04 18:49:31 -0300
committerfiatjaf <fiatjaf@gmail.com>2026-04-04 18:49:31 -0300
commit85dd28b2414db6c0b6a72d4ecf5d0aa35f41cc24 (patch)
tree16f725e20af453ab7e84fc1dad9b277272149740
parente5a2a7e2b29f01d9320dd8b18927bb538ad8e05d (diff)
update parameter passing protocol with presence byte (by @TheAwiteb).
-rw-r--r--5C.md38
1 files changed, 26 insertions, 12 deletions
diff --git a/5C.md b/5C.md
index dcf0d2c..37197e1 100644
--- a/5C.md
+++ b/5C.md
@@ -117,24 +117,38 @@ For example, this scroll could be displayed as an option to be clicked on any us
117 117
118### Parameter Passing 118### Parameter Passing
119 119
120When the host calls `run()`, it passes a single pointer to a buffer containing all parameters in the order they appear in the tags. Each type has a specific encoding: 120When the host calls `run()`, it passes a single pointer to a buffer containing all parameters in the order they appear in the tags. Each type has a specific length or a way to determine its length (for strings, as described in "String Convention", this is a 4-byte prefix).
121 121
122| Type | Encoding | Size | 122The host must prefix every parameter with a single presence byte: `1` indicates the parameter is provided, and `0` indicates it is omitted. If a required parameter is prefixed with `0`, the program must panic.
123| ------------ | --------------------------------------------------------------------- | ------------- |
124| `public_key` | 32 bytes (should all be set to zero if the parameter is not provided) | 32 bytes |
125| `event` | i32 handle | 4 bytes |
126| `string` | u32_be length followed by UTF-8 bytes | 4 + len bytes |
127| `number` | i32 | 4 bytes |
128| `timestamp` | unix timestamp as u32_be | 4 bytes |
129| `relay` | relay URL, same as string | 4 + len bytes |
130 123
131For example: in a scroll with parameters `[me: public_key, target_event: event, target_relay: relay]` the buffer layout would be: 124| Type | Encoding | Size (if provided) |
125| ------------ | --------------------------------------------------------------------- | ------------------ |
126| `public_key` | 32 bytes | 32 bytes |
127| `event` | i32 handle | 4 bytes |
128| `string` | u32_be length followed by UTF-8 bytes | 4 + len bytes |
129| `number` | i32 | 4 bytes |
130| `timestamp` | Unix timestamp as u32_be | 4 bytes |
131| `relay` | Relay URL, same encoding as string | 4 + len bytes |
132 132
133
134For example, in a scroll with these parameters:
135
136```json
137[
138 ["param", "me", "", "public_key", "required"],
139 ["param", "note", "", "event", "required", "1,1111"],
140 ["param", "author", "", "public_key", ""],
141 ["param", "place", "", "relay", "required"]
142]
133``` 143```
134[ 32-byte current user pubkey ][ 4-byte i32 handle ][ 4-byte len for relay URL ][ UTF-8 relay URL ] 144
145The buffer layout would be:
146
147```text
148[ 1 ][ 32-byte pubkey ][ 1 ][ 4-byte handle ][ 0 ][ 1 ][ 4-byte len ][ UTF-8 relay URL ]
135``` 149```
136 150
137The WASM program reads this by iterating through the declared parameters in order, reading the appropriate number of bytes for each type. 151Because `author` is optional and not provided, its position contains only the `0` presence byte.
138 152
139--- 153---
140 154