@proto-kit/common 0.1.1-develop.153

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 (112) hide show
  1. package/LICENSE.md +201 -0
  2. package/dist/Constants.d.ts +4 -0
  3. package/dist/Constants.d.ts.map +1 -0
  4. package/dist/Constants.js +3 -0
  5. package/dist/config/ConfigurableModule.d.ts +21 -0
  6. package/dist/config/ConfigurableModule.d.ts.map +1 -0
  7. package/dist/config/ConfigurableModule.js +19 -0
  8. package/dist/config/ConfigurationAggregator.d.ts +10 -0
  9. package/dist/config/ConfigurationAggregator.d.ts.map +1 -0
  10. package/dist/config/ConfigurationAggregator.js +35 -0
  11. package/dist/config/ConfigurationReceiver.d.ts +25 -0
  12. package/dist/config/ConfigurationReceiver.d.ts.map +1 -0
  13. package/dist/config/ConfigurationReceiver.js +36 -0
  14. package/dist/config/ModuleContainer.d.ts +103 -0
  15. package/dist/config/ModuleContainer.d.ts.map +1 -0
  16. package/dist/config/ModuleContainer.js +163 -0
  17. package/dist/config/types.d.ts +2 -0
  18. package/dist/config/types.d.ts.map +1 -0
  19. package/dist/config/types.js +1 -0
  20. package/dist/index.d.ts +9 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +9 -0
  23. package/dist/model/MethodPublicInput.d.ts +51 -0
  24. package/dist/model/MethodPublicInput.d.ts.map +1 -0
  25. package/dist/model/MethodPublicInput.js +11 -0
  26. package/dist/model/Option.d.ts +89 -0
  27. package/dist/model/Option.d.ts.map +1 -0
  28. package/dist/model/Option.js +86 -0
  29. package/dist/model/Path.d.ts +31 -0
  30. package/dist/model/Path.d.ts.map +1 -0
  31. package/dist/model/Path.js +44 -0
  32. package/dist/model/StateTransition.d.ts +85 -0
  33. package/dist/model/StateTransition.d.ts.map +1 -0
  34. package/dist/model/StateTransition.js +58 -0
  35. package/dist/model/StateTransitionProvableBatch.d.ts +56 -0
  36. package/dist/model/StateTransitionProvableBatch.d.ts.map +1 -0
  37. package/dist/model/StateTransitionProvableBatch.js +20 -0
  38. package/dist/prover/block/BlockProver.d.ts +199 -0
  39. package/dist/prover/block/BlockProver.d.ts.map +1 -0
  40. package/dist/prover/block/BlockProver.js +119 -0
  41. package/dist/prover/block/BlockScopedModule.d.ts +3 -0
  42. package/dist/prover/block/BlockScopedModule.d.ts.map +1 -0
  43. package/dist/prover/block/BlockScopedModule.js +6 -0
  44. package/dist/prover/statetransition/StateTransitionProver.d.ts +92 -0
  45. package/dist/prover/statetransition/StateTransitionProver.d.ts.map +1 -0
  46. package/dist/prover/statetransition/StateTransitionProver.js +127 -0
  47. package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts +16 -0
  48. package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts.map +1 -0
  49. package/dist/prover/statetransition/StateTransitionWitnessProvider.js +17 -0
  50. package/dist/src/model/Option.d.ts +158 -0
  51. package/dist/src/model/Option.d.ts.map +1 -0
  52. package/dist/src/model/Option.js +53 -0
  53. package/dist/src/model/Path.d.ts +35 -0
  54. package/dist/src/model/Path.d.ts.map +1 -0
  55. package/dist/src/model/Path.js +51 -0
  56. package/dist/src/model/StateTransition.d.ts +201 -0
  57. package/dist/src/model/StateTransition.d.ts.map +1 -0
  58. package/dist/src/model/StateTransition.js +43 -0
  59. package/dist/src/utils/PrefixedHashList.d.ts +15 -0
  60. package/dist/src/utils/PrefixedHashList.d.ts.map +1 -0
  61. package/dist/src/utils/PrefixedHashList.js +28 -0
  62. package/dist/src/utils/ProvableHashList.d.ts +30 -0
  63. package/dist/src/utils/ProvableHashList.d.ts.map +1 -0
  64. package/dist/src/utils/ProvableHashList.js +43 -0
  65. package/dist/types.d.ts +11 -0
  66. package/dist/types.d.ts.map +1 -0
  67. package/dist/types.js +1 -0
  68. package/dist/utils/PrefixedHashList.d.ts +14 -0
  69. package/dist/utils/PrefixedHashList.d.ts.map +1 -0
  70. package/dist/utils/PrefixedHashList.js +12 -0
  71. package/dist/utils/PrefixedProvableHashList.d.ts +8 -0
  72. package/dist/utils/PrefixedProvableHashList.d.ts.map +1 -0
  73. package/dist/utils/PrefixedProvableHashList.js +12 -0
  74. package/dist/utils/ProvableHashList.d.ts +26 -0
  75. package/dist/utils/ProvableHashList.d.ts.map +1 -0
  76. package/dist/utils/ProvableHashList.js +35 -0
  77. package/dist/utils/Utils.d.ts +22 -0
  78. package/dist/utils/Utils.d.ts.map +1 -0
  79. package/dist/utils/Utils.js +41 -0
  80. package/dist/utils/merkletree/MemoryMerkleTreeStorage.d.ts +26 -0
  81. package/dist/utils/merkletree/MemoryMerkleTreeStorage.d.ts.map +1 -0
  82. package/dist/utils/merkletree/MemoryMerkleTreeStorage.js +79 -0
  83. package/dist/utils/merkletree/RollupMerkleTree.d.ts +143 -0
  84. package/dist/utils/merkletree/RollupMerkleTree.d.ts.map +1 -0
  85. package/dist/utils/merkletree/RollupMerkleTree.js +246 -0
  86. package/dist/utils.d.ts +2 -0
  87. package/dist/utils.d.ts.map +1 -0
  88. package/dist/utils.js +7 -0
  89. package/dist/zkProgrammable/ProvableMethodExecutionContext.d.ts +53 -0
  90. package/dist/zkProgrammable/ProvableMethodExecutionContext.d.ts.map +1 -0
  91. package/dist/zkProgrammable/ProvableMethodExecutionContext.js +98 -0
  92. package/dist/zkProgrammable/ZkProgrammable.d.ts +32 -0
  93. package/dist/zkProgrammable/ZkProgrammable.d.ts.map +1 -0
  94. package/dist/zkProgrammable/ZkProgrammable.js +60 -0
  95. package/dist/zkProgrammable/provableMethod.d.ts +16 -0
  96. package/dist/zkProgrammable/provableMethod.d.ts.map +1 -0
  97. package/dist/zkProgrammable/provableMethod.js +69 -0
  98. package/jest.config.cjs +1 -0
  99. package/package.json +35 -0
  100. package/src/config/ConfigurableModule.ts +44 -0
  101. package/src/config/ModuleContainer.ts +265 -0
  102. package/src/index.ts +9 -0
  103. package/src/types.ts +17 -0
  104. package/src/utils.ts +10 -0
  105. package/src/zkProgrammable/ProvableMethodExecutionContext.ts +122 -0
  106. package/src/zkProgrammable/ZkProgrammable.ts +119 -0
  107. package/src/zkProgrammable/provableMethod.ts +109 -0
  108. package/test/config/ModuleContainer.test.ts +82 -0
  109. package/test/tsconfig.json +4 -0
  110. package/test/zkProgrammable/ZkProgrammable.test.ts +283 -0
  111. package/tsconfig.json +8 -0
  112. package/tsconfig.test.json +9 -0
@@ -0,0 +1,9 @@
1
+ export * from "./config/ModuleContainer";
2
+ export * from "./config/ConfigurableModule";
3
+ export * from "./types";
4
+ export * from "./zkProgrammable/ZkProgrammable";
5
+ export * from "./zkProgrammable/ProvableMethodExecutionContext";
6
+ export * from "./zkProgrammable/provableMethod";
7
+ export * from "./utils";
8
+ export { default as log } from "loglevel";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,SAAS,CAAC;AACxB,cAAc,iCAAiC,CAAC;AAChD,cAAc,iDAAiD,CAAC;AAChE,cAAc,iCAAiC,CAAC;AAChD,cAAc,SAAS,CAAC;AAExB,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export * from "./config/ModuleContainer";
2
+ export * from "./config/ConfigurableModule";
3
+ export * from "./types";
4
+ export * from "./zkProgrammable/ZkProgrammable";
5
+ export * from "./zkProgrammable/ProvableMethodExecutionContext";
6
+ export * from "./zkProgrammable/provableMethod";
7
+ export * from "./utils";
8
+ // eslint-disable-next-line import/no-unused-modules
9
+ export { default as log } from "loglevel";
@@ -0,0 +1,51 @@
1
+ import { Bool, Field } from "snarkyjs";
2
+ declare const MethodPublicInput_base: (new (value: {
3
+ stateTransitionsHash: Field;
4
+ status: Bool;
5
+ transactionHash: Field;
6
+ }) => {
7
+ stateTransitionsHash: Field;
8
+ status: Bool;
9
+ transactionHash: Field;
10
+ }) & {
11
+ _isStruct: true;
12
+ } & import("snarkyjs/dist/node/snarky").ProvablePure<{
13
+ stateTransitionsHash: Field;
14
+ status: Bool;
15
+ transactionHash: Field;
16
+ }> & {
17
+ toInput: (x: {
18
+ stateTransitionsHash: Field;
19
+ status: Bool;
20
+ transactionHash: Field;
21
+ }) => {
22
+ fields?: Field[] | undefined;
23
+ packed?: [Field, number][] | undefined;
24
+ };
25
+ toJSON: (x: {
26
+ stateTransitionsHash: Field;
27
+ status: Bool;
28
+ transactionHash: Field;
29
+ }) => {
30
+ stateTransitionsHash: string;
31
+ status: boolean;
32
+ transactionHash: string;
33
+ };
34
+ fromJSON: (x: {
35
+ stateTransitionsHash: string;
36
+ status: boolean;
37
+ transactionHash: string;
38
+ }) => {
39
+ stateTransitionsHash: Field;
40
+ status: Bool;
41
+ transactionHash: Field;
42
+ };
43
+ };
44
+ /**
45
+ * Public input used to link in-circuit execution with
46
+ * the proof's public input.
47
+ */
48
+ export declare class MethodPublicInput extends MethodPublicInput_base {
49
+ }
50
+ export {};
51
+ //# sourceMappingURL=MethodPublicInput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MethodPublicInput.d.ts","sourceRoot":"","sources":["../../src/model/MethodPublicInput.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAU,MAAM,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE/C;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,sBAIrC;CAAG"}
@@ -0,0 +1,11 @@
1
+ import { Bool, Field, Struct } from "snarkyjs";
2
+ /**
3
+ * Public input used to link in-circuit execution with
4
+ * the proof's public input.
5
+ */
6
+ export class MethodPublicInput extends Struct({
7
+ stateTransitionsHash: Field,
8
+ status: Bool,
9
+ transactionHash: Field,
10
+ }) {
11
+ }
@@ -0,0 +1,89 @@
1
+ import { Bool, Field, type FlexibleProvablePure } from "snarkyjs";
2
+ declare const ProvableOption_base: (new (value: {
3
+ isSome: Bool;
4
+ value: Field;
5
+ }) => {
6
+ isSome: Bool;
7
+ value: Field;
8
+ }) & {
9
+ _isStruct: true;
10
+ } & import("snarkyjs/dist/node/snarky").ProvablePure<{
11
+ isSome: Bool;
12
+ value: Field;
13
+ }> & {
14
+ toInput: (x: {
15
+ isSome: Bool;
16
+ value: Field;
17
+ }) => {
18
+ fields?: Field[] | undefined;
19
+ packed?: [Field, number][] | undefined;
20
+ };
21
+ toJSON: (x: {
22
+ isSome: Bool;
23
+ value: Field;
24
+ }) => {
25
+ isSome: boolean;
26
+ value: string;
27
+ };
28
+ fromJSON: (x: {
29
+ isSome: boolean;
30
+ value: string;
31
+ }) => {
32
+ isSome: Bool;
33
+ value: Field;
34
+ };
35
+ };
36
+ export declare class ProvableOption extends ProvableOption_base {
37
+ toSome(): this;
38
+ }
39
+ /**
40
+ * Option facilitating in-circuit values that may or may not exist.
41
+ */
42
+ export declare class Option<Value> {
43
+ isSome: Bool;
44
+ value: Value;
45
+ valueType: FlexibleProvablePure<Value>;
46
+ /**
47
+ * Creates a new Option from the provided parameters
48
+ *
49
+ * @param isSome
50
+ * @param value
51
+ * @param valueType
52
+ * @returns New option from the provided parameters.
53
+ */
54
+ static from<Value>(isSome: Bool, value: Value, valueType: FlexibleProvablePure<Value>): Option<Value>;
55
+ /**
56
+ * Creates a new Option from the provided parameters
57
+ *
58
+ * @param value
59
+ * @param valueType
60
+ * @returns New option from the provided parameters.
61
+ */
62
+ static fromValue<Value>(value: Value, valueType: FlexibleProvablePure<Value>): Option<Value>;
63
+ /**
64
+ * @returns Empty / none option
65
+ */
66
+ static none(): Option<Field>;
67
+ static dummyValueFields<Value>(valueType: FlexibleProvablePure<Value>): Field[];
68
+ /**
69
+ * Computes a dummy value for the given value type.
70
+ *
71
+ * @param valueType - Value type to generate the dummy value for
72
+ * @returns Dummy value for the given value type
73
+ */
74
+ static dummyValue<Value>(valueType: FlexibleProvablePure<Value>): Value;
75
+ isForcedSome: Bool;
76
+ constructor(isSome: Bool, value: Value, valueType: FlexibleProvablePure<Value>);
77
+ clone(): Option<Value>;
78
+ forceSome(): void;
79
+ /**
80
+ * @returns Tree representation of the current value
81
+ */
82
+ get treeValue(): Field;
83
+ /**
84
+ * @returns Provable representation of the current option.
85
+ */
86
+ toProvable(): ProvableOption;
87
+ }
88
+ export {};
89
+ //# sourceMappingURL=Option.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Option.d.ts","sourceRoot":"","sources":["../../src/model/Option.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EAEJ,KAAK,EACL,KAAK,oBAAoB,EAG1B,MAAM,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAElB,qBAAa,cAAe,SAAQ,mBAGlC;IACO,MAAM;CAId;AAED;;GAEG;AACH,qBAAa,MAAM,CAAC,KAAK;IA+Dd,MAAM,EAAE,IAAI;IACZ,KAAK,EAAE,KAAK;IACZ,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAhE/C;;;;;;;OAOG;WACW,IAAI,CAAC,KAAK,EACtB,MAAM,EAAE,IAAI,EACZ,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAKxC;;;;;;OAMG;WACW,SAAS,CAAC,KAAK,EAC3B,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAKxC;;OAEG;WACW,IAAI;WAIJ,gBAAgB,CAAC,KAAK,EAClC,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC,GACrC,KAAK,EAAE;IAKV;;;;;OAKG;WACW,UAAU,CAAC,KAAK,EAC5B,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC,GACrC,KAAK;IAOD,YAAY,OAAe;gBAGzB,MAAM,EAAE,IAAI,EACZ,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAGxC,KAAK;IAIL,SAAS;IAKhB;;OAEG;IACH,IAAW,SAAS,UAQnB;IAED;;OAEG;IACI,UAAU;CAMlB"}
@@ -0,0 +1,86 @@
1
+ import { Bool, Circuit, Field, Poseidon, Struct, } from "snarkyjs";
2
+ export class ProvableOption extends Struct({
3
+ isSome: Bool,
4
+ value: Field,
5
+ }) {
6
+ toSome() {
7
+ this.isSome = Bool(true);
8
+ return this;
9
+ }
10
+ }
11
+ /**
12
+ * Option facilitating in-circuit values that may or may not exist.
13
+ */
14
+ export class Option {
15
+ /**
16
+ * Creates a new Option from the provided parameters
17
+ *
18
+ * @param isSome
19
+ * @param value
20
+ * @param valueType
21
+ * @returns New option from the provided parameters.
22
+ */
23
+ static from(isSome, value, valueType) {
24
+ return new Option(isSome, value, valueType);
25
+ }
26
+ /**
27
+ * Creates a new Option from the provided parameters
28
+ *
29
+ * @param value
30
+ * @param valueType
31
+ * @returns New option from the provided parameters.
32
+ */
33
+ static fromValue(value, valueType) {
34
+ return this.from(Bool(true), value, valueType);
35
+ }
36
+ /**
37
+ * @returns Empty / none option
38
+ */
39
+ static none() {
40
+ return new Option(Bool(false), Field(0), Field);
41
+ }
42
+ static dummyValueFields(valueType) {
43
+ const length = valueType.sizeInFields();
44
+ return Array.from({ length }, () => Field(0));
45
+ }
46
+ /**
47
+ * Computes a dummy value for the given value type.
48
+ *
49
+ * @param valueType - Value type to generate the dummy value for
50
+ * @returns Dummy value for the given value type
51
+ */
52
+ static dummyValue(valueType) {
53
+ const fields = Option.dummyValueFields(valueType);
54
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
55
+ return valueType.fromFields(fields);
56
+ }
57
+ constructor(isSome, value, valueType) {
58
+ this.isSome = isSome;
59
+ this.value = value;
60
+ this.valueType = valueType;
61
+ this.isForcedSome = Bool(false);
62
+ }
63
+ clone() {
64
+ return new Option(this.isSome, this.value, this.valueType);
65
+ }
66
+ forceSome() {
67
+ this.isForcedSome = Circuit.if(this.isSome, Bool(false), Bool(true));
68
+ this.isSome = Bool(true);
69
+ }
70
+ /**
71
+ * @returns Tree representation of the current value
72
+ */
73
+ get treeValue() {
74
+ const treeValue = Poseidon.hash(this.valueType.toFields(this.value));
75
+ return Circuit.if(this.isSome.and(this.isForcedSome.not()), treeValue, Field(0));
76
+ }
77
+ /**
78
+ * @returns Provable representation of the current option.
79
+ */
80
+ toProvable() {
81
+ return new ProvableOption({
82
+ isSome: this.isSome,
83
+ value: this.treeValue,
84
+ });
85
+ }
86
+ }
@@ -0,0 +1,31 @@
1
+ import { Field, type FlexibleProvablePure } from "snarkyjs";
2
+ /**
3
+ * Helps manage path (key) identifiers for key-values in trees.
4
+ */
5
+ export declare class Path {
6
+ /**
7
+ * Encodes a JS string as a Field
8
+ *
9
+ * @param value
10
+ * @returns Field representation of the provided value
11
+ */
12
+ static toField(value: string): Field;
13
+ /**
14
+ * Encodes a class name and its property name into a Field
15
+ *
16
+ * @param className
17
+ * @param propertyKey
18
+ * @returns Field representation of class name + property name
19
+ */
20
+ static fromProperty(className: string, propertyKey: string): Field;
21
+ /**
22
+ * Encodes an existing path with the provided key into a single Field.
23
+ *
24
+ * @param path
25
+ * @param keyType
26
+ * @param key
27
+ * @returns Field representation of the leading path + the provided key.
28
+ */
29
+ static fromKey<KeyType>(path: Field, keyType: FlexibleProvablePure<KeyType>, key: KeyType): Field;
30
+ }
31
+ //# sourceMappingURL=Path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Path.d.ts","sourceRoot":"","sources":["../../src/model/Path.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,KAAK,oBAAoB,EAAY,MAAM,UAAU,CAAC;AAItE;;GAEG;AACH,qBAAa,IAAI;IACf;;;;;OAKG;WACW,OAAO,CAAC,KAAK,EAAE,MAAM;IAInC;;;;;;OAMG;WACW,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,KAAK;IAQzE;;;;;;;OAOG;WACW,OAAO,CAAC,OAAO,EAC3B,IAAI,EAAE,KAAK,EACX,OAAO,EAAE,oBAAoB,CAAC,OAAO,CAAC,EACtC,GAAG,EAAE,OAAO,GACX,KAAK;CAIT"}
@@ -0,0 +1,44 @@
1
+ /* eslint-disable @typescript-eslint/no-extraneous-class */
2
+ /* eslint-disable @shopify/no-fully-static-classes */
3
+ import { Field, Poseidon } from "snarkyjs";
4
+ import { stringToField } from "../utils/utils";
5
+ /**
6
+ * Helps manage path (key) identifiers for key-values in trees.
7
+ */
8
+ export class Path {
9
+ /**
10
+ * Encodes a JS string as a Field
11
+ *
12
+ * @param value
13
+ * @returns Field representation of the provided value
14
+ */
15
+ static toField(value) {
16
+ return stringToField(value);
17
+ }
18
+ /**
19
+ * Encodes a class name and its property name into a Field
20
+ *
21
+ * @param className
22
+ * @param propertyKey
23
+ * @returns Field representation of class name + property name
24
+ */
25
+ static fromProperty(className, propertyKey) {
26
+ return Poseidon.hash([
27
+ Path.toField(className),
28
+ Path.toField(propertyKey),
29
+ Field(0),
30
+ ]);
31
+ }
32
+ /**
33
+ * Encodes an existing path with the provided key into a single Field.
34
+ *
35
+ * @param path
36
+ * @param keyType
37
+ * @param key
38
+ * @returns Field representation of the leading path + the provided key.
39
+ */
40
+ static fromKey(path, keyType, key) {
41
+ const keyHash = Poseidon.hash(keyType.toFields(key));
42
+ return Poseidon.hash([path, keyHash]);
43
+ }
44
+ }
@@ -0,0 +1,85 @@
1
+ import { Field } from "snarkyjs";
2
+ import { Option, ProvableOption } from "./Option.js";
3
+ declare const ProvableStateTransition_base: (new (value: {
4
+ path: Field;
5
+ from: ProvableOption;
6
+ to: ProvableOption;
7
+ }) => {
8
+ path: Field;
9
+ from: ProvableOption;
10
+ to: ProvableOption;
11
+ }) & {
12
+ _isStruct: true;
13
+ } & import("snarkyjs/dist/node/snarky.js").ProvablePure<{
14
+ path: Field;
15
+ from: ProvableOption;
16
+ to: ProvableOption;
17
+ }> & {
18
+ toInput: (x: {
19
+ path: Field;
20
+ from: ProvableOption;
21
+ to: ProvableOption;
22
+ }) => {
23
+ fields?: Field[] | undefined;
24
+ packed?: [Field, number][] | undefined;
25
+ };
26
+ toJSON: (x: {
27
+ path: Field;
28
+ from: ProvableOption;
29
+ to: ProvableOption;
30
+ }) => {
31
+ path: string;
32
+ from: {
33
+ isSome: boolean;
34
+ value: string;
35
+ };
36
+ to: {
37
+ isSome: boolean;
38
+ value: string;
39
+ };
40
+ };
41
+ fromJSON: (x: {
42
+ path: string;
43
+ from: {
44
+ isSome: boolean;
45
+ value: string;
46
+ };
47
+ to: {
48
+ isSome: boolean;
49
+ value: string;
50
+ };
51
+ }) => {
52
+ path: Field;
53
+ from: ProvableOption;
54
+ to: ProvableOption;
55
+ };
56
+ };
57
+ /**
58
+ * Provable representation of a State Transition, used to
59
+ * normalize state transitions of various value types for
60
+ * the state transition circuit.
61
+ */
62
+ export declare class ProvableStateTransition extends ProvableStateTransition_base {
63
+ static dummy(): ProvableStateTransition;
64
+ }
65
+ /**
66
+ * Generic state transition that constraints the current method circuit
67
+ * to external state, by providing a state anchor.
68
+ */
69
+ export declare class StateTransition<Value> {
70
+ path: Field;
71
+ fromValue: Option<Field> | Option<Value>;
72
+ toValue: Option<Field> | Option<Value>;
73
+ static from<Value>(path: Field, fromValue: Option<Value>): StateTransition<Value>;
74
+ static fromTo<Value>(path: Field, fromValue: Option<Value>, toValue: Option<Value>): StateTransition<Value>;
75
+ constructor(path: Field, fromValue: Option<Field> | Option<Value>, toValue: Option<Field> | Option<Value>);
76
+ get from(): Option<Field> | Option<Value>;
77
+ get to(): Option<Field> | Option<Value>;
78
+ /**
79
+ * Converts a StateTransition to a ProvableStateTransition,
80
+ * while enforcing the 'from' property to be 'Some' in all cases.
81
+ */
82
+ toProvable(): ProvableStateTransition;
83
+ }
84
+ export {};
85
+ //# sourceMappingURL=StateTransition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StateTransition.d.ts","sourceRoot":"","sources":["../../src/model/StateTransition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAU,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAErD;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,4BAQ3C;WACc,KAAK,IAAI,uBAAuB;CAO/C;AAED;;;GAGG;AACH,qBAAa,eAAe,CAAC,KAAK;IAcvB,IAAI,EAAE,KAAK;IACX,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;IACxC,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;WAfjC,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC;WAIjD,MAAM,CAAC,KAAK,EACxB,IAAI,EAAE,KAAK,EACX,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,EACxB,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC;gBAMf,IAAI,EAAE,KAAK,EACX,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,EACxC,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;IAG/C,IAAW,IAAI,kCAId;IAED,IAAW,EAAE,kCAEZ;IAED;;;OAGG;IACI,UAAU,IAAI,uBAAuB;CAO7C"}
@@ -0,0 +1,58 @@
1
+ import { Field, Struct } from "snarkyjs";
2
+ import { Option, ProvableOption } 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 class ProvableStateTransition extends Struct({
9
+ path: Field,
10
+ // must be applied even if `None`
11
+ from: ProvableOption,
12
+ // must be ignored if `None`
13
+ to: ProvableOption,
14
+ }) {
15
+ static dummy() {
16
+ return new ProvableStateTransition({
17
+ path: Field(0),
18
+ from: Option.none().toProvable(),
19
+ to: Option.none().toProvable(),
20
+ });
21
+ }
22
+ }
23
+ /**
24
+ * Generic state transition that constraints the current method circuit
25
+ * to external state, by providing a state anchor.
26
+ */
27
+ export class StateTransition {
28
+ static from(path, fromValue) {
29
+ return new StateTransition(path, fromValue, Option.none());
30
+ }
31
+ static fromTo(path, fromValue, toValue) {
32
+ return new StateTransition(path, fromValue, toValue);
33
+ }
34
+ constructor(path, fromValue, toValue) {
35
+ this.path = path;
36
+ this.fromValue = fromValue;
37
+ this.toValue = toValue;
38
+ }
39
+ get from() {
40
+ const from = this.fromValue.clone();
41
+ from.forceSome();
42
+ return from;
43
+ }
44
+ get to() {
45
+ return this.toValue.clone();
46
+ }
47
+ /**
48
+ * Converts a StateTransition to a ProvableStateTransition,
49
+ * while enforcing the 'from' property to be 'Some' in all cases.
50
+ */
51
+ toProvable() {
52
+ return new ProvableStateTransition({
53
+ path: this.path,
54
+ from: this.from.toProvable(),
55
+ to: this.to.toProvable(),
56
+ });
57
+ }
58
+ }
@@ -0,0 +1,56 @@
1
+ import { ProvableStateTransition } from "./StateTransition.js";
2
+ declare const StateTransitionProvableBatch_base: (new (value: {
3
+ batch: ProvableStateTransition[];
4
+ }) => {
5
+ batch: ProvableStateTransition[];
6
+ }) & {
7
+ _isStruct: true;
8
+ } & import("snarkyjs/dist/node/snarky.js").ProvablePure<{
9
+ batch: ProvableStateTransition[];
10
+ }> & {
11
+ toInput: (x: {
12
+ batch: ProvableStateTransition[];
13
+ }) => {
14
+ fields?: import("snarkyjs/dist/node/snarky.js").Field[] | undefined;
15
+ packed?: [import("snarkyjs/dist/node/snarky.js").Field, number][] | undefined;
16
+ };
17
+ toJSON: (x: {
18
+ batch: ProvableStateTransition[];
19
+ }) => {
20
+ batch: {
21
+ path: string;
22
+ from: {
23
+ isSome: boolean;
24
+ value: string;
25
+ };
26
+ to: {
27
+ isSome: boolean;
28
+ value: string;
29
+ };
30
+ }[];
31
+ };
32
+ fromJSON: (x: {
33
+ batch: {
34
+ path: string;
35
+ from: {
36
+ isSome: boolean;
37
+ value: string;
38
+ };
39
+ to: {
40
+ isSome: boolean;
41
+ value: string;
42
+ };
43
+ }[];
44
+ }) => {
45
+ batch: ProvableStateTransition[];
46
+ };
47
+ };
48
+ /**
49
+ * A Batch of StateTransitions to be consumed by the StateTransitionProver
50
+ * to prove multiple STs at once
51
+ */
52
+ export declare class StateTransitionProvableBatch extends StateTransitionProvableBatch_base {
53
+ static fromTransitions(transitions: ProvableStateTransition[]): StateTransitionProvableBatch;
54
+ }
55
+ export {};
56
+ //# sourceMappingURL=StateTransitionProvableBatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StateTransitionProvableBatch.d.ts","sourceRoot":"","sources":["../../src/model/StateTransitionProvableBatch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAM/D;;;GAGG;AACH,qBAAa,4BAA6B,SAAQ,iCAKhD;WACc,eAAe,CAC3B,WAAW,EAAE,uBAAuB,EAAE,GACrC,4BAA4B;CAShC"}
@@ -0,0 +1,20 @@
1
+ import { Circuit, Struct } from "snarkyjs";
2
+ import { ProvableStateTransition } from "./StateTransition.js";
3
+ const constants = {
4
+ stateTransitionProverBatchSize: 8,
5
+ };
6
+ /**
7
+ * A Batch of StateTransitions to be consumed by the StateTransitionProver
8
+ * to prove multiple STs at once
9
+ */
10
+ export class StateTransitionProvableBatch extends Struct({
11
+ batch: Circuit.array(ProvableStateTransition, constants.stateTransitionProverBatchSize),
12
+ }) {
13
+ static fromTransitions(transitions) {
14
+ const array = transitions.slice();
15
+ while (array.length < constants.stateTransitionProverBatchSize) {
16
+ array.push(ProvableStateTransition.dummy());
17
+ }
18
+ return new StateTransitionProvableBatch({ batch: array });
19
+ }
20
+ }