CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-walletconnect--types

tessl install tessl/npm-walletconnect--types@2.21.0

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

Agent Success

Agent success rate when using this tile

70%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.19x

Baseline

Agent success rate without this tile

59%

task.mdevals/scenario-4/

Session Proposal Manager

Build a TypeScript utility that validates and manages WalletConnect session proposals. The utility should help developers check proposal structures before sending them to wallets and track proposal lifecycle states.

Requirements

Your implementation should provide the following capabilities:

  1. Proposal Validation: Create a function that validates proposal structures to ensure they contain all required fields before being sent. The validation should check:

    • Required namespace specifications are present and properly formatted
    • Namespace accounts follow the correct CAIP-10 format (chain:chainId:address)
    • Methods and events arrays are not empty in required namespaces
    • Relay protocol is specified
    • Proposer metadata contains required fields (name, description, url, icons)
  2. Proposal State Tracking: Implement a simple in-memory storage system that can:

    • Store pending proposals with their IDs and expiry timestamps
    • Retrieve proposals by ID
    • List all pending proposals
    • Remove proposals when they expire or are resolved
  3. Proposal Lifecycle: Create functions to:

    • Mark a proposal as approved
    • Mark a proposal as rejected
    • Check if a proposal has expired based on current timestamp

Test Cases

Validation Tests

  • Validates a correctly structured proposal with required namespaces containing proper chain accounts and methods @test
  • Rejects a proposal missing required namespace specifications @test
  • Rejects a proposal with malformed CAIP-10 account format @test

Storage Tests

  • Stores and retrieves a proposal by its ID @test
  • Lists all pending proposals in the storage @test
  • Removes a proposal from storage after it's marked as approved @test

Lifecycle Tests

  • Correctly identifies an expired proposal based on timestamp comparison @test
  • Marks a proposal as approved and removes it from pending state @test

Implementation

@generates

API

import { ProposalTypes } from '@walletconnect/types';

/**
 * Validates a session proposal structure
 * @param proposal - The proposal to validate
 * @returns true if valid, false otherwise
 */
export function validateProposal(proposal: ProposalTypes.Struct): boolean;

/**
 * Stores a proposal in memory
 * @param proposal - The proposal to store
 */
export function storeProposal(proposal: ProposalTypes.Struct): void;

/**
 * Retrieves a proposal by ID
 * @param id - The proposal ID
 * @returns The proposal if found, undefined otherwise
 */
export function getProposal(id: number): ProposalTypes.Struct | undefined;

/**
 * Lists all pending proposals
 * @returns Array of all stored proposals
 */
export function listProposals(): ProposalTypes.Struct[];

/**
 * Checks if a proposal has expired
 * @param proposal - The proposal to check
 * @param currentTimestamp - Current timestamp in seconds
 * @returns true if expired, false otherwise
 */
export function isProposalExpired(proposal: ProposalTypes.Struct, currentTimestamp: number): boolean;

/**
 * Marks a proposal as approved and removes it from storage
 * @param id - The proposal ID
 * @returns true if approved successfully, false if not found
 */
export function approveProposal(id: number): boolean;

/**
 * Marks a proposal as rejected and removes it from storage
 * @param id - The proposal ID
 * @returns true if rejected successfully, false if not found
 */
export function rejectProposal(id: number): boolean;

Dependencies { .dependencies }

@walletconnect/types { .dependency }

Provides TypeScript type definitions for WalletConnect Protocol v2, including proposal structures and interfaces.

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@walletconnect/types@2.21.x
tile.json