@proto-kit/protocol 0.1.1-develop.165 → 0.1.1-develop.1661
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/Constants.js +1 -0
- package/dist/Constants.js.map +1 -0
- package/dist/hashing/mina-prefixes.d.ts +10 -0
- package/dist/hashing/mina-prefixes.d.ts.map +1 -0
- package/dist/hashing/mina-prefixes.js +10 -0
- package/dist/hashing/mina-prefixes.js.map +1 -0
- package/dist/hashing/protokit-prefixes.d.ts +10 -0
- package/dist/hashing/protokit-prefixes.d.ts.map +1 -0
- package/dist/hashing/protokit-prefixes.js +24 -0
- package/dist/hashing/protokit-prefixes.js.map +1 -0
- package/dist/hooks/AccountStateHook.d.ts +52 -0
- package/dist/hooks/AccountStateHook.d.ts.map +1 -0
- package/dist/hooks/AccountStateHook.js +52 -0
- package/dist/hooks/AccountStateHook.js.map +1 -0
- package/dist/hooks/BlockHeightHook.d.ts +7 -0
- package/dist/hooks/BlockHeightHook.d.ts.map +1 -0
- package/dist/hooks/BlockHeightHook.js +16 -0
- package/dist/hooks/BlockHeightHook.js.map +1 -0
- package/dist/hooks/LastStateRootBlockHook.d.ts +7 -0
- package/dist/hooks/LastStateRootBlockHook.d.ts.map +1 -0
- package/dist/hooks/LastStateRootBlockHook.js +16 -0
- package/dist/hooks/LastStateRootBlockHook.js.map +1 -0
- package/dist/hooks/NoopBlockHook.d.ts +8 -0
- package/dist/hooks/NoopBlockHook.d.ts.map +1 -0
- package/dist/hooks/NoopBlockHook.js +10 -0
- package/dist/hooks/NoopBlockHook.js.map +1 -0
- package/dist/hooks/NoopSettlementHook.d.ts +6 -0
- package/dist/hooks/NoopSettlementHook.d.ts.map +1 -0
- package/dist/{prover/statetransition/StateTransitionWitnessProvider.js → hooks/NoopSettlementHook.js} +8 -7
- package/dist/hooks/NoopSettlementHook.js.map +1 -0
- package/dist/hooks/NoopTransactionHook.d.ts +6 -0
- package/dist/hooks/NoopTransactionHook.d.ts.map +1 -0
- package/dist/hooks/NoopTransactionHook.js +11 -0
- package/dist/hooks/NoopTransactionHook.js.map +1 -0
- package/dist/index.d.ts +51 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -9
- package/dist/index.js.map +1 -0
- package/dist/model/AppliedStateTransitionBatch.d.ts +114 -0
- package/dist/model/AppliedStateTransitionBatch.d.ts.map +1 -0
- package/dist/model/AppliedStateTransitionBatch.js +16 -0
- package/dist/model/AppliedStateTransitionBatch.js.map +1 -0
- package/dist/model/MethodPublicOutput.d.ts +83 -29
- package/dist/model/MethodPublicOutput.d.ts.map +1 -1
- package/dist/model/MethodPublicOutput.js +4 -1
- package/dist/model/MethodPublicOutput.js.map +1 -0
- package/dist/model/Option.d.ts +70 -42
- package/dist/model/Option.d.ts.map +1 -1
- package/dist/model/Option.js +62 -47
- package/dist/model/Option.js.map +1 -0
- package/dist/model/Path.d.ts +4 -3
- package/dist/model/Path.d.ts.map +1 -1
- package/dist/model/Path.js +6 -5
- package/dist/model/Path.js.map +1 -0
- package/dist/model/RuntimeLike.d.ts +11 -0
- package/dist/model/RuntimeLike.d.ts.map +1 -0
- package/dist/model/RuntimeLike.js +2 -0
- package/dist/model/RuntimeLike.js.map +1 -0
- package/dist/model/StateTransition.d.ts +67 -16
- package/dist/model/StateTransition.d.ts.map +1 -1
- package/dist/model/StateTransition.js +18 -2
- package/dist/model/StateTransition.js.map +1 -0
- package/dist/model/StateTransitionProvableBatch.d.ts +389 -16
- package/dist/model/StateTransitionProvableBatch.d.ts.map +1 -1
- package/dist/model/StateTransitionProvableBatch.js +88 -11
- package/dist/model/StateTransitionProvableBatch.js.map +1 -0
- package/dist/model/network/NetworkState.d.ts +105 -9
- package/dist/model/network/NetworkState.d.ts.map +1 -1
- package/dist/model/network/NetworkState.js +20 -2
- package/dist/model/network/NetworkState.js.map +1 -0
- package/dist/model/transaction/RuntimeTransaction.d.ts +96 -28
- package/dist/model/transaction/RuntimeTransaction.d.ts.map +1 -1
- package/dist/model/transaction/RuntimeTransaction.js +75 -11
- package/dist/model/transaction/RuntimeTransaction.js.map +1 -0
- package/dist/model/transaction/SignedTransaction.d.ts +107 -0
- package/dist/model/transaction/SignedTransaction.d.ts.map +1 -0
- package/dist/model/transaction/SignedTransaction.js +34 -0
- package/dist/model/transaction/SignedTransaction.js.map +1 -0
- package/dist/model/transaction/ValueOption.d.ts +173 -0
- package/dist/model/transaction/ValueOption.d.ts.map +1 -0
- package/dist/model/transaction/ValueOption.js +25 -0
- package/dist/model/transaction/ValueOption.js.map +1 -0
- package/dist/protocol/Protocol.d.ts +27 -25
- package/dist/protocol/Protocol.d.ts.map +1 -1
- package/dist/protocol/Protocol.js +98 -28
- package/dist/protocol/Protocol.js.map +1 -0
- package/dist/protocol/ProtocolEnvironment.d.ts +9 -0
- package/dist/protocol/ProtocolEnvironment.d.ts.map +1 -0
- package/dist/protocol/ProtocolEnvironment.js +2 -0
- package/dist/protocol/ProtocolEnvironment.js.map +1 -0
- package/dist/protocol/ProtocolModule.d.ts +7 -7
- package/dist/protocol/ProtocolModule.d.ts.map +1 -1
- package/dist/protocol/ProtocolModule.js +10 -7
- package/dist/protocol/ProtocolModule.js.map +1 -0
- package/dist/protocol/ProvableBlockHook.d.ts +19 -0
- package/dist/protocol/ProvableBlockHook.d.ts.map +1 -0
- package/dist/protocol/ProvableBlockHook.js +21 -0
- package/dist/protocol/ProvableBlockHook.js.map +1 -0
- package/dist/protocol/ProvableTransactionHook.d.ts +34 -0
- package/dist/protocol/ProvableTransactionHook.d.ts.map +1 -0
- package/dist/protocol/ProvableTransactionHook.js +13 -0
- package/dist/protocol/ProvableTransactionHook.js.map +1 -0
- package/dist/protocol/TransitioningProtocolModule.d.ts +10 -0
- package/dist/protocol/TransitioningProtocolModule.d.ts.map +1 -0
- package/dist/protocol/TransitioningProtocolModule.js +9 -0
- package/dist/protocol/TransitioningProtocolModule.js.map +1 -0
- package/dist/prover/accumulators/AppliedBatchHashList.d.ts +18 -0
- package/dist/prover/accumulators/AppliedBatchHashList.d.ts.map +1 -0
- package/dist/prover/accumulators/AppliedBatchHashList.js +25 -0
- package/dist/prover/accumulators/AppliedBatchHashList.js.map +1 -0
- package/dist/prover/accumulators/StateTransitionReductionList.d.ts +12 -0
- package/dist/prover/accumulators/StateTransitionReductionList.d.ts.map +1 -0
- package/dist/prover/accumulators/StateTransitionReductionList.js +64 -0
- package/dist/prover/accumulators/StateTransitionReductionList.js.map +1 -0
- package/dist/prover/accumulators/TransactionHashList.d.ts +6 -0
- package/dist/prover/accumulators/TransactionHashList.d.ts.map +1 -0
- package/dist/prover/accumulators/TransactionHashList.js +8 -0
- package/dist/prover/accumulators/TransactionHashList.js.map +1 -0
- package/dist/prover/accumulators/WitnessedRootHashList.d.ts +137 -0
- package/dist/prover/accumulators/WitnessedRootHashList.d.ts.map +1 -0
- package/dist/prover/accumulators/WitnessedRootHashList.js +50 -0
- package/dist/prover/accumulators/WitnessedRootHashList.js.map +1 -0
- package/dist/prover/block/BlockProvable.d.ts +869 -65
- package/dist/prover/block/BlockProvable.d.ts.map +1 -1
- package/dist/prover/block/BlockProvable.js +86 -6
- package/dist/prover/block/BlockProvable.js.map +1 -0
- package/dist/prover/block/BlockProver.d.ts +82 -34
- package/dist/prover/block/BlockProver.d.ts.map +1 -1
- package/dist/prover/block/BlockProver.js +505 -86
- package/dist/prover/block/BlockProver.js.map +1 -0
- package/dist/prover/block/accummulators/BlockHashMerkleTree.d.ts +106 -0
- package/dist/prover/block/accummulators/BlockHashMerkleTree.d.ts.map +1 -0
- package/dist/prover/block/accummulators/BlockHashMerkleTree.js +25 -0
- package/dist/prover/block/accummulators/BlockHashMerkleTree.js.map +1 -0
- package/dist/prover/block/accummulators/RuntimeVerificationKeyTree.d.ts +139 -0
- package/dist/prover/block/accummulators/RuntimeVerificationKeyTree.d.ts.map +1 -0
- package/dist/prover/block/accummulators/RuntimeVerificationKeyTree.js +21 -0
- package/dist/prover/block/accummulators/RuntimeVerificationKeyTree.js.map +1 -0
- package/dist/prover/block/services/RuntimeVerificationKeyRootService.d.ts +7 -0
- package/dist/prover/block/services/RuntimeVerificationKeyRootService.d.ts.map +1 -0
- package/dist/prover/{statetransition/StateTransitionWitnessProviderReference.js → block/services/RuntimeVerificationKeyRootService.js} +11 -8
- package/dist/prover/block/services/RuntimeVerificationKeyRootService.js.map +1 -0
- package/dist/prover/statetransition/StateTransitionProvable.d.ts +137 -48
- package/dist/prover/statetransition/StateTransitionProvable.d.ts.map +1 -1
- package/dist/prover/statetransition/StateTransitionProvable.js +10 -5
- package/dist/prover/statetransition/StateTransitionProvable.js.map +1 -0
- package/dist/prover/statetransition/StateTransitionProver.d.ts +30 -17
- package/dist/prover/statetransition/StateTransitionProver.d.ts.map +1 -1
- package/dist/prover/statetransition/StateTransitionProver.js +169 -74
- package/dist/prover/statetransition/StateTransitionProver.js.map +1 -0
- package/dist/settlement/ContractModule.d.ts +16 -0
- package/dist/settlement/ContractModule.d.ts.map +1 -0
- package/dist/settlement/ContractModule.js +12 -0
- package/dist/settlement/ContractModule.js.map +1 -0
- package/dist/settlement/SettlementContractModule.d.ts +51 -0
- package/dist/settlement/SettlementContractModule.d.ts.map +1 -0
- package/dist/settlement/SettlementContractModule.js +80 -0
- package/dist/settlement/SettlementContractModule.js.map +1 -0
- package/dist/settlement/contracts/BridgeContract.d.ts +116 -0
- package/dist/settlement/contracts/BridgeContract.d.ts.map +1 -0
- package/dist/settlement/contracts/BridgeContract.js +259 -0
- package/dist/settlement/contracts/BridgeContract.js.map +1 -0
- package/dist/settlement/contracts/BridgeContractProtocolModule.d.ts +16 -0
- package/dist/settlement/contracts/BridgeContractProtocolModule.d.ts.map +1 -0
- package/dist/settlement/contracts/BridgeContractProtocolModule.js +41 -0
- package/dist/settlement/contracts/BridgeContractProtocolModule.js.map +1 -0
- package/dist/settlement/contracts/DispatchContractProtocolModule.d.ts +21 -0
- package/dist/settlement/contracts/DispatchContractProtocolModule.d.ts.map +1 -0
- package/dist/settlement/contracts/DispatchContractProtocolModule.js +57 -0
- package/dist/settlement/contracts/DispatchContractProtocolModule.js.map +1 -0
- package/dist/settlement/contracts/DispatchSmartContract.d.ts +44 -0
- package/dist/settlement/contracts/DispatchSmartContract.d.ts.map +1 -0
- package/dist/settlement/contracts/DispatchSmartContract.js +229 -0
- package/dist/settlement/contracts/DispatchSmartContract.js.map +1 -0
- package/dist/settlement/contracts/SettlementContractProtocolModule.d.ts +21 -0
- package/dist/settlement/contracts/SettlementContractProtocolModule.d.ts.map +1 -0
- package/dist/settlement/contracts/SettlementContractProtocolModule.js +84 -0
- package/dist/settlement/contracts/SettlementContractProtocolModule.js.map +1 -0
- package/dist/settlement/contracts/SettlementSmartContract.d.ts +123 -0
- package/dist/settlement/contracts/SettlementSmartContract.d.ts.map +1 -0
- package/dist/settlement/contracts/SettlementSmartContract.js +310 -0
- package/dist/settlement/contracts/SettlementSmartContract.js.map +1 -0
- package/dist/settlement/contracts/TokenBridgeTree.d.ts +228 -0
- package/dist/settlement/contracts/TokenBridgeTree.d.ts.map +1 -0
- package/dist/settlement/contracts/TokenBridgeTree.js +60 -0
- package/dist/settlement/contracts/TokenBridgeTree.js.map +1 -0
- package/dist/settlement/contracts/authorizations/ContractAuthorization.d.ts +10 -0
- package/dist/settlement/contracts/authorizations/ContractAuthorization.d.ts.map +1 -0
- package/dist/settlement/contracts/authorizations/ContractAuthorization.js +2 -0
- package/dist/settlement/contracts/authorizations/ContractAuthorization.js.map +1 -0
- package/dist/settlement/contracts/authorizations/TokenBridgeDeploymentAuth.d.ts +85 -0
- package/dist/settlement/contracts/authorizations/TokenBridgeDeploymentAuth.d.ts.map +1 -0
- package/dist/settlement/contracts/authorizations/TokenBridgeDeploymentAuth.js +11 -0
- package/dist/settlement/contracts/authorizations/TokenBridgeDeploymentAuth.js.map +1 -0
- package/dist/settlement/contracts/authorizations/UpdateMessagesHashAuth.d.ts +79 -0
- package/dist/settlement/contracts/authorizations/UpdateMessagesHashAuth.d.ts.map +1 -0
- package/dist/settlement/contracts/authorizations/UpdateMessagesHashAuth.js +11 -0
- package/dist/settlement/contracts/authorizations/UpdateMessagesHashAuth.js.map +1 -0
- package/dist/settlement/messages/Deposit.d.ts +77 -0
- package/dist/settlement/messages/Deposit.d.ts.map +1 -0
- package/dist/settlement/messages/Deposit.js +8 -0
- package/dist/settlement/messages/Deposit.js.map +1 -0
- package/dist/settlement/messages/OutgoingMessage.d.ts +67 -0
- package/dist/settlement/messages/OutgoingMessage.d.ts.map +1 -0
- package/dist/settlement/messages/OutgoingMessage.js +7 -0
- package/dist/settlement/messages/OutgoingMessage.js.map +1 -0
- package/dist/settlement/messages/OutgoingMessageArgument.d.ts +462 -0
- package/dist/settlement/messages/OutgoingMessageArgument.d.ts.map +1 -0
- package/dist/settlement/messages/OutgoingMessageArgument.js +40 -0
- package/dist/settlement/messages/OutgoingMessageArgument.js.map +1 -0
- package/dist/settlement/messages/Withdrawal.d.ts +2 -0
- package/dist/settlement/messages/Withdrawal.d.ts.map +1 -0
- package/dist/settlement/messages/Withdrawal.js +3 -0
- package/dist/settlement/messages/Withdrawal.js.map +1 -0
- package/dist/settlement/modularity/OutgoingMessageProcessor.d.ts +25 -0
- package/dist/settlement/modularity/OutgoingMessageProcessor.d.ts.map +1 -0
- package/dist/settlement/modularity/OutgoingMessageProcessor.js +30 -0
- package/dist/settlement/modularity/OutgoingMessageProcessor.js.map +1 -0
- package/dist/settlement/modularity/ProvableSettlementHook.d.ts +26 -0
- package/dist/settlement/modularity/ProvableSettlementHook.d.ts.map +1 -0
- package/dist/settlement/modularity/ProvableSettlementHook.js +4 -0
- package/dist/settlement/modularity/ProvableSettlementHook.js.map +1 -0
- package/dist/settlement/modularity/types.d.ts +8 -0
- package/dist/settlement/modularity/types.d.ts.map +1 -0
- package/dist/settlement/modularity/types.js +2 -0
- package/dist/settlement/modularity/types.js.map +1 -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 +15 -0
- package/dist/settlement/modules/NetworkStateSettlementModule.js.map +1 -0
- package/dist/state/SimpleAsyncStateService.d.ts +6 -0
- package/dist/state/SimpleAsyncStateService.d.ts.map +1 -0
- package/dist/state/SimpleAsyncStateService.js +2 -0
- package/dist/state/SimpleAsyncStateService.js.map +1 -0
- package/dist/state/State.d.ts +68 -0
- package/dist/state/State.d.ts.map +1 -0
- package/dist/state/State.js +131 -0
- package/dist/state/State.js.map +1 -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/StateMap.js.map +1 -0
- package/dist/state/StateService.d.ts +6 -0
- package/dist/state/StateService.d.ts.map +1 -0
- package/dist/state/StateService.js +2 -0
- package/dist/state/StateService.js.map +1 -0
- package/dist/state/StateServiceProvider.d.ts +8 -0
- package/dist/state/StateServiceProvider.d.ts.map +1 -0
- package/dist/state/StateServiceProvider.js +37 -0
- package/dist/state/StateServiceProvider.js.map +1 -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 +33 -0
- package/dist/state/assert/assert.js.map +1 -0
- package/dist/state/context/RuntimeMethodExecutionContext.d.ts +193 -0
- package/dist/state/context/RuntimeMethodExecutionContext.d.ts.map +1 -0
- package/dist/state/context/RuntimeMethodExecutionContext.js +138 -0
- package/dist/state/context/RuntimeMethodExecutionContext.js.map +1 -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/context/TransitionMethodExecutionContext.js.map +1 -0
- package/dist/state/protocol/ProtocolState.d.ts +13 -0
- package/dist/state/protocol/ProtocolState.d.ts.map +1 -0
- package/dist/state/protocol/ProtocolState.js +58 -0
- package/dist/state/protocol/ProtocolState.js.map +1 -0
- package/dist/utils/FieldOptions.d.ts +62 -0
- package/dist/utils/FieldOptions.d.ts.map +1 -0
- package/dist/utils/FieldOptions.js +13 -0
- package/dist/utils/FieldOptions.js.map +1 -0
- package/dist/utils/MinaPrefixedProvableHashList.d.ts +19 -0
- package/dist/utils/MinaPrefixedProvableHashList.d.ts.map +1 -0
- package/dist/utils/MinaPrefixedProvableHashList.js +46 -0
- package/dist/utils/MinaPrefixedProvableHashList.js.map +1 -0
- package/dist/utils/PrefixedProvableHashList.d.ts +2 -2
- package/dist/utils/PrefixedProvableHashList.d.ts.map +1 -1
- package/dist/utils/PrefixedProvableHashList.js +2 -1
- package/dist/utils/PrefixedProvableHashList.js.map +1 -0
- package/dist/utils/ProvableHashList.d.ts +23 -4
- package/dist/utils/ProvableHashList.d.ts.map +1 -1
- package/dist/utils/ProvableHashList.js +38 -2
- package/dist/utils/ProvableHashList.js.map +1 -0
- package/dist/utils/ProvableReductionHashList.d.ts +18 -0
- package/dist/utils/ProvableReductionHashList.d.ts.map +1 -0
- package/dist/utils/ProvableReductionHashList.js +54 -0
- package/dist/utils/ProvableReductionHashList.js.map +1 -0
- package/dist/utils/StateTransitionReductionList.d.ts +11 -0
- package/dist/utils/StateTransitionReductionList.d.ts.map +1 -0
- package/dist/utils/StateTransitionReductionList.js +61 -0
- package/dist/utils/StateTransitionReductionList.js.map +1 -0
- package/dist/utils/utils.d.ts +20 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +51 -0
- package/dist/utils/utils.js.map +1 -0
- package/jest.config.cjs +12 -1
- package/package.json +11 -9
- package/src/hashing/mina-prefixes.ts +10 -0
- package/src/hashing/protokit-prefixes.ts +37 -0
- package/src/hooks/AccountStateHook.ts +57 -0
- package/src/hooks/BlockHeightHook.ts +17 -0
- package/src/hooks/LastStateRootBlockHook.ts +25 -0
- package/src/hooks/NoopBlockHook.ts +24 -0
- package/src/hooks/NoopSettlementHook.ts +20 -0
- package/src/hooks/NoopTransactionHook.ts +13 -0
- package/src/index.ts +51 -9
- package/src/model/AppliedStateTransitionBatch.ts +16 -0
- package/src/model/MethodPublicOutput.ts +3 -1
- package/src/model/Option.ts +99 -60
- package/src/model/Path.ts +9 -5
- package/src/model/RuntimeLike.ts +12 -0
- package/src/model/StateTransition.ts +25 -3
- package/src/model/StateTransitionProvableBatch.ts +117 -14
- package/src/model/Transaction.ts +3 -1
- package/src/model/network/NetworkState.ts +21 -3
- package/src/model/transaction/RuntimeTransaction.ts +90 -15
- package/src/model/transaction/SignedTransaction.ts +47 -0
- package/src/model/transaction/ValueOption.ts +28 -0
- package/src/protocol/Protocol.ts +166 -74
- package/src/protocol/ProtocolEnvironment.ts +10 -0
- package/src/protocol/ProtocolModule.ts +16 -16
- package/src/protocol/ProvableBlockHook.ts +68 -0
- package/src/protocol/ProvableTransactionHook.ts +77 -0
- package/src/protocol/TransitioningProtocolModule.ts +12 -0
- package/src/prover/accumulators/AppliedBatchHashList.ts +32 -0
- package/src/prover/accumulators/StateTransitionReductionList.ts +92 -0
- package/src/prover/accumulators/TransactionHashList.ts +9 -0
- package/src/prover/accumulators/WitnessedRootHashList.ts +61 -0
- package/src/prover/block/BlockProvable.ts +188 -15
- package/src/prover/block/BlockProver.ts +979 -143
- package/src/prover/block/accummulators/BlockHashMerkleTree.ts +24 -0
- package/src/prover/block/accummulators/RuntimeVerificationKeyTree.ts +24 -0
- package/src/prover/block/services/RuntimeVerificationKeyRootService.ts +20 -0
- package/src/prover/statetransition/StateTransitionProvable.ts +26 -19
- package/src/prover/statetransition/StateTransitionProver.ts +338 -130
- package/src/settlement/ContractModule.ts +31 -0
- package/src/settlement/SettlementContractModule.ts +145 -0
- package/src/settlement/contracts/BridgeContract.ts +366 -0
- package/src/settlement/contracts/BridgeContractProtocolModule.ts +48 -0
- package/src/settlement/contracts/DispatchContractProtocolModule.ts +75 -0
- package/src/settlement/contracts/DispatchSmartContract.ts +325 -0
- package/src/settlement/contracts/SettlementContractProtocolModule.ts +113 -0
- package/src/settlement/contracts/SettlementSmartContract.ts +502 -0
- package/src/settlement/contracts/TokenBridgeTree.ts +73 -0
- package/src/settlement/contracts/authorizations/ContractAuthorization.ts +11 -0
- package/src/settlement/contracts/authorizations/TokenBridgeDeploymentAuth.ts +16 -0
- package/src/settlement/contracts/authorizations/UpdateMessagesHashAuth.ts +16 -0
- package/src/settlement/messages/Deposit.ts +7 -0
- package/src/settlement/messages/OutgoingMessage.ts +17 -0
- package/src/settlement/messages/OutgoingMessageArgument.ts +53 -0
- package/src/settlement/modularity/OutgoingMessageProcessor.ts +65 -0
- package/src/settlement/modularity/ProvableSettlementHook.ts +36 -0
- package/src/settlement/modularity/types.ts +22 -0
- package/src/settlement/modules/NetworkStateSettlementModule.ts +42 -0
- package/src/state/State.ts +177 -0
- package/src/state/StateMap.ts +73 -0
- package/src/state/StateService.ts +6 -0
- package/src/state/StateServiceProvider.ts +37 -0
- package/src/state/assert/assert.ts +38 -0
- package/src/state/context/RuntimeMethodExecutionContext.ts +181 -0
- package/src/state/context/TransitionMethodExecutionContext.ts +26 -0
- package/src/state/protocol/ProtocolState.ts +98 -0
- package/src/utils/FieldOptions.ts +13 -0
- package/src/utils/MinaPrefixedProvableHashList.ts +66 -0
- package/src/utils/PrefixedProvableHashList.ts +2 -2
- package/src/utils/ProvableHashList.ts +78 -3
- package/src/utils/ProvableReductionHashList.ts +77 -0
- package/src/utils/utils.ts +44 -55
- package/test/BlockProver.test.ts +161 -74
- package/test/Protocol.test.ts +20 -10
- package/test/State.test.ts +45 -0
- package/test/StateTransition.test.ts +57 -65
- package/test/TestingProtocol.ts +56 -0
- package/test/compiling/types.ts +28 -0
- package/test/model/Option.test.ts +72 -0
- package/test/model/StateTransitionProvableBatch.test.ts +137 -0
- package/test/modularity/types.ts +35 -0
- package/test/prover/block/BlockProver.test.ts +18 -0
- package/test/prover/statetransition/StateTransitionProver.test.ts +261 -0
- package/test/state/assert/assert.test.ts +56 -0
- package/test/tsconfig.json +7 -0
- package/test/utils/ProvableHashList.test.ts +44 -0
- package/test/utils/ProvableReductionHashList.test.ts +117 -0
- package/test/utils.test.ts +27 -0
- package/dist/config/ConfigurableModule.d.ts +0 -18
- package/dist/config/ConfigurableModule.d.ts.map +0 -1
- package/dist/config/ConfigurableModule.js +0 -20
- package/dist/config/ConfigurationAggregator.d.ts +0 -10
- package/dist/config/ConfigurationAggregator.d.ts.map +0 -1
- package/dist/config/ConfigurationAggregator.js +0 -35
- package/dist/config/ConfigurationReceiver.d.ts +0 -25
- package/dist/config/ConfigurationReceiver.d.ts.map +0 -1
- package/dist/config/ConfigurationReceiver.js +0 -36
- package/dist/config/ModuleContainer.d.ts +0 -44
- package/dist/config/ModuleContainer.d.ts.map +0 -1
- package/dist/config/ModuleContainer.js +0 -89
- package/dist/config/types.d.ts +0 -2
- package/dist/config/types.d.ts.map +0 -1
- package/dist/config/types.js +0 -1
- package/dist/model/MethodPublicInput.d.ts +0 -51
- package/dist/model/MethodPublicInput.d.ts.map +0 -1
- package/dist/model/MethodPublicInput.js +0 -11
- package/dist/model/transaction/ProtocolTransaction.d.ts +0 -70
- package/dist/model/transaction/ProtocolTransaction.d.ts.map +0 -1
- package/dist/model/transaction/ProtocolTransaction.js +0 -18
- package/dist/prover/block/BlockScopedModule.d.ts +0 -3
- package/dist/prover/block/BlockScopedModule.d.ts.map +0 -1
- package/dist/prover/block/BlockScopedModule.js +0 -6
- package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts +0 -16
- package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts.map +0 -1
- package/dist/prover/statetransition/StateTransitionWitnessProviderReference.d.ts +0 -7
- package/dist/prover/statetransition/StateTransitionWitnessProviderReference.d.ts.map +0 -1
- package/dist/src/model/Option.d.ts +0 -158
- package/dist/src/model/Option.d.ts.map +0 -1
- package/dist/src/model/Option.js +0 -53
- package/dist/src/model/Path.d.ts +0 -35
- package/dist/src/model/Path.d.ts.map +0 -1
- package/dist/src/model/Path.js +0 -51
- package/dist/src/model/StateTransition.d.ts +0 -201
- package/dist/src/model/StateTransition.d.ts.map +0 -1
- package/dist/src/model/StateTransition.js +0 -43
- package/dist/src/utils/PrefixedHashList.d.ts +0 -15
- package/dist/src/utils/PrefixedHashList.d.ts.map +0 -1
- package/dist/src/utils/PrefixedHashList.js +0 -28
- package/dist/src/utils/ProvableHashList.d.ts +0 -30
- package/dist/src/utils/ProvableHashList.d.ts.map +0 -1
- package/dist/src/utils/ProvableHashList.js +0 -43
- package/dist/utils/PrefixedHashList.d.ts +0 -14
- package/dist/utils/PrefixedHashList.d.ts.map +0 -1
- package/dist/utils/PrefixedHashList.js +0 -12
- package/dist/utils/Utils.d.ts +0 -17
- package/dist/utils/Utils.d.ts.map +0 -1
- package/dist/utils/Utils.js +0 -64
- package/dist/utils/merkletree/InMemoryMerkleTreeStorage.d.ts +0 -25
- package/dist/utils/merkletree/InMemoryMerkleTreeStorage.d.ts.map +0 -1
- package/dist/utils/merkletree/InMemoryMerkleTreeStorage.js +0 -77
- package/dist/utils/merkletree/MemoryMerkleTreeStorage.d.ts +0 -26
- package/dist/utils/merkletree/MemoryMerkleTreeStorage.d.ts.map +0 -1
- package/dist/utils/merkletree/MemoryMerkleTreeStorage.js +0 -79
- package/dist/utils/merkletree/MerkleTreeStore.d.ts +0 -11
- package/dist/utils/merkletree/MerkleTreeStore.d.ts.map +0 -1
- package/dist/utils/merkletree/MerkleTreeStore.js +0 -1
- package/dist/utils/merkletree/RollupMerkleTree.d.ts +0 -130
- package/dist/utils/merkletree/RollupMerkleTree.d.ts.map +0 -1
- package/dist/utils/merkletree/RollupMerkleTree.js +0 -244
- package/src/model/Option.test.ts +0 -21
- package/src/model/transaction/ProtocolTransaction.ts +0 -25
- package/src/prover/statetransition/StateTransitionWitnessProvider.ts +0 -24
- package/src/prover/statetransition/StateTransitionWitnessProviderReference.ts +0 -17
- package/src/utils/merkletree/InMemoryMerkleTreeStorage.ts +0 -106
- package/src/utils/merkletree/MerkleTreeStore.ts +0 -15
- package/src/utils/merkletree/RollupMerkleTree.ts +0 -250
- package/src/utils/merkletree/VirtualMerkleTreeStore.ts +0 -21
- package/tsconfig.test.json +0 -9
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Field, Poseidon, PublicKey, Struct, UInt64 } from "
|
|
1
|
+
import { Bool, Field, Poseidon, PublicKey, Struct, UInt64 } from "o1js";
|
|
2
|
+
import { EMPTY_PUBLICKEY, EMPTY_PUBLICKEY_X } from "@proto-kit/common";
|
|
2
3
|
|
|
3
|
-
import {
|
|
4
|
+
import { PublicKeyOption, UInt64Option } from "./ValueOption";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* This struct is used to expose transaction information to the runtime method
|
|
@@ -8,27 +9,101 @@ import { ProtocolTransaction } from "./ProtocolTransaction";
|
|
|
8
9
|
* For example, we don't want to expose the signature or args as fields.
|
|
9
10
|
*/
|
|
10
11
|
export class RuntimeTransaction extends Struct({
|
|
11
|
-
|
|
12
|
-
sender: PublicKey,
|
|
12
|
+
methodId: Field,
|
|
13
13
|
argsHash: Field,
|
|
14
|
+
nonce: UInt64Option,
|
|
15
|
+
sender: PublicKeyOption,
|
|
14
16
|
}) {
|
|
15
|
-
public static
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
public static fromTransaction(input: {
|
|
18
|
+
methodId: Field;
|
|
19
|
+
argsHash: Field;
|
|
20
|
+
nonce: UInt64;
|
|
21
|
+
sender: PublicKey;
|
|
22
|
+
}) {
|
|
23
|
+
return new RuntimeTransaction({
|
|
24
|
+
methodId: input.methodId,
|
|
25
|
+
argsHash: input.argsHash,
|
|
26
|
+
nonce: UInt64Option.fromSome(input.nonce),
|
|
27
|
+
sender: PublicKeyOption.fromSome(input.sender),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public static fromMessage({
|
|
32
|
+
methodId,
|
|
18
33
|
argsHash,
|
|
19
|
-
}:
|
|
34
|
+
}: {
|
|
35
|
+
methodId: Field;
|
|
36
|
+
argsHash: Field;
|
|
37
|
+
}) {
|
|
20
38
|
return new RuntimeTransaction({
|
|
21
|
-
|
|
22
|
-
sender,
|
|
39
|
+
methodId,
|
|
23
40
|
argsHash,
|
|
41
|
+
nonce: UInt64Option.none(UInt64.zero),
|
|
42
|
+
sender: PublicKeyOption.none(EMPTY_PUBLICKEY),
|
|
24
43
|
});
|
|
25
44
|
}
|
|
26
45
|
|
|
27
|
-
public
|
|
28
|
-
return
|
|
29
|
-
|
|
30
|
-
|
|
46
|
+
public static dummyTransaction(): RuntimeTransaction {
|
|
47
|
+
return new RuntimeTransaction({
|
|
48
|
+
methodId: Field(0),
|
|
49
|
+
nonce: new UInt64Option({
|
|
50
|
+
isSome: Bool(true),
|
|
51
|
+
value: UInt64.zero,
|
|
52
|
+
}),
|
|
53
|
+
sender: new PublicKeyOption({
|
|
54
|
+
isSome: Bool(true),
|
|
55
|
+
value: EMPTY_PUBLICKEY,
|
|
56
|
+
}),
|
|
57
|
+
argsHash: Field(0),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public assertTransactionType(isMessage: Bool) {
|
|
62
|
+
const isTransaction = isMessage.not();
|
|
63
|
+
// isSome has to be true when it is a transaction, otherwise false
|
|
64
|
+
this.nonce.isSome
|
|
65
|
+
.equals(isTransaction)
|
|
66
|
+
.assertTrue("Nonce is not right option isSome for type");
|
|
67
|
+
this.sender.isSome
|
|
68
|
+
.equals(isTransaction)
|
|
69
|
+
.assertTrue("Sender is not right option isSome for type");
|
|
70
|
+
this.sender.value.x
|
|
71
|
+
.equals(EMPTY_PUBLICKEY_X)
|
|
72
|
+
.equals(isMessage)
|
|
73
|
+
.assertTrue("Transaction sender is not set to dummy");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public isDummy(): Bool {
|
|
77
|
+
return this.methodId.equals(0);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public hashData(): Field[] {
|
|
81
|
+
return [
|
|
82
|
+
this.methodId,
|
|
83
|
+
...this.sender.value.toFields(),
|
|
84
|
+
...this.nonce.value.toFields(),
|
|
31
85
|
this.argsHash,
|
|
32
|
-
]
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public static fromHashData(fields: Field[]) {
|
|
90
|
+
// sender is 2nd and the first element is x (2nd isOdd)
|
|
91
|
+
const isMessage = fields[1].equals(EMPTY_PUBLICKEY_X);
|
|
92
|
+
return new RuntimeTransaction({
|
|
93
|
+
methodId: fields[0],
|
|
94
|
+
sender: new PublicKeyOption({
|
|
95
|
+
isSome: isMessage.not(),
|
|
96
|
+
value: PublicKey.fromFields([fields[1], fields[2]]),
|
|
97
|
+
}),
|
|
98
|
+
nonce: new UInt64Option({
|
|
99
|
+
isSome: isMessage.not(),
|
|
100
|
+
value: UInt64.fromFields([fields[3]]),
|
|
101
|
+
}),
|
|
102
|
+
argsHash: fields[4],
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public hash(): Field {
|
|
107
|
+
return Poseidon.hash(this.hashData());
|
|
33
108
|
}
|
|
34
109
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Bool, Field, Scalar, Signature, Struct, UInt64 } from "o1js";
|
|
2
|
+
|
|
3
|
+
import { RuntimeTransaction } from "./RuntimeTransaction";
|
|
4
|
+
|
|
5
|
+
export class SignedTransaction extends Struct({
|
|
6
|
+
transaction: RuntimeTransaction,
|
|
7
|
+
signature: Signature,
|
|
8
|
+
}) {
|
|
9
|
+
public static getSignatureData(args: {
|
|
10
|
+
methodId: Field;
|
|
11
|
+
nonce: UInt64;
|
|
12
|
+
argsHash: Field;
|
|
13
|
+
}): Field[] {
|
|
14
|
+
return [args.methodId, ...args.nonce.value.toFields(), args.argsHash];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public static dummy(): SignedTransaction {
|
|
18
|
+
return new SignedTransaction({
|
|
19
|
+
transaction: RuntimeTransaction.dummyTransaction(),
|
|
20
|
+
|
|
21
|
+
signature: Signature.fromObject({
|
|
22
|
+
s: Scalar.from(0),
|
|
23
|
+
r: Field(0),
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public hash(): Field {
|
|
29
|
+
return this.transaction.hash();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public getSignatureData(): Field[] {
|
|
33
|
+
const { methodId, argsHash, nonce } = this.transaction;
|
|
34
|
+
return SignedTransaction.getSignatureData({
|
|
35
|
+
nonce: nonce.value,
|
|
36
|
+
methodId,
|
|
37
|
+
argsHash,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public validateSignature(): Bool {
|
|
42
|
+
return this.signature.verify(
|
|
43
|
+
this.transaction.sender.value,
|
|
44
|
+
this.getSignatureData()
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Bool, ProvableExtended, PublicKey, Struct, UInt64 } from "o1js";
|
|
2
|
+
|
|
3
|
+
function genericOptionFactory<Type>(valueType: ProvableExtended<Type>) {
|
|
4
|
+
return class Generic extends Struct({
|
|
5
|
+
isSome: Bool,
|
|
6
|
+
value: valueType,
|
|
7
|
+
}) {
|
|
8
|
+
public static fromSome(value: Type) {
|
|
9
|
+
return new Generic({
|
|
10
|
+
isSome: Bool(true),
|
|
11
|
+
value,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public static none(value: Type) {
|
|
16
|
+
return new Generic({
|
|
17
|
+
isSome: Bool(false),
|
|
18
|
+
value,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class UInt64Option extends genericOptionFactory<UInt64>(UInt64) {}
|
|
25
|
+
|
|
26
|
+
export class PublicKeyOption extends genericOptionFactory<PublicKey>(
|
|
27
|
+
PublicKey
|
|
28
|
+
) {}
|
package/src/protocol/Protocol.ts
CHANGED
|
@@ -1,90 +1,106 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AreProofsEnabled,
|
|
3
|
+
ChildContainerProvider,
|
|
2
4
|
log,
|
|
3
5
|
ModuleContainer,
|
|
4
|
-
ModulesConfig,
|
|
5
6
|
ModulesRecord,
|
|
7
|
+
Startable,
|
|
6
8
|
StringKeyOf,
|
|
7
9
|
TypedClass,
|
|
8
10
|
} from "@proto-kit/common";
|
|
9
|
-
import { DependencyContainer } from "tsyringe";
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} from "../
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
} from "../
|
|
22
|
-
import { BlockProver } from "../prover/block/BlockProver";
|
|
11
|
+
import { DependencyContainer, Lifecycle } from "tsyringe";
|
|
12
|
+
|
|
13
|
+
import { BlockProvable } from "../prover/block/BlockProvable";
|
|
14
|
+
import { StateTransitionProvable } from "../prover/statetransition/StateTransitionProvable";
|
|
15
|
+
import { StateServiceProvider } from "../state/StateServiceProvider";
|
|
16
|
+
import { SimpleAsyncStateService } from "../state/StateService";
|
|
17
|
+
import { NoopBlockHook } from "../hooks/NoopBlockHook";
|
|
18
|
+
import { BlockHeightHook } from "../hooks/BlockHeightHook";
|
|
19
|
+
import { LastStateRootBlockHook } from "../hooks/LastStateRootBlockHook";
|
|
20
|
+
import { ProvableSettlementHook } from "../settlement/modularity/ProvableSettlementHook";
|
|
21
|
+
import { NoopSettlementHook } from "../hooks/NoopSettlementHook";
|
|
22
|
+
import { AccountStateHook } from "../hooks/AccountStateHook";
|
|
23
|
+
import { NoopTransactionHook } from "../hooks/NoopTransactionHook";
|
|
23
24
|
|
|
24
25
|
import { ProtocolModule } from "./ProtocolModule";
|
|
26
|
+
import { ProvableTransactionHook } from "./ProvableTransactionHook";
|
|
27
|
+
import { ProtocolEnvironment } from "./ProtocolEnvironment";
|
|
28
|
+
import { ProvableBlockHook } from "./ProvableBlockHook";
|
|
29
|
+
import { TransitioningProtocolModule } from "./TransitioningProtocolModule";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* This is a mapping of abstract classes to their respective injection tokens.
|
|
33
|
+
* Keys are the abstract classes names, which need to be set dynamically
|
|
34
|
+
* and can't be hardcoded since producing optimized builds may mangle the
|
|
35
|
+
* class names, making them different from the ones in the source code.
|
|
36
|
+
*/
|
|
37
|
+
const PROTOCOL_INJECTION_TOKENS: Record<string, string> = {
|
|
38
|
+
[ProvableTransactionHook.name]: "ProvableTransactionHook",
|
|
39
|
+
[ProvableBlockHook.name]: "ProvableBlockHook",
|
|
40
|
+
[ProvableSettlementHook.name]: "ProvableSettlementHook",
|
|
41
|
+
};
|
|
25
42
|
|
|
26
|
-
export type
|
|
27
|
-
TypedClass<ProtocolModule<
|
|
43
|
+
export type ProtocolModulesRecord = ModulesRecord<
|
|
44
|
+
TypedClass<ProtocolModule<unknown>>
|
|
28
45
|
>;
|
|
29
46
|
|
|
30
|
-
interface BlockProverType
|
|
31
|
-
extends ProtocolModule<BlockProverPublicInput, BlockProverPublicOutput>,
|
|
32
|
-
BlockProvable {}
|
|
47
|
+
export interface BlockProverType extends ProtocolModule, BlockProvable {}
|
|
33
48
|
|
|
34
|
-
interface StateTransitionProverType
|
|
35
|
-
extends ProtocolModule
|
|
36
|
-
StateTransitionProverPublicInput,
|
|
37
|
-
StateTransitionProverPublicOutput
|
|
38
|
-
>,
|
|
49
|
+
export interface StateTransitionProverType
|
|
50
|
+
extends ProtocolModule,
|
|
39
51
|
StateTransitionProvable {}
|
|
40
52
|
|
|
41
|
-
export
|
|
53
|
+
export type MandatoryProtocolModulesRecord = {
|
|
42
54
|
BlockProver: TypedClass<BlockProverType>;
|
|
43
55
|
StateTransitionProver: TypedClass<StateTransitionProverType>;
|
|
44
|
-
|
|
56
|
+
AccountState: TypedClass<AccountStateHook>;
|
|
57
|
+
BlockHeight: TypedClass<BlockHeightHook>;
|
|
58
|
+
LastStateRoot: TypedClass<LastStateRootBlockHook>;
|
|
59
|
+
};
|
|
45
60
|
|
|
46
|
-
export
|
|
47
|
-
|
|
48
|
-
|
|
61
|
+
export class Protocol<
|
|
62
|
+
Modules extends ProtocolModulesRecord & MandatoryProtocolModulesRecord,
|
|
63
|
+
>
|
|
64
|
+
extends ModuleContainer<Modules>
|
|
65
|
+
implements ProtocolEnvironment, Startable
|
|
66
|
+
{
|
|
67
|
+
public static from<
|
|
68
|
+
Modules extends ProtocolModulesRecord & MandatoryProtocolModulesRecord,
|
|
69
|
+
>(modules: Modules): TypedClass<Protocol<Modules>> {
|
|
70
|
+
return class ScopedProtocol extends Protocol<Modules> {
|
|
71
|
+
public constructor() {
|
|
72
|
+
super(modules);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
49
76
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
77
|
+
// No idea why we have to do this, but if we don't re-define it here,
|
|
78
|
+
// js can't access it from the superclass somehow
|
|
79
|
+
public definition: Modules;
|
|
54
80
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
public static from<Modules extends ProtocolModulesRecord>(
|
|
60
|
-
modules: ProtocolDefinition<Modules>
|
|
61
|
-
) {
|
|
62
|
-
const protocol = new Protocol(modules);
|
|
63
|
-
|
|
64
|
-
// Set empty config for all modules, since we don't have that feature yet
|
|
65
|
-
// eslint-disable-next-line max-len
|
|
66
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment
|
|
67
|
-
const emptyConfig = Object.keys(modules.modules).reduce<any>(
|
|
68
|
-
(agg, item: string) => {
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
70
|
-
agg[item] = {};
|
|
71
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
72
|
-
return agg;
|
|
73
|
-
},
|
|
74
|
-
{}
|
|
75
|
-
);
|
|
76
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
77
|
-
protocol.configure(emptyConfig as ModulesConfig<Modules>);
|
|
81
|
+
public constructor(definition: Modules) {
|
|
82
|
+
super(definition);
|
|
83
|
+
this.definition = definition;
|
|
84
|
+
}
|
|
78
85
|
|
|
79
|
-
|
|
86
|
+
public get stateService(): SimpleAsyncStateService {
|
|
87
|
+
return this.stateServiceProvider.stateService;
|
|
80
88
|
}
|
|
81
89
|
|
|
82
|
-
|
|
90
|
+
public get stateServiceProvider(): StateServiceProvider {
|
|
91
|
+
return this.container.resolve<StateServiceProvider>("StateServiceProvider");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public decorateModule(
|
|
83
95
|
moduleName: StringKeyOf<Modules>,
|
|
84
96
|
containedModule: InstanceType<Modules[StringKeyOf<Modules>]>
|
|
85
97
|
) {
|
|
86
98
|
log.debug(`Decorated ${moduleName}`);
|
|
87
|
-
containedModule.
|
|
99
|
+
containedModule.parent = this;
|
|
100
|
+
|
|
101
|
+
if (containedModule instanceof TransitioningProtocolModule) {
|
|
102
|
+
containedModule.name = moduleName;
|
|
103
|
+
}
|
|
88
104
|
|
|
89
105
|
super.decorateModule(moduleName, containedModule);
|
|
90
106
|
}
|
|
@@ -96,7 +112,7 @@ export class Protocol<
|
|
|
96
112
|
private isModule(
|
|
97
113
|
moduleName: keyof Modules
|
|
98
114
|
): moduleName is StringKeyOf<Modules> {
|
|
99
|
-
return this.definition
|
|
115
|
+
return this.definition[moduleName] !== undefined;
|
|
100
116
|
}
|
|
101
117
|
|
|
102
118
|
public get blockProver(): BlockProvable {
|
|
@@ -112,18 +128,94 @@ export class Protocol<
|
|
|
112
128
|
InstanceType<Modules["StateTransitionProver"]>
|
|
113
129
|
>("StateTransitionProver");
|
|
114
130
|
}
|
|
115
|
-
}
|
|
116
131
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
132
|
+
public getAreProofsEnabled(): AreProofsEnabled {
|
|
133
|
+
return this.container.resolve<AreProofsEnabled>("AreProofsEnabled");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
public create(childContainerProvider: ChildContainerProvider) {
|
|
137
|
+
super.create(childContainerProvider);
|
|
138
|
+
|
|
139
|
+
// Register the BlockModules seperately since we need to
|
|
140
|
+
// inject them differently later
|
|
141
|
+
const ABSTRACT_MODULE_TYPES = [
|
|
142
|
+
{ type: ProvableTransactionHook, defaultType: NoopTransactionHook },
|
|
143
|
+
{ type: ProvableBlockHook, defaultType: NoopBlockHook },
|
|
144
|
+
{ type: ProvableSettlementHook, defaultType: NoopSettlementHook },
|
|
145
|
+
] as const;
|
|
146
|
+
|
|
147
|
+
ABSTRACT_MODULE_TYPES.forEach((moduleTypeRegistration) => {
|
|
148
|
+
const abstractType = moduleTypeRegistration.type;
|
|
149
|
+
|
|
150
|
+
const implementingModules = Object.entries(this.definition).filter(
|
|
151
|
+
([, value]) => Object.prototype.isPrototypeOf.call(abstractType, value)
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const newInjectionToken: string | undefined =
|
|
155
|
+
PROTOCOL_INJECTION_TOKENS[abstractType.name];
|
|
156
|
+
|
|
157
|
+
if (newInjectionToken === undefined) {
|
|
158
|
+
log.error(
|
|
159
|
+
"Can't inject hook under the underlying hook token: Alias not found in mapping"
|
|
160
|
+
);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
implementingModules.forEach(([key]) => {
|
|
165
|
+
this.container.register(
|
|
166
|
+
newInjectionToken,
|
|
167
|
+
{ useToken: key },
|
|
168
|
+
{ lifecycle: Lifecycle.ContainerScoped }
|
|
169
|
+
);
|
|
170
|
+
});
|
|
171
|
+
if (implementingModules.length === 0) {
|
|
172
|
+
// This type annotation shouldn't change anything but is necessary
|
|
173
|
+
// bcs tsyringe complains
|
|
174
|
+
const { defaultType }: { defaultType: TypedClass<unknown> } =
|
|
175
|
+
moduleTypeRegistration;
|
|
176
|
+
|
|
177
|
+
// Register default (noop) version
|
|
178
|
+
this.container.register(
|
|
179
|
+
newInjectionToken,
|
|
180
|
+
{ useClass: defaultType },
|
|
181
|
+
{ lifecycle: Lifecycle.ContainerScoped }
|
|
182
|
+
);
|
|
183
|
+
}
|
|
127
184
|
});
|
|
128
|
-
|
|
129
|
-
|
|
185
|
+
|
|
186
|
+
// Cross-register all runtime modules to the protocol container for easier
|
|
187
|
+
// access of runtime modules inside protocol hooks
|
|
188
|
+
if (this.container.isRegistered("Runtime", true)) {
|
|
189
|
+
const runtimeContainer: ModuleContainer<any> =
|
|
190
|
+
this.container.resolve("Runtime");
|
|
191
|
+
|
|
192
|
+
runtimeContainer.moduleNames.forEach((runtimeModuleName) => {
|
|
193
|
+
this.container.register(runtimeModuleName, {
|
|
194
|
+
useFactory: (dependencyContainer) => {
|
|
195
|
+
// Prevents creation of closure
|
|
196
|
+
const runtime: ModuleContainer<any> =
|
|
197
|
+
dependencyContainer.resolve("Runtime");
|
|
198
|
+
return runtime.resolve(runtimeModuleName);
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
} else {
|
|
203
|
+
log.warn(
|
|
204
|
+
"Couldn't resolve Runtime reference in Protocol, resolving RuntimeModules in hooks won't be available"
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
public async start() {
|
|
210
|
+
// eslint-disable-next-line guard-for-in
|
|
211
|
+
for (const moduleName in this.definition) {
|
|
212
|
+
const protocolModule = this.resolve(moduleName);
|
|
213
|
+
|
|
214
|
+
log.info(
|
|
215
|
+
`Starting protocol module ${moduleName} (${protocolModule.constructor.name})`
|
|
216
|
+
);
|
|
217
|
+
// eslint-disable-next-line no-await-in-loop
|
|
218
|
+
await protocolModule.start();
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AreProofsEnabled } from "@proto-kit/common";
|
|
2
|
+
|
|
3
|
+
import { SimpleAsyncStateService } from "../state/StateService";
|
|
4
|
+
import { StateServiceProvider } from "../state/StateServiceProvider";
|
|
5
|
+
|
|
6
|
+
export interface ProtocolEnvironment {
|
|
7
|
+
get stateService(): SimpleAsyncStateService;
|
|
8
|
+
get stateServiceProvider(): StateServiceProvider;
|
|
9
|
+
getAreProofsEnabled(): AreProofsEnabled;
|
|
10
|
+
}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AreProofsEnabled,
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
ChildContainerProvider,
|
|
4
|
+
ConfigurableModule,
|
|
5
|
+
NoConfig,
|
|
6
|
+
noop,
|
|
5
7
|
} from "@proto-kit/common";
|
|
6
8
|
|
|
7
|
-
import
|
|
8
|
-
import { noop } from "lodash";
|
|
9
|
+
import { ProtocolEnvironment } from "./ProtocolEnvironment";
|
|
9
10
|
|
|
10
|
-
export abstract class ProtocolModule<
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
public config = {};
|
|
11
|
+
export abstract class ProtocolModule<
|
|
12
|
+
Config = NoConfig,
|
|
13
|
+
> extends ConfigurableModule<Config> {
|
|
14
|
+
public parent?: ProtocolEnvironment;
|
|
15
15
|
|
|
16
|
-
public
|
|
16
|
+
public get areProofsEnabled(): AreProofsEnabled | undefined {
|
|
17
|
+
return this.parent?.getAreProofsEnabled();
|
|
18
|
+
}
|
|
17
19
|
|
|
18
|
-
public
|
|
19
|
-
|
|
20
|
-
"AppChain"
|
|
21
|
-
);
|
|
20
|
+
public create(childContainerProvider: ChildContainerProvider): void {
|
|
21
|
+
noop();
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
public
|
|
25
|
-
|
|
24
|
+
public async start() {
|
|
25
|
+
noop();
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Field } from "o1js";
|
|
2
|
+
import { NoConfig } from "@proto-kit/common";
|
|
3
|
+
|
|
4
|
+
import { NetworkState } from "../model/network/NetworkState";
|
|
5
|
+
import { MethodPublicOutput } from "../model/MethodPublicOutput";
|
|
6
|
+
import { BlockProverTransactionArguments } from "../prover/block/BlockProvable";
|
|
7
|
+
|
|
8
|
+
import { TransitioningProtocolModule } from "./TransitioningProtocolModule";
|
|
9
|
+
import {
|
|
10
|
+
AfterTransactionHookArguments,
|
|
11
|
+
BeforeTransactionHookArguments,
|
|
12
|
+
ProvableHookBlockState,
|
|
13
|
+
toProvableHookBlockState,
|
|
14
|
+
} from "./ProvableTransactionHook";
|
|
15
|
+
|
|
16
|
+
export interface BeforeBlockHookArguments extends ProvableHookBlockState {}
|
|
17
|
+
|
|
18
|
+
export interface AfterBlockHookArguments extends BeforeBlockHookArguments {
|
|
19
|
+
stateRoot: Field;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function toBeforeTransactionHookArgument(
|
|
23
|
+
executionData: Omit<
|
|
24
|
+
BlockProverTransactionArguments,
|
|
25
|
+
"verificationKeyAttestation"
|
|
26
|
+
>,
|
|
27
|
+
networkState: NetworkState,
|
|
28
|
+
state: Parameters<typeof toProvableHookBlockState>[0]
|
|
29
|
+
): BeforeTransactionHookArguments {
|
|
30
|
+
const { transaction, signature } = executionData;
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
networkState,
|
|
34
|
+
transaction,
|
|
35
|
+
signature,
|
|
36
|
+
prover: toProvableHookBlockState(state),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function toAfterTransactionHookArgument(
|
|
41
|
+
executionData: Omit<
|
|
42
|
+
BlockProverTransactionArguments,
|
|
43
|
+
"verificationKeyAttestation"
|
|
44
|
+
>,
|
|
45
|
+
networkState: NetworkState,
|
|
46
|
+
state: Parameters<typeof toProvableHookBlockState>[0],
|
|
47
|
+
runtimeResult: MethodPublicOutput
|
|
48
|
+
): AfterTransactionHookArguments {
|
|
49
|
+
return {
|
|
50
|
+
...toBeforeTransactionHookArgument(executionData, networkState, state),
|
|
51
|
+
runtimeResult,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Purpose is to build transition from -> to network state
|
|
56
|
+
export abstract class ProvableBlockHook<
|
|
57
|
+
Config = NoConfig,
|
|
58
|
+
> extends TransitioningProtocolModule<Config> {
|
|
59
|
+
public abstract beforeBlock(
|
|
60
|
+
networkState: NetworkState,
|
|
61
|
+
state: BeforeBlockHookArguments
|
|
62
|
+
): Promise<NetworkState>;
|
|
63
|
+
|
|
64
|
+
public abstract afterBlock(
|
|
65
|
+
networkState: NetworkState,
|
|
66
|
+
state: AfterBlockHookArguments
|
|
67
|
+
): Promise<NetworkState>;
|
|
68
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { NoConfig } from "@proto-kit/common";
|
|
2
|
+
import { Signature } from "o1js";
|
|
3
|
+
|
|
4
|
+
import { RuntimeTransaction } from "../model/transaction/RuntimeTransaction";
|
|
5
|
+
import { NetworkState } from "../model/network/NetworkState";
|
|
6
|
+
import { MethodPublicOutput } from "../model/MethodPublicOutput";
|
|
7
|
+
import type {
|
|
8
|
+
BlockProverState,
|
|
9
|
+
BlockProverStateCommitments,
|
|
10
|
+
} from "../prover/block/BlockProvable";
|
|
11
|
+
|
|
12
|
+
import { TransitioningProtocolModule } from "./TransitioningProtocolModule";
|
|
13
|
+
|
|
14
|
+
export type ProvableHookBlockState = Pick<
|
|
15
|
+
BlockProverStateCommitments,
|
|
16
|
+
| "transactionsHash"
|
|
17
|
+
| "eternalTransactionsHash"
|
|
18
|
+
| "incomingMessagesHash"
|
|
19
|
+
| "blockHashRoot"
|
|
20
|
+
>;
|
|
21
|
+
|
|
22
|
+
export function toProvableHookBlockState(
|
|
23
|
+
state: Pick<
|
|
24
|
+
BlockProverState,
|
|
25
|
+
| "transactionList"
|
|
26
|
+
| "eternalTransactionsList"
|
|
27
|
+
| "incomingMessages"
|
|
28
|
+
| "blockHashRoot"
|
|
29
|
+
>
|
|
30
|
+
) {
|
|
31
|
+
const {
|
|
32
|
+
transactionList,
|
|
33
|
+
eternalTransactionsList,
|
|
34
|
+
incomingMessages,
|
|
35
|
+
blockHashRoot,
|
|
36
|
+
} = state;
|
|
37
|
+
return {
|
|
38
|
+
transactionsHash: transactionList.commitment,
|
|
39
|
+
eternalTransactionsHash: eternalTransactionsList.commitment,
|
|
40
|
+
incomingMessagesHash: incomingMessages.commitment,
|
|
41
|
+
blockHashRoot,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* This type is a reduced set of the runtime method's public output.
|
|
47
|
+
* It omits internal commitments to data that is already present as data in
|
|
48
|
+
* the hook arguments
|
|
49
|
+
*/
|
|
50
|
+
export type TransactionResult = Omit<
|
|
51
|
+
MethodPublicOutput,
|
|
52
|
+
"networkStateHash" | "transactionHash"
|
|
53
|
+
>;
|
|
54
|
+
|
|
55
|
+
export interface BeforeTransactionHookArguments {
|
|
56
|
+
transaction: RuntimeTransaction;
|
|
57
|
+
signature: Signature;
|
|
58
|
+
networkState: NetworkState;
|
|
59
|
+
prover: ProvableHookBlockState;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface AfterTransactionHookArguments
|
|
63
|
+
extends BeforeTransactionHookArguments {
|
|
64
|
+
runtimeResult: TransactionResult;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export abstract class ProvableTransactionHook<
|
|
68
|
+
Config = NoConfig,
|
|
69
|
+
> extends TransitioningProtocolModule<Config> {
|
|
70
|
+
public abstract beforeTransaction(
|
|
71
|
+
executionData: BeforeTransactionHookArguments
|
|
72
|
+
): Promise<void>;
|
|
73
|
+
|
|
74
|
+
public abstract afterTransaction(
|
|
75
|
+
execution: AfterTransactionHookArguments
|
|
76
|
+
): Promise<void>;
|
|
77
|
+
}
|