From c01f2f51fb0c08fc3fd1fcf848f7e49931e0bfd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mas=C5=82owski?= Date: Tue, 26 Nov 2024 14:53:40 +0100 Subject: [PATCH] feat: add trezor support for VP delegation --- source/renderer/app/utils/shelleyTrezor.ts | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/source/renderer/app/utils/shelleyTrezor.ts b/source/renderer/app/utils/shelleyTrezor.ts index 6f3a53be67..6a7f32d2ab 100644 --- a/source/renderer/app/utils/shelleyTrezor.ts +++ b/source/renderer/app/utils/shelleyTrezor.ts @@ -1,5 +1,6 @@ import { utils } from '@cardano-foundation/ledgerjs-hw-app-cardano'; import { Messages } from '@trezor/transport'; +import { CardanoDRep, PROTO } from '@trezor/connect'; import { map } from 'lodash'; import { derivationPathToString, @@ -52,6 +53,33 @@ export const toTrezorOutput = (output: CoinSelectionOutput) => { tokenBundle, }; }; + +const parseVoteDelegation = (cert: CoinSelectionCertificate): CardanoDRep => { + if (cert.vote === 'abstain') { + return { + type: PROTO.CardanoDRepType.ABSTAIN, + }; + } + + if (cert.vote === 'no_confidence') { + return { + type: PROTO.CardanoDRepType.NO_CONFIDENCE, + }; + } + + if (cert.vote.includes('_script')) { + return { + type: PROTO.CardanoDRepType.SCRIPT_HASH, + scriptHash: cert.vote, + }; + } + + return { + type: PROTO.CardanoDRepType.KEY_HASH, + keyHash: cert.vote, + }; +}; + export const toTrezorCertificate = (cert: CoinSelectionCertificate) => { if (cert.pool) { return { @@ -61,6 +89,14 @@ export const toTrezorCertificate = (cert: CoinSelectionCertificate) => { }; } + if (cert.certificateType === 'cast_vote' && 'vote' in cert) { + return { + type: PROTO.CardanoCertificateType.VOTE_DELEGATION, + path: derivationPathToString(cert.rewardAccountPath), + dRep: parseVoteDelegation(cert), + }; + } + return { type: CERTIFICATE_TYPE[cert.certificateType], path: derivationPathToString(cert.rewardAccountPath),