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 fa4689d commit 4d719d6
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 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,
Expand Down Expand Up @@ -52,6 +53,35 @@ 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,
};
}

const voteHash = utils.bech32_decodeAddress(cert.vote).toString('hex');

if (cert.vote.includes('_script')) {
return {
type: PROTO.CardanoDRepType.SCRIPT_HASH,
scriptHash: voteHash,
};
}

return {
type: PROTO.CardanoDRepType.KEY_HASH,
keyHash: voteHash,
};
};

export const toTrezorCertificate = (cert: CoinSelectionCertificate) => {
if (cert.pool) {
return {
Expand All @@ -61,6 +91,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),
Expand Down

0 comments on commit 4d719d6

Please sign in to comment.