@@ -10,6 +10,7 @@ import assert from 'assert';
10
10
import * as rippleBinaryCodec from 'ripple-binary-codec' ;
11
11
import sinon from 'sinon' ;
12
12
import * as testData from '../resources/xrp' ;
13
+ import { SIGNER_USER , SIGNER_BACKUP , SIGNER_BITGO } from '../resources/xrp' ;
13
14
import * as _ from 'lodash' ;
14
15
import { XrpToken } from '../../src' ;
15
16
import * as xrpl from 'xrpl' ;
@@ -224,6 +225,58 @@ describe('XRP:', function () {
224
225
coSignedHexTransaction . id . should . equal ( coSignedJsonTransaction . id ) ;
225
226
} ) ;
226
227
228
+ it ( 'should correctly sort signers by numeric value of addresses' , function ( ) {
229
+ // Use the test signers from the test resources
230
+ // These are known valid key pairs where the private key corresponds to the address
231
+ const signers = [ SIGNER_USER , SIGNER_BACKUP , SIGNER_BITGO ] ;
232
+
233
+ // Unsigned transaction
234
+ const unsignedTxHex =
235
+ '120000228000000024000000072E00000000201B0018D07161400000000003DE2968400000000000002D8114726D0D8A26568D5D9680AC80577C912236717191831449EE221CCACC4DD2BF8862B22B0960A84FC771D9' ;
236
+
237
+ // Sign with first signer
238
+ let signedTx = ripple . signWithPrivateKey ( unsignedTxHex , signers [ 0 ] . prv , {
239
+ signAs : signers [ 0 ] . address ,
240
+ } ) ;
241
+
242
+ // Sign with second signer
243
+ signedTx = ripple . signWithPrivateKey ( signedTx . signedTransaction , signers [ 1 ] . prv , {
244
+ signAs : signers [ 1 ] . address ,
245
+ } ) ;
246
+
247
+ // Sign with third signer
248
+ signedTx = ripple . signWithPrivateKey ( signedTx . signedTransaction , signers [ 2 ] . prv , {
249
+ signAs : signers [ 2 ] . address ,
250
+ } ) ;
251
+
252
+ // Decode the signed transaction
253
+ const decodedTx = rippleBinaryCodec . decode ( signedTx . signedTransaction ) ;
254
+
255
+ // Verify that the Signers array exists and has the correct length
256
+ assert ( Array . isArray ( decodedTx . Signers ) ) ;
257
+ ( decodedTx . Signers as Array < any > ) . length . should . equal ( 3 ) ;
258
+
259
+ // Extract the addresses from the Signers array
260
+ const signerAddresses = ( decodedTx . Signers as Array < any > ) . map ( ( signer ) => signer . Signer . Account ) ;
261
+
262
+ // Convert addresses to BigNumber for numeric comparison
263
+ const addressToBigNumber = ( address ) => {
264
+ const hex = Buffer . from ( xrpl . decodeAccountID ( address ) ) . toString ( 'hex' ) ;
265
+ return BigInt ( '0x' + hex ) ;
266
+ } ;
267
+
268
+ // Convert the addresses to BigNumber values
269
+ const signerValues = signerAddresses . map ( addressToBigNumber ) ;
270
+
271
+ // Verify that the Signers array is sorted in ascending order by numeric value
272
+ for ( let i = 0 ; i < signerValues . length - 1 ; i ++ ) {
273
+ assert (
274
+ signerValues [ i ] < signerValues [ i + 1 ] ,
275
+ `Signers not properly sorted: ${ signerValues [ i ] } should be less than ${ signerValues [ i + 1 ] } `
276
+ ) ;
277
+ }
278
+ } ) ;
279
+
227
280
it ( 'Should be unable to explain bogus XRP transaction' , async function ( ) {
228
281
await basecoin
229
282
. explainTransaction ( { txHex : 'abcdefgH' } )
0 commit comments