Fix(sdk-coin-xrp): Update XRP signers sorting to use numeric comparison#6130
Fix(sdk-coin-xrp): Update XRP signers sorting to use numeric comparison#6130veetragjain merged 1 commit intomasterfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that multiple XRP multisigners are ordered correctly by their numeric address value and adds a unit test to verify this behavior.
- Introduces
addressToBigNumberhelper and sortsSignersarray insignWithPrivateKey - Adds a new test case to confirm the numeric sorting of signer entries
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| modules/sdk-coin-xrp/src/ripple.ts | Added BigNumber import, addressToBigNumber helper, and updated Signers insertion to include sorting |
| modules/sdk-coin-xrp/test/unit/xrp.ts | Imported SIGNER_* constants and added a test case for signer sorting by numeric address value |
Comments suppressed due to low confidence (4)
modules/sdk-coin-xrp/src/ripple.ts:21
- [nitpick] The name
addressToBigNumberis descriptive but verbose. Consider renaming to something shorter likeaddressToBNorparseAddressBNto improve readability.
function addressToBigNumber(address: string): BigNumber {
modules/sdk-coin-xrp/test/unit/xrp.ts:231
- [nitpick] The test currently signs in the input order; consider adding a test where the
signersarray is initially shuffled to explicitly verify that the sorting logic correctly reorders them in numeric ascending order.
const signers = [SIGNER_USER, SIGNER_BACKUP, SIGNER_BITGO];
modules/sdk-coin-xrp/test/unit/xrp.ts:238
- The
ripplenamespace isn't imported in this test file, so callingripple.signWithPrivateKeywill throw. Add a proper import, e.g.import * as ripple from '../../src/ripple';or use the module export that exposessignWithPrivateKey.
let signedTx = ripple.signWithPrivateKey(unsignedTxHex, signers[0].prv, {
modules/sdk-coin-xrp/test/unit/xrp.ts:263
- [nitpick] This helper uses
BigIntto parse addresses while production code usesBigNumber. Consider using the same numeric type (e.g.BigNumber) in tests to align with the implementation and avoid confusion.
const addressToBigNumber = (address) => {
| tx.Signers.sort((a, b) => { | ||
| const addressBN1 = addressToBigNumber(a.Signer.Account); | ||
| const addressBN2 = addressToBigNumber(b.Signer.Account); | ||
| return addressBN1.comparedTo(addressBN2); | ||
| }); |
There was a problem hiding this comment.
[nitpick] The comparator decodes and converts each address to a BigNumber on every comparison. For larger signer arrays this could be optimized by computing each numeric value once before sorting and reusing them.
| tx.Signers.sort((a, b) => { | |
| const addressBN1 = addressToBigNumber(a.Signer.Account); | |
| const addressBN2 = addressToBigNumber(b.Signer.Account); | |
| return addressBN1.comparedTo(addressBN2); | |
| }); | |
| // Precompute BigNumber values for each signer address | |
| tx.Signers = tx.Signers.map(signer => ({ | |
| ...signer, | |
| _addressBN: addressToBigNumber(signer.Signer.Account), | |
| })); | |
| // Sort the Signers array using the precomputed BigNumber values | |
| tx.Signers.sort((a, b) => a._addressBN.comparedTo(b._addressBN)); | |
| // Remove the temporary _addressBN property after sorting | |
| tx.Signers = tx.Signers.map(({ _addressBN, ...signer }) => signer); |
0208b49 to
d3fc28f
Compare
|
This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days. |
d3fc28f to
eef8b0d
Compare
TICKET: WIN-5390