@arcium-hq/clientFunctions
createPacker
createPacker<
TInput,TOutput,TFields>(fields,typeName?):Packer<TInput,TOutput>
Create a type-safe packer from field definitions.
Use as const on the fields array to enable compile-time field name validation.
Type Parameters
| Type Parameter | Default type |
|---|---|
TInput extends Record<string, unknown> | - |
TOutput extends Record<string, unknown> | - |
TFields extends readonly FieldInfo[] | readonly FieldInfo[] |
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
fields | TFields & ValidateFieldNames<TInput, TFields> | undefined | Array of FieldInfo objects defining each field's name and type. |
typeName | string | 'Packer' | Optional name for debugging (default: 'Packer'). |
Returns
Packer<TInput, TOutput>
Packer instance with pack() and unpack() methods.
Throws
TypeError if field types don't match expected values during pack/unpack.
Throws
RangeError if array index is out of bounds.
Example
import { createPacker } from '@arcium-hq/client';
// Define fields matching your circuit's input type
const fields = [
{ name: 'a', type: { Integer: { signed: false, width: 32 } } },
{ name: 'b', type: { Integer: { signed: false, width: 32 } } },
] as const;
// Create packer with explicit input/output types
const packer = createPacker<{ a: number; b: number }, { a: bigint; b: bigint }>(fields);
// Pack values for circuit input
const packed = packer.pack({ a: 10, b: 20 });
// Unpack circuit output (from decrypted computation result)
const result = packer.unpack(decryptedOutput);