Skip to content
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
10 changes: 9 additions & 1 deletion yarn-project/accounts/src/defaults/account_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ import { DefaultAccountInterface } from '../defaults/account_interface.js';
*/
export abstract class DefaultAccountContract implements AccountContract {
abstract getAuthWitnessProvider(address: CompleteAddress): AuthWitnessProvider;
abstract getDeploymentArgs(): Promise<any[] | undefined>;
abstract getDeploymentFunctionAndArgs(): Promise<
| {
/** The name of the function used to deploy the contract */
constructorName: string;
/** The args to the function used to deploy the contract */
constructorArgs: any[];
}
| undefined
>;
abstract getContractArtifact(): Promise<ContractArtifact>;

constructor() {}
Expand Down
7 changes: 5 additions & 2 deletions yarn-project/accounts/src/ecdsa/ecdsa_k/account_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ export abstract class EcdsaKBaseAccountContract extends DefaultAccountContract {
super();
}

async getDeploymentArgs() {
async getDeploymentFunctionAndArgs() {
const signingPublicKey = await new Ecdsa().computePublicKey(this.signingPrivateKey);
return [signingPublicKey.subarray(0, 32), signingPublicKey.subarray(32, 64)];
return {
constructorName: 'constructor',
constructorArgs: [signingPublicKey.subarray(0, 32), signingPublicKey.subarray(32, 64)],
};
}

getAuthWitnessProvider(_address: CompleteAddress): AuthWitnessProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ export abstract class EcdsaRSSHBaseAccountContract extends DefaultAccountContrac
super();
}

getDeploymentArgs() {
return Promise.resolve([this.signingPublicKey.subarray(0, 32), this.signingPublicKey.subarray(32, 64)]);
getDeploymentFunctionAndArgs() {
return Promise.resolve({
constructorName: 'constructor',
constructorArgs: [this.signingPublicKey.subarray(0, 32), this.signingPublicKey.subarray(32, 64)],
});
}

getAuthWitnessProvider(_address: CompleteAddress): AuthWitnessProvider {
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/accounts/src/schnorr/account_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export abstract class SchnorrBaseAccountContract extends DefaultAccountContract
super();
}

async getDeploymentArgs() {
async getDeploymentFunctionAndArgs() {
const signingPublicKey = await new Schnorr().computePublicKey(this.signingPrivateKey);
return [signingPublicKey.x, signingPublicKey.y];
return { constructorName: 'constructor', constructorArgs: [signingPublicKey.x, signingPublicKey.y] };
}

getAuthWitnessProvider(_address: CompleteAddress): AuthWitnessProvider {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/accounts/src/single_key/account_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export abstract class SingleKeyBaseAccountContract extends DefaultAccountContrac
super();
}

getDeploymentArgs() {
getDeploymentFunctionAndArgs() {
return Promise.resolve(undefined);
}

Expand Down
18 changes: 15 additions & 3 deletions yarn-project/aztec.js/src/account/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ export interface AccountContract {
getContractArtifact(): Promise<ContractArtifact>;

/**
* Returns the deployment arguments for this instance, or undefined if this contract does not require deployment.
* Returns the deployment function name and arguments for this instance, or undefined if this contract does not require deployment.
*/
getDeploymentArgs(): Promise<any[] | undefined>;
getDeploymentFunctionAndArgs(): Promise<
| {
/** The name of the function used to deploy the contract */
constructorName: string;
/** The args to the function used to deploy the contract */
constructorArgs: any[];
}
| undefined
>;

/**
* Returns the account interface for this account contract given a deployment at the provided address.
Expand All @@ -45,9 +53,13 @@ export interface AccountContract {
*/
export async function getAccountContractAddress(accountContract: AccountContract, secret: Fr, salt: Fr) {
const { publicKeys } = await deriveKeys(secret);
const constructorArgs = await accountContract.getDeploymentArgs();
const { constructorName, constructorArgs } = (await accountContract.getDeploymentFunctionAndArgs()) ?? {
constructorName: undefined,
constructorArgs: undefined,
};
const artifact = await accountContract.getContractArtifact();
const instance = await getContractInstanceFromDeployParams(artifact, {
constructorArtifact: constructorName,
constructorArgs,
salt,
publicKeys,
Expand Down
23 changes: 16 additions & 7 deletions yarn-project/aztec.js/src/account_manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ export class AccountManager {
const { publicKeys } = await deriveKeys(secretKey);
salt = salt !== undefined ? new Fr(salt) : Fr.random();

const { constructorName, constructorArgs } = (await accountContract.getDeploymentFunctionAndArgs()) ?? {
constructorName: undefined,
constructorArgs: undefined,
};

const artifact = await accountContract.getContractArtifact();
const instance = await getContractInstanceFromDeployParams(artifact, {
constructorArgs: await accountContract.getDeploymentArgs(),
constructorArtifact: constructorName,
constructorArgs,
salt: salt,
publicKeys,
});
Expand Down Expand Up @@ -149,7 +155,10 @@ export class AccountManager {

await this.pxe.registerAccount(this.secretKey, completeAddress.partialAddress);

const args = (await this.accountContract.getDeploymentArgs()) ?? [];
const { constructorName, constructorArgs } = (await this.accountContract.getDeploymentFunctionAndArgs()) ?? {
constructorName: undefined,
constructorArgs: undefined,
};

if (deployWallet) {
// If deploying using an existing wallet/account, treat it like regular contract deployment.
Expand All @@ -159,8 +168,8 @@ export class AccountManager {
deployWallet,
artifact,
address => Contract.at(address, artifact, thisWallet),
args,
'constructor',
constructorArgs,
constructorName,
);
}

Expand All @@ -175,8 +184,8 @@ export class AccountManager {
this.getPublicKeys(),
wallet,
artifact,
args,
'constructor',
constructorArgs,
constructorName,
'entrypoint',
);
}
Expand Down Expand Up @@ -221,7 +230,7 @@ export class AccountManager {
* Returns whether this account contract has a constructor and needs deployment.
*/
public async isDeployable() {
return (await this.accountContract.getDeploymentArgs()) !== undefined;
return (await this.accountContract.getDeploymentFunctionAndArgs()) !== undefined;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SchnorrHardcodedKeyAccountContract extends DefaultAccountContract {
return Promise.resolve(SchnorrHardcodedAccountContractArtifact);
}

getDeploymentArgs() {
getDeploymentFunctionAndArgs() {
// This contract has no constructor
return Promise.resolve(undefined);
}
Expand Down