Skip to content
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

fix(sdk-coin-ada): cosmetic signature array might duplicate #3692

Merged
merged 1 commit into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions modules/sdk-coin-ada/src/lib/transactionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
);
vkeyWitnesses.add(vkeyWitness);
});

// Clear the cosmetic signature array in native txn wrapper to prevent duplicate when builder is inited from a partially witnessed txn
this._transaction.signature.length = 0;
this.getAllSignatures().forEach((signature) => {
const vkey = CardanoWasm.Vkey.new(CardanoWasm.PublicKey.from_bytes(Buffer.from(signature.publicKey.pub, 'hex')));
const ed255Sig = CardanoWasm.Ed25519Signature.from_bytes(signature.signature);
Expand Down
20 changes: 19 additions & 1 deletion modules/sdk-coin-ada/test/unit/stakingPledgeBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ describe('ADA Staking Pledge Transaction Builder', async () => {
rebuiltTx.toBroadcastFormat().should.not.equal(rawTx.unsignedUpdatePledgeTx);
});

it('should init partially signed txn hex and preserver the signature', async () => {
it('should init from partially signed txn hex and preserve the signature', async () => {
const txnBuilderFactory = new TransactionBuilderFactory(coins.get('tada'));
const txnBuilder = txnBuilderFactory.from(rawTx.partiallySignedPledgeTx);
let tx = (await txnBuilder.build()) as Transaction;
tx.type.should.equal(TransactionType.StakingPledge);
tx.signature.length.should.equal(1);
let txData = tx.toJson();
txData.witnesses.length.should.equal(1);
txData.witnesses[0].publicKey.should.equal(rawTx.pledgeNodeKeyPubkey);
Expand All @@ -98,4 +99,21 @@ describe('ADA Staking Pledge Transaction Builder', async () => {
txData.witnesses[1].publicKey.should.equal(rawTx.pledgeNodeKeyPubkey);
txData.witnesses[1].signature.should.equal(rawTx.pledgeNodeWitnessSignature);
});

it('should init from partially signed txn object and preserve the signature', async () => {
const prebuiltTx = new Transaction(coins.get('tada'));
prebuiltTx.fromRawTransaction(rawTx.partiallySignedPledgeTx);
prebuiltTx.toBroadcastFormat().should.equal(rawTx.partiallySignedPledgeTx);
prebuiltTx.signature.length.should.equal(1);
const txBuilder = factory.getStakingPledgeBuilder();
txBuilder.initBuilder(prebuiltTx);
const tx = (await txBuilder.build()) as Transaction;
tx.type.should.equal(TransactionType.StakingPledge);
tx.toBroadcastFormat().should.equal(rawTx.partiallySignedPledgeTx);
tx.signature.length.should.equal(1);
const txData = tx.toJson();
txData.witnesses.length.should.equal(1);
txData.witnesses[0].publicKey.should.equal(rawTx.pledgeNodeKeyPubkey);
txData.witnesses[0].signature.should.equal(rawTx.pledgeNodeWitnessSignature);
});
});