@cardano-sdk/hardware-trezor

中文文档
0.7.39发布于 2026/09/25Apache-2.0TypeScriptESM + CJS近 30 天下载 3.8万

Mappings and integration with Trezor hardware

原始使用文档
文档目录32 节
  1. Features
  2. Installation
  3. Prerequisites
  4. Quick Setup
  5. Quick Start
  6. Basic Usage
  7. With Custom Derivation Type
  8. Master Key Generation Schemes
  9. ICARUS (Baseline - Software Wallets)
  10. ICARUS_TREZOR (Trezor Hardware Compatibility)
  11. LEDGER (Ledger Hardware Wallet)
  12. Key Difference: ICARUS vs ICARUS_TREZOR
  13. Usage Examples
  14. Configuration
  15. TrezorConfig Interface
  16. Communication Types
  17. API Reference
  18. TrezorKeyAgent
  19. Error Handling
  20. Troubleshooting
  21. Common Issues
  22. Device Setup
  23. Examples
  24. Complete Wallet Integration
  25. Development
  26. Running Tests
  27. Building
  28. Implementation Details
  29. Default Behavior
  30. Related Documentation
  31. License
  32. Support

Cardano JS SDK | Hardware | Trezor

Hardware wallet integration for Trezor devices in the Cardano ecosystem. This package provides secure key management and transaction signing capabilities for Trezor hardware wallets.

Features

  • 🔐 Secure Key Management - Private keys never leave the Trezor device
  • 🔄 Multiple Master Key Generation Schemes - Support for ICARUS, ICARUS_TREZOR, and LEDGER master key generation algorithms
  • 📝 Transaction Signing - Sign Cardano transactions securely on hardware
  • 🏗️ TypeScript Support - Full type safety and IntelliSense support
  • 🔌 Trezor Connect Integration - Built on the official Trezor Connect library

Installation

npm install @cardano-sdk/hardware-trezor
# or
yarn add @cardano-sdk/hardware-trezor

Prerequisites

  • Trezor Device - Model T, One, or newer
  • Trezor Bridge - Required for USB communication
  • Node.js - Version 16.20.1 or higher

Quick Setup

For automated setup of the Trezor testing environment:

# Set up Trezor testing environment (from wallet package)
./packages/wallet/scripts/setup-hw-testing.sh

# Or install Trezor Bridge only
./packages/wallet/scripts/install-trezor-bridge.sh

Quick Start

Basic Usage

import { TrezorKeyAgent } from '@cardano-sdk/hardware-trezor';
import { Cardano, CommunicationType } from '@cardano-sdk/core';

// Create a key agent with default settings
const keyAgent = await TrezorKeyAgent.createWithDevice({
  chainId: Cardano.ChainIds.Mainnet,
  trezorConfig: {
    communicationType: CommunicationType.Node,
    manifest: {
      appUrl: 'https://your-app.com',
      email: '[email protected]'
    }
  }
}, dependencies);

With Custom Derivation Type

import { TrezorKeyAgent } from '@cardano-sdk/hardware-trezor';
import { Cardano, CommunicationType } from '@cardano-sdk/core';

// Create a key agent with specific derivation type
const keyAgent = await TrezorKeyAgent.createWithDevice({
  chainId: Cardano.ChainIds.Mainnet,
  trezorConfig: {
    communicationType: CommunicationType.Node,
    derivationType: 'ICARUS', // or 'ICARUS_TREZOR', 'LEDGER'
    manifest: {
      appUrl: 'https://your-app.com',
      email: '[email protected]'
    }
  }
}, dependencies);

Master Key Generation Schemes

The package supports three master key generation algorithms for compatibility with different wallet types:

ICARUS (Baseline - Software Wallets)

  • Value: 'ICARUS'
  • Use Case: Software wallets
  • Algorithm: Standard CIP-3 (BIP-39 → Ed25519-BIP32)
  • Technical Flow: Mnemonic → entropy → BIP-39 seed (using PBKDF2-HMAC-SHA512, with optional passphrase) → ed25519-bip32 master key (CIP-3 spec)

ICARUS_TREZOR (Trezor Hardware Compatibility)

  • Value: 'ICARUS_TREZOR'
  • Use Case: Trezor hardware wallets
  • Algorithm: Trezor's variant of CIP-3 with different PRF for 24-word mnemonics
  • Technical Details: Trezor historically diverged in how it turned the BIP-39 seed into the root master key when dealing with 24-word mnemonics. Instead of doing a direct Icarus (CIP-3) root generation, firmware used a slightly different PRF step when expanding the seed into the Ed25519-BIP32 master key.

LEDGER (Ledger Hardware Wallet)

  • Value: 'LEDGER'
  • Use Case: Ledger hardware wallets
  • Algorithm: Ledger's CIP-3 implementation

Key Difference: ICARUS vs ICARUS_TREZOR

Behavior:

  • 12/18-word mnemonics: ICARUS and ICARUS_TREZOR produce identical keys
  • 24-word mnemonics: ICARUS and ICARUS_TREZOR produce different keys

⚠️ Important: When restoring a Trezor wallet, use ICARUS_TREZOR for 24-word mnemonics that originated from Trezor devices, otherwise you'll get wrong addresses.

Why it matters: If you're writing code to restore a Trezor wallet, you must select the correct derivation scheme (ICARUS_TREZOR) if the mnemonic came from a Trezor, otherwise you'll get a completely different xpub tree and addresses won't match.

Usage Examples

// Software wallet compatibility
const softwareWallet = await TrezorKeyAgent.createWithDevice({
  chainId: Cardano.ChainIds.Mainnet,
  trezorConfig: { derivationType: 'ICARUS' }
});

// Trezor wallet (uses internal default)
const trezorWallet = await TrezorKeyAgent.createWithDevice({
  chainId: Cardano.ChainIds.Mainnet,
  trezorConfig: { /* no derivationType */ }
});

// Ledger wallet migration
const ledgerWallet = await TrezorKeyAgent.createWithDevice({
  chainId: Cardano.ChainIds.Mainnet,
  trezorConfig: { derivationType: 'LEDGER' }
});

Configuration

TrezorConfig Interface

interface TrezorConfig {
  communicationType: CommunicationType;
  derivationType?: 'ICARUS' | 'ICARUS_TREZOR' | 'LEDGER'; // Master key generation scheme
  manifest: {
    appUrl: string;
    email: string;
  };
  shouldHandlePassphrase?: boolean;
}

Communication Types

  • CommunicationType.Node - USB communication via Trezor Bridge (recommended for Node.js)
  • CommunicationType.Web - Web-based communication (for browser environments)

API Reference

TrezorKeyAgent

createWithDevice(options, dependencies)

Creates a new TrezorKeyAgent instance with a connected Trezor device.

Parameters:

  • options.chainId - Cardano chain ID (Mainnet, Preprod, etc.)
  • options.trezorConfig - Trezor configuration object
  • dependencies - Required dependencies (crypto, logger, etc.)

Returns: Promise<TrezorKeyAgent>

getXpub(props)

Retrieves the extended public key from the Trezor device.

Parameters:

  • props.purpose - Key purpose (Payment, Stake, etc.)
  • props.accountIndex - Account index
  • props.derivationType - Optional master key generation scheme override

Returns: Promise<Bip32PublicKeyHex>

signTransaction(txBody, context)

Signs a Cardano transaction using the Trezor device.

Parameters:

  • txBody - Transaction body to sign
  • context - Signing context (addresses, key paths, etc.)

Returns: Promise<CardanoTxWitnesses>

Error Handling

The package provides comprehensive error handling for common scenarios:

import { TrezorKeyAgent } from '@cardano-sdk/hardware-trezor';

try {
  const keyAgent = await TrezorKeyAgent.createWithDevice(config, deps);
} catch (error) {
  if (error.message.includes('Trezor transport failed')) {
    // Handle device connection issues
    console.error('Please ensure your Trezor device is connected and unlocked');
  } else if (error.message.includes('Authentication failure')) {
    // Handle authentication issues
    console.error('Please check your Trezor device and try again');
  }
}

Troubleshooting

Common Issues

  1. "Trezor transport failed"

    • Ensure Trezor Bridge is installed and running
    • Check USB connection
    • Verify device is unlocked
  2. "Authentication failure"

    • Unlock your Trezor device
    • Close other applications using the device
    • Try reconnecting the device
  3. Wrong master key generation scheme

    • Verify the master key generation scheme matches your wallet's origin
    • Check the MASTER_KEY_GENERATION.md for detailed guidance

Device Setup

  1. Install Trezor Bridge

    # Download from https://suite.trezor.io/trezor-bridge
    # Or install via package manager
    
  2. Connect and Unlock Device

    • Connect your Trezor device via USB
    • Unlock the device using your PIN
    • Ensure no other applications are using the device

Examples

Complete Wallet Integration

import { TrezorKeyAgent } from '@cardano-sdk/hardware-trezor';
import { createPersonalWallet } from '@cardano-sdk/wallet';
import { Cardano, CommunicationType } from '@cardano-sdk/core';

async function createTrezorWallet() {
  // Create key agent
  const keyAgent = await TrezorKeyAgent.createWithDevice({
    chainId: Cardano.ChainIds.Mainnet,
    trezorConfig: {
      communicationType: CommunicationType.Node,
      derivationType: 'ICARUS_TREZOR', // or omit to use Trezor's internal default
      manifest: {
        appUrl: 'https://my-cardano-app.com',
        email: '[email protected]'
      }
    }
  }, dependencies);

  // Create wallet
  const wallet = createPersonalWallet(
    { name: 'My Trezor Wallet' },
    {
      keyAgent,
      // ... other providers
    }
  );

  return wallet;
}

Development

Running Tests

# Run all tests
yarn test

# Run with coverage
yarn test --coverage

# Run specific test file
yarn test TrezorKeyAgent.test.ts

Building

# Build the package
yarn build

# Build and watch for changes
yarn build --watch

Implementation Details

Default Behavior

When no derivationType is specified in the TrezorConfig, the SDK passes no derivation type to Trezor, allowing Trezor to use its own internal default:

const trezorConfig: TrezorConfig = {
  communicationType: CommunicationType.Node,
  manifest: {
    appUrl: 'https://your.application.com',
    email: '[email protected]'
  }
  // No derivationType specified - Trezor uses its internal default
};

## Troubleshooting

### Common Issues

1. **Wrong addresses when restoring Trezor wallet**: Use `ICARUS_TREZOR` for 24-word mnemonics that originated from Trezor devices
2. **Same keys for different schemes**: This is expected for 12/18-word seeds with `ICARUS` and `ICARUS_TREZOR`
3. **Test failures**: Ensure tests account for both 12/18 and 24-word seed scenarios

### Debugging

To determine which scenario you're dealing with:

```typescript
const defaultXPub = defaultKeyAgent.extendedAccountPublicKey;
const icarusXPub = icarusKeyAgent.extendedAccountPublicKey;

if (defaultXPub === icarusXPub) {
  console.log('12/18 word seed detected - ICARUS and ICARUS_TREZOR master key generation schemes are identical');
} else {
  console.log('24 word seed detected - ICARUS and ICARUS_TREZOR master key generation schemes are different');
}

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Support

For issues and questions:

版本与发布记录

@cardano-sdk/hardware-trezor 共发布 106 个版本,首次发布于 2023/10/12;过去 12 个月发布了 7 个版本。

版本发布日期距今
0.7.39latest2026/09/251 个月前
0.7.382026/07/084 个月前
0.7.372026/07/044 个月前
0.7.352026/06/204 个月前
0.7.332026/04/156 个月前
0.7.322026/04/136 个月前

关于 @cardano-sdk/hardware-trezor 的常见问题

@cardano-sdk/hardware-trezor 是什么?

Mappings and integration with Trezor hardware

如何安装 @cardano-sdk/hardware-trezor?

在项目目录运行 npm install @cardano-sdk/hardware-trezor,或使用 pnpm add / yarn add / bun add。

@cardano-sdk/hardware-trezor 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cardano-sdk/hardware-trezor 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cardano-sdk/hardware-trezor 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cardano-sdk/hardware-trezor 可以商用吗?

@cardano-sdk/hardware-trezor 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@cardano-sdk/hardware-trezor 的下载量有多少?

根据 npm 官方下载统计,@cardano-sdk/hardware-trezor 在 2026/10/09 – 2026/11/07 这 30 天内被下载 37,615 次,日均约 1,254 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cardano-sdk/hardware-trezor 还在维护吗?

最新版本 0.7.39 发布于 2026/09/25(1 个月前);至今共发布 106 个版本,其中过去 12 个月发布了 7 个;首次发布于 2023/10/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。