@aztec/pxe 3.0.0-nightly.20251216 → 3.0.0-nightly.20251218
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.
- package/dest/block_synchronizer/block_synchronizer.d.ts +39 -0
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -0
- package/dest/{synchronizer/synchronizer.js → block_synchronizer/block_synchronizer.js} +22 -17
- package/dest/block_synchronizer/index.d.ts +2 -0
- package/dest/block_synchronizer/index.d.ts.map +1 -0
- package/dest/block_synchronizer/index.js +1 -0
- package/dest/config/index.d.ts +4 -4
- package/dest/config/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +6 -4
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +7 -6
- package/dest/contract_function_simulator/execution_data_provider.d.ts +6 -26
- package/dest/contract_function_simulator/execution_data_provider.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +1 -1
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +2 -2
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +3 -3
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -2
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +0 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +2 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +8 -4
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +4 -3
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +8 -7
- package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +9 -20
- package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +1 -1
- package/dest/contract_function_simulator/pxe_oracle_interface.js +41 -106
- package/dest/debug/pxe_debug_utils.d.ts +30 -0
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -0
- package/dest/debug/pxe_debug_utils.js +37 -0
- package/dest/events/private_event_filter_validator.d.ts +4 -4
- package/dest/events/private_event_filter_validator.d.ts.map +1 -1
- package/dest/events/private_event_filter_validator.js +4 -4
- package/dest/pxe.d.ts +19 -28
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +70 -86
- package/dest/storage/anchor_block_data_provider/anchor_block_data_provider.d.ts +9 -0
- package/dest/storage/anchor_block_data_provider/anchor_block_data_provider.d.ts.map +1 -0
- package/dest/storage/{sync_data_provider/sync_data_provider.js → anchor_block_data_provider/anchor_block_data_provider.js} +2 -9
- package/dest/storage/anchor_block_data_provider/index.d.ts +2 -0
- package/dest/storage/anchor_block_data_provider/index.d.ts.map +1 -0
- package/dest/storage/anchor_block_data_provider/index.js +1 -0
- package/dest/storage/contract_data_provider/contract_data_provider.d.ts +3 -2
- package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +1 -1
- package/dest/storage/contract_data_provider/contract_data_provider.js +21 -1
- package/dest/storage/index.d.ts +2 -2
- package/dest/storage/index.d.ts.map +1 -1
- package/dest/storage/index.js +1 -1
- package/dest/storage/tagging_data_provider/index.d.ts +3 -2
- package/dest/storage/tagging_data_provider/index.d.ts.map +1 -1
- package/dest/storage/tagging_data_provider/index.js +2 -1
- package/dest/storage/tagging_data_provider/recipient_tagging_data_provider.d.ts +31 -0
- package/dest/storage/tagging_data_provider/recipient_tagging_data_provider.d.ts.map +1 -0
- package/dest/storage/tagging_data_provider/recipient_tagging_data_provider.js +65 -0
- package/dest/storage/tagging_data_provider/sender_tagging_data_provider.d.ts +67 -0
- package/dest/storage/tagging_data_provider/sender_tagging_data_provider.d.ts.map +1 -0
- package/dest/storage/tagging_data_provider/sender_tagging_data_provider.js +196 -0
- package/dest/tagging/constants.d.ts +1 -1
- package/dest/tagging/constants.d.ts.map +1 -1
- package/dest/tagging/constants.js +1 -0
- package/dest/tagging/sync/sync_sender_tagging_indexes.d.ts +21 -0
- package/dest/tagging/sync/sync_sender_tagging_indexes.d.ts.map +1 -0
- package/dest/tagging/sync/sync_sender_tagging_indexes.js +89 -0
- package/dest/tagging/sync/utils/get_status_change_of_pending.d.ts +11 -0
- package/dest/tagging/sync/utils/get_status_change_of_pending.d.ts.map +1 -0
- package/dest/tagging/sync/utils/get_status_change_of_pending.js +32 -0
- package/dest/tagging/sync/utils/load_and_store_new_tagging_indexes.d.ts +18 -0
- package/dest/tagging/sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
- package/dest/tagging/sync/utils/load_and_store_new_tagging_indexes.js +57 -0
- package/dest/tagging/utils.d.ts +2 -2
- package/dest/tagging/utils.d.ts.map +1 -1
- package/dest/tagging/utils.js +3 -2
- package/package.json +16 -16
- package/src/{synchronizer/synchronizer.ts → block_synchronizer/block_synchronizer.ts} +21 -17
- package/src/block_synchronizer/index.ts +1 -0
- package/src/config/index.ts +3 -3
- package/src/contract_function_simulator/contract_function_simulator.ts +21 -5
- package/src/contract_function_simulator/execution_data_provider.ts +7 -28
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +1 -1
- package/src/contract_function_simulator/oracle/interfaces.ts +1 -1
- package/src/contract_function_simulator/oracle/oracle.ts +3 -3
- package/src/contract_function_simulator/oracle/private_execution.ts +1 -3
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +11 -5
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +6 -6
- package/src/contract_function_simulator/pxe_oracle_interface.ts +41 -114
- package/src/debug/pxe_debug_utils.ts +47 -0
- package/src/events/private_event_filter_validator.ts +3 -3
- package/src/pxe.ts +74 -96
- package/src/storage/{sync_data_provider/sync_data_provider.ts → anchor_block_data_provider/anchor_block_data_provider.ts} +2 -12
- package/src/storage/anchor_block_data_provider/index.ts +1 -0
- package/src/storage/contract_data_provider/contract_data_provider.ts +27 -0
- package/src/storage/index.ts +1 -1
- package/src/storage/tagging_data_provider/index.ts +2 -1
- package/src/storage/tagging_data_provider/recipient_tagging_data_provider.ts +86 -0
- package/src/storage/tagging_data_provider/sender_tagging_data_provider.ts +244 -0
- package/src/tagging/constants.ts +1 -0
- package/src/tagging/sync/sync_sender_tagging_indexes.ts +112 -0
- package/src/tagging/sync/utils/get_status_change_of_pending.ts +44 -0
- package/src/tagging/sync/utils/load_and_store_new_tagging_indexes.ts +74 -0
- package/src/tagging/utils.ts +3 -2
- package/dest/storage/sync_data_provider/index.d.ts +0 -2
- package/dest/storage/sync_data_provider/index.d.ts.map +0 -1
- package/dest/storage/sync_data_provider/index.js +0 -1
- package/dest/storage/sync_data_provider/sync_data_provider.d.ts +0 -11
- package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +0 -1
- package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +0 -40
- package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +0 -1
- package/dest/storage/tagging_data_provider/tagging_data_provider.js +0 -89
- package/dest/synchronizer/index.d.ts +0 -2
- package/dest/synchronizer/index.d.ts.map +0 -1
- package/dest/synchronizer/index.js +0 -1
- package/dest/synchronizer/synchronizer.d.ts +0 -36
- package/dest/synchronizer/synchronizer.d.ts.map +0 -1
- package/src/storage/sync_data_provider/index.ts +0 -1
- package/src/storage/tagging_data_provider/tagging_data_provider.ts +0 -120
- package/src/synchronizer/index.ts +0 -1
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { toArray } from '@aztec/foundation/iterable';
|
|
2
|
-
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
-
export class TaggingDataProvider {
|
|
4
|
-
#store;
|
|
5
|
-
#addressBook;
|
|
6
|
-
// Stores the last used index for each directional app tagging secret. Taking into account whether we are
|
|
7
|
-
// requesting the index as a sender or as a recipient because the sender and recipient can be in the same PXE.
|
|
8
|
-
#lastUsedIndexesAsSenders;
|
|
9
|
-
#lastUsedIndexesAsRecipients;
|
|
10
|
-
constructor(store){
|
|
11
|
-
this.#store = store;
|
|
12
|
-
this.#addressBook = this.#store.openMap('address_book');
|
|
13
|
-
this.#lastUsedIndexesAsSenders = this.#store.openMap('last_used_indexes_as_senders');
|
|
14
|
-
this.#lastUsedIndexesAsRecipients = this.#store.openMap('last_used_indexes_as_recipients');
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Sets the last used indexes when sending a log.
|
|
18
|
-
* @param preTags - The pre tags containing the directional app tagging secrets and the indexes that are to be
|
|
19
|
-
* updated in the db.
|
|
20
|
-
* @throws If any two pre tags contain the same directional app tagging secret
|
|
21
|
-
*/ setLastUsedIndexesAsSender(preTags) {
|
|
22
|
-
this.#assertUniqueSecrets(preTags, 'sender');
|
|
23
|
-
return Promise.all(preTags.map(({ secret, index })=>this.#lastUsedIndexesAsSenders.set(secret.toString(), index)));
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Sets the last used indexes when looking for logs.
|
|
27
|
-
* @param preTags - The pre tags containing the directional app tagging secrets and the indexes that are to be
|
|
28
|
-
* updated in the db.
|
|
29
|
-
* @throws If any two pre tags contain the same directional app tagging secret
|
|
30
|
-
*/ setLastUsedIndexesAsRecipient(preTags) {
|
|
31
|
-
this.#assertUniqueSecrets(preTags, 'recipient');
|
|
32
|
-
return Promise.all(preTags.map(({ secret, index })=>this.#lastUsedIndexesAsRecipients.set(secret.toString(), index)));
|
|
33
|
-
}
|
|
34
|
-
// It should never happen that we would receive any two pre tags on the input containing the same directional app
|
|
35
|
-
// tagging secret as everywhere we always just apply the largest index. Hence this check is a good way to catch
|
|
36
|
-
// bugs.
|
|
37
|
-
#assertUniqueSecrets(preTags, role) {
|
|
38
|
-
const secretStrings = preTags.map(({ secret })=>secret.toString());
|
|
39
|
-
const uniqueSecrets = new Set(secretStrings);
|
|
40
|
-
if (uniqueSecrets.size !== secretStrings.length) {
|
|
41
|
-
throw new Error(`Duplicate secrets found when setting last used indexes as ${role}`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Returns the last used index when sending a log with a given secret.
|
|
46
|
-
* @param secret - The directional app tagging secret.
|
|
47
|
-
* @returns The last used index for the given directional app tagging secret, or undefined if not found.
|
|
48
|
-
*/ async getLastUsedIndexesAsSender(secret) {
|
|
49
|
-
return await this.#lastUsedIndexesAsSenders.getAsync(secret.toString());
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Returns the last used indexes when looking for logs as a recipient.
|
|
53
|
-
* @param secrets - The directional app tagging secrets to obtain the indexes for.
|
|
54
|
-
* @returns The last used indexes for the given directional app tagging secrets, or undefined if have never yet found
|
|
55
|
-
* a log for a given secret.
|
|
56
|
-
*/ getLastUsedIndexesAsRecipient(secrets) {
|
|
57
|
-
return Promise.all(secrets.map((secret)=>this.#lastUsedIndexesAsRecipients.getAsync(secret.toString())));
|
|
58
|
-
}
|
|
59
|
-
resetNoteSyncData() {
|
|
60
|
-
return this.#store.transactionAsync(async ()=>{
|
|
61
|
-
const keysForSenders = await toArray(this.#lastUsedIndexesAsSenders.keysAsync());
|
|
62
|
-
await Promise.all(keysForSenders.map((secret)=>this.#lastUsedIndexesAsSenders.delete(secret)));
|
|
63
|
-
const keysForRecipients = await toArray(this.#lastUsedIndexesAsRecipients.keysAsync());
|
|
64
|
-
await Promise.all(keysForRecipients.map((secret)=>this.#lastUsedIndexesAsRecipients.delete(secret)));
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
async addSenderAddress(address) {
|
|
68
|
-
if (await this.#addressBook.hasAsync(address.toString())) {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
await this.#addressBook.set(address.toString(), true);
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
74
|
-
async getSenderAddresses() {
|
|
75
|
-
return (await toArray(this.#addressBook.keysAsync())).map(AztecAddress.fromString);
|
|
76
|
-
}
|
|
77
|
-
async removeSenderAddress(address) {
|
|
78
|
-
if (!await this.#addressBook.hasAsync(address.toString())) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
await this.#addressBook.delete(address.toString());
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
async getSize() {
|
|
85
|
-
const addressesCount = (await toArray(this.#addressBook.keysAsync())).length;
|
|
86
|
-
// All keys are addresses
|
|
87
|
-
return 3 * addressesCount * AztecAddress.SIZE_IN_BYTES;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/synchronizer/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './synchronizer.js';
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { type Logger } from '@aztec/foundation/log';
|
|
3
|
-
import type { L2TipsKVStore } from '@aztec/kv-store/stores';
|
|
4
|
-
import { L2BlockStream, type L2BlockStreamEvent, type L2BlockStreamEventHandler } from '@aztec/stdlib/block';
|
|
5
|
-
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
6
|
-
import type { PXEConfig } from '../config/index.js';
|
|
7
|
-
import type { NoteDataProvider } from '../storage/note_data_provider/note_data_provider.js';
|
|
8
|
-
import type { SyncDataProvider } from '../storage/sync_data_provider/sync_data_provider.js';
|
|
9
|
-
import type { TaggingDataProvider } from '../storage/tagging_data_provider/tagging_data_provider.js';
|
|
10
|
-
/**
|
|
11
|
-
* The Synchronizer class orchestrates synchronization between the PXE and Aztec node, maintaining an up-to-date
|
|
12
|
-
* view of the L2 chain state. It handles block header retrieval, chain reorganizations, and provides an interface
|
|
13
|
-
* for querying sync status.
|
|
14
|
-
*/
|
|
15
|
-
export declare class Synchronizer implements L2BlockStreamEventHandler {
|
|
16
|
-
private node;
|
|
17
|
-
private syncDataProvider;
|
|
18
|
-
private noteDataProvider;
|
|
19
|
-
private taggingDataProvider;
|
|
20
|
-
private l2TipsStore;
|
|
21
|
-
private log;
|
|
22
|
-
private isSyncing;
|
|
23
|
-
protected readonly blockStream: L2BlockStream;
|
|
24
|
-
constructor(node: AztecNode, syncDataProvider: SyncDataProvider, noteDataProvider: NoteDataProvider, taggingDataProvider: TaggingDataProvider, l2TipsStore: L2TipsKVStore, config?: Partial<Pick<PXEConfig, 'l2BlockBatchSize'>>, loggerOrSuffix?: string | Logger);
|
|
25
|
-
protected createBlockStream(config: Partial<Pick<PXEConfig, 'l2BlockBatchSize'>>): L2BlockStream;
|
|
26
|
-
/** Handle events emitted by the block stream. */
|
|
27
|
-
handleBlockStreamEvent(event: L2BlockStreamEvent): Promise<void>;
|
|
28
|
-
/**
|
|
29
|
-
* Syncs PXE and the node by downloading the metadata of the latest blocks, allowing simulations to use
|
|
30
|
-
* recent data (e.g. notes), and handling any reorgs that might have occurred.
|
|
31
|
-
*/
|
|
32
|
-
sync(): Promise<void>;
|
|
33
|
-
private doSync;
|
|
34
|
-
getSynchedBlockNumber(): Promise<BlockNumber>;
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3luY2hyb25pemVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3luY2hyb25pemVyL3N5bmNocm9uaXplci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsV0FBVyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDOUQsT0FBTyxFQUFFLEtBQUssTUFBTSxFQUFnQixNQUFNLHVCQUF1QixDQUFDO0FBQ2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,OAAO,CAAC,gBAAgB;IACxB,OAAO,CAAC,mBAAmB;IAC3B,OAAO,CAAC,WAAW;IATrB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,SAAS,CAA4B;IAC7C,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC;IAE9C,YACU,IAAI,EAAE,SAAS,EACf,gBAAgB,EAAE,gBAAgB,EAClC,gBAAgB,EAAE,gBAAgB,EAClC,mBAAmB,EAAE,mBAAmB,EACxC,WAAW,EAAE,aAAa,EAClC,MAAM,GAAE,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAM,EACzD,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,EAOjC;IAED,SAAS,CAAC,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC,iBAO/E;IAED,iDAAiD;IACpC,sBAAsB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgC5E;IAED;;;OAGG;IACU,IAAI,kBAehB;YAEa,MAAM;IAeb,qBAAqB,yBAE3B;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { SyncDataProvider } from './sync_data_provider.js';
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { toArray } from '@aztec/foundation/iterable';
|
|
2
|
-
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
3
|
-
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
-
import type { DirectionalAppTaggingSecret, PreTag } from '@aztec/stdlib/logs';
|
|
5
|
-
|
|
6
|
-
export class TaggingDataProvider {
|
|
7
|
-
#store: AztecAsyncKVStore;
|
|
8
|
-
#addressBook: AztecAsyncMap<string, true>;
|
|
9
|
-
|
|
10
|
-
// Stores the last used index for each directional app tagging secret. Taking into account whether we are
|
|
11
|
-
// requesting the index as a sender or as a recipient because the sender and recipient can be in the same PXE.
|
|
12
|
-
#lastUsedIndexesAsSenders: AztecAsyncMap<string, number>;
|
|
13
|
-
#lastUsedIndexesAsRecipients: AztecAsyncMap<string, number>;
|
|
14
|
-
|
|
15
|
-
constructor(store: AztecAsyncKVStore) {
|
|
16
|
-
this.#store = store;
|
|
17
|
-
|
|
18
|
-
this.#addressBook = this.#store.openMap('address_book');
|
|
19
|
-
|
|
20
|
-
this.#lastUsedIndexesAsSenders = this.#store.openMap('last_used_indexes_as_senders');
|
|
21
|
-
this.#lastUsedIndexesAsRecipients = this.#store.openMap('last_used_indexes_as_recipients');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Sets the last used indexes when sending a log.
|
|
26
|
-
* @param preTags - The pre tags containing the directional app tagging secrets and the indexes that are to be
|
|
27
|
-
* updated in the db.
|
|
28
|
-
* @throws If any two pre tags contain the same directional app tagging secret
|
|
29
|
-
*/
|
|
30
|
-
setLastUsedIndexesAsSender(preTags: PreTag[]) {
|
|
31
|
-
this.#assertUniqueSecrets(preTags, 'sender');
|
|
32
|
-
|
|
33
|
-
return Promise.all(
|
|
34
|
-
preTags.map(({ secret, index }) => this.#lastUsedIndexesAsSenders.set(secret.toString(), index)),
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Sets the last used indexes when looking for logs.
|
|
40
|
-
* @param preTags - The pre tags containing the directional app tagging secrets and the indexes that are to be
|
|
41
|
-
* updated in the db.
|
|
42
|
-
* @throws If any two pre tags contain the same directional app tagging secret
|
|
43
|
-
*/
|
|
44
|
-
setLastUsedIndexesAsRecipient(preTags: PreTag[]) {
|
|
45
|
-
this.#assertUniqueSecrets(preTags, 'recipient');
|
|
46
|
-
|
|
47
|
-
return Promise.all(
|
|
48
|
-
preTags.map(({ secret, index }) => this.#lastUsedIndexesAsRecipients.set(secret.toString(), index)),
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// It should never happen that we would receive any two pre tags on the input containing the same directional app
|
|
53
|
-
// tagging secret as everywhere we always just apply the largest index. Hence this check is a good way to catch
|
|
54
|
-
// bugs.
|
|
55
|
-
#assertUniqueSecrets(preTags: PreTag[], role: 'sender' | 'recipient'): void {
|
|
56
|
-
const secretStrings = preTags.map(({ secret }) => secret.toString());
|
|
57
|
-
const uniqueSecrets = new Set(secretStrings);
|
|
58
|
-
if (uniqueSecrets.size !== secretStrings.length) {
|
|
59
|
-
throw new Error(`Duplicate secrets found when setting last used indexes as ${role}`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Returns the last used index when sending a log with a given secret.
|
|
65
|
-
* @param secret - The directional app tagging secret.
|
|
66
|
-
* @returns The last used index for the given directional app tagging secret, or undefined if not found.
|
|
67
|
-
*/
|
|
68
|
-
async getLastUsedIndexesAsSender(secret: DirectionalAppTaggingSecret): Promise<number | undefined> {
|
|
69
|
-
return await this.#lastUsedIndexesAsSenders.getAsync(secret.toString());
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Returns the last used indexes when looking for logs as a recipient.
|
|
74
|
-
* @param secrets - The directional app tagging secrets to obtain the indexes for.
|
|
75
|
-
* @returns The last used indexes for the given directional app tagging secrets, or undefined if have never yet found
|
|
76
|
-
* a log for a given secret.
|
|
77
|
-
*/
|
|
78
|
-
getLastUsedIndexesAsRecipient(secrets: DirectionalAppTaggingSecret[]): Promise<(number | undefined)[]> {
|
|
79
|
-
return Promise.all(secrets.map(secret => this.#lastUsedIndexesAsRecipients.getAsync(secret.toString())));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
resetNoteSyncData(): Promise<void> {
|
|
83
|
-
return this.#store.transactionAsync(async () => {
|
|
84
|
-
const keysForSenders = await toArray(this.#lastUsedIndexesAsSenders.keysAsync());
|
|
85
|
-
await Promise.all(keysForSenders.map(secret => this.#lastUsedIndexesAsSenders.delete(secret)));
|
|
86
|
-
const keysForRecipients = await toArray(this.#lastUsedIndexesAsRecipients.keysAsync());
|
|
87
|
-
await Promise.all(keysForRecipients.map(secret => this.#lastUsedIndexesAsRecipients.delete(secret)));
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async addSenderAddress(address: AztecAddress): Promise<boolean> {
|
|
92
|
-
if (await this.#addressBook.hasAsync(address.toString())) {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
await this.#addressBook.set(address.toString(), true);
|
|
97
|
-
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async getSenderAddresses(): Promise<AztecAddress[]> {
|
|
102
|
-
return (await toArray(this.#addressBook.keysAsync())).map(AztecAddress.fromString);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async removeSenderAddress(address: AztecAddress): Promise<boolean> {
|
|
106
|
-
if (!(await this.#addressBook.hasAsync(address.toString()))) {
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
await this.#addressBook.delete(address.toString());
|
|
111
|
-
|
|
112
|
-
return true;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
async getSize() {
|
|
116
|
-
const addressesCount = (await toArray(this.#addressBook.keysAsync())).length;
|
|
117
|
-
// All keys are addresses
|
|
118
|
-
return 3 * addressesCount * AztecAddress.SIZE_IN_BYTES;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './synchronizer.js';
|