@proto-kit/protocol 0.1.1-develop.457 → 0.1.1-develop.600
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.map +1 -1
- package/dist/blockmodules/AccountStateModule.js +10 -3
- package/dist/blockmodules/BlockHeightHook.d.ts +3 -3
- package/dist/blockmodules/BlockHeightHook.d.ts.map +1 -1
- package/dist/blockmodules/BlockHeightHook.js +5 -4
- package/dist/blockmodules/LastStateRootBlockHook.d.ts +8 -0
- package/dist/blockmodules/LastStateRootBlockHook.d.ts.map +1 -0
- package/dist/blockmodules/LastStateRootBlockHook.js +15 -0
- package/dist/blockmodules/NoopBlockHook.d.ts +6 -4
- package/dist/blockmodules/NoopBlockHook.d.ts.map +1 -1
- package/dist/blockmodules/NoopBlockHook.js +4 -4
- package/dist/blockmodules/NoopSettlementHook.d.ts +6 -0
- package/dist/blockmodules/NoopSettlementHook.d.ts.map +1 -0
- package/dist/blockmodules/NoopSettlementHook.js +18 -0
- package/dist/hooks/AccountStateHook.d.ts.map +1 -1
- package/dist/hooks/AccountStateHook.js +7 -2
- package/dist/hooks/BlockHeightHook.d.ts.map +1 -1
- package/dist/index.d.ts +9 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -3
- package/dist/model/MethodPublicOutput.d.ts +8 -0
- package/dist/model/MethodPublicOutput.d.ts.map +1 -1
- package/dist/model/MethodPublicOutput.js +1 -0
- package/dist/model/network/NetworkState.d.ts +40 -0
- package/dist/model/network/NetworkState.d.ts.map +1 -1
- package/dist/model/network/NetworkState.js +14 -2
- package/dist/model/transaction/RuntimeTransaction.d.ts +45 -20
- package/dist/model/transaction/RuntimeTransaction.d.ts.map +1 -1
- package/dist/model/transaction/RuntimeTransaction.js +68 -11
- package/dist/model/transaction/SignedTransaction.d.ts +71 -0
- package/dist/model/transaction/SignedTransaction.d.ts.map +1 -0
- package/dist/model/transaction/SignedTransaction.js +33 -0
- package/dist/model/transaction/ValueOption.d.ts +119 -0
- package/dist/model/transaction/ValueOption.d.ts.map +1 -0
- package/dist/model/transaction/ValueOption.js +24 -0
- package/dist/protocol/Protocol.d.ts +7 -3
- package/dist/protocol/Protocol.d.ts.map +1 -1
- package/dist/protocol/Protocol.js +26 -16
- package/dist/protocol/ProvableBlockHook.d.ts +2 -10
- package/dist/protocol/ProvableBlockHook.d.ts.map +1 -1
- package/dist/protocol/ProvableBlockHook.js +1 -1
- package/dist/protocol/ProvableTransactionHook.d.ts +1 -1
- package/dist/protocol/ProvableTransactionHook.d.ts.map +1 -1
- package/dist/protocol/TransitioningProtocolModule.d.ts +3 -2
- package/dist/protocol/TransitioningProtocolModule.d.ts.map +1 -1
- package/dist/protocol/TransitioningProtocolModule.js +3 -2
- package/dist/prover/block/BlockProvable.d.ts +106 -28
- package/dist/prover/block/BlockProvable.d.ts.map +1 -1
- package/dist/prover/block/BlockProvable.js +23 -5
- package/dist/prover/block/BlockProver.d.ts +29 -8
- package/dist/prover/block/BlockProver.d.ts.map +1 -1
- package/dist/prover/block/BlockProver.js +241 -77
- package/dist/prover/block/accummulators/BlockHashMerkleTree.d.ts +45 -0
- package/dist/prover/block/accummulators/BlockHashMerkleTree.d.ts.map +1 -0
- package/dist/prover/block/accummulators/BlockHashMerkleTree.js +16 -0
- package/dist/settlement/ProvableSettlementHook.d.ts +26 -0
- package/dist/settlement/ProvableSettlementHook.d.ts.map +1 -0
- package/dist/settlement/ProvableSettlementHook.js +3 -0
- package/dist/settlement/SettlementContract.d.ts +230 -0
- package/dist/settlement/SettlementContract.d.ts.map +1 -0
- package/dist/settlement/SettlementContract.js +346 -0
- package/dist/settlement/modules/NetworkStateSettlementModule.d.ts +11 -0
- package/dist/settlement/modules/NetworkStateSettlementModule.d.ts.map +1 -0
- package/dist/settlement/modules/NetworkStateSettlementModule.js +12 -0
- package/dist/state/context/RuntimeMethodExecutionContext.d.ts +75 -1
- package/dist/state/context/RuntimeMethodExecutionContext.d.ts.map +1 -1
- package/dist/state/context/RuntimeMethodExecutionContext.js +19 -1
- package/dist/utils/MinaPrefixedProvableHashList.d.ts +24 -0
- package/dist/utils/MinaPrefixedProvableHashList.d.ts.map +1 -0
- package/dist/utils/MinaPrefixedProvableHashList.js +51 -0
- package/package.json +2 -2
- package/src/blockmodules/AccountStateModule.ts +17 -6
- package/src/blockmodules/BlockHeightHook.ts +5 -8
- package/src/blockmodules/LastStateRootBlockHook.ts +26 -0
- package/src/blockmodules/NoopBlockHook.ts +15 -11
- package/src/blockmodules/NoopSettlementHook.ts +21 -0
- package/src/blockmodules/SequenceStateTransactionModule.ts +25 -0
- package/src/index.ts +9 -3
- package/src/model/MethodPublicOutput.ts +3 -2
- package/src/model/network/NetworkState.ts +15 -3
- package/src/model/transaction/RuntimeTransaction.ts +90 -16
- package/src/model/transaction/SignedTransaction.ts +54 -0
- package/src/model/transaction/ValueOption.ts +28 -0
- package/src/protocol/Protocol.ts +49 -31
- package/src/protocol/ProvableBlockHook.ts +10 -13
- package/src/protocol/ProvableTransactionHook.ts +2 -1
- package/src/protocol/TransitioningProtocolModule.ts +3 -2
- package/src/prover/block/BlockProvable.ts +39 -6
- package/src/prover/block/BlockProver.ts +473 -143
- package/src/prover/block/accummulators/BlockHashMerkleTree.ts +16 -0
- package/src/settlement/ProvableSettlementHook.ts +37 -0
- package/src/settlement/SettlementContract.ts +444 -0
- package/src/settlement/modules/NetworkStateSettlementModule.ts +39 -0
- package/src/state/context/RuntimeMethodExecutionContext.ts +18 -1
- package/src/utils/MinaPrefixedProvableHashList.ts +72 -0
- package/test/BlockProver.test.ts +2 -3
- package/src/model/transaction/ProtocolTransaction.ts +0 -25
- package/src/prover/block/BlockTransactionPosition.ts +0 -34
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { Field, Poseidon, PublicKey, Struct, UInt64 } from "o1js";
|
|
1
|
+
import { Bool, Field, Poseidon, PublicKey, Struct, UInt64, } from "o1js";
|
|
2
|
+
import { PublicKeyOption, UInt64Option } from "./ValueOption";
|
|
3
|
+
import { EMPTY_PUBLICKEY, EMPTY_PUBLICKEY_X } from "@proto-kit/common";
|
|
2
4
|
/**
|
|
3
5
|
* This struct is used to expose transaction information to the runtime method
|
|
4
6
|
* execution. This class has not all data included in transactions on purpose.
|
|
@@ -6,24 +8,79 @@ import { Field, Poseidon, PublicKey, Struct, UInt64 } from "o1js";
|
|
|
6
8
|
*/
|
|
7
9
|
export class RuntimeTransaction extends Struct({
|
|
8
10
|
methodId: Field,
|
|
9
|
-
nonce: UInt64,
|
|
10
|
-
sender: PublicKey,
|
|
11
11
|
argsHash: Field,
|
|
12
|
+
nonce: UInt64Option,
|
|
13
|
+
sender: PublicKeyOption,
|
|
12
14
|
}) {
|
|
13
|
-
static
|
|
15
|
+
static fromTransaction(input) {
|
|
16
|
+
return new RuntimeTransaction({
|
|
17
|
+
methodId: input.methodId,
|
|
18
|
+
argsHash: input.argsHash,
|
|
19
|
+
nonce: UInt64Option.fromValue(input.nonce),
|
|
20
|
+
sender: PublicKeyOption.fromValue(input.sender),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
static fromMessage({ methodId, argsHash, }) {
|
|
14
24
|
return new RuntimeTransaction({
|
|
15
25
|
methodId,
|
|
16
|
-
nonce,
|
|
17
|
-
sender,
|
|
18
26
|
argsHash,
|
|
27
|
+
nonce: UInt64Option.none(UInt64.zero),
|
|
28
|
+
sender: PublicKeyOption.none(EMPTY_PUBLICKEY),
|
|
19
29
|
});
|
|
20
30
|
}
|
|
21
|
-
|
|
22
|
-
return
|
|
31
|
+
static dummyTransaction() {
|
|
32
|
+
return new RuntimeTransaction({
|
|
33
|
+
methodId: Field(0),
|
|
34
|
+
nonce: new UInt64Option({
|
|
35
|
+
isSome: Bool(true),
|
|
36
|
+
value: UInt64.zero,
|
|
37
|
+
}),
|
|
38
|
+
sender: new PublicKeyOption({
|
|
39
|
+
isSome: Bool(true),
|
|
40
|
+
value: EMPTY_PUBLICKEY,
|
|
41
|
+
}),
|
|
42
|
+
argsHash: Field(0),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
assertTransactionType(isMessage) {
|
|
46
|
+
const isTransaction = isMessage.not();
|
|
47
|
+
// isSome has to be true when it is a transaction, otherwise false
|
|
48
|
+
this.nonce.isSome
|
|
49
|
+
.equals(isTransaction)
|
|
50
|
+
.assertTrue("Nonce is not right option isSome for type");
|
|
51
|
+
this.sender.isSome
|
|
52
|
+
.equals(isTransaction)
|
|
53
|
+
.assertTrue("Sender is not right option isSome for type");
|
|
54
|
+
this.sender.value.x
|
|
55
|
+
.equals(EMPTY_PUBLICKEY_X)
|
|
56
|
+
.equals(isMessage)
|
|
57
|
+
.assertTrue("Transaction sender is not set to dummy");
|
|
58
|
+
}
|
|
59
|
+
hashData() {
|
|
60
|
+
return [
|
|
23
61
|
this.methodId,
|
|
24
|
-
...this.sender.toFields(),
|
|
25
|
-
...this.nonce.toFields(),
|
|
62
|
+
...this.sender.value.toFields(),
|
|
63
|
+
...this.nonce.value.toFields(),
|
|
26
64
|
this.argsHash,
|
|
27
|
-
]
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
static fromHashData(fields) {
|
|
68
|
+
// sender is 2nd and the first element is x (2nd isOdd)
|
|
69
|
+
const isMessage = fields[1].equals(EMPTY_PUBLICKEY_X);
|
|
70
|
+
return new RuntimeTransaction({
|
|
71
|
+
methodId: fields[0],
|
|
72
|
+
sender: new PublicKeyOption({
|
|
73
|
+
isSome: isMessage.not(),
|
|
74
|
+
value: PublicKey.fromFields([fields[1], fields[2]]),
|
|
75
|
+
}),
|
|
76
|
+
nonce: new UInt64Option({
|
|
77
|
+
isSome: isMessage.not(),
|
|
78
|
+
value: UInt64.fromFields([fields[3]]),
|
|
79
|
+
}),
|
|
80
|
+
argsHash: fields[4],
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
hash() {
|
|
84
|
+
return Poseidon.hash(this.hashData());
|
|
28
85
|
}
|
|
29
86
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Bool, Field, Signature, UInt64 } from "o1js";
|
|
2
|
+
import { RuntimeTransaction } from "./RuntimeTransaction";
|
|
3
|
+
declare const SignedTransaction_base: (new (value: {
|
|
4
|
+
transaction: RuntimeTransaction;
|
|
5
|
+
signature: Signature;
|
|
6
|
+
}) => {
|
|
7
|
+
transaction: RuntimeTransaction;
|
|
8
|
+
signature: Signature;
|
|
9
|
+
}) & {
|
|
10
|
+
_isStruct: true;
|
|
11
|
+
} & import("o1js/dist/node/lib/provable").Provable<{
|
|
12
|
+
transaction: RuntimeTransaction;
|
|
13
|
+
signature: Signature;
|
|
14
|
+
}> & {
|
|
15
|
+
toInput: (x: {
|
|
16
|
+
transaction: RuntimeTransaction;
|
|
17
|
+
signature: Signature;
|
|
18
|
+
}) => {
|
|
19
|
+
fields?: import("o1js/dist/node/lib/field").Field[] | undefined;
|
|
20
|
+
packed?: [import("o1js/dist/node/lib/field").Field, number][] | undefined;
|
|
21
|
+
};
|
|
22
|
+
toJSON: (x: {
|
|
23
|
+
transaction: RuntimeTransaction;
|
|
24
|
+
signature: Signature;
|
|
25
|
+
}) => {
|
|
26
|
+
transaction: {
|
|
27
|
+
methodId: string;
|
|
28
|
+
argsHash: string;
|
|
29
|
+
nonce: {
|
|
30
|
+
isSome: boolean;
|
|
31
|
+
value: any;
|
|
32
|
+
};
|
|
33
|
+
sender: {
|
|
34
|
+
isSome: boolean;
|
|
35
|
+
value: any;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
signature: any;
|
|
39
|
+
};
|
|
40
|
+
fromJSON: (x: {
|
|
41
|
+
transaction: {
|
|
42
|
+
methodId: string;
|
|
43
|
+
argsHash: string;
|
|
44
|
+
nonce: {
|
|
45
|
+
isSome: boolean;
|
|
46
|
+
value: any;
|
|
47
|
+
};
|
|
48
|
+
sender: {
|
|
49
|
+
isSome: boolean;
|
|
50
|
+
value: any;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
signature: any;
|
|
54
|
+
}) => {
|
|
55
|
+
transaction: RuntimeTransaction;
|
|
56
|
+
signature: Signature;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export declare class SignedTransaction extends SignedTransaction_base {
|
|
60
|
+
static getSignatureData(args: {
|
|
61
|
+
methodId: Field;
|
|
62
|
+
nonce: UInt64;
|
|
63
|
+
argsHash: Field;
|
|
64
|
+
}): Field[];
|
|
65
|
+
static dummy(): SignedTransaction;
|
|
66
|
+
hash(): Field;
|
|
67
|
+
getSignatureData(): Field[];
|
|
68
|
+
validateSignature(): Bool;
|
|
69
|
+
}
|
|
70
|
+
export {};
|
|
71
|
+
//# sourceMappingURL=SignedTransaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SignedTransaction.d.ts","sourceRoot":"","sources":["../../../src/model/transaction/SignedTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,KAAK,EAEL,SAAS,EAET,MAAM,EACP,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1D,qBAAa,iBAAkB,SAAQ,sBAGrC;WACc,gBAAgB,CAAC,IAAI,EAAE;QACnC,QAAQ,EAAE,KAAK,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,KAAK,CAAC;KACjB,GAAG,KAAK,EAAE;WAIG,KAAK,IAAI,iBAAiB;IAWjC,IAAI,IAAI,KAAK;IAIb,gBAAgB,IAAI,KAAK,EAAE;IAS3B,iBAAiB,IAAI,IAAI;CAMjC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Field, Scalar, Signature, Struct, } from "o1js";
|
|
2
|
+
import { RuntimeTransaction } from "./RuntimeTransaction";
|
|
3
|
+
export class SignedTransaction extends Struct({
|
|
4
|
+
transaction: RuntimeTransaction,
|
|
5
|
+
signature: Signature,
|
|
6
|
+
}) {
|
|
7
|
+
static getSignatureData(args) {
|
|
8
|
+
return [args.methodId, ...args.nonce.value.toFields(), args.argsHash];
|
|
9
|
+
}
|
|
10
|
+
static dummy() {
|
|
11
|
+
return new SignedTransaction({
|
|
12
|
+
transaction: RuntimeTransaction.dummyTransaction(),
|
|
13
|
+
signature: Signature.fromObject({
|
|
14
|
+
s: Scalar.from(0),
|
|
15
|
+
r: Field(0),
|
|
16
|
+
}),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
hash() {
|
|
20
|
+
return this.transaction.hash();
|
|
21
|
+
}
|
|
22
|
+
getSignatureData() {
|
|
23
|
+
const { methodId, argsHash, nonce } = this.transaction;
|
|
24
|
+
return SignedTransaction.getSignatureData({
|
|
25
|
+
nonce: nonce.value,
|
|
26
|
+
methodId,
|
|
27
|
+
argsHash,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
validateSignature() {
|
|
31
|
+
return this.signature.verify(this.transaction.sender.value, this.getSignatureData());
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { PublicKey, UInt64 } from "o1js";
|
|
2
|
+
declare const UInt64Option_base: {
|
|
3
|
+
new (value: {
|
|
4
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
5
|
+
value: UInt64;
|
|
6
|
+
}): {
|
|
7
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
8
|
+
value: UInt64;
|
|
9
|
+
};
|
|
10
|
+
fromValue(value: UInt64): {
|
|
11
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
12
|
+
value: UInt64;
|
|
13
|
+
};
|
|
14
|
+
none(value: UInt64): {
|
|
15
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
16
|
+
value: UInt64;
|
|
17
|
+
};
|
|
18
|
+
_isStruct: true;
|
|
19
|
+
toFields: (value: {
|
|
20
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
21
|
+
value: UInt64;
|
|
22
|
+
}) => import("o1js/dist/node/lib/field").Field[];
|
|
23
|
+
toAuxiliary: (value?: {
|
|
24
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
25
|
+
value: UInt64;
|
|
26
|
+
} | undefined) => any[];
|
|
27
|
+
fromFields: (fields: import("o1js/dist/node/lib/field").Field[], aux: any[]) => {
|
|
28
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
29
|
+
value: UInt64;
|
|
30
|
+
};
|
|
31
|
+
sizeInFields(): number;
|
|
32
|
+
check: (value: {
|
|
33
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
34
|
+
value: UInt64;
|
|
35
|
+
}) => void;
|
|
36
|
+
toInput: (x: {
|
|
37
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
38
|
+
value: UInt64;
|
|
39
|
+
}) => {
|
|
40
|
+
fields?: import("o1js/dist/node/lib/field").Field[] | undefined;
|
|
41
|
+
packed?: [import("o1js/dist/node/lib/field").Field, number][] | undefined;
|
|
42
|
+
};
|
|
43
|
+
toJSON: (x: {
|
|
44
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
45
|
+
value: UInt64;
|
|
46
|
+
}) => {
|
|
47
|
+
isSome: boolean;
|
|
48
|
+
value: any;
|
|
49
|
+
};
|
|
50
|
+
fromJSON: (x: {
|
|
51
|
+
isSome: boolean;
|
|
52
|
+
value: any;
|
|
53
|
+
}) => {
|
|
54
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
55
|
+
value: UInt64;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export declare class UInt64Option extends UInt64Option_base {
|
|
59
|
+
}
|
|
60
|
+
declare const PublicKeyOption_base: {
|
|
61
|
+
new (value: {
|
|
62
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
63
|
+
value: PublicKey;
|
|
64
|
+
}): {
|
|
65
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
66
|
+
value: PublicKey;
|
|
67
|
+
};
|
|
68
|
+
fromValue(value: PublicKey): {
|
|
69
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
70
|
+
value: PublicKey;
|
|
71
|
+
};
|
|
72
|
+
none(value: PublicKey): {
|
|
73
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
74
|
+
value: PublicKey;
|
|
75
|
+
};
|
|
76
|
+
_isStruct: true;
|
|
77
|
+
toFields: (value: {
|
|
78
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
79
|
+
value: PublicKey;
|
|
80
|
+
}) => import("o1js/dist/node/lib/field").Field[];
|
|
81
|
+
toAuxiliary: (value?: {
|
|
82
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
83
|
+
value: PublicKey;
|
|
84
|
+
} | undefined) => any[];
|
|
85
|
+
fromFields: (fields: import("o1js/dist/node/lib/field").Field[], aux: any[]) => {
|
|
86
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
87
|
+
value: PublicKey;
|
|
88
|
+
};
|
|
89
|
+
sizeInFields(): number;
|
|
90
|
+
check: (value: {
|
|
91
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
92
|
+
value: PublicKey;
|
|
93
|
+
}) => void;
|
|
94
|
+
toInput: (x: {
|
|
95
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
96
|
+
value: PublicKey;
|
|
97
|
+
}) => {
|
|
98
|
+
fields?: import("o1js/dist/node/lib/field").Field[] | undefined;
|
|
99
|
+
packed?: [import("o1js/dist/node/lib/field").Field, number][] | undefined;
|
|
100
|
+
};
|
|
101
|
+
toJSON: (x: {
|
|
102
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
103
|
+
value: PublicKey;
|
|
104
|
+
}) => {
|
|
105
|
+
isSome: boolean;
|
|
106
|
+
value: any;
|
|
107
|
+
};
|
|
108
|
+
fromJSON: (x: {
|
|
109
|
+
isSome: boolean;
|
|
110
|
+
value: any;
|
|
111
|
+
}) => {
|
|
112
|
+
isSome: import("o1js/dist/node/lib/bool").Bool;
|
|
113
|
+
value: PublicKey;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
export declare class PublicKeyOption extends PublicKeyOption_base {
|
|
117
|
+
}
|
|
118
|
+
export {};
|
|
119
|
+
//# sourceMappingURL=ValueOption.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValueOption.d.ts","sourceRoot":"","sources":["../../../src/model/transaction/ValueOption.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,SAAS,EAAU,MAAM,EAAE,MAAM,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBzE,qBAAa,YAAa,SAAQ,iBAAoC;CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEzE,qBAAa,eAAgB,SAAQ,oBAEpC;CAAG"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Bool, PublicKey, Struct, UInt64 } from "o1js";
|
|
2
|
+
function genericOptionFactory(valueType) {
|
|
3
|
+
return class Generic extends Struct({
|
|
4
|
+
isSome: Bool,
|
|
5
|
+
value: valueType,
|
|
6
|
+
}) {
|
|
7
|
+
static fromValue(value) {
|
|
8
|
+
return new Generic({
|
|
9
|
+
isSome: Bool(true),
|
|
10
|
+
value,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
static none(value) {
|
|
14
|
+
return new Generic({
|
|
15
|
+
isSome: Bool(false),
|
|
16
|
+
value,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export class UInt64Option extends genericOptionFactory(UInt64) {
|
|
22
|
+
}
|
|
23
|
+
export class PublicKeyOption extends genericOptionFactory(PublicKey) {
|
|
24
|
+
}
|
|
@@ -7,15 +7,19 @@ import { StateService } from "../state/StateService";
|
|
|
7
7
|
import { ProtocolModule } from "./ProtocolModule";
|
|
8
8
|
import { ProtocolEnvironment } from "./ProtocolEnvironment";
|
|
9
9
|
import { AccountStateModule } from "../blockmodules/AccountStateModule";
|
|
10
|
+
import { BlockHeightHook } from "../blockmodules/BlockHeightHook";
|
|
11
|
+
import { LastStateRootBlockHook } from "../blockmodules/LastStateRootBlockHook";
|
|
10
12
|
export type GenericProtocolModuleRecord = ModulesRecord<TypedClass<ProtocolModule<unknown>>>;
|
|
11
13
|
interface BlockProverType extends ProtocolModule, BlockProvable {
|
|
12
14
|
}
|
|
13
15
|
interface StateTransitionProverType extends ProtocolModule, StateTransitionProvable {
|
|
14
16
|
}
|
|
15
|
-
export interface ProtocolCustomModulesRecord {
|
|
17
|
+
export interface ProtocolCustomModulesRecord extends GenericProtocolModuleRecord {
|
|
16
18
|
BlockProver: TypedClass<BlockProverType>;
|
|
17
19
|
StateTransitionProver: TypedClass<StateTransitionProverType>;
|
|
18
20
|
AccountState: TypedClass<AccountStateModule>;
|
|
21
|
+
BlockHeight: TypedClass<BlockHeightHook>;
|
|
22
|
+
LastStateRoot: TypedClass<LastStateRootBlockHook>;
|
|
19
23
|
}
|
|
20
24
|
export interface ProtocolModulesRecord extends GenericProtocolModuleRecord, ProtocolCustomModulesRecord {
|
|
21
25
|
}
|
|
@@ -38,8 +42,8 @@ export declare class Protocol<Modules extends ProtocolModulesRecord> extends Mod
|
|
|
38
42
|
create(childContainerProvider: ChildContainerProvider): void;
|
|
39
43
|
}
|
|
40
44
|
export declare const VanillaProtocol: {
|
|
41
|
-
create(): TypedClass<Protocol<
|
|
42
|
-
from<AdditonalModules extends GenericProtocolModuleRecord>(additionalModules: AdditonalModules): TypedClass<Protocol<
|
|
45
|
+
create(): TypedClass<Protocol<ProtocolCustomModulesRecord>>;
|
|
46
|
+
from<AdditonalModules extends GenericProtocolModuleRecord>(additionalModules: AdditonalModules): TypedClass<Protocol<ProtocolCustomModulesRecord & AdditonalModules>>;
|
|
43
47
|
};
|
|
44
48
|
export {};
|
|
45
49
|
//# sourceMappingURL=Protocol.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Protocol.d.ts","sourceRoot":"","sources":["../../src/protocol/Protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EAEtB,eAAe,EACf,aAAa,EACb,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;AAE9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,mDAAmD,CAAC;AAE5F,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"Protocol.d.ts","sourceRoot":"","sources":["../../src/protocol/Protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EAEtB,eAAe,EACf,aAAa,EACb,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;AAE9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,mDAAmD,CAAC;AAE5F,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAGxE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAUhF,MAAM,MAAM,2BAA2B,GAAG,aAAa,CACrD,UAAU,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CACpC,CAAC;AAEF,UAAU,eAAgB,SAAQ,cAAc,EAAE,aAAa;CAAG;AAElE,UAAU,yBACR,SAAQ,cAAc,EACpB,uBAAuB;CAAG;AAE9B,MAAM,WAAW,2BACf,SAAQ,2BAA2B;IACnC,WAAW,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC;IACzC,qBAAqB,EAAE,UAAU,CAAC,yBAAyB,CAAC,CAAC;IAC7D,YAAY,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAC7C,WAAW,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC;IACzC,aAAa,EAAE,UAAU,CAAC,sBAAsB,CAAC,CAAC;CACnD;AAED,MAAM,WAAW,qBACf,SAAQ,2BAA2B,EACjC,2BAA2B;CAAG;AAElC,MAAM,WAAW,kBAAkB,CAAC,OAAO,SAAS,qBAAqB;IACvE,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CACjC;AAED,qBAAa,QAAQ,CAAC,OAAO,SAAS,qBAAqB,CACzD,SAAQ,eAAe,CAAC,OAAO,CAC/B,YAAW,mBAAmB;WAGhB,IAAI,CAAC,OAAO,SAAS,qBAAqB,EACtD,OAAO,EAAE,kBAAkB,CAAC,OAAO,CAAC,GACnC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAQzB,UAAU,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC;gBAE5B,UAAU,EAAE,kBAAkB,CAAC,OAAO,CAAC;IAK1D,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;IAY9D,IAAW,mBAAmB,IAAI,mBAAmB,CAEpD;IAED,OAAO,CAAC,QAAQ;IAMhB,IAAW,WAAW,IAAI,aAAa,CAMtC;IAED,IAAW,qBAAqB,IAAI,uBAAuB,CAI1D;IAEM,mBAAmB,IAAI,gBAAgB;IAIvC,MAAM,CAAC,sBAAsB,EAAE,sBAAsB;CAoD7D;AAED,eAAO,MAAM,eAAe;;;CAmB3B,CAAC"}
|
|
@@ -8,9 +8,13 @@ import { AccountStateModule } from "../blockmodules/AccountStateModule";
|
|
|
8
8
|
import { ProvableBlockHook } from "./ProvableBlockHook";
|
|
9
9
|
import { NoopBlockHook } from "../blockmodules/NoopBlockHook";
|
|
10
10
|
import { BlockHeightHook } from "../blockmodules/BlockHeightHook";
|
|
11
|
+
import { LastStateRootBlockHook } from "../blockmodules/LastStateRootBlockHook";
|
|
12
|
+
import { ProvableSettlementHook } from "../settlement/ProvableSettlementHook";
|
|
13
|
+
import { NoopSettlementHook } from "../blockmodules/NoopSettlementHook";
|
|
11
14
|
const PROTOCOL_INJECTION_TOKENS = {
|
|
12
15
|
ProvableTransactionHook: "ProvableTransactionHook",
|
|
13
16
|
ProvableBlockHook: "ProvableBlockHook",
|
|
17
|
+
ProvableSettlementHook: "ProvableSettlementHook",
|
|
14
18
|
};
|
|
15
19
|
export class Protocol extends ModuleContainer {
|
|
16
20
|
// .from() to create Protocol
|
|
@@ -60,25 +64,30 @@ export class Protocol extends ModuleContainer {
|
|
|
60
64
|
super.create(childContainerProvider);
|
|
61
65
|
// Register the BlockModules seperately since we need to
|
|
62
66
|
// inject them differently later
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
const ABSTRACT_MODULE_TYPES = [
|
|
68
|
+
{ type: ProvableTransactionHook, defaultType: NoopTransactionHook },
|
|
69
|
+
{ type: ProvableBlockHook, defaultType: NoopBlockHook },
|
|
70
|
+
{ type: ProvableSettlementHook, defaultType: NoopSettlementHook },
|
|
71
|
+
];
|
|
72
|
+
ABSTRACT_MODULE_TYPES.forEach((moduleTypeRegistration) => {
|
|
73
|
+
const abstractType = moduleTypeRegistration.type;
|
|
74
|
+
const implementingModules = Object.entries(this.definition.modules).filter(([, value]) => Object.prototype.isPrototypeOf.call(abstractType, value));
|
|
75
|
+
const newInjectionToken = PROTOCOL_INJECTION_TOKENS[abstractType.name];
|
|
76
|
+
if (newInjectionToken === undefined) {
|
|
77
|
+
log.error("Can't inject hook under the underlying hook token: Alias not found in mapping");
|
|
78
|
+
return;
|
|
69
79
|
}
|
|
70
|
-
|
|
71
|
-
this.container.register(
|
|
72
|
-
|
|
80
|
+
implementingModules.forEach(([key]) => {
|
|
81
|
+
this.container.register(abstractType.name, { useToken: key }, { lifecycle: Lifecycle.ContainerScoped });
|
|
82
|
+
});
|
|
83
|
+
if (implementingModules.length === 0) {
|
|
84
|
+
// This type annotation shouldn't change anything but is necessary
|
|
85
|
+
// bcs tsyringe complains
|
|
86
|
+
const { defaultType } = moduleTypeRegistration;
|
|
87
|
+
// Register default (noop) version
|
|
88
|
+
this.container.register(abstractType.name, { useClass: defaultType }, { lifecycle: Lifecycle.ContainerScoped });
|
|
73
89
|
}
|
|
74
90
|
});
|
|
75
|
-
// We need this so that tsyringe doesn't throw when no hooks are registered
|
|
76
|
-
if (!atLeastOneTransactionHookRegistered) {
|
|
77
|
-
this.container.register(PROTOCOL_INJECTION_TOKENS.ProvableTransactionHook, { useClass: NoopTransactionHook }, { lifecycle: Lifecycle.ContainerScoped });
|
|
78
|
-
}
|
|
79
|
-
if (!atLeastOneBlockHookRegistered) {
|
|
80
|
-
this.container.register(PROTOCOL_INJECTION_TOKENS.ProvableBlockHook, { useClass: NoopBlockHook }, { lifecycle: Lifecycle.ContainerScoped });
|
|
81
|
-
}
|
|
82
91
|
}
|
|
83
92
|
}
|
|
84
93
|
export const VanillaProtocol = {
|
|
@@ -92,6 +101,7 @@ export const VanillaProtocol = {
|
|
|
92
101
|
BlockProver,
|
|
93
102
|
AccountState: AccountStateModule,
|
|
94
103
|
BlockHeight: BlockHeightHook,
|
|
104
|
+
LastStateRoot: LastStateRootBlockHook,
|
|
95
105
|
...additionalModules,
|
|
96
106
|
},
|
|
97
107
|
});
|
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import type { BlockProverState } from "../prover/block/BlockProver";
|
|
2
2
|
import { NetworkState } from "../model/network/NetworkState";
|
|
3
3
|
import { TransitioningProtocolModule } from "./TransitioningProtocolModule";
|
|
4
|
-
export interface BeforeBlockParameters {
|
|
5
|
-
state: BlockProverState;
|
|
6
|
-
networkState: NetworkState;
|
|
7
|
-
}
|
|
8
|
-
export interface AfterBlockParameters {
|
|
9
|
-
state: BlockProverState;
|
|
10
|
-
networkState: NetworkState;
|
|
11
|
-
}
|
|
12
4
|
export declare abstract class ProvableBlockHook<Config> extends TransitioningProtocolModule<Config> {
|
|
13
|
-
abstract beforeBlock(
|
|
14
|
-
abstract afterBlock(
|
|
5
|
+
abstract beforeBlock(networkState: NetworkState, state: BlockProverState): NetworkState;
|
|
6
|
+
abstract afterBlock(networkState: NetworkState, state: BlockProverState): NetworkState;
|
|
15
7
|
}
|
|
16
8
|
//# sourceMappingURL=ProvableBlockHook.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProvableBlockHook.d.ts","sourceRoot":"","sources":["../../src/protocol/ProvableBlockHook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"ProvableBlockHook.d.ts","sourceRoot":"","sources":["../../src/protocol/ProvableBlockHook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAG5E,8BAAsB,iBAAiB,CACrC,MAAM,CACN,SAAQ,2BAA2B,CAAC,MAAM,CAAC;aAC3B,WAAW,CACzB,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,gBAAgB,GACtB,YAAY;aAEC,UAAU,CACxB,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,gBAAgB,GACtB,YAAY;CAChB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { TransitioningProtocolModule } from "./TransitioningProtocolModule";
|
|
2
|
-
// Purpose is to
|
|
2
|
+
// Purpose is to build transition from -> to network state
|
|
3
3
|
export class ProvableBlockHook extends TransitioningProtocolModule {
|
|
4
4
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { NoConfig } from "@proto-kit/common";
|
|
1
2
|
import { BlockProverExecutionData } from "../prover/block/BlockProvable";
|
|
2
3
|
import { TransitioningProtocolModule } from "./TransitioningProtocolModule";
|
|
3
|
-
import { NoConfig } from "@proto-kit/common";
|
|
4
4
|
export declare abstract class ProvableTransactionHook<Config = NoConfig> extends TransitioningProtocolModule<Config> {
|
|
5
5
|
abstract onTransaction(executionData: BlockProverExecutionData): void;
|
|
6
6
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProvableTransactionHook.d.ts","sourceRoot":"","sources":["../../src/protocol/ProvableTransactionHook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ProvableTransactionHook.d.ts","sourceRoot":"","sources":["../../src/protocol/ProvableTransactionHook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAE5E,8BAAsB,uBAAuB,CAC3C,MAAM,GAAG,QAAQ,CACjB,SAAQ,2BAA2B,CAAC,MAAM,CAAC;aAC3B,aAAa,CAAC,aAAa,EAAE,wBAAwB,GAAG,IAAI;CAC7E"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ProtocolModule } from "./ProtocolModule";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* TransitioningProtocolModule is a base interface that allows inheriting
|
|
4
|
+
* classes to use State and StateMap since it requires the implementation
|
|
5
|
+
* of a `name: string` property, which those classes need to function.
|
|
5
6
|
*/
|
|
6
7
|
export declare abstract class TransitioningProtocolModule<Config> extends ProtocolModule<Config> {
|
|
7
8
|
name?: string;
|
|
@@ -1 +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
|
|
1
|
+
{"version":3,"file":"TransitioningProtocolModule.d.ts","sourceRoot":"","sources":["../../src/protocol/TransitioningProtocolModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;GAIG;AACH,8BAAsB,2BAA2B,CAC/C,MAAM,CACN,SAAQ,cAAc,CAAC,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;CACtB"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ProtocolModule } from "./ProtocolModule";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* TransitioningProtocolModule is a base interface that allows inheriting
|
|
4
|
+
* classes to use State and StateMap since it requires the implementation
|
|
5
|
+
* of a `name: string` property, which those classes need to function.
|
|
5
6
|
*/
|
|
6
7
|
export class TransitioningProtocolModule extends ProtocolModule {
|
|
7
8
|
}
|