Skip to content
Juvix imports

module arch.node.engines.encryption;

import prelude open;
import arch.node.types.engine open;
import arch.node.engines.encryption_messages open public;
import arch.node.engines.encryption_environment open public;
import arch.node.engines.encryption_behaviour open public;
import arch.node.engines.encryption_config open public;
import arch.node.engines.encryption_messages open public;
import arch.node.engines.encryption_environment open public;
import arch.node.engines.encryption_behaviour open public;
import arch.node.types.anoma as Anoma open;

open encryption_config_example;
open encryption_environment_example;

Encryption Engine

The Encryption engine is responsible for encrypting data to external identities, possibly using known reads_for relationships. It automatically utilizes "reads_for" relationship information from the Reads For Engine along with caller preference information to choose which identity to encrypt to.

Purpose

The Encryption Engine encrypts data to external identities, optionally using known reads_for relationships. It is a stateless function, and calls to it do not need to be ordered. The runtime should implement this intelligently for efficiency.

Components

  • Encryption Messages
  • Encryption Config
  • Encryption Environment
  • Encryption Behaviour

Type

EncryptionEngine : Type :=
Engine
EncryptionCfg
EncryptionLocalState
EncryptionMailboxState
EncryptionTimerHandle
EncryptionActionArguments
Anoma.Msg
Anoma.Cfg
Anoma.Env;

Example of a encryption engine

exampleEncryptionEngine : EncryptionEngine :=
mkEngine@{
cfg := encryptionCfg;
env := encryptionEnv;
behaviour := encryptionBehaviour;
};

where encryptionCfg is defined as follows:

encryptionCfg : EngineCfg EncryptionCfg :=
mkEngineCfg@{
node := Curve25519PubKey "0xabcd1234";
name := "encryption";
cfg :=
mkEncryptionCfg@{
encryptor :=
\{_ _ :=
mkEncryptor@{
encrypt := \{_ x := x};
encryptorHash :=
mkHASH@{
ordKey :=
mkOrdkey@{
compare := Ord.cmp;
};
hash := \{x := "0x1234abcd"};
};
}};
backend := BackendLocalMemory;
readsForEngineAddress := mkPair none "Blah";
};
};

encryptionEnv is defined as follows:

encryptionEnv : EncryptionEnv :=
mkEngineEnv@{
localState :=
mkEncryptionLocalState@{
pendingRequests := Map.empty;
};
mailboxCluster := Map.empty;
acquaintances := Set.empty;
timers := [];
};

and encryptionBehaviour is defined as follows:

encryptionBehaviour : EncryptionBehaviour :=
mkEngineBehaviour@{
guards := First [encryptGuard; readsForResponseGuard];
};