Skip to content

Commit

Permalink
feat: add trezor support for VP delegation
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonmaslowski committed Nov 27, 2024
1 parent 534097a commit c01f2f5
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions source/renderer/app/utils/shelleyTrezor.ts
Original file line number Diff line number Diff line change
@@ -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),

0 comments on commit c01f2f5

Please sign in to comment.