Skip to main content

Overview

Sovran implements the Cashu ecash protocol through the coco-cashu-core and coco-cashu-react libraries. Ecash tokens are digital bearer instruments that can be sent, received, and validated cryptographically.

Token Validation

The helper/coco/utils.ts module provides token validation utilities:

Validate Token Format

From helper/coco/utils.ts:55-62.

Decode Token

Tokens are decoded using coco-cashu-core:

Send Operations

The useSendWithHistory hook manages ecash token creation:

Two-Step Send Flow

From hooks/coco/useSendWithHistory.ts:38-113.

Automatic Rollback

Failed send operations are automatically rolled back:
From hooks/coco/useSendWithHistory.ts:114-138.

Receive Operations

Build Receive History Entry

Centralized receive entry construction:
From helper/coco/utils.ts:334-349.

Sum Proof Amounts

Utility to calculate total token value:
From helper/coco/utils.ts:319-323.

Token Processing

The useProcessPaymentString hook handles token detection and routing:

Regular Ecash Tokens

From hooks/coco/useProcessPaymentString.ts:203-212.

UR-Encoded Tokens

Support for animated QR codes (UR codes):
From hooks/coco/useProcessPaymentString.ts:153-199.

NUT-18 Payment Requests

Support for Nostr-transported payment requests:

Detection

From hooks/coco/useProcessPaymentString.ts:29-45.

Routing Logic

Payment requests are routed based on available data: From hooks/coco/useProcessPaymentString.ts:231-240.

Mint Validation

From hooks/coco/useProcessPaymentString.ts:113-133.

Token Encoding

Tokens can be encoded in multiple versions:

V4 Encoding (NFC)

From hooks/useNfcEcashPayment.tsx:133.

Standard Encoding

Token State Management

Pending Tokens

Tokens in pending state:

Reserved Proofs

Proofs locked during operations:

Recovery Operations

From components/blocks/PrimaryBalance.tsx:188-222.

Coco-Cashu Integration

Core Principles

Never redefine types from coco-cashu-core. Always import from the source library.

Manager Usage

Event Subscription

From hooks/coco/useSendWithHistory.ts:65-73.

Key Features

Token Validation

Cryptographic validation of ecash tokens before receive

Two-Step Send

Prepare and execute pattern with automatic rollback on failure

UR Code Support

Animated QR codes for large tokens with progress tracking

Payment Requests

NUT-18 payment requests with Nostr transport