@zkp2p/contracts-v2/utils/protocolUtils module provides utility functions for protocol operations including hashing, currency handling, and intent calculations.
Import Utilities
Currency Constants
TheCurrency object provides pre-computed Keccak256 hashes for all supported currencies:
Supported Currencies
All 33 supported currency codes:Major Currencies
Major Currencies
USD- United States DollarEUR- EuroGBP- British Pound SterlingJPY- Japanese YenCHF- Swiss FrancCAD- Canadian DollarAUD- Australian DollarNZD- New Zealand Dollar
Asian Currencies
Asian Currencies
CNY- Chinese YuanHKD- Hong Kong DollarSGD- Singapore DollarINR- Indian RupeeIDR- Indonesian RupiahMYR- Malaysian RinggitPHP- Philippine PesoTHB- Thai BahtVND- Vietnamese Dong
European Currencies
European Currencies
CZK- Czech KorunaDKK- Danish KroneHUF- Hungarian ForintNOK- Norwegian KronePLN- Polish ZlotyRON- Romanian LeuSEK- Swedish Krona
Other Currencies
Other Currencies
AED- UAE DirhamARS- Argentine PesoILS- Israeli ShekelKES- Kenyan ShillingMXN- Mexican PesoSAR- Saudi RiyalTRY- Turkish LiraUGX- Ugandan ShillingZAR- South African Rand
Hashing Functions
getKeccak256Hash
Compute Keccak256 hash of a string value:The string value to hash
Keccak256 hash as a hex string with
0x prefixcalculatePaymentMethodHash
Calculate payment method hash (alias forgetKeccak256Hash):
Intent Hash Calculation
calculateIntentHash
Calculate the unique hash for an intent, constrained to the Circom field:Address of the Orchestrator contract
The intent counter value (can be ethers BigNumber or number)
Intent hash constrained to Circom field, zero-padded to 32 bytes
The intent hash is computed as
keccak256(orchestrator, intentCounter) modulo the Circom field prime:
21888242871839275222246405745257275088548364400416034343698204186575808495617Currency Helpers
getCurrencyCodeFromHash
Reverse lookup to get currency code from its hash:The currency hash to look up
Currency code (e.g., “USD”, “EUR”) or empty string if not found
Complete Example
Building Intent Parameters
Currency Validation
Type Definitions
Next Steps
Payment Methods
Work with payment method configurations
Constants
Access protocol constants