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).
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...
}