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

session-management.mddocs/

Session Management

Session lifecycle management types including session structures, proposals, namespaces, and session configuration for WalletConnect connections between dApps and wallets.

Capabilities

Session Structure

Core session structure containing all information about an established WalletConnect connection.

namespace SessionTypes {
  /**
   * Complete session structure representing an active WalletConnect connection
   */
  interface Struct {
    /** Unique session topic identifier */
    topic: string;
    /** Associated pairing topic */
    pairingTopic: string;
    /** Relay protocol configuration */
    relay: RelayerTypes.ProtocolOptions;
    /** Session expiry timestamp */
    expiry: number;
    /** Whether session has been acknowledged */
    acknowledged: boolean;
    /** Controller (proposer) public key */
    controller: string;
    /** Approved namespaces with accounts and methods */
    namespaces: Namespaces;
    /** Self participant (this client) metadata */
    self: Participant;
    /** Peer participant (other client) metadata */
    peer: Participant;
    /** Original required namespaces from proposal */
    requiredNamespaces: ProposalTypes.RequiredNamespaces;
    /** Optional namespaces from proposal */
    optionalNamespaces: ProposalTypes.OptionalNamespaces;
    /** Custom session properties (optional) */
    sessionProperties?: SessionProperties;
    /** Scoped properties for namespace-specific metadata (optional) */
    scopedProperties?: ScopedProperties;
    /** Session configuration options (optional) */
    sessionConfig?: SessionConfig;
    /** Authentication CACAOs (optional) */
    authentication?: AuthTypes.Cacao[];
    /** Transport type for communication (optional) */
    transportType?: RelayerTypes.TransportType;
  }

  /**
   * Session expiry timestamp type
   */
  type Expiry = number;

  /**
   * Session configuration options
   */
  interface SessionConfig {
    /** Disable deep link functionality (optional) */
    disableDeepLink?: boolean;
  }

  /**
   * Session participant information
   */
  interface Participant {
    /** Participant's public key */
    publicKey: string;
    /** Participant's metadata */
    metadata: SignClientTypes.Metadata;
  }
}

Namespace Management

Namespace structures defining blockchain networks, methods, events, and accounts supported in a session.

namespace SessionTypes {
  /**
   * Base namespace structure with accounts, methods, and events
   */
  interface BaseNamespace {
    /** Supported blockchain chain IDs (optional) */
    chains?: string[];
    /** Array of blockchain accounts in CAIP-10 format */
    accounts: string[];
    /** Supported RPC methods */
    methods: string[];
    /** Supported events */
    events: string[];
  }

  /**
   * Session namespace type (same as BaseNamespace)
   */
  type Namespace = BaseNamespace;

  /**
   * Session namespaces mapping
   * Maps namespace names to their configurations
   */
  type Namespaces = Record<string, Namespace>;

  /**
   * Session properties type for custom metadata
   */
  type SessionProperties = Record<string, string>;

  /**
   * Scoped properties type for namespace-specific metadata
   */
  type ScopedProperties = Record<string, Record<string, string>>;
}

Proposal Structure

Proposal structures for initiating WalletConnect sessions with required and optional capabilities.

namespace ProposalTypes {
  /**
   * Complete proposal structure for session establishment
   */
  interface Struct {
    /** Unique proposal ID */
    id: number;
    /** Pairing topic for this proposal */
    pairingTopic: string;
    /** Proposal expiry timestamp */
    expiry: number;
    /** Available relay protocols */
    relays: RelayerTypes.ProtocolOptions[];
    /** Proposer information */
    proposer: {
      /** Proposer's public key */
      publicKey: string;
      /** Proposer's metadata */
      metadata: CoreTypes.Metadata;
    };
    /** Required namespace capabilities */
    requiredNamespaces: RequiredNamespaces;
    /** Optional namespace capabilities */
    optionalNamespaces?: OptionalNamespaces;
    /** Custom session properties */
    sessionProperties?: SessionProperties;
  }

  /**
   * Base required namespace requirements
   */
  interface BaseRequiredNamespace {
    /** Required blockchain chain IDs (optional) */
    chains?: string[];
    /** Required RPC methods */
    methods: string[];
    /** Required events */
    events: string[];
  }

  /**
   * Required namespace type (same as base)
   */
  type RequiredNamespace = BaseRequiredNamespace;

  /**
   * Required namespaces mapping
   * Maps namespace names to their requirements
   */
  type RequiredNamespaces = Record<string, RequiredNamespace>;

  /**
   * Optional namespaces mapping  
   * Maps namespace names to their optional capabilities
   */
  type OptionalNamespaces = Record<string, RequiredNamespace>;

  /**
   * Session properties mapping for custom metadata
   */
  type SessionProperties = Record<string, string>;

  /**
   * Scoped properties mapping for namespace-specific metadata
   */
  type ScopedProperties = Record<string, Record<string, string>>;
}

Session Store Interfaces

Store interfaces for persisting session and proposal data.

/**
 * Store interface for sessions
 * Handles CRUD operations for session persistence
 */
type ISession = IStore<SessionTypes.Struct>;

/**
 * Store interface for proposals  
 * Handles CRUD operations for proposal persistence
 */
type IProposal = IStore<ProposalTypes.Struct>;

Usage Examples:

import { SessionTypes, ProposalTypes } from "@walletconnect/types";

// Create a session proposal
const proposal: ProposalTypes.Struct = {
  id: 1,
  pairingTopic: "pairing_topic_123",
  expiry: Date.now() + 300000, // 5 minutes
  relays: [{ protocol: "irn" }],
  proposer: {
    publicKey: "0x04...",
    metadata: {
      name: "Example dApp",
      description: "A sample decentralized application",
      url: "https://example.com",
      icons: ["https://example.com/icon.png"]
    }
  },
  requiredNamespaces: {
    eip155: {
      chains: ["eip155:1", "eip155:137"], // Ethereum mainnet and Polygon
      methods: ["eth_sendTransaction", "personal_sign"],
      events: ["chainChanged", "accountsChanged"]
    }
  },
  optionalNamespaces: {
    eip155: {
      chains: ["eip155:42161", "eip155:10"], // Arbitrum and Optimism
      methods: ["eth_signTypedData"],
      events: ["disconnect"]
    }
  }
};

// Create a session structure
const session: SessionTypes.Struct = {
  topic: "session_topic_456",
  pairingTopic: "pairing_topic_123",
  relay: { protocol: "irn" },
  expiry: Date.now() + 604800000, // 7 days
  acknowledged: true,
  controller: "0x04...", // Proposer's public key
  namespaces: {
    eip155: {
      chains: ["eip155:1", "eip155:137"],
      accounts: [
        "eip155:1:0x1234567890123456789012345678901234567890",
        "eip155:137:0x1234567890123456789012345678901234567890"
      ],
      methods: ["eth_sendTransaction", "personal_sign"],
      events: ["chainChanged", "accountsChanged"]
    }
  },
  self: {
    publicKey: "0x04...", // Wallet's public key
    metadata: {
      name: "Example Wallet",
      description: "A sample crypto wallet",
      url: "https://wallet.example.com",
      icons: ["https://wallet.example.com/icon.png"]
    }
  },
  peer: {
    publicKey: "0x04...", // dApp's public key  
    metadata: {
      name: "Example dApp",
      description: "A sample decentralized application",
      url: "https://example.com", 
      icons: ["https://example.com/icon.png"]
    }
  }
};

// Define namespaces
const namespaces: SessionTypes.Namespaces = {
  eip155: {
    chains: ["eip155:1"],
    accounts: ["eip155:1:0xabc..."],
    methods: ["eth_sendTransaction"],
    events: ["chainChanged"]
  }
};

Install with Tessl CLI

npx tessl i tessl/npm-walletconnect--types

docs

auth.md

core-protocol.md

crypto.md

index.md

relay.md

session-management.md

sign-client.md

tile.json