-
Couldn't load subscription status.
- Fork 300
Fix(sdk-coin-xrp): Update XRP signers sorting to use numeric comparison #6130
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); | ||
| }); |
Copilot
AI
May 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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