Skip to content

feat: add support for Batch amendment #2801

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

Merged
merged 140 commits into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
4803cdc
improve scripts
mvadari May 3, 2024
84c8900
Update settings.json
mvadari May 7, 2024
6ca94b7
Merge branch 'main' into better-scripts
mvadari May 8, 2024
810bc42
Merge branch 'main' into better-scripts
mvadari May 8, 2024
dce0947
Merge branch 'main' into better-scripts
mvadari May 8, 2024
bac69ca
Merge branch 'main' into better-scripts
mvadari May 23, 2024
7866790
Merge branch 'main' into better-scripts
mvadari Jul 1, 2024
768eb08
Merge branch 'main' into better-scripts
mvadari Jul 3, 2024
8df48e2
Merge branch 'main' into better-scripts
mvadari Jul 8, 2024
e1747a9
Merge branch 'main' into better-scripts
mvadari Jul 9, 2024
9d69271
Merge branch 'main' into better-scripts
mvadari Jul 11, 2024
78e3d05
Merge branch 'main' into better-scripts
mvadari Jul 16, 2024
dc98b1b
Merge branch 'main' into better-scripts
mvadari Jul 22, 2024
fe08836
Merge branch 'main' into better-scripts
mvadari Aug 27, 2024
4fe1986
Merge branch 'main' into better-scripts
mvadari Sep 19, 2024
e696113
Merge branch 'main' into better-scripts
mvadari Sep 24, 2024
ab8d1b1
Merge branch 'main' into better-scripts
mvadari Sep 26, 2024
66dc844
Merge branch 'better-scripts' of https://github.com/XRPLF/xrpl.js int…
mvadari Oct 1, 2024
25ccc09
update file locations after refactor
mvadari Oct 1, 2024
7597807
add LedgerStateFix
mvadari Oct 1, 2024
ef4ab32
add Batch
mvadari Oct 1, 2024
762e57e
add BatchTxn autofill
mvadari Oct 1, 2024
28bce04
add multi-account signing
mvadari Oct 1, 2024
f671532
add combine function
mvadari Oct 1, 2024
9643508
add Batch support to hashing txs
mvadari Oct 1, 2024
e743ddc
add autofill TxID support
mvadari Oct 1, 2024
826fff8
better validation
mvadari Oct 1, 2024
ab09e38
add metadata
mvadari Oct 1, 2024
a4b55e2
update definitions.json
mvadari Oct 1, 2024
7d7acae
clean up
mvadari Oct 1, 2024
8fc2600
update binary codec for signing
mvadari Oct 1, 2024
0d86085
add Batchnet faucet
mvadari Oct 1, 2024
438a9d2
get basic tests working
mvadari Oct 2, 2024
591af47
add rbc tests
mvadari Oct 2, 2024
9b8c819
add autofill tests
mvadari Oct 2, 2024
78e3ad9
add signMultiBatch tests
mvadari Oct 2, 2024
4e3a5fb
refactor
mvadari Oct 2, 2024
7fb9927
add basic tests for combineBatchSigners
mvadari Oct 2, 2024
447c747
handle more edge cases
mvadari Oct 2, 2024
4d84930
better error validation
mvadari Oct 3, 2024
f120ea6
rename
mvadari Oct 3, 2024
1772b45
Merge branch 'main' into batch
mvadari Oct 7, 2024
009e98f
update history
mvadari Oct 7, 2024
211d46a
fix import
mvadari Oct 9, 2024
ff9929c
add more validation
mvadari Oct 10, 2024
29991c2
Merge branch 'main' into batch
mvadari Oct 11, 2024
fcd579a
Merge branch 'main' into batch
mvadari Oct 22, 2024
3818b29
Merge branch 'main' into batch
mvadari Nov 4, 2024
7212c5e
remove BatchTxn, fix autofill
mvadari Nov 7, 2024
39c7ef5
replace BatchTxn in some more places, fix tests
mvadari Nov 7, 2024
3903599
fix linter issues
mvadari Nov 7, 2024
e5f5d3c
Merge branch 'main' into batch
mvadari Nov 7, 2024
ec24418
update definitions
mvadari Nov 7, 2024
f8376eb
Batch integration test
mvadari Nov 7, 2024
260bc32
remove debug statement
mvadari Nov 7, 2024
bf19d12
fix TxnSignature
mvadari Nov 8, 2024
6b03f91
fix BatchMetadata
mvadari Nov 8, 2024
6d63995
Merge branch 'main' into batch
mvadari Dec 13, 2024
4a22d5b
Merge branch 'main' into batch
mvadari Jan 8, 2025
e084f43
fix tests
mvadari Jan 8, 2025
0d08deb
more updates
mvadari Jan 10, 2025
f427bc4
remove TransactionIDs
mvadari Jan 11, 2025
2280b95
add more tests
mvadari Jan 11, 2025
a5d72f9
remove LedgerStateFix
mvadari Jan 12, 2025
08543fc
fix build issues
mvadari Jan 12, 2025
d243ecc
uncomment now-passing test
mvadari Jan 12, 2025
503cf6c
fix linter
mvadari Jan 12, 2025
b3b2c4c
drive-by multisign fix
mvadari Jan 12, 2025
b092a94
add more tests
mvadari Jan 12, 2025
c48957d
better docstrings
mvadari Jan 13, 2025
b519151
Merge branch 'main' into batch
mvadari Feb 6, 2025
793d42f
redo definitions.json
mvadari Feb 6, 2025
f06e83c
fix error
mvadari Feb 6, 2025
dd36b47
minor cleanup
mvadari Feb 7, 2025
60940fa
Merge branch 'main' into batch
mvadari Feb 7, 2025
021999e
Merge branch 'main' into batch
mvadari Feb 10, 2025
1f7c48c
update vscode settings
mvadari Feb 10, 2025
1773246
fix linter
mvadari Feb 10, 2025
27a39bf
fix history
mvadari Feb 10, 2025
4c36d4d
Merge branch 'main' into batch
mvadari Feb 11, 2025
357b5b0
fix tests
mvadari Feb 12, 2025
5d4efda
Merge branch 'main' into batch
mvadari Feb 13, 2025
23e3e07
fix build issue
mvadari Feb 13, 2025
ae20b6b
bump versions for beta
mvadari Feb 13, 2025
3c56343
update packagelock
mvadari Feb 13, 2025
3b899a7
Merge branch 'main' into batch
mvadari Feb 18, 2025
82de5ac
Merge branch 'main' into batch
mvadari Mar 18, 2025
c4a1b21
update package-lock
mvadari Mar 26, 2025
646f71e
Merge branch 'main' into batch
mvadari Mar 26, 2025
916b4a6
Merge branch 'main' into batch
mvadari Apr 1, 2025
0e49ebf
back out unrelated changes
mvadari Apr 1, 2025
f9afbfd
more backing out
mvadari Apr 1, 2025
0b8ecf8
Merge branch 'main' into batch
mvadari Apr 9, 2025
027861e
rename test file
mvadari Apr 10, 2025
3021822
update tfInnerBatchTxn handling
mvadari Apr 10, 2025
335eafe
Merge branch 'main' into batch
mvadari Apr 16, 2025
9a54bec
respond to comments
mvadari Apr 16, 2025
b8db856
fix coderabbit issues
mvadari Apr 16, 2025
27efb57
improve type-checking
mvadari Apr 16, 2025
cffc141
fix errors
mvadari Apr 16, 2025
b612edc
fix errors
mvadari Apr 16, 2025
c3405e0
fix autofill
mvadari Apr 16, 2025
f20f16c
fix ts issues
mvadari Apr 16, 2025
808748d
more fixes
mvadari Apr 16, 2025
d1a4a41
more fixes
mvadari Apr 16, 2025
b2e1122
respond to comments
mvadari Apr 17, 2025
a707718
Merge branch 'main' into batch
mvadari Apr 17, 2025
e19cc51
disable
mvadari Apr 17, 2025
ee1a7ed
Merge branch 'main' into batch
mvadari Apr 23, 2025
2d75bd0
Merge branch 'main' into batch
mvadari Apr 29, 2025
b373a1c
Merge branch 'main' into batch
mvadari May 19, 2025
5cbeee2
update definitions
mvadari May 20, 2025
b360cdf
Merge branch 'main' into batch
mvadari May 20, 2025
bee8240
add Batch to the list of non delegatable transactions
mvadari May 20, 2025
97f454c
Merge branch 'main' into batch
mvadari May 21, 2025
abd3c1c
fix definitions, update amendments in config
mvadari May 27, 2025
cd4f226
fix test
mvadari May 27, 2025
bba11c4
I tried to be too smart for my own good
mvadari May 27, 2025
ac3c5e2
more flag tests
mvadari May 27, 2025
0b58072
roll back beta version changes
mvadari May 27, 2025
7b9d8ab
clean up batchSigner file
mvadari May 27, 2025
661fa4f
fix imports
mvadari May 27, 2025
20fbafe
fix test
mvadari May 27, 2025
21cffbf
fix 4 real
mvadari May 27, 2025
1b637b9
roll back some typing changes
mvadari May 27, 2025
beb1762
remove faucet
mvadari May 28, 2025
2971417
respond to comments
mvadari Jun 4, 2025
5b7569e
Merge branch 'main' into batch
mvadari Jun 4, 2025
b0765dc
respond to comments
mvadari Jun 5, 2025
0bf4a7b
Merge branch 'main' into batch
mvadari Jun 5, 2025
e4f7adf
fix tests
mvadari Jun 5, 2025
5c688c9
fix dependency cycle
mvadari Jun 5, 2025
55c4080
fix imports
mvadari Jun 5, 2025
7e806b0
add address info
mvadari Jun 6, 2025
88a596a
fix browser tests
mvadari Jun 6, 2025
5119cca
respond to comments
mvadari Jun 6, 2025
980309d
improve multisig fee calculations
mvadari Jun 6, 2025
e44e400
fix test
mvadari Jun 6, 2025
7bf7730
address comment
mvadari Jun 6, 2025
e433d6b
Merge branch 'main' into batch
mvadari Jun 6, 2025
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
7 changes: 6 additions & 1 deletion .ci-config/rippled.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,23 @@ fixPreviousTxnID
fixAMMv1_1
# 2.3.0 Amendments
AMMClawback
fixAMMv1_2
Credentials
NFTokenMintOffer
MPTokensV1
fixAMMv1_2
fixNFTokenPageLinks
fixInnerObjTemplate2
fixEnforceNFTokenTrustline
fixReducedOffersV2
# 2.4.0 Amendments
DeepFreeze
DynamicNFT
PermissionedDomains
fixFrozenLPTokenTransfer
fixInvalidTxFlags
# 2.5.0 Amendments
PermissionDelegation
Batch

# This section can be used to simulate various FeeSettings scenarios for rippled node in standalone mode
[voting]
Expand Down
7 changes: 5 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"editor.tabSize": 2,
"cSpell.words": [
"altnet",
"Autofills",
"autofills",
"bignumber",
"Clawback",
"hostid",
"keypair",
"keypairs",
"MPToken",
"multisign",
"multisigned",
"multisigning",
Expand All @@ -16,7 +18,8 @@
"secp256k1",
"Setf",
"Sidechains",
"xchain"
"xchain",
"xrplf"
],
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
Expand Down
5 changes: 3 additions & 2 deletions packages/ripple-binary-codec/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## Unreleased

### Added
* Support for `Account Permissions` and `Account Permission Delegation` (XLS-74d, XLS-75d)
* Support for `Account Permissions` and `Account Permission Delegation` (XLS-74d, XLS-75d).
* Support for the `Batch` amendment (XLS-56).

### Fixed
* add `MPTCurrency` support in `Issue` (rippled internal type)
Expand All @@ -18,7 +19,7 @@
## 2.2.0 (2024-12-23)

### Added
* Support for the Multi-Purpose Token amendment (XLS-33)
* Support for the Multi-Purpose Token amendment (XLS-33).

## 2.1.0 (2024-06-03)

Expand Down
41 changes: 41 additions & 0 deletions packages/ripple-binary-codec/src/binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,51 @@ function multiSigningData(
})
}

/**
* Interface describing fields required for a Batch signer
* @property flags - Flags indicating Batch transaction properties
* @property txIDs - Array of transaction IDs included in the Batch
*/
interface BatchObject extends JsonObject {
flags: number
txIDs: string[]
}

/**
* Serialize a signingClaim
*
* @param batch A Batch object to serialize.
* @returns the serialized object with appropriate prefix
*/
function signingBatchData(batch: BatchObject): Uint8Array {
if (batch.flags == null) {
throw Error("No field `flags'")
}
if (batch.txIDs == null) {
throw Error('No field `txIDs`')
}
const prefix = HashPrefix.batch
const flags = coreTypes.UInt32.from(batch.flags).toBytes()
const txIDsLength = coreTypes.UInt32.from(batch.txIDs.length).toBytes()

const bytesList = new BytesList()

bytesList.put(prefix)
bytesList.put(flags)
bytesList.put(txIDsLength)
batch.txIDs.forEach((txID: string) => {
bytesList.put(coreTypes.Hash256.from(txID).toBytes())
})

return bytesList.toBytes()
}

export {
BinaryParser,
BinarySerializer,
BytesList,
ClaimObject,
BatchObject,
makeParser,
serializeObject,
readJSON,
Expand All @@ -191,4 +231,5 @@ export {
binaryToJSON,
sha512Half,
transactionID,
signingBatchData,
}
2 changes: 2 additions & 0 deletions packages/ripple-binary-codec/src/hash-prefixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const HashPrefix: Record<string, Uint8Array> = {
proposal: bytes(0x50525000),
// payment channel claim
paymentChannelClaim: bytes(0x434c4d00),
// batch
batch: bytes(0x42434800),
}

export { HashPrefix }
33 changes: 23 additions & 10 deletions packages/ripple-binary-codec/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { quality, binary, HashPrefix } from './coretypes'
import { decodeLedgerData } from './ledger-hashes'
import { ClaimObject } from './binary'
import { ClaimObject, BatchObject } from './binary'
import { JsonObject } from './types/serialized-type'
import {
XrplDefinitionsBase,
Expand All @@ -15,6 +15,7 @@ const {
signingData,
signingClaimData,
multiSigningData,
signingBatchData,
binaryToJSON,
serializeObject,
} = binary
Expand Down Expand Up @@ -71,12 +72,10 @@ function encodeForSigning(
}

/**
* Encode a transaction and prepare for signing with a claim
* Encode a payment channel claim for signing.
*
* @param json JSON object representing the transaction
* @param signer string representing the account to sign the transaction with
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
* @returns a hex string of the encoded transaction
* @param json JSON object representing the claim.
* @returns a hex string of the encoded claim.
*/
function encodeForSigningClaim(json: object): string {
if (typeof json !== 'object') {
Expand All @@ -86,12 +85,12 @@ function encodeForSigningClaim(json: object): string {
}

/**
* Encode a transaction and prepare for multi-signing
* Encode a transaction and prepare for multi-signing.
*
* @param json JSON object representing the transaction
* @param signer string representing the account to sign the transaction with
* @param json JSON object representing the transaction.
* @param signer string representing the account to sign the transaction with.
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
* @returns a hex string of the encoded transaction
* @returns a hex string of the encoded transaction.
*/
function encodeForMultisigning(
json: object,
Expand All @@ -110,6 +109,19 @@ function encodeForMultisigning(
)
}

/**
* Encode a Batch transaction for signing.
*
* @param json JSON object representing the transaction.
* @returns a hex string of the encoded transaction.
*/
function encodeForSigningBatch(json: object): string {
if (typeof json !== 'object') {
throw new Error('Need an object to encode a Batch transaction')
}
return bytesToHex(signingBatchData(json as BatchObject))
}

/**
* Encode a quality value
*
Expand Down Expand Up @@ -142,6 +154,7 @@ export {
encodeForSigning,
encodeForSigningClaim,
encodeForMultisigning,
encodeForSigningBatch,
encodeQuality,
decodeQuality,
decodeLedgerData,
Expand Down
5 changes: 4 additions & 1 deletion packages/ripple-binary-codec/src/types/hash.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Comparable } from './serialized-type'
import { BinaryParser } from '../serdes/binary-parser'
import { hexToBytes } from '@xrplf/isomorphic/utils'
import { HEX_REGEX, hexToBytes } from '@xrplf/isomorphic/utils'
import { compare } from '../utils'

/**
Expand All @@ -27,6 +27,9 @@ class Hash extends Comparable<Hash | string> {
}

if (typeof value === 'string') {
if (!HEX_REGEX.test(value)) {
throw new Error(`Invalid hash string ${value}`)
}
Comment on lines +30 to +32
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Excellent defensive programming practice.

The hexadecimal validation prevents invalid strings from being processed, which is crucial for maintaining data integrity in hash operations. The error message is descriptive and will help with debugging.

Note that the HEX_REGEX pattern allows empty strings due to the * quantifier. Verify this is the intended behavior for your use case.


🏁 Script executed:

#!/bin/bash
# Verify if empty strings should be allowed as valid hash inputs
echo "Checking HEX_REGEX pattern and testing empty string behavior..."

# Check the regex pattern definition
rg -A 2 -B 2 "HEX_REGEX.*=" packages/isomorphic/src/utils/shared.ts

# Search for any existing hash creation with empty strings to understand expected behavior
rg -A 3 -B 3 "Hash\.from\(\s*['\"][\s]*['\"]" 
rg -A 3 -B 3 "new.*Hash.*['\"][\s]*['\"]"

Length of output: 48187


Ensure HEX_REGEX doesn’t inadvertently allow empty strings

Great defensive programming here—the check and error are clear and helpful. However, the current pattern in packages/isomorphic/src/utils/shared.ts is:

export const HEX_REGEX = /^[A-F0-9]*$/iu

The * quantifier lets an empty string pass. If you never intend to accept zero‐length hashes, update it to require at least one hex digit:

-export const HEX_REGEX = /^[A-F0-9]*$/iu
+export const HEX_REGEX = /^[A-F0-9]+$/iu

• File to update:

  • packages/isomorphic/src/utils/shared.ts

• Change *+ on the quantifier so empty inputs are rejected.

If you do intend to allow empty hashes, please add a comment to clarify this special case.

🤖 Prompt for AI Agents
In packages/isomorphic/src/utils/shared.ts around the definition of HEX_REGEX,
change the quantifier from '*' to '+' so the regex requires at least one
hexadecimal digit and does not match empty strings. This prevents empty strings
from being considered valid hex hashes, aligning with the validation logic in
packages/ripple-binary-codec/src/types/hash.ts. If empty hashes are intended to
be valid, instead add a comment explaining this special case.

return new this(hexToBytes(value))
}

Expand Down
40 changes: 36 additions & 4 deletions packages/ripple-binary-codec/test/signing-data-encoding.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { XrplDefinitions } from '../src/enums/xrpl-definitions'
const {
import {
encodeForSigning,
encodeForSigningClaim,
encodeForMultisigning,
} = require('../src')
encodeForSigningBatch,
} from '../src'

const normalDefinitions = require('../src/enums/definitions.json')

Expand Down Expand Up @@ -124,8 +125,8 @@ describe('Signing data', function () {
TransactionType: 'NotAPayment',
}

expect(() => encodeForSigning(invalidTransactionType)).toThrowError(
/NotAPayment/u,
expect(() => encodeForSigning(invalidTransactionType)).toThrow(
new TypeError('Unable to interpret "TransactionType: NotAPayment".'),
)
})

Expand Down Expand Up @@ -244,4 +245,35 @@ describe('Signing data', function () {
].join(''),
)
})

it('can create batch blob', function () {
const flags = 1
const txIDs = [
'ABE4871E9083DF66727045D49DEEDD3A6F166EB7F8D1E92FE868F02E76B2C5CA',
'795AAC88B59E95C3497609749127E69F12958BC016C600C770AEEB1474C840B4',
]
const json = { flags, txIDs }
const actual = encodeForSigningBatch(json)
expect(actual).toBe(
[
// hash prefix
'42434800',
// flags
'00000001',
// txIds length
'00000002',
// txIds
'ABE4871E9083DF66727045D49DEEDD3A6F166EB7F8D1E92FE868F02E76B2C5CA',
'795AAC88B59E95C3497609749127E69F12958BC016C600C770AEEB1474C840B4',
].join(''),
)
})

it('encodeForSigningBatch fails on non-object', function () {
const flags = 1
// @ts-expect-error - testing invalid input for JS users
expect(() => encodeForSigningBatch(flags)).toThrow(
new Error('Need an object to encode a Batch transaction'),
)
})
})
2 changes: 1 addition & 1 deletion packages/xrpl/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ module.exports = {
'tsdoc/syntax': 'off',
'jsdoc/require-description-complete-sentence': 'off',
'import/prefer-default-export': 'off',
'max-depth': ['warn', 3],
},
overrides: [
{
Expand Down Expand Up @@ -155,7 +156,6 @@ module.exports = {
'max-lines-per-function': ['off'],
'max-statements': ['off'],
complexity: ['off'],
'max-depth': ['warn', 3],
},
},
],
Expand Down
2 changes: 2 additions & 0 deletions packages/xrpl/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr
* Support for `NFTokenMintOffer` (XLS-52)
* Add Github Actions step to auto-generate documentation
* Support for `Account Permissions` and `Account Permission Delegation` (XLS-74d, XLS-75d)
* Add support for `Batch` amendment (XLS-56)

### Fixed
* Fix `OracleSet` transaction to accept hexadecimal string values for `AssetPrice` field
* `TransactionStream` model includes `hash` field in APIv2
* `TransactionStream` model includes `close_time_iso` field only for APIv2
* Adds `MPTCurrency` type
* Better faucet support
* Improve multisign fee calculations

## 4.2.0 (2025-2-13)

Expand Down
2 changes: 1 addition & 1 deletion packages/xrpl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"test": "jest --config=jest.config.unit.js --verbose false --silent=false",
"test:integration": "TS_NODE_PROJECT=tsconfig.build.json jest --config=jest.config.integration.js --verbose false --silent=false --runInBand",
"test:browser": "npm run build && npm run build:browserTests && karma start ./karma.config.js",
"test:watch": "jest --watch --verbose false --silent=false --runInBand ./test/**/*.test.ts --testPathIgnorePatterns=./test/integration --testPathIgnorePatterns=./test/fixtures",
"test:watch": "jest --watch --config=jest.config.unit.js --verbose false --silent=false",
"format": "prettier --write '{src,test}/**/*.ts'",
"lint": "eslint . --ext .ts --max-warnings 0",
"perf": "./scripts/perf_test.sh",
Expand Down
Loading
Loading