@aztec/pxe 0.66.0 → 0.67.1-devnet
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/bin/index.js +5 -6
- package/dest/config/index.d.ts +0 -9
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +1 -17
- package/dest/config/package_info.d.ts +5 -0
- package/dest/config/package_info.d.ts.map +1 -0
- package/dest/config/package_info.js +4 -0
- package/dest/contract_data_oracle/index.js +2 -2
- package/dest/database/incoming_note_dao.d.ts +1 -1
- package/dest/database/incoming_note_dao.d.ts.map +1 -1
- package/dest/database/incoming_note_dao.js +2 -2
- package/dest/database/kv_pxe_database.d.ts +10 -13
- package/dest/database/kv_pxe_database.d.ts.map +1 -1
- package/dest/database/kv_pxe_database.js +153 -230
- package/dest/database/outgoing_note_dao.js +2 -2
- package/dest/database/pxe_database.d.ts +7 -25
- package/dest/database/pxe_database.d.ts.map +1 -1
- package/dest/database/pxe_database_test_suite.d.ts.map +1 -1
- package/dest/database/pxe_database_test_suite.js +18 -59
- package/dest/index.d.ts +2 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -1
- package/dest/kernel_oracle/index.d.ts.map +1 -1
- package/dest/kernel_oracle/index.js +4 -4
- package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.js +2 -2
- package/dest/kernel_prover/index.d.ts +1 -0
- package/dest/kernel_prover/index.d.ts.map +1 -1
- package/dest/kernel_prover/index.js +2 -1
- package/dest/kernel_prover/kernel_prover.d.ts +1 -0
- package/dest/kernel_prover/kernel_prover.d.ts.map +1 -1
- package/dest/kernel_prover/kernel_prover.js +42 -5
- package/dest/kernel_prover/test/test_circuit_prover.d.ts +1 -2
- package/dest/kernel_prover/test/test_circuit_prover.d.ts.map +1 -1
- package/dest/kernel_prover/test/test_circuit_prover.js +7 -13
- package/dest/note_decryption_utils/add_public_values_to_payload.js +2 -2
- package/dest/note_decryption_utils/brute_force_note_info.d.ts +3 -3
- package/dest/note_decryption_utils/brute_force_note_info.d.ts.map +1 -1
- package/dest/note_decryption_utils/brute_force_note_info.js +8 -8
- package/dest/note_decryption_utils/produce_note_daos.d.ts +3 -6
- package/dest/note_decryption_utils/produce_note_daos.d.ts.map +1 -1
- package/dest/note_decryption_utils/produce_note_daos.js +5 -19
- package/dest/note_decryption_utils/produce_note_daos_for_key.d.ts +1 -1
- package/dest/note_decryption_utils/produce_note_daos_for_key.d.ts.map +1 -1
- package/dest/pxe_service/error_enriching.d.ts +3 -3
- package/dest/pxe_service/error_enriching.d.ts.map +1 -1
- package/dest/pxe_service/error_enriching.js +10 -10
- package/dest/pxe_service/index.d.ts +0 -1
- package/dest/pxe_service/index.d.ts.map +1 -1
- package/dest/pxe_service/index.js +1 -2
- package/dest/pxe_service/pxe_service.d.ts +2 -16
- package/dest/pxe_service/pxe_service.d.ts.map +1 -1
- package/dest/pxe_service/pxe_service.js +74 -96
- package/dest/pxe_service/test/pxe_test_suite.d.ts.map +1 -1
- package/dest/pxe_service/test/pxe_test_suite.js +1 -3
- package/dest/simulator/index.d.ts +1 -1
- package/dest/simulator/index.d.ts.map +1 -1
- package/dest/simulator/index.js +2 -2
- package/dest/simulator_oracle/index.d.ts +14 -11
- package/dest/simulator_oracle/index.d.ts.map +1 -1
- package/dest/simulator_oracle/index.js +170 -140
- package/dest/simulator_oracle/tagging_utils.d.ts +15 -0
- package/dest/simulator_oracle/tagging_utils.d.ts.map +1 -0
- package/dest/simulator_oracle/tagging_utils.js +23 -0
- package/dest/synchronizer/synchronizer.d.ts +10 -40
- package/dest/synchronizer/synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/synchronizer.js +35 -69
- package/dest/{pxe_service → utils}/create_pxe_service.d.ts +1 -1
- package/dest/utils/create_pxe_service.d.ts.map +1 -0
- package/dest/utils/create_pxe_service.js +52 -0
- package/package.json +31 -19
- package/src/bin/index.ts +4 -5
- package/src/config/index.ts +0 -21
- package/src/config/package_info.ts +3 -0
- package/src/contract_data_oracle/index.ts +1 -1
- package/src/database/incoming_note_dao.ts +2 -2
- package/src/database/kv_pxe_database.ts +214 -309
- package/src/database/outgoing_note_dao.ts +1 -1
- package/src/database/pxe_database.ts +7 -28
- package/src/database/pxe_database_test_suite.ts +20 -75
- package/src/index.ts +2 -0
- package/src/kernel_oracle/index.ts +3 -3
- package/src/kernel_prover/hints/build_private_kernel_reset_private_inputs.ts +1 -1
- package/src/kernel_prover/index.ts +2 -0
- package/src/kernel_prover/kernel_prover.ts +72 -3
- package/src/kernel_prover/test/test_circuit_prover.ts +11 -25
- package/src/note_decryption_utils/add_public_values_to_payload.ts +1 -1
- package/src/note_decryption_utils/brute_force_note_info.ts +9 -9
- package/src/note_decryption_utils/produce_note_daos.ts +5 -48
- package/src/note_decryption_utils/produce_note_daos_for_key.ts +1 -1
- package/src/pxe_service/error_enriching.ts +14 -12
- package/src/pxe_service/index.ts +0 -1
- package/src/pxe_service/pxe_service.ts +127 -174
- package/src/pxe_service/test/pxe_test_suite.ts +0 -3
- package/src/simulator/index.ts +1 -1
- package/src/simulator_oracle/index.ts +201 -188
- package/src/simulator_oracle/tagging_utils.ts +28 -0
- package/src/synchronizer/synchronizer.ts +37 -77
- package/src/{pxe_service → utils}/create_pxe_service.ts +16 -13
- package/dest/pxe_service/create_pxe_service.d.ts.map +0 -1
- package/dest/pxe_service/create_pxe_service.js +0 -49
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type InBlock,
|
|
3
|
-
type IncomingNotesFilter,
|
|
4
|
-
MerkleTreeId,
|
|
5
|
-
NoteStatus,
|
|
6
|
-
type OutgoingNotesFilter,
|
|
7
|
-
} from '@aztec/circuit-types';
|
|
1
|
+
import { type InBlock, type IncomingNotesFilter, MerkleTreeId, NoteStatus } from '@aztec/circuit-types';
|
|
8
2
|
import {
|
|
9
3
|
AztecAddress,
|
|
4
|
+
BlockHeader,
|
|
10
5
|
CompleteAddress,
|
|
11
6
|
type ContractInstanceWithAddress,
|
|
12
|
-
Header,
|
|
13
7
|
type IndexedTaggingSecret,
|
|
14
8
|
type PublicKey,
|
|
15
9
|
SerializableContractInstance,
|
|
@@ -17,66 +11,59 @@ import {
|
|
|
17
11
|
import { type ContractArtifact, FunctionSelector, FunctionType } from '@aztec/foundation/abi';
|
|
18
12
|
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
|
|
19
13
|
import { Fr } from '@aztec/foundation/fields';
|
|
14
|
+
import { toArray } from '@aztec/foundation/iterable';
|
|
20
15
|
import {
|
|
21
|
-
type
|
|
22
|
-
type
|
|
23
|
-
type
|
|
24
|
-
type
|
|
25
|
-
type
|
|
26
|
-
type
|
|
16
|
+
type AztecAsyncArray,
|
|
17
|
+
type AztecAsyncKVStore,
|
|
18
|
+
type AztecAsyncMap,
|
|
19
|
+
type AztecAsyncMultiMap,
|
|
20
|
+
type AztecAsyncSet,
|
|
21
|
+
type AztecAsyncSingleton,
|
|
27
22
|
} from '@aztec/kv-store';
|
|
28
23
|
import { contractArtifactFromBuffer, contractArtifactToBuffer } from '@aztec/types/abi';
|
|
29
24
|
|
|
30
25
|
import { IncomingNoteDao } from './incoming_note_dao.js';
|
|
31
|
-
import { OutgoingNoteDao } from './outgoing_note_dao.js';
|
|
32
26
|
import { type PxeDatabase } from './pxe_database.js';
|
|
33
27
|
|
|
34
28
|
/**
|
|
35
29
|
* A PXE database backed by LMDB.
|
|
36
30
|
*/
|
|
37
31
|
export class KVPxeDatabase implements PxeDatabase {
|
|
38
|
-
#synchronizedBlock:
|
|
39
|
-
#completeAddresses:
|
|
40
|
-
#completeAddressIndex:
|
|
41
|
-
#addressBook:
|
|
42
|
-
#authWitnesses:
|
|
43
|
-
#capsules:
|
|
44
|
-
#notes:
|
|
45
|
-
#nullifiedNotes:
|
|
46
|
-
#nullifierToNoteId:
|
|
47
|
-
#nullifiersByBlockNumber:
|
|
48
|
-
|
|
49
|
-
#nullifiedNotesToScope:
|
|
50
|
-
#nullifiedNotesByContract:
|
|
51
|
-
#nullifiedNotesByStorageSlot:
|
|
52
|
-
#nullifiedNotesByTxHash:
|
|
53
|
-
#nullifiedNotesByAddressPoint:
|
|
54
|
-
#nullifiedNotesByNullifier:
|
|
55
|
-
#
|
|
56
|
-
#
|
|
57
|
-
#
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
#
|
|
61
|
-
#
|
|
62
|
-
#
|
|
63
|
-
#
|
|
64
|
-
#
|
|
65
|
-
|
|
66
|
-
#scopes: AztecSet<string>;
|
|
67
|
-
#notesToScope: AztecMultiMap<string, string>;
|
|
68
|
-
#notesByContractAndScope: Map<string, AztecMultiMap<string, string>>;
|
|
69
|
-
#notesByStorageSlotAndScope: Map<string, AztecMultiMap<string, string>>;
|
|
70
|
-
#notesByTxHashAndScope: Map<string, AztecMultiMap<string, string>>;
|
|
71
|
-
#notesByAddressPointAndScope: Map<string, AztecMultiMap<string, string>>;
|
|
32
|
+
#synchronizedBlock: AztecAsyncSingleton<Buffer>;
|
|
33
|
+
#completeAddresses: AztecAsyncArray<Buffer>;
|
|
34
|
+
#completeAddressIndex: AztecAsyncMap<string, number>;
|
|
35
|
+
#addressBook: AztecAsyncSet<string>;
|
|
36
|
+
#authWitnesses: AztecAsyncMap<string, Buffer[]>;
|
|
37
|
+
#capsules: AztecAsyncArray<Buffer[]>;
|
|
38
|
+
#notes: AztecAsyncMap<string, Buffer>;
|
|
39
|
+
#nullifiedNotes: AztecAsyncMap<string, Buffer>;
|
|
40
|
+
#nullifierToNoteId: AztecAsyncMap<string, string>;
|
|
41
|
+
#nullifiersByBlockNumber: AztecAsyncMultiMap<number, string>;
|
|
42
|
+
|
|
43
|
+
#nullifiedNotesToScope: AztecAsyncMultiMap<string, string>;
|
|
44
|
+
#nullifiedNotesByContract: AztecAsyncMultiMap<string, string>;
|
|
45
|
+
#nullifiedNotesByStorageSlot: AztecAsyncMultiMap<string, string>;
|
|
46
|
+
#nullifiedNotesByTxHash: AztecAsyncMultiMap<string, string>;
|
|
47
|
+
#nullifiedNotesByAddressPoint: AztecAsyncMultiMap<string, string>;
|
|
48
|
+
#nullifiedNotesByNullifier: AztecAsyncMap<string, string>;
|
|
49
|
+
#contractArtifacts: AztecAsyncMap<string, Buffer>;
|
|
50
|
+
#contractInstances: AztecAsyncMap<string, Buffer>;
|
|
51
|
+
#db: AztecAsyncKVStore;
|
|
52
|
+
|
|
53
|
+
#scopes: AztecAsyncSet<string>;
|
|
54
|
+
#notesToScope: AztecAsyncMultiMap<string, string>;
|
|
55
|
+
#notesByContractAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
|
|
56
|
+
#notesByStorageSlotAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
|
|
57
|
+
#notesByTxHashAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
|
|
58
|
+
#notesByAddressPointAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
|
|
72
59
|
|
|
73
60
|
// Stores the last index used for each tagging secret, taking direction into account
|
|
74
61
|
// This is necessary to avoid reusing the same index for the same secret, which happens if
|
|
75
62
|
// sender and recipient are the same
|
|
76
|
-
#taggingSecretIndexesForSenders:
|
|
77
|
-
#taggingSecretIndexesForRecipients:
|
|
63
|
+
#taggingSecretIndexesForSenders: AztecAsyncMap<string, number>;
|
|
64
|
+
#taggingSecretIndexesForRecipients: AztecAsyncMap<string, number>;
|
|
78
65
|
|
|
79
|
-
constructor(private db:
|
|
66
|
+
protected constructor(private db: AztecAsyncKVStore) {
|
|
80
67
|
this.#db = db;
|
|
81
68
|
|
|
82
69
|
this.#completeAddresses = db.openArray('complete_addresses');
|
|
@@ -91,7 +78,6 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
91
78
|
this.#contractInstances = db.openMap('contracts_instances');
|
|
92
79
|
|
|
93
80
|
this.#synchronizedBlock = db.openSingleton('header');
|
|
94
|
-
this.#syncedBlockPerPublicKey = db.openMap('synced_block_per_public_key');
|
|
95
81
|
|
|
96
82
|
this.#notes = db.openMap('notes');
|
|
97
83
|
this.#nullifiedNotes = db.openMap('nullified_notes');
|
|
@@ -105,30 +91,28 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
105
91
|
this.#nullifiedNotesByAddressPoint = db.openMultiMap('nullified_notes_by_address_point');
|
|
106
92
|
this.#nullifiedNotesByNullifier = db.openMap('nullified_notes_by_nullifier');
|
|
107
93
|
|
|
108
|
-
this.#outgoingNotes = db.openMap('outgoing_notes');
|
|
109
|
-
this.#outgoingNotesByContract = db.openMultiMap('outgoing_notes_by_contract');
|
|
110
|
-
this.#outgoingNotesByStorageSlot = db.openMultiMap('outgoing_notes_by_storage_slot');
|
|
111
|
-
this.#outgoingNotesByTxHash = db.openMultiMap('outgoing_notes_by_tx_hash');
|
|
112
|
-
this.#outgoingNotesByOvpkM = db.openMultiMap('outgoing_notes_by_ovpk_m');
|
|
113
|
-
|
|
114
94
|
this.#scopes = db.openSet('scopes');
|
|
115
95
|
this.#notesToScope = db.openMultiMap('notes_to_scope');
|
|
116
|
-
this.#notesByContractAndScope = new Map<string,
|
|
117
|
-
this.#notesByStorageSlotAndScope = new Map<string,
|
|
118
|
-
this.#notesByTxHashAndScope = new Map<string,
|
|
119
|
-
this.#notesByAddressPointAndScope = new Map<string,
|
|
120
|
-
|
|
121
|
-
for (const scope of this.#scopes.entries()) {
|
|
122
|
-
this.#notesByContractAndScope.set(scope, db.openMultiMap(`${scope}:notes_by_contract`));
|
|
123
|
-
this.#notesByStorageSlotAndScope.set(scope, db.openMultiMap(`${scope}:notes_by_storage_slot`));
|
|
124
|
-
this.#notesByTxHashAndScope.set(scope, db.openMultiMap(`${scope}:notes_by_tx_hash`));
|
|
125
|
-
this.#notesByAddressPointAndScope.set(scope, db.openMultiMap(`${scope}:notes_by_address_point`));
|
|
126
|
-
}
|
|
96
|
+
this.#notesByContractAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
|
|
97
|
+
this.#notesByStorageSlotAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
|
|
98
|
+
this.#notesByTxHashAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
|
|
99
|
+
this.#notesByAddressPointAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
|
|
127
100
|
|
|
128
101
|
this.#taggingSecretIndexesForSenders = db.openMap('tagging_secret_indexes_for_senders');
|
|
129
102
|
this.#taggingSecretIndexesForRecipients = db.openMap('tagging_secret_indexes_for_recipients');
|
|
130
103
|
}
|
|
131
104
|
|
|
105
|
+
public static async create(db: AztecAsyncKVStore): Promise<KVPxeDatabase> {
|
|
106
|
+
const pxeDB = new KVPxeDatabase(db);
|
|
107
|
+
for await (const scope of pxeDB.#scopes.entriesAsync()) {
|
|
108
|
+
pxeDB.#notesByContractAndScope.set(scope, db.openMultiMap(`${scope}:notes_by_contract`));
|
|
109
|
+
pxeDB.#notesByStorageSlotAndScope.set(scope, db.openMultiMap(`${scope}:notes_by_storage_slot`));
|
|
110
|
+
pxeDB.#notesByTxHashAndScope.set(scope, db.openMultiMap(`${scope}:notes_by_tx_hash`));
|
|
111
|
+
pxeDB.#notesByAddressPointAndScope.set(scope, db.openMultiMap(`${scope}:notes_by_address_point`));
|
|
112
|
+
}
|
|
113
|
+
return pxeDB;
|
|
114
|
+
}
|
|
115
|
+
|
|
132
116
|
public async getContract(
|
|
133
117
|
address: AztecAddress,
|
|
134
118
|
): Promise<(ContractInstanceWithAddress & ContractArtifact) | undefined> {
|
|
@@ -157,10 +141,10 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
157
141
|
await this.#contractArtifacts.set(id.toString(), contractArtifactToBuffer(contract));
|
|
158
142
|
}
|
|
159
143
|
|
|
160
|
-
public getContractArtifact(id: Fr): Promise<ContractArtifact | undefined> {
|
|
161
|
-
const contract = this.#contractArtifacts.
|
|
162
|
-
// TODO(@spalladino):
|
|
163
|
-
return
|
|
144
|
+
public async getContractArtifact(id: Fr): Promise<ContractArtifact | undefined> {
|
|
145
|
+
const contract = await this.#contractArtifacts.getAsync(id.toString());
|
|
146
|
+
// TODO(@spalladino): AztecAsyncMap lies and returns Uint8Arrays instead of Buffers, hence the extra Buffer.from.
|
|
147
|
+
return contract && contractArtifactFromBuffer(Buffer.from(contract));
|
|
164
148
|
}
|
|
165
149
|
|
|
166
150
|
async addContractInstance(contract: ContractInstanceWithAddress): Promise<void> {
|
|
@@ -170,13 +154,14 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
170
154
|
);
|
|
171
155
|
}
|
|
172
156
|
|
|
173
|
-
getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
174
|
-
const contract = this.#contractInstances.
|
|
175
|
-
return
|
|
157
|
+
async getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
158
|
+
const contract = await this.#contractInstances.getAsync(address.toString());
|
|
159
|
+
return contract && SerializableContractInstance.fromBuffer(contract).withAddress(address);
|
|
176
160
|
}
|
|
177
161
|
|
|
178
|
-
getContractsAddresses(): Promise<AztecAddress[]> {
|
|
179
|
-
|
|
162
|
+
async getContractsAddresses(): Promise<AztecAddress[]> {
|
|
163
|
+
const keys = await toArray(this.#contractInstances.keysAsync());
|
|
164
|
+
return keys.map(AztecAddress.fromString);
|
|
180
165
|
}
|
|
181
166
|
|
|
182
167
|
async addAuthWitness(messageHash: Fr, witness: Fr[]): Promise<void> {
|
|
@@ -186,8 +171,8 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
186
171
|
);
|
|
187
172
|
}
|
|
188
173
|
|
|
189
|
-
getAuthWitness(messageHash: Fr): Promise<Fr[] | undefined> {
|
|
190
|
-
const witness = this.#authWitnesses.
|
|
174
|
+
async getAuthWitness(messageHash: Fr): Promise<Fr[] | undefined> {
|
|
175
|
+
const witness = await this.#authWitnesses.getAsync(messageHash.toString());
|
|
191
176
|
return Promise.resolve(witness?.map(w => Fr.fromBuffer(w)));
|
|
192
177
|
}
|
|
193
178
|
|
|
@@ -201,176 +186,164 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
201
186
|
}
|
|
202
187
|
|
|
203
188
|
async addNote(note: IncomingNoteDao, scope?: AztecAddress): Promise<void> {
|
|
204
|
-
await this.addNotes([note],
|
|
189
|
+
await this.addNotes([note], scope);
|
|
205
190
|
}
|
|
206
191
|
|
|
207
|
-
async addNotes(
|
|
208
|
-
|
|
209
|
-
outgoingNotes: OutgoingNoteDao[],
|
|
210
|
-
scope: AztecAddress = AztecAddress.ZERO,
|
|
211
|
-
): Promise<void> {
|
|
212
|
-
if (!this.#scopes.has(scope.toString())) {
|
|
192
|
+
async addNotes(incomingNotes: IncomingNoteDao[], scope: AztecAddress = AztecAddress.ZERO): Promise<void> {
|
|
193
|
+
if (!(await this.#scopes.hasAsync(scope.toString()))) {
|
|
213
194
|
await this.#addScope(scope);
|
|
214
195
|
}
|
|
215
196
|
|
|
216
|
-
return this.db.
|
|
197
|
+
return this.db.transactionAsync(async () => {
|
|
217
198
|
for (const dao of incomingNotes) {
|
|
218
199
|
// store notes by their index in the notes hash tree
|
|
219
200
|
// this provides the uniqueness we need to store individual notes
|
|
220
201
|
// and should also return notes in the order that they were created.
|
|
221
202
|
// Had we stored them by their nullifier, they would be returned in random order
|
|
222
203
|
const noteIndex = toBufferBE(dao.index, 32).toString('hex');
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
for (const dao of outgoingNotes) {
|
|
234
|
-
const noteIndex = toBufferBE(dao.index, 32).toString('hex');
|
|
235
|
-
void this.#outgoingNotes.set(noteIndex, dao.toBuffer());
|
|
236
|
-
void this.#outgoingNotesByContract.set(dao.contractAddress.toString(), noteIndex);
|
|
237
|
-
void this.#outgoingNotesByStorageSlot.set(dao.storageSlot.toString(), noteIndex);
|
|
238
|
-
void this.#outgoingNotesByTxHash.set(dao.txHash.toString(), noteIndex);
|
|
239
|
-
void this.#outgoingNotesByOvpkM.set(dao.ovpkM.toString(), noteIndex);
|
|
204
|
+
await this.#notes.set(noteIndex, dao.toBuffer());
|
|
205
|
+
await this.#notesToScope.set(noteIndex, scope.toString());
|
|
206
|
+
await this.#nullifierToNoteId.set(dao.siloedNullifier.toString(), noteIndex);
|
|
207
|
+
|
|
208
|
+
await this.#notesByContractAndScope.get(scope.toString())!.set(dao.contractAddress.toString(), noteIndex);
|
|
209
|
+
await this.#notesByStorageSlotAndScope.get(scope.toString())!.set(dao.storageSlot.toString(), noteIndex);
|
|
210
|
+
await this.#notesByTxHashAndScope.get(scope.toString())!.set(dao.txHash.toString(), noteIndex);
|
|
211
|
+
await this.#notesByAddressPointAndScope.get(scope.toString())!.set(dao.addressPoint.toString(), noteIndex);
|
|
240
212
|
}
|
|
241
213
|
});
|
|
242
214
|
}
|
|
243
215
|
|
|
244
216
|
public removeNotesAfter(blockNumber: number): Promise<void> {
|
|
245
|
-
return this.db.
|
|
246
|
-
|
|
217
|
+
return this.db.transactionAsync(async () => {
|
|
218
|
+
const notes = await toArray(this.#notes.valuesAsync());
|
|
219
|
+
for (const note of notes) {
|
|
247
220
|
const noteDao = IncomingNoteDao.fromBuffer(note);
|
|
248
221
|
if (noteDao.l2BlockNumber > blockNumber) {
|
|
249
222
|
const noteIndex = toBufferBE(noteDao.index, 32).toString('hex');
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
223
|
+
await this.#notes.delete(noteIndex);
|
|
224
|
+
await this.#notesToScope.delete(noteIndex);
|
|
225
|
+
await this.#nullifierToNoteId.delete(noteDao.siloedNullifier.toString());
|
|
226
|
+
const scopes = await toArray(this.#scopes.entriesAsync());
|
|
227
|
+
for (const scope of scopes) {
|
|
228
|
+
await this.#notesByAddressPointAndScope.get(scope)!.deleteValue(noteDao.addressPoint.toString(), noteIndex);
|
|
229
|
+
await this.#notesByTxHashAndScope.get(scope)!.deleteValue(noteDao.txHash.toString(), noteIndex);
|
|
230
|
+
await this.#notesByContractAndScope.get(scope)!.deleteValue(noteDao.contractAddress.toString(), noteIndex);
|
|
231
|
+
await this.#notesByStorageSlotAndScope.get(scope)!.deleteValue(noteDao.storageSlot.toString(), noteIndex);
|
|
258
232
|
}
|
|
259
233
|
}
|
|
260
234
|
}
|
|
261
|
-
|
|
262
|
-
for (const note of this.#outgoingNotes.values()) {
|
|
263
|
-
const noteDao = OutgoingNoteDao.fromBuffer(note);
|
|
264
|
-
if (noteDao.l2BlockNumber > blockNumber) {
|
|
265
|
-
const noteIndex = toBufferBE(noteDao.index, 32).toString('hex');
|
|
266
|
-
void this.#outgoingNotes.delete(noteIndex);
|
|
267
|
-
void this.#outgoingNotesByContract.deleteValue(noteDao.contractAddress.toString(), noteIndex);
|
|
268
|
-
void this.#outgoingNotesByStorageSlot.deleteValue(noteDao.storageSlot.toString(), noteIndex);
|
|
269
|
-
void this.#outgoingNotesByTxHash.deleteValue(noteDao.txHash.toString(), noteIndex);
|
|
270
|
-
void this.#outgoingNotesByOvpkM.deleteValue(noteDao.ovpkM.toString(), noteIndex);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
235
|
});
|
|
274
236
|
}
|
|
275
237
|
|
|
276
238
|
public async unnullifyNotesAfter(blockNumber: number): Promise<void> {
|
|
277
239
|
const nullifiersToUndo: string[] = [];
|
|
278
240
|
const currentBlockNumber = blockNumber + 1;
|
|
279
|
-
const maxBlockNumber = this.getBlockNumber() ?? currentBlockNumber;
|
|
241
|
+
const maxBlockNumber = (await this.getBlockNumber()) ?? currentBlockNumber;
|
|
280
242
|
for (let i = currentBlockNumber; i <= maxBlockNumber; i++) {
|
|
281
|
-
nullifiersToUndo.push(...this.#nullifiersByBlockNumber.
|
|
243
|
+
nullifiersToUndo.push(...(await toArray(this.#nullifiersByBlockNumber.getValuesAsync(i))));
|
|
282
244
|
}
|
|
283
245
|
|
|
284
|
-
const notesIndexesToReinsert = await
|
|
285
|
-
nullifiersToUndo.map(nullifier => this.#nullifiedNotesByNullifier.
|
|
246
|
+
const notesIndexesToReinsert = await Promise.all(
|
|
247
|
+
nullifiersToUndo.map(nullifier => this.#nullifiedNotesByNullifier.getAsync(nullifier)),
|
|
248
|
+
);
|
|
249
|
+
const notNullNoteIndexes = notesIndexesToReinsert.filter(noteIndex => noteIndex != undefined);
|
|
250
|
+
const nullifiedNoteBuffers = await Promise.all(
|
|
251
|
+
notNullNoteIndexes.map(noteIndex => this.#nullifiedNotes.getAsync(noteIndex!)),
|
|
286
252
|
);
|
|
287
|
-
const nullifiedNoteBuffers = await this.db.transaction(() => {
|
|
288
|
-
return notesIndexesToReinsert
|
|
289
|
-
.filter(noteIndex => noteIndex != undefined)
|
|
290
|
-
.map(noteIndex => this.#nullifiedNotes.get(noteIndex!));
|
|
291
|
-
});
|
|
292
253
|
const noteDaos = nullifiedNoteBuffers
|
|
293
254
|
.filter(buffer => buffer != undefined)
|
|
294
255
|
.map(buffer => IncomingNoteDao.fromBuffer(buffer!));
|
|
295
256
|
|
|
296
|
-
await this.db.
|
|
257
|
+
await this.db.transactionAsync(async () => {
|
|
297
258
|
for (const dao of noteDaos) {
|
|
298
259
|
const noteIndex = toBufferBE(dao.index, 32).toString('hex');
|
|
299
|
-
|
|
300
|
-
|
|
260
|
+
await this.#notes.set(noteIndex, dao.toBuffer());
|
|
261
|
+
await this.#nullifierToNoteId.set(dao.siloedNullifier.toString(), noteIndex);
|
|
301
262
|
|
|
302
|
-
let scopes =
|
|
263
|
+
let scopes = (await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteIndex))) ?? [];
|
|
303
264
|
|
|
304
265
|
if (scopes.length === 0) {
|
|
305
266
|
scopes = [new AztecAddress(dao.addressPoint.x).toString()];
|
|
306
267
|
}
|
|
307
268
|
|
|
308
269
|
for (const scope of scopes) {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
270
|
+
await this.#notesByContractAndScope.get(scope.toString())!.set(dao.contractAddress.toString(), noteIndex);
|
|
271
|
+
await this.#notesByStorageSlotAndScope.get(scope.toString())!.set(dao.storageSlot.toString(), noteIndex);
|
|
272
|
+
await this.#notesByTxHashAndScope.get(scope.toString())!.set(dao.txHash.toString(), noteIndex);
|
|
273
|
+
await this.#notesByAddressPointAndScope.get(scope.toString())!.set(dao.addressPoint.toString(), noteIndex);
|
|
274
|
+
await this.#notesToScope.set(noteIndex, scope);
|
|
314
275
|
}
|
|
315
276
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
277
|
+
await this.#nullifiedNotes.delete(noteIndex);
|
|
278
|
+
await this.#nullifiedNotesToScope.delete(noteIndex);
|
|
279
|
+
await this.#nullifiersByBlockNumber.deleteValue(dao.l2BlockNumber, dao.siloedNullifier.toString());
|
|
280
|
+
await this.#nullifiedNotesByContract.deleteValue(dao.contractAddress.toString(), noteIndex);
|
|
281
|
+
await this.#nullifiedNotesByStorageSlot.deleteValue(dao.storageSlot.toString(), noteIndex);
|
|
282
|
+
await this.#nullifiedNotesByTxHash.deleteValue(dao.txHash.toString(), noteIndex);
|
|
283
|
+
await this.#nullifiedNotesByAddressPoint.deleteValue(dao.addressPoint.toString(), noteIndex);
|
|
284
|
+
await this.#nullifiedNotesByNullifier.delete(dao.siloedNullifier.toString());
|
|
324
285
|
}
|
|
325
286
|
});
|
|
326
287
|
}
|
|
327
288
|
|
|
328
|
-
getIncomingNotes(filter: IncomingNotesFilter): Promise<IncomingNoteDao[]> {
|
|
289
|
+
async getIncomingNotes(filter: IncomingNotesFilter): Promise<IncomingNoteDao[]> {
|
|
329
290
|
const publicKey: PublicKey | undefined = filter.owner ? filter.owner.toAddressPoint() : undefined;
|
|
330
291
|
|
|
331
292
|
filter.status = filter.status ?? NoteStatus.ACTIVE;
|
|
332
293
|
|
|
333
294
|
const candidateNoteSources = [];
|
|
334
295
|
|
|
335
|
-
filter.scopes ??=
|
|
296
|
+
filter.scopes ??= (await toArray(this.#scopes.entriesAsync())).map(addressString =>
|
|
297
|
+
AztecAddress.fromString(addressString),
|
|
298
|
+
);
|
|
336
299
|
|
|
337
|
-
const activeNoteIdsPerScope:
|
|
300
|
+
const activeNoteIdsPerScope: string[][] = [];
|
|
338
301
|
|
|
339
302
|
for (const scope of new Set(filter.scopes)) {
|
|
340
303
|
const formattedScopeString = scope.toString();
|
|
341
|
-
if (!this.#scopes.
|
|
304
|
+
if (!this.#scopes.hasAsync(formattedScopeString)) {
|
|
342
305
|
throw new Error('Trying to get incoming notes of an scope that is not in the PXE database');
|
|
343
306
|
}
|
|
344
307
|
|
|
345
308
|
activeNoteIdsPerScope.push(
|
|
346
309
|
publicKey
|
|
347
|
-
?
|
|
310
|
+
? await toArray(
|
|
311
|
+
this.#notesByAddressPointAndScope.get(formattedScopeString)!.getValuesAsync(publicKey.toString()),
|
|
312
|
+
)
|
|
348
313
|
: filter.txHash
|
|
349
|
-
?
|
|
314
|
+
? await toArray(
|
|
315
|
+
this.#notesByTxHashAndScope.get(formattedScopeString)!.getValuesAsync(filter.txHash.toString()),
|
|
316
|
+
)
|
|
350
317
|
: filter.contractAddress
|
|
351
|
-
?
|
|
318
|
+
? await toArray(
|
|
319
|
+
this.#notesByContractAndScope
|
|
320
|
+
.get(formattedScopeString)!
|
|
321
|
+
.getValuesAsync(filter.contractAddress.toString()),
|
|
322
|
+
)
|
|
352
323
|
: filter.storageSlot
|
|
353
|
-
?
|
|
354
|
-
|
|
324
|
+
? await toArray(
|
|
325
|
+
this.#notesByStorageSlotAndScope.get(formattedScopeString)!.getValuesAsync(filter.storageSlot.toString()),
|
|
326
|
+
)
|
|
327
|
+
: await toArray(this.#notesByAddressPointAndScope.get(formattedScopeString)!.valuesAsync()),
|
|
355
328
|
);
|
|
356
329
|
}
|
|
357
330
|
|
|
358
331
|
candidateNoteSources.push({
|
|
359
|
-
ids: new Set(activeNoteIdsPerScope.
|
|
332
|
+
ids: new Set(activeNoteIdsPerScope.flat()),
|
|
360
333
|
notes: this.#notes,
|
|
361
334
|
});
|
|
362
335
|
|
|
363
336
|
if (filter.status == NoteStatus.ACTIVE_OR_NULLIFIED) {
|
|
364
337
|
candidateNoteSources.push({
|
|
365
338
|
ids: publicKey
|
|
366
|
-
? this.#nullifiedNotesByAddressPoint.
|
|
339
|
+
? await toArray(this.#nullifiedNotesByAddressPoint.getValuesAsync(publicKey.toString()))
|
|
367
340
|
: filter.txHash
|
|
368
|
-
? this.#nullifiedNotesByTxHash.
|
|
341
|
+
? await toArray(this.#nullifiedNotesByTxHash.getValuesAsync(filter.txHash.toString()))
|
|
369
342
|
: filter.contractAddress
|
|
370
|
-
? this.#nullifiedNotesByContract.
|
|
343
|
+
? await toArray(this.#nullifiedNotesByContract.getValuesAsync(filter.contractAddress.toString()))
|
|
371
344
|
: filter.storageSlot
|
|
372
|
-
? this.#nullifiedNotesByStorageSlot.
|
|
373
|
-
: this.#nullifiedNotes.
|
|
345
|
+
? await toArray(this.#nullifiedNotesByStorageSlot.getValuesAsync(filter.storageSlot.toString()))
|
|
346
|
+
: await toArray(this.#nullifiedNotes.keysAsync()),
|
|
374
347
|
notes: this.#nullifiedNotes,
|
|
375
348
|
});
|
|
376
349
|
}
|
|
@@ -378,7 +351,7 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
378
351
|
const result: IncomingNoteDao[] = [];
|
|
379
352
|
for (const { ids, notes } of candidateNoteSources) {
|
|
380
353
|
for (const id of ids) {
|
|
381
|
-
const serializedNote = notes.
|
|
354
|
+
const serializedNote = await notes.getAsync(id);
|
|
382
355
|
if (!serializedNote) {
|
|
383
356
|
continue;
|
|
384
357
|
}
|
|
@@ -408,57 +381,7 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
408
381
|
}
|
|
409
382
|
}
|
|
410
383
|
|
|
411
|
-
return
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
getOutgoingNotes(filter: OutgoingNotesFilter): Promise<OutgoingNoteDao[]> {
|
|
415
|
-
const ovpkM: PublicKey | undefined = filter.owner
|
|
416
|
-
? this.#getCompleteAddress(filter.owner)?.publicKeys.masterOutgoingViewingPublicKey
|
|
417
|
-
: undefined;
|
|
418
|
-
|
|
419
|
-
// Check if ovpkM is truthy
|
|
420
|
-
const ids = ovpkM
|
|
421
|
-
? this.#outgoingNotesByOvpkM.getValues(ovpkM.toString())
|
|
422
|
-
: // If ovpkM is falsy, check if filter.txHash is truthy
|
|
423
|
-
filter.txHash
|
|
424
|
-
? this.#outgoingNotesByTxHash.getValues(filter.txHash.toString())
|
|
425
|
-
: // If both ovpkM and filter.txHash are falsy, check if filter.contractAddress is truthy
|
|
426
|
-
filter.contractAddress
|
|
427
|
-
? this.#outgoingNotesByContract.getValues(filter.contractAddress.toString())
|
|
428
|
-
: // If ovpkM, filter.txHash, and filter.contractAddress are all falsy, check if filter.storageSlot is truthy
|
|
429
|
-
filter.storageSlot
|
|
430
|
-
? this.#outgoingNotesByStorageSlot.getValues(filter.storageSlot.toString())
|
|
431
|
-
: // If none of the above conditions are met, retrieve all keys from this.#outgoingNotes
|
|
432
|
-
this.#outgoingNotes.keys();
|
|
433
|
-
|
|
434
|
-
const notes: OutgoingNoteDao[] = [];
|
|
435
|
-
for (const id of ids) {
|
|
436
|
-
const serializedNote = this.#outgoingNotes.get(id);
|
|
437
|
-
if (!serializedNote) {
|
|
438
|
-
continue;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
const note = OutgoingNoteDao.fromBuffer(serializedNote);
|
|
442
|
-
if (filter.contractAddress && !note.contractAddress.equals(filter.contractAddress)) {
|
|
443
|
-
continue;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
if (filter.txHash && !note.txHash.equals(filter.txHash)) {
|
|
447
|
-
continue;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
if (filter.storageSlot && !note.storageSlot.equals(filter.storageSlot!)) {
|
|
451
|
-
continue;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
if (ovpkM && !note.ovpkM.equals(ovpkM)) {
|
|
455
|
-
continue;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
notes.push(note);
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
return Promise.resolve(notes);
|
|
384
|
+
return result;
|
|
462
385
|
}
|
|
463
386
|
|
|
464
387
|
removeNullifiedNotes(nullifiers: InBlock<Fr>[], accountAddressPoint: PublicKey): Promise<IncomingNoteDao[]> {
|
|
@@ -466,23 +389,23 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
466
389
|
return Promise.resolve([]);
|
|
467
390
|
}
|
|
468
391
|
|
|
469
|
-
return this
|
|
392
|
+
return this.db.transactionAsync(async () => {
|
|
470
393
|
const nullifiedNotes: IncomingNoteDao[] = [];
|
|
471
394
|
|
|
472
395
|
for (const blockScopedNullifier of nullifiers) {
|
|
473
396
|
const { data: nullifier, l2BlockNumber: blockNumber } = blockScopedNullifier;
|
|
474
|
-
const noteIndex = this.#nullifierToNoteId.
|
|
397
|
+
const noteIndex = await this.#nullifierToNoteId.getAsync(nullifier.toString());
|
|
475
398
|
if (!noteIndex) {
|
|
476
399
|
continue;
|
|
477
400
|
}
|
|
478
401
|
|
|
479
|
-
const noteBuffer = noteIndex ? this.#notes.
|
|
402
|
+
const noteBuffer = noteIndex ? await this.#notes.getAsync(noteIndex) : undefined;
|
|
480
403
|
|
|
481
404
|
if (!noteBuffer) {
|
|
482
405
|
// note doesn't exist. Maybe it got nullified already
|
|
483
406
|
continue;
|
|
484
407
|
}
|
|
485
|
-
const noteScopes = this.#notesToScope.
|
|
408
|
+
const noteScopes = (await toArray(this.#notesToScope.getValuesAsync(noteIndex))) ?? [];
|
|
486
409
|
const note = IncomingNoteDao.fromBuffer(noteBuffer);
|
|
487
410
|
if (!note.addressPoint.equals(accountAddressPoint)) {
|
|
488
411
|
// tried to nullify someone else's note
|
|
@@ -491,32 +414,33 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
491
414
|
|
|
492
415
|
nullifiedNotes.push(note);
|
|
493
416
|
|
|
494
|
-
|
|
495
|
-
|
|
417
|
+
await this.#notes.delete(noteIndex);
|
|
418
|
+
await this.#notesToScope.delete(noteIndex);
|
|
496
419
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
420
|
+
const scopes = await toArray(this.#scopes.entriesAsync());
|
|
421
|
+
|
|
422
|
+
for (const scope of scopes) {
|
|
423
|
+
await this.#notesByAddressPointAndScope.get(scope)!.deleteValue(accountAddressPoint.toString(), noteIndex);
|
|
424
|
+
await this.#notesByTxHashAndScope.get(scope)!.deleteValue(note.txHash.toString(), noteIndex);
|
|
425
|
+
await this.#notesByContractAndScope.get(scope)!.deleteValue(note.contractAddress.toString(), noteIndex);
|
|
426
|
+
await this.#notesByStorageSlotAndScope.get(scope)!.deleteValue(note.storageSlot.toString(), noteIndex);
|
|
502
427
|
}
|
|
503
428
|
|
|
504
429
|
if (noteScopes !== undefined) {
|
|
505
430
|
for (const scope of noteScopes) {
|
|
506
|
-
|
|
431
|
+
await this.#nullifiedNotesToScope.set(noteIndex, scope);
|
|
507
432
|
}
|
|
508
433
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
434
|
+
await this.#nullifiedNotes.set(noteIndex, note.toBuffer());
|
|
435
|
+
await this.#nullifiersByBlockNumber.set(blockNumber, nullifier.toString());
|
|
436
|
+
await this.#nullifiedNotesByContract.set(note.contractAddress.toString(), noteIndex);
|
|
437
|
+
await this.#nullifiedNotesByStorageSlot.set(note.storageSlot.toString(), noteIndex);
|
|
438
|
+
await this.#nullifiedNotesByTxHash.set(note.txHash.toString(), noteIndex);
|
|
439
|
+
await this.#nullifiedNotesByAddressPoint.set(note.addressPoint.toString(), noteIndex);
|
|
440
|
+
await this.#nullifiedNotesByNullifier.set(nullifier.toString(), noteIndex);
|
|
441
|
+
|
|
442
|
+
await this.#nullifierToNoteId.delete(nullifier.toString());
|
|
518
443
|
}
|
|
519
|
-
|
|
520
444
|
return nullifiedNotes;
|
|
521
445
|
});
|
|
522
446
|
}
|
|
@@ -529,36 +453,34 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
529
453
|
await this.#nullifiedNotesByStorageSlot.set(note.storageSlot.toString(), noteIndex);
|
|
530
454
|
await this.#nullifiedNotesByTxHash.set(note.txHash.toString(), noteIndex);
|
|
531
455
|
await this.#nullifiedNotesByAddressPoint.set(note.addressPoint.toString(), noteIndex);
|
|
532
|
-
|
|
533
|
-
return Promise.resolve();
|
|
534
456
|
}
|
|
535
457
|
|
|
536
|
-
async setHeader(header:
|
|
458
|
+
async setHeader(header: BlockHeader): Promise<void> {
|
|
537
459
|
await this.#synchronizedBlock.set(header.toBuffer());
|
|
538
460
|
}
|
|
539
461
|
|
|
540
|
-
getBlockNumber(): number | undefined {
|
|
541
|
-
const headerBuffer = this.#synchronizedBlock.
|
|
462
|
+
async getBlockNumber(): Promise<number | undefined> {
|
|
463
|
+
const headerBuffer = await this.#synchronizedBlock.getAsync();
|
|
542
464
|
if (!headerBuffer) {
|
|
543
465
|
return undefined;
|
|
544
466
|
}
|
|
545
467
|
|
|
546
|
-
return Number(
|
|
468
|
+
return Number(BlockHeader.fromBuffer(headerBuffer).globalVariables.blockNumber.toBigInt());
|
|
547
469
|
}
|
|
548
470
|
|
|
549
|
-
|
|
550
|
-
const headerBuffer = this.#synchronizedBlock.
|
|
471
|
+
async getBlockHeader(): Promise<BlockHeader> {
|
|
472
|
+
const headerBuffer = await this.#synchronizedBlock.getAsync();
|
|
551
473
|
if (!headerBuffer) {
|
|
552
474
|
throw new Error(`Header not set`);
|
|
553
475
|
}
|
|
554
476
|
|
|
555
|
-
return
|
|
477
|
+
return BlockHeader.fromBuffer(headerBuffer);
|
|
556
478
|
}
|
|
557
479
|
|
|
558
480
|
async #addScope(scope: AztecAddress): Promise<boolean> {
|
|
559
481
|
const scopeString = scope.toString();
|
|
560
482
|
|
|
561
|
-
if (this.#scopes.
|
|
483
|
+
if (await this.#scopes.hasAsync(scopeString)) {
|
|
562
484
|
return false;
|
|
563
485
|
}
|
|
564
486
|
|
|
@@ -571,23 +493,23 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
571
493
|
return true;
|
|
572
494
|
}
|
|
573
495
|
|
|
574
|
-
|
|
575
|
-
|
|
496
|
+
addCompleteAddress(completeAddress: CompleteAddress): Promise<boolean> {
|
|
497
|
+
return this.db.transactionAsync(async () => {
|
|
498
|
+
await this.#addScope(completeAddress.address);
|
|
576
499
|
|
|
577
|
-
return this.#db.transaction(() => {
|
|
578
500
|
const addressString = completeAddress.address.toString();
|
|
579
501
|
const buffer = completeAddress.toBuffer();
|
|
580
|
-
const existing = this.#completeAddressIndex.
|
|
581
|
-
if (
|
|
582
|
-
const index = this.#completeAddresses.
|
|
583
|
-
|
|
584
|
-
|
|
502
|
+
const existing = await this.#completeAddressIndex.getAsync(addressString);
|
|
503
|
+
if (existing === undefined) {
|
|
504
|
+
const index = await this.#completeAddresses.lengthAsync();
|
|
505
|
+
await this.#completeAddresses.push(buffer);
|
|
506
|
+
await this.#completeAddressIndex.set(addressString, index);
|
|
585
507
|
|
|
586
508
|
return true;
|
|
587
509
|
} else {
|
|
588
|
-
const existingBuffer = this.#completeAddresses.
|
|
510
|
+
const existingBuffer = await this.#completeAddresses.atAsync(existing);
|
|
589
511
|
|
|
590
|
-
if (existingBuffer
|
|
512
|
+
if (existingBuffer && Buffer.from(existingBuffer).equals(buffer)) {
|
|
591
513
|
return false;
|
|
592
514
|
}
|
|
593
515
|
|
|
@@ -598,26 +520,26 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
598
520
|
});
|
|
599
521
|
}
|
|
600
522
|
|
|
601
|
-
#getCompleteAddress(address: AztecAddress): CompleteAddress | undefined {
|
|
602
|
-
const index = this.#completeAddressIndex.
|
|
603
|
-
if (
|
|
523
|
+
async #getCompleteAddress(address: AztecAddress): Promise<CompleteAddress | undefined> {
|
|
524
|
+
const index = await this.#completeAddressIndex.getAsync(address.toString());
|
|
525
|
+
if (index === undefined) {
|
|
604
526
|
return undefined;
|
|
605
527
|
}
|
|
606
528
|
|
|
607
|
-
const value = this.#completeAddresses.
|
|
529
|
+
const value = await this.#completeAddresses.atAsync(index);
|
|
608
530
|
return value ? CompleteAddress.fromBuffer(value) : undefined;
|
|
609
531
|
}
|
|
610
532
|
|
|
611
533
|
getCompleteAddress(account: AztecAddress): Promise<CompleteAddress | undefined> {
|
|
612
|
-
return
|
|
534
|
+
return this.#getCompleteAddress(account);
|
|
613
535
|
}
|
|
614
536
|
|
|
615
|
-
getCompleteAddresses(): Promise<CompleteAddress[]> {
|
|
616
|
-
return
|
|
537
|
+
async getCompleteAddresses(): Promise<CompleteAddress[]> {
|
|
538
|
+
return (await toArray(this.#completeAddresses.valuesAsync())).map(v => CompleteAddress.fromBuffer(v));
|
|
617
539
|
}
|
|
618
540
|
|
|
619
541
|
async addContactAddress(address: AztecAddress): Promise<boolean> {
|
|
620
|
-
if (this.#addressBook.
|
|
542
|
+
if (await this.#addressBook.hasAsync(address.toString())) {
|
|
621
543
|
return false;
|
|
622
544
|
}
|
|
623
545
|
|
|
@@ -626,12 +548,12 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
626
548
|
return true;
|
|
627
549
|
}
|
|
628
550
|
|
|
629
|
-
getContactAddresses(): AztecAddress[] {
|
|
630
|
-
return
|
|
551
|
+
async getContactAddresses(): Promise<AztecAddress[]> {
|
|
552
|
+
return (await toArray(this.#addressBook.entriesAsync())).map(AztecAddress.fromString);
|
|
631
553
|
}
|
|
632
554
|
|
|
633
555
|
async removeContactAddress(address: AztecAddress): Promise<boolean> {
|
|
634
|
-
if (!this.#addressBook.
|
|
556
|
+
if (!this.#addressBook.hasAsync(address.toString())) {
|
|
635
557
|
return false;
|
|
636
558
|
}
|
|
637
559
|
|
|
@@ -640,32 +562,17 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
640
562
|
return true;
|
|
641
563
|
}
|
|
642
564
|
|
|
643
|
-
getSynchedBlockNumberForAccount(account: AztecAddress): number | undefined {
|
|
644
|
-
return this.#syncedBlockPerPublicKey.get(account.toString());
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
setSynchedBlockNumberForAccount(account: AztecAddress, blockNumber: number): Promise<void> {
|
|
648
|
-
return this.#syncedBlockPerPublicKey.set(account.toString(), blockNumber);
|
|
649
|
-
}
|
|
650
|
-
|
|
651
565
|
async estimateSize(): Promise<number> {
|
|
652
|
-
const incomingNotesSize =
|
|
653
|
-
(sum, note) => sum + note.getSize(),
|
|
654
|
-
0,
|
|
655
|
-
);
|
|
656
|
-
const outgoingNotesSize = Array.from(await this.getOutgoingNotes({})).reduce(
|
|
657
|
-
(sum, note) => sum + note.getSize(),
|
|
658
|
-
0,
|
|
659
|
-
);
|
|
566
|
+
const incomingNotesSize = (await this.getIncomingNotes({})).reduce((sum, note) => sum + note.getSize(), 0);
|
|
660
567
|
|
|
661
|
-
const authWitsSize =
|
|
568
|
+
const authWitsSize = (await toArray(this.#authWitnesses.valuesAsync())).reduce(
|
|
662
569
|
(sum, value) => sum + value.length * Fr.SIZE_IN_BYTES,
|
|
663
570
|
0,
|
|
664
571
|
);
|
|
665
|
-
const addressesSize = this.#completeAddresses.
|
|
572
|
+
const addressesSize = (await this.#completeAddresses.lengthAsync()) * CompleteAddress.SIZE_IN_BYTES;
|
|
666
573
|
const treeRootsSize = Object.keys(MerkleTreeId).length * Fr.SIZE_IN_BYTES;
|
|
667
574
|
|
|
668
|
-
return incomingNotesSize +
|
|
575
|
+
return incomingNotesSize + treeRootsSize + authWitsSize + addressesSize;
|
|
669
576
|
}
|
|
670
577
|
|
|
671
578
|
async setTaggingSecretsIndexesAsSender(indexedSecrets: IndexedTaggingSecret[]): Promise<void> {
|
|
@@ -676,12 +583,12 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
676
583
|
await this.#setTaggingSecretsIndexes(indexedSecrets, this.#taggingSecretIndexesForRecipients);
|
|
677
584
|
}
|
|
678
585
|
|
|
679
|
-
#setTaggingSecretsIndexes(indexedSecrets: IndexedTaggingSecret[], storageMap:
|
|
680
|
-
|
|
681
|
-
indexedSecrets.
|
|
682
|
-
|
|
683
|
-
)
|
|
684
|
-
|
|
586
|
+
async #setTaggingSecretsIndexes(indexedSecrets: IndexedTaggingSecret[], storageMap: AztecAsyncMap<string, number>) {
|
|
587
|
+
await Promise.all(
|
|
588
|
+
indexedSecrets.map(indexedSecret =>
|
|
589
|
+
storageMap.set(indexedSecret.appTaggingSecret.toString(), indexedSecret.index),
|
|
590
|
+
),
|
|
591
|
+
);
|
|
685
592
|
}
|
|
686
593
|
|
|
687
594
|
async getTaggingSecretsIndexesAsRecipient(appTaggingSecrets: Fr[]) {
|
|
@@ -692,18 +599,16 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
692
599
|
return await this.#getTaggingSecretsIndexes(appTaggingSecrets, this.#taggingSecretIndexesForSenders);
|
|
693
600
|
}
|
|
694
601
|
|
|
695
|
-
#getTaggingSecretsIndexes(appTaggingSecrets: Fr[], storageMap:
|
|
696
|
-
return
|
|
602
|
+
#getTaggingSecretsIndexes(appTaggingSecrets: Fr[], storageMap: AztecAsyncMap<string, number>): Promise<number[]> {
|
|
603
|
+
return Promise.all(appTaggingSecrets.map(async secret => (await storageMap.getAsync(`${secret.toString()}`)) ?? 0));
|
|
697
604
|
}
|
|
698
605
|
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
void this.#taggingSecretIndexesForSenders.delete(sender);
|
|
706
|
-
}
|
|
606
|
+
resetNoteSyncData(): Promise<void> {
|
|
607
|
+
return this.db.transactionAsync(async () => {
|
|
608
|
+
const recipients = await toArray(this.#taggingSecretIndexesForRecipients.keysAsync());
|
|
609
|
+
await Promise.all(recipients.map(recipient => this.#taggingSecretIndexesForRecipients.delete(recipient)));
|
|
610
|
+
const senders = await toArray(this.#taggingSecretIndexesForSenders.keysAsync());
|
|
611
|
+
await Promise.all(senders.map(sender => this.#taggingSecretIndexesForSenders.delete(sender)));
|
|
707
612
|
});
|
|
708
613
|
}
|
|
709
614
|
}
|