@proto-kit/common 0.1.1-develop.165 → 0.1.1-develop.1665
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/dist/compiling/AtomicCompileHelper.d.ts +13 -0
- package/dist/compiling/AtomicCompileHelper.d.ts.map +1 -0
- package/dist/compiling/AtomicCompileHelper.js +40 -0
- package/dist/compiling/AtomicCompileHelper.js.map +1 -0
- package/dist/compiling/CompilableModule.d.ts +6 -0
- package/dist/compiling/CompilableModule.d.ts.map +1 -0
- package/dist/compiling/CompilableModule.js +2 -0
- package/dist/compiling/CompilableModule.js.map +1 -0
- package/dist/compiling/CompileRegistry.d.ts +26 -0
- package/dist/compiling/CompileRegistry.d.ts.map +1 -0
- package/dist/compiling/CompileRegistry.js +69 -0
- package/dist/compiling/CompileRegistry.js.map +1 -0
- package/dist/compiling/services/ChildVerificationKeyService.d.ts +10 -0
- package/dist/compiling/services/ChildVerificationKeyService.d.ts.map +1 -0
- package/dist/compiling/services/ChildVerificationKeyService.js +27 -0
- package/dist/compiling/services/ChildVerificationKeyService.js.map +1 -0
- package/dist/config/ChildContainerCreatable.d.ts +5 -0
- package/dist/config/ChildContainerCreatable.d.ts.map +1 -0
- package/dist/config/ChildContainerCreatable.js +2 -0
- package/dist/config/ChildContainerCreatable.js.map +1 -0
- package/dist/config/ChildContainerProvider.d.ts +5 -0
- package/dist/config/ChildContainerProvider.d.ts.map +1 -0
- package/dist/config/ChildContainerProvider.js +2 -0
- package/dist/config/ChildContainerProvider.js.map +1 -0
- package/dist/config/ConfigurableModule.d.ts +6 -2
- package/dist/config/ConfigurableModule.d.ts.map +1 -1
- package/dist/config/ConfigurableModule.js +5 -0
- package/dist/config/ConfigurableModule.js.map +1 -0
- package/dist/config/ModuleContainer.d.ts +70 -17
- package/dist/config/ModuleContainer.d.ts.map +1 -1
- package/dist/config/ModuleContainer.js +164 -22
- package/dist/config/ModuleContainer.js.map +1 -0
- package/dist/config/Startable.d.ts +4 -0
- package/dist/config/Startable.d.ts.map +1 -0
- package/dist/config/Startable.js +2 -0
- package/dist/config/Startable.js.map +1 -0
- package/dist/config/injectAlias.d.ts +18 -0
- package/dist/config/injectAlias.d.ts.map +1 -0
- package/dist/config/injectAlias.js +47 -0
- package/dist/config/injectAlias.js.map +1 -0
- package/dist/dependencyFactory/DependencyFactory.d.ts +29 -0
- package/dist/dependencyFactory/DependencyFactory.d.ts.map +1 -0
- package/dist/dependencyFactory/DependencyFactory.js +2 -0
- package/dist/dependencyFactory/DependencyFactory.js.map +1 -0
- package/dist/dummyVerificationKey.d.ts +3 -0
- package/dist/dummyVerificationKey.d.ts.map +1 -0
- package/dist/dummyVerificationKey.js +8 -0
- package/dist/dummyVerificationKey.js.map +1 -0
- package/dist/events/EventEmitter.d.ts +19 -0
- package/dist/events/EventEmitter.d.ts.map +1 -0
- package/dist/events/EventEmitter.js +35 -0
- package/dist/events/EventEmitter.js.map +1 -0
- package/dist/events/EventEmitterProxy.d.ts +18 -0
- package/dist/events/EventEmitterProxy.d.ts.map +1 -0
- package/dist/events/EventEmitterProxy.js +35 -0
- package/dist/events/EventEmitterProxy.js.map +1 -0
- package/dist/events/EventEmittingComponent.d.ts +9 -0
- package/dist/events/EventEmittingComponent.d.ts.map +1 -0
- package/dist/events/EventEmittingComponent.js +2 -0
- package/dist/events/EventEmittingComponent.js.map +1 -0
- package/dist/events/ReplayingSingleUseEventEmitter.d.ts +17 -0
- package/dist/events/ReplayingSingleUseEventEmitter.d.ts.map +1 -0
- package/dist/events/ReplayingSingleUseEventEmitter.js +34 -0
- package/dist/events/ReplayingSingleUseEventEmitter.js.map +1 -0
- package/dist/index.d.ts +24 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -2
- package/dist/index.js.map +1 -0
- package/dist/log.d.ts +37 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +114 -0
- package/dist/log.js.map +1 -0
- package/dist/trees/lmt/AbstractLinkedMerkleTree.d.ts +288 -0
- package/dist/trees/lmt/AbstractLinkedMerkleTree.d.ts.map +1 -0
- package/dist/trees/lmt/AbstractLinkedMerkleTree.js +22 -0
- package/dist/trees/lmt/AbstractLinkedMerkleTree.js.map +1 -0
- package/dist/trees/lmt/InMemoryLinkedLeafStore.d.ts +21 -0
- package/dist/trees/lmt/InMemoryLinkedLeafStore.d.ts.map +1 -0
- package/dist/trees/lmt/InMemoryLinkedLeafStore.js +26 -0
- package/dist/trees/lmt/InMemoryLinkedLeafStore.js.map +1 -0
- package/dist/trees/lmt/LinkedLeafStore.d.ts +16 -0
- package/dist/trees/lmt/LinkedLeafStore.d.ts.map +1 -0
- package/dist/trees/lmt/LinkedLeafStore.js +2 -0
- package/dist/trees/lmt/LinkedLeafStore.js.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTree.d.ts +11 -0
- package/dist/trees/lmt/LinkedMerkleTree.d.ts.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTree.js +241 -0
- package/dist/trees/lmt/LinkedMerkleTree.js.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTreeCircuitOps.d.ts +113 -0
- package/dist/trees/lmt/LinkedMerkleTreeCircuitOps.d.ts.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTreeCircuitOps.js +113 -0
- package/dist/trees/lmt/LinkedMerkleTreeCircuitOps.js.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTreeTypes.d.ts +74 -0
- package/dist/trees/lmt/LinkedMerkleTreeTypes.d.ts.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTreeTypes.js +50 -0
- package/dist/trees/lmt/LinkedMerkleTreeTypes.js.map +1 -0
- package/dist/trees/sparse/InMemoryMerkleTreeStorage.d.ts +11 -0
- package/dist/trees/sparse/InMemoryMerkleTreeStorage.d.ts.map +1 -0
- package/dist/trees/sparse/InMemoryMerkleTreeStorage.js +13 -0
- package/dist/trees/sparse/InMemoryMerkleTreeStorage.js.map +1 -0
- package/dist/trees/sparse/MerkleTreeStore.d.ts +5 -0
- package/dist/trees/sparse/MerkleTreeStore.d.ts.map +1 -0
- package/dist/trees/sparse/MerkleTreeStore.js +2 -0
- package/dist/trees/sparse/MerkleTreeStore.js.map +1 -0
- package/dist/trees/sparse/MockAsyncMerkleStore.d.ts +9 -0
- package/dist/trees/sparse/MockAsyncMerkleStore.d.ts.map +1 -0
- package/dist/trees/sparse/MockAsyncMerkleStore.js +20 -0
- package/dist/trees/sparse/MockAsyncMerkleStore.js.map +1 -0
- package/dist/trees/sparse/RollupMerkleTree.d.ts +157 -0
- package/dist/trees/sparse/RollupMerkleTree.d.ts.map +1 -0
- package/dist/trees/sparse/RollupMerkleTree.js +272 -0
- package/dist/trees/sparse/RollupMerkleTree.js.map +1 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +12 -1
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +62 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +155 -0
- package/dist/utils.js.map +1 -0
- package/dist/zkProgrammable/ProvableMethodExecutionContext.d.ts +4 -3
- package/dist/zkProgrammable/ProvableMethodExecutionContext.d.ts.map +1 -1
- package/dist/zkProgrammable/ProvableMethodExecutionContext.js +2 -3
- package/dist/zkProgrammable/ProvableMethodExecutionContext.js.map +1 -0
- package/dist/zkProgrammable/ZkProgrammable.d.ts +15 -7
- package/dist/zkProgrammable/ZkProgrammable.d.ts.map +1 -1
- package/dist/zkProgrammable/ZkProgrammable.js +34 -15
- package/dist/zkProgrammable/ZkProgrammable.js.map +1 -0
- package/dist/zkProgrammable/provableMethod.d.ts +8 -5
- package/dist/zkProgrammable/provableMethod.d.ts.map +1 -1
- package/dist/zkProgrammable/provableMethod.js +15 -13
- package/dist/zkProgrammable/provableMethod.js.map +1 -0
- package/jest.config.cjs +12 -1
- package/package.json +8 -7
- package/src/compiling/AtomicCompileHelper.ts +62 -0
- package/src/compiling/CompilableModule.ts +6 -0
- package/src/compiling/CompileRegistry.ts +79 -0
- package/src/compiling/services/ChildVerificationKeyService.ts +26 -0
- package/src/config/ChildContainerCreatable.ts +5 -0
- package/src/config/ChildContainerProvider.ts +5 -0
- package/src/config/ConfigurableModule.ts +15 -2
- package/src/config/ModuleContainer.ts +287 -46
- package/src/config/Startable.ts +3 -0
- package/src/config/injectAlias.ts +70 -0
- package/src/dependencyFactory/DependencyFactory.ts +57 -0
- package/src/dummyVerificationKey.ts +10 -0
- package/src/events/EventEmitter.ts +61 -0
- package/src/events/EventEmitterProxy.ts +81 -0
- package/src/events/EventEmittingComponent.ts +11 -0
- package/src/events/ReplayingSingleUseEventEmitter.ts +42 -0
- package/src/index.ts +24 -2
- package/src/log.ts +143 -0
- package/src/trees/lmt/AbstractLinkedMerkleTree.ts +102 -0
- package/src/trees/lmt/InMemoryLinkedLeafStore.ts +42 -0
- package/src/trees/lmt/LinkedLeafStore.ts +13 -0
- package/src/trees/lmt/LinkedMerkleTree.ts +335 -0
- package/src/trees/lmt/LinkedMerkleTreeCircuitOps.ts +188 -0
- package/src/trees/lmt/LinkedMerkleTreeTypes.ts +53 -0
- package/src/trees/sparse/InMemoryMerkleTreeStorage.ts +17 -0
- package/src/trees/sparse/MerkleTreeStore.ts +5 -0
- package/src/trees/sparse/MockAsyncMerkleStore.ts +30 -0
- package/src/trees/sparse/RollupMerkleTree.ts +427 -0
- package/src/types.ts +43 -2
- package/src/utils.ts +287 -0
- package/src/zkProgrammable/ProvableMethodExecutionContext.ts +6 -6
- package/src/zkProgrammable/ZkProgrammable.ts +61 -29
- package/src/zkProgrammable/provableMethod.ts +38 -21
- package/test/config/ContainerEvents.test.ts +65 -0
- package/test/config/ModuleContainer.test.ts +146 -15
- package/test/config/injectAlias.test.ts +28 -0
- package/test/trees/LinkedMerkleTree.test.ts +124 -0
- package/test/trees/LinkedMerkleTreeCircuitOps.test.ts +147 -0
- package/test/trees/MerkleTree.test.ts +220 -0
- package/test/tsconfig.json +5 -2
- package/test/zkProgrammable/ZkProgrammable.test.ts +135 -114
- package/tsconfig.json +1 -1
- package/dist/Constants.d.ts +0 -4
- package/dist/Constants.d.ts.map +0 -1
- package/dist/Constants.js +0 -3
- package/dist/config/ConfigurationAggregator.d.ts +0 -10
- package/dist/config/ConfigurationAggregator.d.ts.map +0 -1
- package/dist/config/ConfigurationAggregator.js +0 -35
- package/dist/config/ConfigurationReceiver.d.ts +0 -25
- package/dist/config/ConfigurationReceiver.d.ts.map +0 -1
- package/dist/config/ConfigurationReceiver.js +0 -36
- package/dist/config/types.d.ts +0 -2
- package/dist/config/types.d.ts.map +0 -1
- package/dist/config/types.js +0 -1
- package/dist/model/MethodPublicInput.d.ts +0 -51
- package/dist/model/MethodPublicInput.d.ts.map +0 -1
- package/dist/model/MethodPublicInput.js +0 -11
- package/dist/model/Option.d.ts +0 -89
- package/dist/model/Option.d.ts.map +0 -1
- package/dist/model/Option.js +0 -86
- package/dist/model/Path.d.ts +0 -31
- package/dist/model/Path.d.ts.map +0 -1
- package/dist/model/Path.js +0 -44
- package/dist/model/StateTransition.d.ts +0 -85
- package/dist/model/StateTransition.d.ts.map +0 -1
- package/dist/model/StateTransition.js +0 -58
- package/dist/model/StateTransitionProvableBatch.d.ts +0 -56
- package/dist/model/StateTransitionProvableBatch.d.ts.map +0 -1
- package/dist/model/StateTransitionProvableBatch.js +0 -20
- package/dist/prover/block/BlockProver.d.ts +0 -199
- package/dist/prover/block/BlockProver.d.ts.map +0 -1
- package/dist/prover/block/BlockProver.js +0 -119
- package/dist/prover/block/BlockScopedModule.d.ts +0 -3
- package/dist/prover/block/BlockScopedModule.d.ts.map +0 -1
- package/dist/prover/block/BlockScopedModule.js +0 -6
- package/dist/prover/statetransition/StateTransitionProver.d.ts +0 -92
- package/dist/prover/statetransition/StateTransitionProver.d.ts.map +0 -1
- package/dist/prover/statetransition/StateTransitionProver.js +0 -127
- package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts +0 -16
- package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts.map +0 -1
- package/dist/prover/statetransition/StateTransitionWitnessProvider.js +0 -17
- package/dist/src/model/Option.d.ts +0 -158
- package/dist/src/model/Option.d.ts.map +0 -1
- package/dist/src/model/Option.js +0 -53
- package/dist/src/model/Path.d.ts +0 -35
- package/dist/src/model/Path.d.ts.map +0 -1
- package/dist/src/model/Path.js +0 -51
- package/dist/src/model/StateTransition.d.ts +0 -201
- package/dist/src/model/StateTransition.d.ts.map +0 -1
- package/dist/src/model/StateTransition.js +0 -43
- package/dist/src/utils/PrefixedHashList.d.ts +0 -15
- package/dist/src/utils/PrefixedHashList.d.ts.map +0 -1
- package/dist/src/utils/PrefixedHashList.js +0 -28
- package/dist/src/utils/ProvableHashList.d.ts +0 -30
- package/dist/src/utils/ProvableHashList.d.ts.map +0 -1
- package/dist/src/utils/ProvableHashList.js +0 -43
- package/dist/utils/PrefixedHashList.d.ts +0 -14
- package/dist/utils/PrefixedHashList.d.ts.map +0 -1
- package/dist/utils/PrefixedHashList.js +0 -12
- package/dist/utils/PrefixedProvableHashList.d.ts +0 -8
- package/dist/utils/PrefixedProvableHashList.d.ts.map +0 -1
- package/dist/utils/PrefixedProvableHashList.js +0 -12
- package/dist/utils/ProvableHashList.d.ts +0 -26
- package/dist/utils/ProvableHashList.d.ts.map +0 -1
- package/dist/utils/ProvableHashList.js +0 -35
- package/dist/utils/Utils.d.ts +0 -22
- package/dist/utils/Utils.d.ts.map +0 -1
- package/dist/utils/Utils.js +0 -41
- package/dist/utils/merkletree/MemoryMerkleTreeStorage.d.ts +0 -26
- package/dist/utils/merkletree/MemoryMerkleTreeStorage.d.ts.map +0 -1
- package/dist/utils/merkletree/MemoryMerkleTreeStorage.js +0 -79
- package/dist/utils/merkletree/RollupMerkleTree.d.ts +0 -143
- package/dist/utils/merkletree/RollupMerkleTree.d.ts.map +0 -1
- package/dist/utils/merkletree/RollupMerkleTree.js +0 -246
- package/tsconfig.test.json +0 -9
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { beforeEach } from "@jest/globals";
|
|
2
|
+
import { Field } from "o1js";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
createMerkleTree,
|
|
6
|
+
InMemoryMerkleTreeStorage,
|
|
7
|
+
log,
|
|
8
|
+
RollupMerkleTree,
|
|
9
|
+
range,
|
|
10
|
+
} from "../../src";
|
|
11
|
+
|
|
12
|
+
describe("batch setLeaf", () => {
|
|
13
|
+
function generateBatch(
|
|
14
|
+
size: number,
|
|
15
|
+
height: number,
|
|
16
|
+
generator = () => Field.random().toBigInt()
|
|
17
|
+
) {
|
|
18
|
+
const max = 2n ** BigInt(height - 1);
|
|
19
|
+
return range(0, size).map(() => ({
|
|
20
|
+
index: generator() % max,
|
|
21
|
+
leaf: Field.random(),
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function generateBatchAdjacent(size: number, height: number) {
|
|
26
|
+
let start = 0n;
|
|
27
|
+
return generateBatch(size, height, () => {
|
|
28
|
+
start += 1n;
|
|
29
|
+
return start - 1n;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function captureTime<R>(f: () => R): [number, R] {
|
|
34
|
+
const start = Date.now();
|
|
35
|
+
const ret = f();
|
|
36
|
+
return [Date.now() - start, ret];
|
|
37
|
+
}
|
|
38
|
+
const height = 10;
|
|
39
|
+
const maxIndex = 2n ** BigInt(height - 1) - 1n;
|
|
40
|
+
|
|
41
|
+
it.each([
|
|
42
|
+
[
|
|
43
|
+
{ index: 1n, leaf: Field(5) },
|
|
44
|
+
{ index: maxIndex, leaf: Field(7) },
|
|
45
|
+
],
|
|
46
|
+
[
|
|
47
|
+
{ index: maxIndex, leaf: Field(7) },
|
|
48
|
+
{ index: maxIndex - 1n, leaf: Field(7) },
|
|
49
|
+
{ index: 50n, leaf: Field(7) },
|
|
50
|
+
{ index: 1n, leaf: Field(5) },
|
|
51
|
+
],
|
|
52
|
+
generateBatch(5, height),
|
|
53
|
+
generateBatch(10, height),
|
|
54
|
+
generateBatch(50, height),
|
|
55
|
+
generateBatch(300, height),
|
|
56
|
+
])("correctness", (...writes) => {
|
|
57
|
+
const Tree = createMerkleTree(height);
|
|
58
|
+
const tree1 = new Tree(new InMemoryMerkleTreeStorage());
|
|
59
|
+
const tree2 = new Tree(new InMemoryMerkleTreeStorage());
|
|
60
|
+
|
|
61
|
+
writes.forEach(({ index, leaf }) => {
|
|
62
|
+
tree1.setLeaf(index, leaf);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
tree2.setLeaves(writes);
|
|
66
|
+
|
|
67
|
+
expect(tree1.getRoot().toString()).toStrictEqual(
|
|
68
|
+
tree2.getRoot().toString()
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it.each([
|
|
73
|
+
// This tests the correct retrieval of previously-set siblings (vs. above
|
|
74
|
+
// where always fetch zero-siblings)
|
|
75
|
+
[[{ index: 1n, leaf: Field(5) }], [{ index: 4n, leaf: Field(1) }]],
|
|
76
|
+
[[{ index: 4n, leaf: Field(5) }], [{ index: 1n, leaf: Field(1) }]],
|
|
77
|
+
])("correctness - batches", (...writes) => {
|
|
78
|
+
expect.assertions(writes.length);
|
|
79
|
+
|
|
80
|
+
const Tree = createMerkleTree(height);
|
|
81
|
+
const tree1 = new Tree(new InMemoryMerkleTreeStorage());
|
|
82
|
+
const tree2 = new Tree(new InMemoryMerkleTreeStorage());
|
|
83
|
+
|
|
84
|
+
writes.forEach((writes2) => {
|
|
85
|
+
writes2.forEach(({ index, leaf }) => {
|
|
86
|
+
tree1.setLeaf(index, leaf);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
tree2.setLeaves(writes2);
|
|
90
|
+
|
|
91
|
+
expect(tree1.getRoot().toString()).toStrictEqual(
|
|
92
|
+
tree2.getRoot().toString()
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it.each([
|
|
98
|
+
["random", 10, generateBatch],
|
|
99
|
+
["random", 100, generateBatch],
|
|
100
|
+
["adjacent", 100, generateBatchAdjacent],
|
|
101
|
+
["adjacent", 10, generateBatchAdjacent],
|
|
102
|
+
])("test speedup: %s (%i leaves)", (label, batchSize, generateFunction) => {
|
|
103
|
+
const tree1 = new RollupMerkleTree(new InMemoryMerkleTreeStorage());
|
|
104
|
+
const tree2 = new RollupMerkleTree(new InMemoryMerkleTreeStorage());
|
|
105
|
+
|
|
106
|
+
const batch = generateFunction(batchSize, RollupMerkleTree.HEIGHT);
|
|
107
|
+
|
|
108
|
+
const slice = batch.slice();
|
|
109
|
+
const [time1] = captureTime(() => tree1.setLeaves(slice));
|
|
110
|
+
const [time2] = captureTime(() =>
|
|
111
|
+
batch.forEach(({ index, leaf }) => tree2.setLeaf(index, leaf))
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
console.log(`Speedup for batch size ${batchSize}, mode ${label}`);
|
|
115
|
+
console.log(time1);
|
|
116
|
+
console.log(time2);
|
|
117
|
+
|
|
118
|
+
expect(tree1.getRoot().toString()).toStrictEqual(
|
|
119
|
+
tree2.getRoot().toString()
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe.each([4, 16, 256])("cachedMerkleTree - %s", (height) => {
|
|
125
|
+
class MerkleTree extends createMerkleTree(height) {}
|
|
126
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
127
|
+
class MerkleTreeWitness extends MerkleTree.WITNESS {}
|
|
128
|
+
|
|
129
|
+
let store: InMemoryMerkleTreeStorage;
|
|
130
|
+
let tree: MerkleTree;
|
|
131
|
+
|
|
132
|
+
beforeEach(() => {
|
|
133
|
+
log.setLevel("INFO");
|
|
134
|
+
|
|
135
|
+
store = new InMemoryMerkleTreeStorage();
|
|
136
|
+
tree = new MerkleTree(store);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("should have the same root when empty", () => {
|
|
140
|
+
expect.assertions(1);
|
|
141
|
+
|
|
142
|
+
expect(tree.getRoot().toBigInt()).toStrictEqual(MerkleTree.EMPTY_ROOT);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("should have a different root when not empty", () => {
|
|
146
|
+
expect.assertions(1);
|
|
147
|
+
|
|
148
|
+
tree.setLeaf(1n, Field(1));
|
|
149
|
+
|
|
150
|
+
expect(tree.getRoot().toBigInt()).not.toStrictEqual(MerkleTree.EMPTY_ROOT);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("should have the same root after adding and removing item", () => {
|
|
154
|
+
expect.assertions(1);
|
|
155
|
+
|
|
156
|
+
tree.setLeaf(1n, Field(1));
|
|
157
|
+
|
|
158
|
+
const root = tree.getRoot();
|
|
159
|
+
|
|
160
|
+
tree.setLeaf(5n, Field(5));
|
|
161
|
+
tree.setLeaf(5n, Field(0));
|
|
162
|
+
|
|
163
|
+
expect(tree.getRoot().toBigInt()).toStrictEqual(root.toBigInt());
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("should provide correct witnesses", () => {
|
|
167
|
+
expect.assertions(1);
|
|
168
|
+
|
|
169
|
+
tree.setLeaf(1n, Field(1));
|
|
170
|
+
tree.setLeaf(5n, Field(5));
|
|
171
|
+
|
|
172
|
+
const witness = tree.getWitness(5n);
|
|
173
|
+
|
|
174
|
+
expect(witness.calculateRoot(Field(5)).toBigInt()).toStrictEqual(
|
|
175
|
+
tree.getRoot().toBigInt()
|
|
176
|
+
);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("should have invalid witnesses with wrong values", () => {
|
|
180
|
+
expect.assertions(1);
|
|
181
|
+
|
|
182
|
+
tree.setLeaf(1n, Field(1));
|
|
183
|
+
tree.setLeaf(5n, Field(5));
|
|
184
|
+
|
|
185
|
+
const witness = tree.getWitness(5n);
|
|
186
|
+
|
|
187
|
+
expect(witness.calculateRoot(Field(6)).toBigInt()).not.toStrictEqual(
|
|
188
|
+
tree.getRoot().toBigInt()
|
|
189
|
+
);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("should have valid witnesses with changed value on the same leafs", () => {
|
|
193
|
+
expect.assertions(1);
|
|
194
|
+
|
|
195
|
+
tree.setLeaf(1n, Field(1));
|
|
196
|
+
tree.setLeaf(5n, Field(5));
|
|
197
|
+
|
|
198
|
+
const witness = tree.getWitness(5n);
|
|
199
|
+
|
|
200
|
+
tree.setLeaf(5n, Field(10));
|
|
201
|
+
|
|
202
|
+
expect(witness.calculateRoot(Field(10)).toBigInt()).toStrictEqual(
|
|
203
|
+
tree.getRoot().toBigInt()
|
|
204
|
+
);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("should throw for invalid index", () => {
|
|
208
|
+
expect.assertions(2);
|
|
209
|
+
|
|
210
|
+
const index = 2n ** BigInt(height) + 1n;
|
|
211
|
+
|
|
212
|
+
expect(() => {
|
|
213
|
+
tree.setLeaf(index, Field(1));
|
|
214
|
+
}).toThrow("Index greater than maximum leaf number");
|
|
215
|
+
|
|
216
|
+
expect(() => {
|
|
217
|
+
tree.getNode(0, index);
|
|
218
|
+
}).toThrow("Index greater than maximum leaf number");
|
|
219
|
+
});
|
|
220
|
+
});
|
package/test/tsconfig.json
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
/* eslint-disable max-classes-per-file */
|
|
2
1
|
import "reflect-metadata";
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
4
2
|
import { jest } from "@jest/globals";
|
|
5
3
|
import { container } from "tsyringe";
|
|
6
|
-
import {
|
|
4
|
+
import { Field, Struct, Proof, ZkProgram } from "o1js";
|
|
7
5
|
|
|
8
6
|
import {
|
|
9
|
-
|
|
7
|
+
MOCK_PROOF,
|
|
10
8
|
provableMethod,
|
|
11
|
-
} from "../../src/zkProgrammable/provableMethod";
|
|
12
|
-
import {
|
|
13
9
|
AreProofsEnabled,
|
|
14
10
|
CompileArtifact,
|
|
15
|
-
|
|
16
|
-
PlainZkProgram,
|
|
11
|
+
MOCK_VERIFICATION_KEY,
|
|
17
12
|
ZkProgrammable,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import { Pickles } from "snarkyjs/dist/node/snarky";
|
|
13
|
+
ProvableMethodExecutionContext,
|
|
14
|
+
} from "../../src";
|
|
21
15
|
|
|
22
16
|
const appChainMock: AreProofsEnabled = {
|
|
23
17
|
areProofsEnabled: false,
|
|
@@ -37,14 +31,16 @@ class TestPublicOutput extends Struct({
|
|
|
37
31
|
|
|
38
32
|
const failErrorMessage = "test failure";
|
|
39
33
|
|
|
34
|
+
type Balance = Field;
|
|
35
|
+
|
|
40
36
|
class TestProgrammable extends ZkProgrammable<
|
|
41
37
|
TestPublicInput,
|
|
42
38
|
TestPublicOutput
|
|
43
39
|
> {
|
|
44
|
-
public
|
|
40
|
+
public areProofsEnabled: AreProofsEnabled = appChainMock;
|
|
45
41
|
|
|
46
42
|
@provableMethod()
|
|
47
|
-
public foo(publicInput: TestPublicInput, bar:
|
|
43
|
+
public async foo(publicInput: TestPublicInput, bar: Balance) {
|
|
48
44
|
// expose the private input as public output again for testing purposes
|
|
49
45
|
return new TestPublicOutput({
|
|
50
46
|
bar,
|
|
@@ -52,7 +48,7 @@ class TestProgrammable extends ZkProgrammable<
|
|
|
52
48
|
}
|
|
53
49
|
|
|
54
50
|
@provableMethod()
|
|
55
|
-
public fail(publicInput: TestPublicInput) {
|
|
51
|
+
public async fail(publicInput: TestPublicInput) {
|
|
56
52
|
publicInput.foo.assertEquals(1, failErrorMessage);
|
|
57
53
|
|
|
58
54
|
return new TestPublicOutput({
|
|
@@ -61,7 +57,8 @@ class TestProgrammable extends ZkProgrammable<
|
|
|
61
57
|
}
|
|
62
58
|
|
|
63
59
|
public zkProgramFactory() {
|
|
64
|
-
const program =
|
|
60
|
+
const program = ZkProgram({
|
|
61
|
+
name: "testprogram",
|
|
65
62
|
publicInput: TestPublicInput,
|
|
66
63
|
publicOutput: TestPublicOutput,
|
|
67
64
|
|
|
@@ -78,43 +75,46 @@ class TestProgrammable extends ZkProgrammable<
|
|
|
78
75
|
},
|
|
79
76
|
});
|
|
80
77
|
|
|
81
|
-
const SelfProof =
|
|
78
|
+
const SelfProof = ZkProgram.Proof(program);
|
|
82
79
|
|
|
83
80
|
const methods = {
|
|
84
81
|
foo: program.foo.bind(program),
|
|
85
82
|
fail: program.fail.bind(program),
|
|
86
83
|
};
|
|
87
84
|
|
|
88
|
-
return
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
85
|
+
return [
|
|
86
|
+
{
|
|
87
|
+
name: program.name,
|
|
88
|
+
compile: program.compile.bind(program),
|
|
89
|
+
verify: program.verify.bind(program),
|
|
90
|
+
analyzeMethods: program.analyzeMethods.bind(program),
|
|
91
|
+
Proof: SelfProof,
|
|
92
|
+
methods,
|
|
93
|
+
},
|
|
94
|
+
];
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
|
|
97
|
-
class OtherTestProgrammable extends ZkProgrammable {
|
|
98
|
-
public
|
|
98
|
+
class OtherTestProgrammable extends ZkProgrammable<undefined, void> {
|
|
99
|
+
public areProofsEnabled: AreProofsEnabled = appChainMock;
|
|
99
100
|
|
|
100
101
|
public constructor(public testProgrammable: TestProgrammable) {
|
|
101
102
|
super();
|
|
102
103
|
}
|
|
103
104
|
|
|
105
|
+
proofType = this.testProgrammable.zkProgram[0].Proof;
|
|
106
|
+
|
|
104
107
|
@provableMethod()
|
|
105
|
-
public bar(
|
|
106
|
-
testProgrammableProof: InstanceType<
|
|
107
|
-
typeof this.testProgrammable.zkProgram.Proof
|
|
108
|
-
>
|
|
109
|
-
) {
|
|
108
|
+
public async bar(testProgrammableProof: InstanceType<typeof this.proofType>) {
|
|
110
109
|
testProgrammableProof.verify();
|
|
111
110
|
}
|
|
112
111
|
|
|
113
|
-
public zkProgramFactory()
|
|
114
|
-
const program =
|
|
112
|
+
public zkProgramFactory() {
|
|
113
|
+
const program = ZkProgram({
|
|
114
|
+
name: "testprogram2",
|
|
115
115
|
methods: {
|
|
116
116
|
bar: {
|
|
117
|
-
privateInputs: [this.testProgrammable.zkProgram.Proof],
|
|
117
|
+
privateInputs: [this.testProgrammable.zkProgram[0].Proof],
|
|
118
118
|
method: this.bar.bind(this),
|
|
119
119
|
},
|
|
120
120
|
},
|
|
@@ -124,47 +124,68 @@ class OtherTestProgrammable extends ZkProgrammable {
|
|
|
124
124
|
bar: program.bar.bind(program),
|
|
125
125
|
};
|
|
126
126
|
|
|
127
|
-
const SelfProof =
|
|
127
|
+
const SelfProof = ZkProgram.Proof(program);
|
|
128
128
|
|
|
129
|
-
return
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
129
|
+
return [
|
|
130
|
+
{
|
|
131
|
+
name: program.name,
|
|
132
|
+
compile: program.compile.bind(program),
|
|
133
|
+
verify: program.verify.bind(program),
|
|
134
|
+
analyzeMethods: program.analyzeMethods.bind(program),
|
|
135
|
+
Proof: SelfProof,
|
|
136
|
+
methods,
|
|
137
|
+
},
|
|
138
|
+
];
|
|
135
139
|
}
|
|
136
140
|
}
|
|
137
141
|
|
|
142
|
+
const testWithProofs = false;
|
|
143
|
+
|
|
138
144
|
describe("zkProgrammable", () => {
|
|
139
145
|
let testProgrammable: TestProgrammable;
|
|
140
146
|
let artifact: CompileArtifact;
|
|
141
147
|
let zkProgramFactorySpy: ReturnType<typeof jest.spyOn>;
|
|
142
148
|
|
|
143
|
-
|
|
149
|
+
const testCases: [
|
|
150
|
+
boolean,
|
|
151
|
+
{
|
|
152
|
+
verificationKey: CompileArtifact["verificationKey"];
|
|
153
|
+
shouldVerifyMockProofs: boolean;
|
|
154
|
+
},
|
|
155
|
+
][] = [
|
|
144
156
|
[
|
|
145
157
|
false,
|
|
146
158
|
{
|
|
147
|
-
verificationKey:
|
|
159
|
+
verificationKey: MOCK_VERIFICATION_KEY,
|
|
148
160
|
shouldVerifyMockProofs: true,
|
|
149
161
|
},
|
|
150
162
|
],
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
163
|
+
];
|
|
164
|
+
|
|
165
|
+
// We want to disable testing with proofs enabled for the CI and other stuff,
|
|
166
|
+
// as it is quite expensive. But we should find a better pattern than this
|
|
167
|
+
if (testWithProofs) {
|
|
168
|
+
// TODO Migrate to new o1js compile artifact format
|
|
169
|
+
// testCases.push([
|
|
170
|
+
// true,
|
|
171
|
+
// {
|
|
172
|
+
// verificationKey:
|
|
173
|
+
// eslint-disable-next-line max-len
|
|
174
|
+
// "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",
|
|
175
|
+
//
|
|
176
|
+
// shouldVerifyMockProofs: false,
|
|
177
|
+
// },
|
|
178
|
+
// ]);
|
|
179
|
+
}
|
|
156
180
|
|
|
157
|
-
|
|
158
|
-
},
|
|
159
|
-
],
|
|
160
|
-
])(
|
|
181
|
+
describe.each(testCases)(
|
|
161
182
|
"areProofsEnabled",
|
|
162
183
|
(areProofsEnabled, { verificationKey, shouldVerifyMockProofs }) => {
|
|
163
184
|
beforeAll(async () => {
|
|
164
185
|
testProgrammable = new TestProgrammable();
|
|
165
|
-
testProgrammable.
|
|
186
|
+
testProgrammable.areProofsEnabled.setProofsEnabled(areProofsEnabled);
|
|
166
187
|
zkProgramFactorySpy = jest.spyOn(testProgrammable, "zkProgramFactory");
|
|
167
|
-
artifact = await testProgrammable.zkProgram.compile();
|
|
188
|
+
artifact = await testProgrammable.zkProgram[0].compile();
|
|
168
189
|
}, 500_000);
|
|
169
190
|
|
|
170
191
|
describe("zkProgramFactory", () => {
|
|
@@ -191,8 +212,8 @@ describe("zkProgrammable", () => {
|
|
|
191
212
|
it("if proofs are disabled, it should successfully verify mock proofs", async () => {
|
|
192
213
|
expect.assertions(1);
|
|
193
214
|
|
|
194
|
-
const proof = new testProgrammable.zkProgram.Proof({
|
|
195
|
-
proof:
|
|
215
|
+
const proof = new testProgrammable.zkProgram[0].Proof({
|
|
216
|
+
proof: MOCK_PROOF,
|
|
196
217
|
|
|
197
218
|
publicInput: new TestPublicInput({
|
|
198
219
|
foo: Field(0),
|
|
@@ -205,7 +226,7 @@ describe("zkProgrammable", () => {
|
|
|
205
226
|
maxProofsVerified: 0,
|
|
206
227
|
});
|
|
207
228
|
|
|
208
|
-
const verified = await testProgrammable.zkProgram.verify(proof);
|
|
229
|
+
const verified = await testProgrammable.zkProgram[0].verify(proof);
|
|
209
230
|
|
|
210
231
|
expect(verified).toBe(shouldVerifyMockProofs);
|
|
211
232
|
|
|
@@ -213,71 +234,71 @@ describe("zkProgrammable", () => {
|
|
|
213
234
|
// const json = proof.toJSON();
|
|
214
235
|
// expect(json).toBeDefined();
|
|
215
236
|
});
|
|
216
|
-
}
|
|
217
|
-
);
|
|
218
237
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
238
|
+
describe("provableMethod", () => {
|
|
239
|
+
const executionContext =
|
|
240
|
+
container.resolve<ProvableMethodExecutionContext>(
|
|
241
|
+
ProvableMethodExecutionContext
|
|
242
|
+
);
|
|
223
243
|
|
|
224
|
-
|
|
244
|
+
let otherTestProgrammable: OtherTestProgrammable;
|
|
225
245
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
describe("zkProgram interoperability", () => {
|
|
231
|
-
beforeAll(async () => {
|
|
232
|
-
otherTestProgrammable = new OtherTestProgrammable(testProgrammable);
|
|
233
|
-
await otherTestProgrammable.zkProgram.compile();
|
|
234
|
-
}, 500_000);
|
|
235
|
-
|
|
236
|
-
it("should successfully pass proof of one zkProgram as input to another zkProgram", async () => {
|
|
237
|
-
expect.assertions(3);
|
|
238
|
-
|
|
239
|
-
// execute foo
|
|
240
|
-
testProgrammable.foo(testPublicInput, Field(0));
|
|
241
|
-
|
|
242
|
-
// prove foo
|
|
243
|
-
const testProof = await executionContext
|
|
244
|
-
.current()
|
|
245
|
-
.result.prove<Proof<TestPublicInput, TestPublicOutput>>();
|
|
246
|
-
const testProofVerified = await testProgrammable.zkProgram.verify(
|
|
247
|
-
testProof
|
|
248
|
-
);
|
|
249
|
-
|
|
250
|
-
// execute bar
|
|
251
|
-
otherTestProgrammable.bar(testProof);
|
|
252
|
-
|
|
253
|
-
// proof bar
|
|
254
|
-
const otherTestProof = await executionContext
|
|
255
|
-
.current()
|
|
256
|
-
.result.prove<Proof<undefined, void>>();
|
|
257
|
-
const otherTestProofVerified =
|
|
258
|
-
await otherTestProgrammable.zkProgram.verify(otherTestProof);
|
|
259
|
-
|
|
260
|
-
expect(testProof.publicOutput.bar.toString()).toBe(
|
|
261
|
-
testPublicInput.foo.toString()
|
|
262
|
-
);
|
|
246
|
+
const testPublicInput = new TestPublicInput({
|
|
247
|
+
foo: Field(0),
|
|
248
|
+
});
|
|
263
249
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
250
|
+
describe("zkProgram interoperability", () => {
|
|
251
|
+
beforeAll(async () => {
|
|
252
|
+
otherTestProgrammable = new OtherTestProgrammable(testProgrammable);
|
|
253
|
+
await otherTestProgrammable.zkProgram[0].compile();
|
|
254
|
+
}, 500_000);
|
|
255
|
+
|
|
256
|
+
it("should successfully pass proof of one zkProgram as input to another zkProgram", async () => {
|
|
257
|
+
expect.assertions(3);
|
|
258
|
+
|
|
259
|
+
// execute foo
|
|
260
|
+
await testProgrammable.foo(testPublicInput, Field(0));
|
|
261
|
+
|
|
262
|
+
// prove foo
|
|
263
|
+
const testProof = await executionContext
|
|
264
|
+
.current()
|
|
265
|
+
.result.prove<Proof<TestPublicInput, TestPublicOutput>>();
|
|
266
|
+
const testProofVerified =
|
|
267
|
+
await testProgrammable.zkProgram[0].verify(testProof);
|
|
268
|
+
|
|
269
|
+
// execute bar
|
|
270
|
+
await otherTestProgrammable.bar(testProof);
|
|
271
|
+
|
|
272
|
+
// proof bar
|
|
273
|
+
const otherTestProof = await executionContext
|
|
274
|
+
.current()
|
|
275
|
+
.result.prove<Proof<undefined, void>>();
|
|
276
|
+
const otherTestProofVerified =
|
|
277
|
+
await otherTestProgrammable.zkProgram[0].verify(otherTestProof);
|
|
278
|
+
|
|
279
|
+
expect(testProof.publicOutput.bar.toString()).toBe(
|
|
280
|
+
testPublicInput.foo.toString()
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
expect(testProofVerified).toBe(true);
|
|
284
|
+
expect(otherTestProofVerified).toBe(true);
|
|
285
|
+
}, 500_000);
|
|
286
|
+
});
|
|
268
287
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
288
|
+
describe("failed method execution", () => {
|
|
289
|
+
it("if the method fails, it should fail to execute and prove", async () => {
|
|
290
|
+
expect.assertions(2);
|
|
272
291
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
292
|
+
await expect(
|
|
293
|
+
testProgrammable.fail(testPublicInput)
|
|
294
|
+
).rejects.toThrow(failErrorMessage);
|
|
276
295
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
296
|
+
await expect(async () => {
|
|
297
|
+
await executionContext.current().result.prove();
|
|
298
|
+
}).rejects.toThrow(failErrorMessage);
|
|
299
|
+
});
|
|
300
|
+
});
|
|
280
301
|
});
|
|
281
|
-
}
|
|
282
|
-
|
|
302
|
+
}
|
|
303
|
+
);
|
|
283
304
|
});
|
package/tsconfig.json
CHANGED
package/dist/Constants.d.ts
DELETED
package/dist/Constants.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Constants.d.ts","sourceRoot":"","sources":["../src/Constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;CAErB,CAAC"}
|
package/dist/Constants.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ComponentConfig, Components, RemoveUndefinedKeys, UninitializedComponentConfig } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* In this context, a "Component" is just a way of generalizing Modules,
|
|
4
|
-
* because they don't have to be modules, they can be any configurable unit
|
|
5
|
-
*/
|
|
6
|
-
export declare abstract class ConfigurationAggregator<Comps extends Components> {
|
|
7
|
-
protected applyConfig(modules: Comps, currentConfig: UninitializedComponentConfig<ComponentConfig<Comps>>, config: RemoveUndefinedKeys<ComponentConfig<Comps>>): ComponentConfig<Comps>;
|
|
8
|
-
abstract configure(config: RemoveUndefinedKeys<ComponentConfig<Comps>>): void;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=ConfigurationAggregator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigurationAggregator.d.ts","sourceRoot":"","sources":["../../src/config/ConfigurationAggregator.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,eAAe,EACf,UAAU,EACV,mBAAmB,EACnB,4BAA4B,EAC7B,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,8BAAsB,uBAAuB,CAAC,KAAK,SAAS,UAAU;IACpE,SAAS,CAAC,WAAW,CACnB,OAAO,EAAE,KAAK,EACd,aAAa,EAAE,4BAA4B,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,EACnE,MAAM,EAAE,mBAAmB,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,GAClD,eAAe,CAAC,KAAK,CAAC;aAgCT,SAAS,CACvB,MAAM,EAAE,mBAAmB,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,GAClD,IAAI;CACR"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any,guard-for-in,@typescript-eslint/no-unsafe-member-access,max-len,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/consistent-type-assertions */
|
|
2
|
-
import merge from "lodash/merge";
|
|
3
|
-
/**
|
|
4
|
-
* In this context, a "Component" is just a way of generalizing Modules,
|
|
5
|
-
* because they don't have to be modules, they can be any configurable unit
|
|
6
|
-
*/
|
|
7
|
-
export class ConfigurationAggregator {
|
|
8
|
-
applyConfig(modules, currentConfig, config) {
|
|
9
|
-
const nextConfig = {};
|
|
10
|
-
for (const key in config) {
|
|
11
|
-
// Set config to module
|
|
12
|
-
if (currentConfig[key] === undefined) {
|
|
13
|
-
// Initialize config with merge between config and defaultConfig
|
|
14
|
-
// eslint-disable-next-line prefer-destructuring,putout/putout
|
|
15
|
-
const defaultConfig = modules[key].defaultConfig;
|
|
16
|
-
const newConfig = config[key];
|
|
17
|
-
for (const configKey in newConfig) {
|
|
18
|
-
defaultConfig[configKey] = newConfig[configKey];
|
|
19
|
-
}
|
|
20
|
-
// The result of that is always a valid Required<Config> since FlipOptional<Config> requires the exact opposite of Config
|
|
21
|
-
modules[key].config = defaultConfig;
|
|
22
|
-
nextConfig[key] = defaultConfig;
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
// Append/overwrite to existing config
|
|
26
|
-
const newConfig = config[key];
|
|
27
|
-
const moduleConfig = currentConfig[key];
|
|
28
|
-
merge(moduleConfig, newConfig);
|
|
29
|
-
modules[key].config = moduleConfig;
|
|
30
|
-
nextConfig[key] = moduleConfig;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return nextConfig;
|
|
34
|
-
}
|
|
35
|
-
}
|