@aztec/foundation 0.87.2 → 0.87.3-nightly.20250528

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/crypto/random/index.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,4BA8BtC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,WAIpC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,WAIvC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,eAGzB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/crypto/random/index.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,4BAOtC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,WAIpC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,WAIvC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,eAGzB,CAAC"}
@@ -1,43 +1,11 @@
1
- import nodeCrypto from 'crypto';
2
- import isNode from 'detect-node';
1
+ import { randomBytes as bbRandomBytes } from '@aztec/bb.js';
3
2
  import { RandomnessSingleton } from './randomness_singleton.js';
4
- // limit of Crypto.getRandomValues()
5
- // https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
6
- const MAX_BYTES = 65536;
7
- const getWebCrypto = ()=>{
8
- if (typeof window !== 'undefined' && window.crypto) {
9
- return window.crypto;
10
- }
11
- if (typeof self !== 'undefined' && self.crypto) {
12
- return self.crypto;
13
- }
14
- return undefined;
15
- };
16
3
  export const randomBytes = (len)=>{
17
4
  const singleton = RandomnessSingleton.getInstance();
18
5
  if (singleton.isDeterministic()) {
19
6
  return singleton.getBytes(len);
20
7
  }
21
- if (isNode) {
22
- return nodeCrypto.randomBytes(len);
23
- }
24
- const crypto = getWebCrypto();
25
- if (!crypto) {
26
- throw new Error('randomBytes UnsupportedEnvironment');
27
- }
28
- const buf = Buffer.allocUnsafe(len);
29
- if (len > MAX_BYTES) {
30
- // this is the max bytes crypto.getRandomValues
31
- // can do at once see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
32
- for(let generated = 0; generated < len; generated += MAX_BYTES){
33
- // buffer.slice automatically checks if the end is past the end of
34
- // the buffer so we don't have to here
35
- crypto.getRandomValues(buf.slice(generated, generated + MAX_BYTES));
36
- }
37
- } else {
38
- crypto.getRandomValues(buf);
39
- }
40
- return buf;
8
+ return Buffer.from(bbRandomBytes(len));
41
9
  };
42
10
  /**
43
11
  * Generate a random integer less than max.
@@ -8,7 +8,6 @@ export type ViemSignature = {
8
8
  r: `0x${string}`;
9
9
  s: `0x${string}`;
10
10
  v: number;
11
- isEmpty: boolean;
12
11
  };
13
12
  /**
14
13
  * Contains a signature split into it's primary components (r,s,v)
@@ -20,18 +19,15 @@ export declare class Signature {
20
19
  readonly s: Buffer32;
21
20
  /** The v value of the signature */
22
21
  readonly v: number;
23
- /** Does this struct store an empty signature */
24
- readonly isEmpty: boolean;
25
22
  private size;
23
+ readonly empty: boolean;
26
24
  constructor(
27
25
  /** The r value of the signature */
28
26
  r: Buffer32,
29
27
  /** The s value of the signature */
30
28
  s: Buffer32,
31
29
  /** The v value of the signature */
32
- v: number,
33
- /** Does this struct store an empty signature */
34
- isEmpty?: boolean);
30
+ v: number);
35
31
  static fromBuffer(buf: Buffer | BufferReader): Signature;
36
32
  static isValidString(sig: `0x${string}`): boolean;
37
33
  /**
@@ -43,6 +39,7 @@ export declare class Signature {
43
39
  static fromViemSignature(sig: ViemSignature): Signature;
44
40
  static random(): Signature;
45
41
  static empty(): Signature;
42
+ isEmpty(): boolean;
46
43
  equals(other: Signature): boolean;
47
44
  toBuffer(): Buffer;
48
45
  getSize(): number;
@@ -1 +1 @@
1
- {"version":3,"file":"eth_signature.d.ts","sourceRoot":"","sources":["../../src/eth-signature/eth_signature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAE9E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;IACjB,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,qBAAa,SAAS;IAKlB,mCAAmC;aACnB,CAAC,EAAE,QAAQ;IAC3B,mCAAmC;aACnB,CAAC,EAAE,QAAQ;IAC3B,mCAAmC;aACnB,CAAC,EAAE,MAAM;IACzB,gDAAgD;aAChC,OAAO,EAAE,OAAO;IAVlC,OAAO,CAAC,IAAI,CAAqB;;IAG/B,mCAAmC;IACnB,CAAC,EAAE,QAAQ;IAC3B,mCAAmC;IACnB,CAAC,EAAE,QAAQ;IAC3B,mCAAmC;IACnB,CAAC,EAAE,MAAM;IACzB,gDAAgD;IAChC,OAAO,GAAE,OAAe;IAG1C,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAYxD,MAAM,CAAC,aAAa,CAAC,GAAG,EAAE,KAAK,MAAM,EAAE,GAAG,OAAO;IAIjD;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,MAAM,EAAE,GAAG,SAAS;IAYhD,MAAM,CAAC,iBAAiB,CAAC,GAAG,EAAE,aAAa,GAAG,SAAS;IASvD,MAAM,CAAC,MAAM,IAAI,SAAS;IAI1B,MAAM,CAAC,KAAK,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D,MAAM,CAAC,iBAAiB,CAAC,GAAG,EAAE,aAAa,GAAG,SAAS;IAIvD,MAAM,CAAC,MAAM,IAAI,SAAS;IAI1B,MAAM,CAAC,KAAK,IAAI,SAAS;IAIzB,OAAO,IAAI,OAAO;IAIlB,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO;IAIjC,QAAQ,IAAI,MAAM;IAMlB,OAAO,IAAI,MAAM;IAUjB,QAAQ,IAAI,KAAK,MAAM,EAAE;IAIzB;;OAEG;IACH,eAAe,IAAI,aAAa;IAQhC,MAAM;IAIN,MAAM,KAAK,MAAM,2HAMhB;CACF"}
@@ -8,22 +8,21 @@ import { hasHexPrefix, hexToBuffer } from '../string/index.js';
8
8
  r;
9
9
  s;
10
10
  v;
11
- isEmpty;
12
11
  // Cached values
13
12
  size;
14
- constructor(/** The r value of the signature */ r, /** The s value of the signature */ s, /** The v value of the signature */ v, /** Does this struct store an empty signature */ isEmpty = false){
13
+ empty;
14
+ constructor(/** The r value of the signature */ r, /** The s value of the signature */ s, /** The v value of the signature */ v){
15
15
  this.r = r;
16
16
  this.s = s;
17
17
  this.v = v;
18
- this.isEmpty = isEmpty;
18
+ this.empty = r.isZero() && s.isZero() && v === 0;
19
19
  }
20
20
  static fromBuffer(buf) {
21
21
  const reader = BufferReader.asReader(buf);
22
22
  const r = reader.readObject(Buffer32);
23
23
  const s = reader.readObject(Buffer32);
24
24
  const v = reader.readNumber();
25
- const isEmpty = r.isZero() && s.isZero();
26
- return new Signature(r, s, v, isEmpty);
25
+ return new Signature(r, s, v);
27
26
  }
28
27
  static isValidString(sig) {
29
28
  return /^0x[0-9a-f]{129,}$/i.test(sig);
@@ -38,20 +37,22 @@ import { hasHexPrefix, hexToBuffer } from '../string/index.js';
38
37
  const r = reader.readObject(Buffer32);
39
38
  const s = reader.readObject(Buffer32);
40
39
  const v = parseInt(sig.slice(2 + 64 * 2), 16);
41
- const isEmpty = r.isZero() && s.isZero();
42
- return new Signature(r, s, v, isEmpty);
40
+ return new Signature(r, s, v);
43
41
  }
44
42
  static fromViemSignature(sig) {
45
- return new Signature(Buffer32.fromBuffer(hexToBuffer(sig.r)), Buffer32.fromBuffer(hexToBuffer(sig.s)), sig.v, sig.isEmpty);
43
+ return new Signature(Buffer32.fromBuffer(hexToBuffer(sig.r)), Buffer32.fromBuffer(hexToBuffer(sig.s)), sig.v);
46
44
  }
47
45
  static random() {
48
- return new Signature(Buffer32.random(), Buffer32.random(), Math.floor(Math.random() * 2), false);
46
+ return new Signature(Buffer32.random(), Buffer32.random(), Math.floor(Math.random() * 2));
49
47
  }
50
48
  static empty() {
51
- return new Signature(Buffer32.ZERO, Buffer32.ZERO, 0, true);
49
+ return new Signature(Buffer32.ZERO, Buffer32.ZERO, 0);
50
+ }
51
+ isEmpty() {
52
+ return this.empty;
52
53
  }
53
54
  equals(other) {
54
- return this.r.equals(other.r) && this.s.equals(other.s) && this.v === other.v && this.isEmpty === other.isEmpty;
55
+ return this.r.equals(other.r) && this.s.equals(other.s) && this.v === other.v && this.empty === other.empty;
55
56
  }
56
57
  toBuffer() {
57
58
  const buffer = serializeToBuffer([
@@ -79,8 +80,7 @@ import { hasHexPrefix, hexToBuffer } from '../string/index.js';
79
80
  return {
80
81
  r: this.r.toString(),
81
82
  s: this.s.toString(),
82
- v: this.v,
83
- isEmpty: this.isEmpty
83
+ v: this.v
84
84
  };
85
85
  }
86
86
  toJSON() {
@@ -14,4 +14,23 @@ export type Writeable<T> = {
14
14
  };
15
15
  /** Removes readonly modifiers for an object. */
16
16
  export declare function unfreeze<T>(obj: T): Writeable<T>;
17
+ /**
18
+ * Type-safe Event Emitter type
19
+ * @example
20
+ * export type ArchiverEmitter = TypedEventEmitter<{
21
+ * [L2BlockSourceEvents.L2PruneDetected]: (args: L2BlockSourceEvent) => void;
22
+ * [L2BlockSourceEvents.L2BlockProven]: (args: L2BlockSourceEvent) => void;
23
+ * }>;
24
+ * class Archiver extends (EventEmitter as new () => ArchiverEmitter) {
25
+ * // ...
26
+ * }
27
+ */
28
+ export interface TypedEventEmitter<TEventMap extends {
29
+ [key in keyof TEventMap]: (...args: any[]) => void;
30
+ }> {
31
+ on<K extends keyof TEventMap>(event: K, listener: TEventMap[K]): this;
32
+ off<K extends keyof TEventMap>(event: K, listener: TEventMap[K]): this;
33
+ emit<K extends keyof TEventMap>(event: K, ...args: Parameters<TEventMap[K]>): boolean;
34
+ removeListener<K extends keyof TEventMap>(event: K, listener: TEventMap[K]): this;
35
+ }
17
36
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KACvB,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAC1D,CAAC;AAEF,kCAAkC;AAClC,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;CAC1D,CAAC;AAEF,uDAAuD;AACvD,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAE/E,6CAA6C;AAC7C,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IAAE,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC;AAE9D,gDAAgD;AAChD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC,CA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C,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACvE,IAAI,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;IACtF,cAAc,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CAEnF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/foundation",
3
- "version": "0.87.2",
3
+ "version": "0.87.3-nightly.20250528",
4
4
  "type": "module",
5
5
  "main": "./dest/index.js",
6
6
  "types": "./dest/index.d.ts",
@@ -100,13 +100,11 @@
100
100
  ]
101
101
  },
102
102
  "dependencies": {
103
- "@aztec/bb.js": "0.87.2",
103
+ "@aztec/bb.js": "0.87.3-nightly.20250528",
104
104
  "@koa/cors": "^5.0.0",
105
105
  "@noble/curves": "^1.2.0",
106
- "bn.js": "^5.2.1",
107
106
  "c-kzg": "4.0.0-alpha.1",
108
107
  "colorette": "^2.0.20",
109
- "debug": "^4.3.4",
110
108
  "detect-node": "^2.1.0",
111
109
  "hash.js": "^1.1.7",
112
110
  "koa": "^2.16.1",
@@ -126,8 +124,6 @@
126
124
  "devDependencies": {
127
125
  "@jest/globals": "^29.5.0",
128
126
  "@libp2p/interface": "1.3.1",
129
- "@types/bn.js": "^5.1.3",
130
- "@types/debug": "^4.1.7",
131
127
  "@types/detect-node": "^2.0.0",
132
128
  "@types/jest": "^29.5.0",
133
129
  "@types/koa": "^2.15.0",
@@ -1,52 +1,14 @@
1
- import nodeCrypto from 'crypto';
2
- import isNode from 'detect-node';
1
+ import { randomBytes as bbRandomBytes } from '@aztec/bb.js';
3
2
 
4
3
  import { RandomnessSingleton } from './randomness_singleton.js';
5
4
 
6
- // limit of Crypto.getRandomValues()
7
- // https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
8
- const MAX_BYTES = 65536;
9
-
10
- const getWebCrypto = () => {
11
- if (typeof window !== 'undefined' && window.crypto) {
12
- return window.crypto;
13
- }
14
- if (typeof self !== 'undefined' && self.crypto) {
15
- return self.crypto;
16
- }
17
- return undefined;
18
- };
19
-
20
5
  export const randomBytes = (len: number) => {
21
6
  const singleton = RandomnessSingleton.getInstance();
22
7
 
23
8
  if (singleton.isDeterministic()) {
24
9
  return singleton.getBytes(len);
25
10
  }
26
-
27
- if (isNode) {
28
- return nodeCrypto.randomBytes(len) as Buffer;
29
- }
30
-
31
- const crypto = getWebCrypto();
32
- if (!crypto) {
33
- throw new Error('randomBytes UnsupportedEnvironment');
34
- }
35
-
36
- const buf = Buffer.allocUnsafe(len);
37
- if (len > MAX_BYTES) {
38
- // this is the max bytes crypto.getRandomValues
39
- // can do at once see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
40
- for (let generated = 0; generated < len; generated += MAX_BYTES) {
41
- // buffer.slice automatically checks if the end is past the end of
42
- // the buffer so we don't have to here
43
- crypto.getRandomValues(buf.slice(generated, generated + MAX_BYTES));
44
- }
45
- } else {
46
- crypto.getRandomValues(buf);
47
- }
48
-
49
- return buf;
11
+ return Buffer.from(bbRandomBytes(len)) as Buffer<ArrayBuffer>;
50
12
  };
51
13
 
52
14
  /**
@@ -12,7 +12,6 @@ export type ViemSignature = {
12
12
  r: `0x${string}`;
13
13
  s: `0x${string}`;
14
14
  v: number;
15
- isEmpty: boolean;
16
15
  };
17
16
 
18
17
  /**
@@ -22,6 +21,8 @@ export class Signature {
22
21
  // Cached values
23
22
  private size: number | undefined;
24
23
 
24
+ public readonly empty: boolean;
25
+
25
26
  constructor(
26
27
  /** The r value of the signature */
27
28
  public readonly r: Buffer32,
@@ -29,9 +30,9 @@ export class Signature {
29
30
  public readonly s: Buffer32,
30
31
  /** The v value of the signature */
31
32
  public readonly v: number,
32
- /** Does this struct store an empty signature */
33
- public readonly isEmpty: boolean = false,
34
- ) {}
33
+ ) {
34
+ this.empty = r.isZero() && s.isZero() && v === 0;
35
+ }
35
36
 
36
37
  static fromBuffer(buf: Buffer | BufferReader): Signature {
37
38
  const reader = BufferReader.asReader(buf);
@@ -40,9 +41,7 @@ export class Signature {
40
41
  const s = reader.readObject(Buffer32);
41
42
  const v = reader.readNumber();
42
43
 
43
- const isEmpty = r.isZero() && s.isZero();
44
-
45
- return new Signature(r, s, v, isEmpty);
44
+ return new Signature(r, s, v);
46
45
  }
47
46
 
48
47
  static isValidString(sig: `0x${string}`): boolean {
@@ -61,30 +60,27 @@ export class Signature {
61
60
  const s = reader.readObject(Buffer32);
62
61
  const v = parseInt(sig.slice(2 + 64 * 2), 16);
63
62
 
64
- const isEmpty = r.isZero() && s.isZero();
65
-
66
- return new Signature(r, s, v, isEmpty);
63
+ return new Signature(r, s, v);
67
64
  }
68
65
 
69
66
  static fromViemSignature(sig: ViemSignature): Signature {
70
- return new Signature(
71
- Buffer32.fromBuffer(hexToBuffer(sig.r)),
72
- Buffer32.fromBuffer(hexToBuffer(sig.s)),
73
- sig.v,
74
- sig.isEmpty,
75
- );
67
+ return new Signature(Buffer32.fromBuffer(hexToBuffer(sig.r)), Buffer32.fromBuffer(hexToBuffer(sig.s)), sig.v);
76
68
  }
77
69
 
78
70
  static random(): Signature {
79
- return new Signature(Buffer32.random(), Buffer32.random(), Math.floor(Math.random() * 2), false);
71
+ return new Signature(Buffer32.random(), Buffer32.random(), Math.floor(Math.random() * 2));
80
72
  }
81
73
 
82
74
  static empty(): Signature {
83
- return new Signature(Buffer32.ZERO, Buffer32.ZERO, 0, true);
75
+ return new Signature(Buffer32.ZERO, Buffer32.ZERO, 0);
76
+ }
77
+
78
+ isEmpty(): boolean {
79
+ return this.empty;
84
80
  }
85
81
 
86
82
  equals(other: Signature): boolean {
87
- return this.r.equals(other.r) && this.s.equals(other.s) && this.v === other.v && this.isEmpty === other.isEmpty;
83
+ return this.r.equals(other.r) && this.s.equals(other.s) && this.v === other.v && this.empty === other.empty;
88
84
  }
89
85
 
90
86
  toBuffer(): Buffer {
@@ -115,7 +111,6 @@ export class Signature {
115
111
  r: this.r.toString(),
116
112
  s: this.s.toString(),
117
113
  v: this.v,
118
- isEmpty: this.isEmpty,
119
114
  };
120
115
  }
121
116
 
@@ -18,3 +18,22 @@ export type Writeable<T> = { -readonly [P in keyof T]: T[P] };
18
18
  export function unfreeze<T>(obj: T): Writeable<T> {
19
19
  return obj as Writeable<T>;
20
20
  }
21
+
22
+ /**
23
+ * Type-safe Event Emitter type
24
+ * @example
25
+ * export type ArchiverEmitter = TypedEventEmitter<{
26
+ * [L2BlockSourceEvents.L2PruneDetected]: (args: L2BlockSourceEvent) => void;
27
+ * [L2BlockSourceEvents.L2BlockProven]: (args: L2BlockSourceEvent) => void;
28
+ * }>;
29
+ * class Archiver extends (EventEmitter as new () => ArchiverEmitter) {
30
+ * // ...
31
+ * }
32
+ */
33
+ export interface TypedEventEmitter<TEventMap extends { [key in keyof TEventMap]: (...args: any[]) => void }> {
34
+ on<K extends keyof TEventMap>(event: K, listener: TEventMap[K]): this;
35
+ off<K extends keyof TEventMap>(event: K, listener: TEventMap[K]): this;
36
+ emit<K extends keyof TEventMap>(event: K, ...args: Parameters<TEventMap[K]>): boolean;
37
+ removeListener<K extends keyof TEventMap>(event: K, listener: TEventMap[K]): this;
38
+ // Can add other EventEmitter methods if needed, like once(), listenerCount(), etc.
39
+ }