@proto-kit/module 0.1.1-develop.211 → 0.1.1-develop.2137

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 (155) hide show
  1. package/dist/factories/MethodIdFactory.d.ts +6 -6
  2. package/dist/factories/MethodIdFactory.d.ts.map +1 -1
  3. package/dist/factories/MethodIdFactory.js +10 -34
  4. package/dist/factories/MethodIdFactory.js.map +1 -0
  5. package/dist/index.d.ts +4 -7
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +5 -7
  8. package/dist/index.js.map +1 -0
  9. package/dist/messages/OutgoingMessage.d.ts +96 -0
  10. package/dist/messages/OutgoingMessage.d.ts.map +1 -0
  11. package/dist/messages/OutgoingMessage.js +68 -0
  12. package/dist/messages/OutgoingMessage.js.map +1 -0
  13. package/dist/messages/OutgoingMessages.d.ts +231 -0
  14. package/dist/messages/OutgoingMessages.d.ts.map +1 -0
  15. package/dist/messages/OutgoingMessages.js +67 -0
  16. package/dist/messages/OutgoingMessages.js.map +1 -0
  17. package/dist/method/MethodParameterEncoder.d.ts +26 -0
  18. package/dist/method/MethodParameterEncoder.d.ts.map +1 -0
  19. package/dist/method/MethodParameterEncoder.js +169 -0
  20. package/dist/method/MethodParameterEncoder.js.map +1 -0
  21. package/dist/method/runtimeMethod.d.ts +21 -5
  22. package/dist/method/runtimeMethod.d.ts.map +1 -1
  23. package/dist/method/runtimeMethod.js +69 -25
  24. package/dist/method/runtimeMethod.js.map +1 -0
  25. package/dist/module/decorator.js +1 -0
  26. package/dist/module/decorator.js.map +1 -0
  27. package/dist/runtime/MethodIdResolver.d.ts +10 -8
  28. package/dist/runtime/MethodIdResolver.d.ts.map +1 -1
  29. package/dist/runtime/MethodIdResolver.js +75 -33
  30. package/dist/runtime/MethodIdResolver.js.map +1 -0
  31. package/dist/runtime/Runtime.d.ts +20 -26
  32. package/dist/runtime/Runtime.d.ts.map +1 -1
  33. package/dist/runtime/Runtime.js +117 -62
  34. package/dist/runtime/Runtime.js.map +1 -0
  35. package/dist/runtime/RuntimeEnvironment.d.ts +10 -0
  36. package/dist/runtime/RuntimeEnvironment.d.ts.map +1 -0
  37. package/dist/runtime/RuntimeEnvironment.js +2 -0
  38. package/dist/runtime/RuntimeEnvironment.js.map +1 -0
  39. package/dist/runtime/RuntimeModule.d.ts +18 -15
  40. package/dist/runtime/RuntimeModule.d.ts.map +1 -1
  41. package/dist/runtime/RuntimeModule.js +33 -8
  42. package/dist/runtime/RuntimeModule.js.map +1 -0
  43. package/dist/state/InMemoryStateService.d.ts +11 -10
  44. package/dist/state/InMemoryStateService.d.ts.map +1 -1
  45. package/dist/state/InMemoryStateService.js +11 -8
  46. package/dist/state/InMemoryStateService.js.map +1 -0
  47. package/dist/state/decorator.d.ts.map +1 -1
  48. package/dist/state/decorator.js +2 -4
  49. package/dist/state/decorator.js.map +1 -0
  50. package/dist/testing/TestingRuntime.d.ts +8 -0
  51. package/dist/testing/TestingRuntime.d.ts.map +1 -0
  52. package/dist/testing/TestingRuntime.js +31 -0
  53. package/dist/testing/TestingRuntime.js.map +1 -0
  54. package/jest.config.cjs +12 -1
  55. package/package.json +9 -9
  56. package/src/factories/MethodIdFactory.ts +10 -17
  57. package/src/index.ts +4 -4
  58. package/src/messages/OutgoingMessages.ts +124 -0
  59. package/src/method/MethodParameterEncoder.ts +262 -0
  60. package/src/method/runtimeMethod.ts +131 -33
  61. package/src/runtime/MethodIdResolver.ts +85 -46
  62. package/src/runtime/Runtime.ts +187 -96
  63. package/src/runtime/RuntimeEnvironment.ts +16 -0
  64. package/src/runtime/RuntimeModule.ts +58 -27
  65. package/src/state/InMemoryStateService.ts +14 -14
  66. package/test/Runtime.test.ts +68 -42
  67. package/test/TestingRuntime.ts +43 -0
  68. package/test/messages/message.test.ts +42 -0
  69. package/test/method/MethodParameterEncoder.test.ts +124 -0
  70. package/test/method/runtimeMethod-fail.test.ts +53 -0
  71. package/{src/method/decorator.test.ts → test/method/runtimeMethod.test.ts} +3 -3
  72. package/test/modules/Admin.ts +4 -4
  73. package/test/modules/Balances.test.ts +88 -79
  74. package/test/modules/Balances.ts +15 -21
  75. package/test/modules/{methodId.test.ts → MethodIdResolver.test.ts} +24 -35
  76. package/test/modules/State.test.ts +46 -53
  77. package/test/runtimeMethod.test.ts +192 -20
  78. package/test/tsconfig.json +7 -0
  79. package/tsconfig.json +2 -2
  80. package/LICENSE.md +0 -201
  81. package/dist/method/MethodParameterDecoder.d.ts +0 -22
  82. package/dist/method/MethodParameterDecoder.d.ts.map +0 -1
  83. package/dist/method/MethodParameterDecoder.js +0 -33
  84. package/dist/method/RuntimeMethodExecutionContext.d.ts +0 -57
  85. package/dist/method/RuntimeMethodExecutionContext.d.ts.map +0 -1
  86. package/dist/method/RuntimeMethodExecutionContext.js +0 -92
  87. package/dist/method/assert.d.ts +0 -12
  88. package/dist/method/assert.d.ts.map +0 -1
  89. package/dist/method/assert.js +0 -23
  90. package/dist/module/src/factories/MethodIdFactory.d.ts +0 -9
  91. package/dist/module/src/factories/MethodIdFactory.d.ts.map +0 -1
  92. package/dist/module/src/factories/MethodIdFactory.js +0 -36
  93. package/dist/module/src/index.d.ts +0 -11
  94. package/dist/module/src/index.d.ts.map +0 -1
  95. package/dist/module/src/index.js +0 -10
  96. package/dist/module/src/method/MethodParameterDecoder.d.ts +0 -22
  97. package/dist/module/src/method/MethodParameterDecoder.d.ts.map +0 -1
  98. package/dist/module/src/method/MethodParameterDecoder.js +0 -33
  99. package/dist/module/src/method/runtimeMethod.d.ts +0 -19
  100. package/dist/module/src/method/runtimeMethod.d.ts.map +0 -1
  101. package/dist/module/src/method/runtimeMethod.js +0 -123
  102. package/dist/module/src/module/decorator.d.ts +0 -8
  103. package/dist/module/src/module/decorator.d.ts.map +0 -1
  104. package/dist/module/src/module/decorator.js +0 -15
  105. package/dist/module/src/runtime/MethodIdResolver.d.ts +0 -18
  106. package/dist/module/src/runtime/MethodIdResolver.d.ts.map +0 -1
  107. package/dist/module/src/runtime/MethodIdResolver.js +0 -50
  108. package/dist/module/src/runtime/Runtime.d.ts +0 -72
  109. package/dist/module/src/runtime/Runtime.d.ts.map +0 -1
  110. package/dist/module/src/runtime/Runtime.js +0 -184
  111. package/dist/module/src/runtime/RuntimeModule.d.ts +0 -35
  112. package/dist/module/src/runtime/RuntimeModule.d.ts.map +0 -1
  113. package/dist/module/src/runtime/RuntimeModule.js +0 -56
  114. package/dist/module/src/state/InMemoryStateService.d.ts +0 -11
  115. package/dist/module/src/state/InMemoryStateService.d.ts.map +0 -1
  116. package/dist/module/src/state/InMemoryStateService.js +0 -21
  117. package/dist/module/src/state/decorator.d.ts +0 -7
  118. package/dist/module/src/state/decorator.d.ts.map +0 -1
  119. package/dist/module/src/state/decorator.js +0 -42
  120. package/dist/protocol/src/model/Option.d.ts +0 -98
  121. package/dist/protocol/src/model/Option.d.ts.map +0 -1
  122. package/dist/protocol/src/model/Option.js +0 -98
  123. package/dist/protocol/src/model/StateTransition.d.ts +0 -96
  124. package/dist/protocol/src/model/StateTransition.d.ts.map +0 -1
  125. package/dist/protocol/src/model/StateTransition.js +0 -65
  126. package/dist/protocol/src/model/network/NetworkState.d.ts +0 -64
  127. package/dist/protocol/src/model/network/NetworkState.d.ts.map +0 -1
  128. package/dist/protocol/src/model/network/NetworkState.js +0 -12
  129. package/dist/protocol/src/model/transaction/ProtocolTransaction.d.ts +0 -70
  130. package/dist/protocol/src/model/transaction/ProtocolTransaction.d.ts.map +0 -1
  131. package/dist/protocol/src/model/transaction/ProtocolTransaction.js +0 -18
  132. package/dist/protocol/src/model/transaction/RuntimeTransaction.d.ts +0 -63
  133. package/dist/protocol/src/model/transaction/RuntimeTransaction.d.ts.map +0 -1
  134. package/dist/protocol/src/model/transaction/RuntimeTransaction.js +0 -29
  135. package/dist/protocol/src/state/assert/assert.d.ts +0 -12
  136. package/dist/protocol/src/state/assert/assert.d.ts.map +0 -1
  137. package/dist/protocol/src/state/assert/assert.js +0 -23
  138. package/dist/protocol/src/state/context/RuntimeMethodExecutionContext.d.ts +0 -60
  139. package/dist/protocol/src/state/context/RuntimeMethodExecutionContext.d.ts.map +0 -1
  140. package/dist/protocol/src/state/context/RuntimeMethodExecutionContext.js +0 -105
  141. package/dist/state/State.d.ts +0 -65
  142. package/dist/state/State.d.ts.map +0 -1
  143. package/dist/state/State.js +0 -114
  144. package/dist/state/StateMap.d.ts +0 -37
  145. package/dist/state/StateMap.d.ts.map +0 -1
  146. package/dist/state/StateMap.js +0 -56
  147. package/dist/state/StateServiceProvider.d.ts +0 -10
  148. package/dist/state/StateServiceProvider.d.ts.map +0 -1
  149. package/dist/state/StateServiceProvider.js +0 -34
  150. package/src/method/MethodParameterDecoder.ts +0 -70
  151. package/src/state/decorator.ts +0 -63
  152. package/test/state/MerkleTree.test.ts +0 -95
  153. package/test/state/MockAsyncMerkleStore.ts +0 -28
  154. package/test/transaction.test.ts +0 -82
  155. package/tsconfig.test.json +0 -9
@@ -1,65 +0,0 @@
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
- toJSON() {
59
- return {
60
- path: this.path.toString(),
61
- from: this.from.toJSON(),
62
- to: this.to.toJSON(),
63
- };
64
- }
65
- }
@@ -1,64 +0,0 @@
1
- import { Field, UInt64 } from "snarkyjs";
2
- declare const CurrentBlock_base: (new (value: {
3
- height: UInt64;
4
- }) => {
5
- height: UInt64;
6
- }) & {
7
- _isStruct: true;
8
- } & import("snarkyjs/dist/node/snarky").ProvablePure<{
9
- height: UInt64;
10
- }> & {
11
- toInput: (x: {
12
- height: UInt64;
13
- }) => {
14
- fields?: import("snarkyjs/dist/node/lib/field").Field[] | undefined;
15
- packed?: [import("snarkyjs/dist/node/lib/field").Field, number][] | undefined;
16
- };
17
- toJSON: (x: {
18
- height: UInt64;
19
- }) => {
20
- height: string;
21
- };
22
- fromJSON: (x: {
23
- height: string;
24
- }) => {
25
- height: UInt64;
26
- };
27
- };
28
- export declare class CurrentBlock extends CurrentBlock_base {
29
- }
30
- declare const NetworkState_base: (new (value: {
31
- block: CurrentBlock;
32
- }) => {
33
- block: CurrentBlock;
34
- }) & {
35
- _isStruct: true;
36
- } & import("snarkyjs/dist/node/snarky").ProvablePure<{
37
- block: CurrentBlock;
38
- }> & {
39
- toInput: (x: {
40
- block: CurrentBlock;
41
- }) => {
42
- fields?: import("snarkyjs/dist/node/lib/field").Field[] | undefined;
43
- packed?: [import("snarkyjs/dist/node/lib/field").Field, number][] | undefined;
44
- };
45
- toJSON: (x: {
46
- block: CurrentBlock;
47
- }) => {
48
- block: {
49
- height: string;
50
- };
51
- };
52
- fromJSON: (x: {
53
- block: {
54
- height: string;
55
- };
56
- }) => {
57
- block: CurrentBlock;
58
- };
59
- };
60
- export declare class NetworkState extends NetworkState_base {
61
- hash(): Field;
62
- }
63
- export {};
64
- //# sourceMappingURL=NetworkState.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NetworkState.d.ts","sourceRoot":"","sources":["../../../../../../protocol/src/model/network/NetworkState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAoB,MAAM,EAAE,MAAM,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,qBAAa,YAAa,SAAQ,iBAEhC;CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEL,qBAAa,YAAa,SAAQ,iBAEhC;IACO,IAAI,IAAI,KAAK;CAGrB"}
@@ -1,12 +0,0 @@
1
- import { Poseidon, Struct, UInt64 } from "snarkyjs";
2
- export class CurrentBlock extends Struct({
3
- height: UInt64,
4
- }) {
5
- }
6
- export class NetworkState extends Struct({
7
- block: CurrentBlock,
8
- }) {
9
- hash() {
10
- return Poseidon.hash(CurrentBlock.toFields(this.block));
11
- }
12
- }
@@ -1,70 +0,0 @@
1
- import { Bool, Field, PublicKey, Signature, UInt64 } from "snarkyjs";
2
- declare const ProtocolTransaction_base: (new (value: {
3
- methodId: import("snarkyjs/dist/node/lib/field").Field;
4
- nonce: UInt64;
5
- sender: PublicKey;
6
- argsHash: import("snarkyjs/dist/node/lib/field").Field;
7
- signature: Signature;
8
- }) => {
9
- methodId: import("snarkyjs/dist/node/lib/field").Field;
10
- nonce: UInt64;
11
- sender: PublicKey;
12
- argsHash: import("snarkyjs/dist/node/lib/field").Field;
13
- signature: Signature;
14
- }) & {
15
- _isStruct: true;
16
- } & import("snarkyjs/dist/node/snarky").ProvablePure<{
17
- methodId: import("snarkyjs/dist/node/lib/field").Field;
18
- nonce: UInt64;
19
- sender: PublicKey;
20
- argsHash: import("snarkyjs/dist/node/lib/field").Field;
21
- signature: Signature;
22
- }> & {
23
- toInput: (x: {
24
- methodId: import("snarkyjs/dist/node/lib/field").Field;
25
- nonce: UInt64;
26
- sender: PublicKey;
27
- argsHash: import("snarkyjs/dist/node/lib/field").Field;
28
- signature: Signature;
29
- }) => {
30
- fields?: import("snarkyjs/dist/node/lib/field").Field[] | undefined;
31
- packed?: [import("snarkyjs/dist/node/lib/field").Field, number][] | undefined;
32
- };
33
- toJSON: (x: {
34
- methodId: import("snarkyjs/dist/node/lib/field").Field;
35
- nonce: UInt64;
36
- sender: PublicKey;
37
- argsHash: import("snarkyjs/dist/node/lib/field").Field;
38
- signature: Signature;
39
- }) => {
40
- methodId: string;
41
- nonce: string;
42
- sender: string;
43
- argsHash: string;
44
- signature: any;
45
- };
46
- fromJSON: (x: {
47
- methodId: string;
48
- nonce: string;
49
- sender: string;
50
- argsHash: string;
51
- signature: any;
52
- }) => {
53
- methodId: import("snarkyjs/dist/node/lib/field").Field;
54
- nonce: UInt64;
55
- sender: PublicKey;
56
- argsHash: import("snarkyjs/dist/node/lib/field").Field;
57
- signature: Signature;
58
- };
59
- };
60
- export declare class ProtocolTransaction extends ProtocolTransaction_base {
61
- static getSignatureData(args: {
62
- methodId: Field;
63
- nonce: UInt64;
64
- argsHash: Field;
65
- }): Field[];
66
- getSignatureData(): Field[];
67
- validateSignature(): Bool;
68
- }
69
- export {};
70
- //# sourceMappingURL=ProtocolTransaction.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ProtocolTransaction.d.ts","sourceRoot":"","sources":["../../../../../../protocol/src/model/transaction/ProtocolTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAU,MAAM,EAAE,MAAM,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE7E,qBAAa,mBAAoB,SAAQ,wBAMvC;WACc,gBAAgB,CAAC,IAAI,EAAE;QACnC,QAAQ,EAAE,KAAK,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,KAAK,CAAC;KACjB,GAAG,KAAK,EAAE;IAIJ,gBAAgB,IAAI,KAAK,EAAE;IAI3B,iBAAiB,IAAI,IAAI;CAGjC"}
@@ -1,18 +0,0 @@
1
- import { Field, PublicKey, Signature, Struct, UInt64 } from "snarkyjs";
2
- export class ProtocolTransaction extends Struct({
3
- methodId: Field,
4
- nonce: UInt64,
5
- sender: PublicKey,
6
- argsHash: Field,
7
- signature: Signature,
8
- }) {
9
- static getSignatureData(args) {
10
- return [args.methodId, ...args.nonce.toFields(), args.argsHash];
11
- }
12
- getSignatureData() {
13
- return ProtocolTransaction.getSignatureData(this);
14
- }
15
- validateSignature() {
16
- return this.signature.verify(this.sender, this.getSignatureData());
17
- }
18
- }
@@ -1,63 +0,0 @@
1
- import { Field, PublicKey, UInt64 } from "snarkyjs";
2
- import { ProtocolTransaction } from "./ProtocolTransaction";
3
- declare const RuntimeTransaction_base: (new (value: {
4
- methodId: import("snarkyjs/dist/node/lib/field").Field;
5
- nonce: UInt64;
6
- sender: PublicKey;
7
- argsHash: import("snarkyjs/dist/node/lib/field").Field;
8
- }) => {
9
- methodId: import("snarkyjs/dist/node/lib/field").Field;
10
- nonce: UInt64;
11
- sender: PublicKey;
12
- argsHash: import("snarkyjs/dist/node/lib/field").Field;
13
- }) & {
14
- _isStruct: true;
15
- } & import("snarkyjs/dist/node/snarky").ProvablePure<{
16
- methodId: import("snarkyjs/dist/node/lib/field").Field;
17
- nonce: UInt64;
18
- sender: PublicKey;
19
- argsHash: import("snarkyjs/dist/node/lib/field").Field;
20
- }> & {
21
- toInput: (x: {
22
- methodId: import("snarkyjs/dist/node/lib/field").Field;
23
- nonce: UInt64;
24
- sender: PublicKey;
25
- argsHash: import("snarkyjs/dist/node/lib/field").Field;
26
- }) => {
27
- fields?: import("snarkyjs/dist/node/lib/field").Field[] | undefined;
28
- packed?: [import("snarkyjs/dist/node/lib/field").Field, number][] | undefined;
29
- };
30
- toJSON: (x: {
31
- methodId: import("snarkyjs/dist/node/lib/field").Field;
32
- nonce: UInt64;
33
- sender: PublicKey;
34
- argsHash: import("snarkyjs/dist/node/lib/field").Field;
35
- }) => {
36
- methodId: string;
37
- nonce: string;
38
- sender: string;
39
- argsHash: string;
40
- };
41
- fromJSON: (x: {
42
- methodId: string;
43
- nonce: string;
44
- sender: string;
45
- argsHash: string;
46
- }) => {
47
- methodId: import("snarkyjs/dist/node/lib/field").Field;
48
- nonce: UInt64;
49
- sender: PublicKey;
50
- argsHash: import("snarkyjs/dist/node/lib/field").Field;
51
- };
52
- };
53
- /**
54
- * This struct is used to expose transaction information to the runtime method
55
- * execution. This class has not all data included in transactions on purpose.
56
- * For example, we don't want to expose the signature or args as fields.
57
- */
58
- export declare class RuntimeTransaction extends RuntimeTransaction_base {
59
- static fromProtocolTransaction({ methodId, nonce, sender, argsHash, }: ProtocolTransaction): RuntimeTransaction;
60
- hash(): Field;
61
- }
62
- export {};
63
- //# sourceMappingURL=RuntimeTransaction.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RuntimeTransaction.d.ts","sourceRoot":"","sources":["../../../../../../protocol/src/model/transaction/RuntimeTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAY,SAAS,EAAU,MAAM,EAAE,MAAM,UAAU,CAAC;AAEtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE5D;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ,uBAKtC;WACc,uBAAuB,CAAC,EACpC,QAAQ,EACR,KAAK,EACL,MAAM,EACN,QAAQ,GACT,EAAE,mBAAmB,GAAG,kBAAkB;IASpC,IAAI,IAAI,KAAK;CAQrB"}
@@ -1,29 +0,0 @@
1
- import { Field, Poseidon, PublicKey, Struct, UInt64 } from "snarkyjs";
2
- /**
3
- * This struct is used to expose transaction information to the runtime method
4
- * execution. This class has not all data included in transactions on purpose.
5
- * For example, we don't want to expose the signature or args as fields.
6
- */
7
- export class RuntimeTransaction extends Struct({
8
- methodId: Field,
9
- nonce: UInt64,
10
- sender: PublicKey,
11
- argsHash: Field,
12
- }) {
13
- static fromProtocolTransaction({ methodId, nonce, sender, argsHash, }) {
14
- return new RuntimeTransaction({
15
- methodId,
16
- nonce,
17
- sender,
18
- argsHash,
19
- });
20
- }
21
- hash() {
22
- return Poseidon.hash([
23
- this.methodId,
24
- ...this.sender.toFields(),
25
- ...this.nonce.toFields(),
26
- this.argsHash,
27
- ]);
28
- }
29
- }
@@ -1,12 +0,0 @@
1
- import { Bool } from "snarkyjs";
2
- /**
3
- * Maintains an execution status of the current runtime module method,
4
- * while prioritizing one-time failures. The assertion won't change the
5
- * execution status if it has previously failed at least once within the
6
- * same method execution context.
7
- *
8
- * @param condition - Result of the assertion made about the execution status
9
- * @param message - Optional message describing the prior status
10
- */
11
- export declare function assert(condition: Bool, message?: string): void;
12
- //# sourceMappingURL=assert.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../../../../../protocol/src/state/assert/assert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAY,MAAM,UAAU,CAAC;AAO1C;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM,QAWvD"}
@@ -1,23 +0,0 @@
1
- import { Bool, Provable } from "snarkyjs";
2
- import { container } from "tsyringe";
3
- import { log } from "@proto-kit/common";
4
- import { RuntimeMethodExecutionContext } from "../context/RuntimeMethodExecutionContext";
5
- /**
6
- * Maintains an execution status of the current runtime module method,
7
- * while prioritizing one-time failures. The assertion won't change the
8
- * execution status if it has previously failed at least once within the
9
- * same method execution context.
10
- *
11
- * @param condition - Result of the assertion made about the execution status
12
- * @param message - Optional message describing the prior status
13
- */
14
- export function assert(condition, message) {
15
- const executionContext = container.resolve(RuntimeMethodExecutionContext);
16
- const previousStatus = executionContext.current().result.status;
17
- const status = Provable.if(previousStatus, Bool, condition, previousStatus);
18
- if (!condition.toBoolean()) {
19
- log.debug("Assertion failed: ", message);
20
- executionContext.setStatusMessage(message);
21
- }
22
- executionContext.setStatus(status);
23
- }
@@ -1,60 +0,0 @@
1
- import { Bool } from "snarkyjs";
2
- import { ProvableMethodExecutionContext, ProvableMethodExecutionResult } from "@proto-kit/common";
3
- import { StateTransition } from "../../model/StateTransition";
4
- import { RuntimeTransaction } from "../../model/transaction/RuntimeTransaction";
5
- import { NetworkState } from "../../model/network/NetworkState";
6
- export declare class RuntimeProvableMethodExecutionResult extends ProvableMethodExecutionResult {
7
- stateTransitions: StateTransition<any>[];
8
- status: Bool;
9
- statusMessage?: string;
10
- }
11
- export interface RuntimeMethodExecutionData {
12
- transaction: RuntimeTransaction;
13
- networkState: NetworkState;
14
- }
15
- /**
16
- * Execution context used to wrap runtime module methods,
17
- * allowing them to post relevant information (such as execution status)
18
- * into the context without any unnecessary 'prop drilling'.
19
- */
20
- export declare class RuntimeMethodExecutionContext extends ProvableMethodExecutionContext {
21
- methods: string[];
22
- input: RuntimeMethodExecutionData | undefined;
23
- private lastInput;
24
- result: RuntimeProvableMethodExecutionResult;
25
- private isSimulated;
26
- private assertSetupCalled;
27
- /**
28
- * Adds an in-method generated state transition to the current context
29
- * @param stateTransition - State transition to add to the context
30
- */
31
- addStateTransition<Value>(stateTransition: StateTransition<Value>): void;
32
- /**
33
- * @param message - Status message to acompany the current status
34
- */
35
- setStatusMessage(message?: string): void;
36
- /**
37
- * @param status - Execution status of the current method
38
- */
39
- setStatus(status: Bool): void;
40
- /**
41
- * @param input Input witness data required for a runtime execution
42
- */
43
- setup(input: RuntimeMethodExecutionData): void;
44
- setSimulated(simulated: boolean): void;
45
- /**
46
- * Manually clears/resets the execution context
47
- */
48
- clear(): void;
49
- afterMethod(): void;
50
- /**
51
- * Had to override current() otherwise it would not infer
52
- * the type of result correctly (parent type would be reused)
53
- */
54
- current(): {
55
- isFinished: boolean;
56
- result: RuntimeProvableMethodExecutionResult;
57
- input: RuntimeMethodExecutionData | undefined;
58
- };
59
- }
60
- //# sourceMappingURL=RuntimeMethodExecutionContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RuntimeMethodExecutionContext.d.ts","sourceRoot":"","sources":["../../../../../../protocol/src/state/context/RuntimeMethodExecutionContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,8BAA8B,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAShE,qBAAa,oCAAqC,SAAQ,6BAA6B;IAE9E,gBAAgB,EAAE,eAAe,CAAC,GAAG,CAAC,EAAE,CAAM;IAE9C,MAAM,EAAE,IAAI,CAAc;IAE1B,aAAa,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,0BAA0B;IACzC,WAAW,EAAE,kBAAkB,CAAC;IAChC,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED;;;;GAIG;AACH,qBACa,6BAA8B,SAAQ,8BAA8B;IACxE,OAAO,EAAE,MAAM,EAAE,CAAM;IAEvB,KAAK,EAAE,0BAA0B,GAAG,SAAS,CAAC;IAGrD,OAAO,CAAC,SAAS,CAAyC;IAE1C,MAAM,uCAA8C;IAEpE,OAAO,CAAC,WAAW,CAAkB;IAErC,OAAO,CAAC,iBAAiB;IAQzB;;;OAGG;IACI,kBAAkB,CAAC,KAAK,EAAE,eAAe,EAAE,eAAe,CAAC,KAAK,CAAC;IAKxE;;OAEG;IACI,gBAAgB,CAAC,OAAO,CAAC,EAAE,MAAM;IAQxC;;OAEG;IACI,SAAS,CAAC,MAAM,EAAE,IAAI;IAQ7B;;OAEG;IACI,KAAK,CAAC,KAAK,EAAE,0BAA0B;IAIvC,YAAY,CAAC,SAAS,EAAE,OAAO;IAItC;;OAEG;IACI,KAAK;IAIL,WAAW;IASlB;;;OAGG;IACI,OAAO;;;;;CAOf"}
@@ -1,105 +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
- import { Bool } from "snarkyjs";
8
- import { singleton } from "tsyringe";
9
- import { ProvableMethodExecutionContext, ProvableMethodExecutionResult } from "@proto-kit/common";
10
- const errors = {
11
- setupNotCalled: () => new Error("Setup has not been called prior to executing a runtime method. Be sure to do that so that the Runtime is setup property for execution"),
12
- };
13
- export class RuntimeProvableMethodExecutionResult extends ProvableMethodExecutionResult {
14
- constructor() {
15
- super(...arguments);
16
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
- this.stateTransitions = [];
18
- this.status = Bool(true);
19
- }
20
- }
21
- /**
22
- * Execution context used to wrap runtime module methods,
23
- * allowing them to post relevant information (such as execution status)
24
- * into the context without any unnecessary 'prop drilling'.
25
- */
26
- let RuntimeMethodExecutionContext = class RuntimeMethodExecutionContext extends ProvableMethodExecutionContext {
27
- constructor() {
28
- super(...arguments);
29
- this.methods = [];
30
- this.result = new RuntimeProvableMethodExecutionResult();
31
- this.isSimulated = false;
32
- }
33
- assertSetupCalled() {
34
- if (this.input === undefined) {
35
- throw errors.setupNotCalled();
36
- }
37
- }
38
- /**
39
- * Adds an in-method generated state transition to the current context
40
- * @param stateTransition - State transition to add to the context
41
- */
42
- addStateTransition(stateTransition) {
43
- this.assertSetupCalled();
44
- this.result.stateTransitions.push(stateTransition);
45
- }
46
- /**
47
- * @param message - Status message to acompany the current status
48
- */
49
- setStatusMessage(message) {
50
- var _a;
51
- this.assertSetupCalled();
52
- if (this.isSimulated) {
53
- return;
54
- }
55
- (_a = this.result).statusMessage ?? (_a.statusMessage = message);
56
- }
57
- /**
58
- * @param status - Execution status of the current method
59
- */
60
- setStatus(status) {
61
- this.assertSetupCalled();
62
- if (this.isSimulated) {
63
- return;
64
- }
65
- this.result.status = status;
66
- }
67
- /**
68
- * @param input Input witness data required for a runtime execution
69
- */
70
- setup(input) {
71
- this.input = input;
72
- }
73
- setSimulated(simulated) {
74
- this.isSimulated = simulated;
75
- }
76
- /**
77
- * Manually clears/resets the execution context
78
- */
79
- clear() {
80
- this.result = new RuntimeProvableMethodExecutionResult();
81
- }
82
- afterMethod() {
83
- super.afterMethod();
84
- if (this.isFinished) {
85
- this.lastInput = this.input;
86
- this.input = undefined;
87
- this.isSimulated = false;
88
- }
89
- }
90
- /**
91
- * Had to override current() otherwise it would not infer
92
- * the type of result correctly (parent type would be reused)
93
- */
94
- current() {
95
- return {
96
- isFinished: this.isFinished,
97
- result: this.result,
98
- input: this.lastInput,
99
- };
100
- }
101
- };
102
- RuntimeMethodExecutionContext = __decorate([
103
- singleton()
104
- ], RuntimeMethodExecutionContext);
105
- export { RuntimeMethodExecutionContext };
@@ -1,65 +0,0 @@
1
- import { Field, type FlexibleProvablePure } from "snarkyjs";
2
- import { Option, type Path } from "@proto-kit/protocol";
3
- import { PartialRuntime } from "../runtime/RuntimeModule.js";
4
- export declare class WithPath {
5
- path?: Field;
6
- hasPathOrFail(): asserts this is {
7
- path: Path;
8
- };
9
- }
10
- export declare class WithRuntime {
11
- runtime?: PartialRuntime;
12
- hasRuntimeOrFail(): asserts this is {
13
- runtime: PartialRuntime;
14
- };
15
- }
16
- declare const State_base: import("ts-mixer/dist/types/types.js").Class<any[], WithPath & WithRuntime, typeof WithPath & typeof WithRuntime, false>;
17
- /**
18
- * Utilities for runtime module state, such as get/set
19
- */
20
- export declare class State<Value> extends State_base {
21
- valueType: FlexibleProvablePure<Value>;
22
- /**
23
- * Creates a new state wrapper for the provided value type.
24
- *
25
- * @param valueType - Type of value to be stored (e.g. UInt64, Struct, ...)
26
- * @returns New state for the given value type.
27
- */
28
- static from<Value>(valueType: FlexibleProvablePure<Value>): State<Value>;
29
- /**
30
- * Computes a dummy value for the given value type.
31
- *
32
- * @param valueType - Value type to generate the dummy value for
33
- * @returns Dummy value for the given value type
34
- */
35
- static dummyValue<Value>(valueType: FlexibleProvablePure<Value>): Value;
36
- constructor(valueType: FlexibleProvablePure<Value>);
37
- /**
38
- * Provides an in-circuit witness for the current state representation,
39
- * and constructs an Option out of it.
40
- *
41
- * @returns Optional value of the current state
42
- */
43
- private witnessState;
44
- /**
45
- * Retrieves the current state and creates a state transition
46
- * anchoring the use of the current state value in the circuit.
47
- *
48
- * @returns Option representation of the current state.
49
- */
50
- get(): Option<Value>;
51
- /**
52
- * Sets a new state value by creating a state transition from
53
- * the current value to the newly set value.
54
- *
55
- * The newly set value isn't available via state.get(), since the
56
- * state transitions are not applied within the same circuit.
57
- * You can however store and access your new value in
58
- * a separate circuit variable.
59
- *
60
- * @param value - Value to be set as the current state
61
- */
62
- set(value: Value): void;
63
- }
64
- export {};
65
- //# sourceMappingURL=State.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../src/state/State.ts"],"names":[],"mappings":"AAGA,OAAO,EAAQ,KAAK,EAAY,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAE5E,OAAO,EAAE,MAAM,EAAmB,KAAK,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAEzE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAG7D,qBAAa,QAAQ;IACZ,IAAI,CAAC,EAAE,KAAK,CAAC;IAEb,aAAa,IAAI,OAAO,CAAC,IAAI,IAAI;QAAE,IAAI,EAAE,IAAI,CAAA;KAAE;CAOvD;AAED,qBAAa,WAAW;IACf,OAAO,CAAC,EAAE,cAAc,CAAC;IAEzB,gBAAgB,IAAI,OAAO,CAAC,IAAI,IAAI;QACzC,OAAO,EAAE,cAAc,CAAC;KACzB;CAOF;;AAED;;GAEG;AACH,qBAAa,KAAK,CAAC,KAAK,CAAE,SAAQ,UAA4B;IA2BlC,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IA1BhE;;;;;OAKG;WACW,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAIhE;;;;;OAKG;WACW,UAAU,CAAC,KAAK,EAC5B,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC,GACrC,KAAK;gBAQkB,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAIhE;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IA6BpB;;;;;OAKG;IACI,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC;IAc3B;;;;;;;;;;OAUG;IACI,GAAG,CAAC,KAAK,EAAE,KAAK;CAiBxB"}