diff --git a/.nvmrc b/.nvmrc index 958b5a36..3f430af8 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v14 +v18 diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..dd449725 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +*.md diff --git a/packages/xrpl/.eslintrc.js b/packages/xrpl/.eslintrc.js index 8773b266..3d4b2d5e 100644 --- a/packages/xrpl/.eslintrc.js +++ b/packages/xrpl/.eslintrc.js @@ -128,6 +128,12 @@ module.exports = { '@typescript-eslint/no-explicit-any': 'off', }, }, + { + files: ['src/models/**/*.ts'], + rules: { + complexity: ['off'], + }, + }, { files: ['.eslintrc.js', 'jest.config.js'], rules: { diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index e0e291d1..4d9dd675 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -1,10 +1,12 @@ # xrpl.js (ripple-lib) Release History Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xrpl-announce) for release announcements. We recommend that xrpl.js (ripple-lib) users stay up-to-date with the latest stable release. + ## Unreleased ## Fixed * Fix request model fields related to AMM +* Fixed `EscrowCancel` and `EscrowFinish` validation ## 2.11.0 (2023-08-24) diff --git a/packages/xrpl/src/models/transactions/AMMBid.ts b/packages/xrpl/src/models/transactions/AMMBid.ts index 48965d7d..046aeacc 100644 --- a/packages/xrpl/src/models/transactions/AMMBid.ts +++ b/packages/xrpl/src/models/transactions/AMMBid.ts @@ -1,4 +1,3 @@ -/* eslint-disable complexity -- required for validateAMMBid */ import { ValidationError } from '../../errors' import { AuthAccount, Currency, IssuedCurrencyAmount } from '../common' diff --git a/packages/xrpl/src/models/transactions/AMMDeposit.ts b/packages/xrpl/src/models/transactions/AMMDeposit.ts index 92648fba..1e852048 100644 --- a/packages/xrpl/src/models/transactions/AMMDeposit.ts +++ b/packages/xrpl/src/models/transactions/AMMDeposit.ts @@ -1,4 +1,3 @@ -/* eslint-disable complexity -- required for validateAMMDeposit */ import { ValidationError } from '../../errors' import { Amount, Currency, IssuedCurrencyAmount } from '../common' diff --git a/packages/xrpl/src/models/transactions/AMMWithdraw.ts b/packages/xrpl/src/models/transactions/AMMWithdraw.ts index 77411616..fcce5912 100644 --- a/packages/xrpl/src/models/transactions/AMMWithdraw.ts +++ b/packages/xrpl/src/models/transactions/AMMWithdraw.ts @@ -1,4 +1,3 @@ -/* eslint-disable complexity -- required for validateAMMWithdraw */ import { ValidationError } from '../../errors' import { Amount, Currency, IssuedCurrencyAmount } from '../common' diff --git a/packages/xrpl/src/models/transactions/accountSet.ts b/packages/xrpl/src/models/transactions/accountSet.ts index a3916356..fe812c17 100644 --- a/packages/xrpl/src/models/transactions/accountSet.ts +++ b/packages/xrpl/src/models/transactions/accountSet.ts @@ -1,5 +1,3 @@ -/* eslint-disable complexity -- Necessary for validateAccountSet */ - import { isValidClassicAddress } from 'ripple-address-codec' import { ValidationError } from '../../errors' diff --git a/packages/xrpl/src/models/transactions/checkCash.ts b/packages/xrpl/src/models/transactions/checkCash.ts index e33afb5c..462f1944 100644 --- a/packages/xrpl/src/models/transactions/checkCash.ts +++ b/packages/xrpl/src/models/transactions/checkCash.ts @@ -1,4 +1,3 @@ -/* eslint-disable complexity -- Necessary for validateCheckCash */ import { ValidationError } from '../../errors' import { Amount } from '../common' diff --git a/packages/xrpl/src/models/transactions/checkCreate.ts b/packages/xrpl/src/models/transactions/checkCreate.ts index 332ad79a..2b2d9c2f 100644 --- a/packages/xrpl/src/models/transactions/checkCreate.ts +++ b/packages/xrpl/src/models/transactions/checkCreate.ts @@ -1,4 +1,3 @@ -/* eslint-disable complexity -- Necessary for validateCheckCreate */ import { ValidationError } from '../../errors' import { Amount } from '../common' diff --git a/packages/xrpl/src/models/transactions/common.ts b/packages/xrpl/src/models/transactions/common.ts index f30e390b..9781e524 100644 --- a/packages/xrpl/src/models/transactions/common.ts +++ b/packages/xrpl/src/models/transactions/common.ts @@ -1,5 +1,4 @@ /* eslint-disable max-lines-per-function -- Necessary for validateBaseTransaction */ -/* eslint-disable complexity -- Necessary for validateBaseTransaction */ /* eslint-disable max-statements -- Necessary for validateBaseTransaction */ import { TRANSACTION_TYPES } from 'ripple-binary-codec' diff --git a/packages/xrpl/src/models/transactions/depositPreauth.ts b/packages/xrpl/src/models/transactions/depositPreauth.ts index 802488e8..eaf186e8 100644 --- a/packages/xrpl/src/models/transactions/depositPreauth.ts +++ b/packages/xrpl/src/models/transactions/depositPreauth.ts @@ -1,4 +1,3 @@ -/* eslint-disable complexity -- Necessary for validateDepositPreauth */ import { ValidationError } from '../../errors' import { BaseTransaction, validateBaseTransaction } from './common' diff --git a/packages/xrpl/src/models/transactions/escrowCancel.ts b/packages/xrpl/src/models/transactions/escrowCancel.ts index 573d504f..6f133888 100644 --- a/packages/xrpl/src/models/transactions/escrowCancel.ts +++ b/packages/xrpl/src/models/transactions/escrowCancel.ts @@ -15,7 +15,7 @@ export interface EscrowCancel extends BaseTransaction { * Transaction sequence (or Ticket number) of EscrowCreate transaction that. * created the escrow to cancel. */ - OfferSequence: number + OfferSequence: number | string } /** @@ -27,7 +27,7 @@ export interface EscrowCancel extends BaseTransaction { export function validateEscrowCancel(tx: Record): void { validateBaseTransaction(tx) - if (tx.Owner === undefined) { + if (tx.Owner == null) { throw new ValidationError('EscrowCancel: missing Owner') } @@ -35,11 +35,15 @@ export function validateEscrowCancel(tx: Record): void { throw new ValidationError('EscrowCancel: Owner must be a string') } - if (tx.OfferSequence === undefined) { + if (tx.OfferSequence == null) { throw new ValidationError('EscrowCancel: missing OfferSequence') } - if (typeof tx.OfferSequence !== 'number') { + if ( + (typeof tx.OfferSequence !== 'number' && + typeof tx.OfferSequence !== 'string') || + Number.isNaN(Number(tx.OfferSequence)) + ) { throw new ValidationError('EscrowCancel: OfferSequence must be a number') } } diff --git a/packages/xrpl/src/models/transactions/escrowCreate.ts b/packages/xrpl/src/models/transactions/escrowCreate.ts index aeb2d88b..8493e9cb 100644 --- a/packages/xrpl/src/models/transactions/escrowCreate.ts +++ b/packages/xrpl/src/models/transactions/escrowCreate.ts @@ -1,4 +1,3 @@ -/* eslint-disable complexity -- Necessary for validateEscrowCreate */ import { ValidationError } from '../../errors' import { BaseTransaction, validateBaseTransaction } from './common' diff --git a/packages/xrpl/src/models/transactions/escrowFinish.ts b/packages/xrpl/src/models/transactions/escrowFinish.ts index 7a362018..f5219f55 100644 --- a/packages/xrpl/src/models/transactions/escrowFinish.ts +++ b/packages/xrpl/src/models/transactions/escrowFinish.ts @@ -15,7 +15,7 @@ export interface EscrowFinish extends BaseTransaction { * Transaction sequence of EscrowCreate transaction that created the held. * payment to finish. */ - OfferSequence: number + OfferSequence: number | string /** * Hex value matching the previously-supplied PREIMAGE-SHA-256. * crypto-condition of the held payment. @@ -37,7 +37,7 @@ export interface EscrowFinish extends BaseTransaction { export function validateEscrowFinish(tx: Record): void { validateBaseTransaction(tx) - if (tx.Owner === undefined) { + if (tx.Owner == null) { throw new ValidationError('EscrowFinish: missing field Owner') } @@ -45,11 +45,15 @@ export function validateEscrowFinish(tx: Record): void { throw new ValidationError('EscrowFinish: Owner must be a string') } - if (tx.OfferSequence === undefined) { + if (tx.OfferSequence == null) { throw new ValidationError('EscrowFinish: missing field OfferSequence') } - if (typeof tx.OfferSequence !== 'number') { + if ( + (typeof tx.OfferSequence !== 'number' && + typeof tx.OfferSequence !== 'string') || + Number.isNaN(Number(tx.OfferSequence)) + ) { throw new ValidationError('EscrowFinish: OfferSequence must be a number') } diff --git a/packages/xrpl/src/models/transactions/offerCreate.ts b/packages/xrpl/src/models/transactions/offerCreate.ts index 07f9d341..782e6354 100644 --- a/packages/xrpl/src/models/transactions/offerCreate.ts +++ b/packages/xrpl/src/models/transactions/offerCreate.ts @@ -1,4 +1,3 @@ -/* eslint-disable complexity -- Necessary for validateOfferCreate */ import { ValidationError } from '../../errors' import { Amount } from '../common' diff --git a/packages/xrpl/src/models/transactions/payment.ts b/packages/xrpl/src/models/transactions/payment.ts index 118e88a5..493afb42 100644 --- a/packages/xrpl/src/models/transactions/payment.ts +++ b/packages/xrpl/src/models/transactions/payment.ts @@ -1,4 +1,3 @@ -/* eslint-disable complexity -- Necessary for validatePayment */ import { ValidationError } from '../../errors' import { Amount, Path } from '../common' import { isFlagEnabled } from '../utils' diff --git a/packages/xrpl/src/models/transactions/paymentChannelClaim.ts b/packages/xrpl/src/models/transactions/paymentChannelClaim.ts index 4aeda9ac..c673f181 100644 --- a/packages/xrpl/src/models/transactions/paymentChannelClaim.ts +++ b/packages/xrpl/src/models/transactions/paymentChannelClaim.ts @@ -1,4 +1,3 @@ -/* eslint-disable complexity -- Necessary for validatePaymentChannelClaim */ import { ValidationError } from '../../errors' import { BaseTransaction, GlobalFlags, validateBaseTransaction } from './common' diff --git a/packages/xrpl/src/models/transactions/paymentChannelCreate.ts b/packages/xrpl/src/models/transactions/paymentChannelCreate.ts index 6bde2c20..4a1b7a04 100644 --- a/packages/xrpl/src/models/transactions/paymentChannelCreate.ts +++ b/packages/xrpl/src/models/transactions/paymentChannelCreate.ts @@ -1,4 +1,3 @@ -/* eslint-disable complexity -- Necessary for validatePaymentChannelCreate */ import { ValidationError } from '../../errors' import { BaseTransaction, validateBaseTransaction } from './common' diff --git a/packages/xrpl/src/models/transactions/signerListSet.ts b/packages/xrpl/src/models/transactions/signerListSet.ts index 0d2cffe2..f264d55b 100644 --- a/packages/xrpl/src/models/transactions/signerListSet.ts +++ b/packages/xrpl/src/models/transactions/signerListSet.ts @@ -36,7 +36,6 @@ const HEX_WALLET_LOCATOR_REGEX = /^[0-9A-Fa-f]{64}$/u * @param tx - An SignerListSet Transaction. * @throws When the SignerListSet is Malformed. */ -// eslint-disable-next-line complexity -- validation can be complex export function validateSignerListSet(tx: Record): void { validateBaseTransaction(tx) diff --git a/packages/xrpl/src/models/transactions/transaction.ts b/packages/xrpl/src/models/transactions/transaction.ts index d726e996..6c7fa409 100644 --- a/packages/xrpl/src/models/transactions/transaction.ts +++ b/packages/xrpl/src/models/transactions/transaction.ts @@ -1,4 +1,3 @@ -/* eslint-disable complexity -- verifies 19 tx types hence a lot of checks needed */ /* eslint-disable max-lines-per-function -- need to work with a lot of Tx verifications */ import { ValidationError } from '../../errors' diff --git a/packages/xrpl/test/models/escrowCancel.test.ts b/packages/xrpl/test/models/escrowCancel.test.ts index c4650a92..e7eba479 100644 --- a/packages/xrpl/test/models/escrowCancel.test.ts +++ b/packages/xrpl/test/models/escrowCancel.test.ts @@ -25,6 +25,13 @@ describe('EscrowCancel', function () { assert.doesNotThrow(() => validate(cancel)) }) + it(`Valid EscrowCancel with string OfferSequence`, function () { + cancel.OfferSequence = '7' + + assert.doesNotThrow(() => validateEscrowCancel(cancel)) + assert.doesNotThrow(() => validate(cancel)) + }) + it(`Invalid EscrowCancel missing owner`, function () { delete cancel.Owner @@ -55,7 +62,7 @@ describe('EscrowCancel', function () { ) }) - it(`Invalid OfferSequence`, function () { + it(`Invalid Owner`, function () { cancel.Owner = 10 assert.throws( @@ -70,8 +77,8 @@ describe('EscrowCancel', function () { ) }) - it(`Invalid owner`, function () { - cancel.OfferSequence = '10' + it(`Invalid OfferSequence`, function () { + cancel.OfferSequence = 'random' assert.throws( () => validateEscrowCancel(cancel), diff --git a/packages/xrpl/test/models/escrowFinish.test.ts b/packages/xrpl/test/models/escrowFinish.test.ts index 4caf04a7..8aa6d0f9 100644 --- a/packages/xrpl/test/models/escrowFinish.test.ts +++ b/packages/xrpl/test/models/escrowFinish.test.ts @@ -35,6 +35,13 @@ describe('EscrowFinish', function () { assert.doesNotThrow(() => validate(escrow)) }) + it(`verifies valid EscrowFinish w/string OfferSequence`, function () { + escrow.OfferSequence = '7' + + assert.doesNotThrow(() => validateEscrowFinish(escrow)) + assert.doesNotThrow(() => validate(escrow)) + }) + it(`throws w/ invalid Owner`, function () { escrow.Owner = 0x15415253 @@ -51,7 +58,7 @@ describe('EscrowFinish', function () { }) it(`throws w/ invalid OfferSequence`, function () { - escrow.OfferSequence = '10' + escrow.OfferSequence = 'random' assert.throws( () => validateEscrowFinish(escrow),