plugins/compact-core/skills/standard-library/SKILL.md
Use when importing from CompactStandardLibrary, working with crypto functions (persistentHash, persistentCommit, ecAdd, ecMul), utility types (Maybe, Either), token operations (mintToken, send, receive, mergeCoin), or time functions (blockTime, blockTimeBefore, blockTimeAfter).
npx skillsauth add aaronbassett/midnight-knowledgebase compact-core:standard-libraryInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
4 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Complete reference for CompactStandardLibrary - the built-in module providing cryptographic functions, utility types, token operations, and time functions.
import { persistentHash, Maybe, mintToken, blockTime } from "CompactStandardLibrary";
| Function | Safe? | Purpose |
|----------|-------|---------|
| persistentCommit(value) | Yes | Create hiding commitment with nonce (cross-transaction stable) |
| transientCommit(value) | Yes | Create hiding commitment with nonce (transaction-local) |
| persistentHash(domain, value) | No | Domain-separated hash (cross-transaction stable) |
| transientHash(domain, value) | No | Domain-separated hash (transaction-local) |
| ecAdd(p1, p2) | - | Elliptic curve point addition |
| ecMul(scalar, point) | - | Elliptic curve scalar multiplication |
Safe vs Unsafe: Commit functions include a random nonce, making them hiding. Hash functions do not include a nonce - if the input has low entropy, the hash can be brute-forced.
| Type | Purpose | Variants |
|------|---------|----------|
| Maybe<T> | Optional value | Some(T), None |
| Either<L, R> | Result/choice | Left(L), Right(R) |
| Function | Purpose |
|----------|---------|
| mintToken(info) | Create new tokens |
| send(coin, recipient) | Send tokens to address |
| receive() | Receive tokens in circuit |
| mergeCoin(coins) | Combine multiple coins |
| Function | Purpose |
|----------|---------|
| blockTime() | Current block timestamp |
| blockTimeBefore(time) | Assert current time < time |
| blockTimeAfter(time) | Assert current time > time |
import { persistentCommit } from "CompactStandardLibrary";
witness get_secret(): Field;
export circuit commit_secret(): Bytes<32> {
const secret = get_secret();
// Safe: commitment hides the secret
return persistentCommit(secret);
}
import { persistentHash } from "CompactStandardLibrary";
witness get_secret(): Field;
export circuit generate_nullifier(): Bytes<32> {
const secret = get_secret();
// Unsafe but intentional: nullifier should be deterministic
return persistentHash("nullifier", secret);
}
import { Maybe } from "CompactStandardLibrary";
ledger values: Map<Bytes<32>, Field>;
export circuit get_or_default(key: Bytes<32>): Field {
const result = values.lookup(key);
return if result is Maybe::Some(v) { v } else { 0 };
}
import { blockTime, blockTimeAfter } from "CompactStandardLibrary";
ledger unlock_time: Cell<Uint<64>>;
export circuit withdraw(): [] {
// Fails if current block time <= unlock_time
blockTimeAfter(unlock_time.read());
// Perform withdrawal...
}
tools
Use when setting up Midnight development environment, installing Compact compiler and developer tools, configuring proof server, verifying prerequisites, or getting started with Midnight development.
tools
--- name: midnight-tooling:midnight-debugging description: Use when encountering Midnight errors like "compact: command not found", "ERR_UNSUPPORTED_DIR_IMPORT", version mismatches, proof server failures, "@midnight-ntwrk" package errors, or compilation failures. --- # Midnight Environment Debugging Expert knowledge for identifying and resolving common Midnight development toolchain issues. ## Diagnostic Approach When encountering Midnight-related errors, follow this systematic approach: 1.
tools
Use when checking Midnight version compatibility, understanding pragma language_version, verifying compiler and runtime version relationships, or troubleshooting version mismatch errors between Midnight components.
tools
Use when setting up CI/CD for Midnight projects, configuring GitHub Actions for Compact contract compilation, running TypeScript tests in CI, validating version consistency, or automating contract builds.