ruvnet/ruflo · error · TypeError

key must be a string or Uint8Array

Error message

key must be a string or Uint8Array

What it means

toKeyBytes type guard: the watermark key passed to the API is neither a string nor a Uint8Array (null, number, plain object, etc.). The key must be raw bytes for the WASM core, so anything else is rejected with a TypeError before any watermarking or detection runs.

Source

Thrown at v3/@claude-flow/watermark/index.js:17

// @claude-flow/watermark — ergonomic wrapper over the ruflo-watermark WASM core.
//
// SynthID-Text-style LLM text watermarking (generation + detection). The
// watermark rides the tie-break randomness among plausible tokens — it never
// injects an out-of-distribution word, costs no extra tokens, and is detectable
// only with the key. This package deliberately does NOT include a watermark
// remover / laundering tool.
'use strict';

const wasm = require('./wasm/ruflo_watermark.js');

const SCHEMES = new Set(['tournament', 'tournament_nd', 'gumbel']);

function toKeyBytes(key) {
  if (typeof key === 'string') return new TextEncoder().encode(key);
  if (key instanceof Uint8Array) return key;
  throw new TypeError('key must be a string or Uint8Array');
}
function toU32(a) {
  return a instanceof Uint32Array ? a : Uint32Array.from(a);
}
function toF32(a) {
  return a instanceof Float32Array ? a : Float32Array.from(a);
}
function normScheme(scheme) {
  const s = scheme || 'gumbel';
  if (!SCHEMES.has(s)) throw new RangeError(`unknown scheme "${s}" (use tournament | tournament_nd | gumbel)`);
  return s;
}

/** Shape a raw WasmDetection into a plain object with an `isWatermarked` helper. */
function shape(r) {
  const out = {
    zScore: r.z_score,
    pValue: r.p_value,

View on GitHub (pinned to fa13ee4ad6)

Solutions

  1. Pass the key as a string or Uint8Array.
  2. Convert other types (e.g. Buffer) with new Uint8Array(key) before calling.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at v3/@claude-flow/watermark/index.js:17 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18). Data as JSON: /api/errors/a7b5e556d500decb. Report an issue: GitHub.