@aztec/txe 0.75.0 → 0.76.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,11 @@
1
- import { SchnorrAccountContractArtifact } from '@aztec/accounts/schnorr';
2
1
  import { MerkleTreeId, SimulationError } from '@aztec/circuit-types';
3
2
  import {
3
+ type ContractInstanceWithAddress,
4
4
  DEPLOYER_CONTRACT_ADDRESS,
5
5
  Fr,
6
6
  FunctionSelector,
7
7
  PublicDataWrite,
8
- PublicKeys,
9
8
  computePartialAddress,
10
- getContractInstanceFromDeployParams,
11
9
  } from '@aztec/circuits.js';
12
10
  import { computePublicDataTreeLeafSlot, siloNullifier } from '@aztec/circuits.js/hash';
13
11
  import { type ContractArtifact, NoteSelector } from '@aztec/foundation/abi';
@@ -90,40 +88,19 @@ export class TXEService {
90
88
  return toForeignCallResult(keys.publicKeys.toFields().map(toSingle));
91
89
  }
92
90
 
93
- async deploy(
94
- artifact: ContractArtifact,
95
- initializer: ForeignCallArray,
96
- _length: ForeignCallSingle,
97
- args: ForeignCallArray,
98
- publicKeysHash: ForeignCallSingle,
99
- ) {
100
- const initializerStr = fromArray(initializer)
101
- .map(char => String.fromCharCode(char.toNumber()))
102
- .join('');
103
- const decodedArgs = fromArray(args);
104
- const publicKeysHashFr = fromSingle(publicKeysHash);
105
- this.logger.debug(
106
- `Deploy ${artifact.name} with initializer ${initializerStr}(${decodedArgs}) and public keys hash ${publicKeysHashFr}`,
107
- );
108
-
109
- const instance = await getContractInstanceFromDeployParams(artifact, {
110
- constructorArgs: decodedArgs,
111
- skipArgsDecoding: true,
112
- salt: Fr.ONE,
113
- // TODO: Modify this to allow for passing public keys.
114
- publicKeys: PublicKeys.default(),
115
- constructorArtifact: initializerStr ? initializerStr : undefined,
116
- deployer: AztecAddress.ZERO,
117
- });
118
-
91
+ async deploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: ForeignCallSingle) {
119
92
  // Emit deployment nullifier
120
93
  (this.typedOracle as TXE).addSiloedNullifiersFromPublic([
121
94
  await siloNullifier(AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS), instance.address.toField()),
122
95
  ]);
123
96
 
97
+ if (!fromSingle(secret).equals(Fr.ZERO)) {
98
+ await this.createAccount(secret);
99
+ }
100
+
124
101
  this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
125
102
  await (this.typedOracle as TXE).addContractInstance(instance);
126
- await (this.typedOracle as TXE).addContractArtifact(artifact);
103
+ await (this.typedOracle as TXE).addContractArtifact(instance.contractClassId, artifact);
127
104
  return toForeignCallResult([
128
105
  toArray([
129
106
  instance.salt,
@@ -157,9 +134,10 @@ export class TXEService {
157
134
  return toForeignCallResult([toArray(publicDataWrites.map(write => write.value))]);
158
135
  }
159
136
 
160
- async createAccount() {
137
+ async createAccount(secret: ForeignCallSingle) {
161
138
  const keyStore = (this.typedOracle as TXE).getKeyStore();
162
- const completeAddress = await keyStore.createAccount();
139
+ const secretFr = fromSingle(secret);
140
+ const completeAddress = await keyStore.addAccount(secretFr, secretFr);
163
141
  const accountStore = (this.typedOracle as TXE).getTXEDatabase();
164
142
  await accountStore.setAccount(completeAddress.address, completeAddress);
165
143
  this.logger.debug(`Created account ${completeAddress.address}`);
@@ -169,22 +147,10 @@ export class TXEService {
169
147
  ]);
170
148
  }
171
149
 
172
- async addAccount(secret: ForeignCallSingle) {
173
- const keys = await (this.typedOracle as TXE).deriveKeys(fromSingle(secret));
174
- const args = [keys.publicKeys.masterIncomingViewingPublicKey.x, keys.publicKeys.masterIncomingViewingPublicKey.y];
175
- const artifact = SchnorrAccountContractArtifact;
176
- const instance = await getContractInstanceFromDeployParams(artifact, {
177
- constructorArgs: args,
178
- skipArgsDecoding: true,
179
- salt: Fr.ONE,
180
- publicKeys: keys.publicKeys,
181
- constructorArtifact: 'constructor',
182
- deployer: AztecAddress.ZERO,
183
- });
184
-
150
+ async addAccount(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: ForeignCallSingle) {
185
151
  this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
186
152
  await (this.typedOracle as TXE).addContractInstance(instance);
187
- await (this.typedOracle as TXE).addContractArtifact(artifact);
153
+ await (this.typedOracle as TXE).addContractArtifact(instance.contractClassId, artifact);
188
154
 
189
155
  const keyStore = (this.typedOracle as TXE).getKeyStore();
190
156
  const completeAddress = await keyStore.addAccount(fromSingle(secret), await computePartialAddress(instance));
@@ -1,4 +1,4 @@
1
- import { AztecAddress } from '@aztec/circuits.js';
1
+ import { AztecAddress, type ContractInstanceWithAddress, ContractInstanceWithAddressSchema } from '@aztec/circuits.js';
2
2
  import { type ContractArtifact, ContractArtifactSchema } from '@aztec/foundation/abi';
3
3
  import { Fr } from '@aztec/foundation/fields';
4
4
  import { hexToBuffer } from '@aztec/foundation/string';
@@ -9,7 +9,7 @@ export type ForeignCallSingle = string;
9
9
 
10
10
  export type ForeignCallArray = string[];
11
11
 
12
- export type ForeignCallArgs = (ForeignCallSingle | ForeignCallArray | ContractArtifact)[];
12
+ export type ForeignCallArgs = (ForeignCallSingle | ForeignCallArray | ContractArtifact | ContractInstanceWithAddress)[];
13
13
 
14
14
  export type ForeignCallResult = {
15
15
  values: (ForeignCallSingle | ForeignCallArray)[];
@@ -44,7 +44,7 @@ export const ForeignCallSingleSchema = z.string();
44
44
  export const ForeignCallArraySchema = z.array(z.string());
45
45
 
46
46
  export const ForeignCallArgsSchema = z.array(
47
- z.union([ForeignCallSingleSchema, ForeignCallArraySchema, ContractArtifactSchema]),
47
+ z.union([ForeignCallSingleSchema, ForeignCallArraySchema, ContractArtifactSchema, ContractInstanceWithAddressSchema]),
48
48
  );
49
49
 
50
50
  export const ForeignCallResultSchema = z.object({