From 7a79042735ce71636756deeb0d3c7a4013f16378 Mon Sep 17 00:00:00 2001 From: tequ Date: Tue, 8 Jul 2025 01:31:42 +0900 Subject: [PATCH] Add validation amount on Remit (#27) --- packages/xahau/src/models/transactions/remit.ts | 6 +++++- packages/xahau/test/models/remit.test.ts | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/xahau/src/models/transactions/remit.ts b/packages/xahau/src/models/transactions/remit.ts index 3522f374..4758ff57 100644 --- a/packages/xahau/src/models/transactions/remit.ts +++ b/packages/xahau/src/models/transactions/remit.ts @@ -2,7 +2,7 @@ import { ValidationError } from '../../errors' import { AmountEntry, MintURIToken } from '../common/xahau' import { isHex } from '../utils' -import { BaseTransaction, validateBaseTransaction } from './common' +import { BaseTransaction, isAmount, validateBaseTransaction } from './common' const MAX_URI_LENGTH = 512 const DIGEST_LENGTH = 64 @@ -118,6 +118,10 @@ function checkAmounts(tx: Record): void { throw new ValidationError('Remit: invalid Amounts.AmountEntry') } // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- ignore + if (!isAmount(amount.AmountEntry.Amount)) { + throw new ValidationError('Remit: invalid Amounts.AmountEntry.Amount') + } + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- ignore if (typeof amount.AmountEntry.Amount === 'string') { // eslint-disable-next-line max-depth -- ignore if (seenXrp) { diff --git a/packages/xahau/test/models/remit.test.ts b/packages/xahau/test/models/remit.test.ts index 2c0224bd..356bb6af 100644 --- a/packages/xahau/test/models/remit.test.ts +++ b/packages/xahau/test/models/remit.test.ts @@ -157,6 +157,14 @@ describe('Remit', function () { 'Remit: Duplicate amounts are not allowed', ) }) + it(`throws w/ Bad Amount`, function () { + remit.Amounts = [{ AmountEntry: { Amount: 1234 } }] + assert.throws( + () => validateRemit(remit), + ValidationError, + 'Remit: invalid Amounts.AmountEntry.Amount', + ) + }) it(`throws w/ Bad URITokenIDs`, function () { remit.URITokenIDs = {} assert.throws(