@proto-kit/common 0.1.1-develop.191 → 0.1.1-develop.211

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,11 @@
1
+ import { FlexibleProvablePure } from "snarkyjs";
1
2
  export declare function requireTrue(condition: boolean, errorOrFunction: Error | (() => Error)): void;
2
3
  export declare function range(startOrEnd: number, end: number | undefined): number[];
4
+ /**
5
+ * Computes a dummy value for the given value type.
6
+ *
7
+ * @param valueType - Value type to generate the dummy value for
8
+ * @returns Dummy value for the given value type
9
+ */
10
+ export declare function dummyValue<Value>(valueType: FlexibleProvablePure<Value>): Value;
3
11
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CACzB,SAAS,EAAE,OAAO,EAClB,eAAe,EAAE,KAAK,GAAG,CAAC,MAAM,KAAK,CAAC,GACrC,IAAI,CAMN;AAED,wBAAgB,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,CAM3E"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAEzE,wBAAgB,WAAW,CACzB,SAAS,EAAE,OAAO,EAClB,eAAe,EAAE,KAAK,GAAG,CAAC,MAAM,KAAK,CAAC,GACrC,IAAI,CAMN;AAED,wBAAgB,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,CAM3E;AAGD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAC9B,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC,GACrC,KAAK,CAMP"}
package/dist/utils.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { Field } from "snarkyjs";
1
2
  export function requireTrue(condition, errorOrFunction) {
2
3
  if (!condition) {
3
4
  throw typeof errorOrFunction === "function"
@@ -12,3 +13,15 @@ export function range(startOrEnd, end) {
12
13
  }
13
14
  return Array.from({ length: end - startOrEnd }, (ignored, index) => index);
14
15
  }
16
+ /**
17
+ * Computes a dummy value for the given value type.
18
+ *
19
+ * @param valueType - Value type to generate the dummy value for
20
+ * @returns Dummy value for the given value type
21
+ */
22
+ export function dummyValue(valueType) {
23
+ const length = valueType.sizeInFields();
24
+ const fields = Array.from({ length }, () => Field(0));
25
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
26
+ return valueType.fromFields(fields);
27
+ }
@@ -1,5 +1,5 @@
1
1
  import { ProvableMethodExecutionContext } from "./ProvableMethodExecutionContext";
2
- import type { ZkProgrammable } from "./ZkProgrammable";
2
+ import type { WithZkProgrammable, ZkProgrammable } from "./ZkProgrammable";
3
3
  export type DecoratedMethod = (...args: unknown[]) => unknown;
4
4
  export declare const mockProof = "mock-proof";
5
5
  export declare function toProver(methodName: string, simulatedMethod: DecoratedMethod, isFirstParameterPublicInput: boolean, ...args: unknown[]): (this: ZkProgrammable<any, any>) => Promise<import("snarkyjs/dist/node/lib/proof_system").Proof<any, any>>;
@@ -12,5 +12,5 @@ export declare function toProver(methodName: string, simulatedMethod: DecoratedM
12
12
  * @param executionContext
13
13
  * @returns
14
14
  */
15
- export declare function provableMethod(isFirstParameterPublicInput?: boolean, executionContext?: ProvableMethodExecutionContext): <Target extends ZkProgrammable<any, any>>(target: Target, methodName: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
15
+ export declare function provableMethod(isFirstParameterPublicInput?: boolean, executionContext?: ProvableMethodExecutionContext): <Target extends ZkProgrammable<any, any> | WithZkProgrammable<any, any>>(target: Target, methodName: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
16
16
  //# sourceMappingURL=provableMethod.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"provableMethod.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/provableMethod.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGvD,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;AAE9D,eAAO,MAAM,SAAS,eAAe,CAAC;AAEtC,wBAAgB,QAAQ,CACtB,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,eAAe,EAChC,2BAA2B,EAAE,OAAO,EACpC,GAAG,IAAI,EAAE,OAAO,EAAE,UAGiB,eAAe,GAAG,EAAE,GAAG,CAAC,4EAyB5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,2BAA2B,UAAO,EAClC,gBAAgB,GAAE,8BAEjB,yEAKa,MAAM,cACN,kBAAkB,wBA4CjC"}
1
+ {"version":3,"file":"provableMethod.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/provableMethod.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAG3E,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;AAE9D,eAAO,MAAM,SAAS,eAAe,CAAC;AAEtC,wBAAgB,QAAQ,CACtB,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,eAAe,EAChC,2BAA2B,EAAE,OAAO,EACpC,GAAG,IAAI,EAAE,OAAO,EAAE,UAGiB,eAAe,GAAG,EAAE,GAAG,CAAC,4EAyB5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,2BAA2B,UAAO,EAClC,gBAAgB,GAAE,8BAEjB,wGAOa,MAAM,cACN,kBAAkB,wBA4CjC"}
@@ -35,7 +35,6 @@ export function toProver(methodName, simulatedMethod, isFirstParameterPublicInpu
35
35
  * @returns
36
36
  */
37
37
  export function provableMethod(isFirstParameterPublicInput = true, executionContext = container.resolve(ProvableMethodExecutionContext)) {
38
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
38
  return (target, methodName, descriptor) => {
40
39
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
41
40
  const simulatedMethod = descriptor.value;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "license": "MIT",
4
4
  "private": false,
5
5
  "type": "module",
6
- "version": "0.1.1-develop.191+554ba10",
6
+ "version": "0.1.1-develop.211+662735c",
7
7
  "scripts": {
8
8
  "build": "tsc -p tsconfig.json",
9
9
  "dev": "tsc -p tsconfig.json --watch",
@@ -30,5 +30,5 @@
30
30
  "@jest/globals": "^29.5.0",
31
31
  "@types/lodash": "^4.14.194"
32
32
  },
33
- "gitHead": "554ba102c48f41a62409ff01354582567ef4124a"
33
+ "gitHead": "662735cd072170aa01a9f6040e89293a3e3fc8a9"
34
34
  }
package/src/utils.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { Field, FlexibleProvable, FlexibleProvablePure } from "snarkyjs";
2
+
1
3
  export function requireTrue(
2
4
  condition: boolean,
3
5
  errorOrFunction: Error | (() => Error)
@@ -16,3 +18,20 @@ export function range(startOrEnd: number, end: number | undefined): number[] {
16
18
  }
17
19
  return Array.from({ length: end - startOrEnd }, (ignored, index) => index);
18
20
  }
21
+
22
+
23
+ /**
24
+ * Computes a dummy value for the given value type.
25
+ *
26
+ * @param valueType - Value type to generate the dummy value for
27
+ * @returns Dummy value for the given value type
28
+ */
29
+ export function dummyValue<Value>(
30
+ valueType: FlexibleProvablePure<Value>
31
+ ): Value {
32
+ const length = valueType.sizeInFields();
33
+ const fields = Array.from({ length }, () => Field(0));
34
+
35
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
36
+ return valueType.fromFields(fields) as Value;
37
+ }
@@ -2,7 +2,7 @@ import { FlexibleProvable } from "snarkyjs";
2
2
  import { container } from "tsyringe";
3
3
 
4
4
  import { ProvableMethodExecutionContext } from "./ProvableMethodExecutionContext";
5
- import type { ZkProgrammable } from "./ZkProgrammable";
5
+ import type { WithZkProgrammable, ZkProgrammable } from "./ZkProgrammable";
6
6
 
7
7
  // eslint-disable-next-line etc/prefer-interface
8
8
  export type DecoratedMethod = (...args: unknown[]) => unknown;
@@ -58,8 +58,10 @@ export function provableMethod(
58
58
  ProvableMethodExecutionContext
59
59
  )
60
60
  ) {
61
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
62
- return <Target extends ZkProgrammable<any, any>>(
61
+ return <
62
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
+ Target extends WithZkProgrammable<any, any> | ZkProgrammable<any, any>
64
+ >(
63
65
  target: Target,
64
66
  methodName: string,
65
67
  descriptor: PropertyDescriptor