compact-core:compact-witness-ts

Implement TypeScript witness functions for Compact contracts with type mappings.

37|9|Updated Feb 25, 2026
One-click install
npx skills add https://github.com/devrelaicom/midnight-expert --skill compact-core-compact-witness-ts
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: compact-core:compact-witness-ts
Source: https://github.com/devrelaicom/midnight-expert/tree/main/plugins/compact-core/skills/compact-witness-ts
Command: npx skills add https://github.com/devrelaicom/midnight-expert --skill compact-core-compact-witness-ts

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Helps developers implement the TypeScript half of Compact contracts by explaining compiler-generated types, the WitnessContext pattern, private state design, Compact-to-TypeScript type mappings, and how to bind witnesses to the Contract runtime so implementations type-check and interoperate with on-chain contracts.

Core Features & Use Cases

  • Type mapping and runtime validation: clear mapping of Compact primitives and ADTs to TypeScript types and notes about runtime bounds and length checks.
  • Witness implementation patterns: canonical WitnessContext usage, the [PrivateState, ReturnValue] tuple pattern, state-mutating and side-effect witnesses, ledger-reading witnesses, and contract-address keyed state scoping.
  • Contract runtime & verification: guidance for using the generated Contract class, pureCircuits vs impureCircuits, ledger parsing, and mechanical verification to ensure witness implementations match compiled interfaces.
  • Use Case: implement a local_secret_key witness that reads a 32-byte secret from private state, bind it to the compiled Contract, and run verification before deploying.

Quick Start

Implement a TypeScript witnesses file for mycontract that returns a 32-byte Uint8Array secret from private state, bind it to the generated Contract class, and verify the implementation against the compiled types.

Frequently Asked Questions about compact-core:compact-witness-ts

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement Compact witnesses in TypeScript?

To implement Compact witnesses in TypeScript, you must enforce WitnessContext as the first parameter and return a [PrivateState, ReturnValue] tuple. This ensures your implementation type-checks against compiler-generated managed contract APIs.

How does Compact type mapping work when generating TypeScript types?

Compact type mapping translates Compact primitives and ADTs into TypeScript equivalents while enforcing runtime bounds and length checks. This ensures your TypeScript witness functions remain compatible with generated ledger and contract type declarations.

What is the WitnessContext pattern for private state in Compact contracts?

The WitnessContext pattern for private state requires passing WitnessContext as the first parameter to your TypeScript witness function. It enables contract-address keyed state scoping and allows witnesses to read or mutate private state during DApp integration.

How do I verify TypeScript witness implementations against compiled Compact contracts?

To verify TypeScript witness implementations against compiled Compact contracts, bind your witness functions to the generated Contract class and run mechanical verification. This validates compatibility with pureCircuits, impureCircuits, and ledger type declarations before deployment.

How do I write a private state factory for a Compact witness?

Writing a private state factory for a Compact witness involves returning a [PrivateState, ReturnValue] tuple from your TypeScript function. You can implement patterns like a local_secret_key witness that reads a 32-byte Uint8Array secret from private state.

When should I use pureCircuits versus impureCircuits in Compact testing?

Use pureCircuits versus impureCircuits in Compact testing based on side-effect requirements when invoking generated contract APIs. The Skill provides guidance on distinguishing these circuits to ensure proper ledger parsing and runtime verification during DApp integration.