Matrix logo

Financial Workflows - Receipts, vouchers, metering, channels, and storage

This slice of matrix-core turns payment and settlement into a set of tightly linked primitives: EIP-712 signing for quotes, receipts, and vouchers; deterministic hashing for rec...

Overview

This slice of matrix-core turns payment and settlement into a set of tightly linked primitives: EIP-712 signing for quotes, receipts, and vouchers; deterministic hashing for receipt batches; channel accounting for reserved and cumulative value; and Postgres-backed persistence for invocations, receipts, vouchers, deployments, and channel mirrors. The result is a workflow that can quote work, reserve spend, finalize delivery, and persist proof material without mixing those responsibilities into one layer.

The code is organized around three moving parts. deus/internal/receipts/* defines the hashing and signature material, deus/internal/channels/* manages caller-funded channels and co-signed vouchers, and deus/internal/metering/ledger.go records invocation lifecycle transitions while deus/internal/store/* writes the durable rows. These pieces are designed to be composed by higher-level invoke flows, but the financial correctness rules live here.

Settlement Flow

This flow shows the two settlement tracks that share the same persisted state. Invocation settlement reserves an entry, records the receipt, and finalizes or voids the row; channel settlement builds a pending voucher, verifies the caller signature, and commits the co-signed voucher with the channel update in one transaction.

Receipt Signing Primitives

deus/internal/receipts/eip712.go

deus/internal/receipts/eip712.go

This file defines the signer that creates and verifies EIP-712 material for quotes and receipts. It also provides the canonical payload hashing helper used by downstream code to derive stable digests from JSON objects.

Signer

PropertyTypeDescription
ChainIDint64Chain id used in the EIP-712 domain.
VerifyingContractcommon.AddressContract address included in the typed-data domain.
PrivateKey*ecdsa.PrivateKeySigning key used for quote and receipt signatures.

Constructor dependencies

TypeDescription
int64Chain id supplied to the signer.
stringRegistry or verifying-contract address parsed into common.Address.
stringHex-encoded private key parsed into an ECDSA key.

Methods

MethodDescription
NewSignerFromHexTrims the input key, parses it as hex, and builds a Signer with the supplied chain id and verifying-contract address.
GatewayAddressDerives the signer address from PrivateKey.
SignQuoteBuilds the DeusQuote typed data, hashes it, signs it, and returns the digest and signature as 0x-prefixed hex.
VerifyQuoteRecovers the signer from the quote digest and signature, then checks that it matches GatewayAddress.
SignReceiptBuilds the DeusReceipt typed data, hashes it, signs it, and returns the digest and signature as 0x-prefixed hex.
VoucherDigestBuilds the DeusVoucher typed data and returns its unsigned digest.
VerifyVoucherCallerRecovers the signer from the voucher digest and caller signature, then checks that it matches the caller wallet.

QuoteFields

PropertyTypeDescription
ServiceIDstringService identifier included in the signed quote.
EndpointIDstringEndpoint identifier included in the signed quote.
PricingVersionintPricing version encoded into the typed data.
UnitPriceWeistringUnit price represented as a decimal wei string.
MaxUnitsstringMaximum units represented as a decimal string.
CallerstringCaller identity included in the quote.
ExpiresAttime.TimeExpiry timestamp converted to Unix seconds in the signed payload.

ReceiptFields

PropertyTypeDescription
InvocationIDstringInvocation identifier bound into the receipt.
ServiceIDstringService identifier bound into the receipt.
CallerstringCaller identity bound into the receipt.
ArgsHashstringHash of the request arguments.
ResultHashstringHash of the returned result object.
PriceWeistringFinal charge encoded as a decimal wei string.
UnitsstringBilled units encoded as a decimal string.
OutcomestringOutcome string encoded into the receipt.
Timestamptime.TimeReceipt timestamp converted to Unix seconds in the signed payload.

Behavior

  • NewSignerFromHex strips surrounding whitespace and an optional 0x prefix before parsing the key.
  • SignQuote and SignReceipt both use the same EIP-712 domain pattern: EIP712Domain with name, version, chainId, and verifyingContract.
  • Both signing methods normalize the signature recovery byte into the 27 or 28 range before hex encoding.
  • VerifyQuote and VerifyVoucherCaller fail closed on signer mismatch.

Utility functions

FunctionDescription
RecoverSignerRecovers an Ethereum address from a digest and signature.
HashPayloadMarshals a value to JSON and returns the Keccak-256 hash as a 0x-prefixed hex string.
WeiStringFormats a *big.Int as a decimal wei string, returning "0" for nil.

deus/internal/receipts/voucher.go

HashPayload is the common digest builder used for arbitrary JSON objects, while SignQuote, SignReceipt, and VoucherDigest each wrap a typed EIP-712 message. That keeps quote, receipt, and voucher signatures structurally separate even though they all use the same signer.

deus/internal/receipts/voucher.go

This file defines the EIP-712 voucher shape used for caller co-signing and the caller verification step that checks whether a signature belongs to the expected wallet.

VoucherFields

PropertyTypeDescription
ChannelIDstringChannel identifier bound into the voucher.
CumulativeWeistringCumulative channel spend encoded as a decimal wei string.
Nonceuint64Monotonic voucher nonce.
LastReceiptHashstringReceipt digest linked to the voucher.

Behavior

  • VoucherDigest constructs a DeusVoucher typed-data payload and returns only the digest.
  • VerifyVoucherCaller recovers the signer from the voucher digest and caller signature, then compares the recovered address to callerWallet.
  • The digest includes the channel id, cumulative spend, nonce, and last receipt hash, so a voucher is bound to one channel state and one receipt chain position.

deus/internal/receipts/merkle.go

deus/internal/receipts/merkle.go

This file builds deterministic Merkle roots over receipt digests. It uses domain separation on both leaves and internal nodes so a raw receipt digest cannot be confused with a tree node hash.

MerkleRoot

FunctionDescription
MerkleRootDecodes each digest, domain-separates leaves, sorts the first layer, duplicates the trailing node on odd layers, and returns a 0x-prefixed root.

Supporting functions

  • hashLeaf prefixes each leaf with 0x00 before hashing.
  • hashNode prefixes each internal node with 0x01 before hashing.
  • decodeHash strips 0x or 0X, requires exactly 32 bytes, and rejects malformed digests.

Behavior

  • Empty input fails with receipts: empty merkle input.
  • The first layer is sorted, so the output is order-independent.
  • Odd layers are handled by duplicating the final node rather than promoting it.

Channel Voucher Lifecycle

deus/internal/channels/channels.go

deus/internal/channels/channels.go

This file manages caller-funded payment channels. It opens a new channel window, reserves and releases balance, finalizes cumulative charge state, and exposes the current open channel for a caller.

EscrowReader

MethodDescription
FundedWeiReturns the on-chain funded balance for an escrow address as a decimal wei string.

Service

PropertyTypeDescription
store*store.StorePersistence layer used for channel rows and balance updates.
walletwallet.ClientWallet client retained by the service for financial flows.
escrowEscrowReaderOptional chain-backed balance reader used to bound the channel by funded escrow.

Constructor dependencies

TypeDescription
*store.StorePostgres store used for channel persistence.
wallet.ClientWallet client passed into the service.
EscrowReaderOptional on-chain funded-balance reader.

Methods

MethodDescription
NewConstructs a Service and accepts a nil escrow reader for dev mode.
OpenValidates the cap, checks on-chain funding when available, opens a new channel row, and returns the active channel for the caller.
ReserveDelegates a reserve decrement to the store.
VoidReleases reserved balance without charging it.
FinalizeApplies a charge, cumulative spend, voucher nonce, and voucher signature to the channel row.
ActiveLoads the current open channel for a caller.
AddCumulativeAdds a charge to an existing cumulative total using decimal string arithmetic.

OpenInput

PropertyTypeDescription
CallerDIDstringCaller identity for the new channel.
CallerWalletstringCaller wallet address stored with the channel.
CapWeistringRequested channel cap in decimal wei.
EscrowAddrstringEscrow contract address used for funding checks.
FundTxstringFunding transaction reference stored with the channel.
BearerstringCaller bearer token carried in the request shape.

Behavior

  • Open requires a positive CapWei.
  • When escrow is non-nil, Open requires EscrowAddr, queries FundedWei, and caps the off-chain balance to the funded amount when the funded amount is smaller than the requested cap.
  • When escrow is nil and no escrow address is supplied, Open assigns the dev sentinel 0xescrow-dev.
  • defaultWindow is 10 * time.Minute, so new channels get a fixed current window.

deus/internal/channels/voucher.go

deus/internal/channels/voucher.go

This file coordinates voucher construction and co-signing. It turns a channel row into a pending voucher, verifies the caller signature, and persists the signed voucher together with the channel state transition.

VoucherService

PropertyTypeDescription
store*store.StoreStore used to load and persist channel and voucher rows.
signer*receipts.SignerEIP-712 signer used to derive and verify voucher digests.

Constructor dependencies

TypeDescription
*store.StoreStore used for channel and voucher persistence.
*receipts.SignerReceipt signer reused for voucher digests and caller verification.

Methods

MethodDescription
NewVoucherServiceWires the voucher helper with store and signer dependencies.
BuildPendingComputes the next cumulative total, increments the nonce, and returns the unsigned voucher digest for caller signing.
CosignLoads the channel, enforces a monotonic nonce, verifies the caller signature, and commits the co-signed voucher through the store.

PendingVoucher

PropertyTypeDescription
CumulativeWeistringNext cumulative channel spend.
Nonceint64Next voucher nonce.
LastReceiptHashstringReceipt digest that anchors the voucher.
DigeststringUnsigned EIP-712 voucher digest returned to the caller.

CosignInput

PropertyTypeDescription
ChannelIDstringChannel identifier for the voucher.
CumulativeWeistringCumulative spend to persist.
ChargeWeistringIncremental charge that is being finalized.
Nonceint64Voucher nonce that must advance monotonically.
LastReceiptHashstringReceipt digest carried into the voucher.
DigeststringVoucher digest that the caller signs.
CallerSigstringCaller signature over the voucher digest.
CallerWalletstringWallet address expected from the recovered signature.

Behavior

  • BuildPending uses AddCumulative to compute the next cumulative spend and then calls receipts.Signer.VoucherDigest.
  • Cosign rejects any nonce that is less than or equal to the current stored nonce with channels: voucher nonce not monotonic.
  • Cosign verifies the caller signature before persisting anything.
  • The final write path is delegated to store.CosignVoucher, which atomically updates the channel mirror and inserts the voucher row.

Metering Ledger

deus/internal/metering/ledger.go

Cosign relies on the store transaction so the channel nonce/cumulative update and the voucher row insert move together. The write path is intentionally coupled so one cannot advance without the other.

deus/internal/metering/ledger.go

This file records invocation lifecycle transitions. It creates or reuses reserved invocation rows, loads the row back for outcome checks, and then finalizes or voids it through the store.

Ledger

PropertyTypeDescription
store*store.StoreStore used for invocation reservation and finalization.

Constructor dependencies

TypeDescription
*store.StoreStore used to persist invocation state.

Methods

MethodDescription
NewConstructs a new Ledger.
ReserveInserts a reserved invocation row, reloads it, and accepts only reserved, ok, or voided outcomes.
FinalizeMarks the invocation delivered and charged.
VoidReleases a reservation without charging it.

ReserveInput

PropertyTypeDescription
IdempotencyKeystringIdempotency key used to deduplicate reservations.
ServiceIDstringService identifier for the invocation.
EndpointIDstringEndpoint identifier for the invocation.
CallerDIDstringCaller identity recorded with the invocation.
CallerWalletstringCaller wallet recorded with the invocation.
QuoteIDstringQuote identifier, optionally forwarded to the store.
UnitsstringBilled units as a decimal string.
PriceWeistringFinal price as a decimal wei string.
PricingVersionintPricing version stored with the invocation.
ArgsHashstringHash of the invocation arguments.
RailstringPayment rail name such as direct, net, or stream.
ChannelIDstringChannel identifier, optionally forwarded to the store.

Behavior

  • Reserve converts empty QuoteID and ChannelID values into nil pointers before persisting.
  • Reserve uses store.InsertReservedInvocation and then immediately reloads the row with store.GetInvocation.
  • Reserve treats any unexpected outcome as a hard error.

Storage and Persistence

deus/internal/store/store.go

deus/internal/store/store.go

This file owns the Postgres connection pool and the forward-only migration runner. It is the base layer for every financial write path in this section.

Store

PropertyTypeDescription
pool*pgxpool.PoolBacking Postgres connection pool.

Methods

MethodDescription
CloseCloses the pool when it is non-nil.
PoolExposes the underlying pool for query packages.
PingProbes database connectivity through the pool.
MigrateApplies .sql files in lexical order and records each applied version.

Lifecycle

  • New parses the PostgreSQL URI, creates the pool with pgxpool.NewWithConfig, and pings the database before returning.
  • Migrate reads a directory, keeps only .sql files, sorts them lexically, ensures schema_migrations exists, skips files already recorded in schema_migrations, and runs each unapplied file inside its own transaction.
  • ensureMigrationTable creates schema_migrations with version and applied_at.
  • isApplied checks whether a version has already been recorded.

deus/internal/store/channels.go

isApplied checks pgx.ErrNoRows, but the SELECT COUNT(1) query always returns one row. The branch does not drive behavior in the shown code; the real decision is based on whether the count is greater than zero.

deus/internal/store/channels.go

This file mirrors channel state in Postgres. It stores the channel balance, reservation state, cumulative spend, voucher nonce, and settlement metadata.

ChannelRow

PropertyTypeDescription
IDstringChannel row identifier.
CallerDIDstringCaller identity linked to the channel.
CallerWalletstringCaller wallet linked to the channel.
EscrowAddrstringEscrow contract address mirrored on the row.
BalanceWeistringFunded channel balance as a decimal wei string.
ReservedWeistringReserved amount as a decimal wei string.
CumulativeWeistringCumulative charged amount as a decimal wei string.
RedeemedWeistringRedeemed amount mirrored for settlement accounting.
Nonceint64Latest voucher nonce.
LastVoucherSig*stringLast persisted voucher signature.
WindowStarttime.TimeChannel window start timestamp.
WindowEndtime.TimeChannel window end timestamp.
StatusstringChannel status.
FundTx*stringFunding transaction reference.
SettleTx*stringSettlement transaction reference.

Methods

MethodDescription
OpenChannelInserts a new open channel row with zero reserved and cumulative balances.
ActiveChannelForCallerLoads the newest open channel for a caller whose window has not expired.
ReserveChannelBalanceAtomically increments reserved balance when enough unreserved balance remains.
ReleaseChannelReserveReleases reserved wei without charging the channel.
FinalizeChannelChargeDecrements reserved wei and stores cumulative spend, nonce, and voucher signature.
CosignVoucherFinalizes the channel charge and inserts the voucher in a single transaction.
AdvanceChannelRedeemedAdds settled wei to the redeemed mirror.
ReleaseExpiredChannelReservesZeroes dangling reservations on expired open channels.
GetChannelByIDLoads a channel by id.
CloseChannelMarks a channel closed and stores the settlement transaction reference.

Behavior

  • OpenChannel writes status = 'open', reserved_wei = '0', and cumulative_wei = '0'.
  • ActiveChannelForCaller filters on status = 'open' and window_end > now().
  • ReserveChannelBalance uses a numeric comparison so it only succeeds when the remaining available balance can cover the requested amount.
  • CosignVoucher starts a transaction, updates the channel row, inserts the voucher row, and commits only when both writes succeed.
  • ReleaseExpiredChannelReserves is the cleanup path for stale reservations after the channel window ends.

deus/internal/store/invocations.go

deus/internal/store/invocations.go

This file persists the invocation ledger that metering.Ledger works against. It stores the reservation, final outcome, timing, and payment rail.

InvocationRow

PropertyTypeDescription
IDstringInvocation identifier.
IdempotencyKeystringIdempotency key used for reservation deduplication.
ServiceIDstringService identifier.
EndpointIDstringEndpoint identifier.
CallerDIDstringCaller identity.
CallerWalletstringCaller wallet.
QuoteID*stringOptional quote identifier.
UnitsstringBilled units.
PriceWeistringFinal price in wei.
PricingVersionintPricing version stored with the invocation.
ArgsHashstringInvocation argument hash.
ResultHashstringResult hash stored after finalization.
OutcomestringInvocation outcome.
LatencyMS*intOptional latency in milliseconds.
RailstringPayment rail used for the invocation.
ChannelID*stringOptional payment-channel id.
CreatedAttime.TimeRow creation timestamp.

Methods

MethodDescription
InsertReservedInvocationInserts a reserved invocation row and falls back to the existing row when the idempotency key already exists.
GetInvocationByIdempotencyLoads an invocation by idempotency key.
GetInvocationLoads an invocation by id.
FinalizeInvocationUpdates a reserved invocation to its final outcome, result hash, units, price, and latency.
VoidInvocationMarks a reserved invocation voided and zeroes price.

Behavior

  • InsertReservedInvocation uses ON CONFLICT (idempotency_key) DO NOTHING.
  • If InsertReservedInvocation sees the existing key, it reloads the row by idempotency key and returns the existing id.
  • FinalizeInvocation only succeeds when the row is still reserved.
  • VoidInvocation only affects reserved rows.

deus/internal/store/receipts.go

deus/internal/store/receipts.go

This file stores the durable receipt envelope for each finalized invocation.

ReceiptRow

PropertyTypeDescription
DigeststringEIP-712 receipt digest.
GatewaySigstringGateway signature over the receipt digest.
RunnerSig*stringOptional runner signature returned by hosted execution.

Methods

MethodDescription
InsertReceiptInserts a receipt row and ignores duplicate invocation ids.
GetReceiptLoads a receipt by invocation id.

Behavior

  • InsertReceipt uses ON CONFLICT (invocation_id) DO NOTHING.
  • GetReceipt returns store: receipt not found when the invocation has no stored receipt.

deus/internal/store/vouchers.go

deus/internal/store/vouchers.go

This file persists the voucher rows used for caller-co-signed cumulative settlement.

VoucherRow

PropertyTypeDescription
IDstringVoucher row identifier.
ChannelIDstringChannel identifier.
CumulativeWeistringCumulative spend for the voucher.
Nonceint64Voucher nonce.
LastReceiptHashstringLast receipt digest bound into the voucher.
DigeststringEIP-712 voucher digest.
CallerSigstringCaller signature over the digest.
RedeemedIn*stringOptional settlement reference.
CreatedAttime.TimeVoucher creation timestamp.

Methods

MethodDescription
InsertVoucherInserts a co-signed voucher row.
HighestVoucherForChannelReturns the highest-nonce voucher for settlement.

Behavior

  • HighestVoucherForChannel orders by nonce DESC and returns the first row.
  • The table is used as the durable record of a channel’s latest cumulative voucher state.

deus/internal/store/deployments.go

deus/internal/store/deployments.go

This file mirrors deployment records for hosted execution routing and lifecycle tracking.

DeploymentRow

PropertyTypeDescription
IDstringDeployment identifier.
ServiceIDstringService identifier.
AppwriteFunctionID*stringOptional Appwrite function id.
SiteID*stringOptional site id.
RuntimestringRuntime name.
DeploymentID*stringOptional backend deployment id.
ExecEndpoint*stringOptional execution endpoint.
StatusstringDeployment status.
Region*stringOptional region.
LastInvokedAt*time.TimeOptional timestamp of the last invocation.
AlwaysWarmboolWhether the deployment is always warm.
ArtifactKey*stringOptional artifact key.
CreatedAttime.TimeRow creation timestamp.

Methods

MethodDescription
InsertDeploymentCreates a deployment row.
ActiveDeploymentForServiceReturns the newest active deployment for a service.
ListDeploymentsForServiceReturns deployments for a service in reverse chronological order.
GetDeploymentLoads a deployment by id.
UpdateDeploymentStatusUpdates deployment status and optionally the execution endpoint.
CountAlwaysWarmDeploymentsCounts active always-warm deployments.
TouchDeploymentInvokedUpdates last_invoked_at.
SetDeploymentBackendIDsStores backend function and deployment ids after provisioning.
DeactivateDeploymentsForServiceMarks prior active deployments as superseded.

Behavior

  • ActiveDeploymentForService filters on status = 'active' and sorts by created_at DESC.
  • CountAlwaysWarmDeployments counts only active rows with always_warm = true.
  • DeactivateDeploymentsForService updates active rows to superseded before a new deploy becomes active.

Settlement States and Invariants

EntityStored states or valuesRules enforced in code
Channelopen, closedOpenChannel writes open; CloseChannel writes closed; ActiveChannelForCaller only returns open and unexpired rows.
Invocationreserved, ok, voidedInsertReservedInvocation writes reserved; FinalizeInvocation only updates rows still reserved; VoidInvocation only updates rows still reserved.
Deploymentactive, supersededActiveDeploymentForService only reads active; DeactivateDeploymentsForService marks old active rows superseded.
Voucher nonceMonotonic integerBuildPending increments the stored nonce; Cosign rejects non-monotonic input.
Channel reserveDecimal wei stringReserveChannelBalance only succeeds when available balance covers the requested amount.

Error Handling

The financial workflow code uses explicit, package-prefixed errors so each layer can tell reservation failures from signature failures or persistence failures.

LayerExample error textTrigger
Receiptsreceipts: invalid signing keyHex key parsing fails in NewSignerFromHex.
Receiptsreceipts: quote signer mismatchVerifyQuote recovers a different address than the signer address.
Receiptsreceipts: voucher caller mismatchVerifyVoucherCaller recovers a different address than callerWallet.
Receiptsreceipts: empty merkle inputMerkleRoot receives no digests.
Receiptsreceipts: invalid digestdecodeHash cannot parse a digest as a 32-byte hex string.
Receiptsreceipts: invalid signature lengthRecoverSigner receives a signature that is not 65 bytes.
Channelschannels: cap requiredOpen receives an empty channel cap.
Channelschannels: invalid capOpen cannot parse or validate CapWei as a positive integer.
Channelschannels: escrow_addr requiredOpen has an escrow reader but no escrow address.
Channelschannels: escrow not fundedThe escrow reader returns a non-positive funded balance.
Channelschannels: voucher nonce not monotonicCosign receives a nonce that does not advance.
Meteringmetering: unexpected outcomeReserve reloads a row whose outcome is not one of the accepted values.
Storestore: no migrations in Migrate finds no .sql files.
Storestore: deployment not foundDeployment lookups return no rows.
Storestore: channel not foundChannel lookups return no rows.
Storestore: invocation not foundInvocation lookups return no rows.
Storestore: receipt not foundReceipt lookups return no rows.
Storestore: insufficient channel balanceChannel reservation cannot satisfy the requested amount.
Storestore: invocation not in reserved stateFinalization or voiding is attempted on a non-reserved row.

Verification

deus/internal/receipts/eip712_test.go

deus/internal/receipts/eip712_test.go

TestWhat it proves
TestSignAndVerifyQuoteA quote can be signed and verified with the same signer, chain id, and registry address.

The test uses a fixed private-key fixture, a fixed service id, a fixed endpoint id, and a fixed pricing version so the quote digest and signature round-trip deterministically.

deus/internal/receipts/merkle_test.go

deus/internal/receipts/merkle_test.go

TestWhat it proves
TestMerkleRootDeterministicReordering the same digests does not change the Merkle root.
TestMerkleRootOddLeavesOdd layers duplicate the trailing node, and a single leaf is not passed through as the root.

deus/internal/receipts/voucher_test.go

deus/internal/receipts/voucher_test.go

TestWhat it proves
TestVoucherCallerVerifyA voucher digest signed by the caller wallet passes VerifyVoucherCaller.

The test signs the digest with a fixed caller-key fixture and checks that the recovered wallet matches the expected caller wallet fixture.

deus/internal/store/store_test.go

deus/internal/store/store_test.go

TestWhat it proves
TestMigrateCreatesSchemaMigrate creates the schema, can be run twice without failing, and leaves the services table present.

The test reads DEUS_POSTGRES_URI and DEUS_MIGRATIONS_DIR when present and otherwise falls back to a local Postgres URI with embedded credentials and a migrations directory relative to the store package.

External Financial Dependencies

wallet.Client

wallet.Client is injected into deus/internal/channels/channels.go Service and into the Gateway configuration in deus/internal/gateway/gateway.go. In the visible financial invoke path, it is used for spend authorization and payout transfer calls through AuthorizeSpend and Send.

quality.Service

quality.Service is injected into Gateway and sampled after payment rails complete. The visible call sites record outcomes and latency with Sample.

streams.Service

streams.Service is injected into Gateway and is used by the stream rail flow to load ownership, meter deltas, and persist meter progress with GetOwned, MeterDelta, and RecordMeter.

HostingRouter

HostingRouter is injected into Gateway and resolves the active hosted execution endpoint with ActiveEndpoint. That endpoint selection feeds the hosted invocation path that eventually settles through the same store and receipt primitives documented above.

Key Files Reference

FileResponsibility
deus/internal/receipts/eip712.goBuilds and verifies EIP-712 quotes and receipts, recovers signers, and hashes JSON payloads.
deus/internal/receipts/eip712_test.goVerifies quote signing and signature recovery.
deus/internal/receipts/merkle.goProduces deterministic, domain-separated Merkle roots over receipt digests.
deus/internal/receipts/merkle_test.goVerifies deterministic ordering and odd-leaf handling for Merkle roots.
deus/internal/receipts/voucher.goBuilds voucher digests and verifies caller signatures.
deus/internal/receipts/voucher_test.goVerifies voucher caller recovery against a fixed wallet fixture.
deus/internal/channels/channels.goOpens channels, reserves and releases balance, finalizes cumulative spend, and exposes active channels.
deus/internal/channels/voucher.goBuilds pending vouchers and co-signs them with monotonic nonce enforcement.
deus/internal/metering/ledger.goReserves, finalizes, and voids invocation ledger rows.
deus/internal/store/store.goCreates the Postgres pool and applies forward-only SQL migrations.
deus/internal/store/channels.goPersists channel mirrors and channel settlement transitions.
deus/internal/store/invocations.goPersists invocation reservations and final outcomes.
deus/internal/store/receipts.goPersists signed receipts keyed by invocation id.
deus/internal/store/vouchers.goPersists voucher rows and loads the highest nonce for a channel.
deus/internal/store/deployments.goPersists deployment mirrors, active deployment lookup, and warm deployment tracking.
deus/internal/store/store_test.goVerifies migration application and schema creation.