Skip to content

Commit deea40f

Browse files
committed
fixup! feat(web-extension): support wallet-specific trezorConfig in SigningCoordinator
1 parent 0389e54 commit deea40f

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

packages/web-extension/src/walletManager/SigningCoordinator/SigningCoordinator.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,14 @@ export class SigningCoordinator<WalletMetadata extends {}, AccountMetadata exten
9090
* (e.g., derivationType) while inheriting global settings (e.g., communicationType, manifest)
9191
*/
9292
#getTrezorConfig(wallet: AnyBip32Wallet<WalletMetadata, AccountMetadata>): TrezorConfig {
93+
const trezorConfig =
94+
wallet.type === WalletType.Trezor && 'trezorConfig' in wallet.metadata
95+
? (wallet.metadata as { trezorConfig?: Partial<TrezorConfig> }).trezorConfig
96+
: undefined;
97+
9398
return {
9499
...this.#hwOptions, // Global defaults (communicationType, manifest, etc.)
95-
...(wallet.type === WalletType.Trezor && 'trezorConfig' in wallet && wallet.trezorConfig
96-
? wallet.trezorConfig
97-
: {}) // Wallet-specific overrides (derivationType, etc.)
100+
...(trezorConfig || {}) // Wallet-specific overrides (derivationType, etc.)
98101
};
99102
}
100103

packages/web-extension/src/walletManager/types.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,24 @@ export type Bip32Wallet<WalletMetadata extends {}, AccountMetadata extends {}> =
2929
blockchainName?: Blockchain;
3030
};
3131

32-
export type HardwareWallet<WalletMetadata extends {}, AccountMetadata extends {}> = Bip32Wallet<
32+
export type LedgerHardwareWallet<WalletMetadata extends {}, AccountMetadata extends {}> = Bip32Wallet<
3333
WalletMetadata,
3434
AccountMetadata
3535
> & {
36-
type: WalletType.Ledger | WalletType.Trezor;
37-
trezorConfig?: Partial<TrezorConfig>;
36+
type: WalletType.Ledger;
3837
};
3938

39+
export type TrezorHardwareWallet<
40+
WalletMetadata extends { trezorConfig?: Partial<TrezorConfig> },
41+
AccountMetadata extends {}
42+
> = Bip32Wallet<WalletMetadata, AccountMetadata> & {
43+
type: WalletType.Trezor;
44+
};
45+
46+
export type HardwareWallet<WalletMetadata extends {}, AccountMetadata extends {}> =
47+
| LedgerHardwareWallet<WalletMetadata, AccountMetadata>
48+
| TrezorHardwareWallet<WalletMetadata, AccountMetadata>;
49+
4050
export type InMemoryWallet<WalletMetadata extends {}, AccountMetadata extends {}> = Bip32Wallet<
4151
WalletMetadata,
4252
AccountMetadata

packages/web-extension/test/walletManager/SigningCoordinator.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
KeyPurpose,
77
SignDataContext,
88
SignTransactionContext,
9+
TrezorConfig,
910
cip8,
1011
errors
1112
} from '@cardano-sdk/key-management';
@@ -176,12 +177,13 @@ describe('SigningCoordinator', () => {
176177
});
177178

178179
it('should pass wallet trezorConfig to Trezor key agent factory', async () => {
179-
const trezorWallet: HardwareWallet<{}, {}> = {
180+
const trezorWallet: HardwareWallet<{ trezorConfig?: Partial<TrezorConfig> }, {}> = {
180181
accounts: [createAccount(0, 0)],
181-
metadata: {},
182-
trezorConfig: {
183-
communicationType: CommunicationType.Web,
184-
derivationType: 'ICARUS_TREZOR'
182+
metadata: {
183+
trezorConfig: {
184+
communicationType: CommunicationType.Web,
185+
derivationType: 'ICARUS_TREZOR'
186+
}
185187
},
186188
type: WalletType.Trezor,
187189
walletId: Hash28ByteBase16('ad63f855e831d937457afc52a21a7f351137e4a9fff26c217817335a')

0 commit comments

Comments
 (0)