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

signer: Only merge multisigs if there are more than 1 #822

Merged
merged 5 commits into from
Sep 5, 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
6 changes: 5 additions & 1 deletion src/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ export function makeMultiSigAccountTransactionSigner(
partialSigs.push(blob);
}

signed.push(mergeMultisigTransactions(partialSigs));
if (partialSigs.length > 1) {
signed.push(mergeMultisigTransactions(partialSigs));
} else {
signed.push(partialSigs[0]);
}
}

return Promise.resolve(signed);
Expand Down
56 changes: 48 additions & 8 deletions tests/10.ABI.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
/* eslint-env mocha */
import assert from 'assert';
import {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to any other reviewers: these just organize the imports (they are non-functional changes)

ABIMethod,
AtomicTransactionComposer,
AtomicTransactionComposerStatus,
MultisigMetadata,
generateAccount,
makeBasicAccountTransactionSigner,
makeMultiSigAccountTransactionSigner,
makePaymentTxnWithSuggestedParams,
} from '../src';
import {
ABIAddressType,
ABIArrayDynamicType,
Expand All @@ -8,18 +18,11 @@ import {
ABIByteType,
ABIStringType,
ABITupleType,
ABIType,
ABIUfixedType,
ABIUintType,
ABIType,
ABIValue,
} from '../src/abi/abi_type';
import {
AtomicTransactionComposer,
ABIMethod,
makeBasicAccountTransactionSigner,
generateAccount,
AtomicTransactionComposerStatus,
} from '../src';
import { decodeAddress } from '../src/encoding/address';

describe('ABI type checking', () => {
Expand Down Expand Up @@ -534,4 +537,41 @@ describe('ABI encoding', () => {
assert.deepStrictEqual(txn.appAccounts?.length, 1);
assert.deepStrictEqual(txn.appAccounts[0], decodeAddress(foreignAcct));
});

it('should accept at least one signature in the multisig', () => {
const account1 = generateAccount();
const account2 = generateAccount();

// Create a multisig signer
const msig: MultisigMetadata = {
version: 1,
threshold: 1,
addrs: [account1.addr, account2.addr],
};
const sks: Uint8Array[] = [account1.sk];
const signer = makeMultiSigAccountTransactionSigner(msig, sks);

// Create a transaction
const suggestedParams = {
genesisHash: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=',
genesisID: '',
firstRound: 0,
lastRound: 1000,
fee: 1000,
flatFee: true,
};
const actualTxn = makePaymentTxnWithSuggestedParams(
account1.addr,
account2.addr,
1000,
undefined,
undefined,
suggestedParams
);

// A multisig with 1 signature should be accepted
signer([actualTxn], [0]).then((signedTxns) => {
assert.deepStrictEqual(signedTxns.length, 1);
});
});
});
Loading