@aztec/foundation 0.62.0 → 0.63.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.
Files changed (140) hide show
  1. package/dest/abi/abi.d.ts +708 -228
  2. package/dest/abi/abi.d.ts.map +1 -1
  3. package/dest/abi/abi.js +92 -8
  4. package/dest/abi/encoder.d.ts.map +1 -1
  5. package/dest/abi/encoder.js +4 -1
  6. package/dest/abi/event_selector.d.ts +4 -0
  7. package/dest/abi/event_selector.d.ts.map +1 -1
  8. package/dest/abi/event_selector.js +7 -1
  9. package/dest/aztec-address/index.d.ts +19 -3
  10. package/dest/aztec-address/index.d.ts.map +1 -1
  11. package/dest/aztec-address/index.js +43 -14
  12. package/dest/buffer/buffer32.d.ts +1 -0
  13. package/dest/buffer/buffer32.d.ts.map +1 -1
  14. package/dest/buffer/buffer32.js +4 -1
  15. package/dest/config/env_var.d.ts +1 -1
  16. package/dest/config/env_var.d.ts.map +1 -1
  17. package/dest/crypto/index.d.ts +1 -0
  18. package/dest/crypto/index.d.ts.map +1 -1
  19. package/dest/crypto/index.js +2 -1
  20. package/dest/crypto/keys/index.d.ts +5 -0
  21. package/dest/crypto/keys/index.d.ts.map +1 -0
  22. package/dest/crypto/keys/index.js +8 -0
  23. package/dest/eth-address/index.d.ts +2 -6
  24. package/dest/eth-address/index.d.ts.map +1 -1
  25. package/dest/eth-address/index.js +3 -7
  26. package/dest/eth-signature/eth_signature.d.ts +2 -0
  27. package/dest/eth-signature/eth_signature.d.ts.map +1 -1
  28. package/dest/eth-signature/eth_signature.js +7 -1
  29. package/dest/fields/fields.d.ts +1 -3
  30. package/dest/fields/fields.d.ts.map +1 -1
  31. package/dest/fields/fields.js +2 -1
  32. package/dest/json-rpc/client/fetch.d.ts +21 -0
  33. package/dest/json-rpc/client/fetch.d.ts.map +1 -0
  34. package/dest/json-rpc/client/fetch.js +66 -0
  35. package/dest/json-rpc/client/index.d.ts +2 -1
  36. package/dest/json-rpc/client/index.d.ts.map +1 -1
  37. package/dest/json-rpc/client/index.js +3 -2
  38. package/dest/json-rpc/client/safe_json_rpc_client.d.ts +13 -0
  39. package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -0
  40. package/dest/json-rpc/client/safe_json_rpc_client.js +45 -0
  41. package/dest/json-rpc/convert.d.ts +11 -19
  42. package/dest/json-rpc/convert.d.ts.map +1 -1
  43. package/dest/json-rpc/convert.js +30 -123
  44. package/dest/json-rpc/fixtures/test_state.d.ts +45 -3
  45. package/dest/json-rpc/fixtures/test_state.d.ts.map +1 -1
  46. package/dest/json-rpc/fixtures/test_state.js +58 -2
  47. package/dest/json-rpc/index.d.ts +1 -2
  48. package/dest/json-rpc/index.d.ts.map +1 -1
  49. package/dest/json-rpc/index.js +2 -3
  50. package/dest/json-rpc/js_utils.d.ts.map +1 -1
  51. package/dest/json-rpc/js_utils.js +2 -1
  52. package/dest/json-rpc/server/index.d.ts +1 -2
  53. package/dest/json-rpc/server/index.d.ts.map +1 -1
  54. package/dest/json-rpc/server/index.js +2 -3
  55. package/dest/json-rpc/server/safe_json_rpc_server.d.ts +112 -0
  56. package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -0
  57. package/dest/json-rpc/server/safe_json_rpc_server.js +275 -0
  58. package/dest/json-rpc/test/index.d.ts +2 -0
  59. package/dest/json-rpc/test/index.d.ts.map +1 -0
  60. package/dest/json-rpc/test/index.js +2 -0
  61. package/dest/json-rpc/test/integration.d.ts +13 -0
  62. package/dest/json-rpc/test/integration.d.ts.map +1 -0
  63. package/dest/json-rpc/test/integration.js +12 -0
  64. package/dest/log/logger.d.ts.map +1 -1
  65. package/dest/log/logger.js +2 -2
  66. package/dest/schemas/api.d.ts +21 -0
  67. package/dest/schemas/api.d.ts.map +1 -0
  68. package/dest/schemas/api.js +8 -0
  69. package/dest/schemas/index.d.ts +6 -0
  70. package/dest/schemas/index.d.ts.map +1 -0
  71. package/dest/schemas/index.js +6 -0
  72. package/dest/schemas/parse.d.ts +9 -0
  73. package/dest/schemas/parse.d.ts.map +1 -0
  74. package/dest/schemas/parse.js +26 -0
  75. package/dest/schemas/schemas.d.ts +79 -0
  76. package/dest/schemas/schemas.d.ts.map +1 -0
  77. package/dest/schemas/schemas.js +87 -0
  78. package/dest/schemas/types.d.ts +3 -0
  79. package/dest/schemas/types.d.ts.map +1 -0
  80. package/dest/schemas/types.js +2 -0
  81. package/dest/schemas/utils.d.ts +40 -0
  82. package/dest/schemas/utils.d.ts.map +1 -0
  83. package/dest/schemas/utils.js +56 -0
  84. package/dest/string/index.d.ts +7 -0
  85. package/dest/string/index.d.ts.map +1 -0
  86. package/dest/string/index.js +13 -0
  87. package/dest/types/index.d.ts +2 -0
  88. package/dest/types/index.d.ts.map +1 -1
  89. package/dest/validation/index.d.ts +6 -0
  90. package/dest/validation/index.d.ts.map +1 -1
  91. package/dest/validation/index.js +11 -1
  92. package/package.json +7 -4
  93. package/src/abi/abi.ts +203 -233
  94. package/src/abi/encoder.ts +2 -0
  95. package/src/abi/event_selector.ts +7 -0
  96. package/src/aztec-address/index.ts +64 -18
  97. package/src/buffer/buffer32.ts +5 -0
  98. package/src/config/env_var.ts +18 -8
  99. package/src/crypto/index.ts +1 -0
  100. package/src/crypto/keys/index.ts +9 -0
  101. package/src/eth-address/index.ts +2 -6
  102. package/src/eth-signature/eth_signature.ts +8 -0
  103. package/src/fields/fields.ts +2 -3
  104. package/src/json-rpc/client/fetch.ts +81 -0
  105. package/src/json-rpc/client/index.ts +2 -1
  106. package/src/json-rpc/client/safe_json_rpc_client.ts +61 -0
  107. package/src/json-rpc/convert.ts +29 -142
  108. package/src/json-rpc/fixtures/test_state.ts +87 -3
  109. package/src/json-rpc/index.ts +1 -8
  110. package/src/json-rpc/js_utils.ts +1 -0
  111. package/src/json-rpc/server/index.ts +1 -2
  112. package/src/json-rpc/server/safe_json_rpc_server.ts +336 -0
  113. package/src/json-rpc/test/index.ts +1 -0
  114. package/src/json-rpc/test/integration.ts +24 -0
  115. package/src/log/logger.ts +2 -1
  116. package/src/schemas/api.ts +47 -0
  117. package/src/schemas/index.ts +5 -0
  118. package/src/schemas/parse.ts +29 -0
  119. package/src/schemas/schemas.ts +111 -0
  120. package/src/schemas/types.ts +3 -0
  121. package/src/schemas/utils.ts +85 -0
  122. package/src/string/index.ts +15 -0
  123. package/src/types/index.ts +3 -0
  124. package/src/validation/index.ts +11 -0
  125. package/dest/json-rpc/class_converter.d.ts +0 -144
  126. package/dest/json-rpc/class_converter.d.ts.map +0 -1
  127. package/dest/json-rpc/class_converter.js +0 -102
  128. package/dest/json-rpc/client/json_rpc_client.d.ts +0 -35
  129. package/dest/json-rpc/client/json_rpc_client.d.ts.map +0 -1
  130. package/dest/json-rpc/client/json_rpc_client.js +0 -117
  131. package/dest/json-rpc/server/json_proxy.d.ts +0 -30
  132. package/dest/json-rpc/server/json_proxy.d.ts.map +0 -1
  133. package/dest/json-rpc/server/json_proxy.js +0 -46
  134. package/dest/json-rpc/server/json_rpc_server.d.ts +0 -102
  135. package/dest/json-rpc/server/json_rpc_server.d.ts.map +0 -1
  136. package/dest/json-rpc/server/json_rpc_server.js +0 -265
  137. package/src/json-rpc/class_converter.ts +0 -213
  138. package/src/json-rpc/client/json_rpc_client.ts +0 -148
  139. package/src/json-rpc/server/json_proxy.ts +0 -60
  140. package/src/json-rpc/server/json_rpc_server.ts +0 -332
package/src/abi/abi.ts CHANGED
@@ -1,23 +1,21 @@
1
+ /* eslint-disable camelcase */
1
2
  import { inflate } from 'pako';
3
+ import { z } from 'zod';
2
4
 
3
5
  import { type Fr } from '../fields/fields.js';
6
+ import { schemas } from '../schemas/schemas.js';
7
+ import { type ZodFor } from '../schemas/types.js';
4
8
  import { type FunctionSelector } from './function_selector.js';
5
9
  import { type NoteSelector } from './note_selector.js';
6
10
 
7
- /**
8
- * A basic value.
9
- */
11
+ /** A basic value. */
10
12
  export interface BasicValue<T extends string, V> {
11
- /**
12
- * The kind of the value.
13
- */
13
+ /** The kind of the value. */
14
14
  kind: T;
15
15
  value: V;
16
16
  }
17
17
 
18
- /**
19
- * An exported value.
20
- */
18
+ /** An exported value. */
21
19
  export type AbiValue =
22
20
  | BasicValue<'boolean', boolean>
23
21
  | BasicValue<'string', string>
@@ -26,6 +24,18 @@ export type AbiValue =
26
24
  | IntegerValue
27
25
  | StructValue;
28
26
 
27
+ export const AbiValueSchema: z.ZodType<AbiValue> = z.discriminatedUnion('kind', [
28
+ z.object({ kind: z.literal('boolean'), value: z.boolean() }),
29
+ z.object({ kind: z.literal('string'), value: z.string() }),
30
+ z.object({ kind: z.literal('array'), value: z.array(z.lazy(() => AbiValueSchema)) }),
31
+ z.object({ kind: z.literal('tuple'), fields: z.array(z.lazy(() => AbiValueSchema)) }),
32
+ z.object({ kind: z.literal('integer'), value: z.string(), sign: z.boolean() }),
33
+ z.object({
34
+ kind: z.literal('struct'),
35
+ fields: z.array(z.object({ name: z.string(), value: z.lazy(() => AbiValueSchema) })),
36
+ }),
37
+ ]);
38
+
29
39
  export type TypedStructFieldValue<T> = { name: string; value: T };
30
40
 
31
41
  export interface StructValue {
@@ -42,48 +52,23 @@ export interface IntegerValue extends BasicValue<'integer', string> {
42
52
  sign: boolean;
43
53
  }
44
54
 
45
- /**
46
- * A named type.
47
- */
48
- export interface ABIVariable {
49
- /**
50
- * The name of the variable.
51
- */
52
- name: string;
53
- /**
54
- * The type of the variable.
55
- */
56
- type: AbiType;
57
- }
55
+ /** Indicates whether a parameter is public or secret/private. */
56
+ export const ABIParameterVisibility = ['public', 'private', 'databus'] as const;
58
57
 
59
- /**
60
- * Indicates whether a parameter is public or secret/private.
61
- */
62
- export type ABIParameterVisibility = 'public' | 'private' | 'databus';
58
+ /** Indicates whether a parameter is public or secret/private. */
59
+ export type ABIParameterVisibility = (typeof ABIParameterVisibility)[number];
63
60
 
64
- /**
65
- * A function parameter.
66
- */
67
- export interface ABIParameter extends ABIVariable {
68
- /**
69
- * Indicates whether a parameter is public or secret/private.
70
- */
71
- visibility: ABIParameterVisibility;
72
- }
73
-
74
- /**
75
- * A basic type.
76
- */
61
+ /** A basic type. */
77
62
  export interface BasicType<T extends string> {
78
- /**
79
- * The kind of the type.
80
- */
63
+ /** The kind of the type. */
81
64
  kind: T;
82
65
  }
83
66
 
84
- /**
85
- * A variable type.
86
- */
67
+ /** Sign for numeric types. */
68
+ const Sign = ['unsigned', 'signed'] as const;
69
+ type Sign = (typeof Sign)[number];
70
+
71
+ /** A variable type. */
87
72
  export type AbiType =
88
73
  | BasicType<'field'>
89
74
  | BasicType<'boolean'>
@@ -93,156 +78,178 @@ export type AbiType =
93
78
  | StructType
94
79
  | TupleType;
95
80
 
96
- type Sign = 'unsigned' | 'signed';
97
-
98
- /**
99
- * An integer type.
100
- */
81
+ export const AbiTypeSchema: z.ZodType<AbiType> = z.discriminatedUnion('kind', [
82
+ z.object({ kind: z.literal('field') }),
83
+ z.object({ kind: z.literal('boolean') }),
84
+ z.object({ kind: z.literal('integer'), sign: z.enum(Sign), width: z.number() }),
85
+ z.object({ kind: z.literal('array'), length: z.number(), type: z.lazy(() => AbiTypeSchema) }),
86
+ z.object({ kind: z.literal('string'), length: z.number() }),
87
+ z.object({ kind: z.literal('struct'), fields: z.array(z.lazy(() => ABIVariableSchema)), path: z.string() }),
88
+ z.object({ kind: z.literal('tuple'), fields: z.array(z.lazy(() => AbiTypeSchema)) }),
89
+ ]);
90
+
91
+ /** A named type. */
92
+ export const ABIVariableSchema = z.object({
93
+ /** The name of the variable. */
94
+ name: z.string(),
95
+ /** The type of the variable. */
96
+ type: AbiTypeSchema,
97
+ });
98
+
99
+ /** A named type. */
100
+ export type ABIVariable = z.infer<typeof ABIVariableSchema>;
101
+
102
+ /** A function parameter. */
103
+ export const ABIParameterSchema = ABIVariableSchema.and(
104
+ z.object({
105
+ /** Visibility of the parameter in the function. */
106
+ visibility: z.enum(ABIParameterVisibility),
107
+ }),
108
+ );
109
+
110
+ /** A function parameter. */
111
+ export type ABIParameter = z.infer<typeof ABIParameterSchema>;
112
+
113
+ /** An integer type. */
101
114
  export interface IntegerType extends BasicType<'integer'> {
102
- /**
103
- * The sign of the integer.
104
- */
115
+ /** The sign of the integer. */
105
116
  sign: Sign;
106
- /**
107
- * The width of the integer in bits.
108
- */
117
+ /** The width of the integer in bits. */
109
118
  width: number;
110
119
  }
111
120
 
112
- /**
113
- * An array type.
114
- */
121
+ /** An array type. */
115
122
  export interface ArrayType extends BasicType<'array'> {
116
- /**
117
- * The length of the array.
118
- */
123
+ /** The length of the array. */
119
124
  length: number;
120
- /**
121
- * The type of the array elements.
122
- */
125
+ /** The type of the array elements. */
123
126
  type: AbiType;
124
127
  }
125
128
 
126
- /**
127
- * A tuple type.
128
- */
129
+ /** A tuple type. */
129
130
  export interface TupleType extends BasicType<'tuple'> {
130
- /**
131
- * The types of the tuple elements.
132
- */
131
+ /** The types of the tuple elements. */
133
132
  fields: AbiType[];
134
133
  }
135
134
 
136
- /**
137
- * A string type.
138
- */
135
+ /** A string type. */
139
136
  export interface StringType extends BasicType<'string'> {
140
- /**
141
- * The length of the string.
142
- */
137
+ /** The length of the string. */
143
138
  length: number;
144
139
  }
145
140
 
146
- /**
147
- * A struct type.
148
- */
141
+ /** A struct type. */
149
142
  export interface StructType extends BasicType<'struct'> {
150
- /**
151
- * The fields of the struct.
152
- */
143
+ /** The fields of the struct. */
153
144
  fields: ABIVariable[];
154
- /**
155
- * Fully qualified name of the struct.
156
- */
145
+ /** Fully qualified name of the struct. */
157
146
  path: string;
158
147
  }
159
148
 
160
- /**
161
- * Aztec.nr function types.
162
- */
149
+ /** An error could be a custom error of any regular type or a string error. */
150
+ export type AbiErrorType =
151
+ | { error_kind: 'string'; string: string }
152
+ | { error_kind: 'fmtstring'; length: number; item_types: AbiType[] }
153
+ | ({ error_kind: 'custom' } & AbiType);
154
+
155
+ const AbiErrorTypeSchema = z.union([
156
+ z.object({ error_kind: z.literal('string'), string: z.string() }),
157
+ z.object({ error_kind: z.literal('fmtstring'), length: z.number(), item_types: z.array(AbiTypeSchema) }),
158
+ z.object({ error_kind: z.literal('custom') }).and(AbiTypeSchema),
159
+ ]) satisfies ZodFor<AbiErrorType>;
160
+
161
+ /** Aztec.nr function types. */
163
162
  export enum FunctionType {
164
163
  PRIVATE = 'private',
165
164
  PUBLIC = 'public',
166
165
  UNCONSTRAINED = 'unconstrained',
167
166
  }
168
167
 
169
- /**
170
- * The abi entry of a function.
171
- */
168
+ /** The abi entry of a function. */
172
169
  export interface FunctionAbi {
173
- /**
174
- * The name of the function.
175
- */
170
+ /** The name of the function. */
176
171
  name: string;
177
- /**
178
- * Whether the function is secret.
179
- */
172
+ /** Whether the function is secret. */
180
173
  functionType: FunctionType;
181
- /**
182
- * Whether the function is internal.
183
- */
174
+ /** Whether the function is internal. */
184
175
  isInternal: boolean;
185
- /**
186
- * Whether the function can alter state or not
187
- */
176
+ /** Whether the function can alter state or not */
188
177
  isStatic: boolean;
189
- /**
190
- * Function parameters.
191
- */
178
+ /** Function parameters. */
192
179
  parameters: ABIParameter[];
193
- /**
194
- * The types of the return values.
195
- */
180
+ /** The types of the return values. */
196
181
  returnTypes: AbiType[];
197
- /**
198
- * Whether the function is flagged as an initializer.
199
- */
182
+ /** The types of the errors that the function can throw. */
183
+ errorTypes: Partial<Record<string, AbiErrorType>>;
184
+ /** Whether the function is flagged as an initializer. */
200
185
  isInitializer: boolean;
201
186
  }
202
187
 
203
- /**
204
- * The artifact entry of a function.
205
- */
188
+ export const FunctionAbiSchema = z.object({
189
+ name: z.string(),
190
+ functionType: z.nativeEnum(FunctionType),
191
+ isInternal: z.boolean(),
192
+ isStatic: z.boolean(),
193
+ isInitializer: z.boolean(),
194
+ parameters: z.array(z.object({ name: z.string(), type: AbiTypeSchema, visibility: z.enum(ABIParameterVisibility) })),
195
+ returnTypes: z.array(AbiTypeSchema),
196
+ errorTypes: z.record(AbiErrorTypeSchema),
197
+ }) satisfies z.ZodType<FunctionAbi>;
198
+
199
+ /** Debug metadata for a function. */
200
+ export interface FunctionDebugMetadata {
201
+ /** Maps opcodes to source code pointers */
202
+ debugSymbols: DebugInfo;
203
+ /** Maps the file IDs to the file contents to resolve pointers */
204
+ files: DebugFileMap;
205
+ }
206
+
207
+ export const FunctionDebugMetadataSchema = z.object({
208
+ debugSymbols: z.object({
209
+ locations: z.record(
210
+ z.array(z.object({ span: z.object({ start: z.number(), end: z.number() }), file: z.number() })),
211
+ ),
212
+ brillig_locations: z.record(
213
+ z.record(z.array(z.object({ span: z.object({ start: z.number(), end: z.number() }), file: z.number() }))),
214
+ ),
215
+ }),
216
+ files: z.record(z.object({ source: z.string(), path: z.string() })),
217
+ }) satisfies z.ZodType<FunctionDebugMetadata>;
218
+
219
+ /** The artifact entry of a function. */
206
220
  export interface FunctionArtifact extends FunctionAbi {
207
221
  /** The ACIR bytecode of the function. */
208
222
  bytecode: Buffer;
209
- /** The verification key of the function. */
223
+ /** The verification key of the function, base64 encoded, if it's a private fn. */
210
224
  verificationKey?: string;
211
225
  /** Maps opcodes to source code pointers */
212
226
  debugSymbols: string;
213
- /**
214
- * Public functions store their static assertion messages externally to the bytecode.
215
- */
216
- assertMessages?: Record<number, string>;
217
227
  /** Debug metadata for the function. */
218
228
  debug?: FunctionDebugMetadata;
219
229
  }
220
230
 
221
- /**
222
- * A file ID. It's assigned during compilation.
223
- */
231
+ export const FunctionArtifactSchema = FunctionAbiSchema.and(
232
+ z.object({
233
+ bytecode: schemas.BufferB64,
234
+ verificationKey: z.string().optional(),
235
+ debugSymbols: z.string(),
236
+ debug: FunctionDebugMetadataSchema.optional(),
237
+ }),
238
+ ) satisfies ZodFor<FunctionArtifact>;
239
+
240
+ /** A file ID. It's assigned during compilation. */
224
241
  export type FileId = number;
225
242
 
226
- /**
227
- * A pointer to a specific section of the source code.
228
- */
243
+ /** A pointer to a specific section of the source code. */
229
244
  export interface SourceCodeLocation {
230
- /**
231
- * The section of the source code.
232
- */
245
+ /** The section of the source code. */
233
246
  span: {
234
- /**
235
- * The byte where the section starts.
236
- */
247
+ /** The byte where the section starts. */
237
248
  start: number;
238
- /**
239
- * The byte where the section ends.
240
- */
249
+ /** The byte where the section ends. */
241
250
  end: number;
242
251
  };
243
- /**
244
- * The source code file pointed to.
245
- */
252
+ /** The source code file pointed to. */
246
253
  file: FileId;
247
254
  }
248
255
 
@@ -256,65 +263,31 @@ export type BrilligFunctionId = number;
256
263
 
257
264
  export type OpcodeToLocationsMap = Record<OpcodeLocation, SourceCodeLocation[]>;
258
265
 
259
- /**
260
- * The debug information for a given function.
261
- */
266
+ /** The debug information for a given function. */
262
267
  export interface DebugInfo {
263
- /**
264
- * A map of the opcode location to the source code location.
265
- */
268
+ /** A map of the opcode location to the source code location. */
266
269
  locations: OpcodeToLocationsMap;
267
- /**
268
- * For each Brillig function, we have a map of the opcode location to the source code location.
269
- */
270
+ /** For each Brillig function, we have a map of the opcode location to the source code location. */
270
271
  brillig_locations: Record<BrilligFunctionId, OpcodeToLocationsMap>;
271
272
  }
272
273
 
273
- /**
274
- * The debug information for a given program (a collection of functions)
275
- */
274
+ /** The debug information for a given program (a collection of functions) */
276
275
  export interface ProgramDebugInfo {
277
- /**
278
- * A list of debug information that matches with each function in a program
279
- */
276
+ /** A list of debug information that matches with each function in a program */
280
277
  debug_infos: Array<DebugInfo>;
281
278
  }
282
279
 
283
- /**
284
- * Maps a file ID to its metadata for debugging purposes.
285
- */
280
+ /** Maps a file ID to its metadata for debugging purposes. */
286
281
  export type DebugFileMap = Record<
287
282
  FileId,
288
283
  {
289
- /**
290
- * The source code of the file.
291
- */
284
+ /** The source code of the file. */
292
285
  source: string;
293
- /**
294
- * The path of the file.
295
- */
286
+ /** The path of the file. */
296
287
  path: string;
297
288
  }
298
289
  >;
299
290
 
300
- /**
301
- * Type representing a note in use in the contract.
302
- */
303
- export type ContractNote = {
304
- /**
305
- * Note identifier
306
- */
307
- id: NoteSelector;
308
- /**
309
- * Type of the note (e.g., 'TransparentNote')
310
- */
311
- typ: string;
312
- /**
313
- * Fields of the note.
314
- */
315
- fields: NoteField[];
316
- };
317
-
318
291
  /** Type representing a field of a note (e.g. `amount` in `TokenNote`). */
319
292
  export type NoteField = {
320
293
  /** Name of the field (e.g. `amount`). */
@@ -325,77 +298,75 @@ export type NoteField = {
325
298
  nullable: boolean;
326
299
  };
327
300
 
328
- /**
329
- * Type representing a field layout in the storage of a contract.
330
- */
301
+ export const NoteFieldSchema = z.object({
302
+ name: z.string(),
303
+ index: z.number(),
304
+ nullable: z.boolean(),
305
+ }) satisfies z.ZodType<NoteField>;
306
+
307
+ /** Type representing a note in use in the contract. */
308
+ export type ContractNote = {
309
+ /** Note identifier */
310
+ id: NoteSelector;
311
+ /** Type of the note (e.g., 'TransparentNote') */
312
+ typ: string;
313
+ /** Fields of the note. */
314
+ fields: NoteField[];
315
+ };
316
+
317
+ export const ContractNoteSchema = z.object({
318
+ id: schemas.NoteSelector,
319
+ typ: z.string(),
320
+ fields: z.array(NoteFieldSchema),
321
+ }) satisfies ZodFor<ContractNote>;
322
+
323
+ /** Type representing a field layout in the storage of a contract. */
331
324
  export type FieldLayout = {
332
- /**
333
- * Slot in which the field is stored.
334
- */
325
+ /** Slot in which the field is stored. */
335
326
  slot: Fr;
336
327
  };
337
328
 
338
- /**
339
- * Defines artifact of a contract.
340
- */
329
+ /** Defines artifact of a contract. */
341
330
  export interface ContractArtifact {
342
- /**
343
- * The name of the contract.
344
- */
331
+ /** The name of the contract. */
345
332
  name: string;
346
333
 
347
- /**
348
- * The version of compiler used to create this artifact
349
- */
334
+ /** The version of compiler used to create this artifact */
350
335
  aztecNrVersion?: string;
351
336
 
352
- /**
353
- * The functions of the contract.
354
- */
337
+ /** The functions of the contract. */
355
338
  functions: FunctionArtifact[];
356
- /**
357
- * The outputs of the contract.
358
- */
339
+
340
+ /** The outputs of the contract. */
359
341
  outputs: {
360
342
  structs: Record<string, AbiType[]>;
361
343
  globals: Record<string, AbiValue[]>;
362
344
  };
363
- /**
364
- * Storage layout
365
- */
345
+
346
+ /** Storage layout */
366
347
  storageLayout: Record<string, FieldLayout>;
367
- /**
368
- * The notes used in the contract.
369
- */
348
+
349
+ /** The notes used in the contract. */
370
350
  notes: Record<string, ContractNote>;
371
351
 
372
- /**
373
- * The map of file ID to the source code and path of the file.
374
- */
352
+ /** The map of file ID to the source code and path of the file. */
375
353
  fileMap: DebugFileMap;
376
354
  }
377
355
 
378
- /**
379
- * Debug metadata for a function.
380
- */
381
- export interface FunctionDebugMetadata {
382
- /**
383
- * Maps opcodes to source code pointers
384
- */
385
- debugSymbols: DebugInfo;
386
- /**
387
- * Maps the file IDs to the file contents to resolve pointers
388
- */
389
- files: DebugFileMap;
390
- /**
391
- * Public functions store their static assertion messages externally to the bytecode.
392
- */
393
- assertMessages?: Record<number, string>;
394
- }
395
-
396
- /**
397
- * Gets a function artifact including debug metadata given its name or selector.
398
- */
356
+ export const ContractArtifactSchema: ZodFor<ContractArtifact> = z.object({
357
+ name: z.string(),
358
+ aztecNrVersion: z.string().optional(),
359
+ functions: z.array(FunctionArtifactSchema),
360
+ outputs: z.object({
361
+ structs: z.record(z.array(AbiTypeSchema)),
362
+ globals: z.record(z.array(AbiValueSchema)),
363
+ }),
364
+ storageLayout: z.record(z.object({ slot: schemas.Fr })),
365
+ notes: z.record(ContractNoteSchema),
366
+ fileMap: z.record(z.coerce.number(), z.object({ source: z.string(), path: z.string() })),
367
+ });
368
+
369
+ /** Gets a function artifact including debug metadata given its name or selector. */
399
370
  export function getFunctionArtifact(
400
371
  artifact: ContractArtifact,
401
372
  functionNameOrSelector: string | FunctionSelector,
@@ -432,7 +403,6 @@ export function getFunctionDebugMetadata(
432
403
  return {
433
404
  debugSymbols: programDebugSymbols.debug_infos[0],
434
405
  files: contractArtifact.fileMap,
435
- assertMessages: functionArtifact.assertMessages,
436
406
  };
437
407
  }
438
408
  return undefined;
@@ -57,6 +57,8 @@ class ArgumentEncoder {
57
57
  this.flattened.push(Fr.fromBuffer(arg));
58
58
  } else if (typeof arg.toField === 'function') {
59
59
  this.flattened.push(arg.toField());
60
+ } else if (typeof arg.value === 'string') {
61
+ this.flattened.push(Fr.fromString(arg.value));
60
62
  } else {
61
63
  throw new Error(`Argument for ${name} cannot be serialized to a field`);
62
64
  }
@@ -81,4 +81,11 @@ export class EventSelector extends Selector {
81
81
  static random() {
82
82
  return EventSelector.fromBuffer(randomBytes(Selector.SIZE));
83
83
  }
84
+
85
+ toJSON() {
86
+ return {
87
+ type: 'EventSelector',
88
+ value: this.toString(),
89
+ };
90
+ }
84
91
  }