@proto-kit/module 0.1.1-develop.1665 → 0.1.1-develop.1688
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/factories/MethodIdFactory.js +0 -1
- package/dist/factories/MethodIdFactory.js.map +1 -1
- package/dist/messages/OutgoingMessage.d.ts +96 -0
- package/dist/messages/OutgoingMessage.d.ts.map +1 -0
- package/dist/messages/OutgoingMessage.js +68 -0
- package/dist/messages/OutgoingMessage.js.map +1 -0
- package/dist/state/decorator.d.ts +7 -0
- package/dist/state/decorator.d.ts.map +1 -0
- package/dist/state/decorator.js +40 -0
- package/dist/state/decorator.js.map +1 -0
- package/dist/testing/TestingRuntime.d.ts +8 -0
- package/dist/testing/TestingRuntime.d.ts.map +1 -0
- package/dist/testing/TestingRuntime.js +31 -0
- package/dist/testing/TestingRuntime.js.map +1 -0
- package/package.json +3 -3
- package/src/method/MethodParameterEncoder.ts +6 -4
- package/src/runtime/Runtime.ts +14 -1
- package/test/method/MethodParameterEncoder.test.ts +5 -3
- package/test/method/runtimeMethod-fail.test.ts +4 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MethodIdFactory.js","sourceRoot":"","sources":["../../src/factories/MethodIdFactory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,MAAM,OAAO,eAAe;IACnB,MAAM,CAAC,YAAY;QACxB,OAAO;YACL,gBAAgB,EAAE;gBAChB,QAAQ,EAAE,gBAAgB;aAC3B;SACyB,CAAC;IAC/B,CAAC;CACF
|
|
1
|
+
{"version":3,"file":"MethodIdFactory.js","sourceRoot":"","sources":["../../src/factories/MethodIdFactory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,MAAM,OAAO,eAAe;IACnB,MAAM,CAAC,YAAY;QACxB,OAAO;YACL,gBAAgB,EAAE;gBAChB,QAAQ,EAAE,gBAAgB;aAC3B;SACyB,CAAC;IAC/B,CAAC;CACF"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Field, FlexibleProvablePure, InferProvable } from "o1js";
|
|
2
|
+
import { state, WithPath, WithStateServiceProvider } from "@proto-kit/protocol";
|
|
3
|
+
import { StringKeyOf } from "@proto-kit/common";
|
|
4
|
+
declare const OutgoingMessageKeyStruct_base: (new (value: {
|
|
5
|
+
index: import("o1js/dist/node/lib/provable/field").Field;
|
|
6
|
+
tokenId: import("o1js/dist/node/lib/provable/field").Field;
|
|
7
|
+
}) => {
|
|
8
|
+
index: import("o1js/dist/node/lib/provable/field").Field;
|
|
9
|
+
tokenId: import("o1js/dist/node/lib/provable/field").Field;
|
|
10
|
+
}) & {
|
|
11
|
+
_isStruct: true;
|
|
12
|
+
} & Omit<import("o1js/dist/node/lib/provable/types/provable-intf").Provable<{
|
|
13
|
+
index: import("o1js/dist/node/lib/provable/field").Field;
|
|
14
|
+
tokenId: import("o1js/dist/node/lib/provable/field").Field;
|
|
15
|
+
}, {
|
|
16
|
+
index: bigint;
|
|
17
|
+
tokenId: bigint;
|
|
18
|
+
}>, "fromFields"> & {
|
|
19
|
+
fromFields: (fields: import("o1js/dist/node/lib/provable/field").Field[]) => {
|
|
20
|
+
index: import("o1js/dist/node/lib/provable/field").Field;
|
|
21
|
+
tokenId: import("o1js/dist/node/lib/provable/field").Field;
|
|
22
|
+
};
|
|
23
|
+
} & {
|
|
24
|
+
fromValue: (value: {
|
|
25
|
+
index: string | number | bigint | import("o1js/dist/node/lib/provable/field").Field;
|
|
26
|
+
tokenId: string | number | bigint | import("o1js/dist/node/lib/provable/field").Field;
|
|
27
|
+
}) => {
|
|
28
|
+
index: import("o1js/dist/node/lib/provable/field").Field;
|
|
29
|
+
tokenId: import("o1js/dist/node/lib/provable/field").Field;
|
|
30
|
+
};
|
|
31
|
+
toInput: (x: {
|
|
32
|
+
index: import("o1js/dist/node/lib/provable/field").Field;
|
|
33
|
+
tokenId: import("o1js/dist/node/lib/provable/field").Field;
|
|
34
|
+
}) => {
|
|
35
|
+
fields?: import("o1js/dist/node/lib/provable/field").Field[] | undefined;
|
|
36
|
+
packed?: [import("o1js/dist/node/lib/provable/field").Field, number][] | undefined;
|
|
37
|
+
};
|
|
38
|
+
toJSON: (x: {
|
|
39
|
+
index: import("o1js/dist/node/lib/provable/field").Field;
|
|
40
|
+
tokenId: import("o1js/dist/node/lib/provable/field").Field;
|
|
41
|
+
}) => {
|
|
42
|
+
index: string;
|
|
43
|
+
tokenId: string;
|
|
44
|
+
};
|
|
45
|
+
fromJSON: (x: {
|
|
46
|
+
index: string;
|
|
47
|
+
tokenId: string;
|
|
48
|
+
}) => {
|
|
49
|
+
index: import("o1js/dist/node/lib/provable/field").Field;
|
|
50
|
+
tokenId: import("o1js/dist/node/lib/provable/field").Field;
|
|
51
|
+
};
|
|
52
|
+
empty: () => {
|
|
53
|
+
index: import("o1js/dist/node/lib/provable/field").Field;
|
|
54
|
+
tokenId: import("o1js/dist/node/lib/provable/field").Field;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export declare class OutgoingMessageKeyStruct extends OutgoingMessageKeyStruct_base {
|
|
58
|
+
}
|
|
59
|
+
export type OutgoingMessage<T> = {
|
|
60
|
+
key: OutgoingMessageKeyStruct;
|
|
61
|
+
value: T;
|
|
62
|
+
type: Field;
|
|
63
|
+
};
|
|
64
|
+
export type OutgoingMessagesRecord = Record<string, FlexibleProvablePure<any>>;
|
|
65
|
+
export declare const OUTGOING_MESSAGE_BASE_PATH: import("o1js/dist/node/lib/provable/field").Field;
|
|
66
|
+
export declare const OUTGOING_MESSAGE_COUNTER_PATH: import("o1js/dist/node/lib/provable/field").Field;
|
|
67
|
+
export declare const outgoingMessage: typeof state;
|
|
68
|
+
declare const OutgoingMessages_base: import("ts-mixer/dist/types/types").Class<any[], WithPath & WithStateServiceProvider, typeof WithPath & typeof WithStateServiceProvider>;
|
|
69
|
+
export declare class OutgoingMessages<Messages extends OutgoingMessagesRecord> extends OutgoingMessages_base {
|
|
70
|
+
private readonly messages;
|
|
71
|
+
readonly eventTypes: Record<string, {
|
|
72
|
+
valueType: FlexibleProvablePure<any>;
|
|
73
|
+
completeType: FlexibleProvablePure<{
|
|
74
|
+
key: OutgoingMessageKeyStruct;
|
|
75
|
+
value: any;
|
|
76
|
+
type: Field;
|
|
77
|
+
}>;
|
|
78
|
+
}>;
|
|
79
|
+
constructor(messages: Messages);
|
|
80
|
+
private counterState;
|
|
81
|
+
static getEventName(key: string): string;
|
|
82
|
+
computeEventTypes(): {
|
|
83
|
+
[k: string]: {
|
|
84
|
+
valueType: FlexibleProvablePure<any>;
|
|
85
|
+
completeType: FlexibleProvablePure<{
|
|
86
|
+
key: OutgoingMessageKeyStruct;
|
|
87
|
+
value: any;
|
|
88
|
+
type: Field;
|
|
89
|
+
}>;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
private emitEvent;
|
|
93
|
+
emitMessage<Key extends StringKeyOf<Messages>>(key: Key, value: InferProvable<Messages[Key]>, tokenId?: Field): Promise<void>;
|
|
94
|
+
}
|
|
95
|
+
export {};
|
|
96
|
+
//# sourceMappingURL=OutgoingMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OutgoingMessage.d.ts","sourceRoot":"","sources":["../../src/messages/OutgoingMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,oBAAoB,EACpB,aAAa,EAGd,MAAM,MAAM,CAAC;AACd,OAAO,EAEL,KAAK,EAEL,QAAQ,EACR,wBAAwB,EACzB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAiB,WAAW,EAAE,MAAM,mBAAmB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG/D,qBAAa,wBAAyB,SAAQ,6BAG5C;CAAG;AAEL,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI;IAC/B,GAAG,EAAE,wBAAwB,CAAC;IAC9B,KAAK,EAAE,CAAC,CAAC;IACT,IAAI,EAAE,KAAK,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC;AAE/E,eAAO,MAAM,0BAA0B,mDAEtC,CAAC;AAEF,eAAO,MAAM,6BAA6B,mDAEzC,CAAC;AAEF,eAAO,MAAM,eAAe,cAAQ,CAAC;;AAErC,qBAAa,gBAAgB,CAC3B,QAAQ,SAAS,sBAAsB,CACvC,SAAQ,qBAAyC;IAa9B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAZ5C,SAAgB,UAAU,EAAE,MAAM,CAChC,MAAM,EACN;QACE,SAAS,EAAE,oBAAoB,CAAC,GAAG,CAAC,CAAC;QACrC,YAAY,EAAE,oBAAoB,CAAC;YACjC,GAAG,EAAE,wBAAwB,CAAC;YAC9B,KAAK,EAAE,GAAG,CAAC;YACX,IAAI,EAAE,KAAK,CAAC;SACb,CAAC,CAAC;KACJ,CACF,CAAC;gBAEkC,QAAQ,EAAE,QAAQ;IAKtD,OAAO,CAAC,YAAY;WAON,YAAY,CAAC,GAAG,EAAE,MAAM;IAI/B,iBAAiB;;;;qBAcP,wBAAwB;uBACtB,GAAG;sBACJ,KAAK;;;;IAQvB,OAAO,CAAC,SAAS;IAeJ,WAAW,CAAC,GAAG,SAAS,WAAW,CAAC,QAAQ,CAAC,EACxD,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EACnC,OAAO,GAAE,KAAuB;CAmBnC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Field, Struct, TokenId, } from "o1js";
|
|
2
|
+
import { RuntimeMethodExecutionContext, state, StateMap, WithPath, WithStateServiceProvider, } from "@proto-kit/protocol";
|
|
3
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
4
|
+
import { Mixin } from "ts-mixer";
|
|
5
|
+
import { prefixToField } from "@proto-kit/common";
|
|
6
|
+
import { container } from "tsyringe";
|
|
7
|
+
export class OutgoingMessageKeyStruct extends Struct({
|
|
8
|
+
index: Field,
|
|
9
|
+
tokenId: Field,
|
|
10
|
+
}) {
|
|
11
|
+
}
|
|
12
|
+
export const OUTGOING_MESSAGE_BASE_PATH = prefixToField("outgoing-message-base-path");
|
|
13
|
+
export const OUTGOING_MESSAGE_COUNTER_PATH = prefixToField("outgoing-message-base-path");
|
|
14
|
+
export const outgoingMessage = state;
|
|
15
|
+
export class OutgoingMessages extends Mixin(WithPath, WithStateServiceProvider) {
|
|
16
|
+
constructor(messages) {
|
|
17
|
+
super();
|
|
18
|
+
this.messages = messages;
|
|
19
|
+
this.eventTypes = this.computeEventTypes();
|
|
20
|
+
}
|
|
21
|
+
counterState() {
|
|
22
|
+
const state = new StateMap(Field, Field);
|
|
23
|
+
state.path = OUTGOING_MESSAGE_COUNTER_PATH;
|
|
24
|
+
state.stateServiceProvider = this.stateServiceProvider;
|
|
25
|
+
return state;
|
|
26
|
+
}
|
|
27
|
+
static getEventName(key) {
|
|
28
|
+
return `outgoing-${key}`;
|
|
29
|
+
}
|
|
30
|
+
computeEventTypes() {
|
|
31
|
+
return Object.fromEntries(Object.entries(this.messages).map(([key, type]) => {
|
|
32
|
+
class OutgoingMessageStruct extends Struct({
|
|
33
|
+
key: OutgoingMessageKeyStruct,
|
|
34
|
+
value: type,
|
|
35
|
+
type: Field,
|
|
36
|
+
}) {
|
|
37
|
+
}
|
|
38
|
+
return [
|
|
39
|
+
OutgoingMessages.getEventName(key),
|
|
40
|
+
{
|
|
41
|
+
valueType: type,
|
|
42
|
+
completeType: OutgoingMessageStruct,
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
emitEvent(key, value) {
|
|
48
|
+
const eventName = OutgoingMessages.getEventName(key);
|
|
49
|
+
const outgoingMessageType = this.eventTypes[eventName].completeType;
|
|
50
|
+
return container
|
|
51
|
+
.resolve(RuntimeMethodExecutionContext)
|
|
52
|
+
.addEvent(outgoingMessageType, value, eventName);
|
|
53
|
+
}
|
|
54
|
+
async emitMessage(key, value, tokenId = TokenId.default) {
|
|
55
|
+
const stateMap = new StateMap(OutgoingMessageKeyStruct, this.messages[key]);
|
|
56
|
+
stateMap.path = OUTGOING_MESSAGE_BASE_PATH;
|
|
57
|
+
stateMap.stateServiceProvider = this.stateServiceProvider;
|
|
58
|
+
const counterState = this.counterState();
|
|
59
|
+
const counterOption = await counterState.get(tokenId);
|
|
60
|
+
const counter = counterOption.orElse(Field(0));
|
|
61
|
+
const messageKey = { index: counter, tokenId };
|
|
62
|
+
await stateMap.set(messageKey, value);
|
|
63
|
+
await counterState.set(tokenId, counter.add(1));
|
|
64
|
+
const type = prefixToField(key);
|
|
65
|
+
this.emitEvent(key, { key: messageKey, value, type });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=OutgoingMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OutgoingMessage.js","sourceRoot":"","sources":["../../src/messages/OutgoingMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAGL,MAAM,EACN,OAAO,GACR,MAAM,MAAM,CAAC;AACd,OAAO,EACL,6BAA6B,EAC7B,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,wBAAwB,GACzB,MAAM,qBAAqB,CAAC;AAC7B,6DAA6D;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,aAAa,EAAe,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,MAAM,OAAO,wBAAyB,SAAQ,MAAM,CAAC;IACnD,KAAK,EAAE,KAAK;IACZ,OAAO,EAAE,KAAK;CACf,CAAC;CAAG;AAUL,MAAM,CAA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|
1
|
+
import type { RuntimeModule } from "../runtime/RuntimeModule.js";
|
|
2
|
+
/**
|
|
3
|
+
* Decorates a runtime module property as state, passing down some
|
|
4
|
+
* underlying values to improve developer experience.
|
|
5
|
+
*/
|
|
6
|
+
export declare function state(): <TargetRuntimeModule extends RuntimeModule<unknown>>(target: TargetRuntimeModule, propertyKey: string) => void;
|
|
7
|
+
//# sourceMappingURL=decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator.d.ts","sourceRoot":"","sources":["../../src/state/decorator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAgBjE;;;GAGG;AACH,wBAAgB,KAAK,mGAGJ,MAAM,UAmCtB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Path } from "@proto-kit/protocol";
|
|
2
|
+
const errors = {
|
|
3
|
+
missingName: (className) => new Error(`Unable to provide a unique identifier for state, ${className} is missing a name.
|
|
4
|
+
Did you forget to extend your runtime module with 'extends RuntimeModule'?`),
|
|
5
|
+
missingRuntime: (className) => new Error(`Unable to provide 'runtime' for state, ${className} is missing a name.
|
|
6
|
+
Did you forget to extend your runtime module with 'extends RuntimeModule'?`),
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Decorates a runtime module property as state, passing down some
|
|
10
|
+
* underlying values to improve developer experience.
|
|
11
|
+
*/
|
|
12
|
+
export function state() {
|
|
13
|
+
return (target, propertyKey) => {
|
|
14
|
+
let value;
|
|
15
|
+
Object.defineProperty(target, propertyKey, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function get() {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
19
|
+
const self = this;
|
|
20
|
+
if (self.name === undefined) {
|
|
21
|
+
throw errors.missingName(self.constructor.name);
|
|
22
|
+
}
|
|
23
|
+
if (!self.runtime) {
|
|
24
|
+
throw errors.missingRuntime(self.constructor.name);
|
|
25
|
+
}
|
|
26
|
+
const path = Path.fromProperty(self.name, propertyKey);
|
|
27
|
+
if (value) {
|
|
28
|
+
value.path = path;
|
|
29
|
+
// TODO: why is this complaining about `any`?
|
|
30
|
+
value.stateServiceProvider = self.runtime.stateServiceProvider;
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
},
|
|
34
|
+
set: (newValue) => {
|
|
35
|
+
value = newValue;
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator.js","sourceRoot":"","sources":["../../src/state/decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAS,MAAM,qBAAqB,CAAC;AAIlD,MAAM,MAAM,GAAG;IACb,WAAW,EAAE,CAAC,SAAiB,EAAE,EAAE,CACjC,IAAI,KAAK,CACP,oDAAoD,SAAS;iFACc,CAC5E;IAEH,cAAc,EAAE,CAAC,SAAiB,EAAE,EAAE,CACpC,IAAI,KAAK,CACP,0CAA0C,SAAS;iFACwB,CAC5E;CACJ,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,KAAK;IACnB,OAAO,CACL,MAA2B,EAC3B,WAAmB,EACnB,EAAE;QACF,IAAI,KAAiC,CAAC;QAEtC,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE;YACzC,UAAU,EAAE,IAAI;YAEhB,GAAG,EAAE,SAAS,GAAG;gBACf,yEAAyE;gBACzE,MAAM,IAAI,GAAG,IAA2B,CAAC;gBAEzC,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE;oBAC3B,MAAM,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;iBACjD;gBAED,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;oBACjB,MAAM,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;iBACpD;gBAED,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;gBACvD,IAAI,KAAK,EAAE;oBACT,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;oBAElB,6CAA6C;oBAE7C,KAAK,CAAC,oBAAoB,GAAG,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC;iBAChE;gBACD,OAAO,KAAK,CAAC;YACf,CAAC;YAED,GAAG,EAAE,CAAC,QAAwB,EAAE,EAAE;gBAChC,KAAK,GAAG,QAAQ,CAAC;YACnB,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ModulesConfig } from "@proto-kit/common";
|
|
2
|
+
import { Runtime, RuntimeModulesRecord } from "../runtime/Runtime";
|
|
3
|
+
import { InMemoryStateService } from "../state/InMemoryStateService";
|
|
4
|
+
export declare function createTestingRuntime<Modules extends RuntimeModulesRecord>(modules: Modules, config: ModulesConfig<Modules>): {
|
|
5
|
+
runtime: Runtime<Modules>;
|
|
6
|
+
state: InMemoryStateService;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=TestingRuntime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TestingRuntime.d.ts","sourceRoot":"","sources":["../../src/testing/TestingRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIlD,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErE,wBAAgB,oBAAoB,CAAC,OAAO,SAAS,oBAAoB,EACvE,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,GAC7B;IACD,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1B,KAAK,EAAE,oBAAoB,CAAC;CAC7B,CAgCA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { StateServiceProvider } from "@proto-kit/protocol";
|
|
2
|
+
import { container } from "tsyringe";
|
|
3
|
+
import { Runtime } from "../runtime/Runtime";
|
|
4
|
+
import { InMemoryStateService } from "../state/InMemoryStateService";
|
|
5
|
+
export function createTestingRuntime(modules, config) {
|
|
6
|
+
const state = new InMemoryStateService();
|
|
7
|
+
const Runtimeclass = Runtime.from({
|
|
8
|
+
modules,
|
|
9
|
+
});
|
|
10
|
+
const runtime = new Runtimeclass();
|
|
11
|
+
runtime.configure(config);
|
|
12
|
+
runtime.create(() => container.createChildContainer());
|
|
13
|
+
runtime.dependencyContainer.register("AreProofsEnabled", {
|
|
14
|
+
useValue: {
|
|
15
|
+
areProofsEnabled: false,
|
|
16
|
+
setProofsEnabled(areProofsEnabled) {
|
|
17
|
+
this.areProofsEnabled = areProofsEnabled;
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
runtime.registerValue({
|
|
22
|
+
StateServiceProvider: new StateServiceProvider(),
|
|
23
|
+
Runtime: runtime,
|
|
24
|
+
});
|
|
25
|
+
runtime.stateServiceProvider.setCurrentStateService(state);
|
|
26
|
+
return {
|
|
27
|
+
runtime,
|
|
28
|
+
state,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=TestingRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TestingRuntime.js","sourceRoot":"","sources":["../../src/testing/TestingRuntime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,OAAO,EAAE,OAAO,EAAwB,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErE,MAAM,UAAU,oBAAoB,CAClC,OAAgB,EAChB,MAA8B;IAK9B,MAAM,KAAK,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAEzC,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;QAChC,OAAO;KACR,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,IAAI,YAAY,EAAE,CAAC;IAEnC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAE1B,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,oBAAoB,EAAE,CAAC,CAAC;IAEvD,OAAO,CAAC,mBAAmB,CAAC,QAAQ,CAAC,kBAAkB,EAAE;QACvD,QAAQ,EAAE;YACR,gBAAgB,EAAE,KAAK;YAEvB,gBAAgB,CAAC,gBAAyB;gBACxC,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;YAC3C,CAAC;SACF;KACF,CAAC,CAAC;IACH,OAAO,CAAC,aAAa,CAAC;QACpB,oBAAoB,EAAE,IAAI,oBAAoB,EAAE;QAChD,OAAO,EAAE,OAAO;KACjB,CAAC,CAAC;IAEH,OAAO,CAAC,oBAAoB,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;IAE3D,OAAO;QACL,OAAO;QACP,KAAK;KACN,CAAC;AACJ,CAAC"}
|
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.
|
|
5
|
+
"version": "0.1.1-develop.1688+a8257e42",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc -p tsconfig.json",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@proto-kit/common": "*",
|
|
30
30
|
"@proto-kit/protocol": "*",
|
|
31
|
-
"o1js": "^
|
|
31
|
+
"o1js": "^2.10.0",
|
|
32
32
|
"tsyringe": "^4.10.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "a8257e428f8cda2b7252ead17e29482d2fdb0575"
|
|
35
35
|
}
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
Provable,
|
|
6
6
|
DynamicProof,
|
|
7
7
|
FlexibleProvablePure,
|
|
8
|
+
FlexibleProvable,
|
|
8
9
|
} from "o1js";
|
|
9
10
|
import {
|
|
10
11
|
ArgumentTypes,
|
|
@@ -29,7 +30,7 @@ const errors = {
|
|
|
29
30
|
};
|
|
30
31
|
|
|
31
32
|
type ArgumentType =
|
|
32
|
-
|
|
|
33
|
+
| FlexibleProvable<any>
|
|
33
34
|
| typeof Proof<unknown, unknown>
|
|
34
35
|
| typeof DynamicProof<unknown, unknown>;
|
|
35
36
|
|
|
@@ -122,7 +123,7 @@ export class MethodParameterEncoder {
|
|
|
122
123
|
);
|
|
123
124
|
}
|
|
124
125
|
// as any, since we shouldn't be using this workaround in the first place
|
|
125
|
-
return (type as
|
|
126
|
+
return (type as FlexibleProvable<unknown>).sizeInFields();
|
|
126
127
|
}
|
|
127
128
|
|
|
128
129
|
public constructor(private readonly types: ArgTypeArray) {}
|
|
@@ -178,8 +179,9 @@ export class MethodParameterEncoder {
|
|
|
178
179
|
}
|
|
179
180
|
}
|
|
180
181
|
|
|
181
|
-
return (type as
|
|
182
|
-
structFields
|
|
182
|
+
return (type as FlexibleProvable<unknown>).fromFields(
|
|
183
|
+
structFields,
|
|
184
|
+
[]
|
|
183
185
|
) as any;
|
|
184
186
|
})
|
|
185
187
|
);
|
package/src/runtime/Runtime.ts
CHANGED
|
@@ -222,10 +222,23 @@ export class RuntimeZkProgrammable<
|
|
|
222
222
|
|
|
223
223
|
return splitRuntimeMethods().map((bucket, index) => {
|
|
224
224
|
const name = `RuntimeProgram-${index}`;
|
|
225
|
+
const wrappedBucket = Object.fromEntries(
|
|
226
|
+
Object.entries(bucket).map(([methodName, methodDef]) => [
|
|
227
|
+
methodName,
|
|
228
|
+
{
|
|
229
|
+
privateInputs: methodDef.privateInputs,
|
|
230
|
+
method: async (...args: any[]) => {
|
|
231
|
+
const publicOutput = await methodDef.method(...args);
|
|
232
|
+
return { publicOutput };
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
])
|
|
236
|
+
);
|
|
237
|
+
|
|
225
238
|
const program = ZkProgram({
|
|
226
239
|
name,
|
|
227
240
|
publicOutput: MethodPublicOutput,
|
|
228
|
-
methods:
|
|
241
|
+
methods: wrappedBucket,
|
|
229
242
|
});
|
|
230
243
|
|
|
231
244
|
const SelfProof = ZkProgram.Proof(program);
|
|
@@ -25,8 +25,10 @@ const TestProgram = ZkProgram({
|
|
|
25
25
|
privateInputs: [],
|
|
26
26
|
method: async (input: PublicKey) => {
|
|
27
27
|
return {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
publicOutput: {
|
|
29
|
+
a: Field(input.x),
|
|
30
|
+
b: Bool(input.isOdd),
|
|
31
|
+
},
|
|
30
32
|
};
|
|
31
33
|
},
|
|
32
34
|
},
|
|
@@ -117,5 +119,5 @@ describe("MethodParameterEncoder", () => {
|
|
|
117
119
|
expect(decoded1.publicOutput.b.equals(output.b).toBoolean()).toStrictEqual(
|
|
118
120
|
true
|
|
119
121
|
);
|
|
120
|
-
},
|
|
122
|
+
}, 60_000);
|
|
121
123
|
});
|