@proto-kit/common 0.1.1-develop.187 → 0.1.1-develop.188

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 (73) hide show
  1. package/package.json +2 -2
  2. package/dist/Constants.d.ts +0 -4
  3. package/dist/Constants.d.ts.map +0 -1
  4. package/dist/Constants.js +0 -3
  5. package/dist/config/ConfigurationAggregator.d.ts +0 -10
  6. package/dist/config/ConfigurationAggregator.d.ts.map +0 -1
  7. package/dist/config/ConfigurationAggregator.js +0 -35
  8. package/dist/config/ConfigurationReceiver.d.ts +0 -25
  9. package/dist/config/ConfigurationReceiver.d.ts.map +0 -1
  10. package/dist/config/ConfigurationReceiver.js +0 -36
  11. package/dist/config/types.d.ts +0 -2
  12. package/dist/config/types.d.ts.map +0 -1
  13. package/dist/config/types.js +0 -1
  14. package/dist/model/MethodPublicInput.d.ts +0 -51
  15. package/dist/model/MethodPublicInput.d.ts.map +0 -1
  16. package/dist/model/MethodPublicInput.js +0 -11
  17. package/dist/model/Option.d.ts +0 -89
  18. package/dist/model/Option.d.ts.map +0 -1
  19. package/dist/model/Option.js +0 -86
  20. package/dist/model/Path.d.ts +0 -31
  21. package/dist/model/Path.d.ts.map +0 -1
  22. package/dist/model/Path.js +0 -44
  23. package/dist/model/StateTransition.d.ts +0 -85
  24. package/dist/model/StateTransition.d.ts.map +0 -1
  25. package/dist/model/StateTransition.js +0 -58
  26. package/dist/model/StateTransitionProvableBatch.d.ts +0 -56
  27. package/dist/model/StateTransitionProvableBatch.d.ts.map +0 -1
  28. package/dist/model/StateTransitionProvableBatch.js +0 -20
  29. package/dist/prover/block/BlockProver.d.ts +0 -199
  30. package/dist/prover/block/BlockProver.d.ts.map +0 -1
  31. package/dist/prover/block/BlockProver.js +0 -119
  32. package/dist/prover/block/BlockScopedModule.d.ts +0 -3
  33. package/dist/prover/block/BlockScopedModule.d.ts.map +0 -1
  34. package/dist/prover/block/BlockScopedModule.js +0 -6
  35. package/dist/prover/statetransition/StateTransitionProver.d.ts +0 -92
  36. package/dist/prover/statetransition/StateTransitionProver.d.ts.map +0 -1
  37. package/dist/prover/statetransition/StateTransitionProver.js +0 -127
  38. package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts +0 -16
  39. package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts.map +0 -1
  40. package/dist/prover/statetransition/StateTransitionWitnessProvider.js +0 -17
  41. package/dist/src/model/Option.d.ts +0 -158
  42. package/dist/src/model/Option.d.ts.map +0 -1
  43. package/dist/src/model/Option.js +0 -53
  44. package/dist/src/model/Path.d.ts +0 -35
  45. package/dist/src/model/Path.d.ts.map +0 -1
  46. package/dist/src/model/Path.js +0 -51
  47. package/dist/src/model/StateTransition.d.ts +0 -201
  48. package/dist/src/model/StateTransition.d.ts.map +0 -1
  49. package/dist/src/model/StateTransition.js +0 -43
  50. package/dist/src/utils/PrefixedHashList.d.ts +0 -15
  51. package/dist/src/utils/PrefixedHashList.d.ts.map +0 -1
  52. package/dist/src/utils/PrefixedHashList.js +0 -28
  53. package/dist/src/utils/ProvableHashList.d.ts +0 -30
  54. package/dist/src/utils/ProvableHashList.d.ts.map +0 -1
  55. package/dist/src/utils/ProvableHashList.js +0 -43
  56. package/dist/utils/PrefixedHashList.d.ts +0 -14
  57. package/dist/utils/PrefixedHashList.d.ts.map +0 -1
  58. package/dist/utils/PrefixedHashList.js +0 -12
  59. package/dist/utils/PrefixedProvableHashList.d.ts +0 -8
  60. package/dist/utils/PrefixedProvableHashList.d.ts.map +0 -1
  61. package/dist/utils/PrefixedProvableHashList.js +0 -12
  62. package/dist/utils/ProvableHashList.d.ts +0 -26
  63. package/dist/utils/ProvableHashList.d.ts.map +0 -1
  64. package/dist/utils/ProvableHashList.js +0 -35
  65. package/dist/utils/Utils.d.ts +0 -22
  66. package/dist/utils/Utils.d.ts.map +0 -1
  67. package/dist/utils/Utils.js +0 -41
  68. package/dist/utils/merkletree/MemoryMerkleTreeStorage.d.ts +0 -26
  69. package/dist/utils/merkletree/MemoryMerkleTreeStorage.d.ts.map +0 -1
  70. package/dist/utils/merkletree/MemoryMerkleTreeStorage.js +0 -79
  71. package/dist/utils/merkletree/RollupMerkleTree.d.ts +0 -143
  72. package/dist/utils/merkletree/RollupMerkleTree.d.ts.map +0 -1
  73. package/dist/utils/merkletree/RollupMerkleTree.js +0 -246
@@ -1,246 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- /* eslint-disable id-length */
11
- /* eslint-disable line-comment-position */
12
- /* eslint-disable no-inline-comments */
13
- /* eslint-disable @typescript-eslint/no-magic-numbers */
14
- import { Bool, Circuit, Field, Poseidon, Struct } from "snarkyjs";
15
- import { notInCircuit } from "../utils";
16
- // external API
17
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
18
- export { RollupMerkleTree, RollupMerkleWitness };
19
- // internal API
20
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
21
- export { maybeSwap };
22
- /**
23
- * The {@link BaseMerkleWitness} class defines a circuit-compatible base class
24
- * for [Merkle Witness'](https://computersciencewiki.org/index.php/Merkle_proof).
25
- */
26
- class RollupMerkleWitness extends Struct({
27
- path: Circuit.array(Field, 256 - 1),
28
- isLeft: Circuit.array(Bool, 256 - 1),
29
- }) {
30
- height() {
31
- return RollupMerkleWitness.height;
32
- }
33
- /**
34
- * Calculates a root depending on the leaf value.
35
- * @param leaf Value of the leaf node that belongs to this Witness.
36
- * @returns The calculated root.
37
- */
38
- calculateRoot(hash) {
39
- const n = this.height();
40
- for (let index = 1; index < n; ++index) {
41
- const isLeft = this.isLeft[index - 1];
42
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
43
- const [left, right] = maybeSwap(isLeft, hash, this.path[index - 1]);
44
- hash = Poseidon.hash([left, right]);
45
- }
46
- return hash;
47
- }
48
- /**
49
- * Calculates the index of the leaf node that belongs to this Witness.
50
- * @returns Index of the leaf.
51
- */
52
- calculateIndex() {
53
- let powerOfTwo = Field(1);
54
- let index = Field(0);
55
- const n = this.height();
56
- // eslint-disable-next-line no-underscore-dangle
57
- for (let index_ = 1; index_ < n; ++index_) {
58
- index = Circuit.if(this.isLeft[index_ - 1], index, index.add(powerOfTwo));
59
- powerOfTwo = powerOfTwo.mul(2);
60
- }
61
- return index;
62
- }
63
- }
64
- RollupMerkleWitness.height = 256;
65
- /**
66
- * A [Merkle Tree](https://en.wikipedia.org/wiki/Merkle_tree) is a binary tree in
67
- * which every leaf is the cryptography hash of a piece of data,
68
- * and every node is the hash of the concatenation of its two child nodes.
69
- *
70
- * A Merkle Tree allows developers to easily and securely verify
71
- * the integrity of large amounts of data.
72
- *
73
- * Take a look at our [documentation](https://docs.minaprotocol.com/en/zkapps)
74
- * on how to use Merkle Trees in combination with zkApps and
75
- * zero knowledge programming!
76
- *
77
- * Levels are indexed from leaves (level 0) to root (level N - 1).
78
- */
79
- class RollupMerkleTree {
80
- static get leafCount() {
81
- return 2n ** BigInt(RollupMerkleTree.height - 1);
82
- }
83
- constructor(store) {
84
- this.store = store;
85
- // eslint-disable-next-line @shopify/prefer-class-properties
86
- this.zeroes = [0n];
87
- for (let index = 1; index < RollupMerkleTree.height; index += 1) {
88
- const previousLevel = Field(this.zeroes[index - 1]);
89
- this.zeroes.push(Poseidon.hash([previousLevel, previousLevel]).toBigInt());
90
- }
91
- }
92
- /**
93
- * Returns a node which lives at a given index and level.
94
- * @param level Level of the node.
95
- * @param index Index of the node.
96
- * @returns The data of the node.
97
- */
98
- getNode(level, index) {
99
- return Field(this.store.getNode(index, level) ?? this.zeroes[level]);
100
- }
101
- /**
102
- * Returns the root of the [Merkle Tree](https://en.wikipedia.org/wiki/Merkle_tree).
103
- * @returns The root of the Merkle Tree.
104
- */
105
- getRoot() {
106
- return this.getNode(RollupMerkleTree.height - 1, 0n);
107
- }
108
- // eslint-disable-next-line no-warning-comments
109
- // TODO: this allows to set a node at an index larger than the size. OK?
110
- setNode(level, index, value) {
111
- this.store.setNode(index, level, value.toBigInt());
112
- }
113
- /**
114
- * TODO: if this is passed an index bigger than the max, it will set a couple
115
- * of out-of-bounds nodes but not affect the real Merkle root. OK?
116
- */
117
- /**
118
- * Sets the value of a leaf node at a given index to a given value.
119
- * @param index Position of the leaf node.
120
- * @param leaf New value.
121
- */
122
- setLeaf(index, leaf) {
123
- if (index >= this.leafCount) {
124
- index %= this.leafCount;
125
- }
126
- this.store.openTransaction();
127
- this.setNode(0, index, leaf);
128
- let currentIndex = index;
129
- for (let level = 1; level < RollupMerkleTree.height; level += 1) {
130
- currentIndex /= 2n;
131
- const left = this.getNode(level - 1, currentIndex * 2n);
132
- const right = this.getNode(level - 1, currentIndex * 2n + 1n);
133
- this.setNode(level, currentIndex, Poseidon.hash([left, right]));
134
- }
135
- this.store.commit();
136
- }
137
- /**
138
- * Returns the witness (also known as
139
- * [Merkle Proof or Merkle Witness](https://computersciencewiki.org/index.php/Merkle_proof))
140
- * for the leaf at the given index.
141
- * @param index Position of the leaf node.
142
- * @returns The witness that belongs to the leaf.
143
- */
144
- getWitness(index) {
145
- if (index >= this.leafCount) {
146
- index %= this.leafCount;
147
- }
148
- const path = [];
149
- const isLefts = [];
150
- for (let level = 0; level < RollupMerkleTree.height - 1; level += 1) {
151
- const isLeft = index % 2n === 0n;
152
- const sibling = this.getNode(level, isLeft ? index + 1n : index - 1n);
153
- isLefts.push(Bool(isLeft));
154
- path.push(sibling);
155
- index /= 2n;
156
- }
157
- return new RollupMerkleWitness({
158
- isLeft: isLefts,
159
- path,
160
- });
161
- }
162
- // eslint-disable-next-line no-warning-comments, max-len
163
- // TODO: should this take an optional offset? should it fail if the array is too long?
164
- /**
165
- * Fills all leaves of the tree.
166
- * @param leaves Values to fill the leaves with.
167
- */
168
- fill(leaves) {
169
- leaves.forEach((value, index) => {
170
- this.setLeaf(BigInt(index), value);
171
- });
172
- }
173
- /**
174
- * Returns the amount of leaf nodes.
175
- * @returns Amount of leaf nodes.
176
- */
177
- get leafCount() {
178
- return RollupMerkleTree.leafCount;
179
- }
180
- }
181
- RollupMerkleTree.height = 256;
182
- __decorate([
183
- notInCircuit(),
184
- __metadata("design:type", Function),
185
- __metadata("design:paramtypes", [Number, BigInt]),
186
- __metadata("design:returntype", Field)
187
- ], RollupMerkleTree.prototype, "getNode", null);
188
- __decorate([
189
- notInCircuit(),
190
- __metadata("design:type", Function),
191
- __metadata("design:paramtypes", []),
192
- __metadata("design:returntype", Field)
193
- ], RollupMerkleTree.prototype, "getRoot", null);
194
- __decorate([
195
- notInCircuit(),
196
- __metadata("design:type", Function),
197
- __metadata("design:paramtypes", [BigInt, Field]),
198
- __metadata("design:returntype", void 0)
199
- ], RollupMerkleTree.prototype, "setLeaf", null);
200
- __decorate([
201
- notInCircuit(),
202
- __metadata("design:type", Function),
203
- __metadata("design:paramtypes", [BigInt]),
204
- __metadata("design:returntype", RollupMerkleWitness)
205
- ], RollupMerkleTree.prototype, "getWitness", null);
206
- __decorate([
207
- notInCircuit(),
208
- __metadata("design:type", Function),
209
- __metadata("design:paramtypes", [Array]),
210
- __metadata("design:returntype", void 0)
211
- ], RollupMerkleTree.prototype, "fill", null);
212
- // eslint-disable-next-line @typescript-eslint/no-namespace
213
- export var MerkleTreeUtils;
214
- (function (MerkleTreeUtils) {
215
- function normalizeKey(key) {
216
- // if(NJORD_MERKLE_TREE_HEIGHT < 256){
217
- // return fieldMod(key, Field(RollupMerkleTree.leafCount).toConstant())
218
- // eslint-disable-next-line max-len
219
- // // return modPower2(key, RollupMerkleTree.height - 1) //TODO Fix modPower2
220
- // }else{
221
- return key;
222
- // }
223
- }
224
- MerkleTreeUtils.normalizeKey = normalizeKey;
225
- function checkMembership(witness, root, key, value) {
226
- const root2 = witness.calculateRoot(value);
227
- const key2 = witness.calculateIndex();
228
- key.assertEquals(key2, "Keys of MerkleWitness does not match");
229
- return root.equals(root2);
230
- }
231
- MerkleTreeUtils.checkMembership = checkMembership;
232
- function computeRoot(witness, value) {
233
- return witness.calculateRoot(value);
234
- }
235
- MerkleTreeUtils.computeRoot = computeRoot;
236
- })(MerkleTreeUtils || (MerkleTreeUtils = {}));
237
- /**
238
- * More efficient version of `maybeSwapBad` which
239
- * reuses an intermediate variable
240
- */
241
- function maybeSwap(b, x, y) {
242
- const m = b.toField().mul(x.sub(y)); // b*(x - y)
243
- const x1 = y.add(m); // y + b*(x - y)
244
- const y2 = x.sub(m); // x - b*(x - y) = x + b*(y - x)
245
- return [x1, y2];
246
- }