@nktkas/hyperliquid
Version:
Hyperliquid API SDK for all major JS runtimes, written in TypeScript.
33 lines (32 loc) • 1.18 kB
TypeScript
/**
* Schema-driven key canonicalization for Hyperliquid action objects.
* @module
*/
/// <amd-module name="file:///home/runner/work/hyperliquid/hyperliquid/src/signing/_canonicalize.ts" />
import type { GenericSchema } from "valibot";
import { HyperliquidError } from "../_base.js";
/** Thrown when canonicalization fails due to schema/data key mismatch. */
export declare class CanonicalizeError extends HyperliquidError {
constructor(message: string);
}
/**
* Recursively rebuilds a value with object keys in schema-definition order.
*
* @param schema A valibot schema defining the canonical key order.
* @param value The value whose keys should be reordered.
* @return A new value with keys in schema-definition order.
*
* @throws {CanonicalizeError} If keys in data don't match the schema.
*
* @example
* ```ts
* import { canonicalize } from "@nktkas/hyperliquid/signing";
* import { CancelRequest } from "@nktkas/hyperliquid/api/exchange";
*
* const action = canonicalize(CancelRequest.entries.action, {
* type: "cancel",
* cancels: [{ a: 0, o: 12345 }],
* });
* ```
*/
export declare function canonicalize<T>(schema: GenericSchema, value: T): T;