Skip to content

Commit 120878a

Browse files
bhavidhingraat31416
authored andcommitted
refactor(sdk-coin-apt): check feePayerAddress for signablePayload
TICKET: COIN-2838
1 parent 59730e2 commit 120878a

File tree

5 files changed

+14
-22
lines changed

5 files changed

+14
-22
lines changed

modules/sdk-coin-apt/src/lib/transaction/transaction.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ export abstract class Transaction extends BaseTransaction {
135135
return this._feePayerAddress;
136136
}
137137

138-
set feePayerAddress(value: string) {
139-
this._feePayerAddress = value;
140-
}
141-
142138
set transactionType(transactionType: TransactionType) {
143139
this._type = transactionType;
144140
}
@@ -235,15 +231,15 @@ export abstract class Transaction extends BaseTransaction {
235231
this._rawTransaction = rawTxn;
236232

237233
this.loadInputsAndOutputs();
238-
const authenticator = signedTxn.authenticator as any;
234+
const authenticator = signedTxn.authenticator as TransactionAuthenticatorFeePayer;
239235
this._feePayerAddress = authenticator.fee_payer.address.toString();
240-
const senderSignature = Buffer.from(authenticator.sender.signature.toUint8Array());
241-
this.addSenderSignature({ pub: authenticator.sender.public_key.toString() }, senderSignature);
242-
const feePayerSignature = Buffer.from(authenticator.fee_payer.authenticator.signature.toUint8Array());
243-
this.addFeePayerSignature(
244-
{ pub: authenticator.fee_payer.authenticator.public_key.toString() },
245-
feePayerSignature
246-
);
236+
const senderAuthenticator = authenticator.sender as AccountAuthenticatorEd25519;
237+
const senderSignature = Buffer.from(senderAuthenticator.signature.toUint8Array());
238+
this.addSenderSignature({ pub: senderAuthenticator.public_key.toString() }, senderSignature);
239+
240+
const feePayerAuthenticator = authenticator.fee_payer.authenticator as AccountAuthenticatorEd25519;
241+
const feePayerSignature = Buffer.from(feePayerAuthenticator.signature.toUint8Array());
242+
this.addFeePayerSignature({ pub: feePayerAuthenticator.public_key.toString() }, feePayerSignature);
247243
} catch (e) {
248244
console.error('invalid signed transaction', e);
249245
throw new Error('invalid signed transaction');
@@ -312,6 +308,7 @@ export abstract class Transaction extends BaseTransaction {
312308
!this._senderSignature ||
313309
!this._senderSignature.publicKey ||
314310
!this._senderSignature.signature ||
311+
!this._feePayerSignature ||
315312
!this._feePayerSignature.publicKey ||
316313
!this._feePayerSignature.signature
317314
) {

modules/sdk-coin-apt/test/resources/apt.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ export const sender = {
2121
};
2222

2323
export const sender2 = {
24-
address: '0xc8f02d25aa698b3e9fbd8a08e8da4c8ee261832a25a4cde8731b5ec356537d09',
25-
publicKey: '0x2121dcd098069ae535697dd019cfd8677ca7aba0adac1d1959cbce6dc54b1259',
26-
};
27-
28-
export const sender3 = {
2924
address: '0x1aed808916ab9b1b30b07abb53561afd46847285ce28651221d406173a372449',
3025
publicKey: '0xf73836f42257240e43d439552471fc9dbcc3f1af5bd0b4ed83f44b5f66146442',
3126
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ describe('APT:', function () {
104104
describe('Parse and Explain Transactions: ', () => {
105105
const transferInputsResponse = [
106106
{
107-
address: testData.sender3.address,
107+
address: testData.sender2.address,
108108
amount: testData.AMOUNT.toString(),
109109
},
110110
];

modules/sdk-coin-apt/test/unit/transferBuilder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('Apt Transfer Transaction', () => {
4545
const rawTx = tx.toBroadcastFormat();
4646
should.equal(utils.isValidRawTransaction(rawTx), true);
4747
rawTx.should.equal(
48-
'0xc8f02d25aa698b3e9fbd8a08e8da4c8ee261832a25a4cde8731b5ec356537d090e000000000000000200000000000000000000000000000000000000000000000000000000000000010d6170746f735f6163636f756e74087472616e73666572000220f7405c28a02cf5bab4ea4498240bb3579db45951794eb1c843bef0534c093ad908e803000000000000400d03000000000064000000000000008b037d670000000002030020000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000dbc87a1c816d9bcd06b683c37e80c7162e4d48da7812198b830e4d5d8e0629f2002000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
48+
'0x1aed808916ab9b1b30b07abb53561afd46847285ce28651221d406173a3724490e000000000000000200000000000000000000000000000000000000000000000000000000000000010d6170746f735f6163636f756e74087472616e73666572000220f7405c28a02cf5bab4ea4498240bb3579db45951794eb1c843bef0534c093ad908e803000000000000400d03000000000064000000000000008b037d670000000002030020000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000dbc87a1c816d9bcd06b683c37e80c7162e4d48da7812198b830e4d5d8e0629f2002000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
4949
);
5050
});
5151

@@ -55,7 +55,7 @@ describe('Apt Transfer Transaction', () => {
5555
should.equal(tx.type, TransactionType.Send);
5656
tx.inputs.length.should.equal(1);
5757
tx.inputs[0].should.deepEqual({
58-
address: testData.sender3.address,
58+
address: testData.sender2.address,
5959
value: testData.recipients[0].amount,
6060
coin: 'tapt',
6161
});
@@ -92,7 +92,7 @@ describe('Apt Transfer Transaction', () => {
9292
const signablePayload = tx.signablePayload;
9393
should.equal(
9494
signablePayload.toString('hex'),
95-
'5efa3c4f02f83a0f4b2d69fc95c607cc02825cc4e7be536ef0992df050d9e67c01c8f02d25aa698b3e9fbd8a08e8da4c8ee261832a25a4cde8731b5ec356537d090e000000000000000200000000000000000000000000000000000000000000000000000000000000010d6170746f735f6163636f756e74087472616e73666572000220f7405c28a02cf5bab4ea4498240bb3579db45951794eb1c843bef0534c093ad908e803000000000000400d03000000000064000000000000008b037d67000000000200dbc87a1c816d9bcd06b683c37e80c7162e4d48da7812198b830e4d5d8e0629f2'
95+
'5efa3c4f02f83a0f4b2d69fc95c607cc02825cc4e7be536ef0992df050d9e67c011aed808916ab9b1b30b07abb53561afd46847285ce28651221d406173a3724490e000000000000000200000000000000000000000000000000000000000000000000000000000000010d6170746f735f6163636f756e74087472616e73666572000220f7405c28a02cf5bab4ea4498240bb3579db45951794eb1c843bef0534c093ad908e803000000000000400d03000000000064000000000000008b037d67000000000200dbc87a1c816d9bcd06b683c37e80c7162e4d48da7812198b830e4d5d8e0629f2'
9696
);
9797
});
9898

modules/sdk-coin-apt/test/unit/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('Aptos util library', function () {
3838
const signedTxn: SignedTransaction = utils.deserializeSignedTransaction(testData.TRANSFER);
3939
const rawTx = signedTxn.raw_txn;
4040
const recipient = utils.getRecipientFromTransactionPayload(rawTx.payload);
41-
should.equal(rawTx.sender.toString(), testData.sender3.address);
41+
should.equal(rawTx.sender.toString(), testData.sender2.address);
4242
should.equal(rawTx.max_gas_amount, 200000);
4343
should.equal(rawTx.gas_unit_price, 100);
4444
should.equal(rawTx.sequence_number, 146);

0 commit comments

Comments
 (0)