@aztec/builder 0.46.5 → 0.46.6

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.
Files changed (47) hide show
  1. package/dest/cli.js +4 -25
  2. package/package.json +4 -20
  3. package/src/cli.ts +3 -25
  4. package/dest/cli/codegen.d.ts +0 -10
  5. package/dest/cli/codegen.d.ts.map +0 -1
  6. package/dest/cli/codegen.js +0 -71
  7. package/dest/cli/update/common.d.ts +0 -17
  8. package/dest/cli/update/common.d.ts.map +0 -1
  9. package/dest/cli/update/common.js +0 -2
  10. package/dest/cli/update/github.d.ts +0 -4
  11. package/dest/cli/update/github.d.ts.map +0 -1
  12. package/dest/cli/update/github.js +0 -4
  13. package/dest/cli/update/noir.d.ts +0 -10
  14. package/dest/cli/update/noir.d.ts.map +0 -1
  15. package/dest/cli/update/noir.js +0 -47
  16. package/dest/cli/update/npm.d.ts +0 -34
  17. package/dest/cli/update/npm.d.ts.map +0 -1
  18. package/dest/cli/update/npm.js +0 -125
  19. package/dest/cli/update/update.d.ts +0 -3
  20. package/dest/cli/update/update.d.ts.map +0 -1
  21. package/dest/cli/update/update.js +0 -58
  22. package/dest/cli/update/utils.d.ts +0 -14
  23. package/dest/cli/update/utils.d.ts.map +0 -1
  24. package/dest/cli/update/utils.js +0 -43
  25. package/dest/contract-interface-gen/typescript.d.ts +0 -9
  26. package/dest/contract-interface-gen/typescript.d.ts.map +0 -1
  27. package/dest/contract-interface-gen/typescript.js +0 -349
  28. package/dest/index.d.ts +0 -2
  29. package/dest/index.d.ts.map +0 -1
  30. package/dest/index.js +0 -2
  31. package/dest/mocked_keys.d.ts +0 -2
  32. package/dest/mocked_keys.d.ts.map +0 -1
  33. package/dest/mocked_keys.js +0 -2
  34. package/dest/utils.d.ts +0 -10
  35. package/dest/utils.d.ts.map +0 -1
  36. package/dest/utils.js +0 -32
  37. package/src/cli/codegen.ts +0 -91
  38. package/src/cli/update/common.ts +0 -16
  39. package/src/cli/update/github.ts +0 -3
  40. package/src/cli/update/noir.ts +0 -57
  41. package/src/cli/update/npm.ts +0 -154
  42. package/src/cli/update/update.ts +0 -78
  43. package/src/cli/update/utils.ts +0 -50
  44. package/src/contract-interface-gen/typescript.ts +0 -389
  45. package/src/index.ts +0 -1
  46. package/src/mocked_keys.ts +0 -2
  47. package/src/utils.ts +0 -33
@@ -1,389 +0,0 @@
1
- import {
2
- type ABIParameter,
3
- type ContractArtifact,
4
- type FunctionArtifact,
5
- getDefaultInitializer,
6
- isAztecAddressStruct,
7
- isEthAddressStruct,
8
- isFunctionSelectorStruct,
9
- isWrappedFieldStruct,
10
- } from '@aztec/foundation/abi';
11
-
12
- /**
13
- * Returns the corresponding typescript type for a given Noir type.
14
- * @param type - The input Noir type.
15
- * @returns An equivalent typescript type.
16
- */
17
- function abiTypeToTypescript(type: ABIParameter['type']): string {
18
- switch (type.kind) {
19
- case 'field':
20
- return 'FieldLike';
21
- case 'boolean':
22
- return 'boolean';
23
- case 'integer':
24
- return '(bigint | number)';
25
- case 'string':
26
- return 'string';
27
- case 'array':
28
- return `${abiTypeToTypescript(type.type)}[]`;
29
- case 'struct':
30
- if (isEthAddressStruct(type)) {
31
- return 'EthAddressLike';
32
- }
33
- if (isAztecAddressStruct(type)) {
34
- return 'AztecAddressLike';
35
- }
36
- if (isFunctionSelectorStruct(type)) {
37
- return 'FunctionSelectorLike';
38
- }
39
- if (isWrappedFieldStruct(type)) {
40
- return 'WrappedFieldLike';
41
- }
42
- return `{ ${type.fields.map(f => `${f.name}: ${abiTypeToTypescript(f.type)}`).join(', ')} }`;
43
- default:
44
- throw new Error(`Unknown type ${type}`);
45
- }
46
- }
47
-
48
- /**
49
- * Generates the typescript code to represent a Noir parameter.
50
- * @param param - A Noir parameter with name and type.
51
- * @returns The corresponding ts code.
52
- */
53
- function generateParameter(param: ABIParameter) {
54
- return `${param.name}: ${abiTypeToTypescript(param.type)}`;
55
- }
56
-
57
- /**
58
- * Generates the typescript code to represent a Noir function as a type.
59
- * @param param - A Noir function.
60
- * @returns The corresponding ts code.
61
- */
62
- function generateMethod(entry: FunctionArtifact) {
63
- const args = entry.parameters.map(generateParameter).join(', ');
64
- return `
65
- /** ${entry.name}(${entry.parameters.map(p => `${p.name}: ${p.type.kind}`).join(', ')}) */
66
- ${entry.name}: ((${args}) => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;`;
67
- }
68
-
69
- /**
70
- * Generates a deploy method for this contract.
71
- * @param input - Build artifact of the contract.
72
- * @returns A type-safe deploy method in ts.
73
- */
74
- function generateDeploy(input: ContractArtifact) {
75
- const ctor = getDefaultInitializer(input);
76
- const args = (ctor?.parameters ?? []).map(generateParameter).join(', ');
77
- const contractName = `${input.name}Contract`;
78
- const artifactName = `${contractName}Artifact`;
79
-
80
- return `
81
- /**
82
- * Creates a tx to deploy a new instance of this contract.
83
- */
84
- public static deploy(wallet: Wallet, ${args}) {
85
- return new DeployMethod<${contractName}>(Fr.ZERO, wallet, ${artifactName}, ${contractName}.at, Array.from(arguments).slice(1));
86
- }
87
-
88
- /**
89
- * Creates a tx to deploy a new instance of this contract using the specified public keys hash to derive the address.
90
- */
91
- public static deployWithPublicKeysHash(publicKeysHash: Fr, wallet: Wallet, ${args}) {
92
- return new DeployMethod<${contractName}>(publicKeysHash, wallet, ${artifactName}, ${contractName}.at, Array.from(arguments).slice(2));
93
- }
94
-
95
- /**
96
- * Creates a tx to deploy a new instance of this contract using the specified constructor method.
97
- */
98
- public static deployWithOpts<M extends keyof ${contractName}['methods']>(
99
- opts: { publicKeysHash?: Fr; method?: M; wallet: Wallet },
100
- ...args: Parameters<${contractName}['methods'][M]>
101
- ) {
102
- return new DeployMethod<${contractName}>(
103
- opts.publicKeysHash ?? Fr.ZERO,
104
- opts.wallet,
105
- ${artifactName},
106
- ${contractName}.at,
107
- Array.from(arguments).slice(1),
108
- opts.method ?? 'constructor',
109
- );
110
- }
111
- `;
112
- }
113
-
114
- /**
115
- * Generates the constructor by supplying the ABI to the parent class so the user doesn't have to.
116
- * @param name - Name of the contract to derive the ABI name from.
117
- * @returns A constructor method.
118
- * @remarks The constructor is private because we want to force the user to use the create method.
119
- */
120
- function generateConstructor(name: string) {
121
- return `
122
- private constructor(
123
- instance: ContractInstanceWithAddress,
124
- wallet: Wallet,
125
- ) {
126
- super(instance, ${name}ContractArtifact, wallet);
127
- }
128
- `;
129
- }
130
-
131
- /**
132
- * Generates the at method for this contract.
133
- * @param name - Name of the contract to derive the ABI name from.
134
- * @returns An at method.
135
- * @remarks We don't use constructor directly because of the async `wallet.getContractData` call.
136
- */
137
- function generateAt(name: string) {
138
- return `
139
- /**
140
- * Creates a contract instance.
141
- * @param address - The deployed contract's address.
142
- * @param wallet - The wallet to use when interacting with the contract.
143
- * @returns A promise that resolves to a new Contract instance.
144
- */
145
- public static async at(
146
- address: AztecAddress,
147
- wallet: Wallet,
148
- ) {
149
- return Contract.at(address, ${name}Contract.artifact, wallet) as Promise<${name}Contract>;
150
- }`;
151
- }
152
-
153
- /**
154
- * Generates a static getter for the contract's artifact.
155
- * @param name - Name of the contract used to derive name of the artifact import.
156
- */
157
- function generateArtifactGetter(name: string) {
158
- const artifactName = `${name}ContractArtifact`;
159
- return `
160
- /**
161
- * Returns this contract's artifact.
162
- */
163
- public static get artifact(): ContractArtifact {
164
- return ${artifactName};
165
- }
166
- `;
167
- }
168
-
169
- /**
170
- * Generates statements for importing the artifact from json and re-exporting it.
171
- * @param name - Name of the contract.
172
- * @param artifactImportPath - Path to load the ABI from.
173
- * @returns Code.
174
- */
175
- function generateAbiStatement(name: string, artifactImportPath: string) {
176
- const stmts = [
177
- `import ${name}ContractArtifactJson from '${artifactImportPath}' assert { type: 'json' };`,
178
- `export const ${name}ContractArtifact = loadContractArtifact(${name}ContractArtifactJson as NoirCompiledContract);`,
179
- ];
180
- return stmts.join('\n');
181
- }
182
-
183
- /**
184
- * Generates a getter for the contract's storage layout.
185
- * @param input - The contract artifact.
186
- */
187
- function generateStorageLayoutGetter(input: ContractArtifact) {
188
- const entries = Object.entries(input.storageLayout);
189
-
190
- if (entries.length === 0) {
191
- return '';
192
- }
193
-
194
- const storageFieldsUnionType = entries.map(([name]) => `'${name}'`).join(' | ');
195
- const layout = entries
196
- .map(
197
- ([name, { slot }]) =>
198
- `${name}: {
199
- slot: new Fr(${slot.toBigInt()}n),
200
- }`,
201
- )
202
- .join(',\n');
203
-
204
- return `public static get storage(): ContractStorageLayout<${storageFieldsUnionType}> {
205
- return {
206
- ${layout}
207
- } as ContractStorageLayout<${storageFieldsUnionType}>;
208
- }
209
- `;
210
- }
211
-
212
- /**
213
- * Generates a getter for the contract notes
214
- * @param input - The contract artifact.
215
- */
216
- function generateNotesGetter(input: ContractArtifact) {
217
- const entries = Object.entries(input.notes);
218
-
219
- if (entries.length === 0) {
220
- return '';
221
- }
222
-
223
- const notesUnionType = entries.map(([name]) => `'${name}'`).join(' | ');
224
- const noteMetadata = entries
225
- .map(
226
- ([name, { id }]) =>
227
- `${name}: {
228
- id: new NoteSelector(${id.value}),
229
- }`,
230
- )
231
- .join(',\n');
232
-
233
- return `public static get notes(): ContractNotes<${notesUnionType}> {
234
- return {
235
- ${noteMetadata}
236
- } as ContractNotes<${notesUnionType}>;
237
- }
238
- `;
239
- }
240
-
241
- // events is of type AbiType
242
- function generateEvents(events: any[] | undefined) {
243
- if (events === undefined) {
244
- return { events: '', eventDefs: '' };
245
- }
246
-
247
- const eventsMetadata = events.map(event => {
248
- const eventName = event.path.split('::').at(-1);
249
-
250
- const eventDefProps = event.fields.map((field: any) => `${field.name}: Fr`);
251
- const eventDef = `
252
- export type ${eventName} = {
253
- ${eventDefProps.join('\n')}
254
- }
255
- `;
256
-
257
- const fieldNames = event.fields.map((field: any) => `"${field.name}"`);
258
- const eventType = `${eventName}: {decode: (payload: L1EventPayload | undefined) => ${eventName} | undefined, eventSelector: EventSelector, fieldNames: string[] }`;
259
-
260
- const eventImpl = `${eventName}: {
261
- decode: this.decodeEvent(${event.fields.length}, EventSelector.fromSignature('${eventName}(${event.fields
262
- .map(() => 'Field')
263
- .join(',')})'), [${fieldNames}]),
264
- eventSelector: EventSelector.fromSignature('${eventName}(${event.fields.map(() => 'Field').join(',')})'),
265
- fieldNames: [${fieldNames}],
266
- }`;
267
-
268
- return {
269
- eventDef,
270
- eventType,
271
- eventImpl,
272
- };
273
- });
274
-
275
- return {
276
- eventDefs: eventsMetadata.map(({ eventDef }) => eventDef).join('\n'),
277
- events: `
278
- // Partial application is chosen is to avoid the duplication of so much codegen.
279
- private static decodeEvent<T>(fieldsLength: number, eventSelector: EventSelector, fields: string[]): (payload: L1EventPayload | undefined) => T | undefined {
280
- return (payload: L1EventPayload | undefined): T | undefined => {
281
- if (payload === undefined) {
282
- return undefined;
283
- }
284
- if (!eventSelector.equals(payload.eventTypeId)) {
285
- return undefined;
286
- }
287
- if (payload.event.items.length !== fieldsLength) {
288
- throw new Error(
289
- 'Something is weird here, we have matching EventSelectors, but the actual payload has mismatched length',
290
- );
291
- }
292
-
293
- return fields.reduce(
294
- (acc, curr, i) => ({
295
- ...acc,
296
- [curr]: payload.event.items[i],
297
- }),
298
- {} as T,
299
- );
300
- };
301
- }
302
-
303
- public static get events(): { ${eventsMetadata.map(({ eventType }) => eventType).join(', ')} } {
304
- return {
305
- ${eventsMetadata.map(({ eventImpl }) => eventImpl).join(',\n')}
306
- };
307
- }
308
- `,
309
- };
310
- }
311
-
312
- /**
313
- * Generates the typescript code to represent a contract.
314
- * @param input - The compiled Noir artifact.
315
- * @param artifactImportPath - Optional path to import the artifact (if not set, will be required in the constructor).
316
- * @returns The corresponding ts code.
317
- */
318
- export function generateTypescriptContractInterface(input: ContractArtifact, artifactImportPath?: string) {
319
- const methods = input.functions.filter(f => !f.isInternal).map(generateMethod);
320
- const deploy = artifactImportPath && generateDeploy(input);
321
- const ctor = artifactImportPath && generateConstructor(input.name);
322
- const at = artifactImportPath && generateAt(input.name);
323
- const artifactStatement = artifactImportPath && generateAbiStatement(input.name, artifactImportPath);
324
- const artifactGetter = artifactImportPath && generateArtifactGetter(input.name);
325
- const storageLayoutGetter = artifactImportPath && generateStorageLayoutGetter(input);
326
- const notesGetter = artifactImportPath && generateNotesGetter(input);
327
- const { eventDefs, events } = generateEvents(input.outputs.structs?.events);
328
-
329
- return `
330
- /* Autogenerated file, do not edit! */
331
-
332
- /* eslint-disable */
333
- import {
334
- AztecAddress,
335
- AztecAddressLike,
336
- CompleteAddress,
337
- Contract,
338
- ContractArtifact,
339
- ContractBase,
340
- ContractFunctionInteraction,
341
- ContractInstanceWithAddress,
342
- ContractMethod,
343
- ContractStorageLayout,
344
- ContractNotes,
345
- DeployMethod,
346
- EthAddress,
347
- EthAddressLike,
348
- EventSelector,
349
- FieldLike,
350
- Fr,
351
- FunctionSelectorLike,
352
- L1EventPayload,
353
- loadContractArtifact,
354
- NoirCompiledContract,
355
- NoteSelector,
356
- Point,
357
- PublicKey,
358
- Wallet,
359
- WrappedFieldLike,
360
- } from '@aztec/aztec.js';
361
- ${artifactStatement}
362
-
363
- ${eventDefs}
364
-
365
- /**
366
- * Type-safe interface for contract ${input.name};
367
- */
368
- export class ${input.name}Contract extends ContractBase {
369
- ${ctor}
370
-
371
- ${at}
372
-
373
- ${deploy}
374
-
375
- ${artifactGetter}
376
-
377
- ${storageLayoutGetter}
378
-
379
- ${notesGetter}
380
-
381
- /** Type-safe wrappers for the public methods exposed by the contract. */
382
- public override methods!: {
383
- ${methods.join('\n')}
384
- };
385
-
386
- ${events}
387
- }
388
- `;
389
- }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export { generateTypescriptContractInterface } from './contract-interface-gen/typescript.js';
@@ -1,2 +0,0 @@
1
- export const mockVerificationKey =
2
- '0000000200000800000000740000000f00000003515f3109623eb3c25aa5b16a1a79fd558bac7a7ce62c4560a8c537c77ce80dd339128d1d37b6582ee9e6df9567efb64313471dfa18f520f9ce53161b50dbf7731bc5f900000003515f322bc4cce83a486a92c92fd59bd84e0f92595baa639fc2ed86b00ffa0dfded2a092a669a3bdb7a273a015eda494457cc7ed5236f26cee330c290d45a33b9daa94800000003515f332729426c008c085a81bd34d8ef12dd31e80130339ef99d50013a89e4558eee6d0fa4ffe2ee7b7b62eb92608b2251ac31396a718f9b34978888789042b790a30100000003515f342be6b6824a913eb7a57b03cb1ee7bfb4de02f2f65fe8a4e97baa7766ddb353a82a8a25c49dc63778cd9fe96173f12a2bc77f3682f4c4448f98f1df82c75234a100000003515f351f85760d6ab567465aadc2f180af9eae3800e6958fec96aef53fd8a7b195d7c000c6267a0dd5cfc22b3fe804f53e266069c0e36f51885baec1e7e67650c62e170000000c515f41524954484d455449430d9d0f8ece2aa12012fa21e6e5c859e97bd5704e5c122064a66051294bc5e04213f61f54a0ebdf6fee4d4a6ecf693478191de0c2899bcd8e86a636c8d3eff43400000003515f43224a99d02c86336737c8dd5b746c40d2be6aead8393889a76a18d664029096e90f7fe81adcc92a74350eada9622ac453f49ebac24a066a1f83b394df54dfa0130000000c515f46495845445f42415345060e8a013ed289c2f9fd7473b04f6594b138ddb4b4cf6b901622a14088f04b8d2c83ff74fce56e3d5573b99c7b26d85d5046ce0c6559506acb7a675e7713eb3a00000007515f4c4f4749430721a91cb8da4b917e054f72147e1760cfe0ef3d45090ac0f4961d84ec1996961a25e787b26bd8b50b1a99450f77a424a83513c2b33af268cd253b0587ff50c700000003515f4d05dbd8623b8652511e1eb38d38887a69eceb082f807514f09e127237c5213b401b9325b48c6c225968002318095f89d0ef9cf629b2b7f0172e03bc39aacf6ed800000007515f52414e474504b57a3805e41df328f5ca9aefa40fad5917391543b7b65c6476e60b8f72e9ad07c92f3b3e11c8feae96dedc4b14a6226ef3201244f37cfc1ee5b96781f48d2b000000075349474d415f3125001d1954a18571eaa007144c5a567bb0d2be4def08a8be918b8c05e3b27d312c59ed41e09e144eab5de77ca89a2fd783be702a47c951d3112e3de02ce6e47c000000075349474d415f3223994e6a23618e60fa01c449a7ab88378709197e186d48d604bfb6931ffb15ad11c5ec7a0700570f80088fd5198ab5d5c227f2ad2a455a6edeec024156bb7beb000000075349474d415f3300cda5845f23468a13275d18bddae27c6bb189cf9aa95b6a03a0cb6688c7e8d829639b45cf8607c525cc400b55ebf90205f2f378626dc3406cc59b2d1b474fba000000075349474d415f342d299e7928496ea2d37f10b43afd6a80c90a33b483090d18069ffa275eedb2fc2f82121e8de43dc036d99b478b6227ceef34248939987a19011f065d8b5cef5c0000000010000000000000000100000002000000030000000400000005000000060000000700000008000000090000000a0000000b0000000c0000000d0000000e0000000f';
package/src/utils.ts DELETED
@@ -1,33 +0,0 @@
1
- import { type ContractArtifact } from '@aztec/foundation/abi';
2
-
3
- /**
4
- * Checks if the given input looks like a valid ContractArtifact. The check is not exhaustive,
5
- * and it's just meant to differentiate between nargo raw build artifacts and the ones
6
- * produced by this compiler.
7
- * @param input - Input object.
8
- * @returns True if it looks like a ContractArtifact.
9
- */
10
- export function isContractArtifact(input: any): input is ContractArtifact {
11
- if (typeof input !== 'object') {
12
- return false;
13
- }
14
- const maybeContractArtifact = input as ContractArtifact;
15
- if (typeof maybeContractArtifact.name !== 'string') {
16
- return false;
17
- }
18
- if (!Array.isArray(maybeContractArtifact.functions)) {
19
- return false;
20
- }
21
- for (const fn of maybeContractArtifact.functions) {
22
- if (typeof fn.name !== 'string') {
23
- return false;
24
- }
25
- if (typeof fn.functionType !== 'string') {
26
- return false;
27
- }
28
- if (typeof fn.isInternal !== 'boolean') {
29
- return false;
30
- }
31
- }
32
- return true;
33
- }