@proto-kit/module 0.1.1-develop.254 → 0.1.1-develop.260

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.
@@ -1 +1 @@
1
- {"version":3,"file":"runtimeMethod.d.ts","sourceRoot":"","sources":["../../src/method/runtimeMethod.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,eAAe,EAGf,kBAAkB,EAEnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAIL,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAoBjE,wBAAgB,sBAAsB,CAEpC,gBAAgB,EAAE,eAAe,CAAC,GAAG,CAAC,EAAE,mDAczC;AAGD,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,kBAAkB,CAAC;AAEvE,wBAAgB,eAAe,CAC7B,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,EAC5B,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EAC7C,eAAe,EAAE,WAAW,EAAE,iBA0E/B;AAED,wBAAgB,iBAAiB,CAC/B,iBAAiB,EAAE,MAAM,EACzB,UAAU,EAAE,MAAM,UAGnB;AAED,eAAO,MAAM,wBAAwB,eAAe,CAAC;AACrD,eAAO,MAAM,6BAA6B,8BAA8B,CAAC;AAEzE;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAC9B,WAAW,EAAE,MAAM,WAKpB;AAED,wBAAgB,aAAa,aAEjB,cAAc,OAAO,CAAC,cAClB,MAAM,cACN,kBAAkB,UAwFjC"}
1
+ {"version":3,"file":"runtimeMethod.d.ts","sourceRoot":"","sources":["../../src/method/runtimeMethod.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,eAAe,EAGf,kBAAkB,EAEnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAIL,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAoBjE,wBAAgB,sBAAsB,CAEpC,gBAAgB,EAAE,eAAe,CAAC,GAAG,CAAC,EAAE,mDAczC;AAGD,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,kBAAkB,CAAC;AAEvE,wBAAgB,eAAe,CAC7B,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,EAC5B,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EAC7C,eAAe,EAAE,WAAW,EAAE,iBAoF/B;AAED,wBAAgB,iBAAiB,CAC/B,iBAAiB,EAAE,MAAM,EACzB,UAAU,EAAE,MAAM,UAGnB;AAED,eAAO,MAAM,wBAAwB,eAAe,CAAC;AACrD,eAAO,MAAM,6BAA6B,8BAA8B,CAAC;AAEzE;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAC9B,WAAW,EAAE,MAAM,WAKpB;AAED,wBAAgB,aAAa,aAEjB,cAAc,OAAO,CAAC,cAClB,MAAM,cACN,kBAAkB,UAwFjC"}
@@ -40,13 +40,17 @@ export function toWrappedMethod(methodName, moduleMethod, methodArguments) {
40
40
  throw errors.fieldNotConstant("methodId");
41
41
  }
42
42
  input.transaction.methodId.assertEquals(thisMethodId, "Runtimemethod called with wrong methodId on the transaction object");
43
+ const paramTypes = Reflect.getMetadata("design:paramtypes", this, methodName);
44
+ /**
45
+ * Use the type info obtained previously to convert
46
+ * the args passed to fields
47
+ */
48
+ const argsFields = args.flatMap((arg, index) => paramTypes[index].toFields(arg));
43
49
  // Assert that the argsHash that has been signed matches the given arguments
44
50
  // We can use js-if here, because methodArguments is statically sizes
45
51
  // i.e. the result of the if-statement will be the same for all executions
46
52
  // of this method
47
- const argsHash = methodArguments.length > 0
48
- ? Poseidon.hash(methodArguments.flatMap((argument) => argument.toFields()))
49
- : Field(0);
53
+ const argsHash = methodArguments.length > 0 ? Poseidon.hash(argsFields) : Field(0);
50
54
  input.transaction.argsHash.assertEquals(argsHash, "argsHash and therefore arguments of transaction and runtime call does not match");
51
55
  const transactionHash = input.transaction.hash();
52
56
  const networkStateHash = input.networkState.hash();
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@proto-kit/module",
3
3
  "license": "MIT",
4
4
  "private": false,
5
- "version": "0.1.1-develop.254+2fba72e",
5
+ "version": "0.1.1-develop.260+4c60192",
6
6
  "type": "module",
7
7
  "scripts": {
8
8
  "build": "tsc -p tsconfig.json",
@@ -31,5 +31,5 @@
31
31
  "snarkyjs": "0.12.0",
32
32
  "tsyringe": "^4.7.0"
33
33
  },
34
- "gitHead": "2fba72ec580c20289658d5c831430ca601ea5a71"
34
+ "gitHead": "4c60192291eba37f98698b538ae893afaef7e835"
35
35
  }
@@ -1,4 +1,4 @@
1
- import { Field, Poseidon } from "snarkyjs";
1
+ import { Field, FlexibleProvable, Poseidon } from "snarkyjs";
2
2
  import { container } from "tsyringe";
3
3
  import {
4
4
  StateTransition,
@@ -100,16 +100,26 @@ export function toWrappedMethod(
100
100
  "Runtimemethod called with wrong methodId on the transaction object"
101
101
  );
102
102
 
103
+ const paramTypes: FlexibleProvable<unknown>[] = Reflect.getMetadata(
104
+ "design:paramtypes",
105
+ this,
106
+ methodName
107
+ );
108
+
109
+ /**
110
+ * Use the type info obtained previously to convert
111
+ * the args passed to fields
112
+ */
113
+ const argsFields = args.flatMap((arg, index) =>
114
+ paramTypes[index].toFields(arg as any)
115
+ );
116
+
103
117
  // Assert that the argsHash that has been signed matches the given arguments
104
118
  // We can use js-if here, because methodArguments is statically sizes
105
119
  // i.e. the result of the if-statement will be the same for all executions
106
120
  // of this method
107
121
  const argsHash =
108
- methodArguments.length > 0
109
- ? Poseidon.hash(
110
- methodArguments.flatMap((argument) => argument.toFields())
111
- )
112
- : Field(0);
122
+ methodArguments.length > 0 ? Poseidon.hash(argsFields) : Field(0);
113
123
 
114
124
  input.transaction.argsHash.assertEquals(
115
125
  argsHash,