@proto-kit/module 0.1.1-develop.245 → 0.1.1-develop.254
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/method/runtimeMethod.d.ts +2 -1
- package/dist/method/runtimeMethod.d.ts.map +1 -1
- package/dist/method/runtimeMethod.js +29 -3
- package/package.json +2 -2
- package/src/method/runtimeMethod.ts +58 -5
- package/test/modules/Balances.test.ts +4 -8
- package/test/modules/Balances.ts +2 -5
- package/test/modules/State.test.ts +8 -3
- package/test/runtimeMethod.test.ts +55 -6
- package/test/transaction.test.ts +1 -1
- package/dist/method/RuntimeMethodExecutionContext.d.ts +0 -57
- package/dist/method/RuntimeMethodExecutionContext.d.ts.map +0 -1
- package/dist/method/RuntimeMethodExecutionContext.js +0 -92
- package/dist/method/assert.d.ts +0 -12
- package/dist/method/assert.d.ts.map +0 -1
- package/dist/method/assert.js +0 -23
- package/dist/module/src/factories/MethodIdFactory.d.ts +0 -9
- package/dist/module/src/factories/MethodIdFactory.d.ts.map +0 -1
- package/dist/module/src/factories/MethodIdFactory.js +0 -36
- package/dist/module/src/index.d.ts +0 -11
- package/dist/module/src/index.d.ts.map +0 -1
- package/dist/module/src/index.js +0 -10
- package/dist/module/src/method/MethodParameterDecoder.d.ts +0 -22
- package/dist/module/src/method/MethodParameterDecoder.d.ts.map +0 -1
- package/dist/module/src/method/MethodParameterDecoder.js +0 -33
- package/dist/module/src/method/runtimeMethod.d.ts +0 -19
- package/dist/module/src/method/runtimeMethod.d.ts.map +0 -1
- package/dist/module/src/method/runtimeMethod.js +0 -123
- package/dist/module/src/module/decorator.d.ts +0 -8
- package/dist/module/src/module/decorator.d.ts.map +0 -1
- package/dist/module/src/module/decorator.js +0 -15
- package/dist/module/src/runtime/MethodIdResolver.d.ts +0 -18
- package/dist/module/src/runtime/MethodIdResolver.d.ts.map +0 -1
- package/dist/module/src/runtime/MethodIdResolver.js +0 -50
- package/dist/module/src/runtime/Runtime.d.ts +0 -72
- package/dist/module/src/runtime/Runtime.d.ts.map +0 -1
- package/dist/module/src/runtime/Runtime.js +0 -184
- package/dist/module/src/runtime/RuntimeModule.d.ts +0 -34
- package/dist/module/src/runtime/RuntimeModule.d.ts.map +0 -1
- package/dist/module/src/runtime/RuntimeModule.js +0 -56
- package/dist/module/src/state/InMemoryStateService.d.ts +0 -11
- package/dist/module/src/state/InMemoryStateService.d.ts.map +0 -1
- package/dist/module/src/state/InMemoryStateService.js +0 -21
- package/dist/module/src/state/decorator.d.ts +0 -7
- package/dist/module/src/state/decorator.d.ts.map +0 -1
- package/dist/module/src/state/decorator.js +0 -42
- package/dist/protocol/src/model/Option.d.ts +0 -98
- package/dist/protocol/src/model/Option.d.ts.map +0 -1
- package/dist/protocol/src/model/Option.js +0 -98
- package/dist/protocol/src/model/StateTransition.d.ts +0 -96
- package/dist/protocol/src/model/StateTransition.d.ts.map +0 -1
- package/dist/protocol/src/model/StateTransition.js +0 -65
- package/dist/protocol/src/model/network/NetworkState.d.ts +0 -64
- package/dist/protocol/src/model/network/NetworkState.d.ts.map +0 -1
- package/dist/protocol/src/model/network/NetworkState.js +0 -12
- package/dist/protocol/src/model/transaction/ProtocolTransaction.d.ts +0 -70
- package/dist/protocol/src/model/transaction/ProtocolTransaction.d.ts.map +0 -1
- package/dist/protocol/src/model/transaction/ProtocolTransaction.js +0 -18
- package/dist/protocol/src/model/transaction/RuntimeTransaction.d.ts +0 -63
- package/dist/protocol/src/model/transaction/RuntimeTransaction.d.ts.map +0 -1
- package/dist/protocol/src/model/transaction/RuntimeTransaction.js +0 -29
- package/dist/protocol/src/state/assert/assert.d.ts +0 -12
- package/dist/protocol/src/state/assert/assert.d.ts.map +0 -1
- package/dist/protocol/src/state/assert/assert.js +0 -23
- package/dist/protocol/src/state/context/RuntimeMethodExecutionContext.d.ts +0 -60
- package/dist/protocol/src/state/context/RuntimeMethodExecutionContext.d.ts.map +0 -1
- package/dist/protocol/src/state/context/RuntimeMethodExecutionContext.js +0 -105
- package/dist/state/State.d.ts +0 -65
- package/dist/state/State.d.ts.map +0 -1
- package/dist/state/State.js +0 -114
- package/dist/state/StateMap.d.ts +0 -37
- package/dist/state/StateMap.d.ts.map +0 -1
- package/dist/state/StateMap.js +0 -56
- package/dist/state/StateServiceProvider.d.ts +0 -10
- package/dist/state/StateServiceProvider.d.ts.map +0 -1
- package/dist/state/StateServiceProvider.js +0 -34
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MethodParameterDecoder.d.ts","sourceRoot":"","sources":["../../../../src/method/MethodParameterDecoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,KAAK,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;IAC7B,UAAU,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,SAAS,CAAC;IAC3C,IAAI,EAAE,MAAM,CAAC;IAEb,SAAS,EAAE;QACT,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;KACjB,CAAC;IACF,YAAY,CAAC,EAAE,MAAM,MAAM,CAAC;CAC7B;AAYD,qBAAa,sBAAsB;IAWb,OAAO,CAAC,QAAQ,CAAC,KAAK;WAV5B,UAAU,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,MAAM;IAU3E,OAAO;IAEA,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,SAAS,EAAE;IAmB/C,IAAW,SAAS,IAAI,MAAM,CAM7B;CACF"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
const errors = {
|
|
2
|
-
fieldLengthNotMatching: (expected, actual) => new Error(`Expected ${expected} field elements, got ${actual}`),
|
|
3
|
-
typeNotCompatible: (name) => new Error(`Cannot decode type ${name}, it has to be either a Struct, CircuitValue or built-in snarkyjs type`),
|
|
4
|
-
};
|
|
5
|
-
export class MethodParameterDecoder {
|
|
6
|
-
static fromMethod(target, methodName) {
|
|
7
|
-
const paramtypes = Reflect.getMetadata("design:paramtypes", target, methodName);
|
|
8
|
-
return new MethodParameterDecoder(paramtypes);
|
|
9
|
-
}
|
|
10
|
-
constructor(types) {
|
|
11
|
-
this.types = types;
|
|
12
|
-
}
|
|
13
|
-
fromFields(fields) {
|
|
14
|
-
if (fields.length < this.fieldSize) {
|
|
15
|
-
throw errors.fieldLengthNotMatching(this.fieldSize, fields.length);
|
|
16
|
-
}
|
|
17
|
-
let stack = fields.slice();
|
|
18
|
-
return this.types.map((type) => {
|
|
19
|
-
const numberFieldsNeeded = type.prototype._fields?.length ?? type.sizeInFields?.() ?? -1;
|
|
20
|
-
if (numberFieldsNeeded === -1) {
|
|
21
|
-
throw errors.typeNotCompatible(type.name);
|
|
22
|
-
}
|
|
23
|
-
const structFields = stack.slice(0, numberFieldsNeeded);
|
|
24
|
-
stack = stack.slice(numberFieldsNeeded);
|
|
25
|
-
return type.fromFields(structFields);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
get fieldSize() {
|
|
29
|
-
return this.types
|
|
30
|
-
.map((type) => type.prototype._fields?.length ?? type.sizeInFields?.() ?? 0)
|
|
31
|
-
.reduce((a, b) => a + b, 0);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { StateTransition, MethodPublicOutput } from "@proto-kit/protocol";
|
|
2
|
-
import type { RuntimeModule } from "../runtime/RuntimeModule.js";
|
|
3
|
-
export declare function toStateTransitionsHash(stateTransitions: StateTransition<any>[]): import("snarkyjs/dist/node/lib/field.js").Field;
|
|
4
|
-
export type WrappedMethod = (...args: unknown[]) => MethodPublicOutput;
|
|
5
|
-
export declare function toWrappedMethod(this: RuntimeModule<unknown>, methodName: string, moduleMethod: (...args: unknown[]) => unknown): WrappedMethod;
|
|
6
|
-
export declare function combineMethodName(runtimeModuleName: string, methodName: string): string;
|
|
7
|
-
export declare const runtimeMethodMetadataKey = "yab-method";
|
|
8
|
-
export declare const runtimeMethodNamesMetadataKey = "proto-kit-runtime-methods";
|
|
9
|
-
/**
|
|
10
|
-
* Checks the metadata of the provided runtime module and its method,
|
|
11
|
-
* to see if it has been decorated with @runtimeMethod()
|
|
12
|
-
*
|
|
13
|
-
* @param target - Runtime module to check
|
|
14
|
-
* @param propertyKey - Name of the method to check in the prior runtime module
|
|
15
|
-
* @returns - If the provided method name is a runtime method or not
|
|
16
|
-
*/
|
|
17
|
-
export declare function isRuntimeMethod(target: RuntimeModule<unknown>, propertyKey: string): boolean;
|
|
18
|
-
export declare function runtimeMethod(): (target: RuntimeModule<unknown>, methodName: string, descriptor: PropertyDescriptor) => void;
|
|
19
|
-
//# sourceMappingURL=runtimeMethod.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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;AAG7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAYjE,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,iBAoC9C;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,UAuFjC"}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { container } from "tsyringe";
|
|
2
|
-
import { DefaultProvableHashList, ProvableStateTransition, MethodPublicOutput, RuntimeMethodExecutionContext } from "@proto-kit/protocol";
|
|
3
|
-
import { toProver } from "@proto-kit/common";
|
|
4
|
-
const errors = {
|
|
5
|
-
runtimeNotProvided: (name) => new Error(`Runtime was not provided for module: ${name}`),
|
|
6
|
-
methodInputsNotProvided: () => new Error("Method execution inputs not provided, provide them via context.inputs"),
|
|
7
|
-
};
|
|
8
|
-
export function toStateTransitionsHash(
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
-
stateTransitions) {
|
|
11
|
-
const stateTransitionsHashList = new DefaultProvableHashList(ProvableStateTransition);
|
|
12
|
-
return stateTransitions
|
|
13
|
-
.map((stateTransition) => stateTransition.toProvable())
|
|
14
|
-
.reduce((allStateTransitionsHashList, stateTransition) => allStateTransitionsHashList.push(stateTransition), stateTransitionsHashList)
|
|
15
|
-
.toField();
|
|
16
|
-
}
|
|
17
|
-
export function toWrappedMethod(methodName, moduleMethod) {
|
|
18
|
-
const executionContext = container.resolve(RuntimeMethodExecutionContext);
|
|
19
|
-
const wrappedMethod = (...args) => {
|
|
20
|
-
Reflect.apply(moduleMethod, this, args);
|
|
21
|
-
const { result: { stateTransitions, status }, input, } = executionContext.current();
|
|
22
|
-
const stateTransitionsHash = toStateTransitionsHash(stateTransitions);
|
|
23
|
-
if (input === undefined) {
|
|
24
|
-
throw errors.methodInputsNotProvided();
|
|
25
|
-
}
|
|
26
|
-
const transactionHash = input.transaction.hash();
|
|
27
|
-
const networkStateHash = input.networkState.hash();
|
|
28
|
-
return new MethodPublicOutput({
|
|
29
|
-
stateTransitionsHash,
|
|
30
|
-
status,
|
|
31
|
-
transactionHash,
|
|
32
|
-
networkStateHash,
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
Object.defineProperty(wrappedMethod, "name", {
|
|
36
|
-
value: `wrapped_${methodName}`,
|
|
37
|
-
writable: false,
|
|
38
|
-
});
|
|
39
|
-
return wrappedMethod;
|
|
40
|
-
}
|
|
41
|
-
export function combineMethodName(runtimeModuleName, methodName) {
|
|
42
|
-
return `${runtimeModuleName}.${methodName}`;
|
|
43
|
-
}
|
|
44
|
-
export const runtimeMethodMetadataKey = "yab-method";
|
|
45
|
-
export const runtimeMethodNamesMetadataKey = "proto-kit-runtime-methods";
|
|
46
|
-
/**
|
|
47
|
-
* Checks the metadata of the provided runtime module and its method,
|
|
48
|
-
* to see if it has been decorated with @runtimeMethod()
|
|
49
|
-
*
|
|
50
|
-
* @param target - Runtime module to check
|
|
51
|
-
* @param propertyKey - Name of the method to check in the prior runtime module
|
|
52
|
-
* @returns - If the provided method name is a runtime method or not
|
|
53
|
-
*/
|
|
54
|
-
export function isRuntimeMethod(target, propertyKey) {
|
|
55
|
-
return Boolean(Reflect.getMetadata(runtimeMethodMetadataKey, target, propertyKey));
|
|
56
|
-
}
|
|
57
|
-
export function runtimeMethod() {
|
|
58
|
-
return (target, methodName, descriptor) => {
|
|
59
|
-
const executionContext = container.resolve(RuntimeMethodExecutionContext);
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
61
|
-
let data = Reflect.getMetadata(runtimeMethodNamesMetadataKey, target);
|
|
62
|
-
if (data !== undefined) {
|
|
63
|
-
data.push(methodName);
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
data = [methodName];
|
|
67
|
-
}
|
|
68
|
-
Reflect.defineMetadata(runtimeMethodNamesMetadataKey, data, target);
|
|
69
|
-
Reflect.defineMetadata(runtimeMethodMetadataKey, true, target, methodName);
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
71
|
-
const simulatedMethod = descriptor.value;
|
|
72
|
-
descriptor.value = function value(...args) {
|
|
73
|
-
const constructorName = this.constructor.name;
|
|
74
|
-
/**
|
|
75
|
-
* If its a top level method call, wrap it into a wrapped method,
|
|
76
|
-
* since it'll be turned into a real/mock prover in provableMethod().
|
|
77
|
-
*
|
|
78
|
-
* Otherwise provableMethod() will just call the originalMethod provided
|
|
79
|
-
* if method is not called at the top level.
|
|
80
|
-
*/
|
|
81
|
-
const simulatedWrappedMethod = Reflect.apply(toWrappedMethod, this, [
|
|
82
|
-
methodName,
|
|
83
|
-
simulatedMethod,
|
|
84
|
-
]);
|
|
85
|
-
/**
|
|
86
|
-
* Before the prover runs, make sure it is operating on the correct
|
|
87
|
-
* RuntimeMethodExecutionContext state, meaning it enters and exits
|
|
88
|
-
* the context properly.
|
|
89
|
-
*/
|
|
90
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
91
|
-
async function prover() {
|
|
92
|
-
executionContext.beforeMethod(constructorName, methodName, args);
|
|
93
|
-
const innerProver = toProver(combineMethodName(constructorName, methodName), simulatedWrappedMethod, false, ...args).bind(this);
|
|
94
|
-
// eslint-disable-next-line @typescript-eslint/init-declarations
|
|
95
|
-
let result;
|
|
96
|
-
try {
|
|
97
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
98
|
-
result = await Reflect.apply(innerProver, this, args);
|
|
99
|
-
}
|
|
100
|
-
finally {
|
|
101
|
-
executionContext.afterMethod();
|
|
102
|
-
}
|
|
103
|
-
return result;
|
|
104
|
-
}
|
|
105
|
-
executionContext.beforeMethod(constructorName, methodName, args);
|
|
106
|
-
if (executionContext.isTopLevel) {
|
|
107
|
-
if (!this.runtime) {
|
|
108
|
-
throw errors.runtimeNotProvided(constructorName);
|
|
109
|
-
}
|
|
110
|
-
executionContext.setProver(prover.bind(this.runtime.zkProgrammable));
|
|
111
|
-
}
|
|
112
|
-
// eslint-disable-next-line @typescript-eslint/init-declarations
|
|
113
|
-
let result;
|
|
114
|
-
try {
|
|
115
|
-
result = Reflect.apply(simulatedMethod, this, args);
|
|
116
|
-
}
|
|
117
|
-
finally {
|
|
118
|
-
executionContext.afterMethod();
|
|
119
|
-
}
|
|
120
|
-
return result;
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { StaticConfigurableModule, TypedClass } from "@proto-kit/common";
|
|
2
|
-
import { RuntimeModule } from "../runtime/RuntimeModule.js";
|
|
3
|
-
/**
|
|
4
|
-
* Marks the decorated class as a runtime module, while also
|
|
5
|
-
* making it injectable with our dependency injection solution.
|
|
6
|
-
*/
|
|
7
|
-
export declare function runtimeModule(): (target: StaticConfigurableModule<unknown> & TypedClass<RuntimeModule<unknown>>) => void;
|
|
8
|
-
//# sourceMappingURL=decorator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decorator.d.ts","sourceRoot":"","sources":["../../../../src/module/decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEzE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D;;;GAGG;AACH,wBAAgB,aAAa,aAMjB,yBAAyB,OAAO,CAAC,GACvC,WAAW,cAAc,OAAO,CAAC,CAAC,UAIvC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { injectable } from "tsyringe";
|
|
2
|
-
/**
|
|
3
|
-
* Marks the decorated class as a runtime module, while also
|
|
4
|
-
* making it injectable with our dependency injection solution.
|
|
5
|
-
*/
|
|
6
|
-
export function runtimeModule() {
|
|
7
|
-
return (
|
|
8
|
-
/**
|
|
9
|
-
* Check if the target class extends RuntimeModule, while
|
|
10
|
-
* also providing static config presets
|
|
11
|
-
*/
|
|
12
|
-
target) => {
|
|
13
|
-
injectable()(target);
|
|
14
|
-
};
|
|
15
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Runtime, RuntimeModulesRecord } from "./Runtime";
|
|
2
|
-
/**
|
|
3
|
-
* How do we encode MethodIds
|
|
4
|
-
* A MethodId is defined as the following in little-endian
|
|
5
|
-
* [0
|
|
6
|
-
* ...hash(stringToField(moduleName))[0..128],
|
|
7
|
-
* ...hash(stringToField(methodName))[0..128]
|
|
8
|
-
* ]
|
|
9
|
-
*/
|
|
10
|
-
export declare class MethodIdResolver {
|
|
11
|
-
private readonly runtime;
|
|
12
|
-
private readonly modules;
|
|
13
|
-
private readonly dictionary;
|
|
14
|
-
constructor(runtime: Runtime<RuntimeModulesRecord>, modules: RuntimeModulesRecord);
|
|
15
|
-
getMethodNameFromId(methodId: bigint): [string, string] | undefined;
|
|
16
|
-
getMethodId(moduleName: string, methodName: string): bigint;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=MethodIdResolver.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MethodIdResolver.d.ts","sourceRoot":"","sources":["../../../../src/runtime/MethodIdResolver.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAM/D;;;;;;;GAOG;AACH,qBAAa,gBAAgB;IAIzB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJ1B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiC;gBAGzC,OAAO,EAAE,OAAO,CAAC,oBAAoB,CAAC,EACtC,OAAO,EAAE,oBAAoB;IAmBzC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS;IAsBnE,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM;CAQnE"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { singleFieldToString, stringToField } from "@proto-kit/protocol";
|
|
2
|
-
const offset = 128n;
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
4
|
-
const modulus = 2n ** (offset - 1n);
|
|
5
|
-
/**
|
|
6
|
-
* How do we encode MethodIds
|
|
7
|
-
* A MethodId is defined as the following in little-endian
|
|
8
|
-
* [0
|
|
9
|
-
* ...hash(stringToField(moduleName))[0..128],
|
|
10
|
-
* ...hash(stringToField(methodName))[0..128]
|
|
11
|
-
* ]
|
|
12
|
-
*/
|
|
13
|
-
export class MethodIdResolver {
|
|
14
|
-
constructor(runtime, modules) {
|
|
15
|
-
this.runtime = runtime;
|
|
16
|
-
this.modules = modules;
|
|
17
|
-
this.dictionary = {};
|
|
18
|
-
this.dictionary = runtime.runtimeModuleNames.reduce((dict, moduleName) => {
|
|
19
|
-
this.runtime.assertIsValidModuleName(modules, moduleName);
|
|
20
|
-
dict[(stringToField(moduleName).toBigInt() % modulus).toString()] =
|
|
21
|
-
moduleName;
|
|
22
|
-
runtime.resolve(moduleName).runtimeMethodNames.forEach((methodName) => {
|
|
23
|
-
dict[(stringToField(methodName).toBigInt() % modulus).toString()] =
|
|
24
|
-
methodName;
|
|
25
|
-
});
|
|
26
|
-
return dict;
|
|
27
|
-
}, {});
|
|
28
|
-
}
|
|
29
|
-
getMethodNameFromId(methodId) {
|
|
30
|
-
const moduleNameHash = singleFieldToString(methodId >> offset);
|
|
31
|
-
const methodNameHash = singleFieldToString(methodId % modulus);
|
|
32
|
-
const moduleName = this.dictionary[moduleNameHash];
|
|
33
|
-
// eslint-disable-next-line no-warning-comments
|
|
34
|
-
// TODO Replace by throwing exception?
|
|
35
|
-
if (moduleName === undefined) {
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
this.runtime.assertIsValidModuleName(this.modules, moduleName);
|
|
39
|
-
const methodName = this.dictionary[methodNameHash];
|
|
40
|
-
if (methodName === undefined) {
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
return [moduleName, methodName];
|
|
44
|
-
}
|
|
45
|
-
getMethodId(moduleName, methodName) {
|
|
46
|
-
this.runtime.assertIsValidModuleName(this.modules, moduleName);
|
|
47
|
-
return ((stringToField(moduleName).toBigInt() % modulus << offset) +
|
|
48
|
-
(stringToField(methodName).toBigInt() % modulus));
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { Experimental } from "snarkyjs";
|
|
2
|
-
import { DependencyContainer } from "tsyringe";
|
|
3
|
-
import { StringKeyOf, ModuleContainer, ModulesConfig, ModulesRecord, TypedClass, ZkProgrammable, PlainZkProgram, WithZkProgrammable, AreProofsEnabled } from "@proto-kit/common";
|
|
4
|
-
import { MethodPublicOutput, StateServiceProvider, StateService } from "@proto-kit/protocol";
|
|
5
|
-
import { RuntimeModule } from "./RuntimeModule";
|
|
6
|
-
/**
|
|
7
|
-
* Record of modules accepted by the Runtime module container.
|
|
8
|
-
*
|
|
9
|
-
* We have to use TypedClass since RuntimeModule
|
|
10
|
-
* is an abstract class
|
|
11
|
-
*/
|
|
12
|
-
export type RuntimeModulesRecord = ModulesRecord<TypedClass<RuntimeModule<unknown>>>;
|
|
13
|
-
/**
|
|
14
|
-
* Definition / required arguments for the Runtime class
|
|
15
|
-
*/
|
|
16
|
-
export interface RuntimeDefinition<Modules extends RuntimeModulesRecord> {
|
|
17
|
-
/**
|
|
18
|
-
* @deprecated
|
|
19
|
-
*/
|
|
20
|
-
state?: StateService;
|
|
21
|
-
modules: Modules;
|
|
22
|
-
config?: ModulesConfig<Modules>;
|
|
23
|
-
}
|
|
24
|
-
export declare class RuntimeZkProgrammable<Modules extends RuntimeModulesRecord> extends ZkProgrammable<undefined, MethodPublicOutput> {
|
|
25
|
-
runtime: Runtime<Modules>;
|
|
26
|
-
constructor(runtime: Runtime<Modules>);
|
|
27
|
-
get appChain(): AreProofsEnabled | undefined;
|
|
28
|
-
zkProgramFactory(): PlainZkProgram<undefined, MethodPublicOutput>;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Wrapper for an application specific runtime, which helps orchestrate
|
|
32
|
-
* runtime modules into an interoperable runtime.
|
|
33
|
-
*/
|
|
34
|
-
export declare class Runtime<Modules extends RuntimeModulesRecord> extends ModuleContainer<Modules> implements WithZkProgrammable<undefined, MethodPublicOutput> {
|
|
35
|
-
static from<Modules extends RuntimeModulesRecord>(definition: RuntimeDefinition<Modules>): Runtime<Modules>;
|
|
36
|
-
program?: ReturnType<typeof Experimental.ZkProgram>;
|
|
37
|
-
definition: RuntimeDefinition<Modules>;
|
|
38
|
-
zkProgrammable: ZkProgrammable<undefined, MethodPublicOutput>;
|
|
39
|
-
private readonly stateServiceProviderInstance;
|
|
40
|
-
/**
|
|
41
|
-
* Creates a new Runtime from the provided config
|
|
42
|
-
*
|
|
43
|
-
* @param modules - Configuration object for the constructed Runtime
|
|
44
|
-
*/
|
|
45
|
-
constructor(definition: RuntimeDefinition<Modules>);
|
|
46
|
-
start(): void;
|
|
47
|
-
get appChain(): AreProofsEnabled | undefined;
|
|
48
|
-
get stateService(): StateService;
|
|
49
|
-
get stateServiceProvider(): StateServiceProvider;
|
|
50
|
-
/**
|
|
51
|
-
* @returns The dependency injection container of this runtime
|
|
52
|
-
*/
|
|
53
|
-
get dependencyContainer(): DependencyContainer;
|
|
54
|
-
/**
|
|
55
|
-
* @param methodId The encoded name of the method to call.
|
|
56
|
-
* Encoding: "stringToField(module.name) << 128 + stringToField(method-name)"
|
|
57
|
-
*/
|
|
58
|
-
getMethodById(methodId: bigint): ((...args: unknown[]) => unknown) | undefined;
|
|
59
|
-
/**
|
|
60
|
-
* Add a name and other respective properties required by RuntimeModules,
|
|
61
|
-
* that come from the current Runtime
|
|
62
|
-
*
|
|
63
|
-
* @param moduleName - Name of the runtime module to decorate
|
|
64
|
-
* @param containedModule
|
|
65
|
-
*/
|
|
66
|
-
decorateModule(moduleName: StringKeyOf<Modules>, containedModule: InstanceType<Modules[StringKeyOf<Modules>]>): void;
|
|
67
|
-
/**
|
|
68
|
-
* @returns A list of names of all the registered module names
|
|
69
|
-
*/
|
|
70
|
-
get runtimeModuleNames(): string[];
|
|
71
|
-
}
|
|
72
|
-
//# sourceMappingURL=Runtime.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Runtime.d.ts","sourceRoot":"","sources":["../../../../src/runtime/Runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAc,MAAM,UAAU,CAAC;AAC3D,OAAO,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,aAAa,EACb,UAAU,EACV,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACb,MAAM,qBAAqB,CAAC;AAU7B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,aAAa,CAC9C,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CACnC,CAAC;AAOF;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,OAAO,SAAS,oBAAoB;IACrE;;OAEG;IACH,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CACjC;AAED,qBAAa,qBAAqB,CAChC,OAAO,SAAS,oBAAoB,CACpC,SAAQ,cAAc,CAAC,SAAS,EAAE,kBAAkB,CAAC;IAE3B,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;gBAAzB,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;IAInD,IAAW,QAAQ,iCAElB;IAEM,gBAAgB,IAAI,cAAc,CAAC,SAAS,EAAE,kBAAkB,CAAC;CAgHzE;AAED;;;GAGG;AACH,qBACa,OAAO,CAAC,OAAO,SAAS,oBAAoB,CACvD,SAAQ,eAAe,CAAC,OAAO,CAC/B,YAAW,kBAAkB,CAAC,SAAS,EAAE,kBAAkB,CAAC;WAE9C,IAAI,CAAC,OAAO,SAAS,oBAAoB,EACrD,UAAU,EAAE,iBAAiB,CAAC,OAAO,CAAC;IAMjC,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,SAAS,CAAC,CAAC;IAEpD,UAAU,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAEvC,cAAc,EAAE,cAAc,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC;IAErE,OAAO,CAAC,QAAQ,CAAC,4BAA4B,CAG3C;IAEF;;;;OAIG;gBACgB,UAAU,EAAE,iBAAiB,CAAC,OAAO,CAAC;IAQlD,KAAK;IAOZ,IAAW,QAAQ,IAAI,gBAAgB,GAAG,SAAS,CAElD;IAED,IAAW,YAAY,IAAI,YAAY,CAEtC;IAED,IAAW,oBAAoB,IAAI,oBAAoB,CAEtD;IAED;;OAEG;IACH,IAAW,mBAAmB,IAAI,mBAAmB,CAEpD;IAED;;;OAGG;IACI,aAAa,CAClB,QAAQ,EAAE,MAAM,GACf,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,GAAG,SAAS;IAwBhD;;;;;;OAMG;IACI,cAAc,CACnB,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAChC,eAAe,EAAE,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;IAQ9D;;OAEG;IACH,IAAW,kBAAkB,aAE5B;CACF"}
|
|
@@ -1,184 +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
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
var Runtime_1;
|
|
11
|
-
// eslint-disable-next-line max-len
|
|
12
|
-
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,max-lines */
|
|
13
|
-
import { Experimental } from "snarkyjs";
|
|
14
|
-
import { injectable } from "tsyringe";
|
|
15
|
-
import { ModuleContainer, ZkProgrammable, } from "@proto-kit/common";
|
|
16
|
-
import { MethodPublicOutput, StateServiceProvider, } from "@proto-kit/protocol";
|
|
17
|
-
import { combineMethodName, isRuntimeMethod, toWrappedMethod, } from "../method/runtimeMethod";
|
|
18
|
-
import { MethodIdFactory } from "../factories/MethodIdFactory";
|
|
19
|
-
const errors = {
|
|
20
|
-
methodNotFound: (methodKey) => new Error(`Unable to find method with id ${methodKey}`),
|
|
21
|
-
};
|
|
22
|
-
export class RuntimeZkProgrammable extends ZkProgrammable {
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
24
|
-
constructor(runtime) {
|
|
25
|
-
super();
|
|
26
|
-
this.runtime = runtime;
|
|
27
|
-
}
|
|
28
|
-
get appChain() {
|
|
29
|
-
return this.runtime.appChain;
|
|
30
|
-
}
|
|
31
|
-
zkProgramFactory() {
|
|
32
|
-
// We need to use explicit type annotations here,
|
|
33
|
-
// therefore we can't use destructuring
|
|
34
|
-
// eslint-disable-next-line max-len
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define,prefer-destructuring,putout/putout
|
|
36
|
-
const runtime = this.runtime;
|
|
37
|
-
const runtimeMethods = runtime.runtimeModuleNames.reduce((allMethods, runtimeModuleName) => {
|
|
38
|
-
runtime.isValidModuleName(runtime.definition.modules, runtimeModuleName);
|
|
39
|
-
/**
|
|
40
|
-
* Couldnt find a better way to circumvent the type assertion
|
|
41
|
-
* regarding resolving only known modules. We assert in the line above
|
|
42
|
-
* but we cast it to any anyways to satisfy the proof system.
|
|
43
|
-
*/
|
|
44
|
-
// eslint-disable-next-line max-len
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
46
|
-
const runtimeModule = runtime.resolve(runtimeModuleName);
|
|
47
|
-
// eslint-disable-next-line max-len
|
|
48
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
49
|
-
const modulePrototype = Object.getPrototypeOf(runtimeModule);
|
|
50
|
-
const modulePrototypeMethods = Object.getOwnPropertyNames(modulePrototype);
|
|
51
|
-
const moduleMethods = modulePrototypeMethods.reduce((allModuleMethods, methodName) => {
|
|
52
|
-
if (isRuntimeMethod(runtimeModule, methodName)) {
|
|
53
|
-
const combinedMethodName = combineMethodName(runtimeModuleName, methodName);
|
|
54
|
-
const method = modulePrototype[methodName];
|
|
55
|
-
const wrappedMethod = Reflect.apply(toWrappedMethod, runtimeModule, [methodName, method]);
|
|
56
|
-
// eslint-disable-next-line no-warning-comments
|
|
57
|
-
// TODO: find out how to import the Tuple type
|
|
58
|
-
const privateInputs = Reflect.getMetadata("design:paramtypes", runtimeModule, methodName);
|
|
59
|
-
return {
|
|
60
|
-
...allModuleMethods,
|
|
61
|
-
[combinedMethodName]: {
|
|
62
|
-
privateInputs,
|
|
63
|
-
method: wrappedMethod,
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return allModuleMethods;
|
|
68
|
-
}, {});
|
|
69
|
-
return {
|
|
70
|
-
...allMethods,
|
|
71
|
-
...moduleMethods,
|
|
72
|
-
};
|
|
73
|
-
}, {});
|
|
74
|
-
const sortedRuntimeMethods = Object.fromEntries(
|
|
75
|
-
// eslint-disable-next-line @typescript-eslint/require-array-sort-compare
|
|
76
|
-
Object.entries(runtimeMethods).sort());
|
|
77
|
-
const program = Experimental.ZkProgram({
|
|
78
|
-
publicOutput: MethodPublicOutput,
|
|
79
|
-
methods: sortedRuntimeMethods,
|
|
80
|
-
});
|
|
81
|
-
const SelfProof = Experimental.ZkProgram.Proof(program);
|
|
82
|
-
const methods = Object.keys(sortedRuntimeMethods).reduce((boundMethods, methodName) => {
|
|
83
|
-
boundMethods[methodName] = program[methodName].bind(program);
|
|
84
|
-
return boundMethods;
|
|
85
|
-
}, {});
|
|
86
|
-
return {
|
|
87
|
-
compile: program.compile.bind(program),
|
|
88
|
-
verify: program.verify.bind(program),
|
|
89
|
-
Proof: SelfProof,
|
|
90
|
-
methods,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Wrapper for an application specific runtime, which helps orchestrate
|
|
96
|
-
* runtime modules into an interoperable runtime.
|
|
97
|
-
*/
|
|
98
|
-
let Runtime = Runtime_1 = class Runtime extends ModuleContainer {
|
|
99
|
-
static from(definition) {
|
|
100
|
-
return new Runtime_1(definition);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Creates a new Runtime from the provided config
|
|
104
|
-
*
|
|
105
|
-
* @param modules - Configuration object for the constructed Runtime
|
|
106
|
-
*/
|
|
107
|
-
constructor(definition) {
|
|
108
|
-
super(definition);
|
|
109
|
-
this.stateServiceProviderInstance = new StateServiceProvider(
|
|
110
|
-
// eslint-disable-next-line etc/no-deprecated
|
|
111
|
-
this.definition.state);
|
|
112
|
-
this.definition = definition;
|
|
113
|
-
this.zkProgrammable = new RuntimeZkProgrammable(this);
|
|
114
|
-
}
|
|
115
|
-
// eslint-disable-next-line no-warning-comments
|
|
116
|
-
// TODO Remove after changing DFs to type-based approach
|
|
117
|
-
start() {
|
|
118
|
-
this.registerValue({
|
|
119
|
-
Runtime: this,
|
|
120
|
-
});
|
|
121
|
-
this.registerDependencyFactories([MethodIdFactory]);
|
|
122
|
-
}
|
|
123
|
-
get appChain() {
|
|
124
|
-
return this.container.resolve("AppChain");
|
|
125
|
-
}
|
|
126
|
-
get stateService() {
|
|
127
|
-
return this.stateServiceProviderInstance.stateService;
|
|
128
|
-
}
|
|
129
|
-
get stateServiceProvider() {
|
|
130
|
-
return this.stateServiceProviderInstance;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* @returns The dependency injection container of this runtime
|
|
134
|
-
*/
|
|
135
|
-
get dependencyContainer() {
|
|
136
|
-
return this.container;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* @param methodId The encoded name of the method to call.
|
|
140
|
-
* Encoding: "stringToField(module.name) << 128 + stringToField(method-name)"
|
|
141
|
-
*/
|
|
142
|
-
getMethodById(methodId) {
|
|
143
|
-
const methodDescriptor = this.container
|
|
144
|
-
.resolve("MethodIdResolver")
|
|
145
|
-
.getMethodNameFromId(methodId);
|
|
146
|
-
if (methodDescriptor === undefined) {
|
|
147
|
-
return undefined;
|
|
148
|
-
}
|
|
149
|
-
const [moduleName, methodName] = methodDescriptor;
|
|
150
|
-
this.isValidModuleName(this.definition.modules, moduleName);
|
|
151
|
-
const module = this.resolve(moduleName);
|
|
152
|
-
// eslint-disable-next-line max-len
|
|
153
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions,@typescript-eslint/no-unsafe-member-access
|
|
154
|
-
const method = module[methodName];
|
|
155
|
-
if (method === undefined) {
|
|
156
|
-
throw errors.methodNotFound(`${moduleName}.${methodName}`);
|
|
157
|
-
}
|
|
158
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
159
|
-
return method.bind(module);
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Add a name and other respective properties required by RuntimeModules,
|
|
163
|
-
* that come from the current Runtime
|
|
164
|
-
*
|
|
165
|
-
* @param moduleName - Name of the runtime module to decorate
|
|
166
|
-
* @param containedModule
|
|
167
|
-
*/
|
|
168
|
-
decorateModule(moduleName, containedModule) {
|
|
169
|
-
containedModule.name = moduleName;
|
|
170
|
-
containedModule.runtime = this;
|
|
171
|
-
super.decorateModule(moduleName, containedModule);
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* @returns A list of names of all the registered module names
|
|
175
|
-
*/
|
|
176
|
-
get runtimeModuleNames() {
|
|
177
|
-
return Object.keys(this.definition.modules);
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
Runtime = Runtime_1 = __decorate([
|
|
181
|
-
injectable(),
|
|
182
|
-
__metadata("design:paramtypes", [Object])
|
|
183
|
-
], Runtime);
|
|
184
|
-
export { Runtime };
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { ConfigurableModule, Presets } from "@proto-kit/common";
|
|
2
|
-
import { NetworkState, RuntimeTransaction, StateService } from "@proto-kit/protocol";
|
|
3
|
-
import type { Runtime, RuntimeDefinition, RuntimeModulesRecord } from "./Runtime";
|
|
4
|
-
/**
|
|
5
|
-
* This type exists to carry over certain runtime properties
|
|
6
|
-
* to runtime modules, until we can inject them through DI.
|
|
7
|
-
*/
|
|
8
|
-
export interface PartialRuntime extends Pick<Runtime<RuntimeModulesRecord>, "zkProgrammable"> {
|
|
9
|
-
definition: Pick<RuntimeDefinition<RuntimeModulesRecord>, "state">;
|
|
10
|
-
get stateService(): StateService;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Base class for runtime modules providing the necessary utilities.
|
|
14
|
-
*/
|
|
15
|
-
export declare class RuntimeModule<Config> extends ConfigurableModule<Config> {
|
|
16
|
-
static presets: Presets<unknown>;
|
|
17
|
-
/**
|
|
18
|
-
* Holds all method names that are callable throw transactions
|
|
19
|
-
*/
|
|
20
|
-
readonly runtimeMethodNames: string[];
|
|
21
|
-
/**
|
|
22
|
-
* This property exists only to typecheck that the RuntimeModule
|
|
23
|
-
* was extended correctly in e.g. a decorator. We need at least
|
|
24
|
-
* one non-optional property in this class to make the typechecking work.
|
|
25
|
-
*/
|
|
26
|
-
isRuntimeModule: boolean;
|
|
27
|
-
name?: string;
|
|
28
|
-
runtime?: Runtime<RuntimeModulesRecord>;
|
|
29
|
-
constructor();
|
|
30
|
-
private getInputs;
|
|
31
|
-
get transaction(): RuntimeTransaction;
|
|
32
|
-
get network(): NetworkState;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=RuntimeModule.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RuntimeModule.d.ts","sourceRoot":"","sources":["../../../../src/runtime/RuntimeModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEhE,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,YAAY,EAGb,MAAM,qBAAqB,CAAC;AAI7B,OAAO,KAAK,EACV,OAAO,EACP,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,WAAW,CAAC;AAMnB;;;GAGG;AACH,MAAM,WAAW,cACf,SAAQ,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,EAAE,gBAAgB,CAAC;IAC7D,UAAU,EAAE,IAAI,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC,CAAC;IAEnE,IAAI,YAAY,IAAI,YAAY,CAAC;CAClC;AAED;;GAEG;AACH,qBACa,aAAa,CAAC,MAAM,CAAE,SAAQ,kBAAkB,CAAC,MAAM,CAAC;IACnE,OAAc,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAM;IAE7C;;OAEG;IACH,SAAgB,kBAAkB,EAAE,MAAM,EAAE,CAAM;IAElD;;;;OAIG;IACI,eAAe,UAAQ;IAEvB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,OAAO,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;;IAY/C,OAAO,CAAC,SAAS;IAWjB,IAAW,WAAW,IAAI,kBAAkB,CAE3C;IAED,IAAW,OAAO,IAAI,YAAY,CAEjC;CACF"}
|
|
@@ -1,56 +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
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { ConfigurableModule } from "@proto-kit/common";
|
|
11
|
-
import { container, injectable } from "tsyringe";
|
|
12
|
-
import { RuntimeMethodExecutionContext, } from "@proto-kit/protocol";
|
|
13
|
-
import { runtimeMethodNamesMetadataKey } from "../method/runtimeMethod";
|
|
14
|
-
const errors = {
|
|
15
|
-
inputDataNotSet: () => new Error("Input data for runtime execution not set"),
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Base class for runtime modules providing the necessary utilities.
|
|
19
|
-
*/
|
|
20
|
-
let RuntimeModule = class RuntimeModule extends ConfigurableModule {
|
|
21
|
-
constructor() {
|
|
22
|
-
super();
|
|
23
|
-
/**
|
|
24
|
-
* Holds all method names that are callable throw transactions
|
|
25
|
-
*/
|
|
26
|
-
this.runtimeMethodNames = [];
|
|
27
|
-
/**
|
|
28
|
-
* This property exists only to typecheck that the RuntimeModule
|
|
29
|
-
* was extended correctly in e.g. a decorator. We need at least
|
|
30
|
-
* one non-optional property in this class to make the typechecking work.
|
|
31
|
-
*/
|
|
32
|
-
this.isRuntimeModule = true;
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
34
|
-
const methodNames = Reflect.getMetadata(runtimeMethodNamesMetadataKey, this);
|
|
35
|
-
this.runtimeMethodNames = methodNames ?? [];
|
|
36
|
-
}
|
|
37
|
-
getInputs() {
|
|
38
|
-
const { input } = container.resolve(RuntimeMethodExecutionContext);
|
|
39
|
-
if (input === undefined) {
|
|
40
|
-
throw errors.inputDataNotSet();
|
|
41
|
-
}
|
|
42
|
-
return input;
|
|
43
|
-
}
|
|
44
|
-
get transaction() {
|
|
45
|
-
return this.getInputs().transaction;
|
|
46
|
-
}
|
|
47
|
-
get network() {
|
|
48
|
-
return this.getInputs().networkState;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
RuntimeModule.presets = {};
|
|
52
|
-
RuntimeModule = __decorate([
|
|
53
|
-
injectable(),
|
|
54
|
-
__metadata("design:paramtypes", [])
|
|
55
|
-
], RuntimeModule);
|
|
56
|
-
export { RuntimeModule };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Field } from "snarkyjs";
|
|
2
|
-
import { StateService } from "@proto-kit/protocol";
|
|
3
|
-
/**
|
|
4
|
-
* Naive implementation of a StateService for testing purposes
|
|
5
|
-
*/
|
|
6
|
-
export declare class InMemoryStateService implements StateService {
|
|
7
|
-
values: Record<string, Field[] | undefined>;
|
|
8
|
-
get(key: Field): Field[] | undefined;
|
|
9
|
-
set(key: Field, value: Field[] | undefined): void;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=InMemoryStateService.d.ts.map
|