zebflow 0.7.9

Reactive web automation platform — pipelines, templates, and real-time collaboration in a single binary.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
//! `n.crypto` — cryptographic primitives for pipeline security.
//!
//! A single multipurpose node covering the most common cryptographic
//! operations needed in authentication and data-integrity pipelines.
//!
//! # Operations
//!
//! | `--op` | Description | Output pin |
//! |---|---|---|
//! | `sha256` | SHA-256 hex digest of input | `out` |
//! | `sha512` | SHA-512 hex digest of input | `out` |
//! | `bcrypt_hash` | bcrypt password hash | `out` |
//! | `bcrypt_verify` | Compare plaintext against bcrypt hash | `true` / `false` |
//! | `argon2_hash` | Argon2id password hash (PHC string format) | `out` |
//! | `argon2_verify` | Compare plaintext against Argon2 hash | `true` / `false` |
//! | `hmac_sha256` | HMAC-SHA256 hex of input using `key` | `out` |
//! | `base64_encode` | Standard Base64 encode | `out` |
//! | `base64_decode` | Standard Base64 decode to UTF-8 | `out` |
//! | `random_hex` | Cryptographically random hex string | `out` |
//!
//! # Config flags
//!
//! | Flag | Type | Default | Description |
//! |---|---|---|---|
//! | `--op` | string | *(required)* | Operation name (see table above) |
//! | `--input-path` | string | `""` → `payload.input` | JSON pointer for primary input |
//! | `--hash-path` | string | `""` → `payload.hash` | JSON pointer for stored hash (verify ops) |
//! | `--key-path` | string | `""` → `payload.key` | JSON pointer for HMAC secret key |
//! | `--cost` | integer | `12` | bcrypt cost factor (4–31) |
//! | `--length` | integer | `32` | Random byte count for `random_hex` |
//!
//! # Payload extraction
//!
//! Each op reads its inputs from the flowing payload via JSON pointer paths.
//! If a path flag is empty, a well-known field name is used as fallback:
//!
//! | Op | Primary input field | Secondary input field |
//! |---|---|---|
//! | `sha256`, `sha512` | `payload.input` | — |
//! | `bcrypt_hash`, `argon2_hash` | `payload.input` | — |
//! | `bcrypt_verify`, `argon2_verify` | `payload.input` (plaintext) | `payload.hash` (stored hash) |
//! | `hmac_sha256` | `payload.input` (message) | `payload.key` (secret key) |
//! | `base64_encode`, `base64_decode` | `payload.input` | — |
//! | `random_hex` | *(none — generates fresh bytes)* | — |
//!
//! # Output pins
//!
//! Hash / encode / decode operations replace the payload with `{ result }` and
//! emit to the `out` pin.
//!
//! Verify operations (`bcrypt_verify`, `argon2_verify`) route to the `true`
//! or `false` pin, forwarding the original payload unchanged — no extra
//! `n.logic.if` node needed.
//!
//! # Example pipelines
//!
//! **User registration — hash a password:**
//! ```text
//! | n.trigger.webhook --path /auth/register --method POST
//! | n.crypto --op bcrypt_hash
//! | n.pg.query --credential main-db -- "INSERT INTO users (email, pw_hash) VALUES ($.email, $.result)"
//! ```
//!
//! **User login — verify password and issue JWT:**
//! ```text
//! | n.trigger.webhook --path /auth/login --method POST
//! | n.pg.query --credential main-db -- "SELECT pw_hash AS hash FROM users WHERE email = $.email"
//! | n.crypto --op bcrypt_verify
//! | [true]  → n.auth.token.create --credential jwt-key
//! | [false] → n.script -- "return { _status: 401, error: 'Invalid credentials' }"
//! ```
//!
//! **Webhook signature check (HMAC-SHA256):**
//! ```text
//! | n.trigger.webhook --path /webhooks/github --method POST
//! | n.crypto --op hmac_sha256 --key-path /webhook_secret
//! | n.logic.if -- "payload.result === payload.expected_sig"
//! ```
//!
//! **Generate a secure session token:**
//! ```text
//! | n.trigger.webhook --path /auth/session --method POST
//! | n.crypto --op random_hex --length 32
//! | n.pg.query --credential main-db -- "INSERT INTO sessions (token, user_id) VALUES ($.result, $.user_id)"
//! ```

use async_trait::async_trait;
use base64::{Engine as _, engine::general_purpose};
use hmac::{Hmac, Mac};
use serde::{Deserialize, Serialize};
use serde_json::{Value, json};
use sha2::{Digest, Sha256, Sha512};

use crate::pipeline::model::{DslFlag, DslFlagKind, LayoutItem};
use crate::pipeline::{
    NodeDefinition, PipelineError,
    nodes::{NodeExecutionInput, NodeExecutionOutput, NodeHandler},
};

pub const NODE_KIND: &str = "n.crypto";
const INPUT_PIN_IN: &str = "in";
const OUTPUT_PIN_OUT: &str = "out";
const OUTPUT_PIN_TRUE: &str = "true";
const OUTPUT_PIN_FALSE: &str = "false";

/// Return the [`NodeDefinition`] for `n.crypto`.
pub fn definition() -> NodeDefinition {
    NodeDefinition {
        kind: NODE_KIND.to_string(),
        title: "Crypto".to_string(),
        description: "Cryptographic primitives: hash, verify, HMAC, base64, random. \
            Use --op to select the operation. Hash/encode ops replace the payload with \
            { result } and emit to the 'out' pin. Verify ops (bcrypt_verify, argon2_verify) \
            route to 'true' or 'false' pin, forwarding the payload unchanged. \
            Input defaults to payload.input; override with --input-path. \
            Use $trigger or $nodes references for upstream data."
            .to_string(),
        input_schema: json!({
            "type": "object",
            "properties": {
                "input": {
                    "type": "string",
                    "description": "Primary input value (password, message, etc.)."
                },
                "hash": {
                    "type": "string",
                    "description": "Stored hash for verify operations."
                },
                "key": {
                    "type": "string",
                    "description": "HMAC secret key."
                }
            }
        }),
        output_schema: json!({
            "type": "object",
            "properties": {
                "result": {
                    "type": "string",
                    "description": "Computed value (hex digest, base64 string, bcrypt/argon2 hash, etc.)."
                }
            }
        }),
        input_pins: vec![INPUT_PIN_IN.to_string()],
        output_pins: vec![
            OUTPUT_PIN_OUT.to_string(),
            OUTPUT_PIN_TRUE.to_string(),
            OUTPUT_PIN_FALSE.to_string(),
        ],
        script_available: false,
        script_bridge: None,
        config_schema: Default::default(),
        dsl_flags: vec![
            DslFlag { flag: "--op".to_string(), config_key: "op".to_string(), description: "Cryptographic operation: sha256, sha512, bcrypt_hash, bcrypt_verify, argon2_hash, argon2_verify, hmac_sha256, base64_encode, base64_decode, random_hex.".to_string(), kind: DslFlagKind::Scalar, required: true },
            DslFlag { flag: "--input-path".to_string(), config_key: "input_path".to_string(), description: "JSON pointer for primary input value (default: payload.input).".to_string(), kind: DslFlagKind::Scalar, required: false },
            DslFlag { flag: "--hash-path".to_string(), config_key: "hash_path".to_string(), description: "JSON pointer for stored hash for verify operations (default: payload.hash).".to_string(), kind: DslFlagKind::Scalar, required: false },
            DslFlag { flag: "--key-path".to_string(), config_key: "key_path".to_string(), description: "JSON pointer for HMAC secret key (default: payload.key).".to_string(), kind: DslFlagKind::Scalar, required: false },
            DslFlag { flag: "--cost".to_string(), config_key: "cost".to_string(), description: "bcrypt cost factor 4-31 (default 12).".to_string(), kind: DslFlagKind::Scalar, required: false },
            DslFlag { flag: "--length".to_string(), config_key: "length".to_string(), description: "Random byte count for random_hex (default 32).".to_string(), kind: DslFlagKind::Scalar, required: false },
        ],
        fields: {
            use crate::pipeline::model::{NodeFieldDef, NodeFieldType, SelectOptionDef};
            vec![
                NodeFieldDef { name: "op".to_string(), label: "Operation".to_string(), field_type: NodeFieldType::Select, options: vec![
                    SelectOptionDef { value: "sha256".to_string(), label: "SHA-256 hash".to_string() },
                    SelectOptionDef { value: "sha512".to_string(), label: "SHA-512 hash".to_string() },
                    SelectOptionDef { value: "bcrypt_hash".to_string(), label: "bcrypt hash".to_string() },
                    SelectOptionDef { value: "bcrypt_verify".to_string(), label: "bcrypt verify → true/false pin".to_string() },
                    SelectOptionDef { value: "argon2_hash".to_string(), label: "Argon2id hash".to_string() },
                    SelectOptionDef { value: "argon2_verify".to_string(), label: "Argon2id verify → true/false pin".to_string() },
                    SelectOptionDef { value: "hmac_sha256".to_string(), label: "HMAC-SHA256".to_string() },
                    SelectOptionDef { value: "base64_encode".to_string(), label: "Base64 encode".to_string() },
                    SelectOptionDef { value: "base64_decode".to_string(), label: "Base64 decode".to_string() },
                    SelectOptionDef { value: "random_hex".to_string(), label: "Random hex token".to_string() },
                ], help: Some("Cryptographic operation to perform. Verify operations route to true/false pins.".to_string()), ..Default::default() },
                NodeFieldDef { name: "input_path".to_string(), label: "Input Path".to_string(), field_type: NodeFieldType::Text, help: Some("JSON pointer for the primary input value. Empty reads payload.input.".to_string()), ..Default::default() },
                NodeFieldDef { name: "hash_path".to_string(), label: "Hash Path (verify)".to_string(), field_type: NodeFieldType::Text, help: Some("JSON pointer for the stored hash used by verify operations. Empty reads payload.hash.".to_string()), ..Default::default() },
                NodeFieldDef { name: "key_path".to_string(), label: "Key Path (HMAC)".to_string(), field_type: NodeFieldType::Text, help: Some("JSON pointer for the HMAC secret key. Empty reads payload.key.".to_string()), ..Default::default() },
                NodeFieldDef { name: "cost".to_string(), label: "Cost (bcrypt)".to_string(), field_type: NodeFieldType::Text, help: Some("bcrypt cost factor from 4 to 31. Defaults to 12.".to_string()), ..Default::default() },
                NodeFieldDef { name: "length".to_string(), label: "Length (random_hex)".to_string(), field_type: NodeFieldType::Text, help: Some("Random byte count for random_hex output. Defaults to 32.".to_string()), ..Default::default() },
            ]
        },
        layout: vec![
            LayoutItem::Field("op".to_string()),
            LayoutItem::Row { row: vec![LayoutItem::Field("input_path".to_string()), LayoutItem::Field("hash_path".to_string())] },
            LayoutItem::Row { row: vec![LayoutItem::Field("key_path".to_string()), LayoutItem::Field("cost".to_string())] },
            LayoutItem::Field("length".to_string()),
        ],
        ai_tool: Default::default(),
        ..Default::default()
    }
}

/// Configuration for `n.crypto`.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Config {
    /// Cryptographic operation to perform (required).
    ///
    /// Valid values: `sha256`, `sha512`, `bcrypt_hash`, `bcrypt_verify`,
    /// `argon2_hash`, `argon2_verify`, `hmac_sha256`, `base64_encode`,
    /// `base64_decode`, `random_hex`.
    pub op: String,

    /// JSON pointer into the payload for the primary input value.
    ///
    /// Empty (default) → reads `payload["input"]`.
    /// Example: `"/body"` — use `payload.body` as the input.
    #[serde(default)]
    pub input_path: String,

    /// JSON pointer into the payload for the stored hash (verify ops only).
    ///
    /// Empty (default) → reads `payload["hash"]`.
    #[serde(default)]
    pub hash_path: String,

    /// JSON pointer into the payload for the HMAC secret key (`hmac_sha256` only).
    ///
    /// Empty (default) → reads `payload["key"]`.
    #[serde(default)]
    pub key_path: String,

    /// bcrypt cost factor (default `12`, range 4–31).
    ///
    /// Higher cost = slower hash = harder to brute-force.
    /// Cost 12 takes ~200–400 ms on modern hardware.
    #[serde(default)]
    pub cost: Option<u32>,

    /// Number of random bytes for `random_hex` (default `32`).
    ///
    /// Output hex string length = `length * 2`.
    /// Example: `length = 32` → 64-character hex string.
    #[serde(default)]
    pub length: Option<u32>,
}

/// `n.crypto` node instance.
pub struct Node {
    config: Config,
}

impl Node {
    pub fn new(config: Config) -> Result<Self, PipelineError> {
        const VALID_OPS: &[&str] = &[
            "sha256",
            "sha512",
            "bcrypt_hash",
            "bcrypt_verify",
            "argon2_hash",
            "argon2_verify",
            "hmac_sha256",
            "base64_encode",
            "base64_decode",
            "random_hex",
        ];
        if config.op.is_empty() {
            return Err(PipelineError::new(
                "FW_NODE_CRYPTO_CONFIG",
                "n.crypto: --op must be specified",
            ));
        }
        if !VALID_OPS.contains(&config.op.as_str()) {
            return Err(PipelineError::new(
                "FW_NODE_CRYPTO_OP",
                format!(
                    "n.crypto: unknown op '{}'. Valid ops: {}",
                    config.op,
                    VALID_OPS.join(", ")
                ),
            ));
        }
        Ok(Self { config })
    }
}

// ── Payload helpers ──────────────────────────────────────────────────────────

/// Extract a string value from the payload using a JSON pointer path.
///
/// If `path` is empty, falls back to `payload[fallback_key]`.
/// Returns `""` if neither is found or the value is not a string.
fn extract_str<'a>(payload: &'a Value, path: &str, fallback_key: &str) -> &'a str {
    if !path.is_empty() {
        let ptr = if path.starts_with('/') {
            path.to_string()
        } else {
            format!("/{}", path)
        };
        return payload
            .pointer(&ptr)
            .and_then(Value::as_str)
            .unwrap_or_default();
    }
    payload
        .get(fallback_key)
        .and_then(Value::as_str)
        .unwrap_or_default()
}

/// Build a fresh output payload with only the `result` field (replace, not merge).
fn with_result(result: impl Into<Value>) -> Value {
    json!({ "result": result.into() })
}

// ── NodeHandler impl ───────────────────────────────────────────────────────

#[async_trait]
impl NodeHandler for Node {
    fn kind(&self) -> &'static str {
        NODE_KIND
    }
    fn input_pins(&self) -> &'static [&'static str] {
        &[INPUT_PIN_IN]
    }
    fn output_pins(&self) -> &'static [&'static str] {
        &[OUTPUT_PIN_OUT, OUTPUT_PIN_TRUE, OUTPUT_PIN_FALSE]
    }

    async fn execute_async(
        &self,
        input: NodeExecutionInput,
    ) -> Result<NodeExecutionOutput, PipelineError> {
        let payload = input.payload;

        match self.config.op.as_str() {
            // ── sha256 ────────────────────────────────────────────────────────
            "sha256" => {
                let input_val = extract_str(&payload, &self.config.input_path, "input").to_string();
                let mut h = Sha256::new();
                h.update(input_val.as_bytes());
                let result = hex::encode(h.finalize());
                Ok(NodeExecutionOutput {
                    output_pins: vec![OUTPUT_PIN_OUT.to_string()],
                    payload: with_result(result),
                    trace: vec!["n.crypto: sha256".to_string()],
                })
            }

            // ── sha512 ────────────────────────────────────────────────────────
            "sha512" => {
                let input_val = extract_str(&payload, &self.config.input_path, "input").to_string();
                let mut h = Sha512::new();
                h.update(input_val.as_bytes());
                let result = hex::encode(h.finalize());
                Ok(NodeExecutionOutput {
                    output_pins: vec![OUTPUT_PIN_OUT.to_string()],
                    payload: with_result(result),
                    trace: vec!["n.crypto: sha512".to_string()],
                })
            }

            // ── bcrypt_hash ───────────────────────────────────────────────────
            "bcrypt_hash" => {
                let input_val = extract_str(&payload, &self.config.input_path, "input").to_string();
                let cost = self.config.cost.unwrap_or(12);
                let result = tokio::task::spawn_blocking(move || {
                    bcrypt::hash(&input_val, cost).map_err(|e| e.to_string())
                })
                .await
                .map_err(|e| PipelineError::new("FW_NODE_CRYPTO_SPAWN", e.to_string()))?
                .map_err(|e| PipelineError::new("FW_NODE_CRYPTO_BCRYPT_HASH", e))?;
                Ok(NodeExecutionOutput {
                    output_pins: vec![OUTPUT_PIN_OUT.to_string()],
                    payload: with_result(result),
                    trace: vec![format!("n.crypto: bcrypt_hash cost={cost}")],
                })
            }

            // ── bcrypt_verify ─────────────────────────────────────────────────
            "bcrypt_verify" => {
                let plaintext = extract_str(&payload, &self.config.input_path, "input").to_string();
                let stored = extract_str(&payload, &self.config.hash_path, "hash").to_string();
                let is_valid = tokio::task::spawn_blocking(move || {
                    bcrypt::verify(&plaintext, &stored).unwrap_or(false)
                })
                .await
                .map_err(|e| PipelineError::new("FW_NODE_CRYPTO_SPAWN", e.to_string()))?;
                let pin = if is_valid {
                    OUTPUT_PIN_TRUE
                } else {
                    OUTPUT_PIN_FALSE
                };
                Ok(NodeExecutionOutput {
                    output_pins: vec![pin.to_string()],
                    payload,
                    trace: vec![format!("n.crypto: bcrypt_verify result={is_valid}")],
                })
            }

            // ── argon2_hash ───────────────────────────────────────────────────
            "argon2_hash" => {
                let input_val = extract_str(&payload, &self.config.input_path, "input").to_string();
                let result = tokio::task::spawn_blocking(move || {
                    use argon2::{
                        Argon2,
                        password_hash::{PasswordHasher, SaltString, rand_core::OsRng},
                    };
                    let salt = SaltString::generate(&mut OsRng);
                    Argon2::default()
                        .hash_password(input_val.as_bytes(), &salt)
                        .map(|h| h.to_string())
                        .map_err(|e| e.to_string())
                })
                .await
                .map_err(|e| PipelineError::new("FW_NODE_CRYPTO_SPAWN", e.to_string()))?
                .map_err(|e| PipelineError::new("FW_NODE_CRYPTO_ARGON2_HASH", e))?;
                Ok(NodeExecutionOutput {
                    output_pins: vec![OUTPUT_PIN_OUT.to_string()],
                    payload: with_result(result),
                    trace: vec!["n.crypto: argon2_hash".to_string()],
                })
            }

            // ── argon2_verify ─────────────────────────────────────────────────
            "argon2_verify" => {
                let plaintext = extract_str(&payload, &self.config.input_path, "input").to_string();
                let stored = extract_str(&payload, &self.config.hash_path, "hash").to_string();
                let is_valid = tokio::task::spawn_blocking(move || {
                    use argon2::{
                        Argon2,
                        password_hash::{PasswordHash, PasswordVerifier},
                    };
                    PasswordHash::new(&stored)
                        .map(|h| {
                            Argon2::default()
                                .verify_password(plaintext.as_bytes(), &h)
                                .is_ok()
                        })
                        .unwrap_or(false)
                })
                .await
                .map_err(|e| PipelineError::new("FW_NODE_CRYPTO_SPAWN", e.to_string()))?;
                let pin = if is_valid {
                    OUTPUT_PIN_TRUE
                } else {
                    OUTPUT_PIN_FALSE
                };
                Ok(NodeExecutionOutput {
                    output_pins: vec![pin.to_string()],
                    payload,
                    trace: vec![format!("n.crypto: argon2_verify result={is_valid}")],
                })
            }

            // ── hmac_sha256 ───────────────────────────────────────────────────
            "hmac_sha256" => {
                let input_val = extract_str(&payload, &self.config.input_path, "input").to_string();
                let key_val = extract_str(&payload, &self.config.key_path, "key").to_string();
                type HmacSha256 = Hmac<Sha256>;
                let mut mac = HmacSha256::new_from_slice(key_val.as_bytes())
                    .map_err(|e| PipelineError::new("FW_NODE_CRYPTO_HMAC_KEY", e.to_string()))?;
                mac.update(input_val.as_bytes());
                let result = hex::encode(mac.finalize().into_bytes());
                Ok(NodeExecutionOutput {
                    output_pins: vec![OUTPUT_PIN_OUT.to_string()],
                    payload: with_result(result),
                    trace: vec!["n.crypto: hmac_sha256".to_string()],
                })
            }

            // ── base64_encode ─────────────────────────────────────────────────
            "base64_encode" => {
                let input_val = extract_str(&payload, &self.config.input_path, "input").to_string();
                let result = general_purpose::STANDARD.encode(input_val.as_bytes());
                Ok(NodeExecutionOutput {
                    output_pins: vec![OUTPUT_PIN_OUT.to_string()],
                    payload: with_result(result),
                    trace: vec!["n.crypto: base64_encode".to_string()],
                })
            }

            // ── base64_decode ─────────────────────────────────────────────────
            "base64_decode" => {
                let input_val = extract_str(&payload, &self.config.input_path, "input").to_string();
                let bytes = general_purpose::STANDARD
                    .decode(input_val.as_bytes())
                    .map_err(|e| {
                        PipelineError::new("FW_NODE_CRYPTO_BASE64_DECODE", e.to_string())
                    })?;
                let result = String::from_utf8(bytes)
                    .map_err(|e| PipelineError::new("FW_NODE_CRYPTO_BASE64_UTF8", e.to_string()))?;
                Ok(NodeExecutionOutput {
                    output_pins: vec![OUTPUT_PIN_OUT.to_string()],
                    payload: with_result(result),
                    trace: vec!["n.crypto: base64_decode".to_string()],
                })
            }

            // ── random_hex ────────────────────────────────────────────────────
            "random_hex" => {
                let length = self.config.length.unwrap_or(32) as usize;
                let result = tokio::task::spawn_blocking(move || {
                    use rand::RngExt;
                    let mut rng = rand::rng();
                    let bytes: Vec<u8> = (0..length).map(|_| rng.random::<u8>()).collect();
                    hex::encode(&bytes)
                })
                .await
                .map_err(|e| PipelineError::new("FW_NODE_CRYPTO_SPAWN", e.to_string()))?;
                Ok(NodeExecutionOutput {
                    output_pins: vec![OUTPUT_PIN_OUT.to_string()],
                    payload: with_result(result),
                    trace: vec![format!("n.crypto: random_hex length={length}")],
                })
            }

            // ── unknown op (validation should have caught this) ───────────────
            other => Err(PipelineError::new(
                "FW_NODE_CRYPTO_OP",
                format!("n.crypto: unknown op '{other}'"),
            )),
        }
    }
}