4
4
type AbiType ,
5
5
type BasicValue ,
6
6
type ContractArtifact ,
7
+ ContractArtifactSchema ,
7
8
type ContractNote ,
8
9
type FieldLayout ,
9
10
type FunctionArtifact ,
@@ -133,7 +134,10 @@ type NoirCompiledContractFunction = NoirCompiledContract['functions'][number];
133
134
* @param contract - Parent contract.
134
135
* @returns Function artifact.
135
136
*/
136
- function generateFunctionArtifact ( fn : NoirCompiledContractFunction , contract : NoirCompiledContract ) : FunctionArtifact {
137
+ function generateFunctionArtifact (
138
+ fn : NoirCompiledContractFunction ,
139
+ contract : NoirCompiledContract ,
140
+ ) : Omit < FunctionArtifact , 'bytecode' > & { bytecode : string } {
137
141
if ( fn . custom_attributes === undefined ) {
138
142
throw new Error (
139
143
`No custom attributes found for contract function ${ fn . name } . Try rebuilding the contract with the latest nargo version.` ,
@@ -178,7 +182,7 @@ function generateFunctionArtifact(fn: NoirCompiledContractFunction, contract: No
178
182
isInitializer : fn . custom_attributes . includes ( AZTEC_INITIALIZER_ATTRIBUTE ) ,
179
183
parameters,
180
184
returnTypes,
181
- bytecode : Buffer . from ( fn . bytecode , 'base64' ) ,
185
+ bytecode : fn . bytecode ,
182
186
debugSymbols : fn . debug_symbols ,
183
187
errorTypes : fn . abi . error_types ,
184
188
...( fn . assert_messages ? { assertMessages : fn . assert_messages } : undefined ) ,
@@ -238,11 +242,11 @@ function getStorageLayout(input: NoirCompiledContract) {
238
242
return { } ;
239
243
}
240
244
241
- return storageFields . reduce ( ( acc : Record < string , FieldLayout > , field ) => {
245
+ return storageFields . reduce ( ( acc : Record < string , Omit < FieldLayout , 'slot' > & { slot : string } > , field ) => {
242
246
const name = field . name ;
243
247
const slot = field . value . fields [ 0 ] . value as IntegerValue ;
244
248
acc [ name ] = {
245
- slot : Fr . fromString ( slot . value ) ,
249
+ slot : slot . value ,
246
250
} ;
247
251
return acc ;
248
252
} , { } ) ;
@@ -262,7 +266,7 @@ function getNoteTypes(input: NoirCompiledContract) {
262
266
return { } ;
263
267
}
264
268
265
- return notes . reduce ( ( acc : Record < string , ContractNote > , note ) => {
269
+ return notes . reduce ( ( acc : Record < string , Omit < ContractNote , 'id' > & { id : string } > , note ) => {
266
270
const noteFields = note . fields ;
267
271
268
272
// We find note type id by looking for respective kinds as each of them is unique
@@ -274,7 +278,7 @@ function getNoteTypes(input: NoirCompiledContract) {
274
278
throw new Error ( `Could not find note type id, name or fields for note ${ note } ` ) ;
275
279
}
276
280
277
- const noteTypeId = NoteSelector . fromField ( Fr . fromString ( rawNoteTypeId . value ) ) ;
281
+ const noteTypeId = rawNoteTypeId . value as string ;
278
282
const name = rawName . value as string ;
279
283
280
284
// Note type id is encoded as a hex string
@@ -301,15 +305,15 @@ function getNoteTypes(input: NoirCompiledContract) {
301
305
*/
302
306
function generateContractArtifact ( contract : NoirCompiledContract , aztecNrVersion ?: string ) : ContractArtifact {
303
307
try {
304
- return {
308
+ return ContractArtifactSchema . parse ( {
305
309
name : contract . name ,
306
310
functions : contract . functions . map ( f => generateFunctionArtifact ( f , contract ) ) ,
307
311
outputs : contract . outputs ,
308
312
storageLayout : getStorageLayout ( contract ) ,
309
313
notes : getNoteTypes ( contract ) ,
310
314
fileMap : contract . file_map ,
311
315
...( aztecNrVersion ? { aztecNrVersion } : { } ) ,
312
- } ;
316
+ } ) ;
313
317
} catch ( err ) {
314
318
throw new Error ( `Could not generate contract artifact for ${ contract . name } : ${ err } ` ) ;
315
319
}
0 commit comments