@aztec/stdlib 0.86.0-nightly.20250513 → 0.86.0-nightly.20250514

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.
@@ -166,29 +166,16 @@ import { AZTEC_INITIALIZER_ATTRIBUTE, AZTEC_INTERNAL_ATTRIBUTE, AZTEC_PRIVATE_AT
166
166
  };
167
167
  }
168
168
  function getFunctionType(fn) {
169
- if (fn.custom_attributes.some((attr)=>attr.endsWith(AZTEC_PRIVATE_ATTRIBUTE))) {
169
+ if (fn.custom_attributes.includes(AZTEC_PRIVATE_ATTRIBUTE)) {
170
170
  return FunctionType.PRIVATE;
171
- } else if (fn.custom_attributes.some((attr)=>attr.endsWith(AZTEC_PUBLIC_ATTRIBUTE))) {
171
+ } else if (fn.custom_attributes.includes(AZTEC_PUBLIC_ATTRIBUTE)) {
172
172
  return FunctionType.PUBLIC;
173
- } else if (fn.custom_attributes.some((attr)=>attr.endsWith(AZTEC_UTILITY_ATTRIBUTE))) {
173
+ } else if (fn.custom_attributes.includes(AZTEC_UTILITY_ATTRIBUTE)) {
174
174
  return FunctionType.UTILITY;
175
175
  } else {
176
176
  throw new Error(`Invalid function type for a noir contract function ${fn.name}`);
177
177
  }
178
178
  }
179
- // TODO(https://github.com/noir-lang/noir/issues/7912): Replace the above function with this one once the linked issue
180
- // is fixed.
181
- // function getFunctionType(fn: NoirCompiledContractFunction): FunctionType {
182
- // if (fn.custom_attributes.includes(AZTEC_PRIVATE_ATTRIBUTE)) {
183
- // return FunctionType.PRIVATE;
184
- // } else if (fn.custom_attributes.includes(AZTEC_PUBLIC_ATTRIBUTE)) {
185
- // return FunctionType.PUBLIC;
186
- // } else if (fn.custom_attributes.includes(AZTEC_UTILITY_ATTRIBUTE)) {
187
- // return FunctionType.UTILITY;
188
- // } else {
189
- // throw new Error(`Invalid function type for a noir contract function ${fn.name}`);
190
- // }
191
- // }
192
179
  /**
193
180
  * Returns true if the first parameter is kernel function inputs.
194
181
  *
@@ -5,6 +5,7 @@ import type { ReadOnlyFileStore } from './interface.js';
5
5
  export declare class HttpFileStore implements ReadOnlyFileStore {
6
6
  private readonly baseUrl;
7
7
  private readonly log;
8
+ private readonly axiosInstance;
8
9
  private readonly fetch;
9
10
  constructor(baseUrl: string, log?: Logger);
10
11
  read(pathOrUrl: string): Promise<Buffer>;
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/file-store/http.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AASlE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,qBAAa,aAAc,YAAW,iBAAiB;IAGzC,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,GAAG;IAFlE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;gBAER,OAAO,EAAE,MAAM,EAAmB,GAAG,GAAE,MAA+C;IAYtG,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAUxC,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY5D,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAMxD,OAAO,CAAC,MAAM;CAGf"}
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/file-store/http.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAUlE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,qBAAa,aAAc,YAAW,iBAAiB;IAIzC,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,GAAG;IAHlE,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA+D;gBAExD,OAAO,EAAE,MAAM,EAAmB,GAAG,GAAE,MAA+C;IAatG,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAUxC,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW5D,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAUxD,OAAO,CAAC,MAAM;CAGf"}
@@ -1,19 +1,21 @@
1
1
  import { createLogger } from '@aztec/foundation/log';
2
2
  import { makeBackoff, retry } from '@aztec/foundation/retry';
3
+ import axios from 'axios';
3
4
  import { createWriteStream } from 'fs';
4
5
  import { mkdir } from 'fs/promises';
5
6
  import { dirname } from 'path';
6
- import { Readable } from 'stream';
7
7
  import { finished } from 'stream/promises';
8
8
  export class HttpFileStore {
9
9
  baseUrl;
10
10
  log;
11
+ axiosInstance;
11
12
  fetch;
12
13
  constructor(baseUrl, log = createLogger('stdlib:http-file-store')){
13
14
  this.baseUrl = baseUrl;
14
15
  this.log = log;
15
- this.fetch = async (...args)=>{
16
- return await retry(()=>fetch(...args), `Fetching ${args[0]}`, makeBackoff([
16
+ this.axiosInstance = axios.create();
17
+ this.fetch = async (config)=>{
18
+ return await retry(()=>this.axiosInstance.request(config), `Fetching ${config.url}`, makeBackoff([
17
19
  1,
18
20
  1,
19
21
  3
@@ -22,30 +24,44 @@ export class HttpFileStore {
22
24
  }
23
25
  async read(pathOrUrl) {
24
26
  const url = this.getUrl(pathOrUrl);
25
- const response = await this.fetch(url);
26
- if (response.ok) {
27
- return Buffer.from(await response.arrayBuffer());
28
- } else {
29
- throw new Error(`Error fetching file from ${url}: ${response.statusText}`);
27
+ try {
28
+ const response = await this.fetch({
29
+ url,
30
+ method: 'GET',
31
+ responseType: 'arraybuffer'
32
+ });
33
+ return Buffer.from(response.data);
34
+ } catch (error) {
35
+ throw new Error(`Error fetching file from ${url}: ${error instanceof Error ? error.message : String(error)}`);
30
36
  }
31
37
  }
32
38
  async download(pathOrUrl, destPath) {
33
39
  const url = this.getUrl(pathOrUrl);
34
- const response = await this.fetch(url);
35
- if (response.ok) {
40
+ try {
41
+ const response = await this.fetch({
42
+ url,
43
+ method: 'GET',
44
+ responseType: 'stream'
45
+ });
36
46
  await mkdir(dirname(destPath), {
37
47
  recursive: true
38
48
  });
39
- // Typescript complains about Readable.fromWeb, hence the cast
40
- await finished(Readable.fromWeb(response.body).pipe(createWriteStream(destPath)));
41
- } else {
42
- throw new Error(`Error fetching file from ${url}: ${response.statusText}`);
49
+ await finished(response.data.pipe(createWriteStream(destPath)));
50
+ } catch (error) {
51
+ throw new Error(`Error fetching file from ${url}: ${error instanceof Error ? error.message : String(error)}`);
43
52
  }
44
53
  }
45
54
  async exists(pathOrUrl) {
46
55
  const url = this.getUrl(pathOrUrl);
47
- const response = await this.fetch(url);
48
- return response.ok;
56
+ try {
57
+ await this.fetch({
58
+ url,
59
+ method: 'HEAD'
60
+ });
61
+ return true;
62
+ } catch (error) {
63
+ return false;
64
+ }
49
65
  }
50
66
  getUrl(path) {
51
67
  return URL.canParse(path) ? path : `${this.baseUrl.replace(/\/$/, '')}/${path}`;
@@ -15,5 +15,10 @@ export declare class InboxLeaf {
15
15
  toBuffer(): Buffer;
16
16
  fromBuffer(buffer: Buffer | BufferReader): InboxLeaf;
17
17
  static smallestIndexFromL2Block(l2block: bigint): bigint;
18
+ /**
19
+ * Returns the range of valid indices for a given L2 block.
20
+ * Start index is inclusive, end index is exclusive.
21
+ */
22
+ static indexRangeFromL2Block(l2block: bigint): [bigint, bigint];
18
23
  }
19
24
  //# sourceMappingURL=inbox_leaf.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"inbox_leaf.d.ts","sourceRoot":"","sources":["../../src/messaging/inbox_leaf.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAE9E,qBAAa,SAAS;IAElB,2CAA2C;aAC3B,KAAK,EAAE,MAAM;IAC7B,wCAAwC;aACxB,IAAI,EAAE,EAAE;;IAHxB,2CAA2C;IAC3B,KAAK,EAAE,MAAM;IAC7B,wCAAwC;IACxB,IAAI,EAAE,EAAE;IAG1B,QAAQ,IAAI,MAAM;IAIlB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAOpD,MAAM,CAAC,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;CAGzD"}
1
+ {"version":3,"file":"inbox_leaf.d.ts","sourceRoot":"","sources":["../../src/messaging/inbox_leaf.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAE9E,qBAAa,SAAS;IAElB,2CAA2C;aAC3B,KAAK,EAAE,MAAM;IAC7B,wCAAwC;aACxB,IAAI,EAAE,EAAE;;IAHxB,2CAA2C;IAC3B,KAAK,EAAE,MAAM;IAC7B,wCAAwC;IACxB,IAAI,EAAE,EAAE;IAG1B,QAAQ,IAAI,MAAM;IAIlB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAOpD,MAAM,CAAC,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAIxD;;;OAGG;IACH,MAAM,CAAC,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;CAKhE"}
@@ -24,4 +24,15 @@ export class InboxLeaf {
24
24
  static smallestIndexFromL2Block(l2block) {
25
25
  return (l2block - BigInt(INITIAL_L2_BLOCK_NUM)) * BigInt(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
26
26
  }
27
+ /**
28
+ * Returns the range of valid indices for a given L2 block.
29
+ * Start index is inclusive, end index is exclusive.
30
+ */ static indexRangeFromL2Block(l2block) {
31
+ const start = this.smallestIndexFromL2Block(l2block);
32
+ const end = start + BigInt(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
33
+ return [
34
+ start,
35
+ end
36
+ ];
37
+ }
27
38
  }
@@ -35,7 +35,7 @@ export declare class BlockAttestation extends Gossipable {
35
35
  /** The signature of the block attester */
36
36
  signature: Signature);
37
37
  static get schema(): ZodFor<BlockAttestation>;
38
- p2pMessageIdentifier(): Promise<Buffer32>;
38
+ generateP2PMessageIdentifier(): Promise<Buffer32>;
39
39
  get archive(): Fr;
40
40
  get slotNumber(): Fr;
41
41
  /**Get sender
@@ -1 +1 @@
1
- {"version":3,"file":"block_attestation.d.ts","sourceRoot":"","sources":["../../src/p2p/block_attestation.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAC5D,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAI9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,qBAAa,oBAAqB,SAAQ,QAAQ;gBACpC,IAAI,EAAE,MAAM;CAGzB;AAED;;;;;GAKG;AACH,qBAAa,gBAAiB,SAAQ,UAAU;IAM5C,2CAA2C;aAC3B,WAAW,EAAE,EAAE;IAE/B,iEAAiE;aACjD,OAAO,EAAE,gBAAgB;IAEzC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SAAQ,QAAQ;gBACpC,IAAI,EAAE,MAAM;CAGzB;AAED;;;;;GAKG;AACH,qBAAa,gBAAiB,SAAQ,UAAU;IAM5C,2CAA2C;aAC3B,WAAW,EAAE,EAAE;IAE/B,iEAAiE;aACjD,OAAO,EAAE,gBAAgB;IAEzC,0CAA0C;aAC1B,SAAS,EAAE,SAAS;IAZtC,OAAgB,QAAQ,YAA+B;IAEvD,OAAO,CAAC,MAAM,CAAyB;;IAGrC,2CAA2C;IAC3B,WAAW,EAAE,EAAE;IAE/B,iEAAiE;IACjD,OAAO,EAAE,gBAAgB;IAEzC,0CAA0C;IAC1B,SAAS,EAAE,SAAS;IAKtC,MAAM,KAAK,MAAM,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAQ5C;IAEQ,4BAA4B,IAAI,OAAO,CAAC,QAAQ,CAAC;IAI1D,IAAI,OAAO,IAAI,EAAE,CAEhB;IAED,IAAI,UAAU,IAAI,EAAE,CAEnB;IAED;;;;OAIG;IACH,SAAS,IAAI,UAAU;IAWvB,UAAU,IAAI,MAAM;IAIpB,QAAQ,IAAI,MAAM;IAIlB,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,GAAG,gBAAgB;IAS/D,MAAM,CAAC,KAAK,IAAI,gBAAgB;IAIhC,OAAO,IAAI,MAAM;CAGlB"}
@@ -34,7 +34,7 @@ export class BlockAttestationHash extends Buffer32 {
34
34
  signature: Signature.schema
35
35
  }).transform((obj)=>new BlockAttestation(obj.blockNumber, obj.payload, obj.signature));
36
36
  }
37
- p2pMessageIdentifier() {
37
+ generateP2PMessageIdentifier() {
38
38
  return Promise.resolve(new BlockAttestationHash(keccak256(this.signature.toBuffer())));
39
39
  }
40
40
  get archive() {
@@ -38,7 +38,7 @@ export declare class BlockProposal extends Gossipable {
38
38
  signature: Signature,
39
39
  /** The transactions in the block */
40
40
  txs?: Tx[] | undefined);
41
- p2pMessageIdentifier(): Promise<Buffer32>;
41
+ generateP2PMessageIdentifier(): Promise<Buffer32>;
42
42
  get archive(): Fr;
43
43
  get slotNumber(): Fr;
44
44
  static createProposalFromSigner(blockNumber: Fr, payload: ConsensusPayload, txs: Tx[], payloadSigner: (payload: Buffer32) => Promise<Signature>): Promise<BlockProposal>;
@@ -1 +1 @@
1
- {"version":3,"file":"block_proposal.d.ts","sourceRoot":"","sources":["../../src/p2p/block_proposal.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAC5D,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAE9E,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAM7C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,qBAAa,iBAAkB,SAAQ,QAAQ;gBACjC,IAAI,EAAE,MAAM;CAGzB;AAED;;;;;GAKG;AACH,qBAAa,aAAc,SAAQ,UAAU;IAMzC,8BAA8B;aACd,WAAW,EAAE,EAAE;IAE/B,iEAAiE;aACjD,OAAO,EAAE,gBAAgB;IAEzC,sEAAsE;aACtD,SAAS,EAAE,SAAS;IAGpC,oCAAoC;aACpB,GAAG,CAAC;IAhBtB,OAAgB,QAAQ,YAA4B;IAEpD,OAAO,CAAC,MAAM,CAAyB;;IAGrC,8BAA8B;IACd,WAAW,EAAE,EAAE;IAE/B,iEAAiE;IACjD,OAAO,EAAE,gBAAgB;IAEzC,sEAAsE;IACtD,SAAS,EAAE,SAAS;IAGpC,oCAAoC;IACpB,GAAG,CAAC,kBAAM;IAKnB,oB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,SAAS;IAGpC,oCAAoC;aACpB,GAAG,CAAC;IAhBtB,OAAgB,QAAQ,YAA4B;IAEpD,OAAO,CAAC,MAAM,CAAyB;;IAGrC,8BAA8B;IACd,WAAW,EAAE,EAAE;IAE/B,iEAAiE;IACjD,OAAO,EAAE,gBAAgB;IAEzC,sEAAsE;IACtD,SAAS,EAAE,SAAS;IAGpC,oCAAoC;IACpB,GAAG,CAAC,kBAAM;IAKnB,4BAA4B,IAAI,OAAO,CAAC,QAAQ,CAAC;IAI1D,IAAI,OAAO,IAAI,EAAE,CAEhB;IAED,IAAI,UAAU,IAAI,EAAE,CAEnB;WAEY,wBAAwB,CACnC,WAAW,EAAE,EAAE,EACf,OAAO,EAAE,gBAAgB,EAEzB,GAAG,EAAE,EAAE,EAAE,EACT,aAAa,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,OAAO,CAAC,SAAS,CAAC;IAQ1D;;OAEG;IACH,SAAS;IAUT,UAAU;IAIV,QAAQ,IAAI,MAAM;IASlB,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,GAAG,aAAa;IAe5D,OAAO,IAAI,MAAM;CAQlB"}
@@ -29,7 +29,7 @@ export class BlockProposalHash extends Buffer32 {
29
29
  /** The transactions in the block */ txs){
30
30
  super(), this.blockNumber = blockNumber, this.payload = payload, this.signature = signature, this.txs = txs;
31
31
  }
32
- p2pMessageIdentifier() {
32
+ generateP2PMessageIdentifier() {
33
33
  return Promise.resolve(new BlockProposalHash(keccak256(this.signature.toBuffer())));
34
34
  }
35
35
  get archive() {
@@ -1,13 +1,23 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  /// <reference types="node" resolution-mode="require"/>
3
- import type { Buffer32 } from '@aztec/foundation/buffer';
3
+ import { Buffer32 } from '@aztec/foundation/buffer';
4
4
  import type { TopicType } from './topic_type.js';
5
+ export declare class P2PMessage {
6
+ readonly publishTime: Date;
7
+ readonly id: Buffer32;
8
+ readonly payload: Buffer;
9
+ constructor(publishTime: Date, id: Buffer32, payload: Buffer);
10
+ static fromGossipable(message: Gossipable): Promise<P2PMessage>;
11
+ static fromMessageData(messageData: Buffer): P2PMessage;
12
+ toMessageData(): Buffer;
13
+ }
5
14
  /**
6
15
  * Gossipable
7
16
  *
8
17
  * Any class which extends gossipable will be able to be Gossiped over the p2p network
9
18
  */
10
19
  export declare abstract class Gossipable {
20
+ private cachedId;
11
21
  /** p2p Topic
12
22
  *
13
23
  * - The p2p topic identifier, this determines how the message is handled
@@ -17,12 +27,14 @@ export declare abstract class Gossipable {
17
27
  *
18
28
  * - A digest of the message information, this key is used for deduplication
19
29
  */
20
- abstract p2pMessageIdentifier(): Promise<Buffer32>;
30
+ p2pMessageIdentifier(): Promise<Buffer32>;
31
+ abstract generateP2PMessageIdentifier(): Promise<Buffer32>;
21
32
  /** To Buffer
22
33
  *
23
34
  * - Serialization method
24
35
  */
25
36
  abstract toBuffer(): Buffer;
37
+ toMessage(): Buffer;
26
38
  /**
27
39
  * Get the size of the gossipable object.
28
40
  *
@@ -1 +1 @@
1
- {"version":3,"file":"gossipable.d.ts","sourceRoot":"","sources":["../../src/p2p/gossipable.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD;;;;GAIG;AACH,8BAAsB,UAAU;IAC9B;;;OAGG;IACH,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC;IAE3B;;;OAGG;IACH,QAAQ,CAAC,oBAAoB,IAAI,OAAO,CAAC,QAAQ,CAAC;IAElD;;;OAGG;IACH,QAAQ,CAAC,QAAQ,IAAI,MAAM;IAE3B;;;;OAIG;IACH,QAAQ,CAAC,OAAO,IAAI,MAAM;CAC3B"}
1
+ {"version":3,"file":"gossipable.d.ts","sourceRoot":"","sources":["../../src/p2p/gossipable.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAGpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,qBAAa,UAAU;aACO,WAAW,EAAE,IAAI;aAAkB,EAAE,EAAE,QAAQ;aAAkB,OAAO,EAAE,MAAM;gBAAhF,WAAW,EAAE,IAAI,EAAkB,EAAE,EAAE,QAAQ,EAAkB,OAAO,EAAE,MAAM;WAE/F,cAAc,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAIrE,MAAM,CAAC,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,UAAU;IAQvD,aAAa,IAAI,MAAM;CAOxB;AAED;;;;GAIG;AACH,8BAAsB,UAAU;IAC9B,OAAO,CAAC,QAAQ,CAAuB;IACvC;;;OAGG;IACH,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC;IAE3B;;;OAGG;IACG,oBAAoB,IAAI,OAAO,CAAC,QAAQ,CAAC;IAQ/C,QAAQ,CAAC,4BAA4B,IAAI,OAAO,CAAC,QAAQ,CAAC;IAE1D;;;OAGG;IACH,QAAQ,CAAC,QAAQ,IAAI,MAAM;IAE3B,SAAS,IAAI,MAAM;IAInB;;;;OAIG;IACH,QAAQ,CAAC,OAAO,IAAI,MAAM;CAC3B"}
@@ -1,10 +1,53 @@
1
+ import { Buffer32 } from '@aztec/foundation/buffer';
2
+ import { BufferReader, bigintToUInt64BE, serializeToBuffer } from '@aztec/foundation/serialize';
3
+ export class P2PMessage {
4
+ publishTime;
5
+ id;
6
+ payload;
7
+ constructor(publishTime, id, payload){
8
+ this.publishTime = publishTime;
9
+ this.id = id;
10
+ this.payload = payload;
11
+ }
12
+ static async fromGossipable(message) {
13
+ return new P2PMessage(new Date(), await message.p2pMessageIdentifier(), message.toBuffer());
14
+ }
15
+ static fromMessageData(messageData) {
16
+ const reader = new BufferReader(messageData);
17
+ const publishTime = reader.readUInt64();
18
+ const id = Buffer32.fromBuffer(reader);
19
+ const payload = reader.readBuffer();
20
+ return new P2PMessage(new Date(Number(publishTime)), id, payload);
21
+ }
22
+ toMessageData() {
23
+ return serializeToBuffer([
24
+ bigintToUInt64BE(BigInt(this.publishTime.getTime())),
25
+ this.id,
26
+ serializeToBuffer(this.payload.length, this.payload)
27
+ ]);
28
+ }
29
+ }
1
30
  /**
2
31
  * Gossipable
3
32
  *
4
33
  * Any class which extends gossipable will be able to be Gossiped over the p2p network
5
34
  */ export class Gossipable {
35
+ cachedId;
6
36
  /** p2p Topic
7
37
  *
8
38
  * - The p2p topic identifier, this determines how the message is handled
9
39
  */ static p2pTopic;
40
+ /** p2p Message Identifier
41
+ *
42
+ * - A digest of the message information, this key is used for deduplication
43
+ */ async p2pMessageIdentifier() {
44
+ if (this.cachedId) {
45
+ return this.cachedId;
46
+ }
47
+ this.cachedId = await this.generateP2PMessageIdentifier();
48
+ return this.cachedId;
49
+ }
50
+ toMessage() {
51
+ return this.toBuffer();
52
+ }
10
53
  }
package/dest/tx/tx.d.ts CHANGED
@@ -61,7 +61,7 @@ export declare class Tx extends Gossipable {
61
61
  * An array of calldata for the enqueued public function calls and the teardown function call.
62
62
  */
63
63
  publicFunctionCalldata: HashedValues[]);
64
- p2pMessageIdentifier(): Promise<Buffer32>;
64
+ generateP2PMessageIdentifier(): Promise<Buffer32>;
65
65
  hasPublicCalls(): boolean;
66
66
  numberOfPublicCalls(): number;
67
67
  getNonRevertiblePublicCallRequestsWithCalldata(): PublicCallRequestWithCalldata[];
@@ -1 +1 @@
1
- {"version":3,"file":"tx.d.ts","sourceRoot":"","sources":["../../src/tx/tx.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAyD,MAAM,6BAA6B,CAAC;AAClH,OAAO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IACU,aAAa,CAAC,UAAU,EAAE,YAAY,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAIpF;;;;OAIG;IACG,yBAAyB,CAAC,UAAU,EAAE,OAAO,EAAE,IAAI,GAAE,OAAe,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAWxG;;;;;OAKG;IACG,uBAAuB,CAAC,SAAS,EAAE,aAAa,EAAE,EAAE,IAAI,GAAE,OAAe,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAiB7G;;;OAGG;IACG,SAAS,CAAC,cAAc,UAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAUxD;;;;;OAKG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM;IAItB,cAAc,IAAI,GAAG,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC;IAUnC,mCAAmC;IAC7B,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IAmBlC,OAAO;IASP;;;OAGG;IACH,gCAAgC;IAShC;;;;OAIG;WACU,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAIvD;;;;OAIG;WACU,SAAS,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAIhE;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE;IAaxB;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,WAAW,UAAQ;IASjC;;;;;;;;;;OAUG;IAEU,kBAAkB;CAWhC;AAED,uEAAuE;AACvE,KAAK,OAAO,GAAG;IAAqB,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC"}
package/dest/tx/tx.js CHANGED
@@ -35,7 +35,7 @@ import { TxHash } from './tx_hash.js';
35
35
  super(), this.data = data, this.clientIvcProof = clientIvcProof, this.contractClassLogs = contractClassLogs, this.publicFunctionCalldata = publicFunctionCalldata;
36
36
  }
37
37
  // Gossipable method
38
- async p2pMessageIdentifier() {
38
+ async generateP2PMessageIdentifier() {
39
39
  return new Buffer32((await this.getTxHash()).toBuffer());
40
40
  }
41
41
  hasPublicCalls() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/stdlib",
3
- "version": "0.86.0-nightly.20250513",
3
+ "version": "0.86.0-nightly.20250514",
4
4
  "type": "module",
5
5
  "inherits": [
6
6
  "../package.common.json",
@@ -66,13 +66,14 @@
66
66
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
67
67
  },
68
68
  "dependencies": {
69
- "@aztec/bb.js": "0.86.0-nightly.20250513",
70
- "@aztec/blob-lib": "0.86.0-nightly.20250513",
71
- "@aztec/constants": "0.86.0-nightly.20250513",
72
- "@aztec/ethereum": "0.86.0-nightly.20250513",
73
- "@aztec/foundation": "0.86.0-nightly.20250513",
74
- "@aztec/noir-noirc_abi": "0.86.0-nightly.20250513",
69
+ "@aztec/bb.js": "0.86.0-nightly.20250514",
70
+ "@aztec/blob-lib": "0.86.0-nightly.20250514",
71
+ "@aztec/constants": "0.86.0-nightly.20250514",
72
+ "@aztec/ethereum": "0.86.0-nightly.20250514",
73
+ "@aztec/foundation": "0.86.0-nightly.20250514",
74
+ "@aztec/noir-noirc_abi": "0.86.0-nightly.20250514",
75
75
  "@google-cloud/storage": "^7.15.0",
76
+ "axios": "^1.9.0",
76
77
  "lodash.chunk": "^4.2.0",
77
78
  "lodash.isequal": "^4.5.0",
78
79
  "lodash.omit": "^4.5.0",
@@ -216,31 +216,17 @@ function generateFunctionArtifact(
216
216
  }
217
217
 
218
218
  function getFunctionType(fn: NoirCompiledContractFunction): FunctionType {
219
- if (fn.custom_attributes.some(attr => attr.endsWith(AZTEC_PRIVATE_ATTRIBUTE))) {
219
+ if (fn.custom_attributes.includes(AZTEC_PRIVATE_ATTRIBUTE)) {
220
220
  return FunctionType.PRIVATE;
221
- } else if (fn.custom_attributes.some(attr => attr.endsWith(AZTEC_PUBLIC_ATTRIBUTE))) {
221
+ } else if (fn.custom_attributes.includes(AZTEC_PUBLIC_ATTRIBUTE)) {
222
222
  return FunctionType.PUBLIC;
223
- } else if (fn.custom_attributes.some(attr => attr.endsWith(AZTEC_UTILITY_ATTRIBUTE))) {
223
+ } else if (fn.custom_attributes.includes(AZTEC_UTILITY_ATTRIBUTE)) {
224
224
  return FunctionType.UTILITY;
225
225
  } else {
226
226
  throw new Error(`Invalid function type for a noir contract function ${fn.name}`);
227
227
  }
228
228
  }
229
229
 
230
- // TODO(https://github.com/noir-lang/noir/issues/7912): Replace the above function with this one once the linked issue
231
- // is fixed.
232
- // function getFunctionType(fn: NoirCompiledContractFunction): FunctionType {
233
- // if (fn.custom_attributes.includes(AZTEC_PRIVATE_ATTRIBUTE)) {
234
- // return FunctionType.PRIVATE;
235
- // } else if (fn.custom_attributes.includes(AZTEC_PUBLIC_ATTRIBUTE)) {
236
- // return FunctionType.PUBLIC;
237
- // } else if (fn.custom_attributes.includes(AZTEC_UTILITY_ATTRIBUTE)) {
238
- // return FunctionType.UTILITY;
239
- // } else {
240
- // throw new Error(`Invalid function type for a noir contract function ${fn.name}`);
241
- // }
242
- // }
243
-
244
230
  /**
245
231
  * Returns true if the first parameter is kernel function inputs.
246
232
  *
@@ -1,6 +1,7 @@
1
1
  import { type Logger, createLogger } from '@aztec/foundation/log';
2
2
  import { makeBackoff, retry } from '@aztec/foundation/retry';
3
3
 
4
+ import axios, { type AxiosInstance, type AxiosRequestConfig, type AxiosResponse } from 'axios';
4
5
  import { createWriteStream } from 'fs';
5
6
  import { mkdir } from 'fs/promises';
6
7
  import { dirname } from 'path';
@@ -10,13 +11,15 @@ import { finished } from 'stream/promises';
10
11
  import type { ReadOnlyFileStore } from './interface.js';
11
12
 
12
13
  export class HttpFileStore implements ReadOnlyFileStore {
13
- private readonly fetch: typeof fetch;
14
+ private readonly axiosInstance: AxiosInstance;
15
+ private readonly fetch: <T>(config: AxiosRequestConfig) => Promise<AxiosResponse<T>>;
14
16
 
15
17
  constructor(private readonly baseUrl: string, private readonly log: Logger = createLogger('stdlib:http-file-store')) {
16
- this.fetch = async (...args: Parameters<typeof fetch>): Promise<Response> => {
18
+ this.axiosInstance = axios.create();
19
+ this.fetch = async <T>(config: AxiosRequestConfig) => {
17
20
  return await retry(
18
- () => fetch(...args),
19
- `Fetching ${args[0]}`,
21
+ () => this.axiosInstance.request<T>(config),
22
+ `Fetching ${config.url}`,
20
23
  makeBackoff([1, 1, 3]),
21
24
  this.log,
22
25
  /*failSilently=*/ true,
@@ -26,30 +29,33 @@ export class HttpFileStore implements ReadOnlyFileStore {
26
29
 
27
30
  public async read(pathOrUrl: string): Promise<Buffer> {
28
31
  const url = this.getUrl(pathOrUrl);
29
- const response = await this.fetch(url);
30
- if (response.ok) {
31
- return Buffer.from(await response.arrayBuffer());
32
- } else {
33
- throw new Error(`Error fetching file from ${url}: ${response.statusText}`);
32
+ try {
33
+ const response = await this.fetch<ArrayBuffer>({ url, method: 'GET', responseType: 'arraybuffer' });
34
+ return Buffer.from(response.data);
35
+ } catch (error) {
36
+ throw new Error(`Error fetching file from ${url}: ${error instanceof Error ? error.message : String(error)}`);
34
37
  }
35
38
  }
36
39
 
37
40
  public async download(pathOrUrl: string, destPath: string): Promise<void> {
38
41
  const url = this.getUrl(pathOrUrl);
39
- const response = await this.fetch(url);
40
- if (response.ok) {
42
+ try {
43
+ const response = await this.fetch<Readable>({ url, method: 'GET', responseType: 'stream' });
41
44
  await mkdir(dirname(destPath), { recursive: true });
42
- // Typescript complains about Readable.fromWeb, hence the cast
43
- await finished(Readable.fromWeb(response.body! as any).pipe(createWriteStream(destPath)));
44
- } else {
45
- throw new Error(`Error fetching file from ${url}: ${response.statusText}`);
45
+ await finished(response.data.pipe(createWriteStream(destPath)));
46
+ } catch (error) {
47
+ throw new Error(`Error fetching file from ${url}: ${error instanceof Error ? error.message : String(error)}`);
46
48
  }
47
49
  }
48
50
 
49
51
  public async exists(pathOrUrl: string): Promise<boolean> {
50
52
  const url = this.getUrl(pathOrUrl);
51
- const response = await this.fetch(url);
52
- return response.ok;
53
+ try {
54
+ await this.fetch<unknown>({ url, method: 'HEAD' });
55
+ return true;
56
+ } catch (error) {
57
+ return false;
58
+ }
53
59
  }
54
60
 
55
61
  private getUrl(path: string): string {
@@ -25,4 +25,14 @@ export class InboxLeaf {
25
25
  static smallestIndexFromL2Block(l2block: bigint): bigint {
26
26
  return (l2block - BigInt(INITIAL_L2_BLOCK_NUM)) * BigInt(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
27
27
  }
28
+
29
+ /**
30
+ * Returns the range of valid indices for a given L2 block.
31
+ * Start index is inclusive, end index is exclusive.
32
+ */
33
+ static indexRangeFromL2Block(l2block: bigint): [bigint, bigint] {
34
+ const start = this.smallestIndexFromL2Block(l2block);
35
+ const end = start + BigInt(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
36
+ return [start, end];
37
+ }
28
38
  }
@@ -53,7 +53,7 @@ export class BlockAttestation extends Gossipable {
53
53
  .transform(obj => new BlockAttestation(obj.blockNumber, obj.payload, obj.signature));
54
54
  }
55
55
 
56
- override p2pMessageIdentifier(): Promise<Buffer32> {
56
+ override generateP2PMessageIdentifier(): Promise<Buffer32> {
57
57
  return Promise.resolve(new BlockAttestationHash(keccak256(this.signature.toBuffer())));
58
58
  }
59
59
 
@@ -49,7 +49,7 @@ export class BlockProposal extends Gossipable {
49
49
  super();
50
50
  }
51
51
 
52
- override p2pMessageIdentifier(): Promise<Buffer32> {
52
+ override generateP2PMessageIdentifier(): Promise<Buffer32> {
53
53
  return Promise.resolve(new BlockProposalHash(keccak256(this.signature.toBuffer())));
54
54
  }
55
55
 
@@ -1,13 +1,39 @@
1
- import type { Buffer32 } from '@aztec/foundation/buffer';
1
+ import { Buffer32 } from '@aztec/foundation/buffer';
2
+ import { BufferReader, bigintToUInt64BE, serializeToBuffer } from '@aztec/foundation/serialize';
2
3
 
3
4
  import type { TopicType } from './topic_type.js';
4
5
 
6
+ export class P2PMessage {
7
+ constructor(public readonly publishTime: Date, public readonly id: Buffer32, public readonly payload: Buffer) {}
8
+
9
+ static async fromGossipable(message: Gossipable): Promise<P2PMessage> {
10
+ return new P2PMessage(new Date(), await message.p2pMessageIdentifier(), message.toBuffer());
11
+ }
12
+
13
+ static fromMessageData(messageData: Buffer): P2PMessage {
14
+ const reader = new BufferReader(messageData);
15
+ const publishTime = reader.readUInt64();
16
+ const id = Buffer32.fromBuffer(reader);
17
+ const payload = reader.readBuffer();
18
+ return new P2PMessage(new Date(Number(publishTime)), id, payload);
19
+ }
20
+
21
+ toMessageData(): Buffer {
22
+ return serializeToBuffer([
23
+ bigintToUInt64BE(BigInt(this.publishTime.getTime())),
24
+ this.id,
25
+ serializeToBuffer(this.payload.length, this.payload),
26
+ ]);
27
+ }
28
+ }
29
+
5
30
  /**
6
31
  * Gossipable
7
32
  *
8
33
  * Any class which extends gossipable will be able to be Gossiped over the p2p network
9
34
  */
10
35
  export abstract class Gossipable {
36
+ private cachedId: Buffer32 | undefined;
11
37
  /** p2p Topic
12
38
  *
13
39
  * - The p2p topic identifier, this determines how the message is handled
@@ -18,7 +44,15 @@ export abstract class Gossipable {
18
44
  *
19
45
  * - A digest of the message information, this key is used for deduplication
20
46
  */
21
- abstract p2pMessageIdentifier(): Promise<Buffer32>;
47
+ async p2pMessageIdentifier(): Promise<Buffer32> {
48
+ if (this.cachedId) {
49
+ return this.cachedId;
50
+ }
51
+ this.cachedId = await this.generateP2PMessageIdentifier();
52
+ return this.cachedId;
53
+ }
54
+
55
+ abstract generateP2PMessageIdentifier(): Promise<Buffer32>;
22
56
 
23
57
  /** To Buffer
24
58
  *
@@ -26,6 +60,10 @@ export abstract class Gossipable {
26
60
  */
27
61
  abstract toBuffer(): Buffer;
28
62
 
63
+ toMessage(): Buffer {
64
+ return this.toBuffer();
65
+ }
66
+
29
67
  /**
30
68
  * Get the size of the gossipable object.
31
69
  *
package/src/tx/tx.ts CHANGED
@@ -54,7 +54,7 @@ export class Tx extends Gossipable {
54
54
  }
55
55
 
56
56
  // Gossipable method
57
- override async p2pMessageIdentifier(): Promise<Buffer32> {
57
+ override async generateP2PMessageIdentifier(): Promise<Buffer32> {
58
58
  return new Buffer32((await this.getTxHash()).toBuffer());
59
59
  }
60
60