> ## Documentation Index
> Fetch the complete documentation index at: https://docs.revoengine.com/llms.txt
> Use this file to discover all available pages before exploring further.

# util reference

> Validation, timing, identifiers, encoding, hashing, signatures, JWT, and crypto helpers.

<Note>
  Generated from the same public contract that feeds the Monaco editor. Declaration-marked deprecated compatibility methods are intentionally excluded. Do not edit this page manually.
</Note>

This page contains **33 methods**. Search the docs for an exact method name, or use this index:

* [`util.sleep()`](#util-sleep)
* [`util.aesDecrypt()`](#util-aesDecrypt)
* [`util.aesEncrypt()`](#util-aesEncrypt)
* [`util.compareHash()`](#util-compareHash)
* [`util.isBase64()`](#util-isBase64)
* [`util.decodeBase64()`](#util-decodeBase64)
* [`util.encodeBase64()`](#util-encodeBase64)
* [`util.generateHash()`](#util-generateHash)
* [`util.isUUID()`](#util-isUUID)
* [`util.randomUUID()`](#util-randomUUID)
* [`util.getUUID()`](#util-getUUID)
* [`util.hashObject()`](#util-hashObject)
* [`util.sha1()`](#util-sha1)
* [`util.sha256()`](#util-sha256)
* [`util.md5()`](#util-md5)
* [`util.timingSafeEqual()`](#util-timingSafeEqual)
* [`util.hmac()`](#util-hmac)
* [`util.verifyHmacSignature()`](#util-verifyHmacSignature)
* [`util.base64UrlEncode()`](#util-base64UrlEncode)
* [`util.base64UrlDecode()`](#util-base64UrlDecode)
* [`util.randomBytes()`](#util-randomBytes)
* [`util.randomInt()`](#util-randomInt)
* [`util.randomString()`](#util-randomString)
* [`util.otp()`](#util-otp)
* [`util.validate()`](#util-validate)
* [`util.jwtDecode()`](#util-jwtDecode)
* [`util.jwtSign()`](#util-jwtSign)
* [`util.jwtVerify()`](#util-jwtVerify)
* [`util.rsaDecrypt()`](#util-rsaDecrypt)
* [`util.rsaEncrypt()`](#util-rsaEncrypt)
* [`util.rsaGeneratePair()`](#util-rsaGeneratePair)
* [`util.rsaSign()`](#util-rsaSign)
* [`util.rsaVerify()`](#util-rsaVerify)

<span id="util-sleep" aria-hidden="true" />

## `util.sleep()`

Waits asynchronously, capped at 60 seconds per call.

### Signature

```ts theme={null}
static sleep(ms: number): Promise<void>;
```

### Example

```ts theme={null}
await util.sleep(250);
```

<span id="util-aesDecrypt" aria-hidden="true" />

## `util.aesDecrypt()`

AES decrypt helper.

### Signature

```ts theme={null}
static aesDecrypt(encrypted: string, passphrase: string): string;
```

### Example

```ts theme={null}
const plain = util.aesDecrypt(encrypted, passphrase);
```

<span id="util-aesEncrypt" aria-hidden="true" />

## `util.aesEncrypt()`

AES encrypt helper.

### Signature

```ts theme={null}
static aesEncrypt(payload: string, passphrase: string): string;
```

### Example

```ts theme={null}
const encrypted = util.aesEncrypt('secret', passphrase);
```

<span id="util-compareHash" aria-hidden="true" />

## `util.compareHash()`

Compares a value against a password hash.

### Signature

```ts theme={null}
static compareHash(
      password: string | undefined,
      hash: string | undefined,
    ): Promise<boolean>;
```

### Example

```ts theme={null}
const valid = await util.compareHash(password, hash);
```

<span id="util-isBase64" aria-hidden="true" />

## `util.isBase64()`

Checks whether a value is base64.

### Signature

```ts theme={null}
static isBase64(input: any): boolean;
```

### Example

```ts theme={null}
const ok = util.isBase64(value);
```

<span id="util-decodeBase64" aria-hidden="true" />

## `util.decodeBase64()`

Decodes a base64 string.

### Signature

```ts theme={null}
static decodeBase64(base64String: string): string;
```

### Example

```ts theme={null}
const text = util.decodeBase64(base64String);
```

<span id="util-encodeBase64" aria-hidden="true" />

## `util.encodeBase64()`

Encodes a string to base64.

### Signature

```ts theme={null}
static encodeBase64(plainString: string): string;
```

### Example

```ts theme={null}
const encoded = util.encodeBase64('hello');
```

<span id="util-generateHash" aria-hidden="true" />

## `util.generateHash()`

Generates a password hash.

### Signature

```ts theme={null}
static generateHash(
      password: string | undefined,
      rounds?: number,
    ): Promise<string>;
```

### Example

```ts theme={null}
const hash = await util.generateHash(password, 10);
```

<span id="util-isUUID" aria-hidden="true" />

## `util.isUUID()`

Validates UUID shape.

### Signature

```ts theme={null}
static isUUID(input: any): boolean;
```

### Example

```ts theme={null}
const ok = util.isUUID(value);
```

<span id="util-randomUUID" aria-hidden="true" />

## `util.randomUUID()`

Generates a random UUIDv7.

### Signature

```ts theme={null}
static randomUUID(): string;
```

### Example

```ts theme={null}
const id = util.randomUUID();
```

<span id="util-getUUID" aria-hidden="true" />

## `util.getUUID()`

Returns a random UUIDv7 with no arguments, or a deterministic UUIDv5 only when
both value and namespace are supplied. Do not generate IDs for server-created
platform resources; use this only for caller-owned data values.

### Signature

```ts theme={null}
static getUUID(...args: [] | [value: string, namespace: string]): string;
```

### Example

```ts theme={null}
const id = util.getUUID('customer-1', 'customers');
```

<span id="util-hashObject" aria-hidden="true" />

## `util.hashObject()`

Creates a stable hash from an object.

### Signature

```ts theme={null}
static hashObject(object: any): string;
```

### Example

```ts theme={null}
const hash = util.hashObject({ customerId: 'c-1' });
```

<span id="util-sha1" aria-hidden="true" />

## `util.sha1()`

SHA-1 hash helper.

### Signature

```ts theme={null}
static sha1(payload: string): string;
```

### Example

```ts theme={null}
const digest = util.sha1('payload');
```

<span id="util-sha256" aria-hidden="true" />

## `util.sha256()`

SHA-256 hash helper.

### Signature

```ts theme={null}
static sha256(payload: string): string;
```

### Example

```ts theme={null}
const digest = util.sha256('payload');
```

<span id="util-md5" aria-hidden="true" />

## `util.md5()`

MD5 hash helper.

### Signature

```ts theme={null}
static md5(payload: string): string;
```

### Example

```ts theme={null}
const digest = util.md5('payload');
```

<span id="util-timingSafeEqual" aria-hidden="true" />

## `util.timingSafeEqual()`

Performs a timing-safe comparison.

### Signature

```ts theme={null}
static timingSafeEqual(a: string | Buffer, b: string | Buffer): boolean;
```

### Example

```ts theme={null}
const match = util.timingSafeEqual(a, b);
```

<span id="util-hmac" aria-hidden="true" />

## `util.hmac()`

Creates an HMAC signature.

### Signature

```ts theme={null}
static hmac(
      payload: Uint8Array | string,
      secret: string,
      algorithm?: 'sha1' | 'sha256' | 'sha512',
      encoding?: 'hex' | 'base64',
    ): string;
```

### Example

```ts theme={null}
const signature = util.hmac('payload', secret, 'sha256', 'hex');
```

<span id="util-verifyHmacSignature" aria-hidden="true" />

## `util.verifyHmacSignature()`

Verifies an HMAC signature.

### Signature

```ts theme={null}
static verifyHmacSignature(
      payload: Uint8Array | string,
      signature: string,
      secret: string,
      algorithm?: 'sha1' | 'sha256' | 'sha512',
      encoding?: 'hex' | 'base64',
    ): boolean;
```

### Example

```ts theme={null}
const ok = util.verifyHmacSignature('payload', signature, secret);
```

<span id="util-base64UrlEncode" aria-hidden="true" />

## `util.base64UrlEncode()`

Encodes base64url.

### Signature

```ts theme={null}
static base64UrlEncode(input: Uint8Array | string): string;
```

### Example

```ts theme={null}
const encoded = util.base64UrlEncode('payload');
```

<span id="util-base64UrlDecode" aria-hidden="true" />

## `util.base64UrlDecode()`

Decodes base64url.

### Signature

```ts theme={null}
static base64UrlDecode(input: string): Uint8Array;
```

### Example

```ts theme={null}
const decoded = util.base64UrlDecode(tokenPart);
```

<span id="util-randomBytes" aria-hidden="true" />

## `util.randomBytes()`

Generates random bytes as a string.

### Signature

```ts theme={null}
static randomBytes(size?: number, encoding?: 'hex' | 'base64'): string;
```

### Example

```ts theme={null}
const bytes = util.randomBytes(16, 'hex');
```

<span id="util-randomInt" aria-hidden="true" />

## `util.randomInt()`

Generates a random integer.

### Signature

```ts theme={null}
static randomInt(min?: number, max?: number): number;
```

### Example

```ts theme={null}
const n = util.randomInt(1000, 9999);
```

<span id="util-randomString" aria-hidden="true" />

## `util.randomString()`

Generates a random string.

### Signature

```ts theme={null}
static randomString(length?: number, alphabet?: string): string;
```

### Example

```ts theme={null}
const token = util.randomString(24);
```

<span id="util-otp" aria-hidden="true" />

## `util.otp()`

Generates a numeric one-time code.

### Signature

```ts theme={null}
static otp(length?: number): string;
```

### Example

```ts theme={null}
const code = util.otp(6);
```

<span id="util-validate" aria-hidden="true" />

## `util.validate()`

Validates a payload with the platform schema validator used by Endpoints.

Notes:

* When 'whitelist' is false and 'whitelistErrors' is false, unknown properties are removed from the returned value.

### Signature

```ts theme={null}
static validate(
      payload: any,
      schema: ValidatorSchemaInput,
    ): ValidationResult<any>;
```

### Example

```ts theme={null}
const result = util.validate(
  api.input()?.body,
  {
    whitelist: false,
    whitelistErrors: false,
    schema: {
      type: 'object',
      required: true,
      objectSchema: [
        { property: 'email', schema: { type: 'string', required: true } },
      ],
    },
  },
);
```

<span id="util-jwtDecode" aria-hidden="true" />

## `util.jwtDecode()`

Decodes a JWT without verifying it.

### Signature

```ts theme={null}
static jwtDecode(
      token: string,
      options?: { complete?: boolean; json?: boolean },
    ): any;
```

### Example

```ts theme={null}
const payload = util.jwtDecode(token);
```

<span id="util-jwtSign" aria-hidden="true" />

## `util.jwtSign()`

Signs a JWT.

### Signature

```ts theme={null}
static jwtSign(
      payload: string | object,
      secret: string | { key: string; passphrase: string },
      options?: {
        algorithm?:
          | 'HS256'
          | 'HS384'
          | 'HS512'
          | 'RS256'
          | 'RS384'
          | 'RS512'
          | 'ES256'
          | 'ES384'
          | 'ES512'
          | 'PS256'
          | 'PS384'
          | 'PS512'
          | 'none';
        keyid?: string;
        expiresIn?: string | number;
        notBefore?: string | number;
        audience?: string | string[];
        subject?: string;
        issuer?: string;
        jwtid?: string;
        mutatePayload?: boolean;
        noTimestamp?: boolean;
        header?: JWTHeader;
        encoding?: string;
        allowInsecureKeySizes?: boolean;
        allowInvalidAsymmetricKeyTypes?: boolean;
      },
    ): string;
```

### Example

```ts theme={null}
const token = util.jwtSign(
  { sub: 'c-1' },
  secret,
  { expiresIn: '1h' },
);
```

<span id="util-jwtVerify" aria-hidden="true" />

## `util.jwtVerify()`

Verifies a JWT.

### Signature

```ts theme={null}
static jwtVerify(
      token: string,
      secret: string | { key: string; passphrase: string },
      options?: {
        algorithms?: (
          | 'HS256'
          | 'HS384'
          | 'HS512'
          | 'RS256'
          | 'RS384'
          | 'RS512'
          | 'ES256'
          | 'ES384'
          | 'ES512'
          | 'PS256'
          | 'PS384'
          | 'PS512'
          | 'none'
        )[];
        audience?: string | RegExp | Array<string | RegExp>;
        clockTimestamp?: number;
        clockTolerance?: number;
        complete?: boolean;
        issuer?: string | string[];
        ignoreExpiration?: boolean;
        ignoreNotBefore?: boolean;
        jwtid?: string;
        nonce?: string;
        subject?: string;
        maxAge?: string | number;
        allowInvalidAsymmetricKeyTypes?: boolean;
      },
    ): any;
```

### Example

```ts theme={null}
const payload = util.jwtVerify(token, secret);
```

<span id="util-rsaDecrypt" aria-hidden="true" />

## `util.rsaDecrypt()`

Decrypts with RSA.

### Signature

```ts theme={null}
static rsaDecrypt(
      privateKey: string,
      payload: string,
      passphrase?: string,
    ): string;
```

### Example

```ts theme={null}
const plain = util.rsaDecrypt(privateKey, encrypted, passphrase);
```

<span id="util-rsaEncrypt" aria-hidden="true" />

## `util.rsaEncrypt()`

Encrypts with RSA.

### Signature

```ts theme={null}
static rsaEncrypt(publicKey: string, payload: string): string;
```

### Example

```ts theme={null}
const encrypted = util.rsaEncrypt(publicKey, 'hello');
```

<span id="util-rsaGeneratePair" aria-hidden="true" />

## `util.rsaGeneratePair()`

Generates an RSA key pair.

### Signature

```ts theme={null}
static rsaGeneratePair(config?: {
      modulusLength?: number;
      passphrase?: string;
    }): { publicKey: string; privateKey: string };
```

### Example

```ts theme={null}
const pair = util.rsaGeneratePair({ modulusLength: 2048 });
```

<span id="util-rsaSign" aria-hidden="true" />

## `util.rsaSign()`

Signs data with RSA.

### Signature

```ts theme={null}
static rsaSign(
      privateKey: string,
      payload: string,
      passphrase?: string,
    ): string;
```

### Example

```ts theme={null}
const signature = util.rsaSign(privateKey, 'hello', passphrase);
```

<span id="util-rsaVerify" aria-hidden="true" />

## `util.rsaVerify()`

Verifies an RSA signature.

### Signature

```ts theme={null}
static rsaVerify(
      publicKey: string,
      payload: string,
      signature: string,
    ): boolean;
```

### Example

```ts theme={null}
const ok = util.rsaVerify(publicKey, 'hello', signature);
```
