forked from trezor/connect
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cardano): add support for catalyst voting registration
- Loading branch information
1 parent
4cd54eb
commit 5631472
Showing
11 changed files
with
564 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* @flow */ | ||
import { addressParametersToProto, validateAddressParameters } from './cardanoAddressParameters'; | ||
import { validateParams } from './paramsValidator'; | ||
import { validatePath } from '../../../utils/pathUtils'; | ||
|
||
import type { | ||
CardanoTxAuxiliaryDataType, | ||
CardanoTxMetadataType, | ||
CardanoCatalystRegistrationParametersType, | ||
} from '../../../types/trezor/protobuf'; | ||
import type { | ||
CardanoAuxiliaryData, | ||
CardanoMetadata, | ||
CardanoCatalystRegistrationParameters, | ||
} from '../../../types/networks/cardano'; | ||
|
||
const transformCatalystRegistrationParameters = ( | ||
catalystRegistrationParameters: CardanoCatalystRegistrationParameters, | ||
): CardanoCatalystRegistrationParametersType => { | ||
validateParams(catalystRegistrationParameters, [ | ||
{ name: 'votingPublicKey', type: 'string', obligatory: true }, | ||
{ name: 'stakingPath', obligatory: true }, | ||
{ name: 'nonce', type: 'number', obligatory: true }, | ||
]); | ||
validateAddressParameters(catalystRegistrationParameters.rewardAddressParameters); | ||
|
||
return { | ||
voting_public_key: catalystRegistrationParameters.votingPublicKey, | ||
staking_path: validatePath(catalystRegistrationParameters.stakingPath, 3), | ||
reward_address_parameters: addressParametersToProto( | ||
catalystRegistrationParameters.rewardAddressParameters, | ||
), | ||
nonce: catalystRegistrationParameters.nonce, | ||
}; | ||
}; | ||
|
||
const transformMetadata = (metadata: CardanoMetadata): CardanoTxMetadataType => { | ||
validateParams(metadata, [{ name: 'type', type: 'number', obligatory: true }]); | ||
|
||
let catalystRegistrationParameters; | ||
if (metadata.catalystRegistrationParameters) { | ||
catalystRegistrationParameters = transformCatalystRegistrationParameters( | ||
metadata.catalystRegistrationParameters, | ||
); | ||
} | ||
|
||
return { | ||
type: metadata.type, | ||
catalyst_registration_parameters: catalystRegistrationParameters, | ||
}; | ||
}; | ||
|
||
export const transformAuxiliaryData = ( | ||
auxiliaryData: CardanoAuxiliaryData, | ||
): CardanoTxAuxiliaryDataType => { | ||
validateParams(auxiliaryData, [ | ||
{ | ||
name: 'type', | ||
type: 'number', | ||
obligatory: true, | ||
}, | ||
{ | ||
name: 'blob', | ||
type: 'string', | ||
}, | ||
]); | ||
|
||
let metadata; | ||
if (auxiliaryData.metadata) { | ||
metadata = transformMetadata(auxiliaryData.metadata); | ||
} | ||
|
||
return { | ||
type: auxiliaryData.type, | ||
blob: auxiliaryData.blob, | ||
metadata, | ||
}; | ||
}; |
Oops, something went wrong.