Skip to content

Commit

Permalink
refactor(sdk-coin-apt): check feePayerAddress for signablePayload
Browse files Browse the repository at this point in the history
TICKET: COIN-2838
  • Loading branch information
bhavidhingra authored and at31416 committed Jan 22, 2025
1 parent 59730e2 commit 120878a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 22 deletions.
21 changes: 9 additions & 12 deletions modules/sdk-coin-apt/src/lib/transaction/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ export abstract class Transaction extends BaseTransaction {
return this._feePayerAddress;
}

set feePayerAddress(value: string) {
this._feePayerAddress = value;
}

set transactionType(transactionType: TransactionType) {
this._type = transactionType;
}
Expand Down Expand Up @@ -235,15 +231,15 @@ export abstract class Transaction extends BaseTransaction {
this._rawTransaction = rawTxn;

this.loadInputsAndOutputs();
const authenticator = signedTxn.authenticator as any;
const authenticator = signedTxn.authenticator as TransactionAuthenticatorFeePayer;
this._feePayerAddress = authenticator.fee_payer.address.toString();
const senderSignature = Buffer.from(authenticator.sender.signature.toUint8Array());
this.addSenderSignature({ pub: authenticator.sender.public_key.toString() }, senderSignature);
const feePayerSignature = Buffer.from(authenticator.fee_payer.authenticator.signature.toUint8Array());
this.addFeePayerSignature(
{ pub: authenticator.fee_payer.authenticator.public_key.toString() },
feePayerSignature
);
const senderAuthenticator = authenticator.sender as AccountAuthenticatorEd25519;
const senderSignature = Buffer.from(senderAuthenticator.signature.toUint8Array());
this.addSenderSignature({ pub: senderAuthenticator.public_key.toString() }, senderSignature);

const feePayerAuthenticator = authenticator.fee_payer.authenticator as AccountAuthenticatorEd25519;
const feePayerSignature = Buffer.from(feePayerAuthenticator.signature.toUint8Array());
this.addFeePayerSignature({ pub: feePayerAuthenticator.public_key.toString() }, feePayerSignature);
} catch (e) {
console.error('invalid signed transaction', e);
throw new Error('invalid signed transaction');
Expand Down Expand Up @@ -312,6 +308,7 @@ export abstract class Transaction extends BaseTransaction {
!this._senderSignature ||
!this._senderSignature.publicKey ||
!this._senderSignature.signature ||
!this._feePayerSignature ||
!this._feePayerSignature.publicKey ||
!this._feePayerSignature.signature
) {
Expand Down
5 changes: 0 additions & 5 deletions modules/sdk-coin-apt/test/resources/apt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ export const sender = {
};

export const sender2 = {
address: '0xc8f02d25aa698b3e9fbd8a08e8da4c8ee261832a25a4cde8731b5ec356537d09',
publicKey: '0x2121dcd098069ae535697dd019cfd8677ca7aba0adac1d1959cbce6dc54b1259',
};

export const sender3 = {
address: '0x1aed808916ab9b1b30b07abb53561afd46847285ce28651221d406173a372449',
publicKey: '0xf73836f42257240e43d439552471fc9dbcc3f1af5bd0b4ed83f44b5f66146442',
};
Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-coin-apt/test/unit/apt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('APT:', function () {
describe('Parse and Explain Transactions: ', () => {
const transferInputsResponse = [
{
address: testData.sender3.address,
address: testData.sender2.address,
amount: testData.AMOUNT.toString(),
},
];
Expand Down
6 changes: 3 additions & 3 deletions modules/sdk-coin-apt/test/unit/transferBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('Apt Transfer Transaction', () => {
const rawTx = tx.toBroadcastFormat();
should.equal(utils.isValidRawTransaction(rawTx), true);
rawTx.should.equal(
'0xc8f02d25aa698b3e9fbd8a08e8da4c8ee261832a25a4cde8731b5ec356537d090e000000000000000200000000000000000000000000000000000000000000000000000000000000010d6170746f735f6163636f756e74087472616e73666572000220f7405c28a02cf5bab4ea4498240bb3579db45951794eb1c843bef0534c093ad908e803000000000000400d03000000000064000000000000008b037d670000000002030020000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000dbc87a1c816d9bcd06b683c37e80c7162e4d48da7812198b830e4d5d8e0629f2002000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
'0x1aed808916ab9b1b30b07abb53561afd46847285ce28651221d406173a3724490e000000000000000200000000000000000000000000000000000000000000000000000000000000010d6170746f735f6163636f756e74087472616e73666572000220f7405c28a02cf5bab4ea4498240bb3579db45951794eb1c843bef0534c093ad908e803000000000000400d03000000000064000000000000008b037d670000000002030020000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000dbc87a1c816d9bcd06b683c37e80c7162e4d48da7812198b830e4d5d8e0629f2002000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
);
});

Expand All @@ -55,7 +55,7 @@ describe('Apt Transfer Transaction', () => {
should.equal(tx.type, TransactionType.Send);
tx.inputs.length.should.equal(1);
tx.inputs[0].should.deepEqual({
address: testData.sender3.address,
address: testData.sender2.address,
value: testData.recipients[0].amount,
coin: 'tapt',
});
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('Apt Transfer Transaction', () => {
const signablePayload = tx.signablePayload;
should.equal(
signablePayload.toString('hex'),
'5efa3c4f02f83a0f4b2d69fc95c607cc02825cc4e7be536ef0992df050d9e67c01c8f02d25aa698b3e9fbd8a08e8da4c8ee261832a25a4cde8731b5ec356537d090e000000000000000200000000000000000000000000000000000000000000000000000000000000010d6170746f735f6163636f756e74087472616e73666572000220f7405c28a02cf5bab4ea4498240bb3579db45951794eb1c843bef0534c093ad908e803000000000000400d03000000000064000000000000008b037d67000000000200dbc87a1c816d9bcd06b683c37e80c7162e4d48da7812198b830e4d5d8e0629f2'
'5efa3c4f02f83a0f4b2d69fc95c607cc02825cc4e7be536ef0992df050d9e67c011aed808916ab9b1b30b07abb53561afd46847285ce28651221d406173a3724490e000000000000000200000000000000000000000000000000000000000000000000000000000000010d6170746f735f6163636f756e74087472616e73666572000220f7405c28a02cf5bab4ea4498240bb3579db45951794eb1c843bef0534c093ad908e803000000000000400d03000000000064000000000000008b037d67000000000200dbc87a1c816d9bcd06b683c37e80c7162e4d48da7812198b830e4d5d8e0629f2'
);
});

Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-coin-apt/test/unit/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Aptos util library', function () {
const signedTxn: SignedTransaction = utils.deserializeSignedTransaction(testData.TRANSFER);
const rawTx = signedTxn.raw_txn;
const recipient = utils.getRecipientFromTransactionPayload(rawTx.payload);
should.equal(rawTx.sender.toString(), testData.sender3.address);
should.equal(rawTx.sender.toString(), testData.sender2.address);
should.equal(rawTx.max_gas_amount, 200000);
should.equal(rawTx.gas_unit_price, 100);
should.equal(rawTx.sequence_number, 146);
Expand Down

0 comments on commit 120878a

Please sign in to comment.