API reference@evolu/commonType › createIdFromString

function createIdFromString<B>(
  value: string,
  ..._validation: IdBrandValidation<B>
): CreatedId<B>;

Defined in: packages/common/src/Type.ts:5973

Deterministically creates an Id from the first 16 SHA-256 bytes.

Use this to map an external identifier consistently on every client. The operation is not reversible; store the original identifier separately when it must be retained.

Example

import {
  assertEqual,
  assertType,
  createIdFromString,
  type Brand,
  type Id,
} from "@evolu/common";

const first = createIdFromString("external-user-123");
const second = createIdFromString("external-user-123");
const todoId = createIdFromString<"Todo">("external-todo-456");

assertEqual(first, second);
assertType<Id & Brand<"Todo">, typeof todoId>();