multifactor.sol

Overview

The Multifactor smart contract implements a multi-factor authentication system for secure transaction management and key control. It integrates zero-knowledge proof (ZKP) factors, JSON Web Key (JWK) management, and security card functionality to protect and authorize transfers of cryptocurrency and token exchanges. The contract supports adding, deleting, and validating cryptographic factors, managing queued transactions requiring multiple confirmations, and updating recovery and ownership keys with robust signature verification and expiration control.

This contract is designed to operate with cryptographic proofs and external validation (e.g., TLS checks) via WebAssembly modules, enforcing strong security practices to prevent unauthorized operations. It provides mechanisms to maintain and clean expired keys and transactions, ensuring the system remains efficient and secure over time.

Data Structures

Transaction

Represents a queued transaction awaiting confirmation.

Field

Type

Description

id

uint64

Unique transaction identifier.

creator

uint256

Ephemeral public key (Epk) of the transaction creator.

dest

address

Destination address of the transfer.

value

uint128

Amount of nanograms to transfer.

cc

mapping(uint32 => varuint32)

Mapping of ECC token amounts to transfer.

sendFlags

uint16

Flags controlling message sending behavior.

payload

TvmCell

Payload for the internal message body.

bounce

bool

Bounce flag for outbound message header.

JWKData

Stores JSON Web Key modulus data with expiration.

Field

Type

Description

modulus

bytes

Modulus bytes of the JWK key.

modulus_expire_at

uint64

Expiration timestamp for the modulus.

Constants

Key contract constants include:

State Variables

Constructor

Initializes the contract with trusted parameters, verifying all input keys and cryptographic proofs with strict expiration and non-repetition checks. It sets the initial ZKP factor, JWK modulus, root provider certificates, and relevant identity strings.

Parameters:

Usage example:

Multifactor multifactor = new Multifactor(
    "zkid_example",
    proof_bytes,
    epk,
    epk_signature,
    epk_expiration,
    jwk_modulus_bytes,
    kid_bytes,
    jwk_expiration,
    index_mod_4,
    iss_base64_str,
    "provider_name",
    header_base64_str,
    pub_recovery_key,
    pub_recovery_key_signature,
    jwk_update_key,
    jwk_update_key_signature,
    initial_value,
    root_provider_certificates_mapping
);

Key Functions

JWK Management

ZKP Factor Management

Owner and Key Updates

Security Card Management

Transaction Management

Auxiliary Functions

Getter Functions

Important Implementation Details and Algorithms

Interaction with Other Components

Visual Diagram

classDiagram
class Multifactor {
+constructor()
+addJwkModulus()
+deleteJwkModulusByUpdateJwkKey()
+cleanExpiredJwks()
+addZKPfactor()
+deleteZKPfactorByItself()
+cleanExpiredZKPFactors()
+cleanOldestZKPFactor()
+setWasmHash()
+addRootProviderCertificate()
+deleteRootProviderCertificate()
+updateRecoveryPhrase()
+updateSeedPhrase()
+changeSeedPhrase()
+acceptCandidateSeedPhrase()
+deleteCandidateSeedPhrase()
+addSecurityCard()
+turnOffSecurityCards()
+submitTransaction()
+confirmTransaction()
+removeExpiredTransactions()
+exchangeToken()
+setMaxCleanupTxns()
+setMinValue()
+getTransaction()
+getTransactions()
+getZKPEphemeralPublicKeys()
}
class Transaction {
+id: uint64
+creator: uint256
+dest: address
+value: uint128
+cc: mapping
+sendFlags: uint16
+payload: TvmCell
+bounce: bool
}
class JWKData {
+modulus: bytes
+modulus_expire_at: uint64
}
Multifactor "1" *-- "many" Transaction : manages
Multifactor "1" *-- "many" JWKData : manages