@aztec/pxe 0.0.1-commit.b8a057fa → 0.0.1-commit.be03c316

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 (167) hide show
  1. package/dest/bin/check_oracle_version.js +3 -8
  2. package/dest/bin/index.d.ts +2 -2
  3. package/dest/bin/index.d.ts.map +1 -1
  4. package/dest/bin/index.js +1 -1
  5. package/dest/bin/oracle_version_helpers.d.ts +8 -25
  6. package/dest/bin/oracle_version_helpers.d.ts.map +1 -1
  7. package/dest/bin/oracle_version_helpers.js +11 -219
  8. package/dest/contract/helpers.d.ts +1 -1
  9. package/dest/contract/helpers.d.ts.map +1 -1
  10. package/dest/contract/helpers.js +3 -3
  11. package/dest/contract/skip_sync_contracts.d.ts +11 -0
  12. package/dest/contract/skip_sync_contracts.d.ts.map +1 -0
  13. package/dest/contract/skip_sync_contracts.js +18 -0
  14. package/dest/contract_function_simulator/aztec_node_read_cache.d.ts +39 -0
  15. package/dest/contract_function_simulator/aztec_node_read_cache.d.ts.map +1 -0
  16. package/dest/contract_function_simulator/aztec_node_read_cache.js +60 -0
  17. package/dest/contract_function_simulator/index.d.ts +3 -3
  18. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  19. package/dest/contract_function_simulator/index.js +1 -2
  20. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts +1 -1
  21. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.js +7 -0
  23. package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts +7 -9
  24. package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts.map +1 -1
  25. package/dest/contract_function_simulator/noir-structs/resolved_tx.js +3 -44
  26. package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts +5 -4
  27. package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/noir-structs/tx_effect_data.js +2 -2
  29. package/dest/contract_function_simulator/oracle/acir_callback.js +1 -1
  30. package/dest/contract_function_simulator/oracle/legacy_oracle_registry.d.ts +3 -3
  31. package/dest/contract_function_simulator/oracle/legacy_oracle_registry.d.ts.map +1 -1
  32. package/dest/contract_function_simulator/oracle/legacy_oracle_registry.js +34 -1
  33. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts +7 -4
  34. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts.map +1 -1
  35. package/dest/contract_function_simulator/oracle/oracle_registry.js +40 -13
  36. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts +87 -35
  37. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts.map +1 -1
  38. package/dest/contract_function_simulator/oracle/oracle_type_mappings.js +286 -286
  39. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +1 -1
  40. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  41. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +7 -10
  42. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +14 -8
  43. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  44. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +61 -34
  45. package/dest/entrypoints/client/bundle/index.d.ts +2 -1
  46. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  47. package/dest/entrypoints/client/bundle/index.js +1 -0
  48. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  49. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  50. package/dest/entrypoints/client/bundle/utils.js +10 -4
  51. package/dest/entrypoints/client/lazy/index.d.ts +2 -1
  52. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  53. package/dest/entrypoints/client/lazy/index.js +1 -0
  54. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  55. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  56. package/dest/entrypoints/client/lazy/utils.js +10 -4
  57. package/dest/entrypoints/client/store.d.ts +14 -0
  58. package/dest/entrypoints/client/store.d.ts.map +1 -0
  59. package/dest/entrypoints/client/store.js +42 -0
  60. package/dest/entrypoints/server/index.d.ts +2 -1
  61. package/dest/entrypoints/server/index.d.ts.map +1 -1
  62. package/dest/entrypoints/server/index.js +1 -0
  63. package/dest/entrypoints/server/store.d.ts +18 -0
  64. package/dest/entrypoints/server/store.d.ts.map +1 -0
  65. package/dest/entrypoints/server/store.js +28 -0
  66. package/dest/entrypoints/server/utils.d.ts +1 -1
  67. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  68. package/dest/entrypoints/server/utils.js +8 -2
  69. package/dest/hooks/index.d.ts +2 -2
  70. package/dest/hooks/index.d.ts.map +1 -1
  71. package/dest/hooks/index.js +1 -0
  72. package/dest/hooks/resolve_tagging_secret_strategy.d.ts +3 -1
  73. package/dest/hooks/resolve_tagging_secret_strategy.d.ts.map +1 -1
  74. package/dest/hooks/resolve_tagging_secret_strategy.js +3 -3
  75. package/dest/logs/log_service.d.ts +3 -2
  76. package/dest/logs/log_service.d.ts.map +1 -1
  77. package/dest/logs/log_service.js +12 -3
  78. package/dest/messages/tx_resolver_service.d.ts +2 -2
  79. package/dest/messages/tx_resolver_service.d.ts.map +1 -1
  80. package/dest/messages/tx_resolver_service.js +7 -2
  81. package/dest/notes/note_service.d.ts +1 -1
  82. package/dest/notes/note_service.js +1 -1
  83. package/dest/oracle_version.d.ts +2 -2
  84. package/dest/oracle_version.js +3 -3
  85. package/dest/pxe.d.ts +1 -1
  86. package/dest/pxe.d.ts.map +1 -1
  87. package/dest/pxe.js +8 -5
  88. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts +1 -1
  89. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts.map +1 -1
  90. package/dest/storage/backwards_compatibility_tests/schema_tests.js +26 -2
  91. package/dest/storage/fact_store/index.d.ts +2 -2
  92. package/dest/storage/fact_store/index.d.ts.map +1 -1
  93. package/dest/storage/fact_store/index.js +1 -1
  94. package/dest/storage/fact_store/origin_state.d.ts +3 -1
  95. package/dest/storage/fact_store/origin_state.d.ts.map +1 -1
  96. package/dest/storage/fact_store/origin_state.js +7 -0
  97. package/dest/storage/metadata.d.ts +1 -1
  98. package/dest/storage/metadata.js +1 -1
  99. package/dest/storage/store_identity.d.ts +35 -0
  100. package/dest/storage/store_identity.d.ts.map +1 -0
  101. package/dest/storage/store_identity.js +44 -0
  102. package/dest/storage/tagging_store/sender_tagging_store.d.ts +19 -3
  103. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  104. package/dest/storage/tagging_store/sender_tagging_store.js +48 -11
  105. package/dest/tagging/constants.d.ts +3 -2
  106. package/dest/tagging/constants.d.ts.map +1 -1
  107. package/dest/tagging/constants.js +26 -5
  108. package/dest/tagging/index.d.ts +2 -2
  109. package/dest/tagging/index.d.ts.map +1 -1
  110. package/dest/tagging/index.js +1 -1
  111. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts +9 -4
  112. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts.map +1 -1
  113. package/dest/tagging/recipient_sync/sync_tagged_private_logs.js +60 -25
  114. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +1 -1
  115. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +1 -1
  116. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  117. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +6 -2
  118. package/dest/tagging/testing/tag_query_test_utils.d.ts +6 -0
  119. package/dest/tagging/testing/tag_query_test_utils.d.ts.map +1 -0
  120. package/dest/tagging/testing/tag_query_test_utils.js +10 -0
  121. package/package.json +17 -17
  122. package/src/bin/check_oracle_version.ts +3 -10
  123. package/src/bin/index.ts +1 -5
  124. package/src/bin/oracle_version_helpers.ts +11 -268
  125. package/src/contract/helpers.ts +3 -3
  126. package/src/contract/skip_sync_contracts.ts +23 -0
  127. package/src/contract_function_simulator/aztec_node_read_cache.ts +89 -0
  128. package/src/contract_function_simulator/index.ts +23 -3
  129. package/src/contract_function_simulator/noir-structs/resolved_tagging_strategy.ts +8 -0
  130. package/src/contract_function_simulator/noir-structs/resolved_tx.ts +11 -45
  131. package/src/contract_function_simulator/noir-structs/tx_effect_data.ts +4 -3
  132. package/src/contract_function_simulator/oracle/acir_callback.ts +1 -1
  133. package/src/contract_function_simulator/oracle/legacy_oracle_registry.ts +30 -3
  134. package/src/contract_function_simulator/oracle/oracle_registry.ts +32 -11
  135. package/src/contract_function_simulator/oracle/oracle_type_mappings.ts +285 -197
  136. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +17 -12
  137. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +92 -39
  138. package/src/entrypoints/client/bundle/index.ts +1 -0
  139. package/src/entrypoints/client/bundle/utils.ts +15 -3
  140. package/src/entrypoints/client/lazy/index.ts +1 -0
  141. package/src/entrypoints/client/lazy/utils.ts +15 -3
  142. package/src/entrypoints/client/store.ts +54 -0
  143. package/src/entrypoints/server/index.ts +1 -0
  144. package/src/entrypoints/server/store.ts +47 -0
  145. package/src/entrypoints/server/utils.ts +21 -7
  146. package/src/hooks/index.ts +1 -0
  147. package/src/hooks/resolve_tagging_secret_strategy.ts +3 -0
  148. package/src/logs/log_service.ts +11 -2
  149. package/src/messages/tx_resolver_service.ts +8 -8
  150. package/src/notes/note_service.ts +1 -1
  151. package/src/oracle_version.ts +3 -3
  152. package/src/pxe.ts +8 -5
  153. package/src/storage/backwards_compatibility_tests/__snapshots__/RecipientTaggingStore.json +11 -3
  154. package/src/storage/backwards_compatibility_tests/__snapshots__/SenderTaggingStore.json +12 -4
  155. package/src/storage/backwards_compatibility_tests/__snapshots__/opened_stores.json +1 -1
  156. package/src/storage/backwards_compatibility_tests/schema_tests.ts +30 -1
  157. package/src/storage/fact_store/index.ts +1 -0
  158. package/src/storage/fact_store/origin_state.ts +9 -0
  159. package/src/storage/metadata.ts +1 -1
  160. package/src/storage/store_identity.ts +72 -0
  161. package/src/storage/tagging_store/sender_tagging_store.ts +62 -15
  162. package/src/tagging/constants.ts +27 -5
  163. package/src/tagging/index.ts +1 -1
  164. package/src/tagging/recipient_sync/sync_tagged_private_logs.ts +103 -46
  165. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +1 -1
  166. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +6 -2
  167. package/src/tagging/testing/tag_query_test_utils.ts +11 -0
@@ -4,12 +4,12 @@ import { padArrayEnd } from '@aztec/foundation/collection';
4
4
  import { Fr } from '@aztec/foundation/curves/bn254';
5
5
  import { EthAddress } from '@aztec/foundation/eth-address';
6
6
  import { FieldReader } from '@aztec/foundation/serialize';
7
- import { fromUintArray } from '@aztec/simulator/client';
8
7
  import { FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
9
8
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
10
9
  import { BlockHash } from '@aztec/stdlib/block';
11
10
  import { Tag, appTaggingSecretKindFromDeliveryMode } from '@aztec/stdlib/logs';
12
11
  import { TxHash } from '@aztec/stdlib/tx';
12
+ import { originBlockStateFromNumber } from '../../storage/fact_store/index.js';
13
13
  import { BoundedVec } from '../noir-structs/bounded_vec.js';
14
14
  import { EphemeralArray } from '../noir-structs/ephemeral_array.js';
15
15
  import { EventValidationRequest } from '../noir-structs/event_validation_request.js';
@@ -28,7 +28,25 @@ import { packAsHintedNote } from './note_packing_utils.js';
28
28
  });
29
29
  }
30
30
  // ─── Scalar Type Mappings ────────────────────────────────────────────────────
31
- export const FIELD = {
31
+ /**
32
+ * A leaf mapping whose {@link TypeMapping.label} is just its bare {@link TypeMapping.kind}. Its wire shape is arbitrary
33
+ * (several fields, or a variable-width run); a single-field scalar uses the shorter {@link SCALAR} instead.
34
+ */ export function LEAF(mapping) {
35
+ return {
36
+ ...mapping,
37
+ label: mapping.kind
38
+ };
39
+ }
40
+ /** A {@link LEAF} occupying a single `'scalar'` wire slot, so callers omit the shape. */ export function SCALAR(mapping) {
41
+ return LEAF({
42
+ ...mapping,
43
+ shape: [
44
+ 'scalar'
45
+ ]
46
+ });
47
+ }
48
+ export const FIELD = SCALAR({
49
+ kind: 'field',
32
50
  serialization: {
33
51
  fn: (v)=>[
34
52
  v
@@ -36,12 +54,10 @@ export const FIELD = {
36
54
  },
37
55
  deserialization: {
38
56
  fn: ([reader])=>reader.readField()
39
- },
40
- shape: [
41
- 'scalar'
42
- ]
43
- };
44
- export const BOOL = {
57
+ }
58
+ });
59
+ export const BOOL = SCALAR({
60
+ kind: 'bool',
45
61
  serialization: {
46
62
  fn: (v)=>[
47
63
  new Fr(v ? 1n : 0n)
@@ -49,70 +65,43 @@ export const BOOL = {
49
65
  },
50
66
  deserialization: {
51
67
  fn: ([reader])=>!reader.readField().isZero()
52
- },
53
- shape: [
54
- 'scalar'
55
- ]
56
- };
57
- export const U32 = {
58
- serialization: {
59
- fn: (v)=>[
60
- new Fr(v)
61
- ]
62
- },
63
- deserialization: {
64
- fn: ([reader])=>{
65
- const value = reader.readField().toBigInt();
66
- if (value > 0xffffffffn) {
67
- throw new Error(`U32 overflow: value ${value} exceeds u32 max (${0xffffffffn})`);
68
- }
69
- return Number(value);
70
- }
71
- },
72
- shape: [
73
- 'scalar'
74
- ]
75
- };
76
- export const BLOCK_NUMBER = {
68
+ }
69
+ });
70
+ export const U32 = SCALAR({
71
+ kind: 'u32',
77
72
  serialization: {
78
73
  fn: (v)=>[
79
74
  new Fr(v)
80
75
  ]
81
76
  },
82
77
  deserialization: {
83
- fn: ([reader])=>BlockNumber(reader.readField().toNumber())
84
- },
85
- shape: [
86
- 'scalar'
87
- ]
88
- };
89
- /** A u8 byte: serializes to a single Fr; deserializes from a single Fr to a number in [0, 255]. */ export const BYTE = {
78
+ fn: ([reader])=>Number(uintFromField(reader.readField(), 32))
79
+ }
80
+ });
81
+ export const BLOCK_NUMBER = ALIAS(U32, {
82
+ wrap: (v)=>BlockNumber(v),
83
+ unwrap: (v)=>v
84
+ });
85
+ export const U8 = SCALAR({
86
+ kind: 'u8',
90
87
  serialization: {
91
88
  fn: (byte)=>[
92
89
  new Fr(byte)
93
90
  ]
94
91
  },
95
92
  deserialization: {
96
- fn: ([reader])=>{
97
- const value = reader.readField().toBigInt();
98
- if (value > 0xffn) {
99
- throw new Error(`BYTE overflow: value ${value} exceeds u8 max (255)`);
100
- }
101
- return Number(value);
102
- }
103
- },
104
- shape: [
105
- 'scalar'
106
- ]
107
- };
93
+ fn: ([reader])=>Number(uintFromField(reader.readField(), 8))
94
+ }
95
+ });
108
96
  // Noir passes `MessageDelivery` onchain variants here.
109
- export const DELIVERY_MODE = {
97
+ export const DELIVERY_MODE = SCALAR({
98
+ kind: 'onchain-delivery-mode',
110
99
  deserialization: {
111
- fn: (readers)=>appTaggingSecretKindFromDeliveryMode(BYTE.deserialization.fn(readers))
112
- },
113
- shape: BYTE.shape
114
- };
115
- export const RESOLVED_TAGGING_STRATEGY = {
100
+ fn: (readers)=>appTaggingSecretKindFromDeliveryMode(U8.deserialization.fn(readers))
101
+ }
102
+ });
103
+ export const RESOLVED_TAGGING_STRATEGY = LEAF({
104
+ kind: 'resolved-tagging-strategy',
116
105
  serialization: {
117
106
  fn: (resolved)=>resolvedTaggingStrategyToFields(resolved)
118
107
  },
@@ -123,21 +112,39 @@ export const RESOLVED_TAGGING_STRATEGY = {
123
112
  'scalar',
124
113
  'scalar'
125
114
  ]
126
- };
127
- export const BIGINT = {
115
+ });
116
+ export const BIGINT = ALIAS(FIELD, {
117
+ wrap: (f)=>f.toBigInt(),
118
+ unwrap: (v)=>new Fr(v)
119
+ });
120
+ export const U64 = SCALAR({
121
+ kind: 'u64',
128
122
  serialization: {
129
123
  fn: (v)=>[
130
124
  new Fr(v)
131
125
  ]
132
126
  },
133
127
  deserialization: {
134
- fn: ([reader])=>reader.readField().toBigInt()
128
+ fn: ([reader])=>uintFromField(reader.readField(), 64)
129
+ }
130
+ });
131
+ export const U128 = SCALAR({
132
+ kind: 'u128',
133
+ serialization: {
134
+ fn: (v)=>[
135
+ new Fr(v)
136
+ ]
135
137
  },
136
- shape: [
137
- 'scalar'
138
- ]
139
- };
140
- /** Reads every field in the slot as a UTF-8 character code. */ export const STR = {
138
+ deserialization: {
139
+ fn: ([reader])=>uintFromField(reader.readField(), 128)
140
+ }
141
+ });
142
+ export const LEAF_INDEX = ALIAS(FIELD, {
143
+ wrap: (f)=>f.toNumber(),
144
+ unwrap: (v)=>new Fr(v)
145
+ });
146
+ /** Reads every field in the slot as a UTF-8 character code. */ export const STR = LEAF({
147
+ kind: 'str',
141
148
  serialization: {
142
149
  fn: (str)=>[
143
150
  Array.from(Buffer.from(str, 'utf-8')).map((b)=>new Fr(b))
@@ -155,8 +162,9 @@ export const BIGINT = {
155
162
  shape: [
156
163
  'variable'
157
164
  ]
158
- };
159
- export const AZTEC_ADDRESS = {
165
+ });
166
+ export const AZTEC_ADDRESS = SCALAR({
167
+ kind: 'aztec-address',
160
168
  serialization: {
161
169
  fn: (v)=>[
162
170
  v.toField()
@@ -164,25 +172,14 @@ export const AZTEC_ADDRESS = {
164
172
  },
165
173
  deserialization: {
166
174
  fn: ([reader])=>AztecAddress.fromFieldUnsafe(reader.readField())
167
- },
168
- shape: [
169
- 'scalar'
170
- ]
171
- };
172
- export const BLOCK_HASH = {
173
- serialization: {
174
- fn: (v)=>[
175
- new Fr(v.toBuffer())
176
- ]
177
- },
178
- deserialization: {
179
- fn: ([reader])=>new BlockHash(reader.readField())
180
- },
181
- shape: [
182
- 'scalar'
183
- ]
184
- };
185
- export const FUNCTION_SELECTOR = {
175
+ }
176
+ });
177
+ export const BLOCK_HASH = ALIAS(FIELD, {
178
+ wrap: (f)=>new BlockHash(f),
179
+ unwrap: (v)=>new Fr(v.toBuffer())
180
+ });
181
+ export const FUNCTION_SELECTOR = SCALAR({
182
+ kind: 'function-selector',
186
183
  serialization: {
187
184
  fn: (v)=>[
188
185
  v.toField()
@@ -190,50 +187,20 @@ export const FUNCTION_SELECTOR = {
190
187
  },
191
188
  deserialization: {
192
189
  fn: ([reader])=>FunctionSelector.fromField(reader.readField())
193
- },
194
- shape: [
195
- 'scalar'
196
- ]
197
- };
198
- export const NOTE_SELECTOR = {
199
- serialization: {
200
- fn: (v)=>[
201
- v.toField()
202
- ]
203
- },
204
- deserialization: {
205
- fn: ([reader])=>NoteSelector.fromField(reader.readField())
206
- },
207
- shape: [
208
- 'scalar'
209
- ]
210
- };
211
- export const TX_HASH = {
212
- serialization: {
213
- fn: (v)=>[
214
- v.hash
215
- ]
216
- },
217
- deserialization: {
218
- fn: ([reader])=>TxHash.fromField(reader.readField())
219
- },
220
- shape: [
221
- 'scalar'
222
- ]
223
- };
224
- const TAG = {
225
- serialization: {
226
- fn: (v)=>[
227
- v.value
228
- ]
229
- },
230
- deserialization: {
231
- fn: ([reader])=>new Tag(reader.readField())
232
- },
233
- shape: [
234
- 'scalar'
235
- ]
236
- };
190
+ }
191
+ });
192
+ export const NOTE_SELECTOR = ALIAS(FIELD, {
193
+ wrap: (f)=>NoteSelector.fromField(f),
194
+ unwrap: (v)=>v.toField()
195
+ });
196
+ export const TX_HASH = ALIAS(FIELD, {
197
+ wrap: (f)=>TxHash.fromField(f),
198
+ unwrap: (v)=>v.hash
199
+ });
200
+ const TAG = ALIAS(FIELD, {
201
+ wrap: (f)=>new Tag(f),
202
+ unwrap: (v)=>v.value
203
+ });
237
204
  export const POINT = STRUCT([
238
205
  {
239
206
  name: 'x',
@@ -244,7 +211,8 @@ export const POINT = STRUCT([
244
211
  type: FIELD
245
212
  }
246
213
  ]);
247
- const LOG_SOURCE = {
214
+ const LOG_SOURCE = SCALAR({
215
+ kind: 'log-source',
248
216
  serialization: {
249
217
  fn: (v)=>[
250
218
  new Fr(v)
@@ -252,12 +220,10 @@ const LOG_SOURCE = {
252
220
  },
253
221
  deserialization: {
254
222
  fn: ([reader])=>logSourceFromField(reader.readField())
255
- },
256
- shape: [
257
- 'scalar'
258
- ]
259
- };
260
- export const ETH_ADDRESS = {
223
+ }
224
+ });
225
+ export const ETH_ADDRESS = SCALAR({
226
+ kind: 'eth-address',
261
227
  serialization: {
262
228
  fn: (v)=>[
263
229
  v.toField()
@@ -265,21 +231,11 @@ export const ETH_ADDRESS = {
265
231
  },
266
232
  deserialization: {
267
233
  fn: ([reader])=>EthAddress.fromField(reader.readField())
268
- },
269
- shape: [
270
- 'scalar'
271
- ]
272
- };
273
- export const SLOT_NUMBER = {
274
- serialization: {
275
- fn: (v)=>[
276
- new Fr(v)
277
- ]
278
- },
279
- shape: [
280
- 'scalar'
281
- ]
282
- };
234
+ }
235
+ });
236
+ export const SLOT_NUMBER = ALIAS(FIELD, {
237
+ unwrap: (v)=>new Fr(v)
238
+ });
283
239
  const APPEND_ONLY_TREE_SNAPSHOT = STRUCT([
284
240
  {
285
241
  name: 'root',
@@ -287,7 +243,7 @@ const APPEND_ONLY_TREE_SNAPSHOT = STRUCT([
287
243
  },
288
244
  {
289
245
  name: 'nextAvailableLeafIndex',
290
- type: U32
246
+ type: LEAF_INDEX
291
247
  }
292
248
  ]);
293
249
  const PARTIAL_STATE_REFERENCE = STRUCT([
@@ -317,11 +273,11 @@ const STATE_REFERENCE = STRUCT([
317
273
  const GAS_FEES = STRUCT([
318
274
  {
319
275
  name: 'feePerDaGas',
320
- type: BIGINT
276
+ type: U128
321
277
  },
322
278
  {
323
279
  name: 'feePerL2Gas',
324
- type: BIGINT
280
+ type: U128
325
281
  }
326
282
  ]);
327
283
  const GLOBAL_VARIABLES = STRUCT([
@@ -343,7 +299,7 @@ const GLOBAL_VARIABLES = STRUCT([
343
299
  },
344
300
  {
345
301
  name: 'timestamp',
346
- type: BIGINT
302
+ type: U64
347
303
  },
348
304
  {
349
305
  name: 'coinbase',
@@ -577,16 +533,6 @@ export const CONTRACT_CLASS_LOG = STRUCT([
577
533
  type: U32
578
534
  }
579
535
  ]);
580
- const REVERT_CODE = {
581
- serialization: {
582
- fn: (rc)=>[
583
- rc.toField()
584
- ]
585
- },
586
- shape: [
587
- 'scalar'
588
- ]
589
- };
590
536
  const PUBLIC_DATA_WRITE = STRUCT([
591
537
  {
592
538
  name: 'leafSlot',
@@ -635,7 +581,7 @@ const CONTRACT_CLASS_LOGS = FIXED_ARRAY(CONTRACT_CLASS_LOG_ENTRY, MAX_CONTRACT_C
635
581
  export const TX_EFFECT = STRUCT([
636
582
  {
637
583
  name: 'revertCode',
638
- type: REVERT_CODE
584
+ type: U8
639
585
  },
640
586
  {
641
587
  name: 'txHash',
@@ -674,7 +620,8 @@ export const TX_EFFECT = STRUCT([
674
620
  type: CONTRACT_CLASS_LOGS
675
621
  }
676
622
  ]);
677
- export const NOTE = {
623
+ export const NOTE = LEAF({
624
+ kind: 'note',
678
625
  serialization: {
679
626
  fn: (noteData)=>packAsHintedNote({
680
627
  contractAddress: noteData.contractAddress,
@@ -691,23 +638,25 @@ export const NOTE = {
691
638
  shape: [
692
639
  'variable'
693
640
  ]
694
- };
695
- export const NOTE_VALIDATION_REQUEST = {
641
+ });
642
+ export const NOTE_VALIDATION_REQUEST = LEAF({
643
+ kind: 'note-validation-request',
696
644
  deserialization: {
697
645
  fn: ([reader])=>NoteValidationRequest.fromFields(reader)
698
646
  },
699
647
  shape: [
700
648
  'variable'
701
649
  ]
702
- };
703
- export const EVENT_VALIDATION_REQUEST = {
650
+ });
651
+ export const EVENT_VALIDATION_REQUEST = LEAF({
652
+ kind: 'event-validation-request',
704
653
  deserialization: {
705
654
  fn: ([reader])=>EventValidationRequest.fromFields(reader)
706
655
  },
707
656
  shape: [
708
657
  'variable'
709
658
  ]
710
- };
659
+ });
711
660
  export const LOG_RETRIEVAL_REQUEST = STRUCT([
712
661
  {
713
662
  name: 'contractAddress',
@@ -753,27 +702,35 @@ export const LOG_RETRIEVAL_RESPONSE = STRUCT([
753
702
  },
754
703
  {
755
704
  name: 'blockTimestamp',
756
- type: BIGINT
705
+ type: U64
757
706
  },
758
707
  {
759
708
  name: 'blockHash',
760
709
  type: BLOCK_HASH
761
710
  }
762
711
  ]);
763
- // `ResolvedTx.toFields()` packs the whole struct into a single slot: txHash, the uniqueNoteHashesInTx BoundedVec
764
- // (MAX_NOTE_HASHES_PER_TX storage fields + length), firstNullifierInTx, blockNumber and blockHash.
765
- export const RESOLVED_TX = {
766
- serialization: {
767
- fn: (resolved)=>[
768
- resolved.toFields()
769
- ]
712
+ export const RESOLVED_TX = STRUCT([
713
+ {
714
+ name: 'txHash',
715
+ type: TX_HASH
770
716
  },
771
- shape: [
772
- {
773
- len: MAX_NOTE_HASHES_PER_TX + 5
774
- }
775
- ]
776
- };
717
+ {
718
+ name: 'uniqueNoteHashesInTx',
719
+ type: FIXED_BOUNDED_VEC(FIELD, MAX_NOTE_HASHES_PER_TX)
720
+ },
721
+ {
722
+ name: 'firstNullifierInTx',
723
+ type: FIELD
724
+ },
725
+ {
726
+ name: 'blockNumber',
727
+ type: U32
728
+ },
729
+ {
730
+ name: 'blockHash',
731
+ type: FIELD
732
+ }
733
+ ]);
777
734
  export const PENDING_TAGGED_LOG = STRUCT([
778
735
  {
779
736
  name: 'log',
@@ -784,93 +741,109 @@ export const PENDING_TAGGED_LOG = STRUCT([
784
741
  type: RESOLVED_TX
785
742
  }
786
743
  ]);
787
- export const ORIGIN_BLOCK = {
744
+ export const ORIGIN_BLOCK = STRUCT([
745
+ {
746
+ name: 'blockNumber',
747
+ type: U32
748
+ },
749
+ {
750
+ name: 'blockHash',
751
+ type: FIELD
752
+ }
753
+ ]);
754
+ const ORIGIN_BLOCK_STATE = SCALAR({
755
+ kind: 'origin-block-state',
788
756
  serialization: {
789
- fn: (ob)=>[
790
- new Fr(ob.blockNumber),
791
- ob.blockHash
757
+ fn: (v)=>[
758
+ new Fr(v)
792
759
  ]
793
760
  },
794
761
  deserialization: {
795
- fn: ([blockNumberReader, blockHashReader])=>({
796
- blockNumber: blockNumberReader.readField().toNumber(),
797
- blockHash: blockHashReader.readField()
798
- })
762
+ fn: ([reader])=>originBlockStateFromNumber(reader.readField().toNumber())
763
+ }
764
+ });
765
+ /** Read-side origin of a retractable fact, carrying the chain state of its origin block. */ export const RETRACTABLE_FACT_ORIGIN = STRUCT([
766
+ {
767
+ name: 'blockNumber',
768
+ type: U32
799
769
  },
800
- shape: [
801
- 'scalar',
802
- 'scalar'
803
- ]
804
- };
805
- /** Read-side origin of a retractable fact, carrying the chain state of its origin block. */ export const RETRACTABLE_FACT_ORIGIN = {
806
- serialization: {
807
- fn: (o)=>[
808
- new Fr(o.blockNumber),
809
- o.blockHash,
810
- new Fr(o.blockState)
811
- ]
770
+ {
771
+ name: 'blockHash',
772
+ type: FIELD
812
773
  },
813
- shape: [
814
- 'scalar',
815
- 'scalar',
816
- 'scalar'
817
- ]
818
- };
819
- // `facts` and `payload` each materialize to a single service-slot id, so a Fact occupies: factTypeId, the payload
820
- // array slot, and `OPTION(RETRACTABLE_FACT_ORIGIN)` (its discriminant plus RETRACTABLE_FACT_ORIGIN's three slots).
821
- export const FACT = {
822
- serialization: {
823
- fn: (f)=>[
824
- f.factTypeId,
825
- f.payload.materializeSlot((v)=>FIELD.serialization.fn(v).flat()),
826
- ...OPTION(RETRACTABLE_FACT_ORIGIN).serialization.fn(f.originBlock)
827
- ]
774
+ {
775
+ name: 'blockState',
776
+ type: ORIGIN_BLOCK_STATE
777
+ }
778
+ ]);
779
+ export const FACT = STRUCT([
780
+ {
781
+ name: 'factTypeId',
782
+ type: FIELD
828
783
  },
829
- shape: [
830
- 'scalar',
831
- 'scalar',
832
- 'scalar',
833
- 'scalar',
834
- 'scalar',
835
- 'scalar'
836
- ]
837
- };
838
- export const FACT_COLLECTION = {
839
- serialization: {
840
- fn: (c)=>[
841
- c.contractAddress.toField(),
842
- c.scope.toField(),
843
- c.factCollectionTypeId,
844
- c.factCollectionId,
845
- c.facts.materializeSlot((v)=>FACT.serialization.fn(v).flat())
846
- ]
784
+ {
785
+ name: 'payload',
786
+ type: EPHEMERAL_ARRAY(FIELD)
847
787
  },
848
- shape: [
849
- 'scalar',
850
- 'scalar',
851
- 'scalar',
852
- 'scalar',
853
- 'scalar'
854
- ]
855
- };
856
- export const PROVIDED_SECRET = {
857
- deserialization: {
858
- fn: ([reader])=>({
859
- secret: reader.readField(),
860
- mode: appTaggingSecretKindFromDeliveryMode(BYTE.deserialization.fn([
861
- reader
862
- ]))
863
- })
788
+ {
789
+ name: 'originBlock',
790
+ type: OPTION(RETRACTABLE_FACT_ORIGIN)
791
+ }
792
+ ]);
793
+ export const FACT_COLLECTION = STRUCT([
794
+ {
795
+ name: 'contractAddress',
796
+ type: AZTEC_ADDRESS
864
797
  },
865
- shape: [
866
- {
867
- len: 2
868
- }
869
- ]
870
- };
798
+ {
799
+ name: 'scope',
800
+ type: AZTEC_ADDRESS
801
+ },
802
+ {
803
+ name: 'factCollectionTypeId',
804
+ type: FIELD
805
+ },
806
+ {
807
+ name: 'factCollectionId',
808
+ type: FIELD
809
+ },
810
+ {
811
+ name: 'facts',
812
+ type: EPHEMERAL_ARRAY(FACT)
813
+ }
814
+ ]);
815
+ export const PROVIDED_SECRET = STRUCT([
816
+ {
817
+ name: 'secret',
818
+ type: FIELD
819
+ },
820
+ {
821
+ name: 'mode',
822
+ type: DELIVERY_MODE
823
+ }
824
+ ]);
871
825
  // ─── Combinator Type Mappings ────────────────────────────────────────────────
872
- function SIBLING_PATH(height) {
826
+ /**
827
+ * A TS-side alias of `base`: the same Noir type on the wire (it inherits `base`'s `kind`, `label`, and `shape`) but a
828
+ * richer TS value. `wrap` maps a base value to the alias, `unwrap` back; a serialize-only alias passes only `unwrap`.
829
+ */ export function ALIAS(base, conversions) {
830
+ const { wrap, unwrap } = conversions;
873
831
  return {
832
+ kind: base.kind,
833
+ label: base.label,
834
+ serialization: base.serialization && unwrap ? {
835
+ fn: (value)=>base.serialization.fn(unwrap(value))
836
+ } : undefined,
837
+ deserialization: base.deserialization && wrap ? {
838
+ fn: (readers)=>wrap(base.deserialization.fn(readers))
839
+ } : undefined,
840
+ shape: base.shape
841
+ };
842
+ }
843
+ function SIBLING_PATH(height) {
844
+ return LEAF({
845
+ // On the wire (and in Noir) a sibling path is a plain `[Field; height]`, so it shares the fixed-array kind.
846
+ kind: `array(field,${height})`,
874
847
  serialization: {
875
848
  fn: (sp)=>[
876
849
  sp.toFields()
@@ -881,7 +854,7 @@ function SIBLING_PATH(height) {
881
854
  len: height
882
855
  }
883
856
  ]
884
- };
857
+ });
885
858
  }
886
859
  export function MEMBERSHIP_WITNESS(height) {
887
860
  return STRUCT([
@@ -898,6 +871,7 @@ export function MEMBERSHIP_WITNESS(height) {
898
871
  export function ARRAY(inner) {
899
872
  return {
900
873
  kind: 'array',
874
+ label: `array(${inner.label})`,
901
875
  inner,
902
876
  serialization: inner.serialization ? {
903
877
  fn: (values)=>[
@@ -924,6 +898,7 @@ export function ARRAY(inner) {
924
898
  const elementWidth = fieldWidth(element.shape);
925
899
  return {
926
900
  kind: 'fixed-array',
901
+ label: `array(${element.label},${length})`,
927
902
  inner: element,
928
903
  length,
929
904
  serialization: element.serialization ? {
@@ -948,7 +923,7 @@ export function ARRAY(inner) {
948
923
  *
949
924
  * Both directions are derived from `element`: bidirectional iff `element` has both serialization and deserialization.
950
925
  *
951
- * @example Serializing `BoundedVec.from({ data: [0x41, 0x42], maxLength: 4 })` with `BOUNDED_VEC(BYTE)`:
926
+ * @example Serializing `BoundedVec.from({ data: [0x41, 0x42], maxLength: 4 })` with `BOUNDED_VEC(U8)`:
952
927
  * ```
953
928
  * slot 0: [Fr(0x41), Fr(0x42), Fr(0), Fr(0)] // data padded to maxLength
954
929
  * slot 1: Fr(2) // actual length
@@ -956,6 +931,7 @@ export function ARRAY(inner) {
956
931
  */ export function BOUNDED_VEC(inner) {
957
932
  return {
958
933
  kind: 'bounded-vec',
934
+ label: `bounded-vec(${inner.label})`,
959
935
  inner,
960
936
  serialization: inner.serialization ? {
961
937
  fn: (bv)=>{
@@ -1003,6 +979,7 @@ export function ARRAY(inner) {
1003
979
  const width = fieldWidth(element.shape);
1004
980
  return {
1005
981
  kind: 'fixed-bounded-vec',
982
+ label: `bounded-vec(${element.label},${maxLength})`,
1006
983
  inner: element,
1007
984
  maxLength,
1008
985
  serialization: element.serialization ? {
@@ -1046,6 +1023,7 @@ export function ARRAY(inner) {
1046
1023
  */ export function OPTION(inner) {
1047
1024
  return {
1048
1025
  kind: 'option',
1026
+ label: `option(${inner.label})`,
1049
1027
  inner,
1050
1028
  serialization: inner.serialization ? {
1051
1029
  fn: (opt)=>opt.isSome() ? [
@@ -1074,31 +1052,13 @@ export function ARRAY(inner) {
1074
1052
  ]
1075
1053
  };
1076
1054
  }
1077
- /**
1078
- * A fixed packed uint buffer (Noir `[u8; length]` at `bitSize` 8): one slot of `length` packed uint values ↔ `Buffer`.
1079
- * `length` is the field count, which equals the byte count at `bitSize` 8.
1080
- */ export function BUFFER(bitSize, length) {
1081
- return {
1082
- serialization: {
1083
- fn: (buf)=>[
1084
- Array.from(buf).map((b)=>new Fr(b))
1085
- ]
1086
- },
1087
- deserialization: {
1088
- fn: ([reader])=>fromUintArray(reader.readFieldArray(length).map((f)=>f.toString()), bitSize)
1089
- },
1090
- shape: [
1091
- {
1092
- len: length
1093
- }
1094
- ]
1095
- };
1096
- }
1097
1055
  export function EPHEMERAL_ARRAY(element) {
1098
1056
  // EphemeralArray.readAll hands each row's flat fields in as a single reader; reconstruct the element's per-slot
1099
1057
  // readers from its shape, deserialize, and assert the row was fully consumed so a row with trailing fields is
1100
1058
  // rejected.
1101
1059
  const rowElement = element.deserialization ? {
1060
+ kind: element.kind,
1061
+ label: element.label,
1102
1062
  deserialization: {
1103
1063
  fn: ([rowReader])=>deserializeElement(element, rowReader.readFieldArray(rowReader.remainingFields()))
1104
1064
  },
@@ -1109,6 +1069,9 @@ export function EPHEMERAL_ARRAY(element) {
1109
1069
  ]
1110
1070
  } : undefined;
1111
1071
  return {
1072
+ kind: 'ephemeral-array',
1073
+ label: `ephemeral-array(${element.label})`,
1074
+ inner: element,
1112
1075
  serialization: element.serialization ? {
1113
1076
  fn: (ea)=>[
1114
1077
  ea.materializeSlot((v)=>serializeElement(element, v))
@@ -1130,6 +1093,7 @@ export function EPHEMERAL_ARRAY(element) {
1130
1093
  */ export function STRUCT(fields) {
1131
1094
  return {
1132
1095
  kind: 'struct',
1096
+ label: `{${structFieldLabels(fields)}}`,
1133
1097
  fields,
1134
1098
  serialization: fields.every((f)=>f.type.serialization) ? {
1135
1099
  fn: (value)=>{
@@ -1152,6 +1116,42 @@ export function EPHEMERAL_ARRAY(element) {
1152
1116
  shape: fields.flatMap((f)=>f.type.shape)
1153
1117
  };
1154
1118
  }
1119
+ export function isArrayMapping(type) {
1120
+ return type.kind === 'array';
1121
+ }
1122
+ export function isBoundedVecMapping(type) {
1123
+ return type.kind === 'bounded-vec';
1124
+ }
1125
+ export function isOptionMapping(type) {
1126
+ return type.kind === 'option';
1127
+ }
1128
+ export function isStructMapping(type) {
1129
+ return type.kind === 'struct';
1130
+ }
1131
+ export function isFixedArrayMapping(type) {
1132
+ return type.kind === 'fixed-array';
1133
+ }
1134
+ export function isFixedBoundedVecMapping(type) {
1135
+ return type.kind === 'fixed-bounded-vec';
1136
+ }
1137
+ export function isEphemeralArrayMapping(type) {
1138
+ return type.kind === 'ephemeral-array';
1139
+ }
1140
+ /**
1141
+ * The comma-joined labels of a struct's fields, with nested struct labels spliced into the parent: nesting affects
1142
+ * neither the wire (struct slots concatenate) nor the interface, so the label treats nested and flat declarations as
1143
+ * the same type.
1144
+ */ function structFieldLabels(fields) {
1145
+ return fields.map((f)=>isStructMapping(f.type) ? structFieldLabels(f.type.fields) : f.type.label).join(',');
1146
+ }
1147
+ /** The field's value as a bigint, asserted to fit a `bits`-wide uint. */ function uintFromField(field, bits) {
1148
+ const max = 2n ** BigInt(bits) - 1n;
1149
+ const value = field.toBigInt();
1150
+ if (value > max) {
1151
+ throw new Error(`u${bits} overflow: value ${value} exceeds max (${max})`);
1152
+ }
1153
+ return value;
1154
+ }
1155
1155
  /** Number of InputSlots a deserializable type spans, derived from its {@link TypeMapping.shape}. */ export function slotsOf(mapping) {
1156
1156
  return mapping.shape.length;
1157
1157
  }