Skip to content

Commit

Permalink
[SQUASH] typos, checking functionality and PLUTUS corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
mkv-vcm authored and janmazak committed Jan 12, 2022
1 parent d3e17c8 commit 6b09bb3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 63 deletions.
12 changes: 5 additions & 7 deletions src/errors/invalidDataReason.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export enum InvalidDataReason {
OUTPUT_INVALID_AMOUNT = "invalid amount in an output",
OUTPUT_INVALID_ADDRESS = "invalid address in an output",
OUTPUT_INVALID_ADDRESS_PARAMS = "change address must have path as payment part",
OUTPUT_INVALID_DATUM_HASH_WITHOUT_SCRIPT_HASH = "datum hash is only allowed when payment or staking is scripthash",
OUTPUT_INVALID_DATUM_HASH_WITHOUT_SCRIPT_HASH = "datum hash is only allowed when the output address contains a scripthash",

MULTIASSET_INVALID_POLICY_NAME = "invalid policy id in a multiasset token bundle",
MULTIASSET_INVALID_TOKEN_BUNDLE_NOT_ARRAY = "invalid multiasset token bundle - asset groups not an array",
Expand Down Expand Up @@ -151,9 +151,9 @@ export enum InvalidDataReason {
SIGN_MODE_ORDINARY__WITHDRAWAL_ONLY_AS_PATH =
"withdrawal must be given as a path in TransactionSigningMode.ORDINARY_TRANSACTION",
SIGN_MODE_ORDINARY__COLLATERALS_NOT_ALLOWED =
"collaterals now allowed in TransactionSigningMode.ORDINARY_TRANSACTION",
"collaterals not allowed in TransactionSigningMode.ORDINARY_TRANSACTION",
SIGN_MODE_ORDINARY__REQUIRED_SIGNERS_NOT_ALLOWED =
"required signers now allowed in TransactionSigningMode.ORDINARY_TRANSACTION",
"required signers not allowed in TransactionSigningMode.ORDINARY_TRANSACTION",

SIGN_MODE_MULTISIG__POOL_REGISTRATION_NOT_ALLOWED =
"pool registration is not allowed in TransactionSigningMode.MULTISIG_TRANSACTION",
Expand All @@ -166,9 +166,9 @@ export enum InvalidDataReason {
SIGN_MODE_MULTISIG__WITHDRAWAL_ONLY_AS_SCRIPT =
"withdrawal must be given as a script hash in TransactionSigningMode.MULTISIG_TRANSACTION",
SIGN_MODE_MULTISIG__COLLATERALS_NOT_ALLOWED =
"collaterals now allowed in TransactionSigningMode.MULTISIG_TRANSACTION",
"collaterals not allowed in TransactionSigningMode.MULTISIG_TRANSACTION",
SIGN_MODE_MULTISIG__REQUIRED_SIGNERS_NOT_ALLOWED =
"required signers now allowed in TransactionSigningMode.MULTISIG_TRANSACTION",
"required signers not allowed in TransactionSigningMode.MULTISIG_TRANSACTION",

SIGN_MODE_POOL_OWNER__DEVICE_OWNED_ADDRESS_NOT_ALLOWED =
"outputs given by path are not allowed in TransactionSigningMode.POOL_REGISTRATION_AS_OWNER",
Expand Down Expand Up @@ -208,8 +208,6 @@ export enum InvalidDataReason {
"outputs given by path are not allowed in TransactionSigningMode.PLUTUS_TRANSACTION",
SIGN_MODE_PLUTUS__POOL_REGISTRATION_NOT_ALLOWED =
"pool registration is not allowed in TransactionSigningMode.PLUTUS_TRANSACTION",
SIGN_MODE_PLUTUS__CERTIFICATE_STAKE_CREDENTIAL_ONLY_AS_SCRIPT =
"certificate stake credential must be given as a script hash in TransactionSigningMode.PLUTUS_TRANSACTION",

ADDITIONAL_WITNESSES_NOT_ARRAY = "additional witnesses not an array",

Expand Down
73 changes: 33 additions & 40 deletions src/parsing/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,13 @@ function parseTxDestination(
function addressContainsScripthash(destination: OutputDestination): boolean {
let type: AddressType
switch (destination.type) {
case TxOutputDestinationType.THIRD_PARTY: {
case TxOutputDestinationType.THIRD_PARTY:
const addressBytes: Buffer = hex_to_buf(destination.addressHex)
type = (addressBytes[0] & 0b11110000) >> 4
break
}
case TxOutputDestinationType.DEVICE_OWNED: {
case TxOutputDestinationType.DEVICE_OWNED:
type = destination.addressParams.type
}
break
}
switch (type) {
case AddressType.BASE_PAYMENT_SCRIPT_STAKE_KEY:
Expand Down Expand Up @@ -302,6 +301,14 @@ export function parseSigningMode(mode: TransactionSigningMode): TransactionSigni
}
}

function validateNoCollaterals(collaterals: ParsedInput[], errMsg: InvalidDataReason) {
validate(collaterals.length === 0, errMsg)
}

function validateNoRequiredSigners(requiredSigners: ParsedRequiredSigner[], errMsg: InvalidDataReason) {
validate(requiredSigners.length === 0, errMsg)
}

export function parseSignTransactionRequest(request: SignTransactionRequest): ParsedSigningRequest {
const tx = parseTransaction(request.tx)
const signingMode = parseSigningMode(request.signingMode)
Expand Down Expand Up @@ -337,13 +344,13 @@ export function parseSignTransactionRequest(request: SignTransactionRequest): Pa
InvalidDataReason.SIGN_MODE_ORDINARY__WITHDRAWAL_ONLY_AS_PATH,
)
// cannot have collaterals in the tx
validate(
!tx.collaterals || tx.collaterals.length == 0,
validateNoCollaterals(
tx.collaterals,
InvalidDataReason.SIGN_MODE_ORDINARY__COLLATERALS_NOT_ALLOWED
)
// cannot have collaterals in the tx
validate(
!tx.requiredSigners || tx.requiredSigners.length == 0,
// cannot have required signers in the tx
validateNoRequiredSigners(
tx.requiredSigners,
InvalidDataReason.SIGN_MODE_ORDINARY__REQUIRED_SIGNERS_NOT_ALLOWED
)
break
Expand Down Expand Up @@ -385,13 +392,13 @@ export function parseSignTransactionRequest(request: SignTransactionRequest): Pa
InvalidDataReason.SIGN_MODE_MULTISIG__DEVICE_OWNED_ADDRESS_NOT_ALLOWED,
)
// cannot have collaterals in the tx
validate(
!tx.collaterals || tx.collaterals.length == 0,
validateNoCollaterals(
tx.collaterals,
InvalidDataReason.SIGN_MODE_MULTISIG__COLLATERALS_NOT_ALLOWED
)
// cannot have collaterals in the tx
validate(
!tx.requiredSigners || tx.requiredSigners.length == 0,
// cannot have required signers in the tx
validateNoRequiredSigners(
tx.requiredSigners,
InvalidDataReason.SIGN_MODE_MULTISIG__REQUIRED_SIGNERS_NOT_ALLOWED
)
break
Expand Down Expand Up @@ -439,19 +446,19 @@ export function parseSignTransactionRequest(request: SignTransactionRequest): Pa

// cannot have mint in the tx
validate(
!tx.mint || tx.mint.length == 0,
!tx.mint || tx.mint.length === 0,
InvalidDataReason.SIGN_MODE_POOL_OWNER__MINT_NOT_ALLOWED
)

// cannot have collaterals in the tx
validate(
!tx.collaterals || tx.collaterals.length == 0,
validateNoCollaterals(
tx.collaterals,
InvalidDataReason.SIGN_MODE_POOL_OWNER__COLLATERALS_NOT_ALLOWED
)

// cannot have collaterals in the tx
validate(
!tx.requiredSigners || tx.requiredSigners.length == 0,
// cannot have required signers in the tx
validateNoRequiredSigners(
tx.requiredSigners,
InvalidDataReason.SIGN_MODE_POOL_OWNER__REQUIRED_SIGNERS_NOT_ALLOWED
)
break
Expand Down Expand Up @@ -489,19 +496,19 @@ export function parseSignTransactionRequest(request: SignTransactionRequest): Pa

// cannot have mint in the tx
validate(
!tx.mint || tx.mint?.length == 0,
!tx.mint || tx.mint?.length === 0,
InvalidDataReason.SIGN_MODE_POOL_OPERATOR__MINT_NOT_ALLOWED
)

// cannot have collaterals in the tx
validate(
!tx.collaterals || tx.collaterals.length == 0,
validateNoCollaterals(
tx.collaterals,
InvalidDataReason.SIGN_MODE_POOL_OPERATOR__COLLATERALS_NOT_ALLOWED
)

// cannot have collaterals in the tx
validate(
!tx.requiredSigners || tx.requiredSigners.length == 0,
// cannot have required signers in the tx
validateNoRequiredSigners(
tx.requiredSigners,
InvalidDataReason.SIGN_MODE_POOL_OPERATOR__REQUIRED_SIGNERS_NOT_ALLOWED
)
break
Expand All @@ -514,20 +521,6 @@ export function parseSignTransactionRequest(request: SignTransactionRequest): Pa
tx.certificates.every(certificate => certificate.type !== CertificateType.STAKE_POOL_REGISTRATION),
InvalidDataReason.SIGN_MODE_PLUTUS__POOL_REGISTRATION_NOT_ALLOWED,
)
// certificate stake credentials given by scripts
validate(
tx.certificates.every(certificate => {
switch (certificate.type) {
case CertificateType.STAKE_REGISTRATION:
case CertificateType.STAKE_DEREGISTRATION:
case CertificateType.STAKE_DELEGATION:
return certificate.stakeCredential.type === StakeCredentialType.SCRIPT_HASH
default:
return true
}
}),
InvalidDataReason.SIGN_MODE_PLUTUS__CERTIFICATE_STAKE_CREDENTIAL_ONLY_AS_SCRIPT,
)
break
}
default:
Expand Down
16 changes: 0 additions & 16 deletions test/integration/__fixtures__/signTxRejects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,22 +866,6 @@ export const certificateStakingRejectTestcases: TestcaseRejectShelley[] = [
errMsg: DeviceStatusMessages[DeviceStatusCodes.ERR_REJECTED_BY_POLICY],
rejectReason: InvalidDataReason.SIGN_MODE_MULTISIG__CERTIFICATE_STAKE_CREDENTIAL_ONLY_AS_SCRIPT,
},
{
testname: "Path in Plutus Tx",
tx: {
...shelleyBase,
certificates: [
{
type: CertificateType.STAKE_REGISTRATION,
params: stakeRegistrationPathParam,
},
],
},
signingMode: TransactionSigningMode.PLUTUS_TRANSACTION,
errCls: DeviceStatusError,
errMsg: DeviceStatusMessages[DeviceStatusCodes.ERR_REJECTED_BY_POLICY],
rejectReason: InvalidDataReason.SIGN_MODE_PLUTUS__CERTIFICATE_STAKE_CREDENTIAL_ONLY_AS_SCRIPT,
},
]

export const certificateStakePoolRetirementRejectTestcases: TestcaseRejectShelley[] = [
Expand Down

0 comments on commit 6b09bb3

Please sign in to comment.