{"record":{"id":"a7b5e556d500decb","repo":"ruvnet/ruflo","slug":"key-must-be-a-string-or-uint8array","errorCode":null,"errorMessage":"key must be a string or Uint8Array","messagePattern":"key must be a string or Uint8Array","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/watermark/index.js","lineNumber":17,"sourceCode":"// @claude-flow/watermark — ergonomic wrapper over the ruflo-watermark WASM core.\n//\n// SynthID-Text-style LLM text watermarking (generation + detection). The\n// watermark rides the tie-break randomness among plausible tokens — it never\n// injects an out-of-distribution word, costs no extra tokens, and is detectable\n// only with the key. This package deliberately does NOT include a watermark\n// remover / laundering tool.\n'use strict';\n\nconst wasm = require('./wasm/ruflo_watermark.js');\n\nconst SCHEMES = new Set(['tournament', 'tournament_nd', 'gumbel']);\n\nfunction toKeyBytes(key) {\n  if (typeof key === 'string') return new TextEncoder().encode(key);\n  if (key instanceof Uint8Array) return key;\n  throw new TypeError('key must be a string or Uint8Array');\n}\nfunction toU32(a) {\n  return a instanceof Uint32Array ? a : Uint32Array.from(a);\n}\nfunction toF32(a) {\n  return a instanceof Float32Array ? a : Float32Array.from(a);\n}\nfunction normScheme(scheme) {\n  const s = scheme || 'gumbel';\n  if (!SCHEMES.has(s)) throw new RangeError(`unknown scheme \"${s}\" (use tournament | tournament_nd | gumbel)`);\n  return s;\n}\n\n/** Shape a raw WasmDetection into a plain object with an `isWatermarked` helper. */\nfunction shape(r) {\n  const out = {\n    zScore: r.z_score,\n    pValue: r.p_value,","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/watermark/index.js#L1-L35","documentation":"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.","triggerScenarios":"Thrown at v3/@claude-flow/watermark/index.js:17 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass the key as a string or Uint8Array.","Convert other types (e.g. Buffer) with new Uint8Array(key) before calling."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}