@proto-kit/common 0.1.1-develop.340 → 0.1.1-develop.456

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.
Files changed (61) hide show
  1. package/dist/config/ConfigurableModule.d.ts +2 -1
  2. package/dist/config/ConfigurableModule.d.ts.map +1 -1
  3. package/dist/config/ModuleContainer.d.ts +35 -11
  4. package/dist/config/ModuleContainer.d.ts.map +1 -1
  5. package/dist/config/ModuleContainer.js +86 -19
  6. package/dist/dependencyFactory/DependencyFactory.d.ts +13 -9
  7. package/dist/dependencyFactory/DependencyFactory.d.ts.map +1 -1
  8. package/dist/dependencyFactory/DependencyFactory.js +1 -97
  9. package/dist/events/EventEmitter.d.ts +14 -0
  10. package/dist/events/EventEmitter.d.ts.map +1 -0
  11. package/dist/events/EventEmitter.js +35 -0
  12. package/dist/events/EventEmitterProxy.d.ts +17 -0
  13. package/dist/events/EventEmitterProxy.d.ts.map +1 -0
  14. package/dist/events/EventEmitterProxy.js +21 -0
  15. package/dist/events/EventEmittingComponent.d.ts +6 -0
  16. package/dist/events/EventEmittingComponent.d.ts.map +1 -0
  17. package/dist/index.d.ts +7 -0
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +7 -0
  20. package/dist/trees/InMemoryMerkleTreeStorage.d.ts +11 -0
  21. package/dist/trees/InMemoryMerkleTreeStorage.d.ts.map +1 -0
  22. package/dist/trees/InMemoryMerkleTreeStorage.js +12 -0
  23. package/dist/trees/MerkleTreeStore.d.ts +5 -0
  24. package/dist/trees/MerkleTreeStore.d.ts.map +1 -0
  25. package/dist/trees/MerkleTreeStore.js +1 -0
  26. package/dist/trees/MockAsyncMerkleStore.d.ts +9 -0
  27. package/dist/trees/MockAsyncMerkleStore.d.ts.map +1 -0
  28. package/dist/trees/MockAsyncMerkleStore.js +19 -0
  29. package/dist/trees/RollupMerkleTree.d.ts +126 -0
  30. package/dist/trees/RollupMerkleTree.d.ts.map +1 -0
  31. package/dist/trees/RollupMerkleTree.js +216 -0
  32. package/dist/types.d.ts +5 -0
  33. package/dist/types.d.ts.map +1 -1
  34. package/dist/zkProgrammable/ZkProgrammable.d.ts +1 -1
  35. package/dist/zkProgrammable/ZkProgrammable.d.ts.map +1 -1
  36. package/dist/zkProgrammable/ZkProgrammable.js +4 -4
  37. package/dist/zkProgrammable/provableMethod.d.ts +1 -1
  38. package/dist/zkProgrammable/provableMethod.d.ts.map +1 -1
  39. package/dist/zkProgrammable/provableMethod.js +2 -2
  40. package/package.json +2 -2
  41. package/src/config/ConfigurableModule.ts +3 -1
  42. package/src/config/ModuleContainer.ts +150 -30
  43. package/src/dependencyFactory/DependencyFactory.ts +25 -114
  44. package/src/events/EventEmitter.ts +58 -0
  45. package/src/events/EventEmitterProxy.ts +57 -0
  46. package/src/events/EventEmittingComponent.ts +7 -0
  47. package/src/index.ts +7 -0
  48. package/src/trees/InMemoryMerkleTreeStorage.ts +17 -0
  49. package/src/trees/MerkleTreeStore.ts +5 -0
  50. package/src/trees/MockAsyncMerkleStore.ts +29 -0
  51. package/src/trees/RollupMerkleTree.ts +354 -0
  52. package/src/trees/VirtualMerkleTreeStore.ts +21 -0
  53. package/src/types.ts +12 -0
  54. package/src/zkProgrammable/ZkProgrammable.ts +5 -4
  55. package/src/zkProgrammable/provableMethod.ts +2 -2
  56. package/test/config/ContainerEvents.test.ts +86 -0
  57. package/test/config/ModuleContainer.test.ts +111 -6
  58. package/test/trees/MerkleTree.test.ts +105 -0
  59. package/dist/config/ChildContainerStartable.d.ts +0 -5
  60. package/dist/config/ChildContainerStartable.d.ts.map +0 -1
  61. /package/dist/{config/ChildContainerStartable.js → events/EventEmittingComponent.js} +0 -0
@@ -0,0 +1,9 @@
1
+ import { InMemoryMerkleTreeStorage } from "./InMemoryMerkleTreeStorage";
2
+ export declare class MockAsyncMerkleTreeStore {
3
+ readonly store: InMemoryMerkleTreeStorage;
4
+ commit(): void;
5
+ openTransaction(): void;
6
+ getNodeAsync(key: bigint, level: number): Promise<bigint | undefined>;
7
+ setNodeAsync(key: bigint, level: number, value: bigint): Promise<void>;
8
+ }
9
+ //# sourceMappingURL=MockAsyncMerkleStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MockAsyncMerkleStore.d.ts","sourceRoot":"","sources":["../../src/trees/MockAsyncMerkleStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAGxE,qBAAa,wBAAwB;IACnC,SAAgB,KAAK,4BAAmC;IAEjD,MAAM,IAAI,IAAI;IAId,eAAe,IAAI,IAAI;IAIjB,YAAY,CACvB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAIjB,YAAY,CACvB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC;CAGjB"}
@@ -0,0 +1,19 @@
1
+ import { InMemoryMerkleTreeStorage } from "./InMemoryMerkleTreeStorage";
2
+ import { noop } from "./../utils";
3
+ export class MockAsyncMerkleTreeStore {
4
+ constructor() {
5
+ this.store = new InMemoryMerkleTreeStorage();
6
+ }
7
+ commit() {
8
+ noop();
9
+ }
10
+ openTransaction() {
11
+ noop();
12
+ }
13
+ async getNodeAsync(key, level) {
14
+ return this.store.getNode(key, level);
15
+ }
16
+ async setNodeAsync(key, level, value) {
17
+ this.store.setNode(key, level, value);
18
+ }
19
+ }
@@ -0,0 +1,126 @@
1
+ import { Bool, Field } from "o1js";
2
+ import { TypedClass } from "../types";
3
+ import { MerkleTreeStore } from "./MerkleTreeStore";
4
+ declare const StructTemplate_base: (new (value: {
5
+ path: import("o1js/dist/node/lib/field").Field[];
6
+ isLeft: import("o1js/dist/node/lib/bool").Bool[];
7
+ }) => {
8
+ path: import("o1js/dist/node/lib/field").Field[];
9
+ isLeft: import("o1js/dist/node/lib/bool").Bool[];
10
+ }) & {
11
+ _isStruct: true;
12
+ } & import("o1js/dist/node/snarky").ProvablePure<{
13
+ path: import("o1js/dist/node/lib/field").Field[];
14
+ isLeft: import("o1js/dist/node/lib/bool").Bool[];
15
+ }> & {
16
+ toInput: (x: {
17
+ path: import("o1js/dist/node/lib/field").Field[];
18
+ isLeft: import("o1js/dist/node/lib/bool").Bool[];
19
+ }) => {
20
+ fields?: import("o1js/dist/node/lib/field").Field[] | undefined;
21
+ packed?: [import("o1js/dist/node/lib/field").Field, number][] | undefined;
22
+ };
23
+ toJSON: (x: {
24
+ path: import("o1js/dist/node/lib/field").Field[];
25
+ isLeft: import("o1js/dist/node/lib/bool").Bool[];
26
+ }) => {
27
+ path: string[];
28
+ isLeft: boolean[];
29
+ };
30
+ fromJSON: (x: {
31
+ path: string[];
32
+ isLeft: boolean[];
33
+ }) => {
34
+ path: import("o1js/dist/node/lib/field").Field[];
35
+ isLeft: import("o1js/dist/node/lib/bool").Bool[];
36
+ };
37
+ };
38
+ declare class StructTemplate extends StructTemplate_base {
39
+ }
40
+ export interface AbstractMerkleWitness extends StructTemplate {
41
+ height(): number;
42
+ /**
43
+ * Calculates a root depending on the leaf value.
44
+ * @param leaf Value of the leaf node that belongs to this Witness.
45
+ * @returns The calculated root.
46
+ */
47
+ calculateRoot(hash: Field): Field;
48
+ /**
49
+ * Calculates the index of the leaf node that belongs to this Witness.
50
+ * @returns Index of the leaf.
51
+ */
52
+ calculateIndex(): Field;
53
+ checkMembership(root: Field, key: Field, value: Field): Bool;
54
+ checkMembershipGetRoots(root: Field, key: Field, value: Field): [Bool, Field, Field];
55
+ toShortenedEntries(): string[];
56
+ }
57
+ export interface AbstractMerkleTree {
58
+ store: MerkleTreeStore;
59
+ readonly leafCount: bigint;
60
+ assertIndexRange(index: bigint): void;
61
+ /**
62
+ * Returns a node which lives at a given index and level.
63
+ * @param level Level of the node.
64
+ * @param index Index of the node.
65
+ * @returns The data of the node.
66
+ */
67
+ getNode(level: number, index: bigint): Field;
68
+ /**
69
+ * Returns the root of the [Merkle Tree](https://en.wikipedia.org/wiki/Merkle_tree).
70
+ * @returns The root of the Merkle Tree.
71
+ */
72
+ getRoot(): Field;
73
+ /**
74
+ * Sets the value of a leaf node at a given index to a given value.
75
+ * @param index Position of the leaf node.
76
+ * @param leaf New value.
77
+ */
78
+ setLeaf(index: bigint, leaf: Field): void;
79
+ /**
80
+ * Returns the witness (also known as
81
+ * [Merkle Proof or Merkle Witness](https://computersciencewiki.org/index.php/Merkle_proof))
82
+ * for the leaf at the given index.
83
+ * @param index Position of the leaf node.
84
+ * @returns The witness that belongs to the leaf.
85
+ */
86
+ getWitness(index: bigint): AbstractMerkleWitness;
87
+ /**
88
+ * Fills all leaves of the tree.
89
+ * @param leaves Values to fill the leaves with.
90
+ */
91
+ fill(leaves: Field[]): void;
92
+ }
93
+ export interface AbstractMerkleTreeClass {
94
+ new (...args: any[]): AbstractMerkleTree;
95
+ WITNESS: TypedClass<AbstractMerkleWitness> & typeof StructTemplate;
96
+ HEIGHT: number;
97
+ EMPTY_ROOT: bigint;
98
+ get leafCount(): bigint;
99
+ }
100
+ /**
101
+ * A [Merkle Tree](https://en.wikipedia.org/wiki/Merkle_tree) is a binary tree in
102
+ * which every leaf is the cryptography hash of a piece of data,
103
+ * and every node is the hash of the concatenation of its two child nodes.
104
+ *
105
+ * A Merkle Tree allows developers to easily and securely verify
106
+ * the integrity of large amounts of data.
107
+ *
108
+ * Take a look at our [documentation](https://docs.minaprotocol.com/en/zkapps)
109
+ * on how to use Merkle Trees in combination with zkApps and
110
+ * zero knowledge programming!
111
+ *
112
+ * Levels are indexed from leaves (level 0) to root (level N - 1).
113
+ *
114
+ * This function takes a height as argument and returns a class
115
+ * that implements a merkletree with that specified height.
116
+ *
117
+ * It also holds the Witness class under tree.WITNESS
118
+ */
119
+ export declare function createMerkleTree(height: number): AbstractMerkleTreeClass;
120
+ declare const RollupMerkleTree_base: AbstractMerkleTreeClass;
121
+ export declare class RollupMerkleTree extends RollupMerkleTree_base {
122
+ }
123
+ export declare class RollupMerkleTreeWitness extends RollupMerkleTree.WITNESS {
124
+ }
125
+ export {};
126
+ //# sourceMappingURL=RollupMerkleTree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RollupMerkleTree.d.ts","sourceRoot":"","sources":["../../src/trees/RollupMerkleTree.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,IAAI,EAAE,KAAK,EAA8B,MAAM,MAAM,CAAC;AAG/D,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGpD,cAAM,cAAe,SAAQ,mBAG3B;CAAG;AAEL,MAAM,WAAW,qBAAsB,SAAQ,cAAc;IAC3D,MAAM,IAAI,MAAM,CAAC;IAEjB;;;;OAIG;IACH,aAAa,CAAC,IAAI,EAAE,KAAK,GAAG,KAAK,CAAC;IAElC;;;OAGG;IACH,cAAc,IAAI,KAAK,CAAC;IAExB,eAAe,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAE7D,uBAAuB,CACrB,IAAI,EAAE,KAAK,EACX,GAAG,EAAE,KAAK,EACV,KAAK,EAAE,KAAK,GACX,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAExB,kBAAkB,IAAI,MAAM,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtC;;;;;OAKG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC;IAE7C;;;OAGG;IACH,OAAO,IAAI,KAAK,CAAC;IAEjB;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;IAE1C;;;;;;OAMG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,qBAAqB,CAAC;IAEjD;;;OAGG;IACH,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,uBAAuB;IACtC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,kBAAkB,CAAC;IAEzC,OAAO,EAAE,UAAU,CAAC,qBAAqB,CAAC,GAAG,OAAO,cAAc,CAAC;IAEnE,MAAM,EAAE,MAAM,CAAC;IAEf,UAAU,EAAE,MAAM,CAAC;IAEnB,IAAI,SAAS,IAAI,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,uBAAuB,CA4NxE;;AAED,qBAAa,gBAAiB,SAAQ,qBAAqB;CAAG;AAC9D,qBAAa,uBAAwB,SAAQ,gBAAgB,CAAC,OAAO;CAAG"}
@@ -0,0 +1,216 @@
1
+ /* eslint-disable id-length */
2
+ /* eslint-disable line-comment-position */
3
+ /* eslint-disable no-inline-comments */
4
+ /* eslint-disable @typescript-eslint/no-magic-numbers */
5
+ /* eslint-disable @typescript-eslint/method-signature-style */
6
+ import { Bool, Field, Poseidon, Provable, Struct } from "o1js";
7
+ import { range } from "../utils";
8
+ import { InMemoryMerkleTreeStorage } from "./InMemoryMerkleTreeStorage";
9
+ class StructTemplate extends Struct({
10
+ path: Provable.Array(Field, 0),
11
+ isLeft: Provable.Array(Bool, 0),
12
+ }) {
13
+ }
14
+ /**
15
+ * A [Merkle Tree](https://en.wikipedia.org/wiki/Merkle_tree) is a binary tree in
16
+ * which every leaf is the cryptography hash of a piece of data,
17
+ * and every node is the hash of the concatenation of its two child nodes.
18
+ *
19
+ * A Merkle Tree allows developers to easily and securely verify
20
+ * the integrity of large amounts of data.
21
+ *
22
+ * Take a look at our [documentation](https://docs.minaprotocol.com/en/zkapps)
23
+ * on how to use Merkle Trees in combination with zkApps and
24
+ * zero knowledge programming!
25
+ *
26
+ * Levels are indexed from leaves (level 0) to root (level N - 1).
27
+ *
28
+ * This function takes a height as argument and returns a class
29
+ * that implements a merkletree with that specified height.
30
+ *
31
+ * It also holds the Witness class under tree.WITNESS
32
+ */
33
+ export function createMerkleTree(height) {
34
+ var _a;
35
+ /**
36
+ * The {@link BaseMerkleWitness} class defines a circuit-compatible base class
37
+ * for [Merkle Witness'](https://computersciencewiki.org/index.php/Merkle_proof).
38
+ */
39
+ class RollupMerkleWitness extends Struct({
40
+ path: Provable.Array(Field, height - 1),
41
+ isLeft: Provable.Array(Bool, height - 1),
42
+ }) {
43
+ height() {
44
+ return RollupMerkleWitness.height;
45
+ }
46
+ /**
47
+ * Calculates a root depending on the leaf value.
48
+ * @param leaf Value of the leaf node that belongs to this Witness.
49
+ * @returns The calculated root.
50
+ */
51
+ calculateRoot(hash) {
52
+ const n = this.height();
53
+ for (let index = 1; index < n; ++index) {
54
+ const isLeft = this.isLeft[index - 1];
55
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
56
+ const [left, right] = maybeSwap(isLeft, hash, this.path[index - 1]);
57
+ hash = Poseidon.hash([left, right]);
58
+ }
59
+ return hash;
60
+ }
61
+ /**
62
+ * Calculates the index of the leaf node that belongs to this Witness.
63
+ * @returns Index of the leaf.
64
+ */
65
+ calculateIndex() {
66
+ let powerOfTwo = Field(1);
67
+ let index = Field(0);
68
+ const n = this.height();
69
+ // eslint-disable-next-line no-underscore-dangle
70
+ for (let index_ = 1; index_ < n; ++index_) {
71
+ index = Provable.if(this.isLeft[index_ - 1], index, index.add(powerOfTwo));
72
+ powerOfTwo = powerOfTwo.mul(2);
73
+ }
74
+ return index;
75
+ }
76
+ checkMembership(root, key, value) {
77
+ const calculatedRoot = this.calculateRoot(value);
78
+ const calculatedKey = this.calculateIndex();
79
+ // We don't have to range-check the key, because if it would be greater
80
+ // than leafCount, it would not match the computedKey
81
+ key.assertEquals(calculatedKey, "Keys of MerkleWitness does not match");
82
+ return root.equals(calculatedRoot);
83
+ }
84
+ checkMembershipGetRoots(root, key, value) {
85
+ const calculatedRoot = this.calculateRoot(value);
86
+ const calculatedKey = this.calculateIndex();
87
+ key.assertEquals(calculatedKey, "Keys of MerkleWitness does not match");
88
+ return [root.equals(calculatedRoot), root, calculatedRoot];
89
+ }
90
+ toShortenedEntries() {
91
+ return range(0, 5)
92
+ .concat(range(this.height() - 4, this.height()))
93
+ .map((index) => [
94
+ this.path[index].toString(),
95
+ this.isLeft[index].toString(),
96
+ ].toString());
97
+ }
98
+ }
99
+ RollupMerkleWitness.height = height;
100
+ return _a = class AbstractRollupMerkleTree {
101
+ static get leafCount() {
102
+ return 2n ** BigInt(AbstractRollupMerkleTree.HEIGHT - 1);
103
+ }
104
+ constructor(store) {
105
+ this.store = store;
106
+ this.zeroes = [0n];
107
+ for (let index = 1; index < AbstractRollupMerkleTree.HEIGHT; index += 1) {
108
+ const previousLevel = Field(this.zeroes[index - 1]);
109
+ this.zeroes.push(Poseidon.hash([previousLevel, previousLevel]).toBigInt());
110
+ }
111
+ }
112
+ assertIndexRange(index) {
113
+ if (index > this.leafCount) {
114
+ throw new Error("Index greater than maximum leaf number");
115
+ }
116
+ }
117
+ /**
118
+ * Returns a node which lives at a given index and level.
119
+ * @param level Level of the node.
120
+ * @param index Index of the node.
121
+ * @returns The data of the node.
122
+ */
123
+ getNode(level, index) {
124
+ this.assertIndexRange(index);
125
+ return Field(this.store.getNode(index, level) ?? this.zeroes[level]);
126
+ }
127
+ /**
128
+ * Returns the root of the [Merkle Tree](https://en.wikipedia.org/wiki/Merkle_tree).
129
+ * @returns The root of the Merkle Tree.
130
+ */
131
+ getRoot() {
132
+ return this.getNode(AbstractRollupMerkleTree.HEIGHT - 1, 0n);
133
+ }
134
+ // private in interface
135
+ setNode(level, index, value) {
136
+ this.store.setNode(index, level, value.toBigInt());
137
+ }
138
+ /**
139
+ * Sets the value of a leaf node at a given index to a given value.
140
+ * @param index Position of the leaf node.
141
+ * @param leaf New value.
142
+ */
143
+ setLeaf(index, leaf) {
144
+ this.assertIndexRange(index);
145
+ this.setNode(0, index, leaf);
146
+ let currentIndex = index;
147
+ for (let level = 1; level < AbstractRollupMerkleTree.HEIGHT; level += 1) {
148
+ currentIndex /= 2n;
149
+ const left = this.getNode(level - 1, currentIndex * 2n);
150
+ const right = this.getNode(level - 1, currentIndex * 2n + 1n);
151
+ this.setNode(level, currentIndex, Poseidon.hash([left, right]));
152
+ }
153
+ }
154
+ /**
155
+ * Returns the witness (also known as
156
+ * [Merkle Proof or Merkle Witness](https://computersciencewiki.org/index.php/Merkle_proof))
157
+ * for the leaf at the given index.
158
+ * @param index Position of the leaf node.
159
+ * @returns The witness that belongs to the leaf.
160
+ */
161
+ getWitness(index) {
162
+ this.assertIndexRange(index);
163
+ const path = [];
164
+ const isLefts = [];
165
+ for (let level = 0; level < AbstractRollupMerkleTree.HEIGHT - 1; level += 1) {
166
+ const isLeft = index % 2n === 0n;
167
+ const sibling = this.getNode(level, isLeft ? index + 1n : index - 1n);
168
+ isLefts.push(Bool(isLeft));
169
+ path.push(sibling);
170
+ index /= 2n;
171
+ }
172
+ return new RollupMerkleWitness({
173
+ isLeft: isLefts,
174
+ path,
175
+ });
176
+ }
177
+ // eslint-disable-next-line no-warning-comments, max-len
178
+ // TODO: should this take an optional offset? should it fail if the array is too long?
179
+ /**
180
+ * Fills all leaves of the tree.
181
+ * @param leaves Values to fill the leaves with.
182
+ */
183
+ fill(leaves) {
184
+ leaves.forEach((value, index) => {
185
+ this.setLeaf(BigInt(index), value);
186
+ });
187
+ }
188
+ /**
189
+ * Returns the amount of leaf nodes.
190
+ * @returns Amount of leaf nodes.
191
+ */
192
+ get leafCount() {
193
+ return AbstractRollupMerkleTree.leafCount;
194
+ }
195
+ },
196
+ _a.HEIGHT = height,
197
+ _a.EMPTY_ROOT = new _a(new InMemoryMerkleTreeStorage())
198
+ .getRoot()
199
+ .toBigInt(),
200
+ _a.WITNESS = RollupMerkleWitness,
201
+ _a;
202
+ }
203
+ export class RollupMerkleTree extends createMerkleTree(256) {
204
+ }
205
+ export class RollupMerkleTreeWitness extends RollupMerkleTree.WITNESS {
206
+ }
207
+ /**
208
+ * More efficient version of `maybeSwapBad` which
209
+ * reuses an intermediate variable
210
+ */
211
+ function maybeSwap(b, x, y) {
212
+ const m = b.toField().mul(x.sub(y)); // b*(x - y)
213
+ const x1 = y.add(m); // y + b*(x - y)
214
+ const y2 = x.sub(m); // x - b*(x - y) = x + b*(y - x)
215
+ return [x1, y2];
216
+ }
package/dist/types.d.ts CHANGED
@@ -9,4 +9,9 @@ export type StringKeyOf<Target extends object> = Extract<keyof Target, string> &
9
9
  * Utility type to infer element type from an array type
10
10
  */
11
11
  export type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
12
+ /**
13
+ * Transforms X | Y => X & Y
14
+ */
15
+ export type UnionToIntersection<Union> = (Union extends any ? (x: Union) => void : never) extends (x: infer Intersection) => void ? Intersection : never;
16
+ export type MergeObjects<Input extends Record<string, unknown>> = UnionToIntersection<Input[keyof Input]>;
12
17
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,UAAU,CAAC,KAAK,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,KAAK,CAAC;AAE9D,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAEvD;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,MAAM,IAAI,OAAO,CAAC,MAAM,MAAM,EAAE,MAAM,CAAC,GAC5E,MAAM,CAAC;AAGT;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,SAAS,SAAS,SAAS,OAAO,EAAE,IAE3D,SAAS,SAAS,SAAS,CAAC,MAAM,WAAW,CAAC,EAAE,GAAG,WAAW,GAAG,KAAK,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,UAAU,CAAC,KAAK,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,KAAK,CAAC;AAE9D,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAEvD;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,MAAM,IAAI,OAAO,CAAC,MAAM,MAAM,EAAE,MAAM,CAAC,GAC5E,MAAM,CAAC;AAGT;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,SAAS,SAAS,SAAS,OAAO,EAAE,IAE3D,SAAS,SAAS,SAAS,CAAC,MAAM,WAAW,CAAC,EAAE,GAAG,WAAW,GAAG,KAAK,CAAC;AAEzE;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,KAAK,IAAI,CACvC,KAAK,SAAS,GAAG,GAAG,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,GAAG,KAAK,CAC/C,SAAS,CAAC,CAAC,EAAE,MAAM,YAAY,KAAK,IAAI,GACrC,YAAY,GACZ,KAAK,CAAC;AAEV,MAAM,MAAM,YAAY,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC5D,mBAAmB,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC"}
@@ -19,7 +19,7 @@ export interface PlainZkProgram<PublicInput = undefined, PublicOutput = void> {
19
19
  methods: Record<string, ((...args: any) => Promise<Proof<PublicInput, PublicOutput>>) | ((publicInput: PublicInput, ...args: any) => Promise<Proof<PublicInput, PublicOutput>>)>;
20
20
  }
21
21
  export declare function verifyToMockable<PublicInput, PublicOutput>(verify: Verify<PublicInput, PublicOutput>, { areProofsEnabled }: AreProofsEnabled): (proof: Proof<PublicInput, PublicOutput>) => Promise<boolean>;
22
- export declare const mockVerificationKey = "mock-verification-key";
22
+ export declare const MOCK_VERIFICATION_KEY = "mock-verification-key";
23
23
  export declare function compileToMockable(compile: Compile, { areProofsEnabled }: AreProofsEnabled): () => Promise<CompileArtifact>;
24
24
  export declare abstract class ZkProgrammable<PublicInput = undefined, PublicOutput = void> {
25
25
  abstract get appChain(): AreProofsEnabled | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"ZkProgrammable.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/ZkProgrammable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAUjE,MAAM,WAAW,eAAe;IAC9B,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,gBAAgB;IAC/B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,gBAAgB,EAAE,CAAC,gBAAgB,EAAE,OAAO,KAAK,IAAI,CAAC;CACvD;AAED,MAAM,WAAW,MAAM,CAAC,WAAW,EAAE,YAAY;IAC/C,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,YAAY,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7D;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC;CAC9B;AAED,MAAM,WAAW,cAAc,CAAC,WAAW,GAAG,SAAS,EAAE,YAAY,GAAG,IAAI;IAC1E,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;IAC1C,KAAK,EAAE,UAAU,CACf,OAAO,YAAY,CAAC,SAAS,CAAC,KAAK,CACjC,oBAAoB,CAAC,WAAW,CAAC,EACjC,oBAAoB,CAAC,Y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AAqB,0BAA0B,CAAC;AAE7D,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,OAAO,EAChB,EAAE,gBAAgB,EAAE,EAAE,gBAAgB,GACrC,MAAM,OAAO,CAAC,eAAe,CAAC,CAUhC;AAED,8BAAsB,cAAc,CAClC,WAAW,GAAG,SAAS,EACvB,YAAY,GAAG,IAAI;IAEnB,aAAoB,QAAQ,IAAI,gBAAgB,GAAG,SAAS,CAAC;aAE7C,gBAAgB,IAAI,cAAc,CAAC,WAAW,EAAE,YAAY,CAAC;IAE7E,IACW,SAAS,IAAI,cAAc,CAAC,WAAW,EAAE,YAAY,CAAC,CAYhE;CACF;AAED,MAAM,WAAW,kBAAkB,CACjC,WAAW,GAAG,SAAS,EACvB,YAAY,GAAG,IAAI;IAEnB,cAAc,EAAE,cAAc,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;CAC3D"}
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
10
  import { Memoize } from "typescript-memoize";
11
- import { mockProof } from "./provableMethod";
11
+ import { MOCK_PROOF } from "./provableMethod";
12
12
  const errors = {
13
13
  appChainNotSet: (name) => new Error(`Appchain was not injected for: ${name}`),
14
14
  };
@@ -26,17 +26,17 @@ export function verifyToMockable(verify, { areProofsEnabled }) {
26
26
  }
27
27
  return verified;
28
28
  }
29
- return proof.proof === mockProof;
29
+ return proof.proof === MOCK_PROOF;
30
30
  };
31
31
  }
32
- export const mockVerificationKey = "mock-verification-key";
32
+ export const MOCK_VERIFICATION_KEY = "mock-verification-key";
33
33
  export function compileToMockable(compile, { areProofsEnabled }) {
34
34
  return async () => {
35
35
  if (areProofsEnabled) {
36
36
  return await compile();
37
37
  }
38
38
  return {
39
- verificationKey: mockVerificationKey,
39
+ verificationKey: MOCK_VERIFICATION_KEY,
40
40
  };
41
41
  };
42
42
  }
@@ -5,7 +5,7 @@ import { ToFieldable } from "../utils";
5
5
  export type O1JSPrimitive = ProvableExtended<unknown> & ToFieldable;
6
6
  export type ArgumentTypes = O1JSPrimitive[] | Proof<unknown, unknown>[];
7
7
  export type DecoratedMethod = (...args: ArgumentTypes) => unknown;
8
- export declare const mockProof = "mock-proof";
8
+ export declare const MOCK_PROOF = "mock-proof";
9
9
  export declare function toProver(methodName: string, simulatedMethod: DecoratedMethod, isFirstParameterPublicInput: boolean, ...args: ArgumentTypes): (this: ZkProgrammable<any, any>) => Promise<Proof<any, any>>;
10
10
  /**
11
11
  * Decorates a provable method on a 'prover class', depending on
@@ -1 +1 @@
1
- {"version":3,"file":"provableMethod.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/provableMethod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AAGjE,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,MAAM,aAAa,GAAG,gBAAgB,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC;AACpE,MAAM,MAAM,aAAa,GAAG,aAAa,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC;AAGxE,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC;AAElE,eAAO,MAAM,SAAS,eAAe,CAAC;AAEtC,wBAAgB,QAAQ,CACtB,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,eAAe,EAChC,2BAA2B,EAAE,OAAO,EACpC,GAAG,IAAI,EAAE,aAAa,UAGa,eAAe,GAAG,EAAE,GAAG,CAAC,8BAyB5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,2BAA2B,UAAO,EAClC,gBAAgB,GAAE,8BAEjB,wGAOa,MAAM,cACN,kBAAkB,wBA4CjC"}
1
+ {"version":3,"file":"provableMethod.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/provableMethod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AAGjE,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,MAAM,aAAa,GAAG,gBAAgB,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC;AACpE,MAAM,MAAM,aAAa,GAAG,aAAa,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC;AAGxE,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC;AAElE,eAAO,MAAM,UAAU,eAAe,CAAC;AAEvC,wBAAgB,QAAQ,CACtB,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,eAAe,EAChC,2BAA2B,EAAE,OAAO,EACpC,GAAG,IAAI,EAAE,aAAa,UAGa,eAAe,GAAG,EAAE,GAAG,CAAC,8BAyB5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,2BAA2B,UAAO,EAClC,gBAAgB,GAAE,8BAEjB,wGAOa,MAAM,cACN,kBAAkB,wBA4CjC"}
@@ -1,6 +1,6 @@
1
1
  import { container } from "tsyringe";
2
2
  import { ProvableMethodExecutionContext } from "./ProvableMethodExecutionContext";
3
- export const mockProof = "mock-proof";
3
+ export const MOCK_PROOF = "mock-proof";
4
4
  export function toProver(methodName, simulatedMethod, isFirstParameterPublicInput, ...args) {
5
5
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
6
  return async function prover() {
@@ -12,7 +12,7 @@ export function toProver(methodName, simulatedMethod, isFirstParameterPublicInpu
12
12
  // create a mock proof by simulating method execution in JS
13
13
  const publicOutput = Reflect.apply(simulatedMethod, this, args);
14
14
  return new this.zkProgram.Proof({
15
- proof: mockProof,
15
+ proof: MOCK_PROOF,
16
16
  // eslint-disable-next-line no-warning-comments
17
17
  // TODO: provide undefined if public input is not used
18
18
  publicInput: isFirstParameterPublicInput ? args[0] : undefined,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "license": "MIT",
4
4
  "private": false,
5
5
  "type": "module",
6
- "version": "0.1.1-develop.340+730512d",
6
+ "version": "0.1.1-develop.456+bdb345d",
7
7
  "scripts": {
8
8
  "build": "tsc -p tsconfig.json",
9
9
  "dev": "tsc -p tsconfig.json --watch",
@@ -30,5 +30,5 @@
30
30
  "@jest/globals": "^29.5.0",
31
31
  "@types/lodash": "^4.14.194"
32
32
  },
33
- "gitHead": "730512da45bf47d359a259ea24b357a17f610548"
33
+ "gitHead": "bdb345d9e6132387a870c8a4236d8fe295502ce4"
34
34
  }
@@ -19,10 +19,12 @@ export interface Configurable<Config> {
19
19
  config: Config;
20
20
  }
21
21
 
22
+ export type NoConfig = Record<string, never>;
23
+
22
24
  /**
23
25
  * Used by various module sub-types that may need to be configured
24
26
  */
25
- export class ConfigurableModule<Config>
27
+ export class ConfigurableModule<Config = NoConfig>
26
28
  implements BaseModuleInstanceType
27
29
  {
28
30
  /**