Skip to content
Juvix imports

module arch.node.engines.decryption_behaviour;

import prelude open;
import arch.node.types.messages open;
import arch.system.identity.identity open;
import arch.node.types.engine open;
import arch.node.engines.decryption_config open;
import arch.node.engines.decryption_environment open;
import arch.node.engines.decryption_messages open;
import arch.node.types.identities open;
import arch.node.types.anoma as Anoma open;

Decryption Behaviour

Overview

The behavior of the Decryption Engine defines how it processes incoming decryption requests and produces the corresponding responses.

Action arguments

DecryptionActionArgumentReplyTo ReplyTo

type ReplyTo :=
mkReplyTo@{
whoAsked : Option EngineID;
mailbox : Option MailboxID;
};

This action argument contains the address and mailbox ID of where the response message should be sent.

whoAsked:
is the address of the engine that sent the message.
mailbox:
is the mailbox ID where the response message should be sent.

DecryptionActionArgument

type DecryptionActionArgument := DecryptionActionArgumentReplyTo ReplyTo;

DecryptionActionArguments

DecryptionActionArguments : Type := List DecryptionActionArgument;

Actions

Auxiliary Juvix code

DecryptionAction

DecryptionAction : Type :=
Action
DecryptionCfg
DecryptionLocalState
DecryptionMailboxState
DecryptionTimerHandle
DecryptionActionArguments
Anoma.Msg
Anoma.Cfg
Anoma.Env;

DecryptionActionInput

DecryptionActionInput : Type :=
ActionInput
DecryptionCfg
DecryptionLocalState
DecryptionMailboxState
DecryptionTimerHandle
DecryptionActionArguments
Anoma.Msg;

DecryptionActionEffect

DecryptionActionEffect : Type :=
ActionEffect
DecryptionLocalState
DecryptionMailboxState
DecryptionTimerHandle
Anoma.Msg
Anoma.Cfg
Anoma.Env;

DecryptionActionExec

DecryptionActionExec : Type :=
ActionExec
DecryptionCfg
DecryptionLocalState
DecryptionMailboxState
DecryptionTimerHandle
DecryptionActionArguments
Anoma.Msg
Anoma.Cfg
Anoma.Env;

decryptAction

Process a decryption request.

State update
The state remains unchanged.
Messages to be sent
A ResponseDecryption message is sent back to the requester.
Engines to be spawned
No engine is created by this action.
Timer updates
No timers are set or cancelled.
decryptAction (input : DecryptionActionInput) : Option DecryptionActionEffect :=
let
env := ActionInput.env input;
cfg := ActionInput.cfg input;
tt := ActionInput.trigger input;
in case getEngineMsgFromTimestampedTrigger tt of
| some emsg :=
case EngineMsg.msg emsg of {
| Anoma.MsgDecryption (MsgDecryptionRequest request) :=
let
decryptedData :=
Decryptor.decrypt
(DecryptionCfg.decryptor (EngineCfg.cfg cfg))
(DecryptionCfg.backend (EngineCfg.cfg cfg))
(RequestDecryption.data request);
responseMsg :=
case decryptedData of
| none :=
mkResponseDecryption@{
data := emptyByteString;
err := some "Decryption Failed";
}
| some plaintext :=
mkResponseDecryption@{
data := plaintext;
err := none;
};
in some
mkActionEffect@{
env := env;
msgs :=
[
mkEngineMsg@{
sender := getEngineIDFromEngineCfg cfg;
target := EngineMsg.sender emsg;
mailbox := some 0;
msg :=
Anoma.MsgDecryption
(MsgDecryptionResponse responseMsg);
};
];
timers := [];
engines := [];
}
| _ := none
}
| _ := none;

Action Labels

decryptActionLabel

decryptActionLabel : DecryptionActionExec := Seq [decryptAction];

Guards

Auxiliary Juvix code

DecryptionGuard

DecryptionGuard : Type :=
Guard
DecryptionCfg
DecryptionLocalState
DecryptionMailboxState
DecryptionTimerHandle
DecryptionActionArguments
Anoma.Msg
Anoma.Cfg
Anoma.Env;

DecryptionGuardOutput

DecryptionGuardOutput : Type :=
GuardOutput
DecryptionCfg
DecryptionLocalState
DecryptionMailboxState
DecryptionTimerHandle
DecryptionActionArguments
Anoma.Msg
Anoma.Cfg
Anoma.Env;

DecryptionGuardEval

DecryptionGuardEval : Type :=
GuardEval
DecryptionCfg
DecryptionLocalState
DecryptionMailboxState
DecryptionTimerHandle
DecryptionActionArguments
Anoma.Msg
Anoma.Cfg
Anoma.Env;

decryptGuard

Condition
Message type is MsgDecryptionRequest.
decryptGuard
(tt : TimestampedTrigger DecryptionTimerHandle Anoma.Msg)
(cfg : EngineCfg DecryptionCfg)
(env : DecryptionEnv)
: Option DecryptionGuardOutput :=
case getEngineMsgFromTimestampedTrigger tt of
| some mkEngineMsg@{msg := Anoma.MsgDecryption (MsgDecryptionRequest _)} :=
some
mkGuardOutput@{
action := decryptActionLabel;
args := [];
}
| _ := none;

The Decryption Behavior

DecryptionBehaviour

DecryptionBehaviour : Type :=
EngineBehaviour
DecryptionCfg
DecryptionLocalState
DecryptionMailboxState
DecryptionTimerHandle
DecryptionActionArguments
Anoma.Msg
Anoma.Cfg
Anoma.Env;

Instantiation

decryptionBehaviour : DecryptionBehaviour :=
mkEngineBehaviour@{
guards := First [decryptGuard];
};

Decryption Action Flowchart

decryptAction flowchart

flowchart TD
  subgraph C[Conditions]
    CMsg>MsgDecryptionRequest]
  end

  G(decryptGuard)
  A(decryptAction)

  C --> G -- *decryptActionLabel* --> A --> E

  subgraph E[Effects]
    EMsg>MsgDecryptionResponse<br/>decryptedData]
  end
decryptAction flowchart