Skip to main content

Lambit Documentation

Lambit is a functional TypeScript to Bitcoin Script compiler. Contracts are authored as pure TypeScript expression trees, then compiled into artifact-style JSON with ABI and locking script output.

Start Here​

What Lambit provides​

AreaSummary
DSLUnified named contract() overloads plus explicit method(schema, fn) declarations.
ExpressionsTyped combinators for logic, arithmetic, bytes, crypto, and build-time array transforms.
CompilerStack compilation, state lowering, and artifact assembly into JSON v10-compatible output.
TestsGolden fixtures, compiler tests, and docs example validation.

Quick example​

The standard P2PKH helper provides the byte-minimal address check plus signature check. Use pubKey2Addr(pubkey) when authoring custom P2PKH-style predicates; it documents address intent while lowering to the same OP_HASH160 script surface as hash160(pubkey).

import {
P2PKH,
} from '@opcat-labs/lambit';

const p2pkh = P2PKH({ addr: '00112233445566778899aabbccddeeff00112233' });
console.log(P2PKH.name); // P2PKH
console.log(p2pkh.artifact.hex); // 76a9<addr>88ac

Wrap the same predicate in assert(...) when you want assertion metadata at an explicit verify boundary.

import {
contract,
method,
TypeTag,
and,
assert,
eq,
pubKey2Addr,
checkSig,
} from '@opcat-labs/lambit';

const AssertP2PKH = contract(
'AssertP2PKH',
{ addr: TypeTag.Ripemd160 },
({ props }) => ({
unlock: method(
{ sig: TypeTag.Sig, pubkey: TypeTag.PubKey },
(sig, pubkey) => assert(and(eq(pubKey2Addr(pubkey), props.addr), checkSig(sig, pubkey))),
),
}),
);

const assertP2pkh = AssertP2PKH({ addr: '00112233445566778899aabbccddeeff00112233' });
console.log(assertP2pkh.artifact.hex); // 76a9<addr>88ac6951
note

The repository validates published TypeScript examples through docs tests so the public guide snippets stay aligned with the current API.

Repository​

What's Next​