Components
Every internal package of wallet-api in detail: onchain, multisig, trading, walletapi, the HTTP APIs, the durable job queue, and the MPC layer.
wallet-api is a single Go binary composed of internal packages behind clean interfaces. This is what each one does.
On-chain core
| Package | Role |
|---|---|
internal/onchain | The ERC-3643 / T-REX deployer + identity + venue-gate backbone. Self-deploys the shared infra (backbone, factory, USDL, TokenSettlement) lazily via get-or-deploy, and owns EnsureVerified (ONCHAINID + IdentityRegistry), chain reads, and the KV state. |
internal/multisig | The V42 threshold-multisig wallet factory flow. CreateWallet deploys a per-user V42 clone around the user's MPC address, provisions its executor + guardian, funds it for gas, and (strict guard) verifies the signer's identity first. |
internal/trading | Asset lifecycle (create / mint / burn / freeze / forced-transfer / transfer), the dual-intent propose + settle trade path, chain-read views, and the pluggable stores (asset registry, holdings, country/wallet lookup, order-nonce, settle-record). |
HTTP surfaces
| Package | Endpoints |
|---|---|
internal/walletapi | Wallet provisioning (POST /wallet), server-side sign, and the MPC relays: GET /wallet/mpc-config plus the WebSockets /wallet/mpc/relay (keygen) and /wallet/mpc/sign (signing). Both sockets are mounted by RegisterWS outside the request-timeout group - the timeout wrapper breaks the Hijack an upgrade needs, and a ceremony outlives any request timeout. |
internal/assetapi | Asset create/mint/burn/accredit, deposit (USDL), issuer ops (freeze / forced-transfer / transfer), identity register/deregister/verify, and the balance/frozen reads. |
internal/tradeapi | POST /trade/propose + /trade/propose-tx (build the unsigned vouch), /trade/cancel-tx, POST /settlement/settle (+ status by trade_id), GET /contracts, and the standing-allowance approve flow. |
internal/chainapi | Generic chain reads for consumers: GET /chain/head, /chain/block/{n}/hash, POST /chain/logs, GET /chain/tx/{hash}/receipt. |
internal/rawcallapi | Per-role raw-call escape hatches: POST /wallets/{wallet}/{user,executor,guardian,read}-call, POST /settlement/{admin,executor,user,read}-call, POST /regimes/{admin,read}-call, and GET /capabilities (the signer-lane boundary map). The caller ABI-encodes the calldata; this surface enforces which key signs, the submit/wait semantics, and an optional exact-selector allowlist. Synchronous, and must sit behind auth. |
Durable job queue
internal/jobs - a Postgres-backed durable queue. Write endpoints enqueue
and return 202 { job_id }; workers execute, retry with backoff, dead-letter,
reap crashed leases, and POST the result to callback_url.
- Lanes:
admin(concurrency 1 - the ta-admin nonce is serial) anduser(parallel across wallets). - Lease: atomic claim of the oldest runnable job in a lane via
UPDATE ... WHERE id = (SELECT ... FOR UPDATE SKIP LOCKED LIMIT 1). - Reap: jobs whose
locked_untilhas passed (a crashed worker) return topending.
MPC & signing layer
| File / package | Role |
|---|---|
pkg/mpc/signer.go · hashsigner.go | The signer seam: Signer / HashSigner interfaces every caller depends on, so the backing key store swaps without touching business logic. |
pkg/mpc/devsigner.go · devkeygen.go | Dev-only in-process keys, clearly labelled and never valid in production config. |
pkg/mpc/httpsigner.go | Generic HTTP signing backend. |
pkg/mpc/hub.go · keygen.go · mpciumsigner.go | Engine mode: MpciumHub (one result subscription per process, fanned out by WalletID / TxID), MpciumKeygen (DKG + authorizer-signature gate), MpciumSigner. |
pkg/mpc/hsmsigner.go · hsmgen.go | The HSM keystore seam for platform keys: digest-mode POST /sign by label id, and POST /generate-address?curve=secp256k1 to provision per-wallet executor keys (persist the returned label). |
pkg/mpc/node3token.go | Mints the short-lived HS256 token that authorizes one party against node3. |
internal/walletapi/relay.go | The node3 relay: dials node3 before upgrading the device socket (so a dial failure is a clean HTTP error), strips the caller's own token/api_key, injects the node3 credential, and pipes frames both ways without decoding them. |
See mpc for how these fit together at runtime.
Platform & infra packages
| Package | Role |
|---|---|
pkg/postgres | Pool(ctx, url) (pgxpool) + Migrate(ctx, url) (goose over embedded //go:embed migrations/*.sql). |
pkg/config | Typed WALLET_* env config with dev defaults. |
pkg/chain | go-ethereum client helpers (dial, reads, receipts). |
pkg/substrate | The substrate gas-sponsor client (sponsor mode - the sponsor pays user trade gas so the user wallet can hold zero). |
pkg/observability | slog JSON logging + Prometheus metrics. |
Store interfaces (why swapping the DB was clean)
The business logic depends only on interfaces, implemented once against Postgres:
onchain.KV, walletapi.WalletStore + SignerResolver,
trading.{AssetRegistry, HoldingsStore, CountryLookup, WalletLookup, ExecutorResolver},
and jobs.Enqueuer. Replacing the persistence layer (Mongo -> Postgres) touched
only the implementations and boot wiring, not the domain code.