Skip to content

Commit 011e248

Browse files
Merge pull request #5011 from BitGo/WIN-3569-fix
fix(sdk-coin-xrp): fix xrp signing bug
2 parents 0fc9629 + a845372 commit 011e248

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

modules/sdk-coin-xrp/src/xrp.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,20 @@ export class Xrp extends BaseCoin {
136136
if (!txPrebuild.txHex) {
137137
throw new Error(`missing txHex in txPrebuild`);
138138
}
139-
const signedTx = utils.signString(txPrebuild.txHex, prv);
139+
const keyPair = new XrpKeyPair({ prv });
140+
const address = keyPair.getAddress();
141+
const privateKey = (keyPair.getPrivateKey() as Buffer).toString('hex');
142+
143+
const tx = ripple.signWithPrivateKey(txPrebuild.txHex, privateKey, {
144+
signAs: address,
145+
});
140146

141147
// Normally the SDK provides the first signature for an XRP tx, but occasionally it provides the final one as well
142148
// (recoveries)
143149
if (isLastSignature) {
144-
return { txHex: signedTx };
150+
return { txHex: tx.signedTransaction };
145151
}
146-
return { halfSigned: { txHex: signedTx } };
152+
return { halfSigned: { txHex: tx.signedTransaction } };
147153
}
148154

149155
/**

modules/sdk-coin-xrp/test/unit/xrp.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,24 @@ describe('XRP:', function () {
129129
unsignedExplanation.fee.fee.should.equal('45');
130130
});
131131

132+
it('should be able to sign an XRP transaction', async function () {
133+
const txPrebuild = {
134+
txHex:
135+
'{"TransactionType":"Payment","Account":"rar86Kj9diPKaXWJM3kMaoRZw2r15opm5u","Fee":"45","Sequence":464628,"Destination":"rPWH6reJ8N1DcCkda8owpzWtJXgUNw2d3q","Amount":"10000","Flags":2147483648,"DestinationTag":0}',
136+
};
137+
const prv =
138+
'xprv9s21ZrQH143K4AEvLzUYqTg3whAkhHAfkPDcrCMYGBPPeFi4qBSgfPD57yTxbBogR7YwFZRjpRZpT5rWY9iA7LtHp1SG37LecCz1CfpkxVS';
139+
140+
const halfSigned = {
141+
halfSigned: {
142+
txHex:
143+
'120000228000000024000716F42E0000000061400000000000271068400000000000002D7300811436FEC5FB86E7E8348286D30FCD3BEAE9840B67178314F6DCC31A1BEE1F554C6CAB6E78D89D094D7C5126F3E01073210221C49E7F3F1B981396E577223B9EA14D85097B2A40C16A057C573EAAF4E9CD9374463044022072FF9C168A8B680F0C27D266B36E592E40116551F0A82C3A7EBF73447980D0B60220061CB55027C66DDC26638D3B45A91A199A7EFFCD494CDE958F86751946A4F5DB81146A38C6C4B589D0915A2325F7EA01994BF30C03C9E1F1',
144+
},
145+
};
146+
const res = await basecoin.signTransaction({ txPrebuild, prv });
147+
res.should.deepEqual(halfSigned);
148+
});
149+
132150
it('should be able to add second signature to half signed XRP transaction', function () {
133151
const halfSignedTxHex =
134152
'12000022800000002402364C9A2E00000000201B0251041E614000000000E4E1A268400000000000001E730081146ED6833681CD87DBC055D8DC5A92BC9E3CD287848314CF522A61021FA485553A6CE48E226D973258B9BBF3E01073210335479B7F82FC3280B72ED8659BC621A3284544DA9704B518EBC9275F669429CF7447304502210098AF70338FF43B9BEC9916BB8762E54C95CA85DBCE418F30A9640BF804DCB2DA02204221C2480BE44D9F6ED7331FD5FE580E42177873BA796B00255A6F55672BE26081149460A1C4C25209500B55D09F8CD13BD330968521E1F1';

0 commit comments

Comments
 (0)