@proto-kit/protocol 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/blockmodules/AccountStateModule.d.ts +38 -0
- package/dist/blockmodules/AccountStateModule.d.ts.map +1 -0
- package/dist/blockmodules/AccountStateModule.js +38 -0
- package/dist/blockmodules/NoopTransactionHook.d.ts +6 -0
- package/dist/blockmodules/NoopTransactionHook.d.ts.map +1 -0
- package/dist/blockmodules/NoopTransactionHook.js +5 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -0
- package/dist/model/Option.d.ts +8 -8
- package/dist/model/Option.d.ts.map +1 -1
- package/dist/model/Option.js +7 -15
- package/dist/model/StateTransition.d.ts.map +1 -1
- package/dist/model/StateTransitionProvableBatch.d.ts +59 -1
- package/dist/model/StateTransitionProvableBatch.d.ts.map +1 -1
- package/dist/model/StateTransitionProvableBatch.js +58 -4
- package/dist/protocol/Protocol.d.ts +21 -6
- package/dist/protocol/Protocol.d.ts.map +1 -1
- package/dist/protocol/Protocol.js +44 -1
- package/dist/protocol/ProtocolModule.d.ts +2 -3
- package/dist/protocol/ProtocolModule.d.ts.map +1 -1
- package/dist/protocol/ProtocolModule.js +1 -3
- package/dist/protocol/ProvableTransactionHook.d.ts +6 -0
- package/dist/protocol/ProvableTransactionHook.d.ts.map +1 -0
- package/dist/protocol/ProvableTransactionHook.js +3 -0
- package/dist/protocol/TransitioningProtocolModule.d.ts +5 -0
- package/dist/protocol/TransitioningProtocolModule.d.ts.map +1 -0
- package/dist/protocol/TransitioningProtocolModule.js +3 -0
- package/dist/prover/block/BlockProvable.d.ts +2 -2
- package/dist/prover/block/BlockProvable.d.ts.map +1 -1
- package/dist/prover/block/BlockProver.d.ts +25 -11
- package/dist/prover/block/BlockProver.d.ts.map +1 -1
- package/dist/prover/block/BlockProver.js +74 -17
- package/dist/prover/statetransition/StateTransitionProvable.d.ts +18 -2
- package/dist/prover/statetransition/StateTransitionProvable.d.ts.map +1 -1
- package/dist/prover/statetransition/StateTransitionProvable.js +2 -0
- package/dist/prover/statetransition/StateTransitionProver.d.ts +16 -6
- package/dist/prover/statetransition/StateTransitionProver.d.ts.map +1 -1
- package/dist/prover/statetransition/StateTransitionProver.js +45 -13
- package/dist/state/State.d.ts +60 -0
- package/dist/state/State.d.ts.map +1 -0
- package/dist/state/State.js +116 -0
- package/dist/state/StateMap.d.ts +37 -0
- package/dist/state/StateMap.d.ts.map +1 -0
- package/dist/state/StateMap.js +56 -0
- package/dist/state/StateService.d.ts +6 -0
- package/dist/state/StateService.d.ts.map +1 -0
- package/dist/state/StateService.js +1 -0
- package/dist/state/StateServiceProvider.d.ts +10 -0
- package/dist/state/StateServiceProvider.d.ts.map +1 -0
- package/dist/state/StateServiceProvider.js +42 -0
- package/dist/state/assert/assert.d.ts +12 -0
- package/dist/state/assert/assert.d.ts.map +1 -0
- package/dist/state/assert/assert.js +23 -0
- package/dist/state/context/ProtocolMethodExecutionContext.d.ts +22 -0
- package/dist/state/context/ProtocolMethodExecutionContext.d.ts.map +1 -0
- package/dist/state/context/ProtocolMethodExecutionContext.js +28 -0
- package/dist/state/context/RuntimeMethodExecutionContext.d.ts +60 -0
- package/dist/state/context/RuntimeMethodExecutionContext.d.ts.map +1 -0
- package/dist/state/context/RuntimeMethodExecutionContext.js +105 -0
- package/dist/state/context/TransitionMethodExecutionContext.d.ts +23 -0
- package/dist/state/context/TransitionMethodExecutionContext.d.ts.map +1 -0
- package/dist/state/context/TransitionMethodExecutionContext.js +6 -0
- package/dist/state/protocol/ProtocolState.d.ts +7 -0
- package/dist/state/protocol/ProtocolState.d.ts.map +1 -0
- package/dist/state/protocol/ProtocolState.js +42 -0
- package/dist/utils/merkletree/MemoryMerkleTreeStorage.d.ts +26 -0
- package/dist/utils/merkletree/MemoryMerkleTreeStorage.d.ts.map +1 -0
- package/dist/utils/merkletree/MemoryMerkleTreeStorage.js +79 -0
- package/package.json +5 -3
- package/src/blockmodules/AccountStateModule.ts +31 -0
- package/src/blockmodules/NoopTransactionHook.ts +7 -0
- package/src/index.ts +12 -0
- package/src/model/Option.ts +18 -22
- package/src/model/StateTransition.ts +1 -1
- package/src/model/StateTransitionProvableBatch.ts +86 -5
- package/src/protocol/Protocol.ts +85 -23
- package/src/protocol/ProtocolModule.ts +1 -7
- package/src/protocol/ProvableTransactionHook.ts +7 -0
- package/src/protocol/TransitioningProtocolModule.ts +5 -0
- package/src/prover/block/BlockProvable.ts +2 -2
- package/src/prover/block/BlockProver.ts +139 -21
- package/src/prover/statetransition/StateTransitionProvable.ts +4 -2
- package/src/prover/statetransition/StateTransitionProver.ts +93 -13
- package/src/state/State.ts +160 -0
- package/src/state/StateMap.ts +74 -0
- package/src/state/StateService.ts +6 -0
- package/src/state/StateServiceProvider.ts +37 -0
- package/src/state/assert/assert.test.ts +49 -0
- package/src/state/assert/assert.ts +28 -0
- package/src/state/context/ProtocolMethodExecutionContext.ts +36 -0
- package/src/state/context/RuntimeMethodExecutionContext.ts +124 -0
- package/src/state/context/TransitionMethodExecutionContext.ts +27 -0
- package/src/state/protocol/ProtocolState.ts +63 -0
- package/test/BlockProver.test.ts +139 -36
- package/test/Protocol.test.ts +22 -5
- package/test/StateTransition.test.ts +1 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { PublicKey, UInt64 } from "snarkyjs";
|
|
2
|
+
import { BlockProverExecutionData } from "../prover/block/BlockProvable";
|
|
3
|
+
import { StateMap } from "../state/StateMap";
|
|
4
|
+
import { ProvableTransactionHook } from "../protocol/ProvableTransactionHook";
|
|
5
|
+
declare const AccountState_base: (new (value: {
|
|
6
|
+
nonce: UInt64;
|
|
7
|
+
}) => {
|
|
8
|
+
nonce: UInt64;
|
|
9
|
+
}) & {
|
|
10
|
+
_isStruct: true;
|
|
11
|
+
} & import("snarkyjs/dist/node/snarky").ProvablePure<{
|
|
12
|
+
nonce: UInt64;
|
|
13
|
+
}> & {
|
|
14
|
+
toInput: (x: {
|
|
15
|
+
nonce: UInt64;
|
|
16
|
+
}) => {
|
|
17
|
+
fields?: import("snarkyjs/dist/node/lib/field").Field[] | undefined;
|
|
18
|
+
packed?: [import("snarkyjs/dist/node/lib/field").Field, number][] | undefined;
|
|
19
|
+
};
|
|
20
|
+
toJSON: (x: {
|
|
21
|
+
nonce: UInt64;
|
|
22
|
+
}) => {
|
|
23
|
+
nonce: string;
|
|
24
|
+
};
|
|
25
|
+
fromJSON: (x: {
|
|
26
|
+
nonce: string;
|
|
27
|
+
}) => {
|
|
28
|
+
nonce: UInt64;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export declare class AccountState extends AccountState_base {
|
|
32
|
+
}
|
|
33
|
+
export declare class AccountStateModule extends ProvableTransactionHook {
|
|
34
|
+
accountState: StateMap<PublicKey, AccountState>;
|
|
35
|
+
onTransaction({ transaction }: BlockProverExecutionData): void;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=AccountStateModule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccountStateModule.d.ts","sourceRoot":"","sources":["../../src/blockmodules/AccountStateModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,SAAS,EAAU,MAAM,EAAE,MAAM,UAAU,CAAC;AAE/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG9E,qBAAa,YAAa,SAAQ,iBAEhC;CAAG;AAEL,qBAAa,kBAAmB,SAAQ,uBAAuB;IACrC,YAAY,oCAAmE;IAEhG,aAAa,CAAC,EAAE,WAAW,EAAE,EAAE,wBAAwB,GAAG,IAAI;CAetE"}
|
|
@@ -0,0 +1,38 @@
|
|
|
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 { Provable, PublicKey, Struct, UInt64 } from "snarkyjs";
|
|
11
|
+
import { StateMap } from "../state/StateMap";
|
|
12
|
+
import { protocolState } from "../state/protocol/ProtocolState";
|
|
13
|
+
import { ProvableTransactionHook } from "../protocol/ProvableTransactionHook";
|
|
14
|
+
import { assert } from "../state/assert/assert";
|
|
15
|
+
export class AccountState extends Struct({
|
|
16
|
+
nonce: UInt64,
|
|
17
|
+
}) {
|
|
18
|
+
}
|
|
19
|
+
export class AccountStateModule extends ProvableTransactionHook {
|
|
20
|
+
constructor() {
|
|
21
|
+
super(...arguments);
|
|
22
|
+
this.accountState = StateMap.from(PublicKey, AccountState);
|
|
23
|
+
}
|
|
24
|
+
onTransaction({ transaction }) {
|
|
25
|
+
const accountState = this.accountState
|
|
26
|
+
.get(transaction.sender)
|
|
27
|
+
.orElse(new AccountState({ nonce: UInt64.zero }));
|
|
28
|
+
const currentNonce = accountState.nonce;
|
|
29
|
+
Provable.log("Current Nonce", currentNonce);
|
|
30
|
+
Provable.log("Tx Nonce", transaction.nonce);
|
|
31
|
+
assert(currentNonce.equals(transaction.nonce), "Nonce not matching");
|
|
32
|
+
this.accountState.set(transaction.sender, new AccountState({ nonce: currentNonce.add(1) }));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
__decorate([
|
|
36
|
+
protocolState(),
|
|
37
|
+
__metadata("design:type", Object)
|
|
38
|
+
], AccountStateModule.prototype, "accountState", void 0);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ProvableTransactionHook } from "../protocol/ProvableTransactionHook";
|
|
2
|
+
import { BlockProverExecutionData } from "../prover/block/BlockProvable";
|
|
3
|
+
export declare class NoopTransactionHook extends ProvableTransactionHook {
|
|
4
|
+
onTransaction(executionData: BlockProverExecutionData): void;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=NoopTransactionHook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NoopTransactionHook.d.ts","sourceRoot":"","sources":["../../src/blockmodules/NoopTransactionHook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,qBAAa,mBAAoB,SAAQ,uBAAuB;IACvD,aAAa,CAAC,aAAa,EAAE,wBAAwB,GAAG,IAAI;CAEpE"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from "./blockmodules/AccountStateModule";
|
|
1
2
|
export * from "./utils/ProvableHashList";
|
|
2
3
|
export * from "./model/StateTransition";
|
|
3
4
|
export * from "./model/StateTransitionProvableBatch";
|
|
@@ -20,5 +21,16 @@ export * from "./model/MethodPublicOutput";
|
|
|
20
21
|
export * from "./prover/statetransition/StateTransitionWitnessProviderReference";
|
|
21
22
|
export * from "./protocol/Protocol";
|
|
22
23
|
export * from "./protocol/ProtocolModule";
|
|
24
|
+
export * from "./protocol/TransitioningProtocolModule";
|
|
25
|
+
export * from "./protocol/ProvableTransactionHook";
|
|
26
|
+
export * from "./state/assert/assert";
|
|
27
|
+
export * from "./state/context/ProtocolMethodExecutionContext";
|
|
28
|
+
export * from "./state/context/TransitionMethodExecutionContext";
|
|
29
|
+
export * from "./state/context/RuntimeMethodExecutionContext";
|
|
30
|
+
export * from "./state/protocol/ProtocolState";
|
|
31
|
+
export * from "./state/State";
|
|
32
|
+
export * from "./state/StateMap";
|
|
33
|
+
export * from "./state/StateService";
|
|
34
|
+
export * from "./state/StateServiceProvider";
|
|
23
35
|
export { constants as ProtocolConstants } from "./Constants";
|
|
24
36
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sCAAsC,CAAC;AACrD,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yCAAyC,CAAC;AACxD,cAAc,wCAAwC,CAAC;AACvD,cAAc,qCAAqC,CAAC;AACpD,cAAc,eAAe,CAAC;AAC9B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gDAAgD,CAAC;AAC/D,cAAc,kDAAkD,CAAC;AACjE,cAAc,yDAAyD,CAAC;AACxE,cAAc,oCAAoC,CAAC;AACnD,cAAc,8CAA8C,CAAC;AAC7D,cAAc,qCAAqC,CAAC;AACpD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kEAAkE,CAAC;AACjF,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,OAAO,EAAE,SAAS,IAAI,iBAAiB,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sCAAsC,CAAC;AACrD,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yCAAyC,CAAC;AACxD,cAAc,wCAAwC,CAAC;AACvD,cAAc,qCAAqC,CAAC;AACpD,cAAc,eAAe,CAAC;AAC9B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gDAAgD,CAAC;AAC/D,cAAc,kDAAkD,CAAC;AACjE,cAAc,yDAAyD,CAAC;AACxE,cAAc,oCAAoC,CAAC;AACnD,cAAc,8CAA8C,CAAC;AAC7D,cAAc,qCAAqC,CAAC;AACpD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kEAAkE,CAAC;AACjF,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wCAAwC,CAAC;AACvD,cAAc,oCAAoC,CAAC;AACnD,cAAc,uBAAuB,CAAC;AACtC,cAAc,gDAAgD,CAAC;AAC/D,cAAc,kDAAkD,CAAC;AACjE,cAAc,+CAA+C,CAAC;AAC9D,cAAc,gCAAgC,CAAC;AAC/C,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,OAAO,EAAE,SAAS,IAAI,iBAAiB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from "./blockmodules/AccountStateModule";
|
|
1
2
|
export * from "./utils/ProvableHashList";
|
|
2
3
|
export * from "./model/StateTransition";
|
|
3
4
|
export * from "./model/StateTransitionProvableBatch";
|
|
@@ -20,4 +21,15 @@ export * from "./model/MethodPublicOutput";
|
|
|
20
21
|
export * from "./prover/statetransition/StateTransitionWitnessProviderReference";
|
|
21
22
|
export * from "./protocol/Protocol";
|
|
22
23
|
export * from "./protocol/ProtocolModule";
|
|
24
|
+
export * from "./protocol/TransitioningProtocolModule";
|
|
25
|
+
export * from "./protocol/ProvableTransactionHook";
|
|
26
|
+
export * from "./state/assert/assert";
|
|
27
|
+
export * from "./state/context/ProtocolMethodExecutionContext";
|
|
28
|
+
export * from "./state/context/TransitionMethodExecutionContext";
|
|
29
|
+
export * from "./state/context/RuntimeMethodExecutionContext";
|
|
30
|
+
export * from "./state/protocol/ProtocolState";
|
|
31
|
+
export * from "./state/State";
|
|
32
|
+
export * from "./state/StateMap";
|
|
33
|
+
export * from "./state/StateService";
|
|
34
|
+
export * from "./state/StateServiceProvider";
|
|
23
35
|
export { constants as ProtocolConstants } from "./Constants";
|
package/dist/model/Option.d.ts
CHANGED
|
@@ -36,6 +36,9 @@ declare const ProvableOption_base: (new (value: {
|
|
|
36
36
|
export declare class ProvableOption extends ProvableOption_base {
|
|
37
37
|
toSome(): this;
|
|
38
38
|
}
|
|
39
|
+
export interface ToFieldable {
|
|
40
|
+
toFields: () => Field[];
|
|
41
|
+
}
|
|
39
42
|
/**
|
|
40
43
|
* Option facilitating in-circuit values that may or may not exist.
|
|
41
44
|
*/
|
|
@@ -64,14 +67,6 @@ export declare class Option<Value> {
|
|
|
64
67
|
* @returns Empty / none option
|
|
65
68
|
*/
|
|
66
69
|
static none(): Option<import("snarkyjs/dist/node/lib/field").Field>;
|
|
67
|
-
static dummyValueFields<Value>(valueType: FlexibleProvablePure<Value>): Field[];
|
|
68
|
-
/**
|
|
69
|
-
* Computes a dummy value for the given value type.
|
|
70
|
-
*
|
|
71
|
-
* @param valueType - Value type to generate the dummy value for
|
|
72
|
-
* @returns Dummy value for the given value type
|
|
73
|
-
*/
|
|
74
|
-
static dummyValue<Value>(valueType: FlexibleProvablePure<Value>): Value;
|
|
75
70
|
isForcedSome: import("snarkyjs/dist/node/lib/bool").Bool;
|
|
76
71
|
constructor(isSome: Bool, value: Value, valueType: FlexibleProvablePure<Value>);
|
|
77
72
|
clone(): Option<Value>;
|
|
@@ -89,6 +84,11 @@ export declare class Option<Value> {
|
|
|
89
84
|
* @returns Provable representation of the current option.
|
|
90
85
|
*/
|
|
91
86
|
toProvable(): ProvableOption;
|
|
87
|
+
/**
|
|
88
|
+
* @returns Returns the value of this option if it isSome,
|
|
89
|
+
* otherwise returns the given defaultValue
|
|
90
|
+
*/
|
|
91
|
+
orElse(defaultValue: Value): Value;
|
|
92
92
|
toJSON(): {
|
|
93
93
|
isSome: boolean;
|
|
94
94
|
value: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Option.d.ts","sourceRoot":"","sources":["../../src/model/Option.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,KAAK,
|
|
1
|
+
{"version":3,"file":"Option.d.ts","sourceRoot":"","sources":["../../src/model/Option.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,KAAK,EAEL,KAAK,oBAAoB,EAI1B,MAAM,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAElB,qBAAa,cAAe,SAAQ,mBAGlC;IACO,MAAM;CAId;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,KAAK,EAAE,CAAC;CACzB;AAED;;GAEG;AACH,qBAAa,MAAM,CAAC,KAAK;IAyCd,MAAM,EAAE,IAAI;IACZ,KAAK,EAAE,KAAK;IACZ,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IA1C/C;;;;;;;OAOG;WACW,IAAI,CAAC,KAAK,EACtB,MAAM,EAAE,IAAI,EACZ,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAKxC;;;;;;OAMG;WACW,SAAS,CAAC,KAAK,EAC3B,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAKxC;;OAEG;WACW,IAAI;IAIX,YAAY,6CAAe;gBAGzB,MAAM,EAAE,IAAI,EACZ,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAGxC,KAAK;IAIL,SAAS;IAKhB;;OAEG;IACH,IAAW,SAAS,iDAQnB;IAED;;;OAGG;IACI,QAAQ,IAAI,KAAK,EAAE;IAO1B;;OAEG;IACI,UAAU;IAOjB;;;OAGG;IACI,MAAM,CAAC,YAAY,EAAE,KAAK,GAAG,KAAK;IASlC,MAAM;;;;CAYd"}
|
package/dist/model/Option.js
CHANGED
|
@@ -39,21 +39,6 @@ export class Option {
|
|
|
39
39
|
static none() {
|
|
40
40
|
return new Option(Bool(false), Field(0), Field);
|
|
41
41
|
}
|
|
42
|
-
static dummyValueFields(valueType) {
|
|
43
|
-
const length = valueType.sizeInFields();
|
|
44
|
-
return Array.from({ length }, () => Field(0));
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Computes a dummy value for the given value type.
|
|
48
|
-
*
|
|
49
|
-
* @param valueType - Value type to generate the dummy value for
|
|
50
|
-
* @returns Dummy value for the given value type
|
|
51
|
-
*/
|
|
52
|
-
static dummyValue(valueType) {
|
|
53
|
-
const fields = Option.dummyValueFields(valueType);
|
|
54
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
55
|
-
return valueType.fromFields(fields);
|
|
56
|
-
}
|
|
57
42
|
constructor(isSome, value, valueType) {
|
|
58
43
|
this.isSome = isSome;
|
|
59
44
|
this.value = value;
|
|
@@ -93,6 +78,13 @@ export class Option {
|
|
|
93
78
|
value: this.treeValue,
|
|
94
79
|
});
|
|
95
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* @returns Returns the value of this option if it isSome,
|
|
83
|
+
* otherwise returns the given defaultValue
|
|
84
|
+
*/
|
|
85
|
+
orElse(defaultValue) {
|
|
86
|
+
return Provable.if(this.isSome, this.valueType, this.value, defaultValue);
|
|
87
|
+
}
|
|
96
88
|
toJSON() {
|
|
97
89
|
const valueContent = this.valueType
|
|
98
90
|
.toFields(this.value)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StateTransition.d.ts","sourceRoot":"","sources":["../../src/model/StateTransition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAU,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"StateTransition.d.ts","sourceRoot":"","sources":["../../src/model/StateTransition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAU,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAe,MAAM,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAElE;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,4BAQ3C;WACc,KAAK,IAAI,uBAAuB;CAO/C;AAED;;;GAGG;AACH,qBAAa,eAAe,CAAC,KAAK;IAcvB,IAAI,EAAE,KAAK;IACX,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;IACxC,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;WAfjC,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC;WAIjD,MAAM,CAAC,KAAK,EACxB,IAAI,EAAE,KAAK,EACX,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,EACxB,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC;gBAMf,IAAI,EAAE,KAAK,EACX,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,EACxC,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;IAG/C,IAAW,IAAI,4EAId;IAED,IAAW,EAAE,4EAEZ;IAED;;;OAGG;IACI,UAAU,IAAI,uBAAuB;IAQrC,MAAM;;;;;;;;;;;CAOd"}
|
|
@@ -1,21 +1,65 @@
|
|
|
1
|
+
import { Bool } from "snarkyjs";
|
|
1
2
|
import { ProvableStateTransition } from "./StateTransition.js";
|
|
3
|
+
export declare class StateTransitionType {
|
|
4
|
+
static readonly normal = true;
|
|
5
|
+
static readonly protocol = false;
|
|
6
|
+
static isNormal(type: boolean): boolean;
|
|
7
|
+
static isProtocol(type: boolean): boolean;
|
|
8
|
+
}
|
|
9
|
+
declare const ProvableStateTransitionType_base: (new (value: {
|
|
10
|
+
type: import("snarkyjs/dist/node/lib/bool").Bool;
|
|
11
|
+
}) => {
|
|
12
|
+
type: import("snarkyjs/dist/node/lib/bool").Bool;
|
|
13
|
+
}) & {
|
|
14
|
+
_isStruct: true;
|
|
15
|
+
} & import("snarkyjs/dist/node/snarky").ProvablePure<{
|
|
16
|
+
type: import("snarkyjs/dist/node/lib/bool").Bool;
|
|
17
|
+
}> & {
|
|
18
|
+
toInput: (x: {
|
|
19
|
+
type: import("snarkyjs/dist/node/lib/bool").Bool;
|
|
20
|
+
}) => {
|
|
21
|
+
fields?: import("snarkyjs/dist/node/lib/field").Field[] | undefined;
|
|
22
|
+
packed?: [import("snarkyjs/dist/node/lib/field").Field, number][] | undefined;
|
|
23
|
+
};
|
|
24
|
+
toJSON: (x: {
|
|
25
|
+
type: import("snarkyjs/dist/node/lib/bool").Bool;
|
|
26
|
+
}) => {
|
|
27
|
+
type: boolean;
|
|
28
|
+
};
|
|
29
|
+
fromJSON: (x: {
|
|
30
|
+
type: boolean;
|
|
31
|
+
}) => {
|
|
32
|
+
type: import("snarkyjs/dist/node/lib/bool").Bool;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export declare class ProvableStateTransitionType extends ProvableStateTransitionType_base {
|
|
36
|
+
static get normal(): ProvableStateTransitionType;
|
|
37
|
+
static get protocol(): ProvableStateTransitionType;
|
|
38
|
+
isNormal(): Bool;
|
|
39
|
+
isProtocol(): Bool;
|
|
40
|
+
}
|
|
2
41
|
declare const StateTransitionProvableBatch_base: (new (value: {
|
|
3
42
|
batch: ProvableStateTransition[];
|
|
43
|
+
transitionTypes: ProvableStateTransitionType[];
|
|
4
44
|
}) => {
|
|
5
45
|
batch: ProvableStateTransition[];
|
|
46
|
+
transitionTypes: ProvableStateTransitionType[];
|
|
6
47
|
}) & {
|
|
7
48
|
_isStruct: true;
|
|
8
49
|
} & import("snarkyjs/dist/node/snarky").ProvablePure<{
|
|
9
50
|
batch: ProvableStateTransition[];
|
|
51
|
+
transitionTypes: ProvableStateTransitionType[];
|
|
10
52
|
}> & {
|
|
11
53
|
toInput: (x: {
|
|
12
54
|
batch: ProvableStateTransition[];
|
|
55
|
+
transitionTypes: ProvableStateTransitionType[];
|
|
13
56
|
}) => {
|
|
14
57
|
fields?: import("snarkyjs/dist/node/lib/field").Field[] | undefined;
|
|
15
58
|
packed?: [import("snarkyjs/dist/node/lib/field").Field, number][] | undefined;
|
|
16
59
|
};
|
|
17
60
|
toJSON: (x: {
|
|
18
61
|
batch: ProvableStateTransition[];
|
|
62
|
+
transitionTypes: ProvableStateTransitionType[];
|
|
19
63
|
}) => {
|
|
20
64
|
batch: {
|
|
21
65
|
path: string;
|
|
@@ -28,6 +72,9 @@ declare const StateTransitionProvableBatch_base: (new (value: {
|
|
|
28
72
|
value: string;
|
|
29
73
|
};
|
|
30
74
|
}[];
|
|
75
|
+
transitionTypes: {
|
|
76
|
+
type: boolean;
|
|
77
|
+
}[];
|
|
31
78
|
};
|
|
32
79
|
fromJSON: (x: {
|
|
33
80
|
batch: {
|
|
@@ -41,16 +88,27 @@ declare const StateTransitionProvableBatch_base: (new (value: {
|
|
|
41
88
|
value: string;
|
|
42
89
|
};
|
|
43
90
|
}[];
|
|
91
|
+
transitionTypes: {
|
|
92
|
+
type: boolean;
|
|
93
|
+
}[];
|
|
44
94
|
}) => {
|
|
45
95
|
batch: ProvableStateTransition[];
|
|
96
|
+
transitionTypes: ProvableStateTransitionType[];
|
|
46
97
|
};
|
|
47
98
|
};
|
|
48
99
|
/**
|
|
49
100
|
* A Batch of StateTransitions to be consumed by the StateTransitionProver
|
|
50
101
|
* to prove multiple STs at once
|
|
102
|
+
*
|
|
103
|
+
* transitionType:
|
|
104
|
+
* true == normal ST, false == protocol ST
|
|
51
105
|
*/
|
|
52
106
|
export declare class StateTransitionProvableBatch extends StateTransitionProvableBatch_base {
|
|
53
|
-
static
|
|
107
|
+
static fromMappings(transitions: {
|
|
108
|
+
transition: ProvableStateTransition;
|
|
109
|
+
type: ProvableStateTransitionType;
|
|
110
|
+
}[]): StateTransitionProvableBatch;
|
|
111
|
+
static fromTransitions(transitions: ProvableStateTransition[], protocolTransitions: ProvableStateTransition[]): StateTransitionProvableBatch;
|
|
54
112
|
private constructor();
|
|
55
113
|
}
|
|
56
114
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StateTransitionProvableBatch.d.ts","sourceRoot":"","sources":["../../src/model/StateTransitionProvableBatch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"StateTransitionProvableBatch.d.ts","sourceRoot":"","sources":["../../src/model/StateTransitionProvableBatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAoB,MAAM,UAAU,CAAC;AAIlD,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAG/D,qBAAa,mBAAmB;IAC9B,gBAAuB,MAAM,QAAQ;IACrC,gBAAuB,QAAQ,SAAS;WAE1B,QAAQ,CAAC,IAAI,EAAE,OAAO;WAItB,UAAU,CAAC,IAAI,EAAE,OAAO;CAGvC;;;;;;;;;;;;;;;;;;;;;;;;;;;AAED,qBAAa,2BAA4B,SAAQ,gCAE/C;IACA,WAAkB,MAAM,IAAI,2BAA2B,CAItD;IAED,WAAkB,QAAQ,IAAI,2BAA2B,CAIxD;IAEM,QAAQ,IAAI,IAAI;IAIhB,UAAU,IAAI,IAAI;CAG1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAED;;;;;;GAMG;AACH,qBAAa,4BAA6B,SAAQ,iCAUhD;WACc,YAAY,CACxB,WAAW,EAAE;QACX,UAAU,EAAE,uBAAuB,CAAC;QACpC,IAAI,EAAE,2BAA2B,CAAC;KACnC,EAAE,GACF,4BAA4B;WAcjB,eAAe,CAC3B,WAAW,EAAE,uBAAuB,EAAE,EACtC,mBAAmB,EAAE,uBAAuB,EAAE,GAC7C,4BAA4B;IAsB/B,OAAO;CAMR"}
|
|
@@ -1,19 +1,73 @@
|
|
|
1
|
-
import { Provable, Struct } from "snarkyjs";
|
|
1
|
+
import { Bool, Provable, Struct } from "snarkyjs";
|
|
2
2
|
import { constants } from "../Constants";
|
|
3
3
|
import { ProvableStateTransition } from "./StateTransition.js";
|
|
4
|
+
import { range } from "@proto-kit/common";
|
|
5
|
+
export class StateTransitionType {
|
|
6
|
+
static isNormal(type) {
|
|
7
|
+
return type === StateTransitionType.normal;
|
|
8
|
+
}
|
|
9
|
+
static isProtocol(type) {
|
|
10
|
+
return type === StateTransitionType.protocol;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
StateTransitionType.normal = true;
|
|
14
|
+
StateTransitionType.protocol = false;
|
|
15
|
+
export class ProvableStateTransitionType extends Struct({
|
|
16
|
+
type: Bool,
|
|
17
|
+
}) {
|
|
18
|
+
static get normal() {
|
|
19
|
+
return new ProvableStateTransitionType({
|
|
20
|
+
type: Bool(StateTransitionType.normal),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
static get protocol() {
|
|
24
|
+
return new ProvableStateTransitionType({
|
|
25
|
+
type: Bool(StateTransitionType.protocol),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
isNormal() {
|
|
29
|
+
return this.type;
|
|
30
|
+
}
|
|
31
|
+
isProtocol() {
|
|
32
|
+
return this.type.not();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
4
35
|
/**
|
|
5
36
|
* A Batch of StateTransitions to be consumed by the StateTransitionProver
|
|
6
37
|
* to prove multiple STs at once
|
|
38
|
+
*
|
|
39
|
+
* transitionType:
|
|
40
|
+
* true == normal ST, false == protocol ST
|
|
7
41
|
*/
|
|
8
42
|
export class StateTransitionProvableBatch extends Struct({
|
|
9
43
|
batch: Provable.Array(ProvableStateTransition, constants.stateTransitionProverBatchSize),
|
|
44
|
+
transitionTypes: Provable.Array(ProvableStateTransitionType, constants.stateTransitionProverBatchSize),
|
|
10
45
|
}) {
|
|
11
|
-
static
|
|
12
|
-
const
|
|
46
|
+
static fromMappings(transitions) {
|
|
47
|
+
const batch = transitions.map((entry) => entry.transition);
|
|
48
|
+
const transitionTypes = transitions.map((entry) => entry.type);
|
|
49
|
+
while (batch.length < constants.stateTransitionProverBatchSize) {
|
|
50
|
+
batch.push(ProvableStateTransition.dummy());
|
|
51
|
+
transitionTypes.push(ProvableStateTransitionType.normal);
|
|
52
|
+
}
|
|
53
|
+
return new StateTransitionProvableBatch({
|
|
54
|
+
batch,
|
|
55
|
+
transitionTypes,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
static fromTransitions(transitions, protocolTransitions) {
|
|
59
|
+
const array = transitions.slice().concat(protocolTransitions);
|
|
60
|
+
const transitionTypes = range(0, transitions.length)
|
|
61
|
+
.map(() => ProvableStateTransitionType.normal)
|
|
62
|
+
.concat(range(0, protocolTransitions.length).map(() => ProvableStateTransitionType.protocol));
|
|
13
63
|
while (array.length < constants.stateTransitionProverBatchSize) {
|
|
14
64
|
array.push(ProvableStateTransition.dummy());
|
|
65
|
+
transitionTypes.push(ProvableStateTransitionType.normal);
|
|
15
66
|
}
|
|
16
|
-
return new StateTransitionProvableBatch({
|
|
67
|
+
return new StateTransitionProvableBatch({
|
|
68
|
+
batch: array,
|
|
69
|
+
transitionTypes,
|
|
70
|
+
});
|
|
17
71
|
}
|
|
18
72
|
constructor(object) {
|
|
19
73
|
super(object);
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { ModuleContainer, ModulesRecord, StringKeyOf, TypedClass } from "@proto-kit/common";
|
|
2
2
|
import { DependencyContainer } from "tsyringe";
|
|
3
|
-
import { BlockProvable
|
|
3
|
+
import { BlockProvable } from "../prover/block/BlockProvable";
|
|
4
4
|
import { StateTransitionProver } from "../prover/statetransition/StateTransitionProver";
|
|
5
|
-
import { StateTransitionProvable
|
|
5
|
+
import { StateTransitionProvable } from "../prover/statetransition/StateTransitionProvable";
|
|
6
6
|
import { BlockProver } from "../prover/block/BlockProver";
|
|
7
|
+
import { StateServiceProvider } from "../state/StateServiceProvider";
|
|
8
|
+
import { StateService } from "../state/StateService";
|
|
7
9
|
import { ProtocolModule } from "./ProtocolModule";
|
|
8
|
-
export type GenericProtocolModuleRecord = ModulesRecord<TypedClass<ProtocolModule
|
|
9
|
-
interface BlockProverType extends ProtocolModule
|
|
10
|
+
export type GenericProtocolModuleRecord = ModulesRecord<TypedClass<ProtocolModule>>;
|
|
11
|
+
interface BlockProverType extends ProtocolModule, BlockProvable {
|
|
10
12
|
}
|
|
11
|
-
interface StateTransitionProverType extends ProtocolModule
|
|
13
|
+
interface StateTransitionProverType extends ProtocolModule, StateTransitionProvable {
|
|
12
14
|
}
|
|
13
15
|
export interface ProtocolCustomModulesRecord {
|
|
14
16
|
BlockProver: TypedClass<BlockProverType>;
|
|
@@ -18,9 +20,18 @@ export interface ProtocolModulesRecord extends GenericProtocolModuleRecord, Prot
|
|
|
18
20
|
}
|
|
19
21
|
export interface ProtocolDefinition<Modules extends ProtocolModulesRecord> {
|
|
20
22
|
modules: Modules;
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated
|
|
25
|
+
*/
|
|
26
|
+
state?: StateService;
|
|
21
27
|
}
|
|
22
28
|
export declare class Protocol<Modules extends ProtocolModulesRecord> extends ModuleContainer<Modules> {
|
|
23
29
|
static from<Modules extends ProtocolModulesRecord>(modules: ProtocolDefinition<Modules>): Protocol<Modules>;
|
|
30
|
+
definition: ProtocolDefinition<Modules>;
|
|
31
|
+
private readonly stateServiceProviderInstance;
|
|
32
|
+
constructor(definition: ProtocolDefinition<Modules>);
|
|
33
|
+
get stateService(): StateService;
|
|
34
|
+
get stateServiceProvider(): StateServiceProvider;
|
|
24
35
|
decorateModule(moduleName: StringKeyOf<Modules>, containedModule: InstanceType<Modules[StringKeyOf<Modules>]>): void;
|
|
25
36
|
get dependencyContainer(): DependencyContainer;
|
|
26
37
|
private isModule;
|
|
@@ -28,7 +39,11 @@ export declare class Protocol<Modules extends ProtocolModulesRecord> extends Mod
|
|
|
28
39
|
get stateTransitionProver(): StateTransitionProvable;
|
|
29
40
|
}
|
|
30
41
|
export declare const VanillaProtocol: {
|
|
31
|
-
create(): Protocol<{
|
|
42
|
+
create(stateService?: StateService): Protocol<{
|
|
43
|
+
StateTransitionProver: typeof StateTransitionProver;
|
|
44
|
+
BlockProver: typeof BlockProver;
|
|
45
|
+
}>;
|
|
46
|
+
from<AdditonalModules extends GenericProtocolModuleRecord>(additionalModules: AdditonalModules, stateService?: StateService): Protocol<AdditonalModules & {
|
|
32
47
|
StateTransitionProver: typeof StateTransitionProver;
|
|
33
48
|
BlockProver: typeof BlockProver;
|
|
34
49
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Protocol.d.ts","sourceRoot":"","sources":["../../src/protocol/Protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EAEf,aAAa,EACb,WAAW,EACX,UAAU,EACX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mBAAmB,
|
|
1
|
+
{"version":3,"file":"Protocol.d.ts","sourceRoot":"","sources":["../../src/protocol/Protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EAEf,aAAa,EACb,WAAW,EACX,UAAU,EACX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mBAAmB,EAAa,MAAM,UAAU,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,iDAAiD,CAAC;AACxF,OAAO,EAAE,uBAAuB,EAAE,MAAM,mDAAmD,CAAC;AAC5F,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIlD,MAAM,MAAM,2BAA2B,GAAG,aAAa,CACrD,UAAU,CAAC,cAAc,CAAC,CAC3B,CAAC;AAEF,UAAU,eAAgB,SAAQ,cAAc,EAAE,aAAa;CAAG;AAElE,UAAU,yBACR,SAAQ,cAAc,EACpB,uBAAuB;CAAG;AAE9B,MAAM,WAAW,2BAA2B;IAC1C,WAAW,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC;IACzC,qBAAqB,EAAE,UAAU,CAAC,yBAAyB,CAAC,CAAC;CAC9D;AAED,MAAM,WAAW,qBACf,SAAQ,2BAA2B,EACjC,2BAA2B;CAAG;AAElC,MAAM,WAAW,kBAAkB,CAAC,OAAO,SAAS,qBAAqB;IACvE,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,KAAK,CAAC,EAAE,YAAY,CAAC;CAEtB;AAED,qBAAa,QAAQ,CACnB,OAAO,SAAS,qBAAqB,CACrC,SAAQ,eAAe,CAAC,OAAO,CAAC;WAElB,IAAI,CAAC,OAAO,SAAS,qBAAqB,EACtD,OAAO,EAAE,kBAAkB,CAAC,OAAO,CAAC;IAsB/B,UAAU,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAE/C,OAAO,CAAC,QAAQ,CAAC,4BAA4B,CAG3C;gBAEiB,UAAU,EAAE,kBAAkB,CAAC,OAAO,CAAC;IA+B1D,IAAW,YAAY,IAAI,YAAY,CAEtC;IAED,IAAW,oBAAoB,IAAI,oBAAoB,CAEtD;IAEM,cAAc,CACnB,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAChC,eAAe,EAAE,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;IAiB9D,IAAW,mBAAmB,IAAI,mBAAmB,CAEpD;IAED,OAAO,CAAC,QAAQ;IAMhB,IAAW,WAAW,IAAI,aAAa,CAMtC;IAED,IAAW,qBAAqB,IAAI,uBAAuB,CAI1D;CACF;AAED,eAAO,MAAM,eAAe;0BACJ,YAAY;+BASP,4BAA4B;qBACtC,kBAAkB;;mHAJlB,YAAY;+BAGF,4BAA4B;qBACtC,kBAAkB;;CAYpC,CAAC"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { log, ModuleContainer, } from "@proto-kit/common";
|
|
2
|
+
import { Lifecycle } from "tsyringe";
|
|
2
3
|
import { StateTransitionProver } from "../prover/statetransition/StateTransitionProver";
|
|
3
4
|
import { BlockProver } from "../prover/block/BlockProver";
|
|
5
|
+
import { StateServiceProvider } from "../state/StateServiceProvider";
|
|
6
|
+
import { ProvableTransactionHook } from "./ProvableTransactionHook";
|
|
7
|
+
import { NoopTransactionHook } from "../blockmodules/NoopTransactionHook";
|
|
4
8
|
export class Protocol extends ModuleContainer {
|
|
5
9
|
// .from() to create Protocol
|
|
6
10
|
static from(modules) {
|
|
@@ -18,9 +22,43 @@ export class Protocol extends ModuleContainer {
|
|
|
18
22
|
protocol.configure(emptyConfig);
|
|
19
23
|
return protocol;
|
|
20
24
|
}
|
|
25
|
+
constructor(definition) {
|
|
26
|
+
super(definition);
|
|
27
|
+
this.stateServiceProviderInstance = new StateServiceProvider(
|
|
28
|
+
// eslint-disable-next-line etc/no-deprecated
|
|
29
|
+
this.definition.state);
|
|
30
|
+
this.definition = definition;
|
|
31
|
+
// Register the BlockModules seperately since we need to
|
|
32
|
+
// inject them differently later
|
|
33
|
+
let atLeastOneTransactionHookRegistered = false;
|
|
34
|
+
Object.entries(definition.modules).forEach(([key, value]) => {
|
|
35
|
+
if (Object.prototype.isPrototypeOf.call(ProvableTransactionHook, value)) {
|
|
36
|
+
this.container.register("ProvableTransactionHook", { useToken: key }, { lifecycle: Lifecycle.ContainerScoped });
|
|
37
|
+
atLeastOneTransactionHookRegistered = true;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
// We need this so that tsyringe doesn't throw when no hooks are registered
|
|
41
|
+
if (!atLeastOneTransactionHookRegistered) {
|
|
42
|
+
this.container.register("ProvableTransactionHook", { useClass: NoopTransactionHook }, { lifecycle: Lifecycle.ContainerScoped });
|
|
43
|
+
}
|
|
44
|
+
// this.container.afterResolution<ProvableTransactionHook>("ProvableTransactionHook", (token, result) => {
|
|
45
|
+
// if ()
|
|
46
|
+
// })
|
|
47
|
+
}
|
|
48
|
+
get stateService() {
|
|
49
|
+
return this.stateServiceProviderInstance.stateService;
|
|
50
|
+
}
|
|
51
|
+
get stateServiceProvider() {
|
|
52
|
+
return this.stateServiceProviderInstance;
|
|
53
|
+
}
|
|
21
54
|
decorateModule(moduleName, containedModule) {
|
|
22
55
|
log.debug(`Decorated ${moduleName}`);
|
|
23
56
|
containedModule.protocol = this;
|
|
57
|
+
log.debug("Is instanceof:", containedModule instanceof ProvableTransactionHook);
|
|
58
|
+
if (containedModule instanceof ProvableTransactionHook) {
|
|
59
|
+
console.log(`Setting name to ${moduleName}`);
|
|
60
|
+
containedModule.name = moduleName;
|
|
61
|
+
}
|
|
24
62
|
super.decorateModule(moduleName, containedModule);
|
|
25
63
|
}
|
|
26
64
|
get dependencyContainer() {
|
|
@@ -39,12 +77,17 @@ export class Protocol extends ModuleContainer {
|
|
|
39
77
|
}
|
|
40
78
|
}
|
|
41
79
|
export const VanillaProtocol = {
|
|
42
|
-
create() {
|
|
80
|
+
create(stateService) {
|
|
81
|
+
return VanillaProtocol.from({}, stateService);
|
|
82
|
+
},
|
|
83
|
+
from(additionalModules, stateService) {
|
|
43
84
|
return Protocol.from({
|
|
44
85
|
modules: {
|
|
45
86
|
StateTransitionProver,
|
|
46
87
|
BlockProver,
|
|
88
|
+
...additionalModules,
|
|
47
89
|
},
|
|
90
|
+
state: stateService,
|
|
48
91
|
});
|
|
49
92
|
},
|
|
50
93
|
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { AreProofsEnabled, Configurable
|
|
1
|
+
import { AreProofsEnabled, Configurable } from "@proto-kit/common";
|
|
2
2
|
import type { Protocol, ProtocolModulesRecord } from "./Protocol";
|
|
3
|
-
export declare abstract class ProtocolModule
|
|
3
|
+
export declare abstract class ProtocolModule implements Configurable<unknown> {
|
|
4
4
|
config: {};
|
|
5
5
|
protocol?: Protocol<ProtocolModulesRecord>;
|
|
6
|
-
constructor();
|
|
7
6
|
get appChain(): AreProofsEnabled | undefined;
|
|
8
7
|
}
|
|
9
8
|
//# sourceMappingURL=ProtocolModule.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProtocolModule.d.ts","sourceRoot":"","sources":["../../src/protocol/ProtocolModule.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,YAAY,
|
|
1
|
+
{"version":3,"file":"ProtocolModule.d.ts","sourceRoot":"","sources":["../../src/protocol/ProtocolModule.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACb,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAElE,8BAAsB,cACpB,YAAW,YAAY,CAAC,OAAO,CAAC;IAEzB,MAAM,KAAM;IAEZ,QAAQ,CAAC,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;IAElD,IAAW,QAAQ,IAAI,gBAAgB,GAAG,SAAS,CAIlD;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BlockProverExecutionData } from "../prover/block/BlockProvable";
|
|
2
|
+
import { TransitioningProtocolModule } from "./TransitioningProtocolModule";
|
|
3
|
+
export declare abstract class ProvableTransactionHook extends TransitioningProtocolModule {
|
|
4
|
+
abstract onTransaction(executionData: BlockProverExecutionData): void;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=ProvableTransactionHook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProvableTransactionHook.d.ts","sourceRoot":"","sources":["../../src/protocol/ProvableTransactionHook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAE5E,8BAAsB,uBAAwB,SAAQ,2BAA2B;aAC/D,aAAa,CAAC,aAAa,EAAE,wBAAwB,GAAG,IAAI;CAC7E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransitioningProtocolModule.d.ts","sourceRoot":"","sources":["../../src/protocol/TransitioningProtocolModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,8BAAsB,2BAA4B,SAAQ,cAAc;IAC/D,IAAI,CAAC,EAAE,MAAM,CAAC;CACtB"}
|