Skip to content

Commit

Permalink
feat: support vote delegation also on BitBox hw wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
refi93 committed Nov 20, 2024
1 parent b79a52e commit a82ba4d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
27 changes: 22 additions & 5 deletions app/frontend/wallet/shelley/shelley-bitbox02-crypto-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import {
CryptoProviderType,
Network,
TxCertificate,
TxDRepType,
TxInput,
TxOutput,
TxShelleyWitness,
TxVoteDelegationCert,
} from '../types'
import {encodeCbor} from '../helpers/cbor'
import {safeAssertUnreachable} from '../../helpers/common'

import {
import type {
CardanoAssetGroup,
CardanoCertificate,
CardanoInput,
Expand Down Expand Up @@ -175,6 +177,23 @@ const ShelleyBitBox02CryptoProvider = async ({
}
}

const prepareVoteDelegation = (
voteDelegation: TxVoteDelegationCert,
addressToAbsPathMapper: AddressToPathMapper
): CardanoCertificate => {
switch (voteDelegation.dRep.type) {
case TxDRepType.ALWAYS_ABSTAIN:
return {
voteDelegation: {
keypath: addressToAbsPathMapper(voteDelegation.stakingAddress),
type: 'alwaysAbstain',
},
}
default:
return safeAssertUnreachable(voteDelegation.dRep.type)
}
}

const prepareCertificate = (
certificate: TxCertificate,
addressToAbsPathMapper: AddressToPathMapper
Expand All @@ -199,14 +218,12 @@ const ShelleyBitBox02CryptoProvider = async ({
poolKeyhash: Buffer.from(certificate.poolHash, 'hex'),
},
}
case CertificateType.VOTE_DELEGATION:
return prepareVoteDelegation(certificate, addressToAbsPathMapper)
case CertificateType.STAKEPOOL_REGISTRATION:
throw new UnexpectedError(UnexpectedErrorReason.UnsupportedOperationError, {
message: 'Stakepool registration not supported',
})
case CertificateType.VOTE_DELEGATION:
throw new UnexpectedError(UnexpectedErrorReason.UnsupportedOperationError, {
message: 'Vote delegation not supported',
})
default:
return safeAssertUnreachable(certificate)
}
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"babel-polyfill": "6.26.0",
"bignumber.js": "^9.0.2",
"bip39-light": "^1.0.7",
"bitbox-api": "^0.5.0",
"bitbox-api": "^0.8.0",
"cardano-crypto.js": "^6.1.2",
"cbor": "^8.1.0",
"chacha-js": "^2.1.1",
Expand Down
8 changes: 4 additions & 4 deletions app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1291,10 +1291,10 @@ bip66@^1.1.5:
dependencies:
safe-buffer "^5.0.1"

bitbox-api@^0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/bitbox-api/-/bitbox-api-0.5.0.tgz#c1d002ba9b72a8032ff1b5d2ff3ef1113ff515f7"
integrity sha512-5VFN01Kk/iUgFvXm5lPBepvf6bM8cv6LQFGBjgkTiTuusGdmCcSjDiVqQrMvBhJUMLoBkAFf7QsFDw3G/RaQ9w==
bitbox-api@^0.8.0:
version "0.8.0"
resolved "https://registry.yarnpkg.com/bitbox-api/-/bitbox-api-0.8.0.tgz#17cbbb58ab040a83de9e2f724a4509985c9e9fd2"
integrity sha512-lRDxS818osr9hrdmkEmbpsAZ1bWPSfU3qokpAZEWVSMTBKYE2GZ0Y4ZpNwdC5Cxmqj+zEo7hrpCJXYC7mqjw9w==

bitcoin-ops@^1.3.0, bitcoin-ops@^1.4.1:
version "1.4.1"
Expand Down

0 comments on commit a82ba4d

Please sign in to comment.