-
Notifications
You must be signed in to change notification settings - Fork 294
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
base: master
Are you sure you want to change the base?
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
addressToBigNumber
helper and sortsSigners
array 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
addressToBigNumber
is descriptive but verbose. Consider renaming to something shorter likeaddressToBN
orparseAddressBN
to 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
signers
array 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
ripple
namespace isn't imported in this test file, so callingripple.signWithPrivateKey
will 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
BigInt
to 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.
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); |
Copilot uses AI. Check for mistakes.
0208b49
to
d3fc28f
Compare
TICKET: WIN-5390