CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-walletconnect--types

TypeScript type definitions and interfaces for the WalletConnect Protocol v2, enabling type-safe development across the WalletConnect ecosystem

70

1.18x
Overview
Eval results
Files

task.mdevals/scenario-5/

Multi-Chain Session Configuration Builder

Build a utility that creates and validates multi-chain session configurations for blockchain applications. The tool should handle different blockchain networks and their supported operations.

Requirements

Create a configuration builder that:

  1. Accepts blockchain network definitions including supported accounts, methods, and events
  2. Constructs session configurations with required and optional blockchain capabilities
  3. Validates that configurations meet the necessary structure requirements
  4. Exports configurations in a standardized format

Input Structure

Your builder should accept inputs specifying:

  • Blockchain network identifiers (e.g., "eip155:1" for Ethereum mainnet, "eip155:137" for Polygon)
  • Account addresses for each network
  • Supported RPC methods for each network (e.g., "eth_sendTransaction", "personal_sign")
  • Events that can be emitted (e.g., "chainChanged", "accountsChanged")

Configuration Types

Support two types of capabilities:

  1. Required capabilities: Must be supported by the session
  2. Optional capabilities: May be supported but are not mandatory

Validation Rules

The configuration must satisfy:

  • Each blockchain network must have at least one account
  • Each network must specify at least one method
  • Events can be empty but must be defined
  • Network identifiers must follow the CAIP-2 format (namespace:reference)

Test Cases

  • Given Ethereum mainnet with one account and two methods, creates a valid required configuration @test
  • Given multiple chains (Ethereum and Polygon) with different accounts, creates a valid multi-chain configuration @test
  • Given a configuration with both required and optional capabilities, correctly structures both sections @test
  • Throws an error when a network has no accounts specified @test

Implementation

@generates

API

/**
 * Represents a blockchain namespace configuration
 */
export interface NamespaceConfig {
  chains: string[];
  methods: string[];
  events: string[];
  accounts: string[];
}

/**
 * Configuration input for a single blockchain
 */
export interface ChainInput {
  chainId: string;
  accounts: string[];
  methods: string[];
  events: string[];
}

/**
 * Session configuration with required and optional namespaces
 */
export interface SessionConfig {
  requiredNamespaces?: Record<string, NamespaceConfig>;
  optionalNamespaces?: Record<string, NamespaceConfig>;
}

/**
 * Builds a session configuration with required namespaces
 */
export function buildRequiredNamespaces(chains: ChainInput[]): SessionConfig;

/**
 * Builds a session configuration with optional namespaces
 */
export function buildOptionalNamespaces(chains: ChainInput[]): SessionConfig;

/**
 * Builds a session configuration with both required and optional namespaces
 */
export function buildSessionConfig(
  required: ChainInput[],
  optional: ChainInput[]
): SessionConfig;

/**
 * Validates a namespace configuration
 * Throws an error if validation fails
 */
export function validateNamespaceConfig(config: NamespaceConfig): void;

Dependencies { .dependencies }

@walletconnect/types { .dependency }

Provides TypeScript type definitions for WalletConnect Protocol v2, including session and namespace types.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-walletconnect--types

tile.json