Skip to content

Commit

Permalink
add more validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mvadari committed Oct 10, 2024
1 parent 211d46a commit ff9929c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/xrpl/src/Wallet/batchSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function combineBatchSigners(
transactions: Array<Batch | string>,
): string {
if (transactions.length === 0) {
throw new ValidationError('There were 0 transactions to combine')
throw new ValidationError('There were 0 transactions to combine.')
}

const decodedTransactions: Transaction[] = transactions.map(
Expand All @@ -121,7 +121,7 @@ export function combineBatchSigners(
validateBatch(tx as unknown as Record<string, unknown>)
if (tx.BatchSigners == null || tx.BatchSigners.length === 0) {
throw new ValidationError(
"For multisigning all transactions must include a Signers field containing an array of signatures. You may have forgotten to pass the 'forMultisign' parameter when signing.",
'For combining Batch transaction signatures, all transactions must include a BatchSigners field containing an array of signatures.',
)
}

Expand Down Expand Up @@ -162,12 +162,12 @@ function validateBatchTransactionEquivalence(transactions: Batch[]): void {
)
) {
throw new ValidationError(
'Flags and TxIDs is not the same for all provided transactions',
'Flags and TxIDs is not the same for all provided transactions.',
)
}
}

function getTransactionWithAllBatchSigners(transactions: Batch[]): Transaction {
function getTransactionWithAllBatchSigners(transactions: Batch[]): Batch {
// Signers must be sorted in the combined transaction - See compareSigners' documentation for more details
const sortedSigners: BatchSigner[] = transactions
.flatMap((tx) => tx.BatchSigners ?? [])
Expand Down
12 changes: 12 additions & 0 deletions packages/xrpl/src/models/transactions/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ export function validateBatch(tx: Record<string, unknown>): void {
isObject,
`RawTransactions[${index}].RawTransaction`,
)
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- needed here
// @ts-expect-error -- checked above
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- checked above
const rawTx = field.RawTransaction as Record<string, unknown>
if (!isObject(rawTx)) {
throw new ValidationError(`Batch: RawTransactions[${index} is not object`)
}
if (rawTx.TransactionType === 'Batch') {
throw new ValidationError(
`Batch: RawTransactions[${index} is a Batch transaction. Cannot nest Batch transactions.`,
)
}
})
// Full validation of each `RawTransaction` object is done in `validate` to avoid dependency cycles

Expand Down

0 comments on commit ff9929c

Please sign in to comment.