@aztec/pxe 0.0.1-commit.d1f2d6c → 0.0.1-commit.d431d1c
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 +4 -6
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +11 -51
- package/dest/config/index.d.ts +1 -3
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +0 -17
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +4 -1
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +4 -7
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +2 -4
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +9 -19
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +6 -5
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +1 -10
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +1 -9
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +5 -17
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +6 -14
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +33 -31
- package/dest/debug/pxe_debug_utils.d.ts +1 -1
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +1 -2
- package/dest/logs/log_service.d.ts +1 -1
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +11 -18
- package/dest/notes/note_service.d.ts +2 -3
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +6 -8
- package/dest/oracle_version.d.ts +3 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +3 -4
- package/dest/pxe.d.ts +1 -1
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +7 -10
- package/dest/storage/note_store/note_store.d.ts +55 -43
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +252 -238
- package/dest/storage/private_event_store/private_event_store.d.ts +4 -17
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +135 -163
- package/dest/tagging/index.d.ts +1 -2
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +0 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +2 -3
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +2 -2
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +2 -3
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +2 -5
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +2 -3
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +2 -2
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +8 -5
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +2 -3
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +4 -7
- package/dest/tree_membership/tree_membership_service.d.ts +50 -0
- package/dest/tree_membership/tree_membership_service.d.ts.map +1 -0
- package/dest/tree_membership/tree_membership_service.js +75 -0
- package/package.json +16 -16
- package/src/block_synchronizer/block_synchronizer.ts +14 -53
- package/src/config/index.ts +0 -14
- package/src/contract_function_simulator/contract_function_simulator.ts +9 -1
- package/src/contract_function_simulator/oracle/interfaces.ts +3 -12
- package/src/contract_function_simulator/oracle/oracle.ts +13 -26
- package/src/contract_function_simulator/oracle/private_execution.ts +1 -20
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +6 -33
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +38 -46
- package/src/debug/pxe_debug_utils.ts +1 -2
- package/src/logs/log_service.ts +8 -25
- package/src/notes/note_service.ts +11 -15
- package/src/oracle_version.ts +3 -4
- package/src/pxe.ts +8 -32
- package/src/storage/note_store/note_store.ts +313 -279
- package/src/storage/private_event_store/private_event_store.ts +175 -214
- package/src/tagging/index.ts +0 -1
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +1 -11
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +1 -7
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +1 -3
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +17 -5
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +3 -12
- package/src/tree_membership/tree_membership_service.ts +97 -0
- package/dest/storage/note_store/stored_note.d.ts +0 -16
- package/dest/storage/note_store/stored_note.d.ts.map +0 -1
- package/dest/storage/note_store/stored_note.js +0 -43
- package/dest/storage/private_event_store/stored_private_event.d.ts +0 -23
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +0 -1
- package/dest/storage/private_event_store/stored_private_event.js +0 -56
- package/dest/tagging/get_all_logs_by_tags.d.ts +0 -24
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +0 -1
- package/dest/tagging/get_all_logs_by_tags.js +0 -46
- package/src/storage/note_store/stored_note.ts +0 -48
- package/src/storage/private_event_store/stored_private_event.ts +0 -73
- package/src/tagging/get_all_logs_by_tags.ts +0 -68
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/constants';
|
|
2
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import type { SiblingPath } from '@aztec/foundation/trees';
|
|
4
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
6
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
7
|
+
import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
|
|
8
|
+
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
9
|
+
|
|
10
|
+
// TODO: REmove this class as it no longer seems valuable. The only somewhat real functionality in this class is in
|
|
11
|
+
// the `getMembershipWitness` method that is used by `utilityGetMembershipWitness` oracle by then in Aztec.nr we
|
|
12
|
+
// have helper functions around that oracle for archive and note hash tree and the generic method itself is not used
|
|
13
|
+
// anywhere else - make sense to just have simple specific handlers for the archive and note hash trees and drop this.
|
|
14
|
+
export class TreeMembershipService {
|
|
15
|
+
constructor(private readonly aztecNode: AztecNode) {}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Gets the index of a nullifier in the nullifier tree.
|
|
19
|
+
* @returns - The index of the nullifier. Undefined if it does not exist in the tree.
|
|
20
|
+
*/
|
|
21
|
+
public async getNullifierIndex(nullifier: Fr): Promise<bigint | undefined> {
|
|
22
|
+
const [leafIndex] = await this.aztecNode.findLeavesIndexes('latest', MerkleTreeId.NULLIFIER_TREE, [nullifier]);
|
|
23
|
+
return leafIndex?.data;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Fetches the index and sibling path of a leaf at a given block from a given tree.
|
|
28
|
+
* @param blockHash - The block hash at which to get the membership witness.
|
|
29
|
+
* @param treeId - Id of the tree to get the sibling path from.
|
|
30
|
+
* @param leafValue - The leaf value
|
|
31
|
+
* @returns The index and sibling path concatenated [index, sibling_path]
|
|
32
|
+
*/
|
|
33
|
+
public async getMembershipWitness(blockHash: L2BlockHash, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[]> {
|
|
34
|
+
const witness = await this.#tryGetMembershipWitness(blockHash, treeId, leafValue);
|
|
35
|
+
if (!witness) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`Leaf value ${leafValue} not found in tree ${MerkleTreeId[treeId]} at block hash ${blockHash.toString()}`,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return witness;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
45
|
+
* @param blockHash - The block hash at which to get the index.
|
|
46
|
+
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
47
|
+
* @returns The low nullifier membership witness (if found).
|
|
48
|
+
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
49
|
+
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
50
|
+
* we are trying to prove non-inclusion for.
|
|
51
|
+
*/
|
|
52
|
+
public getLowNullifierMembershipWitness(
|
|
53
|
+
blockHash: L2BlockHash,
|
|
54
|
+
nullifier: Fr,
|
|
55
|
+
): Promise<NullifierMembershipWitness | undefined> {
|
|
56
|
+
return this.aztecNode.getLowNullifierMembershipWitness(blockHash, nullifier);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Returns a witness for a given slot of the public data tree at a given block.
|
|
61
|
+
* @param blockHash - The block hash at which to get the witness.
|
|
62
|
+
* @param leafSlot - The slot of the public data in the public data tree.
|
|
63
|
+
*/
|
|
64
|
+
public getPublicDataWitness(blockHash: L2BlockHash, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
65
|
+
return this.aztecNode.getPublicDataWitness(blockHash, leafSlot);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Looks for the L1 to L2 membership witness of a message at the Aztec node, given its hash.
|
|
70
|
+
* @param contractAddress - Address of a contract by which the message was emitted.
|
|
71
|
+
* @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages.
|
|
72
|
+
* The message nullifier is computed locally, so the secret is not sent to the node.
|
|
73
|
+
* @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
|
|
74
|
+
*/
|
|
75
|
+
public getL1ToL2MembershipWitness(
|
|
76
|
+
contractAddress: AztecAddress,
|
|
77
|
+
messageHash: Fr,
|
|
78
|
+
secret: Fr,
|
|
79
|
+
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>]> {
|
|
80
|
+
return getNonNullifiedL1ToL2MessageWitness(this.aztecNode, contractAddress, messageHash, secret);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async #tryGetMembershipWitness(blockHash: L2BlockHash, treeId: MerkleTreeId, value: Fr): Promise<Fr[] | undefined> {
|
|
84
|
+
switch (treeId) {
|
|
85
|
+
case MerkleTreeId.NULLIFIER_TREE:
|
|
86
|
+
return (await this.aztecNode.getNullifierMembershipWitness(blockHash, value))?.withoutPreimage().toFields();
|
|
87
|
+
case MerkleTreeId.NOTE_HASH_TREE:
|
|
88
|
+
return (await this.aztecNode.getNoteHashMembershipWitness(blockHash, value))?.toFields();
|
|
89
|
+
case MerkleTreeId.PUBLIC_DATA_TREE:
|
|
90
|
+
return (await this.aztecNode.getPublicDataWitness(blockHash, value))?.withoutPreimage().toFields();
|
|
91
|
+
case MerkleTreeId.ARCHIVE:
|
|
92
|
+
return (await this.aztecNode.getArchiveMembershipWitness(blockHash, value))?.toFields();
|
|
93
|
+
default:
|
|
94
|
+
throw new Error('Not implemented');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { NoteDao } from '@aztec/stdlib/note';
|
|
3
|
-
export declare class StoredNote {
|
|
4
|
-
readonly noteDao: NoteDao;
|
|
5
|
-
readonly scopes: Set<string>;
|
|
6
|
-
private _nullifiedAt;
|
|
7
|
-
constructor(noteDao: NoteDao, scopes: Set<string>, _nullifiedAt?: BlockNumber | undefined);
|
|
8
|
-
static fromBuffer(buffer: Buffer): StoredNote;
|
|
9
|
-
toBuffer(): Buffer;
|
|
10
|
-
addScope(scope: string): void;
|
|
11
|
-
markAsNullified(blockNumber: BlockNumber): void;
|
|
12
|
-
markAsActive(): void;
|
|
13
|
-
isNullified(): boolean;
|
|
14
|
-
get nullifiedAt(): BlockNumber | undefined;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RvcmVkX25vdGUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zdG9yYWdlL25vdGVfc3RvcmUvc3RvcmVkX25vdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBRTlELE9BQU8sRUFBRSxPQUFPLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUU3QyxxQkFBYSxVQUFVO0lBRW5CLFFBQVEsQ0FBQyxPQUFPLEVBQUUsT0FBTztJQUN6QixRQUFRLENBQUMsTUFBTSxFQUFFLEdBQUcsQ0FBQyxNQUFNLENBQUM7SUFDNUIsT0FBTyxDQUFDLFlBQVk7SUFIdEIsWUFDVyxPQUFPLEVBQUUsT0FBTyxFQUNoQixNQUFNLEVBQUUsR0FBRyxDQUFDLE1BQU0sQ0FBQyxFQUNwQixZQUFZLEdBQUUsV0FBVyxHQUFHLFNBQXFCLEVBQ3ZEO0lBRUosTUFBTSxDQUFDLFVBQVUsQ0FBQyxNQUFNLEVBQUUsTUFBTSxjQVUvQjtJQUVELFFBQVEsSUFBSSxNQUFNLENBR2pCO0lBRUQsUUFBUSxDQUFDLEtBQUssRUFBRSxNQUFNLFFBRXJCO0lBRUQsZUFBZSxDQUFDLFdBQVcsRUFBRSxXQUFXLFFBRXZDO0lBRUQsWUFBWSxTQUVYO0lBRUQsV0FBVyxZQUVWO0lBRUQsSUFBSSxXQUFXLDRCQUVkO0NBQ0YifQ==
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stored_note.d.ts","sourceRoot":"","sources":["../../../src/storage/note_store/stored_note.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,qBAAa,UAAU;IAEnB,QAAQ,CAAC,OAAO,EAAE,OAAO;IACzB,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC;IAC5B,OAAO,CAAC,YAAY;IAHtB,YACW,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,EACpB,YAAY,GAAE,WAAW,GAAG,SAAqB,EACvD;IAEJ,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,cAU/B;IAED,QAAQ,IAAI,MAAM,CAGjB;IAED,QAAQ,CAAC,KAAK,EAAE,MAAM,QAErB;IAED,eAAe,CAAC,WAAW,EAAE,WAAW,QAEvC;IAED,YAAY,SAEX;IAED,WAAW,YAEV;IAED,IAAI,WAAW,4BAEd;CACF"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
2
|
-
import { NoteDao } from '@aztec/stdlib/note';
|
|
3
|
-
export class StoredNote {
|
|
4
|
-
noteDao;
|
|
5
|
-
scopes;
|
|
6
|
-
_nullifiedAt;
|
|
7
|
-
constructor(noteDao, scopes, _nullifiedAt = undefined){
|
|
8
|
-
this.noteDao = noteDao;
|
|
9
|
-
this.scopes = scopes;
|
|
10
|
-
this._nullifiedAt = _nullifiedAt;
|
|
11
|
-
}
|
|
12
|
-
static fromBuffer(buffer) {
|
|
13
|
-
const reader = BufferReader.asReader(buffer);
|
|
14
|
-
const noteDao = NoteDao.fromBuffer(reader);
|
|
15
|
-
const scopes = reader.readVector({
|
|
16
|
-
fromBuffer: (r)=>r.readString()
|
|
17
|
-
});
|
|
18
|
-
const nullifiedAtRaw = reader.readNumber();
|
|
19
|
-
const nullifiedAt = nullifiedAtRaw === 0 ? undefined : nullifiedAtRaw;
|
|
20
|
-
return new StoredNote(noteDao, new Set(scopes), nullifiedAt);
|
|
21
|
-
}
|
|
22
|
-
toBuffer() {
|
|
23
|
-
const scopesArray = [
|
|
24
|
-
...this.scopes
|
|
25
|
-
];
|
|
26
|
-
return serializeToBuffer(this.noteDao, scopesArray.length, ...scopesArray, this._nullifiedAt ?? 0);
|
|
27
|
-
}
|
|
28
|
-
addScope(scope) {
|
|
29
|
-
this.scopes.add(scope);
|
|
30
|
-
}
|
|
31
|
-
markAsNullified(blockNumber) {
|
|
32
|
-
this._nullifiedAt = blockNumber;
|
|
33
|
-
}
|
|
34
|
-
markAsActive() {
|
|
35
|
-
this._nullifiedAt = undefined;
|
|
36
|
-
}
|
|
37
|
-
isNullified() {
|
|
38
|
-
return this._nullifiedAt !== undefined;
|
|
39
|
-
}
|
|
40
|
-
get nullifiedAt() {
|
|
41
|
-
return this._nullifiedAt;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
-
import { EventSelector } from '@aztec/stdlib/abi';
|
|
3
|
-
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
-
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
5
|
-
import { TxHash } from '@aztec/stdlib/tx';
|
|
6
|
-
/** Serializable private event entry with scope tracking. */
|
|
7
|
-
export declare class StoredPrivateEvent {
|
|
8
|
-
readonly randomness: Fr;
|
|
9
|
-
readonly msgContent: Fr[];
|
|
10
|
-
readonly l2BlockNumber: number;
|
|
11
|
-
readonly l2BlockHash: L2BlockHash;
|
|
12
|
-
readonly txHash: TxHash;
|
|
13
|
-
readonly txIndexInBlock: number;
|
|
14
|
-
readonly eventIndexInTx: number;
|
|
15
|
-
readonly contractAddress: AztecAddress;
|
|
16
|
-
readonly eventSelector: EventSelector;
|
|
17
|
-
readonly scopes: Set<string>;
|
|
18
|
-
constructor(randomness: Fr, msgContent: Fr[], l2BlockNumber: number, l2BlockHash: L2BlockHash, txHash: TxHash, txIndexInBlock: number, eventIndexInTx: number, contractAddress: AztecAddress, eventSelector: EventSelector, scopes: Set<string>);
|
|
19
|
-
addScope(scope: string): void;
|
|
20
|
-
toBuffer(): Buffer;
|
|
21
|
-
static fromBuffer(buffer: Buffer): StoredPrivateEvent;
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RvcmVkX3ByaXZhdGVfZXZlbnQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zdG9yYWdlL3ByaXZhdGVfZXZlbnRfc3RvcmUvc3RvcmVkX3ByaXZhdGVfZXZlbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXBELE9BQU8sRUFBRSxhQUFhLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUNsRCxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sNkJBQTZCLENBQUM7QUFDM0QsT0FBTyxFQUFFLFdBQVcsRUFB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AE,MAAM,GAAG,kBAAkB,CA2BpD;CACF"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
-
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
3
|
-
import { EventSelector } from '@aztec/stdlib/abi';
|
|
4
|
-
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
-
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
6
|
-
import { TxHash } from '@aztec/stdlib/tx';
|
|
7
|
-
/** Serializable private event entry with scope tracking. */ export class StoredPrivateEvent {
|
|
8
|
-
randomness;
|
|
9
|
-
msgContent;
|
|
10
|
-
l2BlockNumber;
|
|
11
|
-
l2BlockHash;
|
|
12
|
-
txHash;
|
|
13
|
-
txIndexInBlock;
|
|
14
|
-
eventIndexInTx;
|
|
15
|
-
contractAddress;
|
|
16
|
-
eventSelector;
|
|
17
|
-
scopes;
|
|
18
|
-
constructor(randomness, msgContent, l2BlockNumber, l2BlockHash, txHash, txIndexInBlock, eventIndexInTx, contractAddress, eventSelector, scopes){
|
|
19
|
-
this.randomness = randomness;
|
|
20
|
-
this.msgContent = msgContent;
|
|
21
|
-
this.l2BlockNumber = l2BlockNumber;
|
|
22
|
-
this.l2BlockHash = l2BlockHash;
|
|
23
|
-
this.txHash = txHash;
|
|
24
|
-
this.txIndexInBlock = txIndexInBlock;
|
|
25
|
-
this.eventIndexInTx = eventIndexInTx;
|
|
26
|
-
this.contractAddress = contractAddress;
|
|
27
|
-
this.eventSelector = eventSelector;
|
|
28
|
-
this.scopes = scopes;
|
|
29
|
-
}
|
|
30
|
-
addScope(scope) {
|
|
31
|
-
this.scopes.add(scope);
|
|
32
|
-
}
|
|
33
|
-
toBuffer() {
|
|
34
|
-
const scopesArray = [
|
|
35
|
-
...this.scopes
|
|
36
|
-
];
|
|
37
|
-
return serializeToBuffer(this.randomness, this.msgContent.length, ...this.msgContent, this.l2BlockNumber, this.l2BlockHash, this.txHash, this.txIndexInBlock, this.eventIndexInTx, this.contractAddress, this.eventSelector.toBuffer(), scopesArray.length, ...scopesArray);
|
|
38
|
-
}
|
|
39
|
-
static fromBuffer(buffer) {
|
|
40
|
-
const reader = BufferReader.asReader(buffer);
|
|
41
|
-
const randomness = Fr.fromBuffer(reader);
|
|
42
|
-
const msgContentLength = reader.readNumber();
|
|
43
|
-
const msgContent = reader.readArray(msgContentLength, Fr);
|
|
44
|
-
const l2BlockNumber = reader.readNumber();
|
|
45
|
-
const l2BlockHash = L2BlockHash.fromBuffer(reader);
|
|
46
|
-
const txHash = TxHash.fromBuffer(reader);
|
|
47
|
-
const txIndexInBlock = reader.readNumber();
|
|
48
|
-
const eventIndexInTx = reader.readNumber();
|
|
49
|
-
const contractAddress = AztecAddress.fromBuffer(reader);
|
|
50
|
-
const eventSelector = EventSelector.fromBuffer(reader);
|
|
51
|
-
const scopes = reader.readVector({
|
|
52
|
-
fromBuffer: (r)=>r.readString()
|
|
53
|
-
});
|
|
54
|
-
return new StoredPrivateEvent(randomness, msgContent, l2BlockNumber, l2BlockHash, txHash, txIndexInBlock, eventIndexInTx, contractAddress, eventSelector, new Set(scopes));
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
2
|
-
import type { L2BlockHash } from '@aztec/stdlib/block';
|
|
3
|
-
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
4
|
-
import type { SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
5
|
-
/**
|
|
6
|
-
* Fetches all private logs for the given tags, automatically paginating through all pages.
|
|
7
|
-
* @param aztecNode - The Aztec node to query.
|
|
8
|
-
* @param tags - The siloed tags to search for.
|
|
9
|
-
* @param anchorBlockHash - reference block for the Aztec node query, throws if block is not found there (typically
|
|
10
|
-
* because of reorgs).
|
|
11
|
-
* @returns An array of log arrays, one per tag, containing all logs across all pages.
|
|
12
|
-
*/
|
|
13
|
-
export declare function getAllPrivateLogsByTags(aztecNode: AztecNode, tags: SiloedTag[], anchorBlockHash: L2BlockHash): Promise<TxScopedL2Log[][]>;
|
|
14
|
-
/**
|
|
15
|
-
* Fetches all public logs for the given tags from a contract, automatically paginating through all pages.
|
|
16
|
-
* @param aztecNode - The Aztec node to query.
|
|
17
|
-
* @param contractAddress - The contract address to search logs for.
|
|
18
|
-
* @param tags - The tags to search for.
|
|
19
|
-
* @param anchorBlockHash - reference block for the Aztec node query, throws if block is not found there (typically
|
|
20
|
-
* because of reorgs).
|
|
21
|
-
* @returns An array of log arrays, one per tag, containing all logs across all pages.
|
|
22
|
-
*/
|
|
23
|
-
export declare function getAllPublicLogsByTagsFromContract(aztecNode: AztecNode, contractAddress: AztecAddress, tags: Tag[], anchorBlockHash: L2BlockHash): Promise<TxScopedL2Log[][]>;
|
|
24
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2V0X2FsbF9sb2dzX2J5X3RhZ3MuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90YWdnaW5nL2dldF9hbGxfbG9nc19ieV90YWdzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQ2hFLE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBRXZELE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQ2pFLE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxHQUFHLEVBQUUsYUFBYSxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUE2QnhFOzs7Ozs7O0dBT0c7QUFDSCx3QkFBZ0IsdUJBQXVCLENBQ3JDLFNBQVMsRUFBRSxTQU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lib/interfaces/api-limit';
|
|
2
|
-
/**
|
|
3
|
-
* Generic pagination helper that fetches all pages of results.
|
|
4
|
-
* @param numTags - The number of tags being queried (determines result array size).
|
|
5
|
-
* @param fetchPage - Function that fetches a single page of results given a page number.
|
|
6
|
-
* @returns An array of arrays, one per tag, containing all results across all pages.
|
|
7
|
-
*/ async function getAllPages(numTags, fetchPage) {
|
|
8
|
-
const allResultsPerTag = Array.from({
|
|
9
|
-
length: numTags
|
|
10
|
-
}, ()=>[]);
|
|
11
|
-
let page = 0;
|
|
12
|
-
let hasMore = true;
|
|
13
|
-
while(hasMore){
|
|
14
|
-
const resultsPage = await fetchPage(page);
|
|
15
|
-
hasMore = false;
|
|
16
|
-
for(let i = 0; i < resultsPage.length; i++){
|
|
17
|
-
allResultsPerTag[i].push(...resultsPage[i]);
|
|
18
|
-
if (resultsPage[i].length === MAX_LOGS_PER_TAG) {
|
|
19
|
-
hasMore = true;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
page++;
|
|
23
|
-
}
|
|
24
|
-
return allResultsPerTag;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Fetches all private logs for the given tags, automatically paginating through all pages.
|
|
28
|
-
* @param aztecNode - The Aztec node to query.
|
|
29
|
-
* @param tags - The siloed tags to search for.
|
|
30
|
-
* @param anchorBlockHash - reference block for the Aztec node query, throws if block is not found there (typically
|
|
31
|
-
* because of reorgs).
|
|
32
|
-
* @returns An array of log arrays, one per tag, containing all logs across all pages.
|
|
33
|
-
*/ export function getAllPrivateLogsByTags(aztecNode, tags, anchorBlockHash) {
|
|
34
|
-
return getAllPages(tags.length, (page)=>aztecNode.getPrivateLogsByTags(tags, page, anchorBlockHash));
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Fetches all public logs for the given tags from a contract, automatically paginating through all pages.
|
|
38
|
-
* @param aztecNode - The Aztec node to query.
|
|
39
|
-
* @param contractAddress - The contract address to search logs for.
|
|
40
|
-
* @param tags - The tags to search for.
|
|
41
|
-
* @param anchorBlockHash - reference block for the Aztec node query, throws if block is not found there (typically
|
|
42
|
-
* because of reorgs).
|
|
43
|
-
* @returns An array of log arrays, one per tag, containing all logs across all pages.
|
|
44
|
-
*/ export function getAllPublicLogsByTagsFromContract(aztecNode, contractAddress, tags, anchorBlockHash) {
|
|
45
|
-
return getAllPages(tags.length, (page)=>aztecNode.getPublicLogsByTagsFromContract(contractAddress, tags, page, anchorBlockHash));
|
|
46
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
3
|
-
import { NoteDao } from '@aztec/stdlib/note';
|
|
4
|
-
|
|
5
|
-
export class StoredNote {
|
|
6
|
-
constructor(
|
|
7
|
-
readonly noteDao: NoteDao,
|
|
8
|
-
readonly scopes: Set<string>,
|
|
9
|
-
private _nullifiedAt: BlockNumber | undefined = undefined,
|
|
10
|
-
) {}
|
|
11
|
-
|
|
12
|
-
static fromBuffer(buffer: Buffer) {
|
|
13
|
-
const reader = BufferReader.asReader(buffer);
|
|
14
|
-
|
|
15
|
-
const noteDao = NoteDao.fromBuffer(reader);
|
|
16
|
-
const scopes = reader.readVector({ fromBuffer: (r: BufferReader) => r.readString() });
|
|
17
|
-
|
|
18
|
-
const nullifiedAtRaw = reader.readNumber();
|
|
19
|
-
const nullifiedAt = nullifiedAtRaw === 0 ? undefined : (nullifiedAtRaw as BlockNumber);
|
|
20
|
-
|
|
21
|
-
return new StoredNote(noteDao, new Set(scopes), nullifiedAt);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
toBuffer(): Buffer {
|
|
25
|
-
const scopesArray = [...this.scopes];
|
|
26
|
-
return serializeToBuffer(this.noteDao, scopesArray.length, ...scopesArray, this._nullifiedAt ?? 0);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
addScope(scope: string) {
|
|
30
|
-
this.scopes.add(scope);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
markAsNullified(blockNumber: BlockNumber) {
|
|
34
|
-
this._nullifiedAt = blockNumber;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
markAsActive() {
|
|
38
|
-
this._nullifiedAt = undefined;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
isNullified() {
|
|
42
|
-
return this._nullifiedAt !== undefined;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
get nullifiedAt() {
|
|
46
|
-
return this._nullifiedAt;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
-
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
3
|
-
import { EventSelector } from '@aztec/stdlib/abi';
|
|
4
|
-
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
-
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
6
|
-
import { TxHash } from '@aztec/stdlib/tx';
|
|
7
|
-
|
|
8
|
-
/** Serializable private event entry with scope tracking. */
|
|
9
|
-
export class StoredPrivateEvent {
|
|
10
|
-
constructor(
|
|
11
|
-
readonly randomness: Fr,
|
|
12
|
-
readonly msgContent: Fr[],
|
|
13
|
-
readonly l2BlockNumber: number,
|
|
14
|
-
readonly l2BlockHash: L2BlockHash,
|
|
15
|
-
readonly txHash: TxHash,
|
|
16
|
-
readonly txIndexInBlock: number,
|
|
17
|
-
readonly eventIndexInTx: number,
|
|
18
|
-
readonly contractAddress: AztecAddress,
|
|
19
|
-
readonly eventSelector: EventSelector,
|
|
20
|
-
readonly scopes: Set<string>,
|
|
21
|
-
) {}
|
|
22
|
-
|
|
23
|
-
addScope(scope: string) {
|
|
24
|
-
this.scopes.add(scope);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
toBuffer(): Buffer {
|
|
28
|
-
const scopesArray = [...this.scopes];
|
|
29
|
-
return serializeToBuffer(
|
|
30
|
-
this.randomness,
|
|
31
|
-
this.msgContent.length,
|
|
32
|
-
...this.msgContent,
|
|
33
|
-
this.l2BlockNumber,
|
|
34
|
-
this.l2BlockHash,
|
|
35
|
-
this.txHash,
|
|
36
|
-
this.txIndexInBlock,
|
|
37
|
-
this.eventIndexInTx,
|
|
38
|
-
this.contractAddress,
|
|
39
|
-
this.eventSelector.toBuffer(),
|
|
40
|
-
scopesArray.length,
|
|
41
|
-
...scopesArray,
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
static fromBuffer(buffer: Buffer): StoredPrivateEvent {
|
|
46
|
-
const reader = BufferReader.asReader(buffer);
|
|
47
|
-
|
|
48
|
-
const randomness = Fr.fromBuffer(reader);
|
|
49
|
-
const msgContentLength = reader.readNumber();
|
|
50
|
-
const msgContent = reader.readArray(msgContentLength, Fr);
|
|
51
|
-
const l2BlockNumber = reader.readNumber();
|
|
52
|
-
const l2BlockHash = L2BlockHash.fromBuffer(reader);
|
|
53
|
-
const txHash = TxHash.fromBuffer(reader);
|
|
54
|
-
const txIndexInBlock = reader.readNumber();
|
|
55
|
-
const eventIndexInTx = reader.readNumber();
|
|
56
|
-
const contractAddress = AztecAddress.fromBuffer(reader);
|
|
57
|
-
const eventSelector = EventSelector.fromBuffer(reader);
|
|
58
|
-
const scopes = reader.readVector({ fromBuffer: (r: BufferReader) => r.readString() });
|
|
59
|
-
|
|
60
|
-
return new StoredPrivateEvent(
|
|
61
|
-
randomness,
|
|
62
|
-
msgContent,
|
|
63
|
-
l2BlockNumber,
|
|
64
|
-
l2BlockHash,
|
|
65
|
-
txHash,
|
|
66
|
-
txIndexInBlock,
|
|
67
|
-
eventIndexInTx,
|
|
68
|
-
contractAddress,
|
|
69
|
-
eventSelector,
|
|
70
|
-
new Set(scopes),
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
2
|
-
import type { L2BlockHash } from '@aztec/stdlib/block';
|
|
3
|
-
import { MAX_LOGS_PER_TAG } from '@aztec/stdlib/interfaces/api-limit';
|
|
4
|
-
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
5
|
-
import type { SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Generic pagination helper that fetches all pages of results.
|
|
9
|
-
* @param numTags - The number of tags being queried (determines result array size).
|
|
10
|
-
* @param fetchPage - Function that fetches a single page of results given a page number.
|
|
11
|
-
* @returns An array of arrays, one per tag, containing all results across all pages.
|
|
12
|
-
*/
|
|
13
|
-
async function getAllPages<T>(numTags: number, fetchPage: (page: number) => Promise<T[][]>): Promise<T[][]> {
|
|
14
|
-
const allResultsPerTag: T[][] = Array.from({ length: numTags }, () => []);
|
|
15
|
-
let page = 0;
|
|
16
|
-
let hasMore = true;
|
|
17
|
-
|
|
18
|
-
while (hasMore) {
|
|
19
|
-
const resultsPage = await fetchPage(page);
|
|
20
|
-
hasMore = false;
|
|
21
|
-
|
|
22
|
-
for (let i = 0; i < resultsPage.length; i++) {
|
|
23
|
-
allResultsPerTag[i].push(...resultsPage[i]);
|
|
24
|
-
if (resultsPage[i].length === MAX_LOGS_PER_TAG) {
|
|
25
|
-
hasMore = true;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
page++;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return allResultsPerTag;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Fetches all private logs for the given tags, automatically paginating through all pages.
|
|
36
|
-
* @param aztecNode - The Aztec node to query.
|
|
37
|
-
* @param tags - The siloed tags to search for.
|
|
38
|
-
* @param anchorBlockHash - reference block for the Aztec node query, throws if block is not found there (typically
|
|
39
|
-
* because of reorgs).
|
|
40
|
-
* @returns An array of log arrays, one per tag, containing all logs across all pages.
|
|
41
|
-
*/
|
|
42
|
-
export function getAllPrivateLogsByTags(
|
|
43
|
-
aztecNode: AztecNode,
|
|
44
|
-
tags: SiloedTag[],
|
|
45
|
-
anchorBlockHash: L2BlockHash,
|
|
46
|
-
): Promise<TxScopedL2Log[][]> {
|
|
47
|
-
return getAllPages(tags.length, page => aztecNode.getPrivateLogsByTags(tags, page, anchorBlockHash));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Fetches all public logs for the given tags from a contract, automatically paginating through all pages.
|
|
52
|
-
* @param aztecNode - The Aztec node to query.
|
|
53
|
-
* @param contractAddress - The contract address to search logs for.
|
|
54
|
-
* @param tags - The tags to search for.
|
|
55
|
-
* @param anchorBlockHash - reference block for the Aztec node query, throws if block is not found there (typically
|
|
56
|
-
* because of reorgs).
|
|
57
|
-
* @returns An array of log arrays, one per tag, containing all logs across all pages.
|
|
58
|
-
*/
|
|
59
|
-
export function getAllPublicLogsByTagsFromContract(
|
|
60
|
-
aztecNode: AztecNode,
|
|
61
|
-
contractAddress: AztecAddress,
|
|
62
|
-
tags: Tag[],
|
|
63
|
-
anchorBlockHash: L2BlockHash,
|
|
64
|
-
): Promise<TxScopedL2Log[][]> {
|
|
65
|
-
return getAllPages(tags.length, page =>
|
|
66
|
-
aztecNode.getPublicLogsByTagsFromContract(contractAddress, tags, page, anchorBlockHash),
|
|
67
|
-
);
|
|
68
|
-
}
|