TAP CAIP
Implementation of Chain Agnostic Identifier Standards for the Transaction Authorization Protocol (TAP).
Features
- CAIP-2: Support for Chain IDs in namespace:reference format
- CAIP-10: Support for Account IDs
- CAIP-19: Support for Asset IDs
- Validation: Proper validation of identifiers against the CAIP specifications
- Parsing and Serialization: Easy conversion between strings and structured types
Usage
Chain ID (CAIP-2)
use ChainId;
use FromStr;
// Create from string
let chain_id = from_str?;
// Access components
assert_eq!;
assert_eq!;
// Convert back to string
assert_eq!;
Account ID (CAIP-10)
use ;
use FromStr;
// Create from string
let account_id = from_str?;
// Create from components
let chain_id = from_str?;
let account_id = new;
// Access components
assert_eq!;
assert_eq!;
assert_eq!;
// Convert back to string
assert_eq!;
Asset ID (CAIP-19)
use ;
use FromStr;
// Create from string
let asset_id = from_str?;
// Create from components
let chain_id = from_str?;
let asset_id = new;
// Access components
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// Convert back to string
assert_eq!;
Validation
Each identifier type includes validation to ensure it conforms to the CAIP standards:
use ;
use FromStr;
// Valid chain ID
let valid_chain = from_str;
assert!;
// Invalid chain ID (missing reference)
let invalid_chain = from_str;
assert!;
// Valid account ID
let valid_account = from_str;
assert!;
// Invalid account ID (missing address)
let invalid_account = from_str;
assert!;
// Valid asset ID
let valid_asset = from_str;
assert!;
// Invalid asset ID (missing asset reference)
let invalid_asset = from_str;
assert!;
Integration with TAP Messages
The CAIP types are designed to integrate seamlessly with TAP messages:
use ;
use AssetId;
use FromStr;
use HashMap;
// Create a TAP Transfer message with a CAIP-19 Asset ID
let asset = from_str?;
let transfer = Transfer ;
Supported CAIP Standards
Examples
See the examples directory for more detailed examples of using CAIP identifiers.