@aztec/stdlib 3.0.0-nightly.20251126 → 3.0.0-nightly.20251127
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/note/index.d.ts +1 -1
- package/dest/note/index.d.ts.map +1 -1
- package/dest/note/index.js +1 -1
- package/dest/note/note_dao.d.ts +97 -0
- package/dest/note/note_dao.d.ts.map +1 -0
- package/dest/note/note_dao.js +101 -0
- package/dest/tests/mocks.d.ts +0 -2
- package/dest/tests/mocks.d.ts.map +1 -1
- package/dest/tests/mocks.js +0 -5
- package/package.json +9 -9
- package/src/note/index.ts +1 -1
- package/src/note/note_dao.ts +151 -0
- package/src/tests/mocks.ts +0 -12
- package/dest/note/unique_note.d.ts +0 -39
- package/dest/note/unique_note.d.ts.map +0 -1
- package/dest/note/unique_note.js +0 -62
- package/src/note/unique_note.ts +0 -70
package/dest/note/index.d.ts
CHANGED
package/dest/note/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/note/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/note/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC"}
|
package/dest/note/index.js
CHANGED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { BufferReader } from '@aztec/foundation/serialize';
|
|
3
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import { Note } from '@aztec/stdlib/note';
|
|
5
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
6
|
+
/**
|
|
7
|
+
* A Note Data Access Object, representing a note that was committed to the note hash tree, holding all of the
|
|
8
|
+
* information required to use it during execution and manage its state.
|
|
9
|
+
*/
|
|
10
|
+
export declare class NoteDao {
|
|
11
|
+
/** The packed content of the note, as will be returned in the getNotes oracle. */
|
|
12
|
+
note: Note;
|
|
13
|
+
/** The address of the contract that created the note (i.e. the address used by the kernel during siloing). */
|
|
14
|
+
contractAddress: AztecAddress;
|
|
15
|
+
/**
|
|
16
|
+
* The storage location of the note. This value is not used for anything in PXE, but we do index by storage slot
|
|
17
|
+
* since contracts typically make queries based on it.
|
|
18
|
+
*/
|
|
19
|
+
storageSlot: Fr;
|
|
20
|
+
/**
|
|
21
|
+
* The randomness injected to the note.
|
|
22
|
+
*/
|
|
23
|
+
randomness: Fr;
|
|
24
|
+
/** The nonce that was injected into the note hash preimage in order to guarantee uniqueness. */
|
|
25
|
+
noteNonce: Fr;
|
|
26
|
+
/**
|
|
27
|
+
* The inner hash (non-unique, non-siloed) of the note. Each contract determines how the note is hashed. Can
|
|
28
|
+
* be used alongside contractAddress and nonce to compute the uniqueNoteHash and the siloedNoteHash.
|
|
29
|
+
*/
|
|
30
|
+
noteHash: Fr;
|
|
31
|
+
/**
|
|
32
|
+
* The nullifier of the note, siloed by contract address.
|
|
33
|
+
* Note: Might be set as 0 if the note was added to PXE as nullified.
|
|
34
|
+
*/
|
|
35
|
+
siloedNullifier: Fr;
|
|
36
|
+
/** The hash of the tx in which this note was created. Knowing the tx hash allows for efficient node queries e.g.
|
|
37
|
+
* when searching for txEffects.
|
|
38
|
+
*/
|
|
39
|
+
txHash: TxHash;
|
|
40
|
+
/** The L2 block number in which the tx with this note was included. Used for note management while processing
|
|
41
|
+
* reorgs.*/
|
|
42
|
+
l2BlockNumber: number;
|
|
43
|
+
/** The L2 block hash in which the tx with this note was included. Used for note management while processing
|
|
44
|
+
* reorgs.*/
|
|
45
|
+
l2BlockHash: string;
|
|
46
|
+
/** The index of the leaf in the global note hash tree the note is stored at */
|
|
47
|
+
index: bigint;
|
|
48
|
+
constructor(
|
|
49
|
+
/** The packed content of the note, as will be returned in the getNotes oracle. */
|
|
50
|
+
note: Note,
|
|
51
|
+
/** The address of the contract that created the note (i.e. the address used by the kernel during siloing). */
|
|
52
|
+
contractAddress: AztecAddress,
|
|
53
|
+
/**
|
|
54
|
+
* The storage location of the note. This value is not used for anything in PXE, but we do index by storage slot
|
|
55
|
+
* since contracts typically make queries based on it.
|
|
56
|
+
*/
|
|
57
|
+
storageSlot: Fr,
|
|
58
|
+
/**
|
|
59
|
+
* The randomness injected to the note.
|
|
60
|
+
*/
|
|
61
|
+
randomness: Fr,
|
|
62
|
+
/** The nonce that was injected into the note hash preimage in order to guarantee uniqueness. */
|
|
63
|
+
noteNonce: Fr,
|
|
64
|
+
/**
|
|
65
|
+
* The inner hash (non-unique, non-siloed) of the note. Each contract determines how the note is hashed. Can
|
|
66
|
+
* be used alongside contractAddress and nonce to compute the uniqueNoteHash and the siloedNoteHash.
|
|
67
|
+
*/
|
|
68
|
+
noteHash: Fr,
|
|
69
|
+
/**
|
|
70
|
+
* The nullifier of the note, siloed by contract address.
|
|
71
|
+
* Note: Might be set as 0 if the note was added to PXE as nullified.
|
|
72
|
+
*/
|
|
73
|
+
siloedNullifier: Fr,
|
|
74
|
+
/** The hash of the tx in which this note was created. Knowing the tx hash allows for efficient node queries e.g.
|
|
75
|
+
* when searching for txEffects.
|
|
76
|
+
*/
|
|
77
|
+
txHash: TxHash,
|
|
78
|
+
/** The L2 block number in which the tx with this note was included. Used for note management while processing
|
|
79
|
+
* reorgs.*/
|
|
80
|
+
l2BlockNumber: number,
|
|
81
|
+
/** The L2 block hash in which the tx with this note was included. Used for note management while processing
|
|
82
|
+
* reorgs.*/
|
|
83
|
+
l2BlockHash: string,
|
|
84
|
+
/** The index of the leaf in the global note hash tree the note is stored at */
|
|
85
|
+
index: bigint);
|
|
86
|
+
toBuffer(): Buffer;
|
|
87
|
+
static fromBuffer(buffer: Buffer | BufferReader): NoteDao;
|
|
88
|
+
toString(): string;
|
|
89
|
+
static fromString(str: string): NoteDao;
|
|
90
|
+
/**
|
|
91
|
+
* Returns the size in bytes of the Note Dao.
|
|
92
|
+
* @returns - Its size in bytes.
|
|
93
|
+
*/
|
|
94
|
+
getSize(): number;
|
|
95
|
+
static random({ note, contractAddress, storageSlot, randomness, noteNonce, noteHash, siloedNullifier, txHash, l2BlockNumber, l2BlockHash, index, }?: Partial<NoteDao>): Promise<NoteDao>;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=note_dao.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"note_dao.d.ts","sourceRoot":"","sources":["../../src/note/note_dao.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAS,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C;;;GAGG;AACH,qBAAa,OAAO;IAIhB,kFAAkF;IAC3E,IAAI,EAAE,IAAI;IACjB,8GAA8G;IACvG,eAAe,EAAE,YAAY;IACpC;;;OAGG;IACI,WAAW,EAAE,EAAE;IACtB;;OAEG;IACI,UAAU,EAAE,EAAE;IACrB,gGAAgG;IACzF,SAAS,EAAE,EAAE;IAGpB;;;OAGG;IACI,QAAQ,EAAE,EAAE;IACnB;;;OAGG;IACI,eAAe,EAAE,EAAE;IAG1B;;OAEG;IACI,MAAM,EAAE,MAAM;IACrB;gBACY;IACL,aAAa,EAAE,MAAM;IAC5B;gBACY;IACL,WAAW,EAAE,MAAM;IAC1B,+EAA+E;IACxE,KAAK,EAAE,MAAM;;IAxCpB,kFAAkF;IAC3E,IAAI,EAAE,IAAI;IACjB,8GAA8G;IACvG,eAAe,EAAE,YAAY;IACpC;;;OAGG;IACI,WAAW,EAAE,EAAE;IACtB;;OAEG;IACI,UAAU,EAAE,EAAE;IACrB,gGAAgG;IACzF,SAAS,EAAE,EAAE;IAGpB;;;OAGG;IACI,QAAQ,EAAE,EAAE;IACnB;;;OAGG;IACI,eAAe,EAAE,EAAE;IAG1B;;OAEG;IACI,MAAM,EAAE,MAAM;IACrB;gBACY;IACL,aAAa,EAAE,MAAM;IAC5B;gBACY;IACL,WAAW,EAAE,MAAM;IAC1B,+EAA+E;IACxE,KAAK,EAAE,MAAM;IAGtB,QAAQ,IAAI,MAAM;IAgBlB,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY;IA8B/C,QAAQ;IAIR,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM;IAK7B;;;OAGG;IACI,OAAO;WAMD,MAAM,CAAC,EAClB,IAAoB,EACpB,eAA2B,EAC3B,WAAyB,EACzB,UAAwB,EACxB,SAAuB,EACvB,QAAsB,EACtB,eAA6B,EAC7B,MAAwB,EACxB,aAAgD,EAChD,WAAoC,EACpC,KAA8B,GAC/B,GAAE,OAAO,CAAC,OAAO,CAAM;CAezB"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { toBigIntBE } from '@aztec/foundation/bigint-buffer';
|
|
2
|
+
import { Fr, Point } from '@aztec/foundation/fields';
|
|
3
|
+
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
import { Note } from '@aztec/stdlib/note';
|
|
6
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
7
|
+
/**
|
|
8
|
+
* A Note Data Access Object, representing a note that was committed to the note hash tree, holding all of the
|
|
9
|
+
* information required to use it during execution and manage its state.
|
|
10
|
+
*/ export class NoteDao {
|
|
11
|
+
note;
|
|
12
|
+
contractAddress;
|
|
13
|
+
storageSlot;
|
|
14
|
+
randomness;
|
|
15
|
+
noteNonce;
|
|
16
|
+
noteHash;
|
|
17
|
+
siloedNullifier;
|
|
18
|
+
txHash;
|
|
19
|
+
l2BlockNumber;
|
|
20
|
+
l2BlockHash;
|
|
21
|
+
index;
|
|
22
|
+
constructor(// Note information
|
|
23
|
+
/** The packed content of the note, as will be returned in the getNotes oracle. */ note, /** The address of the contract that created the note (i.e. the address used by the kernel during siloing). */ contractAddress, /**
|
|
24
|
+
* The storage location of the note. This value is not used for anything in PXE, but we do index by storage slot
|
|
25
|
+
* since contracts typically make queries based on it.
|
|
26
|
+
*/ storageSlot, /**
|
|
27
|
+
* The randomness injected to the note.
|
|
28
|
+
*/ randomness, /** The nonce that was injected into the note hash preimage in order to guarantee uniqueness. */ noteNonce, // Computed values
|
|
29
|
+
/**
|
|
30
|
+
* The inner hash (non-unique, non-siloed) of the note. Each contract determines how the note is hashed. Can
|
|
31
|
+
* be used alongside contractAddress and nonce to compute the uniqueNoteHash and the siloedNoteHash.
|
|
32
|
+
*/ noteHash, /**
|
|
33
|
+
* The nullifier of the note, siloed by contract address.
|
|
34
|
+
* Note: Might be set as 0 if the note was added to PXE as nullified.
|
|
35
|
+
*/ siloedNullifier, // Metadata
|
|
36
|
+
/** The hash of the tx in which this note was created. Knowing the tx hash allows for efficient node queries e.g.
|
|
37
|
+
* when searching for txEffects.
|
|
38
|
+
*/ txHash, /** The L2 block number in which the tx with this note was included. Used for note management while processing
|
|
39
|
+
* reorgs.*/ l2BlockNumber, /** The L2 block hash in which the tx with this note was included. Used for note management while processing
|
|
40
|
+
* reorgs.*/ l2BlockHash, /** The index of the leaf in the global note hash tree the note is stored at */ index){
|
|
41
|
+
this.note = note;
|
|
42
|
+
this.contractAddress = contractAddress;
|
|
43
|
+
this.storageSlot = storageSlot;
|
|
44
|
+
this.randomness = randomness;
|
|
45
|
+
this.noteNonce = noteNonce;
|
|
46
|
+
this.noteHash = noteHash;
|
|
47
|
+
this.siloedNullifier = siloedNullifier;
|
|
48
|
+
this.txHash = txHash;
|
|
49
|
+
this.l2BlockNumber = l2BlockNumber;
|
|
50
|
+
this.l2BlockHash = l2BlockHash;
|
|
51
|
+
this.index = index;
|
|
52
|
+
}
|
|
53
|
+
toBuffer() {
|
|
54
|
+
return serializeToBuffer([
|
|
55
|
+
this.note,
|
|
56
|
+
this.contractAddress,
|
|
57
|
+
this.storageSlot,
|
|
58
|
+
this.randomness,
|
|
59
|
+
this.noteNonce,
|
|
60
|
+
this.noteHash,
|
|
61
|
+
this.siloedNullifier,
|
|
62
|
+
this.txHash,
|
|
63
|
+
this.l2BlockNumber,
|
|
64
|
+
Fr.fromHexString(this.l2BlockHash),
|
|
65
|
+
this.index
|
|
66
|
+
]);
|
|
67
|
+
}
|
|
68
|
+
static fromBuffer(buffer) {
|
|
69
|
+
const reader = BufferReader.asReader(buffer);
|
|
70
|
+
const note = Note.fromBuffer(reader);
|
|
71
|
+
const contractAddress = AztecAddress.fromBuffer(reader);
|
|
72
|
+
const storageSlot = Fr.fromBuffer(reader);
|
|
73
|
+
const randomness = Fr.fromBuffer(reader);
|
|
74
|
+
const noteNonce = Fr.fromBuffer(reader);
|
|
75
|
+
const noteHash = Fr.fromBuffer(reader);
|
|
76
|
+
const siloedNullifier = Fr.fromBuffer(reader);
|
|
77
|
+
const txHash = reader.readObject(TxHash);
|
|
78
|
+
const l2BlockNumber = reader.readNumber();
|
|
79
|
+
const l2BlockHash = Fr.fromBuffer(reader).toString();
|
|
80
|
+
const index = toBigIntBE(reader.readBytes(32));
|
|
81
|
+
return new NoteDao(note, contractAddress, storageSlot, randomness, noteNonce, noteHash, siloedNullifier, txHash, l2BlockNumber, l2BlockHash, index);
|
|
82
|
+
}
|
|
83
|
+
toString() {
|
|
84
|
+
return '0x' + this.toBuffer().toString('hex');
|
|
85
|
+
}
|
|
86
|
+
static fromString(str) {
|
|
87
|
+
const hex = str.replace(/^0x/, '');
|
|
88
|
+
return NoteDao.fromBuffer(Buffer.from(hex, 'hex'));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Returns the size in bytes of the Note Dao.
|
|
92
|
+
* @returns - Its size in bytes.
|
|
93
|
+
*/ getSize() {
|
|
94
|
+
const indexSize = Math.ceil(Math.log2(Number(this.index)));
|
|
95
|
+
const noteSize = 4 + this.note.items.length * Fr.SIZE_IN_BYTES;
|
|
96
|
+
return noteSize + AztecAddress.SIZE_IN_BYTES + Fr.SIZE_IN_BYTES * 4 + TxHash.SIZE + Point.SIZE_IN_BYTES + indexSize;
|
|
97
|
+
}
|
|
98
|
+
static async random({ note = Note.random(), contractAddress = undefined, storageSlot = Fr.random(), randomness = Fr.random(), noteNonce = Fr.random(), noteHash = Fr.random(), siloedNullifier = Fr.random(), txHash = TxHash.random(), l2BlockNumber = Math.floor(Math.random() * 1000), l2BlockHash = Fr.random().toString(), index = Fr.random().toBigInt() } = {}) {
|
|
99
|
+
return new NoteDao(note, contractAddress ?? await AztecAddress.random(), storageSlot, randomness, noteNonce, noteHash, siloedNullifier, txHash, l2BlockNumber, l2BlockHash, index);
|
|
100
|
+
}
|
|
101
|
+
}
|
package/dest/tests/mocks.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ import { Gas } from '../gas/gas.js';
|
|
|
12
12
|
import { GasFees } from '../gas/gas_fees.js';
|
|
13
13
|
import { GasSettings } from '../gas/gas_settings.js';
|
|
14
14
|
import type { MerkleTreeReadOperations } from '../interfaces/merkle_tree_operations.js';
|
|
15
|
-
import { UniqueNote } from '../note/unique_note.js';
|
|
16
15
|
import { BlockAttestation } from '../p2p/block_attestation.js';
|
|
17
16
|
import { BlockProposal } from '../p2p/block_proposal.js';
|
|
18
17
|
import { ChonkProof } from '../proofs/chonk_proof.js';
|
|
@@ -21,7 +20,6 @@ import { BlockHeader, GlobalVariables, ProtocolContracts, StateReference, Tx } f
|
|
|
21
20
|
import { TxSimulationResult } from '../tx/simulated_tx.js';
|
|
22
21
|
import { TxHash } from '../tx/tx_hash.js';
|
|
23
22
|
export declare const randomTxHash: () => TxHash;
|
|
24
|
-
export declare const randomUniqueNote: ({ note, contractAddress, txHash, storageSlot, noteNonce, }?: Partial<UniqueNote>) => Promise<UniqueNote>;
|
|
25
23
|
export declare const mockTx: (seed?: number, { numberOfNonRevertiblePublicCallRequests, numberOfRevertiblePublicCallRequests, numberOfRevertibleNullifiers, hasPublicTeardownCallRequest, publicCalldataSize, feePayer, chonkProof, maxPriorityFeesPerGas, gasUsed, chainId, version, vkTreeRoot, protocolContractsHash, }?: {
|
|
26
24
|
numberOfNonRevertiblePublicCallRequests?: number;
|
|
27
25
|
numberOfRevertiblePublicCallRequests?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mocks.d.ts","sourceRoot":"","sources":["../../src/tests/mocks.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,eAAe,EAAe,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAyC,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACzF,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,+CAA+C,CAAC;AACrG,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAIlE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAExE,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"mocks.d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
|
package/dest/tests/mocks.js
CHANGED
|
@@ -24,8 +24,6 @@ import { PartialPrivateTailPublicInputsForPublic, PrivateKernelTailCircuitPublic
|
|
|
24
24
|
import { PrivateToAvmAccumulatedData } from '../kernel/private_to_avm_accumulated_data.js';
|
|
25
25
|
import { PrivateToPublicAccumulatedDataBuilder } from '../kernel/private_to_public_accumulated_data_builder.js';
|
|
26
26
|
import { PublicCallRequestArrayLengths } from '../kernel/public_call_request.js';
|
|
27
|
-
import { Note } from '../note/note.js';
|
|
28
|
-
import { UniqueNote } from '../note/unique_note.js';
|
|
29
27
|
import { BlockAttestation } from '../p2p/block_attestation.js';
|
|
30
28
|
import { BlockProposal } from '../p2p/block_proposal.js';
|
|
31
29
|
import { ConsensusPayload } from '../p2p/consensus_payload.js';
|
|
@@ -40,9 +38,6 @@ import { TxEffect } from '../tx/tx_effect.js';
|
|
|
40
38
|
import { TxHash } from '../tx/tx_hash.js';
|
|
41
39
|
import { makeAvmCircuitInputs, makeAztecAddress, makeGas, makeGlobalVariables, makeHeader, makeL2BlockHeader, makePrivateToPublicAccumulatedData, makePrivateToRollupAccumulatedData, makeProtocolContracts, makePublicCallRequest, makePublicDataWrite } from './factories.js';
|
|
42
40
|
export const randomTxHash = ()=>TxHash.random();
|
|
43
|
-
export const randomUniqueNote = async ({ note = Note.random(), contractAddress = undefined, txHash = randomTxHash(), storageSlot = Fr.random(), noteNonce = Fr.random() } = {})=>{
|
|
44
|
-
return new UniqueNote(note, contractAddress ?? await AztecAddress.random(), storageSlot, txHash, noteNonce);
|
|
45
|
-
};
|
|
46
41
|
export const mockTx = async (seed = 1, { numberOfNonRevertiblePublicCallRequests = MAX_ENQUEUED_CALLS_PER_TX / 2, numberOfRevertiblePublicCallRequests = MAX_ENQUEUED_CALLS_PER_TX / 2, numberOfRevertibleNullifiers = 0, hasPublicTeardownCallRequest = false, publicCalldataSize = 2, feePayer, chonkProof = ChonkProof.random(), maxPriorityFeesPerGas, gasUsed = Gas.empty(), chainId = Fr.ZERO, version = Fr.ZERO, vkTreeRoot = Fr.ZERO, protocolContractsHash = Fr.ZERO } = {})=>{
|
|
47
42
|
const totalPublicCallRequests = numberOfNonRevertiblePublicCallRequests + numberOfRevertiblePublicCallRequests + (hasPublicTeardownCallRequest ? 1 : 0);
|
|
48
43
|
const isForPublic = totalPublicCallRequests > 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/stdlib",
|
|
3
|
-
"version": "3.0.0-nightly.
|
|
3
|
+
"version": "3.0.0-nightly.20251127",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"inherits": [
|
|
6
6
|
"../package.common.json",
|
|
@@ -72,13 +72,13 @@
|
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"@aws-sdk/client-s3": "^3.892.0",
|
|
75
|
-
"@aztec/bb.js": "3.0.0-nightly.
|
|
76
|
-
"@aztec/blob-lib": "3.0.0-nightly.
|
|
77
|
-
"@aztec/constants": "3.0.0-nightly.
|
|
78
|
-
"@aztec/ethereum": "3.0.0-nightly.
|
|
79
|
-
"@aztec/foundation": "3.0.0-nightly.
|
|
80
|
-
"@aztec/l1-artifacts": "3.0.0-nightly.
|
|
81
|
-
"@aztec/noir-noirc_abi": "3.0.0-nightly.
|
|
75
|
+
"@aztec/bb.js": "3.0.0-nightly.20251127",
|
|
76
|
+
"@aztec/blob-lib": "3.0.0-nightly.20251127",
|
|
77
|
+
"@aztec/constants": "3.0.0-nightly.20251127",
|
|
78
|
+
"@aztec/ethereum": "3.0.0-nightly.20251127",
|
|
79
|
+
"@aztec/foundation": "3.0.0-nightly.20251127",
|
|
80
|
+
"@aztec/l1-artifacts": "3.0.0-nightly.20251127",
|
|
81
|
+
"@aztec/noir-noirc_abi": "3.0.0-nightly.20251127",
|
|
82
82
|
"@google-cloud/storage": "^7.15.0",
|
|
83
83
|
"axios": "^1.12.0",
|
|
84
84
|
"json-stringify-deterministic": "1.0.12",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"msgpackr": "^1.11.2",
|
|
90
90
|
"pako": "^2.1.0",
|
|
91
91
|
"tslib": "^2.4.0",
|
|
92
|
-
"viem": "npm:@
|
|
92
|
+
"viem": "npm:@aztec/viem@2.38.2",
|
|
93
93
|
"zod": "^3.23.8"
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
package/src/note/index.ts
CHANGED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { toBigIntBE } from '@aztec/foundation/bigint-buffer';
|
|
2
|
+
import { Fr, Point } from '@aztec/foundation/fields';
|
|
3
|
+
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
import { Note } from '@aztec/stdlib/note';
|
|
6
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A Note Data Access Object, representing a note that was committed to the note hash tree, holding all of the
|
|
10
|
+
* information required to use it during execution and manage its state.
|
|
11
|
+
*/
|
|
12
|
+
export class NoteDao {
|
|
13
|
+
constructor(
|
|
14
|
+
// Note information
|
|
15
|
+
|
|
16
|
+
/** The packed content of the note, as will be returned in the getNotes oracle. */
|
|
17
|
+
public note: Note,
|
|
18
|
+
/** The address of the contract that created the note (i.e. the address used by the kernel during siloing). */
|
|
19
|
+
public contractAddress: AztecAddress,
|
|
20
|
+
/**
|
|
21
|
+
* The storage location of the note. This value is not used for anything in PXE, but we do index by storage slot
|
|
22
|
+
* since contracts typically make queries based on it.
|
|
23
|
+
*/
|
|
24
|
+
public storageSlot: Fr,
|
|
25
|
+
/**
|
|
26
|
+
* The randomness injected to the note.
|
|
27
|
+
*/
|
|
28
|
+
public randomness: Fr,
|
|
29
|
+
/** The nonce that was injected into the note hash preimage in order to guarantee uniqueness. */
|
|
30
|
+
public noteNonce: Fr,
|
|
31
|
+
|
|
32
|
+
// Computed values
|
|
33
|
+
/**
|
|
34
|
+
* The inner hash (non-unique, non-siloed) of the note. Each contract determines how the note is hashed. Can
|
|
35
|
+
* be used alongside contractAddress and nonce to compute the uniqueNoteHash and the siloedNoteHash.
|
|
36
|
+
*/
|
|
37
|
+
public noteHash: Fr,
|
|
38
|
+
/**
|
|
39
|
+
* The nullifier of the note, siloed by contract address.
|
|
40
|
+
* Note: Might be set as 0 if the note was added to PXE as nullified.
|
|
41
|
+
*/
|
|
42
|
+
public siloedNullifier: Fr,
|
|
43
|
+
|
|
44
|
+
// Metadata
|
|
45
|
+
/** The hash of the tx in which this note was created. Knowing the tx hash allows for efficient node queries e.g.
|
|
46
|
+
* when searching for txEffects.
|
|
47
|
+
*/
|
|
48
|
+
public txHash: TxHash,
|
|
49
|
+
/** The L2 block number in which the tx with this note was included. Used for note management while processing
|
|
50
|
+
* reorgs.*/
|
|
51
|
+
public l2BlockNumber: number,
|
|
52
|
+
/** The L2 block hash in which the tx with this note was included. Used for note management while processing
|
|
53
|
+
* reorgs.*/
|
|
54
|
+
public l2BlockHash: string,
|
|
55
|
+
/** The index of the leaf in the global note hash tree the note is stored at */
|
|
56
|
+
public index: bigint,
|
|
57
|
+
) {}
|
|
58
|
+
|
|
59
|
+
toBuffer(): Buffer {
|
|
60
|
+
return serializeToBuffer([
|
|
61
|
+
this.note,
|
|
62
|
+
this.contractAddress,
|
|
63
|
+
this.storageSlot,
|
|
64
|
+
this.randomness,
|
|
65
|
+
this.noteNonce,
|
|
66
|
+
this.noteHash,
|
|
67
|
+
this.siloedNullifier,
|
|
68
|
+
this.txHash,
|
|
69
|
+
this.l2BlockNumber,
|
|
70
|
+
Fr.fromHexString(this.l2BlockHash),
|
|
71
|
+
this.index,
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static fromBuffer(buffer: Buffer | BufferReader) {
|
|
76
|
+
const reader = BufferReader.asReader(buffer);
|
|
77
|
+
|
|
78
|
+
const note = Note.fromBuffer(reader);
|
|
79
|
+
const contractAddress = AztecAddress.fromBuffer(reader);
|
|
80
|
+
const storageSlot = Fr.fromBuffer(reader);
|
|
81
|
+
const randomness = Fr.fromBuffer(reader);
|
|
82
|
+
const noteNonce = Fr.fromBuffer(reader);
|
|
83
|
+
const noteHash = Fr.fromBuffer(reader);
|
|
84
|
+
const siloedNullifier = Fr.fromBuffer(reader);
|
|
85
|
+
const txHash = reader.readObject(TxHash);
|
|
86
|
+
const l2BlockNumber = reader.readNumber();
|
|
87
|
+
const l2BlockHash = Fr.fromBuffer(reader).toString();
|
|
88
|
+
const index = toBigIntBE(reader.readBytes(32));
|
|
89
|
+
|
|
90
|
+
return new NoteDao(
|
|
91
|
+
note,
|
|
92
|
+
contractAddress,
|
|
93
|
+
storageSlot,
|
|
94
|
+
randomness,
|
|
95
|
+
noteNonce,
|
|
96
|
+
noteHash,
|
|
97
|
+
siloedNullifier,
|
|
98
|
+
txHash,
|
|
99
|
+
l2BlockNumber,
|
|
100
|
+
l2BlockHash,
|
|
101
|
+
index,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
toString() {
|
|
106
|
+
return '0x' + this.toBuffer().toString('hex');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static fromString(str: string) {
|
|
110
|
+
const hex = str.replace(/^0x/, '');
|
|
111
|
+
return NoteDao.fromBuffer(Buffer.from(hex, 'hex'));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Returns the size in bytes of the Note Dao.
|
|
116
|
+
* @returns - Its size in bytes.
|
|
117
|
+
*/
|
|
118
|
+
public getSize() {
|
|
119
|
+
const indexSize = Math.ceil(Math.log2(Number(this.index)));
|
|
120
|
+
const noteSize = 4 + this.note.items.length * Fr.SIZE_IN_BYTES;
|
|
121
|
+
return noteSize + AztecAddress.SIZE_IN_BYTES + Fr.SIZE_IN_BYTES * 4 + TxHash.SIZE + Point.SIZE_IN_BYTES + indexSize;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
static async random({
|
|
125
|
+
note = Note.random(),
|
|
126
|
+
contractAddress = undefined,
|
|
127
|
+
storageSlot = Fr.random(),
|
|
128
|
+
randomness = Fr.random(),
|
|
129
|
+
noteNonce = Fr.random(),
|
|
130
|
+
noteHash = Fr.random(),
|
|
131
|
+
siloedNullifier = Fr.random(),
|
|
132
|
+
txHash = TxHash.random(),
|
|
133
|
+
l2BlockNumber = Math.floor(Math.random() * 1000),
|
|
134
|
+
l2BlockHash = Fr.random().toString(),
|
|
135
|
+
index = Fr.random().toBigInt(),
|
|
136
|
+
}: Partial<NoteDao> = {}) {
|
|
137
|
+
return new NoteDao(
|
|
138
|
+
note,
|
|
139
|
+
contractAddress ?? (await AztecAddress.random()),
|
|
140
|
+
storageSlot,
|
|
141
|
+
randomness,
|
|
142
|
+
noteNonce,
|
|
143
|
+
noteHash,
|
|
144
|
+
siloedNullifier,
|
|
145
|
+
txHash,
|
|
146
|
+
l2BlockNumber,
|
|
147
|
+
l2BlockHash,
|
|
148
|
+
index,
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
}
|
package/src/tests/mocks.ts
CHANGED
|
@@ -40,8 +40,6 @@ import {
|
|
|
40
40
|
import { PrivateToAvmAccumulatedData } from '../kernel/private_to_avm_accumulated_data.js';
|
|
41
41
|
import { PrivateToPublicAccumulatedDataBuilder } from '../kernel/private_to_public_accumulated_data_builder.js';
|
|
42
42
|
import { PublicCallRequestArrayLengths } from '../kernel/public_call_request.js';
|
|
43
|
-
import { Note } from '../note/note.js';
|
|
44
|
-
import { UniqueNote } from '../note/unique_note.js';
|
|
45
43
|
import { BlockAttestation } from '../p2p/block_attestation.js';
|
|
46
44
|
import { BlockProposal } from '../p2p/block_proposal.js';
|
|
47
45
|
import { ConsensusPayload } from '../p2p/consensus_payload.js';
|
|
@@ -82,16 +80,6 @@ import {
|
|
|
82
80
|
|
|
83
81
|
export const randomTxHash = (): TxHash => TxHash.random();
|
|
84
82
|
|
|
85
|
-
export const randomUniqueNote = async ({
|
|
86
|
-
note = Note.random(),
|
|
87
|
-
contractAddress = undefined,
|
|
88
|
-
txHash = randomTxHash(),
|
|
89
|
-
storageSlot = Fr.random(),
|
|
90
|
-
noteNonce = Fr.random(),
|
|
91
|
-
}: Partial<UniqueNote> = {}) => {
|
|
92
|
-
return new UniqueNote(note, contractAddress ?? (await AztecAddress.random()), storageSlot, txHash, noteNonce);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
83
|
export const mockTx = async (
|
|
96
84
|
seed = 1,
|
|
97
85
|
{
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { BufferReader } from '@aztec/foundation/serialize';
|
|
3
|
-
import { AztecAddress } from '../aztec-address/index.js';
|
|
4
|
-
import { type ZodFor } from '../schemas/index.js';
|
|
5
|
-
import { TxHash } from '../tx/tx_hash.js';
|
|
6
|
-
import { Note } from './note.js';
|
|
7
|
-
/**
|
|
8
|
-
* A note with contextual data and a nonce that makes it unique.
|
|
9
|
-
*/
|
|
10
|
-
export declare class UniqueNote {
|
|
11
|
-
/** The note as emitted from the Noir contract. */
|
|
12
|
-
note: Note;
|
|
13
|
-
/** The contract address this note is created in. */
|
|
14
|
-
contractAddress: AztecAddress;
|
|
15
|
-
/** The specific storage location of the note on the contract. */
|
|
16
|
-
storageSlot: Fr;
|
|
17
|
-
/** The hash of the tx the note was created in. */
|
|
18
|
-
txHash: TxHash;
|
|
19
|
-
/** The nonce that was injected into the note hash preimage in order to guarantee uniqueness. */
|
|
20
|
-
noteNonce: Fr;
|
|
21
|
-
constructor(
|
|
22
|
-
/** The note as emitted from the Noir contract. */
|
|
23
|
-
note: Note,
|
|
24
|
-
/** The contract address this note is created in. */
|
|
25
|
-
contractAddress: AztecAddress,
|
|
26
|
-
/** The specific storage location of the note on the contract. */
|
|
27
|
-
storageSlot: Fr,
|
|
28
|
-
/** The hash of the tx the note was created in. */
|
|
29
|
-
txHash: TxHash,
|
|
30
|
-
/** The nonce that was injected into the note hash preimage in order to guarantee uniqueness. */
|
|
31
|
-
noteNonce: Fr);
|
|
32
|
-
static get schema(): ZodFor<UniqueNote>;
|
|
33
|
-
toBuffer(): Buffer;
|
|
34
|
-
static random(): Promise<UniqueNote>;
|
|
35
|
-
static fromBuffer(buffer: Buffer | BufferReader): UniqueNote;
|
|
36
|
-
static fromString(str: string): UniqueNote;
|
|
37
|
-
toString(): `0x${string}`;
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=unique_note.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unique_note.d.ts","sourceRoot":"","sources":["../../src/note/unique_note.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAK9E,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,KAAK,MAAM,EAAW,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;GAEG;AACH,qBAAa,UAAU;IAEnB,kDAAkD;IAC3C,IAAI,EAAE,IAAI;IACjB,oDAAoD;IAC7C,eAAe,EAAE,YAAY;IACpC,iEAAiE;IAC1D,WAAW,EAAE,EAAE;IACtB,kDAAkD;IAC3C,MAAM,EAAE,MAAM;IACrB,gGAAgG;IACzF,SAAS,EAAE,EAAE;;IATpB,kDAAkD;IAC3C,IAAI,EAAE,IAAI;IACjB,oDAAoD;IAC7C,eAAe,EAAE,YAAY;IACpC,iEAAiE;IAC1D,WAAW,EAAE,EAAE;IACtB,kDAAkD;IAC3C,MAAM,EAAE,MAAM;IACrB,gGAAgG;IACzF,SAAS,EAAE,EAAE;IAGtB,MAAM,KAAK,MAAM,IAAI,MAAM,CAAC,UAAU,CAAC,CAYtC;IAED,QAAQ,IAAI,MAAM;WAIL,MAAM;IAInB,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY;IAY/C,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM;IAI7B,QAAQ;CAGT"}
|
package/dest/note/unique_note.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
3
|
-
import { bufferToHex, hexToBuffer } from '@aztec/foundation/string';
|
|
4
|
-
import { z } from 'zod';
|
|
5
|
-
import { AztecAddress } from '../aztec-address/index.js';
|
|
6
|
-
import { schemas } from '../schemas/index.js';
|
|
7
|
-
import { TxHash } from '../tx/tx_hash.js';
|
|
8
|
-
import { Note } from './note.js';
|
|
9
|
-
/**
|
|
10
|
-
* A note with contextual data and a nonce that makes it unique.
|
|
11
|
-
*/ export class UniqueNote {
|
|
12
|
-
note;
|
|
13
|
-
contractAddress;
|
|
14
|
-
storageSlot;
|
|
15
|
-
txHash;
|
|
16
|
-
noteNonce;
|
|
17
|
-
constructor(/** The note as emitted from the Noir contract. */ note, /** The contract address this note is created in. */ contractAddress, /** The specific storage location of the note on the contract. */ storageSlot, /** The hash of the tx the note was created in. */ txHash, /** The nonce that was injected into the note hash preimage in order to guarantee uniqueness. */ noteNonce){
|
|
18
|
-
this.note = note;
|
|
19
|
-
this.contractAddress = contractAddress;
|
|
20
|
-
this.storageSlot = storageSlot;
|
|
21
|
-
this.txHash = txHash;
|
|
22
|
-
this.noteNonce = noteNonce;
|
|
23
|
-
}
|
|
24
|
-
static get schema() {
|
|
25
|
-
return z.object({
|
|
26
|
-
note: Note.schema,
|
|
27
|
-
contractAddress: schemas.AztecAddress,
|
|
28
|
-
storageSlot: schemas.Fr,
|
|
29
|
-
txHash: TxHash.schema,
|
|
30
|
-
noteNonce: schemas.Fr
|
|
31
|
-
}).transform(({ note, contractAddress, storageSlot, txHash, noteNonce })=>{
|
|
32
|
-
return new UniqueNote(note, contractAddress, storageSlot, txHash, noteNonce);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
toBuffer() {
|
|
36
|
-
return serializeToBuffer([
|
|
37
|
-
this.note,
|
|
38
|
-
this.contractAddress,
|
|
39
|
-
this.storageSlot,
|
|
40
|
-
this.txHash,
|
|
41
|
-
this.noteNonce
|
|
42
|
-
]);
|
|
43
|
-
}
|
|
44
|
-
static async random() {
|
|
45
|
-
return new UniqueNote(Note.random(), await AztecAddress.random(), Fr.random(), TxHash.random(), Fr.random());
|
|
46
|
-
}
|
|
47
|
-
static fromBuffer(buffer) {
|
|
48
|
-
const reader = BufferReader.asReader(buffer);
|
|
49
|
-
const note = reader.readObject(Note);
|
|
50
|
-
const contractAddress = reader.readObject(AztecAddress);
|
|
51
|
-
const storageSlot = reader.readObject(Fr);
|
|
52
|
-
const txHash = reader.readObject(TxHash);
|
|
53
|
-
const noteNonce = reader.readObject(Fr);
|
|
54
|
-
return new UniqueNote(note, contractAddress, storageSlot, txHash, noteNonce);
|
|
55
|
-
}
|
|
56
|
-
static fromString(str) {
|
|
57
|
-
return UniqueNote.fromBuffer(hexToBuffer(str));
|
|
58
|
-
}
|
|
59
|
-
toString() {
|
|
60
|
-
return bufferToHex(this.toBuffer());
|
|
61
|
-
}
|
|
62
|
-
}
|
package/src/note/unique_note.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
3
|
-
import { bufferToHex, hexToBuffer } from '@aztec/foundation/string';
|
|
4
|
-
|
|
5
|
-
import { z } from 'zod';
|
|
6
|
-
|
|
7
|
-
import { AztecAddress } from '../aztec-address/index.js';
|
|
8
|
-
import { type ZodFor, schemas } from '../schemas/index.js';
|
|
9
|
-
import { TxHash } from '../tx/tx_hash.js';
|
|
10
|
-
import { Note } from './note.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A note with contextual data and a nonce that makes it unique.
|
|
14
|
-
*/
|
|
15
|
-
export class UniqueNote {
|
|
16
|
-
constructor(
|
|
17
|
-
/** The note as emitted from the Noir contract. */
|
|
18
|
-
public note: Note,
|
|
19
|
-
/** The contract address this note is created in. */
|
|
20
|
-
public contractAddress: AztecAddress,
|
|
21
|
-
/** The specific storage location of the note on the contract. */
|
|
22
|
-
public storageSlot: Fr,
|
|
23
|
-
/** The hash of the tx the note was created in. */
|
|
24
|
-
public txHash: TxHash,
|
|
25
|
-
/** The nonce that was injected into the note hash preimage in order to guarantee uniqueness. */
|
|
26
|
-
public noteNonce: Fr,
|
|
27
|
-
) {}
|
|
28
|
-
|
|
29
|
-
static get schema(): ZodFor<UniqueNote> {
|
|
30
|
-
return z
|
|
31
|
-
.object({
|
|
32
|
-
note: Note.schema,
|
|
33
|
-
contractAddress: schemas.AztecAddress,
|
|
34
|
-
storageSlot: schemas.Fr,
|
|
35
|
-
txHash: TxHash.schema,
|
|
36
|
-
noteNonce: schemas.Fr,
|
|
37
|
-
})
|
|
38
|
-
.transform(({ note, contractAddress, storageSlot, txHash, noteNonce }) => {
|
|
39
|
-
return new UniqueNote(note, contractAddress, storageSlot, txHash, noteNonce);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
toBuffer(): Buffer {
|
|
44
|
-
return serializeToBuffer([this.note, this.contractAddress, this.storageSlot, this.txHash, this.noteNonce]);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
static async random() {
|
|
48
|
-
return new UniqueNote(Note.random(), await AztecAddress.random(), Fr.random(), TxHash.random(), Fr.random());
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
static fromBuffer(buffer: Buffer | BufferReader) {
|
|
52
|
-
const reader = BufferReader.asReader(buffer);
|
|
53
|
-
|
|
54
|
-
const note = reader.readObject(Note);
|
|
55
|
-
const contractAddress = reader.readObject(AztecAddress);
|
|
56
|
-
const storageSlot = reader.readObject(Fr);
|
|
57
|
-
const txHash = reader.readObject(TxHash);
|
|
58
|
-
const noteNonce = reader.readObject(Fr);
|
|
59
|
-
|
|
60
|
-
return new UniqueNote(note, contractAddress, storageSlot, txHash, noteNonce);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
static fromString(str: string) {
|
|
64
|
-
return UniqueNote.fromBuffer(hexToBuffer(str));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
toString() {
|
|
68
|
-
return bufferToHex(this.toBuffer());
|
|
69
|
-
}
|
|
70
|
-
}
|