Overview
The Settlement contract (identipay::settlement) is the core orchestrator for identiPay transactions. It implements atomic execution of commerce settlements, ensuring all operations succeed or fail together.
Per the whitepaper (section 5), the settlement uses Programmable Transaction Blocks (PTBs) to atomically:
- Verify ZK eligibility proofs (if age-gated)
- Verify buyer’s intent signature
- Transfer payment to merchant
- Mint encrypted receipt to buyer’s stealth address
- Optionally mint warranty
- Emit settlement event
Source Code
Location:contracts/sources/settlement.move:12
Data Structures
SettlementState
Shared state for settlement replay protection.Sui object identifier
Maps intent hash to execution status. Prevents replay of signed intents.
SettlementEvent
Emitted on successful settlement. Indexed by intent hash, not buyer identity.SHA3-256 hash of the canonicalized intent
Merchant’s Sui address receiving payment
Payment amount in smallest token units
Object ID of the minted receipt
Optional warranty object ID
One-time stealth address where artifacts were delivered
Entry Functions
execute_commerce
Execute a full commerce settlement atomically with ZK proof verification. Function Signature:Mutable reference to the shared settlement state
Coin to split payment from. Change remains with sender.
Payment amount to transfer to merchant
Merchant’s Sui address for payment delivery
One-time stealth address for receipt/warranty delivery
Ed25519 signature (64 bytes) over intent_hash
SHA3-256 hash of canonicalized commerce proposal
Buyer’s Ed25519 public key (32 bytes)
Proposal expiration timestamp (epoch ms). Must be in the future.
ZK verification key for eligibility proof
Groth16 proof bytes
Public inputs for ZK circuit
AES-256-GCM encrypted receipt payload
12-byte GCM nonce for receipt decryption
Ephemeral X25519 public key (32 bytes) for ECDH
Encrypted warranty terms. Pass empty vector if no warranty.
12-byte GCM nonce for warranty decryption
Warranty expiration timestamp (epoch ms)
Whether warranty can be transferred
EInvalidAmount(0): Amount is zero or exceeds payment coin valueEProposalExpired(1): Current time exceeds proposal_expiryEIntentAlreadyExecuted(2): Intent hash was already settled
settlement.move:77-167
execute_commerce_no_zk
Execute a commerce settlement without ZK proof verification. For transactions without age gates or other constraints. Function Signature:execute_commerce except ZK-related parameters are omitted.
Location: settlement.move:171-248
Public Functions
is_intent_executed
Check if an intent hash has already been executed.Reference to settlement state
Intent hash to check
Returns
true if intent was already executedsettlement.move:253-255
Usage Example
Security Considerations
Atomicity: All operations execute in a single PTB. If any step fails (ZK proof invalid, signature invalid, insufficient balance), the entire transaction reverts with no state changes.
Generic Tokens: The contract is generic over
<T> and works with any Sui coin type. Most deployments use Coin<USDC> on testnet.Related Modules
Intent
Signature verification logic
Receipt
Receipt minting and structure
Warranty
Warranty minting and transfers
ZK Verifier
Groth16 proof verification
