@aztec/stdlib 1.0.0 → 1.1.2
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/l2_block_stream/l2_block_stream.js +1 -1
- package/dest/block/proposal/committee_attestation.d.ts +3 -3
- package/dest/block/proposal/committee_attestation.d.ts.map +1 -1
- package/dest/block/proposal/committee_attestation.js +41 -2
- package/dest/contract/contract_instance_update.d.ts +2 -1
- package/dest/contract/contract_instance_update.d.ts.map +1 -1
- package/dest/contract/contract_instance_update.js +6 -6
- package/dest/contract/interfaces/contract_data_source.d.ts +5 -2
- package/dest/contract/interfaces/contract_data_source.d.ts.map +1 -1
- package/dest/contract/interfaces/contract_instance_update.d.ts +9 -8
- package/dest/contract/interfaces/contract_instance_update.d.ts.map +1 -1
- package/dest/contract/interfaces/contract_instance_update.js +1 -1
- package/dest/hash/hash.d.ts +1 -1
- package/dest/hash/hash.d.ts.map +1 -1
- package/dest/hash/hash.js +7 -3
- package/dest/interfaces/archiver.js +1 -1
- package/dest/interfaces/aztec-node.d.ts +1 -1
- package/dest/interfaces/client.d.ts +1 -0
- package/dest/interfaces/client.d.ts.map +1 -1
- package/dest/interfaces/client.js +1 -0
- package/dest/interfaces/proving-job.d.ts +22 -1
- package/dest/interfaces/proving-job.d.ts.map +1 -1
- package/dest/interfaces/proving-job.js +13 -0
- package/dest/interfaces/server.d.ts +1 -0
- package/dest/interfaces/server.d.ts.map +1 -1
- package/dest/interfaces/server.js +1 -0
- package/dest/interfaces/server_circuit_prover.d.ts +2 -0
- package/dest/interfaces/server_circuit_prover.d.ts.map +1 -1
- package/dest/kernel/hints/rollup_validation_requests.d.ts +6 -10
- package/dest/kernel/hints/rollup_validation_requests.d.ts.map +1 -1
- package/dest/kernel/hints/rollup_validation_requests.js +9 -11
- package/dest/kernel/private_circuit_public_inputs.d.ts +6 -6
- package/dest/kernel/private_circuit_public_inputs.d.ts.map +1 -1
- package/dest/kernel/private_circuit_public_inputs.js +10 -10
- package/dest/proofs/proving_request_type.d.ts +8 -7
- package/dest/proofs/proving_request_type.d.ts.map +1 -1
- package/dest/proofs/proving_request_type.js +8 -7
- package/dest/rollup/base_or_merge_rollup_public_inputs.d.ts +0 -9
- package/dest/rollup/base_or_merge_rollup_public_inputs.d.ts.map +1 -1
- package/dest/rollup/base_or_merge_rollup_public_inputs.js +3 -8
- package/dest/rollup/empty_block_root_rollup_inputs.d.ts +2 -3
- package/dest/rollup/empty_block_root_rollup_inputs.d.ts.map +1 -1
- package/dest/rollup/empty_block_root_rollup_inputs.js +3 -6
- package/dest/rollup/index.d.ts +1 -0
- package/dest/rollup/index.d.ts.map +1 -1
- package/dest/rollup/index.js +1 -0
- package/dest/rollup/padding_block_root_rollup_inputs.d.ts +20 -0
- package/dest/rollup/padding_block_root_rollup_inputs.d.ts.map +1 -0
- package/dest/rollup/padding_block_root_rollup_inputs.js +39 -0
- package/dest/shared_mutable/scheduled_delay_change.d.ts +5 -5
- package/dest/shared_mutable/scheduled_delay_change.d.ts.map +1 -1
- package/dest/shared_mutable/scheduled_delay_change.js +5 -5
- package/dest/shared_mutable/scheduled_value_change.d.ts +4 -3
- package/dest/shared_mutable/scheduled_value_change.d.ts.map +1 -1
- package/dest/shared_mutable/scheduled_value_change.js +7 -7
- package/dest/shared_mutable/shared_mutable_values.js +7 -7
- package/dest/stats/stats.d.ts +1 -1
- package/dest/stats/stats.d.ts.map +1 -1
- package/dest/tests/factories.d.ts.map +1 -1
- package/dest/tests/factories.js +6 -6
- package/dest/tx/include_by_timestamp.d.ts +54 -0
- package/dest/tx/include_by_timestamp.d.ts.map +1 -0
- package/dest/tx/include_by_timestamp.js +72 -0
- package/dest/tx/index.d.ts +1 -1
- package/dest/tx/index.d.ts.map +1 -1
- package/dest/tx/index.js +1 -1
- package/dest/tx/offchain_effect.d.ts.map +1 -1
- package/dest/tx/offchain_effect.js +1 -0
- package/dest/tx/validator/error_texts.d.ts +2 -2
- package/dest/tx/validator/error_texts.d.ts.map +1 -1
- package/dest/tx/validator/error_texts.js +2 -2
- package/dest/types/shared.d.ts +0 -8
- package/dest/types/shared.d.ts.map +1 -1
- package/dest/types/shared.js +0 -8
- package/dest/vks/verification_key.d.ts +1 -0
- package/dest/vks/verification_key.d.ts.map +1 -1
- package/dest/vks/verification_key.js +5 -0
- package/package.json +7 -7
- package/src/block/l2_block_stream/l2_block_stream.ts +1 -1
- package/src/block/proposal/committee_attestation.ts +49 -3
- package/src/contract/contract_instance_update.ts +7 -6
- package/src/contract/interfaces/contract_data_source.ts +5 -2
- package/src/contract/interfaces/contract_instance_update.ts +4 -3
- package/src/hash/hash.ts +7 -3
- package/src/interfaces/archiver.ts +1 -1
- package/src/interfaces/aztec-node.ts +1 -1
- package/src/interfaces/client.ts +1 -0
- package/src/interfaces/proving-job.ts +21 -0
- package/src/interfaces/server.ts +1 -0
- package/src/interfaces/server_circuit_prover.ts +9 -0
- package/src/kernel/hints/rollup_validation_requests.ts +8 -10
- package/src/kernel/private_circuit_public_inputs.ts +8 -8
- package/src/proofs/proving_request_type.ts +1 -0
- package/src/rollup/base_or_merge_rollup_public_inputs.ts +0 -8
- package/src/rollup/empty_block_root_rollup_inputs.ts +2 -7
- package/src/rollup/index.ts +1 -0
- package/src/rollup/padding_block_root_rollup_inputs.ts +47 -0
- package/src/shared_mutable/scheduled_delay_change.ts +6 -6
- package/src/shared_mutable/scheduled_value_change.ts +7 -5
- package/src/shared_mutable/shared_mutable_values.ts +9 -9
- package/src/stats/stats.ts +1 -0
- package/src/tests/factories.ts +4 -6
- package/src/tx/include_by_timestamp.ts +90 -0
- package/src/tx/index.ts +1 -1
- package/src/tx/offchain_effect.ts +1 -0
- package/src/tx/validator/error_texts.ts +2 -2
- package/src/types/shared.ts +0 -9
- package/src/vks/verification_key.ts +6 -0
- package/dest/tx/max_block_number.d.ts +0 -54
- package/dest/tx/max_block_number.d.ts.map +0 -1
- package/dest/tx/max_block_number.js +0 -64
- package/src/tx/max_block_number.ts +0 -81
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { INCLUDE_BY_TIMESTAMP_LENGTH } from '@aztec/constants';
|
|
2
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
import { BufferReader, FieldReader, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize';
|
|
4
|
+
import type { FieldsOf } from '@aztec/foundation/types';
|
|
5
|
+
|
|
6
|
+
import type { UInt64 } from '../types/index.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Maximum block timestamp value at which the transaction can still be included.
|
|
10
|
+
*/
|
|
11
|
+
export class IncludeByTimestamp {
|
|
12
|
+
constructor(
|
|
13
|
+
/**
|
|
14
|
+
* Whether max inclusion timestamp was requested.
|
|
15
|
+
*/
|
|
16
|
+
public isSome: boolean,
|
|
17
|
+
/**
|
|
18
|
+
* The requested max inclusion timestamp of a block, if isSome is true.
|
|
19
|
+
*/
|
|
20
|
+
public value: UInt64,
|
|
21
|
+
) {
|
|
22
|
+
// For sanity we check that the value is less than 2 ** 64.
|
|
23
|
+
if (value >= 1n << 64n) {
|
|
24
|
+
throw new Error('Value is not a u64.');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Serialize as a buffer.
|
|
30
|
+
* @returns The buffer.
|
|
31
|
+
*/
|
|
32
|
+
toBuffer() {
|
|
33
|
+
return serializeToBuffer(...IncludeByTimestamp.getFields(this));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
toFields(): Fr[] {
|
|
37
|
+
const fields = serializeToFields(...IncludeByTimestamp.getFields(this));
|
|
38
|
+
if (fields.length !== INCLUDE_BY_TIMESTAMP_LENGTH) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`Invalid number of fields for IncludeByTimestamp. Expected ${INCLUDE_BY_TIMESTAMP_LENGTH}, got ${fields.length}`,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return fields;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Deserializes IncludeByTimestamp from a buffer or reader.
|
|
48
|
+
* @param buffer - Buffer to read from.
|
|
49
|
+
* @returns The IncludeByTimestamp.
|
|
50
|
+
*/
|
|
51
|
+
static fromBuffer(buffer: Buffer | BufferReader): IncludeByTimestamp {
|
|
52
|
+
const reader = BufferReader.asReader(buffer);
|
|
53
|
+
const isSome = reader.readBoolean();
|
|
54
|
+
// UInt64 is aliased to bigint in TypeScript, causing it to be serialized as a 256-bit integer.
|
|
55
|
+
// Therefore, we must read it back using readUInt256() rather than readUInt64().
|
|
56
|
+
const value = reader.readUInt256();
|
|
57
|
+
return new IncludeByTimestamp(isSome, value);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static fromFields(fields: Fr[] | FieldReader): IncludeByTimestamp {
|
|
61
|
+
const reader = FieldReader.asReader(fields);
|
|
62
|
+
return new IncludeByTimestamp(reader.readBoolean(), reader.readU64());
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static empty() {
|
|
66
|
+
return new IncludeByTimestamp(false, 0n);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
isEmpty(): boolean {
|
|
70
|
+
return !this.isSome && this.value === 0n;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Create a new instance from a fields dictionary.
|
|
75
|
+
* @param fields - The dictionary.
|
|
76
|
+
* @returns A new instance.
|
|
77
|
+
*/
|
|
78
|
+
static from(fields: FieldsOf<IncludeByTimestamp>): IncludeByTimestamp {
|
|
79
|
+
return new IncludeByTimestamp(...IncludeByTimestamp.getFields(fields));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Serialize into a field array. Low-level utility.
|
|
84
|
+
* @param fields - Object with fields.
|
|
85
|
+
* @returns The array.
|
|
86
|
+
*/
|
|
87
|
+
static getFields(fields: FieldsOf<IncludeByTimestamp>) {
|
|
88
|
+
return [fields.isSome, fields.value] as const;
|
|
89
|
+
}
|
|
90
|
+
}
|
package/src/tx/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './block_header.js';
|
|
2
2
|
export * from './call_context.js';
|
|
3
3
|
export * from './global_variables.js';
|
|
4
|
-
export * from './
|
|
4
|
+
export * from './include_by_timestamp.js';
|
|
5
5
|
export * from './content_commitment.js';
|
|
6
6
|
export * from './state_reference.js';
|
|
7
7
|
export * from './partial_state_reference.js';
|
|
@@ -2,6 +2,7 @@ import { Fr } from '@aztec/foundation/fields';
|
|
|
2
2
|
|
|
3
3
|
import type { AztecAddress } from '../aztec-address/index.js';
|
|
4
4
|
|
|
5
|
+
// The following identifier was copied over from `noir-projects/aztec-nr/aztec/src/messages/offchain_messages.nr`.
|
|
5
6
|
// poseidon2hash("aztecnr_offchain_message")
|
|
6
7
|
export const OFFCHAIN_MESSAGE_IDENTIFIER: Fr = new Fr(
|
|
7
8
|
6023466688192654631553769360478808766602235351827869819420284624004071427516n,
|
|
@@ -11,10 +11,10 @@ export const TX_ERROR_DUPLICATE_NULLIFIER_IN_TX = 'Duplicate nullifier in tx';
|
|
|
11
11
|
export const TX_ERROR_EXISTING_NULLIFIER = 'Existing nullifier';
|
|
12
12
|
|
|
13
13
|
// Metadata
|
|
14
|
-
export const
|
|
14
|
+
export const TX_ERROR_INVALID_INCLUDE_BY_TIMESTAMP = 'Invalid expiration timestamp';
|
|
15
15
|
export const TX_ERROR_INCORRECT_L1_CHAIN_ID = 'Incorrect L1 chain id';
|
|
16
16
|
export const TX_ERROR_INCORRECT_ROLLUP_VERSION = 'Incorrect rollup version';
|
|
17
|
-
export const TX_ERROR_INCORRECT_VK_TREE_ROOT = 'Incorrect
|
|
17
|
+
export const TX_ERROR_INCORRECT_VK_TREE_ROOT = 'Incorrect verification keys tree root';
|
|
18
18
|
export const TX_ERROR_INCORRECT_PROTOCOL_CONTRACT_TREE_ROOT = 'Incorrect protocol contracts tree root';
|
|
19
19
|
|
|
20
20
|
// Proof
|
package/src/types/shared.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { bufferSchemaFor } from '@aztec/foundation/schemas';
|
|
|
9
9
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
10
10
|
import { bufferToHex, hexToBuffer } from '@aztec/foundation/string';
|
|
11
11
|
|
|
12
|
+
import { hashVK } from '../hash/index.js';
|
|
12
13
|
import { CircuitType } from '../types/shared.js';
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -93,6 +94,11 @@ export class VerificationKeyAsFields {
|
|
|
93
94
|
public hash: Fr,
|
|
94
95
|
) {}
|
|
95
96
|
|
|
97
|
+
static async fromKey(key: Fr[]) {
|
|
98
|
+
const hash = await hashVK(key);
|
|
99
|
+
return new VerificationKeyAsFields(key, hash);
|
|
100
|
+
}
|
|
101
|
+
|
|
96
102
|
public get numPublicInputs() {
|
|
97
103
|
return Number(this.key[CIRCUIT_PUBLIC_INPUTS_INDEX]);
|
|
98
104
|
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { BufferReader, FieldReader } from '@aztec/foundation/serialize';
|
|
3
|
-
import type { FieldsOf } from '@aztec/foundation/types';
|
|
4
|
-
import type { UInt32 } from '../types/index.js';
|
|
5
|
-
/**
|
|
6
|
-
* Maximum block number.
|
|
7
|
-
*/
|
|
8
|
-
export declare class MaxBlockNumber {
|
|
9
|
-
/**
|
|
10
|
-
* Whether a max block number was requested.
|
|
11
|
-
*/
|
|
12
|
-
isSome: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* The requested max block number, if isSome is true.
|
|
15
|
-
*/
|
|
16
|
-
value: UInt32;
|
|
17
|
-
constructor(
|
|
18
|
-
/**
|
|
19
|
-
* Whether a max block number was requested.
|
|
20
|
-
*/
|
|
21
|
-
isSome: boolean,
|
|
22
|
-
/**
|
|
23
|
-
* The requested max block number, if isSome is true.
|
|
24
|
-
*/
|
|
25
|
-
value: UInt32);
|
|
26
|
-
/**
|
|
27
|
-
* Serialize as a buffer.
|
|
28
|
-
* @returns The buffer.
|
|
29
|
-
*/
|
|
30
|
-
toBuffer(): Buffer<ArrayBufferLike>;
|
|
31
|
-
toFields(): Fr[];
|
|
32
|
-
/**
|
|
33
|
-
* Deserializes MaxBlockNumber from a buffer or reader.
|
|
34
|
-
* @param buffer - Buffer to read from.
|
|
35
|
-
* @returns The MaxBlockNumber.
|
|
36
|
-
*/
|
|
37
|
-
static fromBuffer(buffer: Buffer | BufferReader): MaxBlockNumber;
|
|
38
|
-
static fromFields(fields: Fr[] | FieldReader): MaxBlockNumber;
|
|
39
|
-
static empty(): MaxBlockNumber;
|
|
40
|
-
isEmpty(): boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Create a new instance from a fields dictionary.
|
|
43
|
-
* @param fields - The dictionary.
|
|
44
|
-
* @returns A new instance.
|
|
45
|
-
*/
|
|
46
|
-
static from(fields: FieldsOf<MaxBlockNumber>): MaxBlockNumber;
|
|
47
|
-
/**
|
|
48
|
-
* Serialize into a field array. Low-level utility.
|
|
49
|
-
* @param fields - Object with fields.
|
|
50
|
-
* @returns The array.
|
|
51
|
-
*/
|
|
52
|
-
static getFields(fields: FieldsOf<MaxBlockNumber>): readonly [boolean, number];
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=max_block_number.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"max_block_number.d.ts","sourceRoot":"","sources":["../../src/tx/max_block_number.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAwC,MAAM,6BAA6B,CAAC;AAC9G,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;GAEG;AACH,qBAAa,cAAc;IAEvB;;OAEG;IACI,MAAM,EAAE,OAAO;IACtB;;OAEG;IACI,KAAK,EAAE,MAAM;;IAPpB;;OAEG;IACI,MAAM,EAAE,OAAO;IACtB;;OAEG;IACI,KAAK,EAAE,MAAM;IAGtB;;;OAGG;IACH,QAAQ;IAIR,QAAQ,IAAI,EAAE,EAAE;IAUhB;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,cAAc;IAKhE,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,WAAW,GAAG,cAAc;IAK7D,MAAM,CAAC,KAAK;IAIZ,OAAO,IAAI,OAAO;IAIlB;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,cAAc,CAAC,GAAG,cAAc;IAI7D;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,cAAc,CAAC;CAGlD"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { MAX_BLOCK_NUMBER_LENGTH } from '@aztec/constants';
|
|
2
|
-
import { BufferReader, FieldReader, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize';
|
|
3
|
-
/**
|
|
4
|
-
* Maximum block number.
|
|
5
|
-
*/ export class MaxBlockNumber {
|
|
6
|
-
isSome;
|
|
7
|
-
value;
|
|
8
|
-
constructor(/**
|
|
9
|
-
* Whether a max block number was requested.
|
|
10
|
-
*/ isSome, /**
|
|
11
|
-
* The requested max block number, if isSome is true.
|
|
12
|
-
*/ value){
|
|
13
|
-
this.isSome = isSome;
|
|
14
|
-
this.value = value;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Serialize as a buffer.
|
|
18
|
-
* @returns The buffer.
|
|
19
|
-
*/ toBuffer() {
|
|
20
|
-
return serializeToBuffer(...MaxBlockNumber.getFields(this));
|
|
21
|
-
}
|
|
22
|
-
toFields() {
|
|
23
|
-
const fields = serializeToFields(...MaxBlockNumber.getFields(this));
|
|
24
|
-
if (fields.length !== MAX_BLOCK_NUMBER_LENGTH) {
|
|
25
|
-
throw new Error(`Invalid number of fields for MaxBlockNumber. Expected ${MAX_BLOCK_NUMBER_LENGTH}, got ${fields.length}`);
|
|
26
|
-
}
|
|
27
|
-
return fields;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Deserializes MaxBlockNumber from a buffer or reader.
|
|
31
|
-
* @param buffer - Buffer to read from.
|
|
32
|
-
* @returns The MaxBlockNumber.
|
|
33
|
-
*/ static fromBuffer(buffer) {
|
|
34
|
-
const reader = BufferReader.asReader(buffer);
|
|
35
|
-
return new MaxBlockNumber(reader.readBoolean(), reader.readNumber());
|
|
36
|
-
}
|
|
37
|
-
static fromFields(fields) {
|
|
38
|
-
const reader = FieldReader.asReader(fields);
|
|
39
|
-
return new MaxBlockNumber(reader.readBoolean(), reader.readU32());
|
|
40
|
-
}
|
|
41
|
-
static empty() {
|
|
42
|
-
return new MaxBlockNumber(false, 0);
|
|
43
|
-
}
|
|
44
|
-
isEmpty() {
|
|
45
|
-
return !this.isSome && this.value === 0;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Create a new instance from a fields dictionary.
|
|
49
|
-
* @param fields - The dictionary.
|
|
50
|
-
* @returns A new instance.
|
|
51
|
-
*/ static from(fields) {
|
|
52
|
-
return new MaxBlockNumber(...MaxBlockNumber.getFields(fields));
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Serialize into a field array. Low-level utility.
|
|
56
|
-
* @param fields - Object with fields.
|
|
57
|
-
* @returns The array.
|
|
58
|
-
*/ static getFields(fields) {
|
|
59
|
-
return [
|
|
60
|
-
fields.isSome,
|
|
61
|
-
fields.value
|
|
62
|
-
];
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { MAX_BLOCK_NUMBER_LENGTH } from '@aztec/constants';
|
|
2
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
-
import { BufferReader, FieldReader, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize';
|
|
4
|
-
import type { FieldsOf } from '@aztec/foundation/types';
|
|
5
|
-
|
|
6
|
-
import type { UInt32 } from '../types/index.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Maximum block number.
|
|
10
|
-
*/
|
|
11
|
-
export class MaxBlockNumber {
|
|
12
|
-
constructor(
|
|
13
|
-
/**
|
|
14
|
-
* Whether a max block number was requested.
|
|
15
|
-
*/
|
|
16
|
-
public isSome: boolean,
|
|
17
|
-
/**
|
|
18
|
-
* The requested max block number, if isSome is true.
|
|
19
|
-
*/
|
|
20
|
-
public value: UInt32,
|
|
21
|
-
) {}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Serialize as a buffer.
|
|
25
|
-
* @returns The buffer.
|
|
26
|
-
*/
|
|
27
|
-
toBuffer() {
|
|
28
|
-
return serializeToBuffer(...MaxBlockNumber.getFields(this));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
toFields(): Fr[] {
|
|
32
|
-
const fields = serializeToFields(...MaxBlockNumber.getFields(this));
|
|
33
|
-
if (fields.length !== MAX_BLOCK_NUMBER_LENGTH) {
|
|
34
|
-
throw new Error(
|
|
35
|
-
`Invalid number of fields for MaxBlockNumber. Expected ${MAX_BLOCK_NUMBER_LENGTH}, got ${fields.length}`,
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
return fields;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Deserializes MaxBlockNumber from a buffer or reader.
|
|
43
|
-
* @param buffer - Buffer to read from.
|
|
44
|
-
* @returns The MaxBlockNumber.
|
|
45
|
-
*/
|
|
46
|
-
static fromBuffer(buffer: Buffer | BufferReader): MaxBlockNumber {
|
|
47
|
-
const reader = BufferReader.asReader(buffer);
|
|
48
|
-
return new MaxBlockNumber(reader.readBoolean(), reader.readNumber());
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
static fromFields(fields: Fr[] | FieldReader): MaxBlockNumber {
|
|
52
|
-
const reader = FieldReader.asReader(fields);
|
|
53
|
-
return new MaxBlockNumber(reader.readBoolean(), reader.readU32());
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
static empty() {
|
|
57
|
-
return new MaxBlockNumber(false, 0);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
isEmpty(): boolean {
|
|
61
|
-
return !this.isSome && this.value === 0;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Create a new instance from a fields dictionary.
|
|
66
|
-
* @param fields - The dictionary.
|
|
67
|
-
* @returns A new instance.
|
|
68
|
-
*/
|
|
69
|
-
static from(fields: FieldsOf<MaxBlockNumber>): MaxBlockNumber {
|
|
70
|
-
return new MaxBlockNumber(...MaxBlockNumber.getFields(fields));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Serialize into a field array. Low-level utility.
|
|
75
|
-
* @param fields - Object with fields.
|
|
76
|
-
* @returns The array.
|
|
77
|
-
*/
|
|
78
|
-
static getFields(fields: FieldsOf<MaxBlockNumber>) {
|
|
79
|
-
return [fields.isSome, fields.value] as const;
|
|
80
|
-
}
|
|
81
|
-
}
|