MEM
WebsiteLabsGuides
  • โš—๏ธMolecular Execution Machine
  • ๐Ÿ‘‹Introduction
    • What is MEM?
    • MEM features
    • MEM vs alternatives
    • Technical architecture
    • Use-case examples
  • โšกQuickstart
    • Quickstart guide
  • ๐Ÿ“–MEM Specifications
    • Function syntax
    • Function specs
    • Transaction specs
    • Supported languages
    • About MIPs
  • โš›๏ธMolecules
    • Overview
    • Multichain authentication
    • Using APIs
    • API reference
  • ๐ŸงชMEM IDE
    • Overview
    • Function ABI
  • โš’๏ธMEM Carbon Testnet
    • Overview
    • Deploy to testnet
    • Interact with testnet functions
  • โš™๏ธMEM SDK
    • SDK Usage
  • ๐Ÿ–ฅ๏ธMEM CLI
    • Function deployment
    • Function interaction
  • ๐Ÿ—๏ธMEM API
    • Overview
    • Write operations
    • Read operations
  • โš›๏ธ3EM-MEM
    • Overview
    • EXM API
    • Key-Value Storage (KVS)
  • ๐ŸงฉExamples
    • Pastebin clone
    • Query onchain data
Powered by GitBook

mem.tech ยฉ 2023

On this page
  • Supported Networks
  • Example: EVM-based Caller Authentication with signer atom of evm molecule
  1. Molecules

Multichain authentication

Enhanced functionality and blockchain support with molecule.sh

PreviousOverviewNextUsing APIs

Last updated 1 year ago

molecule.sh not only serves as the global library for MEM functions, offering access to pre-defined plugins and reusable code, but it also provides support for 14 networks. This allows your functions to seamlessly authenticate with various network standards.

For , you can code a MEM function that is compatible with MetaMask wallet for caller validation (using msg.sender in this case).

Supported Networks

Network
elliptic curve / crypto-algo

EVM

secp256k1

Dfinity

ed25519

Arweave

rsa256

Solana

ed25519

Zilliqa

EC-Schnorr (ECC)

Tron

ECDSA

Stacks (STX)

ECDSA

Substrate

sr25519

TON

ed25519

Massa

ed25519

Tezos (tz1 address)

ed25519

Aptos

PureEdDSA

Nostr

Schnorr (over secp256k1)

Fuels

secp256k1

Example: EVM-based Caller Authentication with signer atom of evm molecule

MEM function source code

function.js
export async function handle(state, action) {
  const input = action.input;

  const names = state.names;
  const signatures = state.signatures;
  const verification_message = state.verification_message;
  const evm_molecule_endpoint = state.evm_molecule_endpoint;

  if (input.function === "register") {
    const name = input.name;
    const caller = input.caller;
    const signature = input.signature;

    ContractAssert(name.trim().length, "error invalid name");
    ContractAssert(!(name in names), "name already registered");
    ContractAssert(caller && signature, "missing required arguments");
    ContractAssert(
      !signatures.includes(signature),
      "error signed message used"
    );

    const message = btoa(verification_message);
    await _moleculeSignatureVerification(caller, message, signature);
    state.names[caller] = name.trim();
    signatures.push(signature);

    return { state };
  }

  async function _moleculeSignatureVerification(caller, message, signature) {
    try {
      const isValid = await EXM.deterministicFetch(
        `${evm_molecule_endpoint}/signer/${caller}/${message}/${signature}`
      );
      ContractAssert(isValid.asJSON()?.result, "unauthorized caller");
    } catch (error) {
      throw new ContractError("molecule res error");
    }
  }
}

MEM function initial state

state.json
{
	"names": {},
	"signatures": [],
	"verification_message": "hello world",
	"evm_molecule_endpoint": "http://evm.molecule.sh"
}

The following example demonstrates a MEM function implementation that utilizes EVM for caller authentication (action.caller or similar to msg.sender). This authentication mechanism is provided by the signer of the evm molecule. This approach ensures secure and reliable validation of the function's caller.

โš›๏ธ
atom
example