multifactor_test.sol

Overview

The Multifactor contract implements a multi-factor authentication mechanism for secure transaction execution and key management on a blockchain platform. It supports Zero-Knowledge Proof (ZKP) factors, JSON Web Key (JWK) management, security card integration, and controlled transaction submission with confirmation by authorized security cards. The contract enforces strict cryptographic verification, expiration handling, and multi-signature validation to ensure robust security in key updates, transaction authorization, and ownership changes.


Contract: Multifactor

Inherits from Modifiers (imported from ./modifiers/modifiers.sol), which presumably provides access control modifiers such as onlyOwnerPubkey.

Data Structures


Constants


State Variables


Constructor

Initializes the contract with critical keys, TLS proof, JWK modulus, provider info, and root certificates.

Parameters include various cryptographic keys, signatures, proofs, expiration timestamps, and provider data.

The constructor performs multiple validations:

Sets initial state variables and inserts the first ZKP factor and JWK modulus data.


Key Functions and Methods

ID Generation


JWK Management


ZKP Factor Management


Ownership and Key Updates


Security Card Management


Transaction Management


Token Exchange


Auxiliary Setters


Getters


Important Implementation Details


Interaction with Other Parts of the System


Usage Examples

Adding a ZKP Factor

bool success = multifactor.addZKPfactor(
    proofData,
    ephemeralPubKey,
    kidBytes,
    headerBase64,
    epkExpireAt
);

Adds a new zero-knowledge proof factor after validating the proof, JWK presence, and expiration constraints.


Submitting a Transaction with Security Cards Enabled

uint64 txnId = multifactor.submitTransaction(
    epkExpireAt,
    destinationAddress,
    valueInNanoGrams,
    ccMapping,
    bounceFlag,
    allBalanceFlag,
    payloadCell
);
// Transaction is queued and requires confirmation by a security card.

Confirming a Queued Transaction

multifactor.confirmTransaction(transactionId);

Called by an authorized security card public key to execute the queued transaction.


Mermaid Diagram

classDiagram
class Multifactor {
+Transaction struct
+JWKData struct
+constructor()
+addJwkModulus()
+deleteJwkModulusByUpdateJwkKey()
+cleanExpiredJwks()
+addZKPfactor()
+deleteZKPfactorByItself()
+cleanExpiredZKPFactors()
+deleteZKPfactor()
+changeSeedPhrase()
+acceptCandidateSeedPhrase()
+addSecurityCard()
+turnOffSecurityCards()
+turnOnSecurityCards()
+deleteSecurityCard()
+sendTransaction()
+submitTransaction()
+confirmTransaction()
+removeExpiredTransactions()
+exchangeToken()
+setMaxCleanupTxns()
+setMinValue()
+getTransaction()
+getTransactions()
+getZKPEphemeralPublicKeys()
+getSecurityCardKeys()
}
Multifactor --> Modifiers