@proto-kit/protocol 0.1.1-develop.165 → 0.1.1-develop.185

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 (100) hide show
  1. package/dist/model/MethodPublicOutput.d.ts +6 -7
  2. package/dist/model/MethodPublicOutput.d.ts.map +1 -1
  3. package/dist/model/Option.d.ts +11 -7
  4. package/dist/model/Option.d.ts.map +1 -1
  5. package/dist/model/Option.js +10 -0
  6. package/dist/model/StateTransition.d.ts +11 -0
  7. package/dist/model/StateTransition.d.ts.map +1 -1
  8. package/dist/model/StateTransition.js +7 -0
  9. package/dist/model/StateTransitionProvableBatch.d.ts +4 -4
  10. package/dist/model/StateTransitionProvableBatch.d.ts.map +1 -1
  11. package/dist/model/StateTransitionProvableBatch.js +6 -6
  12. package/dist/model/network/NetworkState.d.ts.map +1 -1
  13. package/dist/model/network/NetworkState.js +1 -3
  14. package/dist/model/transaction/RuntimeTransaction.d.ts +9 -1
  15. package/dist/model/transaction/RuntimeTransaction.d.ts.map +1 -1
  16. package/dist/model/transaction/RuntimeTransaction.js +5 -2
  17. package/dist/protocol/Protocol.d.ts +1 -1
  18. package/dist/protocol/Protocol.d.ts.map +1 -1
  19. package/dist/protocol/ProtocolModule.d.ts +1 -1
  20. package/dist/protocol/ProtocolModule.d.ts.map +1 -1
  21. package/dist/protocol/ProtocolModule.js +3 -3
  22. package/dist/prover/block/BlockProvable.d.ts +1 -1
  23. package/dist/prover/block/BlockProvable.d.ts.map +1 -1
  24. package/dist/prover/block/BlockProver.d.ts.map +1 -1
  25. package/dist/prover/statetransition/StateTransitionProver.d.ts +2 -2
  26. package/dist/prover/statetransition/StateTransitionProver.d.ts.map +1 -1
  27. package/dist/prover/statetransition/StateTransitionProver.js +5 -4
  28. package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts +1 -1
  29. package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts.map +1 -1
  30. package/dist/prover/statetransition/StateTransitionWitnessProvider.js +1 -1
  31. package/dist/prover/statetransition/StateTransitionWitnessProviderReference.d.ts.map +1 -1
  32. package/dist/utils/merkletree/InMemoryMerkleTreeStorage.d.ts.map +1 -1
  33. package/dist/utils/merkletree/InMemoryMerkleTreeStorage.js +3 -3
  34. package/dist/utils/merkletree/RollupMerkleTree.d.ts +6 -6
  35. package/dist/utils/merkletree/RollupMerkleTree.d.ts.map +1 -1
  36. package/dist/utils/merkletree/RollupMerkleTree.js +4 -4
  37. package/dist/utils/{Utils.d.ts → utils.d.ts} +2 -5
  38. package/dist/utils/{Utils.d.ts.map → utils.d.ts.map} +1 -1
  39. package/dist/utils/utils.js +51 -0
  40. package/package.json +4 -4
  41. package/src/model/Option.ts +13 -0
  42. package/src/model/StateTransition.ts +8 -0
  43. package/src/model/StateTransitionProvableBatch.ts +8 -7
  44. package/src/model/network/NetworkState.ts +1 -3
  45. package/src/model/transaction/RuntimeTransaction.ts +5 -1
  46. package/src/protocol/Protocol.ts +1 -1
  47. package/src/protocol/ProtocolModule.ts +4 -5
  48. package/src/prover/block/BlockProvable.ts +2 -2
  49. package/src/prover/block/BlockProver.ts +6 -1
  50. package/src/prover/statetransition/StateTransitionProver.ts +6 -9
  51. package/src/prover/statetransition/StateTransitionWitnessProvider.ts +1 -1
  52. package/src/prover/statetransition/StateTransitionWitnessProviderReference.ts +2 -2
  53. package/src/utils/merkletree/InMemoryMerkleTreeStorage.ts +4 -4
  54. package/src/utils/merkletree/MerkleTreeStore.ts +1 -1
  55. package/src/utils/merkletree/RollupMerkleTree.ts +9 -4
  56. package/src/utils/utils.ts +29 -45
  57. package/test/utils.test.ts +30 -0
  58. package/dist/config/ConfigurableModule.d.ts +0 -18
  59. package/dist/config/ConfigurableModule.d.ts.map +0 -1
  60. package/dist/config/ConfigurableModule.js +0 -20
  61. package/dist/config/ConfigurationAggregator.d.ts +0 -10
  62. package/dist/config/ConfigurationAggregator.d.ts.map +0 -1
  63. package/dist/config/ConfigurationAggregator.js +0 -35
  64. package/dist/config/ConfigurationReceiver.d.ts +0 -25
  65. package/dist/config/ConfigurationReceiver.d.ts.map +0 -1
  66. package/dist/config/ConfigurationReceiver.js +0 -36
  67. package/dist/config/ModuleContainer.d.ts +0 -44
  68. package/dist/config/ModuleContainer.d.ts.map +0 -1
  69. package/dist/config/ModuleContainer.js +0 -89
  70. package/dist/config/types.d.ts +0 -2
  71. package/dist/config/types.d.ts.map +0 -1
  72. package/dist/config/types.js +0 -1
  73. package/dist/model/MethodPublicInput.d.ts +0 -51
  74. package/dist/model/MethodPublicInput.d.ts.map +0 -1
  75. package/dist/model/MethodPublicInput.js +0 -11
  76. package/dist/prover/block/BlockScopedModule.d.ts +0 -3
  77. package/dist/prover/block/BlockScopedModule.d.ts.map +0 -1
  78. package/dist/prover/block/BlockScopedModule.js +0 -6
  79. package/dist/src/model/Option.d.ts +0 -158
  80. package/dist/src/model/Option.d.ts.map +0 -1
  81. package/dist/src/model/Option.js +0 -53
  82. package/dist/src/model/Path.d.ts +0 -35
  83. package/dist/src/model/Path.d.ts.map +0 -1
  84. package/dist/src/model/Path.js +0 -51
  85. package/dist/src/model/StateTransition.d.ts +0 -201
  86. package/dist/src/model/StateTransition.d.ts.map +0 -1
  87. package/dist/src/model/StateTransition.js +0 -43
  88. package/dist/src/utils/PrefixedHashList.d.ts +0 -15
  89. package/dist/src/utils/PrefixedHashList.d.ts.map +0 -1
  90. package/dist/src/utils/PrefixedHashList.js +0 -28
  91. package/dist/src/utils/ProvableHashList.d.ts +0 -30
  92. package/dist/src/utils/ProvableHashList.d.ts.map +0 -1
  93. package/dist/src/utils/ProvableHashList.js +0 -43
  94. package/dist/utils/PrefixedHashList.d.ts +0 -14
  95. package/dist/utils/PrefixedHashList.d.ts.map +0 -1
  96. package/dist/utils/PrefixedHashList.js +0 -12
  97. package/dist/utils/Utils.js +0 -64
  98. package/dist/utils/merkletree/MemoryMerkleTreeStorage.d.ts +0 -26
  99. package/dist/utils/merkletree/MemoryMerkleTreeStorage.d.ts.map +0 -1
  100. package/dist/utils/merkletree/MemoryMerkleTreeStorage.js +0 -79
@@ -1,201 +0,0 @@
1
- import { Field } from "snarkyjs";
2
- import { Option, ProvableOptionStruct } from "./Option.js";
3
- /**
4
- * Provable representation of a State Transition, used to
5
- * normalize state transitions of various value types for
6
- * the state transition circuit.
7
- */
8
- export declare function ProvableStateTransition(value: {
9
- path: Field;
10
- from: ProvableOptionStruct;
11
- to: ProvableOptionStruct;
12
- }): {
13
- path: {
14
- neg: {};
15
- inv: {};
16
- add: {};
17
- sub: {};
18
- mul: {};
19
- div: {};
20
- square: {};
21
- sqrt: {};
22
- toString: {};
23
- toBigInt: {};
24
- toJSON: {};
25
- sizeInFields: {};
26
- toFields: {};
27
- lessThan: {};
28
- lessThanOrEqual: {};
29
- greaterThan: {};
30
- greaterThanOrEqual: {};
31
- assertLessThan: {};
32
- assertLessThanOrEqual: {};
33
- assertGreaterThan: {};
34
- assertGreaterThanOrEqual: {};
35
- lt: {};
36
- lte: {};
37
- gt: {};
38
- gte: {};
39
- assertLt: {};
40
- assertLte: {};
41
- assertGt: {};
42
- assertGte: {};
43
- assertEquals: {};
44
- assertBool: {};
45
- assertBoolean: {};
46
- isZero: {};
47
- toBits: {};
48
- equals: {};
49
- seal: {};
50
- rangeCheckHelper: {};
51
- isConstant: {};
52
- toConstant: {};
53
- fromFields: {};
54
- };
55
- from: {
56
- isSome: {
57
- toField: {};
58
- not: {};
59
- and: {};
60
- or: {};
61
- assertEquals: {};
62
- assertTrue: {};
63
- assertFalse: {};
64
- equals: {};
65
- sizeInFields: {};
66
- toFields: {};
67
- toString: {};
68
- toJSON: {};
69
- toBoolean: {};
70
- };
71
- value: {
72
- neg: {};
73
- inv: {};
74
- add: {};
75
- sub: {};
76
- mul: {};
77
- div: {};
78
- square: {};
79
- sqrt: {};
80
- toString: {};
81
- toBigInt: {};
82
- toJSON: {};
83
- sizeInFields: {};
84
- toFields: {};
85
- lessThan: {};
86
- lessThanOrEqual: {};
87
- greaterThan: {};
88
- greaterThanOrEqual: {};
89
- assertLessThan: {};
90
- assertLessThanOrEqual: {};
91
- assertGreaterThan: {};
92
- assertGreaterThanOrEqual: {};
93
- lt: {};
94
- lte: {};
95
- gt: {};
96
- gte: {};
97
- assertLt: {};
98
- assertLte: {};
99
- assertGt: {};
100
- assertGte: {};
101
- assertEquals: {};
102
- assertBool: {};
103
- assertBoolean: {};
104
- isZero: {};
105
- toBits: {};
106
- equals: {};
107
- seal: {};
108
- rangeCheckHelper: {};
109
- isConstant: {};
110
- toConstant: {};
111
- fromFields: {};
112
- };
113
- };
114
- to: {
115
- isSome: {
116
- toField: {};
117
- not: {};
118
- and: {};
119
- or: {};
120
- assertEquals: {};
121
- assertTrue: {};
122
- assertFalse: {};
123
- equals: {};
124
- sizeInFields: {};
125
- toFields: {};
126
- toString: {};
127
- toJSON: {};
128
- toBoolean: {};
129
- };
130
- value: {
131
- neg: {};
132
- inv: {};
133
- add: {};
134
- sub: {};
135
- mul: {};
136
- div: {};
137
- square: {};
138
- sqrt: {};
139
- toString: {};
140
- toBigInt: {};
141
- toJSON: {};
142
- sizeInFields: {};
143
- toFields: {};
144
- lessThan: {};
145
- lessThanOrEqual: {};
146
- greaterThan: {};
147
- greaterThanOrEqual: {};
148
- assertLessThan: {};
149
- assertLessThanOrEqual: {};
150
- assertGreaterThan: {};
151
- assertGreaterThanOrEqual: {};
152
- lt: {};
153
- lte: {};
154
- gt: {};
155
- gte: {};
156
- assertLt: {};
157
- assertLte: {};
158
- assertGt: {};
159
- assertGte: {};
160
- assertEquals: {};
161
- assertBool: {};
162
- assertBoolean: {};
163
- isZero: {};
164
- toBits: {};
165
- equals: {};
166
- seal: {};
167
- rangeCheckHelper: {};
168
- isConstant: {};
169
- toConstant: {};
170
- fromFields: {};
171
- };
172
- };
173
- };
174
- export type ProvableStateTransitionStruct = ReturnType<
175
- typeof ProvableStateTransition
176
- >;
177
- /**
178
- * Generic state transition that constraints the current method circuit
179
- * to external state, by providing a state anchor.
180
- */
181
- export declare class StateTransition<Value> {
182
- path: Field;
183
- from: Option<Field> | Option<Value>;
184
- to: Option<Field> | Option<Value>;
185
- toValue?: Value | undefined;
186
- static from<Value>(path: Field, from: Option<Value>): StateTransition<Value>;
187
- static fromTo<Value>(
188
- path: Field,
189
- from: Option<Field> | Option<Value>,
190
- to: Option<Field> | Option<Value>,
191
- toValue: Value
192
- ): StateTransition<Value>;
193
- constructor(
194
- path: Field,
195
- from: Option<Field> | Option<Value>,
196
- to: Option<Field> | Option<Value>,
197
- toValue?: Value | undefined
198
- );
199
- toProvable(): ProvableStateTransitionStruct;
200
- }
201
- //# sourceMappingURL=StateTransition.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StateTransition.d.ts","sourceRoot":"","sources":["../../../src/model/StateTransition.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,EAAU,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE3D;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,oBAAoB,CAAC;IAAC,EAAE,EAAE,oBAAoB,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAInH;AAED,MAAM,MAAM,6BAA6B,GAAG,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAEvF;;;GAGG;AACH,qBAAa,eAAe,CAAC,KAAK;IAYvB,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;IACnC,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;IACjC,OAAO,CAAC;WAdH,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC;WAK5C,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,KAAK;gBAMtH,IAAI,EAAE,KAAK,EACX,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,EACnC,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,EACjC,OAAO,CAAC,mBAAO;IAGjB,UAAU,IAAI,6BAA6B;CAOnD"}
@@ -1,43 +0,0 @@
1
- /* eslint-disable import/no-unused-modules */
2
- /* eslint-disable max-classes-per-file */
3
- /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
4
- /* eslint-disable new-cap */
5
- /* eslint-disable import/prefer-default-export */
6
- import { Struct } from "snarkyjs";
7
- import { Option } from "./Option.js";
8
- /**
9
- * Provable representation of a State Transition, used to
10
- * normalize state transitions of various value types for
11
- * the state transition circuit.
12
- */
13
- export function ProvableStateTransition(value) {
14
- class ProvableStateTransitionStruct extends Struct(value) {}
15
- return new ProvableStateTransitionStruct(value);
16
- }
17
- /**
18
- * Generic state transition that constraints the current method circuit
19
- * to external state, by providing a state anchor.
20
- */
21
- export class StateTransition {
22
- static from(path, from) {
23
- return new StateTransition(path, from, Option.none());
24
- }
25
- // eslint-disable-next-line max-params
26
- static fromTo(path, from, to, toValue) {
27
- return new StateTransition(path, from, to, toValue);
28
- }
29
- // eslint-disable-next-line max-params
30
- constructor(path, from, to, toValue) {
31
- this.path = path;
32
- this.from = from;
33
- this.to = to;
34
- this.toValue = toValue;
35
- }
36
- toProvable() {
37
- return ProvableStateTransition({
38
- path: this.path,
39
- from: this.from.toProvable(),
40
- to: this.to.toProvable(),
41
- });
42
- }
43
- }
@@ -1,15 +0,0 @@
1
- import { Field, FlexibleProvablePure } from "snarkyjs";
2
- import { ProvableHashList } from "./ProvableHashList.js";
3
- export declare class PrefixedProvableHashList<
4
- Value
5
- > extends ProvableHashList<Value> {
6
- private readonly prefix;
7
- constructor(
8
- valueType: FlexibleProvablePure<Value>,
9
- prefix: string,
10
- internalCommitment?: Field
11
- );
12
- protected hash(e: Field[]): Field;
13
- }
14
- export declare function prefixToField(prefix: string): Field;
15
- //# sourceMappingURL=PrefixedHashList.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PrefixedHashList.d.ts","sourceRoot":"","sources":["../../../src/utils/PrefixedHashList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAY,MAAM,UAAU,CAAC;AAEjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,qBAAa,wBAAwB,CAAC,KAAK,CAAE,SAAQ,gBAAgB,CAAC,KAAK,CAAC;IAE1E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;gBAG7B,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC,EACtC,MAAM,EAAE,MAAM,EACd,kBAAkB,GAAE,KAAgB;IAMtC,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,KAAK;CAIlC;AAGD,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,SAmB3C"}
@@ -1,28 +0,0 @@
1
- import { Field, Poseidon } from "snarkyjs";
2
- import { TextEncoder } from "node:util";
3
- import { ProvableHashList } from "./ProvableHashList.js";
4
- export class PrefixedProvableHashList extends ProvableHashList {
5
- constructor(valueType, prefix, internalCommitment = Field(0)) {
6
- super(valueType, internalCommitment);
7
- this.prefix = prefixToField(prefix);
8
- }
9
- hash(e) {
10
- return Poseidon.hash([this.prefix, ...e]);
11
- }
12
- }
13
- export function prefixToField(prefix) {
14
- const fieldSize = Field.sizeInBytes();
15
- if (prefix.length >= fieldSize) {
16
- throw new Error("prefix too long");
17
- }
18
- const encoder = new TextEncoder();
19
- function stringToBytes(s) {
20
- return Array.from(encoder.encode(s));
21
- }
22
- const stringBytes = stringToBytes(prefix);
23
- const padding = Array.from({ length: fieldSize - stringBytes.length }).fill(
24
- 0
25
- );
26
- const data = stringBytes.concat(padding);
27
- return Field.fromBytes(data);
28
- }
@@ -1,30 +0,0 @@
1
- import { type Bool, Field } from "snarkyjs";
2
- import { FlexibleProvablePure } from "snarkyjs";
3
- /**
4
- * Utilities for creating a hash list from a given value type.
5
- */
6
- export declare abstract class ProvableHashList<Value> {
7
- private readonly valueType;
8
- commitment: Field;
9
- constructor(valueType: FlexibleProvablePure<Value>, commitment?: Field);
10
- protected abstract hash(e: Field[]): Field;
11
- /**
12
- * Converts the provided value to Field[] and appends it to
13
- * the current hashlist.
14
- *
15
- * @param value - Value to be appended to the hash list
16
- * @returns Current hash list.
17
- */
18
- push(value: Value): this;
19
- remove(preimage: Field, value: Value): Bool;
20
- /**
21
- * @returns Traling hash of the current hashlist.
22
- */
23
- toField(): Field;
24
- }
25
- export declare class DefaultProvableHashList<
26
- Value
27
- > extends ProvableHashList<Value> {
28
- hash(e: Field[]): Field;
29
- }
30
- //# sourceMappingURL=ProvableHashList.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ProvableHashList.d.ts","sourceRoot":"","sources":["../../../src/utils/ProvableHashList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAW,KAAK,EAAY,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGhD;;GAEG;AACH,8BAAsB,gBAAgB,CAAC,KAAK;IAGxC,OAAO,CAAC,QAAQ,CAAC,SAAS;IACnB,UAAU,EAAE,KAAK;gBADP,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC,EAChD,UAAU,GAAE,KAAgB;IAIrC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,KAAK;IAE1C;;;;;;OAMG;IACI,IAAI,CAAC,KAAK,EAAE,KAAK;IAKjB,MAAM,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI;IAMlD;;OAEG;IACI,OAAO;CAIf;AAED,qBAAa,uBAAuB,CAAC,KAAK,CAAE,SAAQ,gBAAgB,CAAC,KAAK,CAAC;IAElE,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,KAAK;CAI/B"}
@@ -1,43 +0,0 @@
1
- import { Circuit, Field, Poseidon } from "snarkyjs";
2
- /**
3
- * Utilities for creating a hash list from a given value type.
4
- */
5
- export class ProvableHashList {
6
- constructor(valueType, commitment = Field(0)) {
7
- this.valueType = valueType;
8
- this.commitment = commitment;
9
- }
10
- /**
11
- * Converts the provided value to Field[] and appends it to
12
- * the current hashlist.
13
- *
14
- * @param value - Value to be appended to the hash list
15
- * @returns Current hash list.
16
- */
17
- push(value) {
18
- this.commitment = this.hash([
19
- this.commitment,
20
- ...this.valueType.toFields(value),
21
- ]);
22
- return this;
23
- }
24
- remove(preimage, value) {
25
- const success = this.hash([
26
- preimage,
27
- ...this.valueType.toFields(value),
28
- ]).equals(this.commitment);
29
- this.commitment = Circuit.if(success, preimage, this.commitment);
30
- return success;
31
- }
32
- /**
33
- * @returns Traling hash of the current hashlist.
34
- */
35
- toField() {
36
- return this.commitment;
37
- }
38
- }
39
- export class DefaultProvableHashList extends ProvableHashList {
40
- hash(e) {
41
- return Poseidon.hash(e);
42
- }
43
- }
@@ -1,14 +0,0 @@
1
- import { Field, FlexibleProvablePure } from "snarkyjs";
2
- import { ProvableHashList } from "./ProvableHashList.js";
3
- export declare class PrefixedProvableHashList<
4
- Value
5
- > extends ProvableHashList<Value> {
6
- private readonly prefix;
7
- constructor(
8
- valueType: FlexibleProvablePure<Value>,
9
- prefix: string,
10
- internalCommitment?: Field
11
- );
12
- protected hash(elements: Field[]): Field;
13
- }
14
- //# sourceMappingURL=PrefixedHashList.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PrefixedHashList.d.ts","sourceRoot":"","sources":["../../src/utils/PrefixedHashList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAY,MAAM,UAAU,CAAC;AAEjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,qBAAa,wBAAwB,CAAC,KAAK,CAAE,SAAQ,gBAAgB,CAAC,KAAK,CAAC;IAC1E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;gBAG7B,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC,EACtC,MAAM,EAAE,MAAM,EACd,kBAAkB,GAAE,KAAgB;IAMtC,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,KAAK;CAGzC"}
@@ -1,12 +0,0 @@
1
- import { Field, Poseidon } from "snarkyjs";
2
- import { ProvableHashList } from "./ProvableHashList.js";
3
- import { stringToField } from "./Utils";
4
- export class PrefixedProvableHashList extends ProvableHashList {
5
- constructor(valueType, prefix, internalCommitment = Field(0)) {
6
- super(valueType, internalCommitment);
7
- this.prefix = stringToField(prefix);
8
- }
9
- hash(elements) {
10
- return Poseidon.hash([this.prefix, ...elements]);
11
- }
12
- }
@@ -1,64 +0,0 @@
1
- // eslint-disable-next-line max-len
2
- /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/ban-types, @typescript-eslint/no-unsafe-return,@typescript-eslint/no-empty-function */
3
- import { Circuit, Field, Poseidon } from "snarkyjs";
4
- export function notInCircuit() {
5
- return function ReplacedFunction(target, propertyKey, descriptor) {
6
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
7
- const childFunction = descriptor.value;
8
- descriptor.value = function value(...args) {
9
- if (Circuit.inCheckedComputation() || Circuit.inProver()) {
10
- throw new Error(`Method ${propertyKey.toString()} is supposed to be only called outside of the circuit`);
11
- }
12
- // eslint-disable-next-line max-len
13
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
14
- return childFunction.apply(this, args);
15
- };
16
- return descriptor;
17
- };
18
- }
19
- export function stringToField(value, throwOnOverflow = false) {
20
- const fieldSize = Field.sizeInBytes();
21
- // eslint-disable-next-line putout/putout
22
- const encoder = new TextEncoder();
23
- const stringBytes = Array.from(encoder.encode(value));
24
- const padding = Array.from({
25
- length: fieldSize - stringBytes.length,
26
- }).fill(0);
27
- const data = stringBytes.concat(padding);
28
- if (data.length > fieldSize) {
29
- if (throwOnOverflow) {
30
- throw new Error("Trying to encode a stringt that is larger than 256 bits");
31
- }
32
- // Hash the result Field[] to reduce it to
33
- const chunks = data.reduce((a, b, index) => {
34
- const arrayIndex = index / fieldSize;
35
- if (a.length <= arrayIndex) {
36
- a.push([]);
37
- }
38
- a[arrayIndex].push(b);
39
- return a;
40
- }, []);
41
- return Poseidon.hash(chunks.map((x) => Field.fromBytes(x)));
42
- }
43
- return Field.fromBytes(data);
44
- }
45
- /**
46
- * Note: This only works for strings that have been encoded using the `throwOnOverflow` set to true
47
- */
48
- export function fieldToString(value) {
49
- if (typeof value === "bigint") {
50
- value = Field(value);
51
- }
52
- let bytes = Field.toBytes(value);
53
- // Find start of padded zeroes in order to remove them.
54
- const zeroesStart = bytes.length -
55
- bytes
56
- .slice()
57
- .reverse()
58
- .findIndex((element) => element !== 0);
59
- bytes = bytes.slice(0, zeroesStart);
60
- // eslint-disable-next-line putout/putout
61
- const decoder = new TextDecoder();
62
- return decoder.decode(new Uint8Array(bytes));
63
- }
64
- export function noop() { }
@@ -1,26 +0,0 @@
1
- import { type MerkleTreeStore, type SyncMerkleTreeStore } from "./RollupMerkleTree.js";
2
- export declare class NoOpMerkleTreeStorage implements SyncMerkleTreeStore {
3
- parent: MerkleTreeStore;
4
- openTransaction(): void;
5
- commit(): void;
6
- getNode(): bigint | undefined;
7
- setNode(): void;
8
- virtualize(): MerkleTreeStore;
9
- getNodeAsync(): Promise<bigint | undefined>;
10
- setNodeAsync(): Promise<void>;
11
- }
12
- export declare class MemoryMerkleTreeStorage implements SyncMerkleTreeStore {
13
- private readonly nodes;
14
- private readonly cache;
15
- parent: SyncMerkleTreeStore;
16
- constructor(parent?: SyncMerkleTreeStore | undefined);
17
- openTransaction(): void;
18
- commit(): void;
19
- getNode(key: bigint, level: number): bigint | undefined;
20
- setNode(key: bigint, level: number, value: bigint): void;
21
- virtualize(): MerkleTreeStore;
22
- getNodeAsync(key: bigint, level: number): Promise<bigint | undefined>;
23
- setNodeAsync(key: bigint, level: number, value: bigint): Promise<void>;
24
- cacheFromParent(index: bigint): Promise<void>;
25
- }
26
- //# sourceMappingURL=MemoryMerkleTreeStorage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MemoryMerkleTreeStorage.d.ts","sourceRoot":"","sources":["../../../src/utils/merkletree/MemoryMerkleTreeStorage.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,mBAAmB,EACzB,MAAM,uBAAuB,CAAC;AAE/B,qBAAa,qBAAsB,YAAW,mBAAmB;IACxD,MAAM,EAAE,eAAe,CAAQ;IAE/B,eAAe,IAAI,IAAI;IAIvB,MAAM,IAAI,IAAI;IAId,OAAO,IAAI,MAAM,GAAG,SAAS;IAI7B,OAAO,IAAI,IAAI;IAIf,UAAU,IAAI,eAAe;IAIvB,YAAY,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAI3C,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CAG3C;AAED,qBAAa,uBAAwB,YAAW,mBAAmB;IACjE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAGf;IAEP,OAAO,CAAC,QAAQ,CAAC,KAAK,CAGf;IAEA,MAAM,EAAE,mBAAmB,CAAC;gBAEhB,MAAM,GAAE,mBAAmB,GAAG,SAAqB;IAI/D,eAAe,IAAI,IAAI;IAIvB,MAAM,IAAI,IAAI;IAId,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAQvD,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAIxD,UAAU,IAAI,eAAe;IAIvB,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;IAKH,eAAe,CAAC,KAAK,EAAE,MAAM;CAoB3C"}
@@ -1,79 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-magic-numbers */
2
- import { noop } from "../utils";
3
- import { RollupMerkleTree, } from "./RollupMerkleTree.js";
4
- export class NoOpMerkleTreeStorage {
5
- constructor() {
6
- this.parent = this;
7
- }
8
- openTransaction() {
9
- noop();
10
- }
11
- commit() {
12
- noop();
13
- }
14
- getNode() {
15
- return undefined;
16
- }
17
- setNode() {
18
- noop();
19
- }
20
- virtualize() {
21
- return this;
22
- }
23
- async getNodeAsync() {
24
- return undefined;
25
- }
26
- async setNodeAsync() {
27
- return undefined;
28
- }
29
- }
30
- export class MemoryMerkleTreeStorage {
31
- constructor(parent = undefined) {
32
- this.nodes = {};
33
- this.cache = {};
34
- this.parent = parent ?? new NoOpMerkleTreeStorage();
35
- }
36
- openTransaction() {
37
- noop();
38
- }
39
- commit() {
40
- noop();
41
- }
42
- getNode(key, level) {
43
- return (this.nodes[level]?.[key.toString()] ??
44
- this.cache[level]?.[key.toString()] ??
45
- this.parent.getNode(key, level));
46
- }
47
- setNode(key, level, value) {
48
- var _a;
49
- ((_a = this.nodes)[level] ?? (_a[level] = {}))[key.toString()] = value;
50
- }
51
- virtualize() {
52
- return new MemoryMerkleTreeStorage(this);
53
- }
54
- async getNodeAsync(key, level) {
55
- return this.getNode(key, level);
56
- }
57
- async setNodeAsync(key, level, value) {
58
- this.setNode(key, level, value);
59
- return undefined;
60
- }
61
- async cacheFromParent(index) {
62
- var _a;
63
- // Algo from RollupMerkleTree.getWitness()
64
- const { leafCount, height } = RollupMerkleTree;
65
- if (index >= leafCount) {
66
- index %= leafCount;
67
- }
68
- for (let level = 0; level < height - 1; level++) {
69
- const isLeft = index % 2n === 0n;
70
- const key = isLeft ? index + 1n : index - 1n;
71
- // eslint-disable-next-line no-await-in-loop
72
- const value = await this.parent.getNodeAsync(key, level);
73
- if (value !== undefined) {
74
- ((_a = this.nodes)[level] ?? (_a[level] = {}))[key.toString()] = value;
75
- }
76
- index /= 2n;
77
- }
78
- }
79
- }