Skip to content

Commit

Permalink
fix(account): dont allow additional signatures in execute
Browse files Browse the repository at this point in the history
  • Loading branch information
janek26 committed Feb 9, 2022
1 parent 0be78c6 commit ac02d46
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 28 deletions.
24 changes: 8 additions & 16 deletions src/account/default.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import assert from 'minimalistic-assert';

import { compileCalldata } from '../contract';
import { Provider } from '../provider';
import { Signer, SignerInterface } from '../signer';
import {
Abi,
AddTransactionResponse,
Invocation,
ExecuteInvocation,
InvocationsDetails,
KeyPair,
Signature,
Expand Down Expand Up @@ -44,7 +42,7 @@ export class Account extends Provider implements AccountInterface {
* @returns a confirmation of invoking a function on the starknet contract
*/
public async execute(
transactions: Invocation | Invocation[],
transactions: ExecuteInvocation | ExecuteInvocation[],
abis: Abi[] = [],
transactionsDetail: InvocationsDetails = {}
): Promise<AddTransactionResponse> {
Expand All @@ -60,11 +58,6 @@ export class Account extends Provider implements AccountInterface {
} = Array.isArray(transactions) ? transactions[0] : transactions;
const { nonce } = transactionsDetail;

assert(
!invocation.signature,
"Adding signatures to an account transaction currently isn't supported"
);

const nonceBn = toBN(nonce ?? (await this.getNonce()));
const calldataDecimal = bigNumberishArrayToDecimalStringArray(calldata);

Expand All @@ -83,18 +76,17 @@ export class Account extends Provider implements AccountInterface {

const entrypointSelector = getSelectorFromName(entrypoint);

return super.fetchEndpoint('add_transaction', undefined, {
type: 'INVOKE_FUNCTION',
entry_point_selector: getSelectorFromName('execute'),
calldata: bigNumberishArrayToDecimalStringArray([
return super.invokeFunction({
contractAddress: this.address,
entrypoint: 'execute',
calldata: [
contractAddress,
entrypointSelector,
calldataDecimal.length.toString(),
...calldataDecimal,
nonceBn.toString(),
]),
contract_address: this.address,
signature: bigNumberishArrayToDecimalStringArray(signature),
],
signature,
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/account/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
Abi,
AddTransactionResponse,
DeployContractPayload,
Invocation,
ExecuteInvocation,
InvocationsDetails,
Signature,
} from '../types';
Expand Down Expand Up @@ -41,7 +41,7 @@ export abstract class AccountInterface extends ProviderInterface {
* @returns response from addTransaction
*/
public abstract execute(
transactions: Invocation | Invocation[],
transactions: ExecuteInvocation | ExecuteInvocation[],
abis?: Abi[],
transactionsDetail?: InvocationsDetails
): Promise<AddTransactionResponse>;
Expand Down
12 changes: 2 additions & 10 deletions src/provider/interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {
Abi,
AddTransactionResponse,
Call,
CallContractResponse,
Expand Down Expand Up @@ -120,13 +119,9 @@ export abstract class ProviderInterface {
* - compiled contract code
* - constructor calldata
* - address salt
* @param abi the abi of the contract
* @returns a confirmation of sending a transaction on the starknet contract
*/
public abstract deployContract(
payload: DeployContractPayload,
abi?: Abi
): Promise<AddTransactionResponse>;
public abstract deployContract(payload: DeployContractPayload): Promise<AddTransactionResponse>;

/**
* Invokes a function on starknet
Expand All @@ -140,10 +135,7 @@ export abstract class ProviderInterface {
*
* @returns response from addTransaction
*/
public abstract invokeFunction(
invocation: Invocation,
abi?: Abi
): Promise<AddTransactionResponse>;
public abstract invokeFunction(invocation: Invocation): Promise<AddTransactionResponse>;

public abstract waitForTx(txHash: BigNumberish, retryInterval?: number): Promise<void>;
}
2 changes: 2 additions & 0 deletions src/types/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export type Invocation = {
signature?: Signature;
};

export type ExecuteInvocation = Omit<Invocation, 'signature'>;

export type InvocationsDetails = {
nonce?: BigNumberish;
};
Expand Down

0 comments on commit ac02d46

Please sign in to comment.