A Rust/Soroban escrow contract + a thin TypeScript SDK. This repo is
deliberately generic — no healthcare domain logic, no dependency on the
other two repos in the DocForum org. This guide is for humans picking
up a scoped issue — if you're an AI coding agent, read `AGENTS.md'
instead.
Requires a Rust toolchain with the wasm32v1-none target.
git clone https://github.com/DocForum/docforum-escrow.git
cd docforum-escrow/contracts/escrow
cargo test
# Build the deployable contract
cargo build --target wasm32v1-none --release
# → target/wasm32v1-none/release/docforum_escrow.wasmThe stellar CLI is needed to deploy to testnet yourself (see
docs/testnet-deployments.md for the existing deployment) and to
regenerate the SDK's generated bindings
(scripts/check-generated-bindings.sh). It is not required just to build
and test the contract; pin the version in scripts/stellar-cli-version
when you do need it.
The TypeScript SDK lives in sdk/. Install its dependencies and run its
checks with:
cd sdk
npm ci
npm run typecheck
npm run build
npm run test:offline # no network: event fixtures + quorum input validation
npm test # also runs the live-testnet suite — see belownpm test includes tests/testnet-integration.test.ts, which funds accounts
through Friendbot and talks to the live testnet contract. CI deliberately runs
only offline checks (test:offline, test:runtime, browser smoke) for the SDK;
run npm test locally when your change touches network calls, and expect it to
need a testnet deployment that actually has the methods you're testing.
The SDK is published to npm as @docforum/escrow-sdk via an automated,
provenance-signed release workflow — see Releasing the SDK
below. The GitHub Release tarball is still attached for existing consumers.
An HTML API reference is generated from the SDK's doc comments with
npm run docs in sdk/ (TypeDoc, config in sdk/typedoc.json). It also acts
as a missing-doc lint: every exported symbol must have a doc comment, or the
command fails — so document new exports as you add them. CI builds the
reference on every PR and publishes it to GitHub Pages from main
(.github/workflows/docs.yml); enabling Pages is a one-time maintainer step,
documented in that workflow. Runnable examples live in sdk/examples/
(from sdk/: npm run build && node examples/<flow>.ts) and run against
testnet with runtime-generated, Friendbot-funded keys — never a committed
secret; CI type-checks them (npm run typecheck:examples) but does not run
them.
Open issues are scoped, real, and tagged with a complexity/point value (Trivial/100, Medium/150, High/200) in the issue body — see the issue list. Comment on an issue to claim it before starting, and check it's still open.
ROADMAP.md shows the bigger picture: E1–E3 are done (E2/E4 verified live on testnet), E4's independent security review is still open and blocking for any mainnet use, and E5/E7 are the active contract-feature and verification/release-engineering tracks.
- Tests are required in the same PR as the logic, not a follow-up — see
AGENTS.mdhard rule 2.release/refundin particular need tests covering unauthorized-caller and double-release/refund attempts, not just the happy path — this is a funds-moving contract. - If your change starts, completes, or blocks a roadmap-tracked item,
tick or update that item's line in
ROADMAP.mdand add a changelog entry as a new file inchangelog.d/, in the same PR. Don't append to the end ofROADMAP.md; that is what made every PR conflict. Seechangelog.d/README.md. - Don't add new lines to
ROADMAP.md,ARCHITECTURE_ESSENTIALS.md,README.mdordocs/threat-model.md. Put new items, rows, paragraphs and sections in a fragment underdocs.d/that names the doc and the heading (or line) they go under; a maintainer folds them in. Editing existing lines in place is fine. CI enforces this. Seedocs.d/README.md. - If you change the contract (
contracts/escrow/src/), add a fragment undercontract-changes.d/with the bump level and a one-line summary. Don't editCONTRACT_VERSION: a maintainer bumps it once per batch. NewErrorvariants use a provisional code (your issue number × 100 + n); never renumber or remove an existing one. CI checks all three. Seecontract-changes.d/README.md. - Changes to escrow lifecycle semantics must also update the TLA+
specification under
spec/and rerun TLC. That includes changes to settlement auth, status transitions, timeouts, payee acceptance, release/refund rules, or quorum behavior. - Keep doc edits to your own lines: new lines go in
docs.d/, and don't rewrite other people's paragraphs. SeeAGENTS.md→ "Shared docs". - Run
cargo testandcargo build --target wasm32v1-none --releaselocally — this is exactly what CI checks. cargo testalso rewritescontracts/escrow/test_snapshots/. Review that diff (it shows events, auth entries and storage writes) and commit any intentional change with your PR — CI fails if the committed snapshots no longer match a test run. See Test snapshots below.- If you changed the contract's public surface, regenerate the SDK bindings and
run
./scripts/check-generated-bindings.sh. See Generated SDK bindings. - For SDK changes, run
npm run typecheck && npm run buildinsdk/, plusnpm run test:integrationwhen the change touches network calls. - Any change to the SDK's public surface is a contract change and needs
tests and a
changesetentry (see Releasing the SDK). Strict semver applies to the SDK. - If your change touches a file listed as in scope in
docs/audit/README.md, say so in the PR so it can get a delta review instead of silently changing the reviewed surface.
The Soroban test environment writes one snapshot per test to
contracts/escrow/test_snapshots/<test-name>.<n>.json when the Env is
dropped, and those files are committed (issue #120). They make "this PR changed
which events are emitted" or "the storage layout moved" a visible diff instead
of something a reviewer has to infer from the code.
- Update them intentionally: run
cargo test, inspectgit diff contracts/escrow/test_snapshots/, and commit the change with an explanation in the PR. Never hand-edit a snapshot; regenerate by running the test. - Never delete a snapshot to make CI pass. If a test stops producing a snapshot, that usually means it no longer touches storage/events — check why.
- Event capture caveat: the SDK clears the event buffer at the start of every
top-level contract invocation, so a snapshot only contains the events of the
test's last call. A test that ends with a read (
get_status, a tokenbalancecall, ...) therefore records no events.tests/top_up.rs'stop_up_emits_an_eventdeliberately ends on the emitting call so the event path stays visible in a diff. - Snapshots must be deterministic: fresh keypairs come from the SDK's seeded
Address::generate, so a secondcargo testmust produce a byte-identical snapshot. CI's snapshot step catches both drift and nondeterminism.
sdk/src/generated/contract-client.ts is machine-generated from the compiled
WASM and must never be hand-edited (issue #121). After any change to
the contract's public functions, types or doc comments
(contracts/escrow/src/):
# Uses the Stellar CLI version pinned in scripts/stellar-cli-version.
./scripts/check-generated-bindings.sh # prints the regeneration command on driftThe sdk-bindings CI job rewrites nothing: it fails and tells you to
regenerate. Full steps live in sdk/src/generated/README.md. A regenerated
binding that changes the SDK's public surface is also a semver bump
(hard rule 3) and needs a changeset.
- Branch off
main. - Reference the issue you're closing (
Closes #N). - State what changed, why, and which
ROADMAP.mdItem it maps to. - CI (
cargo test+ wasm release build, plus SDK typecheck/build/test) must pass before merge — it runs automatically on your PR.
The SDK is released by pushing an sdk-v* tag (e.g. sdk-v0.5.0).
The release workflow (.github/workflows/release-sdk.yml) then
- installs dependencies and runs
typecheck + build + testfor the SDK, - refuses to publish if the tag version does not match
sdk/package.json, - publishes to npm with
provenancevia npm trusted publishing (OIDC — no long-lived token in secrets), and - attaches the
npm packtarball to the GitHub Release for existing consumers.
Version bumps and changelogs are managed with changesets. Add a changeset file with every SDK change:
npx changeset addCommit the generated .changeset/*.md file with your PR. Release managers
run npx changeset version to bump sdk/package.json and update
sdk/CHANGELOG.md, then tag the resulting commit.
Before the first automated release, a maintainer must do the following once:
- Create (or join) the
docforumnpm org and ensure the@docforumscope is available. - Configure npm trusted publishing for the
@docforum/escrow-sdkpackage, pointing at this repository and the release workflow file. Trusted publishing uses GitHub Actions OIDC (id-token: write) and requires no long-lived npm token. - If trusted publishing is not yet available for the org, fall back to
a granular automation token stored as the
NPM_TOKENrepository secret (bypass 2fa) and remove it once trusted publishing is enabled. - Enable branch protection so only maintainers can push
sdk-v*tags.
The release process itself is documented in docs/adr/0005 (npm publishing),
which supersedes ADR 0003 (tarball-only releases). Note: that ADR file is
referenced by ROADMAP.md Phase E6 but is not present in this tree.
docs/audit/ holds what an independent reviewer needs: the reviewed commit,
the files in and out of scope, and reproducible test and build results.
SECURITY.md is the reporting path; the threat model is
docs/threat-model.md.
What this means for contributors:
- Report privately. A suspected vulnerability goes through
SECURITY.md, never a public issue or PR. Do not describe it indocs/audit/, in a test name, or in a commit message; reference the private advisory ID instead. - Respect the reviewed scope.
docs/audit/README.mdnames the commit under review and the in-scope files. A change to one of those files after the freeze needs a delta note indocs/audit/(a newdelta-<n>.md), not an edit to the frozen documents. - Keep the threat model current. If you change contract behaviour that
the threat model covers, update
docs/threat-model.mdin the same PR. Planned-but-unimplemented features belong in its "planned" section, marked as such — do not describe them as current behaviour.
Use the bug report template, not a comment on an unrelated issue — keeps scope and Wave points honest.