@aztec/pxe 3.0.0-nightly.20251222 → 3.0.0-nightly.20251223

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 (108) hide show
  1. package/dest/contract_function_simulator/contract_function_simulator.d.ts +31 -6
  2. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  3. package/dest/contract_function_simulator/contract_function_simulator.js +35 -11
  4. package/dest/contract_function_simulator/oracle/private_execution.d.ts +6 -8
  5. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  6. package/dest/contract_function_simulator/oracle/private_execution.js +10 -9
  7. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +13 -4
  8. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  9. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +18 -13
  10. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +44 -6
  11. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  12. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +135 -30
  13. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +2 -2
  14. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  15. package/dest/contract_function_simulator/proxied_contract_data_source.js +18 -0
  16. package/dest/debug/pxe_debug_utils.d.ts +3 -2
  17. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  18. package/dest/entrypoints/client/bundle/index.d.ts +1 -2
  19. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  20. package/dest/entrypoints/client/bundle/index.js +0 -1
  21. package/dest/entrypoints/client/lazy/index.d.ts +1 -2
  22. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  23. package/dest/entrypoints/client/lazy/index.js +0 -1
  24. package/dest/entrypoints/server/index.d.ts +2 -2
  25. package/dest/entrypoints/server/index.d.ts.map +1 -1
  26. package/dest/entrypoints/server/index.js +1 -1
  27. package/dest/events/event_service.d.ts +15 -0
  28. package/dest/events/event_service.d.ts.map +1 -0
  29. package/dest/events/event_service.js +47 -0
  30. package/dest/events/private_event_filter_validator.d.ts +3 -2
  31. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  32. package/dest/logs/log_service.d.ts +43 -0
  33. package/dest/logs/log_service.d.ts.map +1 -0
  34. package/dest/logs/log_service.js +258 -0
  35. package/dest/notes/index.d.ts +2 -0
  36. package/dest/notes/index.d.ts.map +1 -0
  37. package/dest/notes/index.js +1 -0
  38. package/dest/notes/note_service.d.ts +48 -0
  39. package/dest/notes/note_service.d.ts.map +1 -0
  40. package/dest/notes/note_service.js +152 -0
  41. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +2 -2
  42. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -1
  43. package/dest/public_storage/public_storage_service.d.ts +24 -0
  44. package/dest/public_storage/public_storage_service.d.ts.map +1 -0
  45. package/dest/public_storage/public_storage_service.js +26 -0
  46. package/dest/pxe.d.ts +1 -1
  47. package/dest/pxe.d.ts.map +1 -1
  48. package/dest/pxe.js +3 -5
  49. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +33 -1
  50. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +1 -1
  51. package/dest/storage/capsule_data_provider/capsule_data_provider.js +32 -4
  52. package/dest/storage/contract_data_provider/contract_data_provider.d.ts +2 -1
  53. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +1 -1
  54. package/dest/storage/contract_data_provider/contract_data_provider.js +11 -0
  55. package/dest/storage/tagging_data_provider/sender_tagging_data_provider.js +3 -3
  56. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +14 -0
  57. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -0
  58. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +99 -0
  59. package/dest/tagging/recipient_sync/new_recipient_tagging_data_provider.d.ts +21 -0
  60. package/dest/tagging/recipient_sync/new_recipient_tagging_data_provider.d.ts.map +1 -0
  61. package/dest/tagging/recipient_sync/new_recipient_tagging_data_provider.js +42 -0
  62. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +12 -0
  63. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -0
  64. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +20 -0
  65. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +14 -0
  66. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -0
  67. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +32 -0
  68. package/dest/tagging/sync/sync_sender_tagging_indexes.d.ts +2 -2
  69. package/dest/tagging/sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  70. package/dest/tagging/sync/sync_sender_tagging_indexes.js +3 -3
  71. package/dest/tree_membership/tree_membership_service.d.ts +52 -0
  72. package/dest/tree_membership/tree_membership_service.d.ts.map +1 -0
  73. package/dest/tree_membership/tree_membership_service.js +84 -0
  74. package/package.json +16 -16
  75. package/src/contract_function_simulator/contract_function_simulator.ts +59 -10
  76. package/src/contract_function_simulator/oracle/private_execution.ts +13 -10
  77. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +80 -20
  78. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +199 -38
  79. package/src/contract_function_simulator/proxied_contract_data_source.ts +18 -1
  80. package/src/debug/pxe_debug_utils.ts +2 -1
  81. package/src/entrypoints/client/bundle/index.ts +0 -1
  82. package/src/entrypoints/client/lazy/index.ts +0 -1
  83. package/src/entrypoints/server/index.ts +1 -1
  84. package/src/events/event_service.ts +77 -0
  85. package/src/events/private_event_filter_validator.ts +2 -1
  86. package/src/logs/log_service.ts +386 -0
  87. package/src/notes/index.ts +1 -0
  88. package/src/notes/note_service.ts +200 -0
  89. package/src/private_kernel/private_kernel_oracle_impl.ts +1 -1
  90. package/src/public_storage/public_storage_service.ts +33 -0
  91. package/src/pxe.ts +13 -11
  92. package/src/storage/capsule_data_provider/capsule_data_provider.ts +32 -0
  93. package/src/storage/contract_data_provider/contract_data_provider.ts +15 -0
  94. package/src/storage/tagging_data_provider/sender_tagging_data_provider.ts +3 -3
  95. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +129 -0
  96. package/src/tagging/recipient_sync/new_recipient_tagging_data_provider.ts +53 -0
  97. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +34 -0
  98. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +47 -0
  99. package/src/tagging/sync/sync_sender_tagging_indexes.ts +3 -3
  100. package/src/tree_membership/tree_membership_service.ts +112 -0
  101. package/dest/contract_function_simulator/execution_data_provider.d.ts +0 -248
  102. package/dest/contract_function_simulator/execution_data_provider.d.ts.map +0 -1
  103. package/dest/contract_function_simulator/execution_data_provider.js +0 -14
  104. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +0 -113
  105. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +0 -1
  106. package/dest/contract_function_simulator/pxe_oracle_interface.js +0 -648
  107. package/src/contract_function_simulator/execution_data_provider.ts +0 -322
  108. package/src/contract_function_simulator/pxe_oracle_interface.ts +0 -967
@@ -0,0 +1,43 @@
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
+ import type { KeyStore } from '@aztec/key-store';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import type { AztecNode } from '@aztec/stdlib/interfaces/server';
5
+ import { DirectionalAppTaggingSecret, PrivateLogWithTxData, PublicLogWithTxData } from '@aztec/stdlib/logs';
6
+ import type { LogRetrievalRequest } from '../contract_function_simulator/noir-structs/log_retrieval_request.js';
7
+ import { LogRetrievalResponse } from '../contract_function_simulator/noir-structs/log_retrieval_response.js';
8
+ import { AddressDataProvider } from '../storage/address_data_provider/address_data_provider.js';
9
+ import { AnchorBlockDataProvider } from '../storage/anchor_block_data_provider/anchor_block_data_provider.js';
10
+ import { CapsuleDataProvider } from '../storage/capsule_data_provider/capsule_data_provider.js';
11
+ import { RecipientTaggingDataProvider } from '../storage/tagging_data_provider/recipient_tagging_data_provider.js';
12
+ export declare class LogService {
13
+ #private;
14
+ private readonly aztecNode;
15
+ private readonly anchorBlockDataProvider;
16
+ private readonly keyStore;
17
+ private readonly capsuleDataProvider;
18
+ private readonly recipientTaggingDataProvider;
19
+ private readonly addressDataProvider;
20
+ constructor(aztecNode: AztecNode, anchorBlockDataProvider: AnchorBlockDataProvider, keyStore: KeyStore, capsuleDataProvider: CapsuleDataProvider, recipientTaggingDataProvider: RecipientTaggingDataProvider, addressDataProvider: AddressDataProvider);
21
+ bulkRetrieveLogs(logRetrievalRequests: LogRetrievalRequest[]): Promise<(LogRetrievalResponse | null)[]>;
22
+ getPublicLogByTag(tag: Fr, contractAddress: AztecAddress): Promise<PublicLogWithTxData | null>;
23
+ getPrivateLogByTag(siloedTag: Fr): Promise<PrivateLogWithTxData | null>;
24
+ syncTaggedLogs(contractAddress: AztecAddress, pendingTaggedLogArrayBaseSlot: Fr, scopes?: AztecAddress[]): Promise<void>;
25
+ /**
26
+ * Returns the last used tagging indexes along with the directional app tagging secrets for a given recipient and all
27
+ * the senders in the address book.
28
+ * This method should be exposed as an oracle call to allow aztec.nr to perform the orchestration
29
+ * of the syncTaggedLogs and processTaggedLogs methods. However, it is not possible to do so at the moment,
30
+ * so we're keeping it private for now.
31
+ * @param contractAddress - The contract address to silo the secret for
32
+ * @param recipient - The address receiving the notes
33
+ * @returns A list of directional app tagging secrets along with the last used tagging indexes. If the corresponding
34
+ * secret was never used, the index is undefined.
35
+ * TODO(#17775): The naming here is broken as the function name does not reflect the return type. Make sure this gets
36
+ * fixed when implementing the linked issue.
37
+ */
38
+ protected getLastUsedTaggingIndexesForSenders(contractAddress: AztecAddress, recipient: AztecAddress): Promise<{
39
+ secret: DirectionalAppTaggingSecret;
40
+ index: number | undefined;
41
+ }[]>;
42
+ }
43
+ //# sourceMappingURL=data:application/json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B,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC,CAAC,oBAAoB,GAAG,IAAI,CAAC,EAAE,CAAC,CAkCnH;IAGY,iBAAiB,CAAC,GAAG,EAAE,EAAE,EAAE,eAAe,EAAE,YAAY,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC,CA6B1G;IAGY,kBAAkB,CAAC,SAAS,EAAE,EAAE,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CA6BnF;IAsBY,cAAc,CACzB,eAAe,EAAE,YAAY,EAC7B,6BAA6B,EAAE,EAAE,EACjC,MAAM,CAAC,EAAE,YAAY,EAAE,iBAuIxB;IAED;;;;;;;;;;;;OAYG;IACH,UAAgB,mCAAmC,CACjD,eAAe,EAAE,YAAY,EAC7B,SAAS,EAAE,YAAY,GACtB,OAAO,CAAC;QAAE,MAAM,EAAE,2BAA2B,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,EAAE,CAAC,CA8B/E;CA2CF"}
@@ -0,0 +1,258 @@
1
+ import { siloPrivateLog } from '@aztec/stdlib/hash';
2
+ import { DirectionalAppTaggingSecret, PendingTaggedLog, PrivateLogWithTxData, PublicLogWithTxData } from '@aztec/stdlib/logs';
3
+ import { LogRetrievalResponse } from '../contract_function_simulator/noir-structs/log_retrieval_response.js';
4
+ import { WINDOW_HALF_SIZE } from '../tagging/constants.js';
5
+ import { SiloedTag } from '../tagging/siloed_tag.js';
6
+ import { Tag } from '../tagging/tag.js';
7
+ import { getInitialIndexesMap, getPreTagsForTheWindow } from '../tagging/utils.js';
8
+ export class LogService {
9
+ aztecNode;
10
+ anchorBlockDataProvider;
11
+ keyStore;
12
+ capsuleDataProvider;
13
+ recipientTaggingDataProvider;
14
+ addressDataProvider;
15
+ constructor(aztecNode, anchorBlockDataProvider, keyStore, capsuleDataProvider, recipientTaggingDataProvider, addressDataProvider){
16
+ this.aztecNode = aztecNode;
17
+ this.anchorBlockDataProvider = anchorBlockDataProvider;
18
+ this.keyStore = keyStore;
19
+ this.capsuleDataProvider = capsuleDataProvider;
20
+ this.recipientTaggingDataProvider = recipientTaggingDataProvider;
21
+ this.addressDataProvider = addressDataProvider;
22
+ }
23
+ async bulkRetrieveLogs(logRetrievalRequests) {
24
+ return await Promise.all(logRetrievalRequests.map(async (request)=>{
25
+ // TODO(#14555): remove these internal functions and have node endpoints that do this instead
26
+ const [publicLog, privateLog] = await Promise.all([
27
+ this.getPublicLogByTag(request.unsiloedTag, request.contractAddress),
28
+ this.getPrivateLogByTag(await siloPrivateLog(request.contractAddress, request.unsiloedTag))
29
+ ]);
30
+ if (publicLog !== null) {
31
+ if (privateLog !== null) {
32
+ throw new Error(`Found both a public and private log when searching for tag ${request.unsiloedTag} from contract ${request.contractAddress}`);
33
+ }
34
+ return new LogRetrievalResponse(publicLog.logPayload, publicLog.txHash, publicLog.uniqueNoteHashesInTx, publicLog.firstNullifierInTx);
35
+ } else if (privateLog !== null) {
36
+ return new LogRetrievalResponse(privateLog.logPayload, privateLog.txHash, privateLog.uniqueNoteHashesInTx, privateLog.firstNullifierInTx);
37
+ } else {
38
+ return null;
39
+ }
40
+ }));
41
+ }
42
+ // TODO(#14555): delete this function and implement this behavior in the node instead
43
+ async getPublicLogByTag(tag, contractAddress) {
44
+ const logs = await this.#getPublicLogsByTagsFromContract([
45
+ tag
46
+ ], contractAddress);
47
+ const logsForTag = logs[0];
48
+ if (logsForTag.length == 0) {
49
+ return null;
50
+ } else if (logsForTag.length > 1) {
51
+ // TODO(#11627): handle this case
52
+ throw new Error(`Got ${logsForTag.length} logs for tag ${tag} and contract ${contractAddress.toString()}. getPublicLogByTag currently only supports a single log per tag`);
53
+ }
54
+ const scopedLog = logsForTag[0];
55
+ // getLogsByTag doesn't have all of the information that we need (notably note hashes and the first nullifier), so
56
+ // we need to make a second call to the node for `getTxEffect`.
57
+ // TODO(#9789): bundle this information in the `getLogsByTag` call.
58
+ const txEffect = await this.aztecNode.getTxEffect(scopedLog.txHash);
59
+ if (txEffect == undefined) {
60
+ throw new Error(`Unexpected: failed to retrieve tx effects for tx ${scopedLog.txHash} which is known to exist`);
61
+ }
62
+ return new PublicLogWithTxData(scopedLog.log.getEmittedFieldsWithoutTag(), scopedLog.txHash, txEffect.data.noteHashes, txEffect.data.nullifiers[0]);
63
+ }
64
+ // TODO(#14555): delete this function and implement this behavior in the node instead
65
+ async getPrivateLogByTag(siloedTag) {
66
+ const logs = await this.#getPrivateLogsByTags([
67
+ siloedTag
68
+ ]);
69
+ const logsForTag = logs[0];
70
+ if (logsForTag.length == 0) {
71
+ return null;
72
+ } else if (logsForTag.length > 1) {
73
+ // TODO(#11627): handle this case
74
+ throw new Error(`Got ${logsForTag.length} logs for tag ${siloedTag}. getPrivateLogByTag currently only supports a single log per tag`);
75
+ }
76
+ const scopedLog = logsForTag[0];
77
+ // getLogsByTag doesn't have all of the information that we need (notably note hashes and the first nullifier), so
78
+ // we need to make a second call to the node for `getTxEffect`.
79
+ // TODO(#9789): bundle this information in the `getLogsByTag` call.
80
+ const txEffect = await this.aztecNode.getTxEffect(scopedLog.txHash);
81
+ if (txEffect == undefined) {
82
+ throw new Error(`Unexpected: failed to retrieve tx effects for tx ${scopedLog.txHash} which is known to exist`);
83
+ }
84
+ return new PrivateLogWithTxData(scopedLog.log.getEmittedFieldsWithoutTag(), scopedLog.txHash, txEffect.data.noteHashes, txEffect.data.nullifiers[0]);
85
+ }
86
+ // TODO(#12656): Make this a public function on the AztecNode interface and remove the original getLogsByTags. This
87
+ // was not done yet as we were unsure about the API and we didn't want to introduce a breaking change.
88
+ async #getPublicLogsByTagsFromContract(tags, contractAddress) {
89
+ const allLogs = await this.aztecNode.getLogsByTags(tags);
90
+ const allPublicLogs = allLogs.map((logs)=>logs.filter((log)=>log.isFromPublic));
91
+ return allPublicLogs.map((logs)=>logs.filter((log)=>log.log.contractAddress.equals(contractAddress)));
92
+ }
93
+ // TODO(#12656): Make this a public function on the AztecNode interface and remove the original getLogsByTags. This
94
+ // was not done yet as we were unsure about the API and we didn't want to introduce a breaking change.
95
+ async #getPrivateLogsByTags(tags) {
96
+ const allLogs = await this.aztecNode.getLogsByTags(tags);
97
+ return allLogs.map((logs)=>logs.filter((log)=>!log.isFromPublic));
98
+ }
99
+ // TODO(#17775): Replace this implementation of this function with one implementing an approach similar
100
+ // to syncSenderTaggingIndexes. Not done yet due to re-prioritization to devex and this doesn't directly affect
101
+ // devex.
102
+ async syncTaggedLogs(contractAddress, pendingTaggedLogArrayBaseSlot, scopes) {
103
+ const maxBlockNumber = (await this.anchorBlockDataProvider.getBlockHeader()).getBlockNumber();
104
+ // Ideally this algorithm would be implemented in noir, exposing its building blocks as oracles.
105
+ // However it is impossible at the moment due to the language not supporting nested slices.
106
+ // This nesting is necessary because for a given set of tags we don't
107
+ // know how many logs we will get back. Furthermore, these logs are of undetermined
108
+ // length, since we don't really know the note they correspond to until we decrypt them.
109
+ const recipients = scopes ? scopes : await this.keyStore.getAccounts();
110
+ for (const recipient of recipients){
111
+ // Get all the secrets for the recipient and sender pairs (#9365)
112
+ const indexedSecrets = await this.getLastUsedTaggingIndexesForSenders(contractAddress, recipient);
113
+ // We fetch logs for a window of indexes in a range:
114
+ // <latest_log_index - WINDOW_HALF_SIZE, latest_log_index + WINDOW_HALF_SIZE>.
115
+ //
116
+ // We use this window approach because it could happen that a sender might have messed up and inadvertently
117
+ // incremented their index without us getting any logs (for example, in case of a revert). If we stopped looking
118
+ // for logs the first time we don't receive any logs for a tag, we might never receive anything from that sender again.
119
+ // Also there's a possibility that we have advanced our index, but the sender has reused it, so we might have missed
120
+ // some logs. For these reasons, we have to look both back and ahead of the stored index.
121
+ let secretsAndWindows = indexedSecrets.map((indexedSecret)=>{
122
+ if (indexedSecret.index === undefined) {
123
+ return {
124
+ secret: indexedSecret.secret,
125
+ leftMostIndex: 0,
126
+ rightMostIndex: WINDOW_HALF_SIZE
127
+ };
128
+ } else {
129
+ return {
130
+ secret: indexedSecret.secret,
131
+ leftMostIndex: Math.max(0, indexedSecret.index - WINDOW_HALF_SIZE),
132
+ rightMostIndex: indexedSecret.index + WINDOW_HALF_SIZE
133
+ };
134
+ }
135
+ });
136
+ // As we iterate we store the largest index we have seen for a given secret to later on store it in the db.
137
+ const newLargestIndexMapToStore = {};
138
+ // The initial/unmodified indexes of the secrets stored in a key-value map where key is the directional app
139
+ // tagging secret.
140
+ const initialIndexesMap = getInitialIndexesMap(indexedSecrets);
141
+ while(secretsAndWindows.length > 0){
142
+ const preTagsForTheWholeWindow = getPreTagsForTheWindow(secretsAndWindows);
143
+ const tagsForTheWholeWindow = await Promise.all(preTagsForTheWholeWindow.map(async (preTag)=>{
144
+ return SiloedTag.compute(await Tag.compute(preTag), contractAddress);
145
+ }));
146
+ // We store the new largest indexes we find in the iteration in the following map to later on construct
147
+ // a new set of secrets and windows to fetch logs for.
148
+ const newLargestIndexMapForIteration = {};
149
+ // Fetch the private logs for the tags and iterate over them
150
+ // TODO: The following conversion is unfortunate and we should most likely just type the #getPrivateLogsByTags
151
+ // to accept SiloedTag[] instead of Fr[]. That would result in a large change so I didn't do it yet.
152
+ const tagsForTheWholeWindowAsFr = tagsForTheWholeWindow.map((tag)=>tag.value);
153
+ const logsByTags = await this.#getPrivateLogsByTags(tagsForTheWholeWindowAsFr);
154
+ for(let logIndex = 0; logIndex < logsByTags.length; logIndex++){
155
+ const logsByTag = logsByTags[logIndex];
156
+ if (logsByTag.length > 0) {
157
+ // We filter out the logs that are newer than the anchor block number of the tx currently being constructed
158
+ const filteredLogsByBlockNumber = logsByTag.filter((l)=>l.blockNumber <= maxBlockNumber);
159
+ // We store the logs in capsules (to later be obtained in Noir)
160
+ await this.#storePendingTaggedLogs(contractAddress, pendingTaggedLogArrayBaseSlot, recipient, filteredLogsByBlockNumber);
161
+ // We retrieve the pre-tag corresponding to the log as I need that to evaluate whether
162
+ // a new largest index have been found.
163
+ const preTagCorrespondingToLog = preTagsForTheWholeWindow[logIndex];
164
+ const initialIndex = initialIndexesMap[preTagCorrespondingToLog.secret.toString()];
165
+ if (preTagCorrespondingToLog.index >= initialIndex && (newLargestIndexMapForIteration[preTagCorrespondingToLog.secret.toString()] === undefined || preTagCorrespondingToLog.index >= newLargestIndexMapForIteration[preTagCorrespondingToLog.secret.toString()])) {
166
+ // We have found a new largest index so we store it for later processing (storing it in the db + fetching
167
+ // the difference of the window sets of current and the next iteration)
168
+ newLargestIndexMapForIteration[preTagCorrespondingToLog.secret.toString()] = preTagCorrespondingToLog.index + 1;
169
+ }
170
+ }
171
+ }
172
+ // Now based on the new largest indexes we found, we will construct a new secrets and windows set to fetch logs
173
+ // for. Note that it's very unlikely that a new log from the current window would appear between the iterations
174
+ // so we fetch the logs only for the difference of the window sets.
175
+ const newSecretsAndWindows = [];
176
+ for (const [directionalAppTaggingSecret, newIndex] of Object.entries(newLargestIndexMapForIteration)){
177
+ const maybeIndexedSecret = indexedSecrets.find((indexedSecret)=>indexedSecret.secret.toString() === directionalAppTaggingSecret);
178
+ if (maybeIndexedSecret) {
179
+ newSecretsAndWindows.push({
180
+ secret: maybeIndexedSecret.secret,
181
+ // We set the left most index to the new index to avoid fetching the same logs again
182
+ leftMostIndex: newIndex,
183
+ rightMostIndex: newIndex + WINDOW_HALF_SIZE
184
+ });
185
+ // We store the new largest index in the map to later store it in the db.
186
+ newLargestIndexMapToStore[directionalAppTaggingSecret] = newIndex;
187
+ } else {
188
+ throw new Error(`Secret not found for directionalAppTaggingSecret ${directionalAppTaggingSecret}. This is a bug as it should never happen!`);
189
+ }
190
+ }
191
+ // Now we set the new secrets and windows and proceed to the next iteration.
192
+ secretsAndWindows = newSecretsAndWindows;
193
+ }
194
+ // At this point we have processed all the logs for the recipient so we store the last used indexes in the db.
195
+ // newLargestIndexMapToStore contains "next" indexes to look for (one past the last found), so subtract 1 to get
196
+ // last used.
197
+ await this.recipientTaggingDataProvider.setLastUsedIndexes(Object.entries(newLargestIndexMapToStore).map(([directionalAppTaggingSecret, index])=>({
198
+ secret: DirectionalAppTaggingSecret.fromString(directionalAppTaggingSecret),
199
+ index: index - 1
200
+ })));
201
+ }
202
+ }
203
+ /**
204
+ * Returns the last used tagging indexes along with the directional app tagging secrets for a given recipient and all
205
+ * the senders in the address book.
206
+ * This method should be exposed as an oracle call to allow aztec.nr to perform the orchestration
207
+ * of the syncTaggedLogs and processTaggedLogs methods. However, it is not possible to do so at the moment,
208
+ * so we're keeping it private for now.
209
+ * @param contractAddress - The contract address to silo the secret for
210
+ * @param recipient - The address receiving the notes
211
+ * @returns A list of directional app tagging secrets along with the last used tagging indexes. If the corresponding
212
+ * secret was never used, the index is undefined.
213
+ * TODO(#17775): The naming here is broken as the function name does not reflect the return type. Make sure this gets
214
+ * fixed when implementing the linked issue.
215
+ */ async getLastUsedTaggingIndexesForSenders(contractAddress, recipient) {
216
+ const recipientCompleteAddress = await this.#getCompleteAddress(recipient);
217
+ const recipientIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(recipient);
218
+ // We implicitly add all PXE accounts as senders, this helps us decrypt tags on notes that we send to ourselves
219
+ // (recipient = us, sender = us)
220
+ const senders = [
221
+ ...await this.recipientTaggingDataProvider.getSenderAddresses(),
222
+ ...await this.keyStore.getAccounts()
223
+ ].filter((address, index, self)=>index === self.findIndex((otherAddress)=>otherAddress.equals(address)));
224
+ const secrets = await Promise.all(senders.map((contact)=>{
225
+ return DirectionalAppTaggingSecret.compute(recipientCompleteAddress, recipientIvsk, contact, contractAddress, recipient);
226
+ }));
227
+ const indexes = await this.recipientTaggingDataProvider.getLastUsedIndexes(secrets);
228
+ if (indexes.length !== secrets.length) {
229
+ throw new Error('Indexes and directional app tagging secrets have different lengths');
230
+ }
231
+ return secrets.map((secret, i)=>({
232
+ secret,
233
+ index: indexes[i]
234
+ }));
235
+ }
236
+ async #storePendingTaggedLogs(contractAddress, capsuleArrayBaseSlot, recipient, privateLogs) {
237
+ // Build all pending tagged logs upfront with their tx effects
238
+ const pendingTaggedLogs = await Promise.all(privateLogs.map(async (scopedLog)=>{
239
+ // TODO(#9789): get these effects along with the log
240
+ const txEffect = await this.aztecNode.getTxEffect(scopedLog.txHash);
241
+ if (!txEffect) {
242
+ throw new Error(`Could not find tx effect for tx hash ${scopedLog.txHash}`);
243
+ }
244
+ const pendingTaggedLog = new PendingTaggedLog(scopedLog.log.fields, scopedLog.txHash, txEffect.data.noteHashes, txEffect.data.nullifiers[0], recipient);
245
+ return pendingTaggedLog.toFields();
246
+ }));
247
+ // TODO: This looks like it could belong more at the oracle interface level
248
+ return this.capsuleDataProvider.appendToCapsuleArray(contractAddress, capsuleArrayBaseSlot, pendingTaggedLogs);
249
+ }
250
+ async #getCompleteAddress(account) {
251
+ const completeAddress = await this.addressDataProvider.getCompleteAddress(account);
252
+ if (!completeAddress) {
253
+ throw new Error(`No public key registered for address ${account}.
254
+ Register it by calling pxe.addAccount(...).\nSee docs for context: https://docs.aztec.network/developers/resources/debugging/aztecnr-errors#simulation-error-no-public-key-registered-for-address-0x0-register-it-by-calling-pxeregisterrecipient-or-pxeregisteraccount`);
255
+ }
256
+ return completeAddress;
257
+ }
258
+ }
@@ -0,0 +1,2 @@
1
+ export { NoteService } from './note_service.js';
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ub3Rlcy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsV0FBVyxFQUFFLE1BQU0sbUJBQW1CLENBQUMifQ==
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/notes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1 @@
1
+ export { NoteService } from './note_service.js';
@@ -0,0 +1,48 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import { type AztecNode } from '@aztec/stdlib/interfaces/client';
4
+ import { Note, NoteStatus } from '@aztec/stdlib/note';
5
+ import type { TxHash } from '@aztec/stdlib/tx';
6
+ import type { AnchorBlockDataProvider } from '../storage/anchor_block_data_provider/anchor_block_data_provider.js';
7
+ import type { NoteDataProvider } from '../storage/note_data_provider/note_data_provider.js';
8
+ export declare class NoteService {
9
+ private readonly noteDataProvider;
10
+ private readonly aztecNode;
11
+ private readonly anchorBlockDataProvider;
12
+ constructor(noteDataProvider: NoteDataProvider, aztecNode: AztecNode, anchorBlockDataProvider: AnchorBlockDataProvider);
13
+ /**
14
+ * Retrieves a set of notes stored in the database for a given contract address and storage slot.
15
+ * The query result is paginated using 'limit' and 'offset' values.
16
+ * Returns an object containing an array of note data.
17
+ *
18
+ * @param owner - The owner of the notes. If undefined, returns notes for all known owners.
19
+ * @param status - The status of notes to fetch.
20
+ * @param scopes - The accounts whose notes we can access in this call. Currently optional and will default to all.
21
+ */
22
+ getNotes(contractAddress: AztecAddress, owner: AztecAddress | undefined, storageSlot: Fr, status: NoteStatus, scopes?: AztecAddress[]): Promise<{
23
+ contractAddress: AztecAddress;
24
+ owner: AztecAddress;
25
+ storageSlot: Fr;
26
+ randomness: Fr;
27
+ noteNonce: Fr;
28
+ note: Note;
29
+ noteHash: Fr;
30
+ siloedNullifier: Fr;
31
+ index: bigint;
32
+ }[]>;
33
+ /**
34
+ * Looks for nullifiers of active contract notes and marks them as nullified if a nullifier is found.
35
+ *
36
+ * Fetches notes from the NoteDataProvider and checks which nullifiers are present in the
37
+ * onchain nullifier Merkle tree - up to the latest locally synced block. We use the
38
+ * locally synced block instead of querying the chain's 'latest' block to ensure correctness:
39
+ * notes are only marked nullified once their corresponding nullifier has been included in a
40
+ * block up to which the PXE has synced.
41
+ * This allows recent nullifications to be processed even if the node is not an archive node.
42
+ *
43
+ * @param contractAddress - The contract whose notes should be checked and nullified.
44
+ */
45
+ syncNoteNullifiers(contractAddress: AztecAddress): Promise<void>;
46
+ deliverNote(contractAddress: AztecAddress, owner: AztecAddress, storageSlot: Fr, randomness: Fr, noteNonce: Fr, content: Fr[], noteHash: Fr, nullifier: Fr, txHash: TxHash, recipient: AztecAddress): Promise<void>;
47
+ }
48
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm90ZV9zZXJ2aWNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbm90ZXMvbm90ZV9zZXJ2aWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUNwRCxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUdoRSxPQUFPLEVBQUUsS0FBSyxTQUFTLEVBQWUsTUFBTSxpQ0FBaUMsQ0FBQztBQUM5RSxPQUFPLEVBQUUsSUFBSSxFQUFXLFVBQVUsRUFBRSxNQUFNLG9CQUFvQixDQUFDO0FBRS9ELE9BQU8sS0FBSyxFQUFFLE1BQU0sRUFBRSxNQUFNLGtCQUFrQixDQUFDO0FBRS9DLE9BQU8sS0FBSyxFQUFFLHVCQUF1QixFQUFFLE1BQU0scUVBQXFFLENBQUM7QUFDbkgsT0FBTyxLQUFLLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxxREFBcUQsQ0FBQztBQUU1RixxQkFBYSxXQUFXO0lBRXBCLE9BQU8sQ0FBQyxRQUFRLENBQUMsZ0JBQWdCO0lBQ2pDLE9BQU8sQ0FBQyxRQUFRLENBQUMsU0FBUztJQUMxQixPQUFPLENBQUMsUUFBUSxDQUFDLHVCQUF1QjtJQUgxQyxZQUNtQixnQkFBZ0IsRUFBRSxnQkFBZ0IsRUFDbEMsU0FBUyxFQUFFLFNBQVMsRUFDcEIsdUJBQXVCLEVBQUUsdUJBQXV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AAuB,EAAE,MAAM,qEAAqE,CAAC;AACnH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qDAAqD,CAAC;AAE5F,qBAAa,WAAW;IAEpB,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,uBAAuB;IAH1C,YACmB,gBAAgB,EAAE,gBAAgB,EAClC,SAAS,EAAE,SAAS,EACpB,uBAAuB,EAAE,uBAAuB,EAC/D;IAEJ;;;;;;;;OAQG;IACU,QAAQ,CACnB,eAAe,EAAE,YAAY,EAC7B,KAAK,EAAE,YAAY,GAAG,SAAS,EAC/B,WAAW,EAAE,EAAE,EACf,MAAM,EAAE,UAAU,EAClB,MAAM,CAAC,EAAE,YAAY,EAAE;;;;;;;;;;SAuBxB;IAED;;;;;;;;;;;OAWG;IACU,kBAAkB,CAAC,eAAe,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAsC5E;IAEY,WAAW,CACtB,eAAe,EAAE,YAAY,EAC7B,KAAK,EAAE,YAAY,EACnB,WAAW,EAAE,EAAE,EACf,UAAU,EAAE,EAAE,EACd,SAAS,EAAE,EAAE,EACb,OAAO,EAAE,EAAE,EAAE,EACb,QAAQ,EAAE,EAAE,EACZ,SAAS,EAAE,EAAE,EACb,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,YAAY,GACtB,OAAO,CAAC,IAAI,CAAC,CA6Ef;CACF"}
@@ -0,0 +1,152 @@
1
+ import { computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
2
+ import { MAX_RPC_LEN } from '@aztec/stdlib/interfaces/client';
3
+ import { Note, NoteDao } from '@aztec/stdlib/note';
4
+ import { MerkleTreeId } from '@aztec/stdlib/trees';
5
+ export class NoteService {
6
+ noteDataProvider;
7
+ aztecNode;
8
+ anchorBlockDataProvider;
9
+ constructor(noteDataProvider, aztecNode, anchorBlockDataProvider){
10
+ this.noteDataProvider = noteDataProvider;
11
+ this.aztecNode = aztecNode;
12
+ this.anchorBlockDataProvider = anchorBlockDataProvider;
13
+ }
14
+ /**
15
+ * Retrieves a set of notes stored in the database for a given contract address and storage slot.
16
+ * The query result is paginated using 'limit' and 'offset' values.
17
+ * Returns an object containing an array of note data.
18
+ *
19
+ * @param owner - The owner of the notes. If undefined, returns notes for all known owners.
20
+ * @param status - The status of notes to fetch.
21
+ * @param scopes - The accounts whose notes we can access in this call. Currently optional and will default to all.
22
+ */ async getNotes(contractAddress, owner, storageSlot, status, scopes) {
23
+ const noteDaos = await this.noteDataProvider.getNotes({
24
+ contractAddress,
25
+ owner,
26
+ storageSlot,
27
+ status,
28
+ scopes
29
+ });
30
+ return noteDaos.map(({ contractAddress, owner, storageSlot, randomness, noteNonce, note, noteHash, siloedNullifier, index })=>({
31
+ contractAddress,
32
+ owner,
33
+ storageSlot,
34
+ randomness,
35
+ noteNonce,
36
+ note,
37
+ noteHash,
38
+ siloedNullifier,
39
+ // PXE can use this index to get full MembershipWitness
40
+ index
41
+ }));
42
+ }
43
+ /**
44
+ * Looks for nullifiers of active contract notes and marks them as nullified if a nullifier is found.
45
+ *
46
+ * Fetches notes from the NoteDataProvider and checks which nullifiers are present in the
47
+ * onchain nullifier Merkle tree - up to the latest locally synced block. We use the
48
+ * locally synced block instead of querying the chain's 'latest' block to ensure correctness:
49
+ * notes are only marked nullified once their corresponding nullifier has been included in a
50
+ * block up to which the PXE has synced.
51
+ * This allows recent nullifications to be processed even if the node is not an archive node.
52
+ *
53
+ * @param contractAddress - The contract whose notes should be checked and nullified.
54
+ */ async syncNoteNullifiers(contractAddress) {
55
+ const syncedBlockNumber = (await this.anchorBlockDataProvider.getBlockHeader()).getBlockNumber();
56
+ const contractNotes = await this.noteDataProvider.getNotes({
57
+ contractAddress
58
+ });
59
+ if (contractNotes.length === 0) {
60
+ return;
61
+ }
62
+ const nullifiersToCheck = contractNotes.map((note)=>note.siloedNullifier);
63
+ const nullifierBatches = nullifiersToCheck.reduce((acc, nullifier)=>{
64
+ if (acc[acc.length - 1].length < MAX_RPC_LEN) {
65
+ acc[acc.length - 1].push(nullifier);
66
+ } else {
67
+ acc.push([
68
+ nullifier
69
+ ]);
70
+ }
71
+ return acc;
72
+ }, [
73
+ []
74
+ ]);
75
+ const nullifierIndexes = (await Promise.all(nullifierBatches.map((batch)=>this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NULLIFIER_TREE, batch)))).flat();
76
+ const foundNullifiers = nullifiersToCheck.map((nullifier, i)=>{
77
+ if (nullifierIndexes[i] !== undefined) {
78
+ return {
79
+ ...nullifierIndexes[i],
80
+ ...{
81
+ data: nullifier
82
+ }
83
+ };
84
+ }
85
+ }).filter((nullifier)=>nullifier !== undefined);
86
+ await this.noteDataProvider.applyNullifiers(foundNullifiers);
87
+ }
88
+ async deliverNote(contractAddress, owner, storageSlot, randomness, noteNonce, content, noteHash, nullifier, txHash, recipient) {
89
+ // We are going to store the new note in the NoteDataProvider, which will let us later return it via `getNotes`.
90
+ // There's two things we need to check before we do this however:
91
+ // - we must make sure the note does actually exist in the note hash tree
92
+ // - we need to check if the note has already been nullified
93
+ //
94
+ // Failing to do either of the above would result in circuits getting either non-existent notes and failing to
95
+ // produce inclusion proofs for them, or getting nullified notes and producing duplicate nullifiers, both of which
96
+ // are catastrophic failure modes.
97
+ //
98
+ // Note that adding a note and removing it is *not* equivalent to never adding it in the first place. A nullifier
99
+ // emitted in a block that comes after note creation might result in the note being de-nullified by a chain reorg,
100
+ // so we must store both the note hash and nullifier block information.
101
+ // We avoid making node queries at 'latest' since we don't want to process notes or nullifiers that only exist ahead
102
+ // in time of the locally synced state.
103
+ // Note that while this technically results in historical queries, we perform it at the latest locally synced block
104
+ // number which *should* be recent enough to be available, even for non-archive nodes.
105
+ // Also note that the note should never be ahead of the synced block here since `fetchTaggedLogs` only processes
106
+ // logs up to the synced block making this only an additional safety check.
107
+ const syncedBlockNumber = (await this.anchorBlockDataProvider.getBlockHeader()).getBlockNumber();
108
+ // By computing siloed and unique note hashes ourselves we prevent contracts from interfering with the note storage
109
+ // of other contracts, which would constitute a security breach.
110
+ const uniqueNoteHash = await computeUniqueNoteHash(noteNonce, await siloNoteHash(contractAddress, noteHash));
111
+ const siloedNullifier = await siloNullifier(contractAddress, nullifier);
112
+ const txEffect = await this.aztecNode.getTxEffect(txHash);
113
+ if (!txEffect) {
114
+ throw new Error(`Could not find tx effect for tx hash ${txHash}`);
115
+ }
116
+ if (txEffect.l2BlockNumber > syncedBlockNumber) {
117
+ throw new Error(`Could not find tx effect for tx hash ${txHash} as of block number ${syncedBlockNumber}`);
118
+ }
119
+ const noteInTx = txEffect.data.noteHashes.some((nh)=>nh.equals(uniqueNoteHash));
120
+ if (!noteInTx) {
121
+ throw new Error(`Note hash ${noteHash} (uniqued as ${uniqueNoteHash}) is not present in tx ${txHash}`);
122
+ }
123
+ // We store notes by their index in the global note hash tree, which has the convenient side effect of validating
124
+ // note existence in said tree. We concurrently also check if the note's nullifier exists, performing all node
125
+ // queries in a single round-trip.
126
+ const [[uniqueNoteHashTreeIndexInBlock], [nullifierIndex]] = await Promise.all([
127
+ this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NOTE_HASH_TREE, [
128
+ uniqueNoteHash
129
+ ]),
130
+ this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NULLIFIER_TREE, [
131
+ siloedNullifier
132
+ ])
133
+ ]);
134
+ if (uniqueNoteHashTreeIndexInBlock === undefined) {
135
+ throw new Error(`Note hash ${noteHash} (uniqued as ${uniqueNoteHash}) is not present on the tree at block ${syncedBlockNumber} (from tx ${txHash})`);
136
+ }
137
+ const noteDao = new NoteDao(new Note(content), contractAddress, owner, storageSlot, randomness, noteNonce, noteHash, siloedNullifier, txHash, uniqueNoteHashTreeIndexInBlock.l2BlockNumber, uniqueNoteHashTreeIndexInBlock.l2BlockHash.toString(), uniqueNoteHashTreeIndexInBlock.data);
138
+ // The note was found by `recipient`, so we use that as the scope when storing the note.
139
+ await this.noteDataProvider.addNotes([
140
+ noteDao
141
+ ], recipient);
142
+ if (nullifierIndex !== undefined) {
143
+ const { data: _, ...blockHashAndNum } = nullifierIndex;
144
+ await this.noteDataProvider.applyNullifiers([
145
+ {
146
+ data: siloedNullifier,
147
+ ...blockHashAndNum
148
+ }
149
+ ]);
150
+ }
151
+ }
152
+ }
@@ -10,7 +10,7 @@ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
10
10
  import { UpdatedClassIdHints } from '@aztec/stdlib/kernel';
11
11
  import type { NullifierMembershipWitness } from '@aztec/stdlib/trees';
12
12
  import type { VerificationKeyAsFields } from '@aztec/stdlib/vks';
13
- import type { ContractDataProvider } from '../storage/index.js';
13
+ import type { ContractDataProvider } from '../storage/contract_data_provider/contract_data_provider.js';
14
14
  import type { PrivateKernelOracle } from './private_kernel_oracle.js';
15
15
  /**
16
16
  * A data oracle that provides information needed for simulating a transaction.
@@ -43,4 +43,4 @@ export declare class PrivateKernelOracleImpl implements PrivateKernelOracle {
43
43
  getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string>;
44
44
  getUpdatedClassIdHints(contractAddress: AztecAddress): Promise<UpdatedClassIdHints>;
45
45
  }
46
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJpdmF0ZV9rZXJuZWxfb3JhY2xlX2ltcGwuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9wcml2YXRlX2tlcm5lbC9wcml2YXRlX2tlcm5lbF9vcmFjbGVfaW1wbC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUscUJBQXFCLEVBQTJDLE1BQU0sa0JBQWtCLENBQUM7QUFDbEcsT0FBTyxLQUFLLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDekQsT0FBTyxLQUFL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,SAAS,CAAC,CAE5F;IAEK,mBAAmB,IAAI,OAAO,CAAC,EAAE,CAAC,CAMvC;IAEM,kBAAkB,CAAC,eAAe,EAAE,KAAK,GAAG,OAAO,CAAC,cAAc,CAAC,CAEzE;IAEM,oBAAoB,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAEtG;IAEY,sBAAsB,CAAC,eAAe,EAAE,YAAY,GAAG,OAAO,CAAC,mBAAmB,CAAC,CA8B/F;CACF"}
@@ -0,0 +1,24 @@
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import type { BlockParameter } from '@aztec/stdlib/block';
4
+ import type { AztecNode } from '@aztec/stdlib/interfaces/server';
5
+ import type { AnchorBlockDataProvider } from '../storage/anchor_block_data_provider/anchor_block_data_provider.js';
6
+ export declare class PublicStorageService {
7
+ private readonly anchorBlockDataProvider;
8
+ private readonly aztecNode;
9
+ constructor(anchorBlockDataProvider: AnchorBlockDataProvider, aztecNode: AztecNode);
10
+ /**
11
+ * Gets the storage value at the given contract storage slot.
12
+ *
13
+ * @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
14
+ * Aztec's version of `eth_getStorageAt`.
15
+ *
16
+ * @param blockNumber - The block number at which to get the data.
17
+ * @param contract - Address of the contract to query.
18
+ * @param slot - Slot to query.
19
+ * @returns Storage value at the given contract slot.
20
+ * @throws If the contract is not deployed.
21
+ */
22
+ getPublicStorageAt(blockNumber: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr>;
23
+ }
24
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljX3N0b3JhZ2Vfc2VydmljZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3B1YmxpY19zdG9yYWdlL3B1YmxpY19zdG9yYWdlX3Nl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AAM,qEAAqE,CAAC;AAEnH,qBAAa,oBAAoB;IAE7B,OAAO,CAAC,QAAQ,CAAC,uBAAuB;IACxC,OAAO,CAAC,QAAQ,CAAC,SAAS;IAF5B,YACmB,uBAAuB,EAAE,uBAAuB,EAChD,SAAS,EAAE,SAAS,EACnC;IAEJ;;;;;;;;;;;OAWG;IACU,kBAAkB,CAAC,WAAW,EAAE,cAAc,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,CAM1G;CACF"}
@@ -0,0 +1,26 @@
1
+ export class PublicStorageService {
2
+ anchorBlockDataProvider;
3
+ aztecNode;
4
+ constructor(anchorBlockDataProvider, aztecNode){
5
+ this.anchorBlockDataProvider = anchorBlockDataProvider;
6
+ this.aztecNode = aztecNode;
7
+ }
8
+ /**
9
+ * Gets the storage value at the given contract storage slot.
10
+ *
11
+ * @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
12
+ * Aztec's version of `eth_getStorageAt`.
13
+ *
14
+ * @param blockNumber - The block number at which to get the data.
15
+ * @param contract - Address of the contract to query.
16
+ * @param slot - Slot to query.
17
+ * @returns Storage value at the given contract slot.
18
+ * @throws If the contract is not deployed.
19
+ */ async getPublicStorageAt(blockNumber, contract, slot) {
20
+ const anchorBlockNumber = (await this.anchorBlockDataProvider.getBlockHeader()).getBlockNumber();
21
+ if (blockNumber !== 'latest' && blockNumber > anchorBlockNumber) {
22
+ throw new Error(`Block number ${blockNumber} is higher than current block ${anchorBlockNumber}`);
23
+ }
24
+ return await this.aztecNode.getPublicStorageAt(blockNumber, contract, slot);
25
+ }
26
+ }