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

crypto.mddocs/

Cryptographic Types

Cryptographic operations and type definitions for WalletConnect Protocol including key management, encryption/decryption, and secure message encoding/decoding.

Capabilities

Crypto Interface

Main cryptographic operations interface for key management and secure message handling throughout the protocol.

/**
 * Cryptographic operations interface for key management, encoding/decoding
 * Handles all cryptographic operations in the WalletConnect protocol
 */
interface ICrypto extends IEvents {
  readonly name: string;
  readonly context: string;

  /** Initialize the crypto module */
  init(): Promise<void>;
  /** Check if keys exist for given tag */
  hasKeys(tag: string): boolean;
  /** Get client ID derived from keys */
  getClientId(): Promise<string>;
  /** Generate a new key pair and return public key */
  generateKeyPair(): Promise<string>;
  /** Generate shared key from self and peer public keys */
  generateSharedKey(self: string, peer: string, overrideTopic?: string): Promise<string>;
  /** Set symmetric key with optional topic override */
  setSymKey(symKey: string, overrideTopic?: string): Promise<string>;
  /** Delete key pair by public key */
  deleteKeyPair(publicKey: string): Promise<void>;
  /** Delete symmetric key by topic */
  deleteSymKey(topic: string): Promise<void>;
  /** Encode payload with encryption */
  encode(topic: string, payload: JsonRpcPayload, opts?: CryptoTypes.EncodeOptions): Promise<string>;
  /** Decode encrypted message */
  decode(topic: string, encrypted: string, opts?: CryptoTypes.DecodeOptions): Promise<JsonRpcPayload>;
}

Key Management Types

Type definitions for cryptographic key structures and key pair management.

namespace CryptoTypes {
  /**
   * Private/public key pair structure
   */
  interface KeyPair {
    /** Private key in hex format */
    privateKey: string;
    /** Public key in hex format */
    publicKey: string;
  }

  /**
   * Public key holder in cryptographic operations
   */
  interface Participant {
    /** Public key identifier */
    publicKey: string;
  }
}

Encryption/Decryption Types

Parameters and options for encryption and decryption operations with support for different encryption types.

namespace CryptoTypes {
  /**
   * Parameters for encryption operations
   */
  interface EncryptParams {
    /** Message content to encrypt */
    message: string;
    /** Symmetric key for encryption */
    symKey: string;
    /** Encryption type (optional) */
    type?: number;
    /** Initialization vector (optional) */
    iv?: string;
    /** Sender's public key for authenticated encryption (optional) */
    senderPublicKey?: string;
  }

  /**
   * Parameters for decryption operations
   */
  interface DecryptParams {
    /** Symmetric key for decryption */
    symKey: string;
    /** Encrypted/encoded message */
    encoded: string;
  }

  /**
   * Type 1 encryption parameters with sender/receiver keys
   * Used for authenticated encryption with key exchange
   */
  interface TypeOneParams {
    /** Sender's public key */
    senderPublicKey: string;
    /** Receiver's public key */
    receiverPublicKey: string;
  }
}

Encoding/Decoding Types

Low-level and high-level encoding/decoding parameters for message serialization and validation.

namespace CryptoTypes {
  /**
   * Encoding format options for message serialization
   */
  type EncodingType = "base64pad" | "base64url";

  /**
   * Low-level encoding parameters with Uint8Arrays
   */
  interface EncodingParams {
    /** Message as byte array */
    message: Uint8Array;
    /** Symmetric key as byte array */
    symKey: Uint8Array;
    /** Initialization vector as byte array */
    iv: Uint8Array;
  }

  /**
   * Low-level decoding parameters
   */
  interface DecodingParams {
    /** Symmetric key as byte array */
    symKey: Uint8Array;
    /** Encoded message as byte array */
    encoded: Uint8Array;
  }

  /**
   * High-level encoding options
   */
  interface EncodeOptions {
    /** Encoding type for output format */
    type?: EncodingType;
    /** Sender's public key (optional) */
    senderPublicKey?: string;
    /** Receiver's public key (optional) */
    receiverPublicKey?: string;
  }

  /**
   * High-level decoding options
   */
  interface DecodeOptions {
    /** Receiver's public key (optional) */
    receiverPublicKey?: string;
  }

  /**
   * Validation parameters for encoding operations
   */
  interface EncodingValidation {
    /** Message content to validate */
    message: string;
    /** Symmetric key to validate */
    symKey: string;
  }
}

Usage Examples:

import { ICrypto, CryptoTypes } from "@walletconnect/types";

// Generate a key pair
const publicKey = await crypto.generateKeyPair();

// Generate shared key for secure communication
const sharedKey = await crypto.generateSharedKey(selfPublicKey, peerPublicKey);

// Encrypt a message
const encrypted = await crypto.encode(topic, {
  id: 1,
  jsonrpc: "2.0", 
  method: "wc_sessionPropose",
  params: proposalParams
});

// Decrypt a message
const decrypted = await crypto.decode(topic, encrypted);

// Key pair structure
const keyPair: CryptoTypes.KeyPair = {
  privateKey: "0x...",
  publicKey: "0x..."
};

// Encryption parameters
const encryptParams: CryptoTypes.EncryptParams = {
  message: "Hello, WalletConnect!",
  symKey: "0x...",
  type: 1,
  senderPublicKey: "0x..."
};

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