Skip to content

Commit bda86db

Browse files
chore(hardware-trezor): apply requested changes
1 parent beda310 commit bda86db

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

packages/hardware-trezor/src/transformers/keyPaths.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BIP32Path } from '@cardano-sdk/crypto';
22
import { Cardano } from '@cardano-sdk/core';
3+
import { GroupedAddress, TxInId, util } from '@cardano-sdk/key-management';
34
import { TrezorTxTransformerContext } from '../types';
4-
import { TxInId, util } from '@cardano-sdk/key-management';
55

66
/** Uses the given Trezor input resolver to resolve the payment key path for known addresses for given input transaction. */
77
export const resolvePaymentKeyPathForTxIn = (
@@ -16,12 +16,10 @@ export const resolvePaymentKeyPathForTxIn = (
1616
};
1717

1818
export const resolveStakeKeyPath = (
19-
rewardAddress: Cardano.RewardAddress | undefined,
20-
context?: TrezorTxTransformerContext
19+
rewardAddress: Cardano.RewardAddress,
20+
knownAddresses: GroupedAddress[]
2121
): BIP32Path | null => {
22-
if (!rewardAddress) return null;
23-
24-
const knownAddress = context?.knownAddresses.find(
22+
const knownAddress = knownAddresses.find(
2523
({ rewardAccount }) => rewardAccount === rewardAddress.toAddress().toBech32()
2624
);
2725
return util.stakeKeyPathFromGroupedAddress(knownAddress);

packages/hardware-trezor/src/transformers/withdrawals.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const toTrezorWithdrawal: Transform<Cardano.Withdrawal, Trezor.CardanoWit
2222
* - The script hash, blake2b-224 hash digests of serialized monetary scripts.
2323
*/
2424
if (rewardAddress.getPaymentCredential().type === Cardano.CredentialType.KeyHash) {
25-
const keyPath = resolveStakeKeyPath(rewardAddress, context);
25+
const keyPath = context?.knownAddresses ? resolveStakeKeyPath(rewardAddress, context.knownAddresses) : null;
2626
trezorWithdrawal = keyPath
2727
? {
2828
amount: withdrawal.quantity.toString(),

packages/hardware-trezor/test/testData.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export const txOutWithReferenceScriptAndInlineDatum: Cardano.TxOut = {
115115
export const rewardKey = 'stake1u89sasnfyjtmgk8ydqfv3fdl52f36x3djedfnzfc9rkgzrcss5vgr';
116116
export const rewardScript = 'stake178phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gtcccycj5';
117117
export const rewardAccount = Cardano.RewardAccount(rewardKey);
118-
export const rewardAddress = Cardano.Address.fromBech32(rewardAccount)?.asReward();
118+
export const rewardAddress = Cardano.Address.fromBech32(rewardAccount)?.asReward() as Cardano.RewardAddress;
119119
export const rewardAccountWithPaymentScriptCredential = Cardano.RewardAccount(rewardScript);
120120
export const stakeKeyHash = Cardano.RewardAccount.toHash(rewardAccount);
121121
export const stakeCredential = {

packages/hardware-trezor/test/transformers/keyPaths.test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ describe('key-paths', () => {
2222
});
2323
describe('resolveStakeKeyPath', () => {
2424
it('returns the stake key path for a known address', async () => {
25-
expect(resolveStakeKeyPath(rewardAddress, contextWithKnownAddresses)).toEqual(knownAddressStakeKeyPath);
25+
expect(resolveStakeKeyPath(rewardAddress, contextWithKnownAddresses.knownAddresses)).toEqual(
26+
knownAddressStakeKeyPath
27+
);
2628
});
2729
});
2830
});

0 commit comments

Comments
 (0)