Skip to content

Commit

Permalink
feat: enable cip-129 for hardware wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonmaslowski committed Jan 27, 2025
1 parent 295cf77 commit 9195bee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
12 changes: 7 additions & 5 deletions source/renderer/app/utils/dataSerialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import blakejs from 'blakejs';
import { encode } from 'borc';
import { utils } from '@cardano-foundation/ledgerjs-hw-app-cardano';
import { base58_decode } from '@cardano-foundation/ledgerjs-hw-app-cardano/dist/utils/address';
import { Cardano } from '@cardano-sdk/core';
import { AddressStyles } from '../domains/WalletAddress';
import {
derivationPathToLedgerPath,
Expand Down Expand Up @@ -182,11 +183,12 @@ const parseVoteDelegation = (vote: string): [number] | [number, Buffer] => {
if (vote === 'abstain') return [2];
if (vote === 'no_confidence') return [3];

const voteHash = Buffer.from(
utils.buf_to_hex(utils.bech32_decodeAddress(vote)),
'hex'
);
return [vote.includes('_script') ? 1 : 0, voteHash];
const { type, hash } = Cardano.DRepID.toCredential(Cardano.DRepID(vote));

return [
type === Cardano.CredentialType.ScriptHash ? 1 : 0,
Buffer.from(hash, 'hex'),
];
};

export function toTxCertificate(cert: {
Expand Down
9 changes: 5 additions & 4 deletions source/renderer/app/utils/shelleyLedger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
base58_decode,
str_to_path,
} from '@cardano-foundation/ledgerjs-hw-app-cardano/dist/utils/address';
import { Cardano } from '@cardano-sdk/core';
import {
CATALYST_VOTING_REGISTRATION_TYPE,
CERTIFICATE_TYPE,
Expand Down Expand Up @@ -67,18 +68,18 @@ const parseVoteDelegation = (
};
}

const votHash = utils.buf_to_hex(utils.bech32_decodeAddress(cert.vote));
const { type, hash } = Cardano.DRepID.toCredential(Cardano.DRepID(cert.vote));

if (cert.vote.includes('_script')) {
if (type === Cardano.CredentialType.ScriptHash) {
return {
type: DRepParamsType.SCRIPT_HASH,
scriptHashHex: votHash,
scriptHashHex: hash,
};
}

return {
type: DRepParamsType.KEY_HASH,
keyHashHex: votHash,
keyHashHex: hash,
};
};

Expand Down

0 comments on commit 9195bee

Please sign in to comment.