Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conway #20

Merged
merged 3 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
"bech",
"cardano",
"cbor",
"Deleg",
"deregistration",
"ipfs",
"DREP",
"fixability",
"ipfs",
"multiasset",
"multiassets",
"reserialized",
Expand Down
46 changes: 46 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Change Log

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [3.0.0] - [December 21th 2023]

### Added

- support for Conway transaction body elements
- optional 258 tags for sets

### Changed

- credential types are generalized

### Fixed

- some missing validations were added
- treatment of tag 30 (no longer removed when decoding CBOR)


## [2.0.0] - [December 9th 2022]

### Added

### Changed

API related to raw transactions --- cardano-cli had moved away from its raw tx file format towards a CDDL-compliant one.

### Fixed


## [1.0.0] - [August 12th 2022]

First release supporting Babbage transaction elements.

### Added

### Changed

### Fixed

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cardano-hw-interop-lib",
"version": "2.0.2",
"version": "3.0.0",
"files": [
"dist"
],
Expand Down
82 changes: 53 additions & 29 deletions src/errors/parseError.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
export enum ParseErrorReason {
INVALID_ADDRESS = 'Invalid address',
INVALID_REWARD_ACCOUNT = 'Invalid reward account',
INVALID_COIN = 'Invalid coin',
INVALID_EPOCH = 'Invalid epoch',

INVALID_POLICY_ID = 'Invalid policy id',
INVALID_ASSET_NAME = 'Invalid asset name',
INVALID_MULTIASSET = 'Invalid multiasset map',

INVALID_TRANSACTION_ID = 'Invalid transaction id',
INVALID_TX_INPUT_INDEX = 'Invalid transaction input index',
INVALID_TX_INPUT = 'Invalid transaction input',
INVALID_TX_INPUTS = 'Invalid transaction inputs',

INVALID_POLICY_ID = 'Invalid policy id',
INVALID_ASSET_NAME = 'Invalid asset name',
INVALID_MULTIASSET = 'Invalid multiasset map',
INVALID_OUTPUT_ADDRESS = 'Invalid output address',
INVALID_OUTPUT_AMOUNT = 'Invalid output amount',
INVALID_OUTPUT_MULTIASSET = 'Invalid output multiasset',
Expand All @@ -21,12 +18,18 @@ export enum ParseErrorReason {
INVALID_OUTPUT_DATUM = 'Invalid output datum',
INVALID_OUTPUT_REFERENCE_SCRIPT = 'Invalid output reference script',
INVALID_TX_OUTPUT = 'Invalid transaction output',
INVALID_TX_OUTPUTS = 'Invalid transaction outputs',

INVALID_FEE = 'Invalid transaction fee',

INVALID_TTL = 'Invalid transaction ttl',

INVALID_CERTIFICATE_TYPE = 'Invalid certificate type',
INVALID_STAKE_CREDENTIAL_TYPE = 'Invalid stake credential type',
INVALID_STAKE_CREDENTIAL_KEY_HASH = 'Invalid stake credential key hash',
INVALID_STAKE_CREDENTIAL_SCRIPT_HASH = 'Invalid stake credential script hash',
INVALID_STAKE_CREDENTIAL = 'Invalid stake credential',
INVALID_CERTIFICATE = 'Invalid certificate',
INVALID_CREDENTIAL_TYPE = 'Invalid credential type',
INVALID_CREDENTIAL_KEY_HASH = 'Invalid credential key hash',
INVALID_CREDENTIAL_SCRIPT_HASH = 'Invalid credential script hash',
INVALID_CREDENTIAL = 'Invalid credential',
INVALID_POOL_KEY_HASH = 'Invalid pool key hash',
INVALID_VRF_KEY_HASH = 'Invalid vrf key hash',
INVALID_POOL_PARAMS = 'Invalid pool params',
Expand All @@ -42,40 +45,61 @@ export enum ParseErrorReason {
INVALID_RELAY_DNS_NAME = 'Invalid relay DNS name',
INVALID_RELAY = 'Invalid relay',
INVALID_RELAYS = 'Invalid relays',
INVALID_POOL_METADATA_URL = 'Invalid pool metadata url',
INVALID_POOL_METADATA_URL = 'Invalid pool metadata URL',
INVALID_POOL_METADATA_METADATA_HASH = 'Invalid pool metadata metadata hash',
INVALID_POOL_METADATA = 'Invalid pool metadata',
INVALID_CERTIFICATE = 'Invalid certificate',
INVALID_EPOCH = 'Invalid epoch',
INVALID_DREP_TYPE = 'Invalid DRep type',
INVALID_DREP = 'Invalid DRep',
INVALID_ANCHOR = 'Invalid anchor',
INVALID_ANCHOR_URL = 'Invalid anchor URL',
INVALID_ANCHOR_DATA_HASH = 'Invalid anchor data hash',
INVALID_CERTIFICATES = 'Invalid transaction certificates',

INVALID_WITHDRAWAL_AMOUNT = 'Invalid withdrawal amount',

INVALID_MINT_AMOUNT = 'Invalid mint amount',

INVALID_COLLATERAL_INPUT_INDEX = 'Invalid transaction collateral input index',
INVALID_COLLATERAL_INPUT = 'Invalid transaction collateral input',

INVALID_REFERENCE_INPUT_INDEX = 'Invalid transaction reference input index',
INVALID_REFERENCE_INPUT = 'Invalid transaction reference input',

INVALID_TX_BODY_CBOR = 'Invalid transaction body CBOR',
INVALID_TX_BODY_UNKNOWN_ITEMS = 'Transaction body contains unknown items',
INVALID_TX_INPUTS = 'Invalid transaction inputs',
INVALID_TX_OUTPUTS = 'Invalid transaction outputs',
INVALID_FEE = 'Invalid transaction fee',
INVALID_TTL = 'Invalid transaction ttl',
INVALID_CERTIFICATES = 'Invalid transaction certificates',
INVALID_REWARD_ACCOUNT = 'Invalid reward account',
INVALID_WITHDRAWALS = 'Invalid transaction withdrawals',

INVALID_AUXILIARY_DATA_HASH = 'Invalid transaction auxiliary data hash',

INVALID_VALIDITY_INTERVAL_START = 'Invalid transaction validity interval start',

INVALID_MINT_AMOUNT = 'Invalid mint amount',
INVALID_MINT = 'Invalid transaction mint',

INVALID_SCRIPT_DATA_HASH = 'Invalid transaction script data hash',

INVALID_COLLATERAL_INPUT_INDEX = 'Invalid transaction collateral input index',
INVALID_COLLATERAL_INPUT = 'Invalid transaction collateral input',
INVALID_COLLATERAL_INPUTS = 'Invalid transaction collateral inputs',

INVALID_REQUIRED_SIGNERS = 'Invalid transaction required signers',

INVALID_NETWORK_ID = 'Invalid transaction network id',

INVALID_TOTAL_COLLATERAL = 'Invalid transaction total collateral',

INVALID_REFERENCE_INPUT_INDEX = 'Invalid transaction reference input index',
INVALID_REFERENCE_INPUT = 'Invalid transaction reference input',
INVALID_REFERENCE_INPUTS = 'Invalid transaction reference inputs',

INVALID_VOTING_PROCEDURES = 'Invalid transaction voting procedures',
INVALID_VOTING_PROCEDURES_EMPTY_MAP = 'Invalid transaction voting procedures --- an empty map included',
INVALID_VOTER = 'Invalid voter',
INVALID_GOV_ACTION_ID = 'Invalid governance action id',
INVALID_VOTE_OPTION = 'Invalid vote',
INVALID_VOTING_PROCEDURE = 'Invalid voting procedure',

INVALID_PROPOSAL_PROCEDURES = 'Invalid proposal procedures',
INVALID_PROPOSAL_PROCEDURE = 'Invalid proposal procedure',

INVALID_TREASURY = 'Invalid treasury',

INVALID_DONATION = 'Invalid donation',

INVALID_TX_CBOR = 'Invalid transaction CBOR',
INVALID_TX_BODY_CBOR = 'Invalid transaction body CBOR',
INVALID_TX_BODY_UNKNOWN_ITEMS = 'Transaction body contains unknown items',
}

export class ParseError extends Error {
Expand Down
59 changes: 50 additions & 9 deletions src/errors/validationError.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
export enum ValidationErrorReason {
// Unfixable validation errors
UNSUPPORTED_TX_UPDATE = 'The transaction body entry update must not be included',
UNSUPPORTED_TX_PROPOSAL_PROCEDURES = 'The transaction body entry proposal_procedures must not be included',
UNSUPPORTED_CERTIFICATE_GENESIS_KEY_DELEGATION = 'Certificate of type genesis_key_delegation is not supported and must not be included',
UNSUPPORTED_CERTIFICATE_MOVE_INSTANTANEOUS_REWARDS_CERT = 'Certificate of type move_instantaneous_rewards_cert is not supported and must not be included',
UNSUPPORTED_CERTIFICATE_STAKE_VOTE_DELEG = 'Certificate of type stake_vote_deleg_cert is not supported and must not be included',
UNSUPPORTED_CERTIFICATE_STAKE_REG_DELEG = 'Certificate of type stake_reg_deleg_cert is not supported and must not be included',
UNSUPPORTED_CERTIFICATE_VOTE_REG_DELEG = 'Certificate of type vote_reg_deleg_cert is not supported and must not be included',
UNSUPPORTED_CERTIFICATE_STAKE_VOTE_REG_DELEG = 'Certificate of type stake_vote_reg_deleg_cert is not supported and must not be included',
INTEGER_NOT_INT64 = 'Hardware wallets support integers up to int64, integers from -2^63 to 2^63-1',
UNSIGNED_INTEGER_NOT_UINT64 = 'Hardware wallets support unsigned integers up to uint64, unsigned integers from 0 to 2^64-1',
NUMBER_OF_ELEMENTS_EXCEEDS_UINT16 = 'The number of transaction elements individually must not exceed UINT16_MAX, i.e. 65535',
CERTIFICATES_MUST_HAVE_THE_SAME_TYPE_OF_STAKE_CREDENTIAL = 'All certificates included in a transaction must have the same type of stake credential',
WITHDRAWALS_MUST_HAVE_THE_SAME_TYPE_OF_STAKE_CREDENTIAL = 'All withdrawals included in a transaction must have the same type of stake credential',
CERTIFICATES_AND_WITHDRAWALS_STAKE_CREDENTIAL_TYPES_MUST_BE_CONSISTENT = 'The stake credential type of certificates must be consistent with the type used for withdrawals',
POOL_REGISTRATION_CERTIFICATE_WITH_OTHER_CERTIFICATES = 'If a transaction contains a pool registration certificate, then it must not contain any other certificate',
POOL_REGISTRATION_CERTIFICATE_WITH_WITHDRAWALS = 'If a transaction contains a pool registration certificate, then it must not contain any withdrawal',
POOL_REGISTRATION_CERTIFICATE_WITH_MINT_ENTRY = 'If a transaction contains a pool registration certificate, then it must not contain mint entry',
POOL_REGISTRATION_CERTIFICATE_WITH_PLUTUS_OUTPUTS = 'If a transaction contains a pool registration certificate, then it must not contain datums and reference scripts in outputs',
POOL_REGISTRATION_CERTIFICATE_WITH_SCRIPT_DATA_HASH = 'If a transaction contains a pool registration certificate, then it must not contain script data hash',
POOL_REGISTRATION_CERTIFICATE_WITH_COLLATERAL_INPUTS = 'If a transaction contains a pool registration certificate, then it must not contain collateral inputs',
POOL_REGISTRATION_CERTIFICATE_WITH_REQUIRED_SIGNERS = 'If a transaction contains a pool registration certificate, then it must not contain required signers',
POOL_REGISTRATION_CERTIFICATE_WITH_COLLATERAL_RETURN_OUTPUT = 'If a transaction contains a pool registration certificate, then it must not contain collateral return output',
POOL_REGISTRATION_CERTIFICATE_WITH_TOTAL_COLLATERAL = 'If a transaction contains a pool registration certificate, then it must not contain total collateral',
POOL_REGISTRATION_CERTIFICATE_WITH_REFERENCE_INPUTS = 'If a transaction contains a pool registration certificate, then it must not contain reference inputs',
POOL_REGISTRATION_CERTIFICATE_WITH_VOTING_PROCEDURES = 'If a transaction contains a pool registration certificate, then it must not contain voting procedures',
POOL_REGISTRATION_CERTIFICATE_WITH_TREASURY = 'If a transaction contains a pool registration certificate, then it must not contain treasury value entry',
POOL_REGISTRATION_CERTIFICATE_WITH_DONATION = 'If a transaction contains a pool registration certificate, then it must not contain treasury donation entry',
TOO_MANY_VOTERS_IN_VOTING_PROCEDURES = 'Only a single voter is allowed in voting procedures',
INVALID_NUMBER_OF_VOTING_PROCEDURES = 'There must be exactly one voting procedure per voter',

// Fixable validation errors
CBOR_IS_NOT_CANONICAL = 'CBOR is not canonical',
Expand All @@ -21,32 +35,58 @@ export enum ValidationErrorReason {
REFERENCE_SCRIPT_MUST_NOT_BE_EMPTY_IF_DEFINED = 'Reference script must not be empty if defined',
COLLATERAL_RETURN_MUST_NOT_CONTAIN_DATUM = 'Collateral return must not contain datum',
COLLATERAL_RETURN_MUST_NOT_CONTAIN_REFERENCE_SCRIPT = 'Collateral return must not contain reference script',
TX_INCONSISTENT_SET_TAGS = 'Inconsistent set tags 258 across the transaction body',
}

const FIXABLE = true
const UNFIXABLE = false

const validationErrorFixability: Record<ValidationErrorReason, boolean> = {
// unfixable
[ValidationErrorReason.UNSUPPORTED_TX_UPDATE]: UNFIXABLE,
[ValidationErrorReason.UNSUPPORTED_TX_PROPOSAL_PROCEDURES]: UNFIXABLE,
[ValidationErrorReason.UNSUPPORTED_CERTIFICATE_GENESIS_KEY_DELEGATION]:
UNFIXABLE,
[ValidationErrorReason.UNSUPPORTED_CERTIFICATE_MOVE_INSTANTANEOUS_REWARDS_CERT]:
UNFIXABLE,
[ValidationErrorReason.UNSUPPORTED_CERTIFICATE_STAKE_VOTE_DELEG]: UNFIXABLE,
[ValidationErrorReason.UNSUPPORTED_CERTIFICATE_STAKE_REG_DELEG]: UNFIXABLE,
[ValidationErrorReason.UNSUPPORTED_CERTIFICATE_VOTE_REG_DELEG]: UNFIXABLE,
[ValidationErrorReason.UNSUPPORTED_CERTIFICATE_STAKE_VOTE_REG_DELEG]:
UNFIXABLE,
[ValidationErrorReason.INTEGER_NOT_INT64]: UNFIXABLE,
[ValidationErrorReason.UNSIGNED_INTEGER_NOT_UINT64]: UNFIXABLE,
[ValidationErrorReason.NUMBER_OF_ELEMENTS_EXCEEDS_UINT16]: UNFIXABLE,
[ValidationErrorReason.CERTIFICATES_MUST_HAVE_THE_SAME_TYPE_OF_STAKE_CREDENTIAL]:
UNFIXABLE,
[ValidationErrorReason.WITHDRAWALS_MUST_HAVE_THE_SAME_TYPE_OF_STAKE_CREDENTIAL]:
UNFIXABLE,
[ValidationErrorReason.CERTIFICATES_AND_WITHDRAWALS_STAKE_CREDENTIAL_TYPES_MUST_BE_CONSISTENT]:
UNFIXABLE,
[ValidationErrorReason.POOL_REGISTRATION_CERTIFICATE_WITH_OTHER_CERTIFICATES]:
UNFIXABLE,
[ValidationErrorReason.POOL_REGISTRATION_CERTIFICATE_WITH_WITHDRAWALS]:
UNFIXABLE,
[ValidationErrorReason.POOL_REGISTRATION_CERTIFICATE_WITH_MINT_ENTRY]:
UNFIXABLE,
[ValidationErrorReason.POOL_REGISTRATION_CERTIFICATE_WITH_PLUTUS_OUTPUTS]:
UNFIXABLE,
[ValidationErrorReason.POOL_REGISTRATION_CERTIFICATE_WITH_SCRIPT_DATA_HASH]:
UNFIXABLE,
[ValidationErrorReason.POOL_REGISTRATION_CERTIFICATE_WITH_COLLATERAL_INPUTS]:
UNFIXABLE,
[ValidationErrorReason.POOL_REGISTRATION_CERTIFICATE_WITH_REQUIRED_SIGNERS]:
UNFIXABLE,
[ValidationErrorReason.POOL_REGISTRATION_CERTIFICATE_WITH_COLLATERAL_RETURN_OUTPUT]:
UNFIXABLE,
[ValidationErrorReason.POOL_REGISTRATION_CERTIFICATE_WITH_TOTAL_COLLATERAL]:
UNFIXABLE,
[ValidationErrorReason.POOL_REGISTRATION_CERTIFICATE_WITH_REFERENCE_INPUTS]:
UNFIXABLE,
[ValidationErrorReason.POOL_REGISTRATION_CERTIFICATE_WITH_VOTING_PROCEDURES]:
UNFIXABLE,
[ValidationErrorReason.POOL_REGISTRATION_CERTIFICATE_WITH_TREASURY]:
UNFIXABLE,
[ValidationErrorReason.POOL_REGISTRATION_CERTIFICATE_WITH_DONATION]:
UNFIXABLE,
[ValidationErrorReason.TOO_MANY_VOTERS_IN_VOTING_PROCEDURES]: UNFIXABLE,
[ValidationErrorReason.INVALID_NUMBER_OF_VOTING_PROCEDURES]: UNFIXABLE,

// fixable
[ValidationErrorReason.CBOR_IS_NOT_CANONICAL]: FIXABLE,
[ValidationErrorReason.OPTIONAL_EMPTY_LISTS_AND_MAPS_MUST_NOT_BE_INCLUDED]:
FIXABLE,
Expand All @@ -58,6 +98,7 @@ const validationErrorFixability: Record<ValidationErrorReason, boolean> = {
[ValidationErrorReason.COLLATERAL_RETURN_MUST_NOT_CONTAIN_DATUM]: FIXABLE,
[ValidationErrorReason.COLLATERAL_RETURN_MUST_NOT_CONTAIN_REFERENCE_SCRIPT]:
FIXABLE,
[ValidationErrorReason.TX_INCONSISTENT_SET_TAGS]: FIXABLE,
}

export type ValidationError = {
Expand Down
Loading