|
| 1 | +# Trezor Master Key Generation Types |
| 2 | + |
| 3 | +This package now supports multiple master key generation algorithms for Trezor hardware wallets, allowing compatibility with different wallet implementations and enabling seamless integration with various existing wallet types. |
| 4 | + |
| 5 | +## Supported Master Key Generation Types |
| 6 | + |
| 7 | +### 1. ICARUS |
| 8 | +- Standard CIP-3 wallet compatibility mode |
| 9 | + |
| 10 | +### 2. ICARUS_TREZOR |
| 11 | +- CIP-3 variant with 24-word mnemonic compatibility |
| 12 | +- This is Trezor's internal default (SDK passes no `derivationType`) |
| 13 | + |
| 14 | +### 3. LEDGER |
| 15 | +- Ledger hardware wallet compatibility mode |
| 16 | +- Use this if your wallet was originally created on a Ledger device |
| 17 | +- Enables access to Ledger-generated accounts on Trezor hardware |
| 18 | + |
| 19 | +## Key Concept |
| 20 | + |
| 21 | +All types use the same derivation path but different master key generation algorithms from the mnemonic. The `derivationType` tells Trezor which algorithm to use. |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +### Importing Types and Constants |
| 26 | + |
| 27 | +All types and constants are fully exportable from their respective packages: |
| 28 | + |
| 29 | +```typescript |
| 30 | +// Core constants |
| 31 | +import { |
| 32 | + HD_WALLET_CIP_ID, |
| 33 | + Cardano |
| 34 | +} from '@cardano-sdk/core'; |
| 35 | + |
| 36 | +// Key management types |
| 37 | +import { |
| 38 | + TrezorConfig, |
| 39 | + KeyPurpose, |
| 40 | + MasterKeyGeneration |
| 41 | +} from '@cardano-sdk/key-management'; |
| 42 | + |
| 43 | +// Hardware Trezor implementation |
| 44 | +import { TrezorKeyAgent } from '@cardano-sdk/hardware-trezor'; |
| 45 | +``` |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +### Basic Configuration |
| 50 | + |
| 51 | +```typescript |
| 52 | +import { TrezorConfig, MasterKeyGeneration } from '@cardano-sdk/key-management'; |
| 53 | + |
| 54 | +const trezorConfig: TrezorConfig = { |
| 55 | + communicationType: 'web', |
| 56 | + manifest: { |
| 57 | + |
| 58 | + appUrl: 'https://myapp.com' |
| 59 | + }, |
| 60 | + // Use CIP-3 master key generation |
| 61 | + derivationType: 'ICARUS' |
| 62 | +}; |
| 63 | +``` |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | +### Creating a Trezor Key Agent |
| 68 | + |
| 69 | +```typescript |
| 70 | +import { TrezorKeyAgent } from '@cardano-sdk/hardware-trezor'; |
| 71 | +import { Cardano } from '@cardano-sdk/core'; |
| 72 | +import { createBip32Ed25519 } from '@cardano-sdk/crypto'; |
| 73 | + |
| 74 | +const dependencies = { |
| 75 | + logger: console, // or your preferred logger |
| 76 | + bip32Ed25519: await createBip32Ed25519() |
| 77 | +}; |
| 78 | + |
| 79 | +const keyAgent = await TrezorKeyAgent.createWithDevice({ |
| 80 | + chainId: Cardano.ChainIds.Mainnet, |
| 81 | + accountIndex: 0, |
| 82 | + trezorConfig: { |
| 83 | + communicationType: 'web', |
| 84 | + manifest: { |
| 85 | + |
| 86 | + appUrl: 'https://myapp.com' |
| 87 | + }, |
| 88 | + derivationType: 'ICARUS' |
| 89 | + } |
| 90 | +}, dependencies); |
| 91 | +``` |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | +## Discovery & UX Guidelines |
| 96 | + |
| 97 | +### Automatic Discovery Pattern |
| 98 | + |
| 99 | +When pairing a Trezor device, follow this discovery pattern to find existing accounts: |
| 100 | + |
| 101 | +1. **Try ICARUS first** - Most common for software wallets |
| 102 | +2. **Try ICARUS_TREZOR** - If balance not found and user has 24-word mnemonic |
| 103 | +3. **Try LEDGER** - If user confirms wallet was originally created on Ledger device |
| 104 | + |
| 105 | +This is why many wallet UIs show a "Derivation type override" dropdown - to help users discover their existing accounts. |
| 106 | + |
| 107 | +### Manual Selection During Onboarding |
| 108 | + |
| 109 | +For applications that prefer explicit user control, consider exposing derivation type selection during the onboarding process: |
| 110 | + |
| 111 | +```typescript |
| 112 | +// Example onboarding flow |
| 113 | +const derivationTypeOptions = [ |
| 114 | + { value: 'ICARUS', label: 'Software Wallet', description: 'Most common for wallets created with software applications' }, |
| 115 | + { value: 'ICARUS_TREZOR', label: 'Trezor Default', description: 'Trezor\'s internal default (24-word mnemonic compatible)' }, |
| 116 | + { value: 'LEDGER', label: 'Ledger Hardware Wallet', description: 'For wallets originally created on Ledger devices' } |
| 117 | +]; |
| 118 | + |
| 119 | +// Let user select during onboarding |
| 120 | +const selectedDerivationType = await showDerivationTypeSelection(derivationTypeOptions); |
| 121 | + |
| 122 | +const keyAgent = await TrezorKeyAgent.createWithDevice({ |
| 123 | + chainId: Cardano.ChainIds.Mainnet, |
| 124 | + trezorConfig: { |
| 125 | + communicationType: 'web', |
| 126 | + manifest: { email: '[email protected]', appUrl: 'https://myapp.com' }, |
| 127 | + derivationType: selectedDerivationType |
| 128 | + } |
| 129 | +}, dependencies); |
| 130 | +``` |
| 131 | + |
| 132 | +**Benefits of Manual Selection:** |
| 133 | +- **User Control**: Users explicitly choose their derivation type |
| 134 | +- **Multi-Wallet Support**: Users can create multiple wallets with different derivation types |
| 135 | +- **Transparency**: Clear understanding of which derivation type is being used |
| 136 | +- **No Guessing**: Eliminates the need for automatic discovery patterns |
| 137 | + |
| 138 | +**When to Use Manual Selection:** |
| 139 | +- Applications that prioritize user control and transparency |
| 140 | +- Multi-wallet applications where users might have accounts with different derivation types |
| 141 | +- Enterprise applications where explicit configuration is preferred |
| 142 | +- When users have used multiple wallet types and need to access different accounts |
| 143 | + |
| 144 | +## Implementation Details |
| 145 | + |
| 146 | +When a non-default derivation type is specified, the SDK sets the appropriate `derivationType` in the `cardanoSignTransaction` call. For the default type, no `derivationType` is sent to Trezor. |
| 147 | + |
| 148 | +## Backward Compatibility |
| 149 | + |
| 150 | +Existing wallets without a `derivationType` configuration will continue to work as before. No changes are required for existing users. |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | +## References |
| 155 | + |
| 156 | +- **[CIP-1852](https://cips.cardano.org/cip/CIP-1852)**: HD paths and role meanings |
| 157 | +- **[CIP-3](https://cips.cardano.org/cip/CIP-3)**: Master key generation and 24-word compatibility note |
| 158 | +- **[Trezor Forum](https://forum.trezor.io/t/cardano-ada-transaction-signing-error/10466)**: Community discussion on derivation types |
| 159 | +- **[Cardano Stack Exchange](https://cardano.stackexchange.com/questions/5977/how-does-ledger-generate-the-public-keys)**: Ledger key generation details |
| 160 | +- **[Cardano Foundation](https://cardano-foundation.github.io/cardano-wallet/concepts/master-key-generation)**: Master key generation background |
0 commit comments