Implementing zkLogin and On-Chain Points with SUI Blockchain

Implementing zkLogin and On-Chain Points with SUI Blockchain

In a recent project, we worked on the integration of the SUI blockchain, an emerging but promising technology, to enhance our solution. This post quickly dives into how we adopted SUI blockchain, its unique features, and the benefits it brought to our project. Our focus was on two key objectives: implementing zkLogin for secure user registration and wallet management, and creating an on-chain points system.

⛓️ What is SUI Blockchain?

Firs things first. What is SUI? SUI is blockchain technology that offers a robust, scalable infrastructure ideal for various decentralized applications (dApps). Its architecture is designed for high throughput and low latency, making it perfect for applications requiring fast, secure transactions. For more detailed information, you can refer to the SUI documentation.

💻 Our Implementation Goals

Certainly SUI, and blockchain in general, can be used for a wide variety of purposes but we’ll focus on two specific primary objectives:

  1. Implementing zkLogin for Secure User Registration and Wallet Management
  2. Creating an On-Chain Points System

1. Implementing zkLogin for Secure User Registration and Wallet Management

The idea of a zkLogin solution leverages zero-knowledge proofs to provide a secure and user-friendly registration process. This method ensures user data remains confidential while enabling seamless wallet management.

  • Why zkLogin?Security and user experience are crucial in modern applications. zkLogin simplifies the registration process by allowing users to sign up and manage their wallets securely without compromising their personal information.
  • Repository: Check out the code for a demo available on our GitHub repository sui-login-demo.

2. Creating an On-Chain Points System

The second objective was to develop a robust on-chain points system that could track and reward user actions on the platform. Although is a very specific purpose, it demonstrates the capabilities to store objects and metadata on-chain at a very low cost and high processing speed.

  • User Profiles On-Chain: We created on-chain profiles for users, managed through their wallets using the zkLogin strategy of the previous demo. This ensures that each user’s actions and points are securely recorded and associated with their unique profile.
  • Action Traceability: What’s the idea behind this? Well, the system tracks user actions such as creating posts, interacting, responding, and giving likes. This traceability allows for a transparent and fair points allocation system.
  • Points Allocation: Points are directly associated with the user’s profile, ensuring an accurate and immutable record of their contributions and interactions.
  • Demo Code: The system was implemented using the Move programming language, specifically designed for the SUI blockchain. You can find below a demo of the implementation code for creating profiles.


module zircon::profile {
    // === Imports ===

    use std::string::String;

    use zircon::profile_cap::{Self, ProfileCap};

    // === Structs ===

    /// The user's Profile.
    public struct Profile has key {
        id: UID,
        /// For tracing ownership from Profile
        cap_id: ID,
        /// Global points in platform
        points: u64,
        username: String,
        user_address: address 
    }

    // === Public-Mutative Functions ===

    public(package) fun new(points: u64, username: String, user_address: address, ctx: &mut TxContext): (Profile, ProfileCap) {
        let mut profile = Profile {
            id: object::new(ctx),
            cap_id: object::id_from_address(@0x0),
            points,
            username,
            user_address
        };

        let profile_cap = profile_cap::new(object::id(&profile), ctx);
        profile.cap_id = object::id(&profile_cap);
        (profile, profile_cap)
    }

    #[allow(lint(share_owned))]
    public(package) fun share(profile: Profile) {
        transfer::share_object(profile);
    }

    public(package) fun drop(profile: Profile) {
        let Profile {
            id,
            cap_id: _,
            points: _,
            username: _,
            user_address: _
        } = profile;
        id.delete();
    }

    public(package) fun points_mut(profile: &mut Profile): &mut u64 {
        &mut profile.points
    }

    public(package) fun username_mut(profile: &mut Profile): &mut String {
        &mut profile.username
    }

    // === Public-View Functions ===

    public(package) fun cap_id(profile: &Profile): &ID {
        &profile.cap_id
    }

    public(package) fun points(profile: &Profile): &u64 {
        &profile.points
    }

    public(package) fun username(profile: &Profile): &String {
        &profile.username
    }

}

💡Conclusion

Our adoption of the SUI blockchain in this project not only addressed our immediate technical needs but also opened up new possibilities for future innovations. By leveraging SUI’s capabilities, we enhanced user security, streamlined registration processes, and implemented a transparent points system.

If you’re looking to explore cutting-edge blockchain technologies for your projects, ZirconTech is here to help. Our expertise in blockchain and decentralized applications ensures we can deliver innovative solutions tailored to your needs.

Feel free to reach out for more information or to discuss how we can assist with your next project.

That’s pretty much it. Thanks for reading! 📖

You can follow me on Twitter and check other posts at ZirconTech for another dose of cool tech stuff.

Cheers!

Will