sdk/js-sdk/notes/ARCHITECTURE.md
// full client (chain, provider, encrypt module, decrypt module)
const fhevmFull = createFhevmClient({ chain, provider });
// partial decrypt client (chain, provider, decrypt module, no encrypt module)
const fhevmDecrypt = createFhevmDecryptClient({ chain, provider });
// partial encrypt client (chain, provider, encrypt module, no decrypt module)
const fhevmEncrypt = createFhevmEncryptClient({ chain, provider });
// create with optional publicKeyBytes,
const fhevmEncrypt = createFhevmEncryptClient({
chain,
provider,
publicKeyBytes,
});
// Problem: how to get the publicKeyBytes ?
// publicKeyBytes can be fetched independently
// Convert partial client to full client
const fhevmFull = fhevmEncrypt.extend(decryptActions);
// decryptActions is a function that takes the client as argument and returns an object that consists in a group of functions
// with client captured
// Function groups usually depends on modules that must be extended to the client runtime to run properly
// For example the decryptActions needs the decryptModule.
// after client extend, the client must be initialized again (because the underlying new decryptModule needs to be initialized)
// decryptActions should automatically extend the module
// The encrypt module requires the global FHE public key
fhevmEncrypt = fhevmEncrypt.withPublicKey(publicKeyBytes);
await fhevmEncrypt.fetchPublicKey();
// returns a promise (eq to { return init(); })
await fhevmEncrypt.ready;
// manual init call (fetch key if needed)
await fhevmEncrypt.init();
// any call to withPublicKey or fetchPublicKey should throw an error after init()
// if init is not called the first call to encrypt will call init()