Mvmultifactor.sol

Overview

The Multifactor contract implements a multi-factor authentication system for secure transaction management and key handling on the blockchain. It manages ephemeral public keys (factors), JSON Web Key (JWK) data, and security cards, allowing controlled authorization of transactions through multiple cryptographic proofs and signatures. It also maintains a queue of pending transactions requiring confirmation from security cards before execution, enabling stronger security for value transfers.

The contract supports adding, updating, and deleting cryptographic factors and keys, managing ownership and recovery mechanisms, and interacting with a mirrored contract instance for whitelist updates. It enforces expiration policies on keys and transactions to ensure ongoing security.

Data Structures

Transaction

Represents a queued transaction requiring confirmation.

JWKData

Represents JSON Web Key modulus data.

Constants and Flags

State Variables

Constructor

Initializes the contract with provided parameters including contract name, cryptographic keys, proofs, zero-knowledge identifiers, provider information, and root certificates.

Parameters:

Initialization Steps:

Key Functionalities

Factor Management

JWK Management

Transaction Management

Security Cards

Owner and Recovery Key Management

Whitelist Management

Auxiliary Functions

Important Implementation Details and Algorithms

Interactions with Other Contracts and Components

The contract assumes a tightly coupled environment where these external components provide necessary cryptographic and blockchain utilities.

Usage Examples

Adding a New ZKP Factor

bool added = multifactor.addZKPfactor(
    proof,
    epk,
    kid,
    header_base_64,
    epk_expire_at
);
require(added, "Failed to add ZKP factor");

Submitting a Transaction (queued if security cards enabled)

uint64 transactionId = multifactor.submitTransaction(
    epk_expire_at,
    dest,
    value,
    cc,
    bounce,
    allBalance,
    payload
);
if (transactionId == 0) {
    // Transaction executed immediately
} else {
    // Transaction queued for confirmation
}

Confirming a Queued Transaction

multifactor.confirmTransaction(transactionId);

Updating Recovery Key by Owner

multifactor.updateRecoveryPhrase(new_pub_recovery_key, new_pub_recovery_key_sig);

Managing Security Cards

multifactor.addSecurityCard(pubkey, pubkey_sig);
multifactor.turnOnSecurityCards();
multifactor.deleteSecurityCard(pubkey);

Mermaid Diagram

classDiagram
class Multifactor {
+Transaction
+JWKData
-_factors_ordered_by_timestamp: mapping
-_factors_len: uint8
-_root: address
-_name: string
-_owner_pubkey: uint256
-_candidate_new_owner_pubkey_and_expiration: optional
-_pub_recovery_key: uint256
-_jwk_update_key: uint256
-_root_provider_certificates: mapping
-_jwk_modulus_data: mapping
-_jwk_modulus_data_len: uint8
-_start_point_jwk: optional
-_zkid: string
-_index_mod_4: uint8
-_iss_base_64: string
-_lv_provider_bytes: bytes
-_use_security_card: bool
-_m_security_cards: mapping
-_m_security_cards_len: uint8
-_m_transactions: mapping
-_m_transactions_len: uint8
-_min_value: uint128
-_max_cleanup_txns: uint256
-_force_remove_oldest: bool
-_whiteListOfAddress: mapping
-_verification_key_index: uint32
+constructor()
+addZKPfactor()
+deleteZKPfactorByItself()
+cleanExpiredZKPFactors()
+cleanOldestZKPFactor()
+cleanAllExpiredZKPFactors()
+addJwkModulus()
+deleteJwkModulusByUpdateJwkKey()
+cleanExpiredJwks()
+cleanAllExpiredJwks()
+deleteJwkModulusByFactor()
+submitTransaction()
+confirmTransaction()
+sendTransaction()
+addSecurityCard()
+turnOffSecurityCards()
+turnOnSecurityCards()
+deleteSecurityCard()
+deleteAllSecurityCards()
+updateRecoveryPhrase()
+updateJwkUpdateKey()
+updateSeedPhrase()
+changeSeedPhrase()
+acceptCandidateSeedPhrase()
+deleteCandidateSeedPhrase()
+cleanWhiteList()
+updateWhiteList()
+setWhiteList()
+getTransaction()
+getTransactions()
+getTransactionIds()
+getZKPEphemeralPublicKeys()
+getSecurityCardKeys()
+get_epk_expire_at()
+getVersion()
}