Haven1
  • Get started
    • ๐Ÿง‘โ€๐Ÿš€Welcome Havenauts!
    • ๐Ÿ“„Haven1 Litepaper
    • ๐ŸงฎH1 Tokenomics
  • Foundations of Haven1
    • ๐Ÿ“Architecture & network design
    • ๐Ÿ”Network-level security
    • ๐Ÿ“šHaven1 Core protocols
    • ๐Ÿ’ฑBest in class liquidity
    • ๐Ÿ‘ฎNetwork Guardians: Firewall on Haven1
    • ๐ŸŒ‰hBridge: Intro to Haven1 Bridge
  • Learn
    • ๐Ÿ’ตWhat does Haven1 solve?
    • ๐Ÿ’กHaven1: Use Cases
    • ๐Ÿ“šUnderstanding GoQuorum
    • ๐Ÿ”คHaven1 Blockchain basics
    • ๐Ÿ›‚KYC policies on Haven1 blockchain
    • Security at Haven1
    • ๐Ÿ”“What is esH1?
    • โš–๏ธDispute resolution mechanism
    • ๐Ÿ›ฃ๏ธHaven1 Roadmap
    • ๐Ÿ–ฅ๏ธHaven1 is EVM compatible
  • Products
    • ๐Ÿ”ƒhSwap - Spot DEX on Haven1
    • ๐Ÿ“hsETH on Haven1
    • Earn on Haven1
    • ๐Ÿ›ก๏ธ2FA Wallet Shield
    • ๐ŸงŠHaven1 block explorer
    • ๐Ÿ›๏ธGovernance & veH1
    • ๐Ÿ†”hPassport - Key to Haven1
      • Advantages of having ID verification at a network level
      • Understanding the ID Verification Process
    • ๐Ÿ’ผVesting esH1 - Converting esH1 to H1
    • ๐Ÿ“Staking H1 & esH1 - Earning rewards on your H1 holdings
      • Flexible Staking
      • Locked Staking
  • hPerpetuals - Perps DEX on Haven1
  • Haven1 Guides
    • ๐Ÿ”—Quick links
    • โœ…Haven1 onboarding Guide
      • ๐ŸชชKYC Guide
      • Business KYC(KYB) Guide
    • Adding multiple wallets to a hPassport
    • ๐ŸŒ‰Simple Bridging Guide on Haven1 network
    • ๐Ÿ Haven1 Portal - Your Gateway into Haven1
    • ๐Ÿ”‘2FA Set up Guide
    • ๐Ÿค‘Haven1 Airdrop: Claim Process and Strategies
    • Claim Process Walkthrough on Team Finance
    • ๐Ÿ“„Contract Addresses
  • Build
    • ๐Ÿ“–Getting started
    • ๐ŸŒHaven1 Network information
    • ๐ŸฆNovel developer benefits on Haven1
    • ๐Ÿ“‘High level guide for secure deployment
    • โš™๏ธDetailed deployment Guide
    • ๐ŸงฐDeveloper tools
      • ๐Ÿ‘›Haven1 Gnosis Safe wallet
      • ๐Ÿ› ๏ธHaven1 SDK
        • ๐Ÿ”Œ@haven1/sdk-api-client
          • Class: Haven1SDK
          • Class: AuthModule
          • Class: SdkModule
        • โ›“๏ธ@haven1/blockchain-sdk
          • Contracts
        • ๐Ÿงฐ@haven1/wagmi-sdk
          • Constant Module
            • Variable: haven1Devnet
            • Variable: haven1Testnet
            • Variable: H1
          • Contract Module
            • ProofOfIdentity
            • ProofOfIdentityV2
            • NativeAppFee
          • Utility Module
            • bigIntMax
            • formatBigint
            • bigintFromDecimals
          • Hook Module
            • useWatch
            • useBalance
            • useApproveERC20
            • useContractWrite
        • โš›๏ธ@haven1/react-sdk
          • useHaven1SDK
          • useAuth
          • useIdentity
          • useNotifications
          • useOTP
          • useSignIn
        • ๐Ÿ“œUse cases & Examples
          • Adding the Notification Component to Your React UI
          • Check Proof of Identity (POI) Status
      • Oracles on Haven1
      • Subgraph on Haven1
      • Haven1 block explorer
      • Web3 libraries and tools
    • Development frameworks
    • ๐Ÿ”Using hPassport in Your dApps
      • Integrating hPassport into Your dApp
      • Implementing Identity Checks in Smart Contracts
        • Country codes
      • Sample Application - Country ID
      • Sample Application - Composable verification level
      • Sample Application - User type
      • Repository Information
    • โ›ฝApplication fees
      • FeeContract.sol
      • Example FeeContract Interactions
      • Case Studies
    • ๐Ÿ‘ทBuilders grants program
  • Additional resources
    • ๐Ÿ“šHaven1 terminology
  • Quick Links
    • Website
    • Twitter
    • Blog
    • Telegram
    • Customer Support
Powered by GitBook
On this page
  • 1. Retrieve User Attributes from hPassport
  • 2. Enforcing Identity Verification in Smart Contracts
  • 3. Personalizing User Experiences Based on hPassport Attributes
  • 4. Handling Suspended Users
  • 5. Multiple Account Support
  • hPassport API Reference
  • Example Use Case: Auction with Verified Users
  1. Build
  2. Using hPassport in Your dApps

Integrating hPassport into Your dApp

Sample smart contract interactions for provable identity applications on Haven1.

1. Retrieve User Attributes from hPassport

When a user interacts with your dApp, you can retrieve various attributes from their hPassport to verify identity or personalize the experience.

Example: Retrieve the User's Primary Identity

solidityCopy code// Retrieve the userโ€™s primary identity
(bool primaryID, uint256 expiry, uint256 updatedAt) = proofOfIdentity.getPrimaryID(userAddress);

// Ensure the user is verified
require(primaryID, "User is not verified.");

Example: Retrieve the User's Country of Residence Code

solidityCopy code// Retrieve the userโ€™s country code
(string memory countryCode, uint256 expiry, uint256 updatedAt) = proofOfIdentity.getCountryCode(userAddress);

2. Enforcing Identity Verification in Smart Contracts

To ensure only verified users can interact with your contract, check their hPassport before executing any logic. Here's how you can implement this in your contract:

solidityCopy codepragma solidity ^0.8.0;

import { IProofOfIdentity } from "./IProofOfIdentity.sol";

contract VerifiedAuction {

    IProofOfIdentity proofOfIdentity;

    constructor(address _proofOfIdentity) {
        proofOfIdentity = IProofOfIdentity(_proofOfIdentity);
    }

    modifier onlyVerified(address user) {
        (bool primaryID,,) = proofOfIdentity.getPrimaryID(user);
        require(primaryID, "User is not verified.");
        _;
    }

    function placeBid() external onlyVerified(msg.sender) {
        // auction logic here
    }
}

3. Personalizing User Experiences Based on hPassport Attributes

You can personalize the experience for users based on the anonymized data available on their hPassport. For example, you can restrict certain features based on a user's county of residence, or other attributes.

Example: Regional Restriction

solidityCopy code// Retrieve the userโ€™s country code
(string memory countryCode,,) = proofOfIdentity.getCountryCode(userAddress);

// Check if the user is from an allowed country
require(keccak256(abi.encodePacked(countryCode)) == keccak256(abi.encodePacked("US")), "Service not available in your country.");

4. Handling Suspended Users

To prevent suspended users from interacting with your dApp, you can check the suspension status of the user's hPassport:

solidityCopy code// Check if user account is suspended
bool isSuspended = proofOfIdentity.isSuspended(userAddress);
require(!isSuspended, "User account is suspended.");

5. Multiple Account Support

hPassport allows verified users to have multiple wallets, linking their identity to both a primary account and auxiliary accounts. You can retrieve the auxiliary accounts linked to a userโ€™s hPassport as follows:

solidityCopy code// Retrieve auxiliary accounts linked to a principal account
address[] memory auxAccounts = proofOfIdentity.auxiliaryAccounts(principalAddress);

hPassport API Reference

Below are the key functions available in the hPassport contract:

Identity Verification Functions

  • getPrimaryID(address account): Returns a boolean indicating if the user is verified, along with the expiration and last update timestamp.

    solidityCopy code(bool primaryID, uint256 expiry, uint256 updatedAt) = proofOfIdentity.getPrimaryID(userAddress);
  • getCountryCode(address account): Retrieves the userโ€™s country code (stored as a string).

    solidityCopy code(string memory countryCode, uint256 expiry, uint256 updatedAt) = proofOfIdentity.getCountryCode(userAddress);
  • getProofOfLiveliness(address account): Retrieves whether the user has passed proof of liveliness checks.

    solidityCopy code(bool liveliness, uint256 expiry, uint256 updatedAt) = proofOfIdentity.getProofOfLiveliness(userAddress);
  • getUserType(address account): Retrieves the type of user (e.g., retail, institution).

    solidityCopy code(uint256 userType, uint256 expiry, uint256 updatedAt) = proofOfIdentity.getUserType(userAddress);
  • isSuspended(address account): Checks if the userโ€™s hPassport is suspended.

    solidityCopy codebool suspended = proofOfIdentity.isSuspended(userAddress);

Auxiliary Account Functions

  • auxiliaryAccounts(address principal): Returns auxiliary accounts linked to the principal account.

    solidityCopy codeaddress[] memory auxAccounts = proofOfIdentity.auxiliaryAccounts(principalAddress);

Example Use Case: Auction with Verified Users

This example demonstrates how to build an auction application that only allows verified users to participate. The auction uses hPassport to ensure that only users with a verified identity can place bids. This directory contains this example contract

solidityCopy codepragma solidity ^0.8.0;

import { IProofOfIdentity } from "./IProofOfIdentity.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";

contract VerifiedAuction is ReentrancyGuardUpgradeable {

    IProofOfIdentity proofOfIdentity;
    IERC721Upgradeable nft;
    address highestBidder;
    uint256 highestBid;
    uint256 auctionEndTime;

    constructor(address _proofOfIdentity, address _nft) {
        proofOfIdentity = IProofOfIdentity(_proofOfIdentity);
        nft = IERC721Upgradeable(_nft);
    }

    modifier onlyVerified(address user) {
        (bool primaryID,,) = proofOfIdentity.getPrimaryID(user);
        require(primaryID, "User is not verified.");
        _;
    }

    function placeBid() external payable onlyVerified(msg.sender) {
        require(msg.value > highestBid, "Bid too low.");
        require(block.timestamp < auctionEndTime, "Auction has ended.");

        // Refund the previous highest bidder
        if (highestBidder != address(0)) {
            payable(highestBidder).transfer(highestBid);
        }

        highestBid = msg.value;
        highestBidder = msg.sender;
    }

    function endAuction() external {
        require(block.timestamp >= auctionEndTime, "Auction not ended.");
        nft.transferFrom(address(this), highestBidder, 1);
    }
}

Important Notes

  • Demonstration Purpose: These contracts incorporate many Solidity best practices but are intended for demonstration purposes only.

  • Production Considerations:

    • The bid function in AuctionPOI.sol (line 280) should include a reentrancy guard in a production environment.

    • The transfer of H1 tokens in AuctionPOI.sol (lines 454 and 468) should be approached with caution, avoiding optimistic transfers in most cases.

Identity Verification Checks

Both contracts include explicit checks for:

  • The presence of an accountโ€™s ID NFT.

  • The suspended status of the account.

In the Haven1 network, these checks would typically be redundant as the network itself restricts transactions for accounts without an ID NFT or with a suspended status. However, they are included in these examples for educational purposes.

Testing

Example tests for both contracts are available in the directory: test/proof-of-identity/examples. These tests can be used as a reference for developing and validating your own contracts that interact with the hPassport.

PreviousUsing hPassport in Your dAppsNextImplementing Identity Checks in Smart Contracts

Last updated 6 months ago

: This contract is an implementation of an NFT auction system. It uses the userType of an account to permission the auction process, showcasing how user identity attributes can govern smart contract functionalities.

๐Ÿ”
AuctionPOI.sol