# Hash Data

> Hashes data with SHA-256, SHA-384 or SHA-512 (hex).

Source: https://docs.sommatic.ai/en/nodes/crypto.hash/

- Slug: `crypto.hash`
- Family: Identity
- Version: 2.0.0
- Status: Available
- Execution: sync

Hashes data with SHA-256, SHA-384 or SHA-512 (hex).

## Configuration

- `data` (any, required): Data to hash (objects are JSON-serialized)
- `algorithm` (string, optional): Default: `sha256`. Allowed values: `sha256`, `sha384`, `sha512`.

## Output ports

- `out` (default): Hashed string
- `error`: Hash failed

## Input contract

- `data` (any, required)
- `algorithm` (string, optional)

## Output contract

- `hash` (string, optional)

## In expressions

What a later node can read from this node's output with `$("Hash Data").item.json.<path>` (write your node's label instead of `Hash Data`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `out`, from the output shown in Ports.

- `$("Hash Data").item.json.hash` (string) = `"8c87b489ce35cf2e2f39f80e282cb2e804932a56a213…"`


## How it works

Computes the hexadecimal SHA-256, SHA-384 or SHA-512 digest of a value. Strings are hashed as UTF-8; any other value is JSON-serialized first.

1. Resolves the config; use a pure expression such as `{{ $json.email }}` in `data`.
2. Leaves through `error` with `data is required` when `data` is undefined, null or an empty string.
3. Checks `algorithm` (default `sha256`) against `sha256`, `sha384` and `sha512`.
4. Serializes non-string values with `JSON.stringify` and digests the UTF-8 text.
5. Returns `{ hash }` (lowercase hex) on `out`, with `meta.crypto`.

## In a workflow

### Node

```json
{
  "node_id": "node-hash-email",
  "label": "Hash customer email",
  "operator_slug": "crypto.hash",
  "operator_version": "2.0.0",
  "config": {
    "data": "{{ $json.email }}",
    "algorithm": "sha256"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "port": "out",
  "data": {
    "hash": "8c87b489ce35cf2e2f39f80e282cb2e804932a56a213983eeeb428407d43b52d"
  },
  "meta": {
    "crypto": {
      "op": "hash",
      "key_source": null,
      "alias": null,
      "credential_id": null,
      "algorithm": "sha256",
      "ok": true
    }
  }
}
```

## Output ports (behaviour in the code)

### `out`

The digest was computed.

```json
{
  "hash": "8c87b489ce35cf2e2f39f80e282cb2e804932a56a213983eeeb428407d43b52d"
}
```

### `error`

`data` is missing or the algorithm is not supported.

```json
{
  "error": "Unsupported hash algorithm: md5"
}
```

## Behaviour in the code

- `data`: Objects are serialized with `JSON.stringify`, so key order matters: `{"a":1,"b":2}` and `{"b":2,"a":1}` give different hashes. Normalize the value first when you compare hashes across systems.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `data is required` | `error` | `data` is empty or its expression resolved to nothing. `0` and `false` are valid values. |
| `Unsupported hash algorithm: <algorithm>` | `error` | Only `sha256`, `sha384` and `sha512` are accepted. |

## Notes and limits

- The digest is unkeyed: the same input always gives the same hash, which makes it suitable for equality checks and pseudonymous keys.
- Leaving through `error` does not fail the run: the engine follows the edges wired to `error`, and if there are none the branch simply ends.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "crypto.hash",
  "name": "Hash Data",
  "category": "identity",
  "version": "2.0.0",
  "description": "Hashes data with SHA-256, SHA-384 or SHA-512 (hex).",
  "capabilities": [
    "crypto",
    "hash"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "data": {
        "description": "Data to hash (objects are JSON-serialized)"
      },
      "algorithm": {
        "type": "string",
        "default": "sha256",
        "enum": [
          "sha256",
          "sha384",
          "sha512"
        ]
      }
    },
    "required": [
      "data"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "data": {},
      "algorithm": {
        "type": "string"
      }
    },
    "required": [
      "data"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "hash": {
        "type": "string"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Hash",
      "description": "Hashed string",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Hash failed",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "sync",
  "required_resources": [],
  "compatible_worker_pools": [
    "standard"
  ],
  "tags": [
    "crypto",
    "security"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_veripass",
    "profile": {
      "name": "Veripass",
      "verified": true,
      "url": "https://me.veripass.com/veripass",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "data": {
      "description": "Data to hash (objects are JSON-serialized)"
    },
    "algorithm": {
      "type": "string",
      "default": "sha256",
      "enum": [
        "sha256",
        "sha384",
        "sha512"
      ]
    }
  },
  "required": [
    "data"
  ]
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "data": {},
    "algorithm": {
      "type": "string"
    }
  },
  "required": [
    "data"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "hash": {
      "type": "string"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Hash",
    "description": "Hashed string",
    "is_default": true,
    "supports_condition": true
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Hash failed",
    "is_default": false,
    "supports_condition": false
  }
]
```
