# data

Node.js-side data envelope factory and validators; the schema hash comes from Node's `crypto` module.

A `Data<T>` is the envelope that wraps every application message inside a packet ([`pid`](https://www.hyperfrontend.dev/docs/libraries/network-protocol/node/data/#api-Data-prop-pid), [`id`](https://www.hyperfrontend.dev/docs/libraries/network-protocol/node/data/#api-Data-prop-id), [`sequence`](https://www.hyperfrontend.dev/docs/libraries/network-protocol/node/data/#api-Data-prop-sequence), [`message`](https://www.hyperfrontend.dev/docs/libraries/network-protocol/node/data/#api-Data-prop-message), [`schema`](https://www.hyperfrontend.dev/docs/libraries/network-protocol/node/data/#api-Data-prop-schema), [`schemaHash`](https://www.hyperfrontend.dev/docs/libraries/network-protocol/node/data/#api-Data-prop-schemaHash)). This entry point binds the runtime-agnostic `lib/data` factory to [`createHash`](https://www.hyperfrontend.dev/docs/libraries/cryptography/#api-createHash) from [`@hyperfrontend/cryptography/node`](https://www.hyperfrontend.dev/docs/libraries/cryptography/node.md), so `createData(pid, sequence, message)` generates a JSON Schema for the message and hashes it with SHA-256 via `node:crypto`.

- Serialization helpers ([`serializeData`](https://www.hyperfrontend.dev/docs/libraries/network-protocol/node/data/#api-serializeData), [`deserializeData`](https://www.hyperfrontend.dev/docs/libraries/network-protocol/node/data/#api-deserializeData), [`asJSONString`](https://www.hyperfrontend.dev/docs/libraries/network-protocol/node/data/#api-asJSONString), [`parseJSONString`](https://www.hyperfrontend.dev/docs/libraries/network-protocol/node/data/#api-parseJSONString), [`isJSONString`](https://www.hyperfrontend.dev/docs/libraries/network-protocol/node/data/#api-isJSONString)) and [`getSchema`](https://www.hyperfrontend.dev/docs/libraries/network-protocol/node/data/#api-getSchema) are re-exported for callers that need to manipulate the envelope outside the pipeline.
- Validation helpers ([`isValidId`](https://www.hyperfrontend.dev/docs/libraries/network-protocol/node/data/#api-isValidId), [`isValidPid`](https://www.hyperfrontend.dev/docs/libraries/network-protocol/node/data/#api-isValidPid), [`isValidSequence`](https://www.hyperfrontend.dev/docs/libraries/network-protocol/node/data/#api-isValidSequence), [`isValidMessage`](https://www.hyperfrontend.dev/docs/libraries/network-protocol/node/data/#api-isValidMessage), [`isValidSchema`](https://www.hyperfrontend.dev/docs/libraries/network-protocol/node/data/#api-isValidSchema), [`isValidSchemaHash`](https://www.hyperfrontend.dev/docs/libraries/network-protocol/node/data/#api-isValidSchemaHash), [`isValidUnencryptedData`](https://www.hyperfrontend.dev/docs/libraries/network-protocol/node/data/#api-isValidUnencryptedData)) are exposed for upstream guards.
- Function signatures match [`/browser/data`](https://www.hyperfrontend.dev/docs/libraries/network-protocol/browser/data.md) so envelopes are interchangeable across runtimes; pick the adapter that matches the process and the rest of the code stays identical.

---

Canonical page: https://www.hyperfrontend.dev/docs/libraries/network-protocol/node/data/
This file: https://www.hyperfrontend.dev/docs/libraries/network-protocol/node/data.md
Documentation index: https://www.hyperfrontend.dev/llms.txt
